Blame SOURCES/mod_nss-group-permissions.patch

7212c2
From 302905ffe8fdcb9abdf36f16bc4420f5e1dbab01 Mon Sep 17 00:00:00 2001
7212c2
From: Rob Crittenden <rcritten@redhat.com>
7212c2
Date: Thu, 23 Feb 2017 13:06:21 -0500
7212c2
Subject: [PATCH] Handle group membership when testing for file permissions
7212c2
7212c2
This was a bit of a corner case but group membership wasn't
7212c2
considered when trying to determine if the NSS databases are
7212c2
readable.
7212c2
7212c2
Resolves BZ 1395300
7212c2
---
7212c2
 nss_engine_init.c | 45 +++++++++++++++++++++++++++++++++------------
7212c2
 1 file changed, 33 insertions(+), 12 deletions(-)
7212c2
7212c2
diff --git a/nss_engine_init.c b/nss_engine_init.c
7212c2
index 0bb2054..14f86d8 100644
7212c2
--- a/nss_engine_init.c
7212c2
+++ b/nss_engine_init.c
7212c2
@@ -29,6 +29,7 @@
7212c2
 #include "cert.h"
7212c2
 #include <sys/types.h>
7212c2
 #include <pwd.h>
7212c2
+#include <grp.h>
7212c2
 
7212c2
 static SECStatus ownBadCertHandler(void *arg, PRFileDesc * socket);
7212c2
 static SECStatus ownHandshakeCallback(PRFileDesc * socket, void *arg);
