1@node Name Service Switch, Users and Groups, Job Control, Top 2@chapter System Databases and Name Service Switch 3@c %MENU% Accessing system databases 4@cindex Name Service Switch 5@cindex NSS 6@cindex databases 7 8Various functions in the C Library need to be configured to work 9correctly in the local environment. Traditionally, this was done by 10using files (e.g., @file{/etc/passwd}), but other nameservices (like the 11Network Information Service (NIS) and the Domain Name Service (DNS)) 12became popular, and were hacked into the C library, usually with a fixed 13search order. 14 15@Theglibc{} contains a cleaner solution to this problem. It is 16designed after a method used by Sun Microsystems in the C library of 17@w{Solaris 2}. @Theglibc{} follows their name and calls this 18scheme @dfn{Name Service Switch} (NSS). 19 20Though the interface might be similar to Sun's version there is no 21common code. We never saw any source code of Sun's implementation and 22so the internal interface is incompatible. This also manifests in the 23file names we use as we will see later. 24 25 26@menu 27* NSS Basics:: What is this NSS good for. 28* NSS Configuration File:: Configuring NSS. 29* NSS Module Internals:: How does it work internally. 30* Extending NSS:: What to do to add services or databases. 31@end menu 32 33@node NSS Basics, NSS Configuration File, Name Service Switch, Name Service Switch 34@section NSS Basics 35 36The basic idea is to put the implementation of the different services 37offered to access the databases in separate modules. This has some 38advantages: 39 40@enumerate 41@item 42Contributors can add new services without adding them to @theglibc{}. 43@item 44The modules can be updated separately. 45@item 46The C library image is smaller. 47@end enumerate 48 49To fulfill the first goal above, the ABI of the modules will be described 50below. For getting the implementation of a new service right it is 51important to understand how the functions in the modules get called. 52They are in no way designed to be used by the programmer directly. 53Instead the programmer should only use the documented and standardized 54functions to access the databases. 55 56@noindent 57The databases available in the NSS are 58 59@cindex aliases 60@cindex ethers 61@cindex group 62@cindex gshadow 63@cindex hosts 64@cindex initgroups 65@cindex netgroup 66@cindex networks 67@cindex passwd 68@cindex protocols 69@cindex publickey 70@cindex rpc 71@cindex services 72@cindex shadow 73@table @code 74@item aliases 75Mail aliases 76@comment @pxref{Mail Aliases}. 77@item ethers 78Ethernet numbers, 79@comment @pxref{Ethernet Numbers}. 80@item group 81Groups of users, @pxref{Group Database}. 82@item gshadow 83Group passphrase hashes and related information. 84@item hosts 85Host names and numbers, @pxref{Host Names}. 86@item initgroups 87Supplementary group access list. 88@item netgroup 89Network wide list of host and users, @pxref{Netgroup Database}. 90@item networks 91Network names and numbers, @pxref{Networks Database}. 92@item passwd 93User identities, @pxref{User Database}. 94@item protocols 95Network protocols, @pxref{Protocols Database}. 96@item publickey 97Public keys for Secure RPC. 98@item rpc 99Remote procedure call names and numbers. 100@comment @pxref{RPC Database}. 101@item services 102Network services, @pxref{Services Database}. 103@item shadow 104User passphrase hashes and related information. 105@comment @pxref{Shadow Passphrase Database}. 106@end table 107 108@noindent 109@c We currently don't implement automount, netmasks, or bootparams. 110More databases may be added later. 111 112@node NSS Configuration File, NSS Module Internals, NSS Basics, Name Service Switch 113@section The NSS Configuration File 114 115@cindex @file{/etc/nsswitch.conf} 116@cindex @file{nsswitch.conf} 117Somehow the NSS code must be told about the wishes of the user. For 118this reason there is the file @file{/etc/nsswitch.conf}. For each 119database, this file contains a specification of how the lookup process should 120work. The file could look like this: 121 122@example 123@include nsswitch.texi 124@end example 125 126The first column is the database as you can guess from the table above. 127The rest of the line specifies how the lookup process works. Please 128note that you specify the way it works for each database individually. 129This cannot be done with the old way of a monolithic implementation. 130 131The configuration specification for each database can contain two 132different items: 133 134@itemize @bullet 135@item 136the service specification like @code{files}, @code{db}, or @code{nis}. 137@item 138the reaction on lookup result like @code{[NOTFOUND=return]}. 139@end itemize 140 141@menu 142* Services in the NSS configuration:: Service names in the NSS configuration. 143* Actions in the NSS configuration:: React appropriately to the lookup result. 144* Notes on NSS Configuration File:: Things to take care about while 145 configuring NSS. 146@end menu 147 148@node Services in the NSS configuration, Actions in the NSS configuration, NSS Configuration File, NSS Configuration File 149@subsection Services in the NSS configuration File 150 151The above example file mentions five different services: @code{files}, 152@code{db}, @code{dns}, @code{nis}, and @code{nisplus}. This does not 153mean these 154services are available on all sites and neither does it mean these are 155all the services which will ever be available. 156 157In fact, these names are simply strings which the NSS code uses to find 158the implicitly addressed functions. The internal interface will be 159described later. Visible to the user are the modules which implement an 160individual service. 161 162Assume the service @var{name} shall be used for a lookup. The code for 163this service is implemented in a module called @file{libnss_@var{name}}. 164On a system supporting shared libraries this is in fact a shared library 165with the name (for example) @file{libnss_@var{name}.so.2}. The number 166at the end is the currently used version of the interface which will not 167change frequently. Normally the user should not have to be cognizant of 168these files since they should be placed in a directory where they are 169found automatically. Only the names of all available services are 170important. 171 172Lastly, some system software may make use of the NSS configuration file 173to store their own configuration for similar purposes. Examples of this 174include the @code{automount} service which is used by @code{autofs}. 175 176@node Actions in the NSS configuration, Notes on NSS Configuration File, Services in the NSS configuration, NSS Configuration File 177@subsection Actions in the NSS configuration 178 179The second item in the specification gives the user much finer control 180on the lookup process. Action items are placed between two service 181names and are written within brackets. The general form is 182 183@display 184@code{[} ( @code{!}? @var{status} @code{=} @var{action} )+ @code{]} 185@end display 186 187@noindent 188where 189 190@smallexample 191@var{status} @result{} success | notfound | unavail | tryagain 192@var{action} @result{} return | continue 193@end smallexample 194 195The case of the keywords is insignificant. The @var{status} 196values are the results of a call to a lookup function of a specific 197service. They mean: 198 199@ftable @samp 200@item success 201No error occurred and the wanted entry is returned. The default action 202for this is @code{return}. 203 204@item notfound 205The lookup process works ok but the needed value was not found. The 206default action is @code{continue}. 207 208@item unavail 209@cindex DNS server unavailable 210The service is permanently unavailable. This can either mean the needed 211file is not available, or, for DNS, the server is not available or does 212not allow queries. The default action is @code{continue}. 213 214@item tryagain 215The service is temporarily unavailable. This could mean a file is 216locked or a server currently cannot accept more connections. The 217default action is @code{continue}. 218@end ftable 219 220@noindent 221The @var{action} values mean: 222 223@ftable @samp 224@item return 225 226If the status matches, stop the lookup process at this service 227specification. If an entry is available, provide it to the application. 228If an error occurred, report it to the application. In case of a prior 229@samp{merge} action, the data is combined with previous lookup results, 230as explained below. 231 232@item continue 233 234If the status matches, proceed with the lookup process at the next 235entry, discarding the result of the current lookup (and any merged 236data). An exception is the @samp{initgroups} database and the 237@samp{success} status, where @samp{continue} acts like @code{merge} 238below. 239 240@item merge 241 242Proceed with the lookup process, retaining the current lookup result. 243This action is useful only with the @samp{success} status. If a 244subsequent service lookup succeeds and has a matching @samp{return} 245specification, the results are merged, the lookup process ends, and the 246merged results are returned to the application. If the following service 247has a matching @samp{merge} action, the lookup process continues, 248retaining the combined data from this and any previous lookups. 249 250After a @code{merge} action, errors from subsequent lookups are ignored, 251and the data gathered so far will be returned. 252 253The @samp{merge} only applies to the @samp{success} status. It is 254currently implemented for the @samp{group} database and its group 255members field, @samp{gr_mem}. If specified for other databases, it 256causes the lookup to fail (if the @var{status} matches). 257 258When processing @samp{merge} for @samp{group} membership, the group GID 259and name must be identical for both entries. If only one or the other is 260a match, the behavior is undefined. 261 262@end ftable 263 264@noindent 265If we have a line like 266 267@smallexample 268ethers: nisplus [NOTFOUND=return] db files 269@end smallexample 270 271@noindent 272this is equivalent to 273 274@smallexample 275ethers: nisplus [SUCCESS=return NOTFOUND=return UNAVAIL=continue 276 TRYAGAIN=continue] 277 db [SUCCESS=return NOTFOUND=continue UNAVAIL=continue 278 TRYAGAIN=continue] 279 files 280@end smallexample 281 282@noindent 283(except that it would have to be written on one line). The default 284value for the actions are normally what you want, and only need to be 285changed in exceptional cases. 286 287If the optional @code{!} is placed before the @var{status} this means 288the following action is used for all statuses but @var{status} itself. 289I.e., @code{!} is negation as in the C language (and others). 290 291Before we explain the exception which makes this action item necessary 292one more remark: obviously it makes no sense to add another action 293item after the @code{files} service. Since there is no other service 294following the action @emph{always} is @code{return}. 295 296@cindex nisplus, and completeness 297Now, why is this @code{[NOTFOUND=return]} action useful? To understand 298this we should know that the @code{nisplus} service is often 299complete; i.e., if an entry is not available in the NIS+ tables it is 300not available anywhere else. This is what is expressed by this action 301item: it is useless to examine further services since they will not give 302us a result. 303 304@cindex nisplus, and booting 305@cindex bootstrapping, and services 306The situation would be different if the NIS+ service is not available 307because the machine is booting. In this case the return value of the 308lookup function is not @code{notfound} but instead @code{unavail}. And 309as you can see in the complete form above: in this situation the 310@code{db} and @code{files} services are used. Neat, isn't it? The 311system administrator need not pay special care for the time the system 312is not completely ready to work (while booting or shutdown or 313network problems). 314 315 316@node Notes on NSS Configuration File, , Actions in the NSS configuration, NSS Configuration File 317@subsection Notes on the NSS Configuration File 318 319Finally a few more hints. The NSS implementation is not completely 320helpless if @file{/etc/nsswitch.conf} does not exist. For 321all supported databases there is a default value so it should normally 322be possible to get the system running even if the file is corrupted or 323missing. 324 325@cindex default value, and NSS 326For the @code{hosts} and @code{networks} databases the default value is 327@code{files dns}. I.e., local configuration will override the contents 328of the domain name system (DNS). 329 330The @code{passwd}, @code{group}, and @code{shadow} databases was 331traditionally handled in a special way. The appropriate files in the 332@file{/etc} directory were read but if an entry with a name starting 333with a @code{+} character was found NIS was used. This kind of lookup 334was removed and now the default value for the services is @code{files}. 335libnss_compat no longer depends on libnsl and can be used without NIS. 336 337For all other databases the default value is @code{files}. 338 339@cindex optimizing NSS 340A second point is that the user should try to optimize the lookup 341process. The different service have different response times. 342A simple file look up on a local file could be fast, but if the file 343is long and the needed entry is near the end of the file this may take 344quite some time. In this case it might be better to use the @code{db} 345service which allows fast local access to large data sets. 346 347Often the situation is that some global information like NIS must be 348used. So it is unavoidable to use service entries like @code{nis} etc. 349But one should avoid slow services like this if possible. 350 351 352@node NSS Module Internals, Extending NSS, NSS Configuration File, Name Service Switch 353@section NSS Module Internals 354 355Now it is time to describe what the modules look like. The functions 356contained in a module are identified by their names. I.e., there is no 357jump table or the like. How this is done is of no interest here; those 358interested in this topic should read about Dynamic Linking. 359@comment @ref{Dynamic Linking}. 360 361 362@menu 363* NSS Module Names:: Construction of the interface function of 364 the NSS modules. 365* NSS Modules Interface:: Programming interface in the NSS module 366 functions. 367@end menu 368 369@node NSS Module Names, NSS Modules Interface, NSS Module Internals, NSS Module Internals 370@subsection The Naming Scheme of the NSS Modules 371 372@noindent 373The name of each function consists of various parts: 374 375@quotation 376 _nss_@var{service}_@var{function} 377@end quotation 378 379@var{service} of course corresponds to the name of the module this 380function is found in.@footnote{Now you might ask why this information is 381duplicated. The answer is that we want to make it possible to link 382directly with these shared objects.} The @var{function} part is derived 383from the interface function in the C library itself. If the user calls 384the function @code{gethostbyname} and the service used is @code{files} 385the function 386 387@smallexample 388 _nss_files_gethostbyname_r 389@end smallexample 390 391@noindent 392in the module 393 394@smallexample 395 libnss_files.so.2 396@end smallexample 397 398@noindent 399@cindex reentrant NSS functions 400is used. You see, what is explained above in not the whole truth. In 401fact the NSS modules only contain reentrant versions of the lookup 402functions. I.e., if the user would call the @code{gethostbyname_r} 403function this also would end in the above function. For all user 404interface functions the C library maps this call to a call to the 405reentrant function. For reentrant functions this is trivial since the 406interface is (nearly) the same. For the non-reentrant version the 407library keeps internal buffers which are used to replace the user 408supplied buffer. 409 410I.e., the reentrant functions @emph{can} have counterparts. No service 411module is forced to have functions for all databases and all kinds to 412access them. If a function is not available it is simply treated as if 413the function would return @code{unavail} 414(@pxref{Actions in the NSS configuration}). 415 416The file name @file{libnss_files.so.2} would be on a @w{Solaris 2} 417system @file{nss_files.so.2}. This is the difference mentioned above. 418Sun's NSS modules are usable as modules which get indirectly loaded 419only. 420 421The NSS modules in @theglibc{} are prepared to be used as normal 422libraries themselves. This is @emph{not} true at the moment, though. 423However, the organization of the name space in the modules does not make it 424impossible like it is for Solaris. Now you can see why the modules are 425still libraries.@footnote{There is a second explanation: we were too 426lazy to change the Makefiles to allow the generation of shared objects 427not starting with @file{lib} but don't tell this to anybody.} 428 429 430@node NSS Modules Interface, , NSS Module Names, NSS Module Internals 431@subsection The Interface of the Function in NSS Modules 432 433Now we know about the functions contained in the modules. It is now 434time to describe the types. When we mentioned the reentrant versions of 435the functions above, this means there are some additional arguments 436(compared with the standard, non-reentrant versions). The prototypes for 437the non-reentrant and reentrant versions of our function above are: 438 439@smallexample 440struct hostent *gethostbyname (const char *name) 441 442int gethostbyname_r (const char *name, struct hostent *result_buf, 443 char *buf, size_t buflen, struct hostent **result, 444 int *h_errnop) 445@end smallexample 446 447@noindent 448The actual prototype of the function in the NSS modules in this case is 449 450@smallexample 451enum nss_status _nss_files_gethostbyname_r (const char *name, 452 struct hostent *result_buf, 453 char *buf, size_t buflen, 454 int *errnop, int *h_errnop) 455@end smallexample 456 457I.e., the interface function is in fact the reentrant function with the 458change of the return value, the omission of the @var{result} parameter, 459and the addition of the @var{errnop} parameter. While the user-level 460function returns a pointer to the result the reentrant function return 461an @code{enum nss_status} value: 462 463@vtable @code 464@item NSS_STATUS_TRYAGAIN 465numeric value @code{-2} 466 467@item NSS_STATUS_UNAVAIL 468numeric value @code{-1} 469 470@item NSS_STATUS_NOTFOUND 471numeric value @code{0} 472 473@item NSS_STATUS_SUCCESS 474numeric value @code{1} 475@end vtable 476 477@noindent 478Now you see where the action items of the @file{/etc/nsswitch.conf} file 479are used. 480 481If you study the source code you will find there is a fifth value: 482@code{NSS_STATUS_RETURN}. This is an internal use only value, used by a 483few functions in places where none of the above value can be used. If 484necessary the source code should be examined to learn about the details. 485 486In case the interface function has to return an error it is important 487that the correct error code is stored in @code{*@var{errnop}}. Some 488return status values have only one associated error code, others have 489more. 490 491@multitable @columnfractions .3 .2 .50 492@item 493@code{NSS_STATUS_TRYAGAIN} @tab 494 @code{EAGAIN} @tab One of the functions used ran temporarily out of 495resources or a service is currently not available. 496@item 497@tab 498 @code{ERANGE} @tab The provided buffer is not large enough. 499The function should be called again with a larger buffer. 500@item 501@code{NSS_STATUS_UNAVAIL} @tab 502 @code{ENOENT} @tab A necessary input file cannot be found. 503@item 504@code{NSS_STATUS_NOTFOUND} @tab 505 @code{ENOENT} @tab The requested entry is not available. 506 507@item 508@code{NSS_STATUS_NOTFOUND} @tab 509 @code{SUCCESS} @tab There are no entries. 510Use this to avoid returning errors for inactive services which may 511be enabled at a later time. This is not the same as the service 512being temporarily unavailable. 513@end multitable 514 515These are proposed values. There can be other error codes and the 516described error codes can have different meaning. @strong{With one 517exception:} when returning @code{NSS_STATUS_TRYAGAIN} the error code 518@code{ERANGE} @emph{must} mean that the user provided buffer is too 519small. Everything else is non-critical. 520 521In statically linked programs, the main application and NSS modules do 522not share the same thread-local variable @code{errno}, which is the 523reason why there is an explicit @var{errnop} function argument. 524 525The above function has something special which is missing for almost all 526the other module functions. There is an argument @var{h_errnop}. This 527points to a variable which will be filled with the error code in case 528the execution of the function fails for some reason. (In statically 529linked programs, the thread-local variable @code{h_errno} is not shared 530with the main application.) 531 532The @code{get@var{XXX}by@var{YYY}} functions are the most important 533functions in the NSS modules. But there are others which implement 534the other ways to access system databases (say for the 535user database, there are @code{setpwent}, @code{getpwent}, and 536@code{endpwent}). These will be described in more detail later. 537Here we give a general way to determine the 538signature of the module function: 539 540@itemize @bullet 541@item 542the return value is @code{enum nss_status}; 543@item 544the name (@pxref{NSS Module Names}); 545@item 546the first arguments are identical to the arguments of the non-reentrant 547function; 548@item 549the next four arguments are: 550 551@table @code 552@item STRUCT_TYPE *result_buf 553pointer to buffer where the result is stored. @code{STRUCT_TYPE} is 554normally a struct which corresponds to the database. 555@item char *buffer 556pointer to a buffer where the function can store additional data for 557the result etc. 558@item size_t buflen 559length of the buffer pointed to by @var{buffer}. 560@item int *errnop 561the low-level error code to return to the application. If the return 562value is not @code{NSS_STATUS_SUCCESS}, @code{*@var{errnop}} needs to be 563set to a non-zero value. An NSS module should never set 564@code{*@var{errnop}} to zero. The value @code{ERANGE} is special, as 565described above. 566@end table 567 568@item 569possibly a last argument @var{h_errnop}, for the host name and network 570name lookup functions. If the return value is not 571@code{NSS_STATUS_SUCCESS}, @code{*@var{h_errnop}} needs to be set to a 572non-zero value. A generic error code is @code{NETDB_INTERNAL}, which 573instructs the caller to examine @code{*@var{errnop}} for further 574details. (This includes the @code{ERANGE} special case.) 575@end itemize 576 577@noindent 578This table is correct for all functions but the @code{set@dots{}ent} 579and @code{end@dots{}ent} functions. 580 581 582@node Extending NSS, , NSS Module Internals, Name Service Switch 583@section Extending NSS 584 585One of the advantages of NSS mentioned above is that it can be extended 586quite easily. There are two ways in which the extension can happen: 587adding another database or adding another service. The former is 588normally done only by the C library developers. It is 589here only important to remember that adding another database is 590independent from adding another service because a service need not 591support all databases or lookup functions. 592 593A designer/implementer of a new service is therefore free to choose the 594databases s/he is interested in and leave the rest for later (or 595completely aside). 596 597@menu 598* Adding another Service to NSS:: What is to do to add a new service. 599* NSS Module Function Internals:: Guidelines for writing new NSS 600 service functions. 601@end menu 602 603@node Adding another Service to NSS, NSS Module Function Internals, Extending NSS, Extending NSS 604@subsection Adding another Service to NSS 605 606The sources for a new service need not (and should not) be part of @theglibc{} 607itself. The developer retains complete control over the 608sources and its development. The links between the C library and the 609new service module consists solely of the interface functions. 610 611Each module is designed following a specific interface specification. 612For now the version is 2 (the interface in version 1 was not adequate) 613and this manifests in the version number of the shared library object of 614the NSS modules: they have the extension @code{.2}. If the interface 615changes again in an incompatible way, this number will be increased. 616Modules using the old interface will still be usable. 617 618Developers of a new service will have to make sure that their module is 619created using the correct interface number. This means the file itself 620must have the correct name and on ELF systems the @dfn{soname} (Shared 621Object Name) must also have this number. Building a module from a bunch 622of object files on an ELF system using GNU CC could be done like this: 623 624@smallexample 625gcc -shared -o libnss_NAME.so.2 -Wl,-soname,libnss_NAME.so.2 OBJECTS 626@end smallexample 627 628@noindent 629@ref{Link Options, Options for Linking, , gcc, GNU CC}, to learn 630more about this command line. 631 632To use the new module the library must be able to find it. This can be 633achieved by using options for the dynamic linker so that it will search 634the directory where the binary is placed. For an ELF system this could be 635done by adding the wanted directory to the value of 636@code{LD_LIBRARY_PATH}. 637 638But this is not always possible since some programs (those which run 639under IDs which do not belong to the user) ignore this variable. 640Therefore the stable version of the module should be placed into a 641directory which is searched by the dynamic linker. Normally this should 642be the directory @file{$prefix/lib}, where @file{$prefix} corresponds to 643the value given to configure using the @code{--prefix} option. But be 644careful: this should only be done if it is clear the module does not 645cause any harm. System administrators should be careful. 646 647 648@node NSS Module Function Internals, , Adding another Service to NSS, Extending NSS 649@subsection Internals of the NSS Module Functions 650 651Until now we only provided the syntactic interface for the functions in 652the NSS module. In fact there is not much more we can say since the 653implementation obviously is different for each function. But a few 654general rules must be followed by all functions. 655 656In fact there are four kinds of different functions which may appear in 657the interface. All derive from the traditional ones for system databases. 658@var{db} in the following table is normally an abbreviation for the 659database (e.g., it is @code{pw} for the user database). 660 661@table @code 662@item enum nss_status _nss_@var{database}_set@var{db}ent (void) 663This function prepares the service for following operations. For a 664simple file based lookup this means files could be opened, for other 665services this function simply is a noop. 666 667One special case for this function is that it takes an additional 668argument for some @var{database}s (i.e., the interface is 669@code{int set@var{db}ent (int)}). @ref{Host Names}, which describes the 670@code{sethostent} function. 671 672The return value should be @var{NSS_STATUS_SUCCESS} or according to the 673table above in case of an error (@pxref{NSS Modules Interface}). 674 675@item enum nss_status _nss_@var{database}_end@var{db}ent (void) 676This function simply closes all files which are still open or removes 677buffer caches. If there are no files or buffers to remove this is again 678a simple noop. 679 680There normally is no return value other than @var{NSS_STATUS_SUCCESS}. 681 682@item enum nss_status _nss_@var{database}_get@var{db}ent_r (@var{STRUCTURE} *result, char *buffer, size_t buflen, int *errnop) 683Since this function will be called several times in a row to retrieve 684one entry after the other it must keep some kind of state. But this 685also means the functions are not really reentrant. They are reentrant 686only in that simultaneous calls to this function will not try to 687write the retrieved data in the same place (as it would be the case for 688the non-reentrant functions); instead, it writes to the structure 689pointed to by the @var{result} parameter. But the calls share a common 690state and in the case of a file access this means they return neighboring 691entries in the file. 692 693The buffer of length @var{buflen} pointed to by @var{buffer} can be used 694for storing some additional data for the result. It is @emph{not} 695guaranteed that the same buffer will be passed for the next call of this 696function. Therefore one must not misuse this buffer to save some state 697information from one call to another. 698 699Before the function returns with a failure code, the implementation 700should store the value of the local @code{errno} variable in the variable 701pointed to be @var{errnop}. This is important to guarantee the module 702working in statically linked programs. The stored value must not be 703zero. 704 705As explained above this function could also have an additional last 706argument. This depends on the database used; it happens only for 707@code{host} and @code{networks}. 708 709The function shall return @code{NSS_STATUS_SUCCESS} as long as there are 710more entries. When the last entry was read it should return 711@code{NSS_STATUS_NOTFOUND}. When the buffer given as an argument is too 712small for the data to be returned @code{NSS_STATUS_TRYAGAIN} should be 713returned. When the service was not formerly initialized by a call to 714@code{_nss_@var{DATABASE}_set@var{db}ent} all return values allowed for 715this function can also be returned here. 716 717@item enum nss_status _nss_@var{DATABASE}_get@var{db}by@var{XX}_r (@var{PARAMS}, @var{STRUCTURE} *result, char *buffer, size_t buflen, int *errnop) 718This function shall return the entry from the database which is 719addressed by the @var{PARAMS}. The type and number of these arguments 720vary. It must be individually determined by looking to the user-level 721interface functions. All arguments given to the non-reentrant version 722are here described by @var{PARAMS}. 723 724The result must be stored in the structure pointed to by @var{result}. 725If there are additional data to return (say strings, where the 726@var{result} structure only contains pointers) the function must use the 727@var{buffer} of length @var{buflen}. There must not be any references 728to non-constant global data. 729 730The implementation of this function should honor the @var{stayopen} 731flag set by the @code{set@var{DB}ent} function whenever this makes sense. 732 733Before the function returns, the implementation should store the value of 734the local @code{errno} variable in the variable pointed to by 735@var{errnop}. This is important to guarantee the module works in 736statically linked programs. 737 738Again, this function takes an additional last argument for the 739@code{host} and @code{networks} database. 740 741The return value should as always follow the rules given above 742(@pxref{NSS Modules Interface}). 743 744@end table 745