From abd666b1a78ba1067adf9914fd74cdc43940a354 Mon Sep 17 00:00:00 2001 From: deraadt Date: Thu, 25 Apr 1996 00:53:43 +0000 Subject: [PATCH] NIS+ in YP compatibility mode does not support a working yp_order(). amd wants one so it can flush it's cache intelligently. Here's a working compromise... solution worked out by matthieu@laas.fr and I. --- lib/libc/yp/yp_order.c | 8 ++---- usr.sbin/amd/amd/info_nis.c | 57 +++++++++++++++++++++++++++++++------ 2 files changed, 51 insertions(+), 14 deletions(-) diff --git a/lib/libc/yp/yp_order.c b/lib/libc/yp/yp_order.c index c9292f724cf..fab5c2524d5 100644 --- a/lib/libc/yp/yp_order.c +++ b/lib/libc/yp/yp_order.c @@ -1,4 +1,4 @@ -/* $OpenBSD: yp_order.c,v 1.1 1996/04/24 12:56:26 deraadt Exp $ */ +/* $OpenBSD: yp_order.c,v 1.2 1996/04/25 00:53:49 deraadt Exp $ */ /* $NetBSD: yplib.c,v 1.17 1996/02/04 23:26:26 jtc Exp $ */ /* @@ -80,12 +80,10 @@ again: 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? + * NIS+ YP emulation package does not impliment YPPROC_ORDER */ if (r == RPC_PROCUNAVAIL) { - *outorder = 0; - r = 0; + r = YPERR_YPERR; goto bail; } if (r != RPC_SUCCESS) { diff --git a/usr.sbin/amd/amd/info_nis.c b/usr.sbin/amd/amd/info_nis.c index fc88e22241c..2d445a30d7b 100644 --- a/usr.sbin/amd/amd/info_nis.c +++ b/usr.sbin/amd/amd/info_nis.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * from: @(#)info_nis.c 8.1 (Berkeley) 6/6/93 - * $Id: info_nis.c,v 1.1.1.1 1995/10/18 08:47:10 deraadt Exp $ + * $Id: info_nis.c,v 1.2 1996/04/25 00:53:43 deraadt Exp $ */ /* @@ -48,6 +48,12 @@ #ifdef HAS_NIS_MAPS #include #include +#include + +/* + * Sun's NIS+ server in NIS compat mode does not have yp_order() + */ +static int has_yp_order = FALSE; /* * Figure out the nis domain name @@ -180,10 +186,24 @@ time_t *tp; /* * Make sure domain initialised */ - if (!domain) { - int error = determine_nis_domain(); - if (error) - return error; + if (has_yp_order) { + /* check if map has changed */ + if (yp_order(domain, map, &order)) + return EIO; + if ((time_t) order > *tp) { + *tp = (time_t) order; + return -1; + } + } else { + /* + * NIS+ server without yp_order + * Check if timeout has expired to invalidate the cache + */ + order = time(NULL); + if ((time_t)order - *tp > am_timeo) { + *tp = (time_t)order; + return(-1); + } } /* @@ -223,6 +243,8 @@ char *map; time_t *tp; { int order; + int yp_order_result; + char *master; if (!domain) { int error = determine_nis_domain(); @@ -234,12 +256,29 @@ time_t *tp; * To see if the map exists, try to find * a master for it. */ - if (yp_order(domain, map, &order)) - return ENOENT; - *tp = (time_t) order; + yp_order_result = yp_order(domain, map, &order); + switch (yp_order_result) { + case 0: + has_yp_order = TRUE; + *tp = (time_t)order; #ifdef DEBUG - dlog("NIS master for %s@%s has order %d", map, domain, order); + dlog("NIS master for %s@%s has order %d", map, domain, order); #endif + break; + case YPERR_YPERR: + plog(XLOG_ERROR, "%s: %s", map, "NIS+ server"); + /* NIS+ server found ! */ + has_yp_order = FALSE; + + /* try yp_master() instead */ + if (yp_master(domain, map, &master)) + return ENOENT; + else + *tp = time(NULL); /* Use fake timestamps */ + break; + default: + return ENOENT; + } return 0; } #endif /* HAS_NIS_MAPS */ -- 2.20.1