File 0002-scratchbox2-Allow-specifying-of-nsswitch.conf-path.patch of Package glibc

From 58e734321b71a1da52817e30220afa4b65669dfa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= <bjorn.bidar@jolla.com>
Date: Tue, 31 Aug 2021 01:51:17 +0300
Subject: [PATCH 2/4] (scratchbox2) Allow specifying of nsswitch.conf path

This patch makes location of the /etc/nsswitch.conf file
to be run-time configurable via an environment variable.

This is needed for correct operation with Scratchbox 2.
Without this, the sb2-virtualized environment will
always read /etc/nsswitch.conf from the host.

(cherry picked from commit 1fe6591231fcf48de2d30d08241f3f53f7e73f66)
---
 nss/nss_database.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/nss/nss_database.c b/nss/nss_database.c
index 73cfd15a07..bd94a0108a 100644
--- a/nss/nss_database.c
+++ b/nss/nss_database.c
@@ -28,6 +28,7 @@
 #include <netdb.h>
 #include <stdio_ext.h>
 #include <string.h>
+#include <unistd.h> /* __libc_enable_secure */
 
 struct nss_database_state
 {
@@ -303,7 +304,15 @@ static bool
 nss_database_reload (struct nss_database_data *staging,
                      struct file_change_detection *initial)
 {
-  FILE *fp = fopen (_PATH_NSSWITCH_CONF, "rce");
+  const char *ext_nss_config_file = NULL;
+  if (__libc_enable_secure == 0)
+  {
+    ext_nss_config_file = getenv ("NSSWITCH_CONF_PATH");
+  }
+  /* Open config file.  */
+  FILE *fp = fopen (ext_nss_config_file ?
+    ext_nss_config_file : _PATH_NSSWITCH_CONF, "rce");
+
   if (fp == NULL)
     fp = fopen ("/usr" _PATH_NSSWITCH_CONF, "rce");
   if (fp == NULL)
-- 
2.52.0

openSUSE Build Service is sponsored by