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 /*
22fb2a9baeSyi zhang - Sun Microsystems - Beijing China  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23fcf3ce44SJohn Forte  */
24fcf3ce44SJohn Forte 
25fcf3ce44SJohn Forte #include <stdlib.h>
26fcf3ce44SJohn Forte #include <stdio.h>
27fcf3ce44SJohn Forte #include <wchar.h>
28fcf3ce44SJohn Forte #include <widec.h>
29fcf3ce44SJohn Forte #include <sys/types.h>
30fcf3ce44SJohn Forte #include <sys/socket.h>
31fcf3ce44SJohn Forte #include <arpa/inet.h>
32fcf3ce44SJohn Forte #include <netdb.h>
33fcf3ce44SJohn Forte #include <unistd.h>
34fcf3ce44SJohn Forte #include <libintl.h>
35fcf3ce44SJohn Forte #include <limits.h>
36fcf3ce44SJohn Forte #include <string.h>
37fcf3ce44SJohn Forte #include <strings.h>
38fcf3ce44SJohn Forte #include <syslog.h>
39fcf3ce44SJohn Forte #include <errno.h>
40fcf3ce44SJohn Forte #include <netinet/in.h>
41fcf3ce44SJohn Forte #include <sys/socket.h>
42fcf3ce44SJohn Forte #include <arpa/inet.h>
43fcf3ce44SJohn Forte #include <wctype.h>
44fcf3ce44SJohn Forte #include <assert.h>
45fcf3ce44SJohn Forte 
46fcf3ce44SJohn Forte #include <ima.h>
47aff4bce5Syi zhang - Sun Microsystems - Beijing China #include <libsun_ima.h>
481a1a84a3SPeter Dunlap #include <sys/iscsi_protocol.h>
49fcf3ce44SJohn Forte #include <sys/scsi/adapters/iscsi_if.h>
50fcf3ce44SJohn Forte 
51fcf3ce44SJohn Forte #include "cmdparse.h"
52fcf3ce44SJohn Forte #include "sun_ima.h"
53fcf3ce44SJohn Forte #include "iscsiadm.h"
54fcf3ce44SJohn Forte 
55fcf3ce44SJohn Forte #define	VERSION_STRING_MAX_LEN	10
56fcf3ce44SJohn Forte #define	MAX_LONG_CHAR_LEN 19
57fcf3ce44SJohn Forte 
58fcf3ce44SJohn Forte #define	MAX_AUTH_METHODS 5
59fcf3ce44SJohn Forte /*
60fcf3ce44SJohn Forte  * Version number:
61fcf3ce44SJohn Forte  *  MAJOR - This should only change when there is an incompatible change made
62fcf3ce44SJohn Forte  *  to the interfaces or the output.
63fcf3ce44SJohn Forte  *
64fcf3ce44SJohn Forte  *  MINOR - This should change whenever there is a new command or new feature
65fcf3ce44SJohn Forte  *  with no incompatible change.
66fcf3ce44SJohn Forte  */
67fcf3ce44SJohn Forte #define	VERSION_STRING_MAJOR	    "1"
68fcf3ce44SJohn Forte #define	VERSION_STRING_MINOR	    "0"
69fcf3ce44SJohn Forte 
70fcf3ce44SJohn Forte #define	OPTIONSTRING1	"yes|no"
71fcf3ce44SJohn Forte #define	OPTIONSTRING2	"initiator node name"
72fcf3ce44SJohn Forte #define	OPTIONSTRING3	"initiator node alias"
73fcf3ce44SJohn Forte #define	OPTIONSTRING4	"enable|disable"
74fcf3ce44SJohn Forte #define	OPTIONSTRING5	"key=value,..."
75fcf3ce44SJohn Forte #define	OPTIONSTRING6	"none|CRC32"
76fcf3ce44SJohn Forte #define	OPTIONSTRING7	"CHAP name"
77fcf3ce44SJohn Forte #define	OPTIONSTRING8	"<# sessions>|<IP Address>[,<IP Address>]*"
78aff4bce5Syi zhang - Sun Microsystems - Beijing China #define	OPTIONSTRING9	"tunable-prop=value"
79fcf3ce44SJohn Forte #define	OPTIONVAL1	"0 to 3600"
80fcf3ce44SJohn Forte #define	OPTIONVAL2	"512 to 2**24 - 1"
81fcf3ce44SJohn Forte #define	OPTIONVAL3	"1 to 65535"
82fcf3ce44SJohn Forte #define	OPTIONVAL4	"<IP address>[:port]"
83fcf3ce44SJohn Forte 
84fcf3ce44SJohn Forte #define	MAX_ISCSI_NAME_LEN	    223
85fcf3ce44SJohn Forte #define	MAX_ADDRESS_LEN		    255
86fcf3ce44SJohn Forte #define	MIN_CHAP_SECRET_LEN	    12
87fcf3ce44SJohn Forte #define	MAX_CHAP_SECRET_LEN	    16
88fcf3ce44SJohn Forte #define	DEFAULT_ISCSI_PORT	    3260
89fcf3ce44SJohn Forte #define	ISNS_DEFAULT_SERVER_PORT    3205
90fcf3ce44SJohn Forte #define	DEFAULT_RADIUS_PORT	    1812
91fcf3ce44SJohn Forte #define	MAX_CHAP_NAME_LEN	    512
92aff4bce5Syi zhang - Sun Microsystems - Beijing China #define	ISCSI_DEFAULT_RX_TIMEOUT_VALUE		"60"
93aff4bce5Syi zhang - Sun Microsystems - Beijing China #define	ISCSI_DEFAULT_CONN_DEFAULT_LOGIN_MAX	"180"
94aff4bce5Syi zhang - Sun Microsystems - Beijing China #define	ISCSI_DEFAULT_LOGIN_POLLING_DELAY	"60"
95fcf3ce44SJohn Forte 
96fcf3ce44SJohn Forte /* For listNode */
97fcf3ce44SJohn Forte #define	INF_ERROR		1
98fcf3ce44SJohn Forte #define	INVALID_NODE_NAME	2
99fcf3ce44SJohn Forte 
100fcf3ce44SJohn Forte #define	IMABOOLPRINT(prop, option)	 \
101fcf3ce44SJohn Forte 	if ((option) == PRINT_CONFIGURED_PARAMS) { \
102fcf3ce44SJohn Forte 		(void) fprintf(stdout, "%s/%s\n", \
103fcf3ce44SJohn Forte 		(prop).defaultValue == IMA_TRUE ? gettext("yes") : \
104fcf3ce44SJohn Forte 			gettext("no"), \
105fcf3ce44SJohn Forte 		(prop).currentValueValid == IMA_TRUE ? \
106fcf3ce44SJohn Forte 			((prop).currentValue == IMA_TRUE ? \
107fcf3ce44SJohn Forte 			gettext("yes"): gettext("no")) : "-"); \
108fcf3ce44SJohn Forte 	} else if ((option) == PRINT_NEGOTIATED_PARAMS) { \
109fcf3ce44SJohn Forte 		(void) fprintf(stdout, "%s\n", \
110fcf3ce44SJohn Forte 		(prop).currentValueValid == IMA_TRUE ? \
111fcf3ce44SJohn Forte 		(((prop).currentValue == IMA_TRUE) ? gettext("yes") : \
112fcf3ce44SJohn Forte 		gettext("no")) : "-"); \
113fcf3ce44SJohn Forte 	}
114fcf3ce44SJohn Forte 
115fcf3ce44SJohn Forte #define	IMAMINMAXPRINT(prop, option) \
116fcf3ce44SJohn Forte 	if ((option) == PRINT_CONFIGURED_PARAMS) { \
117fcf3ce44SJohn Forte 		(void) fprintf(stdout, "%d/", (prop).defaultValue); \
118fcf3ce44SJohn Forte 		if ((prop).currentValueValid == IMA_TRUE) { \
119fcf3ce44SJohn Forte 			(void) fprintf(stdout, "%d\n", (prop).currentValue); \
120fcf3ce44SJohn Forte 		} else if ((prop).currentValueValid == IMA_FALSE) { \
121fcf3ce44SJohn Forte 			(void) fprintf(stdout, "%s\n", "-"); \
122fcf3ce44SJohn Forte 		} \
123fcf3ce44SJohn Forte 	} else if ((option) == PRINT_NEGOTIATED_PARAMS) { \
124fcf3ce44SJohn Forte 		if ((prop).currentValueValid == IMA_TRUE) { \
125fcf3ce44SJohn Forte 			(void) fprintf(stdout, "%d\n", (prop).currentValue); \
126fcf3ce44SJohn Forte 		} else if ((prop).currentValueValid == IMA_FALSE) { \
127fcf3ce44SJohn Forte 			(void) fprintf(stdout, "%s\n", "-"); \
128fcf3ce44SJohn Forte 		} \
129fcf3ce44SJohn Forte 	}
130fcf3ce44SJohn Forte 
131fcf3ce44SJohn Forte /* forward declarations */
132fcf3ce44SJohn Forte #define	PARSE_ADDR_OK				0
133fcf3ce44SJohn Forte #define	PARSE_ADDR_MISSING_CLOSING_BRACKET	1
134fcf3ce44SJohn Forte #define	PARSE_ADDR_PORT_OUT_OF_RANGE		2
135fcf3ce44SJohn Forte #define	PARSE_TARGET_OK				0
136fcf3ce44SJohn Forte #define	PARSE_TARGET_INVALID_TPGT		1
137fcf3ce44SJohn Forte #define	PARSE_TARGET_INVALID_ADDR		2
138fcf3ce44SJohn Forte 
139fcf3ce44SJohn Forte #define	PRINT_CONFIGURED_PARAMS			1
140fcf3ce44SJohn Forte #define	PRINT_NEGOTIATED_PARAMS			2
141fcf3ce44SJohn Forte 
142fcf3ce44SJohn Forte typedef enum iSCSINameCheckStatus {
143fcf3ce44SJohn Forte 	iSCSINameCheckOK,
144fcf3ce44SJohn Forte 	iSCSINameLenZero,
145fcf3ce44SJohn Forte 	iSCSINameLenExceededMax,
146fcf3ce44SJohn Forte 	iSCSINameUnknownType,
147fcf3ce44SJohn Forte 	iSCSINameInvalidCharacter,
148fcf3ce44SJohn Forte 	iSCSINameIqnFormatError,
149fcf3ce44SJohn Forte 	iSCSINameEUIFormatError,
150fcf3ce44SJohn Forte 	iSCSINameIqnDateFormatError,
151fcf3ce44SJohn Forte 	iSCSINameIqnSubdomainFormatError,
152fcf3ce44SJohn Forte 	iSCSINameIqnInvalidYearError,
153fcf3ce44SJohn Forte 	iSCSINameIqnInvalidMonthError,
154fcf3ce44SJohn Forte 	iSCSINameIqnFQDNError
155fcf3ce44SJohn Forte } iSCSINameCheckStatusType;
156fcf3ce44SJohn Forte 
157fcf3ce44SJohn Forte /* Utility functions */
158fcf3ce44SJohn Forte iSCSINameCheckStatusType iSCSINameStringProfileCheck(wchar_t *name);
159fcf3ce44SJohn Forte boolean_t isNaturalNumber(char *numberStr, uint32_t upperBound);
160fcf3ce44SJohn Forte static int parseAddress(char *address_port_str, uint16_t defaultPort,
161fcf3ce44SJohn Forte     char *address_str, size_t address_str_len,
162fcf3ce44SJohn Forte     uint16_t *port, boolean_t *isIpv6);
163fcf3ce44SJohn Forte int parseTarget(char *targetStr,
164fcf3ce44SJohn Forte     wchar_t *targetNameStr,
165fcf3ce44SJohn Forte     size_t targetNameStrLen,
166fcf3ce44SJohn Forte     boolean_t *targetAddressSpecified,
167fcf3ce44SJohn Forte     wchar_t *targetAddressStr,
168fcf3ce44SJohn Forte     size_t targetAddressStrLen,
169fcf3ce44SJohn Forte     uint16_t *port,
170fcf3ce44SJohn Forte     boolean_t *tpgtSpecified,
171fcf3ce44SJohn Forte     uint16_t *tpgt,
172fcf3ce44SJohn Forte     boolean_t *isIpv6);
173aff4bce5Syi zhang - Sun Microsystems - Beijing China static int chkConnLoginMaxPollingLoginDelay(IMA_OID oid,
174aff4bce5Syi zhang - Sun Microsystems - Beijing China     int key, int uintValue);
175fcf3ce44SJohn Forte 
176fcf3ce44SJohn Forte /* subcommand functions */
177fcf3ce44SJohn Forte static int addFunc(int, char **, int, cmdOptions_t *, void *, int *);
178fcf3ce44SJohn Forte static int listFunc(int, char **, int, cmdOptions_t *, void *, int *);
179fcf3ce44SJohn Forte static int modifyFunc(int, char **, int, cmdOptions_t *, void *, int *);
180fcf3ce44SJohn Forte static int removeFunc(int, char **, int, cmdOptions_t *, void *, int *);
181fcf3ce44SJohn Forte 
182fcf3ce44SJohn Forte /* helper functions */
183fcf3ce44SJohn Forte static char *getExecBasename(char *);
184fcf3ce44SJohn Forte static int getNodeProps(IMA_NODE_PROPERTIES *);
185fcf3ce44SJohn Forte static int getSecret(char *, int *, int, int);
186fcf3ce44SJohn Forte static int getTargetAddress(int, char *, IMA_TARGET_ADDRESS *);
187fcf3ce44SJohn Forte static int printLoginParameters(char *, IMA_OID, int);
188fcf3ce44SJohn Forte static void printDiscoveryMethod(char *, IMA_UINT32);
189fcf3ce44SJohn Forte static void printTargetLuns(IMA_OID_LIST *);
190fcf3ce44SJohn Forte static void printSendTargets(SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES *);
191fcf3ce44SJohn Forte static void printDigestAlgorithm(SUN_IMA_DIGEST_ALGORITHM_VALUE *, int);
192fcf3ce44SJohn Forte static int setLoginParameter(IMA_OID, int, char *);
193fcf3ce44SJohn Forte static int setLoginParameters(IMA_OID, char *);
194aff4bce5Syi zhang - Sun Microsystems - Beijing China static int setTunableParameters(IMA_OID, char *);
195fcf3ce44SJohn Forte static void printLibError(IMA_STATUS);
196fcf3ce44SJohn Forte /* LINTED E_STATIC_UNUSED */
197fcf3ce44SJohn Forte static int sunPluginChk(IMA_OID, boolean_t *);
198fcf3ce44SJohn Forte static int sunInitiatorFind(IMA_OID *);
199fcf3ce44SJohn Forte static int getAuthMethodValue(char *, IMA_AUTHMETHOD *);
200fcf3ce44SJohn Forte static int getLoginParam(char *);
201aff4bce5Syi zhang - Sun Microsystems - Beijing China static int getTunableParam(char *);
202fcf3ce44SJohn Forte static void iSCSINameCheckStatusDisplay(iSCSINameCheckStatusType status);
203fcf3ce44SJohn Forte static int modifyIndividualTargetParam(cmdOptions_t *optionList,
204fcf3ce44SJohn Forte     IMA_OID targetOid, int *);
205fcf3ce44SJohn Forte static void listCHAPName(IMA_OID oid);
206fcf3ce44SJohn Forte static int printConfiguredSessions(IMA_OID);
207aff4bce5Syi zhang - Sun Microsystems - Beijing China static int printTunableParameters(IMA_OID oid);
208fcf3ce44SJohn Forte 
209fcf3ce44SJohn Forte /* object functions per subcommand */
210fcf3ce44SJohn Forte static int addAddress(int, int, char *[], int *);
211fcf3ce44SJohn Forte static int addStaticConfig(int, char *[], int *);
212fcf3ce44SJohn Forte static int listDiscovery(int *);
213fcf3ce44SJohn Forte static int listDiscoveryAddress(int, char *[], cmdOptions_t *, int *);
214fcf3ce44SJohn Forte static int listISNSServerAddress(int, char *[], cmdOptions_t *, int *);
215fcf3ce44SJohn Forte static int listNode(int *);
216fcf3ce44SJohn Forte static int listStaticConfig(int, char *[], int *);
217fcf3ce44SJohn Forte static int listTarget(int, char *[], cmdOptions_t *, int *);
218fcf3ce44SJohn Forte static int listTargetParam(int, char *[], cmdOptions_t *, int *);
219fcf3ce44SJohn Forte static int modifyDiscovery(cmdOptions_t *, int *);
220fcf3ce44SJohn Forte static int modifyNodeAuthMethod(IMA_OID, char *, int *);
221fcf3ce44SJohn Forte static int modifyNodeAuthParam(IMA_OID oid, int, char *, int *);
222fcf3ce44SJohn Forte static int modifyNodeRadiusConfig(IMA_OID, char *, int *);
223fcf3ce44SJohn Forte static int modifyNodeRadiusAccess(IMA_OID, char *, int *);
224fcf3ce44SJohn Forte static int modifyNodeRadiusSharedSecret(IMA_OID, int *);
225fcf3ce44SJohn Forte static int modifyNode(cmdOptions_t *, int *);
226fcf3ce44SJohn Forte static int modifyTargetAuthMethod(IMA_OID, char *, int *);
227fcf3ce44SJohn Forte static int modifyTargetAuthParam(IMA_OID oid, int param, char *chapName, int *);
228fcf3ce44SJohn Forte static int modifyTargetParam(cmdOptions_t *, char *, int *);
229fcf3ce44SJohn Forte static int removeAddress(int, int, char *[], int *);
230fcf3ce44SJohn Forte static int removeStaticConfig(int, char *[], int *);
231fcf3ce44SJohn Forte static int removeTargetParam(int, char *[], int *);
232fcf3ce44SJohn Forte static int modifyTargetBidirAuthFlag(IMA_OID, char *, int *);
233fcf3ce44SJohn Forte static int modifyConfiguredSessions(IMA_OID targetOid, char *optarg);
234fcf3ce44SJohn Forte 
235fcf3ce44SJohn Forte /* LINTED E_STATIC_UNUSED */
236fcf3ce44SJohn Forte static IMA_STATUS getISCSINodeParameter(int paramType,
237fcf3ce44SJohn Forte     IMA_OID *oid,
238fcf3ce44SJohn Forte     void *pProps,
239fcf3ce44SJohn Forte     uint32_t paramIndex);
240fcf3ce44SJohn Forte /* LINTED E_STATIC_UNUSED */
241fcf3ce44SJohn Forte static IMA_STATUS setISCSINodeParameter(int paramType,
242fcf3ce44SJohn Forte     IMA_OID *oid,
243fcf3ce44SJohn Forte     void *pProps,
244fcf3ce44SJohn Forte     uint32_t paramIndex);
245fcf3ce44SJohn Forte /* LINTED E_STATIC_UNUSED */
246fcf3ce44SJohn Forte static IMA_STATUS getDigest(IMA_OID oid, int ioctlCmd,
247fcf3ce44SJohn Forte     SUN_IMA_DIGEST_ALGORITHM_VALUE *algorithm);
248fcf3ce44SJohn Forte 
249fcf3ce44SJohn Forte IMA_STATUS getNegotiatedDigest(int digestType,
250fcf3ce44SJohn Forte 	SUN_IMA_DIGEST_ALGORITHM_VALUE *algorithm,
251fcf3ce44SJohn Forte 	SUN_IMA_CONN_PROPERTIES *connProps);
252fcf3ce44SJohn Forte 
253fcf3ce44SJohn Forte /* globals */
254fcf3ce44SJohn Forte static char *cmdName;
255fcf3ce44SJohn Forte 
256fcf3ce44SJohn Forte /*
257fcf3ce44SJohn Forte  * Available option letters:
258fcf3ce44SJohn Forte  *
259904e51f6SJack Meng  * befgijklmnoquwxyz
260fcf3ce44SJohn Forte  *
261aff4bce5Syi zhang - Sun Microsystems - Beijing China  * DEFGHIJKLMOQUVWXYZ
262fcf3ce44SJohn Forte  */
263fcf3ce44SJohn Forte 
264fcf3ce44SJohn Forte /*
265fcf3ce44SJohn Forte  * Add new options here
266fcf3ce44SJohn Forte  */
267fcf3ce44SJohn Forte optionTbl_t longOptions[] = {
268fcf3ce44SJohn Forte 	{"static", required_arg, 's', OPTIONSTRING4},
269fcf3ce44SJohn Forte 	{"sendtargets", required_arg, 't', OPTIONSTRING4},
270fcf3ce44SJohn Forte 	{"iSNS", required_arg, 'i', OPTIONSTRING4},
271fcf3ce44SJohn Forte 	{"headerdigest", required_arg, 'h', OPTIONSTRING6},
272fcf3ce44SJohn Forte 	{"datadigest", required_arg, 'd', OPTIONSTRING6},
273fcf3ce44SJohn Forte 	{"login-param", required_arg, 'p', OPTIONSTRING5},
274fcf3ce44SJohn Forte 	{"authentication", required_arg, 'a', "CHAP|none"},
275fcf3ce44SJohn Forte 	{"bi-directional-authentication", required_arg, 'B', OPTIONSTRING4},
276fcf3ce44SJohn Forte 	{"CHAP-secret", no_arg, 'C', NULL},
277fcf3ce44SJohn Forte 	{"CHAP-name", required_arg, 'H', OPTIONSTRING7},
278fcf3ce44SJohn Forte 	{"node-name", required_arg, 'N', OPTIONSTRING2},
279fcf3ce44SJohn Forte 	{"node-alias", required_arg, 'A', OPTIONSTRING3},
280fcf3ce44SJohn Forte 	{"radius-server", required_arg, 'r', OPTIONVAL4},
281fcf3ce44SJohn Forte 	{"radius-access", required_arg, 'R', OPTIONSTRING4},
282fcf3ce44SJohn Forte 	{"radius-shared-secret", no_arg, 'P', NULL},
283fcf3ce44SJohn Forte 	{"verbose", no_arg, 'v', NULL},
284fcf3ce44SJohn Forte 	{"scsi-target", no_arg, 'S', NULL},
285fcf3ce44SJohn Forte 	{"configured-sessions", required_arg, 'c', OPTIONSTRING8},
286aff4bce5Syi zhang - Sun Microsystems - Beijing China 	{"tunable-param", required_arg, 'T', OPTIONSTRING9},
287fcf3ce44SJohn Forte 	{NULL, 0, 0, 0}
288fcf3ce44SJohn Forte };
289fcf3ce44SJohn Forte 
290fcf3ce44SJohn Forte parameterTbl_t loginParams[] = {
291fcf3ce44SJohn Forte 	{"dataseqinorder", DATA_SEQ_IN_ORDER},
292fcf3ce44SJohn Forte 	{"defaulttime2retain", DEFAULT_TIME_2_RETAIN},
293fcf3ce44SJohn Forte 	{"defaulttime2wait", DEFAULT_TIME_2_WAIT},
294fcf3ce44SJohn Forte 	{"firstburstlength", FIRST_BURST_LENGTH},
295fcf3ce44SJohn Forte 	{"immediatedata", IMMEDIATE_DATA},
296fcf3ce44SJohn Forte 	{"initialr2t", INITIAL_R2T},
297fcf3ce44SJohn Forte 	{"maxburstlength", MAX_BURST_LENGTH},
298fcf3ce44SJohn Forte 	{"datapduinorder", DATA_PDU_IN_ORDER},
299fcf3ce44SJohn Forte 	{"maxoutstandingr2t", MAX_OUTSTANDING_R2T},
300fcf3ce44SJohn Forte 	{"maxrecvdataseglen", MAX_RECV_DATA_SEG_LEN},
301fcf3ce44SJohn Forte 	{"maxconnections", MAX_CONNECTIONS},
302fcf3ce44SJohn Forte 	{"errorrecoverylevel", ERROR_RECOVERY_LEVEL},
303fcf3ce44SJohn Forte 	{NULL, 0}
304fcf3ce44SJohn Forte };
305fcf3ce44SJohn Forte 
306aff4bce5Syi zhang - Sun Microsystems - Beijing China parameterTbl_t tunableParams[] = {
307aff4bce5Syi zhang - Sun Microsystems - Beijing China 	{"recv-login-rsp-timeout", RECV_LOGIN_RSP_TIMEOUT},
308aff4bce5Syi zhang - Sun Microsystems - Beijing China 	{"conn-login-max", CONN_LOGIN_MAX},
309aff4bce5Syi zhang - Sun Microsystems - Beijing China 	{"polling-login-delay", POLLING_LOGIN_DELAY},
310aff4bce5Syi zhang - Sun Microsystems - Beijing China 	{NULL, 0}
311aff4bce5Syi zhang - Sun Microsystems - Beijing China };
312aff4bce5Syi zhang - Sun Microsystems - Beijing China 
313fcf3ce44SJohn Forte /*
314fcf3ce44SJohn Forte  * Add new subcommands here
315fcf3ce44SJohn Forte  */
316fcf3ce44SJohn Forte subcommand_t subcommands[] = {
317fcf3ce44SJohn Forte 	{"add", ADD, addFunc},
318fcf3ce44SJohn Forte 	{"list", LIST, listFunc},
319fcf3ce44SJohn Forte 	{"modify", MODIFY, modifyFunc},
320fcf3ce44SJohn Forte 	{"remove", REMOVE, removeFunc},
321fcf3ce44SJohn Forte 	{NULL, 0, NULL}
322fcf3ce44SJohn Forte };
323fcf3ce44SJohn Forte 
324fcf3ce44SJohn Forte /*
325fcf3ce44SJohn Forte  * Add objects here
326fcf3ce44SJohn Forte  */
327fcf3ce44SJohn Forte object_t objects[] = {
328fcf3ce44SJohn Forte 	{"discovery", DISCOVERY},
329fcf3ce44SJohn Forte 	{"discovery-address", DISCOVERY_ADDRESS},
330fcf3ce44SJohn Forte 	{"isns-server", ISNS_SERVER_ADDRESS},
331fcf3ce44SJohn Forte 	{"initiator-node", NODE},
332fcf3ce44SJohn Forte 	{"static-config", STATIC_CONFIG},
333fcf3ce44SJohn Forte 	{"target", TARGET},
334fcf3ce44SJohn Forte 	{"target-param", TARGET_PARAM},
335fcf3ce44SJohn Forte 	{NULL, 0}
336fcf3ce44SJohn Forte };
337fcf3ce44SJohn Forte 
338fcf3ce44SJohn Forte /*
339fcf3ce44SJohn Forte  * Rules for subcommands and objects
340fcf3ce44SJohn Forte  */
341fcf3ce44SJohn Forte objectRules_t objectRules[] = {
342fcf3ce44SJohn Forte 	{TARGET, 0, LIST, 0, ADD|REMOVE|MODIFY, LIST,
343fcf3ce44SJohn Forte 	"target-name"},
344fcf3ce44SJohn Forte 	{TARGET_PARAM, MODIFY|REMOVE, LIST, 0, ADD, MODIFY,
345fcf3ce44SJohn Forte 	"target-name"},
346fcf3ce44SJohn Forte 	{DISCOVERY, 0, 0, LIST|MODIFY, ADD|REMOVE, 0, NULL},
347fcf3ce44SJohn Forte 	{NODE, 0, 0, MODIFY|LIST, ADD|REMOVE, 0, NULL},
348fcf3ce44SJohn Forte 	{STATIC_CONFIG, ADD|REMOVE, LIST, 0, MODIFY, ADD|REMOVE|LIST,
349fcf3ce44SJohn Forte 	"target-name,target-address[:port-number][,tpgt]"},
350fcf3ce44SJohn Forte 	{DISCOVERY_ADDRESS, ADD|REMOVE, LIST, 0, MODIFY,
351fcf3ce44SJohn Forte 	ADD|REMOVE|LIST, "IP-address[:port-number]"},
352fcf3ce44SJohn Forte 	{ISNS_SERVER_ADDRESS, ADD|REMOVE, LIST, 0, MODIFY,
353fcf3ce44SJohn Forte 	ADD|REMOVE|LIST, "IP-address[:port-number]"},
35433c72b75SToomas Soome 	{0, 0, 0, 0, 0, 0}
355fcf3ce44SJohn Forte };
356fcf3ce44SJohn Forte 
357fcf3ce44SJohn Forte /*
358fcf3ce44SJohn Forte  * list of objects, subcommands, valid short options, required flag and
359fcf3ce44SJohn Forte  * exclusive option string
360fcf3ce44SJohn Forte  *
361fcf3ce44SJohn Forte  * If it's not here, there are no options for that object.
362fcf3ce44SJohn Forte  */
363fcf3ce44SJohn Forte optionRules_t optionRules[] = {
364fcf3ce44SJohn Forte 	{DISCOVERY, MODIFY, "sti", B_TRUE, NULL},
365fcf3ce44SJohn Forte 	{DISCOVERY_ADDRESS, LIST, "v", B_FALSE, NULL},
366fcf3ce44SJohn Forte 	{ISNS_SERVER_ADDRESS, LIST, "v", B_FALSE, NULL},
367fcf3ce44SJohn Forte 	{TARGET, LIST, "vS", B_FALSE, NULL},
368aff4bce5Syi zhang - Sun Microsystems - Beijing China 	{NODE, MODIFY, "NAhdCaRrPHcT", B_TRUE, "CP"},
369aff4bce5Syi zhang - Sun Microsystems - Beijing China 	{TARGET_PARAM, MODIFY, "ahdBCpcHT", B_TRUE, "C"},
370fcf3ce44SJohn Forte 	{TARGET_PARAM, LIST, "v", B_FALSE, NULL},
371fcf3ce44SJohn Forte 	{0, 0, 0, 0, 0}
372fcf3ce44SJohn Forte };
373fcf3ce44SJohn Forte 
374fcf3ce44SJohn Forte 
375fcf3ce44SJohn Forte static boolean_t
targetNamesEqual(wchar_t * name1,wchar_t * name2)376fcf3ce44SJohn Forte targetNamesEqual(wchar_t *name1, wchar_t *name2)
377fcf3ce44SJohn Forte {
378fcf3ce44SJohn Forte 	int i;
379fcf3ce44SJohn Forte 	wchar_t wchar1, wchar2;
380fcf3ce44SJohn Forte 
381fcf3ce44SJohn Forte 	if (name1 == NULL || name2 == NULL) {
382fcf3ce44SJohn Forte 		return (B_FALSE);
383fcf3ce44SJohn Forte 	}
384fcf3ce44SJohn Forte 
385fcf3ce44SJohn Forte 	if (wcslen(name1) != wcslen(name2)) {
386fcf3ce44SJohn Forte 		return (B_FALSE);
387fcf3ce44SJohn Forte 	}
388fcf3ce44SJohn Forte 
389fcf3ce44SJohn Forte 	/*
390fcf3ce44SJohn Forte 	 * Convert names to lower case and compare
391fcf3ce44SJohn Forte 	 */
392fcf3ce44SJohn Forte 	for (i = 0; i < wcslen(name1); i++) {
393fcf3ce44SJohn Forte 		wchar1 = towctrans((wint_t)name1[i], wctrans("tolower"));
394fcf3ce44SJohn Forte 		wchar2 = towctrans((wint_t)name2[i], wctrans("tolower"));
395fcf3ce44SJohn Forte 
396fcf3ce44SJohn Forte 		if (wchar1 != wchar2) {
397fcf3ce44SJohn Forte 			return (B_FALSE);
398fcf3ce44SJohn Forte 		}
399fcf3ce44SJohn Forte 	}
400fcf3ce44SJohn Forte 
401fcf3ce44SJohn Forte 	return (B_TRUE);
402fcf3ce44SJohn Forte }
403fcf3ce44SJohn Forte 
404fcf3ce44SJohn Forte static boolean_t
ipAddressesEqual(IMA_TARGET_ADDRESS addr1,IMA_TARGET_ADDRESS addr2)405fcf3ce44SJohn Forte ipAddressesEqual(IMA_TARGET_ADDRESS addr1, IMA_TARGET_ADDRESS addr2)
406fcf3ce44SJohn Forte {
407fcf3ce44SJohn Forte #define	IPV4_ADDR_BYTES 4
408fcf3ce44SJohn Forte #define	IPV6_ADDR_BYTES 16
409fcf3ce44SJohn Forte 
410fcf3ce44SJohn Forte 	int compSize;
411fcf3ce44SJohn Forte 
412fcf3ce44SJohn Forte 	if (addr1.hostnameIpAddress.id.ipAddress.ipv4Address !=
413fcf3ce44SJohn Forte 	    addr2.hostnameIpAddress.id.ipAddress.ipv4Address) {
414fcf3ce44SJohn Forte 		return (B_FALSE);
415fcf3ce44SJohn Forte 	}
416fcf3ce44SJohn Forte 
417fcf3ce44SJohn Forte 	compSize = IPV6_ADDR_BYTES;
418fcf3ce44SJohn Forte 	if (addr1.hostnameIpAddress.id.ipAddress.ipv4Address) {
419fcf3ce44SJohn Forte 		compSize = IPV4_ADDR_BYTES;
420fcf3ce44SJohn Forte 	}
421fcf3ce44SJohn Forte 
422fcf3ce44SJohn Forte 	if (bcmp(addr1.hostnameIpAddress.id.ipAddress.ipAddress,
423fcf3ce44SJohn Forte 	    addr2.hostnameIpAddress.id.ipAddress.ipAddress, compSize) == 0) {
424fcf3ce44SJohn Forte 		return (B_TRUE);
425fcf3ce44SJohn Forte 	}
426fcf3ce44SJohn Forte 
427fcf3ce44SJohn Forte 	return (B_FALSE);
428fcf3ce44SJohn Forte }
429fcf3ce44SJohn Forte 
430fcf3ce44SJohn Forte static int
getLoginParam(char * arg)431fcf3ce44SJohn Forte getLoginParam(char *arg)
432fcf3ce44SJohn Forte {
433fcf3ce44SJohn Forte 	parameterTbl_t *paramp;
434fcf3ce44SJohn Forte 	int len;
435fcf3ce44SJohn Forte 
436fcf3ce44SJohn Forte 	for (paramp = loginParams; paramp->name; paramp++) {
437fcf3ce44SJohn Forte 		len = strlen(arg);
438fcf3ce44SJohn Forte 		if (len == strlen(paramp->name) &&
439fcf3ce44SJohn Forte 		    strncasecmp(arg, paramp->name, len) == 0) {
440fcf3ce44SJohn Forte 			return (paramp->val);
441fcf3ce44SJohn Forte 		}
442fcf3ce44SJohn Forte 	}
443fcf3ce44SJohn Forte 	return (-1);
444fcf3ce44SJohn Forte }
445fcf3ce44SJohn Forte 
446aff4bce5Syi zhang - Sun Microsystems - Beijing China static int
getTunableParam(char * arg)447aff4bce5Syi zhang - Sun Microsystems - Beijing China getTunableParam(char *arg)
448aff4bce5Syi zhang - Sun Microsystems - Beijing China {
449aff4bce5Syi zhang - Sun Microsystems - Beijing China 	parameterTbl_t *paramp;
450aff4bce5Syi zhang - Sun Microsystems - Beijing China 	int len;
451aff4bce5Syi zhang - Sun Microsystems - Beijing China 
452aff4bce5Syi zhang - Sun Microsystems - Beijing China 	for (paramp = tunableParams; paramp->name != NULL; paramp++) {
453aff4bce5Syi zhang - Sun Microsystems - Beijing China 		len = strlen(arg);
454aff4bce5Syi zhang - Sun Microsystems - Beijing China 		if (len == strlen(paramp->name) &&
455aff4bce5Syi zhang - Sun Microsystems - Beijing China 		    strncasecmp(arg, paramp->name, len) == 0) {
456aff4bce5Syi zhang - Sun Microsystems - Beijing China 			return (paramp->val);
457aff4bce5Syi zhang - Sun Microsystems - Beijing China 		}
458aff4bce5Syi zhang - Sun Microsystems - Beijing China 	}
459aff4bce5Syi zhang - Sun Microsystems - Beijing China 	return (-1);
460aff4bce5Syi zhang - Sun Microsystems - Beijing China }
461aff4bce5Syi zhang - Sun Microsystems - Beijing China 
462fcf3ce44SJohn Forte static void
printLibError(IMA_STATUS status)463fcf3ce44SJohn Forte printLibError(IMA_STATUS status)
464fcf3ce44SJohn Forte {
465fcf3ce44SJohn Forte 	char *errorString;
466fcf3ce44SJohn Forte 	switch (status) {
467fcf3ce44SJohn Forte 	case IMA_ERROR_NOT_SUPPORTED:
468fcf3ce44SJohn Forte 		errorString =
469fcf3ce44SJohn Forte 		gettext("Operation currently not supported");
470fcf3ce44SJohn Forte 		break;
471fcf3ce44SJohn Forte 	case IMA_ERROR_INSUFFICIENT_MEMORY:
472fcf3ce44SJohn Forte 		errorString = gettext("Insufficient memory");
473fcf3ce44SJohn Forte 		break;
474fcf3ce44SJohn Forte 	case IMA_ERROR_UNEXPECTED_OS_ERROR:
475fcf3ce44SJohn Forte 		errorString = gettext("unexpected OS error");
476fcf3ce44SJohn Forte 		break;
477fcf3ce44SJohn Forte 	case IMA_ERROR_UNKNOWN_ERROR:
478fcf3ce44SJohn Forte 		errorString = gettext("Unknown error");
479fcf3ce44SJohn Forte 		break;
480fcf3ce44SJohn Forte 	case IMA_ERROR_LU_IN_USE:
481fcf3ce44SJohn Forte 		errorString = gettext("Logical unit in use");
482fcf3ce44SJohn Forte 		break;
483fcf3ce44SJohn Forte 	case IMA_ERROR_INVALID_PARAMETER:
484fcf3ce44SJohn Forte 		errorString = gettext("Invalid parameter specified");
485fcf3ce44SJohn Forte 		break;
486fcf3ce44SJohn Forte 	case IMA_ERROR_INVALID_OBJECT_TYPE:
487fcf3ce44SJohn Forte 		errorString =
488fcf3ce44SJohn Forte 		gettext("Internal library error: Invalid oid type specified");
489fcf3ce44SJohn Forte 		break;
490fcf3ce44SJohn Forte 	case IMA_ERROR_INCORRECT_OBJECT_TYPE:
491fcf3ce44SJohn Forte 		errorString =
492fcf3ce44SJohn Forte 		gettext("Internal library error: Incorrect oid type specified");
493fcf3ce44SJohn Forte 		break;
494fcf3ce44SJohn Forte 	case IMA_ERROR_OBJECT_NOT_FOUND:
495fcf3ce44SJohn Forte 		errorString = gettext("Internal library error: Oid not found");
496fcf3ce44SJohn Forte 		break;
497fcf3ce44SJohn Forte 	case IMA_ERROR_NAME_TOO_LONG:
498fcf3ce44SJohn Forte 		errorString = gettext("Name too long");
499fcf3ce44SJohn Forte 		break;
500fcf3ce44SJohn Forte 	default:
501fcf3ce44SJohn Forte 		errorString = gettext("Unknown error");
502fcf3ce44SJohn Forte 	}
503fcf3ce44SJohn Forte 	(void) fprintf(stderr, "%s: %s\n", cmdName, errorString);
504fcf3ce44SJohn Forte }
505fcf3ce44SJohn Forte 
506fcf3ce44SJohn Forte /*
507fcf3ce44SJohn Forte  * input:
508fcf3ce44SJohn Forte  *  execFullName - exec name of program (argv[0])
509fcf3ce44SJohn Forte  *
510fcf3ce44SJohn Forte  * Returns:
511fcf3ce44SJohn Forte  *  command name portion of execFullName
512fcf3ce44SJohn Forte  */
513fcf3ce44SJohn Forte static char *
getExecBasename(char * execFullname)514fcf3ce44SJohn Forte getExecBasename(char *execFullname)
515fcf3ce44SJohn Forte {
516fcf3ce44SJohn Forte 	char *lastSlash, *execBasename;
517fcf3ce44SJohn Forte 
518fcf3ce44SJohn Forte 	/* guard against '/' at end of command invocation */
519fcf3ce44SJohn Forte 	for (;;) {
520fcf3ce44SJohn Forte 		lastSlash = strrchr(execFullname, '/');
521fcf3ce44SJohn Forte 		if (lastSlash == NULL) {
522fcf3ce44SJohn Forte 			execBasename = execFullname;
523fcf3ce44SJohn Forte 			break;
524fcf3ce44SJohn Forte 		} else {
525fcf3ce44SJohn Forte 			execBasename = lastSlash + 1;
526fcf3ce44SJohn Forte 			if (*execBasename == '\0') {
527fcf3ce44SJohn Forte 				*lastSlash = '\0';
528fcf3ce44SJohn Forte 				continue;
529fcf3ce44SJohn Forte 			}
530fcf3ce44SJohn Forte 			break;
531fcf3ce44SJohn Forte 		}
532fcf3ce44SJohn Forte 	}
533fcf3ce44SJohn Forte 	return (execBasename);
534fcf3ce44SJohn Forte }
535fcf3ce44SJohn Forte 
536fcf3ce44SJohn Forte 
537fcf3ce44SJohn Forte /*
538fcf3ce44SJohn Forte  * input:
539fcf3ce44SJohn Forte  *  nodeProps - pointer to caller allocated IMA_NODE_PROPERTIES
540fcf3ce44SJohn Forte  *
541fcf3ce44SJohn Forte  * returns:
542fcf3ce44SJohn Forte  *  zero on success
543fcf3ce44SJohn Forte  *  non-zero otherwise
544fcf3ce44SJohn Forte  */
545fcf3ce44SJohn Forte static int
getNodeProps(IMA_NODE_PROPERTIES * nodeProps)546fcf3ce44SJohn Forte getNodeProps(IMA_NODE_PROPERTIES *nodeProps)
547fcf3ce44SJohn Forte {
548fcf3ce44SJohn Forte 	IMA_OID sharedNodeOid;
549fcf3ce44SJohn Forte 
550fcf3ce44SJohn Forte 	IMA_STATUS status = IMA_GetSharedNodeOid(&sharedNodeOid);
551fcf3ce44SJohn Forte 	if (!(IMA_SUCCESS(status))) {
552fcf3ce44SJohn Forte 		printLibError(status);
553fcf3ce44SJohn Forte 		return (INF_ERROR);
554fcf3ce44SJohn Forte 	}
555fcf3ce44SJohn Forte 
556fcf3ce44SJohn Forte 	status = IMA_GetNodeProperties(sharedNodeOid, nodeProps);
557fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
558fcf3ce44SJohn Forte 		printLibError(status);
559fcf3ce44SJohn Forte 		return (INF_ERROR);
560fcf3ce44SJohn Forte 	}
561fcf3ce44SJohn Forte 
562fcf3ce44SJohn Forte 	return (0);
563fcf3ce44SJohn Forte }
564fcf3ce44SJohn Forte 
565fcf3ce44SJohn Forte /*
566fcf3ce44SJohn Forte  * sunInitiatorFind
567fcf3ce44SJohn Forte  * Purpose:
568fcf3ce44SJohn Forte  *  Finds the Sun iSCSI initiator (LHBA). This CLI currently supports only
569fcf3ce44SJohn Forte  *  one initiator.
570fcf3ce44SJohn Forte  *
571fcf3ce44SJohn Forte  * output:
572fcf3ce44SJohn Forte  *  oid of initiator
573fcf3ce44SJohn Forte  *
574fcf3ce44SJohn Forte  * Returns:
575fcf3ce44SJohn Forte  *  zero on success with initiator found
576fcf3ce44SJohn Forte  *  > 0 on success with no initiator found
577fcf3ce44SJohn Forte  *  < 0 on failure
578fcf3ce44SJohn Forte  */
579fcf3ce44SJohn Forte static int
sunInitiatorFind(IMA_OID * oid)580fcf3ce44SJohn Forte sunInitiatorFind(IMA_OID *oid)
581fcf3ce44SJohn Forte {
582f5fc5c04SJack Meng 	IMA_OID_LIST *lhbaList = NULL;
583fcf3ce44SJohn Forte 
584fcf3ce44SJohn Forte 	IMA_STATUS status = IMA_GetLhbaOidList(&lhbaList);
585fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
586fcf3ce44SJohn Forte 		printLibError(status);
587fcf3ce44SJohn Forte 		return (-1);
588fcf3ce44SJohn Forte 	}
589fcf3ce44SJohn Forte 
590f5fc5c04SJack Meng 	if ((lhbaList == NULL) || (lhbaList->oidCount == 0)) {
591f5fc5c04SJack Meng 		printLibError(IMA_ERROR_OBJECT_NOT_FOUND);
592f5fc5c04SJack Meng 		if (lhbaList != NULL)
593f5fc5c04SJack Meng 			(void) IMA_FreeMemory(lhbaList);
594f5fc5c04SJack Meng 		return (-1);
595f5fc5c04SJack Meng 	}
596f5fc5c04SJack Meng 
597fcf3ce44SJohn Forte 	*oid = lhbaList->oids[0];
598f5fc5c04SJack Meng 	(void) IMA_FreeMemory(lhbaList);
599fcf3ce44SJohn Forte 
600fcf3ce44SJohn Forte 	return (0);
601fcf3ce44SJohn Forte }
602fcf3ce44SJohn Forte 
603fcf3ce44SJohn Forte /*
604fcf3ce44SJohn Forte  * input:
605fcf3ce44SJohn Forte  *  wcInput - wide character string containing discovery address
606fcf3ce44SJohn Forte  * output:
607fcf3ce44SJohn Forte  *  address - IMA_TARGET_ADDRESS structure containing valid
608fcf3ce44SJohn Forte  *	discovery address
609fcf3ce44SJohn Forte  * returns:
610fcf3ce44SJohn Forte  *  zero on success
611fcf3ce44SJohn Forte  *  non-zero on failure
612fcf3ce44SJohn Forte  */
613fcf3ce44SJohn Forte 
614fcf3ce44SJohn Forte static int
getTargetAddress(int addrType,char * ipStr,IMA_TARGET_ADDRESS * address)615fcf3ce44SJohn Forte getTargetAddress(int addrType, char *ipStr, IMA_TARGET_ADDRESS *address)
616fcf3ce44SJohn Forte {
617fcf3ce44SJohn Forte 	char cCol = ':';
618fcf3ce44SJohn Forte 	char cBracketL = '['; /* Open Bracket '[' */
619fcf3ce44SJohn Forte 	char cBracketR = ']'; /* Close Bracket ']' */
620fcf3ce44SJohn Forte 	char *colPos;
621fcf3ce44SJohn Forte 	char *startPos;
622fcf3ce44SJohn Forte 	unsigned long inputPort;
623fcf3ce44SJohn Forte 	int addressType = AF_INET;
624fcf3ce44SJohn Forte 	char *tmpStrPtr, tmpStr[SUN_IMA_IP_ADDRESS_PORT_LEN];
625fcf3ce44SJohn Forte 	int rval;
626fcf3ce44SJohn Forte 
627fcf3ce44SJohn Forte 	/* Check if this is a ipv6 address */
628fcf3ce44SJohn Forte 	if (ipStr[0] == cBracketL) {
629fcf3ce44SJohn Forte 		addressType = AF_INET6;
630fcf3ce44SJohn Forte 		startPos = strchr(ipStr, cBracketR);
631fcf3ce44SJohn Forte 		if (!startPos) {
632fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s: ']' %s\n",
633fcf3ce44SJohn Forte 			    cmdName, ipStr, gettext("missing"));
634fcf3ce44SJohn Forte 			return (1);
635fcf3ce44SJohn Forte 		}
636fcf3ce44SJohn Forte 		(void) strlcpy(tmpStr, ipStr+1, startPos-ipStr);
637fcf3ce44SJohn Forte 		address->hostnameIpAddress.id.ipAddress.ipv4Address = IMA_FALSE;
638fcf3ce44SJohn Forte 		tmpStrPtr = tmpStr;
639fcf3ce44SJohn Forte 	} else {
640fcf3ce44SJohn Forte 		/* set start position to beginning of input object */
641fcf3ce44SJohn Forte 		addressType = AF_INET;
642fcf3ce44SJohn Forte 		startPos = ipStr;
643fcf3ce44SJohn Forte 		address->hostnameIpAddress.id.ipAddress.ipv4Address = IMA_TRUE;
644fcf3ce44SJohn Forte 		tmpStrPtr = ipStr;
645fcf3ce44SJohn Forte 	}
646fcf3ce44SJohn Forte 	/* wcschr for ':'. If not there, use default port */
647fcf3ce44SJohn Forte 	colPos = strchr(startPos, cCol);
648fcf3ce44SJohn Forte 
649fcf3ce44SJohn Forte 	if (!colPos) {
650fcf3ce44SJohn Forte 		if (addrType == DISCOVERY_ADDRESS) {
651fcf3ce44SJohn Forte 			inputPort = DEFAULT_ISCSI_PORT;
652fcf3ce44SJohn Forte 		} else if (addrType == ISNS_SERVER_ADDRESS) {
653fcf3ce44SJohn Forte 			inputPort = ISNS_DEFAULT_SERVER_PORT;
654fcf3ce44SJohn Forte 		} else {
65533c72b75SToomas Soome 			*colPos = '\0';
656fcf3ce44SJohn Forte 		}
657fcf3ce44SJohn Forte 	} else {
65833c72b75SToomas Soome 		*colPos = '\0';
659fcf3ce44SJohn Forte 	}
660fcf3ce44SJohn Forte 
661fcf3ce44SJohn Forte 	rval = inet_pton(addressType, tmpStrPtr,
662fcf3ce44SJohn Forte 	    address->hostnameIpAddress.id.ipAddress.ipAddress);
663fcf3ce44SJohn Forte 	/* inet_pton returns 1 on success */
664fcf3ce44SJohn Forte 	if (rval != 1) {
665fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s: %s\n", cmdName, ipStr,
666fcf3ce44SJohn Forte 		    gettext("invalid IP address"));
667fcf3ce44SJohn Forte 		return (1);
668fcf3ce44SJohn Forte 	}
669fcf3ce44SJohn Forte 
670fcf3ce44SJohn Forte 
671fcf3ce44SJohn Forte 	if (colPos) {
672fcf3ce44SJohn Forte 		char *errchr;
673fcf3ce44SJohn Forte 
674fcf3ce44SJohn Forte 		colPos++;
67533c72b75SToomas Soome 		if (*colPos == '\0') {
676fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s: %s\n",
677fcf3ce44SJohn Forte 			    cmdName, ipStr,
678fcf3ce44SJohn Forte 			    gettext("port number missing"));
679fcf3ce44SJohn Forte 			return (1);
680fcf3ce44SJohn Forte 		}
681fcf3ce44SJohn Forte 
682fcf3ce44SJohn Forte 		/*
683fcf3ce44SJohn Forte 		 * convert port string to unsigned value
684fcf3ce44SJohn Forte 		 * Note:  Don't remove errno = 0 as you may get false failures.
685fcf3ce44SJohn Forte 		 */
686fcf3ce44SJohn Forte 		errno = 0;
687fcf3ce44SJohn Forte 		inputPort = strtol(colPos, &errchr, 10);
688fcf3ce44SJohn Forte 		if (errno != 0 || inputPort == 0 && errchr != NULL) {
689fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s:%s %s\n",
690fcf3ce44SJohn Forte 			    cmdName, ipStr, colPos,
691fcf3ce44SJohn Forte 			    gettext("port number invalid"));
692fcf3ce44SJohn Forte 			return (1);
693fcf3ce44SJohn Forte 		}
694fcf3ce44SJohn Forte 		/* make sure it's in the range */
695fcf3ce44SJohn Forte 		if (inputPort > USHRT_MAX) {
696fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s: %s\n",
697fcf3ce44SJohn Forte 			    cmdName, ipStr,
698fcf3ce44SJohn Forte 			    gettext("port number out of range"));
699fcf3ce44SJohn Forte 			return (1);
700fcf3ce44SJohn Forte 		}
701fcf3ce44SJohn Forte 	}
702fcf3ce44SJohn Forte 	address->portNumber  = inputPort;
703fcf3ce44SJohn Forte 
704fcf3ce44SJohn Forte 	return (0);
705fcf3ce44SJohn Forte }
706fcf3ce44SJohn Forte 
707fcf3ce44SJohn Forte /*
708fcf3ce44SJohn Forte  * Print results of send targets command
709fcf3ce44SJohn Forte  */
710fcf3ce44SJohn Forte static void
printSendTargets(SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES * pList)711fcf3ce44SJohn Forte printSendTargets(SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES *pList)
712fcf3ce44SJohn Forte {
713fcf3ce44SJohn Forte 	char outBuf[INET6_ADDRSTRLEN];
714fcf3ce44SJohn Forte 	int inetSize;
715fcf3ce44SJohn Forte 	int af;
716fcf3ce44SJohn Forte 	int i;
717fcf3ce44SJohn Forte 
718fcf3ce44SJohn Forte 	for (i = 0; i < pList->keyCount; i++) {
719fcf3ce44SJohn Forte 		if (pList->keys[i].address.ipAddress.ipv4Address == IMA_TRUE) {
720fcf3ce44SJohn Forte 			af = AF_INET;
721fcf3ce44SJohn Forte 			inetSize = INET_ADDRSTRLEN;
722fcf3ce44SJohn Forte 		} else {
723fcf3ce44SJohn Forte 			af = AF_INET6;
724fcf3ce44SJohn Forte 			inetSize = INET6_ADDRSTRLEN;
725fcf3ce44SJohn Forte 		}
726fcf3ce44SJohn Forte 		(void) fprintf(stdout, gettext("\tTarget name: %ws\n"),
727fcf3ce44SJohn Forte 		    pList->keys[i].name);
728fcf3ce44SJohn Forte 		(void) fprintf(stdout, "\t\t%s: %15s:%d", "Target address",
729fcf3ce44SJohn Forte 		    inet_ntop(af, &(pList->keys[i].address.ipAddress.ipAddress),
730fcf3ce44SJohn Forte 		    outBuf, inetSize), pList->keys[i].address.portNumber);
731fcf3ce44SJohn Forte 		(void) fprintf(stdout, ", %d", pList->keys[i].tpgt);
732fcf3ce44SJohn Forte 		(void) fprintf(stdout, "\n");
733fcf3ce44SJohn Forte 	}
734fcf3ce44SJohn Forte }
735fcf3ce44SJohn Forte 
736fcf3ce44SJohn Forte 
737fcf3ce44SJohn Forte /*
738fcf3ce44SJohn Forte  * Print all login parameters
739fcf3ce44SJohn Forte  */
740fcf3ce44SJohn Forte static int
printLoginParameters(char * prefix,IMA_OID oid,int printOption)741fcf3ce44SJohn Forte printLoginParameters(char *prefix, IMA_OID oid, int printOption)
742fcf3ce44SJohn Forte {
743fcf3ce44SJohn Forte 	IMA_STATUS status;
744fcf3ce44SJohn Forte 	IMA_BOOL_VALUE propBool;
745fcf3ce44SJohn Forte 	IMA_MIN_MAX_VALUE propMinMax;
746fcf3ce44SJohn Forte 	char longString[MAX_LONG_CHAR_LEN + 1];
747fcf3ce44SJohn Forte 	SUN_IMA_CONN_PROPERTIES	*connProps = NULL;
748fcf3ce44SJohn Forte 	IMA_OID_LIST *pConnList;
749fcf3ce44SJohn Forte 
750fcf3ce44SJohn Forte 	(void) memset(longString, 0, sizeof (longString));
751fcf3ce44SJohn Forte 
752fcf3ce44SJohn Forte 	switch (printOption) {
753fcf3ce44SJohn Forte 		case PRINT_CONFIGURED_PARAMS:
754fcf3ce44SJohn Forte 			(void) fprintf(stdout, "%s%s:\n",
755fcf3ce44SJohn Forte 			    prefix,
756fcf3ce44SJohn Forte 			    gettext("Login Parameters (Default/Configured)"));
757fcf3ce44SJohn Forte 			break;
758fcf3ce44SJohn Forte 		case PRINT_NEGOTIATED_PARAMS:
759fcf3ce44SJohn Forte 			(void) fprintf(stdout, "%s%s:\n",
760fcf3ce44SJohn Forte 			    prefix,
761fcf3ce44SJohn Forte 			    gettext("Login Parameters (Negotiated)"));
762fcf3ce44SJohn Forte 			status = SUN_IMA_GetConnOidList(
763fcf3ce44SJohn Forte 			    &oid,
764fcf3ce44SJohn Forte 			    &pConnList);
765fcf3ce44SJohn Forte 
766fcf3ce44SJohn Forte 			if (!IMA_SUCCESS(status)) {
767fcf3ce44SJohn Forte 				printLibError(status);
768fcf3ce44SJohn Forte 				return (1);
769fcf3ce44SJohn Forte 			}
770fcf3ce44SJohn Forte 
771fcf3ce44SJohn Forte 			status = SUN_IMA_GetConnProperties(&pConnList->oids[0],
772fcf3ce44SJohn Forte 			    &connProps);
773fcf3ce44SJohn Forte 			propBool.currentValueValid = connProps->valuesValid;
774fcf3ce44SJohn Forte 			propMinMax.currentValueValid = connProps->valuesValid;
775fcf3ce44SJohn Forte 			break;
776fcf3ce44SJohn Forte 		default:
777fcf3ce44SJohn Forte 			return (1);
778fcf3ce44SJohn Forte 	}
779fcf3ce44SJohn Forte 
780fcf3ce44SJohn Forte 	if (printOption == PRINT_NEGOTIATED_PARAMS) {
781fcf3ce44SJohn Forte 		propBool.currentValue = connProps->dataSequenceInOrder;
782fcf3ce44SJohn Forte 	} else {
783fcf3ce44SJohn Forte 		status = IMA_GetDataSequenceInOrderProperties(oid, &propBool);
784fcf3ce44SJohn Forte 	}
785fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
786fcf3ce44SJohn Forte 		printLibError(status);
787fcf3ce44SJohn Forte 		(void) IMA_FreeMemory(connProps);
788fcf3ce44SJohn Forte 		return (1);
789fcf3ce44SJohn Forte 	}
790fcf3ce44SJohn Forte 	(void) fprintf(stdout, "%s\t%s: ", prefix,
791fcf3ce44SJohn Forte 	    gettext("Data Sequence In Order"));
792fcf3ce44SJohn Forte 	IMABOOLPRINT(propBool, printOption);
793fcf3ce44SJohn Forte 
794fcf3ce44SJohn Forte 
795fcf3ce44SJohn Forte 	if (printOption == PRINT_NEGOTIATED_PARAMS) {
796fcf3ce44SJohn Forte 		propBool.currentValue = connProps->dataPduInOrder;
797fcf3ce44SJohn Forte 	} else {
798fcf3ce44SJohn Forte 		status = IMA_GetDataPduInOrderProperties(oid, &propBool);
799fcf3ce44SJohn Forte 	}
800fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
801fcf3ce44SJohn Forte 		printLibError(status);
802fcf3ce44SJohn Forte 		(void) IMA_FreeMemory(connProps);
803fcf3ce44SJohn Forte 		return (1);
804fcf3ce44SJohn Forte 	}
805fcf3ce44SJohn Forte 	(void) fprintf(stdout, "%s\t%s: ", prefix,
806fcf3ce44SJohn Forte 	    gettext("Data PDU In Order"));
807fcf3ce44SJohn Forte 	IMABOOLPRINT(propBool, printOption);
808fcf3ce44SJohn Forte 
809fcf3ce44SJohn Forte 
810fcf3ce44SJohn Forte 	if (printOption == PRINT_NEGOTIATED_PARAMS) {
811fcf3ce44SJohn Forte 		propMinMax.currentValue = connProps->defaultTime2Retain;
812fcf3ce44SJohn Forte 	} else {
813fcf3ce44SJohn Forte 		status = IMA_GetDefaultTime2RetainProperties(oid, &propMinMax);
814fcf3ce44SJohn Forte 	}
815fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
816fcf3ce44SJohn Forte 		printLibError(status);
817fcf3ce44SJohn Forte 		(void) IMA_FreeMemory(connProps);
818fcf3ce44SJohn Forte 		return (1);
819fcf3ce44SJohn Forte 	}
820fcf3ce44SJohn Forte 	(void) fprintf(stdout, "%s\t%s: ", prefix,
821fcf3ce44SJohn Forte 	    gettext("Default Time To Retain"));
822fcf3ce44SJohn Forte 	IMAMINMAXPRINT(propMinMax, printOption);
823fcf3ce44SJohn Forte 
824fcf3ce44SJohn Forte 
825fcf3ce44SJohn Forte 	if (printOption == PRINT_NEGOTIATED_PARAMS) {
826fcf3ce44SJohn Forte 		propMinMax.currentValue = connProps->defaultTime2Wait;
827fcf3ce44SJohn Forte 	} else {
828fcf3ce44SJohn Forte 		status = IMA_GetDefaultTime2WaitProperties(oid, &propMinMax);
829fcf3ce44SJohn Forte 	}
830fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
831fcf3ce44SJohn Forte 		printLibError(status);
832fcf3ce44SJohn Forte 		(void) IMA_FreeMemory(connProps);
833fcf3ce44SJohn Forte 		return (1);
834fcf3ce44SJohn Forte 	}
835fcf3ce44SJohn Forte 	(void) fprintf(stdout, "%s\t%s: ", prefix,
836fcf3ce44SJohn Forte 	    gettext("Default Time To Wait"));
837fcf3ce44SJohn Forte 	IMAMINMAXPRINT(propMinMax, printOption);
838fcf3ce44SJohn Forte 
839fcf3ce44SJohn Forte 
840fcf3ce44SJohn Forte 	if (printOption == PRINT_NEGOTIATED_PARAMS) {
841fcf3ce44SJohn Forte 		propMinMax.currentValue = connProps->errorRecoveryLevel;
842fcf3ce44SJohn Forte 	} else {
843fcf3ce44SJohn Forte 		status = IMA_GetErrorRecoveryLevelProperties(oid, &propMinMax);
844fcf3ce44SJohn Forte 	}
845fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
846fcf3ce44SJohn Forte 		printLibError(status);
847fcf3ce44SJohn Forte 		(void) IMA_FreeMemory(connProps);
848fcf3ce44SJohn Forte 		return (1);
849fcf3ce44SJohn Forte 	}
850fcf3ce44SJohn Forte 	(void) fprintf(stdout, "%s\t%s: ", prefix,
851fcf3ce44SJohn Forte 	    gettext("Error Recovery Level"));
852fcf3ce44SJohn Forte 	IMAMINMAXPRINT(propMinMax, printOption);
853fcf3ce44SJohn Forte 
854fcf3ce44SJohn Forte 
855fcf3ce44SJohn Forte 	if (printOption == PRINT_NEGOTIATED_PARAMS) {
856fcf3ce44SJohn Forte 		propMinMax.currentValue = connProps->firstBurstLength;
857fcf3ce44SJohn Forte 	} else {
858fcf3ce44SJohn Forte 		status = IMA_GetFirstBurstLengthProperties(oid,
859fcf3ce44SJohn Forte 		    &propMinMax);
860fcf3ce44SJohn Forte 	}
861fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
862fcf3ce44SJohn Forte 		printLibError(status);
863fcf3ce44SJohn Forte 		(void) IMA_FreeMemory(connProps);
864fcf3ce44SJohn Forte 		return (1);
865fcf3ce44SJohn Forte 	}
866fcf3ce44SJohn Forte 	(void) fprintf(stdout, "%s\t%s: ",
867fcf3ce44SJohn Forte 	    prefix, gettext("First Burst Length"));
868fcf3ce44SJohn Forte 	IMAMINMAXPRINT(propMinMax, printOption);
869fcf3ce44SJohn Forte 
870fcf3ce44SJohn Forte 
871fcf3ce44SJohn Forte 	if (printOption == PRINT_NEGOTIATED_PARAMS) {
872fcf3ce44SJohn Forte 		propBool.currentValue = connProps->immediateData;
873fcf3ce44SJohn Forte 	} else {
874fcf3ce44SJohn Forte 		status = IMA_GetImmediateDataProperties(oid, &propBool);
875fcf3ce44SJohn Forte 	}
876fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
877fcf3ce44SJohn Forte 		printLibError(status);
878fcf3ce44SJohn Forte 		(void) IMA_FreeMemory(connProps);
879fcf3ce44SJohn Forte 		return (1);
880fcf3ce44SJohn Forte 	}
881fcf3ce44SJohn Forte 	(void) fprintf(stdout, "%s\t%s: ", prefix, gettext("Immediate Data"));
882fcf3ce44SJohn Forte 	IMABOOLPRINT(propBool, printOption);
883fcf3ce44SJohn Forte 
884fcf3ce44SJohn Forte 
885fcf3ce44SJohn Forte 	if (printOption == PRINT_NEGOTIATED_PARAMS) {
886fcf3ce44SJohn Forte 		propBool.currentValue = connProps->initialR2T;
887fcf3ce44SJohn Forte 	} else {
888fcf3ce44SJohn Forte 		status = IMA_GetInitialR2TProperties(oid, &propBool);
889fcf3ce44SJohn Forte 	}
890fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
891fcf3ce44SJohn Forte 		printLibError(status);
892fcf3ce44SJohn Forte 		(void) IMA_FreeMemory(connProps);
893fcf3ce44SJohn Forte 		return (1);
894fcf3ce44SJohn Forte 	}
895fcf3ce44SJohn Forte 	(void) fprintf(stdout, "%s\t%s: ", prefix,
896fcf3ce44SJohn Forte 	    gettext("Initial Ready To Transfer (R2T)"));
897fcf3ce44SJohn Forte 	IMABOOLPRINT(propBool, printOption);
898fcf3ce44SJohn Forte 
899fcf3ce44SJohn Forte 
900fcf3ce44SJohn Forte 	if (printOption == PRINT_NEGOTIATED_PARAMS) {
901fcf3ce44SJohn Forte 		propMinMax.currentValue = connProps->maxBurstLength;
902fcf3ce44SJohn Forte 	} else {
903fcf3ce44SJohn Forte 		status = IMA_GetMaxBurstLengthProperties(oid, &propMinMax);
904fcf3ce44SJohn Forte 	}
905fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
906fcf3ce44SJohn Forte 		printLibError(status);
907fcf3ce44SJohn Forte 		(void) IMA_FreeMemory(connProps);
908fcf3ce44SJohn Forte 		return (1);
909fcf3ce44SJohn Forte 	}
910fcf3ce44SJohn Forte 	(void) fprintf(stdout, "%s\t%s: ", prefix, gettext("Max Burst Length"));
911fcf3ce44SJohn Forte 	IMAMINMAXPRINT(propMinMax, printOption);
912fcf3ce44SJohn Forte 
913fcf3ce44SJohn Forte 
914fcf3ce44SJohn Forte 	if (printOption == PRINT_NEGOTIATED_PARAMS) {
915fcf3ce44SJohn Forte 		propMinMax.currentValue = connProps->maxOutstandingR2T;
916fcf3ce44SJohn Forte 	} else {
917fcf3ce44SJohn Forte 		status = IMA_GetMaxOutstandingR2TProperties(oid, &propMinMax);
918fcf3ce44SJohn Forte 	}
919fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
920fcf3ce44SJohn Forte 		printLibError(status);
921fcf3ce44SJohn Forte 		(void) IMA_FreeMemory(connProps);
922fcf3ce44SJohn Forte 		return (1);
923fcf3ce44SJohn Forte 	}
924fcf3ce44SJohn Forte 	(void) fprintf(stdout, "%s\t%s: ", prefix,
925fcf3ce44SJohn Forte 	    gettext("Max Outstanding R2T"));
926fcf3ce44SJohn Forte 	IMAMINMAXPRINT(propMinMax, printOption);
927fcf3ce44SJohn Forte 
928fcf3ce44SJohn Forte 
929fcf3ce44SJohn Forte 	if (printOption == PRINT_NEGOTIATED_PARAMS) {
930fcf3ce44SJohn Forte 		propMinMax.currentValue = connProps->maxRecvDataSegmentLength;
931fcf3ce44SJohn Forte 	} else {
932fcf3ce44SJohn Forte 		status = IMA_GetMaxRecvDataSegmentLengthProperties(oid,
933fcf3ce44SJohn Forte 		    &propMinMax);
934fcf3ce44SJohn Forte 	}
935fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
936fcf3ce44SJohn Forte 		printLibError(status);
937fcf3ce44SJohn Forte 		(void) IMA_FreeMemory(connProps);
938fcf3ce44SJohn Forte 		return (1);
939fcf3ce44SJohn Forte 	}
940fcf3ce44SJohn Forte 	(void) fprintf(stdout, "%s\t%s: ", prefix,
941fcf3ce44SJohn Forte 	    gettext("Max Receive Data Segment Length"));
942fcf3ce44SJohn Forte 	IMAMINMAXPRINT(propMinMax, printOption);
943fcf3ce44SJohn Forte 
944fcf3ce44SJohn Forte 
945fcf3ce44SJohn Forte 	if (printOption == PRINT_NEGOTIATED_PARAMS) {
946fcf3ce44SJohn Forte 		propMinMax.currentValue = connProps->maxConnections;
947fcf3ce44SJohn Forte 	} else {
948fcf3ce44SJohn Forte 		status = IMA_GetMaxConnectionsProperties(oid, &propMinMax);
949fcf3ce44SJohn Forte 	}
950fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
951fcf3ce44SJohn Forte 		printLibError(status);
952fcf3ce44SJohn Forte 		(void) IMA_FreeMemory(connProps);
953fcf3ce44SJohn Forte 		return (1);
954fcf3ce44SJohn Forte 	}
955fcf3ce44SJohn Forte 	(void) fprintf(stdout, "%s\t%s: ", prefix, gettext("Max Connections"));
956fcf3ce44SJohn Forte 	IMAMINMAXPRINT(propMinMax, printOption);
957fcf3ce44SJohn Forte 
958fcf3ce44SJohn Forte 	(void) IMA_FreeMemory(connProps);
959fcf3ce44SJohn Forte 	return (0);
960fcf3ce44SJohn Forte }
961fcf3ce44SJohn Forte 
962fcf3ce44SJohn Forte /*
963fcf3ce44SJohn Forte  * Print discovery information.
964fcf3ce44SJohn Forte  */
965fcf3ce44SJohn Forte static void
printDiscoveryMethod(char * prefix,IMA_UINT32 discoveryMethodFlags)966fcf3ce44SJohn Forte printDiscoveryMethod(char *prefix, IMA_UINT32 discoveryMethodFlags)
967fcf3ce44SJohn Forte {
968fcf3ce44SJohn Forte 	(void) fprintf(stdout, "%s%s: ", prefix, gettext("Discovery Method"));
969fcf3ce44SJohn Forte 	if (discoveryMethodFlags == IMA_TARGET_DISCOVERY_METHOD_UNKNOWN) {
970fcf3ce44SJohn Forte 		(void) fprintf(stdout, "%s\n", gettext("NA"));
971fcf3ce44SJohn Forte 	} else {
972fcf3ce44SJohn Forte 		if (!((discoveryMethodFlags &
973fcf3ce44SJohn Forte 		    IMA_TARGET_DISCOVERY_METHOD_STATIC) ^
974fcf3ce44SJohn Forte 		    IMA_TARGET_DISCOVERY_METHOD_STATIC)) {
975fcf3ce44SJohn Forte 			(void) fprintf(stdout, "%s ", gettext("Static"));
976fcf3ce44SJohn Forte 		}
977fcf3ce44SJohn Forte 		if (!((discoveryMethodFlags &
978fcf3ce44SJohn Forte 		    IMA_TARGET_DISCOVERY_METHOD_SENDTARGETS) ^
979fcf3ce44SJohn Forte 		    IMA_TARGET_DISCOVERY_METHOD_SENDTARGETS)) {
980fcf3ce44SJohn Forte 			(void) fprintf(stdout, "%s ", gettext("SendTargets"));
981fcf3ce44SJohn Forte 		}
982fcf3ce44SJohn Forte 		if (!((discoveryMethodFlags &
983fcf3ce44SJohn Forte 		    IMA_TARGET_DISCOVERY_METHOD_ISNS) ^
984fcf3ce44SJohn Forte 		    IMA_TARGET_DISCOVERY_METHOD_ISNS)) {
985fcf3ce44SJohn Forte 			(void) fprintf(stdout, "%s ", gettext("iSNS"));
986fcf3ce44SJohn Forte 		}
987fcf3ce44SJohn Forte 		(void) fprintf(stdout, "\n");
988fcf3ce44SJohn Forte 	}
989fcf3ce44SJohn Forte }
990fcf3ce44SJohn Forte 
991fcf3ce44SJohn Forte /*
992fcf3ce44SJohn Forte  * printConnectionList - Prints the conection list provided
993fcf3ce44SJohn Forte  */
994fcf3ce44SJohn Forte static void
printConnectionList(char * prefix,IMA_OID_LIST * pConnList)995fcf3ce44SJohn Forte printConnectionList(char *prefix, IMA_OID_LIST *pConnList)
996fcf3ce44SJohn Forte {
997fcf3ce44SJohn Forte 	IMA_STATUS		imaStatus;
998fcf3ce44SJohn Forte 	int			i;
999fcf3ce44SJohn Forte 	SUN_IMA_CONN_PROPERTIES	*connProps;
1000fcf3ce44SJohn Forte 	union {
1001fcf3ce44SJohn Forte 		char	ipv4[INET_ADDRSTRLEN+1];
1002fcf3ce44SJohn Forte 		char	ipv6[INET6_ADDRSTRLEN+1];
1003fcf3ce44SJohn Forte 	} tmp;
1004fcf3ce44SJohn Forte 
1005fcf3ce44SJohn Forte 	for (i = 0; i < pConnList->oidCount; i++) {
1006fcf3ce44SJohn Forte 		imaStatus = SUN_IMA_GetConnProperties(&pConnList->oids[i],
1007fcf3ce44SJohn Forte 		    &connProps);
1008fcf3ce44SJohn Forte 
1009fcf3ce44SJohn Forte 		if (imaStatus != IMA_STATUS_SUCCESS) {
1010fcf3ce44SJohn Forte 			continue;
1011fcf3ce44SJohn Forte 		}
1012fcf3ce44SJohn Forte 
1013fcf3ce44SJohn Forte 		(void) fprintf(stdout, "%sCID: %d\n", prefix,
1014fcf3ce44SJohn Forte 		    connProps->connectionID);
1015fcf3ce44SJohn Forte 
1016fcf3ce44SJohn Forte 		(void) memset(&tmp, 0, sizeof (tmp));
1017fcf3ce44SJohn Forte 		if (connProps->local.ipAddress.ipv4Address == IMA_TRUE) {
1018fcf3ce44SJohn Forte 			if (inet_ntop(AF_INET,
1019fcf3ce44SJohn Forte 			    &connProps->local.ipAddress.ipAddress[0],
1020fcf3ce44SJohn Forte 			    &tmp.ipv4[0],
1021fcf3ce44SJohn Forte 			    INET_ADDRSTRLEN)) {
1022fcf3ce44SJohn Forte 				(void) fprintf(stdout,
1023fcf3ce44SJohn Forte 				    "%s  %s: %s:%u\n",
1024fcf3ce44SJohn Forte 				    prefix,
1025fcf3ce44SJohn Forte 				    gettext("IP address (Local)"),
1026fcf3ce44SJohn Forte 				    &tmp.ipv4[0],
1027fcf3ce44SJohn Forte 				    ntohs(connProps->local.portNumber));
1028fcf3ce44SJohn Forte 			}
1029fcf3ce44SJohn Forte 		} else {
1030fcf3ce44SJohn Forte 			if (inet_ntop(AF_INET6,
1031fcf3ce44SJohn Forte 			    &connProps->local.ipAddress.ipAddress[0],
1032fcf3ce44SJohn Forte 			    &tmp.ipv6[0],
1033fcf3ce44SJohn Forte 			    INET6_ADDRSTRLEN)) {
1034fcf3ce44SJohn Forte 				(void) fprintf(stdout,
1035fcf3ce44SJohn Forte 				    "%s  %s: [%s]:%u\n",
1036fcf3ce44SJohn Forte 				    prefix,
1037fcf3ce44SJohn Forte 				    gettext("IP address (Local)"),
1038fcf3ce44SJohn Forte 				    &tmp.ipv6[0],
1039fcf3ce44SJohn Forte 				    ntohs(connProps->local.portNumber));
1040fcf3ce44SJohn Forte 			}
1041fcf3ce44SJohn Forte 		}
1042fcf3ce44SJohn Forte 		if (connProps->peer.ipAddress.ipv4Address == IMA_TRUE) {
1043fcf3ce44SJohn Forte 			if (inet_ntop(AF_INET,
1044fcf3ce44SJohn Forte 			    &connProps->peer.ipAddress.ipAddress[0],
1045fcf3ce44SJohn Forte 			    &tmp.ipv4[0],
1046fcf3ce44SJohn Forte 			    INET_ADDRSTRLEN)) {
1047fcf3ce44SJohn Forte 				(void) fprintf(stdout,
1048fcf3ce44SJohn Forte 				    "%s  %s: %s:%u\n",
1049fcf3ce44SJohn Forte 				    prefix,
1050fcf3ce44SJohn Forte 				    gettext("IP address (Peer)"),
1051fcf3ce44SJohn Forte 				    &tmp.ipv4[0],
1052fcf3ce44SJohn Forte 				    ntohs(connProps->peer.portNumber));
1053fcf3ce44SJohn Forte 			}
1054fcf3ce44SJohn Forte 		} else {
1055fcf3ce44SJohn Forte 			if (inet_ntop(AF_INET6,
1056fcf3ce44SJohn Forte 			    &connProps->peer.ipAddress.ipAddress[0],
1057fcf3ce44SJohn Forte 			    &tmp.ipv6[0],
1058fcf3ce44SJohn Forte 			    INET6_ADDRSTRLEN)) {
1059fcf3ce44SJohn Forte 				(void) fprintf(stdout,
1060fcf3ce44SJohn Forte 				    "%s  %s: [%s]:%u\n",
1061fcf3ce44SJohn Forte 				    prefix,
1062fcf3ce44SJohn Forte 				    gettext("IP address (Peer)"),
1063fcf3ce44SJohn Forte 				    &tmp.ipv6[0],
1064fcf3ce44SJohn Forte 				    ntohs(connProps->peer.portNumber));
1065fcf3ce44SJohn Forte 			}
1066fcf3ce44SJohn Forte 		}
1067fcf3ce44SJohn Forte 
1068fcf3ce44SJohn Forte 		(void) IMA_FreeMemory(connProps);
1069fcf3ce44SJohn Forte 	}
1070fcf3ce44SJohn Forte }
1071fcf3ce44SJohn Forte 
1072fcf3ce44SJohn Forte /*
1073fcf3ce44SJohn Forte  * Set login parameters on a target or initiator
1074fcf3ce44SJohn Forte  */
1075fcf3ce44SJohn Forte static int
setLoginParameter(IMA_OID oid,int optval,char * optarg)1076fcf3ce44SJohn Forte setLoginParameter(IMA_OID oid, int optval, char *optarg)
1077fcf3ce44SJohn Forte {
1078fcf3ce44SJohn Forte 	IMA_STATUS status = IMA_STATUS_SUCCESS;
1079fcf3ce44SJohn Forte 	IMA_UINT uintValue;
1080fcf3ce44SJohn Forte 	IMA_BOOL boolValue;
1081fcf3ce44SJohn Forte 	SUN_IMA_DIGEST_ALGORITHM digestAlgList[1];
1082fcf3ce44SJohn Forte 	IMA_MIN_MAX_VALUE propMinMax;
1083fcf3ce44SJohn Forte 	char *endptr;
1084fcf3ce44SJohn Forte 
1085fcf3ce44SJohn Forte 	/*
1086fcf3ce44SJohn Forte 	 * for clarity, there are two switch statements
1087fcf3ce44SJohn Forte 	 * The first loads the variable and the second
1088fcf3ce44SJohn Forte 	 * calls the appropriate API
1089fcf3ce44SJohn Forte 	 */
1090fcf3ce44SJohn Forte 	switch (optval) {
1091fcf3ce44SJohn Forte 		case DATA_SEQ_IN_ORDER:
1092fcf3ce44SJohn Forte 		case IMMEDIATE_DATA:
1093fcf3ce44SJohn Forte 		case INITIAL_R2T:
1094fcf3ce44SJohn Forte 		case DATA_PDU_IN_ORDER:
1095fcf3ce44SJohn Forte 			/* implement 'default'? */
1096fcf3ce44SJohn Forte 			if (strcasecmp(optarg, "yes") == 0) {
1097fcf3ce44SJohn Forte 				boolValue = IMA_TRUE;
1098fcf3ce44SJohn Forte 			} else if (strcasecmp(optarg, "no") == 0) {
1099fcf3ce44SJohn Forte 				boolValue = IMA_FALSE;
1100fcf3ce44SJohn Forte 			} else {
1101fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s - %s\n",
1102fcf3ce44SJohn Forte 				    cmdName,
1103fcf3ce44SJohn Forte 				    gettext("invalid option argument"),
1104fcf3ce44SJohn Forte 				    optarg);
1105fcf3ce44SJohn Forte 				return (1);
1106fcf3ce44SJohn Forte 			}
1107fcf3ce44SJohn Forte 			break;
1108fcf3ce44SJohn Forte 		case DEFAULT_TIME_2_RETAIN:
1109fcf3ce44SJohn Forte 		case DEFAULT_TIME_2_WAIT:
1110fcf3ce44SJohn Forte 			errno = 0;
1111fcf3ce44SJohn Forte 			uintValue = strtoul(optarg, &endptr, 0);
1112fcf3ce44SJohn Forte 			if (*endptr != '\0' || errno != 0) {
1113fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s - %s\n",
1114fcf3ce44SJohn Forte 				    cmdName,
1115fcf3ce44SJohn Forte 				    gettext("invalid option argument"),
1116fcf3ce44SJohn Forte 				    optarg);
1117fcf3ce44SJohn Forte 				return (1);
1118fcf3ce44SJohn Forte 			}
1119fcf3ce44SJohn Forte 			if (uintValue > 3600) {
1120fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n",
1121fcf3ce44SJohn Forte 				    cmdName,
1122fcf3ce44SJohn Forte gettext("value must be between 0 and 3600"));
1123fcf3ce44SJohn Forte 				return (1);
1124fcf3ce44SJohn Forte 			}
1125fcf3ce44SJohn Forte 			break;
1126fcf3ce44SJohn Forte 		case FIRST_BURST_LENGTH:
1127fcf3ce44SJohn Forte 		case MAX_BURST_LENGTH:
1128fcf3ce44SJohn Forte 		case MAX_RECV_DATA_SEG_LEN:
1129fcf3ce44SJohn Forte 			errno = 0;
1130fcf3ce44SJohn Forte 			/* implement 'default'? */
1131fcf3ce44SJohn Forte 			uintValue = strtoul(optarg, &endptr, 0);
1132fcf3ce44SJohn Forte 			if (*endptr != '\0' || errno != 0) {
1133fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s - %s\n",
1134fcf3ce44SJohn Forte 				    cmdName,
1135fcf3ce44SJohn Forte 				    gettext("invalid option argument"),
1136fcf3ce44SJohn Forte 				    optarg);
1137fcf3ce44SJohn Forte 				return (1);
1138fcf3ce44SJohn Forte 			}
1139fcf3ce44SJohn Forte 			if (uintValue < 512 || uintValue > 16777215) {
1140fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n",
1141fcf3ce44SJohn Forte 				    cmdName,
1142fcf3ce44SJohn Forte gettext("value must be between 512 and 16777215"));
1143fcf3ce44SJohn Forte 				return (1);
1144fcf3ce44SJohn Forte 			}
1145fcf3ce44SJohn Forte 			break;
1146fcf3ce44SJohn Forte 		case MAX_OUTSTANDING_R2T:
1147fcf3ce44SJohn Forte 			errno = 0;
1148fcf3ce44SJohn Forte 			uintValue = strtoul(optarg, &endptr, 0);
1149fcf3ce44SJohn Forte 			if (*endptr != '\0' || errno != 0) {
1150fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s - %s\n",
1151fcf3ce44SJohn Forte 				    cmdName,
1152fcf3ce44SJohn Forte 				    gettext("invalid option argument"),
1153fcf3ce44SJohn Forte 				    optarg);
1154fcf3ce44SJohn Forte 				return (1);
1155fcf3ce44SJohn Forte 			}
1156fcf3ce44SJohn Forte 			if (uintValue < 1 || uintValue > 65535) {
1157fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n",
1158fcf3ce44SJohn Forte 				    cmdName,
1159fcf3ce44SJohn Forte gettext("value must be between 1 and 65535"));
1160fcf3ce44SJohn Forte 				return (1);
1161fcf3ce44SJohn Forte 			}
1162fcf3ce44SJohn Forte 			break;
1163fcf3ce44SJohn Forte 		case HEADER_DIGEST:
1164fcf3ce44SJohn Forte 		case DATA_DIGEST:
1165fcf3ce44SJohn Forte 			if (strcasecmp(optarg, "none") == 0) {
1166fcf3ce44SJohn Forte 				digestAlgList[0] = SUN_IMA_DIGEST_NONE;
1167fcf3ce44SJohn Forte 			} else if (strcasecmp(optarg, "CRC32") == 0) {
1168fcf3ce44SJohn Forte 				digestAlgList[0] = SUN_IMA_DIGEST_CRC32;
1169fcf3ce44SJohn Forte 			} else {
1170fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s - %s\n",
1171fcf3ce44SJohn Forte 				    cmdName,
1172fcf3ce44SJohn Forte 				    gettext("invalid option argument"),
1173fcf3ce44SJohn Forte 				    optarg);
1174fcf3ce44SJohn Forte 				return (1);
1175fcf3ce44SJohn Forte 			}
1176fcf3ce44SJohn Forte 			break;
1177fcf3ce44SJohn Forte 		case MAX_CONNECTIONS:
1178fcf3ce44SJohn Forte 			errno = 0;
1179fcf3ce44SJohn Forte 			uintValue = strtoul(optarg, &endptr, 0);
1180fcf3ce44SJohn Forte 			if (*endptr != '\0' || errno != 0) {
1181fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s - %s\n",
1182fcf3ce44SJohn Forte 				    cmdName,
1183fcf3ce44SJohn Forte 				    gettext("invalid option argument"),
1184fcf3ce44SJohn Forte 				    optarg);
1185fcf3ce44SJohn Forte 				return (1);
1186fcf3ce44SJohn Forte 			}
1187fcf3ce44SJohn Forte 			if (uintValue < 1 || uintValue > 256) {
1188fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n",
1189fcf3ce44SJohn Forte 				    cmdName,
1190fcf3ce44SJohn Forte gettext("value must be between 1 and 256"));
1191fcf3ce44SJohn Forte 				return (1);
1192fcf3ce44SJohn Forte 			}
1193fcf3ce44SJohn Forte 			break;
1194fcf3ce44SJohn Forte 		case ERROR_RECOVERY_LEVEL:
1195fcf3ce44SJohn Forte 			errno = 0;
1196fcf3ce44SJohn Forte 			uintValue = strtoul(optarg, &endptr, 0);
1197fcf3ce44SJohn Forte 			if (*endptr != '\0' || errno != 0) {
1198fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s - %s\n",
1199fcf3ce44SJohn Forte 				    cmdName,
1200fcf3ce44SJohn Forte 				    gettext("invalid option argument"),
1201fcf3ce44SJohn Forte 				    optarg);
1202fcf3ce44SJohn Forte 				return (1);
1203fcf3ce44SJohn Forte 			}
1204fcf3ce44SJohn Forte 			if (uintValue > 2) {
1205fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n",
1206fcf3ce44SJohn Forte 				    cmdName,
1207fcf3ce44SJohn Forte gettext("value must be between 0 and 2"));
1208fcf3ce44SJohn Forte 				return (1);
1209fcf3ce44SJohn Forte 			}
1210fcf3ce44SJohn Forte 			break;
1211fcf3ce44SJohn Forte 		default:
1212fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %c: %s\n",
1213fcf3ce44SJohn Forte 			    cmdName, optval, gettext("unknown option"));
1214fcf3ce44SJohn Forte 			return (1);
1215fcf3ce44SJohn Forte 	}
1216fcf3ce44SJohn Forte 
1217fcf3ce44SJohn Forte 	switch (optval) {
1218fcf3ce44SJohn Forte 		case DATA_PDU_IN_ORDER:
1219fcf3ce44SJohn Forte 			status = IMA_SetDataPduInOrder(oid, boolValue);
1220fcf3ce44SJohn Forte 			break;
1221fcf3ce44SJohn Forte 		case DATA_SEQ_IN_ORDER:
1222fcf3ce44SJohn Forte 			status = IMA_SetDataSequenceInOrder(oid, boolValue);
1223fcf3ce44SJohn Forte 			break;
1224fcf3ce44SJohn Forte 		case DEFAULT_TIME_2_RETAIN:
1225fcf3ce44SJohn Forte 			status = IMA_SetDefaultTime2Retain(oid, uintValue);
1226fcf3ce44SJohn Forte 			break;
1227fcf3ce44SJohn Forte 		case DEFAULT_TIME_2_WAIT:
1228fcf3ce44SJohn Forte 			status = IMA_SetDefaultTime2Wait(oid, uintValue);
1229fcf3ce44SJohn Forte 			break;
1230fcf3ce44SJohn Forte 		case FIRST_BURST_LENGTH:
1231fcf3ce44SJohn Forte 			status = IMA_SetFirstBurstLength(oid, uintValue);
1232fcf3ce44SJohn Forte 
1233fcf3ce44SJohn Forte 			/*
1234fcf3ce44SJohn Forte 			 * If this call fails check to see if it's because
1235fcf3ce44SJohn Forte 			 * the requested value is > than maxBurstLength
1236fcf3ce44SJohn Forte 			 */
1237fcf3ce44SJohn Forte 			if (!IMA_SUCCESS(status)) {
1238fcf3ce44SJohn Forte 				status = IMA_GetMaxBurstLengthProperties(oid,
1239fcf3ce44SJohn Forte 				    &propMinMax);
1240fcf3ce44SJohn Forte 				if (!IMA_SUCCESS(status)) {
1241fcf3ce44SJohn Forte 					printLibError(status);
1242fcf3ce44SJohn Forte 					return (1);
1243fcf3ce44SJohn Forte 				}
1244fcf3ce44SJohn Forte 				if (uintValue > propMinMax.currentValue) {
1245fcf3ce44SJohn Forte 					(void) fprintf(stderr,
1246fcf3ce44SJohn Forte 					    "%s: %s\n", cmdName,
1247fcf3ce44SJohn Forte 					    gettext("firstBurstLength must " \
1248fcf3ce44SJohn Forte 					    "be less than or equal to than " \
1249fcf3ce44SJohn Forte 					    "maxBurstLength"));
1250fcf3ce44SJohn Forte 				}
1251fcf3ce44SJohn Forte 				return (1);
1252fcf3ce44SJohn Forte 			}
1253fcf3ce44SJohn Forte 
1254fcf3ce44SJohn Forte 			break;
1255fcf3ce44SJohn Forte 		case IMMEDIATE_DATA:
1256fcf3ce44SJohn Forte 			status = IMA_SetImmediateData(oid, boolValue);
1257fcf3ce44SJohn Forte 			break;
1258fcf3ce44SJohn Forte 		case INITIAL_R2T:
1259fcf3ce44SJohn Forte 			status = IMA_SetInitialR2T(oid, boolValue);
1260fcf3ce44SJohn Forte 			break;
1261fcf3ce44SJohn Forte 		case MAX_BURST_LENGTH:
1262fcf3ce44SJohn Forte 			status = IMA_SetMaxBurstLength(oid, uintValue);
1263fcf3ce44SJohn Forte 			/*
1264fcf3ce44SJohn Forte 			 * If this call fails check to see if it's because
1265fcf3ce44SJohn Forte 			 * the requested value is < than firstBurstLength
1266fcf3ce44SJohn Forte 			 */
1267fcf3ce44SJohn Forte 			if (!IMA_SUCCESS(status)) {
1268fcf3ce44SJohn Forte 				status = IMA_GetFirstBurstLengthProperties(oid,
1269fcf3ce44SJohn Forte 				    &propMinMax);
1270fcf3ce44SJohn Forte 				if (!IMA_SUCCESS(status)) {
1271fcf3ce44SJohn Forte 					printLibError(status);
1272fcf3ce44SJohn Forte 					return (1);
1273fcf3ce44SJohn Forte 				}
1274fcf3ce44SJohn Forte 				if (uintValue < propMinMax.currentValue) {
1275fcf3ce44SJohn Forte 					(void) fprintf(stderr, "%s: %s\n",
1276fcf3ce44SJohn Forte 					    cmdName,
1277fcf3ce44SJohn Forte 					    gettext("maxBurstLength must be " \
1278fcf3ce44SJohn Forte 					    "greater than or equal to " \
1279fcf3ce44SJohn Forte 					    "firstBurstLength"));
1280fcf3ce44SJohn Forte 				}
1281fcf3ce44SJohn Forte 				return (1);
1282fcf3ce44SJohn Forte 			}
1283fcf3ce44SJohn Forte 			break;
1284fcf3ce44SJohn Forte 
1285fcf3ce44SJohn Forte 		case MAX_OUTSTANDING_R2T:
1286fcf3ce44SJohn Forte 			status = IMA_SetMaxOutstandingR2T(oid, uintValue);
1287fcf3ce44SJohn Forte 			break;
1288fcf3ce44SJohn Forte 		case MAX_RECV_DATA_SEG_LEN:
1289fcf3ce44SJohn Forte 			status = IMA_SetMaxRecvDataSegmentLength(oid,
1290fcf3ce44SJohn Forte 			    uintValue);
1291fcf3ce44SJohn Forte 			break;
1292fcf3ce44SJohn Forte 		case HEADER_DIGEST:
1293fcf3ce44SJohn Forte 			status = SUN_IMA_SetHeaderDigest(oid, 1,
1294fcf3ce44SJohn Forte 			    &digestAlgList[0]);
1295fcf3ce44SJohn Forte 			break;
1296fcf3ce44SJohn Forte 		case DATA_DIGEST:
1297fcf3ce44SJohn Forte 			status = SUN_IMA_SetDataDigest(oid, 1,
1298fcf3ce44SJohn Forte 			    &digestAlgList[0]);
1299fcf3ce44SJohn Forte 			break;
1300fcf3ce44SJohn Forte 		case MAX_CONNECTIONS:
1301fcf3ce44SJohn Forte 			status = IMA_SetMaxConnections(oid, uintValue);
1302fcf3ce44SJohn Forte 			break;
1303fcf3ce44SJohn Forte 		case ERROR_RECOVERY_LEVEL:
1304fcf3ce44SJohn Forte 			status = IMA_SetErrorRecoveryLevel(oid, uintValue);
1305fcf3ce44SJohn Forte 			break;
1306fcf3ce44SJohn Forte 	}
1307fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
1308fcf3ce44SJohn Forte 		printLibError(status);
1309fcf3ce44SJohn Forte 		return (1);
1310fcf3ce44SJohn Forte 	}
1311fcf3ce44SJohn Forte 	return (0);
1312fcf3ce44SJohn Forte }
1313fcf3ce44SJohn Forte 
1314fcf3ce44SJohn Forte static void
printDigestAlgorithm(SUN_IMA_DIGEST_ALGORITHM_VALUE * digestAlgorithms,int printOption)1315fcf3ce44SJohn Forte printDigestAlgorithm(SUN_IMA_DIGEST_ALGORITHM_VALUE *digestAlgorithms,
1316fcf3ce44SJohn Forte     int printOption)
1317fcf3ce44SJohn Forte {
1318fcf3ce44SJohn Forte 	int i;
1319fcf3ce44SJohn Forte 
1320fcf3ce44SJohn Forte 	if (printOption == PRINT_CONFIGURED_PARAMS) {
1321fcf3ce44SJohn Forte 		for (i = 0; i < digestAlgorithms->defaultAlgorithmCount; i++) {
1322fcf3ce44SJohn Forte 			if (i > 0) {
1323fcf3ce44SJohn Forte 				(void) fprintf(stdout, "|");
1324fcf3ce44SJohn Forte 			}
1325fcf3ce44SJohn Forte 			switch (digestAlgorithms->defaultAlgorithms[i]) {
1326fcf3ce44SJohn Forte 				case SUN_IMA_DIGEST_NONE:
1327fcf3ce44SJohn Forte 					(void) fprintf(stdout,
1328fcf3ce44SJohn Forte 					    gettext("NONE"));
1329fcf3ce44SJohn Forte 					break;
1330fcf3ce44SJohn Forte 				case SUN_IMA_DIGEST_CRC32:
1331fcf3ce44SJohn Forte 					(void) fprintf(stdout,
1332fcf3ce44SJohn Forte 					    gettext("CRC32"));
1333fcf3ce44SJohn Forte 					break;
1334fcf3ce44SJohn Forte 				default:
1335fcf3ce44SJohn Forte 					(void) fprintf(stdout,
1336fcf3ce44SJohn Forte 					    gettext("Unknown"));
1337fcf3ce44SJohn Forte 					break;
1338fcf3ce44SJohn Forte 			}
1339fcf3ce44SJohn Forte 		}
1340fcf3ce44SJohn Forte 		(void) fprintf(stdout, "/");
1341fcf3ce44SJohn Forte 		if (digestAlgorithms->currentValid == IMA_TRUE) {
1342fcf3ce44SJohn Forte 			for (i = 0;
1343fcf3ce44SJohn Forte 			    i < digestAlgorithms->currentAlgorithmCount; i++) {
1344fcf3ce44SJohn Forte 				if (i > 0) {
1345fcf3ce44SJohn Forte 					(void) fprintf(stdout, "|");
1346fcf3ce44SJohn Forte 				}
1347fcf3ce44SJohn Forte 				switch (digestAlgorithms->
1348fcf3ce44SJohn Forte 				    currentAlgorithms[i]) {
1349fcf3ce44SJohn Forte 					case SUN_IMA_DIGEST_NONE:
1350fcf3ce44SJohn Forte 						(void) fprintf(stdout,
1351fcf3ce44SJohn Forte 						    gettext("NONE"));
1352fcf3ce44SJohn Forte 						break;
1353fcf3ce44SJohn Forte 					case SUN_IMA_DIGEST_CRC32:
1354fcf3ce44SJohn Forte 						(void) fprintf(stdout,
1355fcf3ce44SJohn Forte 						    gettext("CRC32"));
1356fcf3ce44SJohn Forte 						break;
1357fcf3ce44SJohn Forte 					default:
1358fcf3ce44SJohn Forte 						(void) fprintf(stdout,
1359fcf3ce44SJohn Forte 						    gettext("Unknown"));
1360fcf3ce44SJohn Forte 						break;
1361fcf3ce44SJohn Forte 				}
1362fcf3ce44SJohn Forte 			}
1363fcf3ce44SJohn Forte 		} else {
1364fcf3ce44SJohn Forte 			(void) fprintf(stdout, "-");
1365fcf3ce44SJohn Forte 		}
1366fcf3ce44SJohn Forte 		(void) fprintf(stdout, "\n");
1367fcf3ce44SJohn Forte 	} else if (printOption == PRINT_NEGOTIATED_PARAMS) {
1368fcf3ce44SJohn Forte 
1369fcf3ce44SJohn Forte 		if (digestAlgorithms->negotiatedValid == IMA_TRUE) {
1370fcf3ce44SJohn Forte 			for (i = 0;
1371fcf3ce44SJohn Forte 			    i < digestAlgorithms->negotiatedAlgorithmCount;
1372fcf3ce44SJohn Forte 			    i++) {
1373fcf3ce44SJohn Forte 				if (i > 0) {
1374fcf3ce44SJohn Forte 					(void) fprintf(stdout, "|");
1375fcf3ce44SJohn Forte 				}
1376fcf3ce44SJohn Forte 				switch (digestAlgorithms->
1377fcf3ce44SJohn Forte 				    negotiatedAlgorithms[i]) {
1378fcf3ce44SJohn Forte 					case SUN_IMA_DIGEST_NONE:
1379fcf3ce44SJohn Forte 						(void) fprintf(stdout,
1380fcf3ce44SJohn Forte 						    gettext("NONE"));
1381fcf3ce44SJohn Forte 						break;
1382fcf3ce44SJohn Forte 					case SUN_IMA_DIGEST_CRC32:
1383fcf3ce44SJohn Forte 						(void) fprintf(stdout,
1384fcf3ce44SJohn Forte 						    gettext("CRC32"));
1385fcf3ce44SJohn Forte 						break;
1386fcf3ce44SJohn Forte 					default:
1387fcf3ce44SJohn Forte 						(void) fprintf(stdout,
1388fcf3ce44SJohn Forte 						    gettext("Unknown"));
1389fcf3ce44SJohn Forte 						break;
1390fcf3ce44SJohn Forte 				}
1391fcf3ce44SJohn Forte 			}
1392fcf3ce44SJohn Forte 		} else {
1393fcf3ce44SJohn Forte 			(void) fprintf(stdout, "-");
1394fcf3ce44SJohn Forte 		}
1395fcf3ce44SJohn Forte 		(void) fprintf(stdout, "\n");
1396fcf3ce44SJohn Forte 	}
1397fcf3ce44SJohn Forte }
1398fcf3ce44SJohn Forte 
1399fcf3ce44SJohn Forte static int
setLoginParameters(IMA_OID oid,char * optarg)1400fcf3ce44SJohn Forte setLoginParameters(IMA_OID oid, char *optarg)
1401fcf3ce44SJohn Forte {
1402fcf3ce44SJohn Forte 	char keyp[MAXOPTARGLEN];
1403fcf3ce44SJohn Forte 	char valp[MAXOPTARGLEN];
1404fcf3ce44SJohn Forte 	int key;
1405fcf3ce44SJohn Forte 	char *nameValueString, *indexp, *delim = NULL;
1406fcf3ce44SJohn Forte 
1407fcf3ce44SJohn Forte 	if ((nameValueString = strdup(optarg)) == NULL) {
1408fcf3ce44SJohn Forte 		if (errno == ENOMEM) {
1409fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n",
1410fcf3ce44SJohn Forte 			    cmdName, strerror(errno));
1411fcf3ce44SJohn Forte 		} else {
1412fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
1413fcf3ce44SJohn Forte 			    gettext("unknown error"));
1414fcf3ce44SJohn Forte 		}
1415fcf3ce44SJohn Forte 		return (1);
1416fcf3ce44SJohn Forte 	}
1417fcf3ce44SJohn Forte 
1418fcf3ce44SJohn Forte 	indexp = nameValueString;
1419fcf3ce44SJohn Forte 
1420fcf3ce44SJohn Forte 	/*
1421fcf3ce44SJohn Forte 	 * Retrieve all login params from option argument
1422fcf3ce44SJohn Forte 	 * Syntax <key=value,...>
1423fcf3ce44SJohn Forte 	 */
1424fcf3ce44SJohn Forte 	while (indexp) {
1425fcf3ce44SJohn Forte 		if (delim = strchr(indexp, ',')) {
1426fcf3ce44SJohn Forte 			delim[0] = '\0';
1427fcf3ce44SJohn Forte 		}
1428fcf3ce44SJohn Forte 		(void) memset(keyp, 0, sizeof (keyp));
1429fcf3ce44SJohn Forte 		(void) memset(valp, 0, sizeof (valp));
1430fcf3ce44SJohn Forte 		if (sscanf(indexp, gettext("%[^=]=%s"), keyp, valp) != 2) {
1431fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
1432fcf3ce44SJohn Forte 			    gettext("Unknown param"), indexp);
1433aff4bce5Syi zhang - Sun Microsystems - Beijing China 			if (nameValueString) {
1434aff4bce5Syi zhang - Sun Microsystems - Beijing China 				free(nameValueString);
1435aff4bce5Syi zhang - Sun Microsystems - Beijing China 				nameValueString = NULL;
1436aff4bce5Syi zhang - Sun Microsystems - Beijing China 			}
1437fcf3ce44SJohn Forte 			return (1);
1438fcf3ce44SJohn Forte 		}
1439fcf3ce44SJohn Forte 		if ((key = getLoginParam(keyp)) == -1) {
1440fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
1441fcf3ce44SJohn Forte 			    gettext("Unknown key"), keyp);
1442aff4bce5Syi zhang - Sun Microsystems - Beijing China 			if (nameValueString) {
1443aff4bce5Syi zhang - Sun Microsystems - Beijing China 				free(nameValueString);
1444aff4bce5Syi zhang - Sun Microsystems - Beijing China 				nameValueString = NULL;
1445aff4bce5Syi zhang - Sun Microsystems - Beijing China 			}
1446fcf3ce44SJohn Forte 			return (1);
1447fcf3ce44SJohn Forte 		}
1448fcf3ce44SJohn Forte 		if (setLoginParameter(oid, key, valp) != 0) {
1449aff4bce5Syi zhang - Sun Microsystems - Beijing China 			if (nameValueString) {
1450aff4bce5Syi zhang - Sun Microsystems - Beijing China 				free(nameValueString);
1451aff4bce5Syi zhang - Sun Microsystems - Beijing China 				nameValueString = NULL;
1452aff4bce5Syi zhang - Sun Microsystems - Beijing China 			}
1453fcf3ce44SJohn Forte 			return (1);
1454fcf3ce44SJohn Forte 		}
1455fcf3ce44SJohn Forte 		if (delim) {
1456fcf3ce44SJohn Forte 			indexp = delim + 1;
1457fcf3ce44SJohn Forte 		} else {
1458fcf3ce44SJohn Forte 			indexp = NULL;
1459fcf3ce44SJohn Forte 		}
1460fcf3ce44SJohn Forte 	}
1461fcf3ce44SJohn Forte 
1462aff4bce5Syi zhang - Sun Microsystems - Beijing China 	if (nameValueString) {
1463aff4bce5Syi zhang - Sun Microsystems - Beijing China 		free(nameValueString);
1464aff4bce5Syi zhang - Sun Microsystems - Beijing China 		nameValueString = NULL;
1465aff4bce5Syi zhang - Sun Microsystems - Beijing China 	}
1466fcf3ce44SJohn Forte 	return (0);
1467fcf3ce44SJohn Forte }
1468fcf3ce44SJohn Forte 
1469fcf3ce44SJohn Forte /*
1470fcf3ce44SJohn Forte  * Print logical unit information for a specific target
1471fcf3ce44SJohn Forte  */
1472fcf3ce44SJohn Forte static void
printTargetLuns(IMA_OID_LIST * lunList)1473fcf3ce44SJohn Forte printTargetLuns(IMA_OID_LIST * lunList)
1474fcf3ce44SJohn Forte {
1475fcf3ce44SJohn Forte 	int	j;
1476fcf3ce44SJohn Forte 	IMA_STATUS status;
1477fcf3ce44SJohn Forte 	SUN_IMA_LU_PROPERTIES	lunProps;
1478fcf3ce44SJohn Forte 
1479fcf3ce44SJohn Forte 	for (j = 0; j < lunList->oidCount; j++) {
1480fcf3ce44SJohn Forte 		status = SUN_IMA_GetLuProperties(lunList->oids[j],
1481fcf3ce44SJohn Forte 		    &lunProps);
1482fcf3ce44SJohn Forte 		if (!IMA_SUCCESS(status)) {
1483fcf3ce44SJohn Forte 			printLibError(status);
1484fcf3ce44SJohn Forte 			return;
1485fcf3ce44SJohn Forte 		}
1486fcf3ce44SJohn Forte 
1487904e51f6SJack Meng 		(void) fprintf(stdout, "\tLUN: %lld\n",
1488904e51f6SJack Meng 		    lunProps.imaProps.targetLun);
1489904e51f6SJack Meng 		(void) fprintf(stdout, "\t     Vendor:  %s\n",
1490904e51f6SJack Meng 		    lunProps.vendorId);
1491904e51f6SJack Meng 		(void) fprintf(stdout, "\t     Product: %s\n",
1492904e51f6SJack Meng 		    lunProps.productId);
1493904e51f6SJack Meng 		/*
1494904e51f6SJack Meng 		 * The lun is valid though the os Device Name is not.
1495904e51f6SJack Meng 		 * Give this information to users for judgement.
1496904e51f6SJack Meng 		 */
1497fcf3ce44SJohn Forte 		if (lunProps.imaProps.osDeviceNameValid == IMA_TRUE) {
1498fcf3ce44SJohn Forte 			(void) fprintf(stdout,
1499fcf3ce44SJohn Forte 			    gettext("\t     OS Device Name: %ws\n"),
1500fcf3ce44SJohn Forte 			    lunProps.imaProps.osDeviceName);
1501904e51f6SJack Meng 		} else {
1502904e51f6SJack Meng 			(void) fprintf(stdout,
1503904e51f6SJack Meng 			    gettext("\t     OS Device Name: Not"
1504904e51f6SJack Meng 			    " Available\n"));
1505fcf3ce44SJohn Forte 		}
1506fcf3ce44SJohn Forte 	}
1507fcf3ce44SJohn Forte }
1508fcf3ce44SJohn Forte 
1509fcf3ce44SJohn Forte /*
1510fcf3ce44SJohn Forte  * Retrieve CHAP secret from input
1511fcf3ce44SJohn Forte  */
1512fcf3ce44SJohn Forte static int
getSecret(char * secret,int * secretLen,int minSecretLen,int maxSecretLen)1513fcf3ce44SJohn Forte getSecret(char *secret, int *secretLen, int minSecretLen, int maxSecretLen)
1514fcf3ce44SJohn Forte {
1515fcf3ce44SJohn Forte 	char *chapSecret;
1516fcf3ce44SJohn Forte 
1517fcf3ce44SJohn Forte 	/* get password */
1518fcf3ce44SJohn Forte 	chapSecret = getpassphrase(gettext("Enter secret:"));
1519fcf3ce44SJohn Forte 
15205279807dSJack Meng 	if (chapSecret == NULL) {
15215279807dSJack Meng 		(void) fprintf(stderr, "%s: %s\n", cmdName,
15225279807dSJack Meng 		    gettext("Unable to get secret"));
152333c72b75SToomas Soome 		*secret = '\0';
15245279807dSJack Meng 		return (1);
15255279807dSJack Meng 	}
15265279807dSJack Meng 
1527fcf3ce44SJohn Forte 	if (strlen(chapSecret) > maxSecretLen) {
1528fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s %d\n", cmdName,
1529fcf3ce44SJohn Forte 		    gettext("secret too long, maximum length is"),
1530fcf3ce44SJohn Forte 		    maxSecretLen);
153133c72b75SToomas Soome 		*secret = '\0';
1532fcf3ce44SJohn Forte 		return (1);
1533fcf3ce44SJohn Forte 	}
1534fcf3ce44SJohn Forte 
1535fcf3ce44SJohn Forte 	if (strlen(chapSecret) < minSecretLen) {
1536fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s %d\n", cmdName,
1537fcf3ce44SJohn Forte 		    gettext("secret too short, minimum length is"),
1538fcf3ce44SJohn Forte 		    minSecretLen);
153933c72b75SToomas Soome 		*secret = '\0';
1540fcf3ce44SJohn Forte 		return (1);
1541fcf3ce44SJohn Forte 	}
1542fcf3ce44SJohn Forte 
1543fcf3ce44SJohn Forte 	(void) strcpy(secret, chapSecret);
1544fcf3ce44SJohn Forte 
1545fcf3ce44SJohn Forte 	chapSecret = getpassphrase(gettext("Re-enter secret:"));
15465279807dSJack Meng 
15475279807dSJack Meng 	if (chapSecret == NULL) {
15485279807dSJack Meng 		(void) fprintf(stderr, "%s: %s\n", cmdName,
15495279807dSJack Meng 		    gettext("Unable to get secret"));
155033c72b75SToomas Soome 		*secret = '\0';
15515279807dSJack Meng 		return (1);
15525279807dSJack Meng 	}
15535279807dSJack Meng 
1554fcf3ce44SJohn Forte 	if (strcmp(secret, chapSecret) != 0) {
1555fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n", cmdName,
1556fcf3ce44SJohn Forte 		    gettext("secrets do not match, secret not changed"));
155733c72b75SToomas Soome 		*secret = '\0';
1558fcf3ce44SJohn Forte 		return (1);
1559fcf3ce44SJohn Forte 	}
1560fcf3ce44SJohn Forte 	*secretLen = strlen(chapSecret);
1561fcf3ce44SJohn Forte 	return (0);
1562fcf3ce44SJohn Forte }
1563fcf3ce44SJohn Forte 
1564fcf3ce44SJohn Forte /*
1565fcf3ce44SJohn Forte  * Lists the discovery attributes
1566fcf3ce44SJohn Forte  */
1567fcf3ce44SJohn Forte static int
listDiscovery(int * funcRet)1568fcf3ce44SJohn Forte listDiscovery(int *funcRet)
1569fcf3ce44SJohn Forte {
1570fcf3ce44SJohn Forte 	IMA_OID	initiatorOid;
1571fcf3ce44SJohn Forte 	IMA_DISCOVERY_PROPERTIES discProps;
1572fcf3ce44SJohn Forte 	int ret;
1573fcf3ce44SJohn Forte 	IMA_STATUS status;
1574fcf3ce44SJohn Forte 
1575fcf3ce44SJohn Forte 	assert(funcRet != NULL);
1576fcf3ce44SJohn Forte 
1577fcf3ce44SJohn Forte 
1578fcf3ce44SJohn Forte 	/* Find Sun initiator */
1579fcf3ce44SJohn Forte 	ret = sunInitiatorFind(&initiatorOid);
1580fcf3ce44SJohn Forte 	if (ret > 0) {
1581fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n",
1582fcf3ce44SJohn Forte 		    cmdName, gettext("no initiator found"));
1583fcf3ce44SJohn Forte 	}
1584fcf3ce44SJohn Forte 
1585fcf3ce44SJohn Forte 	if (ret != 0) {
1586fcf3ce44SJohn Forte 		return (ret);
1587fcf3ce44SJohn Forte 	}
1588fcf3ce44SJohn Forte 
1589fcf3ce44SJohn Forte 	/* Get discovery attributes from IMA */
1590fcf3ce44SJohn Forte 	status = IMA_GetDiscoveryProperties(initiatorOid, &discProps);
1591fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
1592fcf3ce44SJohn Forte 		printLibError(status);
1593fcf3ce44SJohn Forte 		*funcRet = 1;
1594fcf3ce44SJohn Forte 		return (ret);
1595fcf3ce44SJohn Forte 	}
1596fcf3ce44SJohn Forte 
1597fcf3ce44SJohn Forte 
1598fcf3ce44SJohn Forte 	(void) fprintf(stdout, "%s:\n", "Discovery");
1599fcf3ce44SJohn Forte 	(void) fprintf(stdout, "\tStatic: %s\n",
1600fcf3ce44SJohn Forte 	    discProps.staticDiscoveryEnabled == IMA_TRUE ? \
1601fcf3ce44SJohn Forte 	    gettext("enabled") : gettext("disabled"));
1602fcf3ce44SJohn Forte 	(void) fprintf(stdout, "\tSend Targets: %s\n",
1603fcf3ce44SJohn Forte 	    discProps.sendTargetsDiscoveryEnabled == IMA_TRUE ? \
1604fcf3ce44SJohn Forte 	    gettext("enabled") : gettext("disabled"));
1605fcf3ce44SJohn Forte 	(void) fprintf(stdout, "\tiSNS: %s\n",
1606fcf3ce44SJohn Forte 	    discProps.iSnsDiscoveryEnabled == IMA_TRUE ? \
1607fcf3ce44SJohn Forte 	    gettext("enabled") : gettext("disabled"));
1608fcf3ce44SJohn Forte 
1609fcf3ce44SJohn Forte 	return (0);
1610fcf3ce44SJohn Forte }
1611fcf3ce44SJohn Forte 
1612fcf3ce44SJohn Forte /*
1613fcf3ce44SJohn Forte  * Print all initiator node attributes
1614fcf3ce44SJohn Forte  */
1615fcf3ce44SJohn Forte static int
listNode(int * funcRet)1616fcf3ce44SJohn Forte listNode(int *funcRet)
1617fcf3ce44SJohn Forte {
1618fcf3ce44SJohn Forte 	IMA_OID	initiatorOid;
1619fcf3ce44SJohn Forte 	IMA_NODE_PROPERTIES nodeProps;
1620fcf3ce44SJohn Forte 	IMA_STATUS status;
1621fcf3ce44SJohn Forte 	int ret;
1622fcf3ce44SJohn Forte 	IMA_UINT maxEntries = MAX_AUTH_METHODS;
1623fcf3ce44SJohn Forte 	IMA_AUTHMETHOD	methodList[MAX_AUTH_METHODS];
1624fcf3ce44SJohn Forte 	SUN_IMA_RADIUS_CONFIG radiusConfig;
1625fcf3ce44SJohn Forte 	SUN_IMA_DIGEST_ALGORITHM_VALUE digestAlgorithms;
1626fcf3ce44SJohn Forte 	IMA_BOOL radiusAccess;
1627fcf3ce44SJohn Forte 
1628fcf3ce44SJohn Forte 	int i;
1629fcf3ce44SJohn Forte 
1630fcf3ce44SJohn Forte 	assert(funcRet != NULL);
1631fcf3ce44SJohn Forte 
1632fcf3ce44SJohn Forte 	ret = getNodeProps(&nodeProps);
1633fcf3ce44SJohn Forte 	if (ret != 0) {
1634fcf3ce44SJohn Forte 		return (ret);
1635fcf3ce44SJohn Forte 	}
1636fcf3ce44SJohn Forte 
1637fcf3ce44SJohn Forte 	if (nodeProps.nameValid == IMA_FALSE) {
1638fcf3ce44SJohn Forte 		return (INVALID_NODE_NAME);
1639fcf3ce44SJohn Forte 	}
1640fcf3ce44SJohn Forte 
1641fcf3ce44SJohn Forte 	/* Find Sun initiator */
1642fcf3ce44SJohn Forte 	ret = sunInitiatorFind(&initiatorOid);
1643fcf3ce44SJohn Forte 	if (ret > 0) {
1644fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n",
1645fcf3ce44SJohn Forte 		    cmdName, gettext("no initiator found"));
1646fcf3ce44SJohn Forte 	}
1647fcf3ce44SJohn Forte 
1648fcf3ce44SJohn Forte 	if (ret != 0) {
1649fcf3ce44SJohn Forte 		return (ret);
1650fcf3ce44SJohn Forte 	}
1651fcf3ce44SJohn Forte 	/* Begin output */
1652fcf3ce44SJohn Forte 	(void) fprintf(stdout, gettext("%s: %ws\n"),
1653fcf3ce44SJohn Forte 	    gettext("Initiator node name"),
1654fcf3ce44SJohn Forte 	    nodeProps.name);
1655fcf3ce44SJohn Forte 	(void) fprintf(stdout, gettext("Initiator node alias: "));
1656fcf3ce44SJohn Forte 	if (nodeProps.aliasValid == IMA_TRUE) {
1657fcf3ce44SJohn Forte 		(void) fprintf(stdout, gettext("%ws\n"), nodeProps.alias);
1658fcf3ce44SJohn Forte 	} else {
1659fcf3ce44SJohn Forte 		(void) fprintf(stdout, "%s\n", "-");
1660fcf3ce44SJohn Forte 	}
1661fcf3ce44SJohn Forte 	(void) fprintf(stdout, "\t%s:\n",
1662fcf3ce44SJohn Forte 	    gettext("Login Parameters (Default/Configured)"));
1663fcf3ce44SJohn Forte 
1664fcf3ce44SJohn Forte 	/* Get Digest configuration */
1665fcf3ce44SJohn Forte 	status = SUN_IMA_GetHeaderDigest(initiatorOid, &digestAlgorithms);
1666fcf3ce44SJohn Forte 	if (IMA_SUCCESS(status)) {
1667fcf3ce44SJohn Forte 		(void) fprintf(stdout, "\t\t%s: ", gettext("Header Digest"));
1668fcf3ce44SJohn Forte 		printDigestAlgorithm(&digestAlgorithms,
1669fcf3ce44SJohn Forte 		    PRINT_CONFIGURED_PARAMS);
1670fcf3ce44SJohn Forte 	} else {
1671fcf3ce44SJohn Forte 		printLibError(status);
1672fcf3ce44SJohn Forte 		*funcRet = 1;
1673fcf3ce44SJohn Forte 		return (ret);
1674fcf3ce44SJohn Forte 	}
1675fcf3ce44SJohn Forte 
1676fcf3ce44SJohn Forte 	status = SUN_IMA_GetDataDigest(initiatorOid, &digestAlgorithms);
1677fcf3ce44SJohn Forte 	if (IMA_SUCCESS(status)) {
1678fcf3ce44SJohn Forte 		(void) fprintf(stdout, "\t\t%s: ", gettext("Data Digest"));
1679fcf3ce44SJohn Forte 		printDigestAlgorithm(&digestAlgorithms,
1680fcf3ce44SJohn Forte 		    PRINT_CONFIGURED_PARAMS);
1681fcf3ce44SJohn Forte 	} else {
1682fcf3ce44SJohn Forte 		printLibError(status);
1683fcf3ce44SJohn Forte 		*funcRet = 1;
1684fcf3ce44SJohn Forte 		return (ret);
1685fcf3ce44SJohn Forte 	}
1686fcf3ce44SJohn Forte 
1687fcf3ce44SJohn Forte 	/* Get authentication type for this lhba */
1688fcf3ce44SJohn Forte 	status = IMA_GetInUseInitiatorAuthMethods(initiatorOid, &maxEntries,
1689fcf3ce44SJohn Forte 	    &methodList[0]);
1690fcf3ce44SJohn Forte 	(void) fprintf(stdout, "\t%s: ", gettext("Authentication Type"));
1691fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
1692fcf3ce44SJohn Forte 		/* No authentication method set - default is NONE */
1693fcf3ce44SJohn Forte 		(void) fprintf(stdout, gettext("NONE"));
1694fcf3ce44SJohn Forte 	} else {
1695fcf3ce44SJohn Forte 		for (i = 0; i < maxEntries; i++) {
1696fcf3ce44SJohn Forte 			if (i > 0) {
1697fcf3ce44SJohn Forte 				(void) fprintf(stdout, "|");
1698fcf3ce44SJohn Forte 			}
1699fcf3ce44SJohn Forte 			switch (methodList[i]) {
1700fcf3ce44SJohn Forte 				case IMA_AUTHMETHOD_NONE:
1701fcf3ce44SJohn Forte 					(void) fprintf(stdout, gettext("NONE"));
1702fcf3ce44SJohn Forte 					break;
1703fcf3ce44SJohn Forte 				case IMA_AUTHMETHOD_CHAP:
1704fcf3ce44SJohn Forte 					(void) fprintf(stdout, gettext("CHAP"));
1705fcf3ce44SJohn Forte 					listCHAPName(initiatorOid);
1706fcf3ce44SJohn Forte 					break;
1707fcf3ce44SJohn Forte 				default:
1708fcf3ce44SJohn Forte 					(void) fprintf(stdout,
1709fcf3ce44SJohn Forte 					    gettext("unknown type"));
1710fcf3ce44SJohn Forte 					break;
1711fcf3ce44SJohn Forte 			}
1712fcf3ce44SJohn Forte 		}
1713fcf3ce44SJohn Forte 	}
1714fcf3ce44SJohn Forte 	(void) fprintf(stdout, "\n");
1715fcf3ce44SJohn Forte 
1716fcf3ce44SJohn Forte 
1717fcf3ce44SJohn Forte 	/* Get RADIUS configuration */
1718fcf3ce44SJohn Forte 	status = SUN_IMA_GetInitiatorRadiusConfig(initiatorOid, &radiusConfig);
1719fcf3ce44SJohn Forte 	(void) fprintf(stdout, "\t%s: ", gettext("RADIUS Server"));
1720fcf3ce44SJohn Forte 	if (IMA_SUCCESS(status)) {
1721fcf3ce44SJohn Forte 		if (strlen(radiusConfig.hostnameIpAddress) > 0) {
1722fcf3ce44SJohn Forte 			(void) fprintf(stdout, "%s:%d",
1723fcf3ce44SJohn Forte 			    radiusConfig.hostnameIpAddress,
1724fcf3ce44SJohn Forte 			    radiusConfig.port);
1725fcf3ce44SJohn Forte 		} else {
1726fcf3ce44SJohn Forte 			(void) fprintf(stdout, "%s", gettext("NONE"));
1727fcf3ce44SJohn Forte 		}
1728fcf3ce44SJohn Forte 	} else {
1729fcf3ce44SJohn Forte 		(void) fprintf(stdout, "%s", gettext("NONE"));
1730fcf3ce44SJohn Forte 	}
1731fcf3ce44SJohn Forte 	(void) fprintf(stdout, "\n");
1732fcf3ce44SJohn Forte 
1733fcf3ce44SJohn Forte 	status = SUN_IMA_GetInitiatorRadiusAccess(initiatorOid,
1734fcf3ce44SJohn Forte 	    &radiusAccess);
1735fcf3ce44SJohn Forte 	(void) fprintf(stdout, "\t%s: ", gettext("RADIUS Access"));
1736fcf3ce44SJohn Forte 	if (IMA_SUCCESS(status)) {
1737fcf3ce44SJohn Forte 		if (radiusAccess == IMA_TRUE) {
1738fcf3ce44SJohn Forte 			(void) fprintf(stdout, "%s", gettext("enabled"));
1739fcf3ce44SJohn Forte 		} else {
1740fcf3ce44SJohn Forte 			(void) fprintf(stdout, "%s", gettext("disabled"));
1741fcf3ce44SJohn Forte 		}
1742fcf3ce44SJohn Forte 	} else if (status == IMA_ERROR_OBJECT_NOT_FOUND) {
1743fcf3ce44SJohn Forte 		(void) fprintf(stdout, "%s", gettext("disabled"));
1744fcf3ce44SJohn Forte 	} else {
1745fcf3ce44SJohn Forte 		(void) fprintf(stdout, "%s", gettext("unknown"));
1746fcf3ce44SJohn Forte 	}
1747fcf3ce44SJohn Forte 	(void) fprintf(stdout, "\n");
1748fcf3ce44SJohn Forte 
1749aff4bce5Syi zhang - Sun Microsystems - Beijing China 	/* print tunable parameters information. */
1750aff4bce5Syi zhang - Sun Microsystems - Beijing China 	ret = printTunableParameters(initiatorOid);
1751aff4bce5Syi zhang - Sun Microsystems - Beijing China 
1752fcf3ce44SJohn Forte 	/* print configured session information. */
1753fcf3ce44SJohn Forte 	ret = printConfiguredSessions(initiatorOid);
1754fcf3ce44SJohn Forte 
1755fcf3ce44SJohn Forte 	return (ret);
1756fcf3ce44SJohn Forte }
1757fcf3ce44SJohn Forte 
1758fcf3ce44SJohn Forte /*
1759fcf3ce44SJohn Forte  * Print discovery addresses
1760fcf3ce44SJohn Forte  */
1761fcf3ce44SJohn Forte static int
listDiscoveryAddress(int objectLen,char * objects[],cmdOptions_t * options,int * funcRet)1762fcf3ce44SJohn Forte listDiscoveryAddress(int objectLen, char *objects[], cmdOptions_t *options,
1763fcf3ce44SJohn Forte     int *funcRet)
1764fcf3ce44SJohn Forte {
1765fcf3ce44SJohn Forte 	IMA_OID	initiatorOid;
1766fcf3ce44SJohn Forte 	SUN_IMA_DISC_ADDR_PROP_LIST *discoveryAddressPropertiesList;
1767fcf3ce44SJohn Forte 	IMA_DISCOVERY_ADDRESS_PROPERTIES discAddrProps;
1768fcf3ce44SJohn Forte 	IMA_TARGET_ADDRESS address;
1769fcf3ce44SJohn Forte 	SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES *pList;
1770fcf3ce44SJohn Forte 	IMA_STATUS status;
1771fcf3ce44SJohn Forte 	wchar_t wcInputObject[MAX_ADDRESS_LEN + 1];
1772fcf3ce44SJohn Forte 	int ret;
1773fcf3ce44SJohn Forte 	boolean_t object = B_FALSE;
1774fcf3ce44SJohn Forte 	int outerLoop;
1775fcf3ce44SJohn Forte 	boolean_t found;
1776fcf3ce44SJohn Forte 	boolean_t verbose = B_FALSE;
1777fcf3ce44SJohn Forte 	int i, j;
1778fcf3ce44SJohn Forte 	cmdOptions_t *optionList = options;
1779fcf3ce44SJohn Forte 	char sAddr[SUN_IMA_IP_ADDRESS_PORT_LEN];
1780fcf3ce44SJohn Forte 
1781fcf3ce44SJohn Forte 	assert(funcRet != NULL);
1782fcf3ce44SJohn Forte 
1783fcf3ce44SJohn Forte 	/* Find Sun initiator */
1784fcf3ce44SJohn Forte 	ret = sunInitiatorFind(&initiatorOid);
1785fcf3ce44SJohn Forte 	if (ret > 0) {
1786fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n",
1787fcf3ce44SJohn Forte 		    cmdName, gettext("no initiator found"));
1788fcf3ce44SJohn Forte 	}
1789fcf3ce44SJohn Forte 
1790fcf3ce44SJohn Forte 	if (ret != 0) {
1791fcf3ce44SJohn Forte 		return (ret);
1792fcf3ce44SJohn Forte 	}
1793fcf3ce44SJohn Forte 
1794fcf3ce44SJohn Forte 	for (; optionList->optval; optionList++) {
1795fcf3ce44SJohn Forte 		switch (optionList->optval) {
1796fcf3ce44SJohn Forte 			case 'v':
1797fcf3ce44SJohn Forte 				verbose = B_TRUE;
1798fcf3ce44SJohn Forte 				break;
1799fcf3ce44SJohn Forte 			default:
1800fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %c: %s\n",
1801fcf3ce44SJohn Forte 				    cmdName, optionList->optval,
1802fcf3ce44SJohn Forte 				    gettext("unknown option"));
1803fcf3ce44SJohn Forte 				return (1);
1804fcf3ce44SJohn Forte 		}
1805fcf3ce44SJohn Forte 	}
1806fcf3ce44SJohn Forte 
1807fcf3ce44SJohn Forte 	/*
1808fcf3ce44SJohn Forte 	 * If there are multiple objects, execute outer 'for' loop that
1809fcf3ce44SJohn Forte 	 * many times for each target detail, otherwise, execute it only
1810fcf3ce44SJohn Forte 	 * once with summaries only
1811fcf3ce44SJohn Forte 	 */
1812fcf3ce44SJohn Forte 	if (objectLen > 0) {
1813fcf3ce44SJohn Forte 		object = B_TRUE;
1814fcf3ce44SJohn Forte 		outerLoop = objectLen;
1815fcf3ce44SJohn Forte 	} else {
1816fcf3ce44SJohn Forte 		object = B_FALSE;
1817fcf3ce44SJohn Forte 		outerLoop = 1;
1818fcf3ce44SJohn Forte 	}
1819fcf3ce44SJohn Forte 
1820fcf3ce44SJohn Forte 	status = SUN_IMA_GetDiscoveryAddressPropertiesList(
1821fcf3ce44SJohn Forte 	    &discoveryAddressPropertiesList);
1822fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
1823fcf3ce44SJohn Forte 		printLibError(status);
1824fcf3ce44SJohn Forte 		*funcRet = 1;
1825fcf3ce44SJohn Forte 		return (ret);
1826fcf3ce44SJohn Forte 	}
1827fcf3ce44SJohn Forte 
1828fcf3ce44SJohn Forte 	for (i = 0; i < outerLoop; i++) {
1829fcf3ce44SJohn Forte 		if (object) {
1830fcf3ce44SJohn Forte 			/* initialize */
1831fcf3ce44SJohn Forte 			(void) memset(&wcInputObject[0], 0,
1832fcf3ce44SJohn Forte 			    sizeof (wcInputObject));
1833fcf3ce44SJohn Forte 			(void) memset(&address, 0, sizeof (address));
1834fcf3ce44SJohn Forte 			if (mbstowcs(wcInputObject, objects[i],
1835fcf3ce44SJohn Forte 			    (MAX_ADDRESS_LEN + 1)) == (size_t)-1) {
1836fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n",
1837fcf3ce44SJohn Forte 				    cmdName,
1838fcf3ce44SJohn Forte 				    gettext("conversion error"));
1839fcf3ce44SJohn Forte 				ret = 1;
1840fcf3ce44SJohn Forte 				continue;
1841fcf3ce44SJohn Forte 			}
1842fcf3ce44SJohn Forte 
1843fcf3ce44SJohn Forte 			/*
1844fcf3ce44SJohn Forte 			 * if one or more objects were input,
1845fcf3ce44SJohn Forte 			 * get the values
1846fcf3ce44SJohn Forte 			 */
1847fcf3ce44SJohn Forte 			if (getTargetAddress(DISCOVERY_ADDRESS,
1848fcf3ce44SJohn Forte 			    objects[i], &address) != 0) {
1849fcf3ce44SJohn Forte 				ret = 1;
1850fcf3ce44SJohn Forte 				continue;
1851fcf3ce44SJohn Forte 			}
1852fcf3ce44SJohn Forte 		}
1853fcf3ce44SJohn Forte 		for (found = B_FALSE, j = 0;
1854fcf3ce44SJohn Forte 		    j < discoveryAddressPropertiesList->discAddrCount;
1855fcf3ce44SJohn Forte 		    j++) {
1856fcf3ce44SJohn Forte 			discAddrProps =
1857fcf3ce44SJohn Forte 			    discoveryAddressPropertiesList->props[j];
1858fcf3ce44SJohn Forte 
1859fcf3ce44SJohn Forte 			/*
1860fcf3ce44SJohn Forte 			 * Compare the discovery address with the input if
1861fcf3ce44SJohn Forte 			 * one was input
1862fcf3ce44SJohn Forte 			 */
1863fcf3ce44SJohn Forte 			if (object &&
1864fcf3ce44SJohn Forte 			    ipAddressesEqual(discAddrProps.discoveryAddress,
1865fcf3ce44SJohn Forte 			    address) && (discAddrProps.discoveryAddress.
1866fcf3ce44SJohn Forte 			    portNumber == address.portNumber)) {
1867fcf3ce44SJohn Forte 				found = B_TRUE;
1868fcf3ce44SJohn Forte 			}
1869fcf3ce44SJohn Forte 
1870fcf3ce44SJohn Forte 			if (!object || found) {
1871fcf3ce44SJohn Forte 				/* Print summary - always */
1872fcf3ce44SJohn Forte 				if (discAddrProps.discoveryAddress.
1873fcf3ce44SJohn Forte 				    hostnameIpAddress.id.ipAddress.
1874fcf3ce44SJohn Forte 				    ipv4Address) {
1875fcf3ce44SJohn Forte 					(void) inet_ntop(AF_INET, discAddrProps.
1876fcf3ce44SJohn Forte 					    discoveryAddress.hostnameIpAddress.
1877fcf3ce44SJohn Forte 					    id.ipAddress.ipAddress, sAddr,
1878fcf3ce44SJohn Forte 					    sizeof (sAddr));
1879fcf3ce44SJohn Forte 					(void) fprintf(stdout,
1880fcf3ce44SJohn Forte 					    "Discovery Address: %s:%u\n",
1881fcf3ce44SJohn Forte 					    sAddr, discAddrProps.
1882fcf3ce44SJohn Forte 					    discoveryAddress.portNumber);
1883fcf3ce44SJohn Forte 				} else {
1884fcf3ce44SJohn Forte 					(void) inet_ntop(AF_INET6,
1885fcf3ce44SJohn Forte 					    discAddrProps.
1886fcf3ce44SJohn Forte 					    discoveryAddress.hostnameIpAddress.
1887fcf3ce44SJohn Forte 					    id.ipAddress.ipAddress, sAddr,
1888fcf3ce44SJohn Forte 					    sizeof (sAddr));
1889fcf3ce44SJohn Forte 					(void) fprintf(stdout,
1890fcf3ce44SJohn Forte 					    "DiscoveryAddress: [%s]:%u\n",
1891fcf3ce44SJohn Forte 					    sAddr, discAddrProps.
1892fcf3ce44SJohn Forte 					    discoveryAddress.portNumber);
1893fcf3ce44SJohn Forte 				}
1894fcf3ce44SJohn Forte 			}
1895fcf3ce44SJohn Forte 
1896fcf3ce44SJohn Forte 			if ((!object || found) && verbose) {
1897fcf3ce44SJohn Forte 				IMA_NODE_PROPERTIES nodeProps;
1898fcf3ce44SJohn Forte 
1899fcf3ce44SJohn Forte 				if (getNodeProps(&nodeProps) != 0) {
1900fcf3ce44SJohn Forte 					break;
1901fcf3ce44SJohn Forte 				}
1902fcf3ce44SJohn Forte 
1903fcf3ce44SJohn Forte 				/*
1904fcf3ce44SJohn Forte 				 * Issue sendTargets only when an addr is
1905fcf3ce44SJohn Forte 				 * specified.
1906fcf3ce44SJohn Forte 				 */
1907fcf3ce44SJohn Forte 				status = SUN_IMA_SendTargets(nodeProps.name,
1908fcf3ce44SJohn Forte 				    discAddrProps.discoveryAddress, &pList);
1909fcf3ce44SJohn Forte 				if (!IMA_SUCCESS(status)) {
1910fcf3ce44SJohn Forte 					(void) fprintf(stderr, "%s\n",
1911fcf3ce44SJohn Forte 					    gettext("\tUnable to get "\
1912fcf3ce44SJohn Forte 					    "targets."));
1913fcf3ce44SJohn Forte 					*funcRet = 1;
1914fcf3ce44SJohn Forte 					continue;
1915fcf3ce44SJohn Forte 				}
1916fcf3ce44SJohn Forte 				printSendTargets(pList);
1917fcf3ce44SJohn Forte 			}
1918fcf3ce44SJohn Forte 
1919fcf3ce44SJohn Forte 			if (found) {
1920fcf3ce44SJohn Forte 				/* we found the discovery address - break */
1921fcf3ce44SJohn Forte 				break;
1922fcf3ce44SJohn Forte 			}
1923fcf3ce44SJohn Forte 		}
1924fcf3ce44SJohn Forte 		/*
1925fcf3ce44SJohn Forte 		 * There was an object entered but we didn't
1926fcf3ce44SJohn Forte 		 * find it.
1927fcf3ce44SJohn Forte 		 */
1928fcf3ce44SJohn Forte 		if (object && !found) {
1929fcf3ce44SJohn Forte 			(void) fprintf(stdout, "%s: %s\n",
1930fcf3ce44SJohn Forte 			    objects[i], gettext("not found"));
1931fcf3ce44SJohn Forte 		}
1932fcf3ce44SJohn Forte 	}
1933fcf3ce44SJohn Forte 	return (ret);
1934fcf3ce44SJohn Forte }
1935fcf3ce44SJohn Forte 
1936fcf3ce44SJohn Forte /*
1937fcf3ce44SJohn Forte  * Print ISNS Server addresses
1938fcf3ce44SJohn Forte  */
1939fcf3ce44SJohn Forte static int
listISNSServerAddress(int objectLen,char * objects[],cmdOptions_t * options,int * funcRet)1940fcf3ce44SJohn Forte listISNSServerAddress(int objectLen, char *objects[], cmdOptions_t *options,
1941fcf3ce44SJohn Forte     int *funcRet)
1942fcf3ce44SJohn Forte {
1943fcf3ce44SJohn Forte 	IMA_OID	initiatorOid;
1944fcf3ce44SJohn Forte 	SUN_IMA_DISC_ADDR_PROP_LIST	    *discoveryAddressPropertiesList;
1945fcf3ce44SJohn Forte 	IMA_DISCOVERY_ADDRESS_PROPERTIES discAddrProps;
1946fcf3ce44SJohn Forte 	IMA_TARGET_ADDRESS address;
1947fcf3ce44SJohn Forte 	SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES *pList;
1948fcf3ce44SJohn Forte 	IMA_STATUS status;
1949fcf3ce44SJohn Forte 	wchar_t wcInputObject[MAX_ADDRESS_LEN + 1];
1950fcf3ce44SJohn Forte 	int ret;
1951fcf3ce44SJohn Forte 	boolean_t object = B_FALSE;
1952fcf3ce44SJohn Forte 	int outerLoop;
1953fcf3ce44SJohn Forte 	boolean_t found;
1954fcf3ce44SJohn Forte 	boolean_t showTarget = B_FALSE;
1955fcf3ce44SJohn Forte 	int i, j;
1956fcf3ce44SJohn Forte 	cmdOptions_t *optionList = options;
1957fcf3ce44SJohn Forte 	char sAddr[SUN_IMA_IP_ADDRESS_PORT_LEN];
1958fcf3ce44SJohn Forte 
1959fcf3ce44SJohn Forte 	assert(funcRet != NULL);
1960fcf3ce44SJohn Forte 
1961fcf3ce44SJohn Forte 	/* Find Sun initiator */
1962fcf3ce44SJohn Forte 	ret = sunInitiatorFind(&initiatorOid);
1963fcf3ce44SJohn Forte 	if (ret > 0) {
1964fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n",
1965fcf3ce44SJohn Forte 		    cmdName, gettext("no initiator found"));
1966fcf3ce44SJohn Forte 	}
1967fcf3ce44SJohn Forte 
1968fcf3ce44SJohn Forte 	if (ret != 0) {
1969fcf3ce44SJohn Forte 		return (ret);
1970fcf3ce44SJohn Forte 	}
1971fcf3ce44SJohn Forte 
1972fcf3ce44SJohn Forte 	for (; optionList->optval; optionList++) {
1973fcf3ce44SJohn Forte 		switch (optionList->optval) {
1974fcf3ce44SJohn Forte 			case 'v':
1975fcf3ce44SJohn Forte 				showTarget = B_TRUE;
1976fcf3ce44SJohn Forte 				break;
1977fcf3ce44SJohn Forte 			default:
1978fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %c: %s\n",
1979fcf3ce44SJohn Forte 				    cmdName, optionList->optval,
1980fcf3ce44SJohn Forte 				    gettext("unknown option"));
1981fcf3ce44SJohn Forte 				return (1);
1982fcf3ce44SJohn Forte 		}
1983fcf3ce44SJohn Forte 	}
1984fcf3ce44SJohn Forte 
1985fcf3ce44SJohn Forte 	/*
1986fcf3ce44SJohn Forte 	 * If there are multiple objects, execute outer 'for' loop that
1987fcf3ce44SJohn Forte 	 * many times for each target detail, otherwise, execute it only
1988fcf3ce44SJohn Forte 	 * once with summaries only
1989fcf3ce44SJohn Forte 	 */
1990fcf3ce44SJohn Forte 	if (objectLen > 0) {
1991fcf3ce44SJohn Forte 		object = B_TRUE;
1992fcf3ce44SJohn Forte 		outerLoop = objectLen;
1993fcf3ce44SJohn Forte 	} else {
1994fcf3ce44SJohn Forte 		object = B_FALSE;
1995fcf3ce44SJohn Forte 		outerLoop = 1;
1996fcf3ce44SJohn Forte 	}
1997fcf3ce44SJohn Forte 
1998fcf3ce44SJohn Forte 	status = SUN_IMA_GetISNSServerAddressPropertiesList(
1999fcf3ce44SJohn Forte 	    &discoveryAddressPropertiesList);
2000fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
2001fcf3ce44SJohn Forte 		printLibError(status);
2002fcf3ce44SJohn Forte 		*funcRet = 1;
2003fcf3ce44SJohn Forte 		return (ret);
2004fcf3ce44SJohn Forte 	}
2005fcf3ce44SJohn Forte 
2006fcf3ce44SJohn Forte 	for (i = 0; i < outerLoop; i++) {
2007fcf3ce44SJohn Forte 		if (object) {
2008fcf3ce44SJohn Forte 			/* initialize */
2009fcf3ce44SJohn Forte 			(void) memset(&wcInputObject[0], 0,
2010fcf3ce44SJohn Forte 			    sizeof (wcInputObject));
2011fcf3ce44SJohn Forte 			(void) memset(&address, 0, sizeof (address));
2012fcf3ce44SJohn Forte 			if (mbstowcs(wcInputObject, objects[i],
2013fcf3ce44SJohn Forte 			    (MAX_ADDRESS_LEN + 1)) == (size_t)-1) {
2014fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s\n",
2015fcf3ce44SJohn Forte 				    cmdName,
2016fcf3ce44SJohn Forte 				    gettext("conversion error"));
2017fcf3ce44SJohn Forte 				ret = 1;
2018fcf3ce44SJohn Forte 				continue;
2019fcf3ce44SJohn Forte 			}
2020fcf3ce44SJohn Forte 
2021fcf3ce44SJohn Forte 			/*
2022fcf3ce44SJohn Forte 			 * if one or more objects were input,
2023fcf3ce44SJohn Forte 			 * get the values
2024fcf3ce44SJohn Forte 			 */
2025fcf3ce44SJohn Forte 			if (getTargetAddress(ISNS_SERVER_ADDRESS,
2026fcf3ce44SJohn Forte 			    objects[i], &address) != 0) {
2027fcf3ce44SJohn Forte 				ret = 1;
2028fcf3ce44SJohn Forte 				continue;
2029fcf3ce44SJohn Forte 			}
2030fcf3ce44SJohn Forte 		}
2031fcf3ce44SJohn Forte 		for (found = B_FALSE, j = 0;
2032fcf3ce44SJohn Forte 		    j < discoveryAddressPropertiesList->discAddrCount;
2033fcf3ce44SJohn Forte 		    j++) {
2034fcf3ce44SJohn Forte 			discAddrProps =
2035fcf3ce44SJohn Forte 			    discoveryAddressPropertiesList->props[j];
2036fcf3ce44SJohn Forte 
2037fcf3ce44SJohn Forte 			/*
2038fcf3ce44SJohn Forte 			 * Compare the discovery address with the input if
2039fcf3ce44SJohn Forte 			 * one was input
2040fcf3ce44SJohn Forte 			 */
2041fcf3ce44SJohn Forte 			if (object &&
2042fcf3ce44SJohn Forte 			    ipAddressesEqual(discAddrProps.discoveryAddress,
2043fcf3ce44SJohn Forte 			    address) &&
2044fcf3ce44SJohn Forte 			    (discAddrProps.discoveryAddress.portNumber ==
2045fcf3ce44SJohn Forte 			    address.portNumber)) {
2046fcf3ce44SJohn Forte 				found = B_TRUE;
2047fcf3ce44SJohn Forte 			}
2048fcf3ce44SJohn Forte 
2049fcf3ce44SJohn Forte 			if (!object || found) {
2050fcf3ce44SJohn Forte 				/* Print summary - always */
2051fcf3ce44SJohn Forte 				if (discAddrProps.discoveryAddress.
2052fcf3ce44SJohn Forte 				    hostnameIpAddress.id.ipAddress.
2053fcf3ce44SJohn Forte 				    ipv4Address) {
2054fcf3ce44SJohn Forte 					(void) inet_ntop(AF_INET, discAddrProps.
2055fcf3ce44SJohn Forte 					    discoveryAddress.hostnameIpAddress.
2056fcf3ce44SJohn Forte 					    id.ipAddress.ipAddress, sAddr,
2057fcf3ce44SJohn Forte 					    sizeof (sAddr));
2058fcf3ce44SJohn Forte 				} else {
2059fcf3ce44SJohn Forte 					(void) inet_ntop(AF_INET6,
2060fcf3ce44SJohn Forte 					    discAddrProps.
2061fcf3ce44SJohn Forte 					    discoveryAddress.hostnameIpAddress.
2062fcf3ce44SJohn Forte 					    id.ipAddress.ipAddress, sAddr,
2063fcf3ce44SJohn Forte 					    sizeof (sAddr));
2064fcf3ce44SJohn Forte 				}
2065fcf3ce44SJohn Forte 				(void) fprintf(stdout,
2066fcf3ce44SJohn Forte 				    "iSNS Server IP Address: %s:%u\n",
2067fcf3ce44SJohn Forte 				    sAddr,
2068fcf3ce44SJohn Forte 				    discAddrProps.discoveryAddress.portNumber);
2069fcf3ce44SJohn Forte 			}
2070fcf3ce44SJohn Forte 
2071fcf3ce44SJohn Forte 			if ((!object || found) && showTarget) {
2072fcf3ce44SJohn Forte 				IMA_NODE_PROPERTIES nodeProps;
2073fcf3ce44SJohn Forte 
2074fcf3ce44SJohn Forte 				if (getNodeProps(&nodeProps) != 0) {
2075fcf3ce44SJohn Forte 					break;
2076fcf3ce44SJohn Forte 				}
2077fcf3ce44SJohn Forte 
2078fcf3ce44SJohn Forte 				/*
2079fcf3ce44SJohn Forte 				 * Issue sendTargets only when an addr is
2080fcf3ce44SJohn Forte 				 * specified.
2081fcf3ce44SJohn Forte 				 */
2082fcf3ce44SJohn Forte 				status = SUN_IMA_RetrieveISNSServerTargets(
2083fcf3ce44SJohn Forte 				    discAddrProps.discoveryAddress,
2084fcf3ce44SJohn Forte 				    &pList);
2085fcf3ce44SJohn Forte 				if (!IMA_SUCCESS(status)) {
2086fcf3ce44SJohn Forte 					/*
2087fcf3ce44SJohn Forte 					 * Check if the discovery mode is
2088fcf3ce44SJohn Forte 					 * disabled.
2089fcf3ce44SJohn Forte 					 */
2090fcf3ce44SJohn Forte 					if (status ==
2091fcf3ce44SJohn Forte 					    IMA_ERROR_OBJECT_NOT_FOUND) {
2092fcf3ce44SJohn Forte 						(void) fprintf(stderr, "%s\n",
2093fcf3ce44SJohn Forte 						    gettext("\tiSNS "\
2094fcf3ce44SJohn Forte 						    "discovery "\
2095fcf3ce44SJohn Forte 						    "mode "\
2096fcf3ce44SJohn Forte 						    "disabled. "\
2097fcf3ce44SJohn Forte 						    "No targets "\
2098fcf3ce44SJohn Forte 						    "to report."));
2099fcf3ce44SJohn Forte 
2100fcf3ce44SJohn Forte 					} else {
2101fcf3ce44SJohn Forte 						(void) fprintf(stderr, "%s\n",
2102fcf3ce44SJohn Forte 						    gettext("\tUnable "\
2103fcf3ce44SJohn Forte 						    "to get "\
2104fcf3ce44SJohn Forte 						    "targets."));
2105fcf3ce44SJohn Forte 					}
2106fcf3ce44SJohn Forte 					continue;
2107fcf3ce44SJohn Forte 				}
2108fcf3ce44SJohn Forte 				printSendTargets(pList);
2109fcf3ce44SJohn Forte 			}
2110fcf3ce44SJohn Forte 
2111fcf3ce44SJohn Forte 			if (found) {
2112fcf3ce44SJohn Forte 				/* we found the discovery address - break */
2113fcf3ce44SJohn Forte 				break;
2114fcf3ce44SJohn Forte 			}
2115fcf3ce44SJohn Forte 		}
2116fcf3ce44SJohn Forte 		/*
2117fcf3ce44SJohn Forte 		 * There was an object entered but we didn't
2118fcf3ce44SJohn Forte 		 * find it.
2119fcf3ce44SJohn Forte 		 */
2120fcf3ce44SJohn Forte 		if (object && !found) {
2121fcf3ce44SJohn Forte 			(void) fprintf(stdout, "%s: %s\n",
2122fcf3ce44SJohn Forte 			    objects[i], gettext("not found"));
2123fcf3ce44SJohn Forte 		}
2124fcf3ce44SJohn Forte 	}
2125fcf3ce44SJohn Forte 	return (ret);
2126fcf3ce44SJohn Forte }
2127fcf3ce44SJohn Forte 
2128fcf3ce44SJohn Forte /*
2129fcf3ce44SJohn Forte  * Print static configuration targets
2130fcf3ce44SJohn Forte  */
2131fcf3ce44SJohn Forte static int
listStaticConfig(int operandLen,char * operand[],int * funcRet)2132fcf3ce44SJohn Forte listStaticConfig(int operandLen, char *operand[], int *funcRet)
2133fcf3ce44SJohn Forte {
2134fcf3ce44SJohn Forte 	IMA_STATUS status;
2135fcf3ce44SJohn Forte 	IMA_OID	initiatorOid;
2136fcf3ce44SJohn Forte 	IMA_OID_LIST *staticTargetList;
2137fcf3ce44SJohn Forte 	SUN_IMA_STATIC_TARGET_PROPERTIES staticTargetProps;
2138fcf3ce44SJohn Forte 	wchar_t staticTargetName[MAX_ISCSI_NAME_LEN + 1];
2139fcf3ce44SJohn Forte 	wchar_t staticTargetAddress[SUN_IMA_IP_ADDRESS_PORT_LEN];
2140fcf3ce44SJohn Forte 	wchar_t wcCol;
2141fcf3ce44SJohn Forte 	char sAddr[SUN_IMA_IP_ADDRESS_PORT_LEN];
2142fcf3ce44SJohn Forte 	int ret;
2143fcf3ce44SJohn Forte 	boolean_t object = B_FALSE;
2144fcf3ce44SJohn Forte 	int outerLoop;
2145fcf3ce44SJohn Forte 	boolean_t found; /* B_TRUE if a target name is found */
2146fcf3ce44SJohn Forte 	boolean_t matched; /* B_TRUE if a specific target is found */
2147fcf3ce44SJohn Forte 	boolean_t targetAddressSpecified = B_FALSE;
2148fcf3ce44SJohn Forte 	boolean_t tpgtSpecified = B_FALSE;
2149fcf3ce44SJohn Forte 	boolean_t isIpv6;
2150fcf3ce44SJohn Forte 	int i, j;
2151fcf3ce44SJohn Forte 	IMA_UINT16 port = 0;
2152fcf3ce44SJohn Forte 	IMA_UINT16 tpgt = 0;
2153fcf3ce44SJohn Forte 	char tmpStr[SUN_IMA_IP_ADDRESS_PORT_LEN];
2154fcf3ce44SJohn Forte 	wchar_t tmpTargetAddress[SUN_IMA_IP_ADDRESS_PORT_LEN];
2155fcf3ce44SJohn Forte 
2156fcf3ce44SJohn Forte 	assert(funcRet != NULL);
2157fcf3ce44SJohn Forte 
2158fcf3ce44SJohn Forte 	/* Find Sun initiator */
2159fcf3ce44SJohn Forte 	ret = sunInitiatorFind(&initiatorOid);
2160fcf3ce44SJohn Forte 	if (ret > 0) {
2161fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n",
2162fcf3ce44SJohn Forte 		    cmdName, gettext("no initiator found"));
2163fcf3ce44SJohn Forte 	}
2164fcf3ce44SJohn Forte 
2165fcf3ce44SJohn Forte 	if (ret != 0) {
2166fcf3ce44SJohn Forte 		return (ret);
2167fcf3ce44SJohn Forte 	}
2168fcf3ce44SJohn Forte 
2169fcf3ce44SJohn Forte 	/*
2170fcf3ce44SJohn Forte 	 * If there are multiple objects, execute outer 'for' loop that
2171fcf3ce44SJohn Forte 	 * many times for each static config detail, otherwise, execute it only
2172fcf3ce44SJohn Forte 	 * once with summaries only
2173fcf3ce44SJohn Forte 	 */
2174fcf3ce44SJohn Forte 	if (operandLen > 0) {
2175fcf3ce44SJohn Forte 		object = B_TRUE;
2176fcf3ce44SJohn Forte 		outerLoop = operandLen;
2177fcf3ce44SJohn Forte 	} else {
2178fcf3ce44SJohn Forte 		object = B_FALSE;
2179fcf3ce44SJohn Forte 		outerLoop = 1;
2180fcf3ce44SJohn Forte 	}
2181fcf3ce44SJohn Forte 
2182fcf3ce44SJohn Forte 	/* convert ':' to wide char for wchar string search */
2183fcf3ce44SJohn Forte 	if (mbtowc(&wcCol, ":", sizeof (wcCol)) == -1) {
2184fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n",
2185fcf3ce44SJohn Forte 		    cmdName, gettext("conversion error"));
2186fcf3ce44SJohn Forte 		return (1);
2187fcf3ce44SJohn Forte 	}
2188fcf3ce44SJohn Forte 
2189fcf3ce44SJohn Forte 	status = IMA_GetStaticDiscoveryTargetOidList(initiatorOid,
2190fcf3ce44SJohn Forte 	    &staticTargetList);
2191fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
2192fcf3ce44SJohn Forte 		printLibError(status);
2193fcf3ce44SJohn Forte 		*funcRet = 1;
2194fcf3ce44SJohn Forte 		return (ret);
2195fcf3ce44SJohn Forte 	}
2196fcf3ce44SJohn Forte 
2197fcf3ce44SJohn Forte 	for (i = 0; i < outerLoop; i++) {
2198fcf3ce44SJohn Forte 		if (object) {
2199fcf3ce44SJohn Forte 			if (parseTarget(operand[i],
2200fcf3ce44SJohn Forte 			    &staticTargetName[0],
2201fcf3ce44SJohn Forte 			    MAX_ISCSI_NAME_LEN + 1,
2202fcf3ce44SJohn Forte 			    &targetAddressSpecified,
2203fcf3ce44SJohn Forte 			    &staticTargetAddress[0],
2204fcf3ce44SJohn Forte 			    SUN_IMA_IP_ADDRESS_PORT_LEN,
2205fcf3ce44SJohn Forte 			    &port,
2206fcf3ce44SJohn Forte 			    &tpgtSpecified,
2207fcf3ce44SJohn Forte 			    &tpgt,
2208fcf3ce44SJohn Forte 			    &isIpv6) != PARSE_TARGET_OK) {
2209fcf3ce44SJohn Forte 				ret = 1;
2210fcf3ce44SJohn Forte 				continue;
2211fcf3ce44SJohn Forte 			}
2212fcf3ce44SJohn Forte 		}
2213fcf3ce44SJohn Forte 
2214fcf3ce44SJohn Forte 		for (found = B_FALSE, j = 0; j < staticTargetList->oidCount;
2215fcf3ce44SJohn Forte 		    j++) {
2216fcf3ce44SJohn Forte 			boolean_t isIpv6 = B_FALSE;
2217fcf3ce44SJohn Forte 			IMA_UINT16 stpgt;
2218fcf3ce44SJohn Forte 			IMA_BOOL defaultTpgt;
2219fcf3ce44SJohn Forte 
2220fcf3ce44SJohn Forte 			matched = B_FALSE;
2221fcf3ce44SJohn Forte 			(void) memset(&staticTargetProps, 0,
2222fcf3ce44SJohn Forte 			    sizeof (staticTargetProps));
2223fcf3ce44SJohn Forte 
2224fcf3ce44SJohn Forte 			status = SUN_IMA_GetStaticTargetProperties(
2225fcf3ce44SJohn Forte 			    staticTargetList->oids[j], &staticTargetProps);
2226fcf3ce44SJohn Forte 			if (!IMA_SUCCESS(status)) {
2227fcf3ce44SJohn Forte 				printLibError(status);
2228fcf3ce44SJohn Forte 				(void) IMA_FreeMemory(staticTargetList);
2229fcf3ce44SJohn Forte 				*funcRet = 1;
2230fcf3ce44SJohn Forte 				return (ret);
2231fcf3ce44SJohn Forte 			}
2232fcf3ce44SJohn Forte 
2233fcf3ce44SJohn Forte 			stpgt = staticTargetProps.staticTarget.targetAddress.
2234fcf3ce44SJohn Forte 			    tpgt;
2235fcf3ce44SJohn Forte 
2236fcf3ce44SJohn Forte 			defaultTpgt = staticTargetProps.staticTarget.
2237fcf3ce44SJohn Forte 			    targetAddress.defaultTpgt;
2238fcf3ce44SJohn Forte 
2239fcf3ce44SJohn Forte 			isIpv6 = !staticTargetProps.staticTarget.targetAddress.
2240fcf3ce44SJohn Forte 			    imaStruct.hostnameIpAddress.id.ipAddress.
2241fcf3ce44SJohn Forte 			    ipv4Address;
2242fcf3ce44SJohn Forte 
2243fcf3ce44SJohn Forte 			/*
2244fcf3ce44SJohn Forte 			 * Compare the static target name with the input if
2245fcf3ce44SJohn Forte 			 * one was input
2246fcf3ce44SJohn Forte 			 */
2247fcf3ce44SJohn Forte 
2248fcf3ce44SJohn Forte 			if (object &&
2249fcf3ce44SJohn Forte 			    (targetNamesEqual(
2250fcf3ce44SJohn Forte 			    staticTargetProps.staticTarget.targetName,
2251fcf3ce44SJohn Forte 			    staticTargetName) == B_TRUE)) {
2252fcf3ce44SJohn Forte 				/* targetName found - found = B_TRUE */
2253fcf3ce44SJohn Forte 				found = B_TRUE;
2254fcf3ce44SJohn Forte 				if (targetAddressSpecified == B_FALSE) {
2255fcf3ce44SJohn Forte 					matched = B_TRUE;
2256fcf3ce44SJohn Forte 				} else {
2257fcf3ce44SJohn Forte 
2258fcf3ce44SJohn Forte 				if (staticTargetProps.staticTarget.
2259fcf3ce44SJohn Forte 				    targetAddress.imaStruct.
2260fcf3ce44SJohn Forte 				    hostnameIpAddress.id.ipAddress.
2261fcf3ce44SJohn Forte 				    ipv4Address == IMA_TRUE) {
2262fcf3ce44SJohn Forte 					(void) inet_ntop(AF_INET,
2263fcf3ce44SJohn Forte 					    staticTargetProps.
2264fcf3ce44SJohn Forte 					    staticTarget.targetAddress.
2265fcf3ce44SJohn Forte 					    imaStruct.hostnameIpAddress.id.
2266fcf3ce44SJohn Forte 					    ipAddress.ipAddress, tmpStr,
2267fcf3ce44SJohn Forte 					    sizeof (tmpStr));
2268fcf3ce44SJohn Forte 				} else {
2269fcf3ce44SJohn Forte 					(void) inet_ntop(AF_INET6,
2270fcf3ce44SJohn Forte 					    staticTargetProps.
2271fcf3ce44SJohn Forte 					    staticTarget.targetAddress.
2272fcf3ce44SJohn Forte 					    imaStruct.hostnameIpAddress.id.
2273fcf3ce44SJohn Forte 					    ipAddress.ipAddress, tmpStr,
2274fcf3ce44SJohn Forte 					    sizeof (tmpStr));
2275fcf3ce44SJohn Forte 				}
2276fcf3ce44SJohn Forte 
2277fcf3ce44SJohn Forte 				if (mbstowcs(tmpTargetAddress, tmpStr,
2278fcf3ce44SJohn Forte 				    SUN_IMA_IP_ADDRESS_PORT_LEN) ==
2279fcf3ce44SJohn Forte 				    (size_t)-1) {
2280fcf3ce44SJohn Forte 					(void) fprintf(stderr, "%s: %s\n",
2281fcf3ce44SJohn Forte 					    cmdName,
2282fcf3ce44SJohn Forte 					gettext("conversion error"));
2283fcf3ce44SJohn Forte 					ret = 1;
2284fcf3ce44SJohn Forte 					continue;
2285fcf3ce44SJohn Forte 				}
2286fcf3ce44SJohn Forte 
2287fcf3ce44SJohn Forte 				if (wcsncmp(tmpTargetAddress,
2288fcf3ce44SJohn Forte 				    staticTargetAddress,
2289fcf3ce44SJohn Forte 				    SUN_IMA_IP_ADDRESS_PORT_LEN)
2290fcf3ce44SJohn Forte 				    == 0 &&
2291fcf3ce44SJohn Forte 				    staticTargetProps.
2292fcf3ce44SJohn Forte 				    staticTarget.targetAddress.
2293fcf3ce44SJohn Forte 				    imaStruct.portNumber == port) {
2294fcf3ce44SJohn Forte 					/*
2295fcf3ce44SJohn Forte 					 * Since an object is
2296fcf3ce44SJohn Forte 					 * specified, it should also
2297fcf3ce44SJohn Forte 					 * have a tpgt specified. If
2298fcf3ce44SJohn Forte 					 * not, that means the object
2299fcf3ce44SJohn Forte 					 * specified is associated with
2300fcf3ce44SJohn Forte 					 * the default tpgt. In
2301fcf3ce44SJohn Forte 					 * either case, a tpgt
2302fcf3ce44SJohn Forte 					 * comparison should be done
2303fcf3ce44SJohn Forte 					 * before claiming that a
2304fcf3ce44SJohn Forte 					 * match is found.
2305fcf3ce44SJohn Forte 					 */
2306fcf3ce44SJohn Forte 					if ((tpgt == stpgt &&
2307fcf3ce44SJohn Forte 					    tpgtSpecified == B_TRUE &&
2308fcf3ce44SJohn Forte 					    defaultTpgt == IMA_FALSE) ||
2309fcf3ce44SJohn Forte 					    (tpgt == stpgt &&
2310fcf3ce44SJohn Forte 					    tpgtSpecified == B_FALSE &&
2311fcf3ce44SJohn Forte 					    defaultTpgt == IMA_TRUE)) {
2312fcf3ce44SJohn Forte 						matched = B_TRUE;
2313fcf3ce44SJohn Forte 					}
2314fcf3ce44SJohn Forte 				}
2315fcf3ce44SJohn Forte 
2316fcf3ce44SJohn Forte 				}
2317fcf3ce44SJohn Forte 			}
2318fcf3ce44SJohn Forte 
2319fcf3ce44SJohn Forte 			if (!object || matched) {
2320fcf3ce44SJohn Forte 				/* print summary - always */
2321fcf3ce44SJohn Forte 				(void) fprintf(stdout, gettext("%s: %ws,"),
2322fcf3ce44SJohn Forte 				    "Static Configuration Target",
2323fcf3ce44SJohn Forte 				    staticTargetProps.staticTarget.targetName);
2324fcf3ce44SJohn Forte 
2325fcf3ce44SJohn Forte 				if (isIpv6 == B_FALSE) {
2326fcf3ce44SJohn Forte 					(void) inet_ntop(AF_INET,
2327fcf3ce44SJohn Forte 					    staticTargetProps.
2328fcf3ce44SJohn Forte 					    staticTarget.targetAddress.
2329fcf3ce44SJohn Forte 					    imaStruct.hostnameIpAddress.id.
2330fcf3ce44SJohn Forte 					    ipAddress.ipAddress, sAddr,
2331fcf3ce44SJohn Forte 					    sizeof (sAddr));
2332fcf3ce44SJohn Forte 					(void) fprintf(stdout, "%s:%d",
2333fcf3ce44SJohn Forte 					    sAddr,
2334fcf3ce44SJohn Forte 					    staticTargetProps.staticTarget.
2335fcf3ce44SJohn Forte 					    targetAddress.imaStruct.portNumber);
2336fcf3ce44SJohn Forte 				} else {
2337fcf3ce44SJohn Forte 					(void) inet_ntop(AF_INET6,
2338fcf3ce44SJohn Forte 					    staticTargetProps.
2339fcf3ce44SJohn Forte 					    staticTarget.targetAddress.
2340fcf3ce44SJohn Forte 					    imaStruct.hostnameIpAddress.id.
2341fcf3ce44SJohn Forte 					    ipAddress.ipAddress, sAddr,
2342fcf3ce44SJohn Forte 					    sizeof (sAddr));
2343fcf3ce44SJohn Forte 					(void) fprintf(stdout, "[%s]:%d",
2344fcf3ce44SJohn Forte 					    sAddr,
2345fcf3ce44SJohn Forte 					    staticTargetProps.staticTarget.
2346fcf3ce44SJohn Forte 					    targetAddress.imaStruct.portNumber);
2347fcf3ce44SJohn Forte 				}
2348fcf3ce44SJohn Forte 
2349fcf3ce44SJohn Forte 				if (staticTargetProps.staticTarget.
2350fcf3ce44SJohn Forte 				    targetAddress.
2351fcf3ce44SJohn Forte 				    defaultTpgt == IMA_FALSE) {
2352fcf3ce44SJohn Forte 					(void) fprintf(stdout, ",%d\n",
2353fcf3ce44SJohn Forte 					    staticTargetProps.
2354fcf3ce44SJohn Forte 					    staticTarget.targetAddress.tpgt);
2355fcf3ce44SJohn Forte 				} else {
2356fcf3ce44SJohn Forte 					(void) fprintf(stdout, "\n");
2357fcf3ce44SJohn Forte 				}
2358fcf3ce44SJohn Forte 			}
2359fcf3ce44SJohn Forte 
2360fcf3ce44SJohn Forte 		}
2361fcf3ce44SJohn Forte 		/*
2362fcf3ce44SJohn Forte 		 * No details to display, but if there were:
2363fcf3ce44SJohn Forte 		 *  if (object && found)...
2364fcf3ce44SJohn Forte 		 *
2365fcf3ce44SJohn Forte 		 */
2366fcf3ce44SJohn Forte 
2367fcf3ce44SJohn Forte 		/*
2368fcf3ce44SJohn Forte 		 * There was an object entered but we didn't
2369fcf3ce44SJohn Forte 		 * find it.
2370fcf3ce44SJohn Forte 		 */
2371fcf3ce44SJohn Forte 		if (object && !found) {
2372fcf3ce44SJohn Forte 			(void) fprintf(stdout, "%s: %s\n",
2373fcf3ce44SJohn Forte 			    operand[i], gettext("not found"));
2374fcf3ce44SJohn Forte 			ret = 1; /* DIY test fix */
2375fcf3ce44SJohn Forte 		}
2376fcf3ce44SJohn Forte 	}
2377fcf3ce44SJohn Forte 	return (ret);
2378fcf3ce44SJohn Forte }
2379fcf3ce44SJohn Forte 
2380fcf3ce44SJohn Forte /*
2381fcf3ce44SJohn Forte  * Print targets
2382fcf3ce44SJohn Forte  */
2383fcf3ce44SJohn Forte /*ARGSUSED*/
2384fcf3ce44SJohn Forte static int
listTarget(int objectLen,char * objects[],cmdOptions_t * options,int * funcRet)2385fcf3ce44SJohn Forte listTarget(int objectLen, char *objects[], cmdOptions_t *options, int *funcRet)
2386fcf3ce44SJohn Forte {
2387fcf3ce44SJohn Forte 	IMA_OID	initiatorOid;
2388fcf3ce44SJohn Forte 	IMA_OID_LIST *targetList;
2389fcf3ce44SJohn Forte 	IMA_OID_LIST *lunList;
2390fcf3ce44SJohn Forte 	SUN_IMA_TARGET_PROPERTIES targetProps;
2391fcf3ce44SJohn Forte 	IMA_STATUS status;
2392fcf3ce44SJohn Forte 	IMA_OID_LIST *pConnList;
2393fcf3ce44SJohn Forte 	SUN_IMA_CONN_PROPERTIES *connProps;
2394fcf3ce44SJohn Forte 
2395fcf3ce44SJohn Forte 	int ret;
2396fcf3ce44SJohn Forte 	wchar_t targetName[MAX_ISCSI_NAME_LEN + 1];
2397fcf3ce44SJohn Forte 	wchar_t targetAddress[SUN_IMA_IP_ADDRESS_PORT_LEN];
2398fcf3ce44SJohn Forte 	int outerLoop;
2399fcf3ce44SJohn Forte 	boolean_t found;
2400fcf3ce44SJohn Forte 	boolean_t operandEntered = B_FALSE;
2401fcf3ce44SJohn Forte 	boolean_t verbose = B_FALSE;
2402fcf3ce44SJohn Forte 	boolean_t scsi_target = B_FALSE;
2403fcf3ce44SJohn Forte 	boolean_t targetAddressSpecified = B_FALSE;
2404fcf3ce44SJohn Forte 	boolean_t isIpv6 = B_FALSE;
2405fcf3ce44SJohn Forte 	int i, j;
2406fcf3ce44SJohn Forte 	cmdOptions_t *optionList = options;
2407fcf3ce44SJohn Forte 	boolean_t tpgtSpecified = B_FALSE;
2408fcf3ce44SJohn Forte 	IMA_UINT16 port = 0;
2409fcf3ce44SJohn Forte 	uint16_t tpgt;
2410fcf3ce44SJohn Forte 
2411fcf3ce44SJohn Forte 	assert(funcRet != NULL);
2412fcf3ce44SJohn Forte 
2413fcf3ce44SJohn Forte 	/* Find Sun initiator */
2414fcf3ce44SJohn Forte 	ret = sunInitiatorFind(&initiatorOid);
2415fcf3ce44SJohn Forte 	if (ret > 0) {
2416fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n",
2417fcf3ce44SJohn Forte 		    cmdName, gettext("no initiator found"));
2418fcf3ce44SJohn Forte 	}
2419fcf3ce44SJohn Forte 
2420fcf3ce44SJohn Forte 	if (ret != 0) {
2421fcf3ce44SJohn Forte 		return (ret);
2422fcf3ce44SJohn Forte 	}
2423fcf3ce44SJohn Forte 
2424fcf3ce44SJohn Forte 	for (; optionList->optval; optionList++) {
2425fcf3ce44SJohn Forte 		switch (optionList->optval) {
2426fcf3ce44SJohn Forte 			case 'S':
2427fcf3ce44SJohn Forte 				scsi_target = B_TRUE;
2428fcf3ce44SJohn Forte 				break;
2429fcf3ce44SJohn Forte 			case 'v':
2430fcf3ce44SJohn Forte 				verbose = B_TRUE;
2431fcf3ce44SJohn Forte 				break;
2432fcf3ce44SJohn Forte 			default:
2433fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %c: %s\n",
2434fcf3ce44SJohn Forte 				    cmdName, optionList->optval,
2435fcf3ce44SJohn Forte 				    gettext("unknown option"));
2436fcf3ce44SJohn Forte 				return (1);
2437fcf3ce44SJohn Forte 		}
2438fcf3ce44SJohn Forte 	}
2439fcf3ce44SJohn Forte 
2440fcf3ce44SJohn Forte 	/*
2441fcf3ce44SJohn Forte 	 * If there are multiple objects, execute outer 'for' loop that
2442fcf3ce44SJohn Forte 	 * many times for each target detail, otherwise, execute it only
2443fcf3ce44SJohn Forte 	 * once with summaries only
2444fcf3ce44SJohn Forte 	 */
2445fcf3ce44SJohn Forte 	if (objectLen > 0) {
2446fcf3ce44SJohn Forte 		operandEntered = B_TRUE;
2447fcf3ce44SJohn Forte 		outerLoop = objectLen;
2448fcf3ce44SJohn Forte 	} else {
2449fcf3ce44SJohn Forte 		operandEntered = B_FALSE;
2450fcf3ce44SJohn Forte 		outerLoop = 1;
2451fcf3ce44SJohn Forte 	}
2452fcf3ce44SJohn Forte 
2453fcf3ce44SJohn Forte 	status = SUN_IMA_GetSessionOidList(initiatorOid, &targetList);
2454fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
2455fcf3ce44SJohn Forte 		printLibError(status);
2456fcf3ce44SJohn Forte 		*funcRet = 1;
2457fcf3ce44SJohn Forte 		return (ret);
2458fcf3ce44SJohn Forte 	}
2459fcf3ce44SJohn Forte 
2460fcf3ce44SJohn Forte 	for (i = 0; i < outerLoop; i++) {
2461fcf3ce44SJohn Forte 
2462fcf3ce44SJohn Forte 		tpgtSpecified = B_FALSE;
2463fcf3ce44SJohn Forte 		if (operandEntered) {
2464fcf3ce44SJohn Forte 			if (parseTarget(objects[i],
2465fcf3ce44SJohn Forte 			    &targetName[0],
2466fcf3ce44SJohn Forte 			    MAX_ISCSI_NAME_LEN + 1,
2467fcf3ce44SJohn Forte 			    &targetAddressSpecified,
2468fcf3ce44SJohn Forte 			    &targetAddress[0],
2469fcf3ce44SJohn Forte 			    SUN_IMA_IP_ADDRESS_PORT_LEN,
2470fcf3ce44SJohn Forte 			    &port,
2471fcf3ce44SJohn Forte 			    &tpgtSpecified,
2472fcf3ce44SJohn Forte 			    &tpgt,
2473fcf3ce44SJohn Forte 			    &isIpv6) != PARSE_TARGET_OK) {
2474fcf3ce44SJohn Forte 				ret = 1;
2475fcf3ce44SJohn Forte 				continue;
2476fcf3ce44SJohn Forte 			}
2477fcf3ce44SJohn Forte 		}
2478fcf3ce44SJohn Forte 		for (found = B_FALSE, j = 0; j < targetList->oidCount; j++) {
2479fcf3ce44SJohn Forte 			status = SUN_IMA_GetTargetProperties(
2480fcf3ce44SJohn Forte 			    targetList->oids[j],
2481fcf3ce44SJohn Forte 			    &targetProps);
2482fcf3ce44SJohn Forte 			if (!IMA_SUCCESS(status)) {
2483fcf3ce44SJohn Forte 				printLibError(status);
2484fcf3ce44SJohn Forte 				(void) IMA_FreeMemory(targetList);
2485fcf3ce44SJohn Forte 				*funcRet = 1;
2486fcf3ce44SJohn Forte 				return (ret);
2487fcf3ce44SJohn Forte 			}
2488fcf3ce44SJohn Forte 
2489fcf3ce44SJohn Forte 			/*
2490fcf3ce44SJohn Forte 			 * Compare the target name with the input if
2491fcf3ce44SJohn Forte 			 * one was input, if they match, print the target's info
2492fcf3ce44SJohn Forte 			 *
2493fcf3ce44SJohn Forte 			 * if no target name was input, continue printing this
2494fcf3ce44SJohn Forte 			 * target
2495fcf3ce44SJohn Forte 			 */
2496fcf3ce44SJohn Forte 			if (operandEntered) {
2497fcf3ce44SJohn Forte 				if (targetNamesEqual(targetProps.imaProps.name,
2498fcf3ce44SJohn Forte 				    targetName) == B_TRUE) {
2499fcf3ce44SJohn Forte 					if (tpgtSpecified == B_TRUE) {
2500fcf3ce44SJohn Forte 						if (targetProps.
2501fcf3ce44SJohn Forte 						    defaultTpgtConf ==
2502fcf3ce44SJohn Forte 						    IMA_FALSE &&
2503fcf3ce44SJohn Forte 						    targetProps.
2504fcf3ce44SJohn Forte 						    tpgtConf == tpgt) {
2505fcf3ce44SJohn Forte 							found = B_TRUE;
2506fcf3ce44SJohn Forte 						} else {
2507fcf3ce44SJohn Forte 							/*
2508fcf3ce44SJohn Forte 							 * tpgt does not match,
2509fcf3ce44SJohn Forte 							 * move on to next
2510fcf3ce44SJohn Forte 							 * target
2511fcf3ce44SJohn Forte 							 */
2512fcf3ce44SJohn Forte 							continue;
2513fcf3ce44SJohn Forte 						}
2514fcf3ce44SJohn Forte 					} else {
2515fcf3ce44SJohn Forte 						found = B_TRUE;
2516fcf3ce44SJohn Forte 					}
2517fcf3ce44SJohn Forte 				} else {
2518fcf3ce44SJohn Forte 					/*
2519fcf3ce44SJohn Forte 					 * target name does not match, move on
2520fcf3ce44SJohn Forte 					 * to next target
2521fcf3ce44SJohn Forte 					 */
2522fcf3ce44SJohn Forte 					continue;
2523fcf3ce44SJohn Forte 				}
2524fcf3ce44SJohn Forte 			}
2525fcf3ce44SJohn Forte 
2526fcf3ce44SJohn Forte 			/* print summary - always */
2527fcf3ce44SJohn Forte 			(void) fprintf(stdout, gettext("%s: %ws\n"),
2528fcf3ce44SJohn Forte 			    gettext("Target"), targetProps.imaProps.name);
2529fcf3ce44SJohn Forte 
2530fcf3ce44SJohn Forte 			/* Alias */
2531fcf3ce44SJohn Forte 			(void) fprintf(stdout, "\t%s: ", gettext("Alias"));
2532fcf3ce44SJohn Forte 			if (wslen(targetProps.imaProps.alias) > (size_t)0) {
2533fcf3ce44SJohn Forte 				(void) fprintf(stdout, gettext("%ws\n"),
2534fcf3ce44SJohn Forte 				    targetProps.imaProps.alias);
2535fcf3ce44SJohn Forte 			} else {
2536fcf3ce44SJohn Forte 				(void) fprintf(stdout, "%s\n", "-");
2537fcf3ce44SJohn Forte 			}
2538fcf3ce44SJohn Forte 
2539fcf3ce44SJohn Forte 			if (targetProps.defaultTpgtNego != IMA_TRUE) {
2540fcf3ce44SJohn Forte 				(void) fprintf(stdout, "%s%s: %d\n",
2541fcf3ce44SJohn Forte 				    "\t", gettext("TPGT"),
2542fcf3ce44SJohn Forte 				    targetProps.tpgtNego);
2543fcf3ce44SJohn Forte 			} else if (targetProps.defaultTpgtConf != IMA_TRUE) {
2544fcf3ce44SJohn Forte 				(void) fprintf(stdout, "%s%s: %d\n",
2545fcf3ce44SJohn Forte 				    "\t", gettext("TPGT"),
2546fcf3ce44SJohn Forte 				    targetProps.tpgtConf);
2547fcf3ce44SJohn Forte 			}
2548fcf3ce44SJohn Forte 
2549fcf3ce44SJohn Forte 			(void) fprintf(stdout,
2550fcf3ce44SJohn Forte 			    "%s%s: %02x%02x%02x%02x%02x%02x\n",
2551fcf3ce44SJohn Forte 			    "\t", gettext("ISID"),
2552fcf3ce44SJohn Forte 			    targetProps.isid[0], targetProps.isid[1],
2553fcf3ce44SJohn Forte 			    targetProps.isid[2], targetProps.isid[3],
2554fcf3ce44SJohn Forte 			    targetProps.isid[4], targetProps.isid[5]);
2555fcf3ce44SJohn Forte 
2556fcf3ce44SJohn Forte 			pConnList = NULL;
2557fcf3ce44SJohn Forte 			status = SUN_IMA_GetConnOidList(
2558fcf3ce44SJohn Forte 			    &targetList->oids[j],
2559fcf3ce44SJohn Forte 			    &pConnList);
2560fcf3ce44SJohn Forte 
2561fcf3ce44SJohn Forte 			if (!IMA_SUCCESS(status)) {
2562fcf3ce44SJohn Forte 				printLibError(status);
2563fcf3ce44SJohn Forte 				(void) IMA_FreeMemory(targetList);
2564fcf3ce44SJohn Forte 				*funcRet = 1;
2565fcf3ce44SJohn Forte 				return (ret);
2566fcf3ce44SJohn Forte 			}
2567fcf3ce44SJohn Forte 
2568fcf3ce44SJohn Forte 			(void) fprintf(stdout, "%s%s: %lu\n",
2569fcf3ce44SJohn Forte 			    "\t",
2570fcf3ce44SJohn Forte 			    gettext("Connections"),
2571fcf3ce44SJohn Forte 			    pConnList->oidCount);
2572fcf3ce44SJohn Forte 
2573fcf3ce44SJohn Forte 			if (verbose) {
2574fcf3ce44SJohn Forte 				SUN_IMA_DIGEST_ALGORITHM_VALUE digestAlgorithms;
2575fcf3ce44SJohn Forte 
2576fcf3ce44SJohn Forte 				printConnectionList("\t\t", pConnList);
2577fcf3ce44SJohn Forte 				printDiscoveryMethod(
2578fcf3ce44SJohn Forte 				    "\t\t  ",
2579fcf3ce44SJohn Forte 				    targetProps.imaProps.discoveryMethodFlags);
2580fcf3ce44SJohn Forte 				(void) printLoginParameters(
2581fcf3ce44SJohn Forte 				    "\t\t  ",
2582fcf3ce44SJohn Forte 				    targetList->oids[j],
2583fcf3ce44SJohn Forte 				    PRINT_NEGOTIATED_PARAMS);
2584fcf3ce44SJohn Forte 
2585fcf3ce44SJohn Forte 				/* Get Digest configuration */
2586fcf3ce44SJohn Forte 				status = SUN_IMA_GetConnProperties(
2587fcf3ce44SJohn Forte 				    &pConnList->oids[0], &connProps);
2588fcf3ce44SJohn Forte 
2589fcf3ce44SJohn Forte 				(void) getNegotiatedDigest(
2590fcf3ce44SJohn Forte 				    ISCSI_LOGIN_PARAM_HEADER_DIGEST,
2591fcf3ce44SJohn Forte 				    &digestAlgorithms, connProps);
2592fcf3ce44SJohn Forte 
2593fcf3ce44SJohn Forte 				if (IMA_SUCCESS(status)) {
2594fcf3ce44SJohn Forte 					(void) fprintf(stdout, "\t\t  \t%s: ",
2595fcf3ce44SJohn Forte 					    gettext("Header Digest"));
2596fcf3ce44SJohn Forte 					printDigestAlgorithm(
2597fcf3ce44SJohn Forte 					    &digestAlgorithms,
2598fcf3ce44SJohn Forte 					    PRINT_NEGOTIATED_PARAMS);
2599fcf3ce44SJohn Forte 				} else {
2600fcf3ce44SJohn Forte 					(void) IMA_FreeMemory(pConnList);
2601fcf3ce44SJohn Forte 					(void) IMA_FreeMemory(targetList);
2602fcf3ce44SJohn Forte 					printLibError(status);
2603fcf3ce44SJohn Forte 					*funcRet = 1;
2604fcf3ce44SJohn Forte 					return (ret);
2605fcf3ce44SJohn Forte 				}
2606fcf3ce44SJohn Forte 
2607fcf3ce44SJohn Forte 				(void) getNegotiatedDigest(
2608fcf3ce44SJohn Forte 				    ISCSI_LOGIN_PARAM_DATA_DIGEST,
2609fcf3ce44SJohn Forte 				    &digestAlgorithms, connProps);
2610fcf3ce44SJohn Forte 
2611fcf3ce44SJohn Forte 				if (IMA_SUCCESS(status)) {
2612fcf3ce44SJohn Forte 					(void) fprintf(stdout, "\t\t  \t%s: ",
2613fcf3ce44SJohn Forte 					    gettext("Data Digest"));
2614fcf3ce44SJohn Forte 					printDigestAlgorithm(
2615fcf3ce44SJohn Forte 					    &digestAlgorithms,
2616fcf3ce44SJohn Forte 					    PRINT_NEGOTIATED_PARAMS);
2617fcf3ce44SJohn Forte 				} else {
2618fcf3ce44SJohn Forte 					(void) IMA_FreeMemory(pConnList);
2619fcf3ce44SJohn Forte 					(void) IMA_FreeMemory(targetList);
2620fcf3ce44SJohn Forte 					printLibError(status);
2621fcf3ce44SJohn Forte 					*funcRet = 1;
2622fcf3ce44SJohn Forte 					return (ret);
2623fcf3ce44SJohn Forte 				}
2624fcf3ce44SJohn Forte 
2625fcf3ce44SJohn Forte 				(void) fprintf(stdout, "\n");
2626fcf3ce44SJohn Forte 			}
2627fcf3ce44SJohn Forte 
2628fcf3ce44SJohn Forte 			if (scsi_target) {
2629904e51f6SJack Meng 				status = SUN_IMA_ReEnumeration(
2630904e51f6SJack Meng 				    targetList->oids[j]);
2631904e51f6SJack Meng 				if (!IMA_SUCCESS(status)) {
2632904e51f6SJack Meng 					/*
2633904e51f6SJack Meng 					 * Proceeds the listing
2634904e51f6SJack Meng 					 * but indicates the
2635904e51f6SJack Meng 					 * error in return value
2636904e51f6SJack Meng 					 */
2637904e51f6SJack Meng 					ret = 1;
2638904e51f6SJack Meng 				}
2639904e51f6SJack Meng 
2640fcf3ce44SJohn Forte 				status = IMA_GetLuOidList(
2641fcf3ce44SJohn Forte 				    targetList->oids[j],
2642fcf3ce44SJohn Forte 				    &lunList);
2643fcf3ce44SJohn Forte 				if (!IMA_SUCCESS(status)) {
2644fcf3ce44SJohn Forte 					printLibError(status);
2645fcf3ce44SJohn Forte 					(void) IMA_FreeMemory(targetList);
2646fcf3ce44SJohn Forte 					*funcRet = 1;
2647fcf3ce44SJohn Forte 					return (ret);
2648fcf3ce44SJohn Forte 				}
2649fcf3ce44SJohn Forte 				if (lunList->oidCount != 0) {
2650fcf3ce44SJohn Forte 					printTargetLuns(lunList);
2651fcf3ce44SJohn Forte 				}
2652fcf3ce44SJohn Forte 				(void) fprintf(stdout, "\n");
2653fcf3ce44SJohn Forte 				(void) IMA_FreeMemory(lunList);
2654fcf3ce44SJohn Forte 			}
2655fcf3ce44SJohn Forte 		}
2656fcf3ce44SJohn Forte 		/*
2657fcf3ce44SJohn Forte 		 * did we find the object
2658fcf3ce44SJohn Forte 		 */
2659fcf3ce44SJohn Forte 
2660fcf3ce44SJohn Forte 		if (operandEntered && !found) {
2661fcf3ce44SJohn Forte 			(void) fprintf(stdout, "%s: %s\n",
2662fcf3ce44SJohn Forte 			    objects[i], gettext("not found"));
2663fcf3ce44SJohn Forte 		}
2664fcf3ce44SJohn Forte 	}
2665fcf3ce44SJohn Forte 
2666fcf3ce44SJohn Forte 	(void) IMA_FreeMemory(targetList);
2667fcf3ce44SJohn Forte 	return (ret);
2668fcf3ce44SJohn Forte }
2669fcf3ce44SJohn Forte 
2670fcf3ce44SJohn Forte 
2671fcf3ce44SJohn Forte /*
2672fcf3ce44SJohn Forte  * Print configured session information
2673fcf3ce44SJohn Forte  */
2674fcf3ce44SJohn Forte static int
printConfiguredSessions(IMA_OID oid)2675fcf3ce44SJohn Forte printConfiguredSessions(IMA_OID oid)
2676fcf3ce44SJohn Forte {
2677fcf3ce44SJohn Forte 	IMA_STATUS		status;
2678fcf3ce44SJohn Forte 	const char		*rtn;
2679fcf3ce44SJohn Forte 	SUN_IMA_CONFIG_SESSIONS	*pConfigSessions;
2680fcf3ce44SJohn Forte 	char			address[MAX_ADDRESS_LEN];
2681fcf3ce44SJohn Forte 	int			out;
2682fcf3ce44SJohn Forte 
2683fcf3ce44SJohn Forte 	/* Get configured session information */
2684fcf3ce44SJohn Forte 	status = SUN_IMA_GetConfigSessions(oid, &pConfigSessions);
2685fcf3ce44SJohn Forte 
2686fcf3ce44SJohn Forte 	if (IMA_SUCCESS(status)) {
2687fcf3ce44SJohn Forte 		(void) fprintf(stdout, "\t%s: ",
2688fcf3ce44SJohn Forte 		    gettext("Configured Sessions"));
2689fcf3ce44SJohn Forte 		if (pConfigSessions->bound == IMA_FALSE) {
2690fcf3ce44SJohn Forte 			/* default binding */
2691fcf3ce44SJohn Forte 			(void) fprintf(stdout, "%lu\n", pConfigSessions->out);
2692fcf3ce44SJohn Forte 		} else {
2693fcf3ce44SJohn Forte 			/* hardcoded binding */
2694fcf3ce44SJohn Forte 			for (out = 0;
2695fcf3ce44SJohn Forte 			    out < pConfigSessions->out; out++) {
2696fcf3ce44SJohn Forte 				if (pConfigSessions->bindings[out].
2697fcf3ce44SJohn Forte 				    ipAddress.ipv4Address == IMA_TRUE) {
2698fcf3ce44SJohn Forte 					rtn = inet_ntop(AF_INET,
2699fcf3ce44SJohn Forte 					    pConfigSessions->bindings[out].
2700fcf3ce44SJohn Forte 					    ipAddress.ipAddress, address,
2701fcf3ce44SJohn Forte 					    MAX_ADDRESS_LEN);
2702fcf3ce44SJohn Forte 				} else {
2703fcf3ce44SJohn Forte 					rtn = inet_ntop(AF_INET6,
2704fcf3ce44SJohn Forte 					    pConfigSessions->bindings[out].
2705fcf3ce44SJohn Forte 					    ipAddress.ipAddress, address,
2706fcf3ce44SJohn Forte 					    MAX_ADDRESS_LEN);
2707fcf3ce44SJohn Forte 				}
2708fcf3ce44SJohn Forte 				if (rtn != NULL) {
2709fcf3ce44SJohn Forte 					(void) printf("%s ", address);
2710fcf3ce44SJohn Forte 				}
2711fcf3ce44SJohn Forte 			}
2712fcf3ce44SJohn Forte 			(void) fprintf(stdout, "\n");
2713fcf3ce44SJohn Forte 		}
2714fcf3ce44SJohn Forte 	} else {
2715fcf3ce44SJohn Forte 		free(pConfigSessions);
2716fcf3ce44SJohn Forte 		printLibError(status);
2717fcf3ce44SJohn Forte 		return (1);
2718fcf3ce44SJohn Forte 	}
2719fcf3ce44SJohn Forte 
2720fcf3ce44SJohn Forte 	free(pConfigSessions);
2721fcf3ce44SJohn Forte 	return (0);
2722fcf3ce44SJohn Forte }
2723fcf3ce44SJohn Forte 
2724fcf3ce44SJohn Forte /*
2725fcf3ce44SJohn Forte  * Print target parameters
2726fcf3ce44SJohn Forte  */
2727fcf3ce44SJohn Forte static int
listTargetParam(int operandLen,char * operand[],cmdOptions_t * options,int * funcRet)2728fcf3ce44SJohn Forte listTargetParam(int operandLen, char *operand[], cmdOptions_t *options,
2729fcf3ce44SJohn Forte     int *funcRet)
2730fcf3ce44SJohn Forte {
2731fcf3ce44SJohn Forte 	IMA_STATUS status;
2732fcf3ce44SJohn Forte 	IMA_OID	initiatorOid;
2733fcf3ce44SJohn Forte 	IMA_OID_LIST *targetList;
2734fcf3ce44SJohn Forte 	IMA_AUTHMETHOD	methodList[MAX_AUTH_METHODS];
2735fcf3ce44SJohn Forte 	SUN_IMA_TARGET_PROPERTIES targetProps;
2736fcf3ce44SJohn Forte 	IMA_UINT maxEntries = MAX_AUTH_METHODS;
2737fcf3ce44SJohn Forte 	IMA_BOOL bidirAuth;
2738fcf3ce44SJohn Forte 	int ret;
2739fcf3ce44SJohn Forte 	wchar_t targetName[MAX_ISCSI_NAME_LEN + 1];
2740fcf3ce44SJohn Forte 	wchar_t targetAddress[SUN_IMA_IP_ADDRESS_PORT_LEN];
2741fcf3ce44SJohn Forte 	boolean_t operandEntered = B_FALSE;
2742fcf3ce44SJohn Forte 	boolean_t targetAddressSpecified = B_FALSE;
2743fcf3ce44SJohn Forte 	boolean_t printObject = B_FALSE;
2744fcf3ce44SJohn Forte 	boolean_t tpgtSpecified = B_FALSE;
2745fcf3ce44SJohn Forte 	boolean_t isIpv6 = B_FALSE;
2746fcf3ce44SJohn Forte 	int outerLoop;
2747fcf3ce44SJohn Forte 	boolean_t found;
2748fcf3ce44SJohn Forte 	int i, j;
2749fcf3ce44SJohn Forte 	SUN_IMA_DIGEST_ALGORITHM_VALUE digestAlgorithms;
2750fcf3ce44SJohn Forte 	boolean_t verbose = B_FALSE;
2751fcf3ce44SJohn Forte 	cmdOptions_t *optionList = options;
2752fcf3ce44SJohn Forte 	IMA_UINT16 port = 0;
2753fcf3ce44SJohn Forte 	IMA_UINT16 tpgt = 0;
2754fcf3ce44SJohn Forte 
2755fcf3ce44SJohn Forte 	assert(funcRet != NULL);
2756fcf3ce44SJohn Forte 
2757fcf3ce44SJohn Forte 	/* Find Sun initiator */
2758fcf3ce44SJohn Forte 	ret = sunInitiatorFind(&initiatorOid);
2759fcf3ce44SJohn Forte 	if (ret > 0) {
2760fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n",
2761fcf3ce44SJohn Forte 		    cmdName, gettext("no initiator found"));
2762fcf3ce44SJohn Forte 	}
2763fcf3ce44SJohn Forte 
2764fcf3ce44SJohn Forte 	if (ret != 0) {
2765fcf3ce44SJohn Forte 		return (ret);
2766fcf3ce44SJohn Forte 	}
2767fcf3ce44SJohn Forte 
2768fcf3ce44SJohn Forte 	for (; optionList->optval; optionList++) {
2769fcf3ce44SJohn Forte 		switch (optionList->optval) {
2770fcf3ce44SJohn Forte 			case 'v':
2771fcf3ce44SJohn Forte 				verbose = B_TRUE;
2772fcf3ce44SJohn Forte 				break;
2773fcf3ce44SJohn Forte 			default:
2774fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %c: %s\n",
2775fcf3ce44SJohn Forte 				    cmdName, optionList->optval,
2776fcf3ce44SJohn Forte 				    gettext("unknown option"));
2777fcf3ce44SJohn Forte 				return (1);
2778fcf3ce44SJohn Forte 		}
2779fcf3ce44SJohn Forte 	}
2780fcf3ce44SJohn Forte 
2781fcf3ce44SJohn Forte 	/*
2782fcf3ce44SJohn Forte 	 * If there are multiple operands, execute outer 'for' loop that
2783fcf3ce44SJohn Forte 	 * many times to find each target parameter operand entered, otherwise,
2784fcf3ce44SJohn Forte 	 * execute it only once for all target parameters returned.
2785fcf3ce44SJohn Forte 	 */
2786fcf3ce44SJohn Forte 	if (operandLen > 0) {
2787fcf3ce44SJohn Forte 		operandEntered = B_TRUE;
2788fcf3ce44SJohn Forte 		outerLoop = operandLen;
2789fcf3ce44SJohn Forte 	} else {
2790fcf3ce44SJohn Forte 		operandEntered = B_FALSE;
2791fcf3ce44SJohn Forte 		outerLoop = 1;
2792fcf3ce44SJohn Forte 	}
2793fcf3ce44SJohn Forte 
2794fcf3ce44SJohn Forte 	/*
2795fcf3ce44SJohn Forte 	 * Ideally there should be an interface available for obtaining
2796fcf3ce44SJohn Forte 	 * the list of target-param objects. Since the driver currently
2797fcf3ce44SJohn Forte 	 * creates a target OID and the associated session structure when
2798fcf3ce44SJohn Forte 	 * a target-param object is created, we can leverage the target
2799fcf3ce44SJohn Forte 	 * OID list and use it to manage the target-param objects. When
2800fcf3ce44SJohn Forte 	 * we stop creating a session for target-param object in the
2801fcf3ce44SJohn Forte 	 * driver, we will switch to using a different interface to
2802fcf3ce44SJohn Forte 	 * obtain target-param objects.
2803fcf3ce44SJohn Forte 	 */
2804fcf3ce44SJohn Forte 	status = IMA_GetTargetOidList(initiatorOid, &targetList);
2805fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
2806fcf3ce44SJohn Forte 		printLibError(status);
2807fcf3ce44SJohn Forte 		*funcRet = 1;
2808fcf3ce44SJohn Forte 		return (ret);
2809fcf3ce44SJohn Forte 	}
2810fcf3ce44SJohn Forte 
2811fcf3ce44SJohn Forte 	for (i = 0; i < outerLoop; i++) {
2812fcf3ce44SJohn Forte 		if (operandEntered) {
2813fcf3ce44SJohn Forte 			if (parseTarget(operand[i],
2814fcf3ce44SJohn Forte 			    &targetName[0],
2815fcf3ce44SJohn Forte 			    MAX_ISCSI_NAME_LEN + 1,
2816fcf3ce44SJohn Forte 			    &targetAddressSpecified,
2817fcf3ce44SJohn Forte 			    &targetAddress[0],
2818fcf3ce44SJohn Forte 			    SUN_IMA_IP_ADDRESS_PORT_LEN,
2819fcf3ce44SJohn Forte 			    &port,
2820fcf3ce44SJohn Forte 			    &tpgtSpecified,
2821fcf3ce44SJohn Forte 			    &tpgt,
2822fcf3ce44SJohn Forte 			    &isIpv6) != PARSE_TARGET_OK) {
2823fcf3ce44SJohn Forte 				ret = 1;
2824fcf3ce44SJohn Forte 				continue;
2825fcf3ce44SJohn Forte 			}
2826fcf3ce44SJohn Forte 		}
2827fcf3ce44SJohn Forte 		for (j = 0; j < targetList->oidCount; j++) {
2828fcf3ce44SJohn Forte 			found = B_FALSE;
2829fcf3ce44SJohn Forte 			printObject = B_FALSE;
2830fcf3ce44SJohn Forte 			status = SUN_IMA_GetTargetProperties(
2831fcf3ce44SJohn Forte 			    targetList->oids[j],
2832fcf3ce44SJohn Forte 			    &targetProps);
2833fcf3ce44SJohn Forte 			if (!IMA_SUCCESS(status)) {
2834fcf3ce44SJohn Forte 				printLibError(status);
2835fcf3ce44SJohn Forte 				(void) IMA_FreeMemory(targetList);
2836fcf3ce44SJohn Forte 				*funcRet = 1;
2837fcf3ce44SJohn Forte 				return (ret);
2838fcf3ce44SJohn Forte 			}
2839fcf3ce44SJohn Forte 
2840fcf3ce44SJohn Forte 			/*
2841fcf3ce44SJohn Forte 			 * Compare the target name with the input if
2842fcf3ce44SJohn Forte 			 * one was input
2843fcf3ce44SJohn Forte 			 */
2844fcf3ce44SJohn Forte 			if (operandEntered &&
2845fcf3ce44SJohn Forte 			    (targetNamesEqual(targetProps.imaProps.name,
2846fcf3ce44SJohn Forte 			    targetName) == B_TRUE)) {
2847fcf3ce44SJohn Forte 				/*
2848fcf3ce44SJohn Forte 				 * For now, regardless of whether a target
2849fcf3ce44SJohn Forte 				 * address is specified, we return B_TRUE
2850fcf3ce44SJohn Forte 				 * because IMA_TARGET_PROPERTIES does not
2851fcf3ce44SJohn Forte 				 * have a field for specifying address.
2852fcf3ce44SJohn Forte 				 */
2853fcf3ce44SJohn Forte 				found = B_TRUE;
2854fcf3ce44SJohn Forte 			}
2855fcf3ce44SJohn Forte 
2856fcf3ce44SJohn Forte 			/*
2857fcf3ce44SJohn Forte 			 * if no operand was entered OR
2858fcf3ce44SJohn Forte 			 * an operand was entered and it was
2859fcf3ce44SJohn Forte 			 * found, we want to print
2860fcf3ce44SJohn Forte 			 */
2861fcf3ce44SJohn Forte 			if (!operandEntered || found) {
2862fcf3ce44SJohn Forte 				printObject = B_TRUE;
2863fcf3ce44SJohn Forte 			}
2864fcf3ce44SJohn Forte 
2865fcf3ce44SJohn Forte 			if (printObject) {
2866fcf3ce44SJohn Forte 				(void) fprintf(stdout, gettext("%s: %ws\n"),
2867fcf3ce44SJohn Forte 				    gettext("Target"),
2868fcf3ce44SJohn Forte 				    targetProps.imaProps.name);
2869fcf3ce44SJohn Forte 
2870fcf3ce44SJohn Forte 				(void) fprintf(stdout,
2871fcf3ce44SJohn Forte 				    "\t%s: ", gettext("Alias"));
2872fcf3ce44SJohn Forte 				if (wslen(targetProps.imaProps.alias) >
2873fcf3ce44SJohn Forte 				    (size_t)0) {
2874fcf3ce44SJohn Forte 					(void) fprintf(stdout,
2875fcf3ce44SJohn Forte 					    gettext("%ws\n"),
2876fcf3ce44SJohn Forte 					    targetProps.imaProps.alias);
2877fcf3ce44SJohn Forte 				} else {
2878fcf3ce44SJohn Forte 					(void) fprintf(stdout, "%s\n", "-");
2879fcf3ce44SJohn Forte 				}
2880fcf3ce44SJohn Forte 			}
2881fcf3ce44SJohn Forte 
2882fcf3ce44SJohn Forte 			if (printObject && verbose) {
2883fcf3ce44SJohn Forte 				/* Get bidirectional authentication flag */
2884fcf3ce44SJohn Forte 				(void) fprintf(stdout, "\t%s: ",
2885fcf3ce44SJohn Forte 				    gettext("Bi-directional Authentication"));
2886fcf3ce44SJohn Forte 				status = SUN_IMA_GetTargetBidirAuthFlag(
2887fcf3ce44SJohn Forte 				    targetList->oids[j],
2888fcf3ce44SJohn Forte 				    &bidirAuth);
2889fcf3ce44SJohn Forte 				if (IMA_SUCCESS(status)) {
2890fcf3ce44SJohn Forte 					if (bidirAuth == IMA_TRUE) {
2891fcf3ce44SJohn Forte 						(void) fprintf(stdout,
2892fcf3ce44SJohn Forte 						    gettext("enabled"));
2893fcf3ce44SJohn Forte 					} else {
2894fcf3ce44SJohn Forte 						(void) fprintf(stdout,
2895fcf3ce44SJohn Forte 						    gettext("disabled"));
2896fcf3ce44SJohn Forte 					}
2897fcf3ce44SJohn Forte 				} else {
2898fcf3ce44SJohn Forte 					(void) fprintf(stdout,
2899fcf3ce44SJohn Forte 					    gettext("disabled"));
2900fcf3ce44SJohn Forte 				}
2901fcf3ce44SJohn Forte 				(void) fprintf(stdout, "\n");
2902fcf3ce44SJohn Forte 
2903fcf3ce44SJohn Forte 				/* Get authentication type for this target */
2904fcf3ce44SJohn Forte 				status = SUN_IMA_GetTargetAuthMethods(
2905fcf3ce44SJohn Forte 				    initiatorOid,
2906fcf3ce44SJohn Forte 				    targetList->oids[j],
2907fcf3ce44SJohn Forte 				    &maxEntries,
2908fcf3ce44SJohn Forte 				    &methodList[0]);
2909fcf3ce44SJohn Forte 				(void) fprintf(stdout, "\t%s: ",
2910fcf3ce44SJohn Forte 				    gettext("Authentication Type"));
2911fcf3ce44SJohn Forte 				if (!IMA_SUCCESS(status)) {
2912fcf3ce44SJohn Forte 					/*
2913fcf3ce44SJohn Forte 					 * No authentication method define
2914fcf3ce44SJohn Forte 					 * NONE by default.
2915fcf3ce44SJohn Forte 					 */
2916fcf3ce44SJohn Forte 					(void) fprintf(stdout, gettext("NONE"));
2917fcf3ce44SJohn Forte 				} else {
2918fcf3ce44SJohn Forte 					for (i = 0; i < maxEntries; i++) {
2919fcf3ce44SJohn Forte 						if (i > 0) {
2920fcf3ce44SJohn Forte 							(void) fprintf(stdout,
2921fcf3ce44SJohn Forte 							    "|");
2922fcf3ce44SJohn Forte 						}
2923fcf3ce44SJohn Forte 						switch (methodList[i]) {
2924fcf3ce44SJohn Forte 						case IMA_AUTHMETHOD_NONE:
2925fcf3ce44SJohn Forte 							(void) fprintf(stdout,
2926fcf3ce44SJohn Forte 							    gettext("NONE"));
2927fcf3ce44SJohn Forte 							break;
2928fcf3ce44SJohn Forte 
2929fcf3ce44SJohn Forte 						case IMA_AUTHMETHOD_CHAP:
2930fcf3ce44SJohn Forte 							(void) fprintf(stdout,
2931fcf3ce44SJohn Forte 							    gettext("CHAP"));
2932fcf3ce44SJohn Forte 							listCHAPName(
2933fcf3ce44SJohn Forte 							    targetList->
2934fcf3ce44SJohn Forte 							    oids[j]);
2935fcf3ce44SJohn Forte 							break;
2936fcf3ce44SJohn Forte 
2937fcf3ce44SJohn Forte 						default:
2938fcf3ce44SJohn Forte 							(void) fprintf(stdout,
2939fcf3ce44SJohn Forte 							    gettext(
2940fcf3ce44SJohn Forte 							    "unknown "
2941fcf3ce44SJohn Forte 							    "type"));
2942fcf3ce44SJohn Forte 							break;
2943fcf3ce44SJohn Forte 						}
2944fcf3ce44SJohn Forte 					}
2945fcf3ce44SJohn Forte 				}
2946fcf3ce44SJohn Forte 				(void) fprintf(stdout, "\n");
2947fcf3ce44SJohn Forte 				if (printLoginParameters("\t",
2948fcf3ce44SJohn Forte 				    targetList->oids[j],
2949fcf3ce44SJohn Forte 				    PRINT_CONFIGURED_PARAMS)
2950fcf3ce44SJohn Forte 				    != 0) {
2951fcf3ce44SJohn Forte 					(void) IMA_FreeMemory(targetList);
2952fcf3ce44SJohn Forte 					*funcRet = 1;
2953fcf3ce44SJohn Forte 					return (ret);
2954fcf3ce44SJohn Forte 				}
2955fcf3ce44SJohn Forte 
2956fcf3ce44SJohn Forte 				/* Get Digest configuration */
2957fcf3ce44SJohn Forte 				status = SUN_IMA_GetHeaderDigest(
2958fcf3ce44SJohn Forte 				    targetList->oids[j],
2959fcf3ce44SJohn Forte 				    &digestAlgorithms);
2960fcf3ce44SJohn Forte 				if (IMA_SUCCESS(status)) {
2961fcf3ce44SJohn Forte 					(void) fprintf(stdout, "\t\t%s: ",
2962fcf3ce44SJohn Forte 					    gettext("Header Digest"));
2963fcf3ce44SJohn Forte 					printDigestAlgorithm(&digestAlgorithms,
2964fcf3ce44SJohn Forte 					    PRINT_CONFIGURED_PARAMS);
2965fcf3ce44SJohn Forte 				} else {
2966fcf3ce44SJohn Forte 					printLibError(status);
2967fcf3ce44SJohn Forte 					*funcRet = 1;
2968fcf3ce44SJohn Forte 					return (ret);
2969fcf3ce44SJohn Forte 				}
2970fcf3ce44SJohn Forte 
2971fcf3ce44SJohn Forte 				status = SUN_IMA_GetDataDigest(
2972fcf3ce44SJohn Forte 				    targetList->oids[j],
2973fcf3ce44SJohn Forte 				    &digestAlgorithms);
2974fcf3ce44SJohn Forte 				if (IMA_SUCCESS(status)) {
2975fcf3ce44SJohn Forte 					(void) fprintf(stdout, "\t\t%s: ",
2976fcf3ce44SJohn Forte 					    gettext("Data Digest"));
2977fcf3ce44SJohn Forte 					printDigestAlgorithm(&digestAlgorithms,
2978fcf3ce44SJohn Forte 					    PRINT_CONFIGURED_PARAMS);
2979fcf3ce44SJohn Forte 				} else {
2980fcf3ce44SJohn Forte 					printLibError(status);
2981fcf3ce44SJohn Forte 					*funcRet = 1;
2982fcf3ce44SJohn Forte 					return (ret);
2983fcf3ce44SJohn Forte 				}
2984fcf3ce44SJohn Forte 
2985aff4bce5Syi zhang - Sun Microsystems - Beijing China 				/* print tunable parameters infomation */
2986aff4bce5Syi zhang - Sun Microsystems - Beijing China 				if (printTunableParameters(
2987aff4bce5Syi zhang - Sun Microsystems - Beijing China 				    targetList->oids[j]) != 0) {
2988aff4bce5Syi zhang - Sun Microsystems - Beijing China 					*funcRet = 1;
2989aff4bce5Syi zhang - Sun Microsystems - Beijing China 					return (ret);
2990aff4bce5Syi zhang - Sun Microsystems - Beijing China 				}
2991aff4bce5Syi zhang - Sun Microsystems - Beijing China 
2992fcf3ce44SJohn Forte 				/* print configured session information */
2993fcf3ce44SJohn Forte 				if (printConfiguredSessions(
2994fcf3ce44SJohn Forte 				    targetList->oids[j]) != 0) {
2995fcf3ce44SJohn Forte 					*funcRet = 1;
2996fcf3ce44SJohn Forte 					return (ret);
2997fcf3ce44SJohn Forte 				}
2998fcf3ce44SJohn Forte 
2999fcf3ce44SJohn Forte 				(void) fprintf(stdout, "\n");
3000fcf3ce44SJohn Forte 			}
3001fcf3ce44SJohn Forte 
3002fcf3ce44SJohn Forte 			if (found) {
3003fcf3ce44SJohn Forte 				break;
3004fcf3ce44SJohn Forte 			}
3005fcf3ce44SJohn Forte 		}
3006fcf3ce44SJohn Forte 		if (operandEntered && !found) {
3007fcf3ce44SJohn Forte 			*funcRet = 1; /* DIY message fix */
3008fcf3ce44SJohn Forte 			(void) fprintf(stdout, "%s: %s\n",
3009fcf3ce44SJohn Forte 			    operand[i], gettext("not found"));
3010fcf3ce44SJohn Forte 		}
3011fcf3ce44SJohn Forte 	}
3012fcf3ce44SJohn Forte 
3013fcf3ce44SJohn Forte 	(void) IMA_FreeMemory(targetList);
3014fcf3ce44SJohn Forte 	return (ret);
3015fcf3ce44SJohn Forte }
3016fcf3ce44SJohn Forte 
3017fcf3ce44SJohn Forte /*
3018fcf3ce44SJohn Forte  * Modify discovery attributes
3019fcf3ce44SJohn Forte  */
3020fcf3ce44SJohn Forte static int
modifyDiscovery(cmdOptions_t * options,int * funcRet)3021fcf3ce44SJohn Forte modifyDiscovery(cmdOptions_t *options, int *funcRet)
3022fcf3ce44SJohn Forte {
3023fcf3ce44SJohn Forte 	IMA_OID oid;
3024fcf3ce44SJohn Forte 	IMA_STATUS status;
3025fcf3ce44SJohn Forte 	IMA_BOOL setDiscovery;
3026fcf3ce44SJohn Forte 	IMA_HOST_ID hostId;
3027fcf3ce44SJohn Forte 
3028fcf3ce44SJohn Forte 	int ret;
3029fcf3ce44SJohn Forte 	cmdOptions_t *optionList = options;
3030fcf3ce44SJohn Forte 
3031fcf3ce44SJohn Forte 	assert(funcRet != NULL);
3032fcf3ce44SJohn Forte 
3033fcf3ce44SJohn Forte 	/* Find Sun initiator */
3034fcf3ce44SJohn Forte 	ret = sunInitiatorFind(&oid);
3035fcf3ce44SJohn Forte 	if (ret > 0) {
3036fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n",
3037fcf3ce44SJohn Forte 		    cmdName, gettext("no initiator found"));
3038fcf3ce44SJohn Forte 	}
3039fcf3ce44SJohn Forte 
3040fcf3ce44SJohn Forte 	if (ret != 0) {
3041fcf3ce44SJohn Forte 		return (ret);
3042fcf3ce44SJohn Forte 	}
3043fcf3ce44SJohn Forte 
3044fcf3ce44SJohn Forte 	for (; optionList->optval; optionList++) {
3045fcf3ce44SJohn Forte 		/* check optarg and set bool accordingly */
3046fcf3ce44SJohn Forte 		if (strcasecmp(optionList->optarg, ISCSIADM_ARG_ENABLE) == 0) {
3047fcf3ce44SJohn Forte 			setDiscovery = IMA_TRUE;
3048fcf3ce44SJohn Forte 		} else if (strcasecmp(optionList->optarg, ISCSIADM_ARG_DISABLE)
3049fcf3ce44SJohn Forte 		    == 0) {
3050fcf3ce44SJohn Forte 			setDiscovery = IMA_FALSE;
3051fcf3ce44SJohn Forte 		} else {
3052fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n",
3053fcf3ce44SJohn Forte 			    cmdName, gettext("invalid option argument"));
3054fcf3ce44SJohn Forte 			return (1);
3055fcf3ce44SJohn Forte 		}
3056fcf3ce44SJohn Forte 
3057fcf3ce44SJohn Forte 		switch (optionList->optval) {
3058fcf3ce44SJohn Forte 			case 's':
3059fcf3ce44SJohn Forte 				/* Set static discovery */
3060fcf3ce44SJohn Forte 				status = IMA_SetStaticDiscovery(oid,
3061fcf3ce44SJohn Forte 				    setDiscovery);
3062fcf3ce44SJohn Forte 				if (!IMA_SUCCESS(status)) {
3063fcf3ce44SJohn Forte 					printLibError(status);
3064fcf3ce44SJohn Forte 					*funcRet = 1;
3065fcf3ce44SJohn Forte 					return (ret);
3066fcf3ce44SJohn Forte 				}
3067fcf3ce44SJohn Forte 				break;
3068fcf3ce44SJohn Forte 			case 't':
3069fcf3ce44SJohn Forte 				/* Set send targets discovery */
3070fcf3ce44SJohn Forte 				status = IMA_SetSendTargetsDiscovery(oid,
3071fcf3ce44SJohn Forte 				    setDiscovery);
3072fcf3ce44SJohn Forte 				if (!IMA_SUCCESS(status)) {
3073fcf3ce44SJohn Forte 					printLibError(status);
3074fcf3ce44SJohn Forte 					*funcRet = 1;
3075fcf3ce44SJohn Forte 					return (ret);
3076fcf3ce44SJohn Forte 				}
3077fcf3ce44SJohn Forte 				break;
3078fcf3ce44SJohn Forte 			case 'i':
3079fcf3ce44SJohn Forte 				/* Set iSNS discovery */
3080fcf3ce44SJohn Forte 				(void) memset(&hostId, 0, sizeof (hostId));
3081fcf3ce44SJohn Forte 				status = IMA_SetIsnsDiscovery(oid, setDiscovery,
3082fcf3ce44SJohn Forte 				    IMA_ISNS_DISCOVERY_METHOD_STATIC, &hostId);
3083fcf3ce44SJohn Forte 				if (!IMA_SUCCESS(status)) {
3084fcf3ce44SJohn Forte 					printLibError(status);
3085fcf3ce44SJohn Forte 					*funcRet = 1;
3086fcf3ce44SJohn Forte 					return (ret);
3087fcf3ce44SJohn Forte 				}
3088fcf3ce44SJohn Forte 				break;
3089fcf3ce44SJohn Forte 			default:
3090fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %c: %s\n",
3091fcf3ce44SJohn Forte 				    cmdName, optionList->optval,
3092fcf3ce44SJohn Forte 				    gettext("unknown option"));
3093fcf3ce44SJohn Forte 				return (1);
3094fcf3ce44SJohn Forte 		}
3095fcf3ce44SJohn Forte 	}
3096fcf3ce44SJohn Forte 
3097fcf3ce44SJohn Forte 	return (ret);
3098fcf3ce44SJohn Forte }
3099fcf3ce44SJohn Forte 
3100fcf3ce44SJohn Forte /*
3101fcf3ce44SJohn Forte  * Set the initiator node's authentication method
3102fcf3ce44SJohn Forte  */
3103fcf3ce44SJohn Forte static int
modifyNodeAuthParam(IMA_OID oid,int param,char * chapName,int * funcRet)3104fcf3ce44SJohn Forte modifyNodeAuthParam(IMA_OID oid, int param, char *chapName, int *funcRet)
3105fcf3ce44SJohn Forte {
3106fcf3ce44SJohn Forte 	IMA_INITIATOR_AUTHPARMS authParams;
3107fcf3ce44SJohn Forte 	IMA_STATUS status;
3108fcf3ce44SJohn Forte 	int ret;
3109fcf3ce44SJohn Forte 	int secretLen = MAX_CHAP_SECRET_LEN;
31102e0fe3efSbing zhao - Sun Microsystems - Beijing China 	int nameLen = 0;
3111fcf3ce44SJohn Forte 
3112fcf3ce44SJohn Forte 	IMA_BYTE chapSecret[MAX_CHAP_SECRET_LEN + 1];
3113fcf3ce44SJohn Forte 
3114fcf3ce44SJohn Forte 	assert(funcRet != NULL);
3115fcf3ce44SJohn Forte 
3116fcf3ce44SJohn Forte 	/*
3117fcf3ce44SJohn Forte 	 * Start with existing parameters and modify with the desired change
3118fcf3ce44SJohn Forte 	 * before passing along.  We ignore any failures as they probably
3119fcf3ce44SJohn Forte 	 * are caused by non-existence of auth params for the given node.
3120fcf3ce44SJohn Forte 	 */
3121fcf3ce44SJohn Forte 	status = IMA_GetInitiatorAuthParms(oid, IMA_AUTHMETHOD_CHAP,
3122fcf3ce44SJohn Forte 	    &authParams);
3123fcf3ce44SJohn Forte 
3124fcf3ce44SJohn Forte 	switch (param) {
3125fcf3ce44SJohn Forte 	case AUTH_NAME:
3126fcf3ce44SJohn Forte 		if (chapName == NULL) {
3127fcf3ce44SJohn Forte 			(void) fprintf(stderr, "CHAP name cannot be NULL.\n");
3128fcf3ce44SJohn Forte 			return (1);
3129fcf3ce44SJohn Forte 		}
31302e0fe3efSbing zhao - Sun Microsystems - Beijing China 		nameLen = strlen(chapName);
31312e0fe3efSbing zhao - Sun Microsystems - Beijing China 		if (nameLen == 0) {
3132129b3e6cSJack Meng 			(void) fprintf(stderr, "CHAP name cannot be empty.\n");
3133129b3e6cSJack Meng 			return (1);
3134129b3e6cSJack Meng 		}
31352e0fe3efSbing zhao - Sun Microsystems - Beijing China 		if (nameLen > ISCSI_MAX_C_USER_LEN) {
31362e0fe3efSbing zhao - Sun Microsystems - Beijing China 			(void) fprintf(stderr, "CHAP name is too long.\n");
31372e0fe3efSbing zhao - Sun Microsystems - Beijing China 			return (1);
31382e0fe3efSbing zhao - Sun Microsystems - Beijing China 		}
3139fcf3ce44SJohn Forte 		(void) memset(&authParams.chapParms.name, 0,
3140fcf3ce44SJohn Forte 		    sizeof (authParams.chapParms.name));
3141fcf3ce44SJohn Forte 		(void) memcpy(&authParams.chapParms.name,
31422e0fe3efSbing zhao - Sun Microsystems - Beijing China 		    &chapName[0], nameLen);
31432e0fe3efSbing zhao - Sun Microsystems - Beijing China 		authParams.chapParms.nameLength = nameLen;
3144fcf3ce44SJohn Forte 		break;
3145fcf3ce44SJohn Forte 
3146fcf3ce44SJohn Forte 	case AUTH_PASSWORD :
3147fcf3ce44SJohn Forte 		ret = getSecret((char *)&chapSecret[0], &secretLen,
3148fcf3ce44SJohn Forte 		    MIN_CHAP_SECRET_LEN, MAX_CHAP_SECRET_LEN);
3149fcf3ce44SJohn Forte 
3150fcf3ce44SJohn Forte 		if (ret != 0) {
3151fcf3ce44SJohn Forte 			return (ret);
3152fcf3ce44SJohn Forte 		}
3153fcf3ce44SJohn Forte 
3154fcf3ce44SJohn Forte 		(void) memset(&authParams.chapParms.challengeSecret, 0,
3155fcf3ce44SJohn Forte 		    sizeof (authParams.chapParms.challengeSecret));
3156fcf3ce44SJohn Forte 		(void) memcpy(&authParams.chapParms.challengeSecret,
3157fcf3ce44SJohn Forte 		    &chapSecret[0], secretLen);
3158fcf3ce44SJohn Forte 		authParams.chapParms.challengeSecretLength = secretLen;
3159fcf3ce44SJohn Forte 		break;
3160fcf3ce44SJohn Forte 
3161fcf3ce44SJohn Forte 	default:
3162fcf3ce44SJohn Forte 		(void) fprintf(stderr, "Invalid auth parameter %d\n", param);
3163fcf3ce44SJohn Forte 		return (1);
3164fcf3ce44SJohn Forte 	}
3165fcf3ce44SJohn Forte 
3166fcf3ce44SJohn Forte 	status = IMA_SetInitiatorAuthParms(oid, IMA_AUTHMETHOD_CHAP,
3167fcf3ce44SJohn Forte 	    &authParams);
3168fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
3169fcf3ce44SJohn Forte 		printLibError(status);
3170fcf3ce44SJohn Forte 		*funcRet = 1;
3171fcf3ce44SJohn Forte 	}
3172fcf3ce44SJohn Forte 	return (ret);
3173fcf3ce44SJohn Forte }
3174fcf3ce44SJohn Forte 
3175fcf3ce44SJohn Forte /*
3176fcf3ce44SJohn Forte  * Set the target's authentication method
3177fcf3ce44SJohn Forte  */
3178fcf3ce44SJohn Forte static int
modifyTargetAuthParam(IMA_OID oid,int param,char * chapName,int * funcRet)3179fcf3ce44SJohn Forte modifyTargetAuthParam(IMA_OID oid, int param, char *chapName, int *funcRet)
3180fcf3ce44SJohn Forte {
3181fcf3ce44SJohn Forte 	IMA_INITIATOR_AUTHPARMS authParams;
3182fcf3ce44SJohn Forte 	IMA_STATUS status;
3183fcf3ce44SJohn Forte 	int ret;
3184fcf3ce44SJohn Forte 	int secretLen = MAX_CHAP_SECRET_LEN;
31852e0fe3efSbing zhao - Sun Microsystems - Beijing China 	int nameLen = 0;
3186fcf3ce44SJohn Forte 
3187fcf3ce44SJohn Forte 	IMA_BYTE chapSecret[MAX_CHAP_SECRET_LEN + 1];
3188fcf3ce44SJohn Forte 
3189fcf3ce44SJohn Forte 	assert(funcRet != NULL);
3190fcf3ce44SJohn Forte 
3191fcf3ce44SJohn Forte 	/*
3192fcf3ce44SJohn Forte 	 * Start with existing parameters and modify with the desired change
3193fcf3ce44SJohn Forte 	 * before passing along.  We ignore any get failures as they probably
3194fcf3ce44SJohn Forte 	 * are caused by non-existence of auth params for the given target.
3195fcf3ce44SJohn Forte 	 */
3196fcf3ce44SJohn Forte 	status = SUN_IMA_GetTargetAuthParms(oid, IMA_AUTHMETHOD_CHAP,
3197fcf3ce44SJohn Forte 	    &authParams);
3198fcf3ce44SJohn Forte 
3199fcf3ce44SJohn Forte 	switch (param) {
3200fcf3ce44SJohn Forte 	case AUTH_NAME:
3201fcf3ce44SJohn Forte 		if (chapName == NULL) {
3202fcf3ce44SJohn Forte 			(void) fprintf(stderr, "CHAP name cannot be NULL.\n");
3203fcf3ce44SJohn Forte 			return (1);
3204fcf3ce44SJohn Forte 		}
32052e0fe3efSbing zhao - Sun Microsystems - Beijing China 		nameLen = strlen(chapName);
32062e0fe3efSbing zhao - Sun Microsystems - Beijing China 		if (nameLen == 0) {
3207129b3e6cSJack Meng 			(void) fprintf(stderr, "CHAP name cannot be empty.\n");
3208129b3e6cSJack Meng 			return (1);
3209129b3e6cSJack Meng 		}
32102e0fe3efSbing zhao - Sun Microsystems - Beijing China 		if (nameLen > ISCSI_MAX_C_USER_LEN) {
32112e0fe3efSbing zhao - Sun Microsystems - Beijing China 			(void) fprintf(stderr, "CHAP name is too long.\n");
32122e0fe3efSbing zhao - Sun Microsystems - Beijing China 			return (1);
32132e0fe3efSbing zhao - Sun Microsystems - Beijing China 		}
3214fcf3ce44SJohn Forte 		(void) memset(&authParams.chapParms.name, 0,
3215fcf3ce44SJohn Forte 		    sizeof (authParams.chapParms.name));
3216fcf3ce44SJohn Forte 		(void) memcpy(&authParams.chapParms.name,
32172e0fe3efSbing zhao - Sun Microsystems - Beijing China 		    &chapName[0], nameLen);
32182e0fe3efSbing zhao - Sun Microsystems - Beijing China 		authParams.chapParms.nameLength = nameLen;
3219fcf3ce44SJohn Forte 		break;
3220fcf3ce44SJohn Forte 
3221fcf3ce44SJohn Forte 	case AUTH_PASSWORD :
3222fcf3ce44SJohn Forte 		ret = getSecret((char *)&chapSecret[0], &secretLen,
3223fcf3ce44SJohn Forte 		    1, MAX_CHAP_SECRET_LEN);
3224fcf3ce44SJohn Forte 
3225fcf3ce44SJohn Forte 		if (ret != 0) {
3226fcf3ce44SJohn Forte 			return (ret);
3227fcf3ce44SJohn Forte 		}
3228fcf3ce44SJohn Forte 
3229fcf3ce44SJohn Forte 		(void) memset(&authParams.chapParms.challengeSecret, 0,
3230fcf3ce44SJohn Forte 		    sizeof (authParams.chapParms.challengeSecret));
3231fcf3ce44SJohn Forte 		(void) memcpy(&authParams.chapParms.challengeSecret,
3232fcf3ce44SJohn Forte 		    &chapSecret[0], secretLen);
3233fcf3ce44SJohn Forte 		authParams.chapParms.challengeSecretLength = secretLen;
3234fcf3ce44SJohn Forte 		break;
3235fcf3ce44SJohn Forte 
3236fcf3ce44SJohn Forte 	default:
3237fcf3ce44SJohn Forte 		(void) fprintf(stderr, "Invalid auth parameter %d\n", param);
3238fcf3ce44SJohn Forte 		return (1);
3239fcf3ce44SJohn Forte 	}
3240fcf3ce44SJohn Forte 
3241fcf3ce44SJohn Forte 	status = SUN_IMA_SetTargetAuthParams(oid, IMA_AUTHMETHOD_CHAP,
3242fcf3ce44SJohn Forte 	    &authParams);
3243fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
3244fcf3ce44SJohn Forte 		printLibError(status);
3245fcf3ce44SJohn Forte 		*funcRet = 1;
3246fcf3ce44SJohn Forte 	}
3247fcf3ce44SJohn Forte 	return (0);
3248fcf3ce44SJohn Forte }
3249fcf3ce44SJohn Forte 
3250fcf3ce44SJohn Forte static int
modifyTargetBidirAuthFlag(IMA_OID targetOid,char * optarg,int * funcRet)3251fcf3ce44SJohn Forte modifyTargetBidirAuthFlag(IMA_OID targetOid, char *optarg, int *funcRet)
3252fcf3ce44SJohn Forte {
3253fcf3ce44SJohn Forte 	IMA_BOOL boolValue;
3254fcf3ce44SJohn Forte 	IMA_STATUS status;
3255fcf3ce44SJohn Forte 
3256fcf3ce44SJohn Forte 	assert(funcRet != NULL);
3257fcf3ce44SJohn Forte 
3258fcf3ce44SJohn Forte 	if (strcasecmp(optarg, ISCSIADM_ARG_ENABLE) == 0) {
3259fcf3ce44SJohn Forte 		boolValue = IMA_TRUE;
3260fcf3ce44SJohn Forte 	} else if (strcasecmp(optarg, ISCSIADM_ARG_DISABLE) == 0) {
3261fcf3ce44SJohn Forte 		boolValue = IMA_FALSE;
3262fcf3ce44SJohn Forte 	} else {
3263fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s %s\n",
3264fcf3ce44SJohn Forte 		    cmdName, gettext("invalid option argument"), optarg);
3265fcf3ce44SJohn Forte 		return (1);
3266fcf3ce44SJohn Forte 	}
3267fcf3ce44SJohn Forte 
3268fcf3ce44SJohn Forte 	status = SUN_IMA_SetTargetBidirAuthFlag(targetOid, &boolValue);
3269fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
3270fcf3ce44SJohn Forte 		printLibError(status);
3271fcf3ce44SJohn Forte 		*funcRet = 1;
3272fcf3ce44SJohn Forte 	}
3273fcf3ce44SJohn Forte 	return (0);
3274fcf3ce44SJohn Forte }
3275fcf3ce44SJohn Forte 
3276fcf3ce44SJohn Forte static int
modifyConfiguredSessions(IMA_OID targetOid,char * optarg)3277fcf3ce44SJohn Forte modifyConfiguredSessions(IMA_OID targetOid, char *optarg)
3278fcf3ce44SJohn Forte {
3279fcf3ce44SJohn Forte 	SUN_IMA_CONFIG_SESSIONS *pConfigSessions;
3280fcf3ce44SJohn Forte 	IMA_STATUS		status;
3281fcf3ce44SJohn Forte 	int			sessions;
3282fcf3ce44SJohn Forte 	int			size;
3283fcf3ce44SJohn Forte 	char			tmp[1024];
3284fcf3ce44SJohn Forte 	boolean_t		isIpv6 = B_FALSE;
3285fcf3ce44SJohn Forte 	uint16_t		port;
3286fcf3ce44SJohn Forte 	char			address[MAX_ADDRESS_LEN];
3287fcf3ce44SJohn Forte 	char			*commaPos;
3288fcf3ce44SJohn Forte 	char			*addressPos;
3289fcf3ce44SJohn Forte 	int			rtn;
3290fcf3ce44SJohn Forte 
3291fcf3ce44SJohn Forte 	/*
3292fcf3ce44SJohn Forte 	 * Strip the first int value from the string.  If we sprintf
3293fcf3ce44SJohn Forte 	 * this back to a string and it matches the original string
3294fcf3ce44SJohn Forte 	 * then this command is using default binding.  If not a
3295fcf3ce44SJohn Forte 	 * match we have hard coded binding or a usage error.
3296fcf3ce44SJohn Forte 	 */
3297fcf3ce44SJohn Forte 	sessions = atoi(optarg);
3298fcf3ce44SJohn Forte 	(void) sprintf(tmp, "%d", sessions);
3299fcf3ce44SJohn Forte 	if (strcmp(optarg, tmp) == 0) {
3300fcf3ce44SJohn Forte 		/* default binding */
3301fcf3ce44SJohn Forte 
3302fcf3ce44SJohn Forte 		/* allocate the required pConfigSessions */
3303fcf3ce44SJohn Forte 		size = sizeof (SUN_IMA_CONFIG_SESSIONS);
3304fcf3ce44SJohn Forte 		pConfigSessions = (SUN_IMA_CONFIG_SESSIONS *)calloc(1, size);
3305fcf3ce44SJohn Forte 		if (pConfigSessions == NULL) {
3306fcf3ce44SJohn Forte 			return (1);
3307fcf3ce44SJohn Forte 		}
3308fcf3ce44SJohn Forte 
3309fcf3ce44SJohn Forte 		/* setup pConfigSessions */
3310fcf3ce44SJohn Forte 		pConfigSessions->bound	= IMA_FALSE;
3311fcf3ce44SJohn Forte 		pConfigSessions->in	= sessions;
3312fcf3ce44SJohn Forte 		pConfigSessions->out	= 0;
3313fcf3ce44SJohn Forte 	} else {
3314fcf3ce44SJohn Forte 		/* hardcoded binding */
3315fcf3ce44SJohn Forte 
3316fcf3ce44SJohn Forte 		/*
3317fcf3ce44SJohn Forte 		 * First we need to determine how many bindings
3318fcf3ce44SJohn Forte 		 * are available.  This can be done by scanning
3319fcf3ce44SJohn Forte 		 * for the number of ',' + 1.
3320fcf3ce44SJohn Forte 		 */
3321fcf3ce44SJohn Forte 		sessions = 1;
3322fcf3ce44SJohn Forte 		commaPos = strchr(optarg, ',');
3323fcf3ce44SJohn Forte 		while (commaPos != NULL) {
3324fcf3ce44SJohn Forte 			sessions++;
3325fcf3ce44SJohn Forte 			commaPos = strchr(++commaPos, ',');
3326fcf3ce44SJohn Forte 		}
3327fcf3ce44SJohn Forte 
3328fcf3ce44SJohn Forte 		/* allocate the required pConfigSessions */
3329fcf3ce44SJohn Forte 		size = sizeof (SUN_IMA_CONFIG_SESSIONS) + ((sessions - 1) *
3330fcf3ce44SJohn Forte 		    sizeof (IMA_ADDRESS_KEY));
3331fcf3ce44SJohn Forte 		pConfigSessions = (SUN_IMA_CONFIG_SESSIONS *)calloc(1, size);
3332fcf3ce44SJohn Forte 		if (pConfigSessions == NULL) {
3333fcf3ce44SJohn Forte 			return (1);
3334fcf3ce44SJohn Forte 		}
3335fcf3ce44SJohn Forte 
3336fcf3ce44SJohn Forte 		/* setup pConfigSessions */
3337fcf3ce44SJohn Forte 		pConfigSessions->bound	= IMA_TRUE;
3338fcf3ce44SJohn Forte 		pConfigSessions->in	= sessions;
3339fcf3ce44SJohn Forte 		pConfigSessions->out	= 0;
3340fcf3ce44SJohn Forte 
3341fcf3ce44SJohn Forte 		/* Now fill in the binding information.  */
3342fcf3ce44SJohn Forte 		sessions = 0;
3343fcf3ce44SJohn Forte 		addressPos = optarg;
3344fcf3ce44SJohn Forte 		/*
3345fcf3ce44SJohn Forte 		 * Walk thru possible address strings
3346fcf3ce44SJohn Forte 		 * stop once all strings are processed.
3347fcf3ce44SJohn Forte 		 */
3348fcf3ce44SJohn Forte 		while (addressPos != NULL) {
3349fcf3ce44SJohn Forte 			/*
3350fcf3ce44SJohn Forte 			 * Check if there is another address after this
3351fcf3ce44SJohn Forte 			 * one. If so terminate the current address and
3352fcf3ce44SJohn Forte 			 * keep a pointer to the next one.
3353fcf3ce44SJohn Forte 			 */
3354fcf3ce44SJohn Forte 			commaPos = strchr(addressPos, ',');
3355fcf3ce44SJohn Forte 			if (commaPos != NULL) {
3356fcf3ce44SJohn Forte 				*commaPos++ = 0x00;
3357fcf3ce44SJohn Forte 			}
3358fcf3ce44SJohn Forte 
3359fcf3ce44SJohn Forte 			/*
3360fcf3ce44SJohn Forte 			 * Parse current address.  If invalid abort
3361fcf3ce44SJohn Forte 			 * processing of addresses and free memory.
3362fcf3ce44SJohn Forte 			 */
3363fcf3ce44SJohn Forte 			if (parseAddress(addressPos, 0, address,
3364fcf3ce44SJohn Forte 			    MAX_ADDRESS_LEN, &port, &isIpv6) != PARSE_ADDR_OK) {
3365fcf3ce44SJohn Forte 				free(pConfigSessions);
3366fcf3ce44SJohn Forte 				printLibError(IMA_ERROR_INVALID_PARAMETER);
3367fcf3ce44SJohn Forte 				return (1);
3368fcf3ce44SJohn Forte 			}
3369fcf3ce44SJohn Forte 
3370fcf3ce44SJohn Forte 			/* Convert address into binary form */
3371fcf3ce44SJohn Forte 			if (isIpv6 == B_FALSE) {
3372fcf3ce44SJohn Forte 				pConfigSessions->bindings[sessions].
3373fcf3ce44SJohn Forte 				    ipAddress.ipv4Address = IMA_TRUE;
3374fcf3ce44SJohn Forte 				rtn = inet_pton(AF_INET, address,
3375fcf3ce44SJohn Forte 				    pConfigSessions->bindings[sessions].
3376fcf3ce44SJohn Forte 				    ipAddress.ipAddress);
3377fcf3ce44SJohn Forte 			} else {
3378fcf3ce44SJohn Forte 				pConfigSessions->bindings[sessions].ipAddress.
3379fcf3ce44SJohn Forte 				    ipv4Address =
3380fcf3ce44SJohn Forte 				    IMA_FALSE;
3381fcf3ce44SJohn Forte 				rtn = inet_pton(AF_INET6, address,
3382fcf3ce44SJohn Forte 				    pConfigSessions->bindings[sessions].
3383fcf3ce44SJohn Forte 				    ipAddress.ipAddress);
3384fcf3ce44SJohn Forte 			}
3385fcf3ce44SJohn Forte 			if (rtn == 0) {
3386fcf3ce44SJohn Forte 				/* inet_pton found address invalid */
3387fcf3ce44SJohn Forte 				free(pConfigSessions);
3388fcf3ce44SJohn Forte 				printLibError(IMA_ERROR_INVALID_PARAMETER);
3389fcf3ce44SJohn Forte 				return (1);
3390fcf3ce44SJohn Forte 			}
3391fcf3ce44SJohn Forte 
3392fcf3ce44SJohn Forte 			/* update addressPos to next address */
3393fcf3ce44SJohn Forte 			sessions++;
3394fcf3ce44SJohn Forte 			addressPos = commaPos;
3395fcf3ce44SJohn Forte 		}
3396fcf3ce44SJohn Forte 	}
3397fcf3ce44SJohn Forte 
3398fcf3ce44SJohn Forte 	/* issue SUN_IMA request */
3399fcf3ce44SJohn Forte 	status = SUN_IMA_SetConfigSessions(targetOid,
3400fcf3ce44SJohn Forte 	    pConfigSessions);
3401fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
3402fcf3ce44SJohn Forte 		printLibError(status);
3403fcf3ce44SJohn Forte 		free(pConfigSessions);
3404fcf3ce44SJohn Forte 		return (1);
3405fcf3ce44SJohn Forte 	}
3406fcf3ce44SJohn Forte 
3407fcf3ce44SJohn Forte 	free(pConfigSessions);
3408fcf3ce44SJohn Forte 	return (0);
3409fcf3ce44SJohn Forte }
3410fcf3ce44SJohn Forte 
3411fcf3ce44SJohn Forte static int
getAuthMethodValue(char * method,IMA_AUTHMETHOD * value)3412fcf3ce44SJohn Forte getAuthMethodValue(char *method, IMA_AUTHMETHOD *value)
3413fcf3ce44SJohn Forte {
3414fcf3ce44SJohn Forte 	if (strcasecmp(method, "chap") == 0) {
3415fcf3ce44SJohn Forte 		*value = IMA_AUTHMETHOD_CHAP;
3416fcf3ce44SJohn Forte 		return (0);
3417fcf3ce44SJohn Forte 	}
3418fcf3ce44SJohn Forte 
3419fcf3ce44SJohn Forte 	if (strcasecmp(method, "none") == 0) {
3420fcf3ce44SJohn Forte 		*value =  IMA_AUTHMETHOD_NONE;
3421fcf3ce44SJohn Forte 		return (0);
3422fcf3ce44SJohn Forte 	}
3423fcf3ce44SJohn Forte 
3424fcf3ce44SJohn Forte 	return (1);
3425fcf3ce44SJohn Forte }
3426fcf3ce44SJohn Forte 
3427fcf3ce44SJohn Forte 
3428fcf3ce44SJohn Forte /*
3429fcf3ce44SJohn Forte  * Set the authentication method
3430fcf3ce44SJohn Forte  * Currently only supports CHAP and NONE
3431fcf3ce44SJohn Forte  */
3432fcf3ce44SJohn Forte static int
modifyNodeAuthMethod(IMA_OID oid,char * optarg,int * funcRet)3433fcf3ce44SJohn Forte modifyNodeAuthMethod(IMA_OID oid, char *optarg, int *funcRet)
3434fcf3ce44SJohn Forte {
3435fcf3ce44SJohn Forte 	IMA_AUTHMETHOD methodList[MAX_AUTH_METHODS];
3436fcf3ce44SJohn Forte 	IMA_UINT methodCount = 0;
3437fcf3ce44SJohn Forte 	IMA_STATUS status;
3438fcf3ce44SJohn Forte 	IMA_AUTHMETHOD value;
3439fcf3ce44SJohn Forte 	char *method;
3440fcf3ce44SJohn Forte 	char *commaPos;
3441fcf3ce44SJohn Forte 
3442fcf3ce44SJohn Forte 	assert(funcRet != NULL);
3443fcf3ce44SJohn Forte 
3444fcf3ce44SJohn Forte 	/*
3445fcf3ce44SJohn Forte 	 * optarg will be a , delimited set of auth methods, in order
3446fcf3ce44SJohn Forte 	 * of preference
3447fcf3ce44SJohn Forte 	 * if any values here are incorrect, return without setting
3448fcf3ce44SJohn Forte 	 * anything.
3449fcf3ce44SJohn Forte 	 */
3450fcf3ce44SJohn Forte 	method = optarg;
3451fcf3ce44SJohn Forte 
3452fcf3ce44SJohn Forte 	commaPos = strchr(optarg, ',');
3453fcf3ce44SJohn Forte 
3454fcf3ce44SJohn Forte 	while (commaPos && methodCount < MAX_AUTH_METHODS) {
345533c72b75SToomas Soome 		*commaPos = '\0';
3456fcf3ce44SJohn Forte 		if (getAuthMethodValue(method, &value) != 0) {
3457fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: a: %s\n",
3458fcf3ce44SJohn Forte 			    cmdName, gettext("invalid option argument"));
3459fcf3ce44SJohn Forte 			return (1);
3460fcf3ce44SJohn Forte 		}
3461fcf3ce44SJohn Forte 		methodList[methodCount++] = value;
3462fcf3ce44SJohn Forte 		commaPos++;
3463fcf3ce44SJohn Forte 		method = commaPos;
3464fcf3ce44SJohn Forte 		commaPos = strchr(method, ',');
3465fcf3ce44SJohn Forte 	}
3466fcf3ce44SJohn Forte 	/* Should not find more method specified - if found, error */
3467fcf3ce44SJohn Forte 	if (commaPos) {
3468fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: -a: %s\n",
3469fcf3ce44SJohn Forte 		    cmdName, gettext("invalid option argument"));
3470fcf3ce44SJohn Forte 		return (1);
3471fcf3ce44SJohn Forte 	}
3472fcf3ce44SJohn Forte 	if (getAuthMethodValue(method, &value) != 0) {
3473fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: -a: %s\n",
3474fcf3ce44SJohn Forte 		    cmdName, gettext("invalid option argument"));
3475fcf3ce44SJohn Forte 		return (1);
3476fcf3ce44SJohn Forte 	}
3477fcf3ce44SJohn Forte 	methodList[methodCount++] = value;
3478fcf3ce44SJohn Forte 
3479fcf3ce44SJohn Forte 	status = IMA_SetInitiatorAuthMethods(oid, methodCount, &methodList[0]);
3480fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
3481fcf3ce44SJohn Forte 		printLibError(status);
3482fcf3ce44SJohn Forte 		*funcRet = 1;
3483fcf3ce44SJohn Forte 	}
3484fcf3ce44SJohn Forte 	return (0);
3485fcf3ce44SJohn Forte }
3486fcf3ce44SJohn Forte 
3487fcf3ce44SJohn Forte static int
modifyTargetAuthMethod(IMA_OID oid,char * optarg,int * funcRet)3488fcf3ce44SJohn Forte modifyTargetAuthMethod(IMA_OID oid, char *optarg, int *funcRet)
3489fcf3ce44SJohn Forte {
3490fcf3ce44SJohn Forte 	IMA_AUTHMETHOD methodList[MAX_AUTH_METHODS];
3491fcf3ce44SJohn Forte 	IMA_UINT methodCount = 0;
3492fcf3ce44SJohn Forte 	IMA_STATUS status;
3493fcf3ce44SJohn Forte 	IMA_AUTHMETHOD value;
3494fcf3ce44SJohn Forte 	char *method;
3495fcf3ce44SJohn Forte 	char *commaPos;
3496fcf3ce44SJohn Forte 
3497fcf3ce44SJohn Forte 	assert(funcRet != NULL);
3498fcf3ce44SJohn Forte 
3499fcf3ce44SJohn Forte 	/*
3500fcf3ce44SJohn Forte 	 * optarg will be a , delimited set of auth methods, in order
3501fcf3ce44SJohn Forte 	 * of preference
3502fcf3ce44SJohn Forte 	 * if any values here are incorrect, return without setting
3503fcf3ce44SJohn Forte 	 * anything.
3504fcf3ce44SJohn Forte 	 */
3505fcf3ce44SJohn Forte 	method = optarg;
3506fcf3ce44SJohn Forte 
3507fcf3ce44SJohn Forte 	commaPos = strchr(optarg, ',');
3508fcf3ce44SJohn Forte 
3509fcf3ce44SJohn Forte 	while (commaPos && methodCount < MAX_AUTH_METHODS) {
351033c72b75SToomas Soome 		*commaPos = '\0';
3511fcf3ce44SJohn Forte 		if (getAuthMethodValue(method, &value) != 0) {
3512fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: a: %s\n",
3513fcf3ce44SJohn Forte 			    cmdName, gettext("invalid option argument"));
3514fcf3ce44SJohn Forte 			return (1);
3515fcf3ce44SJohn Forte 		}
3516fcf3ce44SJohn Forte 		methodList[methodCount++] = value;
3517fcf3ce44SJohn Forte 		commaPos++;
3518fcf3ce44SJohn Forte 		method = commaPos;
3519fcf3ce44SJohn Forte 		commaPos = strchr(method, ',');
3520fcf3ce44SJohn Forte 	}
3521fcf3ce44SJohn Forte 	/* Should not find more method specified - if found, error */
3522fcf3ce44SJohn Forte 	if (commaPos) {
3523fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: -a: %s\n",
3524fcf3ce44SJohn Forte 		    cmdName, gettext("invalid option argument"));
3525fcf3ce44SJohn Forte 		return (1);
3526fcf3ce44SJohn Forte 	}
3527fcf3ce44SJohn Forte 	if (getAuthMethodValue(method, &value) != 0) {
3528fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: -a: %s\n",
3529fcf3ce44SJohn Forte 		    cmdName, gettext("invalid option argument"));
3530fcf3ce44SJohn Forte 		return (1);
3531fcf3ce44SJohn Forte 	}
3532fcf3ce44SJohn Forte 	methodList[methodCount++] = value;
3533fcf3ce44SJohn Forte 
3534fcf3ce44SJohn Forte 	status = SUN_IMA_SetTargetAuthMethods(oid, &methodCount,
3535fcf3ce44SJohn Forte 	    &methodList[0]);
3536fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
3537fcf3ce44SJohn Forte 		printLibError(status);
3538fcf3ce44SJohn Forte 		*funcRet = 1;
3539fcf3ce44SJohn Forte 	}
3540fcf3ce44SJohn Forte 	return (0);
3541fcf3ce44SJohn Forte }
3542fcf3ce44SJohn Forte 
3543fcf3ce44SJohn Forte /*
3544fcf3ce44SJohn Forte  * Modify the RADIUS configuration of the initiator node.
3545fcf3ce44SJohn Forte  *
3546fcf3ce44SJohn Forte  * Return 0 on success.
3547fcf3ce44SJohn Forte  */
3548fcf3ce44SJohn Forte static int
modifyNodeRadiusConfig(IMA_OID oid,char * optarg,int * funcRet)3549fcf3ce44SJohn Forte modifyNodeRadiusConfig(IMA_OID oid, char *optarg, int *funcRet)
3550fcf3ce44SJohn Forte {
3551fcf3ce44SJohn Forte 	SUN_IMA_RADIUS_CONFIG config;
3552fcf3ce44SJohn Forte 	IMA_STATUS status;
3553fcf3ce44SJohn Forte 	boolean_t isIpv6 = B_FALSE;
3554fcf3ce44SJohn Forte 	uint16_t port;
3555fcf3ce44SJohn Forte 
3556fcf3ce44SJohn Forte 	assert(funcRet != NULL);
3557fcf3ce44SJohn Forte 
3558fcf3ce44SJohn Forte 	(void) memset(&config, 0, sizeof (SUN_IMA_RADIUS_CONFIG));
3559fcf3ce44SJohn Forte 	if (parseAddress(optarg, DEFAULT_RADIUS_PORT,
3560fcf3ce44SJohn Forte 	    &config.hostnameIpAddress[0], SUN_IMA_IP_ADDRESS_PORT_LEN,
3561fcf3ce44SJohn Forte 	    &port, &isIpv6) !=
3562fcf3ce44SJohn Forte 	    PARSE_ADDR_OK) {
3563fcf3ce44SJohn Forte 		return (1);
3564fcf3ce44SJohn Forte 	}
3565fcf3ce44SJohn Forte 	config.port = (IMA_UINT16)port;
3566fcf3ce44SJohn Forte 	config.isIpv6 = (isIpv6 == B_TRUE) ? IMA_TRUE : IMA_FALSE;
3567fcf3ce44SJohn Forte 	/* Not setting shared secret here. */
3568fcf3ce44SJohn Forte 	config.sharedSecretValid = IMA_FALSE;
3569fcf3ce44SJohn Forte 
3570fcf3ce44SJohn Forte 	status = SUN_IMA_SetInitiatorRadiusConfig(oid, &config);
3571fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
3572fcf3ce44SJohn Forte 		printLibError(status);
3573fcf3ce44SJohn Forte 		*funcRet = 1;
3574fcf3ce44SJohn Forte 	}
3575fcf3ce44SJohn Forte 
3576fcf3ce44SJohn Forte 	return (0);
3577fcf3ce44SJohn Forte }
3578fcf3ce44SJohn Forte 
3579fcf3ce44SJohn Forte /*
3580fcf3ce44SJohn Forte  * Modify the RADIUS access flag of the initiator node.
3581fcf3ce44SJohn Forte  *
3582fcf3ce44SJohn Forte  * Return 0 on success.
3583fcf3ce44SJohn Forte  */
3584fcf3ce44SJohn Forte static int
modifyNodeRadiusAccess(IMA_OID oid,char * optarg,int * funcRet)3585fcf3ce44SJohn Forte modifyNodeRadiusAccess(IMA_OID oid, char *optarg, int *funcRet)
3586fcf3ce44SJohn Forte {
3587fcf3ce44SJohn Forte 	IMA_BOOL radiusAccess;
3588fcf3ce44SJohn Forte 	IMA_OID initiatorOid;
3589fcf3ce44SJohn Forte 	IMA_STATUS status;
3590fcf3ce44SJohn Forte 	SUN_IMA_RADIUS_CONFIG radiusConfig;
3591fcf3ce44SJohn Forte 	int ret;
3592fcf3ce44SJohn Forte 
3593fcf3ce44SJohn Forte 	assert(funcRet != NULL);
3594fcf3ce44SJohn Forte 
3595fcf3ce44SJohn Forte 	/* Check if Radius Config is there */
3596fcf3ce44SJohn Forte 	ret = sunInitiatorFind(&initiatorOid);
3597fcf3ce44SJohn Forte 	if (ret != 0) {
3598fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n",
3599fcf3ce44SJohn Forte 		    cmdName, gettext("no initiator found"));
3600fcf3ce44SJohn Forte 		return (1);
3601fcf3ce44SJohn Forte 	}
3602fcf3ce44SJohn Forte 	(void) memset(&radiusConfig, 0, sizeof (SUN_IMA_RADIUS_CONFIG));
3603fcf3ce44SJohn Forte 	status = SUN_IMA_GetInitiatorRadiusConfig(initiatorOid, &radiusConfig);
3604fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
3605fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n",
3606fcf3ce44SJohn Forte 		    cmdName, gettext("RADIUS server not configured yet"));
3607fcf3ce44SJohn Forte 		*funcRet = 1;
3608fcf3ce44SJohn Forte 		return (ret);
3609fcf3ce44SJohn Forte 	}
3610fcf3ce44SJohn Forte 
3611fcf3ce44SJohn Forte 	/* Check if Radius Shared is set */
3612fcf3ce44SJohn Forte 	if (radiusConfig.sharedSecretValid == IMA_FALSE) {
3613fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n", cmdName,
3614fcf3ce44SJohn Forte 		    gettext("RADIUS server secret not configured yet"));
3615fcf3ce44SJohn Forte 		return (1);
3616fcf3ce44SJohn Forte 	}
3617fcf3ce44SJohn Forte 
3618fcf3ce44SJohn Forte 	if (strcasecmp(optarg, ISCSIADM_ARG_ENABLE) == 0) {
3619fcf3ce44SJohn Forte 		radiusAccess = IMA_TRUE;
3620fcf3ce44SJohn Forte 	} else if (strcasecmp(optarg, ISCSIADM_ARG_DISABLE) == 0) {
3621fcf3ce44SJohn Forte 		radiusAccess = IMA_FALSE;
3622fcf3ce44SJohn Forte 	} else {
3623fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s %s\n",
3624fcf3ce44SJohn Forte 		    cmdName,
3625fcf3ce44SJohn Forte 		    gettext("invalid option argument"),
3626fcf3ce44SJohn Forte 		    optarg);
3627fcf3ce44SJohn Forte 		return (1);
3628fcf3ce44SJohn Forte 	}
3629fcf3ce44SJohn Forte 	status = SUN_IMA_SetInitiatorRadiusAccess(oid, radiusAccess);
3630fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
3631fcf3ce44SJohn Forte 		printLibError(status);
3632fcf3ce44SJohn Forte 		*funcRet = 1;
3633fcf3ce44SJohn Forte 	}
3634fcf3ce44SJohn Forte 
3635fcf3ce44SJohn Forte 	return (ret);
3636fcf3ce44SJohn Forte }
3637fcf3ce44SJohn Forte 
3638fcf3ce44SJohn Forte /*
3639fcf3ce44SJohn Forte  * Modify the RADIUS shared secret.
3640fcf3ce44SJohn Forte  *
3641fcf3ce44SJohn Forte  * Returns:
3642fcf3ce44SJohn Forte  *  zero on success.
3643fcf3ce44SJohn Forte  *  > 0 on failure.
3644fcf3ce44SJohn Forte  */
3645fcf3ce44SJohn Forte static int
modifyNodeRadiusSharedSecret(IMA_OID oid,int * funcRet)3646fcf3ce44SJohn Forte modifyNodeRadiusSharedSecret(IMA_OID oid, int *funcRet)
3647fcf3ce44SJohn Forte {
3648fcf3ce44SJohn Forte 	IMA_BYTE radiusSharedSecret[SUN_IMA_MAX_RADIUS_SECRET_LEN + 1];
3649fcf3ce44SJohn Forte 	IMA_OID initiatorOid;
3650fcf3ce44SJohn Forte 	IMA_STATUS status;
3651fcf3ce44SJohn Forte 	SUN_IMA_RADIUS_CONFIG radiusConfig;
3652fcf3ce44SJohn Forte 	int ret;
3653fcf3ce44SJohn Forte 	int secretLen = SUN_IMA_MAX_RADIUS_SECRET_LEN;
3654fcf3ce44SJohn Forte 
3655fcf3ce44SJohn Forte 	assert(funcRet != NULL);
3656fcf3ce44SJohn Forte 
3657fcf3ce44SJohn Forte 	ret = getSecret((char *)&radiusSharedSecret[0], &secretLen,
3658fcf3ce44SJohn Forte 	    0, SUN_IMA_MAX_RADIUS_SECRET_LEN);
3659fcf3ce44SJohn Forte 	if (ret != 0) {
3660fcf3ce44SJohn Forte 		return (1);
3661fcf3ce44SJohn Forte 	}
3662fcf3ce44SJohn Forte 
3663fcf3ce44SJohn Forte 	ret = sunInitiatorFind(&initiatorOid);
3664fcf3ce44SJohn Forte 	if (ret > 0) {
3665fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n",
3666fcf3ce44SJohn Forte 		    cmdName, gettext("no initiator found"));
3667fcf3ce44SJohn Forte 	}
3668fcf3ce44SJohn Forte 	if (ret != 0) {
3669fcf3ce44SJohn Forte 		return (1);
3670fcf3ce44SJohn Forte 	}
3671fcf3ce44SJohn Forte 	/* First obtain existing RADIUS configuration (if any) */
3672fcf3ce44SJohn Forte 	(void) memset(&radiusConfig, 0, sizeof (SUN_IMA_RADIUS_CONFIG));
3673fcf3ce44SJohn Forte 	status = SUN_IMA_GetInitiatorRadiusConfig(initiatorOid, &radiusConfig);
3674fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
3675fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n",
3676fcf3ce44SJohn Forte 		    cmdName, gettext("RADIUS server not configured yet"));
3677fcf3ce44SJohn Forte 		return (1);
3678fcf3ce44SJohn Forte 	}
3679fcf3ce44SJohn Forte 
3680fcf3ce44SJohn Forte 	/* Modify the shared secret only */
3681fcf3ce44SJohn Forte 	radiusConfig.sharedSecretLength = secretLen;
3682fcf3ce44SJohn Forte 	(void) memcpy(&radiusConfig.sharedSecret,
3683fcf3ce44SJohn Forte 	    &radiusSharedSecret[0], secretLen);
3684fcf3ce44SJohn Forte 	radiusConfig.sharedSecretValid = IMA_TRUE;
3685fcf3ce44SJohn Forte 	status = SUN_IMA_SetInitiatorRadiusConfig(oid, &radiusConfig);
3686fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
3687fcf3ce44SJohn Forte 		printLibError(status);
3688fcf3ce44SJohn Forte 		*funcRet = 1;
3689fcf3ce44SJohn Forte 	}
3690fcf3ce44SJohn Forte 
3691fcf3ce44SJohn Forte 	return (0);
3692fcf3ce44SJohn Forte }
3693fcf3ce44SJohn Forte 
3694fcf3ce44SJohn Forte /*
3695fcf3ce44SJohn Forte  * Set initiator node attributes.
3696fcf3ce44SJohn Forte  */
3697fcf3ce44SJohn Forte static int
modifyNode(cmdOptions_t * options,int * funcRet)3698fcf3ce44SJohn Forte modifyNode(cmdOptions_t *options, int *funcRet)
3699fcf3ce44SJohn Forte {
3700fcf3ce44SJohn Forte 	IMA_NODE_NAME	nodeName;
3701fcf3ce44SJohn Forte 	IMA_NODE_ALIAS	nodeAlias;
3702fcf3ce44SJohn Forte 	IMA_OID		oid;
3703fcf3ce44SJohn Forte 	IMA_STATUS	status;
3704fcf3ce44SJohn Forte 	cmdOptions_t	*optionList = options;
3705fcf3ce44SJohn Forte 	int		ret;
3706fcf3ce44SJohn Forte 	iSCSINameCheckStatusType nameCheckStatus;
3707fcf3ce44SJohn Forte 	IMA_OID sharedNodeOid;
370833c72b75SToomas Soome 	int		i;
370933c72b75SToomas Soome 	int		lowerCase;
37106cefaae1SJack Meng 	IMA_BOOL	iscsiBoot = IMA_FALSE;
37116cefaae1SJack Meng 	IMA_BOOL	mpxioEnabled = IMA_FALSE;
37127f848965Sbing zhao - Sun Microsystems - Beijing China 	char		*mb_name = NULL;
37137f848965Sbing zhao - Sun Microsystems - Beijing China 	int		prefixlen = 0;
3714fcf3ce44SJohn Forte 
3715fcf3ce44SJohn Forte 	assert(funcRet != NULL);
3716fcf3ce44SJohn Forte 
37176cefaae1SJack Meng 	/* Get boot session's info */
37186cefaae1SJack Meng 	(void) SUN_IMA_GetBootIscsi(&iscsiBoot);
37196cefaae1SJack Meng 	if (iscsiBoot == IMA_TRUE) {
37206cefaae1SJack Meng 		status = SUN_IMA_GetBootMpxio(&mpxioEnabled);
37216cefaae1SJack Meng 		if (!IMA_SUCCESS(status)) {
37226cefaae1SJack Meng 			(void) fprintf(stderr, "%s: %s\n",
37236cefaae1SJack Meng 			    cmdName, gettext("unable to get MPxIO info"
37246cefaae1SJack Meng 			    " of root disk"));
37256cefaae1SJack Meng 			*funcRet = 1;
37266cefaae1SJack Meng 			return (1);
37276cefaae1SJack Meng 		}
37286cefaae1SJack Meng 	}
37296cefaae1SJack Meng 
3730fcf3ce44SJohn Forte 	/* Find Sun initiator */
3731fcf3ce44SJohn Forte 	ret = sunInitiatorFind(&oid);
3732f5fc5c04SJack Meng 	if (ret != 0) {
3733fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n",
3734fcf3ce44SJohn Forte 		    cmdName, gettext("no initiator found"));
3735fcf3ce44SJohn Forte 		return (ret);
3736fcf3ce44SJohn Forte 	}
3737fcf3ce44SJohn Forte 
3738fcf3ce44SJohn Forte 	for (; optionList->optval; optionList++) {
3739fcf3ce44SJohn Forte 		switch (optionList->optval) {
3740fcf3ce44SJohn Forte 			case 'N':
3741fcf3ce44SJohn Forte 				if (strlen(optionList->optarg) >=
3742fcf3ce44SJohn Forte 				    MAX_ISCSI_NAME_LEN) {
3743fcf3ce44SJohn Forte 					(void) fprintf(stderr, "%s: %s %d\n",
3744fcf3ce44SJohn Forte 					    cmdName,
3745fcf3ce44SJohn Forte 					    gettext("name too long, \
3746fcf3ce44SJohn Forte 					    maximum length is:"),
3747fcf3ce44SJohn Forte 					    MAX_ISCSI_NAME_LEN);
3748fcf3ce44SJohn Forte 				}
3749fcf3ce44SJohn Forte 
3750fcf3ce44SJohn Forte 				/* Take the first operand as node name. */
3751fcf3ce44SJohn Forte 				(void) memset(&nodeName, 0,
3752fcf3ce44SJohn Forte 				    sizeof (IMA_NODE_NAME));
3753fcf3ce44SJohn Forte 				if (mbstowcs(nodeName, optionList->optarg,
3754fcf3ce44SJohn Forte 				    IMA_NODE_NAME_LEN) == (size_t)-1) {
3755fcf3ce44SJohn Forte 					(void) fprintf(stderr, "%s: %s\n",
3756fcf3ce44SJohn Forte 					    cmdName,
3757fcf3ce44SJohn Forte 					    gettext("conversion error"));
3758fcf3ce44SJohn Forte 					return (1);
3759fcf3ce44SJohn Forte 				}
3760fcf3ce44SJohn Forte 
37617f848965Sbing zhao - Sun Microsystems - Beijing China 				prefixlen = strlen(ISCSI_IQN_NAME_PREFIX);
37627f848965Sbing zhao - Sun Microsystems - Beijing China 				mb_name = (char *)calloc(1, prefixlen + 1);
37637f848965Sbing zhao - Sun Microsystems - Beijing China 				if (mb_name == NULL) {
37647f848965Sbing zhao - Sun Microsystems - Beijing China 					return (1);
3765fcf3ce44SJohn Forte 				}
37667f848965Sbing zhao - Sun Microsystems - Beijing China 
37677f848965Sbing zhao - Sun Microsystems - Beijing China 				if (wcstombs(mb_name, nodeName,
37687f848965Sbing zhao - Sun Microsystems - Beijing China 				    prefixlen) == (size_t)-1) {
37697f848965Sbing zhao - Sun Microsystems - Beijing China 					(void) fprintf(stderr, "%s: %s\n",
37707f848965Sbing zhao - Sun Microsystems - Beijing China 					    cmdName,
37717f848965Sbing zhao - Sun Microsystems - Beijing China 					    gettext("conversion error"));
37727f848965Sbing zhao - Sun Microsystems - Beijing China 					(void) IMA_FreeMemory(mb_name);
37737f848965Sbing zhao - Sun Microsystems - Beijing China 					return (1);
37747f848965Sbing zhao - Sun Microsystems - Beijing China 				}
37757f848965Sbing zhao - Sun Microsystems - Beijing China 				if (strncmp(mb_name, ISCSI_IQN_NAME_PREFIX,
37767f848965Sbing zhao - Sun Microsystems - Beijing China 				    prefixlen) == 0) {
37777f848965Sbing zhao - Sun Microsystems - Beijing China 					/*
37787f848965Sbing zhao - Sun Microsystems - Beijing China 					 * For iqn format, we should map
37797f848965Sbing zhao - Sun Microsystems - Beijing China 					 * the upper-case characters to
37807f848965Sbing zhao - Sun Microsystems - Beijing China 					 * their lower-case equivalents.
37817f848965Sbing zhao - Sun Microsystems - Beijing China 					 */
37827f848965Sbing zhao - Sun Microsystems - Beijing China 					for (i = 0; nodeName[i] != 0; i++) {
37837f848965Sbing zhao - Sun Microsystems - Beijing China 						lowerCase =
37847f848965Sbing zhao - Sun Microsystems - Beijing China 						    tolower(nodeName[i]);
37857f848965Sbing zhao - Sun Microsystems - Beijing China 						nodeName[i] = lowerCase;
37867f848965Sbing zhao - Sun Microsystems - Beijing China 					}
37877f848965Sbing zhao - Sun Microsystems - Beijing China 				}
37887f848965Sbing zhao - Sun Microsystems - Beijing China 				(void) IMA_FreeMemory(mb_name);
37897f848965Sbing zhao - Sun Microsystems - Beijing China 
3790fcf3ce44SJohn Forte 				/* Perform string profile checks */
3791fcf3ce44SJohn Forte 				nameCheckStatus =
3792fcf3ce44SJohn Forte 				    iSCSINameStringProfileCheck(nodeName);
3793fcf3ce44SJohn Forte 				iSCSINameCheckStatusDisplay(nameCheckStatus);
3794fcf3ce44SJohn Forte 				if (nameCheckStatus != iSCSINameCheckOK) {
3795fcf3ce44SJohn Forte 					*funcRet = 1; /* DIY message fix */
3796fcf3ce44SJohn Forte 					return (1);
3797fcf3ce44SJohn Forte 				}
3798fcf3ce44SJohn Forte 
3799fcf3ce44SJohn Forte 				/*
3800fcf3ce44SJohn Forte 				 * IMA_GetSharedNodeOid(&sharedNodeOid);
3801fcf3ce44SJohn Forte 				 * if (!IMA_SUCCESS(status)) {
3802fcf3ce44SJohn Forte 				 *   printLibError(status);
3803fcf3ce44SJohn Forte 				 *   return (INF_ERROR);
3804fcf3ce44SJohn Forte 				 * }
3805fcf3ce44SJohn Forte 				 */
38066cefaae1SJack Meng 				if (iscsiBoot == IMA_TRUE) {
38076cefaae1SJack Meng 					(void) fprintf(stderr, "%s: %s\n",
38086cefaae1SJack Meng 					    cmdName, gettext("iscsi boot, not"
38096cefaae1SJack Meng 					    " allowed to change"
38106cefaae1SJack Meng 					    " initiator's name"));
38116cefaae1SJack Meng 					return (1);
38126cefaae1SJack Meng 				}
3813fcf3ce44SJohn Forte 				oid.objectType = IMA_OBJECT_TYPE_NODE;
3814fcf3ce44SJohn Forte 				status = IMA_SetNodeName(oid, nodeName);
3815fcf3ce44SJohn Forte 				if (!IMA_SUCCESS(status)) {
3816fcf3ce44SJohn Forte 					printLibError(status);
3817fcf3ce44SJohn Forte 					*funcRet = 1;
3818fcf3ce44SJohn Forte 					return (ret);
3819fcf3ce44SJohn Forte 				}
3820fcf3ce44SJohn Forte 				break;
3821fcf3ce44SJohn Forte 
3822fcf3ce44SJohn Forte 			case 'A':
38236cefaae1SJack Meng 				if (iscsiBoot == IMA_TRUE) {
38246cefaae1SJack Meng 					(void) fprintf(stderr, "%s: %s\n",
38256cefaae1SJack Meng 					    cmdName, gettext("iscsi boot, not"
38266cefaae1SJack Meng 					    " allowed to change"
38276cefaae1SJack Meng 					    " initiator's alias"));
38286cefaae1SJack Meng 					return (1);
38296cefaae1SJack Meng 				}
3830fcf3ce44SJohn Forte 				/* Take the first operand as node alias. */
3831fcf3ce44SJohn Forte 				if (strlen(optionList->optarg) >=
3832fcf3ce44SJohn Forte 				    MAX_ISCSI_NAME_LEN) {
3833fcf3ce44SJohn Forte 					(void) fprintf(stderr, "%s: %s %d\n",
3834fcf3ce44SJohn Forte 					    cmdName,
3835fcf3ce44SJohn Forte 					    gettext("alias too long, maximum  \
3836fcf3ce44SJohn Forte 					    length is:"),
3837fcf3ce44SJohn Forte 					    MAX_ISCSI_NAME_LEN);
3838fcf3ce44SJohn Forte 				}
3839fcf3ce44SJohn Forte 
3840fcf3ce44SJohn Forte 				(void) memset(&nodeAlias, 0,
3841fcf3ce44SJohn Forte 				    sizeof (IMA_NODE_ALIAS));
3842fcf3ce44SJohn Forte 				if (mbstowcs(nodeAlias, optionList->optarg,
3843fcf3ce44SJohn Forte 				    IMA_NODE_ALIAS_LEN) == (size_t)-1) {
3844fcf3ce44SJohn Forte 					(void) fprintf(stderr, "%s: %s\n",
3845fcf3ce44SJohn Forte 					    cmdName,
3846fcf3ce44SJohn Forte 					    gettext("conversion error"));
3847fcf3ce44SJohn Forte 					return (1);
3848fcf3ce44SJohn Forte 				}
3849fcf3ce44SJohn Forte 
3850fcf3ce44SJohn Forte 				status = IMA_GetSharedNodeOid(&sharedNodeOid);
3851fcf3ce44SJohn Forte 				if (!IMA_SUCCESS(status)) {
3852fcf3ce44SJohn Forte 					printLibError(status);
3853fcf3ce44SJohn Forte 					*funcRet = 1;
3854fcf3ce44SJohn Forte 					return (ret);
3855fcf3ce44SJohn Forte 				}
3856fcf3ce44SJohn Forte 
3857fcf3ce44SJohn Forte 				status = IMA_SetNodeAlias(sharedNodeOid,
3858fcf3ce44SJohn Forte 				    nodeAlias);
3859fcf3ce44SJohn Forte 				if (!IMA_SUCCESS(status)) {
3860fcf3ce44SJohn Forte 					printLibError(status);
3861fcf3ce44SJohn Forte 					*funcRet = 1;
3862fcf3ce44SJohn Forte 					return (ret);
3863fcf3ce44SJohn Forte 				}
3864fcf3ce44SJohn Forte 				break;
3865fcf3ce44SJohn Forte 
3866fcf3ce44SJohn Forte 			case 'a':
38676cefaae1SJack Meng 				if (iscsiBoot == IMA_TRUE) {
38686cefaae1SJack Meng 					(void) fprintf(stderr, "%s: %s\n",
38696cefaae1SJack Meng 					    cmdName, gettext("iscsi boot, not"
38706cefaae1SJack Meng 					    " allowed to change authentication"
38716cefaae1SJack Meng 					    " method"));
38726cefaae1SJack Meng 					return (1);
38736cefaae1SJack Meng 				}
3874fcf3ce44SJohn Forte 				if (modifyNodeAuthMethod(oid, options->optarg,
3875fcf3ce44SJohn Forte 				    funcRet) != 0) {
3876fcf3ce44SJohn Forte 					return (1);
3877fcf3ce44SJohn Forte 				}
3878fcf3ce44SJohn Forte 				break;
3879fcf3ce44SJohn Forte 
3880fcf3ce44SJohn Forte 			case 'R':
3881fcf3ce44SJohn Forte 				if (modifyNodeRadiusAccess(oid, options->optarg,
3882fcf3ce44SJohn Forte 				    funcRet) != 0) {
3883fcf3ce44SJohn Forte 					return (1);
3884fcf3ce44SJohn Forte 				}
3885fcf3ce44SJohn Forte 				break;
3886fcf3ce44SJohn Forte 
3887fcf3ce44SJohn Forte 			case 'r':
3888fcf3ce44SJohn Forte 				if (modifyNodeRadiusConfig(oid, options->optarg,
3889fcf3ce44SJohn Forte 				    funcRet) != 0) {
3890fcf3ce44SJohn Forte 					return (1);
3891fcf3ce44SJohn Forte 				}
3892fcf3ce44SJohn Forte 				break;
3893fcf3ce44SJohn Forte 
3894fcf3ce44SJohn Forte 			case 'P':
3895fcf3ce44SJohn Forte 				if (modifyNodeRadiusSharedSecret(oid, funcRet)
3896fcf3ce44SJohn Forte 				    != 0) {
3897fcf3ce44SJohn Forte 					return (1);
3898fcf3ce44SJohn Forte 				}
3899fcf3ce44SJohn Forte 				break;
3900fcf3ce44SJohn Forte 
3901fcf3ce44SJohn Forte 			case 'C':
39026cefaae1SJack Meng 				if (iscsiBoot == IMA_TRUE) {
39036cefaae1SJack Meng 					(void) fprintf(stderr, "%s: %s\n",
39046cefaae1SJack Meng 					    cmdName, gettext("iscsi boot, not"
39056cefaae1SJack Meng 					    " allowed to change CHAP secret"));
39066cefaae1SJack Meng 					return (1);
39076cefaae1SJack Meng 				}
3908fcf3ce44SJohn Forte 				if (modifyNodeAuthParam(oid, AUTH_PASSWORD,
3909fcf3ce44SJohn Forte 				    NULL, funcRet) != 0) {
3910fcf3ce44SJohn Forte 					return (1);
3911fcf3ce44SJohn Forte 				}
3912fcf3ce44SJohn Forte 				break;
3913fcf3ce44SJohn Forte 
3914fcf3ce44SJohn Forte 			case 'c':
39156cefaae1SJack Meng 				if (iscsiBoot == IMA_TRUE) {
39166cefaae1SJack Meng 					if (mpxioEnabled == IMA_FALSE) {
39176cefaae1SJack Meng 						(void) fprintf(stderr,
39186cefaae1SJack Meng 						    "%s: %s\n", cmdName,
39196cefaae1SJack Meng 						    gettext("iscsi"
39206cefaae1SJack Meng 						    " boot and MPxIO"
39216cefaae1SJack Meng 						    " is disabled, not allowed"
39226cefaae1SJack Meng 						    " to change number of"
39236cefaae1SJack Meng 						    " sessions to be"
39246cefaae1SJack Meng 						    " configured"));
39256cefaae1SJack Meng 						return (1);
39266cefaae1SJack Meng 					}
39276cefaae1SJack Meng 				}
3928fcf3ce44SJohn Forte 				if (modifyConfiguredSessions(oid,
3929fcf3ce44SJohn Forte 				    optionList->optarg) != 0) {
39306cefaae1SJack Meng 					if (iscsiBoot == IMA_TRUE) {
39316cefaae1SJack Meng 						(void) fprintf(stderr,
39326cefaae1SJack Meng 						    "%s: %s\n", cmdName,
39336cefaae1SJack Meng 						    gettext("iscsi boot,"
39346cefaae1SJack Meng 						    " fail to set configured"
39356cefaae1SJack Meng 						    " session"));
39366cefaae1SJack Meng 					}
3937fcf3ce44SJohn Forte 					return (1);
3938fcf3ce44SJohn Forte 				}
3939fcf3ce44SJohn Forte 				break;
3940fcf3ce44SJohn Forte 
39416cefaae1SJack Meng 
3942fcf3ce44SJohn Forte 			case 'H':
39436cefaae1SJack Meng 				if (iscsiBoot == IMA_TRUE) {
39446cefaae1SJack Meng 					(void) fprintf(stderr, "%s: %s\n",
39456cefaae1SJack Meng 					    cmdName, gettext("iscsi boot, not"
39466cefaae1SJack Meng 					    " allowed to change CHAP name"));
39476cefaae1SJack Meng 					return (1);
39486cefaae1SJack Meng 				}
3949fcf3ce44SJohn Forte 				if (modifyNodeAuthParam(oid, AUTH_NAME,
3950fcf3ce44SJohn Forte 				    optionList->optarg, funcRet) != 0) {
3951fcf3ce44SJohn Forte 					return (1);
3952fcf3ce44SJohn Forte 				}
3953fcf3ce44SJohn Forte 				break;
3954fcf3ce44SJohn Forte 
39556cefaae1SJack Meng 
3956fcf3ce44SJohn Forte 			case 'd':
39576cefaae1SJack Meng 				if (iscsiBoot == IMA_TRUE) {
39586cefaae1SJack Meng 					if (mpxioEnabled == IMA_FALSE) {
39596cefaae1SJack Meng 						(void) fprintf(stderr,
39606cefaae1SJack Meng 						    "%s: %s\n", cmdName,
39616cefaae1SJack Meng 						    gettext("iscsi"
39626cefaae1SJack Meng 						    " boot and MPxIO"
39636cefaae1SJack Meng 						    " is disabled, not"
39646cefaae1SJack Meng 						    " allowed to"
39656cefaae1SJack Meng 						    " change initiator's"
39666cefaae1SJack Meng 						    " login params"));
39676cefaae1SJack Meng 						return (1);
39686cefaae1SJack Meng 					}
39696cefaae1SJack Meng 				}
3970fcf3ce44SJohn Forte 				if (setLoginParameter(oid, DATA_DIGEST,
3971fcf3ce44SJohn Forte 				    optionList->optarg) != 0) {
3972fcf3ce44SJohn Forte 					return (1);
3973fcf3ce44SJohn Forte 				}
3974fcf3ce44SJohn Forte 				break;
3975fcf3ce44SJohn Forte 
3976fcf3ce44SJohn Forte 			case 'h':
39776cefaae1SJack Meng 				if (iscsiBoot == IMA_TRUE) {
39786cefaae1SJack Meng 					if (mpxioEnabled == IMA_FALSE) {
39796cefaae1SJack Meng 						(void) fprintf(stderr,
39806cefaae1SJack Meng 						    "%s: %s\n", cmdName,
39816cefaae1SJack Meng 						    gettext("iscsi"
39826cefaae1SJack Meng 						    " boot and MPxIO"
39836cefaae1SJack Meng 						    " is disabled, not"
39846cefaae1SJack Meng 						    " allowed to"
39856cefaae1SJack Meng 						    " change initiator's"
39866cefaae1SJack Meng 						    " login params"));
39876cefaae1SJack Meng 						return (1);
39886cefaae1SJack Meng 					}
39896cefaae1SJack Meng 				}
3990fcf3ce44SJohn Forte 				if (setLoginParameter(oid, HEADER_DIGEST,
3991fcf3ce44SJohn Forte 				    optionList->optarg) != 0) {
3992fcf3ce44SJohn Forte 					return (1);
3993fcf3ce44SJohn Forte 				}
3994fcf3ce44SJohn Forte 				break;
3995fcf3ce44SJohn Forte 
3996aff4bce5Syi zhang - Sun Microsystems - Beijing China 			case 'T':
3997aff4bce5Syi zhang - Sun Microsystems - Beijing China 				if (setTunableParameters(oid,
3998aff4bce5Syi zhang - Sun Microsystems - Beijing China 				    optionList->optarg) != 0) {
3999aff4bce5Syi zhang - Sun Microsystems - Beijing China 					return (1);
4000aff4bce5Syi zhang - Sun Microsystems - Beijing China 				}
4001aff4bce5Syi zhang - Sun Microsystems - Beijing China 				break;
4002fcf3ce44SJohn Forte 			default:
4003fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %c: %s\n",
4004fcf3ce44SJohn Forte 				    cmdName, optionList->optval,
4005fcf3ce44SJohn Forte 				    gettext("unknown option"));
4006fcf3ce44SJohn Forte 				break;
4007fcf3ce44SJohn Forte 		}
4008fcf3ce44SJohn Forte 	}
4009fcf3ce44SJohn Forte 
4010fcf3ce44SJohn Forte 	return (ret);
4011fcf3ce44SJohn Forte }
4012fcf3ce44SJohn Forte 
4013fcf3ce44SJohn Forte /*
4014fcf3ce44SJohn Forte  * Modify target parameters
4015fcf3ce44SJohn Forte  */
4016fcf3ce44SJohn Forte static int
modifyTargetParam(cmdOptions_t * options,char * targetName,int * funcRet)4017fcf3ce44SJohn Forte modifyTargetParam(cmdOptions_t *options, char *targetName, int *funcRet)
4018fcf3ce44SJohn Forte {
4019fcf3ce44SJohn Forte 	IMA_OID oid;
4020fcf3ce44SJohn Forte 	IMA_OID targetOid;
4021fcf3ce44SJohn Forte 	IMA_STATUS status;
4022fcf3ce44SJohn Forte 	IMA_OID_LIST *targetList;
4023fcf3ce44SJohn Forte 	SUN_IMA_TARGET_PROPERTIES targetProps;
4024fcf3ce44SJohn Forte 	wchar_t wcInputObject[MAX_ISCSI_NAME_LEN + 1];
4025fcf3ce44SJohn Forte 	wchar_t targetAddress[SUN_IMA_IP_ADDRESS_PORT_LEN];
4026fcf3ce44SJohn Forte 	int ret;
4027fcf3ce44SJohn Forte 	boolean_t found;
4028fcf3ce44SJohn Forte 	boolean_t targetAddressSpecified = B_TRUE;
4029fcf3ce44SJohn Forte 	boolean_t tpgtSpecified = B_FALSE;
4030fcf3ce44SJohn Forte 	boolean_t isIpv6 = B_FALSE;
4031fcf3ce44SJohn Forte 	int i;
4032fcf3ce44SJohn Forte 	iSCSINameCheckStatusType nameCheckStatus;
4033fcf3ce44SJohn Forte 	IMA_UINT16 port = 0;
4034fcf3ce44SJohn Forte 	IMA_UINT16 tpgt = 0;
4035fcf3ce44SJohn Forte 
40366cefaae1SJack Meng 	IMA_NODE_NAME bootTargetName;
40376cefaae1SJack Meng 	IMA_INITIATOR_AUTHPARMS bootTargetCHAP;
40386cefaae1SJack Meng 	IMA_BOOL  iscsiBoot;
40396cefaae1SJack Meng 	IMA_BOOL  mpxioEnabled;
40406cefaae1SJack Meng 
4041fcf3ce44SJohn Forte 	cmdOptions_t *optionList = options;
4042fcf3ce44SJohn Forte 
4043fcf3ce44SJohn Forte 	assert(funcRet != NULL);
4044fcf3ce44SJohn Forte 
4045fcf3ce44SJohn Forte 	/* Find Sun initiator */
4046fcf3ce44SJohn Forte 	ret = sunInitiatorFind(&oid);
4047fcf3ce44SJohn Forte 	if (ret > 0) {
4048fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n",
4049fcf3ce44SJohn Forte 		    cmdName, gettext("no initiator found"));
4050fcf3ce44SJohn Forte 	}
4051fcf3ce44SJohn Forte 
4052fcf3ce44SJohn Forte 	if (ret != 0) {
4053fcf3ce44SJohn Forte 		return (ret);
4054fcf3ce44SJohn Forte 	}
4055fcf3ce44SJohn Forte 
4056fcf3ce44SJohn Forte 	if (parseTarget(targetName,
4057fcf3ce44SJohn Forte 	    &wcInputObject[0],
4058fcf3ce44SJohn Forte 	    MAX_ISCSI_NAME_LEN + 1,
4059fcf3ce44SJohn Forte 	    &targetAddressSpecified,
4060fcf3ce44SJohn Forte 	    &targetAddress[0],
4061fcf3ce44SJohn Forte 	    SUN_IMA_IP_ADDRESS_PORT_LEN,
4062fcf3ce44SJohn Forte 	    &port,
4063fcf3ce44SJohn Forte 	    &tpgtSpecified,
4064fcf3ce44SJohn Forte 	    &tpgt,
4065fcf3ce44SJohn Forte 	    &isIpv6) != PARSE_TARGET_OK) {
4066fcf3ce44SJohn Forte 		return (1);
4067fcf3ce44SJohn Forte 	}
4068fcf3ce44SJohn Forte 
4069fcf3ce44SJohn Forte 	/* Perform string profile checks */
4070fcf3ce44SJohn Forte 	nameCheckStatus = iSCSINameStringProfileCheck(wcInputObject);
4071fcf3ce44SJohn Forte 	iSCSINameCheckStatusDisplay(nameCheckStatus);
4072fcf3ce44SJohn Forte 	if (nameCheckStatus != iSCSINameCheckOK) {
4073fcf3ce44SJohn Forte 		return (1);
4074fcf3ce44SJohn Forte 	}
4075fcf3ce44SJohn Forte 
4076fcf3ce44SJohn Forte 	status = IMA_GetTargetOidList(oid, &targetList);
4077fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
4078fcf3ce44SJohn Forte 		printLibError(status);
4079fcf3ce44SJohn Forte 		*funcRet = 1;
4080fcf3ce44SJohn Forte 		return (0);
4081fcf3ce44SJohn Forte 	}
4082fcf3ce44SJohn Forte 
40836cefaae1SJack Meng 	(void) SUN_IMA_GetBootIscsi(&iscsiBoot);
40846cefaae1SJack Meng 	if (iscsiBoot == IMA_TRUE) {
40856cefaae1SJack Meng 		status = SUN_IMA_GetBootMpxio(&mpxioEnabled);
40866cefaae1SJack Meng 		if (!IMA_SUCCESS(status)) {
40876cefaae1SJack Meng 			(void) fprintf(stderr, "%s: %s\n",
40886cefaae1SJack Meng 			    cmdName, gettext("unable to get MPxIO info"
40896cefaae1SJack Meng 			    " of root disk"));
40906cefaae1SJack Meng 			*funcRet = 1;
40916cefaae1SJack Meng 			return (ret);
40926cefaae1SJack Meng 		}
40936cefaae1SJack Meng 		status = SUN_IMA_GetBootTargetName(bootTargetName);
40946cefaae1SJack Meng 		if (!IMA_SUCCESS(status)) {
40956cefaae1SJack Meng 			(void) fprintf(stderr, "%s: %s\n",
40966cefaae1SJack Meng 			    cmdName, gettext("unable to get boot target's"
40976cefaae1SJack Meng 			    " name"));
40986cefaae1SJack Meng 			*funcRet = 1;
40996cefaae1SJack Meng 			return (ret);
41006cefaae1SJack Meng 		}
41016cefaae1SJack Meng 		status = SUN_IMA_GetBootTargetAuthParams(&bootTargetCHAP);
41026cefaae1SJack Meng 		if (!IMA_SUCCESS(status)) {
41036cefaae1SJack Meng 			(void) fprintf(stderr, "%s: %s\n",
41046cefaae1SJack Meng 			    cmdName, gettext("unable to get boot target's"
41056cefaae1SJack Meng 			    " auth param"));
41066cefaae1SJack Meng 			*funcRet = 1;
41076cefaae1SJack Meng 			return (ret);
41086cefaae1SJack Meng 		}
41096cefaae1SJack Meng 	}
41106cefaae1SJack Meng 
4111fcf3ce44SJohn Forte 	/* find target oid */
4112fcf3ce44SJohn Forte 	for (found = B_FALSE, i = 0; i < targetList->oidCount; i++) {
4113fcf3ce44SJohn Forte 		status = SUN_IMA_GetTargetProperties(targetList->oids[i],
4114fcf3ce44SJohn Forte 		    &targetProps);
4115fcf3ce44SJohn Forte 		if (!IMA_SUCCESS(status)) {
4116fcf3ce44SJohn Forte 			printLibError(status);
4117fcf3ce44SJohn Forte 			(void) IMA_FreeMemory(targetList);
4118fcf3ce44SJohn Forte 			*funcRet = 1;
4119fcf3ce44SJohn Forte 			return (ret);
4120fcf3ce44SJohn Forte 		}
4121fcf3ce44SJohn Forte 
4122fcf3ce44SJohn Forte 		/*
4123fcf3ce44SJohn Forte 		 * Compare the target name with the input name
4124fcf3ce44SJohn Forte 		 */
4125fcf3ce44SJohn Forte 		if ((targetNamesEqual(wcInputObject, targetProps.imaProps.name)
4126fcf3ce44SJohn Forte 		    == B_TRUE)) {
4127fcf3ce44SJohn Forte 			/*
4128fcf3ce44SJohn Forte 			 * For now, regardless of whether a target address
4129fcf3ce44SJohn Forte 			 * is specified, we return B_TRUE because
4130fcf3ce44SJohn Forte 			 * IMA_TARGET_PROPERTIES does not have a field for
4131fcf3ce44SJohn Forte 			 * specifying address.
4132fcf3ce44SJohn Forte 			 */
4133fcf3ce44SJohn Forte 			found = B_TRUE;
4134fcf3ce44SJohn Forte 			targetOid = targetList->oids[i];
41356cefaae1SJack Meng 
41366cefaae1SJack Meng 			if ((targetNamesEqual(bootTargetName, wcInputObject)
41376cefaae1SJack Meng 			    == B_TRUE) && (iscsiBoot == IMA_TRUE)) {
41386cefaae1SJack Meng 				/*
41396cefaae1SJack Meng 				 * iscsi booting, need changed target param is
41406cefaae1SJack Meng 				 * booting target, for auth param, not allow
41416cefaae1SJack Meng 				 * to change, for others dependent on mpxio
41426cefaae1SJack Meng 				 */
41436cefaae1SJack Meng 
41446cefaae1SJack Meng 				if ((optionList->optval == 'C') ||
41456cefaae1SJack Meng 				    (optionList->optval == 'H') ||
41466cefaae1SJack Meng 				    (optionList->optval == 'B') ||
41476cefaae1SJack Meng 				    (optionList->optval == 'a')) {
41486cefaae1SJack Meng 					/*
41496cefaae1SJack Meng 					 * -C CHAP secret set
41506cefaae1SJack Meng 					 * -H CHAP name set
41516cefaae1SJack Meng 					 * -a authentication
41526cefaae1SJack Meng 					 * -B bi-directional-authentication
41536cefaae1SJack Meng 					 */
41546cefaae1SJack Meng 					(void) fprintf(stderr, "%s: %s\n",
41556cefaae1SJack Meng 					    cmdName, gettext("iscsi boot,"
41566cefaae1SJack Meng 					    " not allowed to modify"
41576cefaae1SJack Meng 					    " authentication parameters"
41586cefaae1SJack Meng 					    "  of boot target"));
41596cefaae1SJack Meng 					return (1);
41606cefaae1SJack Meng 				}
41616cefaae1SJack Meng 				if (mpxioEnabled == IMA_FALSE) {
41626cefaae1SJack Meng 					(void) fprintf(stderr, "%s: %s\n",
41636cefaae1SJack Meng 					    cmdName, gettext("iscsi boot and"
41646cefaae1SJack Meng 					    " MPxIO is disabled, not allowed"
41656cefaae1SJack Meng 					    " to modify boot target's"
41666cefaae1SJack Meng 					    " parameters"));
41676cefaae1SJack Meng 					return (1);
41686cefaae1SJack Meng 				}
41696cefaae1SJack Meng 
41706cefaae1SJack Meng 			}
41716cefaae1SJack Meng 
4172fcf3ce44SJohn Forte 			if (modifyIndividualTargetParam(optionList, targetOid,
4173fcf3ce44SJohn Forte 			    funcRet) != 0) {
4174fcf3ce44SJohn Forte 				return (ret);
4175fcf3ce44SJohn Forte 			}
4176fcf3ce44SJohn Forte 
4177fcf3ce44SJohn Forte 			/*
4178fcf3ce44SJohn Forte 			 * Even after finding a matched target, keep going
4179fcf3ce44SJohn Forte 			 * since there could be multiple target objects
4180fcf3ce44SJohn Forte 			 * associated with one target name in the system
4181fcf3ce44SJohn Forte 			 * because of different TPGTs.
4182fcf3ce44SJohn Forte 			 */
4183fcf3ce44SJohn Forte 		}
4184fcf3ce44SJohn Forte 	}
4185fcf3ce44SJohn Forte 
4186fcf3ce44SJohn Forte 	/* If the target OID cannot be found create one */
4187fcf3ce44SJohn Forte 	if (!found) {
4188fcf3ce44SJohn Forte 		status = SUN_IMA_CreateTargetOid(wcInputObject, &targetOid);
4189fcf3ce44SJohn Forte 		if (!IMA_SUCCESS(status)) {
4190fcf3ce44SJohn Forte 			printLibError(status);
4191fcf3ce44SJohn Forte 			(void) IMA_FreeMemory(targetList);
4192fcf3ce44SJohn Forte 			*funcRet = 1;
4193fcf3ce44SJohn Forte 			return (ret);
4194fcf3ce44SJohn Forte 		}
4195fcf3ce44SJohn Forte 		if (modifyIndividualTargetParam(optionList, targetOid,
4196fcf3ce44SJohn Forte 		    funcRet) != 0) {
4197fcf3ce44SJohn Forte 				return (ret);
4198fcf3ce44SJohn Forte 		}
4199fcf3ce44SJohn Forte 	}
4200fcf3ce44SJohn Forte 
4201fcf3ce44SJohn Forte 	(void) IMA_FreeMemory(targetList);
4202fcf3ce44SJohn Forte 	return (ret);
4203fcf3ce44SJohn Forte }
4204fcf3ce44SJohn Forte 
4205fcf3ce44SJohn Forte /*
4206fcf3ce44SJohn Forte  * Add one or more addresses
4207fcf3ce44SJohn Forte  */
4208fcf3ce44SJohn Forte static int
addAddress(int addrType,int operandLen,char * operand[],int * funcRet)4209fcf3ce44SJohn Forte addAddress(int addrType, int operandLen, char *operand[], int *funcRet)
4210fcf3ce44SJohn Forte {
4211fcf3ce44SJohn Forte 	IMA_STATUS status;
4212fcf3ce44SJohn Forte 	IMA_OID oid, addressOid;
4213fcf3ce44SJohn Forte 	SUN_IMA_TARGET_ADDRESS address;
4214fcf3ce44SJohn Forte 	wchar_t wcInputObject[MAX_ADDRESS_LEN + 1];
4215fcf3ce44SJohn Forte 	int ret;
4216fcf3ce44SJohn Forte 	int i;
4217fcf3ce44SJohn Forte 
4218fcf3ce44SJohn Forte 	assert(funcRet != NULL);
4219fcf3ce44SJohn Forte 
4220fcf3ce44SJohn Forte 	/* Find Sun initiator */
4221fcf3ce44SJohn Forte 	ret = sunInitiatorFind(&oid);
4222fcf3ce44SJohn Forte 	if (ret > 0) {
4223fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n",
4224fcf3ce44SJohn Forte 		    cmdName, gettext("no initiator found"));
4225fcf3ce44SJohn Forte 	}
4226fcf3ce44SJohn Forte 
4227fcf3ce44SJohn Forte 	if (ret != 0) {
4228fcf3ce44SJohn Forte 		return (ret);
4229fcf3ce44SJohn Forte 	}
4230fcf3ce44SJohn Forte 
4231fcf3ce44SJohn Forte 	/*
4232fcf3ce44SJohn Forte 	 * Format of discovery address operand:
4233fcf3ce44SJohn Forte 	 *
4234fcf3ce44SJohn Forte 	 * <IP address|hostname>:<port>
4235fcf3ce44SJohn Forte 	 */
4236fcf3ce44SJohn Forte 	for (i = 0; i < operandLen; i++) {
4237fcf3ce44SJohn Forte 		/* initialize */
4238fcf3ce44SJohn Forte 		(void) memset(&wcInputObject[0], 0, sizeof (wcInputObject));
4239fcf3ce44SJohn Forte 		(void) memset(&address, 0, sizeof (address));
4240fcf3ce44SJohn Forte 
4241fcf3ce44SJohn Forte 		if (mbstowcs(wcInputObject, operand[i],
4242fcf3ce44SJohn Forte 		    (MAX_ADDRESS_LEN + 1)) == (size_t)-1) {
4243fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n",
4244fcf3ce44SJohn Forte 			    cmdName, gettext("conversion error"));
4245fcf3ce44SJohn Forte 			ret = 1;
4246fcf3ce44SJohn Forte 			continue;
4247fcf3ce44SJohn Forte 		}
4248fcf3ce44SJohn Forte 		if (getTargetAddress(addrType, operand[i], &address.imaStruct)
4249fcf3ce44SJohn Forte 		    != 0) {
4250fcf3ce44SJohn Forte 			ret = 1;
4251fcf3ce44SJohn Forte 			continue;
4252fcf3ce44SJohn Forte 		}
4253fcf3ce44SJohn Forte 		if (addrType == DISCOVERY_ADDRESS) {
4254fcf3ce44SJohn Forte 			status = IMA_AddDiscoveryAddress(oid,
4255fcf3ce44SJohn Forte 			    address.imaStruct, &addressOid);
4256fcf3ce44SJohn Forte 			if (!IMA_SUCCESS(status)) {
4257fcf3ce44SJohn Forte 				printLibError(status);
4258fcf3ce44SJohn Forte 				*funcRet = 1;
4259fcf3ce44SJohn Forte 				return (ret);
4260fcf3ce44SJohn Forte 			}
4261fcf3ce44SJohn Forte 		} else if (addrType == ISNS_SERVER_ADDRESS) {
4262fcf3ce44SJohn Forte 			status = SUN_IMA_AddISNSServerAddress(address);
4263fcf3ce44SJohn Forte 			if (!IMA_SUCCESS(status)) {
4264fcf3ce44SJohn Forte 				printLibError(status);
4265fcf3ce44SJohn Forte 				*funcRet = 1;
4266fcf3ce44SJohn Forte 				return (ret);
4267fcf3ce44SJohn Forte 			}
4268fcf3ce44SJohn Forte 		}
4269fcf3ce44SJohn Forte 	}
4270fcf3ce44SJohn Forte 	return (ret);
4271fcf3ce44SJohn Forte }
4272fcf3ce44SJohn Forte 
4273fcf3ce44SJohn Forte /*
4274fcf3ce44SJohn Forte  * Add one or more static configuration targets
4275fcf3ce44SJohn Forte  */
4276fcf3ce44SJohn Forte static int
addStaticConfig(int operandLen,char * operand[],int * funcRet)4277fcf3ce44SJohn Forte addStaticConfig(int operandLen, char *operand[], int *funcRet)
4278fcf3ce44SJohn Forte {
4279fcf3ce44SJohn Forte 	int i;
4280fcf3ce44SJohn Forte 	boolean_t targetAddressSpecified = B_FALSE;
4281fcf3ce44SJohn Forte 	boolean_t tpgtSpecified = B_FALSE;
4282fcf3ce44SJohn Forte 	boolean_t isIpv6 = B_FALSE;
4283fcf3ce44SJohn Forte 	int ret;
4284fcf3ce44SJohn Forte 	int addrType;
4285fcf3ce44SJohn Forte 	IMA_STATUS status;
4286fcf3ce44SJohn Forte 	IMA_OID oid;
4287fcf3ce44SJohn Forte 	SUN_IMA_STATIC_DISCOVERY_TARGET staticConfig;
4288fcf3ce44SJohn Forte 	IMA_UINT16 port = 0;
4289fcf3ce44SJohn Forte 	IMA_UINT16 tpgt = 0;
4290fcf3ce44SJohn Forte 	wchar_t staticTargetName[MAX_ISCSI_NAME_LEN + 1];
4291fcf3ce44SJohn Forte 	wchar_t staticTargetAddress[SUN_IMA_IP_ADDRESS_PORT_LEN];
4292fcf3ce44SJohn Forte 	iSCSINameCheckStatusType nameCheckStatus;
4293fcf3ce44SJohn Forte 	char sAddr[SUN_IMA_IP_ADDRESS_PORT_LEN];
4294fcf3ce44SJohn Forte 
4295fcf3ce44SJohn Forte 	assert(funcRet != NULL);
4296fcf3ce44SJohn Forte 
4297fcf3ce44SJohn Forte 	/* Find Sun initiator */
4298fcf3ce44SJohn Forte 	ret = sunInitiatorFind(&oid);
4299fcf3ce44SJohn Forte 	if (ret > 0) {
4300fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n",
4301fcf3ce44SJohn Forte 		    cmdName, gettext("no initiator found"));
4302fcf3ce44SJohn Forte 	}
4303fcf3ce44SJohn Forte 
4304fcf3ce44SJohn Forte 	if (ret != 0) {
4305fcf3ce44SJohn Forte 		return (ret);
4306fcf3ce44SJohn Forte 	}
4307fcf3ce44SJohn Forte 
4308fcf3ce44SJohn Forte 	/*
4309fcf3ce44SJohn Forte 	 * Format of static config operand:
4310fcf3ce44SJohn Forte 	 *  <target-name>,<IP address|hostname>[:port][,tpgt]
4311fcf3ce44SJohn Forte 	 */
4312fcf3ce44SJohn Forte 	for (i = 0; i < operandLen; i++) {
4313fcf3ce44SJohn Forte 		if (parseTarget(operand[i],
4314fcf3ce44SJohn Forte 		    &staticTargetName[0],
4315fcf3ce44SJohn Forte 		    MAX_ISCSI_NAME_LEN + 1,
4316fcf3ce44SJohn Forte 		    &targetAddressSpecified,
4317fcf3ce44SJohn Forte 		    &staticTargetAddress[0],
4318fcf3ce44SJohn Forte 		    SUN_IMA_IP_ADDRESS_PORT_LEN,
4319fcf3ce44SJohn Forte 		    &port,
4320fcf3ce44SJohn Forte 		    &tpgtSpecified,
4321fcf3ce44SJohn Forte 		    &tpgt,
4322fcf3ce44SJohn Forte 		    &isIpv6) != PARSE_TARGET_OK) {
4323fcf3ce44SJohn Forte 			ret = 1;
4324fcf3ce44SJohn Forte 			continue;
4325fcf3ce44SJohn Forte 		}
4326fcf3ce44SJohn Forte 
4327fcf3ce44SJohn Forte 		if (targetAddressSpecified != B_TRUE) {
4328fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n",
4329fcf3ce44SJohn Forte 			    cmdName, gettext("missing target address"));
4330fcf3ce44SJohn Forte 			*funcRet = 1; /* DIY message fix */
4331fcf3ce44SJohn Forte 			return (1);
4332fcf3ce44SJohn Forte 		}
4333fcf3ce44SJohn Forte 		/* Perform string profile checks */
4334fcf3ce44SJohn Forte 		nameCheckStatus = iSCSINameStringProfileCheck(staticTargetName);
4335fcf3ce44SJohn Forte 		iSCSINameCheckStatusDisplay(nameCheckStatus);
4336fcf3ce44SJohn Forte 		if (nameCheckStatus != iSCSINameCheckOK) {
4337fcf3ce44SJohn Forte 			*funcRet = 1; /* DIY message fix */
4338fcf3ce44SJohn Forte 			return (1);
4339fcf3ce44SJohn Forte 		}
4340fcf3ce44SJohn Forte 		(void) wcsncpy(staticConfig.targetName, staticTargetName,
4341fcf3ce44SJohn Forte 		    MAX_ISCSI_NAME_LEN + 1);
4342fcf3ce44SJohn Forte 
4343fcf3ce44SJohn Forte 		(void) wcstombs(sAddr, staticTargetAddress, sizeof (sAddr));
4344fcf3ce44SJohn Forte 
4345fcf3ce44SJohn Forte 		if (isIpv6 == B_TRUE) {
4346fcf3ce44SJohn Forte 			staticConfig.targetAddress.imaStruct.hostnameIpAddress.
4347fcf3ce44SJohn Forte 			    id.ipAddress.ipv4Address = B_FALSE;
4348fcf3ce44SJohn Forte 			addrType = AF_INET6;
4349fcf3ce44SJohn Forte 		} else {
4350fcf3ce44SJohn Forte 			staticConfig.targetAddress.imaStruct.hostnameIpAddress.
4351fcf3ce44SJohn Forte 			    id.ipAddress.ipv4Address = B_TRUE;
4352fcf3ce44SJohn Forte 			addrType = AF_INET;
4353fcf3ce44SJohn Forte 		}
4354fcf3ce44SJohn Forte 
4355fcf3ce44SJohn Forte 		if (inet_pton(addrType, sAddr, staticConfig.targetAddress.
4356fcf3ce44SJohn Forte 		    imaStruct.hostnameIpAddress.id.ipAddress.ipAddress) != 1) {
4357fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n",
4358fcf3ce44SJohn Forte 			    cmdName, gettext("static config conversion error"));
4359fcf3ce44SJohn Forte 			ret = 1;
4360fcf3ce44SJohn Forte 			continue;
4361fcf3ce44SJohn Forte 		}
4362fcf3ce44SJohn Forte 
4363fcf3ce44SJohn Forte 		staticConfig.targetAddress.imaStruct.portNumber = port;
4364fcf3ce44SJohn Forte 		if (tpgtSpecified == B_TRUE) {
4365fcf3ce44SJohn Forte 			staticConfig.targetAddress.defaultTpgt = B_FALSE;
4366fcf3ce44SJohn Forte 			staticConfig.targetAddress.tpgt = tpgt;
4367fcf3ce44SJohn Forte 		} else {
4368fcf3ce44SJohn Forte 			staticConfig.targetAddress.defaultTpgt = B_TRUE;
4369fcf3ce44SJohn Forte 			staticConfig.targetAddress.tpgt = 0;
4370fcf3ce44SJohn Forte 		}
4371fcf3ce44SJohn Forte 
4372fcf3ce44SJohn Forte 		status = SUN_IMA_AddStaticTarget(oid, staticConfig, &oid);
4373fcf3ce44SJohn Forte 		if (!IMA_SUCCESS(status)) {
4374fcf3ce44SJohn Forte 			printLibError(status);
4375fcf3ce44SJohn Forte 			*funcRet = 1;
4376fcf3ce44SJohn Forte 			return (1);
4377fcf3ce44SJohn Forte 		}
4378fcf3ce44SJohn Forte 	}
43795df5713fSbing zhao - Sun Microsystems - Beijing China 
43805df5713fSbing zhao - Sun Microsystems - Beijing China 	if (ret != 0) {
43815df5713fSbing zhao - Sun Microsystems - Beijing China 		*funcRet = 1;
43825df5713fSbing zhao - Sun Microsystems - Beijing China 	}
43835df5713fSbing zhao - Sun Microsystems - Beijing China 
4384fcf3ce44SJohn Forte 	return (ret);
4385fcf3ce44SJohn Forte }
4386fcf3ce44SJohn Forte 
4387fcf3ce44SJohn Forte /*
4388fcf3ce44SJohn Forte  * Remove one or more addresses
4389fcf3ce44SJohn Forte  */
4390fcf3ce44SJohn Forte static int
removeAddress(int addrType,int operandLen,char * operand[],int * funcRet)4391fcf3ce44SJohn Forte removeAddress(int addrType, int operandLen, char *operand[], int *funcRet)
4392fcf3ce44SJohn Forte {
4393fcf3ce44SJohn Forte 	IMA_STATUS status;
4394fcf3ce44SJohn Forte 	IMA_OID initiatorOid;
4395fcf3ce44SJohn Forte 	SUN_IMA_TARGET_ADDRESS address;
4396fcf3ce44SJohn Forte 	wchar_t wcInputObject[MAX_ADDRESS_LEN + 1];
4397fcf3ce44SJohn Forte 	int ret;
4398fcf3ce44SJohn Forte 	int i;
4399fcf3ce44SJohn Forte 
4400fcf3ce44SJohn Forte 	assert(funcRet != NULL);
4401fcf3ce44SJohn Forte 
4402fcf3ce44SJohn Forte 	/* Find Sun initiator */
4403fcf3ce44SJohn Forte 	ret = sunInitiatorFind(&initiatorOid);
4404fcf3ce44SJohn Forte 	if (ret > 0) {
4405fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n",
4406fcf3ce44SJohn Forte 		    cmdName, gettext("no initiator found"));
4407fcf3ce44SJohn Forte 	}
4408fcf3ce44SJohn Forte 
4409fcf3ce44SJohn Forte 	if (ret != 0) {
4410fcf3ce44SJohn Forte 		return (ret);
4411fcf3ce44SJohn Forte 	}
4412fcf3ce44SJohn Forte 
4413fcf3ce44SJohn Forte 	for (i = 0; i < operandLen; i++) {
4414fcf3ce44SJohn Forte 		/* initialize */
4415fcf3ce44SJohn Forte 		(void) memset(&wcInputObject[0], 0, sizeof (wcInputObject));
4416fcf3ce44SJohn Forte 		(void) memset(&address, 0, sizeof (address));
4417fcf3ce44SJohn Forte 
4418fcf3ce44SJohn Forte 		if (mbstowcs(wcInputObject, operand[i],
4419fcf3ce44SJohn Forte 		    MAX_ADDRESS_LEN + 1) == (size_t)-1) {
4420fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n",
4421fcf3ce44SJohn Forte 			    cmdName, gettext("conversion error"));
4422fcf3ce44SJohn Forte 			ret = 1;
4423fcf3ce44SJohn Forte 			continue;
4424fcf3ce44SJohn Forte 		}
4425fcf3ce44SJohn Forte 
4426fcf3ce44SJohn Forte 		if (getTargetAddress(addrType, operand[i], &address.imaStruct)
4427fcf3ce44SJohn Forte 		    != 0) {
4428fcf3ce44SJohn Forte 			ret = 1;
4429fcf3ce44SJohn Forte 			continue;
4430fcf3ce44SJohn Forte 		}
4431fcf3ce44SJohn Forte 
4432fcf3ce44SJohn Forte 		if (addrType == DISCOVERY_ADDRESS) {
4433fcf3ce44SJohn Forte 			status = SUN_IMA_RemoveDiscoveryAddress(address);
4434fcf3ce44SJohn Forte 			if (!IMA_SUCCESS(status)) {
4435fcf3ce44SJohn Forte 				if (status == IMA_ERROR_OBJECT_NOT_FOUND) {
4436fcf3ce44SJohn Forte 					(void) fprintf(stderr, "%s: %s\n",
4437fcf3ce44SJohn Forte 					    operand[i], gettext("not found"));
4438fcf3ce44SJohn Forte 				} else {
4439fcf3ce44SJohn Forte 					printLibError(status);
4440fcf3ce44SJohn Forte 				}
4441fcf3ce44SJohn Forte 				*funcRet = 1;
4442fcf3ce44SJohn Forte 			}
4443fcf3ce44SJohn Forte 		} else {
4444fcf3ce44SJohn Forte 			status = SUN_IMA_RemoveISNSServerAddress(address);
4445fcf3ce44SJohn Forte 			if (!IMA_SUCCESS(status)) {
4446fcf3ce44SJohn Forte 				printLibError(status);
4447fcf3ce44SJohn Forte 				*funcRet = 1;
4448fcf3ce44SJohn Forte 			}
4449fcf3ce44SJohn Forte 		}
4450fcf3ce44SJohn Forte 	}
4451fcf3ce44SJohn Forte 	return (ret);
4452fcf3ce44SJohn Forte }
4453fcf3ce44SJohn Forte 
4454fcf3ce44SJohn Forte /*
4455fcf3ce44SJohn Forte  * Remove one or more static configuration targets
4456fcf3ce44SJohn Forte  */
4457fcf3ce44SJohn Forte static int
removeStaticConfig(int operandLen,char * operand[],int * funcRet)4458fcf3ce44SJohn Forte removeStaticConfig(int operandLen, char *operand[], int *funcRet)
4459fcf3ce44SJohn Forte {
4460fcf3ce44SJohn Forte 	IMA_STATUS status;
4461fcf3ce44SJohn Forte 	IMA_OID initiatorOid;
4462fcf3ce44SJohn Forte 	IMA_OID_LIST *staticTargetList;
4463fcf3ce44SJohn Forte 	SUN_IMA_STATIC_TARGET_PROPERTIES staticTargetProps;
4464fcf3ce44SJohn Forte 	wchar_t staticTargetName[MAX_ISCSI_NAME_LEN + 1];
4465fcf3ce44SJohn Forte 	wchar_t staticTargetAddress[SUN_IMA_IP_ADDRESS_PORT_LEN];
4466fcf3ce44SJohn Forte 	int ret;
4467fcf3ce44SJohn Forte 	boolean_t atLeastFoundOne;
4468fcf3ce44SJohn Forte 	boolean_t matched;
4469fcf3ce44SJohn Forte 	boolean_t targetAddressSpecified = B_TRUE;
4470fcf3ce44SJohn Forte 	boolean_t tpgtSpecified = B_FALSE;
4471fcf3ce44SJohn Forte 	boolean_t isIpv6 = B_FALSE;
4472fcf3ce44SJohn Forte 	int i, j;
4473fcf3ce44SJohn Forte 	IMA_UINT16 port = 0;
4474fcf3ce44SJohn Forte 	IMA_UINT16 tpgt = 0;
4475fcf3ce44SJohn Forte 	iSCSINameCheckStatusType nameCheckStatus;
4476fcf3ce44SJohn Forte 	char tmpStr[SUN_IMA_IP_ADDRESS_PORT_LEN];
4477fcf3ce44SJohn Forte 	wchar_t tmpTargetAddress[SUN_IMA_IP_ADDRESS_PORT_LEN];
4478fcf3ce44SJohn Forte 
4479fcf3ce44SJohn Forte 	assert(funcRet != NULL);
4480fcf3ce44SJohn Forte 
4481fcf3ce44SJohn Forte 	/* Find Sun initiator */
4482fcf3ce44SJohn Forte 	ret = sunInitiatorFind(&initiatorOid);
4483fcf3ce44SJohn Forte 	if (ret > 0) {
4484fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n",
4485fcf3ce44SJohn Forte 		    cmdName, gettext("no initiator found"));
4486fcf3ce44SJohn Forte 	}
4487fcf3ce44SJohn Forte 
4488fcf3ce44SJohn Forte 	if (ret != 0) {
4489fcf3ce44SJohn Forte 		return (ret);
4490fcf3ce44SJohn Forte 	}
4491fcf3ce44SJohn Forte 
4492fcf3ce44SJohn Forte 	status = IMA_GetStaticDiscoveryTargetOidList(initiatorOid,
4493fcf3ce44SJohn Forte 	    &staticTargetList);
4494fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
4495fcf3ce44SJohn Forte 		printLibError(status);
4496fcf3ce44SJohn Forte 		*funcRet = 1;
4497fcf3ce44SJohn Forte 		return (ret);
4498fcf3ce44SJohn Forte 	}
4499fcf3ce44SJohn Forte 
4500fcf3ce44SJohn Forte 	for (i = 0; i < operandLen; i++) {
4501fcf3ce44SJohn Forte 		if (parseTarget(operand[i],
4502fcf3ce44SJohn Forte 		    &staticTargetName[0],
4503fcf3ce44SJohn Forte 		    MAX_ISCSI_NAME_LEN + 1,
4504fcf3ce44SJohn Forte 		    &targetAddressSpecified,
4505fcf3ce44SJohn Forte 		    &staticTargetAddress[0],
4506fcf3ce44SJohn Forte 		    SUN_IMA_IP_ADDRESS_PORT_LEN,
4507fcf3ce44SJohn Forte 		    &port,
4508fcf3ce44SJohn Forte 		    &tpgtSpecified,
4509fcf3ce44SJohn Forte 		    &tpgt,
4510fcf3ce44SJohn Forte 		    &isIpv6) != PARSE_TARGET_OK) {
4511fcf3ce44SJohn Forte 			ret = 1;
4512fcf3ce44SJohn Forte 			continue;
4513fcf3ce44SJohn Forte 		}
4514fcf3ce44SJohn Forte 
4515fcf3ce44SJohn Forte 		/* Perform string profile checks */
4516fcf3ce44SJohn Forte 		nameCheckStatus = iSCSINameStringProfileCheck(staticTargetName);
4517fcf3ce44SJohn Forte 		iSCSINameCheckStatusDisplay(nameCheckStatus);
4518fcf3ce44SJohn Forte 		if (nameCheckStatus != iSCSINameCheckOK) {
4519fcf3ce44SJohn Forte 			return (1);
4520fcf3ce44SJohn Forte 		}
4521fcf3ce44SJohn Forte 
4522fcf3ce44SJohn Forte 		for (atLeastFoundOne = B_FALSE, j = 0;
4523fcf3ce44SJohn Forte 		    j < staticTargetList->oidCount;
4524fcf3ce44SJohn Forte 		    j++) {
4525fcf3ce44SJohn Forte 			IMA_UINT16 stpgt;
4526fcf3ce44SJohn Forte 
4527fcf3ce44SJohn Forte 			matched = B_FALSE;
4528fcf3ce44SJohn Forte 			status = SUN_IMA_GetStaticTargetProperties(
4529fcf3ce44SJohn Forte 			    staticTargetList->oids[j], &staticTargetProps);
4530fcf3ce44SJohn Forte 			if (!IMA_SUCCESS(status)) {
4531fcf3ce44SJohn Forte 				if (status == IMA_ERROR_OBJECT_NOT_FOUND) {
4532fcf3ce44SJohn Forte 					/*
4533fcf3ce44SJohn Forte 					 * When removing multiple static-config
4534fcf3ce44SJohn Forte 					 * entries we need to expect get
4535fcf3ce44SJohn Forte 					 * failures. These failures occur when
4536fcf3ce44SJohn Forte 					 * we are trying to get entry
4537fcf3ce44SJohn Forte 					 * information we have just removed.
4538fcf3ce44SJohn Forte 					 * Ignore the failure and continue.
4539fcf3ce44SJohn Forte 					 */
4540fcf3ce44SJohn Forte 					ret = 1;
4541fcf3ce44SJohn Forte 					continue;
4542fcf3ce44SJohn Forte 				} else {
4543fcf3ce44SJohn Forte 					printLibError(status);
4544fcf3ce44SJohn Forte 					(void) IMA_FreeMemory(staticTargetList);
4545fcf3ce44SJohn Forte 					*funcRet = 1;
4546fcf3ce44SJohn Forte 					return (ret);
4547fcf3ce44SJohn Forte 				}
4548fcf3ce44SJohn Forte 			}
4549fcf3ce44SJohn Forte 
4550fcf3ce44SJohn Forte 			stpgt =
4551fcf3ce44SJohn Forte 			    staticTargetProps.staticTarget.targetAddress.tpgt;
4552fcf3ce44SJohn Forte 
4553fcf3ce44SJohn Forte 			/*
4554fcf3ce44SJohn Forte 			 * Compare the static target name with the input if
4555fcf3ce44SJohn Forte 			 * one was input
4556fcf3ce44SJohn Forte 			 */
4557fcf3ce44SJohn Forte 			if ((targetNamesEqual(
4558fcf3ce44SJohn Forte 			    staticTargetProps.staticTarget.targetName,
4559fcf3ce44SJohn Forte 			    staticTargetName) == B_TRUE)) {
4560fcf3ce44SJohn Forte 				if (targetAddressSpecified == B_FALSE) {
4561fcf3ce44SJohn Forte 					matched = B_TRUE;
4562fcf3ce44SJohn Forte 				} else {
4563fcf3ce44SJohn Forte 
4564fcf3ce44SJohn Forte 					if (staticTargetProps.staticTarget.
4565fcf3ce44SJohn Forte 					    targetAddress.imaStruct.
4566fcf3ce44SJohn Forte 					    hostnameIpAddress.
4567fcf3ce44SJohn Forte 					    id.ipAddress.ipv4Address ==
4568fcf3ce44SJohn Forte 					    IMA_TRUE) {
4569fcf3ce44SJohn Forte 						(void) inet_ntop(AF_INET,
4570fcf3ce44SJohn Forte 						    staticTargetProps.
4571fcf3ce44SJohn Forte 						    staticTarget.targetAddress.
4572fcf3ce44SJohn Forte 						    imaStruct.hostnameIpAddress.
4573fcf3ce44SJohn Forte 						    id.ipAddress.ipAddress,
4574fcf3ce44SJohn Forte 						    tmpStr,
4575fcf3ce44SJohn Forte 						    sizeof (tmpStr));
4576fcf3ce44SJohn Forte 					} else {
4577fcf3ce44SJohn Forte 						(void) inet_ntop(AF_INET6,
4578fcf3ce44SJohn Forte 						    staticTargetProps.
4579fcf3ce44SJohn Forte 						    staticTarget.targetAddress.
4580fcf3ce44SJohn Forte 						    imaStruct.hostnameIpAddress.
4581fcf3ce44SJohn Forte 						    id.ipAddress.ipAddress,
4582fcf3ce44SJohn Forte 						    tmpStr,
4583fcf3ce44SJohn Forte 						    sizeof (tmpStr));
4584fcf3ce44SJohn Forte 					}
4585fcf3ce44SJohn Forte 
4586fcf3ce44SJohn Forte 					if (mbstowcs(tmpTargetAddress, tmpStr,
4587fcf3ce44SJohn Forte 					    SUN_IMA_IP_ADDRESS_PORT_LEN) ==
4588fcf3ce44SJohn Forte 					    (size_t)-1) {
4589fcf3ce44SJohn Forte 						(void) fprintf(stderr,
4590fcf3ce44SJohn Forte 						    "%s: %s\n",
4591fcf3ce44SJohn Forte 						    cmdName, gettext(
4592fcf3ce44SJohn Forte 						    "conversion error"));
4593fcf3ce44SJohn Forte 						ret = 1;
4594fcf3ce44SJohn Forte 						continue;
4595fcf3ce44SJohn Forte 					}
4596fcf3ce44SJohn Forte 
4597fcf3ce44SJohn Forte 					if ((wcsncmp(tmpTargetAddress,
4598fcf3ce44SJohn Forte 					    staticTargetAddress,
4599fcf3ce44SJohn Forte 					    SUN_IMA_IP_ADDRESS_PORT_LEN) ==
4600fcf3ce44SJohn Forte 					    0) && (staticTargetProps.
4601fcf3ce44SJohn Forte 					    staticTarget.targetAddress.
4602fcf3ce44SJohn Forte 					    imaStruct.portNumber == port)) {
4603fcf3ce44SJohn Forte 						if (tpgtSpecified == B_FALSE) {
4604fcf3ce44SJohn Forte 							matched = B_TRUE;
4605fcf3ce44SJohn Forte 						} else {
4606fcf3ce44SJohn Forte 							if (tpgt == stpgt) {
4607fcf3ce44SJohn Forte 								matched =
4608fcf3ce44SJohn Forte 								    B_TRUE;
4609fcf3ce44SJohn Forte 							}
4610fcf3ce44SJohn Forte 						}
4611fcf3ce44SJohn Forte 					}
4612fcf3ce44SJohn Forte 				}
4613fcf3ce44SJohn Forte 
4614fcf3ce44SJohn Forte 				if (matched) {
4615fcf3ce44SJohn Forte 					status =
4616fcf3ce44SJohn Forte 					    IMA_RemoveStaticDiscoveryTarget(
4617fcf3ce44SJohn Forte 					    staticTargetList->oids[j]);
4618fcf3ce44SJohn Forte 					if (!IMA_SUCCESS(status)) {
4619fcf3ce44SJohn Forte 						printLibError(status);
4620fcf3ce44SJohn Forte 						*funcRet = 1;
4621fcf3ce44SJohn Forte 						return (ret);
4622fcf3ce44SJohn Forte 					}
4623fcf3ce44SJohn Forte 					atLeastFoundOne = B_TRUE;
4624fcf3ce44SJohn Forte 				}
4625fcf3ce44SJohn Forte 			}
4626fcf3ce44SJohn Forte 		}
4627fcf3ce44SJohn Forte 		if (!atLeastFoundOne) {
4628fcf3ce44SJohn Forte 			(void) fprintf(stderr, gettext("%ws,%ws: %s\n"),
4629fcf3ce44SJohn Forte 			    staticTargetName, staticTargetAddress,
4630fcf3ce44SJohn Forte 			    gettext("not found"));
4631fcf3ce44SJohn Forte 		}
4632fcf3ce44SJohn Forte 	}
4633fcf3ce44SJohn Forte 	return (ret);
4634fcf3ce44SJohn Forte }
4635fcf3ce44SJohn Forte 
4636fcf3ce44SJohn Forte /*
4637fcf3ce44SJohn Forte  * Remove one or more target params.
4638fcf3ce44SJohn Forte  */
4639fcf3ce44SJohn Forte static int
removeTargetParam(int operandLen,char * operand[],int * funcRet)4640fcf3ce44SJohn Forte removeTargetParam(int operandLen, char *operand[], int *funcRet)
4641fcf3ce44SJohn Forte {
4642fcf3ce44SJohn Forte 	char *commaPos;
4643fcf3ce44SJohn Forte 	IMA_STATUS status;
4644fcf3ce44SJohn Forte 	IMA_OID initiatorOid;
4645fcf3ce44SJohn Forte 	IMA_OID_LIST *targetList;
4646fcf3ce44SJohn Forte 	SUN_IMA_TARGET_PROPERTIES targetProps;
4647fcf3ce44SJohn Forte 	wchar_t wcInputObject[MAX_ISCSI_NAME_LEN + 1];
4648fcf3ce44SJohn Forte 	int ret;
4649fcf3ce44SJohn Forte 	boolean_t found;
4650fcf3ce44SJohn Forte 	int i, j;
46516cefaae1SJack Meng 	IMA_NODE_NAME bootTargetName;
46526cefaae1SJack Meng 	IMA_BOOL	iscsiBoot = IMA_FALSE;
46536cefaae1SJack Meng 	IMA_BOOL	mpxioEnabled = IMA_FALSE;
46546cefaae1SJack Meng 
46556cefaae1SJack Meng 	/* Get boot session's info */
46566cefaae1SJack Meng 	(void) SUN_IMA_GetBootIscsi(&iscsiBoot);
46576cefaae1SJack Meng 	if (iscsiBoot == IMA_TRUE) {
46586cefaae1SJack Meng 		status = SUN_IMA_GetBootMpxio(&mpxioEnabled);
46596cefaae1SJack Meng 		if (!IMA_SUCCESS(status)) {
46606cefaae1SJack Meng 			(void) fprintf(stderr, "%s: %s\n",
46616cefaae1SJack Meng 			    cmdName, gettext("unable to get MPxIO info of"
46626cefaae1SJack Meng 			    " root disk"));
46636cefaae1SJack Meng 			*funcRet = 1;
46646cefaae1SJack Meng 			return (1);
46656cefaae1SJack Meng 		}
46666cefaae1SJack Meng 		status = SUN_IMA_GetBootTargetName(bootTargetName);
46676cefaae1SJack Meng 		if (!IMA_SUCCESS(status)) {
46686cefaae1SJack Meng 			(void) fprintf(stderr, "%s: %s\n",
46696cefaae1SJack Meng 			    cmdName, gettext("unable to get boot"
46706cefaae1SJack Meng 			    " target's name"));
46716cefaae1SJack Meng 			*funcRet = 1;
46726cefaae1SJack Meng 			return (1);
46736cefaae1SJack Meng 		}
46746cefaae1SJack Meng 	}
4675fcf3ce44SJohn Forte 
4676fcf3ce44SJohn Forte 	assert(funcRet != NULL);
4677fcf3ce44SJohn Forte 
4678fcf3ce44SJohn Forte 	/* Find Sun initiator */
4679fcf3ce44SJohn Forte 	ret = sunInitiatorFind(&initiatorOid);
4680fcf3ce44SJohn Forte 	if (ret > 0) {
4681fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n",
4682fcf3ce44SJohn Forte 		    cmdName, gettext("no initiator found"));
4683fcf3ce44SJohn Forte 	}
4684fcf3ce44SJohn Forte 
4685fcf3ce44SJohn Forte 	if (ret != 0) {
4686fcf3ce44SJohn Forte 		return (ret);
4687fcf3ce44SJohn Forte 	}
4688fcf3ce44SJohn Forte 
4689fcf3ce44SJohn Forte 	status = IMA_GetTargetOidList(initiatorOid, &targetList);
4690fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
4691fcf3ce44SJohn Forte 		printLibError(status);
4692fcf3ce44SJohn Forte 		*funcRet = 1;
4693fcf3ce44SJohn Forte 		return (ret);
4694fcf3ce44SJohn Forte 	}
4695fcf3ce44SJohn Forte 
4696fcf3ce44SJohn Forte 	for (i = 0; i < operandLen; i++) {
4697fcf3ce44SJohn Forte 		/* initialize */
4698fcf3ce44SJohn Forte 		commaPos = strchr(operand[i], ',');
4699fcf3ce44SJohn Forte 		if (commaPos) {
4700fcf3ce44SJohn Forte 			/* Ignore IP address. */
470133c72b75SToomas Soome 			*commaPos = '\0';
4702fcf3ce44SJohn Forte 		}
4703fcf3ce44SJohn Forte 		(void) memset(&wcInputObject[0], 0, sizeof (wcInputObject));
4704fcf3ce44SJohn Forte 		if (mbstowcs(wcInputObject, operand[i],
4705fcf3ce44SJohn Forte 		    MAX_ISCSI_NAME_LEN + 1) == (size_t)-1) {
4706fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
4707fcf3ce44SJohn Forte 			    gettext("conversion error"));
4708fcf3ce44SJohn Forte 			ret = 1;
4709fcf3ce44SJohn Forte 			continue;
4710fcf3ce44SJohn Forte 		}
4711fcf3ce44SJohn Forte 
4712fcf3ce44SJohn Forte 		for (found = B_FALSE, j = 0; j < targetList->oidCount;
4713fcf3ce44SJohn Forte 		    j++) {
4714fcf3ce44SJohn Forte 			status = SUN_IMA_GetTargetProperties(
4715fcf3ce44SJohn Forte 			    targetList->oids[j], &targetProps);
4716fcf3ce44SJohn Forte 			if (!IMA_SUCCESS(status)) {
4717fcf3ce44SJohn Forte 				printLibError(status);
4718fcf3ce44SJohn Forte 				(void) IMA_FreeMemory(targetList);
4719fcf3ce44SJohn Forte 				*funcRet = 1;
4720fcf3ce44SJohn Forte 				return (ret);
4721fcf3ce44SJohn Forte 			}
4722fcf3ce44SJohn Forte 
4723fcf3ce44SJohn Forte 			/*
4724fcf3ce44SJohn Forte 			 * Compare the target name with the input if
4725fcf3ce44SJohn Forte 			 * one was input
4726fcf3ce44SJohn Forte 			 */
4727fcf3ce44SJohn Forte 			if (targetNamesEqual(targetProps.imaProps.name,
4728fcf3ce44SJohn Forte 			    wcInputObject) == B_TRUE) {
4729fcf3ce44SJohn Forte 				found = B_TRUE;
47306cefaae1SJack Meng 				if ((targetNamesEqual(bootTargetName,
47316cefaae1SJack Meng 				    wcInputObject) == B_TRUE) &&
47326cefaae1SJack Meng 				    (iscsiBoot == IMA_TRUE)) {
47336cefaae1SJack Meng 					/*
47346cefaae1SJack Meng 					 * iscsi booting, need changed target
47356cefaae1SJack Meng 					 * param is booting target, booting
47366cefaae1SJack Meng 					 * session mpxio disabled, not
47376cefaae1SJack Meng 					 * allow to update
47386cefaae1SJack Meng 					 */
47396cefaae1SJack Meng 					if (mpxioEnabled == IMA_FALSE) {
47406cefaae1SJack Meng 						(void) fprintf(stderr,
47416cefaae1SJack Meng 						    "%s: %s\n", cmdName,
47426cefaae1SJack Meng 						    gettext("iscsi boot"
47436cefaae1SJack Meng 						    " with MPxIO disabled,"
47446cefaae1SJack Meng 						    " not allowed to remove"
47456cefaae1SJack Meng 						    " boot sess param"));
4746f03fb72cSyi zhang - Sun Microsystems - Beijing China 						ret = 1;
47476cefaae1SJack Meng 						continue;
47486cefaae1SJack Meng 					}
47496cefaae1SJack Meng 
47506cefaae1SJack Meng 				}
47516cefaae1SJack Meng 
4752fcf3ce44SJohn Forte 				status = SUN_IMA_RemoveTargetParam(
4753fcf3ce44SJohn Forte 				    targetList->oids[j]);
4754fcf3ce44SJohn Forte 				if (!IMA_SUCCESS(status)) {
4755fcf3ce44SJohn Forte 					printLibError(status);
4756fcf3ce44SJohn Forte 					(void) IMA_FreeMemory(targetList);
4757fcf3ce44SJohn Forte 					*funcRet = 1;
4758fcf3ce44SJohn Forte 					return (ret);
4759fcf3ce44SJohn Forte 				}
4760fcf3ce44SJohn Forte 			}
4761fcf3ce44SJohn Forte 		}
4762fcf3ce44SJohn Forte 		if (!found) {
4763fcf3ce44SJohn Forte 			/* Silently ignoring it? */
4764fcf3ce44SJohn Forte 			(void) fprintf(stderr, gettext("%ws: %s\n"),
4765fcf3ce44SJohn Forte 			    wcInputObject, gettext("not found"));
4766fcf3ce44SJohn Forte 		}
4767fcf3ce44SJohn Forte 	}
4768fcf3ce44SJohn Forte 
4769fcf3ce44SJohn Forte 	(void) IMA_FreeMemory(targetList);
4770fcf3ce44SJohn Forte 	return (ret);
4771fcf3ce44SJohn Forte }
4772fcf3ce44SJohn Forte 
4773fcf3ce44SJohn Forte /*ARGSUSED*/
4774fcf3ce44SJohn Forte static int
addFunc(int operandLen,char * operand[],int object,cmdOptions_t * options,void * addArgs,int * funcRet)4775fcf3ce44SJohn Forte addFunc(int operandLen, char *operand[], int object, cmdOptions_t *options,
4776fcf3ce44SJohn Forte     void *addArgs, int *funcRet)
4777fcf3ce44SJohn Forte {
4778fcf3ce44SJohn Forte 	int ret;
4779fcf3ce44SJohn Forte 
4780fcf3ce44SJohn Forte 	assert(funcRet != NULL);
4781fcf3ce44SJohn Forte 
4782fcf3ce44SJohn Forte 	switch (object) {
4783fcf3ce44SJohn Forte 		case DISCOVERY_ADDRESS:
4784fcf3ce44SJohn Forte 		case ISNS_SERVER_ADDRESS:
4785fcf3ce44SJohn Forte 			ret = addAddress(object, operandLen, operand, funcRet);
4786fcf3ce44SJohn Forte 			break;
4787fcf3ce44SJohn Forte 		case STATIC_CONFIG:
4788fcf3ce44SJohn Forte 			ret = addStaticConfig(operandLen, operand, funcRet);
4789fcf3ce44SJohn Forte 			break;
4790fcf3ce44SJohn Forte 		default:
4791fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n",
4792fcf3ce44SJohn Forte 			    cmdName, gettext("unknown object"));
4793fcf3ce44SJohn Forte 			ret = 1;
4794fcf3ce44SJohn Forte 			break;
4795fcf3ce44SJohn Forte 	}
4796fcf3ce44SJohn Forte 	return (ret);
4797fcf3ce44SJohn Forte }
4798fcf3ce44SJohn Forte 
4799fcf3ce44SJohn Forte /*ARGSUSED*/
4800fcf3ce44SJohn Forte static int
listFunc(int operandLen,char * operand[],int object,cmdOptions_t * options,void * addArgs,int * funcRet)4801fcf3ce44SJohn Forte listFunc(int operandLen, char *operand[], int object, cmdOptions_t *options,
4802fcf3ce44SJohn Forte     void *addArgs, int *funcRet)
4803fcf3ce44SJohn Forte {
4804fcf3ce44SJohn Forte 	int ret;
4805fcf3ce44SJohn Forte 
4806fcf3ce44SJohn Forte 	assert(funcRet != NULL);
4807fcf3ce44SJohn Forte 
4808fcf3ce44SJohn Forte 	switch (object) {
4809fcf3ce44SJohn Forte 	case DISCOVERY:
4810fcf3ce44SJohn Forte 		ret = listDiscovery(funcRet);
4811fcf3ce44SJohn Forte 		break;
4812fcf3ce44SJohn Forte 	case DISCOVERY_ADDRESS:
4813fcf3ce44SJohn Forte 		ret = listDiscoveryAddress(operandLen, operand, options,
4814fcf3ce44SJohn Forte 		    funcRet);
4815fcf3ce44SJohn Forte 		break;
4816fcf3ce44SJohn Forte 	case ISNS_SERVER_ADDRESS:
4817fcf3ce44SJohn Forte 		ret = listISNSServerAddress(operandLen, operand, options,
4818fcf3ce44SJohn Forte 		    funcRet);
4819fcf3ce44SJohn Forte 		break;
4820fcf3ce44SJohn Forte 	case NODE:
4821fcf3ce44SJohn Forte 		ret = listNode(funcRet);
4822fcf3ce44SJohn Forte 		break;
4823fcf3ce44SJohn Forte 	case STATIC_CONFIG:
4824fcf3ce44SJohn Forte 		ret = listStaticConfig(operandLen, operand, funcRet);
4825fcf3ce44SJohn Forte 		break;
4826fcf3ce44SJohn Forte 	case TARGET:
4827fcf3ce44SJohn Forte 		ret = listTarget(operandLen, operand, options, funcRet);
4828fcf3ce44SJohn Forte 		break;
4829fcf3ce44SJohn Forte 	case TARGET_PARAM:
4830fcf3ce44SJohn Forte 		ret = listTargetParam(operandLen, operand, options, funcRet);
4831fcf3ce44SJohn Forte 		break;
4832fcf3ce44SJohn Forte 	default:
4833fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n",
4834fcf3ce44SJohn Forte 		    cmdName, gettext("unknown object"));
4835fcf3ce44SJohn Forte 		ret = 1;
4836fcf3ce44SJohn Forte 		break;
4837fcf3ce44SJohn Forte 	}
4838fcf3ce44SJohn Forte 	return (ret);
4839fcf3ce44SJohn Forte }
4840fcf3ce44SJohn Forte 
4841fcf3ce44SJohn Forte /*ARGSUSED*/
4842fcf3ce44SJohn Forte static int
modifyFunc(int operandLen,char * operand[],int object,cmdOptions_t * options,void * addArgs,int * funcRet)4843fcf3ce44SJohn Forte modifyFunc(int operandLen, char *operand[], int object, cmdOptions_t *options,
4844fcf3ce44SJohn Forte     void *addArgs, int *funcRet)
4845fcf3ce44SJohn Forte {
4846fcf3ce44SJohn Forte 	int ret, i;
4847fcf3ce44SJohn Forte 
4848fcf3ce44SJohn Forte 	assert(funcRet != NULL);
4849fcf3ce44SJohn Forte 
4850fcf3ce44SJohn Forte 	switch (object) {
4851fcf3ce44SJohn Forte 	case DISCOVERY:
4852fcf3ce44SJohn Forte 		ret = modifyDiscovery(options, funcRet);
4853fcf3ce44SJohn Forte 		break;
4854fcf3ce44SJohn Forte 	case NODE:
4855fcf3ce44SJohn Forte 		ret = modifyNode(options, funcRet);
4856fcf3ce44SJohn Forte 		break;
4857fcf3ce44SJohn Forte 	case TARGET_PARAM:
4858fcf3ce44SJohn Forte 		i = 0;
4859fcf3ce44SJohn Forte 		while (operand[i]) {
4860fcf3ce44SJohn Forte 			ret = modifyTargetParam(options, operand[i], funcRet);
4861fcf3ce44SJohn Forte 
4862fcf3ce44SJohn Forte 			if (ret) {
4863fcf3ce44SJohn Forte 				(void) fprintf(stderr, "%s: %s: %s\n",
4864fcf3ce44SJohn Forte 				    cmdName, gettext("modify failed"),
4865fcf3ce44SJohn Forte 				    operand[i]);
4866fcf3ce44SJohn Forte 				return (ret);
4867fcf3ce44SJohn Forte 			}
4868fcf3ce44SJohn Forte 			i++;
4869fcf3ce44SJohn Forte 		}
4870fcf3ce44SJohn Forte 
4871fcf3ce44SJohn Forte 		break;
4872fcf3ce44SJohn Forte 	default:
4873fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n",
4874fcf3ce44SJohn Forte 		    cmdName, gettext("unknown object"));
4875fcf3ce44SJohn Forte 		ret = 1;
4876fcf3ce44SJohn Forte 		break;
4877fcf3ce44SJohn Forte 	}
4878fcf3ce44SJohn Forte 	return (ret);
4879fcf3ce44SJohn Forte }
4880fcf3ce44SJohn Forte 
4881fcf3ce44SJohn Forte /*ARGSUSED*/
4882fcf3ce44SJohn Forte static int
removeFunc(int operandLen,char * operand[],int object,cmdOptions_t * options,void * addArgs,int * funcRet)4883fcf3ce44SJohn Forte removeFunc(int operandLen, char *operand[], int object, cmdOptions_t *options,
4884fcf3ce44SJohn Forte     void *addArgs, int *funcRet)
4885fcf3ce44SJohn Forte {
4886fcf3ce44SJohn Forte 	int ret;
4887fcf3ce44SJohn Forte 
4888fcf3ce44SJohn Forte 	switch (object) {
4889fcf3ce44SJohn Forte 		case DISCOVERY_ADDRESS:
4890fcf3ce44SJohn Forte 		case ISNS_SERVER_ADDRESS:
4891fcf3ce44SJohn Forte 			ret = removeAddress(object, operandLen, operand,
4892fcf3ce44SJohn Forte 			    funcRet);
4893fcf3ce44SJohn Forte 			break;
4894fcf3ce44SJohn Forte 		case STATIC_CONFIG:
4895fcf3ce44SJohn Forte 			ret = removeStaticConfig(operandLen, operand, funcRet);
4896fcf3ce44SJohn Forte 			break;
4897fcf3ce44SJohn Forte 		case TARGET_PARAM:
4898fcf3ce44SJohn Forte 			ret = removeTargetParam(operandLen, operand, funcRet);
4899fcf3ce44SJohn Forte 			break;
4900fcf3ce44SJohn Forte 		default:
4901fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n",
4902fcf3ce44SJohn Forte 			    cmdName, gettext("unknown object"));
4903fcf3ce44SJohn Forte 			ret = 1;
4904fcf3ce44SJohn Forte 			break;
4905fcf3ce44SJohn Forte 	}
4906fcf3ce44SJohn Forte 	return (ret);
4907fcf3ce44SJohn Forte }
4908fcf3ce44SJohn Forte 
4909fcf3ce44SJohn Forte static void
iSCSINameCheckStatusDisplay(iSCSINameCheckStatusType status)4910fcf3ce44SJohn Forte iSCSINameCheckStatusDisplay(iSCSINameCheckStatusType status)
4911fcf3ce44SJohn Forte {
4912fcf3ce44SJohn Forte 	switch (status) {
4913fcf3ce44SJohn Forte 		case iSCSINameLenZero:
4914fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n",
4915fcf3ce44SJohn Forte 			    cmdName, gettext("empty iSCSI name."));
4916fcf3ce44SJohn Forte 			break;
4917fcf3ce44SJohn Forte 		case iSCSINameLenExceededMax:
4918fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
4919fcf3ce44SJohn Forte 			    gettext("iSCSI name exceeded maximum length."));
4920fcf3ce44SJohn Forte 			break;
4921fcf3ce44SJohn Forte 		case iSCSINameUnknownType:
4922fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
4923fcf3ce44SJohn Forte 			    gettext("unknown iSCSI name type."));
4924fcf3ce44SJohn Forte 			break;
4925fcf3ce44SJohn Forte 		case iSCSINameInvalidCharacter:
4926fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n",
4927fcf3ce44SJohn Forte 			    cmdName,
4928fcf3ce44SJohn Forte 			    gettext("iSCSI name invalid character used"));
4929fcf3ce44SJohn Forte 			break;
4930fcf3ce44SJohn Forte 		case iSCSINameIqnFormatError:
4931fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
4932fcf3ce44SJohn Forte 			    gettext("iqn formatting error."));
4933fcf3ce44SJohn Forte 			break;
4934fcf3ce44SJohn Forte 		case iSCSINameIqnDateFormatError:
4935fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n",
4936fcf3ce44SJohn Forte 			    cmdName, gettext("invalid iqn date." \
4937fcf3ce44SJohn Forte 			    "  format is: YYYY-MM"));
4938fcf3ce44SJohn Forte 			break;
4939fcf3ce44SJohn Forte 		case iSCSINameIqnSubdomainFormatError:
4940fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n",
4941fcf3ce44SJohn Forte 			    cmdName, gettext("missing subdomain after \":\""));
4942fcf3ce44SJohn Forte 			break;
4943fcf3ce44SJohn Forte 		case iSCSINameIqnInvalidYearError:
4944fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n",
4945fcf3ce44SJohn Forte 			    cmdName, gettext("invalid year"));
4946fcf3ce44SJohn Forte 			break;
4947fcf3ce44SJohn Forte 		case iSCSINameIqnInvalidMonthError:
4948fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n",
4949fcf3ce44SJohn Forte 			    cmdName, gettext("invalid month"));
4950fcf3ce44SJohn Forte 			break;
4951fcf3ce44SJohn Forte 		case iSCSINameIqnFQDNError:
4952fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n",
4953fcf3ce44SJohn Forte 			    cmdName, gettext("missing reversed fully qualified"\
4954fcf3ce44SJohn Forte 			    " domain name"));
4955fcf3ce44SJohn Forte 			break;
4956fcf3ce44SJohn Forte 		case iSCSINameEUIFormatError:
4957fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n", cmdName,
4958fcf3ce44SJohn Forte 			    gettext("eui formatting error."));
4959fcf3ce44SJohn Forte 			break;
4960fcf3ce44SJohn Forte 	}
4961fcf3ce44SJohn Forte }
4962fcf3ce44SJohn Forte 
4963fcf3ce44SJohn Forte /*
4964fcf3ce44SJohn Forte  * A convenient function to modify the target parameters of an individual
4965fcf3ce44SJohn Forte  * target.
4966fcf3ce44SJohn Forte  *
4967fcf3ce44SJohn Forte  * Return 0 if successful
4968fcf3ce44SJohn Forte  * Return 1 if failed
4969fcf3ce44SJohn Forte  */
4970fcf3ce44SJohn Forte static int
modifyIndividualTargetParam(cmdOptions_t * optionList,IMA_OID targetOid,int * funcRet)4971fcf3ce44SJohn Forte modifyIndividualTargetParam(cmdOptions_t *optionList, IMA_OID targetOid,
4972fcf3ce44SJohn Forte     int *funcRet)
4973fcf3ce44SJohn Forte {
4974fcf3ce44SJohn Forte 	assert(funcRet != NULL);
4975fcf3ce44SJohn Forte 
4976fcf3ce44SJohn Forte 	for (; optionList->optval; optionList++) {
4977fcf3ce44SJohn Forte 		switch (optionList->optval) {
4978fcf3ce44SJohn Forte 			case 'a':
4979fcf3ce44SJohn Forte 				if (modifyTargetAuthMethod(targetOid,
4980fcf3ce44SJohn Forte 				    optionList->optarg, funcRet) != 0) {
4981fcf3ce44SJohn Forte 					return (1);
4982fcf3ce44SJohn Forte 				}
4983fcf3ce44SJohn Forte 				break;
4984fcf3ce44SJohn Forte 			case 'B':
4985fcf3ce44SJohn Forte 				if (modifyTargetBidirAuthFlag(targetOid,
4986fcf3ce44SJohn Forte 				    optionList->optarg, funcRet) != 0) {
4987fcf3ce44SJohn Forte 					return (1);
4988fcf3ce44SJohn Forte 				}
4989fcf3ce44SJohn Forte 				break;
4990fcf3ce44SJohn Forte 			case 'C':
4991fcf3ce44SJohn Forte 				if (modifyTargetAuthParam(targetOid,
4992fcf3ce44SJohn Forte 				    AUTH_PASSWORD, NULL, funcRet) != 0) {
4993fcf3ce44SJohn Forte 					return (1);
4994fcf3ce44SJohn Forte 				}
4995fcf3ce44SJohn Forte 				break;
4996fcf3ce44SJohn Forte 			case 'd':
4997fcf3ce44SJohn Forte 				if (setLoginParameter(targetOid, DATA_DIGEST,
4998fcf3ce44SJohn Forte 				    optionList->optarg) != 0) {
4999fcf3ce44SJohn Forte 					return (1);
5000fcf3ce44SJohn Forte 				}
5001fcf3ce44SJohn Forte 				break;
5002fcf3ce44SJohn Forte 			case 'h':
5003fcf3ce44SJohn Forte 				if (setLoginParameter(targetOid, HEADER_DIGEST,
5004fcf3ce44SJohn Forte 				    optionList->optarg) != 0) {
5005fcf3ce44SJohn Forte 					return (1);
5006fcf3ce44SJohn Forte 				}
5007fcf3ce44SJohn Forte 				break;
5008fcf3ce44SJohn Forte 			case 'p':
5009fcf3ce44SJohn Forte 				/* Login parameter */
5010fcf3ce44SJohn Forte 				if (setLoginParameters(targetOid,
5011fcf3ce44SJohn Forte 				    optionList->optarg) != 0) {
5012fcf3ce44SJohn Forte 					return (1);
5013fcf3ce44SJohn Forte 				}
5014fcf3ce44SJohn Forte 				break;
5015fcf3ce44SJohn Forte 			case 'c':
5016fcf3ce44SJohn Forte 				/* Modify configure sessions */
5017fcf3ce44SJohn Forte 				if (modifyConfiguredSessions(targetOid,
5018fcf3ce44SJohn Forte 				    optionList->optarg) != 0) {
5019fcf3ce44SJohn Forte 					return (1);
5020fcf3ce44SJohn Forte 				}
5021fcf3ce44SJohn Forte 				break;
5022fcf3ce44SJohn Forte 			case 'H':
5023fcf3ce44SJohn Forte 				if (modifyTargetAuthParam(targetOid, AUTH_NAME,
5024fcf3ce44SJohn Forte 				    optionList->optarg, funcRet) != 0) {
5025fcf3ce44SJohn Forte 					return (1);
5026fcf3ce44SJohn Forte 				}
5027fcf3ce44SJohn Forte 				break;
5028aff4bce5Syi zhang - Sun Microsystems - Beijing China 			case 'T':
5029aff4bce5Syi zhang - Sun Microsystems - Beijing China 				if (setTunableParameters(targetOid,
5030aff4bce5Syi zhang - Sun Microsystems - Beijing China 				    optionList->optarg) != 0) {
5031aff4bce5Syi zhang - Sun Microsystems - Beijing China 					return (1);
5032aff4bce5Syi zhang - Sun Microsystems - Beijing China 				}
5033aff4bce5Syi zhang - Sun Microsystems - Beijing China 				break;
5034fcf3ce44SJohn Forte 		}
5035fcf3ce44SJohn Forte 	}
5036fcf3ce44SJohn Forte 
5037fcf3ce44SJohn Forte 	return (0);
5038fcf3ce44SJohn Forte }
5039fcf3ce44SJohn Forte 
5040fcf3ce44SJohn Forte /*
5041fcf3ce44SJohn Forte  * This helper function could go into a utility module for general use.
5042fcf3ce44SJohn Forte  */
5043fcf3ce44SJohn Forte static int
parseAddress(char * address_port_str,uint16_t defaultPort,char * address_str,size_t address_str_len,uint16_t * port,boolean_t * isIpv6)5044fcf3ce44SJohn Forte parseAddress(char *address_port_str,
5045fcf3ce44SJohn Forte     uint16_t defaultPort,
5046fcf3ce44SJohn Forte     char *address_str,
5047fcf3ce44SJohn Forte     size_t address_str_len,
5048fcf3ce44SJohn Forte     uint16_t *port,
5049fcf3ce44SJohn Forte     boolean_t *isIpv6)
5050fcf3ce44SJohn Forte {
5051fcf3ce44SJohn Forte 	char port_str[64];
5052fcf3ce44SJohn Forte 	int tmp_port;
5053fcf3ce44SJohn Forte 	char *errchr;
5054fcf3ce44SJohn Forte 
5055fcf3ce44SJohn Forte 	if (address_port_str[0] == '[') {
5056fcf3ce44SJohn Forte 		/* IPv6 address */
5057fcf3ce44SJohn Forte 		char *close_bracket_pos;
5058fcf3ce44SJohn Forte 		close_bracket_pos = strchr(address_port_str, ']');
5059fcf3ce44SJohn Forte 		if (!close_bracket_pos) {
5060fcf3ce44SJohn Forte 			syslog(LOG_USER|LOG_DEBUG,
5061fcf3ce44SJohn Forte 			    "IP address format error: %s\n", address_str);
5062fcf3ce44SJohn Forte 			return (PARSE_ADDR_MISSING_CLOSING_BRACKET);
5063fcf3ce44SJohn Forte 		}
5064fcf3ce44SJohn Forte 
506533c72b75SToomas Soome 		*close_bracket_pos = '\0';
5066fcf3ce44SJohn Forte 		(void) strlcpy(address_str, &address_port_str[1],
5067fcf3ce44SJohn Forte 		    address_str_len);
5068fcf3ce44SJohn Forte 
5069fcf3ce44SJohn Forte 		/* Extract the port number */
5070fcf3ce44SJohn Forte 		close_bracket_pos++;
5071fcf3ce44SJohn Forte 		if (*close_bracket_pos == ':') {
5072fcf3ce44SJohn Forte 			close_bracket_pos++;
507333c72b75SToomas Soome 			if (*close_bracket_pos != '\0') {
5074fcf3ce44SJohn Forte 				(void) strlcpy(port_str, close_bracket_pos, 64);
5075fcf3ce44SJohn Forte 				tmp_port = strtol(port_str, &errchr, 10);
5076fcf3ce44SJohn Forte 				if (tmp_port == 0 && errchr != NULL) {
5077fcf3ce44SJohn Forte 					(void) fprintf(stderr, "%s: %s:%s %s\n",
5078fcf3ce44SJohn Forte 					    cmdName, address_str,
5079fcf3ce44SJohn Forte 					    close_bracket_pos,
5080fcf3ce44SJohn Forte 					    gettext("port number invalid"));
5081fcf3ce44SJohn Forte 					return (PARSE_ADDR_PORT_OUT_OF_RANGE);
5082fcf3ce44SJohn Forte 				}
5083fcf3ce44SJohn Forte 				if ((tmp_port > 0) && (tmp_port > USHRT_MAX) ||
5084fcf3ce44SJohn Forte 				    (tmp_port < 0)) {
5085fcf3ce44SJohn Forte 					/* Port number out of range */
5086fcf3ce44SJohn Forte 					syslog(LOG_USER|LOG_DEBUG,
5087fcf3ce44SJohn Forte 					    "Specified port out of range: %d",
5088fcf3ce44SJohn Forte 					    tmp_port);
5089fcf3ce44SJohn Forte 					return (PARSE_ADDR_PORT_OUT_OF_RANGE);
5090fcf3ce44SJohn Forte 				} else {
5091fcf3ce44SJohn Forte 					*port = (uint16_t)tmp_port;
5092fcf3ce44SJohn Forte 				}
5093fcf3ce44SJohn Forte 			} else {
5094fcf3ce44SJohn Forte 				*port = defaultPort;
5095fcf3ce44SJohn Forte 			}
5096fcf3ce44SJohn Forte 		} else {
5097fcf3ce44SJohn Forte 			*port = defaultPort;
5098fcf3ce44SJohn Forte 		}
5099fcf3ce44SJohn Forte 
5100fcf3ce44SJohn Forte 		*isIpv6 = B_TRUE;
5101fcf3ce44SJohn Forte 	} else {
5102fcf3ce44SJohn Forte 		/* IPv4 address */
5103fcf3ce44SJohn Forte 		char *colon_pos;
5104fcf3ce44SJohn Forte 		colon_pos = strchr(address_port_str, ':');
5105fcf3ce44SJohn Forte 		if (!colon_pos) {
5106fcf3ce44SJohn Forte 			/* No port number specified. */
5107fcf3ce44SJohn Forte 			*port = defaultPort;
5108fcf3ce44SJohn Forte 			(void) strlcpy(address_str, address_port_str,
5109fcf3ce44SJohn Forte 			    address_str_len);
5110fcf3ce44SJohn Forte 		} else {
511133c72b75SToomas Soome 			*colon_pos = '\0';
5112fcf3ce44SJohn Forte 			(void) strlcpy(address_str, address_port_str,
5113fcf3ce44SJohn Forte 			    address_str_len);
5114fcf3ce44SJohn Forte 
5115fcf3ce44SJohn Forte 			/* Extract the port number */
5116fcf3ce44SJohn Forte 			colon_pos++;
511733c72b75SToomas Soome 			if (*colon_pos != '\0') {
5118fcf3ce44SJohn Forte 
5119fcf3ce44SJohn Forte 				(void) strlcpy(port_str, colon_pos, 64);
5120fcf3ce44SJohn Forte 				tmp_port = strtol(port_str, &errchr, 10);
5121fcf3ce44SJohn Forte 				if (tmp_port == 0 && errchr != NULL) {
5122fcf3ce44SJohn Forte 					(void) fprintf(stderr, "%s: %s:%s %s\n",
5123fcf3ce44SJohn Forte 					    cmdName, address_str, colon_pos,
5124fcf3ce44SJohn Forte 					    gettext("port number invalid"));
5125fcf3ce44SJohn Forte 					return (PARSE_ADDR_PORT_OUT_OF_RANGE);
5126fcf3ce44SJohn Forte 				}
5127fcf3ce44SJohn Forte 				if ((tmp_port > 0) && (tmp_port > USHRT_MAX) ||
5128fcf3ce44SJohn Forte 				    (tmp_port < 0)) {
5129fcf3ce44SJohn Forte 					/* Port number out of range */
5130fcf3ce44SJohn Forte 					syslog(LOG_USER|LOG_DEBUG,
5131fcf3ce44SJohn Forte 					    "Specified port out of range: %d",
5132fcf3ce44SJohn Forte 					    tmp_port);
5133fcf3ce44SJohn Forte 					return (PARSE_ADDR_PORT_OUT_OF_RANGE);
5134fcf3ce44SJohn Forte 				} else {
5135fcf3ce44SJohn Forte 					*port = (uint16_t)tmp_port;
5136fcf3ce44SJohn Forte 				}
5137fcf3ce44SJohn Forte 			} else {
5138fcf3ce44SJohn Forte 				*port = defaultPort;
5139fcf3ce44SJohn Forte 			}
5140fcf3ce44SJohn Forte 		}
5141fcf3ce44SJohn Forte 
5142fcf3ce44SJohn Forte 		*isIpv6 = B_FALSE;
5143fcf3ce44SJohn Forte 	}
5144fcf3ce44SJohn Forte 
5145fcf3ce44SJohn Forte 	return (PARSE_ADDR_OK);
5146fcf3ce44SJohn Forte }
5147fcf3ce44SJohn Forte 
5148fcf3ce44SJohn Forte /*
5149fcf3ce44SJohn Forte  * This helper function could go into a utility module for general use.
5150fcf3ce44SJohn Forte  */
5151fcf3ce44SJohn Forte iSCSINameCheckStatusType
iSCSINameStringProfileCheck(wchar_t * name)5152fcf3ce44SJohn Forte iSCSINameStringProfileCheck(wchar_t *name)
5153fcf3ce44SJohn Forte {
5154fcf3ce44SJohn Forte 	char mb_name[MAX_ISCSI_NAME_LEN + 1];
5155fcf3ce44SJohn Forte 	size_t name_len;
5156fcf3ce44SJohn Forte 	char *tmp;
5157fcf3ce44SJohn Forte 
5158fcf3ce44SJohn Forte 	(void) wcstombs(mb_name, name, MAX_ISCSI_NAME_LEN + 1);
5159fcf3ce44SJohn Forte 
5160fcf3ce44SJohn Forte 	if ((name_len = strlen(mb_name)) == 0) {
5161fcf3ce44SJohn Forte 		return (iSCSINameLenZero);
5162fcf3ce44SJohn Forte 	} else if (name_len > MAX_ISCSI_NAME_LEN) {
5163fcf3ce44SJohn Forte 		return (iSCSINameLenExceededMax);
5164fcf3ce44SJohn Forte 	}
5165fcf3ce44SJohn Forte 
5166fcf3ce44SJohn Forte 	/*
5167fcf3ce44SJohn Forte 	 * check for invalid characters
5168fcf3ce44SJohn Forte 	 * According to RFC 3722 iSCSI name must be either a letter,
5169fcf3ce44SJohn Forte 	 * a digit or one of the following '-' '.' ':'
5170fcf3ce44SJohn Forte 	 */
517133c72b75SToomas Soome 	for (tmp = mb_name; *tmp != '\0'; tmp++) {
5172fcf3ce44SJohn Forte 		if ((isalnum(*tmp) == 0) &&
5173fcf3ce44SJohn Forte 		    (*tmp != '-') &&
5174fcf3ce44SJohn Forte 		    (*tmp != '.') &&
5175fcf3ce44SJohn Forte 		    (*tmp != ':')) {
5176fcf3ce44SJohn Forte 			return (iSCSINameInvalidCharacter);
5177fcf3ce44SJohn Forte 		}
5178fcf3ce44SJohn Forte 	}
5179fcf3ce44SJohn Forte 
5180fcf3ce44SJohn Forte 	if (strncmp(mb_name, ISCSI_IQN_NAME_PREFIX,
5181fcf3ce44SJohn Forte 	    strlen(ISCSI_IQN_NAME_PREFIX)) == 0) {
5182fcf3ce44SJohn Forte 		/*
5183fcf3ce44SJohn Forte 		 * If name is of type iqn, check date string and naming
5184fcf3ce44SJohn Forte 		 * authority.
5185fcf3ce44SJohn Forte 		 */
5186fcf3ce44SJohn Forte 		char *strp = NULL;
5187fcf3ce44SJohn Forte 
5188fcf3ce44SJohn Forte 		/*
5189fcf3ce44SJohn Forte 		 * Don't allow the string to end with a colon.  If there is a
5190fcf3ce44SJohn Forte 		 * colon then there must be a subdomain provided.
5191fcf3ce44SJohn Forte 		 */
5192fcf3ce44SJohn Forte 		if (mb_name[strlen(mb_name) - 1] == ':') {
5193fcf3ce44SJohn Forte 			return (iSCSINameIqnSubdomainFormatError);
5194fcf3ce44SJohn Forte 		}
5195fcf3ce44SJohn Forte 
5196fcf3ce44SJohn Forte 		/* Date string */
5197fcf3ce44SJohn Forte 		strp = strtok(&mb_name[3], ".");
5198fcf3ce44SJohn Forte 		if (strp) {
5199fcf3ce44SJohn Forte 			char tmpYear[5], tmpMonth[3], *endPtr = NULL;
5200fcf3ce44SJohn Forte 			int year, month;
5201fcf3ce44SJohn Forte 
5202fcf3ce44SJohn Forte 			/* Date string should be in YYYY-MM format */
5203fcf3ce44SJohn Forte 			if (strlen(strp) != strlen("YYYY-MM") ||
5204fcf3ce44SJohn Forte 			    strp[4] != '-') {
5205fcf3ce44SJohn Forte 				return (iSCSINameIqnDateFormatError);
5206fcf3ce44SJohn Forte 			}
5207fcf3ce44SJohn Forte 
5208fcf3ce44SJohn Forte 			/*
5209fcf3ce44SJohn Forte 			 * Validate year.  Only validating that the
5210fcf3ce44SJohn Forte 			 * year can be converted to a number.  No
5211fcf3ce44SJohn Forte 			 * validation will be done on year's actual
5212fcf3ce44SJohn Forte 			 * value.
5213fcf3ce44SJohn Forte 			 */
5214fcf3ce44SJohn Forte 			(void) strncpy(tmpYear, strp, 4);
5215fcf3ce44SJohn Forte 			tmpYear[4] = '\0';
5216fcf3ce44SJohn Forte 
5217fcf3ce44SJohn Forte 			errno = 0;
5218fcf3ce44SJohn Forte 			year = strtol(tmpYear, &endPtr, 10);
5219fcf3ce44SJohn Forte 			if (errno != 0 || *endPtr != '\0' ||
5220fcf3ce44SJohn Forte 			    year < 0 || year > 9999) {
5221fcf3ce44SJohn Forte 				return (iSCSINameIqnInvalidYearError);
5222fcf3ce44SJohn Forte 			}
5223fcf3ce44SJohn Forte 
5224fcf3ce44SJohn Forte 			/*
5225fcf3ce44SJohn Forte 			 * Validate month is valid.
5226fcf3ce44SJohn Forte 			 */
5227fcf3ce44SJohn Forte 			(void) strncpy(tmpMonth, &strp[5], 2);
5228fcf3ce44SJohn Forte 			tmpMonth[2] = '\0';
5229fcf3ce44SJohn Forte 			errno = 0;
5230fcf3ce44SJohn Forte 			month = strtol(tmpMonth, &endPtr, 10);
5231fcf3ce44SJohn Forte 
5232fcf3ce44SJohn Forte 			if (errno != 0 || *endPtr != '\0' ||
5233fcf3ce44SJohn Forte 			    month < 1 || month > 12) {
5234fcf3ce44SJohn Forte 				return (iSCSINameIqnInvalidMonthError);
5235fcf3ce44SJohn Forte 			}
5236fcf3ce44SJohn Forte 
5237fcf3ce44SJohn Forte 			/*
5238fcf3ce44SJohn Forte 			 * A reversed FQDN needs to be provided.  We
5239fcf3ce44SJohn Forte 			 * will only check for a "." followed by more
5240fcf3ce44SJohn Forte 			 * than two or more characters.  The list of domains is
5241fcf3ce44SJohn Forte 			 * too large and changes too frequently to
5242fcf3ce44SJohn Forte 			 * add validation for.
5243fcf3ce44SJohn Forte 			 */
5244fcf3ce44SJohn Forte 			strp = strtok(NULL, ".");
5245fcf3ce44SJohn Forte 			if (!strp || strlen(strp) < 2) {
5246fcf3ce44SJohn Forte 				return (iSCSINameIqnFQDNError);
5247fcf3ce44SJohn Forte 			}
5248fcf3ce44SJohn Forte 
5249fcf3ce44SJohn Forte 			/* Name authority string */
5250fcf3ce44SJohn Forte 			strp = strtok(NULL, ":");
5251fcf3ce44SJohn Forte 			if (strp) {
5252fcf3ce44SJohn Forte 				return (iSCSINameCheckOK);
5253fcf3ce44SJohn Forte 			} else {
5254fcf3ce44SJohn Forte 				return (iSCSINameIqnFQDNError);
5255fcf3ce44SJohn Forte 			}
5256fcf3ce44SJohn Forte 		} else {
5257fcf3ce44SJohn Forte 			return (iSCSINameIqnFormatError);
5258fcf3ce44SJohn Forte 		}
5259fcf3ce44SJohn Forte 	} else if (strncmp(mb_name, ISCSI_EUI_NAME_PREFIX,
5260fcf3ce44SJohn Forte 	    strlen(ISCSI_EUI_NAME_PREFIX)) == 0) {
5261fcf3ce44SJohn Forte 		/* If name is of type EUI, change its length */
5262fcf3ce44SJohn Forte 
5263fcf3ce44SJohn Forte 		if (strlen(mb_name) != ISCSI_EUI_NAME_LEN) {
5264fcf3ce44SJohn Forte 			return (iSCSINameEUIFormatError);
5265fcf3ce44SJohn Forte 		}
5266fcf3ce44SJohn Forte 
5267fcf3ce44SJohn Forte 		for (tmp = mb_name + strlen(ISCSI_EUI_NAME_PREFIX) + 1;
5268fcf3ce44SJohn Forte 		    *tmp != '\0'; tmp++) {
5269fcf3ce44SJohn Forte 			if (isxdigit(*tmp)) {
5270fcf3ce44SJohn Forte 				continue;
5271fcf3ce44SJohn Forte 			}
5272fcf3ce44SJohn Forte 			return (iSCSINameEUIFormatError);
5273fcf3ce44SJohn Forte 		}
5274fcf3ce44SJohn Forte 
5275fcf3ce44SJohn Forte 		return (iSCSINameCheckOK);
5276fcf3ce44SJohn Forte 	} else {
5277fcf3ce44SJohn Forte 		return (iSCSINameUnknownType);
5278fcf3ce44SJohn Forte 	}
5279fcf3ce44SJohn Forte }
5280fcf3ce44SJohn Forte 
5281fcf3ce44SJohn Forte /*
5282fcf3ce44SJohn Forte  * This helper function could go into a utility module for general use.
5283fcf3ce44SJohn Forte  *
5284fcf3ce44SJohn Forte  * Returns:
5285fcf3ce44SJohn Forte  * B_TRUE is the numberStr is an unsigned natural number and within the
5286fcf3ce44SJohn Forte  * specified bound.
5287fcf3ce44SJohn Forte  * B_FALSE otherwise.
5288fcf3ce44SJohn Forte  */
5289fcf3ce44SJohn Forte boolean_t
isNaturalNumber(char * numberStr,uint32_t upperBound)5290fcf3ce44SJohn Forte isNaturalNumber(char *numberStr, uint32_t upperBound)
5291fcf3ce44SJohn Forte {
5292fcf3ce44SJohn Forte 	int i;
5293fcf3ce44SJohn Forte 	int number_str_len;
5294fcf3ce44SJohn Forte 
5295fcf3ce44SJohn Forte 	if ((number_str_len = strlen(numberStr)) == 0) {
5296fcf3ce44SJohn Forte 		return (B_FALSE);
5297fcf3ce44SJohn Forte 	}
5298fcf3ce44SJohn Forte 
5299fcf3ce44SJohn Forte 	for (i = 0; i < number_str_len; i++) {
5300fcf3ce44SJohn Forte 		if (numberStr[i] < 060 || numberStr[i] > 071) {
5301fcf3ce44SJohn Forte 			return (B_FALSE);
5302fcf3ce44SJohn Forte 		}
5303fcf3ce44SJohn Forte 	}
5304fcf3ce44SJohn Forte 
5305fcf3ce44SJohn Forte 	if (atoi(numberStr) > upperBound) {
5306fcf3ce44SJohn Forte 		return (B_FALSE);
5307fcf3ce44SJohn Forte 	}
5308fcf3ce44SJohn Forte 
5309fcf3ce44SJohn Forte 	return (B_TRUE);
5310fcf3ce44SJohn Forte }
5311fcf3ce44SJohn Forte 
5312fcf3ce44SJohn Forte /*
5313fcf3ce44SJohn Forte  * This helper function could go into a utility module for general use.
5314fcf3ce44SJohn Forte  * It parses a target string in the format of:
5315fcf3ce44SJohn Forte  *
531633c72b75SToomas Soome  *	<target_name>,[<ip_address>[:port][,tpgt]]
5317fcf3ce44SJohn Forte  *
5318fcf3ce44SJohn Forte  * and creates wchar strings for target name and target address. It
5319fcf3ce44SJohn Forte  * also populates port and tpgt if found.
5320fcf3ce44SJohn Forte  *
5321fcf3ce44SJohn Forte  * Returns:
532233c72b75SToomas Soome  *	PARSE_TARGET_OK if parsing is successful.
5323fcf3ce44SJohn Forte  *	PARSE_TARGET_INVALID_TPGT if the specified tpgt is
5324fcf3ce44SJohn Forte  *	invalid.
532533c72b75SToomas Soome  *	PARSE_TARGET_INVALID_ADDR if the address specified is
5326fcf3ce44SJohn Forte  *	invalid.
5327fcf3ce44SJohn Forte  */
5328fcf3ce44SJohn Forte int
parseTarget(char * targetStr,wchar_t * targetNameStr,size_t targetNameStrLen,boolean_t * targetAddressSpecified,wchar_t * targetAddressStr,size_t targetAddressStrLen,uint16_t * port,boolean_t * tpgtSpecified,uint16_t * tpgt,boolean_t * isIpv6)532933c72b75SToomas Soome parseTarget(char *targetStr, wchar_t *targetNameStr, size_t targetNameStrLen,
533033c72b75SToomas Soome     boolean_t *targetAddressSpecified, wchar_t *targetAddressStr,
533133c72b75SToomas Soome     size_t targetAddressStrLen, uint16_t *port, boolean_t *tpgtSpecified,
533233c72b75SToomas Soome     uint16_t *tpgt, boolean_t *isIpv6)
5333fcf3ce44SJohn Forte {
5334fcf3ce44SJohn Forte 	char *commaPos;
5335fcf3ce44SJohn Forte 	char *commaPos2;
5336fcf3ce44SJohn Forte 	char targetAddress[SUN_IMA_IP_ADDRESS_PORT_LEN];
5337fcf3ce44SJohn Forte 	int i;
5338fcf3ce44SJohn Forte 	int lowerCase;
5339fcf3ce44SJohn Forte 
5340fcf3ce44SJohn Forte 	(void) memset(targetNameStr, 0,
5341fcf3ce44SJohn Forte 	    targetNameStrLen * sizeof (wchar_t));
5342fcf3ce44SJohn Forte 	(void) memset(targetAddressStr, 0,
5343fcf3ce44SJohn Forte 	    targetAddressStrLen * sizeof (wchar_t));
5344fcf3ce44SJohn Forte 
5345fcf3ce44SJohn Forte 	commaPos = strchr(targetStr, ',');
5346fcf3ce44SJohn Forte 	if (commaPos != NULL) {
534733c72b75SToomas Soome 		*commaPos = '\0';
5348fcf3ce44SJohn Forte 		commaPos++;
5349fcf3ce44SJohn Forte 		*targetAddressSpecified = B_TRUE;
5350fcf3ce44SJohn Forte 
5351fcf3ce44SJohn Forte 		/*
5352fcf3ce44SJohn Forte 		 * Checking of tpgt makes sense only when
5353fcf3ce44SJohn Forte 		 * the target address/port are specified.
5354fcf3ce44SJohn Forte 		 */
5355fcf3ce44SJohn Forte 		commaPos2 = strchr(commaPos, ',');
5356fcf3ce44SJohn Forte 		if (commaPos2 != NULL) {
535733c72b75SToomas Soome 			*commaPos2 = '\0';
5358fcf3ce44SJohn Forte 			commaPos2++;
5359fcf3ce44SJohn Forte 			if (isNaturalNumber(commaPos2, ISCSI_MAX_TPGT_VALUE) ==
5360fcf3ce44SJohn Forte 			    B_TRUE) {
5361fcf3ce44SJohn Forte 				*tpgt = atoi(commaPos2);
5362fcf3ce44SJohn Forte 				*tpgtSpecified = B_TRUE;
5363fcf3ce44SJohn Forte 			} else {
53645df5713fSbing zhao - Sun Microsystems - Beijing China 				(void) fprintf(stderr, "%s: %s\n", cmdName,
53655df5713fSbing zhao - Sun Microsystems - Beijing China 				    gettext("parse target invalid TPGT"));
5366fcf3ce44SJohn Forte 				return (PARSE_TARGET_INVALID_TPGT);
5367fcf3ce44SJohn Forte 			}
5368fcf3ce44SJohn Forte 		}
5369fcf3ce44SJohn Forte 
5370fcf3ce44SJohn Forte 		switch (parseAddress(commaPos, ISCSI_LISTEN_PORT,
5371fcf3ce44SJohn Forte 		    &targetAddress[0], MAX_ADDRESS_LEN + 1, port, isIpv6)) {
5372fcf3ce44SJohn Forte 		case PARSE_ADDR_PORT_OUT_OF_RANGE:
5373fcf3ce44SJohn Forte 			return (PARSE_TARGET_INVALID_ADDR);
5374fcf3ce44SJohn Forte 		case PARSE_ADDR_OK:
5375fcf3ce44SJohn Forte 			break;
5376fcf3ce44SJohn Forte 		default:
5377fcf3ce44SJohn Forte 			(void) fprintf(stderr, "%s: %s\n",
5378fcf3ce44SJohn Forte 			    cmdName, gettext("cannot parse target name"));
5379fcf3ce44SJohn Forte 			return (PARSE_TARGET_INVALID_ADDR);
5380fcf3ce44SJohn Forte 		}
5381fcf3ce44SJohn Forte 		(void) mbstowcs(targetAddressStr, targetAddress,
5382fcf3ce44SJohn Forte 		    targetAddressStrLen);
5383fcf3ce44SJohn Forte 		for (i = 0; targetAddressStr[i] != 0; i++) {
5384fcf3ce44SJohn Forte 			lowerCase = tolower(targetAddressStr[i]);
5385fcf3ce44SJohn Forte 			targetAddressStr[i] = lowerCase;
5386fcf3ce44SJohn Forte 		}
5387fcf3ce44SJohn Forte 	} else {
5388fcf3ce44SJohn Forte 		*targetAddressSpecified = B_FALSE;
5389fcf3ce44SJohn Forte 		*tpgtSpecified = B_FALSE;
5390fcf3ce44SJohn Forte 	}
5391fcf3ce44SJohn Forte 
5392fcf3ce44SJohn Forte 	(void) mbstowcs(targetNameStr, targetStr, targetNameStrLen);
5393fcf3ce44SJohn Forte 	for (i = 0; targetNameStr[i] != 0; i++) {
5394fcf3ce44SJohn Forte 		lowerCase = tolower(targetNameStr[i]);
5395fcf3ce44SJohn Forte 		targetNameStr[i] = lowerCase;
5396fcf3ce44SJohn Forte 	}
5397fcf3ce44SJohn Forte 
5398fcf3ce44SJohn Forte 	return (PARSE_TARGET_OK);
5399fcf3ce44SJohn Forte }
5400fcf3ce44SJohn Forte 
5401fcf3ce44SJohn Forte /*ARGSUSED*/
5402fcf3ce44SJohn Forte static void
listCHAPName(IMA_OID oid)5403fcf3ce44SJohn Forte listCHAPName(IMA_OID oid)
5404fcf3ce44SJohn Forte {
5405fcf3ce44SJohn Forte 	IMA_INITIATOR_AUTHPARMS authParams;
5406fcf3ce44SJohn Forte 	IMA_STATUS status;
5407fcf3ce44SJohn Forte 	IMA_BYTE chapName [MAX_CHAP_NAME_LEN + 1];
5408fcf3ce44SJohn Forte 
5409fcf3ce44SJohn Forte 	/* Get Chap Name depending upon oid object type */
5410fcf3ce44SJohn Forte 	if (oid.objectType == IMA_OBJECT_TYPE_LHBA) {
5411fcf3ce44SJohn Forte 		status = IMA_GetInitiatorAuthParms(oid,
5412fcf3ce44SJohn Forte 		    IMA_AUTHMETHOD_CHAP, &authParams);
5413fcf3ce44SJohn Forte 	} else {
5414fcf3ce44SJohn Forte 		status = SUN_IMA_GetTargetAuthParms(oid,
5415fcf3ce44SJohn Forte 		    IMA_AUTHMETHOD_CHAP, &authParams);
5416fcf3ce44SJohn Forte 	}
5417fcf3ce44SJohn Forte 
5418fcf3ce44SJohn Forte 	(void) fprintf(stdout, "\n\t\t%s: ", gettext("CHAP Name"));
5419fcf3ce44SJohn Forte 
5420fcf3ce44SJohn Forte 	if (IMA_SUCCESS(status)) {
5421fcf3ce44SJohn Forte 		/*
5422fcf3ce44SJohn Forte 		 * Default chap name will be the node name.  The default will
5423fcf3ce44SJohn Forte 		 * be set by the driver.
5424fcf3ce44SJohn Forte 		 */
5425fcf3ce44SJohn Forte 		if (authParams.chapParms.nameLength != 0) {
5426fcf3ce44SJohn Forte 			(void) memset(chapName, 0, sizeof (chapName));
5427fcf3ce44SJohn Forte 			(void) memcpy(chapName, authParams.chapParms.name,
5428fcf3ce44SJohn Forte 			    authParams.chapParms.nameLength);
5429fcf3ce44SJohn Forte 			(void) fprintf(stdout, "%s", chapName);
5430fcf3ce44SJohn Forte 
5431fcf3ce44SJohn Forte 		} else {
5432fcf3ce44SJohn Forte 			(void) fprintf(stdout, "%s", "-");
5433fcf3ce44SJohn Forte 		}
5434fcf3ce44SJohn Forte 	} else {
5435fcf3ce44SJohn Forte 		(void) fprintf(stdout, "%s", "-");
5436fcf3ce44SJohn Forte 	}
5437fcf3ce44SJohn Forte }
5438fcf3ce44SJohn Forte 
54394246c8e9SJack Meng static boolean_t
checkServiceStatus(void)54404246c8e9SJack Meng checkServiceStatus(void)
54414246c8e9SJack Meng {
54424246c8e9SJack Meng 	IMA_STATUS	status	=	IMA_ERROR_UNKNOWN_ERROR;
54434246c8e9SJack Meng 	IMA_BOOL	enabled =	0;
54444246c8e9SJack Meng 
54454246c8e9SJack Meng 	status = SUN_IMA_GetSvcStatus(&enabled);
54464246c8e9SJack Meng 
54474246c8e9SJack Meng 	if (status != IMA_STATUS_SUCCESS) {
54484246c8e9SJack Meng 		(void) fprintf(stdout, "%s\n%s\n",
54494246c8e9SJack Meng 		    gettext("Unable to query the service status of"
54504246c8e9SJack Meng 		    " iSCSI initiator."),
54514246c8e9SJack Meng 		    gettext("For more information, please refer to"
5452*bbf21555SRichard Lowe 		    " iscsi(4D)."));
54534246c8e9SJack Meng 		return (B_FALSE);
54544246c8e9SJack Meng 	}
54554246c8e9SJack Meng 
54564246c8e9SJack Meng 	if (enabled == 0) {
54574246c8e9SJack Meng 		(void) fprintf(stdout, "%s\n%s\n",
54584246c8e9SJack Meng 		    gettext("iSCSI Initiator Service is disabled,"
54594246c8e9SJack Meng 		    " try 'svcadm enable network/iscsi/initiator' to"
54604246c8e9SJack Meng 		    " enable the service."),
54614246c8e9SJack Meng 		    gettext("For more information, please refer to"
5462*bbf21555SRichard Lowe 		    " iscsi(4D)."));
54634246c8e9SJack Meng 		return (B_FALSE);
54644246c8e9SJack Meng 	}
54654246c8e9SJack Meng 
54664246c8e9SJack Meng 	return (B_TRUE);
54674246c8e9SJack Meng }
54684246c8e9SJack Meng 
5469fcf3ce44SJohn Forte /*
5470fcf3ce44SJohn Forte  * Prints out see manual page.
5471fcf3ce44SJohn Forte  * Called out through atexit(3C) so is always last thing displayed.
5472fcf3ce44SJohn Forte  */
5473fcf3ce44SJohn Forte void
seeMan(void)5474fcf3ce44SJohn Forte seeMan(void)
5475fcf3ce44SJohn Forte {
5476fcf3ce44SJohn Forte 	static int sent = 0;
5477fcf3ce44SJohn Forte 
5478fcf3ce44SJohn Forte 	if (sent)
5479fcf3ce44SJohn Forte 		return;
5480fcf3ce44SJohn Forte 
5481*bbf21555SRichard Lowe 	(void) fprintf(stdout, "%s %s(8)\n",
5482fcf3ce44SJohn Forte 	    gettext("For more information, please see"), cmdName);
5483fcf3ce44SJohn Forte 
5484fcf3ce44SJohn Forte 	sent = 1;
5485fcf3ce44SJohn Forte }
5486fcf3ce44SJohn Forte 
5487fcf3ce44SJohn Forte 
5488fcf3ce44SJohn Forte /*
5489fcf3ce44SJohn Forte  * main calls a parser that checks syntax of the input command against
5490fcf3ce44SJohn Forte  * various rules tables.
5491fcf3ce44SJohn Forte  *
5492fcf3ce44SJohn Forte  * The parser provides usage feedback based upon same tables by calling
5493fcf3ce44SJohn Forte  * two usage functions, usage and subUsage, handling command and subcommand
5494fcf3ce44SJohn Forte  * usage respectively.
5495fcf3ce44SJohn Forte  *
5496fcf3ce44SJohn Forte  * The parser handles all printing of usage syntactical errors
5497fcf3ce44SJohn Forte  *
5498fcf3ce44SJohn Forte  * When syntax is successfully validated, the parser calls the associated
5499fcf3ce44SJohn Forte  * function using the subcommands table functions.
5500fcf3ce44SJohn Forte  *
5501fcf3ce44SJohn Forte  * Syntax is as follows:
5502fcf3ce44SJohn Forte  *	command subcommand [options] resource-type [<object>]
5503fcf3ce44SJohn Forte  *
5504fcf3ce44SJohn Forte  * The return value from the function is placed in funcRet
5505fcf3ce44SJohn Forte  */
5506fcf3ce44SJohn Forte int
main(int argc,char * argv[])5507fcf3ce44SJohn Forte main(int argc, char *argv[])
5508fcf3ce44SJohn Forte {
5509fcf3ce44SJohn Forte 	synTables_t synTables;
5510fcf3ce44SJohn Forte 	char versionString[VERSION_STRING_MAX_LEN];
5511fcf3ce44SJohn Forte 	int ret;
5512fcf3ce44SJohn Forte 	int funcRet = 0;
5513fcf3ce44SJohn Forte 	void *subcommandArgs = NULL;
5514fcf3ce44SJohn Forte 
5515fcf3ce44SJohn Forte 	if (geteuid() != 0) {
5516fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s\n", gettext("permission denied"));
5517fcf3ce44SJohn Forte 		return (1);
5518fcf3ce44SJohn Forte 	}
5519fcf3ce44SJohn Forte 
55204246c8e9SJack Meng 	if (checkServiceStatus() == B_FALSE) {
55214246c8e9SJack Meng 		return (1);
55224246c8e9SJack Meng 	}
55234246c8e9SJack Meng 
5524fcf3ce44SJohn Forte 	/* set global command name */
5525fcf3ce44SJohn Forte 	cmdName = getExecBasename(argv[0]);
5526fcf3ce44SJohn Forte 
5527fcf3ce44SJohn Forte 	(void) snprintf(versionString, sizeof (versionString), "%s.%s",
5528fcf3ce44SJohn Forte 	    VERSION_STRING_MAJOR, VERSION_STRING_MINOR);
5529fcf3ce44SJohn Forte 	synTables.versionString = versionString;
5530fcf3ce44SJohn Forte 	synTables.longOptionTbl = &longOptions[0];
5531fcf3ce44SJohn Forte 	synTables.subcommandTbl = &subcommands[0];
5532fcf3ce44SJohn Forte 	synTables.objectTbl = &objects[0];
5533fcf3ce44SJohn Forte 	synTables.objectRulesTbl = &objectRules[0];
5534fcf3ce44SJohn Forte 	synTables.optionRulesTbl = &optionRules[0];
5535fcf3ce44SJohn Forte 
5536fcf3ce44SJohn Forte 	/* call the CLI parser */
5537fcf3ce44SJohn Forte 	ret = cmdParse(argc, argv, synTables, subcommandArgs, &funcRet);
5538fcf3ce44SJohn Forte 	if (ret == -1) {
5539fcf3ce44SJohn Forte 		perror(cmdName);
5540fcf3ce44SJohn Forte 		ret = 1;
5541fcf3ce44SJohn Forte 	}
5542fcf3ce44SJohn Forte 
5543fcf3ce44SJohn Forte 	if (funcRet != 0) {
5544fcf3ce44SJohn Forte 		(void) fprintf(stderr, "%s: %s\n",
5545fcf3ce44SJohn Forte 		    cmdName, gettext("Unable to complete operation"));
5546fcf3ce44SJohn Forte 		ret = 1;
5547fcf3ce44SJohn Forte 	}
5548fcf3ce44SJohn Forte 	return (ret);
5549fcf3ce44SJohn Forte }
5550aff4bce5Syi zhang - Sun Microsystems - Beijing China 
5551aff4bce5Syi zhang - Sun Microsystems - Beijing China static int
setTunableParameters(IMA_OID oid,char * optarg)5552aff4bce5Syi zhang - Sun Microsystems - Beijing China setTunableParameters(IMA_OID oid, char *optarg)
5553aff4bce5Syi zhang - Sun Microsystems - Beijing China {
5554aff4bce5Syi zhang - Sun Microsystems - Beijing China 	char keyp[MAXOPTARGLEN];
5555aff4bce5Syi zhang - Sun Microsystems - Beijing China 	char valp[MAXOPTARGLEN];
5556aff4bce5Syi zhang - Sun Microsystems - Beijing China 	int key;
5557aff4bce5Syi zhang - Sun Microsystems - Beijing China 	IMA_STATUS status;
5558aff4bce5Syi zhang - Sun Microsystems - Beijing China 	IMA_UINT uintValue;
5559aff4bce5Syi zhang - Sun Microsystems - Beijing China 	ISCSI_TUNABLE_PARAM	tunableObj;
5560aff4bce5Syi zhang - Sun Microsystems - Beijing China 	char *nameValueString, *endptr;
5561aff4bce5Syi zhang - Sun Microsystems - Beijing China 
5562aff4bce5Syi zhang - Sun Microsystems - Beijing China 	if ((nameValueString = strdup(optarg)) == NULL) {
5563aff4bce5Syi zhang - Sun Microsystems - Beijing China 		if (errno == ENOMEM) {
5564aff4bce5Syi zhang - Sun Microsystems - Beijing China 			(void) fprintf(stderr, "%s: %s\n",
5565aff4bce5Syi zhang - Sun Microsystems - Beijing China 			    cmdName, strerror(errno));
5566aff4bce5Syi zhang - Sun Microsystems - Beijing China 		} else {
5567aff4bce5Syi zhang - Sun Microsystems - Beijing China 			(void) fprintf(stderr, "%s: %s\n", cmdName,
5568aff4bce5Syi zhang - Sun Microsystems - Beijing China 			    gettext("unknown error"));
5569aff4bce5Syi zhang - Sun Microsystems - Beijing China 		}
5570aff4bce5Syi zhang - Sun Microsystems - Beijing China 		return (1);
5571aff4bce5Syi zhang - Sun Microsystems - Beijing China 	}
5572aff4bce5Syi zhang - Sun Microsystems - Beijing China 
5573aff4bce5Syi zhang - Sun Microsystems - Beijing China 	(void) memset(keyp, 0, sizeof (keyp));
5574aff4bce5Syi zhang - Sun Microsystems - Beijing China 	(void) memset(valp, 0, sizeof (valp));
5575aff4bce5Syi zhang - Sun Microsystems - Beijing China 	if (sscanf(nameValueString, gettext("%[^=]=%s"), keyp, valp) != 2) {
5576aff4bce5Syi zhang - Sun Microsystems - Beijing China 		(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
5577aff4bce5Syi zhang - Sun Microsystems - Beijing China 		    gettext("Unknown param"), nameValueString);
5578aff4bce5Syi zhang - Sun Microsystems - Beijing China 		if (nameValueString) {
5579aff4bce5Syi zhang - Sun Microsystems - Beijing China 			free(nameValueString);
5580aff4bce5Syi zhang - Sun Microsystems - Beijing China 			nameValueString = NULL;
5581aff4bce5Syi zhang - Sun Microsystems - Beijing China 		}
5582aff4bce5Syi zhang - Sun Microsystems - Beijing China 		return (1);
5583aff4bce5Syi zhang - Sun Microsystems - Beijing China 	}
5584aff4bce5Syi zhang - Sun Microsystems - Beijing China 	if ((key = getTunableParam(keyp)) == -1) {
5585aff4bce5Syi zhang - Sun Microsystems - Beijing China 		(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
5586aff4bce5Syi zhang - Sun Microsystems - Beijing China 		    gettext("Unknown key"), keyp);
5587aff4bce5Syi zhang - Sun Microsystems - Beijing China 		if (nameValueString) {
5588aff4bce5Syi zhang - Sun Microsystems - Beijing China 			free(nameValueString);
5589aff4bce5Syi zhang - Sun Microsystems - Beijing China 			nameValueString = NULL;
5590aff4bce5Syi zhang - Sun Microsystems - Beijing China 		}
5591aff4bce5Syi zhang - Sun Microsystems - Beijing China 		return (1);
5592aff4bce5Syi zhang - Sun Microsystems - Beijing China 	}
5593aff4bce5Syi zhang - Sun Microsystems - Beijing China 	switch (key) {
5594aff4bce5Syi zhang - Sun Microsystems - Beijing China 	case RECV_LOGIN_RSP_TIMEOUT:
5595aff4bce5Syi zhang - Sun Microsystems - Beijing China 	case CONN_LOGIN_MAX:
5596aff4bce5Syi zhang - Sun Microsystems - Beijing China 	case POLLING_LOGIN_DELAY:
5597aff4bce5Syi zhang - Sun Microsystems - Beijing China 		errno = 0;
5598aff4bce5Syi zhang - Sun Microsystems - Beijing China 		uintValue = strtoul(valp, &endptr, 0);
5599aff4bce5Syi zhang - Sun Microsystems - Beijing China 		if (*endptr != '\0' || errno != 0) {
5600aff4bce5Syi zhang - Sun Microsystems - Beijing China 			(void) fprintf(stderr, "%s: %s - %s\n",
5601aff4bce5Syi zhang - Sun Microsystems - Beijing China 			    cmdName,
5602aff4bce5Syi zhang - Sun Microsystems - Beijing China 			    gettext("invalid option argument"),
5603aff4bce5Syi zhang - Sun Microsystems - Beijing China 			    optarg);
5604aff4bce5Syi zhang - Sun Microsystems - Beijing China 			if (nameValueString) {
5605aff4bce5Syi zhang - Sun Microsystems - Beijing China 				free(nameValueString);
5606aff4bce5Syi zhang - Sun Microsystems - Beijing China 				nameValueString = NULL;
5607aff4bce5Syi zhang - Sun Microsystems - Beijing China 			}
5608aff4bce5Syi zhang - Sun Microsystems - Beijing China 			return (1);
5609aff4bce5Syi zhang - Sun Microsystems - Beijing China 		}
5610aff4bce5Syi zhang - Sun Microsystems - Beijing China 		if (uintValue > 3600) {
5611aff4bce5Syi zhang - Sun Microsystems - Beijing China 			(void) fprintf(stderr, "%s: %s\n",
5612aff4bce5Syi zhang - Sun Microsystems - Beijing China 			    cmdName,
5613aff4bce5Syi zhang - Sun Microsystems - Beijing China gettext("value must be between 0 and 3600"));
5614aff4bce5Syi zhang - Sun Microsystems - Beijing China 			if (nameValueString) {
5615aff4bce5Syi zhang - Sun Microsystems - Beijing China 				free(nameValueString);
5616aff4bce5Syi zhang - Sun Microsystems - Beijing China 				nameValueString = NULL;
5617aff4bce5Syi zhang - Sun Microsystems - Beijing China 			}
5618aff4bce5Syi zhang - Sun Microsystems - Beijing China 			return (1);
5619aff4bce5Syi zhang - Sun Microsystems - Beijing China 		}
5620aff4bce5Syi zhang - Sun Microsystems - Beijing China 
5621aff4bce5Syi zhang - Sun Microsystems - Beijing China 		if (chkConnLoginMaxPollingLoginDelay(oid, key, uintValue) > 0) {
5622aff4bce5Syi zhang - Sun Microsystems - Beijing China 			if (nameValueString) {
5623aff4bce5Syi zhang - Sun Microsystems - Beijing China 				free(nameValueString);
5624aff4bce5Syi zhang - Sun Microsystems - Beijing China 				nameValueString = NULL;
5625aff4bce5Syi zhang - Sun Microsystems - Beijing China 			}
5626aff4bce5Syi zhang - Sun Microsystems - Beijing China 			return (1);
5627aff4bce5Syi zhang - Sun Microsystems - Beijing China 		}
5628aff4bce5Syi zhang - Sun Microsystems - Beijing China 
5629aff4bce5Syi zhang - Sun Microsystems - Beijing China 		if (key == RECV_LOGIN_RSP_TIMEOUT) {
5630aff4bce5Syi zhang - Sun Microsystems - Beijing China 			tunableObj.tunable_objectType =
5631aff4bce5Syi zhang - Sun Microsystems - Beijing China 			    ISCSI_RX_TIMEOUT_VALUE;
5632aff4bce5Syi zhang - Sun Microsystems - Beijing China 		} else if (key == CONN_LOGIN_MAX) {
5633aff4bce5Syi zhang - Sun Microsystems - Beijing China 			tunableObj.tunable_objectType =
5634aff4bce5Syi zhang - Sun Microsystems - Beijing China 			    ISCSI_CONN_DEFAULT_LOGIN_MAX;
5635aff4bce5Syi zhang - Sun Microsystems - Beijing China 		} else if (key == POLLING_LOGIN_DELAY) {
5636aff4bce5Syi zhang - Sun Microsystems - Beijing China 			tunableObj.tunable_objectType =
5637aff4bce5Syi zhang - Sun Microsystems - Beijing China 			    ISCSI_LOGIN_POLLING_DELAY;
5638aff4bce5Syi zhang - Sun Microsystems - Beijing China 		}
5639aff4bce5Syi zhang - Sun Microsystems - Beijing China 		tunableObj.tunable_objectValue = valp;
5640aff4bce5Syi zhang - Sun Microsystems - Beijing China 		status = SUN_IMA_SetTunableProperties(oid, &tunableObj);
5641aff4bce5Syi zhang - Sun Microsystems - Beijing China 		break;
5642aff4bce5Syi zhang - Sun Microsystems - Beijing China 	default:
5643aff4bce5Syi zhang - Sun Microsystems - Beijing China 		(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
5644aff4bce5Syi zhang - Sun Microsystems - Beijing China 		    gettext("Unsupported key"), keyp);
5645aff4bce5Syi zhang - Sun Microsystems - Beijing China 		if (nameValueString) {
5646aff4bce5Syi zhang - Sun Microsystems - Beijing China 			free(nameValueString);
5647aff4bce5Syi zhang - Sun Microsystems - Beijing China 			nameValueString = NULL;
5648aff4bce5Syi zhang - Sun Microsystems - Beijing China 		}
5649aff4bce5Syi zhang - Sun Microsystems - Beijing China 		return (1);
5650aff4bce5Syi zhang - Sun Microsystems - Beijing China 	}
5651aff4bce5Syi zhang - Sun Microsystems - Beijing China 	if (!IMA_SUCCESS(status)) {
5652aff4bce5Syi zhang - Sun Microsystems - Beijing China 		printLibError(status);
5653aff4bce5Syi zhang - Sun Microsystems - Beijing China 		if (nameValueString) {
5654aff4bce5Syi zhang - Sun Microsystems - Beijing China 			free(nameValueString);
5655aff4bce5Syi zhang - Sun Microsystems - Beijing China 			nameValueString = NULL;
5656aff4bce5Syi zhang - Sun Microsystems - Beijing China 		}
5657aff4bce5Syi zhang - Sun Microsystems - Beijing China 		return (1);
5658aff4bce5Syi zhang - Sun Microsystems - Beijing China 	}
5659aff4bce5Syi zhang - Sun Microsystems - Beijing China 
5660aff4bce5Syi zhang - Sun Microsystems - Beijing China 	if (nameValueString) {
5661aff4bce5Syi zhang - Sun Microsystems - Beijing China 		free(nameValueString);
5662aff4bce5Syi zhang - Sun Microsystems - Beijing China 		nameValueString = NULL;
5663aff4bce5Syi zhang - Sun Microsystems - Beijing China 	}
5664aff4bce5Syi zhang - Sun Microsystems - Beijing China 	return (0);
5665aff4bce5Syi zhang - Sun Microsystems - Beijing China }
5666aff4bce5Syi zhang - Sun Microsystems - Beijing China 
5667aff4bce5Syi zhang - Sun Microsystems - Beijing China /*
5668aff4bce5Syi zhang - Sun Microsystems - Beijing China  * Print tunable parameters information
5669aff4bce5Syi zhang - Sun Microsystems - Beijing China  */
5670aff4bce5Syi zhang - Sun Microsystems - Beijing China static int
printTunableParameters(IMA_OID oid)5671aff4bce5Syi zhang - Sun Microsystems - Beijing China printTunableParameters(IMA_OID oid)
5672aff4bce5Syi zhang - Sun Microsystems - Beijing China {
5673aff4bce5Syi zhang - Sun Microsystems - Beijing China 	ISCSI_TUNABLE_PARAM tunableObj;
5674aff4bce5Syi zhang - Sun Microsystems - Beijing China 	char value[MAXOPTARGLEN] = "\0";
5675aff4bce5Syi zhang - Sun Microsystems - Beijing China 	IMA_STATUS status;
5676aff4bce5Syi zhang - Sun Microsystems - Beijing China 
5677aff4bce5Syi zhang - Sun Microsystems - Beijing China 	tunableObj.tunable_objectValue = value;
5678aff4bce5Syi zhang - Sun Microsystems - Beijing China 	(void) fprintf(stdout, "\t%s:\n",
5679aff4bce5Syi zhang - Sun Microsystems - Beijing China 	    gettext("Tunable Parameters (Default/Configured)"));
5680aff4bce5Syi zhang - Sun Microsystems - Beijing China 	tunableObj.tunable_objectType = ISCSI_RX_TIMEOUT_VALUE;
5681aff4bce5Syi zhang - Sun Microsystems - Beijing China 	status = SUN_IMA_GetTunableProperties(oid, &tunableObj);
5682aff4bce5Syi zhang - Sun Microsystems - Beijing China 	if (!IMA_SUCCESS(status)) {
5683aff4bce5Syi zhang - Sun Microsystems - Beijing China 		printLibError(status);
5684aff4bce5Syi zhang - Sun Microsystems - Beijing China 		return (1);
5685aff4bce5Syi zhang - Sun Microsystems - Beijing China 	}
5686aff4bce5Syi zhang - Sun Microsystems - Beijing China 	if (value[0] == '\0') {
5687aff4bce5Syi zhang - Sun Microsystems - Beijing China 		value[0] = '-';
5688aff4bce5Syi zhang - Sun Microsystems - Beijing China 		value[1] = '\0';
5689aff4bce5Syi zhang - Sun Microsystems - Beijing China 	}
5690aff4bce5Syi zhang - Sun Microsystems - Beijing China 	(void) fprintf(stdout, "\t\t%s: ",
5691aff4bce5Syi zhang - Sun Microsystems - Beijing China 	    gettext("Session Login Response Time"));
5692aff4bce5Syi zhang - Sun Microsystems - Beijing China 	(void) fprintf(stdout, "%s/%s\n", ISCSI_DEFAULT_RX_TIMEOUT_VALUE,
5693aff4bce5Syi zhang - Sun Microsystems - Beijing China 	    tunableObj.tunable_objectValue);
5694aff4bce5Syi zhang - Sun Microsystems - Beijing China 
5695aff4bce5Syi zhang - Sun Microsystems - Beijing China 	value[0] = '\0';
5696aff4bce5Syi zhang - Sun Microsystems - Beijing China 	tunableObj.tunable_objectType = ISCSI_CONN_DEFAULT_LOGIN_MAX;
5697aff4bce5Syi zhang - Sun Microsystems - Beijing China 	status = SUN_IMA_GetTunableProperties(oid, &tunableObj);
5698aff4bce5Syi zhang - Sun Microsystems - Beijing China 	if (!IMA_SUCCESS(status)) {
5699aff4bce5Syi zhang - Sun Microsystems - Beijing China 		printLibError(status);
5700aff4bce5Syi zhang - Sun Microsystems - Beijing China 		return (1);
5701aff4bce5Syi zhang - Sun Microsystems - Beijing China 	}
5702aff4bce5Syi zhang - Sun Microsystems - Beijing China 	if (value[0] == '\0') {
5703aff4bce5Syi zhang - Sun Microsystems - Beijing China 		value[0] = '-';
5704aff4bce5Syi zhang - Sun Microsystems - Beijing China 		value[1] = '\0';
5705aff4bce5Syi zhang - Sun Microsystems - Beijing China 	}
5706aff4bce5Syi zhang - Sun Microsystems - Beijing China 	(void) fprintf(stdout, "\t\t%s: ",
5707aff4bce5Syi zhang - Sun Microsystems - Beijing China 	    gettext("Maximum Connection Retry Time"));
5708aff4bce5Syi zhang - Sun Microsystems - Beijing China 	(void) fprintf(stdout, "%s/%s\n", ISCSI_DEFAULT_CONN_DEFAULT_LOGIN_MAX,
5709aff4bce5Syi zhang - Sun Microsystems - Beijing China 	    tunableObj.tunable_objectValue);
5710aff4bce5Syi zhang - Sun Microsystems - Beijing China 
5711aff4bce5Syi zhang - Sun Microsystems - Beijing China 	value[0] = '\0';
5712aff4bce5Syi zhang - Sun Microsystems - Beijing China 	tunableObj.tunable_objectType = ISCSI_LOGIN_POLLING_DELAY;
5713aff4bce5Syi zhang - Sun Microsystems - Beijing China 	status = SUN_IMA_GetTunableProperties(oid, &tunableObj);
5714aff4bce5Syi zhang - Sun Microsystems - Beijing China 	if (!IMA_SUCCESS(status)) {
5715aff4bce5Syi zhang - Sun Microsystems - Beijing China 		printLibError(status);
5716aff4bce5Syi zhang - Sun Microsystems - Beijing China 		return (1);
5717aff4bce5Syi zhang - Sun Microsystems - Beijing China 	}
5718aff4bce5Syi zhang - Sun Microsystems - Beijing China 	if (value[0] == '\0') {
5719aff4bce5Syi zhang - Sun Microsystems - Beijing China 		value[0] = '-';
5720aff4bce5Syi zhang - Sun Microsystems - Beijing China 		value[1] = '\0';
5721aff4bce5Syi zhang - Sun Microsystems - Beijing China 	}
5722aff4bce5Syi zhang - Sun Microsystems - Beijing China 	(void) fprintf(stdout, "\t\t%s: ",
5723aff4bce5Syi zhang - Sun Microsystems - Beijing China 	    gettext("Login Retry Time Interval"));
5724aff4bce5Syi zhang - Sun Microsystems - Beijing China 	(void) fprintf(stdout, "%s/%s\n", ISCSI_DEFAULT_LOGIN_POLLING_DELAY,
5725aff4bce5Syi zhang - Sun Microsystems - Beijing China 	    tunableObj.tunable_objectValue);
5726aff4bce5Syi zhang - Sun Microsystems - Beijing China 	return (0);
5727aff4bce5Syi zhang - Sun Microsystems - Beijing China }
5728aff4bce5Syi zhang - Sun Microsystems - Beijing China 
5729aff4bce5Syi zhang - Sun Microsystems - Beijing China /*
5730aff4bce5Syi zhang - Sun Microsystems - Beijing China  * This is helper function to check conn_login_max and polling_login_delay.
5731aff4bce5Syi zhang - Sun Microsystems - Beijing China  */
5732aff4bce5Syi zhang - Sun Microsystems - Beijing China static int
chkConnLoginMaxPollingLoginDelay(IMA_OID oid,int key,int uintValue)5733aff4bce5Syi zhang - Sun Microsystems - Beijing China chkConnLoginMaxPollingLoginDelay(IMA_OID oid, int key, int uintValue)
5734aff4bce5Syi zhang - Sun Microsystems - Beijing China {
5735aff4bce5Syi zhang - Sun Microsystems - Beijing China 	char valuep[MAXOPTARGLEN];
5736aff4bce5Syi zhang - Sun Microsystems - Beijing China 	IMA_STATUS	status;
5737aff4bce5Syi zhang - Sun Microsystems - Beijing China 	IMA_UINT	getValue;
5738aff4bce5Syi zhang - Sun Microsystems - Beijing China 	ISCSI_TUNABLE_PARAM	getObj;
5739aff4bce5Syi zhang - Sun Microsystems - Beijing China 	char *endptr;
5740aff4bce5Syi zhang - Sun Microsystems - Beijing China 
5741aff4bce5Syi zhang - Sun Microsystems - Beijing China 	if (key == CONN_LOGIN_MAX) {
5742aff4bce5Syi zhang - Sun Microsystems - Beijing China 		getObj.tunable_objectType = ISCSI_LOGIN_POLLING_DELAY;
5743fb2a9baeSyi zhang - Sun Microsystems - Beijing China 	} else if (key == POLLING_LOGIN_DELAY) {
5744aff4bce5Syi zhang - Sun Microsystems - Beijing China 		getObj.tunable_objectType = ISCSI_CONN_DEFAULT_LOGIN_MAX;
5745fb2a9baeSyi zhang - Sun Microsystems - Beijing China 	} else {
5746fb2a9baeSyi zhang - Sun Microsystems - Beijing China 		return (0);
5747aff4bce5Syi zhang - Sun Microsystems - Beijing China 	}
5748aff4bce5Syi zhang - Sun Microsystems - Beijing China 	valuep[0] = '\0';
5749aff4bce5Syi zhang - Sun Microsystems - Beijing China 	getObj.tunable_objectValue = valuep;
5750aff4bce5Syi zhang - Sun Microsystems - Beijing China 	status = SUN_IMA_GetTunableProperties(oid, &getObj);
5751aff4bce5Syi zhang - Sun Microsystems - Beijing China 	if (!IMA_SUCCESS(status)) {
5752aff4bce5Syi zhang - Sun Microsystems - Beijing China 		printLibError(status);
5753aff4bce5Syi zhang - Sun Microsystems - Beijing China 		return (1);
5754aff4bce5Syi zhang - Sun Microsystems - Beijing China 	}
5755aff4bce5Syi zhang - Sun Microsystems - Beijing China 	if (valuep[0] == '\0') {
5756aff4bce5Syi zhang - Sun Microsystems - Beijing China 		if (key == CONN_LOGIN_MAX) {
5757aff4bce5Syi zhang - Sun Microsystems - Beijing China 			(void) strlcpy(valuep,
5758aff4bce5Syi zhang - Sun Microsystems - Beijing China 			    ISCSI_DEFAULT_LOGIN_POLLING_DELAY,
5759aff4bce5Syi zhang - Sun Microsystems - Beijing China 			    strlen(ISCSI_DEFAULT_LOGIN_POLLING_DELAY) +1);
5760aff4bce5Syi zhang - Sun Microsystems - Beijing China 		} else {
5761aff4bce5Syi zhang - Sun Microsystems - Beijing China 			(void) strlcpy(valuep,
5762aff4bce5Syi zhang - Sun Microsystems - Beijing China 			    ISCSI_DEFAULT_CONN_DEFAULT_LOGIN_MAX,
5763aff4bce5Syi zhang - Sun Microsystems - Beijing China 			    strlen(ISCSI_DEFAULT_CONN_DEFAULT_LOGIN_MAX) +1);
5764aff4bce5Syi zhang - Sun Microsystems - Beijing China 		}
5765aff4bce5Syi zhang - Sun Microsystems - Beijing China 	}
5766aff4bce5Syi zhang - Sun Microsystems - Beijing China 
5767aff4bce5Syi zhang - Sun Microsystems - Beijing China 	errno = 0;
5768aff4bce5Syi zhang - Sun Microsystems - Beijing China 	getValue = strtoul(valuep, &endptr, 0);
5769aff4bce5Syi zhang - Sun Microsystems - Beijing China 	if (*endptr != '\0' || errno != 0) {
5770aff4bce5Syi zhang - Sun Microsystems - Beijing China 		(void) fprintf(stderr, "%s: %s - %s\n",
5771aff4bce5Syi zhang - Sun Microsystems - Beijing China 		    cmdName,
5772aff4bce5Syi zhang - Sun Microsystems - Beijing China 		    gettext("cannot convert tunable string"),
5773aff4bce5Syi zhang - Sun Microsystems - Beijing China 		    valuep);
5774aff4bce5Syi zhang - Sun Microsystems - Beijing China 		return (1);
5775aff4bce5Syi zhang - Sun Microsystems - Beijing China 	}
5776aff4bce5Syi zhang - Sun Microsystems - Beijing China 	if (key == CONN_LOGIN_MAX) {
5777aff4bce5Syi zhang - Sun Microsystems - Beijing China 		if (uintValue < getValue) {
5778aff4bce5Syi zhang - Sun Microsystems - Beijing China 			(void) fprintf(stderr, "%s: %s %ld\n",
5779aff4bce5Syi zhang - Sun Microsystems - Beijing China 			    cmdName, gettext("value must larger than"),
5780aff4bce5Syi zhang - Sun Microsystems - Beijing China 			    getValue);
5781aff4bce5Syi zhang - Sun Microsystems - Beijing China 			return (1);
5782aff4bce5Syi zhang - Sun Microsystems - Beijing China 		}
5783aff4bce5Syi zhang - Sun Microsystems - Beijing China 	} else {
5784aff4bce5Syi zhang - Sun Microsystems - Beijing China 		if (uintValue > getValue) {
5785aff4bce5Syi zhang - Sun Microsystems - Beijing China 			(void) fprintf(stderr, "%s: %s %ld\n",
5786aff4bce5Syi zhang - Sun Microsystems - Beijing China 			    cmdName, gettext("value must smaller than"),
5787aff4bce5Syi zhang - Sun Microsystems - Beijing China 			    getValue);
5788aff4bce5Syi zhang - Sun Microsystems - Beijing China 			return (1);
5789aff4bce5Syi zhang - Sun Microsystems - Beijing China 		}
5790aff4bce5Syi zhang - Sun Microsystems - Beijing China 	}
5791aff4bce5Syi zhang - Sun Microsystems - Beijing China 	return (0);
5792aff4bce5Syi zhang - Sun Microsystems - Beijing China }
5793