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