Teach addgroup to add user names to groups
This commit is contained in:
parent
b2bfd34a7b
commit
b8dff0c2a2
@ -83,7 +83,7 @@ static int group_study(const char *filename, struct group *g)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* append a new user to the passwd file */
|
/* append a new user to the passwd file */
|
||||||
static int addgroup(const char *filename, char *group, gid_t gid)
|
static int addgroup(const char *filename, char *group, gid_t gid, const char *user)
|
||||||
{
|
{
|
||||||
FILE *etc_group;
|
FILE *etc_group;
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ static int addgroup(const char *filename, char *group, gid_t gid)
|
|||||||
/* add entry to group */
|
/* add entry to group */
|
||||||
etc_group = xfopen(filename, "a");
|
etc_group = xfopen(filename, "a");
|
||||||
|
|
||||||
fprintf(etc_group, entryfmt, group, default_passwd, gr.gr_gid, "");
|
fprintf(etc_group, entryfmt, group, default_passwd, gr.gr_gid, user);
|
||||||
fclose(etc_group);
|
fclose(etc_group);
|
||||||
|
|
||||||
|
|
||||||
@ -133,6 +133,7 @@ static int addgroup(const char *filename, char *group, gid_t gid)
|
|||||||
int addgroup_main(int argc, char **argv)
|
int addgroup_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *group;
|
char *group;
|
||||||
|
char *user;
|
||||||
gid_t gid = 0;
|
gid_t gid = 0;
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
@ -146,13 +147,19 @@ int addgroup_main(int argc, char **argv)
|
|||||||
show_usage();
|
show_usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (argc == 4) {
|
||||||
|
user = argv[3];
|
||||||
|
} else {
|
||||||
|
user = "";
|
||||||
|
}
|
||||||
|
|
||||||
if (geteuid() != 0) {
|
if (geteuid() != 0) {
|
||||||
error_msg_and_die
|
error_msg_and_die
|
||||||
("Only root may add a group to the system.");
|
("Only root may add a group to the system.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* werk */
|
/* werk */
|
||||||
return addgroup(group_file, group, gid);
|
return addgroup(GROUP_FILE, group, gid, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* $Id: addgroup.c,v 1.6 2002/11/14 11:10:14 andersen Exp $ */
|
/* $Id: addgroup.c,v 1.7 2002/12/12 08:57:16 andersen Exp $ */
|
||||||
|
Loading…
Reference in New Issue
Block a user