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 #include <sys/cdefs.h> 32 __FBSDID("$FreeBSD$"); 33 34 #include <sys/param.h> 35 #include <sys/types.h> 36 #include <sys/socket.h> 37 #include <err.h> 38 #include <stdio.h> 39 #include <stdlib.h> 40 #include <time.h> 41 #include <timeconv.h> 42 #include <unistd.h> 43 44 #include <rpc/rpc.h> 45 #include <rpc/xdr.h> 46 #include <rpcsvc/yp_prot.h> 47 #include <rpcsvc/ypclnt.h> 48 49 static void 50 usage(void) 51 { 52 #if 0 53 fprintf(stderr, "usage: yppoll [-h host] [-d domainname] mapname\n"); 54 #else 55 fprintf(stderr, "usage: yppoll [-d domainname] mapname\n"); 56 #endif 57 exit(1); 58 } 59 60 int 61 main(int argc, char *argv[]) 62 { 63 char *domainname; 64 #if 0 65 char *hostname = "localhost"; 66 #endif 67 char *inmap, *master; 68 int order; 69 int c, r; 70 time_t t; 71 72 yp_get_default_domain(&domainname); 73 74 while ((c = getopt(argc, argv, "h:d:")) != -1) 75 switch (c) { 76 case 'd': 77 domainname = optarg; 78 break; 79 case 'h': 80 #if 0 81 hostname = optarg; 82 #else 83 /* does nothing */ 84 #endif 85 break; 86 case '?': 87 usage(); 88 /*NOTREACHED*/ 89 } 90 91 if (optind + 1 != argc) 92 usage(); 93 94 inmap = argv[optind]; 95 96 r = yp_order(domainname, inmap, &order); 97 if (r != 0) 98 errx(1, "no such map %s. Reason: %s", inmap, yperr_string(r)); 99 t = _int_to_time(order); 100 printf("Map %s has order number %d. %s", inmap, order, ctime(&t)); 101 r = yp_master(domainname, inmap, &master); 102 if (r != 0) 103 errx(1, "no such map %s. Reason: %s", inmap, yperr_string(r)); 104 printf("The master server is %s.\n", master); 105 106 exit(0); 107 } 108