glibc-2.25-nscd-socket-location.diff 4.09 KB
Newer Older
1 2 3 4 5 6
diff -ur glibc-2.14.1+p3/nscd/connections.c glibc-2.14.1/nscd/connections.c
--- glibc-2.14.1+p3/nscd/connections.c	2011-10-07 12:48:55.000000000 +0300
+++ glibc-2.14.1/nscd/connections.c	2011-11-16 17:22:40.000000000 +0200
@@ -502,6 +502,20 @@
   return 0;
 }
7

8 9 10 11 12 13 14 15 16 17 18 19 20 21
+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;
+}
+
22

23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
 #ifdef O_CLOEXEC
 # define EXTRA_O_FLAGS O_CLOEXEC
@@ -900,10 +914,15 @@
   /* 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));
40
       do_exit (errno == EACCES ? 4 : 1, 0, NULL);
41
     }
42

43 44
@@ -930,7 +949,7 @@
 #endif
45

46 47 48
   /* Set permissions for the socket.  */
-  chmod (_PATH_NSCDSOCKET, DEFFILEMODE);
+  chmod (sock_addr.sun_path, DEFFILEMODE);
49

50 51 52 53 54 55 56 57
   /* Set the socket up to accept connections.  */
   if (listen (sock, SOMAXCONN) < 0)
diff -ur glibc-2.14.1+p3/nscd/nscd.c glibc-2.14.1/nscd/nscd.c
--- glibc-2.14.1+p3/nscd/nscd.c	2011-10-07 12:48:55.000000000 +0300
+++ glibc-2.14.1/nscd/nscd.c	2011-11-16 17:22:40.000000000 +0200
@@ -126,6 +126,8 @@
 /* True if only statistics are requested.  */
 static bool get_stats;
58

59 60 61 62 63 64 65
+extern int __nscd_get_socket_path(char *buf, size_t bufsiz);
+
 int
 main (int argc, char **argv)
 {
@@ -270,7 +272,11 @@
   signal (SIGPIPE, SIG_IGN);
66

67 68 69 70 71 72 73
   /* 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);
+  }
74

75 76 77 78
   /* Make sure we do not get recursive calls.  */
   __nss_disable_nscd ();
@@ -448,8 +454,12 @@
     return -1;
79

80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
   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);
@@ -464,10 +474,13 @@
 void
 termination_handler (int signum)
 {
+  struct sockaddr_un addr;
+
   close_sockets ();
99

100 101 102 103
   /* 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);
104

105 106 107 108 109 110 111 112
   /* Clean up pid file.  */
   unlink (_PATH_NSCDPID);
diff -ur glibc-2.14.1+p3/nscd/nscd_helper.c glibc-2.14.1/nscd/nscd_helper.c
--- glibc-2.14.1+p3/nscd/nscd_helper.c	2011-10-07 12:48:55.000000000 +0300
+++ glibc-2.14.1/nscd/nscd_helper.c	2011-11-16 17:22:40.000000000 +0200
@@ -159,6 +159,19 @@
   return ret;
 }
113

114 115 116 117 118 119 120 121 122 123 124 125 126
+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;
+}
127

128 129 130
 static int
 open_socket (request_type type, const char *key, size_t keylen)
@@ -203,7 +216,8 @@
131

132 133 134 135 136 137 138 139
   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;