Blame SOURCES/shadow-4.6-check-local-groups.patch

5b8176
From 140510de9de4771feb3af1d859c09604043a4c9b Mon Sep 17 00:00:00 2001
5b8176
From: ikerexxe <ipedrosa@redhat.com>
5b8176
Date: Fri, 27 Mar 2020 14:23:02 +0100
5b8176
Subject: [PATCH 1/2] usermod: check only local groups with -G option
5b8176
5b8176
Check only local groups when adding new supplementary groups to a user
5b8176
5b8176
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1727236
5b8176
---
5b8176
 src/usermod.c | 220 ++++++++++++++++++++++++++++++++------------------
5b8176
 1 file changed, 143 insertions(+), 77 deletions(-)
5b8176
5b8176
diff --git a/src/usermod.c b/src/usermod.c
5b8176
index 05b98715..ef430296 100644
5b8176
--- a/src/usermod.c
5b8176
+++ b/src/usermod.c
5b8176
@@ -183,6 +183,7 @@ static bool sub_gid_locked = false;
5b8176
 static void date_to_str (/*@unique@*//*@out@*/char *buf, size_t maxsize,
5b8176
                          long int date);
5b8176
 static int get_groups (char *);
5b8176
+static struct group * get_local_group (char * grp_name);
5b8176
 static /*@noreturn@*/void usage (int status);
5b8176
 static void new_pwent (struct passwd *);
5b8176
 static void new_spent (struct spwd *);
5b8176
@@ -196,7 +197,9 @@ static void grp_update (void);
5b8176
 
5b8176
 static void process_flags (int, char **);
5b8176
 static void close_files (void);
5b8176
+static void close_group_files (void);
5b8176
 static void open_files (void);
5b8176
+static void open_group_files (void);
5b8176
 static void usr_update (void);
5b8176
 static void move_home (void);
5b8176
 static void update_lastlog (void);
5b8176
@@ -253,6 +256,11 @@ static int get_groups (char *list)
5b8176
 		return 0;
5b8176
 	}
5b8176
 
5b8176
+	/*
5b8176
+	 * Open the group files
5b8176
+	 */
5b8176
+	open_group_files ();
5b8176
+
5b8176
 	/*
5b8176
 	 * So long as there is some data to be converted, strip off each
5b8176
 	 * name and look it up. A mix of numerical and string values for
5b8176
@@ -272,7 +280,7 @@ static int get_groups (char *list)
5b8176
 		 * Names starting with digits are treated as numerical GID
5b8176
 		 * values, otherwise the string is looked up as is.
5b8176
 		 */
5b8176
-		grp = prefix_getgr_nam_gid (list);
5b8176
+		grp = get_local_group (list);
5b8176
 
5b8176
 		/*
5b8176
 		 * There must be a match, either by GID value or by
5b8176
@@ -322,6 +330,8 @@ static int get_groups (char *list)
5b8176
 		gr_free ((struct group *)grp);
5b8176
 	} while (NULL != list);
5b8176
 
5b8176
+	close_group_files ();
5b8176
+
5b8176
 	user_groups[ngroups] = (char *) 0;
5b8176
 
5b8176
 	/*
5b8176
@@ -334,6 +344,44 @@ static int get_groups (char *list)
5b8176
 	return 0;
5b8176
 }
5b8176
 
5b8176
+/*
5b8176
+ * get_local_group - checks if a given group name exists locally
5b8176
+ *
5b8176
+ *	get_local_group() checks if a given group name exists locally.
5b8176
+ *	If the name exists the group information is returned, otherwise NULL is
5b8176
+ *	returned.
5b8176
+ */
5b8176
+static struct group * get_local_group(char * grp_name)
5b8176
+{
5b8176
+	const struct group *grp;
5b8176
+	struct group *result_grp = NULL;
5b8176
+	long long int gid;
5b8176
+	char *endptr;
5b8176
+
5b8176
+	gid = strtoll (grp_name, &endptr, 10);
5b8176
+	if (   ('\0' != *grp_name)
5b8176
+		&& ('\0' == *endptr)
5b8176
+		&& (ERANGE != errno)
5b8176
+		&& (gid == (gid_t)gid)) {
5b8176
+		grp = gr_locate_gid ((gid_t) gid);
5b8176
+	}
5b8176
+	else {
5b8176
+		grp = gr_locate(grp_name);
5b8176
+	}
5b8176
+
5b8176
+	if (grp != NULL) {
5b8176
+		result_grp = __gr_dup (grp);
5b8176
+		if (NULL == result_grp) {
5b8176
+			fprintf (stderr,
5b8176
+					_("%s: Out of memory. Cannot find group '%s'.\n"),
5b8176
+					Prog, grp_name);
5b8176
+			fail_exit (E_GRP_UPDATE);
5b8176
+		}
5b8176
+	}
5b8176
+
5b8176
+	return result_grp;
5b8176
+}
5b8176
+
5b8176
 #ifdef ENABLE_SUBIDS
