From 18128546e25fc6e040ef818b124e08bd5c8a362e Mon Sep 17 00:00:00 2001 From: deraadt Date: Wed, 24 Apr 1996 12:55:09 +0000 Subject: [PATCH] yp_prot.h lies -> use yp.h (from yp.x) instead, change lots of structure accesses to match. change xdr_domainname() and some other functions to take "char **" instead of "char *", as rpcgen intended -- helps programs linking against rpcgen output of yp.x. yp_all() should not free it's return value. split xdryp.c and yplib.c into ~20 files so binaries like "csh" need not link in functions like yp_maplist(). NIS+'s YP emulation code lacks YPPROC_ORDER... attempt to deal nicely. --- lib/libc/gen/getgrent.c | 2 +- lib/libc/gen/getpwent.c | 2 +- lib/libc/net/gethostnamadr.c | 2 +- lib/libc/yp/Makefile.inc | 10 +- lib/libc/yp/_yp_check.c | 71 +++ lib/libc/yp/xdr_domainname.c | 57 ++ lib/libc/yp/xdr_keydat.c | 58 ++ lib/libc/yp/xdr_mapname.c | 57 ++ lib/libc/yp/xdr_peername.c | 57 ++ lib/libc/yp/xdr_valdat.c | 58 ++ lib/libc/yp/xdr_ypbind_binding.c | 60 ++ lib/libc/yp/xdr_ypbind_resp.c | 71 +++ lib/libc/yp/xdr_ypbind_resptype.c | 57 ++ lib/libc/yp/xdr_ypbind_setdom.c | 63 ++ lib/libc/yp/xdr_ypmaplist.c | 61 ++ lib/libc/yp/xdr_ypreq_key.c | 63 ++ lib/libc/yp/xdr_ypreq_nokey.c | 60 ++ lib/libc/yp/xdr_ypresp_all.c | 68 +++ lib/libc/yp/xdr_ypresp_key_val.c | 63 ++ lib/libc/yp/xdr_ypresp_maplist.c | 61 ++ lib/libc/yp/xdr_ypresp_master.c | 60 ++ lib/libc/yp/xdr_ypresp_order.c | 60 ++ lib/libc/yp/xdr_ypresp_val.c | 60 ++ lib/libc/yp/xdr_ypstat.c | 57 ++ lib/libc/yp/xdryp.c | 349 ------------ lib/libc/yp/yp_all.c | 166 ++++++ lib/libc/yp/yp_bind.c | 281 +++++++++ lib/libc/yp/yp_first.c | 110 ++++ lib/libc/yp/yp_get_default_domain.c | 65 +++ lib/libc/yp/yp_maplist.c | 85 +++ lib/libc/yp/yp_master.c | 93 +++ lib/libc/yp/yp_order.c | 102 ++++ lib/libc/yp/yperr_string.c | 98 ++++ lib/libc/yp/ypinternal.h | 78 +++ lib/libc/yp/yplib.c | 852 ---------------------------- lib/libc/yp/ypmatch_cache.c | 288 ++++++++++ lib/libc/yp/ypprot_err.c | 83 +++ 37 files changed, 2683 insertions(+), 1205 deletions(-) create mode 100644 lib/libc/yp/_yp_check.c create mode 100644 lib/libc/yp/xdr_domainname.c create mode 100644 lib/libc/yp/xdr_keydat.c create mode 100644 lib/libc/yp/xdr_mapname.c create mode 100644 lib/libc/yp/xdr_peername.c create mode 100644 lib/libc/yp/xdr_valdat.c create mode 100644 lib/libc/yp/xdr_ypbind_binding.c create mode 100644 lib/libc/yp/xdr_ypbind_resp.c create mode 100644 lib/libc/yp/xdr_ypbind_resptype.c create mode 100644 lib/libc/yp/xdr_ypbind_setdom.c create mode 100644 lib/libc/yp/xdr_ypmaplist.c create mode 100644 lib/libc/yp/xdr_ypreq_key.c create mode 100644 lib/libc/yp/xdr_ypreq_nokey.c create mode 100644 lib/libc/yp/xdr_ypresp_all.c create mode 100644 lib/libc/yp/xdr_ypresp_key_val.c create mode 100644 lib/libc/yp/xdr_ypresp_maplist.c create mode 100644 lib/libc/yp/xdr_ypresp_master.c create mode 100644 lib/libc/yp/xdr_ypresp_order.c create mode 100644 lib/libc/yp/xdr_ypresp_val.c create mode 100644 lib/libc/yp/xdr_ypstat.c delete mode 100644 lib/libc/yp/xdryp.c create mode 100644 lib/libc/yp/yp_all.c create mode 100644 lib/libc/yp/yp_bind.c create mode 100644 lib/libc/yp/yp_first.c create mode 100644 lib/libc/yp/yp_get_default_domain.c create mode 100644 lib/libc/yp/yp_maplist.c create mode 100644 lib/libc/yp/yp_master.c create mode 100644 lib/libc/yp/yp_order.c create mode 100644 lib/libc/yp/yperr_string.c create mode 100644 lib/libc/yp/ypinternal.h delete mode 100644 lib/libc/yp/yplib.c create mode 100644 lib/libc/yp/ypmatch_cache.c create mode 100644 lib/libc/yp/ypprot_err.c diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c index da67f603c50..5ce7a7099f6 100644 --- a/lib/libc/gen/getgrent.c +++ b/lib/libc/gen/getgrent.c @@ -49,7 +49,7 @@ static char rcsid[] = "$NetBSD: getgrent.c,v 1.13 1995/07/28 05:43:57 phil Exp $ #include #ifdef YP #include -#include +#include #include #endif diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c index 450921eeee8..e3c0131290f 100644 --- a/lib/libc/gen/getpwent.c +++ b/lib/libc/gen/getpwent.c @@ -58,7 +58,7 @@ static char rcsid[] = "$NetBSD: getpwent.c,v 1.14 1995/07/28 05:43:01 phil Exp $ #include #include #include -#include +#include #include #endif diff --git a/lib/libc/net/gethostnamadr.c b/lib/libc/net/gethostnamadr.c index 6d8072bd79e..a1fdba5f917 100644 --- a/lib/libc/net/gethostnamadr.c +++ b/lib/libc/net/gethostnamadr.c @@ -75,7 +75,7 @@ static char rcsid[] = "$NetBSD: gethostnamadr.c,v 1.13 1995/05/21 16:21:14 mycro #include #ifdef YP #include -#include +#include #include #endif diff --git a/lib/libc/yp/Makefile.inc b/lib/libc/yp/Makefile.inc index 8ab81a555ee..bcc568f1f1e 100644 --- a/lib/libc/yp/Makefile.inc +++ b/lib/libc/yp/Makefile.inc @@ -3,7 +3,15 @@ # yp sources .PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/yp ${.CURDIR}/yp -SRCS+= xdryp.c yplib.c +SRCS+= ypmatch_cache.c yp_bind.c yp_get_default_domain.c \ + yp_first.c yp_all.c yp_order.c \ + yp_master.c yp_maplist.c yperr_string.c ypprot_err.c _yp_check.c \ + xdr_domainname.c xdr_keydat.c xdr_mapname.c xdr_peername.c \ + xdr_valdat.c xdr_ypbind_binding.c xdr_ypbind_resp.c \ + xdr_ypbind_resptype.c xdr_ypbind_setdom.c xdr_ypmaplist.c \ + xdr_ypreq_key.c xdr_ypreq_nokey.c xdr_ypresp_all.c \ + xdr_ypresp_key_val.c xdr_ypresp_maplist.c xdr_ypresp_master.c \ + xdr_ypresp_order.c xdr_ypresp_val.c xdr_ypstat.c MAN+= ypclnt.3 MLINKS+=ypclnt.3 yp_all.3 ypclnt.3 yp_bind.3 ypclnt.3 yp_first.3 \ diff --git a/lib/libc/yp/_yp_check.c b/lib/libc/yp/_yp_check.c new file mode 100644 index 00000000000..6028d65e2ca --- /dev/null +++ b/lib/libc/yp/_yp_check.c @@ -0,0 +1,71 @@ +/* $OpenBSD: _yp_check.c,v 1.1 1996/04/24 12:55:40 deraadt Exp $ */ +/* $NetBSD: yplib.c,v 1.17 1996/02/04 23:26:26 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$NetBSD: yplib.c,v 1.17 1996/02/04 23:26:26 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ypinternal.h" + +int +_yp_check(dom) + char **dom; +{ + char *unused; + + if (_yp_domain[0] == '\0') + if (yp_get_default_domain(&unused)) + return 0; + + if (dom) + *dom = _yp_domain; + + if (yp_bind(_yp_domain) == 0) + return 1; + return 0; +} diff --git a/lib/libc/yp/xdr_domainname.c b/lib/libc/yp/xdr_domainname.c new file mode 100644 index 00000000000..5202d00f1e5 --- /dev/null +++ b/lib/libc/yp/xdr_domainname.c @@ -0,0 +1,57 @@ +/* $OpenBSD: xdr_domainname.c,v 1.1 1996/04/24 12:55:42 deraadt Exp $ */ +/* $NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool_t +xdr_domainname(xdrs, objp) +XDR *xdrs; +domainname *objp; +{ + return xdr_string(xdrs, objp, YPMAXDOMAIN); +} diff --git a/lib/libc/yp/xdr_keydat.c b/lib/libc/yp/xdr_keydat.c new file mode 100644 index 00000000000..a7cb84fa603 --- /dev/null +++ b/lib/libc/yp/xdr_keydat.c @@ -0,0 +1,58 @@ +/* $OpenBSD: xdr_keydat.c,v 1.1 1996/04/24 12:55:43 deraadt Exp $ */ +/* $NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool_t +xdr_keydat(xdrs, objp) +XDR *xdrs; +keydat *objp; +{ + return xdr_bytes(xdrs, (char **)&objp->keydat_val, + (u_int *)&objp->keydat_len, YPMAXRECORD); +} diff --git a/lib/libc/yp/xdr_mapname.c b/lib/libc/yp/xdr_mapname.c new file mode 100644 index 00000000000..93cfc8f03e6 --- /dev/null +++ b/lib/libc/yp/xdr_mapname.c @@ -0,0 +1,57 @@ +/* $OpenBSD: xdr_mapname.c,v 1.1 1996/04/24 12:55:44 deraadt Exp $ */ +/* $NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool_t +xdr_mapname(xdrs, objp) +XDR *xdrs; +mapname *objp; +{ + return xdr_string(xdrs, objp, YPMAXMAP); +} diff --git a/lib/libc/yp/xdr_peername.c b/lib/libc/yp/xdr_peername.c new file mode 100644 index 00000000000..61f8c116005 --- /dev/null +++ b/lib/libc/yp/xdr_peername.c @@ -0,0 +1,57 @@ +/* $OpenBSD: xdr_peername.c,v 1.1 1996/04/24 12:55:46 deraadt Exp $ */ +/* $NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool_t +xdr_peername(xdrs, objp) +XDR *xdrs; +peername *objp; +{ + return xdr_string(xdrs, objp, YPMAXPEER); +} diff --git a/lib/libc/yp/xdr_valdat.c b/lib/libc/yp/xdr_valdat.c new file mode 100644 index 00000000000..35350ab7d69 --- /dev/null +++ b/lib/libc/yp/xdr_valdat.c @@ -0,0 +1,58 @@ +/* $OpenBSD: xdr_valdat.c,v 1.1 1996/04/24 12:55:47 deraadt Exp $ */ +/* $NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool_t +xdr_valdat(xdrs, objp) +XDR *xdrs; +valdat *objp; +{ + return xdr_bytes(xdrs, (char **)&objp->valdat_val, + (u_int *)&objp->valdat_len, YPMAXRECORD); +} diff --git a/lib/libc/yp/xdr_ypbind_binding.c b/lib/libc/yp/xdr_ypbind_binding.c new file mode 100644 index 00000000000..05213ed6d01 --- /dev/null +++ b/lib/libc/yp/xdr_ypbind_binding.c @@ -0,0 +1,60 @@ +/* $OpenBSD: xdr_ypbind_binding.c,v 1.1 1996/04/24 12:55:49 deraadt Exp $ */ +/* $NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool_t +xdr_ypbind_binding(xdrs, objp) +XDR *xdrs; +struct ypbind_binding *objp; +{ + if (!xdr_opaque(xdrs, objp->ypbind_binding_addr, 4)) { + return (FALSE); + } + return xdr_opaque(xdrs, objp->ypbind_binding_port, 2); +} diff --git a/lib/libc/yp/xdr_ypbind_resp.c b/lib/libc/yp/xdr_ypbind_resp.c new file mode 100644 index 00000000000..927ac19ca3d --- /dev/null +++ b/lib/libc/yp/xdr_ypbind_resp.c @@ -0,0 +1,71 @@ +/* $OpenBSD: xdr_ypbind_resp.c,v 1.1 1996/04/24 12:55:50 deraadt Exp $ */ +/* $NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool_t +xdr_ypbind_resp(xdrs, objp) +XDR *xdrs; +struct ypbind_resp *objp; +{ + if (!xdr_ypbind_resptype(xdrs, &objp->ypbind_status)) { + return FALSE; + } + + switch (objp->ypbind_status) { + case YPBIND_FAIL_VAL: + return xdr_u_int(xdrs, + (u_int *)&objp->ypbind_resp_u.ypbind_error); + case YPBIND_SUCC_VAL: + return xdr_ypbind_binding(xdrs, + &objp->ypbind_resp_u.ypbind_bindinfo); + default: + return FALSE; + } + /* NOTREACHED */ +} diff --git a/lib/libc/yp/xdr_ypbind_resptype.c b/lib/libc/yp/xdr_ypbind_resptype.c new file mode 100644 index 00000000000..16413da3b8e --- /dev/null +++ b/lib/libc/yp/xdr_ypbind_resptype.c @@ -0,0 +1,57 @@ +/* $OpenBSD: xdr_ypbind_resptype.c,v 1.1 1996/04/24 12:55:51 deraadt Exp $ */ +/* $NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool_t +xdr_ypbind_resptype(xdrs, objp) +XDR *xdrs; +enum ypbind_resptype *objp; +{ + return xdr_enum(xdrs, (enum_t *)objp); +} diff --git a/lib/libc/yp/xdr_ypbind_setdom.c b/lib/libc/yp/xdr_ypbind_setdom.c new file mode 100644 index 00000000000..67cf676d9ab --- /dev/null +++ b/lib/libc/yp/xdr_ypbind_setdom.c @@ -0,0 +1,63 @@ +/* $OpenBSD: xdr_ypbind_setdom.c,v 1.1 1996/04/24 12:55:52 deraadt Exp $ */ +/* $NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool_t +xdr_ypbind_setdom(xdrs, objp) +XDR *xdrs; +struct ypbind_setdom *objp; +{ + if (!xdr_domainname(xdrs, (domainname *)&objp->ypsetdom_domain)) { + return FALSE; + } + if (!xdr_ypbind_binding(xdrs, &objp->ypsetdom_binding)) { + return FALSE; + } + return xdr_u_int(xdrs, (u_int *)&objp->ypsetdom_vers); +} diff --git a/lib/libc/yp/xdr_ypmaplist.c b/lib/libc/yp/xdr_ypmaplist.c new file mode 100644 index 00000000000..7e2b2c04c99 --- /dev/null +++ b/lib/libc/yp/xdr_ypmaplist.c @@ -0,0 +1,61 @@ +/* $OpenBSD: xdr_ypmaplist.c,v 1.1 1996/04/24 12:55:56 deraadt Exp $ */ +/* $NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool_t +xdr_ypmaplist(xdrs, objp) +XDR *xdrs; +struct ypmaplist *objp; +{ + if (!xdr_mapname(xdrs, (mapname *)&objp->map)) { + return FALSE; + } + return xdr_pointer(xdrs, (caddr_t *)&objp->next, + sizeof(struct ypmaplist), xdr_ypmaplist); +} diff --git a/lib/libc/yp/xdr_ypreq_key.c b/lib/libc/yp/xdr_ypreq_key.c new file mode 100644 index 00000000000..7f1fb6a18ad --- /dev/null +++ b/lib/libc/yp/xdr_ypreq_key.c @@ -0,0 +1,63 @@ +/* $OpenBSD: xdr_ypreq_key.c,v 1.1 1996/04/24 12:55:58 deraadt Exp $ */ +/* $NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool_t +xdr_ypreq_key(xdrs, objp) +XDR *xdrs; +struct ypreq_key *objp; +{ + if (!xdr_domainname(xdrs, (domainname *)&objp->domain)) { + return FALSE; + } + if (!xdr_mapname(xdrs, (mapname *)&objp->map)) { + return FALSE; + } + return xdr_keydat(xdrs, &objp->key); +} diff --git a/lib/libc/yp/xdr_ypreq_nokey.c b/lib/libc/yp/xdr_ypreq_nokey.c new file mode 100644 index 00000000000..237db4909a6 --- /dev/null +++ b/lib/libc/yp/xdr_ypreq_nokey.c @@ -0,0 +1,60 @@ +/* $OpenBSD: xdr_ypreq_nokey.c,v 1.1 1996/04/24 12:55:59 deraadt Exp $ */ +/* $NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool_t +xdr_ypreq_nokey(xdrs, objp) +XDR *xdrs; +struct ypreq_nokey *objp; +{ + if (!xdr_domainname(xdrs, (domainname *)&objp->domain)) { + return FALSE; + } + return xdr_mapname(xdrs, (mapname *)&objp->map); +} diff --git a/lib/libc/yp/xdr_ypresp_all.c b/lib/libc/yp/xdr_ypresp_all.c new file mode 100644 index 00000000000..ccbc99fd094 --- /dev/null +++ b/lib/libc/yp/xdr_ypresp_all.c @@ -0,0 +1,68 @@ +/* $OpenBSD: xdr_ypresp_all.c,v 1.1 1996/04/24 12:56:01 deraadt Exp $ */ +/* $NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool_t +xdr_ypresp_all(xdrs, objp) +XDR *xdrs; +struct ypresp_all *objp; +{ + if (!xdr_bool(xdrs, &objp->more)) { + return FALSE; + } + switch (objp->more) { + case TRUE: + return xdr_ypresp_key_val(xdrs, &objp->ypresp_all_u.val); + case FALSE: + return (TRUE); + default: + return FALSE; + } + /* NOTREACHED */ +} diff --git a/lib/libc/yp/xdr_ypresp_key_val.c b/lib/libc/yp/xdr_ypresp_key_val.c new file mode 100644 index 00000000000..ca11c4a183a --- /dev/null +++ b/lib/libc/yp/xdr_ypresp_key_val.c @@ -0,0 +1,63 @@ +/* $OpenBSD: xdr_ypresp_key_val.c,v 1.1 1996/04/24 12:56:04 deraadt Exp $ */ +/* $NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool_t +xdr_ypresp_key_val(xdrs, objp) +XDR *xdrs; +struct ypresp_key_val *objp; +{ + if (!xdr_ypstat(xdrs, (ypstat *)&objp->stat)) { + return FALSE; + } + if (!xdr_valdat(xdrs, &objp->val)) { + return FALSE; + } + return xdr_keydat(xdrs, &objp->key); +} diff --git a/lib/libc/yp/xdr_ypresp_maplist.c b/lib/libc/yp/xdr_ypresp_maplist.c new file mode 100644 index 00000000000..5f66d5c42db --- /dev/null +++ b/lib/libc/yp/xdr_ypresp_maplist.c @@ -0,0 +1,61 @@ +/* $OpenBSD: xdr_ypresp_maplist.c,v 1.1 1996/04/24 12:56:06 deraadt Exp $ */ +/* $NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool_t +xdr_ypresp_maplist(xdrs, objp) +XDR *xdrs; +struct ypresp_maplist *objp; +{ + if (!xdr_ypstat(xdrs, (ypstat *)&objp->stat)) { + return FALSE; + } + return xdr_pointer(xdrs, (caddr_t *)&objp->maps, + sizeof(struct ypmaplist), xdr_ypmaplist); +} diff --git a/lib/libc/yp/xdr_ypresp_master.c b/lib/libc/yp/xdr_ypresp_master.c new file mode 100644 index 00000000000..625f1c768f6 --- /dev/null +++ b/lib/libc/yp/xdr_ypresp_master.c @@ -0,0 +1,60 @@ +/* $OpenBSD: xdr_ypresp_master.c,v 1.1 1996/04/24 12:56:07 deraadt Exp $ */ +/* $NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool_t +xdr_ypresp_master(xdrs, objp) +XDR *xdrs; +struct ypresp_master *objp; +{ + if (!xdr_ypstat(xdrs, (ypstat *)&objp->stat)) { + return FALSE; + } + return xdr_peername(xdrs, (peername *)&objp->peer); +} diff --git a/lib/libc/yp/xdr_ypresp_order.c b/lib/libc/yp/xdr_ypresp_order.c new file mode 100644 index 00000000000..1b1643c2876 --- /dev/null +++ b/lib/libc/yp/xdr_ypresp_order.c @@ -0,0 +1,60 @@ +/* $OpenBSD: xdr_ypresp_order.c,v 1.1 1996/04/24 12:56:09 deraadt Exp $ */ +/* $NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool_t +xdr_ypresp_order(xdrs, objp) +XDR *xdrs; +struct ypresp_order *objp; +{ + if (!xdr_ypstat(xdrs, (ypstat *)&objp->stat)) { + return FALSE; + } + return xdr_u_int(xdrs, (u_int *)&objp->ordernum); +} diff --git a/lib/libc/yp/xdr_ypresp_val.c b/lib/libc/yp/xdr_ypresp_val.c new file mode 100644 index 00000000000..daa4fd71c44 --- /dev/null +++ b/lib/libc/yp/xdr_ypresp_val.c @@ -0,0 +1,60 @@ +/* $OpenBSD: xdr_ypresp_val.c,v 1.1 1996/04/24 12:56:10 deraadt Exp $ */ +/* $NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool_t +xdr_ypresp_val(xdrs, objp) +XDR *xdrs; +struct ypresp_val *objp; +{ + if (!xdr_ypstat(xdrs, (ypstat *)&objp->stat)) { + return FALSE; + } + return xdr_valdat(xdrs, &objp->val); +} diff --git a/lib/libc/yp/xdr_ypstat.c b/lib/libc/yp/xdr_ypstat.c new file mode 100644 index 00000000000..97fc280aa72 --- /dev/null +++ b/lib/libc/yp/xdr_ypstat.c @@ -0,0 +1,57 @@ +/* $OpenBSD: xdr_ypstat.c,v 1.1 1996/04/24 12:56:11 deraadt Exp $ */ +/* $NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool_t +xdr_ypstat(xdrs, objp) +XDR *xdrs; +ypstat *objp; +{ + return xdr_enum(xdrs, objp); +} diff --git a/lib/libc/yp/xdryp.c b/lib/libc/yp/xdryp.c deleted file mode 100644 index e8a8b06b568..00000000000 --- a/lib/libc/yp/xdryp.c +++ /dev/null @@ -1,349 +0,0 @@ -/* $OpenBSD: xdryp.c,v 1.3 1996/03/09 02:43:00 niklas Exp $ */ -/* $NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $ */ - -/* - * Copyright (c) 1992, 1993 Theo de Raadt - * All rights reserved. - * - * 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 Theo de Raadt. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$NetBSD: xdryp.c,v 1.10 1996/02/04 23:26:21 jtc Exp $"; -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -extern int (*ypresp_allfn) __P((u_long, char *, int, char *, int, void *)); -extern void *ypresp_data; - -bool_t -xdr_domainname(xdrs, objp) -XDR *xdrs; -char *objp; -{ - return xdr_string(xdrs, &objp, YPMAXDOMAIN); -} - -bool_t -xdr_peername(xdrs, objp) -XDR *xdrs; -char *objp; -{ - return xdr_string(xdrs, &objp, YPMAXPEER); -} - -bool_t -xdr_datum(xdrs, objp) -XDR *xdrs; -datum *objp; -{ - return xdr_bytes(xdrs, (char **)&objp->dptr, - (u_int *)&objp->dsize, YPMAXRECORD); -} - -bool_t -xdr_mapname(xdrs, objp) -XDR *xdrs; -char *objp; -{ - return xdr_string(xdrs, &objp, YPMAXMAP); -} - -bool_t -xdr_ypreq_key(xdrs, objp) -XDR *xdrs; -struct ypreq_key *objp; -{ - if (!xdr_domainname(xdrs, (char *)objp->domain)) { - return FALSE; - } - if (!xdr_mapname(xdrs, (char *)objp->map)) { - return FALSE; - } - return xdr_datum(xdrs, &objp->keydat); -} - -bool_t -xdr_ypreq_nokey(xdrs, objp) -XDR *xdrs; -struct ypreq_nokey *objp; -{ - if (!xdr_domainname(xdrs, (char *)objp->domain)) { - return FALSE; - } - return xdr_mapname(xdrs, (char *)objp->map); -} - -bool_t -xdr_yp_inaddr(xdrs, objp) -XDR *xdrs; -struct in_addr *objp; -{ - return xdr_opaque(xdrs, (caddr_t)&objp->s_addr, sizeof objp->s_addr); -} - -bool_t -xdr_ypbind_binding(xdrs, objp) -XDR *xdrs; -struct ypbind_binding *objp; -{ - if (!xdr_yp_inaddr(xdrs, &objp->ypbind_binding_addr)) { - return FALSE; - } - return xdr_opaque(xdrs, (void *)&objp->ypbind_binding_port, - sizeof objp->ypbind_binding_port); -} - -bool_t -xdr_ypbind_resptype(xdrs, objp) -XDR *xdrs; -enum ypbind_resptype *objp; -{ - return xdr_enum(xdrs, (enum_t *)objp); -} - -bool_t -xdr_ypstat(xdrs, objp) -XDR *xdrs; -enum ypbind_resptype *objp; -{ - return xdr_enum(xdrs, (enum_t *)objp); -} - -bool_t -xdr_ypbind_resp(xdrs, objp) -XDR *xdrs; -struct ypbind_resp *objp; -{ - if (!xdr_ypbind_resptype(xdrs, &objp->ypbind_status)) { - return FALSE; - } - - switch (objp->ypbind_status) { - case YPBIND_FAIL_VAL: - return xdr_u_int(xdrs, - (u_int *)&objp->ypbind_respbody.ypbind_error); - case YPBIND_SUCC_VAL: - return xdr_ypbind_binding(xdrs, - &objp->ypbind_respbody.ypbind_bindinfo); - default: - return FALSE; - } - /* NOTREACHED */ -} - -bool_t -xdr_ypresp_val(xdrs, objp) -XDR *xdrs; -struct ypresp_val *objp; -{ - if (!xdr_ypstat(xdrs, (enum ypbind_resptype *)&objp->status)) { - return FALSE; - } - return xdr_datum(xdrs, &objp->valdat); -} - -bool_t -xdr_ypbind_setdom(xdrs, objp) -XDR *xdrs; -struct ypbind_setdom *objp; -{ - if (!xdr_domainname(xdrs, objp->ypsetdom_domain)) { - return FALSE; - } - if (!xdr_ypbind_binding(xdrs, &objp->ypsetdom_binding)) { - return FALSE; - } - return xdr_u_short(xdrs, &objp->ypsetdom_vers); -} - -bool_t -xdr_ypresp_key_val(xdrs, objp) -XDR *xdrs; -struct ypresp_key_val *objp; -{ - if (!xdr_ypstat(xdrs, (enum ypbind_resptype *)&objp->status)) { - return FALSE; - } - if (!xdr_datum(xdrs, &objp->valdat)) { - return FALSE; - } - return xdr_datum(xdrs, &objp->keydat); -} - -bool_t -xdr_ypresp_all(xdrs, objp) -XDR *xdrs; -struct ypresp_all *objp; -{ - if (!xdr_bool(xdrs, &objp->more)) { - return FALSE; - } - switch (objp->more) { - case TRUE: - return xdr_ypresp_key_val(xdrs, &objp->ypresp_all_u.val); - case FALSE: - return (TRUE); - default: - return FALSE; - } - /* NOTREACHED */ -} - -bool_t -xdr_ypresp_all_seq(xdrs, objp) -XDR *xdrs; -u_long *objp; -{ - struct ypresp_all out; - u_long status; - char *key, *val; - int size; - int r; - - memset(&out, 0, sizeof out); - while(1) { - if( !xdr_ypresp_all(xdrs, &out)) { - xdr_free(xdr_ypresp_all, (char *)&out); - *objp = YP_YPERR; - return FALSE; - } - if(out.more == 0) { - xdr_free(xdr_ypresp_all, (char *)&out); - return FALSE; - } - status = out.ypresp_all_u.val.status; - switch(status) { - case YP_TRUE: - size = out.ypresp_all_u.val.keydat.dsize; - if ((key = malloc(size + 1)) != NULL) { - (void)memcpy(key, - out.ypresp_all_u.val.keydat.dptr, - size); - key[size] = '\0'; - } - size = out.ypresp_all_u.val.valdat.dsize; - if ((val = malloc(size + 1)) != NULL) { - (void)memcpy(val, - out.ypresp_all_u.val.valdat.dptr, - size); - val[size] = '\0'; - } - else { - free(key); - key = NULL; - } - xdr_free(xdr_ypresp_all, (char *)&out); - - if (key == NULL || val == NULL) - return FALSE; - - r = (*ypresp_allfn)(status, - key, out.ypresp_all_u.val.keydat.dsize, - val, out.ypresp_all_u.val.valdat.dsize, - ypresp_data); - *objp = status; - free(key); - free(val); - if(r) - return TRUE; - break; - case YP_NOMORE: - xdr_free(xdr_ypresp_all, (char *)&out); - return TRUE; - default: - xdr_free(xdr_ypresp_all, (char *)&out); - *objp = status; - return TRUE; - } - } -} - -bool_t -xdr_ypresp_master(xdrs, objp) -XDR *xdrs; -struct ypresp_master *objp; -{ - if (!xdr_ypstat(xdrs, (enum ypbind_resptype *)&objp->status)) { - return FALSE; - } - return xdr_string(xdrs, &objp->master, YPMAXPEER); -} - -bool_t -xdr_ypmaplist_str(xdrs, objp) -XDR *xdrs; -char *objp; -{ - return xdr_string(xdrs, &objp, YPMAXMAP+1); -} - -bool_t -xdr_ypmaplist(xdrs, objp) -XDR *xdrs; -struct ypmaplist *objp; -{ - if (!xdr_ypmaplist_str(xdrs, objp->ypml_name)) { - return FALSE; - } - return xdr_pointer(xdrs, (caddr_t *)&objp->ypml_next, - sizeof(struct ypmaplist), xdr_ypmaplist); -} - -bool_t -xdr_ypresp_maplist(xdrs, objp) -XDR *xdrs; -struct ypresp_maplist *objp; -{ - if (!xdr_ypstat(xdrs, (enum ypbind_resptype *)&objp->status)) { - return FALSE; - } - return xdr_pointer(xdrs, (caddr_t *)&objp->list, - sizeof(struct ypmaplist), xdr_ypmaplist); -} - -bool_t -xdr_ypresp_order(xdrs, objp) -XDR *xdrs; -struct ypresp_order *objp; -{ - if (!xdr_ypstat(xdrs, (enum ypbind_resptype *)&objp->status)) { - return FALSE; - } - return xdr_u_long(xdrs, &objp->ordernum); -} diff --git a/lib/libc/yp/yp_all.c b/lib/libc/yp/yp_all.c new file mode 100644 index 00000000000..2a7f5eede5d --- /dev/null +++ b/lib/libc/yp/yp_all.c @@ -0,0 +1,166 @@ +/* $OpenBSD: yp_all.c,v 1.1 1996/04/24 12:56:16 deraadt Exp $ */ +/* $NetBSD: yplib.c,v 1.17 1996/02/04 23:26:26 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$NetBSD: yplib.c,v 1.17 1996/02/04 23:26:26 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ypinternal.h" + +bool_t +xdr_ypresp_all_seq(xdrs, objp) +XDR *xdrs; +u_long *objp; +{ + struct ypresp_all out; + u_long status; + char *key, *val; + int size; + int r; + + memset(&out, 0, sizeof out); + while(1) { + if( !xdr_ypresp_all(xdrs, &out)) { + xdr_free(xdr_ypresp_all, (char *)&out); + *objp = YP_YPERR; + return FALSE; + } + if(out.more == 0) { + xdr_free(xdr_ypresp_all, (char *)&out); + return FALSE; + } + status = out.ypresp_all_u.val.stat; + switch(status) { + case YP_TRUE: + size = out.ypresp_all_u.val.key.keydat_len; + if ((key = malloc(size + 1)) != NULL) { + (void)memcpy(key, + out.ypresp_all_u.val.key.keydat_val, + size); + key[size] = '\0'; + } + size = out.ypresp_all_u.val.val.valdat_len; + if ((val = malloc(size + 1)) != NULL) { + (void)memcpy(val, + out.ypresp_all_u.val.val.valdat_val, + size); + val[size] = '\0'; + } + else { + free(key); + key = NULL; + } + xdr_free(xdr_ypresp_all, (char *)&out); + + if (key == NULL || val == NULL) + return FALSE; + + r = (*ypresp_allfn)(status, + key, out.ypresp_all_u.val.key.keydat_len, + val, out.ypresp_all_u.val.val.valdat_len, + ypresp_data); + *objp = status; + free(key); + free(val); + if(r) + return TRUE; + break; + case YP_NOMORE: + xdr_free(xdr_ypresp_all, (char *)&out); + return TRUE; + default: + xdr_free(xdr_ypresp_all, (char *)&out); + *objp = status; + return TRUE; + } + } +} + +int +yp_all(indomain, inmap, incallback) + const char *indomain; + const char *inmap; + struct ypall_callback *incallback; +{ + struct ypreq_nokey yprnk; + struct dom_binding *ysd; + struct timeval tv; + struct sockaddr_in clnt_sin; + CLIENT *clnt; + u_long status; + int clnt_sock; + int r = 0; + + if (_yp_dobind(indomain, &ysd) != 0) + return YPERR_DOMAIN; + + tv.tv_sec = _yplib_timeout; + tv.tv_usec = 0; + clnt_sock = RPC_ANYSOCK; + clnt_sin = ysd->dom_server_addr; + clnt_sin.sin_port = 0; + clnt = clnttcp_create(&clnt_sin, YPPROG, YPVERS, &clnt_sock, 0, 0); + if (clnt == NULL) { + printf("clnttcp_create failed\n"); + r = YPERR_PMAP; + goto out; + } + yprnk.domain = (char *)indomain; + yprnk.map = (char *)inmap; + ypresp_allfn = incallback->foreach; + ypresp_data = (void *) incallback->data; + + (void) clnt_call(clnt, YPPROC_ALL, + xdr_ypreq_nokey, &yprnk, xdr_ypresp_all_seq, &status, tv); + clnt_destroy(clnt); + if(status != YP_FALSE) + r = ypprot_err(status); +out: + _yp_unbind(ysd); + return r; +} diff --git a/lib/libc/yp/yp_bind.c b/lib/libc/yp/yp_bind.c new file mode 100644 index 00000000000..eda85e693f0 --- /dev/null +++ b/lib/libc/yp/yp_bind.c @@ -0,0 +1,281 @@ +/* $OpenBSD: yp_bind.c,v 1.1 1996/04/24 12:56:18 deraadt Exp $ */ +/* $NetBSD: yplib.c,v 1.17 1996/02/04 23:26:26 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$NetBSD: yplib.c,v 1.17 1996/02/04 23:26:26 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ypinternal.h" + +struct dom_binding *_ypbindlist; +char _yp_domain[MAXHOSTNAMELEN]; +int _yplib_timeout = 10; + +int +_yp_dobind(dom, ypdb) + const char *dom; + struct dom_binding **ypdb; +{ + static int pid = -1; + char path[MAXPATHLEN]; + struct dom_binding *ysd, *ysd2; + struct ypbind_resp ypbr; + struct timeval tv; + struct sockaddr_in clnt_sin; + int clnt_sock, fd, gpid; + CLIENT *client; + int new = 0, r; + int count = 0; + + /* + * test if YP is running or not + */ + if ((fd = open(YPBINDLOCK, O_RDONLY)) == -1) + return YPERR_YPBIND; + if (!(flock(fd, LOCK_EX | LOCK_NB) == -1 && errno == EWOULDBLOCK)) { + (void)close(fd); + return YPERR_YPBIND; + } + (void)close(fd); + + gpid = getpid(); + if (!(pid == -1 || pid == gpid)) { + ysd = _ypbindlist; + while (ysd) { + if (ysd->dom_client) + clnt_destroy(ysd->dom_client); + ysd2 = ysd->dom_pnext; + free(ysd); + ysd = ysd2; + } + _ypbindlist = NULL; + } + pid = gpid; + + if (ypdb != NULL) + *ypdb = NULL; + + if (dom == NULL || strlen(dom) == 0) + return YPERR_BADARGS; + + for (ysd = _ypbindlist; ysd; ysd = ysd->dom_pnext) + if (strcmp(dom, ysd->dom_domain) == 0) + break; + if (ysd == NULL) { + if ((ysd = malloc(sizeof *ysd)) == NULL) + return YPERR_YPERR; + (void)memset(ysd, 0, sizeof *ysd); + ysd->dom_socket = -1; + ysd->dom_vers = 0; + new = 1; + } +again: + if (ysd->dom_vers == 0) { + (void) snprintf(path, sizeof(path), "%s/%s.%d", + BINDINGDIR, dom, 2); + if ((fd = open(path, O_RDONLY)) == -1) { + /* + * no binding file, YP is dead, or not yet fully + * alive. + */ + goto trynet; + } + if (flock(fd, LOCK_EX | LOCK_NB) == -1 && + errno == EWOULDBLOCK) { + struct iovec iov[2]; + struct ypbind_resp ybr; + u_short ypb_port; + struct ypbind_binding *bn; + + iov[0].iov_base = (caddr_t) & ypb_port; + iov[0].iov_len = sizeof ypb_port; + iov[1].iov_base = (caddr_t) & ybr; + iov[1].iov_len = sizeof ybr; + + r = readv(fd, iov, 2); + if (r != iov[0].iov_len + iov[1].iov_len) { + (void)close(fd); + ysd->dom_vers = -1; + goto again; + } + (void)memset(&ysd->dom_server_addr, 0, + sizeof ysd->dom_server_addr); + ysd->dom_server_addr.sin_len = + sizeof(struct sockaddr_in); + ysd->dom_server_addr.sin_family = AF_INET; + bn = &ybr.ypbind_resp_u.ypbind_bindinfo; + memcpy(&ysd->dom_server_addr.sin_port, + &bn->ypbind_binding_port, + sizeof(ysd->dom_server_addr.sin_port)); + + memcpy(&ysd->dom_server_addr.sin_addr, + &bn->ypbind_binding_addr, + sizeof(ysd->dom_server_addr.sin_addr)); + + + ysd->dom_server_port = ysd->dom_server_addr.sin_port; + (void)close(fd); + goto gotit; + } else { + /* no lock on binding file, YP is dead. */ + (void)close(fd); + if (new) + free(ysd); + return YPERR_YPBIND; + } + } +trynet: + if (ysd->dom_vers == -1 || ysd->dom_vers == 0) { + struct ypbind_binding *bn; + (void)memset(&clnt_sin, 0, sizeof clnt_sin); + clnt_sin.sin_len = sizeof(struct sockaddr_in); + clnt_sin.sin_family = AF_INET; + clnt_sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + + clnt_sock = RPC_ANYSOCK; + client = clnttcp_create(&clnt_sin, YPBINDPROG, YPBINDVERS, + &clnt_sock, 0, 0); + if (client == NULL) { + clnt_pcreateerror("clnttcp_create"); + if (new) + free(ysd); + return YPERR_YPBIND; + } + tv.tv_sec = _yplib_timeout; + tv.tv_usec = 0; + r = clnt_call(client, YPBINDPROC_DOMAIN, xdr_domainname, + &dom, xdr_ypbind_resp, &ypbr, tv); + if (r != RPC_SUCCESS) { + if (new == 0 || count) + fprintf(stderr, + "YP server for domain %s not responding, still trying\n", + dom); + count++; + clnt_destroy(client); + ysd->dom_vers = -1; + goto again; + } + clnt_destroy(client); + + (void)memset(&ysd->dom_server_addr, 0, + sizeof ysd->dom_server_addr); + ysd->dom_server_addr.sin_len = sizeof(struct sockaddr_in); + ysd->dom_server_addr.sin_family = AF_INET; + bn = &ypbr.ypbind_resp_u.ypbind_bindinfo; + memcpy(&ysd->dom_server_addr.sin_port, + &bn->ypbind_binding_port, + sizeof(ysd->dom_server_addr.sin_port)); + memcpy(&ysd->dom_server_addr.sin_addr.s_addr, + &bn->ypbind_binding_addr, + sizeof(ysd->dom_server_addr.sin_addr.s_addr)); + ysd->dom_server_port = ysd->dom_server_addr.sin_port; +gotit: + ysd->dom_vers = YPVERS; + (void)strcpy(ysd->dom_domain, dom); + } + tv.tv_sec = _yplib_timeout / 2; + tv.tv_usec = 0; + if (ysd->dom_client) + clnt_destroy(ysd->dom_client); + ysd->dom_socket = RPC_ANYSOCK; + ysd->dom_client = clntudp_create(&ysd->dom_server_addr, + YPPROG, YPVERS, tv, &ysd->dom_socket); + if (ysd->dom_client == NULL) { + clnt_pcreateerror("clntudp_create"); + ysd->dom_vers = -1; + goto again; + } + if (fcntl(ysd->dom_socket, F_SETFD, 1) == -1) + perror("fcntl: F_SETFD"); + + if (new) { + ysd->dom_pnext = _ypbindlist; + _ypbindlist = ysd; + } + if (ypdb != NULL) + *ypdb = ysd; + return 0; +} + +void +_yp_unbind(ypb) + struct dom_binding *ypb; +{ + clnt_destroy(ypb->dom_client); + ypb->dom_client = NULL; + ypb->dom_socket = -1; +} + +int +yp_bind(dom) + const char *dom; +{ + return _yp_dobind(dom, NULL); +} + +void +yp_unbind(dom) + const char *dom; +{ + struct dom_binding *ypb, *ypbp; + + ypbp = NULL; + for (ypb = _ypbindlist; ypb; ypb = ypb->dom_pnext) { + if (strcmp(dom, ypb->dom_domain) == 0) { + clnt_destroy(ypb->dom_client); + if (ypbp) + ypbp->dom_pnext = ypb->dom_pnext; + else + _ypbindlist = ypb->dom_pnext; + free(ypb); + return; + } + ypbp = ypb; + } + return; +} diff --git a/lib/libc/yp/yp_first.c b/lib/libc/yp/yp_first.c new file mode 100644 index 00000000000..10f16a5fdfb --- /dev/null +++ b/lib/libc/yp/yp_first.c @@ -0,0 +1,110 @@ +/* $OpenBSD: yp_first.c,v 1.1 1996/04/24 12:56:19 deraadt Exp $ */ +/* $NetBSD: yplib.c,v 1.17 1996/02/04 23:26:26 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$NetBSD: yplib.c,v 1.17 1996/02/04 23:26:26 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ypinternal.h" + +int +yp_first(indomain, inmap, outkey, outkeylen, outval, outvallen) + const char *indomain; + const char *inmap; + char **outkey; + int *outkeylen; + char **outval; + int *outvallen; +{ + struct ypresp_key_val yprkv; + struct ypreq_nokey yprnk; + struct dom_binding *ysd; + struct timeval tv; + int r; + + *outkey = *outval = NULL; + *outkeylen = *outvallen = 0; + +again: + if (_yp_dobind(indomain, &ysd) != 0) + return YPERR_DOMAIN; + + tv.tv_sec = _yplib_timeout; + tv.tv_usec = 0; + + yprnk.domain = (char *)indomain; + yprnk.map = (char *)inmap; + (void)memset(&yprkv, 0, sizeof yprkv); + + r = clnt_call(ysd->dom_client, YPPROC_FIRST, + xdr_ypreq_nokey, &yprnk, xdr_ypresp_key_val, &yprkv, tv); + if (r != RPC_SUCCESS) { + clnt_perror(ysd->dom_client, "yp_first: clnt_call"); + ysd->dom_vers = -1; + goto again; + } + if (!(r = ypprot_err(yprkv.stat))) { + *outkeylen = yprkv.key.keydat_len; + if ((*outkey = malloc(*outkeylen + 1)) == NULL) + r = RPC_SYSTEMERROR; + else { + (void)memcpy(*outkey, yprkv.key.keydat_val, *outkeylen); + (*outkey)[*outkeylen] = '\0'; + } + *outvallen = yprkv.val.valdat_len; + if ((*outval = malloc(*outvallen + 1)) == NULL) + r = RPC_SYSTEMERROR; + else { + (void)memcpy(*outval, yprkv.val.valdat_val, *outvallen); + (*outval)[*outvallen] = '\0'; + } + } + xdr_free(xdr_ypresp_key_val, (char *) &yprkv); + _yp_unbind(ysd); + return r; +} diff --git a/lib/libc/yp/yp_get_default_domain.c b/lib/libc/yp/yp_get_default_domain.c new file mode 100644 index 00000000000..2c727778d8c --- /dev/null +++ b/lib/libc/yp/yp_get_default_domain.c @@ -0,0 +1,65 @@ +/* $OpenBSD: yp_get_default_domain.c,v 1.1 1996/04/24 12:56:20 deraadt Exp $ */ +/* $NetBSD: yplib.c,v 1.17 1996/02/04 23:26:26 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$NetBSD: yplib.c,v 1.17 1996/02/04 23:26:26 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ypinternal.h" + +int +yp_get_default_domain(domp) + char **domp; +{ + *domp = NULL; + if (_yp_domain[0] == '\0') + if (getdomainname(_yp_domain, sizeof _yp_domain)) + return YPERR_NODOM; + *domp = _yp_domain; + return 0; +} diff --git a/lib/libc/yp/yp_maplist.c b/lib/libc/yp/yp_maplist.c new file mode 100644 index 00000000000..5932ea9612c --- /dev/null +++ b/lib/libc/yp/yp_maplist.c @@ -0,0 +1,85 @@ +/* $OpenBSD: yp_maplist.c,v 1.1 1996/04/24 12:56:22 deraadt Exp $ */ +/* $NetBSD: yplib.c,v 1.17 1996/02/04 23:26:26 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$NetBSD: yplib.c,v 1.17 1996/02/04 23:26:26 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ypinternal.h" + +int +yp_maplist(indomain, outmaplist) + const char *indomain; + struct ypmaplist **outmaplist; +{ + struct dom_binding *ysd; + struct ypresp_maplist ypml; + struct timeval tv; + int r; + +again: + if (_yp_dobind(indomain, &ysd) != 0) + return YPERR_DOMAIN; + + tv.tv_sec = _yplib_timeout; + tv.tv_usec = 0; + + memset(&ypml, 0, sizeof ypml); + + r = clnt_call(ysd->dom_client, YPPROC_MAPLIST, + xdr_domainname, &indomain, xdr_ypresp_maplist, &ypml, tv); + if (r != RPC_SUCCESS) { + clnt_perror(ysd->dom_client, "yp_maplist: clnt_call"); + ysd->dom_vers = -1; + goto again; + } + *outmaplist = ypml.maps; + /* NO: xdr_free(xdr_ypresp_maplist, &ypml); */ + _yp_unbind(ysd); + return ypprot_err(ypml.stat); +} diff --git a/lib/libc/yp/yp_master.c b/lib/libc/yp/yp_master.c new file mode 100644 index 00000000000..181a397a159 --- /dev/null +++ b/lib/libc/yp/yp_master.c @@ -0,0 +1,93 @@ +/* $OpenBSD: yp_master.c,v 1.1 1996/04/24 12:56:25 deraadt Exp $ */ +/* $NetBSD: yplib.c,v 1.17 1996/02/04 23:26:26 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$NetBSD: yplib.c,v 1.17 1996/02/04 23:26:26 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ypinternal.h" + +int +yp_master(indomain, inmap, outname) + const char *indomain; + const char *inmap; + char **outname; +{ + struct dom_binding *ysd; + struct ypresp_master yprm; + struct ypreq_nokey yprnk; + struct timeval tv; + int r; + +again: + if (_yp_dobind(indomain, &ysd) != 0) + return YPERR_DOMAIN; + + tv.tv_sec = _yplib_timeout; + tv.tv_usec = 0; + + yprnk.domain = (char *)indomain; + yprnk.map = (char *)inmap; + + (void)memset(&yprm, 0, sizeof yprm); + + r = clnt_call(ysd->dom_client, YPPROC_MASTER, + xdr_ypreq_nokey, &yprnk, xdr_ypresp_master, &yprm, tv); + if (r != RPC_SUCCESS) { + clnt_perror(ysd->dom_client, "yp_master: clnt_call"); + ysd->dom_vers = -1; + goto again; + } + if (!(r = ypprot_err(yprm.stat))) { + if ((*outname = strdup(yprm.peer)) == NULL) + r = RPC_SYSTEMERROR; + } + xdr_free(xdr_ypresp_master, (char *) &yprm); + _yp_unbind(ysd); + return r; +} diff --git a/lib/libc/yp/yp_order.c b/lib/libc/yp/yp_order.c new file mode 100644 index 00000000000..c9292f724cf --- /dev/null +++ b/lib/libc/yp/yp_order.c @@ -0,0 +1,102 @@ +/* $OpenBSD: yp_order.c,v 1.1 1996/04/24 12:56:26 deraadt Exp $ */ +/* $NetBSD: yplib.c,v 1.17 1996/02/04 23:26:26 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$NetBSD: yplib.c,v 1.17 1996/02/04 23:26:26 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ypinternal.h" + +int +yp_order(indomain, inmap, outorder) + const char *indomain; + const char *inmap; + int *outorder; +{ + struct dom_binding *ysd; + struct ypresp_order ypro; + struct ypreq_nokey yprnk; + struct timeval tv; + int r = 0; + +again: + if (_yp_dobind(indomain, &ysd) != 0) + return YPERR_DOMAIN; + + tv.tv_sec = _yplib_timeout; + tv.tv_usec = 0; + + yprnk.domain = (char *)indomain; + yprnk.map = (char *)inmap; + + (void)memset(&ypro, 0, sizeof ypro); + + r = clnt_call(ysd->dom_client, YPPROC_ORDER, + xdr_ypreq_nokey, &yprnk, xdr_ypresp_order, &ypro, tv); + /* + * XXX + * NIS+ YP emulation package does not impliment YPPROC_ORDER, so + * we always return 0. Or should we return an error? + */ + if (r == RPC_PROCUNAVAIL) { + *outorder = 0; + r = 0; + goto bail; + } + if (r != RPC_SUCCESS) { + clnt_perror(ysd->dom_client, "yp_order: clnt_call"); + ysd->dom_vers = -1; + goto again; + } + *outorder = ypro.ordernum; + xdr_free(xdr_ypresp_order, (char *) &ypro); + r = ypprot_err(ypro.stat); +bail: + _yp_unbind(ysd); + return r; +} diff --git a/lib/libc/yp/yperr_string.c b/lib/libc/yp/yperr_string.c new file mode 100644 index 00000000000..b8c372d9635 --- /dev/null +++ b/lib/libc/yp/yperr_string.c @@ -0,0 +1,98 @@ +/* $OpenBSD: yperr_string.c,v 1.1 1996/04/24 12:56:28 deraadt Exp $ */ +/* $NetBSD: yplib.c,v 1.17 1996/02/04 23:26:26 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$NetBSD: yplib.c,v 1.17 1996/02/04 23:26:26 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +char * +yperr_string(incode) + int incode; +{ + static char err[80]; + + switch (incode) { + case 0: + return "Success"; + case YPERR_BADARGS: + return "Request arguments bad"; + case YPERR_RPC: + return "RPC failure"; + case YPERR_DOMAIN: + return "Can't bind to server which serves this domain"; + case YPERR_MAP: + return "No such map in server's domain"; + case YPERR_KEY: + return "No such key in map"; + case YPERR_YPERR: + return "YP server error"; + case YPERR_RESRC: + return "Local resource allocation failure"; + case YPERR_NOMORE: + return "No more records in map database"; + case YPERR_PMAP: + return "Can't communicate with portmapper"; + case YPERR_YPBIND: + return "Can't communicate with ypbind"; + case YPERR_YPSERV: + return "Can't communicate with ypserv"; + case YPERR_NODOM: + return "Local domain name not set"; + case YPERR_BADDB: + return "Server data base is bad"; + case YPERR_VERS: + return "YP server version mismatch - server can't supply service."; + case YPERR_ACCESS: + return "Access violation"; + case YPERR_BUSY: + return "Database is busy"; + } + (void) snprintf(err, sizeof(err), "YP unknown error %d\n", incode); + return err; +} diff --git a/lib/libc/yp/ypinternal.h b/lib/libc/yp/ypinternal.h new file mode 100644 index 00000000000..82f7a5dc314 --- /dev/null +++ b/lib/libc/yp/ypinternal.h @@ -0,0 +1,78 @@ +/* $OpenBSD: ypinternal.h,v 1.1 1996/04/24 12:56:29 deraadt Exp $ */ + +/* + * Copyright (c) 1992, 1993, 1996 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +/* + * XXX We have to define these here due to clashes between + * yp_prot.h and yp.h. + */ +struct dom_binding { + struct dom_binding *dom_pnext; + char dom_domain[YPMAXDOMAIN + 1]; + struct sockaddr_in dom_server_addr; + u_short dom_server_port; + int dom_socket; + CLIENT *dom_client; + u_short dom_local_port; + long dom_vers; +}; + +#define BINDINGDIR "/var/yp/binding" +#define YPBINDLOCK "/var/run/ypbind.lock" +#define YPMATCHCACHE + +int (*ypresp_allfn) __P((u_long, char *, int, char *, int, void *)); +void *ypresp_data; + +extern struct dom_binding *_ypbindlist; +extern char _yp_domain[MAXHOSTNAMELEN]; +extern int _yplib_timeout; + +void _yp_unbind __P((struct dom_binding *)); + +#ifdef YPMATCHCACHE + +static bool_t ypmatch_add __P((const char *, const char *, + u_int, char *, u_int)); +static bool_t ypmatch_find __P((const char *, const char *, + u_int, char **, u_int *)); + +static struct ypmatch_ent { + struct ypmatch_ent *next; + char *map, *key; + char *val; + int keylen, vallen; + time_t expire_t; +} *ypmc; +extern int _yplib_cache; + +#endif diff --git a/lib/libc/yp/yplib.c b/lib/libc/yp/yplib.c deleted file mode 100644 index cca10d3cda9..00000000000 --- a/lib/libc/yp/yplib.c +++ /dev/null @@ -1,852 +0,0 @@ -/* $OpenBSD: yplib.c,v 1.4 1996/03/09 02:43:01 niklas Exp $ */ -/* $NetBSD: yplib.c,v 1.17 1996/02/04 23:26:26 jtc Exp $ */ - -/* - * Copyright (c) 1992, 1993 Theo de Raadt - * All rights reserved. - * - * 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 Theo de Raadt. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$NetBSD: yplib.c,v 1.17 1996/02/04 23:26:26 jtc Exp $"; -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define BINDINGDIR "/var/yp/binding" -#define YPBINDLOCK "/var/run/ypbind.lock" -#define YPMATCHCACHE - -int (*ypresp_allfn) __P((u_long, char *, int, char *, int, void *)); -void *ypresp_data; - -struct dom_binding *_ypbindlist; -static char _yp_domain[MAXHOSTNAMELEN]; -int _yplib_timeout = 10; - -static bool_t ypmatch_add __P((const char *, const char *, int, char *, int)); -static bool_t ypmatch_find __P((const char *, const char *, int, const char **, - int *)); -static void _yp_unbind __P((struct dom_binding *)); - -#ifdef YPMATCHCACHE -int _yplib_cache = 5; - -static struct ypmatch_ent { - struct ypmatch_ent *next; - char *map, *key; - char *val; - int keylen, vallen; - time_t expire_t; -} *ypmc; - -static bool_t -ypmatch_add(map, key, keylen, val, vallen) - const char *map; - const char *key; - int keylen; - char *val; - int vallen; -{ - struct ypmatch_ent *ep; - time_t t; - - (void)time(&t); - - for (ep = ypmc; ep; ep = ep->next) - if (ep->expire_t < t) - break; - if (ep == NULL) { - if ((ep = malloc(sizeof *ep)) == NULL) - return 0; - (void)memset(ep, 0, sizeof *ep); - if (ypmc) - ep->next = ypmc; - ypmc = ep; - } - - if (ep->key) { - free(ep->key); - ep->key = NULL; - } - if (ep->val) { - free(ep->val); - ep->val = NULL; - } - - if ((ep->key = malloc(keylen)) == NULL) - return 0; - - if ((ep->val = malloc(vallen)) == NULL) { - free(ep->key); - ep->key = NULL; - return 0; - } - - ep->keylen = keylen; - ep->vallen = vallen; - - (void)memcpy(ep->key, key, ep->keylen); - (void)memcpy(ep->val, val, ep->vallen); - - if (ep->map) { - if (strcmp(ep->map, map)) { - free(ep->map); - if ((ep->map = strdup(map)) == NULL) - return 0; - } - } else { - if ((ep->map = strdup(map)) == NULL) - return 0; - } - - ep->expire_t = t + _yplib_cache; - return 1; -} - -static bool_t -ypmatch_find(map, key, keylen, val, vallen) - const char *map; - const char *key; - int keylen; - const char **val; - int *vallen; -{ - struct ypmatch_ent *ep; - time_t t; - - if (ypmc == NULL) - return 0; - - (void) time(&t); - - for (ep = ypmc; ep; ep = ep->next) { - if (ep->keylen != keylen) - continue; - if (strcmp(ep->map, map)) - continue; - if (memcmp(ep->key, key, keylen)) - continue; - if (t > ep->expire_t) - continue; - - *val = ep->val; - *vallen = ep->vallen; - return 1; - } - return 0; -} -#endif - -int -_yp_dobind(dom, ypdb) - const char *dom; - struct dom_binding **ypdb; -{ - static int pid = -1; - char path[MAXPATHLEN]; - struct dom_binding *ysd, *ysd2; - struct ypbind_resp ypbr; - struct timeval tv; - struct sockaddr_in clnt_sin; - int clnt_sock, fd, gpid; - CLIENT *client; - int new = 0, r; - int count = 0; - - /* - * test if YP is running or not - */ - if ((fd = open(YPBINDLOCK, O_RDONLY)) == -1) - return YPERR_YPBIND; - if (!(flock(fd, LOCK_EX | LOCK_NB) == -1 && errno == EWOULDBLOCK)) { - (void)close(fd); - return YPERR_YPBIND; - } - (void)close(fd); - - gpid = getpid(); - if (!(pid == -1 || pid == gpid)) { - ysd = _ypbindlist; - while (ysd) { - if (ysd->dom_client) - clnt_destroy(ysd->dom_client); - ysd2 = ysd->dom_pnext; - free(ysd); - ysd = ysd2; - } - _ypbindlist = NULL; - } - pid = gpid; - - if (ypdb != NULL) - *ypdb = NULL; - - if (dom == NULL || strlen(dom) == 0) - return YPERR_BADARGS; - - for (ysd = _ypbindlist; ysd; ysd = ysd->dom_pnext) - if (strcmp(dom, ysd->dom_domain) == 0) - break; - if (ysd == NULL) { - if ((ysd = malloc(sizeof *ysd)) == NULL) - return YPERR_YPERR; - (void)memset(ysd, 0, sizeof *ysd); - ysd->dom_socket = -1; - ysd->dom_vers = 0; - new = 1; - } -again: - if (ysd->dom_vers == 0) { - (void) snprintf(path, sizeof(path), "%s/%s.%d", - BINDINGDIR, dom, 2); - if ((fd = open(path, O_RDONLY)) == -1) { - /* - * no binding file, YP is dead, or not yet fully - * alive. - */ - goto trynet; - } - if (flock(fd, LOCK_EX | LOCK_NB) == -1 && - errno == EWOULDBLOCK) { - struct iovec iov[2]; - struct ypbind_resp ybr; - u_short ypb_port; - struct ypbind_binding *bn; - - iov[0].iov_base = (caddr_t) & ypb_port; - iov[0].iov_len = sizeof ypb_port; - iov[1].iov_base = (caddr_t) & ybr; - iov[1].iov_len = sizeof ybr; - - r = readv(fd, iov, 2); - if (r != iov[0].iov_len + iov[1].iov_len) { - (void)close(fd); - ysd->dom_vers = -1; - goto again; - } - (void)memset(&ysd->dom_server_addr, 0, - sizeof ysd->dom_server_addr); - ysd->dom_server_addr.sin_len = - sizeof(struct sockaddr_in); - ysd->dom_server_addr.sin_family = AF_INET; - bn = &ybr.ypbind_respbody.ypbind_bindinfo; - ysd->dom_server_addr.sin_port = - bn->ypbind_binding_port; - - ysd->dom_server_addr.sin_addr = - bn->ypbind_binding_addr; - - ysd->dom_server_port = ysd->dom_server_addr.sin_port; - (void)close(fd); - goto gotit; - } else { - /* no lock on binding file, YP is dead. */ - (void)close(fd); - if (new) - free(ysd); - return YPERR_YPBIND; - } - } -trynet: - if (ysd->dom_vers == -1 || ysd->dom_vers == 0) { - struct ypbind_binding *bn; - (void)memset(&clnt_sin, 0, sizeof clnt_sin); - clnt_sin.sin_len = sizeof(struct sockaddr_in); - clnt_sin.sin_family = AF_INET; - clnt_sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - - clnt_sock = RPC_ANYSOCK; - client = clnttcp_create(&clnt_sin, YPBINDPROG, YPBINDVERS, - &clnt_sock, 0, 0); - if (client == NULL) { - clnt_pcreateerror("clnttcp_create"); - if (new) - free(ysd); - return YPERR_YPBIND; - } - tv.tv_sec = _yplib_timeout; - tv.tv_usec = 0; - r = clnt_call(client, YPBINDPROC_DOMAIN, xdr_domainname, - dom, xdr_ypbind_resp, &ypbr, tv); - if (r != RPC_SUCCESS) { - if (new == 0 || count) - fprintf(stderr, - "YP server for domain %s not responding, still trying\n", - dom); - count++; - clnt_destroy(client); - ysd->dom_vers = -1; - goto again; - } - clnt_destroy(client); - - (void)memset(&ysd->dom_server_addr, 0, - sizeof ysd->dom_server_addr); - ysd->dom_server_addr.sin_len = sizeof(struct sockaddr_in); - ysd->dom_server_addr.sin_family = AF_INET; - bn = &ypbr.ypbind_respbody.ypbind_bindinfo; - ysd->dom_server_addr.sin_port = - bn->ypbind_binding_port; - ysd->dom_server_addr.sin_addr.s_addr = - bn->ypbind_binding_addr.s_addr; - ysd->dom_server_port = - bn->ypbind_binding_port; -gotit: - ysd->dom_vers = YPVERS; - (void)strcpy(ysd->dom_domain, dom); - } - tv.tv_sec = _yplib_timeout / 2; - tv.tv_usec = 0; - if (ysd->dom_client) - clnt_destroy(ysd->dom_client); - ysd->dom_socket = RPC_ANYSOCK; - ysd->dom_client = clntudp_create(&ysd->dom_server_addr, - YPPROG, YPVERS, tv, &ysd->dom_socket); - if (ysd->dom_client == NULL) { - clnt_pcreateerror("clntudp_create"); - ysd->dom_vers = -1; - goto again; - } - if (fcntl(ysd->dom_socket, F_SETFD, 1) == -1) - perror("fcntl: F_SETFD"); - - if (new) { - ysd->dom_pnext = _ypbindlist; - _ypbindlist = ysd; - } - if (ypdb != NULL) - *ypdb = ysd; - return 0; -} - -static void -_yp_unbind(ypb) - struct dom_binding *ypb; -{ - clnt_destroy(ypb->dom_client); - ypb->dom_client = NULL; - ypb->dom_socket = -1; -} - -int -yp_bind(dom) - const char *dom; -{ - return _yp_dobind(dom, NULL); -} - -void -yp_unbind(dom) - const char *dom; -{ - struct dom_binding *ypb, *ypbp; - - ypbp = NULL; - for (ypb = _ypbindlist; ypb; ypb = ypb->dom_pnext) { - if (strcmp(dom, ypb->dom_domain) == 0) { - clnt_destroy(ypb->dom_client); - if (ypbp) - ypbp->dom_pnext = ypb->dom_pnext; - else - _ypbindlist = ypb->dom_pnext; - free(ypb); - return; - } - ypbp = ypb; - } - return; -} - -int -yp_match(indomain, inmap, inkey, inkeylen, outval, outvallen) - const char *indomain; - const char *inmap; - const char *inkey; - int inkeylen; - char **outval; - int *outvallen; -{ - struct dom_binding *ysd; - struct ypresp_val yprv; - struct timeval tv; - struct ypreq_key yprk; - int r; - - *outval = NULL; - *outvallen = 0; - -again: - if (_yp_dobind(indomain, &ysd) != 0) - return YPERR_DOMAIN; - -#ifdef YPMATCHCACHE - if (!strcmp(_yp_domain, indomain) && ypmatch_find(inmap, inkey, - inkeylen, &yprv.valdat.dptr, &yprv.valdat.dsize)) { - *outvallen = yprv.valdat.dsize; - if ((*outval = malloc(*outvallen + 1)) == NULL) { - _yp_unbind(ysd); - return YPERR_YPERR; - } - (void)memcpy(*outval, yprv.valdat.dptr, *outvallen); - (*outval)[*outvallen] = '\0'; - _yp_unbind(ysd); - return 0; - } -#endif - - tv.tv_sec = _yplib_timeout; - tv.tv_usec = 0; - - yprk.domain = indomain; - yprk.map = inmap; - yprk.keydat.dptr = (char *) inkey; - yprk.keydat.dsize = inkeylen; - - memset(&yprv, 0, sizeof yprv); - - r = clnt_call(ysd->dom_client, YPPROC_MATCH, - xdr_ypreq_key, &yprk, xdr_ypresp_val, &yprv, tv); - if (r != RPC_SUCCESS) { - clnt_perror(ysd->dom_client, "yp_match: clnt_call"); - ysd->dom_vers = -1; - goto again; - } - if (!(r = ypprot_err(yprv.status))) { - *outvallen = yprv.valdat.dsize; - if ((*outval = malloc(*outvallen + 1)) == NULL) { - r = YPERR_YPERR; - goto out; - } - (void)memcpy(*outval, yprv.valdat.dptr, *outvallen); - (*outval)[*outvallen] = '\0'; -#ifdef YPMATCHCACHE - if (strcmp(_yp_domain, indomain) == 0) - if (!ypmatch_add(inmap, inkey, inkeylen, - *outval, *outvallen)) - r = RPC_SYSTEMERROR; -#endif - } -out: - xdr_free(xdr_ypresp_val, (char *) &yprv); - _yp_unbind(ysd); - return r; -} - -int -yp_get_default_domain(domp) - char **domp; -{ - *domp = NULL; - if (_yp_domain[0] == '\0') - if (getdomainname(_yp_domain, sizeof _yp_domain)) - return YPERR_NODOM; - *domp = _yp_domain; - return 0; -} - -int -yp_first(indomain, inmap, outkey, outkeylen, outval, outvallen) - const char *indomain; - const char *inmap; - char **outkey; - int *outkeylen; - char **outval; - int *outvallen; -{ - struct ypresp_key_val yprkv; - struct ypreq_nokey yprnk; - struct dom_binding *ysd; - struct timeval tv; - int r; - - *outkey = *outval = NULL; - *outkeylen = *outvallen = 0; - -again: - if (_yp_dobind(indomain, &ysd) != 0) - return YPERR_DOMAIN; - - tv.tv_sec = _yplib_timeout; - tv.tv_usec = 0; - - yprnk.domain = indomain; - yprnk.map = inmap; - (void)memset(&yprkv, 0, sizeof yprkv); - - r = clnt_call(ysd->dom_client, YPPROC_FIRST, - xdr_ypreq_nokey, &yprnk, xdr_ypresp_key_val, &yprkv, tv); - if (r != RPC_SUCCESS) { - clnt_perror(ysd->dom_client, "yp_first: clnt_call"); - ysd->dom_vers = -1; - goto again; - } - if (!(r = ypprot_err(yprkv.status))) { - *outkeylen = yprkv.keydat.dsize; - if ((*outkey = malloc(*outkeylen + 1)) == NULL) - r = RPC_SYSTEMERROR; - else { - (void)memcpy(*outkey, yprkv.keydat.dptr, *outkeylen); - (*outkey)[*outkeylen] = '\0'; - } - *outvallen = yprkv.valdat.dsize; - if ((*outval = malloc(*outvallen + 1)) == NULL) - r = RPC_SYSTEMERROR; - else { - (void)memcpy(*outval, yprkv.valdat.dptr, *outvallen); - (*outval)[*outvallen] = '\0'; - } - } - xdr_free(xdr_ypresp_key_val, (char *) &yprkv); - _yp_unbind(ysd); - return r; -} - -int -yp_next(indomain, inmap, inkey, inkeylen, outkey, outkeylen, outval, outvallen) - const char *indomain; - const char *inmap; - const char *inkey; - int inkeylen; - char **outkey; - int *outkeylen; - char **outval; - int *outvallen; -{ - struct ypresp_key_val yprkv; - struct ypreq_key yprk; - struct dom_binding *ysd; - struct timeval tv; - int r; - - *outkey = *outval = NULL; - *outkeylen = *outvallen = 0; - -again: - if (_yp_dobind(indomain, &ysd) != 0) - return YPERR_DOMAIN; - - tv.tv_sec = _yplib_timeout; - tv.tv_usec = 0; - - yprk.domain = indomain; - yprk.map = inmap; - yprk.keydat.dptr = inkey; - yprk.keydat.dsize = inkeylen; - (void)memset(&yprkv, 0, sizeof yprkv); - - r = clnt_call(ysd->dom_client, YPPROC_NEXT, - xdr_ypreq_key, &yprk, xdr_ypresp_key_val, &yprkv, tv); - if (r != RPC_SUCCESS) { - clnt_perror(ysd->dom_client, "yp_next: clnt_call"); - ysd->dom_vers = -1; - goto again; - } - if (!(r = ypprot_err(yprkv.status))) { - *outkeylen = yprkv.keydat.dsize; - if ((*outkey = malloc(*outkeylen + 1)) == NULL) - r = RPC_SYSTEMERROR; - else { - (void)memcpy(*outkey, yprkv.keydat.dptr, *outkeylen); - (*outkey)[*outkeylen] = '\0'; - } - *outvallen = yprkv.valdat.dsize; - if ((*outval = malloc(*outvallen + 1)) == NULL) - r = RPC_SYSTEMERROR; - else { - (void)memcpy(*outval, yprkv.valdat.dptr, *outvallen); - (*outval)[*outvallen] = '\0'; - } - } - xdr_free(xdr_ypresp_key_val, (char *) &yprkv); - _yp_unbind(ysd); - return r; -} - -int -yp_all(indomain, inmap, incallback) - const char *indomain; - const char *inmap; - struct ypall_callback *incallback; -{ - struct ypreq_nokey yprnk; - struct dom_binding *ysd; - struct timeval tv; - struct sockaddr_in clnt_sin; - CLIENT *clnt; - u_long status; - int clnt_sock; - int r = 0; - - if (_yp_dobind(indomain, &ysd) != 0) - return YPERR_DOMAIN; - - tv.tv_sec = _yplib_timeout; - tv.tv_usec = 0; - clnt_sock = RPC_ANYSOCK; - clnt_sin = ysd->dom_server_addr; - clnt_sin.sin_port = 0; - clnt = clnttcp_create(&clnt_sin, YPPROG, YPVERS, &clnt_sock, 0, 0); - if (clnt == NULL) { - printf("clnttcp_create failed\n"); - r = YPERR_PMAP; - goto out; - } - yprnk.domain = indomain; - yprnk.map = inmap; - ypresp_allfn = incallback->foreach; - ypresp_data = (void *) incallback->data; - - (void) clnt_call(clnt, YPPROC_ALL, - xdr_ypreq_nokey, &yprnk, xdr_ypresp_all_seq, &status, tv); - clnt_destroy(clnt); - xdr_free(xdr_ypresp_all_seq, (char *) &status); -out: - _yp_unbind(ysd); - - if (status != YP_FALSE) - return ypprot_err(status); - return r; -} - -int -yp_order(indomain, inmap, outorder) - const char *indomain; - const char *inmap; - int *outorder; -{ - struct dom_binding *ysd; - struct ypresp_order ypro; - struct ypreq_nokey yprnk; - struct timeval tv; - int r; - -again: - if (_yp_dobind(indomain, &ysd) != 0) - return YPERR_DOMAIN; - - tv.tv_sec = _yplib_timeout; - tv.tv_usec = 0; - - yprnk.domain = indomain; - yprnk.map = inmap; - - (void)memset(&ypro, 0, sizeof ypro); - - r = clnt_call(ysd->dom_client, YPPROC_ORDER, - xdr_ypreq_nokey, &yprnk, xdr_ypresp_order, &ypro, tv); - if (r != RPC_SUCCESS) { - clnt_perror(ysd->dom_client, "yp_order: clnt_call"); - ysd->dom_vers = -1; - goto again; - } - *outorder = ypro.ordernum; - xdr_free(xdr_ypresp_order, (char *) &ypro); - _yp_unbind(ysd); - return ypprot_err(ypro.status); -} - -int -yp_master(indomain, inmap, outname) - const char *indomain; - const char *inmap; - char **outname; -{ - struct dom_binding *ysd; - struct ypresp_master yprm; - struct ypreq_nokey yprnk; - struct timeval tv; - int r; - -again: - if (_yp_dobind(indomain, &ysd) != 0) - return YPERR_DOMAIN; - - tv.tv_sec = _yplib_timeout; - tv.tv_usec = 0; - - yprnk.domain = indomain; - yprnk.map = inmap; - - (void)memset(&yprm, 0, sizeof yprm); - - r = clnt_call(ysd->dom_client, YPPROC_MASTER, - xdr_ypreq_nokey, &yprnk, xdr_ypresp_master, &yprm, tv); - if (r != RPC_SUCCESS) { - clnt_perror(ysd->dom_client, "yp_master: clnt_call"); - ysd->dom_vers = -1; - goto again; - } - if (!(r = ypprot_err(yprm.status))) { - if ((*outname = strdup(yprm.master)) == NULL) - r = RPC_SYSTEMERROR; - } - xdr_free(xdr_ypresp_master, (char *) &yprm); - _yp_unbind(ysd); - return r; -} - -int -yp_maplist(indomain, outmaplist) - const char *indomain; - struct ypmaplist **outmaplist; -{ - struct dom_binding *ysd; - struct ypresp_maplist ypml; - struct timeval tv; - int r; - -again: - if (_yp_dobind(indomain, &ysd) != 0) - return YPERR_DOMAIN; - - tv.tv_sec = _yplib_timeout; - tv.tv_usec = 0; - - memset(&ypml, 0, sizeof ypml); - - r = clnt_call(ysd->dom_client, YPPROC_MAPLIST, - xdr_domainname, indomain, xdr_ypresp_maplist, &ypml, tv); - if (r != RPC_SUCCESS) { - clnt_perror(ysd->dom_client, "yp_maplist: clnt_call"); - ysd->dom_vers = -1; - goto again; - } - *outmaplist = ypml.list; - /* NO: xdr_free(xdr_ypresp_maplist, &ypml); */ - _yp_unbind(ysd); - return ypprot_err(ypml.status); -} - -char * -yperr_string(incode) - int incode; -{ - static char err[80]; - - switch (incode) { - case 0: - return "Success"; - case YPERR_BADARGS: - return "Request arguments bad"; - case YPERR_RPC: - return "RPC failure"; - case YPERR_DOMAIN: - return "Can't bind to server which serves this domain"; - case YPERR_MAP: - return "No such map in server's domain"; - case YPERR_KEY: - return "No such key in map"; - case YPERR_YPERR: - return "YP server error"; - case YPERR_RESRC: - return "Local resource allocation failure"; - case YPERR_NOMORE: - return "No more records in map database"; - case YPERR_PMAP: - return "Can't communicate with portmapper"; - case YPERR_YPBIND: - return "Can't communicate with ypbind"; - case YPERR_YPSERV: - return "Can't communicate with ypserv"; - case YPERR_NODOM: - return "Local domain name not set"; - case YPERR_BADDB: - return "Server data base is bad"; - case YPERR_VERS: - return "YP server version mismatch - server can't supply service."; - case YPERR_ACCESS: - return "Access violation"; - case YPERR_BUSY: - return "Database is busy"; - } - (void) snprintf(err, sizeof(err), "YP unknown error %d\n", incode); - return err; -} - -int -ypprot_err(incode) - unsigned int incode; -{ - switch (incode) { - case YP_TRUE: - return 0; - case YP_FALSE: - return YPERR_YPBIND; - case YP_NOMORE: - return YPERR_NOMORE; - case YP_NOMAP: - return YPERR_MAP; - case YP_NODOM: - return YPERR_NODOM; - case YP_NOKEY: - return YPERR_KEY; - case YP_BADOP: - return YPERR_YPERR; - case YP_BADDB: - return YPERR_BADDB; - case YP_YPERR: - return YPERR_YPERR; - case YP_BADARGS: - return YPERR_BADARGS; - case YP_VERS: - return YPERR_VERS; - } - return YPERR_YPERR; -} - -int -_yp_check(dom) - char **dom; -{ - char *unused; - - if (_yp_domain[0] == '\0') - if (yp_get_default_domain(&unused)) - return 0; - - if (dom) - *dom = _yp_domain; - - if (yp_bind(_yp_domain) == 0) - return 1; - return 0; -} diff --git a/lib/libc/yp/ypmatch_cache.c b/lib/libc/yp/ypmatch_cache.c new file mode 100644 index 00000000000..16ad9016148 --- /dev/null +++ b/lib/libc/yp/ypmatch_cache.c @@ -0,0 +1,288 @@ +/* $OpenBSD: ypmatch_cache.c,v 1.1 1996/04/24 12:56:31 deraadt Exp $ */ +/* $NetBSD: yplib.c,v 1.17 1996/02/04 23:26:26 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$NetBSD: yplib.c,v 1.17 1996/02/04 23:26:26 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ypinternal.h" + +int _yplib_cache = 5; + +static bool_t +ypmatch_add(map, key, keylen, val, vallen) + const char *map; + const char *key; + u_int keylen; + char *val; + u_int vallen; +{ + struct ypmatch_ent *ep; + time_t t; + + (void)time(&t); + + for (ep = ypmc; ep; ep = ep->next) + if (ep->expire_t < t) + break; + if (ep == NULL) { + if ((ep = malloc(sizeof *ep)) == NULL) + return 0; + (void)memset(ep, 0, sizeof *ep); + if (ypmc) + ep->next = ypmc; + ypmc = ep; + } + + if (ep->key) { + free(ep->key); + ep->key = NULL; + } + if (ep->val) { + free(ep->val); + ep->val = NULL; + } + + if ((ep->key = malloc(keylen)) == NULL) + return 0; + + if ((ep->val = malloc(vallen)) == NULL) { + free(ep->key); + ep->key = NULL; + return 0; + } + + ep->keylen = keylen; + ep->vallen = vallen; + + (void)memcpy(ep->key, key, ep->keylen); + (void)memcpy(ep->val, val, ep->vallen); + + if (ep->map) { + if (strcmp(ep->map, map)) { + free(ep->map); + if ((ep->map = strdup(map)) == NULL) + return 0; + } + } else { + if ((ep->map = strdup(map)) == NULL) + return 0; + } + + ep->expire_t = t + _yplib_cache; + return 1; +} + +static bool_t +ypmatch_find(map, key, keylen, val, vallen) + const char *map; + const char *key; + u_int keylen; + char **val; + u_int *vallen; +{ + struct ypmatch_ent *ep; + time_t t; + + if (ypmc == NULL) + return 0; + + (void) time(&t); + + for (ep = ypmc; ep; ep = ep->next) { + if (ep->keylen != keylen) + continue; + if (strcmp(ep->map, map)) + continue; + if (memcmp(ep->key, key, keylen)) + continue; + if (t > ep->expire_t) + continue; + + *val = ep->val; + *vallen = ep->vallen; + return 1; + } + return 0; +} + +int +yp_match(indomain, inmap, inkey, inkeylen, outval, outvallen) + const char *indomain; + const char *inmap; + const char *inkey; + int inkeylen; + char **outval; + int *outvallen; +{ + struct dom_binding *ysd; + struct ypresp_val yprv; + struct timeval tv; + struct ypreq_key yprk; + int r; + + *outval = NULL; + *outvallen = 0; + +again: + if (_yp_dobind(indomain, &ysd) != 0) + return YPERR_DOMAIN; + +#ifdef YPMATCHCACHE + if (!strcmp(_yp_domain, indomain) && ypmatch_find(inmap, inkey, + inkeylen, &yprv.val.valdat_val, &yprv.val.valdat_len)) { + *outvallen = yprv.val.valdat_len; + if ((*outval = malloc(*outvallen + 1)) == NULL) { + _yp_unbind(ysd); + return YPERR_YPERR; + } + (void)memcpy(*outval, yprv.val.valdat_val, *outvallen); + (*outval)[*outvallen] = '\0'; + _yp_unbind(ysd); + return 0; + } +#endif + + tv.tv_sec = _yplib_timeout; + tv.tv_usec = 0; + + yprk.domain = (char *)indomain; + yprk.map = (char *)inmap; + yprk.key.keydat_val = (char *) inkey; + yprk.key.keydat_len = inkeylen; + + memset(&yprv, 0, sizeof yprv); + + r = clnt_call(ysd->dom_client, YPPROC_MATCH, + xdr_ypreq_key, &yprk, xdr_ypresp_val, &yprv, tv); + if (r != RPC_SUCCESS) { + clnt_perror(ysd->dom_client, "yp_match: clnt_call"); + ysd->dom_vers = -1; + goto again; + } + if (!(r = ypprot_err(yprv.stat))) { + *outvallen = yprv.val.valdat_len; + if ((*outval = malloc(*outvallen + 1)) == NULL) { + r = YPERR_YPERR; + goto out; + } + (void)memcpy(*outval, yprv.val.valdat_val, *outvallen); + (*outval)[*outvallen] = '\0'; +#ifdef YPMATCHCACHE + if (strcmp(_yp_domain, indomain) == 0) + if (!ypmatch_add(inmap, inkey, inkeylen, + *outval, *outvallen)) + r = RPC_SYSTEMERROR; +#endif + } +out: + xdr_free(xdr_ypresp_val, (char *) &yprv); + _yp_unbind(ysd); + return r; +} + +int +yp_next(indomain, inmap, inkey, inkeylen, outkey, outkeylen, outval, outvallen) + const char *indomain; + const char *inmap; + const char *inkey; + int inkeylen; + char **outkey; + int *outkeylen; + char **outval; + int *outvallen; +{ + struct ypresp_key_val yprkv; + struct ypreq_key yprk; + struct dom_binding *ysd; + struct timeval tv; + int r; + + *outkey = *outval = NULL; + *outkeylen = *outvallen = 0; + +again: + if (_yp_dobind(indomain, &ysd) != 0) + return YPERR_DOMAIN; + + tv.tv_sec = _yplib_timeout; + tv.tv_usec = 0; + + yprk.domain = (char *)indomain; + yprk.map = (char *)inmap; + yprk.key.keydat_val = (char *)inkey; + yprk.key.keydat_len = inkeylen; + (void)memset(&yprkv, 0, sizeof yprkv); + + r = clnt_call(ysd->dom_client, YPPROC_NEXT, + xdr_ypreq_key, &yprk, xdr_ypresp_key_val, &yprkv, tv); + if (r != RPC_SUCCESS) { + clnt_perror(ysd->dom_client, "yp_next: clnt_call"); + ysd->dom_vers = -1; + goto again; + } + if (!(r = ypprot_err(yprkv.stat))) { + *outkeylen = yprkv.key.keydat_len; + if ((*outkey = malloc(*outkeylen + 1)) == NULL) + r = RPC_SYSTEMERROR; + else { + (void)memcpy(*outkey, yprkv.key.keydat_val, *outkeylen); + (*outkey)[*outkeylen] = '\0'; + } + *outvallen = yprkv.val.valdat_len; + if ((*outval = malloc(*outvallen + 1)) == NULL) + r = RPC_SYSTEMERROR; + else { + (void)memcpy(*outval, yprkv.val.valdat_val, *outvallen); + (*outval)[*outvallen] = '\0'; + } + } + xdr_free(xdr_ypresp_key_val, (char *) &yprkv); + _yp_unbind(ysd); + return r; +} diff --git a/lib/libc/yp/ypprot_err.c b/lib/libc/yp/ypprot_err.c new file mode 100644 index 00000000000..833ce75ad22 --- /dev/null +++ b/lib/libc/yp/ypprot_err.c @@ -0,0 +1,83 @@ +/* $OpenBSD: ypprot_err.c,v 1.1 1996/04/24 12:56:33 deraadt Exp $ */ +/* $NetBSD: yplib.c,v 1.17 1996/02/04 23:26:26 jtc Exp $ */ + +/* + * Copyright (c) 1992, 1993 Theo de Raadt + * All rights reserved. + * + * 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 Theo de Raadt. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$NetBSD: yplib.c,v 1.17 1996/02/04 23:26:26 jtc Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int +ypprot_err(incode) + unsigned int incode; +{ + switch (incode) { + case YP_TRUE: + return 0; + case YP_FALSE: + return YPERR_YPBIND; + case YP_NOMORE: + return YPERR_NOMORE; + case YP_NOMAP: + return YPERR_MAP; + case YP_NODOM: + return YPERR_NODOM; + case YP_NOKEY: + return YPERR_KEY; + case YP_BADOP: + return YPERR_YPERR; + case YP_BADDB: + return YPERR_BADDB; + case YP_YPERR: + return YPERR_YPERR; + case YP_BADARGS: + return YPERR_BADARGS; + case YP_VERS: + return YPERR_VERS; + } + return YPERR_YPERR; +} -- 2.20.1