]> git.sur5r.net Git - openldap/blobdiff - clients/tools/ldapmodify.c
Remove a few typos in comments
[openldap] / clients / tools / ldapmodify.c
index 96a667ff118773da6b8269862f20936486d36481..fce920e1836f1625cd5fdbf7ba3db5c8195e03e4 100644 (file)
@@ -6,6 +6,7 @@
 #include <stdlib.h>
 
 #include <ac/ctype.h>
+#include <ac/signal.h>
 #include <ac/string.h>
 #include <ac/unistd.h>
 
@@ -68,8 +69,8 @@ main( int argc, char **argv )
 {
     char               *infile, *rbuf, *start, *p, *q;
     FILE               *fp;
-    int                        rc, i, use_ldif, authmethod, want_bindpw, debug;
-    char               *usage = "usage: %s [-abcknrvWF] [-d debug-level] [-h ldaphost] [-p ldapport] [-D binddn] [-w passwd] [ -f file | < entryfile ]\n";
+       int             rc, i, use_ldif, authmethod, version, want_bindpw, debug;
+       char            *usage = "usage: %s [-abcknrvWF] [-d debug-level] [-h ldaphost] [-P version] [-p ldapport] [-D binddn] [-w passwd] [ -f file | < entryfile ]\n";
 
     if (( prog = strrchr( argv[ 0 ], '/' )) == NULL ) {
        prog = argv[ 0 ];
@@ -81,6 +82,7 @@ main( int argc, char **argv )
     infile = NULL;
     not = verbose = valsfromfiles = want_bindpw = debug = 0;
     authmethod = LDAP_AUTH_SIMPLE;
+       version = -1;
 
     while (( i = getopt( argc, argv, "WFabckKnrtvh:p:D:w:d:f:" )) != EOF ) {
        switch( i ) {
@@ -140,6 +142,17 @@ main( int argc, char **argv )
        case 'W':
                want_bindpw++;
                break;
+       case 'P':
+               switch(optarg[0])
+               {
+               case '2':
+                       version = LDAP_VERSION2;
+                       break;
+               case '3':
+                       version = LDAP_VERSION3;
+                       break;
+               }
+               break;
        default:
            fprintf( stderr, usage, prog );
            exit( 1 );
@@ -166,9 +179,13 @@ main( int argc, char **argv )
                ldif_debug = debug;
        }
 
+#ifdef SIGPIPE
+       (void) SIGNAL( SIGPIPE, SIG_IGN );
+#endif
+
     if ( !not ) {
-       if (( ld = ldap_open( ldaphost, ldapport )) == NULL ) {
-           perror( "ldap_open" );
+       if (( ld = ldap_init( ldaphost, ldapport )) == NULL ) {
+           perror( "ldap_init" );
            exit( 1 );
        }
 
@@ -181,6 +198,10 @@ main( int argc, char **argv )
        if (want_bindpw)
                passwd = getpass("Enter LDAP Password: ");
 
+       if( version != -1 ) {
+               ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version );
+       }
+
        if ( ldap_bind_s( ld, binddn, passwd, authmethod ) != LDAP_SUCCESS ) {
            ldap_perror( ld, "ldap_bind" );
            exit( 1 );
@@ -204,7 +225,7 @@ main( int argc, char **argv )
 
        if ( !use_ldif && ( q = strchr( rbuf, '\n' )) != NULL ) {
            for ( p = rbuf; p < q; ++p ) {
-               if ( !isdigit( *p )) {
+               if ( !isdigit( (unsigned char) *p )) {
                    break;
                }
            }
@@ -445,20 +466,21 @@ process_ldapmod_rec( char *rbuf )
                value = p;
            }
 
-           for ( attr = line; *attr != '\0' && isspace( *attr ); ++attr ) {
+           for ( attr = line;
+                 *attr != '\0' && isspace( (unsigned char) *attr ); ++attr ) {
                ;       /* skip attribute leading white space */
            }
 
-           for ( q = p - 1; q > attr && isspace( *q ); --q ) {
+           for ( q = p - 1; q > attr && isspace( (unsigned char) *q ); --q ) {
                *q = '\0';      /* remove attribute trailing white space */
            }
 
            if ( value != NULL ) {
-               while ( isspace( *value )) {
+               while ( isspace( (unsigned char) *value )) {
                    ++value;            /* skip value leading white space */
                }
                for ( q = value + strlen( value ) - 1; q > value &&
-                       isspace( *q ); --q ) {
+                       isspace( (unsigned char) *q ); --q ) {
                    *q = '\0';  /* remove value trailing white space */
                }
                if ( *value == '\0' ) {