]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc_unshare: Replace getpw*_r by getpw*
authorStéphane Graber <stgraber@ubuntu.com>
Thu, 3 Jan 2013 16:51:52 +0000 (11:51 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Wed, 9 Jan 2013 15:22:54 +0000 (10:22 -0500)
Bionic and maybe some other libc implementations lack the _r nss functions.
This replaces our current getpwnam_r and getpwuid_r calls by getpwnam and
getpwuid.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/lxc/lxc_unshare.c

index 3a848b23d27443312fe21e92aae8e53540989f71..df91456d8369d9119a5d666111b5ee0a778f5bc3 100644 (file)
@@ -54,12 +54,9 @@ void usage(char *cmd)
 
 static uid_t lookup_user(const char *optarg)
 {
-       int bufflen = sysconf(_SC_GETPW_R_SIZE_MAX);
-       char buff[bufflen];
        char name[sysconf(_SC_LOGIN_NAME_MAX)];
        uid_t uid = -1;
-       struct passwd pwent;
-       struct passwd *pent;
+       struct passwd *pwent = NULL;
 
        if (!optarg || (optarg[0] == '\0'))
                return uid;
@@ -69,13 +66,15 @@ static uid_t lookup_user(const char *optarg)
                if (sscanf(optarg, "%s", name) < 1)
                        return uid;
 
-               if (getpwnam_r(name, &pwent, buff, bufflen, &pent) || !pent) {
+               pwent = getpwnam(name);
+               if (!pwent) {
                        ERROR("invalid username %s", name);
                        return uid;
                }
-               uid = pent->pw_uid;
+               uid = pwent->pw_uid;
        } else {
-               if (getpwuid_r(uid, &pwent, buff, bufflen, &pent) || !pent) {
+               pwent = getpwuid(uid);
+               if (!pwent) {
                        ERROR("invalid uid %d", uid);
                        uid = -1;
                        return uid;