Author: nkinder
Update of /cvs/dirsec/ldapserver/ldap/servers/plugins/dna
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv26526
Modified Files:
dna.c
Log Message:
Resolves: 456162
Summary: Merge in DNA plug-in code from FreeIPA
View full diff with command:
/usr/bin/cvs -f diff -kk -u -N -r 1.3 -r 1.4 dna.c
Index: dna.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/plugins/dna/dna.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- dna.c 18 Oct 2007 22:25:14 -0000 1.3
+++ dna.c 23 Jul 2008 16:33:31 -0000 1.4
@@ -2,15 +2,15 @@
* This Program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; version 2 of the License.
- *
+ *
* This Program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License along with
* this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA.
- *
+ *
* In addition, as a special exception, Red Hat, Inc. gives You the additional
* right to link the code of this Program with code not covered under the GNU
* General Public License ("Non-GPL Code") and to distribute linked
combinations
@@ -28,9 +28,9 @@
* version of the file, but you are not obligated to do so. If you do not wish to
* provide this exception without modification, you must delete this exception
* statement from your version and license this file solely under the GPL without
- * exception.
- *
- *
+ * exception.
+ *
+ *
* Copyright (C) 2007 Red Hat, Inc.
* All rights reserved.
* END COPYRIGHT BLOCK **/
@@ -41,11 +41,12 @@
/**
- * Distributed Numeric Assignment plug-in
+ * Distributed Numeric Assignment plug-in
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
+#include <errno.h>
#include "portable.h"
#include "nspr.h"
#include "slapi-private.h"
@@ -59,55 +60,67 @@
#include <sys/stat.h>
#endif
-#define DNA_PLUGIN_SUBSYSTEM "dna-plugin"
-#define DNA_PLUGIN_VERSION 0x00010000
+#define DNA_PLUGIN_SUBSYSTEM "dna-plugin"
+#define DNA_PLUGIN_VERSION 0x00020000
-#define DNA_DN "cn=Distributed Numeric Assignment
Plugin,cn=plugins,cn=config" /* temporary */
+#define DNA_DN "cn=Distributed Numeric Assignment Plugin,cn=plugins,cn=config"
/* temporary */
-#define DNA_SUCCESS 0
-#define DNA_FAILURE -1
+#define DNA_SUCCESS 0
+#define DNA_FAILURE -1
/**
* DNA config types
*/
-#define DNA_TYPE "dnaType"
-#define DNA_PREFIX "dnaPrefix"
-#define DNA_NEXTVAL "dnaNextValue"
-#define DNA_INTERVAL "dnaInterval"
-#define DNA_GENERATE "dnaMagicRegen"
-#define DNA_FILTER "dnaFilter"
-#define DNA_SCOPE "dnaScope"
-
-#define FEATURE_DESC "Distributed Numeric Assignment"
-#define PLUGIN_DESC "Distributed Numeric Assignment plugin"
-
-static Slapi_PluginDesc pdesc = { FEATURE_DESC,
- PLUGIN_MAGIC_VENDOR_STR,
- PRODUCTTEXT,
- PLUGIN_DESC };
+#define DNA_TYPE "dnaType"
+#define DNA_PREFIX "dnaPrefix"
+#define DNA_NEXTVAL "dnaNextValue"
+#define DNA_INTERVAL "dnaInterval"
+#define DNA_GENERATE "dnaMagicRegen"
+#define DNA_FILTER "dnaFilter"
+#define DNA_SCOPE "dnaScope"
+
+/* since v2 */
+#define DNA_MAXVAL "dnaMaxValue"
+#define DNA_SHARED_CFG_DN "dnaSharedCfgDN"
+
+/* Shared Config */
+#define DNA_GLOBAL_RANGE "dnaGlobalRange"
+#define DNA_RANGE "dnaRange"
+#define DNA_MAX_RANGE_SIZE "dnaMaxRangeSize"
+#define DNA_CHUNK_SIZE "dnaChunkSize"
+
+#define FEATURE_DESC "Distributed Numeric Assignment"
+#define PLUGIN_DESC "Distributed Numeric Assignment plugin"
+
+static Slapi_PluginDesc pdesc = { FEATURE_DESC,
+ PLUGIN_MAGIC_VENDOR_STR,
+ PRODUCTTEXT,
+ PLUGIN_DESC };
/**
* linked list of config entries
*/
-struct _defs {
- PRCList list;
- char *dn;
- char *type;
- char *prefix;
- unsigned long nextval;
- unsigned long interval;
- struct slapi_filter *filter;
- char *generate;
- char *scope;
-} dna_anchor;
-typedef struct _defs configEntry;
-static PRCList *config;
+struct configEntry {
+ PRCList list;
+ char *dn;
+ char *type;
+ char *prefix;
+ PRUint64 nextval;
+ PRUint64 interval;
+ PRUint64 maxval;
+ char *filter;
+ struct slapi_filter *slapi_filter;
+ char *generate;
+ char *scope;
+};
+
+static PRCList *dna_global_config = NULL;
static PRRWLock *g_dna_cache_lock;
-static void *_PluginID = NULL;
-static char *_PluginDN = NULL;
+static void *_PluginID = NULL;
+static char *_PluginDN = NULL;
/*
@@ -116,49 +129,50 @@
static Slapi_Mutex *g_new_value_lock;
/**
- *
+ *
* DNA plug-in management functions
*
*/
-int dna_init(Slapi_PBlock *pb);
-static int dna_start(Slapi_PBlock *pb);
-static int dna_close(Slapi_PBlock *pb);
-static int dna_postop_init(Slapi_PBlock *pb);
+int dna_init(Slapi_PBlock * pb);
+static int dna_start(Slapi_PBlock * pb);
+static int dna_close(Slapi_PBlock * pb);
+static int dna_postop_init(Slapi_PBlock * pb);
/**
- *
+ *
* Local operation functions
*
*/
static int loadPluginConfig();
-static int parseConfigEntry(Slapi_Entry *e);
+static int parseConfigEntry(Slapi_Entry * e);
static void deleteConfig();
-static void freeConfigEntry(configEntry **entry);
+static void freeConfigEntry(struct configEntry ** entry);
/**
*
* helpers
*
*/
-static char *dna_get_dn(Slapi_PBlock *pb);
+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(struct configEntry * config_entry,
+ char **next_value_ret);
[...1820 lines suppressed...]
- slapi_ch_free_string(&new_value);
-
- /* make sure we don't generate for this
- * type again
- */
- if(LDAP_SUCCESS == ret)
- {
- last_type = config_entry->type;
- }
+ new_value = slapi_ch_malloc(len);
- generate = 0;
- }
-next:
- list = PR_NEXT_LINK (list);
+ if (config_entry->prefix) {
+ strcpy(new_value, config_entry->prefix);
+ strcat(new_value, value);
+ } else
+ strcpy(new_value, value);
+
+ /* do the mod */
+ if (LDAP_CHANGETYPE_ADD == modtype) {
+ /* add - add to entry */
+ slapi_entry_attr_set_charptr(e,
+ config_entry->type,
+ new_value);
+ } else {
+ /* mod - add to mods */
+ slapi_mods_add_string(smods,
+ LDAP_MOD_REPLACE,
+ config_entry->type, new_value);
+ }
+
+ /* free up */
+ slapi_ch_free_string(&value);
+ slapi_ch_free_string(&new_value);
+
+ /* make sure we don't generate for this
+ * type again
+ */
+ if (LDAP_SUCCESS == ret) {
+ last_type = config_entry->type;
}
+
+ generate = 0;
+ }
+ next:
+ list = PR_NEXT_LINK(list);
}
+ }
- dna_unlock();
+ dna_unlock();
-bailmod:
- if(LDAP_CHANGETYPE_MODIFY == modtype)
- {
- /* these are the mods you made, really,
- * I didn't change them, honest, just had a quick look
- */
- mods = slapi_mods_get_ldapmods_passout(smods);
- slapi_pblock_set( pb, SLAPI_MODIFY_MODS, mods);
- slapi_mods_free(&smods);
- }
+ bailmod:
+ if (LDAP_CHANGETYPE_MODIFY == modtype) {
+ /* these are the mods you made, really,
+ * I didn't change them, honest, just had a quick look
+ */
+ mods = slapi_mods_get_ldapmods_passout(smods);
+ slapi_pblock_set(pb, SLAPI_MODIFY_MODS, mods);
+ slapi_mods_free(&smods);
+ }
-bail:
+ bail:
- if(free_entry && e)
- slapi_entry_free(e);
+ if (free_entry && e)
+ slapi_entry_free(e);
- if(ret)
- slapi_log_error( SLAPI_LOG_PLUGIN, DNA_PLUGIN_SUBSYSTEM , "dna_pre_op: operation
failure [%d]\n", ret);
+ if (ret) {
+ slapi_log_error(SLAPI_LOG_PLUGIN, DNA_PLUGIN_SUBSYSTEM,
+ "dna_pre_op: operation failure [%d]\n", ret);
+ slapi_send_ldap_result(pb, ret, NULL, errstr, 0, NULL);
+ slapi_ch_free((void **)&errstr);
+ ret = DNA_FAILURE;
+ }
- 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;
+ return ret;
}
-
-static int dna_add_pre_op( Slapi_PBlock *pb )
+static int dna_add_pre_op(Slapi_PBlock * pb)
{
- return dna_pre_op(pb, LDAP_CHANGETYPE_ADD);
+ return dna_pre_op(pb, LDAP_CHANGETYPE_ADD);
}
-static int dna_mod_pre_op( Slapi_PBlock *pb )
+static int dna_mod_pre_op(Slapi_PBlock * pb)
{
- return dna_pre_op(pb, LDAP_CHANGETYPE_MODIFY);
+ return dna_pre_op(pb, LDAP_CHANGETYPE_MODIFY);
}
-static int dna_config_check_post_op(Slapi_PBlock *pb)
+static int dna_config_check_post_op(Slapi_PBlock * pb)
{
- char *dn;
+ 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(dna_dn_is_config(dn))
- loadPluginConfig();
- }
+ 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;
+ return 0;
}
/****************************************************
@@ -1149,36 +1387,27 @@
*/
void dnaDumpConfig()
{
- PRCList *list;
+ PRCList *list;
- dna_read_lock();
-
- if(!PR_CLIST_IS_EMPTY(config))
- {
- list = PR_LIST_HEAD(config);
- while(list != config)
- {
- dnaDumpConfigEntry((configEntry*)list);
- list = PR_NEXT_LINK (list);
- }
- }
-
- dna_unlock();
-}
+ dna_read_lock();
+ if (!PR_CLIST_IS_EMPTY(dna_global_config)) {
+ list = PR_LIST_HEAD(dna_global_config);
+ while (list != dna_global_config) {
+ dnaDumpConfigEntry((struct configEntry *) list);
+ list = PR_NEXT_LINK(list);
+ }
+ }
-void dnaDumpConfigEntry(configEntry *entry)
-{
- char buffer[BUFSIZ];
- size_t bufsiz = (size_t)sizeof(buffer);
- printf("<- type --------------> %s\n", entry->type);
- printf("<---- prefix ---------> %s\n", entry->prefix);
- printf("<---- next value -----> %lu\n", entry->nextval);
- printf("<---- interval -------> %lu\n", entry->interval);
- buffer[0] = '\0';
- printf("<---- filter ---------> %s\n",
- slapi_filter_to_string_internal((const struct slapi_filter *)entry->filter, buffer,
&bufsiz));
- printf("<---- generate flag --> %s\n", entry->generate);
+ dna_unlock();
}
+void dnaDumpConfigEntry(struct configEntry * entry)
+{
+ printf("<- type --------------> %s\n", entry->type);
+ printf("<---- prefix ---------> %s\n", entry->prefix);
+ printf("<---- next value -----> %lu\n", entry->nextval);
+ printf("<---- interval -------> %lu\n", entry->interval);
+ printf("<---- generate flag --> %s\n", entry->generate);
+}