NetBSD/lib/libc/yp/ypclnt.3

418 lines
11 KiB
Groff
Raw Normal View History

.\" $NetBSD: ypclnt.3,v 1.20 2002/10/01 19:03:15 wiz Exp $
1994-10-29 02:03:02 +03:00
.\"
.\" Copyright (c) 1996 The NetBSD Foundation, Inc.
1994-10-29 02:03:02 +03:00
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Jason R. Thorpe.
.\"
1994-10-29 02:03:02 +03:00
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the NetBSD
.\" Foundation, Inc. and its contributors.
.\" 4. Neither the name of The NetBSD Foundation nor the names of its
.\" contributors may be used to endorse or promote products derived
.\" from this software without specific prior written permission.
1994-10-29 02:03:02 +03:00
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
1994-10-29 02:03:02 +03:00
.\"
.Dd May 21, 1997
1994-10-29 02:03:02 +03:00
.Dt YPCLNT 3
.Os
.Sh NAME
.Nm yp_all ,
.Nm yp_bind ,
.Nm yp_first ,
.Nm yp_get_default_domain ,
.Nm yp_master ,
.Nm yp_match ,
.Nm yp_next ,
.Nm yp_order ,
.Nm yp_unbind ,
.Nm yperr_string ,
.Nm ypprot_err
.Nd Interface to the YP subsystem
1998-02-05 21:45:17 +03:00
.Sh LIBRARY
.Lb libc
1994-10-29 02:03:02 +03:00
.Sh SYNOPSIS
2002-02-07 10:00:09 +03:00
.Fd #include \*[Lt]sys/types.h\*[Gt]
.Fd #include \*[Lt]rpc/rpc.h\*[Gt]
.Fd #include \*[Lt]rpcsvc/ypclnt.h\*[Gt]
.Fd #include \*[Lt]rpcsvc/yp_prot.h\*[Gt]
1994-10-29 02:03:02 +03:00
.Ft int
.Fn yp_all "const char *indomain" "const char *inmap" "struct ypall_callback *incallback"
1994-10-29 02:03:02 +03:00
.Ft int
.Fn yp_bind "const char *dom"
1994-10-29 02:03:02 +03:00
.Ft int
.Fn yp_first "const char *indomain" "const char *inmap" "char **outkey" "int *outkeylen" "char **outval" "int *outvallen"
1994-10-29 02:03:02 +03:00
.Ft int
.Fn yp_get_default_domain "char **outdomain"
1994-10-29 02:03:02 +03:00
.Ft int
.Fn yp_master "const char *indomain" "const char *inmap" "char **outname"
1994-10-29 02:03:02 +03:00
.Ft int
.Fn yp_match "const char *indomain" "const char *inmap" "const char *inkey" "int inkeylen" "char **outval" "int *outvallen"
1994-10-29 02:03:02 +03:00
.Ft int
.Fn yp_next "const char *indomain" "const char *inmap" "const char *inkey" "int inkeylen" "char **outkey" "int *outkeylen" "char **outval" "int *outvallen"
1994-10-29 02:03:02 +03:00
.Ft int
.Fn yp_order "const char *indomain" "const char *inmap" "int *outorder"
1994-10-29 02:03:02 +03:00
.Ft void
.Fn yp_unbind "const char *dom"
1994-10-29 02:03:02 +03:00
.Ft char *
.Fn yperr_string "int incode"
.Ft int
.Fn ypprot_err "unsigned int incode"
.Sh DESCRIPTION
The
.Nm ypclnt
1998-01-23 16:49:10 +03:00
suite provides an interface to the
.Tn YP
subsystem.
For a general description of the
1998-01-23 16:49:10 +03:00
.Tn YP
subsystem, see
1994-10-29 02:03:02 +03:00
.Xr yp 8 .
.Pp
For all functions, input values begin with
.Pa in
and output values begin with
.Pa out .
.Pp
Any output values of type
1994-10-29 02:03:02 +03:00
.Em char **
should be the addresses of uninitialized character pointers.
These values will be reset to the null pointer (unless the address
itself is the null pointer, in which case the error
.Er YPERR_BADARGS
will be returned).
If necessary,
1998-01-23 16:49:10 +03:00
memory will be allocated by the
.Tn YP
client routines using
.Fn malloc ,
and the result will be stored in the appropriate output value.
1998-01-23 16:49:10 +03:00
If the invocation of a
.Tn YP
client routine doesn't return an error,
and an output value is not the null pointer, then this memory
should be freed by the user when there is no additional need for
the data stored there.
For
1994-10-29 02:03:02 +03:00
.Pa outkey
and
.Pa outval ,
two extra bytes of memory are allocated for a
.Ql \en
and
.Ql \e0 ,
which are not
reflected in the values of
.Pa outkeylen
or
.Pa outvallen .
.Pp
1994-10-29 02:03:02 +03:00
All occurrences of
.Pa indomain
and
.Pa inmap
must be non-null, NUL-terminated strings.
All input strings which also have
a corresponding length parameter cannot be the null pointer unless the
corresponding length value is zero.
Such strings need not be NUL-terminated.
1994-10-29 02:03:02 +03:00
.Pp
1998-01-23 16:49:10 +03:00
All
.Tn YP
lookup calls (the functions
1994-10-29 02:03:02 +03:00
.Fn yp_all ,
.Fn yp_first ,
.Fn yp_master ,
.Fn yp_match ,
.Fn yp_next ,
.Fn yp_order )
1998-01-23 16:49:10 +03:00
require a
.Tn YP
domain name and a
.Tn YP
map name.
The default domain name may be obtained by calling
1994-10-29 02:03:02 +03:00
.Fn yp_get_default_domain ,
1998-01-23 16:49:10 +03:00
and should thus be used before all other
.Tn YP
calls in a client program.
1994-10-29 02:03:02 +03:00
The value it places
.Pa outdomain
is suitable for use as the
.Pa indomain
1998-01-23 16:49:10 +03:00
parameter to all subsequent
.Tn YP
calls.
1994-10-29 02:03:02 +03:00
.Pp
1998-01-23 16:49:10 +03:00
In order for
.Tn YP
lookup calls to succeed, the client process must be bound
to a
.Tn YP
server process.
The client process need not explicitly bind to
1994-10-29 02:03:02 +03:00
the server, as it happens automatically whenever a lookup occurs.
The function
.Fn yp_bind
1998-01-23 16:49:10 +03:00
is provided for a backup strategy, e.g. a local file, when a
.Tn YP
server process is not available.
Each binding uses one socket descriptor on the client
1994-10-29 02:03:02 +03:00
process, which may be explicitly freed using
.Fn yp_unbind ,
which frees all per-process and per-node resources to bind the domain and
marks the domain unbound.
.Pp
1998-01-23 16:49:10 +03:00
If, during a
.Tn YP
lookup, an RPC failure occurs, the domain used in the lookup
1994-10-29 02:03:02 +03:00
is automatically marked unbound and the
.Nm ypclnt
layer retries the lookup as long as
.Xr ypbind 8
is running and either the client process cannot bind to a server for the domain
1998-01-23 16:49:10 +03:00
specified in the lookup, or RPC requests to the
.Tn YP
server process fail.
If an error is not RPC-related, one of the
.Tn YP
error codes described below
1994-10-29 02:03:02 +03:00
is returned and control given back to the user code.
.Pp
The
.Nm ypclnt
suite provides the following functionality:
.Bl -tag -width yp_match()xx
1994-10-29 02:03:02 +03:00
.It Fn yp_match
Provides the value associated with the given key.
.It Fn yp_first
Provides the first key-value pair from the given map in the named domain.
.It Fn yp_next
Provides the next key-value pair in the given map.
To obtain the second pair,
1994-10-29 02:03:02 +03:00
the
.Pa inkey
value should be the
.Pa outkey
value provided by the initial call to
.Fn yp_first .
In the general case, the next key-value pair may be obtained by using the
.Pa outkey
value from the previous call to
.Fn yp_next
as the value for
.Pa inkey .
.Pp
Of course, the notions of
.Dq first
and
.Dq next
are particular to the
1998-01-23 16:49:10 +03:00
type of
.Tn YP
map being accessed, and thus there is no guarantee of lexical order.
The only guarantees provided with
1994-10-29 02:03:02 +03:00
.Fn yp_first
and
.Fn yp_next ,
providing that the same map on the same server is polled repeatedly until
1994-10-29 02:03:02 +03:00
.Fn yp_next
returns YPERR_NOMORE, are that all key-value pairs in that map will be accessed
exactly once, and if the entire procedure is repeated, the order will be
the same.
.Pp
2002-09-04 04:59:44 +04:00
If the server is heavily loaded or the server fails for some reason, the
domain being used may become unbound.
If this happens, and the client process re-binds, the retrieval rules
will break: some entries may be seen twice, and others not at all.
For this reason, the function
1994-10-29 02:03:02 +03:00
.Fn yp_all
provides a better solution for reading all of the entries in a particular map.
1994-10-29 02:03:02 +03:00
.It Fn yp_all
This function provides a way to transfer an entire map from
the server to the client process with a single request.
This transfer uses TCP, unlike all other functions in the
1994-10-29 02:03:02 +03:00
.Nm ypclnt
suite, which use UDP.
The entire transaction occurs in a single RPC request-response.
The third argument to this function provides a way to supply
the name of a function to process each key-value pair in the map.
.Fn yp_all
1994-10-29 02:03:02 +03:00
returns after the entire transaction is complete, or the
.Pa foreach
function decides that it does not want any more key-value pairs.
The third argument to
1994-10-29 02:03:02 +03:00
.Fn yp_all
is:
.Bd -literal -offset indent
struct ypall_callback *incallback {
int (*foreach)();
char *data;
};
.Ed
.Pp
The
.Em char *data
argument is an opaque pointer for use by the callback function.
The
1994-10-29 02:03:02 +03:00
.Pa foreach
function should return non-zero when it no longer wishes to process
key-value pairs, at which time
.Fn yp_all
returns a value of 0, and is called with the following arguments:
.Pp
.Bd -literal -offset indent
int foreach (
int instatus,
char *inkey,
int inkeylen,
char *inval,
int invallen,
char *indata
1994-10-29 02:03:02 +03:00
);
.Ed
.Pp
Where:
.Bl -tag -width "inkey, inval"
.It Fa instatus
Holds one of the return status values described in
2002-02-07 10:00:09 +03:00
.Nm \*[Lt]rpcsvc/yp_prot.h\*[Gt] :
1994-10-29 02:03:02 +03:00
see
.Fn ypprot_err
1998-01-23 16:49:10 +03:00
below for a function that will translate
.Tn YP
protocol errors into a
1994-10-29 02:03:02 +03:00
.Nm ypclnt
layer error code as described in
2002-02-07 10:00:09 +03:00
.Nm \*[Lt]rpcsvc/ypclnt.h\*[Gt] .
1994-10-29 02:03:02 +03:00
.It Fa inkey, inval
The key and value arguments are somewhat different here than described
above.
In this case, the memory pointed to by
1994-10-29 02:03:02 +03:00
.Fa inkey
and
.Fa inval
is private to
.Fn yp_all ,
and is overwritten with each subsequent key-value pair, thus the
.Pa foreach
function should do something useful with the contents of that memory during
each iteration.
If the key-value pairs are not terminated with either
1994-10-29 02:03:02 +03:00
.Ql \en
or
.Ql \e0
in the map, then they will not be terminated as such when given to the
.Pa foreach
function, either.
.It Fa indata
This is the contents of the
2002-02-07 10:00:09 +03:00
.Pa incallback-\*[Gt]data
element of the callback structure.
It is provided as a means to share state between the
1994-10-29 02:03:02 +03:00
.Pa foreach
function and the user code.
Its use is completely optional: cast it to
1994-10-29 02:03:02 +03:00
something useful or simply ignore it.
.El
.It Fn yp_order
Returns the order number for a map.
.It Fn yp_master
1998-01-23 16:49:10 +03:00
Returns the hostname for the machine on which the master
.Tn YP
server process for
1994-10-29 02:03:02 +03:00
a map is running.
.It Fn yperr_string
Returns a pointer to a NUL-terminated error string that does not contain a
1994-10-29 02:03:02 +03:00
.Ql \&.
or
.Ql \en .
.It Fn ypprot_err
1998-01-23 16:49:10 +03:00
Converts a
.Tn YP
protocol error code to a
1994-10-29 02:03:02 +03:00
.Nm ypclnt
error code suitable for
.Fn yperr_string .
.El
.Sh RETURN VALUES
All functions in the
.Nm ypclnt
suite which are of type
.Em int
return 0 upon success or one of the following error codes upon failure:
.Bl -tag -width "YPERR_BADARGS "
.It Bq Er YPERR_BADARGS
The passed arguments to the function are invalid
.It Bq Er YPERR_BADDB
2001-04-09 16:09:11 +04:00
The
1998-01-23 16:49:10 +03:00
.Tn YP
map that was polled is defective.
1994-10-29 02:03:02 +03:00
.It Bq Er YPERR_DOMAIN
2001-04-09 16:09:11 +04:00
Client process cannot bind to server on this
1998-01-23 16:49:10 +03:00
.Tn YP
domain.
1994-10-29 02:03:02 +03:00
.It Bq Er YPERR_KEY
The key passed does not exist.
.It Bq Er YPERR_MAP
There is no such map in the server's domain.
.It Bq Er YPERR_DOM
2001-04-09 16:09:11 +04:00
The local
1998-01-23 16:49:10 +03:00
.Tn YP
domain is not set.
1994-10-29 02:03:02 +03:00
.It Bq Er YPERR_NOMORE
There are no more records in the queried map.
.It Bq Er YPERR_PMAP
Cannot communicate with portmapper (see
2001-04-09 16:09:11 +04:00
.Xr rpcbind 8 ) .
1994-10-29 02:03:02 +03:00
.It Bq Er YPERR_RESRC
A resource allocation failure occurred.
.It Bq Er YPERR_RPC
An RPC failure has occurred.
The domain has been marked unbound.
1994-10-29 02:03:02 +03:00
.It Bq Er YPERR_VERS
Client/server version mismatch.
If the server is running version 1 of the
1998-01-23 16:49:10 +03:00
.Tn YP
protocol,
1994-10-29 02:03:02 +03:00
.Fn yp_all
functionality does not exist.
.It Bq Er YPERR_BIND
Cannot communicate with
.Xr ypbind 8 .
.It Bq Er YPERR_YPERR
An internal server or client error has occurred.
.It Bq Er YPERR_YPSERV
2001-04-09 16:09:11 +04:00
The client cannot communicate with the
1998-01-23 16:49:10 +03:00
.Tn YP
server process.
1994-10-29 02:03:02 +03:00
.El
.Sh SEE ALSO
.Xr malloc 3 ,
.Xr yp 8 ,
2001-09-16 05:33:32 +04:00
.Xr ypbind 8 ,
.Xr ypserv 8
2001-09-16 05:33:32 +04:00
.Sh AUTHORS
.An Theo De Raadt