Deleted Added
full compact
ypwhich.c (7982) ypwhich.c (7990)
1/*
2 * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 28 unchanged lines hidden (view full) ---

37#include <stdio.h>
38#include <ctype.h>
39#include <netdb.h>
40#include <rpc/rpc.h>
41#include <rpc/xdr.h>
42#include <rpcsvc/yp_prot.h>
43#include <rpcsvc/ypclnt.h>
44
1/*
2 * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 28 unchanged lines hidden (view full) ---

37#include <stdio.h>
38#include <ctype.h>
39#include <netdb.h>
40#include <rpc/rpc.h>
41#include <rpc/xdr.h>
42#include <rpcsvc/yp_prot.h>
43#include <rpcsvc/ypclnt.h>
44
45#define ERR_USAGE 1 /* bad arguments - display 'usage' message */
46#define ERR_NOSUCHHOST 2 /* no such host */
47#define ERR_NOBINDING 3 /* error from ypbind -- domain not bound */
48#define ERR_NOYPBIND 4 /* ypbind not running */
49#define ERR_NOMASTER 5 /* could not find master server */
50
45extern bool_t xdr_domainname();
46
47struct ypalias {
48 char *alias, *name;
49} ypaliases[] = {
50 { "passwd", "passwd.byname" },
51 { "group", "group.byname" },
52 { "networks", "networks.byaddr" },

--- 4 unchanged lines hidden (view full) ---

57 { "ethers", "ethers.byname" },
58};
59
60usage()
61{
62 fprintf(stderr, "Usage:\n");
63 fprintf(stderr, "\typwhich [-d domain] [[-t] -m [mname] | host]\n");
64 fprintf(stderr, "\typwhich -x\n");
51extern bool_t xdr_domainname();
52
53struct ypalias {
54 char *alias, *name;
55} ypaliases[] = {
56 { "passwd", "passwd.byname" },
57 { "group", "group.byname" },
58 { "networks", "networks.byaddr" },

--- 4 unchanged lines hidden (view full) ---

63 { "ethers", "ethers.byname" },
64};
65
66usage()
67{
68 fprintf(stderr, "Usage:\n");
69 fprintf(stderr, "\typwhich [-d domain] [[-t] -m [mname] | host]\n");
70 fprintf(stderr, "\typwhich -x\n");
65 exit(1);
71 exit(ERR_USAGE);
66}
67
68
69/*
70 * Like yp_bind except can query a specific host
71 */
72bind_host(dom, sin)
73char *dom;

--- 87 unchanged lines hidden (view full) ---

161 if(mode==0) {
162 switch(argc-optind) {
163 case 0:
164 bzero(&sin, sizeof sin);
165 sin.sin_family = AF_INET;
166 sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
167
168 if(bind_host(domainname, &sin))
72}
73
74
75/*
76 * Like yp_bind except can query a specific host
77 */
78bind_host(dom, sin)
79char *dom;

--- 87 unchanged lines hidden (view full) ---

167 if(mode==0) {
168 switch(argc-optind) {
169 case 0:
170 bzero(&sin, sizeof sin);
171 sin.sin_family = AF_INET;
172 sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
173
174 if(bind_host(domainname, &sin))
169 exit(1);
175 exit(ERR_NOBINDING);
170 break;
171 case 1:
172 bzero(&sin, sizeof sin);
173 sin.sin_family = AF_INET;
174 if( (sin.sin_addr.s_addr=inet_addr(argv[optind]))==-1) {
175 hent = gethostbyname(argv[optind]);
176 if(!hent) {
177 fprintf(stderr, "ypwhich: host %s unknown\n",
178 argv[optind]);
176 break;
177 case 1:
178 bzero(&sin, sizeof sin);
179 sin.sin_family = AF_INET;
180 if( (sin.sin_addr.s_addr=inet_addr(argv[optind]))==-1) {
181 hent = gethostbyname(argv[optind]);
182 if(!hent) {
183 fprintf(stderr, "ypwhich: host %s unknown\n",
184 argv[optind]);
179 exit(1);
185 exit(ERR_NOSUCHHOST);
180 }
181 bcopy((char *)hent->h_addr_list[0],
182 (char *)&sin.sin_addr, sizeof sin.sin_addr);
183 }
184 if(bind_host(domainname, &sin))
186 }
187 bcopy((char *)hent->h_addr_list[0],
188 (char *)&sin.sin_addr, sizeof sin.sin_addr);
189 }
190 if(bind_host(domainname, &sin))
185 exit(1);
191 exit(ERR_NOBINDING);
186 break;
187 default:
188 usage();
189 }
190 exit(0);
191 }
192
193 if( argc-optind > 1)

--- 7 unchanged lines hidden (view full) ---

201 r = yp_master(domainname, map, &master);
202 switch(r) {
203 case 0:
204 printf("%s\n", master);
205 free(master);
206 break;
207 case YPERR_YPBIND:
208 fprintf(stderr, "ypwhich: not running ypbind\n");
192 break;
193 default:
194 usage();
195 }
196 exit(0);
197 }
198
199 if( argc-optind > 1)

--- 7 unchanged lines hidden (view full) ---

207 r = yp_master(domainname, map, &master);
208 switch(r) {
209 case 0:
210 printf("%s\n", master);
211 free(master);
212 break;
213 case YPERR_YPBIND:
214 fprintf(stderr, "ypwhich: not running ypbind\n");
209 exit(1);
215 exit(ERR_NOYPBIND);
210 default:
211 fprintf(stderr, "Can't find master for map %s. Reason: %s\n",
212 map, yperr_string(r));
216 default:
217 fprintf(stderr, "Can't find master for map %s. Reason: %s\n",
218 map, yperr_string(r));
213 exit(1);
219 exit(ERR_NOMASTER);
214 }
215 exit(0);
216 }
217
218 ypml = NULL;
219 r = yp_maplist(domainname, &ypml);
220 switch(r) {
221 case 0:

--- 12 unchanged lines hidden (view full) ---

234 break;
235 }
236 y = ypml->ypml_next;
237 free(ypml);
238 }
239 break;
240 case YPERR_YPBIND:
241 fprintf(stderr, "ypwhich: not running ypbind\n");
220 }
221 exit(0);
222 }
223
224 ypml = NULL;
225 r = yp_maplist(domainname, &ypml);
226 switch(r) {
227 case 0:

--- 12 unchanged lines hidden (view full) ---

240 break;
241 }
242 y = ypml->ypml_next;
243 free(ypml);
244 }
245 break;
246 case YPERR_YPBIND:
247 fprintf(stderr, "ypwhich: not running ypbind\n");
242 exit(1);
248 exit(ERR_NOYPBIND);
243 default:
244 fprintf(stderr, "Can't get map list for domain %s. Reason: %s\n",
245 domainname, yperr_string(r));
249 default:
250 fprintf(stderr, "Can't get map list for domain %s. Reason: %s\n",
251 domainname, yperr_string(r));
246 exit(1);
252 exit(ERR_NOMASTER);
247 }
248 exit(0);
249}
253 }
254 exit(0);
255}