yppoll.c revision 78720
1/* 2 * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca> 3 * Copyright (c) 1992/3 John Brezak 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote 15 * products derived from this software without specific prior written 16 * permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31#ifndef lint 32static const char rcsid[] = 33 "$FreeBSD: head/usr.sbin/yppoll/yppoll.c 78720 2001-06-24 20:25:23Z dd $"; 34#endif /* not lint */ 35 36#include <sys/param.h> 37#include <sys/types.h> 38#include <sys/socket.h> 39#include <err.h> 40#include <stdio.h> 41#include <stdlib.h> 42#include <time.h> 43#include <unistd.h> 44 45#include <rpc/rpc.h> 46#include <rpc/xdr.h> 47#include <rpcsvc/yp_prot.h> 48#include <rpcsvc/ypclnt.h> 49 50static void 51usage() 52{ 53 fprintf(stderr, "usage: yppoll [-h host] [-d domainname] mapname\n"); 54 exit(1); 55} 56 57int 58main(argc, argv) 59char **argv; 60{ 61 char *domainname; 62 char *hostname = "localhost"; 63 char *inmap, *master; 64 int order; 65 int c, r; 66 67 yp_get_default_domain(&domainname); 68 69 while( (c=getopt(argc, argv, "h:d:")) != -1) 70 switch(c) { 71 case 'd': 72 domainname = optarg; 73 break; 74 case 'h': 75 hostname = optarg; 76 break; 77 case '?': 78 usage(); 79 /*NOTREACHED*/ 80 } 81 82 if(optind + 1 != argc ) 83 usage(); 84 85 inmap = argv[optind]; 86 87 r = yp_order(domainname, inmap, &order); 88 if (r != 0) 89 errx(1, "no such map %s. Reason: %s", inmap, yperr_string(r)); 90 printf("Map %s has order number %d. %s", inmap, order, 91 ctime((time_t *)&order)); 92 r = yp_master(domainname, inmap, &master); 93 if (r != 0) 94 errx(1, "no such map %s. Reason: %s", inmap, yperr_string(r)); 95 printf("The master server is %s.\n", master); 96 97 exit(0); 98} 99