int main(int argc, char *argv[]) { char *domainname; char *hostname = NULL; char *inmap, *master; int order; int c, r, tcp = 0; (void)yp_get_default_domain(&domainname); while ((c = getopt(argc, argv, "Th:d:")) != -1) { switch (c) { case 'T': tcp = 1; break; case 'd': domainname = optarg; break; case 'h': hostname = optarg; break; default: usage(); /*NOTREACHED*/ } } if (domainname == NULL) errx(1, "YP domain name not set"); argc -= optind; argv += optind; if (argc != 1) usage(); inmap = argv[0]; if (hostname != NULL) r = get_remote_info(domainname, inmap, hostname, &order, &master, tcp); else { r = yp_order(domainname, inmap, &order); if (r == 0) r = yp_master(domainname, inmap, &master); } if (r != 0) errx(1, "no such map %s. Reason: %s", inmap, yperr_string(r)); (void)printf("Map %s has order number %d. %s", inmap, order, ctime((void *)&order)); (void)printf("The master server is %s.\n", master); return 0; }
/*! @decl int order(string map) *! *! Returns the 'order' number for the map @[map]. *! *! This is usually the number of seconds since Jan 1 1970 (see @[time()]). *! When the map is changed, this number will change as well. *! *! @[map] is the YP-map to search in. This must be the full map name. *! eg @tt{passwd.byname@} instead of just @tt{passwd@}. */ static void f_order(INT32 args) { int err; YP_ORDER_TYPE ret; check_all_args(NULL, args, BIT_STRING, 0); err = yp_order( this->domain, sp[-args].u.string->str, &ret); YPERROR( err ); pop_n_elems( args ); push_int( (INT32) ret ); }
VALUE rb_yp_order(VALUE self, VALUE domain, VALUE map) { int res, order; if( domain == Qnil ) { domain = rb_yp_get_default_domain(self); }; res = yp_order(STR2CSTR(domain), STR2CSTR(map), &order); rb_yp_check_yperr(res); return INT2NUM(order); };
int nis_init(char *map, time_t *tp) { int order; int yp_order_result; char *master; if (!domain) { int error = determine_nis_domain(); if (error) return error; } /* * To see if the map exists, try to find * a master for it. */ 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); #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; }
/* * Try to locate a key using NIS. */ int nis_search(mnt_map *m, char *map, char *key, char **val, time_t *tp) { int outlen; int order; int res; /* * Make sure domain initialised */ 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); } } 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); } } /* * Lookup key */ res = yp_match(domain, map, key, strlen(key), val, &outlen); /* * Do something interesting with the return code */ switch (res) { case 0: return 0; case YPERR_KEY: return ENOENT; default: plog(XLOG_ERROR, "%s: %s", map, yperr_string(res)); return EIO; } }