5b8176
 struct ulong_range
5b8176
 {
5b8176
@@ -1447,50 +1495,7 @@ static void close_files (void)
5b8176
 	}
5b8176
 
5b8176
 	if (Gflg || lflg) {
5b8176
-		if (gr_close () == 0) {
5b8176
-			fprintf (stderr,
5b8176
-			         _("%s: failure while writing changes to %s\n"),
5b8176
-			         Prog, gr_dbname ());
5b8176
-			SYSLOG ((LOG_ERR,
5b8176
-			         "failure while writing changes to %s",
5b8176
-			         gr_dbname ()));
5b8176
-			fail_exit (E_GRP_UPDATE);
5b8176
-		}
5b8176
-#ifdef SHADOWGRP
5b8176
-		if (is_shadow_grp) {
5b8176
-			if (sgr_close () == 0) {
5b8176
-				fprintf (stderr,
5b8176
-				         _("%s: failure while writing changes to %s\n"),
5b8176
-				         Prog, sgr_dbname ());
5b8176
-				SYSLOG ((LOG_ERR,
5b8176
-				         "failure while writing changes to %s",
5b8176
-				         sgr_dbname ()));
5b8176
-				fail_exit (E_GRP_UPDATE);
5b8176
-			}
5b8176
-		}
5b8176
-#endif
5b8176
-#ifdef SHADOWGRP
5b8176
-		if (is_shadow_grp) {
5b8176
-			if (sgr_unlock () == 0) {
5b8176
-				fprintf (stderr,
5b8176
-				         _("%s: failed to unlock %s\n"),
5b8176
-				         Prog, sgr_dbname ());
5b8176
-				SYSLOG ((LOG_ERR,
5b8176
-				         "failed to unlock %s",
5b8176
-				         sgr_dbname ()));
5b8176
-				/* continue */
5b8176
-			}
5b8176
-		}
5b8176
-#endif
5b8176
-		if (gr_unlock () == 0) {
5b8176
-			fprintf (stderr,
5b8176
-			         _("%s: failed to unlock %s\n"),
5b8176
-			         Prog, gr_dbname ());
5b8176
-			SYSLOG ((LOG_ERR,
5b8176
-			         "failed to unlock %s",
5b8176
-			         gr_dbname ()));
5b8176
-			/* continue */
5b8176
-		}
5b8176
+		close_group_files ();
5b8176
 	}
5b8176
 
5b8176
 	if (is_shadow_pwd) {
5b8176
@@ -1559,6 +1564,60 @@ static void close_files (void)
5b8176
 #endif
5b8176
 }
5b8176
 
