diff options
| author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2025-11-22 14:50:27 +0100 |
|---|---|---|
| committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2025-11-22 14:50:27 +0100 |
| commit | 811c5336e00e3357afeb0909a4d182d0c3bb6ad4 (patch) | |
| tree | fe10b6cb9309bef50e7458c5c203905b43529d24 /src/tc-switchuser.c | |
| parent | 62ac2dd91f81d8584d5ab585639dfe29eefc3e20 (diff) | |
| parent | 80101a458f40cc35f39e890baba1a891a83009e7 (diff) | |
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'src/tc-switchuser.c')
| -rw-r--r-- | src/tc-switchuser.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/tc-switchuser.c b/src/tc-switchuser.c index e5d2c25..379dfff 100644 --- a/src/tc-switchuser.c +++ b/src/tc-switchuser.c @@ -10,19 +10,28 @@ #include <libHX/defs.h> #include <libHX/option.h> #include <libHX/proc.h> +#include "internal.h" #if defined(HAVE_INITGROUPS) -static char *user_name, *group_name; static const struct HXoption options_table[] = { - {.sh = 'u', .type = HXTYPE_STRING, .ptr = &user_name}, - {.sh = 'g', .type = HXTYPE_STRING, .ptr= &group_name}, + {.sh = 'u', .type = HXTYPE_STRING}, + {.sh = 'g', .type = HXTYPE_STRING}, HXOPT_TABLEEND, }; static int runner(int argc, char **argv) { - if (HX_getopt(options_table, &argc, &argv, HXOPT_USAGEONERR) != HXOPT_ERR_SUCCESS) + char *user_name = nullptr, *group_name = nullptr; + struct HXopt6_result result; + + if (HX_getopt6(options_table, argc, argv, &result, + HXOPT_USAGEONERR | HXOPT_ITER_OPTS) != HXOPT_ERR_SUCCESS) return EXIT_FAILURE; + for (int i = 0; i < result.nopts; ++i) { + if (result.desc[i]->sh == 'u') user_name = result.oarg[i]; + if (result.desc[i]->sh == 'g') group_name = result.oarg[i]; + } + const char *user = user_name != NULL ? user_name : "-"; const char *group = group_name != NULL ? group_name : "-"; switch (HXproc_switch_user(user_name, group_name)) { @@ -63,7 +72,7 @@ static int runner(int argc, char **argv) break; } } - HX_zvecfree(argv); + HX_getopt6_clean(&result); return EXIT_SUCCESS; } |
