1 /* slapcommon.c - common routine for the slap tools */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2017 The OpenLDAP Foundation.
6 * Portions Copyright 1998-2003 Kurt D. Zeilenga.
7 * Portions Copyright 2003 IBM Corporation.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted only as authorized by the OpenLDAP
14 * A copy of this license is available in file LICENSE in the
15 * top-level directory of the distribution or, alternatively, at
16 * <http://www.OpenLDAP.org/license.html>.
19 * This work was initially developed by Kurt Zeilenga for inclusion
20 * in OpenLDAP Software. Additional signficant contributors include
22 * Hallvard B. Furuseth
31 #include <ac/stdlib.h>
33 #include <ac/string.h>
34 #include <ac/socket.h>
35 #include <ac/unistd.h>
37 #include "slapcommon.h"
41 tool_vars tool_globals;
44 static char *leakfilename;
45 static FILE *leakfile;
50 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
52 static char **syslog_unknowns;
54 static int syslogUser = SLAP_DEFAULT_SYSLOG_USER;
55 #endif /* LOG_LOCAL4 */
56 #endif /* LDAP_DEBUG && LDAP_SYSLOG */
59 usage( int tool, const char *progname )
63 "usage: %s [-v] [-d debuglevel] [-f configfile] [-F configdir] [-o <name>[=<value>]]",
68 options = "\n\t[-U authcID | -D authcDN] [-X authzID | -o authzDN=<DN>]"
69 "\n\t-b DN [-u] [attr[/access][:value]] [...]\n";
73 options = " [-c]\n\t[-g] [-n databasenumber | -b suffix]\n"
74 "\t[-l ldiffile] [-j linenumber] [-q] [-u] [-s] [-w]\n";
78 options = "\n\t[-U authcID] [-X authzID] [-R realm] [-M mech] ID [...]\n";
82 options = " [-c]\n\t[-g] [-n databasenumber | -b suffix]"
83 " [-l ldiffile] [-a filter] [-s subtree] [-H url]\n";
87 options = "\n\t[-N | -P] DN [...]\n";
91 options = " [-c]\n\t[-g] [-n databasenumber | -b suffix] [attr ...] [-q] [-t]\n";
95 options = " [-n databasenumber] [-u] [-Q]\n";
99 options = " [-c]\n\t[-g] [-n databasenumber | -b suffix]"
100 " [-l errorfile] [-a filter] [-s subtree] [-H url]\n";
104 if ( options != NULL ) {
105 fputs( options, stderr );
107 exit( EXIT_FAILURE );
111 parse_slapopt( int tool, int *mode )
116 p = strchr( optarg, '=' );
122 if ( strncasecmp( optarg, "sockurl", len ) == 0 ) {
123 if ( !BER_BVISNULL( &listener_url ) ) {
124 ber_memfree( listener_url.bv_val );
126 ber_str2bv( p, 0, 1, &listener_url );
128 } else if ( strncasecmp( optarg, "domain", len ) == 0 ) {
129 if ( !BER_BVISNULL( &peer_domain ) ) {
130 ber_memfree( peer_domain.bv_val );
132 ber_str2bv( p, 0, 1, &peer_domain );
134 } else if ( strncasecmp( optarg, "peername", len ) == 0 ) {
135 if ( !BER_BVISNULL( &peer_name ) ) {
136 ber_memfree( peer_name.bv_val );
138 ber_str2bv( p, 0, 1, &peer_name );
140 } else if ( strncasecmp( optarg, "sockname", len ) == 0 ) {
141 if ( !BER_BVISNULL( &sock_name ) ) {
142 ber_memfree( sock_name.bv_val );
144 ber_str2bv( p, 0, 1, &sock_name );
146 } else if ( strncasecmp( optarg, "ssf", len ) == 0 ) {
147 if ( lutil_atou( &ssf, p ) ) {
148 Debug( LDAP_DEBUG_ANY, "unable to parse ssf=\"%s\".\n", p, 0, 0 );
152 } else if ( strncasecmp( optarg, "transport_ssf", len ) == 0 ) {
153 if ( lutil_atou( &transport_ssf, p ) ) {
154 Debug( LDAP_DEBUG_ANY, "unable to parse transport_ssf=\"%s\".\n", p, 0, 0 );
158 } else if ( strncasecmp( optarg, "tls_ssf", len ) == 0 ) {
159 if ( lutil_atou( &tls_ssf, p ) ) {
160 Debug( LDAP_DEBUG_ANY, "unable to parse tls_ssf=\"%s\".\n", p, 0, 0 );
164 } else if ( strncasecmp( optarg, "sasl_ssf", len ) == 0 ) {
165 if ( lutil_atou( &sasl_ssf, p ) ) {
166 Debug( LDAP_DEBUG_ANY, "unable to parse sasl_ssf=\"%s\".\n", p, 0, 0 );
170 } else if ( strncasecmp( optarg, "authzDN", len ) == 0 ) {
171 ber_str2bv( p, 0, 1, &authzDN );
173 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
174 } else if ( strncasecmp( optarg, "syslog", len ) == 0 ) {
175 if ( parse_debug_level( p, &ldap_syslog, &syslog_unknowns ) ) {
180 } else if ( strncasecmp( optarg, "syslog-level", len ) == 0 ) {
181 if ( parse_syslog_level( p, &ldap_syslog_level ) ) {
187 } else if ( strncasecmp( optarg, "syslog-user", len ) == 0 ) {
188 if ( parse_syslog_user( p, &syslogUser ) ) {
192 #endif /* LOG_LOCAL4 */
193 #endif /* LDAP_DEBUG && LDAP_SYSLOG */
195 } else if ( strncasecmp( optarg, "schema-check", len ) == 0 ) {
198 if ( strcasecmp( p, "yes" ) == 0 ) {
199 *mode &= ~SLAP_TOOL_NO_SCHEMA_CHECK;
200 } else if ( strcasecmp( p, "no" ) == 0 ) {
201 *mode |= SLAP_TOOL_NO_SCHEMA_CHECK;
203 Debug( LDAP_DEBUG_ANY, "unable to parse schema-check=\"%s\".\n", p, 0, 0 );
209 Debug( LDAP_DEBUG_ANY, "schema-check meaningless for tool.\n", 0, 0, 0 );
213 } else if ( strncasecmp( optarg, "value-check", len ) == 0 ) {
216 if ( strcasecmp( p, "yes" ) == 0 ) {
217 *mode |= SLAP_TOOL_VALUE_CHECK;
218 } else if ( strcasecmp( p, "no" ) == 0 ) {
219 *mode &= ~SLAP_TOOL_VALUE_CHECK;
221 Debug( LDAP_DEBUG_ANY, "unable to parse value-check=\"%s\".\n", p, 0, 0 );
227 Debug( LDAP_DEBUG_ANY, "value-check meaningless for tool.\n", 0, 0, 0 );
231 } else if ( strncasecmp( optarg, "ldif-wrap", len ) == 0 ) {
234 if ( strcasecmp( p, "no" ) == 0 ) {
235 ldif_wrap = LDIF_LINE_WIDTH_MAX;
239 if ( lutil_atou( &u, p ) ) {
240 Debug( LDAP_DEBUG_ANY, "unable to parse ldif-wrap=\"%s\".\n", p, 0, 0 );
243 ldif_wrap = (ber_len_t)u;
248 Debug( LDAP_DEBUG_ANY, "value-check meaningless for tool.\n", 0, 0, 0 );
260 * slap_tool_init - initialize slap utility, handle program options.
264 * argc, argv command line arguments
267 static int need_shutdown;
271 const char* progname,
273 int argc, char **argv )
276 char *conffile = NULL;
277 char *confdir = NULL;
278 struct berval base = BER_BVNULL;
279 char *filterstr = NULL;
280 char *subtree = NULL;
281 char *ldiffile = NULL;
282 char **debug_unknowns = NULL;
284 int mode = SLAP_TOOL_MODE;
285 int truncatemode = 0;
290 /* tools default to "none", so that at least LDAP_DEBUG_ANY
291 * messages show up; use -d 0 to reset */
292 slap_debug = LDAP_DEBUG_NONE;
293 ldif_debug = slap_debug;
298 leakfilename = malloc( strlen( progname ) + STRLENOF( ".leak" ) + 1 );
299 sprintf( leakfilename, "%s.leak", progname );
300 if( ( leakfile = fopen( leakfilename, "w" )) == NULL ) {
303 free( leakfilename );
307 ldif_wrap = LDIF_LINE_WIDTH;
309 scope = LDAP_SCOPE_DEFAULT;
313 options = "b:cd:f:F:gj:l:n:o:qsS:uvw";
317 options = "a:b:cd:f:F:gH:l:n:o:s:v";
318 mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
322 options = "d:f:F:No:Pv";
323 mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
327 options = "b:cd:f:F:gj:l:n:o:qsS:uvw";
331 options = "a:b:cd:f:F:gH:l:n:o:s:v";
332 mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
336 options = "d:f:F:n:o:Quv";
337 mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
341 options = "d:f:F:M:o:R:U:vX:";
342 mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
346 options = "b:cd:f:F:gn:o:qtv";
347 mode |= SLAP_TOOL_READMAIN;
351 options = "b:D:d:f:F:o:uU:vX:";
352 mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
356 fprintf( stderr, "%s: unknown tool mode (%d)\n", progname, tool );
357 exit( EXIT_FAILURE );
361 while ( (i = getopt( argc, argv, options )) != EOF ) {
364 filterstr = ch_strdup( optarg );
368 ber_str2bv( optarg, 0, 1, &base );
371 case 'c': /* enable continue mode */
375 case 'd': { /* turn on debugging */
378 if ( parse_debug_level( optarg, &level, &debug_unknowns ) ) {
379 usage( tool, progname );
383 /* allow to reset log level */
391 fputs( "must compile with LDAP_DEBUG for debugging\n",
397 ber_str2bv( optarg, 0, 1, &authcDN );
400 case 'f': /* specify a conf file */
401 conffile = ch_strdup( optarg );
404 case 'F': /* specify a conf dir */
405 confdir = ch_strdup( optarg );
408 case 'g': /* disable subordinate glue */
416 rc = ldap_url_parse_ext( optarg, &ludp,
417 LDAP_PVT_URL_PARSE_NOEMPTY_HOST | LDAP_PVT_URL_PARSE_NOEMPTY_DN );
418 if ( rc != LDAP_URL_SUCCESS ) {
419 usage( tool, progname );
422 /* don't accept host, port, attrs, extensions */
423 if ( ldap_pvt_url_scheme2proto( ludp->lud_scheme ) != LDAP_PROTO_TCP ) {
424 usage( tool, progname );
427 if ( ludp->lud_host != NULL ) {
428 usage( tool, progname );
431 if ( ludp->lud_port != 0 ) {
432 usage( tool, progname );
435 if ( ludp->lud_attrs != NULL ) {
436 usage( tool, progname );
439 if ( ludp->lud_exts != NULL ) {
440 usage( tool, progname );
443 if ( ludp->lud_dn != NULL && ludp->lud_dn[0] != '\0' ) {
445 subtree = ludp->lud_dn;
449 if ( ludp->lud_filter != NULL && ludp->lud_filter[0] != '\0' ) {
450 filterstr = ludp->lud_filter;
451 ludp->lud_filter = NULL;
454 scope = ludp->lud_scope;
456 ldap_free_urldesc( ludp );
459 case 'j': /* jump to linenumber */
460 if ( lutil_atoul( &jumpline, optarg ) ) {
461 usage( tool, progname );
465 case 'l': /* LDIF file */
466 ldiffile = ch_strdup( optarg );
470 ber_str2bv( optarg, 0, 0, &mech );
474 if ( dn_mode && dn_mode != SLAP_TOOL_LDAPDN_NORMAL ) {
475 usage( tool, progname );
477 dn_mode = SLAP_TOOL_LDAPDN_NORMAL;
480 case 'n': /* which config file db to index */
481 if ( lutil_atoi( &dbnum, optarg ) || dbnum < 0 ) {
482 usage( tool, progname );
487 if ( parse_slapopt( tool, &mode ) ) {
488 usage( tool, progname );
493 if ( dn_mode && dn_mode != SLAP_TOOL_LDAPDN_PRETTY ) {
494 usage( tool, progname );
496 dn_mode = SLAP_TOOL_LDAPDN_PRETTY;
504 case 'q': /* turn on quick */
505 mode |= SLAP_TOOL_QUICK;
513 if ( lutil_atou( &csnsid, optarg )
514 || csnsid > SLAP_SYNC_SID_MAX )
516 usage( tool, progname );
524 /* no schema check */
525 mode |= SLAP_TOOL_NO_SCHEMA_CHECK;
532 subtree = ch_strdup( optarg );
537 case 't': /* turn on truncate */
539 mode |= SLAP_TRUNCATE_MODE;
543 ber_str2bv( optarg, 0, 0, &authcID );
546 case 'u': /* dry run */
550 case 'v': /* turn on verbose */
554 case 'w': /* write context csn at the end */
559 ber_str2bv( optarg, 0, 0, &authzID );
563 usage( tool, progname );
568 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
569 if ( start_syslog ) {
572 logName = ch_strdup( progname );
575 logName = (char *)progname;
579 openlog( logName, OPENLOG_OPTIONS, syslogUser );
580 #elif defined LOG_DEBUG
581 openlog( logName, OPENLOG_OPTIONS );
588 #endif /* LDAP_DEBUG && LDAP_SYSLOG */
606 if ( ( argc != optind ) || (dbnum >= 0 && base.bv_val != NULL ) ) {
607 usage( tool, progname );
613 if ( dbnum >= 0 && base.bv_val != NULL ) {
614 usage( tool, progname );
620 if ( argc == optind ) {
621 usage( tool, progname );
626 if ( argc == optind && BER_BVISNULL( &authcID ) ) {
627 usage( tool, progname );
632 if ( argc != optind ) {
633 usage( tool, progname );
638 if ( !BER_BVISNULL( &authcDN ) && !BER_BVISNULL( &authcID ) ) {
639 usage( tool, progname );
641 if ( BER_BVISNULL( &base ) ) {
642 usage( tool, progname );
644 ber_dupbv( &baseDN, &base );
651 if ( ldiffile == NULL ) {
652 dummy.fp = writer ? stdout : stdin;
655 } else if ((ldiffp = ldif_open( ldiffile, writer ? "w" : "r" ))
659 exit( EXIT_FAILURE );
663 * initialize stuff and figure out which backend we're dealing with
666 rc = slap_init( mode, progname );
668 fprintf( stderr, "%s: slap_init failed!\n", progname );
669 exit( EXIT_FAILURE );
672 rc = read_config( conffile, confdir );
675 fprintf( stderr, "%s: bad configuration %s!\n",
676 progname, confdir ? "directory" : "file" );
677 exit( EXIT_FAILURE );
680 if ( debug_unknowns ) {
681 rc = parse_debug_unknowns( debug_unknowns, &slap_debug );
682 ldap_charray_free( debug_unknowns );
683 debug_unknowns = NULL;
685 exit( EXIT_FAILURE );
688 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
689 if ( syslog_unknowns ) {
690 rc = parse_debug_unknowns( syslog_unknowns, &ldap_syslog );
691 ldap_charray_free( syslog_unknowns );
692 syslog_unknowns = NULL;
694 exit( EXIT_FAILURE );
707 fprintf( stderr, "No databases found "
708 "in config file\n" );
709 exit( EXIT_FAILURE );
718 rc = glue_sub_attach( 0 );
722 "%s: subordinate configuration error\n", progname );
723 exit( EXIT_FAILURE );
727 rc = slap_schema_check();
730 fprintf( stderr, "%s: slap_schema_prep failed!\n", progname );
731 exit( EXIT_FAILURE );
749 filter = str2filter( filterstr );
751 if( filter == NULL ) {
752 fprintf( stderr, "Invalid filter '%s'\n", filterstr );
753 exit( EXIT_FAILURE );
756 ch_free( filterstr );
762 ber_str2bv( subtree, 0, 0, &val );
763 rc = dnNormalize( 0, NULL, NULL, &val, &sub_ndn, NULL );
764 if( rc != LDAP_SUCCESS ) {
765 fprintf( stderr, "Invalid subtree DN '%s'\n", subtree );
766 exit( EXIT_FAILURE );
769 if ( BER_BVISNULL( &base ) && dbnum == -1 ) {
777 if( base.bv_val != NULL ) {
780 rc = dnNormalize( 0, NULL, NULL, &base, &nbase, NULL );
781 if( rc != LDAP_SUCCESS ) {
782 fprintf( stderr, "%s: slap_init invalid suffix (\"%s\")\n",
783 progname, base.bv_val );
784 exit( EXIT_FAILURE );
787 be = select_backend( &nbase, 0 );
788 ber_memfree( nbase.bv_val );
789 BER_BVZERO( &nbase );
792 fprintf( stderr, "%s: slap_init no backend for \"%s\"\n",
793 progname, base.bv_val );
794 exit( EXIT_FAILURE );
804 /* If the named base is a glue master, operate on the
807 if ( SLAP_GLUE_INSTANCE( be ) ) {
811 ch_free( base.bv_val );
814 } else if ( dbnum == -1 ) {
815 /* no suffix and no dbnum specified, just default to
816 * the first available database
818 if ( nbackends <= 0 ) {
819 fprintf( stderr, "No available databases\n" );
820 exit( EXIT_FAILURE );
822 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
825 /* db #0 is cn=config, don't select it as a default */
826 if ( dbnum < 1 ) continue;
828 if ( SLAP_MONITOR(be))
831 /* If just doing the first by default and it is a
832 * glue subordinate, find the master.
834 if ( SLAP_GLUE_SUBORDINATE(be) ) {
842 fprintf( stderr, "Available database(s) "
843 "do not allow %s\n", progname );
844 exit( EXIT_FAILURE );
847 if ( nosubordinates == 0 && dbnum > 1 ) {
848 Debug( LDAP_DEBUG_ANY,
849 "The first database does not allow %s;"
850 " using the first available one (%d)\n",
851 progname, dbnum, 0 );
854 } else if ( dbnum >= nbackends ) {
856 "Database number selected via -n is out of range\n"
857 "Must be in the range 0 to %d"
858 " (the number of configured databases)\n",
860 exit( EXIT_FAILURE );
864 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
865 if ( dbnum == 0 ) break;
870 if ( scope != LDAP_SCOPE_DEFAULT && BER_BVISNULL( &sub_ndn ) ) {
871 if ( be && be->be_nsuffix ) {
872 ber_dupbv( &sub_ndn, be->be_nsuffix );
876 "<scope> needs a DN or a valid database\n" );
877 exit( EXIT_FAILURE );
886 LDAP_STAILQ_FOREACH( bdtmp, &backendDB, be_next ) {
887 if ( bdtmp == be ) break;
896 if ( conffile != NULL ) {
901 if ( confdir != NULL ) {
906 if ( ldiffile != NULL ) {
911 /* slapdn doesn't specify a backend to startup */
912 if ( !dryrun && tool != SLAPDN ) {
915 if ( slap_startup( be ) ) {
918 fprintf( stderr, "slap_startup failed "
919 "(test would succeed using "
920 "the -u switch)\n" );
924 fprintf( stderr, "slap_startup failed\n" );
928 exit( EXIT_FAILURE );
933 int slap_tool_destroy( void )
937 if ( need_shutdown ) {
938 if ( slap_shutdown( be ))
945 if ( slapMode == SLAP_SERVER_MODE ) {
946 /* always false. just pulls in necessary symbol references. */
947 lutil_uuidstr(NULL, 0);
953 ldap_pvt_tls_destroy();
958 mal_dumpleaktrace( leakfile );
961 if ( !BER_BVISNULL( &authcDN ) ) {
962 ch_free( authcDN.bv_val );
963 BER_BVZERO( &authcDN );
966 if ( ldiffp && ldiffp != &dummy ) {
967 ldif_close( ldiffp );
973 slap_tool_update_ctxcsn(
974 const char *progname,
976 struct berval *bvtext )
981 int rc = EXIT_SUCCESS;
983 if ( !(update_ctxcsn && !dryrun && sid != SLAP_SYNC_SID_MAX + 1) ) {
987 if ( SLAP_SYNC_SUBENTRY( be )) {
988 build_new_dn( &ctxdn, &be->be_nsuffix[0],
989 (struct berval *)&slap_ldapsync_cn_bv, NULL );
991 ctxdn = be->be_nsuffix[0];
993 ctxcsn_id = be->be_dn2id_get( be, &ctxdn );
994 if ( ctxcsn_id == NOID ) {
995 if ( SLAP_SYNC_SUBENTRY( be )) {
996 ctxcsn_e = slap_create_context_csn_entry( be, NULL );
997 for ( sid = 0; sid <= SLAP_SYNC_SID_MAX; sid++ ) {
998 if ( maxcsn[ sid ].bv_len ) {
999 attr_merge_one( ctxcsn_e, slap_schema.si_ad_contextCSN,
1000 &maxcsn[ sid ], NULL );
1003 ctxcsn_id = be->be_entry_put( be, ctxcsn_e, bvtext );
1004 if ( ctxcsn_id == NOID ) {
1005 fprintf( stderr, "%s: couldn't create context entry\n", progname );
1008 entry_free( ctxcsn_e );
1010 fprintf( stderr, "%s: context entry is missing\n", progname );
1014 ctxcsn_e = be->be_entry_get( be, ctxcsn_id );
1015 if ( ctxcsn_e != NULL ) {
1016 Operation op = { 0 };
1017 Entry *e = entry_dup( ctxcsn_e );
1018 Attribute *attr = attr_find( e->e_attrs, slap_schema.si_ad_contextCSN );
1022 be_entry_release_r( &op, ctxcsn_e );
1029 for ( i = 0; !BER_BVISNULL( &attr->a_nvals[ i ] ); i++ ) {
1032 const char *text = NULL;
1034 rc_sid = slap_parse_csn_sid( &attr->a_nvals[ i ] );
1036 Debug( LDAP_DEBUG_ANY,
1037 "%s: unable to extract SID "
1038 "from #%d contextCSN=%s\n",
1040 attr->a_nvals[ i ].bv_val );
1044 assert( rc_sid <= SLAP_SYNC_SID_MAX );
1046 sid = (unsigned)rc_sid;
1048 if ( maxcsn[ sid ].bv_len == 0 ) {
1052 value_match( &match, slap_schema.si_ad_entryCSN,
1053 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
1054 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
1055 &maxcsn[ sid ], &attr->a_nvals[i], &text );
1061 AC_MEMCPY( maxcsn[ sid ].bv_val,
1062 attr->a_nvals[ i ].bv_val,
1063 attr->a_nvals[ i ].bv_len );
1064 maxcsn[ sid ].bv_val[ attr->a_nvals[ i ].bv_len ] = '\0';
1065 maxcsn[ sid ].bv_len = attr->a_nvals[ i ].bv_len;
1070 if ( attr->a_nvals != attr->a_vals ) {
1071 ber_bvarray_free( attr->a_nvals );
1073 attr->a_nvals = NULL;
1074 ber_bvarray_free( attr->a_vals );
1075 attr->a_vals = NULL;
1076 attr->a_numvals = 0;
1083 for ( sid = 0; sid <= SLAP_SYNC_SID_MAX; sid++ ) {
1084 if ( maxcsn[ sid ].bv_len ) {
1085 attr_merge_one( e, slap_schema.si_ad_contextCSN,
1086 &maxcsn[ sid], NULL );
1090 ctxcsn_id = be->be_entry_modify( be, e, bvtext );
1091 if( ctxcsn_id == NOID ) {
1092 fprintf( stderr, "%s: could not modify ctxcsn (%s)\n",
1093 progname, bvtext->bv_val ? bvtext->bv_val : "" );
1095 } else if ( verbose ) {
1096 fprintf( stderr, "modified: \"%s\" (%08lx)\n",
1097 e->e_dn, (long) ctxcsn_id );
1109 * -1: update_ctxcsn == 0
1110 * SLAP_SYNC_SID_MAX + 1: unable to extract SID
1111 * 0 <= SLAP_SYNC_SID_MAX: the SID
1114 slap_tool_update_ctxcsn_check(
1115 const char *progname,
1118 if ( update_ctxcsn ) {
1119 unsigned long sid = SLAP_SYNC_SID_MAX + 1;
1123 attr = attr_find( e->e_attrs, slap_schema.si_ad_entryCSN );
1124 assert( attr != NULL );
1126 rc_sid = slap_parse_csn_sid( &attr->a_nvals[ 0 ] );
1128 Debug( LDAP_DEBUG_ANY, "%s: could not "
1129 "extract SID from entryCSN=%s, entry dn=\"%s\"\n",
1130 progname, attr->a_nvals[ 0 ].bv_val, e->e_name.bv_val );
1131 return (unsigned long)(-1);
1135 const char *text = NULL;
1137 assert( rc_sid <= SLAP_SYNC_SID_MAX );
1139 sid = (unsigned)rc_sid;
1140 if ( maxcsn[ sid ].bv_len != 0 ) {
1142 value_match( &match, slap_schema.si_ad_entryCSN,
1143 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
1144 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
1145 &maxcsn[ sid ], &attr->a_nvals[0], &text );
1150 strcpy( maxcsn[ sid ].bv_val, attr->a_nvals[0].bv_val );
1151 maxcsn[ sid ].bv_len = attr->a_nvals[0].bv_len;
1156 return (unsigned long)(-1);
1160 slap_tool_update_ctxcsn_init(void)
1162 if ( update_ctxcsn ) {
1164 maxcsn[ 0 ].bv_val = maxcsnbuf;
1165 for ( sid = 1; sid <= SLAP_SYNC_SID_MAX; sid++ ) {
1166 maxcsn[ sid ].bv_val = maxcsn[ sid - 1 ].bv_val + LDAP_PVT_CSNSTR_BUFSIZE;
1167 maxcsn[ sid ].bv_len = 0;
1175 slap_tool_entry_check(
1176 const char *progname,
1184 /* NOTE: we may want to conditionally enable manage */
1187 Attribute *oc = attr_find( e->e_attrs,
1188 slap_schema.si_ad_objectClass );
1191 fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
1192 progname, e->e_dn, lineno,
1193 "no objectClass attribute");
1194 return LDAP_NO_SUCH_ATTRIBUTE;
1200 if ( (slapMode & SLAP_TOOL_NO_SCHEMA_CHECK) == 0) {
1201 int rc = entry_schema_check( op, e, NULL, manage, 1, NULL,
1202 text, textbuf, textlen );
1204 if( rc != LDAP_SUCCESS ) {
1205 fprintf( stderr, "%s: dn=\"%s\" (line=%d): (%d) %s\n",
1206 progname, e->e_dn, lineno, rc, *text );
1209 textbuf[ 0 ] = '\0';
1212 if ( (slapMode & SLAP_TOOL_VALUE_CHECK) != 0) {
1213 Modifications *ml = NULL;
1215 int rc = slap_entry2mods( e, &ml, text, textbuf, textlen );
1216 if ( rc != LDAP_SUCCESS ) {
1217 fprintf( stderr, "%s: dn=\"%s\" (line=%d): (%d) %s\n",
1218 progname, e->e_dn, lineno, rc, *text );
1221 textbuf[ 0 ] = '\0';
1223 rc = slap_mods_check( op, ml, text, textbuf, textlen, NULL );
1224 slap_mods_free( ml, 1 );
1225 if ( rc != LDAP_SUCCESS ) {
1226 fprintf( stderr, "%s: dn=\"%s\" (line=%d): (%d) %s\n",
1227 progname, e->e_dn, lineno, rc, *text );
1230 textbuf[ 0 ] = '\0';
1233 return LDAP_SUCCESS;