summaryrefslogtreecommitdiff
path: root/src/tc-switchuser.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2025-11-22 14:50:10 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2025-11-22 14:50:10 +0100
commit2e314136ed58b6860c667e379bef22190fe84aa2 (patch)
tree21f897804c03c3419a0c015ace3bf9fb9c1b8e52 /src/tc-switchuser.c
parent50d223b12c1319b4b9c4a5b8e34866c46996cb36 (diff)
New upstream version 5.2upstream/5.2upstream
Diffstat (limited to 'src/tc-switchuser.c')
-rw-r--r--src/tc-switchuser.c19
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;
}