yp_server.c (778c7b1c1c6bcd696918f410306457c989a65d33) yp_server.c (77732bc551aa87226708ef4ccb3477c6b87115e2)
1/*
2 * Copyright (c) 1995
3 * Bill Paul <wpaul@ctr.columbia.edu>. 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 <dirent.h>
38#include <sys/stat.h>
39#include <sys/param.h>
40#include <errno.h>
41#include <sys/types.h>
42#include <sys/socket.h>
43#include <netinet/in.h>
44#include <arpa/inet.h>
1/*
2 * Copyright (c) 1995
3 * Bill Paul <wpaul@ctr.columbia.edu>. 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 <dirent.h>
38#include <sys/stat.h>
39#include <sys/param.h>
40#include <errno.h>
41#include <sys/types.h>
42#include <sys/socket.h>
43#include <netinet/in.h>
44#include <arpa/inet.h>
45#include <rpc/rpc.h>
45
46#ifndef lint
46
47#ifndef lint
47static char rcsid[] = "$Id: yp_server.c,v 1.18 1995/12/16 04:01:55 wpaul Exp $";
48static char rcsid[] = "$Id: yp_server.c,v 1.1.1.1 1995/12/16 20:54:17 wpaul Exp $";
48#endif /* not lint */
49
50int forked = 0;
51int children = 0;
52DB *spec_dbp = NULL; /* Special global DB handle for ypproc_all. */
53
54void *
55ypproc_null_2_svc(void *argp, struct svc_req *rqstp)

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