5b8176
+/*
5b8176
+ * close_group_files - close all of the files that were opened
5b8176
+ *
5b8176
+ *	close_group_files() closes all of the files that were opened related
5b8176
+ *  with groups. This causes any modified entries to be written out.
5b8176
+ */
5b8176
+static void close_group_files (void)
5b8176
+{
5b8176
+	if (gr_close () == 0) {
5b8176
+		fprintf (stderr,
5b8176
+					_("%s: failure while writing changes to %s\n"),
5b8176
+					Prog, gr_dbname ());
5b8176
+		SYSLOG ((LOG_ERR,
5b8176
+					"failure while writing changes to %s",
5b8176
+					gr_dbname ()));
5b8176
+		fail_exit (E_GRP_UPDATE);
5b8176
+	}
5b8176
+#ifdef SHADOWGRP
5b8176
+	if (is_shadow_grp) {
5b8176
+		if (sgr_close () == 0) {
5b8176
+			fprintf (stderr,
5b8176
+						_("%s: failure while writing changes to %s\n"),
5b8176
+						Prog, sgr_dbname ());
5b8176
+			SYSLOG ((LOG_ERR,
5b8176
+						"failure while writing changes to %s",
5b8176
+						sgr_dbname ()));
5b8176
+			fail_exit (E_GRP_UPDATE);
5b8176
+		}
5b8176
+	}
5b8176
+#endif
5b8176
+#ifdef SHADOWGRP
5b8176
+	if (is_shadow_grp) {
5b8176
+		if (sgr_unlock () == 0) {
5b8176
+			fprintf (stderr,
5b8176
+						_("%s: failed to unlock %s\n"),
5b8176
+						Prog, sgr_dbname ());
5b8176
+			SYSLOG ((LOG_ERR,
5b8176
+						"failed to unlock %s",
5b8176
+						sgr_dbname ()));
5b8176
+			/* continue */
5b8176
+		}
5b8176
+	}
5b8176
+#endif
5b8176
+	if (gr_unlock () == 0) {
5b8176
+		fprintf (stderr,
5b8176
+					_("%s: failed to unlock %s\n"),
5b8176
+					Prog, gr_dbname ());
5b8176
+		SYSLOG ((LOG_ERR,
5b8176
+					"failed to unlock %s",
5b8176
+					gr_dbname ()));
5b8176
+		/* continue */
5b8176
+	}
5b8176
+}
5b8176
+
5b8176
 /*
5b8176
  * open_files - lock and open the password files
5b8176
  *
5b8176
@@ -1594,38 +1653,7 @@ static void open_files (void)
5b8176
 	}
5b8176
 
5b8176
 	if (Gflg || lflg) {
5b8176
-		/*
5b8176
-		 * Lock and open the group file. This will load all of the
5b8176
-		 * group entries.
5b8176
-		 */
5b8176
-		if (gr_lock () == 0) {
5b8176
-			fprintf (stderr,
5b8176
-			         _("%s: cannot lock %s; try again later.\n"),
5b8176
-			         Prog, gr_dbname ());
5b8176
-			fail_exit (E_GRP_UPDATE);
5b8176
-		}
5b8176
-		gr_locked = true;
5b8176
-		if (gr_open (O_CREAT | O_RDWR) == 0) {
5b8176
-			fprintf (stderr,
5b8176
-			         _("%s: cannot open %s\n"),
5b8176
-			         Prog, gr_dbname ());
5b8176
-			fail_exit (E_GRP_UPDATE);
5b8176
-		}
5b8176
-#ifdef SHADOWGRP
5b8176
-		if (is_shadow_grp && (sgr_lock () == 0)) {
5b8176
-			fprintf (stderr,
5b8176
-			         _("%s: cannot lock %s; try again later.\n"),
5b8176
-			         Prog, sgr_dbname ());
5b8176
-			fail_exit (E_GRP_UPDATE);
5b8176
-		}
5b8176
-		sgr_locked = true;
5b8176
-		if (is_shadow_grp && (sgr_open (O_CREAT | O_RDWR) == 0)) {
5b8176
-			fprintf (stderr,
5b8176
-			         _("%s: cannot open %s\n"),
5b8176
-			         Prog, sgr_dbname ());
5b8176
-			fail_exit (E_GRP_UPDATE);
5b8176
-		}
5b8176
-#endif
5b8176
+		open_group_files ();
5b8176
 	}
5b8176
 #ifdef ENABLE_SUBIDS
5b8176
 	if (vflg || Vflg) {
5b8176
@@ -1661,6 +1689,44 @@ static void open_files (void)
5b8176
 #endif				/* ENABLE_SUBIDS */
5b8176
 }
5b8176
 
