~ubuntu-branches/debian/sid/freeipa/sid

« back to all changes in this revision

Viewing changes to daemons/ipa-slapi-plugins/ipa-extdom-extop/ipa_extdom_extop.c

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2014-10-25 02:43:59 UTC
  • Revision ID: package-import@ubuntu.com-20141025024359-to6c607ln0lmzwik
Tags: upstream-4.0.4
ImportĀ upstreamĀ versionĀ 4.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
6
 *
 
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.
 
11
 *
 
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/>.
 
14
 *
 
15
 * Additional permission under GPLv3 section 7:
 
16
 *
 
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.
 
21
 *
 
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
 
31
 * Interfaces.
 
32
 *
 
33
 * Authors:
 
34
 * Sumit Bose <sbose@redhat.com>
 
35
 *
 
36
 * Copyright (C) 2011 Red Hat, Inc.
 
37
 * All rights reserved.
 
38
 * END COPYRIGHT BLOCK **/
 
39
 
 
40
#include "ipa_extdom.h"
 
41
#include "util.h"
 
42
 
 
43
Slapi_PluginDesc ipa_extdom_plugin_desc = {
 
44
    IPA_EXTDOM_FEATURE_DESC,
 
45
    "FreeIPA project",
 
46
    "FreeIPA/1.0",
 
47
    IPA_EXTDOM_PLUGIN_DESC
 
48
};
 
49
 
 
50
static char *ipa_extdom_oid_list[] = {
 
51
    EXOP_EXTDOM_OID,
 
52
    NULL
 
53
};
 
54
 
 
55
static char *ipa_extdom_name_list[] = {
 
56
    IPA_EXTDOM_PLUGIN_DESC,
 
57
    NULL
 
58
};
 
59
 
 
60
static int ipa_extdom_start(Slapi_PBlock *pb)
 
61
{
 
62
    return LDAP_SUCCESS;
 
63
}
 
64
 
 
65
static int ipa_extdom_extop(Slapi_PBlock *pb)
 
66
{
 
67
    char *oid = NULL;
 
68
    char *err_msg = NULL;
 
69
    int rc;
 
70
    int ret;
 
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;
 
76
 
 
77
    ret = slapi_pblock_get(pb, SLAPI_EXT_OP_REQ_OID, &oid);
 
78
    if (ret != 0) {
 
79
        rc = LDAP_OPERATIONS_ERROR;
 
80
        err_msg = "Could not get OID value from request.\n";
 
81
        goto done;
 
82
    }
 
83
    LOG("Received extended operation request with OID %s\n", oid);
 
84
 
 
85
    if (strcasecmp(oid, EXOP_EXTDOM_OID) != 0) {
 
86
        return SLAPI_PLUGIN_EXTENDED_NOT_HANDLED;
 
87
    }
 
88
 
 
89
    ret = slapi_pblock_get(pb, SLAPI_EXT_OP_REQ_VALUE, &req_val);
 
90
    if (ret != 0) {
 
91
        rc = LDAP_UNWILLING_TO_PERFORM;
 
92
        err_msg = "Missing request data.\n";
 
93
        goto done;
 
94
    }
 
95
 
 
96
    ret = slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &ctx);
 
97
    if (ret != 0) {
 
98
        rc = LDAP_OPERATIONS_ERROR;
 
99
        err_msg = "Missing plugin context.\n";
 
100
        goto done;
 
101
    }
 
102
 
 
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";
 
107
        goto done;
 
108
    }
 
109
 
 
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";
 
114
        goto done;
 
115
    }
 
116
 
 
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";
 
121
        goto done;
 
122
    }
 
123
 
 
124
    ret = slapi_pblock_set(pb, SLAPI_EXT_OP_RET_OID, EXOP_EXTDOM_OID);
 
125
    if (ret != 0) {
 
126
        rc = LDAP_OPERATIONS_ERROR;
 
127
        err_msg = "Failed to set the OID for the response.\n";
 
128
        goto done;
 
129
    }
 