130 result.val.valdat_val = data.data;
131 }
132
133 /*
134 * Do DNS lookups for hosts maps if database lookup failed.
135 */
136
137 if (do_dns && result.stat != YP_TRUE && strstr(argp->map, "hosts")) {
49#endif /* not lint */
50
51int forked = 0;
52int children = 0;
53DB *spec_dbp = NULL; /* Special global DB handle for ypproc_all. */
54
55void *
56ypproc_null_2_svc(void *argp, struct svc_req *rqstp)

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

131 result.val.valdat_val = data.data;
132 }
133
134 /*
135 * Do DNS lookups for hosts maps if database lookup failed.
136 */
137
138 if (do_dns && result.stat != YP_TRUE && strstr(argp->map, "hosts")) {
138 char *rval;
139 char *rval = NULL;
139
140 /* DNS lookups can take time -- do them in a subprocess */
141
142 if (!debug && children < MAX_CHILDREN && fork()) {
143 children++;
144 forked = 0;
145 /*
146 * Returning NULL here prevents svc_sendreply()

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

263 result.key.keydat_val = key.data;
264 result.val.valdat_len = data.size;
265 result.val.valdat_val = data.data;
266 }
267
268 return (&result);
269}
270
140
141 /* DNS lookups can take time -- do them in a subprocess */
142
143 if (!debug && children < MAX_CHILDREN && fork()) {
144 children++;
145 forked = 0;
146 /*
147 * Returning NULL here prevents svc_sendreply()

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

264 result.key.keydat_val = key.data;
265 result.val.valdat_len = data.size;
266 result.val.valdat_val = data.data;
267 }
268
269 return (&result);
270}
271
272static void ypxfr_callback(rval,addr,transid,prognum,port)
273 ypxfrstat rval;
274 struct sockaddr_in *addr;
275 unsigned int transid;
276 unsigned int prognum;
277 unsigned long port;
278{
279 CLIENT *clnt;
280 int sock = RPC_ANYSOCK;
281 struct timeval timeout;
282 yppushresp_xfr ypxfr_resp;
283
284 timeout.tv_sec = 20;
285 timeout.tv_usec = 0;
286 addr->sin_port = htons(port);
287
288 if ((clnt = clntudp_create(addr, prognum, 1, timeout, &sock)) == NULL)
289 yp_error("%s", clnt_spcreateerror("failed to establish \
290callback handle"));
291
292 ypxfr_resp.status = rval;
293 ypxfr_resp.transid = transid;
294
295 if (yppushproc_xfrresp_1(&ypxfr_resp, clnt) == NULL)
296 yp_error("%s", clnt_sperror(clnt, "ypxfr callback failed"));
297
298 clnt_destroy(clnt);
299 return;
300}
301
271ypresp_xfr *
272ypproc_xfr_2_svc(ypreq_xfr *argp, struct svc_req *rqstp)
273{
274 static ypresp_xfr result;
302ypresp_xfr *
303ypproc_xfr_2_svc(ypreq_xfr *argp, struct svc_req *rqstp)
304{
305 static ypresp_xfr result;
306 struct sockaddr_in *rqhost;
275
276 if (yp_access(argp->map_parms.map, (struct svc_req *)rqstp)) {
277 result.xfrstat = YPXFR_REFUSED;
278 return(&result);
279 }
280
281 if (argp->map_parms.domain == NULL) {
282 result.xfrstat = YPXFR_BADARGS;
283 return (&result);
284 }
285
286 if (yp_validdomain(argp->map_parms.domain)) {
287 result.xfrstat = YPXFR_NODOM;
288 return(&result);
289 }
290
307
308 if (yp_access(argp->map_parms.map, (struct svc_req *)rqstp)) {
309 result.xfrstat = YPXFR_REFUSED;
310 return(&result);
311 }
312
313 if (argp->map_parms.domain == NULL) {
314 result.xfrstat = YPXFR_BADARGS;
315 return (&result);
316 }
317
318 if (yp_validdomain(argp->map_parms.domain)) {
319 result.xfrstat = YPXFR_NODOM;
320 return(&result);
321 }
322
323 rqhost = svc_getcaller(rqstp->rq_xprt);
324
291 switch(fork()) {
292 case 0:
293 {
294 char g[11], t[11], p[11];
325 switch(fork()) {
326 case 0:
327 {
328 char g[11], t[11], p[11];
295 struct sockaddr_in *rqhost;
296 char ypxfr_command[MAXPATHLEN + 2];
297
329 char ypxfr_command[MAXPATHLEN + 2];
330
298 rqhost = svc_getcaller(rqstp->rq_xprt);
299 sprintf (ypxfr_command, "%sypxfr", _PATH_LIBEXEC);
300 sprintf (t, "%u", argp->transid);
301 sprintf (g, "%u", argp->prog);
302 sprintf (p, "%u", argp->port);
331 sprintf (ypxfr_command, "%sypxfr", _PATH_LIBEXEC);
332 sprintf (t, "%u", argp->transid);
333 sprintf (g, "%u", argp->prog);
334 sprintf (p, "%u", argp->port);
303 children++;
304 forked = 0;
305 execl(ypxfr_command, "ypxfr", "-d", argp->map_parms.domain,
306 "-h", argp->map_parms.peer, "-f", "-C", t, g,
307 inet_ntoa(rqhost->sin_addr), p, argp->map_parms.map,
308 NULL);
335 if (debug)
336 close(0); close(1); close(2);
337 if (strcmp(yp_dir, _PATH_YP)) {
338 execl(ypxfr_command, "ypxfr", "-d", argp->map_parms.domain,
339 "-h", argp->map_parms.peer, "-f", "-p", yp_dir, "-C", t,
340 g, inet_ntoa(rqhost->sin_addr), p, argp->map_parms.map,
341 NULL);
342 } else {
343 execl(ypxfr_command, "ypxfr", "-d", argp->map_parms.domain,
344 "-h", argp->map_parms.peer, "-f", "-C", t, g,
345 inet_ntoa(rqhost->sin_addr), p, argp->map_parms.map,
346 NULL);
347 }
348 forked++;
309 yp_error("ypxfr execl(): %s", strerror(errno));
349 yp_error("ypxfr execl(): %s", strerror(errno));
310 return(NULL);
350 ypxfr_callback(YPXFR_XFRERR,rqhost,argp->transid,
351 argp->prog,argp->port);
352 result.xfrstat = YPXFR_XFRERR;
353 return(&result);
354 break;
311 }
312 case -1:
313 yp_error("ypxfr fork(): %s", strerror(errno));
355 }
356 case -1:
357 yp_error("ypxfr fork(): %s", strerror(errno));
358 ypxfr_callback(YPXFR_XFRERR,rqhost,argp->transid,
359 argp->prog,argp->port);
314 result.xfrstat = YPXFR_XFRERR;
360 result.xfrstat = YPXFR_XFRERR;
361 return(&result);
315 break;
316 default:
362 break;
363 default:
317 result.xfrstat = YPXFR_SUCC;
318 forked++;
364 children++;
365 forked = 0;
319 break;
320 }
366 break;
367 }
321
322 result.transid = argp->transid;
323 return (&result);
368 /* Don't return anything -- it's up to ypxfr to do that. */
369 return (NULL);
324}
325
326void *
327ypproc_clear_2_svc(void *argp, struct svc_req *rqstp)
328{
329 static char * result;
330 static char rval = 0;
331

--- 295 unchanged lines hidden ---
370}
371
372void *
373ypproc_clear_2_svc(void *argp, struct svc_req *rqstp)
374{
375 static char * result;
376 static char rval = 0;
377

--- 295 unchanged lines hidden ---