5b8176
+/*
5b8176
+ * open_group_files - lock and open the group files
5b8176
+ *
5b8176
+ *	open_group_files() loads all of the group entries.
5b8176
+ */
5b8176
+static void open_group_files (void)
5b8176
+{
5b8176
+	if (gr_lock () == 0) {
5b8176
+		fprintf (stderr,
5b8176
+					_("%s: cannot lock %s; try again later.\n"),
5b8176
+					Prog, gr_dbname ());
5b8176
+		fail_exit (E_GRP_UPDATE);
5b8176
+	}
5b8176
+	gr_locked = true;
5b8176
+	if (gr_open (O_CREAT | O_RDWR) == 0) {
5b8176
+		fprintf (stderr,
5b8176
+					_("%s: cannot open %s\n"),
5b8176
+					Prog, gr_dbname ());
5b8176
+		fail_exit (E_GRP_UPDATE);
5b8176
+	}
5b8176
+
5b8176
+#ifdef SHADOWGRP
5b8176
+	if (is_shadow_grp && (sgr_lock () == 0)) {
5b8176
+		fprintf (stderr,
5b8176
+					_("%s: cannot lock %s; try again later.\n"),
5b8176
+					Prog, sgr_dbname ());
5b8176
+		fail_exit (E_GRP_UPDATE);
5b8176
+	}
5b8176
+	sgr_locked = true;
5b8176
+	if (is_shadow_grp && (sgr_open (O_CREAT | O_RDWR) == 0)) {
5b8176
+		fprintf (stderr,
5b8176
+					_("%s: cannot open %s\n"),
5b8176
+					Prog, sgr_dbname ());
5b8176
+		fail_exit (E_GRP_UPDATE);
5b8176
+	}
5b8176
+#endif
5b8176
+}
5b8176
+
5b8176
 /*
5b8176
  * usr_update - create the user entries
5b8176
  *
5b8176
-- 
5b8176
2.25.4
5b8176
5b8176
5b8176
From 8762f465d487a52bf68f9c0b7c3c1eb3caea7bc9 Mon Sep 17 00:00:00 2001
5b8176
From: ikerexxe <ipedrosa@redhat.com>
5b8176
Date: Mon, 30 Mar 2020 09:08:23 +0200
5b8176
Subject: [PATCH 2/2] useradd: check only local groups with -G option
5b8176
5b8176
Check only local groups when adding new supplementary groups to a user
5b8176
5b8176
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1727236
5b8176
---
5b8176
 src/useradd.c | 234 +++++++++++++++++++++++++++++++++-----------------
5b8176
 1 file changed, 157 insertions(+), 77 deletions(-)
5b8176
5b8176
diff --git a/src/useradd.c b/src/useradd.c
5b8176
index 645d4a40..90210233 100644
5b8176
--- a/src/useradd.c
5b8176
+++ b/src/useradd.c
5b8176
@@ -211,6 +211,7 @@ static void get_defaults (void);
5b8176
 static void show_defaults (void);
5b8176
 static int set_defaults (void);
5b8176
 static int get_groups (char *);
5b8176
+static struct group * get_local_group (char * grp_name);
5b8176
 static void usage (int status);
5b8176
 static void new_pwent (struct passwd *);
5b8176
 
5b8176
@@ -220,7 +221,10 @@ static void grp_update (void);
5b8176
 
5b8176
 static void process_flags (int argc, char **argv);
5b8176
 static void close_files (void);
5b8176
+static void close_group_files (void);
5b8176
+static void unlock_group_files (void);
5b8176
 static void open_files (void);
5b8176
+static void open_group_files (void);
5b8176
 static void open_shadow (void);
5b8176
 static void faillog_reset (uid_t);
5b8176
 static void lastlog_reset (uid_t);
5b8176
@@ -731,6 +735,11 @@ static int get_groups (char *list)
5b8176
 		return 0;
5b8176
 	}
5b8176
 
5b8176
+	/*
5b8176
+	 * Open the group files
5b8176
+	 */
5b8176
+	open_group_files ();
5b8176
+
5b8176
 	/*
5b8176
 	 * So long as there is some data to be converted, strip off
5b8176
 	 * each name and look it up. A mix of numerical and string
5b8176
@@ -749,7 +758,7 @@ static int get_groups (char *list)
5b8176
 		 * Names starting with digits are treated as numerical
5b8176
 		 * GID values, otherwise the string is looked up as is.
5b8176
 		 */
5b8176
-		grp = prefix_getgr_nam_gid (list);
5b8176
+		grp = get_local_group (list);
5b8176
 
