1 .\" $NetBSD: ypclnt.3,v 1.26 2012/03/04 11:52:32 wiz 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.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
37 .Nm yp_get_default_domain ,
46 .Nd Interface to the YP subsystem
55 .Fn yp_all "const char *indomain" "const char *inmap" "struct ypall_callback *incallback"
57 .Fn yp_bind "const char *dom"
59 .Fn yp_first "const char *indomain" "const char *inmap" "char **outkey" "int *outkeylen" "char **outval" "int *outvallen"
61 .Fn yp_get_default_domain "char **outdomain"
63 .Fn yp_master "const char *indomain" "const char *inmap" "char **outname"
65 .Fn yp_match "const char *indomain" "const char *inmap" "const char *inkey" "int inkeylen" "char **outval" "int *outvallen"
67 .Fn yp_next "const char *indomain" "const char *inmap" "const char *inkey" "int inkeylen" "char **outkey" "int *outkeylen" "char **outval" "int *outvallen"
69 .Fn yp_order "const char *indomain" "const char *inmap" "int *outorder"
71 .Fn yp_unbind "const char *dom"
73 .Fn yperr_string "int incode"
75 .Fn ypprot_err "unsigned int incode"
77 .Fn yp_setbindtries "int ntries"
81 suite provides an interface to the
84 For a general description of the
89 For all functions, input values begin with
91 and output values begin with
94 Any output values of type
96 should be the addresses of uninitialized character pointers.
97 These values will be reset to the null pointer (unless the address
98 itself is the null pointer, in which case the error
102 memory will be allocated by the
104 client routines using
106 and the result will be stored in the appropriate output value.
107 If the invocation of a
109 client routine doesn't return an error,
110 and an output value is not the null pointer, then this memory
111 should be freed by the user when there is no additional need for
112 the data stored there.
117 two extra bytes of memory are allocated for a
122 reflected in the values of
131 must be non-null, NUL-terminated strings.
132 All input strings which also have
133 a corresponding length parameter cannot be the null pointer unless the
134 corresponding length value is zero.
135 Such strings need not be NUL-terminated.
139 lookup calls (the functions
151 The default domain name may be obtained by calling
152 .Fn yp_get_default_domain ,
153 and should thus be used before all other
155 calls in a client program.
158 is suitable for use as the
160 parameter to all subsequent
166 lookup calls to succeed, the client process must be bound
170 The client process need not explicitly bind to
171 the server, as it happens automatically whenever a lookup occurs.
174 is provided for a backup strategy, e.g. a local file, when a
176 server process is not available.
177 Each binding uses one socket descriptor on the client
178 process, which may be explicitly freed using
180 which frees all per-process and per-node resources to bind the domain and
181 marks the domain unbound.
185 lookup, an RPC failure occurs, the domain used in the lookup
186 is automatically marked unbound and the
188 layer retries the lookup as long as
190 is running and either the client process cannot bind to a server for the domain
191 specified in the lookup, or RPC requests to the
194 If an error is not RPC-related, one of the
196 error codes described below
197 is returned and control given back to the user code.
201 suite provides the following functionality:
202 .Bl -tag -width yp_matchxxxx
204 Provides the value associated with the given key.
206 Provides the first key-value pair from the given map in the named domain.
208 Provides the next key-value pair in the given map.
209 To obtain the second pair,
214 value provided by the initial call to
216 In the general case, the next key-value pair may be obtained by using the
218 value from the previous call to
223 Of course, the notions of
227 are particular to the
230 map being accessed, and thus there is no guarantee of lexical order.
231 The only guarantees provided with
235 providing that the same map on the same server is polled repeatedly until
237 returns YPERR_NOMORE, are that all key-value pairs in that map will be accessed
238 exactly once, and if the entire procedure is repeated, the order will be
241 If the server is heavily loaded or the server fails for some reason, the
242 domain being used may become unbound.
243 If this happens, and the client process re-binds, the retrieval rules
244 will break: some entries may be seen twice, and others not at all.
245 For this reason, the function
247 provides a better solution for reading all of the entries in a particular map.
249 This function provides a way to transfer an entire map from
250 the server to the client process with a single request.
251 This transfer uses TCP, unlike all other functions in the
253 suite, which use UDP.
254 The entire transaction occurs in a single RPC request-response.
255 The third argument to this function provides a way to supply
256 the name of a function to process each key-value pair in the map.
258 returns after the entire transaction is complete, or the
260 function decides that it does not want any more key-value pairs.
261 The third argument to
264 .Bd -literal -offset indent
265 struct ypall_callback *incallback {
273 argument is an opaque pointer for use by the callback function.
276 function should return non-zero when it no longer wishes to process
277 key-value pairs, at which time
279 returns a value of 0, and is called with the following arguments:
281 .Bd -literal -offset indent
293 .Bl -tag -width "inkey, inval"
295 Holds one of the return status values described in
296 .In rpcsvc/yp_prot.h :
299 below for a function that will translate
301 protocol errors into a
303 layer error code as described in
304 .In rpcsvc/ypclnt.h .
306 The key and value arguments are somewhat different here than described
308 In this case, the memory pointed to by
314 and is overwritten with each subsequent key-value pair, thus the
316 function should do something useful with the contents of that memory during
318 If the key-value pairs are not terminated with either
322 in the map, then they will not be terminated as such when given to the
326 This is the contents of the
327 .Pa incallback-\*[Gt]data
328 element of the callback structure.
329 It is provided as a means to share state between the
331 function and the user code.
332 Its use is completely optional: cast it to
333 something useful or simply ignore it.
336 Returns the order number for a map.
338 Returns the hostname for the machine on which the master
343 Returns a pointer to a NUL-terminated error string that does not contain a
350 protocol error code to a
352 error code suitable for
354 .It Fn yp_setbindtries
355 Set the number of tries to attempt to bind to the domain before returning
359 which means wait forever if no ypserver is not found of if the RPC
360 communication with the yp server fails.
361 If the number passed is negative, the current number of tries is not modified.
363 This function is an extention to the client library that allows application
364 to catch communication problems with the ypserver without blocking forever.
369 suite which are of type
371 return 0 upon success or one of the following error codes upon failure:
372 .Bl -tag -width "YPERR_BADARGS "
373 .It Bq Er YPERR_BADARGS
374 The passed arguments to the function are invalid.
375 .It Bq Er YPERR_BADDB
378 map that was polled is defective.
379 .It Bq Er YPERR_DOMAIN
380 Client process cannot bind to server on this
384 The key passed does not exist.
386 There is no such map in the server's domain.
391 .It Bq Er YPERR_NOMORE
392 There are no more records in the queried map.
394 Cannot communicate with portmapper (see
396 .It Bq Er YPERR_RESRC
397 A resource allocation failure occurred.
399 An RPC failure has occurred.
400 The domain has been marked unbound.
402 Client/server version mismatch.
403 If the server is running version 1 of the
407 functionality does not exist.
409 Cannot communicate with
411 .It Bq Er YPERR_YPERR
412 An internal server or client error has occurred.
413 .It Bq Er YPERR_YPSERV
414 The client cannot communicate with the