From 2cd524ebede2b227bc0180dda7bd0d3ec7b21972 Mon Sep 17 00:00:00 2001 From: pjd Date: Sat, 21 Apr 2007 13:17:23 +0000 Subject: Improve sharenfs option handling, so it is possible to give hosts list. Before the change the command above: # zfs set sharenfs=freefall.freebsd.org,69.147.83.54 tank/foo was translated to: /tank/foo -freefall.freebsd.org -69.147.83.54 instead of: /tank/foo freefall.freebsd.org 69.147.83.54 This commit corrects this. --- cddl/compat/opensolaris/misc/fsshare.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'cddl/compat/opensolaris') diff --git a/cddl/compat/opensolaris/misc/fsshare.c b/cddl/compat/opensolaris/misc/fsshare.c index 802d120..ca82710 100644 --- a/cddl/compat/opensolaris/misc/fsshare.c +++ b/cddl/compat/opensolaris/misc/fsshare.c @@ -99,21 +99,30 @@ getline(FILE *fd, const char *skip) /* * Function translate options to a format acceptable by exports(5), eg. * - * -ro -network=192.168.0.0 -mask=255.255.255.0 -maproot=0 + * -ro -network=192.168.0.0 -mask=255.255.255.0 -maproot=0 freefall.freebsd.org 69.147.83.54 * * Accepted input formats: * - * ro,network=192.168.0.0,mask=255.255.255.0,maproot=0 - * ro network=192.168.0.0 mask=255.255.255.0 maproot=0 - * -ro,-network=192.168.0.0,-mask=255.255.255.0,-maproot=0 - * -ro -network=192.168.0.0 -mask=255.255.255.0 -maproot=0 + * ro,network=192.168.0.0,mask=255.255.255.0,maproot=0,freefall.freebsd.org + * ro network=192.168.0.0 mask=255.255.255.0 maproot=0 freefall.freebsd.org + * -ro,-network=192.168.0.0,-mask=255.255.255.0,-maproot=0,freefall.freebsd.org + * -ro -network=192.168.0.0 -mask=255.255.255.0 -maproot=0 freefall.freebsd.org + * + * Recognized keywords: + * + * ro, maproot, mapall, mask, network, alldirs, public, webnfs, index, quiet + * */ +static const char *known_opts[] = { "ro", "maproot", "mapall", "mask", + "network", "alldirs", "public", "webnfs", "index", "quiet", NULL }; static char * translate_opts(const char *shareopts) { static char newopts[OPTSSIZE]; - char oldopts[OPTSSIZE], opt[64]; + char oldopts[OPTSSIZE]; char *o, *s = NULL; + unsigned int i; + size_t len; strlcpy(oldopts, shareopts, sizeof(oldopts)); newopts[0] = '\0'; @@ -121,8 +130,16 @@ translate_opts(const char *shareopts) while ((o = strsep(&s, "-, ")) != NULL) { if (o[0] == '\0') continue; - snprintf(opt, sizeof(opt), "-%s ", o); - strlcat(newopts, opt, sizeof(newopts)); + for (i = 0; known_opts[i] != NULL; i++) { + len = strlen(known_opts[i]); + if (strncmp(known_opts[i], o, len) == 0 && + (o[len] == '\0' || o[len] == '=')) { + strlcat(newopts, "-", sizeof(newopts)); + break; + } + } + strlcat(newopts, o, sizeof(newopts)); + strlcat(newopts, " ", sizeof(newopts)); } return (newopts); } -- cgit v1.1