]> git.sur5r.net Git - openldap/blob - contrib/slapi-plugins/addrdnvalues/addrdnvalues.c
Happy New Year
[openldap] / contrib / slapi-plugins / addrdnvalues / addrdnvalues.c
1 /* addrdnvalues.c */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2003-2018 The OpenLDAP Foundation.
6  * Copyright 2003-2004 PADL Software Pty Ltd.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
13  * A copy of this license is available in the file LICENSE in the
14  * top-level directory of the distribution or, alternatively, at
15  * <http://www.OpenLDAP.org/license.html>.
16  */
17 /* ACKNOWLEDGEMENTS:
18  * This work was initially developed by Luke Howard of PADL Software
19  * for inclusion in OpenLDAP Software.
20  */
21
22 #include <string.h>
23 #include <unistd.h>
24
25 #include <ldap.h>
26 #include <lber.h>
27
28 #include <slapi-plugin.h>
29
30 int addrdnvalues_preop_init(Slapi_PBlock *pb);
31
32 static Slapi_PluginDesc pluginDescription = {
33         "addrdnvalues-plugin",
34         "PADL",
35         "1.0",
36         "RDN values addition plugin"
37 };
38
39 static int addrdnvalues_preop_add(Slapi_PBlock *pb)
40 {
41         int rc;
42         Slapi_Entry *e;
43
44         if (slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &e) != 0) {
45                 slapi_log_error(SLAPI_LOG_PLUGIN, "addrdnvalues_preop_add",
46                                 "Error retrieving target entry\n");
47                 return -1;
48         }
49
50         rc = slapi_entry_add_rdn_values(e);
51         if (rc != LDAP_SUCCESS) {
52                 slapi_send_ldap_result(pb, LDAP_OTHER, NULL,
53                         "Failed to parse distinguished name", 0, NULL);
54                 slapi_log_error(SLAPI_LOG_PLUGIN, "addrdnvalues_preop_add",
55                         "Failed to parse distinguished name: %s\n",
56                         ldap_err2string(rc));
57                 return -1;
58         }
59
60         return 0;
61 }
62
63 int addrdnvalues_preop_init(Slapi_PBlock *pb)
64 {
65         if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_03) != 0 ||
66             slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, &pluginDescription) != 0 ||
67             slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_ADD_FN, (void *)addrdnvalues_preop_add) != 0) {
68                 slapi_log_error(SLAPI_LOG_PLUGIN, "addrdnvalues_preop_init",
69                                 "Error registering %s\n", pluginDescription.spd_description);
70                 return -1;
71         }
72
73         return 0;
74 }
75