Slapi_Backend * slapi_be_new( const char *type, const char *name, int isprivate, int logchanges ) { Slapi_Backend *be; int i; /* should add some locking here to prevent concurrent access */ if ( nbackends == maxbackends ) { int oldsize = maxbackends; maxbackends += BACKEND_GRAB_SIZE; backends = (Slapi_Backend **) slapi_ch_realloc( (char *) backends, maxbackends * sizeof(Slapi_Backend *) ); memset( &backends[oldsize], '\0', BACKEND_GRAB_SIZE * sizeof(Slapi_Backend *) ); } for (i=0; ((i<maxbackends) && (backends[i])); i++) ; PR_ASSERT(i<maxbackends); be = (Slapi_Backend *) slapi_ch_calloc(1, sizeof(Slapi_Backend)); be->be_lock = slapi_new_rwlock(); be_init( be, type, name, isprivate, logchanges, defsize, deftime ); backends[i] = be; nbackends++; slapi_log_err(SLAPI_LOG_TRACE, "slapi_be_new", "Added new backend name [%s] type [%s] nbackends [%d]\n", name, type, nbackends); return( be ); }
/* * ************************************************************************** * API * ************************************************************************** */ CSNGen* csngen_new (ReplicaId rid, Slapi_Attr *state) { int rc = CSN_SUCCESS; CSNGen *gen = NULL; gen = (CSNGen*)slapi_ch_calloc (1, sizeof (CSNGen)); if (gen == NULL) { slapi_log_err(SLAPI_LOG_ERR, "csngen_new", "Memory allocation failed\n"); return NULL; } /* create lock to control the access to the state information */ gen->lock = slapi_new_rwlock(); if (gen->lock == NULL) { slapi_log_err(SLAPI_LOG_ERR, "csngen_new", "Failed to create lock\n"); rc = CSN_NSPR_ERROR; goto done; } /* initialize callback list */ _csngen_init_callbacks (gen); gen->state.rid = rid; if (state) { rc = _csngen_parse_state (gen, state); if (rc != CSN_SUCCESS) { goto done; } } else { /* new generator */ gen->state.sampled_time = current_time (); gen->state.local_offset = 0; gen->state.remote_offset = 0; gen->state.seq_num = 0; } done: if (rc != CSN_SUCCESS) { if (gen) { csngen_free (&gen); } return NULL; } return gen; }
void init_features( void ) { supported_features_lock = slapi_new_rwlock(); if (supported_features_lock == NULL) { slapi_log_err(SLAPI_LOG_ERR, "startup", "init_features - failed to create lock.\n"); exit(1); } slapi_register_supported_feature( LDAP_FEATURE_ALL_OP_ATTRS ); }
/* * memberof_config() * * Read configuration and create a configuration data structure. * This is called after the server has configured itself so we can * perform checks with regards to suffixes if it ever becomes * necessary. * Returns an LDAP error code (LDAP_SUCCESS if all goes well). */ int memberof_config(Slapi_Entry *config_e, Slapi_PBlock *pb) { int returncode = LDAP_SUCCESS; char returntext[SLAPI_DSE_RETURNTEXT_SIZE]; if ( inited ) { slapi_log_err(SLAPI_LOG_ERR, MEMBEROF_PLUGIN_SUBSYSTEM, "memberof_config - Only one memberOf plugin instance can be used\n" ); return( LDAP_PARAM_ERROR ); } /* initialize the RW lock to protect the main config */ memberof_config_lock = slapi_new_rwlock(); /* initialize fields */ if (SLAPI_DSE_CALLBACK_OK == memberof_validate_config(NULL, NULL, config_e, &returncode, returntext, NULL)) { memberof_apply_config(NULL, NULL, config_e, &returncode, returntext, NULL); } /* * config DSE must be initialized before we get here we only need the dse callbacks * for the plugin entry, but not the shared config entry. */ if (returncode == LDAP_SUCCESS) { const char *config_dn = slapi_sdn_get_dn(memberof_get_plugin_area()); slapi_config_register_callback_plugin(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP | DSE_FLAG_PLUGIN, config_dn, LDAP_SCOPE_BASE, MEMBEROF_CONFIG_FILTER, memberof_validate_config, NULL,pb); slapi_config_register_callback_plugin(SLAPI_OPERATION_MODIFY, DSE_FLAG_POSTOP | DSE_FLAG_PLUGIN, config_dn, LDAP_SCOPE_BASE, MEMBEROF_CONFIG_FILTER, memberof_apply_config, NULL, pb); slapi_config_register_callback_plugin(SLAPI_OPERATION_MODRDN, DSE_FLAG_PREOP | DSE_FLAG_PLUGIN, config_dn, LDAP_SCOPE_BASE, MEMBEROF_CONFIG_FILTER, dont_allow_that, NULL, pb); slapi_config_register_callback_plugin(SLAPI_OPERATION_DELETE, DSE_FLAG_PREOP | DSE_FLAG_PLUGIN, config_dn, LDAP_SCOPE_BASE, MEMBEROF_CONFIG_FILTER, dont_allow_that, NULL, pb); slapi_config_register_callback_plugin(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP | DSE_FLAG_PLUGIN, config_dn, LDAP_SCOPE_BASE, MEMBEROF_CONFIG_FILTER, memberof_search, NULL, pb); } inited = 1; if (returncode != LDAP_SUCCESS) { slapi_log_err(SLAPI_LOG_ERR, MEMBEROF_PLUGIN_SUBSYSTEM, "memberof_config - Error %d: %s\n", returncode, returntext); } return returncode; }
int aclgroup_init () { aclUserGroups = ( aclGroupCache * ) slapi_ch_calloc (1, sizeof ( aclGroupCache ) ); if ( NULL == (aclUserGroups->aclg_rwlock = slapi_new_rwlock())) { slapi_log_error(SLAPI_LOG_FATAL, plugin_name, "Unable to allocate RWLOCK for group cache\n"); return 1; } return 0; }
static sasl_map_private *sasl_map_new_private(void) { Slapi_RWLock *new_lock = slapi_new_rwlock(); sasl_map_private *new_priv = NULL; if (NULL == new_lock) { return NULL; } new_priv = (sasl_map_private *)slapi_ch_calloc(1,sizeof(sasl_map_private)); new_priv->lock = new_lock; return new_priv; }
/* * aclanom_init (); * Generate a profile for the anonymous user. We can use this profile * later to determine what resources the client is allowed to. * * Dependency: * Before calling this, it is assumed that all the ACLs have been read * and parsed. * * We will go thru all the ACL and pick the ANYONE ACL and generate the anom * profile. * */ int aclanom_init () { acl_anom_profile = (struct anom_profile * ) slapi_ch_calloc (1, sizeof ( struct anom_profile ) ); if (( anom_rwlock = slapi_new_rwlock()) == NULL ) { slapi_log_err(SLAPI_LOG_ERR, plugin_name, "aclanom_init - Failed in getting the ANOM rwlock\n" ); return 1; } return 0; }
static int _csngen_init_callbacks (CSNGen *gen) { /* create a lock to control access to the callback list */ gen->callbacks.lock = slapi_new_rwlock(); if (gen->callbacks.lock == NULL) { return CSN_NSPR_ERROR; } gen->callbacks.list = dl_new (); dl_init (gen->callbacks.list, 0); return CSN_SUCCESS; }
/* Plugin startup function, when this is called any other plugins should already be initialized, so it's safe to e.g. perform internal searches, which is needed to retrieve the plugin configuration */ int acct_policy_start( Slapi_PBlock *pb ) { acctPluginCfg *cfg; void *plugin_id = get_identity(); Slapi_DN *plugindn = NULL; char *config_area = NULL; if(slapi_plugin_running(pb)){ return 0; } slapi_pblock_get(pb, SLAPI_TARGET_SDN, &plugindn); acct_policy_set_plugin_sdn(slapi_sdn_dup(plugindn)); /* Set the alternate config area if one is defined. */ slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_AREA, &config_area); if (config_area) { acct_policy_set_config_area(slapi_sdn_new_normdn_byval(config_area)); } if(config_rwlock == NULL){ if((config_rwlock = slapi_new_rwlock()) == NULL){ return( CALLBACK_ERR ); } } /* Load plugin configuration */ if( acct_policy_load_config_startup( pb, plugin_id ) ) { slapi_log_err(SLAPI_LOG_ERR, PLUGIN_NAME, "acct_policy_start failed to load configuration\n" ); return( CALLBACK_ERR ); } /* Show the configuration */ cfg = get_config(); slapi_log_err(SLAPI_LOG_PLUGIN, PLUGIN_NAME, "acct_policy_start - config: " "stateAttrName=%s altStateAttrName=%s specAttrName=%s limitAttrName=%s " "alwaysRecordLogin=%d\n", cfg->state_attr_name, cfg->alt_state_attr_name?cfg->alt_state_attr_name:"not configured", cfg->spec_attr_name, cfg->limit_attr_name, cfg->always_record_login); return( CALLBACK_OK ); }
/* * Initialize the list structure which contains the list * of outstanding persistent searches. This must be * called early during server startup. */ void ps_init_psearch_system() { if ( !PS_IS_INITIALIZED()) { psearch_list = (PSearch_List *) slapi_ch_calloc( 1, sizeof( PSearch_List )); if (( psearch_list->pl_rwlock = slapi_new_rwlock()) == NULL ) { LDAPDebug( LDAP_DEBUG_ANY, "init_psearch_list: cannot initialize lock structure. " "The server is terminating.\n", 0, 0, 0 ); exit( -1 ); } if (( psearch_list->pl_cvarlock = PR_NewLock()) == NULL ) { LDAPDebug( LDAP_DEBUG_ANY, "init_psearch_list: cannot create new lock. " "The server is terminating.\n", 0, 0, 0 ); exit( -1 ); } if (( psearch_list->pl_cvar = PR_NewCondVar( psearch_list->pl_cvarlock )) == NULL ) { LDAPDebug( LDAP_DEBUG_ANY, "init_psearch_list: cannot create new condition variable. " "The server is terminating.\n", 0, 0, 0 ); exit( -1 ); } psearch_list->pl_head = NULL; } }