Skip to content
Snippets Groups Projects
Commit 52d2b2ec authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

user argument should be optional

parent a07a97e7
No related branches found
No related tags found
No related merge requests found
......@@ -29,8 +29,8 @@ usage(const char *s)
{
fprintf(stderr,
"Change password of an LDAP user\n\n"
"usage: %s [options] user\n"
" user: the identity of the user, normally a DN\n"
"usage: %s [options] [user]\n"
" user: the autentication identity, commonly a DN\n"
"Password change options:\n"
" -a secret old password\n"
" -A prompt for old password\n"
......@@ -70,7 +70,7 @@ main( int argc, char *argv[] )
char *ldaphost = NULL;
char *ldapuri = NULL;
char *dn = NULL;
char *user = NULL;
char *binddn = NULL;
struct berval passwd = { 0, NULL };
......@@ -109,9 +109,6 @@ main( int argc, char *argv[] )
prog = (prog = strrchr(argv[0], *LDAP_DIRSEP)) == NULL ? argv[0] : prog + 1;
if (argc == 1)
usage (argv[0]);
while( (i = getopt( argc, argv,
"Aa:Ss:" "Cd:D:h:H:InO:p:QRU:vw:WxX:Y:Z" )) != EOF )
{
......@@ -490,10 +487,6 @@ main( int argc, char *argv[] )
}
}
if( argc - optind != 1 ) {
usage( argv[0] );
}
if (authmethod == -1) {
#ifdef HAVE_CYRUS_SASL
authmethod = LDAP_AUTH_SASL;
......@@ -502,7 +495,13 @@ main( int argc, char *argv[] )
#endif
}
dn = strdup( argv[optind] );
if( argc - optind > 1 ) {
usage( argv[0] );
} else if ( argc - optind == 1 ) {
user = strdup( argv[optind] );
} else {
user = NULL;
}
if( want_oldpw && oldpw == NULL ) {
/* prompt for old password */
......@@ -532,16 +531,6 @@ main( int argc, char *argv[] )
}
}
if( binddn == NULL && dn != NULL ) {
binddn = dn;
dn = NULL;
if( passwd.bv_val == NULL ) {
passwd.bv_val = oldpw;
passwd.bv_len = oldpw == NULL ? 0 : strlen( oldpw );
}
}
if (want_bindpw && passwd.bv_val == NULL ) {
/* handle bind password */
fprintf( stderr, "Bind DN: %s\n", binddn );
......@@ -656,7 +645,7 @@ main( int argc, char *argv[] )
}
}
if( dn != NULL || oldpw != NULL || newpw != NULL ) {
if( user != NULL || oldpw != NULL || newpw != NULL ) {
/* build change password control */
BerElement *ber = ber_alloc_t( LBER_USE_DER );
......@@ -668,10 +657,10 @@ main( int argc, char *argv[] )
ber_printf( ber, "{" /*}*/ );
if( dn != NULL ) {
if( user != NULL ) {
ber_printf( ber, "ts",
LDAP_TAG_EXOP_X_MODIFY_PASSWD_ID, dn );
free(dn);
LDAP_TAG_EXOP_X_MODIFY_PASSWD_ID, user );
free(user);
}
if( oldpw != NULL ) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment