aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPawel Jakub Dawidek <pjd@FreeBSD.org>2007-04-21 13:17:23 +0000
committerPawel Jakub Dawidek <pjd@FreeBSD.org>2007-04-21 13:17:23 +0000
commit48ac84fc5683d1ebfdc51c38172c94868782c2bc (patch)
tree1939509ebc59fa7a6f7a7b1dbc8f72b597cc116f
parent00a22dc5f95299c406f873c019a9c99f4ba2c0e4 (diff)
downloadsrc-48ac84fc5683d1ebfdc51c38172c94868782c2bc.tar.gz
src-48ac84fc5683d1ebfdc51c38172c94868782c2bc.zip
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.
Notes
Notes: svn path=/head/; revision=168929
-rw-r--r--cddl/compat/opensolaris/misc/fsshare.c33
-rw-r--r--compat/opensolaris/misc/fsshare.c33
2 files changed, 50 insertions, 16 deletions
diff --git a/cddl/compat/opensolaris/misc/fsshare.c b/cddl/compat/opensolaris/misc/fsshare.c
index 802d12062adf..ca82710a3411 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);
}
diff --git a/compat/opensolaris/misc/fsshare.c b/compat/opensolaris/misc/fsshare.c
index 802d12062adf..ca82710a3411 100644
--- a/compat/opensolaris/misc/fsshare.c
+++ b/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);
}