From: Howard Chu Date: Sun, 16 Feb 2003 06:15:28 +0000 (+0000) Subject: Use struct berval for exop reqoid everywhere. Define berval constants X-Git-Tag: NO_SLAP_OP_BLOCKS~351 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=65bf90ff7304fb4c98df5f1ab0251ff851da7029;p=openldap Use struct berval for exop reqoid everywhere. Define berval constants for the known exops. --- diff --git a/servers/slapd/back-bdb/extended.c b/servers/slapd/back-bdb/extended.c index 231d4e903d..9fa49df46b 100644 --- a/servers/slapd/back-bdb/extended.c +++ b/servers/slapd/back-bdb/extended.c @@ -12,12 +12,13 @@ #include "back-bdb.h" #include "external.h" +#include "lber_pvt.h" static struct exop { - char *oid; + struct berval *oid; BI_op_extended *extended; } exop_table[] = { - { LDAP_EXOP_MODIFY_PASSWD, bdb_exop_passwd }, + { (struct berval *)&slap_EXOP_MODIFY_PASSWD, bdb_exop_passwd }, { NULL, NULL } }; @@ -26,7 +27,7 @@ bdb_extended( Backend *be, Connection *conn, Operation *op, - const char *reqoid, + struct berval *reqoid, struct berval *reqdata, char **rspoid, struct berval **rspdata, @@ -37,8 +38,8 @@ bdb_extended( { int i; - for( i=0; exop_table[i].oid != NULL; i++ ) { - if( strcmp( exop_table[i].oid, reqoid ) == 0 ) { + for( i=0; exop_table[i].extended != NULL; i++ ) { + if( ber_bvcmp( exop_table[i].oid, reqoid ) == 0 ) { return (exop_table[i].extended)( be, conn, op, reqoid, reqdata, diff --git a/servers/slapd/back-bdb/passwd.c b/servers/slapd/back-bdb/passwd.c index d801fb9260..7f153e80bd 100644 --- a/servers/slapd/back-bdb/passwd.c +++ b/servers/slapd/back-bdb/passwd.c @@ -12,13 +12,14 @@ #include "back-bdb.h" #include "external.h" +#include "lber_pvt.h" int bdb_exop_passwd( Backend *be, Connection *conn, Operation *op, - const char *reqoid, + struct berval *reqoid, struct berval *reqdata, char **rspoid, struct berval **rspdata, @@ -45,7 +46,7 @@ bdb_exop_passwd( DB_LOCK lock; assert( reqoid != NULL ); - assert( strcmp( LDAP_EXOP_MODIFY_PASSWD, reqoid ) == 0 ); + assert( ber_bvcmp( &slap_EXOP_MODIFY_PASSWD, reqoid ) == 0 ); rc = slap_passwd_parse( reqdata, &id, NULL, &new, text ); diff --git a/servers/slapd/back-ldbm/extended.c b/servers/slapd/back-ldbm/extended.c index 08d6c6d745..c6e092aaa7 100644 --- a/servers/slapd/back-ldbm/extended.c +++ b/servers/slapd/back-ldbm/extended.c @@ -15,12 +15,13 @@ #include "slap.h" #include "back-ldbm.h" #include "proto-back-ldbm.h" +#include "lber_pvt.h" struct exop { - char *oid; + struct berval *oid; BI_op_extended *extended; } exop_table[] = { - { LDAP_EXOP_MODIFY_PASSWD, ldbm_back_exop_passwd }, + { (struct berval *)&slap_EXOP_MODIFY_PASSWD, ldbm_back_exop_passwd }, { NULL, NULL } }; @@ -29,7 +30,7 @@ ldbm_back_extended( Backend *be, Connection *conn, Operation *op, - const char *reqoid, + struct berval *reqoid, struct berval *reqdata, char **rspoid, struct berval **rspdata, @@ -40,8 +41,8 @@ ldbm_back_extended( { int i; - for( i=0; exop_table[i].oid != NULL; i++ ) { - if( strcmp( exop_table[i].oid, reqoid ) == 0 ) { + for( i=0; exop_table[i].extended != NULL; i++ ) { + if( ber_bvcmp( exop_table[i].oid, reqoid ) == 0 ) { return (exop_table[i].extended)( be, conn, op, reqoid, reqdata, diff --git a/servers/slapd/back-ldbm/passwd.c b/servers/slapd/back-ldbm/passwd.c index 3aed5c4df3..18a792bc6e 100644 --- a/servers/slapd/back-ldbm/passwd.c +++ b/servers/slapd/back-ldbm/passwd.c @@ -15,13 +15,14 @@ #include "slap.h" #include "back-ldbm.h" #include "proto-back-ldbm.h" +#include "lber_pvt.h" int ldbm_back_exop_passwd( Backend *be, Connection *conn, Operation *op, - const char *reqoid, + struct berval *reqoid, struct berval *reqdata, char **rspoid, struct berval **rspdata, @@ -42,7 +43,7 @@ ldbm_back_exop_passwd( struct berval ndn; assert( reqoid != NULL ); - assert( strcmp( LDAP_EXOP_MODIFY_PASSWD, reqoid ) == 0 ); + assert( ber_bvcmp( &slap_EXOP_MODIFY_PASSWD, reqoid ) == 0 ); rc = slap_passwd_parse( reqdata, &id, NULL, &new, text ); diff --git a/servers/slapd/backend.c b/servers/slapd/backend.c index 6586e3020f..07877bad8d 100644 --- a/servers/slapd/backend.c +++ b/servers/slapd/backend.c @@ -856,8 +856,7 @@ backend_check_restrictions( } { - struct berval bv = BER_BVC( LDAP_EXOP_START_TLS ); - if( bvmatch( opdata, &bv ) ) { + if( bvmatch( opdata, &slap_EXOP_START_TLS ) ) { session++; starttls++; break; @@ -865,16 +864,14 @@ backend_check_restrictions( } { - struct berval bv = BER_BVC( LDAP_EXOP_X_WHO_AM_I ); - if( bvmatch( opdata, &bv ) ) { + if( bvmatch( opdata, &slap_EXOP_WHOAMI ) ) { break; } } #ifdef LDAP_EXOP_X_CANCEL { - struct berval bv = BER_BVC( LDAP_EXOP_X_CANCEL ); - if ( bvmatch( opdata, &bv ) ) { + if ( bvmatch( opdata, &slap_EXOP_CANCEL ) ) { break; } } diff --git a/servers/slapd/cancel.c b/servers/slapd/cancel.c index f4298a5a5b..0fcce20d69 100644 --- a/servers/slapd/cancel.c +++ b/servers/slapd/cancel.c @@ -24,7 +24,7 @@ int cancel_extop( Connection *conn, Operation *op, - const char *reqoid, + struct berval *reqoid, struct berval *reqdata, char **rspoid, struct berval **rspdata, @@ -40,7 +40,7 @@ int cancel_extop( int i; assert( reqoid != NULL ); - assert( strcmp( LDAP_EXOP_X_CANCEL, reqoid ) == 0 ); + assert( ber_bvcmp( &slap_EXOP_CANCEL, reqoid ) == 0 ); if ( reqdata == NULL ) { *text = "no message ID supplied"; diff --git a/servers/slapd/extended.c b/servers/slapd/extended.c index e4ae486342..5b39e21707 100644 --- a/servers/slapd/extended.c +++ b/servers/slapd/extended.c @@ -49,28 +49,31 @@ static struct extop_list { static SLAP_EXTOP_MAIN_FN whoami_extop; -/* BerVal Constant initializer */ - -#define BVC(x) {sizeof(x)-1, x} - /* this list of built-in extops is for extops that are not part * of backends or in external modules. essentially, this is * just a way to get built-in extops onto the extop list without * having a separate init routine for each built-in extop. */ +#ifdef LDAP_EXOP_X_CANCEL +const struct berval slap_EXOP_CANCEL = BER_BVC(LDAP_EXOP_X_CANCEL); +#endif +const struct berval slap_EXOP_WHOAMI = BER_BVC(LDAP_EXOP_X_WHO_AM_I); +const struct berval slap_EXOP_MODIFY_PASSWD = BER_BVC(LDAP_EXOP_MODIFY_PASSWD); +const struct berval slap_EXOP_START_TLS = BER_BVC(LDAP_EXOP_START_TLS); + static struct { - struct berval oid; + const struct berval *oid; SLAP_EXTOP_MAIN_FN *ext_main; } builtin_extops[] = { #ifdef LDAP_EXOP_X_CANCEL - { BVC(LDAP_EXOP_X_CANCEL), cancel_extop }, + { &slap_EXOP_CANCEL, cancel_extop }, #endif - { BVC(LDAP_EXOP_X_WHO_AM_I), whoami_extop }, - { BVC(LDAP_EXOP_MODIFY_PASSWD), passwd_extop }, + { &slap_EXOP_WHOAMI, whoami_extop }, + { &slap_EXOP_MODIFY_PASSWD, passwd_extop }, #ifdef HAVE_TLS - { BVC(LDAP_EXOP_START_TLS), starttls_extop }, + { &slap_EXOP_START_TLS, starttls_extop }, #endif - { {0,NULL}, NULL } + { NULL, NULL } }; @@ -234,7 +237,7 @@ do_extended( #endif /* defined(LDAP_SLAPI) */ rc = (ext->ext_main)( conn, op, - reqoid.bv_val, reqdata.bv_val ? &reqdata : NULL, + &reqoid, reqdata.bv_val ? &reqdata : NULL, &rspoid, &rspdata, &rspctrls, &text, &refs ); if( rc != SLAPD_ABANDON ) { @@ -336,23 +339,23 @@ done: int load_extop( - const char *ext_oid, + struct berval *ext_oid, SLAP_EXTOP_MAIN_FN *ext_main ) { struct extop_list *ext; - if( ext_oid == NULL || *ext_oid == '\0' ) return -1; + if( ext_oid == NULL || ext_oid->bv_val == NULL || + ext_oid->bv_val[0] == '\0' || ext_oid->bv_len == 0 ) return -1; if(!ext_main) return -1; - ext = ch_calloc(1, sizeof(struct extop_list)); + ext = ch_calloc(1, sizeof(struct extop_list) + ext_oid->bv_len + 1); if (ext == NULL) return(-1); - ber_str2bv( ext_oid, 0, 1, &ext->oid ); - if (ext->oid.bv_val == NULL) { - free(ext); - return(-1); - } + ext->oid.bv_val = (char *)(ext + 1); + AC_MEMCPY( ext->oid.bv_val, ext_oid->bv_val, ext_oid->bv_len ); + ext->oid.bv_len = ext_oid->bv_len; + ext->oid.bv_val[ext->oid.bv_len] = '\0'; ext->ext_main = ext_main; ext->next = supp_ext_list; @@ -367,8 +370,8 @@ extops_init (void) { int i; - for (i = 0; builtin_extops[i].oid.bv_val != NULL; i++) { - load_extop(builtin_extops[i].oid.bv_val, builtin_extops[i].ext_main); + for (i = 0; builtin_extops[i].oid != NULL; i++) { + load_extop((struct berval *)builtin_extops[i].oid, builtin_extops[i].ext_main); } return(0); } @@ -381,8 +384,6 @@ extops_kill (void) /* we allocated the memory, so we have to free it, too. */ while ((ext = supp_ext_list) != NULL) { supp_ext_list = ext->next; - if (ext->oid.bv_val != NULL) - ch_free(ext->oid.bv_val); ch_free(ext); } return(0); @@ -405,7 +406,7 @@ static int whoami_extop ( Connection *conn, Operation *op, - const char * reqoid, + struct berval * reqoid, struct berval * reqdata, char ** rspoid, struct berval ** rspdata, @@ -422,11 +423,8 @@ whoami_extop ( } { - int rc; - struct berval whoami = BER_BVC( LDAP_EXOP_X_WHO_AM_I ); - - rc = backend_check_restrictions( conn->c_authz_backend, - conn, op, &whoami, text ); + int rc = backend_check_restrictions( conn->c_authz_backend, + conn, op, (struct berval *)&slap_EXOP_WHOAMI, text ); if( rc != LDAP_SUCCESS ) return rc; } diff --git a/servers/slapd/module.c b/servers/slapd/module.c index 498622cdd1..d6e1a4b392 100644 --- a/servers/slapd/module.c +++ b/servers/slapd/module.c @@ -266,8 +266,8 @@ load_extop_module ( ) { SLAP_EXTOP_MAIN_FN *ext_main; - int (*ext_getoid)(int index, char *oid, int blen); - char *oid; + SLAP_EXTOP_GETOID_FN *ext_getoid; + struct berval oid; int rc; ext_main = (SLAP_EXTOP_MAIN_FN *)module_resolve(module, "ext_main"); @@ -280,19 +280,15 @@ load_extop_module ( return(-1); } - oid = ch_malloc(256); - rc = (ext_getoid)(0, oid, 256); + rc = (ext_getoid)(0, &oid, 256); if (rc != 0) { - ch_free(oid); return(rc); } - if (*oid == 0) { - free(oid); + if (oid.bv_val == NULL || oid.bv_len == 0) { return(-1); } - rc = load_extop( oid, ext_main ); - free(oid); + rc = load_extop( &oid, ext_main ); return rc; } #endif /* SLAPD_EXTERNAL_EXTENSIONS */ diff --git a/servers/slapd/passwd.c b/servers/slapd/passwd.c index ccbc2cb4d3..bd6157d5e0 100644 --- a/servers/slapd/passwd.c +++ b/servers/slapd/passwd.c @@ -21,7 +21,7 @@ int passwd_extop( Connection *conn, Operation *op, - const char *reqoid, + struct berval *reqoid, struct berval *reqdata, char **rspoid, struct berval **rspdata, @@ -33,7 +33,7 @@ int passwd_extop( int rc; assert( reqoid != NULL ); - assert( strcmp( LDAP_EXOP_MODIFY_PASSWD, reqoid ) == 0 ); + assert( ber_bvcmp( &slap_EXOP_MODIFY_PASSWD, reqoid ) == 0 ); if( op->o_dn.bv_len == 0 ) { *text = "only authenticated users may change passwords"; @@ -50,8 +50,7 @@ int passwd_extop( } { - struct berval passwd = BER_BVC( LDAP_EXOP_MODIFY_PASSWD ); - rc = backend_check_restrictions( be, conn, op, &passwd, text ); + rc = backend_check_restrictions( be, conn, op, &slap_EXOP_MODIFY_PASSWD, text ); } if( rc != LDAP_SUCCESS ) { diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index e2df5f9f6c..badedd508e 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -451,9 +451,16 @@ LDAP_SLAPD_F (int) entry_id_cmp LDAP_P(( const void *v_a, const void *v_b )); /* * extended.c */ +#ifdef LDAP_EXOP_X_CANCEL +const struct berval slap_EXOP_CANCEL; +#endif +const struct berval slap_EXOP_WHOAMI; +const struct berval slap_EXOP_MODIFY_PASSWD; +const struct berval slap_EXOP_START_TLS; + typedef int (SLAP_EXTOP_MAIN_FN) LDAP_P(( Connection *conn, Operation *op, - const char * reqoid, + struct berval * reqoid, struct berval * reqdata, char ** rspoid, struct berval ** rspdata, @@ -462,10 +469,10 @@ typedef int (SLAP_EXTOP_MAIN_FN) LDAP_P(( BerVarray *refs )); typedef int (SLAP_EXTOP_GETOID_FN) LDAP_P(( - int index, char *oid, int blen )); + int index, struct berval *oid, int blen )); LDAP_SLAPD_F (int) load_extop LDAP_P(( - const char *ext_oid, + struct berval *ext_oid, SLAP_EXTOP_MAIN_FN *ext_main )); LDAP_SLAPD_F (int) extops_init LDAP_P(( void )); @@ -891,7 +898,7 @@ LDAP_SLAPD_F (int) slap_sasl_bind LDAP_P(( LDAP_SLAPD_F (int) slap_sasl_setpass( Connection *conn, Operation *op, - const char *reqoid, + struct berval *reqoid, struct berval *reqdata, char **rspoid, struct berval **rspdata, diff --git a/servers/slapd/sasl.c b/servers/slapd/sasl.c index 355a5c3c0b..e763dae5a2 100644 --- a/servers/slapd/sasl.c +++ b/servers/slapd/sasl.c @@ -1436,7 +1436,7 @@ int slap_sasl_setpass( Connection *conn, Operation *op, - const char *reqoid, + struct berval *reqoid, struct berval *reqdata, char **rspoid, struct berval **rspdata, @@ -1449,7 +1449,7 @@ slap_sasl_setpass( struct berval old = { 0, NULL }; assert( reqoid != NULL ); - assert( strcmp( LDAP_EXOP_MODIFY_PASSWD, reqoid ) == 0 ); + assert( ber_bvcmp( &slap_EXOP_MODIFY_PASSWD, reqoid ) == 0 ); rc = sasl_getprop( conn->c_sasl_context, SASL_USERNAME, (SASL_CONST void **)&id.bv_val ); diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 29b8d6e723..eb2f676fd1 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -1412,7 +1412,7 @@ typedef int (BI_op_extended) LDAP_P(( BackendDB *be, struct slap_conn *conn, struct slap_op *op, - const char *reqoid, + struct berval *reqoid, struct berval * reqdata, char **rspoid, struct berval ** rspdata, diff --git a/servers/slapd/starttls.c b/servers/slapd/starttls.c index 4ab33b1036..fce72e4a9a 100644 --- a/servers/slapd/starttls.c +++ b/servers/slapd/starttls.c @@ -24,7 +24,7 @@ int starttls_extop ( Connection *conn, Operation *op, - const char * reqoid, + struct berval * reqoid, struct berval * reqdata, char ** rspoid, struct berval ** rspdata, diff --git a/servers/slapd/tools/mimic.c b/servers/slapd/tools/mimic.c index dd5dc46eaf..baba886817 100644 --- a/servers/slapd/tools/mimic.c +++ b/servers/slapd/tools/mimic.c @@ -160,7 +160,7 @@ int slap_sasl_destroy(void) int slap_sasl_setpass( Connection *conn, Operation *op, - const char *reqoid, + struct berval *reqoid, struct berval *reqdata, char **rspoid, struct berval **rspdata,