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

Commit df9d326

Browse files
committed
Handle additional groups that may not exist in the container.
This patch adds numeric gids in the additional groups list without checking if they exist. This is behaviour that docker expects. Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
1 parent bd9aac7 commit df9d326

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ AM_PROG_CC_C_O
1414
# Checks for libraries.
1515

1616
# Checks for header files.
17-
AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h stddef.h stdint.h stdlib.h string.h sys/mount.h sys/socket.h unistd.h],
17+
AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h stddef.h stdint.h stdlib.h string.h sys/mount.h sys/socket.h unistd.h stdbool.h],
1818
[headers_found=yes],
1919
[headers_found=no])
2020

src/exec.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,18 @@ static int hyper_setup_exec_user(struct hyper_exec *exec)
267267
goto fail;
268268
groups = reallocgroups;
269269
for (i = 0; i < exec->nr_additional_groups; i++) {
270+
unsigned long id;
270271
fprintf(stdout, "try to find the group: %s\n", exec->additional_groups[i]);
271-
struct group *gr = hyper_getgrnam(exec->additional_groups[i]);
272-
if (gr == NULL) {
273-
perror("can't find the group");
274-
goto fail;
272+
if (hyper_name_to_id(exec->additional_groups[i], &id)) {
273+
groups[ngroups] = id;
274+
} else {
275+
struct group *gr = hyper_getgrnam(exec->additional_groups[i]);
276+
if (gr == NULL) {
277+
perror("can't find the group");
278+
goto fail;
279+
}
280+
groups[ngroups] = gr->gr_gid;
275281
}
276-
groups[ngroups] = gr->gr_gid;
277282
ngroups++;
278283
}
279284

src/util.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ static unsigned long id_or_max(const char *name)
132132
return id;
133133
}
134134

135+
// Checks if the name provided is a numeric value and does the conversion.
136+
bool hyper_name_to_id(const char *name, unsigned long *val)
137+
{
138+
char *ptr;
139+
errno = 0;
140+
long id = strtol(name, &ptr, 10);
141+
if (name == ptr || id < 0 || (errno != 0 && id == 0) || *ptr != '\0')
142+
return false;
143+
*val = id;
144+
return true;
145+
}
146+
135147
// the same as getpwnam(), but it only parses /etc/passwd and allows name to be id string
136148
struct passwd *hyper_getpwnam(const char *name)
137149
{

src/util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <stdio.h>
55
#include <grp.h>
66
#include <pwd.h>
7+
#include <stdbool.h>
78
#include "../config.h"
89

910
struct hyper_pod;
@@ -36,6 +37,7 @@ int hyper_setfd_nonblock(int fd);
3637
int hyper_socketpair(int domain, int type, int protocol, int sv[2]);
3738
void hyper_shutdown();
3839
int hyper_insmod(char *module);
40+
bool hyper_name_to_id(const char *name, unsigned long *val);
3941
struct passwd *hyper_getpwnam(const char *name);
4042
struct group *hyper_getgrnam(const char *name);
4143
int hyper_getgrouplist(const char *user, gid_t group, gid_t *groups, int *ngroups);

0 commit comments

Comments
 (0)