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