Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit d81b3e0

Browse files
committed
support user not in /etc/passwd
Signed-off-by: Gao feng <omarapazanadi@gmail.com>
1 parent 41262e6 commit d81b3e0

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/exec.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,12 @@ static int hyper_setup_exec_user(struct hyper_exec *exec)
210210
struct passwd *pwd = hyper_getpwnam(user);
211211
if (pwd == NULL) {
212212
perror("can't find the user");
213-
return -1;
213+
unsigned long id;
214+
if (!hyper_name_to_id(user, &id))
215+
return -1;
216+
uid = id;
217+
gid = 0;
218+
goto setup;
214219
}
215220
uid = pwd->pw_uid;
216221
gid = pwd->pw_gid;
@@ -282,6 +287,7 @@ static int hyper_setup_exec_user(struct hyper_exec *exec)
282287
ngroups++;
283288
}
284289

290+
setup:
285291
// setup the owner of tty
286292
if (exec->tty) {
287293
char ptmx[512];
@@ -293,7 +299,7 @@ static int hyper_setup_exec_user(struct hyper_exec *exec)
293299
}
294300

295301
// apply
296-
if (setgroups(ngroups, groups) < 0) {
302+
if (groups && setgroups(ngroups, groups) < 0) {
297303
perror("setgroups() fails");
298304
goto fail;
299305
}
@@ -306,9 +312,7 @@ static int hyper_setup_exec_user(struct hyper_exec *exec)
306312
goto fail;
307313
}
308314
free(groups);
309-
310315
return 0;
311-
312316
fail:
313317
free(groups);
314318
return -1;

0 commit comments

Comments
 (0)