diff options
author | dougm <none@none> | 2007-07-13 09:21:04 -0700 |
---|---|---|
committer | dougm <none@none> | 2007-07-13 09:21:04 -0700 |
commit | 25a68471b9ababbc21cfdbbb2866014f34f419ec (patch) | |
tree | 37c9aa7232ce142e2ba38d3359fef104c6cbc0d9 /usr/src | |
parent | a1af7ba02a81ee5af0f2cd6b30b99957a93fc605 (diff) | |
download | illumos-joyent-25a68471b9ababbc21cfdbbb2866014f34f419ec.tar.gz |
6549814 libshare has no sense of style
Diffstat (limited to 'usr/src')
-rw-r--r-- | usr/src/cmd/dfs.cmds/sharectl/sharectl.c | 381 | ||||
-rw-r--r-- | usr/src/cmd/dfs.cmds/sharemgr/commands.c | 4534 | ||||
-rw-r--r-- | usr/src/cmd/dfs.cmds/sharemgr/sharemgr_main.c | 26 | ||||
-rw-r--r-- | usr/src/lib/libshare/common/libsharecore.c | 1775 | ||||
-rw-r--r-- | usr/src/lib/libshare/common/plugin.c | 217 | ||||
-rw-r--r-- | usr/src/lib/libshare/common/scfutil.c | 1295 |
6 files changed, 4217 insertions, 4011 deletions
diff --git a/usr/src/cmd/dfs.cmds/sharectl/sharectl.c b/usr/src/cmd/dfs.cmds/sharectl/sharectl.c index a29bbf5a55..2fda948a87 100644 --- a/usr/src/cmd/dfs.cmds/sharectl/sharectl.c +++ b/usr/src/cmd/dfs.cmds/sharectl/sharectl.c @@ -68,19 +68,19 @@ main(int argc, char *argv[]) handle = sa_init(SA_INIT_CONTROL_API); while ((c = getopt(argc, argv, "h?")) != EOF) { - switch (c) { - case '?': - case 'h': - help = 1; - break; - default: - (void) printf(gettext("Invalid option: %c\n"), c); - } + switch (c) { + case '?': + case 'h': + help = 1; + break; + default: + (void) printf(gettext("Invalid option: %c\n"), c); + } } if (optind == argc || help) { - /* no subcommand */ - global_help(); - exit(0); + /* no subcommand */ + global_help(); + exit(0); } optind = 1; @@ -101,14 +101,14 @@ sc_get_usage(sc_usage_t index) switch (index) { case USAGE_CTL_GET: - ret = gettext("get [-h | -p property ...] proto"); - break; + ret = gettext("get [-h | -p property ...] proto"); + break; case USAGE_CTL_SET: - ret = gettext("set [-h] -p property=value ... proto"); - break; + ret = gettext("set [-h] -p property=value ... proto"); + break; case USAGE_CTL_STATUS: - ret = gettext("status [-h | proto ...]"); - break; + ret = gettext("status [-h | proto ...]"); + break; } return (ret); } @@ -123,81 +123,103 @@ sc_get(sa_handle_t handle, int flags, int argc, char *argv[]) int c; while ((c = getopt(argc, argv, "?hp:")) != EOF) { - switch (c) { - case 'p': - ret = add_opt(&optlist, optarg, 1); - if (ret != SA_OK) { - (void) printf(gettext("Problem with property: %s\n"), - optarg); - return (SA_NO_MEMORY); + switch (c) { + case 'p': + ret = add_opt(&optlist, optarg, 1); + if (ret != SA_OK) { + (void) printf(gettext( + "Problem with property: %s\n"), optarg); + return (SA_NO_MEMORY); + } + break; + default: + (void) printf(gettext("usage: %s\n"), + sc_get_usage(USAGE_CTL_GET)); + return (SA_SYNTAX_ERR); + case '?': + case 'h': + (void) printf(gettext("usage: %s\n"), + sc_get_usage(USAGE_CTL_GET)); + return (SA_OK); + break; } - break; - default: - (void) printf(gettext("usage: %s\n"), - sc_get_usage(USAGE_CTL_GET)); - return (SA_SYNTAX_ERR); - case '?': - case 'h': - (void) printf(gettext("usage: %s\n"), - sc_get_usage(USAGE_CTL_GET)); - return (SA_OK); - break; - } } if (optind >= argc) { - (void) printf(gettext("usage: %s\n"), sc_get_usage(USAGE_CTL_GET)); - (void) printf(gettext("\tprotocol must be specified.\n")); - return (SA_INVALID_PROTOCOL); + (void) printf(gettext("usage: %s\n"), + sc_get_usage(USAGE_CTL_GET)); + (void) printf(gettext("\tprotocol must be specified.\n")); + return (SA_INVALID_PROTOCOL); } proto = argv[optind]; if (sa_valid_protocol(proto)) { - sa_protocol_properties_t propset; - propset = sa_proto_get_properties(proto); - if (propset != NULL) { - sa_property_t prop; - char *value; - char *name; - if (optlist == NULL) { - /* display all known properties for this protocol */ - for (prop = sa_get_protocol_property(propset, NULL); - prop != NULL; - prop = sa_get_next_protocol_property(prop)) { - - /* get and display the property and value */ - name = sa_get_property_attr(prop, "type"); - if (name != NULL) { - value = sa_get_property_attr(prop, "value"); - (void) printf(gettext("%s=%s\n"), name, - value != NULL ? value : ""); - } - if (value != NULL) - sa_free_attr_string(value); - if (name != NULL) - sa_free_attr_string(name); - } - } else { - struct options *opt; - /* list the specified option(s) */ - for (opt = optlist; opt != NULL; opt = opt->next) { - prop = sa_get_protocol_property(propset, opt->optname); - if (prop != NULL) { - value = sa_get_property_attr(prop, "value"); - (void) printf(gettext("%s=%s\n"), opt->optname, - value != NULL ? value : ""); - sa_free_attr_string(value); + sa_protocol_properties_t propset; + propset = sa_proto_get_properties(proto); + if (propset != NULL) { + sa_property_t prop; + char *value; + char *name; + + if (optlist == NULL) { + /* + * Display all known properties for + * this protocol. + */ + for (prop = sa_get_protocol_property(propset, + NULL); + prop != NULL; + prop = sa_get_next_protocol_property( + prop)) { + + /* + * Get and display the + * property and value. + */ + name = sa_get_property_attr(prop, + "type"); + if (name != NULL) { + value = sa_get_property_attr( + prop, "value"); + (void) printf(gettext( + "%s=%s\n"), name, + value != NULL ? value : ""); + } + if (value != NULL) + sa_free_attr_string(value); + if (name != NULL) + sa_free_attr_string(name); + } } else { - (void) printf(gettext("%s: not defined\n"), - opt->optname); - ret = SA_NO_SUCH_PROP; + struct options *opt; + /* list the specified option(s) */ + for (opt = optlist; + opt != NULL; + opt = opt->next) { + prop = sa_get_protocol_property( + propset, opt->optname); + if (prop != NULL) { + value = sa_get_property_attr( + prop, "value"); + (void) printf(gettext( + "%s=%s\n"), + opt->optname, + value != NULL ? + value : ""); + sa_free_attr_string(value); + } else { + (void) printf(gettext( + "%s: not defined\n"), + opt->optname); + ret = SA_NO_SUCH_PROP; + } + } } - } } - } } else { - (void) printf(gettext("Invalid protocol specified: %s\n"), proto); - ret = SA_INVALID_PROTOCOL; + (void) printf(gettext("Invalid protocol specified: %s\n"), + proto); + ret = SA_INVALID_PROTOCOL; } return (ret); } @@ -210,85 +232,94 @@ sc_set(sa_handle_t handle, int flags, int argc, char *argv[]) struct options *optlist = NULL; int ret = SA_OK; int c; + sa_protocol_properties_t propset; while ((c = getopt(argc, argv, "?hp:")) != EOF) { - switch (c) { - case 'p': - ret = add_opt(&optlist, optarg, 0); - if (ret != SA_OK) { - (void) printf(gettext("Problem with property: %s\n"), - optarg); - return (SA_NO_MEMORY); + switch (c) { + case 'p': + ret = add_opt(&optlist, optarg, 0); + if (ret != SA_OK) { + (void) printf(gettext( + "Problem with property: %s\n"), optarg); + return (SA_NO_MEMORY); + } + break; + default: + (void) printf(gettext("usage: %s\n"), + sc_get_usage(USAGE_CTL_SET)); + return (SA_SYNTAX_ERR); + case '?': + case 'h': + (void) printf(gettext("usage: %s\n"), + sc_get_usage(USAGE_CTL_SET)); + return (SA_OK); + break; } - break; - default: - (void) printf(gettext("usage: %s\n"), - sc_get_usage(USAGE_CTL_SET)); - return (SA_SYNTAX_ERR); - case '?': - case 'h': - (void) printf(gettext("usage: %s\n"), - sc_get_usage(USAGE_CTL_SET)); - return (SA_OK); - break; - } } if (optind >= argc) { - (void) printf(gettext("usage: %s\n"), - sc_get_usage(USAGE_CTL_SET)); - (void) printf(gettext("\tprotocol must be specified.\n")); - return (SA_INVALID_PROTOCOL); + (void) printf(gettext("usage: %s\n"), + sc_get_usage(USAGE_CTL_SET)); + (void) printf(gettext("\tprotocol must be specified.\n")); + return (SA_INVALID_PROTOCOL); } proto = argv[optind]; - if (sa_valid_protocol(proto)) { - sa_protocol_properties_t propset; - propset = sa_proto_get_properties(proto); - if (propset != NULL) { + if (!sa_valid_protocol(proto)) { + (void) printf(gettext("Invalid protocol specified: %s\n"), + proto); + return (SA_INVALID_PROTOCOL); + } + propset = sa_proto_get_properties(proto); + if (propset != NULL) { sa_property_t prop; int err; - if (optlist == NULL) { - (void) printf(gettext("usage: %s\n"), - sc_get_usage(USAGE_CTL_SET)); - (void) printf(gettext("\tat least one property and value " - "must be specified\n")); + (void) printf(gettext("usage: %s\n"), + sc_get_usage(USAGE_CTL_SET)); + (void) printf(gettext( + "\tat least one property and value " + "must be specified\n")); } else { - struct options *opt; - /* list the specified option(s) */ - for (opt = optlist; opt != NULL; opt = opt->next) { - prop = sa_get_protocol_property(propset, opt->optname); - if (prop != NULL) { - /* - * "err" is used in order to prevent - * setting ret to SA_OK if there has - * been a real error. We want to be - * able to return an error status on - * exit in that case. Error messages - * are printed for each error, so we - * only care on exit that there was an - * error and not the specific error - * value. - */ - err = sa_set_protocol_property(prop, opt->optvalue); - if (err != SA_OK) { - (void) printf(gettext("Could not set property" - " %s: %s\n"), - opt->optname, sa_errorstr(err)); - ret = err; - } - } else { - (void) printf(gettext("%s: not defined\n"), - opt->optname); - ret = SA_NO_SUCH_PROP; + struct options *opt; + /* list the specified option(s) */ + for (opt = optlist; + opt != NULL; + opt = opt->next) { + prop = sa_get_protocol_property( + propset, opt->optname); + if (prop != NULL) { + /* + * "err" is used in order to + * prevent setting ret to + * SA_OK if there has been a + * real error. We want to be + * able to return an error + * status on exit in that + * case. Error messages are + * printed for each error, so + * we only care on exit that + * there was an error and not + * the specific error value. + */ + err = sa_set_protocol_property( + prop, opt->optvalue); + if (err != SA_OK) { + (void) printf(gettext( + "Could not set property" + " %s: %s\n"), + opt->optname, + sa_errorstr(err)); + ret = err; + } + } else { + (void) printf(gettext( + "%s: not defined\n"), + opt->optname); + ret = SA_NO_SUCH_PROP; + } } - } } - } - } else { - (void) printf(gettext("Invalid protocol specified: %s\n"), proto); - ret = SA_INVALID_PROTOCOL; } return (ret); } @@ -297,10 +328,11 @@ static void show_status(char *proto) { char *status; + status = sa_get_protocol_status(proto); (void) printf("%s\t%s\n", proto, status ? gettext(status) : "-"); if (status != NULL) - free(status); + free(status); } static int @@ -308,8 +340,8 @@ valid_proto(char **protos, int num, char *proto) { int i; for (i = 0; i < num; i++) - if (strcmp(protos[i], proto) == 0) - return (1); + if (strcmp(protos[i], proto) == 0) + return (1); return (0); } @@ -325,40 +357,41 @@ sc_status(sa_handle_t handle, int flags, int argc, char *argv[]) int verbose = 0; while ((c = getopt(argc, argv, "?hv")) != EOF) { - switch (c) { - case 'v': - verbose++; - break; - case '?': - case 'h': - (void) printf(gettext("usage: %s\n"), - sc_get_usage(USAGE_CTL_STATUS)); - return (SA_OK); - default: - (void) printf(gettext("usage: %s\n"), - sc_get_usage(USAGE_CTL_STATUS)); - return (SA_SYNTAX_ERR); - } + switch (c) { + case 'v': + verbose++; + break; + case '?': + case 'h': + (void) printf(gettext("usage: %s\n"), + sc_get_usage(USAGE_CTL_STATUS)); + return (SA_OK); + default: + (void) printf(gettext("usage: %s\n"), + sc_get_usage(USAGE_CTL_STATUS)); + return (SA_SYNTAX_ERR); + } } num_proto = sa_get_protocols(&protos); if (optind == argc) { - /* status for all protocols */ - for (i = 0; i < num_proto; i++) { - show_status(protos[i]); - } + /* status for all protocols */ + for (i = 0; i < num_proto; i++) { + show_status(protos[i]); + } } else { - for (i = optind; i < argc; i++) { - if (valid_proto(protos, num_proto, argv[i])) { - show_status(argv[i]); - } else { - (void) printf(gettext("Invalid protocol: %s\n"), argv[i]); - ret = SA_INVALID_PROTOCOL; + for (i = optind; i < argc; i++) { + if (valid_proto(protos, num_proto, argv[i])) { + show_status(argv[i]); + } else { + (void) printf(gettext("Invalid protocol: %s\n"), + argv[i]); + ret = SA_INVALID_PROTOCOL; + } } - } } if (protos != NULL) - free(protos); + free(protos); return (ret); } @@ -379,7 +412,7 @@ sub_command_help(char *proto) for (i = 0; commands[i].cmdname != NULL; i++) { if (!(commands[i].flags & (CMD_ALIAS|CMD_NODISPLAY))) (void) printf("\t%s\n", - sc_get_usage((sc_usage_t)commands[i].cmdidx)); + sc_get_usage((sc_usage_t)commands[i].cmdidx)); } } diff --git a/usr/src/cmd/dfs.cmds/sharemgr/commands.c b/usr/src/cmd/dfs.cmds/sharemgr/commands.c index cd2eba52eb..e31104a2a6 100644 --- a/usr/src/cmd/dfs.cmds/sharemgr/commands.c +++ b/usr/src/cmd/dfs.cmds/sharemgr/commands.c @@ -69,7 +69,7 @@ has_protocol(sa_group_t group, char *protocol) optionset = sa_get_optionset(group, protocol); if (optionset != NULL) { - result++; + result++; } return (result); } @@ -87,15 +87,15 @@ add_list(struct list *listp, void *item, void *data) new = malloc(sizeof (struct list)); if (new != NULL) { - new->next = NULL; - new->item = item; - new->itemdata = data; + new->next = NULL; + new->item = item; + new->itemdata = data; } else { - return (listp); + return (listp); } if (listp == NULL) - return (new); + return (new); for (tmp = listp; tmp->next != NULL; tmp = tmp->next) { /* get to end of list */ @@ -113,9 +113,9 @@ free_list(struct list *listp) { struct list *tmp; while (listp != NULL) { - tmp = listp; - listp = listp->next; - free(tmp); + tmp = listp; + listp = listp->next; + free(tmp); } } @@ -134,59 +134,61 @@ check_authorization(char *instname, int which) char svcstring[SA_MAX_NAME_LEN + sizeof (SA_SVC_FMRI_BASE) + 1]; char *authstr = NULL; ssize_t numauths; - int ret = 1; + int ret = B_TRUE; uid_t uid; struct passwd *pw = NULL; uid = getuid(); pw = getpwuid(uid); - if (pw == NULL) - ret = 0; - - if (ret == 1) { - /* since names are restricted to SA_MAX_NAME_LEN won't overflow */ - (void) snprintf(svcstring, sizeof (svcstring), - "%s:%s", SA_SVC_FMRI_BASE, instname); - handle = scf_handle_create(SCF_VERSION); - if (handle != NULL) { - if (scf_handle_bind(handle) == 0) { - switch (which) { - case SVC_SET: - prop = scf_simple_prop_get(handle, svcstring, - "general", - SVC_AUTH_VALUE); - break; - case SVC_ACTION: - prop = scf_simple_prop_get(handle, svcstring, - "general", - SVC_AUTH_ACTION); - break; - } - } - } + if (pw == NULL) { + ret = B_FALSE; + } else { + /* + * Since names are restricted to SA_MAX_NAME_LEN won't + * overflow. + */ + (void) snprintf(svcstring, sizeof (svcstring), "%s:%s", + SA_SVC_FMRI_BASE, instname); + handle = scf_handle_create(SCF_VERSION); + if (handle != NULL) { + if (scf_handle_bind(handle) == 0) { + switch (which) { + case SVC_SET: + prop = scf_simple_prop_get(handle, + svcstring, "general", + SVC_AUTH_VALUE); + break; + case SVC_ACTION: + prop = scf_simple_prop_get(handle, + svcstring, "general", + SVC_AUTH_ACTION); + break; + } + } + } } /* make sure we have an authorization string property */ if (prop != NULL) { - int i; - numauths = scf_simple_prop_numvalues(prop); - for (ret = 0, i = 0; i < numauths; i++) { - authstr = scf_simple_prop_next_astring(prop); - if (authstr != NULL) { - /* check if this user has one of the strings */ - if (chkauthattr(authstr, pw->pw_name)) { - ret = 1; - break; - } + int i; + numauths = scf_simple_prop_numvalues(prop); + for (ret = 0, i = 0; i < numauths; i++) { + authstr = scf_simple_prop_next_astring(prop); + if (authstr != NULL) { + /* check if this user has one of the strings */ + if (chkauthattr(authstr, pw->pw_name)) { + ret = 1; + break; + } + } } - } - endauthattr(); - scf_simple_prop_free(prop); + endauthattr(); + scf_simple_prop_free(prop); } else { - /* no authorization string defined */ - ret = 0; + /* no authorization string defined */ + ret = 0; } if (handle != NULL) - scf_handle_destroy(handle); + scf_handle_destroy(handle); return (ret); } @@ -206,22 +208,22 @@ check_authorizations(char *instname, int flags) int ret; if (flags & SVC_SET) - ret1 = check_authorization(instname, SVC_SET); + ret1 = check_authorization(instname, SVC_SET); if (flags & SVC_ACTION) - ret2 = check_authorization(instname, SVC_ACTION); + ret2 = check_authorization(instname, SVC_ACTION); switch (flags) { case SVC_ACTION: - ret = ret2; - break; + ret = ret2; + break; case SVC_SET: - ret = ret1; - break; + ret = ret1; + break; case SVC_ACTION|SVC_SET: - ret = ret1 & ret2; - break; + ret = ret1 & ret2; + break; default: - /* if not flags set, we assume we don't need authorizations */ - ret = 1; + /* if not flags set, we assume we don't need authorizations */ + ret = 1; } return (ret); } @@ -242,9 +244,9 @@ enable_group(sa_group_t group, char *updateproto) for (share = sa_get_share(group, NULL); share != NULL; share = sa_get_next_share(share)) { - if (updateproto != NULL) - (void) sa_update_legacy(share, updateproto); - (void) sa_enable_share(share, NULL); + if (updateproto != NULL) + (void) sa_update_legacy(share, updateproto); + (void) sa_enable_share(share, NULL); } } @@ -262,12 +264,12 @@ isenabled(sa_group_t group) int ret = B_FALSE; if (group != NULL) { - state = sa_get_group_attr(group, "state"); - if (state != NULL) { - if (strcmp(state, "enabled") == 0) - ret = B_TRUE; - sa_free_attr_string(state); - } + state = sa_get_group_attr(group, "state"); + if (state != NULL) { + if (strcmp(state, "enabled") == 0) + ret = B_TRUE; + sa_free_attr_string(state); + } } return (ret); } @@ -291,7 +293,7 @@ enable_all_groups(sa_handle_t handle, struct list *work, int setstate, sa_group_t subgroup; for (ret = SA_OK; work != NULL; work = work->next) { - group = (sa_group_t)work->item; + group = (sa_group_t)work->item; /* * If setstate == TRUE, then make sure to set @@ -299,11 +301,11 @@ enable_all_groups(sa_handle_t handle, struct list *work, int setstate, * the isenabled check to succeed on a newly enabled * group. */ - if (setstate == B_TRUE) { - ret = sa_set_group_attr(group, "state", "enabled"); - if (ret != SA_OK) - break; - } + if (setstate == B_TRUE) { + ret = sa_set_group_attr(group, "state", "enabled"); + if (ret != SA_OK) + break; + } /* * Check to see if group is enabled. If it isn't, skip @@ -312,58 +314,60 @@ enable_all_groups(sa_handle_t handle, struct list *work, int setstate, * updated, but there won't be a change until the * group is enabled. */ - if (!isenabled(group)) - continue; - - /* if itemdata != NULL then a single share */ - if (work->itemdata != NULL) { - ret = sa_enable_share((sa_share_t)work->itemdata, NULL); - } - if (ret != SA_OK) - break; + if (!isenabled(group)) + continue; - /* if itemdata == NULL then the whole group */ - if (work->itemdata == NULL) { - zfs = sa_get_group_attr(group, "zfs"); - /* - * if the share is managed by ZFS, don't - * update any of the protocols since ZFS is - * handling this. updateproto will contain - * the name of the protocol that we want to - * update legacy files for. - */ - enable_group(group, zfs == NULL ? updateproto : NULL); - for (subgroup = sa_get_sub_group(group); subgroup != NULL; - subgroup = sa_get_next_group(subgroup)) { - /* never update legacy for ZFS subgroups */ - enable_group(subgroup, NULL); - } - } - if (online) { - zfs = sa_get_group_attr(group, "zfs"); - name = sa_get_group_attr(group, "name"); - if (name != NULL) { - if (zfs == NULL) { - (void) snprintf(instance, sizeof (instance), - "%s:%s", - SA_SVC_FMRI_BASE, name); - state = smf_get_state(instance); - if (state == NULL || - strcmp(state, "online") != 0) { - (void) smf_enable_instance(instance, 0); - free(state); - } - } else { - sa_free_attr_string(zfs); - zfs = NULL; + /* if itemdata != NULL then a single share */ + if (work->itemdata != NULL) { + ret = sa_enable_share((sa_share_t)work->itemdata, NULL); + } + if (ret != SA_OK) + break; + + /* if itemdata == NULL then the whole group */ + if (work->itemdata == NULL) { + zfs = sa_get_group_attr(group, "zfs"); + /* + * if the share is managed by ZFS, don't + * update any of the protocols since ZFS is + * handling this. updateproto will contain + * the name of the protocol that we want to + * update legacy files for. + */ + enable_group(group, zfs == NULL ? updateproto : NULL); + for (subgroup = sa_get_sub_group(group); + subgroup != NULL; + subgroup = sa_get_next_group(subgroup)) { + /* never update legacy for ZFS subgroups */ + enable_group(subgroup, NULL); + } + } + if (online) { + zfs = sa_get_group_attr(group, "zfs"); + name = sa_get_group_attr(group, "name"); + if (name != NULL) { + if (zfs == NULL) { + (void) snprintf(instance, + sizeof (instance), "%s:%s", + SA_SVC_FMRI_BASE, name); + state = smf_get_state(instance); + if (state == NULL || + strcmp(state, "online") != 0) { + (void) smf_enable_instance( + instance, 0); + free(state); + } + } else { + sa_free_attr_string(zfs); + zfs = NULL; + } + if (name != NULL) + sa_free_attr_string(name); } - if (name != NULL) - sa_free_attr_string(name); } - } } if (ret == SA_OK) { - ret = sa_update_config(handle); + ret = sa_update_config(handle); } return (ret); } @@ -385,44 +389,46 @@ chk_opt(struct options *optlistp, int security, char *proto) int ret; for (optlist = optlistp; optlist != NULL; optlist = optlist->next) { - char *optname; - - optname = optlist->optname; - ret = OPT_ADD_OK; - /* extract property/value pair */ - if (sa_is_security(optname, proto)) { - if (!security) - ret = OPT_ADD_SECURITY; - } else { - if (security) - ret = OPT_ADD_PROPERTY; - } - if (ret != OPT_ADD_OK) { - if (notfirst == 0) - (void) printf(gettext("Property syntax error: ")); - switch (ret) { - case OPT_ADD_SYNTAX: - (void) printf(gettext("%ssyntax error: %s"), + char *optname; + + optname = optlist->optname; + ret = OPT_ADD_OK; + /* extract property/value pair */ + if (sa_is_security(optname, proto)) { + if (!security) + ret = OPT_ADD_SECURITY; + } else { + if (security) + ret = OPT_ADD_PROPERTY; + } + if (ret != OPT_ADD_OK) { + if (notfirst == 0) + (void) printf( + gettext("Property syntax error: ")); + switch (ret) { + case OPT_ADD_SYNTAX: + (void) printf(gettext("%ssyntax error: %s"), sep, optname); - sep = ", "; - break; - case OPT_ADD_SECURITY: - (void) printf(gettext("%s%s requires -S"), + sep = ", "; + break; + case OPT_ADD_SECURITY: + (void) printf(gettext("%s%s requires -S"), optname, sep); - sep = ", "; - break; - case OPT_ADD_PROPERTY: - (void) printf(gettext("%s%s not supported with -S"), + sep = ", "; + break; + case OPT_ADD_PROPERTY: + (void) printf( + gettext("%s%s not supported with -S"), optname, sep); - sep = ", "; - break; + sep = ", "; + break; + } + notfirst++; } - notfirst++; - } } if (notfirst) { - (void) printf("\n"); - ret = SA_SYNTAX_ERR; + (void) printf("\n"); + ret = SA_SYNTAX_ERR; } return (ret); } @@ -455,25 +461,25 @@ valid_options(struct options *optlist, char *proto, void *object, char *sec) sa_optionset_t parent = NULL; if (object != NULL) { - if (sec == NULL) - parent = sa_get_optionset(object, proto); - else - parent = sa_get_security(object, sec, proto); + if (sec == NULL) + parent = sa_get_optionset(object, proto); + else + parent = sa_get_security(object, sec, proto); } for (cur = optlist; cur != NULL; cur = cur->next) { - if (cur->optvalue != NULL) { + if (cur->optvalue == NULL) + continue; prop = sa_create_property(cur->optname, cur->optvalue); if (prop == NULL) - ret = SA_NO_MEMORY; + ret = SA_NO_MEMORY; if (ret != SA_OK || (ret = sa_valid_property(parent, proto, prop)) != SA_OK) { - (void) printf(gettext("Could not add property %s: %s\n"), - cur->optname, - sa_errorstr(ret)); + (void) printf( + gettext("Could not add property %s: %s\n"), + cur->optname, sa_errorstr(ret)); } (void) sa_remove_property(prop); - } } return (ret); } @@ -495,11 +501,14 @@ add_optionset(sa_group_t group, struct options *optlist, char *proto, int *err) optionset = sa_get_optionset(group, proto); if (optionset == NULL) { - optionset = sa_create_optionset(group, proto); - result = 1; /* adding a protocol is a change */ + optionset = sa_create_optionset(group, proto); + result = 1; /* adding a protocol is a change */ } - if (optionset != NULL) { - while (optlist != NULL) { + if (optionset == NULL) { + ret = SA_NO_MEMORY; + goto out; + } + while (optlist != NULL) { sa_property_t prop; prop = sa_get_property(optionset, optlist->optname); if (prop == NULL) { @@ -507,50 +516,53 @@ add_optionset(sa_group_t group, struct options *optlist, char *proto, int *err) * add the property, but only if it is * a non-NULL or non-zero length value */ - if (optlist->optvalue != NULL) { - prop = sa_create_property(optlist->optname, - optlist->optvalue); - if (prop != NULL) { - ret = sa_valid_property(optionset, proto, prop); - if (ret != SA_OK) { - (void) sa_remove_property(prop); - (void) printf(gettext("Could not add property " - "%s: %s\n"), - optlist->optname, - sa_errorstr(ret)); - } + if (optlist->optvalue != NULL) { + prop = sa_create_property(optlist->optname, + optlist->optvalue); + if (prop != NULL) { + ret = sa_valid_property(optionset, + proto, prop); + if (ret != SA_OK) { + (void) sa_remove_property(prop); + (void) printf(gettext("Could " + "not add property " + "%s: %s\n"), + optlist->optname, + sa_errorstr(ret)); + } + } + if (ret == SA_OK) { + ret = sa_add_property(optionset, prop); + if (ret != SA_OK) { + (void) printf(gettext( + "Could not add property " + "%s: %s\n"), + optlist->optname, + sa_errorstr(ret)); + } else { + /* there was a change */ + result = 1; + } + } } - if (ret == SA_OK) { - ret = sa_add_property(optionset, prop); - if (ret != SA_OK) { - (void) printf(gettext("Could not add property" - " %s: %s\n"), - optlist->optname, - sa_errorstr(ret)); - } else { - /* there was a change */ + } else { + ret = sa_update_property(prop, optlist->optvalue); + /* should check to see if value changed */ + if (ret != SA_OK) { + (void) printf(gettext("Could not update " + "property %s: %s\n"), optlist->optname, + sa_errorstr(ret)); + } else { result = 1; - } } - } - } else { - ret = sa_update_property(prop, optlist->optvalue); - /* should check to see if value changed */ - if (ret != SA_OK) { - (void) printf(gettext("Could not update " - "property %s: %s\n"), - optlist->optname, - sa_errorstr(ret)); - } else { - result = 1; - } } optlist = optlist->next; - } - ret = sa_commit_properties(optionset, 0); } + ret = sa_commit_properties(optionset, 0); + +out: if (err != NULL) - *err = ret; + *err = ret; return (result); } @@ -576,78 +588,81 @@ sa_create(sa_handle_t handle, int flags, int argc, char *argv[]) int auth; while ((c = getopt(argc, argv, "?hvnP:p:")) != EOF) { - switch (c) { - case 'v': - verbose++; - break; - case 'n': - dryrun++; - break; - case 'P': - protocol = optarg; - if (!sa_valid_protocol(protocol)) { - (void) printf(gettext("Invalid protocol specified: %s\n"), - protocol); - return (SA_INVALID_PROTOCOL); - } - break; - case 'p': - ret = add_opt(&optlist, optarg, 0); - switch (ret) { - case OPT_ADD_SYNTAX: - (void) printf(gettext("Property syntax error for " - "property: %s\n"), + switch (c) { + case 'v': + verbose++; + break; + case 'n': + dryrun++; + break; + case 'P': + protocol = optarg; + if (sa_valid_protocol(protocol)) + break; + (void) printf(gettext( + "Invalid protocol specified: %s\n"), protocol); + return (SA_INVALID_PROTOCOL); + break; + case 'p': + ret = add_opt(&optlist, optarg, 0); + switch (ret) { + case OPT_ADD_SYNTAX: + (void) printf(gettext( + "Property syntax error for property: %s\n"), optarg); - return (SA_SYNTAX_ERR); - case OPT_ADD_SECURITY: - (void) printf(gettext("Security properties need " - "to be set with set-security: %s\n"), + return (SA_SYNTAX_ERR); + case OPT_ADD_SECURITY: + (void) printf(gettext( + "Security properties need " + "to be set with set-security: %s\n"), optarg); - return (SA_SYNTAX_ERR); + return (SA_SYNTAX_ERR); + default: + break; + } + break; default: - break; + case 'h': + case '?': + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_CREATE)); + return (0); } - - break; - default: - case 'h': - case '?': - (void) printf(gettext("usage: %s\n"), - sa_get_usage(USAGE_CREATE)); - return (0); - } } if (optind >= argc) { - (void) printf(gettext("usage: %s\n"), sa_get_usage(USAGE_CREATE)); - (void) printf(gettext("\tgroup must be specified.\n")); - return (SA_BAD_PATH); + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_CREATE)); + (void) printf(gettext("\tgroup must be specified.\n")); + return (SA_BAD_PATH); } if ((optind + 1) < argc) { - (void) printf(gettext("usage: %s\n"), sa_get_usage(USAGE_CREATE)); - (void) printf(gettext("\textraneous group(s) at end\n")); - return (SA_SYNTAX_ERR); + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_CREATE)); + (void) printf(gettext("\textraneous group(s) at end\n")); + return (SA_SYNTAX_ERR); } if (protocol == NULL && optlist != NULL) { - /* lookup default protocol */ - (void) printf(gettext("usage: %s\n"), sa_get_usage(USAGE_CREATE)); - (void) printf(gettext("\tprotocol must be specified " - "with properties\n")); - return (SA_INVALID_PROTOCOL); + /* lookup default protocol */ + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_CREATE)); + (void) printf(gettext("\tprotocol must be specified " + "with properties\n")); + return (SA_INVALID_PROTOCOL); } if (optlist != NULL) - ret = chk_opt(optlist, 0, protocol); + ret = chk_opt(optlist, 0, protocol); if (ret == OPT_ADD_SECURITY) { - (void) printf(gettext("Security properties not " - "supported with create\n")); - return (SA_SYNTAX_ERR); + (void) printf(gettext("Security properties not " + "supported with create\n")); + return (SA_SYNTAX_ERR); } /* - * if a group already exists, we can only add a new protocol + * If a group already exists, we can only add a new protocol * to it and not create a new one or add the same protocol * again. */ @@ -658,85 +673,92 @@ sa_create(sa_handle_t handle, int flags, int argc, char *argv[]) group = sa_get_group(handle, groupname); if (group != NULL) { - /* group exists so must be a protocol add */ - if (protocol != NULL) { - if (has_protocol(group, protocol)) { - (void) printf(gettext("Group \"%s\" already exists" - " with protocol %s\n"), - groupname, protocol); - ret = SA_DUPLICATE_NAME; - } - } else { - /* must add new protocol */ - (void) printf(gettext("Group already exists and no protocol" - " specified.\n")); - ret = SA_DUPLICATE_NAME; - } + /* group exists so must be a protocol add */ + if (protocol != NULL) { + if (has_protocol(group, protocol)) { + (void) printf(gettext( + "Group \"%s\" already exists" + " with protocol %s\n"), groupname, + protocol); + ret = SA_DUPLICATE_NAME; + } + } else { + /* must add new protocol */ + (void) printf(gettext( + "Group already exists and no protocol " + "specified.\n")); + ret = SA_DUPLICATE_NAME; + } } else { /* * is it a valid name? Must comply with SMF instance * name restrictions. */ - if (!sa_valid_group_name(groupname)) { - ret = SA_INVALID_NAME; - (void) printf(gettext("Invalid group name: %s\n"), groupname); - } + if (!sa_valid_group_name(groupname)) { + ret = SA_INVALID_NAME; + (void) printf(gettext("Invalid group name: %s\n"), + groupname); + } } if (ret == SA_OK) { - /* check protocol vs optlist */ - if (optlist != NULL) { - /* check options, if any, for validity */ - ret = valid_options(optlist, protocol, group, NULL); - } + /* check protocol vs optlist */ + if (optlist != NULL) { + /* check options, if any, for validity */ + ret = valid_options(optlist, protocol, group, NULL); + } } if (ret == SA_OK && !dryrun) { - if (group == NULL) { - group = sa_create_group(handle, (char *)groupname, &err); - } - if (group != NULL) { - sa_optionset_t optionset; - if (optlist != NULL) { - (void) add_optionset(group, optlist, protocol, &ret); - } else if (protocol != NULL) { - optionset = sa_create_optionset(group, protocol); - if (optionset == NULL) - ret = SA_NO_MEMORY; - } else if (protocol == NULL) { - char **protolist; - int numprotos, i; - numprotos = sa_get_protocols(&protolist); - for (i = 0; i < numprotos; i++) { - optionset = sa_create_optionset(group, protolist[i]); - } - if (protolist != NULL) - free(protolist); + if (group == NULL) { + group = sa_create_group(handle, (char *)groupname, + &err); } - /* - * we have a group and legal additions - */ - if (ret == SA_OK) { + if (group != NULL) { + sa_optionset_t optionset; + if (optlist != NULL) { + (void) add_optionset(group, optlist, protocol, + &ret); + } else if (protocol != NULL) { + optionset = sa_create_optionset(group, + protocol); + if (optionset == NULL) + ret = SA_NO_MEMORY; + } else if (protocol == NULL) { + char **protolist; + int numprotos, i; + numprotos = sa_get_protocols(&protolist); + for (i = 0; i < numprotos; i++) { + optionset = sa_create_optionset(group, + protolist[i]); + } + if (protolist != NULL) + free(protolist); + } /* - * commit to configuration for protocols that - * need to do block updates. For NFS, this - * doesn't do anything but it will be run for - * all protocols that implement the - * appropriate plugin. + * We have a group and legal additions */ - ret = sa_update_config(handle); + if (ret == SA_OK) { + /* + * Commit to configuration for protocols that + * need to do block updates. For NFS, this + * doesn't do anything but it will be run for + * all protocols that implement the + * appropriate plugin. + */ + ret = sa_update_config(handle); + } else { + if (group != NULL) + (void) sa_remove_group(group); + } } else { - if (group != NULL) - (void) sa_remove_group(group); + ret = err; + (void) printf(gettext("Could not create group: %s\n"), + sa_errorstr(ret)); } - } else { - ret = err; - (void) printf(gettext("Could not create group: %s\n"), - sa_errorstr(ret)); - } } if (dryrun && ret == SA_OK && !auth && verbose) { - (void) printf(gettext("Command would fail: %s\n"), - sa_errorstr(SA_NO_PERMISSION)); - ret = SA_NO_PERMISSION; + (void) printf(gettext("Command would fail: %s\n"), + sa_errorstr(SA_NO_PERMISSION)); + ret = SA_NO_PERMISSION; } free_opt(optlist); return (ret); @@ -756,10 +778,10 @@ group_status(sa_group_t group) state = sa_get_group_attr(group, "state"); if (state != NULL) { - if (strcmp(state, "enabled") == 0) { - enabled = 1; - } - sa_free_attr_string(state); + if (strcmp(state, "enabled") == 0) { + enabled = 1; + } + sa_free_attr_string(state); } return (enabled ? "enabled" : "disabled"); } @@ -786,53 +808,56 @@ sa_delete(sa_handle_t handle, int flags, int argc, char *argv[]) int auth; while ((c = getopt(argc, argv, "?hvnP:fS:")) != EOF) { - switch (c) { - case 'v': - verbose++; - break; - case 'n': - dryrun++; - break; - case 'P': - protocol = optarg; - if (!sa_valid_protocol(protocol)) { - (void) printf(gettext("Invalid protocol specified: %s\n"), - protocol); - return (SA_INVALID_PROTOCOL); + switch (c) { + case 'v': + verbose++; + break; + case 'n': + dryrun++; + break; + case 'P': + protocol = optarg; + if (!sa_valid_protocol(protocol)) { + (void) printf(gettext("Invalid protocol " + "specified: %s\n"), protocol); + return (SA_INVALID_PROTOCOL); + } + break; + case 'S': + sectype = optarg; + break; + case 'f': + force++; + break; + default: + case 'h': + case '?': + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_DELETE)); + return (0); } - break; - case 'S': - sectype = optarg; - break; - case 'f': - force++; - break; - default: - case 'h': - case '?': - (void) printf(gettext("usage: %s\n"), - sa_get_usage(USAGE_DELETE)); - return (0); - } } if (optind >= argc) { - (void) printf(gettext("usage: %s\n"), sa_get_usage(USAGE_DELETE)); - (void) printf(gettext("\tgroup must be specified.\n")); - return (SA_SYNTAX_ERR); + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_DELETE)); + (void) printf(gettext("\tgroup must be specified.\n")); + return (SA_SYNTAX_ERR); } if ((optind + 1) < argc) { - (void) printf(gettext("usage: %s\n"), sa_get_usage(USAGE_DELETE)); - (void) printf(gettext("\textraneous group(s) at end\n")); - return (SA_SYNTAX_ERR); + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_DELETE)); + (void) printf(gettext("\textraneous group(s) at end\n")); + return (SA_SYNTAX_ERR); } if (sectype != NULL && protocol == NULL) { - (void) printf(gettext("usage: %s\n"), sa_get_usage(USAGE_DELETE)); - (void) printf(gettext("\tsecurity requires protocol to be " - "specified.\n")); - return (SA_SYNTAX_ERR); + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_DELETE)); + (void) printf(gettext("\tsecurity requires protocol to be " + "specified.\n")); + return (SA_SYNTAX_ERR); } /* @@ -850,81 +875,89 @@ sa_delete(sa_handle_t handle, int flags, int argc, char *argv[]) group = sa_get_group(handle, groupname); if (group == NULL) { ret = SA_NO_SUCH_GROUP; - } else { - auth = check_authorizations(groupname, flags); - if (protocol == NULL) { + goto done; + } + auth = check_authorizations(groupname, flags); + if (protocol == NULL) { share = sa_get_share(group, NULL); if (share != NULL) - ret = SA_BUSY; + ret = SA_BUSY; if (share == NULL || (share != NULL && force == 1)) { - ret = SA_OK; - if (!dryrun) { - while (share != NULL) { - sa_share_t next_share; - next_share = sa_get_next_share(share); - /* - * need to do the disable of each - * share, but don't actually do - * anything on a dryrun. - */ - ret = sa_disable_share(share, NULL); - ret = sa_remove_share(share); - share = next_share; + ret = SA_OK; + if (!dryrun) { + while (share != NULL) { + sa_share_t next_share; + next_share = sa_get_next_share(share); + /* + * need to do the disable of + * each share, but don't + * actually do anything on a + * dryrun. + */ + ret = sa_disable_share(share, NULL); + ret = sa_remove_share(share); + share = next_share; + } + ret = sa_remove_group(group); } - ret = sa_remove_group(group); - } } - /* commit to configuration if not a dryrun */ + /* Commit to configuration if not a dryrun */ if (!dryrun && ret == SA_OK) { - ret = sa_update_config(handle); + ret = sa_update_config(handle); } - } else { + } else { /* a protocol delete */ sa_optionset_t optionset; sa_security_t security; - if (sectype != NULL) { - /* only delete specified security */ - security = sa_get_security(group, sectype, protocol); - if (security != NULL && !dryrun) { - ret = sa_destroy_security(security); - } else { - ret = SA_INVALID_PROTOCOL; - } - } else { - optionset = sa_get_optionset(group, protocol); - if (optionset != NULL && !dryrun) { - /* have an optionset with protocol to delete */ - ret = sa_destroy_optionset(optionset); - /* - * now find all security sets for the protocol - * and remove them. Don't remove other - * protocols. - */ - for (security = sa_get_security(group, NULL, NULL); - ret == SA_OK && security != NULL; - security = sa_get_next_security(security)) { - char *secprot; - - secprot = sa_get_security_attr(security, "type"); - if (secprot != NULL && - strcmp(secprot, protocol) == 0) + if (sectype != NULL) { + /* only delete specified security */ + security = sa_get_security(group, sectype, protocol); + if (security != NULL && !dryrun) ret = sa_destroy_security(security); - if (secprot != NULL) - sa_free_attr_string(secprot); + else + ret = SA_INVALID_PROTOCOL; + } else { + optionset = sa_get_optionset(group, protocol); + if (optionset != NULL && !dryrun) { + /* + * have an optionset with + * protocol to delete + */ + ret = sa_destroy_optionset(optionset); + /* + * Now find all security sets + * for the protocol and remove + * them. Don't remove other + * protocols. + */ + for (security = + sa_get_security(group, NULL, NULL); + ret == SA_OK && security != NULL; + security = sa_get_next_security(security)) { + char *secprot; + secprot = sa_get_security_attr(security, + "type"); + if (secprot != NULL && + strcmp(secprot, protocol) == 0) + ret = sa_destroy_security( + security); + if (secprot != NULL) + sa_free_attr_string(secprot); + } + } else { + if (!dryrun) + ret = SA_INVALID_PROTOCOL; } - } else { - if (!dryrun) - ret = SA_INVALID_PROTOCOL; - } } - } } + +done: if (ret != SA_OK) { - (void) printf(gettext("Could not delete group: %s\n"), - sa_errorstr(ret)); + (void) printf(gettext("Could not delete group: %s\n"), + sa_errorstr(ret)); } else if (dryrun && !auth && verbose) { - (void) printf(gettext("Command would fail: %s\n"), - sa_errorstr(SA_NO_PERMISSION)); + (void) printf(gettext("Command would fail: %s\n"), + sa_errorstr(SA_NO_PERMISSION)); } return (ret); } @@ -942,23 +975,23 @@ strndupr(char *buff, char *str, int *buffsize) char *orig_buff = buff; if (buff == NULL) { - buff = (char *)malloc(64); - if (buff == NULL) - return (NULL); - *buffsize = 64; - buff[0] = '\0'; + buff = (char *)malloc(64); + if (buff == NULL) + return (NULL); + *buffsize = 64; + buff[0] = '\0'; } limit = strlen(buff) + strlen(str) + 1; if (limit > *buffsize) { - limit = *buffsize = *buffsize + ((limit / 64) + 64); - buff = realloc(buff, limit); + limit = *buffsize = *buffsize + ((limit / 64) + 64); + buff = realloc(buff, limit); } if (buff != NULL) { - (void) strcat(buff, str); + (void) strcat(buff, str); } else { - /* if it fails, fail it hard */ - if (orig_buff != NULL) - free(orig_buff); + /* if it fails, fail it hard */ + if (orig_buff != NULL) + free(orig_buff); } return (buff); } @@ -985,22 +1018,22 @@ group_proto(sa_group_t group) */ buff = strndupr(buff, "", &buffsize); if (buff != NULL) { - for (optionset = sa_get_optionset(group, NULL); - optionset != NULL && buff != NULL; - optionset = sa_get_next_optionset(optionset)) { - /* - * extract out the protocol type from this optionset - * and append it to the buffer "buff". strndupr() will - * reallocate space as necessay. - */ - proto = sa_get_optionset_attr(optionset, "type"); - if (proto != NULL) { - if (addspace++) - buff = strndupr(buff, " ", &buffsize); - buff = strndupr(buff, proto, &buffsize); - sa_free_attr_string(proto); + for (optionset = sa_get_optionset(group, NULL); + optionset != NULL && buff != NULL; + optionset = sa_get_next_optionset(optionset)) { + /* + * extract out the protocol type from this optionset + * and append it to the buffer "buff". strndupr() will + * reallocate space as necessay. + */ + proto = sa_get_optionset_attr(optionset, "type"); + if (proto != NULL) { + if (addspace++) + buff = strndupr(buff, " ", &buffsize); + buff = strndupr(buff, proto, &buffsize); + sa_free_attr_string(proto); + } } - } } return (buff); } @@ -1012,6 +1045,7 @@ group_proto(sa_group_t group) * their state and protocols. */ +/*ARGSUSED*/ static int sa_list(sa_handle_t handle, int flags, int argc, char *argv[]) { @@ -1019,60 +1053,62 @@ sa_list(sa_handle_t handle, int flags, int argc, char *argv[]) int verbose = 0; int c; char *protocol = NULL; -#ifdef lint - flags = flags; -#endif while ((c = getopt(argc, argv, "?hvP:")) != EOF) { - switch (c) { - case 'v': - verbose++; - break; - case 'P': - protocol = optarg; - if (!sa_valid_protocol(protocol)) { - (void) printf(gettext("Invalid protocol specified:" - "%s\n"), - protocol); - return (SA_INVALID_PROTOCOL); + switch (c) { + case 'v': + verbose++; + break; + case 'P': + protocol = optarg; + if (!sa_valid_protocol(protocol)) { + (void) printf(gettext( + "Invalid protocol specified: %s\n"), + protocol); + return (SA_INVALID_PROTOCOL); + } + break; + default: + case 'h': + case '?': + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_LIST)); + return (0); } - break; - default: - case 'h': - case '?': - (void) printf(gettext("usage: %s\n"), sa_get_usage(USAGE_LIST)); - return (0); - } } - for (group = sa_get_group(handle, NULL); group != NULL; + for (group = sa_get_group(handle, NULL); + group != NULL; group = sa_get_next_group(group)) { - char *name; - char *proto; - if (protocol == NULL || has_protocol(group, protocol)) { - name = sa_get_group_attr(group, "name"); - if (name != NULL && (verbose > 1 || name[0] != '#')) { - (void) printf("%s", (char *)name); - if (verbose) { - /* - * need the list of protocols and current - * status once available. We do want to - * translate the enabled/disabled text here. - */ - (void) printf("\t%s", isenabled(group) ? - gettext("enabled") : - gettext("disabled")); - proto = group_proto(group); - if (proto != NULL) { - (void) printf("\t%s", (char *)proto); - free(proto); + char *name; + char *proto; + if (protocol == NULL || has_protocol(group, protocol)) { + name = sa_get_group_attr(group, "name"); + if (name != NULL && (verbose > 1 || name[0] != '#')) { + (void) printf("%s", (char *)name); + if (verbose) { + /* + * Need the list of protocols + * and current status once + * available. We do want to + * translate the + * enabled/disabled text here. + */ + (void) printf("\t%s", isenabled(group) ? + gettext("enabled") : + gettext("disabled")); + proto = group_proto(group); + if (proto != NULL) { + (void) printf("\t%s", + (char *)proto); + free(proto); + } + } + (void) printf("\n"); } - } - (void) printf("\n"); + if (name != NULL) + sa_free_attr_string(name); } - if (name != NULL) - sa_free_attr_string(name); - } } return (0); } @@ -1094,14 +1130,14 @@ out_properties(sa_optionset_t optionset, char *proto, char *sec) int spacer; sa_property_t prop; - if (sec == NULL) { - (void) printf(" %s=(", proto ? proto : gettext("all")); - } else { - (void) printf(" %s:%s=(", proto ? proto : gettext("all"), sec); - } + if (sec == NULL) + (void) printf(" %s=(", proto ? proto : gettext("all")); + else + (void) printf(" %s:%s=(", proto ? proto : gettext("all"), sec); for (spacer = 0, prop = sa_get_property(optionset, NULL); - prop != NULL; prop = sa_get_next_property(prop)) { + prop != NULL; + prop = sa_get_next_property(prop)) { /* * extract the property name/value and output with @@ -1109,20 +1145,20 @@ out_properties(sa_optionset_t optionset, char *proto, char *sec) * first time through but a space on subsequent * properties. */ - type = sa_get_property_attr(prop, "type"); - value = sa_get_property_attr(prop, "value"); - if (type != NULL) { - (void) printf("%s%s=", spacer ? " " : "", type); - spacer = 1; + type = sa_get_property_attr(prop, "type"); + value = sa_get_property_attr(prop, "value"); + if (type != NULL) { + (void) printf("%s%s=", spacer ? " " : "", type); + spacer = 1; + if (value != NULL) + (void) printf("\"%s\"", value); + else + (void) printf("\"\""); + } + if (type != NULL) + sa_free_attr_string(type); if (value != NULL) - (void) printf("\"%s\"", value); - else - (void) printf("\"\""); - } - if (type != NULL) - sa_free_attr_string(type); - if (value != NULL) - sa_free_attr_string(value); + sa_free_attr_string(value); } (void) printf(")"); } @@ -1149,44 +1185,44 @@ show_properties(sa_group_t group, char *protocol, char *prefix) char *secvalue; if (protocol != NULL) { - optionset = sa_get_optionset(group, protocol); - if (optionset != NULL) { - (void) printf("%s", prefix); - prefix = ""; - out_properties(optionset, protocol, NULL); - } - security = sa_get_security(group, protocol, NULL); - if (security != NULL) { - (void) printf("%s", prefix); - prefix = ""; - out_properties(security, protocol, NULL); - } + optionset = sa_get_optionset(group, protocol); + if (optionset != NULL) { + (void) printf("%s", prefix); + prefix = ""; + out_properties(optionset, protocol, NULL); + } + security = sa_get_security(group, protocol, NULL); + if (security != NULL) { + (void) printf("%s", prefix); + prefix = ""; + out_properties(security, protocol, NULL); + } } else { - for (optionset = sa_get_optionset(group, protocol); - optionset != NULL; - optionset = sa_get_next_optionset(optionset)) { - - value = sa_get_optionset_attr(optionset, "type"); - (void) printf("%s", prefix); - prefix = ""; - out_properties(optionset, value, 0); - if (value != NULL) - sa_free_attr_string(value); - } - for (security = sa_get_security(group, NULL, protocol); - security != NULL; - security = sa_get_next_security(security)) { - - value = sa_get_security_attr(security, "type"); - secvalue = sa_get_security_attr(security, "sectype"); - (void) printf("%s", prefix); - prefix = ""; - out_properties(security, value, secvalue); - if (value != NULL) - sa_free_attr_string(value); - if (secvalue != NULL) - sa_free_attr_string(secvalue); - } + for (optionset = sa_get_optionset(group, protocol); + optionset != NULL; + optionset = sa_get_next_optionset(optionset)) { + + value = sa_get_optionset_attr(optionset, "type"); + (void) printf("%s", prefix); + prefix = ""; + out_properties(optionset, value, 0); + if (value != NULL) + sa_free_attr_string(value); + } + for (security = sa_get_security(group, NULL, protocol); + security != NULL; + security = sa_get_next_security(security)) { + + value = sa_get_security_attr(security, "type"); + secvalue = sa_get_security_attr(security, "sectype"); + (void) printf("%s", prefix); + prefix = ""; + out_properties(security, value, secvalue); + if (value != NULL) + sa_free_attr_string(value); + if (secvalue != NULL) + sa_free_attr_string(secvalue); + } } } @@ -1211,10 +1247,10 @@ show_group(sa_group_t group, int verbose, int properties, char *proto, groupname = sa_get_group_attr(group, "name"); if (groupname != NULL) { - if (proto != NULL && !has_protocol(group, proto)) { - sa_free_attr_string(groupname); - return; - } + if (proto != NULL && !has_protocol(group, proto)) { + sa_free_attr_string(groupname); + return; + } /* * check to see if the group is managed by ZFS. If * there is an attribute, then it is. A non-NULL zfs @@ -1222,73 +1258,85 @@ show_group(sa_group_t group, int verbose, int properties, char *proto, * and will remove the transient property indicator * from the output. */ - zfs = sa_get_group_attr(group, "zfs"); - if (zfs != NULL) { - iszfs = 1; - sa_free_attr_string(zfs); - } - share = sa_get_share(group, NULL); - if (subgroup == NULL) - (void) printf("%s", groupname); - else - (void) printf(" %s/%s", subgroup, groupname); - if (properties) { - show_properties(group, proto, ""); - } - (void) printf("\n"); - if (strcmp(groupname, "zfs") == 0) { - sa_group_t zgroup; - - for (zgroup = sa_get_sub_group(group); zgroup != NULL; - zgroup = sa_get_next_group(zgroup)) { - show_group(zgroup, verbose, properties, proto, "zfs"); + zfs = sa_get_group_attr(group, "zfs"); + if (zfs != NULL) { + iszfs = 1; + sa_free_attr_string(zfs); + } + share = sa_get_share(group, NULL); + if (subgroup == NULL) + (void) printf("%s", groupname); + else + (void) printf(" %s/%s", subgroup, groupname); + if (properties) + show_properties(group, proto, ""); + (void) printf("\n"); + if (strcmp(groupname, "zfs") == 0) { + sa_group_t zgroup; + + for (zgroup = sa_get_sub_group(group); + zgroup != NULL; + zgroup = sa_get_next_group(zgroup)) { + show_group(zgroup, verbose, properties, proto, + "zfs"); + } + sa_free_attr_string(groupname); + return; } - sa_free_attr_string(groupname); - return; - } /* - * have a group, so list the contents. Resource and + * Have a group, so list the contents. Resource and * description are only listed if verbose is set. */ - for (share = sa_get_share(group, NULL); share != NULL; - share = sa_get_next_share(share)) { - sharepath = sa_get_share_attr(share, "path"); - if (sharepath != NULL) { - if (verbose) { - resource = sa_get_share_attr(share, "resource"); - description = sa_get_share_description(share); - type = sa_get_share_attr(share, "type"); - if (type != NULL && !iszfs && - strcmp(type, "transient") == 0) - (void) printf("\t* "); - else - (void) printf("\t "); - if (resource != NULL && strlen(resource) > 0) { - (void) printf("%s=%s", resource, sharepath); - } else { - (void) printf("%s", sharepath); - } - if (resource != NULL) - sa_free_attr_string(resource); - if (properties) - show_properties(share, NULL, "\t"); - if (description != NULL) { - if (strlen(description) > 0) { - (void) printf("\t\"%s\"", description); - } - sa_free_share_description(description); - } - if (type != NULL) - sa_free_attr_string(type); - } else { - (void) printf("\t%s", sharepath); - if (properties) - show_properties(share, NULL, "\t"); - } - (void) printf("\n"); - sa_free_attr_string(sharepath); - } - } + for (share = sa_get_share(group, NULL); + share != NULL; + share = sa_get_next_share(share)) { + sharepath = sa_get_share_attr(share, "path"); + if (sharepath != NULL) { + if (verbose) { + resource = sa_get_share_attr(share, + "resource"); + description = + sa_get_share_description(share); + type = sa_get_share_attr(share, + "type"); + if (type != NULL && !iszfs && + strcmp(type, "transient") == 0) + (void) printf("\t* "); + else + (void) printf("\t "); + if (resource != NULL && + strlen(resource) > 0) { + (void) printf("%s=%s", + resource, sharepath); + } else { + (void) printf("%s", sharepath); + } + if (resource != NULL) + sa_free_attr_string(resource); + if (properties) + show_properties(share, NULL, + "\t"); + if (description != NULL) { + if (strlen(description) > 0) { + (void) printf( + "\t\"%s\"", + description); + } + sa_free_share_description( + description); + } + if (type != NULL) + sa_free_attr_string(type); + } else { + (void) printf("\t%s", sharepath); + if (properties) + show_properties(share, NULL, + "\t"); + } + (void) printf("\n"); + sa_free_attr_string(sharepath); + } + } } if (groupname != NULL) { sa_free_attr_string(groupname); @@ -1310,9 +1358,9 @@ show_group_xml_init() doc = xmlNewDoc((xmlChar *)"1.0"); if (doc != NULL) { - root = xmlNewNode(NULL, (xmlChar *)"sharecfg"); - if (root != NULL) - xmlDocSetRootElement(doc, root); + root = xmlNewNode(NULL, (xmlChar *)"sharecfg"); + if (root != NULL) + xmlDocSetRootElement(doc, root); } return (doc); } @@ -1332,7 +1380,7 @@ show_group_xml(xmlDocPtr doc, sa_group_t group) root = xmlDocGetRootElement(doc); node = xmlCopyNode((xmlNodePtr)group, 1); if (node != NULL && root != NULL) { - xmlAddChild(root, node); + xmlAddChild(root, node); /* * In the future, we may have interally used tags that * should not appear in the XML output. Remove @@ -1347,6 +1395,7 @@ show_group_xml(xmlDocPtr doc, sa_group_t group) * Implements the show subcommand. */ +/*ARGSUSED*/ int sa_show(sa_handle_t handle, int flags, int argc, char *argv[]) { @@ -1358,74 +1407,77 @@ sa_show(sa_handle_t handle, int flags, int argc, char *argv[]) char *protocol = NULL; int xml = 0; xmlDocPtr doc; -#ifdef lint - flags = flags; -#endif while ((c = getopt(argc, argv, "?hvP:px")) != EOF) { - switch (c) { - case 'v': - verbose++; - break; - case 'p': - properties++; - break; - case 'P': - protocol = optarg; - if (!sa_valid_protocol(protocol)) { - (void) printf(gettext("Invalid protocol specified: %s\n"), - protocol); - return (SA_INVALID_PROTOCOL); + switch (c) { + case 'v': + verbose++; + break; + case 'p': + properties++; + break; + case 'P': + protocol = optarg; + if (!sa_valid_protocol(protocol)) { + (void) printf(gettext( + "Invalid protocol specified: %s\n"), + protocol); + return (SA_INVALID_PROTOCOL); + } + break; + case 'x': + xml++; + break; + default: + case 'h': + case '?': + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_SHOW)); + return (0); } - break; - case 'x': - xml++; - break; - default: - case 'h': - case '?': - (void) printf(gettext("usage: %s\n"), sa_get_usage(USAGE_SHOW)); - return (0); - } } if (xml) { - doc = show_group_xml_init(); - if (doc == NULL) - ret = SA_NO_MEMORY; + doc = show_group_xml_init(); + if (doc == NULL) + ret = SA_NO_MEMORY; } if (optind == argc) { - /* no group specified so go through them all */ - for (group = sa_get_group(handle, NULL); group != NULL; - group = sa_get_next_group(group)) { - /* - * have a group so check if one we want and then list - * contents with appropriate options. - */ - if (xml) - show_group_xml(doc, group); - else - show_group(group, verbose, properties, protocol, NULL); - } + /* No group specified so go through them all */ + for (group = sa_get_group(handle, NULL); + group != NULL; + group = sa_get_next_group(group)) { + /* + * Have a group so check if one we want and then list + * contents with appropriate options. + */ + if (xml) + show_group_xml(doc, group); + else + show_group(group, verbose, properties, protocol, + NULL); + } } else { - /* have a specified list of groups */ - for (; optind < argc; optind++) { - group = sa_get_group(handle, argv[optind]); - if (group != NULL) { - if (xml) - show_group_xml(doc, group); - else - show_group(group, verbose, properties, protocol, NULL); - } else { - (void) printf(gettext("%s: not found\n"), argv[optind]); - ret = SA_NO_SUCH_GROUP; + /* Have a specified list of groups */ + for (; optind < argc; optind++) { + group = sa_get_group(handle, argv[optind]); + if (group != NULL) { + if (xml) + show_group_xml(doc, group); + else + show_group(group, verbose, properties, + protocol, NULL); + } else { + (void) printf(gettext("%s: not found\n"), + argv[optind]); + ret = SA_NO_SUCH_GROUP; + } } - } } if (xml && ret == SA_OK) { - xmlDocFormatDump(stdout, doc, 1); - xmlFreeDoc(doc); + xmlDocFormatDump(stdout, doc, 1); + xmlFreeDoc(doc); } return (ret); @@ -1456,14 +1508,14 @@ enable_share(sa_handle_t handle, sa_group_t group, sa_share_t share, value = sa_get_group_attr(group, "state"); enabled = value != NULL && strcmp(value, "enabled") == 0; if (value != NULL) - sa_free_attr_string(value); + sa_free_attr_string(value); /* remove legacy config if necessary */ if (update_legacy) - ret = sa_delete_legacy(share); + ret = sa_delete_legacy(share); zfs = sa_get_group_attr(group, "zfs"); if (zfs != NULL) { - iszfs++; - sa_free_attr_string(zfs); + iszfs++; + sa_free_attr_string(zfs); } /* @@ -1475,17 +1527,17 @@ enable_share(sa_handle_t handle, sa_group_t group, sa_share_t share, for (optionset = sa_get_optionset(group, NULL); optionset != NULL && ret == SA_OK; optionset = sa_get_next_optionset(optionset)) { - value = sa_get_optionset_attr(optionset, "type"); - if (value != NULL) { - if (enabled) - ret = sa_enable_share(share, value); - if (update_legacy && !iszfs) - (void) sa_update_legacy(share, value); - sa_free_attr_string(value); - } + value = sa_get_optionset_attr(optionset, "type"); + if (value != NULL) { + if (enabled) + ret = sa_enable_share(share, value); + if (update_legacy && !iszfs) + (void) sa_update_legacy(share, value); + sa_free_attr_string(value); + } } if (ret == SA_OK) - (void) sa_update_config(handle); + (void) sa_update_config(handle); return (ret); } @@ -1512,169 +1564,170 @@ sa_addshare(sa_handle_t handle, int flags, int argc, char *argv[]) char dir[MAXPATHLEN]; while ((c = getopt(argc, argv, "?hvns:d:r:t")) != EOF) { - switch (c) { - case 'n': - dryrun++; - break; - case 'v': - verbose++; - break; - case 'd': - description = optarg; - break; - case 'r': - resource = optarg; - break; - case 's': - /* - * save share path into group. Currently limit - * to one share per command. - */ - if (sharepath != NULL) { - (void) printf(gettext("Adding multiple shares not" - "supported\n")); - return (1); + switch (c) { + case 'n': + dryrun++; + break; + case 'v': + verbose++; + break; + case 'd': + description = optarg; + break; + case 'r': + resource = optarg; + break; + case 's': + /* + * Save share path into group. Currently limit + * to one share per command. + */ + if (sharepath != NULL) { + (void) printf(gettext( + "Adding multiple shares not supported\n")); + return (1); + } + sharepath = optarg; + break; + case 't': + persist = SA_SHARE_TRANSIENT; + break; + default: + case 'h': + case '?': + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_ADD_SHARE)); + return (0); } - sharepath = optarg; - break; - case 't': - persist = SA_SHARE_TRANSIENT; - break; - default: - case 'h': - case '?': - (void) printf(gettext("usage: %s\n"), - sa_get_usage(USAGE_ADD_SHARE)); - return (0); - } } if (optind >= argc) { - (void) printf(gettext("usage: %s\n"), - sa_get_usage(USAGE_ADD_SHARE)); - if (dryrun || sharepath != NULL || description != NULL || - resource != NULL || verbose || persist) { - (void) printf(gettext("\tgroup must be specified\n")); - ret = SA_NO_SUCH_GROUP; - } else { - ret = SA_OK; - } - } else { - if (sharepath == NULL) { (void) printf(gettext("usage: %s\n"), - sa_get_usage(USAGE_ADD_SHARE)); - (void) printf(gettext("\t-s sharepath must be specified\n")); - ret = SA_BAD_PATH; - } - if (ret == SA_OK) { + sa_get_usage(USAGE_ADD_SHARE)); + if (dryrun || sharepath != NULL || description != NULL || + resource != NULL || verbose || persist) { + (void) printf(gettext("\tgroup must be specified\n")); + ret = SA_NO_SUCH_GROUP; + } else { + ret = SA_OK; + } + } else { + if (sharepath == NULL) { + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_ADD_SHARE)); + (void) printf(gettext( + "\t-s sharepath must be specified\n")); + return (SA_BAD_PATH); + } if (realpath(sharepath, dir) == NULL) { - ret = SA_BAD_PATH; - (void) printf(gettext("Path is not valid: %s\n"), - sharepath); + (void) printf(gettext( + "Path is not valid: %s\n"), sharepath); + return (SA_BAD_PATH); } else { - sharepath = dir; - } - } - if (ret == SA_OK && resource != NULL) { - /* check for valid syntax */ - if (strpbrk(resource, " \t/") != NULL) { - (void) printf(gettext("usage: %s\n"), - sa_get_usage(USAGE_ADD_SHARE)); - (void) printf(gettext("\tresource must not contain white" - "space or '/' characters\n")); - ret = SA_BAD_PATH; - } - } - if (ret == SA_OK) { + sharepath = dir; + } + + /* Check for valid syntax */ + if (resource != NULL && strpbrk(resource, " \t/") != NULL) { + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_ADD_SHARE)); + (void) printf(gettext( + "\tresource must not contain white" + "space or '/' characters\n")); + return (SA_BAD_PATH); + } group = sa_get_group(handle, argv[optind]); - if (group != NULL) { - auth = check_authorizations(argv[optind], flags); - share = sa_find_share(handle, sharepath); - if (share != NULL) { + if (group == NULL) { + (void) printf(gettext("Group \"%s\" not found\n"), + argv[optind]); + return (SA_NO_SUCH_GROUP); + } + auth = check_authorizations(argv[optind], flags); + share = sa_find_share(handle, sharepath); + if (share != NULL) { group = sa_get_parent_group(share); if (group != NULL) { - char *groupname; - groupname = sa_get_group_attr(group, "name"); - if (groupname != NULL) { - (void) printf(gettext("Share path already " - "shared in group " - "\"%s\": %s\n"), - groupname, sharepath); - sa_free_attr_string(groupname); - } else { - (void) printf(gettext("Share path already" - "shared: %s\n"), - groupname, sharepath); - } + char *groupname; + groupname = sa_get_group_attr( + group, "name"); + if (groupname != NULL) { + (void) printf(gettext( + "Share path already " + "shared in group " + "\"%s\": %s\n"), + groupname, sharepath); + sa_free_attr_string(groupname); + } else { + (void) printf(gettext( + "Share path already" + "shared: %s\n"), + groupname, sharepath); + } } else { - (void) printf(gettext("Share path %s already " - "shared\n"), + (void) printf(gettext( + "Share path %s already shared\n"), sharepath); } - ret = SA_DUPLICATE_NAME; - } else { + return (SA_DUPLICATE_NAME); + } else { /* - * need to check that resource name is unique - * at some point. Path checking should use the - * "normal" rules which don't check the repository. + * Need to check that resource name is + * unique at some point. Path checking + * should use the "normal" rules which + * don't check the repository. */ if (dryrun) - ret = sa_check_path(group, sharepath, - SA_CHECK_NORMAL); + ret = sa_check_path(group, sharepath, + SA_CHECK_NORMAL); else - share = sa_add_share(group, sharepath, - persist, &ret); + share = sa_add_share(group, sharepath, + persist, &ret); if (!dryrun && share == NULL) { - (void) printf(gettext("Could not add share: " - "%s\n"), - sa_errorstr(ret)); + (void) printf(gettext( + "Could not add share: %s\n"), + sa_errorstr(ret)); } else { - if (!dryrun && ret == SA_OK) { - if (resource != NULL) { - if (strpbrk(resource, " \t/") == NULL) { - ret = sa_set_share_attr(share, - "resource", - resource); - } - } - if (ret == SA_OK && description != NULL) { - ret = sa_set_share_description(share, - description); - } - if (ret == SA_OK) { - /* now enable the share(s) */ - ret = enable_share(handle, group, share, 1); - ret = sa_update_config(handle); - } - switch (ret) { - case SA_DUPLICATE_NAME: - (void) printf(gettext("Resource name in" - "use: %s\n"), - resource); - break; - default: - (void) printf(gettext("Could not set " + if (!dryrun && ret == SA_OK) { + if (resource != NULL && + strpbrk(resource, " \t/") == NULL) { + ret = sa_set_share_attr(share, + "resource", resource); + } + if (ret == SA_OK && + description != NULL) { + ret = sa_set_share_description( + share, description); + } + if (ret == SA_OK) { + /* Now enable the share(s) */ + ret = enable_share(handle, + group, share, 1); + ret = sa_update_config(handle); + } + switch (ret) { + case SA_DUPLICATE_NAME: + (void) printf(gettext( + "Resource name in" + "use: %s\n"), resource); + break; + default: + (void) printf( + gettext("Could not set " "attribute: %s\n"), - sa_errorstr(ret)); - break; - case SA_OK: - break; + sa_errorstr(ret)); + break; + case SA_OK: + break; + } + } else if (dryrun && ret == SA_OK && !auth && + verbose) { + (void) printf(gettext( + "Command would fail: %s\n"), + sa_errorstr(SA_NO_PERMISSION)); + ret = SA_NO_PERMISSION; } - } else if (dryrun && ret == SA_OK && - !auth && verbose) { - (void) printf(gettext("Command would fail: " - "%s\n"), - sa_errorstr(SA_NO_PERMISSION)); - ret = SA_NO_PERMISSION; - } - } - } - } else { - (void) printf(gettext("Group \"%s\" not found\n"), - argv[optind]); - ret = SA_NO_SUCH_GROUP; + } } - } } return (ret); } @@ -1698,123 +1751,127 @@ sa_moveshare(sa_handle_t handle, int flags, int argc, char *argv[]) int authsrc = 0, authdst = 0; while ((c = getopt(argc, argv, "?hvns:")) != EOF) { - switch (c) { - case 'n': - dryrun++; - break; - case 'v': - verbose++; - break; - case 's': - /* - * remove share path from group. Currently limit - * to one share per command. - */ - if (sharepath != NULL) { - (void) printf(gettext("Moving multiple shares not" - "supported\n")); - return (SA_BAD_PATH); + switch (c) { + case 'n': + dryrun++; + break; + case 'v': + verbose++; + break; + case 's': + /* + * Remove share path from group. Currently limit + * to one share per command. + */ + if (sharepath != NULL) { + (void) printf(gettext("Moving multiple shares" + "not supported\n")); + return (SA_BAD_PATH); + } + sharepath = optarg; + break; + default: + case 'h': + case '?': + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_MOVE_SHARE)); + return (0); } - sharepath = optarg; - break; - default: - case 'h': - case '?': - (void) printf(gettext("usage: %s\n"), - sa_get_usage(USAGE_MOVE_SHARE)); - return (0); - } } if (optind >= argc || sharepath == NULL) { (void) printf(gettext("usage: %s\n"), - sa_get_usage(USAGE_MOVE_SHARE)); - if (dryrun || verbose || sharepath != NULL) { - (void) printf(gettext("\tgroup must be specified\n")); - ret = SA_NO_SUCH_GROUP; - } else { - if (sharepath == NULL) { - ret = SA_SYNTAX_ERR; - (void) printf(gettext("\tsharepath must be specified\n")); - } else - ret = SA_OK; - } + sa_get_usage(USAGE_MOVE_SHARE)); + if (dryrun || verbose || sharepath != NULL) { + (void) printf(gettext( + "\tgroup must be specified\n")); + ret = SA_NO_SUCH_GROUP; + } else { + if (sharepath == NULL) { + ret = SA_SYNTAX_ERR; + (void) printf(gettext( + "\tsharepath must be specified\n")); + } else { + ret = SA_OK; + } + } } else { - if (sharepath == NULL) { - (void) printf(gettext("sharepath must be specified with " - "the -s option\n")); - ret = SA_BAD_PATH; - } else { + sa_group_t parent; + char *zfsold; + char *zfsnew; + + if (sharepath == NULL) { + (void) printf(gettext( + "sharepath must be specified with the -s " + "option\n")); + return (SA_BAD_PATH); + } group = sa_get_group(handle, argv[optind]); - if (group != NULL) { - share = sa_find_share(handle, sharepath); - authdst = check_authorizations(argv[optind], flags); - if (share == NULL) { + if (group == NULL) { + (void) printf(gettext("Group \"%s\" not found\n"), + argv[optind]); + return (SA_NO_SUCH_GROUP); + } + share = sa_find_share(handle, sharepath); + authdst = check_authorizations(argv[optind], flags); + if (share == NULL) { (void) printf(gettext("Share not found: %s\n"), - sharepath); - ret = SA_NO_SUCH_PATH; - } else { - sa_group_t parent; - char *zfsold; - char *zfsnew; - - parent = sa_get_parent_group(share); - if (parent != NULL) { - char *pname; - pname = sa_get_group_attr(parent, "name"); - if (pname != NULL) { + sharepath); + return (SA_NO_SUCH_PATH); + } + + parent = sa_get_parent_group(share); + if (parent != NULL) { + char *pname; + pname = sa_get_group_attr(parent, "name"); + if (pname != NULL) { authsrc = check_authorizations(pname, flags); sa_free_attr_string(pname); - } - zfsold = sa_get_group_attr(parent, "zfs"); - zfsnew = sa_get_group_attr(group, "zfs"); - if ((zfsold != NULL && zfsnew == NULL) || - (zfsold == NULL && zfsnew != NULL)) { + } + zfsold = sa_get_group_attr(parent, "zfs"); + zfsnew = sa_get_group_attr(group, "zfs"); + if ((zfsold != NULL && zfsnew == NULL) || + (zfsold == NULL && zfsnew != NULL)) { ret = SA_NOT_ALLOWED; - } - if (zfsold != NULL) + } + if (zfsold != NULL) sa_free_attr_string(zfsold); - if (zfsnew != NULL) + if (zfsnew != NULL) sa_free_attr_string(zfsnew); - } - if (!dryrun && ret == SA_OK) { - ret = sa_move_share(group, share); - } - if (ret == SA_OK && parent != group && !dryrun) { - char *oldstate; - ret = sa_update_config(handle); - /* - * note that the share may need to be - * "unshared" if the new group is - * disabled and the old was enabled or - * it may need to be share to update - * if the new group is enabled. - */ - oldstate = sa_get_group_attr(parent, "state"); - /* enable_share determines what to do */ - if (strcmp(oldstate, "enabled") == 0) { + } + if (!dryrun && ret == SA_OK) + ret = sa_move_share(group, share); + + if (ret == SA_OK && parent != group && !dryrun) { + char *oldstate; + ret = sa_update_config(handle); + /* + * Note that the share may need to be + * "unshared" if the new group is + * disabled and the old was enabled or + * it may need to be share to update + * if the new group is enabled. + */ + oldstate = sa_get_group_attr(parent, "state"); + + /* enable_share determines what to do */ + if (strcmp(oldstate, "enabled") == 0) { (void) sa_disable_share(share, NULL); - } - (void) enable_share(handle, group, share, 1); - if (oldstate != NULL) - sa_free_attr_string(oldstate); } - if (ret != SA_OK) { - (void) printf(gettext("Could not move share: %s\n"), - sa_errorstr(ret)); - } - if (dryrun && ret == SA_OK && !(authsrc & authdst) && - verbose) { - (void) printf(gettext("Command would fail: %s\n"), - sa_errorstr(SA_NO_PERMISSION)); - } - } - } else { - (void) printf(gettext("Group \"%s\" not found\n"), - argv[optind]); - ret = SA_NO_SUCH_GROUP; + (void) enable_share(handle, group, share, 1); + if (oldstate != NULL) + sa_free_attr_string(oldstate); + } + + if (ret != SA_OK) + (void) printf(gettext("Could not move share: %s\n"), + sa_errorstr(ret)); + + if (dryrun && ret == SA_OK && !(authsrc & authdst) && + verbose) { + (void) printf(gettext("Command would fail: %s\n"), + sa_errorstr(SA_NO_PERMISSION)); } - } } return (ret); } @@ -1840,76 +1897,81 @@ sa_removeshare(sa_handle_t handle, int flags, int argc, char *argv[]) int auth; while ((c = getopt(argc, argv, "?hfns:v")) != EOF) { - switch (c) { - case 'n': - dryrun++; - break; - case 'v': - verbose++; - break; - case 'f': - force++; - break; - case 's': - /* - * remove share path from group. Currently limit - * to one share per command. - */ - if (sharepath != NULL) { - (void) printf(gettext("Removing multiple shares not" + switch (c) { + case 'n': + dryrun++; + break; + case 'v': + verbose++; + break; + case 'f': + force++; + break; + case 's': + /* + * Remove share path from group. Currently limit + * to one share per command. + */ + if (sharepath != NULL) { + (void) printf(gettext( + "Removing multiple shares not " "supported\n")); - return (SA_SYNTAX_ERR); + return (SA_SYNTAX_ERR); + } + sharepath = optarg; + break; + default: + case 'h': + case '?': + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_REMOVE_SHARE)); + return (0); } - sharepath = optarg; - break; - default: - case 'h': - case '?': - (void) printf(gettext("usage: %s\n"), - sa_get_usage(USAGE_REMOVE_SHARE)); - return (0); - } } if (optind >= argc || sharepath == NULL) { - if (sharepath == NULL) { + if (sharepath == NULL) { (void) printf(gettext("usage: %s\n"), - sa_get_usage(USAGE_REMOVE_SHARE)); - (void) printf(gettext("\t-s sharepath must be specified\n")); - ret = SA_BAD_PATH; - } else { - ret = SA_OK; - } + sa_get_usage(USAGE_REMOVE_SHARE)); + (void) printf(gettext( + "\t-s sharepath must be specified\n")); + ret = SA_BAD_PATH; + } else { + ret = SA_OK; + } } - if (ret == SA_OK) { - if (optind < argc) { + if (ret != SA_OK) { + return (ret); + } + + if (optind < argc) { if ((optind + 1) < argc) { - (void) printf(gettext("Extraneous group(s) at end of " - "command\n")); - ret = SA_SYNTAX_ERR; + (void) printf(gettext("Extraneous group(s) at end of " + "command\n")); + ret = SA_SYNTAX_ERR; } else { - group = sa_get_group(handle, argv[optind]); - if (group == NULL) { - (void) printf(gettext("Group \"%s\" not found\n"), - argv[optind]); - ret = SA_NO_SUCH_GROUP; - } + group = sa_get_group(handle, argv[optind]); + if (group == NULL) { + (void) printf(gettext( + "Group \"%s\" not found\n"), argv[optind]); + ret = SA_NO_SUCH_GROUP; + } } - } else { + } else { group = NULL; - } + } - /* - * Lookup the path in the internal configuration. Care - * must be taken to handle the case where the - * underlying path has been removed since we need to - * be able to deal with that as well. - */ - if (ret == SA_OK) { + /* + * Lookup the path in the internal configuration. Care + * must be taken to handle the case where the + * underlying path has been removed since we need to + * be able to deal with that as well. + */ + if (ret == SA_OK) { if (group != NULL) - share = sa_get_share(group, sharepath); + share = sa_get_share(group, sharepath); else - share = sa_find_share(handle, sharepath); + share = sa_find_share(handle, sharepath); /* * If we didn't find the share with the provided path, * it may be a symlink so attempt to resolve it using @@ -1921,76 +1983,76 @@ sa_removeshare(sa_handle_t handle, int flags, int argc, char *argv[]) * operations are based off of the share variable. */ if (share == NULL) { - if (realpath(sharepath, dir) == NULL) { - ret = SA_BAD_PATH; - (void) printf(gettext("Path is not valid: %s\n"), - sharepath); - } else { - if (group != NULL) - share = sa_get_share(group, dir); - else - share = sa_find_share(handle, dir); - } + if (realpath(sharepath, dir) == NULL) { + ret = SA_BAD_PATH; + (void) printf(gettext( + "Path is not valid: %s\n"), sharepath); + } else { + if (group != NULL) + share = sa_get_share(group, dir); + else + share = sa_find_share(handle, dir); + } } - } + } - /* - * If there hasn't been an error, there was likely a - * path found. If not, give the appropriate error - * message and set the return error. If it was found, - * then disable the share and then remove it from the - * configuration. - */ - if (ret == SA_OK) { - if (share == NULL) { - if (group != NULL) + /* + * If there hasn't been an error, there was likely a + * path found. If not, give the appropriate error + * message and set the return error. If it was found, + * then disable the share and then remove it from the + * configuration. + */ + if (ret != SA_OK) { + return (ret); + } + if (share == NULL) { + if (group != NULL) (void) printf(gettext("Share not found in group %s:" - " %s\n"), - argv[optind], sharepath); - else + " %s\n"), argv[optind], sharepath); + else (void) printf(gettext("Share not found: %s\n"), - sharepath); - ret = SA_NO_SUCH_PATH; - } else { - if (group == NULL) + sharepath); + ret = SA_NO_SUCH_PATH; + } else { + if (group == NULL) group = sa_get_parent_group(share); - if (!dryrun) { + if (!dryrun) { if (ret == SA_OK) { - ret = sa_disable_share(share, NULL); + ret = sa_disable_share(share, NULL); /* - * we don't care if it fails since it + * We don't care if it fails since it * could be disabled already. Some * unexpected errors could occur that * prevent removal, so also check for * force being set. */ - if (ret == SA_OK || ret == SA_NO_SUCH_PATH || - ret == SA_NOT_SUPPORTED || - ret == SA_SYSTEM_ERR || force) { - ret = sa_remove_share(share); - } - if (ret == SA_OK) - ret = sa_update_config(handle); - } - if (ret != SA_OK) { - (void) printf(gettext("Could not remove share:" - " %s\n"), - sa_errorstr(ret)); + if (ret == SA_OK || ret == SA_NO_SUCH_PATH || + ret == SA_NOT_SUPPORTED || + ret == SA_SYSTEM_ERR || force) { + ret = sa_remove_share(share); + } + if (ret == SA_OK) + ret = sa_update_config(handle); } - } else if (ret == SA_OK) { + if (ret != SA_OK) + (void) printf(gettext( + "Could not remove share: %s\n"), + sa_errorstr(ret)); + + } else if (ret == SA_OK) { char *pname; pname = sa_get_group_attr(group, "name"); if (pname != NULL) { - auth = check_authorizations(pname, flags); - sa_free_attr_string(pname); + auth = check_authorizations(pname, flags); + sa_free_attr_string(pname); } if (!auth && verbose) { - (void) printf(gettext("Command would fail: %s\n"), - sa_errorstr(SA_NO_PERMISSION)); + (void) printf(gettext( + "Command would fail: %s\n"), + sa_errorstr(SA_NO_PERMISSION)); } - } } - } } return (ret); } @@ -2014,136 +2076,137 @@ sa_set_share(sa_handle_t handle, int flags, int argc, char *argv[]) char *resource = NULL; int auth; int verbose = 0; + char *groupname; while ((c = getopt(argc, argv, "?hnd:r:s:")) != EOF) { - switch (c) { - case 'n': - dryrun++; - break; - case 'd': - description = optarg; - break; - case 'r': - resource = optarg; - break; - case 'v': - verbose++; - break; - case 's': - /* - * save share path into group. Currently limit - * to one share per command. - */ - if (sharepath != NULL) { - (void) printf(gettext("Updating multiple shares not" + switch (c) { + case 'n': + dryrun++; + break; + case 'd': + description = optarg; + break; + case 'r': + resource = optarg; + break; + case 'v': + verbose++; + break; + case 's': + /* + * Save share path into group. Currently limit + * to one share per command. + */ + if (sharepath != NULL) { + (void) printf(gettext( + "Updating multiple shares not " "supported\n")); - return (SA_BAD_PATH); + return (SA_BAD_PATH); + } + sharepath = optarg; + break; + default: + case 'h': + case '?': + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_SET_SHARE)); + return (SA_OK); } - sharepath = optarg; - break; - default: - case 'h': - case '?': - (void) printf(gettext("usage: %s\n"), - sa_get_usage(USAGE_SET_SHARE)); - return (SA_OK); - } } + if (optind >= argc || sharepath == NULL) { - if (sharepath == NULL) { - (void) printf(gettext("usage: %s\n"), - sa_get_usage(USAGE_SET_SHARE)); - (void) printf(gettext("\tgroup must be specified\n")); - ret = SA_BAD_PATH; - } else { - ret = SA_OK; - } + if (sharepath == NULL) { + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_SET_SHARE)); + (void) printf(gettext("\tgroup must be specified\n")); + ret = SA_BAD_PATH; + } else { + ret = SA_OK; + } } if ((optind + 1) < argc) { - (void) printf(gettext("usage: %s\n"), - sa_get_usage(USAGE_SET_SHARE)); - (void) printf(gettext("\tExtraneous group(s) at end\n")); - ret = SA_SYNTAX_ERR; + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_SET_SHARE)); + (void) printf(gettext("\tExtraneous group(s) at end\n")); + ret = SA_SYNTAX_ERR; } - if (ret == SA_OK) { - char *groupname; - if (optind < argc) { + + if (ret != SA_OK) + return (ret); + + if (optind < argc) { groupname = argv[optind]; group = sa_get_group(handle, groupname); - } else { + } else { group = NULL; groupname = NULL; - } - share = sa_find_share(handle, sharepath); - if (share != NULL) { - sharegroup = sa_get_parent_group(share); - if (group != NULL && group != sharegroup) { - (void) printf(gettext("Group \"%s\" does not contain " - "share %s\n"), - argv[optind], sharepath); - ret = SA_BAD_PATH; - } else { - int delgroupname = 0; - if (groupname == NULL) { + } + share = sa_find_share(handle, sharepath); + if (share == NULL) { + (void) printf(gettext("Share path \"%s\" not found\n"), + sharepath); + return (SA_NO_SUCH_PATH); + } + sharegroup = sa_get_parent_group(share); + if (group != NULL && group != sharegroup) { + (void) printf(gettext("Group \"%s\" does not contain " + "share %s\n"), argv[optind], sharepath); + ret = SA_BAD_PATH; + } else { + int delgroupname = 0; + if (groupname == NULL) { groupname = sa_get_group_attr(sharegroup, "name"); delgroupname = 1; - } - if (groupname != NULL) { + } + if (groupname != NULL) { auth = check_authorizations(groupname, flags); if (delgroupname) { - sa_free_attr_string(groupname); - groupname = NULL; + sa_free_attr_string(groupname); + groupname = NULL; } - } else { + } else { ret = SA_NO_MEMORY; - } - if (resource != NULL) { + } + if (resource != NULL) { if (strpbrk(resource, " \t/") == NULL) { - if (!dryrun) { - ret = sa_set_share_attr(share, "resource", - resource); - } else { - sa_share_t resshare; - resshare = sa_get_resource(sharegroup, - resource); - if (resshare != NULL && resshare != share) - ret = SA_DUPLICATE_NAME; - } + if (!dryrun) { + ret = sa_set_share_attr(share, + "resource", resource); + } else { + sa_share_t resshare; + resshare = sa_get_resource(sharegroup, + resource); + if (resshare != NULL && + resshare != share) + ret = SA_DUPLICATE_NAME; + } } else { - ret = SA_BAD_PATH; - (void) printf(gettext("Resource must not contain " - "white space or '/'\n")); + ret = SA_BAD_PATH; + (void) printf(gettext("Resource must not " + "contain white space or '/'\n")); } - } - if (ret == SA_OK && description != NULL) { - ret = sa_set_share_description(share, description); - } - } - if (!dryrun && ret == SA_OK) { - ret = sa_update_config(handle); } - switch (ret) { - case SA_DUPLICATE_NAME: - (void) printf(gettext("Resource name in use: %s\n"), - resource); - break; - default: - (void) printf(gettext("Could not set attribute: %s\n"), - sa_errorstr(ret)); - break; - case SA_OK: - if (dryrun && !auth && verbose) { + if (ret == SA_OK && description != NULL) + ret = sa_set_share_description(share, description); + } + if (!dryrun && ret == SA_OK) + ret = sa_update_config(handle); + + switch (ret) { + case SA_DUPLICATE_NAME: + (void) printf(gettext("Resource name in use: %s\n"), resource); + break; + default: + (void) printf(gettext("Could not set attribute: %s\n"), + sa_errorstr(ret)); + break; + case SA_OK: + if (dryrun && !auth && verbose) (void) printf(gettext("Command would fail: %s\n"), - sa_errorstr(SA_NO_PERMISSION)); - } - break; - } - } else { - (void) printf(gettext("Share path \"%s\" not found\n"), - sharepath); - ret = SA_NO_SUCH_PATH; - } + sa_errorstr(SA_NO_PERMISSION)); + break; } + return (ret); } @@ -2164,60 +2227,67 @@ add_security(sa_group_t group, char *sectype, sectype = sa_proto_space_alias(proto, sectype); security = sa_get_security(group, sectype, proto); - if (security == NULL) { - security = sa_create_security(group, sectype, proto); - } + if (security == NULL) + security = sa_create_security(group, sectype, proto); + if (sectype != NULL) - sa_free_attr_string(sectype); - if (security != NULL) { - while (optlist != NULL) { + sa_free_attr_string(sectype); + + if (security == NULL) + return (ret); + + while (optlist != NULL) { sa_property_t prop; prop = sa_get_property(security, optlist->optname); if (prop == NULL) { /* - * add the property, but only if it is + * Add the property, but only if it is * a non-NULL or non-zero length value */ - if (optlist->optvalue != NULL) { - prop = sa_create_property(optlist->optname, - optlist->optvalue); - if (prop != NULL) { - ret = sa_valid_property(security, proto, prop); - if (ret != SA_OK) { - (void) sa_remove_property(prop); - (void) printf(gettext("Could not add " - "property %s: %s\n"), - optlist->optname, - sa_errorstr(ret)); - } - if (ret == SA_OK) { - ret = sa_add_property(security, prop); - if (ret != SA_OK) { - (void) printf(gettext("Could not add " - "property (%s=%s): %s\n"), - optlist->optname, - optlist->optvalue, - sa_errorstr(ret)); - } else { - result = 1; + if (optlist->optvalue != NULL) { + prop = sa_create_property(optlist->optname, + optlist->optvalue); + if (prop != NULL) { + ret = sa_valid_property(security, proto, + prop); + if (ret != SA_OK) { + (void) sa_remove_property(prop); + (void) printf(gettext( + "Could not add " + "property %s: %s\n"), + optlist->optname, + sa_errorstr(ret)); + } + if (ret == SA_OK) { + ret = sa_add_property(security, + prop); + if (ret != SA_OK) { + (void) printf(gettext( + "Could not add " + "property (%s=%s): " + "%s\n"), + optlist->optname, + optlist->optvalue, + sa_errorstr(ret)); + } else { + result = 1; + } + } } - } } - } } else { - ret = sa_update_property(prop, optlist->optvalue); - result = 1; /* should check if really changed */ + ret = sa_update_property(prop, optlist->optvalue); + result = 1; /* should check if really changed */ } optlist = optlist->next; - } - /* - * when done, properties may have all been removed but - * we need to keep the security type itself until - * explicitly removed. - */ - if (result) - ret = sa_commit_properties(security, 0); } + /* + * When done, properties may have all been removed but + * we need to keep the security type itself until + * explicitly removed. + */ + if (result) + ret = sa_commit_properties(security, 0); *err = ret; return (result); } @@ -2241,32 +2311,33 @@ basic_set(sa_handle_t handle, char *groupname, struct options *optlist, group = sa_get_group(handle, groupname); if (group != NULL) { - sa_share_t share = NULL; - if (sharepath != NULL) { - share = sa_get_share(group, sharepath); - if (share == NULL) { - (void) printf(gettext("Share does not exist in group %s\n"), - groupname, sharepath); - ret = SA_NO_SUCH_PATH; + sa_share_t share = NULL; + if (sharepath != NULL) { + share = sa_get_share(group, sharepath); + if (share == NULL) { + (void) printf(gettext( + "Share does not exist in group %s\n"), + groupname, sharepath); + ret = SA_NO_SUCH_PATH; + } } - } - if (ret == SA_OK) { - /* group must exist */ - ret = valid_options(optlist, protocol, - share == NULL ? group : share, NULL); - if (ret == SA_OK && !dryrun) { - if (share != NULL) - change |= add_optionset(share, optlist, protocol, - &ret); - else - change |= add_optionset(group, optlist, protocol, - &ret); - if (ret == SA_OK && change) { - worklist = add_list(worklist, group, share); - } - } - } - free_opt(optlist); + if (ret == SA_OK) { + /* group must exist */ + ret = valid_options(optlist, protocol, + share == NULL ? group : share, NULL); + if (ret == SA_OK && !dryrun) { + if (share != NULL) + change |= add_optionset(share, optlist, + protocol, &ret); + else + change |= add_optionset(group, optlist, + protocol, &ret); + if (ret == SA_OK && change) + worklist = add_list(worklist, group, + share); + } + } + free_opt(optlist); } else { (void) printf(gettext("Group \"%s\" not found\n"), groupname); ret = SA_NO_SUCH_GROUP; @@ -2275,15 +2346,16 @@ basic_set(sa_handle_t handle, char *groupname, struct options *optlist, * we have a group and potentially legal additions */ - /* commit to configuration if not a dryrun */ - if (!dryrun && ret == SA_OK) { - if (change && worklist != NULL) { + /* + * Commit to configuration if not a dryrunp and properties + * have changed. + */ + if (!dryrun && ret == SA_OK && change && worklist != NULL) /* properties changed, so update all shares */ (void) enable_all_groups(handle, worklist, 0, 0, protocol); - } - } + if (worklist != NULL) - free_list(worklist); + free_list(worklist); return (ret); } @@ -2309,44 +2381,43 @@ space_set(sa_handle_t handle, char *groupname, struct options *optlist, */ if (sa_proto_valid_space(protocol, sectype) == 0) { - (void) printf(gettext("Option space \"%s\" not valid " - "for protocol.\n"), - sectype); - return (SA_INVALID_SECURITY); + (void) printf(gettext("Option space \"%s\" not valid " + "for protocol.\n"), sectype); + return (SA_INVALID_SECURITY); } group = sa_get_group(handle, groupname); if (group != NULL) { - sa_share_t share = NULL; - if (sharepath != NULL) { - share = sa_get_share(group, sharepath); - if (share == NULL) { - (void) printf(gettext("Share does not exist in group %s\n"), - groupname, sharepath); - ret = SA_NO_SUCH_PATH; + sa_share_t share = NULL; + if (sharepath != NULL) { + share = sa_get_share(group, sharepath); + if (share == NULL) { + (void) printf(gettext( + "Share does not exist in group %s\n"), + groupname, sharepath); + ret = SA_NO_SUCH_PATH; + } } - } - if (ret == SA_OK) { - /* group must exist */ - ret = valid_options(optlist, protocol, - share == NULL ? group : share, sectype); - if (ret == SA_OK && !dryrun) { - if (share != NULL) - change = add_security(share, sectype, optlist, - protocol, - &ret); - else - change = add_security(group, sectype, optlist, - protocol, - &ret); - if (ret != SA_OK) - (void) printf(gettext("Could not set property: %s\n"), - sa_errorstr(ret)); + if (ret == SA_OK) { + /* group must exist */ + ret = valid_options(optlist, protocol, + share == NULL ? group : share, sectype); + if (ret == SA_OK && !dryrun) { + if (share != NULL) + change = add_security(share, sectype, + optlist, protocol, &ret); + else + change = add_security(group, sectype, + optlist, protocol, &ret); + if (ret != SA_OK) + (void) printf(gettext( + "Could not set property: %s\n"), + sa_errorstr(ret)); + } + if (ret == SA_OK && change) + worklist = add_list(worklist, group, share); } - if (ret == SA_OK && change) - worklist = add_list(worklist, group, share); - } - free_opt(optlist); + free_opt(optlist); } else { (void) printf(gettext("Group \"%s\" not found\n"), groupname); ret = SA_NO_SUCH_GROUP; @@ -2355,16 +2426,17 @@ space_set(sa_handle_t handle, char *groupname, struct options *optlist, * we have a group and potentially legal additions */ - /* commit to configuration if not a dryrun */ + /* Commit to configuration if not a dryrun */ if (!dryrun && ret == 0) { - if (change && worklist != NULL) { - /* properties changed, so update all shares */ - (void) enable_all_groups(handle, worklist, 0, 0, protocol); - } - ret = sa_update_config(handle); + if (change && worklist != NULL) { + /* properties changed, so update all shares */ + (void) enable_all_groups(handle, worklist, 0, 0, + protocol); + } + ret = sa_update_config(handle); } if (worklist != NULL) - free_list(worklist); + free_list(worklist); return (ret); } @@ -2390,94 +2462,96 @@ sa_set(sa_handle_t handle, int flags, int argc, char *argv[]) int auth; while ((c = getopt(argc, argv, "?hvnP:p:s:S:")) != EOF) { - switch (c) { - case 'v': - verbose++; - break; - case 'n': - dryrun++; - break; - case 'P': - protocol = optarg; - if (!sa_valid_protocol(protocol)) { - (void) printf(gettext("Invalid protocol specified:" - "%s\n"), - protocol); - return (SA_INVALID_PROTOCOL); - } - break; - case 'p': - ret = add_opt(&optlist, optarg, 0); - switch (ret) { - case OPT_ADD_SYNTAX: - (void) printf(gettext("Property syntax error: %s\n"), - optarg); - return (SA_SYNTAX_ERR); - case OPT_ADD_MEMORY: - (void) printf(gettext("No memory to set property: %s\n"), - optarg); - return (SA_NO_MEMORY); + switch (c) { + case 'v': + verbose++; + break; + case 'n': + dryrun++; + break; + case 'P': + protocol = optarg; + if (!sa_valid_protocol(protocol)) { + (void) printf(gettext( + "Invalid protocol specified: %s\n"), + protocol); + return (SA_INVALID_PROTOCOL); + } + break; + case 'p': + ret = add_opt(&optlist, optarg, 0); + switch (ret) { + case OPT_ADD_SYNTAX: + (void) printf(gettext("Property syntax error:" + " %s\n"), optarg); + return (SA_SYNTAX_ERR); + case OPT_ADD_MEMORY: + (void) printf(gettext("No memory to set " + "property: %s\n"), optarg); + return (SA_NO_MEMORY); + default: + break; + } + break; + case 's': + sharepath = optarg; + break; + case 'S': + optset = optarg; + break; default: - break; + case 'h': + case '?': + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_SET)); + return (SA_OK); } - break; - case 's': - sharepath = optarg; - break; - case 'S': - optset = optarg; - break; - default: - case 'h': - case '?': - (void) printf(gettext("usage: %s\n"), - sa_get_usage(USAGE_SET)); - return (SA_OK); - } } if (optlist != NULL) - ret = chk_opt(optlist, optset != NULL, protocol); + ret = chk_opt(optlist, optset != NULL, protocol); if (optind >= argc || (optlist == NULL && optset == NULL) || - protocol == NULL || - ret != OPT_ADD_OK) { - char *sep = "\t"; - (void) printf(gettext("usage: %s\n"), sa_get_usage(USAGE_SET)); - if (optind >= argc) { - (void) printf(gettext("%sgroup must be specified"), sep); - sep = ", "; - } - if (optlist == NULL) { - (void) printf(gettext("%sat least one property must be" - " specified"), sep); - sep = ", "; - } - if (protocol == NULL) { - (void) printf(gettext("%sprotocol must be specified"), sep); - sep = ", "; - } - (void) printf("\n"); - ret = SA_SYNTAX_ERR; + protocol == NULL || ret != OPT_ADD_OK) { + char *sep = "\t"; + + (void) printf(gettext("usage: %s\n"), sa_get_usage(USAGE_SET)); + if (optind >= argc) { + (void) printf(gettext("%sgroup must be specified"), + sep); + sep = ", "; + } + if (optlist == NULL) { + (void) printf(gettext("%sat least one property must be" + " specified"), sep); + sep = ", "; + } + if (protocol == NULL) { + (void) printf(gettext("%sprotocol must be specified"), + sep); + sep = ", "; + } + (void) printf("\n"); + ret = SA_SYNTAX_ERR; } else { /* - * if a group already exists, we can only add a new + * If a group already exists, we can only add a new * protocol to it and not create a new one or add the * same protocol again. */ - groupname = argv[optind]; - auth = check_authorizations(groupname, flags); - if (optset == NULL) - ret = basic_set(handle, groupname, optlist, protocol, - sharepath, dryrun); - else - ret = space_set(handle, groupname, optlist, protocol, - sharepath, dryrun, optset); - if (dryrun && ret == SA_OK && !auth && verbose) { - (void) printf(gettext("Command would fail: %s\n"), - sa_errorstr(SA_NO_PERMISSION)); - } + groupname = argv[optind]; + auth = check_authorizations(groupname, flags); + if (optset == NULL) + ret = basic_set(handle, groupname, optlist, protocol, + sharepath, dryrun); + else + ret = space_set(handle, groupname, optlist, protocol, + sharepath, dryrun, optset); + if (dryrun && ret == SA_OK && !auth && verbose) { + (void) printf(gettext("Command would fail: %s\n"), + sa_errorstr(SA_NO_PERMISSION)); + } } return (ret); } @@ -2485,7 +2559,7 @@ sa_set(sa_handle_t handle, int flags, int argc, char *argv[]) /* * remove_options(group, optlist, proto, *err) * - * helper function to actually remove options from a group after all + * Helper function to actually remove options from a group after all * preprocessing is done. */ @@ -2501,21 +2575,21 @@ remove_options(sa_group_t group, struct options *optlist, optionset = sa_get_optionset(group, proto); if (optionset != NULL) { - for (cur = optlist; cur != NULL; cur = cur->next) { - prop = sa_get_property(optionset, cur->optname); - if (prop != NULL) { - ret = sa_remove_property(prop); - if (ret != SA_OK) - break; - change = 1; + for (cur = optlist; cur != NULL; cur = cur->next) { + prop = sa_get_property(optionset, cur->optname); + if (prop != NULL) { + ret = sa_remove_property(prop); + if (ret != SA_OK) + break; + change = 1; + } } - } } if (ret == SA_OK && change) - ret = sa_commit_properties(optionset, 0); + ret = sa_commit_properties(optionset, 0); if (err != NULL) - *err = ret; + *err = ret; return (change); } @@ -2536,15 +2610,15 @@ valid_unset(sa_group_t group, struct options *optlist, char *proto) optionset = sa_get_optionset(group, proto); if (optionset != NULL) { - for (cur = optlist; cur != NULL; cur = cur->next) { - prop = sa_get_property(optionset, cur->optname); - if (prop == NULL) { - (void) printf(gettext("Could not unset property %s:" - " not set\n"), - cur->optname); - ret = SA_NO_SUCH_PROP; + for (cur = optlist; cur != NULL; cur = cur->next) { + prop = sa_get_property(optionset, cur->optname); + if (prop == NULL) { + (void) printf(gettext( + "Could not unset property %s: not set\n"), + cur->optname); + ret = SA_NO_SUCH_PROP; + } } - } } return (ret); } @@ -2569,22 +2643,22 @@ valid_unset_security(sa_group_t group, struct options *optlist, char *proto, sec = sa_proto_space_alias(proto, sectype); security = sa_get_security(group, sec, proto); if (security != NULL) { - for (cur = optlist; cur != NULL; cur = cur->next) { - prop = sa_get_property(security, cur->optname); - if (prop == NULL) { - (void) printf(gettext("Could not unset property %s:" - " not set\n"), - cur->optname); - ret = SA_NO_SUCH_PROP; + for (cur = optlist; cur != NULL; cur = cur->next) { + prop = sa_get_property(security, cur->optname); + if (prop == NULL) { + (void) printf(gettext( + "Could not unset property %s: not set\n"), + cur->optname); + ret = SA_NO_SUCH_PROP; + } } - } } else { - (void) printf(gettext("Could not unset %s: space not defined\n"), - sectype); - ret = SA_NO_SUCH_SECURITY; + (void) printf(gettext( + "Could not unset %s: space not defined\n"), sectype); + ret = SA_NO_SUCH_SECURITY; } if (sec != NULL) - sa_free_attr_string(sec); + sa_free_attr_string(sec); return (ret); } @@ -2605,39 +2679,39 @@ remove_security(sa_group_t group, char *sectype, sectype = sa_proto_space_alias(proto, sectype); security = sa_get_security(group, sectype, proto); if (sectype != NULL) - sa_free_attr_string(sectype); + sa_free_attr_string(sectype); if (security != NULL) { - while (optlist != NULL) { - sa_property_t prop; - prop = sa_get_property(security, optlist->optname); - if (prop != NULL) { - ret = sa_remove_property(prop); - if (ret != SA_OK) - break; - change = 1; + while (optlist != NULL) { + sa_property_t prop; + prop = sa_get_property(security, optlist->optname); + if (prop != NULL) { + ret = sa_remove_property(prop); + if (ret != SA_OK) + break; + change = 1; + } + optlist = optlist->next; } - optlist = optlist->next; - } /* * when done, properties may have all been removed but * we need to keep the security type itself until * explicitly removed. */ - if (ret == SA_OK && change) - ret = sa_commit_properties(security, 0); + if (ret == SA_OK && change) + ret = sa_commit_properties(security, 0); } else { - ret = SA_NO_SUCH_PROP; + ret = SA_NO_SUCH_PROP; } if (err != NULL) - *err = ret; + *err = ret; return (change); } /* * basic_unset(groupname, optlist, protocol, sharepath, dryrun) * - * unset non-named optionset properties. + * Unset non-named optionset properties. */ static int @@ -2648,73 +2722,83 @@ basic_unset(sa_handle_t handle, char *groupname, struct options *optlist, int ret = SA_OK; int change = 0; struct list *worklist = NULL; + sa_share_t share = NULL; group = sa_get_group(handle, groupname); - if (group != NULL) { - sa_share_t share = NULL; - if (sharepath != NULL) { + if (group == NULL) + return (ret); + + if (sharepath != NULL) { share = sa_get_share(group, sharepath); if (share == NULL) { - (void) printf(gettext("Share does not exist in group %s\n"), - groupname, sharepath); - ret = SA_NO_SUCH_PATH; + (void) printf(gettext( + "Share does not exist in group %s\n"), + groupname, sharepath); + ret = SA_NO_SUCH_PATH; } - } - if (ret == SA_OK) { + } + if (ret == SA_OK) { /* group must exist */ ret = valid_unset(share != NULL ? share : group, - optlist, protocol); + optlist, protocol); if (ret == SA_OK && !dryrun) { - if (share != NULL) { - sa_optionset_t optionset; - sa_property_t prop; - change |= remove_options(share, optlist, protocol, - &ret); - /* if a share optionset is empty, remove it */ - optionset = sa_get_optionset((sa_share_t)share, - protocol); - if (optionset != NULL) { - prop = sa_get_property(optionset, NULL); - if (prop == NULL) - (void) sa_destroy_optionset(optionset); - } - } else { - change |= remove_options(group, optlist, protocol, - &ret); - } - if (ret == SA_OK && change) - worklist = add_list(worklist, group, share); - if (ret != SA_OK) - (void) printf(gettext("Could not remove properties:" - "%s\n"), - sa_errorstr(ret)); - } - } else { - (void) printf(gettext("Group \"%s\" not found\n"), groupname); + if (share != NULL) { + sa_optionset_t optionset; + sa_property_t prop; + change |= remove_options(share, optlist, + protocol, &ret); + /* + * If a share optionset is + * empty, remove it. + */ + optionset = sa_get_optionset((sa_share_t)share, + protocol); + if (optionset != NULL) { + prop = sa_get_property(optionset, NULL); + if (prop == NULL) + (void) sa_destroy_optionset( + optionset); + } + } else { + change |= remove_options(group, + optlist, protocol, &ret); + } + if (ret == SA_OK && change) + worklist = add_list(worklist, group, + share); + if (ret != SA_OK) + (void) printf(gettext( + "Could not remove properties: " + "%s\n"), sa_errorstr(ret)); + } + } else { + (void) printf(gettext("Group \"%s\" not found\n"), + groupname); ret = SA_NO_SUCH_GROUP; - } - free_opt(optlist); } + free_opt(optlist); /* - * we have a group and potentially legal additions + * We have a group and potentially legal additions + * + * Commit to configuration if not a dryrun */ - /* commit to configuration if not a dryrun */ if (!dryrun && ret == SA_OK) { - if (change && worklist != NULL) { - /* properties changed, so update all shares */ - (void) enable_all_groups(handle, worklist, 0, 0, protocol); - } + if (change && worklist != NULL) { + /* properties changed, so update all shares */ + (void) enable_all_groups(handle, worklist, 0, 0, + protocol); + } } if (worklist != NULL) - free_list(worklist); + free_list(worklist); return (ret); } /* * space_unset(groupname, optlist, protocol, sharepath, dryrun) * - * unset named optionset properties. + * Unset named optionset properties. */ static int space_unset(sa_handle_t handle, char *groupname, struct options *optlist, @@ -2724,92 +2808,92 @@ space_unset(sa_handle_t handle, char *groupname, struct options *optlist, int ret = SA_OK; int change = 0; struct list *worklist = NULL; + sa_share_t share = NULL; group = sa_get_group(handle, groupname); - if (group != NULL) { - sa_share_t share = NULL; - if (sharepath != NULL) { + if (group == NULL) { + (void) printf(gettext("Group \"%s\" not found\n"), groupname); + return (SA_NO_SUCH_GROUP); + } + if (sharepath != NULL) { share = sa_get_share(group, sharepath); if (share == NULL) { - (void) printf(gettext("Share does not exist in group %s\n"), - groupname, sharepath); - ret = SA_NO_SUCH_PATH; - } - } - if (ret == SA_OK) { - ret = valid_unset_security(share != NULL ? share : group, - optlist, protocol, sectype); - if (ret == SA_OK && !dryrun) { - if (optlist != NULL) { + (void) printf(gettext( + "Share does not exist in group %s\n"), + groupname, sharepath); + return (SA_NO_SUCH_PATH); + } + } + ret = valid_unset_security(share != NULL ? share : group, optlist, + protocol, sectype); + + if (ret == SA_OK && !dryrun) { + if (optlist != NULL) { if (share != NULL) { - sa_security_t optionset; - sa_property_t prop; - change = remove_security(share, sectype, - optlist, protocol, - &ret); - /* if a share security is empty, remove it */ - optionset = sa_get_security((sa_group_t)share, - sectype, - protocol); - if (optionset != NULL) { - prop = sa_get_property(optionset, NULL); - if (prop == NULL) - ret = sa_destroy_security(optionset); - } + sa_security_t optionset; + sa_property_t prop; + change = remove_security(share, + sectype, optlist, protocol, &ret); + + /* If a share security is empty, remove it */ + optionset = sa_get_security((sa_group_t)share, + sectype, protocol); + if (optionset != NULL) { + prop = sa_get_property(optionset, + NULL); + if (prop == NULL) + ret = sa_destroy_security( + optionset); + } } else { - change = remove_security(group, sectype, - optlist, protocol, - &ret); + change = remove_security(group, sectype, + optlist, protocol, &ret); } - } else { + } else { sa_security_t security; char *sec; sec = sa_proto_space_alias(protocol, sectype); security = sa_get_security(group, sec, protocol); if (sec != NULL) - sa_free_attr_string(sec); + sa_free_attr_string(sec); if (security != NULL) { - ret = sa_destroy_security(security); - if (ret == SA_OK) - change = 1; + ret = sa_destroy_security(security); + if (ret == SA_OK) + change = 1; } else { - ret = SA_NO_SUCH_PROP; + ret = SA_NO_SUCH_PROP; } - } - if (ret != SA_OK) - (void) printf(gettext("Could not unset property: %s\n"), - sa_errorstr(ret)); } - - if (ret == SA_OK && change) - worklist = add_list(worklist, group, 0); - } - } else { - (void) printf(gettext("Group \"%s\" not found\n"), groupname); - ret = SA_NO_SUCH_GROUP; + if (ret != SA_OK) + (void) printf(gettext("Could not unset property: %s\n"), + sa_errorstr(ret)); } + + if (ret == SA_OK && change) + worklist = add_list(worklist, group, 0); + free_opt(optlist); /* - * we have a group and potentially legal additions + * We have a group and potentially legal additions */ - /* commit to configuration if not a dryrun */ + /* Commit to configuration if not a dryrun */ if (!dryrun && ret == 0) { - if (change && worklist != NULL) { /* properties changed, so update all shares */ - (void) enable_all_groups(handle, worklist, 0, 0, protocol); - } - ret = sa_update_config(handle); + if (change && worklist != NULL) + (void) enable_all_groups(handle, worklist, 0, 0, + protocol); + ret = sa_update_config(handle); } if (worklist != NULL) - free_list(worklist); + free_list(worklist); return (ret); } /* * sa_unset(flags, argc, argv) * - * implements the unset subcommand. Parsing done here and then basic + * Implements the unset subcommand. Parsing done here and then basic * or space versions of the real code are called. */ @@ -2828,97 +2912,99 @@ sa_unset(sa_handle_t handle, int flags, int argc, char *argv[]) int auth; while ((c = getopt(argc, argv, "?hvnP:p:s:S:")) != EOF) { - switch (c) { - case 'v': - verbose++; - break; - case 'n': - dryrun++; - break; - case 'P': - protocol = optarg; - if (!sa_valid_protocol(protocol)) { - (void) printf(gettext("Invalid protocol specified: %s\n"), - protocol); - return (SA_INVALID_PROTOCOL); - } - break; - case 'p': - ret = add_opt(&optlist, optarg, 1); - switch (ret) { - case OPT_ADD_SYNTAX: - (void) printf(gettext("Property syntax error for " - "property %s\n"), - optarg); - return (SA_SYNTAX_ERR); - case OPT_ADD_PROPERTY: - (void) printf(gettext("Properties need to be set" - " with set command: %s\n"), - optarg); - return (SA_SYNTAX_ERR); + switch (c) { + case 'v': + verbose++; + break; + case 'n': + dryrun++; + break; + case 'P': + protocol = optarg; + if (!sa_valid_protocol(protocol)) { + (void) printf(gettext( + "Invalid protocol specified: %s\n"), + protocol); + return (SA_INVALID_PROTOCOL); + } + break; + case 'p': + ret = add_opt(&optlist, optarg, 1); + switch (ret) { + case OPT_ADD_SYNTAX: + (void) printf(gettext("Property syntax error " + "for property %s\n"), optarg); + return (SA_SYNTAX_ERR); + + case OPT_ADD_PROPERTY: + (void) printf(gettext("Properties need to be " + "set with set command: %s\n"), optarg); + return (SA_SYNTAX_ERR); + + default: + break; + } + break; + case 's': + sharepath = optarg; + break; + case 'S': + optset = optarg; + break; default: - break; + case 'h': + case '?': + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_UNSET)); + return (SA_OK); } - break; - case 's': - sharepath = optarg; - break; - case 'S': - optset = optarg; - break; - default: - case 'h': - case '?': - (void) printf(gettext("usage: %s\n"), - sa_get_usage(USAGE_UNSET)); - return (SA_OK); - } } if (optlist != NULL) - ret = chk_opt(optlist, optset != NULL, protocol); + ret = chk_opt(optlist, optset != NULL, protocol); if (optind >= argc || (optlist == NULL && optset == NULL) || protocol == NULL) { - char *sep = "\t"; - (void) printf(gettext("usage: %s\n"), sa_get_usage(USAGE_UNSET)); - if (optind >= argc) { - (void) printf(gettext("%sgroup must be specified"), sep); - sep = ", "; - } - if (optlist == NULL) { - (void) printf(gettext("%sat least one property must be " - "specified"), - sep); - sep = ", "; - } - if (protocol == NULL) { - (void) printf(gettext("%sprotocol must be specified"), sep); - sep = ", "; - } - (void) printf("\n"); - ret = SA_SYNTAX_ERR; + char *sep = "\t"; + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_UNSET)); + if (optind >= argc) { + (void) printf(gettext("%sgroup must be specified"), + sep); + sep = ", "; + } + if (optlist == NULL) { + (void) printf(gettext("%sat least one property must " + "be specified"), sep); + sep = ", "; + } + if (protocol == NULL) { + (void) printf(gettext("%sprotocol must be specified"), + sep); + sep = ", "; + } + (void) printf("\n"); + ret = SA_SYNTAX_ERR; } else { /* - * if a group already exists, we can only add a new + * If a group already exists, we can only add a new * protocol to it and not create a new one or add the * same protocol again. */ - groupname = argv[optind]; - auth = check_authorizations(groupname, flags); - if (optset == NULL) - ret = basic_unset(handle, groupname, optlist, protocol, - sharepath, dryrun); - else - ret = space_unset(handle, groupname, optlist, protocol, - sharepath, dryrun, optset); + groupname = argv[optind]; + auth = check_authorizations(groupname, flags); + if (optset == NULL) + ret = basic_unset(handle, groupname, optlist, protocol, + sharepath, dryrun); + else + ret = space_unset(handle, groupname, optlist, protocol, + sharepath, dryrun, optset); - if (dryrun && ret == SA_OK && !auth && verbose) { - (void) printf(gettext("Command would fail: %s\n"), - sa_errorstr(SA_NO_PERMISSION)); - } + if (dryrun && ret == SA_OK && !auth && verbose) + (void) printf(gettext("Command would fail: %s\n"), + sa_errorstr(SA_NO_PERMISSION)); } return (ret); } @@ -2941,89 +3027,95 @@ sa_enable_group(sa_handle_t handle, int flags, int argc, char *argv[]) char *state; struct list *worklist = NULL; int auth = 1; + sa_group_t group; while ((c = getopt(argc, argv, "?havnP:")) != EOF) { - switch (c) { - case 'a': - all = 1; - break; - case 'n': - dryrun++; - break; - case 'P': - protocol = optarg; - if (!sa_valid_protocol(protocol)) { - (void) printf(gettext("Invalid protocol specified: %s\n"), + switch (c) { + case 'a': + all = 1; + break; + case 'n': + dryrun++; + break; + case 'P': + protocol = optarg; + if (!sa_valid_protocol(protocol)) { + (void) printf(gettext( + "Invalid protocol specified: %s\n"), protocol); - return (SA_INVALID_PROTOCOL); + return (SA_INVALID_PROTOCOL); + } + break; + case 'v': + verbose++; + break; + default: + case 'h': + case '?': + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_ENABLE)); + return (0); } - break; - case 'v': - verbose++; - break; - default: - case 'h': - case '?': - (void) printf(gettext("usage: %s\n"), - sa_get_usage(USAGE_ENABLE)); - return (0); - } } if (optind == argc && !all) { - (void) printf(gettext("usage: %s\n"), sa_get_usage(USAGE_ENABLE)); - (void) printf(gettext("\tmust specify group\n")); - ret = SA_NO_SUCH_PATH; - } else { - sa_group_t group; - if (!all) { + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_ENABLE)); + (void) printf(gettext("\tmust specify group\n")); + return (SA_NO_SUCH_PATH); + } + if (!all) { while (optind < argc) { - group = sa_get_group(handle, argv[optind]); - if (group != NULL) { - auth &= check_authorizations(argv[optind], flags); - state = sa_get_group_attr(group, "state"); - if (state != NULL && - strcmp(state, "enabled") == 0) { - /* already enabled */ - if (verbose) - (void) printf(gettext("Group \"%s\" is already " - "enabled\n"), - argv[optind]); - ret = SA_BUSY; /* already enabled */ + group = sa_get_group(handle, argv[optind]); + if (group != NULL) { + auth &= check_authorizations(argv[optind], + flags); + state = sa_get_group_attr(group, "state"); + if (state != NULL && + strcmp(state, "enabled") == 0) { + /* already enabled */ + if (verbose) + (void) printf(gettext( + "Group \"%s\" is already " + "enabled\n"), + argv[optind]); + ret = SA_BUSY; /* already enabled */ + } else { + worklist = add_list(worklist, group, + 0); + if (verbose) + (void) printf(gettext( + "Enabling group \"%s\"\n"), + argv[optind]); + } + if (state != NULL) + sa_free_attr_string(state); } else { - worklist = add_list(worklist, group, 0); - if (verbose) - (void) printf(gettext("Enabling group " - "\"%s\"\n"), - argv[optind]); + ret = SA_NO_SUCH_GROUP; } - if (state != NULL) - sa_free_attr_string(state); - } else { - ret = SA_NO_SUCH_GROUP; - } - optind++; + optind++; } - } else { - for (group = sa_get_group(handle, NULL); group != NULL; + } else { + for (group = sa_get_group(handle, NULL); + group != NULL; group = sa_get_next_group(group)) { - worklist = add_list(worklist, group, 0); + worklist = add_list(worklist, group, 0); } - } - if (!dryrun && ret == SA_OK) { + } + if (!dryrun && ret == SA_OK) ret = enable_all_groups(handle, worklist, 1, 0, NULL); - } - if (ret != SA_OK && ret != SA_BUSY) + + if (ret != SA_OK && ret != SA_BUSY) (void) printf(gettext("Could not enable group: %s\n"), - sa_errorstr(ret)); - if (ret == SA_BUSY) + sa_errorstr(ret)); + if (ret == SA_BUSY) ret = SA_OK; - } + if (worklist != NULL) - free_list(worklist); + free_list(worklist); if (dryrun && ret == SA_OK && !auth && verbose) { - (void) printf(gettext("Command would fail: %s\n"), - sa_errorstr(SA_NO_PERMISSION)); + (void) printf(gettext("Command would fail: %s\n"), + sa_errorstr(SA_NO_PERMISSION)); } return (ret); } @@ -3031,7 +3123,7 @@ sa_enable_group(sa_handle_t handle, int flags, int argc, char *argv[]) /* * disable_group(group, setstate) * - * disable all the shares in the specified group honoring the setstate + * Disable all the shares in the specified group honoring the setstate * argument. This is a helper for disable_all_groups in order to * simplify regular and subgroup (zfs) disabling. Group has already * been checked for non-NULL. @@ -3046,14 +3138,14 @@ disable_group(sa_group_t group) for (share = sa_get_share(group, NULL); share != NULL && ret == SA_OK; share = sa_get_next_share(share)) { - ret = sa_disable_share(share, NULL); - if (ret == SA_NO_SUCH_PATH) { - /* - * this is OK since the path is gone. we can't - * re-share it anyway so no error. - */ - ret = SA_OK; - } + ret = sa_disable_share(share, NULL); + if (ret == SA_NO_SUCH_PATH) { + /* + * this is OK since the path is gone. we can't + * re-share it anyway so no error. + */ + ret = SA_OK; + } } return (ret); } @@ -3074,32 +3166,33 @@ disable_all_groups(sa_handle_t handle, struct list *work, int setstate) sa_group_t subgroup, group; while (work != NULL && ret == SA_OK) { - group = (sa_group_t)work->item; - if (setstate) - ret = sa_set_group_attr(group, "state", "disabled"); - if (ret == SA_OK) { - char *name; - name = sa_get_group_attr(group, "name"); - if (name != NULL && strcmp(name, "zfs") == 0) { - /* need to get the sub-groups for stopping */ - for (subgroup = sa_get_sub_group(group); subgroup != NULL; - subgroup = sa_get_next_group(subgroup)) { - ret = disable_group(subgroup); - } - } else { - ret = disable_group(group); + group = (sa_group_t)work->item; + if (setstate) + ret = sa_set_group_attr(group, "state", "disabled"); + if (ret == SA_OK) { + char *name; + name = sa_get_group_attr(group, "name"); + if (name != NULL && strcmp(name, "zfs") == 0) { + /* need to get the sub-groups for stopping */ + for (subgroup = sa_get_sub_group(group); + subgroup != NULL; + subgroup = sa_get_next_group(subgroup)) { + ret = disable_group(subgroup); + } + } else { + ret = disable_group(group); + } + /* + * We don't want to "disable" since it won't come + * up after a reboot. The SMF framework should do + * the right thing. On enable we do want to do + * something. + */ } - /* - * we don't want to "disable" since it won't come - * up after a reboot. The SMF framework should do - * the right thing. On enable we do want to do - * something. - */ - } - work = work->next; + work = work->next; } if (ret == SA_OK) - ret = sa_update_config(handle); + ret = sa_update_config(handle); return (ret); } @@ -3120,92 +3213,93 @@ sa_disable_group(sa_handle_t handle, int flags, int argc, char *argv[]) char *protocol; char *state; struct list *worklist = NULL; + sa_group_t group; int auth = 1; while ((c = getopt(argc, argv, "?havn")) != EOF) { - switch (c) { - case 'a': - all = 1; - break; - case 'n': - dryrun++; - break; - case 'P': - protocol = optarg; - if (!sa_valid_protocol(protocol)) { - (void) printf(gettext("Invalid protocol specified: %s\n"), - protocol); - return (SA_INVALID_PROTOCOL); + switch (c) { + case 'a': + all = 1; + break; + case 'n': + dryrun++; + break; + case 'P': + protocol = optarg; + if (!sa_valid_protocol(protocol)) { + (void) printf(gettext( + "Invalid protocol specified: %s\n"), + protocol); + return (SA_INVALID_PROTOCOL); + } + break; + case 'v': + verbose++; + break; + default: + case 'h': + case '?': + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_DISABLE)); + return (0); } - break; - case 'v': - verbose++; - break; - default: - case 'h': - case '?': - (void) printf(gettext("usage: %s\n"), - sa_get_usage(USAGE_DISABLE)); - return (0); - } } if (optind == argc && !all) { (void) printf(gettext("usage: %s\n"), - sa_get_usage(USAGE_DISABLE)); + sa_get_usage(USAGE_DISABLE)); (void) printf(gettext("\tmust specify group\n")); - ret = SA_NO_SUCH_PATH; - } else { - sa_group_t group; - if (!all) { - while (optind < argc) { + return (SA_NO_SUCH_PATH); + } + if (!all) { + while (optind < argc) { group = sa_get_group(handle, argv[optind]); if (group != NULL) { - auth &= check_authorizations(argv[optind], flags); - state = sa_get_group_attr(group, "state"); - if (state == NULL || - strcmp(state, "disabled") == 0) { - /* already disabled */ - if (verbose) - (void) printf(gettext("Group \"%s\" is " - "already disabled\n"), - argv[optind]); - ret = SA_BUSY; /* already disable */ - } else { - worklist = add_list(worklist, group, 0); - if (verbose) - (void) printf(gettext("Disabling group " - "\"%s\"\n"), - argv[optind]); - } - if (state != NULL) - sa_free_attr_string(state); + auth &= check_authorizations(argv[optind], + flags); + state = sa_get_group_attr(group, "state"); + if (state == NULL || + strcmp(state, "disabled") == 0) { + /* already disabled */ + if (verbose) + (void) printf(gettext( + "Group \"%s\" is " + "already disabled\n"), + argv[optind]); + ret = SA_BUSY; /* already disable */ + } else { + worklist = add_list(worklist, group, 0); + if (verbose) + (void) printf(gettext( + "Disabling group " + "\"%s\"\n"), argv[optind]); + } + if (state != NULL) + sa_free_attr_string(state); } else { - ret = SA_NO_SUCH_GROUP; + ret = SA_NO_SUCH_GROUP; } optind++; - } - } else { - for (group = sa_get_group(handle, NULL); group != NULL; - group = sa_get_next_group(group)) { - worklist = add_list(worklist, group, 0); - } - } - if (ret == SA_OK && !dryrun) { - ret = disable_all_groups(handle, worklist, 1); } - if (ret != SA_OK && ret != SA_BUSY) - (void) printf(gettext("Could not disable group: %s\n"), - sa_errorstr(ret)); - if (ret == SA_BUSY) - ret = SA_OK; + } else { + for (group = sa_get_group(handle, NULL); + group != NULL; + group = sa_get_next_group(group)) + worklist = add_list(worklist, group, 0); } + + if (ret == SA_OK && !dryrun) + ret = disable_all_groups(handle, worklist, 1); + if (ret != SA_OK && ret != SA_BUSY) + (void) printf(gettext("Could not disable group: %s\n"), + sa_errorstr(ret)); + if (ret == SA_BUSY) + ret = SA_OK; if (worklist != NULL) - free_list(worklist); - if (dryrun && ret == SA_OK && !auth && verbose) { - (void) printf(gettext("Command would fail: %s\n"), - sa_errorstr(SA_NO_PERMISSION)); - } + free_list(worklist); + if (dryrun && ret == SA_OK && !auth && verbose) + (void) printf(gettext("Command would fail: %s\n"), + sa_errorstr(SA_NO_PERMISSION)); return (ret); } @@ -3217,7 +3311,7 @@ sa_disable_group(sa_handle_t handle, int flags, int argc, char *argv[]) * of the group(s) and only enables shares if the group is already * enabled. */ - +/*ARGSUSED*/ int sa_start_group(sa_handle_t handle, int flags, int argc, char *argv[]) { @@ -3228,84 +3322,84 @@ sa_start_group(sa_handle_t handle, int flags, int argc, char *argv[]) char *protocol = NULL; char *state; struct list *worklist = NULL; -#ifdef lint - flags = flags; -#endif + sa_group_t group; while ((c = getopt(argc, argv, "?havP:")) != EOF) { - switch (c) { - case 'a': - all = 1; - break; - case 'P': - protocol = optarg; - if (!sa_valid_protocol(protocol)) { - (void) printf(gettext("Invalid protocol specified: %s\n"), + switch (c) { + case 'a': + all = 1; + break; + case 'P': + protocol = optarg; + if (!sa_valid_protocol(protocol)) { + (void) printf(gettext( + "Invalid protocol specified: %s\n"), protocol); - return (SA_INVALID_PROTOCOL); + return (SA_INVALID_PROTOCOL); + } + break; + case 'v': + verbose++; + break; + default: + case 'h': + case '?': + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_START)); + return (SA_OK); } - break; - case 'v': - verbose++; - break; - default: - case 'h': - case '?': - (void) printf(gettext("usage: %s\n"), - sa_get_usage(USAGE_START)); - return (SA_OK); - } } if (optind == argc && !all) { (void) printf(gettext("usage: %s\n"), - sa_get_usage(USAGE_START)); - ret = SMF_EXIT_ERR_FATAL; - } else { - sa_group_t group; + sa_get_usage(USAGE_START)); + return (SMF_EXIT_ERR_FATAL); + } - if (!all) { - while (optind < argc) { + if (!all) { + while (optind < argc) { group = sa_get_group(handle, argv[optind]); if (group != NULL) { - state = sa_get_group_attr(group, "state"); - if (state == NULL || - strcmp(state, "enabled") == 0) { - worklist = add_list(worklist, group, 0); - if (verbose) - (void) printf(gettext("Starting group " - "\"%s\"\n"), - argv[optind]); - } else { - /* - * determine if there are any - * protocols. if there aren't any, - * then there isn't anything to do in - * any case so no error. - */ - if (sa_get_optionset(group, protocol) != NULL) { - ret = SMF_EXIT_OK; + state = sa_get_group_attr(group, "state"); + if (state == NULL || + strcmp(state, "enabled") == 0) { + worklist = add_list(worklist, group, 0); + if (verbose) + (void) printf(gettext( + "Starting group \"%s\"\n"), + argv[optind]); + } else { + /* + * Determine if there are any + * protocols. if there aren't any, + * then there isn't anything to do in + * any case so no error. + */ + if (sa_get_optionset(group, + protocol) != NULL) { + ret = SMF_EXIT_OK; + } } - } - if (state != NULL) - sa_free_attr_string(state); + if (state != NULL) + sa_free_attr_string(state); } optind++; - } - } else { - for (group = sa_get_group(handle, NULL); group != NULL; - group = sa_get_next_group(group)) { + } + } else { + for (group = sa_get_group(handle, NULL); group != NULL; + group = sa_get_next_group(group)) { state = sa_get_group_attr(group, "state"); if (state == NULL || strcmp(state, "enabled") == 0) - worklist = add_list(worklist, group, 0); + worklist = add_list(worklist, group, 0); if (state != NULL) - sa_free_attr_string(state); - } + sa_free_attr_string(state); } - (void) enable_all_groups(handle, worklist, 0, 1, NULL); } + + (void) enable_all_groups(handle, worklist, 0, 1, NULL); + if (worklist != NULL) - free_list(worklist); + free_list(worklist); return (ret); } @@ -3317,7 +3411,7 @@ sa_start_group(sa_handle_t handle, int flags, int argc, char *argv[]) * of the group(s) and only disables shares if the group is already * enabled. */ - +/*ARGSUSED*/ int sa_stop_group(sa_handle_t handle, int flags, int argc, char *argv[]) { @@ -3328,75 +3422,74 @@ sa_stop_group(sa_handle_t handle, int flags, int argc, char *argv[]) char *protocol = NULL; char *state; struct list *worklist = NULL; -#ifdef lint - flags = flags; -#endif + sa_group_t group; while ((c = getopt(argc, argv, "?havP:")) != EOF) { - switch (c) { - case 'a': - all = 1; - break; - case 'P': - protocol = optarg; - if (!sa_valid_protocol(protocol)) { - (void) printf(gettext("Invalid protocol specified: %s\n"), - protocol); - return (SA_INVALID_PROTOCOL); + switch (c) { + case 'a': + all = 1; + break; + case 'P': + protocol = optarg; + if (!sa_valid_protocol(protocol)) { + (void) printf(gettext( + "Invalid protocol specified: %s\n"), + protocol); + return (SA_INVALID_PROTOCOL); + } + break; + case 'v': + verbose++; + break; + default: + case 'h': + case '?': + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_STOP)); + return (0); } - break; - case 'v': - verbose++; - break; - default: - case 'h': - case '?': - (void) printf(gettext("usage: %s\n"), - sa_get_usage(USAGE_STOP)); - return (0); - } } if (optind == argc && !all) { - (void) printf(gettext("usage: %s\n"), sa_get_usage(USAGE_STOP)); - ret = SMF_EXIT_ERR_FATAL; - } else { - sa_group_t group; - if (!all) { - while (optind < argc) { + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_STOP)); + return (SMF_EXIT_ERR_FATAL); + } else if (!all) { + while (optind < argc) { group = sa_get_group(handle, argv[optind]); if (group != NULL) { - state = sa_get_group_attr(group, "state"); - if (state == NULL || - strcmp(state, "enabled") == 0) { - worklist = add_list(worklist, group, 0); - if (verbose) - (void) printf(gettext("Stopping group " - "\"%s\"\n"), - argv[optind]); - } else { - ret = SMF_EXIT_OK; - } - if (state != NULL) - sa_free_attr_string(state); + state = sa_get_group_attr(group, "state"); + if (state == NULL || + strcmp(state, "enabled") == 0) { + worklist = add_list(worklist, group, 0); + if (verbose) + (void) printf(gettext( + "Stopping group \"%s\"\n"), + argv[optind]); + } else { + ret = SMF_EXIT_OK; + } + if (state != NULL) + sa_free_attr_string(state); } optind++; - } - } else { - for (group = sa_get_group(handle, NULL); group != NULL; - group = sa_get_next_group(group)) { + } + } else { + for (group = sa_get_group(handle, NULL); group != NULL; + group = sa_get_next_group(group)) { state = sa_get_group_attr(group, "state"); if (state == NULL || strcmp(state, "enabled") == 0) - worklist = add_list(worklist, group, 0); + worklist = add_list(worklist, group, 0); if (state != NULL) - sa_free_attr_string(state); - } + sa_free_attr_string(state); } - (void) disable_all_groups(handle, worklist, 0); - ret = sa_update_config(handle); } + + (void) disable_all_groups(handle, worklist, 0); + ret = sa_update_config(handle); + if (worklist != NULL) - free_list(worklist); + free_list(worklist); return (ret); } @@ -3415,37 +3508,37 @@ remove_all_options(sa_share_t share, char *proto) optionset = sa_get_optionset(share, proto); if (optionset != NULL) - (void) sa_destroy_optionset(optionset); + (void) sa_destroy_optionset(optionset); for (security = sa_get_security(share, NULL, NULL); security != NULL; security = sa_get_next_security(security)) { - char *type; + char *type; /* - * we walk through the list. prevsec keeps the + * We walk through the list. prevsec keeps the * previous security so we can delete it without * destroying the list. */ - if (prevsec != NULL) { - /* remove the previously seen security */ - (void) sa_destroy_security(prevsec); - /* set to NULL so we don't try multiple times */ - prevsec = NULL; - } - type = sa_get_security_attr(security, "type"); - if (type != NULL) { - /* - * if the security matches the specified protocol, we - * want to remove it. prevsec holds it until either - * the next pass or we fall out of the loop. - */ - if (strcmp(type, proto) == 0) - prevsec = security; - sa_free_attr_string(type); - } + if (prevsec != NULL) { + /* remove the previously seen security */ + (void) sa_destroy_security(prevsec); + /* set to NULL so we don't try multiple times */ + prevsec = NULL; + } + type = sa_get_security_attr(security, "type"); + if (type != NULL) { + /* + * if the security matches the specified protocol, we + * want to remove it. prevsec holds it until either + * the next pass or we fall out of the loop. + */ + if (strcmp(type, proto) == 0) + prevsec = security; + sa_free_attr_string(type); + } } /* in case there is one left */ if (prevsec != NULL) - (void) sa_destroy_security(prevsec); + (void) sa_destroy_security(prevsec); } @@ -3462,7 +3555,7 @@ format_legacy_path(char *buff, int buffsize, char *proto, char *cmd) err = snprintf(buff, buffsize, "/usr/lib/fs/%s/%s", proto, cmd); if (err > buffsize) - return (-1); + return (-1); return (0); } @@ -3481,8 +3574,9 @@ check_legacy_cmd(char *path) int ret = 0; if (stat(path, &st) == 0) { - if (S_ISREG(st.st_mode) && st.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)) - ret = 1; + if (S_ISREG(st.st_mode) && + st.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)) + ret = 1; } return (ret); } @@ -3490,7 +3584,7 @@ check_legacy_cmd(char *path) /* * run_legacy_command(proto, cmd, argv) * - * we know the command exists, so attempt to execute it with all the + * We know the command exists, so attempt to execute it with all the * arguments. This implements full legacy share support for those * protocols that don't have plugin providers. */ @@ -3502,14 +3596,14 @@ run_legacy_command(char *path, char *argv[]) ret = execv(path, argv); if (ret < 0) { - switch (errno) { - case EACCES: - ret = SA_NO_PERMISSION; - break; - default: - ret = SA_SYSTEM_ERR; - break; - } + switch (errno) { + case EACCES: + ret = SA_NO_PERMISSION; + break; + default: + ret = SA_SYSTEM_ERR; + break; + } } return (ret); } @@ -3527,66 +3621,66 @@ out_share(FILE *out, sa_group_t group, char *proto) sa_share_t share; char resfmt[128]; - for (share = sa_get_share(group, NULL); share != NULL; - share = sa_get_next_share(share)) { - char *path; - char *type; - char *resource; - char *description; - char *groupname; - char *sharedstate; - int shared = 1; - char *soptions; - - sharedstate = sa_get_share_attr(share, "shared"); - path = sa_get_share_attr(share, "path"); - type = sa_get_share_attr(share, "type"); - resource = sa_get_share_attr(share, "resource"); - groupname = sa_get_group_attr(group, "name"); - - if (groupname != NULL && strcmp(groupname, "default") == 0) { - sa_free_attr_string(groupname); - groupname = NULL; - } - description = sa_get_share_description(share); - - /* want the sharetab version if it exists */ - soptions = sa_get_share_attr(share, "shareopts"); - - if (sharedstate == NULL) - shared = 0; - - if (soptions == NULL) - soptions = sa_proto_legacy_format(proto, share, 1); - - if (shared) { - /* only active shares go here */ - (void) snprintf(resfmt, sizeof (resfmt), "%s%s%s", - resource != NULL ? resource : "-", - groupname != NULL ? "@" : "", - groupname != NULL ? groupname : ""); - (void) fprintf(out, "%-14.14s %s %s \"%s\" \n", - resfmt, - path, - (soptions != NULL && strlen(soptions) > 0) ? - soptions : "rw", - (description != NULL) ? description : ""); - } - - if (path != NULL) - sa_free_attr_string(path); - if (type != NULL) - sa_free_attr_string(type); - if (resource != NULL) - sa_free_attr_string(resource); - if (groupname != NULL) - sa_free_attr_string(groupname); - if (description != NULL) - sa_free_share_description(description); - if (sharedstate != NULL) - sa_free_attr_string(sharedstate); - if (soptions != NULL) - sa_format_free(soptions); + for (share = sa_get_share(group, NULL); + share != NULL; + share = sa_get_next_share(share)) { + char *path; + char *type; + char *resource; + char *description; + char *groupname; + char *sharedstate; + int shared = 1; + char *soptions; + + sharedstate = sa_get_share_attr(share, "shared"); + path = sa_get_share_attr(share, "path"); + type = sa_get_share_attr(share, "type"); + resource = sa_get_share_attr(share, "resource"); + groupname = sa_get_group_attr(group, "name"); + + if (groupname != NULL && strcmp(groupname, "default") == 0) { + sa_free_attr_string(groupname); + groupname = NULL; + } + description = sa_get_share_description(share); + + /* Want the sharetab version if it exists */ + soptions = sa_get_share_attr(share, "shareopts"); + + if (sharedstate == NULL) + shared = 0; + + if (soptions == NULL) + soptions = sa_proto_legacy_format(proto, share, 1); + + if (shared) { + /* only active shares go here */ + (void) snprintf(resfmt, sizeof (resfmt), "%s%s%s", + resource != NULL ? resource : "-", + groupname != NULL ? "@" : "", + groupname != NULL ? groupname : ""); + (void) fprintf(out, "%-14.14s %s %s \"%s\" \n", + resfmt, path, + (soptions != NULL && strlen(soptions) > 0) ? + soptions : "rw", + (description != NULL) ? description : ""); + } + + if (path != NULL) + sa_free_attr_string(path); + if (type != NULL) + sa_free_attr_string(type); + if (resource != NULL) + sa_free_attr_string(resource); + if (groupname != NULL) + sa_free_attr_string(groupname); + if (description != NULL) + sa_free_share_description(description); + if (sharedstate != NULL) + sa_free_attr_string(sharedstate); + if (soptions != NULL) + sa_format_free(soptions); } } @@ -3604,36 +3698,38 @@ output_legacy_file(FILE *out, char *proto, sa_handle_t handle) sa_group_t group; for (group = sa_get_group(handle, NULL); group != NULL; - group = sa_get_next_group(group)) { - char *options; - char *zfs; + group = sa_get_next_group(group)) { + char *options; + char *zfs; /* - * get default options preformated, being careful to + * Get default options preformated, being careful to * handle legacy shares differently from new style * shares. Legacy share have options on the share. */ - zfs = sa_get_group_attr(group, "zfs"); - if (zfs != NULL) { - sa_group_t zgroup; - sa_free_attr_string(zfs); - options = sa_proto_legacy_format(proto, group, 1); - for (zgroup = sa_get_sub_group(group); zgroup != NULL; - zgroup = sa_get_next_group(zgroup)) { - - /* got a group, so display it */ - out_share(out, zgroup, proto); + zfs = sa_get_group_attr(group, "zfs"); + if (zfs != NULL) { + sa_group_t zgroup; + sa_free_attr_string(zfs); + options = sa_proto_legacy_format(proto, group, 1); + for (zgroup = sa_get_sub_group(group); + zgroup != NULL; + zgroup = sa_get_next_group(zgroup)) { + + /* got a group, so display it */ + out_share(out, zgroup, proto); + } + } else { + options = sa_proto_legacy_format(proto, group, 1); + out_share(out, group, proto); } - } else { - options = sa_proto_legacy_format(proto, group, 1); - out_share(out, group, proto); - } - if (options != NULL) - free(options); + if (options != NULL) + free(options); } } +/*ARGSUSED*/ int sa_legacy_share(sa_handle_t handle, int flags, int argc, char *argv[]) { @@ -3652,186 +3748,195 @@ sa_legacy_share(sa_handle_t handle, int flags, int argc, char *argv[]) int true_legacy = 0; int curtype = SA_SHARE_TRANSIENT; char cmd[MAXPATHLEN]; -#ifdef lint - flags = flags; -#endif + sa_group_t group = NULL; + sa_share_t share; + char dir[MAXPATHLEN]; while ((c = getopt(argc, argv, "?hF:d:o:p")) != EOF) { - switch (c) { - case 'd': - description = optarg; - argsused++; - break; - case 'F': - protocol = optarg; - if (!sa_valid_protocol(protocol)) { - if (format_legacy_path(cmd, MAXPATHLEN, - protocol, "share") == 0 && check_legacy_cmd(cmd)) { - true_legacy++; - } else { - (void) fprintf(stderr, - gettext("Invalid protocol specified:" - "%s\n"), - protocol); - return (SA_INVALID_PROTOCOL); - } + switch (c) { + case 'd': + description = optarg; + argsused++; + break; + case 'F': + protocol = optarg; + if (!sa_valid_protocol(protocol)) { + if (format_legacy_path(cmd, MAXPATHLEN, + protocol, "share") == 0 && + check_legacy_cmd(cmd)) { + true_legacy++; + } else { + (void) fprintf(stderr, gettext( + "Invalid protocol specified: " + "%s\n"), protocol); + return (SA_INVALID_PROTOCOL); + } + } + break; + case 'o': + options = optarg; + argsused++; + break; + case 'p': + persist = SA_SHARE_PERMANENT; + argsused++; + break; + case 'h': + case '?': + default: + (void) fprintf(stderr, gettext("usage: %s\n"), + sa_get_usage(USAGE_SHARE)); + return (SA_OK); } - break; - case 'o': - options = optarg; - argsused++; - break; - case 'p': - persist = SA_SHARE_PERMANENT; - argsused++; - break; - case 'h': - case '?': - default: - (void) fprintf(stderr, gettext("usage: %s\n"), - sa_get_usage(USAGE_SHARE)); - return (SA_OK); - } } - /* have the info so construct what is needed */ + /* Have the info so construct what is needed */ if (!argsused && optind == argc) { - /* display current info in share format */ - (void) output_legacy_file(stdout, "nfs", handle); - } else { - sa_group_t group = NULL; - sa_share_t share; - char dir[MAXPATHLEN]; + /* display current info in share format */ + (void) output_legacy_file(stdout, "nfs", handle); + return (ret); + } - /* we are modifying the configuration */ - if (optind == argc) { + /* We are modifying the configuration */ + if (optind == argc) { (void) fprintf(stderr, gettext("usage: %s\n"), - sa_get_usage(USAGE_SHARE)); + sa_get_usage(USAGE_SHARE)); return (SA_LEGACY_ERR); - } - - if (true_legacy) { - /* if still using legacy share/unshare, exec it */ + } + if (true_legacy) { + /* If still using legacy share/unshare, exec it */ ret = run_legacy_command(cmd, argv); return (ret); - } + } - sharepath = argv[optind++]; - if (optind < argc) { + sharepath = argv[optind++]; + if (optind < argc) { resource = argv[optind]; groupname = strchr(resource, '@'); if (groupname != NULL) - *groupname++ = '\0'; - } - if (realpath(sharepath, dir) == NULL) + *groupname++ = '\0'; + } + if (realpath(sharepath, dir) == NULL) ret = SA_BAD_PATH; - else + else sharepath = dir; - if (ret == SA_OK) { + if (ret == SA_OK) share = sa_find_share(handle, sharepath); - } else { + else share = NULL; - } - if (groupname != NULL) { - ret = SA_NOT_ALLOWED; - } else if (ret == SA_OK) { + + if (groupname != NULL) { + ret = SA_NOT_ALLOWED; + } else if (ret == SA_OK) { char *legacygroup = "default"; /* - * the legacy group is always present and zfs groups + * The legacy group is always present and zfs groups * come and go. zfs shares may be in sub-groups and * the zfs share will already be in that group so it * isn't an error. */ - if (share != NULL) { /* - * if the share exists, then make sure it is one we - * want to handle. + * If the share exists (not NULL), then make sure it + * is one we want to handle by getting the parent + * group. */ - group = sa_get_parent_group(share); - } else { - group = sa_get_group(handle, legacygroup); - } + if (share != NULL) + group = sa_get_parent_group(share); + else + group = sa_get_group(handle, legacygroup); + if (group != NULL) { - groupstatus = group_status(group); - if (share == NULL) { - share = sa_add_share(group, sharepath, persist, &ret); - if (share == NULL && ret == SA_DUPLICATE_NAME) { - /* could be a ZFS path being started */ - if (sa_zfs_is_shared(handle, sharepath)) { - ret = SA_OK; - group = sa_get_group(handle, "zfs"); - if (group == NULL) { - /* this shouldn't happen */ - ret = SA_CONFIG_ERR; - } - if (group != NULL) { - share = sa_add_share(group, sharepath, + groupstatus = group_status(group); + if (share == NULL) { + share = sa_add_share(group, sharepath, + persist, &ret); + if (share == NULL && + ret == SA_DUPLICATE_NAME) { + /* + * Could be a ZFS path being started + */ + if (sa_zfs_is_shared(handle, + sharepath)) { + ret = SA_OK; + group = sa_get_group(handle, + "zfs"); + if (group == NULL) { + /* + * This shouldn't + * happen. + */ + ret = SA_CONFIG_ERR; + } else { + share = sa_add_share( + group, sharepath, persist, &ret); + } + } + } + } else { + char *type; + /* + * May want to change persist state, but the + * important thing is to change options. We + * need to change them regardless of the + * source. + */ + if (sa_zfs_is_shared(handle, sharepath)) { + zfs = 1; + } + remove_all_options(share, protocol); + type = sa_get_share_attr(share, "type"); + if (type != NULL && + strcmp(type, "transient") != 0) { + curtype = SA_SHARE_PERMANENT; + } + if (type != NULL) + sa_free_attr_string(type); + if (curtype != persist) { + (void) sa_set_share_attr(share, "type", + persist == SA_SHARE_PERMANENT ? + "persist" : "transient"); } - } } - } else { - char *type; - /* - * may want to change persist state, but the - * important thing is to change options. We - * need to change them regardless of the - * source. - */ - if (sa_zfs_is_shared(handle, sharepath)) { - zfs = 1; - } - remove_all_options(share, protocol); - type = sa_get_share_attr(share, "type"); - if (type != NULL && - strcmp(type, "transient") != 0) { - curtype = SA_SHARE_PERMANENT; - } - if (type != NULL) - sa_free_attr_string(type); - if (curtype != persist) { - (void) sa_set_share_attr(share, "type", - persist == SA_SHARE_PERMANENT ? - "persist" : "transient"); - } - } - /* have a group to hold this share path */ - if (ret == SA_OK && options != NULL && - strlen(options) > 0) { - ret = sa_parse_legacy_options(share, - options, - protocol); - } - if (!zfs) { - /* - * zfs shares never have resource or - * description and we can't store the values - * so don't try. - */ - if (ret == SA_OK && description != NULL) - ret = sa_set_share_description(share, description); - if (ret == SA_OK && resource != NULL) - ret = sa_set_share_attr(share, "resource", - resource); - } - if (ret == SA_OK) { - if (strcmp(groupstatus, "enabled") == 0) - ret = sa_enable_share(share, protocol); - if (ret == SA_OK && persist == SA_SHARE_PERMANENT) { - (void) sa_update_legacy(share, protocol); - } - if (ret == SA_OK) - ret = sa_update_config(handle); - } + /* Have a group to hold this share path */ + if (ret == SA_OK && options != NULL && + strlen(options) > 0) { + ret = sa_parse_legacy_options(share, + options, + protocol); + } + if (!zfs) { + /* + * ZFS shares never have resource or + * description and we can't store the values + * so don't try. + */ + if (ret == SA_OK && description != NULL) + ret = sa_set_share_description(share, + description); + if (ret == SA_OK && resource != NULL) + ret = sa_set_share_attr(share, + "resource", resource); + } + if (ret == SA_OK) { + if (strcmp(groupstatus, "enabled") == 0) + ret = sa_enable_share(share, protocol); + if (ret == SA_OK && + persist == SA_SHARE_PERMANENT) { + (void) sa_update_legacy(share, + protocol); + } + if (ret == SA_OK) + ret = sa_update_config(handle); + } } else { - ret = SA_SYSTEM_ERR; + ret = SA_SYSTEM_ERR; } - } } if (ret != SA_OK) { - (void) fprintf(stderr, gettext("Could not share: %s: %s\n"), - sharepath, sa_errorstr(ret)); - ret = SA_LEGACY_ERR; + (void) fprintf(stderr, gettext("Could not share: %s: %s\n"), + sharepath, sa_errorstr(ret)); + ret = SA_LEGACY_ERR; } return (ret); @@ -3842,7 +3947,7 @@ sa_legacy_share(sa_handle_t handle, int flags, int argc, char *argv[]) * * Implements the original unshare command. */ - +/*ARGSUSED*/ int sa_legacy_unshare(sa_handle_t handle, int flags, int argc, char *argv[]) { @@ -3855,105 +3960,102 @@ sa_legacy_unshare(sa_handle_t handle, int flags, int argc, char *argv[]) int ret = SA_OK; int true_legacy = 0; char cmd[MAXPATHLEN]; -#ifdef lint - flags = flags; - options = options; -#endif while ((c = getopt(argc, argv, "?hF:o:p")) != EOF) { - switch (c) { - case 'h': - case '?': - break; - case 'F': - protocol = optarg; - if (!sa_valid_protocol(protocol)) { - if (format_legacy_path(cmd, MAXPATHLEN, - protocol, "unshare") == 0 && - check_legacy_cmd(cmd)) { - true_legacy++; - } else { - (void) printf(gettext("Invalid file system name\n")); - return (SA_INVALID_PROTOCOL); - } + switch (c) { + case 'h': + case '?': + break; + case 'F': + protocol = optarg; + if (!sa_valid_protocol(protocol)) { + if (format_legacy_path(cmd, MAXPATHLEN, + protocol, "unshare") == 0 && + check_legacy_cmd(cmd)) { + true_legacy++; + } else { + (void) printf(gettext( + "Invalid file system name\n")); + return (SA_INVALID_PROTOCOL); + } + } + break; + case 'o': + options = optarg; + argsused++; + break; + case 'p': + persist = SA_SHARE_PERMANENT; + argsused++; + break; + default: + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_UNSHARE)); + return (SA_OK); } - break; - case 'o': - options = optarg; - argsused++; - break; - case 'p': - persist = SA_SHARE_PERMANENT; - argsused++; - break; - default: - (void) printf(gettext("usage: %s\n"), - sa_get_usage(USAGE_UNSHARE)); - return (SA_OK); - } } - /* have the info so construct what is needed */ - if (optind == argc || (optind + 1) < argc) { - ret = SA_SYNTAX_ERR; + /* Have the info so construct what is needed */ + if (optind == argc || (optind + 1) < argc || options != NULL) { + ret = SA_SYNTAX_ERR; } else { - sa_share_t share; - char dir[MAXPATHLEN]; - if (true_legacy) { - /* if still using legacy share/unshare, exec it */ - ret = run_legacy_command(cmd, argv); - return (ret); - } + sa_share_t share; + char dir[MAXPATHLEN]; + if (true_legacy) { + /* if still using legacy share/unshare, exec it */ + ret = run_legacy_command(cmd, argv); + return (ret); + } /* * Find the path in the internal configuration. If it * isn't found, attempt to resolve the path via * realpath() and try again. */ - sharepath = argv[optind++]; - share = sa_find_share(handle, sharepath); - if (share == NULL) { - if (realpath(sharepath, dir) == NULL) { - ret = SA_NO_SUCH_PATH; - } else { - share = sa_find_share(handle, dir); + sharepath = argv[optind++]; + share = sa_find_share(handle, sharepath); + if (share == NULL) { + if (realpath(sharepath, dir) == NULL) { + ret = SA_NO_SUCH_PATH; + } else { + share = sa_find_share(handle, dir); + } } - } - if (share != NULL) { - ret = sa_disable_share(share, protocol); - /* - * Errors are ok and removal should still occur. The - * legacy unshare is more forgiving of errors than the - * remove-share subcommand which may need the force - * flag set for some error conditions. That is, the - * "unshare" command will always unshare if it can - * while "remove-share" might require the force option. - */ - if (persist == SA_SHARE_PERMANENT) { - ret = sa_remove_share(share); - if (ret == SA_OK) - ret = sa_update_config(handle); + if (share != NULL) { + ret = sa_disable_share(share, protocol); + /* + * Errors are ok and removal should still occur. The + * legacy unshare is more forgiving of errors than the + * remove-share subcommand which may need the force + * flag set for some error conditions. That is, the + * "unshare" command will always unshare if it can + * while "remove-share" might require the force option. + */ + if (persist == SA_SHARE_PERMANENT) { + ret = sa_remove_share(share); + if (ret == SA_OK) + ret = sa_update_config(handle); + } + } else { + ret = SA_NOT_SHARED; } - } else { - ret = SA_NOT_SHARED; - } } switch (ret) { default: - (void) printf("%s: %s\n", sharepath, sa_errorstr(ret)); - ret = SA_LEGACY_ERR; - break; + (void) printf("%s: %s\n", sharepath, sa_errorstr(ret)); + ret = SA_LEGACY_ERR; + break; case SA_SYNTAX_ERR: - (void) printf(gettext("usage: %s\n"), - sa_get_usage(USAGE_UNSHARE)); - break; + (void) printf(gettext("usage: %s\n"), + sa_get_usage(USAGE_UNSHARE)); + break; case SA_OK: - break; + break; } return (ret); } /* - * common commands that implement the sub-commands used by all + * Common commands that implement the sub-commands used by all * protcols. The entries are found via the lookup command */ @@ -3984,66 +4086,69 @@ sa_get_usage(sa_usage_t index) char *ret = NULL; switch (index) { case USAGE_ADD_SHARE: - ret = gettext("add-share [-nth] [-r resource-name] " - "[-d \"description text\"] -s sharepath group"); - break; + ret = gettext("add-share [-nth] [-r resource-name] " + "[-d \"description text\"] -s sharepath group"); + break; case USAGE_CREATE: - ret = gettext("create [-nvh] [-P proto [-p property=value]] group"); - break; + ret = gettext( + "create [-nvh] [-P proto [-p property=value]] group"); + break; case USAGE_DELETE: - ret = gettext("delete [-nvh] [-P proto] [-f] group"); - break; + ret = gettext("delete [-nvh] [-P proto] [-f] group"); + break; case USAGE_DISABLE: - ret = gettext("disable [-nvh] {-a | group ...}"); - break; + ret = gettext("disable [-nvh] {-a | group ...}"); + break; case USAGE_ENABLE: - ret = gettext("enable [-nvh] {-a | group ...}"); - break; + ret = gettext("enable [-nvh] {-a | group ...}"); + break; case USAGE_LIST: - ret = gettext("list [-vh] [-P proto]"); - break; + ret = gettext("list [-vh] [-P proto]"); + break; case USAGE_MOVE_SHARE: - ret = gettext("move-share [-nvh] -s sharepath destination-group"); - break; + ret = gettext( + "move-share [-nvh] -s sharepath destination-group"); + break; case USAGE_REMOVE_SHARE: - ret = gettext("remove-share [-fnvh] -s sharepath group"); - break; + ret = gettext("remove-share [-fnvh] -s sharepath group"); + break; case USAGE_SET: - ret = gettext("set [-nvh] -P proto [-S optspace] " - "[-p property=value]* [-s sharepath] group"); - break; + ret = gettext("set [-nvh] -P proto [-S optspace] " + "[-p property=value]* [-s sharepath] group"); + break; case USAGE_SET_SECURITY: - ret = gettext("set-security [-nvh] -P proto -S security-type " - "[-p property=value]* group"); - break; + ret = gettext("set-security [-nvh] -P proto -S security-type " + "[-p property=value]* group"); + break; case USAGE_SET_SHARE: - ret = gettext("set-share [-nh] [-r resource] " - "[-d \"description text\"] -s sharepath group"); - break; + ret = gettext("set-share [-nh] [-r resource] " + "[-d \"description text\"] -s sharepath group"); + break; case USAGE_SHOW: - ret = gettext("show [-pvxh] [-P proto] [group ...]"); - break; + ret = gettext("show [-pvxh] [-P proto] [group ...]"); + break; case USAGE_SHARE: - ret = gettext("share [-F fstype] [-p] [-o optionlist]" - "[-d description] [pathname [resourcename]]"); - break; + ret = gettext("share [-F fstype] [-p] [-o optionlist]" + "[-d description] [pathname [resourcename]]"); + break; case USAGE_START: - ret = gettext("start [-vh] [-P proto] {-a | group ...}"); - break; + ret = gettext("start [-vh] [-P proto] {-a | group ...}"); + break; case USAGE_STOP: - ret = gettext("stop [-vh] [-P proto] {-a | group ...}"); - break; + ret = gettext("stop [-vh] [-P proto] {-a | group ...}"); + break; case USAGE_UNSET: - ret = gettext("unset [-nvh] -P proto [-S optspace] " - "[-p property]* group"); - break; + ret = gettext("unset [-nvh] -P proto [-S optspace] " + "[-p property]* group"); + break; case USAGE_UNSET_SECURITY: - ret = gettext("unset-security [-nvh] -P proto -S security-type " - "[-p property]* group"); - break; + ret = gettext("unset-security [-nvh] -P proto -S security-type" + " [-p property]* group"); + break; case USAGE_UNSHARE: - ret = gettext("unshare [-F fstype] [-p] [-o optionlist] sharepath"); - break; + ret = gettext( + "unshare [-F fstype] [-p] sharepath"); + break; } return (ret); } @@ -4054,36 +4159,31 @@ sa_get_usage(sa_usage_t index) * Lookup the sub-command. proto isn't currently used, but it may * eventually provide a way to provide protocol specific sub-commands. */ - +/*ARGSUSED*/ sa_command_t * sa_lookup(char *cmd, char *proto) { int i; size_t len; -#ifdef lint - proto = proto; -#endif len = strlen(cmd); for (i = 0; commands[i].cmdname != NULL; i++) { - if (strncmp(cmd, commands[i].cmdname, len) == 0) - return (&commands[i]); + if (strncmp(cmd, commands[i].cmdname, len) == 0) + return (&commands[i]); } return (NULL); } +/*ARGSUSED*/ void sub_command_help(char *proto) { int i; -#ifdef lint - proto = proto; -#endif (void) printf(gettext("\tsub-commands:\n")); for (i = 0; commands[i].cmdname != NULL; i++) { - if (!(commands[i].flags & (CMD_ALIAS|CMD_NODISPLAY))) - (void) printf("\t%s\n", - sa_get_usage((sa_usage_t)commands[i].cmdidx)); + if (!(commands[i].flags & (CMD_ALIAS|CMD_NODISPLAY))) + (void) printf("\t%s\n", + sa_get_usage((sa_usage_t)commands[i].cmdidx)); } } diff --git a/usr/src/cmd/dfs.cmds/sharemgr/sharemgr_main.c b/usr/src/cmd/dfs.cmds/sharemgr/sharemgr_main.c index 206895cf19..8fd346c678 100644 --- a/usr/src/cmd/dfs.cmds/sharemgr/sharemgr_main.c +++ b/usr/src/cmd/dfs.cmds/sharemgr/sharemgr_main.c @@ -73,23 +73,23 @@ main(int argc, char *argv[]) */ command = basename(argv[0]); if (strcmp(command, "share") != 0 && strcmp(command, "unshare") != 0) { - while ((c = getopt(argc, argv, "h?")) != EOF) { - switch (c) { - default: - case 'h': - case '?': - help = 1; - break; + while ((c = getopt(argc, argv, "h?")) != EOF) { + switch (c) { + default: + case 'h': + case '?': + help = 1; + break; + } } - } - if (argc == 1) - help = 1; + if (argc == 1) + help = 1; } if (strcmp(command, "sharemgr") == 0) { - command = argv[optind]; - argv++; - argc--; + command = argv[optind]; + argv++; + argc--; } if (help) { diff --git a/usr/src/lib/libshare/common/libsharecore.c b/usr/src/lib/libshare/common/libsharecore.c index cbef53feab..ba9d7f4b97 100644 --- a/usr/src/lib/libshare/common/libsharecore.c +++ b/usr/src/lib/libshare/common/libsharecore.c @@ -107,12 +107,12 @@ sablocksigs(sigset_t *sigs) sigset_t new; if (sigs != NULL) { - (void) sigprocmask(SIG_BLOCK, NULL, &new); - (void) sigaddset(&new, SIGHUP); - (void) sigaddset(&new, SIGINT); - (void) sigaddset(&new, SIGQUIT); - (void) sigaddset(&new, SIGTSTP); - (void) sigprocmask(SIG_SETMASK, &new, sigs); + (void) sigprocmask(SIG_BLOCK, NULL, &new); + (void) sigaddset(&new, SIGHUP); + (void) sigaddset(&new, SIGINT); + (void) sigaddset(&new, SIGQUIT); + (void) sigaddset(&new, SIGTSTP); + (void) sigprocmask(SIG_SETMASK, &new, sigs); } } @@ -125,7 +125,7 @@ void saunblocksigs(sigset_t *sigs) { if (sigs != NULL) - (void) sigprocmask(SIG_SETMASK, sigs, NULL); + (void) sigprocmask(SIG_SETMASK, sigs, NULL); } /* @@ -141,7 +141,7 @@ alloc_sharelist() item = (xfs_sharelist_t *)malloc(sizeof (xfs_sharelist_t)); if (item != NULL) - (void) memset(item, '\0', sizeof (xfs_sharelist_t)); + (void) memset(item, '\0', sizeof (xfs_sharelist_t)); return (item); } @@ -159,29 +159,29 @@ fix_notice(xfs_sharelist_t *list) int i; if (list == NULL) { - /* zero length dfstab */ - list = alloc_sharelist(); - if (list == NULL) - return (NULL); - list->description = strdup("#\n"); + /* zero length dfstab */ + list = alloc_sharelist(); + if (list == NULL) + return (NULL); + list->description = strdup("#\n"); } if (list->path == NULL && list->description != NULL && strcmp(list->description, notice[0]) != 0) { - for (prev = NULL, i = 0; i < DFSTAB_NOTICE_LINES; i++) { - item = alloc_sharelist(); - if (item != NULL) { - item->description = strdup(notice[i]); - if (prev == NULL) { - item->next = list; - prev = item; - list = item; - } else { - item->next = prev->next; - prev->next = item; - prev = item; - } + for (prev = NULL, i = 0; i < DFSTAB_NOTICE_LINES; i++) { + item = alloc_sharelist(); + if (item != NULL) { + item->description = strdup(notice[i]); + if (prev == NULL) { + item->next = list; + prev = item; + list = item; + } else { + item->next = prev->next; + prev->next = item; + prev = item; + } + } } - } } return (list); } @@ -208,94 +208,94 @@ getdfstab(FILE *dfs) xfs_sharelist_t *item = NULL, *first = NULL, *last; if (dfs != NULL) { - first = NULL; - line = 0; - while (fgets(buff, sizeof (buff), dfs) != NULL) { - line++; - bp = buff; - if (buff[0] == '#') { - item = alloc_sharelist(); - if (item != NULL) { - /* if no path, then comment */ - item->lineno = line; - item->description = strdup(buff); - if (first == NULL) { - first = item; - last = item; + first = NULL; + line = 0; + while (fgets(buff, sizeof (buff), dfs) != NULL) { + line++; + bp = buff; + if (buff[0] == '#') { + item = alloc_sharelist(); + if (item != NULL) { + /* if no path, then comment */ + item->lineno = line; + item->description = strdup(buff); + if (first == NULL) { + first = item; + last = item; + } else { + last->next = item; + last = item; + } + } else { + break; + } + continue; + } else if (buff[0] == '\n') { + continue; + } + optind = 1; + item = alloc_sharelist(); + if (item == NULL) { + break; + } else if (first == NULL) { + first = item; + last = item; } else { - last->next = item; - last = item; + last->next = item; + last = item; } - } else { - break; - } - continue; - } else if (buff[0] == '\n') { - continue; - } - optind = 1; - item = alloc_sharelist(); - if (item == NULL) { - break; - } else if (first == NULL) { - first = item; - last = item; - } else { - last->next = item; - last = item; - } - item->lineno = line; - item->origline = strdup(buff); - (void) get_token(NULL); /* reset to new pointers */ - argc = 0; - while ((token = get_token(bp)) != NULL) { - if (argc < MAXARGSFORSHARE) { - args[argc++] = token; - } - } - while ((c = getopt(argc, args, "F:o:d:pg:")) != -1) { - switch (c) { - case 'p': - item->persist = 1; - break; - case 'F': - item->fstype = strdup(optarg); - break; - case 'o': - item->options = strdup(optarg); - break; - case 'd': - item->description = strdup(optarg); - break; - case 'g': - item->group = strdup(optarg); - break; - default: - break; - } - } - if (optind < argc) { - item->path = strdup(args[optind]); - optind++; - if (optind < argc) { - char *resource; - char *optgroup; - /* resource and/or groupname */ - resource = args[optind]; - optgroup = strchr(resource, '@'); - if (optgroup != NULL) { - *optgroup++ = '\0'; + item->lineno = line; + item->origline = strdup(buff); + (void) get_token(NULL); /* reset to new pointers */ + argc = 0; + while ((token = get_token(bp)) != NULL) { + if (argc < MAXARGSFORSHARE) + args[argc++] = token; } - if (optgroup != NULL) - item->group = strdup(optgroup); - if (resource != NULL && strlen(resource) > 0) - item->resource = strdup(resource); - } - } - if (item != NULL && item->fstype == NULL) { - item->fstype = strdup("nfs"); /* this is the default */ + while ((c = getopt(argc, args, "F:o:d:pg:")) != -1) { + switch (c) { + case 'p': + item->persist = 1; + break; + case 'F': + item->fstype = strdup(optarg); + break; + case 'o': + item->options = strdup(optarg); + break; + case 'd': + item->description = strdup(optarg); + break; + case 'g': + item->group = strdup(optarg); + break; + default: + break; + } + } + if (optind < argc) { + item->path = strdup(args[optind]); + optind++; + if (optind < argc) { + char *resource; + char *optgroup; + /* resource and/or groupname */ + resource = args[optind]; + optgroup = strchr(resource, '@'); + if (optgroup != NULL) + *optgroup++ = '\0'; + if (optgroup != NULL) + item->group = strdup(optgroup); + if (resource != NULL && + strlen(resource) > 0) + item->resource = + strdup(resource); + } + } + /* NFS is the default if none defined */ + if (item != NULL && item->fstype == NULL) + item->fstype = strdup("nfs"); } - } } first = fix_notice(first); return (first); @@ -314,7 +314,7 @@ finddfsentry(xfs_sharelist_t *list, char *path) xfs_sharelist_t *item; for (item = list; item != NULL; item = item->next) { - if (item->path != NULL && strcmp(item->path, path) == 0) + if (item->path != NULL && strcmp(item->path, path) == 0) return (item); } return (NULL); @@ -335,27 +335,26 @@ remdfsentry(xfs_sharelist_t *list, char *path, char *proto) for (item = prev = list; item != NULL; item = item->next) { /* skip comment entry but don't lose it */ - if (item->path == NULL) { + if (item->path == NULL) { + prev = item; + continue; + } + /* if proto is NULL, remove all protocols */ + if (proto == NULL || (strcmp(item->path, path) == 0 && + (item->fstype != NULL && strcmp(item->fstype, proto) == 0))) + break; + if (item->fstype == NULL && + (proto == NULL || strcmp(proto, "nfs") == 0)) + break; prev = item; - continue; - } - /* if proto is NULL, remove all protocols */ - if (proto == NULL || (strcmp(item->path, path) == 0 && - (item->fstype != NULL && strcmp(item->fstype, proto) == 0))) - break; - if (item->fstype == NULL && - (proto == NULL || strcmp(proto, "nfs") == 0)) - break; - prev = item; } if (item != NULL) { - if (item == prev) { - list = item->next; /* this must be the first one */ - } else { - prev->next = item->next; - } - item->next = NULL; - dfs_free_list(item); + if (item == prev) + list = item->next; /* this must be the first one */ + else + prev->next = item->next; + item->next = NULL; + dfs_free_list(item); } return (list); } @@ -372,24 +371,22 @@ remdfsline(xfs_sharelist_t *list, char *line) xfs_sharelist_t *item, *prev = NULL; for (item = prev = list; item != NULL; item = item->next) { - /* skip comment entry but don't lose it */ - if (item->path == NULL) { + /* skip comment entry but don't lose it */ + if (item->path == NULL) { prev = item; continue; - } - if (strcmp(item->origline, line) == 0) { - break; - } - prev = item; + } + if (strcmp(item->origline, line) == 0) + break; + prev = item; } if (item != NULL) { - if (item == prev) { - list = item->next; /* this must be the first one */ - } else { - prev->next = item->next; - } - item->next = NULL; - dfs_free_list(item); + if (item == prev) + list = item->next; /* this must be the first one */ + else + prev->next = item->next; + item->next = NULL; + dfs_free_list(item); } return (list); } @@ -410,33 +407,34 @@ adddfsentry(xfs_sharelist_t *list, sa_share_t share, char *proto) item = alloc_sharelist(); if (item != NULL) { - parent = sa_get_parent_group(share); - groupname = sa_get_group_attr(parent, "name"); - if (strcmp(groupname, "default") == 0) { - sa_free_attr_string(groupname); - groupname = NULL; - } - item->path = sa_get_share_attr(share, "path"); - item->resource = sa_get_share_attr(share, "resource"); - item->group = groupname; - item->fstype = strdup(proto); - item->options = sa_proto_legacy_format(proto, share, 1); - if (item->options != NULL && strlen(item->options) == 0) { - free(item->options); - item->options = NULL; - } - item->description = sa_get_share_description(share); - if (item->description != NULL && strlen(item->description) == 0) { - sa_free_share_description(item->description); - item->description = NULL; - } - if (list == NULL) { - list = item; - } else { - for (tmp = list; tmp->next != NULL; tmp = tmp->next) - /* do nothing */; - tmp->next = item; - } + parent = sa_get_parent_group(share); + groupname = sa_get_group_attr(parent, "name"); + if (strcmp(groupname, "default") == 0) { + sa_free_attr_string(groupname); + groupname = NULL; + } + item->path = sa_get_share_attr(share, "path"); + item->resource = sa_get_share_attr(share, "resource"); + item->group = groupname; + item->fstype = strdup(proto); + item->options = sa_proto_legacy_format(proto, share, 1); + if (item->options != NULL && strlen(item->options) == 0) { + free(item->options); + item->options = NULL; + } + item->description = sa_get_share_description(share); + if (item->description != NULL && + strlen(item->description) == 0) { + sa_free_share_description(item->description); + item->description = NULL; + } + if (list == NULL) { + list = item; + } else { + for (tmp = list; tmp->next != NULL; tmp = tmp->next) + /* do nothing */; + tmp->next = item; + } } return (list); } @@ -456,32 +454,36 @@ outdfstab(FILE *dfstab, xfs_sharelist_t *list) (void) ftruncate(fileno(dfstab), 0); for (item = list; item != NULL; item = item->next) { - if (item->path != NULL) { - if (*item->path == '/') - (void) fprintf(dfstab, "share %s%s%s%s%s%s%s %s%s%s%s%s\n", - (item->fstype != NULL) ? "-F " : "", - (item->fstype != NULL) ? item->fstype : "", - (item->options != NULL) ? " -o " : "", - (item->options != NULL) ? item->options : "", - (item->description != NULL) ? " -d \"" : "", - (item->description != NULL) ? - item->description : "", - (item->description != NULL) ? "\"" : "", - item->path, - ((item->resource != NULL) || - (item->group != NULL)) ? " " : "", - (item->resource != NULL) ? item->resource : "", - item->group != NULL ? "@" : "", - item->group != NULL ? item->group : ""); - else - (void) fprintf(dfstab, "%s", item->origline); - } else { - if (item->description != NULL) { - (void) fprintf(dfstab, "%s", item->description); + if (item->path != NULL) { + if (*item->path == '/') { + (void) fprintf(dfstab, + "share %s%s%s%s%s%s%s %s%s%s%s%s\n", + (item->fstype != NULL) ? "-F " : "", + (item->fstype != NULL) ? item->fstype : "", + (item->options != NULL) ? " -o " : "", + (item->options != NULL) ? + item->options : "", + (item->description != NULL) ? + " -d \"" : "", + (item->description != NULL) ? + item->description : "", + (item->description != NULL) ? "\"" : "", + item->path, + ((item->resource != NULL) || + (item->group != NULL)) ? " " : "", + (item->resource != NULL) ? + item->resource : "", + item->group != NULL ? "@" : "", + item->group != NULL ? item->group : ""); + } else { + (void) fprintf(dfstab, "%s", item->origline); + } } else { - (void) fprintf(dfstab, "%s", item->origline); + if (item->description != NULL) + (void) fprintf(dfstab, "%s", item->description); + else + (void) fprintf(dfstab, "%s", item->origline); } - } } } @@ -503,20 +505,21 @@ open_dfstab(char *file) dfstab = fopen(file, "r+"); if (dfstab == NULL) { - dfstab = fopen(file, "w+"); + dfstab = fopen(file, "w+"); } if (dfstab != NULL) { grsize = sysconf(_SC_GETGR_R_SIZE_MAX); buff = malloc(grsize); if (buff != NULL) - grp = getgrnam_r(SA_DEFAULT_FILE_GRP, &group, buff, grsize); + grp = getgrnam_r(SA_DEFAULT_FILE_GRP, &group, buff, + grsize); else - grp = getgrnam(SA_DEFAULT_FILE_GRP); /* take the risk */ + grp = getgrnam(SA_DEFAULT_FILE_GRP); (void) fchmod(fileno(dfstab), 0644); (void) fchown(fileno(dfstab), 0, - grp != NULL ? grp->gr_gid : 3); + grp != NULL ? grp->gr_gid : 3); if (buff != NULL) - free(buff); + free(buff); rewind(dfstab); } return (dfstab); @@ -555,7 +558,7 @@ sa_comment_line(char *line, char *err) (void) fclose(dfstab); saunblocksigs(&old); if (list != NULL) - dfs_free_list(list); + dfs_free_list(list); } } @@ -584,46 +587,48 @@ sa_delete_legacy(sa_share_t share) path = sa_get_share_attr(share, "path"); parent = sa_get_parent_group(share); if (parent != NULL) { - (void) lockf(fileno(dfstab), F_LOCK, 0); - list = getdfstab(dfstab); - rewind(dfstab); - for (optionset = sa_get_optionset(parent, NULL); - optionset != NULL; - optionset = sa_get_next_optionset(optionset)) { - char *proto = sa_get_optionset_attr(optionset, "type"); - if (list != NULL && proto != NULL) - list = remdfsentry(list, path, proto); - if (proto == NULL) - ret = SA_NO_MEMORY; - /* - * may want to only do the dfstab if this call - * returns NOT IMPLEMENTED but it shouldn't - * hurt. - */ - if (ret == SA_OK) { - err = sa_proto_delete_legacy(proto, share); - if (err != SA_NOT_IMPLEMENTED) - ret = err; + (void) lockf(fileno(dfstab), F_LOCK, 0); + list = getdfstab(dfstab); + rewind(dfstab); + for (optionset = sa_get_optionset(parent, NULL); + optionset != NULL; + optionset = sa_get_next_optionset(optionset)) { + char *proto = sa_get_optionset_attr(optionset, + "type"); + if (list != NULL && proto != NULL) + list = remdfsentry(list, path, + proto); + if (proto == NULL) + ret = SA_NO_MEMORY; + /* + * May want to only do the dfstab if + * this call returns NOT IMPLEMENTED + * but it shouldn't hurt. + */ + if (ret == SA_OK) { + err = sa_proto_delete_legacy(proto, + share); + if (err != SA_NOT_IMPLEMENTED) + ret = err; + } + if (proto != NULL) + sa_free_attr_string(proto); } - if (proto != NULL) - sa_free_attr_string(proto); - } - outdfstab(dfstab, list); - if (list != NULL) - dfs_free_list(list); - (void) fflush(dfstab); - (void) lockf(fileno(dfstab), F_ULOCK, 0); + outdfstab(dfstab, list); + if (list != NULL) + dfs_free_list(list); + (void) fflush(dfstab); + (void) lockf(fileno(dfstab), F_ULOCK, 0); } (void) fsync(fileno(dfstab)); saunblocksigs(&old); (void) fclose(dfstab); sa_free_attr_string(path); } else { - if (errno == EACCES || errno == EPERM) { - ret = SA_NO_PERMISSION; - } else { - ret = SA_CONFIG_ERR; - } + if (errno == EACCES || errno == EPERM) + ret = SA_NO_PERMISSION; + else + ret = SA_CONFIG_ERR; } return (ret); } @@ -653,7 +658,7 @@ sa_update_legacy(sa_share_t share, char *proto) ret = sa_proto_update_legacy(proto, share); if (ret != SA_NOT_IMPLEMENTED) - return (ret); + return (ret); /* do the dfstab format */ persist = sa_get_share_attr(share, "type"); /* @@ -661,36 +666,35 @@ sa_update_legacy(sa_share_t share, char *proto) * set or the type is not "transient". */ if (persist == NULL || strcmp(persist, "transient") != 0) { - dfstab = open_dfstab(SA_LEGACY_DFSTAB); - if (dfstab != NULL) { - (void) setvbuf(dfstab, NULL, _IOLBF, BUFSIZ * 8); - sablocksigs(&old); - path = sa_get_share_attr(share, "path"); - (void) lockf(fileno(dfstab), F_LOCK, 0); - list = getdfstab(dfstab); - rewind(dfstab); - if (list != NULL) - list = remdfsentry(list, path, proto); - list = adddfsentry(list, share, proto); - outdfstab(dfstab, list); - (void) fflush(dfstab); - (void) lockf(fileno(dfstab), F_ULOCK, 0); - (void) fsync(fileno(dfstab)); - saunblocksigs(&old); - (void) fclose(dfstab); - sa_free_attr_string(path); - if (list != NULL) - dfs_free_list(list); - } else { - if (errno == EACCES || errno == EPERM) { - ret = SA_NO_PERMISSION; + dfstab = open_dfstab(SA_LEGACY_DFSTAB); + if (dfstab != NULL) { + (void) setvbuf(dfstab, NULL, _IOLBF, BUFSIZ * 8); + sablocksigs(&old); + path = sa_get_share_attr(share, "path"); + (void) lockf(fileno(dfstab), F_LOCK, 0); + list = getdfstab(dfstab); + rewind(dfstab); + if (list != NULL) + list = remdfsentry(list, path, proto); + list = adddfsentry(list, share, proto); + outdfstab(dfstab, list); + (void) fflush(dfstab); + (void) lockf(fileno(dfstab), F_ULOCK, 0); + (void) fsync(fileno(dfstab)); + saunblocksigs(&old); + (void) fclose(dfstab); + sa_free_attr_string(path); + if (list != NULL) + dfs_free_list(list); } else { - ret = SA_CONFIG_ERR; + if (errno == EACCES || errno == EPERM) + ret = SA_NO_PERMISSION; + else + ret = SA_CONFIG_ERR; } - } } if (persist != NULL) - sa_free_attr_string(persist); + sa_free_attr_string(persist); return (ret); } @@ -706,14 +710,14 @@ sa_is_security(char *optname, char *proto) { int ret = 0; if (proto != NULL) - ret = sa_proto_security_prop(proto, optname); + ret = sa_proto_security_prop(proto, optname); return (ret); } /* * add_syntax_comment(root, line, err, todfstab) * - * add a comment to the document indicating a syntax error. If + * Add a comment to the document indicating a syntax error. If * todfstab is set, write it back to the dfstab file as well. */ @@ -723,11 +727,10 @@ add_syntax_comment(xmlNodePtr root, char *line, char *err, int todfstab) xmlNodePtr node; node = xmlNewChild(root, NULL, (xmlChar *)"error", (xmlChar *)line); - if (node != NULL) { - xmlSetProp(node, (xmlChar *)"type", (xmlChar *)err); - } + if (node != NULL) + xmlSetProp(node, (xmlChar *)"type", (xmlChar *)err); if (todfstab) - sa_comment_line(line, err); + sa_comment_line(line, err); } /* @@ -740,7 +743,7 @@ int sa_is_share(void *object) { if (object != NULL) { - if (strcmp((char *)((xmlNodePtr)object)->name, "share") == 0) + if (strcmp((char *)((xmlNodePtr)object)->name, "share") == 0) return (1); } return (0); @@ -775,22 +778,22 @@ _sa_create_dummy_share() parent_node = xmlNewNode(NULL, (xmlChar *)"group"); if (parent_node != NULL) { - child_node = xmlNewChild(parent_node, NULL, (xmlChar *)"share", - NULL); - if (child_node != NULL) { - /* - * Use a "zfs" tag since that will make sure nothing - * really attempts to put values into the - * repository. Also ZFS is currently the only user of - * this interface. - */ - set_node_attr(parent_node, "type", "transient"); - set_node_attr(parent_node, "zfs", "true"); - set_node_attr(child_node, "type", "transient"); - set_node_attr(child_node, "zfs", "true"); - } else { - xmlFreeNode(parent_node); - } + child_node = xmlNewChild(parent_node, NULL, (xmlChar *)"share", + NULL); + if (child_node != NULL) { + /* + * Use a "zfs" tag since that will make sure nothing + * really attempts to put values into the + * repository. Also ZFS is currently the only user of + * this interface. + */ + set_node_attr(parent_node, "type", "transient"); + set_node_attr(parent_node, "zfs", "true"); + set_node_attr(child_node, "type", "transient"); + set_node_attr(child_node, "zfs", "true"); + } else { + xmlFreeNode(parent_node); + } } return (child_node); } @@ -811,24 +814,24 @@ _sa_free_dummy_share(sa_share_t share) char *name; if (node != NULL) { - parent = node->parent; - name = (char *)xmlGetProp(node, (xmlChar *)"path"); - if (name != NULL) { - /* Real shares always have a path but a dummy doesn't */ - ret = SA_NOT_ALLOWED; - sa_free_attr_string(name); - } else { - /* - * If there is a parent, do the free on that since - * xmlFreeNode is a recursive function and free's an - * child nodes. - */ - if (parent != NULL) { - node = parent; + parent = node->parent; + name = (char *)xmlGetProp(node, (xmlChar *)"path"); + if (name != NULL) { + /* Real shares always have a path but a dummy doesn't */ + ret = SA_NOT_ALLOWED; + sa_free_attr_string(name); + } else { + /* + * If there is a parent, do the free on that since + * xmlFreeNode is a recursive function and free's an + * child nodes. + */ + if (parent != NULL) { + node = parent; + } + xmlUnlinkNode(node); + xmlFreeNode(node); } - xmlUnlinkNode(node); - xmlFreeNode(node); - } } return (ret); } @@ -855,127 +858,144 @@ sa_parse_legacy_options(sa_group_t group, char *options, char *proto) sa_group_t parent; int using_dummy = B_FALSE; char *pvalue; + sa_optionset_t optionset; + sa_property_t popt, prop; + sa_optionset_t localoptions; /* - * if "group" is NULL, this is just a parse without saving + * If "group" is NULL, this is just a parse without saving * anything in either SMF or ZFS. Create a dummy group to * handle this case. */ if (group == NULL) { - group = (sa_group_t)_sa_create_dummy_share(); - using_dummy = B_TRUE; + group = (sa_group_t)_sa_create_dummy_share(); + using_dummy = B_TRUE; } parent = sa_get_parent_group(group); if (proto != NULL) - ret = sa_proto_legacy_opts(proto, group, options); + ret = sa_proto_legacy_opts(proto, group, options); if (using_dummy) { - /* Since this is a dummy parse, cleanup and quit here */ - (void) _sa_free_dummy_share(parent); - return (ret); + /* Since this is a dummy parse, cleanup and quit here */ + (void) _sa_free_dummy_share(parent); + return (ret); } + + if (ret != SA_OK) + return (ret); + /* - * if in a group, remove the inherited options and security + * If in a group, remove the inherited options and security */ - if (ret == SA_OK) { - if (parent != NULL) { - sa_optionset_t optionset; - sa_property_t popt, prop; - sa_optionset_t localoptions; - /* find parent options to remove from child */ - optionset = sa_get_derived_optionset(parent, proto, 1); - localoptions = sa_get_optionset(group, proto); - if (optionset != NULL) { - for (popt = sa_get_property(optionset, NULL); - popt != NULL; - popt = sa_get_next_property(popt)) { + + if (parent == NULL) + return (ret); + + /* Find parent options to remove from child */ + optionset = sa_get_derived_optionset(parent, proto, 1); + localoptions = sa_get_optionset(group, proto); + if (optionset != NULL) { + for (popt = sa_get_property(optionset, NULL); + popt != NULL; + popt = sa_get_next_property(popt)) { char *tag; char *value; - tag = sa_get_property_attr(popt, "type"); - if (tag != NULL) { - prop = sa_get_property(localoptions, tag); - if (prop != NULL) { - value = sa_get_property_attr(popt, "value"); - pvalue = sa_get_property_attr(prop, "value"); + if (tag == NULL) + continue; + prop = sa_get_property(localoptions, tag); + if (prop != NULL) { + value = sa_get_property_attr(popt, + "value"); + pvalue = sa_get_property_attr(prop, + "value"); if (value != NULL && pvalue != NULL && strcmp(value, pvalue) == 0) { /* - * Remove the property from the - * child. While we removed it, we - * don't need to reset as we do - * below since we always search - * from the beginning. + * Remove the property + * from the + * child. While we + * removed it, we + * don't need to reset + * as we do below + * since we always + * search from the + * beginning. */ - (void) _sa_remove_property(prop); + (void) _sa_remove_property( + prop); } if (value != NULL) - sa_free_attr_string(value); + sa_free_attr_string(value); if (pvalue != NULL) - sa_free_attr_string(pvalue); - } - sa_free_attr_string(tag); + sa_free_attr_string(pvalue); } - } - prop = sa_get_property(localoptions, NULL); - if (prop == NULL && sa_is_share(group)) { + sa_free_attr_string(tag); + } + prop = sa_get_property(localoptions, NULL); + if (prop == NULL && sa_is_share(group)) { /* - * all properties removed so remove the + * All properties removed so remove the * optionset if it is on a share */ (void) _sa_remove_optionset(localoptions); - } - sa_free_derived_optionset(optionset); } - /* - * need to remove security here. If there are no - * security options on the local group/share, don't - * bother since those are the only ones that would be - * affected. - */ - localoptions = sa_get_all_security_types(group, proto, 0); - if (localoptions != NULL) { - for (prop = sa_get_property(localoptions, NULL); - prop != NULL; prop = sa_get_next_property(prop)) { + sa_free_derived_optionset(optionset); + } + /* + * Need to remove security here. If there are no + * security options on the local group/share, don't + * bother since those are the only ones that would be + * affected. + */ + localoptions = sa_get_all_security_types(group, proto, 0); + if (localoptions != NULL) { + for (prop = sa_get_property(localoptions, NULL); + prop != NULL; + prop = sa_get_next_property(prop)) { char *tag; sa_security_t security; tag = sa_get_property_attr(prop, "type"); if (tag != NULL) { - sa_property_t nextpopt = NULL; - - security = sa_get_security(group, tag, proto); - sa_free_attr_string(tag); - /* prop's value only changes outside this loop */ - pvalue = sa_get_property_attr(prop, "value"); - for (popt = sa_get_property(security, NULL); - popt != NULL; - popt = nextpopt) { - char *value; + sa_property_t nextpopt = NULL; + security = sa_get_security(group, tag, proto); + sa_free_attr_string(tag); /* - * Need to get the next prop now since - * we could break the list during removal. + * prop's value only changes outside this loop */ - nextpopt = sa_get_next_property(popt); - - /* remove duplicates from this level */ - value = sa_get_property_attr(popt, "value"); - if (value != NULL && pvalue != NULL && - strcmp(value, pvalue) == 0) { - /* remove the property from the child */ - (void) _sa_remove_property(popt); + pvalue = sa_get_property_attr(prop, "value"); + for (popt = sa_get_property(security, NULL); + popt != NULL; + popt = nextpopt) { + char *value; + /* + * Need to get the next prop + * now since we could break + * the list during removal. + */ + nextpopt = sa_get_next_property(popt); + /* remove Duplicates from this level */ + value = sa_get_property_attr(popt, + "value"); + if (value != NULL && pvalue != NULL && + strcmp(value, pvalue) == 0) { + /* + * remove the property + * from the child + */ + (void) _sa_remove_property + (popt); + } + if (value != NULL) + sa_free_attr_string(value); } - if (value != NULL) - sa_free_attr_string(value); - } - if (pvalue != NULL) - sa_free_attr_string(pvalue); + if (pvalue != NULL) + sa_free_attr_string(pvalue); } - } - (void) sa_destroy_optionset(localoptions); } - } + (void) sa_destroy_optionset(localoptions); } return (ret); } @@ -993,22 +1013,22 @@ dfs_free_list(xfs_sharelist_t *list) { xfs_sharelist_t *entry; for (entry = list; entry != NULL; entry = list) { - if (entry->path != NULL) - free(entry->path); - if (entry->resource != NULL) - free(entry->resource); - if (entry->fstype != NULL) - free(entry->fstype); - if (entry->options != NULL) - free(entry->options); - if (entry->description != NULL) - free(entry->description); - if (entry->origline != NULL) - free(entry->origline); - if (entry->group != NULL) - free(entry->group); - list = list->next; - free(entry); + if (entry->path != NULL) + free(entry->path); + if (entry->resource != NULL) + free(entry->resource); + if (entry->fstype != NULL) + free(entry->fstype); + if (entry->options != NULL) + free(entry->options); + if (entry->description != NULL) + free(entry->description); + if (entry->origline != NULL) + free(entry->origline); + if (entry->group != NULL) + free(entry->group); + list = list->next; + free(entry); } } @@ -1036,131 +1056,128 @@ parse_dfstab(sa_handle_t handle, char *dfstab, xmlNodePtr root) /* read the dfstab format file and fill in the doc tree */ dfs = fopen(dfstab, "r"); - if (dfs == NULL) { - return; - } + if (dfs == NULL) + return; defgroup = sa_get_group(handle, "default"); for (head = list = getdfstab(dfs); - list != NULL; - list = list->next) { - share = NULL; - group = NULL; - defined_group = 0; - err = 0; - - if (list->origline == NULL) { - /* - * Comment line that we will likely skip. - * If the line has the syntax: - * # error: string: string - * It should be preserved until manually deleted. - */ - if (list->description != NULL && - strncmp(list->description, "# Error: ", 9) == 0) { - char *line; - char *error; - char *cmd; - line = strdup(list->description); - if (line != NULL) { - error = line + 9; - cmd = strchr(error, ':'); - if (cmd != NULL) { - int len; - *cmd = '\0'; - cmd += 2; - len = strlen(cmd); - cmd[len - 1] = '\0'; - add_syntax_comment(root, cmd, error, 0); + list != NULL; + list = list->next) { + share = NULL; + group = NULL; + defined_group = 0; + err = 0; + + if (list->origline == NULL) { + /* + * Comment line that we will likely skip. + * If the line has the syntax: + * # error: string: string + * It should be preserved until manually deleted. + */ + if (list->description != NULL && + strncmp(list->description, "# Error: ", 9) == 0) { + char *line; + char *error; + char *cmd; + line = strdup(list->description); + if (line != NULL) { + error = line + 9; + cmd = strchr(error, ':'); + if (cmd != NULL) { + int len; + *cmd = '\0'; + cmd += 2; + len = strlen(cmd); + cmd[len - 1] = '\0'; + add_syntax_comment(root, cmd, + error, 0); + } + free(line); + } } - free(line); - } + continue; } - continue; - } - if (list->path != NULL && strlen(list->path) > 0 && + if (list->path != NULL && strlen(list->path) > 0 && *list->path == '/') { - share = sa_find_share(handle, list->path); - if (share != NULL) - sgroup = sa_get_parent_group(share); - else - sgroup = NULL; - } else { - (void) printf(dgettext(TEXT_DOMAIN, - "No share specified in dfstab: " - "line %d: %s\n"), - list->lineno, list->origline); - add_syntax_comment(root, list->origline, - dgettext(TEXT_DOMAIN, "No share specified"), - 1); - continue; - } - if (list->group != NULL && strlen(list->group) > 0) { - group = sa_get_group(handle, list->group); - defined_group = 1; - } else { - group = defgroup; - } - if (defined_group && group == NULL) { - (void) printf(dgettext(TEXT_DOMAIN, - "Unknown group used in dfstab: " - "line %d: %s\n"), - list->lineno, list->origline); - add_syntax_comment(root, list->origline, - dgettext(TEXT_DOMAIN, - "Unknown group specified"), 1); - continue; - } - if (group != NULL) { + share = sa_find_share(handle, list->path); + if (share != NULL) + sgroup = sa_get_parent_group(share); + else + sgroup = NULL; + } else { + (void) printf(dgettext(TEXT_DOMAIN, + "No share specified in dfstab: " + "line %d: %s\n"), + list->lineno, list->origline); + add_syntax_comment(root, list->origline, + dgettext(TEXT_DOMAIN, "No share specified"), 1); + continue; + } + if (list->group != NULL && strlen(list->group) > 0) { + group = sa_get_group(handle, list->group); + defined_group = 1; + } else { + group = defgroup; + } + if (defined_group && group == NULL) { + (void) printf(dgettext(TEXT_DOMAIN, + "Unknown group used in dfstab: line %d: %s\n"), + list->lineno, list->origline); + add_syntax_comment(root, list->origline, + dgettext(TEXT_DOMAIN, "Unknown group specified"), + 1); + continue; + } + if (group == NULL) { + /* Shouldn't happen unless an SMF error */ + err = SA_CONFIG_ERR; + continue; + } if (share == NULL) { - if (!defined_group && group == defgroup) { - /* this is an OK add for legacy */ + if (defined_group || group != defgroup) + continue; + /* This is an OK add for legacy */ share = sa_add_share(defgroup, list->path, - SA_SHARE_PERMANENT | SA_SHARE_PARSER, - &err); + SA_SHARE_PERMANENT | SA_SHARE_PARSER, &err); if (share != NULL) { - if (list->description != NULL && - strlen(list->description) > 0) - (void) sa_set_share_description(share, - list->description); - if (list->options != NULL && - strlen(list->options) > 0) { - (void) sa_parse_legacy_options(share, - list->options, - list->fstype); - } - if (list->resource != NULL) - (void) sa_set_share_attr(share, "resource", - list->resource); + if (list->description != NULL && + strlen(list->description) > 0) + (void) sa_set_share_description(share, + list->description); + if (list->options != NULL && + strlen(list->options) > 0) { + (void) sa_parse_legacy_options(share, + list->options, list->fstype); + } + if (list->resource != NULL) + (void) sa_set_share_attr(share, + "resource", list->resource); } else { - (void) printf(dgettext(TEXT_DOMAIN, - "Error in dfstab: " - "line %d: %s\n"), + (void) printf(dgettext(TEXT_DOMAIN, + "Error in dfstab: line %d: %s\n"), list->lineno, list->origline); - if (err != SA_BAD_PATH) - add_syntax_comment(root, list->origline, - dgettext(TEXT_DOMAIN, - "Syntax"), 1); - else - add_syntax_comment(root, list->origline, - dgettext(TEXT_DOMAIN, - "Path"), 1); - continue; + if (err != SA_BAD_PATH) + add_syntax_comment(root, list->origline, + dgettext(TEXT_DOMAIN, "Syntax"), 1); + else + add_syntax_comment(root, list->origline, + dgettext(TEXT_DOMAIN, + "Path"), 1); + continue; } - } } else { - if (group != sgroup) { - (void) printf(dgettext(TEXT_DOMAIN, "Attempt to change" - "configuration in" - "dfstab: line %d: %s\n"), - list->lineno, list->origline); - add_syntax_comment(root, list->origline, - dgettext(TEXT_DOMAIN, - "Attempt to change configuration"), - 1); - continue; - } + if (group != sgroup) { + (void) printf(dgettext(TEXT_DOMAIN, + "Attempt to change configuration in " + "dfstab: line %d: %s\n"), + list->lineno, list->origline); + add_syntax_comment(root, list->origline, + dgettext(TEXT_DOMAIN, + "Attempt to change configuration"), 1); + continue; + } /* * It is the same group but could have changed * options. Make sure we include the group's @@ -1169,36 +1186,35 @@ parse_dfstab(sa_handle_t handle, char *dfstab, xmlNodePtr root) * true says to get the inherited properties as well * as the local properties. */ - oldprops = sa_proto_legacy_format(list->fstype, share, - B_TRUE); - if (oldprops != NULL) { + oldprops = sa_proto_legacy_format(list->fstype, share, + B_TRUE); + + if (oldprops == NULL) + continue; + if (list->options != NULL && - strcmp(oldprops, list->options) != 0) { - sa_optionset_t opts; - sa_security_t secs; - /* possibly different values */ - opts = sa_get_optionset((sa_group_t)share, - list->fstype); - (void) sa_destroy_optionset(opts); - for (secs = sa_get_security((sa_group_t)share, - NULL, list->fstype); - secs != NULL; - secs = sa_get_security((sa_group_t)share, - NULL, list->fstype)) { - (void) sa_destroy_security(secs); - } - (void) sa_parse_legacy_options(share, - list->options, - list->fstype); + strcmp(oldprops, list->options) != 0) { + sa_optionset_t opts; + sa_security_t secs; + + /* possibly different values */ + opts = sa_get_optionset((sa_group_t) + share, list->fstype); + (void) sa_destroy_optionset(opts); + + for (secs = sa_get_security( + (sa_group_t)share, NULL, list->fstype); + secs != NULL; + secs = sa_get_security((sa_group_t)share, + NULL, list->fstype)) { + (void) sa_destroy_security( + secs); + } + (void) sa_parse_legacy_options(share, + list->options, list->fstype); } sa_format_free(oldprops); - } } - } else { - /* shouldn't happen */ - err = SA_CONFIG_ERR; - } - } dfs_free_list(head); } @@ -1223,27 +1239,30 @@ legacy_removes(sa_group_t group, char *file) dfstab = fopen(file, "r"); if (dfstab != NULL) { - list = getdfstab(dfstab); - (void) fclose(dfstab); + list = getdfstab(dfstab); + (void) fclose(dfstab); retry: - for (share = sa_get_share(group, NULL); share != NULL; - share = sa_get_next_share(share)) { - /* now see if the share is in the dfstab file */ - path = sa_get_share_attr(share, "path"); - if (path != NULL) { - item = finddfsentry(list, path); - sa_free_attr_string(path); - if (item == NULL) { - /* the share was removed this way */ - (void) sa_remove_share(share); - - /* start over since the list was broken */ - goto retry; - } + for (share = sa_get_share(group, NULL); + share != NULL; + share = sa_get_next_share(share)) { + /* now see if the share is in the dfstab file */ + path = sa_get_share_attr(share, "path"); + if (path != NULL) { + item = finddfsentry(list, path); + sa_free_attr_string(path); + if (item == NULL) { + /* The share was removed this way */ + (void) sa_remove_share(share); + + /* + * Start over since the list was broken + */ + goto retry; + } + } } - } - if (list != NULL) - dfs_free_list(list); + if (list != NULL) + dfs_free_list(list); } } @@ -1260,25 +1279,24 @@ getlegacyconfig(sa_handle_t handle, char *path, xmlNodePtr *root) sa_group_t defgroup; if (root != NULL) { - if (*root == NULL) - *root = xmlNewNode(NULL, (xmlChar *)"sharecfg"); - if (*root != NULL) { - if (strcmp(path, SA_LEGACY_DFSTAB) == 0) { - /* - * walk the default shares and find anything - * missing. we do this first to make sure it - * is cleaned up since there may be legacy - * code add/del via dfstab and we need to - * cleanup SMF. - */ - defgroup = sa_get_group(handle, "default"); - if (defgroup != NULL) { - legacy_removes(defgroup, path); - } - /* parse the dfstab and add anything new */ - parse_dfstab(handle, path, *root); + if (*root == NULL) + *root = xmlNewNode(NULL, (xmlChar *)"sharecfg"); + if (*root != NULL) { + if (strcmp(path, SA_LEGACY_DFSTAB) == 0) { + /* + * Walk the default shares and find anything + * missing. we do this first to make sure it + * is cleaned up since there may be legacy + * code add/del via dfstab and we need to + * cleanup SMF. + */ + defgroup = sa_get_group(handle, "default"); + if (defgroup != NULL) + legacy_removes(defgroup, path); + /* Parse the dfstab and add anything new */ + parse_dfstab(handle, path, *root); + } } - } } } @@ -1304,43 +1322,42 @@ get_share_list(int *errp) struct share *sharetab_entry; while (getshare(fp, &sharetab_entry) > 0) { - newp = alloc_sharelist(); - if (newp == NULL) { - goto err; - } + newp = alloc_sharelist(); + if (newp == NULL) + goto err; /* - * link into the list here so we don't leak + * Link into the list here so we don't leak * memory on a failure from strdup(). */ - if (headp == NULL) { - headp = newp; - tailp = newp; - } else { - tailp->next = newp; - tailp = newp; - } - - newp->path = strdup(sharetab_entry->sh_path); - if (newp->path == NULL) - goto err; - newp->resource = strdup(sharetab_entry->sh_res); - if (newp->resource == NULL) - goto err; - newp->fstype = strdup(sharetab_entry->sh_fstype); - if (newp->fstype == NULL) - goto err; - newp->options = strdup(sharetab_entry->sh_opts); - if (newp->options == NULL) - goto err; - newp->description = strdup(sharetab_entry->sh_descr); - if (newp->description == NULL) - goto err; + if (headp == NULL) { + headp = newp; + tailp = newp; + } else { + tailp->next = newp; + tailp = newp; + } + + newp->path = strdup(sharetab_entry->sh_path); + if (newp->path == NULL) + goto err; + newp->resource = strdup(sharetab_entry->sh_res); + if (newp->resource == NULL) + goto err; + newp->fstype = strdup(sharetab_entry->sh_fstype); + if (newp->fstype == NULL) + goto err; + newp->options = strdup(sharetab_entry->sh_opts); + if (newp->options == NULL) + goto err; + newp->description = strdup(sharetab_entry->sh_descr); + if (newp->description == NULL) + goto err; } (void) lockf(fileno(fp), F_ULOCK, 0); (void) fclose(fp); } else { - *errp = errno; + *errp = errno; } /* @@ -1378,110 +1395,121 @@ parse_sharetab(sa_handle_t handle) list = get_share_list(&err); if (list == NULL) - return (legacy); + return (legacy); lgroup = sa_get_group(handle, "default"); for (tmplist = list; tmplist != NULL; tmplist = tmplist->next) { - group = NULL; - share = sa_find_share(handle, tmplist->path); - if (share == NULL) { + group = NULL; + share = sa_find_share(handle, tmplist->path); + if (share != NULL) { + /* + * If this is a legacy share, mark as shared so we + * only update sharetab appropriately. We also keep + * the sharetab options in order to display for legacy + * share with no arguments. + */ + set_node_attr(share, "shared", "true"); + set_node_attr(share, "shareopts", tmplist->options); + continue; + } + /* - * this share is transient so needs to be + * This share is transient so needs to be * added. Initially, this will be under * default(legacy) unless it is a ZFS * share. If zfs, we need a zfs group. */ if (tmplist->resource != NULL && (groupname = strchr(tmplist->resource, '@')) != NULL) { - /* there is a defined group */ - *groupname++ = '\0'; - group = sa_get_group(handle, groupname); - if (group != NULL) { - share = _sa_add_share(group, tmplist->path, - SA_SHARE_TRANSIENT, &err); - } else { - /* - * While this case shouldn't occur very often, - * it does occur out of a "zfs set - * sharenfs=off" when the dataset is also set - * to canmount=off. A warning will then cause - * the zfs command to abort. Since we add it - * to the default list, everything works - * properly anyway and the library doesn't - * need to give a warning. - */ - share = _sa_add_share(lgroup, tmplist->path, - SA_SHARE_TRANSIENT, &err); - } - } else { - if (sa_zfs_is_shared(handle, tmplist->path)) { - group = sa_get_group(handle, "zfs"); - if (group == NULL) { - group = sa_create_group(handle, "zfs", &err); - if (group == NULL && err == SA_NO_PERMISSION) { - group = _sa_create_group( - (sa_handle_impl_t)handle, - "zfs"); - } - if (group != NULL) { - (void) sa_create_optionset(group, - tmplist->fstype); - (void) sa_set_group_attr(group, "zfs", "true"); - } - } + /* There is a defined group */ + *groupname++ = '\0'; + group = sa_get_group(handle, groupname); if (group != NULL) { - share = _sa_add_share(group, tmplist->path, - SA_SHARE_TRANSIENT, &err); + share = _sa_add_share(group, + tmplist->path, + SA_SHARE_TRANSIENT, &err); + } else { + /* + * While this case shouldn't + * occur very often, it does + * occur out of a "zfs set + * sharenfs=off" when the + * dataset is also set to + * canmount=off. A warning + * will then cause the zfs + * command to abort. Since we + * add it to the default list, + * everything works properly + * anyway and the library + * doesn't need to give a + * warning. + */ + share = _sa_add_share(lgroup, + tmplist->path, SA_SHARE_TRANSIENT, + &err); + } + } else { + if (sa_zfs_is_shared(handle, tmplist->path)) { + group = sa_get_group(handle, "zfs"); + if (group == NULL) { + group = sa_create_group(handle, + "zfs", &err); + if (group == NULL && + err == SA_NO_PERMISSION) { + group = _sa_create_group( + (sa_handle_impl_t) + handle, + "zfs"); + } + if (group != NULL) { + (void) sa_create_optionset( + group, tmplist->fstype); + (void) sa_set_group_attr(group, + "zfs", "true"); + } + } + if (group != NULL) { + share = _sa_add_share(group, + tmplist->path, SA_SHARE_TRANSIENT, + &err); + } + } else { + share = _sa_add_share(lgroup, tmplist->path, + SA_SHARE_TRANSIENT, &err); } - } else { - share = _sa_add_share(lgroup, tmplist->path, - SA_SHARE_TRANSIENT, &err); - } } if (share == NULL) - (void) printf(dgettext(TEXT_DOMAIN, - "Problem with transient: %s\n"), - sa_errorstr(err)); + (void) printf(dgettext(TEXT_DOMAIN, + "Problem with transient: %s\n"), sa_errorstr(err)); if (share != NULL) - set_node_attr(share, "shared", "true"); - + set_node_attr(share, "shared", "true"); if (err == SA_OK) { - if (tmplist->options != NULL && - strlen(tmplist->options) > 0) { - (void) sa_parse_legacy_options(share, - tmplist->options, - tmplist->fstype); - } - if (tmplist->resource != NULL && - strcmp(tmplist->resource, "-") != 0) - set_node_attr(share, "resource", tmplist->resource); - if (tmplist->description != NULL) { - xmlNodePtr node; - node = xmlNewChild((xmlNodePtr)share, NULL, - (xmlChar *)"description", NULL); - xmlNodeSetContent(node, - (xmlChar *)tmplist->description); - } - legacy = 1; + if (tmplist->options != NULL && + strlen(tmplist->options) > 0) { + (void) sa_parse_legacy_options(share, + tmplist->options, tmplist->fstype); + } + if (tmplist->resource != NULL && + strcmp(tmplist->resource, "-") != 0) + set_node_attr(share, "resource", + tmplist->resource); + if (tmplist->description != NULL) { + xmlNodePtr node; + node = xmlNewChild((xmlNodePtr)share, NULL, + (xmlChar *)"description", NULL); + xmlNodeSetContent(node, + (xmlChar *)tmplist->description); + } + legacy = 1; } - } else { - /* - * if this is a legacy share, mark as shared so we - * only update sharetab appropriately. We also keep - * the sharetab options in order to display for legacy - * share with no arguments. - */ - set_node_attr(share, "shared", "true"); - set_node_attr(share, "shareopts", tmplist->options); - } } dfs_free_list(list); return (legacy); } /* - * get the transient shares from the sharetab (or other) file. since + * Get the transient shares from the sharetab (or other) file. since * these are transient, they only appear in the working file and not * in a repository. */ @@ -1491,11 +1519,10 @@ gettransients(sa_handle_impl_t ihandle, xmlNodePtr *root) int legacy = 0; if (root != NULL) { - if (*root == NULL) - *root = xmlNewNode(NULL, (xmlChar *)"sharecfg"); - if (*root != NULL) { - legacy = parse_sharetab(ihandle); - } + if (*root == NULL) + *root = xmlNewNode(NULL, (xmlChar *)"sharecfg"); + if (*root != NULL) + legacy = parse_sharetab(ihandle); } return (legacy); } @@ -1514,13 +1541,13 @@ sa_has_prop(sa_optionset_t optionset, sa_property_t prop) int result = 0; if (optionset != NULL) { - name = sa_get_property_attr(prop, "type"); - if (name != NULL) { - otherprop = sa_get_property(optionset, name); - if (otherprop != NULL) - result = 1; - sa_free_attr_string(name); - } + name = sa_get_property_attr(prop, "type"); + if (name != NULL) { + otherprop = sa_get_property(optionset, name); + if (otherprop != NULL) + result = 1; + sa_free_attr_string(name); + } } return (result); } @@ -1557,7 +1584,7 @@ sa_valid_property(void *object, char *proto, sa_property_t property) int ret = SA_OK; if (proto != NULL && property != NULL) { - ret = sa_proto_valid_prop(proto, property, object); + ret = sa_proto_valid_prop(proto, property, object); } return (ret); @@ -1577,15 +1604,17 @@ sa_fstype(char *path) struct stat st; err = stat(path, &st); - if (err < 0) { - err = SA_NO_SUCH_PATH; - } else { - err = SA_OK; - } - if (err == SA_OK) { - /* have a valid path at this point */ - return (strdup(st.st_fstype)); - } + if (err < 0) + err = SA_NO_SUCH_PATH; + else + err = SA_OK; + + /* + * If we have a valid path at this point ret, return the fstype. + */ + if (err == SA_OK) + return (strdup(st.st_fstype)); + return (NULL); } @@ -1615,56 +1644,61 @@ sa_get_derived_optionset(void *object, char *proto, int hier) if (hier && (group = sa_get_parent_group((sa_share_t)object)) != NULL) { - newoptionset = sa_get_derived_optionset((void *)group, proto, hier); + newoptionset = sa_get_derived_optionset((void *)group, proto, + hier); } else { - newoptionset = (sa_optionset_t)xmlNewNode(NULL, - (xmlChar *)"optionset"); - if (newoptionset != NULL) { - sa_set_optionset_attr(newoptionset, "type", proto); - } + newoptionset = (sa_optionset_t)xmlNewNode(NULL, + (xmlChar *)"optionset"); + if (newoptionset != NULL) { + sa_set_optionset_attr(newoptionset, "type", proto); + } } - /* dont' do anything if memory wasn't allocated */ + /* Dont' do anything if memory wasn't allocated */ if (newoptionset == NULL) - return (NULL); + return (NULL); - /* found the top so working back down the stack */ + /* Found the top so working back down the stack */ optionset = sa_get_optionset((sa_optionset_t)object, proto); if (optionset != NULL) { - sa_property_t prop; - /* add optionset to the newoptionset */ - for (prop = sa_get_property(optionset, NULL); - prop != NULL; prop = sa_get_next_property(prop)) { - sa_property_t newprop; - char *name; - char *value; - name = sa_get_property_attr(prop, "type"); - value = sa_get_property_attr(prop, "value"); - if (name != NULL) { - newprop = sa_get_property(newoptionset, name); - /* replace the value with the new value */ - if (newprop != NULL) { - /* - * only set if value is non NULL, old value ok - * if it is NULL. - */ - if (value != NULL) - set_node_attr(newprop, "value", value); - } else { - /* an entirely new property */ - if (value != NULL) { - newprop = sa_create_property(name, value); - if (newprop != NULL) { - newprop = (sa_property_t) - xmlAddChild((xmlNodePtr)newoptionset, - (xmlNodePtr)newprop); - } + sa_property_t prop; + /* add optionset to the newoptionset */ + for (prop = sa_get_property(optionset, NULL); + prop != NULL; + prop = sa_get_next_property(prop)) { + sa_property_t newprop; + char *name; + char *value; + name = sa_get_property_attr(prop, "type"); + value = sa_get_property_attr(prop, "value"); + if (name == NULL) + continue; + newprop = sa_get_property(newoptionset, name); + /* Replace the value with the new value */ + if (newprop != NULL) { + /* + * Only set if value is non NULL, old value ok + * if it is NULL. + */ + if (value != NULL) + set_node_attr(newprop, "value", value); + } else { + /* an entirely new property */ + if (value != NULL) { + newprop = sa_create_property(name, + value); + if (newprop != NULL) { + newprop = (sa_property_t) + xmlAddChild( + (xmlNodePtr)newoptionset, + (xmlNodePtr)newprop); + } + } } - } - sa_free_attr_string(name); + sa_free_attr_string(name); + + if (value != NULL) + sa_free_attr_string(value); } - if (value != NULL) - sa_free_attr_string(value); - } } return (newoptionset); } @@ -1672,17 +1706,17 @@ sa_get_derived_optionset(void *object, char *proto, int hier) void sa_free_derived_optionset(sa_optionset_t optionset) { - /* while it shouldn't be linked, it doesn't hurt */ + /* While it shouldn't be linked, it doesn't hurt */ if (optionset != NULL) { - xmlUnlinkNode((xmlNodePtr) optionset); - xmlFreeNode((xmlNodePtr) optionset); + xmlUnlinkNode((xmlNodePtr) optionset); + xmlFreeNode((xmlNodePtr) optionset); } } /* * sa_get_all_security_types(object, proto, hier) * - * find all the security types set for this object. This is + * Find all the security types set for this object. This is * preliminary to getting a derived security set. The return value is an * optionset containg properties which are the sectype values found by * walking up the XML document struture. The returned optionset @@ -1701,45 +1735,50 @@ sa_get_all_security_types(void *object, char *proto, int hier) options = NULL; if (hier && - (group = sa_get_parent_group((sa_share_t)object)) != NULL) { - options = sa_get_all_security_types((void *)group, proto, hier); - } else { - options = (sa_optionset_t)xmlNewNode(NULL, - (xmlChar *)"optionset"); - } - /* hit the top so collect the security types working back */ - if (options != NULL) { - for (security = sa_get_security((sa_group_t)object, NULL, NULL); - security != NULL; security = sa_get_next_security(security)) { + (group = sa_get_parent_group((sa_share_t)object)) != NULL) + options = sa_get_all_security_types((void *)group, proto, hier); + else + options = (sa_optionset_t)xmlNewNode(NULL, + (xmlChar *)"optionset"); + + if (options == NULL) + return (options); + + /* Hit the top so collect the security types working back. */ + for (security = sa_get_security((sa_group_t)object, NULL, NULL); + security != NULL; + security = sa_get_next_security(security)) { char *type; char *sectype; type = sa_get_security_attr(security, "type"); if (type != NULL) { - if (strcmp(type, proto) != 0) { - sa_free_attr_string(type); - continue; - } - sectype = sa_get_security_attr(security, "sectype"); - if (sectype != NULL) { - /* - * have a security type, check to see if - * already present in optionset and add if it - * isn't. - */ - if (sa_get_property(options, sectype) == NULL) { - prop = sa_create_property(sectype, "true"); - if (prop != NULL) - prop = (sa_property_t) - xmlAddChild((xmlNodePtr)options, - (xmlNodePtr)prop); + if (strcmp(type, proto) != 0) { + sa_free_attr_string(type); + continue; + } + sectype = sa_get_security_attr(security, "sectype"); + if (sectype != NULL) { + /* + * Have a security type, check to see if + * already present in optionset and add if it + * isn't. + */ + if (sa_get_property(options, sectype) == NULL) { + prop = sa_create_property(sectype, + "true"); + if (prop != NULL) + prop = (sa_property_t) + xmlAddChild( + (xmlNodePtr)options, + (xmlNodePtr)prop); + } + sa_free_attr_string(sectype); } - sa_free_attr_string(sectype); - } - sa_free_attr_string(type); + sa_free_attr_string(type); } - } } + return (options); } @@ -1758,59 +1797,61 @@ sa_get_derived_security(void *object, char *sectype, char *proto, int hier) sa_security_t newsecurity; sa_security_t security; sa_group_t group; + sa_property_t prop; if (hier && (group = sa_get_parent_group((sa_share_t)object)) != NULL) { - newsecurity = sa_get_derived_security((void *)group, - sectype, proto, hier); + newsecurity = sa_get_derived_security((void *)group, + sectype, proto, hier); } else { - newsecurity = (sa_security_t)xmlNewNode(NULL, - (xmlChar *)"security"); - if (newsecurity != NULL) { - sa_set_security_attr(newsecurity, "type", proto); - sa_set_security_attr(newsecurity, "sectype", sectype); - } + newsecurity = (sa_security_t)xmlNewNode(NULL, + (xmlChar *)"security"); + if (newsecurity != NULL) { + sa_set_security_attr(newsecurity, "type", proto); + sa_set_security_attr(newsecurity, "sectype", sectype); + } } - /* dont' do anything if memory wasn't allocated */ + /* Don't do anything if memory wasn't allocated */ if (newsecurity == NULL) - return (NULL); + return (newsecurity); - /* found the top so working back down the stack */ + /* Found the top so working back down the stack. */ security = sa_get_security((sa_security_t)object, sectype, proto); - if (security != NULL) { - sa_property_t prop; - /* add security to the newsecurity */ - for (prop = sa_get_property(security, NULL); - prop != NULL; prop = sa_get_next_property(prop)) { + if (security == NULL) + return (newsecurity); + + /* add security to the newsecurity */ + for (prop = sa_get_property(security, NULL); + prop != NULL; prop = sa_get_next_property(prop)) { sa_property_t newprop; char *name; char *value; name = sa_get_property_attr(prop, "type"); value = sa_get_property_attr(prop, "value"); if (name != NULL) { - newprop = sa_get_property(newsecurity, name); - /* replace the value with the new value */ - if (newprop != NULL) { - /* - * only set if value is non NULL, old value ok - * if it is NULL. - */ - if (value != NULL) - set_node_attr(newprop, name, value); - } else { - /* an entirely new property */ - if (value != NULL) { - newprop = sa_create_property(name, value); - newprop = (sa_property_t) - xmlAddChild((xmlNodePtr)newsecurity, + newprop = sa_get_property(newsecurity, name); + /* Replace the value with the new value */ + if (newprop != NULL) { + /* + * Only set if value is non NULL, old value ok + * if it is NULL. + */ + if (value != NULL) + set_node_attr(newprop, name, value); + } else { + /* An entirely new property */ + if (value != NULL) { + newprop = sa_create_property(name, + value); + newprop = (sa_property_t) + xmlAddChild((xmlNodePtr)newsecurity, (xmlNodePtr)newprop); + } } - } - sa_free_attr_string(name); + sa_free_attr_string(name); } if (value != NULL) - sa_free_attr_string(value); - } + sa_free_attr_string(value); } return (newsecurity); } @@ -1820,15 +1861,15 @@ sa_free_derived_security(sa_security_t security) { /* while it shouldn't be linked, it doesn't hurt */ if (security != NULL) { - xmlUnlinkNode((xmlNodePtr)security); - xmlFreeNode((xmlNodePtr)security); + xmlUnlinkNode((xmlNodePtr)security); + xmlFreeNode((xmlNodePtr)security); } } /* * sharetab utility functions * - * makes use of the original sharetab.c from fs.d/nfs/lib + * Makes use of the original sharetab.c from fs.d/nfs/lib */ /* @@ -1847,72 +1888,74 @@ sa_fillshare(sa_share_t share, char *proto, struct share *sh) group = sa_get_parent_group(share); if (group != NULL) { - zfs = sa_get_group_attr(group, "zfs"); - groupname = sa_get_group_attr(group, "name"); + zfs = sa_get_group_attr(group, "zfs"); + groupname = sa_get_group_attr(group, "name"); - if (groupname != NULL && - (strcmp(groupname, "default") == 0 || zfs != NULL)) { - /* - * since the groupname is either "default" or the - * group is a ZFS group, we don't want to keep - * groupname. We do want it if it is any other type of - * group. - */ - sa_free_attr_string(groupname); - groupname = NULL; - } - if (zfs != NULL) - sa_free_attr_string(zfs); + if (groupname != NULL && + (strcmp(groupname, "default") == 0 || zfs != NULL)) { + /* + * since the groupname is either "default" or the + * group is a ZFS group, we don't want to keep + * groupname. We do want it if it is any other type of + * group. + */ + sa_free_attr_string(groupname); + groupname = NULL; + } + if (zfs != NULL) + sa_free_attr_string(zfs); } value = sa_get_share_attr(share, "path"); if (value != NULL) { - sh->sh_path = strdup(value); - sa_free_attr_string(value); + sh->sh_path = strdup(value); + sa_free_attr_string(value); } value = sa_get_share_attr(share, "resource"); if (value != NULL || groupname != NULL) { - int len = 0; - - if (value != NULL) - len += strlen(value); - if (groupname != NULL) - len += strlen(groupname); - len += 3; /* worst case */ - buff = malloc(len); - (void) snprintf(buff, len, "%s%s%s", + int len = 0; + + if (value != NULL) + len += strlen(value); + if (groupname != NULL) + len += strlen(groupname); + len += 3; /* worst case */ + buff = malloc(len); + (void) snprintf(buff, len, "%s%s%s", (value != NULL && strlen(value) > 0) ? value : "-", groupname != NULL ? "@" : "", groupname != NULL ? groupname : ""); - sh->sh_res = buff; - if (value != NULL) - sa_free_attr_string(value); - if (groupname != NULL) { - sa_free_attr_string(groupname); - groupname = NULL; - } + sh->sh_res = buff; + if (value != NULL) + sa_free_attr_string(value); + if (groupname != NULL) { + sa_free_attr_string(groupname); + groupname = NULL; + } } else { - sh->sh_res = strdup("-"); + sh->sh_res = strdup("-"); } sh->sh_fstype = strdup(proto); value = sa_proto_legacy_format(proto, share, 1); if (value != NULL) { - if (strlen(value) > 0) - sh->sh_opts = strdup(value); - else + if (strlen(value) > 0) + sh->sh_opts = strdup(value); + else + sh->sh_opts = strdup("rw"); + free(value); + } else { sh->sh_opts = strdup("rw"); - free(value); - } else - sh->sh_opts = strdup("rw"); + } value = sa_get_share_description(share); if (value != NULL) { - sh->sh_descr = strdup(value); - sa_free_share_description(value); - } else - sh->sh_descr = strdup(""); + sh->sh_descr = strdup(value); + sa_free_share_description(value); + } else { + sh->sh_descr = strdup(""); + } } /* @@ -1925,19 +1968,19 @@ void sa_emptyshare(struct share *sh) { if (sh->sh_path != NULL) - free(sh->sh_path); + free(sh->sh_path); sh->sh_path = NULL; if (sh->sh_res != NULL) - free(sh->sh_res); + free(sh->sh_res); sh->sh_res = NULL; if (sh->sh_fstype != NULL) - free(sh->sh_fstype); + free(sh->sh_fstype); sh->sh_fstype = NULL; if (sh->sh_opts != NULL) - free(sh->sh_opts); + free(sh->sh_opts); sh->sh_opts = NULL; if (sh->sh_descr != NULL) - free(sh->sh_descr); + free(sh->sh_descr); sh->sh_descr = NULL; } diff --git a/usr/src/lib/libshare/common/plugin.c b/usr/src/lib/libshare/common/plugin.c index 83bc4d5d94..4079e24ff7 100644 --- a/usr/src/lib/libshare/common/plugin.c +++ b/usr/src/lib/libshare/common/plugin.c @@ -81,83 +81,90 @@ proto_plugin_init() struct stat st; /* - * should walk "/usr/lib/fs/" for files of the form: + * Should walk "/usr/lib/fs/" for files of the form: * libshare_*.so */ dir = opendir(SA_LIB_DIR); if (dir != NULL) { - while (ret == SA_OK && (dent = readdir(dir)) != NULL) { - char path[MAXPATHLEN]; - char isa[MAXISALEN]; + while (ret == SA_OK && (dent = readdir(dir)) != NULL) { + char path[MAXPATHLEN]; + char isa[MAXISALEN]; #if defined(_LP64) - if (sysinfo(SI_ARCHITECTURE_64, isa, MAXISALEN) == -1) - isa[0] = '\0'; + if (sysinfo(SI_ARCHITECTURE_64, isa, MAXISALEN) == -1) + isa[0] = '\0'; #else - isa[0] = '\0'; + isa[0] = '\0'; #endif - (void) snprintf(path, MAXPATHLEN, - "%s/%s/%s/libshare_%s.so.1", - SA_LIB_DIR, - dent->d_name, - isa, - dent->d_name); - if (stat(path, &st) < 0) { - /* file doesn't exist, so don't try to map it */ - continue; - } - dlhandle = dlopen(path, RTLD_FIRST|RTLD_LAZY); - if (dlhandle != NULL) { - plugin_ops = (struct sa_plugin_ops *) - dlsym(dlhandle, "sa_plugin_ops"); - proto = (struct sa_proto_plugin *) - calloc(1, sizeof (struct sa_proto_plugin)); - if (proto != NULL) { - proto->plugin_ops = plugin_ops; - proto->plugin_handle = dlhandle; - num_protos++; - proto->plugin_next = sap_proto_list; - sap_proto_list = proto; - } else { - ret = SA_NO_MEMORY; - } - } else { - (void) fprintf(stderr, - dgettext(TEXT_DOMAIN, + (void) snprintf(path, MAXPATHLEN, + "%s/%s/%s/libshare_%s.so.1", SA_LIB_DIR, + dent->d_name, isa, dent->d_name); + /* + * If file doesn't exist, don't try to map it + */ + if (stat(path, &st) < 0) + continue; + + dlhandle = dlopen(path, RTLD_FIRST|RTLD_LAZY); + if (dlhandle != NULL) { + plugin_ops = (struct sa_plugin_ops *) + dlsym(dlhandle, "sa_plugin_ops"); + proto = (struct sa_proto_plugin *) + calloc(1, sizeof (struct sa_proto_plugin)); + if (proto != NULL) { + proto->plugin_ops = plugin_ops; + proto->plugin_handle = dlhandle; + num_protos++; + proto->plugin_next = sap_proto_list; + sap_proto_list = proto; + } else { + ret = SA_NO_MEMORY; + } + } else { + (void) fprintf(stderr, + dgettext(TEXT_DOMAIN, "Error in plugin for protocol %s: %s\n"), - dent->d_name, dlerror()); + dent->d_name, dlerror()); + } } - } - (void) closedir(dir); + (void) closedir(dir); } if (ret == SA_OK) { - sa_proto_handle.sa_proto = - (char **)calloc(num_protos, sizeof (char *)); - sa_proto_handle.sa_ops = - (struct sa_plugin_ops **)calloc(num_protos, - sizeof (struct sa_plugin_ops *)); - if (sa_proto_handle.sa_proto != NULL && - sa_proto_handle.sa_ops != NULL) { - int i; - struct sa_proto_plugin *tmp; - for (i = 0, tmp = sap_proto_list; i < num_protos; - tmp = tmp->plugin_next) { - err = 0; - if (tmp->plugin_ops->sa_init != NULL) - err = tmp->plugin_ops->sa_init(); - if (err == SA_OK) { - /* only include if the init succeeded or was NULL */ - sa_proto_handle.sa_num_proto++; - sa_proto_handle.sa_ops[i] = tmp->plugin_ops; - sa_proto_handle.sa_proto[i] = - tmp->plugin_ops->sa_protocol; - i++; - } + sa_proto_handle.sa_proto = + (char **)calloc(num_protos, sizeof (char *)); + sa_proto_handle.sa_ops = + (struct sa_plugin_ops **)calloc(num_protos, + sizeof (struct sa_plugin_ops *)); + if (sa_proto_handle.sa_proto != NULL && + sa_proto_handle.sa_ops != NULL) { + int i; + struct sa_proto_plugin *tmp; + + for (i = 0, tmp = sap_proto_list; + i < num_protos; + tmp = tmp->plugin_next) { + err = 0; + if (tmp->plugin_ops->sa_init != NULL) + err = tmp->plugin_ops->sa_init(); + if (err == SA_OK) { + /* + * Only include if the init + * succeeded or was NULL + */ + sa_proto_handle.sa_num_proto++; + sa_proto_handle.sa_ops[i] = + tmp->plugin_ops; + sa_proto_handle.sa_proto[i] = + tmp->plugin_ops->sa_protocol; + i++; + } + } } - } } else { - /* there was an error, so cleanup prior to return of failure. */ - proto_plugin_fini(); + /* + * There was an error, so cleanup prior to return of failure. + */ + proto_plugin_fini(); } return (ret); } @@ -165,32 +172,33 @@ proto_plugin_init() /* * proto_plugin_fini() * - * uninitialize all the plugin modules. + * Uninitialize all the plugin modules. */ void proto_plugin_fini() { /* - * free up all the protocols, calling their fini, if there is + * Free up all the protocols, calling their fini, if there is * one. */ while (sap_proto_list != NULL) { - struct sa_proto_plugin *next; - next = sap_proto_list->plugin_next; - sap_proto_list->plugin_ops->sa_fini(); - if (sap_proto_list->plugin_handle != NULL) - (void) dlclose(sap_proto_list->plugin_handle); - free(sap_proto_list); - sap_proto_list = next; + struct sa_proto_plugin *next; + + next = sap_proto_list->plugin_next; + sap_proto_list->plugin_ops->sa_fini(); + if (sap_proto_list->plugin_handle != NULL) + (void) dlclose(sap_proto_list->plugin_handle); + free(sap_proto_list); + sap_proto_list = next; } if (sa_proto_handle.sa_ops != NULL) { - free(sa_proto_handle.sa_ops); - sa_proto_handle.sa_ops = NULL; + free(sa_proto_handle.sa_ops); + sa_proto_handle.sa_ops = NULL; } if (sa_proto_handle.sa_proto != NULL) { - free(sa_proto_handle.sa_proto); - sa_proto_handle.sa_proto = NULL; + free(sa_proto_handle.sa_proto); + sa_proto_handle.sa_proto = NULL; } sa_proto_handle.sa_num_proto = 0; } @@ -208,10 +216,10 @@ find_protocol(char *proto) int i; if (proto != NULL) { - for (i = 0; i < sa_proto_handle.sa_num_proto; i++) { - if (strcmp(proto, sa_proto_handle.sa_proto[i]) == 0) - return (sa_proto_handle.sa_ops[i]); - } + for (i = 0; i < sa_proto_handle.sa_num_proto; i++) { + if (strcmp(proto, sa_proto_handle.sa_proto[i]) == 0) + return (sa_proto_handle.sa_ops[i]); + } } return (NULL); } @@ -229,7 +237,7 @@ sa_proto_share(char *proto, sa_share_t share) int ret = SA_INVALID_PROTOCOL; if (ops != NULL && ops->sa_share != NULL) - ret = ops->sa_share(share); + ret = ops->sa_share(share); return (ret); } @@ -246,14 +254,14 @@ sa_proto_unshare(sa_share_t share, char *proto, char *path) int ret = SA_INVALID_PROTOCOL; if (ops != NULL && ops->sa_unshare != NULL) - ret = ops->sa_unshare(share, path); + ret = ops->sa_unshare(share, path); return (ret); } /* * sa_proto_valid_prop(proto, prop, opt) * - * check to see if the specified prop is valid for this protocol. + * Check to see if the specified prop is valid for this protocol. */ int @@ -263,14 +271,14 @@ sa_proto_valid_prop(char *proto, sa_property_t prop, sa_optionset_t opt) int ret = 0; if (ops != NULL && ops->sa_valid_prop != NULL) - ret = ops->sa_valid_prop(prop, opt); + ret = ops->sa_valid_prop(prop, opt); return (ret); } /* * sa_proto_valid_space(proto, space) * - * check if space is valid optionspace for proto. + * Check if space is valid optionspace for proto. * Protocols that don't implement this don't support spaces. */ int @@ -280,14 +288,14 @@ sa_proto_valid_space(char *proto, char *token) int ret = 0; if (ops != NULL && ops->sa_valid_space != NULL) - ret = ops->sa_valid_space(token); + ret = ops->sa_valid_space(token); return (ret); } /* * sa_proto_space_alias(proto, space) * - * if the name for space is an alias, return its proper name. This is + * If the name for space is an alias, return its proper name. This is * used to translate "default" values into proper form. */ char * @@ -297,7 +305,7 @@ sa_proto_space_alias(char *proto, char *space) char *ret = space; if (ops != NULL && ops->sa_space_alias != NULL) - ret = ops->sa_space_alias(space); + ret = ops->sa_space_alias(space); return (ret); } @@ -315,7 +323,7 @@ sa_proto_security_prop(char *proto, char *token) int ret = 0; if (ops != NULL && ops->sa_security_prop != NULL) - ret = ops->sa_security_prop(token); + ret = ops->sa_security_prop(token); return (ret); } @@ -333,7 +341,7 @@ sa_proto_legacy_opts(char *proto, sa_group_t group, char *options) int ret = SA_INVALID_PROTOCOL; if (ops != NULL && ops->sa_legacy_opts != NULL) - ret = ops->sa_legacy_opts(group, options); + ret = ops->sa_legacy_opts(group, options); return (ret); } @@ -351,7 +359,7 @@ sa_proto_legacy_format(char *proto, sa_group_t group, int hier) char *ret = NULL; if (ops != NULL && ops->sa_legacy_format != NULL) - ret = ops->sa_legacy_format(group, hier); + ret = ops->sa_legacy_format(group, hier); return (ret); } @@ -380,7 +388,7 @@ sa_proto_get_properties(char *proto) sa_protocol_properties_t props = NULL; if (ops != NULL && ops->sa_get_proto_set != NULL) - props = ops->sa_get_proto_set(); + props = ops->sa_get_proto_set(); return (props); } @@ -395,15 +403,16 @@ sa_proto_set_property(char *proto, sa_property_t prop) { struct sa_plugin_ops *ops = find_protocol(proto); int ret = SA_OK; + if (ops != NULL && ops->sa_set_proto_prop != NULL) - ret = ops->sa_set_proto_prop(prop); + ret = ops->sa_set_proto_prop(prop); return (ret); } /* * sa_valid_protocol(proto) * - * check to see if the protocol specified is defined by a + * Check to see if the protocol specified is defined by a * plugin. Returns true (1) or false (0) */ @@ -424,7 +433,7 @@ sa_get_protocol_status(char *proto) struct sa_plugin_ops *ops = find_protocol(proto); char *ret = NULL; if (ops != NULL && ops->sa_get_proto_status != NULL) - ret = ops->sa_get_proto_status(proto); + ret = ops->sa_get_proto_status(proto); return (ret); } @@ -442,8 +451,8 @@ sa_proto_update_legacy(char *proto, sa_share_t share) int ret = SA_NOT_IMPLEMENTED; if (ops != NULL) { - if (ops->sa_update_legacy != NULL) - ret = ops->sa_update_legacy(share); + if (ops->sa_update_legacy != NULL) + ret = ops->sa_update_legacy(share); } return (ret); } @@ -451,7 +460,7 @@ sa_proto_update_legacy(char *proto, sa_share_t share) /* * sa_delete_legacy(proto, share) * - * remove the specified share from the protocol specific legacy files. + * Remove the specified share from the protocol specific legacy files. */ int @@ -461,13 +470,13 @@ sa_proto_delete_legacy(char *proto, sa_share_t share) int ret = SA_OK; if (ops != NULL) { - if (ops->sa_delete_legacy != NULL) - ret = ops->sa_delete_legacy(share); + if (ops->sa_delete_legacy != NULL) + ret = ops->sa_delete_legacy(share); } else { - if (proto != NULL) - ret = SA_NOT_IMPLEMENTED; - else - ret = SA_INVALID_PROTOCOL; + if (proto != NULL) + ret = SA_NOT_IMPLEMENTED; + else + ret = SA_INVALID_PROTOCOL; } return (ret); } diff --git a/usr/src/lib/libshare/common/scfutil.c b/usr/src/lib/libshare/common/scfutil.c index 9aa79ae5c8..05421d605b 100644 --- a/usr/src/lib/libshare/common/scfutil.c +++ b/usr/src/lib/libshare/common/scfutil.c @@ -58,7 +58,7 @@ static char *skip_props[] = { /* * sa_scf_fini(handle) * - * must be called when done. Called with the handle allocated in + * Must be called when done. Called with the handle allocated in * sa_scf_init(), it cleans up the state and frees any SCF resources * still in use. Called by sa_fini(). */ @@ -67,31 +67,31 @@ void sa_scf_fini(scfutilhandle_t *handle) { if (handle != NULL) { - int unbind = 0; - if (handle->scope != NULL) { - unbind = 1; - scf_scope_destroy(handle->scope); - } - if (handle->instance != NULL) - scf_instance_destroy(handle->instance); - if (handle->service != NULL) - scf_service_destroy(handle->service); - if (handle->pg != NULL) - scf_pg_destroy(handle->pg); - if (handle->handle != NULL) { - handle->scf_state = SCH_STATE_UNINIT; - if (unbind) - (void) scf_handle_unbind(handle->handle); - scf_handle_destroy(handle->handle); - } - free(handle); + int unbind = 0; + if (handle->scope != NULL) { + unbind = 1; + scf_scope_destroy(handle->scope); + } + if (handle->instance != NULL) + scf_instance_destroy(handle->instance); + if (handle->service != NULL) + scf_service_destroy(handle->service); + if (handle->pg != NULL) + scf_pg_destroy(handle->pg); + if (handle->handle != NULL) { + handle->scf_state = SCH_STATE_UNINIT; + if (unbind) + (void) scf_handle_unbind(handle->handle); + scf_handle_destroy(handle->handle); + } + free(handle); } } /* * sa_scf_init() * - * must be called before using any of the SCF functions. Called by + * Must be called before using any of the SCF functions. Called by * sa_init() during the API setup. */ @@ -102,69 +102,65 @@ sa_scf_init(sa_handle_impl_t ihandle) scf_max_name_len = scf_limit(SCF_LIMIT_MAX_NAME_LENGTH); if (scf_max_name_len <= 0) - scf_max_name_len = SA_MAX_NAME_LEN + 1; + scf_max_name_len = SA_MAX_NAME_LEN + 1; handle = calloc(1, sizeof (scfutilhandle_t)); - if (handle != NULL) { - ihandle->scfhandle = handle; - handle->scf_state = SCH_STATE_INITIALIZING; - handle->handle = scf_handle_create(SCF_VERSION); - if (handle->handle != NULL) { - if (scf_handle_bind(handle->handle) == 0) { - handle->scope = scf_scope_create(handle->handle); - handle->service = scf_service_create(handle->handle); - handle->pg = scf_pg_create(handle->handle); - - /* make sure we have sufficient SMF running */ - handle->instance = scf_instance_create(handle->handle); - if (handle->scope == NULL || handle->service == NULL || - handle->pg == NULL || handle->instance == NULL) - goto err; - - if (scf_handle_get_scope(handle->handle, - SCF_SCOPE_LOCAL, handle->scope) == 0) { - if (scf_scope_get_service(handle->scope, - SA_GROUP_SVC_NAME, - handle->service) != 0) { - goto err; - } - handle->scf_state = SCH_STATE_INIT; - if (sa_get_instance(handle, "default") != SA_OK) { - char **protolist; - int numprotos, i; - sa_group_t defgrp; - defgrp = sa_create_group((sa_handle_t)ihandle, - "default", NULL); - if (defgrp != NULL) { - numprotos = sa_get_protocols(&protolist); - for (i = 0; i < numprotos; i++) { - (void) sa_create_optionset(defgrp, - protolist[i]); - } - if (protolist != NULL) - free(protolist); - } - } - } else { - goto err; - } - } else { - goto err; - } - } else { + if (handle == NULL) + return (handle); + + ihandle->scfhandle = handle; + handle->scf_state = SCH_STATE_INITIALIZING; + handle->handle = scf_handle_create(SCF_VERSION); + if (handle->handle == NULL) { free(handle); handle = NULL; (void) printf("libshare could not access SMF repository: %s\n", - scf_strerror(scf_error())); - } + scf_strerror(scf_error())); + return (handle); } + if (scf_handle_bind(handle->handle) != 0) + goto err; + + handle->scope = scf_scope_create(handle->handle); + handle->service = scf_service_create(handle->handle); + handle->pg = scf_pg_create(handle->handle); + + /* Make sure we have sufficient SMF running */ + handle->instance = scf_instance_create(handle->handle); + if (handle->scope == NULL || handle->service == NULL || + handle->pg == NULL || handle->instance == NULL) + goto err; + if (scf_handle_get_scope(handle->handle, + SCF_SCOPE_LOCAL, handle->scope) != 0) + goto err; + if (scf_scope_get_service(handle->scope, + SA_GROUP_SVC_NAME, handle->service) != 0) + goto err; + + handle->scf_state = SCH_STATE_INIT; + if (sa_get_instance(handle, "default") != SA_OK) { + char **protolist; + int numprotos, i; + sa_group_t defgrp; + defgrp = sa_create_group((sa_handle_t)ihandle, "default", NULL); + if (defgrp != NULL) { + numprotos = sa_get_protocols( + &protolist); + for (i = 0; i < numprotos; i++) + (void) sa_create_optionset(defgrp, + protolist[i]); + if (protolist != NULL) + free(protolist); + } + } + return (handle); - /* error handling/unwinding */ + /* Error handling/unwinding */ err: (void) sa_scf_fini(handle); (void) printf("libshare SMF initialization problem: %s\n", - scf_strerror(scf_error())); + scf_strerror(scf_error())); return (NULL); } @@ -183,14 +179,14 @@ get_scf_limit(uint32_t name) vallen = scf_limit(name); if (vallen == (ssize_t)-1) - vallen = MAXPATHLEN; + vallen = MAXPATHLEN; return (vallen); } /* * skip_property(name) * - * internal function to check to see if a property is an SMF magic + * Internal function to check to see if a property is an SMF magic * property that needs to be skipped. */ static int @@ -199,7 +195,7 @@ skip_property(char *name) int i; for (i = 0; skip_props[i] != NULL; i++) - if (strcmp(name, skip_props[i]) == 0) + if (strcmp(name, skip_props[i]) == 0) return (1); return (0); } @@ -225,7 +221,7 @@ generate_unique_sharename(char *sharename) /* * valid_protocol(proto) * - * check to see if the specified protocol is a valid one for the + * Check to see if the specified protocol is a valid one for the * general sharemgr facility. We determine this by checking which * plugin protocols were found. */ @@ -236,15 +232,15 @@ valid_protocol(char *proto) struct sa_proto_plugin *plugin; for (plugin = sap_proto_list; plugin != NULL; plugin = plugin->plugin_next) - if (strcmp(proto, plugin->plugin_ops->sa_protocol) == 0) - return (1); + if (strcmp(proto, plugin->plugin_ops->sa_protocol) == 0) + return (1); return (0); } /* * sa_extract_pgroup(root, handle, pg, nodetype, proto, sectype) * - * extract the name property group and create the specified type of + * Extract the name property group and create the specified type of * node on the provided group. type will be optionset or security. */ @@ -265,77 +261,79 @@ sa_extract_pgroup(xmlNodePtr root, scfutilhandle_t *handle, vallen = get_scf_limit(SCF_LIMIT_MAX_VALUE_LENGTH); node = xmlNewChild(root, NULL, (xmlChar *)nodetype, NULL); - if (node != NULL) { - if (proto != NULL) + if (node == NULL) + return (ret); + + if (proto != NULL) xmlSetProp(node, (xmlChar *)"type", (xmlChar *)proto); - if (sectype != NULL) + if (sectype != NULL) xmlSetProp(node, (xmlChar *)"sectype", (xmlChar *)sectype); - /* - * have node to work with so iterate over the properties - * in the pg and create option sub nodes. - */ - iter = scf_iter_create(handle->handle); - value = scf_value_create(handle->handle); - prop = scf_property_create(handle->handle); - name = malloc(scf_max_name_len); - valuestr = malloc(vallen); - /* - * want to iterate through the properties and add them - * to the base optionset. - */ - if (iter != NULL && value != NULL && prop != NULL && - valuestr != NULL && name != NULL) { - if (scf_iter_pg_properties(iter, pg) == 0) { - /* now iterate the properties in the group */ - while (scf_iter_next_property(iter, prop) > 0) { - /* have a property */ - if (scf_property_get_name(prop, name, - scf_max_name_len) > 0) { - /* some properties are part of the framework */ + /* + * Have node to work with so iterate over the properties + * in the pg and create option sub nodes. + */ + iter = scf_iter_create(handle->handle); + value = scf_value_create(handle->handle); + prop = scf_property_create(handle->handle); + name = malloc(scf_max_name_len); + valuestr = malloc(vallen); + /* + * Want to iterate through the properties and add them + * to the base optionset. + */ + if (iter == NULL || value == NULL || prop == NULL || + valuestr == NULL || name == NULL) { + ret = SA_NO_MEMORY; + goto out; + } + if (scf_iter_pg_properties(iter, pg) == 0) { + /* Now iterate the properties in the group */ + while (scf_iter_next_property(iter, prop) > 0) { + /* have a property */ + if (scf_property_get_name(prop, name, + scf_max_name_len) > 0) { + sa_property_t saprop; + /* Some properties are part of the framework */ if (skip_property(name)) - continue; - if (scf_property_get_value(prop, value) == 0) { - if (scf_value_get_astring(value, valuestr, - vallen) >= 0) { - sa_property_t saprop; - saprop = sa_create_property(name, - valuestr); - if (saprop != NULL) { + continue; + if (scf_property_get_value(prop, value) != 0) + continue; + if (scf_value_get_astring(value, valuestr, + vallen) < 0) + continue; + saprop = sa_create_property(name, valuestr); + if (saprop != NULL) { /* - * since in SMF, don't + * Since in SMF, don't * recurse. Use xmlAddChild * directly, instead. */ - xmlAddChild(node, - (xmlNodePtr) saprop); - } - } + xmlAddChild(node, + (xmlNodePtr) saprop); } - } } - } - } else { - ret = SA_NO_MEMORY; } - /* cleanup to avoid memory leaks */ - if (value != NULL) - scf_value_destroy(value); - if (iter != NULL) - scf_iter_destroy(iter); - if (prop != NULL) - scf_property_destroy(prop); - if (name != NULL) - free(name); - if (valuestr != NULL) - free(valuestr); } +out: + /* cleanup to avoid memory leaks */ + if (value != NULL) + scf_value_destroy(value); + if (iter != NULL) + scf_iter_destroy(iter); + if (prop != NULL) + scf_property_destroy(prop); + if (name != NULL) + free(name); + if (valuestr != NULL) + free(valuestr); + return (ret); } /* * sa_extract_attrs(root, handle, instance) * - * local function to extract the actual attributes/properties from the + * Local function to extract the actual attributes/properties from the * property group of the service instance. These are the well known * attributes of "state" and "zfs". If additional attributes are * added, they should be added here. @@ -354,42 +352,45 @@ sa_extract_attrs(xmlNodePtr root, scfutilhandle_t *handle, prop = scf_property_create(handle->handle); value = scf_value_create(handle->handle); valuestr = malloc(vallen); - if (prop != NULL && value != NULL && valuestr != NULL && - scf_instance_get_pg(instance, "operation", - handle->pg) == 0) { - /* - * have a property group with desired name so now get - * the known attributes. - */ - if (scf_pg_get_property(handle->pg, "state", prop) == 0) { - /* found the property so get the value */ + if (prop == NULL || value == NULL || valuestr == NULL || + scf_instance_get_pg(instance, "operation", handle->pg) != 0) { + goto out; + } + /* + * Have a property group with desired name so now get + * the known attributes. + */ + if (scf_pg_get_property(handle->pg, "state", prop) == 0) { + /* Found the property so get the value */ if (scf_property_get_value(prop, value) == 0) { - if (scf_value_get_astring(value, valuestr, vallen) >= 0) { - xmlSetProp(root, (xmlChar *)"state", + if (scf_value_get_astring(value, valuestr, + vallen) >= 0) { + xmlSetProp(root, (xmlChar *)"state", (xmlChar *)valuestr); - } + } } - } - if (scf_pg_get_property(handle->pg, "zfs", prop) == 0) { - /* found the property so get the value */ + } + if (scf_pg_get_property(handle->pg, "zfs", prop) == 0) { + /* Found the property so get the value */ if (scf_property_get_value(prop, value) == 0) { - if (scf_value_get_astring(value, valuestr, vallen) > 0) { - xmlSetProp(root, (xmlChar *)"zfs", + if (scf_value_get_astring(value, valuestr, + vallen) > 0) { + xmlSetProp(root, (xmlChar *)"zfs", (xmlChar *)valuestr); - } + } } - } } +out: if (valuestr != NULL) - free(valuestr); + free(valuestr); if (value != NULL) - scf_value_destroy(value); + scf_value_destroy(value); if (prop != NULL) - scf_property_destroy(prop); + scf_property_destroy(prop); } /* - * list of known share attributes. + * List of known share attributes. */ static char *share_attr[] = { @@ -404,15 +405,15 @@ is_share_attr(char *name) { int i; for (i = 0; share_attr[i] != NULL; i++) - if (strcmp(name, share_attr[i]) == 0) - return (1); + if (strcmp(name, share_attr[i]) == 0) + return (1); return (0); } /* * sa_share_from_pgroup * - * extract the share definition from the share property group. We do + * Extract the share definition from the share property group. We do * some sanity checking to avoid bad data. * * Since this is only constructing the internal data structures, we @@ -440,12 +441,13 @@ sa_share_from_pgroup(xmlNodePtr root, scfutilhandle_t *handle, */ vallen = strlen(id); if (*id == SA_SHARE_PG_PREFIX[0] && vallen == SA_SHARE_PG_LEN) { - uuid_t uuid; - if (strncmp(id, SA_SHARE_PG_PREFIX, SA_SHARE_PG_PREFIXLEN) != 0 || - uuid_parse(id + 2, uuid) < 0) - return; + uuid_t uuid; + if (strncmp(id, SA_SHARE_PG_PREFIX, + SA_SHARE_PG_PREFIXLEN) != 0 || + uuid_parse(id + 2, uuid) < 0) + return; } else { - return; + return; } vallen = get_scf_limit(SCF_LIMIT_MAX_VALUE_LENGTH); @@ -457,7 +459,7 @@ sa_share_from_pgroup(xmlNodePtr root, scfutilhandle_t *handle, valuestr = malloc(vallen); /* - * construct the share XML node. It is similar to sa_add_share + * Construct the share XML node. It is similar to sa_add_share * but never changes the repository. Also, there won't be any * ZFS or transient shares. Root will be the group it is * associated with. @@ -465,81 +467,82 @@ sa_share_from_pgroup(xmlNodePtr root, scfutilhandle_t *handle, node = xmlNewChild(root, NULL, (xmlChar *)"share", NULL); if (node != NULL) { /* - * make sure the UUID part of the property group is + * Make sure the UUID part of the property group is * stored in the share "id" property. We use this * later. */ - xmlSetProp(node, (xmlChar *)"id", (xmlChar *)id); - xmlSetProp(node, (xmlChar *)"type", (xmlChar *)"persist"); + xmlSetProp(node, (xmlChar *)"id", (xmlChar *)id); + xmlSetProp(node, (xmlChar *)"type", (xmlChar *)"persist"); } - if (iter != NULL && value != NULL && prop != NULL && name != NULL) { - /* iterate over the share pg properties */ - if (scf_iter_pg_properties(iter, pg) == 0) { - while (scf_iter_next_property(iter, prop) > 0) { - ret = SA_SYSTEM_ERR; /* assume the worst */ - if (scf_property_get_name(prop, name, - scf_max_name_len) > 0) { + if (iter == NULL || value == NULL || prop == NULL || name == NULL) + goto out; + + /* Iterate over the share pg properties */ + if (scf_iter_pg_properties(iter, pg) != 0) + goto out; + + while (scf_iter_next_property(iter, prop) > 0) { + ret = SA_SYSTEM_ERR; /* assume the worst */ + if (scf_property_get_name(prop, name, scf_max_name_len) > 0) { if (scf_property_get_value(prop, value) == 0) { - if (scf_value_get_astring(value, valuestr, - vallen) >= 0) { - ret = SA_OK; - } + if (scf_value_get_astring(value, valuestr, + vallen) >= 0) { + ret = SA_OK; + } } - } - if (ret == SA_OK) { + } + if (ret == SA_OK) { /* - * check that we have the "path" property in + * Check that we have the "path" property in * name. The string in name will always be nul * terminated if scf_property_get_name() * succeeded. */ if (strcmp(name, "path") == 0) - have_path = 1; + have_path = 1; if (is_share_attr(name)) { /* - * if a share attr, then simple - + * If a share attr, then simple - * usually path and resource name */ - xmlSetProp(node, (xmlChar *)name, - (xmlChar *)valuestr); + xmlSetProp(node, (xmlChar *)name, + (xmlChar *)valuestr); } else { - if (strcmp(name, "description") == 0) { - /* we have a description node */ - xmlNodePtr desc; - desc = xmlNewChild(node, NULL, - (xmlChar *)"description", - NULL); - if (desc != NULL) - xmlNodeSetContent(desc, - (xmlChar *)valuestr); - } + if (strcmp(name, "description") == 0) { + /* We have a description node */ + xmlNodePtr desc; + desc = xmlNewChild(node, NULL, + (xmlChar *)"description", NULL); + if (desc != NULL) + xmlNodeSetContent(desc, + (xmlChar *)valuestr); + } } - } } - } } +out: /* - * a share without a path is broken so we want to not include + * A share without a path is broken so we want to not include * these. They shouldn't happen but if you kill a sharemgr in * the process of creating a share, it could happen. They * should be harmless. It is also possible that another * sharemgr is running and in the process of creating a share. */ if (have_path == 0 && node != NULL) { - xmlUnlinkNode(node); - xmlFreeNode(node); + xmlUnlinkNode(node); + xmlFreeNode(node); } if (name != NULL) - free(name); + free(name); if (valuestr != NULL) - free(valuestr); + free(valuestr); if (value != NULL) - scf_value_destroy(value); + scf_value_destroy(value); if (iter != NULL) - scf_iter_destroy(iter); + scf_iter_destroy(iter); if (prop != NULL) - scf_property_destroy(prop); + scf_property_destroy(prop); } /* @@ -557,10 +560,12 @@ find_share_by_id(sa_handle_t handle, char *shareid) char *id = NULL; int done = 0; - for (group = sa_get_group(handle, NULL); group != NULL && !done; - group = sa_get_next_group(group)) { - for (share = sa_get_share(group, NULL); share != NULL; - share = sa_get_next_share(share)) { + for (group = sa_get_group(handle, NULL); + group != NULL && !done; + group = sa_get_next_group(group)) { + for (share = sa_get_share(group, NULL); + share != NULL; + share = sa_get_next_share(share)) { id = sa_get_share_attr(share, "id"); if (id != NULL && strcmp(id, shareid) == 0) { sa_free_attr_string(id); @@ -569,8 +574,8 @@ find_share_by_id(sa_handle_t handle, char *shareid) break; } if (id != NULL) { - sa_free_attr_string(id); - id = NULL; + sa_free_attr_string(id); + id = NULL; } } } @@ -580,7 +585,7 @@ find_share_by_id(sa_handle_t handle, char *shareid) /* * sa_share_props_from_pgroup(root, handle, pg, id) * - * extract share properties from the SMF property group. More sanity + * Extract share properties from the SMF property group. More sanity * checks are done and the share object is created. We ignore some * errors that could exist in the repository and only worry about * property groups that validate in naming. @@ -591,16 +596,17 @@ sa_share_props_from_pgroup(xmlNodePtr root, scfutilhandle_t *handle, scf_propertygroup_t *pg, char *id, sa_handle_t sahandle) { xmlNodePtr node; - char *name; - scf_iter_t *iter; - scf_property_t *prop; - scf_value_t *value; + char *name = NULL; + scf_iter_t *iter = NULL; + scf_property_t *prop = NULL; + scf_value_t *value = NULL; ssize_t vallen; - char *valuestr; + char *valuestr = NULL; int ret = SA_OK; char *sectype = NULL; char *proto; sa_share_t share; + uuid_t uuid; /* * While preliminary check (starts with 'S') passed before @@ -611,39 +617,37 @@ sa_share_props_from_pgroup(xmlNodePtr root, scfutilhandle_t *handle, * versions. */ vallen = strlen(id); - if (*id == SA_SHARE_PG_PREFIX[0] && vallen > SA_SHARE_PG_LEN) { - uuid_t uuid; - if (strncmp(id, SA_SHARE_PG_PREFIX, SA_SHARE_PG_PREFIXLEN) == 0) { + if (*id != SA_SHARE_PG_PREFIX[0] || vallen <= SA_SHARE_PG_LEN) { + /* + * It is ok to not have what we thought since someone might + * have added a name via SMF. + */ + return (ret); + } + if (strncmp(id, SA_SHARE_PG_PREFIX, SA_SHARE_PG_PREFIXLEN) == 0) { proto = strchr(id, '_'); if (proto == NULL) - return (ret); + return (ret); *proto++ = '\0'; if (uuid_parse(id + SA_SHARE_PG_PREFIXLEN, uuid) < 0) - return (ret); + return (ret); /* * probably a legal optionset so check a few more * syntax points below. */ if (*proto == '\0') { - /* not a valid proto (null) */ - return (ret); + /* not a valid proto (null) */ + return (ret); } sectype = strchr(proto, '_'); if (sectype != NULL) - *sectype++ = '\0'; + *sectype++ = '\0'; if (!valid_protocol(proto)) - return (ret); - } - } else { - /* - * it is ok to not have what we thought since someone might - * have added a name via SMF. - */ - return (ret); + return (ret); } /* - * to get here, we have a valid protocol and possibly a + * To get here, we have a valid protocol and possibly a * security. We now have to find the share that it is really * associated with. The "id" portion of the pgroup name will * match. @@ -651,78 +655,82 @@ sa_share_props_from_pgroup(xmlNodePtr root, scfutilhandle_t *handle, share = find_share_by_id(sahandle, id); if (share == NULL) - return (SA_BAD_PATH); + return (SA_BAD_PATH); root = (xmlNodePtr)share; vallen = get_scf_limit(SCF_LIMIT_MAX_VALUE_LENGTH); + if (sectype == NULL) + node = xmlNewChild(root, NULL, (xmlChar *)"optionset", NULL); + else { + node = xmlNewChild(root, NULL, (xmlChar *)"security", NULL); + if (node != NULL) + xmlSetProp(node, (xmlChar *)"sectype", + (xmlChar *)sectype); + } + if (node == NULL) { + ret = SA_NO_MEMORY; + goto out; + } + + xmlSetProp(node, (xmlChar *)"type", (xmlChar *)proto); + /* now find the properties */ iter = scf_iter_create(handle->handle); value = scf_value_create(handle->handle); prop = scf_property_create(handle->handle); name = malloc(scf_max_name_len); valuestr = malloc(vallen); - if (sectype == NULL) - node = xmlNewChild(root, NULL, (xmlChar *)"optionset", NULL); - else { - node = xmlNewChild(root, NULL, (xmlChar *)"security", NULL); - if (node != NULL) - xmlSetProp(node, (xmlChar *)"sectype", (xmlChar *)sectype); - } - if (node != NULL) { - xmlSetProp(node, (xmlChar *)"type", (xmlChar *)proto); - /* now find the properties */ - if (iter != NULL && value != NULL && prop != NULL && name != NULL) { - /* iterate over the share pg properties */ - if (scf_iter_pg_properties(iter, pg) == 0) { - while (scf_iter_next_property(iter, prop) > 0) { + if (iter == NULL || value == NULL || prop == NULL || name == NULL) + goto out; + + /* Iterate over the share pg properties */ + if (scf_iter_pg_properties(iter, pg) == 0) { + while (scf_iter_next_property(iter, prop) > 0) { ret = SA_SYSTEM_ERR; /* assume the worst */ if (scf_property_get_name(prop, name, - scf_max_name_len) > 0) { - if (scf_property_get_value(prop, value) == 0) { - if (scf_value_get_astring(value, valuestr, - vallen) >= 0) { - ret = SA_OK; + scf_max_name_len) > 0) { + if (scf_property_get_value(prop, value) == 0) { + if (scf_value_get_astring(value, + valuestr, vallen) >= 0) { + ret = SA_OK; + } } - } } else { - ret = SA_SYSTEM_ERR; + ret = SA_SYSTEM_ERR; } if (ret == SA_OK) { - sa_property_t prop; - prop = sa_create_property(name, valuestr); - if (prop != NULL) - prop = (sa_property_t)xmlAddChild(node, - (xmlNodePtr)prop); - else - ret = SA_NO_MEMORY; + sa_property_t prop; + prop = sa_create_property(name, valuestr); + if (prop != NULL) + prop = (sa_property_t)xmlAddChild(node, + (xmlNodePtr)prop); + else + ret = SA_NO_MEMORY; } - } - } else { - ret = SA_SYSTEM_ERR; } - } } else { - ret = SA_NO_MEMORY; + ret = SA_SYSTEM_ERR; } +out: if (iter != NULL) - scf_iter_destroy(iter); + scf_iter_destroy(iter); if (value != NULL) - scf_value_destroy(value); + scf_value_destroy(value); if (prop != NULL) - scf_property_destroy(prop); + scf_property_destroy(prop); if (name != NULL) - free(name); + free(name); if (valuestr != NULL) - free(valuestr); + free(valuestr); return (ret); } /* * sa_extract_group(root, handle, instance) * - * get the config info for this instance of a group and create the XML + * Get the config info for this instance of a group and create the XML * subtree from it. */ @@ -742,152 +750,153 @@ sa_extract_group(xmlNodePtr root, scfutilhandle_t *handle, int err; buff = malloc(scf_max_name_len); + if (buff == NULL) + return (SA_NO_MEMORY); + iter = scf_iter_create(handle->handle); - if (buff != NULL) { - if (scf_instance_get_name(instance, buff, - scf_max_name_len) > 0) { + if (iter == NULL) { + ret = SA_NO_MEMORY; + goto out; + } + + if (scf_instance_get_name(instance, buff, scf_max_name_len) > 0) { node = xmlNewChild(root, NULL, (xmlChar *)"group", NULL); - if (node != NULL) { - xmlSetProp(node, (xmlChar *)"name", (xmlChar *)buff); - if (strcmp(buff, "default") == 0) + if (node == NULL) { + ret = SA_NO_MEMORY; + goto out; + } + xmlSetProp(node, (xmlChar *)"name", (xmlChar *)buff); + if (strcmp(buff, "default") == 0) is_default++; - sa_extract_attrs(node, handle, instance); - /* - * Iterate through all the property groups - * looking for those with security or - * optionset prefixes. The names of the - * matching pgroups are parsed to get the - * protocol, and for security, the sectype. - * Syntax is as follows: - * optionset | optionset_<proto> - * security_default | security_<proto>_<sectype> - * "operation" is handled by - * sa_extract_attrs(). - */ - if (iter != NULL) { - if (scf_iter_instance_pgs(iter, instance) == 0) { - while (scf_iter_next_pg(iter, handle->pg) > 0) { - /* have a pgroup so sort it out */ - ret = scf_pg_get_name(handle->pg, buff, - scf_max_name_len); - if (ret > 0) { - if (buff[0] == SA_SHARE_PG_PREFIX[0]) { + + sa_extract_attrs(node, handle, instance); + /* + * Iterate through all the property groups + * looking for those with security or + * optionset prefixes. The names of the + * matching pgroups are parsed to get the + * protocol, and for security, the sectype. + * Syntax is as follows: + * optionset | optionset_<proto> + * security_default | security_<proto>_<sectype> + * "operation" is handled by + * sa_extract_attrs(). + */ + if (scf_iter_instance_pgs(iter, instance) != 0) { + ret = SA_NO_MEMORY; + goto out; + } + while (scf_iter_next_pg(iter, handle->pg) > 0) { + /* Have a pgroup so sort it out */ + ret = scf_pg_get_name(handle->pg, buff, + scf_max_name_len); + if (ret > 0) { + if (buff[0] == SA_SHARE_PG_PREFIX[0]) { sa_share_from_pgroup(node, handle, - handle->pg, - buff); + handle->pg, buff); have_shares++; - } else if (strncmp(buff, "optionset", 9) == - 0) { + } else if (strncmp(buff, "optionset", 9) == + 0) { char *nodetype = "optionset"; - /* have an optionset */ + /* Have an optionset */ sectype = NULL; proto = strchr(buff, '_'); if (proto != NULL) { - *proto++ = '\0'; - sectype = strchr(proto, '_'); - if (sectype != NULL) { - *sectype++ = '\0'; - nodetype = "security"; - } + *proto++ = '\0'; + sectype = strchr(proto, '_'); + if (sectype != NULL) { + *sectype++ = '\0'; + nodetype = "security"; + } } ret = sa_extract_pgroup(node, handle, - handle->pg, - nodetype, - proto, sectype); + handle->pg, nodetype, proto, + sectype); has_proto++; - } else if (strncmp(buff, - "security", 8) == 0) { + } else if (strncmp(buff, "security", 8) == 0) { /* - * have a security (note that + * Have a security (note that * this should change in the * future) */ proto = strchr(buff, '_'); sectype = NULL; if (proto != NULL) { - *proto++ = '\0'; - sectype = strchr(proto, '_'); - if (sectype != NULL) - *sectype++ = '\0'; - if (strcmp(proto, "default") == 0) - proto = NULL; + *proto++ = '\0'; + sectype = strchr(proto, '_'); + if (sectype != NULL) + *sectype++ = '\0'; + if (strcmp(proto, "default") == + 0) + proto = NULL; } ret = sa_extract_pgroup(node, handle, - handle->pg, - "security", proto, - sectype); + handle->pg, "security", proto, + sectype); has_proto++; - } - /* ignore everything else */ } - } - } else { - ret = SA_NO_MEMORY; + /* Ignore everything else */ } - /* - * Make sure we have a valid default group. - * On first boot, default won't have any - * protocols defined and won't be enabled (but - * should be). - */ - if (is_default) { - char *state = sa_get_group_attr((sa_group_t)node, - "state"); - char **protos; - int numprotos; - int i; - - if (state == NULL) { + } + /* + * Make sure we have a valid default group. + * On first boot, default won't have any + * protocols defined and won't be enabled (but + * should be). + */ + if (is_default) { + char *state = sa_get_group_attr((sa_group_t)node, + "state"); + char **protos; + int numprotos; + int i; + + if (state == NULL) { /* set attribute to enabled */ (void) sa_set_group_attr((sa_group_t)node, - "state", - "enabled"); - /* we can assume no protocols */ + "state", "enabled"); + /* We can assume no protocols */ numprotos = sa_get_protocols(&protos); for (i = 0; i < numprotos; i++) - (void) sa_create_optionset((sa_group_t)node, - protos[i]); + (void) sa_create_optionset( + (sa_group_t)node, protos[i]); if (numprotos > 0) - free(protos); - } else { + free(protos); + } else { sa_free_attr_string(state); - } } - /* do a second pass if shares were found */ - if (have_shares && - scf_iter_instance_pgs(iter, instance) == 0) { - while (scf_iter_next_pg(iter, handle->pg) > 0) { + } + /* Do a second pass if shares were found */ + if (have_shares && scf_iter_instance_pgs(iter, instance) == 0) { + while (scf_iter_next_pg(iter, handle->pg) > 0) { /* - * have a pgroup so see if it is a + * Have a pgroup so see if it is a * share optionset */ err = scf_pg_get_name(handle->pg, buff, - scf_max_name_len); - if (err > 0) { - if (buff[0] == SA_SHARE_PG_PREFIX[0]) { + scf_max_name_len); + if (err <= 0) + continue; + if (buff[0] == SA_SHARE_PG_PREFIX[0]) { ret = sa_share_props_from_pgroup(node, - handle, - handle->pg, - buff, sahandle); - } + handle, handle->pg, buff, + sahandle); } - } } - } } - } } +out: if (iter != NULL) - scf_iter_destroy(iter); + scf_iter_destroy(iter); if (buff != NULL) - free(buff); + free(buff); return (ret); } /* * sa_extract_defaults(root, handle, instance) * - * local function to find the default properties that live in the + * Local function to find the default properties that live in the * default instance's "operation" proprerty group. */ @@ -905,39 +914,41 @@ sa_extract_defaults(xmlNodePtr root, scfutilhandle_t *handle, prop = scf_property_create(handle->handle); value = scf_value_create(handle->handle); valuestr = malloc(vallen); - if (prop != NULL && value != NULL && vallen != NULL && - scf_instance_get_pg(instance, "operation", - handle->pg) == 0) { - if (scf_pg_get_property(handle->pg, - "legacy-timestamp", prop) == 0) { - /* found the property so get the value */ - if (scf_property_get_value(prop, value) == 0) { - if (scf_value_get_astring(value, valuestr, vallen) > 0) { + + if (prop == NULL || value == NULL || vallen == 0 || + scf_instance_get_pg(instance, "operation", handle->pg) != 0) + goto out; + + if (scf_pg_get_property(handle->pg, "legacy-timestamp", prop) != 0) + goto out; + + /* Found the property so get the value */ + if (scf_property_get_value(prop, value) == 0) { + if (scf_value_get_astring(value, valuestr, vallen) > 0) { node = xmlNewChild(root, NULL, (xmlChar *)"legacy", - NULL); + NULL); if (node != NULL) { - xmlSetProp(node, (xmlChar *)"timestamp", - (xmlChar *)valuestr); - xmlSetProp(node, (xmlChar *)"path", - (xmlChar *)SA_LEGACY_DFSTAB); + xmlSetProp(node, (xmlChar *)"timestamp", + (xmlChar *)valuestr); + xmlSetProp(node, (xmlChar *)"path", + (xmlChar *)SA_LEGACY_DFSTAB); } - } } - } } +out: if (valuestr != NULL) - free(valuestr); + free(valuestr); if (value != NULL) - scf_value_destroy(value); + scf_value_destroy(value); if (prop != NULL) - scf_property_destroy(prop); + scf_property_destroy(prop); } /* * sa_get_config(handle, root, doc, sahandlec) * - * walk the SMF repository for /network/shares/group and find all the + * Walk the SMF repository for /network/shares/group and find all the * instances. These become group names. Then add the XML structure * below the groups based on property groups and properties. */ @@ -952,33 +963,34 @@ sa_get_config(scfutilhandle_t *handle, xmlNodePtr root, sa_handle_t sahandle) instance = scf_instance_create(handle->handle); iter = scf_iter_create(handle->handle); if (instance != NULL && iter != NULL) { - if ((ret = scf_iter_service_instances(iter, - handle->service)) == 0) { - while ((ret = scf_iter_next_instance(iter, - instance)) > 0) { - if (scf_instance_get_name(instance, buff, - sizeof (buff)) > 0) { - if (strcmp(buff, "default") == 0) - sa_extract_defaults(root, handle, instance); - ret = sa_extract_group(root, handle, instance, - sahandle); - } + if ((ret = scf_iter_service_instances(iter, + handle->service)) == 0) { + while ((ret = scf_iter_next_instance(iter, + instance)) > 0) { + if (scf_instance_get_name(instance, buff, + sizeof (buff)) > 0) { + if (strcmp(buff, "default") == 0) + sa_extract_defaults(root, + handle, instance); + ret = sa_extract_group(root, handle, + instance, sahandle); + } + } } - } } - /* always cleanup these */ + /* Always cleanup these */ if (instance != NULL) - scf_instance_destroy(instance); + scf_instance_destroy(instance); if (iter != NULL) - scf_iter_destroy(iter); + scf_iter_destroy(iter); return (ret); } /* * sa_get_instance(handle, instance) * - * get the instance of the group service. This is actually the + * Get the instance of the group service. This is actually the * specific group name. The instance is needed for all property and * control operations. */ @@ -987,8 +999,8 @@ int sa_get_instance(scfutilhandle_t *handle, char *instname) { if (scf_service_get_instance(handle->service, instname, - handle->instance) != 0) { - return (SA_NO_SUCH_GROUP); + handle->instance) != 0) { + return (SA_NO_SUCH_GROUP); } return (SA_OK); } @@ -1006,17 +1018,17 @@ sa_create_instance(scfutilhandle_t *handle, char *instname) int ret = SA_OK; char instance[SA_GROUP_INST_LEN]; if (scf_service_add_instance(handle->service, instname, - handle->instance) != 0) { + handle->instance) != 0) { /* better error returns need to be added based on real error */ - if (scf_error() == SCF_ERROR_PERMISSION_DENIED) - ret = SA_NO_PERMISSION; - else - ret = SA_DUPLICATE_NAME; + if (scf_error() == SCF_ERROR_PERMISSION_DENIED) + ret = SA_NO_PERMISSION; + else + ret = SA_DUPLICATE_NAME; } else { - /* have the service created, so enable it */ - (void) snprintf(instance, sizeof (instance), "%s:%s", - SA_SVC_FMRI_BASE, instname); - (void) smf_enable_instance(instance, 0); + /* have the service created, so enable it */ + (void) snprintf(instance, sizeof (instance), "%s:%s", + SA_SVC_FMRI_BASE, instname); + (void) smf_enable_instance(instance, 0); } return (ret); } @@ -1033,13 +1045,13 @@ sa_delete_instance(scfutilhandle_t *handle, char *instname) int ret; if (strcmp(instname, "default") == 0) { - ret = SA_NO_PERMISSION; + ret = SA_NO_PERMISSION; } else { - if ((ret = sa_get_instance(handle, instname)) == SA_OK) { - if (scf_instance_delete(handle->instance) != 0) - /* need better analysis */ - ret = SA_NO_PERMISSION; - } + if ((ret = sa_get_instance(handle, instname)) == SA_OK) { + if (scf_instance_delete(handle->instance) != 0) + /* need better analysis */ + ret = SA_NO_PERMISSION; + } } return (ret); } @@ -1055,31 +1067,30 @@ sa_create_pgroup(scfutilhandle_t *handle, char *pgroup) { int ret = SA_OK; /* - * only create a handle if it doesn't exist. It is ok to exist + * Only create a handle if it doesn't exist. It is ok to exist * since the pg handle will be set as a side effect. */ - if (handle->pg == NULL) { - handle->pg = scf_pg_create(handle->handle); - } + if (handle->pg == NULL) + handle->pg = scf_pg_create(handle->handle); + /* - * if the pgroup exists, we are done. If it doesn't, then we + * If the pgroup exists, we are done. If it doesn't, then we * need to actually add one to the service instance. */ if (scf_instance_get_pg(handle->instance, - pgroup, handle->pg) != 0) { - /* doesn't exist so create one */ - if (scf_instance_add_pg(handle->instance, pgroup, - SCF_GROUP_APPLICATION, 0, - handle->pg) != 0) { - switch (scf_error()) { - case SCF_ERROR_PERMISSION_DENIED: - ret = SA_NO_PERMISSION; - break; - default: - ret = SA_SYSTEM_ERR; - break; + pgroup, handle->pg) != 0) { + /* Doesn't exist so create one */ + if (scf_instance_add_pg(handle->instance, pgroup, + SCF_GROUP_APPLICATION, 0, handle->pg) != 0) { + switch (scf_error()) { + case SCF_ERROR_PERMISSION_DENIED: + ret = SA_NO_PERMISSION; + break; + default: + ret = SA_SYSTEM_ERR; + break; + } } - } } return (ret); } @@ -1087,7 +1098,7 @@ sa_create_pgroup(scfutilhandle_t *handle, char *pgroup) /* * sa_delete_pgroup(handle, pgroup) * - * remove the property group from the current instance of the service, + * Remove the property group from the current instance of the service, * but only if it actually exists. */ @@ -1096,16 +1107,14 @@ sa_delete_pgroup(scfutilhandle_t *handle, char *pgroup) { int ret = SA_OK; /* - * only delete if it does exist. + * Only delete if it does exist. */ - if (scf_instance_get_pg(handle->instance, - pgroup, handle->pg) == 0) { - /* does exist so delete it */ - if (scf_pg_delete(handle->pg) != 0) { - ret = SA_SYSTEM_ERR; - } + if (scf_instance_get_pg(handle->instance, pgroup, handle->pg) == 0) { + /* does exist so delete it */ + if (scf_pg_delete(handle->pg) != 0) + ret = SA_SYSTEM_ERR; } else { - ret = SA_SYSTEM_ERR; + ret = SA_SYSTEM_ERR; } if (ret == SA_SYSTEM_ERR && scf_error() == SCF_ERROR_PERMISSION_DENIED) { @@ -1136,25 +1145,26 @@ sa_start_transaction(scfutilhandle_t *handle, char *propgroup) { int ret = SA_OK; /* - * lookup the property group and create it if it doesn't already + * Lookup the property group and create it if it doesn't already * exist. */ if (handle->scf_state == SCH_STATE_INIT) { - ret = sa_create_pgroup(handle, propgroup); - if (ret == SA_OK) { - handle->trans = scf_transaction_create(handle->handle); - if (handle->trans != NULL) { - if (scf_transaction_start(handle->trans, handle->pg) != 0) { - ret = SA_SYSTEM_ERR; - } - if (ret != SA_OK) { - scf_transaction_destroy(handle->trans); - handle->trans = NULL; - } - } else { - ret = SA_SYSTEM_ERR; + ret = sa_create_pgroup(handle, propgroup); + if (ret == SA_OK) { + handle->trans = scf_transaction_create(handle->handle); + if (handle->trans != NULL) { + if (scf_transaction_start(handle->trans, + handle->pg) != 0) { + ret = SA_SYSTEM_ERR; + } + if (ret != SA_OK) { + scf_transaction_destroy(handle->trans); + handle->trans = NULL; + } + } else { + ret = SA_SYSTEM_ERR; + } } - } } if (ret == SA_SYSTEM_ERR && scf_error() == SCF_ERROR_PERMISSION_DENIED) { @@ -1176,13 +1186,13 @@ sa_end_transaction(scfutilhandle_t *handle) int ret = SA_OK; if (handle->trans == NULL) { - ret = SA_SYSTEM_ERR; - } else { - if (scf_transaction_commit(handle->trans) < 0) ret = SA_SYSTEM_ERR; - scf_transaction_destroy_children(handle->trans); - scf_transaction_destroy(handle->trans); - handle->trans = NULL; + } else { + if (scf_transaction_commit(handle->trans) < 0) + ret = SA_SYSTEM_ERR; + scf_transaction_destroy_children(handle->trans); + scf_transaction_destroy(handle->trans); + handle->trans = NULL; } return (ret); } @@ -1198,17 +1208,17 @@ void sa_abort_transaction(scfutilhandle_t *handle) { if (handle->trans != NULL) { - scf_transaction_reset_all(handle->trans); - scf_transaction_destroy_children(handle->trans); - scf_transaction_destroy(handle->trans); - handle->trans = NULL; + scf_transaction_reset_all(handle->trans); + scf_transaction_destroy_children(handle->trans); + scf_transaction_destroy(handle->trans); + handle->trans = NULL; } } /* * sa_set_property(handle, prop, value) * - * set a property transaction entry into the pending SMF transaction. + * Set a property transaction entry into the pending SMF transaction. */ int @@ -1218,59 +1228,57 @@ sa_set_property(scfutilhandle_t *handle, char *propname, char *valstr) scf_value_t *value; scf_transaction_entry_t *entry; /* - * properties must be set in transactions and don't take + * Properties must be set in transactions and don't take * effect until the transaction has been ended/committed. */ value = scf_value_create(handle->handle); entry = scf_entry_create(handle->handle); if (value != NULL && entry != NULL) { - if (scf_transaction_property_change(handle->trans, entry, - propname, - SCF_TYPE_ASTRING) == 0 || - scf_transaction_property_new(handle->trans, entry, - propname, - SCF_TYPE_ASTRING) == 0) { - if (scf_value_set_astring(value, valstr) == 0) { - if (scf_entry_add_value(entry, value) != 0) { - ret = SA_SYSTEM_ERR; - scf_value_destroy(value); - } - /* the value is in the transaction */ - value = NULL; + if (scf_transaction_property_change(handle->trans, entry, + propname, SCF_TYPE_ASTRING) == 0 || + scf_transaction_property_new(handle->trans, entry, + propname, SCF_TYPE_ASTRING) == 0) { + if (scf_value_set_astring(value, valstr) == 0) { + if (scf_entry_add_value(entry, value) != 0) { + ret = SA_SYSTEM_ERR; + scf_value_destroy(value); + } + /* The value is in the transaction */ + value = NULL; + } else { + /* Value couldn't be constructed */ + ret = SA_SYSTEM_ERR; + } + /* The entry is in the transaction */ + entry = NULL; } else { - /* value couldn't be constructed */ - ret = SA_SYSTEM_ERR; + ret = SA_SYSTEM_ERR; } - /* the entry is in the transaction */ - entry = NULL; - } else { - ret = SA_SYSTEM_ERR; - } } else { - ret = SA_SYSTEM_ERR; + ret = SA_SYSTEM_ERR; } if (ret == SA_SYSTEM_ERR) { - switch (scf_error()) { - case SCF_ERROR_PERMISSION_DENIED: - ret = SA_NO_PERMISSION; - break; - } + switch (scf_error()) { + case SCF_ERROR_PERMISSION_DENIED: + ret = SA_NO_PERMISSION; + break; + } } /* - * cleanup if there were any errors that didn't leave these + * Cleanup if there were any errors that didn't leave these * values where they would be cleaned up later. */ if (value != NULL) - scf_value_destroy(value); + scf_value_destroy(value); if (entry != NULL) - scf_entry_destroy(entry); + scf_entry_destroy(entry); return (ret); } /* * sa_commit_share(handle, group, share) * - * commit this share to the repository. + * Commit this share to the repository. * properties are added if they exist but can be added later. * Need to add to dfstab and sharetab, if appropriate. */ @@ -1287,113 +1295,120 @@ sa_commit_share(scfutilhandle_t *handle, sa_group_t group, sa_share_t share) char *propstring; /* - * don't commit in the zfs group. We do commit legacy + * Don't commit in the zfs group. We do commit legacy * (default) and all other groups/shares. ZFS is handled * through the ZFS configuration rather than SMF. */ groupname = sa_get_group_attr(group, "name"); if (groupname != NULL) { - if (strcmp(groupname, "zfs") == 0) { - /* - * adding to the ZFS group will result in the sharenfs - * property being set but we don't want to do anything - * SMF related at this point. - */ - sa_free_attr_string(groupname); - return (ret); - } + if (strcmp(groupname, "zfs") == 0) { + /* + * Adding to the ZFS group will result in the sharenfs + * property being set but we don't want to do anything + * SMF related at this point. + */ + sa_free_attr_string(groupname); + return (ret); + } } proplen = get_scf_limit(SCF_LIMIT_MAX_VALUE_LENGTH); propstring = malloc(proplen); if (propstring == NULL) - ret = SA_NO_MEMORY; + ret = SA_NO_MEMORY; if (groupname != NULL && ret == SA_OK) { - ret = sa_get_instance(handle, groupname); - sa_free_attr_string(groupname); - groupname = NULL; - sharename = sa_get_share_attr(share, "id"); - if (sharename == NULL) { - /* slipped by */ - char shname[SA_SHARE_UUID_BUFLEN]; - generate_unique_sharename(shname); - xmlSetProp((xmlNodePtr)share, (xmlChar *)"id", + ret = sa_get_instance(handle, groupname); + sa_free_attr_string(groupname); + groupname = NULL; + sharename = sa_get_share_attr(share, "id"); + if (sharename == NULL) { + /* slipped by */ + char shname[SA_SHARE_UUID_BUFLEN]; + generate_unique_sharename(shname); + xmlSetProp((xmlNodePtr)share, (xmlChar *)"id", (xmlChar *)shname); - sharename = strdup(shname); - } - if (sharename != NULL) { - sigset_t old, new; - /* - * have a share name allocated so create a pgroup for - * it. It may already exist, but that is OK. In order - * to avoid creating a share pgroup that doesn't have - * a path property, block signals around the critical - * region of creating the share pgroup and props. - */ - (void) sigprocmask(SIG_BLOCK, NULL, &new); - (void) sigaddset(&new, SIGHUP); - (void) sigaddset(&new, SIGINT); - (void) sigaddset(&new, SIGQUIT); - (void) sigaddset(&new, SIGTSTP); - (void) sigprocmask(SIG_SETMASK, &new, &old); - - ret = sa_create_pgroup(handle, sharename); - if (ret == SA_OK) { + sharename = strdup(shname); + } + if (sharename != NULL) { + sigset_t old, new; /* - * now start the transaction for the - * properties that define this share. They may - * exist so attempt to update before create. + * Have a share name allocated so create a pgroup for + * it. It may already exist, but that is OK. In order + * to avoid creating a share pgroup that doesn't have + * a path property, block signals around the critical + * region of creating the share pgroup and props. */ - ret = sa_start_transaction(handle, sharename); - } - if (ret == SA_OK) { - name = sa_get_share_attr(share, "path"); - if (name != NULL) { - /* there needs to be a path for a share to exist */ - ret = sa_set_property(handle, "path", name); - sa_free_attr_string(name); - } else { - ret = SA_NO_MEMORY; - } - } - if (ret == SA_OK) { - resource = sa_get_share_attr(share, "resource"); - if (resource != NULL) { - ret = sa_set_property(handle, "resource", resource); - sa_free_attr_string(resource); - } - } - if (ret == SA_OK) { - description = sa_get_share_description(share); - if (description != NULL) { - ret = sa_set_property(handle, "description", - description); - sa_free_share_description(description); - } - } - /* make sure we cleanup the transaction */ - if (ret == SA_OK) { - ret = sa_end_transaction(handle); - } else { - sa_abort_transaction(handle); - } + (void) sigprocmask(SIG_BLOCK, NULL, &new); + (void) sigaddset(&new, SIGHUP); + (void) sigaddset(&new, SIGINT); + (void) sigaddset(&new, SIGQUIT); + (void) sigaddset(&new, SIGTSTP); + (void) sigprocmask(SIG_SETMASK, &new, &old); + + ret = sa_create_pgroup(handle, sharename); + if (ret == SA_OK) { + /* + * Now start the transaction for the + * properties that define this share. They may + * exist so attempt to update before create. + */ + ret = sa_start_transaction(handle, sharename); + } + if (ret == SA_OK) { + name = sa_get_share_attr(share, "path"); + if (name != NULL) { + /* + * There needs to be a path + * for a share to exist. + */ + ret = sa_set_property(handle, "path", + name); + sa_free_attr_string(name); + } else { + ret = SA_NO_MEMORY; + } + } + if (ret == SA_OK) { + resource = sa_get_share_attr(share, + "resource"); + if (resource != NULL) { + ret = sa_set_property(handle, + "resource", resource); + sa_free_attr_string(resource); + } + } + if (ret == SA_OK) { + description = sa_get_share_description(share); + if (description != NULL) { + ret = sa_set_property(handle, + "description", + description); + sa_free_share_description(description); + } + } + /* Make sure we cleanup the transaction */ + if (ret == SA_OK) { + ret = sa_end_transaction(handle); + } else { + sa_abort_transaction(handle); + } - (void) sigprocmask(SIG_SETMASK, &old, NULL); + (void) sigprocmask(SIG_SETMASK, &old, NULL); - free(sharename); - } + free(sharename); + } } if (ret == SA_SYSTEM_ERR) { - int err = scf_error(); - if (err == SCF_ERROR_PERMISSION_DENIED) - ret = SA_NO_PERMISSION; + int err = scf_error(); + if (err == SCF_ERROR_PERMISSION_DENIED) + ret = SA_NO_PERMISSION; } if (propstring != NULL) - free(propstring); + free(propstring); if (groupname != NULL) - sa_free_attr_string(groupname); + sa_free_attr_string(groupname); return (ret); } @@ -1401,7 +1416,7 @@ sa_commit_share(scfutilhandle_t *handle, sa_group_t group, sa_share_t share) /* * sa_delete_share(handle, group, share) * - * remove the specified share from the group (and service instance). + * Remove the specified share from the group (and service instance). */ int @@ -1418,63 +1433,69 @@ sa_delete_share(scfutilhandle_t *handle, sa_group_t group, sa_share_t share) proplen = get_scf_limit(SCF_LIMIT_MAX_VALUE_LENGTH); propstring = malloc(proplen); if (propstring == NULL) - ret = SA_NO_MEMORY; + ret = SA_NO_MEMORY; if (ret == SA_OK) { - groupname = sa_get_group_attr(group, "name"); - shareid = sa_get_share_attr(share, "id"); - if (groupname != NULL && shareid != NULL) { + groupname = sa_get_group_attr(group, "name"); + shareid = sa_get_share_attr(share, "id"); + if (groupname == NULL || shareid == NULL) { + ret = SA_CONFIG_ERR; + goto out; + } ret = sa_get_instance(handle, groupname); if (ret == SA_OK) { - /* if a share has properties, remove them */ - ret = sa_delete_pgroup(handle, shareid); - for (opt = sa_get_optionset(share, NULL); opt != NULL; - opt = sa_get_next_optionset(opt)) { - char *proto; - proto = sa_get_optionset_attr(opt, "type"); - if (proto != NULL) { - (void) snprintf(propstring, proplen, "%s_%s", - shareid, proto); - ret = sa_delete_pgroup(handle, propstring); - sa_free_attr_string(proto); - } else { - ret = SA_NO_MEMORY; + /* If a share has properties, remove them */ + ret = sa_delete_pgroup(handle, shareid); + for (opt = sa_get_optionset(share, NULL); + opt != NULL; + opt = sa_get_next_optionset(opt)) { + char *proto; + proto = sa_get_optionset_attr(opt, "type"); + if (proto != NULL) { + (void) snprintf(propstring, + proplen, "%s_%s", shareid, + proto); + ret = sa_delete_pgroup(handle, + propstring); + sa_free_attr_string(proto); + } else { + ret = SA_NO_MEMORY; + } } - } /* - * if a share has security/negotiable + * If a share has security/negotiable * properties, remove them. */ - for (sec = sa_get_security(share, NULL, NULL); sec != NULL; - sec = sa_get_next_security(sec)) { - char *proto; - char *sectype; - proto = sa_get_security_attr(sec, "type"); - sectype = sa_get_security_attr(sec, "sectype"); - if (proto != NULL && sectype != NULL) { - (void) snprintf(propstring, proplen, "%s_%s_%s", - shareid, - proto, sectype); - ret = sa_delete_pgroup(handle, propstring); - } else { - ret = SA_NO_MEMORY; + for (sec = sa_get_security(share, NULL, NULL); + sec != NULL; + sec = sa_get_next_security(sec)) { + char *proto; + char *sectype; + proto = sa_get_security_attr(sec, "type"); + sectype = sa_get_security_attr(sec, "sectype"); + if (proto != NULL && sectype != NULL) { + (void) snprintf(propstring, proplen, + "%s_%s_%s", shareid, proto, + sectype); + ret = sa_delete_pgroup(handle, + propstring); + } else { + ret = SA_NO_MEMORY; + } + if (proto != NULL) + sa_free_attr_string(proto); + if (sectype != NULL) + sa_free_attr_string(sectype); } - if (proto != NULL) - sa_free_attr_string(proto); - if (sectype != NULL) - sa_free_attr_string(sectype); - } } - } else { - ret = SA_CONFIG_ERR; - } } +out: if (groupname != NULL) - sa_free_attr_string(groupname); + sa_free_attr_string(groupname); if (shareid != NULL) - sa_free_attr_string(shareid); + sa_free_attr_string(shareid); if (propstring != NULL) - free(propstring); + free(propstring); return (ret); } |