]> git.sur5r.net Git - openldap/commitdiff
move getpassphrase inside tool_bind; make sure password is always malloc'd and freed
authorPierangelo Masarati <ando@openldap.org>
Mon, 12 Apr 2010 04:06:13 +0000 (04:06 +0000)
committerPierangelo Masarati <ando@openldap.org>
Mon, 12 Apr 2010 04:06:13 +0000 (04:06 +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 aa7a0babab4293f03707ca98ca9202ccb753a13a..51e4edc414343af9cc2983e52ea1f875ea21b725 100644 (file)
@@ -261,11 +261,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
@@ -1381,6 +1383,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 412ad85932ffa783bc929540342f2e050bf97e94..3b9d72626bc12cd4a55bfe2811e1308e56e2cc18 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 359a5c541d4571889a914152ccb338e72b504e6a..1332f9ee995130b95c284ca0a146be2cfe6bd639 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 e9f5d285dec5535bd4a2370d2108afd723c38ade..b69a4dfe64528deb457f5645cedadf539907774d 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 4e2a10f9239eb42b83b562b81d3b60b4895dc830..afbff968bcbfec823256a76f010865b486433205 100644 (file)
@@ -262,18 +262,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 ) {
-                                       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 );
        }
 
index 93570f701ec3e36caa58242d10c92c90b9277f87..74cbf0ba24fa9717de6124a1f310fe10c15a60a8 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 d1638500541abb9439a2997c9a50eec6cc7af813..6b772a4de263f51442b28232faacf0293b6731ca 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 b1b3bf72aa752836957185d2d6ec61449ebaeaee..c1f76f719a798c5f99682c8c4bc6b504c7f99a05 100644 (file)
@@ -909,16 +909,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 006d401245f207ce5a6cda79d1951d4834a81670..5942fec16a4dca41572a3a1cfb1982fdbf6234f3 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 );