blob: f9aecb75571cd1746e2a0c336e04670c6a4b0c57 [file] [log] [blame]
Lorenz Brune306d782021-09-01 13:01:06 +02001--- a/main.c
2+++ b/main.c
3@@ -439,6 +439,7 @@ int main
4 int scfilter_level = 0, lock_memory = 0, sched_priority = 0;
5 int clock_control = 1, system_log = 1, log_severity = LOGS_INFO;
6 int user_check = 1, config_args = 0, print_config = 0;
7+ int uid = -1, gid = -1;
8
9 do_platform_checks();
10
11@@ -458,7 +459,7 @@ int main
12 optind = 1;
13
14 /* Parse short command-line options */
15- while ((opt = getopt(argc, argv, "46df:F:hl:L:mnpP:qQrRst:u:Uvx")) != -1) {
16+ while ((opt = getopt(argc, argv, "46df:F:g:hi:l:L:mnpP:qQrRst:u:Uvx")) != -1) {
17 switch (opt) {
18 case '4':
19 case '6':
20@@ -475,6 +476,12 @@ int main
21 case 'F':
22 scfilter_level = parse_int_arg(optarg);
23 break;
24+ case 'g':
25+ gid = parse_int_arg(optarg);
26+ break;
27+ case 'i': // u and U were alredy used, so i for id
28+ uid = parse_int_arg(optarg);
29+ break;
30 case 'l':
31 log_file = optarg;
32 break;
33@@ -583,9 +590,13 @@ int main
34 if (!user)
35 user = CNF_GetUser();
36
37- pw = getpwnam(user);
38- if (!pw)
39- LOG_FATAL("Could not get user/group ID of %s", user);
40+ if (uid != -1 && gid != -1) {
41+ pw = &(struct passwd) { .pw_uid = uid, .pw_gid = gid };
42+ } else {
43+ pw = getpwnam(user);
44+ if (!pw)
45+ LOG_FATAL("Could not get user/group ID of %s", user);
46+ }
47
48 /* Create directories for sockets, log files, and dump files */
49 CNF_CreateDirs(pw->pw_uid, pw->pw_gid);
50--
512.25.1
52