5b8176
 		/*
5b8176
 		 * There must be a match, either by GID value or by
5b8176
@@ -799,6 +808,9 @@ static int get_groups (char *list)
5b8176
 		user_groups[ngroups++] = xstrdup (grp->gr_name);
5b8176
 	} while (NULL != list);
5b8176
 
5b8176
+	close_group_files ();
5b8176
+	unlock_group_files ();
5b8176
+
5b8176
 	user_groups[ngroups] = (char *) 0;
5b8176
 
5b8176
 	/*
5b8176
@@ -811,6 +823,44 @@ static int get_groups (char *list)
5b8176
 	return 0;
5b8176
 }
5b8176
 
5b8176
+/*
5b8176
+ * get_local_group - checks if a given group name exists locally
5b8176
+ *
5b8176
+ *	get_local_group() checks if a given group name exists locally.
5b8176
+ *	If the name exists the group information is returned, otherwise NULL is
5b8176
+ *	returned.
5b8176
+ */
5b8176
+static struct group * get_local_group(char * grp_name)
5b8176
+{
5b8176
+	const struct group *grp;
5b8176
+	struct group *result_grp = NULL;
5b8176
+	long long int gid;
5b8176
+	char *endptr;
5b8176
+
5b8176
+	gid = strtoll (grp_name, &endptr, 10);
5b8176
+	if (   ('\0' != *grp_name)
5b8176
+		&& ('\0' == *endptr)
5b8176
+		&& (ERANGE != errno)
5b8176
+		&& (gid == (gid_t)gid)) {
5b8176
+		grp = gr_locate_gid ((gid_t) gid);
5b8176
+	}
5b8176
+	else {
5b8176
+		grp = gr_locate(grp_name);
5b8176
+	}
5b8176
+
5b8176
+	if (grp != NULL) {
5b8176
+		result_grp = __gr_dup (grp);
5b8176
+		if (NULL == result_grp) {
5b8176
+			fprintf (stderr,
5b8176
+					_("%s: Out of memory. Cannot find group '%s'.\n"),
5b8176
+					Prog, grp_name);
5b8176
+			fail_exit (E_GRP_UPDATE);
5b8176
+		}
5b8176
+	}
5b8176
+
5b8176
+	return result_grp;
5b8176
+}
5b8176
+
5b8176
 /*
5b8176
  * usage - display usage message and exit
5b8176
  */
5b8176
@@ -1530,23 +1580,9 @@ static void close_files (void)
5b8176
 		SYSLOG ((LOG_ERR, "failure while writing changes to %s", spw_dbname ()));
5b8176
 		fail_exit (E_PW_UPDATE);
5b8176
 	}
5b8176
-	if (do_grp_update) {
5b8176
-		if (gr_close () == 0) {
5b8176
-			fprintf (stderr,
5b8176
-			         _("%s: failure while writing changes to %s\n"), Prog, gr_dbname ());
5b8176
-			SYSLOG ((LOG_ERR, "failure while writing changes to %s", gr_dbname ()));
5b8176
-			fail_exit (E_GRP_UPDATE);
5b8176
-		}
5b8176
-#ifdef	SHADOWGRP
5b8176
-		if (is_shadow_grp && (sgr_close () == 0)) {
5b8176
-			fprintf (stderr,
5b8176
-			         _("%s: failure while writing changes to %s\n"),
5b8176
-			         Prog, sgr_dbname ());
5b8176
-			SYSLOG ((LOG_ERR, "failure while writing changes to %s", sgr_dbname ()));
5b8176
-			fail_exit (E_GRP_UPDATE);
5b8176
-		}
5b8176
-#endif
5b8176
-	}
5b8176
+
5b8176
+	close_group_files ();
5b8176
+
5b8176
 #ifdef ENABLE_SUBIDS
