]> git.sur5r.net Git - openldap/commitdiff
move getpassphrase inside tool_bind; make sure password is always malloc'd and freed
authorQuanah Gibson-Mount <quanah@openldap.org>
Fri, 16 Apr 2010 00:16:49 +0000 (00:16 +0000)
committerQuanah Gibson-Mount <quanah@openldap.org>
Fri, 16 Apr 2010 00:16:49 +0000 (00:16 +0000)
clients/tools/common.c
clients/tools/ldapcompare.c
clients/tools/ldapdelete.c
clients/tools/ldapexop.c
clients/tools/ldapmodify.c
clients/tools/ldapmodrdn.c
clients/tools/ldappasswd.c
clients/tools/ldapsearch.c
clients/tools/ldapwhoami.c

index 6f79e8804d51dedff3c7078e966d6641437dba4f..bd6df553288b37207f7129833c27f70c63486b52 100644 (file)
@@ -260,11 +260,13 @@ tool_destroy( void )
                ber_memfree( binddn );
        }
 
-#if 0  /* not yet */
        if ( passwd.bv_val != NULL ) {
                ber_memfree( passwd.bv_val );
        }
-#endif
+
+       if ( infile != NULL ) {
+               ber_memfree( infile );
+       }
 }
 
 void
@@ -1357,6 +1359,23 @@ tool_bind( LDAP *ld )
 
        assert( nsctrls < (int) (sizeof(sctrls)/sizeof(sctrls[0])) );
 
+       if ( pw_file || want_bindpw ) {
+               assert( passwd.bv_val == NULL && passwd.bv_len == 0 );
+
+               if ( pw_file ) {
+                       if ( lutil_get_filed_password( pw_file, &passwd ) ) {
+                               exit( EXIT_FAILURE );
+                       }
+
+               } else {
+                       char *pw = getpassphrase( _("Enter LDAP Password: ") );
+                       if ( pw ) {
+                               passwd.bv_val = ber_strdup( pw );
+                               passwd.bv_len = strlen( passwd.bv_val );
+                       }
+               }
+       }
+
        if ( authmethod == LDAP_AUTH_SASL ) {
 #ifdef HAVE_CYRUS_SASL
                void *defaults;
index 1160105cbcacab9087ba2179802a0ac489655a60..460d7e9ae49478054dcd41563b5bdeef1da44f63 100644 (file)
@@ -230,16 +230,6 @@ main( int argc, char **argv )
 
        ld = tool_conn_setup( 0, 0 );
 
-       if ( pw_file || want_bindpw ) {
-               if ( pw_file ) {
-                       rc = lutil_get_filed_password( pw_file, &passwd );
-                       if( rc ) return EXIT_FAILURE;
-               } else {
-                       passwd.bv_val = getpassphrase( _("Enter LDAP Password: ") );
-                       passwd.bv_len = passwd.bv_val ? strlen( passwd.bv_val ) : 0;
-               }
-       }
-
        tool_bind( ld );
 
        if ( 0
index 24f297e6f2bf36fda25a1271e7bd7ed6a4196235..c7e1552e91b307279acc295a5b204f5c4e9cc5e5 100644 (file)
@@ -184,24 +184,10 @@ main( int argc, char **argv )
                if ( optind >= argc ) {
                        fp = stdin;
                }
-    }
+       }
 
        ld = tool_conn_setup( 0, &private_conn_setup );
 
-       if ( pw_file || want_bindpw ) {
-               if ( pw_file ) {
-                       rc = lutil_get_filed_password( pw_file, &passwd );
-                       if( rc ) {
-                               if ( fp && fp != stdin )
-                                       fclose( fp );
-                               return EXIT_FAILURE;
-                       }
-               } else {
-                       passwd.bv_val = getpassphrase( _("Enter LDAP Password: ") );
-                       passwd.bv_len = passwd.bv_val ? strlen( passwd.bv_val ) : 0;
-               }
-       }
-
        tool_bind( ld );
 
        tool_server_controls( ld, NULL, 0 );
index 3125bb1c8078f0591fde4a335c4479c86679aee5..095d5e337669bc82d1bde190527464e17ba62afc 100644 (file)
@@ -89,16 +89,6 @@ main( int argc, char *argv[] )
                usage();
        }
 
