From a75cb8813684da0cd7c2f1782a1a17fd97123f17 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Wed, 16 Aug 2000 21:28:58 +0000 Subject: [PATCH] Import latest changes from devel --- build/openldap.m4 | 12 +- clients/finger/main.c | 8 +- doc/man/man5/slapd.conf.5 | 53 +++-- doc/man/man8/in.xfingerd.8 | 7 +- doc/man/man8/slapadd.8 | 4 +- doc/man/man8/slapcat.8 | 4 +- doc/man/man8/slapd.8 | 30 ++- doc/man/man8/slapindex.8 | 4 +- doc/man/man8/slappasswd.8 | 4 +- doc/man/man8/slurpd.8 | 6 +- include/ldap_pvt.h | 2 + libraries/liblber/memory.c | 6 - libraries/libldap/cyrus.c | 9 +- libraries/libldap/init.c | 10 +- libraries/libldap/os-ip.c | 11 + libraries/libldap/sasl.c | 2 +- libraries/libldap/util-int.c | 31 +++ libraries/libldbm/ldbm.c | 12 +- libraries/liblutil/authpasswd.c | 8 +- libraries/liblutil/passwd.c | 8 +- servers/slapd/back-ldbm/filterindex.c | 27 ++- servers/slapd/back-ldbm/idl.c | 1 - servers/slapd/back-ldbm/modify.c | 25 +- .../rdbms_depend/mssql/testdb_metadata.sql | 180 +++++++++++++++ .../rdbms_depend/mysql/testdb_metadata.sql | 74 ++++++ .../rdbms_depend/oracle/testdb_metadata.sql | 214 ++++++++++++++++++ servers/slapd/sasl.c | 15 +- servers/slapd/schema_init.c | 5 +- servers/slurpd/Makefile.in | 1 + servers/slurpd/slurp.h | 4 +- 30 files changed, 669 insertions(+), 108 deletions(-) create mode 100644 servers/slapd/back-sql/rdbms_depend/mssql/testdb_metadata.sql create mode 100644 servers/slapd/back-sql/rdbms_depend/mysql/testdb_metadata.sql create mode 100644 servers/slapd/back-sql/rdbms_depend/oracle/testdb_metadata.sql diff --git a/build/openldap.m4 b/build/openldap.m4 index a12b0a2577..2db4042fb0 100644 --- a/build/openldap.m4 +++ b/build/openldap.m4 @@ -317,14 +317,17 @@ main() int rc; u_int32_t flags = DB_CREATE | DB_THREAD; - #if DB_VERSION_MAJOR > 2 DB_ENV *env = NULL; rc = db_env_create( &env, 0 ); if( rc == 0 ) { +#if (DB_VERSION_MAJOR > 3) || (DB_VERSION_MINOR >= 1) + rc = env->open( env, NULL, flags, 0 ); +#else rc = env->open( env, NULL, NULL, flags, 0 ); +#endif } #else @@ -336,6 +339,13 @@ main() if( rc == 0 ) { db_appexit( &env ); } +#endif +#if DB_VERSION_MAJOR > 2 +#if (DB_VERSION_MAJOR > 3) || (DB_VERSION_MINOR >= 1) + env->remove( env, NULL, DB_FORCE); +#else + env->remove( env, NULL, NULL, DB_FORCE); +#endif #endif return rc; diff --git a/clients/finger/main.c b/clients/finger/main.c index 5e8111633e..bc02da053a 100644 --- a/clients/finger/main.c +++ b/clients/finger/main.c @@ -52,7 +52,7 @@ static void do_read(LDAP *ld, LDAPMessage *e); static void usage( char *name ) { - fprintf( stderr, "usage: %s [-l] [-x ldaphost] [-p ldapport] [-f filterfile] [-t templatefile] [-c rdncount]\r\n", name ); + fprintf( stderr, "usage: %s [-l] [-x ldaphost] [-p ldapport] [-b searchbase] [-f filterfile] [-t templatefile] [-c rdncount]\r\n", name ); exit( EXIT_FAILURE ); } @@ -67,7 +67,7 @@ main( int argc, char **argv ) int interactive = 0; deref = FINGER_DEREF; - while ( (i = getopt( argc, argv, "f:ilp:t:x:p:c:" )) != EOF ) { + while ( (i = getopt( argc, argv, "f:ilp:t:x:p:b:c:" )) != EOF ) { switch( i ) { case 'f': /* ldap filter file */ filterfile = strdup( optarg ); @@ -93,6 +93,10 @@ main( int argc, char **argv ) ldapport = atoi( optarg ); break; + case 'b': /* specify search base */ + base = strdup( optarg ); + break; + case 'c': /* specify number of DN components to show */ rdncount = atoi( optarg ); break; diff --git a/doc/man/man5/slapd.conf.5 b/doc/man/man5/slapd.conf.5 index 5b101652f2..a86c8aa22d 100644 --- a/doc/man/man5/slapd.conf.5 +++ b/doc/man/man5/slapd.conf.5 @@ -1,4 +1,4 @@ -.TH SLAPD.CONF 5 "5 August 1999" "OpenLDAP LDVERSION" +.TH SLAPD.CONF 5 "13 August 2000" "OpenLDAP LDVERSION" .\" $OpenLDAP$ .\" Copyright 1998-2000 The OpenLDAP Foundation All Rights Reserved. .\" Copying restrictions apply. See COPYRIGHT/LICENSE. @@ -66,18 +66,19 @@ Options described in this section apply to all backends, unless specifically overridden in a backend definition. Arguments that should be replaced by actual text are shown in brackets <>. .TP -.B -access to [ by ]+ +.B access to [ by ]+ Grant access (specified by ) to a set of entries and/or attributes (specified by ) by one or more requestors (specified by ). See Developer's FAQ (http://www.openldap.org/faq/) for details. -.TP -.B -attributetype ( [NAME ] [DESC ] \ -[OBSOLETE] [SUP ] [EQUALITY ] [ORDERING ] \ -[SUBSTR ] [SYNTAX ] [SINGLE\-VALUE] [COLLECTIVE] \ -[NO\-USER\-MODIFICATION] [USAGE ] ) +.HP +.hy 0 +.B attributetype (\ [NAME\ ] [OBSOLETE]\ + [DESC\ ]\ + [SUP\ ] [EQUALITY\ ] [ORDERING\ ]\ + [SUBSTR\ ] [SYNTAX\ ] [SINGLE\-VALUE] [COLLECTIVE]\ + [NO\-USER\-MODIFICATION] [USAGE\ ]\ ) +.RS Specify an attribute type using the LDAPv3 syntax defined in RFC 2252. The slapd parser extends the RFC 2252 definition by allowing string forms as well as numeric OIDs to be used for the attribute OID and @@ -102,19 +103,21 @@ SubstringAssertion NISnetgrouptriple Bootparameter .PD .RE .RE +.RE .TP .B concurrency Specify a desired level of concurrency. Provided to the underlying thread system as a hint. The default is not to provdide any hint. -.TP -.B -defaultaccess { none | auth | compare | search | read | write } +.HP +.B defaultaccess { none | auth | compare | search | read | write } +.RS Specify the default access level to grant requestors when no access directives were provided for the database. The default behavior is to grant 'read' access. It is recommended that .B access directives be used instead. +.RE .TP .B idletimeout Specify the number of seconds to wait before forcibly closing @@ -186,11 +189,11 @@ entry parsing .PD .RE .RE -.TP -.B -objectclass ( [NAME ] [DESC ] [{ ABSTRACT | STRUCTURAL | AUXILIARY }] [MUST ] \ -[MAY ] ) +.HP +.B objectclass ( [NAME ] [DESC ] [{ ABSTRACT | STRUCTURAL | AUXILIARY }] [MUST ]\ + [MAY ] ) +.RS Specify an objectclass using the LDAPv3 syntax defined in RFC 2252. The slapd parser extends the RFC 2252 definition by allowing string forms as well as numeric OIDs to be used for the object class OID. @@ -198,6 +201,7 @@ forms as well as numeric OIDs to be used for the object class OID. .B objectidentifier description.) Object classes are "STRUCTURAL" by default. +.RE .TP .B objectidentifier { | [:] } Define a string name that equates to the given OID. The string can be used @@ -280,17 +284,16 @@ createTimestamp attributes for entries. By default, lastmod is on. This option puts the database into "read-only" mode. Any attempts to modify the database will return an "unwilling to perform" error. By default, readonly is off. -.TP -.B -replica host=[:port] "binddn=" bindmethod=simple | -.B -kerberos [credentials=] [srvtab=] -.br +.HP +.B replica host=[:port] "binddn=" bindmethod=simple |\ + kerberos [credentials=] [srvtab= ] +.RS Specify a replication site for this database. Refer to "The SLAPD and SLURPD Administrator's Guide" for detailed information on setting up a replicated .B slapd directory service. +.RE .TP .B replogfile Specify the name of the replication log file to log changes to. @@ -417,7 +420,7 @@ file. Specifies an alternate passwd file to use. The default is .B /etc/passwd. .SH EXAMPLE -"The SLAPD and SLURPD Administrator's Guide" contains an annotated +"OpenLDAP Administrator's Guide" contains an annotated example of a configuration file. .SH FILES ETCDIR/slapd.conf @@ -433,7 +436,7 @@ ETCDIR/slapd.conf .BR slappassword (8), .BR slurpd (8), .LP -"The SLAPD and SLURPD Administrator's Guide" +"OpenLDAP Administrator's Guide" .SH ACKNOWLEDGEMENTS .B OpenLDAP is developed and maintained by The OpenLDAP Project (http://www.openldap.org/). diff --git a/doc/man/man8/in.xfingerd.8 b/doc/man/man8/in.xfingerd.8 index 5f65271896..0baa476b94 100644 --- a/doc/man/man8/in.xfingerd.8 +++ b/doc/man/man8/in.xfingerd.8 @@ -1,4 +1,4 @@ -.TH IN.XFINGERD 8C "22 September 1998" "OpenLDAP LDVERSION" +.TH IN.XFINGERD 8C "16 August 200" "OpenLDAP LDVERSION" .\" $OpenLDAP$ .\" Copyright 1998-2000 The OpenLDAP Foundation All Rights Reserved. .\" Copying restrictions apply. See COPYRIGHT/LICENSE. @@ -7,7 +7,7 @@ in.xfingerd \- Finger to LDAP/X.500 gateway daemon .SH SYNOPSIS .B LIBEXECDIR/in.xfingerd [\-f filterfile] [\-i] .B [\-l] [\-t templatefile] [\-c rdncount] [\-x hostname] -.B [\-p port] +.B [\-b searchbase] [\-p port] .SH DESCRIPTION .B in.xfingerd is the LDAP/X.500 finger daemon. It runs from @@ -66,6 +66,9 @@ Specify an alternate host on which the ldap server is running. .TP .BI \-p " port" Specify an alternate port on which the ldap server is listening. +.TP +.BI \-b " searchbase" +Specify an alternate search base for queries. .SH NOTES The default values for most of the things you can specify with options are configured at compile time in the diff --git a/doc/man/man8/slapadd.8 b/doc/man/man8/slapadd.8 index 3c066c2cf7..9359ab0d9f 100644 --- a/doc/man/man8/slapadd.8 +++ b/doc/man/man8/slapadd.8 @@ -1,4 +1,4 @@ -.TH SLAPADD 8C "17 August 1999" "OpenLDAP LDVERSION" +.TH SLAPADD 8C "13 August 2000" "OpenLDAP LDVERSION" .\" $OpenLDAP$ .\" Copyright 1998-2000 The OpenLDAP Foundation All Rights Reserved. .\" Copying restrictions apply. See COPYRIGHT/LICENSE. @@ -96,6 +96,8 @@ database give the command: .BR slapcat (8), .BR ldapadd (1), .BR slapd (8) +.LP +"OpenLDAP Administrator's Guide" .SH ACKNOWLEDGEMENTS .B OpenLDAP is developed and maintained by The OpenLDAP Project (http://www.openldap.org/). diff --git a/doc/man/man8/slapcat.8 b/doc/man/man8/slapcat.8 index 3b0faea380..49499a68ac 100644 --- a/doc/man/man8/slapcat.8 +++ b/doc/man/man8/slapcat.8 @@ -1,4 +1,4 @@ -.TH SLAPCAT 8C "17 August 1999" "OpenLDAP LDVERSION" +.TH SLAPCAT 8C "13 August 2000" "OpenLDAP LDVERSION" .\" $OpenLDAP$ .\" Copyright 1998-2000 The OpenLDAP Foundation All Rights Reserved. .\" Copying restrictions apply. See COPYRIGHT/LICENSE. @@ -85,6 +85,8 @@ give the command: .BR slapadd (8), .BR ldapadd (1), .BR slapd (8) +.LP +"OpenLDAP Administrator's Guide" .SH ACKNOWLEDGEMENTS .B OpenLDAP is developed and maintained by The OpenLDAP Project (http://www.openldap.org/). diff --git a/doc/man/man8/slapd.8 b/doc/man/man8/slapd.8 index 1e353dd3b5..e84476f4da 100644 --- a/doc/man/man8/slapd.8 +++ b/doc/man/man8/slapd.8 @@ -1,4 +1,4 @@ -.TH SLAPD 8C "19 September 1999" "OpenLDAP LDVERSION" +.TH SLAPD 8C "13 August 2000" "OpenLDAP LDVERSION" .\" $OpenLDAP$ .\" Copyright 1998-2000 The OpenLDAP Foundation All Rights Reserved. .\" Copying restrictions apply. See COPYRIGHT/LICENSE. @@ -10,6 +10,7 @@ slapd \- Stand-alone LDAP Daemon .B [\-h URLs] .B [\-d debug\-level] .B [\-n service\-name] [\-s syslog\-level] [\-l syslog\-local\-user] +.B [\-r directory] .B [\-u user] [\-g group] .B .SH DESCRIPTION @@ -100,19 +101,28 @@ Specifies the slapd configuration file. The default is .B slapd will serve .B ldap:/// -(LDAP over TCP on all interfaces on default LDAP port). As such, -it will bind to INADDR_ANY, port 389. +(LDAP over TCP on all interfaces on default LDAP port). That is, +it will bind to using INADDR_ANY and port 389. The .B \-h option may be used to specify LDAP (and LDAPS) URLs to serve. For example, if slapd is given -.B \-h " ldap://127.0.0.1:9009/ ldaps:///", -It will bind 127.0.0.1:9009 for LDAP and INADDR_ANY:636 for LDAP over TLS. +.B \-h " ldap://127.0.0.1:9009/ ldaps:/// ldapi:///", +It will bind 127.0.0.1:9009 for LDAP, INADDR_ANY:636 for LDAP over TLS, +and LDAP over IPC (Unix domain sockets). A space separated list of URLs is expected. The URLS should be of -LDAP (ldap://) or, if supported, LDAP over TLS (ldaps://) type without -a DN or other optional parameters. Hosts may be specified in either -Internet '.' format (preferred) or by name. Ports, if specfied, -must be numeric. +LDAP (ldap://) or LDAP over TLS (ldaps://) or LDAP over IPC (ldapi://) +scheme without a DN or other optional parameters. Support for the +latter two schemes depends on selected configuration options. Hosts +may be specified by name or IPv4 and IPv6 address formats. +Ports, if specfied, must be numeric. The default ldap:// port is 389 +and the default ldaps:// port is 636. +.TP +.BI \-r " directory" +Specifies a run-time directory. slapd will +.BR chroot (2) +to this directory after opening listeners but before any reading +any configuration file or initializing any backend. .TP .BI \-u " user" .B slapd @@ -156,7 +166,7 @@ on voluminous debugging which will be printed on standard error, type: .BR slapd.conf (5), .BR slurpd (8) .LP -"The SLAPD and SLURPD Administrator's Guide" +"OpenLDAP Administrator's Guide" .SH BUGS See http://www.openldap.org/its/ .SH ACKNOWLEDGEMENTS diff --git a/doc/man/man8/slapindex.8 b/doc/man/man8/slapindex.8 index b94fc7dbee..32334bf845 100644 --- a/doc/man/man8/slapindex.8 +++ b/doc/man/man8/slapindex.8 @@ -1,4 +1,4 @@ -.TH SLAPINDEX 8C "17 July 1999" "OpenLDAP LDVERSION" +.TH SLAPINDEX 8C "13 August 2000" "OpenLDAP LDVERSION" .\" $OpenLDAP$ .\" Copyright 1998-2000 The OpenLDAP Foundation All Rights Reserved. .\" Copying restrictions apply. See COPYRIGHT/LICENSE. @@ -76,6 +76,8 @@ To reindex your SLAPD database, give the command: .BR slapadd (8), .BR ldapadd (1), .BR slapd (8) +.LP +"OpenLDAP Administrator's Guide" .SH ACKNOWLEDGEMENTS .B OpenLDAP is developed and maintained by The OpenLDAP Project (http://www.openldap.org/). diff --git a/doc/man/man8/slappasswd.8 b/doc/man/man8/slappasswd.8 index 706125a18a..bfe842d683 100644 --- a/doc/man/man8/slappasswd.8 +++ b/doc/man/man8/slappasswd.8 @@ -1,4 +1,4 @@ -.TH SLAPPASSWD 8C "15 June 2000" "OpenLDAP LDVERSION" +.TH SLAPPASSWD 8C "13 August 2000" "OpenLDAP LDVERSION" .\" $OpenLDAP$ .\" Copyright 1998-2000 The OpenLDAP Foundation All Rights Reserved. .\" Copying restrictions apply. See COPYRIGHT/LICENSE. @@ -62,6 +62,8 @@ were clear text passwords. .BR ldappasswd (1), .BR ldapmodify (1), .BR slapd (8) +.LP +"OpenLDAP Administrator's Guide" .SH ACKNOWLEDGEMENTS .B OpenLDAP is developed and maintained by The OpenLDAP Project (http://www.openldap.org/). diff --git a/doc/man/man8/slurpd.8 b/doc/man/man8/slurpd.8 index 2b8fea8b5d..b4fd42a153 100644 --- a/doc/man/man8/slurpd.8 +++ b/doc/man/man8/slurpd.8 @@ -1,4 +1,4 @@ -.TH SLURPD 8C "22 September 1998" "OpenLDAP LDVERSION" +.TH SLURPD 8C "13 August 2000" "OpenLDAP LDVERSION" .\" $OpenLDAP$ .\" Copyright 1998-2000 The OpenLDAP Foundation All Rights Reserved. .\" Copying restrictions apply. See COPYRIGHT/LICENSE. @@ -109,7 +109,7 @@ processes a replication log and exits. copies the replication log to a working directory before processing it. This option allows you to specify the location of these temporary files. The default is -.BR /usr/tmp . +.BR LOCALSTATEDIR/openldap-slurp . .TP .BI \-k " srvtab\-file" Specify the location of the kerberos srvtab file which contains keys @@ -151,7 +151,7 @@ on voluminous debugging which will be printed on standard error, type: .BR slapd.replog (5), .BR slapd (8) .LP -"The SLAPD and SLURPD Administrator's Guide" +"OpenLDAP Administrator's Guide" .SH ACKNOWLEDGEMENTS .B OpenLDAP is developed and maintained by The OpenLDAP Project (http://www.openldap.org/). diff --git a/include/ldap_pvt.h b/include/ldap_pvt.h index 92e287cdfd..5a2fa336cd 100644 --- a/include/ldap_pvt.h +++ b/include/ldap_pvt.h @@ -45,6 +45,8 @@ ldap_pvt_ctime LDAP_P(( const time_t *tp, char *buf )); +LDAP_F( char *) ldap_pvt_get_fqdn LDAP_P(( char * )); + LDAP_F( int ) ldap_pvt_gethostbyname_a LDAP_P(( const char *name, diff --git a/libraries/liblber/memory.c b/libraries/liblber/memory.c index 861dd3a23a..b908c40b7d 100644 --- a/libraries/liblber/memory.c +++ b/libraries/liblber/memory.c @@ -498,12 +498,6 @@ ber_bvstr( return NULL; } - if ( *s == '\0' ) { - new->bv_val = NULL; - new->bv_len = 0; - return new; - } - new->bv_val = (char *) s; new->bv_len = strlen( s ); diff --git a/libraries/libldap/cyrus.c b/libraries/libldap/cyrus.c index 0320f7bbc8..c63bc37da7 100644 --- a/libraries/libldap/cyrus.c +++ b/libraries/libldap/cyrus.c @@ -555,6 +555,13 @@ ldap_int_sasl_bind( } if ( rc != LDAP_SUCCESS && rc != LDAP_SASL_BIND_IN_PROGRESS ) { + if( scred ) { + /* and server provided us with data? */ + Debug( LDAP_DEBUG_TRACE, + "ldap_int_sasl_bind: rc=%d sasl=%d len=%ld\n", + rc, saslrc, scred->bv_len ); + ber_bvfree( scred ); + } return ld->ld_errno; } @@ -609,8 +616,6 @@ ldap_int_sasl_bind( return ld->ld_errno = sasl_err2ldap( saslrc ); } - /* likely should add a quiet option */ - if( flags != LDAP_SASL_QUIET ) { saslrc = sasl_getprop( ctx, SASL_USERNAME, (void **) &data ); if( saslrc == SASL_OK && data && *data ) { diff --git a/libraries/libldap/init.c b/libraries/libldap/init.c index 164761b6ed..1941a8b980 100644 --- a/libraries/libldap/init.c +++ b/libraries/libldap/init.c @@ -427,7 +427,7 @@ void ldap_int_initialize_global_options( struct ldapoptions *gopts, int *dbglvl #if defined(LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND) \ || defined(HAVE_TLS) || defined(HAVE_CYRUS_SASL) -char * ldap_int_hostname = "localhost"; +char * ldap_int_hostname = NULL; #endif void ldap_int_initialize( struct ldapoptions *gopts, int *dbglvl ) @@ -438,13 +438,7 @@ void ldap_int_initialize( struct ldapoptions *gopts, int *dbglvl ) #if defined(LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND) \ || defined(HAVE_TLS) || defined(HAVE_CYRUS_SASL) - { - char hostbuf[MAXHOSTNAMELEN+1]; - if( gethostname( hostbuf, MAXHOSTNAMELEN ) == 0 ) { - hostbuf[MAXHOSTNAMELEN] = '\0'; - ldap_int_hostname = hostbuf; - } - } + ldap_int_hostname = ldap_pvt_get_fqdn( ldap_int_hostname ); #endif ldap_int_utils_init(); diff --git a/libraries/libldap/os-ip.c b/libraries/libldap/os-ip.c index c2143561a1..cf7f322e76 100644 --- a/libraries/libldap/os-ip.c +++ b/libraries/libldap/os-ip.c @@ -473,6 +473,17 @@ ldap_host_connected_to( Sockbuf *sb ) { return LDAP_STRDUP( ldap_int_hostname ); } + +#ifdef INADDR_LOOPBACK + localhost.sin_addr.s_addr = htonl( INADDR_LOOPBACK ); + + if( memcmp ( &localhost.sin_addr, + &((struct sockaddr_in *)&sa)->sin_addr, + sizeof(localhost.sin_addr) ) == 0 ) + { + return LDAP_STRDUP( ldap_int_hostname ); + } +#endif } break; diff --git a/libraries/libldap/sasl.c b/libraries/libldap/sasl.c index a98f41e205..1c74713da6 100644 --- a/libraries/libldap/sasl.c +++ b/libraries/libldap/sasl.c @@ -357,7 +357,7 @@ ldap_pvt_sasl_getmechs ( LDAP *ld, char **pmechlist ) Debug( LDAP_DEBUG_TRACE, "ldap_pvt_sasl_getmech\n", 0, 0, 0 ); - rc = ldap_search_s( ld, NULL, LDAP_SCOPE_BASE, + rc = ldap_search_s( ld, "", LDAP_SCOPE_BASE, NULL, attrs, 0, &res ); if ( rc != LDAP_SUCCESS ) { diff --git a/libraries/libldap/util-int.c b/libraries/libldap/util-int.c index 126b573cb2..0cc70589d6 100644 --- a/libraries/libldap/util-int.c +++ b/libraries/libldap/util-int.c @@ -142,6 +142,7 @@ int ldap_pvt_gethostbyname_a( # define NEED_COPY_HOSTENT struct hostent *he; int retval; + *buf = NULL; ldap_pvt_thread_mutex_lock( &ldap_int_gethostby_mutex ); @@ -162,6 +163,7 @@ int ldap_pvt_gethostbyname_a( return retval; #else + *buf = NULL; *result = gethostbyname( name ); if (*result!=NULL) { @@ -221,6 +223,7 @@ int ldap_pvt_gethostbyaddr_a( # define NEED_COPY_HOSTENT struct hostent *he; int retval; + *buf = NULL; ldap_pvt_thread_mutex_lock( &ldap_int_gethostby_mutex ); @@ -241,6 +244,7 @@ int ldap_pvt_gethostbyaddr_a( return retval; #else /* gethostbyaddr() */ + *buf = NULL; *result = gethostbyaddr( addr, len, type ); if (*result!=NULL) { @@ -377,4 +381,31 @@ static char *safe_realloc( char **buf, int len ) } #endif +char * ldap_pvt_get_fqdn( char *name ) +{ + char *fqdn, *ha_buf; + char hostbuf[MAXHOSTNAMELEN+1]; + struct hostent *hp, he_buf; + int rc, local_h_errno; + + if( name == NULL ) { + if( gethostname( hostbuf, MAXHOSTNAMELEN ) == 0 ) { + hostbuf[MAXHOSTNAMELEN] = '\0'; + name = hostbuf; + } else { + name = "localhost"; + } + } + + rc = ldap_pvt_gethostbyname_a( name, + &he_buf, &ha_buf, &hp, &local_h_errno ); + + if( rc < 0 || hp == NULL || hp->h_name == NULL ) { + fqdn = LDAP_STRDUP( name ); + } else { + fqdn = LDAP_STRDUP( hp->h_name ); + } + LDAP_FREE( ha_buf ); + return fqdn; +} diff --git a/libraries/libldbm/ldbm.c b/libraries/libldbm/ldbm.c index 8b857f630d..951e06b276 100644 --- a/libraries/libldbm/ldbm.c +++ b/libraries/libldbm/ldbm.c @@ -145,12 +145,17 @@ int ldbm_initialize( void ) return( 1 ); } -#if DB_VERSION_MAJOR >= 3 +#if DB_VERSION_MAJOR > 2 ldbm_Env->set_errcall( ldbm_Env, ldbm_db_errcall ); ldbm_Env->set_errpfx( ldbm_Env, "==>" ); envFlags |= DB_INIT_MPOOL; + +#if (DB_VERSION_MAJOR > 3) || (DB_VERSION_MINOR >= 1) + err = ldbm_Env->open( ldbm_Env, NULL, envFlags, 0 ); +#else err = ldbm_Env->open( ldbm_Env, NULL, NULL, envFlags, 0 ); +#endif if ( err != 0 ) { char error[BUFSIZ]; @@ -175,7 +180,7 @@ int ldbm_shutdown( void ) if( !ldbm_initialized ) return 1; #if DB_VERSION_MAJOR >= 3 - ldbm_Env->close( ldbm_Env, 0 ); + ldbm_Env->close( ldbm_Env, 0 ); #else db_appexit( ldbm_Env ); #endif @@ -253,8 +258,7 @@ ldbm_open( char *name, int rw, int mode, int dbcachesize ) memset( &dbinfo, '\0', sizeof( dbinfo )); -#if defined( DB_VERSION_MAJOR ) && defined( DB_VERSION_MINOR ) && \ - DB_VERSION_MAJOR == 2 && DB_VERSION_MINOR == 4 +#if DB_VERSION_MAJOR == 2 && DB_VERSION_MINOR == 4 /* * BerkeleyDB 2.4 do not allow db_cachesize * to be specified if an DB_ENV is. diff --git a/libraries/liblutil/authpasswd.c b/libraries/liblutil/authpasswd.c index e179f32dbc..b7dab5a25d 100644 --- a/libraries/liblutil/authpasswd.c +++ b/libraries/liblutil/authpasswd.c @@ -609,18 +609,18 @@ static int chk_kerberos( } { - char host[MAXHOSTNAMELEN+1]; + char *host = ldap_pvt_get_fqdn( NULL ); - if( gethostname( host, MAXHOSTNAMELEN ) != 0 ) { + if( host == NULL ) { krb5_free_principal( context, client ); krb5_free_context( context ); return 1; } - host[MAXHOSTNAMELEN] = '\0'; - ret = krb5_sname_to_principal( context, host, "ldap", KRB5_NT_SRV_HST, &server ); + + ber_memfree( host ); } if (ret) { diff --git a/libraries/liblutil/passwd.c b/libraries/liblutil/passwd.c index 68c2709ab6..eca2ff12b1 100644 --- a/libraries/liblutil/passwd.c +++ b/libraries/liblutil/passwd.c @@ -726,18 +726,18 @@ static int chk_kerberos( } { - char host[MAXHOSTNAMELEN+1]; + char *host = ldap_pvt_get_fqdn( NULL ); - if( gethostname( host, MAXHOSTNAMELEN ) != 0 ) { + if( host == NULL ) { krb5_free_principal( context, client ); krb5_free_context( context ); return 1; } - host[MAXHOSTNAMELEN] = '\0'; - ret = krb5_sname_to_principal( context, host, "ldap", KRB5_NT_SRV_HST, &server ); + + ber_memfree( host ); } if (ret) { diff --git a/servers/slapd/back-ldbm/filterindex.c b/servers/slapd/back-ldbm/filterindex.c index 59acdb94a1..674910ddb8 100644 --- a/servers/slapd/back-ldbm/filterindex.c +++ b/servers/slapd/back-ldbm/filterindex.c @@ -133,6 +133,7 @@ presence_candidates( if( dbname == NULL ) { /* not indexed */ + ber_bvfree( prefix ); return idl; } @@ -142,6 +143,7 @@ presence_candidates( Debug( LDAP_DEBUG_ANY, "<= presense_candidates db open failed (%s%s)\n", dbname, LDBM_SUFFIX, 0 ); + ber_bvfree( prefix ); return idl; } @@ -152,17 +154,19 @@ presence_candidates( rc = key_read( be, db, prefix, &idl ); if( rc != LDAP_SUCCESS ) { - Debug( LDAP_DEBUG_TRACE, "<= presense_candidates key read failed (%d)\n", + Debug( LDAP_DEBUG_TRACE, + "<= presense_candidates key read failed (%d)\n", rc, 0, 0 ); } else if( idl == NULL ) { - Debug( LDAP_DEBUG_TRACE, "<= presense_candidates NULL\n", + Debug( LDAP_DEBUG_TRACE, + "<= presense_candidates NULL\n", 0, 0, 0 ); } } ldbm_cache_close( be, db ); - + ber_bvfree( prefix ); Debug( LDAP_DEBUG_TRACE, "<= presence_candidates %ld\n", idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 ); @@ -198,16 +202,19 @@ equality_candidates( if( dbname == NULL ) { /* not indexed */ + ber_bvfree( prefix ); return idl; } mr = ava->aa_desc->ad_type->sat_equality; if( !mr ) { + ber_bvfree( prefix ); /* return LDAP_INAPPROPRIATE_MATCHING; */ return idl; } if( !mr->smr_filter ) { + ber_bvfree( prefix ); return idl; } @@ -219,6 +226,8 @@ equality_candidates( ava->aa_value, &keys ); + ber_bvfree( prefix ); + if( rc != LDAP_SUCCESS ) { return idl; } @@ -241,7 +250,8 @@ equality_candidates( if( rc != LDAP_SUCCESS ) { idl_free( idl ); idl = NULL; - Debug( LDAP_DEBUG_TRACE, "<= equality_candidates key read failed (%d)\n", + Debug( LDAP_DEBUG_TRACE, + "<= equality_candidates key read failed (%d)\n", rc, 0, 0 ); break; } @@ -249,7 +259,8 @@ equality_candidates( if( tmp == NULL ) { idl_free( idl ); idl = NULL; - Debug( LDAP_DEBUG_TRACE, "<= equality_candidates NULL\n", + Debug( LDAP_DEBUG_TRACE, + "<= equality_candidates NULL\n", 0, 0, 0 ); break; } @@ -257,6 +268,7 @@ equality_candidates( save = idl; idl = idl_intersection( be, idl, tmp ); idl_free( save ); + idl_free( tmp ); if( idl == NULL ) break; } @@ -300,6 +312,7 @@ approx_candidates( if( dbname == NULL ) { /* not indexed */ + ber_bvfree( prefix ); return idl; } @@ -310,11 +323,13 @@ approx_candidates( } if( !mr ) { + ber_bvfree( prefix ); /* return LDAP_INAPPROPRIATE_MATCHING; */ return idl; } if( !mr->smr_filter ) { + ber_bvfree( prefix ); return idl; } @@ -326,6 +341,8 @@ approx_candidates( ava->aa_value, &keys ); + ber_bvfree( prefix ); + if( rc != LDAP_SUCCESS ) { return idl; } diff --git a/servers/slapd/back-ldbm/idl.c b/servers/slapd/back-ldbm/idl.c index 13ac4235b0..e189a5bd6b 100644 --- a/servers/slapd/back-ldbm/idl.c +++ b/servers/slapd/back-ldbm/idl.c @@ -551,7 +551,6 @@ idl_insert_key( id, 0, 0 ); } - assert( 0 ); /* not yet implemented */ idl_free( tmp ); idl_free( tmp2 ); idl_free( idl ); diff --git a/servers/slapd/back-ldbm/modify.c b/servers/slapd/back-ldbm/modify.c index 6d3974cef4..114dbb0c62 100644 --- a/servers/slapd/back-ldbm/modify.c +++ b/servers/slapd/back-ldbm/modify.c @@ -379,26 +379,17 @@ delete_values( if( rc == LDAP_SUCCESS && match != 0 ) { continue; } + + /* found a matching value */ found = 1; - /* found a matching value - delete it */ + /* delete it */ ber_bvfree( a->a_vals[j] ); for ( k = j + 1; a->a_vals[k] != NULL; k++ ) { a->a_vals[k - 1] = a->a_vals[k]; } a->a_vals[k - 1] = NULL; - /* delete the entire attribute, if no values remain */ - if ( a->a_vals[0] == NULL) { - Debug( LDAP_DEBUG_ARGS, - "removing entire attribute %s\n", - desc, 0, 0 ); - if ( attr_delete( &e->e_attrs, mod->sm_desc ) ) { - ber_bvfree( asserted ); - return LDAP_NO_SUCH_ATTRIBUTE; - } - } - break; } @@ -413,6 +404,16 @@ delete_values( } } + /* if no values remain, delete the entire attribute */ + if ( a->a_vals[0] == NULL ) { + Debug( LDAP_DEBUG_ARGS, + "removing entire attribute %s\n", + desc, 0, 0 ); + if ( attr_delete( &e->e_attrs, mod->sm_desc ) ) { + return LDAP_NO_SUCH_ATTRIBUTE; + } + } + return LDAP_SUCCESS; } diff --git a/servers/slapd/back-sql/rdbms_depend/mssql/testdb_metadata.sql b/servers/slapd/back-sql/rdbms_depend/mssql/testdb_metadata.sql new file mode 100644 index 0000000000..f360815355 --- /dev/null +++ b/servers/slapd/back-sql/rdbms_depend/mssql/testdb_metadata.sql @@ -0,0 +1,180 @@ +-- mappings + + +SET IDENTITY_INSERT ldap_oc_mappings ON +insert into ldap_oc_mappings (id,name,keytbl,keycol,create_proc,delete_proc,expect_return) +values (1,'inetorgperson','persons','id','{call create_person(?)}','{call delete_person(?)}',0) + +insert into ldap_oc_mappings (id,name,keytbl,keycol,create_proc,delete_proc,expect_return) +values (2,'document','documents','id','{call create_document(?)}','{call delete_document(?)}',0) + +insert into ldap_oc_mappings (id,name,keytbl,keycol,create_proc,delete_proc,expect_return) +values (3,'organization','institutes','id','{call create_org(?)}','{call delete_org(?)}',0) +SET IDENTITY_INSERT ldap_oc_mappings OFF + + +SET IDENTITY_INSERT ldap_attr_mappings ON +insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) +values (1,1,'cn','persons.name','persons',NULL,'{call set_person_name(?,?)}', + NULL,NULL,0,0) + +insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) +values (2,1,'telephoneNumber','phones.phone','persons,phones', + 'phones.pers_id=persons.id','{call add_phone(?,?)}', + NULL,'{call delete_phone(?,?)}',0,0) + +insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) +values (3,1,'sn','persons.name','persons',NULL,'{call set_person_name(?,?)}', + NULL,NULL,0,0) + +insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) +values (4,2,'description','documents.abstract','documents',NULL,'{call set_doc_abstract(?,?)}', + NULL,NULL,0,0) + +insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) +values (5,2,'documentTitle','documents.title','documents',NULL,'{call set_doc_title(?,?)}', + NULL,NULL,0,0) + +-- insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) +-- values (6,2,'documentAuthor','persons.name','persons,documents,authors_docs', +-- 'persons.id=authors_docs.pers_id AND documents.id=authors_docs.doc_id', +-- NULL,NULL,NULL,0,0) + +insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) +values (7,3,'o','institutes.name','institutes',NULL,'{call set_org_name(?,?)}', + NULL,NULL,0,0) + +insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) +values (8,1,'documentDN','ldap_entries.dn','ldap_entries,documents,authors_docs,persons', + 'ldap_entries.keyval=documents.id AND ldap_entries.oc_map_id=2 AND authors_docs.doc_id=documents.id AND authors_docs.pers_id=persons.id', + '{call make_doc_link(?,?)}',NULL,'{call del_doc_link(?,?)}',0,0) + +insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,modify_proc,delete_proc,param_order,expect_return) +values (9,2,'documentAuthor','ldap_entries.dn','ldap_entries,documents,authors_docs,persons', + 'ldap_entries.keyval=persons.id AND ldap_entries.oc_map_id=1 AND authors_docs.doc_id=documents.id AND authors_docs.pers_id=persons.id', + '{call make_author_link(?,?)}',NULL,'{call del_author_link(?,?)}',0,0) + +SET IDENTITY_INSERT ldap_attr_mappings OFF + +-- entries + +SET IDENTITY_INSERT ldap_entries ON +insert into ldap_entries (id,dn,oc_map_id,parent,keyval) +values (1,'o=sql,c=RU',3,0,1) + +insert into ldap_entries (id,dn,oc_map_id,parent,keyval) +values (2,'cn=Mitya Kovalev,o=sql,c=RU',1,1,1) + +insert into ldap_entries (id,dn,oc_map_id,parent,keyval) +values (3,'cn=Torvlobnor Puzdoy,o=sql,c=RU',1,1,2) + +insert into ldap_entries (id,dn,oc_map_id,parent,keyval) +values (4,'cn=Akakiy Zinberstein,o=sql,c=RU',1,1,3) + +insert into ldap_entries (id,dn,oc_map_id,parent,keyval) +values (5,'documentTitle=book1,o=sql,c=RU',2,1,1) + +insert into ldap_entries (id,dn,oc_map_id,parent,keyval) +values (6,'documentTitle=book2,o=sql,c=RU',2,1,2) + +SET IDENTITY_INSERT ldap_entries OFF + +-- referrals + +insert into ldap_entry_objclasses (entry_id,oc_name) +values (4,'referral'); + +insert into ldap_referrals (entry_id,url) +values (4,'http://localhost'); + +-- support procedures + +SET QUOTED_IDENTIFIER OFF SET ANSI_NULLS ON +GO + + +CREATE PROCEDURE add_phone @pers_id int, @phone varchar(255) AS +INSERT INTO ldap.phones (pers_id,phone) VALUES (@pers_id,@phone) +GO + +CREATE PROCEDURE create_person @@keyval int OUTPUT AS +INSERT INTO ldap.persons (name) VALUES (''); +set @@keyval=(SELECT MAX(id) FROM ldap.persons) +GO + +CREATE PROCEDURE delete_person @keyval int AS +DELETE FROM ldap.phones WHERE pers_id=@keyval; +DELETE FROM ldap.authors_docs WHERE pers_id=@keyval; +DELETE FROM ldap.persons WHERE id=@keyval; +GO + +CREATE PROCEDURE create_org @@keyval int OUTPUT AS +INSERT INTO ldap.institutes (name) VALUES (''); +set @@keyval=(SELECT MAX(id) FROM ldap.institutes) +GO + +CREATE PROCEDURE create_document @@keyval int OUTPUT AS +INSERT INTO ldap.documents (title) VALUES (''); +set @@keyval=(SELECT MAX(id) FROM ldap.documents) +GO + +CREATE PROCEDURE delete_org @keyval int AS +DELETE FROM ldap.institutes WHERE id=@keyval; +GO + +CREATE PROCEDURE delete_document @keyval int AS +DELETE FROM ldap.authors_docs WHERE doc_id=@keyval; +DELETE FROM ldap.documents WHERE id=@keyval; +GO + +CREATE PROCEDURE delete_phone @keyval int,@phone varchar(64) AS +DELETE FROM ldap.phones WHERE pers_id=@keyval AND phone=@phone; +GO + +CREATE PROCEDURE set_person_name @keyval int, @new_name varchar(255) AS +UPDATE ldap.persons SET name=@new_name WHERE id=@keyval; +GO + +CREATE PROCEDURE set_org_name @keyval int, @new_name varchar(255) AS +UPDATE ldap.institutes SET name=@new_name WHERE id=@keyval; +GO + +CREATE PROCEDURE set_doc_title @keyval int, @new_title varchar(255) AS +UPDATE ldap.documents SET title=@new_title WHERE id=@keyval; +GO + +CREATE PROCEDURE set_doc_abstract @keyval int, @new_abstract varchar(255) AS +UPDATE ldap.documents SET abstract=@new_abstract WHERE id=@keyval; +GO + +CREATE PROCEDURE make_author_link @keyval int, @author_dn varchar(255) AS +DECLARE @per_id int; +SET @per_id=(SELECT keyval FROM ldap.ldap_entries + WHERE oc_map_id=1 AND dn=@author_dn); +IF NOT (@per_id IS NULL) + INSERT INTO ldap.authors_docs (doc_id,pers_id) VALUES (@keyval,@per_id); +GO + +CREATE PROCEDURE make_doc_link @keyval int, @doc_dn varchar(255) AS +DECLARE @doc_id int; +SET @doc_id=(SELECT keyval FROM ldap.ldap_entries + WHERE oc_map_id=2 AND dn=@doc_dn); +IF NOT (@doc_id IS NULL) + INSERT INTO ldap.authors_docs (pers_id,doc_id) VALUES (@keyval,@doc_id); +GO + +CREATE PROCEDURE del_doc_link @keyval int, @doc_dn varchar(255) AS +DECLARE @doc_id int; +SET @doc_id=(SELECT keyval FROM ldap.ldap_entries + WHERE oc_map_id=2 AND dn=@doc_dn); +IF NOT (@doc_id IS NULL) +DELETE FROM ldap.authors_docs WHERE pers_id=@keyval AND doc_id=@doc_id; +GO + +CREATE PROCEDURE del_author_link @keyval int, @author_dn varchar(255) AS +DECLARE @per_id int; +SET @per_id=(SELECT keyval FROM ldap.ldap_entries + WHERE oc_map_id=1 AND dn=@author_dn); +IF NOT (@per_id IS NULL) + DELETE FROM ldap.authors_docs WHERE doc_id=@keyval AND pers_id=@per_id; +GO diff --git a/servers/slapd/back-sql/rdbms_depend/mysql/testdb_metadata.sql b/servers/slapd/back-sql/rdbms_depend/mysql/testdb_metadata.sql new file mode 100644 index 0000000000..13aef2574e --- /dev/null +++ b/servers/slapd/back-sql/rdbms_depend/mysql/testdb_metadata.sql @@ -0,0 +1,74 @@ +--mappings + +insert into ldap_oc_mappings (id,name,keytbl,keycol,create_proc,delete_proc,expect_return) +values (1,'inetOrgPerson','persons','id',"insert into persons (name) values ('');\n select last_insert_id();",NULL,0); + +insert into ldap_oc_mappings (id,name,keytbl,keycol,create_proc,delete_proc,expect_return) +values (2,'document','documents','id',NULL,NULL,0); + +insert into ldap_oc_mappings (id,name,keytbl,keycol,create_proc,delete_proc,expect_return) +values (3,'organization','institutes','id',NULL,NULL,0); + + +insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) +values (1,1,'cn','persons.name','persons',NULL,NULL,NULL,3,0); + +insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) +values (2,1,'telephoneNumber','phones.phone','persons,phones', + 'phones.pers_id=persons.id',NULL,NULL,3,0); + +insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) +values (3,1,'sn','persons.name','persons',NULL,NULL,NULL,3,0); + +insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) +values (4,2,'description','documents.abstract','documents',NULL,NULL,NULL,3,0); + +insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) +values (5,2,'documentTitle','documents.title','documents',NULL,NULL,NULL,3,0); + +-- insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) +-- values (6,2,'documentAuthor','persons.name','persons,documents,authors_docs', +-- 'persons.id=authors_docs.pers_id AND documents.id=authors_docs.doc_id', +-- NULL,NULL,3,0); + +insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) +values (7,3,'o','institutes.name','institutes',NULL,NULL,NULL,3,0); + +insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) +values (8,1,'documentDN','ldap_entries.dn','ldap_entries,documents,authors_docs,persons', + 'ldap_entries.keyval=documents.id AND ldap_entries.oc_map_id=2 AND authors_docs.doc_id=documents.id AND authors_docs.pers_id=persons.id', + NULL,NULL,3,0); + +insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) +values (9,2,'documentAuthor','ldap_entries.dn','ldap_entries,documents,authors_docs,persons', + 'ldap_entries.keyval=persons.id AND ldap_entries.oc_map_id=1 AND authors_docs.doc_id=documents.id AND authors_docs.pers_id=persons.id', + NULL,NULL,3,0); + +-- entries + +insert into ldap_entries (id,dn,oc_map_id,parent,keyval) +values (1,'o=sql,c=RU',3,0,1); + +insert into ldap_entries (id,dn,oc_map_id,parent,keyval) +values (2,'cn=Mitya Kovalev,o=sql,c=RU',1,1,1); + +insert into ldap_entries (id,dn,oc_map_id,parent,keyval) +values (3,'cn=Torvlobnor Puzdoy,o=sql,c=RU',1,1,2); + +insert into ldap_entries (id,dn,oc_map_id,parent,keyval) +values (4,'cn=Akakiy Zinberstein,o=sql,c=RU',1,1,3); + +insert into ldap_entries (id,dn,oc_map_id,parent,keyval) +values (5,'documentTitle=book1,o=sql,c=RU',2,1,1); + +insert into ldap_entries (id,dn,oc_map_id,parent,keyval) +values (6,'documentTitle=book2,o=sql,c=RU',2,1,2); + + +-- referrals + +insert into ldap_entry_objclasses (entry_id,oc_name) +values (4,'referral'); + +insert into ldap_referrals (entry_id,url) +values (4,'http://localhost'); diff --git a/servers/slapd/back-sql/rdbms_depend/oracle/testdb_metadata.sql b/servers/slapd/back-sql/rdbms_depend/oracle/testdb_metadata.sql new file mode 100644 index 0000000000..7571527f22 --- /dev/null +++ b/servers/slapd/back-sql/rdbms_depend/oracle/testdb_metadata.sql @@ -0,0 +1,214 @@ +-- mappings + +insert into ldap_oc_mappings (id,name,keytbl,keycol,create_proc,delete_proc,expect_return) +values (1,'person','persons','id','{call create_person(?)}','{call delete_person(?)}',0); + +insert into ldap_oc_mappings (id,name,keytbl,keycol,create_proc,delete_proc,expect_return) +values (2,'document','documents','id','{call create_document(?)}','{call delete_document(?)}',0); + +insert into ldap_oc_mappings (id,name,keytbl,keycol,create_proc,delete_proc,expect_return) +values (3,'organization','institutes','id','{call create_org(?)}','{call delete_org(?)}',0); + + +insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) +values (1,1,'cn','persons.name','persons',NULL,'{call set_person_name(?,?)}', + NULL,0,0); + +insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) +values (2,1,'telephoneNumber','phones.phone','persons,phones', + 'phones.pers_id=persons.id','{call add_phone(?,?)}', + '{call delete_phone(?,?)}',0,0); + +insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) +values (3,1,'sn','persons.name','persons',NULL,'{call set_person_name(?,?)}', + NULL,0,0); + +insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) +values (4,2,'abstract','documents.abstract','documents',NULL,'{call set_doc_abstract(?,?)}', + NULL,0,0); + +insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) +values (5,2,'documentTitle','documents.title','documents',NULL,'{call set_doc_title(?,?)}', + NULL,0,0); + +-- insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) +-- values (6,2,'documentAuthor','persons.name','persons,documents,authors_docs', +-- 'persons.id=authors_docs.pers_id AND documents.id=authors_docs.doc_id', +-- NULL,NULL,0,0); + +insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) +values (7,3,'o','institutes.name','institutes',NULL,'{call set_org_name(?,?)}', + NULL,0,0); + +insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) +values (8,1,'documentDN','ldap_entries.dn','ldap_entries,documents,authors_docs,persons', + 'ldap_entries.keyval=documents.id AND ldap_entries.oc_map_id=2 AND authors_docs.doc_id=documents.id AND authors_docs.pers_id=persons.id', + '{?=call make_doc_link(?,?)}','{?=call del_doc_link(?,?)}',0,3); + +insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) +values (9,2,'documentAuthor','ldap_entries.dn','ldap_entries,documents,authors_docs,persons', + 'ldap_entries.keyval=persons.id AND ldap_entries.oc_map_id=1 AND authors_docs.doc_id=documents.id AND authors_docs.pers_id=persons.id', + '{?=call make_author_link(?,?)}','{?=call del_author_link(?,?)}',0,3); + + +-- entries + +insert into ldap_entries (id,dn,oc_map_id,parent,keyval) +values (ldap_entry_ids.nextval,'o=sql,c=RU',3,0,1); + +insert into ldap_entries (id,dn,oc_map_id,parent,keyval) +values (ldap_entry_ids.nextval,'cn=Mitya Kovalev,o=sql,c=RU',1,1,1); + +insert into ldap_entries (id,dn,oc_map_id,parent,keyval) +values (ldap_entry_ids.nextval,'cn=Torvlobnor Puzdoy,o=sql,c=RU',1,1,2); + +insert into ldap_entries (id,dn,oc_map_id,parent,keyval) +values (ldap_entry_ids.nextval,'cn=Akakiy Zinberstein,o=sql,c=RU',1,1,3); + +insert into ldap_entries (id,dn,oc_map_id,parent,keyval) +values (ldap_entry_ids.nextval,'documentTitle=book1,o=sql,c=RU',2,1,1); + +insert into ldap_entries (id,dn,oc_map_id,parent,keyval) +values (ldap_entry_ids.nextval,'documentTitle=book2,o=sql,c=RU',2,1,2); + +-- referrals + +insert into ldap_entry_objclasses (entry_id,oc_name) +values (4,'referral'); + +insert into ldap_referrals (entry_id,url) +values (4,'http://localhost'); + + +-- procedures + +CREATE OR REPLACE PROCEDURE create_person(keyval OUT NUMBER) AS +BEGIN +INSERT INTO persons (id,name) VALUES (person_ids.nextval,' '); +SELECT person_ids.currval INTO keyval FROM DUAL; +END; +/ + +CREATE OR REPLACE PROCEDURE delete_person(keyval IN NUMBER) AS +BEGIN +DELETE FROM phones WHERE pers_id=keyval; +DELETE FROM authors_docs WHERE pers_id=keyval; +DELETE FROM persons WHERE id=keyval; +END; +/ + +CREATE OR REPLACE PROCEDURE create_org(keyval OUT NUMBER) AS +BEGIN +INSERT INTO institutes (id,name) VALUES (institute_ids.nextval,' '); +SELECT institute_ids.currval INTO keyval FROM DUAL; +END; +/ + +CREATE OR REPLACE PROCEDURE delete_org(keyval IN NUMBER) AS +BEGIN +DELETE FROM institutes WHERE id=keyval; +END; +/ + +CREATE OR REPLACE PROCEDURE create_document(keyval OUT NUMBER) AS +BEGIN +INSERT INTO documents (id,title) VALUES (document_ids.nextval,' '); +SELECT document_ids.currval INTO keyval FROM DUAL; +END; +/ + +CREATE OR REPLACE PROCEDURE delete_document (keyval IN NUMBER) AS +BEGIN +DELETE FROM authors_docs WHERE doc_id=keyval; +DELETE FROM documents WHERE id=keyval; +END; +/ + +CREATE OR REPLACE PROCEDURE add_phone(pers_id IN NUMBER, phone IN varchar2) AS +BEGIN +INSERT INTO phones (id,pers_id,phone) VALUES (phone_ids.nextval,pers_id,phone); +END; +/ + +CREATE OR REPLACE PROCEDURE delete_phone(keyval IN NUMBER, phone IN varchar2) AS +BEGIN +DELETE FROM phones WHERE pers_id=keyval AND phone=phone; +END; +/ + +CREATE OR REPLACE PROCEDURE set_person_name(keyval IN NUMBER, new_name IN varchar2) AS +BEGIN +UPDATE persons SET name=new_name WHERE id=keyval; +END; +/ + +CREATE OR REPLACE PROCEDURE set_org_name(keyval IN NUMBER, new_name IN varchar2) AS +BEGIN +UPDATE institutes SET name=new_name WHERE id=keyval; +END; +/ + +CREATE OR REPLACE PROCEDURE set_doc_title (keyval IN NUMBER, new_title IN varchar2) AS +BEGIN +UPDATE documents SET title=new_title WHERE id=keyval; +END; +/ + +CREATE OR REPLACE PROCEDURE set_doc_abstract (keyval IN NUMBER, new_abstract IN varchar2) AS +BEGIN +UPDATE documents SET abstract=new_abstract WHERE id=keyval; +END; +/ + +CREATE OR REPLACE FUNCTION make_author_link (keyval IN NUMBER, author_dn IN varchar2) RETURN NUMBER AS +per_id NUMBER; +BEGIN +SELECT keyval INTO per_id FROM ldap_entries + WHERE oc_map_id=1 AND dn=author_dn; +IF NOT (per_id IS NULL) THEN + INSERT INTO authors_docs (doc_id,pers_id) VALUES (keyval,per_id); + RETURN 1; +END IF; +RETURN 0; +END; +/ + +CREATE OR REPLACE FUNCTION make_doc_link (keyval IN NUMBER, doc_dn IN varchar2) RETURN NUMBER AS +docid NUMBER; +BEGIN +SELECT keyval INTO docid FROM ldap_entries + WHERE oc_map_id=2 AND dn=doc_dn; +IF NOT (docid IS NULL) THEN + INSERT INTO authors_docs (pers_id,doc_id) VALUES (keyval,docid); + RETURN 1; +END IF; +RETURN 0; +END; +/ + +CREATE OR REPLACE FUNCTION del_doc_link (keyval IN NUMBER, doc_dn IN varchar2) RETURN NUMBER AS +docid NUMBER; +BEGIN +SELECT keyval INTO docid FROM ldap_entries + WHERE oc_map_id=2 AND dn=doc_dn; +IF NOT (docid IS NULL) THEN + DELETE FROM authors_docs WHERE pers_id=keyval AND doc_id=docid; + RETURN 1; +END IF; +RETURN 0; +END; +/ + +CREATE OR REPLACE FUNCTION del_author_link (keyval IN NUMBER, author_dn IN varchar2) RETURN NUMBER AS +per_id NUMBER; +BEGIN +SELECT keyval INTO per_id FROM ldap_entries + WHERE oc_map_id=1 AND dn=author_dn; + +IF NOT (per_id IS NULL) THEN + DELETE FROM authors_docs WHERE doc_id=keyval AND pers_id=per_id; + RETURN 1; +END IF; + RETURN 0; +END; +/ diff --git a/servers/slapd/sasl.c b/servers/slapd/sasl.c index 6e46d65fe3..dcc83f5c74 100644 --- a/servers/slapd/sasl.c +++ b/servers/slapd/sasl.c @@ -196,12 +196,7 @@ int slap_sasl_init( void ) } if( sasl_host == NULL ) { - static char hostname[MAXHOSTNAMELEN+1]; - - if( gethostname( hostname, MAXHOSTNAMELEN ) == 0 ) { - hostname[MAXHOSTNAMELEN] = '\0'; - sasl_host = hostname; - } + sasl_host = ldap_pvt_get_fqdn( NULL ); } Debug( LDAP_DEBUG_TRACE, @@ -468,16 +463,16 @@ int slap_sasl_bind( rc = LDAP_SUCCESS; if( username == NULL || ( - !strncasecmp( username, "anonymous", sizeof("anonyous")-1 ) && - ( ( username[sizeof("anonymous")] == '\0' ) || - ( username[sizeof("anonymous")] == '@' ) ) ) ) + !strncasecmp( username, "anonymous", sizeof("anonymous")-1 ) && + ( username[sizeof("anonymous")-1] == '\0' || + username[sizeof("anonymous")-1] == '@' ) ) ) { Debug(LDAP_DEBUG_TRACE, "<== slap_sasl_bind: anonymous\n", 0, 0, 0); } else if ( username[0] == 'u' && username[1] == ':' && username[2] != '\0' - && strpbrk( &username[2], "=,;\"\\") == NULL ) + && strpbrk( &username[2], "+=,;\"\\ \t") == NULL ) { *edn = ch_malloc( sizeof( "uid= + realm=" ) + strlen( &username[2] ) diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c index 51db9b7247..814004e67c 100644 --- a/servers/slapd/schema_init.c +++ b/servers/slapd/schema_init.c @@ -541,7 +541,8 @@ IA5StringConvert( struct berval *bv = ch_malloc( sizeof(struct berval) ); bv->bv_len = len * sizeof( ldap_unicode_t ); - bv->bv_val = (char *) u = ch_malloc( bv->bv_len + sizeof(ldap_unicode_t) ); + u = (ldap_unicode_t *) ch_malloc( bv->bv_len + sizeof(ldap_unicode_t) ); + bv->bv_val = (char *) u; for(i=0; i < len; i++ ) { /* @@ -1611,7 +1612,7 @@ numericStringNormalize( assert( *newval->bv_val ); assert( newval->bv_val < p ); - assert( p <= q ); + assert( q <= p ); /* cannot start with a space */ assert( !ASCII_SPACE(*newval->bv_val) ); diff --git a/servers/slurpd/Makefile.in b/servers/slurpd/Makefile.in index 6a1137eb16..613ba59da7 100644 --- a/servers/slurpd/Makefile.in +++ b/servers/slurpd/Makefile.in @@ -45,6 +45,7 @@ version.c: $(OBJS) $(LDAP_LIBDEPEND) $(LDAP_LIBTHREAD_DEPEND) install-local-srv: FORCE -$(MKDIR) $(DESTDIR)$(libexecdir) + -$(MKDIR) $(DESTDIR)$(localstatedir)/openldap-slurp @( \ for prg in $(PROGRAMS); do \ $(LTINSTALL) $(INSTALLFLAGS) -s -m 755 $$prg$(EXEEXT) \ diff --git a/servers/slurpd/slurp.h b/servers/slurpd/slurp.h index 4983641a60..f1f54b35c0 100644 --- a/servers/slurpd/slurp.h +++ b/servers/slurpd/slurp.h @@ -40,7 +40,7 @@ /* Default directory for slurpd's private copy of replication logs */ -#define DEFAULT_SLURPD_REPLICA_DIR "/usr/tmp" +#define DEFAULT_SLURPD_REPLICA_DIR LDAP_RUNDIR LDAP_DIRSEP "openldap-slurp" /* Default name for slurpd's private copy of the replication log */ #define DEFAULT_SLURPD_REPLOGFILE "slurpd.replog" @@ -49,7 +49,7 @@ #define DEFAULT_SLURPD_STATUS_FILE "slurpd.status" /* slurpd dump file - contents of rq struct are written here (debugging) */ -#define SLURPD_DUMPFILE "/tmp/slurpd.dump" +#define SLURPD_DUMPFILE LDAP_TMPDIR LDAP_DIRSEP "slurpd.dump" /* default srvtab file. Can be overridden */ #define SRVTAB "/etc/srvtab" -- 2.39.5