diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 14:54:37 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 14:54:37 +0000 |
commit | 97c26c1924b076ef23ebe4381558e8aa025712b2 (patch) | |
tree | 109724175f07436696f51b14b5abbd3f4d704d6d /src/new_subid_range.c | |
parent | Initial commit. (diff) | |
download | shadow-e5df02f9b4d325b0ac1812e1456ba966566da242.tar.xz shadow-e5df02f9b4d325b0ac1812e1456ba966566da242.zip |
Adding upstream version 1:4.13+dfsg1.upstream/1%4.13+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/new_subid_range.c')
-rw-r--r-- | src/new_subid_range.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/new_subid_range.c b/src/new_subid_range.c new file mode 100644 index 0000000..523d480 --- /dev/null +++ b/src/new_subid_range.c @@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#include <stdio.h> +#include <unistd.h> +#include "subid.h" +#include "stdlib.h" +#include "prototypes.h" +#include "shadowlog.h" + +/* Test program for the subid creation routine */ + +const char *Prog; + +static void usage(void) +{ + fprintf(stderr, "Usage: %s [-g] [-n] user count\n", Prog); + fprintf(stderr, " Find a subuid (or with -g, subgid) range for user\n"); + fprintf(stderr, " If -n is given, a new range will be created even if one exists\n"); + fprintf(stderr, " count defaults to 65536\n"); + exit(EXIT_FAILURE); +} + +int main(int argc, char *argv[]) +{ + int c; + struct subordinate_range range; + bool makenew = false; // reuse existing by default + bool group = false; // get subuids by default + bool ok; + + Prog = Basename (argv[0]); + log_set_progname(Prog); + log_set_logfd(stderr); + while ((c = getopt(argc, argv, "gn")) != EOF) { + switch(c) { + case 'n': makenew = true; break; + case 'g': group = true; break; + default: usage(); + } + } + argv = &argv[optind]; + argc = argc - optind; + if (argc == 0) + usage(); + range.owner = argv[0]; + range.start = 0; + range.count = 65536; + if (argc > 1) + range.count = atoi(argv[1]); + if (group) + ok = subid_grant_gid_range(&range, !makenew); + else + ok = subid_grant_uid_range(&range, !makenew); + + if (!ok) { + fprintf(stderr, "Failed creating new id range\n"); + exit(EXIT_FAILURE); + } + printf("Subuid range %lu:%lu\n", range.start, range.count); + + return 0; +} |