From 6aa9fdccbc9910c3dfacb22ba22596c9b514b5b4 Mon Sep 17 00:00:00 2001 From: Noriko Hosoi Date: Mar 04 2015 21:47:00 +0000 Subject: Ticket #47431 - Duplicate values for the attribute nsslapd-pluginarg are not handled correctly Description: In case nsslapd-pluginargN has simple syntax errors, recover them. 1) nsslapd-pluginargN: val_1 nsslapd-pluginargN: val_2 nsslapd-pluginargN+1: val_3 ==> nsslapd-pluginargN: val_1 nsslapd-pluginargN+1: val_2 nsslapd-pluginargN+2: val_3 Note: val_2 used to be ignored. 2) nsslapd-pluginargM: val_1 nsslapd-pluginargN: val_2 nsslapd-pluginargN+1: val_3 where N != M + 1 ==> nsslapd-pluginargM: val_1 nsslapd-pluginargM+1: val_2 nsslapd-pluginargM+2: val_3 Note: nsslapd-pluginargN and the rest were not loaded. Reviewed by rmeggins@redhat.com (Thank you, Rich!!) https://fedorahosted.org/389/ticket/47431 --- diff --git a/ldap/servers/plugins/uiduniq/7bit.c b/ldap/servers/plugins/uiduniq/7bit.c index c84c79c..a96951e 100644 --- a/ldap/servers/plugins/uiduniq/7bit.c +++ b/ldap/servers/plugins/uiduniq/7bit.c @@ -288,7 +288,7 @@ preop_add(Slapi_PBlock *pb) firstSubtree++; argc--; - for (attrName = argv; strcmp(*attrName, ",") != 0; attrName++ ) + for (attrName = argv; attrName && *attrName && strcmp(*attrName, ","); attrName++) { /* * if the attribute is userpassword, check unhashed user password @@ -300,15 +300,14 @@ preop_add(Slapi_PBlock *pb) if ( strcasecmp(*attrName, "userpassword") == 0 ) { origpwd = pwd = slapi_get_first_clear_text_pw(e); - if (pwd == NULL) - { + if (pwd == NULL) { continue; } val.bv_val = pwd; val.bv_len = strlen(val.bv_val); } else { attr_name = *attrName; - err = slapi_entry_attr_find(e, attr_name, &attr); + err = slapi_entry_attr_find(e, attr_name, &attr); if (err) continue; /* break;*/ /* no 7-bit attribute */ } @@ -745,11 +744,16 @@ NS7bitAttr_Init(Slapi_PBlock *pb) err = slapi_pblock_get(pb, SLAPI_PLUGIN_ARGV, &argv); if (err) break; + for (attr_count = 0; argv && argv[attr_count]; attr_count++) { + slapi_log_error(SLAPI_LOG_PLUGIN, "NS7bitAttr_Init", "%d: %s\n", + attr_count, argv[attr_count]); + } /* * Arguments before "," are the 7-bit attribute names. Arguments after * "," are the subtree DN's. */ if (argc < 1) { err = -2; break; } /* missing arguments */ + attr_count = 0; for(;*argv && strcmp(*argv, ",") != 0 && argc > 0; attr_count++, argc--, argv++); if (argc == 0) { err = -3; break; } /* no comma separator */ if(attr_count == 0){ err = -4; break; } /* no attributes */ diff --git a/ldap/servers/slapd/plugin.c b/ldap/servers/slapd/plugin.c index 4df2eb5..2b3428e 100644 --- a/ldap/servers/slapd/plugin.c +++ b/ldap/servers/slapd/plugin.c @@ -2693,24 +2693,25 @@ plugin_setup(Slapi_Entry *plugin_entry, struct slapi_componentid *group, slapi_plugin_init_fnptr p_initfunc, int add_entry, char *returntext) { int ii = 0; - char attrname[BUFSIZ]; - char *value = 0; + char attrname[SLAPD_TYPICAL_ATTRIBUTE_NAME_MAX_LENGTH]; + char *value = NULL; + char **values = NULL; struct slapdplugin *plugin = NULL; struct slapdplugin **plugin_list = NULL; - struct slapi_componentid *cid=NULL; + struct slapi_componentid *cid = NULL; const char *existname = 0; slapi_plugin_init_fnptr initfunc = p_initfunc; Slapi_PBlock pb; int status = 0; int enabled = 1; char *configdir = 0; + int skipped; attrname[0] = '\0'; if (!slapi_entry_get_sdn_const(plugin_entry)) { - LDAPDebug(LDAP_DEBUG_ANY, "plugin_setup: DN is missing from the plugin.\n", - 0, 0, 0); + LDAPDebug0Args(LDAP_DEBUG_ANY, "plugin_setup: DN is missing from the plugin.\n"); PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE,"Plugin is missing dn."); return -1; } @@ -2815,8 +2816,7 @@ plugin_setup(Slapi_Entry *plugin_entry, struct slapi_componentid *group, slapi_ch_free((void**)&value); } - if (!(value = slapi_entry_attr_get_charptr(plugin_entry, - ATTR_PLUGIN_INITFN))) + if (!(value = slapi_entry_attr_get_charptr(plugin_entry, ATTR_PLUGIN_INITFN))) { if (!initfunc) { @@ -2906,13 +2906,35 @@ plugin_setup(Slapi_Entry *plugin_entry, struct slapi_componentid *group, 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) - { - charray_add(&plugin->plg_argv, value); - plugin->plg_argc++; - ++ii; - PR_snprintf(attrname, sizeof(attrname), "%s%d", ATTR_PLUGIN_ARG, ii); - } + skipped = 0; +#define MAXSKIPPED 10 /* Max allowed missing args */ + do { + /* + * nsslapd-pluginarg0: val0 + * nsslapd-pluginarg0: val00 + * nsslapd-pluginarg2: val2 + * nsslapd-pluginarg5: val5 + * ==> + * treated as + * nsslapd-pluginarg0: val0 + * nsslapd-pluginarg1: val00 + * nsslapd-pluginarg2: val2 + * nsslapd-pluginarg3: val5 + */ + char **vp = values = slapi_entry_attr_get_charray(plugin_entry, attrname); + if (values) { + charray_add(&plugin->plg_argv, slapi_ch_strdup(*vp)); + plugin->plg_argc++; + for (vp++; vp && *vp; vp++) { + charray_add(&plugin->plg_argv, slapi_ch_strdup(*vp)); + plugin->plg_argc++; + } + charray_free(values); + } else { + skipped++; + } + PR_snprintf(attrname, sizeof(attrname), "%s%d", ATTR_PLUGIN_ARG, ++ii); + } while (skipped < MAXSKIPPED); memset((char *)&pb, '\0', sizeof(pb)); slapi_pblock_set(&pb, SLAPI_PLUGIN, plugin);