ldap/schema/01core389.ldif | 16 ++++++++
ldap/servers/slapd/plugin.c | 87 +++++++++++++++++++++++++++++++++++++++++---
2 files changed, 99 insertions(+), 4 deletions(-)
New commits:
commit d2c5b35e20578043117f84e928d96d296bdfc046
Author: Anupam Jain <anjain(a)localhost.localdomain>
Date: Tue Jul 16 18:16:27 2013 -0700
Ticket #47431 - Duplicate values for the attribute nsslapd-pluginarg are not handled
correctly
Fix description: Added the attributes nsslapd-pluginarg0 to
nsslapd-pluginarg15 in the schema file with the condition that
they must be singlevalued. This solves the issue of incorrect
handling of duplicate and multiple values of these attributes.
This fix also solves the problem of non-continuous numbers in
the nsslapd-pluginarg attributes and makes them continuous if
they are not.
https://fedorahosted.org/389/ticket/47431
Reviewed by nhosoi.
diff --git a/ldap/schema/01core389.ldif b/ldap/schema/01core389.ldif
index 8ef702d..8c49918 100644
--- a/ldap/schema/01core389.ldif
+++ b/ldap/schema/01core389.ldif
@@ -153,6 +153,22 @@ attributeTypes: ( 2.16.840.1.113730.3.1.2152 NAME
'nsds5ReplicaProtocolTimeout'
attributeTypes: ( 2.16.840.1.113730.3.1.2154 NAME 'nsds5ReplicaBackoffMin' DESC
'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.27
SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
attributeTypes: ( 2.16.840.1.113730.3.1.2155 NAME 'nsds5ReplicaBackoffMax' DESC
'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.27
SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
attributeTypes: ( 2.16.840.1.113730.3.1.2156 NAME 'nsslapd-sasl-max-buffer-size'
DESC 'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.27
SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
+attributeTypes: ( 2.16.840.1.113730.3.1.2161 NAME 'nsslapd-pluginArg0' DESC
'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
+attributeTypes: ( 2.16.840.1.113730.3.1.2162 NAME 'nsslapd-pluginArg1' DESC
'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
+attributeTypes: ( 2.16.840.1.113730.3.1.2163 NAME 'nsslapd-pluginArg2' DESC
'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
+attributeTypes: ( 2.16.840.1.113730.3.1.2164 NAME 'nsslapd-pluginArg3' DESC
'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
+attributeTypes: ( 2.16.840.1.113730.3.1.2165 NAME 'nsslapd-pluginArg4' DESC
'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
+attributeTypes: ( 2.16.840.1.113730.3.1.2166 NAME 'nsslapd-pluginArg5' DESC
'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
+attributeTypes: ( 2.16.840.1.113730.3.1.2167 NAME 'nsslapd-pluginArg6' DESC
'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
+attributeTypes: ( 2.16.840.1.113730.3.1.2168 NAME 'nsslapd-pluginArg7' DESC
'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
+attributeTypes: ( 2.16.840.1.113730.3.1.2169 NAME 'nsslapd-pluginArg8' DESC
'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
+attributeTypes: ( 2.16.840.1.113730.3.1.2170 NAME 'nsslapd-pluginArg9' DESC
'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
+attributeTypes: ( 2.16.840.1.113730.3.1.2171 NAME 'nsslapd-pluginArg10' DESC
'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
+attributeTypes: ( 2.16.840.1.113730.3.1.2172 NAME 'nsslapd-pluginArg11' DESC
'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
+attributeTypes: ( 2.16.840.1.113730.3.1.2173 NAME 'nsslapd-pluginArg12' DESC
'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
+attributeTypes: ( 2.16.840.1.113730.3.1.2174 NAME 'nsslapd-pluginArg13' DESC
'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
+attributeTypes: ( 2.16.840.1.113730.3.1.2175 NAME 'nsslapd-pluginArg14' DESC
'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
+attributeTypes: ( 2.16.840.1.113730.3.1.2176 NAME 'nsslapd-pluginArg15' DESC
'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
#
# objectclasses
#
diff --git a/ldap/servers/slapd/plugin.c b/ldap/servers/slapd/plugin.c
index 52b9c3c..d9b925c 100644
--- a/ldap/servers/slapd/plugin.c
+++ b/ldap/servers/slapd/plugin.c
@@ -54,6 +54,11 @@
#define ROOT_BIND "directory manager"
#define ANONYMOUS_BIND "anonymous"
+/* This defines the maximum number that an nsslapd-pluginArg attribute can have.
+ * A plugin can have 16 arguments nsslapd-pluginArg0 to nsslapd-pluginArg15
+ */
+#define MAX_PLUGINARG_NUM 15
+
/* Forward Declarations */
static int plugin_call_list (struct slapdplugin *list, int operation, Slapi_PBlock *pb);
static int plugin_call_one (struct slapdplugin *list, int operation, Slapi_PBlock *pb);
@@ -2097,8 +2102,19 @@ plugin_setup(Slapi_Entry *plugin_entry, struct slapi_componentid
*group,
int status = 0;
int enabled = 1;
char *configdir = 0;
+ int diff = 0;
+ int index_prev = 0;
+ char attr_prev[BUFSIZ];
+ int rc = 0;
+ int num_args = 0;
+ Slapi_Attr *newattr = 0;
+ int arg_length = 0;
+ char *attrnamenum = NULL;
+ char *attr_prevnum = NULL;
+ int numsize = 0;
attrname[0] = '\0';
+ attr_prev[0] = '\0';
if (!slapi_entry_get_sdn_const(plugin_entry))
{
@@ -2278,15 +2294,78 @@ plugin_setup(Slapi_Entry *plugin_entry, struct slapi_componentid
*group,
}
/* add the plugin arguments */
+ rc = 0;
+ arg_length = strlen(ATTR_PLUGIN_ARG);
+
+ for (rc = slapi_entry_first_attr(plugin_entry, &newattr); !rc &&
newattr; rc = slapi_entry_next_attr(plugin_entry, newattr, &newattr))
+ {
+ char *type = NULL;
+ slapi_attr_get_type(newattr, &type);
+ if (strncasecmp(type, ATTR_PLUGIN_ARG, arg_length) == 0)
+ {
+ char *ptr = type;
+ ptr += arg_length;
+ int numdigits = 0;
+ char *ptr_num = ptr;
+ if ((*ptr == '\0') || ((*ptr == '0') && (*(ptr+1) !=
'\0')))
+ {
+ slapi_log_error( SLAPI_LOG_FATAL, plugin->plg_dn, "Invalid Plugin argument:
%s. Argument ignored\n", type);
+ continue;
+ }
+ while(*ptr != '\0')
+ {
+ if (!isdigit(*ptr))
+ {
+ slapi_log_error( SLAPI_LOG_FATAL, plugin->plg_dn, "Invalid Plugin argument:
%s. Argument ignored\n", type);
+ break;
+ }
+ numdigits++;
+ ptr++;
+ }
+ if (*ptr == '\0')
+ {
+ if ((numdigits < 3) && (atoi(ptr_num) <= MAX_PLUGINARG_NUM))
+ num_args++;
+ else
+ {
+ slapi_log_error( SLAPI_LOG_FATAL, plugin->plg_dn, "Plugin argument value
nsslapd-pluginArg%s exceeded maximum allowed value nsslapd-pluginArg%d\n", ptr_num,
MAX_PLUGINARG_NUM);
+ status = -1;
+ goto PLUGIN_CLEANUP;
+ }
+ }
+ }
+ }
+
+ PR_snprintf(attrname, sizeof(attrname), "%s", ATTR_PLUGIN_ARG);
+ PR_snprintf(attr_prev, sizeof(attr_prev), "%s", ATTR_PLUGIN_ARG);
+ attrnamenum = attrname + sizeof(ATTR_PLUGIN_ARG) -1;
+ attr_prevnum = attr_prev + sizeof(ATTR_PLUGIN_ARG) -1;
+ numsize = sizeof(attrname) - sizeof(ATTR_PLUGIN_ARG);
value = 0;
ii = 0;
- PR_snprintf(attrname, sizeof(attrname), "%s%d", ATTR_PLUGIN_ARG, ii);
- while ((value = slapi_entry_attr_get_charptr(plugin_entry, attrname)) != NULL)
+ while (plugin->plg_argc < num_args)
{
+ PR_snprintf(attrnamenum, numsize, "%d", ii);
+ if (diff == 0)
+ {
+ strcpy(attr_prev, attrname);
+ index_prev = ii;
+ }
+ while ((value = slapi_entry_attr_get_charptr(plugin_entry, attrname)) == NULL)
+ {
+ PR_snprintf(attrnamenum, numsize, "%d", ++ii);
+ }
+
+ if(strcmp(attrname, attr_prev) != 0)
+ {
+ slapi_entry_add_string(plugin_entry, attr_prev, value);
+ slapi_entry_attr_delete(plugin_entry, attrname);
+ diff = 1;
+ PR_snprintf(attr_prevnum, numsize, "%d", ++index_prev);
+ }
charray_add(&plugin->plg_argv, value);
plugin->plg_argc++;
++ii;
- PR_snprintf(attrname, sizeof(attrname), "%s%d", ATTR_PLUGIN_ARG, ii);
}
memset((char *)&pb, '\0', sizeof(pb));
@@ -3233,4 +3312,4 @@ slapi_disordely_shutdown(PRBool set)
is_disordely_shutdown = PR_TRUE;
}
return (is_disordely_shutdown);
-}
\ No newline at end of file
+}