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