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