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