Skip to content

Commit

Permalink
libzfs: make userquota_propname_decode threadsafe
Browse files Browse the repository at this point in the history
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Tino Reichardt <[email protected]>
Signed-off-by: Richard Kojedzinszky <[email protected]>
Closes openzfs#15793
  • Loading branch information
rkojedzinszky authored and lundman committed Mar 13, 2024
1 parent da9600f commit 153264b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/libzfs/libzfs_dataset.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
#include "libzfs_impl.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,
zfs_userquota_prop_t *typep, char *domain, int domainlen, uint64_t *ridp);

Expand Down Expand Up @@ -3208,11 +3212,15 @@ userquota_propname_decode(const char *propname, boolean_t zoned,

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)
return (ENOENT);
*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)
return (ENOENT);
*ridp = gr->gr_gid;
Expand Down

0 comments on commit 153264b

Please sign in to comment.