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 <[email protected]>
Reviewed-by: nephele nephele <[email protected]>
This commit is contained in:
Philippe Houdoin
2026-04-11 11:45:52 +00:00
parent 730f8fe6a2
commit 84b6b469cf
2 changed files with 46 additions and 2 deletions
@@ -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 <sys/cdefs.h>
__BEGIN_DECLS
#ifdef __HAIKU__
char * nsswitch_conf_file_path(void);
#endif
int nsdispatch(void *, const ns_dtab [], const char *,
const char *, const ns_src [], ...);
@@ -87,8 +87,17 @@ __RCSID("$NetBSD: nsdispatch.c,v 1.37 2012/03/13 21:13:42 christos Exp $");
#include <libutil.h>
#ifdef __HAIKU__
#include <FindDirectory.h>
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