예제 #1
0
파일: main.c 프로젝트: CoryXie/opensolaris
/*ARGSUSED*/
static int
deleteInitiator(int operandLen, char *operand[], cmdOptions_t *options)
{
	char		*first_str	= NULL;
	tgt_node_t	*node;
	cmdOptions_t	*optionList = options;

	if (operand == NULL)
		return (1);
	if (options == NULL)
		return (1);

	tgt_buf_add_tag(&first_str, "delete", Tag_Start);
	tgt_buf_add_tag(&first_str, XML_ELEMENT_INIT, Tag_Start);
	tgt_buf_add(&first_str, XML_ELEMENT_NAME, operand[0]);

	switch (optionList->optval) {
	case 'A': /* all */
		tgt_buf_add(&first_str, XML_ELEMENT_ALL, optionList->optarg);
		break;
	default:
		(void) fprintf(stderr, "%s: %c: %s\n",
		    cmdName, optionList->optval,
		    gettext("unknown option"));
		free(first_str);
		return (1);
	}

	tgt_buf_add_tag(&first_str, XML_ELEMENT_INIT, Tag_End);
	tgt_buf_add_tag(&first_str, "delete", Tag_End);

	node = tgt_door_call(first_str, 0);
	free(first_str);
	return (formatErrString(node));
}
예제 #2
0
파일: main.c 프로젝트: CoryXie/opensolaris
/*ARGSUSED*/
static int
modifyTarget(int operandLen, char *operand[], cmdOptions_t *options)
{
	char		*first_str	= NULL;
	tgt_node_t	*node;
	cmdOptions_t	*optionList	= options;

	if (operand == NULL)
		return (1);

	tgt_buf_add_tag(&first_str, "modify", Tag_Start);
	tgt_buf_add_tag(&first_str, XML_ELEMENT_TARG, Tag_Start);
	tgt_buf_add(&first_str, XML_ELEMENT_NAME, operand[0]);

	for (; optionList->optval; optionList++) {
		switch (optionList->optval) {
			case 'p': /* tpgt number */
				tgt_buf_add(&first_str, XML_ELEMENT_TPGT,
				    optionList->optarg);
				break;
			case 'l': /* acl */
				tgt_buf_add(&first_str, XML_ELEMENT_ACL,
				    optionList->optarg);
				break;
			case 'a': /* alias */
				tgt_buf_add(&first_str, XML_ELEMENT_ALIAS,
				    optionList->optarg);
				break;
			case 'm': /* max recv */
				tgt_buf_add(&first_str, XML_ELEMENT_MAXRECV,
				    optionList->optarg);
				break;
			case 'z': /* grow lun size */
				tgt_buf_add(&first_str, XML_ELEMENT_SIZE,
				    optionList->optarg);
				break;
			case 'u':
				tgt_buf_add(&first_str, XML_ELEMENT_LUN,
				    optionList->optarg);
				break;
			default:
				(void) fprintf(stderr, "%s: %c: %s\n",
				    cmdName, optionList->optval,
				    gettext("unknown option"));
				free(first_str);
				return (1);
		}
	}

	tgt_buf_add_tag(&first_str, XML_ELEMENT_TARG, Tag_End);
	tgt_buf_add_tag(&first_str, "modify", Tag_End);

	node = tgt_door_call(first_str, 0);
	free(first_str);
	return (formatErrString(node));
}
예제 #3
0
파일: main.c 프로젝트: CoryXie/opensolaris
/*ARGSUSED*/
static int
deleteTpgt(int operandLen, char *operand[], cmdOptions_t *options)
{
	char		*first_str	= NULL;
	tgt_node_t	*node;
	cmdOptions_t	*optionList = options;
	boolean_t	isIpv6 = B_FALSE;
	uint16_t	port;
	char		IpAddress[MAX_IPADDRESS_LEN];

	if (operand == NULL)
		return (1);
	if (options == NULL)
		return (1);

	tgt_buf_add_tag(&first_str, "delete", Tag_Start);
	tgt_buf_add_tag(&first_str, XML_ELEMENT_TPGT, Tag_Start);
	tgt_buf_add(&first_str, XML_ELEMENT_NAME, operand[0]);

	switch (optionList->optval) {
	case 'A': /* all */
		tgt_buf_add(&first_str, XML_ELEMENT_ALL, optionList->optarg);
		break;
	case 'i': /* ip address */
		if (parseAddress(optionList->optarg, 0,
		    IpAddress, 256, &port, &isIpv6) !=
		    PARSE_ADDR_OK) {
			return (1);
		}
		tgt_buf_add(&first_str, XML_ELEMENT_IPADDR, IpAddress);
		break;
	default:
		(void) fprintf(stderr, "%s: %c: %s\n",
		    cmdName, optionList->optval,
		    gettext("unknown option"));
		free(first_str);
		return (1);
	}

	tgt_buf_add_tag(&first_str, XML_ELEMENT_TPGT, Tag_End);
	tgt_buf_add_tag(&first_str, "delete", Tag_End);

	node = tgt_door_call(first_str, 0);
	free(first_str);
	return (formatErrString(node));
}
예제 #4
0
파일: xml.c 프로젝트: imp/slist
/*
 * tgt_dump2buf -- dumps node tree to buffer, allocating memory as it goes
 *
 * It is up to the caller, when finished with 'buf', to call free()
 */
