link_with : [libbasic],
dependencies : [libdl])
-foreach tuple : [['myhostname', 'HAVE_MYHOSTNAME', []],
- ['systemd', '', []],
- ['mymachines', 'ENABLE_MACHINED', []],
- ['resolve', 'ENABLE_RESOLVED', [libdl]]]
+foreach tuple : [['myhostname', 'HAVE_MYHOSTNAME'],
+ ['systemd', '' ],
+ ['mymachines', 'ENABLE_MACHINED'],
+ ['resolve', 'ENABLE_RESOLVED']]
condition = tuple[1] == '' or conf.get(tuple[1], false)
if condition
module = tuple[0]
- extra_deps = tuple[2]
sym = 'src/nss-@0@/nss-@0@.sym'.format(module)
version_script_arg = join_paths(meson.current_source_dir(), sym)
link_with : [libsystemd_internal,
libbasic],
dependencies : [threads,
- librt] + extra_deps,
+ librt],
link_depends : sym,
install : true,
install_dir : rootlibdir)
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-#include <dlfcn.h>
#include <errno.h>
#include <netdb.h>
#include <nss.h>
#define DNS_CALL_TIMEOUT_USEC (45*USEC_PER_SEC)
-typedef void (*voidfunc_t)(void);
-
-static voidfunc_t find_fallback(const char *module, const char *symbol) {
- void *dl;
-
- /* Try to find a fallback NSS module symbol */
-
- dl = dlopen(module, RTLD_LAZY|RTLD_NODELETE);
- if (!dl)
- return NULL;
-
- return dlsym(dl, symbol);
-}
-
static bool bus_error_shall_fallback(sd_bus_error *e) {
return sd_bus_error_has_name(e, SD_BUS_ERROR_SERVICE_UNKNOWN) ||
sd_bus_error_has_name(e, SD_BUS_ERROR_NAME_HAS_NO_OWNER) ||
r = sd_bus_open_system(&bus);
if (r < 0)
- goto fallback;
+ goto fail;
r = sd_bus_message_new_method_call(
bus,
return NSS_STATUS_NOTFOUND;
}
- if (bus_error_shall_fallback(&error))
- goto fallback;
+ /* Return NSS_STATUS_UNAVAIL when communication with systemd-resolved fails,
+ allowing falling back to other nss modules. Treat all other error conditions as
+ NOTFOUND. This includes DNSSEC errors and suchlike. (We don't use UNAVAIL in this
+ case so that the nsswitch.conf configuration can distuingish such executed but
+ negative replies from complete failure to talk to resolved). */
+ if (!bus_error_shall_fallback(&error))
+ ret = NSS_STATUS_NOTFOUND;
- /* Treat all other error conditions as NOTFOUND, and fail. This includes DNSSEC errors and
- suchlike. (We don't use UNAVAIL in this case so that the nsswitch.conf configuration can distuingish
- such executed but negative replies from complete failure to talk to resolved. */
- ret = NSS_STATUS_NOTFOUND;
goto fail;
}
return NSS_STATUS_SUCCESS;
-fallback:
- {
- _nss_gethostbyname4_r_t fallback;
-
- fallback = (_nss_gethostbyname4_r_t)
- find_fallback("libnss_dns.so.2", "_nss_dns_gethostbyname4_r");
-
- if (fallback)
- return fallback(name, pat, buffer, buflen, errnop, h_errnop, ttlp);
- }
-
fail:
*errnop = -r;
*h_errnop = NO_RECOVERY;
r = sd_bus_open_system(&bus);
if (r < 0)
- goto fallback;
+ goto fail;
r = sd_bus_message_new_method_call(
bus,
return NSS_STATUS_NOTFOUND;
}
- if (bus_error_shall_fallback(&error))
- goto fallback;
+ if (!bus_error_shall_fallback(&error))
+ ret = NSS_STATUS_NOTFOUND;
- ret = NSS_STATUS_NOTFOUND;
goto fail;
}
return NSS_STATUS_SUCCESS;
-fallback:
- {
- _nss_gethostbyname3_r_t fallback;
-
- fallback = (_nss_gethostbyname3_r_t)
- find_fallback("libnss_dns.so.2", "_nss_dns_gethostbyname3_r");
- if (fallback)
- return fallback(name, af, result, buffer, buflen, errnop, h_errnop, ttlp, canonp);
- }
-
fail:
*errnop = -r;
*h_errnop = NO_RECOVERY;
r = sd_bus_open_system(&bus);
if (r < 0)
- goto fallback;
+ goto fail;
r = sd_bus_message_new_method_call(
bus,
return NSS_STATUS_NOTFOUND;
}
- if (bus_error_shall_fallback(&error))
- goto fallback;
+ if (!bus_error_shall_fallback(&error))
+ ret = NSS_STATUS_NOTFOUND;
- ret = NSS_STATUS_NOTFOUND;
goto fail;
}
return NSS_STATUS_SUCCESS;
-fallback:
- {
- _nss_gethostbyaddr2_r_t fallback;
-
- fallback = (_nss_gethostbyaddr2_r_t)
- find_fallback("libnss_dns.so.2", "_nss_dns_gethostbyaddr2_r");
-
- if (fallback)
- return fallback(addr, len, af, result, buffer, buflen, errnop, h_errnop, ttlp);
- }
-
fail:
*errnop = -r;
*h_errnop = NO_RECOVERY;