summaryrefslogtreecommitdiff
path: root/usr/src
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src')
-rw-r--r--usr/src/lib/libzfs/common/libzfs_dataset.c43
-rw-r--r--usr/src/lib/pyzfs/common/ioctl.c50
-rw-r--r--usr/src/uts/common/fs/zfs/zfs_fuid.c1
3 files changed, 55 insertions, 39 deletions
diff --git a/usr/src/lib/libzfs/common/libzfs_dataset.c b/usr/src/lib/libzfs/common/libzfs_dataset.c
index ac91226055..024c2910a2 100644
--- a/usr/src/lib/libzfs/common/libzfs_dataset.c
+++ b/usr/src/lib/libzfs/common/libzfs_dataset.c
@@ -47,6 +47,7 @@
#include <ucred.h>
#include <idmap.h>
#include <aclutils.h>
+#include <directory.h>
#include <sys/spa.h>
#include <sys/zap.h>
@@ -2074,6 +2075,7 @@ userquota_propname_decode(const char *propname, boolean_t zoned,
{
zfs_userquota_prop_t type;
char *cp, *end;
+ char *numericsid = NULL;
boolean_t isuser;
domain[0] = '\0';
@@ -2096,33 +2098,41 @@ userquota_propname_decode(const char *propname, boolean_t zoned,
if (strchr(cp, '@')) {
/*
* It's a SID name (eg "user@domain") that needs to be
- * turned into S-1-domainID-RID. There should be a
- * better way to do this, but for now just translate it
- * to the (possibly ephemeral) uid and then back to the
- * SID. This is like getsidname(noresolve=TRUE).
+ * turned into S-1-domainID-RID.
*/
- uid_t id;
- idmap_rid_t rid;
- char *mapdomain;
-
+ directory_error_t e;
if (zoned && getzoneid() == GLOBAL_ZONEID)
return (ENOENT);
- if (sid_to_id(cp, isuser, &id) != 0)
+ if (isuser) {
+ e = directory_sid_from_user_name(NULL,
+ cp, &numericsid);
+ } else {
+ e = directory_sid_from_group_name(NULL,
+ cp, &numericsid);
+ }
+ if (e != NULL) {
+ directory_error_free(e);
return (ENOENT);
- if (idmap_id_to_numeric_domain_rid(id, isuser,
- &mapdomain, &rid) != 0)
+ }
+ if (numericsid == NULL)
return (ENOENT);
- (void) strlcpy(domain, mapdomain, domainlen);
- *ridp = rid;
- } else if (strncmp(cp, "S-1-", 4) == 0) {
+ cp = numericsid;
+ /* will be further decoded below */
+ }
+
+ if (strncmp(cp, "S-1-", 4) == 0) {
/* It's a numeric SID (eg "S-1-234-567-89") */
- (void) strcpy(domain, cp);
+ (void) strlcpy(domain, cp, domainlen);
cp = strrchr(domain, '-');
*cp = '\0';
cp++;
errno = 0;
*ridp = strtoull(cp, &end, 10);
+ if (numericsid) {
+ free(numericsid);
+ numericsid = NULL;
+ }
if (errno != 0 || *end != '\0')
return (EINVAL);
} else if (!isdigit(*cp)) {
@@ -2158,13 +2168,14 @@ userquota_propname_decode(const char *propname, boolean_t zoned,
if (idmap_id_to_numeric_domain_rid(id, isuser,
&mapdomain, &rid) != 0)
return (ENOENT);
- (void) strcpy(domain, mapdomain);
+ (void) strlcpy(domain, mapdomain, domainlen);
*ridp = rid;
} else {
*ridp = id;
}
}
+ ASSERT3P(numericsid, ==, NULL);
return (0);
}
diff --git a/usr/src/lib/pyzfs/common/ioctl.c b/usr/src/lib/pyzfs/common/ioctl.c
index 7a10a4e25e..ae3fa74dc2 100644
--- a/usr/src/lib/pyzfs/common/ioctl.c
+++ b/usr/src/lib/pyzfs/common/ioctl.c
@@ -33,6 +33,7 @@
#include <zone.h>
#include <libintl.h>
#include <libzfs.h>
+#include <directory.h>
#include "zfs_prop.h"
static PyObject *ZFSError;
@@ -456,43 +457,46 @@ py_sid_to_id(PyObject *self, PyObject *args)
/*
* Translate the sid string ("S-1-...") to the user@domain name, if
- * possible. There should be a better way to do this, but for now we
- * just translate to the (possibly ephemeral) uid and then back again.
+ * possible.
*/
static PyObject *
py_sid_to_name(PyObject *self, PyObject *args)
{
- char *sid;
- int err, isuser;
- uid_t id;
- char *name, *domain;
- char buf[256];
+ int isuser;
+ char *name, *sid;
+ directory_error_t e;
+ uint64_t classes;
+ PyObject *ret;
if (!PyArg_ParseTuple(args, "si", &sid, &isuser))
return (NULL);
-
- err = sid_to_id(sid, isuser, &id);
- if (err) {
+ e = directory_name_from_sid(NULL, sid, &name, &classes);
+ if (e != NULL) {
+ directory_error_free(e);
PyErr_SetString(PyExc_KeyError, sid);
return (NULL);
}
-
- if (isuser) {
- err = idmap_getwinnamebyuid(id,
- IDMAP_REQ_FLG_USE_CACHE, &name, &domain);
- } else {
- err = idmap_getwinnamebygid(id,
- IDMAP_REQ_FLG_USE_CACHE, &name, &domain);
- }
- if (err != IDMAP_SUCCESS) {
+ if (name == NULL) {
PyErr_SetString(PyExc_KeyError, sid);
return (NULL);
}
- (void) snprintf(buf, sizeof (buf), "%s@%s", name, domain);
- free(name);
- free(domain);
+ if (isuser) {
+ if (!(classes & DIRECTORY_CLASS_USER)) {
+ free(name);
+ PyErr_SetString(PyExc_KeyError, sid);
+ return (NULL);
+ }
+ } else {
+ if (!(classes & DIRECTORY_CLASS_GROUP)) {
+ free(name);
+ PyErr_SetString(PyExc_KeyError, sid);
+ return (NULL);
+ }
+ }
- return (Py_BuildValue("s", buf));
+ ret = PyString_FromString(name);
+ free(name);
+ return (ret);
}
static PyObject *
diff --git a/usr/src/uts/common/fs/zfs/zfs_fuid.c b/usr/src/uts/common/fs/zfs/zfs_fuid.c
index 8e481dffb3..e704b1ca9d 100644
--- a/usr/src/uts/common/fs/zfs/zfs_fuid.c
+++ b/usr/src/uts/common/fs/zfs/zfs_fuid.c
@@ -353,6 +353,7 @@ retry:
rw_exit(&zfsvfs->z_fuid_lock);
return (retidx);
} else {
+ rw_exit(&zfsvfs->z_fuid_lock);
return (-1);
}
}