2 * Copyright 2003-2004 PADL Software Pty Ltd.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted only as authorized by the OpenLDAP
9 * A copy of this license is available in the file LICENSE in the
10 * top-level directory of the distribution or, alternatively, at
11 * <http://www.OpenLDAP.org/license.html>.
13 /* (C) Copyright PADL Software Pty Ltd. 2003
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that this notice is preserved
16 * and that due credit is given to PADL Software Pty Ltd. This software
17 * is provided ``as is'' without express or implied warranty.
26 #include <slapi-plugin.h>
28 int addrdnvalues_preop_init(Slapi_PBlock *pb);
30 static Slapi_PluginDesc pluginDescription = {
31 "addrdnvalues-plugin",
34 "RDN values addition plugin"
37 static int addrdnvalues_preop_add(Slapi_PBlock *pb)
45 if (slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &e) != 0) {
46 slapi_log_error(SLAPI_LOG_PLUGIN, "addrdnvalues_preop_add",
47 "Error retrieving target entry\n");
51 szDN = slapi_entry_get_dn(e);
52 rc = ldap_str2dn(szDN, &dn, LDAP_DN_FORMAT_LDAPV3);
53 if (rc != LDAP_SUCCESS) {
54 slapi_send_ldap_result(pb, rc, NULL, NULL, 0, NULL);
55 slapi_log_error(SLAPI_LOG_PLUGIN, "addrdnvalues_preop_add", "%s\n", ldap_err2string(rc));
62 for (i = 0; rdn[i] != NULL; i++) {
63 LDAPAVA *ava = &rdn[0][i];
64 struct berval *vals[2];
67 /* 0 means attr exists */
68 if (slapi_entry_attr_find(e, ava->la_attr.bv_val, &a) == 0 &&
70 slapi_attr_value_find(a, &ava->la_value) == 0)
74 } /* else RDN not in entry */
76 vals[0] = &ava->la_value;
79 slapi_entry_attr_merge(e, ava->la_attr.bv_val, vals);
88 int addrdnvalues_preop_init(Slapi_PBlock *pb)
90 if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_03) != 0 ||
91 slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, &pluginDescription) != 0 ||
92 slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_ADD_FN, (void *)addrdnvalues_preop_add) != 0) {
93 slapi_log_error(SLAPI_LOG_PLUGIN, "addrdnvalues_preop_init",
94 "Error registering %s\n", pluginDescription.spd_description);