Back to index

openldap  2.4.31
schema.c
Go to the documentation of this file.
00001 /* schema.c - routines to manage schema definitions */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 1998-2012 The OpenLDAP Foundation.
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted only as authorized by the OpenLDAP
00010  * Public License.
00011  *
00012  * A copy of this license is available in the file LICENSE in the
00013  * top-level directory of the distribution or, alternatively, at
00014  * <http://www.OpenLDAP.org/license.html>.
00015  */
00016 
00017 #include "portable.h"
00018 
00019 #include <stdio.h>
00020 
00021 #include <ac/ctype.h>
00022 #include <ac/string.h>
00023 #include <ac/socket.h>
00024 
00025 #include "slap.h"
00026 #include "lutil.h"
00027 
00028 
00029 int
00030 schema_info( Entry **entry, const char **text )
00031 {
00032        AttributeDescription *ad_structuralObjectClass
00033               = slap_schema.si_ad_structuralObjectClass;
00034        AttributeDescription *ad_objectClass
00035               = slap_schema.si_ad_objectClass;
00036        AttributeDescription *ad_createTimestamp
00037               = slap_schema.si_ad_createTimestamp;
00038        AttributeDescription *ad_modifyTimestamp
00039               = slap_schema.si_ad_modifyTimestamp;
00040 
00041        Entry         *e;
00042        struct berval vals[5];
00043        struct berval nvals[5];
00044 
00045        e = entry_alloc();
00046        if( e == NULL ) {
00047               /* Out of memory, do something about it */
00048               Debug( LDAP_DEBUG_ANY, 
00049                      "schema_info: entry_alloc failed - out of memory.\n", 0, 0, 0 );
00050               *text = "out of memory";
00051               return LDAP_OTHER;
00052        }
00053 
00054        e->e_attrs = NULL;
00055        /* backend-specific schema info should be created by the
00056         * backend itself
00057         */
00058        ber_dupbv( &e->e_name, &frontendDB->be_schemadn );
00059        ber_dupbv( &e->e_nname, &frontendDB->be_schemandn );
00060        e->e_private = NULL;
00061 
00062        BER_BVSTR( &vals[0], "subentry" );
00063        if( attr_merge_one( e, ad_structuralObjectClass, vals, NULL ) ) {
00064               /* Out of memory, do something about it */
00065               entry_free( e );
00066               *text = "out of memory";
00067               return LDAP_OTHER;
00068        }
00069 
00070        BER_BVSTR( &vals[0], "top" );
00071        BER_BVSTR( &vals[1], "subentry" );
00072        BER_BVSTR( &vals[2], "subschema" );
00073        BER_BVSTR( &vals[3], "extensibleObject" );
00074        BER_BVZERO( &vals[4] );
00075        if ( attr_merge( e, ad_objectClass, vals, NULL ) ) {
00076               /* Out of memory, do something about it */
00077               entry_free( e );
00078               *text = "out of memory";
00079               return LDAP_OTHER;
00080        }
00081 
00082        {
00083               int rc;
00084               AttributeDescription *desc = NULL;
00085               struct berval rdn = frontendDB->be_schemadn;
00086               vals[0].bv_val = ber_bvchr( &rdn, '=' );
00087 
00088               if( vals[0].bv_val == NULL ) {
00089                      *text = "improperly configured subschema subentry";
00090                      return LDAP_OTHER;
00091               }
00092 
00093               vals[0].bv_val++;
00094               vals[0].bv_len = rdn.bv_len - (vals[0].bv_val - rdn.bv_val);
00095               rdn.bv_len -= vals[0].bv_len + 1;
00096 
00097               rc = slap_bv2ad( &rdn, &desc, text );
00098 
00099               if( rc != LDAP_SUCCESS ) {
00100                      entry_free( e );
00101                      *text = "improperly configured subschema subentry";
00102                      return LDAP_OTHER;
00103               }
00104 
00105               nvals[0].bv_val = ber_bvchr( &frontendDB->be_schemandn, '=' );
00106               assert( nvals[0].bv_val != NULL );
00107               nvals[0].bv_val++;
00108               nvals[0].bv_len = frontendDB->be_schemandn.bv_len -
00109                      (nvals[0].bv_val - frontendDB->be_schemandn.bv_val);
00110 
00111               if ( attr_merge_one( e, desc, vals, nvals ) ) {
00112                      /* Out of memory, do something about it */
00113                      entry_free( e );
00114                      *text = "out of memory";
00115                      return LDAP_OTHER;
00116               }
00117        }
00118 
00119        {
00120               char          timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
00121 
00122               /*
00123                * According to RFC 4512:
00124 
00125    Servers SHOULD maintain the 'creatorsName', 'createTimestamp',       
00126    'modifiersName', and 'modifyTimestamp' attributes for all entries of 
00127    the DIT. 
00128 
00129                * to be conservative, we declare schema created 
00130                * AND modified at server startup time ...
00131                */
00132 
00133               vals[0].bv_val = timebuf;
00134               vals[0].bv_len = sizeof( timebuf );
00135 
00136               slap_timestamp( &starttime, vals );
00137 
00138               if( attr_merge_one( e, ad_createTimestamp, vals, NULL ) ) {
00139                      /* Out of memory, do something about it */
00140                      entry_free( e );
00141                      *text = "out of memory";
00142                      return LDAP_OTHER;
00143               }
00144               if( attr_merge_one( e, ad_modifyTimestamp, vals, NULL ) ) {
00145                      /* Out of memory, do something about it */
00146                      entry_free( e );
00147                      *text = "out of memory";
00148                      return LDAP_OTHER;
00149               }
00150        }
00151 
00152        if ( syn_schema_info( e ) 
00153               || mr_schema_info( e )
00154               || mru_schema_info( e )
00155               || at_schema_info( e )
00156               || oc_schema_info( e )
00157               || cr_schema_info( e ) )
00158        {
00159               /* Out of memory, do something about it */
00160               entry_free( e );
00161               *text = "out of memory";
00162               return LDAP_OTHER;
00163        }
00164        
00165        *entry = e;
00166        return LDAP_SUCCESS;
00167 }