summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2009-07-31 17:06:22 +0000
committerStef Walter <stef@memberwebs.com>2009-07-31 17:06:22 +0000
commit54433365264edb859ac8612b17b72566f68932cc (patch)
tree8a036c8ea508f6f77e844ad2a34e595e0a9f73ba
parent7579c6992e07b3f4e1357d73d6bdccf9d0260c55 (diff)
A bunch of fixes during testing
git-svn-id: http://internal-svn-server/svn/network/slapi-suffix@1515 96c7dce7-e4ff-0310-afa0-05b99c2e9643
-rw-r--r--plugin/suffix.c70
1 files changed, 44 insertions, 26 deletions
diff --git a/plugin/suffix.c b/plugin/suffix.c
index e8aeeca..3500624 100644
--- a/plugin/suffix.c
+++ b/plugin/suffix.c
@@ -54,13 +54,31 @@ static struct berval suffix_delimiter = { 0, NULL };
* LDAP OPERATIONS
*/
+static void
+bv_to_string (struct berval *bv, char *string, size_t n_string)
+{
+ assert (bv);
+ assert (string);
+ assert (n_string);
+
+ /* For null terminator */
+ --n_string;
+ if (bv->bv_len < n_string)
+ n_string = bv->bv_len;
+ memcpy (string, bv->bv_val, n_string);
+ string[n_string] = 0;
+}
+
static struct berval**
entry_values (Slapi_Entry *entry, const char *name)
{
struct berval **values;
Slapi_Attr *attr;
int rc;
-
+
+ assert (entry);
+ assert (name);
+
/* The attribute we're after */
rc = slapi_entry_attr_find (entry, (char*)name, &attr);
if (rc != 0)
@@ -138,12 +156,12 @@ has_suffix (struct berval *value, struct berval *suffix, struct berval *delim)
/* The delim must be in the right place */
if (memcmp (ptr + (value->bv_len - (suffix->bv_len + delim->bv_len)),
- delim, delim->bv_len) != 0)
+ delim->bv_val, delim->bv_len) != 0)
return 0;
/* And the suffix must be in the right place */
if (memcmp (ptr + (value->bv_len - suffix->bv_len),
- suffix, suffix->bv_len) != 0)
+ suffix->bv_val, suffix->bv_len) != 0)
return 0;
return 1;
@@ -152,7 +170,7 @@ has_suffix (struct berval *value, struct berval *suffix, struct berval *delim)
static int
check_suffix_constraints (Slapi_PBlock *pb, struct berval **suffixes, struct berval **values)
{
- struct berval *value, *suffix;
+ struct berval *value, **suffix;
char string[128];
char msg[512];
int found;
@@ -165,20 +183,16 @@ check_suffix_constraints (Slapi_PBlock *pb, struct berval **suffixes, struct ber
for (value = *values; value; value = *(++values)) {
found = 0;
- for (suffix = *suffixes; suffix; suffix = *(++suffixes)) {
- if (has_suffix (value, suffix, &suffix_delimiter)) {
+ for (suffix = suffixes; suffix; ++suffix) {
+ if (has_suffix (value, *suffix, &suffix_delimiter)) {
found = 1;
break;
}
}
-
+
if (!found) {
- /* Null terminate the value for the message below */
- strncpy (string, value->bv_val,
- value->bv_len >= sizeof (string) ? sizeof (string) : value->bv_len);
- string[sizeof(string) - 1] = 0;
-
/* Build and return our error message */
+ bv_to_string (value, string, sizeof (string));
snprintf (msg, sizeof (msg),
"The value '%s' for the %s attribute does not have a valid suffix",
string, suffix_attribute);
@@ -199,13 +213,17 @@ suffix_pre_add (Slapi_PBlock *pb, const char *dn)
Slapi_Entry *entry;
char *parent;
int rc = 0;
-
+
+ assert (pb);
+ assert (dn);
+
if (!suffix_attribute)
return 0;
- parent = slapi_dn_parent (dn);
- return_val_if_fail (parent, -1);
-
+ parent = slapi_dn_beparent (pb, dn);
+ if (!parent)
+ return 0;
+
suffixes = lookup_values (parent, suffix_attribute, &ipb);
slapi_ch_free_string (&parent);
@@ -231,13 +249,17 @@ suffix_pre_modify (Slapi_PBlock *pb, const char *dn)
LDAPMod **mods, *mod;
char *parent;
int rc = 0;
-
+
+ assert (pb);
+ assert (dn);
+
if (!suffix_attribute)
return 0;
-
- parent = slapi_dn_parent (dn);
- return_val_if_fail (parent, -1);
-
+
+ parent = slapi_dn_beparent (pb, dn);
+ if (!parent)
+ return 0;
+
suffixes = lookup_values (parent, suffix_attribute, &ipb);
slapi_ch_free_string (&parent);
@@ -270,6 +292,7 @@ suffix_config (const char *name, const char *value)
} else if (strcmp ("suffix-delimiter", name) == 0 && value) {
suffix_delimiter.bv_val = (void*)value;
suffix_delimiter.bv_len = strlen (value);
+ return 1;
}
return 0;
@@ -284,10 +307,5 @@ suffix_destroy (void)
int
suffix_init (void)
{
- if (!suffix_attribute || !suffix_attribute[0]) {
- log_plugin ("'attribute' argument not specified");
- return -1;
- }
-
return 0;
}