-
Notifications
You must be signed in to change notification settings - Fork 4
/
0006-scratchbox2-Allow-specifying-of-nscd-socket-location.patch
152 lines (137 loc) · 4.79 KB
/
0006-scratchbox2-Allow-specifying-of-nscd-socket-location.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= <[email protected]>
Date: Tue, 31 Aug 2021 01:47:36 +0300
Subject: [PATCH] (scratchbox2) Allow specifying of nscd socket location
This patch makes location of nscd's socket to be run-time
configurable via an environment variable.
---
nscd/connections.c | 25 ++++++++++++++++++++++---
nscd/nscd.c | 21 +++++++++++++++++----
nscd/nscd_helper.c | 16 +++++++++++++++-
3 files changed, 54 insertions(+), 8 deletions(-)
diff --git a/nscd/connections.c b/nscd/connections.c
index a9bc00de9056c83b579c0fb7a1e29a9a98c6a5bb..05953bfcc2da3e8e4eff8f49205aa42435976fe5 100644
--- a/nscd/connections.c
+++ b/nscd/connections.c
@@ -477,6 +477,20 @@ fail:
return 0;
}
+int __nscd_get_socket_path(char *buf, size_t bufsiz)
+{
+ const char *ext_nscd_socket_path = getenv ("NSCD_SOCKET_PATH");
+ if (ext_nscd_socket_path) {
+ int len = strlen(ext_nscd_socket_path);
+ strncpy (buf, ext_nscd_socket_path, bufsiz);
+ if (len >= bufsiz) return -1;
+ return 0;
+ }
+ strncpy (buf, _PATH_NSCDSOCKET, bufsiz);
+ if (sizeof(_PATH_NSCDSOCKET) >= bufsiz) return -1;
+ return 0;
+}
+
/* Initialize database information structures. */
void
@@ -788,15 +802,20 @@ cannot create read-only descriptor for \"%s\"; no mmap"),
/* Bind a name to the socket. */
struct sockaddr_un sock_addr;
sock_addr.sun_family = AF_UNIX;
- strcpy (sock_addr.sun_path, _PATH_NSCDSOCKET);
+ if (__nscd_get_socket_path (sock_addr.sun_path, sizeof(sock_addr.sun_path)) < 0)
+ {
+ dbg_log ("Path to nscd socket is too long");
+ exit (1);
+ }
+
if (bind (sock, (struct sockaddr *) &sock_addr, sizeof (sock_addr)) < 0)
{
- dbg_log ("%s: %s", _PATH_NSCDSOCKET, strerror (errno));
+ dbg_log ("%s: %s", sock_addr.sun_path, strerror (errno));
do_exit (errno == EACCES ? 4 : 1, 0, NULL);
}
/* Set permissions for the socket. */
- chmod (_PATH_NSCDSOCKET, DEFFILEMODE);
+ chmod (sock_addr.sun_path, DEFFILEMODE);
/* Set the socket up to accept connections. */
if (listen (sock, SOMAXCONN) < 0)
diff --git a/nscd/nscd.c b/nscd/nscd.c
index eea1db7ad500cac4a405a6eba62e0f13dbbc16ef..6c68dee3a1a361c04e204273ab8c5eecfb68ceb6 100644
--- a/nscd/nscd.c
+++ b/nscd/nscd.c
@@ -134,6 +134,8 @@ static struct argp argp =
static bool get_stats;
static int parent_fd = -1;
+extern int __nscd_get_socket_path(char *buf, size_t bufsiz);
+
int
main (int argc, char **argv)
{
@@ -290,7 +292,11 @@ main (int argc, char **argv)
signal (SIGPIPE, SIG_IGN);
/* Cleanup files created by a previous 'bind'. */
- unlink (_PATH_NSCDSOCKET);
+ {
+ struct sockaddr_un addr;
+ if (__nscd_get_socket_path (addr.sun_path, sizeof(addr.sun_path)) >= 0)
+ unlink (addr.sun_path);
+ }
#ifdef HAVE_INOTIFY
/* Use inotify to recognize changed files. */
@@ -528,8 +534,12 @@ nscd_open_socket (void)
return -1;
addr.sun_family = AF_UNIX;
- assert (sizeof (addr.sun_path) >= sizeof (_PATH_NSCDSOCKET));
- strcpy (addr.sun_path, _PATH_NSCDSOCKET);
+ if (__nscd_get_socket_path (addr.sun_path, sizeof(addr.sun_path)) < 0)
+ {
+ close (sock);
+ return -1;
+ }
+
if (connect (sock, (struct sockaddr *) &addr, sizeof (addr)) < 0)
{
close (sock);
@@ -544,10 +554,13 @@ nscd_open_socket (void)
void
termination_handler (int signum)
{
+ struct sockaddr_un addr;
+
close_sockets ();
/* Clean up the file created by 'bind'. */
- unlink (_PATH_NSCDSOCKET);
+ if (__nscd_get_socket_path (addr.sun_path, sizeof(addr.sun_path)) >= 0)
+ unlink (addr.sun_path);
/* Clean up pid file. */
unlink (_PATH_NSCDPID);
diff --git a/nscd/nscd_helper.c b/nscd/nscd_helper.c
index 733c2a60cd01338c344fabb5a9dccb71f6ba9492..55b7d234633ed23bd8b1f72f2175f1e533388090 100644
--- a/nscd/nscd_helper.c
+++ b/nscd/nscd_helper.c
@@ -160,6 +160,19 @@ __readvall (int fd, const struct iovec *iov, int iovcnt)
return ret;
}
+static int nscd_get_socket_path(char *buf, size_t bufsiz)
+{
+ const char *ext_nscd_socket_path = getenv ("NSCD_SOCKET_PATH");
+ if (ext_nscd_socket_path) {
+ int len = strlen(ext_nscd_socket_path);
+ strncpy (buf, ext_nscd_socket_path, bufsiz);
+ if (len >= bufsiz) return -1;
+ return 0;
+ }
+ strncpy (buf, _PATH_NSCDSOCKET, bufsiz);
+ if (sizeof(_PATH_NSCDSOCKET) >= bufsiz) return -1;
+ return 0;
+}
static int
open_socket (request_type type, const char *key, size_t keylen)
@@ -179,7 +192,8 @@ open_socket (request_type type, const char *key, size_t keylen)
struct sockaddr_un sun;
sun.sun_family = AF_UNIX;
- strcpy (sun.sun_path, _PATH_NSCDSOCKET);
+ if (nscd_get_socket_path (sun.sun_path, sizeof(sun.sun_path)) < 0) goto out;
+
if (__connect (sock, (struct sockaddr *) &sun, sizeof (sun)) < 0
&& errno != EINPROGRESS)
goto out;