コード例 #1
0
static int
ndmp_disable_auth(int argc, char **argv, ndmp_command_t *cur_cmd)
{
	char *auth_type;
	int c, i, auth_type_flag = 0;

	/* disable <-a auth-type> */
	if (argc != 3) {
		usage(B_FALSE, cur_cmd);
	}

	while ((c = getopt(argc, argv, ":a:")) != -1) {
		switch (c) {
		case 'a':
			auth_type = strdup(optarg);
			break;
		case ':':
			(void) fprintf(stderr, gettext("Option -%c "
			    "requires an operand\n"), optopt);
			break;
		case '?':
			(void) fprintf(stderr, gettext("Unrecognized "
			    "option: -%c\n"), optopt);
		}
	}
	for (i = 0; i < NAUTH; i++) {
		if (strncmp(auth_type, ndmp_auth_table[i].auth_type,
		    strlen(ndmp_auth_table[i].auth_type)) == 0) {
			auth_type_flag = 1;
			if ((ndmp_set_prop(ndmp_auth_table[i].username,
			    "")) == -1) {
				(void) fprintf(stdout,
				    gettext("Could not clear username - %s\n"),
				    ndmp_strerror(ndmp_errno));
				continue;
			}
			if ((ndmp_set_prop(ndmp_auth_table[i].password,
			    "")) == -1) {
				(void) fprintf(stdout,
				    gettext("Could not clear password - %s\n"),
				    ndmp_strerror(ndmp_errno));
				continue;
			}
			if (!ndmp_door_status() &&
			    (ndmp_service_refresh()) != 0) {
				(void) fprintf(stdout, gettext("Could not "
				    "refesh ndmpd service properties\n"));
			}
		}
	}
	free(auth_type);

	if (!auth_type_flag)
		usage(B_FALSE, cur_cmd);

	return (0);
}
コード例 #2
0
ファイル: ndmpd_prop.c プロジェクト: NanXiao/illumos-joyent
/*
 * Loads all the NDMP configuration parameters and sets up the
 * config table.
 */
int
ndmpd_load_prop(void)
{
	ndmpd_cfg_id_t id;
	ndmpd_cfg_param_t *cfg;
	char *value;

	for (id = 0; id < NDMP_MAXALL; id++) {
		cfg = &ndmpd_cfg_table[id];
		if ((ndmp_get_prop(cfg->sc_name, &value)) == -1) {
			syslog(LOG_DEBUG, "%s %s",
			    cfg->sc_name, ndmp_strerror(ndmp_errno));
			continue;
		}
		/*
		 * enval == 0 could mean two things, either the
		 * config param is not defined, or it has been
		 * removed. If the variable has already been defined
		 * and now enval is 0, it should be removed, otherwise
		 * we don't need to do anything in this case.
		 */
		if ((cfg->sc_flags & NDMP_CF_DEFINED) || value) {
			if (ndmpd_config_update(cfg, value)) {
				free(value);
				return (-1);
			}
		}
		free(value);
	}
	return (0);
}
コード例 #3
0
static void
ndmp_set_config_process(char *propname)
{
	char *propvalue;
	int ret, j;

	if ((propvalue = strchr(propname, '=')) == NULL) {
		(void) fprintf(stderr, gettext("Missing value in "
		    "property=value argument for %s\n"), propname);
		return;
	}
	*propvalue = '\0';
	propvalue++;

	if (*propname == '\0') {
		(void) fprintf(stderr, gettext("Missing property in "
		    "property=value argument for %s\n"), propname);
		return;
	}
	for (j = 0; j < NDMPADM_NPROP; j++) {
		if (strcmp(propname, prop_table[j]) == 0)
			break;
	}
	if (j == NDMPADM_NPROP) {
		(void) fprintf(stdout, gettext("%s is invalid property or "
		    "variable\n"), propname);
		return;
	}
	ret = ndmp_set_prop(propname, propvalue);
	if (ret != -1) {
		if (!ndmp_door_status()) {
			if (ndmp_service_refresh() != 0)
				(void) fprintf(stdout, gettext("Could not "
				    "refesh property of service ndmpd\n"));
		}
	} else {
		(void) fprintf(stdout, gettext("Could not set property for "
		    "%s - %s\n"), propname, ndmp_strerror(ndmp_errno));
	}
}
コード例 #4
0
static int
ndmp_enable_auth(int argc, char **argv, ndmp_command_t *cur_cmd)
{
	char *auth_type, *username, *password;
	int c, i, auth_type_flag = 0;
	char *enc_password;

	/* enable <-a auth-type> <-u username> */
	if (argc != 5) {
		usage(B_FALSE, cur_cmd);
	}

	while ((c = getopt(argc, argv, ":a:u:")) != -1) {
		switch (c) {
		case 'a':
			auth_type = strdup(optarg);
			break;
		case 'u':
			username = strdup(optarg);
			break;
		case ':':
			(void) fprintf(stderr, gettext("Option -%c "
			    "requires an operand\n"), optopt);
			usage(B_FALSE, cur_cmd);
			break;
		case '?':
			(void) fprintf(stderr, gettext("Unrecognized "
			    "option: -%c\n"), optopt);
			usage(B_FALSE, cur_cmd);
		}
	}

	if ((auth_type) && (username)) {
		if (ndmp_get_password(&password)) {
			(void) fprintf(stderr, gettext("Could not get correct "
			    "password, exiting..."));
			free(auth_type);
			free(username);
			exit(-1);
		}
	} else {
		(void) fprintf(stderr, gettext("%s or %s can not be blank"),
		    "'auth-type'", "'username'");
		free(auth_type);
		free(username);
		exit(-1);
	}

	if ((enc_password = ndmp_base64_encode(password)) == NULL) {
		(void) fprintf(stdout,
		    gettext("Could not encode password - %s\n"),
		    ndmp_strerror(ndmp_errno));
		free(auth_type);
		free(username);
		exit(-1);
	}

	for (i = 0; i < NAUTH; i++) {
		if (strncmp(auth_type, ndmp_auth_table[i].auth_type,
		    strlen(ndmp_auth_table[i].auth_type)) == 0) {
			auth_type_flag = 1;
			if ((ndmp_set_prop(ndmp_auth_table[i].username,
			    username)) == -1) {
				(void) fprintf(stdout,
				    gettext("Could not set username - %s\n"),
				    ndmp_strerror(ndmp_errno));
				continue;
			}
			if ((ndmp_set_prop(ndmp_auth_table[i].password,
			    enc_password)) == -1) {
				(void) fprintf(stdout,
				    gettext("Could not set password - %s\n"),
				    ndmp_strerror(ndmp_errno));
				continue;
			}
			if (!ndmp_door_status() &&
			    (ndmp_service_refresh()) != 0) {
				(void) fprintf(stdout,
				    gettext("Could not refesh ndmpd service "
				    "properties\n"));
			}
		}
	}
	free(auth_type);
	free(username);
	free(enc_password);

	if (!auth_type_flag)
		usage(B_FALSE, cur_cmd);

	return (0);
}