]> git.saurik.com Git - apple/libinfo.git/blame - nis.subproj/ypclnt.3
Libinfo-392.1.tar.gz
[apple/libinfo.git] / nis.subproj / ypclnt.3
CommitLineData
3b7c7bd7
A
1.\" $OpenBSD: ypclnt.3,v 1.5 1996/12/28 09:06:29 downsj Exp $
2.\"
3.\" Copyright (c) 1996 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Jason R. Thorpe.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
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.
24.\"
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.
36.\"
37.Dd October 26, 1994
38.Dt YPCLNT 3
39.Os
40.Sh NAME
41.Nm yp_all ,
42.Nm yp_bind ,
43.Nm yp_first ,
44.Nm yp_get_default_domain ,
45.Nm yp_master ,
46.Nm yp_match ,
47.Nm yp_next ,
48.Nm yp_order ,
49.Nm yp_unbind ,
50.Nm yperr_string ,
51.Nm ypprot_err
52.Nd Interface to the YP subsystem
53.Sh SYNOPSIS
b3dd680f 54.Fd #include <rpc/rpc.h>
3b7c7bd7
A
55.Fd #include <rpcsvc/ypclnt.h>
56.Fd #include <rpcsvc/yp_prot.h>
57.Ft int
58.Fn yp_all "char *indomain" "char *inmap" "struct ypall_callback *incallback"
59.Ft int
60.Fn yp_bind "char *dom"
61.Ft int
62.Fn yp_first "char *indomain" "char *inmap" "char **outkey" "int *outkeylen" "char **outval" "int *outvallen"
63.Ft int
64.Fn yp_get_default_domain "char **domp"
65.Ft int
66.Fn yp_master "char *indomain" "char *inmap" "char **outname"
67.Ft int
68.Fn yp_match "char *indomain" "char *inmap" "const char *inkey" "int inkeylen" "char **outval" "int *outvallen"
69.Ft int
70.Fn yp_next "char *indomain" "char *inmap" "char *inkey" "int inkeylen" "char **outkey" "int *outkeylen" "char **outval" "int *outvallen"
71.Ft int
72.Fn yp_order "char *indomain" "char *inmap" "char *outorder"
73.Ft void
74.Fn yp_unbind "char *dom"
75.Ft char *
76.Fn yperr_string "int incode"
77.Ft int
78.Fn ypprot_err "unsigned int incode"
79.Sh DESCRIPTION
80The
81.Nm ypclnt
82suite provides an interface to the YP subsystem. For a general description
83of the YP subsystem, see
84.Xr yp 8 .
85.Pp
86For all functions, input values begin with
87.Pa in
88and output values begin with
89.Pa out .
90Any output values of type
91.Em char **
92should be the addresses of uninitialized character pointers. Memory will be
93allocated by the YP client routines using
94.Fn malloc .
95This memory can later be freed by the user if there is no additional need for
96the data stored there. For
97.Pa outkey
98and
99.Pa outval ,
100two extra bytes of memory are allocated for a
101.Ql \en
102and
103.Ql \e0 ,
104which are not
105reflected in the values of
106.Pa outkeylen
107or
108.Pa outvallen .
109All occurrences of
110.Pa indomain
111and
112.Pa inmap
113must be non-null, null-terminated strings. All input strings which also have
114a corresponding length parameter cannot be null unless the corresponding
115length value is zero. Such strings need not be null-terminated.
116.Pp
117All YP lookup calls (the functions
118.Fn yp_all ,
119.Fn yp_first ,
120.Fn yp_master ,
121.Fn yp_match ,
122.Fn yp_next ,
123.Fn yp_order )
124require a YP domain name and a YP map name. The default domain name may be
125obtained by calling
126.Fn yp_get_default_domain ,
127and should thus be used before all other YP calls in a client program.
128The value it places
129.Pa outdomain
130is suitable for use as the
131.Pa indomain
132parameter to all subsequent YP calls.
133.Pp
134In order for YP lookup calls to succeed, the client process must be bound
135to a YP server process. The client process need not explicitly bind to
136the server, as it happens automatically whenever a lookup occurs.
137The function
138.Fn yp_bind
139is provided for a backup strategy, e.g. a local file, when a YP server process
140is not available. Each binding uses one socket descriptor on the client
141process, which may be explicitly freed using
142.Fn yp_unbind ,
143which frees all per-process and per-node resources to bind the domain and
144marks the domain unbound.
145.Pp
146If, during a YP lookup, an RPC failure occurs, the domain used in the lookup
147is automatically marked unbound and the
148.Nm ypclnt
149layer retries the lookup as long as
150.Xr ypbind 8
151is running and either the client process cannot bind to a server for the domain
152specified in the lookup, or RPC requests to the YP server process fail.
153If an error is not RPC-related, one of the YP error codes described below
154is returned and control given back to the user code.
155.Pp
156The
157.Nm ypclnt
158suite provides the following functionality:
c29f2fcc 159.Bl -tag -width ".Fn yperr_string"
3b7c7bd7
A
160.It Fn yp_match
161Provides the value associated with the given key.
162.It Fn yp_first
163Provides the first key-value pair from the given map in the named domain.
164.It Fn yp_next
165Provides the next key-value pair in the given map. To obtain the second pair,
166the
167.Pa inkey
168value should be the
169.Pa outkey
170value provided by the initial call to
171.Fn yp_first .
172In the general case, the next key-value pair may be obtained by using the
173.Pa outkey
174value from the previous call to
175.Fn yp_next
176as the value for
177.Pa inkey .
178.Pp
179Of course, the notions of ``first'' and ``next'' are particular to the
180type of YP map being accessed, and thus there is no guarantee of lexical
181order. The only guarantees provided with
182.Fn yp_first
183and
184.Fn yp_next ,
185providing that the same map on the same server is polled repeatedly
186until
187.Fn yp_next
188returns YPERR_NOMORE, are that all key-value pairs in that map will be accessed
189exactly once, and if the entire procedure is repeated, the order will be
190the same.
191.Pp
192If the server is heaviliy loaded or the server fails for some reason, the
193domain being used may become unbound. If this happens, and the client process
194re-binds, the retrieval rules will break: some entries may be seen twice, and
195others not at all. For this reason, the function
196.Fn yp_all
197provides a better solution for reading all of the entries in a particular
198map.
199.It Fn yp_all
200This function provides a way to transfer an entire map from
201the server to the client process with a single request. This transfer
202uses TCP, unlike all other functions in the
203.Nm ypclnt
204suite, which use UDP. The entire transaction occurs in a single RPC
205request-response. The third argument to this function provides a way
206to supply the name of a function to process each key-value pair in the
207map.
208.Fn Yp_all
209returns after the entire transaction is complete, or the
210.Pa foreach
211function decides that it does not want any more key-value pairs. The third
212argument to
213.Fn yp_all
214is:
215.Bd -literal -offset indent
216struct ypall_callback *incallback {
217 int (*foreach)();
218 char *data;
219};
220.Ed
221.Pp
222The
223.Em char *data
224argument is an opaque pointer for use by the callback function. The
225.Pa foreach
226function should return non-zero when it no longer wishes to process
227key-value pairs, at which time
228.Fn yp_all
229returns a value of 0, and is called with the following arguments:
230.Pp
231.Bd -literal -offset indent
232int foreach (
233 int instatus,
234 char *inkey,
235 int inkeylen,
236 char *inval,
237 int invallen,
238 char *indata
239);
240.Ed
241.Pp
242Where:
243.Bl -tag -width "inkey, inval"
244.It Fa instatus
245Holds one of the return status values described in
246.Nm <rpcsvc/yp_prot.h> :
247see
248.Fn ypprot_err
249below for a function that will translate YP protocol errors into a
250.Nm ypclnt
251layer error code as described in
252.Nm <rpcsvc/ypclnt.h> .
253.It Fa inkey, inval
254The key and value arguments are somewhat different here than described
255above. In this case, the memory pointed to by
256.Fa inkey
257and
258.Fa inval
259is private to
260.Fn yp_all ,
261and is overwritten with each subsequent key-value pair, thus the
262.Pa foreach
263function should do something useful with the contents of that memory during
264each iteration. If the key-value pairs are not terminated with either
265.Ql \en
266or
267.Ql \e0
268in the map, then they will not be terminated as such when given to the
269.Pa foreach
270function, either.
271.It Fa indata
272This is the contents of the
273.Pa incallback->data
274element of the callback structure. It is provided as a means to share
275state between the
276.Pa foreach
277function and the user code. Its use is completely optional: cast it to
278something useful or simply ignore it.
279.El
280.It Fn yp_order
281Returns the order number for a map.
d49d4c81
A
282The order number is updated whenever a map is updated.
283Clients may use the order number to check whether they are using the most
284recent map.
3b7c7bd7
A
285.It Fn yp_master
286Returns the hostname for the machine on which the master YP server process for
287a map is running.
288.It Fn yperr_string
289Returns a pointer to a null-terminated error string that does not contain a
290.Ql \&.
291or
292.Ql \en .
293.It Fn ypprot_err
294Converts a YP protocol error code to a
295.Nm ypclnt
296error code suitable for
297.Fn yperr_string .
298.El
299.Sh RETURN VALUES
300All functions in the
301.Nm ypclnt
302suite which are of type
303.Em int
304return 0 upon success or one of the following error codes upon failure:
305.Bl -tag -width "YPERR_BADARGS "
306.It Bq Er YPERR_BADARGS
307The passed arguments to the function are invalid
308.It Bq Er YPERR_BADDB
309The YP map that was polled is defective.
310.It Bq Er YPERR_DOMAIN
311Client process cannot bind to server on this YP domain.
312.It Bq Er YPERR_KEY
313The key passed does not exist.
314.It Bq Er YPERR_MAP
315There is no such map in the server's domain.
316.It Bq Er YPERR_DOM
317The local YP domain is not set.
318.It Bq Er YPERR_NOMORE
319There are no more records in the queried map.
320.It Bq Er YPERR_PMAP
321Cannot communicate with portmap.
322.It Bq Er YPERR_RESRC
323A resource allocation failure occurred.
324.It Bq Er YPERR_RPC
325An RPC failure has occurred. The domain has been marked unbound.
326.It Bq Er YPERR_VERS
327Client/server version mismatch. If the server is running version 1
328of the YP protocol,
329.Fn yp_all
330functionality does not exist.
331.It Bq Er YPERR_BIND
332Cannot communicate with
333.Xr ypbind 8 .
334.It Bq Er YPERR_YPERR
335An internal server or client error has occurred.
336.It Bq Er YPERR_YPSERV
337The client cannot communicate with the YP server process.
338.El
339.Sh SEE ALSO
340.Xr malloc 3 ,
341.Xr yp 8 ,
342.Xr ypbind 8 ,
343.Xr ypserv 8
344.Sh AUTHOR
d49d4c81 345Theo De Raadt