Node:NSS Module Function Internals, Previous:Adding another Service to NSS, Up:Extending NSS
Until now we only provided the syntactic interface for the functions in the NSS module. In fact there is not much more we can say since the implementation obviously is different for each function. But a few general rules must be followed by all functions.
In fact there are four kinds of different functions which may appear in
the interface. All derive from the traditional ones for system databases.
db in the following table is normally an abbreviation for the
database (e.g., it is pw
for the password database).
enum nss_status _nss_database_setdbent (void)
One special case for this function is that it takes an additional
argument for some databases (i.e., the interface is
int setdbent (int)
). Host Names, which describes the
sethostent
function.
The return value should be NSS_STATUS_SUCCESS or according to the
table above in case of an error (see NSS Modules Interface).
enum nss_status _nss_database_enddbent (void)
There normally is no return value different to NSS_STATUS_SUCCESS.
enum nss_status _nss_database_getdbent_r (STRUCTURE *result, char *buffer, size_t buflen, int *errnop)
The buffer of length buflen pointed to by buffer can be used for storing some additional data for the result. It is not guaranteed that the same buffer will be passed for the next call of this function. Therefore one must not misuse this buffer to save some state information from one call to another.
Before the function returns the implementation should store the value of the local errno variable in the variable pointed to be errnop. This is important to guarantee the module working in statically linked programs.
As explained above this function could also have an additional last
argument. This depends on the database used; it happens only for
host
and networks
.
The function shall return NSS_STATUS_SUCCESS
as long as there are
more entries. When the last entry was read it should return
NSS_STATUS_NOTFOUND
. When the buffer given as an argument is too
small for the data to be returned NSS_STATUS_TRYAGAIN
should be
returned. When the service was not formerly initialized by a call to
_nss_DATABASE_setdbent
all return value allowed for
this function can also be returned here.
enum nss_status _nss_DATABASE_getdbbyXX_r (PARAMS, STRUCTURE *result, char *buffer, size_t buflen, int *errnop)
The result must be stored in the structure pointed to by result. If there is additional data to return (say strings, where the result structure only contains pointers) the function must use the buffer or length buflen. There must not be any references to non-constant global data.
The implementation of this function should honor the stayopen
flag set by the setDBent
function whenever this makes sense.
Before the function returns the implementation should store the value of the local errno variable in the variable pointed to be errnop. This is important to guarantee the module working in statically linked programs.
Again, this function takes an additional last argument for the
host
and networks
database.
The return value should as always follow the rules given above (see NSS Modules Interface).