YPCLNT(3NSL) | Networking Services Library Functions | YPCLNT(3NSL) |
ypclnt, yp_get_default_domain, yp_bind, yp_unbind, yp_match, yp_first, yp_next, yp_all, yp_order, yp_master, yperr_string, ypprot_err - NIS Version 2 client interface
cc [ -flag... ] file... -lnsl [ library...] #include <rpcsvc/ypclnt.h> #include <rpcsvc/yp_prot.h> int yp_bind(char *indomain);
void yp_unbind (char *indomain);
int yp_get_default_domain(char **outdomain);
int yp_match(char *indomain, char *inmap, char *inkey, int inkeylen,
char *char **outval, int *outvallen);
int yp_first(char *indomain, char *inmap, char **outkey, int *outkeylen,
char **outval, int *outvallen);
int yp_next(char *indomain, char *inmap, char *inkey, int *inkeylen,
char **outkey, int *outkeylen, char **outval,
int *outvallen);
int yp_all(char *indomain, char *inmap, struct ypall_callback *incallback);
int yp_order(char *indomain, char *inmap, unsigned long *outorder);
int yp_master(char *indomain, char *inmap, char **outname);
char *yperr_string(int incode);
int ypprot_err(char *domain);
This package of functions provides an interface to NIS, Network Information Service Version 2, formerly referred to as YP. For commands used to access NIS from a client machine, see ypbind(8), ypwhich(1), ypmatch(1), and ypcat(1). The package can be loaded from the standard library, /usr/lib/libnsl.so.1.
All input parameter names begin with in. Output parameters begin with out. Output parameters of type char ** should be addresses of uninitialized character pointers. Memory is allocated by the NIS client package using malloc(3C) and can be freed by the user code if it has no continuing need for it. For each outkey and outval, two extra bytes of memory are allocated at the end that contain NEWLINE and null, respectively, but these two bytes are not reflected in outkeylen or outvallen. The indomain and inmap strings must be non-null and null-terminated. String parameters that are accompanied by a count parameter may not be null, but they may point to null strings, with the count parameter indicating this. Counted strings need not be null-terminated.
All functions in this package of type int return 0 if they succeed. Otherwise, they return a failure code (YPERR_xxxx). Failure codes are described in the ERRORS section.
yp_bind()
yp_unbind()
If an RPC failure results upon use of a binding, that domain will be unbound automatically. At that point, the ypclnt() layer will retry a few more times or until the operation succeeds, provided that rpcbind(8) and ypbind(8) are running, and either:
Under the following circumstances, the ypclnt layer will return control to the user code, with either an error or success code and the results:
yp_get_default_domain()
yp_match()
yp_first()
yp_next()
The concept of first and next is particular to the structure of the NIS map being processed. Retrieval order is not related to either the lexical order within any original (non-NIS name service) data base, or to any obvious numerical sorting order on the keys, values, or key-value pairs. The only ordering guarantee is that if the yp_first() function is called on a particular map, and then the yp_next() function is repeatedly called on the same map at the same server until the call fails with a reason of YPERR_NOMORE, every entry in the data base is seen exactly once. Further, if the same sequence of operations is performed on the same map at the same server, the entries are seen in the same order.
Under conditions of heavy server load or server failure, the domain can become unbound, then bound once again (perhaps to a different server) while a client is running. This binding can cause a break in one of the enumeration rules. Specific entries may be seen twice by the client, or not at all. This approach protects the client from error messages that would otherwise be returned in the midst of the enumeration. For a better solution to enumerating all entries in a map, see yp_all().
yp_all()
The third parameter to yp_all() is:
struct ypall_callback *incallback { int (*foreach)(); char *data; };
The function foreach() is called:
foreach(int instatus, char *inkey, int inkeylen, char *inval, int invallen, char *indata);
The instatus parameter holds one of the return status values defined in <rpcsvc/yp_prot.h>, either YP_TRUE or an error code. See ypprot_err(), for a function that converts an NIS name service protocol error code to a ypclnt layer error code.
The key and value parameters are somewhat different than defined in the synopsis section above. First, the memory pointed to by the inkey and inval parameters is private to the yp_all() function, and is overwritten with the arrival of each new key-value pair. The foreach() function must do something useful with the contents of that memory, but it does not own the memory itself. Key and value objects presented to the foreach() function look exactly as they do in the server's map. If they were not NEWLINE-terminated or null-terminated in the map, they would not be here either.
The indata parameter is the contents of the incallback->data element passed to yp_all(). The data element of the callback structure can be used to share state information between the foreach() function and the mainline code. Its use is optional, and no part of the NIS client package inspects its contents; cast it to something useful, or ignore it. The foreach() function is Boolean. It should return 0 to indicate that it wants to be called again for further received key-value pairs, or non-zero to stop the flow of key-value pairs. If foreach() returns a non-zero value, it is not called again. The functional value of yp_all() is then 0.
yp_order()
yp_master()
yperr_string()
ypprot_err()
All integer functions return 0 if the requested operation is successful, or one of the following errors if the operation fails:
YPERR_ACCESS
YPERR_BADARGS
YPERR_BADDB
YPERR_BUSY
YPERR_DOMAIN
YPERR_KEY
YPERR_MAP
YPERR_NODOM
YPERR_NOMORE
YPERR_PMAP
YPERR_RESRC
YPERR_RPC
YPERR_YPBIND
YPERR_YPERR
YPERR_YPSERV
YPERR_VERS
/usr/lib/libnsl.so.1
See attributes(7) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
MT-Level | Safe |
ypcat(1), ypmatch(1), ypwhich(1), sysinfo(2), malloc(3C), ypfiles(5), attributes(7), rpcbind(8), ypbind(8), ypserv(8)
February 17, 2023 | OmniOS |