mirror of
https://github.com/sheumann/hush.git
synced 2025-01-03 00:31:16 +00:00
Converted option parsing to getopt() and made some minor formatting changes.
This commit is contained in:
parent
27a804246a
commit
aa4f108338
@ -33,28 +33,30 @@ extern int id_main(int argc, char **argv)
|
|||||||
int no_user = 0, no_group = 0, print_real = 0;
|
int no_user = 0, no_group = 0, print_real = 0;
|
||||||
char *cp, *user, *group;
|
char *cp, *user, *group;
|
||||||
unsigned long gid;
|
unsigned long gid;
|
||||||
|
int opt;
|
||||||
|
|
||||||
cp = user = group = NULL;
|
cp = user = group = NULL;
|
||||||
|
|
||||||
argc--; argv++;
|
while ((opt = getopt(argc, argv, "ugr")) > 0) {
|
||||||
|
switch (opt) {
|
||||||
while (argc > 0) {
|
case 'u':
|
||||||
cp = *argv;
|
no_group++;
|
||||||
if (*cp == '-') {
|
break;
|
||||||
switch (*++cp) {
|
case 'g':
|
||||||
case 'u': no_group = 1; break;
|
no_user++;
|
||||||
case 'g': no_user = 1; break;
|
break;
|
||||||
case 'r': print_real = 1; break;
|
case 'r':
|
||||||
default: usage(id_usage);
|
print_real++;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
usage(id_usage);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
user = cp;
|
|
||||||
}
|
|
||||||
argc--; argv++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (no_user && no_group) usage(id_usage);
|
if (no_user && no_group) usage(id_usage);
|
||||||
|
|
||||||
|
user = argv[optind];
|
||||||
|
|
||||||
if (user == NULL) {
|
if (user == NULL) {
|
||||||
user = xmalloc(9);
|
user = xmalloc(9);
|
||||||
group = xmalloc(9);
|
group = xmalloc(9);
|
||||||
@ -71,13 +73,14 @@ extern int id_main(int argc, char **argv)
|
|||||||
my_getgrgid(group, gid);
|
my_getgrgid(group, gid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (no_group) printf("%lu\n", my_getpwnam(user));
|
if (no_group)
|
||||||
else if (no_user) printf("%lu\n", my_getgrnam(group));
|
printf("%lu\n", my_getpwnam(user));
|
||||||
|
else if (no_user)
|
||||||
|
printf("%lu\n", my_getgrnam(group));
|
||||||
else
|
else
|
||||||
printf("uid=%lu(%s) gid=%lu(%s)\n",
|
printf("uid=%lu(%s) gid=%lu(%s)\n",
|
||||||
my_getpwnam(user), user, my_getgrnam(group), group);
|
my_getpwnam(user), user, my_getgrnam(group), group);
|
||||||
|
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
37
id.c
37
id.c
@ -33,28 +33,30 @@ extern int id_main(int argc, char **argv)
|
|||||||
int no_user = 0, no_group = 0, print_real = 0;
|
int no_user = 0, no_group = 0, print_real = 0;
|
||||||
char *cp, *user, *group;
|
char *cp, *user, *group;
|
||||||
unsigned long gid;
|
unsigned long gid;
|
||||||
|
int opt;
|
||||||
|
|
||||||
cp = user = group = NULL;
|
cp = user = group = NULL;
|
||||||
|
|
||||||
argc--; argv++;
|
while ((opt = getopt(argc, argv, "ugr")) > 0) {
|
||||||
|
switch (opt) {
|
||||||
while (argc > 0) {
|
case 'u':
|
||||||
cp = *argv;
|
no_group++;
|
||||||
if (*cp == '-') {
|
break;
|
||||||
switch (*++cp) {
|
case 'g':
|
||||||
case 'u': no_group = 1; break;
|
no_user++;
|
||||||
case 'g': no_user = 1; break;
|
break;
|
||||||
case 'r': print_real = 1; break;
|
case 'r':
|
||||||
default: usage(id_usage);
|
print_real++;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
usage(id_usage);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
user = cp;
|
|
||||||
}
|
|
||||||
argc--; argv++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (no_user && no_group) usage(id_usage);
|
if (no_user && no_group) usage(id_usage);
|
||||||
|
|
||||||
|
user = argv[optind];
|
||||||
|
|
||||||
if (user == NULL) {
|
if (user == NULL) {
|
||||||
user = xmalloc(9);
|
user = xmalloc(9);
|
||||||
group = xmalloc(9);
|
group = xmalloc(9);
|
||||||
@ -71,13 +73,14 @@ extern int id_main(int argc, char **argv)
|
|||||||
my_getgrgid(group, gid);
|
my_getgrgid(group, gid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (no_group) printf("%lu\n", my_getpwnam(user));
|
if (no_group)
|
||||||
else if (no_user) printf("%lu\n", my_getgrnam(group));
|
printf("%lu\n", my_getpwnam(user));
|
||||||
|
else if (no_user)
|
||||||
|
printf("%lu\n", my_getgrnam(group));
|
||||||
else
|
else
|
||||||
printf("uid=%lu(%s) gid=%lu(%s)\n",
|
printf("uid=%lu(%s) gid=%lu(%s)\n",
|
||||||
my_getpwnam(user), user, my_getgrnam(group), group);
|
my_getpwnam(user), user, my_getgrnam(group), group);
|
||||||
|
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user