1fcf3ce44SJohn Forte /*
2fcf3ce44SJohn Forte * CDDL HEADER START
3fcf3ce44SJohn Forte *
4fcf3ce44SJohn Forte * The contents of this file are subject to the terms of the
5fcf3ce44SJohn Forte * Common Development and Distribution License (the "License").
6fcf3ce44SJohn Forte * You may not use this file except in compliance with the License.
7fcf3ce44SJohn Forte *
8fcf3ce44SJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fcf3ce44SJohn Forte * or http://www.opensolaris.org/os/licensing.
10fcf3ce44SJohn Forte * See the License for the specific language governing permissions
11fcf3ce44SJohn Forte * and limitations under the License.
12fcf3ce44SJohn Forte *
13fcf3ce44SJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
14fcf3ce44SJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fcf3ce44SJohn Forte * If applicable, add the following below this CDDL HEADER, with the
16fcf3ce44SJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
17fcf3ce44SJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
18fcf3ce44SJohn Forte *
19fcf3ce44SJohn Forte * CDDL HEADER END
20fcf3ce44SJohn Forte */
21fcf3ce44SJohn Forte /*
223f1da666Swl * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23fcf3ce44SJohn Forte * Use is subject to license terms.
24fcf3ce44SJohn Forte */
25fcf3ce44SJohn Forte
26fcf3ce44SJohn Forte #include <libxml/xmlreader.h>
27fcf3ce44SJohn Forte #include <libxml/xmlwriter.h>
28fcf3ce44SJohn Forte #include <libxml/tree.h>
29fcf3ce44SJohn Forte #include <libxml/parser.h>
30fcf3ce44SJohn Forte #include <libxml/xpath.h>
31fcf3ce44SJohn Forte #include <stropts.h>
32fcf3ce44SJohn Forte #include <door.h>
33fcf3ce44SJohn Forte #include <errno.h>
34fcf3ce44SJohn Forte #include <sys/types.h>
35fcf3ce44SJohn Forte #include <unistd.h>
36fcf3ce44SJohn Forte #include <pwd.h>
37fcf3ce44SJohn Forte #include <auth_attr.h>
38fcf3ce44SJohn Forte #include <secdb.h>
39fcf3ce44SJohn Forte #include <sys/stat.h>
40fcf3ce44SJohn Forte #include <fcntl.h>
41fcf3ce44SJohn Forte #include <sys/stat.h>
42fcf3ce44SJohn Forte #include <sys/mman.h>
43fcf3ce44SJohn Forte #include <string.h>
44fcf3ce44SJohn Forte #include <alloca.h>
45fcf3ce44SJohn Forte #include <pthread.h>
46fcf3ce44SJohn Forte #include <ucred.h>
47*b0709259SAndy Fiddaman #include <stdlib.h>
48fcf3ce44SJohn Forte #include "isns_server.h"
49fcf3ce44SJohn Forte #include "admintf.h"
50fcf3ce44SJohn Forte #include "isns_mgmt.h"
51fcf3ce44SJohn Forte #include "isns_utils.h"
52fcf3ce44SJohn Forte #include "isns_protocol.h"
53fcf3ce44SJohn Forte #include "isns_log.h"
54fcf3ce44SJohn Forte #include "isns_provider.h"
55fcf3ce44SJohn Forte
563f1da666Swl /* door creation flag */
573f1da666Swl extern boolean_t door_created;
583f1da666Swl
59fcf3ce44SJohn Forte /* macro for allocating name buffers for the request */
60fcf3ce44SJohn Forte #define NEW_REQARGV(old, n) (xmlChar **)realloc((xmlChar *)old, \
61fcf3ce44SJohn Forte (unsigned)(n+2) * sizeof (xmlChar *))
62fcf3ce44SJohn Forte
63fcf3ce44SJohn Forte /* macro for allocating association pair buffers for the request */
64fcf3ce44SJohn Forte #define NEW_REQPAIRARGV(old, n) (assoc_pair_t **)realloc((assoc_pair_t *)old, \
65fcf3ce44SJohn Forte (unsigned)(n+2) * sizeof (assoc_pair_t *))
66fcf3ce44SJohn Forte
67fcf3ce44SJohn Forte /* macro for allocating DD/DD set attribute list buffers for the request */
68fcf3ce44SJohn Forte #define NEW_REQATTRLISTARGV(old, n)\
69fcf3ce44SJohn Forte (object_attrlist_t **)realloc((object_attrlist_t *)old, \
70fcf3ce44SJohn Forte (unsigned)(n+2) * sizeof (object_attrlist_t *))
71fcf3ce44SJohn Forte
720687de4fSAlexander Pyhalov #if LIBXML_VERSION >= 20904
730687de4fSAlexander Pyhalov #define XMLSTRING_CAST (const char *)
740687de4fSAlexander Pyhalov #else
750687de4fSAlexander Pyhalov #define XMLSTRING_CAST (const xmlChar *)
760687de4fSAlexander Pyhalov #endif
770687de4fSAlexander Pyhalov
78fcf3ce44SJohn Forte /* operation table */
79fcf3ce44SJohn Forte static op_table_entry_t op_table[] = {
80fcf3ce44SJohn Forte {GET, get_op},
81fcf3ce44SJohn Forte {GETASSOCIATED, getAssociated_op},
82fcf3ce44SJohn Forte {ENUMERATE, enumerate_op},
83fcf3ce44SJohn Forte {CREATEMODIFY, createModify_op},
84fcf3ce44SJohn Forte {DELETE, delete_op},
85fcf3ce44SJohn Forte {NULL, 0}
86fcf3ce44SJohn Forte };
87fcf3ce44SJohn Forte
88fcf3ce44SJohn Forte /* object table */
89fcf3ce44SJohn Forte static obj_table_entry_t obj_table[] = {
90fcf3ce44SJohn Forte {NODEOBJECT, Node},
91fcf3ce44SJohn Forte {DDOBJECT, DiscoveryDomain},
92fcf3ce44SJohn Forte {DDSETOBJECT, DiscoveryDomainSet},
93fcf3ce44SJohn Forte {DDOBJECTMEMBER, DiscoveryDomainMember},
94fcf3ce44SJohn Forte {DDSETOBJECTMEMBER, DiscoveryDomainSetMember},
95fcf3ce44SJohn Forte {ISNSSERVER, ServerConfig},
96fcf3ce44SJohn Forte {NULL, 0}
97fcf3ce44SJohn Forte };
98fcf3ce44SJohn Forte
99fcf3ce44SJohn Forte /*
100fcf3ce44SJohn Forte * list to capture thread id and associated door return buffer
101fcf3ce44SJohn Forte * the return buffer from the previous door return is freed
102fcf3ce44SJohn Forte * when the same thread is invoked to take another request.
103fcf3ce44SJohn Forte * While the server is running one buffer is outstanding
104fcf3ce44SJohn Forte * to be freed.
105fcf3ce44SJohn Forte */
106fcf3ce44SJohn Forte static thr_elem_t *thr_list = NULL;
107fcf3ce44SJohn Forte
108fcf3ce44SJohn Forte /*
109fcf3ce44SJohn Forte * get_op_id_from_doc --
110fcf3ce44SJohn Forte * extracts an operation id through the given context ptr.
111fcf3ce44SJohn Forte *
112fcf3ce44SJohn Forte * ctext: context ptr for the original doc
113fcf3ce44SJohn Forte *
114fcf3ce44SJohn Forte * Returns an operation id if found or -1 otherwise.
115fcf3ce44SJohn Forte */
116fcf3ce44SJohn Forte static int
get_op_id_from_doc(xmlXPathContextPtr ctext)117fcf3ce44SJohn Forte get_op_id_from_doc(xmlXPathContextPtr ctext)
118fcf3ce44SJohn Forte {
119fcf3ce44SJohn Forte xmlChar expr[ISNS_MAX_LABEL_LEN + 13];
120fcf3ce44SJohn Forte xmlXPathObjectPtr xpath_obj = NULL;
121fcf3ce44SJohn Forte int i;
122fcf3ce44SJohn Forte
123fcf3ce44SJohn Forte for (i = 0; op_table[i].op_str != NULL; i++) {
124fcf3ce44SJohn Forte (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13,
1250687de4fSAlexander Pyhalov XMLSTRING_CAST "%s\"%s\"]", "//*[name()=",
126fcf3ce44SJohn Forte op_table[i].op_str);
127fcf3ce44SJohn Forte xpath_obj = xmlXPathEvalExpression(expr, ctext);
128fcf3ce44SJohn Forte if ((xpath_obj) && (xpath_obj->nodesetval) &&
129fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeNr > 0) &&
130fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeTab)) {
131fcf3ce44SJohn Forte isnslog(LOG_DEBUG, "get_op_id_from_doc ",
132fcf3ce44SJohn Forte "xpath obj->nodesetval->nodeNr: %d",
133fcf3ce44SJohn Forte xpath_obj->nodesetval->nodeNr);
134fcf3ce44SJohn Forte isnslog(LOG_DEBUG, "get_op_id_from_doc", "operation: %s id: %d",
135fcf3ce44SJohn Forte op_table[i].op_str, op_table[i].op_id);
136fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
137fcf3ce44SJohn Forte return (op_table[i].op_id);
138fcf3ce44SJohn Forte }
139fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
140fcf3ce44SJohn Forte }
141fcf3ce44SJohn Forte
142fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
143fcf3ce44SJohn Forte return (-1);
144fcf3ce44SJohn Forte }
145fcf3ce44SJohn Forte
146fcf3ce44SJohn Forte /*
147fcf3ce44SJohn Forte * process_get_request_from_doc --
148fcf3ce44SJohn Forte * looks for the object through the context ptr and gets the object
149fcf3ce44SJohn Forte * name. Possible object types are Node, DD, DD set and server-config.
150fcf3ce44SJohn Forte *
151fcf3ce44SJohn Forte * ctext: context ptr for the original doc to parse request info.
152fcf3ce44SJohn Forte * req: request to be filled up.
153fcf3ce44SJohn Forte *
154fcf3ce44SJohn Forte * Returns 0 if successful or an error code otherwise.
155fcf3ce44SJohn Forte */
156fcf3ce44SJohn Forte static int
process_get_request_from_doc(xmlXPathContextPtr ctext,request_t * req)157fcf3ce44SJohn Forte process_get_request_from_doc(xmlXPathContextPtr ctext, request_t *req)
158fcf3ce44SJohn Forte {
159fcf3ce44SJohn Forte xmlChar expr[ISNS_MAX_LABEL_LEN + 13];
160fcf3ce44SJohn Forte xmlXPathObjectPtr xpath_obj = NULL;
161fcf3ce44SJohn Forte xmlNodeSetPtr r_nodes = NULL;
162fcf3ce44SJohn Forte xmlAttrPtr attr = NULL;
163fcf3ce44SJohn Forte int i, cnt;
164fcf3ce44SJohn Forte
165fcf3ce44SJohn Forte int obj = 0;
166fcf3ce44SJohn Forte
167fcf3ce44SJohn Forte isnslog(LOG_DEBUG, "process_get_request_from_doc", "entered");
168fcf3ce44SJohn Forte (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13,
1690687de4fSAlexander Pyhalov XMLSTRING_CAST "%s\"%s\"]", "//*[name()=", ISNSOBJECT);
170fcf3ce44SJohn Forte xpath_obj = xmlXPathEvalExpression(expr, ctext);
171fcf3ce44SJohn Forte if ((xpath_obj) && (xpath_obj->nodesetval) &&
172fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeTab) &&
173fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeNr > 0) &&
174fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeTab[0]->children) &&
175fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeTab[0]->children->name)) {
176fcf3ce44SJohn Forte for (i = 0; obj_table[i].obj_str != NULL; i++) {
177fcf3ce44SJohn Forte /*
178fcf3ce44SJohn Forte * To handle DiscoveryDomain and DiscoveryDomainSet
179fcf3ce44SJohn Forte * searches isnsobject instead of the object directly.
180fcf3ce44SJohn Forte */
181fcf3ce44SJohn Forte if (xmlStrncmp(
182fcf3ce44SJohn Forte xpath_obj->nodesetval->nodeTab[0]->children->name,
183fcf3ce44SJohn Forte (xmlChar *)obj_table[i].obj_str, xmlStrlen(
184fcf3ce44SJohn Forte xpath_obj->nodesetval->nodeTab[0]->children->name))
185fcf3ce44SJohn Forte == 0) {
186fcf3ce44SJohn Forte obj = obj_table[i].obj_id;
187fcf3ce44SJohn Forte break;
188fcf3ce44SJohn Forte }
189fcf3ce44SJohn Forte }
190fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
191fcf3ce44SJohn Forte }
192fcf3ce44SJohn Forte
193fcf3ce44SJohn Forte if (obj == 0) {
194fcf3ce44SJohn Forte /* check the server config request. */
195fcf3ce44SJohn Forte (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13,
1960687de4fSAlexander Pyhalov XMLSTRING_CAST "%s\"%s\"]", "//*[name()=", ISNSSERVER);
197fcf3ce44SJohn Forte xpath_obj = xmlXPathEvalExpression(expr, ctext);
198fcf3ce44SJohn Forte if ((xpath_obj) && (xpath_obj->nodesetval) &&
199fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeNr > 0) &&
200fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeTab)) {
201fcf3ce44SJohn Forte for (i = 0; obj_table[i].obj_str != NULL; i++) {
202fcf3ce44SJohn Forte if (strncmp(ISNSSERVER, obj_table[i].obj_str,
203fcf3ce44SJohn Forte strlen(ISNSSERVER)) == 0) {
204fcf3ce44SJohn Forte obj = obj_table[i].obj_id;
205fcf3ce44SJohn Forte break;
206fcf3ce44SJohn Forte }
207fcf3ce44SJohn Forte }
208fcf3ce44SJohn Forte }
209fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
210fcf3ce44SJohn Forte }
211fcf3ce44SJohn Forte
212fcf3ce44SJohn Forte if (obj == 0) {
213fcf3ce44SJohn Forte return (ERR_XML_VALID_OBJECT_NOT_FOUND);
214fcf3ce44SJohn Forte }
215fcf3ce44SJohn Forte
216fcf3ce44SJohn Forte req->op_info.obj = obj;
217fcf3ce44SJohn Forte
218fcf3ce44SJohn Forte if (ISNS_MGMT_OBJECT_TYPE_ENABLED()) {
219fcf3ce44SJohn Forte ISNS_MGMT_OBJECT_TYPE(obj);
220fcf3ce44SJohn Forte }
221fcf3ce44SJohn Forte
222fcf3ce44SJohn Forte (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 12,
2230687de4fSAlexander Pyhalov XMLSTRING_CAST "%s\"%s\"]", "//*[name()=",
224fcf3ce44SJohn Forte obj_table[i].obj_str);
225fcf3ce44SJohn Forte xpath_obj = xmlXPathEvalExpression(expr, ctext);
226fcf3ce44SJohn Forte if (((xpath_obj == NULL) || (xpath_obj->nodesetval == NULL) ||
227fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeNr <= 0) ||
228fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeTab == NULL))) {
229fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
230fcf3ce44SJohn Forte return (ERR_XML_VALID_OBJECT_NOT_FOUND);
231fcf3ce44SJohn Forte }
232fcf3ce44SJohn Forte
233fcf3ce44SJohn Forte switch (obj) {
234fcf3ce44SJohn Forte /* using the same algorithm for isns object */
235fcf3ce44SJohn Forte case Node:
236fcf3ce44SJohn Forte case DiscoveryDomain:
237fcf3ce44SJohn Forte case DiscoveryDomainSet:
238fcf3ce44SJohn Forte r_nodes = xpath_obj->nodesetval;
239fcf3ce44SJohn Forte cnt = r_nodes->nodeNr;
240fcf3ce44SJohn Forte req->count = 0;
241fcf3ce44SJohn Forte req->req_data.data = (xmlChar **) malloc(sizeof (xmlChar *));
242fcf3ce44SJohn Forte for (i = 0; i < cnt; i++) {
243fcf3ce44SJohn Forte attr = r_nodes->nodeTab[i]->properties;
244fcf3ce44SJohn Forte for (; attr != NULL; attr = attr->next) {
245fcf3ce44SJohn Forte if (xmlStrncmp(attr->name, (xmlChar *)NAMEATTR,
246fcf3ce44SJohn Forte xmlStrlen((xmlChar *)NAMEATTR)) == 0) {
247fcf3ce44SJohn Forte req->req_data.data =
248fcf3ce44SJohn Forte NEW_REQARGV(req->req_data.data, req->count);
249fcf3ce44SJohn Forte if (req->req_data.data == (xmlChar **)NULL) {
250fcf3ce44SJohn Forte if (xpath_obj)
251fcf3ce44SJohn Forte xmlXPathFreeObject(xpath_obj);
252fcf3ce44SJohn Forte return (ERR_MALLOC_FAILED);
253fcf3ce44SJohn Forte }
254fcf3ce44SJohn Forte req->req_data.data[req->count] =
255fcf3ce44SJohn Forte xmlNodeGetContent(attr->children);
256fcf3ce44SJohn Forte req->req_data.data[++req->count] = NULL;
257fcf3ce44SJohn Forte }
258fcf3ce44SJohn Forte }
259fcf3ce44SJohn Forte }
260fcf3ce44SJohn Forte break;
261fcf3ce44SJohn Forte case ServerConfig:
262fcf3ce44SJohn Forte /* indication the obj type is sufficient. */
263fcf3ce44SJohn Forte break;
264fcf3ce44SJohn Forte default:
265fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
266fcf3ce44SJohn Forte return (ERR_XML_OP_FAILED);
267fcf3ce44SJohn Forte }
268fcf3ce44SJohn Forte
269fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
270fcf3ce44SJohn Forte return (0);
271fcf3ce44SJohn Forte }
272fcf3ce44SJohn Forte
273fcf3ce44SJohn Forte /*
274fcf3ce44SJohn Forte * process_enumerate_request_from_doc --
275fcf3ce44SJohn Forte * looks for the object through the context ptr and sets the
276fcf3ce44SJohn Forte * request with object type.
277fcf3ce44SJohn Forte *
278fcf3ce44SJohn Forte * ctext: context ptr for the original doc to parse request info.
279fcf3ce44SJohn Forte * req: request to be filled up.
280fcf3ce44SJohn Forte *
281fcf3ce44SJohn Forte * Returns 0 if successful or an error code otherwise.
282fcf3ce44SJohn Forte */
283fcf3ce44SJohn Forte static int
process_enumerate_request_from_doc(xmlXPathContextPtr ctext,request_t * req)284fcf3ce44SJohn Forte process_enumerate_request_from_doc(xmlXPathContextPtr ctext, request_t *req)
285fcf3ce44SJohn Forte {
286fcf3ce44SJohn Forte xmlChar expr[ISNS_MAX_LABEL_LEN + 13];
287fcf3ce44SJohn Forte xmlXPathObjectPtr xpath_obj = NULL;
288fcf3ce44SJohn Forte int i;
289fcf3ce44SJohn Forte
290fcf3ce44SJohn Forte int obj = 0;
291fcf3ce44SJohn Forte
292fcf3ce44SJohn Forte isnslog(LOG_DEBUG, "process_enumerate_request_from_doc", "entered");
293fcf3ce44SJohn Forte (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13,
2940687de4fSAlexander Pyhalov XMLSTRING_CAST "%s\"%s\"]", "//*[name()=", ISNSOBJECTTYPE);
295fcf3ce44SJohn Forte xpath_obj = xmlXPathEvalExpression(expr, ctext);
296fcf3ce44SJohn Forte isnslog(LOG_DEBUG, "process_enumerate_request_from_doc",
297fcf3ce44SJohn Forte "xpath obj->nodesetval->nodeNR: %d", xpath_obj->nodesetval->nodeNr);
298fcf3ce44SJohn Forte if ((xpath_obj) && (xpath_obj->nodesetval) &&
299fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeNr > 0) &&
300fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeTab)) {
301fcf3ce44SJohn Forte for (i = 0; obj_table[i].obj_str != NULL; i++) {
302fcf3ce44SJohn Forte if (xmlStrncmp(
303fcf3ce44SJohn Forte xpath_obj->nodesetval->nodeTab[0]->children->content,
304fcf3ce44SJohn Forte (xmlChar *)obj_table[i].obj_str, xmlStrlen((xmlChar *)
305fcf3ce44SJohn Forte xpath_obj->nodesetval->nodeTab[0]->children->content))
306fcf3ce44SJohn Forte == 0) {
307fcf3ce44SJohn Forte obj = obj_table[i].obj_id;
308fcf3ce44SJohn Forte break;
309fcf3ce44SJohn Forte }
310fcf3ce44SJohn Forte }
311fcf3ce44SJohn Forte } else {
312fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
313fcf3ce44SJohn Forte return (ERR_XML_VALID_OBJECT_NOT_FOUND);
314fcf3ce44SJohn Forte }
315fcf3ce44SJohn Forte
316fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
317fcf3ce44SJohn Forte
318fcf3ce44SJohn Forte if (obj == 0) {
319fcf3ce44SJohn Forte return (ERR_XML_VALID_OBJECT_NOT_FOUND);
320fcf3ce44SJohn Forte }
321fcf3ce44SJohn Forte
322fcf3ce44SJohn Forte req->op_info.obj = obj;
323fcf3ce44SJohn Forte
324fcf3ce44SJohn Forte if (ISNS_MGMT_OBJECT_TYPE_ENABLED()) {
325fcf3ce44SJohn Forte ISNS_MGMT_OBJECT_TYPE(obj);
326fcf3ce44SJohn Forte }
327fcf3ce44SJohn Forte
328fcf3ce44SJohn Forte return (0);
329fcf3ce44SJohn Forte }
330fcf3ce44SJohn Forte
331fcf3ce44SJohn Forte /*
332fcf3ce44SJohn Forte * process_getAssociated_request_from_doc --
333fcf3ce44SJohn Forte * first looks for association type through the contexti and then
334fcf3ce44SJohn Forte * find out the given object. That will indicate the direction of
335fcf3ce44SJohn Forte * association, containter to member or vice versa.
336fcf3ce44SJohn Forte * Lastly it extract the object name form the doc that assocation
337fcf3ce44SJohn Forte * is requested.
338fcf3ce44SJohn Forte *
339fcf3ce44SJohn Forte * ctext: context ptr for the original doc to parse request info.
340fcf3ce44SJohn Forte * req: request to be filled up.
341fcf3ce44SJohn Forte *
342fcf3ce44SJohn Forte * Returns 0 if successful or an error code otherwise.
343fcf3ce44SJohn Forte */
344fcf3ce44SJohn Forte static int
process_getAssociated_request_from_doc(xmlXPathContextPtr ctext,request_t * req)345fcf3ce44SJohn Forte process_getAssociated_request_from_doc(xmlXPathContextPtr ctext, request_t *req)
346fcf3ce44SJohn Forte {
347fcf3ce44SJohn Forte xmlChar expr[ISNS_MAX_LABEL_LEN + 13];
348fcf3ce44SJohn Forte xmlXPathObjectPtr xpath_obj = NULL;
349fcf3ce44SJohn Forte xmlNodeSetPtr r_nodes = NULL;
350fcf3ce44SJohn Forte xmlAttrPtr attr = NULL;
351fcf3ce44SJohn Forte int i, cnt, obj = 0;
352fcf3ce44SJohn Forte
353fcf3ce44SJohn Forte isnslog(LOG_DEBUG, "process_getAssociated_request_from_doc", "entered");
354fcf3ce44SJohn Forte (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13,
3550687de4fSAlexander Pyhalov XMLSTRING_CAST "%s\"%s\"]", "//*[name()=", ASSOCIATIONTYPE);
356fcf3ce44SJohn Forte xpath_obj = xmlXPathEvalExpression(expr, ctext);
357fcf3ce44SJohn Forte if ((xpath_obj) && (xpath_obj->nodesetval) &&
358fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeNr > 0) &&
359fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeTab)) {
360fcf3ce44SJohn Forte for (i = 0; obj_table[i].obj_str != NULL; i++) {
361fcf3ce44SJohn Forte if (xmlStrncmp(
362fcf3ce44SJohn Forte xpath_obj->nodesetval->nodeTab[0]->children->content,
363fcf3ce44SJohn Forte (xmlChar *)obj_table[i].obj_str, xmlStrlen(
364fcf3ce44SJohn Forte xpath_obj->nodesetval->nodeTab[0]->children->content))
365fcf3ce44SJohn Forte == 0) {
366fcf3ce44SJohn Forte obj = obj_table[i].obj_id;
367fcf3ce44SJohn Forte break;
368fcf3ce44SJohn Forte }
369fcf3ce44SJohn Forte }
370fcf3ce44SJohn Forte }
371fcf3ce44SJohn Forte
372fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
373fcf3ce44SJohn Forte
374fcf3ce44SJohn Forte if (obj == 0) {
375fcf3ce44SJohn Forte return (ERR_XML_VALID_OBJECT_NOT_FOUND);
376fcf3ce44SJohn Forte }
377fcf3ce44SJohn Forte
378fcf3ce44SJohn Forte req->op_info.obj = obj;
379fcf3ce44SJohn Forte
380fcf3ce44SJohn Forte if (ISNS_MGMT_OBJECT_TYPE_ENABLED()) {
381fcf3ce44SJohn Forte ISNS_MGMT_OBJECT_TYPE(obj);
382fcf3ce44SJohn Forte }
383fcf3ce44SJohn Forte
384fcf3ce44SJohn Forte switch (obj) {
385fcf3ce44SJohn Forte /* using the same algorithm for isns object */
386fcf3ce44SJohn Forte case DiscoveryDomainMember:
387fcf3ce44SJohn Forte (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13,
3880687de4fSAlexander Pyhalov XMLSTRING_CAST "%s\"%s\"]", "//*[name()=", NODEOBJECT);
389fcf3ce44SJohn Forte xpath_obj = xmlXPathEvalExpression(expr, ctext);
390fcf3ce44SJohn Forte r_nodes = xpath_obj->nodesetval;
391fcf3ce44SJohn Forte if ((xpath_obj) && (xpath_obj->nodesetval) &&
392fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeNr > 0) &&
393fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeTab)) {
394fcf3ce44SJohn Forte req->assoc_req = member_to_container;
395fcf3ce44SJohn Forte } else {
396fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
397fcf3ce44SJohn Forte (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13,
3980687de4fSAlexander Pyhalov XMLSTRING_CAST "%s\"%s\"]", "//*[name()=",
399fcf3ce44SJohn Forte DDOBJECT);
400fcf3ce44SJohn Forte xpath_obj = xmlXPathEvalExpression(expr, ctext);
401fcf3ce44SJohn Forte r_nodes = xpath_obj->nodesetval;
402fcf3ce44SJohn Forte if ((xpath_obj) && (xpath_obj->nodesetval) &&
403fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeNr > 0) &&
404fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeTab)) {
405fcf3ce44SJohn Forte req->assoc_req = container_to_member;
406fcf3ce44SJohn Forte } else {
407fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
408fcf3ce44SJohn Forte return (ERR_XML_VALID_OBJECT_NOT_FOUND);
409fcf3ce44SJohn Forte }
410fcf3ce44SJohn Forte }
411fcf3ce44SJohn Forte break;
412fcf3ce44SJohn Forte case DiscoveryDomainSetMember:
413fcf3ce44SJohn Forte (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13,
4140687de4fSAlexander Pyhalov XMLSTRING_CAST "%s\"%s\"]", "//*[name()=", DDSETOBJECT);
415fcf3ce44SJohn Forte xpath_obj = xmlXPathEvalExpression(expr, ctext);
416fcf3ce44SJohn Forte r_nodes = xpath_obj->nodesetval;
417fcf3ce44SJohn Forte if ((xpath_obj) && (xpath_obj->nodesetval) &&
418fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeNr > 0) &&
419fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeTab)) {
420fcf3ce44SJohn Forte req->assoc_req = container_to_member;
421fcf3ce44SJohn Forte } else {
422fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
423fcf3ce44SJohn Forte (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13,
4240687de4fSAlexander Pyhalov XMLSTRING_CAST "%s\"%s\"]", "//*[name()=",
425fcf3ce44SJohn Forte DDOBJECT);
426fcf3ce44SJohn Forte xpath_obj = xmlXPathEvalExpression(expr, ctext);
427fcf3ce44SJohn Forte r_nodes = xpath_obj->nodesetval;
428fcf3ce44SJohn Forte if ((xpath_obj) && (xpath_obj->nodesetval) &&
429fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeNr > 0) &&
430fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeTab)) {
431fcf3ce44SJohn Forte req->assoc_req = member_to_container;
432fcf3ce44SJohn Forte } else {
433fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
434fcf3ce44SJohn Forte return (ERR_XML_VALID_OBJECT_NOT_FOUND);
435fcf3ce44SJohn Forte }
436fcf3ce44SJohn Forte }
437fcf3ce44SJohn Forte break;
438fcf3ce44SJohn Forte default:
439fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
440fcf3ce44SJohn Forte return (ERR_XML_OP_FAILED);
441fcf3ce44SJohn Forte }
442fcf3ce44SJohn Forte
443fcf3ce44SJohn Forte /* now process the name attr */
444fcf3ce44SJohn Forte cnt = r_nodes->nodeNr;
445fcf3ce44SJohn Forte req->count = 0;
446fcf3ce44SJohn Forte req->req_data.data = (xmlChar **) malloc(sizeof (xmlChar *));
447fcf3ce44SJohn Forte /* for (i = cnt - 1; i >= 0; i--) { */
448fcf3ce44SJohn Forte for (i = 0; i < cnt; i++) {
449fcf3ce44SJohn Forte attr = r_nodes->nodeTab[i]->properties;
450fcf3ce44SJohn Forte for (; attr != NULL; attr = attr->next) {
451fcf3ce44SJohn Forte if (xmlStrncmp(attr->name, (xmlChar *)NAMEATTR,
452fcf3ce44SJohn Forte xmlStrlen((xmlChar *)NAMEATTR)) == 0) {
453fcf3ce44SJohn Forte req->req_data.data =
454fcf3ce44SJohn Forte NEW_REQARGV(req->req_data.data, req->count);
455fcf3ce44SJohn Forte if (req->req_data.data == (xmlChar **)NULL) {
456fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
457fcf3ce44SJohn Forte return (ERR_MALLOC_FAILED);
458fcf3ce44SJohn Forte }
459fcf3ce44SJohn Forte req->req_data.data[req->count++] =
460fcf3ce44SJohn Forte xmlNodeGetContent(attr->children);
461fcf3ce44SJohn Forte req->req_data.data[req->count] = NULL;
462fcf3ce44SJohn Forte }
463fcf3ce44SJohn Forte }
464fcf3ce44SJohn Forte }
465fcf3ce44SJohn Forte
466fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
467fcf3ce44SJohn Forte return (0);
468fcf3ce44SJohn Forte }
469fcf3ce44SJohn Forte
470fcf3ce44SJohn Forte /*
471fcf3ce44SJohn Forte * process_delete_request_from_doc --
472fcf3ce44SJohn Forte * first looks for the object through the context ptr and sets the
473fcf3ce44SJohn Forte * request with additional data.
474fcf3ce44SJohn Forte * For DD and DD set, the name is given.
475fcf3ce44SJohn Forte * For DD and DD set membership, container and member pairs are given.
476fcf3ce44SJohn Forte *
477fcf3ce44SJohn Forte * ctext: context ptr for the original doc to parse request info.
478fcf3ce44SJohn Forte * req: request to be filled up.
479fcf3ce44SJohn Forte *
480fcf3ce44SJohn Forte * Returns 0 if successful or an error code otherwise.
481fcf3ce44SJohn Forte */
482fcf3ce44SJohn Forte static int
process_delete_request_from_doc(xmlXPathContextPtr ctext,request_t * req)483fcf3ce44SJohn Forte process_delete_request_from_doc(xmlXPathContextPtr ctext, request_t *req)
484fcf3ce44SJohn Forte {
485fcf3ce44SJohn Forte xmlChar expr[ISNS_MAX_LABEL_LEN + 13];
486fcf3ce44SJohn Forte xmlXPathObjectPtr xpath_obj = NULL;
487fcf3ce44SJohn Forte xmlNodeSetPtr r_nodes = NULL;
488fcf3ce44SJohn Forte xmlAttrPtr attr = NULL;
489fcf3ce44SJohn Forte xmlChar *container = NULL, *member = NULL;
490fcf3ce44SJohn Forte int i, cnt;
491fcf3ce44SJohn Forte
492fcf3ce44SJohn Forte int obj = 0;
493fcf3ce44SJohn Forte
494fcf3ce44SJohn Forte isnslog(LOG_DEBUG, "process_delete_request_from_doc", "entered");
495fcf3ce44SJohn Forte for (i = 0; obj_table[i].obj_str != NULL; i++) {
496fcf3ce44SJohn Forte (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13,
4970687de4fSAlexander Pyhalov XMLSTRING_CAST "%s\"%s\"]", "//*[name()=",
498fcf3ce44SJohn Forte obj_table[i].obj_str);
499fcf3ce44SJohn Forte xpath_obj = xmlXPathEvalExpression(expr, ctext);
500fcf3ce44SJohn Forte if ((xpath_obj) && (xpath_obj->nodesetval) &&
501fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeNr > 0) &&
502fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeTab)) {
503fcf3ce44SJohn Forte obj = obj_table[i].obj_id;
504fcf3ce44SJohn Forte break;
505fcf3ce44SJohn Forte }
506fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
507fcf3ce44SJohn Forte }
508fcf3ce44SJohn Forte
509fcf3ce44SJohn Forte if (obj == 0) {
510fcf3ce44SJohn Forte return (ERR_XML_VALID_OBJECT_NOT_FOUND);
511fcf3ce44SJohn Forte }
512fcf3ce44SJohn Forte
513fcf3ce44SJohn Forte req->op_info.obj = obj;
514fcf3ce44SJohn Forte
515fcf3ce44SJohn Forte if (ISNS_MGMT_OBJECT_TYPE_ENABLED()) {
516fcf3ce44SJohn Forte ISNS_MGMT_OBJECT_TYPE(obj);
517fcf3ce44SJohn Forte }
518fcf3ce44SJohn Forte
519fcf3ce44SJohn Forte switch (obj) {
520fcf3ce44SJohn Forte case DiscoveryDomainMember:
521fcf3ce44SJohn Forte /* at least one object exists to get here. */
522fcf3ce44SJohn Forte r_nodes = xpath_obj->nodesetval;
523fcf3ce44SJohn Forte cnt = r_nodes->nodeNr;
524fcf3ce44SJohn Forte req->count = 0;
525fcf3ce44SJohn Forte req->req_data.pair =
526fcf3ce44SJohn Forte (assoc_pair_t **)malloc(sizeof (assoc_pair_t *));
527fcf3ce44SJohn Forte for (i = 0; i < cnt; i++) {
528fcf3ce44SJohn Forte attr = r_nodes->nodeTab[i]->properties;
529fcf3ce44SJohn Forte for (; attr != NULL; attr = attr->next) {
530fcf3ce44SJohn Forte if (xmlStrncmp(attr->name, (xmlChar *)DDNAMEATTR,
531fcf3ce44SJohn Forte xmlStrlen((xmlChar *)DDNAMEATTR)) == 0) {
532fcf3ce44SJohn Forte container =
533fcf3ce44SJohn Forte xmlNodeGetContent(attr->children);
534fcf3ce44SJohn Forte }
535fcf3ce44SJohn Forte if (xmlStrncmp(attr->name, (xmlChar *)NODENAMEATTR,
536fcf3ce44SJohn Forte xmlStrlen((xmlChar *)NODENAMEATTR)) == 0) {
537fcf3ce44SJohn Forte member =
538fcf3ce44SJohn Forte xmlNodeGetContent(attr->children);
539fcf3ce44SJohn Forte }
540fcf3ce44SJohn Forte }
541fcf3ce44SJohn Forte if (container != NULL && member != NULL) {
542fcf3ce44SJohn Forte req->req_data.pair =
543fcf3ce44SJohn Forte NEW_REQPAIRARGV(req->req_data.pair, req->count);
544fcf3ce44SJohn Forte if (req->req_data.pair == (assoc_pair_t **)NULL) {
545fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
546fcf3ce44SJohn Forte return (ERR_MALLOC_FAILED);
547fcf3ce44SJohn Forte }
548fcf3ce44SJohn Forte req->req_data.pair[req->count] = (assoc_pair_t *)
549fcf3ce44SJohn Forte malloc(sizeof (assoc_pair_t));
550fcf3ce44SJohn Forte if (req->req_data.pair[req->count] == NULL) {
551fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
552fcf3ce44SJohn Forte return (ERR_MALLOC_FAILED);
553fcf3ce44SJohn Forte }
554fcf3ce44SJohn Forte req->req_data.pair[req->count]->container =
555fcf3ce44SJohn Forte container;
556fcf3ce44SJohn Forte req->req_data.pair[req->count]->member =
557fcf3ce44SJohn Forte member;
558fcf3ce44SJohn Forte req->req_data.data[++req->count] = NULL;
559fcf3ce44SJohn Forte } else {
560fcf3ce44SJohn Forte if (container != NULL) {
561fcf3ce44SJohn Forte xmlFree(container);
562fcf3ce44SJohn Forte }
563fcf3ce44SJohn Forte if (member != NULL) {
564fcf3ce44SJohn Forte xmlFree(member);
565fcf3ce44SJohn Forte }
566fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
567fcf3ce44SJohn Forte return (ERR_XML_OP_FAILED);
568fcf3ce44SJohn Forte }
569fcf3ce44SJohn Forte container = NULL;
570fcf3ce44SJohn Forte member = NULL;
571fcf3ce44SJohn Forte }
572fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
573fcf3ce44SJohn Forte break;
574fcf3ce44SJohn Forte case DiscoveryDomainSetMember:
575fcf3ce44SJohn Forte /* at least one object exists to get here. */
576fcf3ce44SJohn Forte r_nodes = xpath_obj->nodesetval;
577fcf3ce44SJohn Forte cnt = r_nodes->nodeNr;
578fcf3ce44SJohn Forte req->count = 0;
579fcf3ce44SJohn Forte req->req_data.pair =
580fcf3ce44SJohn Forte (assoc_pair_t **)malloc(sizeof (assoc_pair_t *));
581fcf3ce44SJohn Forte for (i = 0; i < cnt; i++) {
582fcf3ce44SJohn Forte attr = r_nodes->nodeTab[i]->properties;
583fcf3ce44SJohn Forte for (; attr != NULL; attr = attr->next) {
584fcf3ce44SJohn Forte if (xmlStrncmp(attr->name, (xmlChar *)DDSETNAMEATTR,
585fcf3ce44SJohn Forte xmlStrlen((xmlChar *)DDNAMEATTR)) == 0) {
586fcf3ce44SJohn Forte container =
587fcf3ce44SJohn Forte xmlNodeGetContent(attr->children);
588fcf3ce44SJohn Forte }
589fcf3ce44SJohn Forte if (xmlStrncmp(attr->name, (xmlChar *)DDNAMEATTR,
590fcf3ce44SJohn Forte xmlStrlen((xmlChar *)NODENAMEATTR)) == 0) {
591fcf3ce44SJohn Forte member =
592fcf3ce44SJohn Forte xmlNodeGetContent(attr->children);
593fcf3ce44SJohn Forte }
594fcf3ce44SJohn Forte }
595fcf3ce44SJohn Forte if (container != NULL && member != NULL) {
596fcf3ce44SJohn Forte req->req_data.pair =
597fcf3ce44SJohn Forte NEW_REQPAIRARGV(req->req_data.pair, req->count);
598fcf3ce44SJohn Forte if (req->req_data.pair == (assoc_pair_t **)NULL) {
599fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
600fcf3ce44SJohn Forte return (ERR_MALLOC_FAILED);
601fcf3ce44SJohn Forte }
602fcf3ce44SJohn Forte req->req_data.pair[req->count] = (assoc_pair_t *)
603fcf3ce44SJohn Forte malloc(sizeof (assoc_pair_t));
604fcf3ce44SJohn Forte if (req->req_data.pair[req->count] == NULL) {
605fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
606fcf3ce44SJohn Forte return (ERR_MALLOC_FAILED);
607fcf3ce44SJohn Forte }
608fcf3ce44SJohn Forte req->req_data.pair[req->count]->container =
609fcf3ce44SJohn Forte container;
610fcf3ce44SJohn Forte req->req_data.pair[req->count++]->member =
611fcf3ce44SJohn Forte member;
612fcf3ce44SJohn Forte req->req_data.data[req->count] = NULL;
613fcf3ce44SJohn Forte } else {
614fcf3ce44SJohn Forte if (container != NULL) {
615fcf3ce44SJohn Forte xmlFree(container);
616fcf3ce44SJohn Forte }
617fcf3ce44SJohn Forte if (member != NULL) {
618fcf3ce44SJohn Forte xmlFree(member);
619fcf3ce44SJohn Forte }
620fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
621fcf3ce44SJohn Forte return (ERR_XML_OP_FAILED);
622fcf3ce44SJohn Forte }
623fcf3ce44SJohn Forte }
624fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
625fcf3ce44SJohn Forte break;
626fcf3ce44SJohn Forte case DiscoveryDomain:
627fcf3ce44SJohn Forte case DiscoveryDomainSet:
628fcf3ce44SJohn Forte r_nodes = xpath_obj->nodesetval;
629fcf3ce44SJohn Forte cnt = r_nodes->nodeNr;
630fcf3ce44SJohn Forte req->count = 0;
631fcf3ce44SJohn Forte req->req_data.data = (xmlChar **) malloc(sizeof (xmlChar *));
632fcf3ce44SJohn Forte for (i = 0; i < cnt; i++) {
633fcf3ce44SJohn Forte attr = r_nodes->nodeTab[i]->properties;
634fcf3ce44SJohn Forte for (; attr != NULL; attr = attr->next) {
635fcf3ce44SJohn Forte if (xmlStrncmp(attr->name, (xmlChar *)NAMEATTR,
636fcf3ce44SJohn Forte xmlStrlen((xmlChar *)NAMEATTR)) == 0) {
637fcf3ce44SJohn Forte req->req_data.data =
638fcf3ce44SJohn Forte NEW_REQARGV(req->req_data.data, req->count);
639fcf3ce44SJohn Forte if (req->req_data.data == (xmlChar **)NULL) {
640fcf3ce44SJohn Forte if (xpath_obj)
641fcf3ce44SJohn Forte xmlXPathFreeObject(xpath_obj);
642fcf3ce44SJohn Forte return (ERR_MALLOC_FAILED);
643fcf3ce44SJohn Forte }
644fcf3ce44SJohn Forte req->req_data.data[req->count] =
645fcf3ce44SJohn Forte xmlNodeGetContent(attr->children);
646fcf3ce44SJohn Forte req->req_data.data[++req->count] = NULL;
647fcf3ce44SJohn Forte }
648fcf3ce44SJohn Forte }
649fcf3ce44SJohn Forte }
650fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
651fcf3ce44SJohn Forte break;
652fcf3ce44SJohn Forte default:
653fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
654fcf3ce44SJohn Forte return (ERR_XML_OP_FAILED);
655fcf3ce44SJohn Forte }
656fcf3ce44SJohn Forte
657fcf3ce44SJohn Forte return (0);
658fcf3ce44SJohn Forte }
659fcf3ce44SJohn Forte
660fcf3ce44SJohn Forte /*
661fcf3ce44SJohn Forte * process_createModify_request_from_doc --
662fcf3ce44SJohn Forte * first looks for the object through the context ptr and sets the
663fcf3ce44SJohn Forte * request with additional data.
664fcf3ce44SJohn Forte * For DD and DD set, the name is given.
665fcf3ce44SJohn Forte * For DD and DD set membership, container and member pairs are given.
666fcf3ce44SJohn Forte *
667fcf3ce44SJohn Forte * ctext: context ptr for the original doc to parse request info.
668fcf3ce44SJohn Forte * req: request to be filled up.
669fcf3ce44SJohn Forte *
670fcf3ce44SJohn Forte * Returns 0 if successful or an error code otherwise.
671fcf3ce44SJohn Forte */
672fcf3ce44SJohn Forte static int
process_createModify_request_from_doc(xmlXPathContextPtr ctext,request_t * req)673fcf3ce44SJohn Forte process_createModify_request_from_doc(xmlXPathContextPtr ctext, request_t *req)
674fcf3ce44SJohn Forte {
675fcf3ce44SJohn Forte xmlChar expr[ISNS_MAX_LABEL_LEN + 13];
676fcf3ce44SJohn Forte xmlXPathObjectPtr xpath_obj = NULL;
677fcf3ce44SJohn Forte xmlNodeSetPtr r_nodes = NULL;
678fcf3ce44SJohn Forte xmlAttrPtr attr = NULL;
679fcf3ce44SJohn Forte xmlChar *container = NULL, *member = NULL, *xml_id;
680fcf3ce44SJohn Forte int i, cnt;
681fcf3ce44SJohn Forte
682fcf3ce44SJohn Forte int obj = 0;
683fcf3ce44SJohn Forte
684fcf3ce44SJohn Forte isnslog(LOG_DEBUG, "process_createModify_request_from_doc", "entered");
685fcf3ce44SJohn Forte for (i = 0; obj_table[i].obj_str != NULL; i++) {
686fcf3ce44SJohn Forte (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13,
6870687de4fSAlexander Pyhalov XMLSTRING_CAST "%s\"%s\"]", "//*[name()=",
688fcf3ce44SJohn Forte obj_table[i].obj_str);
689fcf3ce44SJohn Forte xpath_obj = xmlXPathEvalExpression(expr, ctext);
690fcf3ce44SJohn Forte if ((xpath_obj) && (xpath_obj->nodesetval) &&
691fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeNr > 0) &&
692fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeTab)) {
693fcf3ce44SJohn Forte obj = obj_table[i].obj_id;
694fcf3ce44SJohn Forte break;
695fcf3ce44SJohn Forte }
696fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
697fcf3ce44SJohn Forte }
698fcf3ce44SJohn Forte
699fcf3ce44SJohn Forte if (obj == 0) {
700fcf3ce44SJohn Forte return (ERR_XML_VALID_OBJECT_NOT_FOUND);
701fcf3ce44SJohn Forte }
702fcf3ce44SJohn Forte
703fcf3ce44SJohn Forte req->op_info.obj = obj;
704fcf3ce44SJohn Forte
705fcf3ce44SJohn Forte if (ISNS_MGMT_OBJECT_TYPE_ENABLED()) {
706fcf3ce44SJohn Forte ISNS_MGMT_OBJECT_TYPE(obj);
707fcf3ce44SJohn Forte }
708fcf3ce44SJohn Forte
709fcf3ce44SJohn Forte switch (obj) {
710fcf3ce44SJohn Forte case DiscoveryDomainMember:
711fcf3ce44SJohn Forte /* at least one object exists to get here. */
712fcf3ce44SJohn Forte r_nodes = xpath_obj->nodesetval;
713fcf3ce44SJohn Forte cnt = r_nodes->nodeNr;
714fcf3ce44SJohn Forte req->count = 0;
715fcf3ce44SJohn Forte req->req_data.pair =
716fcf3ce44SJohn Forte (assoc_pair_t **)malloc(sizeof (assoc_pair_t *));
717fcf3ce44SJohn Forte for (i = 0; i < cnt; i++) {
718fcf3ce44SJohn Forte attr = r_nodes->nodeTab[i]->properties;
719fcf3ce44SJohn Forte for (; attr != NULL; attr = attr->next) {
720fcf3ce44SJohn Forte if (xmlStrncmp(attr->name, (xmlChar *)DDNAMEATTR,
721fcf3ce44SJohn Forte xmlStrlen((xmlChar *)DDNAMEATTR)) == 0) {
722fcf3ce44SJohn Forte container =
723fcf3ce44SJohn Forte xmlNodeGetContent(attr->children);
724fcf3ce44SJohn Forte }
725fcf3ce44SJohn Forte if (xmlStrncmp(attr->name, (xmlChar *)NODENAMEATTR,
726fcf3ce44SJohn Forte xmlStrlen((xmlChar *)NODENAMEATTR)) == 0) {
727fcf3ce44SJohn Forte member =
728fcf3ce44SJohn Forte xmlNodeGetContent(attr->children);
729fcf3ce44SJohn Forte }
730fcf3ce44SJohn Forte }
731fcf3ce44SJohn Forte if (container != NULL && member != NULL) {
732fcf3ce44SJohn Forte req->req_data.pair =
733fcf3ce44SJohn Forte NEW_REQPAIRARGV(req->req_data.pair, req->count);
734fcf3ce44SJohn Forte if (req->req_data.pair == (assoc_pair_t **)NULL) {
735fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
736fcf3ce44SJohn Forte return (ERR_MALLOC_FAILED);
737fcf3ce44SJohn Forte }
738fcf3ce44SJohn Forte req->req_data.pair[req->count] = (assoc_pair_t *)
739fcf3ce44SJohn Forte malloc(sizeof (assoc_pair_t));
740fcf3ce44SJohn Forte if (req->req_data.pair[req->count] == NULL) {
741fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
742fcf3ce44SJohn Forte return (ERR_MALLOC_FAILED);
743fcf3ce44SJohn Forte }
744fcf3ce44SJohn Forte req->req_data.pair[req->count]->container =
745fcf3ce44SJohn Forte container;
746fcf3ce44SJohn Forte req->req_data.pair[req->count]->member =
747fcf3ce44SJohn Forte member;
748fcf3ce44SJohn Forte req->req_data.data[++req->count] = NULL;
749fcf3ce44SJohn Forte } else {
750fcf3ce44SJohn Forte if (container != NULL) {
751fcf3ce44SJohn Forte xmlFree(container);
752fcf3ce44SJohn Forte }
753fcf3ce44SJohn Forte if (member != NULL) {
754fcf3ce44SJohn Forte xmlFree(member);
755fcf3ce44SJohn Forte }
756fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
757fcf3ce44SJohn Forte return (ERR_XML_OP_FAILED);
758fcf3ce44SJohn Forte }
759fcf3ce44SJohn Forte container = member = NULL;
760fcf3ce44SJohn Forte }
761fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
762fcf3ce44SJohn Forte break;
763fcf3ce44SJohn Forte case DiscoveryDomainSetMember:
764fcf3ce44SJohn Forte /* at least one object exists to get here. */
765fcf3ce44SJohn Forte r_nodes = xpath_obj->nodesetval;
766fcf3ce44SJohn Forte cnt = r_nodes->nodeNr;
767fcf3ce44SJohn Forte req->count = 0;
768fcf3ce44SJohn Forte req->req_data.pair =
769fcf3ce44SJohn Forte (assoc_pair_t **)malloc(sizeof (assoc_pair_t *));
770fcf3ce44SJohn Forte for (i = 0; i < cnt; i++) {
771fcf3ce44SJohn Forte attr = r_nodes->nodeTab[i]->properties;
772fcf3ce44SJohn Forte for (; attr != NULL; attr = attr->next) {
773fcf3ce44SJohn Forte if (xmlStrncmp(attr->name, (xmlChar *)DDSETNAMEATTR,
774fcf3ce44SJohn Forte xmlStrlen((xmlChar *)DDSETNAMEATTR)) == 0) {
775fcf3ce44SJohn Forte container =
776fcf3ce44SJohn Forte xmlNodeGetContent(attr->children);
777fcf3ce44SJohn Forte }
778fcf3ce44SJohn Forte if (xmlStrncmp(attr->name, (xmlChar *)DDNAMEATTR,
779fcf3ce44SJohn Forte xmlStrlen((xmlChar *)DDNAMEATTR)) == 0) {
780fcf3ce44SJohn Forte member =
781fcf3ce44SJohn Forte xmlNodeGetContent(attr->children);
782fcf3ce44SJohn Forte }
783fcf3ce44SJohn Forte }
784fcf3ce44SJohn Forte if (container != NULL && member != NULL) {
785fcf3ce44SJohn Forte req->req_data.pair =
786fcf3ce44SJohn Forte NEW_REQPAIRARGV(req->req_data.pair, req->count);
787fcf3ce44SJohn Forte if (req->req_data.pair == (assoc_pair_t **)NULL) {
788fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
789fcf3ce44SJohn Forte return (ERR_MALLOC_FAILED);
790fcf3ce44SJohn Forte }
791fcf3ce44SJohn Forte req->req_data.pair[req->count] = (assoc_pair_t *)
792fcf3ce44SJohn Forte malloc(sizeof (assoc_pair_t));
793fcf3ce44SJohn Forte if (req->req_data.pair[req->count] == NULL) {
794fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
795fcf3ce44SJohn Forte return (ERR_MALLOC_FAILED);
796fcf3ce44SJohn Forte }
797fcf3ce44SJohn Forte req->req_data.pair[req->count]->container =
798fcf3ce44SJohn Forte container;
799fcf3ce44SJohn Forte req->req_data.pair[req->count]->member =
800fcf3ce44SJohn Forte member;
801fcf3ce44SJohn Forte req->req_data.data[++req->count] = NULL;
802fcf3ce44SJohn Forte } else {
803fcf3ce44SJohn Forte if (container != NULL) {
804fcf3ce44SJohn Forte xmlFree(container);
805fcf3ce44SJohn Forte }
806fcf3ce44SJohn Forte if (member != NULL) {
807fcf3ce44SJohn Forte xmlFree(member);
808fcf3ce44SJohn Forte }
809fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
810fcf3ce44SJohn Forte return (ERR_XML_OP_FAILED);
811fcf3ce44SJohn Forte }
812fcf3ce44SJohn Forte container = member = NULL;
813fcf3ce44SJohn Forte }
814fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
815fcf3ce44SJohn Forte break;
816fcf3ce44SJohn Forte case DiscoveryDomain:
817fcf3ce44SJohn Forte case DiscoveryDomainSet:
818fcf3ce44SJohn Forte /* at least one object exists to get here. */
819fcf3ce44SJohn Forte r_nodes = xpath_obj->nodesetval;
820fcf3ce44SJohn Forte cnt = r_nodes->nodeNr;
821fcf3ce44SJohn Forte req->count = 0;
822fcf3ce44SJohn Forte req->req_data.attrlist =
823fcf3ce44SJohn Forte (object_attrlist_t **)malloc(sizeof (object_attrlist_t *));
824fcf3ce44SJohn Forte for (i = 0; i < cnt; i++) {
825fcf3ce44SJohn Forte req->req_data.attrlist =
826fcf3ce44SJohn Forte NEW_REQATTRLISTARGV(req->req_data.attrlist, req->count);
827fcf3ce44SJohn Forte if (req->req_data.attrlist ==
828fcf3ce44SJohn Forte (object_attrlist_t **)NULL) {
829fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
830fcf3ce44SJohn Forte return (ERR_MALLOC_FAILED);
831fcf3ce44SJohn Forte }
832fcf3ce44SJohn Forte req->req_data.attrlist[req->count] = (object_attrlist_t *)
833fcf3ce44SJohn Forte malloc(sizeof (object_attrlist_t));
834fcf3ce44SJohn Forte if (req->req_data.attrlist[req->count] == NULL) {
835fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
836fcf3ce44SJohn Forte return (ERR_MALLOC_FAILED);
837fcf3ce44SJohn Forte }
838fcf3ce44SJohn Forte req->req_data.attrlist[req->count]->name = NULL;
839fcf3ce44SJohn Forte req->req_data.attrlist[req->count]->id = NULL;
840fcf3ce44SJohn Forte req->req_data.attrlist[req->count]->enabled = NULL;
841fcf3ce44SJohn Forte attr = r_nodes->nodeTab[i]->properties;
842fcf3ce44SJohn Forte for (; attr != NULL; attr = attr->next) {
843fcf3ce44SJohn Forte if ((xmlStrncmp(attr->name, (xmlChar *)NAMEATTR,
844fcf3ce44SJohn Forte xmlStrlen((xmlChar *)NAMEATTR))) == 0) {
845fcf3ce44SJohn Forte req->req_data.attrlist[req->count]->name =
846fcf3ce44SJohn Forte xmlNodeGetContent(attr->children);
847fcf3ce44SJohn Forte }
848fcf3ce44SJohn Forte if ((xmlStrncmp(attr->name, (xmlChar *)IDATTR,
849fcf3ce44SJohn Forte xmlStrlen((xmlChar *)IDATTR))) == 0) {
850fcf3ce44SJohn Forte req->req_data.attrlist[req->count]->id =
851fcf3ce44SJohn Forte (uint32_t *)calloc(1, sizeof (uint32_t));
852fcf3ce44SJohn Forte if (req->req_data.attrlist[req->count]->id ==
853fcf3ce44SJohn Forte NULL) {
854fcf3ce44SJohn Forte if (xpath_obj)
855fcf3ce44SJohn Forte xmlXPathFreeObject(xpath_obj);
856fcf3ce44SJohn Forte return (ERR_MALLOC_FAILED);
857fcf3ce44SJohn Forte }
858fcf3ce44SJohn Forte xml_id = xmlNodeGetContent(attr->children);
859fcf3ce44SJohn Forte if (xml_id != NULL) {
860fcf3ce44SJohn Forte *(req->req_data.attrlist[req->count]->id) =
861fcf3ce44SJohn Forte atoi((const char *)xml_id);
862fcf3ce44SJohn Forte xmlFree(xml_id);
863fcf3ce44SJohn Forte }
864fcf3ce44SJohn Forte }
865fcf3ce44SJohn Forte }
866fcf3ce44SJohn Forte /*
867fcf3ce44SJohn Forte * check the enabled element.
868fcf3ce44SJohn Forte * Only one child element so check the children ptr.
869fcf3ce44SJohn Forte */
870fcf3ce44SJohn Forte if (r_nodes->nodeTab[i]->children) {
871fcf3ce44SJohn Forte req->req_data.attrlist[req->count]->enabled =
872fcf3ce44SJohn Forte (boolean_t *)malloc(sizeof (boolean_t));
873fcf3ce44SJohn Forte if (req->req_data.attrlist[req->count]->enabled
874fcf3ce44SJohn Forte == NULL) {
875fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
876fcf3ce44SJohn Forte return (ERR_MALLOC_FAILED);
877fcf3ce44SJohn Forte }
878fcf3ce44SJohn Forte /* value is children of enabled. */
879fcf3ce44SJohn Forte if (xmlStrncmp(
880fcf3ce44SJohn Forte r_nodes->nodeTab[i]->children->children->content,
881fcf3ce44SJohn Forte (xmlChar *)XMLTRUE, xmlStrlen((xmlChar *)XMLTRUE))
882fcf3ce44SJohn Forte == 0) {
883fcf3ce44SJohn Forte *(req->req_data.attrlist[req->count]->enabled)
884fcf3ce44SJohn Forte = B_TRUE;
885fcf3ce44SJohn Forte } else {
886fcf3ce44SJohn Forte *(req->req_data.attrlist[req->count]->enabled)
887fcf3ce44SJohn Forte = B_FALSE;
888fcf3ce44SJohn Forte }
889fcf3ce44SJohn Forte }
890fcf3ce44SJohn Forte req->req_data.attrlist[++req->count] = NULL;
891fcf3ce44SJohn Forte }
892fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
893fcf3ce44SJohn Forte break;
894fcf3ce44SJohn Forte default:
895fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
896fcf3ce44SJohn Forte return (ERR_XML_OP_FAILED);
897fcf3ce44SJohn Forte }
898fcf3ce44SJohn Forte
899fcf3ce44SJohn Forte return (0);
900fcf3ce44SJohn Forte }
901fcf3ce44SJohn Forte
902fcf3ce44SJohn Forte /*
903fcf3ce44SJohn Forte * build_mgmt_request -- extracts the request info from the given XML doc.
904fcf3ce44SJohn Forte *
905fcf3ce44SJohn Forte * x_doc: ptr to the request XML doc
906fcf3ce44SJohn Forte * req: ptr to the request struct to be filled up.
907fcf3ce44SJohn Forte *
908fcf3ce44SJohn Forte * Return value: ISNS_RSP_SUCCESSFUL if successful or an error code.
909fcf3ce44SJohn Forte */
910fcf3ce44SJohn Forte static int
process_mgmt_request(xmlDocPtr x_doc,request_t * req,ucred_t * uc)911fcf3ce44SJohn Forte process_mgmt_request(xmlDocPtr x_doc, request_t *req, ucred_t *uc)
912fcf3ce44SJohn Forte {
913fcf3ce44SJohn Forte result_code_t ret;
914fcf3ce44SJohn Forte int op;
915fcf3ce44SJohn Forte xmlXPathContextPtr ctext = NULL;
916fcf3ce44SJohn Forte uid_t user;
917fcf3ce44SJohn Forte struct passwd pwds, *pwd;
918fcf3ce44SJohn Forte char buf_pwd[1024];
919fcf3ce44SJohn Forte
920fcf3ce44SJohn Forte
921fcf3ce44SJohn Forte isnslog(LOG_DEBUG, "process_mgmt_request", "entered");
922fcf3ce44SJohn Forte (void) memset(req, 0, sizeof (request_t));
923fcf3ce44SJohn Forte /* get the operation first. */
924fcf3ce44SJohn Forte ctext = xmlXPathNewContext(x_doc);
925fcf3ce44SJohn Forte if (ctext == NULL) {
926fcf3ce44SJohn Forte return (ERR_XML_FAILED_TO_SET_XPATH_CONTEXT);
927fcf3ce44SJohn Forte }
928fcf3ce44SJohn Forte
929fcf3ce44SJohn Forte isnslog(LOG_DEBUG, "process_mgmt_request", "xpath context succeeded");
930fcf3ce44SJohn Forte op = get_op_id_from_doc(ctext);
931fcf3ce44SJohn Forte if (op == -1) {
932fcf3ce44SJohn Forte if (ctext) xmlXPathFreeContext(ctext);
933fcf3ce44SJohn Forte return (ERR_XML_VALID_OPERATION_NOT_FOUND);
934fcf3ce44SJohn Forte }
935fcf3ce44SJohn Forte
936fcf3ce44SJohn Forte user = ucred_getruid(uc);
937fcf3ce44SJohn Forte ret = getpwuid_r(user, &pwds, buf_pwd, sizeof (buf_pwd), &pwd);
938fcf3ce44SJohn Forte if (ret != 0) {
939fcf3ce44SJohn Forte if (ctext) xmlXPathFreeContext(ctext);
940fcf3ce44SJohn Forte return (ERR_DOOR_SERVER_DETECTED_INVALID_USER);
941fcf3ce44SJohn Forte }
942fcf3ce44SJohn Forte
943fcf3ce44SJohn Forte /* write operations are restricted. */
944fcf3ce44SJohn Forte if ((op == delete_op) || (op == createModify_op)) {
945fcf3ce44SJohn Forte if (!chkauthattr(ISNS_ADMIN_WRITE_AUTH, pwd->pw_name)) {
946fcf3ce44SJohn Forte if (ctext) xmlXPathFreeContext(ctext);
947fcf3ce44SJohn Forte return (ERR_DOOR_SERVER_DETECTED_NOT_AUTHORIZED_USER);
948fcf3ce44SJohn Forte }
949fcf3ce44SJohn Forte }
950fcf3ce44SJohn Forte
951fcf3ce44SJohn Forte req->op_info.op = op;
952fcf3ce44SJohn Forte
953fcf3ce44SJohn Forte if (ISNS_MGMT_OPERATION_TYPE_ENABLED()) {
954fcf3ce44SJohn Forte ISNS_MGMT_OPERATION_TYPE(op);
955fcf3ce44SJohn Forte }
956fcf3ce44SJohn Forte
957fcf3ce44SJohn Forte switch (op) {
958fcf3ce44SJohn Forte case (get_op):
959fcf3ce44SJohn Forte ret = process_get_request_from_doc(ctext, req);
960fcf3ce44SJohn Forte break;
961fcf3ce44SJohn Forte case (getAssociated_op):
962fcf3ce44SJohn Forte ret = process_getAssociated_request_from_doc(ctext, req);
963fcf3ce44SJohn Forte break;
964fcf3ce44SJohn Forte case (enumerate_op):
965fcf3ce44SJohn Forte ret = process_enumerate_request_from_doc(ctext, req);
966fcf3ce44SJohn Forte break;
967fcf3ce44SJohn Forte case (delete_op):
968fcf3ce44SJohn Forte ret = process_delete_request_from_doc(ctext, req);
969fcf3ce44SJohn Forte break;
970fcf3ce44SJohn Forte case (createModify_op):
971fcf3ce44SJohn Forte ret = process_createModify_request_from_doc(ctext, req);
972fcf3ce44SJohn Forte break;
973fcf3ce44SJohn Forte default:
974fcf3ce44SJohn Forte ret = ERR_XML_VALID_OPERATION_NOT_FOUND;
975fcf3ce44SJohn Forte }
976fcf3ce44SJohn Forte
977fcf3ce44SJohn Forte if (ctext) xmlXPathFreeContext(ctext);
978fcf3ce44SJohn Forte return (ret);
979fcf3ce44SJohn Forte }
980fcf3ce44SJohn Forte
981fcf3ce44SJohn Forte /*
982fcf3ce44SJohn Forte * build_mgmt_response -- sets an XML doc with a root and calls a porper
983fcf3ce44SJohn Forte * routine based on the request. If the called routine constructed
984fcf3ce44SJohn Forte * the response doc with the result element, this routine fills up
985fcf3ce44SJohn Forte * response buffer with raw XML doc.
986fcf3ce44SJohn Forte *
987fcf3ce44SJohn Forte * reponse: ptr to response buffer
988fcf3ce44SJohn Forte * req: request to be processed.
989fcf3ce44SJohn Forte * size: ptr to the response doc buffer
990fcf3ce44SJohn Forte */
991fcf3ce44SJohn Forte static int
build_mgmt_response(xmlChar ** response,request_t req,int * size)992fcf3ce44SJohn Forte build_mgmt_response(xmlChar **response, request_t req, int *size)
993fcf3ce44SJohn Forte {
994fcf3ce44SJohn Forte
995fcf3ce44SJohn Forte int ret;
996fcf3ce44SJohn Forte xmlDocPtr doc;
997fcf3ce44SJohn Forte xmlNodePtr root;
998fcf3ce44SJohn Forte xmlXPathContextPtr ctext = NULL;
999fcf3ce44SJohn Forte xmlChar expr[ISNS_MAX_LABEL_LEN + 13];
1000fcf3ce44SJohn Forte xmlXPathObjectPtr xpath_obj = NULL;
1001fcf3ce44SJohn Forte
1002fcf3ce44SJohn Forte isnslog(LOG_DEBUG, "build_mgmt_response", "entered");
1003fcf3ce44SJohn Forte
1004fcf3ce44SJohn Forte doc = xmlNewDoc((uchar_t *)"1.0");
1005fcf3ce44SJohn Forte root = xmlNewNode(NULL, (xmlChar *)ISNSRESPONSE);
1006fcf3ce44SJohn Forte (void) xmlDocSetRootElement(doc, root);
1007fcf3ce44SJohn Forte if (xmlSetProp(root, (xmlChar *)XMLNSATTR, (xmlChar *)XMLNSATTRVAL) ==
1008fcf3ce44SJohn Forte NULL) {
1009fcf3ce44SJohn Forte return (ERR_XML_SETPROP_FAILED);
1010fcf3ce44SJohn Forte }
1011fcf3ce44SJohn Forte
1012fcf3ce44SJohn Forte switch (req.op_info.op) {
1013fcf3ce44SJohn Forte case get_op:
1014fcf3ce44SJohn Forte switch (req.op_info.obj) {
1015fcf3ce44SJohn Forte case Node:
1016fcf3ce44SJohn Forte ret = get_node_op(&req, doc);
1017fcf3ce44SJohn Forte break;
1018fcf3ce44SJohn Forte case DiscoveryDomain:
1019fcf3ce44SJohn Forte ret = get_dd_op(&req, doc);
1020fcf3ce44SJohn Forte break;
1021fcf3ce44SJohn Forte case DiscoveryDomainSet:
1022fcf3ce44SJohn Forte ret = get_ddset_op(&req, doc);
1023fcf3ce44SJohn Forte break;
1024fcf3ce44SJohn Forte case ServerConfig:
1025fcf3ce44SJohn Forte ret = get_serverconfig_op(doc);
1026fcf3ce44SJohn Forte break;
1027fcf3ce44SJohn Forte default:
1028fcf3ce44SJohn Forte ret = ERR_INVALID_MGMT_REQUEST;
1029fcf3ce44SJohn Forte }
1030fcf3ce44SJohn Forte break;
1031fcf3ce44SJohn Forte case enumerate_op:
1032fcf3ce44SJohn Forte isnslog(LOG_DEBUG, "build_mgmt_response", "enumerate_op");
1033fcf3ce44SJohn Forte switch (req.op_info.obj) {
1034fcf3ce44SJohn Forte case Node:
1035fcf3ce44SJohn Forte ret = enumerate_node_op(doc);
1036fcf3ce44SJohn Forte break;
1037fcf3ce44SJohn Forte case DiscoveryDomain:
1038fcf3ce44SJohn Forte ret = enumerate_dd_op(doc);
1039fcf3ce44SJohn Forte break;
1040fcf3ce44SJohn Forte case DiscoveryDomainSet:
1041fcf3ce44SJohn Forte ret = enumerate_ddset_op(doc);
1042fcf3ce44SJohn Forte break;
1043fcf3ce44SJohn Forte default:
1044fcf3ce44SJohn Forte ret = ERR_INVALID_MGMT_REQUEST;
1045fcf3ce44SJohn Forte }
1046fcf3ce44SJohn Forte break;
1047fcf3ce44SJohn Forte case getAssociated_op:
1048fcf3ce44SJohn Forte switch (req.op_info.obj) {
1049fcf3ce44SJohn Forte case DiscoveryDomainMember:
1050fcf3ce44SJohn Forte if (req.assoc_req == container_to_member) {
1051fcf3ce44SJohn Forte ret = getAssociated_dd_to_node_op(&req, doc);
1052fcf3ce44SJohn Forte } else {
1053fcf3ce44SJohn Forte ret = getAssociated_node_to_dd_op(&req, doc);
1054fcf3ce44SJohn Forte }
1055fcf3ce44SJohn Forte break;
1056fcf3ce44SJohn Forte case DiscoveryDomainSetMember:
1057fcf3ce44SJohn Forte if (req.assoc_req == container_to_member) {
1058fcf3ce44SJohn Forte ret = getAssociated_ddset_to_dd_op(&req, doc);
1059fcf3ce44SJohn Forte } else {
1060fcf3ce44SJohn Forte ret = getAssociated_dd_to_ddset_op(&req, doc);
1061fcf3ce44SJohn Forte }
1062fcf3ce44SJohn Forte break;
1063fcf3ce44SJohn Forte default:
1064fcf3ce44SJohn Forte ret = ERR_INVALID_MGMT_REQUEST;
1065fcf3ce44SJohn Forte }
1066fcf3ce44SJohn Forte break;
1067fcf3ce44SJohn Forte case createModify_op:
1068fcf3ce44SJohn Forte switch (req.op_info.obj) {
1069fcf3ce44SJohn Forte case DiscoveryDomain:
1070fcf3ce44SJohn Forte case DiscoveryDomainSet:
1071fcf3ce44SJohn Forte ret = createModify_dd_ddset_op(&req, doc);
1072fcf3ce44SJohn Forte break;
1073fcf3ce44SJohn Forte case DiscoveryDomainMember:
1074fcf3ce44SJohn Forte case DiscoveryDomainSetMember:
1075fcf3ce44SJohn Forte ret = create_ddmember_ddsetmember_op(&req, doc,
1076fcf3ce44SJohn Forte req.op_info.obj);
1077fcf3ce44SJohn Forte break;
1078fcf3ce44SJohn Forte default:
1079fcf3ce44SJohn Forte ret = ERR_INVALID_MGMT_REQUEST;
1080fcf3ce44SJohn Forte }
1081fcf3ce44SJohn Forte break;
1082fcf3ce44SJohn Forte case delete_op:
1083fcf3ce44SJohn Forte switch (req.op_info.obj) {
1084fcf3ce44SJohn Forte case DiscoveryDomainMember:
1085fcf3ce44SJohn Forte case DiscoveryDomainSetMember:
1086fcf3ce44SJohn Forte ret = delete_ddmember_ddsetmember_op(&req, doc,
1087fcf3ce44SJohn Forte req.op_info.obj);
1088fcf3ce44SJohn Forte break;
1089fcf3ce44SJohn Forte case DiscoveryDomain:
1090fcf3ce44SJohn Forte case DiscoveryDomainSet:
1091fcf3ce44SJohn Forte ret = delete_dd_ddset_op(&req, doc, req.op_info.obj);
1092fcf3ce44SJohn Forte break;
1093fcf3ce44SJohn Forte default:
1094fcf3ce44SJohn Forte ret = ERR_INVALID_MGMT_REQUEST;
1095fcf3ce44SJohn Forte }
1096fcf3ce44SJohn Forte break;
1097fcf3ce44SJohn Forte default:
1098fcf3ce44SJohn Forte ret = ERR_INVALID_MGMT_REQUEST;
1099fcf3ce44SJohn Forte }
1100fcf3ce44SJohn Forte
1101fcf3ce44SJohn Forte /*
1102fcf3ce44SJohn Forte * if failed check to see the doc contains the result element.
1103fcf3ce44SJohn Forte * if not, the response is set with only an error code.
1104fcf3ce44SJohn Forte */
1105fcf3ce44SJohn Forte if (ret != ISNS_RSP_SUCCESSFUL) {
1106fcf3ce44SJohn Forte ctext = xmlXPathNewContext(doc);
1107fcf3ce44SJohn Forte if (ctext != NULL) {
1108fcf3ce44SJohn Forte (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13,
11090687de4fSAlexander Pyhalov XMLSTRING_CAST "%s\"%s\"]", "//*[name()=", RESULT);
1110fcf3ce44SJohn Forte xpath_obj = xmlXPathEvalExpression(expr, ctext);
1111fcf3ce44SJohn Forte if ((xpath_obj == NULL) || (xpath_obj->nodesetval == NULL) ||
1112fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeNr <= 0) ||
1113fcf3ce44SJohn Forte (xpath_obj->nodesetval->nodeTab == NULL)) {
1114fcf3ce44SJohn Forte isnslog(LOG_DEBUG,
1115fcf3ce44SJohn Forte "build_mgmt_response",
1116fcf3ce44SJohn Forte "returning repsonse only with error code %d\n", ret);
1117fcf3ce44SJohn Forte *response = malloc(sizeof (ret));
1118fcf3ce44SJohn Forte if (*response) **response = ret;
1119fcf3ce44SJohn Forte *size = sizeof (ret);
1120fcf3ce44SJohn Forte } else {
1121fcf3ce44SJohn Forte xmlDocDumpMemory(doc, response, size);
1122fcf3ce44SJohn Forte }
1123fcf3ce44SJohn Forte } else {
1124fcf3ce44SJohn Forte /* can't verify the xml doc. dump return the doc anyway. */
1125fcf3ce44SJohn Forte xmlDocDumpMemory(doc, response, size);
1126fcf3ce44SJohn Forte }
1127fcf3ce44SJohn Forte } else {
1128fcf3ce44SJohn Forte xmlDocDumpMemory(doc, response, size);
1129fcf3ce44SJohn Forte }
1130fcf3ce44SJohn Forte
1131fcf3ce44SJohn Forte if (xpath_obj) xmlXPathFreeObject(xpath_obj);
1132fcf3ce44SJohn Forte if (ctext) xmlXPathFreeContext(ctext);
1133fcf3ce44SJohn Forte if (doc) xmlFreeDoc(doc);
1134fcf3ce44SJohn Forte return (ret);
1135fcf3ce44SJohn Forte }
1136fcf3ce44SJohn Forte
1137fcf3ce44SJohn Forte /*
1138fcf3ce44SJohn Forte * build_result_message -- construct a response doc with the given result.
1139fcf3ce44SJohn Forte * Result contains status code and message.
1140fcf3ce44SJohn Forte *
1141fcf3ce44SJohn Forte * reponse: ptr to response doc
1142fcf3ce44SJohn Forte * code: result code
1143fcf3ce44SJohn Forte * size: ptr to the response doc size
1144fcf3ce44SJohn Forte */
1145fcf3ce44SJohn Forte static int
build_result_message(xmlChar ** response,result_code_t code,int * size)1146fcf3ce44SJohn Forte build_result_message(xmlChar **response, result_code_t code, int *size)
1147fcf3ce44SJohn Forte {
1148fcf3ce44SJohn Forte int ret = ISNS_RSP_SUCCESSFUL;
1149fcf3ce44SJohn Forte xmlDocPtr doc;
1150fcf3ce44SJohn Forte xmlNodePtr root, n_obj;
1151fcf3ce44SJohn Forte char numbuf[32];
1152fcf3ce44SJohn Forte
1153fcf3ce44SJohn Forte isnslog(LOG_DEBUG, "build_result_response", "entered");
1154fcf3ce44SJohn Forte
1155fcf3ce44SJohn Forte doc = xmlNewDoc((uchar_t *)"1.0");
1156fcf3ce44SJohn Forte root = xmlNewNode(NULL, (xmlChar *)ISNSRESPONSE);
1157fcf3ce44SJohn Forte (void) xmlDocSetRootElement(doc, root);
1158fcf3ce44SJohn Forte
1159fcf3ce44SJohn Forte n_obj = xmlNewChild(root, NULL, (xmlChar *)RESULT, NULL);
1160fcf3ce44SJohn Forte
1161fcf3ce44SJohn Forte if (code == ISNS_RSP_SUCCESSFUL) {
1162fcf3ce44SJohn Forte (void) sprintf(numbuf, "%d", ISNS_RSP_SUCCESSFUL);
1163fcf3ce44SJohn Forte if (xmlNewChild(n_obj, NULL, (xmlChar *)STATUSELEMENT,
1164fcf3ce44SJohn Forte (xmlChar *)numbuf) == NULL) {
1165fcf3ce44SJohn Forte ret = ERR_XML_NEWCHILD_FAILED;
1166fcf3ce44SJohn Forte }
1167fcf3ce44SJohn Forte } else {
1168fcf3ce44SJohn Forte (void) sprintf(numbuf, "%d", code);
1169fcf3ce44SJohn Forte if (xmlNewChild(n_obj, NULL, (xmlChar *)STATUSELEMENT,
1170fcf3ce44SJohn Forte (xmlChar *)numbuf) == NULL) {
1171fcf3ce44SJohn Forte ret = ERR_XML_NEWCHILD_FAILED;
1172fcf3ce44SJohn Forte }
1173fcf3ce44SJohn Forte if (xmlNewChild(n_obj, NULL, (xmlChar *)MESSAGEELEMENT,
1174fcf3ce44SJohn Forte (xmlChar *)result_code_to_str(code)) == NULL) {
1175fcf3ce44SJohn Forte ret = ERR_XML_NEWCHILD_FAILED;
1176fcf3ce44SJohn Forte }
1177fcf3ce44SJohn Forte }
1178fcf3ce44SJohn Forte
1179fcf3ce44SJohn Forte xmlDocDumpMemory(doc, response, size);
1180fcf3ce44SJohn Forte
1181fcf3ce44SJohn Forte if (doc) xmlFreeDoc(doc);
1182fcf3ce44SJohn Forte return (ret);
1183fcf3ce44SJohn Forte }
1184fcf3ce44SJohn Forte
1185fcf3ce44SJohn Forte /*
1186fcf3ce44SJohn Forte * cleanup_request -- deallocatate memory associated with the given request
1187fcf3ce44SJohn Forte * structure.
1188fcf3ce44SJohn Forte */
1189fcf3ce44SJohn Forte static void
cleanup_request(request_t req)1190fcf3ce44SJohn Forte cleanup_request(request_t req)
1191fcf3ce44SJohn Forte {
1192fcf3ce44SJohn Forte int i;
1193fcf3ce44SJohn Forte
1194fcf3ce44SJohn Forte isnslog(LOG_DEBUG, "cleanup_request", "entered");
1195fcf3ce44SJohn Forte switch (req.op_info.op) {
1196fcf3ce44SJohn Forte case (get_op):
1197fcf3ce44SJohn Forte for (i = 0; i < req.count; i++) {
1198fcf3ce44SJohn Forte if (req.req_data.data[i])
1199fcf3ce44SJohn Forte xmlFree(req.req_data.data[i]);
1200fcf3ce44SJohn Forte }
1201fcf3ce44SJohn Forte if (req.req_data.data) free(req.req_data.data);
1202fcf3ce44SJohn Forte break;
1203fcf3ce44SJohn Forte case (getAssociated_op):
1204fcf3ce44SJohn Forte for (i = 0; i < req.count; i++) {
1205fcf3ce44SJohn Forte if (req.req_data.data[i])
1206fcf3ce44SJohn Forte xmlFree(req.req_data.data[i]);
1207fcf3ce44SJohn Forte }
1208fcf3ce44SJohn Forte if (req.req_data.data) free(req.req_data.data);
1209fcf3ce44SJohn Forte break;
1210fcf3ce44SJohn Forte case (enumerate_op):
1211fcf3ce44SJohn Forte break;
1212fcf3ce44SJohn Forte case (delete_op):
1213fcf3ce44SJohn Forte if ((req.op_info.obj == DiscoveryDomainMember) ||
1214fcf3ce44SJohn Forte (req.op_info.obj == DiscoveryDomainSetMember)) {
1215fcf3ce44SJohn Forte for (i = 0; i < req.count; i++) {
1216fcf3ce44SJohn Forte if (req.req_data.pair[i]->container)
1217fcf3ce44SJohn Forte xmlFree(req.req_data.pair[i]->container);
1218fcf3ce44SJohn Forte if (req.req_data.pair[i]->member)
1219fcf3ce44SJohn Forte xmlFree(req.req_data.pair[i]->member);
1220fcf3ce44SJohn Forte if (req.req_data.pair[i])
1221fcf3ce44SJohn Forte free(req.req_data.pair[i]);
1222fcf3ce44SJohn Forte }
1223fcf3ce44SJohn Forte if (req.req_data.pair) free(req.req_data.pair);
1224fcf3ce44SJohn Forte } else {
1225fcf3ce44SJohn Forte for (i = 0; i < req.count; i++) {
1226fcf3ce44SJohn Forte if (req.req_data.data[i])
1227fcf3ce44SJohn Forte xmlFree(req.req_data.data[i]);
1228fcf3ce44SJohn Forte }
1229fcf3ce44SJohn Forte if (req.req_data.data) free(req.req_data.data);
1230fcf3ce44SJohn Forte }
1231fcf3ce44SJohn Forte break;
1232fcf3ce44SJohn Forte case (createModify_op):
1233fcf3ce44SJohn Forte if ((req.op_info.obj == DiscoveryDomainMember) ||
1234fcf3ce44SJohn Forte (req.op_info.obj == DiscoveryDomainSetMember)) {
1235fcf3ce44SJohn Forte for (i = 0; i < req.count; i++) {
1236fcf3ce44SJohn Forte if (req.req_data.pair[i]->container)
1237fcf3ce44SJohn Forte xmlFree(req.req_data.pair[i]->container);
1238fcf3ce44SJohn Forte if (req.req_data.pair[i]->member)
1239fcf3ce44SJohn Forte xmlFree(req.req_data.pair[i]->member);
1240fcf3ce44SJohn Forte if (req.req_data.pair[i])
1241fcf3ce44SJohn Forte free(req.req_data.pair[i]);
1242fcf3ce44SJohn Forte }
1243fcf3ce44SJohn Forte if (req.req_data.pair) free(req.req_data.pair);
1244fcf3ce44SJohn Forte } else if ((req.op_info.obj == DiscoveryDomain) ||
1245fcf3ce44SJohn Forte (req.op_info.obj == DiscoveryDomainSet)) {
1246fcf3ce44SJohn Forte for (i = 0; i < req.count; i++) {
1247fcf3ce44SJohn Forte if (req.req_data.attrlist[i]->name)
1248fcf3ce44SJohn Forte xmlFree(req.req_data.attrlist[i]->name);
1249fcf3ce44SJohn Forte if (req.req_data.attrlist[i]->id)
1250fcf3ce44SJohn Forte free(req.req_data.attrlist[i]->id);
1251fcf3ce44SJohn Forte if (req.req_data.attrlist[i]->enabled)
1252fcf3ce44SJohn Forte free(req.req_data.attrlist[i]->enabled);
1253fcf3ce44SJohn Forte if (req.req_data.pair[i])
1254fcf3ce44SJohn Forte free(req.req_data.pair[i]);
1255fcf3ce44SJohn Forte }
1256fcf3ce44SJohn Forte if (req.req_data.attrlist) free(req.req_data.attrlist);
1257fcf3ce44SJohn Forte }
1258fcf3ce44SJohn Forte break;
1259fcf3ce44SJohn Forte }
1260fcf3ce44SJohn Forte }
1261fcf3ce44SJohn Forte
1262fcf3ce44SJohn Forte /*
1263fcf3ce44SJohn Forte * Find a matching entry for the given thread id.
1264fcf3ce44SJohn Forte */
match_entry(pthread_t tid)1265fcf3ce44SJohn Forte static thr_elem_t *match_entry(pthread_t tid)
1266fcf3ce44SJohn Forte {
1267fcf3ce44SJohn Forte
1268fcf3ce44SJohn Forte thr_elem_t *thr = thr_list;
1269fcf3ce44SJohn Forte
1270fcf3ce44SJohn Forte while (thr) {
1271fcf3ce44SJohn Forte if (pthread_equal(thr->thr_id, tid)) {
1272fcf3ce44SJohn Forte return (thr);
1273fcf3ce44SJohn Forte }
1274fcf3ce44SJohn Forte thr = thr->next;
1275fcf3ce44SJohn Forte }
1276fcf3ce44SJohn Forte
1277fcf3ce44SJohn Forte return (NULL);
1278fcf3ce44SJohn Forte }
1279fcf3ce44SJohn Forte
1280fcf3ce44SJohn Forte /*
1281fcf3ce44SJohn Forte * Add an entry to the thr_list for the given thread id.
1282fcf3ce44SJohn Forte */
1283fcf3ce44SJohn Forte static int
add_entry(pthread_t tid,xmlChar * doc)1284fcf3ce44SJohn Forte add_entry(pthread_t tid, xmlChar *doc)
1285fcf3ce44SJohn Forte {
1286fcf3ce44SJohn Forte
1287fcf3ce44SJohn Forte thr_elem_t *new_e;
1288fcf3ce44SJohn Forte thr_elem_t *thr = thr_list;
1289fcf3ce44SJohn Forte
1290fcf3ce44SJohn Forte if ((new_e = malloc(sizeof (thr_elem_t))) == NULL) {
1291fcf3ce44SJohn Forte return (ERR_MALLOC_FAILED);
1292fcf3ce44SJohn Forte }
1293fcf3ce44SJohn Forte new_e->thr_id = tid;
1294fcf3ce44SJohn Forte new_e->doc = doc;
1295fcf3ce44SJohn Forte new_e->next = NULL;
1296fcf3ce44SJohn Forte
1297fcf3ce44SJohn Forte if (thr_list == NULL) {
1298fcf3ce44SJohn Forte thr_list = new_e;
1299fcf3ce44SJohn Forte } else {
1300fcf3ce44SJohn Forte while (thr->next) {
1301fcf3ce44SJohn Forte thr = thr->next;
1302fcf3ce44SJohn Forte }
1303fcf3ce44SJohn Forte thr->next = new_e;
1304fcf3ce44SJohn Forte }
1305fcf3ce44SJohn Forte
1306fcf3ce44SJohn Forte return (ISNS_RSP_SUCCESSFUL);
1307fcf3ce44SJohn Forte }
1308fcf3ce44SJohn Forte
1309fcf3ce44SJohn Forte /*
1310fcf3ce44SJohn Forte * door_server -- proecess the management request and send response back
1311fcf3ce44SJohn Forte * the client.
1312fcf3ce44SJohn Forte *
1313fcf3ce44SJohn Forte * In order to handle allocation after door_return,
1314fcf3ce44SJohn Forte * a global list, thr_list, is maintained to free the response buffer
1315fcf3ce44SJohn Forte * from the previous invocation of the server function on the same thread.
1316fcf3ce44SJohn Forte * Note: the door framework creates a thread and the same thread is used
1317fcf3ce44SJohn Forte * while a new thread is created for concurrent door_calls.
1318fcf3ce44SJohn Forte *
1319fcf3ce44SJohn Forte * If a thread is used once the buffer will be left allocated.
1320fcf3ce44SJohn Forte */
1321fcf3ce44SJohn Forte /*ARGSUSED*/
1322fcf3ce44SJohn Forte static void
door_server(void * cookie,char * argp,size_t arg_size,door_desc_t * dp,uint_t n_desc)1323fcf3ce44SJohn Forte door_server(void *cookie, char *argp, size_t arg_size, door_desc_t *dp,
1324fcf3ce44SJohn Forte uint_t n_desc)
1325fcf3ce44SJohn Forte {
1326fcf3ce44SJohn Forte request_t req;
1327fcf3ce44SJohn Forte xmlDocPtr x_doc;
1328fcf3ce44SJohn Forte xmlChar *resp_buf = NULL;
1329fcf3ce44SJohn Forte int ret, size = 0;
1330fcf3ce44SJohn Forte pthread_t tid;
1331fcf3ce44SJohn Forte thr_elem_t *thr;
1332fcf3ce44SJohn Forte ucred_t *uc = NULL;
1333fcf3ce44SJohn Forte
1334fcf3ce44SJohn Forte if (ISNS_MGMT_REQUEST_RECEIVED_ENABLED()) {
1335fcf3ce44SJohn Forte ISNS_MGMT_REQUEST_RECEIVED();
1336fcf3ce44SJohn Forte }
1337fcf3ce44SJohn Forte
1338fcf3ce44SJohn Forte if (door_ucred(&uc) != 0) {
1339fcf3ce44SJohn Forte isnslog(LOG_DEBUG, "door_server",
1340fcf3ce44SJohn Forte "door_ucred failed. errno: %d\n", errno);
1341fcf3ce44SJohn Forte ret = build_result_message(&resp_buf,
1342fcf3ce44SJohn Forte ERR_DOOR_UCRED_FAILED, &size);
1343fcf3ce44SJohn Forte if (ret == ISNS_RSP_SUCCESSFUL) {
1344fcf3ce44SJohn Forte (void) door_return((char *)resp_buf, size + 1, NULL, 0);
1345fcf3ce44SJohn Forte /* Not reached */
1346fcf3ce44SJohn Forte } else {
1347fcf3ce44SJohn Forte ret = ERR_DOOR_UCRED_FAILED;
1348fcf3ce44SJohn Forte (void) door_return((void *)&ret, sizeof (ret), NULL, 0);
1349fcf3ce44SJohn Forte /* Not reached */
1350fcf3ce44SJohn Forte }
1351fcf3ce44SJohn Forte }
1352fcf3ce44SJohn Forte
1353fcf3ce44SJohn Forte isnslog(LOG_DEBUG, "door_server", "entered with request:\n %s\n", argp);
1354fcf3ce44SJohn Forte if ((x_doc = xmlParseMemory(argp, arg_size)) != NULL) {
1355fcf3ce44SJohn Forte isnslog(LOG_DEBUG, "door_server", "ParseMemory succeeded");
1356fcf3ce44SJohn Forte if ((ret = process_mgmt_request(x_doc, &req, uc)) == 0) {
1357fcf3ce44SJohn Forte ret = build_mgmt_response(&resp_buf, req, &size);
1358fcf3ce44SJohn Forte } else {
1359fcf3ce44SJohn Forte ret = build_result_message(&resp_buf, ret, &size);
1360fcf3ce44SJohn Forte }
1361fcf3ce44SJohn Forte xmlFreeDoc(x_doc);
1362fcf3ce44SJohn Forte cleanup_request(req);
1363fcf3ce44SJohn Forte } else {
1364fcf3ce44SJohn Forte ret = build_result_message(&resp_buf,
1365fcf3ce44SJohn Forte ERR_XML_PARSE_MEMORY_FAILED, &size);
1366fcf3ce44SJohn Forte }
1367fcf3ce44SJohn Forte
1368fcf3ce44SJohn Forte /* free the ucred */
1369fcf3ce44SJohn Forte ucred_free(uc);
1370fcf3ce44SJohn Forte
1371fcf3ce44SJohn Forte if (resp_buf) {
1372fcf3ce44SJohn Forte tid = pthread_self();
1373fcf3ce44SJohn Forte if ((thr = match_entry(tid)) == NULL) {
1374fcf3ce44SJohn Forte (void) add_entry(tid, resp_buf);
1375fcf3ce44SJohn Forte } else {
1376fcf3ce44SJohn Forte isnslog(LOG_DEBUG, "door_server",
1377fcf3ce44SJohn Forte "free the previouly returned buffer %x on this thread\n",
1378fcf3ce44SJohn Forte thr->doc);
1379fcf3ce44SJohn Forte xmlFree(thr->doc);
1380fcf3ce44SJohn Forte isnslog(LOG_DEBUG, "door_server",
1381fcf3ce44SJohn Forte "store the currently allocated buffer %x on this thread\n",
1382fcf3ce44SJohn Forte resp_buf);
1383fcf3ce44SJohn Forte thr->doc = resp_buf;
1384fcf3ce44SJohn Forte }
1385fcf3ce44SJohn Forte isnslog(LOG_DEBUG,
1386fcf3ce44SJohn Forte "door_server", "exiting with response:\n %s\n",
1387fcf3ce44SJohn Forte (const char *)resp_buf);
1388fcf3ce44SJohn Forte
1389fcf3ce44SJohn Forte if (ISNS_MGMT_REQUEST_RESPONDED_ENABLED()) {
1390fcf3ce44SJohn Forte ISNS_MGMT_REQUEST_RESPONDED();
1391fcf3ce44SJohn Forte }
1392fcf3ce44SJohn Forte
1393fcf3ce44SJohn Forte (void) door_return((char *)resp_buf, size + 1, NULL, 0);
1394fcf3ce44SJohn Forte /* Not reached */
1395fcf3ce44SJohn Forte }
1396fcf3ce44SJohn Forte
1397fcf3ce44SJohn Forte isnslog(LOG_DEBUG,
1398fcf3ce44SJohn Forte "door_server", "exiting only with error code %d\n", ret);
1399fcf3ce44SJohn Forte
1400fcf3ce44SJohn Forte if (ISNS_MGMT_REQUEST_RESPONDED_ENABLED()) {
1401fcf3ce44SJohn Forte ISNS_MGMT_REQUEST_RESPONDED();
1402fcf3ce44SJohn Forte }
1403fcf3ce44SJohn Forte
1404fcf3ce44SJohn Forte (void) door_return((void *)&ret, sizeof (ret), NULL, 0);
1405fcf3ce44SJohn Forte
1406fcf3ce44SJohn Forte }
1407fcf3ce44SJohn Forte
1408fcf3ce44SJohn Forte /*
1409fcf3ce44SJohn Forte * setup_mgmt_door -- Create a door portal for management application requests
1410fcf3ce44SJohn Forte *
1411fcf3ce44SJohn Forte * First check to see if another daemon is already running by attempting
1412fcf3ce44SJohn Forte * to send an empty request to the door. If successful it means this
1413fcf3ce44SJohn Forte * daemon should exit.
1414fcf3ce44SJohn Forte */
1415fcf3ce44SJohn Forte int
setup_mgmt_door(msg_queue_t * sys_q)1416fcf3ce44SJohn Forte setup_mgmt_door(msg_queue_t *sys_q)
1417fcf3ce44SJohn Forte {
1418fcf3ce44SJohn Forte int fd, door_id;
1419fcf3ce44SJohn Forte struct stat buf;
1420fcf3ce44SJohn Forte door_arg_t darg;
1421fcf3ce44SJohn Forte
1422fcf3ce44SJohn Forte isnslog(LOG_DEBUG, "setup_mgmt_door", "entered");
1423fcf3ce44SJohn Forte /* check if a door is already running. */
1424fcf3ce44SJohn Forte if ((fd = open(ISNS_DOOR_NAME, 0)) >= 0) {
1425fcf3ce44SJohn Forte darg.data_ptr = "<?xml version='1.0' encoding='UTF-8'?>"
1426fcf3ce44SJohn Forte "<isnsRequest><get><isnsObject>"
1427fcf3ce44SJohn Forte "<DiscoveryDomain name=\"default\">"
1428fcf3ce44SJohn Forte "</DiscoveryDomain></isnsObject></get>"
1429fcf3ce44SJohn Forte "</isnsRequest>";
1430fcf3ce44SJohn Forte darg.data_size = xmlStrlen((xmlChar *)darg.data_ptr) + 1;
1431fcf3ce44SJohn Forte darg.desc_ptr = NULL;
1432fcf3ce44SJohn Forte darg.desc_num = 0;
1433fcf3ce44SJohn Forte darg.rbuf = NULL;
1434fcf3ce44SJohn Forte darg.rsize = 0;
1435fcf3ce44SJohn Forte
1436fcf3ce44SJohn Forte if (door_call(fd, &darg) == 0) {
1437fcf3ce44SJohn Forte /* door already running. */
1438fcf3ce44SJohn Forte (void) close(fd);
1439fcf3ce44SJohn Forte isnslog(LOG_DEBUG, "setup_mgmt_door",
1440fcf3ce44SJohn Forte "management door is already runninng.");
1441fcf3ce44SJohn Forte if (darg.rsize > darg.data_size) {
1442fcf3ce44SJohn Forte (void) munmap(darg.rbuf, darg.rsize);
1443fcf3ce44SJohn Forte }
14443f1da666Swl door_created = B_FALSE;
1445fcf3ce44SJohn Forte return (0);
1446fcf3ce44SJohn Forte }
1447fcf3ce44SJohn Forte (void) close(fd);
1448fcf3ce44SJohn Forte }
1449fcf3ce44SJohn Forte
1450fcf3ce44SJohn Forte if ((door_id = door_create(door_server, (void *)sys_q, 0)) < 0) {
1451fcf3ce44SJohn Forte isnslog(LOG_DEBUG, "setup_mgmt_door",
1452fcf3ce44SJohn Forte "Failed to create managment door");
1453fcf3ce44SJohn Forte exit(1);
1454fcf3ce44SJohn Forte }
1455fcf3ce44SJohn Forte
1456fcf3ce44SJohn Forte if (stat(ISNS_DOOR_NAME, &buf) < 0) {
1457fcf3ce44SJohn Forte if ((fd = creat(ISNS_DOOR_NAME, 0666)) < 0) {
1458fcf3ce44SJohn Forte isnslog(LOG_DEBUG, "setup_mgmt_door",
1459fcf3ce44SJohn Forte "open failed on %s errno = %d", ISNS_DOOR_NAME, errno);
1460fcf3ce44SJohn Forte exit(1);
1461fcf3ce44SJohn Forte }
1462fcf3ce44SJohn Forte (void) close(fd);
1463fcf3ce44SJohn Forte }
1464fcf3ce44SJohn Forte
1465fcf3ce44SJohn Forte /* make sure the file permission set to general access. */
1466fcf3ce44SJohn Forte (void) chmod(ISNS_DOOR_NAME, 0666);
1467fcf3ce44SJohn Forte (void) fdetach(ISNS_DOOR_NAME);
1468fcf3ce44SJohn Forte
1469fcf3ce44SJohn Forte if (fattach(door_id, ISNS_DOOR_NAME) < 0) {
1470fcf3ce44SJohn Forte syslog(LOG_DEBUG, "setup_mgmt_door",
1471fcf3ce44SJohn Forte "fattach failed on %s errno=%d",
1472fcf3ce44SJohn Forte ISNS_DOOR_NAME, errno);
1473fcf3ce44SJohn Forte return (-1);
1474fcf3ce44SJohn Forte }
1475fcf3ce44SJohn Forte
14763f1da666Swl door_created = B_TRUE;
14773f1da666Swl
1478fcf3ce44SJohn Forte return (0);
1479fcf3ce44SJohn Forte }
1480