1 .\" $OpenBSD: ypclnt.3,v 1.5 1996/12/28 09:06:29 downsj Exp $
3 .\" Copyright (c) 1996 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Jason R. Thorpe.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
17 .\" 3. All advertising materials mentioning features or use of this software
18 .\" must display the following acknowledgement:
19 .\" This product includes software developed by the NetBSD
20 .\" Foundation, Inc. and its contributors.
21 .\" 4. Neither the name of The NetBSD Foundation nor the names of its
22 .\" contributors may be used to endorse or promote products derived
23 .\" from this software without specific prior written permission.
25 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
29 .\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 .\" POSSIBILITY OF SUCH DAMAGE.
44 .Nm yp_get_default_domain ,
52 .Nd Interface to the YP subsystem
54 .Fd #include <rpc/rpc.h>
55 .Fd #include <rpcsvc/ypclnt.h>
56 .Fd #include <rpcsvc/yp_prot.h>
58 .Fn yp_all "char *indomain" "char *inmap" "struct ypall_callback *incallback"
60 .Fn yp_bind "char *dom"
62 .Fn yp_first "char *indomain" "char *inmap" "char **outkey" "int *outkeylen" "char **outval" "int *outvallen"
64 .Fn yp_get_default_domain "char **domp"
66 .Fn yp_master "char *indomain" "char *inmap" "char **outname"
68 .Fn yp_match "char *indomain" "char *inmap" "const char *inkey" "int inkeylen" "char **outval" "int *outvallen"
70 .Fn yp_next "char *indomain" "char *inmap" "char *inkey" "int inkeylen" "char **outkey" "int *outkeylen" "char **outval" "int *outvallen"
72 .Fn yp_order "char *indomain" "char *inmap" "char *outorder"
74 .Fn yp_unbind "char *dom"
76 .Fn yperr_string "int incode"
78 .Fn ypprot_err "unsigned int incode"
82 suite provides an interface to the YP subsystem. For a general description
83 of the YP subsystem, see
86 For all functions, input values begin with
88 and output values begin with
90 Any output values of type
92 should be the addresses of uninitialized character pointers. Memory will be
93 allocated by the YP client routines using
95 This memory can later be freed by the user if there is no additional need for
96 the data stored there. For
100 two extra bytes of memory are allocated for a
105 reflected in the values of
113 must be non-null, null-terminated strings. All input strings which also have
114 a corresponding length parameter cannot be null unless the corresponding
115 length value is zero. Such strings need not be null-terminated.
117 All YP lookup calls (the functions
124 require a YP domain name and a YP map name. The default domain name may be
126 .Fn yp_get_default_domain ,
127 and should thus be used before all other YP calls in a client program.
130 is suitable for use as the
132 parameter to all subsequent YP calls.
134 In order for YP lookup calls to succeed, the client process must be bound
135 to a YP server process. The client process need not explicitly bind to
136 the server, as it happens automatically whenever a lookup occurs.
139 is provided for a backup strategy, e.g. a local file, when a YP server process
140 is not available. Each binding uses one socket descriptor on the client
141 process, which may be explicitly freed using
143 which frees all per-process and per-node resources to bind the domain and
144 marks the domain unbound.
146 If, during a YP lookup, an RPC failure occurs, the domain used in the lookup
147 is automatically marked unbound and the
149 layer retries the lookup as long as
151 is running and either the client process cannot bind to a server for the domain
152 specified in the lookup, or RPC requests to the YP server process fail.
153 If an error is not RPC-related, one of the YP error codes described below
154 is returned and control given back to the user code.
158 suite provides the following functionality:
159 .Bl -tag -width ".Fn yperr_string"
161 Provides the value associated with the given key.
163 Provides the first key-value pair from the given map in the named domain.
165 Provides the next key-value pair in the given map. To obtain the second pair,
170 value provided by the initial call to
172 In the general case, the next key-value pair may be obtained by using the
174 value from the previous call to
179 Of course, the notions of ``first'' and ``next'' are particular to the
180 type of YP map being accessed, and thus there is no guarantee of lexical
181 order. The only guarantees provided with
185 providing that the same map on the same server is polled repeatedly
188 returns YPERR_NOMORE, are that all key-value pairs in that map will be accessed
189 exactly once, and if the entire procedure is repeated, the order will be
192 If the server is heaviliy loaded or the server fails for some reason, the
193 domain being used may become unbound. If this happens, and the client process
194 re-binds, the retrieval rules will break: some entries may be seen twice, and
195 others not at all. For this reason, the function
197 provides a better solution for reading all of the entries in a particular
200 This function provides a way to transfer an entire map from
201 the server to the client process with a single request. This transfer
202 uses TCP, unlike all other functions in the
204 suite, which use UDP. The entire transaction occurs in a single RPC
205 request-response. The third argument to this function provides a way
206 to supply the name of a function to process each key-value pair in the
209 returns after the entire transaction is complete, or the
211 function decides that it does not want any more key-value pairs. The third
215 .Bd -literal -offset indent
216 struct ypall_callback *incallback {
224 argument is an opaque pointer for use by the callback function. The
226 function should return non-zero when it no longer wishes to process
227 key-value pairs, at which time
229 returns a value of 0, and is called with the following arguments:
231 .Bd -literal -offset indent
243 .Bl -tag -width "inkey, inval"
245 Holds one of the return status values described in
246 .Nm <rpcsvc/yp_prot.h> :
249 below for a function that will translate YP protocol errors into a
251 layer error code as described in
252 .Nm <rpcsvc/ypclnt.h> .
254 The key and value arguments are somewhat different here than described
255 above. In this case, the memory pointed to by
261 and is overwritten with each subsequent key-value pair, thus the
263 function should do something useful with the contents of that memory during
264 each iteration. If the key-value pairs are not terminated with either
268 in the map, then they will not be terminated as such when given to the
272 This is the contents of the
274 element of the callback structure. It is provided as a means to share
277 function and the user code. Its use is completely optional: cast it to
278 something useful or simply ignore it.
281 Returns the order number for a map.
282 The order number is updated whenever a map is updated.
283 Clients may use the order number to check whether they are using the most
286 Returns the hostname for the machine on which the master YP server process for
289 Returns a pointer to a null-terminated error string that does not contain a
294 Converts a YP protocol error code to a
296 error code suitable for
302 suite which are of type
304 return 0 upon success or one of the following error codes upon failure:
305 .Bl -tag -width "YPERR_BADARGS "
306 .It Bq Er YPERR_BADARGS
307 The passed arguments to the function are invalid
308 .It Bq Er YPERR_BADDB
309 The YP map that was polled is defective.
310 .It Bq Er YPERR_DOMAIN
311 Client process cannot bind to server on this YP domain.
313 The key passed does not exist.
315 There is no such map in the server's domain.
317 The local YP domain is not set.
318 .It Bq Er YPERR_NOMORE
319 There are no more records in the queried map.
321 Cannot communicate with portmap.
322 .It Bq Er YPERR_RESRC
323 A resource allocation failure occurred.
325 An RPC failure has occurred. The domain has been marked unbound.
327 Client/server version mismatch. If the server is running version 1
330 functionality does not exist.
332 Cannot communicate with
334 .It Bq Er YPERR_YPERR
335 An internal server or client error has occurred.
336 .It Bq Er YPERR_YPSERV
337 The client cannot communicate with the YP server process.