1 .\" $NetBSD: ypclnt.3,v 1.23 2008/04/30 13:10:51 martin 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 ,
45 .Nd Interface to the YP subsystem
54 .Fn yp_all "char *indomain" "char *inmap" "struct ypall_callback *incallback"
56 .Fn yp_bind "char *dom"
58 .Fn yp_first "char *indomain" "char *inmap" "char **outkey" "size_t *outkeylen" "char **outval" "size_t *outvallen"
60 .Fn yp_get_default_domain "char **domp"
62 .Fn yp_master "char *indomain" "char *inmap" "char **outname"
64 .Fn yp_match "char *indomain" "char *inmap" "const char *inkey" "int inkeylen" "char **outval" "int *outvallen"
66 .Fn yp_next "char *indomain" "char *inmap" "char *inkey" "size_t inkeylen" "char **outkey" "int *outkeylen" "char **outval" "size_t *outvallen"
68 .Fn yp_order "char *indomain" "char *inmap" "int *outorder"
70 .Fn yp_unbind "char *dom"
72 .Fn yperr_string "int incode"
74 .Fn ypprot_err "unsigned int incode"
78 suite provides an interface to the
81 For a general description of the
86 For all functions, input values begin with
88 and output values begin with
91 Any output values of type
93 should be the addresses of uninitialized character pointers.
94 These values will be reset to the null pointer (unless the address
95 itself is the null pointer, in which case the error
99 memory will be allocated by the
101 client routines using
103 and the result will be stored in the appropriate output value.
104 If the invocation of a
106 client routine doesn't return an error,
107 and an output value is not the null pointer, then this memory
108 should be freed by the user when there is no additional need for
109 the data stored there.
114 two extra bytes of memory are allocated for a
119 reflected in the values of
128 must be non-null, NUL-terminated strings.
129 All input strings which also have
130 a corresponding length parameter cannot be the null pointer unless the
131 corresponding length value is zero.
132 Such strings need not be NUL-terminated.
136 lookup calls (the functions
148 The default domain name may be obtained by calling
149 .Fn yp_get_default_domain ,
150 and should thus be used before all other
152 calls in a client program.
155 is suitable for use as the
157 parameter to all subsequent
163 lookup calls to succeed, the client process must be bound
167 The client process need not explicitly bind to
168 the server, as it happens automatically whenever a lookup occurs.
171 is provided for a backup strategy, e.g. a local file, when a
173 server process is not available.
174 Each binding uses one socket descriptor on the client
175 process, which may be explicitly freed using
177 which frees all per-process and per-node resources to bind the domain and
178 marks the domain unbound.
182 lookup, an RPC failure occurs, the domain used in the lookup
183 is automatically marked unbound and the
185 layer retries the lookup as long as
187 is running and either the client process cannot bind to a server for the domain
188 specified in the lookup, or RPC requests to the
191 If an error is not RPC-related, one of the
193 error codes described below
194 is returned and control given back to the user code.
198 suite provides the following functionality:
199 .Bl -tag -width yp_match()xx
201 Provides the value associated with the given key.
203 Provides the first key-value pair from the given map in the named domain.
205 Provides the next key-value pair in the given map.
206 To obtain the second pair,
211 value provided by the initial call to
213 In the general case, the next key-value pair may be obtained by using the
215 value from the previous call to
220 Of course, the notions of
224 are particular to the
227 map being accessed, and thus there is no guarantee of lexical order.
228 The only guarantees provided with
232 providing that the same map on the same server is polled repeatedly until
234 returns YPERR_NOMORE, are that all key-value pairs in that map will be accessed
235 exactly once, and if the entire procedure is repeated, the order will be
238 If the server is heavily loaded or the server fails for some reason, the
239 domain being used may become unbound.
240 If this happens, and the client process re-binds, the retrieval rules
241 will break: some entries may be seen twice, and others not at all.
242 For this reason, the function
244 provides a better solution for reading all of the entries in a particular map.
246 This function provides a way to transfer an entire map from
247 the server to the client process with a single request.
248 This transfer uses TCP, unlike all other functions in the
250 suite, which use UDP.
251 The entire transaction occurs in a single RPC request-response.
252 The third argument to this function provides a way to supply
253 the name of a function to process each key-value pair in the map.
255 returns after the entire transaction is complete, or the
257 function decides that it does not want any more key-value pairs.
258 The third argument to
261 .Bd -literal -offset indent
262 struct ypall_callback *incallback {
270 argument is an opaque pointer for use by the callback function.
273 function should return non-zero when it no longer wishes to process
274 key-value pairs, at which time
276 returns a value of 0, and is called with the following arguments:
277 .Bd -literal -offset indent
289 .Bl -tag -width "inkey, inval"
291 Holds one of the return status values described in
292 .In rpcsvc/yp_prot.h :
295 below for a function that will translate
297 protocol errors into a
299 layer error code as described in
300 .In rpcsvc/ypclnt.h .
302 The key and value arguments are somewhat different here than described
304 In this case, the memory pointed to by
310 and is overwritten with each subsequent key-value pair, thus the
312 function should do something useful with the contents of that memory during
314 If the key-value pairs are not terminated with either
318 in the map, then they will not be terminated as such when given to the
322 This is the contents of the
324 element of the callback structure.
325 It is provided as a means to share state between the
327 function and the user code.
328 Its use is completely optional: cast it to
329 something useful or simply ignore it.
332 Returns the order number for a map.
334 Returns the hostname for the machine on which the master
339 Returns a pointer to a NUL-terminated error string that does not contain a
346 protocol error code to a
348 error code suitable for
354 suite which are of type
356 return 0 upon success or one of the following error codes upon failure:
357 .Bl -tag -width "YPERR_BADARGS "
358 .It Bq Er YPERR_BADARGS
359 The passed arguments to the function are invalid.
360 .It Bq Er YPERR_BADDB
363 map that was polled is defective.
364 .It Bq Er YPERR_DOMAIN
365 Client process cannot bind to server on this
369 The key passed does not exist.
371 There is no such map in the server's domain.
376 .It Bq Er YPERR_NOMORE
377 There are no more records in the queried map.
379 Cannot communicate with portmapper (see
381 .It Bq Er YPERR_RESRC
382 A resource allocation failure occurred.
384 An RPC failure has occurred.
385 The domain has been marked unbound.
387 Client/server version mismatch.
388 If the server is running version 1 of the
392 functionality does not exist.
394 Cannot communicate with
396 .It Bq Er YPERR_YPERR
397 An internal server or client error has occurred.
398 .It Bq Er YPERR_YPSERV
399 The client cannot communicate with the