xref: /titanic_52/usr/src/cmd/isns/isnsadm/isnsadm.c (revision 2ce653330eaceaac2db2130e6a6f2e0e4f26519f)
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 /*
22fcf3ce44SJohn Forte  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23fcf3ce44SJohn Forte  * Use is subject to license terms.
24fcf3ce44SJohn Forte  */
25fcf3ce44SJohn Forte 
26fcf3ce44SJohn Forte /*
27fcf3ce44SJohn Forte  * isnsadm.c : isnsadm CL
28fcf3ce44SJohn Forte  *
29fcf3ce44SJohn Forte  */
30fcf3ce44SJohn Forte 
31fcf3ce44SJohn Forte #include <sys/types.h>
32fcf3ce44SJohn Forte #include <sys/stat.h>
33fcf3ce44SJohn Forte #include <unistd.h>
34fcf3ce44SJohn Forte #include <stdlib.h>
35fcf3ce44SJohn Forte #include <devid.h>
36fcf3ce44SJohn Forte #include <fcntl.h>
37fcf3ce44SJohn Forte #include <door.h>
38fcf3ce44SJohn Forte #include <errno.h>
39fcf3ce44SJohn Forte #include <strings.h>
40fcf3ce44SJohn Forte #include <libscf.h>
41fcf3ce44SJohn Forte #include <libxml/xmlreader.h>
42fcf3ce44SJohn Forte #include <libxml/xmlwriter.h>
43fcf3ce44SJohn Forte #include <libxml/parser.h>
44fcf3ce44SJohn Forte #include <libxml/xpath.h>
45fcf3ce44SJohn Forte #include <libxml/tree.h>
46fcf3ce44SJohn Forte #include <wchar.h>
47fcf3ce44SJohn Forte #include <locale.h>
48fcf3ce44SJohn Forte #include "isns_mgmt.h"
49fcf3ce44SJohn Forte #include "isns_utils.h"
50fcf3ce44SJohn Forte #include "isns_protocol.h"
51fcf3ce44SJohn Forte #include "cmdparse.h"
52fcf3ce44SJohn Forte #include "isnsadm.h"
53fcf3ce44SJohn Forte 
54fcf3ce44SJohn Forte /* object functions per subcommand */
55fcf3ce44SJohn Forte static int list_node_func(int, char **, cmdOptions_t *, void *);
56fcf3ce44SJohn Forte static int list_dd_func(int, char **, cmdOptions_t *, void *);
57fcf3ce44SJohn Forte static int list_ddset_func(int, char **, cmdOptions_t *, void *);
58fcf3ce44SJohn Forte static int add_node_func(int, char **, cmdOptions_t *, void *);
59fcf3ce44SJohn Forte static int add_dd_func(int, char **, cmdOptions_t *, void *);
60fcf3ce44SJohn Forte static int delete_dd_func(int, char **, cmdOptions_t *, void *);
61fcf3ce44SJohn Forte static int delete_ddset_func(int, char **, cmdOptions_t *, void *);
62fcf3ce44SJohn Forte static int create_dd_func(int, char **, cmdOptions_t *, void *);
63fcf3ce44SJohn Forte static int create_ddset_func(int, char **, cmdOptions_t *, void *);
64fcf3ce44SJohn Forte static int remove_node_func(int, char **, cmdOptions_t *, void *);
65fcf3ce44SJohn Forte static int remove_dd_func(int, char **, cmdOptions_t *, void *);
66fcf3ce44SJohn Forte static int modify_dd_func(int, char **, cmdOptions_t *, void *);
67fcf3ce44SJohn Forte static int modify_ddset_func(int, char **, cmdOptions_t *, void *);
68fcf3ce44SJohn Forte static int enable_ddset_func(int, char **, cmdOptions_t *, void *);
69fcf3ce44SJohn Forte static int disable_ddset_func(int, char **, cmdOptions_t *, void *);
70fcf3ce44SJohn Forte static int show_config_func(int, char **, cmdOptions_t *, void *);
71fcf3ce44SJohn Forte static int i_enableddset(int, char **, boolean_t);
72fcf3ce44SJohn Forte static xmlTextReaderPtr lookup_next_matching_elem(xmlTextReaderPtr, int *,
73fcf3ce44SJohn Forte 	const char *, const char *);
74fcf3ce44SJohn Forte static int handle_association_info(xmlChar *, association_t);
75fcf3ce44SJohn Forte static int process_result_response(xmlChar *, int obj);
76fcf3ce44SJohn Forte static int process_get_assoc_response(xmlChar *, association_t);
77fcf3ce44SJohn Forte static int process_get_response(object_type, xmlChar *, uint32_t);
78fcf3ce44SJohn Forte static int cvt_enumerate_rsp_to_get_req(xmlChar *, xmlChar **, object_type,
79fcf3ce44SJohn Forte 	uint32_t);
80fcf3ce44SJohn Forte static int build_get_xml_doc(int, char **, object_type, xmlChar **);
81fcf3ce44SJohn Forte static int build_delete_xml_doc(int, char **, object_type, char *, xmlChar **);
82fcf3ce44SJohn Forte static int build_create_xml_doc(int, char **, object_type, char *, xmlChar **);
83fcf3ce44SJohn Forte static int build_modify_xml_doc(int, char **, object_type, boolean_t,
84fcf3ce44SJohn Forte 	xmlChar **);
85fcf3ce44SJohn Forte static int build_rename_xml_doc(char *, object_type, uint32_t, xmlChar **);
86fcf3ce44SJohn Forte static int build_assoc_xml_doc(xmlChar *, association_t, xmlChar **);
87fcf3ce44SJohn Forte static int build_assoc_xml_doc(xmlChar *, association_t, xmlChar **);
88fcf3ce44SJohn Forte static int build_enumerate_xml_doc(object_type, xmlChar **);
89fcf3ce44SJohn Forte 
90fcf3ce44SJohn Forte #define	NEW_XMLARGV(old, n) (xmlChar **)realloc((xmlChar *)old, \
91fcf3ce44SJohn Forte 	(unsigned)(n+2) * sizeof (xmlChar *))
92fcf3ce44SJohn Forte 
93fcf3ce44SJohn Forte #define	XML_SFREE(x)	(((x) != NULL) ? (xmlFree(x), (x) = NULL) : (void *)0)
94fcf3ce44SJohn Forte 
95fcf3ce44SJohn Forte #define	VERSION_STRING_MAX_LEN	10
96fcf3ce44SJohn Forte 
97fcf3ce44SJohn Forte #define	OPTIONSTRING_NAME	"name"
98fcf3ce44SJohn Forte #define	OPTIONSTRING_DDNAME	"Discovery Domain name"
99fcf3ce44SJohn Forte #define	OPTIONSTRING_DDSETNAME	"Discovery Domain Set name"
100fcf3ce44SJohn Forte #define	OPTIONSTRING_TARGET	"target"
101fcf3ce44SJohn Forte #define	OPTIONSTRING_INITIATOR	"initiator"
102fcf3ce44SJohn Forte #define	OPTIONSTRING_VERBOSE	"verbose"
103fcf3ce44SJohn Forte 
104fcf3ce44SJohn Forte #define	VERBOSE		0x00000001
105fcf3ce44SJohn Forte #define	INITIATOR_ONLY	0x00000010
106fcf3ce44SJohn Forte #define	TARGET_ONLY	0x00000100
107fcf3ce44SJohn Forte 
108*2ce65333SAlexander Pyhalov #if LIBXML_VERSION >= 20904
109*2ce65333SAlexander Pyhalov #define	XMLSTRING_CAST (const char *)
110*2ce65333SAlexander Pyhalov #else
111*2ce65333SAlexander Pyhalov #define	XMLSTRING_CAST (const xmlChar *)
112*2ce65333SAlexander Pyhalov #endif
113*2ce65333SAlexander Pyhalov 
114fcf3ce44SJohn Forte /* object table based on definitions in isns_mgmt.h. */
115fcf3ce44SJohn Forte static obj_table_entry_t obj_table[] = {
116fcf3ce44SJohn Forte 	{NODEOBJECT, Node},
117fcf3ce44SJohn Forte 	{DDOBJECT, DiscoveryDomain},
118fcf3ce44SJohn Forte 	{DDSETOBJECT, DiscoveryDomainSet},
119fcf3ce44SJohn Forte 	{DDOBJECTMEMBER, DiscoveryDomainMember},
120fcf3ce44SJohn Forte 	{DDSETOBJECTMEMBER, DiscoveryDomainSetMember},
121fcf3ce44SJohn Forte 	{ISNSSERVER, ServerConfig},
122fcf3ce44SJohn Forte 	{NULL, 0}
123fcf3ce44SJohn Forte };
124fcf3ce44SJohn Forte 
125fcf3ce44SJohn Forte /*
126fcf3ce44SJohn Forte  *  MAJOR - This should only change when there is an incompatible change made
127fcf3ce44SJohn Forte  *  to the interfaces or the output.
128fcf3ce44SJohn Forte  *
129fcf3ce44SJohn Forte  *  MINOR - This should change whenever there is a new command or new feature
130fcf3ce44SJohn Forte  *  with no incompatible change.
131fcf3ce44SJohn Forte  */
132fcf3ce44SJohn Forte #define	VERSION_STRING_MAJOR	    "1"
133fcf3ce44SJohn Forte #define	VERSION_STRING_MINOR	    "0"
134fcf3ce44SJohn Forte static char *ISNS_FMRI = "network/isns_server:default";
135fcf3ce44SJohn Forte 
136fcf3ce44SJohn Forte /*
137fcf3ce44SJohn Forte  * Add new options here
138fcf3ce44SJohn Forte  */
139fcf3ce44SJohn Forte 
140fcf3ce44SJohn Forte /* tables set up based on cmdparse instructions */
141fcf3ce44SJohn Forte optionTbl_t longOptions[] = {
142fcf3ce44SJohn Forte 	{"target", no_arg, 't', OPTIONSTRING_TARGET},
143fcf3ce44SJohn Forte 	{"initiator", no_arg, 'i', OPTIONSTRING_INITIATOR},
144fcf3ce44SJohn Forte 	{"verbose", no_arg, 'v', OPTIONSTRING_VERBOSE},
145fcf3ce44SJohn Forte 	{"name", required_arg, 'n', OPTIONSTRING_NAME},
146fcf3ce44SJohn Forte 	{"dd", required_arg, 'd', OPTIONSTRING_DDNAME},
147fcf3ce44SJohn Forte 	{"dd-set", required_arg, 's', OPTIONSTRING_DDSETNAME},
148fcf3ce44SJohn Forte 	{NULL, 0, 0, 0}
149fcf3ce44SJohn Forte };
150fcf3ce44SJohn Forte 
151fcf3ce44SJohn Forte 
152fcf3ce44SJohn Forte /*
153fcf3ce44SJohn Forte  * Add new subcommands here
154fcf3ce44SJohn Forte  */
155fcf3ce44SJohn Forte subCommandProps_t subcommands[] = {
156fcf3ce44SJohn Forte 	{"list-node", LISTNODE, list_node_func, "itv", B_FALSE, NULL,
157fcf3ce44SJohn Forte 		OPERAND_OPTIONAL_MULTIPLE, "node-name"},
158fcf3ce44SJohn Forte 	{"list-dd", LISTDD, list_dd_func, "v", B_FALSE, NULL,
159fcf3ce44SJohn Forte 		OPERAND_OPTIONAL_MULTIPLE, OPTIONSTRING_DDNAME},
160fcf3ce44SJohn Forte 	{"list-dd-set", LISTDDSET, list_ddset_func, "v", B_FALSE, NULL,
161fcf3ce44SJohn Forte 		OPERAND_OPTIONAL_MULTIPLE, OPTIONSTRING_DDSETNAME},
162fcf3ce44SJohn Forte 	{"create-dd", CREATEDD, create_dd_func, NULL, B_FALSE, NULL,
163fcf3ce44SJohn Forte 		OPERAND_MANDATORY_MULTIPLE, OPTIONSTRING_DDNAME},
164fcf3ce44SJohn Forte 	{"create-dd-set", CREATEDDSET, create_ddset_func, NULL, B_FALSE, NULL,
165fcf3ce44SJohn Forte 		OPERAND_MANDATORY_MULTIPLE, OPTIONSTRING_DDSETNAME},
166fcf3ce44SJohn Forte 	{"delete-dd", DELETEDD, delete_dd_func, NULL, B_FALSE, NULL,
167fcf3ce44SJohn Forte 		OPERAND_MANDATORY_MULTIPLE, OPTIONSTRING_DDNAME},
168fcf3ce44SJohn Forte 	{"delete-dd-set", DELETEDDSET, delete_ddset_func, NULL, B_FALSE, NULL,
169fcf3ce44SJohn Forte 		OPERAND_MANDATORY_MULTIPLE, OPTIONSTRING_DDSETNAME},
170fcf3ce44SJohn Forte 	{"add-node", ADDNODE, add_node_func, "d", B_TRUE, NULL,
171fcf3ce44SJohn Forte 		OPERAND_MANDATORY_MULTIPLE, "node-name"},
172fcf3ce44SJohn Forte 	{"add-dd", ADDDD, add_dd_func, "s", B_TRUE, NULL,
173fcf3ce44SJohn Forte 		OPERAND_MANDATORY_MULTIPLE, OPTIONSTRING_DDNAME},
174fcf3ce44SJohn Forte 	{"remove-node", REMOVENODE, remove_node_func, "d", B_TRUE, NULL,
175fcf3ce44SJohn Forte 		OPERAND_MANDATORY_MULTIPLE, "node-name"},
176fcf3ce44SJohn Forte 	{"remove-dd", REMOVEDD, remove_dd_func, "s", B_TRUE, NULL,
177fcf3ce44SJohn Forte 		OPERAND_MANDATORY_MULTIPLE, OPTIONSTRING_DDNAME},
178fcf3ce44SJohn Forte 	{"modify-dd", MODIFYDD, modify_dd_func, "n", B_TRUE, NULL,
179fcf3ce44SJohn Forte 		OPERAND_MANDATORY_SINGLE, OPTIONSTRING_NAME},
180fcf3ce44SJohn Forte 	{"modify-dd-set", MODIFYDDSET, modify_ddset_func, "n", B_TRUE, NULL,
181fcf3ce44SJohn Forte 		OPERAND_MANDATORY_SINGLE, OPTIONSTRING_NAME},
182fcf3ce44SJohn Forte 	{"enable-dd-set", ENABLEDDSET, enable_ddset_func, NULL, B_FALSE, NULL,
183fcf3ce44SJohn Forte 		OPERAND_MANDATORY_MULTIPLE, OPTIONSTRING_DDSETNAME},
184fcf3ce44SJohn Forte 	{"disable-dd-set", DISABLEDDSET, disable_ddset_func, NULL, B_FALSE,
185fcf3ce44SJohn Forte 		NULL, OPERAND_MANDATORY_MULTIPLE, OPTIONSTRING_DDSETNAME},
186fcf3ce44SJohn Forte 	{"show-config", SHOWCONFIG, show_config_func, NULL, B_FALSE, NULL,
187fcf3ce44SJohn Forte 		OPERAND_NONE, NULL},
188fcf3ce44SJohn Forte 	{NULL, 0, NULL, NULL, 0, NULL, 0, NULL}
189fcf3ce44SJohn Forte };
190fcf3ce44SJohn Forte 
191fcf3ce44SJohn Forte /*
192fcf3ce44SJohn Forte  * ****************************************************************************
193fcf3ce44SJohn Forte  *
194fcf3ce44SJohn Forte  * check_door_error
195fcf3ce44SJohn Forte  *
196fcf3ce44SJohn Forte  * input:
197fcf3ce44SJohn Forte  *  errno from the door call.
198fcf3ce44SJohn Forte  *
199fcf3ce44SJohn Forte  * Returns:
200fcf3ce44SJohn Forte  *  either door error or smf service error.
201fcf3ce44SJohn Forte  *
202fcf3ce44SJohn Forte  * ****************************************************************************
203fcf3ce44SJohn Forte  */
204fcf3ce44SJohn Forte static int
205fcf3ce44SJohn Forte check_door_error(int door_err, int err)
206fcf3ce44SJohn Forte {
207fcf3ce44SJohn Forte 	char	*state = NULL;
208fcf3ce44SJohn Forte 	int	ret;
209fcf3ce44SJohn Forte 
210fcf3ce44SJohn Forte 	if (((state = smf_get_state(ISNS_FMRI)) != NULL) &&
211fcf3ce44SJohn Forte 	    (strcmp(state, SCF_STATE_STRING_ONLINE) != 0)) {
212fcf3ce44SJohn Forte 		ret = ERROR_ISNS_SMF_SERVICE_NOT_ONLINE;
213fcf3ce44SJohn Forte 	} else {
214fcf3ce44SJohn Forte 	    (void) fprintf(stderr, "%s\n",
215fcf3ce44SJohn Forte 		(door_err == ERROR_DOOR_CALL_FAILED) ?
216fcf3ce44SJohn Forte 		getTextMessage(ERROR_DOOR_CALL_FAILED) :
217fcf3ce44SJohn Forte 		getTextMessage(ERROR_DOOR_OPEN_FAILED));
218fcf3ce44SJohn Forte 	    (void) fprintf(stderr, "\terrno: %s\n", strerror(err));
219fcf3ce44SJohn Forte 	    ret = door_err;
220fcf3ce44SJohn Forte 	}
221fcf3ce44SJohn Forte 
222fcf3ce44SJohn Forte 	if (state) free(state);
223fcf3ce44SJohn Forte 
224fcf3ce44SJohn Forte 	return (ret);
225fcf3ce44SJohn Forte }
226fcf3ce44SJohn Forte 
227fcf3ce44SJohn Forte /*
228fcf3ce44SJohn Forte  * ****************************************************************************
229fcf3ce44SJohn Forte  *
230fcf3ce44SJohn Forte  * lookup an element based on the element name.
231fcf3ce44SJohn Forte  *
232fcf3ce44SJohn Forte  * reader	- current xmlReaderReadPtr
233fcf3ce44SJohn Forte  * m_falg	- indicate lookup result
234fcf3ce44SJohn Forte  * elem		- name of element to look up.
235fcf3ce44SJohn Forte  * endelem	- name of end element to look up.
236fcf3ce44SJohn Forte  *
237fcf3ce44SJohn Forte  * ****************************************************************************
238fcf3ce44SJohn Forte  */
239fcf3ce44SJohn Forte static	xmlTextReaderPtr
240fcf3ce44SJohn Forte lookup_next_matching_elem(xmlTextReaderPtr reader, int *m_flag,
241fcf3ce44SJohn Forte 	const char *elem, const char *endelem)
242fcf3ce44SJohn Forte {
243fcf3ce44SJohn Forte 
244fcf3ce44SJohn Forte 	if (reader == NULL) {
245fcf3ce44SJohn Forte 	    *m_flag = NO_MATCH;
246fcf3ce44SJohn Forte 	    return (NULL);
247fcf3ce44SJohn Forte 	}
248fcf3ce44SJohn Forte 
249fcf3ce44SJohn Forte 	do {
250fcf3ce44SJohn Forte 	/*
251fcf3ce44SJohn Forte 	 * if (xmlTextReaderName(reader) != NULL) {
252fcf3ce44SJohn Forte 	 * 	printf("%s ", xmlTextReaderName(reader));
253fcf3ce44SJohn Forte 	 * }
254fcf3ce44SJohn Forte 	 * printf("%d %d %d\n",
255fcf3ce44SJohn Forte 	 * xmlTextReaderDepth(reader),
256fcf3ce44SJohn Forte 	 * xmlTextReaderNodeType(reader),
257fcf3ce44SJohn Forte 	 * xmlTextReaderIsEmptyElement(reader));
258fcf3ce44SJohn Forte 	 */
259fcf3ce44SJohn Forte 		/*
260fcf3ce44SJohn Forte 		 * if match with elem, return the reader with READER_MATCH flag.
261fcf3ce44SJohn Forte 		 * if match with end elem, return the reader wtih
262fcf3ce44SJohn Forte 		 * END_READER_MATCH flag.
263fcf3ce44SJohn Forte 		 */
264fcf3ce44SJohn Forte 	    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT) {
265fcf3ce44SJohn Forte 		if (XMLNCMP(reader, elem) == 0) {
266fcf3ce44SJohn Forte 		    *m_flag = READER_MATCH;
267fcf3ce44SJohn Forte 		    return (reader);
268fcf3ce44SJohn Forte 		}
269fcf3ce44SJohn Forte 	    } else if (xmlTextReaderNodeType(reader) ==
270fcf3ce44SJohn Forte 		XML_READER_TYPE_END_ELEMENT) {
271fcf3ce44SJohn Forte 		if (XMLNCMP(reader, endelem) == 0) {
272fcf3ce44SJohn Forte 		    *m_flag = END_READER_MATCH;
273fcf3ce44SJohn Forte 		    return (reader);
274fcf3ce44SJohn Forte 		}
275fcf3ce44SJohn Forte 	    }
276fcf3ce44SJohn Forte 	} while (xmlTextReaderRead(reader) == 1);
277fcf3ce44SJohn Forte 
278fcf3ce44SJohn Forte 	*m_flag = NO_MATCH;
279fcf3ce44SJohn Forte 	return (NULL);
280fcf3ce44SJohn Forte }
281fcf3ce44SJohn Forte 
282fcf3ce44SJohn Forte /*
283fcf3ce44SJohn Forte  * ****************************************************************************
284fcf3ce44SJohn Forte  *
285fcf3ce44SJohn Forte  * Routine for getAssociated operation
286fcf3ce44SJohn Forte  *	Construct association request  based on the name and calls door
287fcf3ce44SJohn Forte  *	interface.
288fcf3ce44SJohn Forte  *
289fcf3ce44SJohn Forte  * name		- name attributes of an object for getting an association
290fcf3ce44SJohn Forte  * assoc	- association type
291fcf3ce44SJohn Forte  *
292fcf3ce44SJohn Forte  * ****************************************************************************
293fcf3ce44SJohn Forte  */
294fcf3ce44SJohn Forte static int
295fcf3ce44SJohn Forte handle_association_info(xmlChar *name, association_t assoc)
296fcf3ce44SJohn Forte {
297fcf3ce44SJohn Forte 
298fcf3ce44SJohn Forte 	xmlChar *doc;
299fcf3ce44SJohn Forte 	door_arg_t darg;
300fcf3ce44SJohn Forte 	msg_code_t ret;
301fcf3ce44SJohn Forte 	int fd;
302fcf3ce44SJohn Forte 
303fcf3ce44SJohn Forte 	if ((ret = build_assoc_xml_doc(name, assoc, &doc)) != 0) {
304fcf3ce44SJohn Forte 	    return (ret);
305fcf3ce44SJohn Forte 	}
306fcf3ce44SJohn Forte 
307fcf3ce44SJohn Forte 	if ((fd = open(ISNS_DOOR_NAME, 0)) == -1) {
308fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_OPEN_FAILED, errno);
309fcf3ce44SJohn Forte 	    return (ret);
310fcf3ce44SJohn Forte 	}
311fcf3ce44SJohn Forte 
312fcf3ce44SJohn Forte 	(void) bzero(&darg, sizeof (darg));
313fcf3ce44SJohn Forte 	bzero(&darg, sizeof (darg));
314fcf3ce44SJohn Forte 	darg.data_ptr = (char *)doc;
315fcf3ce44SJohn Forte 	darg.data_size = xmlStrlen(doc) + 1;
316fcf3ce44SJohn Forte 	darg.rbuf = NULL;
317fcf3ce44SJohn Forte 	darg.rsize = 0;
318fcf3ce44SJohn Forte 	if ((door_call(fd, &darg)) == -1) {
319fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_CALL_FAILED, errno);
320fcf3ce44SJohn Forte 	    (void) close(fd);
321fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
322fcf3ce44SJohn Forte 	    return (ret);
323fcf3ce44SJohn Forte 	}
324fcf3ce44SJohn Forte 
325fcf3ce44SJohn Forte 	if ((ret = process_get_assoc_response((xmlChar *)darg.rbuf,
326fcf3ce44SJohn Forte 	    assoc)) != 0) {
327fcf3ce44SJohn Forte 	/*
328fcf3ce44SJohn Forte 	 * door frame work allocated a buffer when the date lager
329fcf3ce44SJohn Forte 	 * that rbuf. indicate if munmap is required on rbuf.
330fcf3ce44SJohn Forte 	 */
331fcf3ce44SJohn Forte 	    (void) munmap(darg.rbuf, darg.rsize);
332fcf3ce44SJohn Forte 	    (void) close(fd);
333fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
334fcf3ce44SJohn Forte 	    return (ret);
335fcf3ce44SJohn Forte 	}
336fcf3ce44SJohn Forte 
337fcf3ce44SJohn Forte 	(void) munmap(darg.rbuf, darg.rsize);
338fcf3ce44SJohn Forte 
339fcf3ce44SJohn Forte 	(void) close(fd);
340fcf3ce44SJohn Forte 	(void) xmlFree(doc);
341fcf3ce44SJohn Forte 
342fcf3ce44SJohn Forte 	return (0);
343fcf3ce44SJohn Forte }
344fcf3ce44SJohn Forte 
345fcf3ce44SJohn Forte /*
346fcf3ce44SJohn Forte  * ****************************************************************************
347fcf3ce44SJohn Forte  *
348fcf3ce44SJohn Forte  * process_error_status
349fcf3ce44SJohn Forte  *	The routine process non 0 status and print out error message.
350fcf3ce44SJohn Forte  *
351fcf3ce44SJohn Forte  * status	- status code
352fcf3ce44SJohn Forte  * reader	- reader that points to the message element.
353fcf3ce44SJohn Forte  *
354fcf3ce44SJohn Forte  * ****************************************************************************
355fcf3ce44SJohn Forte  */
356fcf3ce44SJohn Forte static void
357fcf3ce44SJohn Forte print_error_status(int status, int obj, xmlTextReaderPtr reader)
358fcf3ce44SJohn Forte {
359fcf3ce44SJohn Forte 	int m_flag = 0;
360fcf3ce44SJohn Forte 
361fcf3ce44SJohn Forte 	switch (status) {
362fcf3ce44SJohn Forte 	case ISNS_RSP_BUSY:
363fcf3ce44SJohn Forte 	    (void) fprintf(stderr, "%s\n",
364fcf3ce44SJohn Forte 		getTextMessage(ERROR_SERVER_BUSY));
365fcf3ce44SJohn Forte 	    break;
366fcf3ce44SJohn Forte 	case ISNS_RSP_INTERNAL_ERROR:
367fcf3ce44SJohn Forte 	    (void) fprintf(stderr, "%s\n",
368fcf3ce44SJohn Forte 		getTextMessage(ERROR_SERVER_INTERNAL_ERROR));
369fcf3ce44SJohn Forte 	    break;
370fcf3ce44SJohn Forte 	case ISNS_RSP_OPTION_NOT_UNDERSTOOD:
371fcf3ce44SJohn Forte 	    if ((obj == DiscoveryDomain) ||
372fcf3ce44SJohn Forte 		(obj == DiscoveryDomainMember)) {
373fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n",
374fcf3ce44SJohn Forte 		getTextMessage(ERROR_OPERATION_NOT_ALLOWED_FOR_DEFAULT_DD));
375fcf3ce44SJohn Forte 	    } else {
376fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n",
377fcf3ce44SJohn Forte 		getTextMessage(ERROR_OPERATION_NOT_ALLOWED_FOR_DEFAULT_DDSET));
378fcf3ce44SJohn Forte 	    }
379fcf3ce44SJohn Forte 	    break;
380fcf3ce44SJohn Forte 	case PARTIAL_FAILURE:
381fcf3ce44SJohn Forte 	    (void) fprintf(stderr, "%s\n",
382fcf3ce44SJohn Forte 		getTextMessage(ERROR_PARTIAL_FAILURE));
383fcf3ce44SJohn Forte 	    break;
384fcf3ce44SJohn Forte 	case ERR_NO_SUCH_ASSOCIATION:
385fcf3ce44SJohn Forte 	    if ((obj == DiscoveryDomain) ||
386fcf3ce44SJohn Forte 		(obj == DiscoveryDomainMember)) {
387fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n",
388fcf3ce44SJohn Forte 		getTextMessage(ERROR_DDMEMBER_NOT_FOUND));
389fcf3ce44SJohn Forte 	    } else {
390fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n",
391fcf3ce44SJohn Forte 		getTextMessage(ERROR_DDSETMEMBER_NOT_FOUND));
392fcf3ce44SJohn Forte 	    }
393fcf3ce44SJohn Forte 	    break;
394fcf3ce44SJohn Forte 	case ERR_ALREADY_ASSOCIATED:
395fcf3ce44SJohn Forte 	    if ((obj == DiscoveryDomain) ||
396fcf3ce44SJohn Forte 		(obj == DiscoveryDomainMember)) {
397fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n",
398fcf3ce44SJohn Forte 		getTextMessage(ERROR_DDMEMBER_ALREADY_EXIST));
399fcf3ce44SJohn Forte 	    } else {
400fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n",
401fcf3ce44SJohn Forte 		getTextMessage(ERROR_DDSETMEMBER_ALREADY_EXIST));
402fcf3ce44SJohn Forte 	    }
403fcf3ce44SJohn Forte 	    break;
404fcf3ce44SJohn Forte 	case ERR_NAME_IN_USE:
405fcf3ce44SJohn Forte 	    if ((obj == DiscoveryDomain) ||
406fcf3ce44SJohn Forte 		(obj == DiscoveryDomainMember)) {
407fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n",
408fcf3ce44SJohn Forte 		getTextMessage(ERROR_DD_NAME_IN_USE));
409fcf3ce44SJohn Forte 	    } else {
410fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n",
411fcf3ce44SJohn Forte 		getTextMessage(ERROR_DDSET_NAME_IN_USE));
412fcf3ce44SJohn Forte 	    }
413fcf3ce44SJohn Forte 	    break;
414fcf3ce44SJohn Forte 	default:
415fcf3ce44SJohn Forte 	    reader = lookup_next_matching_elem(reader, &m_flag,
416fcf3ce44SJohn Forte 		MESSAGEELEMENT, RESULTELEMENT);
417fcf3ce44SJohn Forte 	    if (m_flag == READER_MATCH) {
418fcf3ce44SJohn Forte 		(void) xmlTextReaderRead(reader);
419fcf3ce44SJohn Forte 		(void) fprintf(stderr, "Error: %s\n",
420fcf3ce44SJohn Forte 			(const char *) xmlTextReaderConstValue(reader));
421fcf3ce44SJohn Forte 	    } else {
422fcf3ce44SJohn Forte 		(void) fprintf(stderr, "Error: %s\n",
423fcf3ce44SJohn Forte 		getTextMessage(ERROR_XML_MESSAGE_ELEM_NOT_FOUND));
424fcf3ce44SJohn Forte 	    }
425fcf3ce44SJohn Forte 	}
426fcf3ce44SJohn Forte }
427fcf3ce44SJohn Forte 
428fcf3ce44SJohn Forte /*
429fcf3ce44SJohn Forte  * ****************************************************************************
430fcf3ce44SJohn Forte  *
431fcf3ce44SJohn Forte  * print_partial_failure_info
432fcf3ce44SJohn Forte  *	The routine prints partial failure info.
433fcf3ce44SJohn Forte  *
434fcf3ce44SJohn Forte  * status	- status code
435fcf3ce44SJohn Forte  * reader	- reader that points to the message element.
436fcf3ce44SJohn Forte  *
437fcf3ce44SJohn Forte  * ****************************************************************************
438fcf3ce44SJohn Forte  */
439fcf3ce44SJohn Forte static void
440fcf3ce44SJohn Forte print_partial_failure_info(xmlChar *doc)
441fcf3ce44SJohn Forte {
442fcf3ce44SJohn Forte 	xmlChar expr[ISNS_MAX_LABEL_LEN + 13];
443fcf3ce44SJohn Forte 	xmlDocPtr x_doc;
444fcf3ce44SJohn Forte 	xmlXPathContextPtr ctext = NULL;
445fcf3ce44SJohn Forte 	xmlXPathObjectPtr xpath_obj = NULL;
446fcf3ce44SJohn Forte 	xmlNodeSetPtr r_nodes = NULL;
447fcf3ce44SJohn Forte 	xmlAttrPtr attr = NULL;
448fcf3ce44SJohn Forte 	int i, cnt, obj = 0;
449fcf3ce44SJohn Forte 
450fcf3ce44SJohn Forte 	if ((x_doc = xmlParseMemory((const char *)doc, xmlStrlen(doc))) ==
451fcf3ce44SJohn Forte 	    NULL) {
452fcf3ce44SJohn Forte 	    (void) fprintf(stderr, "%s\n",
453fcf3ce44SJohn Forte 		getTextMessage(ERROR_NO_ADDITIONAL_PARTIAL_FAILIRE_INFO));
454fcf3ce44SJohn Forte 	}
455fcf3ce44SJohn Forte 
456fcf3ce44SJohn Forte 	ctext = xmlXPathNewContext(x_doc);
457fcf3ce44SJohn Forte 	if (ctext == NULL) {
458fcf3ce44SJohn Forte 	    (void) fprintf(stderr, "%s\n",
459fcf3ce44SJohn Forte 		getTextMessage(ERROR_NO_ADDITIONAL_PARTIAL_FAILIRE_INFO));
460fcf3ce44SJohn Forte 	}
461fcf3ce44SJohn Forte 
462fcf3ce44SJohn Forte 	for (i = 0; obj_table[i].obj_str != NULL; i++) {
463fcf3ce44SJohn Forte 	    (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13,
464*2ce65333SAlexander Pyhalov 		XMLSTRING_CAST "%s\"%s\"]", "//*[name()=",
465fcf3ce44SJohn Forte 		obj_table[i].obj_str);
466fcf3ce44SJohn Forte 	    xpath_obj = xmlXPathEvalExpression(expr, ctext);
467fcf3ce44SJohn Forte 	    if ((xpath_obj) && (xpath_obj->nodesetval) &&
468fcf3ce44SJohn Forte 		(xpath_obj->nodesetval->nodeNr > 0) &&
469fcf3ce44SJohn Forte 		(xpath_obj->nodesetval->nodeTab)) {
470fcf3ce44SJohn Forte 		obj = obj_table[i].obj_id;
471fcf3ce44SJohn Forte 		break;
472fcf3ce44SJohn Forte 	    }
473fcf3ce44SJohn Forte 	}
474fcf3ce44SJohn Forte 
475fcf3ce44SJohn Forte 	if (obj == 0) {
476fcf3ce44SJohn Forte 	    if (xpath_obj) xmlXPathFreeObject(xpath_obj);
477fcf3ce44SJohn Forte 	    (void) fprintf(stderr, "%s\n",
478fcf3ce44SJohn Forte 		getTextMessage(ERROR_NO_ADDITIONAL_PARTIAL_FAILIRE_INFO));
479fcf3ce44SJohn Forte 	}
480fcf3ce44SJohn Forte 
481fcf3ce44SJohn Forte 	switch (obj) {
482fcf3ce44SJohn Forte 	    case DiscoveryDomainMember:
483fcf3ce44SJohn Forte 		r_nodes = xpath_obj->nodesetval;
484fcf3ce44SJohn Forte 		cnt = r_nodes->nodeNr;
485fcf3ce44SJohn Forte 		for (i = 0; i < cnt; i++) {
486fcf3ce44SJohn Forte 		    attr = r_nodes->nodeTab[i]->properties;
487fcf3ce44SJohn Forte 		    for (; attr != NULL; attr = attr->next) {
488fcf3ce44SJohn Forte 			if (xmlStrncmp(attr->name, (xmlChar *)DDNAMEATTR,
489fcf3ce44SJohn Forte 			    xmlStrlen((xmlChar *)DDNAMEATTR)) == 0) {
490fcf3ce44SJohn Forte 				(void) fprintf(stderr, "DD Name: %s\t",
491fcf3ce44SJohn Forte 				xmlNodeGetContent(attr->children));
492fcf3ce44SJohn Forte 			}
493fcf3ce44SJohn Forte 			if (xmlStrncmp(attr->name, (xmlChar *)NODENAMEATTR,
494fcf3ce44SJohn Forte 			    xmlStrlen((xmlChar *)NODENAMEATTR)) == 0) {
495fcf3ce44SJohn Forte 				(void) fprintf(stderr, "Node Name: %s\t",
496fcf3ce44SJohn Forte 				xmlNodeGetContent(attr->children));
497fcf3ce44SJohn Forte 			}
498fcf3ce44SJohn Forte 		    }
499fcf3ce44SJohn Forte 		    (void) fprintf(stderr, "\n");
500fcf3ce44SJohn Forte 		}
501fcf3ce44SJohn Forte 		if (xpath_obj) xmlXPathFreeObject(xpath_obj);
502fcf3ce44SJohn Forte 		break;
503fcf3ce44SJohn Forte 	    case DiscoveryDomainSetMember:
504fcf3ce44SJohn Forte 		r_nodes = xpath_obj->nodesetval;
505fcf3ce44SJohn Forte 		cnt = r_nodes->nodeNr;
506fcf3ce44SJohn Forte 		for (i = 0; i < cnt; i++) {
507fcf3ce44SJohn Forte 		    attr = r_nodes->nodeTab[i]->properties;
508fcf3ce44SJohn Forte 		    for (; attr != NULL; attr = attr->next) {
509fcf3ce44SJohn Forte 			if (xmlStrncmp(attr->name, (xmlChar *)DDSETNAMEATTR,
510fcf3ce44SJohn Forte 			    xmlStrlen((xmlChar *)DDNAMEATTR)) == 0) {
511fcf3ce44SJohn Forte 				(void) fprintf(stderr, "DD Set Name: %s\t",
512fcf3ce44SJohn Forte 				xmlNodeGetContent(attr->children));
513fcf3ce44SJohn Forte 			}
514fcf3ce44SJohn Forte 			if (xmlStrncmp(attr->name, (xmlChar *)DDNAMEATTR,
515fcf3ce44SJohn Forte 			    xmlStrlen((xmlChar *)NODENAMEATTR)) == 0) {
516fcf3ce44SJohn Forte 				(void) fprintf(stderr, "DD Name: %s\t",
517fcf3ce44SJohn Forte 				xmlNodeGetContent(attr->children));
518fcf3ce44SJohn Forte 			}
519fcf3ce44SJohn Forte 		    }
520fcf3ce44SJohn Forte 		    (void) fprintf(stderr, "\n");
521fcf3ce44SJohn Forte 		}
522fcf3ce44SJohn Forte 		if (xpath_obj) xmlXPathFreeObject(xpath_obj);
523fcf3ce44SJohn Forte 		break;
524fcf3ce44SJohn Forte 	    case Node:
525fcf3ce44SJohn Forte 	    case DiscoveryDomain:
526fcf3ce44SJohn Forte 	    case DiscoveryDomainSet:
527fcf3ce44SJohn Forte 		r_nodes = xpath_obj->nodesetval;
528fcf3ce44SJohn Forte 		cnt = r_nodes->nodeNr;
529fcf3ce44SJohn Forte 		for (i = 0; i < cnt; i++) {
530fcf3ce44SJohn Forte 		    attr = r_nodes->nodeTab[i]->properties;
531fcf3ce44SJohn Forte 		    for (; attr != NULL; attr = attr->next) {
532fcf3ce44SJohn Forte 			if ((xmlStrncmp(attr->name, (xmlChar *)NAMEATTR,
533fcf3ce44SJohn Forte 			    xmlStrlen((xmlChar *)NAMEATTR))) == 0) {
534fcf3ce44SJohn Forte 				(void) fprintf(stderr, "Object Name: %s\n",
535fcf3ce44SJohn Forte 				xmlNodeGetContent(attr->children));
536fcf3ce44SJohn Forte 			}
537fcf3ce44SJohn Forte 		    }
538fcf3ce44SJohn Forte 		}
539fcf3ce44SJohn Forte 		if (xpath_obj) xmlXPathFreeObject(xpath_obj);
540fcf3ce44SJohn Forte 		break;
541fcf3ce44SJohn Forte 	}
542fcf3ce44SJohn Forte }
543fcf3ce44SJohn Forte 
544fcf3ce44SJohn Forte /*
545fcf3ce44SJohn Forte  * ****************************************************************************
546fcf3ce44SJohn Forte  *
547fcf3ce44SJohn Forte  * process_result_response
548fcf3ce44SJohn Forte  *	The routine process association data based on the association type.
549fcf3ce44SJohn Forte  *
550fcf3ce44SJohn Forte  * doc		- result
551fcf3ce44SJohn Forte  * obj		- associated object type
552fcf3ce44SJohn Forte  *
553fcf3ce44SJohn Forte  * ****************************************************************************
554fcf3ce44SJohn Forte  */
555fcf3ce44SJohn Forte static int
556fcf3ce44SJohn Forte process_result_response(xmlChar *doc, int obj)
557fcf3ce44SJohn Forte {
558fcf3ce44SJohn Forte 	xmlTextReaderPtr reader;
559fcf3ce44SJohn Forte 	int m_flag = 0, status;
560fcf3ce44SJohn Forte 
561fcf3ce44SJohn Forte 	if ((reader = (xmlTextReaderPtr)xmlReaderForMemory((const char *)doc,
562fcf3ce44SJohn Forte 	    xmlStrlen(doc), NULL, NULL, 0)) == NULL) {
563fcf3ce44SJohn Forte 		return (ERROR_XML_READER_NULL);
564fcf3ce44SJohn Forte 	}
565fcf3ce44SJohn Forte 
566fcf3ce44SJohn Forte 	/* if status is 0, continue on.  Otherwise return an error. */
567fcf3ce44SJohn Forte 	if (reader = lookup_next_matching_elem(reader, &m_flag, STATUSELEMENT,
568fcf3ce44SJohn Forte 	    RESULTELEMENT)) {
569fcf3ce44SJohn Forte 	    if (m_flag == READER_MATCH) {
570fcf3ce44SJohn Forte 		if (xmlTextReaderRead(reader) == 1) {
571fcf3ce44SJohn Forte 		    status =
572fcf3ce44SJohn Forte 		    atoi((const char *)xmlTextReaderConstValue(reader));
573fcf3ce44SJohn Forte 		    if (status != 0) {
574fcf3ce44SJohn Forte 			print_error_status(status, obj, reader);
575fcf3ce44SJohn Forte 			(void) xmlTextReaderClose(reader);
576fcf3ce44SJohn Forte 			(void) xmlFreeTextReader(reader);
577fcf3ce44SJohn Forte 			if (status == PARTIAL_FAILURE) {
578fcf3ce44SJohn Forte 			    print_partial_failure_info(doc);
579fcf3ce44SJohn Forte 			}
580fcf3ce44SJohn Forte 			return (status);
581fcf3ce44SJohn Forte 		    }
582fcf3ce44SJohn Forte 		} else {
583fcf3ce44SJohn Forte 		    (void) xmlTextReaderClose(reader);
584fcf3ce44SJohn Forte 		    (void) xmlFreeTextReader(reader);
585fcf3ce44SJohn Forte 		    return (ERROR_XML_STATUS_ELEM_NOT_FOUND);
586fcf3ce44SJohn Forte 		}
587fcf3ce44SJohn Forte 	    } else {
588fcf3ce44SJohn Forte 		(void) xmlTextReaderClose(reader);
589fcf3ce44SJohn Forte 		(void) xmlFreeTextReader(reader);
590fcf3ce44SJohn Forte 		return (ERROR_XML_STATUS_ELEM_NOT_FOUND);
591fcf3ce44SJohn Forte 	    }
592fcf3ce44SJohn Forte 	} else {
593fcf3ce44SJohn Forte 	    (void) fprintf(stderr, "%s\n",
594fcf3ce44SJohn Forte 		getTextMessage(ERROR_XML_READER_NULL));
595fcf3ce44SJohn Forte 	    return (ERROR_XML_READER_NULL);
596fcf3ce44SJohn Forte 	}
597fcf3ce44SJohn Forte 
598fcf3ce44SJohn Forte 	(void) xmlTextReaderClose(reader);
599fcf3ce44SJohn Forte 	(void) xmlFreeTextReader(reader);
600fcf3ce44SJohn Forte 	return (0);
601fcf3ce44SJohn Forte }
602fcf3ce44SJohn Forte 
603fcf3ce44SJohn Forte /*
604fcf3ce44SJohn Forte  * ****************************************************************************
605fcf3ce44SJohn Forte  *
606fcf3ce44SJohn Forte  * process_get_assoc_response
607fcf3ce44SJohn Forte  *	The routine process association data based on the association type.
608fcf3ce44SJohn Forte  *
609fcf3ce44SJohn Forte  * doc		- association data
610fcf3ce44SJohn Forte  * assoc	- associatiion type
611fcf3ce44SJohn Forte  *
612fcf3ce44SJohn Forte  * ****************************************************************************
613fcf3ce44SJohn Forte  */
614fcf3ce44SJohn Forte static int
615fcf3ce44SJohn Forte process_get_assoc_response(xmlChar *doc, association_t assoc)
616fcf3ce44SJohn Forte {
617fcf3ce44SJohn Forte 	xmlTextReaderPtr reader;
618fcf3ce44SJohn Forte 	xmlChar *ddsname, *ddname, *nodename;
619fcf3ce44SJohn Forte 	wchar_t wc_name[ISNS_MAX_NAME_LEN];
620fcf3ce44SJohn Forte 	int m_flag = 0, h_printed = 0, status;
621fcf3ce44SJohn Forte 
622fcf3ce44SJohn Forte 	if ((reader = (xmlTextReaderPtr)xmlReaderForMemory((const char *)doc,
623fcf3ce44SJohn Forte 			xmlStrlen(doc), NULL, NULL, 0)) == NULL) {
624fcf3ce44SJohn Forte 	    return (ERROR_XML_READER_NULL);
625fcf3ce44SJohn Forte 	}
626fcf3ce44SJohn Forte 
627fcf3ce44SJohn Forte 	/* if status is 0, continue on.  Otherwise return an error. */
628fcf3ce44SJohn Forte 	if (reader = lookup_next_matching_elem(reader, &m_flag, STATUSELEMENT,
629fcf3ce44SJohn Forte 	    RESULTELEMENT)) {
630fcf3ce44SJohn Forte 	    if (m_flag == READER_MATCH) {
631fcf3ce44SJohn Forte 		if (xmlTextReaderRead(reader) == 1) {
632fcf3ce44SJohn Forte 		    status =
633fcf3ce44SJohn Forte 		    atoi((const char *)xmlTextReaderConstValue(reader));
634fcf3ce44SJohn Forte 		    if ((status != 0) && (status != PARTIAL_SUCCESS)) {
635fcf3ce44SJohn Forte 			/* not an error */
636fcf3ce44SJohn Forte 			if ((status !=  ERR_NO_SUCH_ASSOCIATION) &&
637fcf3ce44SJohn Forte 			    (status !=  ERR_NO_ASSOCIATED_DD_FOUND) &&
638fcf3ce44SJohn Forte 			    (status !=  ERR_NO_ASSOCIATED_DDSET_FOUND)) {
639fcf3ce44SJohn Forte 			    (void) xmlTextReaderClose(reader);
640fcf3ce44SJohn Forte 			    (void) xmlFreeTextReader(reader);
641fcf3ce44SJohn Forte 			    return (0);
642fcf3ce44SJohn Forte 			} else {
643fcf3ce44SJohn Forte 			    print_error_status(status,
644fcf3ce44SJohn Forte 				((assoc == node_to_dd) || (dd_to_node)) ?
645fcf3ce44SJohn Forte 				DiscoveryDomain : DiscoveryDomainSet, reader);
646fcf3ce44SJohn Forte 			    (void) xmlTextReaderClose(reader);
647fcf3ce44SJohn Forte 			    (void) xmlFreeTextReader(reader);
648fcf3ce44SJohn Forte 			    return (status);
649fcf3ce44SJohn Forte 			}
650fcf3ce44SJohn Forte 		    }
651fcf3ce44SJohn Forte 		} else {
652fcf3ce44SJohn Forte 		    (void) xmlTextReaderClose(reader);
653fcf3ce44SJohn Forte 		    (void) xmlFreeTextReader(reader);
654fcf3ce44SJohn Forte 		    return (ERROR_XML_STATUS_ELEM_NOT_FOUND);
655fcf3ce44SJohn Forte 		}
656fcf3ce44SJohn Forte 	    } else {
657fcf3ce44SJohn Forte 		return (ERROR_XML_STATUS_ELEM_NOT_FOUND);
658fcf3ce44SJohn Forte 	    }
659fcf3ce44SJohn Forte 	} else {
660fcf3ce44SJohn Forte 	    return (ERROR_XML_READER_NULL);
661fcf3ce44SJohn Forte 	}
662fcf3ce44SJohn Forte 
663fcf3ce44SJohn Forte 	m_flag = 0;
664fcf3ce44SJohn Forte 
665fcf3ce44SJohn Forte 	switch (assoc) {
666fcf3ce44SJohn Forte 	    case node_to_dd:
667fcf3ce44SJohn Forte 		/* process DD elements */
668fcf3ce44SJohn Forte 		while (reader = lookup_next_matching_elem(reader, &m_flag,
669fcf3ce44SJohn Forte 		    DDOBJECTMEMBER, ISNSRESPONSE)) {
670fcf3ce44SJohn Forte 		    if (m_flag == END_READER_MATCH) {
671fcf3ce44SJohn Forte 			(void) xmlTextReaderNext(reader);
672fcf3ce44SJohn Forte 			break;
673fcf3ce44SJohn Forte 		    } else if (m_flag == READER_MATCH) {
674fcf3ce44SJohn Forte 			if ((ddname = (xmlTextReaderGetAttribute(reader,
675fcf3ce44SJohn Forte 			    (const xmlChar *)DDNAMEATTR))) != NULL) {
676fcf3ce44SJohn Forte 			    if (mbstowcs(wc_name, (const char *)ddname,
677fcf3ce44SJohn Forte 				ISNS_MAX_NAME_LEN) == (size_t)-1) {
678fcf3ce44SJohn Forte 				(void) wcscpy(wc_name, L"-");
679fcf3ce44SJohn Forte 			    }
680fcf3ce44SJohn Forte 			    if (h_printed) {
681fcf3ce44SJohn Forte 				(void) printf("\tDD Name: %ws\n", wc_name);
682fcf3ce44SJohn Forte 			    } else {
683fcf3ce44SJohn Forte 				(void) printf("\tDD Name: %ws\n", wc_name);
684fcf3ce44SJohn Forte 				h_printed = 1;
685fcf3ce44SJohn Forte 			    }
686fcf3ce44SJohn Forte 			    xmlFree(ddname);
687fcf3ce44SJohn Forte 			} else {
688fcf3ce44SJohn Forte 			    if (h_printed) {
689fcf3ce44SJohn Forte 				(void) printf("\t         %s\n", "-");
690fcf3ce44SJohn Forte 			    } else {
691fcf3ce44SJohn Forte 				(void) printf("\tDD Name: %s\n", "-");
692fcf3ce44SJohn Forte 				h_printed = 1;
693fcf3ce44SJohn Forte 			    }
694fcf3ce44SJohn Forte 			}
695fcf3ce44SJohn Forte 		    }
696fcf3ce44SJohn Forte 		    m_flag = 0;
697fcf3ce44SJohn Forte 		    (void) xmlTextReaderRead(reader);
698fcf3ce44SJohn Forte 		}
699fcf3ce44SJohn Forte 	    break;
700fcf3ce44SJohn Forte 	case dd_to_node:
701fcf3ce44SJohn Forte 		/* process the DiscoveryDoamin elements */
702fcf3ce44SJohn Forte 	    while (reader = lookup_next_matching_elem(reader, &m_flag,
703fcf3ce44SJohn Forte 		    DDOBJECTMEMBER, ISNSRESPONSE)) {
704fcf3ce44SJohn Forte 		if (m_flag == END_READER_MATCH) {
705fcf3ce44SJohn Forte 		    (void) xmlTextReaderNext(reader);
706fcf3ce44SJohn Forte 		    break;
707fcf3ce44SJohn Forte 		} else if (m_flag == READER_MATCH) {
708fcf3ce44SJohn Forte 		    if ((nodename = (xmlTextReaderGetAttribute(reader,
709fcf3ce44SJohn Forte 			    (const xmlChar *)NODENAMEATTR))) != NULL) {
710fcf3ce44SJohn Forte 			if (mbstowcs(wc_name, (const char *)nodename,
711fcf3ce44SJohn Forte 			    ISNS_MAX_NAME_LEN) == (size_t)-1) {
712fcf3ce44SJohn Forte 			    (void) wcscpy(wc_name, L"-");
713fcf3ce44SJohn Forte 			}
714fcf3ce44SJohn Forte 			(void) printf("\tiSCSI name: %ws\n", wc_name);
715fcf3ce44SJohn Forte 			xmlFree(nodename);
716fcf3ce44SJohn Forte 		    } else {
717fcf3ce44SJohn Forte 			(void) printf("\tiSCSI name: %s\n", "-");
718fcf3ce44SJohn Forte 		    }
719fcf3ce44SJohn Forte 		}
720fcf3ce44SJohn Forte 		m_flag = 0;
721fcf3ce44SJohn Forte 		(void) xmlTextReaderRead(reader);
722fcf3ce44SJohn Forte 	    }
723fcf3ce44SJohn Forte 	    break;
724fcf3ce44SJohn Forte 	case dd_to_ddset:
725fcf3ce44SJohn Forte 		/* process the DiscoveryDoaminSet elements */
726fcf3ce44SJohn Forte 	    while (reader = lookup_next_matching_elem(reader, &m_flag,
727fcf3ce44SJohn Forte 		    DDSETOBJECTMEMBER, ISNSRESPONSE)) {
728fcf3ce44SJohn Forte 		if (m_flag == END_READER_MATCH) {
729fcf3ce44SJohn Forte 		    (void) xmlTextReaderNext(reader);
730fcf3ce44SJohn Forte 		    break;
731fcf3ce44SJohn Forte 		} else if (m_flag == READER_MATCH) {
732fcf3ce44SJohn Forte 		    if ((ddsname = (xmlTextReaderGetAttribute(reader,
733fcf3ce44SJohn Forte 			(const xmlChar *)DDSETNAMEATTR))) != NULL) {
734fcf3ce44SJohn Forte 			if (mbstowcs(wc_name, (const char *)ddsname,
735fcf3ce44SJohn Forte 			    ISNS_MAX_NAME_LEN) == (size_t)-1) {
736fcf3ce44SJohn Forte 			    (void) wcscpy(wc_name, L"-");
737fcf3ce44SJohn Forte 			}
738fcf3ce44SJohn Forte 			if (h_printed) {
739fcf3ce44SJohn Forte 			    (void) printf("\t           %ws\n", wc_name);
740fcf3ce44SJohn Forte 			} else {
741fcf3ce44SJohn Forte 			    (void) printf("\tDD set(s): %ws\n", wc_name);
742fcf3ce44SJohn Forte 			    h_printed = 1;
743fcf3ce44SJohn Forte 			}
744fcf3ce44SJohn Forte 			xmlFree(ddsname);
745fcf3ce44SJohn Forte 		    } else {
746fcf3ce44SJohn Forte 			(void) printf("\tDD set(s): %s\n", "-");
747fcf3ce44SJohn Forte 		    }
748fcf3ce44SJohn Forte 		}
749fcf3ce44SJohn Forte 		m_flag = 0;
750fcf3ce44SJohn Forte 		(void) xmlTextReaderRead(reader);
751fcf3ce44SJohn Forte 	    }
752fcf3ce44SJohn Forte 	    break;
753fcf3ce44SJohn Forte 	case ddset_to_dd:
754fcf3ce44SJohn Forte 		/* process the DiscoveryDoaminSet elements */
755fcf3ce44SJohn Forte 	    while (reader = lookup_next_matching_elem(reader, &m_flag,
756fcf3ce44SJohn Forte 		    DDSETOBJECTMEMBER, ISNSRESPONSE)) {
757fcf3ce44SJohn Forte 		if (m_flag == END_READER_MATCH) {
758fcf3ce44SJohn Forte 		    (void) xmlTextReaderNext(reader);
759fcf3ce44SJohn Forte 		    break;
760fcf3ce44SJohn Forte 		} else if (m_flag == READER_MATCH) {
761fcf3ce44SJohn Forte 			if ((ddname = (xmlTextReaderGetAttribute(reader,
762fcf3ce44SJohn Forte 			    (const xmlChar *)DDNAMEATTR))) != NULL) {
763fcf3ce44SJohn Forte 			    if (mbstowcs(wc_name, (const char *)ddname,
764fcf3ce44SJohn Forte 				ISNS_MAX_NAME_LEN) == (size_t)-1) {
765fcf3ce44SJohn Forte 				(void) wcscpy(wc_name, L"-");
766fcf3ce44SJohn Forte 			    }
767fcf3ce44SJohn Forte 			    (void) printf("\tDD Name: %ws\n", wc_name);
768fcf3ce44SJohn Forte 			    xmlFree(ddname);
769fcf3ce44SJohn Forte 			} else {
770fcf3ce44SJohn Forte 			    (void) printf("\tDD Name: %s\n", "-");
771fcf3ce44SJohn Forte 			}
772fcf3ce44SJohn Forte 		}
773fcf3ce44SJohn Forte 		m_flag = 0;
774fcf3ce44SJohn Forte 		(void) xmlTextReaderRead(reader);
775fcf3ce44SJohn Forte 	    }
776fcf3ce44SJohn Forte 	    break;
777fcf3ce44SJohn Forte 	default:
778fcf3ce44SJohn Forte 	    (void) xmlTextReaderClose(reader);
779fcf3ce44SJohn Forte 	    (void) xmlFreeTextReader(reader);
780fcf3ce44SJohn Forte 	    return (UNKNOWN);
781fcf3ce44SJohn Forte 	}
782fcf3ce44SJohn Forte 
783fcf3ce44SJohn Forte 	if (status == PARTIAL_SUCCESS) {
784fcf3ce44SJohn Forte 	    (void) fprintf(stderr, "%s\n",
785fcf3ce44SJohn Forte 		getTextMessage(ERROR_PARTIAL_SUCCESS));
786fcf3ce44SJohn Forte 	}
787fcf3ce44SJohn Forte 	(void) xmlTextReaderClose(reader);
788fcf3ce44SJohn Forte 	(void) xmlFreeTextReader(reader);
789fcf3ce44SJohn Forte 	return (status);
790fcf3ce44SJohn Forte }
791fcf3ce44SJohn Forte 
792fcf3ce44SJohn Forte /*
793fcf3ce44SJohn Forte  * ****************************************************************************
794fcf3ce44SJohn Forte  *
795fcf3ce44SJohn Forte  * process_get_response :
796fcf3ce44SJohn Forte  *	display data from the get response doc based on flag.
797fcf3ce44SJohn Forte  *
798fcf3ce44SJohn Forte  * obj		- object type
799fcf3ce44SJohn Forte  * doc		- docuemet to process
800fcf3ce44SJohn Forte  * flag		- options from the subcommand
801fcf3ce44SJohn Forte  *
802fcf3ce44SJohn Forte  * ****************************************************************************
803fcf3ce44SJohn Forte  */
804fcf3ce44SJohn Forte static int
805fcf3ce44SJohn Forte process_get_response(object_type obj, xmlChar *doc, uint32_t flag)
806fcf3ce44SJohn Forte {
807fcf3ce44SJohn Forte 	xmlTextReaderPtr reader;
808fcf3ce44SJohn Forte 	int m_flag = 0, ret = 0, status;
809fcf3ce44SJohn Forte 	xmlChar *name = NULL;
810fcf3ce44SJohn Forte 	wchar_t wc_name[ISNS_MAX_NAME_LEN];
811fcf3ce44SJohn Forte 	int tag_printed = 0;
812fcf3ce44SJohn Forte 
813fcf3ce44SJohn Forte 	if ((reader = (xmlTextReaderPtr)xmlReaderForMemory((const char *)doc,
814fcf3ce44SJohn Forte 	    xmlStrlen(doc), NULL, NULL, 0)) == NULL) {
815fcf3ce44SJohn Forte 		return (ERROR_XML_READER_NULL);
816fcf3ce44SJohn Forte 	}
817fcf3ce44SJohn Forte 
818fcf3ce44SJohn Forte 	/* if status is 0, continue on.  Otherwise return an error. */
819fcf3ce44SJohn Forte 	if (reader = lookup_next_matching_elem(reader, &m_flag, STATUSELEMENT,
820fcf3ce44SJohn Forte 	    RESULTELEMENT)) {
821fcf3ce44SJohn Forte 	    if (m_flag == READER_MATCH) {
822fcf3ce44SJohn Forte 		if (xmlTextReaderRead(reader) == 1) {
823fcf3ce44SJohn Forte 		    status =
824fcf3ce44SJohn Forte 		    atoi((const char *)xmlTextReaderConstValue(reader));
825fcf3ce44SJohn Forte 		    if ((status != 0) && (status != PARTIAL_SUCCESS)) {
826fcf3ce44SJohn Forte 			print_error_status(status, obj, reader);
827fcf3ce44SJohn Forte 			(void) xmlTextReaderClose(reader);
828fcf3ce44SJohn Forte 			(void) xmlFreeTextReader(reader);
829fcf3ce44SJohn Forte 			return (status);
830fcf3ce44SJohn Forte 		    }
831fcf3ce44SJohn Forte 		} else {
832fcf3ce44SJohn Forte 		    (void) xmlTextReaderClose(reader);
833fcf3ce44SJohn Forte 		    (void) xmlFreeTextReader(reader);
834fcf3ce44SJohn Forte 		    return (ERROR_XML_STATUS_ELEM_NOT_FOUND);
835fcf3ce44SJohn Forte 		}
836fcf3ce44SJohn Forte 	    } else {
837fcf3ce44SJohn Forte 		(void) xmlTextReaderClose(reader);
838fcf3ce44SJohn Forte 		(void) xmlFreeTextReader(reader);
839fcf3ce44SJohn Forte 		return (ERROR_XML_STATUS_ELEM_NOT_FOUND);
840fcf3ce44SJohn Forte 	    }
841fcf3ce44SJohn Forte 	} else {
842fcf3ce44SJohn Forte 	    return (ERROR_XML_READER_NULL);
843fcf3ce44SJohn Forte 	}
844fcf3ce44SJohn Forte 
845fcf3ce44SJohn Forte 	m_flag = 0;
846fcf3ce44SJohn Forte 
847fcf3ce44SJohn Forte 	switch (obj) {
848fcf3ce44SJohn Forte 	    case Node:
849fcf3ce44SJohn Forte 		/* process the node elements */
850fcf3ce44SJohn Forte 		while (reader = lookup_next_matching_elem(reader, &m_flag,
851fcf3ce44SJohn Forte 		    NODEOBJECT, ISNSRESPONSE)) {
852fcf3ce44SJohn Forte 		    if (m_flag == END_READER_MATCH) {
853fcf3ce44SJohn Forte 			break;
854fcf3ce44SJohn Forte 		    }
855fcf3ce44SJohn Forte 
856fcf3ce44SJohn Forte 		    /* check the type */
857fcf3ce44SJohn Forte 		    if ((xmlTextReaderMoveToAttribute(reader,
858fcf3ce44SJohn Forte 			(const xmlChar *)TYPEATTR)) == 1) {
859fcf3ce44SJohn Forte 			if (((flag & TARGET_ONLY) == TARGET_ONLY) &&
860fcf3ce44SJohn Forte 			    (XMLNCMPVAL(reader, TARGETTYPE) != 0)) {
861fcf3ce44SJohn Forte 			    /* move to next node object. */
862fcf3ce44SJohn Forte 			    (void) xmlTextReaderMoveToElement(reader);
863fcf3ce44SJohn Forte 			    (void) xmlTextReaderNext(reader);
864fcf3ce44SJohn Forte 			    continue;
865fcf3ce44SJohn Forte 			}
866fcf3ce44SJohn Forte 			if (((flag & INITIATOR_ONLY) == INITIATOR_ONLY) &&
867fcf3ce44SJohn Forte 			    (XMLNCMPVAL(reader, INITIATORTYPE) != 0)) {
868fcf3ce44SJohn Forte 			    /* move to next node object. */
869fcf3ce44SJohn Forte 			    (void) xmlTextReaderMoveToElement(reader);
870fcf3ce44SJohn Forte 			    (void) xmlTextReaderNext(reader);
871fcf3ce44SJohn Forte 			    continue;
872fcf3ce44SJohn Forte 			}
873fcf3ce44SJohn Forte 		    } else {
874fcf3ce44SJohn Forte 			ret = ERROR_XML_TYPE_ATTR_NOT_FOUND;
875fcf3ce44SJohn Forte 			goto out;
876fcf3ce44SJohn Forte 		    }
877fcf3ce44SJohn Forte 
878fcf3ce44SJohn Forte 		    if (((xmlTextReaderMoveToAttribute(reader,
879fcf3ce44SJohn Forte 			(const xmlChar *)NAMEATTR)) == 1) &&
880fcf3ce44SJohn Forte 			(const char *)xmlTextReaderConstValue(reader)) {
881fcf3ce44SJohn Forte 			if (mbstowcs(wc_name,
882fcf3ce44SJohn Forte 			    (const char *)xmlTextReaderConstValue(reader),
883fcf3ce44SJohn Forte 			    ISNS_MAX_NAME_LEN) == (size_t)-1) {
884fcf3ce44SJohn Forte 			    (void) wcscpy(wc_name, L"-");
885fcf3ce44SJohn Forte 			}
886fcf3ce44SJohn Forte 			if ((flag & VERBOSE) == VERBOSE) {
887fcf3ce44SJohn Forte 			    name = xmlTextReaderValue(reader);
888fcf3ce44SJohn Forte 			    (void) printf("iSCSI Name: %ws\n", wc_name);
889fcf3ce44SJohn Forte 			} else {
890fcf3ce44SJohn Forte 			    (void) printf("iSCSI Name: %ws\n", wc_name);
891fcf3ce44SJohn Forte 			}
892fcf3ce44SJohn Forte 		    } else {
893fcf3ce44SJohn Forte 			XML_SFREE(name);
894fcf3ce44SJohn Forte 			ret = ERROR_XML_TYPE_ATTR_NOT_FOUND;
895fcf3ce44SJohn Forte 			goto out;
896fcf3ce44SJohn Forte 		    }
897fcf3ce44SJohn Forte 		    if ((xmlTextReaderMoveToAttribute(reader,
898fcf3ce44SJohn Forte 			(const xmlChar *)ALIASATTR)) == 1) {
899fcf3ce44SJohn Forte 			if (xmlStrcmp(xmlTextReaderConstValue(reader),
900fcf3ce44SJohn Forte 			    (xmlChar *)"") == 0) {
901fcf3ce44SJohn Forte 			    (void) printf("\tAlias: %s\n", "-");
902fcf3ce44SJohn Forte 			} else {
903fcf3ce44SJohn Forte 			    if (mbstowcs(wc_name,
904fcf3ce44SJohn Forte 				(const char *)xmlTextReaderConstValue(reader),
905fcf3ce44SJohn Forte 				ISNS_MAX_NAME_LEN) == (size_t)-1) {
906fcf3ce44SJohn Forte 				(void) wcscpy(wc_name, L"-");
907fcf3ce44SJohn Forte 			    }
908fcf3ce44SJohn Forte 			    (void) printf("\tAlias: %ws\n", wc_name);
909fcf3ce44SJohn Forte 			}
910fcf3ce44SJohn Forte 		    }
911fcf3ce44SJohn Forte 
912fcf3ce44SJohn Forte 		    /* type attribute exist based on the previous checking. */
913fcf3ce44SJohn Forte 		    (void) xmlTextReaderMoveToAttribute(reader,
914fcf3ce44SJohn Forte 			(const xmlChar *)TYPEATTR);
915fcf3ce44SJohn Forte 		    (void) printf("\tType: %s\n",
916fcf3ce44SJohn Forte 			(const char *)xmlTextReaderConstValue(reader) ?
917fcf3ce44SJohn Forte 			(const char *)xmlTextReaderConstValue(reader) : "-");
918fcf3ce44SJohn Forte 
919fcf3ce44SJohn Forte 		    if ((flag & VERBOSE) == VERBOSE) {
920fcf3ce44SJohn Forte 			/* print more details */
921fcf3ce44SJohn Forte 			m_flag = 0;
922fcf3ce44SJohn Forte 			/*
923fcf3ce44SJohn Forte 			 * No details for deregistered node.
924fcf3ce44SJohn Forte 			 * skip to next isns object.
925fcf3ce44SJohn Forte 			 */
926fcf3ce44SJohn Forte 			if ((reader = lookup_next_matching_elem(reader,
927fcf3ce44SJohn Forte 			    &m_flag, ENTITYID, ISNSOBJECT))) {
928fcf3ce44SJohn Forte 			    if (m_flag == READER_MATCH) {
929fcf3ce44SJohn Forte 				/* move to entity id value. */
930fcf3ce44SJohn Forte 				if ((xmlTextReaderRead(reader) == 1) &&
931fcf3ce44SJohn Forte 				    xmlTextReaderConstValue(reader)) {
932fcf3ce44SJohn Forte 				    if (mbstowcs(wc_name,
933fcf3ce44SJohn Forte 					(const char *)
934fcf3ce44SJohn Forte 					xmlTextReaderConstValue(reader),
935fcf3ce44SJohn Forte 					ISNS_MAX_NAME_LEN) == (size_t)-1) {
936fcf3ce44SJohn Forte 					(void) wcscpy(wc_name,
937fcf3ce44SJohn Forte 					    L"-");
938fcf3ce44SJohn Forte 				    }
939fcf3ce44SJohn Forte 				    (void) printf("\tNetwork Entity: %ws\n",
940fcf3ce44SJohn Forte 					wc_name);
941fcf3ce44SJohn Forte 				} else {
942fcf3ce44SJohn Forte 				    (void) printf("\tNework Entity: -\n");
943fcf3ce44SJohn Forte 				}
944fcf3ce44SJohn Forte 			    } else if (m_flag == END_READER_MATCH) {
945fcf3ce44SJohn Forte 				(void) xmlTextReaderRead(reader);
946fcf3ce44SJohn Forte 				XML_SFREE(name);
947fcf3ce44SJohn Forte 				continue;
948fcf3ce44SJohn Forte 			    }
949fcf3ce44SJohn Forte 			}
950fcf3ce44SJohn Forte 
951fcf3ce44SJohn Forte 			/* print  portal info */
952fcf3ce44SJohn Forte 			m_flag = 0;
953fcf3ce44SJohn Forte 			while ((reader = lookup_next_matching_elem(reader,
954fcf3ce44SJohn Forte 			    &m_flag, IPADDR, NODEOBJECT))) {
955fcf3ce44SJohn Forte 			    if (m_flag == END_READER_MATCH) {
956fcf3ce44SJohn Forte 				(void) xmlTextReaderRead(reader);
957fcf3ce44SJohn Forte 				break;
958fcf3ce44SJohn Forte 			    }
959fcf3ce44SJohn Forte 			    /* move to the value of IP addr. */
960fcf3ce44SJohn Forte 			    if ((xmlTextReaderRead(reader) == 1) &&
961fcf3ce44SJohn Forte 				xmlTextReaderConstValue(reader)) {
962fcf3ce44SJohn Forte 				(void) printf("\tPortal: %s",
963fcf3ce44SJohn Forte 				xmlTextReaderConstValue(reader));
964fcf3ce44SJohn Forte 				/* get port number */
965fcf3ce44SJohn Forte 				m_flag = 0;
966fcf3ce44SJohn Forte 				if (reader = lookup_next_matching_elem(reader,
967fcf3ce44SJohn Forte 				    &m_flag, PORTNUMBER, UDPTCPPORT)) {
968fcf3ce44SJohn Forte 				    if ((xmlTextReaderRead(reader) == 1) &&
969fcf3ce44SJohn Forte 					xmlTextReaderConstValue(reader)) {
970fcf3ce44SJohn Forte 				    (void) printf(":%d\n",
971fcf3ce44SJohn Forte 					atoi((const char *)
972fcf3ce44SJohn Forte 					xmlTextReaderConstValue(reader)));
973fcf3ce44SJohn Forte 				    } else {
974fcf3ce44SJohn Forte 					(void) printf(":-\n");
975fcf3ce44SJohn Forte 				    }
976fcf3ce44SJohn Forte 				}
977fcf3ce44SJohn Forte 				m_flag = 0;
978fcf3ce44SJohn Forte 				if (reader = lookup_next_matching_elem(reader,
979fcf3ce44SJohn Forte 				    &m_flag, GROUPTAG, GROUPTAG)) {
980fcf3ce44SJohn Forte 				    if ((xmlTextReaderRead(reader) == 1) &&
981fcf3ce44SJohn Forte 					xmlTextReaderConstValue(reader)) {
982fcf3ce44SJohn Forte 				    (void) printf("\t\tPortal Group: %s\n",
983fcf3ce44SJohn Forte 					xmlTextReaderConstValue(reader));
984fcf3ce44SJohn Forte 				    } else {
985fcf3ce44SJohn Forte 					(void) printf(":-\n");
986fcf3ce44SJohn Forte 				    }
987fcf3ce44SJohn Forte 				}
988fcf3ce44SJohn Forte 			    }
989fcf3ce44SJohn Forte 			} /* Portal end */
990fcf3ce44SJohn Forte 			if ((ret = handle_association_info(name,
991fcf3ce44SJohn Forte 			    node_to_dd)) != 0) {
992fcf3ce44SJohn Forte 			    XML_SFREE(name);
993fcf3ce44SJohn Forte 			    goto out;
994fcf3ce44SJohn Forte 			}
995fcf3ce44SJohn Forte 		    } /* verbose end */
996fcf3ce44SJohn Forte 		    XML_SFREE(name);
997fcf3ce44SJohn Forte 		    (void) xmlTextReaderRead(reader);
998fcf3ce44SJohn Forte 		    m_flag = 0;
999fcf3ce44SJohn Forte 		} /* end for node while */
1000fcf3ce44SJohn Forte 		break;
1001fcf3ce44SJohn Forte 	    case DiscoveryDomain:
1002fcf3ce44SJohn Forte 		/* process the DiscoveryDoamin elements */
1003fcf3ce44SJohn Forte 		while (reader = lookup_next_matching_elem(reader, &m_flag,
1004fcf3ce44SJohn Forte 		    DDOBJECT, ISNSRESPONSE)) {
1005fcf3ce44SJohn Forte 		    if (m_flag == END_READER_MATCH) {
1006fcf3ce44SJohn Forte 			(void) xmlTextReaderNext(reader);
1007fcf3ce44SJohn Forte 			break;
1008fcf3ce44SJohn Forte 		    }
1009fcf3ce44SJohn Forte 
1010fcf3ce44SJohn Forte 		    if (((xmlTextReaderMoveToAttribute(reader,
1011fcf3ce44SJohn Forte 			(const xmlChar *)NAMEATTR)) == 1) &&
1012fcf3ce44SJohn Forte 			(name = xmlTextReaderValue(reader))) {
1013fcf3ce44SJohn Forte 			if (mbstowcs(wc_name, (const char *)name,
1014fcf3ce44SJohn Forte 			    ISNS_MAX_NAME_LEN) == (size_t)-1) {
1015fcf3ce44SJohn Forte 			    (void) wcscpy(wc_name, L"-");
1016fcf3ce44SJohn Forte 			}
1017fcf3ce44SJohn Forte 			(void) printf("DD name: %ws\n", wc_name);
1018fcf3ce44SJohn Forte 		    } else {
1019fcf3ce44SJohn Forte 			ret = ERROR_XML_NAME_ATTR_NOT_FOUND;
1020fcf3ce44SJohn Forte 			XML_SFREE(name);
1021fcf3ce44SJohn Forte 			goto out;
1022fcf3ce44SJohn Forte 		    }
1023fcf3ce44SJohn Forte 		    if ((ret = handle_association_info(name, dd_to_ddset)) !=
1024fcf3ce44SJohn Forte 			0) {
1025fcf3ce44SJohn Forte 			XML_SFREE(name);
1026fcf3ce44SJohn Forte 			goto out;
1027fcf3ce44SJohn Forte 		    }
1028fcf3ce44SJohn Forte 		    /* handle verbose */
1029fcf3ce44SJohn Forte 		    if ((flag & VERBOSE) == VERBOSE) {
1030fcf3ce44SJohn Forte 			if ((ret = handle_association_info(name,
1031fcf3ce44SJohn Forte 			    dd_to_node)) != 0) {
1032fcf3ce44SJohn Forte 			    XML_SFREE(name);
1033fcf3ce44SJohn Forte 			    goto out;
1034fcf3ce44SJohn Forte 			}
1035fcf3ce44SJohn Forte 		    }
1036fcf3ce44SJohn Forte 		    XML_SFREE(name);
1037fcf3ce44SJohn Forte 		    m_flag = 0;
1038fcf3ce44SJohn Forte 		}
1039fcf3ce44SJohn Forte 		break;
1040fcf3ce44SJohn Forte 	    case DiscoveryDomainSet:
1041fcf3ce44SJohn Forte 		/* process the DiscoveryDoaminSet elements */
1042fcf3ce44SJohn Forte 		while (reader = lookup_next_matching_elem(reader, &m_flag,
1043fcf3ce44SJohn Forte 		    DDSETOBJECT, ISNSRESPONSE)) {
1044fcf3ce44SJohn Forte 		    if (m_flag == END_READER_MATCH) {
1045fcf3ce44SJohn Forte 			(void) xmlTextReaderNext(reader);
1046fcf3ce44SJohn Forte 			break;
1047fcf3ce44SJohn Forte 		    }
1048fcf3ce44SJohn Forte 
1049fcf3ce44SJohn Forte 		    if (((xmlTextReaderMoveToAttribute(reader,
1050fcf3ce44SJohn Forte 			(const xmlChar *)NAMEATTR)) == 1) &&
1051fcf3ce44SJohn Forte 			(const char *)xmlTextReaderConstValue(reader)) {
1052fcf3ce44SJohn Forte 			if (mbstowcs(wc_name,
1053fcf3ce44SJohn Forte 			    (const char *)xmlTextReaderConstValue(reader),
1054fcf3ce44SJohn Forte 			    ISNS_MAX_NAME_LEN) == (size_t)-1) {
1055fcf3ce44SJohn Forte 			    (void) wcscpy(wc_name, L"-");
1056fcf3ce44SJohn Forte 			}
1057fcf3ce44SJohn Forte 			if ((flag & VERBOSE) == VERBOSE) {
1058fcf3ce44SJohn Forte 			    name = xmlTextReaderValue(reader);
1059fcf3ce44SJohn Forte 			    (void) printf("DD Set name: %ws\n", wc_name);
1060fcf3ce44SJohn Forte 			} else {
1061fcf3ce44SJohn Forte 			    (void) printf("DD Set name: %ws\n", wc_name);
1062fcf3ce44SJohn Forte 			}
1063fcf3ce44SJohn Forte 		    } else {
1064fcf3ce44SJohn Forte 			ret = ERROR_XML_NAME_ATTR_NOT_FOUND;
1065fcf3ce44SJohn Forte 			XML_SFREE(name);
1066fcf3ce44SJohn Forte 			goto out;
1067fcf3ce44SJohn Forte 		    }
1068fcf3ce44SJohn Forte 		    m_flag = 0;
1069fcf3ce44SJohn Forte 		    if ((reader = lookup_next_matching_elem(reader,
1070fcf3ce44SJohn Forte 			&m_flag, ENABLEDELEM, ISNSOBJECT))) {
1071fcf3ce44SJohn Forte 			if (m_flag == READER_MATCH) {
1072fcf3ce44SJohn Forte 			    /* move to entity id value. */
1073fcf3ce44SJohn Forte 			    if ((xmlTextReaderRead(reader) == 1) &&
1074fcf3ce44SJohn Forte 				(XMLNCMPVAL(reader, XMLTRUE) == 0)) {
1075fcf3ce44SJohn Forte 				(void) printf("\tState: Enabled\n");
1076fcf3ce44SJohn Forte 			    } else {
1077fcf3ce44SJohn Forte 				(void) printf("\tState: Disabled\n");
1078fcf3ce44SJohn Forte 			    }
1079fcf3ce44SJohn Forte 			} else if (m_flag == END_READER_MATCH) {
1080fcf3ce44SJohn Forte 			    (void) xmlTextReaderRead(reader);
1081fcf3ce44SJohn Forte 			}
1082fcf3ce44SJohn Forte 		    }
1083fcf3ce44SJohn Forte 
1084fcf3ce44SJohn Forte 		    /* handle verbose */
1085fcf3ce44SJohn Forte 		    if ((flag & VERBOSE) == VERBOSE) {
1086fcf3ce44SJohn Forte 			if ((ret = handle_association_info(name,
1087fcf3ce44SJohn Forte 			    ddset_to_dd)) != 0) {
1088fcf3ce44SJohn Forte 			    XML_SFREE(name);
1089fcf3ce44SJohn Forte 			    goto out;
1090fcf3ce44SJohn Forte 			}
1091fcf3ce44SJohn Forte 		    }
1092fcf3ce44SJohn Forte 		    XML_SFREE(name);
1093fcf3ce44SJohn Forte 		    m_flag = 0;
1094fcf3ce44SJohn Forte 		}
1095fcf3ce44SJohn Forte 		break;
1096fcf3ce44SJohn Forte 	    case ServerConfig:
1097fcf3ce44SJohn Forte 		/* process the DiscoveryDoaminSet elements */
1098fcf3ce44SJohn Forte 		m_flag = 0;
1099fcf3ce44SJohn Forte 		reader = lookup_next_matching_elem(reader, &m_flag,
1100fcf3ce44SJohn Forte 		    ISNSSERVER, ISNSRESPONSE);
1101fcf3ce44SJohn Forte 		if (m_flag == END_READER_MATCH) {
1102fcf3ce44SJohn Forte 		    ret = ERROR_XML_ISNSSERVER_ELEM_NOT_FOUND;
1103fcf3ce44SJohn Forte 		    goto out;
1104fcf3ce44SJohn Forte 		}
1105fcf3ce44SJohn Forte 		m_flag = 0;
1106fcf3ce44SJohn Forte 		if ((reader = lookup_next_matching_elem(reader,
1107fcf3ce44SJohn Forte 		    &m_flag, DATASTORELOCATION, ISNSRESPONSE))) {
1108fcf3ce44SJohn Forte 		    if (m_flag == READER_MATCH) {
1109fcf3ce44SJohn Forte 			(void) xmlTextReaderRead(reader);
1110fcf3ce44SJohn Forte 			(void) printf("\tData Store Location: %s\n",
1111fcf3ce44SJohn Forte 			(const char *)xmlTextReaderConstValue(reader) ?
1112fcf3ce44SJohn Forte 			(const char *)xmlTextReaderConstValue(reader) : "-");
1113fcf3ce44SJohn Forte 		    }
1114fcf3ce44SJohn Forte 		}
1115fcf3ce44SJohn Forte 		m_flag = 0;
1116fcf3ce44SJohn Forte 		if ((reader = lookup_next_matching_elem(reader,
1117fcf3ce44SJohn Forte 		    &m_flag, ESIRETRYTHRESHOLD, ISNSRESPONSE))) {
1118fcf3ce44SJohn Forte 		    if (m_flag == READER_MATCH) {
1119fcf3ce44SJohn Forte 			(void) xmlTextReaderRead(reader);
1120fcf3ce44SJohn Forte 			(void) printf("\tEntity Status Inquiry Non-Response ");
1121fcf3ce44SJohn Forte 			(void) printf("Threshold: %d\n",
1122fcf3ce44SJohn Forte 			xmlTextReaderConstValue(reader) ?
1123fcf3ce44SJohn Forte 			atoi((const char *)xmlTextReaderConstValue(reader))
1124fcf3ce44SJohn Forte 			: 0);
1125fcf3ce44SJohn Forte 		    }
1126fcf3ce44SJohn Forte 		}
1127fcf3ce44SJohn Forte 		m_flag = 0;
1128fcf3ce44SJohn Forte 		if ((reader = lookup_next_matching_elem(reader,
1129fcf3ce44SJohn Forte 		    &m_flag, MANAGEMENTSCNENABLED, ISNSRESPONSE))) {
1130fcf3ce44SJohn Forte 		    if (m_flag == READER_MATCH) {
1131fcf3ce44SJohn Forte 			(void) xmlTextReaderRead(reader);
1132fcf3ce44SJohn Forte 			(void) printf("\tManagement SCN Enabled: %s\n",
1133fcf3ce44SJohn Forte 			(XMLNCMPVAL(reader, XMLTRUE) == 0) ?
1134fcf3ce44SJohn Forte 			"yes" : "no");
1135fcf3ce44SJohn Forte 		    }
1136fcf3ce44SJohn Forte 		}
1137fcf3ce44SJohn Forte 		m_flag = 0;
1138fcf3ce44SJohn Forte 		while ((reader = lookup_next_matching_elem(reader,
1139fcf3ce44SJohn Forte 		    &m_flag, CONTROLNODENAME, ISNSSERVER))) {
1140fcf3ce44SJohn Forte 		    if (m_flag == READER_MATCH) {
1141fcf3ce44SJohn Forte 			if (!xmlTextReaderIsEmptyElement(reader)) {
1142fcf3ce44SJohn Forte 			    (void) xmlTextReaderRead(reader);
1143fcf3ce44SJohn Forte 			    if (mbstowcs(wc_name,
1144fcf3ce44SJohn Forte 				(const char *)xmlTextReaderConstValue(reader),
1145fcf3ce44SJohn Forte 				ISNS_MAX_NAME_LEN) == (size_t)-1) {
1146fcf3ce44SJohn Forte 				(void) wcscpy(wc_name, L"-");
1147fcf3ce44SJohn Forte 			    }
1148fcf3ce44SJohn Forte 			    if (tag_printed) {
1149fcf3ce44SJohn Forte 				if (xmlTextReaderConstValue(reader)) {
1150fcf3ce44SJohn Forte 				    if (mbstowcs(wc_name,
1151fcf3ce44SJohn Forte 					(const char *)
1152fcf3ce44SJohn Forte 					xmlTextReaderConstValue(reader),
1153fcf3ce44SJohn Forte 					ISNS_MAX_NAME_LEN) == (size_t)-1) {
1154fcf3ce44SJohn Forte 					(void) wcscpy(wc_name, L"-");
1155fcf3ce44SJohn Forte 				    }
1156fcf3ce44SJohn Forte 				    (void) printf(
1157fcf3ce44SJohn Forte 				    "\t                               %ws\n",
1158fcf3ce44SJohn Forte 					wc_name);
1159fcf3ce44SJohn Forte 				} else {
1160fcf3ce44SJohn Forte 				    (void) printf(
1161fcf3ce44SJohn Forte 				    "\t                               %s\n",
1162fcf3ce44SJohn Forte 				    "-");
1163fcf3ce44SJohn Forte 				}
1164fcf3ce44SJohn Forte 			    } else {
1165fcf3ce44SJohn Forte 				if (xmlTextReaderConstValue(reader)) {
1166fcf3ce44SJohn Forte 				    if (mbstowcs(wc_name,
1167fcf3ce44SJohn Forte 					(const char *)
1168fcf3ce44SJohn Forte 					xmlTextReaderConstValue(reader),
1169fcf3ce44SJohn Forte 					ISNS_MAX_NAME_LEN) == (size_t)-1) {
1170fcf3ce44SJohn Forte 					(void) wcscpy(wc_name, L"-");
1171fcf3ce44SJohn Forte 				    }
1172fcf3ce44SJohn Forte 				    (void) printf(
1173fcf3ce44SJohn Forte 				    "\tAuthorized Control Node Names: %ws\n",
1174fcf3ce44SJohn Forte 					wc_name);
1175fcf3ce44SJohn Forte 				} else {
1176fcf3ce44SJohn Forte 				    (void) printf(
1177fcf3ce44SJohn Forte 				    "\tAuthorized Control Node Names: %s\n",
1178fcf3ce44SJohn Forte 				    "-");
1179fcf3ce44SJohn Forte 				}
1180fcf3ce44SJohn Forte 				tag_printed = 1;
1181fcf3ce44SJohn Forte 			    }
1182fcf3ce44SJohn Forte 			} else {
1183fcf3ce44SJohn Forte 			    (void) printf(
1184fcf3ce44SJohn Forte 				"\tAuthorized Control Node Names: %s\n", "-");
1185fcf3ce44SJohn Forte 			    break;
1186fcf3ce44SJohn Forte 			}
1187fcf3ce44SJohn Forte 		    } else {
1188fcf3ce44SJohn Forte 			break;
1189fcf3ce44SJohn Forte 		    }
1190fcf3ce44SJohn Forte 		}
1191fcf3ce44SJohn Forte 		break;
1192fcf3ce44SJohn Forte 	    default:
1193fcf3ce44SJohn Forte 		ret = UNKNOWN;
1194fcf3ce44SJohn Forte 	}
1195fcf3ce44SJohn Forte 
1196fcf3ce44SJohn Forte out:
1197fcf3ce44SJohn Forte 	(void) xmlTextReaderClose(reader);
1198fcf3ce44SJohn Forte 	(void) xmlFreeTextReader(reader);
1199fcf3ce44SJohn Forte 	if (status == PARTIAL_SUCCESS) {
1200fcf3ce44SJohn Forte 	    (void) fprintf(stderr, "%s\n",
1201fcf3ce44SJohn Forte 		getTextMessage(ERROR_PARTIAL_SUCCESS));
1202fcf3ce44SJohn Forte 	    if (ret == 0) ret = status;
1203fcf3ce44SJohn Forte 	}
1204fcf3ce44SJohn Forte 	return (ret);
1205fcf3ce44SJohn Forte 
1206fcf3ce44SJohn Forte }
1207fcf3ce44SJohn Forte 
1208fcf3ce44SJohn Forte /*
1209fcf3ce44SJohn Forte  * ****************************************************************************
1210fcf3ce44SJohn Forte  *
1211fcf3ce44SJohn Forte  * cvt_enumerate_rsp_to_get_req:
1212fcf3ce44SJohn Forte  *	pull out object info from enumerate response and calls
1213fcf3ce44SJohn Forte  *	build_get_xml_doc based on object type.
1214fcf3ce44SJohn Forte  *
1215fcf3ce44SJohn Forte  * doc		- enumerate resonse from the server.
1216fcf3ce44SJohn Forte  * req_do	- pointer to get request doc.
1217fcf3ce44SJohn Forte  * object_type	- isns object type.
1218fcf3ce44SJohn Forte  * flag		- user options
1219fcf3ce44SJohn Forte  *
1220fcf3ce44SJohn Forte  * ****************************************************************************
1221fcf3ce44SJohn Forte  */
1222fcf3ce44SJohn Forte static int
1223fcf3ce44SJohn Forte cvt_enumerate_rsp_to_get_req(xmlChar *doc, xmlChar **req_doc,
1224fcf3ce44SJohn Forte 	object_type obj, uint32_t flag)
1225fcf3ce44SJohn Forte {
1226fcf3ce44SJohn Forte 	xmlTextReaderPtr reader;
1227fcf3ce44SJohn Forte 	xmlChar **argxmlv;
1228fcf3ce44SJohn Forte 	int ret = 0, status;
1229fcf3ce44SJohn Forte 	int i, argxmlc = 0, m_flag = 0;
1230fcf3ce44SJohn Forte 
1231fcf3ce44SJohn Forte 	if ((reader = (xmlTextReaderPtr)xmlReaderForMemory((const char *)doc,
1232fcf3ce44SJohn Forte 	    xmlStrlen(doc), NULL, NULL, 0)) == NULL) {
1233fcf3ce44SJohn Forte 	    return (ERROR_XML_READER_NULL);
1234fcf3ce44SJohn Forte 	}
1235fcf3ce44SJohn Forte 
1236fcf3ce44SJohn Forte 	/* if status is 0, continue on.  Otherwise return an error. */
1237fcf3ce44SJohn Forte 	if (reader = lookup_next_matching_elem(reader, &m_flag, STATUSELEMENT,
1238fcf3ce44SJohn Forte 	    RESULTELEMENT)) {
1239fcf3ce44SJohn Forte 	    if (m_flag == READER_MATCH) {
1240fcf3ce44SJohn Forte 		if (xmlTextReaderRead(reader) == 1) {
1241fcf3ce44SJohn Forte 		    status =
1242fcf3ce44SJohn Forte 		    atoi((const char *)xmlTextReaderConstValue(reader));
1243fcf3ce44SJohn Forte 		    if (status != 0) {
1244fcf3ce44SJohn Forte 			print_error_status(status, obj, reader);
1245fcf3ce44SJohn Forte 			(void) xmlTextReaderClose(reader);
1246fcf3ce44SJohn Forte 			(void) xmlFreeTextReader(reader);
1247fcf3ce44SJohn Forte 			return (status);
1248fcf3ce44SJohn Forte 		    }
1249fcf3ce44SJohn Forte 		} else {
1250fcf3ce44SJohn Forte 		    (void) xmlTextReaderClose(reader);
1251fcf3ce44SJohn Forte 		    xmlFreeTextReader(reader);
1252fcf3ce44SJohn Forte 		    return (ERROR_XML_STATUS_ELEM_NOT_FOUND);
1253fcf3ce44SJohn Forte 		}
1254fcf3ce44SJohn Forte 	    } else {
1255fcf3ce44SJohn Forte 		return (ERROR_XML_STATUS_ELEM_NOT_FOUND);
1256fcf3ce44SJohn Forte 	    }
1257fcf3ce44SJohn Forte 	} else {
1258fcf3ce44SJohn Forte 	    return (ERROR_XML_READER_NULL);
1259fcf3ce44SJohn Forte 	}
1260fcf3ce44SJohn Forte 
1261fcf3ce44SJohn Forte 	m_flag = 0;
1262fcf3ce44SJohn Forte 
1263fcf3ce44SJohn Forte 	argxmlv = (xmlChar **)malloc(sizeof (xmlChar *));
1264fcf3ce44SJohn Forte 
1265fcf3ce44SJohn Forte 	/* XXX - validate isnsResponse element from response doc. */
1266fcf3ce44SJohn Forte 	switch (obj) {
1267fcf3ce44SJohn Forte 	    case Node:
1268fcf3ce44SJohn Forte 		/* process the node elements */
1269fcf3ce44SJohn Forte 		while (reader = lookup_next_matching_elem(reader, &m_flag,
1270fcf3ce44SJohn Forte 		    NODEOBJECT, ISNSRESPONSE)) {
1271fcf3ce44SJohn Forte 		    if (m_flag == END_READER_MATCH) {
1272fcf3ce44SJohn Forte 			(void) xmlTextReaderNext(reader);
1273fcf3ce44SJohn Forte 			break;
1274fcf3ce44SJohn Forte 		    }
1275fcf3ce44SJohn Forte 
1276fcf3ce44SJohn Forte 		    /* check the type */
1277fcf3ce44SJohn Forte 		    if ((xmlTextReaderMoveToAttribute(reader,
1278fcf3ce44SJohn Forte 			(const xmlChar *)TYPEATTR)) == 1) {
1279fcf3ce44SJohn Forte 			if (((flag & TARGET_ONLY) == TARGET_ONLY) &&
1280fcf3ce44SJohn Forte 			    (XMLNCMPVAL(reader, TARGETTYPE) != 0)) {
1281fcf3ce44SJohn Forte 			    /* move to next node object. */
1282fcf3ce44SJohn Forte 			    (void) xmlTextReaderMoveToElement(reader);
1283fcf3ce44SJohn Forte 			    (void) xmlTextReaderNext(reader);
1284fcf3ce44SJohn Forte 			    continue;
1285fcf3ce44SJohn Forte 			}
1286fcf3ce44SJohn Forte 			if (((flag & INITIATOR_ONLY) == INITIATOR_ONLY) &&
1287fcf3ce44SJohn Forte 			    (XMLNCMPVAL(reader, INITIATORTYPE) != 0)) {
1288fcf3ce44SJohn Forte 			    /* move to next node object. */
1289fcf3ce44SJohn Forte 			    (void) xmlTextReaderMoveToElement(reader);
1290fcf3ce44SJohn Forte 			    (void) xmlTextReaderNext(reader);
1291fcf3ce44SJohn Forte 			    continue;
1292fcf3ce44SJohn Forte 			}
1293fcf3ce44SJohn Forte 		    } else {
1294fcf3ce44SJohn Forte 			ret = ERROR_XML_TYPE_ATTR_NOT_FOUND;
1295fcf3ce44SJohn Forte 			goto out;
1296fcf3ce44SJohn Forte 		    }
1297fcf3ce44SJohn Forte 
1298fcf3ce44SJohn Forte 		    if (((xmlTextReaderMoveToAttribute(reader,
1299fcf3ce44SJohn Forte 			(const xmlChar *)NAMEATTR)) == 1) &&
1300fcf3ce44SJohn Forte 			xmlTextReaderConstValue(reader)) {
1301fcf3ce44SJohn Forte 			argxmlv = NEW_XMLARGV(argxmlv, argxmlc);
1302fcf3ce44SJohn Forte 			if (argxmlv == (xmlChar **)NULL) {
1303fcf3ce44SJohn Forte 			    ret = ERROR_MALLOC_FAILED;
1304fcf3ce44SJohn Forte 			    goto out;
1305fcf3ce44SJohn Forte 			}
1306fcf3ce44SJohn Forte 			argxmlv[argxmlc++] =
1307fcf3ce44SJohn Forte 			    xmlStrdup(xmlTextReaderConstValue(reader));
1308fcf3ce44SJohn Forte 			argxmlv[argxmlc] = NULL;
1309fcf3ce44SJohn Forte 		    } else {
1310fcf3ce44SJohn Forte 			ret = ERROR_XML_NAME_ATTR_NOT_FOUND;
1311fcf3ce44SJohn Forte 			goto out;
1312fcf3ce44SJohn Forte 		    }
1313fcf3ce44SJohn Forte 		    (void) xmlTextReaderRead(reader);
1314fcf3ce44SJohn Forte 		    m_flag = 0;
1315fcf3ce44SJohn Forte 		} /* end for node while */
1316fcf3ce44SJohn Forte 		break;
1317fcf3ce44SJohn Forte 	    case DiscoveryDomain:
1318fcf3ce44SJohn Forte 		/* process the DiscoveryDoamin elements */
1319fcf3ce44SJohn Forte 		while (reader = lookup_next_matching_elem(reader, &m_flag,
1320fcf3ce44SJohn Forte 		    DDOBJECT, ISNSRESPONSE)) {
1321fcf3ce44SJohn Forte 		    if (m_flag == END_READER_MATCH) {
1322fcf3ce44SJohn Forte 			(void) xmlTextReaderNext(reader);
1323fcf3ce44SJohn Forte 			break;
1324fcf3ce44SJohn Forte 		    }
1325fcf3ce44SJohn Forte 
1326fcf3ce44SJohn Forte 		    if (((xmlTextReaderMoveToAttribute(reader,
1327fcf3ce44SJohn Forte 			(const xmlChar *)NAMEATTR)) == 1) &&
1328fcf3ce44SJohn Forte 			xmlTextReaderConstValue(reader)) {
1329fcf3ce44SJohn Forte 			argxmlv = NEW_XMLARGV(argxmlv, argxmlc);
1330fcf3ce44SJohn Forte 			if (argxmlv == (xmlChar **)NULL) {
1331fcf3ce44SJohn Forte 			    ret = ERROR_MALLOC_FAILED;
1332fcf3ce44SJohn Forte 			    goto out;
1333fcf3ce44SJohn Forte 			}
1334fcf3ce44SJohn Forte 			argxmlv[argxmlc++] =
1335fcf3ce44SJohn Forte 			    xmlStrdup(xmlTextReaderConstValue(reader));
1336fcf3ce44SJohn Forte 			argxmlv[argxmlc] = NULL;
1337fcf3ce44SJohn Forte 		    } else {
1338fcf3ce44SJohn Forte 			    ret = ERROR_XML_NAME_ATTR_NOT_FOUND;
1339fcf3ce44SJohn Forte 			    goto out;
1340fcf3ce44SJohn Forte 		    }
1341fcf3ce44SJohn Forte 		    m_flag = 0;
1342fcf3ce44SJohn Forte 		    (void) xmlTextReaderRead(reader);
1343fcf3ce44SJohn Forte 		}
1344fcf3ce44SJohn Forte 		break;
1345fcf3ce44SJohn Forte 	    case DiscoveryDomainSet:
1346fcf3ce44SJohn Forte 		/* process the DiscoveryDoaminSet elements */
1347fcf3ce44SJohn Forte 		while (reader = lookup_next_matching_elem(reader, &m_flag,
1348fcf3ce44SJohn Forte 		    DDSETOBJECT, ISNSRESPONSE)) {
1349fcf3ce44SJohn Forte 		    if (m_flag == END_READER_MATCH) {
1350fcf3ce44SJohn Forte 			(void) xmlTextReaderNext(reader);
1351fcf3ce44SJohn Forte 			break;
1352fcf3ce44SJohn Forte 		    }
1353fcf3ce44SJohn Forte 
1354fcf3ce44SJohn Forte 		    if (((xmlTextReaderMoveToAttribute(reader,
1355fcf3ce44SJohn Forte 			(const xmlChar *)NAMEATTR)) == 1) &&
1356fcf3ce44SJohn Forte 			(const char *)xmlTextReaderConstValue(reader)) {
1357fcf3ce44SJohn Forte 			argxmlv = NEW_XMLARGV(argxmlv, argxmlc);
1358fcf3ce44SJohn Forte 			if (argxmlv == (xmlChar **)NULL) {
1359fcf3ce44SJohn Forte 			    ret = ERROR_MALLOC_FAILED;
1360fcf3ce44SJohn Forte 			    goto out;
1361fcf3ce44SJohn Forte 			}
1362fcf3ce44SJohn Forte 			argxmlv[argxmlc++] =
1363fcf3ce44SJohn Forte 			    xmlStrdup(xmlTextReaderConstValue(reader));
1364fcf3ce44SJohn Forte 			argxmlv[argxmlc] = NULL;
1365fcf3ce44SJohn Forte 		    } else {
1366fcf3ce44SJohn Forte 			ret = ERROR_XML_NAME_ATTR_NOT_FOUND;
1367fcf3ce44SJohn Forte 			goto out;
1368fcf3ce44SJohn Forte 		    }
1369fcf3ce44SJohn Forte 		    m_flag = 0;
1370fcf3ce44SJohn Forte 		    (void) xmlTextReaderRead(reader);
1371fcf3ce44SJohn Forte 		}
1372fcf3ce44SJohn Forte 		break;
1373fcf3ce44SJohn Forte 	    default:
1374fcf3ce44SJohn Forte 		ret = UNKNOWN;
1375fcf3ce44SJohn Forte 		goto out;
1376fcf3ce44SJohn Forte 	}
1377fcf3ce44SJohn Forte 
1378fcf3ce44SJohn Forte 	/* if no object found, stop here.  The status can be still 0. */
1379fcf3ce44SJohn Forte 	if (argxmlc != 0) {
1380fcf3ce44SJohn Forte 	    if ((ret = build_get_xml_doc(argxmlc, (char **)argxmlv, obj,
1381fcf3ce44SJohn Forte 		req_doc)) != 0) {
1382fcf3ce44SJohn Forte 		return (ret);
1383fcf3ce44SJohn Forte 	    }
1384fcf3ce44SJohn Forte 	} else {
1385fcf3ce44SJohn Forte 	    if (ret == 0) {
1386fcf3ce44SJohn Forte 		/* indicate there is no error but not object is found. */
1387fcf3ce44SJohn Forte 		ret = SUCCESS_WITH_NO_OBJECT;
1388fcf3ce44SJohn Forte 	    }
1389fcf3ce44SJohn Forte 	}
1390fcf3ce44SJohn Forte 
1391fcf3ce44SJohn Forte out:
1392fcf3ce44SJohn Forte 	(void) xmlTextReaderClose(reader);
1393fcf3ce44SJohn Forte 	(void) xmlFreeTextReader(reader);
1394fcf3ce44SJohn Forte 	if (argxmlc != 0) {
1395fcf3ce44SJohn Forte 	    for (i = 0; i < argxmlc; i++) {
1396fcf3ce44SJohn Forte 		xmlFree(argxmlv[i]);
1397fcf3ce44SJohn Forte 	    }
1398fcf3ce44SJohn Forte 	    (void) free(argxmlv);
1399fcf3ce44SJohn Forte 	}
1400fcf3ce44SJohn Forte 	return (ret);
1401fcf3ce44SJohn Forte 
1402fcf3ce44SJohn Forte }
1403fcf3ce44SJohn Forte 
1404fcf3ce44SJohn Forte /*
1405fcf3ce44SJohn Forte  * ****************************************************************************
1406fcf3ce44SJohn Forte  *
1407fcf3ce44SJohn Forte  * build_delete_xml_doc -
1408fcf3ce44SJohn Forte  *	build remove request doc based the name.
1409fcf3ce44SJohn Forte  *	the resulted doc is passed in the doc ptr.
1410fcf3ce44SJohn Forte  *
1411fcf3ce44SJohn Forte  * name		- object type
1412fcf3ce44SJohn Forte  * assoc	- association type
1413fcf3ce44SJohn Forte  * doc		- ptr to the resulted doc
1414fcf3ce44SJohn Forte  *
1415fcf3ce44SJohn Forte  * ****************************************************************************
1416fcf3ce44SJohn Forte  */
1417fcf3ce44SJohn Forte static int
1418fcf3ce44SJohn Forte build_delete_xml_doc(int operandLen, char **operand, object_type obj,
1419fcf3ce44SJohn Forte 	char *container, xmlChar **doc)
1420fcf3ce44SJohn Forte {
1421fcf3ce44SJohn Forte 	xmlTextWriterPtr writer;
1422fcf3ce44SJohn Forte 	xmlBufferPtr xbuf;
1423fcf3ce44SJohn Forte 	int i, len;
1424fcf3ce44SJohn Forte 
1425fcf3ce44SJohn Forte 	if ((xbuf = xmlBufferCreate()) == NULL) {
1426fcf3ce44SJohn Forte 		return (ERROR_XML_CREATE_BUFFER_FAILED);
1427fcf3ce44SJohn Forte 	}
1428fcf3ce44SJohn Forte 
1429fcf3ce44SJohn Forte 	if ((writer = xmlNewTextWriterMemory(xbuf, 0)) == NULL) {
1430fcf3ce44SJohn Forte 		return (ERROR_XML_CREATE_WRITER_FAILED);
1431fcf3ce44SJohn Forte 	}
1432fcf3ce44SJohn Forte 
1433fcf3ce44SJohn Forte 	if (xmlTextWriterStartDocument(writer, "1.0", NULL, NULL) < 0) {
1434fcf3ce44SJohn Forte 		return (ERROR_XML_START_DOC_FAILED);
1435fcf3ce44SJohn Forte 	}
1436fcf3ce44SJohn Forte 
1437fcf3ce44SJohn Forte 	/* Start element "isnsRequest". */
1438fcf3ce44SJohn Forte 	if (xmlTextWriterStartElement(writer, (xmlChar *)ISNSREQUEST) < 0) {
1439fcf3ce44SJohn Forte 	    return (ERROR_XML_START_ELEMENT_FAILED);
1440fcf3ce44SJohn Forte 	}
1441fcf3ce44SJohn Forte 
1442fcf3ce44SJohn Forte 	if ((xmlTextWriterWriteAttribute(writer,
1443fcf3ce44SJohn Forte 	    (xmlChar *)XMLNSATTR, (xmlChar *)XMLNSATTRVAL)) < 0) {
1444fcf3ce44SJohn Forte 	    return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
1445fcf3ce44SJohn Forte 	}
1446fcf3ce44SJohn Forte 
1447fcf3ce44SJohn Forte 	/* request delete operation to get the entire list of obejct. */
1448fcf3ce44SJohn Forte 	if (xmlTextWriterStartElement(writer, (xmlChar *)DELETE) < 0) {
1449fcf3ce44SJohn Forte 		return (ERROR_XML_START_ELEMENT_FAILED);
1450fcf3ce44SJohn Forte 	}
1451fcf3ce44SJohn Forte 
1452fcf3ce44SJohn Forte 	switch (obj) {
1453fcf3ce44SJohn Forte 	    case DiscoveryDomain:
1454fcf3ce44SJohn Forte 		for (i = 0; i < operandLen; i++) {
1455fcf3ce44SJohn Forte 		    /* start Discovery Domain element. */
1456fcf3ce44SJohn Forte 		    if (xmlTextWriterStartElement(writer,
1457fcf3ce44SJohn Forte 			(xmlChar *)DDOBJECT) < 0) {
1458fcf3ce44SJohn Forte 			return (ERROR_XML_START_ELEMENT_FAILED);
1459fcf3ce44SJohn Forte 		    }
1460fcf3ce44SJohn Forte 
1461fcf3ce44SJohn Forte 		    /* Start attr "name". */
1462fcf3ce44SJohn Forte 		    if ((xmlTextWriterWriteAttribute(writer,
1463fcf3ce44SJohn Forte 			(xmlChar *)NAMEATTR, (xmlChar *)operand[i])) < 0) {
1464fcf3ce44SJohn Forte 			return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
1465fcf3ce44SJohn Forte 		    }
1466fcf3ce44SJohn Forte 
1467fcf3ce44SJohn Forte 		    /* End element "DiscoveryDomain". */
1468fcf3ce44SJohn Forte 		    if (xmlTextWriterEndElement(writer) < 0) {
1469fcf3ce44SJohn Forte 			return (ERROR_XML_END_ELEMENT_FAILED);
1470fcf3ce44SJohn Forte 		    }
1471fcf3ce44SJohn Forte 		}
1472fcf3ce44SJohn Forte 		break;
1473fcf3ce44SJohn Forte 	    case DiscoveryDomainSet:
1474fcf3ce44SJohn Forte 		for (i = 0; i < operandLen; i++) {
1475fcf3ce44SJohn Forte 		    /* start Discovery DomainSet element. */
1476fcf3ce44SJohn Forte 		    if (xmlTextWriterStartElement(writer,
1477fcf3ce44SJohn Forte 			(xmlChar *)DDSETOBJECT) < 0) {
1478fcf3ce44SJohn Forte 			return (ERROR_XML_START_ELEMENT_FAILED);
1479fcf3ce44SJohn Forte 		    }
1480fcf3ce44SJohn Forte 
1481fcf3ce44SJohn Forte 		    /* Start attr "name". */
1482fcf3ce44SJohn Forte 		    if (xmlTextWriterWriteAttribute(writer,
1483fcf3ce44SJohn Forte 			(xmlChar *)NAMEATTR, (xmlChar *)operand[i]) < 0) {
1484fcf3ce44SJohn Forte 			return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
1485fcf3ce44SJohn Forte 		    }
1486fcf3ce44SJohn Forte 
1487fcf3ce44SJohn Forte 		    /* End element "DiscoveryDomainSet". */
1488fcf3ce44SJohn Forte 		    if (xmlTextWriterEndElement(writer) < 0) {
1489fcf3ce44SJohn Forte 			return (ERROR_XML_END_ELEMENT_FAILED);
1490fcf3ce44SJohn Forte 		    }
1491fcf3ce44SJohn Forte 		}
1492fcf3ce44SJohn Forte 		break;
1493fcf3ce44SJohn Forte 	    case DiscoveryDomainMember:
1494fcf3ce44SJohn Forte 		for (i = 0; i < operandLen; i++) {
1495fcf3ce44SJohn Forte 		    /* start Discovery Domain Member element. */
1496fcf3ce44SJohn Forte 		    if (xmlTextWriterStartElement(writer,
1497fcf3ce44SJohn Forte 			(xmlChar *)DDOBJECTMEMBER) < 0) {
1498fcf3ce44SJohn Forte 			return (ERROR_XML_START_ELEMENT_FAILED);
1499fcf3ce44SJohn Forte 		    }
1500fcf3ce44SJohn Forte 
1501fcf3ce44SJohn Forte 		    /* Start attr "DD Name". */
1502fcf3ce44SJohn Forte 		    if (xmlTextWriterWriteAttribute(writer,
1503fcf3ce44SJohn Forte 			(xmlChar *)DDNAMEATTR, (xmlChar *)container) < 0) {
1504fcf3ce44SJohn Forte 			return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
1505fcf3ce44SJohn Forte 		    }
1506fcf3ce44SJohn Forte 
1507fcf3ce44SJohn Forte 		    /* Start attr "Node Name". */
1508fcf3ce44SJohn Forte 		    if (xmlTextWriterWriteAttribute(writer,
1509fcf3ce44SJohn Forte 			(xmlChar *)NODENAMEATTR, (xmlChar *)operand[i]) < 0) {
1510fcf3ce44SJohn Forte 			return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
1511fcf3ce44SJohn Forte 		    }
1512fcf3ce44SJohn Forte 
1513fcf3ce44SJohn Forte 		    /* End element "DiscoveryDomainMember. */
1514fcf3ce44SJohn Forte 		    if (xmlTextWriterEndElement(writer) < 0) {
1515fcf3ce44SJohn Forte 			return (ERROR_XML_END_ELEMENT_FAILED);
1516fcf3ce44SJohn Forte 		    }
1517fcf3ce44SJohn Forte 		}
1518fcf3ce44SJohn Forte 		break;
1519fcf3ce44SJohn Forte 	    case DiscoveryDomainSetMember:
1520fcf3ce44SJohn Forte 		for (i = 0; i < operandLen; i++) {
1521fcf3ce44SJohn Forte 		    /* start Discovery Domain Member element. */
1522fcf3ce44SJohn Forte 		    if (xmlTextWriterStartElement(writer,
1523fcf3ce44SJohn Forte 			(xmlChar *)DDSETOBJECTMEMBER) < 0) {
1524fcf3ce44SJohn Forte 			return (ERROR_XML_START_ELEMENT_FAILED);
1525fcf3ce44SJohn Forte 		    }
1526fcf3ce44SJohn Forte 
1527fcf3ce44SJohn Forte 		    /* Start attr "DD Set Name". */
1528fcf3ce44SJohn Forte 		    if (xmlTextWriterWriteAttribute(writer,
1529fcf3ce44SJohn Forte 			(xmlChar *)DDSETNAMEATTR, (xmlChar *)(container)) < 0) {
1530fcf3ce44SJohn Forte 			return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
1531fcf3ce44SJohn Forte 		    }
1532fcf3ce44SJohn Forte 
1533fcf3ce44SJohn Forte 		    /* Start attr "DD Name". */
1534fcf3ce44SJohn Forte 		    if (xmlTextWriterWriteAttribute(writer,
1535fcf3ce44SJohn Forte 			(xmlChar *)DDNAMEATTR, (xmlChar *)(operand[i])) < 0) {
1536fcf3ce44SJohn Forte 			return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
1537fcf3ce44SJohn Forte 		    }
1538fcf3ce44SJohn Forte 
1539fcf3ce44SJohn Forte 		    /* End element "DiscoveryDomainSetMember. */
1540fcf3ce44SJohn Forte 		    if (xmlTextWriterEndElement(writer) < 0) {
1541fcf3ce44SJohn Forte 			return (ERROR_XML_END_ELEMENT_FAILED);
1542fcf3ce44SJohn Forte 		    }
1543fcf3ce44SJohn Forte 		}
1544fcf3ce44SJohn Forte 		break;
1545fcf3ce44SJohn Forte 	    default:
1546fcf3ce44SJohn Forte 		    xmlFreeTextWriter(writer);
1547fcf3ce44SJohn Forte 		    return (UNKNOWN);
1548fcf3ce44SJohn Forte 	}
1549fcf3ce44SJohn Forte 
1550fcf3ce44SJohn Forte 	/* end createModify */
1551fcf3ce44SJohn Forte 	if (xmlTextWriterEndElement(writer) < 0) {
1552fcf3ce44SJohn Forte 	    xmlFreeTextWriter(writer);
1553fcf3ce44SJohn Forte 	    return (ERROR_XML_END_ELEMENT_FAILED);
1554fcf3ce44SJohn Forte 	}
1555fcf3ce44SJohn Forte 
1556fcf3ce44SJohn Forte 	/* End element "isnsRequest". */
1557fcf3ce44SJohn Forte 	if (xmlTextWriterEndElement(writer) < 0) {
1558fcf3ce44SJohn Forte 	    xmlFreeTextWriter(writer);
1559fcf3ce44SJohn Forte 	    return (ERROR_XML_END_ELEMENT_FAILED);
1560fcf3ce44SJohn Forte 	}
1561fcf3ce44SJohn Forte 	if (xmlTextWriterEndDocument(writer) < 0) {
1562fcf3ce44SJohn Forte 	    xmlFreeTextWriter(writer);
1563fcf3ce44SJohn Forte 	    return (ERROR_XML_END_DOC_FAILED);
1564fcf3ce44SJohn Forte 	}
1565fcf3ce44SJohn Forte 
1566fcf3ce44SJohn Forte 	xmlFreeTextWriter(writer);
1567fcf3ce44SJohn Forte 
1568fcf3ce44SJohn Forte 	len = xmlStrlen(xbuf->content) + 1;
1569fcf3ce44SJohn Forte 	/* XXX - copy NULL at the end by having one more extra byte */
1570fcf3ce44SJohn Forte 	if ((*doc = xmlStrndup(xbuf->content, len)) == NULL) {
1571fcf3ce44SJohn Forte 	    return (ERROR_XML_STRDUP_FAILED);
1572fcf3ce44SJohn Forte 	}
1573fcf3ce44SJohn Forte 
1574fcf3ce44SJohn Forte 	xmlBufferFree(xbuf);
1575fcf3ce44SJohn Forte 
1576fcf3ce44SJohn Forte 	return (0);
1577fcf3ce44SJohn Forte }
1578fcf3ce44SJohn Forte 
1579fcf3ce44SJohn Forte /*
1580fcf3ce44SJohn Forte  * ****************************************************************************
1581fcf3ce44SJohn Forte  *
1582fcf3ce44SJohn Forte  * build_modify_xml_doc -
1583fcf3ce44SJohn Forte  *	build create request doc based the name.
1584fcf3ce44SJohn Forte  *	the resulted doc is passed in the doc ptr.
1585fcf3ce44SJohn Forte  *
1586fcf3ce44SJohn Forte  * operannLen	- number of objects
1587fcf3ce44SJohn Forte  * operand	- object list
1588fcf3ce44SJohn Forte  * enabled	- indication of enable and disable boolean type element.
1589fcf3ce44SJohn Forte  * doc		- ptr to the resulted doc
1590fcf3ce44SJohn Forte  *
1591fcf3ce44SJohn Forte  * ****************************************************************************
1592fcf3ce44SJohn Forte  */
1593fcf3ce44SJohn Forte static int
1594fcf3ce44SJohn Forte build_modify_xml_doc(int operandLen, char **operand, object_type obj,
1595fcf3ce44SJohn Forte 	boolean_t enabled, xmlChar **doc)
1596fcf3ce44SJohn Forte {
1597fcf3ce44SJohn Forte 	xmlTextWriterPtr writer;
1598fcf3ce44SJohn Forte 	xmlBufferPtr xbuf;
1599fcf3ce44SJohn Forte 	int i, len;
1600fcf3ce44SJohn Forte 
1601fcf3ce44SJohn Forte 	if ((xbuf = xmlBufferCreate()) == NULL) {
1602fcf3ce44SJohn Forte 		return (ERROR_XML_CREATE_BUFFER_FAILED);
1603fcf3ce44SJohn Forte 	}
1604fcf3ce44SJohn Forte 
1605fcf3ce44SJohn Forte 	if ((writer = xmlNewTextWriterMemory(xbuf, 0)) == NULL) {
1606fcf3ce44SJohn Forte 		return (ERROR_XML_CREATE_WRITER_FAILED);
1607fcf3ce44SJohn Forte 	}
1608fcf3ce44SJohn Forte 
1609fcf3ce44SJohn Forte 	if (xmlTextWriterStartDocument(writer, "1.0", NULL, NULL) < 0) {
1610fcf3ce44SJohn Forte 		return (ERROR_XML_START_DOC_FAILED);
1611fcf3ce44SJohn Forte 	}
1612fcf3ce44SJohn Forte 
1613fcf3ce44SJohn Forte 	/* Start element "isnsRequest". */
1614fcf3ce44SJohn Forte 	if (xmlTextWriterStartElement(writer, (xmlChar *)ISNSREQUEST) < 0) {
1615fcf3ce44SJohn Forte 	    return (ERROR_XML_START_ELEMENT_FAILED);
1616fcf3ce44SJohn Forte 	}
1617fcf3ce44SJohn Forte 
1618fcf3ce44SJohn Forte 	if ((xmlTextWriterWriteAttribute(writer,
1619fcf3ce44SJohn Forte 	    (xmlChar *)XMLNSATTR, (xmlChar *)XMLNSATTRVAL)) < 0) {
1620fcf3ce44SJohn Forte 	    return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
1621fcf3ce44SJohn Forte 	}
1622fcf3ce44SJohn Forte 
1623fcf3ce44SJohn Forte 	/* request createModify operation to get the entire list of obejct. */
1624fcf3ce44SJohn Forte 	if (xmlTextWriterStartElement(writer, (xmlChar *)CREATEMODIFY) < 0) {
1625fcf3ce44SJohn Forte 		return (ERROR_XML_START_ELEMENT_FAILED);
1626fcf3ce44SJohn Forte 	}
1627fcf3ce44SJohn Forte 
1628fcf3ce44SJohn Forte 	switch (obj) {
1629fcf3ce44SJohn Forte 	    case DiscoveryDomain:
1630fcf3ce44SJohn Forte 		for (i = 0; i < operandLen; i++) {
1631fcf3ce44SJohn Forte 		    /* start Discovery Domain element. */
1632fcf3ce44SJohn Forte 		    if (xmlTextWriterStartElement(writer,
1633fcf3ce44SJohn Forte 			(xmlChar *)DDOBJECT) < 0) {
1634fcf3ce44SJohn Forte 			return (ERROR_XML_START_ELEMENT_FAILED);
1635fcf3ce44SJohn Forte 		    }
1636fcf3ce44SJohn Forte 
1637fcf3ce44SJohn Forte 		    /* write attr "name". */
1638fcf3ce44SJohn Forte 		    if ((xmlTextWriterWriteAttribute(writer,
1639fcf3ce44SJohn Forte 			(xmlChar *)NAMEATTR, (xmlChar *)operand[i])) < 0) {
1640fcf3ce44SJohn Forte 			return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
1641fcf3ce44SJohn Forte 		    }
1642fcf3ce44SJohn Forte 
1643fcf3ce44SJohn Forte 		    /* write bootlist_enabled elem */
1644fcf3ce44SJohn Forte 		    if (xmlTextWriterWriteElement(writer,
1645fcf3ce44SJohn Forte 			(xmlChar *)BOOTLISTENABLEDELEM, (enabled)?
1646fcf3ce44SJohn Forte 			(xmlChar *)XMLTRUE : (xmlChar *)XMLFALSE) < 0) {
1647fcf3ce44SJohn Forte 			return (ERROR_XML_WRITE_ELEMENT_FAILED);
1648fcf3ce44SJohn Forte 		    }
1649fcf3ce44SJohn Forte 
1650fcf3ce44SJohn Forte 		    /* End element "DiscoveryDomain". */
1651fcf3ce44SJohn Forte 		    if (xmlTextWriterEndElement(writer) < 0) {
1652fcf3ce44SJohn Forte 			return (ERROR_XML_END_ELEMENT_FAILED);
1653fcf3ce44SJohn Forte 		    }
1654fcf3ce44SJohn Forte 		}
1655fcf3ce44SJohn Forte 		break;
1656fcf3ce44SJohn Forte 	    case DiscoveryDomainSet:
1657fcf3ce44SJohn Forte 		for (i = 0; i < operandLen; i++) {
1658fcf3ce44SJohn Forte 		    /* start Discovery DomainSet element. */
1659fcf3ce44SJohn Forte 		    if (xmlTextWriterStartElement(writer,
1660fcf3ce44SJohn Forte 			(xmlChar *)DDSETOBJECT) < 0) {
1661fcf3ce44SJohn Forte 			return (ERROR_XML_START_ELEMENT_FAILED);
1662fcf3ce44SJohn Forte 		    }
1663fcf3ce44SJohn Forte 
1664fcf3ce44SJohn Forte 		    /* Start attr "name". */
1665fcf3ce44SJohn Forte 		    if (xmlTextWriterWriteAttribute(writer,
1666fcf3ce44SJohn Forte 			(xmlChar *)NAMEATTR, (xmlChar *)operand[i]) < 0) {
1667fcf3ce44SJohn Forte 			return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
1668fcf3ce44SJohn Forte 		    }
1669fcf3ce44SJohn Forte 
1670fcf3ce44SJohn Forte 		    /* write enabled elem */
1671fcf3ce44SJohn Forte 		    if (xmlTextWriterWriteElement(writer,
1672fcf3ce44SJohn Forte 			(xmlChar *)ENABLEDELEM, (enabled) ?
1673fcf3ce44SJohn Forte 			(xmlChar *)XMLTRUE : (xmlChar *)XMLFALSE) < 0) {
1674fcf3ce44SJohn Forte 			return (ERROR_XML_WRITE_ELEMENT_FAILED);
1675fcf3ce44SJohn Forte 		    }
1676fcf3ce44SJohn Forte 
1677fcf3ce44SJohn Forte 		    /* End element "DiscoveryDomainSet". */
1678fcf3ce44SJohn Forte 		    if (xmlTextWriterEndElement(writer) < 0) {
1679fcf3ce44SJohn Forte 			return (ERROR_XML_END_ELEMENT_FAILED);
1680fcf3ce44SJohn Forte 		    }
1681fcf3ce44SJohn Forte 		}
1682fcf3ce44SJohn Forte 		break;
1683fcf3ce44SJohn Forte 	    default:
1684fcf3ce44SJohn Forte 		    xmlFreeTextWriter(writer);
1685fcf3ce44SJohn Forte 		    return (UNKNOWN);
1686fcf3ce44SJohn Forte 	}
1687fcf3ce44SJohn Forte 
1688fcf3ce44SJohn Forte 	/* end createModify */
1689fcf3ce44SJohn Forte 	if (xmlTextWriterEndElement(writer) < 0) {
1690fcf3ce44SJohn Forte 	    xmlFreeTextWriter(writer);
1691fcf3ce44SJohn Forte 	    return (ERROR_XML_END_ELEMENT_FAILED);
1692fcf3ce44SJohn Forte 	}
1693fcf3ce44SJohn Forte 
1694fcf3ce44SJohn Forte 	/* End element "isnsRequest". */
1695fcf3ce44SJohn Forte 	if (xmlTextWriterEndElement(writer) < 0) {
1696fcf3ce44SJohn Forte 	    xmlFreeTextWriter(writer);
1697fcf3ce44SJohn Forte 	    return (ERROR_XML_END_ELEMENT_FAILED);
1698fcf3ce44SJohn Forte 	}
1699fcf3ce44SJohn Forte 	if (xmlTextWriterEndDocument(writer) < 0) {
1700fcf3ce44SJohn Forte 	    xmlFreeTextWriter(writer);
1701fcf3ce44SJohn Forte 	    return (ERROR_XML_END_DOC_FAILED);
1702fcf3ce44SJohn Forte 	}
1703fcf3ce44SJohn Forte 
1704fcf3ce44SJohn Forte 	xmlFreeTextWriter(writer);
1705fcf3ce44SJohn Forte 
1706fcf3ce44SJohn Forte 	len = xmlStrlen(xbuf->content) + 1;
1707fcf3ce44SJohn Forte 	/* XXX - copy NULL at the end by having one more extra byte */
1708fcf3ce44SJohn Forte 	if ((*doc = xmlStrndup(xbuf->content, len)) == NULL) {
1709fcf3ce44SJohn Forte 	    return (ERROR_XML_STRDUP_FAILED);
1710fcf3ce44SJohn Forte 	}
1711fcf3ce44SJohn Forte 
1712fcf3ce44SJohn Forte 	xmlBufferFree(xbuf);
1713fcf3ce44SJohn Forte 
1714fcf3ce44SJohn Forte 	return (0);
1715fcf3ce44SJohn Forte }
1716fcf3ce44SJohn Forte 
1717fcf3ce44SJohn Forte /*
1718fcf3ce44SJohn Forte  * ****************************************************************************
1719fcf3ce44SJohn Forte  *
1720fcf3ce44SJohn Forte  * build_rename_xml_doc -
1721fcf3ce44SJohn Forte  *	build create request doc based the name.
1722fcf3ce44SJohn Forte  *	the resulted doc is passed in the doc ptr.
1723fcf3ce44SJohn Forte  *
1724fcf3ce44SJohn Forte  * assoc	- a new name
1725fcf3ce44SJohn Forte  * id		- index of the object of which name  to be changed
1726fcf3ce44SJohn Forte  * doc		- ptr to the resulted doc
1727fcf3ce44SJohn Forte  *
1728fcf3ce44SJohn Forte  * ****************************************************************************
1729fcf3ce44SJohn Forte  */
1730fcf3ce44SJohn Forte static int
1731fcf3ce44SJohn Forte build_rename_xml_doc(char *name, object_type obj, uint32_t id, xmlChar **doc)
1732fcf3ce44SJohn Forte {
1733fcf3ce44SJohn Forte 	xmlTextWriterPtr writer;
1734fcf3ce44SJohn Forte 	xmlBufferPtr xbuf;
1735fcf3ce44SJohn Forte 	int len;
1736fcf3ce44SJohn Forte 	char namebuf[32];
1737fcf3ce44SJohn Forte 
1738fcf3ce44SJohn Forte 	if ((xbuf = xmlBufferCreate()) == NULL) {
1739fcf3ce44SJohn Forte 		return (ERROR_XML_CREATE_BUFFER_FAILED);
1740fcf3ce44SJohn Forte 	}
1741fcf3ce44SJohn Forte 
1742fcf3ce44SJohn Forte 	if ((writer = xmlNewTextWriterMemory(xbuf, 0)) == NULL) {
1743fcf3ce44SJohn Forte 		return (ERROR_XML_CREATE_WRITER_FAILED);
1744fcf3ce44SJohn Forte 	}
1745fcf3ce44SJohn Forte 
1746fcf3ce44SJohn Forte 	if (xmlTextWriterStartDocument(writer, "1.0", NULL, NULL) < 0) {
1747fcf3ce44SJohn Forte 		return (ERROR_XML_START_DOC_FAILED);
1748fcf3ce44SJohn Forte 	}
1749fcf3ce44SJohn Forte 
1750fcf3ce44SJohn Forte 	/* Start element "isnsRequest". */
1751fcf3ce44SJohn Forte 	if (xmlTextWriterStartElement(writer, (xmlChar *)ISNSREQUEST) < 0) {
1752fcf3ce44SJohn Forte 	    return (ERROR_XML_START_ELEMENT_FAILED);
1753fcf3ce44SJohn Forte 	}
1754fcf3ce44SJohn Forte 
1755fcf3ce44SJohn Forte 	if ((xmlTextWriterWriteAttribute(writer,
1756fcf3ce44SJohn Forte 	    (xmlChar *)XMLNSATTR, (xmlChar *)XMLNSATTRVAL)) < 0) {
1757fcf3ce44SJohn Forte 	    return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
1758fcf3ce44SJohn Forte 	}
1759fcf3ce44SJohn Forte 
1760fcf3ce44SJohn Forte 	/* request createModify operation to get the entire list of obejct. */
1761fcf3ce44SJohn Forte 	if (xmlTextWriterStartElement(writer, (xmlChar *)CREATEMODIFY) < 0) {
1762fcf3ce44SJohn Forte 		return (ERROR_XML_START_ELEMENT_FAILED);
1763fcf3ce44SJohn Forte 	}
1764fcf3ce44SJohn Forte 
1765fcf3ce44SJohn Forte 	switch (obj) {
1766fcf3ce44SJohn Forte 	    case DiscoveryDomain:
1767fcf3ce44SJohn Forte 		    /* start Discovery Domain element. */
1768fcf3ce44SJohn Forte 		    if (xmlTextWriterStartElement(writer,
1769fcf3ce44SJohn Forte 			(xmlChar *)DDOBJECT) < 0) {
1770fcf3ce44SJohn Forte 			return (ERROR_XML_START_ELEMENT_FAILED);
1771fcf3ce44SJohn Forte 		    }
1772fcf3ce44SJohn Forte 
1773fcf3ce44SJohn Forte 		    /* write attr "name". */
1774fcf3ce44SJohn Forte 		    if ((xmlTextWriterWriteAttribute(writer,
1775fcf3ce44SJohn Forte 			(xmlChar *)NAMEATTR, (xmlChar *)name)) < 0) {
1776fcf3ce44SJohn Forte 			return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
1777fcf3ce44SJohn Forte 		    }
1778fcf3ce44SJohn Forte 
1779fcf3ce44SJohn Forte 		    /* write attr "id". */
1780fcf3ce44SJohn Forte 		    (void) sprintf(namebuf, "%d", id);
1781fcf3ce44SJohn Forte 		    if ((xmlTextWriterWriteAttribute(writer,
1782fcf3ce44SJohn Forte 			(xmlChar *)IDATTR, (xmlChar *)namebuf)) < 0) {
1783fcf3ce44SJohn Forte 			return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
1784fcf3ce44SJohn Forte 		    }
1785fcf3ce44SJohn Forte 
1786fcf3ce44SJohn Forte 		    /* End element "DiscoveryDomain". */
1787fcf3ce44SJohn Forte 		    if (xmlTextWriterEndElement(writer) < 0) {
1788fcf3ce44SJohn Forte 			return (ERROR_XML_END_ELEMENT_FAILED);
1789fcf3ce44SJohn Forte 		    }
1790fcf3ce44SJohn Forte 		break;
1791fcf3ce44SJohn Forte 	    case DiscoveryDomainSet:
1792fcf3ce44SJohn Forte 		    /* start Discovery DomainSet element. */
1793fcf3ce44SJohn Forte 		    if (xmlTextWriterStartElement(writer,
1794fcf3ce44SJohn Forte 			(xmlChar *)DDSETOBJECT) < 0) {
1795fcf3ce44SJohn Forte 			return (ERROR_XML_START_ELEMENT_FAILED);
1796fcf3ce44SJohn Forte 		    }
1797fcf3ce44SJohn Forte 
1798fcf3ce44SJohn Forte 		    /* Start attr "name". */
1799fcf3ce44SJohn Forte 		    if (xmlTextWriterWriteAttribute(writer,
1800fcf3ce44SJohn Forte 			(xmlChar *)NAMEATTR, (xmlChar *)name) < 0) {
1801fcf3ce44SJohn Forte 			return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
1802fcf3ce44SJohn Forte 		    }
1803fcf3ce44SJohn Forte 
1804fcf3ce44SJohn Forte 		    /* write attr "id". */
1805fcf3ce44SJohn Forte 		    (void) sprintf(namebuf, "%d", id);
1806fcf3ce44SJohn Forte 		    if ((xmlTextWriterWriteAttribute(writer,
1807fcf3ce44SJohn Forte 			(xmlChar *)IDATTR, (xmlChar *)namebuf)) < 0) {
1808fcf3ce44SJohn Forte 			return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
1809fcf3ce44SJohn Forte 		    }
1810fcf3ce44SJohn Forte 
1811fcf3ce44SJohn Forte 		    /* End element "DiscoveryDomainSet". */
1812fcf3ce44SJohn Forte 		    if (xmlTextWriterEndElement(writer) < 0) {
1813fcf3ce44SJohn Forte 			return (ERROR_XML_END_ELEMENT_FAILED);
1814fcf3ce44SJohn Forte 		    }
1815fcf3ce44SJohn Forte 		break;
1816fcf3ce44SJohn Forte 	    default:
1817fcf3ce44SJohn Forte 		    xmlFreeTextWriter(writer);
1818fcf3ce44SJohn Forte 		    return (UNKNOWN);
1819fcf3ce44SJohn Forte 	}
1820fcf3ce44SJohn Forte 
1821fcf3ce44SJohn Forte 	/* end createModify */
1822fcf3ce44SJohn Forte 	if (xmlTextWriterEndElement(writer) < 0) {
1823fcf3ce44SJohn Forte 	    xmlFreeTextWriter(writer);
1824fcf3ce44SJohn Forte 	    return (ERROR_XML_END_ELEMENT_FAILED);
1825fcf3ce44SJohn Forte 	}
1826fcf3ce44SJohn Forte 
1827fcf3ce44SJohn Forte 	/* End element "isnsRequest". */
1828fcf3ce44SJohn Forte 	if (xmlTextWriterEndElement(writer) < 0) {
1829fcf3ce44SJohn Forte 	    xmlFreeTextWriter(writer);
1830fcf3ce44SJohn Forte 	    return (ERROR_XML_END_ELEMENT_FAILED);
1831fcf3ce44SJohn Forte 	}
1832fcf3ce44SJohn Forte 	if (xmlTextWriterEndDocument(writer) < 0) {
1833fcf3ce44SJohn Forte 	    xmlFreeTextWriter(writer);
1834fcf3ce44SJohn Forte 	    return (ERROR_XML_END_DOC_FAILED);
1835fcf3ce44SJohn Forte 	}
1836fcf3ce44SJohn Forte 
1837fcf3ce44SJohn Forte 	xmlFreeTextWriter(writer);
1838fcf3ce44SJohn Forte 
1839fcf3ce44SJohn Forte 	len = xmlStrlen(xbuf->content) + 1;
1840fcf3ce44SJohn Forte 	/* XXX - copy NULL at the end by having one more extra byte */
1841fcf3ce44SJohn Forte 	if ((*doc = xmlStrndup(xbuf->content, len)) == NULL) {
1842fcf3ce44SJohn Forte 	    return (ERROR_XML_STRDUP_FAILED);
1843fcf3ce44SJohn Forte 	}
1844fcf3ce44SJohn Forte 
1845fcf3ce44SJohn Forte 	xmlBufferFree(xbuf);
1846fcf3ce44SJohn Forte 
1847fcf3ce44SJohn Forte 	return (0);
1848fcf3ce44SJohn Forte }
1849fcf3ce44SJohn Forte 
1850fcf3ce44SJohn Forte /*
1851fcf3ce44SJohn Forte  * ****************************************************************************
1852fcf3ce44SJohn Forte  *
1853fcf3ce44SJohn Forte  * build_create_xml_doc -
1854fcf3ce44SJohn Forte  *	build create request doc based the name.
1855fcf3ce44SJohn Forte  *	the resulted doc is passed in the doc ptr.
1856fcf3ce44SJohn Forte  *
1857fcf3ce44SJohn Forte  * name		- object type
1858fcf3ce44SJohn Forte  * assoc	- association type
1859fcf3ce44SJohn Forte  * doc		- ptr to the resulted doc
1860fcf3ce44SJohn Forte  *
1861fcf3ce44SJohn Forte  * ****************************************************************************
1862fcf3ce44SJohn Forte  */
1863fcf3ce44SJohn Forte static int
1864fcf3ce44SJohn Forte build_create_xml_doc(int operandLen, char **operand, object_type obj,
1865fcf3ce44SJohn Forte 	char *container, xmlChar **doc)
1866fcf3ce44SJohn Forte {
1867fcf3ce44SJohn Forte 	xmlTextWriterPtr writer;
1868fcf3ce44SJohn Forte 	xmlBufferPtr xbuf;
1869fcf3ce44SJohn Forte 	int i, len;
1870fcf3ce44SJohn Forte 
1871fcf3ce44SJohn Forte 	if ((xbuf = xmlBufferCreate()) == NULL) {
1872fcf3ce44SJohn Forte 		return (ERROR_XML_CREATE_BUFFER_FAILED);
1873fcf3ce44SJohn Forte 	}
1874fcf3ce44SJohn Forte 
1875fcf3ce44SJohn Forte 	if ((writer = xmlNewTextWriterMemory(xbuf, 0)) == NULL) {
1876fcf3ce44SJohn Forte 		return (ERROR_XML_CREATE_WRITER_FAILED);
1877fcf3ce44SJohn Forte 	}
1878fcf3ce44SJohn Forte 
1879fcf3ce44SJohn Forte 	if (xmlTextWriterStartDocument(writer, "1.0", NULL, NULL) < 0) {
1880fcf3ce44SJohn Forte 		return (ERROR_XML_START_DOC_FAILED);
1881fcf3ce44SJohn Forte 	}
1882fcf3ce44SJohn Forte 
1883fcf3ce44SJohn Forte 	/* Start element "isnsRequest". */
1884fcf3ce44SJohn Forte 	if (xmlTextWriterStartElement(writer, (xmlChar *)ISNSREQUEST) < 0) {
1885fcf3ce44SJohn Forte 	    return (ERROR_XML_START_ELEMENT_FAILED);
1886fcf3ce44SJohn Forte 	}
1887fcf3ce44SJohn Forte 
1888fcf3ce44SJohn Forte 	/* request createModify operation to get the entire list of obejct. */
1889fcf3ce44SJohn Forte 	if (xmlTextWriterStartElement(writer, (xmlChar *)CREATEMODIFY) < 0) {
1890fcf3ce44SJohn Forte 		return (ERROR_XML_START_ELEMENT_FAILED);
1891fcf3ce44SJohn Forte 	}
1892fcf3ce44SJohn Forte 
1893fcf3ce44SJohn Forte 	switch (obj) {
1894fcf3ce44SJohn Forte 	    case DiscoveryDomain:
1895fcf3ce44SJohn Forte 		for (i = 0; i < operandLen; i++) {
1896fcf3ce44SJohn Forte 		    /* start Discovery Domain element. */
1897fcf3ce44SJohn Forte 		    if (xmlTextWriterStartElement(writer,
1898fcf3ce44SJohn Forte 			(xmlChar *)DDOBJECT) < 0) {
1899fcf3ce44SJohn Forte 			return (ERROR_XML_START_ELEMENT_FAILED);
1900fcf3ce44SJohn Forte 		    }
1901fcf3ce44SJohn Forte 
1902fcf3ce44SJohn Forte 		    /* Start attr "name". */
1903fcf3ce44SJohn Forte 		    if ((xmlTextWriterWriteAttribute(writer,
1904fcf3ce44SJohn Forte 			(xmlChar *)NAMEATTR, (xmlChar *)operand[i])) < 0) {
1905fcf3ce44SJohn Forte 			return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
1906fcf3ce44SJohn Forte 		    }
1907fcf3ce44SJohn Forte 
1908fcf3ce44SJohn Forte 		    /* End element "DiscoveryDomain". */
1909fcf3ce44SJohn Forte 		    if (xmlTextWriterEndElement(writer) < 0) {
1910fcf3ce44SJohn Forte 			return (ERROR_XML_END_ELEMENT_FAILED);
1911fcf3ce44SJohn Forte 		    }
1912fcf3ce44SJohn Forte 		}
1913fcf3ce44SJohn Forte 		break;
1914fcf3ce44SJohn Forte 	    case DiscoveryDomainSet:
1915fcf3ce44SJohn Forte 		for (i = 0; i < operandLen; i++) {
1916fcf3ce44SJohn Forte 		    /* start Discovery DomainSet element. */
1917fcf3ce44SJohn Forte 		    if (xmlTextWriterStartElement(writer,
1918fcf3ce44SJohn Forte 			(xmlChar *)DDSETOBJECT) < 0) {
1919fcf3ce44SJohn Forte 			return (ERROR_XML_START_ELEMENT_FAILED);
1920fcf3ce44SJohn Forte 		    }
1921fcf3ce44SJohn Forte 
1922fcf3ce44SJohn Forte 		    /* Start attr "name". */
1923fcf3ce44SJohn Forte 		    if (xmlTextWriterWriteAttribute(writer,
1924fcf3ce44SJohn Forte 			(xmlChar *)NAMEATTR, (xmlChar *)operand[i]) < 0) {
1925fcf3ce44SJohn Forte 			return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
1926fcf3ce44SJohn Forte 		    }
1927fcf3ce44SJohn Forte 
1928fcf3ce44SJohn Forte 		    /* End element "DiscoveryDomainSet". */
1929fcf3ce44SJohn Forte 		    if (xmlTextWriterEndElement(writer) < 0) {
1930fcf3ce44SJohn Forte 			return (ERROR_XML_END_ELEMENT_FAILED);
1931fcf3ce44SJohn Forte 		    }
1932fcf3ce44SJohn Forte 		}
1933fcf3ce44SJohn Forte 		break;
1934fcf3ce44SJohn Forte 	    case DiscoveryDomainMember:
1935fcf3ce44SJohn Forte 		for (i = 0; i < operandLen; i++) {
1936fcf3ce44SJohn Forte 		    /* start Discovery Domain Member element. */
1937fcf3ce44SJohn Forte 		    if (xmlTextWriterStartElement(writer,
1938fcf3ce44SJohn Forte 			(xmlChar *)DDOBJECTMEMBER) < 0) {
1939fcf3ce44SJohn Forte 			return (ERROR_XML_START_ELEMENT_FAILED);
1940fcf3ce44SJohn Forte 		    }
1941fcf3ce44SJohn Forte 
1942fcf3ce44SJohn Forte 		    /* Start attr "DD Name". */
1943fcf3ce44SJohn Forte 		    if (xmlTextWriterWriteAttribute(writer,
1944fcf3ce44SJohn Forte 			(xmlChar *)DDNAMEATTR, (xmlChar *)container) < 0) {
1945fcf3ce44SJohn Forte 			return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
1946fcf3ce44SJohn Forte 		    }
1947fcf3ce44SJohn Forte 
1948fcf3ce44SJohn Forte 		    /* Start attr "Node Name". */
1949fcf3ce44SJohn Forte 		    if (xmlTextWriterWriteAttribute(writer,
1950fcf3ce44SJohn Forte 			(xmlChar *)NODENAMEATTR, (xmlChar *)operand[i]) < 0) {
1951fcf3ce44SJohn Forte 			return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
1952fcf3ce44SJohn Forte 		    }
1953fcf3ce44SJohn Forte 
1954fcf3ce44SJohn Forte 		    /* End element "DiscoveryDomainMember. */
1955fcf3ce44SJohn Forte 		    if (xmlTextWriterEndElement(writer) < 0) {
1956fcf3ce44SJohn Forte 			return (ERROR_XML_END_ELEMENT_FAILED);
1957fcf3ce44SJohn Forte 		    }
1958fcf3ce44SJohn Forte 		}
1959fcf3ce44SJohn Forte 		break;
1960fcf3ce44SJohn Forte 	    case DiscoveryDomainSetMember:
1961fcf3ce44SJohn Forte 		for (i = 0; i < operandLen; i++) {
1962fcf3ce44SJohn Forte 		    /* start Discovery Domain Member element. */
1963fcf3ce44SJohn Forte 		    if (xmlTextWriterStartElement(writer,
1964fcf3ce44SJohn Forte 			(xmlChar *)DDSETOBJECTMEMBER) < 0) {
1965fcf3ce44SJohn Forte 			return (ERROR_XML_START_ELEMENT_FAILED);
1966fcf3ce44SJohn Forte 		    }
1967fcf3ce44SJohn Forte 
1968fcf3ce44SJohn Forte 		    /* Start attr "DD Set Name". */
1969fcf3ce44SJohn Forte 		    if (xmlTextWriterWriteAttribute(writer,
1970fcf3ce44SJohn Forte 			(xmlChar *)DDSETNAMEATTR, (xmlChar *)(container)) < 0) {
1971fcf3ce44SJohn Forte 			return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
1972fcf3ce44SJohn Forte 		    }
1973fcf3ce44SJohn Forte 
1974fcf3ce44SJohn Forte 		    /* Start attr "DD Name". */
1975fcf3ce44SJohn Forte 		    if (xmlTextWriterWriteAttribute(writer,
1976fcf3ce44SJohn Forte 			(xmlChar *)DDNAMEATTR, (xmlChar *)(operand[i])) < 0) {
1977fcf3ce44SJohn Forte 			return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
1978fcf3ce44SJohn Forte 		    }
1979fcf3ce44SJohn Forte 
1980fcf3ce44SJohn Forte 		    /* End element "DiscoveryDomainSetMember. */
1981fcf3ce44SJohn Forte 		    if (xmlTextWriterEndElement(writer) < 0) {
1982fcf3ce44SJohn Forte 			return (ERROR_XML_END_ELEMENT_FAILED);
1983fcf3ce44SJohn Forte 		    }
1984fcf3ce44SJohn Forte 		}
1985fcf3ce44SJohn Forte 		break;
1986fcf3ce44SJohn Forte 	    default:
1987fcf3ce44SJohn Forte 		    xmlFreeTextWriter(writer);
1988fcf3ce44SJohn Forte 		    return (UNKNOWN);
1989fcf3ce44SJohn Forte 	}
1990fcf3ce44SJohn Forte 
1991fcf3ce44SJohn Forte 	/* end createModify */
1992fcf3ce44SJohn Forte 	if (xmlTextWriterEndElement(writer) < 0) {
1993fcf3ce44SJohn Forte 	    xmlFreeTextWriter(writer);
1994fcf3ce44SJohn Forte 	    return (ERROR_XML_END_ELEMENT_FAILED);
1995fcf3ce44SJohn Forte 	}
1996fcf3ce44SJohn Forte 
1997fcf3ce44SJohn Forte 	/* End element "isnsRequest". */
1998fcf3ce44SJohn Forte 	if (xmlTextWriterEndElement(writer) < 0) {
1999fcf3ce44SJohn Forte 	    xmlFreeTextWriter(writer);
2000fcf3ce44SJohn Forte 	    return (ERROR_XML_END_ELEMENT_FAILED);
2001fcf3ce44SJohn Forte 	}
2002fcf3ce44SJohn Forte 	if (xmlTextWriterEndDocument(writer) < 0) {
2003fcf3ce44SJohn Forte 	    xmlFreeTextWriter(writer);
2004fcf3ce44SJohn Forte 	    return (ERROR_XML_END_DOC_FAILED);
2005fcf3ce44SJohn Forte 	}
2006fcf3ce44SJohn Forte 
2007fcf3ce44SJohn Forte 	xmlFreeTextWriter(writer);
2008fcf3ce44SJohn Forte 
2009fcf3ce44SJohn Forte 	len = xmlStrlen(xbuf->content) + 1;
2010fcf3ce44SJohn Forte 	/* XXX - copy NULL at the end by having one more extra byte */
2011fcf3ce44SJohn Forte 	if ((*doc = xmlStrndup(xbuf->content, len)) == NULL) {
2012fcf3ce44SJohn Forte 	    return (ERROR_XML_STRDUP_FAILED);
2013fcf3ce44SJohn Forte 	}
2014fcf3ce44SJohn Forte 
2015fcf3ce44SJohn Forte 	xmlBufferFree(xbuf);
2016fcf3ce44SJohn Forte 
2017fcf3ce44SJohn Forte 	return (0);
2018fcf3ce44SJohn Forte }
2019fcf3ce44SJohn Forte 
2020fcf3ce44SJohn Forte /*
2021fcf3ce44SJohn Forte  * ****************************************************************************
2022fcf3ce44SJohn Forte  *
2023fcf3ce44SJohn Forte  * build_assoc_xml_doc -
2024fcf3ce44SJohn Forte  *	build association request doc based the name.
2025fcf3ce44SJohn Forte  *	the resulted doc is passed in the doc ptr.
2026fcf3ce44SJohn Forte  *
2027fcf3ce44SJohn Forte  * name		- object type
2028fcf3ce44SJohn Forte  * assoc	- association type
2029fcf3ce44SJohn Forte  * doc		- ptr to the resulted doc
2030fcf3ce44SJohn Forte  *
2031fcf3ce44SJohn Forte  * ****************************************************************************
2032fcf3ce44SJohn Forte  */
2033fcf3ce44SJohn Forte static int
2034fcf3ce44SJohn Forte build_assoc_xml_doc(xmlChar *name, association_t assoc, xmlChar **doc)
2035fcf3ce44SJohn Forte {
2036fcf3ce44SJohn Forte 	xmlTextWriterPtr writer;
2037fcf3ce44SJohn Forte 	xmlBufferPtr xbuf;
2038fcf3ce44SJohn Forte 	int len;
2039fcf3ce44SJohn Forte 
2040fcf3ce44SJohn Forte 	if ((xbuf = xmlBufferCreate()) == NULL) {
2041fcf3ce44SJohn Forte 		return (ERROR_XML_CREATE_BUFFER_FAILED);
2042fcf3ce44SJohn Forte 	}
2043fcf3ce44SJohn Forte 
2044fcf3ce44SJohn Forte 	if ((writer = xmlNewTextWriterMemory(xbuf, 0)) == NULL) {
2045fcf3ce44SJohn Forte 		return (ERROR_XML_CREATE_WRITER_FAILED);
2046fcf3ce44SJohn Forte 	}
2047fcf3ce44SJohn Forte 
2048fcf3ce44SJohn Forte 	if (xmlTextWriterStartDocument(writer, "1.0", NULL, NULL) < 0) {
2049fcf3ce44SJohn Forte 		return (ERROR_XML_START_DOC_FAILED);
2050fcf3ce44SJohn Forte 	}
2051fcf3ce44SJohn Forte 
2052fcf3ce44SJohn Forte 	/* Start element "isnsRequest". */
2053fcf3ce44SJohn Forte 	if (xmlTextWriterStartElement(writer, (xmlChar *)ISNSREQUEST) < 0) {
2054fcf3ce44SJohn Forte 	    return (ERROR_XML_START_ELEMENT_FAILED);
2055fcf3ce44SJohn Forte 	}
2056fcf3ce44SJohn Forte 
2057fcf3ce44SJohn Forte 	/* request getAssociated operation to get the entire list of obejct. */
2058fcf3ce44SJohn Forte 	if (xmlTextWriterStartElement(writer, (xmlChar *)GETASSOCIATED) < 0) {
2059fcf3ce44SJohn Forte 		return (ERROR_XML_START_ELEMENT_FAILED);
2060fcf3ce44SJohn Forte 	}
2061fcf3ce44SJohn Forte 
2062fcf3ce44SJohn Forte 	switch (assoc) {
2063fcf3ce44SJohn Forte 	    case (node_to_dd):
2064fcf3ce44SJohn Forte 		/* write association type. */
2065fcf3ce44SJohn Forte 		if (xmlTextWriterWriteElement(writer,
2066fcf3ce44SJohn Forte 		    (xmlChar *)ASSOCIATIONTYPE,
2067fcf3ce44SJohn Forte 		    (xmlChar *)DDOBJECTMEMBER) < 0) {
2068fcf3ce44SJohn Forte 		    return (ERROR_XML_WRITE_ELEMENT_FAILED);
2069fcf3ce44SJohn Forte 		}
2070fcf3ce44SJohn Forte 
2071fcf3ce44SJohn Forte 		if (xmlTextWriterStartElement(writer,
2072fcf3ce44SJohn Forte 		    (xmlChar *)ISNSOBJECT) < 0) {
2073fcf3ce44SJohn Forte 		    return (ERROR_XML_START_ELEMENT_FAILED);
2074fcf3ce44SJohn Forte 		}
2075fcf3ce44SJohn Forte 
2076fcf3ce44SJohn Forte 		if (xmlTextWriterStartElement(writer,
2077fcf3ce44SJohn Forte 		    (xmlChar *)NODEOBJECT) < 0) {
2078fcf3ce44SJohn Forte 		    return (ERROR_XML_START_ELEMENT_FAILED);
2079fcf3ce44SJohn Forte 		}
2080fcf3ce44SJohn Forte 
2081fcf3ce44SJohn Forte 		/* Start attr "name". */
2082fcf3ce44SJohn Forte 		if (xmlTextWriterWriteAttribute(writer,
2083fcf3ce44SJohn Forte 		    (xmlChar *)NAMEATTR, name) < 0) {
2084fcf3ce44SJohn Forte 		    return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
2085fcf3ce44SJohn Forte 		}
2086fcf3ce44SJohn Forte 		if (xmlTextWriterWriteAttribute(writer,
2087fcf3ce44SJohn Forte 		    (xmlChar *)TYPEATTR, (xmlChar *)EMPTYSTR) < 0) {
2088fcf3ce44SJohn Forte 		    return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
2089fcf3ce44SJohn Forte 		}
2090fcf3ce44SJohn Forte 		if (xmlTextWriterWriteAttribute(writer,
2091fcf3ce44SJohn Forte 		    (xmlChar *)ALIASATTR, (xmlChar *)EMPTYSTR) < 0) {
2092fcf3ce44SJohn Forte 		    return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
2093fcf3ce44SJohn Forte 		}
2094fcf3ce44SJohn Forte 
2095fcf3ce44SJohn Forte 		/* End element "Node". */
2096fcf3ce44SJohn Forte 		if (xmlTextWriterEndElement(writer) < 0) {
2097fcf3ce44SJohn Forte 		    return (ERROR_XML_END_ELEMENT_FAILED);
2098fcf3ce44SJohn Forte 		}
2099fcf3ce44SJohn Forte 
2100fcf3ce44SJohn Forte 		/* End element "isnsObject". */
2101fcf3ce44SJohn Forte 		if (xmlTextWriterEndElement(writer) < 0) {
2102fcf3ce44SJohn Forte 		    return (ERROR_XML_END_ELEMENT_FAILED);
2103fcf3ce44SJohn Forte 		}
2104fcf3ce44SJohn Forte 		break;
2105fcf3ce44SJohn Forte 	    case (dd_to_node):
2106fcf3ce44SJohn Forte 		/* write association type. */
2107fcf3ce44SJohn Forte 		if (xmlTextWriterWriteElement(writer,
2108fcf3ce44SJohn Forte 		    (xmlChar *)ASSOCIATIONTYPE,
2109fcf3ce44SJohn Forte 		    (xmlChar *)DDOBJECTMEMBER) < 0) {
2110fcf3ce44SJohn Forte 		    return (ERROR_XML_WRITE_ELEMENT_FAILED);
2111fcf3ce44SJohn Forte 		}
2112fcf3ce44SJohn Forte 
2113fcf3ce44SJohn Forte 		/* start isnsObject */
2114fcf3ce44SJohn Forte 		if (xmlTextWriterStartElement(writer,
2115fcf3ce44SJohn Forte 		    (xmlChar *)ISNSOBJECT) < 0) {
2116fcf3ce44SJohn Forte 		    return (ERROR_XML_START_ELEMENT_FAILED);
2117fcf3ce44SJohn Forte 		}
2118fcf3ce44SJohn Forte 
2119fcf3ce44SJohn Forte 		/* start DiscoveryDomain */
2120fcf3ce44SJohn Forte 		if (xmlTextWriterStartElement(writer,
2121fcf3ce44SJohn Forte 		    (xmlChar *)DDOBJECT) < 0) {
2122fcf3ce44SJohn Forte 		    return (ERROR_XML_START_ELEMENT_FAILED);
2123fcf3ce44SJohn Forte 		}
2124fcf3ce44SJohn Forte 
2125fcf3ce44SJohn Forte 		/* Start attr "name". */
2126fcf3ce44SJohn Forte 		if (xmlTextWriterWriteAttribute(writer,
2127fcf3ce44SJohn Forte 		    (xmlChar *)NAMEATTR, name) < 0) {
2128fcf3ce44SJohn Forte 		    return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
2129fcf3ce44SJohn Forte 		}
2130fcf3ce44SJohn Forte 
2131fcf3ce44SJohn Forte 		/* End element "DiscoveryDomain". */
2132fcf3ce44SJohn Forte 		if (xmlTextWriterEndElement(writer) < 0) {
2133fcf3ce44SJohn Forte 		    return (ERROR_XML_END_ELEMENT_FAILED);
2134fcf3ce44SJohn Forte 		}
2135fcf3ce44SJohn Forte 
2136fcf3ce44SJohn Forte 		/* End element "isnsObject". */
2137fcf3ce44SJohn Forte 		if (xmlTextWriterEndElement(writer) < 0) {
2138fcf3ce44SJohn Forte 		    return (ERROR_XML_END_ELEMENT_FAILED);
2139fcf3ce44SJohn Forte 		}
2140fcf3ce44SJohn Forte 		break;
2141fcf3ce44SJohn Forte 	    case (ddset_to_dd):
2142fcf3ce44SJohn Forte 		/* write association type. */
2143fcf3ce44SJohn Forte 		if (xmlTextWriterWriteElement(writer,
2144fcf3ce44SJohn Forte 		    (xmlChar *)ASSOCIATIONTYPE,
2145fcf3ce44SJohn Forte 		    (xmlChar *)DDSETOBJECTMEMBER) < 0) {
2146fcf3ce44SJohn Forte 		    return (ERROR_XML_WRITE_ELEMENT_FAILED);
2147fcf3ce44SJohn Forte 		}
2148fcf3ce44SJohn Forte 
2149fcf3ce44SJohn Forte 		/* start isnsObject */
2150fcf3ce44SJohn Forte 		if (xmlTextWriterStartElement(writer,
2151fcf3ce44SJohn Forte 		    (xmlChar *)ISNSOBJECT) < 0) {
2152fcf3ce44SJohn Forte 		    return (ERROR_XML_START_ELEMENT_FAILED);
2153fcf3ce44SJohn Forte 		}
2154fcf3ce44SJohn Forte 
2155fcf3ce44SJohn Forte 		/* start DiscoveryDomainSet */
2156fcf3ce44SJohn Forte 		if (xmlTextWriterStartElement(writer,
2157fcf3ce44SJohn Forte 		    (xmlChar *)DDSETOBJECT) < 0) {
2158fcf3ce44SJohn Forte 		    return (ERROR_XML_START_ELEMENT_FAILED);
2159fcf3ce44SJohn Forte 		}
2160fcf3ce44SJohn Forte 
2161fcf3ce44SJohn Forte 		/* Start attr "name". */
2162fcf3ce44SJohn Forte 		if (xmlTextWriterWriteAttribute(writer,
2163fcf3ce44SJohn Forte 		    (xmlChar *)NAMEATTR, name) < 0) {
2164fcf3ce44SJohn Forte 		    return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
2165fcf3ce44SJohn Forte 		}
2166fcf3ce44SJohn Forte 
2167fcf3ce44SJohn Forte 		/* End element "DiscoveryDomain". */
2168fcf3ce44SJohn Forte 		if (xmlTextWriterEndElement(writer) < 0) {
2169fcf3ce44SJohn Forte 		    return (ERROR_XML_END_ELEMENT_FAILED);
2170fcf3ce44SJohn Forte 		}
2171fcf3ce44SJohn Forte 
2172fcf3ce44SJohn Forte 		/* End element "isnsObject". */
2173fcf3ce44SJohn Forte 		if (xmlTextWriterEndElement(writer) < 0) {
2174fcf3ce44SJohn Forte 		    return (ERROR_XML_END_ELEMENT_FAILED);
2175fcf3ce44SJohn Forte 		}
2176fcf3ce44SJohn Forte 		break;
2177fcf3ce44SJohn Forte 	    case (dd_to_ddset):
2178fcf3ce44SJohn Forte 		/* write association type. */
2179fcf3ce44SJohn Forte 		if (xmlTextWriterWriteElement(writer,
2180fcf3ce44SJohn Forte 		    (xmlChar *)ASSOCIATIONTYPE,
2181fcf3ce44SJohn Forte 		    (xmlChar *)DDSETOBJECTMEMBER) < 0) {
2182fcf3ce44SJohn Forte 		    return (ERROR_XML_WRITE_ELEMENT_FAILED);
2183fcf3ce44SJohn Forte 		}
2184fcf3ce44SJohn Forte 
2185fcf3ce44SJohn Forte 		/* start isnsObject */
2186fcf3ce44SJohn Forte 		if (xmlTextWriterStartElement(writer,
2187fcf3ce44SJohn Forte 		    (xmlChar *)ISNSOBJECT) < 0) {
2188fcf3ce44SJohn Forte 		    return (ERROR_XML_START_ELEMENT_FAILED);
2189fcf3ce44SJohn Forte 		}
2190fcf3ce44SJohn Forte 
2191fcf3ce44SJohn Forte 		/* start DiscoveryDomain */
2192fcf3ce44SJohn Forte 		if (xmlTextWriterStartElement(writer,
2193fcf3ce44SJohn Forte 		    (xmlChar *)DDOBJECT) < 0) {
2194fcf3ce44SJohn Forte 		    return (ERROR_XML_START_ELEMENT_FAILED);
2195fcf3ce44SJohn Forte 		}
2196fcf3ce44SJohn Forte 
2197fcf3ce44SJohn Forte 		/* Start attr "name". */
2198fcf3ce44SJohn Forte 		if (xmlTextWriterWriteAttribute(writer,
2199fcf3ce44SJohn Forte 		    (xmlChar *)NAMEATTR, name) < 0) {
2200fcf3ce44SJohn Forte 		    return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
2201fcf3ce44SJohn Forte 		}
2202fcf3ce44SJohn Forte 
2203fcf3ce44SJohn Forte 		/* End element "DiscoveryDomain". */
2204fcf3ce44SJohn Forte 		if (xmlTextWriterEndElement(writer) < 0) {
2205fcf3ce44SJohn Forte 		    return (ERROR_XML_END_ELEMENT_FAILED);
2206fcf3ce44SJohn Forte 		}
2207fcf3ce44SJohn Forte 
2208fcf3ce44SJohn Forte 		/* End element "isnsObject". */
2209fcf3ce44SJohn Forte 		if (xmlTextWriterEndElement(writer) < 0) {
2210fcf3ce44SJohn Forte 		    return (ERROR_XML_END_ELEMENT_FAILED);
2211fcf3ce44SJohn Forte 		}
2212fcf3ce44SJohn Forte 		break;
2213fcf3ce44SJohn Forte 	    default:
2214fcf3ce44SJohn Forte 		return (UNKNOWN);
2215fcf3ce44SJohn Forte 	}
2216fcf3ce44SJohn Forte 
2217fcf3ce44SJohn Forte 	/* end getAssociated */
2218fcf3ce44SJohn Forte 	if (xmlTextWriterEndElement(writer) < 0) {
2219fcf3ce44SJohn Forte 		return (ERROR_XML_END_ELEMENT_FAILED);
2220fcf3ce44SJohn Forte 	}
2221fcf3ce44SJohn Forte 
2222fcf3ce44SJohn Forte 	/* End element "isnsRequest". */
2223fcf3ce44SJohn Forte 	if (xmlTextWriterEndElement(writer) < 0) {
2224fcf3ce44SJohn Forte 	    return (ERROR_XML_END_ELEMENT_FAILED);
2225fcf3ce44SJohn Forte 	}
2226fcf3ce44SJohn Forte 	if (xmlTextWriterEndDocument(writer) < 0) {
2227fcf3ce44SJohn Forte 	    return (ERROR_XML_END_DOC_FAILED);
2228fcf3ce44SJohn Forte 	}
2229fcf3ce44SJohn Forte 
2230fcf3ce44SJohn Forte 	xmlFreeTextWriter(writer);
2231fcf3ce44SJohn Forte 
2232fcf3ce44SJohn Forte 	len = xmlStrlen(xbuf->content) + 1;
2233fcf3ce44SJohn Forte 	/* XXX - copy NULL at the end by having one more extra byte */
2234fcf3ce44SJohn Forte 	if ((*doc = xmlStrndup(xbuf->content, len)) == NULL) {
2235fcf3ce44SJohn Forte 	    return (ERROR_XML_STRDUP_FAILED);
2236fcf3ce44SJohn Forte 	}
2237fcf3ce44SJohn Forte 
2238fcf3ce44SJohn Forte 	xmlBufferFree(xbuf);
2239fcf3ce44SJohn Forte 	return (0);
2240fcf3ce44SJohn Forte }
2241fcf3ce44SJohn Forte 
2242fcf3ce44SJohn Forte /*
2243fcf3ce44SJohn Forte  * ****************************************************************************
2244fcf3ce44SJohn Forte  *
2245fcf3ce44SJohn Forte  * build_enumerate_xml_doc -
2246fcf3ce44SJohn Forte  *	build association request doc based the name.
2247fcf3ce44SJohn Forte  *	the resulted doc is passed in the doc ptr.
2248fcf3ce44SJohn Forte  *
2249fcf3ce44SJohn Forte  * name		- object type
2250fcf3ce44SJohn Forte  * doc		- ptr to the resulted doc
2251fcf3ce44SJohn Forte  *
2252fcf3ce44SJohn Forte  * ****************************************************************************
2253fcf3ce44SJohn Forte  */
2254fcf3ce44SJohn Forte static int
2255fcf3ce44SJohn Forte build_enumerate_xml_doc(object_type obj, xmlChar **doc)
2256fcf3ce44SJohn Forte {
2257fcf3ce44SJohn Forte 	xmlTextWriterPtr writer;
2258fcf3ce44SJohn Forte 	xmlBufferPtr xbuf;
2259fcf3ce44SJohn Forte 	int len;
2260fcf3ce44SJohn Forte 
2261fcf3ce44SJohn Forte 	if ((xbuf = xmlBufferCreate()) == NULL) {
2262fcf3ce44SJohn Forte 		return (ERROR_XML_CREATE_BUFFER_FAILED);
2263fcf3ce44SJohn Forte 	}
2264fcf3ce44SJohn Forte 
2265fcf3ce44SJohn Forte 	if ((writer = xmlNewTextWriterMemory(xbuf, 0)) == NULL) {
2266fcf3ce44SJohn Forte 		return (ERROR_XML_CREATE_WRITER_FAILED);
2267fcf3ce44SJohn Forte 	}
2268fcf3ce44SJohn Forte 
2269fcf3ce44SJohn Forte 	if (xmlTextWriterStartDocument(writer, "1.0", NULL, NULL) < 0) {
2270fcf3ce44SJohn Forte 		return (ERROR_XML_START_DOC_FAILED);
2271fcf3ce44SJohn Forte 	}
2272fcf3ce44SJohn Forte 
2273fcf3ce44SJohn Forte 	/* Start element "isnsRequest". */
2274fcf3ce44SJohn Forte 	if (xmlTextWriterStartElement(writer, (xmlChar *)ISNSREQUEST) < 0) {
2275fcf3ce44SJohn Forte 	    return (ERROR_XML_START_ELEMENT_FAILED);
2276fcf3ce44SJohn Forte 	}
2277fcf3ce44SJohn Forte 
2278fcf3ce44SJohn Forte 	/* Start attr "xmlns". */
2279fcf3ce44SJohn Forte 	if (xmlTextWriterWriteAttribute(writer,
2280fcf3ce44SJohn Forte 	    (xmlChar *)"xmlns",
2281fcf3ce44SJohn Forte 	    (xmlChar *)"http://www.sun.com/schema/isnsmanagement")) {
2282fcf3ce44SJohn Forte 	    return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
2283fcf3ce44SJohn Forte 	}
2284fcf3ce44SJohn Forte 
2285fcf3ce44SJohn Forte 	/* request enumerate operation to get the entire list of obejct. */
2286fcf3ce44SJohn Forte 	if (xmlTextWriterStartElement(writer, (xmlChar *)ENUMERATE) < 0) {
2287fcf3ce44SJohn Forte 	    return (ERROR_XML_START_ELEMENT_FAILED);
2288fcf3ce44SJohn Forte 	}
2289fcf3ce44SJohn Forte 
2290fcf3ce44SJohn Forte 	switch (obj) {
2291fcf3ce44SJohn Forte 	    case (Node):
2292fcf3ce44SJohn Forte 		if (xmlTextWriterWriteElement(writer,
2293fcf3ce44SJohn Forte 		    (xmlChar *)ISNSOBJECTTYPE, (xmlChar *)NODEOBJECT) < 0) {
2294fcf3ce44SJohn Forte 		    return (ERROR_XML_WRITE_ELEMENT_FAILED);
2295fcf3ce44SJohn Forte 		}
2296fcf3ce44SJohn Forte 		break;
2297fcf3ce44SJohn Forte 	    case (DiscoveryDomain):
2298fcf3ce44SJohn Forte 		if (xmlTextWriterWriteElement(writer,
2299fcf3ce44SJohn Forte 		    (xmlChar *)ISNSOBJECTTYPE,
2300fcf3ce44SJohn Forte 		    (xmlChar *)DDOBJECT) < 0) {
2301fcf3ce44SJohn Forte 		    return (ERROR_XML_WRITE_ELEMENT_FAILED);
2302fcf3ce44SJohn Forte 		}
2303fcf3ce44SJohn Forte 		break;
2304fcf3ce44SJohn Forte 	    case (DiscoveryDomainSet):
2305fcf3ce44SJohn Forte 		if (xmlTextWriterWriteElement(writer,
2306fcf3ce44SJohn Forte 		    (xmlChar *)ISNSOBJECTTYPE,
2307fcf3ce44SJohn Forte 		    (xmlChar *)DDSETOBJECT) < 0) {
2308fcf3ce44SJohn Forte 		    return (ERROR_XML_WRITE_ELEMENT_FAILED);
2309fcf3ce44SJohn Forte 		}
2310fcf3ce44SJohn Forte 		break;
2311fcf3ce44SJohn Forte 	    default:
2312fcf3ce44SJohn Forte 		return (UNKNOWN);
2313fcf3ce44SJohn Forte 	}
2314fcf3ce44SJohn Forte 
2315fcf3ce44SJohn Forte 	/* end isns object type */
2316fcf3ce44SJohn Forte 	if (xmlTextWriterEndElement(writer) < 0) {
2317fcf3ce44SJohn Forte 	    return (ERROR_XML_END_ELEMENT_FAILED);
2318fcf3ce44SJohn Forte 	}
2319fcf3ce44SJohn Forte 
2320fcf3ce44SJohn Forte 	/* End element "isnsRequest". */
2321fcf3ce44SJohn Forte 	if (xmlTextWriterEndElement(writer) < 0) {
2322fcf3ce44SJohn Forte 	    return (ERROR_XML_END_ELEMENT_FAILED);
2323fcf3ce44SJohn Forte 	}
2324fcf3ce44SJohn Forte 	if (xmlTextWriterEndDocument(writer) < 0) {
2325fcf3ce44SJohn Forte 	    return (ERROR_XML_END_DOC_FAILED);
2326fcf3ce44SJohn Forte 	}
2327fcf3ce44SJohn Forte 
2328fcf3ce44SJohn Forte 	xmlFreeTextWriter(writer);
2329fcf3ce44SJohn Forte 
2330fcf3ce44SJohn Forte 	len = xmlStrlen(xbuf->content) + 1;
2331fcf3ce44SJohn Forte 	/* XXX - copy NULL at the end by having one more extra byte */
2332fcf3ce44SJohn Forte 	if ((*doc = xmlStrndup(xbuf->content, len)) == NULL) {
2333fcf3ce44SJohn Forte 	    return (ERROR_XML_STRDUP_FAILED);
2334fcf3ce44SJohn Forte 	}
2335fcf3ce44SJohn Forte 
2336fcf3ce44SJohn Forte 	xmlBufferFree(xbuf);
2337fcf3ce44SJohn Forte 	return (0);
2338fcf3ce44SJohn Forte }
2339fcf3ce44SJohn Forte 
2340fcf3ce44SJohn Forte /*
2341fcf3ce44SJohn Forte  * ****************************************************************************
2342fcf3ce44SJohn Forte  *
2343fcf3ce44SJohn Forte  * build_get_xml_doc -
2344fcf3ce44SJohn Forte  *	build association request doc based the name.
2345fcf3ce44SJohn Forte  *	the resulted doc is passed in the doc ptr.
2346fcf3ce44SJohn Forte  *
2347fcf3ce44SJohn Forte  * name		- object type
2348fcf3ce44SJohn Forte  * assoc	- association type
2349fcf3ce44SJohn Forte  * doc		- ptr to the resulted doc
2350fcf3ce44SJohn Forte  *
2351fcf3ce44SJohn Forte  * ****************************************************************************
2352fcf3ce44SJohn Forte  */
2353fcf3ce44SJohn Forte static int
2354fcf3ce44SJohn Forte build_get_xml_doc(int operandLen, char **operand, object_type obj,
2355fcf3ce44SJohn Forte 	xmlChar **doc)
2356fcf3ce44SJohn Forte {
2357fcf3ce44SJohn Forte 	xmlTextWriterPtr writer;
2358fcf3ce44SJohn Forte 	xmlBufferPtr xbuf;
2359fcf3ce44SJohn Forte 	int i, len;
2360fcf3ce44SJohn Forte 
2361fcf3ce44SJohn Forte 	if ((xbuf = xmlBufferCreate()) == NULL) {
2362fcf3ce44SJohn Forte 		return (ERROR_XML_CREATE_BUFFER_FAILED);
2363fcf3ce44SJohn Forte 	}
2364fcf3ce44SJohn Forte 
2365fcf3ce44SJohn Forte 	if ((writer = xmlNewTextWriterMemory(xbuf, 0)) == NULL) {
2366fcf3ce44SJohn Forte 		return (ERROR_XML_CREATE_WRITER_FAILED);
2367fcf3ce44SJohn Forte 	}
2368fcf3ce44SJohn Forte 
2369fcf3ce44SJohn Forte 	if (xmlTextWriterStartDocument(writer, "1.0", NULL, NULL) < 0) {
2370fcf3ce44SJohn Forte 		return (ERROR_XML_START_DOC_FAILED);
2371fcf3ce44SJohn Forte 	}
2372fcf3ce44SJohn Forte 
2373fcf3ce44SJohn Forte 	/* Start element "isnsRequest". */
2374fcf3ce44SJohn Forte 	if (xmlTextWriterStartElement(writer, (xmlChar *)ISNSREQUEST) < 0) {
2375fcf3ce44SJohn Forte 	    return (ERROR_XML_START_ELEMENT_FAILED);
2376fcf3ce44SJohn Forte 	}
2377fcf3ce44SJohn Forte 
2378fcf3ce44SJohn Forte 	/* Start attr "xmlns". */
2379fcf3ce44SJohn Forte 	if (xmlTextWriterWriteAttribute(writer,
2380fcf3ce44SJohn Forte 	    (xmlChar *)"xmlns",
2381fcf3ce44SJohn Forte 	    (xmlChar *)"http://www.sun.com/schema/isnsmanagement")) {
2382fcf3ce44SJohn Forte 	    return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
2383fcf3ce44SJohn Forte 	}
2384fcf3ce44SJohn Forte 
2385fcf3ce44SJohn Forte 	/* Start element "get". */
2386fcf3ce44SJohn Forte 	if (xmlTextWriterStartElement(writer, (xmlChar *)GET) < 0) {
2387fcf3ce44SJohn Forte 	    return (ERROR_XML_START_ELEMENT_FAILED);
2388fcf3ce44SJohn Forte 	}
2389fcf3ce44SJohn Forte 
2390fcf3ce44SJohn Forte 	switch (obj) {
2391fcf3ce44SJohn Forte 	    case (Node):
2392fcf3ce44SJohn Forte 		for (i = 0; i < operandLen; i++) {
2393fcf3ce44SJohn Forte 		    /* Start element "isnsObject". */
2394fcf3ce44SJohn Forte 		    if (xmlTextWriterStartElement(writer,
2395fcf3ce44SJohn Forte 			(xmlChar *)ISNSOBJECT) < 0) {
2396fcf3ce44SJohn Forte 			return (ERROR_XML_START_ELEMENT_FAILED);
2397fcf3ce44SJohn Forte 		    }
2398fcf3ce44SJohn Forte 
2399fcf3ce44SJohn Forte 		    /* Start element Node. */
2400fcf3ce44SJohn Forte 		    if (xmlTextWriterStartElement(writer,
2401fcf3ce44SJohn Forte 			(xmlChar *)NODEOBJECT) < 0) {
2402fcf3ce44SJohn Forte 			return (ERROR_XML_START_ELEMENT_FAILED);
2403fcf3ce44SJohn Forte 		    }
2404fcf3ce44SJohn Forte 
2405fcf3ce44SJohn Forte 		    /* Start attr "name". */
2406fcf3ce44SJohn Forte 		    if (xmlTextWriterWriteAttribute(writer,
2407fcf3ce44SJohn Forte 			(xmlChar *)NAMEATTR, (xmlChar *)operand[i]) < 0) {
2408fcf3ce44SJohn Forte 			return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
2409fcf3ce44SJohn Forte 		    }
2410fcf3ce44SJohn Forte 		    if (xmlTextWriterWriteAttribute(writer,
2411fcf3ce44SJohn Forte 			(xmlChar *)TYPEATTR, (xmlChar *)EMPTYSTR) < 0) {
2412fcf3ce44SJohn Forte 			return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
2413fcf3ce44SJohn Forte 		    }
2414fcf3ce44SJohn Forte 		    if (xmlTextWriterWriteAttribute(writer,
2415fcf3ce44SJohn Forte 			(xmlChar *)ALIASATTR, (xmlChar *)EMPTYSTR) < 0) {
2416fcf3ce44SJohn Forte 			return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
2417fcf3ce44SJohn Forte 		    }
2418fcf3ce44SJohn Forte 
2419fcf3ce44SJohn Forte 		    /* End element "Node". */
2420fcf3ce44SJohn Forte 		    if (xmlTextWriterEndElement(writer) < 0) {
2421fcf3ce44SJohn Forte 			return (ERROR_XML_END_ELEMENT_FAILED);
2422fcf3ce44SJohn Forte 		    }
2423fcf3ce44SJohn Forte 
2424fcf3ce44SJohn Forte 		    /* End element "isnsObject". */
2425fcf3ce44SJohn Forte 		    if (xmlTextWriterEndElement(writer) < 0) {
2426fcf3ce44SJohn Forte 			return (ERROR_XML_END_ELEMENT_FAILED);
2427fcf3ce44SJohn Forte 		    }
2428fcf3ce44SJohn Forte 		}
2429fcf3ce44SJohn Forte 		break;
2430fcf3ce44SJohn Forte 	    case (DiscoveryDomain):
2431fcf3ce44SJohn Forte 		    for (i = 0; i < operandLen; i++) {
2432fcf3ce44SJohn Forte 			/* Start element "isnsObject". */
2433fcf3ce44SJohn Forte 			if (xmlTextWriterStartElement(writer,
2434fcf3ce44SJohn Forte 			    (xmlChar *)ISNSOBJECT) < 0) {
2435fcf3ce44SJohn Forte 			    return (ERROR_XML_START_ELEMENT_FAILED);
2436fcf3ce44SJohn Forte 			}
2437fcf3ce44SJohn Forte 
2438fcf3ce44SJohn Forte 			if (xmlTextWriterStartElement(writer,
2439fcf3ce44SJohn Forte 			    (xmlChar *)DDOBJECT) < 0) {
2440fcf3ce44SJohn Forte 			    return (ERROR_XML_START_ELEMENT_FAILED);
2441fcf3ce44SJohn Forte 			}
2442fcf3ce44SJohn Forte 
2443fcf3ce44SJohn Forte 			/* Start attr "name". */
2444fcf3ce44SJohn Forte 			if (xmlTextWriterWriteAttribute(writer,
2445fcf3ce44SJohn Forte 			    (xmlChar *)NAMEATTR, (xmlChar *)operand[i]) < 0) {
2446fcf3ce44SJohn Forte 			    return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
2447fcf3ce44SJohn Forte 			}
2448fcf3ce44SJohn Forte 
2449fcf3ce44SJohn Forte 			/* End element "DiscoveryDomain". */
2450fcf3ce44SJohn Forte 			if (xmlTextWriterEndElement(writer) < 0) {
2451fcf3ce44SJohn Forte 			    return (ERROR_XML_END_ELEMENT_FAILED);
2452fcf3ce44SJohn Forte 			}
2453fcf3ce44SJohn Forte 
2454fcf3ce44SJohn Forte 			/* End element "isnsObject". */
2455fcf3ce44SJohn Forte 			if (xmlTextWriterEndElement(writer) < 0) {
2456fcf3ce44SJohn Forte 			    return (ERROR_XML_END_ELEMENT_FAILED);
2457fcf3ce44SJohn Forte 			}
2458fcf3ce44SJohn Forte 		    }
2459fcf3ce44SJohn Forte 		    break;
2460fcf3ce44SJohn Forte 	    case (DiscoveryDomainSet):
2461fcf3ce44SJohn Forte 		    for (i = 0; i < operandLen; i++) {
2462fcf3ce44SJohn Forte 			/* Start element "isnsObject". */
2463fcf3ce44SJohn Forte 			if (xmlTextWriterStartElement(writer,
2464fcf3ce44SJohn Forte 			    (xmlChar *)ISNSOBJECT) < 0) {
2465fcf3ce44SJohn Forte 			    return (ERROR_XML_START_ELEMENT_FAILED);
2466fcf3ce44SJohn Forte 			}
2467fcf3ce44SJohn Forte 
2468fcf3ce44SJohn Forte 			if (xmlTextWriterStartElement(writer,
2469fcf3ce44SJohn Forte 			    (xmlChar *)DDSETOBJECT) < 0) {
2470fcf3ce44SJohn Forte 			    return (ERROR_XML_START_ELEMENT_FAILED);
2471fcf3ce44SJohn Forte 			}
2472fcf3ce44SJohn Forte 
2473fcf3ce44SJohn Forte 			/* Start attr "name". */
2474fcf3ce44SJohn Forte 			if (xmlTextWriterWriteAttribute(writer,
2475fcf3ce44SJohn Forte 			    (xmlChar *)NAMEATTR, (xmlChar *)operand[i]) < 0) {
2476fcf3ce44SJohn Forte 			    return (ERROR_XML_WRITE_ATTRIBUTE_FAILED);
2477fcf3ce44SJohn Forte 			}
2478fcf3ce44SJohn Forte 
2479fcf3ce44SJohn Forte 			/* End element "DiscoveryDomain". */
2480fcf3ce44SJohn Forte 			if (xmlTextWriterEndElement(writer) < 0) {
2481fcf3ce44SJohn Forte 			    return (ERROR_XML_END_ELEMENT_FAILED);
2482fcf3ce44SJohn Forte 			}
2483fcf3ce44SJohn Forte 
2484fcf3ce44SJohn Forte 			/* End element "isnsObject". */
2485fcf3ce44SJohn Forte 			if (xmlTextWriterEndElement(writer) < 0) {
2486fcf3ce44SJohn Forte 			    return (ERROR_XML_END_ELEMENT_FAILED);
2487fcf3ce44SJohn Forte 			}
2488fcf3ce44SJohn Forte 		    }
2489fcf3ce44SJohn Forte 		    break;
2490fcf3ce44SJohn Forte 	    case (ServerConfig):
2491fcf3ce44SJohn Forte 		if (xmlTextWriterStartElement(writer,
2492fcf3ce44SJohn Forte 		    (xmlChar *)ISNSSERVER) < 0) {
2493fcf3ce44SJohn Forte 		    return (ERROR_XML_START_ELEMENT_FAILED);
2494fcf3ce44SJohn Forte 		}
2495fcf3ce44SJohn Forte 		if (xmlTextWriterEndElement(writer) < 0) {
2496fcf3ce44SJohn Forte 		    return (ERROR_XML_END_ELEMENT_FAILED);
2497fcf3ce44SJohn Forte 		}
2498fcf3ce44SJohn Forte 		break;
2499fcf3ce44SJohn Forte 	    default:
2500fcf3ce44SJohn Forte 	    return (UNKNOWN);
2501fcf3ce44SJohn Forte 	}
2502fcf3ce44SJohn Forte 
2503fcf3ce44SJohn Forte 	/* End element "get". */
2504fcf3ce44SJohn Forte 	if (xmlTextWriterEndElement(writer) < 0) {
2505fcf3ce44SJohn Forte 	    return (ERROR_XML_END_ELEMENT_FAILED);
2506fcf3ce44SJohn Forte 	}
2507fcf3ce44SJohn Forte 	/* End element "isnsRequest". */
2508fcf3ce44SJohn Forte 	if (xmlTextWriterEndElement(writer) < 0) {
2509fcf3ce44SJohn Forte 	    return (ERROR_XML_END_ELEMENT_FAILED);
2510fcf3ce44SJohn Forte 	}
2511fcf3ce44SJohn Forte 	if (xmlTextWriterEndDocument(writer) < 0) {
2512fcf3ce44SJohn Forte 	    return (ERROR_XML_END_DOC_FAILED);
2513fcf3ce44SJohn Forte 	}
2514fcf3ce44SJohn Forte 
2515fcf3ce44SJohn Forte 	xmlFreeTextWriter(writer);
2516fcf3ce44SJohn Forte 
2517fcf3ce44SJohn Forte 	len = xmlStrlen(xbuf->content) + 1;
2518fcf3ce44SJohn Forte 	/* XXX - copy NULL at the end by having one more extra byte */
2519fcf3ce44SJohn Forte 	if ((*doc = xmlStrndup(xbuf->content, len)) == NULL) {
2520fcf3ce44SJohn Forte 	    return (ERROR_XML_STRDUP_FAILED);
2521fcf3ce44SJohn Forte 	}
2522fcf3ce44SJohn Forte 
2523fcf3ce44SJohn Forte 	xmlBufferFree(xbuf);
2524fcf3ce44SJohn Forte 	return (0);
2525fcf3ce44SJohn Forte }
2526fcf3ce44SJohn Forte 
2527fcf3ce44SJohn Forte /*
2528fcf3ce44SJohn Forte  * ****************************************************************************
2529fcf3ce44SJohn Forte  *
2530fcf3ce44SJohn Forte  * list_node_func -
2531fcf3ce44SJohn Forte  * 	isnsadm list-node [options] [<node name>, ...]
2532fcf3ce44SJohn Forte  *
2533fcf3ce44SJohn Forte  * operandLen	- number of operands user passed into the cli
2534fcf3ce44SJohn Forte  * operand	- pointer to operand list from user
2535fcf3ce44SJohn Forte  * options	- pointer to option list from user
2536fcf3ce44SJohn Forte  *
2537fcf3ce44SJohn Forte  * ****************************************************************************
2538fcf3ce44SJohn Forte  */
2539fcf3ce44SJohn Forte /*ARGSUSED*/
2540fcf3ce44SJohn Forte static int
2541fcf3ce44SJohn Forte list_node_func(int operandLen, char *operand[], cmdOptions_t *options,
2542fcf3ce44SJohn Forte 	void *addarg)
2543fcf3ce44SJohn Forte {
2544fcf3ce44SJohn Forte 
2545fcf3ce44SJohn Forte 	cmdOptions_t *optionList = options;
2546fcf3ce44SJohn Forte 	xmlChar *doc, *e_doc;
2547fcf3ce44SJohn Forte 	int ret;
2548fcf3ce44SJohn Forte 	door_arg_t		darg;
2549fcf3ce44SJohn Forte 	int			fd, flag = 0;
2550fcf3ce44SJohn Forte 
2551fcf3ce44SJohn Forte 	for (; optionList->optval; optionList++) {
2552fcf3ce44SJohn Forte 	    switch (optionList->optval) {
2553fcf3ce44SJohn Forte 		case 'i':
2554fcf3ce44SJohn Forte 		    flag |= INITIATOR_ONLY;
2555fcf3ce44SJohn Forte 		    break;
2556fcf3ce44SJohn Forte 		case 't':
2557fcf3ce44SJohn Forte 		    flag |= TARGET_ONLY;
2558fcf3ce44SJohn Forte 		    break;
2559fcf3ce44SJohn Forte 		case 'v':
2560fcf3ce44SJohn Forte 		    flag |= VERBOSE;
2561fcf3ce44SJohn Forte 		    break;
2562fcf3ce44SJohn Forte 		default:
2563fcf3ce44SJohn Forte 		    return (UNKNOWN);
2564fcf3ce44SJohn Forte 	    }
2565fcf3ce44SJohn Forte 	}
2566fcf3ce44SJohn Forte 
2567fcf3ce44SJohn Forte 	if ((fd = open(ISNS_DOOR_NAME, 0)) == -1) {
2568fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_OPEN_FAILED, errno);
2569fcf3ce44SJohn Forte 	    return (ret);
2570fcf3ce44SJohn Forte 	}
2571fcf3ce44SJohn Forte 
2572fcf3ce44SJohn Forte 	/* No operand specified. Issue enumerate. */
2573fcf3ce44SJohn Forte 	if (operandLen == 0) {
2574fcf3ce44SJohn Forte 	    ret = build_enumerate_xml_doc(Node, &doc);
2575fcf3ce44SJohn Forte 	    if (ret != 0) {
2576fcf3ce44SJohn Forte 		(void) close(fd);
2577fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n", getTextMessage(ret));
2578fcf3ce44SJohn Forte 		return (ret);
2579fcf3ce44SJohn Forte 	    }
2580fcf3ce44SJohn Forte 	    bzero(&darg, sizeof (darg));
2581fcf3ce44SJohn Forte 	    darg.data_ptr = (char *)doc;
2582fcf3ce44SJohn Forte 	    darg.data_size = xmlStrlen(doc) + 1;
2583fcf3ce44SJohn Forte 	    darg.rbuf = NULL;
2584fcf3ce44SJohn Forte 	    darg.rsize = 0;
2585fcf3ce44SJohn Forte 
2586fcf3ce44SJohn Forte 	    if ((flag & VERBOSE) == VERBOSE) {
2587fcf3ce44SJohn Forte 		if ((door_call(fd, &darg)) == -1) {
2588fcf3ce44SJohn Forte 		    ret = check_door_error(ERROR_DOOR_CALL_FAILED, errno);
2589fcf3ce44SJohn Forte 		    (void) close(fd);
2590fcf3ce44SJohn Forte 		    (void) xmlFree(doc);
2591fcf3ce44SJohn Forte 		    return (ret);
2592fcf3ce44SJohn Forte 		}
2593fcf3ce44SJohn Forte 
2594fcf3ce44SJohn Forte 		if ((ret = cvt_enumerate_rsp_to_get_req((xmlChar *)darg.rbuf,
2595fcf3ce44SJohn Forte 		    &e_doc, Node, flag)) != 0) {
2596fcf3ce44SJohn Forte 		    (void) munmap(darg.rbuf, darg.rsize);
2597fcf3ce44SJohn Forte 		    (void) close(fd);
2598fcf3ce44SJohn Forte 		    (void) xmlFree(doc);
2599fcf3ce44SJohn Forte 		    if (ret != SUCCESS_WITH_NO_OBJECT) {
2600fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s\n", getTextMessage(ret));
2601fcf3ce44SJohn Forte 		    } else {
2602fcf3ce44SJohn Forte 			ret = SUBCOMMAND_SUCCESS;
2603fcf3ce44SJohn Forte 		    }
2604fcf3ce44SJohn Forte 		    return (ret);
2605fcf3ce44SJohn Forte 		} else {
2606fcf3ce44SJohn Forte 		    (void) munmap(darg.rbuf, darg.rsize);
2607fcf3ce44SJohn Forte 		    (void) xmlFree(doc);
2608fcf3ce44SJohn Forte 		    doc = e_doc;
2609fcf3ce44SJohn Forte 		    bzero(&darg, sizeof (door_arg_t));
2610fcf3ce44SJohn Forte 		    darg.data_ptr = (char *)doc;
2611fcf3ce44SJohn Forte 		    darg.data_size = xmlStrlen(doc) + 1;
2612fcf3ce44SJohn Forte 		    darg.rbuf = NULL;
2613fcf3ce44SJohn Forte 		    darg.rsize = 0;
2614fcf3ce44SJohn Forte 		}
2615fcf3ce44SJohn Forte 	    }
2616fcf3ce44SJohn Forte 	} else {
2617fcf3ce44SJohn Forte 	    if ((ret = build_get_xml_doc(operandLen, operand, Node, &doc)) ==
2618fcf3ce44SJohn Forte 		0) {
2619fcf3ce44SJohn Forte 		bzero(&darg, sizeof (darg));
2620fcf3ce44SJohn Forte 		darg.data_ptr = (char *)doc;
2621fcf3ce44SJohn Forte 		darg.data_size = xmlStrlen(doc) + 1;
2622fcf3ce44SJohn Forte 		darg.rbuf = NULL;
2623fcf3ce44SJohn Forte 		darg.rsize = 0;
2624fcf3ce44SJohn Forte 	    } else {
2625fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n", getTextMessage(ret));
2626fcf3ce44SJohn Forte 		(void) close(fd);
2627fcf3ce44SJohn Forte 		(void) xmlFree(doc);
2628fcf3ce44SJohn Forte 		return (ret);
2629fcf3ce44SJohn Forte 	    }
2630fcf3ce44SJohn Forte 	}
2631fcf3ce44SJohn Forte 
2632fcf3ce44SJohn Forte 	if ((door_call(fd, &darg)) == -1) {
2633fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_CALL_FAILED, errno);
2634fcf3ce44SJohn Forte 	    (void) close(fd);
2635fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
2636fcf3ce44SJohn Forte 	    return (ret);
2637fcf3ce44SJohn Forte 	}
2638fcf3ce44SJohn Forte 
2639fcf3ce44SJohn Forte 	if ((ret = process_get_response(Node, (xmlChar *)darg.rbuf, flag)) !=
2640fcf3ce44SJohn Forte 	    0) {
2641fcf3ce44SJohn Forte 	/*
2642fcf3ce44SJohn Forte 	 * door frame work allocated a buffer when the date lager that rbuf.
2643fcf3ce44SJohn Forte 	 * indicate if munmap is required on rbuf.
2644fcf3ce44SJohn Forte 	 */
2645fcf3ce44SJohn Forte 	    (void) munmap(darg.rbuf, darg.rsize);
2646fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
2647fcf3ce44SJohn Forte 	    (void) close(fd);
2648fcf3ce44SJohn Forte 	    return (ret);
2649fcf3ce44SJohn Forte 	}
2650fcf3ce44SJohn Forte 
2651fcf3ce44SJohn Forte 	(void) munmap(darg.rbuf, darg.rsize);
2652fcf3ce44SJohn Forte 	(void) close(fd);
2653fcf3ce44SJohn Forte 	xmlFree(doc);
2654fcf3ce44SJohn Forte 
2655fcf3ce44SJohn Forte 	return (SUBCOMMAND_SUCCESS);
2656fcf3ce44SJohn Forte }
2657fcf3ce44SJohn Forte 
2658fcf3ce44SJohn Forte /*
2659fcf3ce44SJohn Forte  * ****************************************************************************
2660fcf3ce44SJohn Forte  *
2661fcf3ce44SJohn Forte  * list_dd_func -
2662fcf3ce44SJohn Forte  * 	isnsadm list-dd [options] [<dd name>, ...]
2663fcf3ce44SJohn Forte  *
2664fcf3ce44SJohn Forte  * operandLen	- number of operands user passed into the cli
2665fcf3ce44SJohn Forte  * operand	- pointer to operand list from user
2666fcf3ce44SJohn Forte  * options	- pointer to option list from user
2667fcf3ce44SJohn Forte  *
2668fcf3ce44SJohn Forte  * ****************************************************************************
2669fcf3ce44SJohn Forte  */
2670fcf3ce44SJohn Forte /*ARGSUSED*/
2671fcf3ce44SJohn Forte static int
2672fcf3ce44SJohn Forte list_dd_func(int operandLen, char *operand[], cmdOptions_t *options,
2673fcf3ce44SJohn Forte 	void *addarg)
2674fcf3ce44SJohn Forte {
2675fcf3ce44SJohn Forte 	cmdOptions_t *optionList = options;
2676fcf3ce44SJohn Forte 	xmlChar *doc, *e_doc;
2677fcf3ce44SJohn Forte 	int ret;
2678fcf3ce44SJohn Forte 	door_arg_t		darg;
2679fcf3ce44SJohn Forte 	int			fd, flag = 0;
2680fcf3ce44SJohn Forte 
2681fcf3ce44SJohn Forte 	for (; optionList->optval; optionList++) {
2682fcf3ce44SJohn Forte 	    switch (optionList->optval) {
2683fcf3ce44SJohn Forte 		case 'v':
2684fcf3ce44SJohn Forte 		    flag |= VERBOSE;
2685fcf3ce44SJohn Forte 		    break;
2686fcf3ce44SJohn Forte 	    }
2687fcf3ce44SJohn Forte 	}
2688fcf3ce44SJohn Forte 
2689fcf3ce44SJohn Forte 	if ((fd = open(ISNS_DOOR_NAME, 0)) == -1) {
2690fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_OPEN_FAILED, errno);
2691fcf3ce44SJohn Forte 	    return (ret);
2692fcf3ce44SJohn Forte 	}
2693fcf3ce44SJohn Forte 
2694fcf3ce44SJohn Forte 	/* No operand specified. Issue enumerate. */
2695fcf3ce44SJohn Forte 	if (operandLen == 0) {
2696fcf3ce44SJohn Forte 	    ret = build_enumerate_xml_doc(DiscoveryDomain, &doc);
2697fcf3ce44SJohn Forte 	    if (ret != 0) {
2698fcf3ce44SJohn Forte 		(void) close(fd);
2699fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n", getTextMessage(ret));
2700fcf3ce44SJohn Forte 		return (ret);
2701fcf3ce44SJohn Forte 	    }
2702fcf3ce44SJohn Forte 	    /* get the enumerate resposne first. */
2703fcf3ce44SJohn Forte 	    bzero(&darg, sizeof (darg));
2704fcf3ce44SJohn Forte 	    darg.data_ptr = (char *)doc;
2705fcf3ce44SJohn Forte 	    darg.data_size = xmlStrlen(doc) + 1;
2706fcf3ce44SJohn Forte 	    darg.rbuf = NULL;
2707fcf3ce44SJohn Forte 	    darg.rsize = 0;
2708fcf3ce44SJohn Forte 	    if ((door_call(fd, &darg)) == -1) {
2709fcf3ce44SJohn Forte 		ret = check_door_error(ERROR_DOOR_CALL_FAILED, errno);
2710fcf3ce44SJohn Forte 		(void) close(fd);
2711fcf3ce44SJohn Forte 		(void) xmlFree(doc);
2712fcf3ce44SJohn Forte 		return (ret);
2713fcf3ce44SJohn Forte 	    }
2714fcf3ce44SJohn Forte 	    if ((ret = cvt_enumerate_rsp_to_get_req((xmlChar *)darg.rbuf,
2715fcf3ce44SJohn Forte 		&e_doc, DiscoveryDomain, flag)) != 0) {
2716fcf3ce44SJohn Forte 		(void) munmap(darg.rbuf, darg.rsize);
2717fcf3ce44SJohn Forte 		(void) close(fd);
2718fcf3ce44SJohn Forte 		(void) xmlFree(doc);
2719fcf3ce44SJohn Forte 		if (ret != SUCCESS_WITH_NO_OBJECT) {
2720fcf3ce44SJohn Forte 		    (void) fprintf(stderr, "%s\n", getTextMessage(ret));
2721fcf3ce44SJohn Forte 		} else {
2722fcf3ce44SJohn Forte 		    ret = SUBCOMMAND_SUCCESS;
2723fcf3ce44SJohn Forte 		}
2724fcf3ce44SJohn Forte 		return (ret);
2725fcf3ce44SJohn Forte 	    } else {
2726fcf3ce44SJohn Forte 		(void) munmap(darg.rbuf, darg.rsize);
2727fcf3ce44SJohn Forte 		(void) xmlFree(doc);
2728fcf3ce44SJohn Forte 		doc = e_doc;
2729fcf3ce44SJohn Forte 	    }
2730fcf3ce44SJohn Forte 	} else {
2731fcf3ce44SJohn Forte 	    if ((ret = build_get_xml_doc(operandLen, operand,
2732fcf3ce44SJohn Forte 		DiscoveryDomain, &doc)) != 0) {
2733fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n", getTextMessage(ret));
2734fcf3ce44SJohn Forte 		(void) close(fd);
2735fcf3ce44SJohn Forte 		(void) xmlFree(doc);
2736fcf3ce44SJohn Forte 		return (ret);
2737fcf3ce44SJohn Forte 	    }
2738fcf3ce44SJohn Forte 	}
2739fcf3ce44SJohn Forte 
2740fcf3ce44SJohn Forte 	bzero(&darg, sizeof (darg));
2741fcf3ce44SJohn Forte 	darg.data_ptr = (char *)doc;
2742fcf3ce44SJohn Forte 	darg.data_size = xmlStrlen(doc) + 1;
2743fcf3ce44SJohn Forte 	darg.rbuf = NULL;
2744fcf3ce44SJohn Forte 	darg.rsize = 0;
2745fcf3ce44SJohn Forte 
2746fcf3ce44SJohn Forte 	if ((door_call(fd, &darg)) == -1) {
2747fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_CALL_FAILED, errno);
2748fcf3ce44SJohn Forte 	    (void) close(fd);
2749fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
2750fcf3ce44SJohn Forte 	    return (ret);
2751fcf3ce44SJohn Forte 	}
2752fcf3ce44SJohn Forte 
2753fcf3ce44SJohn Forte 	if ((ret = process_get_response(DiscoveryDomain, (xmlChar *)darg.rbuf,
2754fcf3ce44SJohn Forte 	    flag)) != 0) {
2755fcf3ce44SJohn Forte 	    (void) munmap(darg.rbuf, darg.rsize);
2756fcf3ce44SJohn Forte 	    (void) close(fd);
2757fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
2758fcf3ce44SJohn Forte 	    return (ret);
2759fcf3ce44SJohn Forte 	}
2760fcf3ce44SJohn Forte 
2761fcf3ce44SJohn Forte 	(void) munmap(darg.rbuf, darg.rsize);
2762fcf3ce44SJohn Forte 
2763fcf3ce44SJohn Forte 	(void) close(fd);
2764fcf3ce44SJohn Forte 	xmlFree(doc);
2765fcf3ce44SJohn Forte 
2766fcf3ce44SJohn Forte 	return (SUBCOMMAND_SUCCESS);
2767fcf3ce44SJohn Forte }
2768fcf3ce44SJohn Forte 
2769fcf3ce44SJohn Forte /*
2770fcf3ce44SJohn Forte  * ****************************************************************************
2771fcf3ce44SJohn Forte  *
2772fcf3ce44SJohn Forte  * list_ddset_func -
2773fcf3ce44SJohn Forte  * 	isnsadm list-dd-set [options] [<dd set name>, ...]
2774fcf3ce44SJohn Forte  *
2775fcf3ce44SJohn Forte  * operandLen	- number of operands user passed into the cli
2776fcf3ce44SJohn Forte  * operand	- pointer to operand list from user
2777fcf3ce44SJohn Forte  * options	- pointer to option list from user
2778fcf3ce44SJohn Forte  *
2779fcf3ce44SJohn Forte  * ****************************************************************************
2780fcf3ce44SJohn Forte  */
2781fcf3ce44SJohn Forte /*ARGSUSED*/
2782fcf3ce44SJohn Forte static int
2783fcf3ce44SJohn Forte list_ddset_func(int operandLen, char *operand[], cmdOptions_t *options,
2784fcf3ce44SJohn Forte 	void *addarg)
2785fcf3ce44SJohn Forte {
2786fcf3ce44SJohn Forte 	cmdOptions_t *optionList = options;
2787fcf3ce44SJohn Forte 	xmlChar *doc, *e_doc;
2788fcf3ce44SJohn Forte 	msg_code_t ret;
2789fcf3ce44SJohn Forte 	door_arg_t		darg;
2790fcf3ce44SJohn Forte 	int			fd, flag = 0;
2791fcf3ce44SJohn Forte 
2792fcf3ce44SJohn Forte 	for (; optionList->optval; optionList++) {
2793fcf3ce44SJohn Forte 	    switch (optionList->optval) {
2794fcf3ce44SJohn Forte 		case 'v':
2795fcf3ce44SJohn Forte 		    flag |= VERBOSE;
2796fcf3ce44SJohn Forte 		    break;
2797fcf3ce44SJohn Forte 	    }
2798fcf3ce44SJohn Forte 	}
2799fcf3ce44SJohn Forte 
2800fcf3ce44SJohn Forte 	if ((fd = open(ISNS_DOOR_NAME, 0)) == -1) {
2801fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_OPEN_FAILED, errno);
2802fcf3ce44SJohn Forte 	    return (ret);
2803fcf3ce44SJohn Forte 	}
2804fcf3ce44SJohn Forte 
2805fcf3ce44SJohn Forte 	/* No operand specified. Issue enumerate. */
2806fcf3ce44SJohn Forte 	if (operandLen == 0) {
2807fcf3ce44SJohn Forte 	    ret = build_enumerate_xml_doc(DiscoveryDomainSet, &doc);
2808fcf3ce44SJohn Forte 	    if (ret != 0) {
2809fcf3ce44SJohn Forte 		(void) close(fd);
2810fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n", getTextMessage(ret));
2811fcf3ce44SJohn Forte 		return (ret);
2812fcf3ce44SJohn Forte 	    }
2813fcf3ce44SJohn Forte 	    /* get the enumerate resposne. */
2814fcf3ce44SJohn Forte 	    bzero(&darg, sizeof (darg));
2815fcf3ce44SJohn Forte 	    darg.data_ptr = (char *)doc;
2816fcf3ce44SJohn Forte 	    darg.data_size = xmlStrlen(doc) + 1;
2817fcf3ce44SJohn Forte 	    darg.rbuf = NULL;
2818fcf3ce44SJohn Forte 	    darg.rsize = 0;
2819fcf3ce44SJohn Forte 	    if ((door_call(fd, &darg)) == -1) {
2820fcf3ce44SJohn Forte 		ret = check_door_error(ERROR_DOOR_CALL_FAILED, errno);
2821fcf3ce44SJohn Forte 		(void) close(fd);
2822fcf3ce44SJohn Forte 		(void) xmlFree(doc);
2823fcf3ce44SJohn Forte 		return (ret);
2824fcf3ce44SJohn Forte 	    }
2825fcf3ce44SJohn Forte 
2826fcf3ce44SJohn Forte 	    if ((ret = cvt_enumerate_rsp_to_get_req((xmlChar *)darg.rbuf,
2827fcf3ce44SJohn Forte 		&e_doc, DiscoveryDomainSet, flag)) != 0) {
2828fcf3ce44SJohn Forte 		(void) munmap(darg.rbuf, darg.rsize);
2829fcf3ce44SJohn Forte 		(void) close(fd);
2830fcf3ce44SJohn Forte 		(void) xmlFree(doc);
2831fcf3ce44SJohn Forte 		if (ret != SUCCESS_WITH_NO_OBJECT) {
2832fcf3ce44SJohn Forte 		    (void) fprintf(stderr, "%s\n", getTextMessage(ret));
2833fcf3ce44SJohn Forte 		} else {
2834fcf3ce44SJohn Forte 		    ret = SUBCOMMAND_SUCCESS;
2835fcf3ce44SJohn Forte 		}
2836fcf3ce44SJohn Forte 		return (ret);
2837fcf3ce44SJohn Forte 	    } else {
2838fcf3ce44SJohn Forte 		(void) munmap(darg.rbuf, darg.rsize);
2839fcf3ce44SJohn Forte 		(void) xmlFree(doc);
2840fcf3ce44SJohn Forte 		doc = e_doc;
2841fcf3ce44SJohn Forte 		bzero(&darg, sizeof (darg));
2842fcf3ce44SJohn Forte 		darg.data_ptr = (char *)doc;
2843fcf3ce44SJohn Forte 		darg.data_size = xmlStrlen(doc) + 1;
2844fcf3ce44SJohn Forte 		darg.rbuf = NULL;
2845fcf3ce44SJohn Forte 		darg.rsize = 0;
2846fcf3ce44SJohn Forte 	    }
2847fcf3ce44SJohn Forte 	} else {
2848fcf3ce44SJohn Forte 	    if ((ret = build_get_xml_doc(operandLen, operand,
2849fcf3ce44SJohn Forte 		DiscoveryDomainSet, &doc)) == 0) {
2850fcf3ce44SJohn Forte 		bzero(&darg, sizeof (darg));
2851fcf3ce44SJohn Forte 		darg.data_ptr = (char *)doc;
2852fcf3ce44SJohn Forte 		darg.data_size = xmlStrlen(doc) + 1;
2853fcf3ce44SJohn Forte 		darg.rbuf = NULL;
2854fcf3ce44SJohn Forte 		darg.rsize = 0;
2855fcf3ce44SJohn Forte 	    } else {
2856fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n", getTextMessage(ret));
2857fcf3ce44SJohn Forte 	    }
2858fcf3ce44SJohn Forte 	}
2859fcf3ce44SJohn Forte 
2860fcf3ce44SJohn Forte 	if ((door_call(fd, &darg)) == -1) {
2861fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_CALL_FAILED, errno);
2862fcf3ce44SJohn Forte 	    (void) close(fd);
2863fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
2864fcf3ce44SJohn Forte 	    return (ret);
2865fcf3ce44SJohn Forte 	}
2866fcf3ce44SJohn Forte 
2867fcf3ce44SJohn Forte 	/*
2868fcf3ce44SJohn Forte 	 * door frame work allocated a buffer when the date lager that rbuf.
2869fcf3ce44SJohn Forte 	 * indicate if munmap is required on rbuf.
2870fcf3ce44SJohn Forte 	 */
2871fcf3ce44SJohn Forte 	if ((ret = process_get_response(DiscoveryDomainSet,
2872fcf3ce44SJohn Forte 	    (xmlChar *)darg.rbuf, flag)) != 0) {
2873fcf3ce44SJohn Forte 	    (void) munmap(darg.rbuf, darg.rsize);
2874fcf3ce44SJohn Forte 	    (void) close(fd);
2875fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
2876fcf3ce44SJohn Forte 	    return (ret);
2877fcf3ce44SJohn Forte 	}
2878fcf3ce44SJohn Forte 
2879fcf3ce44SJohn Forte 	(void) munmap(darg.rbuf, darg.rsize);
2880fcf3ce44SJohn Forte 	(void) close(fd);
2881fcf3ce44SJohn Forte 	(void) xmlFree(doc);
2882fcf3ce44SJohn Forte 
2883fcf3ce44SJohn Forte 	return (SUBCOMMAND_SUCCESS);
2884fcf3ce44SJohn Forte }
2885fcf3ce44SJohn Forte 
2886fcf3ce44SJohn Forte /*
2887fcf3ce44SJohn Forte  * ****************************************************************************
2888fcf3ce44SJohn Forte  *
2889fcf3ce44SJohn Forte  * create_dd_func -
2890fcf3ce44SJohn Forte  * 	create a DiscoveryDomain create-dd <dd name>, ...
2891fcf3ce44SJohn Forte  *
2892fcf3ce44SJohn Forte  * operandLen	- number of operands user passed into the cli
2893fcf3ce44SJohn Forte  * operand	- pointer to operand list from user
2894fcf3ce44SJohn Forte  * options	- pointer to option list from user
2895fcf3ce44SJohn Forte  *
2896fcf3ce44SJohn Forte  * ****************************************************************************
2897fcf3ce44SJohn Forte  */
2898fcf3ce44SJohn Forte /*ARGSUSED*/
2899fcf3ce44SJohn Forte static int
2900fcf3ce44SJohn Forte create_dd_func(int operandLen, char *operand[], cmdOptions_t *options,
2901fcf3ce44SJohn Forte 	void *addarg)
2902fcf3ce44SJohn Forte {
2903fcf3ce44SJohn Forte 	xmlChar *doc;
2904fcf3ce44SJohn Forte 	msg_code_t ret;
2905fcf3ce44SJohn Forte 	door_arg_t		darg;
2906fcf3ce44SJohn Forte 	int			fd;
2907fcf3ce44SJohn Forte 
2908fcf3ce44SJohn Forte 	if ((fd = open(ISNS_DOOR_NAME, 0)) == -1) {
2909fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_OPEN_FAILED, errno);
2910fcf3ce44SJohn Forte 	    return (ret);
2911fcf3ce44SJohn Forte 	}
2912fcf3ce44SJohn Forte 
2913fcf3ce44SJohn Forte 	if ((ret = build_create_xml_doc(operandLen, operand,
2914fcf3ce44SJohn Forte 		DiscoveryDomain, NULL, &doc)) == 0) {
2915fcf3ce44SJohn Forte 		bzero(&darg, sizeof (darg));
2916fcf3ce44SJohn Forte 		darg.data_ptr = (char *)doc;
2917fcf3ce44SJohn Forte 		darg.data_size = xmlStrlen(doc) + 1;
2918fcf3ce44SJohn Forte 		darg.rbuf = NULL;
2919fcf3ce44SJohn Forte 		darg.rsize = 0;
2920fcf3ce44SJohn Forte 	} else {
2921fcf3ce44SJohn Forte 		(void) close(fd);
2922fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n", getTextMessage(ret));
2923fcf3ce44SJohn Forte 		return (ret);
2924fcf3ce44SJohn Forte 	}
2925fcf3ce44SJohn Forte 
2926fcf3ce44SJohn Forte 	if ((door_call(fd, &darg)) == -1) {
2927fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_CALL_FAILED, errno);
2928fcf3ce44SJohn Forte 	    (void) close(fd);
2929fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
2930fcf3ce44SJohn Forte 	    return (ret);
2931fcf3ce44SJohn Forte 	}
2932fcf3ce44SJohn Forte 
2933fcf3ce44SJohn Forte 	/*
2934fcf3ce44SJohn Forte 	 * door frame work allocated a buffer when the date lager that rbuf.
2935fcf3ce44SJohn Forte 	 * indicate if munmap is required on rbuf.
2936fcf3ce44SJohn Forte 	 */
2937fcf3ce44SJohn Forte 	if ((ret = process_result_response((xmlChar *)darg.rbuf,
2938fcf3ce44SJohn Forte 		DiscoveryDomain)) != 0) {
2939fcf3ce44SJohn Forte 	    (void) munmap(darg.rbuf, darg.rsize);
2940fcf3ce44SJohn Forte 	    (void) close(fd);
2941fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
2942fcf3ce44SJohn Forte 	    return (ret);
2943fcf3ce44SJohn Forte 	}
2944fcf3ce44SJohn Forte 
2945fcf3ce44SJohn Forte 	(void) munmap(darg.rbuf, darg.rsize);
2946fcf3ce44SJohn Forte 	(void) close(fd);
2947fcf3ce44SJohn Forte 	xmlFree(doc);
2948fcf3ce44SJohn Forte 
2949fcf3ce44SJohn Forte 	return (SUBCOMMAND_SUCCESS);
2950fcf3ce44SJohn Forte }
2951fcf3ce44SJohn Forte 
2952fcf3ce44SJohn Forte /*
2953fcf3ce44SJohn Forte  * ****************************************************************************
2954fcf3ce44SJohn Forte  *
2955fcf3ce44SJohn Forte  * create_ddset_func -
2956fcf3ce44SJohn Forte  * 	create a DiscoveryDomainSet create-dd-set <dd set name>, ...
2957fcf3ce44SJohn Forte  *
2958fcf3ce44SJohn Forte  * operandLen	- number of operands user passed into the cli
2959fcf3ce44SJohn Forte  * operand	- pointer to operand list from user
2960fcf3ce44SJohn Forte  * options	- pointer to option list from user
2961fcf3ce44SJohn Forte  *
2962fcf3ce44SJohn Forte  * ****************************************************************************
2963fcf3ce44SJohn Forte  */
2964fcf3ce44SJohn Forte /*ARGSUSED*/
2965fcf3ce44SJohn Forte static int
2966fcf3ce44SJohn Forte create_ddset_func(int operandLen, char *operand[], cmdOptions_t *options,
2967fcf3ce44SJohn Forte     void *addarg)
2968fcf3ce44SJohn Forte {
2969fcf3ce44SJohn Forte 	xmlChar *doc;
2970fcf3ce44SJohn Forte 	msg_code_t ret;
2971fcf3ce44SJohn Forte 	door_arg_t		darg;
2972fcf3ce44SJohn Forte 	int			fd;
2973fcf3ce44SJohn Forte 
2974fcf3ce44SJohn Forte 	if ((fd = open(ISNS_DOOR_NAME, 0)) == -1) {
2975fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_OPEN_FAILED, errno);
2976fcf3ce44SJohn Forte 	    return (ret);
2977fcf3ce44SJohn Forte 	}
2978fcf3ce44SJohn Forte 
2979fcf3ce44SJohn Forte 	if ((ret = build_create_xml_doc(operandLen, operand,
2980fcf3ce44SJohn Forte 		DiscoveryDomainSet, NULL, &doc)) == 0) {
2981fcf3ce44SJohn Forte 		bzero(&darg, sizeof (darg));
2982fcf3ce44SJohn Forte 		darg.data_ptr = (char *)doc;
2983fcf3ce44SJohn Forte 		darg.data_size = xmlStrlen(doc) + 1;
2984fcf3ce44SJohn Forte 		darg.rbuf = NULL;
2985fcf3ce44SJohn Forte 		darg.rsize = 0;
2986fcf3ce44SJohn Forte 	} else {
2987fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n", getTextMessage(ret));
2988fcf3ce44SJohn Forte 		(void) close(fd);
2989fcf3ce44SJohn Forte 		return (ret);
2990fcf3ce44SJohn Forte 	}
2991fcf3ce44SJohn Forte 
2992fcf3ce44SJohn Forte 	if ((door_call(fd, &darg)) == -1) {
2993fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_CALL_FAILED, errno);
2994fcf3ce44SJohn Forte 	    (void) close(fd);
2995fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
2996fcf3ce44SJohn Forte 	    return (ret);
2997fcf3ce44SJohn Forte 	}
2998fcf3ce44SJohn Forte 
2999fcf3ce44SJohn Forte 	/*
3000fcf3ce44SJohn Forte 	 * door frame work allocated a buffer when the date lager that rbuf.
3001fcf3ce44SJohn Forte 	 * indicate if munmap is required on rbuf.
3002fcf3ce44SJohn Forte 	 */
3003fcf3ce44SJohn Forte 	if ((ret = process_result_response((xmlChar *)darg.rbuf,
3004fcf3ce44SJohn Forte 		DiscoveryDomainSet)) != 0) {
3005fcf3ce44SJohn Forte 	    (void) munmap(darg.rbuf, darg.rsize);
3006fcf3ce44SJohn Forte 	    (void) close(fd);
3007fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
3008fcf3ce44SJohn Forte 	    return (ret);
3009fcf3ce44SJohn Forte 	}
3010fcf3ce44SJohn Forte 
3011fcf3ce44SJohn Forte 	(void) munmap(darg.rbuf, darg.rsize);
3012fcf3ce44SJohn Forte 
3013fcf3ce44SJohn Forte 	(void) close(fd);
3014fcf3ce44SJohn Forte 	xmlFree(doc);
3015fcf3ce44SJohn Forte 
3016fcf3ce44SJohn Forte 	return (SUBCOMMAND_SUCCESS);
3017fcf3ce44SJohn Forte }
3018fcf3ce44SJohn Forte 
3019fcf3ce44SJohn Forte /*
3020fcf3ce44SJohn Forte  * ****************************************************************************
3021fcf3ce44SJohn Forte  *
3022fcf3ce44SJohn Forte  * modify_dd_func -
3023fcf3ce44SJohn Forte  * 	Modify a dd attr. currently rename function is supported
3024fcf3ce44SJohn Forte  *	modify-dd -n name <dd name>
3025fcf3ce44SJohn Forte  *
3026fcf3ce44SJohn Forte  * operandLen	- number of operands user passed into the cli
3027fcf3ce44SJohn Forte  * operand	- pointer to operand list from user
3028fcf3ce44SJohn Forte  * options	- pointer to option list from user
3029fcf3ce44SJohn Forte  *
3030fcf3ce44SJohn Forte  * ****************************************************************************
3031fcf3ce44SJohn Forte  */
3032fcf3ce44SJohn Forte /*ARGSUSED*/
3033fcf3ce44SJohn Forte static int
3034fcf3ce44SJohn Forte modify_dd_func(int operandLen, char *operand[], cmdOptions_t *options,
3035fcf3ce44SJohn Forte 	void *addarg)
3036fcf3ce44SJohn Forte {
3037fcf3ce44SJohn Forte 	xmlChar *doc;
3038fcf3ce44SJohn Forte 	xmlTextReaderPtr reader;
3039fcf3ce44SJohn Forte 	msg_code_t ret;
3040fcf3ce44SJohn Forte 	door_arg_t	darg;
3041fcf3ce44SJohn Forte 	int	fd, m_flag = 0;
3042fcf3ce44SJohn Forte 	uint32_t    id;
3043fcf3ce44SJohn Forte 
3044fcf3ce44SJohn Forte 	if ((fd = open(ISNS_DOOR_NAME, 0)) == -1) {
3045fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_OPEN_FAILED, errno);
3046fcf3ce44SJohn Forte 	    return (ret);
3047fcf3ce44SJohn Forte 	}
3048fcf3ce44SJohn Forte 
3049fcf3ce44SJohn Forte 	if ((ret = build_get_xml_doc(operandLen, operand,
3050fcf3ce44SJohn Forte 		DiscoveryDomain, &doc)) == 0) {
3051fcf3ce44SJohn Forte 		bzero(&darg, sizeof (darg));
3052fcf3ce44SJohn Forte 		darg.data_ptr = (char *)doc;
3053fcf3ce44SJohn Forte 		darg.data_size = xmlStrlen(doc) + 1;
3054fcf3ce44SJohn Forte 		darg.rbuf = NULL;
3055fcf3ce44SJohn Forte 		darg.rsize = 0;
3056fcf3ce44SJohn Forte 	} else {
3057fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n", getTextMessage(ret));
3058fcf3ce44SJohn Forte 		(void) close(fd);
3059fcf3ce44SJohn Forte 		return (ret);
3060fcf3ce44SJohn Forte 	}
3061fcf3ce44SJohn Forte 
3062fcf3ce44SJohn Forte 	if ((door_call(fd, &darg)) == -1) {
3063fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_CALL_FAILED, errno);
3064fcf3ce44SJohn Forte 	    (void) close(fd);
3065fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
3066fcf3ce44SJohn Forte 	    return (ret);
3067fcf3ce44SJohn Forte 	}
3068fcf3ce44SJohn Forte 
3069fcf3ce44SJohn Forte 	/* Free the request that is created by xmlStrnDup. */
3070fcf3ce44SJohn Forte 	(void) xmlFree(doc);
3071fcf3ce44SJohn Forte 
3072fcf3ce44SJohn Forte 	/*
3073fcf3ce44SJohn Forte 	 * door frame work allocated a buffer when the date lager that rbuf.
3074fcf3ce44SJohn Forte 	 * indicate if munmap is required on rbuf.
3075fcf3ce44SJohn Forte 	 */
3076fcf3ce44SJohn Forte 	if ((ret = process_result_response((xmlChar *)darg.rbuf,
3077fcf3ce44SJohn Forte 		DiscoveryDomain)) != 0) {
3078fcf3ce44SJohn Forte 	    (void) munmap(darg.rbuf, darg.rsize);
3079fcf3ce44SJohn Forte 	    (void) close(fd);
3080fcf3ce44SJohn Forte 	    return (ret);
3081fcf3ce44SJohn Forte 	}
3082fcf3ce44SJohn Forte 
3083fcf3ce44SJohn Forte 	/* setup xml parser on the response. */
3084fcf3ce44SJohn Forte 	if ((reader = (xmlTextReaderPtr)xmlReaderForMemory
3085fcf3ce44SJohn Forte 	    ((const char *)darg.rbuf, xmlStrlen((xmlChar *)darg.rbuf),
3086fcf3ce44SJohn Forte 	    NULL, NULL, 0)) == NULL) {
3087fcf3ce44SJohn Forte 	    (void) munmap(darg.rbuf, darg.rsize);
3088fcf3ce44SJohn Forte 	    (void) close(fd);
3089fcf3ce44SJohn Forte 	    return (ERROR_XML_READER_NULL);
3090fcf3ce44SJohn Forte 	}
3091fcf3ce44SJohn Forte 
3092fcf3ce44SJohn Forte 	if (reader = lookup_next_matching_elem(reader, &m_flag, DDOBJECT,
3093fcf3ce44SJohn Forte 	    ISNSRESPONSE)) {
3094fcf3ce44SJohn Forte 	    if (m_flag == READER_MATCH) {
3095fcf3ce44SJohn Forte 		if ((xmlTextReaderMoveToAttribute(reader,
3096fcf3ce44SJohn Forte 			(const xmlChar *)IDATTR)) == 1) {
3097fcf3ce44SJohn Forte 		    id = atoi((const char *)xmlTextReaderConstValue(reader));
3098fcf3ce44SJohn Forte 		} else {
3099fcf3ce44SJohn Forte 			(void) xmlTextReaderClose(reader);
3100fcf3ce44SJohn Forte 			(void) xmlFreeTextReader(reader);
3101fcf3ce44SJohn Forte 			return (ERROR_XML_ID_ATTR_NOT_FOUND);
3102fcf3ce44SJohn Forte 		}
3103fcf3ce44SJohn Forte 	    } else {
3104fcf3ce44SJohn Forte 		(void) xmlTextReaderClose(reader);
3105fcf3ce44SJohn Forte 		(void) xmlFreeTextReader(reader);
3106fcf3ce44SJohn Forte 		return (ERROR_XML_DD_OBJECT_NOT_FOUND);
3107fcf3ce44SJohn Forte 	    }
3108fcf3ce44SJohn Forte 	} else {
3109fcf3ce44SJohn Forte 	    (void) fprintf(stderr, "%s\n",
3110fcf3ce44SJohn Forte 		getTextMessage(ERROR_XML_READER_NULL));
3111fcf3ce44SJohn Forte 	    return (ERROR_XML_READER_NULL);
3112fcf3ce44SJohn Forte 	}
3113fcf3ce44SJohn Forte 
3114fcf3ce44SJohn Forte 	(void) xmlTextReaderClose(reader);
3115fcf3ce44SJohn Forte 	(void) xmlFreeTextReader(reader);
3116fcf3ce44SJohn Forte 
3117fcf3ce44SJohn Forte 	if ((ret = build_rename_xml_doc(options->optarg, DiscoveryDomain,
3118fcf3ce44SJohn Forte 		id, &doc)) == 0) {
3119fcf3ce44SJohn Forte 		bzero(&darg, sizeof (darg));
3120fcf3ce44SJohn Forte 		darg.data_ptr = (char *)doc;
3121fcf3ce44SJohn Forte 		darg.data_size = xmlStrlen(doc) + 1;
3122fcf3ce44SJohn Forte 		darg.rbuf = NULL;
3123fcf3ce44SJohn Forte 		darg.rsize = 0;
3124fcf3ce44SJohn Forte 	} else {
3125fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n", getTextMessage(ret));
3126fcf3ce44SJohn Forte 		(void) close(fd);
3127fcf3ce44SJohn Forte 		return (ret);
3128fcf3ce44SJohn Forte 	}
3129fcf3ce44SJohn Forte 
3130fcf3ce44SJohn Forte 	if ((door_call(fd, &darg)) == -1) {
3131fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_CALL_FAILED, errno);
3132fcf3ce44SJohn Forte 	    (void) close(fd);
3133fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
3134fcf3ce44SJohn Forte 	    return (ret);
3135fcf3ce44SJohn Forte 	}
3136fcf3ce44SJohn Forte 
3137fcf3ce44SJohn Forte 	/*
3138fcf3ce44SJohn Forte 	 * door frame work allocated a buffer when the date lager that rbuf.
3139fcf3ce44SJohn Forte 	 * indicate if munmap is required on rbuf.
3140fcf3ce44SJohn Forte 	 */
3141fcf3ce44SJohn Forte 	if ((ret = process_result_response((xmlChar *)darg.rbuf,
3142fcf3ce44SJohn Forte 		DiscoveryDomain)) != 0) {
3143fcf3ce44SJohn Forte 	    (void) munmap(darg.rbuf, darg.rsize);
3144fcf3ce44SJohn Forte 	    (void) close(fd);
3145fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
3146fcf3ce44SJohn Forte 	    return (ret);
3147fcf3ce44SJohn Forte 	}
3148fcf3ce44SJohn Forte 
3149fcf3ce44SJohn Forte 	(void) munmap(darg.rbuf, darg.rsize);
3150fcf3ce44SJohn Forte 	(void) close(fd);
3151fcf3ce44SJohn Forte 	xmlFree(doc);
3152fcf3ce44SJohn Forte 
3153fcf3ce44SJohn Forte 	return (SUBCOMMAND_SUCCESS);
3154fcf3ce44SJohn Forte }
3155fcf3ce44SJohn Forte 
3156fcf3ce44SJohn Forte /*
3157fcf3ce44SJohn Forte  * ****************************************************************************
3158fcf3ce44SJohn Forte  *
3159fcf3ce44SJohn Forte  * modify_ddset_func -
3160fcf3ce44SJohn Forte  * 	Modify a dd attr. currently rename function is supported
3161fcf3ce44SJohn Forte  *	modify-dd-set -n name <dd name>
3162fcf3ce44SJohn Forte  *
3163fcf3ce44SJohn Forte  * operandLen	- number of operands user passed into the cli
3164fcf3ce44SJohn Forte  * operand	- pointer to operand list from user
3165fcf3ce44SJohn Forte  * options	- pointer to option list from user
3166fcf3ce44SJohn Forte  *
3167fcf3ce44SJohn Forte  * ****************************************************************************
3168fcf3ce44SJohn Forte  */
3169fcf3ce44SJohn Forte /*ARGSUSED*/
3170fcf3ce44SJohn Forte static int
3171fcf3ce44SJohn Forte modify_ddset_func(int operandLen, char *operand[], cmdOptions_t *options,
3172fcf3ce44SJohn Forte 	void *addarg)
3173fcf3ce44SJohn Forte {
3174fcf3ce44SJohn Forte 	xmlChar *doc;
3175fcf3ce44SJohn Forte 	xmlTextReaderPtr reader;
3176fcf3ce44SJohn Forte 	msg_code_t ret;
3177fcf3ce44SJohn Forte 	door_arg_t	darg;
3178fcf3ce44SJohn Forte 	int	fd, m_flag = 0;
3179fcf3ce44SJohn Forte 	uint32_t    id;
3180fcf3ce44SJohn Forte 
3181fcf3ce44SJohn Forte 	if ((fd = open(ISNS_DOOR_NAME, 0)) == -1) {
3182fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_OPEN_FAILED, errno);
3183fcf3ce44SJohn Forte 	    return (ret);
3184fcf3ce44SJohn Forte 	}
3185fcf3ce44SJohn Forte 
3186fcf3ce44SJohn Forte 	if ((ret = build_get_xml_doc(operandLen, operand,
3187fcf3ce44SJohn Forte 		DiscoveryDomainSet, &doc)) == 0) {
3188fcf3ce44SJohn Forte 		bzero(&darg, sizeof (darg));
3189fcf3ce44SJohn Forte 		darg.data_ptr = (char *)doc;
3190fcf3ce44SJohn Forte 		darg.data_size = xmlStrlen(doc) + 1;
3191fcf3ce44SJohn Forte 		darg.rbuf = NULL;
3192fcf3ce44SJohn Forte 		darg.rsize = 0;
3193fcf3ce44SJohn Forte 	} else {
3194fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n", getTextMessage(ret));
3195fcf3ce44SJohn Forte 		(void) close(fd);
3196fcf3ce44SJohn Forte 		return (ret);
3197fcf3ce44SJohn Forte 	}
3198fcf3ce44SJohn Forte 
3199fcf3ce44SJohn Forte 	if ((door_call(fd, &darg)) == -1) {
3200fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_CALL_FAILED, errno);
3201fcf3ce44SJohn Forte 	    (void) close(fd);
3202fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
3203fcf3ce44SJohn Forte 	    return (ret);
3204fcf3ce44SJohn Forte 	}
3205fcf3ce44SJohn Forte 
3206fcf3ce44SJohn Forte 	/* Free the request that is created by xmlStrnDup. */
3207fcf3ce44SJohn Forte 	(void) xmlFree(doc);
3208fcf3ce44SJohn Forte 
3209fcf3ce44SJohn Forte 	/*
3210fcf3ce44SJohn Forte 	 * door frame work allocated a buffer when the date lager that rbuf.
3211fcf3ce44SJohn Forte 	 * indicate if munmap is required on rbuf.
3212fcf3ce44SJohn Forte 	 */
3213fcf3ce44SJohn Forte 	if ((ret = process_result_response((xmlChar *)darg.rbuf,
3214fcf3ce44SJohn Forte 		DiscoveryDomainSet)) != 0) {
3215fcf3ce44SJohn Forte 	    (void) munmap(darg.rbuf, darg.rsize);
3216fcf3ce44SJohn Forte 	    (void) close(fd);
3217fcf3ce44SJohn Forte 	    return (ret);
3218fcf3ce44SJohn Forte 	}
3219fcf3ce44SJohn Forte 
3220fcf3ce44SJohn Forte 	/* setup xml parser on the response. */
3221fcf3ce44SJohn Forte 	if ((reader = (xmlTextReaderPtr)xmlReaderForMemory
3222fcf3ce44SJohn Forte 	    ((const char *)darg.rbuf, xmlStrlen((xmlChar *)darg.rbuf),
3223fcf3ce44SJohn Forte 	    NULL, NULL, 0)) == NULL) {
3224fcf3ce44SJohn Forte 	    (void) munmap(darg.rbuf, darg.rsize);
3225fcf3ce44SJohn Forte 	    (void) close(fd);
3226fcf3ce44SJohn Forte 	    return (ERROR_XML_READER_NULL);
3227fcf3ce44SJohn Forte 	}
3228fcf3ce44SJohn Forte 
3229fcf3ce44SJohn Forte 	if (reader = lookup_next_matching_elem(reader, &m_flag, DDSETOBJECT,
3230fcf3ce44SJohn Forte 	    ISNSRESPONSE)) {
3231fcf3ce44SJohn Forte 	    if (m_flag == READER_MATCH) {
3232fcf3ce44SJohn Forte 		if ((xmlTextReaderMoveToAttribute(reader,
3233fcf3ce44SJohn Forte 			(const xmlChar *)IDATTR)) == 1) {
3234fcf3ce44SJohn Forte 		    id = atoi((const char *)xmlTextReaderConstValue(reader));
3235fcf3ce44SJohn Forte 		} else {
3236fcf3ce44SJohn Forte 			(void) xmlTextReaderClose(reader);
3237fcf3ce44SJohn Forte 			(void) xmlFreeTextReader(reader);
3238fcf3ce44SJohn Forte 			return (ERROR_XML_ID_ATTR_NOT_FOUND);
3239fcf3ce44SJohn Forte 		}
3240fcf3ce44SJohn Forte 	    } else {
3241fcf3ce44SJohn Forte 		(void) xmlTextReaderClose(reader);
3242fcf3ce44SJohn Forte 		(void) xmlFreeTextReader(reader);
3243fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n",
3244fcf3ce44SJohn Forte 		    getTextMessage(ERROR_XML_NAME_ATTR_NOT_FOUND));
3245fcf3ce44SJohn Forte 		return (ERROR_XML_DD_SET_OBJECT_NOT_FOUND);
3246fcf3ce44SJohn Forte 	    }
3247fcf3ce44SJohn Forte 	}
3248fcf3ce44SJohn Forte 
3249fcf3ce44SJohn Forte 	(void) xmlTextReaderClose(reader);
3250fcf3ce44SJohn Forte 	(void) xmlFreeTextReader(reader);
3251fcf3ce44SJohn Forte 
3252fcf3ce44SJohn Forte 	if ((ret = build_rename_xml_doc(options->optarg, DiscoveryDomainSet,
3253fcf3ce44SJohn Forte 		id, &doc)) == 0) {
3254fcf3ce44SJohn Forte 		bzero(&darg, sizeof (darg));
3255fcf3ce44SJohn Forte 		darg.data_ptr = (char *)doc;
3256fcf3ce44SJohn Forte 		darg.data_size = xmlStrlen(doc) + 1;
3257fcf3ce44SJohn Forte 		darg.rbuf = NULL;
3258fcf3ce44SJohn Forte 		darg.rsize = 0;
3259fcf3ce44SJohn Forte 	} else {
3260fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n", getTextMessage(ret));
3261fcf3ce44SJohn Forte 		(void) close(fd);
3262fcf3ce44SJohn Forte 		return (ret);
3263fcf3ce44SJohn Forte 	}
3264fcf3ce44SJohn Forte 
3265fcf3ce44SJohn Forte 	if ((door_call(fd, &darg)) == -1) {
3266fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_CALL_FAILED, errno);
3267fcf3ce44SJohn Forte 	    (void) close(fd);
3268fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
3269fcf3ce44SJohn Forte 	    return (ret);
3270fcf3ce44SJohn Forte 	}
3271fcf3ce44SJohn Forte 
3272fcf3ce44SJohn Forte 	/*
3273fcf3ce44SJohn Forte 	 * door frame work allocated a buffer when the date lager that rbuf.
3274fcf3ce44SJohn Forte 	 * indicate if munmap is required on rbuf.
3275fcf3ce44SJohn Forte 	 */
3276fcf3ce44SJohn Forte 	if ((ret = process_result_response((xmlChar *)darg.rbuf,
3277fcf3ce44SJohn Forte 		DiscoveryDomainSet)) != 0) {
3278fcf3ce44SJohn Forte 	    (void) munmap(darg.rbuf, darg.rsize);
3279fcf3ce44SJohn Forte 	    (void) close(fd);
3280fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
3281fcf3ce44SJohn Forte 	    return (ret);
3282fcf3ce44SJohn Forte 	}
3283fcf3ce44SJohn Forte 
3284fcf3ce44SJohn Forte 	(void) munmap(darg.rbuf, darg.rsize);
3285fcf3ce44SJohn Forte 	(void) close(fd);
3286fcf3ce44SJohn Forte 	xmlFree(doc);
3287fcf3ce44SJohn Forte 
3288fcf3ce44SJohn Forte 	return (SUBCOMMAND_SUCCESS);
3289fcf3ce44SJohn Forte }
3290fcf3ce44SJohn Forte 
3291fcf3ce44SJohn Forte /*
3292fcf3ce44SJohn Forte  * ****************************************************************************
3293fcf3ce44SJohn Forte  *
3294fcf3ce44SJohn Forte  * add_node_func -
3295fcf3ce44SJohn Forte  * 	Add a node to a DiscoveryDomain add-node -d dd-name <node name>, ...
3296fcf3ce44SJohn Forte  *
3297fcf3ce44SJohn Forte  * operandLen	- number of operands user passed into the cli
3298fcf3ce44SJohn Forte  * operand	- pointer to operand list from user
3299fcf3ce44SJohn Forte  * options	- pointer to option list from user
3300fcf3ce44SJohn Forte  *
3301fcf3ce44SJohn Forte  * ****************************************************************************
3302fcf3ce44SJohn Forte  */
3303fcf3ce44SJohn Forte /*ARGSUSED*/
3304fcf3ce44SJohn Forte static int
3305fcf3ce44SJohn Forte add_node_func(int operandLen, char *operand[], cmdOptions_t *options,
3306fcf3ce44SJohn Forte 	void *addarg)
3307fcf3ce44SJohn Forte {
3308fcf3ce44SJohn Forte 	xmlChar *doc;
3309fcf3ce44SJohn Forte 	msg_code_t ret;
3310fcf3ce44SJohn Forte 	door_arg_t	darg;
3311fcf3ce44SJohn Forte 	int	fd;
3312fcf3ce44SJohn Forte 
3313fcf3ce44SJohn Forte 	if ((fd = open(ISNS_DOOR_NAME, 0)) == -1) {
3314fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_OPEN_FAILED, errno);
3315fcf3ce44SJohn Forte 	    return (ret);
3316fcf3ce44SJohn Forte 	}
3317fcf3ce44SJohn Forte 
3318fcf3ce44SJohn Forte 	if ((ret = build_create_xml_doc(operandLen, operand,
3319fcf3ce44SJohn Forte 		DiscoveryDomainMember, options->optarg, &doc)) == 0) {
3320fcf3ce44SJohn Forte 		bzero(&darg, sizeof (darg));
3321fcf3ce44SJohn Forte 		darg.data_ptr = (char *)doc;
3322fcf3ce44SJohn Forte 		darg.data_size = xmlStrlen(doc) + 1;
3323fcf3ce44SJohn Forte 		darg.rbuf = NULL;
3324fcf3ce44SJohn Forte 		darg.rsize = 0;
3325fcf3ce44SJohn Forte 	} else {
3326fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n", getTextMessage(ret));
3327fcf3ce44SJohn Forte 		(void) close(fd);
3328fcf3ce44SJohn Forte 		return (ret);
3329fcf3ce44SJohn Forte 	}
3330fcf3ce44SJohn Forte 
3331fcf3ce44SJohn Forte 	if ((door_call(fd, &darg)) == -1) {
3332fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_CALL_FAILED, errno);
3333fcf3ce44SJohn Forte 	    (void) close(fd);
3334fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
3335fcf3ce44SJohn Forte 	    return (ret);
3336fcf3ce44SJohn Forte 	}
3337fcf3ce44SJohn Forte 
3338fcf3ce44SJohn Forte 	/*
3339fcf3ce44SJohn Forte 	 * door frame work allocated a buffer when the date lager that rbuf.
3340fcf3ce44SJohn Forte 	 * indicate if munmap is required on rbuf.
3341fcf3ce44SJohn Forte 	 */
3342fcf3ce44SJohn Forte 	if ((ret = process_result_response((xmlChar *)darg.rbuf,
3343fcf3ce44SJohn Forte 		DiscoveryDomainMember)) != 0) {
3344fcf3ce44SJohn Forte 	    (void) munmap(darg.rbuf, darg.rsize);
3345fcf3ce44SJohn Forte 	    (void) close(fd);
3346fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
3347fcf3ce44SJohn Forte 	    return (ret);
3348fcf3ce44SJohn Forte 	}
3349fcf3ce44SJohn Forte 
3350fcf3ce44SJohn Forte 	(void) munmap(darg.rbuf, darg.rsize);
3351fcf3ce44SJohn Forte 	(void) close(fd);
3352fcf3ce44SJohn Forte 	xmlFree(doc);
3353fcf3ce44SJohn Forte 
3354fcf3ce44SJohn Forte 	return (SUBCOMMAND_SUCCESS);
3355fcf3ce44SJohn Forte }
3356fcf3ce44SJohn Forte 
3357fcf3ce44SJohn Forte /*
3358fcf3ce44SJohn Forte  * ****************************************************************************
3359fcf3ce44SJohn Forte  *
3360fcf3ce44SJohn Forte  * add_dd_func -
3361fcf3ce44SJohn Forte  * 	Add a dd to a DiscoveryDomainSet add-dd -s dd-set name <dd name>, ...
3362fcf3ce44SJohn Forte  *
3363fcf3ce44SJohn Forte  * operandLen	- number of operands user passed into the cli
3364fcf3ce44SJohn Forte  * operand	- pointer to operand list from user
3365fcf3ce44SJohn Forte  * options	- pointer to option list from user
3366fcf3ce44SJohn Forte  *
3367fcf3ce44SJohn Forte  * ****************************************************************************
3368fcf3ce44SJohn Forte  */
3369fcf3ce44SJohn Forte /*ARGSUSED*/
3370fcf3ce44SJohn Forte static int
3371fcf3ce44SJohn Forte add_dd_func(int operandLen, char *operand[], cmdOptions_t *options,
3372fcf3ce44SJohn Forte 	void *addarg)
3373fcf3ce44SJohn Forte {
3374fcf3ce44SJohn Forte 	xmlChar *doc;
3375fcf3ce44SJohn Forte 	msg_code_t ret;
3376fcf3ce44SJohn Forte 	door_arg_t	darg;
3377fcf3ce44SJohn Forte 	int	fd;
3378fcf3ce44SJohn Forte 
3379fcf3ce44SJohn Forte 	if ((fd = open(ISNS_DOOR_NAME, 0)) == -1) {
3380fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_OPEN_FAILED, errno);
3381fcf3ce44SJohn Forte 	    return (ret);
3382fcf3ce44SJohn Forte 	}
3383fcf3ce44SJohn Forte 
3384fcf3ce44SJohn Forte 	if ((ret = build_create_xml_doc(operandLen, operand,
3385fcf3ce44SJohn Forte 		DiscoveryDomainSetMember, options->optarg, &doc)) == 0) {
3386fcf3ce44SJohn Forte 		bzero(&darg, sizeof (darg));
3387fcf3ce44SJohn Forte 		darg.data_ptr = (char *)doc;
3388fcf3ce44SJohn Forte 		darg.data_size = xmlStrlen(doc) + 1;
3389fcf3ce44SJohn Forte 		darg.rbuf = NULL;
3390fcf3ce44SJohn Forte 		darg.rsize = 0;
3391fcf3ce44SJohn Forte 	} else {
3392fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n", getTextMessage(ret));
3393fcf3ce44SJohn Forte 		(void) close(fd);
3394fcf3ce44SJohn Forte 		return (ret);
3395fcf3ce44SJohn Forte 	}
3396fcf3ce44SJohn Forte 
3397fcf3ce44SJohn Forte 	if ((door_call(fd, &darg)) == -1) {
3398fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_CALL_FAILED, errno);
3399fcf3ce44SJohn Forte 	    (void) close(fd);
3400fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
3401fcf3ce44SJohn Forte 	    return (ret);
3402fcf3ce44SJohn Forte 	}
3403fcf3ce44SJohn Forte 
3404fcf3ce44SJohn Forte 	/*
3405fcf3ce44SJohn Forte 	 * door frame work allocated a buffer when the date lager that rbuf.
3406fcf3ce44SJohn Forte 	 * indicate if munmap is required on rbuf.
3407fcf3ce44SJohn Forte 	 */
3408fcf3ce44SJohn Forte 	if ((ret = process_result_response((xmlChar *)darg.rbuf,
3409fcf3ce44SJohn Forte 		DiscoveryDomainSetMember)) != 0) {
3410fcf3ce44SJohn Forte 	    (void) munmap(darg.rbuf, darg.rsize);
3411fcf3ce44SJohn Forte 	    (void) close(fd);
3412fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
3413fcf3ce44SJohn Forte 	    return (ret);
3414fcf3ce44SJohn Forte 	}
3415fcf3ce44SJohn Forte 
3416fcf3ce44SJohn Forte 	(void) munmap(darg.rbuf, darg.rsize);
3417fcf3ce44SJohn Forte 	(void) close(fd);
3418fcf3ce44SJohn Forte 	xmlFree(doc);
3419fcf3ce44SJohn Forte 
3420fcf3ce44SJohn Forte 	return (SUBCOMMAND_SUCCESS);
3421fcf3ce44SJohn Forte }
3422fcf3ce44SJohn Forte 
3423fcf3ce44SJohn Forte /*
3424fcf3ce44SJohn Forte  * ****************************************************************************
3425fcf3ce44SJohn Forte  *
3426fcf3ce44SJohn Forte  * remove_node_func -
3427fcf3ce44SJohn Forte  * 	Remove a node from DiscoveryDomain
3428fcf3ce44SJohn Forte  *	remov-node -d dd-name <node name>, ...
3429fcf3ce44SJohn Forte  *
3430fcf3ce44SJohn Forte  * operandLen	- number of operands user passed into the cli
3431fcf3ce44SJohn Forte  * operand	- pointer to operand list from user
3432fcf3ce44SJohn Forte  * options	- pointer to option list from user
3433fcf3ce44SJohn Forte  *
3434fcf3ce44SJohn Forte  * ****************************************************************************
3435fcf3ce44SJohn Forte  */
3436fcf3ce44SJohn Forte /*ARGSUSED*/
3437fcf3ce44SJohn Forte static int
3438fcf3ce44SJohn Forte remove_node_func(int operandLen, char *operand[], cmdOptions_t *options,
3439fcf3ce44SJohn Forte 	void *addarg)
3440fcf3ce44SJohn Forte {
3441fcf3ce44SJohn Forte 	xmlChar *doc;
3442fcf3ce44SJohn Forte 	msg_code_t ret;
3443fcf3ce44SJohn Forte 	door_arg_t	darg;
3444fcf3ce44SJohn Forte 	int	fd;
3445fcf3ce44SJohn Forte 
3446fcf3ce44SJohn Forte 	if ((fd = open(ISNS_DOOR_NAME, 0)) == -1) {
3447fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_OPEN_FAILED, errno);
3448fcf3ce44SJohn Forte 	    return (ret);
3449fcf3ce44SJohn Forte 	}
3450fcf3ce44SJohn Forte 
3451fcf3ce44SJohn Forte 	if ((ret = build_delete_xml_doc(operandLen, operand,
3452fcf3ce44SJohn Forte 		DiscoveryDomainMember, options->optarg, &doc)) == 0) {
3453fcf3ce44SJohn Forte 		bzero(&darg, sizeof (darg));
3454fcf3ce44SJohn Forte 		darg.data_ptr = (char *)doc;
3455fcf3ce44SJohn Forte 		darg.data_size = xmlStrlen(doc) + 1;
3456fcf3ce44SJohn Forte 		darg.rbuf = NULL;
3457fcf3ce44SJohn Forte 		darg.rsize = 0;
3458fcf3ce44SJohn Forte 	} else {
3459fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n", getTextMessage(ret));
3460fcf3ce44SJohn Forte 		(void) close(fd);
3461fcf3ce44SJohn Forte 		return (ret);
3462fcf3ce44SJohn Forte 	}
3463fcf3ce44SJohn Forte 
3464fcf3ce44SJohn Forte 	if ((door_call(fd, &darg)) == -1) {
3465fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_CALL_FAILED, errno);
3466fcf3ce44SJohn Forte 	    (void) close(fd);
3467fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
3468fcf3ce44SJohn Forte 	    return (ret);
3469fcf3ce44SJohn Forte 	}
3470fcf3ce44SJohn Forte 
3471fcf3ce44SJohn Forte 	/*
3472fcf3ce44SJohn Forte 	 * door frame work allocated a buffer when the date lager that rbuf.
3473fcf3ce44SJohn Forte 	 * indicate if munmap is required on rbuf.
3474fcf3ce44SJohn Forte 	 */
3475fcf3ce44SJohn Forte 	if ((ret = process_result_response((xmlChar *)darg.rbuf,
3476fcf3ce44SJohn Forte 		DiscoveryDomainMember)) != 0) {
3477fcf3ce44SJohn Forte 	    (void) munmap(darg.rbuf, darg.rsize);
3478fcf3ce44SJohn Forte 	    (void) close(fd);
3479fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
3480fcf3ce44SJohn Forte 	    return (ret);
3481fcf3ce44SJohn Forte 	}
3482fcf3ce44SJohn Forte 
3483fcf3ce44SJohn Forte 	(void) munmap(darg.rbuf, darg.rsize);
3484fcf3ce44SJohn Forte 	(void) close(fd);
3485fcf3ce44SJohn Forte 	xmlFree(doc);
3486fcf3ce44SJohn Forte 
3487fcf3ce44SJohn Forte 	return (SUBCOMMAND_SUCCESS);
3488fcf3ce44SJohn Forte }
3489fcf3ce44SJohn Forte 
3490fcf3ce44SJohn Forte /*
3491fcf3ce44SJohn Forte  * ****************************************************************************
3492fcf3ce44SJohn Forte  *
3493fcf3ce44SJohn Forte  * remove_dd_func -
3494fcf3ce44SJohn Forte  * 	Remove a dd from DiscoveryDomainSet
3495fcf3ce44SJohn Forte  *	remove-dd -s dd-set name <dd name>, ...
3496fcf3ce44SJohn Forte  *
3497fcf3ce44SJohn Forte  * operandLen	- number of operands user passed into the cli
3498fcf3ce44SJohn Forte  * operand	- pointer to operand list from user
3499fcf3ce44SJohn Forte  * options	- pointer to option list from user
3500fcf3ce44SJohn Forte  *
3501fcf3ce44SJohn Forte  * ****************************************************************************
3502fcf3ce44SJohn Forte  */
3503fcf3ce44SJohn Forte /*ARGSUSED*/
3504fcf3ce44SJohn Forte static int
3505fcf3ce44SJohn Forte remove_dd_func(int operandLen, char *operand[], cmdOptions_t *options,
3506fcf3ce44SJohn Forte 	void *addarg)
3507fcf3ce44SJohn Forte {
3508fcf3ce44SJohn Forte 	xmlChar *doc;
3509fcf3ce44SJohn Forte 	msg_code_t ret;
3510fcf3ce44SJohn Forte 	door_arg_t	darg;
3511fcf3ce44SJohn Forte 	int	fd;
3512fcf3ce44SJohn Forte 
3513fcf3ce44SJohn Forte 	if ((fd = open(ISNS_DOOR_NAME, 0)) == -1) {
3514fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_OPEN_FAILED, errno);
3515fcf3ce44SJohn Forte 	    return (ret);
3516fcf3ce44SJohn Forte 	}
3517fcf3ce44SJohn Forte 
3518fcf3ce44SJohn Forte 	if ((ret = build_delete_xml_doc(operandLen, operand,
3519fcf3ce44SJohn Forte 		DiscoveryDomainSetMember, options->optarg, &doc)) == 0) {
3520fcf3ce44SJohn Forte 		bzero(&darg, sizeof (darg));
3521fcf3ce44SJohn Forte 		darg.data_ptr = (char *)doc;
3522fcf3ce44SJohn Forte 		darg.data_size = xmlStrlen(doc) + 1;
3523fcf3ce44SJohn Forte 		darg.rbuf = NULL;
3524fcf3ce44SJohn Forte 		darg.rsize = 0;
3525fcf3ce44SJohn Forte 	} else {
3526fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n", getTextMessage(ret));
3527fcf3ce44SJohn Forte 		(void) close(fd);
3528fcf3ce44SJohn Forte 		return (ret);
3529fcf3ce44SJohn Forte 	}
3530fcf3ce44SJohn Forte 
3531fcf3ce44SJohn Forte 	if ((door_call(fd, &darg)) == -1) {
3532fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_CALL_FAILED, errno);
3533fcf3ce44SJohn Forte 	    (void) close(fd);
3534fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
3535fcf3ce44SJohn Forte 	    return (ret);
3536fcf3ce44SJohn Forte 	}
3537fcf3ce44SJohn Forte 
3538fcf3ce44SJohn Forte 	/*
3539fcf3ce44SJohn Forte 	 * door frame work allocated a buffer when the date lager that rbuf.
3540fcf3ce44SJohn Forte 	 * indicate if munmap is required on rbuf.
3541fcf3ce44SJohn Forte 	 */
3542fcf3ce44SJohn Forte 	if ((ret = process_result_response((xmlChar *)darg.rbuf,
3543fcf3ce44SJohn Forte 		DiscoveryDomainSetMember)) != 0) {
3544fcf3ce44SJohn Forte 	    (void) munmap(darg.rbuf, darg.rsize);
3545fcf3ce44SJohn Forte 	    (void) close(fd);
3546fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
3547fcf3ce44SJohn Forte 	    return (ret);
3548fcf3ce44SJohn Forte 	}
3549fcf3ce44SJohn Forte 
3550fcf3ce44SJohn Forte 	(void) munmap(darg.rbuf, darg.rsize);
3551fcf3ce44SJohn Forte 	(void) close(fd);
3552fcf3ce44SJohn Forte 	xmlFree(doc);
3553fcf3ce44SJohn Forte 
3554fcf3ce44SJohn Forte 	return (SUBCOMMAND_SUCCESS);
3555fcf3ce44SJohn Forte }
3556fcf3ce44SJohn Forte 
3557fcf3ce44SJohn Forte /*
3558fcf3ce44SJohn Forte  * ****************************************************************************
3559fcf3ce44SJohn Forte  *
3560fcf3ce44SJohn Forte  * delete_dd_func -
3561fcf3ce44SJohn Forte  * 	remove a DiscoveryDomain remove-dd <dd name>, ...
3562fcf3ce44SJohn Forte  *
3563fcf3ce44SJohn Forte  * operandLen	- number of operands user passed into the cli
3564fcf3ce44SJohn Forte  * operand	- pointer to operand list from user
3565fcf3ce44SJohn Forte  * options	- pointer to option list from user
3566fcf3ce44SJohn Forte  *
3567fcf3ce44SJohn Forte  * ****************************************************************************
3568fcf3ce44SJohn Forte  */
3569fcf3ce44SJohn Forte /*ARGSUSED*/
3570fcf3ce44SJohn Forte static int
3571fcf3ce44SJohn Forte delete_dd_func(int operandLen, char *operand[], cmdOptions_t *options,
3572fcf3ce44SJohn Forte 	void *addarg)
3573fcf3ce44SJohn Forte {
3574fcf3ce44SJohn Forte 	xmlChar *doc;
3575fcf3ce44SJohn Forte 	msg_code_t ret;
3576fcf3ce44SJohn Forte 	door_arg_t		darg;
3577fcf3ce44SJohn Forte 	int			fd;
3578fcf3ce44SJohn Forte 
3579fcf3ce44SJohn Forte 	if ((fd = open(ISNS_DOOR_NAME, 0)) == -1) {
3580fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_OPEN_FAILED, errno);
3581fcf3ce44SJohn Forte 	    return (ret);
3582fcf3ce44SJohn Forte 	}
3583fcf3ce44SJohn Forte 
3584fcf3ce44SJohn Forte 	if ((ret = build_delete_xml_doc(operandLen, operand,
3585fcf3ce44SJohn Forte 		DiscoveryDomain, NULL, &doc)) == 0) {
3586fcf3ce44SJohn Forte 		bzero(&darg, sizeof (darg));
3587fcf3ce44SJohn Forte 		darg.data_ptr = (char *)doc;
3588fcf3ce44SJohn Forte 		darg.data_size = xmlStrlen(doc) + 1;
3589fcf3ce44SJohn Forte 		darg.rbuf = NULL;
3590fcf3ce44SJohn Forte 		darg.rsize = 0;
3591fcf3ce44SJohn Forte 	} else {
3592fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n", getTextMessage(ret));
3593fcf3ce44SJohn Forte 		(void) close(fd);
3594fcf3ce44SJohn Forte 		return (ret);
3595fcf3ce44SJohn Forte 	}
3596fcf3ce44SJohn Forte 
3597fcf3ce44SJohn Forte 	if ((door_call(fd, &darg)) == -1) {
3598fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_CALL_FAILED, errno);
3599fcf3ce44SJohn Forte 	    (void) close(fd);
3600fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
3601fcf3ce44SJohn Forte 	    return (ret);
3602fcf3ce44SJohn Forte 	}
3603fcf3ce44SJohn Forte 
3604fcf3ce44SJohn Forte 	/*
3605fcf3ce44SJohn Forte 	 * door frame work allocated a buffer when the date lager that rbuf.
3606fcf3ce44SJohn Forte 	 * indicate if munmap is required on rbuf.
3607fcf3ce44SJohn Forte 	 */
3608fcf3ce44SJohn Forte 	if ((ret = process_result_response((xmlChar *)darg.rbuf,
3609fcf3ce44SJohn Forte 		DiscoveryDomain)) != 0) {
3610fcf3ce44SJohn Forte 	    (void) munmap(darg.rbuf, darg.rsize);
3611fcf3ce44SJohn Forte 	    (void) close(fd);
3612fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
3613fcf3ce44SJohn Forte 	    return (ret);
3614fcf3ce44SJohn Forte 	}
3615fcf3ce44SJohn Forte 
3616fcf3ce44SJohn Forte 	(void) munmap(darg.rbuf, darg.rsize);
3617fcf3ce44SJohn Forte 
3618fcf3ce44SJohn Forte 	(void) close(fd);
3619fcf3ce44SJohn Forte 	xmlFree(doc);
3620fcf3ce44SJohn Forte 
3621fcf3ce44SJohn Forte 	return (SUBCOMMAND_SUCCESS);
3622fcf3ce44SJohn Forte }
3623fcf3ce44SJohn Forte 
3624fcf3ce44SJohn Forte /*
3625fcf3ce44SJohn Forte  * ****************************************************************************
3626fcf3ce44SJohn Forte  *
3627fcf3ce44SJohn Forte  * delete_ddset_func -
3628fcf3ce44SJohn Forte  * 	delete DiscoveryDomainSet(s) delete-dd-set <dd set name>, ...
3629fcf3ce44SJohn Forte  *
3630fcf3ce44SJohn Forte  * operandLen	- number of operands user passed into the cli
3631fcf3ce44SJohn Forte  * operand	- pointer to operand list from user
3632fcf3ce44SJohn Forte  * options	- pointer to option list from user
3633fcf3ce44SJohn Forte  *
3634fcf3ce44SJohn Forte  * ****************************************************************************
3635fcf3ce44SJohn Forte  */
3636fcf3ce44SJohn Forte /*ARGSUSED*/
3637fcf3ce44SJohn Forte static int
3638fcf3ce44SJohn Forte delete_ddset_func(int operandLen, char *operand[], cmdOptions_t *options,
3639fcf3ce44SJohn Forte     void *addarg)
3640fcf3ce44SJohn Forte {
3641fcf3ce44SJohn Forte 	xmlChar *doc;
3642fcf3ce44SJohn Forte 	msg_code_t ret;
3643fcf3ce44SJohn Forte 	door_arg_t		darg;
3644fcf3ce44SJohn Forte 	int			fd;
3645fcf3ce44SJohn Forte 
3646fcf3ce44SJohn Forte 	if ((fd = open(ISNS_DOOR_NAME, 0)) == -1) {
3647fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_OPEN_FAILED, errno);
3648fcf3ce44SJohn Forte 	    return (ret);
3649fcf3ce44SJohn Forte 	}
3650fcf3ce44SJohn Forte 
3651fcf3ce44SJohn Forte 	if ((ret = build_delete_xml_doc(operandLen, operand,
3652fcf3ce44SJohn Forte 		DiscoveryDomainSet, NULL, &doc)) == 0) {
3653fcf3ce44SJohn Forte 		bzero(&darg, sizeof (darg));
3654fcf3ce44SJohn Forte 		darg.data_ptr = (char *)doc;
3655fcf3ce44SJohn Forte 		darg.data_size = xmlStrlen(doc) + 1;
3656fcf3ce44SJohn Forte 		darg.rbuf = NULL;
3657fcf3ce44SJohn Forte 		darg.rsize = 0;
3658fcf3ce44SJohn Forte 	} else {
3659fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n", getTextMessage(ret));
3660fcf3ce44SJohn Forte 		(void) close(fd);
3661fcf3ce44SJohn Forte 		return (ret);
3662fcf3ce44SJohn Forte 	}
3663fcf3ce44SJohn Forte 
3664fcf3ce44SJohn Forte 	if ((door_call(fd, &darg)) == -1) {
3665fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_CALL_FAILED, errno);
3666fcf3ce44SJohn Forte 	    (void) close(fd);
3667fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
3668fcf3ce44SJohn Forte 	    return (ret);
3669fcf3ce44SJohn Forte 	}
3670fcf3ce44SJohn Forte 
3671fcf3ce44SJohn Forte 	/*
3672fcf3ce44SJohn Forte 	 * door frame work allocated a buffer when the date lager that rbuf.
3673fcf3ce44SJohn Forte 	 * indicate if munmap is required on rbuf.
3674fcf3ce44SJohn Forte 	 */
3675fcf3ce44SJohn Forte 	if ((ret = process_result_response((xmlChar *)darg.rbuf,
3676fcf3ce44SJohn Forte 		DiscoveryDomainSet)) != 0) {
3677fcf3ce44SJohn Forte 	    (void) munmap(darg.rbuf, darg.rsize);
3678fcf3ce44SJohn Forte 	    (void) close(fd);
3679fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
3680fcf3ce44SJohn Forte 	    return (ret);
3681fcf3ce44SJohn Forte 	}
3682fcf3ce44SJohn Forte 
3683fcf3ce44SJohn Forte 	(void) munmap(darg.rbuf, darg.rsize);
3684fcf3ce44SJohn Forte 	(void) close(fd);
3685fcf3ce44SJohn Forte 	xmlFree(doc);
3686fcf3ce44SJohn Forte 
3687fcf3ce44SJohn Forte 	return (SUBCOMMAND_SUCCESS);
3688fcf3ce44SJohn Forte }
3689fcf3ce44SJohn Forte 
3690fcf3ce44SJohn Forte /*
3691fcf3ce44SJohn Forte  * ****************************************************************************
3692fcf3ce44SJohn Forte  *
3693fcf3ce44SJohn Forte  * i_enableddset
3694fcf3ce44SJohn Forte  * 	enables/disables DiscoveryDomainSet(s)
3695fcf3ce44SJohn Forte  *
3696fcf3ce44SJohn Forte  * operandLen	- number of operands user passed into the cli
3697fcf3ce44SJohn Forte  * operand	- pointer to operand list from user
3698fcf3ce44SJohn Forte  * enable	- indication of enable/disable
3699fcf3ce44SJohn Forte  *
3700fcf3ce44SJohn Forte  * ****************************************************************************
3701fcf3ce44SJohn Forte  */
3702fcf3ce44SJohn Forte static int
3703fcf3ce44SJohn Forte i_enableddset(int operandLen, char *operand[], boolean_t enable)
3704fcf3ce44SJohn Forte {
3705fcf3ce44SJohn Forte 	xmlChar *doc;
3706fcf3ce44SJohn Forte 	door_arg_t		darg;
3707fcf3ce44SJohn Forte 	int fd, ret = 0;
3708fcf3ce44SJohn Forte 
3709fcf3ce44SJohn Forte 	if ((fd = open(ISNS_DOOR_NAME, 0)) == -1) {
3710fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_OPEN_FAILED, errno);
3711fcf3ce44SJohn Forte 	    return (ret);
3712fcf3ce44SJohn Forte 	}
3713fcf3ce44SJohn Forte 
3714fcf3ce44SJohn Forte 	if ((ret = build_modify_xml_doc(operandLen, operand,
3715fcf3ce44SJohn Forte 		DiscoveryDomainSet, enable, &doc)) == 0) {
3716fcf3ce44SJohn Forte 		bzero(&darg, sizeof (darg));
3717fcf3ce44SJohn Forte 		darg.data_ptr = (char *)doc;
3718fcf3ce44SJohn Forte 		darg.data_size = xmlStrlen(doc) + 1;
3719fcf3ce44SJohn Forte 		darg.rbuf = NULL;
3720fcf3ce44SJohn Forte 		darg.rsize = 0;
3721fcf3ce44SJohn Forte 	} else {
3722fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n", getTextMessage(ret));
3723fcf3ce44SJohn Forte 		(void) close(fd);
3724fcf3ce44SJohn Forte 		return (ret);
3725fcf3ce44SJohn Forte 	}
3726fcf3ce44SJohn Forte 
3727fcf3ce44SJohn Forte 	if ((door_call(fd, &darg)) == -1) {
3728fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_CALL_FAILED, errno);
3729fcf3ce44SJohn Forte 	    (void) close(fd);
3730fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
3731fcf3ce44SJohn Forte 	    return (ret);
3732fcf3ce44SJohn Forte 	}
3733fcf3ce44SJohn Forte 
3734fcf3ce44SJohn Forte 	xmlFree(doc);
3735fcf3ce44SJohn Forte 
3736fcf3ce44SJohn Forte 	if ((ret = process_result_response((xmlChar *)darg.rbuf,
3737fcf3ce44SJohn Forte 		DiscoveryDomainSet)) != 0) {
3738fcf3ce44SJohn Forte 	    (void) munmap(darg.rbuf, darg.rsize);
3739fcf3ce44SJohn Forte 	    (void) close(fd);
3740fcf3ce44SJohn Forte 	    return (ret);
3741fcf3ce44SJohn Forte 	}
3742fcf3ce44SJohn Forte 
3743fcf3ce44SJohn Forte 	(void) munmap(darg.rbuf, darg.rsize);
3744fcf3ce44SJohn Forte 	(void) close(fd);
3745fcf3ce44SJohn Forte 	return (SUBCOMMAND_SUCCESS);
3746fcf3ce44SJohn Forte }
3747fcf3ce44SJohn Forte 
3748fcf3ce44SJohn Forte /*
3749fcf3ce44SJohn Forte  * ****************************************************************************
3750fcf3ce44SJohn Forte  *
3751fcf3ce44SJohn Forte  * enable_ddset_func -
3752fcf3ce44SJohn Forte  * 	enables DiscoveryDomainSet(s) enable-dd-set <dd set name>, ...
3753fcf3ce44SJohn Forte  *
3754fcf3ce44SJohn Forte  * operandLen	- number of operands user passed into the cli
3755fcf3ce44SJohn Forte  * operand	- pointer to operand list from user
3756fcf3ce44SJohn Forte  * options	- pointer to option list from user
3757fcf3ce44SJohn Forte  *
3758fcf3ce44SJohn Forte  * ****************************************************************************
3759fcf3ce44SJohn Forte  */
3760fcf3ce44SJohn Forte /*ARGSUSED*/
3761fcf3ce44SJohn Forte static int
3762fcf3ce44SJohn Forte enable_ddset_func(int operandLen, char *operand[], cmdOptions_t *options,
3763fcf3ce44SJohn Forte     void *addarg)
3764fcf3ce44SJohn Forte {
3765fcf3ce44SJohn Forte 	return (i_enableddset(operandLen, operand, B_TRUE));
3766fcf3ce44SJohn Forte }
3767fcf3ce44SJohn Forte 
3768fcf3ce44SJohn Forte /*
3769fcf3ce44SJohn Forte  * ****************************************************************************
3770fcf3ce44SJohn Forte  *
3771fcf3ce44SJohn Forte  * disabledsetFunc -
3772fcf3ce44SJohn Forte  * 	disable DiscoveryDomainSet(s) disable-dd-set <dd set name>, ...
3773fcf3ce44SJohn Forte  *
3774fcf3ce44SJohn Forte  * operandLen	- number of operands user passed into the cli
3775fcf3ce44SJohn Forte  * operand	- pointer to operand list from user
3776fcf3ce44SJohn Forte  * options	- pointer to option list from user
3777fcf3ce44SJohn Forte  *
3778fcf3ce44SJohn Forte  * ****************************************************************************
3779fcf3ce44SJohn Forte  */
3780fcf3ce44SJohn Forte /*ARGSUSED*/
3781fcf3ce44SJohn Forte static int
3782fcf3ce44SJohn Forte disable_ddset_func(int operandLen, char *operand[], cmdOptions_t *options,
3783fcf3ce44SJohn Forte     void *addarg)
3784fcf3ce44SJohn Forte {
3785fcf3ce44SJohn Forte 	return (i_enableddset(operandLen, operand, B_FALSE));
3786fcf3ce44SJohn Forte }
3787fcf3ce44SJohn Forte 
3788fcf3ce44SJohn Forte /*
3789fcf3ce44SJohn Forte  * ****************************************************************************
3790fcf3ce44SJohn Forte  *
3791fcf3ce44SJohn Forte  * show_config_func -
3792fcf3ce44SJohn Forte  * 	isnsadm show-config
3793fcf3ce44SJohn Forte  *
3794fcf3ce44SJohn Forte  * operandLen	- number of operands user passed into the cli
3795fcf3ce44SJohn Forte  * operand	- pointer to operand list from user
3796fcf3ce44SJohn Forte  * options	- pointer to option list from user
3797fcf3ce44SJohn Forte  *
3798fcf3ce44SJohn Forte  * ****************************************************************************
3799fcf3ce44SJohn Forte  */
3800fcf3ce44SJohn Forte /*ARGSUSED*/
3801fcf3ce44SJohn Forte static int
3802fcf3ce44SJohn Forte show_config_func(int operandLen, char *operand[], cmdOptions_t *options,
3803fcf3ce44SJohn Forte 	void *addarg)
3804fcf3ce44SJohn Forte {
3805fcf3ce44SJohn Forte 	xmlChar *doc;
3806fcf3ce44SJohn Forte 	int ret;
3807fcf3ce44SJohn Forte 	door_arg_t		darg;
3808fcf3ce44SJohn Forte 	int			fd, flag = 0;
3809fcf3ce44SJohn Forte 
3810fcf3ce44SJohn Forte 	if ((fd = open(ISNS_DOOR_NAME, 0)) == -1) {
3811fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_OPEN_FAILED, errno);
3812fcf3ce44SJohn Forte 	    return (ret);
3813fcf3ce44SJohn Forte 	}
3814fcf3ce44SJohn Forte 
3815fcf3ce44SJohn Forte 	if ((ret = build_get_xml_doc(operandLen, operand,
3816fcf3ce44SJohn Forte 		ServerConfig, &doc)) == 0) {
3817fcf3ce44SJohn Forte 		bzero(&darg, sizeof (darg));
3818fcf3ce44SJohn Forte 		darg.data_ptr = (char *)doc;
3819fcf3ce44SJohn Forte 		darg.data_size = xmlStrlen(doc) + 1;
3820fcf3ce44SJohn Forte 		darg.rbuf = NULL;
3821fcf3ce44SJohn Forte 		darg.rsize = 0;
3822fcf3ce44SJohn Forte 	} else {
3823fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n", getTextMessage(ret));
3824fcf3ce44SJohn Forte 		(void) close(fd);
3825fcf3ce44SJohn Forte 		(void) xmlFree(doc);
3826fcf3ce44SJohn Forte 		return (ret);
3827fcf3ce44SJohn Forte 	}
3828fcf3ce44SJohn Forte 
3829fcf3ce44SJohn Forte 	if ((door_call(fd, &darg)) == -1) {
3830fcf3ce44SJohn Forte 	    ret = check_door_error(ERROR_DOOR_CALL_FAILED, errno);
3831fcf3ce44SJohn Forte 	    (void) close(fd);
3832fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
3833fcf3ce44SJohn Forte 	    return (ret);
3834fcf3ce44SJohn Forte 	}
3835fcf3ce44SJohn Forte 
3836fcf3ce44SJohn Forte 	if ((ret = process_get_response(ServerConfig, (xmlChar *)darg.rbuf,
3837fcf3ce44SJohn Forte 	    flag)) != 0) {
3838fcf3ce44SJohn Forte 	    (void) munmap(darg.rbuf, darg.rsize);
3839fcf3ce44SJohn Forte 	    (void) close(fd);
3840fcf3ce44SJohn Forte 	    (void) xmlFree(doc);
3841fcf3ce44SJohn Forte 	    return (ret);
3842fcf3ce44SJohn Forte 	}
3843fcf3ce44SJohn Forte 
3844fcf3ce44SJohn Forte 	(void) munmap(darg.rbuf, darg.rsize);
3845fcf3ce44SJohn Forte 	(void) close(fd);
3846fcf3ce44SJohn Forte 	xmlFree(doc);
3847fcf3ce44SJohn Forte 
3848fcf3ce44SJohn Forte 	return (SUBCOMMAND_SUCCESS);
3849fcf3ce44SJohn Forte }
3850fcf3ce44SJohn Forte 
3851fcf3ce44SJohn Forte /*
3852fcf3ce44SJohn Forte  * *************************************************************************
3853fcf3ce44SJohn Forte  *
3854fcf3ce44SJohn Forte  * main
3855fcf3ce44SJohn Forte  *
3856fcf3ce44SJohn Forte  * *************************************************************************
3857fcf3ce44SJohn Forte  */
3858fcf3ce44SJohn Forte int
3859fcf3ce44SJohn Forte main(int argc, char *argv[])
3860fcf3ce44SJohn Forte {
3861fcf3ce44SJohn Forte 	synTables_t 			synTables;
3862fcf3ce44SJohn Forte 	char 				versionString[VERSION_STRING_MAX_LEN];
3863fcf3ce44SJohn Forte 	int 				ret;
3864fcf3ce44SJohn Forte 	int 				funcRet;
3865fcf3ce44SJohn Forte 	void 				*subcommandArgs = NULL;
3866fcf3ce44SJohn Forte 
3867fcf3ce44SJohn Forte 	(void) setlocale(LC_ALL, "");
3868fcf3ce44SJohn Forte 
3869fcf3ce44SJohn Forte 	(void) sprintf(versionString, "%2s.%2s",
3870fcf3ce44SJohn Forte 	    VERSION_STRING_MAJOR, VERSION_STRING_MINOR);
3871fcf3ce44SJohn Forte 	synTables.versionString = versionString;
3872fcf3ce44SJohn Forte 	synTables.longOptionTbl = &longOptions[0];
3873fcf3ce44SJohn Forte 	synTables.subCommandPropsTbl = &subcommands[0];
3874fcf3ce44SJohn Forte 
3875fcf3ce44SJohn Forte 	ret = cmdParse(argc, argv, synTables, subcommandArgs, &funcRet);
3876fcf3ce44SJohn Forte 
3877fcf3ce44SJohn Forte 	if (ret == 1) {
3878fcf3ce44SJohn Forte 		return (COMMAND_SYNTAX_FAILED);
3879fcf3ce44SJohn Forte 	} else if (ret == -1) {
3880fcf3ce44SJohn Forte 		perror(argv[0]);
3881fcf3ce44SJohn Forte 		return (1);
3882fcf3ce44SJohn Forte 	} else if (ret == 0) {
3883fcf3ce44SJohn Forte 		/*
3884fcf3ce44SJohn Forte 		 * strawman way to sort out the error code.
3885fcf3ce44SJohn Forte 		 * isnsi server protocol error range 0 - 99
3886fcf3ce44SJohn Forte 		 * isns server maangement op error range 100 -199
3887fcf3ce44SJohn Forte 		 * isnsadm error range 200 -299
3888fcf3ce44SJohn Forte 		 */
3889fcf3ce44SJohn Forte 	    if (funcRet == SUBCOMMAND_SUCCESS) {
3890fcf3ce44SJohn Forte 		return (0);
3891fcf3ce44SJohn Forte 	    } else if (funcRet > SUBCOMMAND_SUCCESS) {
3892fcf3ce44SJohn Forte 		if (funcRet != ERROR_DOOR_CALL_FAILED &&
3893fcf3ce44SJohn Forte 		    funcRet != ERROR_DOOR_OPEN_FAILED) {
3894fcf3ce44SJohn Forte 		    (void) fprintf(stderr, "%s\n", getTextMessage(funcRet));
3895fcf3ce44SJohn Forte 		}
3896fcf3ce44SJohn Forte 		return (1);
3897fcf3ce44SJohn Forte 	    } else {
3898fcf3ce44SJohn Forte 		return (1);
3899fcf3ce44SJohn Forte 	    }
3900fcf3ce44SJohn Forte 	}
3901fcf3ce44SJohn Forte 
3902fcf3ce44SJohn Forte 	return (0);
3903fcf3ce44SJohn Forte } /* end main */
3904