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