5b8176
 	if (is_sub_uid  && (sub_uid_close () == 0)) {
5b8176
 		fprintf (stderr,
5b8176
@@ -1587,34 +1623,9 @@ static void close_files (void)
5b8176
 		/* continue */
5b8176
 	}
5b8176
 	pw_locked = false;
5b8176
-	if (gr_unlock () == 0) {
5b8176
-		fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ());
5b8176
-		SYSLOG ((LOG_ERR, "failed to unlock %s", gr_dbname ()));
5b8176
-#ifdef WITH_AUDIT
5b8176
-		audit_logger (AUDIT_ADD_USER, Prog,
5b8176
-		              "unlocking-group-file",
5b8176
-		              user_name, AUDIT_NO_ID,
5b8176
-		              SHADOW_AUDIT_FAILURE);
5b8176
-#endif
5b8176
-		/* continue */
5b8176
-	}
5b8176
-	gr_locked = false;
5b8176
-#ifdef	SHADOWGRP
5b8176
-	if (is_shadow_grp) {
5b8176
-		if (sgr_unlock () == 0) {
5b8176
-			fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ());
5b8176
-			SYSLOG ((LOG_ERR, "failed to unlock %s", sgr_dbname ()));
5b8176
-#ifdef WITH_AUDIT
5b8176
-			audit_logger (AUDIT_ADD_USER, Prog,
5b8176
-			              "unlocking-gshadow-file",
5b8176
-			              user_name, AUDIT_NO_ID,
5b8176
-			              SHADOW_AUDIT_FAILURE);
5b8176
-#endif
5b8176
-			/* continue */
5b8176
-		}
5b8176
-		sgr_locked = false;
5b8176
-	}
5b8176
-#endif
5b8176
+
5b8176
+	unlock_group_files ();
5b8176
+
5b8176
 #ifdef ENABLE_SUBIDS
5b8176
 	if (is_sub_uid) {
5b8176
 		if (sub_uid_unlock () == 0) {
5b8176
@@ -1647,6 +1658,71 @@ static void close_files (void)
5b8176
 #endif				/* ENABLE_SUBIDS */
5b8176
 }
5b8176
 
5b8176
+/*
5b8176
+ * close_group_files - close all of the files that were opened
5b8176
+ *
5b8176
+ *	close_group_files() closes all of the files that were opened related
5b8176
+ *  with groups. This causes any modified entries to be written out.
5b8176
+ */
5b8176
+static void close_group_files (void)
5b8176
+{
5b8176
+	if (do_grp_update) {
5b8176
+		if (gr_close () == 0) {
5b8176
+			fprintf (stderr,
5b8176
+			         _("%s: failure while writing changes to %s\n"), Prog, gr_dbname ());
5b8176
+			SYSLOG ((LOG_ERR, "failure while writing changes to %s", gr_dbname ()));
5b8176
+			fail_exit (E_GRP_UPDATE);
5b8176
+		}
5b8176
+#ifdef	SHADOWGRP
5b8176
+		if (is_shadow_grp && (sgr_close () == 0)) {
5b8176
+			fprintf (stderr,
5b8176
+			         _("%s: failure while writing changes to %s\n"),
5b8176
+			         Prog, sgr_dbname ());
5b8176
+			SYSLOG ((LOG_ERR, "failure while writing changes to %s", sgr_dbname ()));
5b8176
+			fail_exit (E_GRP_UPDATE);
5b8176
+		}
5b8176
+#endif /* SHADOWGRP */
5b8176
+	}
5b8176
+}
5b8176
+
5b8176
+/*
5b8176
+ * unlock_group_files - unlock all of the files that were locked
5b8176
+ *
5b8176
+ *	unlock_group_files() unlocks all of the files that were locked related
5b8176
+ *  with groups. This causes any modified entries to be written out.
5b8176
+ */
5b8176
+static void unlock_group_files (void)
5b8176
+{
5b8176
+	if (gr_unlock () == 0) {
5b8176
+		fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ());
5b8176
+		SYSLOG ((LOG_ERR, "failed to unlock %s", gr_dbname ()));
5b8176
+#ifdef WITH_AUDIT
5b8176
+		audit_logger (AUDIT_ADD_USER, Prog,
5b8176
+		              "unlocking-group-file",
5b8176
+		              user_name, AUDIT_NO_ID,
5b8176
+		              SHADOW_AUDIT_FAILURE);
5b8176
+#endif /* WITH_AUDIT */
5b8176
+		/* continue */
5b8176
+	}
5b8176
+	gr_locked = false;
5b8176
+#ifdef	SHADOWGRP
5b8176
+	if (is_shadow_grp) {
5b8176
+		if (sgr_unlock () == 0) {
5b8176
+			fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ());
5b8176
+			SYSLOG ((LOG_ERR, "failed to unlock %s", sgr_dbname ()));
5b8176
+#ifdef WITH_AUDIT
5b8176
+			audit_logger (AUDIT_ADD_USER, Prog,
5b8176
+			              "unlocking-gshadow-file",
5b8176
+			              user_name, AUDIT_NO_ID,
5b8176
+			              SHADOW_AUDIT_FAILURE);
5b8176
+#endif /* WITH_AUDIT */
5b8176
+			/* continue */
5b8176
+		}
5b8176
+		sgr_locked = false;
5b8176
+	}
5b8176
+#endif /* SHADOWGRP */
5b8176
+}
5b8176
+
5b8176
 /*
5b8176
  * open_files - lock and open the password files
5b8176
  *
5b8176
@@ -1668,37 +1744,8 @@ static void open_files (void)
5b8176
 
5b8176
 	/* shadow file will be opened by open_shadow(); */
