/* append a new user to the passwd file */ static void new_group(char *group, gid_t gid) { FILE *file; struct group gr; /* make sure gid and group haven't already been allocated */ gr.gr_gid = gid; gr.gr_name = group; xgroup_study(&gr); /* add entry to group */ file = xfopen(bb_path_group_file, "a"); /* group:passwd:gid:userlist */ fprintf(file, "%s:x:%u:\n", group, (unsigned)gr.gr_gid); if (ENABLE_FEATURE_CLEAN_UP) fclose(file); #if ENABLE_FEATURE_SHADOWPASSWDS file = fopen_or_warn(bb_path_gshadow_file, "a"); if (file) { fprintf(file, "%s:!::\n", group); if (ENABLE_FEATURE_CLEAN_UP) fclose(file); } #endif }
/* append a new user to the passwd file */ static void new_group(char *group, gid_t gid) { struct group gr; char *p; /* make sure gid and group haven't already been allocated */ gr.gr_gid = gid; gr.gr_name = group; xgroup_study(&gr); /* add entry to group */ p = xasprintf("x:%u:", (unsigned) gr.gr_gid); if (update_passwd(bb_path_group_file, group, p, NULL) < 0) exit(EXIT_FAILURE); if (ENABLE_FEATURE_CLEAN_UP) free(p); #if ENABLE_FEATURE_SHADOWPASSWDS /* /etc/gshadow fields: * 1. Group name. * 2. Encrypted password. * If set, non-members of the group can join the group * by typing the password for that group using the newgrp command. * If the value is of this field ! then no user is allowed * to access the group using the newgrp command. A value of !! * is treated the same as a value of ! only it indicates * that a password has never been set before. If the value is null, * only group members can log into the group. * 3. Group administrators (comma delimited list). * Group members listed here can add or remove group members * using the gpasswd command. * 4. Group members (comma delimited list). */ /* Ignore errors: if file is missing we assume admin doesn't want it */ update_passwd(bb_path_gshadow_file, group, "!::", NULL); #endif }