Commit 119cbcab authored by Howard Chu's avatar Howard Chu
Browse files

Schema unparsing support

parent fba9235d
......@@ -58,8 +58,8 @@ struct aindexrec {
static Avlnode *attr_index = NULL;
static Avlnode *attr_cache = NULL;
static LDAP_SLIST_HEAD(ATList, slap_attribute_type) attr_list
= LDAP_SLIST_HEAD_INITIALIZER(&attr_list);
static LDAP_STAILQ_HEAD(ATList, slap_attribute_type) attr_list
= LDAP_STAILQ_HEAD_INITIALIZER(attr_list);
int at_oc_cache;
......@@ -210,9 +210,9 @@ at_destroy( void )
AttributeType *a;
avl_free(attr_index, ldap_memfree);
while( !LDAP_SLIST_EMPTY(&attr_list) ) {
a = LDAP_SLIST_FIRST(&attr_list);
LDAP_SLIST_REMOVE_HEAD(&attr_list, sat_next);
while( !LDAP_STAILQ_EMPTY(&attr_list) ) {
a = LDAP_STAILQ_FIRST(&attr_list);
LDAP_STAILQ_REMOVE_HEAD(&attr_list, sat_next);
if (a->sat_subtypes) ldap_memfree(a->sat_subtypes);
ad_destroy(a->sat_ad);
......@@ -230,7 +230,7 @@ at_start( AttributeType **at )
{
assert( at );
*at = LDAP_SLIST_FIRST(&attr_list);
*at = LDAP_STAILQ_FIRST(&attr_list);
return (*at != NULL);
}
......@@ -244,7 +244,7 @@ at_next( AttributeType **at )
{
AttributeType *tmp = NULL;
LDAP_SLIST_FOREACH(tmp,&attr_list,sat_next) {
LDAP_STAILQ_FOREACH(tmp,&attr_list,sat_next) {
if ( tmp == *at ) {
break;
}
......@@ -254,7 +254,7 @@ at_next( AttributeType **at )
}
#endif
*at = LDAP_SLIST_NEXT(*at,sat_next);
*at = LDAP_STAILQ_NEXT(*at,sat_next);
return (*at != NULL);
}
......@@ -269,9 +269,6 @@ at_insert(
struct aindexrec *air;
char **names;
LDAP_SLIST_NEXT( sat, sat_next ) = NULL;
LDAP_SLIST_INSERT_HEAD( &attr_list, sat, sat_next );
if ( sat->sat_oid ) {
air = (struct aindexrec *)
ch_calloc( 1, sizeof(struct aindexrec) );
......@@ -307,6 +304,8 @@ at_insert(
}
}
LDAP_STAILQ_INSERT_TAIL( &attr_list, sat, sat_next );
return 0;
}
......@@ -314,6 +313,7 @@ int
at_add(
LDAPAttributeType *at,
int user,
AttributeType **rsat,
const char **err )
{
AttributeType *sat;
......@@ -596,6 +596,8 @@ at_add(
}
code = at_insert(sat,err);
if ( code == 0 && rsat )
*rsat = sat;
return code;
}
......@@ -618,6 +620,53 @@ at_index_print( void )
}
#endif
void
at_unparse( BerVarray *res, AttributeType *start, AttributeType *end, int sys )
{
AttributeType *at;
int i, num;
struct berval bv, *bva = NULL, idx;
char ibuf[32], *ptr;
if ( !start )
start = LDAP_STAILQ_FIRST( &attr_list );
/* count the result size */
i = 0;
for ( at=start; at && at!=end; at=LDAP_STAILQ_NEXT(at, sat_next)) {
if ( sys && !(at->sat_flags & SLAP_AT_HARDCODE)) continue;
i++;
}
if (!i) return;
num = i;
bva = ch_malloc( (num+1) * sizeof(struct berval) );
BER_BVZERO( bva );
idx.bv_val = ibuf;
if ( sys ) {
idx.bv_len = 0;
ibuf[0] = '\0';
}
i = 0;
for ( at=start; at && at!=end; at=LDAP_STAILQ_NEXT(at, sat_next)) {
if ( sys && !(at->sat_flags & SLAP_AT_HARDCODE)) continue;
if ( ldap_attributetype2bv( &at->sat_atype, &bv ) == NULL ) {
ber_bvarray_free( bva );
}
if ( !sys ) {
idx.bv_len = sprintf(idx.bv_val, "{%02d}", i);
}
bva[i].bv_len = idx.bv_len + bv.bv_len;
bva[i].bv_val = ch_malloc( bva[i].bv_len + 1 );
strcpy( bva[i].bv_val, ibuf );
strcpy( bva[i].bv_val + idx.bv_len, bv.bv_val );
i++;
bva[i].bv_val = NULL;
ldap_memfree( bv.bv_val );
}
*res = bva;
}
int
at_schema_info( Entry *e )
{
......@@ -626,15 +675,14 @@ at_schema_info( Entry *e )
struct berval val;
struct berval nval;
LDAP_SLIST_FOREACH(at,&attr_list,sat_next) {
LDAP_STAILQ_FOREACH(at,&attr_list,sat_next) {
if( at->sat_flags & SLAP_AT_HIDE ) continue;
if ( ldap_attributetype2bv( &at->sat_atype, &val ) == NULL ) {
return -1;
}
nval.bv_val = at->sat_oid;
nval.bv_len = strlen(at->sat_oid);
ber_str2bv( at->sat_oid, 0, 0, &nval );
if( attr_merge_one( e, ad_attributeTypes, &val, &nval ) )
{
......
......@@ -1035,7 +1035,7 @@ monitor_back_db_init(
return -1;
}
code = at_add(at, 0, &err);
code = at_add(at, 0, NULL, &err);
if ( code ) {
Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
"%s in attributeType \"%s\"\n",
......@@ -1078,7 +1078,7 @@ monitor_back_db_init(
return -1;
}
code = oc_add(oc, 0, &err);
code = oc_add(oc, 0, NULL, &err);
if ( code ) {
Debug( LDAP_DEBUG_ANY,
"objectclass \"%s\": %s \"%s\"\n" ,
......
......@@ -36,6 +36,7 @@
#include "config.h"
static struct berval config_rdn = BER_BVC("cn=config");
static struct berval schema_rdn = BER_BVC("cn=schema");
#ifdef SLAPD_MODULES
typedef struct modpath_s {
......@@ -43,16 +44,18 @@ typedef struct modpath_s {
struct berval mp_path;
BerVarray mp_loads;
} ModPaths;
static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
#endif
typedef struct ConfigFile {
struct ConfigFile *c_sibs;
struct ConfigFile *c_kids;
struct berval c_file;
#ifdef SLAPD_MODULES
ModPaths c_modpaths;
ModPaths *c_modlast;
#endif
AttributeType *c_at_head, *c_at_tail;
ContentRule *c_cr_head, *c_cr_tail;
ObjectClass *c_oc_head, *c_oc_tail;
OidMacro *c_om_head, *c_om_tail;
BerVarray c_dseFiles;
} ConfigFile;
......@@ -63,6 +66,7 @@ typedef struct CfOcInfo {
} CfOcInfo;
typedef struct CfEntryInfo {
struct CfEntryInfo *ce_parent;
struct CfEntryInfo *ce_sibs;
struct CfEntryInfo *ce_kids;
Entry *ce_entry;
......@@ -96,7 +100,7 @@ static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
*cfAd_include;
static ObjectClass *cfOc_schema, *cfOc_global, *cfOc_backend, *cfOc_database,
*cfOc_include, *cfOc_overlay;
*cfOc_include, *cfOc_overlay, *cfOc_module;
static ConfigFile cf_prv, *cfn = &cf_prv;
......@@ -227,9 +231,12 @@ ConfigTable config_back_cf_table[] = {
"DESC 'File for slapd command line options' "
"EQUALITY caseIgnoreMatch "
"SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
/* Use standard 'attributeTypes' attr */
{ "attribute", "attribute", 2, 0, 9, ARG_PAREN|ARG_MAGIC|CFG_ATTR,
&config_generic, NULL, NULL, NULL },
&config_generic, "( OLcfgAt:4 NAME 'olcAttributeTypes' "
"DESC 'OpenLDAP attributeTypes' "
"EQUALITY objectIdentifierFirstComponentMatch "
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.3 X-ORDERED 'VALUES' )",
NULL, NULL },
{ "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
&config_generic, "( OLcfgAt:5 NAME 'olcAttributeOptions' "
"EQUALITY caseIgnoreMatch "
......@@ -276,9 +283,12 @@ ConfigTable config_back_cf_table[] = {
&config_disallows, "( OLcfgAt:15 NAME 'olcDisallows' "
"EQUALITY caseIgnoreMatch "
"SYNTAX OMsDirectoryString )", NULL, NULL },
/* use standard schema */
{ "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT,
&config_generic, NULL, NULL, NULL },
&config_generic, "( OLcfgAt:16 NAME 'olcDitContentRules' "
"DESC 'OpenLDAP DIT content rules' "
"EQUALITY objectIdentifierFirstComponentMatch "
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.16 X-ORDERED 'VALUES' )",
NULL, NULL },
{ "gentlehup", "on|off", 2, 2, 0,
#ifdef SIGHUP
ARG_ON_OFF, &global_gentlehup,
......@@ -340,9 +350,12 @@ ConfigTable config_back_cf_table[] = {
#endif
"( OLcfgAt:31 NAME 'olcModulePath' "
"SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
/* use standard schema */
{ "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
&config_generic, NULL, NULL, NULL },
&config_generic, "( OLcfgAt:32 NAME 'olcObjectClasses' "
"DESC 'OpenLDAP object classes' "
"EQUALITY objectIdentifierFirstComponentMatch "
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.37 X-ORDERED 'VALUES' )",
NULL, NULL },
{ "objectidentifier", NULL, 0, 0, 0, ARG_MAGIC|CFG_OID,
&config_generic, "( OLcfgAt:33 NAME 'olcObjectIdentifier' "
"SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
......@@ -578,7 +591,7 @@ static ConfigOCs cf_ocs[] = {
"olcDefaultSearchBase $ olcDisallows $ olcGentleHUP $ "
"olcIdleTimeout $ olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
"olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcLocalSSF $ "
"olcLogLevel $ olcModuleLoad $ olcModulePath $ olcObjectIdentifier $ "
"olcLogLevel $ olcModulePath $ olcObjectIdentifier $ "
"olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
"olcPlugin $ olcPluginLogFile $ olcReadOnly $ olcReferral $ "
"olcReplicaPidFile $ olcReplicaArgsFile $ olcReplicationInterval $ "
......@@ -594,8 +607,8 @@ static ConfigOCs cf_ocs[] = {
"NAME 'olcSchemaConfig' "
"DESC 'OpenLDAP schema object' "
"SUP olcConfig STRUCTURAL "
"MAY ( olcObjectIdentifier $ attributeTypes $ objectClasses $ "
"ditContentRules ) )", Cft_Schema, &cfOc_schema },
"MAY ( olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
"olcDitContentRules ) )", Cft_Schema, &cfOc_schema },
{ "( OLcfgOc:4 "
"NAME 'olcBackendConfig' "
"DESC 'OpenLDAP Backend-specific options' "
......@@ -620,8 +633,16 @@ static ConfigOCs cf_ocs[] = {
"NAME 'olcIncludeFile' "
"DESC 'OpenLDAP configuration include file' "
"SUP olcConfig STRUCTURAL "
"MAY ( olcInclude $ olcModuleLoad $ olcModulePath $ olcRootDSE ) )",
"MAY ( olcInclude $ olcRootDSE ) )",
Cft_Include, &cfOc_include },
#ifdef SLAPD_MODULES
{ "( OLcfgOc:8 "
"NAME 'olcModuleList' "
"DESC 'OpenLDAP dynamic module info' "
"SUP olcConfig STRUCTURAL "
"MUST olcModuleLoad )",
Cft_Module, &cfOc_module },
#endif
{ NULL, 0, NULL }
};
......@@ -687,11 +708,51 @@ config_generic(ConfigArgs *c) {
case CFG_DEPTH:
c->value_int = c->be->be_max_deref_depth;
break;
case CFG_OID:
oidm_unparse( &c->rvalue_vals );
case CFG_OID: {
ConfigFile *cf = c->private;
if ( !cf )
oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
else if ( cf->c_om_head )
oidm_unparse( &c->rvalue_vals, cf->c_om_head,
cf->c_om_tail, 0 );
if ( !c->rvalue_vals )
rc = 1;
}
break;
case CFG_OC: {
ConfigFile *cf = c->private;
if ( !cf )
oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
else if ( cf->c_oc_head )
oc_unparse( &c->rvalue_vals, cf->c_oc_head,
cf->c_oc_tail, 0 );
if ( !c->rvalue_vals )
rc = 1;
}
break;
case CFG_ATTR: {
ConfigFile *cf = c->private;
if ( !cf )
at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
else if ( cf->c_at_head )
at_unparse( &c->rvalue_vals, cf->c_at_head,
cf->c_at_tail, 0 );
if ( !c->rvalue_vals )
rc = 1;
}
break;
case CFG_DIT: {
ConfigFile *cf = c->private;
if ( !cf )
cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
else if ( cf->c_cr_head )
cr_unparse( &c->rvalue_vals, cf->c_cr_head,
cf->c_cr_tail, 0 );
if ( !c->rvalue_vals )
rc = 1;
}
break;
case CFG_CHECK:
c->value_int = global_schemacheck;
break;
......@@ -725,7 +786,7 @@ config_generic(ConfigArgs *c) {
c->value_string = ch_strdup( c->be->be_replogfile );
break;
case CFG_ROOTDSE: {
ConfigFile *cf = (ConfigFile *)c->line;
ConfigFile *cf = c->private;
if ( cf->c_dseFiles ) {
value_add( &c->rvalue_vals, cf->c_dseFiles );
} else {
......@@ -750,26 +811,24 @@ config_generic(ConfigArgs *c) {
break;
#ifdef SLAPD_MODULES
case CFG_MODLOAD: {
ConfigFile *cf = (ConfigFile *)c->line;
ModPaths *mp;
for (i=0, mp=&cf->c_modpaths; mp; mp=mp->mp_next, i++) {
int j;
if (!mp->mp_loads) continue;
for (j=0; !BER_BVISNULL(&mp->mp_loads[j]); j++) {
ModPaths *mp = c->private;
if (mp->mp_loads) {
int i;
for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
struct berval bv;
bv.bv_val = c->log;
bv.bv_len = sprintf( bv.bv_val, "{%d}{%d}%s", i, j,
mp->mp_loads[j].bv_val );
bv.bv_len = sprintf( bv.bv_val, "{%d}%s", i,
mp->mp_loads[i].bv_val );
value_add_one( &c->rvalue_vals, &bv );
}
}
rc = c->rvalue_vals ? 0 : 1;
}
break;
case CFG_MODPATH: {
ConfigFile *cf = (ConfigFile *)c->line;
ModPaths *mp;
for (i=0, mp=&cf->c_modpaths; mp; mp=mp->mp_next, i++) {
for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
struct berval bv;
if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
continue;
......@@ -898,20 +957,41 @@ config_generic(ConfigArgs *c) {
c->be->be_max_deref_depth = c->value_int;
break;
case CFG_OID:
if(parse_oidm(c->fname, c->lineno, c->argc, c->argv, 1)) return(0);
case CFG_OID: {
OidMacro *om;
if(parse_oidm(c->fname, c->lineno, c->argc, c->argv, 1, &om))
return(1);
if (!cfn->c_om_head) cfn->c_om_head = om;
cfn->c_om_tail = om;
}
break;
case CFG_OC:
if(parse_oc(c->fname, c->lineno, p, c->argv)) return(1);
case CFG_OC: {
ObjectClass *oc;
if(parse_oc(c->fname, c->lineno, p, c->argv, &oc)) return(1);
if (!cfn->c_oc_head) cfn->c_oc_head = oc;
cfn->c_oc_tail = oc;
}
break;
case CFG_DIT:
if(parse_cr(c->fname, c->lineno, p, c->argv)) return(1);
case CFG_DIT: {
ContentRule *cr;
if(parse_cr(c->fname, c->lineno, p, c->argv, &cr)) return(1);
if (!cfn->c_cr_head) cfn->c_cr_head = cr;
cfn->c_cr_tail = cr;
}
break;
case CFG_ATTR:
if(parse_at(c->fname, c->lineno, p, c->argv)) return(1);
case CFG_ATTR: {
AttributeType *at;
if(parse_at(c->fname, c->lineno, p, c->argv, &at)) return(1);
if (!cfn->c_at_head) cfn->c_at_head = at;
cfn->c_at_tail = at;
}
break;
case CFG_ATOPT:
......@@ -1007,7 +1087,7 @@ config_generic(ConfigArgs *c) {
{
struct berval bv;
ber_str2bv(c->line, 0, 1, &bv);
ber_bvarray_add( &cfn->c_modlast->mp_loads, &bv );
ber_bvarray_add( &modcur->mp_loads, &bv );
}
break;
......@@ -1017,16 +1097,18 @@ config_generic(ConfigArgs *c) {
{
ModPaths *mp;
if (!cfn->c_modpaths.mp_loads) {
mp = &cfn->c_modpaths;
if (!modpaths.mp_loads) {
mp = &modpaths;
} else {
mp = ch_malloc( sizeof( ModPaths ));
cfn->c_modlast->mp_next = mp;
modlast->mp_next = mp;
}
ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
mp->mp_next = NULL;
mp->mp_loads = NULL;
cfn->c_modlast = mp;
modlast = mp;
if ( c->op == SLAP_CONFIG_ADD )
modcur = mp;
}
break;
......@@ -1064,8 +1146,8 @@ config_generic(ConfigArgs *c) {
static int
config_fname(ConfigArgs *c) {
if(c->op == SLAP_CONFIG_EMIT) {
if (c->line) {
ConfigFile *cf = (ConfigFile *)c->line;
if (c->private) {
ConfigFile *cf = c->private;
value_add_one( &c->rvalue_vals, &cf->c_file );
return 0;
}
......@@ -1904,9 +1986,6 @@ config_include(ConfigArgs *c) {
return 1;
}
cf = ch_calloc( 1, sizeof(ConfigFile));
#ifdef SLAPD_MODULES
cf->c_modlast = &cf->c_modpaths;
#endif
if ( cfn->c_kids ) {
for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
cf2->c_sibs = cf;
......@@ -2933,6 +3012,13 @@ config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs )
rc = LDAP_CONSTRAINT_VIOLATION;
goto leave;
}
#ifdef SLAPD_MODULES
case Cft_Module:
if ( !last || last->ce_type != Cft_Global ) {
rc = LDAP_CONSTRAINT_VIOLATION;
goto leave;
}
#endif
break;
}
......@@ -2940,10 +3026,15 @@ config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs )
* performing any set actions.
*/
switch (colst[0]->co_type) {
case Cft_Global: /* */
case Cft_Schema:
/* The cn=schema entry is all hardcoded, so never reparse it */
if (last->ce_type == Cft_Global )
goto ok;
/* FALLTHRU */
case Cft_Global:
ca.be = cfb->cb_be;
break;
case Cft_Backend:
if ( last->ce_type == Cft_Backend )
ca.bi = last->ce_bi;
......@@ -2968,6 +3059,27 @@ config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs )
if ( !rs ) /* ignored */
break;
type_ad = cfAd_include;
#ifdef SLAPD_MODULES
case Cft_Module: {
ModPaths *mp;
char *ptr;
ptr = strchr( e->e_name.bv_val, '{' );
if ( !ptr ) {
rc = LDAP_NAMING_VIOLATION;
goto leave;
}
j = atoi(ptr+1);
for (i=0, mp=&modpaths; mp && i<j; mp=mp->mp_next);
/* There is no corresponding modpath for this load? */
if ( i != j ) {
rc = LDAP_NAMING_VIOLATION;
goto leave;
}
module_path( mp->mp_path.bv_val );
ca.private = mp;
}
break;
#endif
}
init_config_argv( &ca );
if ( type_ad ) {
......@@ -3019,7 +3131,9 @@ config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs )
if ( rc ) goto leave;
}
}
ok:
ce = ch_calloc( 1, sizeof(CfEntryInfo) );
ce->ce_parent = last;
ce->ce_entry = entry_dup( e );
ce->ce_entry->e_private = ce;
ce->ce_type = colst[0]->co_type;
......@@ -3146,13 +3260,22 @@ out:
}
static Entry *
config_alloc_entry( struct berval *pdn, struct berval *rdn )
config_alloc_entry( CfEntryInfo *parent, struct berval *rdn )
{
Entry *e = ch_calloc( 1, sizeof(Entry) );
CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
struct berval pdn;
e->e_private = ce;
ce->ce_entry = e;
build_new_dn( &e->e_name, pdn, rdn, NULL );
ce->ce_parent = parent;
if ( parent ) {
pdn = parent->ce_entry->e_nname;
} else {
BER_BVZERO( &pdn );
}
build_new_dn( &e->e_name, &pdn, rdn, NULL );
ber_dupbv( &e->e_nname, &e->e_name );
return e;
}
......@@ -3247,21 +3370,24 @@ config_build_entry( ConfigArgs *c, Entry *e, ObjectClass *oc,
}
static CfEntryInfo *
config_build_includes( ConfigArgs *c, Entry *parent,
config_build_includes( ConfigArgs *c, CfEntryInfo *ceparent,
Operation *op, SlapReply *rs )
{
Entry *e;
int i;
ConfigFile *cf = (ConfigFile *)c->line;
CfEntryInfo *ce, *ceparent, *ceprev;
ConfigFile *cf = c->private;
CfEntryInfo *ce, *ceprev;
ceparent = parent->e_private;
if ( ceparent->ce_kids ) {
for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
ceprev = ceprev->ce_sibs );
}
for (i=0; cf; cf=cf->c_sibs, i++) {
c->value_dn.bv_val = c->log;
c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=include{%d}", i);
e = config_alloc_entry( &parent->e_nname, &c->value_dn );
c->line = (char *)cf;
c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=include{%02d}", i);