diff options
| author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2025-11-24 06:50:20 +0100 |
|---|---|---|
| committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2025-11-24 06:50:20 +0100 |
| commit | d2c60504265dbd03a31c357724618bac70ac4ffe (patch) | |
| tree | b630969b8f5ae3690f764738b249668fcef843df /src/tc-switchuser.c | |
| parent | afd606e6806b6c34b816893f6d04789d86a83fbc (diff) | |
| parent | a384d3bf0397c8237f3a78e690db6d9141e6345c (diff) | |
Merge branch 'release/debian/5.2-1_exp1'HEADdebian/5.2-1_exp1master
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; } |
