Fix addgroup so it actually works

-Erik
This commit is contained in:
Eric Andersen 2003-01-09 18:53:53 +00:00
parent e931909d2d
commit f05fd444e8

View File

@ -132,23 +132,33 @@ static int addgroup(const char *filename, char *group, gid_t gid, const char *us
* ________________________________________________________________________ */ * ________________________________________________________________________ */
int addgroup_main(int argc, char **argv) int addgroup_main(int argc, char **argv)
{ {
int opt;
char *group; char *group;
char *user; char *user;
gid_t gid = 0; gid_t gid = 0;
if (argc < 2) { /* get remaining args */
while ((opt = getopt (argc, argv, "g:")) != -1) {
switch (opt) {
case 'g':
gid = strtol(optarg, NULL, 10);
break;
default:
show_usage(); show_usage();
break;
}
} }
if (strncmp(argv[1], "-g", 2) == 0) { if (optind < argc) {
gid = strtol(argv[2], NULL, 10); group = argv[optind];
group = argv[2]; optind++;
} else { } else {
show_usage(); show_usage();
} }
if (argc == 4) { if (optind < argc) {
user = argv[3]; user = argv[optind];
optind++;
} else { } else {
user = ""; user = "";
} }
@ -162,4 +172,4 @@ int addgroup_main(int argc, char **argv)
return addgroup(group_file, group, gid, user); return addgroup(group_file, group, gid, user);
} }
/* $Id: addgroup.c,v 1.8 2002/12/13 22:02:12 timr Exp $ */ /* $Id: addgroup.c,v 1.9 2003/01/09 18:53:53 andersen Exp $ */