mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-03-07 14:18:15 +08:00
Use struct berval for exop reqoid everywhere. Define berval constants
for the known exops.
This commit is contained in:
parent
8f88bc1f8f
commit
65bf90ff73
@ -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,
|
||||
|
@ -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 );
|
||||
|
@ -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,
|
||||
|
@ -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 );
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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";
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 */
|
||||
|
@ -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 ) {
|
||||
|
@ -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,
|
||||
|
@ -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 );
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user