xref: /onnv-gate/usr/src/cmd/iscsiadm/iscsiadm_main.c (revision 12546:b9d61378e1b8)
17836SJohn.Forte@Sun.COM /*
27836SJohn.Forte@Sun.COM  * CDDL HEADER START
37836SJohn.Forte@Sun.COM  *
47836SJohn.Forte@Sun.COM  * The contents of this file are subject to the terms of the
57836SJohn.Forte@Sun.COM  * Common Development and Distribution License (the "License").
67836SJohn.Forte@Sun.COM  * You may not use this file except in compliance with the License.
77836SJohn.Forte@Sun.COM  *
87836SJohn.Forte@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97836SJohn.Forte@Sun.COM  * or http://www.opensolaris.org/os/licensing.
107836SJohn.Forte@Sun.COM  * See the License for the specific language governing permissions
117836SJohn.Forte@Sun.COM  * and limitations under the License.
127836SJohn.Forte@Sun.COM  *
137836SJohn.Forte@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
147836SJohn.Forte@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157836SJohn.Forte@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
167836SJohn.Forte@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
177836SJohn.Forte@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
187836SJohn.Forte@Sun.COM  *
197836SJohn.Forte@Sun.COM  * CDDL HEADER END
207836SJohn.Forte@Sun.COM  */
217836SJohn.Forte@Sun.COM /*
2212052SZhang.Yi@Sun.COM  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
237836SJohn.Forte@Sun.COM  */
247836SJohn.Forte@Sun.COM 
257836SJohn.Forte@Sun.COM #include <stdlib.h>
267836SJohn.Forte@Sun.COM #include <stdio.h>
277836SJohn.Forte@Sun.COM #include <wchar.h>
287836SJohn.Forte@Sun.COM #include <widec.h>
297836SJohn.Forte@Sun.COM #include <sys/types.h>
307836SJohn.Forte@Sun.COM #include <sys/socket.h>
317836SJohn.Forte@Sun.COM #include <arpa/inet.h>
327836SJohn.Forte@Sun.COM #include <netdb.h>
337836SJohn.Forte@Sun.COM #include <unistd.h>
347836SJohn.Forte@Sun.COM #include <libintl.h>
357836SJohn.Forte@Sun.COM #include <limits.h>
367836SJohn.Forte@Sun.COM #include <string.h>
377836SJohn.Forte@Sun.COM #include <strings.h>
387836SJohn.Forte@Sun.COM #include <syslog.h>
397836SJohn.Forte@Sun.COM #include <errno.h>
407836SJohn.Forte@Sun.COM #include <netinet/in.h>
417836SJohn.Forte@Sun.COM #include <sys/socket.h>
427836SJohn.Forte@Sun.COM #include <arpa/inet.h>
437836SJohn.Forte@Sun.COM #include <wctype.h>
447836SJohn.Forte@Sun.COM #include <assert.h>
457836SJohn.Forte@Sun.COM 
467836SJohn.Forte@Sun.COM #include <ima.h>
4710156SZhang.Yi@Sun.COM #include <libsun_ima.h>
488656SPeter.Dunlap@Sun.COM #include <sys/iscsi_protocol.h>
497836SJohn.Forte@Sun.COM #include <sys/scsi/adapters/iscsi_if.h>
507836SJohn.Forte@Sun.COM 
517836SJohn.Forte@Sun.COM #include "cmdparse.h"
527836SJohn.Forte@Sun.COM #include "sun_ima.h"
537836SJohn.Forte@Sun.COM #include "iscsiadm.h"
547836SJohn.Forte@Sun.COM 
557836SJohn.Forte@Sun.COM #define	VERSION_STRING_MAX_LEN	10
567836SJohn.Forte@Sun.COM #define	MAX_LONG_CHAR_LEN 19
577836SJohn.Forte@Sun.COM 
587836SJohn.Forte@Sun.COM #define	MAX_AUTH_METHODS 5
597836SJohn.Forte@Sun.COM /*
607836SJohn.Forte@Sun.COM  * Version number:
617836SJohn.Forte@Sun.COM  *  MAJOR - This should only change when there is an incompatible change made
627836SJohn.Forte@Sun.COM  *  to the interfaces or the output.
637836SJohn.Forte@Sun.COM  *
647836SJohn.Forte@Sun.COM  *  MINOR - This should change whenever there is a new command or new feature
657836SJohn.Forte@Sun.COM  *  with no incompatible change.
667836SJohn.Forte@Sun.COM  */
677836SJohn.Forte@Sun.COM #define	VERSION_STRING_MAJOR	    "1"
687836SJohn.Forte@Sun.COM #define	VERSION_STRING_MINOR	    "0"
697836SJohn.Forte@Sun.COM 
707836SJohn.Forte@Sun.COM #define	OPTIONSTRING1	"yes|no"
717836SJohn.Forte@Sun.COM #define	OPTIONSTRING2	"initiator node name"
727836SJohn.Forte@Sun.COM #define	OPTIONSTRING3	"initiator node alias"
737836SJohn.Forte@Sun.COM #define	OPTIONSTRING4	"enable|disable"
747836SJohn.Forte@Sun.COM #define	OPTIONSTRING5	"key=value,..."
757836SJohn.Forte@Sun.COM #define	OPTIONSTRING6	"none|CRC32"
767836SJohn.Forte@Sun.COM #define	OPTIONSTRING7	"CHAP name"
777836SJohn.Forte@Sun.COM #define	OPTIONSTRING8	"<# sessions>|<IP Address>[,<IP Address>]*"
7810156SZhang.Yi@Sun.COM #define	OPTIONSTRING9	"tunable-prop=value"
797836SJohn.Forte@Sun.COM #define	OPTIONVAL1	"0 to 3600"
807836SJohn.Forte@Sun.COM #define	OPTIONVAL2	"512 to 2**24 - 1"
817836SJohn.Forte@Sun.COM #define	OPTIONVAL3	"1 to 65535"
827836SJohn.Forte@Sun.COM #define	OPTIONVAL4	"<IP address>[:port]"
837836SJohn.Forte@Sun.COM 
847836SJohn.Forte@Sun.COM #define	MAX_ISCSI_NAME_LEN	    223
857836SJohn.Forte@Sun.COM #define	MAX_ADDRESS_LEN		    255
867836SJohn.Forte@Sun.COM #define	MIN_CHAP_SECRET_LEN	    12
877836SJohn.Forte@Sun.COM #define	MAX_CHAP_SECRET_LEN	    16
887836SJohn.Forte@Sun.COM #define	DEFAULT_ISCSI_PORT	    3260
897836SJohn.Forte@Sun.COM #define	ISNS_DEFAULT_SERVER_PORT    3205
907836SJohn.Forte@Sun.COM #define	DEFAULT_RADIUS_PORT	    1812
917836SJohn.Forte@Sun.COM #define	MAX_CHAP_NAME_LEN	    512
9210156SZhang.Yi@Sun.COM #define	ISCSI_DEFAULT_RX_TIMEOUT_VALUE		"60"
9310156SZhang.Yi@Sun.COM #define	ISCSI_DEFAULT_CONN_DEFAULT_LOGIN_MAX	"180"
9410156SZhang.Yi@Sun.COM #define	ISCSI_DEFAULT_LOGIN_POLLING_DELAY	"60"
957836SJohn.Forte@Sun.COM 
967836SJohn.Forte@Sun.COM /* For listNode */
977836SJohn.Forte@Sun.COM #define	INF_ERROR		1
987836SJohn.Forte@Sun.COM #define	INVALID_NODE_NAME	2
997836SJohn.Forte@Sun.COM 
1007836SJohn.Forte@Sun.COM #define	IMABOOLPRINT(prop, option)	 \
1017836SJohn.Forte@Sun.COM 	if ((option) == PRINT_CONFIGURED_PARAMS) { \
1027836SJohn.Forte@Sun.COM 		(void) fprintf(stdout, "%s/%s\n", \
1037836SJohn.Forte@Sun.COM 		(prop).defaultValue == IMA_TRUE ? gettext("yes") : \
1047836SJohn.Forte@Sun.COM 			gettext("no"), \
1057836SJohn.Forte@Sun.COM 		(prop).currentValueValid == IMA_TRUE ? \
1067836SJohn.Forte@Sun.COM 			((prop).currentValue == IMA_TRUE ? \
1077836SJohn.Forte@Sun.COM 			gettext("yes"): gettext("no")) : "-"); \
1087836SJohn.Forte@Sun.COM 	} else if ((option) == PRINT_NEGOTIATED_PARAMS) { \
1097836SJohn.Forte@Sun.COM 		(void) fprintf(stdout, "%s\n", \
1107836SJohn.Forte@Sun.COM 		(prop).currentValueValid == IMA_TRUE ? \
1117836SJohn.Forte@Sun.COM 		(((prop).currentValue == IMA_TRUE) ? gettext("yes") : \
1127836SJohn.Forte@Sun.COM 		gettext("no")) : "-"); \
1137836SJohn.Forte@Sun.COM 	}
1147836SJohn.Forte@Sun.COM 
1157836SJohn.Forte@Sun.COM #define	IMAMINMAXPRINT(prop, option) \
1167836SJohn.Forte@Sun.COM 	if ((option) == PRINT_CONFIGURED_PARAMS) { \
1177836SJohn.Forte@Sun.COM 		(void) fprintf(stdout, "%d/", (prop).defaultValue); \
1187836SJohn.Forte@Sun.COM 		if ((prop).currentValueValid == IMA_TRUE) { \
1197836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "%d\n", (prop).currentValue); \
1207836SJohn.Forte@Sun.COM 		} else if ((prop).currentValueValid == IMA_FALSE) { \
1217836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "%s\n", "-"); \
1227836SJohn.Forte@Sun.COM 		} \
1237836SJohn.Forte@Sun.COM 	} else if ((option) == PRINT_NEGOTIATED_PARAMS) { \
1247836SJohn.Forte@Sun.COM 		if ((prop).currentValueValid == IMA_TRUE) { \
1257836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "%d\n", (prop).currentValue); \
1267836SJohn.Forte@Sun.COM 		} else if ((prop).currentValueValid == IMA_FALSE) { \
1277836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "%s\n", "-"); \
1287836SJohn.Forte@Sun.COM 		} \
1297836SJohn.Forte@Sun.COM 	}
1307836SJohn.Forte@Sun.COM 
1317836SJohn.Forte@Sun.COM /* forward declarations */
1327836SJohn.Forte@Sun.COM #define	PARSE_ADDR_OK				0
1337836SJohn.Forte@Sun.COM #define	PARSE_ADDR_MISSING_CLOSING_BRACKET	1
1347836SJohn.Forte@Sun.COM #define	PARSE_ADDR_PORT_OUT_OF_RANGE		2
1357836SJohn.Forte@Sun.COM #define	PARSE_TARGET_OK				0
1367836SJohn.Forte@Sun.COM #define	PARSE_TARGET_INVALID_TPGT		1
1377836SJohn.Forte@Sun.COM #define	PARSE_TARGET_INVALID_ADDR		2
1387836SJohn.Forte@Sun.COM 
1397836SJohn.Forte@Sun.COM #define	PRINT_CONFIGURED_PARAMS			1
1407836SJohn.Forte@Sun.COM #define	PRINT_NEGOTIATED_PARAMS			2
1417836SJohn.Forte@Sun.COM 
1427836SJohn.Forte@Sun.COM typedef enum iSCSINameCheckStatus {
1437836SJohn.Forte@Sun.COM 	iSCSINameCheckOK,
1447836SJohn.Forte@Sun.COM 	iSCSINameLenZero,
1457836SJohn.Forte@Sun.COM 	iSCSINameLenExceededMax,
1467836SJohn.Forte@Sun.COM 	iSCSINameUnknownType,
1477836SJohn.Forte@Sun.COM 	iSCSINameInvalidCharacter,
1487836SJohn.Forte@Sun.COM 	iSCSINameIqnFormatError,
1497836SJohn.Forte@Sun.COM 	iSCSINameEUIFormatError,
1507836SJohn.Forte@Sun.COM 	iSCSINameIqnDateFormatError,
1517836SJohn.Forte@Sun.COM 	iSCSINameIqnSubdomainFormatError,
1527836SJohn.Forte@Sun.COM 	iSCSINameIqnInvalidYearError,
1537836SJohn.Forte@Sun.COM 	iSCSINameIqnInvalidMonthError,
1547836SJohn.Forte@Sun.COM 	iSCSINameIqnFQDNError
1557836SJohn.Forte@Sun.COM } iSCSINameCheckStatusType;
1567836SJohn.Forte@Sun.COM 
1577836SJohn.Forte@Sun.COM /* Utility functions */
1587836SJohn.Forte@Sun.COM iSCSINameCheckStatusType iSCSINameStringProfileCheck(wchar_t *name);
1597836SJohn.Forte@Sun.COM boolean_t isNaturalNumber(char *numberStr, uint32_t upperBound);
1607836SJohn.Forte@Sun.COM static int parseAddress(char *address_port_str, uint16_t defaultPort,
1617836SJohn.Forte@Sun.COM     char *address_str, size_t address_str_len,
1627836SJohn.Forte@Sun.COM     uint16_t *port, boolean_t *isIpv6);
1637836SJohn.Forte@Sun.COM int parseTarget(char *targetStr,
1647836SJohn.Forte@Sun.COM     wchar_t *targetNameStr,
1657836SJohn.Forte@Sun.COM     size_t targetNameStrLen,
1667836SJohn.Forte@Sun.COM     boolean_t *targetAddressSpecified,
1677836SJohn.Forte@Sun.COM     wchar_t *targetAddressStr,
1687836SJohn.Forte@Sun.COM     size_t targetAddressStrLen,
1697836SJohn.Forte@Sun.COM     uint16_t *port,
1707836SJohn.Forte@Sun.COM     boolean_t *tpgtSpecified,
1717836SJohn.Forte@Sun.COM     uint16_t *tpgt,
1727836SJohn.Forte@Sun.COM     boolean_t *isIpv6);
17310156SZhang.Yi@Sun.COM static int chkConnLoginMaxPollingLoginDelay(IMA_OID oid,
17410156SZhang.Yi@Sun.COM     int key, int uintValue);
1757836SJohn.Forte@Sun.COM 
1767836SJohn.Forte@Sun.COM /* subcommand functions */
1777836SJohn.Forte@Sun.COM static int addFunc(int, char **, int, cmdOptions_t *, void *, int *);
1787836SJohn.Forte@Sun.COM static int listFunc(int, char **, int, cmdOptions_t *, void *, int *);
1797836SJohn.Forte@Sun.COM static int modifyFunc(int, char **, int, cmdOptions_t *, void *, int *);
1807836SJohn.Forte@Sun.COM static int removeFunc(int, char **, int, cmdOptions_t *, void *, int *);
1817836SJohn.Forte@Sun.COM 
1827836SJohn.Forte@Sun.COM /* helper functions */
1837836SJohn.Forte@Sun.COM static char *getExecBasename(char *);
1847836SJohn.Forte@Sun.COM static int getNodeProps(IMA_NODE_PROPERTIES *);
1857836SJohn.Forte@Sun.COM static int getSecret(char *, int *, int, int);
1867836SJohn.Forte@Sun.COM static int getTargetAddress(int, char *, IMA_TARGET_ADDRESS *);
1877836SJohn.Forte@Sun.COM static int printLoginParameters(char *, IMA_OID, int);
1887836SJohn.Forte@Sun.COM static void printDiscoveryMethod(char *, IMA_UINT32);
1897836SJohn.Forte@Sun.COM static void printTargetLuns(IMA_OID_LIST *);
1907836SJohn.Forte@Sun.COM static void printSendTargets(SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES *);
1917836SJohn.Forte@Sun.COM static void printDigestAlgorithm(SUN_IMA_DIGEST_ALGORITHM_VALUE *, int);
1927836SJohn.Forte@Sun.COM static int setLoginParameter(IMA_OID, int, char *);
1937836SJohn.Forte@Sun.COM static int setLoginParameters(IMA_OID, char *);
19410156SZhang.Yi@Sun.COM static int setTunableParameters(IMA_OID, char *);
1957836SJohn.Forte@Sun.COM static void printLibError(IMA_STATUS);
1967836SJohn.Forte@Sun.COM /* LINTED E_STATIC_UNUSED */
1977836SJohn.Forte@Sun.COM static int sunPluginChk(IMA_OID, boolean_t *);
1987836SJohn.Forte@Sun.COM static int sunInitiatorFind(IMA_OID *);
1997836SJohn.Forte@Sun.COM static int getAuthMethodValue(char *, IMA_AUTHMETHOD *);
2007836SJohn.Forte@Sun.COM static int getLoginParam(char *);
20110156SZhang.Yi@Sun.COM static int getTunableParam(char *);
2027836SJohn.Forte@Sun.COM static void iSCSINameCheckStatusDisplay(iSCSINameCheckStatusType status);
2037836SJohn.Forte@Sun.COM static int modifyIndividualTargetParam(cmdOptions_t *optionList,
2047836SJohn.Forte@Sun.COM     IMA_OID targetOid, int *);
2057836SJohn.Forte@Sun.COM static void listCHAPName(IMA_OID oid);
2067836SJohn.Forte@Sun.COM static int printConfiguredSessions(IMA_OID);
20710156SZhang.Yi@Sun.COM static int printTunableParameters(IMA_OID oid);
2087836SJohn.Forte@Sun.COM 
2097836SJohn.Forte@Sun.COM /* object functions per subcommand */
2107836SJohn.Forte@Sun.COM static int addAddress(int, int, char *[], int *);
2117836SJohn.Forte@Sun.COM static int addStaticConfig(int, char *[], int *);
2127836SJohn.Forte@Sun.COM static int listDiscovery(int *);
2137836SJohn.Forte@Sun.COM static int listDiscoveryAddress(int, char *[], cmdOptions_t *, int *);
2147836SJohn.Forte@Sun.COM static int listISNSServerAddress(int, char *[], cmdOptions_t *, int *);
2157836SJohn.Forte@Sun.COM static int listNode(int *);
2167836SJohn.Forte@Sun.COM static int listStaticConfig(int, char *[], int *);
2177836SJohn.Forte@Sun.COM static int listTarget(int, char *[], cmdOptions_t *, int *);
2187836SJohn.Forte@Sun.COM static int listTargetParam(int, char *[], cmdOptions_t *, int *);
2197836SJohn.Forte@Sun.COM static int modifyDiscovery(cmdOptions_t *, int *);
2207836SJohn.Forte@Sun.COM static int modifyNodeAuthMethod(IMA_OID, char *, int *);
2217836SJohn.Forte@Sun.COM static int modifyNodeAuthParam(IMA_OID oid, int, char *, int *);
2227836SJohn.Forte@Sun.COM static int modifyNodeRadiusConfig(IMA_OID, char *, int *);
2237836SJohn.Forte@Sun.COM static int modifyNodeRadiusAccess(IMA_OID, char *, int *);
2247836SJohn.Forte@Sun.COM static int modifyNodeRadiusSharedSecret(IMA_OID, int *);
2257836SJohn.Forte@Sun.COM static int modifyNode(cmdOptions_t *, int *);
2267836SJohn.Forte@Sun.COM static int modifyTargetAuthMethod(IMA_OID, char *, int *);
2277836SJohn.Forte@Sun.COM static int modifyTargetAuthParam(IMA_OID oid, int param, char *chapName, int *);
2287836SJohn.Forte@Sun.COM static int modifyTargetParam(cmdOptions_t *, char *, int *);
2297836SJohn.Forte@Sun.COM static int removeAddress(int, int, char *[], int *);
2307836SJohn.Forte@Sun.COM static int removeStaticConfig(int, char *[], int *);
2317836SJohn.Forte@Sun.COM static int removeTargetParam(int, char *[], int *);
2327836SJohn.Forte@Sun.COM static int modifyTargetBidirAuthFlag(IMA_OID, char *, int *);
2337836SJohn.Forte@Sun.COM static int modifyConfiguredSessions(IMA_OID targetOid, char *optarg);
2347836SJohn.Forte@Sun.COM 
2357836SJohn.Forte@Sun.COM /* LINTED E_STATIC_UNUSED */
2367836SJohn.Forte@Sun.COM static IMA_STATUS getISCSINodeParameter(int paramType,
2377836SJohn.Forte@Sun.COM     IMA_OID *oid,
2387836SJohn.Forte@Sun.COM     void *pProps,
2397836SJohn.Forte@Sun.COM     uint32_t paramIndex);
2407836SJohn.Forte@Sun.COM /* LINTED E_STATIC_UNUSED */
2417836SJohn.Forte@Sun.COM static IMA_STATUS setISCSINodeParameter(int paramType,
2427836SJohn.Forte@Sun.COM     IMA_OID *oid,
2437836SJohn.Forte@Sun.COM     void *pProps,
2447836SJohn.Forte@Sun.COM     uint32_t paramIndex);
2457836SJohn.Forte@Sun.COM /* LINTED E_STATIC_UNUSED */
2467836SJohn.Forte@Sun.COM static IMA_STATUS getDigest(IMA_OID oid, int ioctlCmd,
2477836SJohn.Forte@Sun.COM     SUN_IMA_DIGEST_ALGORITHM_VALUE *algorithm);
2487836SJohn.Forte@Sun.COM 
2497836SJohn.Forte@Sun.COM IMA_STATUS getNegotiatedDigest(int digestType,
2507836SJohn.Forte@Sun.COM 	SUN_IMA_DIGEST_ALGORITHM_VALUE *algorithm,
2517836SJohn.Forte@Sun.COM 	SUN_IMA_CONN_PROPERTIES *connProps);
2527836SJohn.Forte@Sun.COM 
2537836SJohn.Forte@Sun.COM /* globals */
2547836SJohn.Forte@Sun.COM static char *cmdName;
2557836SJohn.Forte@Sun.COM 
2567836SJohn.Forte@Sun.COM /*
2577836SJohn.Forte@Sun.COM  * Available option letters:
2587836SJohn.Forte@Sun.COM  *
25912161SJack.Meng@Sun.COM  * befgijklmnoquwxyz
2607836SJohn.Forte@Sun.COM  *
26110156SZhang.Yi@Sun.COM  * DEFGHIJKLMOQUVWXYZ
2627836SJohn.Forte@Sun.COM  */
2637836SJohn.Forte@Sun.COM 
2647836SJohn.Forte@Sun.COM /*
2657836SJohn.Forte@Sun.COM  * Add new options here
2667836SJohn.Forte@Sun.COM  */
2677836SJohn.Forte@Sun.COM optionTbl_t longOptions[] = {
2687836SJohn.Forte@Sun.COM 	{"static", required_arg, 's', OPTIONSTRING4},
2697836SJohn.Forte@Sun.COM 	{"sendtargets", required_arg, 't', OPTIONSTRING4},
2707836SJohn.Forte@Sun.COM 	{"iSNS", required_arg, 'i', OPTIONSTRING4},
2717836SJohn.Forte@Sun.COM 	{"headerdigest", required_arg, 'h', OPTIONSTRING6},
2727836SJohn.Forte@Sun.COM 	{"datadigest", required_arg, 'd', OPTIONSTRING6},
2737836SJohn.Forte@Sun.COM 	{"login-param", required_arg, 'p', OPTIONSTRING5},
2747836SJohn.Forte@Sun.COM 	{"authentication", required_arg, 'a', "CHAP|none"},
2757836SJohn.Forte@Sun.COM 	{"bi-directional-authentication", required_arg, 'B', OPTIONSTRING4},
2767836SJohn.Forte@Sun.COM 	{"CHAP-secret", no_arg, 'C', NULL},
2777836SJohn.Forte@Sun.COM 	{"CHAP-name", required_arg, 'H', OPTIONSTRING7},
2787836SJohn.Forte@Sun.COM 	{"node-name", required_arg, 'N', OPTIONSTRING2},
2797836SJohn.Forte@Sun.COM 	{"node-alias", required_arg, 'A', OPTIONSTRING3},
2807836SJohn.Forte@Sun.COM 	{"radius-server", required_arg, 'r', OPTIONVAL4},
2817836SJohn.Forte@Sun.COM 	{"radius-access", required_arg, 'R', OPTIONSTRING4},
2827836SJohn.Forte@Sun.COM 	{"radius-shared-secret", no_arg, 'P', NULL},
2837836SJohn.Forte@Sun.COM 	{"verbose", no_arg, 'v', NULL},
2847836SJohn.Forte@Sun.COM 	{"scsi-target", no_arg, 'S', NULL},
2857836SJohn.Forte@Sun.COM 	{"configured-sessions", required_arg, 'c', OPTIONSTRING8},
28610156SZhang.Yi@Sun.COM 	{"tunable-param", required_arg, 'T', OPTIONSTRING9},
2877836SJohn.Forte@Sun.COM 	{NULL, 0, 0, 0}
2887836SJohn.Forte@Sun.COM };
2897836SJohn.Forte@Sun.COM 
2907836SJohn.Forte@Sun.COM parameterTbl_t loginParams[] = {
2917836SJohn.Forte@Sun.COM 	{"dataseqinorder", DATA_SEQ_IN_ORDER},
2927836SJohn.Forte@Sun.COM 	{"defaulttime2retain", DEFAULT_TIME_2_RETAIN},
2937836SJohn.Forte@Sun.COM 	{"defaulttime2wait", DEFAULT_TIME_2_WAIT},
2947836SJohn.Forte@Sun.COM 	{"firstburstlength", FIRST_BURST_LENGTH},
2957836SJohn.Forte@Sun.COM 	{"immediatedata", IMMEDIATE_DATA},
2967836SJohn.Forte@Sun.COM 	{"initialr2t", INITIAL_R2T},
2977836SJohn.Forte@Sun.COM 	{"maxburstlength", MAX_BURST_LENGTH},
2987836SJohn.Forte@Sun.COM 	{"datapduinorder", DATA_PDU_IN_ORDER},
2997836SJohn.Forte@Sun.COM 	{"maxoutstandingr2t", MAX_OUTSTANDING_R2T},
3007836SJohn.Forte@Sun.COM 	{"maxrecvdataseglen", MAX_RECV_DATA_SEG_LEN},
3017836SJohn.Forte@Sun.COM 	{"maxconnections", MAX_CONNECTIONS},
3027836SJohn.Forte@Sun.COM 	{"errorrecoverylevel", ERROR_RECOVERY_LEVEL},
3037836SJohn.Forte@Sun.COM 	{NULL, 0}
3047836SJohn.Forte@Sun.COM };
3057836SJohn.Forte@Sun.COM 
30610156SZhang.Yi@Sun.COM parameterTbl_t tunableParams[] = {
30710156SZhang.Yi@Sun.COM 	{"recv-login-rsp-timeout", RECV_LOGIN_RSP_TIMEOUT},
30810156SZhang.Yi@Sun.COM 	{"conn-login-max", CONN_LOGIN_MAX},
30910156SZhang.Yi@Sun.COM 	{"polling-login-delay", POLLING_LOGIN_DELAY},
31010156SZhang.Yi@Sun.COM 	{NULL, 0}
31110156SZhang.Yi@Sun.COM };
31210156SZhang.Yi@Sun.COM 
3137836SJohn.Forte@Sun.COM /*
3147836SJohn.Forte@Sun.COM  * Add new subcommands here
3157836SJohn.Forte@Sun.COM  */
3167836SJohn.Forte@Sun.COM subcommand_t subcommands[] = {
3177836SJohn.Forte@Sun.COM 	{"add", ADD, addFunc},
3187836SJohn.Forte@Sun.COM 	{"list", LIST, listFunc},
3197836SJohn.Forte@Sun.COM 	{"modify", MODIFY, modifyFunc},
3207836SJohn.Forte@Sun.COM 	{"remove", REMOVE, removeFunc},
3217836SJohn.Forte@Sun.COM 	{NULL, 0, NULL}
3227836SJohn.Forte@Sun.COM };
3237836SJohn.Forte@Sun.COM 
3247836SJohn.Forte@Sun.COM /*
3257836SJohn.Forte@Sun.COM  * Add objects here
3267836SJohn.Forte@Sun.COM  */
3277836SJohn.Forte@Sun.COM object_t objects[] = {
3287836SJohn.Forte@Sun.COM 	{"discovery", DISCOVERY},
3297836SJohn.Forte@Sun.COM 	{"discovery-address", DISCOVERY_ADDRESS},
3307836SJohn.Forte@Sun.COM 	{"isns-server", ISNS_SERVER_ADDRESS},
3317836SJohn.Forte@Sun.COM 	{"initiator-node", NODE},
3327836SJohn.Forte@Sun.COM 	{"static-config", STATIC_CONFIG},
3337836SJohn.Forte@Sun.COM 	{"target", TARGET},
3347836SJohn.Forte@Sun.COM 	{"target-param", TARGET_PARAM},
3357836SJohn.Forte@Sun.COM 	{NULL, 0}
3367836SJohn.Forte@Sun.COM };
3377836SJohn.Forte@Sun.COM 
3387836SJohn.Forte@Sun.COM /*
3397836SJohn.Forte@Sun.COM  * Rules for subcommands and objects
3407836SJohn.Forte@Sun.COM  */
3417836SJohn.Forte@Sun.COM objectRules_t objectRules[] = {
3427836SJohn.Forte@Sun.COM 	{TARGET, 0, LIST, 0, ADD|REMOVE|MODIFY, LIST,
3437836SJohn.Forte@Sun.COM 	"target-name"},
3447836SJohn.Forte@Sun.COM 	{TARGET_PARAM, MODIFY|REMOVE, LIST, 0, ADD, MODIFY,
3457836SJohn.Forte@Sun.COM 	"target-name"},
3467836SJohn.Forte@Sun.COM 	{DISCOVERY, 0, 0, LIST|MODIFY, ADD|REMOVE, 0, NULL},
3477836SJohn.Forte@Sun.COM 	{NODE, 0, 0, MODIFY|LIST, ADD|REMOVE, 0, NULL},
3487836SJohn.Forte@Sun.COM 	{STATIC_CONFIG, ADD|REMOVE, LIST, 0, MODIFY, ADD|REMOVE|LIST,
3497836SJohn.Forte@Sun.COM 	"target-name,target-address[:port-number][,tpgt]"},
3507836SJohn.Forte@Sun.COM 	{DISCOVERY_ADDRESS, ADD|REMOVE, LIST, 0, MODIFY,
3517836SJohn.Forte@Sun.COM 	ADD|REMOVE|LIST, "IP-address[:port-number]"},
3527836SJohn.Forte@Sun.COM 	{ISNS_SERVER_ADDRESS, ADD|REMOVE, LIST, 0, MODIFY,
3537836SJohn.Forte@Sun.COM 	ADD|REMOVE|LIST, "IP-address[:port-number]"},
3547836SJohn.Forte@Sun.COM 	{0, 0, 0, 0, 0, NULL}
3557836SJohn.Forte@Sun.COM };
3567836SJohn.Forte@Sun.COM 
3577836SJohn.Forte@Sun.COM /*
3587836SJohn.Forte@Sun.COM  * list of objects, subcommands, valid short options, required flag and
3597836SJohn.Forte@Sun.COM  * exclusive option string
3607836SJohn.Forte@Sun.COM  *
3617836SJohn.Forte@Sun.COM  * If it's not here, there are no options for that object.
3627836SJohn.Forte@Sun.COM  */
3637836SJohn.Forte@Sun.COM optionRules_t optionRules[] = {
3647836SJohn.Forte@Sun.COM 	{DISCOVERY, MODIFY, "sti", B_TRUE, NULL},
3657836SJohn.Forte@Sun.COM 	{DISCOVERY_ADDRESS, LIST, "v", B_FALSE, NULL},
3667836SJohn.Forte@Sun.COM 	{ISNS_SERVER_ADDRESS, LIST, "v", B_FALSE, NULL},
3677836SJohn.Forte@Sun.COM 	{TARGET, LIST, "vS", B_FALSE, NULL},
36810156SZhang.Yi@Sun.COM 	{NODE, MODIFY, "NAhdCaRrPHcT", B_TRUE, "CP"},
36910156SZhang.Yi@Sun.COM 	{TARGET_PARAM, MODIFY, "ahdBCpcHT", B_TRUE, "C"},
3707836SJohn.Forte@Sun.COM 	{TARGET_PARAM, LIST, "v", B_FALSE, NULL},
3717836SJohn.Forte@Sun.COM 	{0, 0, 0, 0, 0}
3727836SJohn.Forte@Sun.COM };
3737836SJohn.Forte@Sun.COM 
3747836SJohn.Forte@Sun.COM 
3757836SJohn.Forte@Sun.COM static boolean_t
targetNamesEqual(wchar_t * name1,wchar_t * name2)3767836SJohn.Forte@Sun.COM targetNamesEqual(wchar_t *name1, wchar_t *name2)
3777836SJohn.Forte@Sun.COM {
3787836SJohn.Forte@Sun.COM 	int i;
3797836SJohn.Forte@Sun.COM 	wchar_t wchar1, wchar2;
3807836SJohn.Forte@Sun.COM 
3817836SJohn.Forte@Sun.COM 	if (name1 == NULL || name2 == NULL) {
3827836SJohn.Forte@Sun.COM 		return (B_FALSE);
3837836SJohn.Forte@Sun.COM 	}
3847836SJohn.Forte@Sun.COM 
3857836SJohn.Forte@Sun.COM 	if (wcslen(name1) != wcslen(name2)) {
3867836SJohn.Forte@Sun.COM 		return (B_FALSE);
3877836SJohn.Forte@Sun.COM 	}
3887836SJohn.Forte@Sun.COM 
3897836SJohn.Forte@Sun.COM 	/*
3907836SJohn.Forte@Sun.COM 	 * Convert names to lower case and compare
3917836SJohn.Forte@Sun.COM 	 */
3927836SJohn.Forte@Sun.COM 	for (i = 0; i < wcslen(name1); i++) {
3937836SJohn.Forte@Sun.COM 		wchar1 = towctrans((wint_t)name1[i], wctrans("tolower"));
3947836SJohn.Forte@Sun.COM 		wchar2 = towctrans((wint_t)name2[i], wctrans("tolower"));
3957836SJohn.Forte@Sun.COM 
3967836SJohn.Forte@Sun.COM 		if (wchar1 != wchar2) {
3977836SJohn.Forte@Sun.COM 			return (B_FALSE);
3987836SJohn.Forte@Sun.COM 		}
3997836SJohn.Forte@Sun.COM 	}
4007836SJohn.Forte@Sun.COM 
4017836SJohn.Forte@Sun.COM 	return (B_TRUE);
4027836SJohn.Forte@Sun.COM }
4037836SJohn.Forte@Sun.COM 
4047836SJohn.Forte@Sun.COM static boolean_t
ipAddressesEqual(IMA_TARGET_ADDRESS addr1,IMA_TARGET_ADDRESS addr2)4057836SJohn.Forte@Sun.COM ipAddressesEqual(IMA_TARGET_ADDRESS addr1, IMA_TARGET_ADDRESS addr2)
4067836SJohn.Forte@Sun.COM {
4077836SJohn.Forte@Sun.COM #define	IPV4_ADDR_BYTES 4
4087836SJohn.Forte@Sun.COM #define	IPV6_ADDR_BYTES 16
4097836SJohn.Forte@Sun.COM 
4107836SJohn.Forte@Sun.COM 	int compSize;
4117836SJohn.Forte@Sun.COM 
4127836SJohn.Forte@Sun.COM 	if (addr1.hostnameIpAddress.id.ipAddress.ipv4Address !=
4137836SJohn.Forte@Sun.COM 	    addr2.hostnameIpAddress.id.ipAddress.ipv4Address) {
4147836SJohn.Forte@Sun.COM 		return (B_FALSE);
4157836SJohn.Forte@Sun.COM 	}
4167836SJohn.Forte@Sun.COM 
4177836SJohn.Forte@Sun.COM 	compSize = IPV6_ADDR_BYTES;
4187836SJohn.Forte@Sun.COM 	if (addr1.hostnameIpAddress.id.ipAddress.ipv4Address) {
4197836SJohn.Forte@Sun.COM 		compSize = IPV4_ADDR_BYTES;
4207836SJohn.Forte@Sun.COM 	}
4217836SJohn.Forte@Sun.COM 
4227836SJohn.Forte@Sun.COM 	if (bcmp(addr1.hostnameIpAddress.id.ipAddress.ipAddress,
4237836SJohn.Forte@Sun.COM 	    addr2.hostnameIpAddress.id.ipAddress.ipAddress, compSize) == 0) {
4247836SJohn.Forte@Sun.COM 		return (B_TRUE);
4257836SJohn.Forte@Sun.COM 	}
4267836SJohn.Forte@Sun.COM 
4277836SJohn.Forte@Sun.COM 	return (B_FALSE);
4287836SJohn.Forte@Sun.COM }
4297836SJohn.Forte@Sun.COM 
4307836SJohn.Forte@Sun.COM static int
getLoginParam(char * arg)4317836SJohn.Forte@Sun.COM getLoginParam(char *arg)
4327836SJohn.Forte@Sun.COM {
4337836SJohn.Forte@Sun.COM 	parameterTbl_t *paramp;
4347836SJohn.Forte@Sun.COM 	int len;
4357836SJohn.Forte@Sun.COM 
4367836SJohn.Forte@Sun.COM 	for (paramp = loginParams; paramp->name; paramp++) {
4377836SJohn.Forte@Sun.COM 		len = strlen(arg);
4387836SJohn.Forte@Sun.COM 		if (len == strlen(paramp->name) &&
4397836SJohn.Forte@Sun.COM 		    strncasecmp(arg, paramp->name, len) == 0) {
4407836SJohn.Forte@Sun.COM 			return (paramp->val);
4417836SJohn.Forte@Sun.COM 		}
4427836SJohn.Forte@Sun.COM 	}
4437836SJohn.Forte@Sun.COM 	return (-1);
4447836SJohn.Forte@Sun.COM }
4457836SJohn.Forte@Sun.COM 
44610156SZhang.Yi@Sun.COM static int
getTunableParam(char * arg)44710156SZhang.Yi@Sun.COM getTunableParam(char *arg)
44810156SZhang.Yi@Sun.COM {
44910156SZhang.Yi@Sun.COM 	parameterTbl_t *paramp;
45010156SZhang.Yi@Sun.COM 	int len;
45110156SZhang.Yi@Sun.COM 
45210156SZhang.Yi@Sun.COM 	for (paramp = tunableParams; paramp->name != NULL; paramp++) {
45310156SZhang.Yi@Sun.COM 		len = strlen(arg);
45410156SZhang.Yi@Sun.COM 		if (len == strlen(paramp->name) &&
45510156SZhang.Yi@Sun.COM 		    strncasecmp(arg, paramp->name, len) == 0) {
45610156SZhang.Yi@Sun.COM 			return (paramp->val);
45710156SZhang.Yi@Sun.COM 		}
45810156SZhang.Yi@Sun.COM 	}
45910156SZhang.Yi@Sun.COM 	return (-1);
46010156SZhang.Yi@Sun.COM }
46110156SZhang.Yi@Sun.COM 
4627836SJohn.Forte@Sun.COM static void
printLibError(IMA_STATUS status)4637836SJohn.Forte@Sun.COM printLibError(IMA_STATUS status)
4647836SJohn.Forte@Sun.COM {
4657836SJohn.Forte@Sun.COM 	char *errorString;
4667836SJohn.Forte@Sun.COM 	switch (status) {
4677836SJohn.Forte@Sun.COM 	case IMA_ERROR_NOT_SUPPORTED:
4687836SJohn.Forte@Sun.COM 		errorString =
4697836SJohn.Forte@Sun.COM 		gettext("Operation currently not supported");
4707836SJohn.Forte@Sun.COM 		break;
4717836SJohn.Forte@Sun.COM 	case IMA_ERROR_INSUFFICIENT_MEMORY:
4727836SJohn.Forte@Sun.COM 		errorString = gettext("Insufficient memory");
4737836SJohn.Forte@Sun.COM 		break;
4747836SJohn.Forte@Sun.COM 	case IMA_ERROR_UNEXPECTED_OS_ERROR:
4757836SJohn.Forte@Sun.COM 		errorString = gettext("unexpected OS error");
4767836SJohn.Forte@Sun.COM 		break;
4777836SJohn.Forte@Sun.COM 	case IMA_ERROR_UNKNOWN_ERROR:
4787836SJohn.Forte@Sun.COM 		errorString = gettext("Unknown error");
4797836SJohn.Forte@Sun.COM 		break;
4807836SJohn.Forte@Sun.COM 	case IMA_ERROR_LU_IN_USE:
4817836SJohn.Forte@Sun.COM 		errorString = gettext("Logical unit in use");
4827836SJohn.Forte@Sun.COM 		break;
4837836SJohn.Forte@Sun.COM 	case IMA_ERROR_INVALID_PARAMETER:
4847836SJohn.Forte@Sun.COM 		errorString = gettext("Invalid parameter specified");
4857836SJohn.Forte@Sun.COM 		break;
4867836SJohn.Forte@Sun.COM 	case IMA_ERROR_INVALID_OBJECT_TYPE:
4877836SJohn.Forte@Sun.COM 		errorString =
4887836SJohn.Forte@Sun.COM 		gettext("Internal library error: Invalid oid type specified");
4897836SJohn.Forte@Sun.COM 		break;
4907836SJohn.Forte@Sun.COM 	case IMA_ERROR_INCORRECT_OBJECT_TYPE:
4917836SJohn.Forte@Sun.COM 		errorString =
4927836SJohn.Forte@Sun.COM 		gettext("Internal library error: Incorrect oid type specified");
4937836SJohn.Forte@Sun.COM 		break;
4947836SJohn.Forte@Sun.COM 	case IMA_ERROR_OBJECT_NOT_FOUND:
4957836SJohn.Forte@Sun.COM 		errorString = gettext("Internal library error: Oid not found");
4967836SJohn.Forte@Sun.COM 		break;
4977836SJohn.Forte@Sun.COM 	case IMA_ERROR_NAME_TOO_LONG:
4987836SJohn.Forte@Sun.COM 		errorString = gettext("Name too long");
4997836SJohn.Forte@Sun.COM 		break;
5007836SJohn.Forte@Sun.COM 	default:
5017836SJohn.Forte@Sun.COM 		errorString = gettext("Unknown error");
5027836SJohn.Forte@Sun.COM 	}
5037836SJohn.Forte@Sun.COM 	(void) fprintf(stderr, "%s: %s\n", cmdName, errorString);
5047836SJohn.Forte@Sun.COM }
5057836SJohn.Forte@Sun.COM 
5067836SJohn.Forte@Sun.COM /*
5077836SJohn.Forte@Sun.COM  * input:
5087836SJohn.Forte@Sun.COM  *  execFullName - exec name of program (argv[0])
5097836SJohn.Forte@Sun.COM  *
5107836SJohn.Forte@Sun.COM  * Returns:
5117836SJohn.Forte@Sun.COM  *  command name portion of execFullName
5127836SJohn.Forte@Sun.COM  */
5137836SJohn.Forte@Sun.COM static char *
getExecBasename(char * execFullname)5147836SJohn.Forte@Sun.COM getExecBasename(char *execFullname)
5157836SJohn.Forte@Sun.COM {
5167836SJohn.Forte@Sun.COM 	char *lastSlash, *execBasename;
5177836SJohn.Forte@Sun.COM 
5187836SJohn.Forte@Sun.COM 	/* guard against '/' at end of command invocation */
5197836SJohn.Forte@Sun.COM 	for (;;) {
5207836SJohn.Forte@Sun.COM 		lastSlash = strrchr(execFullname, '/');
5217836SJohn.Forte@Sun.COM 		if (lastSlash == NULL) {
5227836SJohn.Forte@Sun.COM 			execBasename = execFullname;
5237836SJohn.Forte@Sun.COM 			break;
5247836SJohn.Forte@Sun.COM 		} else {
5257836SJohn.Forte@Sun.COM 			execBasename = lastSlash + 1;
5267836SJohn.Forte@Sun.COM 			if (*execBasename == '\0') {
5277836SJohn.Forte@Sun.COM 				*lastSlash = '\0';
5287836SJohn.Forte@Sun.COM 				continue;
5297836SJohn.Forte@Sun.COM 			}
5307836SJohn.Forte@Sun.COM 			break;
5317836SJohn.Forte@Sun.COM 		}
5327836SJohn.Forte@Sun.COM 	}
5337836SJohn.Forte@Sun.COM 	return (execBasename);
5347836SJohn.Forte@Sun.COM }
5357836SJohn.Forte@Sun.COM 
5367836SJohn.Forte@Sun.COM 
5377836SJohn.Forte@Sun.COM /*
5387836SJohn.Forte@Sun.COM  * input:
5397836SJohn.Forte@Sun.COM  *  nodeProps - pointer to caller allocated IMA_NODE_PROPERTIES
5407836SJohn.Forte@Sun.COM  *
5417836SJohn.Forte@Sun.COM  * returns:
5427836SJohn.Forte@Sun.COM  *  zero on success
5437836SJohn.Forte@Sun.COM  *  non-zero otherwise
5447836SJohn.Forte@Sun.COM  */
5457836SJohn.Forte@Sun.COM static int
getNodeProps(IMA_NODE_PROPERTIES * nodeProps)5467836SJohn.Forte@Sun.COM getNodeProps(IMA_NODE_PROPERTIES *nodeProps)
5477836SJohn.Forte@Sun.COM {
5487836SJohn.Forte@Sun.COM 	IMA_OID sharedNodeOid;
5497836SJohn.Forte@Sun.COM 
5507836SJohn.Forte@Sun.COM 	IMA_STATUS status = IMA_GetSharedNodeOid(&sharedNodeOid);
5517836SJohn.Forte@Sun.COM 	if (!(IMA_SUCCESS(status))) {
5527836SJohn.Forte@Sun.COM 		printLibError(status);
5537836SJohn.Forte@Sun.COM 		return (INF_ERROR);
5547836SJohn.Forte@Sun.COM 	}
5557836SJohn.Forte@Sun.COM 
5567836SJohn.Forte@Sun.COM 	status = IMA_GetNodeProperties(sharedNodeOid, nodeProps);
5577836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
5587836SJohn.Forte@Sun.COM 		printLibError(status);
5597836SJohn.Forte@Sun.COM 		return (INF_ERROR);
5607836SJohn.Forte@Sun.COM 	}
5617836SJohn.Forte@Sun.COM 
5627836SJohn.Forte@Sun.COM 	return (0);
5637836SJohn.Forte@Sun.COM }
5647836SJohn.Forte@Sun.COM 
5657836SJohn.Forte@Sun.COM /*
5667836SJohn.Forte@Sun.COM  * sunInitiatorFind
5677836SJohn.Forte@Sun.COM  * Purpose:
5687836SJohn.Forte@Sun.COM  *  Finds the Sun iSCSI initiator (LHBA). This CLI currently supports only
5697836SJohn.Forte@Sun.COM  *  one initiator.
5707836SJohn.Forte@Sun.COM  *
5717836SJohn.Forte@Sun.COM  * output:
5727836SJohn.Forte@Sun.COM  *  oid of initiator
5737836SJohn.Forte@Sun.COM  *
5747836SJohn.Forte@Sun.COM  * Returns:
5757836SJohn.Forte@Sun.COM  *  zero on success with initiator found
5767836SJohn.Forte@Sun.COM  *  > 0 on success with no initiator found
5777836SJohn.Forte@Sun.COM  *  < 0 on failure
5787836SJohn.Forte@Sun.COM  */
5797836SJohn.Forte@Sun.COM static int
sunInitiatorFind(IMA_OID * oid)5807836SJohn.Forte@Sun.COM sunInitiatorFind(IMA_OID *oid)
5817836SJohn.Forte@Sun.COM {
5828389SJack.Meng@Sun.COM 	IMA_OID_LIST *lhbaList = NULL;
5837836SJohn.Forte@Sun.COM 
5847836SJohn.Forte@Sun.COM 	IMA_STATUS status = IMA_GetLhbaOidList(&lhbaList);
5857836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
5867836SJohn.Forte@Sun.COM 		printLibError(status);
5877836SJohn.Forte@Sun.COM 		return (-1);
5887836SJohn.Forte@Sun.COM 	}
5897836SJohn.Forte@Sun.COM 
5908389SJack.Meng@Sun.COM 	if ((lhbaList == NULL) || (lhbaList->oidCount == 0)) {
5918389SJack.Meng@Sun.COM 		printLibError(IMA_ERROR_OBJECT_NOT_FOUND);
5928389SJack.Meng@Sun.COM 		if (lhbaList != NULL)
5938389SJack.Meng@Sun.COM 			(void) IMA_FreeMemory(lhbaList);
5948389SJack.Meng@Sun.COM 		return (-1);
5958389SJack.Meng@Sun.COM 	}
5968389SJack.Meng@Sun.COM 
5977836SJohn.Forte@Sun.COM 	*oid = lhbaList->oids[0];
5988389SJack.Meng@Sun.COM 	(void) IMA_FreeMemory(lhbaList);
5997836SJohn.Forte@Sun.COM 
6007836SJohn.Forte@Sun.COM 	return (0);
6017836SJohn.Forte@Sun.COM }
6027836SJohn.Forte@Sun.COM 
6037836SJohn.Forte@Sun.COM /*
6047836SJohn.Forte@Sun.COM  * input:
6057836SJohn.Forte@Sun.COM  *  wcInput - wide character string containing discovery address
6067836SJohn.Forte@Sun.COM  * output:
6077836SJohn.Forte@Sun.COM  *  address - IMA_TARGET_ADDRESS structure containing valid
6087836SJohn.Forte@Sun.COM  *	discovery address
6097836SJohn.Forte@Sun.COM  * returns:
6107836SJohn.Forte@Sun.COM  *  zero on success
6117836SJohn.Forte@Sun.COM  *  non-zero on failure
6127836SJohn.Forte@Sun.COM  */
6137836SJohn.Forte@Sun.COM 
6147836SJohn.Forte@Sun.COM static int
getTargetAddress(int addrType,char * ipStr,IMA_TARGET_ADDRESS * address)6157836SJohn.Forte@Sun.COM getTargetAddress(int addrType, char *ipStr, IMA_TARGET_ADDRESS *address)
6167836SJohn.Forte@Sun.COM {
6177836SJohn.Forte@Sun.COM 	char cCol = ':';
6187836SJohn.Forte@Sun.COM 	char cBracketL = '['; /* Open Bracket '[' */
6197836SJohn.Forte@Sun.COM 	char cBracketR = ']'; /* Close Bracket ']' */
6207836SJohn.Forte@Sun.COM 	char *colPos;
6217836SJohn.Forte@Sun.COM 	char *startPos;
6227836SJohn.Forte@Sun.COM 	unsigned long inputPort;
6237836SJohn.Forte@Sun.COM 	int addressType = AF_INET;
6247836SJohn.Forte@Sun.COM 	char *tmpStrPtr, tmpStr[SUN_IMA_IP_ADDRESS_PORT_LEN];
6257836SJohn.Forte@Sun.COM 	int rval;
6267836SJohn.Forte@Sun.COM 
6277836SJohn.Forte@Sun.COM 	/* Check if this is a ipv6 address */
6287836SJohn.Forte@Sun.COM 	if (ipStr[0] == cBracketL) {
6297836SJohn.Forte@Sun.COM 		addressType = AF_INET6;
6307836SJohn.Forte@Sun.COM 		startPos = strchr(ipStr, cBracketR);
6317836SJohn.Forte@Sun.COM 		if (!startPos) {
6327836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s: ']' %s\n",
6337836SJohn.Forte@Sun.COM 			    cmdName, ipStr, gettext("missing"));
6347836SJohn.Forte@Sun.COM 			return (1);
6357836SJohn.Forte@Sun.COM 		}
6367836SJohn.Forte@Sun.COM 		(void) strlcpy(tmpStr, ipStr+1, startPos-ipStr);
6377836SJohn.Forte@Sun.COM 		address->hostnameIpAddress.id.ipAddress.ipv4Address = IMA_FALSE;
6387836SJohn.Forte@Sun.COM 		tmpStrPtr = tmpStr;
6397836SJohn.Forte@Sun.COM 	} else {
6407836SJohn.Forte@Sun.COM 		/* set start position to beginning of input object */
6417836SJohn.Forte@Sun.COM 		addressType = AF_INET;
6427836SJohn.Forte@Sun.COM 		startPos = ipStr;
6437836SJohn.Forte@Sun.COM 		address->hostnameIpAddress.id.ipAddress.ipv4Address = IMA_TRUE;
6447836SJohn.Forte@Sun.COM 		tmpStrPtr = ipStr;
6457836SJohn.Forte@Sun.COM 	}
6467836SJohn.Forte@Sun.COM 	/* wcschr for ':'. If not there, use default port */
6477836SJohn.Forte@Sun.COM 	colPos = strchr(startPos, cCol);
6487836SJohn.Forte@Sun.COM 
6497836SJohn.Forte@Sun.COM 	if (!colPos) {
6507836SJohn.Forte@Sun.COM 		if (addrType == DISCOVERY_ADDRESS) {
6517836SJohn.Forte@Sun.COM 			inputPort = DEFAULT_ISCSI_PORT;
6527836SJohn.Forte@Sun.COM 		} else if (addrType == ISNS_SERVER_ADDRESS) {
6537836SJohn.Forte@Sun.COM 			inputPort = ISNS_DEFAULT_SERVER_PORT;
6547836SJohn.Forte@Sun.COM 		} else {
6557836SJohn.Forte@Sun.COM 			*colPos = NULL;
6567836SJohn.Forte@Sun.COM 		}
6577836SJohn.Forte@Sun.COM 	} else {
6587836SJohn.Forte@Sun.COM 		*colPos = NULL;
6597836SJohn.Forte@Sun.COM 	}
6607836SJohn.Forte@Sun.COM 
6617836SJohn.Forte@Sun.COM 	rval = inet_pton(addressType, tmpStrPtr,
6627836SJohn.Forte@Sun.COM 	    address->hostnameIpAddress.id.ipAddress.ipAddress);
6637836SJohn.Forte@Sun.COM 	/* inet_pton returns 1 on success */
6647836SJohn.Forte@Sun.COM 	if (rval != 1) {
6657836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s: %s\n", cmdName, ipStr,
6667836SJohn.Forte@Sun.COM 		    gettext("invalid IP address"));
6677836SJohn.Forte@Sun.COM 		return (1);
6687836SJohn.Forte@Sun.COM 	}
6697836SJohn.Forte@Sun.COM 
6707836SJohn.Forte@Sun.COM 
6717836SJohn.Forte@Sun.COM 	if (colPos) {
6727836SJohn.Forte@Sun.COM 		char *errchr;
6737836SJohn.Forte@Sun.COM 
6747836SJohn.Forte@Sun.COM 		colPos++;
6757836SJohn.Forte@Sun.COM 		if (*colPos == NULL) {
6767836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s: %s\n",
6777836SJohn.Forte@Sun.COM 			    cmdName, ipStr,
6787836SJohn.Forte@Sun.COM 			    gettext("port number missing"));
6797836SJohn.Forte@Sun.COM 			return (1);
6807836SJohn.Forte@Sun.COM 		}
6817836SJohn.Forte@Sun.COM 
6827836SJohn.Forte@Sun.COM 		/*
6837836SJohn.Forte@Sun.COM 		 * convert port string to unsigned value
6847836SJohn.Forte@Sun.COM 		 * Note:  Don't remove errno = 0 as you may get false failures.
6857836SJohn.Forte@Sun.COM 		 */
6867836SJohn.Forte@Sun.COM 		errno = 0;
6877836SJohn.Forte@Sun.COM 		inputPort = strtol(colPos, &errchr, 10);
6887836SJohn.Forte@Sun.COM 		if (errno != 0 || inputPort == 0 && errchr != NULL) {
6897836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s:%s %s\n",
6907836SJohn.Forte@Sun.COM 			    cmdName, ipStr, colPos,
6917836SJohn.Forte@Sun.COM 			    gettext("port number invalid"));
6927836SJohn.Forte@Sun.COM 			return (1);
6937836SJohn.Forte@Sun.COM 		}
6947836SJohn.Forte@Sun.COM 		/* make sure it's in the range */
6957836SJohn.Forte@Sun.COM 		if (inputPort > USHRT_MAX) {
6967836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s: %s\n",
6977836SJohn.Forte@Sun.COM 			    cmdName, ipStr,
6987836SJohn.Forte@Sun.COM 			    gettext("port number out of range"));
6997836SJohn.Forte@Sun.COM 			return (1);
7007836SJohn.Forte@Sun.COM 		}
7017836SJohn.Forte@Sun.COM 	}
7027836SJohn.Forte@Sun.COM 	address->portNumber  = inputPort;
7037836SJohn.Forte@Sun.COM 
7047836SJohn.Forte@Sun.COM 	return (0);
7057836SJohn.Forte@Sun.COM }
7067836SJohn.Forte@Sun.COM 
7077836SJohn.Forte@Sun.COM /*
7087836SJohn.Forte@Sun.COM  * Print results of send targets command
7097836SJohn.Forte@Sun.COM  */
7107836SJohn.Forte@Sun.COM static void
printSendTargets(SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES * pList)7117836SJohn.Forte@Sun.COM printSendTargets(SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES *pList)
7127836SJohn.Forte@Sun.COM {
7137836SJohn.Forte@Sun.COM 	char outBuf[INET6_ADDRSTRLEN];
7147836SJohn.Forte@Sun.COM 	int inetSize;
7157836SJohn.Forte@Sun.COM 	int af;
7167836SJohn.Forte@Sun.COM 	int i;
7177836SJohn.Forte@Sun.COM 
7187836SJohn.Forte@Sun.COM 	for (i = 0; i < pList->keyCount; i++) {
7197836SJohn.Forte@Sun.COM 		if (pList->keys[i].address.ipAddress.ipv4Address == IMA_TRUE) {
7207836SJohn.Forte@Sun.COM 			af = AF_INET;
7217836SJohn.Forte@Sun.COM 			inetSize = INET_ADDRSTRLEN;
7227836SJohn.Forte@Sun.COM 		} else {
7237836SJohn.Forte@Sun.COM 			af = AF_INET6;
7247836SJohn.Forte@Sun.COM 			inetSize = INET6_ADDRSTRLEN;
7257836SJohn.Forte@Sun.COM 		}
7267836SJohn.Forte@Sun.COM 		(void) fprintf(stdout, gettext("\tTarget name: %ws\n"),
7277836SJohn.Forte@Sun.COM 		    pList->keys[i].name);
7287836SJohn.Forte@Sun.COM 		(void) fprintf(stdout, "\t\t%s: %15s:%d", "Target address",
7297836SJohn.Forte@Sun.COM 		    inet_ntop(af, &(pList->keys[i].address.ipAddress.ipAddress),
7307836SJohn.Forte@Sun.COM 		    outBuf, inetSize), pList->keys[i].address.portNumber);
7317836SJohn.Forte@Sun.COM 		(void) fprintf(stdout, ", %d", pList->keys[i].tpgt);
7327836SJohn.Forte@Sun.COM 		(void) fprintf(stdout, "\n");
7337836SJohn.Forte@Sun.COM 	}
7347836SJohn.Forte@Sun.COM }
7357836SJohn.Forte@Sun.COM 
7367836SJohn.Forte@Sun.COM 
7377836SJohn.Forte@Sun.COM /*
7387836SJohn.Forte@Sun.COM  * Print all login parameters
7397836SJohn.Forte@Sun.COM  */
7407836SJohn.Forte@Sun.COM static int
printLoginParameters(char * prefix,IMA_OID oid,int printOption)7417836SJohn.Forte@Sun.COM printLoginParameters(char *prefix, IMA_OID oid, int printOption)
7427836SJohn.Forte@Sun.COM {
7437836SJohn.Forte@Sun.COM 	IMA_STATUS status;
7447836SJohn.Forte@Sun.COM 	IMA_BOOL_VALUE propBool;
7457836SJohn.Forte@Sun.COM 	IMA_MIN_MAX_VALUE propMinMax;
7467836SJohn.Forte@Sun.COM 	char longString[MAX_LONG_CHAR_LEN + 1];
7477836SJohn.Forte@Sun.COM 	SUN_IMA_CONN_PROPERTIES	*connProps = NULL;
7487836SJohn.Forte@Sun.COM 	IMA_OID_LIST *pConnList;
7497836SJohn.Forte@Sun.COM 
7507836SJohn.Forte@Sun.COM 	(void) memset(longString, 0, sizeof (longString));
7517836SJohn.Forte@Sun.COM 
7527836SJohn.Forte@Sun.COM 	switch (printOption) {
7537836SJohn.Forte@Sun.COM 		case PRINT_CONFIGURED_PARAMS:
7547836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "%s%s:\n",
7557836SJohn.Forte@Sun.COM 			    prefix,
7567836SJohn.Forte@Sun.COM 			    gettext("Login Parameters (Default/Configured)"));
7577836SJohn.Forte@Sun.COM 			break;
7587836SJohn.Forte@Sun.COM 		case PRINT_NEGOTIATED_PARAMS:
7597836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "%s%s:\n",
7607836SJohn.Forte@Sun.COM 			    prefix,
7617836SJohn.Forte@Sun.COM 			    gettext("Login Parameters (Negotiated)"));
7627836SJohn.Forte@Sun.COM 			status = SUN_IMA_GetConnOidList(
7637836SJohn.Forte@Sun.COM 			    &oid,
7647836SJohn.Forte@Sun.COM 			    &pConnList);
7657836SJohn.Forte@Sun.COM 
7667836SJohn.Forte@Sun.COM 			if (!IMA_SUCCESS(status)) {
7677836SJohn.Forte@Sun.COM 				printLibError(status);
7687836SJohn.Forte@Sun.COM 				return (1);
7697836SJohn.Forte@Sun.COM 			}
7707836SJohn.Forte@Sun.COM 
7717836SJohn.Forte@Sun.COM 			status = SUN_IMA_GetConnProperties(&pConnList->oids[0],
7727836SJohn.Forte@Sun.COM 			    &connProps);
7737836SJohn.Forte@Sun.COM 			propBool.currentValueValid = connProps->valuesValid;
7747836SJohn.Forte@Sun.COM 			propMinMax.currentValueValid = connProps->valuesValid;
7757836SJohn.Forte@Sun.COM 			break;
7767836SJohn.Forte@Sun.COM 		default:
7777836SJohn.Forte@Sun.COM 			return (1);
7787836SJohn.Forte@Sun.COM 	}
7797836SJohn.Forte@Sun.COM 
7807836SJohn.Forte@Sun.COM 	if (printOption == PRINT_NEGOTIATED_PARAMS) {
7817836SJohn.Forte@Sun.COM 		propBool.currentValue = connProps->dataSequenceInOrder;
7827836SJohn.Forte@Sun.COM 	} else {
7837836SJohn.Forte@Sun.COM 		status = IMA_GetDataSequenceInOrderProperties(oid, &propBool);
7847836SJohn.Forte@Sun.COM 	}
7857836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
7867836SJohn.Forte@Sun.COM 		printLibError(status);
7877836SJohn.Forte@Sun.COM 		(void) IMA_FreeMemory(connProps);
7887836SJohn.Forte@Sun.COM 		return (1);
7897836SJohn.Forte@Sun.COM 	}
7907836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "%s\t%s: ", prefix,
7917836SJohn.Forte@Sun.COM 	    gettext("Data Sequence In Order"));
7927836SJohn.Forte@Sun.COM 	IMABOOLPRINT(propBool, printOption);
7937836SJohn.Forte@Sun.COM 
7947836SJohn.Forte@Sun.COM 
7957836SJohn.Forte@Sun.COM 	if (printOption == PRINT_NEGOTIATED_PARAMS) {
7967836SJohn.Forte@Sun.COM 		propBool.currentValue = connProps->dataPduInOrder;
7977836SJohn.Forte@Sun.COM 	} else {
7987836SJohn.Forte@Sun.COM 		status = IMA_GetDataPduInOrderProperties(oid, &propBool);
7997836SJohn.Forte@Sun.COM 	}
8007836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
8017836SJohn.Forte@Sun.COM 		printLibError(status);
8027836SJohn.Forte@Sun.COM 		(void) IMA_FreeMemory(connProps);
8037836SJohn.Forte@Sun.COM 		return (1);
8047836SJohn.Forte@Sun.COM 	}
8057836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "%s\t%s: ", prefix,
8067836SJohn.Forte@Sun.COM 	    gettext("Data PDU In Order"));
8077836SJohn.Forte@Sun.COM 	IMABOOLPRINT(propBool, printOption);
8087836SJohn.Forte@Sun.COM 
8097836SJohn.Forte@Sun.COM 
8107836SJohn.Forte@Sun.COM 	if (printOption == PRINT_NEGOTIATED_PARAMS) {
8117836SJohn.Forte@Sun.COM 		propMinMax.currentValue = connProps->defaultTime2Retain;
8127836SJohn.Forte@Sun.COM 	} else {
8137836SJohn.Forte@Sun.COM 		status = IMA_GetDefaultTime2RetainProperties(oid, &propMinMax);
8147836SJohn.Forte@Sun.COM 	}
8157836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
8167836SJohn.Forte@Sun.COM 		printLibError(status);
8177836SJohn.Forte@Sun.COM 		(void) IMA_FreeMemory(connProps);
8187836SJohn.Forte@Sun.COM 		return (1);
8197836SJohn.Forte@Sun.COM 	}
8207836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "%s\t%s: ", prefix,
8217836SJohn.Forte@Sun.COM 	    gettext("Default Time To Retain"));
8227836SJohn.Forte@Sun.COM 	IMAMINMAXPRINT(propMinMax, printOption);
8237836SJohn.Forte@Sun.COM 
8247836SJohn.Forte@Sun.COM 
8257836SJohn.Forte@Sun.COM 	if (printOption == PRINT_NEGOTIATED_PARAMS) {
8267836SJohn.Forte@Sun.COM 		propMinMax.currentValue = connProps->defaultTime2Wait;
8277836SJohn.Forte@Sun.COM 	} else {
8287836SJohn.Forte@Sun.COM 		status = IMA_GetDefaultTime2WaitProperties(oid, &propMinMax);
8297836SJohn.Forte@Sun.COM 	}
8307836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
8317836SJohn.Forte@Sun.COM 		printLibError(status);
8327836SJohn.Forte@Sun.COM 		(void) IMA_FreeMemory(connProps);
8337836SJohn.Forte@Sun.COM 		return (1);
8347836SJohn.Forte@Sun.COM 	}
8357836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "%s\t%s: ", prefix,
8367836SJohn.Forte@Sun.COM 	    gettext("Default Time To Wait"));
8377836SJohn.Forte@Sun.COM 	IMAMINMAXPRINT(propMinMax, printOption);
8387836SJohn.Forte@Sun.COM 
8397836SJohn.Forte@Sun.COM 
8407836SJohn.Forte@Sun.COM 	if (printOption == PRINT_NEGOTIATED_PARAMS) {
8417836SJohn.Forte@Sun.COM 		propMinMax.currentValue = connProps->errorRecoveryLevel;
8427836SJohn.Forte@Sun.COM 	} else {
8437836SJohn.Forte@Sun.COM 		status = IMA_GetErrorRecoveryLevelProperties(oid, &propMinMax);
8447836SJohn.Forte@Sun.COM 	}
8457836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
8467836SJohn.Forte@Sun.COM 		printLibError(status);
8477836SJohn.Forte@Sun.COM 		(void) IMA_FreeMemory(connProps);
8487836SJohn.Forte@Sun.COM 		return (1);
8497836SJohn.Forte@Sun.COM 	}
8507836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "%s\t%s: ", prefix,
8517836SJohn.Forte@Sun.COM 	    gettext("Error Recovery Level"));
8527836SJohn.Forte@Sun.COM 	IMAMINMAXPRINT(propMinMax, printOption);
8537836SJohn.Forte@Sun.COM 
8547836SJohn.Forte@Sun.COM 
8557836SJohn.Forte@Sun.COM 	if (printOption == PRINT_NEGOTIATED_PARAMS) {
8567836SJohn.Forte@Sun.COM 		propMinMax.currentValue = connProps->firstBurstLength;
8577836SJohn.Forte@Sun.COM 	} else {
8587836SJohn.Forte@Sun.COM 		status = IMA_GetFirstBurstLengthProperties(oid,
8597836SJohn.Forte@Sun.COM 		    &propMinMax);
8607836SJohn.Forte@Sun.COM 	}
8617836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
8627836SJohn.Forte@Sun.COM 		printLibError(status);
8637836SJohn.Forte@Sun.COM 		(void) IMA_FreeMemory(connProps);
8647836SJohn.Forte@Sun.COM 		return (1);
8657836SJohn.Forte@Sun.COM 	}
8667836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "%s\t%s: ",
8677836SJohn.Forte@Sun.COM 	    prefix, gettext("First Burst Length"));
8687836SJohn.Forte@Sun.COM 	IMAMINMAXPRINT(propMinMax, printOption);
8697836SJohn.Forte@Sun.COM 
8707836SJohn.Forte@Sun.COM 
8717836SJohn.Forte@Sun.COM 	if (printOption == PRINT_NEGOTIATED_PARAMS) {
8727836SJohn.Forte@Sun.COM 		propBool.currentValue = connProps->immediateData;
8737836SJohn.Forte@Sun.COM 	} else {
8747836SJohn.Forte@Sun.COM 		status = IMA_GetImmediateDataProperties(oid, &propBool);
8757836SJohn.Forte@Sun.COM 	}
8767836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
8777836SJohn.Forte@Sun.COM 		printLibError(status);
8787836SJohn.Forte@Sun.COM 		(void) IMA_FreeMemory(connProps);
8797836SJohn.Forte@Sun.COM 		return (1);
8807836SJohn.Forte@Sun.COM 	}
8817836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "%s\t%s: ", prefix, gettext("Immediate Data"));
8827836SJohn.Forte@Sun.COM 	IMABOOLPRINT(propBool, printOption);
8837836SJohn.Forte@Sun.COM 
8847836SJohn.Forte@Sun.COM 
8857836SJohn.Forte@Sun.COM 	if (printOption == PRINT_NEGOTIATED_PARAMS) {
8867836SJohn.Forte@Sun.COM 		propBool.currentValue = connProps->initialR2T;
8877836SJohn.Forte@Sun.COM 	} else {
8887836SJohn.Forte@Sun.COM 		status = IMA_GetInitialR2TProperties(oid, &propBool);
8897836SJohn.Forte@Sun.COM 	}
8907836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
8917836SJohn.Forte@Sun.COM 		printLibError(status);
8927836SJohn.Forte@Sun.COM 		(void) IMA_FreeMemory(connProps);
8937836SJohn.Forte@Sun.COM 		return (1);
8947836SJohn.Forte@Sun.COM 	}
8957836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "%s\t%s: ", prefix,
8967836SJohn.Forte@Sun.COM 	    gettext("Initial Ready To Transfer (R2T)"));
8977836SJohn.Forte@Sun.COM 	IMABOOLPRINT(propBool, printOption);
8987836SJohn.Forte@Sun.COM 
8997836SJohn.Forte@Sun.COM 
9007836SJohn.Forte@Sun.COM 	if (printOption == PRINT_NEGOTIATED_PARAMS) {
9017836SJohn.Forte@Sun.COM 		propMinMax.currentValue = connProps->maxBurstLength;
9027836SJohn.Forte@Sun.COM 	} else {
9037836SJohn.Forte@Sun.COM 		status = IMA_GetMaxBurstLengthProperties(oid, &propMinMax);
9047836SJohn.Forte@Sun.COM 	}
9057836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
9067836SJohn.Forte@Sun.COM 		printLibError(status);
9077836SJohn.Forte@Sun.COM 		(void) IMA_FreeMemory(connProps);
9087836SJohn.Forte@Sun.COM 		return (1);
9097836SJohn.Forte@Sun.COM 	}
9107836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "%s\t%s: ", prefix, gettext("Max Burst Length"));
9117836SJohn.Forte@Sun.COM 	IMAMINMAXPRINT(propMinMax, printOption);
9127836SJohn.Forte@Sun.COM 
9137836SJohn.Forte@Sun.COM 
9147836SJohn.Forte@Sun.COM 	if (printOption == PRINT_NEGOTIATED_PARAMS) {
9157836SJohn.Forte@Sun.COM 		propMinMax.currentValue = connProps->maxOutstandingR2T;
9167836SJohn.Forte@Sun.COM 	} else {
9177836SJohn.Forte@Sun.COM 		status = IMA_GetMaxOutstandingR2TProperties(oid, &propMinMax);
9187836SJohn.Forte@Sun.COM 	}
9197836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
9207836SJohn.Forte@Sun.COM 		printLibError(status);
9217836SJohn.Forte@Sun.COM 		(void) IMA_FreeMemory(connProps);
9227836SJohn.Forte@Sun.COM 		return (1);
9237836SJohn.Forte@Sun.COM 	}
9247836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "%s\t%s: ", prefix,
9257836SJohn.Forte@Sun.COM 	    gettext("Max Outstanding R2T"));
9267836SJohn.Forte@Sun.COM 	IMAMINMAXPRINT(propMinMax, printOption);
9277836SJohn.Forte@Sun.COM 
9287836SJohn.Forte@Sun.COM 
9297836SJohn.Forte@Sun.COM 	if (printOption == PRINT_NEGOTIATED_PARAMS) {
9307836SJohn.Forte@Sun.COM 		propMinMax.currentValue = connProps->maxRecvDataSegmentLength;
9317836SJohn.Forte@Sun.COM 	} else {
9327836SJohn.Forte@Sun.COM 		status = IMA_GetMaxRecvDataSegmentLengthProperties(oid,
9337836SJohn.Forte@Sun.COM 		    &propMinMax);
9347836SJohn.Forte@Sun.COM 	}
9357836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
9367836SJohn.Forte@Sun.COM 		printLibError(status);
9377836SJohn.Forte@Sun.COM 		(void) IMA_FreeMemory(connProps);
9387836SJohn.Forte@Sun.COM 		return (1);
9397836SJohn.Forte@Sun.COM 	}
9407836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "%s\t%s: ", prefix,
9417836SJohn.Forte@Sun.COM 	    gettext("Max Receive Data Segment Length"));
9427836SJohn.Forte@Sun.COM 	IMAMINMAXPRINT(propMinMax, printOption);
9437836SJohn.Forte@Sun.COM 
9447836SJohn.Forte@Sun.COM 
9457836SJohn.Forte@Sun.COM 	if (printOption == PRINT_NEGOTIATED_PARAMS) {
9467836SJohn.Forte@Sun.COM 		propMinMax.currentValue = connProps->maxConnections;
9477836SJohn.Forte@Sun.COM 	} else {
9487836SJohn.Forte@Sun.COM 		status = IMA_GetMaxConnectionsProperties(oid, &propMinMax);
9497836SJohn.Forte@Sun.COM 	}
9507836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
9517836SJohn.Forte@Sun.COM 		printLibError(status);
9527836SJohn.Forte@Sun.COM 		(void) IMA_FreeMemory(connProps);
9537836SJohn.Forte@Sun.COM 		return (1);
9547836SJohn.Forte@Sun.COM 	}
9557836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "%s\t%s: ", prefix, gettext("Max Connections"));
9567836SJohn.Forte@Sun.COM 	IMAMINMAXPRINT(propMinMax, printOption);
9577836SJohn.Forte@Sun.COM 
9587836SJohn.Forte@Sun.COM 	(void) IMA_FreeMemory(connProps);
9597836SJohn.Forte@Sun.COM 	return (0);
9607836SJohn.Forte@Sun.COM }
9617836SJohn.Forte@Sun.COM 
9627836SJohn.Forte@Sun.COM /*
9637836SJohn.Forte@Sun.COM  * Print discovery information.
9647836SJohn.Forte@Sun.COM  */
9657836SJohn.Forte@Sun.COM static void
printDiscoveryMethod(char * prefix,IMA_UINT32 discoveryMethodFlags)9667836SJohn.Forte@Sun.COM printDiscoveryMethod(char *prefix, IMA_UINT32 discoveryMethodFlags)
9677836SJohn.Forte@Sun.COM {
9687836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "%s%s: ", prefix, gettext("Discovery Method"));
9697836SJohn.Forte@Sun.COM 	if (discoveryMethodFlags == IMA_TARGET_DISCOVERY_METHOD_UNKNOWN) {
9707836SJohn.Forte@Sun.COM 		(void) fprintf(stdout, "%s\n", gettext("NA"));
9717836SJohn.Forte@Sun.COM 	} else {
9727836SJohn.Forte@Sun.COM 		if (!((discoveryMethodFlags &
9737836SJohn.Forte@Sun.COM 		    IMA_TARGET_DISCOVERY_METHOD_STATIC) ^
9747836SJohn.Forte@Sun.COM 		    IMA_TARGET_DISCOVERY_METHOD_STATIC)) {
9757836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "%s ", gettext("Static"));
9767836SJohn.Forte@Sun.COM 		}
9777836SJohn.Forte@Sun.COM 		if (!((discoveryMethodFlags &
9787836SJohn.Forte@Sun.COM 		    IMA_TARGET_DISCOVERY_METHOD_SENDTARGETS) ^
9797836SJohn.Forte@Sun.COM 		    IMA_TARGET_DISCOVERY_METHOD_SENDTARGETS)) {
9807836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "%s ", gettext("SendTargets"));
9817836SJohn.Forte@Sun.COM 		}
9827836SJohn.Forte@Sun.COM 		if (!((discoveryMethodFlags &
9837836SJohn.Forte@Sun.COM 		    IMA_TARGET_DISCOVERY_METHOD_ISNS) ^
9847836SJohn.Forte@Sun.COM 		    IMA_TARGET_DISCOVERY_METHOD_ISNS)) {
9857836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "%s ", gettext("iSNS"));
9867836SJohn.Forte@Sun.COM 		}
9877836SJohn.Forte@Sun.COM 		(void) fprintf(stdout, "\n");
9887836SJohn.Forte@Sun.COM 	}
9897836SJohn.Forte@Sun.COM }
9907836SJohn.Forte@Sun.COM 
9917836SJohn.Forte@Sun.COM /*
9927836SJohn.Forte@Sun.COM  * printConnectionList - Prints the conection list provided
9937836SJohn.Forte@Sun.COM  */
9947836SJohn.Forte@Sun.COM static void
printConnectionList(char * prefix,IMA_OID_LIST * pConnList)9957836SJohn.Forte@Sun.COM printConnectionList(char *prefix, IMA_OID_LIST *pConnList)
9967836SJohn.Forte@Sun.COM {
9977836SJohn.Forte@Sun.COM 	IMA_STATUS		imaStatus;
9987836SJohn.Forte@Sun.COM 	int			i;
9997836SJohn.Forte@Sun.COM 	SUN_IMA_CONN_PROPERTIES	*connProps;
10007836SJohn.Forte@Sun.COM 	union {
10017836SJohn.Forte@Sun.COM 		char	ipv4[INET_ADDRSTRLEN+1];
10027836SJohn.Forte@Sun.COM 		char	ipv6[INET6_ADDRSTRLEN+1];
10037836SJohn.Forte@Sun.COM 	} tmp;
10047836SJohn.Forte@Sun.COM 
10057836SJohn.Forte@Sun.COM 	for (i = 0; i < pConnList->oidCount; i++) {
10067836SJohn.Forte@Sun.COM 		imaStatus = SUN_IMA_GetConnProperties(&pConnList->oids[i],
10077836SJohn.Forte@Sun.COM 		    &connProps);
10087836SJohn.Forte@Sun.COM 
10097836SJohn.Forte@Sun.COM 		if (imaStatus != IMA_STATUS_SUCCESS) {
10107836SJohn.Forte@Sun.COM 			continue;
10117836SJohn.Forte@Sun.COM 		}
10127836SJohn.Forte@Sun.COM 
10137836SJohn.Forte@Sun.COM 		(void) fprintf(stdout, "%sCID: %d\n", prefix,
10147836SJohn.Forte@Sun.COM 		    connProps->connectionID);
10157836SJohn.Forte@Sun.COM 
10167836SJohn.Forte@Sun.COM 		(void) memset(&tmp, 0, sizeof (tmp));
10177836SJohn.Forte@Sun.COM 		if (connProps->local.ipAddress.ipv4Address == IMA_TRUE) {
10187836SJohn.Forte@Sun.COM 			if (inet_ntop(AF_INET,
10197836SJohn.Forte@Sun.COM 			    &connProps->local.ipAddress.ipAddress[0],
10207836SJohn.Forte@Sun.COM 			    &tmp.ipv4[0],
10217836SJohn.Forte@Sun.COM 			    INET_ADDRSTRLEN)) {
10227836SJohn.Forte@Sun.COM 				(void) fprintf(stdout,
10237836SJohn.Forte@Sun.COM 				    "%s  %s: %s:%u\n",
10247836SJohn.Forte@Sun.COM 				    prefix,
10257836SJohn.Forte@Sun.COM 				    gettext("IP address (Local)"),
10267836SJohn.Forte@Sun.COM 				    &tmp.ipv4[0],
10277836SJohn.Forte@Sun.COM 				    ntohs(connProps->local.portNumber));
10287836SJohn.Forte@Sun.COM 			}
10297836SJohn.Forte@Sun.COM 		} else {
10307836SJohn.Forte@Sun.COM 			if (inet_ntop(AF_INET6,
10317836SJohn.Forte@Sun.COM 			    &connProps->local.ipAddress.ipAddress[0],
10327836SJohn.Forte@Sun.COM 			    &tmp.ipv6[0],
10337836SJohn.Forte@Sun.COM 			    INET6_ADDRSTRLEN)) {
10347836SJohn.Forte@Sun.COM 				(void) fprintf(stdout,
10357836SJohn.Forte@Sun.COM 				    "%s  %s: [%s]:%u\n",
10367836SJohn.Forte@Sun.COM 				    prefix,
10377836SJohn.Forte@Sun.COM 				    gettext("IP address (Local)"),
10387836SJohn.Forte@Sun.COM 				    &tmp.ipv6[0],
10397836SJohn.Forte@Sun.COM 				    ntohs(connProps->local.portNumber));
10407836SJohn.Forte@Sun.COM 			}
10417836SJohn.Forte@Sun.COM 		}
10427836SJohn.Forte@Sun.COM 		if (connProps->peer.ipAddress.ipv4Address == IMA_TRUE) {
10437836SJohn.Forte@Sun.COM 			if (inet_ntop(AF_INET,
10447836SJohn.Forte@Sun.COM 			    &connProps->peer.ipAddress.ipAddress[0],
10457836SJohn.Forte@Sun.COM 			    &tmp.ipv4[0],
10467836SJohn.Forte@Sun.COM 			    INET_ADDRSTRLEN)) {
10477836SJohn.Forte@Sun.COM 				(void) fprintf(stdout,
10487836SJohn.Forte@Sun.COM 				    "%s  %s: %s:%u\n",
10497836SJohn.Forte@Sun.COM 				    prefix,
10507836SJohn.Forte@Sun.COM 				    gettext("IP address (Peer)"),
10517836SJohn.Forte@Sun.COM 				    &tmp.ipv4[0],
10527836SJohn.Forte@Sun.COM 				    ntohs(connProps->peer.portNumber));
10537836SJohn.Forte@Sun.COM 			}
10547836SJohn.Forte@Sun.COM 		} else {
10557836SJohn.Forte@Sun.COM 			if (inet_ntop(AF_INET6,
10567836SJohn.Forte@Sun.COM 			    &connProps->peer.ipAddress.ipAddress[0],
10577836SJohn.Forte@Sun.COM 			    &tmp.ipv6[0],
10587836SJohn.Forte@Sun.COM 			    INET6_ADDRSTRLEN)) {
10597836SJohn.Forte@Sun.COM 				(void) fprintf(stdout,
10607836SJohn.Forte@Sun.COM 				    "%s  %s: [%s]:%u\n",
10617836SJohn.Forte@Sun.COM 				    prefix,
10627836SJohn.Forte@Sun.COM 				    gettext("IP address (Peer)"),
10637836SJohn.Forte@Sun.COM 				    &tmp.ipv6[0],
10647836SJohn.Forte@Sun.COM 				    ntohs(connProps->peer.portNumber));
10657836SJohn.Forte@Sun.COM 			}
10667836SJohn.Forte@Sun.COM 		}
10677836SJohn.Forte@Sun.COM 
10687836SJohn.Forte@Sun.COM 		(void) IMA_FreeMemory(connProps);
10697836SJohn.Forte@Sun.COM 	}
10707836SJohn.Forte@Sun.COM }
10717836SJohn.Forte@Sun.COM 
10727836SJohn.Forte@Sun.COM /*
10737836SJohn.Forte@Sun.COM  * Set login parameters on a target or initiator
10747836SJohn.Forte@Sun.COM  */
10757836SJohn.Forte@Sun.COM static int
setLoginParameter(IMA_OID oid,int optval,char * optarg)10767836SJohn.Forte@Sun.COM setLoginParameter(IMA_OID oid, int optval, char *optarg)
10777836SJohn.Forte@Sun.COM {
10787836SJohn.Forte@Sun.COM 	IMA_STATUS status = IMA_STATUS_SUCCESS;
10797836SJohn.Forte@Sun.COM 	IMA_UINT uintValue;
10807836SJohn.Forte@Sun.COM 	IMA_BOOL boolValue;
10817836SJohn.Forte@Sun.COM 	SUN_IMA_DIGEST_ALGORITHM digestAlgList[1];
10827836SJohn.Forte@Sun.COM 	IMA_MIN_MAX_VALUE propMinMax;
10837836SJohn.Forte@Sun.COM 	char *endptr;
10847836SJohn.Forte@Sun.COM 
10857836SJohn.Forte@Sun.COM 	/*
10867836SJohn.Forte@Sun.COM 	 * for clarity, there are two switch statements
10877836SJohn.Forte@Sun.COM 	 * The first loads the variable and the second
10887836SJohn.Forte@Sun.COM 	 * calls the appropriate API
10897836SJohn.Forte@Sun.COM 	 */
10907836SJohn.Forte@Sun.COM 	switch (optval) {
10917836SJohn.Forte@Sun.COM 		case DATA_SEQ_IN_ORDER:
10927836SJohn.Forte@Sun.COM 		case IMMEDIATE_DATA:
10937836SJohn.Forte@Sun.COM 		case INITIAL_R2T:
10947836SJohn.Forte@Sun.COM 		case DATA_PDU_IN_ORDER:
10957836SJohn.Forte@Sun.COM 			/* implement 'default'? */
10967836SJohn.Forte@Sun.COM 			if (strcasecmp(optarg, "yes") == 0) {
10977836SJohn.Forte@Sun.COM 				boolValue = IMA_TRUE;
10987836SJohn.Forte@Sun.COM 			} else if (strcasecmp(optarg, "no") == 0) {
10997836SJohn.Forte@Sun.COM 				boolValue = IMA_FALSE;
11007836SJohn.Forte@Sun.COM 			} else {
11017836SJohn.Forte@Sun.COM 				(void) fprintf(stderr, "%s: %s - %s\n",
11027836SJohn.Forte@Sun.COM 				    cmdName,
11037836SJohn.Forte@Sun.COM 				    gettext("invalid option argument"),
11047836SJohn.Forte@Sun.COM 				    optarg);
11057836SJohn.Forte@Sun.COM 				return (1);
11067836SJohn.Forte@Sun.COM 			}
11077836SJohn.Forte@Sun.COM 			break;
11087836SJohn.Forte@Sun.COM 		case DEFAULT_TIME_2_RETAIN:
11097836SJohn.Forte@Sun.COM 		case DEFAULT_TIME_2_WAIT:
11107836SJohn.Forte@Sun.COM 			errno = 0;
11117836SJohn.Forte@Sun.COM 			uintValue = strtoul(optarg, &endptr, 0);
11127836SJohn.Forte@Sun.COM 			if (*endptr != '\0' || errno != 0) {
11137836SJohn.Forte@Sun.COM 				(void) fprintf(stderr, "%s: %s - %s\n",
11147836SJohn.Forte@Sun.COM 				    cmdName,
11157836SJohn.Forte@Sun.COM 				    gettext("invalid option argument"),
11167836SJohn.Forte@Sun.COM 				    optarg);
11177836SJohn.Forte@Sun.COM 				return (1);
11187836SJohn.Forte@Sun.COM 			}
11197836SJohn.Forte@Sun.COM 			if (uintValue > 3600) {
11207836SJohn.Forte@Sun.COM 				(void) fprintf(stderr, "%s: %s\n",
11217836SJohn.Forte@Sun.COM 				    cmdName,
11227836SJohn.Forte@Sun.COM gettext("value must be between 0 and 3600"));
11237836SJohn.Forte@Sun.COM 				return (1);
11247836SJohn.Forte@Sun.COM 			}
11257836SJohn.Forte@Sun.COM 			break;
11267836SJohn.Forte@Sun.COM 		case FIRST_BURST_LENGTH:
11277836SJohn.Forte@Sun.COM 		case MAX_BURST_LENGTH:
11287836SJohn.Forte@Sun.COM 		case MAX_RECV_DATA_SEG_LEN:
11297836SJohn.Forte@Sun.COM 			errno = 0;
11307836SJohn.Forte@Sun.COM 			/* implement 'default'? */
11317836SJohn.Forte@Sun.COM 			uintValue = strtoul(optarg, &endptr, 0);
11327836SJohn.Forte@Sun.COM 			if (*endptr != '\0' || errno != 0) {
11337836SJohn.Forte@Sun.COM 				(void) fprintf(stderr, "%s: %s - %s\n",
11347836SJohn.Forte@Sun.COM 				    cmdName,
11357836SJohn.Forte@Sun.COM 				    gettext("invalid option argument"),
11367836SJohn.Forte@Sun.COM 				    optarg);
11377836SJohn.Forte@Sun.COM 				return (1);
11387836SJohn.Forte@Sun.COM 			}
11397836SJohn.Forte@Sun.COM 			if (uintValue < 512 || uintValue > 16777215) {
11407836SJohn.Forte@Sun.COM 				(void) fprintf(stderr, "%s: %s\n",
11417836SJohn.Forte@Sun.COM 				    cmdName,
11427836SJohn.Forte@Sun.COM gettext("value must be between 512 and 16777215"));
11437836SJohn.Forte@Sun.COM 				return (1);
11447836SJohn.Forte@Sun.COM 			}
11457836SJohn.Forte@Sun.COM 			break;
11467836SJohn.Forte@Sun.COM 		case MAX_OUTSTANDING_R2T:
11477836SJohn.Forte@Sun.COM 			errno = 0;
11487836SJohn.Forte@Sun.COM 			uintValue = strtoul(optarg, &endptr, 0);
11497836SJohn.Forte@Sun.COM 			if (*endptr != '\0' || errno != 0) {
11507836SJohn.Forte@Sun.COM 				(void) fprintf(stderr, "%s: %s - %s\n",
11517836SJohn.Forte@Sun.COM 				    cmdName,
11527836SJohn.Forte@Sun.COM 				    gettext("invalid option argument"),
11537836SJohn.Forte@Sun.COM 				    optarg);
11547836SJohn.Forte@Sun.COM 				return (1);
11557836SJohn.Forte@Sun.COM 			}
11567836SJohn.Forte@Sun.COM 			if (uintValue < 1 || uintValue > 65535) {
11577836SJohn.Forte@Sun.COM 				(void) fprintf(stderr, "%s: %s\n",
11587836SJohn.Forte@Sun.COM 				    cmdName,
11597836SJohn.Forte@Sun.COM gettext("value must be between 1 and 65535"));
11607836SJohn.Forte@Sun.COM 				return (1);
11617836SJohn.Forte@Sun.COM 			}
11627836SJohn.Forte@Sun.COM 			break;
11637836SJohn.Forte@Sun.COM 		case HEADER_DIGEST:
11647836SJohn.Forte@Sun.COM 		case DATA_DIGEST:
11657836SJohn.Forte@Sun.COM 			if (strcasecmp(optarg, "none") == 0) {
11667836SJohn.Forte@Sun.COM 				digestAlgList[0] = SUN_IMA_DIGEST_NONE;
11677836SJohn.Forte@Sun.COM 			} else if (strcasecmp(optarg, "CRC32") == 0) {
11687836SJohn.Forte@Sun.COM 				digestAlgList[0] = SUN_IMA_DIGEST_CRC32;
11697836SJohn.Forte@Sun.COM 			} else {
11707836SJohn.Forte@Sun.COM 				(void) fprintf(stderr, "%s: %s - %s\n",
11717836SJohn.Forte@Sun.COM 				    cmdName,
11727836SJohn.Forte@Sun.COM 				    gettext("invalid option argument"),
11737836SJohn.Forte@Sun.COM 				    optarg);
11747836SJohn.Forte@Sun.COM 				return (1);
11757836SJohn.Forte@Sun.COM 			}
11767836SJohn.Forte@Sun.COM 			break;
11777836SJohn.Forte@Sun.COM 		case MAX_CONNECTIONS:
11787836SJohn.Forte@Sun.COM 			errno = 0;
11797836SJohn.Forte@Sun.COM 			uintValue = strtoul(optarg, &endptr, 0);
11807836SJohn.Forte@Sun.COM 			if (*endptr != '\0' || errno != 0) {
11817836SJohn.Forte@Sun.COM 				(void) fprintf(stderr, "%s: %s - %s\n",
11827836SJohn.Forte@Sun.COM 				    cmdName,
11837836SJohn.Forte@Sun.COM 				    gettext("invalid option argument"),
11847836SJohn.Forte@Sun.COM 				    optarg);
11857836SJohn.Forte@Sun.COM 				return (1);
11867836SJohn.Forte@Sun.COM 			}
11877836SJohn.Forte@Sun.COM 			if (uintValue < 1 || uintValue > 256) {
11887836SJohn.Forte@Sun.COM 				(void) fprintf(stderr, "%s: %s\n",
11897836SJohn.Forte@Sun.COM 				    cmdName,
11907836SJohn.Forte@Sun.COM gettext("value must be between 1 and 256"));
11917836SJohn.Forte@Sun.COM 				return (1);
11927836SJohn.Forte@Sun.COM 			}
11937836SJohn.Forte@Sun.COM 			break;
11947836SJohn.Forte@Sun.COM 		case ERROR_RECOVERY_LEVEL:
11957836SJohn.Forte@Sun.COM 			errno = 0;
11967836SJohn.Forte@Sun.COM 			uintValue = strtoul(optarg, &endptr, 0);
11977836SJohn.Forte@Sun.COM 			if (*endptr != '\0' || errno != 0) {
11987836SJohn.Forte@Sun.COM 				(void) fprintf(stderr, "%s: %s - %s\n",
11997836SJohn.Forte@Sun.COM 				    cmdName,
12007836SJohn.Forte@Sun.COM 				    gettext("invalid option argument"),
12017836SJohn.Forte@Sun.COM 				    optarg);
12027836SJohn.Forte@Sun.COM 				return (1);
12037836SJohn.Forte@Sun.COM 			}
12047836SJohn.Forte@Sun.COM 			if (uintValue > 2) {
12057836SJohn.Forte@Sun.COM 				(void) fprintf(stderr, "%s: %s\n",
12067836SJohn.Forte@Sun.COM 				    cmdName,
12077836SJohn.Forte@Sun.COM gettext("value must be between 0 and 2"));
12087836SJohn.Forte@Sun.COM 				return (1);
12097836SJohn.Forte@Sun.COM 			}
12107836SJohn.Forte@Sun.COM 			break;
12117836SJohn.Forte@Sun.COM 		default:
12127836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %c: %s\n",
12137836SJohn.Forte@Sun.COM 			    cmdName, optval, gettext("unknown option"));
12147836SJohn.Forte@Sun.COM 			return (1);
12157836SJohn.Forte@Sun.COM 	}
12167836SJohn.Forte@Sun.COM 
12177836SJohn.Forte@Sun.COM 	switch (optval) {
12187836SJohn.Forte@Sun.COM 		case DATA_PDU_IN_ORDER:
12197836SJohn.Forte@Sun.COM 			status = IMA_SetDataPduInOrder(oid, boolValue);
12207836SJohn.Forte@Sun.COM 			break;
12217836SJohn.Forte@Sun.COM 		case DATA_SEQ_IN_ORDER:
12227836SJohn.Forte@Sun.COM 			status = IMA_SetDataSequenceInOrder(oid, boolValue);
12237836SJohn.Forte@Sun.COM 			break;
12247836SJohn.Forte@Sun.COM 		case DEFAULT_TIME_2_RETAIN:
12257836SJohn.Forte@Sun.COM 			status = IMA_SetDefaultTime2Retain(oid, uintValue);
12267836SJohn.Forte@Sun.COM 			break;
12277836SJohn.Forte@Sun.COM 		case DEFAULT_TIME_2_WAIT:
12287836SJohn.Forte@Sun.COM 			status = IMA_SetDefaultTime2Wait(oid, uintValue);
12297836SJohn.Forte@Sun.COM 			break;
12307836SJohn.Forte@Sun.COM 		case FIRST_BURST_LENGTH:
12317836SJohn.Forte@Sun.COM 			status = IMA_SetFirstBurstLength(oid, uintValue);
12327836SJohn.Forte@Sun.COM 
12337836SJohn.Forte@Sun.COM 			/*
12347836SJohn.Forte@Sun.COM 			 * If this call fails check to see if it's because
12357836SJohn.Forte@Sun.COM 			 * the requested value is > than maxBurstLength
12367836SJohn.Forte@Sun.COM 			 */
12377836SJohn.Forte@Sun.COM 			if (!IMA_SUCCESS(status)) {
12387836SJohn.Forte@Sun.COM 				status = IMA_GetMaxBurstLengthProperties(oid,
12397836SJohn.Forte@Sun.COM 				    &propMinMax);
12407836SJohn.Forte@Sun.COM 				if (!IMA_SUCCESS(status)) {
12417836SJohn.Forte@Sun.COM 					printLibError(status);
12427836SJohn.Forte@Sun.COM 					return (1);
12437836SJohn.Forte@Sun.COM 				}
12447836SJohn.Forte@Sun.COM 				if (uintValue > propMinMax.currentValue) {
12457836SJohn.Forte@Sun.COM 					(void) fprintf(stderr,
12467836SJohn.Forte@Sun.COM 					    "%s: %s\n", cmdName,
12477836SJohn.Forte@Sun.COM 					    gettext("firstBurstLength must " \
12487836SJohn.Forte@Sun.COM 					    "be less than or equal to than " \
12497836SJohn.Forte@Sun.COM 					    "maxBurstLength"));
12507836SJohn.Forte@Sun.COM 				}
12517836SJohn.Forte@Sun.COM 				return (1);
12527836SJohn.Forte@Sun.COM 			}
12537836SJohn.Forte@Sun.COM 
12547836SJohn.Forte@Sun.COM 			break;
12557836SJohn.Forte@Sun.COM 		case IMMEDIATE_DATA:
12567836SJohn.Forte@Sun.COM 			status = IMA_SetImmediateData(oid, boolValue);
12577836SJohn.Forte@Sun.COM 			break;
12587836SJohn.Forte@Sun.COM 		case INITIAL_R2T:
12597836SJohn.Forte@Sun.COM 			status = IMA_SetInitialR2T(oid, boolValue);
12607836SJohn.Forte@Sun.COM 			break;
12617836SJohn.Forte@Sun.COM 		case MAX_BURST_LENGTH:
12627836SJohn.Forte@Sun.COM 			status = IMA_SetMaxBurstLength(oid, uintValue);
12637836SJohn.Forte@Sun.COM 			/*
12647836SJohn.Forte@Sun.COM 			 * If this call fails check to see if it's because
12657836SJohn.Forte@Sun.COM 			 * the requested value is < than firstBurstLength
12667836SJohn.Forte@Sun.COM 			 */
12677836SJohn.Forte@Sun.COM 			if (!IMA_SUCCESS(status)) {
12687836SJohn.Forte@Sun.COM 				status = IMA_GetFirstBurstLengthProperties(oid,
12697836SJohn.Forte@Sun.COM 				    &propMinMax);
12707836SJohn.Forte@Sun.COM 				if (!IMA_SUCCESS(status)) {
12717836SJohn.Forte@Sun.COM 					printLibError(status);
12727836SJohn.Forte@Sun.COM 					return (1);
12737836SJohn.Forte@Sun.COM 				}
12747836SJohn.Forte@Sun.COM 				if (uintValue < propMinMax.currentValue) {
12757836SJohn.Forte@Sun.COM 					(void) fprintf(stderr, "%s: %s\n",
12767836SJohn.Forte@Sun.COM 					    cmdName,
12777836SJohn.Forte@Sun.COM 					    gettext("maxBurstLength must be " \
12787836SJohn.Forte@Sun.COM 					    "greater than or equal to " \
12797836SJohn.Forte@Sun.COM 					    "firstBurstLength"));
12807836SJohn.Forte@Sun.COM 				}
12817836SJohn.Forte@Sun.COM 				return (1);
12827836SJohn.Forte@Sun.COM 			}
12837836SJohn.Forte@Sun.COM 			break;
12847836SJohn.Forte@Sun.COM 
12857836SJohn.Forte@Sun.COM 		case MAX_OUTSTANDING_R2T:
12867836SJohn.Forte@Sun.COM 			status = IMA_SetMaxOutstandingR2T(oid, uintValue);
12877836SJohn.Forte@Sun.COM 			break;
12887836SJohn.Forte@Sun.COM 		case MAX_RECV_DATA_SEG_LEN:
12897836SJohn.Forte@Sun.COM 			status = IMA_SetMaxRecvDataSegmentLength(oid,
12907836SJohn.Forte@Sun.COM 			    uintValue);
12917836SJohn.Forte@Sun.COM 			break;
12927836SJohn.Forte@Sun.COM 		case HEADER_DIGEST:
12937836SJohn.Forte@Sun.COM 			status = SUN_IMA_SetHeaderDigest(oid, 1,
12947836SJohn.Forte@Sun.COM 			    &digestAlgList[0]);
12957836SJohn.Forte@Sun.COM 			break;
12967836SJohn.Forte@Sun.COM 		case DATA_DIGEST:
12977836SJohn.Forte@Sun.COM 			status = SUN_IMA_SetDataDigest(oid, 1,
12987836SJohn.Forte@Sun.COM 			    &digestAlgList[0]);
12997836SJohn.Forte@Sun.COM 			break;
13007836SJohn.Forte@Sun.COM 		case MAX_CONNECTIONS:
13017836SJohn.Forte@Sun.COM 			status = IMA_SetMaxConnections(oid, uintValue);
13027836SJohn.Forte@Sun.COM 			break;
13037836SJohn.Forte@Sun.COM 		case ERROR_RECOVERY_LEVEL:
13047836SJohn.Forte@Sun.COM 			status = IMA_SetErrorRecoveryLevel(oid, uintValue);
13057836SJohn.Forte@Sun.COM 			break;
13067836SJohn.Forte@Sun.COM 	}
13077836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
13087836SJohn.Forte@Sun.COM 		printLibError(status);
13097836SJohn.Forte@Sun.COM 		return (1);
13107836SJohn.Forte@Sun.COM 	}
13117836SJohn.Forte@Sun.COM 	return (0);
13127836SJohn.Forte@Sun.COM }
13137836SJohn.Forte@Sun.COM 
13147836SJohn.Forte@Sun.COM static void
printDigestAlgorithm(SUN_IMA_DIGEST_ALGORITHM_VALUE * digestAlgorithms,int printOption)13157836SJohn.Forte@Sun.COM printDigestAlgorithm(SUN_IMA_DIGEST_ALGORITHM_VALUE *digestAlgorithms,
13167836SJohn.Forte@Sun.COM     int printOption)
13177836SJohn.Forte@Sun.COM {
13187836SJohn.Forte@Sun.COM 	int i;
13197836SJohn.Forte@Sun.COM 
13207836SJohn.Forte@Sun.COM 	if (printOption == PRINT_CONFIGURED_PARAMS) {
13217836SJohn.Forte@Sun.COM 		for (i = 0; i < digestAlgorithms->defaultAlgorithmCount; i++) {
13227836SJohn.Forte@Sun.COM 			if (i > 0) {
13237836SJohn.Forte@Sun.COM 				(void) fprintf(stdout, "|");
13247836SJohn.Forte@Sun.COM 			}
13257836SJohn.Forte@Sun.COM 			switch (digestAlgorithms->defaultAlgorithms[i]) {
13267836SJohn.Forte@Sun.COM 				case SUN_IMA_DIGEST_NONE:
13277836SJohn.Forte@Sun.COM 					(void) fprintf(stdout,
13287836SJohn.Forte@Sun.COM 					    gettext("NONE"));
13297836SJohn.Forte@Sun.COM 					break;
13307836SJohn.Forte@Sun.COM 				case SUN_IMA_DIGEST_CRC32:
13317836SJohn.Forte@Sun.COM 					(void) fprintf(stdout,
13327836SJohn.Forte@Sun.COM 					    gettext("CRC32"));
13337836SJohn.Forte@Sun.COM 					break;
13347836SJohn.Forte@Sun.COM 				default:
13357836SJohn.Forte@Sun.COM 					(void) fprintf(stdout,
13367836SJohn.Forte@Sun.COM 					    gettext("Unknown"));
13377836SJohn.Forte@Sun.COM 					break;
13387836SJohn.Forte@Sun.COM 			}
13397836SJohn.Forte@Sun.COM 		}
13407836SJohn.Forte@Sun.COM 		(void) fprintf(stdout, "/");
13417836SJohn.Forte@Sun.COM 		if (digestAlgorithms->currentValid == IMA_TRUE) {
13427836SJohn.Forte@Sun.COM 			for (i = 0;
13437836SJohn.Forte@Sun.COM 			    i < digestAlgorithms->currentAlgorithmCount; i++) {
13447836SJohn.Forte@Sun.COM 				if (i > 0) {
13457836SJohn.Forte@Sun.COM 					(void) fprintf(stdout, "|");
13467836SJohn.Forte@Sun.COM 				}
13477836SJohn.Forte@Sun.COM 				switch (digestAlgorithms->
13487836SJohn.Forte@Sun.COM 				    currentAlgorithms[i]) {
13497836SJohn.Forte@Sun.COM 					case SUN_IMA_DIGEST_NONE:
13507836SJohn.Forte@Sun.COM 						(void) fprintf(stdout,
13517836SJohn.Forte@Sun.COM 						    gettext("NONE"));
13527836SJohn.Forte@Sun.COM 						break;
13537836SJohn.Forte@Sun.COM 					case SUN_IMA_DIGEST_CRC32:
13547836SJohn.Forte@Sun.COM 						(void) fprintf(stdout,
13557836SJohn.Forte@Sun.COM 						    gettext("CRC32"));
13567836SJohn.Forte@Sun.COM 						break;
13577836SJohn.Forte@Sun.COM 					default:
13587836SJohn.Forte@Sun.COM 						(void) fprintf(stdout,
13597836SJohn.Forte@Sun.COM 						    gettext("Unknown"));
13607836SJohn.Forte@Sun.COM 						break;
13617836SJohn.Forte@Sun.COM 				}
13627836SJohn.Forte@Sun.COM 			}
13637836SJohn.Forte@Sun.COM 		} else {
13647836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "-");
13657836SJohn.Forte@Sun.COM 		}
13667836SJohn.Forte@Sun.COM 		(void) fprintf(stdout, "\n");
13677836SJohn.Forte@Sun.COM 	} else if (printOption == PRINT_NEGOTIATED_PARAMS) {
13687836SJohn.Forte@Sun.COM 
13697836SJohn.Forte@Sun.COM 		if (digestAlgorithms->negotiatedValid == IMA_TRUE) {
13707836SJohn.Forte@Sun.COM 			for (i = 0;
13717836SJohn.Forte@Sun.COM 			    i < digestAlgorithms->negotiatedAlgorithmCount;
13727836SJohn.Forte@Sun.COM 			    i++) {
13737836SJohn.Forte@Sun.COM 				if (i > 0) {
13747836SJohn.Forte@Sun.COM 					(void) fprintf(stdout, "|");
13757836SJohn.Forte@Sun.COM 				}
13767836SJohn.Forte@Sun.COM 				switch (digestAlgorithms->
13777836SJohn.Forte@Sun.COM 				    negotiatedAlgorithms[i]) {
13787836SJohn.Forte@Sun.COM 					case SUN_IMA_DIGEST_NONE:
13797836SJohn.Forte@Sun.COM 						(void) fprintf(stdout,
13807836SJohn.Forte@Sun.COM 						    gettext("NONE"));
13817836SJohn.Forte@Sun.COM 						break;
13827836SJohn.Forte@Sun.COM 					case SUN_IMA_DIGEST_CRC32:
13837836SJohn.Forte@Sun.COM 						(void) fprintf(stdout,
13847836SJohn.Forte@Sun.COM 						    gettext("CRC32"));
13857836SJohn.Forte@Sun.COM 						break;
13867836SJohn.Forte@Sun.COM 					default:
13877836SJohn.Forte@Sun.COM 						(void) fprintf(stdout,
13887836SJohn.Forte@Sun.COM 						    gettext("Unknown"));
13897836SJohn.Forte@Sun.COM 						break;
13907836SJohn.Forte@Sun.COM 				}
13917836SJohn.Forte@Sun.COM 			}
13927836SJohn.Forte@Sun.COM 		} else {
13937836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "-");
13947836SJohn.Forte@Sun.COM 		}
13957836SJohn.Forte@Sun.COM 		(void) fprintf(stdout, "\n");
13967836SJohn.Forte@Sun.COM 	}
13977836SJohn.Forte@Sun.COM }
13987836SJohn.Forte@Sun.COM 
13997836SJohn.Forte@Sun.COM static int
setLoginParameters(IMA_OID oid,char * optarg)14007836SJohn.Forte@Sun.COM setLoginParameters(IMA_OID oid, char *optarg)
14017836SJohn.Forte@Sun.COM {
14027836SJohn.Forte@Sun.COM 	char keyp[MAXOPTARGLEN];
14037836SJohn.Forte@Sun.COM 	char valp[MAXOPTARGLEN];
14047836SJohn.Forte@Sun.COM 	int key;
14057836SJohn.Forte@Sun.COM 	char *nameValueString, *indexp, *delim = NULL;
14067836SJohn.Forte@Sun.COM 
14077836SJohn.Forte@Sun.COM 	if ((nameValueString = strdup(optarg)) == NULL) {
14087836SJohn.Forte@Sun.COM 		if (errno == ENOMEM) {
14097836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s\n",
14107836SJohn.Forte@Sun.COM 			    cmdName, strerror(errno));
14117836SJohn.Forte@Sun.COM 		} else {
14127836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s\n", cmdName,
14137836SJohn.Forte@Sun.COM 			    gettext("unknown error"));
14147836SJohn.Forte@Sun.COM 		}
14157836SJohn.Forte@Sun.COM 		return (1);
14167836SJohn.Forte@Sun.COM 	}
14177836SJohn.Forte@Sun.COM 
14187836SJohn.Forte@Sun.COM 	indexp = nameValueString;
14197836SJohn.Forte@Sun.COM 
14207836SJohn.Forte@Sun.COM 	/*
14217836SJohn.Forte@Sun.COM 	 * Retrieve all login params from option argument
14227836SJohn.Forte@Sun.COM 	 * Syntax <key=value,...>
14237836SJohn.Forte@Sun.COM 	 */
14247836SJohn.Forte@Sun.COM 	while (indexp) {
14257836SJohn.Forte@Sun.COM 		if (delim = strchr(indexp, ',')) {
14267836SJohn.Forte@Sun.COM 			delim[0] = '\0';
14277836SJohn.Forte@Sun.COM 		}
14287836SJohn.Forte@Sun.COM 		(void) memset(keyp, 0, sizeof (keyp));
14297836SJohn.Forte@Sun.COM 		(void) memset(valp, 0, sizeof (valp));
14307836SJohn.Forte@Sun.COM 		if (sscanf(indexp, gettext("%[^=]=%s"), keyp, valp) != 2) {
14317836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
14327836SJohn.Forte@Sun.COM 			    gettext("Unknown param"), indexp);
143310156SZhang.Yi@Sun.COM 			if (nameValueString) {
143410156SZhang.Yi@Sun.COM 				free(nameValueString);
143510156SZhang.Yi@Sun.COM 				nameValueString = NULL;
143610156SZhang.Yi@Sun.COM 			}
14377836SJohn.Forte@Sun.COM 			return (1);
14387836SJohn.Forte@Sun.COM 		}
14397836SJohn.Forte@Sun.COM 		if ((key = getLoginParam(keyp)) == -1) {
14407836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
14417836SJohn.Forte@Sun.COM 			    gettext("Unknown key"), keyp);
144210156SZhang.Yi@Sun.COM 			if (nameValueString) {
144310156SZhang.Yi@Sun.COM 				free(nameValueString);
144410156SZhang.Yi@Sun.COM 				nameValueString = NULL;
144510156SZhang.Yi@Sun.COM 			}
14467836SJohn.Forte@Sun.COM 			return (1);
14477836SJohn.Forte@Sun.COM 		}
14487836SJohn.Forte@Sun.COM 		if (setLoginParameter(oid, key, valp) != 0) {
144910156SZhang.Yi@Sun.COM 			if (nameValueString) {
145010156SZhang.Yi@Sun.COM 				free(nameValueString);
145110156SZhang.Yi@Sun.COM 				nameValueString = NULL;
145210156SZhang.Yi@Sun.COM 			}
14537836SJohn.Forte@Sun.COM 			return (1);
14547836SJohn.Forte@Sun.COM 		}
14557836SJohn.Forte@Sun.COM 		if (delim) {
14567836SJohn.Forte@Sun.COM 			indexp = delim + 1;
14577836SJohn.Forte@Sun.COM 		} else {
14587836SJohn.Forte@Sun.COM 			indexp = NULL;
14597836SJohn.Forte@Sun.COM 		}
14607836SJohn.Forte@Sun.COM 	}
14617836SJohn.Forte@Sun.COM 
146210156SZhang.Yi@Sun.COM 	if (nameValueString) {
146310156SZhang.Yi@Sun.COM 		free(nameValueString);
146410156SZhang.Yi@Sun.COM 		nameValueString = NULL;
146510156SZhang.Yi@Sun.COM 	}
14667836SJohn.Forte@Sun.COM 	return (0);
14677836SJohn.Forte@Sun.COM }
14687836SJohn.Forte@Sun.COM 
14697836SJohn.Forte@Sun.COM /*
14707836SJohn.Forte@Sun.COM  * Print logical unit information for a specific target
14717836SJohn.Forte@Sun.COM  */
14727836SJohn.Forte@Sun.COM static void
printTargetLuns(IMA_OID_LIST * lunList)14737836SJohn.Forte@Sun.COM printTargetLuns(IMA_OID_LIST * lunList)
14747836SJohn.Forte@Sun.COM {
14757836SJohn.Forte@Sun.COM 	int	j;
14767836SJohn.Forte@Sun.COM 	IMA_STATUS status;
14777836SJohn.Forte@Sun.COM 	SUN_IMA_LU_PROPERTIES	lunProps;
14787836SJohn.Forte@Sun.COM 
14797836SJohn.Forte@Sun.COM 	for (j = 0; j < lunList->oidCount; j++) {
14807836SJohn.Forte@Sun.COM 		status = SUN_IMA_GetLuProperties(lunList->oids[j],
14817836SJohn.Forte@Sun.COM 		    &lunProps);
14827836SJohn.Forte@Sun.COM 		if (!IMA_SUCCESS(status)) {
14837836SJohn.Forte@Sun.COM 			printLibError(status);
14847836SJohn.Forte@Sun.COM 			return;
14857836SJohn.Forte@Sun.COM 		}
14867836SJohn.Forte@Sun.COM 
148712161SJack.Meng@Sun.COM 		(void) fprintf(stdout, "\tLUN: %lld\n",
148812161SJack.Meng@Sun.COM 		    lunProps.imaProps.targetLun);
148912161SJack.Meng@Sun.COM 		(void) fprintf(stdout, "\t     Vendor:  %s\n",
149012161SJack.Meng@Sun.COM 		    lunProps.vendorId);
149112161SJack.Meng@Sun.COM 		(void) fprintf(stdout, "\t     Product: %s\n",
149212161SJack.Meng@Sun.COM 		    lunProps.productId);
149312161SJack.Meng@Sun.COM 		/*
149412161SJack.Meng@Sun.COM 		 * The lun is valid though the os Device Name is not.
149512161SJack.Meng@Sun.COM 		 * Give this information to users for judgement.
149612161SJack.Meng@Sun.COM 		 */
14977836SJohn.Forte@Sun.COM 		if (lunProps.imaProps.osDeviceNameValid == IMA_TRUE) {
14987836SJohn.Forte@Sun.COM 			(void) fprintf(stdout,
14997836SJohn.Forte@Sun.COM 			    gettext("\t     OS Device Name: %ws\n"),
15007836SJohn.Forte@Sun.COM 			    lunProps.imaProps.osDeviceName);
150112161SJack.Meng@Sun.COM 		} else {
150212161SJack.Meng@Sun.COM 			(void) fprintf(stdout,
150312161SJack.Meng@Sun.COM 			    gettext("\t     OS Device Name: Not"
150412161SJack.Meng@Sun.COM 			    " Available\n"));
15057836SJohn.Forte@Sun.COM 		}
15067836SJohn.Forte@Sun.COM 	}
15077836SJohn.Forte@Sun.COM }
15087836SJohn.Forte@Sun.COM 
15097836SJohn.Forte@Sun.COM /*
15107836SJohn.Forte@Sun.COM  * Retrieve CHAP secret from input
15117836SJohn.Forte@Sun.COM  */
15127836SJohn.Forte@Sun.COM static int
getSecret(char * secret,int * secretLen,int minSecretLen,int maxSecretLen)15137836SJohn.Forte@Sun.COM getSecret(char *secret, int *secretLen, int minSecretLen, int maxSecretLen)
15147836SJohn.Forte@Sun.COM {
15157836SJohn.Forte@Sun.COM 	char *chapSecret;
15167836SJohn.Forte@Sun.COM 
15177836SJohn.Forte@Sun.COM 	/* get password */
15187836SJohn.Forte@Sun.COM 	chapSecret = getpassphrase(gettext("Enter secret:"));
15197836SJohn.Forte@Sun.COM 
15209620SJack.Meng@Sun.COM 	if (chapSecret == NULL) {
15219620SJack.Meng@Sun.COM 		(void) fprintf(stderr, "%s: %s\n", cmdName,
15229620SJack.Meng@Sun.COM 		    gettext("Unable to get secret"));
15239620SJack.Meng@Sun.COM 		*secret = NULL;
15249620SJack.Meng@Sun.COM 		return (1);
15259620SJack.Meng@Sun.COM 	}
15269620SJack.Meng@Sun.COM 
15277836SJohn.Forte@Sun.COM 	if (strlen(chapSecret) > maxSecretLen) {
15287836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s %d\n", cmdName,
15297836SJohn.Forte@Sun.COM 		    gettext("secret too long, maximum length is"),
15307836SJohn.Forte@Sun.COM 		    maxSecretLen);
15317836SJohn.Forte@Sun.COM 		*secret = NULL;
15327836SJohn.Forte@Sun.COM 		return (1);
15337836SJohn.Forte@Sun.COM 	}
15347836SJohn.Forte@Sun.COM 
15357836SJohn.Forte@Sun.COM 	if (strlen(chapSecret) < minSecretLen) {
15367836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s %d\n", cmdName,
15377836SJohn.Forte@Sun.COM 		    gettext("secret too short, minimum length is"),
15387836SJohn.Forte@Sun.COM 		    minSecretLen);
15397836SJohn.Forte@Sun.COM 		*secret = NULL;
15407836SJohn.Forte@Sun.COM 		return (1);
15417836SJohn.Forte@Sun.COM 	}
15427836SJohn.Forte@Sun.COM 
15437836SJohn.Forte@Sun.COM 	(void) strcpy(secret, chapSecret);
15447836SJohn.Forte@Sun.COM 
15457836SJohn.Forte@Sun.COM 	chapSecret = getpassphrase(gettext("Re-enter secret:"));
15469620SJack.Meng@Sun.COM 
15479620SJack.Meng@Sun.COM 	if (chapSecret == NULL) {
15489620SJack.Meng@Sun.COM 		(void) fprintf(stderr, "%s: %s\n", cmdName,
15499620SJack.Meng@Sun.COM 		    gettext("Unable to get secret"));
15509620SJack.Meng@Sun.COM 		*secret = NULL;
15519620SJack.Meng@Sun.COM 		return (1);
15529620SJack.Meng@Sun.COM 	}
15539620SJack.Meng@Sun.COM 
15547836SJohn.Forte@Sun.COM 	if (strcmp(secret, chapSecret) != 0) {
15557836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s\n", cmdName,
15567836SJohn.Forte@Sun.COM 		    gettext("secrets do not match, secret not changed"));
15577836SJohn.Forte@Sun.COM 		*secret = NULL;
15587836SJohn.Forte@Sun.COM 		return (1);
15597836SJohn.Forte@Sun.COM 	}
15607836SJohn.Forte@Sun.COM 	*secretLen = strlen(chapSecret);
15617836SJohn.Forte@Sun.COM 	return (0);
15627836SJohn.Forte@Sun.COM }
15637836SJohn.Forte@Sun.COM 
15647836SJohn.Forte@Sun.COM /*
15657836SJohn.Forte@Sun.COM  * Lists the discovery attributes
15667836SJohn.Forte@Sun.COM  */
15677836SJohn.Forte@Sun.COM static int
listDiscovery(int * funcRet)15687836SJohn.Forte@Sun.COM listDiscovery(int *funcRet)
15697836SJohn.Forte@Sun.COM {
15707836SJohn.Forte@Sun.COM 	IMA_OID	initiatorOid;
15717836SJohn.Forte@Sun.COM 	IMA_DISCOVERY_PROPERTIES discProps;
15727836SJohn.Forte@Sun.COM 	int ret;
15737836SJohn.Forte@Sun.COM 	IMA_STATUS status;
15747836SJohn.Forte@Sun.COM 
15757836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
15767836SJohn.Forte@Sun.COM 
15777836SJohn.Forte@Sun.COM 
15787836SJohn.Forte@Sun.COM 	/* Find Sun initiator */
15797836SJohn.Forte@Sun.COM 	ret = sunInitiatorFind(&initiatorOid);
15807836SJohn.Forte@Sun.COM 	if (ret > 0) {
15817836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s\n",
15827836SJohn.Forte@Sun.COM 		    cmdName, gettext("no initiator found"));
15837836SJohn.Forte@Sun.COM 	}
15847836SJohn.Forte@Sun.COM 
15857836SJohn.Forte@Sun.COM 	if (ret != 0) {
15867836SJohn.Forte@Sun.COM 		return (ret);
15877836SJohn.Forte@Sun.COM 	}
15887836SJohn.Forte@Sun.COM 
15897836SJohn.Forte@Sun.COM 	/* Get discovery attributes from IMA */
15907836SJohn.Forte@Sun.COM 	status = IMA_GetDiscoveryProperties(initiatorOid, &discProps);
15917836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
15927836SJohn.Forte@Sun.COM 		printLibError(status);
15937836SJohn.Forte@Sun.COM 		*funcRet = 1;
15947836SJohn.Forte@Sun.COM 		return (ret);
15957836SJohn.Forte@Sun.COM 	}
15967836SJohn.Forte@Sun.COM 
15977836SJohn.Forte@Sun.COM 
15987836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "%s:\n", "Discovery");
15997836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "\tStatic: %s\n",
16007836SJohn.Forte@Sun.COM 	    discProps.staticDiscoveryEnabled == IMA_TRUE ? \
16017836SJohn.Forte@Sun.COM 	    gettext("enabled") : gettext("disabled"));
16027836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "\tSend Targets: %s\n",
16037836SJohn.Forte@Sun.COM 	    discProps.sendTargetsDiscoveryEnabled == IMA_TRUE ? \
16047836SJohn.Forte@Sun.COM 	    gettext("enabled") : gettext("disabled"));
16057836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "\tiSNS: %s\n",
16067836SJohn.Forte@Sun.COM 	    discProps.iSnsDiscoveryEnabled == IMA_TRUE ? \
16077836SJohn.Forte@Sun.COM 	    gettext("enabled") : gettext("disabled"));
16087836SJohn.Forte@Sun.COM 
16097836SJohn.Forte@Sun.COM 	return (0);
16107836SJohn.Forte@Sun.COM }
16117836SJohn.Forte@Sun.COM 
16127836SJohn.Forte@Sun.COM /*
16137836SJohn.Forte@Sun.COM  * Print all initiator node attributes
16147836SJohn.Forte@Sun.COM  */
16157836SJohn.Forte@Sun.COM static int
listNode(int * funcRet)16167836SJohn.Forte@Sun.COM listNode(int *funcRet)
16177836SJohn.Forte@Sun.COM {
16187836SJohn.Forte@Sun.COM 	IMA_OID	initiatorOid;
16197836SJohn.Forte@Sun.COM 	IMA_NODE_PROPERTIES nodeProps;
16207836SJohn.Forte@Sun.COM 	IMA_STATUS status;
16217836SJohn.Forte@Sun.COM 	int ret;
16227836SJohn.Forte@Sun.COM 	IMA_UINT maxEntries = MAX_AUTH_METHODS;
16237836SJohn.Forte@Sun.COM 	IMA_AUTHMETHOD	methodList[MAX_AUTH_METHODS];
16247836SJohn.Forte@Sun.COM 	SUN_IMA_RADIUS_CONFIG radiusConfig;
16257836SJohn.Forte@Sun.COM 	SUN_IMA_DIGEST_ALGORITHM_VALUE digestAlgorithms;
16267836SJohn.Forte@Sun.COM 	IMA_BOOL radiusAccess;
16277836SJohn.Forte@Sun.COM 
16287836SJohn.Forte@Sun.COM 	int i;
16297836SJohn.Forte@Sun.COM 
16307836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
16317836SJohn.Forte@Sun.COM 
16327836SJohn.Forte@Sun.COM 	ret = getNodeProps(&nodeProps);
16337836SJohn.Forte@Sun.COM 	if (ret != 0) {
16347836SJohn.Forte@Sun.COM 		return (ret);
16357836SJohn.Forte@Sun.COM 	}
16367836SJohn.Forte@Sun.COM 
16377836SJohn.Forte@Sun.COM 	if (nodeProps.nameValid == IMA_FALSE) {
16387836SJohn.Forte@Sun.COM 		return (INVALID_NODE_NAME);
16397836SJohn.Forte@Sun.COM 	}
16407836SJohn.Forte@Sun.COM 
16417836SJohn.Forte@Sun.COM 	/* Find Sun initiator */
16427836SJohn.Forte@Sun.COM 	ret = sunInitiatorFind(&initiatorOid);
16437836SJohn.Forte@Sun.COM 	if (ret > 0) {
16447836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s\n",
16457836SJohn.Forte@Sun.COM 		    cmdName, gettext("no initiator found"));
16467836SJohn.Forte@Sun.COM 	}
16477836SJohn.Forte@Sun.COM 
16487836SJohn.Forte@Sun.COM 	if (ret != 0) {
16497836SJohn.Forte@Sun.COM 		return (ret);
16507836SJohn.Forte@Sun.COM 	}
16517836SJohn.Forte@Sun.COM 	/* Begin output */
16527836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, gettext("%s: %ws\n"),
16537836SJohn.Forte@Sun.COM 	    gettext("Initiator node name"),
16547836SJohn.Forte@Sun.COM 	    nodeProps.name);
16557836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, gettext("Initiator node alias: "));
16567836SJohn.Forte@Sun.COM 	if (nodeProps.aliasValid == IMA_TRUE) {
16577836SJohn.Forte@Sun.COM 		(void) fprintf(stdout, gettext("%ws\n"), nodeProps.alias);
16587836SJohn.Forte@Sun.COM 	} else {
16597836SJohn.Forte@Sun.COM 		(void) fprintf(stdout, "%s\n", "-");
16607836SJohn.Forte@Sun.COM 	}
16617836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "\t%s:\n",
16627836SJohn.Forte@Sun.COM 	    gettext("Login Parameters (Default/Configured)"));
16637836SJohn.Forte@Sun.COM 
16647836SJohn.Forte@Sun.COM 	/* Get Digest configuration */
16657836SJohn.Forte@Sun.COM 	status = SUN_IMA_GetHeaderDigest(initiatorOid, &digestAlgorithms);
16667836SJohn.Forte@Sun.COM 	if (IMA_SUCCESS(status)) {
16677836SJohn.Forte@Sun.COM 		(void) fprintf(stdout, "\t\t%s: ", gettext("Header Digest"));
16687836SJohn.Forte@Sun.COM 		printDigestAlgorithm(&digestAlgorithms,
16697836SJohn.Forte@Sun.COM 		    PRINT_CONFIGURED_PARAMS);
16707836SJohn.Forte@Sun.COM 	} else {
16717836SJohn.Forte@Sun.COM 		printLibError(status);
16727836SJohn.Forte@Sun.COM 		*funcRet = 1;
16737836SJohn.Forte@Sun.COM 		return (ret);
16747836SJohn.Forte@Sun.COM 	}
16757836SJohn.Forte@Sun.COM 
16767836SJohn.Forte@Sun.COM 	status = SUN_IMA_GetDataDigest(initiatorOid, &digestAlgorithms);
16777836SJohn.Forte@Sun.COM 	if (IMA_SUCCESS(status)) {
16787836SJohn.Forte@Sun.COM 		(void) fprintf(stdout, "\t\t%s: ", gettext("Data Digest"));
16797836SJohn.Forte@Sun.COM 		printDigestAlgorithm(&digestAlgorithms,
16807836SJohn.Forte@Sun.COM 		    PRINT_CONFIGURED_PARAMS);
16817836SJohn.Forte@Sun.COM 	} else {
16827836SJohn.Forte@Sun.COM 		printLibError(status);
16837836SJohn.Forte@Sun.COM 		*funcRet = 1;
16847836SJohn.Forte@Sun.COM 		return (ret);
16857836SJohn.Forte@Sun.COM 	}
16867836SJohn.Forte@Sun.COM 
16877836SJohn.Forte@Sun.COM 	/* Get authentication type for this lhba */
16887836SJohn.Forte@Sun.COM 	status = IMA_GetInUseInitiatorAuthMethods(initiatorOid, &maxEntries,
16897836SJohn.Forte@Sun.COM 	    &methodList[0]);
16907836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "\t%s: ", gettext("Authentication Type"));
16917836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
16927836SJohn.Forte@Sun.COM 		/* No authentication method set - default is NONE */
16937836SJohn.Forte@Sun.COM 		(void) fprintf(stdout, gettext("NONE"));
16947836SJohn.Forte@Sun.COM 	} else {
16957836SJohn.Forte@Sun.COM 		for (i = 0; i < maxEntries; i++) {
16967836SJohn.Forte@Sun.COM 			if (i > 0) {
16977836SJohn.Forte@Sun.COM 				(void) fprintf(stdout, "|");
16987836SJohn.Forte@Sun.COM 			}
16997836SJohn.Forte@Sun.COM 			switch (methodList[i]) {
17007836SJohn.Forte@Sun.COM 				case IMA_AUTHMETHOD_NONE:
17017836SJohn.Forte@Sun.COM 					(void) fprintf(stdout, gettext("NONE"));
17027836SJohn.Forte@Sun.COM 					break;
17037836SJohn.Forte@Sun.COM 				case IMA_AUTHMETHOD_CHAP:
17047836SJohn.Forte@Sun.COM 					(void) fprintf(stdout, gettext("CHAP"));
17057836SJohn.Forte@Sun.COM 					listCHAPName(initiatorOid);
17067836SJohn.Forte@Sun.COM 					break;
17077836SJohn.Forte@Sun.COM 				default:
17087836SJohn.Forte@Sun.COM 					(void) fprintf(stdout,
17097836SJohn.Forte@Sun.COM 					    gettext("unknown type"));
17107836SJohn.Forte@Sun.COM 					break;
17117836SJohn.Forte@Sun.COM 			}
17127836SJohn.Forte@Sun.COM 		}
17137836SJohn.Forte@Sun.COM 	}
17147836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "\n");
17157836SJohn.Forte@Sun.COM 
17167836SJohn.Forte@Sun.COM 
17177836SJohn.Forte@Sun.COM 	/* Get RADIUS configuration */
17187836SJohn.Forte@Sun.COM 	status = SUN_IMA_GetInitiatorRadiusConfig(initiatorOid, &radiusConfig);
17197836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "\t%s: ", gettext("RADIUS Server"));
17207836SJohn.Forte@Sun.COM 	if (IMA_SUCCESS(status)) {
17217836SJohn.Forte@Sun.COM 		if (strlen(radiusConfig.hostnameIpAddress) > 0) {
17227836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "%s:%d",
17237836SJohn.Forte@Sun.COM 			    radiusConfig.hostnameIpAddress,
17247836SJohn.Forte@Sun.COM 			    radiusConfig.port);
17257836SJohn.Forte@Sun.COM 		} else {
17267836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "%s", gettext("NONE"));
17277836SJohn.Forte@Sun.COM 		}
17287836SJohn.Forte@Sun.COM 	} else {
17297836SJohn.Forte@Sun.COM 		(void) fprintf(stdout, "%s", gettext("NONE"));
17307836SJohn.Forte@Sun.COM 	}
17317836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "\n");
17327836SJohn.Forte@Sun.COM 
17337836SJohn.Forte@Sun.COM 	status = SUN_IMA_GetInitiatorRadiusAccess(initiatorOid,
17347836SJohn.Forte@Sun.COM 	    &radiusAccess);
17357836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "\t%s: ", gettext("RADIUS Access"));
17367836SJohn.Forte@Sun.COM 	if (IMA_SUCCESS(status)) {
17377836SJohn.Forte@Sun.COM 		if (radiusAccess == IMA_TRUE) {
17387836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "%s", gettext("enabled"));
17397836SJohn.Forte@Sun.COM 		} else {
17407836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "%s", gettext("disabled"));
17417836SJohn.Forte@Sun.COM 		}
17427836SJohn.Forte@Sun.COM 	} else if (status == IMA_ERROR_OBJECT_NOT_FOUND) {
17437836SJohn.Forte@Sun.COM 		(void) fprintf(stdout, "%s", gettext("disabled"));
17447836SJohn.Forte@Sun.COM 	} else {
17457836SJohn.Forte@Sun.COM 		(void) fprintf(stdout, "%s", gettext("unknown"));
17467836SJohn.Forte@Sun.COM 	}
17477836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "\n");
17487836SJohn.Forte@Sun.COM 
174910156SZhang.Yi@Sun.COM 	/* print tunable parameters information. */
175010156SZhang.Yi@Sun.COM 	ret = printTunableParameters(initiatorOid);
175110156SZhang.Yi@Sun.COM 
17527836SJohn.Forte@Sun.COM 	/* print configured session information. */
17537836SJohn.Forte@Sun.COM 	ret = printConfiguredSessions(initiatorOid);
17547836SJohn.Forte@Sun.COM 
17557836SJohn.Forte@Sun.COM 	return (ret);
17567836SJohn.Forte@Sun.COM }
17577836SJohn.Forte@Sun.COM 
17587836SJohn.Forte@Sun.COM /*
17597836SJohn.Forte@Sun.COM  * Print discovery addresses
17607836SJohn.Forte@Sun.COM  */
17617836SJohn.Forte@Sun.COM static int
listDiscoveryAddress(int objectLen,char * objects[],cmdOptions_t * options,int * funcRet)17627836SJohn.Forte@Sun.COM listDiscoveryAddress(int objectLen, char *objects[], cmdOptions_t *options,
17637836SJohn.Forte@Sun.COM     int *funcRet)
17647836SJohn.Forte@Sun.COM {
17657836SJohn.Forte@Sun.COM 	IMA_OID	initiatorOid;
17667836SJohn.Forte@Sun.COM 	SUN_IMA_DISC_ADDR_PROP_LIST *discoveryAddressPropertiesList;
17677836SJohn.Forte@Sun.COM 	IMA_DISCOVERY_ADDRESS_PROPERTIES discAddrProps;
17687836SJohn.Forte@Sun.COM 	IMA_TARGET_ADDRESS address;
17697836SJohn.Forte@Sun.COM 	SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES *pList;
17707836SJohn.Forte@Sun.COM 	IMA_STATUS status;
17717836SJohn.Forte@Sun.COM 	wchar_t wcInputObject[MAX_ADDRESS_LEN + 1];
17727836SJohn.Forte@Sun.COM 	int ret;
17737836SJohn.Forte@Sun.COM 	boolean_t object = B_FALSE;
17747836SJohn.Forte@Sun.COM 	int outerLoop;
17757836SJohn.Forte@Sun.COM 	boolean_t found;
17767836SJohn.Forte@Sun.COM 	boolean_t verbose = B_FALSE;
17777836SJohn.Forte@Sun.COM 	int i, j;
17787836SJohn.Forte@Sun.COM 	cmdOptions_t *optionList = options;
17797836SJohn.Forte@Sun.COM 	char sAddr[SUN_IMA_IP_ADDRESS_PORT_LEN];
17807836SJohn.Forte@Sun.COM 
17817836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
17827836SJohn.Forte@Sun.COM 
17837836SJohn.Forte@Sun.COM 	/* Find Sun initiator */
17847836SJohn.Forte@Sun.COM 	ret = sunInitiatorFind(&initiatorOid);
17857836SJohn.Forte@Sun.COM 	if (ret > 0) {
17867836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s\n",
17877836SJohn.Forte@Sun.COM 		    cmdName, gettext("no initiator found"));
17887836SJohn.Forte@Sun.COM 	}
17897836SJohn.Forte@Sun.COM 
17907836SJohn.Forte@Sun.COM 	if (ret != 0) {
17917836SJohn.Forte@Sun.COM 		return (ret);
17927836SJohn.Forte@Sun.COM 	}
17937836SJohn.Forte@Sun.COM 
17947836SJohn.Forte@Sun.COM 	for (; optionList->optval; optionList++) {
17957836SJohn.Forte@Sun.COM 		switch (optionList->optval) {
17967836SJohn.Forte@Sun.COM 			case 'v':
17977836SJohn.Forte@Sun.COM 				verbose = B_TRUE;
17987836SJohn.Forte@Sun.COM 				break;
17997836SJohn.Forte@Sun.COM 			default:
18007836SJohn.Forte@Sun.COM 				(void) fprintf(stderr, "%s: %c: %s\n",
18017836SJohn.Forte@Sun.COM 				    cmdName, optionList->optval,
18027836SJohn.Forte@Sun.COM 				    gettext("unknown option"));
18037836SJohn.Forte@Sun.COM 				return (1);
18047836SJohn.Forte@Sun.COM 		}
18057836SJohn.Forte@Sun.COM 	}
18067836SJohn.Forte@Sun.COM 
18077836SJohn.Forte@Sun.COM 	/*
18087836SJohn.Forte@Sun.COM 	 * If there are multiple objects, execute outer 'for' loop that
18097836SJohn.Forte@Sun.COM 	 * many times for each target detail, otherwise, execute it only
18107836SJohn.Forte@Sun.COM 	 * once with summaries only
18117836SJohn.Forte@Sun.COM 	 */
18127836SJohn.Forte@Sun.COM 	if (objectLen > 0) {
18137836SJohn.Forte@Sun.COM 		object = B_TRUE;
18147836SJohn.Forte@Sun.COM 		outerLoop = objectLen;
18157836SJohn.Forte@Sun.COM 	} else {
18167836SJohn.Forte@Sun.COM 		object = B_FALSE;
18177836SJohn.Forte@Sun.COM 		outerLoop = 1;
18187836SJohn.Forte@Sun.COM 	}
18197836SJohn.Forte@Sun.COM 
18207836SJohn.Forte@Sun.COM 	status = SUN_IMA_GetDiscoveryAddressPropertiesList(
18217836SJohn.Forte@Sun.COM 	    &discoveryAddressPropertiesList);
18227836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
18237836SJohn.Forte@Sun.COM 		printLibError(status);
18247836SJohn.Forte@Sun.COM 		*funcRet = 1;
18257836SJohn.Forte@Sun.COM 		return (ret);
18267836SJohn.Forte@Sun.COM 	}
18277836SJohn.Forte@Sun.COM 
18287836SJohn.Forte@Sun.COM 	for (i = 0; i < outerLoop; i++) {
18297836SJohn.Forte@Sun.COM 		if (object) {
18307836SJohn.Forte@Sun.COM 			/* initialize */
18317836SJohn.Forte@Sun.COM 			(void) memset(&wcInputObject[0], 0,
18327836SJohn.Forte@Sun.COM 			    sizeof (wcInputObject));
18337836SJohn.Forte@Sun.COM 			(void) memset(&address, 0, sizeof (address));
18347836SJohn.Forte@Sun.COM 			if (mbstowcs(wcInputObject, objects[i],
18357836SJohn.Forte@Sun.COM 			    (MAX_ADDRESS_LEN + 1)) == (size_t)-1) {
18367836SJohn.Forte@Sun.COM 				(void) fprintf(stderr, "%s: %s\n",
18377836SJohn.Forte@Sun.COM 				    cmdName,
18387836SJohn.Forte@Sun.COM 				    gettext("conversion error"));
18397836SJohn.Forte@Sun.COM 				ret = 1;
18407836SJohn.Forte@Sun.COM 				continue;
18417836SJohn.Forte@Sun.COM 			}
18427836SJohn.Forte@Sun.COM 
18437836SJohn.Forte@Sun.COM 			/*
18447836SJohn.Forte@Sun.COM 			 * if one or more objects were input,
18457836SJohn.Forte@Sun.COM 			 * get the values
18467836SJohn.Forte@Sun.COM 			 */
18477836SJohn.Forte@Sun.COM 			if (getTargetAddress(DISCOVERY_ADDRESS,
18487836SJohn.Forte@Sun.COM 			    objects[i], &address) != 0) {
18497836SJohn.Forte@Sun.COM 				ret = 1;
18507836SJohn.Forte@Sun.COM 				continue;
18517836SJohn.Forte@Sun.COM 			}
18527836SJohn.Forte@Sun.COM 		}
18537836SJohn.Forte@Sun.COM 		for (found = B_FALSE, j = 0;
18547836SJohn.Forte@Sun.COM 		    j < discoveryAddressPropertiesList->discAddrCount;
18557836SJohn.Forte@Sun.COM 		    j++) {
18567836SJohn.Forte@Sun.COM 			discAddrProps =
18577836SJohn.Forte@Sun.COM 			    discoveryAddressPropertiesList->props[j];
18587836SJohn.Forte@Sun.COM 
18597836SJohn.Forte@Sun.COM 			/*
18607836SJohn.Forte@Sun.COM 			 * Compare the discovery address with the input if
18617836SJohn.Forte@Sun.COM 			 * one was input
18627836SJohn.Forte@Sun.COM 			 */
18637836SJohn.Forte@Sun.COM 			if (object &&
18647836SJohn.Forte@Sun.COM 			    ipAddressesEqual(discAddrProps.discoveryAddress,
18657836SJohn.Forte@Sun.COM 			    address) && (discAddrProps.discoveryAddress.
18667836SJohn.Forte@Sun.COM 			    portNumber == address.portNumber)) {
18677836SJohn.Forte@Sun.COM 				found = B_TRUE;
18687836SJohn.Forte@Sun.COM 			}
18697836SJohn.Forte@Sun.COM 
18707836SJohn.Forte@Sun.COM 			if (!object || found) {
18717836SJohn.Forte@Sun.COM 				/* Print summary - always */
18727836SJohn.Forte@Sun.COM 				if (discAddrProps.discoveryAddress.
18737836SJohn.Forte@Sun.COM 				    hostnameIpAddress.id.ipAddress.
18747836SJohn.Forte@Sun.COM 				    ipv4Address) {
18757836SJohn.Forte@Sun.COM 					(void) inet_ntop(AF_INET, discAddrProps.
18767836SJohn.Forte@Sun.COM 					    discoveryAddress.hostnameIpAddress.
18777836SJohn.Forte@Sun.COM 					    id.ipAddress.ipAddress, sAddr,
18787836SJohn.Forte@Sun.COM 					    sizeof (sAddr));
18797836SJohn.Forte@Sun.COM 					(void) fprintf(stdout,
18807836SJohn.Forte@Sun.COM 					    "Discovery Address: %s:%u\n",
18817836SJohn.Forte@Sun.COM 					    sAddr, discAddrProps.
18827836SJohn.Forte@Sun.COM 					    discoveryAddress.portNumber);
18837836SJohn.Forte@Sun.COM 				} else {
18847836SJohn.Forte@Sun.COM 					(void) inet_ntop(AF_INET6,
18857836SJohn.Forte@Sun.COM 					    discAddrProps.
18867836SJohn.Forte@Sun.COM 					    discoveryAddress.hostnameIpAddress.
18877836SJohn.Forte@Sun.COM 					    id.ipAddress.ipAddress, sAddr,
18887836SJohn.Forte@Sun.COM 					    sizeof (sAddr));
18897836SJohn.Forte@Sun.COM 					(void) fprintf(stdout,
18907836SJohn.Forte@Sun.COM 					    "DiscoveryAddress: [%s]:%u\n",
18917836SJohn.Forte@Sun.COM 					    sAddr, discAddrProps.
18927836SJohn.Forte@Sun.COM 					    discoveryAddress.portNumber);
18937836SJohn.Forte@Sun.COM 				}
18947836SJohn.Forte@Sun.COM 			}
18957836SJohn.Forte@Sun.COM 
18967836SJohn.Forte@Sun.COM 			if ((!object || found) && verbose) {
18977836SJohn.Forte@Sun.COM 				IMA_NODE_PROPERTIES nodeProps;
18987836SJohn.Forte@Sun.COM 
18997836SJohn.Forte@Sun.COM 				if (getNodeProps(&nodeProps) != 0) {
19007836SJohn.Forte@Sun.COM 					break;
19017836SJohn.Forte@Sun.COM 				}
19027836SJohn.Forte@Sun.COM 
19037836SJohn.Forte@Sun.COM 				/*
19047836SJohn.Forte@Sun.COM 				 * Issue sendTargets only when an addr is
19057836SJohn.Forte@Sun.COM 				 * specified.
19067836SJohn.Forte@Sun.COM 				 */
19077836SJohn.Forte@Sun.COM 				status = SUN_IMA_SendTargets(nodeProps.name,
19087836SJohn.Forte@Sun.COM 				    discAddrProps.discoveryAddress, &pList);
19097836SJohn.Forte@Sun.COM 				if (!IMA_SUCCESS(status)) {
19107836SJohn.Forte@Sun.COM 					(void) fprintf(stderr, "%s\n",
19117836SJohn.Forte@Sun.COM 					    gettext("\tUnable to get "\
19127836SJohn.Forte@Sun.COM 					    "targets."));
19137836SJohn.Forte@Sun.COM 					*funcRet = 1;
19147836SJohn.Forte@Sun.COM 					continue;
19157836SJohn.Forte@Sun.COM 				}
19167836SJohn.Forte@Sun.COM 				printSendTargets(pList);
19177836SJohn.Forte@Sun.COM 			}
19187836SJohn.Forte@Sun.COM 
19197836SJohn.Forte@Sun.COM 			if (found) {
19207836SJohn.Forte@Sun.COM 				/* we found the discovery address - break */
19217836SJohn.Forte@Sun.COM 				break;
19227836SJohn.Forte@Sun.COM 			}
19237836SJohn.Forte@Sun.COM 		}
19247836SJohn.Forte@Sun.COM 		/*
19257836SJohn.Forte@Sun.COM 		 * There was an object entered but we didn't
19267836SJohn.Forte@Sun.COM 		 * find it.
19277836SJohn.Forte@Sun.COM 		 */
19287836SJohn.Forte@Sun.COM 		if (object && !found) {
19297836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "%s: %s\n",
19307836SJohn.Forte@Sun.COM 			    objects[i], gettext("not found"));
19317836SJohn.Forte@Sun.COM 		}
19327836SJohn.Forte@Sun.COM 	}
19337836SJohn.Forte@Sun.COM 	return (ret);
19347836SJohn.Forte@Sun.COM }
19357836SJohn.Forte@Sun.COM 
19367836SJohn.Forte@Sun.COM /*
19377836SJohn.Forte@Sun.COM  * Print ISNS Server addresses
19387836SJohn.Forte@Sun.COM  */
19397836SJohn.Forte@Sun.COM static int
listISNSServerAddress(int objectLen,char * objects[],cmdOptions_t * options,int * funcRet)19407836SJohn.Forte@Sun.COM listISNSServerAddress(int objectLen, char *objects[], cmdOptions_t *options,
19417836SJohn.Forte@Sun.COM     int *funcRet)
19427836SJohn.Forte@Sun.COM {
19437836SJohn.Forte@Sun.COM 	IMA_OID	initiatorOid;
19447836SJohn.Forte@Sun.COM 	SUN_IMA_DISC_ADDR_PROP_LIST	    *discoveryAddressPropertiesList;
19457836SJohn.Forte@Sun.COM 	IMA_DISCOVERY_ADDRESS_PROPERTIES discAddrProps;
19467836SJohn.Forte@Sun.COM 	IMA_TARGET_ADDRESS address;
19477836SJohn.Forte@Sun.COM 	SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES *pList;
19487836SJohn.Forte@Sun.COM 	IMA_STATUS status;
19497836SJohn.Forte@Sun.COM 	wchar_t wcInputObject[MAX_ADDRESS_LEN + 1];
19507836SJohn.Forte@Sun.COM 	int ret;
19517836SJohn.Forte@Sun.COM 	boolean_t object = B_FALSE;
19527836SJohn.Forte@Sun.COM 	int outerLoop;
19537836SJohn.Forte@Sun.COM 	boolean_t found;
19547836SJohn.Forte@Sun.COM 	boolean_t showTarget = B_FALSE;
19557836SJohn.Forte@Sun.COM 	int i, j;
19567836SJohn.Forte@Sun.COM 	cmdOptions_t *optionList = options;
19577836SJohn.Forte@Sun.COM 	char sAddr[SUN_IMA_IP_ADDRESS_PORT_LEN];
19587836SJohn.Forte@Sun.COM 
19597836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
19607836SJohn.Forte@Sun.COM 
19617836SJohn.Forte@Sun.COM 	/* Find Sun initiator */
19627836SJohn.Forte@Sun.COM 	ret = sunInitiatorFind(&initiatorOid);
19637836SJohn.Forte@Sun.COM 	if (ret > 0) {
19647836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s\n",
19657836SJohn.Forte@Sun.COM 		    cmdName, gettext("no initiator found"));
19667836SJohn.Forte@Sun.COM 	}
19677836SJohn.Forte@Sun.COM 
19687836SJohn.Forte@Sun.COM 	if (ret != 0) {
19697836SJohn.Forte@Sun.COM 		return (ret);
19707836SJohn.Forte@Sun.COM 	}
19717836SJohn.Forte@Sun.COM 
19727836SJohn.Forte@Sun.COM 	for (; optionList->optval; optionList++) {
19737836SJohn.Forte@Sun.COM 		switch (optionList->optval) {
19747836SJohn.Forte@Sun.COM 			case 'v':
19757836SJohn.Forte@Sun.COM 				showTarget = B_TRUE;
19767836SJohn.Forte@Sun.COM 				break;
19777836SJohn.Forte@Sun.COM 			default:
19787836SJohn.Forte@Sun.COM 				(void) fprintf(stderr, "%s: %c: %s\n",
19797836SJohn.Forte@Sun.COM 				    cmdName, optionList->optval,
19807836SJohn.Forte@Sun.COM 				    gettext("unknown option"));
19817836SJohn.Forte@Sun.COM 				return (1);
19827836SJohn.Forte@Sun.COM 		}
19837836SJohn.Forte@Sun.COM 	}
19847836SJohn.Forte@Sun.COM 
19857836SJohn.Forte@Sun.COM 	/*
19867836SJohn.Forte@Sun.COM 	 * If there are multiple objects, execute outer 'for' loop that
19877836SJohn.Forte@Sun.COM 	 * many times for each target detail, otherwise, execute it only
19887836SJohn.Forte@Sun.COM 	 * once with summaries only
19897836SJohn.Forte@Sun.COM 	 */
19907836SJohn.Forte@Sun.COM 	if (objectLen > 0) {
19917836SJohn.Forte@Sun.COM 		object = B_TRUE;
19927836SJohn.Forte@Sun.COM 		outerLoop = objectLen;
19937836SJohn.Forte@Sun.COM 	} else {
19947836SJohn.Forte@Sun.COM 		object = B_FALSE;
19957836SJohn.Forte@Sun.COM 		outerLoop = 1;
19967836SJohn.Forte@Sun.COM 	}
19977836SJohn.Forte@Sun.COM 
19987836SJohn.Forte@Sun.COM 	status = SUN_IMA_GetISNSServerAddressPropertiesList(
19997836SJohn.Forte@Sun.COM 	    &discoveryAddressPropertiesList);
20007836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
20017836SJohn.Forte@Sun.COM 		printLibError(status);
20027836SJohn.Forte@Sun.COM 		*funcRet = 1;
20037836SJohn.Forte@Sun.COM 		return (ret);
20047836SJohn.Forte@Sun.COM 	}
20057836SJohn.Forte@Sun.COM 
20067836SJohn.Forte@Sun.COM 	for (i = 0; i < outerLoop; i++) {
20077836SJohn.Forte@Sun.COM 		if (object) {
20087836SJohn.Forte@Sun.COM 			/* initialize */
20097836SJohn.Forte@Sun.COM 			(void) memset(&wcInputObject[0], 0,
20107836SJohn.Forte@Sun.COM 			    sizeof (wcInputObject));
20117836SJohn.Forte@Sun.COM 			(void) memset(&address, 0, sizeof (address));
20127836SJohn.Forte@Sun.COM 			if (mbstowcs(wcInputObject, objects[i],
20137836SJohn.Forte@Sun.COM 			    (MAX_ADDRESS_LEN + 1)) == (size_t)-1) {
20147836SJohn.Forte@Sun.COM 				(void) fprintf(stderr, "%s: %s\n",
20157836SJohn.Forte@Sun.COM 				    cmdName,
20167836SJohn.Forte@Sun.COM 				    gettext("conversion error"));
20177836SJohn.Forte@Sun.COM 				ret = 1;
20187836SJohn.Forte@Sun.COM 				continue;
20197836SJohn.Forte@Sun.COM 			}
20207836SJohn.Forte@Sun.COM 
20217836SJohn.Forte@Sun.COM 			/*
20227836SJohn.Forte@Sun.COM 			 * if one or more objects were input,
20237836SJohn.Forte@Sun.COM 			 * get the values
20247836SJohn.Forte@Sun.COM 			 */
20257836SJohn.Forte@Sun.COM 			if (getTargetAddress(ISNS_SERVER_ADDRESS,
20267836SJohn.Forte@Sun.COM 			    objects[i], &address) != 0) {
20277836SJohn.Forte@Sun.COM 				ret = 1;
20287836SJohn.Forte@Sun.COM 				continue;
20297836SJohn.Forte@Sun.COM 			}
20307836SJohn.Forte@Sun.COM 		}
20317836SJohn.Forte@Sun.COM 		for (found = B_FALSE, j = 0;
20327836SJohn.Forte@Sun.COM 		    j < discoveryAddressPropertiesList->discAddrCount;
20337836SJohn.Forte@Sun.COM 		    j++) {
20347836SJohn.Forte@Sun.COM 			discAddrProps =
20357836SJohn.Forte@Sun.COM 			    discoveryAddressPropertiesList->props[j];
20367836SJohn.Forte@Sun.COM 
20377836SJohn.Forte@Sun.COM 			/*
20387836SJohn.Forte@Sun.COM 			 * Compare the discovery address with the input if
20397836SJohn.Forte@Sun.COM 			 * one was input
20407836SJohn.Forte@Sun.COM 			 */
20417836SJohn.Forte@Sun.COM 			if (object &&
20427836SJohn.Forte@Sun.COM 			    ipAddressesEqual(discAddrProps.discoveryAddress,
20437836SJohn.Forte@Sun.COM 			    address) &&
20447836SJohn.Forte@Sun.COM 			    (discAddrProps.discoveryAddress.portNumber ==
20457836SJohn.Forte@Sun.COM 			    address.portNumber)) {
20467836SJohn.Forte@Sun.COM 				found = B_TRUE;
20477836SJohn.Forte@Sun.COM 			}
20487836SJohn.Forte@Sun.COM 
20497836SJohn.Forte@Sun.COM 			if (!object || found) {
20507836SJohn.Forte@Sun.COM 				/* Print summary - always */
20517836SJohn.Forte@Sun.COM 				if (discAddrProps.discoveryAddress.
20527836SJohn.Forte@Sun.COM 				    hostnameIpAddress.id.ipAddress.
20537836SJohn.Forte@Sun.COM 				    ipv4Address) {
20547836SJohn.Forte@Sun.COM 					(void) inet_ntop(AF_INET, discAddrProps.
20557836SJohn.Forte@Sun.COM 					    discoveryAddress.hostnameIpAddress.
20567836SJohn.Forte@Sun.COM 					    id.ipAddress.ipAddress, sAddr,
20577836SJohn.Forte@Sun.COM 					    sizeof (sAddr));
20587836SJohn.Forte@Sun.COM 				} else {
20597836SJohn.Forte@Sun.COM 					(void) inet_ntop(AF_INET6,
20607836SJohn.Forte@Sun.COM 					    discAddrProps.
20617836SJohn.Forte@Sun.COM 					    discoveryAddress.hostnameIpAddress.
20627836SJohn.Forte@Sun.COM 					    id.ipAddress.ipAddress, sAddr,
20637836SJohn.Forte@Sun.COM 					    sizeof (sAddr));
20647836SJohn.Forte@Sun.COM 				}
20657836SJohn.Forte@Sun.COM 				(void) fprintf(stdout,
20667836SJohn.Forte@Sun.COM 				    "iSNS Server IP Address: %s:%u\n",
20677836SJohn.Forte@Sun.COM 				    sAddr,
20687836SJohn.Forte@Sun.COM 				    discAddrProps.discoveryAddress.portNumber);
20697836SJohn.Forte@Sun.COM 			}
20707836SJohn.Forte@Sun.COM 
20717836SJohn.Forte@Sun.COM 			if ((!object || found) && showTarget) {
20727836SJohn.Forte@Sun.COM 				IMA_NODE_PROPERTIES nodeProps;
20737836SJohn.Forte@Sun.COM 
20747836SJohn.Forte@Sun.COM 				if (getNodeProps(&nodeProps) != 0) {
20757836SJohn.Forte@Sun.COM 					break;
20767836SJohn.Forte@Sun.COM 				}
20777836SJohn.Forte@Sun.COM 
20787836SJohn.Forte@Sun.COM 				/*
20797836SJohn.Forte@Sun.COM 				 * Issue sendTargets only when an addr is
20807836SJohn.Forte@Sun.COM 				 * specified.
20817836SJohn.Forte@Sun.COM 				 */
20827836SJohn.Forte@Sun.COM 				status = SUN_IMA_RetrieveISNSServerTargets(
20837836SJohn.Forte@Sun.COM 				    discAddrProps.discoveryAddress,
20847836SJohn.Forte@Sun.COM 				    &pList);
20857836SJohn.Forte@Sun.COM 				if (!IMA_SUCCESS(status)) {
20867836SJohn.Forte@Sun.COM 					/*
20877836SJohn.Forte@Sun.COM 					 * Check if the discovery mode is
20887836SJohn.Forte@Sun.COM 					 * disabled.
20897836SJohn.Forte@Sun.COM 					 */
20907836SJohn.Forte@Sun.COM 					if (status ==
20917836SJohn.Forte@Sun.COM 					    IMA_ERROR_OBJECT_NOT_FOUND) {
20927836SJohn.Forte@Sun.COM 						(void) fprintf(stderr, "%s\n",
20937836SJohn.Forte@Sun.COM 						    gettext("\tiSNS "\
20947836SJohn.Forte@Sun.COM 						    "discovery "\
20957836SJohn.Forte@Sun.COM 						    "mode "\
20967836SJohn.Forte@Sun.COM 						    "disabled. "\
20977836SJohn.Forte@Sun.COM 						    "No targets "\
20987836SJohn.Forte@Sun.COM 						    "to report."));
20997836SJohn.Forte@Sun.COM 
21007836SJohn.Forte@Sun.COM 					} else {
21017836SJohn.Forte@Sun.COM 						(void) fprintf(stderr, "%s\n",
21027836SJohn.Forte@Sun.COM 						    gettext("\tUnable "\
21037836SJohn.Forte@Sun.COM 						    "to get "\
21047836SJohn.Forte@Sun.COM 						    "targets."));
21057836SJohn.Forte@Sun.COM 					}
21067836SJohn.Forte@Sun.COM 					continue;
21077836SJohn.Forte@Sun.COM 				}
21087836SJohn.Forte@Sun.COM 				printSendTargets(pList);
21097836SJohn.Forte@Sun.COM 			}
21107836SJohn.Forte@Sun.COM 
21117836SJohn.Forte@Sun.COM 			if (found) {
21127836SJohn.Forte@Sun.COM 				/* we found the discovery address - break */
21137836SJohn.Forte@Sun.COM 				break;
21147836SJohn.Forte@Sun.COM 			}
21157836SJohn.Forte@Sun.COM 		}
21167836SJohn.Forte@Sun.COM 		/*
21177836SJohn.Forte@Sun.COM 		 * There was an object entered but we didn't
21187836SJohn.Forte@Sun.COM 		 * find it.
21197836SJohn.Forte@Sun.COM 		 */
21207836SJohn.Forte@Sun.COM 		if (object && !found) {
21217836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "%s: %s\n",
21227836SJohn.Forte@Sun.COM 			    objects[i], gettext("not found"));
21237836SJohn.Forte@Sun.COM 		}
21247836SJohn.Forte@Sun.COM 	}
21257836SJohn.Forte@Sun.COM 	return (ret);
21267836SJohn.Forte@Sun.COM }
21277836SJohn.Forte@Sun.COM 
21287836SJohn.Forte@Sun.COM /*
21297836SJohn.Forte@Sun.COM  * Print static configuration targets
21307836SJohn.Forte@Sun.COM  */
21317836SJohn.Forte@Sun.COM static int
listStaticConfig(int operandLen,char * operand[],int * funcRet)21327836SJohn.Forte@Sun.COM listStaticConfig(int operandLen, char *operand[], int *funcRet)
21337836SJohn.Forte@Sun.COM {
21347836SJohn.Forte@Sun.COM 	IMA_STATUS status;
21357836SJohn.Forte@Sun.COM 	IMA_OID	initiatorOid;
21367836SJohn.Forte@Sun.COM 	IMA_OID_LIST *staticTargetList;
21377836SJohn.Forte@Sun.COM 	SUN_IMA_STATIC_TARGET_PROPERTIES staticTargetProps;
21387836SJohn.Forte@Sun.COM 	wchar_t staticTargetName[MAX_ISCSI_NAME_LEN + 1];
21397836SJohn.Forte@Sun.COM 	wchar_t staticTargetAddress[SUN_IMA_IP_ADDRESS_PORT_LEN];
21407836SJohn.Forte@Sun.COM 	wchar_t wcCol;
21417836SJohn.Forte@Sun.COM 	char sAddr[SUN_IMA_IP_ADDRESS_PORT_LEN];
21427836SJohn.Forte@Sun.COM 	int ret;
21437836SJohn.Forte@Sun.COM 	boolean_t object = B_FALSE;
21447836SJohn.Forte@Sun.COM 	int outerLoop;
21457836SJohn.Forte@Sun.COM 	boolean_t found; /* B_TRUE if a target name is found */
21467836SJohn.Forte@Sun.COM 	boolean_t matched; /* B_TRUE if a specific target is found */
21477836SJohn.Forte@Sun.COM 	boolean_t targetAddressSpecified = B_FALSE;
21487836SJohn.Forte@Sun.COM 	boolean_t tpgtSpecified = B_FALSE;
21497836SJohn.Forte@Sun.COM 	boolean_t isIpv6;
21507836SJohn.Forte@Sun.COM 	int i, j;
21517836SJohn.Forte@Sun.COM 	IMA_UINT16 port = 0;
21527836SJohn.Forte@Sun.COM 	IMA_UINT16 tpgt = 0;
21537836SJohn.Forte@Sun.COM 	char tmpStr[SUN_IMA_IP_ADDRESS_PORT_LEN];
21547836SJohn.Forte@Sun.COM 	wchar_t tmpTargetAddress[SUN_IMA_IP_ADDRESS_PORT_LEN];
21557836SJohn.Forte@Sun.COM 
21567836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
21577836SJohn.Forte@Sun.COM 
21587836SJohn.Forte@Sun.COM 	/* Find Sun initiator */
21597836SJohn.Forte@Sun.COM 	ret = sunInitiatorFind(&initiatorOid);
21607836SJohn.Forte@Sun.COM 	if (ret > 0) {
21617836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s\n",
21627836SJohn.Forte@Sun.COM 		    cmdName, gettext("no initiator found"));
21637836SJohn.Forte@Sun.COM 	}
21647836SJohn.Forte@Sun.COM 
21657836SJohn.Forte@Sun.COM 	if (ret != 0) {
21667836SJohn.Forte@Sun.COM 		return (ret);
21677836SJohn.Forte@Sun.COM 	}
21687836SJohn.Forte@Sun.COM 
21697836SJohn.Forte@Sun.COM 	/*
21707836SJohn.Forte@Sun.COM 	 * If there are multiple objects, execute outer 'for' loop that
21717836SJohn.Forte@Sun.COM 	 * many times for each static config detail, otherwise, execute it only
21727836SJohn.Forte@Sun.COM 	 * once with summaries only
21737836SJohn.Forte@Sun.COM 	 */
21747836SJohn.Forte@Sun.COM 	if (operandLen > 0) {
21757836SJohn.Forte@Sun.COM 		object = B_TRUE;
21767836SJohn.Forte@Sun.COM 		outerLoop = operandLen;
21777836SJohn.Forte@Sun.COM 	} else {
21787836SJohn.Forte@Sun.COM 		object = B_FALSE;
21797836SJohn.Forte@Sun.COM 		outerLoop = 1;
21807836SJohn.Forte@Sun.COM 	}
21817836SJohn.Forte@Sun.COM 
21827836SJohn.Forte@Sun.COM 	/* convert ':' to wide char for wchar string search */
21837836SJohn.Forte@Sun.COM 	if (mbtowc(&wcCol, ":", sizeof (wcCol)) == -1) {
21847836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s\n",
21857836SJohn.Forte@Sun.COM 		    cmdName, gettext("conversion error"));
21867836SJohn.Forte@Sun.COM 		return (1);
21877836SJohn.Forte@Sun.COM 	}
21887836SJohn.Forte@Sun.COM 
21897836SJohn.Forte@Sun.COM 	status = IMA_GetStaticDiscoveryTargetOidList(initiatorOid,
21907836SJohn.Forte@Sun.COM 	    &staticTargetList);
21917836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
21927836SJohn.Forte@Sun.COM 		printLibError(status);
21937836SJohn.Forte@Sun.COM 		*funcRet = 1;
21947836SJohn.Forte@Sun.COM 		return (ret);
21957836SJohn.Forte@Sun.COM 	}
21967836SJohn.Forte@Sun.COM 
21977836SJohn.Forte@Sun.COM 	for (i = 0; i < outerLoop; i++) {
21987836SJohn.Forte@Sun.COM 		if (object) {
21997836SJohn.Forte@Sun.COM 			if (parseTarget(operand[i],
22007836SJohn.Forte@Sun.COM 			    &staticTargetName[0],
22017836SJohn.Forte@Sun.COM 			    MAX_ISCSI_NAME_LEN + 1,
22027836SJohn.Forte@Sun.COM 			    &targetAddressSpecified,
22037836SJohn.Forte@Sun.COM 			    &staticTargetAddress[0],
22047836SJohn.Forte@Sun.COM 			    SUN_IMA_IP_ADDRESS_PORT_LEN,
22057836SJohn.Forte@Sun.COM 			    &port,
22067836SJohn.Forte@Sun.COM 			    &tpgtSpecified,
22077836SJohn.Forte@Sun.COM 			    &tpgt,
22087836SJohn.Forte@Sun.COM 			    &isIpv6) != PARSE_TARGET_OK) {
22097836SJohn.Forte@Sun.COM 				ret = 1;
22107836SJohn.Forte@Sun.COM 				continue;
22117836SJohn.Forte@Sun.COM 			}
22127836SJohn.Forte@Sun.COM 		}
22137836SJohn.Forte@Sun.COM 
22147836SJohn.Forte@Sun.COM 		for (found = B_FALSE, j = 0; j < staticTargetList->oidCount;
22157836SJohn.Forte@Sun.COM 		    j++) {
22167836SJohn.Forte@Sun.COM 			boolean_t isIpv6 = B_FALSE;
22177836SJohn.Forte@Sun.COM 			IMA_UINT16 stpgt;
22187836SJohn.Forte@Sun.COM 			IMA_BOOL defaultTpgt;
22197836SJohn.Forte@Sun.COM 
22207836SJohn.Forte@Sun.COM 			matched = B_FALSE;
22217836SJohn.Forte@Sun.COM 			(void) memset(&staticTargetProps, 0,
22227836SJohn.Forte@Sun.COM 			    sizeof (staticTargetProps));
22237836SJohn.Forte@Sun.COM 
22247836SJohn.Forte@Sun.COM 			status = SUN_IMA_GetStaticTargetProperties(
22257836SJohn.Forte@Sun.COM 			    staticTargetList->oids[j], &staticTargetProps);
22267836SJohn.Forte@Sun.COM 			if (!IMA_SUCCESS(status)) {
22277836SJohn.Forte@Sun.COM 				printLibError(status);
22287836SJohn.Forte@Sun.COM 				(void) IMA_FreeMemory(staticTargetList);
22297836SJohn.Forte@Sun.COM 				*funcRet = 1;
22307836SJohn.Forte@Sun.COM 				return (ret);
22317836SJohn.Forte@Sun.COM 			}
22327836SJohn.Forte@Sun.COM 
22337836SJohn.Forte@Sun.COM 			stpgt = staticTargetProps.staticTarget.targetAddress.
22347836SJohn.Forte@Sun.COM 			    tpgt;
22357836SJohn.Forte@Sun.COM 
22367836SJohn.Forte@Sun.COM 			defaultTpgt = staticTargetProps.staticTarget.
22377836SJohn.Forte@Sun.COM 			    targetAddress.defaultTpgt;
22387836SJohn.Forte@Sun.COM 
22397836SJohn.Forte@Sun.COM 			isIpv6 = !staticTargetProps.staticTarget.targetAddress.
22407836SJohn.Forte@Sun.COM 			    imaStruct.hostnameIpAddress.id.ipAddress.
22417836SJohn.Forte@Sun.COM 			    ipv4Address;
22427836SJohn.Forte@Sun.COM 
22437836SJohn.Forte@Sun.COM 			/*
22447836SJohn.Forte@Sun.COM 			 * Compare the static target name with the input if
22457836SJohn.Forte@Sun.COM 			 * one was input
22467836SJohn.Forte@Sun.COM 			 */
22477836SJohn.Forte@Sun.COM 
22487836SJohn.Forte@Sun.COM 			if (object &&
22497836SJohn.Forte@Sun.COM 			    (targetNamesEqual(
22507836SJohn.Forte@Sun.COM 			    staticTargetProps.staticTarget.targetName,
22517836SJohn.Forte@Sun.COM 			    staticTargetName) == B_TRUE)) {
22527836SJohn.Forte@Sun.COM 				/* targetName found - found = B_TRUE */
22537836SJohn.Forte@Sun.COM 				found = B_TRUE;
22547836SJohn.Forte@Sun.COM 				if (targetAddressSpecified == B_FALSE) {
22557836SJohn.Forte@Sun.COM 					matched = B_TRUE;
22567836SJohn.Forte@Sun.COM 				} else {
22577836SJohn.Forte@Sun.COM 
22587836SJohn.Forte@Sun.COM 				if (staticTargetProps.staticTarget.
22597836SJohn.Forte@Sun.COM 				    targetAddress.imaStruct.
22607836SJohn.Forte@Sun.COM 				    hostnameIpAddress.id.ipAddress.
22617836SJohn.Forte@Sun.COM 				    ipv4Address == IMA_TRUE) {
22627836SJohn.Forte@Sun.COM 					(void) inet_ntop(AF_INET,
22637836SJohn.Forte@Sun.COM 					    staticTargetProps.
22647836SJohn.Forte@Sun.COM 					    staticTarget.targetAddress.
22657836SJohn.Forte@Sun.COM 					    imaStruct.hostnameIpAddress.id.
22667836SJohn.Forte@Sun.COM 					    ipAddress.ipAddress, tmpStr,
22677836SJohn.Forte@Sun.COM 					    sizeof (tmpStr));
22687836SJohn.Forte@Sun.COM 				} else {
22697836SJohn.Forte@Sun.COM 					(void) inet_ntop(AF_INET6,
22707836SJohn.Forte@Sun.COM 					    staticTargetProps.
22717836SJohn.Forte@Sun.COM 					    staticTarget.targetAddress.
22727836SJohn.Forte@Sun.COM 					    imaStruct.hostnameIpAddress.id.
22737836SJohn.Forte@Sun.COM 					    ipAddress.ipAddress, tmpStr,
22747836SJohn.Forte@Sun.COM 					    sizeof (tmpStr));
22757836SJohn.Forte@Sun.COM 				}
22767836SJohn.Forte@Sun.COM 
22777836SJohn.Forte@Sun.COM 				if (mbstowcs(tmpTargetAddress, tmpStr,
22787836SJohn.Forte@Sun.COM 				    SUN_IMA_IP_ADDRESS_PORT_LEN) ==
22797836SJohn.Forte@Sun.COM 				    (size_t)-1) {
22807836SJohn.Forte@Sun.COM 					(void) fprintf(stderr, "%s: %s\n",
22817836SJohn.Forte@Sun.COM 					    cmdName,
22827836SJohn.Forte@Sun.COM 					gettext("conversion error"));
22837836SJohn.Forte@Sun.COM 					ret = 1;
22847836SJohn.Forte@Sun.COM 					continue;
22857836SJohn.Forte@Sun.COM 				}
22867836SJohn.Forte@Sun.COM 
22877836SJohn.Forte@Sun.COM 				if (wcsncmp(tmpTargetAddress,
22887836SJohn.Forte@Sun.COM 				    staticTargetAddress,
22897836SJohn.Forte@Sun.COM 				    SUN_IMA_IP_ADDRESS_PORT_LEN)
22907836SJohn.Forte@Sun.COM 				    == 0 &&
22917836SJohn.Forte@Sun.COM 				    staticTargetProps.
22927836SJohn.Forte@Sun.COM 				    staticTarget.targetAddress.
22937836SJohn.Forte@Sun.COM 				    imaStruct.portNumber == port) {
22947836SJohn.Forte@Sun.COM 					/*
22957836SJohn.Forte@Sun.COM 					 * Since an object is
22967836SJohn.Forte@Sun.COM 					 * specified, it should also
22977836SJohn.Forte@Sun.COM 					 * have a tpgt specified. If
22987836SJohn.Forte@Sun.COM 					 * not, that means the object
22997836SJohn.Forte@Sun.COM 					 * specified is associated with
23007836SJohn.Forte@Sun.COM 					 * the default tpgt. In
23017836SJohn.Forte@Sun.COM 					 * either case, a tpgt
23027836SJohn.Forte@Sun.COM 					 * comparison should be done
23037836SJohn.Forte@Sun.COM 					 * before claiming that a
23047836SJohn.Forte@Sun.COM 					 * match is found.
23057836SJohn.Forte@Sun.COM 					 */
23067836SJohn.Forte@Sun.COM 					if ((tpgt == stpgt &&
23077836SJohn.Forte@Sun.COM 					    tpgtSpecified == B_TRUE &&
23087836SJohn.Forte@Sun.COM 					    defaultTpgt == IMA_FALSE) ||
23097836SJohn.Forte@Sun.COM 					    (tpgt == stpgt &&
23107836SJohn.Forte@Sun.COM 					    tpgtSpecified == B_FALSE &&
23117836SJohn.Forte@Sun.COM 					    defaultTpgt == IMA_TRUE)) {
23127836SJohn.Forte@Sun.COM 						matched = B_TRUE;
23137836SJohn.Forte@Sun.COM 					}
23147836SJohn.Forte@Sun.COM 				}
23157836SJohn.Forte@Sun.COM 
23167836SJohn.Forte@Sun.COM 				}
23177836SJohn.Forte@Sun.COM 			}
23187836SJohn.Forte@Sun.COM 
23197836SJohn.Forte@Sun.COM 			if (!object || matched) {
23207836SJohn.Forte@Sun.COM 				/* print summary - always */
23217836SJohn.Forte@Sun.COM 				(void) fprintf(stdout, gettext("%s: %ws,"),
23227836SJohn.Forte@Sun.COM 				    "Static Configuration Target",
23237836SJohn.Forte@Sun.COM 				    staticTargetProps.staticTarget.targetName);
23247836SJohn.Forte@Sun.COM 
23257836SJohn.Forte@Sun.COM 				if (isIpv6 == B_FALSE) {
23267836SJohn.Forte@Sun.COM 					(void) inet_ntop(AF_INET,
23277836SJohn.Forte@Sun.COM 					    staticTargetProps.
23287836SJohn.Forte@Sun.COM 					    staticTarget.targetAddress.
23297836SJohn.Forte@Sun.COM 					    imaStruct.hostnameIpAddress.id.
23307836SJohn.Forte@Sun.COM 					    ipAddress.ipAddress, sAddr,
23317836SJohn.Forte@Sun.COM 					    sizeof (sAddr));
23327836SJohn.Forte@Sun.COM 					(void) fprintf(stdout, "%s:%d",
23337836SJohn.Forte@Sun.COM 					    sAddr,
23347836SJohn.Forte@Sun.COM 					    staticTargetProps.staticTarget.
23357836SJohn.Forte@Sun.COM 					    targetAddress.imaStruct.portNumber);
23367836SJohn.Forte@Sun.COM 				} else {
23377836SJohn.Forte@Sun.COM 					(void) inet_ntop(AF_INET6,
23387836SJohn.Forte@Sun.COM 					    staticTargetProps.
23397836SJohn.Forte@Sun.COM 					    staticTarget.targetAddress.
23407836SJohn.Forte@Sun.COM 					    imaStruct.hostnameIpAddress.id.
23417836SJohn.Forte@Sun.COM 					    ipAddress.ipAddress, sAddr,
23427836SJohn.Forte@Sun.COM 					    sizeof (sAddr));
23437836SJohn.Forte@Sun.COM 					(void) fprintf(stdout, "[%s]:%d",
23447836SJohn.Forte@Sun.COM 					    sAddr,
23457836SJohn.Forte@Sun.COM 					    staticTargetProps.staticTarget.
23467836SJohn.Forte@Sun.COM 					    targetAddress.imaStruct.portNumber);
23477836SJohn.Forte@Sun.COM 				}
23487836SJohn.Forte@Sun.COM 
23497836SJohn.Forte@Sun.COM 				if (staticTargetProps.staticTarget.
23507836SJohn.Forte@Sun.COM 				    targetAddress.
23517836SJohn.Forte@Sun.COM 				    defaultTpgt == IMA_FALSE) {
23527836SJohn.Forte@Sun.COM 					(void) fprintf(stdout, ",%d\n",
23537836SJohn.Forte@Sun.COM 					    staticTargetProps.
23547836SJohn.Forte@Sun.COM 					    staticTarget.targetAddress.tpgt);
23557836SJohn.Forte@Sun.COM 				} else {
23567836SJohn.Forte@Sun.COM 					(void) fprintf(stdout, "\n");
23577836SJohn.Forte@Sun.COM 				}
23587836SJohn.Forte@Sun.COM 			}
23597836SJohn.Forte@Sun.COM 
23607836SJohn.Forte@Sun.COM 		}
23617836SJohn.Forte@Sun.COM 		/*
23627836SJohn.Forte@Sun.COM 		 * No details to display, but if there were:
23637836SJohn.Forte@Sun.COM 		 *  if (object && found)...
23647836SJohn.Forte@Sun.COM 		 *
23657836SJohn.Forte@Sun.COM 		 */
23667836SJohn.Forte@Sun.COM 
23677836SJohn.Forte@Sun.COM 		/*
23687836SJohn.Forte@Sun.COM 		 * There was an object entered but we didn't
23697836SJohn.Forte@Sun.COM 		 * find it.
23707836SJohn.Forte@Sun.COM 		 */
23717836SJohn.Forte@Sun.COM 		if (object && !found) {
23727836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "%s: %s\n",
23737836SJohn.Forte@Sun.COM 			    operand[i], gettext("not found"));
23747836SJohn.Forte@Sun.COM 			ret = 1; /* DIY test fix */
23757836SJohn.Forte@Sun.COM 		}
23767836SJohn.Forte@Sun.COM 	}
23777836SJohn.Forte@Sun.COM 	return (ret);
23787836SJohn.Forte@Sun.COM }
23797836SJohn.Forte@Sun.COM 
23807836SJohn.Forte@Sun.COM /*
23817836SJohn.Forte@Sun.COM  * Print targets
23827836SJohn.Forte@Sun.COM  */
23837836SJohn.Forte@Sun.COM /*ARGSUSED*/
23847836SJohn.Forte@Sun.COM static int
listTarget(int objectLen,char * objects[],cmdOptions_t * options,int * funcRet)23857836SJohn.Forte@Sun.COM listTarget(int objectLen, char *objects[], cmdOptions_t *options, int *funcRet)
23867836SJohn.Forte@Sun.COM {
23877836SJohn.Forte@Sun.COM 	IMA_OID	initiatorOid;
23887836SJohn.Forte@Sun.COM 	IMA_OID_LIST *targetList;
23897836SJohn.Forte@Sun.COM 	IMA_OID_LIST *lunList;
23907836SJohn.Forte@Sun.COM 	SUN_IMA_TARGET_PROPERTIES targetProps;
23917836SJohn.Forte@Sun.COM 	IMA_STATUS status;
23927836SJohn.Forte@Sun.COM 	IMA_OID_LIST *pConnList;
23937836SJohn.Forte@Sun.COM 	SUN_IMA_CONN_PROPERTIES *connProps;
23947836SJohn.Forte@Sun.COM 
23957836SJohn.Forte@Sun.COM 	int ret;
23967836SJohn.Forte@Sun.COM 	wchar_t targetName[MAX_ISCSI_NAME_LEN + 1];
23977836SJohn.Forte@Sun.COM 	wchar_t targetAddress[SUN_IMA_IP_ADDRESS_PORT_LEN];
23987836SJohn.Forte@Sun.COM 	int outerLoop;
23997836SJohn.Forte@Sun.COM 	boolean_t found;
24007836SJohn.Forte@Sun.COM 	boolean_t operandEntered = B_FALSE;
24017836SJohn.Forte@Sun.COM 	boolean_t verbose = B_FALSE;
24027836SJohn.Forte@Sun.COM 	boolean_t scsi_target = B_FALSE;
24037836SJohn.Forte@Sun.COM 	boolean_t targetAddressSpecified = B_FALSE;
24047836SJohn.Forte@Sun.COM 	boolean_t isIpv6 = B_FALSE;
24057836SJohn.Forte@Sun.COM 	int i, j;
24067836SJohn.Forte@Sun.COM 	cmdOptions_t *optionList = options;
24077836SJohn.Forte@Sun.COM 	boolean_t tpgtSpecified = B_FALSE;
24087836SJohn.Forte@Sun.COM 	IMA_UINT16 port = 0;
24097836SJohn.Forte@Sun.COM 	uint16_t tpgt;
24107836SJohn.Forte@Sun.COM 
24117836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
24127836SJohn.Forte@Sun.COM 
24137836SJohn.Forte@Sun.COM 	/* Find Sun initiator */
24147836SJohn.Forte@Sun.COM 	ret = sunInitiatorFind(&initiatorOid);
24157836SJohn.Forte@Sun.COM 	if (ret > 0) {
24167836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s\n",
24177836SJohn.Forte@Sun.COM 		    cmdName, gettext("no initiator found"));
24187836SJohn.Forte@Sun.COM 	}
24197836SJohn.Forte@Sun.COM 
24207836SJohn.Forte@Sun.COM 	if (ret != 0) {
24217836SJohn.Forte@Sun.COM 		return (ret);
24227836SJohn.Forte@Sun.COM 	}
24237836SJohn.Forte@Sun.COM 
24247836SJohn.Forte@Sun.COM 	for (; optionList->optval; optionList++) {
24257836SJohn.Forte@Sun.COM 		switch (optionList->optval) {
24267836SJohn.Forte@Sun.COM 			case 'S':
24277836SJohn.Forte@Sun.COM 				scsi_target = B_TRUE;
24287836SJohn.Forte@Sun.COM 				break;
24297836SJohn.Forte@Sun.COM 			case 'v':
24307836SJohn.Forte@Sun.COM 				verbose = B_TRUE;
24317836SJohn.Forte@Sun.COM 				break;
24327836SJohn.Forte@Sun.COM 			default:
24337836SJohn.Forte@Sun.COM 				(void) fprintf(stderr, "%s: %c: %s\n",
24347836SJohn.Forte@Sun.COM 				    cmdName, optionList->optval,
24357836SJohn.Forte@Sun.COM 				    gettext("unknown option"));
24367836SJohn.Forte@Sun.COM 				return (1);
24377836SJohn.Forte@Sun.COM 		}
24387836SJohn.Forte@Sun.COM 	}
24397836SJohn.Forte@Sun.COM 
24407836SJohn.Forte@Sun.COM 	/*
24417836SJohn.Forte@Sun.COM 	 * If there are multiple objects, execute outer 'for' loop that
24427836SJohn.Forte@Sun.COM 	 * many times for each target detail, otherwise, execute it only
24437836SJohn.Forte@Sun.COM 	 * once with summaries only
24447836SJohn.Forte@Sun.COM 	 */
24457836SJohn.Forte@Sun.COM 	if (objectLen > 0) {
24467836SJohn.Forte@Sun.COM 		operandEntered = B_TRUE;
24477836SJohn.Forte@Sun.COM 		outerLoop = objectLen;
24487836SJohn.Forte@Sun.COM 	} else {
24497836SJohn.Forte@Sun.COM 		operandEntered = B_FALSE;
24507836SJohn.Forte@Sun.COM 		outerLoop = 1;
24517836SJohn.Forte@Sun.COM 	}
24527836SJohn.Forte@Sun.COM 
24537836SJohn.Forte@Sun.COM 	status = SUN_IMA_GetSessionOidList(initiatorOid, &targetList);
24547836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
24557836SJohn.Forte@Sun.COM 		printLibError(status);
24567836SJohn.Forte@Sun.COM 		*funcRet = 1;
24577836SJohn.Forte@Sun.COM 		return (ret);
24587836SJohn.Forte@Sun.COM 	}
24597836SJohn.Forte@Sun.COM 
24607836SJohn.Forte@Sun.COM 	for (i = 0; i < outerLoop; i++) {
24617836SJohn.Forte@Sun.COM 
24627836SJohn.Forte@Sun.COM 		tpgtSpecified = B_FALSE;
24637836SJohn.Forte@Sun.COM 		if (operandEntered) {
24647836SJohn.Forte@Sun.COM 			if (parseTarget(objects[i],
24657836SJohn.Forte@Sun.COM 			    &targetName[0],
24667836SJohn.Forte@Sun.COM 			    MAX_ISCSI_NAME_LEN + 1,
24677836SJohn.Forte@Sun.COM 			    &targetAddressSpecified,
24687836SJohn.Forte@Sun.COM 			    &targetAddress[0],
24697836SJohn.Forte@Sun.COM 			    SUN_IMA_IP_ADDRESS_PORT_LEN,
24707836SJohn.Forte@Sun.COM 			    &port,
24717836SJohn.Forte@Sun.COM 			    &tpgtSpecified,
24727836SJohn.Forte@Sun.COM 			    &tpgt,
24737836SJohn.Forte@Sun.COM 			    &isIpv6) != PARSE_TARGET_OK) {
24747836SJohn.Forte@Sun.COM 				ret = 1;
24757836SJohn.Forte@Sun.COM 				continue;
24767836SJohn.Forte@Sun.COM 			}
24777836SJohn.Forte@Sun.COM 		}
24787836SJohn.Forte@Sun.COM 		for (found = B_FALSE, j = 0; j < targetList->oidCount; j++) {
24797836SJohn.Forte@Sun.COM 			status = SUN_IMA_GetTargetProperties(
24807836SJohn.Forte@Sun.COM 			    targetList->oids[j],
24817836SJohn.Forte@Sun.COM 			    &targetProps);
24827836SJohn.Forte@Sun.COM 			if (!IMA_SUCCESS(status)) {
24837836SJohn.Forte@Sun.COM 				printLibError(status);
24847836SJohn.Forte@Sun.COM 				(void) IMA_FreeMemory(targetList);
24857836SJohn.Forte@Sun.COM 				*funcRet = 1;
24867836SJohn.Forte@Sun.COM 				return (ret);
24877836SJohn.Forte@Sun.COM 			}
24887836SJohn.Forte@Sun.COM 
24897836SJohn.Forte@Sun.COM 			/*
24907836SJohn.Forte@Sun.COM 			 * Compare the target name with the input if
24917836SJohn.Forte@Sun.COM 			 * one was input, if they match, print the target's info
24927836SJohn.Forte@Sun.COM 			 *
24937836SJohn.Forte@Sun.COM 			 * if no target name was input, continue printing this
24947836SJohn.Forte@Sun.COM 			 * target
24957836SJohn.Forte@Sun.COM 			 */
24967836SJohn.Forte@Sun.COM 			if (operandEntered) {
24977836SJohn.Forte@Sun.COM 				if (targetNamesEqual(targetProps.imaProps.name,
24987836SJohn.Forte@Sun.COM 				    targetName) == B_TRUE) {
24997836SJohn.Forte@Sun.COM 					if (tpgtSpecified == B_TRUE) {
25007836SJohn.Forte@Sun.COM 						if (targetProps.
25017836SJohn.Forte@Sun.COM 						    defaultTpgtConf ==
25027836SJohn.Forte@Sun.COM 						    IMA_FALSE &&
25037836SJohn.Forte@Sun.COM 						    targetProps.
25047836SJohn.Forte@Sun.COM 						    tpgtConf == tpgt) {
25057836SJohn.Forte@Sun.COM 							found = B_TRUE;
25067836SJohn.Forte@Sun.COM 						} else {
25077836SJohn.Forte@Sun.COM 							/*
25087836SJohn.Forte@Sun.COM 							 * tpgt does not match,
25097836SJohn.Forte@Sun.COM 							 * move on to next
25107836SJohn.Forte@Sun.COM 							 * target
25117836SJohn.Forte@Sun.COM 							 */
25127836SJohn.Forte@Sun.COM 							continue;
25137836SJohn.Forte@Sun.COM 						}
25147836SJohn.Forte@Sun.COM 					} else {
25157836SJohn.Forte@Sun.COM 						found = B_TRUE;
25167836SJohn.Forte@Sun.COM 					}
25177836SJohn.Forte@Sun.COM 				} else {
25187836SJohn.Forte@Sun.COM 					/*
25197836SJohn.Forte@Sun.COM 					 * target name does not match, move on
25207836SJohn.Forte@Sun.COM 					 * to next target
25217836SJohn.Forte@Sun.COM 					 */
25227836SJohn.Forte@Sun.COM 					continue;
25237836SJohn.Forte@Sun.COM 				}
25247836SJohn.Forte@Sun.COM 			}
25257836SJohn.Forte@Sun.COM 
25267836SJohn.Forte@Sun.COM 			/* print summary - always */
25277836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, gettext("%s: %ws\n"),
25287836SJohn.Forte@Sun.COM 			    gettext("Target"), targetProps.imaProps.name);
25297836SJohn.Forte@Sun.COM 
25307836SJohn.Forte@Sun.COM 			/* Alias */
25317836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "\t%s: ", gettext("Alias"));
25327836SJohn.Forte@Sun.COM 			if (wslen(targetProps.imaProps.alias) > (size_t)0) {
25337836SJohn.Forte@Sun.COM 				(void) fprintf(stdout, gettext("%ws\n"),
25347836SJohn.Forte@Sun.COM 				    targetProps.imaProps.alias);
25357836SJohn.Forte@Sun.COM 			} else {
25367836SJohn.Forte@Sun.COM 				(void) fprintf(stdout, "%s\n", "-");
25377836SJohn.Forte@Sun.COM 			}
25387836SJohn.Forte@Sun.COM 
25397836SJohn.Forte@Sun.COM 			if (targetProps.defaultTpgtNego != IMA_TRUE) {
25407836SJohn.Forte@Sun.COM 				(void) fprintf(stdout, "%s%s: %d\n",
25417836SJohn.Forte@Sun.COM 				    "\t", gettext("TPGT"),
25427836SJohn.Forte@Sun.COM 				    targetProps.tpgtNego);
25437836SJohn.Forte@Sun.COM 			} else if (targetProps.defaultTpgtConf != IMA_TRUE) {
25447836SJohn.Forte@Sun.COM 				(void) fprintf(stdout, "%s%s: %d\n",
25457836SJohn.Forte@Sun.COM 				    "\t", gettext("TPGT"),
25467836SJohn.Forte@Sun.COM 				    targetProps.tpgtConf);
25477836SJohn.Forte@Sun.COM 			}
25487836SJohn.Forte@Sun.COM 
25497836SJohn.Forte@Sun.COM 			(void) fprintf(stdout,
25507836SJohn.Forte@Sun.COM 			    "%s%s: %02x%02x%02x%02x%02x%02x\n",
25517836SJohn.Forte@Sun.COM 			    "\t", gettext("ISID"),
25527836SJohn.Forte@Sun.COM 			    targetProps.isid[0], targetProps.isid[1],
25537836SJohn.Forte@Sun.COM 			    targetProps.isid[2], targetProps.isid[3],
25547836SJohn.Forte@Sun.COM 			    targetProps.isid[4], targetProps.isid[5]);
25557836SJohn.Forte@Sun.COM 
25567836SJohn.Forte@Sun.COM 			pConnList = NULL;
25577836SJohn.Forte@Sun.COM 			status = SUN_IMA_GetConnOidList(
25587836SJohn.Forte@Sun.COM 			    &targetList->oids[j],
25597836SJohn.Forte@Sun.COM 			    &pConnList);
25607836SJohn.Forte@Sun.COM 
25617836SJohn.Forte@Sun.COM 			if (!IMA_SUCCESS(status)) {
25627836SJohn.Forte@Sun.COM 				printLibError(status);
25637836SJohn.Forte@Sun.COM 				(void) IMA_FreeMemory(targetList);
25647836SJohn.Forte@Sun.COM 				*funcRet = 1;
25657836SJohn.Forte@Sun.COM 				return (ret);
25667836SJohn.Forte@Sun.COM 			}
25677836SJohn.Forte@Sun.COM 
25687836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "%s%s: %lu\n",
25697836SJohn.Forte@Sun.COM 			    "\t",
25707836SJohn.Forte@Sun.COM 			    gettext("Connections"),
25717836SJohn.Forte@Sun.COM 			    pConnList->oidCount);
25727836SJohn.Forte@Sun.COM 
25737836SJohn.Forte@Sun.COM 			if (verbose) {
25747836SJohn.Forte@Sun.COM 				SUN_IMA_DIGEST_ALGORITHM_VALUE digestAlgorithms;
25757836SJohn.Forte@Sun.COM 
25767836SJohn.Forte@Sun.COM 				printConnectionList("\t\t", pConnList);
25777836SJohn.Forte@Sun.COM 				printDiscoveryMethod(
25787836SJohn.Forte@Sun.COM 				    "\t\t  ",
25797836SJohn.Forte@Sun.COM 				    targetProps.imaProps.discoveryMethodFlags);
25807836SJohn.Forte@Sun.COM 				(void) printLoginParameters(
25817836SJohn.Forte@Sun.COM 				    "\t\t  ",
25827836SJohn.Forte@Sun.COM 				    targetList->oids[j],
25837836SJohn.Forte@Sun.COM 				    PRINT_NEGOTIATED_PARAMS);
25847836SJohn.Forte@Sun.COM 
25857836SJohn.Forte@Sun.COM 				/* Get Digest configuration */
25867836SJohn.Forte@Sun.COM 				status = SUN_IMA_GetConnProperties(
25877836SJohn.Forte@Sun.COM 				    &pConnList->oids[0], &connProps);
25887836SJohn.Forte@Sun.COM 
25897836SJohn.Forte@Sun.COM 				(void) getNegotiatedDigest(
25907836SJohn.Forte@Sun.COM 				    ISCSI_LOGIN_PARAM_HEADER_DIGEST,
25917836SJohn.Forte@Sun.COM 				    &digestAlgorithms, connProps);
25927836SJohn.Forte@Sun.COM 
25937836SJohn.Forte@Sun.COM 				if (IMA_SUCCESS(status)) {
25947836SJohn.Forte@Sun.COM 					(void) fprintf(stdout, "\t\t  \t%s: ",
25957836SJohn.Forte@Sun.COM 					    gettext("Header Digest"));
25967836SJohn.Forte@Sun.COM 					printDigestAlgorithm(
25977836SJohn.Forte@Sun.COM 					    &digestAlgorithms,
25987836SJohn.Forte@Sun.COM 					    PRINT_NEGOTIATED_PARAMS);
25997836SJohn.Forte@Sun.COM 				} else {
26007836SJohn.Forte@Sun.COM 					(void) IMA_FreeMemory(pConnList);
26017836SJohn.Forte@Sun.COM 					(void) IMA_FreeMemory(targetList);
26027836SJohn.Forte@Sun.COM 					printLibError(status);
26037836SJohn.Forte@Sun.COM 					*funcRet = 1;
26047836SJohn.Forte@Sun.COM 					return (ret);
26057836SJohn.Forte@Sun.COM 				}
26067836SJohn.Forte@Sun.COM 
26077836SJohn.Forte@Sun.COM 				(void) getNegotiatedDigest(
26087836SJohn.Forte@Sun.COM 				    ISCSI_LOGIN_PARAM_DATA_DIGEST,
26097836SJohn.Forte@Sun.COM 				    &digestAlgorithms, connProps);
26107836SJohn.Forte@Sun.COM 
26117836SJohn.Forte@Sun.COM 				if (IMA_SUCCESS(status)) {
26127836SJohn.Forte@Sun.COM 					(void) fprintf(stdout, "\t\t  \t%s: ",
26137836SJohn.Forte@Sun.COM 					    gettext("Data Digest"));
26147836SJohn.Forte@Sun.COM 					printDigestAlgorithm(
26157836SJohn.Forte@Sun.COM 					    &digestAlgorithms,
26167836SJohn.Forte@Sun.COM 					    PRINT_NEGOTIATED_PARAMS);
26177836SJohn.Forte@Sun.COM 				} else {
26187836SJohn.Forte@Sun.COM 					(void) IMA_FreeMemory(pConnList);
26197836SJohn.Forte@Sun.COM 					(void) IMA_FreeMemory(targetList);
26207836SJohn.Forte@Sun.COM 					printLibError(status);
26217836SJohn.Forte@Sun.COM 					*funcRet = 1;
26227836SJohn.Forte@Sun.COM 					return (ret);
26237836SJohn.Forte@Sun.COM 				}
26247836SJohn.Forte@Sun.COM 
26257836SJohn.Forte@Sun.COM 				(void) fprintf(stdout, "\n");
26267836SJohn.Forte@Sun.COM 			}
26277836SJohn.Forte@Sun.COM 
26287836SJohn.Forte@Sun.COM 			if (scsi_target) {
262912161SJack.Meng@Sun.COM 				status = SUN_IMA_ReEnumeration(
263012161SJack.Meng@Sun.COM 				    targetList->oids[j]);
263112161SJack.Meng@Sun.COM 				if (!IMA_SUCCESS(status)) {
263212161SJack.Meng@Sun.COM 					/*
263312161SJack.Meng@Sun.COM 					 * Proceeds the listing
263412161SJack.Meng@Sun.COM 					 * but indicates the
263512161SJack.Meng@Sun.COM 					 * error in return value
263612161SJack.Meng@Sun.COM 					 */
263712161SJack.Meng@Sun.COM 					ret = 1;
263812161SJack.Meng@Sun.COM 				}
263912161SJack.Meng@Sun.COM 
26407836SJohn.Forte@Sun.COM 				status = IMA_GetLuOidList(
26417836SJohn.Forte@Sun.COM 				    targetList->oids[j],
26427836SJohn.Forte@Sun.COM 				    &lunList);
26437836SJohn.Forte@Sun.COM 				if (!IMA_SUCCESS(status)) {
26447836SJohn.Forte@Sun.COM 					printLibError(status);
26457836SJohn.Forte@Sun.COM 					(void) IMA_FreeMemory(targetList);
26467836SJohn.Forte@Sun.COM 					*funcRet = 1;
26477836SJohn.Forte@Sun.COM 					return (ret);
26487836SJohn.Forte@Sun.COM 				}
26497836SJohn.Forte@Sun.COM 				if (lunList->oidCount != 0) {
26507836SJohn.Forte@Sun.COM 					printTargetLuns(lunList);
26517836SJohn.Forte@Sun.COM 				}
26527836SJohn.Forte@Sun.COM 				(void) fprintf(stdout, "\n");
26537836SJohn.Forte@Sun.COM 				(void) IMA_FreeMemory(lunList);
26547836SJohn.Forte@Sun.COM 			}
26557836SJohn.Forte@Sun.COM 		}
26567836SJohn.Forte@Sun.COM 		/*
26577836SJohn.Forte@Sun.COM 		 * did we find the object
26587836SJohn.Forte@Sun.COM 		 */
26597836SJohn.Forte@Sun.COM 
26607836SJohn.Forte@Sun.COM 		if (operandEntered && !found) {
26617836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "%s: %s\n",
26627836SJohn.Forte@Sun.COM 			    objects[i], gettext("not found"));
26637836SJohn.Forte@Sun.COM 		}
26647836SJohn.Forte@Sun.COM 	}
26657836SJohn.Forte@Sun.COM 
26667836SJohn.Forte@Sun.COM 	(void) IMA_FreeMemory(targetList);
26677836SJohn.Forte@Sun.COM 	return (ret);
26687836SJohn.Forte@Sun.COM }
26697836SJohn.Forte@Sun.COM 
26707836SJohn.Forte@Sun.COM 
26717836SJohn.Forte@Sun.COM /*
26727836SJohn.Forte@Sun.COM  * Print configured session information
26737836SJohn.Forte@Sun.COM  */
26747836SJohn.Forte@Sun.COM static int
printConfiguredSessions(IMA_OID oid)26757836SJohn.Forte@Sun.COM printConfiguredSessions(IMA_OID oid)
26767836SJohn.Forte@Sun.COM {
26777836SJohn.Forte@Sun.COM 	IMA_STATUS		status;
26787836SJohn.Forte@Sun.COM 	const char		*rtn;
26797836SJohn.Forte@Sun.COM 	SUN_IMA_CONFIG_SESSIONS	*pConfigSessions;
26807836SJohn.Forte@Sun.COM 	char			address[MAX_ADDRESS_LEN];
26817836SJohn.Forte@Sun.COM 	int			out;
26827836SJohn.Forte@Sun.COM 
26837836SJohn.Forte@Sun.COM 	/* Get configured session information */
26847836SJohn.Forte@Sun.COM 	status = SUN_IMA_GetConfigSessions(oid, &pConfigSessions);
26857836SJohn.Forte@Sun.COM 
26867836SJohn.Forte@Sun.COM 	if (IMA_SUCCESS(status)) {
26877836SJohn.Forte@Sun.COM 		(void) fprintf(stdout, "\t%s: ",
26887836SJohn.Forte@Sun.COM 		    gettext("Configured Sessions"));
26897836SJohn.Forte@Sun.COM 		if (pConfigSessions->bound == IMA_FALSE) {
26907836SJohn.Forte@Sun.COM 			/* default binding */
26917836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "%lu\n", pConfigSessions->out);
26927836SJohn.Forte@Sun.COM 		} else {
26937836SJohn.Forte@Sun.COM 			/* hardcoded binding */
26947836SJohn.Forte@Sun.COM 			for (out = 0;
26957836SJohn.Forte@Sun.COM 			    out < pConfigSessions->out; out++) {
26967836SJohn.Forte@Sun.COM 				if (pConfigSessions->bindings[out].
26977836SJohn.Forte@Sun.COM 				    ipAddress.ipv4Address == IMA_TRUE) {
26987836SJohn.Forte@Sun.COM 					rtn = inet_ntop(AF_INET,
26997836SJohn.Forte@Sun.COM 					    pConfigSessions->bindings[out].
27007836SJohn.Forte@Sun.COM 					    ipAddress.ipAddress, address,
27017836SJohn.Forte@Sun.COM 					    MAX_ADDRESS_LEN);
27027836SJohn.Forte@Sun.COM 				} else {
27037836SJohn.Forte@Sun.COM 					rtn = inet_ntop(AF_INET6,
27047836SJohn.Forte@Sun.COM 					    pConfigSessions->bindings[out].
27057836SJohn.Forte@Sun.COM 					    ipAddress.ipAddress, address,
27067836SJohn.Forte@Sun.COM 					    MAX_ADDRESS_LEN);
27077836SJohn.Forte@Sun.COM 				}
27087836SJohn.Forte@Sun.COM 				if (rtn != NULL) {
27097836SJohn.Forte@Sun.COM 					(void) printf("%s ", address);
27107836SJohn.Forte@Sun.COM 				}
27117836SJohn.Forte@Sun.COM 			}
27127836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "\n");
27137836SJohn.Forte@Sun.COM 		}
27147836SJohn.Forte@Sun.COM 	} else {
27157836SJohn.Forte@Sun.COM 		free(pConfigSessions);
27167836SJohn.Forte@Sun.COM 		printLibError(status);
27177836SJohn.Forte@Sun.COM 		return (1);
27187836SJohn.Forte@Sun.COM 	}
27197836SJohn.Forte@Sun.COM 
27207836SJohn.Forte@Sun.COM 	free(pConfigSessions);
27217836SJohn.Forte@Sun.COM 	return (0);
27227836SJohn.Forte@Sun.COM }
27237836SJohn.Forte@Sun.COM 
27247836SJohn.Forte@Sun.COM /*
27257836SJohn.Forte@Sun.COM  * Print target parameters
27267836SJohn.Forte@Sun.COM  */
27277836SJohn.Forte@Sun.COM static int
listTargetParam(int operandLen,char * operand[],cmdOptions_t * options,int * funcRet)27287836SJohn.Forte@Sun.COM listTargetParam(int operandLen, char *operand[], cmdOptions_t *options,
27297836SJohn.Forte@Sun.COM     int *funcRet)
27307836SJohn.Forte@Sun.COM {
27317836SJohn.Forte@Sun.COM 	IMA_STATUS status;
27327836SJohn.Forte@Sun.COM 	IMA_OID	initiatorOid;
27337836SJohn.Forte@Sun.COM 	IMA_OID_LIST *targetList;
27347836SJohn.Forte@Sun.COM 	IMA_AUTHMETHOD	methodList[MAX_AUTH_METHODS];
27357836SJohn.Forte@Sun.COM 	SUN_IMA_TARGET_PROPERTIES targetProps;
27367836SJohn.Forte@Sun.COM 	IMA_UINT maxEntries = MAX_AUTH_METHODS;
27377836SJohn.Forte@Sun.COM 	IMA_BOOL bidirAuth;
27387836SJohn.Forte@Sun.COM 	int ret;
27397836SJohn.Forte@Sun.COM 	wchar_t targetName[MAX_ISCSI_NAME_LEN + 1];
27407836SJohn.Forte@Sun.COM 	wchar_t targetAddress[SUN_IMA_IP_ADDRESS_PORT_LEN];
27417836SJohn.Forte@Sun.COM 	boolean_t operandEntered = B_FALSE;
27427836SJohn.Forte@Sun.COM 	boolean_t targetAddressSpecified = B_FALSE;
27437836SJohn.Forte@Sun.COM 	boolean_t printObject = B_FALSE;
27447836SJohn.Forte@Sun.COM 	boolean_t tpgtSpecified = B_FALSE;
27457836SJohn.Forte@Sun.COM 	boolean_t isIpv6 = B_FALSE;
27467836SJohn.Forte@Sun.COM 	int outerLoop;
27477836SJohn.Forte@Sun.COM 	boolean_t found;
27487836SJohn.Forte@Sun.COM 	int i, j;
27497836SJohn.Forte@Sun.COM 	SUN_IMA_DIGEST_ALGORITHM_VALUE digestAlgorithms;
27507836SJohn.Forte@Sun.COM 	boolean_t verbose = B_FALSE;
27517836SJohn.Forte@Sun.COM 	cmdOptions_t *optionList = options;
27527836SJohn.Forte@Sun.COM 	IMA_UINT16 port = 0;
27537836SJohn.Forte@Sun.COM 	IMA_UINT16 tpgt = 0;
27547836SJohn.Forte@Sun.COM 
27557836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
27567836SJohn.Forte@Sun.COM 
27577836SJohn.Forte@Sun.COM 	/* Find Sun initiator */
27587836SJohn.Forte@Sun.COM 	ret = sunInitiatorFind(&initiatorOid);
27597836SJohn.Forte@Sun.COM 	if (ret > 0) {
27607836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s\n",
27617836SJohn.Forte@Sun.COM 		    cmdName, gettext("no initiator found"));
27627836SJohn.Forte@Sun.COM 	}
27637836SJohn.Forte@Sun.COM 
27647836SJohn.Forte@Sun.COM 	if (ret != 0) {
27657836SJohn.Forte@Sun.COM 		return (ret);
27667836SJohn.Forte@Sun.COM 	}
27677836SJohn.Forte@Sun.COM 
27687836SJohn.Forte@Sun.COM 	for (; optionList->optval; optionList++) {
27697836SJohn.Forte@Sun.COM 		switch (optionList->optval) {
27707836SJohn.Forte@Sun.COM 			case 'v':
27717836SJohn.Forte@Sun.COM 				verbose = B_TRUE;
27727836SJohn.Forte@Sun.COM 				break;
27737836SJohn.Forte@Sun.COM 			default:
27747836SJohn.Forte@Sun.COM 				(void) fprintf(stderr, "%s: %c: %s\n",
27757836SJohn.Forte@Sun.COM 				    cmdName, optionList->optval,
27767836SJohn.Forte@Sun.COM 				    gettext("unknown option"));
27777836SJohn.Forte@Sun.COM 				return (1);
27787836SJohn.Forte@Sun.COM 		}
27797836SJohn.Forte@Sun.COM 	}
27807836SJohn.Forte@Sun.COM 
27817836SJohn.Forte@Sun.COM 	/*
27827836SJohn.Forte@Sun.COM 	 * If there are multiple operands, execute outer 'for' loop that
27837836SJohn.Forte@Sun.COM 	 * many times to find each target parameter operand entered, otherwise,
27847836SJohn.Forte@Sun.COM 	 * execute it only once for all target parameters returned.
27857836SJohn.Forte@Sun.COM 	 */
27867836SJohn.Forte@Sun.COM 	if (operandLen > 0) {
27877836SJohn.Forte@Sun.COM 		operandEntered = B_TRUE;
27887836SJohn.Forte@Sun.COM 		outerLoop = operandLen;
27897836SJohn.Forte@Sun.COM 	} else {
27907836SJohn.Forte@Sun.COM 		operandEntered = B_FALSE;
27917836SJohn.Forte@Sun.COM 		outerLoop = 1;
27927836SJohn.Forte@Sun.COM 	}
27937836SJohn.Forte@Sun.COM 
27947836SJohn.Forte@Sun.COM 	/*
27957836SJohn.Forte@Sun.COM 	 * Ideally there should be an interface available for obtaining
27967836SJohn.Forte@Sun.COM 	 * the list of target-param objects. Since the driver currently
27977836SJohn.Forte@Sun.COM 	 * creates a target OID and the associated session structure when
27987836SJohn.Forte@Sun.COM 	 * a target-param object is created, we can leverage the target
27997836SJohn.Forte@Sun.COM 	 * OID list and use it to manage the target-param objects. When
28007836SJohn.Forte@Sun.COM 	 * we stop creating a session for target-param object in the
28017836SJohn.Forte@Sun.COM 	 * driver, we will switch to using a different interface to
28027836SJohn.Forte@Sun.COM 	 * obtain target-param objects.
28037836SJohn.Forte@Sun.COM 	 */
28047836SJohn.Forte@Sun.COM 	status = IMA_GetTargetOidList(initiatorOid, &targetList);
28057836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
28067836SJohn.Forte@Sun.COM 		printLibError(status);
28077836SJohn.Forte@Sun.COM 		*funcRet = 1;
28087836SJohn.Forte@Sun.COM 		return (ret);
28097836SJohn.Forte@Sun.COM 	}
28107836SJohn.Forte@Sun.COM 
28117836SJohn.Forte@Sun.COM 	for (i = 0; i < outerLoop; i++) {
28127836SJohn.Forte@Sun.COM 		if (operandEntered) {
28137836SJohn.Forte@Sun.COM 			if (parseTarget(operand[i],
28147836SJohn.Forte@Sun.COM 			    &targetName[0],
28157836SJohn.Forte@Sun.COM 			    MAX_ISCSI_NAME_LEN + 1,
28167836SJohn.Forte@Sun.COM 			    &targetAddressSpecified,
28177836SJohn.Forte@Sun.COM 			    &targetAddress[0],
28187836SJohn.Forte@Sun.COM 			    SUN_IMA_IP_ADDRESS_PORT_LEN,
28197836SJohn.Forte@Sun.COM 			    &port,
28207836SJohn.Forte@Sun.COM 			    &tpgtSpecified,
28217836SJohn.Forte@Sun.COM 			    &tpgt,
28227836SJohn.Forte@Sun.COM 			    &isIpv6) != PARSE_TARGET_OK) {
28237836SJohn.Forte@Sun.COM 				ret = 1;
28247836SJohn.Forte@Sun.COM 				continue;
28257836SJohn.Forte@Sun.COM 			}
28267836SJohn.Forte@Sun.COM 		}
28277836SJohn.Forte@Sun.COM 		for (j = 0; j < targetList->oidCount; j++) {
28287836SJohn.Forte@Sun.COM 			found = B_FALSE;
28297836SJohn.Forte@Sun.COM 			printObject = B_FALSE;
28307836SJohn.Forte@Sun.COM 			status = SUN_IMA_GetTargetProperties(
28317836SJohn.Forte@Sun.COM 			    targetList->oids[j],
28327836SJohn.Forte@Sun.COM 			    &targetProps);
28337836SJohn.Forte@Sun.COM 			if (!IMA_SUCCESS(status)) {
28347836SJohn.Forte@Sun.COM 				printLibError(status);
28357836SJohn.Forte@Sun.COM 				(void) IMA_FreeMemory(targetList);
28367836SJohn.Forte@Sun.COM 				*funcRet = 1;
28377836SJohn.Forte@Sun.COM 				return (ret);
28387836SJohn.Forte@Sun.COM 			}
28397836SJohn.Forte@Sun.COM 
28407836SJohn.Forte@Sun.COM 			/*
28417836SJohn.Forte@Sun.COM 			 * Compare the target name with the input if
28427836SJohn.Forte@Sun.COM 			 * one was input
28437836SJohn.Forte@Sun.COM 			 */
28447836SJohn.Forte@Sun.COM 			if (operandEntered &&
28457836SJohn.Forte@Sun.COM 			    (targetNamesEqual(targetProps.imaProps.name,
28467836SJohn.Forte@Sun.COM 			    targetName) == B_TRUE)) {
28477836SJohn.Forte@Sun.COM 				/*
28487836SJohn.Forte@Sun.COM 				 * For now, regardless of whether a target
28497836SJohn.Forte@Sun.COM 				 * address is specified, we return B_TRUE
28507836SJohn.Forte@Sun.COM 				 * because IMA_TARGET_PROPERTIES does not
28517836SJohn.Forte@Sun.COM 				 * have a field for specifying address.
28527836SJohn.Forte@Sun.COM 				 */
28537836SJohn.Forte@Sun.COM 				found = B_TRUE;
28547836SJohn.Forte@Sun.COM 			}
28557836SJohn.Forte@Sun.COM 
28567836SJohn.Forte@Sun.COM 			/*
28577836SJohn.Forte@Sun.COM 			 * if no operand was entered OR
28587836SJohn.Forte@Sun.COM 			 * an operand was entered and it was
28597836SJohn.Forte@Sun.COM 			 * found, we want to print
28607836SJohn.Forte@Sun.COM 			 */
28617836SJohn.Forte@Sun.COM 			if (!operandEntered || found) {
28627836SJohn.Forte@Sun.COM 				printObject = B_TRUE;
28637836SJohn.Forte@Sun.COM 			}
28647836SJohn.Forte@Sun.COM 
28657836SJohn.Forte@Sun.COM 			if (printObject) {
28667836SJohn.Forte@Sun.COM 				(void) fprintf(stdout, gettext("%s: %ws\n"),
28677836SJohn.Forte@Sun.COM 				    gettext("Target"),
28687836SJohn.Forte@Sun.COM 				    targetProps.imaProps.name);
28697836SJohn.Forte@Sun.COM 
28707836SJohn.Forte@Sun.COM 				(void) fprintf(stdout,
28717836SJohn.Forte@Sun.COM 				    "\t%s: ", gettext("Alias"));
28727836SJohn.Forte@Sun.COM 				if (wslen(targetProps.imaProps.alias) >
28737836SJohn.Forte@Sun.COM 				    (size_t)0) {
28747836SJohn.Forte@Sun.COM 					(void) fprintf(stdout,
28757836SJohn.Forte@Sun.COM 					    gettext("%ws\n"),
28767836SJohn.Forte@Sun.COM 					    targetProps.imaProps.alias);
28777836SJohn.Forte@Sun.COM 				} else {
28787836SJohn.Forte@Sun.COM 					(void) fprintf(stdout, "%s\n", "-");
28797836SJohn.Forte@Sun.COM 				}
28807836SJohn.Forte@Sun.COM 			}
28817836SJohn.Forte@Sun.COM 
28827836SJohn.Forte@Sun.COM 			if (printObject && verbose) {
28837836SJohn.Forte@Sun.COM 				/* Get bidirectional authentication flag */
28847836SJohn.Forte@Sun.COM 				(void) fprintf(stdout, "\t%s: ",
28857836SJohn.Forte@Sun.COM 				    gettext("Bi-directional Authentication"));
28867836SJohn.Forte@Sun.COM 				status = SUN_IMA_GetTargetBidirAuthFlag(
28877836SJohn.Forte@Sun.COM 				    targetList->oids[j],
28887836SJohn.Forte@Sun.COM 				    &bidirAuth);
28897836SJohn.Forte@Sun.COM 				if (IMA_SUCCESS(status)) {
28907836SJohn.Forte@Sun.COM 					if (bidirAuth == IMA_TRUE) {
28917836SJohn.Forte@Sun.COM 						(void) fprintf(stdout,
28927836SJohn.Forte@Sun.COM 						    gettext("enabled"));
28937836SJohn.Forte@Sun.COM 					} else {
28947836SJohn.Forte@Sun.COM 						(void) fprintf(stdout,
28957836SJohn.Forte@Sun.COM 						    gettext("disabled"));
28967836SJohn.Forte@Sun.COM 					}
28977836SJohn.Forte@Sun.COM 				} else {
28987836SJohn.Forte@Sun.COM 					(void) fprintf(stdout,
28997836SJohn.Forte@Sun.COM 					    gettext("disabled"));
29007836SJohn.Forte@Sun.COM 				}
29017836SJohn.Forte@Sun.COM 				(void) fprintf(stdout, "\n");
29027836SJohn.Forte@Sun.COM 
29037836SJohn.Forte@Sun.COM 				/* Get authentication type for this target */
29047836SJohn.Forte@Sun.COM 				status = SUN_IMA_GetTargetAuthMethods(
29057836SJohn.Forte@Sun.COM 				    initiatorOid,
29067836SJohn.Forte@Sun.COM 				    targetList->oids[j],
29077836SJohn.Forte@Sun.COM 				    &maxEntries,
29087836SJohn.Forte@Sun.COM 				    &methodList[0]);
29097836SJohn.Forte@Sun.COM 				(void) fprintf(stdout, "\t%s: ",
29107836SJohn.Forte@Sun.COM 				    gettext("Authentication Type"));
29117836SJohn.Forte@Sun.COM 				if (!IMA_SUCCESS(status)) {
29127836SJohn.Forte@Sun.COM 					/*
29137836SJohn.Forte@Sun.COM 					 * No authentication method define
29147836SJohn.Forte@Sun.COM 					 * NONE by default.
29157836SJohn.Forte@Sun.COM 					 */
29167836SJohn.Forte@Sun.COM 					(void) fprintf(stdout, gettext("NONE"));
29177836SJohn.Forte@Sun.COM 				} else {
29187836SJohn.Forte@Sun.COM 					for (i = 0; i < maxEntries; i++) {
29197836SJohn.Forte@Sun.COM 						if (i > 0) {
29207836SJohn.Forte@Sun.COM 							(void) fprintf(stdout,
29217836SJohn.Forte@Sun.COM 							    "|");
29227836SJohn.Forte@Sun.COM 						}
29237836SJohn.Forte@Sun.COM 						switch (methodList[i]) {
29247836SJohn.Forte@Sun.COM 						case IMA_AUTHMETHOD_NONE:
29257836SJohn.Forte@Sun.COM 							(void) fprintf(stdout,
29267836SJohn.Forte@Sun.COM 							    gettext("NONE"));
29277836SJohn.Forte@Sun.COM 							break;
29287836SJohn.Forte@Sun.COM 
29297836SJohn.Forte@Sun.COM 						case IMA_AUTHMETHOD_CHAP:
29307836SJohn.Forte@Sun.COM 							(void) fprintf(stdout,
29317836SJohn.Forte@Sun.COM 							    gettext("CHAP"));
29327836SJohn.Forte@Sun.COM 							listCHAPName(
29337836SJohn.Forte@Sun.COM 							    targetList->
29347836SJohn.Forte@Sun.COM 							    oids[j]);
29357836SJohn.Forte@Sun.COM 							break;
29367836SJohn.Forte@Sun.COM 
29377836SJohn.Forte@Sun.COM 						default:
29387836SJohn.Forte@Sun.COM 							(void) fprintf(stdout,
29397836SJohn.Forte@Sun.COM 							    gettext(
29407836SJohn.Forte@Sun.COM 							    "unknown "
29417836SJohn.Forte@Sun.COM 							    "type"));
29427836SJohn.Forte@Sun.COM 							break;
29437836SJohn.Forte@Sun.COM 						}
29447836SJohn.Forte@Sun.COM 					}
29457836SJohn.Forte@Sun.COM 				}
29467836SJohn.Forte@Sun.COM 				(void) fprintf(stdout, "\n");
29477836SJohn.Forte@Sun.COM 				if (printLoginParameters("\t",
29487836SJohn.Forte@Sun.COM 				    targetList->oids[j],
29497836SJohn.Forte@Sun.COM 				    PRINT_CONFIGURED_PARAMS)
29507836SJohn.Forte@Sun.COM 				    != 0) {
29517836SJohn.Forte@Sun.COM 					(void) IMA_FreeMemory(targetList);
29527836SJohn.Forte@Sun.COM 					*funcRet = 1;
29537836SJohn.Forte@Sun.COM 					return (ret);
29547836SJohn.Forte@Sun.COM 				}
29557836SJohn.Forte@Sun.COM 
29567836SJohn.Forte@Sun.COM 				/* Get Digest configuration */
29577836SJohn.Forte@Sun.COM 				status = SUN_IMA_GetHeaderDigest(
29587836SJohn.Forte@Sun.COM 				    targetList->oids[j],
29597836SJohn.Forte@Sun.COM 				    &digestAlgorithms);
29607836SJohn.Forte@Sun.COM 				if (IMA_SUCCESS(status)) {
29617836SJohn.Forte@Sun.COM 					(void) fprintf(stdout, "\t\t%s: ",
29627836SJohn.Forte@Sun.COM 					    gettext("Header Digest"));
29637836SJohn.Forte@Sun.COM 					printDigestAlgorithm(&digestAlgorithms,
29647836SJohn.Forte@Sun.COM 					    PRINT_CONFIGURED_PARAMS);
29657836SJohn.Forte@Sun.COM 				} else {
29667836SJohn.Forte@Sun.COM 					printLibError(status);
29677836SJohn.Forte@Sun.COM 					*funcRet = 1;
29687836SJohn.Forte@Sun.COM 					return (ret);
29697836SJohn.Forte@Sun.COM 				}
29707836SJohn.Forte@Sun.COM 
29717836SJohn.Forte@Sun.COM 				status = SUN_IMA_GetDataDigest(
29727836SJohn.Forte@Sun.COM 				    targetList->oids[j],
29737836SJohn.Forte@Sun.COM 				    &digestAlgorithms);
29747836SJohn.Forte@Sun.COM 				if (IMA_SUCCESS(status)) {
29757836SJohn.Forte@Sun.COM 					(void) fprintf(stdout, "\t\t%s: ",
29767836SJohn.Forte@Sun.COM 					    gettext("Data Digest"));
29777836SJohn.Forte@Sun.COM 					printDigestAlgorithm(&digestAlgorithms,
29787836SJohn.Forte@Sun.COM 					    PRINT_CONFIGURED_PARAMS);
29797836SJohn.Forte@Sun.COM 				} else {
29807836SJohn.Forte@Sun.COM 					printLibError(status);
29817836SJohn.Forte@Sun.COM 					*funcRet = 1;
29827836SJohn.Forte@Sun.COM 					return (ret);
29837836SJohn.Forte@Sun.COM 				}
29847836SJohn.Forte@Sun.COM 
298510156SZhang.Yi@Sun.COM 				/* print tunable parameters infomation */
298610156SZhang.Yi@Sun.COM 				if (printTunableParameters(
298710156SZhang.Yi@Sun.COM 				    targetList->oids[j]) != 0) {
298810156SZhang.Yi@Sun.COM 					*funcRet = 1;
298910156SZhang.Yi@Sun.COM 					return (ret);
299010156SZhang.Yi@Sun.COM 				}
299110156SZhang.Yi@Sun.COM 
29927836SJohn.Forte@Sun.COM 				/* print configured session information */
29937836SJohn.Forte@Sun.COM 				if (printConfiguredSessions(
29947836SJohn.Forte@Sun.COM 				    targetList->oids[j]) != 0) {
29957836SJohn.Forte@Sun.COM 					*funcRet = 1;
29967836SJohn.Forte@Sun.COM 					return (ret);
29977836SJohn.Forte@Sun.COM 				}
29987836SJohn.Forte@Sun.COM 
29997836SJohn.Forte@Sun.COM 				(void) fprintf(stdout, "\n");
30007836SJohn.Forte@Sun.COM 			}
30017836SJohn.Forte@Sun.COM 
30027836SJohn.Forte@Sun.COM 			if (found) {
30037836SJohn.Forte@Sun.COM 				break;
30047836SJohn.Forte@Sun.COM 			}
30057836SJohn.Forte@Sun.COM 		}
30067836SJohn.Forte@Sun.COM 		if (operandEntered && !found) {
30077836SJohn.Forte@Sun.COM 			*funcRet = 1; /* DIY message fix */
30087836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "%s: %s\n",
30097836SJohn.Forte@Sun.COM 			    operand[i], gettext("not found"));
30107836SJohn.Forte@Sun.COM 		}
30117836SJohn.Forte@Sun.COM 	}
30127836SJohn.Forte@Sun.COM 
30137836SJohn.Forte@Sun.COM 	(void) IMA_FreeMemory(targetList);
30147836SJohn.Forte@Sun.COM 	return (ret);
30157836SJohn.Forte@Sun.COM }
30167836SJohn.Forte@Sun.COM 
30177836SJohn.Forte@Sun.COM /*
30187836SJohn.Forte@Sun.COM  * Modify discovery attributes
30197836SJohn.Forte@Sun.COM  */
30207836SJohn.Forte@Sun.COM static int
modifyDiscovery(cmdOptions_t * options,int * funcRet)30217836SJohn.Forte@Sun.COM modifyDiscovery(cmdOptions_t *options, int *funcRet)
30227836SJohn.Forte@Sun.COM {
30237836SJohn.Forte@Sun.COM 	IMA_OID oid;
30247836SJohn.Forte@Sun.COM 	IMA_STATUS status;
30257836SJohn.Forte@Sun.COM 	IMA_BOOL setDiscovery;
30267836SJohn.Forte@Sun.COM 	IMA_HOST_ID hostId;
30277836SJohn.Forte@Sun.COM 
30287836SJohn.Forte@Sun.COM 	int ret;
30297836SJohn.Forte@Sun.COM 	cmdOptions_t *optionList = options;
30307836SJohn.Forte@Sun.COM 
30317836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
30327836SJohn.Forte@Sun.COM 
30337836SJohn.Forte@Sun.COM 	/* Find Sun initiator */
30347836SJohn.Forte@Sun.COM 	ret = sunInitiatorFind(&oid);
30357836SJohn.Forte@Sun.COM 	if (ret > 0) {
30367836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s\n",
30377836SJohn.Forte@Sun.COM 		    cmdName, gettext("no initiator found"));
30387836SJohn.Forte@Sun.COM 	}
30397836SJohn.Forte@Sun.COM 
30407836SJohn.Forte@Sun.COM 	if (ret != 0) {
30417836SJohn.Forte@Sun.COM 		return (ret);
30427836SJohn.Forte@Sun.COM 	}
30437836SJohn.Forte@Sun.COM 
30447836SJohn.Forte@Sun.COM 	for (; optionList->optval; optionList++) {
30457836SJohn.Forte@Sun.COM 		/* check optarg and set bool accordingly */
30467836SJohn.Forte@Sun.COM 		if (strcasecmp(optionList->optarg, ISCSIADM_ARG_ENABLE) == 0) {
30477836SJohn.Forte@Sun.COM 			setDiscovery = IMA_TRUE;
30487836SJohn.Forte@Sun.COM 		} else if (strcasecmp(optionList->optarg, ISCSIADM_ARG_DISABLE)
30497836SJohn.Forte@Sun.COM 		    == 0) {
30507836SJohn.Forte@Sun.COM 			setDiscovery = IMA_FALSE;
30517836SJohn.Forte@Sun.COM 		} else {
30527836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s\n",
30537836SJohn.Forte@Sun.COM 			    cmdName, gettext("invalid option argument"));
30547836SJohn.Forte@Sun.COM 			return (1);
30557836SJohn.Forte@Sun.COM 		}
30567836SJohn.Forte@Sun.COM 
30577836SJohn.Forte@Sun.COM 		switch (optionList->optval) {
30587836SJohn.Forte@Sun.COM 			case 's':
30597836SJohn.Forte@Sun.COM 				/* Set static discovery */
30607836SJohn.Forte@Sun.COM 				status = IMA_SetStaticDiscovery(oid,
30617836SJohn.Forte@Sun.COM 				    setDiscovery);
30627836SJohn.Forte@Sun.COM 				if (!IMA_SUCCESS(status)) {
30637836SJohn.Forte@Sun.COM 					printLibError(status);
30647836SJohn.Forte@Sun.COM 					*funcRet = 1;
30657836SJohn.Forte@Sun.COM 					return (ret);
30667836SJohn.Forte@Sun.COM 				}
30677836SJohn.Forte@Sun.COM 				break;
30687836SJohn.Forte@Sun.COM 			case 't':
30697836SJohn.Forte@Sun.COM 				/* Set send targets discovery */
30707836SJohn.Forte@Sun.COM 				status = IMA_SetSendTargetsDiscovery(oid,
30717836SJohn.Forte@Sun.COM 				    setDiscovery);
30727836SJohn.Forte@Sun.COM 				if (!IMA_SUCCESS(status)) {
30737836SJohn.Forte@Sun.COM 					printLibError(status);
30747836SJohn.Forte@Sun.COM 					*funcRet = 1;
30757836SJohn.Forte@Sun.COM 					return (ret);
30767836SJohn.Forte@Sun.COM 				}
30777836SJohn.Forte@Sun.COM 				break;
30787836SJohn.Forte@Sun.COM 			case 'i':
30797836SJohn.Forte@Sun.COM 				/* Set iSNS discovery */
30807836SJohn.Forte@Sun.COM 				(void) memset(&hostId, 0, sizeof (hostId));
30817836SJohn.Forte@Sun.COM 				status = IMA_SetIsnsDiscovery(oid, setDiscovery,
30827836SJohn.Forte@Sun.COM 				    IMA_ISNS_DISCOVERY_METHOD_STATIC, &hostId);
30837836SJohn.Forte@Sun.COM 				if (!IMA_SUCCESS(status)) {
30847836SJohn.Forte@Sun.COM 					printLibError(status);
30857836SJohn.Forte@Sun.COM 					*funcRet = 1;
30867836SJohn.Forte@Sun.COM 					return (ret);
30877836SJohn.Forte@Sun.COM 				}
30887836SJohn.Forte@Sun.COM 				break;
30897836SJohn.Forte@Sun.COM 			default:
30907836SJohn.Forte@Sun.COM 				(void) fprintf(stderr, "%s: %c: %s\n",
30917836SJohn.Forte@Sun.COM 				    cmdName, optionList->optval,
30927836SJohn.Forte@Sun.COM 				    gettext("unknown option"));
30937836SJohn.Forte@Sun.COM 				return (1);
30947836SJohn.Forte@Sun.COM 		}
30957836SJohn.Forte@Sun.COM 	}
30967836SJohn.Forte@Sun.COM 
30977836SJohn.Forte@Sun.COM 	return (ret);
30987836SJohn.Forte@Sun.COM }
30997836SJohn.Forte@Sun.COM 
31007836SJohn.Forte@Sun.COM /*
31017836SJohn.Forte@Sun.COM  * Set the initiator node's authentication method
31027836SJohn.Forte@Sun.COM  */
31037836SJohn.Forte@Sun.COM static int
modifyNodeAuthParam(IMA_OID oid,int param,char * chapName,int * funcRet)31047836SJohn.Forte@Sun.COM modifyNodeAuthParam(IMA_OID oid, int param, char *chapName, int *funcRet)
31057836SJohn.Forte@Sun.COM {
31067836SJohn.Forte@Sun.COM 	IMA_INITIATOR_AUTHPARMS authParams;
31077836SJohn.Forte@Sun.COM 	IMA_STATUS status;
31087836SJohn.Forte@Sun.COM 	int ret;
31097836SJohn.Forte@Sun.COM 	int secretLen = MAX_CHAP_SECRET_LEN;
3110*12546SBing.Zhao@Sun.COM 	int nameLen = 0;
31117836SJohn.Forte@Sun.COM 
31127836SJohn.Forte@Sun.COM 	IMA_BYTE chapSecret[MAX_CHAP_SECRET_LEN + 1];
31137836SJohn.Forte@Sun.COM 
31147836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
31157836SJohn.Forte@Sun.COM 
31167836SJohn.Forte@Sun.COM 	/*
31177836SJohn.Forte@Sun.COM 	 * Start with existing parameters and modify with the desired change
31187836SJohn.Forte@Sun.COM 	 * before passing along.  We ignore any failures as they probably
31197836SJohn.Forte@Sun.COM 	 * are caused by non-existence of auth params for the given node.
31207836SJohn.Forte@Sun.COM 	 */
31217836SJohn.Forte@Sun.COM 	status = IMA_GetInitiatorAuthParms(oid, IMA_AUTHMETHOD_CHAP,
31227836SJohn.Forte@Sun.COM 	    &authParams);
31237836SJohn.Forte@Sun.COM 
31247836SJohn.Forte@Sun.COM 	switch (param) {
31257836SJohn.Forte@Sun.COM 	case AUTH_NAME:
31267836SJohn.Forte@Sun.COM 		if (chapName == NULL) {
31277836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "CHAP name cannot be NULL.\n");
31287836SJohn.Forte@Sun.COM 			return (1);
31297836SJohn.Forte@Sun.COM 		}
3130*12546SBing.Zhao@Sun.COM 		nameLen = strlen(chapName);
3131*12546SBing.Zhao@Sun.COM 		if (nameLen == 0) {
31329896SJack.Meng@Sun.COM 			(void) fprintf(stderr, "CHAP name cannot be empty.\n");
31339896SJack.Meng@Sun.COM 			return (1);
31349896SJack.Meng@Sun.COM 		}
3135*12546SBing.Zhao@Sun.COM 		if (nameLen > ISCSI_MAX_C_USER_LEN) {
3136*12546SBing.Zhao@Sun.COM 			(void) fprintf(stderr, "CHAP name is too long.\n");
3137*12546SBing.Zhao@Sun.COM 			return (1);
3138*12546SBing.Zhao@Sun.COM 		}
31397836SJohn.Forte@Sun.COM 		(void) memset(&authParams.chapParms.name, 0,
31407836SJohn.Forte@Sun.COM 		    sizeof (authParams.chapParms.name));
31417836SJohn.Forte@Sun.COM 		(void) memcpy(&authParams.chapParms.name,
3142*12546SBing.Zhao@Sun.COM 		    &chapName[0], nameLen);
3143*12546SBing.Zhao@Sun.COM 		authParams.chapParms.nameLength = nameLen;
31447836SJohn.Forte@Sun.COM 		break;
31457836SJohn.Forte@Sun.COM 
31467836SJohn.Forte@Sun.COM 	case AUTH_PASSWORD :
31477836SJohn.Forte@Sun.COM 		ret = getSecret((char *)&chapSecret[0], &secretLen,
31487836SJohn.Forte@Sun.COM 		    MIN_CHAP_SECRET_LEN, MAX_CHAP_SECRET_LEN);
31497836SJohn.Forte@Sun.COM 
31507836SJohn.Forte@Sun.COM 		if (ret != 0) {
31517836SJohn.Forte@Sun.COM 			return (ret);
31527836SJohn.Forte@Sun.COM 		}
31537836SJohn.Forte@Sun.COM 
31547836SJohn.Forte@Sun.COM 		(void) memset(&authParams.chapParms.challengeSecret, 0,
31557836SJohn.Forte@Sun.COM 		    sizeof (authParams.chapParms.challengeSecret));
31567836SJohn.Forte@Sun.COM 		(void) memcpy(&authParams.chapParms.challengeSecret,
31577836SJohn.Forte@Sun.COM 		    &chapSecret[0], secretLen);
31587836SJohn.Forte@Sun.COM 		authParams.chapParms.challengeSecretLength = secretLen;
31597836SJohn.Forte@Sun.COM 		break;
31607836SJohn.Forte@Sun.COM 
31617836SJohn.Forte@Sun.COM 	default:
31627836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "Invalid auth parameter %d\n", param);
31637836SJohn.Forte@Sun.COM 		return (1);
31647836SJohn.Forte@Sun.COM 	}
31657836SJohn.Forte@Sun.COM 
31667836SJohn.Forte@Sun.COM 	status = IMA_SetInitiatorAuthParms(oid, IMA_AUTHMETHOD_CHAP,
31677836SJohn.Forte@Sun.COM 	    &authParams);
31687836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
31697836SJohn.Forte@Sun.COM 		printLibError(status);
31707836SJohn.Forte@Sun.COM 		*funcRet = 1;
31717836SJohn.Forte@Sun.COM 	}
31727836SJohn.Forte@Sun.COM 	return (ret);
31737836SJohn.Forte@Sun.COM }
31747836SJohn.Forte@Sun.COM 
31757836SJohn.Forte@Sun.COM /*
31767836SJohn.Forte@Sun.COM  * Set the target's authentication method
31777836SJohn.Forte@Sun.COM  */
31787836SJohn.Forte@Sun.COM static int
modifyTargetAuthParam(IMA_OID oid,int param,char * chapName,int * funcRet)31797836SJohn.Forte@Sun.COM modifyTargetAuthParam(IMA_OID oid, int param, char *chapName, int *funcRet)
31807836SJohn.Forte@Sun.COM {
31817836SJohn.Forte@Sun.COM 	IMA_INITIATOR_AUTHPARMS authParams;
31827836SJohn.Forte@Sun.COM 	IMA_STATUS status;
31837836SJohn.Forte@Sun.COM 	int ret;
31847836SJohn.Forte@Sun.COM 	int secretLen = MAX_CHAP_SECRET_LEN;
3185*12546SBing.Zhao@Sun.COM 	int nameLen = 0;
31867836SJohn.Forte@Sun.COM 
31877836SJohn.Forte@Sun.COM 	IMA_BYTE chapSecret[MAX_CHAP_SECRET_LEN + 1];
31887836SJohn.Forte@Sun.COM 
31897836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
31907836SJohn.Forte@Sun.COM 
31917836SJohn.Forte@Sun.COM 	/*
31927836SJohn.Forte@Sun.COM 	 * Start with existing parameters and modify with the desired change
31937836SJohn.Forte@Sun.COM 	 * before passing along.  We ignore any get failures as they probably
31947836SJohn.Forte@Sun.COM 	 * are caused by non-existence of auth params for the given target.
31957836SJohn.Forte@Sun.COM 	 */
31967836SJohn.Forte@Sun.COM 	status = SUN_IMA_GetTargetAuthParms(oid, IMA_AUTHMETHOD_CHAP,
31977836SJohn.Forte@Sun.COM 	    &authParams);
31987836SJohn.Forte@Sun.COM 
31997836SJohn.Forte@Sun.COM 	switch (param) {
32007836SJohn.Forte@Sun.COM 	case AUTH_NAME:
32017836SJohn.Forte@Sun.COM 		if (chapName == NULL) {
32027836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "CHAP name cannot be NULL.\n");
32037836SJohn.Forte@Sun.COM 			return (1);
32047836SJohn.Forte@Sun.COM 		}
3205*12546SBing.Zhao@Sun.COM 		nameLen = strlen(chapName);
3206*12546SBing.Zhao@Sun.COM 		if (nameLen == 0) {
32079896SJack.Meng@Sun.COM 			(void) fprintf(stderr, "CHAP name cannot be empty.\n");
32089896SJack.Meng@Sun.COM 			return (1);
32099896SJack.Meng@Sun.COM 		}
3210*12546SBing.Zhao@Sun.COM 		if (nameLen > ISCSI_MAX_C_USER_LEN) {
3211*12546SBing.Zhao@Sun.COM 			(void) fprintf(stderr, "CHAP name is too long.\n");
3212*12546SBing.Zhao@Sun.COM 			return (1);
3213*12546SBing.Zhao@Sun.COM 		}
32147836SJohn.Forte@Sun.COM 		(void) memset(&authParams.chapParms.name, 0,
32157836SJohn.Forte@Sun.COM 		    sizeof (authParams.chapParms.name));
32167836SJohn.Forte@Sun.COM 		(void) memcpy(&authParams.chapParms.name,
3217*12546SBing.Zhao@Sun.COM 		    &chapName[0], nameLen);
3218*12546SBing.Zhao@Sun.COM 		authParams.chapParms.nameLength = nameLen;
32197836SJohn.Forte@Sun.COM 		break;
32207836SJohn.Forte@Sun.COM 
32217836SJohn.Forte@Sun.COM 	case AUTH_PASSWORD :
32227836SJohn.Forte@Sun.COM 		ret = getSecret((char *)&chapSecret[0], &secretLen,
32237836SJohn.Forte@Sun.COM 		    1, MAX_CHAP_SECRET_LEN);
32247836SJohn.Forte@Sun.COM 
32257836SJohn.Forte@Sun.COM 		if (ret != 0) {
32267836SJohn.Forte@Sun.COM 			return (ret);
32277836SJohn.Forte@Sun.COM 		}
32287836SJohn.Forte@Sun.COM 
32297836SJohn.Forte@Sun.COM 		(void) memset(&authParams.chapParms.challengeSecret, 0,
32307836SJohn.Forte@Sun.COM 		    sizeof (authParams.chapParms.challengeSecret));
32317836SJohn.Forte@Sun.COM 		(void) memcpy(&authParams.chapParms.challengeSecret,
32327836SJohn.Forte@Sun.COM 		    &chapSecret[0], secretLen);
32337836SJohn.Forte@Sun.COM 		authParams.chapParms.challengeSecretLength = secretLen;
32347836SJohn.Forte@Sun.COM 		break;
32357836SJohn.Forte@Sun.COM 
32367836SJohn.Forte@Sun.COM 	default:
32377836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "Invalid auth parameter %d\n", param);
32387836SJohn.Forte@Sun.COM 		return (1);
32397836SJohn.Forte@Sun.COM 	}
32407836SJohn.Forte@Sun.COM 
32417836SJohn.Forte@Sun.COM 	status = SUN_IMA_SetTargetAuthParams(oid, IMA_AUTHMETHOD_CHAP,
32427836SJohn.Forte@Sun.COM 	    &authParams);
32437836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
32447836SJohn.Forte@Sun.COM 		printLibError(status);
32457836SJohn.Forte@Sun.COM 		*funcRet = 1;
32467836SJohn.Forte@Sun.COM 	}
32477836SJohn.Forte@Sun.COM 	return (0);
32487836SJohn.Forte@Sun.COM }
32497836SJohn.Forte@Sun.COM 
32507836SJohn.Forte@Sun.COM static int
modifyTargetBidirAuthFlag(IMA_OID targetOid,char * optarg,int * funcRet)32517836SJohn.Forte@Sun.COM modifyTargetBidirAuthFlag(IMA_OID targetOid, char *optarg, int *funcRet)
32527836SJohn.Forte@Sun.COM {
32537836SJohn.Forte@Sun.COM 	IMA_BOOL boolValue;
32547836SJohn.Forte@Sun.COM 	IMA_STATUS status;
32557836SJohn.Forte@Sun.COM 
32567836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
32577836SJohn.Forte@Sun.COM 
32587836SJohn.Forte@Sun.COM 	if (strcasecmp(optarg, ISCSIADM_ARG_ENABLE) == 0) {
32597836SJohn.Forte@Sun.COM 		boolValue = IMA_TRUE;
32607836SJohn.Forte@Sun.COM 	} else if (strcasecmp(optarg, ISCSIADM_ARG_DISABLE) == 0) {
32617836SJohn.Forte@Sun.COM 		boolValue = IMA_FALSE;
32627836SJohn.Forte@Sun.COM 	} else {
32637836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s %s\n",
32647836SJohn.Forte@Sun.COM 		    cmdName, gettext("invalid option argument"), optarg);
32657836SJohn.Forte@Sun.COM 		return (1);
32667836SJohn.Forte@Sun.COM 	}
32677836SJohn.Forte@Sun.COM 
32687836SJohn.Forte@Sun.COM 	status = SUN_IMA_SetTargetBidirAuthFlag(targetOid, &boolValue);
32697836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
32707836SJohn.Forte@Sun.COM 		printLibError(status);
32717836SJohn.Forte@Sun.COM 		*funcRet = 1;
32727836SJohn.Forte@Sun.COM 	}
32737836SJohn.Forte@Sun.COM 	return (0);
32747836SJohn.Forte@Sun.COM }
32757836SJohn.Forte@Sun.COM 
32767836SJohn.Forte@Sun.COM static int
modifyConfiguredSessions(IMA_OID targetOid,char * optarg)32777836SJohn.Forte@Sun.COM modifyConfiguredSessions(IMA_OID targetOid, char *optarg)
32787836SJohn.Forte@Sun.COM {
32797836SJohn.Forte@Sun.COM 	SUN_IMA_CONFIG_SESSIONS *pConfigSessions;
32807836SJohn.Forte@Sun.COM 	IMA_STATUS		status;
32817836SJohn.Forte@Sun.COM 	int			sessions;
32827836SJohn.Forte@Sun.COM 	int			size;
32837836SJohn.Forte@Sun.COM 	char			tmp[1024];
32847836SJohn.Forte@Sun.COM 	boolean_t		isIpv6 = B_FALSE;
32857836SJohn.Forte@Sun.COM 	uint16_t		port;
32867836SJohn.Forte@Sun.COM 	char			address[MAX_ADDRESS_LEN];
32877836SJohn.Forte@Sun.COM 	char			*commaPos;
32887836SJohn.Forte@Sun.COM 	char			*addressPos;
32897836SJohn.Forte@Sun.COM 	int			rtn;
32907836SJohn.Forte@Sun.COM 
32917836SJohn.Forte@Sun.COM 	/*
32927836SJohn.Forte@Sun.COM 	 * Strip the first int value from the string.  If we sprintf
32937836SJohn.Forte@Sun.COM 	 * this back to a string and it matches the original string
32947836SJohn.Forte@Sun.COM 	 * then this command is using default binding.  If not a
32957836SJohn.Forte@Sun.COM 	 * match we have hard coded binding or a usage error.
32967836SJohn.Forte@Sun.COM 	 */
32977836SJohn.Forte@Sun.COM 	sessions = atoi(optarg);
32987836SJohn.Forte@Sun.COM 	(void) sprintf(tmp, "%d", sessions);
32997836SJohn.Forte@Sun.COM 	if (strcmp(optarg, tmp) == 0) {
33007836SJohn.Forte@Sun.COM 		/* default binding */
33017836SJohn.Forte@Sun.COM 
33027836SJohn.Forte@Sun.COM 		/* allocate the required pConfigSessions */
33037836SJohn.Forte@Sun.COM 		size = sizeof (SUN_IMA_CONFIG_SESSIONS);
33047836SJohn.Forte@Sun.COM 		pConfigSessions = (SUN_IMA_CONFIG_SESSIONS *)calloc(1, size);
33057836SJohn.Forte@Sun.COM 		if (pConfigSessions == NULL) {
33067836SJohn.Forte@Sun.COM 			return (1);
33077836SJohn.Forte@Sun.COM 		}
33087836SJohn.Forte@Sun.COM 
33097836SJohn.Forte@Sun.COM 		/* setup pConfigSessions */
33107836SJohn.Forte@Sun.COM 		pConfigSessions->bound	= IMA_FALSE;
33117836SJohn.Forte@Sun.COM 		pConfigSessions->in	= sessions;
33127836SJohn.Forte@Sun.COM 		pConfigSessions->out	= 0;
33137836SJohn.Forte@Sun.COM 	} else {
33147836SJohn.Forte@Sun.COM 		/* hardcoded binding */
33157836SJohn.Forte@Sun.COM 
33167836SJohn.Forte@Sun.COM 		/*
33177836SJohn.Forte@Sun.COM 		 * First we need to determine how many bindings
33187836SJohn.Forte@Sun.COM 		 * are available.  This can be done by scanning
33197836SJohn.Forte@Sun.COM 		 * for the number of ',' + 1.
33207836SJohn.Forte@Sun.COM 		 */
33217836SJohn.Forte@Sun.COM 		sessions = 1;
33227836SJohn.Forte@Sun.COM 		commaPos = strchr(optarg, ',');
33237836SJohn.Forte@Sun.COM 		while (commaPos != NULL) {
33247836SJohn.Forte@Sun.COM 			sessions++;
33257836SJohn.Forte@Sun.COM 			commaPos = strchr(++commaPos, ',');
33267836SJohn.Forte@Sun.COM 		}
33277836SJohn.Forte@Sun.COM 
33287836SJohn.Forte@Sun.COM 		/* allocate the required pConfigSessions */
33297836SJohn.Forte@Sun.COM 		size = sizeof (SUN_IMA_CONFIG_SESSIONS) + ((sessions - 1) *
33307836SJohn.Forte@Sun.COM 		    sizeof (IMA_ADDRESS_KEY));
33317836SJohn.Forte@Sun.COM 		pConfigSessions = (SUN_IMA_CONFIG_SESSIONS *)calloc(1, size);
33327836SJohn.Forte@Sun.COM 		if (pConfigSessions == NULL) {
33337836SJohn.Forte@Sun.COM 			return (1);
33347836SJohn.Forte@Sun.COM 		}
33357836SJohn.Forte@Sun.COM 
33367836SJohn.Forte@Sun.COM 		/* setup pConfigSessions */
33377836SJohn.Forte@Sun.COM 		pConfigSessions->bound	= IMA_TRUE;
33387836SJohn.Forte@Sun.COM 		pConfigSessions->in	= sessions;
33397836SJohn.Forte@Sun.COM 		pConfigSessions->out	= 0;
33407836SJohn.Forte@Sun.COM 
33417836SJohn.Forte@Sun.COM 		/* Now fill in the binding information.  */
33427836SJohn.Forte@Sun.COM 		sessions = 0;
33437836SJohn.Forte@Sun.COM 		addressPos = optarg;
33447836SJohn.Forte@Sun.COM 		/*
33457836SJohn.Forte@Sun.COM 		 * Walk thru possible address strings
33467836SJohn.Forte@Sun.COM 		 * stop once all strings are processed.
33477836SJohn.Forte@Sun.COM 		 */
33487836SJohn.Forte@Sun.COM 		while (addressPos != NULL) {
33497836SJohn.Forte@Sun.COM 			/*
33507836SJohn.Forte@Sun.COM 			 * Check if there is another address after this
33517836SJohn.Forte@Sun.COM 			 * one. If so terminate the current address and
33527836SJohn.Forte@Sun.COM 			 * keep a pointer to the next one.
33537836SJohn.Forte@Sun.COM 			 */
33547836SJohn.Forte@Sun.COM 			commaPos = strchr(addressPos, ',');
33557836SJohn.Forte@Sun.COM 			if (commaPos != NULL) {
33567836SJohn.Forte@Sun.COM 				*commaPos++ = 0x00;
33577836SJohn.Forte@Sun.COM 			}
33587836SJohn.Forte@Sun.COM 
33597836SJohn.Forte@Sun.COM 			/*
33607836SJohn.Forte@Sun.COM 			 * Parse current address.  If invalid abort
33617836SJohn.Forte@Sun.COM 			 * processing of addresses and free memory.
33627836SJohn.Forte@Sun.COM 			 */
33637836SJohn.Forte@Sun.COM 			if (parseAddress(addressPos, 0, address,
33647836SJohn.Forte@Sun.COM 			    MAX_ADDRESS_LEN, &port, &isIpv6) != PARSE_ADDR_OK) {
33657836SJohn.Forte@Sun.COM 				free(pConfigSessions);
33667836SJohn.Forte@Sun.COM 				printLibError(IMA_ERROR_INVALID_PARAMETER);
33677836SJohn.Forte@Sun.COM 				return (1);
33687836SJohn.Forte@Sun.COM 			}
33697836SJohn.Forte@Sun.COM 
33707836SJohn.Forte@Sun.COM 			/* Convert address into binary form */
33717836SJohn.Forte@Sun.COM 			if (isIpv6 == B_FALSE) {
33727836SJohn.Forte@Sun.COM 				pConfigSessions->bindings[sessions].
33737836SJohn.Forte@Sun.COM 				    ipAddress.ipv4Address = IMA_TRUE;
33747836SJohn.Forte@Sun.COM 				rtn = inet_pton(AF_INET, address,
33757836SJohn.Forte@Sun.COM 				    pConfigSessions->bindings[sessions].
33767836SJohn.Forte@Sun.COM 				    ipAddress.ipAddress);
33777836SJohn.Forte@Sun.COM 			} else {
33787836SJohn.Forte@Sun.COM 				pConfigSessions->bindings[sessions].ipAddress.
33797836SJohn.Forte@Sun.COM 				    ipv4Address =
33807836SJohn.Forte@Sun.COM 				    IMA_FALSE;
33817836SJohn.Forte@Sun.COM 				rtn = inet_pton(AF_INET6, address,
33827836SJohn.Forte@Sun.COM 				    pConfigSessions->bindings[sessions].
33837836SJohn.Forte@Sun.COM 				    ipAddress.ipAddress);
33847836SJohn.Forte@Sun.COM 			}
33857836SJohn.Forte@Sun.COM 			if (rtn == 0) {
33867836SJohn.Forte@Sun.COM 				/* inet_pton found address invalid */
33877836SJohn.Forte@Sun.COM 				free(pConfigSessions);
33887836SJohn.Forte@Sun.COM 				printLibError(IMA_ERROR_INVALID_PARAMETER);
33897836SJohn.Forte@Sun.COM 				return (1);
33907836SJohn.Forte@Sun.COM 			}
33917836SJohn.Forte@Sun.COM 
33927836SJohn.Forte@Sun.COM 			/* update addressPos to next address */
33937836SJohn.Forte@Sun.COM 			sessions++;
33947836SJohn.Forte@Sun.COM 			addressPos = commaPos;
33957836SJohn.Forte@Sun.COM 		}
33967836SJohn.Forte@Sun.COM 	}
33977836SJohn.Forte@Sun.COM 
33987836SJohn.Forte@Sun.COM 	/* issue SUN_IMA request */
33997836SJohn.Forte@Sun.COM 	status = SUN_IMA_SetConfigSessions(targetOid,
34007836SJohn.Forte@Sun.COM 	    pConfigSessions);
34017836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
34027836SJohn.Forte@Sun.COM 		printLibError(status);
34037836SJohn.Forte@Sun.COM 		free(pConfigSessions);
34047836SJohn.Forte@Sun.COM 		return (1);
34057836SJohn.Forte@Sun.COM 	}
34067836SJohn.Forte@Sun.COM 
34077836SJohn.Forte@Sun.COM 	free(pConfigSessions);
34087836SJohn.Forte@Sun.COM 	return (0);
34097836SJohn.Forte@Sun.COM }
34107836SJohn.Forte@Sun.COM 
34117836SJohn.Forte@Sun.COM static int
getAuthMethodValue(char * method,IMA_AUTHMETHOD * value)34127836SJohn.Forte@Sun.COM getAuthMethodValue(char *method, IMA_AUTHMETHOD *value)
34137836SJohn.Forte@Sun.COM {
34147836SJohn.Forte@Sun.COM 	if (strcasecmp(method, "chap") == 0) {
34157836SJohn.Forte@Sun.COM 		*value = IMA_AUTHMETHOD_CHAP;
34167836SJohn.Forte@Sun.COM 		return (0);
34177836SJohn.Forte@Sun.COM 	}
34187836SJohn.Forte@Sun.COM 
34197836SJohn.Forte@Sun.COM 	if (strcasecmp(method, "none") == 0) {
34207836SJohn.Forte@Sun.COM 		*value =  IMA_AUTHMETHOD_NONE;
34217836SJohn.Forte@Sun.COM 		return (0);
34227836SJohn.Forte@Sun.COM 	}
34237836SJohn.Forte@Sun.COM 
34247836SJohn.Forte@Sun.COM 	return (1);
34257836SJohn.Forte@Sun.COM }
34267836SJohn.Forte@Sun.COM 
34277836SJohn.Forte@Sun.COM 
34287836SJohn.Forte@Sun.COM /*
34297836SJohn.Forte@Sun.COM  * Set the authentication method
34307836SJohn.Forte@Sun.COM  * Currently only supports CHAP and NONE
34317836SJohn.Forte@Sun.COM  */
34327836SJohn.Forte@Sun.COM static int
modifyNodeAuthMethod(IMA_OID oid,char * optarg,int * funcRet)34337836SJohn.Forte@Sun.COM modifyNodeAuthMethod(IMA_OID oid, char *optarg, int *funcRet)
34347836SJohn.Forte@Sun.COM {
34357836SJohn.Forte@Sun.COM 	IMA_AUTHMETHOD methodList[MAX_AUTH_METHODS];
34367836SJohn.Forte@Sun.COM 	IMA_UINT methodCount = 0;
34377836SJohn.Forte@Sun.COM 	IMA_STATUS status;
34387836SJohn.Forte@Sun.COM 	IMA_AUTHMETHOD value;
34397836SJohn.Forte@Sun.COM 	char *method;
34407836SJohn.Forte@Sun.COM 	char *commaPos;
34417836SJohn.Forte@Sun.COM 
34427836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
34437836SJohn.Forte@Sun.COM 
34447836SJohn.Forte@Sun.COM 	/*
34457836SJohn.Forte@Sun.COM 	 * optarg will be a , delimited set of auth methods, in order
34467836SJohn.Forte@Sun.COM 	 * of preference
34477836SJohn.Forte@Sun.COM 	 * if any values here are incorrect, return without setting
34487836SJohn.Forte@Sun.COM 	 * anything.
34497836SJohn.Forte@Sun.COM 	 */
34507836SJohn.Forte@Sun.COM 	method = optarg;
34517836SJohn.Forte@Sun.COM 
34527836SJohn.Forte@Sun.COM 	commaPos = strchr(optarg, ',');
34537836SJohn.Forte@Sun.COM 
34547836SJohn.Forte@Sun.COM 	while (commaPos && methodCount < MAX_AUTH_METHODS) {
34557836SJohn.Forte@Sun.COM 		*commaPos = NULL;
34567836SJohn.Forte@Sun.COM 		if (getAuthMethodValue(method, &value) != 0) {
34577836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: a: %s\n",
34587836SJohn.Forte@Sun.COM 			    cmdName, gettext("invalid option argument"));
34597836SJohn.Forte@Sun.COM 			return (1);
34607836SJohn.Forte@Sun.COM 		}
34617836SJohn.Forte@Sun.COM 		methodList[methodCount++] = value;
34627836SJohn.Forte@Sun.COM 		commaPos++;
34637836SJohn.Forte@Sun.COM 		method = commaPos;
34647836SJohn.Forte@Sun.COM 		commaPos = strchr(method, ',');
34657836SJohn.Forte@Sun.COM 	}
34667836SJohn.Forte@Sun.COM 	/* Should not find more method specified - if found, error */
34677836SJohn.Forte@Sun.COM 	if (commaPos) {
34687836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: -a: %s\n",
34697836SJohn.Forte@Sun.COM 		    cmdName, gettext("invalid option argument"));
34707836SJohn.Forte@Sun.COM 		return (1);
34717836SJohn.Forte@Sun.COM 	}
34727836SJohn.Forte@Sun.COM 	if (getAuthMethodValue(method, &value) != 0) {
34737836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: -a: %s\n",
34747836SJohn.Forte@Sun.COM 		    cmdName, gettext("invalid option argument"));
34757836SJohn.Forte@Sun.COM 		return (1);
34767836SJohn.Forte@Sun.COM 	}
34777836SJohn.Forte@Sun.COM 	methodList[methodCount++] = value;
34787836SJohn.Forte@Sun.COM 
34797836SJohn.Forte@Sun.COM 	status = IMA_SetInitiatorAuthMethods(oid, methodCount, &methodList[0]);
34807836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
34817836SJohn.Forte@Sun.COM 		printLibError(status);
34827836SJohn.Forte@Sun.COM 		*funcRet = 1;
34837836SJohn.Forte@Sun.COM 	}
34847836SJohn.Forte@Sun.COM 	return (0);
34857836SJohn.Forte@Sun.COM }
34867836SJohn.Forte@Sun.COM 
34877836SJohn.Forte@Sun.COM static int
modifyTargetAuthMethod(IMA_OID oid,char * optarg,int * funcRet)34887836SJohn.Forte@Sun.COM modifyTargetAuthMethod(IMA_OID oid, char *optarg, int *funcRet)
34897836SJohn.Forte@Sun.COM {
34907836SJohn.Forte@Sun.COM 	IMA_AUTHMETHOD methodList[MAX_AUTH_METHODS];
34917836SJohn.Forte@Sun.COM 	IMA_UINT methodCount = 0;
34927836SJohn.Forte@Sun.COM 	IMA_STATUS status;
34937836SJohn.Forte@Sun.COM 	IMA_AUTHMETHOD value;
34947836SJohn.Forte@Sun.COM 	char *method;
34957836SJohn.Forte@Sun.COM 	char *commaPos;
34967836SJohn.Forte@Sun.COM 
34977836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
34987836SJohn.Forte@Sun.COM 
34997836SJohn.Forte@Sun.COM 	/*
35007836SJohn.Forte@Sun.COM 	 * optarg will be a , delimited set of auth methods, in order
35017836SJohn.Forte@Sun.COM 	 * of preference
35027836SJohn.Forte@Sun.COM 	 * if any values here are incorrect, return without setting
35037836SJohn.Forte@Sun.COM 	 * anything.
35047836SJohn.Forte@Sun.COM 	 */
35057836SJohn.Forte@Sun.COM 	method = optarg;
35067836SJohn.Forte@Sun.COM 
35077836SJohn.Forte@Sun.COM 	commaPos = strchr(optarg, ',');
35087836SJohn.Forte@Sun.COM 
35097836SJohn.Forte@Sun.COM 	while (commaPos && methodCount < MAX_AUTH_METHODS) {
35107836SJohn.Forte@Sun.COM 		*commaPos = NULL;
35117836SJohn.Forte@Sun.COM 		if (getAuthMethodValue(method, &value) != 0) {
35127836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: a: %s\n",
35137836SJohn.Forte@Sun.COM 			    cmdName, gettext("invalid option argument"));
35147836SJohn.Forte@Sun.COM 			return (1);
35157836SJohn.Forte@Sun.COM 		}
35167836SJohn.Forte@Sun.COM 		methodList[methodCount++] = value;
35177836SJohn.Forte@Sun.COM 		commaPos++;
35187836SJohn.Forte@Sun.COM 		method = commaPos;
35197836SJohn.Forte@Sun.COM 		commaPos = strchr(method, ',');
35207836SJohn.Forte@Sun.COM 	}
35217836SJohn.Forte@Sun.COM 	/* Should not find more method specified - if found, error */
35227836SJohn.Forte@Sun.COM 	if (commaPos) {
35237836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: -a: %s\n",
35247836SJohn.Forte@Sun.COM 		    cmdName, gettext("invalid option argument"));
35257836SJohn.Forte@Sun.COM 		return (1);
35267836SJohn.Forte@Sun.COM 	}
35277836SJohn.Forte@Sun.COM 	if (getAuthMethodValue(method, &value) != 0) {
35287836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: -a: %s\n",
35297836SJohn.Forte@Sun.COM 		    cmdName, gettext("invalid option argument"));
35307836SJohn.Forte@Sun.COM 		return (1);
35317836SJohn.Forte@Sun.COM 	}
35327836SJohn.Forte@Sun.COM 	methodList[methodCount++] = value;
35337836SJohn.Forte@Sun.COM 
35347836SJohn.Forte@Sun.COM 	status = SUN_IMA_SetTargetAuthMethods(oid, &methodCount,
35357836SJohn.Forte@Sun.COM 	    &methodList[0]);
35367836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
35377836SJohn.Forte@Sun.COM 		printLibError(status);
35387836SJohn.Forte@Sun.COM 		*funcRet = 1;
35397836SJohn.Forte@Sun.COM 	}
35407836SJohn.Forte@Sun.COM 	return (0);
35417836SJohn.Forte@Sun.COM }
35427836SJohn.Forte@Sun.COM 
35437836SJohn.Forte@Sun.COM /*
35447836SJohn.Forte@Sun.COM  * Modify the RADIUS configuration of the initiator node.
35457836SJohn.Forte@Sun.COM  *
35467836SJohn.Forte@Sun.COM  * Return 0 on success.
35477836SJohn.Forte@Sun.COM  */
35487836SJohn.Forte@Sun.COM static int
modifyNodeRadiusConfig(IMA_OID oid,char * optarg,int * funcRet)35497836SJohn.Forte@Sun.COM modifyNodeRadiusConfig(IMA_OID oid, char *optarg, int *funcRet)
35507836SJohn.Forte@Sun.COM {
35517836SJohn.Forte@Sun.COM 	SUN_IMA_RADIUS_CONFIG config;
35527836SJohn.Forte@Sun.COM 	IMA_STATUS status;
35537836SJohn.Forte@Sun.COM 	boolean_t isIpv6 = B_FALSE;
35547836SJohn.Forte@Sun.COM 	uint16_t port;
35557836SJohn.Forte@Sun.COM 
35567836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
35577836SJohn.Forte@Sun.COM 
35587836SJohn.Forte@Sun.COM 	(void) memset(&config, 0, sizeof (SUN_IMA_RADIUS_CONFIG));
35597836SJohn.Forte@Sun.COM 	if (parseAddress(optarg, DEFAULT_RADIUS_PORT,
35607836SJohn.Forte@Sun.COM 	    &config.hostnameIpAddress[0], SUN_IMA_IP_ADDRESS_PORT_LEN,
35617836SJohn.Forte@Sun.COM 	    &port, &isIpv6) !=
35627836SJohn.Forte@Sun.COM 	    PARSE_ADDR_OK) {
35637836SJohn.Forte@Sun.COM 		return (1);
35647836SJohn.Forte@Sun.COM 	}
35657836SJohn.Forte@Sun.COM 	config.port = (IMA_UINT16)port;
35667836SJohn.Forte@Sun.COM 	config.isIpv6 = (isIpv6 == B_TRUE) ? IMA_TRUE : IMA_FALSE;
35677836SJohn.Forte@Sun.COM 	/* Not setting shared secret here. */
35687836SJohn.Forte@Sun.COM 	config.sharedSecretValid = IMA_FALSE;
35697836SJohn.Forte@Sun.COM 
35707836SJohn.Forte@Sun.COM 	status = SUN_IMA_SetInitiatorRadiusConfig(oid, &config);
35717836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
35727836SJohn.Forte@Sun.COM 		printLibError(status);
35737836SJohn.Forte@Sun.COM 		*funcRet = 1;
35747836SJohn.Forte@Sun.COM 	}
35757836SJohn.Forte@Sun.COM 
35767836SJohn.Forte@Sun.COM 	return (0);
35777836SJohn.Forte@Sun.COM }
35787836SJohn.Forte@Sun.COM 
35797836SJohn.Forte@Sun.COM /*
35807836SJohn.Forte@Sun.COM  * Modify the RADIUS access flag of the initiator node.
35817836SJohn.Forte@Sun.COM  *
35827836SJohn.Forte@Sun.COM  * Return 0 on success.
35837836SJohn.Forte@Sun.COM  */
35847836SJohn.Forte@Sun.COM static int
modifyNodeRadiusAccess(IMA_OID oid,char * optarg,int * funcRet)35857836SJohn.Forte@Sun.COM modifyNodeRadiusAccess(IMA_OID oid, char *optarg, int *funcRet)
35867836SJohn.Forte@Sun.COM {
35877836SJohn.Forte@Sun.COM 	IMA_BOOL radiusAccess;
35887836SJohn.Forte@Sun.COM 	IMA_OID initiatorOid;
35897836SJohn.Forte@Sun.COM 	IMA_STATUS status;
35907836SJohn.Forte@Sun.COM 	SUN_IMA_RADIUS_CONFIG radiusConfig;
35917836SJohn.Forte@Sun.COM 	int ret;
35927836SJohn.Forte@Sun.COM 
35937836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
35947836SJohn.Forte@Sun.COM 
35957836SJohn.Forte@Sun.COM 	/* Check if Radius Config is there */
35967836SJohn.Forte@Sun.COM 	ret = sunInitiatorFind(&initiatorOid);
35977836SJohn.Forte@Sun.COM 	if (ret != 0) {
35987836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s\n",
35997836SJohn.Forte@Sun.COM 		    cmdName, gettext("no initiator found"));
36007836SJohn.Forte@Sun.COM 		return (1);
36017836SJohn.Forte@Sun.COM 	}
36027836SJohn.Forte@Sun.COM 	(void) memset(&radiusConfig, 0, sizeof (SUN_IMA_RADIUS_CONFIG));
36037836SJohn.Forte@Sun.COM 	status = SUN_IMA_GetInitiatorRadiusConfig(initiatorOid, &radiusConfig);
36047836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
36057836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s\n",
36067836SJohn.Forte@Sun.COM 		    cmdName, gettext("RADIUS server not configured yet"));
36077836SJohn.Forte@Sun.COM 		*funcRet = 1;
36087836SJohn.Forte@Sun.COM 		return (ret);
36097836SJohn.Forte@Sun.COM 	}
36107836SJohn.Forte@Sun.COM 
36117836SJohn.Forte@Sun.COM 	/* Check if Radius Shared is set */
36127836SJohn.Forte@Sun.COM 	if (radiusConfig.sharedSecretValid == IMA_FALSE) {
36137836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s\n", cmdName,
36147836SJohn.Forte@Sun.COM 		    gettext("RADIUS server secret not configured yet"));
36157836SJohn.Forte@Sun.COM 		return (1);
36167836SJohn.Forte@Sun.COM 	}
36177836SJohn.Forte@Sun.COM 
36187836SJohn.Forte@Sun.COM 	if (strcasecmp(optarg, ISCSIADM_ARG_ENABLE) == 0) {
36197836SJohn.Forte@Sun.COM 		radiusAccess = IMA_TRUE;
36207836SJohn.Forte@Sun.COM 	} else if (strcasecmp(optarg, ISCSIADM_ARG_DISABLE) == 0) {
36217836SJohn.Forte@Sun.COM 		radiusAccess = IMA_FALSE;
36227836SJohn.Forte@Sun.COM 	} else {
36237836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s %s\n",
36247836SJohn.Forte@Sun.COM 		    cmdName,
36257836SJohn.Forte@Sun.COM 		    gettext("invalid option argument"),
36267836SJohn.Forte@Sun.COM 		    optarg);
36277836SJohn.Forte@Sun.COM 		return (1);
36287836SJohn.Forte@Sun.COM 	}
36297836SJohn.Forte@Sun.COM 	status = SUN_IMA_SetInitiatorRadiusAccess(oid, radiusAccess);
36307836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
36317836SJohn.Forte@Sun.COM 		printLibError(status);
36327836SJohn.Forte@Sun.COM 		*funcRet = 1;
36337836SJohn.Forte@Sun.COM 	}
36347836SJohn.Forte@Sun.COM 
36357836SJohn.Forte@Sun.COM 	return (ret);
36367836SJohn.Forte@Sun.COM }
36377836SJohn.Forte@Sun.COM 
36387836SJohn.Forte@Sun.COM /*
36397836SJohn.Forte@Sun.COM  * Modify the RADIUS shared secret.
36407836SJohn.Forte@Sun.COM  *
36417836SJohn.Forte@Sun.COM  * Returns:
36427836SJohn.Forte@Sun.COM  *  zero on success.
36437836SJohn.Forte@Sun.COM  *  > 0 on failure.
36447836SJohn.Forte@Sun.COM  */
36457836SJohn.Forte@Sun.COM static int
modifyNodeRadiusSharedSecret(IMA_OID oid,int * funcRet)36467836SJohn.Forte@Sun.COM modifyNodeRadiusSharedSecret(IMA_OID oid, int *funcRet)
36477836SJohn.Forte@Sun.COM {
36487836SJohn.Forte@Sun.COM 	IMA_BYTE radiusSharedSecret[SUN_IMA_MAX_RADIUS_SECRET_LEN + 1];
36497836SJohn.Forte@Sun.COM 	IMA_OID initiatorOid;
36507836SJohn.Forte@Sun.COM 	IMA_STATUS status;
36517836SJohn.Forte@Sun.COM 	SUN_IMA_RADIUS_CONFIG radiusConfig;
36527836SJohn.Forte@Sun.COM 	int ret;
36537836SJohn.Forte@Sun.COM 	int secretLen = SUN_IMA_MAX_RADIUS_SECRET_LEN;
36547836SJohn.Forte@Sun.COM 
36557836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
36567836SJohn.Forte@Sun.COM 
36577836SJohn.Forte@Sun.COM 	ret = getSecret((char *)&radiusSharedSecret[0], &secretLen,
36587836SJohn.Forte@Sun.COM 	    0, SUN_IMA_MAX_RADIUS_SECRET_LEN);
36597836SJohn.Forte@Sun.COM 	if (ret != 0) {
36607836SJohn.Forte@Sun.COM 		return (1);
36617836SJohn.Forte@Sun.COM 	}
36627836SJohn.Forte@Sun.COM 
36637836SJohn.Forte@Sun.COM 	ret = sunInitiatorFind(&initiatorOid);
36647836SJohn.Forte@Sun.COM 	if (ret > 0) {
36657836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s\n",
36667836SJohn.Forte@Sun.COM 		    cmdName, gettext("no initiator found"));
36677836SJohn.Forte@Sun.COM 	}
36687836SJohn.Forte@Sun.COM 	if (ret != 0) {
36697836SJohn.Forte@Sun.COM 		return (1);
36707836SJohn.Forte@Sun.COM 	}
36717836SJohn.Forte@Sun.COM 	/* First obtain existing RADIUS configuration (if any) */
36727836SJohn.Forte@Sun.COM 	(void) memset(&radiusConfig, 0, sizeof (SUN_IMA_RADIUS_CONFIG));
36737836SJohn.Forte@Sun.COM 	status = SUN_IMA_GetInitiatorRadiusConfig(initiatorOid, &radiusConfig);
36747836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
36757836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s\n",
36767836SJohn.Forte@Sun.COM 		    cmdName, gettext("RADIUS server not configured yet"));
36777836SJohn.Forte@Sun.COM 		return (1);
36787836SJohn.Forte@Sun.COM 	}
36797836SJohn.Forte@Sun.COM 
36807836SJohn.Forte@Sun.COM 	/* Modify the shared secret only */
36817836SJohn.Forte@Sun.COM 	radiusConfig.sharedSecretLength = secretLen;
36827836SJohn.Forte@Sun.COM 	(void) memcpy(&radiusConfig.sharedSecret,
36837836SJohn.Forte@Sun.COM 	    &radiusSharedSecret[0], secretLen);
36847836SJohn.Forte@Sun.COM 	radiusConfig.sharedSecretValid = IMA_TRUE;
36857836SJohn.Forte@Sun.COM 	status = SUN_IMA_SetInitiatorRadiusConfig(oid, &radiusConfig);
36867836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
36877836SJohn.Forte@Sun.COM 		printLibError(status);
36887836SJohn.Forte@Sun.COM 		*funcRet = 1;
36897836SJohn.Forte@Sun.COM 	}
36907836SJohn.Forte@Sun.COM 
36917836SJohn.Forte@Sun.COM 	return (0);
36927836SJohn.Forte@Sun.COM }
36937836SJohn.Forte@Sun.COM 
36947836SJohn.Forte@Sun.COM /*
36957836SJohn.Forte@Sun.COM  * Set initiator node attributes.
36967836SJohn.Forte@Sun.COM  */
36977836SJohn.Forte@Sun.COM static int
modifyNode(cmdOptions_t * options,int * funcRet)36987836SJohn.Forte@Sun.COM modifyNode(cmdOptions_t *options, int *funcRet)
36997836SJohn.Forte@Sun.COM {
37007836SJohn.Forte@Sun.COM 	IMA_NODE_NAME	nodeName;
37017836SJohn.Forte@Sun.COM 	IMA_NODE_ALIAS	nodeAlias;
37027836SJohn.Forte@Sun.COM 	IMA_OID		oid;
37037836SJohn.Forte@Sun.COM 	IMA_STATUS	status;
37047836SJohn.Forte@Sun.COM 	cmdOptions_t	*optionList = options;
37057836SJohn.Forte@Sun.COM 	int		ret;
37067836SJohn.Forte@Sun.COM 	iSCSINameCheckStatusType nameCheckStatus;
37077836SJohn.Forte@Sun.COM 	IMA_OID sharedNodeOid;
37088265SBing.Zhao@Sun.COM 	int 		i;
37098265SBing.Zhao@Sun.COM 	int 		lowerCase;
37108194SJack.Meng@Sun.COM 	IMA_BOOL	iscsiBoot = IMA_FALSE;
37118194SJack.Meng@Sun.COM 	IMA_BOOL	mpxioEnabled = IMA_FALSE;
37128265SBing.Zhao@Sun.COM 	char		*mb_name = NULL;
37138265SBing.Zhao@Sun.COM 	int		prefixlen = 0;
37147836SJohn.Forte@Sun.COM 
37157836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
37167836SJohn.Forte@Sun.COM 
37178194SJack.Meng@Sun.COM 	/* Get boot session's info */
37188194SJack.Meng@Sun.COM 	(void) SUN_IMA_GetBootIscsi(&iscsiBoot);
37198194SJack.Meng@Sun.COM 	if (iscsiBoot == IMA_TRUE) {
37208194SJack.Meng@Sun.COM 		status = SUN_IMA_GetBootMpxio(&mpxioEnabled);
37218194SJack.Meng@Sun.COM 		if (!IMA_SUCCESS(status)) {
37228194SJack.Meng@Sun.COM 			(void) fprintf(stderr, "%s: %s\n",
37238194SJack.Meng@Sun.COM 			    cmdName, gettext("unable to get MPxIO info"
37248194SJack.Meng@Sun.COM 			    " of root disk"));
37258194SJack.Meng@Sun.COM 			*funcRet = 1;
37268194SJack.Meng@Sun.COM 			return (1);
37278194SJack.Meng@Sun.COM 		}
37288194SJack.Meng@Sun.COM 	}
37298194SJack.Meng@Sun.COM 
37307836SJohn.Forte@Sun.COM 	/* Find Sun initiator */
37317836SJohn.Forte@Sun.COM 	ret = sunInitiatorFind(&oid);
37328389SJack.Meng@Sun.COM 	if (ret != 0) {
37337836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s\n",
37347836SJohn.Forte@Sun.COM 		    cmdName, gettext("no initiator found"));
37357836SJohn.Forte@Sun.COM 		return (ret);
37367836SJohn.Forte@Sun.COM 	}
37377836SJohn.Forte@Sun.COM 
37387836SJohn.Forte@Sun.COM 	for (; optionList->optval; optionList++) {
37397836SJohn.Forte@Sun.COM 		switch (optionList->optval) {
37407836SJohn.Forte@Sun.COM 			case 'N':
37417836SJohn.Forte@Sun.COM 				if (strlen(optionList->optarg) >=
37427836SJohn.Forte@Sun.COM 				    MAX_ISCSI_NAME_LEN) {
37437836SJohn.Forte@Sun.COM 					(void) fprintf(stderr, "%s: %s %d\n",
37447836SJohn.Forte@Sun.COM 					    cmdName,
37457836SJohn.Forte@Sun.COM 					    gettext("name too long, \
37467836SJohn.Forte@Sun.COM 					    maximum length is:"),
37477836SJohn.Forte@Sun.COM 					    MAX_ISCSI_NAME_LEN);
37487836SJohn.Forte@Sun.COM 				}
37497836SJohn.Forte@Sun.COM 
37507836SJohn.Forte@Sun.COM 				/* Take the first operand as node name. */
37517836SJohn.Forte@Sun.COM 				(void) memset(&nodeName, 0,
37527836SJohn.Forte@Sun.COM 				    sizeof (IMA_NODE_NAME));
37537836SJohn.Forte@Sun.COM 				if (mbstowcs(nodeName, optionList->optarg,
37547836SJohn.Forte@Sun.COM 				    IMA_NODE_NAME_LEN) == (size_t)-1) {
37557836SJohn.Forte@Sun.COM 					(void) fprintf(stderr, "%s: %s\n",
37567836SJohn.Forte@Sun.COM 					    cmdName,
37577836SJohn.Forte@Sun.COM 					    gettext("conversion error"));
37587836SJohn.Forte@Sun.COM 					return (1);
37597836SJohn.Forte@Sun.COM 				}
37607836SJohn.Forte@Sun.COM 
37618265SBing.Zhao@Sun.COM 				prefixlen = strlen(ISCSI_IQN_NAME_PREFIX);
37628265SBing.Zhao@Sun.COM 				mb_name = (char *)calloc(1, prefixlen + 1);
37638265SBing.Zhao@Sun.COM 				if (mb_name == NULL) {
37648265SBing.Zhao@Sun.COM 					return (1);
37658265SBing.Zhao@Sun.COM 				}
37668265SBing.Zhao@Sun.COM 
37678265SBing.Zhao@Sun.COM 				if (wcstombs(mb_name, nodeName,
37688265SBing.Zhao@Sun.COM 				    prefixlen) == (size_t)-1) {
37698265SBing.Zhao@Sun.COM 					(void) fprintf(stderr, "%s: %s\n",
37708265SBing.Zhao@Sun.COM 					    cmdName,
37718265SBing.Zhao@Sun.COM 					    gettext("conversion error"));
37728265SBing.Zhao@Sun.COM 					(void) IMA_FreeMemory(mb_name);
37738265SBing.Zhao@Sun.COM 					return (1);
37747836SJohn.Forte@Sun.COM 				}
37758265SBing.Zhao@Sun.COM 				if (strncmp(mb_name, ISCSI_IQN_NAME_PREFIX,
37768265SBing.Zhao@Sun.COM 				    prefixlen) == 0) {
37778265SBing.Zhao@Sun.COM 					/*
37788265SBing.Zhao@Sun.COM 					 * For iqn format, we should map
37798265SBing.Zhao@Sun.COM 					 * the upper-case characters to
37808265SBing.Zhao@Sun.COM 					 * their lower-case equivalents.
37818265SBing.Zhao@Sun.COM 					 */
37828265SBing.Zhao@Sun.COM 					for (i = 0; nodeName[i] != 0; i++) {
37838265SBing.Zhao@Sun.COM 						lowerCase =
37848265SBing.Zhao@Sun.COM 						    tolower(nodeName[i]);
37858265SBing.Zhao@Sun.COM 						nodeName[i] = lowerCase;
37868265SBing.Zhao@Sun.COM 					}
37878265SBing.Zhao@Sun.COM 				}
37888265SBing.Zhao@Sun.COM 				(void) IMA_FreeMemory(mb_name);
37898265SBing.Zhao@Sun.COM 
37907836SJohn.Forte@Sun.COM 				/* Perform string profile checks */
37917836SJohn.Forte@Sun.COM 				nameCheckStatus =
37927836SJohn.Forte@Sun.COM 				    iSCSINameStringProfileCheck(nodeName);
37937836SJohn.Forte@Sun.COM 				iSCSINameCheckStatusDisplay(nameCheckStatus);
37947836SJohn.Forte@Sun.COM 				if (nameCheckStatus != iSCSINameCheckOK) {
37957836SJohn.Forte@Sun.COM 					*funcRet = 1; /* DIY message fix */
37967836SJohn.Forte@Sun.COM 					return (1);
37977836SJohn.Forte@Sun.COM 				}
37987836SJohn.Forte@Sun.COM 
37997836SJohn.Forte@Sun.COM 				/*
38007836SJohn.Forte@Sun.COM 				 * IMA_GetSharedNodeOid(&sharedNodeOid);
38017836SJohn.Forte@Sun.COM 				 * if (!IMA_SUCCESS(status)) {
38027836SJohn.Forte@Sun.COM 				 *   printLibError(status);
38037836SJohn.Forte@Sun.COM 				 *   return (INF_ERROR);
38047836SJohn.Forte@Sun.COM 				 * }
38057836SJohn.Forte@Sun.COM 				 */
38068194SJack.Meng@Sun.COM 				if (iscsiBoot == IMA_TRUE) {
38078194SJack.Meng@Sun.COM 					(void) fprintf(stderr, "%s: %s\n",
38088194SJack.Meng@Sun.COM 					    cmdName, gettext("iscsi boot, not"
38098194SJack.Meng@Sun.COM 					    " allowed to change"
38108194SJack.Meng@Sun.COM 					    " initiator's name"));
38118194SJack.Meng@Sun.COM 					return (1);
38128194SJack.Meng@Sun.COM 				}
38137836SJohn.Forte@Sun.COM 				oid.objectType = IMA_OBJECT_TYPE_NODE;
38147836SJohn.Forte@Sun.COM 				status = IMA_SetNodeName(oid, nodeName);
38157836SJohn.Forte@Sun.COM 				if (!IMA_SUCCESS(status)) {
38167836SJohn.Forte@Sun.COM 					printLibError(status);
38177836SJohn.Forte@Sun.COM 					*funcRet = 1;
38187836SJohn.Forte@Sun.COM 					return (ret);
38197836SJohn.Forte@Sun.COM 				}
38207836SJohn.Forte@Sun.COM 				break;
38217836SJohn.Forte@Sun.COM 
38227836SJohn.Forte@Sun.COM 			case 'A':
38238194SJack.Meng@Sun.COM 				if (iscsiBoot == IMA_TRUE) {
38248194SJack.Meng@Sun.COM 					(void) fprintf(stderr, "%s: %s\n",
38258194SJack.Meng@Sun.COM 					    cmdName, gettext("iscsi boot, not"
38268194SJack.Meng@Sun.COM 					    " allowed to change"
38278194SJack.Meng@Sun.COM 					    " initiator's alias"));
38288194SJack.Meng@Sun.COM 					return (1);
38298194SJack.Meng@Sun.COM 				}
38307836SJohn.Forte@Sun.COM 				/* Take the first operand as node alias. */
38317836SJohn.Forte@Sun.COM 				if (strlen(optionList->optarg) >=
38327836SJohn.Forte@Sun.COM 				    MAX_ISCSI_NAME_LEN) {
38337836SJohn.Forte@Sun.COM 					(void) fprintf(stderr, "%s: %s %d\n",
38347836SJohn.Forte@Sun.COM 					    cmdName,
38357836SJohn.Forte@Sun.COM 					    gettext("alias too long, maximum  \
38367836SJohn.Forte@Sun.COM 					    length is:"),
38377836SJohn.Forte@Sun.COM 					    MAX_ISCSI_NAME_LEN);
38387836SJohn.Forte@Sun.COM 				}
38397836SJohn.Forte@Sun.COM 
38407836SJohn.Forte@Sun.COM 				(void) memset(&nodeAlias, 0,
38417836SJohn.Forte@Sun.COM 				    sizeof (IMA_NODE_ALIAS));
38427836SJohn.Forte@Sun.COM 				if (mbstowcs(nodeAlias, optionList->optarg,
38437836SJohn.Forte@Sun.COM 				    IMA_NODE_ALIAS_LEN) == (size_t)-1) {
38447836SJohn.Forte@Sun.COM 					(void) fprintf(stderr, "%s: %s\n",
38457836SJohn.Forte@Sun.COM 					    cmdName,
38467836SJohn.Forte@Sun.COM 					    gettext("conversion error"));
38477836SJohn.Forte@Sun.COM 					return (1);
38487836SJohn.Forte@Sun.COM 				}
38497836SJohn.Forte@Sun.COM 
38507836SJohn.Forte@Sun.COM 				status = IMA_GetSharedNodeOid(&sharedNodeOid);
38517836SJohn.Forte@Sun.COM 				if (!IMA_SUCCESS(status)) {
38527836SJohn.Forte@Sun.COM 					printLibError(status);
38537836SJohn.Forte@Sun.COM 					*funcRet = 1;
38547836SJohn.Forte@Sun.COM 					return (ret);
38557836SJohn.Forte@Sun.COM 				}
38567836SJohn.Forte@Sun.COM 
38577836SJohn.Forte@Sun.COM 				status = IMA_SetNodeAlias(sharedNodeOid,
38587836SJohn.Forte@Sun.COM 				    nodeAlias);
38597836SJohn.Forte@Sun.COM 				if (!IMA_SUCCESS(status)) {
38607836SJohn.Forte@Sun.COM 					printLibError(status);
38617836SJohn.Forte@Sun.COM 					*funcRet = 1;
38627836SJohn.Forte@Sun.COM 					return (ret);
38637836SJohn.Forte@Sun.COM 				}
38647836SJohn.Forte@Sun.COM 				break;
38657836SJohn.Forte@Sun.COM 
38667836SJohn.Forte@Sun.COM 			case 'a':
38678194SJack.Meng@Sun.COM 				if (iscsiBoot == IMA_TRUE) {
38688194SJack.Meng@Sun.COM 					(void) fprintf(stderr, "%s: %s\n",
38698194SJack.Meng@Sun.COM 					    cmdName, gettext("iscsi boot, not"
38708194SJack.Meng@Sun.COM 					    " allowed to change authentication"
38718194SJack.Meng@Sun.COM 					    " method"));
38728194SJack.Meng@Sun.COM 					return (1);
38738194SJack.Meng@Sun.COM 				}
38747836SJohn.Forte@Sun.COM 				if (modifyNodeAuthMethod(oid, options->optarg,
38757836SJohn.Forte@Sun.COM 				    funcRet) != 0) {
38767836SJohn.Forte@Sun.COM 					return (1);
38777836SJohn.Forte@Sun.COM 				}
38787836SJohn.Forte@Sun.COM 				break;
38797836SJohn.Forte@Sun.COM 
38807836SJohn.Forte@Sun.COM 			case 'R':
38817836SJohn.Forte@Sun.COM 				if (modifyNodeRadiusAccess(oid, options->optarg,
38827836SJohn.Forte@Sun.COM 				    funcRet) != 0) {
38837836SJohn.Forte@Sun.COM 					return (1);
38847836SJohn.Forte@Sun.COM 				}
38857836SJohn.Forte@Sun.COM 				break;
38867836SJohn.Forte@Sun.COM 
38877836SJohn.Forte@Sun.COM 			case 'r':
38887836SJohn.Forte@Sun.COM 				if (modifyNodeRadiusConfig(oid, options->optarg,
38897836SJohn.Forte@Sun.COM 				    funcRet) != 0) {
38907836SJohn.Forte@Sun.COM 					return (1);
38917836SJohn.Forte@Sun.COM 				}
38927836SJohn.Forte@Sun.COM 				break;
38937836SJohn.Forte@Sun.COM 
38947836SJohn.Forte@Sun.COM 			case 'P':
38957836SJohn.Forte@Sun.COM 				if (modifyNodeRadiusSharedSecret(oid, funcRet)
38967836SJohn.Forte@Sun.COM 				    != 0) {
38977836SJohn.Forte@Sun.COM 					return (1);
38987836SJohn.Forte@Sun.COM 				}
38997836SJohn.Forte@Sun.COM 				break;
39007836SJohn.Forte@Sun.COM 
39017836SJohn.Forte@Sun.COM 			case 'C':
39028194SJack.Meng@Sun.COM 				if (iscsiBoot == IMA_TRUE) {
39038194SJack.Meng@Sun.COM 					(void) fprintf(stderr, "%s: %s\n",
39048194SJack.Meng@Sun.COM 					    cmdName, gettext("iscsi boot, not"
39058194SJack.Meng@Sun.COM 					    " allowed to change CHAP secret"));
39068194SJack.Meng@Sun.COM 					return (1);
39078194SJack.Meng@Sun.COM 				}
39087836SJohn.Forte@Sun.COM 				if (modifyNodeAuthParam(oid, AUTH_PASSWORD,
39097836SJohn.Forte@Sun.COM 				    NULL, funcRet) != 0) {
39107836SJohn.Forte@Sun.COM 					return (1);
39117836SJohn.Forte@Sun.COM 				}
39127836SJohn.Forte@Sun.COM 				break;
39137836SJohn.Forte@Sun.COM 
39147836SJohn.Forte@Sun.COM 			case 'c':
39158194SJack.Meng@Sun.COM 				if (iscsiBoot == IMA_TRUE) {
39168194SJack.Meng@Sun.COM 					if (mpxioEnabled == IMA_FALSE) {
39178194SJack.Meng@Sun.COM 						(void) fprintf(stderr,
39188194SJack.Meng@Sun.COM 						    "%s: %s\n", cmdName,
39198194SJack.Meng@Sun.COM 						    gettext("iscsi"
39208194SJack.Meng@Sun.COM 						    " boot and MPxIO"
39218194SJack.Meng@Sun.COM 						    " is disabled, not allowed"
39228194SJack.Meng@Sun.COM 						    " to change number of"
39238194SJack.Meng@Sun.COM 						    " sessions to be"
39248194SJack.Meng@Sun.COM 						    " configured"));
39258194SJack.Meng@Sun.COM 						return (1);
39268194SJack.Meng@Sun.COM 					}
39278194SJack.Meng@Sun.COM 				}
39287836SJohn.Forte@Sun.COM 				if (modifyConfiguredSessions(oid,
39297836SJohn.Forte@Sun.COM 				    optionList->optarg) != 0) {
39308194SJack.Meng@Sun.COM 					if (iscsiBoot == IMA_TRUE) {
39318194SJack.Meng@Sun.COM 						(void) fprintf(stderr,
39328194SJack.Meng@Sun.COM 						    "%s: %s\n", cmdName,
39338194SJack.Meng@Sun.COM 						    gettext("iscsi boot,"
39348194SJack.Meng@Sun.COM 						    " fail to set configured"
39358194SJack.Meng@Sun.COM 						    " session"));
39368194SJack.Meng@Sun.COM 					}
39377836SJohn.Forte@Sun.COM 					return (1);
39387836SJohn.Forte@Sun.COM 				}
39397836SJohn.Forte@Sun.COM 				break;
39407836SJohn.Forte@Sun.COM 
39418194SJack.Meng@Sun.COM 
39427836SJohn.Forte@Sun.COM 			case 'H':
39438194SJack.Meng@Sun.COM 				if (iscsiBoot == IMA_TRUE) {
39448194SJack.Meng@Sun.COM 					(void) fprintf(stderr, "%s: %s\n",
39458194SJack.Meng@Sun.COM 					    cmdName, gettext("iscsi boot, not"
39468194SJack.Meng@Sun.COM 					    " allowed to change CHAP name"));
39478194SJack.Meng@Sun.COM 					return (1);
39488194SJack.Meng@Sun.COM 				}
39497836SJohn.Forte@Sun.COM 				if (modifyNodeAuthParam(oid, AUTH_NAME,
39507836SJohn.Forte@Sun.COM 				    optionList->optarg, funcRet) != 0) {
39517836SJohn.Forte@Sun.COM 					return (1);
39527836SJohn.Forte@Sun.COM 				}
39537836SJohn.Forte@Sun.COM 				break;
39547836SJohn.Forte@Sun.COM 
39558194SJack.Meng@Sun.COM 
39567836SJohn.Forte@Sun.COM 			case 'd':
39578194SJack.Meng@Sun.COM 				if (iscsiBoot == IMA_TRUE) {
39588194SJack.Meng@Sun.COM 					if (mpxioEnabled == IMA_FALSE) {
39598194SJack.Meng@Sun.COM 						(void) fprintf(stderr,
39608194SJack.Meng@Sun.COM 						    "%s: %s\n", cmdName,
39618194SJack.Meng@Sun.COM 						    gettext("iscsi"
39628194SJack.Meng@Sun.COM 						    " boot and MPxIO"
39638194SJack.Meng@Sun.COM 						    " is disabled, not"
39648194SJack.Meng@Sun.COM 						    " allowed to"
39658194SJack.Meng@Sun.COM 						    " change initiator's"
39668194SJack.Meng@Sun.COM 						    " login params"));
39678194SJack.Meng@Sun.COM 						return (1);
39688194SJack.Meng@Sun.COM 					}
39698194SJack.Meng@Sun.COM 				}
39707836SJohn.Forte@Sun.COM 				if (setLoginParameter(oid, DATA_DIGEST,
39717836SJohn.Forte@Sun.COM 				    optionList->optarg) != 0) {
39727836SJohn.Forte@Sun.COM 					return (1);
39737836SJohn.Forte@Sun.COM 				}
39747836SJohn.Forte@Sun.COM 				break;
39757836SJohn.Forte@Sun.COM 
39767836SJohn.Forte@Sun.COM 			case 'h':
39778194SJack.Meng@Sun.COM 				if (iscsiBoot == IMA_TRUE) {
39788194SJack.Meng@Sun.COM 					if (mpxioEnabled == IMA_FALSE) {
39798194SJack.Meng@Sun.COM 						(void) fprintf(stderr,
39808194SJack.Meng@Sun.COM 						    "%s: %s\n", cmdName,
39818194SJack.Meng@Sun.COM 						    gettext("iscsi"
39828194SJack.Meng@Sun.COM 						    " boot and MPxIO"
39838194SJack.Meng@Sun.COM 						    " is disabled, not"
39848194SJack.Meng@Sun.COM 						    " allowed to"
39858194SJack.Meng@Sun.COM 						    " change initiator's"
39868194SJack.Meng@Sun.COM 						    " login params"));
39878194SJack.Meng@Sun.COM 						return (1);
39888194SJack.Meng@Sun.COM 					}
39898194SJack.Meng@Sun.COM 				}
39907836SJohn.Forte@Sun.COM 				if (setLoginParameter(oid, HEADER_DIGEST,
39917836SJohn.Forte@Sun.COM 				    optionList->optarg) != 0) {
39927836SJohn.Forte@Sun.COM 					return (1);
39937836SJohn.Forte@Sun.COM 				}
39947836SJohn.Forte@Sun.COM 				break;
39957836SJohn.Forte@Sun.COM 
399610156SZhang.Yi@Sun.COM 			case 'T':
399710156SZhang.Yi@Sun.COM 				if (setTunableParameters(oid,
399810156SZhang.Yi@Sun.COM 				    optionList->optarg) != 0) {
399910156SZhang.Yi@Sun.COM 					return (1);
400010156SZhang.Yi@Sun.COM 				}
400110156SZhang.Yi@Sun.COM 				break;
40027836SJohn.Forte@Sun.COM 			default:
40037836SJohn.Forte@Sun.COM 				(void) fprintf(stderr, "%s: %c: %s\n",
40047836SJohn.Forte@Sun.COM 				    cmdName, optionList->optval,
40057836SJohn.Forte@Sun.COM 				    gettext("unknown option"));
40067836SJohn.Forte@Sun.COM 				break;
40077836SJohn.Forte@Sun.COM 		}
40087836SJohn.Forte@Sun.COM 	}
40097836SJohn.Forte@Sun.COM 
40107836SJohn.Forte@Sun.COM 	return (ret);
40117836SJohn.Forte@Sun.COM }
40127836SJohn.Forte@Sun.COM 
40137836SJohn.Forte@Sun.COM /*
40147836SJohn.Forte@Sun.COM  * Modify target parameters
40157836SJohn.Forte@Sun.COM  */
40167836SJohn.Forte@Sun.COM static int
modifyTargetParam(cmdOptions_t * options,char * targetName,int * funcRet)40177836SJohn.Forte@Sun.COM modifyTargetParam(cmdOptions_t *options, char *targetName, int *funcRet)
40187836SJohn.Forte@Sun.COM {
40197836SJohn.Forte@Sun.COM 	IMA_OID oid;
40207836SJohn.Forte@Sun.COM 	IMA_OID targetOid;
40217836SJohn.Forte@Sun.COM 	IMA_STATUS status;
40227836SJohn.Forte@Sun.COM 	IMA_OID_LIST *targetList;
40237836SJohn.Forte@Sun.COM 	SUN_IMA_TARGET_PROPERTIES targetProps;
40247836SJohn.Forte@Sun.COM 	wchar_t wcInputObject[MAX_ISCSI_NAME_LEN + 1];
40257836SJohn.Forte@Sun.COM 	wchar_t targetAddress[SUN_IMA_IP_ADDRESS_PORT_LEN];
40267836SJohn.Forte@Sun.COM 	int ret;
40277836SJohn.Forte@Sun.COM 	boolean_t found;
40287836SJohn.Forte@Sun.COM 	boolean_t targetAddressSpecified = B_TRUE;
40297836SJohn.Forte@Sun.COM 	boolean_t tpgtSpecified = B_FALSE;
40307836SJohn.Forte@Sun.COM 	boolean_t isIpv6 = B_FALSE;
40317836SJohn.Forte@Sun.COM 	int i;
40327836SJohn.Forte@Sun.COM 	iSCSINameCheckStatusType nameCheckStatus;
40337836SJohn.Forte@Sun.COM 	IMA_UINT16 port = 0;
40347836SJohn.Forte@Sun.COM 	IMA_UINT16 tpgt = 0;
40357836SJohn.Forte@Sun.COM 
40368194SJack.Meng@Sun.COM 	IMA_NODE_NAME bootTargetName;
40378194SJack.Meng@Sun.COM 	IMA_INITIATOR_AUTHPARMS bootTargetCHAP;
40388194SJack.Meng@Sun.COM 	IMA_BOOL  iscsiBoot;
40398194SJack.Meng@Sun.COM 	IMA_BOOL  mpxioEnabled;
40408194SJack.Meng@Sun.COM 
40417836SJohn.Forte@Sun.COM 	cmdOptions_t *optionList = options;
40427836SJohn.Forte@Sun.COM 
40437836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
40447836SJohn.Forte@Sun.COM 
40457836SJohn.Forte@Sun.COM 	/* Find Sun initiator */
40467836SJohn.Forte@Sun.COM 	ret = sunInitiatorFind(&oid);
40477836SJohn.Forte@Sun.COM 	if (ret > 0) {
40487836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s\n",
40497836SJohn.Forte@Sun.COM 		    cmdName, gettext("no initiator found"));
40507836SJohn.Forte@Sun.COM 	}
40517836SJohn.Forte@Sun.COM 
40527836SJohn.Forte@Sun.COM 	if (ret != 0) {
40537836SJohn.Forte@Sun.COM 		return (ret);
40547836SJohn.Forte@Sun.COM 	}
40557836SJohn.Forte@Sun.COM 
40567836SJohn.Forte@Sun.COM 	if (parseTarget(targetName,
40577836SJohn.Forte@Sun.COM 	    &wcInputObject[0],
40587836SJohn.Forte@Sun.COM 	    MAX_ISCSI_NAME_LEN + 1,
40597836SJohn.Forte@Sun.COM 	    &targetAddressSpecified,
40607836SJohn.Forte@Sun.COM 	    &targetAddress[0],
40617836SJohn.Forte@Sun.COM 	    SUN_IMA_IP_ADDRESS_PORT_LEN,
40627836SJohn.Forte@Sun.COM 	    &port,
40637836SJohn.Forte@Sun.COM 	    &tpgtSpecified,
40647836SJohn.Forte@Sun.COM 	    &tpgt,
40657836SJohn.Forte@Sun.COM 	    &isIpv6) != PARSE_TARGET_OK) {
40667836SJohn.Forte@Sun.COM 		return (1);
40677836SJohn.Forte@Sun.COM 	}
40687836SJohn.Forte@Sun.COM 
40697836SJohn.Forte@Sun.COM 	/* Perform string profile checks */
40707836SJohn.Forte@Sun.COM 	nameCheckStatus = iSCSINameStringProfileCheck(wcInputObject);
40717836SJohn.Forte@Sun.COM 	iSCSINameCheckStatusDisplay(nameCheckStatus);
40727836SJohn.Forte@Sun.COM 	if (nameCheckStatus != iSCSINameCheckOK) {
40737836SJohn.Forte@Sun.COM 		return (1);
40747836SJohn.Forte@Sun.COM 	}
40757836SJohn.Forte@Sun.COM 
40767836SJohn.Forte@Sun.COM 	status = IMA_GetTargetOidList(oid, &targetList);
40777836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
40787836SJohn.Forte@Sun.COM 		printLibError(status);
40797836SJohn.Forte@Sun.COM 		*funcRet = 1;
40807836SJohn.Forte@Sun.COM 		return (0);
40817836SJohn.Forte@Sun.COM 	}
40827836SJohn.Forte@Sun.COM 
40838194SJack.Meng@Sun.COM 	(void) SUN_IMA_GetBootIscsi(&iscsiBoot);
40848194SJack.Meng@Sun.COM 	if (iscsiBoot == IMA_TRUE) {
40858194SJack.Meng@Sun.COM 		status = SUN_IMA_GetBootMpxio(&mpxioEnabled);
40868194SJack.Meng@Sun.COM 		if (!IMA_SUCCESS(status)) {
40878194SJack.Meng@Sun.COM 			(void) fprintf(stderr, "%s: %s\n",
40888194SJack.Meng@Sun.COM 			    cmdName, gettext("unable to get MPxIO info"
40898194SJack.Meng@Sun.COM 			    " of root disk"));
40908194SJack.Meng@Sun.COM 			*funcRet = 1;
40918194SJack.Meng@Sun.COM 			return (ret);
40928194SJack.Meng@Sun.COM 		}
40938194SJack.Meng@Sun.COM 		status = SUN_IMA_GetBootTargetName(bootTargetName);
40948194SJack.Meng@Sun.COM 		if (!IMA_SUCCESS(status)) {
40958194SJack.Meng@Sun.COM 			(void) fprintf(stderr, "%s: %s\n",
40968194SJack.Meng@Sun.COM 			    cmdName, gettext("unable to get boot target's"
40978194SJack.Meng@Sun.COM 			    " name"));
40988194SJack.Meng@Sun.COM 			*funcRet = 1;
40998194SJack.Meng@Sun.COM 			return (ret);
41008194SJack.Meng@Sun.COM 		}
41018194SJack.Meng@Sun.COM 		status = SUN_IMA_GetBootTargetAuthParams(&bootTargetCHAP);
41028194SJack.Meng@Sun.COM 		if (!IMA_SUCCESS(status)) {
41038194SJack.Meng@Sun.COM 			(void) fprintf(stderr, "%s: %s\n",
41048194SJack.Meng@Sun.COM 			    cmdName, gettext("unable to get boot target's"
41058194SJack.Meng@Sun.COM 			    " auth param"));
41068194SJack.Meng@Sun.COM 			*funcRet = 1;
41078194SJack.Meng@Sun.COM 			return (ret);
41088194SJack.Meng@Sun.COM 		}
41098194SJack.Meng@Sun.COM 	}
41108194SJack.Meng@Sun.COM 
41117836SJohn.Forte@Sun.COM 	/* find target oid */
41127836SJohn.Forte@Sun.COM 	for (found = B_FALSE, i = 0; i < targetList->oidCount; i++) {
41137836SJohn.Forte@Sun.COM 		status = SUN_IMA_GetTargetProperties(targetList->oids[i],
41147836SJohn.Forte@Sun.COM 		    &targetProps);
41157836SJohn.Forte@Sun.COM 		if (!IMA_SUCCESS(status)) {
41167836SJohn.Forte@Sun.COM 			printLibError(status);
41177836SJohn.Forte@Sun.COM 			(void) IMA_FreeMemory(targetList);
41187836SJohn.Forte@Sun.COM 			*funcRet = 1;
41197836SJohn.Forte@Sun.COM 			return (ret);
41207836SJohn.Forte@Sun.COM 		}
41217836SJohn.Forte@Sun.COM 
41227836SJohn.Forte@Sun.COM 		/*
41237836SJohn.Forte@Sun.COM 		 * Compare the target name with the input name
41247836SJohn.Forte@Sun.COM 		 */
41257836SJohn.Forte@Sun.COM 		if ((targetNamesEqual(wcInputObject, targetProps.imaProps.name)
41267836SJohn.Forte@Sun.COM 		    == B_TRUE)) {
41277836SJohn.Forte@Sun.COM 			/*
41287836SJohn.Forte@Sun.COM 			 * For now, regardless of whether a target address
41297836SJohn.Forte@Sun.COM 			 * is specified, we return B_TRUE because
41307836SJohn.Forte@Sun.COM 			 * IMA_TARGET_PROPERTIES does not have a field for
41317836SJohn.Forte@Sun.COM 			 * specifying address.
41327836SJohn.Forte@Sun.COM 			 */
41337836SJohn.Forte@Sun.COM 			found = B_TRUE;
41347836SJohn.Forte@Sun.COM 			targetOid = targetList->oids[i];
41358194SJack.Meng@Sun.COM 
41368194SJack.Meng@Sun.COM 			if ((targetNamesEqual(bootTargetName, wcInputObject)
41378194SJack.Meng@Sun.COM 			    == B_TRUE) && (iscsiBoot == IMA_TRUE)) {
41388194SJack.Meng@Sun.COM 				/*
41398194SJack.Meng@Sun.COM 				 * iscsi booting, need changed target param is
41408194SJack.Meng@Sun.COM 				 * booting target, for auth param, not allow
41418194SJack.Meng@Sun.COM 				 * to change, for others dependent on mpxio
41428194SJack.Meng@Sun.COM 				 */
41438194SJack.Meng@Sun.COM 
41448194SJack.Meng@Sun.COM 				if ((optionList->optval == 'C') ||
41458194SJack.Meng@Sun.COM 				    (optionList->optval == 'H') ||
41468194SJack.Meng@Sun.COM 				    (optionList->optval == 'B') ||
41478194SJack.Meng@Sun.COM 				    (optionList->optval == 'a')) {
41488194SJack.Meng@Sun.COM 					/*
41498194SJack.Meng@Sun.COM 					 * -C CHAP secret set
41508194SJack.Meng@Sun.COM 					 * -H CHAP name set
41518194SJack.Meng@Sun.COM 					 * -a authentication
41528194SJack.Meng@Sun.COM 					 * -B bi-directional-authentication
41538194SJack.Meng@Sun.COM 					 */
41548194SJack.Meng@Sun.COM 					(void) fprintf(stderr, "%s: %s\n",
41558194SJack.Meng@Sun.COM 					    cmdName, gettext("iscsi boot,"
41568194SJack.Meng@Sun.COM 					    " not allowed to modify"
41578194SJack.Meng@Sun.COM 					    " authentication parameters"
41588194SJack.Meng@Sun.COM 					    "  of boot target"));
41598194SJack.Meng@Sun.COM 					return (1);
41608194SJack.Meng@Sun.COM 				}
41618194SJack.Meng@Sun.COM 				if (mpxioEnabled == IMA_FALSE) {
41628194SJack.Meng@Sun.COM 					(void) fprintf(stderr, "%s: %s\n",
41638194SJack.Meng@Sun.COM 					    cmdName, gettext("iscsi boot and"
41648194SJack.Meng@Sun.COM 					    " MPxIO is disabled, not allowed"
41658194SJack.Meng@Sun.COM 					    " to modify boot target's"
41668194SJack.Meng@Sun.COM 					    " parameters"));
41678194SJack.Meng@Sun.COM 					return (1);
41688194SJack.Meng@Sun.COM 				}
41698194SJack.Meng@Sun.COM 
41708194SJack.Meng@Sun.COM 			}
41718194SJack.Meng@Sun.COM 
41727836SJohn.Forte@Sun.COM 			if (modifyIndividualTargetParam(optionList, targetOid,
41737836SJohn.Forte@Sun.COM 			    funcRet) != 0) {
41747836SJohn.Forte@Sun.COM 				return (ret);
41757836SJohn.Forte@Sun.COM 			}
41767836SJohn.Forte@Sun.COM 
41777836SJohn.Forte@Sun.COM 			/*
41787836SJohn.Forte@Sun.COM 			 * Even after finding a matched target, keep going
41797836SJohn.Forte@Sun.COM 			 * since there could be multiple target objects
41807836SJohn.Forte@Sun.COM 			 * associated with one target name in the system
41817836SJohn.Forte@Sun.COM 			 * because of different TPGTs.
41827836SJohn.Forte@Sun.COM 			 */
41837836SJohn.Forte@Sun.COM 		}
41847836SJohn.Forte@Sun.COM 	}
41857836SJohn.Forte@Sun.COM 
41867836SJohn.Forte@Sun.COM 	/* If the target OID cannot be found create one */
41877836SJohn.Forte@Sun.COM 	if (!found) {
41887836SJohn.Forte@Sun.COM 		status = SUN_IMA_CreateTargetOid(wcInputObject, &targetOid);
41897836SJohn.Forte@Sun.COM 		if (!IMA_SUCCESS(status)) {
41907836SJohn.Forte@Sun.COM 			printLibError(status);
41917836SJohn.Forte@Sun.COM 			(void) IMA_FreeMemory(targetList);
41927836SJohn.Forte@Sun.COM 			*funcRet = 1;
41937836SJohn.Forte@Sun.COM 			return (ret);
41947836SJohn.Forte@Sun.COM 		}
41957836SJohn.Forte@Sun.COM 		if (modifyIndividualTargetParam(optionList, targetOid,
41967836SJohn.Forte@Sun.COM 		    funcRet) != 0) {
41977836SJohn.Forte@Sun.COM 				return (ret);
41987836SJohn.Forte@Sun.COM 		}
41997836SJohn.Forte@Sun.COM 	}
42007836SJohn.Forte@Sun.COM 
42017836SJohn.Forte@Sun.COM 	(void) IMA_FreeMemory(targetList);
42027836SJohn.Forte@Sun.COM 	return (ret);
42037836SJohn.Forte@Sun.COM }
42047836SJohn.Forte@Sun.COM 
42057836SJohn.Forte@Sun.COM /*
42067836SJohn.Forte@Sun.COM  * Add one or more addresses
42077836SJohn.Forte@Sun.COM  */
42087836SJohn.Forte@Sun.COM static int
addAddress(int addrType,int operandLen,char * operand[],int * funcRet)42097836SJohn.Forte@Sun.COM addAddress(int addrType, int operandLen, char *operand[], int *funcRet)
42107836SJohn.Forte@Sun.COM {
42117836SJohn.Forte@Sun.COM 	IMA_STATUS status;
42127836SJohn.Forte@Sun.COM 	IMA_OID oid, addressOid;
42137836SJohn.Forte@Sun.COM 	SUN_IMA_TARGET_ADDRESS address;
42147836SJohn.Forte@Sun.COM 	wchar_t wcInputObject[MAX_ADDRESS_LEN + 1];
42157836SJohn.Forte@Sun.COM 	int ret;
42167836SJohn.Forte@Sun.COM 	int i;
42177836SJohn.Forte@Sun.COM 
42187836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
42197836SJohn.Forte@Sun.COM 
42207836SJohn.Forte@Sun.COM 	/* Find Sun initiator */
42217836SJohn.Forte@Sun.COM 	ret = sunInitiatorFind(&oid);
42227836SJohn.Forte@Sun.COM 	if (ret > 0) {
42237836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s\n",
42247836SJohn.Forte@Sun.COM 		    cmdName, gettext("no initiator found"));
42257836SJohn.Forte@Sun.COM 	}
42267836SJohn.Forte@Sun.COM 
42277836SJohn.Forte@Sun.COM 	if (ret != 0) {
42287836SJohn.Forte@Sun.COM 		return (ret);
42297836SJohn.Forte@Sun.COM 	}
42307836SJohn.Forte@Sun.COM 
42317836SJohn.Forte@Sun.COM 	/*
42327836SJohn.Forte@Sun.COM 	 * Format of discovery address operand:
42337836SJohn.Forte@Sun.COM 	 *
42347836SJohn.Forte@Sun.COM 	 * <IP address|hostname>:<port>
42357836SJohn.Forte@Sun.COM 	 */
42367836SJohn.Forte@Sun.COM 	for (i = 0; i < operandLen; i++) {
42377836SJohn.Forte@Sun.COM 		/* initialize */
42387836SJohn.Forte@Sun.COM 		(void) memset(&wcInputObject[0], 0, sizeof (wcInputObject));
42397836SJohn.Forte@Sun.COM 		(void) memset(&address, 0, sizeof (address));
42407836SJohn.Forte@Sun.COM 
42417836SJohn.Forte@Sun.COM 		if (mbstowcs(wcInputObject, operand[i],
42427836SJohn.Forte@Sun.COM 		    (MAX_ADDRESS_LEN + 1)) == (size_t)-1) {
42437836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s\n",
42447836SJohn.Forte@Sun.COM 			    cmdName, gettext("conversion error"));
42457836SJohn.Forte@Sun.COM 			ret = 1;
42467836SJohn.Forte@Sun.COM 			continue;
42477836SJohn.Forte@Sun.COM 		}
42487836SJohn.Forte@Sun.COM 		if (getTargetAddress(addrType, operand[i], &address.imaStruct)
42497836SJohn.Forte@Sun.COM 		    != 0) {
42507836SJohn.Forte@Sun.COM 			ret = 1;
42517836SJohn.Forte@Sun.COM 			continue;
42527836SJohn.Forte@Sun.COM 		}
42537836SJohn.Forte@Sun.COM 		if (addrType == DISCOVERY_ADDRESS) {
42547836SJohn.Forte@Sun.COM 			status = IMA_AddDiscoveryAddress(oid,
42557836SJohn.Forte@Sun.COM 			    address.imaStruct, &addressOid);
42567836SJohn.Forte@Sun.COM 			if (!IMA_SUCCESS(status)) {
42577836SJohn.Forte@Sun.COM 				printLibError(status);
42587836SJohn.Forte@Sun.COM 				*funcRet = 1;
42597836SJohn.Forte@Sun.COM 				return (ret);
42607836SJohn.Forte@Sun.COM 			}
42617836SJohn.Forte@Sun.COM 		} else if (addrType == ISNS_SERVER_ADDRESS) {
42627836SJohn.Forte@Sun.COM 			status = SUN_IMA_AddISNSServerAddress(address);
42637836SJohn.Forte@Sun.COM 			if (!IMA_SUCCESS(status)) {
42647836SJohn.Forte@Sun.COM 				printLibError(status);
42657836SJohn.Forte@Sun.COM 				*funcRet = 1;
42667836SJohn.Forte@Sun.COM 				return (ret);
42677836SJohn.Forte@Sun.COM 			}
42687836SJohn.Forte@Sun.COM 		}
42697836SJohn.Forte@Sun.COM 	}
42707836SJohn.Forte@Sun.COM 	return (ret);
42717836SJohn.Forte@Sun.COM }
42727836SJohn.Forte@Sun.COM 
42737836SJohn.Forte@Sun.COM /*
42747836SJohn.Forte@Sun.COM  * Add one or more static configuration targets
42757836SJohn.Forte@Sun.COM  */
42767836SJohn.Forte@Sun.COM static int
addStaticConfig(int operandLen,char * operand[],int * funcRet)42777836SJohn.Forte@Sun.COM addStaticConfig(int operandLen, char *operand[], int *funcRet)
42787836SJohn.Forte@Sun.COM {
42797836SJohn.Forte@Sun.COM 	int i;
42807836SJohn.Forte@Sun.COM 	boolean_t targetAddressSpecified = B_FALSE;
42817836SJohn.Forte@Sun.COM 	boolean_t tpgtSpecified = B_FALSE;
42827836SJohn.Forte@Sun.COM 	boolean_t isIpv6 = B_FALSE;
42837836SJohn.Forte@Sun.COM 	int ret;
42847836SJohn.Forte@Sun.COM 	int addrType;
42857836SJohn.Forte@Sun.COM 	IMA_STATUS status;
42867836SJohn.Forte@Sun.COM 	IMA_OID oid;
42877836SJohn.Forte@Sun.COM 	SUN_IMA_STATIC_DISCOVERY_TARGET staticConfig;
42887836SJohn.Forte@Sun.COM 	IMA_UINT16 port = 0;
42897836SJohn.Forte@Sun.COM 	IMA_UINT16 tpgt = 0;
42907836SJohn.Forte@Sun.COM 	wchar_t staticTargetName[MAX_ISCSI_NAME_LEN + 1];
42917836SJohn.Forte@Sun.COM 	wchar_t staticTargetAddress[SUN_IMA_IP_ADDRESS_PORT_LEN];
42927836SJohn.Forte@Sun.COM 	iSCSINameCheckStatusType nameCheckStatus;
42937836SJohn.Forte@Sun.COM 	char sAddr[SUN_IMA_IP_ADDRESS_PORT_LEN];
42947836SJohn.Forte@Sun.COM 
42957836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
42967836SJohn.Forte@Sun.COM 
42977836SJohn.Forte@Sun.COM 	/* Find Sun initiator */
42987836SJohn.Forte@Sun.COM 	ret = sunInitiatorFind(&oid);
42997836SJohn.Forte@Sun.COM 	if (ret > 0) {
43007836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s\n",
43017836SJohn.Forte@Sun.COM 		    cmdName, gettext("no initiator found"));
43027836SJohn.Forte@Sun.COM 	}
43037836SJohn.Forte@Sun.COM 
43047836SJohn.Forte@Sun.COM 	if (ret != 0) {
43057836SJohn.Forte@Sun.COM 		return (ret);
43067836SJohn.Forte@Sun.COM 	}
43077836SJohn.Forte@Sun.COM 
43087836SJohn.Forte@Sun.COM 	/*
43097836SJohn.Forte@Sun.COM 	 * Format of static config operand:
43107836SJohn.Forte@Sun.COM 	 *  <target-name>,<IP address|hostname>[:port][,tpgt]
43117836SJohn.Forte@Sun.COM 	 */
43127836SJohn.Forte@Sun.COM 	for (i = 0; i < operandLen; i++) {
43137836SJohn.Forte@Sun.COM 		if (parseTarget(operand[i],
43147836SJohn.Forte@Sun.COM 		    &staticTargetName[0],
43157836SJohn.Forte@Sun.COM 		    MAX_ISCSI_NAME_LEN + 1,
43167836SJohn.Forte@Sun.COM 		    &targetAddressSpecified,
43177836SJohn.Forte@Sun.COM 		    &staticTargetAddress[0],
43187836SJohn.Forte@Sun.COM 		    SUN_IMA_IP_ADDRESS_PORT_LEN,
43197836SJohn.Forte@Sun.COM 		    &port,
43207836SJohn.Forte@Sun.COM 		    &tpgtSpecified,
43217836SJohn.Forte@Sun.COM 		    &tpgt,
43227836SJohn.Forte@Sun.COM 		    &isIpv6) != PARSE_TARGET_OK) {
43237836SJohn.Forte@Sun.COM 			ret = 1;
43247836SJohn.Forte@Sun.COM 			continue;
43257836SJohn.Forte@Sun.COM 		}
43267836SJohn.Forte@Sun.COM 
43277836SJohn.Forte@Sun.COM 		if (targetAddressSpecified != B_TRUE) {
43287836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s\n",
43297836SJohn.Forte@Sun.COM 			    cmdName, gettext("missing target address"));
43307836SJohn.Forte@Sun.COM 			*funcRet = 1; /* DIY message fix */
43317836SJohn.Forte@Sun.COM 			return (1);
43327836SJohn.Forte@Sun.COM 		}
43337836SJohn.Forte@Sun.COM 		/* Perform string profile checks */
43347836SJohn.Forte@Sun.COM 		nameCheckStatus = iSCSINameStringProfileCheck(staticTargetName);
43357836SJohn.Forte@Sun.COM 		iSCSINameCheckStatusDisplay(nameCheckStatus);
43367836SJohn.Forte@Sun.COM 		if (nameCheckStatus != iSCSINameCheckOK) {
43377836SJohn.Forte@Sun.COM 			*funcRet = 1; /* DIY message fix */
43387836SJohn.Forte@Sun.COM 			return (1);
43397836SJohn.Forte@Sun.COM 		}
43407836SJohn.Forte@Sun.COM 		(void) wcsncpy(staticConfig.targetName, staticTargetName,
43417836SJohn.Forte@Sun.COM 		    MAX_ISCSI_NAME_LEN + 1);
43427836SJohn.Forte@Sun.COM 
43437836SJohn.Forte@Sun.COM 		(void) wcstombs(sAddr, staticTargetAddress, sizeof (sAddr));
43447836SJohn.Forte@Sun.COM 
43457836SJohn.Forte@Sun.COM 		if (isIpv6 == B_TRUE) {
43467836SJohn.Forte@Sun.COM 			staticConfig.targetAddress.imaStruct.hostnameIpAddress.
43477836SJohn.Forte@Sun.COM 			    id.ipAddress.ipv4Address = B_FALSE;
43487836SJohn.Forte@Sun.COM 			addrType = AF_INET6;
43497836SJohn.Forte@Sun.COM 		} else {
43507836SJohn.Forte@Sun.COM 			staticConfig.targetAddress.imaStruct.hostnameIpAddress.
43517836SJohn.Forte@Sun.COM 			    id.ipAddress.ipv4Address = B_TRUE;
43527836SJohn.Forte@Sun.COM 			addrType = AF_INET;
43537836SJohn.Forte@Sun.COM 		}
43547836SJohn.Forte@Sun.COM 
43557836SJohn.Forte@Sun.COM 		if (inet_pton(addrType, sAddr, staticConfig.targetAddress.
43567836SJohn.Forte@Sun.COM 		    imaStruct.hostnameIpAddress.id.ipAddress.ipAddress) != 1) {
43577836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s\n",
43587836SJohn.Forte@Sun.COM 			    cmdName, gettext("static config conversion error"));
43597836SJohn.Forte@Sun.COM 			ret = 1;
43607836SJohn.Forte@Sun.COM 			continue;
43617836SJohn.Forte@Sun.COM 		}
43627836SJohn.Forte@Sun.COM 
43637836SJohn.Forte@Sun.COM 		staticConfig.targetAddress.imaStruct.portNumber = port;
43647836SJohn.Forte@Sun.COM 		if (tpgtSpecified == B_TRUE) {
43657836SJohn.Forte@Sun.COM 			staticConfig.targetAddress.defaultTpgt = B_FALSE;
43667836SJohn.Forte@Sun.COM 			staticConfig.targetAddress.tpgt = tpgt;
43677836SJohn.Forte@Sun.COM 		} else {
43687836SJohn.Forte@Sun.COM 			staticConfig.targetAddress.defaultTpgt = B_TRUE;
43697836SJohn.Forte@Sun.COM 			staticConfig.targetAddress.tpgt = 0;
43707836SJohn.Forte@Sun.COM 		}
43717836SJohn.Forte@Sun.COM 
43727836SJohn.Forte@Sun.COM 		status = SUN_IMA_AddStaticTarget(oid, staticConfig, &oid);
43737836SJohn.Forte@Sun.COM 		if (!IMA_SUCCESS(status)) {
43747836SJohn.Forte@Sun.COM 			printLibError(status);
43757836SJohn.Forte@Sun.COM 			*funcRet = 1;
43767836SJohn.Forte@Sun.COM 			return (1);
43777836SJohn.Forte@Sun.COM 		}
43787836SJohn.Forte@Sun.COM 	}
43799414SBing.Zhao@Sun.COM 
43809414SBing.Zhao@Sun.COM 	if (ret != 0) {
43819414SBing.Zhao@Sun.COM 		*funcRet = 1;
43829414SBing.Zhao@Sun.COM 	}
43839414SBing.Zhao@Sun.COM 
43847836SJohn.Forte@Sun.COM 	return (ret);
43857836SJohn.Forte@Sun.COM }
43867836SJohn.Forte@Sun.COM 
43877836SJohn.Forte@Sun.COM /*
43887836SJohn.Forte@Sun.COM  * Remove one or more addresses
43897836SJohn.Forte@Sun.COM  */
43907836SJohn.Forte@Sun.COM static int
removeAddress(int addrType,int operandLen,char * operand[],int * funcRet)43917836SJohn.Forte@Sun.COM removeAddress(int addrType, int operandLen, char *operand[], int *funcRet)
43927836SJohn.Forte@Sun.COM {
43937836SJohn.Forte@Sun.COM 	IMA_STATUS status;
43947836SJohn.Forte@Sun.COM 	IMA_OID initiatorOid;
43957836SJohn.Forte@Sun.COM 	SUN_IMA_TARGET_ADDRESS address;
43967836SJohn.Forte@Sun.COM 	wchar_t wcInputObject[MAX_ADDRESS_LEN + 1];
43977836SJohn.Forte@Sun.COM 	int ret;
43987836SJohn.Forte@Sun.COM 	int i;
43997836SJohn.Forte@Sun.COM 
44007836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
44017836SJohn.Forte@Sun.COM 
44027836SJohn.Forte@Sun.COM 	/* Find Sun initiator */
44037836SJohn.Forte@Sun.COM 	ret = sunInitiatorFind(&initiatorOid);
44047836SJohn.Forte@Sun.COM 	if (ret > 0) {
44057836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s\n",
44067836SJohn.Forte@Sun.COM 		    cmdName, gettext("no initiator found"));
44077836SJohn.Forte@Sun.COM 	}
44087836SJohn.Forte@Sun.COM 
44097836SJohn.Forte@Sun.COM 	if (ret != 0) {
44107836SJohn.Forte@Sun.COM 		return (ret);
44117836SJohn.Forte@Sun.COM 	}
44127836SJohn.Forte@Sun.COM 
44137836SJohn.Forte@Sun.COM 	for (i = 0; i < operandLen; i++) {
44147836SJohn.Forte@Sun.COM 		/* initialize */
44157836SJohn.Forte@Sun.COM 		(void) memset(&wcInputObject[0], 0, sizeof (wcInputObject));
44167836SJohn.Forte@Sun.COM 		(void) memset(&address, 0, sizeof (address));
44177836SJohn.Forte@Sun.COM 
44187836SJohn.Forte@Sun.COM 		if (mbstowcs(wcInputObject, operand[i],
44197836SJohn.Forte@Sun.COM 		    MAX_ADDRESS_LEN + 1) == (size_t)-1) {
44207836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s\n",
44217836SJohn.Forte@Sun.COM 			    cmdName, gettext("conversion error"));
44227836SJohn.Forte@Sun.COM 			ret = 1;
44237836SJohn.Forte@Sun.COM 			continue;
44247836SJohn.Forte@Sun.COM 		}
44257836SJohn.Forte@Sun.COM 
44267836SJohn.Forte@Sun.COM 		if (getTargetAddress(addrType, operand[i], &address.imaStruct)
44277836SJohn.Forte@Sun.COM 		    != 0) {
44287836SJohn.Forte@Sun.COM 			ret = 1;
44297836SJohn.Forte@Sun.COM 			continue;
44307836SJohn.Forte@Sun.COM 		}
44317836SJohn.Forte@Sun.COM 
44327836SJohn.Forte@Sun.COM 		if (addrType == DISCOVERY_ADDRESS) {
44337836SJohn.Forte@Sun.COM 			status = SUN_IMA_RemoveDiscoveryAddress(address);
44347836SJohn.Forte@Sun.COM 			if (!IMA_SUCCESS(status)) {
44357836SJohn.Forte@Sun.COM 				if (status == IMA_ERROR_OBJECT_NOT_FOUND) {
44367836SJohn.Forte@Sun.COM 					(void) fprintf(stderr, "%s: %s\n",
44377836SJohn.Forte@Sun.COM 					    operand[i], gettext("not found"));
44387836SJohn.Forte@Sun.COM 				} else {
44397836SJohn.Forte@Sun.COM 					printLibError(status);
44407836SJohn.Forte@Sun.COM 				}
44417836SJohn.Forte@Sun.COM 				*funcRet = 1;
44427836SJohn.Forte@Sun.COM 			}
44437836SJohn.Forte@Sun.COM 		} else {
44447836SJohn.Forte@Sun.COM 			status = SUN_IMA_RemoveISNSServerAddress(address);
44457836SJohn.Forte@Sun.COM 			if (!IMA_SUCCESS(status)) {
44467836SJohn.Forte@Sun.COM 				printLibError(status);
44477836SJohn.Forte@Sun.COM 				*funcRet = 1;
44487836SJohn.Forte@Sun.COM 			}
44497836SJohn.Forte@Sun.COM 		}
44507836SJohn.Forte@Sun.COM 	}
44517836SJohn.Forte@Sun.COM 	return (ret);
44527836SJohn.Forte@Sun.COM }
44537836SJohn.Forte@Sun.COM 
44547836SJohn.Forte@Sun.COM /*
44557836SJohn.Forte@Sun.COM  * Remove one or more static configuration targets
44567836SJohn.Forte@Sun.COM  */
44577836SJohn.Forte@Sun.COM static int
removeStaticConfig(int operandLen,char * operand[],int * funcRet)44587836SJohn.Forte@Sun.COM removeStaticConfig(int operandLen, char *operand[], int *funcRet)
44597836SJohn.Forte@Sun.COM {
44607836SJohn.Forte@Sun.COM 	IMA_STATUS status;
44617836SJohn.Forte@Sun.COM 	IMA_OID initiatorOid;
44627836SJohn.Forte@Sun.COM 	IMA_OID_LIST *staticTargetList;
44637836SJohn.Forte@Sun.COM 	SUN_IMA_STATIC_TARGET_PROPERTIES staticTargetProps;
44647836SJohn.Forte@Sun.COM 	wchar_t staticTargetName[MAX_ISCSI_NAME_LEN + 1];
44657836SJohn.Forte@Sun.COM 	wchar_t staticTargetAddress[SUN_IMA_IP_ADDRESS_PORT_LEN];
44667836SJohn.Forte@Sun.COM 	int ret;
44677836SJohn.Forte@Sun.COM 	boolean_t atLeastFoundOne;
44687836SJohn.Forte@Sun.COM 	boolean_t matched;
44697836SJohn.Forte@Sun.COM 	boolean_t targetAddressSpecified = B_TRUE;
44707836SJohn.Forte@Sun.COM 	boolean_t tpgtSpecified = B_FALSE;
44717836SJohn.Forte@Sun.COM 	boolean_t isIpv6 = B_FALSE;
44727836SJohn.Forte@Sun.COM 	int i, j;
44737836SJohn.Forte@Sun.COM 	IMA_UINT16 port = 0;
44747836SJohn.Forte@Sun.COM 	IMA_UINT16 tpgt = 0;
44757836SJohn.Forte@Sun.COM 	iSCSINameCheckStatusType nameCheckStatus;
44767836SJohn.Forte@Sun.COM 	char tmpStr[SUN_IMA_IP_ADDRESS_PORT_LEN];
44777836SJohn.Forte@Sun.COM 	wchar_t tmpTargetAddress[SUN_IMA_IP_ADDRESS_PORT_LEN];
44787836SJohn.Forte@Sun.COM 
44797836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
44807836SJohn.Forte@Sun.COM 
44817836SJohn.Forte@Sun.COM 	/* Find Sun initiator */
44827836SJohn.Forte@Sun.COM 	ret = sunInitiatorFind(&initiatorOid);
44837836SJohn.Forte@Sun.COM 	if (ret > 0) {
44847836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s\n",
44857836SJohn.Forte@Sun.COM 		    cmdName, gettext("no initiator found"));
44867836SJohn.Forte@Sun.COM 	}
44877836SJohn.Forte@Sun.COM 
44887836SJohn.Forte@Sun.COM 	if (ret != 0) {
44897836SJohn.Forte@Sun.COM 		return (ret);
44907836SJohn.Forte@Sun.COM 	}
44917836SJohn.Forte@Sun.COM 
44927836SJohn.Forte@Sun.COM 	status = IMA_GetStaticDiscoveryTargetOidList(initiatorOid,
44937836SJohn.Forte@Sun.COM 	    &staticTargetList);
44947836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
44957836SJohn.Forte@Sun.COM 		printLibError(status);
44967836SJohn.Forte@Sun.COM 		*funcRet = 1;
44977836SJohn.Forte@Sun.COM 		return (ret);
44987836SJohn.Forte@Sun.COM 	}
44997836SJohn.Forte@Sun.COM 
45007836SJohn.Forte@Sun.COM 	for (i = 0; i < operandLen; i++) {
45017836SJohn.Forte@Sun.COM 		if (parseTarget(operand[i],
45027836SJohn.Forte@Sun.COM 		    &staticTargetName[0],
45037836SJohn.Forte@Sun.COM 		    MAX_ISCSI_NAME_LEN + 1,
45047836SJohn.Forte@Sun.COM 		    &targetAddressSpecified,
45057836SJohn.Forte@Sun.COM 		    &staticTargetAddress[0],
45067836SJohn.Forte@Sun.COM 		    SUN_IMA_IP_ADDRESS_PORT_LEN,
45077836SJohn.Forte@Sun.COM 		    &port,
45087836SJohn.Forte@Sun.COM 		    &tpgtSpecified,
45097836SJohn.Forte@Sun.COM 		    &tpgt,
45107836SJohn.Forte@Sun.COM 		    &isIpv6) != PARSE_TARGET_OK) {
45117836SJohn.Forte@Sun.COM 			ret = 1;
45127836SJohn.Forte@Sun.COM 			continue;
45137836SJohn.Forte@Sun.COM 		}
45147836SJohn.Forte@Sun.COM 
45157836SJohn.Forte@Sun.COM 		/* Perform string profile checks */
45167836SJohn.Forte@Sun.COM 		nameCheckStatus = iSCSINameStringProfileCheck(staticTargetName);
45177836SJohn.Forte@Sun.COM 		iSCSINameCheckStatusDisplay(nameCheckStatus);
45187836SJohn.Forte@Sun.COM 		if (nameCheckStatus != iSCSINameCheckOK) {
45197836SJohn.Forte@Sun.COM 			return (1);
45207836SJohn.Forte@Sun.COM 		}
45217836SJohn.Forte@Sun.COM 
45227836SJohn.Forte@Sun.COM 		for (atLeastFoundOne = B_FALSE, j = 0;
45237836SJohn.Forte@Sun.COM 		    j < staticTargetList->oidCount;
45247836SJohn.Forte@Sun.COM 		    j++) {
45257836SJohn.Forte@Sun.COM 			IMA_UINT16 stpgt;
45267836SJohn.Forte@Sun.COM 
45277836SJohn.Forte@Sun.COM 			matched = B_FALSE;
45287836SJohn.Forte@Sun.COM 			status = SUN_IMA_GetStaticTargetProperties(
45297836SJohn.Forte@Sun.COM 			    staticTargetList->oids[j], &staticTargetProps);
45307836SJohn.Forte@Sun.COM 			if (!IMA_SUCCESS(status)) {
45317836SJohn.Forte@Sun.COM 				if (status == IMA_ERROR_OBJECT_NOT_FOUND) {
45327836SJohn.Forte@Sun.COM 					/*
45337836SJohn.Forte@Sun.COM 					 * When removing multiple static-config
45347836SJohn.Forte@Sun.COM 					 * entries we need to expect get
45357836SJohn.Forte@Sun.COM 					 * failures. These failures occur when
45367836SJohn.Forte@Sun.COM 					 * we are trying to get entry
45377836SJohn.Forte@Sun.COM 					 * information we have just removed.
45387836SJohn.Forte@Sun.COM 					 * Ignore the failure and continue.
45397836SJohn.Forte@Sun.COM 					 */
45407836SJohn.Forte@Sun.COM 					ret = 1;
45417836SJohn.Forte@Sun.COM 					continue;
45427836SJohn.Forte@Sun.COM 				} else {
45437836SJohn.Forte@Sun.COM 					printLibError(status);
45447836SJohn.Forte@Sun.COM 					(void) IMA_FreeMemory(staticTargetList);
45457836SJohn.Forte@Sun.COM 					*funcRet = 1;
45467836SJohn.Forte@Sun.COM 					return (ret);
45477836SJohn.Forte@Sun.COM 				}
45487836SJohn.Forte@Sun.COM 			}
45497836SJohn.Forte@Sun.COM 
45507836SJohn.Forte@Sun.COM 			stpgt =
45517836SJohn.Forte@Sun.COM 			    staticTargetProps.staticTarget.targetAddress.tpgt;
45527836SJohn.Forte@Sun.COM 
45537836SJohn.Forte@Sun.COM 			/*
45547836SJohn.Forte@Sun.COM 			 * Compare the static target name with the input if
45557836SJohn.Forte@Sun.COM 			 * one was input
45567836SJohn.Forte@Sun.COM 			 */
45577836SJohn.Forte@Sun.COM 			if ((targetNamesEqual(
45587836SJohn.Forte@Sun.COM 			    staticTargetProps.staticTarget.targetName,
45597836SJohn.Forte@Sun.COM 			    staticTargetName) == B_TRUE)) {
45607836SJohn.Forte@Sun.COM 				if (targetAddressSpecified == B_FALSE) {
45617836SJohn.Forte@Sun.COM 					matched = B_TRUE;
45627836SJohn.Forte@Sun.COM 				} else {
45637836SJohn.Forte@Sun.COM 
45647836SJohn.Forte@Sun.COM 					if (staticTargetProps.staticTarget.
45657836SJohn.Forte@Sun.COM 					    targetAddress.imaStruct.
45667836SJohn.Forte@Sun.COM 					    hostnameIpAddress.
45677836SJohn.Forte@Sun.COM 					    id.ipAddress.ipv4Address ==
45687836SJohn.Forte@Sun.COM 					    IMA_TRUE) {
45697836SJohn.Forte@Sun.COM 						(void) inet_ntop(AF_INET,
45707836SJohn.Forte@Sun.COM 						    staticTargetProps.
45717836SJohn.Forte@Sun.COM 						    staticTarget.targetAddress.
45727836SJohn.Forte@Sun.COM 						    imaStruct.hostnameIpAddress.
45737836SJohn.Forte@Sun.COM 						    id.ipAddress.ipAddress,
45747836SJohn.Forte@Sun.COM 						    tmpStr,
45757836SJohn.Forte@Sun.COM 						    sizeof (tmpStr));
45767836SJohn.Forte@Sun.COM 					} else {
45777836SJohn.Forte@Sun.COM 						(void) inet_ntop(AF_INET6,
45787836SJohn.Forte@Sun.COM 						    staticTargetProps.
45797836SJohn.Forte@Sun.COM 						    staticTarget.targetAddress.
45807836SJohn.Forte@Sun.COM 						    imaStruct.hostnameIpAddress.
45817836SJohn.Forte@Sun.COM 						    id.ipAddress.ipAddress,
45827836SJohn.Forte@Sun.COM 						    tmpStr,
45837836SJohn.Forte@Sun.COM 						    sizeof (tmpStr));
45847836SJohn.Forte@Sun.COM 					}
45857836SJohn.Forte@Sun.COM 
45867836SJohn.Forte@Sun.COM 					if (mbstowcs(tmpTargetAddress, tmpStr,
45877836SJohn.Forte@Sun.COM 					    SUN_IMA_IP_ADDRESS_PORT_LEN) ==
45887836SJohn.Forte@Sun.COM 					    (size_t)-1) {
45897836SJohn.Forte@Sun.COM 						(void) fprintf(stderr,
45907836SJohn.Forte@Sun.COM 						    "%s: %s\n",
45917836SJohn.Forte@Sun.COM 						    cmdName, gettext(
45927836SJohn.Forte@Sun.COM 						    "conversion error"));
45937836SJohn.Forte@Sun.COM 						ret = 1;
45947836SJohn.Forte@Sun.COM 						continue;
45957836SJohn.Forte@Sun.COM 					}
45967836SJohn.Forte@Sun.COM 
45977836SJohn.Forte@Sun.COM 					if ((wcsncmp(tmpTargetAddress,
45987836SJohn.Forte@Sun.COM 					    staticTargetAddress,
45997836SJohn.Forte@Sun.COM 					    SUN_IMA_IP_ADDRESS_PORT_LEN) ==
46007836SJohn.Forte@Sun.COM 					    0) && (staticTargetProps.
46017836SJohn.Forte@Sun.COM 					    staticTarget.targetAddress.
46027836SJohn.Forte@Sun.COM 					    imaStruct.portNumber == port)) {
46037836SJohn.Forte@Sun.COM 						if (tpgtSpecified == B_FALSE) {
46047836SJohn.Forte@Sun.COM 							matched = B_TRUE;
46057836SJohn.Forte@Sun.COM 						} else {
46067836SJohn.Forte@Sun.COM 							if (tpgt == stpgt) {
46077836SJohn.Forte@Sun.COM 								matched =
46087836SJohn.Forte@Sun.COM 								    B_TRUE;
46097836SJohn.Forte@Sun.COM 							}
46107836SJohn.Forte@Sun.COM 						}
46117836SJohn.Forte@Sun.COM 					}
46127836SJohn.Forte@Sun.COM 				}
46137836SJohn.Forte@Sun.COM 
46147836SJohn.Forte@Sun.COM 				if (matched) {
46157836SJohn.Forte@Sun.COM 					status =
46167836SJohn.Forte@Sun.COM 					    IMA_RemoveStaticDiscoveryTarget(
46177836SJohn.Forte@Sun.COM 					    staticTargetList->oids[j]);
46187836SJohn.Forte@Sun.COM 					if (!IMA_SUCCESS(status)) {
46197836SJohn.Forte@Sun.COM 						printLibError(status);
46207836SJohn.Forte@Sun.COM 						*funcRet = 1;
46217836SJohn.Forte@Sun.COM 						return (ret);
46227836SJohn.Forte@Sun.COM 					}
46237836SJohn.Forte@Sun.COM 					atLeastFoundOne = B_TRUE;
46247836SJohn.Forte@Sun.COM 				}
46257836SJohn.Forte@Sun.COM 			}
46267836SJohn.Forte@Sun.COM 		}
46277836SJohn.Forte@Sun.COM 		if (!atLeastFoundOne) {
46287836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, gettext("%ws,%ws: %s\n"),
46297836SJohn.Forte@Sun.COM 			    staticTargetName, staticTargetAddress,
46307836SJohn.Forte@Sun.COM 			    gettext("not found"));
46317836SJohn.Forte@Sun.COM 		}
46327836SJohn.Forte@Sun.COM 	}
46337836SJohn.Forte@Sun.COM 	return (ret);
46347836SJohn.Forte@Sun.COM }
46357836SJohn.Forte@Sun.COM 
46367836SJohn.Forte@Sun.COM /*
46377836SJohn.Forte@Sun.COM  * Remove one or more target params.
46387836SJohn.Forte@Sun.COM  */
46397836SJohn.Forte@Sun.COM static int
removeTargetParam(int operandLen,char * operand[],int * funcRet)46407836SJohn.Forte@Sun.COM removeTargetParam(int operandLen, char *operand[], int *funcRet)
46417836SJohn.Forte@Sun.COM {
46427836SJohn.Forte@Sun.COM 	char *commaPos;
46437836SJohn.Forte@Sun.COM 	IMA_STATUS status;
46447836SJohn.Forte@Sun.COM 	IMA_OID initiatorOid;
46457836SJohn.Forte@Sun.COM 	IMA_OID_LIST *targetList;
46467836SJohn.Forte@Sun.COM 	SUN_IMA_TARGET_PROPERTIES targetProps;
46477836SJohn.Forte@Sun.COM 	wchar_t wcInputObject[MAX_ISCSI_NAME_LEN + 1];
46487836SJohn.Forte@Sun.COM 	int ret;
46497836SJohn.Forte@Sun.COM 	boolean_t found;
46507836SJohn.Forte@Sun.COM 	int i, j;
46518194SJack.Meng@Sun.COM 	IMA_NODE_NAME bootTargetName;
46528194SJack.Meng@Sun.COM 	IMA_BOOL	iscsiBoot = IMA_FALSE;
46538194SJack.Meng@Sun.COM 	IMA_BOOL	mpxioEnabled = IMA_FALSE;
46548194SJack.Meng@Sun.COM 
46558194SJack.Meng@Sun.COM 	/* Get boot session's info */
46568194SJack.Meng@Sun.COM 	(void) SUN_IMA_GetBootIscsi(&iscsiBoot);
46578194SJack.Meng@Sun.COM 	if (iscsiBoot == IMA_TRUE) {
46588194SJack.Meng@Sun.COM 		status = SUN_IMA_GetBootMpxio(&mpxioEnabled);
46598194SJack.Meng@Sun.COM 		if (!IMA_SUCCESS(status)) {
46608194SJack.Meng@Sun.COM 			(void) fprintf(stderr, "%s: %s\n",
46618194SJack.Meng@Sun.COM 			    cmdName, gettext("unable to get MPxIO info of"
46628194SJack.Meng@Sun.COM 			    " root disk"));
46638194SJack.Meng@Sun.COM 			*funcRet = 1;
46648194SJack.Meng@Sun.COM 			return (1);
46658194SJack.Meng@Sun.COM 		}
46668194SJack.Meng@Sun.COM 		status = SUN_IMA_GetBootTargetName(bootTargetName);
46678194SJack.Meng@Sun.COM 		if (!IMA_SUCCESS(status)) {
46688194SJack.Meng@Sun.COM 			(void) fprintf(stderr, "%s: %s\n",
46698194SJack.Meng@Sun.COM 			    cmdName, gettext("unable to get boot"
46708194SJack.Meng@Sun.COM 			    " target's name"));
46718194SJack.Meng@Sun.COM 			*funcRet = 1;
46728194SJack.Meng@Sun.COM 			return (1);
46738194SJack.Meng@Sun.COM 		}
46748194SJack.Meng@Sun.COM 	}
46757836SJohn.Forte@Sun.COM 
46767836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
46777836SJohn.Forte@Sun.COM 
46787836SJohn.Forte@Sun.COM 	/* Find Sun initiator */
46797836SJohn.Forte@Sun.COM 	ret = sunInitiatorFind(&initiatorOid);
46807836SJohn.Forte@Sun.COM 	if (ret > 0) {
46817836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s\n",
46827836SJohn.Forte@Sun.COM 		    cmdName, gettext("no initiator found"));
46837836SJohn.Forte@Sun.COM 	}
46847836SJohn.Forte@Sun.COM 
46857836SJohn.Forte@Sun.COM 	if (ret != 0) {
46867836SJohn.Forte@Sun.COM 		return (ret);
46877836SJohn.Forte@Sun.COM 	}
46887836SJohn.Forte@Sun.COM 
46897836SJohn.Forte@Sun.COM 	status = IMA_GetTargetOidList(initiatorOid, &targetList);
46907836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
46917836SJohn.Forte@Sun.COM 		printLibError(status);
46927836SJohn.Forte@Sun.COM 		*funcRet = 1;
46937836SJohn.Forte@Sun.COM 		return (ret);
46947836SJohn.Forte@Sun.COM 	}
46957836SJohn.Forte@Sun.COM 
46967836SJohn.Forte@Sun.COM 	for (i = 0; i < operandLen; i++) {
46977836SJohn.Forte@Sun.COM 		/* initialize */
46987836SJohn.Forte@Sun.COM 		commaPos = strchr(operand[i], ',');
46997836SJohn.Forte@Sun.COM 		if (commaPos) {
47007836SJohn.Forte@Sun.COM 			/* Ignore IP address. */
47017836SJohn.Forte@Sun.COM 			*commaPos = NULL;
47027836SJohn.Forte@Sun.COM 		}
47037836SJohn.Forte@Sun.COM 		(void) memset(&wcInputObject[0], 0, sizeof (wcInputObject));
47047836SJohn.Forte@Sun.COM 		if (mbstowcs(wcInputObject, operand[i],
47057836SJohn.Forte@Sun.COM 		    MAX_ISCSI_NAME_LEN + 1) == (size_t)-1) {
47067836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s\n", cmdName,
47077836SJohn.Forte@Sun.COM 			    gettext("conversion error"));
47087836SJohn.Forte@Sun.COM 			ret = 1;
47097836SJohn.Forte@Sun.COM 			continue;
47107836SJohn.Forte@Sun.COM 		}
47117836SJohn.Forte@Sun.COM 
47127836SJohn.Forte@Sun.COM 		for (found = B_FALSE, j = 0; j < targetList->oidCount;
47137836SJohn.Forte@Sun.COM 		    j++) {
47147836SJohn.Forte@Sun.COM 			status = SUN_IMA_GetTargetProperties(
47157836SJohn.Forte@Sun.COM 			    targetList->oids[j], &targetProps);
47167836SJohn.Forte@Sun.COM 			if (!IMA_SUCCESS(status)) {
47177836SJohn.Forte@Sun.COM 				printLibError(status);
47187836SJohn.Forte@Sun.COM 				(void) IMA_FreeMemory(targetList);
47197836SJohn.Forte@Sun.COM 				*funcRet = 1;
47207836SJohn.Forte@Sun.COM 				return (ret);
47217836SJohn.Forte@Sun.COM 			}
47227836SJohn.Forte@Sun.COM 
47237836SJohn.Forte@Sun.COM 			/*
47247836SJohn.Forte@Sun.COM 			 * Compare the target name with the input if
47257836SJohn.Forte@Sun.COM 			 * one was input
47267836SJohn.Forte@Sun.COM 			 */
47277836SJohn.Forte@Sun.COM 			if (targetNamesEqual(targetProps.imaProps.name,
47287836SJohn.Forte@Sun.COM 			    wcInputObject) == B_TRUE) {
47297836SJohn.Forte@Sun.COM 				found = B_TRUE;
47308194SJack.Meng@Sun.COM 				if ((targetNamesEqual(bootTargetName,
47318194SJack.Meng@Sun.COM 				    wcInputObject) == B_TRUE) &&
47328194SJack.Meng@Sun.COM 				    (iscsiBoot == IMA_TRUE)) {
47338194SJack.Meng@Sun.COM 					/*
47348194SJack.Meng@Sun.COM 					 * iscsi booting, need changed target
47358194SJack.Meng@Sun.COM 					 * param is booting target, booting
47368194SJack.Meng@Sun.COM 					 * session mpxio disabled, not
47378194SJack.Meng@Sun.COM 					 * allow to update
47388194SJack.Meng@Sun.COM 					 */
47398194SJack.Meng@Sun.COM 					if (mpxioEnabled == IMA_FALSE) {
47408194SJack.Meng@Sun.COM 						(void) fprintf(stderr,
47418194SJack.Meng@Sun.COM 						    "%s: %s\n", cmdName,
47428194SJack.Meng@Sun.COM 						    gettext("iscsi boot"
47438194SJack.Meng@Sun.COM 						    " with MPxIO disabled,"
47448194SJack.Meng@Sun.COM 						    " not allowed to remove"
47458194SJack.Meng@Sun.COM 						    " boot sess param"));
47468318SZhang.Yi@Sun.COM 						ret = 1;
47478194SJack.Meng@Sun.COM 						continue;
47488194SJack.Meng@Sun.COM 					}
47498194SJack.Meng@Sun.COM 
47508194SJack.Meng@Sun.COM 				}
47518194SJack.Meng@Sun.COM 
47527836SJohn.Forte@Sun.COM 				status = SUN_IMA_RemoveTargetParam(
47537836SJohn.Forte@Sun.COM 				    targetList->oids[j]);
47547836SJohn.Forte@Sun.COM 				if (!IMA_SUCCESS(status)) {
47557836SJohn.Forte@Sun.COM 					printLibError(status);
47567836SJohn.Forte@Sun.COM 					(void) IMA_FreeMemory(targetList);
47577836SJohn.Forte@Sun.COM 					*funcRet = 1;
47587836SJohn.Forte@Sun.COM 					return (ret);
47597836SJohn.Forte@Sun.COM 				}
47607836SJohn.Forte@Sun.COM 			}
47617836SJohn.Forte@Sun.COM 		}
47627836SJohn.Forte@Sun.COM 		if (!found) {
47637836SJohn.Forte@Sun.COM 			/* Silently ignoring it? */
47647836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, gettext("%ws: %s\n"),
47657836SJohn.Forte@Sun.COM 			    wcInputObject, gettext("not found"));
47667836SJohn.Forte@Sun.COM 		}
47677836SJohn.Forte@Sun.COM 	}
47687836SJohn.Forte@Sun.COM 
47697836SJohn.Forte@Sun.COM 	(void) IMA_FreeMemory(targetList);
47707836SJohn.Forte@Sun.COM 	return (ret);
47717836SJohn.Forte@Sun.COM }
47727836SJohn.Forte@Sun.COM 
47737836SJohn.Forte@Sun.COM /*ARGSUSED*/
47747836SJohn.Forte@Sun.COM static int
addFunc(int operandLen,char * operand[],int object,cmdOptions_t * options,void * addArgs,int * funcRet)47757836SJohn.Forte@Sun.COM addFunc(int operandLen, char *operand[], int object, cmdOptions_t *options,
47767836SJohn.Forte@Sun.COM     void *addArgs, int *funcRet)
47777836SJohn.Forte@Sun.COM {
47787836SJohn.Forte@Sun.COM 	int ret;
47797836SJohn.Forte@Sun.COM 
47807836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
47817836SJohn.Forte@Sun.COM 
47827836SJohn.Forte@Sun.COM 	switch (object) {
47837836SJohn.Forte@Sun.COM 		case DISCOVERY_ADDRESS:
47847836SJohn.Forte@Sun.COM 		case ISNS_SERVER_ADDRESS:
47857836SJohn.Forte@Sun.COM 			ret = addAddress(object, operandLen, operand, funcRet);
47867836SJohn.Forte@Sun.COM 			break;
47877836SJohn.Forte@Sun.COM 		case STATIC_CONFIG:
47887836SJohn.Forte@Sun.COM 			ret = addStaticConfig(operandLen, operand, funcRet);
47897836SJohn.Forte@Sun.COM 			break;
47907836SJohn.Forte@Sun.COM 		default:
47917836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s\n",
47927836SJohn.Forte@Sun.COM 			    cmdName, gettext("unknown object"));
47937836SJohn.Forte@Sun.COM 			ret = 1;
47947836SJohn.Forte@Sun.COM 			break;
47957836SJohn.Forte@Sun.COM 	}
47967836SJohn.Forte@Sun.COM 	return (ret);
47977836SJohn.Forte@Sun.COM }
47987836SJohn.Forte@Sun.COM 
47997836SJohn.Forte@Sun.COM /*ARGSUSED*/
48007836SJohn.Forte@Sun.COM static int
listFunc(int operandLen,char * operand[],int object,cmdOptions_t * options,void * addArgs,int * funcRet)48017836SJohn.Forte@Sun.COM listFunc(int operandLen, char *operand[], int object, cmdOptions_t *options,
48027836SJohn.Forte@Sun.COM     void *addArgs, int *funcRet)
48037836SJohn.Forte@Sun.COM {
48047836SJohn.Forte@Sun.COM 	int ret;
48057836SJohn.Forte@Sun.COM 
48067836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
48077836SJohn.Forte@Sun.COM 
48087836SJohn.Forte@Sun.COM 	switch (object) {
48097836SJohn.Forte@Sun.COM 	case DISCOVERY:
48107836SJohn.Forte@Sun.COM 		ret = listDiscovery(funcRet);
48117836SJohn.Forte@Sun.COM 		break;
48127836SJohn.Forte@Sun.COM 	case DISCOVERY_ADDRESS:
48137836SJohn.Forte@Sun.COM 		ret = listDiscoveryAddress(operandLen, operand, options,
48147836SJohn.Forte@Sun.COM 		    funcRet);
48157836SJohn.Forte@Sun.COM 		break;
48167836SJohn.Forte@Sun.COM 	case ISNS_SERVER_ADDRESS:
48177836SJohn.Forte@Sun.COM 		ret = listISNSServerAddress(operandLen, operand, options,
48187836SJohn.Forte@Sun.COM 		    funcRet);
48197836SJohn.Forte@Sun.COM 		break;
48207836SJohn.Forte@Sun.COM 	case NODE:
48217836SJohn.Forte@Sun.COM 		ret = listNode(funcRet);
48227836SJohn.Forte@Sun.COM 		break;
48237836SJohn.Forte@Sun.COM 	case STATIC_CONFIG:
48247836SJohn.Forte@Sun.COM 		ret = listStaticConfig(operandLen, operand, funcRet);
48257836SJohn.Forte@Sun.COM 		break;
48267836SJohn.Forte@Sun.COM 	case TARGET:
48277836SJohn.Forte@Sun.COM 		ret = listTarget(operandLen, operand, options, funcRet);
48287836SJohn.Forte@Sun.COM 		break;
48297836SJohn.Forte@Sun.COM 	case TARGET_PARAM:
48307836SJohn.Forte@Sun.COM 		ret = listTargetParam(operandLen, operand, options, funcRet);
48317836SJohn.Forte@Sun.COM 		break;
48327836SJohn.Forte@Sun.COM 	default:
48337836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s\n",
48347836SJohn.Forte@Sun.COM 		    cmdName, gettext("unknown object"));
48357836SJohn.Forte@Sun.COM 		ret = 1;
48367836SJohn.Forte@Sun.COM 		break;
48377836SJohn.Forte@Sun.COM 	}
48387836SJohn.Forte@Sun.COM 	return (ret);
48397836SJohn.Forte@Sun.COM }
48407836SJohn.Forte@Sun.COM 
48417836SJohn.Forte@Sun.COM /*ARGSUSED*/
48427836SJohn.Forte@Sun.COM static int
modifyFunc(int operandLen,char * operand[],int object,cmdOptions_t * options,void * addArgs,int * funcRet)48437836SJohn.Forte@Sun.COM modifyFunc(int operandLen, char *operand[], int object, cmdOptions_t *options,
48447836SJohn.Forte@Sun.COM     void *addArgs, int *funcRet)
48457836SJohn.Forte@Sun.COM {
48467836SJohn.Forte@Sun.COM 	int ret, i;
48477836SJohn.Forte@Sun.COM 
48487836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
48497836SJohn.Forte@Sun.COM 
48507836SJohn.Forte@Sun.COM 	switch (object) {
48517836SJohn.Forte@Sun.COM 	case DISCOVERY:
48527836SJohn.Forte@Sun.COM 		ret = modifyDiscovery(options, funcRet);
48537836SJohn.Forte@Sun.COM 		break;
48547836SJohn.Forte@Sun.COM 	case NODE:
48557836SJohn.Forte@Sun.COM 		ret = modifyNode(options, funcRet);
48567836SJohn.Forte@Sun.COM 		break;
48577836SJohn.Forte@Sun.COM 	case TARGET_PARAM:
48587836SJohn.Forte@Sun.COM 		i = 0;
48597836SJohn.Forte@Sun.COM 		while (operand[i]) {
48607836SJohn.Forte@Sun.COM 			ret = modifyTargetParam(options, operand[i], funcRet);
48617836SJohn.Forte@Sun.COM 
48627836SJohn.Forte@Sun.COM 			if (ret) {
48637836SJohn.Forte@Sun.COM 				(void) fprintf(stderr, "%s: %s: %s\n",
48647836SJohn.Forte@Sun.COM 				    cmdName, gettext("modify failed"),
48657836SJohn.Forte@Sun.COM 				    operand[i]);
48667836SJohn.Forte@Sun.COM 				return (ret);
48677836SJohn.Forte@Sun.COM 			}
48687836SJohn.Forte@Sun.COM 			i++;
48697836SJohn.Forte@Sun.COM 		}
48707836SJohn.Forte@Sun.COM 
48717836SJohn.Forte@Sun.COM 		break;
48727836SJohn.Forte@Sun.COM 	default:
48737836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s\n",
48747836SJohn.Forte@Sun.COM 		    cmdName, gettext("unknown object"));
48757836SJohn.Forte@Sun.COM 		ret = 1;
48767836SJohn.Forte@Sun.COM 		break;
48777836SJohn.Forte@Sun.COM 	}
48787836SJohn.Forte@Sun.COM 	return (ret);
48797836SJohn.Forte@Sun.COM }
48807836SJohn.Forte@Sun.COM 
48817836SJohn.Forte@Sun.COM /*ARGSUSED*/
48827836SJohn.Forte@Sun.COM static int
removeFunc(int operandLen,char * operand[],int object,cmdOptions_t * options,void * addArgs,int * funcRet)48837836SJohn.Forte@Sun.COM removeFunc(int operandLen, char *operand[], int object, cmdOptions_t *options,
48847836SJohn.Forte@Sun.COM     void *addArgs, int *funcRet)
48857836SJohn.Forte@Sun.COM {
48867836SJohn.Forte@Sun.COM 	int ret;
48877836SJohn.Forte@Sun.COM 
48887836SJohn.Forte@Sun.COM 	switch (object) {
48897836SJohn.Forte@Sun.COM 		case DISCOVERY_ADDRESS:
48907836SJohn.Forte@Sun.COM 		case ISNS_SERVER_ADDRESS:
48917836SJohn.Forte@Sun.COM 			ret = removeAddress(object, operandLen, operand,
48927836SJohn.Forte@Sun.COM 			    funcRet);
48937836SJohn.Forte@Sun.COM 			break;
48947836SJohn.Forte@Sun.COM 		case STATIC_CONFIG:
48957836SJohn.Forte@Sun.COM 			ret = removeStaticConfig(operandLen, operand, funcRet);
48967836SJohn.Forte@Sun.COM 			break;
48977836SJohn.Forte@Sun.COM 		case TARGET_PARAM:
48987836SJohn.Forte@Sun.COM 			ret = removeTargetParam(operandLen, operand, funcRet);
48997836SJohn.Forte@Sun.COM 			break;
49007836SJohn.Forte@Sun.COM 		default:
49017836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s\n",
49027836SJohn.Forte@Sun.COM 			    cmdName, gettext("unknown object"));
49037836SJohn.Forte@Sun.COM 			ret = 1;
49047836SJohn.Forte@Sun.COM 			break;
49057836SJohn.Forte@Sun.COM 	}
49067836SJohn.Forte@Sun.COM 	return (ret);
49077836SJohn.Forte@Sun.COM }
49087836SJohn.Forte@Sun.COM 
49097836SJohn.Forte@Sun.COM static void
iSCSINameCheckStatusDisplay(iSCSINameCheckStatusType status)49107836SJohn.Forte@Sun.COM iSCSINameCheckStatusDisplay(iSCSINameCheckStatusType status)
49117836SJohn.Forte@Sun.COM {
49127836SJohn.Forte@Sun.COM 	switch (status) {
49137836SJohn.Forte@Sun.COM 		case iSCSINameLenZero:
49147836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s\n",
49157836SJohn.Forte@Sun.COM 			    cmdName, gettext("empty iSCSI name."));
49167836SJohn.Forte@Sun.COM 			break;
49177836SJohn.Forte@Sun.COM 		case iSCSINameLenExceededMax:
49187836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s\n", cmdName,
49197836SJohn.Forte@Sun.COM 			    gettext("iSCSI name exceeded maximum length."));
49207836SJohn.Forte@Sun.COM 			break;
49217836SJohn.Forte@Sun.COM 		case iSCSINameUnknownType:
49227836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s\n", cmdName,
49237836SJohn.Forte@Sun.COM 			    gettext("unknown iSCSI name type."));
49247836SJohn.Forte@Sun.COM 			break;
49257836SJohn.Forte@Sun.COM 		case iSCSINameInvalidCharacter:
49267836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s\n",
49277836SJohn.Forte@Sun.COM 			    cmdName,
49287836SJohn.Forte@Sun.COM 			    gettext("iSCSI name invalid character used"));
49297836SJohn.Forte@Sun.COM 			break;
49307836SJohn.Forte@Sun.COM 		case iSCSINameIqnFormatError:
49317836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s\n", cmdName,
49327836SJohn.Forte@Sun.COM 			    gettext("iqn formatting error."));
49337836SJohn.Forte@Sun.COM 			break;
49347836SJohn.Forte@Sun.COM 		case iSCSINameIqnDateFormatError:
49357836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s\n",
49367836SJohn.Forte@Sun.COM 			    cmdName, gettext("invalid iqn date." \
49377836SJohn.Forte@Sun.COM 			    "  format is: YYYY-MM"));
49387836SJohn.Forte@Sun.COM 			break;
49397836SJohn.Forte@Sun.COM 		case iSCSINameIqnSubdomainFormatError:
49407836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s\n",
49417836SJohn.Forte@Sun.COM 			    cmdName, gettext("missing subdomain after \":\""));
49427836SJohn.Forte@Sun.COM 			break;
49437836SJohn.Forte@Sun.COM 		case iSCSINameIqnInvalidYearError:
49447836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s\n",
49457836SJohn.Forte@Sun.COM 			    cmdName, gettext("invalid year"));
49467836SJohn.Forte@Sun.COM 			break;
49477836SJohn.Forte@Sun.COM 		case iSCSINameIqnInvalidMonthError:
49487836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s\n",
49497836SJohn.Forte@Sun.COM 			    cmdName, gettext("invalid month"));
49507836SJohn.Forte@Sun.COM 			break;
49517836SJohn.Forte@Sun.COM 		case iSCSINameIqnFQDNError:
49527836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s\n",
49537836SJohn.Forte@Sun.COM 			    cmdName, gettext("missing reversed fully qualified"\
49547836SJohn.Forte@Sun.COM 			    " domain name"));
49557836SJohn.Forte@Sun.COM 			break;
49567836SJohn.Forte@Sun.COM 		case iSCSINameEUIFormatError:
49577836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s\n", cmdName,
49587836SJohn.Forte@Sun.COM 			    gettext("eui formatting error."));
49597836SJohn.Forte@Sun.COM 			break;
49607836SJohn.Forte@Sun.COM 	}
49617836SJohn.Forte@Sun.COM }
49627836SJohn.Forte@Sun.COM 
49637836SJohn.Forte@Sun.COM /*
49647836SJohn.Forte@Sun.COM  * A convenient function to modify the target parameters of an individual
49657836SJohn.Forte@Sun.COM  * target.
49667836SJohn.Forte@Sun.COM  *
49677836SJohn.Forte@Sun.COM  * Return 0 if successful
49687836SJohn.Forte@Sun.COM  * Return 1 if failed
49697836SJohn.Forte@Sun.COM  */
49707836SJohn.Forte@Sun.COM static int
modifyIndividualTargetParam(cmdOptions_t * optionList,IMA_OID targetOid,int * funcRet)49717836SJohn.Forte@Sun.COM modifyIndividualTargetParam(cmdOptions_t *optionList, IMA_OID targetOid,
49727836SJohn.Forte@Sun.COM     int *funcRet)
49737836SJohn.Forte@Sun.COM {
49747836SJohn.Forte@Sun.COM 	assert(funcRet != NULL);
49757836SJohn.Forte@Sun.COM 
49767836SJohn.Forte@Sun.COM 	for (; optionList->optval; optionList++) {
49777836SJohn.Forte@Sun.COM 		switch (optionList->optval) {
49787836SJohn.Forte@Sun.COM 			case 'a':
49797836SJohn.Forte@Sun.COM 				if (modifyTargetAuthMethod(targetOid,
49807836SJohn.Forte@Sun.COM 				    optionList->optarg, funcRet) != 0) {
49817836SJohn.Forte@Sun.COM 					return (1);
49827836SJohn.Forte@Sun.COM 				}
49837836SJohn.Forte@Sun.COM 				break;
49847836SJohn.Forte@Sun.COM 			case 'B':
49857836SJohn.Forte@Sun.COM 				if (modifyTargetBidirAuthFlag(targetOid,
49867836SJohn.Forte@Sun.COM 				    optionList->optarg, funcRet) != 0) {
49877836SJohn.Forte@Sun.COM 					return (1);
49887836SJohn.Forte@Sun.COM 				}
49897836SJohn.Forte@Sun.COM 				break;
49907836SJohn.Forte@Sun.COM 			case 'C':
49917836SJohn.Forte@Sun.COM 				if (modifyTargetAuthParam(targetOid,
49927836SJohn.Forte@Sun.COM 				    AUTH_PASSWORD, NULL, funcRet) != 0) {
49937836SJohn.Forte@Sun.COM 					return (1);
49947836SJohn.Forte@Sun.COM 				}
49957836SJohn.Forte@Sun.COM 				break;
49967836SJohn.Forte@Sun.COM 			case 'd':
49977836SJohn.Forte@Sun.COM 				if (setLoginParameter(targetOid, DATA_DIGEST,
49987836SJohn.Forte@Sun.COM 				    optionList->optarg) != 0) {
49997836SJohn.Forte@Sun.COM 					return (1);
50007836SJohn.Forte@Sun.COM 				}
50017836SJohn.Forte@Sun.COM 				break;
50027836SJohn.Forte@Sun.COM 			case 'h':
50037836SJohn.Forte@Sun.COM 				if (setLoginParameter(targetOid, HEADER_DIGEST,
50047836SJohn.Forte@Sun.COM 				    optionList->optarg) != 0) {
50057836SJohn.Forte@Sun.COM 					return (1);
50067836SJohn.Forte@Sun.COM 				}
50077836SJohn.Forte@Sun.COM 				break;
50087836SJohn.Forte@Sun.COM 			case 'p':
50097836SJohn.Forte@Sun.COM 				/* Login parameter */
50107836SJohn.Forte@Sun.COM 				if (setLoginParameters(targetOid,
50117836SJohn.Forte@Sun.COM 				    optionList->optarg) != 0) {
50127836SJohn.Forte@Sun.COM 					return (1);
50137836SJohn.Forte@Sun.COM 				}
50147836SJohn.Forte@Sun.COM 				break;
50157836SJohn.Forte@Sun.COM 			case 'c':
50167836SJohn.Forte@Sun.COM 				/* Modify configure sessions */
50177836SJohn.Forte@Sun.COM 				if (modifyConfiguredSessions(targetOid,
50187836SJohn.Forte@Sun.COM 				    optionList->optarg) != 0) {
50197836SJohn.Forte@Sun.COM 					return (1);
50207836SJohn.Forte@Sun.COM 				}
50217836SJohn.Forte@Sun.COM 				break;
50227836SJohn.Forte@Sun.COM 			case 'H':
50237836SJohn.Forte@Sun.COM 				if (modifyTargetAuthParam(targetOid, AUTH_NAME,
50247836SJohn.Forte@Sun.COM 				    optionList->optarg, funcRet) != 0) {
50257836SJohn.Forte@Sun.COM 					return (1);
50267836SJohn.Forte@Sun.COM 				}
50277836SJohn.Forte@Sun.COM 				break;
502810156SZhang.Yi@Sun.COM 			case 'T':
502910156SZhang.Yi@Sun.COM 				if (setTunableParameters(targetOid,
503010156SZhang.Yi@Sun.COM 				    optionList->optarg) != 0) {
503110156SZhang.Yi@Sun.COM 					return (1);
503210156SZhang.Yi@Sun.COM 				}
503310156SZhang.Yi@Sun.COM 				break;
50347836SJohn.Forte@Sun.COM 		}
50357836SJohn.Forte@Sun.COM 	}
50367836SJohn.Forte@Sun.COM 
50377836SJohn.Forte@Sun.COM 	return (0);
50387836SJohn.Forte@Sun.COM }
50397836SJohn.Forte@Sun.COM 
50407836SJohn.Forte@Sun.COM /*
50417836SJohn.Forte@Sun.COM  * This helper function could go into a utility module for general use.
50427836SJohn.Forte@Sun.COM  */
50437836SJohn.Forte@Sun.COM static int
parseAddress(char * address_port_str,uint16_t defaultPort,char * address_str,size_t address_str_len,uint16_t * port,boolean_t * isIpv6)50447836SJohn.Forte@Sun.COM parseAddress(char *address_port_str,
50457836SJohn.Forte@Sun.COM     uint16_t defaultPort,
50467836SJohn.Forte@Sun.COM     char *address_str,
50477836SJohn.Forte@Sun.COM     size_t address_str_len,
50487836SJohn.Forte@Sun.COM     uint16_t *port,
50497836SJohn.Forte@Sun.COM     boolean_t *isIpv6)
50507836SJohn.Forte@Sun.COM {
50517836SJohn.Forte@Sun.COM 	char port_str[64];
50527836SJohn.Forte@Sun.COM 	int tmp_port;
50537836SJohn.Forte@Sun.COM 	char *errchr;
50547836SJohn.Forte@Sun.COM 
50557836SJohn.Forte@Sun.COM 	if (address_port_str[0] == '[') {
50567836SJohn.Forte@Sun.COM 		/* IPv6 address */
50577836SJohn.Forte@Sun.COM 		char *close_bracket_pos;
50587836SJohn.Forte@Sun.COM 		close_bracket_pos = strchr(address_port_str, ']');
50597836SJohn.Forte@Sun.COM 		if (!close_bracket_pos) {
50607836SJohn.Forte@Sun.COM 			syslog(LOG_USER|LOG_DEBUG,
50617836SJohn.Forte@Sun.COM 			    "IP address format error: %s\n", address_str);
50627836SJohn.Forte@Sun.COM 			return (PARSE_ADDR_MISSING_CLOSING_BRACKET);
50637836SJohn.Forte@Sun.COM 		}
50647836SJohn.Forte@Sun.COM 
50657836SJohn.Forte@Sun.COM 		*close_bracket_pos = NULL;
50667836SJohn.Forte@Sun.COM 		(void) strlcpy(address_str, &address_port_str[1],
50677836SJohn.Forte@Sun.COM 		    address_str_len);
50687836SJohn.Forte@Sun.COM 
50697836SJohn.Forte@Sun.COM 		/* Extract the port number */
50707836SJohn.Forte@Sun.COM 		close_bracket_pos++;
50717836SJohn.Forte@Sun.COM 		if (*close_bracket_pos == ':') {
50727836SJohn.Forte@Sun.COM 			close_bracket_pos++;
50737836SJohn.Forte@Sun.COM 			if (*close_bracket_pos != NULL) {
50747836SJohn.Forte@Sun.COM 				(void) strlcpy(port_str, close_bracket_pos, 64);
50757836SJohn.Forte@Sun.COM 				tmp_port = strtol(port_str, &errchr, 10);
50767836SJohn.Forte@Sun.COM 				if (tmp_port == 0 && errchr != NULL) {
50777836SJohn.Forte@Sun.COM 					(void) fprintf(stderr, "%s: %s:%s %s\n",
50787836SJohn.Forte@Sun.COM 					    cmdName, address_str,
50797836SJohn.Forte@Sun.COM 					    close_bracket_pos,
50807836SJohn.Forte@Sun.COM 					    gettext("port number invalid"));
50817836SJohn.Forte@Sun.COM 					return (PARSE_ADDR_PORT_OUT_OF_RANGE);
50827836SJohn.Forte@Sun.COM 				}
50837836SJohn.Forte@Sun.COM 				if ((tmp_port > 0) && (tmp_port > USHRT_MAX) ||
50847836SJohn.Forte@Sun.COM 				    (tmp_port < 0)) {
50857836SJohn.Forte@Sun.COM 					/* Port number out of range */
50867836SJohn.Forte@Sun.COM 					syslog(LOG_USER|LOG_DEBUG,
50877836SJohn.Forte@Sun.COM 					    "Specified port out of range: %d",
50887836SJohn.Forte@Sun.COM 					    tmp_port);
50897836SJohn.Forte@Sun.COM 					return (PARSE_ADDR_PORT_OUT_OF_RANGE);
50907836SJohn.Forte@Sun.COM 				} else {
50917836SJohn.Forte@Sun.COM 					*port = (uint16_t)tmp_port;
50927836SJohn.Forte@Sun.COM 				}
50937836SJohn.Forte@Sun.COM 			} else {
50947836SJohn.Forte@Sun.COM 				*port = defaultPort;
50957836SJohn.Forte@Sun.COM 			}
50967836SJohn.Forte@Sun.COM 		} else {
50977836SJohn.Forte@Sun.COM 			*port = defaultPort;
50987836SJohn.Forte@Sun.COM 		}
50997836SJohn.Forte@Sun.COM 
51007836SJohn.Forte@Sun.COM 		*isIpv6 = B_TRUE;
51017836SJohn.Forte@Sun.COM 	} else {
51027836SJohn.Forte@Sun.COM 		/* IPv4 address */
51037836SJohn.Forte@Sun.COM 		char *colon_pos;
51047836SJohn.Forte@Sun.COM 		colon_pos = strchr(address_port_str, ':');
51057836SJohn.Forte@Sun.COM 		if (!colon_pos) {
51067836SJohn.Forte@Sun.COM 			/* No port number specified. */
51077836SJohn.Forte@Sun.COM 			*port = defaultPort;
51087836SJohn.Forte@Sun.COM 			(void) strlcpy(address_str, address_port_str,
51097836SJohn.Forte@Sun.COM 			    address_str_len);
51107836SJohn.Forte@Sun.COM 		} else {
51117836SJohn.Forte@Sun.COM 			*colon_pos = (char)NULL;
51127836SJohn.Forte@Sun.COM 			(void) strlcpy(address_str, address_port_str,
51137836SJohn.Forte@Sun.COM 			    address_str_len);
51147836SJohn.Forte@Sun.COM 
51157836SJohn.Forte@Sun.COM 			/* Extract the port number */
51167836SJohn.Forte@Sun.COM 			colon_pos++;
51177836SJohn.Forte@Sun.COM 			if (*colon_pos != NULL) {
51187836SJohn.Forte@Sun.COM 
51197836SJohn.Forte@Sun.COM 				(void) strlcpy(port_str, colon_pos, 64);
51207836SJohn.Forte@Sun.COM 				tmp_port = strtol(port_str, &errchr, 10);
51217836SJohn.Forte@Sun.COM 				if (tmp_port == 0 && errchr != NULL) {
51227836SJohn.Forte@Sun.COM 					(void) fprintf(stderr, "%s: %s:%s %s\n",
51237836SJohn.Forte@Sun.COM 					    cmdName, address_str, colon_pos,
51247836SJohn.Forte@Sun.COM 					    gettext("port number invalid"));
51257836SJohn.Forte@Sun.COM 					return (PARSE_ADDR_PORT_OUT_OF_RANGE);
51267836SJohn.Forte@Sun.COM 				}
51277836SJohn.Forte@Sun.COM 				if ((tmp_port > 0) && (tmp_port > USHRT_MAX) ||
51287836SJohn.Forte@Sun.COM 				    (tmp_port < 0)) {
51297836SJohn.Forte@Sun.COM 					/* Port number out of range */
51307836SJohn.Forte@Sun.COM 					syslog(LOG_USER|LOG_DEBUG,
51317836SJohn.Forte@Sun.COM 					    "Specified port out of range: %d",
51327836SJohn.Forte@Sun.COM 					    tmp_port);
51337836SJohn.Forte@Sun.COM 					return (PARSE_ADDR_PORT_OUT_OF_RANGE);
51347836SJohn.Forte@Sun.COM 				} else {
51357836SJohn.Forte@Sun.COM 					*port = (uint16_t)tmp_port;
51367836SJohn.Forte@Sun.COM 				}
51377836SJohn.Forte@Sun.COM 			} else {
51387836SJohn.Forte@Sun.COM 				*port = defaultPort;
51397836SJohn.Forte@Sun.COM 			}
51407836SJohn.Forte@Sun.COM 		}
51417836SJohn.Forte@Sun.COM 
51427836SJohn.Forte@Sun.COM 		*isIpv6 = B_FALSE;
51437836SJohn.Forte@Sun.COM 	}
51447836SJohn.Forte@Sun.COM 
51457836SJohn.Forte@Sun.COM 	return (PARSE_ADDR_OK);
51467836SJohn.Forte@Sun.COM }
51477836SJohn.Forte@Sun.COM 
51487836SJohn.Forte@Sun.COM /*
51497836SJohn.Forte@Sun.COM  * This helper function could go into a utility module for general use.
51507836SJohn.Forte@Sun.COM  */
51517836SJohn.Forte@Sun.COM iSCSINameCheckStatusType
iSCSINameStringProfileCheck(wchar_t * name)51527836SJohn.Forte@Sun.COM iSCSINameStringProfileCheck(wchar_t *name)
51537836SJohn.Forte@Sun.COM {
51547836SJohn.Forte@Sun.COM 	char mb_name[MAX_ISCSI_NAME_LEN + 1];
51557836SJohn.Forte@Sun.COM 	size_t name_len;
51567836SJohn.Forte@Sun.COM 	char *tmp;
51577836SJohn.Forte@Sun.COM 
51587836SJohn.Forte@Sun.COM 	(void) wcstombs(mb_name, name, MAX_ISCSI_NAME_LEN + 1);
51597836SJohn.Forte@Sun.COM 
51607836SJohn.Forte@Sun.COM 	if ((name_len = strlen(mb_name)) == 0) {
51617836SJohn.Forte@Sun.COM 		return (iSCSINameLenZero);
51627836SJohn.Forte@Sun.COM 	} else if (name_len > MAX_ISCSI_NAME_LEN) {
51637836SJohn.Forte@Sun.COM 		return (iSCSINameLenExceededMax);
51647836SJohn.Forte@Sun.COM 	}
51657836SJohn.Forte@Sun.COM 
51667836SJohn.Forte@Sun.COM 	/*
51677836SJohn.Forte@Sun.COM 	 * check for invalid characters
51687836SJohn.Forte@Sun.COM 	 * According to RFC 3722 iSCSI name must be either a letter,
51697836SJohn.Forte@Sun.COM 	 * a digit or one of the following '-' '.' ':'
51707836SJohn.Forte@Sun.COM 	 */
51717836SJohn.Forte@Sun.COM 	for (tmp = mb_name; *tmp != NULL; tmp++) {
51727836SJohn.Forte@Sun.COM 		if ((isalnum(*tmp) == 0) &&
51737836SJohn.Forte@Sun.COM 		    (*tmp != '-') &&
51747836SJohn.Forte@Sun.COM 		    (*tmp != '.') &&
51757836SJohn.Forte@Sun.COM 		    (*tmp != ':')) {
51767836SJohn.Forte@Sun.COM 			return (iSCSINameInvalidCharacter);
51777836SJohn.Forte@Sun.COM 		}
51787836SJohn.Forte@Sun.COM 	}
51797836SJohn.Forte@Sun.COM 
51807836SJohn.Forte@Sun.COM 	if (strncmp(mb_name, ISCSI_IQN_NAME_PREFIX,
51817836SJohn.Forte@Sun.COM 	    strlen(ISCSI_IQN_NAME_PREFIX)) == 0) {
51827836SJohn.Forte@Sun.COM 		/*
51837836SJohn.Forte@Sun.COM 		 * If name is of type iqn, check date string and naming
51847836SJohn.Forte@Sun.COM 		 * authority.
51857836SJohn.Forte@Sun.COM 		 */
51867836SJohn.Forte@Sun.COM 		char *strp = NULL;
51877836SJohn.Forte@Sun.COM 
51887836SJohn.Forte@Sun.COM 		/*
51897836SJohn.Forte@Sun.COM 		 * Don't allow the string to end with a colon.  If there is a
51907836SJohn.Forte@Sun.COM 		 * colon then there must be a subdomain provided.
51917836SJohn.Forte@Sun.COM 		 */
51927836SJohn.Forte@Sun.COM 		if (mb_name[strlen(mb_name) - 1] == ':') {
51937836SJohn.Forte@Sun.COM 			return (iSCSINameIqnSubdomainFormatError);
51947836SJohn.Forte@Sun.COM 		}
51957836SJohn.Forte@Sun.COM 
51967836SJohn.Forte@Sun.COM 		/* Date string */
51977836SJohn.Forte@Sun.COM 		strp = strtok(&mb_name[3], ".");
51987836SJohn.Forte@Sun.COM 		if (strp) {
51997836SJohn.Forte@Sun.COM 			char tmpYear[5], tmpMonth[3], *endPtr = NULL;
52007836SJohn.Forte@Sun.COM 			int year, month;
52017836SJohn.Forte@Sun.COM 
52027836SJohn.Forte@Sun.COM 			/* Date string should be in YYYY-MM format */
52037836SJohn.Forte@Sun.COM 			if (strlen(strp) != strlen("YYYY-MM") ||
52047836SJohn.Forte@Sun.COM 			    strp[4] != '-') {
52057836SJohn.Forte@Sun.COM 				return (iSCSINameIqnDateFormatError);
52067836SJohn.Forte@Sun.COM 			}
52077836SJohn.Forte@Sun.COM 
52087836SJohn.Forte@Sun.COM 			/*
52097836SJohn.Forte@Sun.COM 			 * Validate year.  Only validating that the
52107836SJohn.Forte@Sun.COM 			 * year can be converted to a number.  No
52117836SJohn.Forte@Sun.COM 			 * validation will be done on year's actual
52127836SJohn.Forte@Sun.COM 			 * value.
52137836SJohn.Forte@Sun.COM 			 */
52147836SJohn.Forte@Sun.COM 			(void) strncpy(tmpYear, strp, 4);
52157836SJohn.Forte@Sun.COM 			tmpYear[4] = '\0';
52167836SJohn.Forte@Sun.COM 
52177836SJohn.Forte@Sun.COM 			errno = 0;
52187836SJohn.Forte@Sun.COM 			year = strtol(tmpYear, &endPtr, 10);
52197836SJohn.Forte@Sun.COM 			if (errno != 0 || *endPtr != '\0' ||
52207836SJohn.Forte@Sun.COM 			    year < 0 || year > 9999) {
52217836SJohn.Forte@Sun.COM 				return (iSCSINameIqnInvalidYearError);
52227836SJohn.Forte@Sun.COM 			}
52237836SJohn.Forte@Sun.COM 
52247836SJohn.Forte@Sun.COM 			/*
52257836SJohn.Forte@Sun.COM 			 * Validate month is valid.
52267836SJohn.Forte@Sun.COM 			 */
52277836SJohn.Forte@Sun.COM 			(void) strncpy(tmpMonth, &strp[5], 2);
52287836SJohn.Forte@Sun.COM 			tmpMonth[2] = '\0';
52297836SJohn.Forte@Sun.COM 			errno = 0;
52307836SJohn.Forte@Sun.COM 			month = strtol(tmpMonth, &endPtr, 10);
52317836SJohn.Forte@Sun.COM 
52327836SJohn.Forte@Sun.COM 			if (errno != 0 || *endPtr != '\0' ||
52337836SJohn.Forte@Sun.COM 			    month < 1 || month > 12) {
52347836SJohn.Forte@Sun.COM 				return (iSCSINameIqnInvalidMonthError);
52357836SJohn.Forte@Sun.COM 			}
52367836SJohn.Forte@Sun.COM 
52377836SJohn.Forte@Sun.COM 			/*
52387836SJohn.Forte@Sun.COM 			 * A reversed FQDN needs to be provided.  We
52397836SJohn.Forte@Sun.COM 			 * will only check for a "." followed by more
52407836SJohn.Forte@Sun.COM 			 * than two or more characters.  The list of domains is
52417836SJohn.Forte@Sun.COM 			 * too large and changes too frequently to
52427836SJohn.Forte@Sun.COM 			 * add validation for.
52437836SJohn.Forte@Sun.COM 			 */
52447836SJohn.Forte@Sun.COM 			strp = strtok(NULL, ".");
52457836SJohn.Forte@Sun.COM 			if (!strp || strlen(strp) < 2) {
52467836SJohn.Forte@Sun.COM 				return (iSCSINameIqnFQDNError);
52477836SJohn.Forte@Sun.COM 			}
52487836SJohn.Forte@Sun.COM 
52497836SJohn.Forte@Sun.COM 			/* Name authority string */
52507836SJohn.Forte@Sun.COM 			strp = strtok(NULL, ":");
52517836SJohn.Forte@Sun.COM 			if (strp) {
52527836SJohn.Forte@Sun.COM 				return (iSCSINameCheckOK);
52537836SJohn.Forte@Sun.COM 			} else {
52547836SJohn.Forte@Sun.COM 				return (iSCSINameIqnFQDNError);
52557836SJohn.Forte@Sun.COM 			}
52567836SJohn.Forte@Sun.COM 		} else {
52577836SJohn.Forte@Sun.COM 			return (iSCSINameIqnFormatError);
52587836SJohn.Forte@Sun.COM 		}
52597836SJohn.Forte@Sun.COM 	} else if (strncmp(mb_name, ISCSI_EUI_NAME_PREFIX,
52607836SJohn.Forte@Sun.COM 	    strlen(ISCSI_EUI_NAME_PREFIX)) == 0) {
52617836SJohn.Forte@Sun.COM 		/* If name is of type EUI, change its length */
52627836SJohn.Forte@Sun.COM 
52637836SJohn.Forte@Sun.COM 		if (strlen(mb_name) != ISCSI_EUI_NAME_LEN) {
52647836SJohn.Forte@Sun.COM 			return (iSCSINameEUIFormatError);
52657836SJohn.Forte@Sun.COM 		}
52667836SJohn.Forte@Sun.COM 
52677836SJohn.Forte@Sun.COM 		for (tmp = mb_name + strlen(ISCSI_EUI_NAME_PREFIX) + 1;
52687836SJohn.Forte@Sun.COM 		    *tmp != '\0'; tmp++) {
52697836SJohn.Forte@Sun.COM 			if (isxdigit(*tmp)) {
52707836SJohn.Forte@Sun.COM 				continue;
52717836SJohn.Forte@Sun.COM 			}
52727836SJohn.Forte@Sun.COM 			return (iSCSINameEUIFormatError);
52737836SJohn.Forte@Sun.COM 		}
52747836SJohn.Forte@Sun.COM 
52757836SJohn.Forte@Sun.COM 		return (iSCSINameCheckOK);
52767836SJohn.Forte@Sun.COM 	} else {
52777836SJohn.Forte@Sun.COM 		return (iSCSINameUnknownType);
52787836SJohn.Forte@Sun.COM 	}
52797836SJohn.Forte@Sun.COM }
52807836SJohn.Forte@Sun.COM 
52817836SJohn.Forte@Sun.COM /*
52827836SJohn.Forte@Sun.COM  * This helper function could go into a utility module for general use.
52837836SJohn.Forte@Sun.COM  *
52847836SJohn.Forte@Sun.COM  * Returns:
52857836SJohn.Forte@Sun.COM  * B_TRUE is the numberStr is an unsigned natural number and within the
52867836SJohn.Forte@Sun.COM  * specified bound.
52877836SJohn.Forte@Sun.COM  * B_FALSE otherwise.
52887836SJohn.Forte@Sun.COM  */
52897836SJohn.Forte@Sun.COM boolean_t
isNaturalNumber(char * numberStr,uint32_t upperBound)52907836SJohn.Forte@Sun.COM isNaturalNumber(char *numberStr, uint32_t upperBound)
52917836SJohn.Forte@Sun.COM {
52927836SJohn.Forte@Sun.COM 	int i;
52937836SJohn.Forte@Sun.COM 	int number_str_len;
52947836SJohn.Forte@Sun.COM 
52957836SJohn.Forte@Sun.COM 	if ((number_str_len = strlen(numberStr)) == 0) {
52967836SJohn.Forte@Sun.COM 		return (B_FALSE);
52977836SJohn.Forte@Sun.COM 	}
52987836SJohn.Forte@Sun.COM 
52997836SJohn.Forte@Sun.COM 	for (i = 0; i < number_str_len; i++) {
53007836SJohn.Forte@Sun.COM 		if (numberStr[i] < 060 || numberStr[i] > 071) {
53017836SJohn.Forte@Sun.COM 			return (B_FALSE);
53027836SJohn.Forte@Sun.COM 		}
53037836SJohn.Forte@Sun.COM 	}
53047836SJohn.Forte@Sun.COM 
53057836SJohn.Forte@Sun.COM 	if (atoi(numberStr) > upperBound) {
53067836SJohn.Forte@Sun.COM 		return (B_FALSE);
53077836SJohn.Forte@Sun.COM 	}
53087836SJohn.Forte@Sun.COM 
53097836SJohn.Forte@Sun.COM 	return (B_TRUE);
53107836SJohn.Forte@Sun.COM }
53117836SJohn.Forte@Sun.COM 
53127836SJohn.Forte@Sun.COM /*
53137836SJohn.Forte@Sun.COM  * This helper function could go into a utility module for general use.
53147836SJohn.Forte@Sun.COM  * It parses a target string in the format of:
53157836SJohn.Forte@Sun.COM  *
53167836SJohn.Forte@Sun.COM  * 	<target_name>,[<ip_address>[:port][,tpgt]]
53177836SJohn.Forte@Sun.COM  *
53187836SJohn.Forte@Sun.COM  * and creates wchar strings for target name and target address. It
53197836SJohn.Forte@Sun.COM  * also populates port and tpgt if found.
53207836SJohn.Forte@Sun.COM  *
53217836SJohn.Forte@Sun.COM  * Returns:
53227836SJohn.Forte@Sun.COM  * 	PARSE_TARGET_OK if parsing is successful.
53237836SJohn.Forte@Sun.COM  *	PARSE_TARGET_INVALID_TPGT if the specified tpgt is
53247836SJohn.Forte@Sun.COM  *	invalid.
53257836SJohn.Forte@Sun.COM  * 	PARSE_TARGET_INVALID_ADDR if the address specified is
53267836SJohn.Forte@Sun.COM  *	invalid.
53277836SJohn.Forte@Sun.COM  */
53287836SJohn.Forte@Sun.COM 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)53297836SJohn.Forte@Sun.COM parseTarget(char *targetStr,
53307836SJohn.Forte@Sun.COM 		wchar_t *targetNameStr,
53317836SJohn.Forte@Sun.COM 		size_t targetNameStrLen,
53327836SJohn.Forte@Sun.COM 		boolean_t *targetAddressSpecified,
53337836SJohn.Forte@Sun.COM 		wchar_t *targetAddressStr,
53347836SJohn.Forte@Sun.COM 		size_t targetAddressStrLen,
53357836SJohn.Forte@Sun.COM 		uint16_t *port,
53367836SJohn.Forte@Sun.COM 		boolean_t *tpgtSpecified,
53377836SJohn.Forte@Sun.COM 		uint16_t *tpgt,
53387836SJohn.Forte@Sun.COM 		boolean_t *isIpv6)
53397836SJohn.Forte@Sun.COM {
53407836SJohn.Forte@Sun.COM 	char *commaPos;
53417836SJohn.Forte@Sun.COM 	char *commaPos2;
53427836SJohn.Forte@Sun.COM 	char targetAddress[SUN_IMA_IP_ADDRESS_PORT_LEN];
53437836SJohn.Forte@Sun.COM 	int i;
53447836SJohn.Forte@Sun.COM 	int lowerCase;
53457836SJohn.Forte@Sun.COM 
53467836SJohn.Forte@Sun.COM 	(void) memset(targetNameStr, 0,
53477836SJohn.Forte@Sun.COM 	    targetNameStrLen * sizeof (wchar_t));
53487836SJohn.Forte@Sun.COM 	(void) memset(targetAddressStr, 0,
53497836SJohn.Forte@Sun.COM 	    targetAddressStrLen * sizeof (wchar_t));
53507836SJohn.Forte@Sun.COM 
53517836SJohn.Forte@Sun.COM 	commaPos = strchr(targetStr, ',');
53527836SJohn.Forte@Sun.COM 	if (commaPos != NULL) {
53537836SJohn.Forte@Sun.COM 		*commaPos = NULL;
53547836SJohn.Forte@Sun.COM 		commaPos++;
53557836SJohn.Forte@Sun.COM 		*targetAddressSpecified = B_TRUE;
53567836SJohn.Forte@Sun.COM 
53577836SJohn.Forte@Sun.COM 		/*
53587836SJohn.Forte@Sun.COM 		 * Checking of tpgt makes sense only when
53597836SJohn.Forte@Sun.COM 		 * the target address/port are specified.
53607836SJohn.Forte@Sun.COM 		 */
53617836SJohn.Forte@Sun.COM 		commaPos2 = strchr(commaPos, ',');
53627836SJohn.Forte@Sun.COM 		if (commaPos2 != NULL) {
53637836SJohn.Forte@Sun.COM 			*commaPos2 = NULL;
53647836SJohn.Forte@Sun.COM 			commaPos2++;
53657836SJohn.Forte@Sun.COM 			if (isNaturalNumber(commaPos2, ISCSI_MAX_TPGT_VALUE) ==
53667836SJohn.Forte@Sun.COM 			    B_TRUE) {
53677836SJohn.Forte@Sun.COM 				*tpgt = atoi(commaPos2);
53687836SJohn.Forte@Sun.COM 				*tpgtSpecified = B_TRUE;
53697836SJohn.Forte@Sun.COM 			} else {
53709414SBing.Zhao@Sun.COM 				(void) fprintf(stderr, "%s: %s\n", cmdName,
53719414SBing.Zhao@Sun.COM 				    gettext("parse target invalid TPGT"));
53727836SJohn.Forte@Sun.COM 				return (PARSE_TARGET_INVALID_TPGT);
53737836SJohn.Forte@Sun.COM 			}
53747836SJohn.Forte@Sun.COM 		}
53757836SJohn.Forte@Sun.COM 
53767836SJohn.Forte@Sun.COM 		switch (parseAddress(commaPos, ISCSI_LISTEN_PORT,
53777836SJohn.Forte@Sun.COM 		    &targetAddress[0], MAX_ADDRESS_LEN + 1, port, isIpv6)) {
53787836SJohn.Forte@Sun.COM 		case PARSE_ADDR_PORT_OUT_OF_RANGE:
53797836SJohn.Forte@Sun.COM 			return (PARSE_TARGET_INVALID_ADDR);
53807836SJohn.Forte@Sun.COM 		case PARSE_ADDR_OK:
53817836SJohn.Forte@Sun.COM 			break;
53827836SJohn.Forte@Sun.COM 		default:
53837836SJohn.Forte@Sun.COM 			(void) fprintf(stderr, "%s: %s\n",
53847836SJohn.Forte@Sun.COM 			    cmdName, gettext("cannot parse target name"));
53857836SJohn.Forte@Sun.COM 			return (PARSE_TARGET_INVALID_ADDR);
53867836SJohn.Forte@Sun.COM 		}
53877836SJohn.Forte@Sun.COM 		(void) mbstowcs(targetAddressStr, targetAddress,
53887836SJohn.Forte@Sun.COM 		    targetAddressStrLen);
53897836SJohn.Forte@Sun.COM 		for (i = 0; targetAddressStr[i] != 0; i++) {
53907836SJohn.Forte@Sun.COM 			lowerCase = tolower(targetAddressStr[i]);
53917836SJohn.Forte@Sun.COM 			targetAddressStr[i] = lowerCase;
53927836SJohn.Forte@Sun.COM 		}
53937836SJohn.Forte@Sun.COM 	} else {
53947836SJohn.Forte@Sun.COM 		*targetAddressSpecified = B_FALSE;
53957836SJohn.Forte@Sun.COM 		*tpgtSpecified = B_FALSE;
53967836SJohn.Forte@Sun.COM 	}
53977836SJohn.Forte@Sun.COM 
53987836SJohn.Forte@Sun.COM 	(void) mbstowcs(targetNameStr, targetStr, targetNameStrLen);
53997836SJohn.Forte@Sun.COM 	for (i = 0; targetNameStr[i] != 0; i++) {
54007836SJohn.Forte@Sun.COM 		lowerCase = tolower(targetNameStr[i]);
54017836SJohn.Forte@Sun.COM 		targetNameStr[i] = lowerCase;
54027836SJohn.Forte@Sun.COM 	}
54037836SJohn.Forte@Sun.COM 
54047836SJohn.Forte@Sun.COM 	return (PARSE_TARGET_OK);
54057836SJohn.Forte@Sun.COM }
54067836SJohn.Forte@Sun.COM 
54077836SJohn.Forte@Sun.COM /*ARGSUSED*/
54087836SJohn.Forte@Sun.COM static void
listCHAPName(IMA_OID oid)54097836SJohn.Forte@Sun.COM listCHAPName(IMA_OID oid)
54107836SJohn.Forte@Sun.COM {
54117836SJohn.Forte@Sun.COM 	IMA_INITIATOR_AUTHPARMS authParams;
54127836SJohn.Forte@Sun.COM 	IMA_STATUS status;
54137836SJohn.Forte@Sun.COM 	IMA_BYTE chapName [MAX_CHAP_NAME_LEN + 1];
54147836SJohn.Forte@Sun.COM 
54157836SJohn.Forte@Sun.COM 	/* Get Chap Name depending upon oid object type */
54167836SJohn.Forte@Sun.COM 	if (oid.objectType == IMA_OBJECT_TYPE_LHBA) {
54177836SJohn.Forte@Sun.COM 		status = IMA_GetInitiatorAuthParms(oid,
54187836SJohn.Forte@Sun.COM 		    IMA_AUTHMETHOD_CHAP, &authParams);
54197836SJohn.Forte@Sun.COM 	} else {
54207836SJohn.Forte@Sun.COM 		status = SUN_IMA_GetTargetAuthParms(oid,
54217836SJohn.Forte@Sun.COM 		    IMA_AUTHMETHOD_CHAP, &authParams);
54227836SJohn.Forte@Sun.COM 	}
54237836SJohn.Forte@Sun.COM 
54247836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "\n\t\t%s: ", gettext("CHAP Name"));
54257836SJohn.Forte@Sun.COM 
54267836SJohn.Forte@Sun.COM 	if (IMA_SUCCESS(status)) {
54277836SJohn.Forte@Sun.COM 		/*
54287836SJohn.Forte@Sun.COM 		 * Default chap name will be the node name.  The default will
54297836SJohn.Forte@Sun.COM 		 * be set by the driver.
54307836SJohn.Forte@Sun.COM 		 */
54317836SJohn.Forte@Sun.COM 		if (authParams.chapParms.nameLength != 0) {
54327836SJohn.Forte@Sun.COM 			(void) memset(chapName, 0, sizeof (chapName));
54337836SJohn.Forte@Sun.COM 			(void) memcpy(chapName, authParams.chapParms.name,
54347836SJohn.Forte@Sun.COM 			    authParams.chapParms.nameLength);
54357836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "%s", chapName);
54367836SJohn.Forte@Sun.COM 
54377836SJohn.Forte@Sun.COM 		} else {
54387836SJohn.Forte@Sun.COM 			(void) fprintf(stdout, "%s", "-");
54397836SJohn.Forte@Sun.COM 		}
54407836SJohn.Forte@Sun.COM 	} else {
54417836SJohn.Forte@Sun.COM 		(void) fprintf(stdout, "%s", "-");
54427836SJohn.Forte@Sun.COM 	}
54437836SJohn.Forte@Sun.COM }
54447836SJohn.Forte@Sun.COM 
54459201SJack.Meng@Sun.COM static boolean_t
checkServiceStatus(void)54469201SJack.Meng@Sun.COM checkServiceStatus(void)
54479201SJack.Meng@Sun.COM {
54489201SJack.Meng@Sun.COM 	IMA_STATUS	status	=	IMA_ERROR_UNKNOWN_ERROR;
54499201SJack.Meng@Sun.COM 	IMA_BOOL	enabled =	0;
54509201SJack.Meng@Sun.COM 
54519201SJack.Meng@Sun.COM 	status = SUN_IMA_GetSvcStatus(&enabled);
54529201SJack.Meng@Sun.COM 
54539201SJack.Meng@Sun.COM 	if (status != IMA_STATUS_SUCCESS) {
54549201SJack.Meng@Sun.COM 		(void) fprintf(stdout, "%s\n%s\n",
54559201SJack.Meng@Sun.COM 		    gettext("Unable to query the service status of"
54569201SJack.Meng@Sun.COM 		    " iSCSI initiator."),
54579201SJack.Meng@Sun.COM 		    gettext("For more information, please refer to"
54589201SJack.Meng@Sun.COM 		    " iscsi(7D)."));
54599201SJack.Meng@Sun.COM 		return (B_FALSE);
54609201SJack.Meng@Sun.COM 	}
54619201SJack.Meng@Sun.COM 
54629201SJack.Meng@Sun.COM 	if (enabled == 0) {
54639201SJack.Meng@Sun.COM 		(void) fprintf(stdout, "%s\n%s\n",
54649201SJack.Meng@Sun.COM 		    gettext("iSCSI Initiator Service is disabled,"
54659201SJack.Meng@Sun.COM 		    " try 'svcadm enable network/iscsi/initiator' to"
54669201SJack.Meng@Sun.COM 		    " enable the service."),
54679201SJack.Meng@Sun.COM 		    gettext("For more information, please refer to"
54689201SJack.Meng@Sun.COM 		    " iscsi(7D)."));
54699201SJack.Meng@Sun.COM 		return (B_FALSE);
54709201SJack.Meng@Sun.COM 	}
54719201SJack.Meng@Sun.COM 
54729201SJack.Meng@Sun.COM 	return (B_TRUE);
54739201SJack.Meng@Sun.COM }
54749201SJack.Meng@Sun.COM 
54757836SJohn.Forte@Sun.COM /*
54767836SJohn.Forte@Sun.COM  * Prints out see manual page.
54777836SJohn.Forte@Sun.COM  * Called out through atexit(3C) so is always last thing displayed.
54787836SJohn.Forte@Sun.COM  */
54797836SJohn.Forte@Sun.COM void
seeMan(void)54807836SJohn.Forte@Sun.COM seeMan(void)
54817836SJohn.Forte@Sun.COM {
54827836SJohn.Forte@Sun.COM 	static int sent = 0;
54837836SJohn.Forte@Sun.COM 
54847836SJohn.Forte@Sun.COM 	if (sent)
54857836SJohn.Forte@Sun.COM 		return;
54867836SJohn.Forte@Sun.COM 
54877836SJohn.Forte@Sun.COM 	(void) fprintf(stdout, "%s %s(1M)\n",
54887836SJohn.Forte@Sun.COM 	    gettext("For more information, please see"), cmdName);
54897836SJohn.Forte@Sun.COM 
54907836SJohn.Forte@Sun.COM 	sent = 1;
54917836SJohn.Forte@Sun.COM }
54927836SJohn.Forte@Sun.COM 
54937836SJohn.Forte@Sun.COM 
54947836SJohn.Forte@Sun.COM /*
54957836SJohn.Forte@Sun.COM  * main calls a parser that checks syntax of the input command against
54967836SJohn.Forte@Sun.COM  * various rules tables.
54977836SJohn.Forte@Sun.COM  *
54987836SJohn.Forte@Sun.COM  * The parser provides usage feedback based upon same tables by calling
54997836SJohn.Forte@Sun.COM  * two usage functions, usage and subUsage, handling command and subcommand
55007836SJohn.Forte@Sun.COM  * usage respectively.
55017836SJohn.Forte@Sun.COM  *
55027836SJohn.Forte@Sun.COM  * The parser handles all printing of usage syntactical errors
55037836SJohn.Forte@Sun.COM  *
55047836SJohn.Forte@Sun.COM  * When syntax is successfully validated, the parser calls the associated
55057836SJohn.Forte@Sun.COM  * function using the subcommands table functions.
55067836SJohn.Forte@Sun.COM  *
55077836SJohn.Forte@Sun.COM  * Syntax is as follows:
55087836SJohn.Forte@Sun.COM  *	command subcommand [options] resource-type [<object>]
55097836SJohn.Forte@Sun.COM  *
55107836SJohn.Forte@Sun.COM  * The return value from the function is placed in funcRet
55117836SJohn.Forte@Sun.COM  */
55127836SJohn.Forte@Sun.COM int
main(int argc,char * argv[])55137836SJohn.Forte@Sun.COM main(int argc, char *argv[])
55147836SJohn.Forte@Sun.COM {
55157836SJohn.Forte@Sun.COM 	synTables_t synTables;
55167836SJohn.Forte@Sun.COM 	char versionString[VERSION_STRING_MAX_LEN];
55177836SJohn.Forte@Sun.COM 	int ret;
55187836SJohn.Forte@Sun.COM 	int funcRet = 0;
55197836SJohn.Forte@Sun.COM 	void *subcommandArgs = NULL;
55207836SJohn.Forte@Sun.COM 
55217836SJohn.Forte@Sun.COM 	if (geteuid() != 0) {
55227836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s\n", gettext("permission denied"));
55237836SJohn.Forte@Sun.COM 		return (1);
55247836SJohn.Forte@Sun.COM 	}
55257836SJohn.Forte@Sun.COM 
55269201SJack.Meng@Sun.COM 	if (checkServiceStatus() == B_FALSE) {
55279201SJack.Meng@Sun.COM 		return (1);
55289201SJack.Meng@Sun.COM 	}
55299201SJack.Meng@Sun.COM 
55307836SJohn.Forte@Sun.COM 	/* set global command name */
55317836SJohn.Forte@Sun.COM 	cmdName = getExecBasename(argv[0]);
55327836SJohn.Forte@Sun.COM 
55337836SJohn.Forte@Sun.COM 	(void) snprintf(versionString, sizeof (versionString), "%s.%s",
55347836SJohn.Forte@Sun.COM 	    VERSION_STRING_MAJOR, VERSION_STRING_MINOR);
55357836SJohn.Forte@Sun.COM 	synTables.versionString = versionString;
55367836SJohn.Forte@Sun.COM 	synTables.longOptionTbl = &longOptions[0];
55377836SJohn.Forte@Sun.COM 	synTables.subcommandTbl = &subcommands[0];
55387836SJohn.Forte@Sun.COM 	synTables.objectTbl = &objects[0];
55397836SJohn.Forte@Sun.COM 	synTables.objectRulesTbl = &objectRules[0];
55407836SJohn.Forte@Sun.COM 	synTables.optionRulesTbl = &optionRules[0];
55417836SJohn.Forte@Sun.COM 
55427836SJohn.Forte@Sun.COM 	/* call the CLI parser */
55437836SJohn.Forte@Sun.COM 	ret = cmdParse(argc, argv, synTables, subcommandArgs, &funcRet);
55447836SJohn.Forte@Sun.COM 	if (ret == -1) {
55457836SJohn.Forte@Sun.COM 		perror(cmdName);
55467836SJohn.Forte@Sun.COM 		ret = 1;
55477836SJohn.Forte@Sun.COM 	}
55487836SJohn.Forte@Sun.COM 
55497836SJohn.Forte@Sun.COM 	if (funcRet != 0) {
55507836SJohn.Forte@Sun.COM 		(void) fprintf(stderr, "%s: %s\n",
55517836SJohn.Forte@Sun.COM 		    cmdName, gettext("Unable to complete operation"));
55527836SJohn.Forte@Sun.COM 		ret = 1;
55537836SJohn.Forte@Sun.COM 	}
55547836SJohn.Forte@Sun.COM 	return (ret);
55557836SJohn.Forte@Sun.COM }
555610156SZhang.Yi@Sun.COM 
555710156SZhang.Yi@Sun.COM static int
setTunableParameters(IMA_OID oid,char * optarg)555810156SZhang.Yi@Sun.COM setTunableParameters(IMA_OID oid, char *optarg)
555910156SZhang.Yi@Sun.COM {
556010156SZhang.Yi@Sun.COM 	char keyp[MAXOPTARGLEN];
556110156SZhang.Yi@Sun.COM 	char valp[MAXOPTARGLEN];
556210156SZhang.Yi@Sun.COM 	int key;
556310156SZhang.Yi@Sun.COM 	IMA_STATUS status;
556410156SZhang.Yi@Sun.COM 	IMA_UINT uintValue;
556510156SZhang.Yi@Sun.COM 	ISCSI_TUNABLE_PARAM	tunableObj;
556610156SZhang.Yi@Sun.COM 	char *nameValueString, *endptr;
556710156SZhang.Yi@Sun.COM 
556810156SZhang.Yi@Sun.COM 	if ((nameValueString = strdup(optarg)) == NULL) {
556910156SZhang.Yi@Sun.COM 		if (errno == ENOMEM) {
557010156SZhang.Yi@Sun.COM 			(void) fprintf(stderr, "%s: %s\n",
557110156SZhang.Yi@Sun.COM 			    cmdName, strerror(errno));
557210156SZhang.Yi@Sun.COM 		} else {
557310156SZhang.Yi@Sun.COM 			(void) fprintf(stderr, "%s: %s\n", cmdName,
557410156SZhang.Yi@Sun.COM 			    gettext("unknown error"));
557510156SZhang.Yi@Sun.COM 		}
557610156SZhang.Yi@Sun.COM 		return (1);
557710156SZhang.Yi@Sun.COM 	}
557810156SZhang.Yi@Sun.COM 
557910156SZhang.Yi@Sun.COM 	(void) memset(keyp, 0, sizeof (keyp));
558010156SZhang.Yi@Sun.COM 	(void) memset(valp, 0, sizeof (valp));
558110156SZhang.Yi@Sun.COM 	if (sscanf(nameValueString, gettext("%[^=]=%s"), keyp, valp) != 2) {
558210156SZhang.Yi@Sun.COM 		(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
558310156SZhang.Yi@Sun.COM 		    gettext("Unknown param"), nameValueString);
558410156SZhang.Yi@Sun.COM 		if (nameValueString) {
558510156SZhang.Yi@Sun.COM 			free(nameValueString);
558610156SZhang.Yi@Sun.COM 			nameValueString = NULL;
558710156SZhang.Yi@Sun.COM 		}
558810156SZhang.Yi@Sun.COM 		return (1);
558910156SZhang.Yi@Sun.COM 	}
559010156SZhang.Yi@Sun.COM 	if ((key = getTunableParam(keyp)) == -1) {
559110156SZhang.Yi@Sun.COM 		(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
559210156SZhang.Yi@Sun.COM 		    gettext("Unknown key"), keyp);
559310156SZhang.Yi@Sun.COM 		if (nameValueString) {
559410156SZhang.Yi@Sun.COM 			free(nameValueString);
559510156SZhang.Yi@Sun.COM 			nameValueString = NULL;
559610156SZhang.Yi@Sun.COM 		}
559710156SZhang.Yi@Sun.COM 		return (1);
559810156SZhang.Yi@Sun.COM 	}
559910156SZhang.Yi@Sun.COM 	switch (key) {
560010156SZhang.Yi@Sun.COM 	case RECV_LOGIN_RSP_TIMEOUT:
560110156SZhang.Yi@Sun.COM 	case CONN_LOGIN_MAX:
560210156SZhang.Yi@Sun.COM 	case POLLING_LOGIN_DELAY:
560310156SZhang.Yi@Sun.COM 		errno = 0;
560410156SZhang.Yi@Sun.COM 		uintValue = strtoul(valp, &endptr, 0);
560510156SZhang.Yi@Sun.COM 		if (*endptr != '\0' || errno != 0) {
560610156SZhang.Yi@Sun.COM 			(void) fprintf(stderr, "%s: %s - %s\n",
560710156SZhang.Yi@Sun.COM 			    cmdName,
560810156SZhang.Yi@Sun.COM 			    gettext("invalid option argument"),
560910156SZhang.Yi@Sun.COM 			    optarg);
561010156SZhang.Yi@Sun.COM 			if (nameValueString) {
561110156SZhang.Yi@Sun.COM 				free(nameValueString);
561210156SZhang.Yi@Sun.COM 				nameValueString = NULL;
561310156SZhang.Yi@Sun.COM 			}
561410156SZhang.Yi@Sun.COM 			return (1);
561510156SZhang.Yi@Sun.COM 		}
561610156SZhang.Yi@Sun.COM 		if (uintValue > 3600) {
561710156SZhang.Yi@Sun.COM 			(void) fprintf(stderr, "%s: %s\n",
561810156SZhang.Yi@Sun.COM 			    cmdName,
561910156SZhang.Yi@Sun.COM gettext("value must be between 0 and 3600"));
562010156SZhang.Yi@Sun.COM 			if (nameValueString) {
562110156SZhang.Yi@Sun.COM 				free(nameValueString);
562210156SZhang.Yi@Sun.COM 				nameValueString = NULL;
562310156SZhang.Yi@Sun.COM 			}
562410156SZhang.Yi@Sun.COM 			return (1);
562510156SZhang.Yi@Sun.COM 		}
562610156SZhang.Yi@Sun.COM 
562710156SZhang.Yi@Sun.COM 		if (chkConnLoginMaxPollingLoginDelay(oid, key, uintValue) > 0) {
562810156SZhang.Yi@Sun.COM 			if (nameValueString) {
562910156SZhang.Yi@Sun.COM 				free(nameValueString);
563010156SZhang.Yi@Sun.COM 				nameValueString = NULL;
563110156SZhang.Yi@Sun.COM 			}
563210156SZhang.Yi@Sun.COM 			return (1);
563310156SZhang.Yi@Sun.COM 		}
563410156SZhang.Yi@Sun.COM 
563510156SZhang.Yi@Sun.COM 		if (key == RECV_LOGIN_RSP_TIMEOUT) {
563610156SZhang.Yi@Sun.COM 			tunableObj.tunable_objectType =
563710156SZhang.Yi@Sun.COM 			    ISCSI_RX_TIMEOUT_VALUE;
563810156SZhang.Yi@Sun.COM 		} else if (key == CONN_LOGIN_MAX) {
563910156SZhang.Yi@Sun.COM 			tunableObj.tunable_objectType =
564010156SZhang.Yi@Sun.COM 			    ISCSI_CONN_DEFAULT_LOGIN_MAX;
564110156SZhang.Yi@Sun.COM 		} else if (key == POLLING_LOGIN_DELAY) {
564210156SZhang.Yi@Sun.COM 			tunableObj.tunable_objectType =
564310156SZhang.Yi@Sun.COM 			    ISCSI_LOGIN_POLLING_DELAY;
564410156SZhang.Yi@Sun.COM 		}
564510156SZhang.Yi@Sun.COM 		tunableObj.tunable_objectValue = valp;
564610156SZhang.Yi@Sun.COM 		status = SUN_IMA_SetTunableProperties(oid, &tunableObj);
564710156SZhang.Yi@Sun.COM 		break;
564810156SZhang.Yi@Sun.COM 	default:
564910156SZhang.Yi@Sun.COM 		(void) fprintf(stderr, "%s: %s: %s\n", cmdName,
565010156SZhang.Yi@Sun.COM 		    gettext("Unsupported key"), keyp);
565110156SZhang.Yi@Sun.COM 		if (nameValueString) {
565210156SZhang.Yi@Sun.COM 			free(nameValueString);
565310156SZhang.Yi@Sun.COM 			nameValueString = NULL;
565410156SZhang.Yi@Sun.COM 		}
565510156SZhang.Yi@Sun.COM 		return (1);
565610156SZhang.Yi@Sun.COM 	}
565710156SZhang.Yi@Sun.COM 	if (!IMA_SUCCESS(status)) {
565810156SZhang.Yi@Sun.COM 		printLibError(status);
565910156SZhang.Yi@Sun.COM 		if (nameValueString) {
566010156SZhang.Yi@Sun.COM 			free(nameValueString);
566110156SZhang.Yi@Sun.COM 			nameValueString = NULL;
566210156SZhang.Yi@Sun.COM 		}
566310156SZhang.Yi@Sun.COM 		return (1);
566410156SZhang.Yi@Sun.COM 	}
566510156SZhang.Yi@Sun.COM 
566610156SZhang.Yi@Sun.COM 	if (nameValueString) {
566710156SZhang.Yi@Sun.COM 		free(nameValueString);
566810156SZhang.Yi@Sun.COM 		nameValueString = NULL;
566910156SZhang.Yi@Sun.COM 	}
567010156SZhang.Yi@Sun.COM 	return (0);
567110156SZhang.Yi@Sun.COM }
567210156SZhang.Yi@Sun.COM 
567310156SZhang.Yi@Sun.COM /*
567410156SZhang.Yi@Sun.COM  * Print tunable parameters information
567510156SZhang.Yi@Sun.COM  */
567610156SZhang.Yi@Sun.COM static int
printTunableParameters(IMA_OID oid)567710156SZhang.Yi@Sun.COM printTunableParameters(IMA_OID oid)
567810156SZhang.Yi@Sun.COM {
567910156SZhang.Yi@Sun.COM 	ISCSI_TUNABLE_PARAM tunableObj;
568010156SZhang.Yi@Sun.COM 	char value[MAXOPTARGLEN] = "\0";
568110156SZhang.Yi@Sun.COM 	IMA_STATUS status;
568210156SZhang.Yi@Sun.COM 
568310156SZhang.Yi@Sun.COM 	tunableObj.tunable_objectValue = value;
568410156SZhang.Yi@Sun.COM 	(void) fprintf(stdout, "\t%s:\n",
568510156SZhang.Yi@Sun.COM 	    gettext("Tunable Parameters (Default/Configured)"));
568610156SZhang.Yi@Sun.COM 	tunableObj.tunable_objectType = ISCSI_RX_TIMEOUT_VALUE;
568710156SZhang.Yi@Sun.COM 	status = SUN_IMA_GetTunableProperties(oid, &tunableObj);
568810156SZhang.Yi@Sun.COM 	if (!IMA_SUCCESS(status)) {
568910156SZhang.Yi@Sun.COM 		printLibError(status);
569010156SZhang.Yi@Sun.COM 		return (1);
569110156SZhang.Yi@Sun.COM 	}
569210156SZhang.Yi@Sun.COM 	if (value[0] == '\0') {
569310156SZhang.Yi@Sun.COM 		value[0] = '-';
569410156SZhang.Yi@Sun.COM 		value[1] = '\0';
569510156SZhang.Yi@Sun.COM 	}
569610156SZhang.Yi@Sun.COM 	(void) fprintf(stdout, "\t\t%s: ",
569710156SZhang.Yi@Sun.COM 	    gettext("Session Login Response Time"));
569810156SZhang.Yi@Sun.COM 	(void) fprintf(stdout, "%s/%s\n", ISCSI_DEFAULT_RX_TIMEOUT_VALUE,
569910156SZhang.Yi@Sun.COM 	    tunableObj.tunable_objectValue);
570010156SZhang.Yi@Sun.COM 
570110156SZhang.Yi@Sun.COM 	value[0] = '\0';
570210156SZhang.Yi@Sun.COM 	tunableObj.tunable_objectType = ISCSI_CONN_DEFAULT_LOGIN_MAX;
570310156SZhang.Yi@Sun.COM 	status = SUN_IMA_GetTunableProperties(oid, &tunableObj);
570410156SZhang.Yi@Sun.COM 	if (!IMA_SUCCESS(status)) {
570510156SZhang.Yi@Sun.COM 		printLibError(status);
570610156SZhang.Yi@Sun.COM 		return (1);
570710156SZhang.Yi@Sun.COM 	}
570810156SZhang.Yi@Sun.COM 	if (value[0] == '\0') {
570910156SZhang.Yi@Sun.COM 		value[0] = '-';
571010156SZhang.Yi@Sun.COM 		value[1] = '\0';
571110156SZhang.Yi@Sun.COM 	}
571210156SZhang.Yi@Sun.COM 	(void) fprintf(stdout, "\t\t%s: ",
571310156SZhang.Yi@Sun.COM 	    gettext("Maximum Connection Retry Time"));
571410156SZhang.Yi@Sun.COM 	(void) fprintf(stdout, "%s/%s\n", ISCSI_DEFAULT_CONN_DEFAULT_LOGIN_MAX,
571510156SZhang.Yi@Sun.COM 	    tunableObj.tunable_objectValue);
571610156SZhang.Yi@Sun.COM 
571710156SZhang.Yi@Sun.COM 	value[0] = '\0';
571810156SZhang.Yi@Sun.COM 	tunableObj.tunable_objectType = ISCSI_LOGIN_POLLING_DELAY;
571910156SZhang.Yi@Sun.COM 	status = SUN_IMA_GetTunableProperties(oid, &tunableObj);
572010156SZhang.Yi@Sun.COM 	if (!IMA_SUCCESS(status)) {
572110156SZhang.Yi@Sun.COM 		printLibError(status);
572210156SZhang.Yi@Sun.COM 		return (1);
572310156SZhang.Yi@Sun.COM 	}
572410156SZhang.Yi@Sun.COM 	if (value[0] == '\0') {
572510156SZhang.Yi@Sun.COM 		value[0] = '-';
572610156SZhang.Yi@Sun.COM 		value[1] = '\0';
572710156SZhang.Yi@Sun.COM 	}
572810156SZhang.Yi@Sun.COM 	(void) fprintf(stdout, "\t\t%s: ",
572910156SZhang.Yi@Sun.COM 	    gettext("Login Retry Time Interval"));
573010156SZhang.Yi@Sun.COM 	(void) fprintf(stdout, "%s/%s\n", ISCSI_DEFAULT_LOGIN_POLLING_DELAY,
573110156SZhang.Yi@Sun.COM 	    tunableObj.tunable_objectValue);
573210156SZhang.Yi@Sun.COM 	return (0);
573310156SZhang.Yi@Sun.COM }
573410156SZhang.Yi@Sun.COM 
573510156SZhang.Yi@Sun.COM /*
573610156SZhang.Yi@Sun.COM  * This is helper function to check conn_login_max and polling_login_delay.
573710156SZhang.Yi@Sun.COM  */
573810156SZhang.Yi@Sun.COM static int
chkConnLoginMaxPollingLoginDelay(IMA_OID oid,int key,int uintValue)573910156SZhang.Yi@Sun.COM chkConnLoginMaxPollingLoginDelay(IMA_OID oid, int key, int uintValue)
574010156SZhang.Yi@Sun.COM {
574110156SZhang.Yi@Sun.COM 	char valuep[MAXOPTARGLEN];
574210156SZhang.Yi@Sun.COM 	IMA_STATUS	status;
574310156SZhang.Yi@Sun.COM 	IMA_UINT	getValue;
574410156SZhang.Yi@Sun.COM 	ISCSI_TUNABLE_PARAM	getObj;
574510156SZhang.Yi@Sun.COM 	char *endptr;
574610156SZhang.Yi@Sun.COM 
574710156SZhang.Yi@Sun.COM 	if (key == CONN_LOGIN_MAX) {
574810156SZhang.Yi@Sun.COM 		getObj.tunable_objectType = ISCSI_LOGIN_POLLING_DELAY;
574912052SZhang.Yi@Sun.COM 	} else if (key == POLLING_LOGIN_DELAY) {
575012052SZhang.Yi@Sun.COM 		getObj.tunable_objectType = ISCSI_CONN_DEFAULT_LOGIN_MAX;
575110156SZhang.Yi@Sun.COM 	} else {
575212052SZhang.Yi@Sun.COM 		return (0);
575310156SZhang.Yi@Sun.COM 	}
575410156SZhang.Yi@Sun.COM 	valuep[0] = '\0';
575510156SZhang.Yi@Sun.COM 	getObj.tunable_objectValue = valuep;
575610156SZhang.Yi@Sun.COM 	status = SUN_IMA_GetTunableProperties(oid, &getObj);
575710156SZhang.Yi@Sun.COM 	if (!IMA_SUCCESS(status)) {
575810156SZhang.Yi@Sun.COM 		printLibError(status);
575910156SZhang.Yi@Sun.COM 		return (1);
576010156SZhang.Yi@Sun.COM 	}
576110156SZhang.Yi@Sun.COM 	if (valuep[0] == '\0') {
576210156SZhang.Yi@Sun.COM 		if (key == CONN_LOGIN_MAX) {
576310156SZhang.Yi@Sun.COM 			(void) strlcpy(valuep,
576410156SZhang.Yi@Sun.COM 			    ISCSI_DEFAULT_LOGIN_POLLING_DELAY,
576510156SZhang.Yi@Sun.COM 			    strlen(ISCSI_DEFAULT_LOGIN_POLLING_DELAY) +1);
576610156SZhang.Yi@Sun.COM 		} else {
576710156SZhang.Yi@Sun.COM 			(void) strlcpy(valuep,
576810156SZhang.Yi@Sun.COM 			    ISCSI_DEFAULT_CONN_DEFAULT_LOGIN_MAX,
576910156SZhang.Yi@Sun.COM 			    strlen(ISCSI_DEFAULT_CONN_DEFAULT_LOGIN_MAX) +1);
577010156SZhang.Yi@Sun.COM 		}
577110156SZhang.Yi@Sun.COM 	}
577210156SZhang.Yi@Sun.COM 
577310156SZhang.Yi@Sun.COM 	errno = 0;
577410156SZhang.Yi@Sun.COM 	getValue = strtoul(valuep, &endptr, 0);
577510156SZhang.Yi@Sun.COM 	if (*endptr != '\0' || errno != 0) {
577610156SZhang.Yi@Sun.COM 		(void) fprintf(stderr, "%s: %s - %s\n",
577710156SZhang.Yi@Sun.COM 		    cmdName,
577810156SZhang.Yi@Sun.COM 		    gettext("cannot convert tunable string"),
577910156SZhang.Yi@Sun.COM 		    valuep);
578010156SZhang.Yi@Sun.COM 		return (1);
578110156SZhang.Yi@Sun.COM 	}
578210156SZhang.Yi@Sun.COM 	if (key == CONN_LOGIN_MAX) {
578310156SZhang.Yi@Sun.COM 		if (uintValue < getValue) {
578410156SZhang.Yi@Sun.COM 			(void) fprintf(stderr, "%s: %s %ld\n",
578510156SZhang.Yi@Sun.COM 			    cmdName, gettext("value must larger than"),
578610156SZhang.Yi@Sun.COM 			    getValue);
578710156SZhang.Yi@Sun.COM 			return (1);
578810156SZhang.Yi@Sun.COM 		}
578910156SZhang.Yi@Sun.COM 	} else {
579010156SZhang.Yi@Sun.COM 		if (uintValue > getValue) {
579110156SZhang.Yi@Sun.COM 			(void) fprintf(stderr, "%s: %s %ld\n",
579210156SZhang.Yi@Sun.COM 			    cmdName, gettext("value must smaller than"),
579310156SZhang.Yi@Sun.COM 			    getValue);
579410156SZhang.Yi@Sun.COM 			return (1);
579510156SZhang.Yi@Sun.COM 		}
579610156SZhang.Yi@Sun.COM 	}
579710156SZhang.Yi@Sun.COM 	return (0);
579810156SZhang.Yi@Sun.COM }
5799