1*8b2238e1Sjmc.\" $OpenBSD: yp_bind.3,v 1.2 2020/12/03 22:47:21 jmc Exp $ 24523e709Sderaadt.\" 34523e709Sderaadt.\" Copyright (c) 1996 The NetBSD Foundation, Inc. 44523e709Sderaadt.\" All rights reserved. 54523e709Sderaadt.\" 64523e709Sderaadt.\" This code is derived from software contributed to The NetBSD Foundation 74523e709Sderaadt.\" by Jason R. Thorpe. 84523e709Sderaadt.\" 94523e709Sderaadt.\" Redistribution and use in source and binary forms, with or without 104523e709Sderaadt.\" modification, are permitted provided that the following conditions 114523e709Sderaadt.\" are met: 124523e709Sderaadt.\" 1. Redistributions of source code must retain the above copyright 134523e709Sderaadt.\" notice, this list of conditions and the following disclaimer. 144523e709Sderaadt.\" 2. Redistributions in binary form must reproduce the above copyright 154523e709Sderaadt.\" notice, this list of conditions and the following disclaimer in the 164523e709Sderaadt.\" documentation and/or other materials provided with the distribution. 174523e709Sderaadt.\" 184523e709Sderaadt.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 194523e709Sderaadt.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 204523e709Sderaadt.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 214523e709Sderaadt.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE 224523e709Sderaadt.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 234523e709Sderaadt.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 244523e709Sderaadt.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 254523e709Sderaadt.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 264523e709Sderaadt.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 274523e709Sderaadt.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 284523e709Sderaadt.\" POSSIBILITY OF SUCH DAMAGE. 294523e709Sderaadt.\" 30*8b2238e1Sjmc.Dd $Mdocdate: December 3 2020 $ 314523e709Sderaadt.Dt YP_BIND 3 324523e709Sderaadt.Os 334523e709Sderaadt.Sh NAME 344523e709Sderaadt.Nm yp_all , 354523e709Sderaadt.Nm yp_bind , 364523e709Sderaadt.Nm yp_first , 374523e709Sderaadt.Nm yp_get_default_domain , 384523e709Sderaadt.Nm yp_maplist , 394523e709Sderaadt.Nm yp_master , 404523e709Sderaadt.Nm yp_match , 414523e709Sderaadt.Nm yp_next , 424523e709Sderaadt.Nm yp_order , 434523e709Sderaadt.Nm yp_unbind , 444523e709Sderaadt.Nm yperr_string , 454523e709Sderaadt.Nm ypprot_err 464523e709Sderaadt.Nd Interface to the YP subsystem 474523e709Sderaadt.Sh SYNOPSIS 484523e709Sderaadt.In sys/types.h 494523e709Sderaadt.In rpc/rpc.h 504523e709Sderaadt.In rpcsvc/ypclnt.h 514523e709Sderaadt.In rpcsvc/yp_prot.h 524523e709Sderaadt.Ft int 534523e709Sderaadt.Fn yp_all "char *indomain" "char *inmap" "struct ypall_callback *incallback" 544523e709Sderaadt.Ft int 554523e709Sderaadt.Fn yp_bind "char *dom" 564523e709Sderaadt.Ft int 574523e709Sderaadt.Fn yp_first "char *indomain" "char *inmap" "char **outkey" "int *outkeylen" "char **outval" "int *outvallen" 584523e709Sderaadt.Ft int 594523e709Sderaadt.Fn yp_get_default_domain "char **domp" 604523e709Sderaadt.Ft int 614523e709Sderaadt.Fn yp_maplist "char *indomain" "struct ypmaplist **outmaplist" 624523e709Sderaadt.Ft int 634523e709Sderaadt.Fn yp_master "char *indomain" "char *inmap" "char **outname" 644523e709Sderaadt.Ft int 654523e709Sderaadt.Fn yp_match "char *indomain" "char *inmap" "const char *inkey" "int inkeylen" "char **outval" "int *outvallen" 664523e709Sderaadt.Ft int 674523e709Sderaadt.Fn yp_next "char *indomain" "char *inmap" "char *inkey" "int inkeylen" "char **outkey" "int *outkeylen" "char **outval" "int *outvallen" 684523e709Sderaadt.Ft int 694523e709Sderaadt.Fn yp_order "char *indomain" "char *inmap" "char *outorder" 704523e709Sderaadt.Ft void 714523e709Sderaadt.Fn yp_unbind "char *dom" 724523e709Sderaadt.Ft char * 734523e709Sderaadt.Fn yperr_string "int incode" 744523e709Sderaadt.Ft int 754523e709Sderaadt.Fn ypprot_err "unsigned int incode" 764523e709Sderaadt.Sh DESCRIPTION 774523e709SderaadtThis function suite provides an interface to the YP subsystem. 784523e709SderaadtFor a general description of the YP subsystem, see 794523e709Sderaadt.Xr yp 8 . 804523e709Sderaadt.Pp 814523e709SderaadtFor all functions, input values begin with 824523e709Sderaadt.Sq in 834523e709Sderaadtand output values begin with 844523e709Sderaadt.Sq out . 854523e709SderaadtAny output values of type 864523e709Sderaadt.Em char ** 874523e709Sderaadtshould be the addresses of uninitialized character pointers. 884523e709SderaadtOnly if a call succeeds will memory be allocated by the YP client routines 894523e709Sderaadtusing 904523e709Sderaadt.Fn malloc . 914523e709SderaadtThis memory can later be freed by the user if there is no additional need for 924523e709Sderaadtthe data stored there. 934523e709SderaadtFor 944523e709Sderaadt.Fa outkey 954523e709Sderaadtand 964523e709Sderaadt.Fa outval , 974523e709Sderaadttwo extra bytes of memory are allocated for a 984523e709Sderaadt.Ql \en 994523e709Sderaadtand 1004523e709Sderaadt.Ql \e0 , 1014523e709Sderaadtwhich are not 1024523e709Sderaadtreflected in the values of 1034523e709Sderaadt.Fa outkeylen 1044523e709Sderaadtor 1054523e709Sderaadt.Fa outvallen . 1064523e709SderaadtAll occurrences of 1074523e709Sderaadt.Fa indomain 1084523e709Sderaadtand 1094523e709Sderaadt.Fa inmap 1104523e709Sderaadtmust be non-null, NUL-terminated strings. 1114523e709SderaadtAll input strings which also have 1124523e709Sderaadta corresponding length parameter cannot be null unless the corresponding 1134523e709Sderaadtlength value is zero. 1144523e709SderaadtSuch strings need not be NUL-terminated. 1154523e709Sderaadt.Pp 1164523e709SderaadtAll YP lookup calls (the functions 1174523e709Sderaadt.Fn yp_all , 1184523e709Sderaadt.Fn yp_first , 1194523e709Sderaadt.Fn yp_master , 1204523e709Sderaadt.Fn yp_match , 1214523e709Sderaadt.Fn yp_next , 1224523e709Sderaadt.Fn yp_order ) 1234523e709Sderaadtrequire a YP domain name and a YP map name. 1244523e709SderaadtThe default domain name may be obtained by calling 1254523e709Sderaadt.Fn yp_get_default_domain , 1264523e709Sderaadtand should thus be used before all other YP calls in a client program. 1274523e709SderaadtThe value it places 1284523e709Sderaadt.Fa outdomain 1294523e709Sderaadtis suitable for use as the 1304523e709Sderaadt.Fa indomain 1314523e709Sderaadtparameter to all subsequent YP calls. 1324523e709Sderaadt.Pp 1334523e709SderaadtIn order for YP lookup calls to succeed, the client process must be bound 1344523e709Sderaadtto a YP server process. 1354523e709SderaadtThe client process need not explicitly bind to the server, as it happens 1364523e709Sderaadtautomatically whenever a lookup occurs. 1374523e709SderaadtThe function 1384523e709Sderaadt.Fn yp_bind 1394523e709Sderaadtis provided for a backup strategy, e.g., a local file, when a YP server process 1404523e709Sderaadtis not available. 1414523e709SderaadtEach binding uses one socket descriptor on the client process, which may 1424523e709Sderaadtbe explicitly freed using 1434523e709Sderaadt.Fn yp_unbind , 1444523e709Sderaadtwhich frees all per-process and per-node resources to bind the domain and 1454523e709Sderaadtmarks the domain unbound. 1464523e709Sderaadt.Pp 1474523e709SderaadtIf, during a YP lookup, an RPC failure occurs, the domain used in the lookup 1484523e709Sderaadtis automatically marked unbound and the layer retries the lookup as long as 1494523e709Sderaadt.Xr ypbind 8 1504523e709Sderaadtis running and either the client process cannot bind to a server for the domain 1514523e709Sderaadtspecified in the lookup, or RPC requests to the YP server process fail. 1524523e709SderaadtIf an error is not RPC-related, one of the YP error codes described below 1534523e709Sderaadtis returned and control given back to the user code. 1544523e709Sderaadt.Pp 1554523e709SderaadtThe suite provides the following functionality: 1564523e709Sderaadt.Bl -tag -width "yperr_string()" 1574523e709Sderaadt.It Fn yp_match 1584523e709SderaadtProvides the value associated with the given key. 1594523e709Sderaadt.It Fn yp_first 1604523e709SderaadtProvides the first key-value pair from the given map in the named domain. 1614523e709Sderaadt.It Fn yp_next 1624523e709SderaadtProvides the next key-value pair in the given map. 1634523e709SderaadtTo obtain the second pair, the 1644523e709Sderaadt.Fa inkey 1654523e709Sderaadtvalue should be the 1664523e709Sderaadt.Fa outkey 1674523e709Sderaadtvalue provided by the initial call to 1684523e709Sderaadt.Fn yp_first . 1694523e709SderaadtIn the general case, the next key-value pair may be obtained by using the 1704523e709Sderaadt.Fa outkey 1714523e709Sderaadtvalue from the previous call to 1724523e709Sderaadt.Fn yp_next 1734523e709Sderaadtas the value for 1744523e709Sderaadt.Fa inkey . 1754523e709Sderaadt.Pp 1764523e709SderaadtOf course, the notions of 1774523e709Sderaadt.Dq first 1784523e709Sderaadtand 1794523e709Sderaadt.Dq next 1804523e709Sderaadtare particular to the 1814523e709Sderaadttype of YP map being accessed, and thus there is no guarantee of lexical 1824523e709Sderaadtorder. 1834523e709SderaadtThe only guarantees provided with 1844523e709Sderaadt.Fn yp_first 1854523e709Sderaadtand 1864523e709Sderaadt.Fn yp_next , 1874523e709Sderaadtproviding that the same map on the same server is polled repeatedly 1884523e709Sderaadtuntil 1894523e709Sderaadt.Fn yp_next 1904523e709Sderaadtreturns YPERR_NOMORE, are that all key-value pairs in that map will be accessed 1914523e709Sderaadtexactly once, and if the entire procedure is repeated, the order will be 1924523e709Sderaadtthe same. 1934523e709Sderaadt.Pp 1944523e709SderaadtIf the server is heavily loaded or the server fails for some reason, the 1954523e709Sderaadtdomain being used may become unbound. 1964523e709SderaadtIf this happens, and the client process 1974523e709Sderaadtre-binds, the retrieval rules will break: some entries may be seen twice, and 1984523e709Sderaadtothers not at all. 1994523e709SderaadtFor this reason, the function 2004523e709Sderaadt.Fn yp_all 2014523e709Sderaadtprovides a better solution for reading all of the entries in a particular 2024523e709Sderaadtmap. 2034523e709Sderaadt.It Fn yp_all 2044523e709SderaadtThis function provides a way to transfer an entire map from 2054523e709Sderaadtthe server to the client process with a single request. 2064523e709SderaadtThis transfer method uses TCP, unlike all other functions which use UDP. 2074523e709SderaadtThe entire transaction occurs in a single RPC request-response. 2084523e709SderaadtThe third argument to this function provides a way to supply the name 2094523e709Sderaadtof a function to process each key-value pair in the map. 2104523e709Sderaadt.Fn yp_all 2114523e709Sderaadtreturns after the entire transaction is complete, or the 2124523e709Sderaadt.Fn foreach 2134523e709Sderaadtfunction decides that it does not want any more key-value pairs. 2144523e709SderaadtThe third argument to 2154523e709Sderaadt.Fn yp_all 2164523e709Sderaadtis: 2174523e709Sderaadt.Bd -literal -offset indent 2184523e709Sderaadtstruct ypall_callback *incallback { 2194523e709Sderaadt int (*foreach)(); 2204523e709Sderaadt char *data; 2214523e709Sderaadt}; 2224523e709Sderaadt.Ed 2234523e709Sderaadt.Pp 2244523e709SderaadtThe 2254523e709Sderaadt.Vt char * Ns Va data 2264523e709Sderaadtargument is an opaque pointer for use by the callback function. 2274523e709SderaadtThe 2284523e709Sderaadt.Fn foreach 2294523e709Sderaadtfunction should return non-zero when it no longer wishes to process 2304523e709Sderaadtkey-value pairs, at which time 2314523e709Sderaadt.Fn yp_all 2324523e709Sderaadtreturns a value of 0, and is called with the following arguments: 2334523e709Sderaadt.Bd -literal -offset indent 2344523e709Sderaadtint foreach ( 2354523e709Sderaadt unsigned long instatus, 2364523e709Sderaadt char *inkey, 2374523e709Sderaadt int inkeylen, 2384523e709Sderaadt char *inval, 2394523e709Sderaadt int invallen, 2404523e709Sderaadt char *indata 2414523e709Sderaadt); 2424523e709Sderaadt.Ed 2434523e709Sderaadt.Pp 2444523e709SderaadtWhere: 2454523e709Sderaadt.Bl -tag -width "inkey, inval" 2464523e709Sderaadt.It Fa instatus 2474523e709SderaadtHolds one of the return status values described in 2484523e709Sderaadt.In rpcsvc/yp_prot.h : 2494523e709Sderaadtsee 2504523e709Sderaadt.Fn ypprot_err 2514523e709Sderaadtbelow for a function that will translate YP protocol errors into a 2524523e709Sderaadterror code as described in 2534523e709Sderaadt.In rpcsvc/ypclnt.h . 2544523e709Sderaadt.It Fa inkey , inval 2554523e709SderaadtThe key and value arguments are somewhat different here than described 2564523e709Sderaadtabove. 2574523e709SderaadtIn this case, the memory pointed to by 2584523e709Sderaadt.Fa inkey 2594523e709Sderaadtand 2604523e709Sderaadt.Fa inval 2614523e709Sderaadtis private to 2624523e709Sderaadt.Fn yp_all , 2634523e709Sderaadtand is overwritten with each subsequent key-value pair; therefore, the 2644523e709Sderaadt.Fn foreach 2654523e709Sderaadtfunction should do something useful with the contents of that memory during 2664523e709Sderaadteach iteration. 2674523e709SderaadtIf the key-value pairs are not terminated with either 2684523e709Sderaadt.Ql \en 2694523e709Sderaadtor 2704523e709Sderaadt.Ql \e0 2714523e709Sderaadtin the map, then they will not be terminated as such when given to the 2724523e709Sderaadt.Fn foreach 2734523e709Sderaadtfunction, either. 2744523e709Sderaadt.It Fa indata 2754523e709SderaadtThis is the contents of the 2764523e709Sderaadt.Fa incallback Ns -> Ns Va data 2774523e709Sderaadtelement of the callback structure. 2784523e709SderaadtIt is provided as a means to share state between the 2794523e709Sderaadt.Fn foreach 2804523e709Sderaadtfunction and the user code. 2814523e709SderaadtIts use is completely optional: cast it to something useful or simply 2824523e709Sderaadtignore it. 2834523e709Sderaadt.El 2844523e709Sderaadt.It Fn yp_order 2854523e709SderaadtReturns the order number for a map. 2864523e709Sderaadt.It Fn yp_master 2874523e709SderaadtReturns the hostname for the machine on which the master YP server process for 2884523e709Sderaadta map is running. 2894523e709Sderaadt.It Fn yp_maplist 2904523e709SderaadtReturns a singly-linked list of the names of all the maps available in the 2914523e709Sderaadtnamed domain. 2924523e709SderaadtThe second argument to 2934523e709Sderaadt.Fn yp_maplist 2944523e709Sderaadtis: 2954523e709Sderaadt.Bd -literal -offset indent 2964523e709Sderaadtstruct ypmaplist { 2974523e709Sderaadt char *map; 2984523e709Sderaadt struct ypmaplist *next; 2994523e709Sderaadt}; 3004523e709Sderaadt.Ed 3014523e709Sderaadt.It Fn yperr_string 3024523e709SderaadtReturns a pointer to a NUL-terminated error string that does not contain a 3034523e709Sderaadt.Ql \&. 3044523e709Sderaadtor 3054523e709Sderaadt.Ql \en . 3064523e709Sderaadt.It Fn ypprot_err 307*8b2238e1SjmcConverts a YP protocol error code to an error code suitable for 3084523e709Sderaadt.Fn yperr_string . 3094523e709Sderaadt.El 3104523e709Sderaadt.Sh RETURN VALUES 3114523e709SderaadtAll functions which are of type 3124523e709Sderaadt.Em int 3134523e709Sderaadtreturn 0 upon success or one of the following error codes upon failure: 3144523e709Sderaadt.Bl -tag -width "YPERR_BADARGS " 3154523e709Sderaadt.It Bq Er YPERR_BADARGS 3164523e709SderaadtThe passed arguments to the function are invalid. 3174523e709Sderaadt.It Bq Er YPERR_BADDB 3184523e709SderaadtThe YP map that was polled is defective. 3194523e709Sderaadt.It Bq Er YPERR_DOMAIN 3204523e709SderaadtClient process cannot bind to server on this YP domain. 3214523e709Sderaadt.It Bq Er YPERR_KEY 3224523e709SderaadtThe key passed does not exist. 3234523e709Sderaadt.It Bq Er YPERR_MAP 3244523e709SderaadtThere is no such map in the server's domain. 3254523e709Sderaadt.It Bq Er YPERR_NODOM 3264523e709SderaadtThe local YP domain is not set. 3274523e709Sderaadt.It Bq Er YPERR_NOMORE 3284523e709SderaadtThere are no more records in the queried map. 3294523e709Sderaadt.It Bq Er YPERR_PMAP 3304523e709SderaadtCannot communicate with portmap. 3314523e709Sderaadt.It Bq Er YPERR_RESRC 3324523e709SderaadtA resource allocation failure occurred. 3334523e709Sderaadt.It Bq Er YPERR_RPC 3344523e709SderaadtAn RPC failure has occurred. 3354523e709SderaadtThe domain has been marked unbound. 3364523e709Sderaadt.It Bq Er YPERR_VERS 3374523e709SderaadtClient/server version mismatch. 3384523e709SderaadtIf the server is running version 1 of the YP protocol, 3394523e709Sderaadt.Fn yp_all 3404523e709Sderaadtfunctionality does not exist. 3414523e709Sderaadt.It Bq Er YPERR_YPBIND 3424523e709SderaadtCannot communicate with 3434523e709Sderaadt.Xr ypbind 8 . 3444523e709Sderaadt.It Bq Er YPERR_YPERR 3454523e709SderaadtAn internal server or client error has occurred. 3464523e709Sderaadt.It Bq Er YPERR_YPSERV 3474523e709SderaadtThe client cannot communicate with the YP server process. 3484523e709Sderaadt.El 3494523e709Sderaadt.Sh SEE ALSO 3504523e709Sderaadt.Xr malloc 3 , 3514523e709Sderaadt.Xr yp 8 , 3524523e709Sderaadt.Xr ypbind 8 , 3534523e709Sderaadt.Xr ypserv 8 3544523e709Sderaadt.Sh AUTHORS 3554523e709Sderaadt.An Theo de Raadt 356