mirror of
https://github.com/troglobit/finit.git
synced 2026-11-23 20:11:44 +00:00
service: lift the limit of four supplementary groups
A service listing more than four supplementary groups, in extra-groups
or as @user:group,sup1,sup2,..., got only the first four:
too many supplementary groups, max 4
The names were stored in a fixed array of four. It was also only
reset when the new configuration listed groups, so groups dropped from
a service lingered until reboot.
Store the list as one string, split when the service starts, and set
it on every (re)registration. A list longer than 511 characters drops
the name it cuts off, which may otherwise match another group.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
5 files changed
+76
-22
No files matched your search
+18
-19
@@ -780,20 +780,22 @@ static pid_t service_fork(svc_t *svc)
|
||||
{
|
||||
gid_t supgids[NGROUPS_MAX];
|
||||
int ngroups = NGROUPS_MAX;
|
||||
int i, j, n = 0;
|
||||
char *sup, *ptr;
|
||||
int j, n = 0;
|
||||
|
||||
/* Get user's supplementary groups from /etc/group */
|
||||
if (getgrouplist(svc->username, gid, supgids, &ngroups) >= 0)
|
||||
n = ngroups;
|
||||
|
||||
/* Add explicitly configured supplementary groups */
|
||||
for (i = 0; i < svc->num_supgroups && n < NGROUPS_MAX; i++) {
|
||||
int g = getgroup(svc->supgroups[i]);
|
||||
for (sup = strtok_r(strdupa(svc->supgroups), ",", &ptr);
|
||||
sup && n < NGROUPS_MAX; sup = strtok_r(NULL, ",", &ptr)) {
|
||||
int g = getgroup(sup);
|
||||
int found = 0;
|
||||
|
||||
if (g < 0) {
|
||||
warn("%s: unknown supplementary group '%s'",
|
||||
svc_ident(svc, NULL, 0), svc->supgroups[i]);
|
||||
warnx("%s: unknown supplementary group '%s'",
|
||||
svc_ident(svc, NULL, 0), sup);
|
||||
continue;
|
||||
}
|
||||
/* Skip if already in list from /etc/group */
|
||||
@@ -2490,10 +2492,12 @@ svc_t *service_register_desc(int type, char *cfg, const char *desc,
|
||||
svc_unblock(svc);
|
||||
}
|
||||
|
||||
svc->supgroups[0] = 0;
|
||||
if (username) {
|
||||
char *ptr = strchr(username, ':');
|
||||
|
||||
if (ptr) {
|
||||
size_t len = sizeof(svc->supgroups);
|
||||
char *sup;
|
||||
|
||||
*ptr++ = 0;
|
||||
@@ -2501,20 +2505,15 @@ svc_t *service_register_desc(int type, char *cfg, const char *desc,
|
||||
sup = strchr(ptr, ',');
|
||||
if (sup) {
|
||||
*sup++ = 0;
|
||||
svc->num_supgroups = 0;
|
||||
while (sup) {
|
||||
char *next = strchr(sup, ',');
|
||||
if (next)
|
||||
*next++ = 0;
|
||||
if (svc->num_supgroups >= MAX_NUM_SUPGROUPS) {
|
||||
warn("%s: too many supplementary groups, max %d",
|
||||
svc->cmd, MAX_NUM_SUPGROUPS);
|
||||
break;
|
||||
}
|
||||
strlcpy(svc->supgroups[svc->num_supgroups], sup,
|
||||
sizeof(svc->supgroups[0]));
|
||||
svc->num_supgroups++;
|
||||
sup = next;
|
||||
if (strlcpy(svc->supgroups, sup, len) >= len) {
|
||||
/* Drop the cut-off name, it may match another group */
|
||||
sup = strrchr(svc->supgroups, ',');
|
||||
if (sup)
|
||||
*sup = 0;
|
||||
else
|
||||
svc->supgroups[0] = 0;
|
||||
warnx("%s: supplementary group list too long, max %zu characters",
|
||||
svc->cmd, len - 1);
|
||||
}
|
||||
}
|
||||
strlcpy(svc->group, ptr, sizeof(svc->group));
|
||||
|
||||
@@ -101,7 +101,7 @@ typedef enum {
|
||||
#define MAX_STR_LEN 64
|
||||
#define MAX_COND_LEN (MAX_ARG_LEN * 3)
|
||||
#define MAX_USER_LEN MAX_ARG_LEN
|
||||
#define MAX_NUM_SUPGROUPS 4
|
||||
#define MAX_SUPGROUPS_LEN (MAX_CMD_LEN * 2)
|
||||
#define MAX_NUM_PROVIDES 4
|
||||
#define MAX_NUM_FDS 64 /* Max number of I/O plugins */
|
||||
#define MAX_NUM_SVC_ARGS 64
|
||||
@@ -200,8 +200,7 @@ typedef struct svc {
|
||||
/* Identity */
|
||||
char username[MAX_USER_LEN];
|
||||
char group[MAX_USER_LEN];
|
||||
char supgroups[MAX_NUM_SUPGROUPS][MAX_USER_LEN];
|
||||
int num_supgroups;
|
||||
char supgroups[MAX_SUPGROUPS_LEN]; /* sup1,sup2,... */
|
||||
char capabilities[MAX_CMD_LEN];
|
||||
char pam[MAX_ARG_LEN]; /* /etc/pam.d/NAME, block format only */
|
||||
|
||||
|
||||
Reference in new issue
Block a user