1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-01 08:27:59 +00:00

libzfs: make userquota_propname_decode threadsafe

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Tino Reichardt <milky-zfs@mcmilk.de>
Signed-off-by: Richard Kojedzinszky <richard@kojedz.in>
Closes #15793
This commit is contained in:
Richard Kojedzinszky 2024-01-17 20:48:02 +01:00 committed by Brian Behlendorf
parent 0cbf135293
commit 692f0daba3

View File

@ -67,6 +67,10 @@
#include "libzfs_impl.h" #include "libzfs_impl.h"
#include "zfs_deleg.h" #include "zfs_deleg.h"
static __thread struct passwd gpwd;
static __thread struct group ggrp;
static __thread char rpbuf[2048];
static int userquota_propname_decode(const char *propname, boolean_t zoned, static int userquota_propname_decode(const char *propname, boolean_t zoned,
zfs_userquota_prop_t *typep, char *domain, int domainlen, uint64_t *ridp); zfs_userquota_prop_t *typep, char *domain, int domainlen, uint64_t *ridp);
@ -3195,11 +3199,15 @@ userquota_propname_decode(const char *propname, boolean_t zoned,
cp = strchr(propname, '@') + 1; cp = strchr(propname, '@') + 1;
if (isuser && (pw = getpwnam(cp)) != NULL) { if (isuser &&
getpwnam_r(cp, &gpwd, rpbuf, sizeof (rpbuf), &pw) == 0 &&
pw != NULL) {
if (zoned && getzoneid() == GLOBAL_ZONEID) if (zoned && getzoneid() == GLOBAL_ZONEID)
return (ENOENT); return (ENOENT);
*ridp = pw->pw_uid; *ridp = pw->pw_uid;
} else if (isgroup && (gr = getgrnam(cp)) != NULL) { } else if (isgroup &&
getgrnam_r(cp, &ggrp, rpbuf, sizeof (rpbuf), &gr) == 0 &&
gr != NULL) {
if (zoned && getzoneid() == GLOBAL_ZONEID) if (zoned && getzoneid() == GLOBAL_ZONEID)
return (ENOENT); return (ENOENT);
*ridp = gr->gr_gid; *ridp = gr->gr_gid;