5b8176
 
5b8176
-	/*
5b8176
-	 * Lock and open the group file.
5b8176
-	 */
5b8176
-	if (gr_lock () == 0) {
5b8176
-		fprintf (stderr,
5b8176
-		         _("%s: cannot lock %s; try again later.\n"),
5b8176
-		         Prog, gr_dbname ());
5b8176
-		fail_exit (E_GRP_UPDATE);
5b8176
-	}
5b8176
-	gr_locked = true;
5b8176
-	if (gr_open (O_CREAT | O_RDWR) == 0) {
5b8176
-		fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ());
5b8176
-		fail_exit (E_GRP_UPDATE);
5b8176
-	}
5b8176
-#ifdef  SHADOWGRP
5b8176
-	if (is_shadow_grp) {
5b8176
-		if (sgr_lock () == 0) {
5b8176
-			fprintf (stderr,
5b8176
-			         _("%s: cannot lock %s; try again later.\n"),
5b8176
-			         Prog, sgr_dbname ());
5b8176
-			fail_exit (E_GRP_UPDATE);
5b8176
-		}
5b8176
-		sgr_locked = true;
5b8176
-		if (sgr_open (O_CREAT | O_RDWR) == 0) {
5b8176
-			fprintf (stderr,
5b8176
-			         _("%s: cannot open %s\n"),
5b8176
-			         Prog, sgr_dbname ());
5b8176
-			fail_exit (E_GRP_UPDATE);
5b8176
-		}
5b8176
-	}
5b8176
-#endif
5b8176
+	open_group_files ();
5b8176
+
5b8176
 #ifdef ENABLE_SUBIDS
5b8176
 	if (is_sub_uid) {
5b8176
 		if (sub_uid_lock () == 0) {
5b8176
@@ -1733,6 +1780,39 @@ static void open_files (void)
5b8176
 #endif				/* ENABLE_SUBIDS */
5b8176
 }
5b8176
 
5b8176
+static void open_group_files (void)
5b8176
+{
5b8176
+	if (gr_lock () == 0) {
5b8176
+		fprintf (stderr,
5b8176
+		         _("%s: cannot lock %s; try again later.\n"),
5b8176
+		         Prog, gr_dbname ());
5b8176
+		fail_exit (E_GRP_UPDATE);
5b8176
+	}
5b8176
+	gr_locked = true;
5b8176
+	if (gr_open (O_CREAT | O_RDWR) == 0) {
5b8176
+		fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ());
5b8176
+		fail_exit (E_GRP_UPDATE);
5b8176
+	}
5b8176
+
5b8176
+#ifdef  SHADOWGRP
5b8176
+	if (is_shadow_grp) {
5b8176
+		if (sgr_lock () == 0) {
5b8176
+			fprintf (stderr,
5b8176
+			         _("%s: cannot lock %s; try again later.\n"),
5b8176
+			         Prog, sgr_dbname ());
5b8176
+			fail_exit (E_GRP_UPDATE);
5b8176
+		}
5b8176
+		sgr_locked = true;
5b8176
+		if (sgr_open (O_CREAT | O_RDWR) == 0) {
5b8176
+			fprintf (stderr,
5b8176
+			         _("%s: cannot open %s\n"),
5b8176
+			         Prog, sgr_dbname ());
5b8176
+			fail_exit (E_GRP_UPDATE);
5b8176
+		}
5b8176
+	}
5b8176
+#endif /* SHADOWGRP */
5b8176
+}
5b8176
+
5b8176
 static void open_shadow (void)
5b8176
 {
5b8176
 	if (!is_shadow_pwd) {
5b8176
-- 
5b8176
2.25.4
5b8176