shadow/src/getsubids.c
Iker Pedrosa 3b6ccf642c getsubids: system binary for user's sub*ids
Rename list_subid_ranges to getsubids to provide a system binary to
check the sub*ids of a user. The intention is to provide this binary
with any distribution that includes the subid feature, so that system
administrators can check the subid ranges of a given user.

Finally, add a man page to explain the behaviour of getsubids.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1980780

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2021-11-17 16:35:50 +01:00

47 lines
987 B
C

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "subid.h"
#include "prototypes.h"
const char *Prog;
FILE *shadow_logfd = NULL;
void usage(void)
{
fprintf(stderr, "Usage: %s [-g] user\n", Prog);
fprintf(stderr, " list subuid ranges for user\n");
fprintf(stderr, " pass -g to list subgid ranges\n");
exit(EXIT_FAILURE);
}
int main(int argc, char *argv[])
{
int i, count=0;
struct subid_range *ranges;
const char *owner;
Prog = Basename (argv[0]);
shadow_logfd = stderr;
if (argc < 2)
usage();
owner = argv[1];
if (argc == 3 && strcmp(argv[1], "-g") == 0) {
owner = argv[2];
count = get_subgid_ranges(owner, &ranges);
} else if (argc == 2 && strcmp(argv[1], "-h") == 0) {
usage();
} else {
count = get_subuid_ranges(owner, &ranges);
}
if (!ranges) {
fprintf(stderr, "Error fetching ranges\n");
exit(1);
}
for (i = 0; i < count; i++) {
printf("%d: %s %lu %lu\n", i, owner,
ranges[i].start, ranges[i].count);
}
return 0;
}