Skip to content

Commit 692f0da

Browse files
rkojedzinszkybehlendorf
authored andcommitted
libzfs: make userquota_propname_decode threadsafe
Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Tino Reichardt <[email protected]> Signed-off-by: Richard Kojedzinszky <[email protected]> Closes #15793
1 parent 0cbf135 commit 692f0da

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/libzfs/libzfs_dataset.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
#include "libzfs_impl.h"
6868
#include "zfs_deleg.h"
6969

70+
static __thread struct passwd gpwd;
71+
static __thread struct group ggrp;
72+
static __thread char rpbuf[2048];
73+
7074
static int userquota_propname_decode(const char *propname, boolean_t zoned,
7175
zfs_userquota_prop_t *typep, char *domain, int domainlen, uint64_t *ridp);
7276

@@ -3195,11 +3199,15 @@ userquota_propname_decode(const char *propname, boolean_t zoned,
31953199

31963200
cp = strchr(propname, '@') + 1;
31973201

3198-
if (isuser && (pw = getpwnam(cp)) != NULL) {
3202+
if (isuser &&
3203+
getpwnam_r(cp, &gpwd, rpbuf, sizeof (rpbuf), &pw) == 0 &&
3204+
pw != NULL) {
31993205
if (zoned && getzoneid() == GLOBAL_ZONEID)
32003206
return (ENOENT);
32013207
*ridp = pw->pw_uid;
3202-
} else if (isgroup && (gr = getgrnam(cp)) != NULL) {
3208+
} else if (isgroup &&
3209+
getgrnam_r(cp, &ggrp, rpbuf, sizeof (rpbuf), &gr) == 0 &&
3210+
gr != NULL) {
32033211
if (zoned && getzoneid() == GLOBAL_ZONEID)
32043212
return (ENOENT);
32053213
*ridp = gr->gr_gid;

0 commit comments

Comments
 (0)