NSDISPATCH(3)
NSDISPATCH(3) β name-service switch dispatcher routine π
okay bestie, this is the Library Functions Manual page for nsdispatch(3), and it is literally the name-service switch dispatcher routine. Itβs giving βlibc matchmaker for name-service databasesβ energy, and weβre gonna read every detail together. π«Ά
π NAME π
nsdispatch β name-service switch dispatcher routine
πΈ LIBRARY πΈ
Standard C Library (libc, -lc). Yes, that one. π
β¨ SYNOPSIS β¨
#include <sys/types.h>
#include <stdarg.h>
#include <nsswitch.h>
int
nsdispatch(void *retval, const ns_dtab dtab[], const char *database,
const char *method_name, const ns_src defaults[], ...);
π¦ DESCRIPTION π¦
The nsdispatch() function invokes the methods specified in dtab in the order given by nsswitch.conf(5) for the database database until a successful entry is found. Slay. π
retval is passed to each method to modify as necessary, to pass back results to the caller of nsdispatch().
Each method has the function signature described by the typedef:
typedef int (*nss_method)(void *retval, void *mdata, va_list *ap);
dtab is an array of ns_dtab structures, which have the following format:
typedef struct _ns_dtab {
const char *src;
nss_method method;
void *mdata;
} ns_dtab;
The dtab array should consist of one entry for each source type that is implemented, with src as the name of the source, method as a function which handles that source, and mdata as a handle on arbitrary data to be passed to the method. The last entry in dtab should contain NULL values for src, method, and mdata.
Additionally, methods may be implemented in NSS modules, in which case they are selected using the database and method_name arguments along with the configured source. Modules must use source names different from the built-in ones.
defaults contains a list of default sources to try if nsswitch.conf(5) is missing or corrupted, or if there is no relevant entry for database. It is an array of ns_src structures, which have the following format:
typedef struct _ns_src {
const char *src;
uint32_t flags;
} ns_src;
The defaults array should consist of one entry for each source to be configured by default indicated by src, and flags set to the criterion desired (usually NS_SUCCESS; refer to βMethod return valuesβ for more information). The last entry in defaults should have src set to NULL and flags set to 0.
For convenience, a global variable defined as:
extern const ns_src __nsdefaultsrc[];
exists which contains a single default entry for the source files that may be used by callers which do not require complicated default rules.
... are optional extra arguments, which are passed to the appropriate method as a variable argument list of the type va_list.
π« Valid source types π«
While there is support for arbitrary sources, the following #defines for commonly implemented sources are available:
#define value
NSSRC_FILES "files"
NSSRC_DB "db"
NSSRC_DNS "dns"
NSSRC_NIS "nis"
NSSRC_COMPAT "compat"
Refer to nsswitch.conf(5) for a complete description of what each source type is.
π₯ Method return values π₯
The nss_method functions must return one of the following values depending upon status of the lookup. Hereβs the mapping, bestie:
NS_SUCCESSβsuccessNS_NOTFOUNDβnotfoundNS_UNAVAILβunavailNS_TRYAGAINβtryagainNS_RETURNβ-none-
Refer to nsswitch.conf(5) for a complete description of each status code.
The nsdispatch() function returns the value of the method that caused the dispatcher to terminate, or NS_NOTFOUND otherwise.
π«Ά NOTES π«Ά
FreeBSD's Standard C Library (libc, -lc) provides stubs for compatibility with NSS modules written for the GNU C Library nsswitch interface. However, these stubs only support the use of the βpasswdβ and βgroupβ databases.
π SEE ALSO π
π HISTORY π
The nsdispatch() function first appeared in FreeBSD 5.0. It was imported from the NetBSD Project, where it appeared first in NetBSD 1.4. Support for NSS modules first appeared in FreeBSD 5.1.
π AUTHORS π
Luke Mewburn <lukem@netbsd.org> wrote this freely-distributable name-service switch implementation, using ideas from the ULTRIX svc.conf(5) and Solaris nsswitch.conf(4) manual pages. The FreeBSD Project added the support for threads and NSS modules, and normalized the uses of nsdispatch() within the standard C library.
okay bestie, thatβs the whole page π Source/version: Debian; date: October 15, 2018. Periodt. π β¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms