mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Indent the plugin accordingly to our style guidelines.
Used indent -kr -nut dna.c for most of the changes
This commit is contained in:
parent
70d5209b11
commit
6f4d71d2cc
@ -68,7 +68,8 @@
|
||||
#define DNA_PLUGIN_SUBSYSTEM "ipa-dna-plugin"
|
||||
#define DNA_PLUGIN_VERSION 0x00010000
|
||||
|
||||
#define DNA_DN "cn=ipa-dna,cn=plugins,cn=config" /* temporary */
|
||||
/* temporary */
|
||||
#define DNA_DN "cn=ipa-dna,cn=plugins,cn=config"
|
||||
|
||||
#define DNA_SUCCESS 0
|
||||
#define DNA_FAILURE -1
|
||||
@ -89,7 +90,8 @@
|
||||
|
||||
static Slapi_PluginDesc pdesc = { FEATURE_DESC,
|
||||
"FreeIPA project", "FreeIPA/1.0",
|
||||
PLUGIN_DESC };
|
||||
PLUGIN_DESC
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
@ -147,7 +149,8 @@ static void freeConfigEntry(configEntry **entry);
|
||||
*/
|
||||
static char *dna_get_dn(Slapi_PBlock * pb);
|
||||
static int dna_dn_is_config(char *dn);
|
||||
static int dna_get_next_value(configEntry *config_entry, char **next_value_ret);
|
||||
static int dna_get_next_value(configEntry * config_entry,
|
||||
char **next_value_ret);
|
||||
|
||||
/**
|
||||
*
|
||||
@ -240,7 +243,8 @@ int ipa_dna_init( Slapi_PBlock *pb )
|
||||
int status = DNA_SUCCESS;
|
||||
char *plugin_identity = NULL;
|
||||
|
||||
slapi_log_error( SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM , "--> ipa_dna_init\n");
|
||||
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
|
||||
"--> ipa_dna_init\n");
|
||||
|
||||
/**
|
||||
* Store the plugin identity for later use.
|
||||
@ -264,8 +268,7 @@ int ipa_dna_init( Slapi_PBlock *pb )
|
||||
slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_ADD_FN,
|
||||
(void *) dna_add_pre_op) != 0 ||
|
||||
/* the config change checking post op */
|
||||
slapi_register_plugin(
|
||||
"postoperation", /* op type */
|
||||
slapi_register_plugin("postoperation", /* op type */
|
||||
1, /* Enabled */
|
||||
"ipa_dna_init", /* this function desc */
|
||||
dna_postop_init, /* init func for post op */
|
||||
@ -273,14 +276,14 @@ int ipa_dna_init( Slapi_PBlock *pb )
|
||||
NULL, /* ? */
|
||||
plugin_identity /* access control */
|
||||
)
|
||||
)
|
||||
{
|
||||
) {
|
||||
slapi_log_error(SLAPI_LOG_FATAL, DNA_PLUGIN_SUBSYSTEM,
|
||||
"ipa_dna_init: failed to register plugin\n");
|
||||
status = DNA_FAILURE;
|
||||
}
|
||||
|
||||
slapi_log_error( SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM , "<-- ipa_dna_init\n");
|
||||
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
|
||||
"<-- ipa_dna_init\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -300,9 +303,7 @@ static int dna_postop_init(Slapi_PBlock *pb)
|
||||
slapi_pblock_set(pb, SLAPI_PLUGIN_POST_DELETE_FN,
|
||||
(void *) dna_config_check_post_op) != 0 ||
|
||||
slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODIFY_FN,
|
||||
(void *) dna_config_check_post_op ) != 0
|
||||
)
|
||||
{
|
||||
(void *) dna_config_check_post_op) != 0) {
|
||||
slapi_log_error(SLAPI_LOG_FATAL, DNA_PLUGIN_SUBSYSTEM,
|
||||
"dna_postop_init: failed to register plugin\n");
|
||||
status = DNA_FAILURE;
|
||||
@ -321,14 +322,14 @@ static int dna_start( Slapi_PBlock *pb )
|
||||
{
|
||||
char *plugindn = NULL;
|
||||
|
||||
slapi_log_error( SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM , "--> dna_start\n");
|
||||
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
|
||||
"--> dna_start\n");
|
||||
|
||||
config = &dna_anchor.list;
|
||||
g_dna_cache_lock = PR_NewRWLock(PR_RWLOCK_RANK_NONE, "dna");
|
||||
g_new_value_lock = slapi_new_mutex();
|
||||
|
||||
if(!g_dna_cache_lock || !g_new_value_lock)
|
||||
{
|
||||
if (!g_dna_cache_lock || !g_new_value_lock) {
|
||||
slapi_log_error(SLAPI_LOG_FATAL, DNA_PLUGIN_SUBSYSTEM,
|
||||
"dna_start: lock creation failed\n");
|
||||
|
||||
@ -341,14 +342,11 @@ static int dna_start( Slapi_PBlock *pb )
|
||||
* hardcoding of DN's in the code.
|
||||
*/
|
||||
slapi_pblock_get(pb, SLAPI_TARGET_DN, &plugindn);
|
||||
if (plugindn == NULL || strlen(plugindn) == 0)
|
||||
{
|
||||
if (plugindn == NULL || strlen(plugindn) == 0) {
|
||||
slapi_log_error(SLAPI_LOG_PLUGIN, DNA_PLUGIN_SUBSYSTEM,
|
||||
"dna_start: had to use hard coded config dn\n");
|
||||
plugindn = DNA_DN;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
slapi_log_error(SLAPI_LOG_PLUGIN, DNA_PLUGIN_SUBSYSTEM,
|
||||
"dna_start: config at %s\n", plugindn);
|
||||
|
||||
@ -360,15 +358,16 @@ static int dna_start( Slapi_PBlock *pb )
|
||||
* Load the config for our plug-in
|
||||
*/
|
||||
PR_INIT_CLIST(config);
|
||||
if (loadPluginConfig() != DNA_SUCCESS)
|
||||
{
|
||||
if (loadPluginConfig() != DNA_SUCCESS) {
|
||||
slapi_log_error(SLAPI_LOG_FATAL, DNA_PLUGIN_SUBSYSTEM,
|
||||
"dna_start: unable to load plug-in configuration\n");
|
||||
return DNA_FAILURE;
|
||||
}
|
||||
|
||||
slapi_log_error( SLAPI_LOG_PLUGIN, DNA_PLUGIN_SUBSYSTEM , "dna: ready for service\n");
|
||||
slapi_log_error( SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM , "<-- dna_start\n");
|
||||
slapi_log_error(SLAPI_LOG_PLUGIN, DNA_PLUGIN_SUBSYSTEM,
|
||||
"dna: ready for service\n");
|
||||
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
|
||||
"<-- dna_start\n");
|
||||
|
||||
return DNA_SUCCESS;
|
||||
}
|
||||
@ -380,11 +379,13 @@ static int dna_start( Slapi_PBlock *pb )
|
||||
*/
|
||||
static int dna_close(Slapi_PBlock * pb)
|
||||
{
|
||||
slapi_log_error( SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM , "--> dna_close\n");
|
||||
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
|
||||
"--> dna_close\n");
|
||||
|
||||
deleteConfig();
|
||||
|
||||
slapi_log_error( SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM , "<-- dna_close\n");
|
||||
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
|
||||
"<-- dna_close\n");
|
||||
|
||||
return DNA_SUCCESS;
|
||||
}
|
||||
@ -407,7 +408,8 @@ static int loadPluginConfig()
|
||||
Slapi_PBlock *search_pb;
|
||||
Slapi_Entry **entries = NULL;
|
||||
|
||||
slapi_log_error( SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM , "--> loadPluginConfig\n");
|
||||
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
|
||||
"--> loadPluginConfig\n");
|
||||
|
||||
dna_write_lock();
|
||||
deleteConfig();
|
||||
@ -415,25 +417,24 @@ static int loadPluginConfig()
|
||||
search_pb = slapi_pblock_new();
|
||||
|
||||
slapi_search_internal_set_pb(search_pb, DNA_DN, LDAP_SCOPE_SUBTREE,
|
||||
"objectclass=*", NULL, 0, NULL, NULL, getPluginID(), 0);
|
||||
"objectclass=*", NULL, 0, NULL, NULL,
|
||||
getPluginID(), 0);
|
||||
slapi_search_internal_pb(search_pb);
|
||||
slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_RESULT, &result);
|
||||
|
||||
if (status != DNA_SUCCESS)
|
||||
{
|
||||
if (status != DNA_SUCCESS) {
|
||||
status = DNA_SUCCESS;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
|
||||
if (NULL == entries || entries[0] == NULL)
|
||||
{
|
||||
slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES,
|
||||
&entries);
|
||||
if (NULL == entries || entries[0] == NULL) {
|
||||
status = DNA_SUCCESS;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
for (i = 0; (entries[i] != NULL); i++)
|
||||
{
|
||||
for (i = 0; (entries[i] != NULL); i++) {
|
||||
status = parseConfigEntry(entries[i]);
|
||||
}
|
||||
|
||||
@ -441,7 +442,8 @@ cleanup:
|
||||
slapi_free_search_results_internal(search_pb);
|
||||
slapi_pblock_destroy(search_pb);
|
||||
dna_unlock();
|
||||
slapi_log_error( SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM , "<-- loadPluginConfig\n");
|
||||
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
|
||||
"<-- loadPluginConfig\n");
|
||||
|
||||
return status;
|
||||
}
|
||||
@ -454,7 +456,8 @@ static int parseConfigEntry(Slapi_Entry *e)
|
||||
PRCList *list = NULL;
|
||||
int entry_added = 0;
|
||||
|
||||
slapi_log_error( SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM , "--> parseConfigEntry\n");
|
||||
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
|
||||
"--> parseConfigEntry\n");
|
||||
|
||||
entry = (configEntry *) slapi_ch_calloc(1, sizeof(configEntry));
|
||||
if (0 == entry)
|
||||
@ -465,61 +468,66 @@ static int parseConfigEntry(Slapi_Entry *e)
|
||||
entry->dn = strdup(value);
|
||||
}
|
||||
|
||||
slapi_log_error( SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM , "----------> dn [%s] \n",entry->dn,0,0);
|
||||
slapi_log_error(SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM,
|
||||
"----------> dn [%s] \n", entry->dn, 0, 0);
|
||||
|
||||
value = slapi_entry_attr_get_charptr(e, DNA_TYPE);
|
||||
if (value) {
|
||||
entry->type = value;
|
||||
}
|
||||
else
|
||||
} else
|
||||
goto bail;
|
||||
|
||||
slapi_log_error( SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM , "----------> dnaType [%s] \n",entry->type,0,0);
|
||||
slapi_log_error(SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM,
|
||||
"----------> dnaType [%s] \n", entry->type, 0, 0);
|
||||
|
||||
value = slapi_entry_attr_get_charptr(e, DNA_NEXTVAL);
|
||||
if (value) {
|
||||
entry->nextval = strtoul(value, 0, 0);
|
||||
slapi_ch_free_string(&value);
|
||||
value = 0;
|
||||
}
|
||||
else
|
||||
} else
|
||||
goto bail;
|
||||
|
||||
slapi_log_error( SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM , "----------> dnaNextValue [%d] \n",entry->nextval,0,0);
|
||||
slapi_log_error(SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM,
|
||||
"----------> dnaNextValue [%d] \n", entry->nextval, 0,
|
||||
0);
|
||||
|
||||
value = slapi_entry_attr_get_charptr(e, DNA_PREFIX);
|
||||
if (value) {
|
||||
entry->prefix = value;
|
||||
}
|
||||
|
||||
slapi_log_error( SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM , "----------> dnaPrefix [%s] \n",entry->prefix,0,0);
|
||||
slapi_log_error(SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM,
|
||||
"----------> dnaPrefix [%s] \n", entry->prefix, 0, 0);
|
||||
|
||||
value = slapi_entry_attr_get_charptr(e, DNA_INTERVAL);
|
||||
if (value) {
|
||||
entry->interval = strtoul(value, 0, 0);
|
||||
slapi_ch_free_string(&value);
|
||||
value = 0;
|
||||
}
|
||||
else
|
||||
} else
|
||||
goto bail;
|
||||
|
||||
slapi_log_error( SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM , "----------> dnaInterval [%s] \n",value,0,0);
|
||||
slapi_log_error(SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM,
|
||||
"----------> dnaInterval [%s] \n", value, 0, 0);
|
||||
|
||||
value = slapi_entry_attr_get_charptr(e, DNA_GENERATE);
|
||||
if (value) {
|
||||
entry->generate = value;
|
||||
}
|
||||
|
||||
slapi_log_error( SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM , "----------> dnaMagicRegen [%s] \n",entry->generate,0,0);
|
||||
slapi_log_error(SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM,
|
||||
"----------> dnaMagicRegen [%s] \n", entry->generate,
|
||||
0, 0);
|
||||
|
||||
value = slapi_entry_attr_get_charptr(e, DNA_FILTER);
|
||||
if (value) {
|
||||
entry->filter = slapi_str2filter(value);
|
||||
}
|
||||
else
|
||||
} else
|
||||
goto bail;
|
||||
|
||||
slapi_log_error( SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM , "----------> dnaFilter [%s] \n",value,0,0);
|
||||
slapi_log_error(SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM,
|
||||
"----------> dnaFilter [%s] \n", value, 0, 0);
|
||||
|
||||
slapi_ch_free_string(&value);
|
||||
value = 0;
|
||||
@ -530,7 +538,8 @@ static int parseConfigEntry(Slapi_Entry *e)
|
||||
entry->scope = canonical_dn;
|
||||
}
|
||||
|
||||
slapi_log_error( SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM , "----------> dnaScope [%s] \n",entry->scope,0,0);
|
||||
slapi_log_error(SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM,
|
||||
"----------> dnaScope [%s] \n", entry->scope, 0, 0);
|
||||
|
||||
|
||||
/**
|
||||
@ -541,11 +550,9 @@ static int parseConfigEntry(Slapi_Entry *e)
|
||||
* code to be simple and quick and
|
||||
* cunningly linear
|
||||
*/
|
||||
if(!PR_CLIST_IS_EMPTY(config))
|
||||
{
|
||||
if (!PR_CLIST_IS_EMPTY(config)) {
|
||||
list = PR_LIST_HEAD(config);
|
||||
while(list != config)
|
||||
{
|
||||
while (list != config) {
|
||||
config_entry = (configEntry *) list;
|
||||
|
||||
if (slapi_attr_type_cmp(config_entry->type, entry->type, 1))
|
||||
@ -554,12 +561,12 @@ static int parseConfigEntry(Slapi_Entry *e)
|
||||
if (slapi_filter_compare(config_entry->filter, entry->filter))
|
||||
goto next;
|
||||
|
||||
if(slapi_dn_issuffix(entry->scope,config_entry->scope))
|
||||
{
|
||||
if (slapi_dn_issuffix(entry->scope, config_entry->scope)) {
|
||||
PR_INSERT_BEFORE(&(entry->list), list);
|
||||
slapi_log_error(SLAPI_LOG_CONFIG,
|
||||
DNA_PLUGIN_SUBSYSTEM,
|
||||
"store [%s] before [%s] \n",entry->scope,config_entry->scope,0);
|
||||
"store [%s] before [%s] \n", entry->scope,
|
||||
config_entry->scope, 0);
|
||||
entry_added = 1;
|
||||
break;
|
||||
}
|
||||
@ -567,33 +574,33 @@ static int parseConfigEntry(Slapi_Entry *e)
|
||||
next:
|
||||
list = PR_NEXT_LINK(list);
|
||||
|
||||
if(config == list)
|
||||
{
|
||||
if (config == list) {
|
||||
/* add to tail */
|
||||
PR_INSERT_BEFORE(&(entry->list), list);
|
||||
slapi_log_error( SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM , "store [%s] at tail\n",entry->scope,0,0);
|
||||
slapi_log_error(SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM,
|
||||
"store [%s] at tail\n", entry->scope, 0,
|
||||
0);
|
||||
entry_added = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* first entry */
|
||||
PR_INSERT_LINK(&(entry->list), config);
|
||||
slapi_log_error( SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM , "store [%s] at head \n",entry->scope,0,0);
|
||||
slapi_log_error(SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM,
|
||||
"store [%s] at head \n", entry->scope, 0, 0);
|
||||
entry_added = 1;
|
||||
}
|
||||
|
||||
bail:
|
||||
if(0 == entry_added)
|
||||
{
|
||||
if (0 == entry_added) {
|
||||
slapi_log_error(SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM,
|
||||
"config entry [%s] skipped\n", entry->dn, 0, 0);
|
||||
freeConfigEntry(&entry);
|
||||
}
|
||||
|
||||
slapi_log_error( SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM , "<-- parseConfigEntry\n");
|
||||
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
|
||||
"<-- parseConfigEntry\n");
|
||||
|
||||
return DNA_SUCCESS;
|
||||
}
|
||||
@ -602,8 +609,7 @@ static void freeConfigEntry(configEntry **entry)
|
||||
{
|
||||
configEntry *e = *entry;
|
||||
|
||||
if(e->dn)
|
||||
{
|
||||
if (e->dn) {
|
||||
slapi_log_error(SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM,
|
||||
"freeing config entry [%s]\n", e->dn, 0, 0);
|
||||
slapi_ch_free_string(&e->dn);
|
||||
@ -637,8 +643,7 @@ static void deleteConfig()
|
||||
{
|
||||
PRCList *list;
|
||||
|
||||
while(!PR_CLIST_IS_EMPTY(config))
|
||||
{
|
||||
while (!PR_CLIST_IS_EMPTY(config)) {
|
||||
list = PR_LIST_HEAD(config);
|
||||
deleteConfigEntry(list);
|
||||
}
|
||||
@ -654,18 +659,20 @@ static void deleteConfig()
|
||||
static char *dna_get_dn(Slapi_PBlock * pb)
|
||||
{
|
||||
char *dn = 0;
|
||||
slapi_log_error( SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM , "--> dna_get_dn\n");
|
||||
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
|
||||
"--> dna_get_dn\n");
|
||||
|
||||
if(slapi_pblock_get( pb, SLAPI_TARGET_DN, &dn ))
|
||||
{
|
||||
slapi_log_error( SLAPI_LOG_FATAL, DNA_PLUGIN_SUBSYSTEM, "dna_get_dn: failed to get dn of changed entry");
|
||||
if (slapi_pblock_get(pb, SLAPI_TARGET_DN, &dn)) {
|
||||
slapi_log_error(SLAPI_LOG_FATAL, DNA_PLUGIN_SUBSYSTEM,
|
||||
"dna_get_dn: failed to get dn of changed entry");
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/* slapi_dn_normalize( dn );
|
||||
*/
|
||||
bail:
|
||||
slapi_log_error( SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM , "<-- dna_get_dn\n");
|
||||
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
|
||||
"<-- dna_get_dn\n");
|
||||
|
||||
return dn;
|
||||
}
|
||||
@ -677,14 +684,15 @@ static int dna_dn_is_config(char *dn)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
slapi_log_error( SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM , "--> dna_is_config\n");
|
||||
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
|
||||
"--> dna_is_config\n");
|
||||
|
||||
if(slapi_dn_issuffix(dn, getPluginDN()))
|
||||
{
|
||||
if (slapi_dn_issuffix(dn, getPluginDN())) {
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
slapi_log_error( SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM , "<-- dna_is_config\n");
|
||||
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
|
||||
"<-- dna_is_config\n");
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -704,7 +712,8 @@ static int dna_dn_is_config(char *dn)
|
||||
* 2. remove current value, add new value in one operation
|
||||
* 3. if failed, and less than 3 times, goto 1
|
||||
*/
|
||||
static int dna_get_next_value(configEntry *config_entry, char **next_value_ret)
|
||||
static int dna_get_next_value(configEntry * config_entry,
|
||||
char **next_value_ret)
|
||||
{
|
||||
int ret = LDAP_SUCCESS;
|
||||
Slapi_DN *dn = 0;
|
||||
@ -712,7 +721,8 @@ static int dna_get_next_value(configEntry *config_entry, char **next_value_ret)
|
||||
Slapi_Entry *e = 0;
|
||||
int attempts = 0;
|
||||
|
||||
slapi_log_error( SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM , "--> dna_get_next_value\n");
|
||||
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
|
||||
"--> dna_get_next_value\n");
|
||||
|
||||
/* get pre-requisites to search */
|
||||
dn = slapi_sdn_new_dn_byref(config_entry->dn);
|
||||
@ -729,25 +739,23 @@ static int dna_get_next_value(configEntry *config_entry, char **next_value_ret)
|
||||
|
||||
slapi_lock_mutex(g_new_value_lock);
|
||||
|
||||
while(attempts < 3 && LDAP_SUCCESS == ret)
|
||||
{
|
||||
while (attempts < 3 && LDAP_SUCCESS == ret) {
|
||||
attempts++;
|
||||
|
||||
/* do update */
|
||||
if(e)
|
||||
{
|
||||
if (e) {
|
||||
slapi_entry_free(e);
|
||||
e = 0;
|
||||
}
|
||||
|
||||
ret = slapi_search_internal_get_entry( dn, attrlist, &e,getPluginID());
|
||||
if(LDAP_SUCCESS == ret)
|
||||
{
|
||||
ret =
|
||||
slapi_search_internal_get_entry(dn, attrlist, &e,
|
||||
getPluginID());
|
||||
if (LDAP_SUCCESS == ret) {
|
||||
char *old_value;
|
||||
|
||||
old_value = slapi_entry_attr_get_charptr(e, DNA_NEXTVAL);
|
||||
if(old_value)
|
||||
{
|
||||
if (old_value) {
|
||||
LDAPMod mod_add;
|
||||
LDAPMod mod_delete;
|
||||
LDAPMod *mods[3];
|
||||
@ -765,8 +773,7 @@ static int dna_get_next_value(configEntry *config_entry, char **next_value_ret)
|
||||
goto bail;
|
||||
|
||||
interval = slapi_entry_attr_get_charptr(e, DNA_INTERVAL);
|
||||
if(0 == interval)
|
||||
{
|
||||
if (0 == interval) {
|
||||
slapi_pblock_destroy(pb);
|
||||
slapi_ch_free_string(&old_value);
|
||||
goto bail;
|
||||
@ -797,46 +804,35 @@ static int dna_get_next_value(configEntry *config_entry, char **next_value_ret)
|
||||
mods[1] = &mod_add;
|
||||
mods[2] = 0;
|
||||
|
||||
slapi_modify_internal_set_pb(
|
||||
pb, config_entry->dn,
|
||||
mods, 0, 0,
|
||||
getPluginID(), 0);
|
||||
slapi_modify_internal_set_pb(pb, config_entry->dn,
|
||||
mods, 0, 0, getPluginID(), 0);
|
||||
|
||||
slapi_modify_internal_pb(pb);
|
||||
|
||||
slapi_pblock_get(pb,
|
||||
SLAPI_PLUGIN_INTOP_RESULT,
|
||||
&ret);
|
||||
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &ret);
|
||||
|
||||
slapi_pblock_destroy(pb);
|
||||
slapi_ch_free_string(&interval);
|
||||
|
||||
if(LDAP_SUCCESS == ret)
|
||||
{
|
||||
if (LDAP_SUCCESS == ret) {
|
||||
*next_value_ret = old_value;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
slapi_ch_free_string(&old_value);
|
||||
if(LDAP_NO_SUCH_ATTRIBUTE != ret)
|
||||
{
|
||||
if (LDAP_NO_SUCH_ATTRIBUTE != ret) {
|
||||
/* not the result of a race
|
||||
to change the value
|
||||
*/
|
||||
break;
|
||||
}
|
||||
else
|
||||
} else
|
||||
/* we lost the race to mod
|
||||
try again
|
||||
*/
|
||||
ret = LDAP_SUCCESS;
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
break;
|
||||
}
|
||||
else
|
||||
} else
|
||||
break;
|
||||
}
|
||||
|
||||
@ -850,7 +846,8 @@ bail:
|
||||
if (e)
|
||||
slapi_entry_free(e);
|
||||
|
||||
slapi_log_error( SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM , "<-- dna_get_next_value\n");
|
||||
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
|
||||
"<-- dna_get_next_value\n");
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -876,7 +873,8 @@ static int dna_pre_op(Slapi_PBlock *pb, int modtype)
|
||||
int free_entry = 0;
|
||||
int ret = 0;
|
||||
|
||||
slapi_log_error( SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM , "--> dna_pre_op\n");
|
||||
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
|
||||
"--> dna_pre_op\n");
|
||||
|
||||
if (0 == (dn = dna_get_dn(pb)))
|
||||
goto bail;
|
||||
@ -884,12 +882,9 @@ static int dna_pre_op(Slapi_PBlock *pb, int modtype)
|
||||
if (dna_dn_is_config(dn))
|
||||
goto bail;
|
||||
|
||||
if(LDAP_CHANGETYPE_ADD == modtype)
|
||||
{
|
||||
if (LDAP_CHANGETYPE_ADD == modtype) {
|
||||
slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &e);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* xxxPAR: Ideally SLAPI_MODIFY_EXISTING_ENTRY should be
|
||||
* available but it turns out that is only true if you are
|
||||
* a dbm backend pre-op plugin - lucky dbm backend pre-op
|
||||
@ -902,10 +897,8 @@ static int dna_pre_op(Slapi_PBlock *pb, int modtype)
|
||||
slapi_pblock_get( pb, SLAPI_MODIFY_EXISTING_ENTRY, &e);
|
||||
*/
|
||||
Slapi_DN *tmp_dn = slapi_sdn_new_dn_byref(dn);
|
||||
if(tmp_dn)
|
||||
{
|
||||
slapi_search_internal_get_entry(
|
||||
tmp_dn, 0, &e,getPluginID());
|
||||
if (tmp_dn) {
|
||||
slapi_search_internal_get_entry(tmp_dn, 0, &e, getPluginID());
|
||||
slapi_sdn_free(&tmp_dn);
|
||||
free_entry = 1;
|
||||
}
|
||||
@ -923,85 +916,64 @@ static int dna_pre_op(Slapi_PBlock *pb, int modtype)
|
||||
|
||||
dna_read_lock();
|
||||
|
||||
if(!PR_CLIST_IS_EMPTY(config))
|
||||
{
|
||||
if (!PR_CLIST_IS_EMPTY(config)) {
|
||||
list = PR_LIST_HEAD(config);
|
||||
|
||||
while(list != config && LDAP_SUCCESS == ret)
|
||||
{
|
||||
while (list != config && LDAP_SUCCESS == ret) {
|
||||
config_entry = (configEntry *) list;
|
||||
|
||||
/* did we already service this type? */
|
||||
if(last_type)
|
||||
{
|
||||
if (last_type) {
|
||||
if (!slapi_attr_type_cmp(config_entry->type, last_type, 1))
|
||||
goto next;
|
||||
}
|
||||
|
||||
/* is the entry in scope? */
|
||||
if(config_entry->scope)
|
||||
{
|
||||
if (config_entry->scope) {
|
||||
if (!slapi_dn_issuffix(dn, config_entry->scope))
|
||||
goto next;
|
||||
}
|
||||
|
||||
/* does the entry match the filter? */
|
||||
if(config_entry->filter)
|
||||
{
|
||||
if (config_entry->filter) {
|
||||
if (LDAP_SUCCESS != slapi_vattr_filter_test(pb,
|
||||
e,
|
||||
config_entry->filter,0))
|
||||
config_entry->
|
||||
filter, 0))
|
||||
goto next;
|
||||
}
|
||||
|
||||
|
||||
if(LDAP_CHANGETYPE_ADD == modtype)
|
||||
{
|
||||
if (LDAP_CHANGETYPE_ADD == modtype) {
|
||||
/* does attribute contain the magic value
|
||||
or is the type not there?
|
||||
*/
|
||||
value = slapi_entry_attr_get_charptr(
|
||||
e, config_entry->type);
|
||||
if((value &&
|
||||
!slapi_UTF8CASECMP(
|
||||
config_entry->generate,
|
||||
value)) ||
|
||||
0 == value)
|
||||
{
|
||||
value =
|
||||
slapi_entry_attr_get_charptr(e, config_entry->type);
|
||||
if ((value
|
||||
&& !slapi_UTF8CASECMP(config_entry->generate, value))
|
||||
|| 0 == value) {
|
||||
generate = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* check mods for magic value */
|
||||
Slapi_Mod *next_mod = slapi_mod_new();
|
||||
smod = slapi_mods_get_first_smod(
|
||||
smods,
|
||||
next_mod);
|
||||
while(smod)
|
||||
{
|
||||
smod = slapi_mods_get_first_smod(smods, next_mod);
|
||||
while (smod) {
|
||||
char *type = (char *)
|
||||
slapi_mod_get_type(smod);
|
||||
|
||||
if(slapi_attr_types_equivalent(
|
||||
type,
|
||||
config_entry->type))
|
||||
{
|
||||
if (slapi_attr_types_equivalent(type,
|
||||
config_entry->type)) {
|
||||
struct berval *bv =
|
||||
slapi_mod_get_first_value(
|
||||
smod);
|
||||
int len = strlen(
|
||||
config_entry->
|
||||
generate);
|
||||
slapi_mod_get_first_value(smod);
|
||||
int len = strlen(config_entry->generate);
|
||||
|
||||
|
||||
if(len == bv->bv_len)
|
||||
{
|
||||
if(!slapi_UTF8NCASECMP(
|
||||
bv->bv_val,
|
||||
if (len == bv->bv_len) {
|
||||
if (!slapi_UTF8NCASECMP(bv->bv_val,
|
||||
config_entry->
|
||||
generate,
|
||||
len))
|
||||
generate, len))
|
||||
|
||||
generate = 1;
|
||||
break;
|
||||
@ -1009,16 +981,13 @@ static int dna_pre_op(Slapi_PBlock *pb, int modtype)
|
||||
}
|
||||
|
||||
slapi_mod_done(next_mod);
|
||||
smod = slapi_mods_get_next_smod(
|
||||
smods,
|
||||
next_mod);
|
||||
smod = slapi_mods_get_next_smod(smods, next_mod);
|
||||
}
|
||||
|
||||
slapi_mod_free(&next_mod);
|
||||
}
|
||||
|
||||
if(generate)
|
||||
{
|
||||
if (generate) {
|
||||
char *new_value;
|
||||
int len;
|
||||
|
||||
@ -1027,39 +996,29 @@ static int dna_pre_op(Slapi_PBlock *pb, int modtype)
|
||||
break;
|
||||
|
||||
len = strlen(value) + 1;
|
||||
if(config_entry->prefix)
|
||||
{
|
||||
if (config_entry->prefix) {
|
||||
len += strlen(config_entry->prefix);
|
||||
}
|
||||
|
||||
new_value = slapi_ch_malloc(len);
|
||||
|
||||
if(config_entry->prefix)
|
||||
{
|
||||
strcpy(new_value,
|
||||
config_entry->prefix);
|
||||
if (config_entry->prefix) {
|
||||
strcpy(new_value, config_entry->prefix);
|
||||
strcat(new_value, value);
|
||||
}
|
||||
else
|
||||
} else
|
||||
strcpy(new_value, value);
|
||||
|
||||
/* do the mod */
|
||||
if(LDAP_CHANGETYPE_ADD == modtype)
|
||||
{
|
||||
if (LDAP_CHANGETYPE_ADD == modtype) {
|
||||
/* add - add to entry */
|
||||
slapi_entry_attr_set_charptr(
|
||||
e,
|
||||
slapi_entry_attr_set_charptr(e,
|
||||
config_entry->type,
|
||||
new_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* mod - add to mods */
|
||||
slapi_mods_add_string(
|
||||
smods,
|
||||
slapi_mods_add_string(smods,
|
||||
LDAP_MOD_REPLACE,
|
||||
config_entry->type,
|
||||
new_value);
|
||||
config_entry->type, new_value);
|
||||
}
|
||||
|
||||
/* free up */
|
||||
@ -1069,8 +1028,7 @@ static int dna_pre_op(Slapi_PBlock *pb, int modtype)
|
||||
/* make sure we don't generate for this
|
||||
* type again
|
||||
*/
|
||||
if(LDAP_SUCCESS == ret)
|
||||
{
|
||||
if (LDAP_SUCCESS == ret) {
|
||||
last_type = config_entry->type;
|
||||
}
|
||||
|
||||
@ -1084,8 +1042,7 @@ next:
|
||||
dna_unlock();
|
||||
|
||||
bailmod:
|
||||
if(LDAP_CHANGETYPE_MODIFY == modtype)
|
||||
{
|
||||
if (LDAP_CHANGETYPE_MODIFY == modtype) {
|
||||
/* these are the mods you made, really,
|
||||
* I didn't change them, honest, just had a quick look
|
||||
*/
|
||||
@ -1100,9 +1057,11 @@ bail:
|
||||
slapi_entry_free(e);
|
||||
|
||||
if (ret)
|
||||
slapi_log_error( SLAPI_LOG_PLUGIN, DNA_PLUGIN_SUBSYSTEM , "dna_pre_op: operation failure [%d]\n", ret);
|
||||
slapi_log_error(SLAPI_LOG_PLUGIN, DNA_PLUGIN_SUBSYSTEM,
|
||||
"dna_pre_op: operation failure [%d]\n", ret);
|
||||
|
||||
slapi_log_error( SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM , "<-- dna_pre_op\n");
|
||||
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
|
||||
"<-- dna_pre_op\n");
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -1122,15 +1081,16 @@ static int dna_config_check_post_op(Slapi_PBlock *pb)
|
||||
{
|
||||
char *dn;
|
||||
|
||||
slapi_log_error( SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM , "--> dna_config_check_post_op\n");
|
||||
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
|
||||
"--> dna_config_check_post_op\n");
|
||||
|
||||
if((dn = dna_get_dn(pb)))
|
||||
{
|
||||
if ((dn = dna_get_dn(pb))) {
|
||||
if (dna_dn_is_config(dn))
|
||||
loadPluginConfig();
|
||||
}
|
||||
|
||||
slapi_log_error( SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM , "<-- dna_config_check_post_op\n");
|
||||
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
|
||||
"<-- dna_config_check_post_op\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1150,11 +1110,9 @@ void dnaDumpConfig()
|
||||
|
||||
dna_read_lock();
|
||||
|
||||
if(!PR_CLIST_IS_EMPTY(config))
|
||||
{
|
||||
if (!PR_CLIST_IS_EMPTY(config)) {
|
||||
list = PR_LIST_HEAD(config);
|
||||
while(list != config)
|
||||
{
|
||||
while (list != config) {
|
||||
dnaDumpConfigEntry((configEntry *) list);
|
||||
list = PR_NEXT_LINK(list);
|
||||
}
|
||||
@ -1172,5 +1130,3 @@ void dnaDumpConfigEntry(configEntry *entry)
|
||||
printf("<---- interval -------> %lu\n", entry->interval);
|
||||
printf("<---- generate flag --> %s\n", entry->generate);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user