Back to index

openldap  2.4.31
addrdnvalues.c
Go to the documentation of this file.
00001 /* addrdnvalues.c */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 2003-2012 The OpenLDAP Foundation.
00006  * Copyright 2003-2004 PADL Software Pty Ltd.
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted only as authorized by the OpenLDAP
00011  * Public License.
00012  *
00013  * A copy of this license is available in the file LICENSE in the
00014  * top-level directory of the distribution or, alternatively, at
00015  * <http://www.OpenLDAP.org/license.html>.
00016  */
00017 /* ACKNOWLEDGEMENTS:
00018  * This work was initially developed by Luke Howard of PADL Software
00019  * for inclusion in OpenLDAP Software.
00020  */
00021 
00022 #include <string.h>
00023 #include <unistd.h>
00024 
00025 #include <ldap.h>
00026 #include <lber.h>
00027 
00028 #include <slapi-plugin.h>
00029 
00030 int addrdnvalues_preop_init(Slapi_PBlock *pb);
00031 
00032 static Slapi_PluginDesc pluginDescription = {
00033        "addrdnvalues-plugin",
00034        "PADL",
00035        "1.0",
00036        "RDN values addition plugin"
00037 };
00038 
00039 static int addrdnvalues_preop_add(Slapi_PBlock *pb)
00040 {
00041        int rc;
00042        Slapi_Entry *e;
00043 
00044        if (slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &e) != 0) {
00045               slapi_log_error(SLAPI_LOG_PLUGIN, "addrdnvalues_preop_add",
00046                             "Error retrieving target entry\n");
00047               return -1;
00048        }
00049 
00050        rc = slapi_entry_add_rdn_values(e);
00051        if (rc != LDAP_SUCCESS) {
00052               slapi_send_ldap_result(pb, LDAP_OTHER, NULL,
00053                      "Failed to parse distinguished name", 0, NULL);
00054               slapi_log_error(SLAPI_LOG_PLUGIN, "addrdnvalues_preop_add",
00055                      "Failed to parse distinguished name: %s\n",
00056                      ldap_err2string(rc));
00057               return -1;
00058        }
00059 
00060        return 0;
00061 }
00062 
00063 int addrdnvalues_preop_init(Slapi_PBlock *pb)
00064 {
00065        if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_03) != 0 ||
00066            slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, &pluginDescription) != 0 ||
00067            slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_ADD_FN, (void *)addrdnvalues_preop_add) != 0) {
00068               slapi_log_error(SLAPI_LOG_PLUGIN, "addrdnvalues_preop_init",
00069                             "Error registering %s\n", pluginDescription.spd_description);
00070               return -1;
00071        }
00072 
00073        return 0;
00074 }
00075