1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
|
/*
* And thus spoke RPCGEN:
* Please do not edit this file.
* It was generated using rpcgen.
*
* And thus replied Lpd@NannyMUD:
* Who cares? :-) /Peter Eriksson <pen@signum.se>
*
* $Id: yp_svc.c,v 1.5 1995/07/08 21:42:59 ats Exp $
*/
#include "system.h"
#include "yp.h"
#include <stdio.h>
#include <stdlib.h>
#include <rpc/pmap_clnt.h>
#include <string.h>
#include <memory.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <syslog.h>
#include <errno.h>
#include <paths.h>
#include <signal.h>
extern int errno;
extern void Perror __P((char *, ...));
extern void my_svc_run __P((void));
extern void reapchild __P((int));
#ifdef __STDC__
#define SIG_PF void(*)(int)
#endif
static void
ypprog_2(struct svc_req *rqstp, register SVCXPRT *transp)
{
union {
domainname ypproc_domain_2_arg;
domainname ypproc_domain_nonack_2_arg;
ypreq_key ypproc_match_2_arg;
ypreq_key ypproc_first_2_arg;
ypreq_key ypproc_next_2_arg;
ypreq_xfr ypproc_xfr_2_arg;
ypreq_nokey ypproc_all_2_arg;
ypreq_nokey ypproc_master_2_arg;
ypreq_nokey ypproc_order_2_arg;
domainname ypproc_maplist_2_arg;
} argument;
char *result;
xdrproc_t __xdr_argument, __xdr_result;
char *(*local)(char *, struct svc_req *);
switch (rqstp->rq_proc) {
case YPPROC_NULL:
__xdr_argument = (xdrproc_t) xdr_void;
__xdr_result = (xdrproc_t) xdr_void;
local = (char *(*)(char *, struct svc_req *)) ypproc_null_2_svc;
break;
case YPPROC_DOMAIN:
__xdr_argument = (xdrproc_t) __xdr_domainname;
__xdr_result = (xdrproc_t) xdr_bool;
local = (char *(*)(char *, struct svc_req *)) ypproc_domain_2_svc;
break;
case YPPROC_DOMAIN_NONACK:
__xdr_argument = (xdrproc_t) __xdr_domainname;
__xdr_result = (xdrproc_t) xdr_bool;
local = (char *(*)(char *, struct svc_req *)) ypproc_domain_nonack_2_svc;
break;
case YPPROC_MATCH:
__xdr_argument = (xdrproc_t) __xdr_ypreq_key;
__xdr_result = (xdrproc_t) __xdr_ypresp_val;
local = (char *(*)(char *, struct svc_req *)) ypproc_match_2_svc;
break;
case YPPROC_FIRST:
#if 0 /* Bug in Sun's yp.x RPC prototype file */
__xdr_argument = (xdrproc_t) __xdr_ypreq_key;
#else
__xdr_argument = (xdrproc_t) __xdr_ypreq_nokey;
#endif
__xdr_result = (xdrproc_t) __xdr_ypresp_key_val;
local = (char *(*)(char *, struct svc_req *)) ypproc_first_2_svc;
break;
case YPPROC_NEXT:
__xdr_argument = (xdrproc_t) __xdr_ypreq_key;
__xdr_result = (xdrproc_t) __xdr_ypresp_key_val;
local = (char *(*)(char *, struct svc_req *)) ypproc_next_2_svc;
break;
case YPPROC_XFR:
__xdr_argument = (xdrproc_t) __xdr_ypreq_xfr;
__xdr_result = (xdrproc_t) __xdr_ypresp_xfr;
local = (char *(*)(char *, struct svc_req *)) ypproc_xfr_2_svc;
break;
case YPPROC_CLEAR:
__xdr_argument = (xdrproc_t) xdr_void;
__xdr_result = (xdrproc_t) xdr_void;
local = (char *(*)(char *, struct svc_req *)) ypproc_clear_2_svc;
break;
case YPPROC_ALL:
__xdr_argument = (xdrproc_t) __xdr_ypreq_nokey;
__xdr_result = (xdrproc_t) __xdr_ypresp_all;
local = (char *(*)(char *, struct svc_req *)) ypproc_all_2_svc;
break;
case YPPROC_MASTER:
__xdr_argument = (xdrproc_t) __xdr_ypreq_nokey;
__xdr_result = (xdrproc_t) __xdr_ypresp_master;
local = (char *(*)(char *, struct svc_req *)) ypproc_master_2_svc;
break;
case YPPROC_ORDER:
__xdr_argument = (xdrproc_t) __xdr_ypreq_nokey;
__xdr_result = (xdrproc_t) __xdr_ypresp_order;
local = (char *(*)(char *, struct svc_req *)) ypproc_order_2_svc;
break;
case YPPROC_MAPLIST:
__xdr_argument = (xdrproc_t) __xdr_domainname;
__xdr_result = (xdrproc_t) __xdr_ypresp_maplist;
local = (char *(*)(char *, struct svc_req *)) ypproc_maplist_2_svc;
break;
default:
svcerr_noproc(transp);
return;
}
(void) memset((char *)&argument, 0, sizeof (argument));
if (!svc_getargs(transp, __xdr_argument, (caddr_t) &argument)) {
svcerr_decode(transp);
return;
}
result = (*local)((char *)&argument, rqstp);
if (result != NULL && !svc_sendreply(transp, __xdr_result, result)) {
svcerr_systemerr(transp);
}
if (!svc_freeargs(transp, __xdr_argument, (caddr_t) &argument)) {
fprintf(stderr, "unable to free arguments");
exit(1);
}
return;
}
#if 0
static void
yppush_xfrrespprog_1(struct svc_req *rqstp, register SVCXPRT *transp)
{
union {
int fill;
} argument;
char *result;
xdrproc_t __xdr_argument, __xdr_result;
char *(*local)(char *, struct svc_req *);
switch (rqstp->rq_proc) {
case YPPUSHPROC_NULL:
__xdr_argument = (xdrproc_t) xdr_void;
__xdr_result = (xdrproc_t) xdr_void;
local = (char *(*)(char *, struct svc_req *)) yppushproc_null_1_svc;
break;
case YPPUSHPROC_XFRRESP:
__xdr_argument = (xdrproc_t) xdr_void;
__xdr_result = (xdrproc_t) __xdr_yppushresp_xfr;
local = (char *(*)(char *, struct svc_req *)) yppushproc_xfrresp_1_svc;
break;
default:
svcerr_noproc(transp);
return;
}
(void) memset((char *)&argument, 0, sizeof (argument));
if (!svc_getargs(transp, __xdr_argument, (caddr_t) &argument)) {
svcerr_decode(transp);
return;
}
result = (*local)((char *)&argument, rqstp);
if (result != NULL && !svc_sendreply(transp, __xdr_result, result)) {
svcerr_systemerr(transp);
}
if (!svc_freeargs(transp, __xdr_argument, (caddr_t) &argument)) {
fprintf(stderr, "unable to free arguments");
exit(1);
}
return;
}
static void
ypbindprog_2(struct svc_req *rqstp, register SVCXPRT *transp)
{
union {
domainname ypbindproc_domain_2_arg;
ypbind_setdom ypbindproc_setdom_2_arg;
} argument;
char *result;
xdrproc_t __xdr_argument, __xdr_result;
char *(*local)(char *, struct svc_req *);
switch (rqstp->rq_proc) {
case YPBINDPROC_NULL:
__xdr_argument = (xdrproc_t) xdr_void;
__xdr_result = (xdrproc_t) xdr_void;
local = (char *(*)(char *, struct svc_req *)) ypbindproc_null_2_svc;
break;
case YPBINDPROC_DOMAIN:
__xdr_argument = (xdrproc_t) __xdr_domainname;
__xdr_result = (xdrproc_t) __xdr_ypbind_resp;
local = (char *(*)(char *, struct svc_req *)) ypbindproc_domain_2_svc;
break;
case YPBINDPROC_SETDOM:
__xdr_argument = (xdrproc_t) __xdr_ypbind_setdom;
__xdr_result = (xdrproc_t) xdr_void;
local = (char *(*)(char *, struct svc_req *)) ypbindproc_setdom_2_svc;
break;
default:
svcerr_noproc(transp);
return;
}
(void) memset((char *)&argument, 0, sizeof (argument));
if (!svc_getargs(transp, __xdr_argument, (caddr_t) &argument)) {
svcerr_decode(transp);
return;
}
result = (*local)((char *)&argument, rqstp);
if (result != NULL && !svc_sendreply(transp, __xdr_result, result)) {
svcerr_systemerr(transp);
}
if (!svc_freeargs(transp, __xdr_argument, (caddr_t) &argument)) {
fprintf(stderr, "unable to free arguments");
exit(1);
}
return;
}
#endif
extern int debug_flag;
extern int dns_flag;
#ifndef _PATH_YP
#define _PATH_YP "/var/yp"
#endif
char *path_ypdb = _PATH_YP;
char *progname;
int main(int argc, char **argv)
{
register SVCXPRT *transp;
int i;
int my_port = -1;
int my_socket;
struct sockaddr_in socket_address;
int result;
int sunos_4_kludge = 0;
struct sigaction sa;
progname = strrchr (argv[0], '/');
if (progname == (char *) NULL)
progname = argv[0];
else
progname++;
openlog(progname, LOG_PID, TCPW_FACILITY);
for (i = 1; i < argc && argv[i][0] == '-'; i++)
{
if (strcmp(argv[i], "-debug") == 0 || strcmp(argv[i], "-d") == 0)
debug_flag = 1;
else if (strcmp(argv[i], "-dns") == 0 || strcmp(argv[i], "-b") == 0)
dns_flag = 1;
else if ((argv[i][1] == 'p') && (argv[i][2] >= '0') && (argv[i][2] <= '9'))
my_port = atoi(argv[i] + 2);
else if (strcmp(argv[i], "-k") == 0)
sunos_4_kludge = 1;
else
{
fprintf(stderr, "%s: Unknown command line switch: %s\n",
progname,
argv[i]);
exit(1);
}
}
if (!debug_flag)
if(daemon(0,0))
{
perror("daemon()");
exit (1);
}
if (debug_flag)
Perror("[Welcome to the NYS YP Server, version 0.13]\n");
if (i < argc)
{
path_ypdb = argv[i];
if (debug_flag)
Perror("Using database directory: %s\n", path_ypdb);
}
/* Change current directory to database location */
if (chdir(path_ypdb) < 0)
{
Perror("%s: chdir: %", argv[0], strerror(errno));
exit(1);
}
/*
* Ignore SIGPIPEs. They can hurt us if someone does a ypcat
* and then hits CTRL-C before it terminates.
*/
sigaction(SIGPIPE, NULL, &sa);
sa.sa_handler = SIG_IGN;
sa.sa_flags |= SA_RESTART;
sigaction(SIGPIPE, &sa, NULL);
sigaction(SIGCHLD, NULL, &sa);
sa.sa_flags |= SA_RESTART;
sa.sa_handler = reapchild;
sa.sa_mask = sigmask(SIGCHLD);
sigaction(SIGCHLD, &sa, NULL);
(void) pmap_unset(YPPROG, YPVERS);
if (sunos_4_kludge)
(void) pmap_unset(YPPROG, 1);
if (my_port >= 0)
{
my_socket = socket (AF_INET, SOCK_DGRAM, 0);
if (my_socket < 0)
{
Perror("%s: can not create UDP: %s",
progname, strerror(errno));
exit (1);
}
socket_address.sin_family = AF_INET;
socket_address.sin_addr.s_addr = htonl (INADDR_ANY);
socket_address.sin_port = htons (my_port);
result = bind (my_socket, (struct sockaddr *) &socket_address,
sizeof (socket_address));
if (result < 0)
{
Perror("%s: can not create UDP: %s",
progname, strerror(errno));
exit (1);
}
}
else
my_socket = RPC_ANYSOCK;
transp = svcudp_create(my_socket);
if (transp == NULL) {
Perror("cannot create udp service.");
exit(1);
}
if (!svc_register(transp, YPPROG, YPVERS, ypprog_2, IPPROTO_UDP)) {
Perror("unable to register (YPPROG, YPVERS, udp).");
exit(1);
}
if (sunos_4_kludge) {
/*
** This is just to make us reply to YP version 1 calls which SunOS 4's
** ypbind seems to insist on finding. If someone _really_ tries to
** use this the they will probably be bitten - _hard_, since I haven't
** got the faintest idea on how the XDR calls for YP version 1 should
** look like. The Domain_NoNack call seems to be compatible though :-)
*/
if (!svc_register(transp, YPPROG, 1, ypprog_2, IPPROTO_UDP)) {
fprintf(stderr, "unable to register (YPPROG, 1, udp).");
exit(1);
}
}
if (my_port >= 0)
{
my_socket = socket (AF_INET, SOCK_STREAM, 0);
if (my_socket < 0)
{
Perror("%s: can not create TCP: %s",
progname, strerror(errno));
exit (1);
}
socket_address.sin_family = AF_INET;
socket_address.sin_addr.s_addr = htonl (INADDR_ANY);
socket_address.sin_port = htons (my_port);
result = bind (my_socket, (struct sockaddr *) &socket_address,
sizeof (socket_address));
if (result < 0)
{
Perror("%s: can not create TCP: %s",
progname, strerror(errno));
exit (1);
}
}
else
my_socket = RPC_ANYSOCK;
transp = svctcp_create(my_socket, 0, 0);
if (transp == NULL) {
Perror("%s: cannot create tcp service\n", progname);
exit(1);
}
if (!svc_register(transp, YPPROG, YPVERS, ypprog_2, IPPROTO_TCP)) {
Perror("%s: unable to register (YPPROG, YPVERS, tcp)\n", progname);
exit(1);
}
my_svc_run();
Perror("svc_run returned");
exit(1);
/* NOTREACHED */
}
|