diff options
author | Noriko Hosoi <nhosoi@redhat.com> | 2010-02-16 17:13:14 -0800 |
---|---|---|
committer | Noriko Hosoi <nhosoi@redhat.com> | 2010-02-17 08:50:04 -0800 |
commit | a7d0c3dd59a1f04eb3987b521d67a0a36c719896 (patch) | |
tree | bc75e2854ee52e266496f629b5fb3649f2be3020 | |
parent | 107d40e05c49211b88f5ec47bc09443640a4e570 (diff) | |
download | ds-a7d0c3dd59a1f04eb3987b521d67a0a36c719896.tar.gz ds-a7d0c3dd59a1f04eb3987b521d67a0a36c719896.tar.xz ds-a7d0c3dd59a1f04eb3987b521d67a0a36c719896.zip |
565987 - redhat-ds-base fails to build due to undefined struct
st_size and nsldapi_build_control et al. in ldclt.c
https://bugzilla.redhat.com/show_bug.cgi?id=565987
Fix Description:
1. stat: sys/types.h and sys/stat.h need to be included.
2. nsldapi_build_control: duplicated nsldapi_build_control from
the mozldap c library.
3. added the sub value [=deref:attr] of deref to the usage.
4. allow -e deref without the sub value. It used to be allowed,
but it was forbidden by the previous change.
-rw-r--r-- | ldap/servers/slapd/tools/ldclt/ldapfct.c | 96 | ||||
-rw-r--r-- | ldap/servers/slapd/tools/ldclt/ldclt.c | 19 | ||||
-rw-r--r-- | ldap/servers/slapd/tools/ldclt/ldcltU.c | 24 |
3 files changed, 123 insertions, 16 deletions
diff --git a/ldap/servers/slapd/tools/ldclt/ldapfct.c b/ldap/servers/slapd/tools/ldclt/ldapfct.c index 359b5fe1..b19c6895 100644 --- a/ldap/servers/slapd/tools/ldclt/ldapfct.c +++ b/ldap/servers/slapd/tools/ldclt/ldapfct.c @@ -265,6 +265,11 @@ dd/mm/yy | Author | Comments #define LDCLT_DEREF_ATTR "secretary" int ldclt_create_deref_control( LDAP *ld, char *derefAttr, char **attrs, LDAPControl **ctrlp ); +#if !defined(USE_OPENLDAP) +int ldclt_build_control( char *oid, BerElement *ber, int freeber, char iscritical, LDAPControl **ctrlp ); +int ldclt_alloc_ber( LDAP *ld, BerElement **berp ); +#endif + /* **************************************************************************** FUNCTION : my_ldap_err2string PURPOSE : This function is targetted to encapsulate the standard @@ -3688,7 +3693,6 @@ doExactSearch ( LDAPControl **ctrlsp = NULL, *ctrls[2], *dctrl = NULL; /* derefence control */ /* the following variables are used for response parsing */ - int i; /* for counting purpose */ int msgtype, parse_rc , rc ; /* for search result parsing */ char *matcheddn, *errmsg, *dn ; LDAPControl **resctrls; @@ -4220,7 +4224,11 @@ ldclt_create_deref_control( } /* create a ber package to hold the controlValue */ - if ( LDAP_SUCCESS != nsldapi_alloc_ber_with_options( ld, &ber ) ) +#if defined(USE_OPENLDAP) + if ( NULL == ( ber = ldap_alloc_ber_with_options( ld ) ) ) +#else + if ( LDAP_SUCCESS != ldclt_alloc_ber( ld, &ber ) ) +#endif { return( LDAP_NO_MEMORY ); } @@ -4231,9 +4239,91 @@ ldclt_create_deref_control( return( LDAP_ENCODING_ERROR ); } - rc = nsldapi_build_control( LDAP_CONTROL_X_DEREF, ber, 1, 1, ctrlp ); +#if defined(USE_OPENLDAP) + rc = ldap_create_control( LDAP_CONTROL_X_DEREF, ber, 1, ctrlp ); +#else + rc = ldclt_build_control( LDAP_CONTROL_X_DEREF, ber, 1, 1, ctrlp ); +#endif return( rc ); } +#if !defined(USE_OPENLDAP) +/* + * Duplicated nsldapi_build_control from + * mozilla/directory/c-sdk/ldap/libraries/libldap/control.c + * + * build an allocated LDAPv3 control. Returns an LDAP error code. + */ +int +ldclt_build_control( char *oid, BerElement *ber, int freeber, char iscritical, + LDAPControl **ctrlp ) +{ + int rc; + struct berval *bvp; + + if ( ber == NULL ) { + bvp = NULL; + } else { + /* allocate struct berval with contents of the BER encoding */ + rc = ber_flatten( ber, &bvp ); + if ( freeber ) { + ber_free( ber, 1 ); + } + if ( rc == -1 ) { + return( LDAP_NO_MEMORY ); + } + } + + /* allocate the new control structure */ + if (( *ctrlp = (LDAPControl *)malloc( sizeof(LDAPControl))) == NULL ) { + if ( bvp != NULL ) { + ber_bvfree( bvp ); + } + return( LDAP_NO_MEMORY ); + } + + /* fill in the fields of this new control */ + (*ctrlp)->ldctl_iscritical = iscritical; + if (( (*ctrlp)->ldctl_oid = strdup( oid )) == NULL ) { + free( *ctrlp ); + if ( bvp != NULL ) { + ber_bvfree( bvp ); + } + return( LDAP_NO_MEMORY ); + } + + if ( bvp == NULL ) { + (*ctrlp)->ldctl_value.bv_len = 0; + (*ctrlp)->ldctl_value.bv_val = NULL; + } else { + (*ctrlp)->ldctl_value = *bvp; /* struct copy */ + free( bvp ); /* free container, not contents! */ + } + + return( LDAP_SUCCESS ); +} + +/* + * Duplicated nsldapi_build_control from + * mozilla/directory/c-sdk/ldap/libraries/libldap/request.c + * + * returns an LDAP error code and also sets error inside LDAP + */ +int +ldclt_alloc_ber( LDAP *ld, BerElement **berp ) +{ + int err; + + /* We use default lberoptions since the value is not public in mozldap. */ + if (( *berp = ber_alloc_t( LBER_OPT_USE_DER )) == (BerElement *)NULL ) { + err = LDAP_NO_MEMORY; + } else { + err = LDAP_SUCCESS; + } + + return( err ); +} +#endif + /* End of file */ diff --git a/ldap/servers/slapd/tools/ldclt/ldclt.c b/ldap/servers/slapd/tools/ldclt/ldclt.c index 7b2a7dd4..53115ad6 100644 --- a/ldap/servers/slapd/tools/ldclt/ldclt.c +++ b/ldap/servers/slapd/tools/ldclt/ldclt.c @@ -300,7 +300,8 @@ dd/mm/yy | Author | Comments #include "utils.h" /* Utilities functions */ /*JLS 16-11-00*/ #include "scalab01.h" /* Scalab01 specific */ /*JLS 12-01-01*/ - +#include <sys/types.h> +#include <sys/stat.h> /* * Global variables @@ -1480,7 +1481,7 @@ basicInit (void) /* * Parse deref subvalue */ - if (mctx.mod2 & M2_DEREF) + if ((mctx.mod2 & M2_DEREF) && mctx.attrpl) { /* * Find the reference attribute name @@ -1508,7 +1509,7 @@ basicInit (void) /* * Parse attreplacefile subvalue */ - if (mctx.mod2 & M2_ATTR_REPLACE_FILE) + if ((mctx.mod2 & M2_ATTR_REPLACE_FILE) && mctx.attrpl) { /* * Find the attribute name @@ -2534,12 +2535,12 @@ decodeExecParams ( break; case EP_DEREF: mctx.mod2 |= M2_DEREF; - if (subvalue == NULL) - { - fprintf (stderr, "Error: missing arg deref argument pair (deref:attr)\n"); - return (-1); - } - mctx.attrpl = strdup (subvalue); + if (subvalue) { + /* if -e deref=deref:attr is given, "deref:attr" is set to attrpl */ + mctx.attrpl = strdup (subvalue); + } else { + mctx.attrpl = NULL; + } break; default: fprintf (stderr, "Error: illegal option -e %s\n", subvalue); diff --git a/ldap/servers/slapd/tools/ldclt/ldcltU.c b/ldap/servers/slapd/tools/ldclt/ldcltU.c index 1233a558..e436e18a 100644 --- a/ldap/servers/slapd/tools/ldclt/ldcltU.c +++ b/ldap/servers/slapd/tools/ldclt/ldcltU.c @@ -79,8 +79,16 @@ * commoncounter : all threads share the same counter. * counteach : count each operation not only successful ones. * delete : ldap_delete() entries. - * deref : adds dereference control to "esearch" - * : adds "secretary" attr to the entries for "add" + * deref[=deref:attr] : This option works with -e add and -e esearch. + * : With -e esearch: + * : adds dereference control. + * : if =deref:attr is given, the deref and attr + * : pair is set to the control request. + * : if not given, "secretary:cn" is set. + * : With -e add: + * : adds "secretary" attr to the netOrgPerson + * : entries to prepare for the search with the + * : default "secretary:cn" dereference control. * dontsleeponserverdown : will loop very fast if server down. * emailPerson : objectclass=emailPerson (-e add only). * esearch : exact search. @@ -174,8 +182,16 @@ void usage () (void) printf (" commoncounter : all threads share the same counter.\n"); (void) printf (" counteach : count each operation not only successful ones.\n"); (void) printf (" delete : ldap_delete() entries.\n"); - (void) printf (" deref : adds dereference control to \"esearch\"\n"); - (void) printf (" : adds \"secretary\" attr to the entries for \"add\"\n"); + (void) printf (" deref[=deref:attr]: This option works with -e add and esearch.\n"); + (void) printf (" : With -e esearch:\n"); + (void) printf (" : adds dereference control.\n"); + (void) printf (" : if =deref:attr is given, the deref and attr\n"); + (void) printf (" : pair is set to the control request.\n"); + (void) printf (" : if not given, \"secretary:cn\" is set.\n"); + (void) printf (" : With -e add:\n"); + (void) printf (" : adds \"secretary\" attr to the inetOrgPerson\n"); + (void) printf (" : entries to prepare for -e esearch using\n"); + (void) printf (" : the default deref attr pair.\n"); (void) printf (" dontsleeponserverdown : will loop very fast if server down.\n"); (void) printf (" emailPerson : objectclass=emailPerson (-e add only).\n"); (void) printf (" esearch : exact search.\n"); |