{
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"
char *ldaphost = NULL;
char *ldapuri = NULL;
- char *dn = NULL;
+ char *user = NULL;
char *binddn = NULL;
struct berval passwd = { 0, NULL };
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 )
{
}
}
- if( argc - optind != 1 ) {
- usage( argv[0] );
- }
-
if (authmethod == -1) {
#ifdef HAVE_CYRUS_SASL
authmethod = LDAP_AUTH_SASL;
#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 */
}
}
- 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 );
}
}
- 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 );
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 ) {