1
/** BEGIN COPYRIGHT BLOCK
2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation, either version 3 of the License, or
5
* (at your option) any later version.
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
12
* You should have received a copy of the GNU General Public License
13
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15
* Additional permission under GPLv3 section 7:
17
* In the following paragraph, "GPL" means the GNU General Public
18
* License, version 3 or any later version, and "Non-GPL Code" means
19
* code that is governed neither by the GPL nor a license
20
* compatible with the GPL.
22
* You may link the code of this Program with Non-GPL Code and convey
23
* linked combinations including the two, provided that such Non-GPL
24
* Code only links to the code of this Program through those well
25
* defined interfaces identified in the file named EXCEPTION found in
26
* the source code files (the "Approved Interfaces"). The files of
27
* Non-GPL Code may instantiate templates or use macros or inline
28
* functions from the Approved Interfaces without causing the resulting
29
* work to be covered by the GPL. Only the copyright holders of this
30
* Program may make changes or additions to the list of Approved
34
* Sumit Bose <sbose@redhat.com>
36
* Copyright (C) 2011 Red Hat, Inc.
37
* All rights reserved.
38
* END COPYRIGHT BLOCK **/
40
#include "ipa_extdom.h"
43
Slapi_PluginDesc ipa_extdom_plugin_desc = {
44
IPA_EXTDOM_FEATURE_DESC,
47
IPA_EXTDOM_PLUGIN_DESC
50
static char *ipa_extdom_oid_list[] = {
55
static char *ipa_extdom_name_list[] = {
56
IPA_EXTDOM_PLUGIN_DESC,
60
static int ipa_extdom_start(Slapi_PBlock *pb)
65
static int ipa_extdom_extop(Slapi_PBlock *pb)
71
struct berval *req_val = NULL;
72
struct berval *ret_val = NULL;
73
struct extdom_req *req = NULL;
74
struct extdom_res *res = NULL;
75
struct ipa_extdom_ctx *ctx;
77
ret = slapi_pblock_get(pb, SLAPI_EXT_OP_REQ_OID, &oid);
79
rc = LDAP_OPERATIONS_ERROR;
80
err_msg = "Could not get OID value from request.\n";
83
LOG("Received extended operation request with OID %s\n", oid);
85
if (strcasecmp(oid, EXOP_EXTDOM_OID) != 0) {
86
return SLAPI_PLUGIN_EXTENDED_NOT_HANDLED;
89
ret = slapi_pblock_get(pb, SLAPI_EXT_OP_REQ_VALUE, &req_val);
91
rc = LDAP_UNWILLING_TO_PERFORM;
92
err_msg = "Missing request data.\n";
96
ret = slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &ctx);
98
rc = LDAP_OPERATIONS_ERROR;
99
err_msg = "Missing plugin context.\n";
103
ret = parse_request_data(req_val, &req);
104
if (ret != LDAP_SUCCESS) {
105
rc = LDAP_UNWILLING_TO_PERFORM;
106
err_msg = "Cannot parse request data.\n";
110
ret = handle_request(ctx, req, &res);
111
if (ret != LDAP_SUCCESS) {
112
rc = LDAP_OPERATIONS_ERROR;
113
err_msg = "Failed to handle the request.\n";
117
ret = pack_response(res, &ret_val);
118
if (ret != LDAP_SUCCESS) {
119
rc = LDAP_OPERATIONS_ERROR;
120
err_msg = "Failed to pack the response.\n";
124
ret = slapi_pblock_set(pb, SLAPI_EXT_OP_RET_OID, EXOP_EXTDOM_OID);
126
rc = LDAP_OPERATIONS_ERROR;
127
err_msg = "Failed to set the OID for the response.\n";
131
ret = slapi_pblock_set( pb, SLAPI_EXT_OP_RET_VALUE, ret_val);
133
rc = LDAP_OPERATIONS_ERROR;
134
err_msg = "Failed to set the value for the response.\n";
143
if (err_msg != NULL) {
146
slapi_send_ldap_result(pb, rc, NULL, err_msg, 0, NULL);
147
return SLAPI_PLUGIN_EXTENDED_SENT_RESULT;
150
static int ipa_extdom_init_ctx(Slapi_PBlock *pb, struct ipa_extdom_ctx **_ctx)
152
struct ipa_extdom_ctx *ctx;
156
ctx = calloc(1, sizeof(struct ipa_extdom_ctx));
158
return LDAP_OPERATIONS_ERROR;
161
ret = slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &ctx->plugin_id);
162
if ((ret != 0) || (NULL == ctx->plugin_id)) {
163
LOG_FATAL("Could not get identity or identity was NULL\n");
170
slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &e);
172
LOG_FATAL("Plugin configuration not found!\n");
177
ctx->base_dn = slapi_entry_attr_get_charptr(e, "nsslapd-basedn");
179
LOG_FATAL("Base DN not found in plugin configuration not found!\n");
194
int ipa_extdom_init(Slapi_PBlock *pb)
197
struct ipa_extdom_ctx *extdom_ctx;
199
ret = ipa_extdom_init_ctx(pb, &extdom_ctx);
201
LOG_FATAL("Failed ot initialize external domain extended operation.\n");
202
/* do not cause DS to stop, simply do nothing */
206
ret = slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01);
208
ret = slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION,
209
(void *)&ipa_extdom_plugin_desc);
212
ret = slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN,
213
(void *)ipa_extdom_start);
216
ret = slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_OIDLIST,
217
ipa_extdom_oid_list);
220
ret = slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_NAMELIST,
221
ipa_extdom_name_list);
224
ret = slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_FN,
225
(void *)ipa_extdom_extop);
228
ret = slapi_pblock_set(pb, SLAPI_PLUGIN_PRIVATE, extdom_ctx);
231
LOG("Failed to set plug-in version, function, and OID.\n" );