From 2f54ff75f32fe3a202ca4219b9f071cc48adbf7d Mon Sep 17 00:00:00 2001 From: "Nicholas J. Kain" Date: Sun, 30 Mar 2014 22:18:04 -0400 Subject: [PATCH] Use nk_uidgidbyname(). --- ndhc/ndhc.c | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/ndhc/ndhc.c b/ndhc/ndhc.c index 53fab0c..74e9b93 100644 --- a/ndhc/ndhc.c +++ b/ndhc/ndhc.c @@ -470,36 +470,12 @@ int main(int argc, char **argv) case 'r': cs.clientAddr = inet_addr(optarg); break; - case 'u': { - struct passwd *pwd; - char *p; - uid_t uidt = strtol(optarg, &p, 10); - if (*p != '\0') - pwd = getpwnam(optarg); - else - pwd = getpwuid(uidt); - if (pwd) { - ndhc_uid = (int)pwd->pw_uid; - ndhc_gid = (int)pwd->pw_gid; - } else - suicide("Bad username provided to '-u'."); + case 'u': + ndhc_uid = nk_uidgidbyname(optarg, &ndhc_gid); break; - } - case 'U': { - struct passwd *pwd; - char *p; - uid_t uidt = strtol(optarg, &p, 10); - if (*p != '\0') - pwd = getpwnam(optarg); - else - pwd = getpwuid(uidt); - if (pwd) { - ifch_uid = (int)pwd->pw_uid; - ifch_gid = (int)pwd->pw_gid; - } else - suicide("Bad username provided to '-U'."); + case 'U': + ifch_uid = nk_uidgidbyname(optarg, &ifch_gid); break; - } case 'C': copy_cmdarg(chroot_dir, optarg, sizeof chroot_dir, "chroot"); break;