-       if ( pw_file || want_bindpw ) {
-               if ( pw_file ) {
-                       rc = lutil_get_filed_password( pw_file, &passwd );
-                       if( rc ) return EXIT_FAILURE;
-               } else {
-                       passwd.bv_val = getpassphrase( _("Enter LDAP Password: ") );
-                       passwd.bv_len = passwd.bv_val ? strlen( passwd.bv_val ) : 0;
-               }
-       }
-
        ld = tool_conn_setup( 0, 0 );
 
        tool_bind( ld );
index 728d96cb41f4af6cf85bc3335de021a8e7a34771..9b20b6667b7d05ad80cb66c9c528255c53c3bc77 100644 (file)
@@ -285,15 +285,6 @@ main( int argc, char **argv )
        ld = tool_conn_setup( dont, 0 );
 
        if ( !dont ) {
-               if ( pw_file || want_bindpw ) {
-                       if ( pw_file ) {
-                               rc = lutil_get_filed_password( pw_file, &passwd );
-                               if( rc ) return EXIT_FAILURE;
-                       } else {
-                               passwd.bv_val = getpassphrase( _("Enter LDAP Password: ") );
-                               passwd.bv_len = passwd.bv_val ? strlen( passwd.bv_val ) : 0;
-                       }
-               }
                tool_bind( ld );
        }
 
index 673e2e3f6212734a04bb063f5c229398534f75e5..a9ccfe87f0ac7f529c461cbb36b0bed5918183b4 100644 (file)
@@ -194,19 +194,6 @@ main(int argc, char **argv)
 
        ld = tool_conn_setup( 0, 0 );
 
-       if ( pw_file || want_bindpw ) {
-               if ( pw_file ) {
-                       rc = lutil_get_filed_password( pw_file, &passwd );
-                       if( rc ) {
-                               retval = EXIT_FAILURE;
-                               goto fail;
-                       }
-               } else {
-                       passwd.bv_val = getpassphrase( _("Enter LDAP Password: ") );
-                       passwd.bv_len = passwd.bv_val ? strlen( passwd.bv_val ) : 0;
-               }
-       }
-
        tool_bind( ld );
 
        tool_server_controls( ld, NULL, 0 );
index b29f50250ccd542af6ee6499664673cfe97c76d5..d526d7677b5c3725ccc0fd526a0ace01a6ebde72 100644 (file)
@@ -245,18 +245,6 @@ main( int argc, char *argv[] )
                newpw.bv_len = strlen( newpw.bv_val );
        }
 
-       if ( pw_file ) {
-               rc = lutil_get_filed_password( pw_file, &passwd );
-               if( rc ) {
-                       rc = EXIT_FAILURE;
-                       goto done;
-               }
-
-       } else if ( want_bindpw ) {
-               passwd.bv_val = getpassphrase( _("Enter LDAP Password: ") );
-               passwd.bv_len = passwd.bv_val ? strlen( passwd.bv_val ) : 0;
-       }
-
        ld = tool_conn_setup( 0, 0 );
 
        tool_bind( ld );
index f4e352467d7515967cdf74435ff8262a6d51c984..f06af7f570efa0fa5f6622c7f4727b2d9627ed17 100644 (file)
@@ -899,16 +899,6 @@ main( int argc, char **argv )
 
        ld = tool_conn_setup( 0, &private_conn_setup );
 
-       if ( pw_file || want_bindpw ) {
-               if ( pw_file ) {
-                       rc = lutil_get_filed_password( pw_file, &passwd );
-                       if( rc ) return EXIT_FAILURE;
-               } else {
-                       passwd.bv_val = getpassphrase( _("Enter LDAP Password: ") );
-                       passwd.bv_len = passwd.bv_val ? strlen( passwd.bv_val ) : 0;
-               }
-       }
-
        tool_bind( ld );
 
 getNextPage:
index 34fab8034cbe4b5b20df595241aaea2ec5506b42..ea312c61b2266f0d5659e339916a74df879e389f 100644 (file)
@@ -129,16 +129,6 @@ main( int argc, char *argv[] )
                usage();
        }
 
-       if ( pw_file || want_bindpw ) {
-               if ( pw_file ) {
-                       rc = lutil_get_filed_password( pw_file, &passwd );
-                       if( rc ) return EXIT_FAILURE;
-               } else {
-                       passwd.bv_val = getpassphrase( _("Enter LDAP Password: ") );
-                       passwd.bv_len = passwd.bv_val ? strlen( passwd.bv_val ) : 0;
-               }
-       }
-
        ld = tool_conn_setup( 0, 0 );
 
        tool_bind( ld );