xref: /netbsd-src/external/bsd/openldap/dist/contrib/slapi-plugins/addrdnvalues/addrdnvalues.c (revision 404fbe5fb94ca1e054339640cabb2801ce52dd30)
1 /* $OpenLDAP: pkg/ldap/contrib/slapi-plugins/addrdnvalues/addrdnvalues.c,v 1.6 2004/05/23 13:45:32 lukeh Exp $ */
2 /*
3  * Copyright 2003-2004 PADL Software Pty Ltd.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted only as authorized by the OpenLDAP
8  * Public License.
9  *
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>.
13  */
14 
15 #include <string.h>
16 #include <unistd.h>
17 
18 #include <ldap.h>
19 #include <lber.h>
20 
21 #include <slapi-plugin.h>
22 
23 int addrdnvalues_preop_init(Slapi_PBlock *pb);
24 
25 static Slapi_PluginDesc pluginDescription = {
26 	"addrdnvalues-plugin",
27 	"PADL",
28 	"1.0",
29 	"RDN values addition plugin"
30 };
31 
32 static int addrdnvalues_preop_add(Slapi_PBlock *pb)
33 {
34 	int rc;
35 	Slapi_Entry *e;
36 
37 	if (slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &e) != 0) {
38 		slapi_log_error(SLAPI_LOG_PLUGIN, "addrdnvalues_preop_add",
39 				"Error retrieving target entry\n");
40 		return -1;
41 	}
42 
43 	rc = slapi_entry_add_rdn_values(e);
44 	if (rc != LDAP_SUCCESS) {
45 		slapi_send_ldap_result(pb, LDAP_OTHER, NULL,
46 			"Failed to parse distinguished name", 0, NULL);
47 		slapi_log_error(SLAPI_LOG_PLUGIN, "addrdnvalues_preop_add",
48 			"Failed to parse distinguished name: %s\n",
49 			ldap_err2string(rc));
50 		return -1;
51 	}
52 
53 	return 0;
54 }
55 
56 int addrdnvalues_preop_init(Slapi_PBlock *pb)
57 {
58 	if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_03) != 0 ||
59 	    slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, &pluginDescription) != 0 ||
60 	    slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_ADD_FN, (void *)addrdnvalues_preop_add) != 0) {
61 		slapi_log_error(SLAPI_LOG_PLUGIN, "addrdnvalues_preop_init",
62 				"Error registering %s\n", pluginDescription.spd_description);
63 		return -1;
64 	}
65 
66 	return 0;
67 }
68 
69