Skip to content

Commit

Permalink
groupadd, groupmod: Update gshadow file with -U
Browse files Browse the repository at this point in the history
When running groupadd or groupmod with the -U|--user option, also update
the group shadow database if it is used.

Fixes: 342c934 (2020-08-09, "add -U option to groupadd and groupmod")
Closes: <shadow-maint#1124>
  • Loading branch information
sandwm authored and alejandro-colomar committed Dec 3, 2024
1 parent 9f12914 commit f220407
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/groupadd.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ static void grp_update (void)
exit (E_GRP_UPDATE);
}
grp.gr_mem = add_list(grp.gr_mem, token);
#ifdef SHADOWGRP
if (is_shadow_grp)
sgrp.sg_mem = add_list(sgrp.sg_mem, token);
#endif
token = strtok(NULL, ",");
}
}
Expand Down
25 changes: 20 additions & 5 deletions src/groupmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ static void grp_update (void)
new_grent (&grp);
#ifdef SHADOWGRP
if ( is_shadow_grp
&& (pflg || nflg)) {
&& (pflg || nflg || user_list)) {
osgrp = sgr_locate (group_name);
if (NULL != osgrp) {
sgrp = *osgrp;
Expand Down Expand Up @@ -262,6 +262,17 @@ static void grp_update (void)
if (NULL != grp.gr_mem[0])
grp.gr_mem = dup_list (grp.gr_mem);
}
#ifdef SHADOWGRP
if (NULL != osgrp) {
if (!aflg) {
sgrp.sg_mem = XMALLOC(1, char *);
sgrp.sg_mem[0] = NULL;
} else {
if (NULL != sgrp.sg_mem[0])
sgrp.sg_mem = dup_list(sgrp.sg_mem);
}
}
#endif /* SHADOWGRP */

token = strtok(user_list, ",");
while (token) {
Expand All @@ -270,6 +281,10 @@ static void grp_update (void)
exit (E_GRP_UPDATE);
}
grp.gr_mem = add_list(grp.gr_mem, token);
#ifdef SHADOWGRP
if (NULL != osgrp)
sgrp.sg_mem = add_list(sgrp.sg_mem, token);
#endif /* SHADOWGRP */
token = strtok(NULL, ",");
}
}
Expand Down Expand Up @@ -486,7 +501,7 @@ static void close_files (void)

#ifdef SHADOWGRP
if ( is_shadow_grp
&& (pflg || nflg)) {
&& (pflg || nflg || user_list)) {
if (sgr_close () == 0) {
fprintf (stderr,
_("%s: failure while writing changes to %s\n"),
Expand Down Expand Up @@ -618,7 +633,7 @@ static void prepare_failure_reports (void)
add_cleanup (cleanup_report_mod_group, &info_group);
#ifdef SHADOWGRP
if ( is_shadow_grp
&& (pflg || nflg)) {
&& (pflg || nflg || user_list)) {
add_cleanup (cleanup_report_mod_gshadow, &info_gshadow);
}
#endif
Expand All @@ -645,7 +660,7 @@ static void lock_files (void)

#ifdef SHADOWGRP
if ( is_shadow_grp
&& (pflg || nflg)) {
&& (pflg || nflg || user_list)) {
if (sgr_lock () == 0) {
fprintf (stderr,
_("%s: cannot lock %s; try again later.\n"),
Expand Down Expand Up @@ -683,7 +698,7 @@ static void open_files (void)

#ifdef SHADOWGRP
if ( is_shadow_grp
&& (pflg || nflg)) {
&& (pflg || nflg || user_list)) {
if (sgr_open (O_CREAT | O_RDWR) == 0) {
fprintf (stderr,
_("%s: cannot open %s\n"),
Expand Down

0 comments on commit f220407

Please sign in to comment.