summaryrefslogtreecommitdiff
path: root/usr/src/lib/libzonecfg
diff options
context:
space:
mode:
authorJohn Levon <john.levon@sun.com>2010-06-16 10:02:44 -0700
committerJohn Levon <john.levon@sun.com>2010-06-16 10:02:44 -0700
commit0fbb751d81ab0a7c7ddfd8d4e447e075a9f7024f (patch)
tree547ed35c638d3c30c437e212b458d74268e35afa /usr/src/lib/libzonecfg
parentded9341448cd6e2573619c7f6fe98909bdd35ec6 (diff)
downloadillumos-joyent-0fbb751d81ab0a7c7ddfd8d4e447e075a9f7024f.tar.gz
PSARC 2010/144 lofi(7D) in non global zones
6354954 lofi support in non-global zones 6942891 prof_lookup_globaldev() leaks rootdir refs 6945005 lofiadm -a /dev/lofi/1: recursive mutex enter 6946486 lofi_ioctl() shouldn't allow disk ioctl()s on /dev/lofictl
Diffstat (limited to 'usr/src/lib/libzonecfg')
-rw-r--r--usr/src/lib/libzonecfg/common/libzonecfg.c121
-rw-r--r--usr/src/lib/libzonecfg/common/mapfile-vers3
-rw-r--r--usr/src/lib/libzonecfg/dtd/zonecfg.dtd.11
3 files changed, 95 insertions, 30 deletions
diff --git a/usr/src/lib/libzonecfg/common/libzonecfg.c b/usr/src/lib/libzonecfg/common/libzonecfg.c
index acfa78371c..8936356ec9 100644
--- a/usr/src/lib/libzonecfg/common/libzonecfg.c
+++ b/usr/src/lib/libzonecfg/common/libzonecfg.c
@@ -132,6 +132,7 @@
#define DTD_ATTR_HOSTID (const xmlChar *) "hostid"
#define DTD_ATTR_USER (const xmlChar *) "user"
#define DTD_ATTR_AUTHS (const xmlChar *) "auths"
+#define DTD_ATTR_FS_ALLOWED (const xmlChar *) "fs-allowed"
#define DTD_ENTITY_BOOLEAN "boolean"
#define DTD_ENTITY_DEVPATH "devpath"
@@ -2384,41 +2385,64 @@ zonecfg_modify_nwif(
}
/*
- * Gets the zone hostid string stored in the specified zone configuration
- * document. This function returns Z_OK on success. Z_BAD_PROPERTY is returned
- * if the config file doesn't specify a hostid or if the hostid is blank.
- *
- * Note that buflen should be at least HW_HOSTID_LEN.
+ * Must be a comma-separated list of alpha-numeric file system names.
*/
+static int
+zonecfg_valid_fs_allowed(const char *fsallowedp)
+{
+ char tmp[ZONE_FS_ALLOWED_MAX];
+ char *cp = tmp;
+ char *p;
+
+ if (strlen(fsallowedp) > ZONE_FS_ALLOWED_MAX)
+ return (Z_TOO_BIG);
+
+ (void) strlcpy(tmp, fsallowedp, sizeof (tmp));
+
+ while (*cp != '\0') {
+ p = cp;
+ while (*p != '\0' && *p != ',') {
+ if (!isalnum(*p))
+ return (Z_INVALID_PROPERTY);
+ p++;
+ }
+
+ if (*p == ',') {
+ if (p == cp)
+ return (Z_INVALID_PROPERTY);
+
+ p++;
+
+ if (*p == '\0')
+ return (Z_INVALID_PROPERTY);
+ }
+
+ cp = p;
+ }
+
+ return (Z_OK);
+}
+
int
-zonecfg_get_hostid(zone_dochandle_t handle, char *bufp, size_t buflen)
+zonecfg_get_fs_allowed(zone_dochandle_t handle, char *bufp, size_t buflen)
{
int err;
- if ((err = getrootattr(handle, DTD_ATTR_HOSTID, bufp, buflen)) != Z_OK)
+ if ((err = getrootattr(handle, DTD_ATTR_FS_ALLOWED,
+ bufp, buflen)) != Z_OK)
return (err);
if (bufp[0] == '\0')
return (Z_BAD_PROPERTY);
- return (Z_OK);
+ return (zonecfg_valid_fs_allowed(bufp));
}
-/*
- * Sets the hostid string in the specified zone config document to the given
- * string value. If 'hostidp' is NULL, then the config document's hostid
- * attribute is cleared. Non-NULL hostids are validated. This function returns
- * Z_OK on success. Any other return value indicates failure.
- */
int
-zonecfg_set_hostid(zone_dochandle_t handle, const char *hostidp)
+zonecfg_set_fs_allowed(zone_dochandle_t handle, const char *bufp)
{
int err;
- /*
- * A NULL hostid string is interpreted as a request to clear the
- * hostid.
- */
- if (hostidp == NULL || (err = zonecfg_valid_hostid(hostidp)) == Z_OK)
- return (setrootattr(handle, DTD_ATTR_HOSTID, hostidp));
+ if (bufp == NULL || (err = zonecfg_valid_fs_allowed(bufp)) == Z_OK)
+ return (setrootattr(handle, DTD_ATTR_FS_ALLOWED, bufp));
return (err);
}
@@ -2426,10 +2450,10 @@ zonecfg_set_hostid(zone_dochandle_t handle, const char *hostidp)
* Determines if the specified string is a valid hostid string. This function
* returns Z_OK if the string is a valid hostid string. It returns Z_INVAL if
* 'hostidp' is NULL, Z_TOO_BIG if 'hostidp' refers to a string buffer
- * containing a hex string with more than 8 digits, and Z_HOSTID_FUBAR if the
- * string has an invalid format.
+ * containing a hex string with more than 8 digits, and Z_INVALID_PROPERTY if
+ * the string has an invalid format.
*/
-int
+static int
zonecfg_valid_hostid(const char *hostidp)
{
char *currentp;
@@ -2441,10 +2465,10 @@ zonecfg_valid_hostid(const char *hostidp)
/* Empty strings and strings with whitespace are invalid. */
if (*hostidp == '\0')
- return (Z_HOSTID_FUBAR);
+ return (Z_INVALID_PROPERTY);
for (currentp = (char *)hostidp; *currentp != '\0'; ++currentp) {
if (isspace(*currentp))
- return (Z_HOSTID_FUBAR);
+ return (Z_INVALID_PROPERTY);
}
len = (size_t)(currentp - hostidp);
@@ -2463,10 +2487,49 @@ zonecfg_valid_hostid(const char *hostidp)
return (Z_TOO_BIG);
if (hostidval > UINT_MAX || hostidval == HW_INVALID_HOSTID ||
currentp != hostidp + len)
- return (Z_HOSTID_FUBAR);
+ return (Z_INVALID_PROPERTY);
return (Z_OK);
}
+/*
+ * Gets the zone hostid string stored in the specified zone configuration
+ * document. This function returns Z_OK on success. Z_BAD_PROPERTY is returned
+ * if the config file doesn't specify a hostid or if the hostid is blank.
+ *
+ * Note that buflen should be at least HW_HOSTID_LEN.
+ */
+int
+zonecfg_get_hostid(zone_dochandle_t handle, char *bufp, size_t buflen)
+{
+ int err;
+
+ if ((err = getrootattr(handle, DTD_ATTR_HOSTID, bufp, buflen)) != Z_OK)
+ return (err);
+ if (bufp[0] == '\0')
+ return (Z_BAD_PROPERTY);
+ return (zonecfg_valid_hostid(bufp));
+}
+
+/*
+ * Sets the hostid string in the specified zone config document to the given
+ * string value. If 'hostidp' is NULL, then the config document's hostid
+ * attribute is cleared. Non-NULL hostids are validated. This function returns
+ * Z_OK on success. Any other return value indicates failure.
+ */
+int
+zonecfg_set_hostid(zone_dochandle_t handle, const char *hostidp)
+{
+ int err;
+
+ /*
+ * A NULL hostid string is interpreted as a request to clear the
+ * hostid.
+ */
+ if (hostidp == NULL || (err = zonecfg_valid_hostid(hostidp)) == Z_OK)
+ return (setrootattr(handle, DTD_ATTR_HOSTID, hostidp));
+ return (err);
+}
+
int
zonecfg_lookup_dev(zone_dochandle_t handle, struct zone_devtab *tabptr)
{
@@ -3651,8 +3714,8 @@ zonecfg_strerror(int errnum)
"Could not create a temporary pool"));
case Z_POOL_BIND:
return (dgettext(TEXT_DOMAIN, "Could not bind zone to pool"));
- case Z_HOSTID_FUBAR:
- return (dgettext(TEXT_DOMAIN, "Specified hostid is invalid"));
+ case Z_INVALID_PROPERTY:
+ return (dgettext(TEXT_DOMAIN, "Specified property is invalid"));
case Z_SYSTEM:
return (strerror(errno));
default:
diff --git a/usr/src/lib/libzonecfg/common/mapfile-vers b/usr/src/lib/libzonecfg/common/mapfile-vers
index 2109a37cf1..c0e19ce706 100644
--- a/usr/src/lib/libzonecfg/common/mapfile-vers
+++ b/usr/src/lib/libzonecfg/common/mapfile-vers
@@ -125,6 +125,7 @@ SUNWprivate_1.1 {
zonecfg_getdevperment;
zonecfg_getdsent;
zonecfg_getfsent;
+ zonecfg_get_fs_allowed;
zonecfg_get_handle;
zonecfg_get_hostid;
zonecfg_getipdent;
@@ -205,6 +206,7 @@ SUNWprivate_1.1 {
zonecfg_setdevperment;
zonecfg_setdsent;
zonecfg_setfsent;
+ zonecfg_set_fs_allowed;
zonecfg_set_hostid;
zonecfg_setipdent;
zonecfg_set_iptype;
@@ -224,7 +226,6 @@ SUNWprivate_1.1 {
zonecfg_valid_auths;
zonecfg_valid_alias_limit;
zonecfg_valid_fs_type;
- zonecfg_valid_hostid;
zonecfg_valid_importance;
zonecfg_valid_memlimit;
zonecfg_valid_ncpus;
diff --git a/usr/src/lib/libzonecfg/dtd/zonecfg.dtd.1 b/usr/src/lib/libzonecfg/dtd/zonecfg.dtd.1
index d89e860268..89ffe59f2e 100644
--- a/usr/src/lib/libzonecfg/dtd/zonecfg.dtd.1
+++ b/usr/src/lib/libzonecfg/dtd/zonecfg.dtd.1
@@ -150,4 +150,5 @@
bootargs CDATA ""
brand CDATA ""
scheduling-class CDATA ""
+ fs-allowed CDATA ""
version NMTOKEN #FIXED '1'>