7212c2
@@ -56,17 +57,33 @@ static char *version_components[] = {
7212c2
  * Return 0 on failure or file doesn't exist
7212c2
  * Return 1 on success
7212c2
  */
7212c2
-static int check_path(uid_t uid, gid_t gid, char *filepath, apr_pool_t *p)
7212c2
+static int check_path(const char *user, uid_t uid, gid_t gid, char *filepath,
7212c2
+                      apr_pool_t *p)
7212c2
 {
7212c2
     apr_finfo_t finfo;
7212c2
-    int rv;
7212c2
+    PRBool in_group = PR_FALSE;
7212c2
+    struct group *gr;
7212c2
+    int i = 0;
7212c2
+
7212c2
+    if ((apr_stat(&finfo, filepath, APR_FINFO_PROT | APR_FINFO_OWNER, p))
7212c2
+        == APR_SUCCESS) {
7212c2
+        if ((gr = getgrgid(finfo.group)) == NULL) {
7212c2
+            return 0;
7212c2
+        }
7212c2
 
7212c2
-    if ((rv = apr_stat(&finfo, filepath, APR_FINFO_PROT | APR_FINFO_OWNER,
7212c2
-         p)) == APR_SUCCESS) {
7212c2
+        if (gid == finfo.group) {
7212c2
+            in_group = PR_TRUE;
7212c2
+        } else {
7212c2
+            while ((gr->gr_mem != NULL) && (gr->gr_mem[i] != NULL)) {
7212c2
+                if (!strcasecmp(user, gr->gr_mem[i++])) {
7212c2
+                    in_group = PR_TRUE;
7212c2
+                    break;
7212c2
+                }
7212c2
+            }
7212c2
+        }
7212c2
         if (((uid == finfo.user) &&
7212c2
             (finfo.protection & APR_FPROT_UREAD)) ||
7212c2
-            ((gid == finfo.group) &&
7212c2
-                (finfo.protection & APR_FPROT_GREAD)) ||
7212c2
+            (in_group && (finfo.protection & APR_FPROT_GREAD)) ||
7212c2
             (finfo.protection & APR_FPROT_WREAD)
7212c2
            )
7212c2
         {
7212c2
@@ -176,7 +193,7 @@ static void nss_init_SSLLibrary(server_rec *base_server, apr_pool_t *p)
7212c2
                 "Checking permissions for user %s: uid %d gid %d",
7212c2
                 mc->user, pw->pw_uid, pw->pw_gid);
7212c2
 
7212c2
-            if (!(check_path(pw->pw_uid, pw->pw_gid, dbdir, p))) {
7212c2
+            if (!(check_path(mc->user, pw->pw_uid, pw->pw_gid, dbdir, p))) {
7212c2
                 ap_log_error(APLOG_MARK, APLOG_ERR, 0, base_server,
7212c2
                     "Server user %s lacks read access to NSS "
7212c2
                     "database directory %s.", mc->user, dbdir);
7212c2
@@ -186,7 +203,8 @@ static void nss_init_SSLLibrary(server_rec *base_server, apr_pool_t *p)
7212c2
             if (strncasecmp(mc->pCertificateDatabase, "sql:", 4) == 0) {
7212c2
                 apr_snprintf(filepath, 1024, "%s/key4.db",
7212c2
                              mc->pCertificateDatabase+4);
7212c2
-                if (!(check_path(pw->pw_uid, pw->pw_gid, filepath, p))) {
7212c2
+                if (!(check_path(mc->user, pw->pw_uid, pw->pw_gid, filepath,
7212c2
+                      p))) {
7212c2
                     ap_log_error(APLOG_MARK, APLOG_ERR, 0, base_server,
7212c2
                         "Server user %s lacks read access to NSS key "
7212c2
                         "database %s.", mc->user, filepath);
7212c2
@@ -194,7 +212,8 @@ static void nss_init_SSLLibrary(server_rec *base_server, apr_pool_t *p)
7212c2
                 }
7212c2
                 apr_snprintf(filepath, 1024, "%s/cert9.db",
7212c2
                              mc->pCertificateDatabase+4);
7212c2
-                if (!(check_path(pw->pw_uid, pw->pw_gid, filepath, p))) {
7212c2
+                if (!(check_path(mc->user, pw->pw_uid, pw->pw_gid, filepath,
7212c2
+                      p))) {
7212c2
                     ap_log_error(APLOG_MARK, APLOG_ERR, 0, base_server,
7212c2
                         "Server user %s lacks read access to NSS cert "
7212c2
                         "database %s.", mc->user, filepath);
7212c2
@@ -203,7 +222,8 @@ static void nss_init_SSLLibrary(server_rec *base_server, apr_pool_t *p)
7212c2
             } else {
7212c2
                 apr_snprintf(filepath, 1024, "%s/key3.db",
7212c2
                              mc->pCertificateDatabase);
7212c2
-                if (!(check_path(pw->pw_uid, pw->pw_gid, filepath, p))) {
7212c2
+                if (!(check_path(mc->user, pw->pw_uid, pw->pw_gid, filepath,
7212c2
+                      p))) {
7212c2
                     ap_log_error(APLOG_MARK, APLOG_ERR, 0, base_server,
7212c2
                         "Server user %s lacks read access to NSS key "
7212c2
                         "database %s.", mc->user, filepath);
7212c2
@@ -211,7 +231,8 @@ static void nss_init_SSLLibrary(server_rec *base_server, apr_pool_t *p)
7212c2
                 }
7212c2
                 apr_snprintf(filepath, 1024, "%s/cert8.db",
7212c2
                              mc->pCertificateDatabase);
7212c2
-                if (!(check_path(pw->pw_uid, pw->pw_gid, filepath, p))) {
7212c2
+                if (!(check_path(mc->user, pw->pw_uid, pw->pw_gid, filepath,
7212c2
+                      p))) {
7212c2
                     ap_log_error(APLOG_MARK, APLOG_ERR, 0, base_server,
7212c2
                         "Server user %s lacks read access to NSS cert "
7212c2
                         "database %s.", mc->user, filepath);
7212c2
@@ -219,7 +240,7 @@ static void nss_init_SSLLibrary(server_rec *base_server, apr_pool_t *p)
7212c2
                 }
7212c2
                 apr_snprintf(filepath, 1024, "%s/secmod.db",
7212c2
                              mc->pCertificateDatabase);
7212c2
-                if (!(check_path(pw->pw_uid, pw->pw_gid, filepath, p))) {
7212c2
+                if (!(check_path(mc->user, pw->pw_uid, pw->pw_gid, filepath, p))) {
7212c2
                     ap_log_error(APLOG_MARK, APLOG_ERR, 0, base_server,
7212c2
                         "Server user %s lacks read access to NSS secmod "
7212c2
                         "database %s.", mc->user, filepath);
7212c2
-- 
7212c2
2.9.3
7212c2