130
 
 
131
    ret = slapi_pblock_set( pb, SLAPI_EXT_OP_RET_VALUE, ret_val);
 
132
    if (ret != 0) {
 
133
        rc = LDAP_OPERATIONS_ERROR;
 
134
        err_msg = "Failed to set the value for the response.\n";
 
135
        goto done;
 
136
    }
 
137
 
 
138
    rc = LDAP_SUCCESS;
 
139
 
 
140
done:
 
141
    free_req_data(req);
 
142
    free_resp_data(res);
 
143
    if (err_msg != NULL) {
 
144
        LOG("%s", err_msg);
 
145
    }
 
146
    slapi_send_ldap_result(pb, rc, NULL, err_msg, 0, NULL);
 
147
    return SLAPI_PLUGIN_EXTENDED_SENT_RESULT;
 
148
}
 
149
 
 
150
static int ipa_extdom_init_ctx(Slapi_PBlock *pb, struct ipa_extdom_ctx **_ctx)
 
151
{
 
152
    struct ipa_extdom_ctx *ctx;
 
153
    Slapi_Entry *e;
 
154
    int ret;
 
155
 
 
156
    ctx = calloc(1, sizeof(struct ipa_extdom_ctx));
 
157
    if (!ctx) {
 
158
        return LDAP_OPERATIONS_ERROR;
 
159
    }
 
160
 
 
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");
 
164
        if (ret == 0) {
 
165
            ret = -1;
 
166
        }
 
167
        goto done;
 
168
    }
 
169
 
 
170
    slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &e);
 
171
    if (!e) {
 
172
        LOG_FATAL("Plugin configuration not found!\n");
 
173
        ret = -1;
 
174
        goto done;
 
175
    }
 
176
 
 
177
    ctx->base_dn = slapi_entry_attr_get_charptr(e, "nsslapd-basedn");
 
178
    if (!ctx->base_dn) {
 
179
        LOG_FATAL("Base DN not found in plugin configuration not found!\n");
 
180
        ret = -1;
 
181
        goto done;
 
182
    }
 
183
 
 
184
 
 
185
done:
 
186
    if (ret) {
 
187
        free(ctx);
 
188
    } else {
 
189
        *_ctx = ctx;
 
190
    }
 
191
    return ret;
 
192
}
 
193
 
 
194
int ipa_extdom_init(Slapi_PBlock *pb)
 
195
{
 
196
    int ret;
 
197
    struct ipa_extdom_ctx *extdom_ctx;
 
198
 
 
199
    ret = ipa_extdom_init_ctx(pb, &extdom_ctx);
 
200
    if (ret) {
 
201
        LOG_FATAL("Failed ot initialize external domain extended operation.\n");
 
202
        /* do not cause DS to stop, simply do nothing */
 
203
        return 0;
 
204
    }
 
205
 
 
206
    ret = slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01);
 
207
    if (!ret) {
 
208
        ret = slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION,
 
209
                               (void *)&ipa_extdom_plugin_desc);
 
210
    }
 
211
    if (!ret) {
 
212
        ret = slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN,
 
213
                               (void *)ipa_extdom_start);
 
214
    }
 
215
    if (!ret) {
 
216
        ret = slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_OIDLIST,
 
217
                               ipa_extdom_oid_list);
 
218
    }
 
219
    if (!ret) {
 
220
        ret = slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_NAMELIST,
 
221
                               ipa_extdom_name_list);
 
222
    }
 
223
    if (!ret) {
 
224
        ret = slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_FN,
 
225
                               (void *)ipa_extdom_extop);
 
226
    }
 
227
    if (!ret) {
 
228
        ret = slapi_pblock_set(pb, SLAPI_PLUGIN_PRIVATE, extdom_ctx);
 
229
    }
 
230
    if (ret) {
 
231
        LOG("Failed to set plug-in version, function, and OID.\n" );
 
232
        return -1;
 
233
    }
 
234
 
 
235
    return 0;
 
236
}