コード例 #1
0
int
main( int argc, char **argv )
{
    char	buf[ 4096 ];
    int		rc = 0;
    int		deref, optind;
    LDAPControl	*ldctrl;

#ifdef notdef
#ifdef HPUX11
#ifndef __LP64__
	_main( argc, argv);
#endif /* __LP64_ */
#endif /* HPUX11 */
#endif

    contoper = 0;

    optind = ldaptool_process_args( argc, argv, "c", 0, options_callback );
	
    if ( optind == -1 ) {
		usage();
    }

    if ( ldaptool_fp == NULL && optind >= argc ) {
	ldaptool_fp = stdin;
    }

    ld = ldaptool_ldap_init( 0 );

    deref = LDAP_DEREF_NEVER;	/* prudent, but probably unnecessary */
    ldap_set_option( ld, LDAP_OPT_DEREF, &deref );

    ldaptool_bind( ld );

    if (( ldctrl = ldaptool_create_manage_dsait_control()) != NULL ) {
	ldaptool_add_control_to_array( ldctrl, ldaptool_request_ctrls);
    } 

    if ((ldctrl = ldaptool_create_proxyauth_control(ld)) !=NULL) {
	ldaptool_add_control_to_array( ldctrl, ldaptool_request_ctrls);
    }

    if ( ldaptool_fp == NULL ) {
	for ( ; optind < argc; ++optind ) {
            char *conv;

            conv = ldaptool_local2UTF8( argv[ optind ], "DN" );
	    rc = dodelete( ld, conv, ldaptool_request_ctrls );
            if( conv != NULL )
                free( conv );
	}
    } else {
	while ((rc == 0 || contoper) &&
		fgets(buf, sizeof(buf), ldaptool_fp) != NULL) {
	    buf[ strlen( buf ) - 1 ] = '\0';	/* remove trailing newline */
	    if ( *buf != '\0' ) {
		rc = dodelete( ld, buf, ldaptool_request_ctrls );
	    }
	}
    }

    ldaptool_reset_control_array( ldaptool_request_ctrls );
    ldaptool_cleanup( ld );

    /* check for and report output error */
    fflush( stdout );
    rc = ldaptool_check_ferror( stdout, rc, "output error (output might be incomplete)" );
    return( rc );
}
コード例 #2
0
int
main( int argc, char **argv )
{
    int			rc, optind;
    LDAP		*ld1, *ld2;

#ifdef notdef
#ifdef HPUX11
#ifndef __LP64__
	_main( argc, argv);
#endif /* __LP64_ */
#endif /* HPUX11 */
#endif

    deref = LDAP_DEREF_NEVER;
    allow_binary = vals2tmp = attrsonly = 0;
    ldif = 1;
    sizelimit = timelimit = 0;
    scope = LDAP_SCOPE_SUBTREE;

    optind = ldaptool_process_args( argc, argv, "Bb:l:s:z:", 1,
	    options_callback );

    if ( optind == -1 ) {
	usage();
    }

    if ( base == NULL ) {
	if (( base = getenv( "LDAP_BASEDN" )) == NULL ) {
	    usage();
	}
    }

    ld1 = ldaptool_ldap_init( 0 );

    ldap_set_option( ld1, LDAP_OPT_DEREF, &deref );
    ldap_set_option( ld1, LDAP_OPT_TIMELIMIT, &timelimit );
    ldap_set_option( ld1, LDAP_OPT_SIZELIMIT, &sizelimit );

    ldaptool_bind( ld1 );

    ld2 = ldaptool_ldap_init( 1 );

    ldap_set_option( ld2, LDAP_OPT_DEREF, &deref );
    ldap_set_option( ld2, LDAP_OPT_TIMELIMIT, &timelimit );
    ldap_set_option( ld2, LDAP_OPT_SIZELIMIT, &sizelimit );

    ldaptool_bind( ld2 );
    if ( ldaptool_verbose ) {
	printf( "Connections to servers established.  Beginning comparison.\n" );
    }

    rc = docompare( ld1, ld2, base );

    ldaptool_cleanup( ld1 );
    ldaptool_cleanup( ld2 );
    if ( ldaptool_verbose && !rc ) {
	if ( !differ ) {
	    printf( "compare completed: no differences found\n" );
	} else {
	    printf( "compare completed: ****differences were found****\n" );
	}
    }

    /* check for and report output error */
    fflush( stdout );
    rc = ldaptool_check_ferror( stdout, rc, "output error (output might be incomplete)" );
    return( rc );
}
コード例 #3
0
ファイル: ldapsearch.c プロジェクト: AlainODea/illumos-gate
int
main( int argc, char **argv )
{
    char		*filtpattern, **attrs;
    int			rc, optind, i, first, free_filtpattern;
    LDAP		*ld;

#ifdef SOLARIS_LDAP_CMD
    char *locale = setlocale(LC_ALL, "");
    textdomain(TEXT_DOMAIN);
    ldaptool_require_binddn = 0;
#endif	/* SOLARIS_LDAP_CMD */

    free_filtpattern = 0;
    deref = LDAP_DEREF_NEVER;
    allow_binary = vals2tmp = attrsonly = 0;
    minimize_base64 = produce_file_urls = 0;
    ldif = 1;
    fold = 1;
    sizelimit = timelimit = 0;
    scope = LDAP_SCOPE_SUBTREE;
	server_sort = 0;


#ifdef notdef
#ifdef HPUX11
#ifndef __LP64__
	_main( argc, argv);
#endif /* __LP64_ */
#endif /* HPUX11 */
#endif


    ldaptool_reset_control_array( ldaptool_request_ctrls );
#ifdef HAVE_SASL_OPTIONS
#ifdef SOLARIS_LDAP_CMD
    optind = ldaptool_process_args( argc, argv, "ABLTU1etuxra:b:F:G:l:S:s:z:C:",
        0, options_callback );
#else
    optind = ldaptool_process_args( argc, argv, "ABLTU1etuxa:b:F:G:l:S:s:z:C:c:",
        0, options_callback );
#endif	/* SOLARIS_LDAP_CMD */
#else
    optind = ldaptool_process_args( argc, argv, "ABLTU1eotuxa:b:F:G:l:S:s:z:C:c:",
        0, options_callback );
#endif	/* HAVE_SASL_OPTIONS */

    if ( optind == -1 ) {
	usage();
    }

    if ( base == NULL ) {
	if (( base = getenv( "LDAP_BASEDN" )) == NULL ) {
	    usage();
	}
    }    
    if ( sortattr ) {
	for ( sortsize = 0; sortattr[sortsize] != NULL; sortsize++ ) {
	    ;       /* NULL */
	}
	sortsize++;             /* add in the final NULL field */
	skipsortattr = (int *) malloc( sortsize * sizeof(int *) );
	if ( skipsortattr == NULL ) {
    		fprintf( stderr, gettext("Out of memory\n") );
		exit( LDAP_NO_MEMORY );
	}
	memset( (char *) skipsortattr, 0, sortsize * sizeof(int *) );
    } else if ( server_sort ) {
	server_sort = 0;   /* ignore this option if no sortattrs were given */
    }

    if ( argc - optind < 1 ) {
	if ( ldaptool_fp == NULL ) {
	    usage();
	}
	attrs = NULL;
	filtpattern = "%s";
    } else {	/* there are additional args (filter + attrs) */
	if ( ldaptool_fp == NULL || strstr( argv[ optind ], "%s" ) != NULL ) {
	    filtpattern = ldaptool_local2UTF8( argv[ optind ] );
	    /* since local2UTF8 always allocates something, we should free it */
	    free_filtpattern = 1;
	    ++optind;
	} else {
	    filtpattern = "%s";
	}

	if ( argv[ optind ] == NULL ) {
	    attrs = NULL;
	} else if ( sortattr == NULL || *sortattr == '\0' || server_sort) {
	    attrs = &argv[ optind ];
	} else {
	    attrs = ldap_charray_dup( &argv[ optind ] );
	    if ( attrs == NULL ) {
		fprintf( stderr, gettext("Out of memory\n") );
		exit( LDAP_NO_MEMORY );
	    }
	    for ( i = 0; i < (sortsize - 1); i++ ) {
                if ( !ldap_charray_inlist( attrs, sortattr[i] ) ) {
                    if ( ldap_charray_add( &attrs, sortattr[i] ) != 0 ) {
    			fprintf( stderr, gettext("Out of memory\n") );
			exit( LDAP_NO_MEMORY );
		    }
                    /*
                     * attribute in the search list only for the purpose of
                     * sorting
                     */
                    skipsortattr[i] = 1;
                }
	    }
        }
    }

    ld = ldaptool_ldap_init( 0 );

    if ( !ldaptool_not ) {
	ldap_set_option( ld, LDAP_OPT_DEREF, &deref );
	ldap_set_option( ld, LDAP_OPT_TIMELIMIT, &timelimit );
	ldap_set_option( ld, LDAP_OPT_SIZELIMIT, &sizelimit );
    }

    ldaptool_bind( ld );

    if ( ldaptool_verbose ) {
	printf( gettext("filter pattern: %s\nreturning: "), filtpattern );
	if ( attrs == NULL ) {
	    printf( gettext("ALL") );
	} else {
	    for ( i = 0; attrs[ i ] != NULL; ++i ) {
		printf( "%s ", attrs[ i ] );
	    }
	}
	putchar( '\n' );
    }

    if ( ldaptool_fp == NULL ) {
	char *conv;

	conv = ldaptool_local2UTF8( base );
	rc = dosearch( ld, conv, scope, attrs, attrsonly, filtpattern, "" );
	if( conv != NULL )
            free( conv );
    } else {
	int done = 0;

	rc = LDAP_SUCCESS;
	first = 1;
	while ( rc == LDAP_SUCCESS && !done ) {
	    char *linep = NULL;
	    int   increment = 0;
	    int	  c, index;
	 
	    /* allocate initial block of memory */ 
	    if ((linep = (char *)malloc(BUFSIZ)) == NULL) {
	        fprintf( stderr, gettext("Out of memory\n") );
		exit( LDAP_NO_MEMORY );
	    }
	    increment++;
	    index = 0;
	    while ((c = fgetc( ldaptool_fp )) != '\n' && c != EOF) {

	        /* check if we will overflow the buffer */
	        if ((c != EOF) && (index == ((increment * BUFSIZ) -1))) {

		    /* if we did, add another BUFSIZ worth of bytes */
	   	    if ((linep = (char *)
			realloc(linep, (increment + 1) * BUFSIZ)) == NULL) {
			fprintf( stderr, gettext("Out of memory\n") );
			exit( LDAP_NO_MEMORY );
		    }
		    increment++;
		}
		linep[index++] = c;
	    }

	    if (c == EOF) {
		done = 1;
		break;
	    }
	    
	    linep[index] = '\0';

	    if ( !first ) {
		putchar( '\n' );
	    } else {
		first = 0;
	    }
	    rc = dosearch( ld, base, scope, attrs, attrsonly, filtpattern,
		    linep );
	    free (linep);
	}
    }

    ldaptool_cleanup( ld );
    if (free_filtpattern != 0 && filtpattern != NULL) {
	free (filtpattern);
    }

    /* check for and report output error */
    fflush( stdout );
    rc = ldaptool_check_ferror( stdout, rc,
		gettext("output error (output might be incomplete)") );
    return( rc );
}
コード例 #4
0
int
main( int argc, char **argv )
{
	int	optind;
	int	rc = LDAP_SUCCESS; /* being superoptimistic for -n */
	LDAP	*ld;
	LDAPControl *ldctrl;
		
#ifdef notdef
#ifdef HPUX11
#ifndef __LP64__
	_main( argc, argv);
#endif /* __LP64_ */
#endif /* HPUX11 */
#endif

	optind = ldaptool_process_args( argc, argv, "ASa:t:s:T:", 0, options_callback );
	
	if ( (optind == -1) || (argc <= 1) ) {
		usage();
	}
	if ( (argc - optind) >= 1 ) {
		if ( argv[ optind ] ) {
			if ( (userid.bv_val = ldaptool_local2UTF8(argv[ optind ], "userid") ) == NULL ) {
				fprintf( stderr, "%s: not enough memory\n", ldaptool_progname );
				exit( LDAP_NO_MEMORY );
			}
			userid.bv_len = strlen( userid.bv_val );
			++optind;
		}
	}
	
	ld = ldaptool_ldap_init( 0 );
	ldaptool_bind( ld );
	
	if ( ldaptool_nobind && (userid.bv_val == NULL) && (userid.bv_len == 0) ) {
		usage();
	}

	if ((ldctrl = ldaptool_create_manage_dsait_control()) != NULL) {
		ldaptool_add_control_to_array(ldctrl, ldaptool_request_ctrls);
	}

	if ((ldctrl = ldaptool_create_proxyauth_control(ld)) != NULL) {
		ldaptool_add_control_to_array(ldctrl, ldaptool_request_ctrls);
	}

	if ( !ldaptool_not ) {
		rc = ldap_passwd_s( ld, userid.bv_val ? &userid : NULL, 
								oldpasswd.bv_val ? &oldpasswd : NULL, 
								newpasswd.bv_val ? &newpasswd : NULL, 
								&genpasswd, ldaptool_request_ctrls, NULL );
		if ( rc != LDAP_SUCCESS ) {
			ldap_perror( ld, ldaptool_progname );
		} else {
			fprintf( stderr, "%s: password successfully changed\n", 
					 ldaptool_progname );
		}
	
		if ( (genpasswd.bv_val != NULL) && (genpasswd.bv_len != 0) ) {
			fprintf( stderr, "New password: %s\n", genpasswd.bv_val );
		}
	}

	ldaptool_cleanup( ld );

	/* check for and report output error */
	fflush( stdout );
	rc = ldaptool_check_ferror( stdout, rc, "output error (output might be incomplete)" );
	return( rc );
}
コード例 #5
0
ファイル: ldapmodrdn.c プロジェクト: AlainODea/illumos-gate
int 
main(int argc, char **argv )
{
	char *myname, *entrydn, *rdn, buf[ 4096 ];
	int rc, havedn, deref, optind;
	char * L_newParent = NULL;
	int haverdn = 0;

	int L_protoVersion = LDAP_VERSION3;

	char *locale = setlocale(LC_ALL, "");
	textdomain(TEXT_DOMAIN);
	ldaplogconfigf(NULL); 


	contoper =  remove_oldrdn = 0;

	if ((myname = strrchr(argv[0], '/')) == NULL)
		myname = argv[0];
	else
		++myname;

	optind = ldaptool_process_args( argc, argv, "cr", 0, options_callback);
	
	if ( optind == -1 ) {
		usage();
	}

	if ( ldaptool_fp == NULL ) {
	ldaptool_fp = stdin;
	}

	havedn = 0;
	if (argc - optind == 3) 		/* accept as arguments: dn rdn newsuperior */
	{
		if (( L_newParent = strdup( argv[argc - 1] )) == NULL ) 
		{
			perror( "strdup" );
			exit( LDAP_NO_MEMORY );
		}

		if (( rdn = strdup( argv[argc - 2] )) == NULL ) 
		{
			perror( "strdup" );
			exit( LDAP_NO_MEMORY );
		}

		if (( entrydn = strdup( argv[argc - 3] )) == NULL ) 
		{
			perror( "strdup" );
			exit( LDAP_NO_MEMORY );
		}
		++havedn;
	} 
	else if (argc - optind == 2) 		/* accept as arguments: dn rdn */
	{
		if (( rdn = strdup( argv[argc - 1] )) == NULL ) 
		{
			perror( "strdup" );
			exit( LDAP_NO_MEMORY );
		}

		if (( entrydn = strdup( argv[argc - 2] )) == NULL ) 
		{
			perror( "strdup" );
			exit( 1 );
		}
		++havedn;
	} 
	else if ( argc - optind != 0 ) 
	{
		fprintf( stderr, gettext("%s: invalid number of arguments, only two or three allowed\n"), myname);
		usage();
		exit( 1 );
	}

	ld = ldaptool_ldap_init (0);

	if ( !ldaptool_not ) {
		deref = LDAP_DEREF_NEVER;	/* this seems prudent */
		ldap_set_option( ld, LDAP_OPT_DEREF, &deref );
	}

	ldaptool_bind( ld );

	rc = 0;
	if (havedn)
	{
		rc = domodrdn(ld, entrydn, rdn, L_newParent, remove_oldrdn);
	}
	else while (	(rc == 0 || contoper) && 
					(fgets(buf, sizeof(buf), ldaptool_fp) != NULL) )

	{
		/* 
		 * The format of the file is one of the following:
		 * 	dn
		 * 	rdn
		 * 	newsuperior
		 * 	<blank lines...>
		 * OR
		 * 	dn
		 * 	rdn
		 * 	<blank lines...>
		 * both types of sequences can be found in the file
		 */
		
		if ( (strlen(buf) == 1) && (ldaptool_fp == stdin) )
			break;

		buf[ strlen( buf ) - 1 ] = '\0';	/* remove nl */
		if ( *buf != '\0' ) 		/* blank lines optional, skip */
		{
			if ( haverdn )		/* first type of sequence */
			{
				if (( L_newParent = strdup( buf )) == NULL ) 
				{
					perror( "strdup" );
					exit( LDAP_NO_MEMORY );
				}
				if ( L_newParent && (L_protoVersion == LDAP_VERSION) )
				{
					printf( gettext("LDAP Server is V2: <newsuperior> argument is ignored...\n") );
					L_newParent = NULL;
				}
				rc = domodrdn(ld, entrydn, rdn, L_newParent, remove_oldrdn);
				haverdn = 0;
			}
			else if ( havedn ) 		/* have DN, get RDN */
			{
				if (( rdn = strdup( buf )) == NULL ) 
				{
					perror( "strdup" );
					exit( LDAP_NO_MEMORY );
				}
				havedn = 0;
				++haverdn;
			}
			else if ( !havedn ) 		/* don't have DN yet */
			{
				if (( entrydn = strdup( buf )) == NULL)
				{
					perror( "strdup" );
					exit( LDAP_NO_MEMORY );
				}
				++havedn;
			}
		}
		else
		{
			printf(gettext("kex: new line %d\n"), rc);
			if ( haverdn )		/* second type of sequence */
			{
				rc = domodrdn(ld, entrydn, rdn, NULL, remove_oldrdn);
				haverdn = 0;
			}
		}
	}
	if ( (rc == 0 || contoper) && haverdn )		/* second type of sequence */
	{
		rc = domodrdn(ld, entrydn, rdn, NULL, remove_oldrdn);
		haverdn = 0;
	}

	ldaptool_cleanup( ld );

	exit( rc );
}
コード例 #6
0
ファイル: ldapmodify.c プロジェクト: alhazred/onarm
static int
process( void *arg )
{
    char	*rbuf, *saved_rbuf, *start, *p, *q;
    FILE	*rfp = NULL;
    int		rc, use_ldif, deref;
    LDAPControl	*ldctrl;

#ifdef SOLARIS_LDAP_CMD
    LDAP	*ld;
#endif  /* SOLARIS_LDAP_CMD */
    
    ld = ldaptool_ldap_init( 0 );

    if ( !ldaptool_not ) {
	deref = LDAP_DEREF_NEVER;	/* this seems prudent */
	ldap_set_option( ld, LDAP_OPT_DEREF, &deref );
    }

    ldaptool_bind( ld );

    if (( ldctrl = ldaptool_create_manage_dsait_control()) != NULL ) {
	ldaptool_add_control_to_array( ldctrl, ldaptool_request_ctrls);
    } 

    if ((ldctrl = ldaptool_create_proxyauth_control(ld)) !=NULL) {
	ldaptool_add_control_to_array( ldctrl, ldaptool_request_ctrls);
    }

    rc = 0;

    /* turn on bulk import?*/
    if (bulkimport_suffix) {
	struct berval	bv, *retdata;
	char		*retoid;

	bv.bv_val = bulkimport_suffix;
	bv.bv_len = strlen(bulkimport_suffix);
	if ((rc = ldap_extended_operation_s(ld,
	    BULKIMPORT_START_OID, &bv, NULL,
	    NULL, &retoid, &retdata)) != 0) {
		fprintf(stderr, gettext("Error: unable to service "
		    "extended operation request\n\t'%s' for "
		    "bulk import\n\t(error:%d:'%s')\n"),
		    BULKIMPORT_START_OID, rc, ldap_err2string(rc));
		return (rc);
	}
	if (retoid)
		ldap_memfree(retoid);
	if (retdata)
		ber_bvfree(retdata);
    }

    while (( rc == 0 || contoper ) &&
		( rbuf = read_one_record( ldaptool_fp )) != NULL ) {
	/*
	 * we assume record is ldif/slapd.replog if the first line
	 * has a colon that appears to the left of any equal signs, OR
	 * if the first line consists entirely of digits (an entry id)
	 */
	use_ldif = ( p = strchr( rbuf, ':' )) != NULL &&
		( q = strchr( rbuf, '\n' )) != NULL && p < q &&
		(( q = strchr( rbuf, '=' )) == NULL || p < q );

	start = rbuf;
	saved_rbuf = strdup( rbuf );

	if ( !use_ldif && ( q = strchr( rbuf, '\n' )) != NULL ) {
	    for ( p = rbuf; p < q; ++p ) {
		if ( !isdigit( *p )) {
		    break;
		}
	    }
	    if ( p >= q ) {
		use_ldif = 1;
		start = q + 1;
	    }
	}

#ifdef SOLARIS_LDAP_CMD
	if ( use_ldif ) {
	    rc = process_ldif_rec( ld, start );
	} else {
	    rc = process_ldapmod_rec( ld, start );
	}
#else
	if ( use_ldif ) {
	    rc = process_ldif_rec( start );
	} else {
	    rc = process_ldapmod_rec( start );
	}
#endif	/* SOLARIS_LDAP_CMD */

	if ( rc != LDAP_SUCCESS && rejfile != NULL ) {
	    /* Write this record to the reject file */
	    int newfile = 0;
	    struct stat stbuf;
	    if ( stat( rejfile, &stbuf ) < 0 ) {
		if ( errno == ENOENT ) {
		    newfile = 1;
		}
	    }
	    if (( rfp = ldaptool_open_file( rejfile, "a" )) == NULL ) {
		fprintf( stderr, gettext("Cannot open error file \"%s\" - "
			"erroneous entries will not be saved\n"), rejfile );
		rejfile = NULL;
	    } else {
		if ( newfile == 0 ) {
		    fputs( "\n", rfp );
		}
		fprintf( rfp, gettext("# Error: %s\n"), ldap_err2string( rc ));
		fputs( saved_rbuf, rfp );
		fclose( rfp );
		rfp = NULL;
	    }
	}

	free( rbuf );
	free( saved_rbuf );
    }
    ldaptool_reset_control_array( ldaptool_request_ctrls );

    /* turn off bulk import?*/
    if (bulkimport_suffix) {
	struct berval	bv, *retdata;
	char		*retoid;

	bv.bv_val = "";
	bv.bv_len = 0;
	if ((rc = ldap_extended_operation_s(ld,
	    BULKIMPORT_STOP_OID, &bv, NULL,
	    NULL, &retoid, &retdata)) != 0) {

		fprintf(stderr, gettext("Error: unable to service "
		    "extended operation request\n\t '%s' for "
		    "bulk import\n\t(rc:%d:'%s')\n"),
		    BULKIMPORT_STOP_OID, rc, ldap_err2string(rc));
		return (rc);
	}
	if (retoid)
		ldap_memfree(retoid);
	if (retdata)
		ber_bvfree(retdata);
    }

#ifdef SOLARIS_LDAP_CMD
    mutex_lock(&read_mutex);	
#endif
    ldaptool_cleanup( ld );
#ifdef SOLARIS_LDAP_CMD
    mutex_unlock(&read_mutex);	
#endif
    return( rc );
}