]> git.sur5r.net Git - openldap/commitdiff
ITS#2657: authzid (and assertion) should apply to most everything
authorKurt Zeilenga <kurt@openldap.org>
Wed, 30 Jul 2003 10:21:16 +0000 (10:21 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Wed, 30 Jul 2003 10:21:16 +0000 (10:21 +0000)
(preliminary modify/incr client-side code)

clients/tools/common.h
clients/tools/ldapcompare.c
clients/tools/ldapdelete.c
clients/tools/ldapmodify.c
clients/tools/ldapmodrdn.c
clients/tools/ldappasswd.c
clients/tools/ldapsearch.c
clients/tools/ldapwhoami.c

index dabcf250c988d3c3c9aacf49e5082ced96eb6556..38ecf7d4bf7f535ba78d9808f44d52ee9760915a 100644 (file)
@@ -29,6 +29,7 @@ extern char   *sasl_secprops;
 #endif
 extern int   use_tls;
 
+extern char *assertion;
 extern char *authzid;
 extern int   manageDSAit;
 extern int   noop;
index da957436a5e0fc603f8957b2e6a2b693dda76b35..93ed554cc5e44cc63ff55ff0e5664d1eca62745d 100644 (file)
@@ -172,8 +172,9 @@ main( int argc, char **argv )
 
        tool_bind( ld );
 
-       if ( authzid || manageDSAit || noop )
+       if ( assertion || authzid || manageDSAit || noop ) {
                tool_server_controls( ld, NULL, 0 );
+       }
 
        if ( verbose ) {
                fprintf( stderr, _("DN:%s, attr:%s, value:%s\n"),
index 908f7f1495f609865c9adf5578fab5301ee83003..7aa0b7bf5e9fb80fa0f9497e4905929f79c6bf48 100644 (file)
@@ -143,8 +143,9 @@ main( int argc, char **argv )
 
        tool_bind( ld );
 
-       if ( authzid || manageDSAit || noop )
+       if ( assertion || authzid || manageDSAit || noop ) {
                tool_server_controls( ld, NULL, 0 );
+       }
 
        retval = rc = 0;
 
index 2003d23dc937b0a72b3cc3c1f65a47d801fbc400..fc737a4862c62c21910cdf17c3378bff998f996e 100644 (file)
@@ -58,6 +58,7 @@ static LDAP   *ld = NULL;
 #define T_MODOPADDSTR          "add"
 #define T_MODOPREPLACESTR      "replace"
 #define T_MODOPDELETESTR       "delete"
+#define T_MODOPINCREMENTSTR    "increment"
 #define T_MODSEPSTR            "-"
 #define T_NEWRDNSTR            "newrdn"
 #define T_DELETEOLDRDNSTR      "deleteoldrdn"
@@ -168,123 +169,123 @@ handle_private_option( int i )
 int
 main( int argc, char **argv )
 {
-    char               *rbuf, *start, *rejbuf = NULL;
-    FILE               *fp, *rejfp;
+       char            *rbuf, *start, *rejbuf = NULL;
+       FILE            *fp, *rejfp;
        char            *matched_msg, *error_msg;
        int             rc, retval;
        int count, len;
 
-    tool_init();
-    prog = lutil_progname( "ldapmodify", argc, argv );
+       tool_init();
+       prog = lutil_progname( "ldapmodify", argc, argv );
 
        /* strncmp instead of strcmp since NT binaries carry .exe extension */
-    ldapadd = ( strncasecmp( prog, "ldapadd", sizeof("ldapadd")-1 ) == 0 );
+       ldapadd = ( strncasecmp( prog, "ldapadd", sizeof("ldapadd")-1 ) == 0 );
 
-    /* Print usage when no parameters */
-    if( argc < 2 ) usage();
+       /* Print usage when no parameters */
+       if( argc < 2 ) usage();
 
        tool_args( argc, argv );
 
-       if ( argc != optind )
-       usage();
+       if ( argc != optind ) usage();
 
-    if ( rejfile != NULL ) {
-       if (( rejfp = fopen( rejfile, "w" )) == NULL ) {
-           perror( rejfile );
-           return( EXIT_FAILURE );
+       if ( rejfile != NULL ) {
+               if (( rejfp = fopen( rejfile, "w" )) == NULL ) {
+                       perror( rejfile );
+                       return( EXIT_FAILURE );
+               }
+       } else {
+               rejfp = NULL;
        }
-    } else {
-       rejfp = NULL;
-    }
 
-    if ( infile != NULL ) {
-       if (( fp = fopen( infile, "r" )) == NULL ) {
-           perror( infile );
-           return( EXIT_FAILURE );
+       if ( infile != NULL ) {
+               if (( fp = fopen( infile, "r" )) == NULL ) {
+                       perror( infile );
+                       return( EXIT_FAILURE );
+               }
+       } else {
+               fp = stdin;
        }
-    } else {
-       fp = stdin;
-    }
 
-       if ( debug )
-               ldif_debug = debug;
+       if ( debug ) ldif_debug = debug;
 
        ld = tool_conn_setup( not, 0 );
 
-    if ( !not ) {
-       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;
+       if ( !not ) {
+               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 );
        }
 
-       tool_bind( ld );
-    }
-
     rc = 0;
 
-       if ( authzid || manageDSAit || noop )
+       if ( assertion || authzid || manageDSAit || noop ) {
                tool_server_controls( ld, NULL, 0 );
+       }
 
        count = 0;
        retval = 0;
-    while (( rc == 0 || contoper ) &&
-               ( rbuf = read_one_record( fp )) != NULL ) {
-       count++;
+       while (( rc == 0 || contoper ) &&
+               ( rbuf = read_one_record( fp )) != NULL )
+       {
+               count++;
 
-       start = rbuf;
+               start = rbuf;
 
-       if ( rejfp ) {
-               len = strlen( rbuf );
-               if (( rejbuf = (char *)ber_memalloc( len+1 )) == NULL ) {
-                       perror( "malloc" );
-                       exit( EXIT_FAILURE );
+               if ( rejfp ) {
+                       len = strlen( rbuf );
+                       if (( rejbuf = (char *)ber_memalloc( len+1 )) == NULL ) {
+                               perror( "malloc" );
+                               exit( EXIT_FAILURE );
+                       }
+                       memcpy( rejbuf, rbuf, len+1 );
                }
-               memcpy( rejbuf, rbuf, len+1 );
-       }
 
-    rc = process_ldif_rec( start, count );
+               rc = process_ldif_rec( start, count );
 
-       if ( rc )
-               retval = rc;
-       if ( rc && rejfp ) {
-               fprintf(rejfp, _("# Error: %s (%d)"), ldap_err2string(rc), rc);
+               if ( rc ) retval = rc;
+               if ( rc && rejfp ) {
+                       fprintf(rejfp, _("# Error: %s (%d)"), ldap_err2string(rc), rc);
 
-               matched_msg = NULL;
-               ldap_get_option(ld, LDAP_OPT_MATCHED_DN, &matched_msg);
-               if ( matched_msg != NULL ) {
-                       if ( *matched_msg != '\0' )
-                               fprintf( rejfp, _(", matched DN: %s"), matched_msg );
-                       ldap_memfree( matched_msg );
-               }
+                       matched_msg = NULL;
+                       ldap_get_option(ld, LDAP_OPT_MATCHED_DN, &matched_msg);
+                       if ( matched_msg != NULL ) {
+                               if ( *matched_msg != '\0' ) {
+                                       fprintf( rejfp, _(", matched DN: %s"), matched_msg );
+                               }
+                               ldap_memfree( matched_msg );
+                       }
 
-               error_msg = NULL;
-               ldap_get_option(ld, LDAP_OPT_ERROR_STRING, &error_msg);
-               if ( error_msg != NULL ) {
-                       if ( *error_msg != '\0' )
-                               fprintf( rejfp, _(", additional info: %s"), error_msg );
-                       ldap_memfree( error_msg );
+                       error_msg = NULL;
+                       ldap_get_option(ld, LDAP_OPT_ERROR_STRING, &error_msg);
+                       if ( error_msg != NULL ) {
+                               if ( *error_msg != '\0' ) {
+                                       fprintf( rejfp, _(", additional info: %s"), error_msg );
+                               }
+                               ldap_memfree( error_msg );
+                       }
+                       fprintf( rejfp, "\n%s\n", rejbuf );
                }
-               fprintf( rejfp, "\n%s\n", rejbuf );
-       }
-               if (rejfp) 
-                       free( rejbuf );
+
+               if (rejfp) free( rejbuf );
                free( rbuf );
-    }
+       }
 
-    if ( !not ) {
+       if ( !not ) {
                ldap_unbind( ld );
-    }
+       }
 
-    if ( rejfp != NULL ) {
-           fclose( rejfp );
-    }
+       if ( rejfp != NULL ) {
+               fclose( rejfp );
+       }
 
-    return( retval );
+       return( retval );
 }
 
 
@@ -461,6 +462,10 @@ process_ldif_rec( char *rbuf, int count )
                modop = LDAP_MOD_DELETE;
                addmodifyop( &pmods, modop, val.bv_val, NULL );
                goto end_line;
+           } else if ( strcasecmp( type, T_MODOPINCREMENTSTR ) == 0 ) {
+               modop = LDAP_MOD_INCREMENT;
+               addmodifyop( &pmods, modop, val.bv_val, NULL );
+               goto end_line;
            } else {    /* no modify op:  use default */
                modop = ldapadd ? LDAP_MOD_ADD : LDAP_MOD_REPLACE;
            }
@@ -829,8 +834,11 @@ domodify(
        for ( i = 0; pmods[ i ] != NULL; ++i ) {
            op = pmods[ i ]->mod_op & ~LDAP_MOD_BVALUES;
            printf( "%s %s:\n",
-                       op == LDAP_MOD_REPLACE ? _("replace") : op == LDAP_MOD_ADD
-                               ?  _("add") : _("delete"),
+                       op == LDAP_MOD_REPLACE ? _("replace") :
+                               op == LDAP_MOD_ADD ?  _("add") :
+                                       op == LDAP_MOD_INCREMENT ?  _("increment") :
+                                               op == LDAP_MOD_DELETE ?  _("delete") :
+                                                       _("unknown"),
                        pmods[ i ]->mod_type );
            if ( pmods[ i ]->mod_bvalues != NULL ) {
                for ( j = 0; pmods[ i ]->mod_bvalues[ j ] != NULL; ++j ) {
index 53db82726d730af4d525af2a78ebf12708da64bb..672a4ca424ee9d7133a340ff7cc940f5eb3ddc76 100644 (file)
@@ -171,8 +171,9 @@ main(int argc, char **argv)
 
        tool_bind( ld );
 
-       if ( authzid || manageDSAit || noop )
+       if ( assertion || authzid || manageDSAit || noop ) {
                tool_server_controls( ld, NULL, 0 );
+       }
 
     retval = rc = 0;
     if (havedn)
index 0551229f8002d6e210b9684cb942647ccadef06b..a8c7f98cd1bef2d0532c30c3f1e583838389c87d 100644 (file)
@@ -221,8 +221,9 @@ main( int argc, char *argv[] )
 
        tool_bind( ld );
 
-       if ( authzid || manageDSAit || noop )
+       if ( assertion || authzid || manageDSAit || noop ) {
                tool_server_controls( ld, NULL, 0 );
+       }
 
        if( user != NULL || oldpw.bv_val != NULL || newpw.bv_val != NULL ) {
                /* build change password control */
index 12b26cd4684af2b144d43cccb00117b186b2e8cc..e98d36892399bcb6dabe234b05c7d408260b11eb 100644 (file)
@@ -548,17 +548,18 @@ main( int argc, char **argv )
        tool_bind( ld );
 
 getNextPage:
-       if ( manageDSAit || noop || subentries || valuesReturnFilter
+       if ( assertion || authzid || manageDSAit || noop
 #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
-                       || domainScope
+               || domainScope
 #endif
 #ifdef LDAP_CONTROL_PAGEDRESULTS
-                       || pageSize
+               || pageSize
 #endif
 #ifdef LDAP_SYNC
-                       || ldapsync
+               || ldapsync
 #endif
-                       ) {
+               || subentries || valuesReturnFilter )
+       {
                int err;
                int i=0;
                LDAPControl c[6];
index f81971dde08c8eb1b70bcb1b0bdffbbca266fbc4..f0ea1c40d8bc782de6dc668bb0543a4f77fb2400 100644 (file)
@@ -124,8 +124,9 @@ main( int argc, char *argv[] )
                goto skip;
        }
 
-       if ( authzid || manageDSAit || noop )
+       if ( assertion || authzid || manageDSAit || noop ) {
                tool_server_controls( ld, NULL, 0 );
+       }
 
        rc = ldap_whoami_s( ld, &retdata, NULL, NULL );