groupadd, groupmod: Update gshadow file with -U

When running groupadd or groupmod with the -U|--user option, also update
the group shadow database if it is used.

Fixes: 342c934a (2020-08-09, "add -U option to groupadd and groupmod")
Closes: <https://github.com/shadow-maint/shadow/issues/1124>
This commit is contained in:
Dennis Baurichter
2024-11-17 03:27:40 +01:00
committed by Alejandro Colomar
parent 9f129146ff
commit f220407144
2 changed files with 24 additions and 5 deletions

View File

@@ -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, ",");
}
}

View File

@@ -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;
@@ -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) {
@@ -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, ",");
}
}
@@ -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"),
@@ -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
@@ -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"),
@@ -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"),