void
tgt_dump2buf(tgt_node_t *n, char **buf)
{
	tgt_node_t	*c;

	if (n == NULL)
		return;
	if (strcmp(n->x_name, XML_COMMENT_STR) == 0) {
		buf_add_comment(buf, n->x_value);
		return;
	}
	buf_add_node_attr(buf, n);
	if (n->x_value != NULL)
		tgt_buf_add_tag(buf, n->x_value, Tag_String);
	for (c = n->x_child; c; c = c->x_sibling)
		tgt_dump2buf(c, buf);
	tgt_buf_add_tag(buf, n->x_name, Tag_End);
}
예제 #5
0
파일: xml.c 프로젝트: imp/slist
void
tgt_buf_add(char **b, char *element, const char *cdata)
{
	char	entity[MAX_REPLACEMENT_ENTITY];
	char	buf[MAX_REPLACEMENT_BUFFER];
	int	len, i;

	bzero(buf, sizeof (buf));

	tgt_buf_add_tag(b, element, Tag_Start);
	/*
	 * we have to transform the predefined xml entities;
	 */
	if (cdata != NULL) {
		len = strlen(cdata);
		for (i = 0; i < len; i++) {
			switch (cdata[i]) {
			case '&':
				(void) strcpy(entity, "&amp;");
				break;
			case '<':
				(void) strcpy(entity, "&lt;");
				break;
			case '>':
				(void) strcpy(entity, "&gt;");
				break;
			case '\'':
				(void) strcpy(entity, "&apos;");
				break;
			case '"':
				(void) strcpy(entity, "&quot;");
				break;
			default:
				entity[0] = cdata[i];
				entity[1] = '\0';
				break;
			}
			(void) strlcat(buf, entity, sizeof (buf));
		}
		tgt_buf_add_tag(b, buf, Tag_String);
	}
	tgt_buf_add_tag(b, element, Tag_End);
}
예제 #6
0
파일: main.c 프로젝트: CoryXie/opensolaris
/*ARGSUSED*/
static int
createTpgt(int operandLen, char *operand[], cmdOptions_t *options)
{
	char		*first_str	= NULL;
	tgt_node_t	*node;

	if (operand == NULL)
		return (1);

	tgt_buf_add_tag(&first_str, "create", Tag_Start);
	tgt_buf_add_tag(&first_str, XML_ELEMENT_TPGT, Tag_Start);
	tgt_buf_add(&first_str, XML_ELEMENT_NAME, operand[0]);
	tgt_buf_add_tag(&first_str, XML_ELEMENT_TPGT, Tag_End);
	tgt_buf_add_tag(&first_str, "create", Tag_End);

	node = tgt_door_call(first_str, 0);
	free(first_str);
	return (formatErrString(node));
}
예제 #7
0
파일: main.c 프로젝트: CoryXie/opensolaris
/*ARGSUSED*/
static int
modifyAdmin(int operandLen, char *operand[], cmdOptions_t *options)
{
	char		*first_str	= NULL;
	tgt_node_t	*node;
	cmdOptions_t	*optionList	= options;
	char		chapSecret[MAX_CHAP_SECRET_LEN+1];
	char		olddir[MAXPATHLEN];
	char		newdir[MAXPATHLEN];
	int		secretLen	= 0;
	int		ret		= 0;

	if (operand == NULL)
		return (1);
	if (options == NULL)
		return (1);

	tgt_buf_add_tag(&first_str, "modify", Tag_Start);
	tgt_buf_add_tag(&first_str, XML_ELEMENT_ADMIN, Tag_Start);
	tgt_buf_add(&first_str, XML_ELEMENT_NAME, operand[0]);

	for (; optionList->optval; optionList++) {
		switch (optionList->optval) {
			case 'd': /* base directory */
				(void) getcwd(olddir, sizeof (olddir));

				/*
				 * Attempt to create the new base directory.
				 * This may fail for one of two reasons.
				 * (a) The path given is invalid or (b) it
				 * already exists. If (a) is true then then
				 * following chdir() will fail and the user
				 * notified. If (b) is true, then chdir() will
				 * succeed.
				 */
				(void) mkdir(optionList->optarg, 0700);

				if (chdir(optionList->optarg) == -1) {
					(void) fprintf(stderr, "%s: %s\n",
					    cmdName, gettext("Invalid path"));
					free(first_str);
					return (1);
				}
				(void) getcwd(newdir, sizeof (newdir));
				tgt_buf_add(&first_str, XML_ELEMENT_BASEDIR,
				    newdir);
				(void) chdir(olddir);
				break;
			case 'H': /* chap name */
				if (strlen(optionList->optarg) != 0) {
					tgt_buf_add(&first_str,
					    XML_ELEMENT_CHAPNAME,
					    optionList->optarg);
				} else {
					tgt_buf_add(&first_str,
					    XML_ELEMENT_DELETE_CHAPNAME,
					    OPT_TRUE);
				}
				break;
			case 'C': /* chap secert */
				ret = getSecret((char *)&chapSecret[0],
				    &secretLen,
				    MIN_CHAP_SECRET_LEN,
				    MAX_CHAP_SECRET_LEN);
				if (ret != 0) {
					(void) fprintf(stderr, "%s: %s\n",
					    cmdName,
					    gettext("Cannot read CHAP secret"));
					free(first_str);
					return (ret);
				}
				chapSecret[secretLen] = '\0';
				if (secretLen != 0) {
					tgt_buf_add(&first_str,
					    XML_ELEMENT_CHAPSECRET,
					    chapSecret);
				} else {
					tgt_buf_add(&first_str,
					    XML_ELEMENT_DELETE_CHAPSECRET,
					    OPT_TRUE);
				}
				break;
			case 'R': /* radius access */
				if (strcmp(optionList->optarg,
				    OPT_ENABLE) == 0) {
					tgt_buf_add(&first_str,
					    XML_ELEMENT_RAD_ACCESS, OPT_TRUE);
				} else
					if (strcmp(optionList->optarg,
					    OPT_DISABLE) == 0) {
					tgt_buf_add(&first_str,
					    XML_ELEMENT_RAD_ACCESS, OPT_FALSE);
				} else {
					(void) fprintf(stderr, "%s: %s\n",
					    cmdName,
					    gettext("Option value should be"
					    "enable/disable"));
					free(first_str);
					return (1);
				}
				break;
			case 'r': /* radius server */
				if (strlen(optionList->optarg) != 0) {
					tgt_buf_add(&first_str,
					    XML_ELEMENT_RAD_SERV,
					    optionList->optarg);
				} else {
					tgt_buf_add(&first_str,
					    XML_ELEMENT_DELETE_RAD_SERV,
					    OPT_TRUE);
				}
				break;
			case 'P': /* radius secret */
				ret = getSecret((char *)&chapSecret[0],
				    &secretLen, MIN_CHAP_SECRET_LEN,
				    MAX_CHAP_SECRET_LEN);
				if (ret != 0) {
					(void) fprintf(stderr, "%s: %s\n",
					    cmdName,
					    gettext("Cannot read RADIUS "
					    "secret"));
					free(first_str);
					return (ret);
				}
				chapSecret[secretLen] = '\0';
				if (secretLen != 0) {
					tgt_buf_add(&first_str,
					    XML_ELEMENT_RAD_SECRET,
					    chapSecret);
				} else {
					tgt_buf_add(&first_str,
					    XML_ELEMENT_DELETE_RAD_SECRET,
					    OPT_TRUE);
				}
				break;
			case 'S': /* iSNS access */
				if (strcmp(optionList->optarg,
				    OPT_ENABLE) == 0) {
					tgt_buf_add(&first_str,
					    XML_ELEMENT_ISNS_ACCESS, OPT_TRUE);
				} else
					if (strcmp(optionList->optarg,
					    OPT_DISABLE) == 0) {
					tgt_buf_add(&first_str,
					    XML_ELEMENT_ISNS_ACCESS, OPT_FALSE);
				} else {
					(void) fprintf(stderr, "%s: %s\n",
					    cmdName,
					    gettext("Option value should be"
					    "enable/disable"));
					free(first_str);
					return (1);
				}
				break;
			case 's': /* iSNS server */
				if (strlen(optionList->optarg) >
				    MAXHOSTNAMELEN) {
					(void) fprintf(stderr, "%s: %s\n",
					    cmdName,
					    gettext("option too long"));
					return (1);
				}
				tgt_buf_add(&first_str, XML_ELEMENT_ISNS_SERV,
				    optionList->optarg);
				break;
			case 'f': /* fast write back */
				if (strcmp(optionList->optarg,
				    OPT_ENABLE) == 0) {
					tgt_buf_add(&first_str,
					    XML_ELEMENT_FAST, OPT_TRUE);
				} else
					if (strcmp(optionList->optarg,
					    OPT_DISABLE) == 0) {
					tgt_buf_add(&first_str,
					    XML_ELEMENT_FAST, OPT_FALSE);
				} else {
					(void) fprintf(stderr, "%s: %s\n",
					    cmdName,
					    gettext("Option value should be"
					    "enable/disable"));
					free(first_str);
					return (1);
				}
				break;
			default:
				(void) fprintf(stderr, "%s: %c: %s\n",
				    cmdName, optionList->optval,
				    gettext("unknown option"));
				free(first_str);
				return (1);
		}
	}

	tgt_buf_add_tag(&first_str, XML_ELEMENT_ADMIN, Tag_End);
	tgt_buf_add_tag(&first_str, "modify", Tag_End);

	node = tgt_door_call(first_str, 0);
	free(first_str);
	return (formatErrString(node));
}
예제 #8
0
파일: main.c 프로젝트: CoryXie/opensolaris
/*ARGSUSED*/
static int
modifyInitiator(int operandLen, char *operand[], cmdOptions_t *options)
{
	char		*first_str	= NULL;
	tgt_node_t	*node;
	cmdOptions_t	*optionList	= options;
	char		chapSecret[MAX_CHAP_SECRET_LEN+1];
	int		secretLen	= 0;
	int		ret		= 0;

	if (operand == NULL)
		return (1);
	if (options == NULL)
		return (1);

	tgt_buf_add_tag(&first_str, "modify", Tag_Start);
	tgt_buf_add_tag(&first_str, XML_ELEMENT_INIT, Tag_Start);
	tgt_buf_add(&first_str, XML_ELEMENT_NAME, operand[0]);

	for (; optionList->optval; optionList++) {
		switch (optionList->optval) {
		case 'H': /* chap-name */
			if (strlen(optionList->optarg) != 0) {
				tgt_buf_add(&first_str, XML_ELEMENT_CHAPNAME,
				    optionList->optarg);
			} else {
				tgt_buf_add(&first_str,
				    XML_ELEMENT_DELETE_CHAPNAME,
				    OPT_TRUE);
			}
			break;
		case 'C': /* chap-secret */
			ret = getSecret((char *)&chapSecret[0], &secretLen,
			    MIN_CHAP_SECRET_LEN, MAX_CHAP_SECRET_LEN);
			if (ret != 0) {
				(void) fprintf(stderr, "%s: %s\n", cmdName,
				    gettext("Cannot read CHAP secret"));
				return (ret);
			}
			chapSecret[secretLen] = '\0';
			if (secretLen != 0) {
				tgt_buf_add(&first_str, XML_ELEMENT_CHAPSECRET,
				    chapSecret);
			} else {
				tgt_buf_add(&first_str,
				    XML_ELEMENT_DELETE_CHAPSECRET,
				    OPT_TRUE);
			}
			break;
		default:
			(void) fprintf(stderr, "%s: %c: %s\n",
			    cmdName, optionList->optval,
			    gettext("unknown option"));
			free(first_str);
			return (1);
		}
	}
	tgt_buf_add_tag(&first_str, XML_ELEMENT_INIT, Tag_End);
	tgt_buf_add_tag(&first_str, "modify", Tag_End);

	node = tgt_door_call(first_str, 0);
	free(first_str);
	return (formatErrString(node));
}
예제 #9
0
파일: main.c 프로젝트: CoryXie/opensolaris
/*ARGSUSED*/
static int
createTarget(int operandLen, char *operand[], cmdOptions_t *options)
{
	char		*first_str	= NULL;
	tgt_node_t	*node;
	cmdOptions_t	*optionList = options;

	if (operand == NULL)
		return (1);

	tgt_buf_add_tag(&first_str, "create", Tag_Start);
	tgt_buf_add_tag(&first_str, XML_ELEMENT_TARG, Tag_Start);
	tgt_buf_add(&first_str, XML_ELEMENT_NAME, operand[0]);

	for (; optionList->optval; optionList++) {
		switch (optionList->optval) {
			case 't': /* type */
				if ((strcmp(optionList->optarg, "disk")) &&
				    (strcmp(optionList->optarg, "tape")) &&
				    (strcmp(optionList->optarg, "raw")) &&
				    (strcmp(optionList->optarg, "osd"))) {
					(void) fprintf(stderr, "%s: %c: %s\n",
					    cmdName, optionList->optval,
					    gettext("unknown type"));
					free(first_str);
					return (1);
				} else {
					tgt_buf_add(&first_str,
					    XML_ELEMENT_TYPE,
					    optionList->optarg);
				}
				break;
			case 'z': /* size */
				tgt_buf_add(&first_str, XML_ELEMENT_SIZE,
				    optionList->optarg);
				break;
			case 'u': /* lun number */
				tgt_buf_add(&first_str, XML_ELEMENT_LUN,
				    optionList->optarg);
				break;
			case 'a': /* alias */
				tgt_buf_add(&first_str, XML_ELEMENT_ALIAS,
				    optionList->optarg);
				break;
			case 'b': /* backing store */
				tgt_buf_add(&first_str, XML_ELEMENT_BACK,
				    optionList->optarg);
				break;
			default:
				(void) fprintf(stderr, "%s: %c: %s\n",
				    cmdName, optionList->optval,
				    gettext("unknown option"));
				free(first_str);
				return (1);
		}
	}

	tgt_buf_add_tag(&first_str, XML_ELEMENT_TARG, Tag_End);
	tgt_buf_add_tag(&first_str, "create", Tag_End);

	node = tgt_door_call(first_str, 0);
	free(first_str);
	return (formatErrString(node));
}
예제 #10
0
파일: main.c 프로젝트: CoryXie/opensolaris
static int
showStats(int operandLen, char *operand[], cmdOptions_t *options)
{
	char		*first_str	= NULL;
	char		scale_buf[16];
	tgt_node_t	*node, *n1;
	int		interval	= -1;
	int		count		= -1;
	int		header;
	stat_delta_t	cur_data, *pd;

	tgt_buf_add_tag(&first_str, "list", Tag_Start);
	tgt_buf_add_tag(&first_str, XML_ELEMENT_TARG, Tag_Start);

	tgt_buf_add(&first_str, XML_ELEMENT_IOSTAT, OPT_TRUE);
	if (operandLen)
		tgt_buf_add(&first_str, XML_ELEMENT_NAME, operand[0]);

	for (; options->optval; options++) {
		switch (options->optval) {
		case 0:
			break;
		case 'I': /* optarg = refresh interval */
			interval = atoi(options->optarg);
			if (interval == 0) {
				(void) fprintf(stderr, "%s: %s\n", cmdName,
				    gettext("interval must be non-zero"));
				free(first_str);
				return (1);
			}
			break;
		case 'N':
			count = atoi(options->optarg);
			if (count == 0) {
				(void) fprintf(stderr, "%s: %s\n", cmdName,
				    gettext("count must be non-zero"));
				free(first_str);
				return (1);
			}
			break;
		default:
			(void) fprintf(stderr, "%s: %c: %s\n", cmdName,
			    options->optval, gettext("unknown option"));
			free(first_str);
			return (1);
		}
	}

	tgt_buf_add_tag(&first_str, XML_ELEMENT_TARG, Tag_End);
	tgt_buf_add_tag(&first_str, "list", Tag_End);

	header = 1;
	/*CONSTANTCONDITION*/
	while (1) {
		if (--header == 0) {
			(void) printf("%20s  %12s  %12s\n", " ",
			    gettext("operations"), gettext("bandwidth "));
			(void) printf("%-20s  %5s  %5s  %5s  %5s\n",
			    gettext("device"), gettext("read"),
			    gettext("write"), gettext("read"),
			    gettext("write"));
			(void) printf("%-20s  %5s  %5s  %5s  %5s\n",
			    "--------------------", "-----", "-----",
			    "-----", "-----");
			header = 20;
		}
		if ((node = tgt_door_call(first_str, 0)) == NULL) {
			(void) fprintf(stderr, "%s: %s\n", cmdName,
			    gettext("No reponse from daemon"));
			return (1);
		}

		if (strcmp(node->x_name, XML_ELEMENT_RESULT)) {
			(void) fprintf(stderr, "%s: %s\n", cmdName,
			    gettext("Bad XML response"));
			free(first_str);
			tgt_node_free(node);
			stats_free();
			return (1);
		}

		n1 = NULL;
		while (n1 = tgt_node_next_child(node, XML_ELEMENT_TARG, n1)) {
			stats_load_counts(n1, &cur_data);
			if ((pd = stats_prev_counts(&cur_data)) == NULL) {
				free(first_str);
				tgt_node_free(node);
				return (1);
			}
			(void) printf("%-20s  ", pd->device);
			(void) printf("%5s  ",
			    number_to_scaled_string(scale_buf,
			    cur_data.read_cmds - pd->read_cmds, 1, 1024));
			(void) printf("%5s  ",
			    number_to_scaled_string(scale_buf,
			    cur_data.write_cmds - pd->write_cmds, 1, 1024));
			(void) printf("%5s  ",
			    number_to_scaled_string(scale_buf,
			    cur_data.read_blks - pd->read_blks, 512, 1024));
			(void) printf("%5s\n",
			    number_to_scaled_string(scale_buf,
			    cur_data.write_blks - pd->write_blks, 512, 1024));
			stats_update_counts(pd, &cur_data);
		}
		tgt_node_free(node);

		if (count == -1) {
			if (interval == -1)
				/* No count or internal, do it just once */
				break;
			else
				(void) sleep(interval);
		} else if (--count) {
			if (interval == -1)
				break;
			else
				(void) sleep(interval);
		} else
			break;
	}

	stats_free();
	free(first_str);
	return (0);
}
예제 #11
0
파일: main.c 프로젝트: CoryXie/opensolaris
/*ARGSUSED*/
static int
showAdmin(int operandLen, char *operand[], cmdOptions_t *options)
{
	char		*first_str	= NULL;
	tgt_node_t	*node		= NULL;
	tgt_node_t	*n1		= NULL; /* pointer to node (depth=1) */
	tgt_node_t	*n2		= NULL; /* pointer to node (depth=2) */

	if (operand == NULL)
		return (1);

	tgt_buf_add_tag(&first_str, "list", Tag_Start);
	tgt_buf_add_tag(&first_str, XML_ELEMENT_ADMIN, Tag_Start);
	tgt_buf_add_tag(&first_str, XML_ELEMENT_ADMIN, Tag_End);
	tgt_buf_add_tag(&first_str, "list", Tag_End);

	if ((node = tgt_door_call(first_str, 0)) == NULL) {
		(void) fprintf(stderr, "%s: %s\n", cmdName,
		    gettext("No reponse from daemon"));
		return (1);
	}
	free(first_str);

	if (strcmp(node->x_name, XML_ELEMENT_RESULT)) {
		(void) fprintf(stderr, "%s: %s\n", cmdName,
		    gettext("Bad XML response"));
		return (1);
	}

	(void) printf("%s:\n", cmdName);

	n1 = tgt_node_next_child(node, XML_ELEMENT_ADMIN, NULL);
	if (n1 == NULL) {
		(void) fprintf(stderr, "%s: %s\n", cmdName,
		    gettext("Bad XML response"));
		return (1);
	}

	n2 = tgt_node_next_child(n1, XML_ELEMENT_BASEDIR, NULL);
	(void) printf("%s%s: %s\n", dospace(1), gettext("Base Directory"),
	    n2 ? n2->x_value : gettext("Not set"));

	n2 = tgt_node_next_child(n1, XML_ELEMENT_CHAPNAME, NULL);
	(void) printf("%s%s: %s\n", dospace(1), gettext("CHAP Name"),
	    n2 ? n2->x_value : gettext("Not set"));

	n2 = tgt_node_next_child(n1, XML_ELEMENT_RAD_ACCESS, NULL);
	(void) printf("%s%s: ", dospace(1), gettext("RADIUS Access"));
	if (n2) {
		if (strcmp(n2->x_value, OPT_TRUE) == 0)
			(void) printf("%s\n", gettext("Enabled"));
		else
			(void) printf("%s\n", gettext("Disabled"));
	} else
		(void) printf("%s\n", gettext("Not set"));

	n2 = tgt_node_next_child(n1, XML_ELEMENT_RAD_SERV, NULL);
	(void) printf("%s%s: %s\n", dospace(1), gettext("RADIUS Server"),
	    n2 ? n2->x_value : gettext("Not set"));

	n2 = tgt_node_next_child(n1, XML_ELEMENT_ISNS_ACCESS, NULL);
	(void) printf("%s%s: ", dospace(1), gettext("iSNS Access"));
	if (n2) {
		if (strcmp(n2->x_value, OPT_TRUE) == 0)
			(void) printf("%s\n", gettext("Enabled"));
		else
			(void) printf("%s\n", gettext("Disabled"));
	} else
		(void) printf("%s\n", gettext("Not set"));

	n2 = tgt_node_next_child(n1, XML_ELEMENT_ISNS_SERV, NULL);
	(void) printf("%s%s: %s\n", dospace(1), gettext("iSNS Server"),
	    n2 ? n2->x_value : gettext("Not set"));

	n2 = tgt_node_next_child(n1, XML_ELEMENT_ISNS_SERVER_STATUS, NULL);
	if (n2) {
		/*
		 * if NULL, that means either the isns discovery is
		 * disabled or the server address is not set.
		 */
		if (n2->x_value != NULL) {
			(void) printf("%s%s: ", dospace(1),
			    gettext("iSNS Server Status"));
			(void) printf("%s\n", n2->x_value);
		}
	}

	n2 = tgt_node_next_child(n1, XML_ELEMENT_FAST, NULL);
	(void) printf("%s%s: ", dospace(1), gettext("Fast Write ACK"));
	if (n2) {
		if (strcmp(n2->x_value, OPT_TRUE) == 0)
			(void) printf("%s\n", gettext("Enabled"));
		else
			(void) printf("%s\n", gettext("Disabled"));
	} else
		(void) printf("%s\n", gettext("Not set"));

	return (0);
}
예제 #12
0
파일: main.c 프로젝트: CoryXie/opensolaris
static int
listTpgt(int operandLen, char *operand[], cmdOptions_t *options)
{
	char		*first_str	= NULL;
	tgt_node_t	*node		= NULL;
	tgt_node_t	*n1		= NULL; /* pointer to node (depth=1) */
	tgt_node_t	*n2		= NULL; /* pointer to node (depth=2) */
	cmdOptions_t	*optionList	= options;
	Boolean_t	verbose		= False;
	int		addrs;

	if (operand == NULL)
		return (1);

	tgt_buf_add_tag(&first_str, "list", Tag_Start);
	tgt_buf_add_tag(&first_str, XML_ELEMENT_TPGT, Tag_Start);

	if (operandLen)
		tgt_buf_add(&first_str, XML_ELEMENT_NAME, operand[0]);
	if (optionList) {
		switch (optionList->optval) {
		case 0: /* no options, treat as --verbose */
			break;
		case 'v':
			verbose = True;
			tgt_buf_add(&first_str,
			    XML_ELEMENT_VERBOSE, OPT_TRUE);
			break;
		default:
			(void) fprintf(stderr, "%s: %c: %s\n",
			    cmdName, optionList->optval,
			    gettext("unknown option"));
			free(first_str);
			return (1);
		}
	}

	tgt_buf_add_tag(&first_str, XML_ELEMENT_TPGT, Tag_End);
	tgt_buf_add_tag(&first_str, "list", Tag_End);

	if ((node = tgt_door_call(first_str, 0)) == NULL) {
		(void) fprintf(stderr, "%s: %s\n", cmdName,
		    gettext("No reponse from daemon"));
		return (1);
	}
	free(first_str);

	if (strcmp(node->x_name, XML_ELEMENT_RESULT)) {
		(void) fprintf(stderr, "%s: %s\n", cmdName,
		    gettext("Bad XML response"));
		return (1);
	}

	n1 = NULL;
	while (n1 = tgt_node_next_child(node, XML_ELEMENT_TPGT, n1)) {
		(void) printf("%s: %s\n", gettext("TPGT"), n1->x_value);
		n2 = NULL;
		addrs = 0;
		while (n2 = tgt_node_next(n1, XML_ELEMENT_IPADDR, n2)) {
			if (verbose == True)
				(void) printf("%s%s: %s\n", dospace(1),
				    gettext("IP Address"),
				    n2 ? n2->x_value : gettext("Not set"));
			addrs++;
		}

		if (verbose == False) {
			(void) printf("%s%s: %d\n", dospace(1),
			    gettext("IP Address count"), addrs);
		} else if (addrs == 0) {

			/*
			 * Verbose is true, but there where no addresses
			 * for this TPGT. To keep the output consistent
			 * dump a "Not set" string out.
			 */
			(void) printf("%s%s: %s\n", dospace(1),
			    gettext("IP Address"), gettext("Not set"));
		}
	}

	return (0);
}
예제 #13
0
파일: main.c 프로젝트: CoryXie/opensolaris
static int
listInitiator(int operandLen, char *operand[], cmdOptions_t *options)
{
	char		*first_str	= NULL;
	tgt_node_t	*node;
	tgt_node_t	*n1		= NULL; /* pointer to node (depth=1) */
	tgt_node_t	*n2		= NULL; /* pointer to node (depth=2) */
	Boolean_t	verbose		= False;
	cmdOptions_t	*optionList	= options;

	if (operand == NULL)
		return (1);

	tgt_buf_add_tag(&first_str, "list", Tag_Start);
	tgt_buf_add_tag(&first_str, XML_ELEMENT_INIT, Tag_Start);

	if (operandLen) {
		tgt_buf_add(&first_str, XML_ELEMENT_NAME, operand[0]);
	}
	if (optionList) {
		switch (optionList->optval) {
		case 0:
			break;
		case 'v':
			verbose = True;
			tgt_buf_add(&first_str,
			    XML_ELEMENT_VERBOSE, OPT_TRUE);
			break;

		default:
			(void) fprintf(stderr, "%s: %c: %s\n",
			    cmdName, optionList->optval,
			    gettext("unknown option"));
			free(first_str);
			return (1);
		}
	}

	tgt_buf_add_tag(&first_str, XML_ELEMENT_INIT, Tag_End);
	tgt_buf_add_tag(&first_str, "list", Tag_End);

	if ((node = tgt_door_call(first_str, 0)) == NULL) {
		(void) fprintf(stderr, "%s: %s\n", cmdName,
		    gettext("No reponse from daemon"));
		return (1);
	}
	free(first_str);

	if (strcmp(node->x_name, XML_ELEMENT_RESULT)) {
		(void) fprintf(stderr, "%s: %s\n", cmdName,
		    gettext("Bad XML response"));
		return (1);
	}

	n1 = NULL;
	while (n1 = tgt_node_next_child(node, XML_ELEMENT_INIT, n1)) {
		(void) printf("%s: %s\n", gettext("Initiator"), n1->x_value);

		n2 = tgt_node_next_child(n1, XML_ELEMENT_INAME, NULL);
		(void) printf("%s%s: %s\n", dospace(1), gettext("iSCSI Name"),
		    n2 ? n2->x_value : gettext("Not set"));

		n2 = tgt_node_next_child(n1, XML_ELEMENT_CHAPNAME, NULL);
		(void) printf("%s%s: %s\n", dospace(1), gettext("CHAP Name"),
		    n2 ? n2->x_value : gettext("Not set"));

		if (verbose == True) {
			n2 = tgt_node_next_child(n1, XML_ELEMENT_CHAPSECRET,
			    NULL);
			(void) printf("%s%s: %s\n", dospace(1),
			    gettext("CHAP Secret"),
			    n2 ? gettext("Set") : gettext("Not set"));
		}

	}

	return (0);
}
예제 #14
0
파일: main.c 프로젝트: CoryXie/opensolaris
static int
listTarget(int operandLen, char *operand[], cmdOptions_t *options)
{
	char		*first_str	= NULL;
	tgt_node_t	*node		= NULL;
	tgt_node_t	*n1		= NULL; /* pointer to node (depth=1) */
	tgt_node_t	*n2		= NULL; /* pointer to node (depth=2) */
	tgt_node_t	*n3		= NULL; /* pointer to node (depth=3) */
	tgt_node_t	*n4		= NULL; /* pointer to node (depth=4) */
	int		conns;
	char		buf[32];
	Boolean_t	verbose		= False;

	if (operand == NULL)
		return (1);

	tgt_buf_add_tag(&first_str, "list", Tag_Start);
	tgt_buf_add_tag(&first_str, XML_ELEMENT_TARG, Tag_Start);

	if (operandLen)
		tgt_buf_add(&first_str, XML_ELEMENT_NAME, operand[0]);

	/*
	 * Always retrieve the iostats which will give us the
	 * connection count information even if we're not doing
	 * a verbose output.
	 */
	tgt_buf_add(&first_str, XML_ELEMENT_IOSTAT, OPT_TRUE);

	if (options) {
		switch (options->optval) {
		case 0:
			break;
		case 'v':
			tgt_buf_add(&first_str, XML_ELEMENT_LUNINFO, OPT_TRUE);
			verbose = True;
			break;
		default:
			(void) fprintf(stderr, "%s: %c: %s\n", cmdName,
			    options->optval, gettext("unknown option"));
			free(first_str);
			return (1);
		}
	}

	tgt_buf_add_tag(&first_str, XML_ELEMENT_TARG, Tag_End);
	tgt_buf_add_tag(&first_str, "list", Tag_End);

	if ((node = tgt_door_call(first_str, 0)) == NULL) {
		(void) fprintf(stderr, "%s: %s\n", cmdName,
		    gettext("No reponse from daemon"));
		return (1);
	}
	free(first_str);

	if (strcmp(node->x_name, XML_ELEMENT_RESULT)) {
		(void) fprintf(stderr, "%s: %s\n", cmdName,
		    gettext("Bad XML response"));
		return (1);
	}

	n1 = NULL;
	while ((n1 = tgt_node_next_child(node, XML_ELEMENT_TARG, n1)) != NULL) {
		(void) printf("%s: %s\n", gettext("Target"), n1->x_value);
		n2 = tgt_node_next_child(n1, XML_ELEMENT_INAME, NULL);
		(void) printf("%s%s: %s\n", dospace(1), gettext("iSCSI Name"),
		    n2 ? n2->x_value : gettext("Not set"));

		if ((n2 = tgt_node_next_child(n1, XML_ELEMENT_ALIAS, NULL)) !=
		    NULL)
			(void) printf("%s%s: %s\n", dospace(1),
			    gettext("Alias"), n2->x_value);

		if ((n2 = tgt_node_next_child(n1, XML_ELEMENT_MAXRECV, NULL)) !=
		    NULL)
			(void) printf("%s%s: %s\n", dospace(1),
			    gettext("MaxRecv"), n2->x_value);

		/*
		 * Count the number of connections available.
		 */
		n2 = NULL;
		conns = 0;
		while (n2 = tgt_node_next_child(n1, XML_ELEMENT_CONN, n2))
			conns++;
		(void) printf("%s%s: %d\n", dospace(1), gettext("Connections"),
		    conns);

		if (verbose == False)
			continue;

		/*
		 * Displaying the individual connections must be done
		 * first when verbose is turned on because you'll notice
		 * above that we've left the output hanging with a label
		 * indicating connections are coming next.
		 */
		n2 = NULL;
		while (n2 = tgt_node_next_child(n1, XML_ELEMENT_CONN, n2)) {
			(void) printf("%s%s:\n", dospace(2),
			    gettext("Initiator"));
			(void) printf("%s%s: %s\n", dospace(3),
			    gettext("iSCSI Name"), n2->x_value);
			n3 = tgt_node_next_child(n2, XML_ELEMENT_ALIAS, NULL);
			(void) printf("%s%s: %s\n", dospace(3),
			    gettext("Alias"),
			    n3 ? n3->x_value : gettext("unknown"));
		}

		(void) printf("%s%s:\n", dospace(1), gettext("ACL list"));
		n2 = tgt_node_next_child(n1, XML_ELEMENT_ACLLIST, NULL);
		n3 = NULL;
		while (n3 = tgt_node_next_child(n2, XML_ELEMENT_INIT, n3)) {
			(void) printf("%s%s: %s\n", dospace(2),
			    gettext("Initiator"),
			    n3->x_value);
		}

		(void) printf("%s%s:\n", dospace(1), gettext("TPGT list"));
		n2 = tgt_node_next_child(n1, XML_ELEMENT_TPGTLIST, NULL);
		n3 = NULL;
		while (n3 = tgt_node_next_child(n2, XML_ELEMENT_TPGT, n3)) {
			(void) printf("%s%s: %s\n", dospace(2),
			    gettext("TPGT"),
			    n3->x_value);
		}

		(void) printf("%s%s:\n", dospace(1),
		    gettext("LUN information"));
		n2 = tgt_node_next_child(n1, XML_ELEMENT_LUNINFO, NULL);
		n3 = NULL;
		while (n3 = tgt_node_next_child(n2, XML_ELEMENT_LUN, n3)) {
			(void) printf("%s%s: %s\n", dospace(2), gettext("LUN"),
			    n3->x_value);

			n4 = tgt_node_next_child(n3, XML_ELEMENT_GUID, NULL);
			(void) printf("%s%s: %s\n", dospace(3), gettext("GUID"),
			    n4 ? n4->x_value : gettext("unknown"));

			n4 = tgt_node_next_child(n3, XML_ELEMENT_VID, NULL);
			(void) printf("%s%s: %s\n", dospace(3), gettext("VID"),
			    n4 ? n4->x_value : gettext("unknown"));

			n4 = tgt_node_next_child(n3, XML_ELEMENT_PID, NULL);
			(void) printf("%s%s: %s\n", dospace(3), gettext("PID"),
			    n4 ? n4->x_value : gettext("unknown"));

			n4 = tgt_node_next_child(n3, XML_ELEMENT_DTYPE, NULL);
			(void) printf("%s%s: %s\n", dospace(3), gettext("Type"),
			    n4 ? n4->x_value : gettext("unknown"));

			n4 = tgt_node_next_child(n3, XML_ELEMENT_SIZE, NULL);
			if (n4 && (strtol(n4->x_value, NULL, 0) != 0)) {
				(void) printf("%s%s: %s\n", dospace(3),
				    gettext("Size"),
				    number_to_scaled_string(buf,
				    strtoll(n4->x_value,
				    NULL, 0), 512, 1024));
			} else {
				(void) printf("%s%s: %s\n", dospace(3),
				    gettext("Size"), gettext("unknown"));
			}

			n4 = tgt_node_next_child(n3, XML_ELEMENT_BACK, NULL);
			if (n4) {
				(void) printf("%s%s: %s\n", dospace(3),
				    gettext("Backing store"), n4->x_value);
			}

			n4 = tgt_node_next_child(n3, XML_ELEMENT_STATUS, NULL);
			(void) printf("%s%s: %s\n", dospace(3),
			    gettext("Status"),
			    n4 ? n4->x_value : gettext("unknown"));
		}
	}

	return (0);
}