Skip to content

Commit d737f26

Browse files
Support group option on command line
1 parent 36ed45d commit d737f26

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

ChangeLog

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Reinstate strong umask before writing report
44
- Use pw_gid to set the group when changing gid
55
- Allow the use of account names for auid & uid in rules
6+
- Support group option on command line
67

78
0.8.3
89
- Add audit support for the linux-4.15 kernel

doc/fapolicyd.8

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ the internal queue of pending decisions is set by this number. It should be a po
3030
.TP
3131
.B \-\-user\ NN
3232
run as a particular user rather than root. This may either be numeric or a user name from the passwd database.
33+
.TP
34+
.B \-\-group\ NN
35+
run using a particular group rather than root. This may either be numeric or a user name from the passwd database.
3336
.SH SIGNALS
3437
.TP
3538
SIGTERM

src/fapolicyd.c

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* fapolicyd.c - Main file for the program
3-
* Copyright (c) 2016 Red Hat Inc., Durham, North Carolina.
3+
* Copyright (c) 2016,2018 Red Hat Inc., Durham, North Carolina.
44
* All Rights Reserved.
55
*
66
* This software may be freely redistributed and/or modified under the
@@ -34,6 +34,7 @@
3434
#include <stdio.h>
3535
#include <ctype.h>
3636
#include <pwd.h>
37+
#include <grp.h>
3738
#include <cap-ng.h>
3839
#include <sys/prctl.h>
3940
#include <linux/unistd.h> /* syscall numbers */
@@ -180,7 +181,7 @@ static void usage(void)
180181
{
181182
fprintf(stderr,
182183
"Usage: fapolicyd [--debug|--debug-deny] [--permissive] "
183-
"[--boost xxx]\n\t\t[--queue xxx] [--user xx] "
184+
"[--boost xxx]\n\t\t[--queue xxx] [--user xx] [--group xx]"
184185
"[--no-details]\n");
185186
exit(1);
186187
}
@@ -266,6 +267,30 @@ int main(int argc, char *argv[])
266267
gid = pw->pw_gid;
267268
endpwent();
268269
}
270+
} else if (strcmp(argv[i], "--group") == 0) {
271+
i++;
272+
if (i == argc || *argv[i] == '-') {
273+
msg(LOG_ERR, "group takes an argument");
274+
exit(1);
275+
}
276+
if (isdigit(*argv[i])) {
277+
errno = 0;
278+
gid = strtol(argv[i], NULL, 10);
279+
if (errno) {
280+
msg(LOG_ERR,
281+
"Error converting group value");
282+
exit(1);
283+
}
284+
} else {
285+
struct group *gr = getgrnam(argv[i]);
286+
if (gr == NULL) {
287+
msg(LOG_ERR, "group %s is unknown",
288+
argv[i]);
289+
exit(1);
290+
}
291+
gid = gr->gr_gid;
292+
endgrent();
293+
}
269294
} else if (strcmp(argv[i], "--no-details") == 0) {
270295
details = 0;
271296
} else {

0 commit comments

Comments
 (0)