From 84b6b469cfb65acc1b344ec92a1dd572bd99d9ac Mon Sep 17 00:00:00 2001 From: Philippe Houdoin Date: Sun, 5 Apr 2026 23:53:47 +0200 Subject: [PATCH] libnetwork: add support for /boot/system/settings/network/nsswitch.conf This open opportunity to use extra netresolv's nsswitch modules, like libnss_mdns.so, for zeroconf .local names resolution. Change-Id: If71fc47d7ab066e99daa97d453e70dddc3449f71 Reviewed-on: https://review.haiku-os.org/c/haiku/+/10667 Tested-by: Commit checker robot Reviewed-by: nephele nephele --- .../libnetwork/netresolv/include/nsswitch.h | 15 +++++++++ .../libnetwork/netresolv/net/nsdispatch.c | 33 +++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/system/libnetwork/netresolv/include/nsswitch.h b/src/system/libnetwork/netresolv/include/nsswitch.h index 4266494ebf..e2961b2949 100644 --- a/src/system/libnetwork/netresolv/include/nsswitch.h +++ b/src/system/libnetwork/netresolv/include/nsswitch.h @@ -38,10 +38,20 @@ #define NSS_MODULE_INTERFACE_VERSION 0 +#ifdef __HAIKU__ + +/* Yacc generated nsparser.y needs _PATH_NS_CONF for error reporting purpose */ +#undef _PATH_NS_CONF +#define _PATH_NS_CONF nsswitch_conf_file_path() + +#else + #ifndef _PATH_NS_CONF #define _PATH_NS_CONF "/etc/nsswitch.conf" #endif +#endif + #define NS_CONTINUE 0 #define NS_RETURN 1 @@ -215,6 +225,11 @@ typedef struct { #include __BEGIN_DECLS + +#ifdef __HAIKU__ +char * nsswitch_conf_file_path(void); +#endif + int nsdispatch(void *, const ns_dtab [], const char *, const char *, const ns_src [], ...); diff --git a/src/system/libnetwork/netresolv/net/nsdispatch.c b/src/system/libnetwork/netresolv/net/nsdispatch.c index c84d4c950d..19a92d3de6 100644 --- a/src/system/libnetwork/netresolv/net/nsdispatch.c +++ b/src/system/libnetwork/netresolv/net/nsdispatch.c @@ -87,8 +87,17 @@ __RCSID("$NetBSD: nsdispatch.c,v 1.37 2012/03/13 21:13:42 christos Exp $"); #include +#ifdef __HAIKU__ + +#include +int __isthreaded = 1; + +#else + #define __isthreaded 1 +#endif + extern FILE *_nsyyin; extern int _nsyyparse(void); @@ -179,7 +188,12 @@ static pthread_mutex_t _ns_drec_lock = PTHREAD_MUTEX_INITIALIZER; /* * Runtime determination of whether we are dynamically linked or not. */ + +#ifdef __HAIKU__ +#define is_dynamic() (1) /* accept to load dynamic NSS modules */ +#else #define is_dynamic() (0) /* don't bother - switch to ELF! */ +#endif /* @@ -478,6 +492,19 @@ _nsdbtput(const ns_dbt *dbt) return (0); } +#ifdef __HAIKU__ + +char * +nsswitch_conf_file_path(void) +{ + static char path[256]; + find_directory(B_SYSTEM_SETTINGS_DIRECTORY, 0, false, path, sizeof(path)); + strlcat(path, "/network/nsswitch.conf", sizeof(path)); + return path; +} + +#endif + /* * This function is called each time nsdispatch() is called. If this * is the first call, or if the configuration has changed, (re-)prepare @@ -492,9 +519,11 @@ _nsconfigure(void) static time_t _nsconfmod; struct stat statbuf; + char * path = nsswitch_conf_file_path(); + pthread_mutex_lock(&_nsconflock); - if (stat(_PATH_NS_CONF, &statbuf) == -1) { + if (stat(path, &statbuf) == -1) { /* * No nsswitch.conf; just use whatever configuration we * currently have, or fall back on the defaults specified @@ -521,7 +550,7 @@ _nsconfigure(void) */ pthread_rwlock_wrlock(&_nslock); - _nsyyin = fopen(_PATH_NS_CONF, "r"); + _nsyyin = fopen(path, "r"); if (_nsyyin == NULL) { /* * Unable to open nsswitch.conf; behave as though the