-/* $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 $ */
/*
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) {
* 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 $
*/
/*
#ifdef HAS_NIS_MAPS
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
+#include <time.h>
+
+/*
+ * 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
/*
* 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);
+ }
}
/*
time_t *tp;
{
int order;
+ int yp_order_result;
+ char *master;
if (!domain) {
int error = determine_nis_domain();
* 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 */