]> git.ipfire.org Git - people/stevee/ipfire-3.x.git/blob - nss_ldap/patches/nss_ldap-259-res_init.patch
Move all packages to root.
[people/stevee/ipfire-3.x.git] / nss_ldap / patches / nss_ldap-259-res_init.patch
1 Workaround for a NetworkManager/Upstart combination making things
2 interesting. When an application starts before the network is up,
3 /etc/resolv.conf is empty, causing the application to attempt to use a
4 local resolver. When the network comes up later, /etc/resolv.conf gets
5 populated with nameserver addresses, but the application doesn't re-read
6 it. This screws nss_ldap later on, because the LDAP client library
7 needs to be able to resolve the directory server's address, but it can't
8 without a local resolver which is probably not started.
9
10 diff -up nss_ldap-259/configure.in nss_ldap-259/configure.in
11 --- nss_ldap-259/configure.in 2008-04-16 10:42:15.000000000 -0400
12 +++ nss_ldap-259/configure.in 2008-04-16 10:42:15.000000000 -0400
13 @@ -176,6 +176,7 @@ AC_CHECK_HEADERS(alignof.h)
14 AC_CHECK_HEADERS(rpc/rpcent.h)
15 AC_CHECK_HEADERS(sys/byteorder.h)
16 AC_CHECK_HEADERS(sys/un.h)
17 +AC_CHECK_HEADERS(sys/stat.h)
18 AC_CHECK_HEADERS(libc-lock.h)
19 AC_CHECK_HEADERS(bits/libc-lock.h)
20 AC_CHECK_HEADERS(sasl.h sasl/sasl.h)
21 diff -up nss_ldap-259/ldap-nss.c nss_ldap-259/ldap-nss.c
22 --- nss_ldap-259/ldap-nss.c 2008-04-16 10:42:15.000000000 -0400
23 +++ nss_ldap-259/ldap-nss.c 2008-04-16 10:48:02.000000000 -0400
24 @@ -44,10 +44,16 @@ static char rcsId[] =
25 #include <syslog.h>
26 #include <signal.h>
27 #include <fcntl.h>
28 +#ifdef HAVE_SYS_STAT_H
29 +#include <sys/stat.h>
30 +#endif
31 #include <sys/time.h>
32 #include <sys/socket.h>
33 #include <sys/param.h>
34 #include <errno.h>
35 +#ifdef HAVE_RESOLV_H
36 +#include <resolv.h>
37 +#endif
38 #ifdef HAVE_SYS_UN_H
39 #include <sys/un.h>
40 #endif
41 @@ -1021,8 +1027,31 @@ _nss_ldap_close (void)
42 do_close ();
43 }
44
45 +static void
46 +_nss_ldap_res_init (const char *uri)
47 +{
48 + if (strncmp(uri, "ldapi://", 8) != 0)
49 + {
50 + struct stat st;
51 + static time_t last_mtime = (time_t) -1;
52 +#if defined(HAVE_RESOLV_H) && defined(_PATH_RESCONF)
53 + NSS_LDAP_DEFINE_LOCK (_nss_ldap_res_init_lock);
54 + NSS_LDAP_LOCK (_nss_ldap_res_init_lock);
55 + if (stat(_PATH_RESCONF, &st) == 0)
56 + {
57 + if (last_mtime != st.st_mtime)
58 + {
59 + last_mtime = st.st_mtime;
60 + res_init();
61 + }
62 + }
63 + NSS_LDAP_UNLOCK (_nss_ldap_res_init_lock);
64 +#endif
65 + }
66 +}
67 +
68 static NSS_STATUS
69 -do_init_session (LDAP ** ld, const char *uri, int defport)
70 +do_init_session (LDAP ** ld, const char *uri, int defport, int res_init_hack)
71 {
72 int rc;
73 int ldaps;
74 @@ -1050,6 +1079,8 @@ do_init_session (LDAP ** ld, const char
75 uri = uribuf;
76 }
77
78 + if (res_init_hack)
79 + _nss_ldap_res_init(uri);
80 rc = ldap_initialize (ld, uri);
81 #else
82 if (strncasecmp (uri, "ldap://", sizeof ("ldap://") - 1) != 0)
83 @@ -1075,6 +1106,8 @@ do_init_session (LDAP ** ld, const char
84 defport = atoi (p + 1);
85 uri = uribuf;
86 }
87 + if (res_init_hack)
88 + _nss_ldap_res_init(NULL);
89 # ifdef HAVE_LDAP_INIT
90 *ld = ldap_init (uri, defport);
91 # else
92 @@ -1346,7 +1379,8 @@ do_init (void)
93
94 stat = do_init_session (&__session.ls_conn,
95 cfg->ldc_uris[__session.ls_current_uri],
96 - cfg->ldc_port);
97 + cfg->ldc_port,
98 + cfg->ldc_resolv_conf_res_init_hack);
99 if (stat != NSS_SUCCESS)
100 {
101 debug ("<== do_init (failed to initialize LDAP session)");
102 diff -up nss_ldap-259/ldap-nss.h nss_ldap-259/ldap-nss.h
103 --- nss_ldap-259/ldap-nss.h 2008-04-16 10:45:49.000000000 -0400
104 +++ nss_ldap-259/ldap-nss.h 2008-04-16 10:45:52.000000000 -0400
105 @@ -400,6 +400,9 @@ struct ldap_config
106 time_t ldc_mtime;
107
108 char **ldc_initgroups_ignoreusers;
109 +
110 + /* disable the do-res_init()-on-resolv.conf-changes hack */
111 + unsigned int ldc_resolv_conf_res_init_hack;
112 };
113
114 typedef struct ldap_config ldap_config_t;
115 diff -up nss_ldap-259/util.c nss_ldap-259/util.c
116 --- nss_ldap-259/util.c 2008-04-16 10:48:08.000000000 -0400
117 +++ nss_ldap-259/util.c 2008-04-16 10:50:14.000000000 -0400
118 @@ -680,6 +680,8 @@ NSS_STATUS _nss_ldap_init_config (ldap_c
119 }
120 }
121
122 + result->ldc_resolv_conf_res_init_hack = 1;
123 +
124 return NSS_SUCCESS;
125 }
126
127 @@ -1204,6 +1206,19 @@ _nss_ldap_readconfig (ldap_config_t ** p
128 {
129 t = &result->ldc_srv_domain;
130 }
131 + else if (!strcasecmp (k, "nss_resolv_conf_res_init_hack"))
132 + {
133 + if (!strcasecmp (v, "on") || !strcasecmp (v, "yes")
134 + || !strcasecmp (v, "true"))
135 + {
136 + result->ldc_resolv_conf_res_init_hack = 1;
137 + }
138 + else if (!strcasecmp (v, "off") || !strcasecmp (v, "no")
139 + || !strcasecmp (v, "false"))
140 + {
141 + result->ldc_resolv_conf_res_init_hack = 0;
142 + }
143 + }
144 else
145 {
146 /*