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.
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[] =
28 +#ifdef HAVE_SYS_STAT_H
29 +#include <sys/stat.h>
32 #include <sys/socket.h>
33 #include <sys/param.h>
41 @@ -1021,8 +1027,31 @@ _nss_ldap_close (void)
46 +_nss_ldap_res_init (const char *uri)
48 + if (strncmp(uri, "ldapi://", 8) != 0)
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)
57 + if (last_mtime != st.st_mtime)
59 + last_mtime = st.st_mtime;
63 + NSS_LDAP_UNLOCK (_nss_ldap_res_init_lock);
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)
74 @@ -1050,6 +1079,8 @@ do_init_session (LDAP ** ld, const char
79 + _nss_ldap_res_init(uri);
80 rc = ldap_initialize (ld, uri);
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);
88 + _nss_ldap_res_init(NULL);
89 # ifdef HAVE_LDAP_INIT
90 *ld = ldap_init (uri, defport);
92 @@ -1346,7 +1379,8 @@ do_init (void)
94 stat = do_init_session (&__session.ls_conn,
95 cfg->ldc_uris[__session.ls_current_uri],
98 + cfg->ldc_resolv_conf_res_init_hack);
99 if (stat != NSS_SUCCESS)
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
108 char **ldc_initgroups_ignoreusers;
110 + /* disable the do-res_init()-on-resolv.conf-changes hack */
111 + unsigned int ldc_resolv_conf_res_init_hack;
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
122 + result->ldc_resolv_conf_res_init_hack = 1;
127 @@ -1204,6 +1206,19 @@ _nss_ldap_readconfig (ldap_config_t ** p
129 t = &result->ldc_srv_domain;
131 + else if (!strcasecmp (k, "nss_resolv_conf_res_init_hack"))
133 + if (!strcasecmp (v, "on") || !strcasecmp (v, "yes")
134 + || !strcasecmp (v, "true"))
136 + result->ldc_resolv_conf_res_init_hack = 1;
138 + else if (!strcasecmp (v, "off") || !strcasecmp (v, "no")
139 + || !strcasecmp (v, "false"))
141 + result->ldc_resolv_conf_res_init_hack = 0;