Deleted Added
full compact
yp_server.c (22997) yp_server.c (24780)
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

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

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>
46
47#ifndef lint
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

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

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>
46
47#ifndef lint
48static const char rcsid[] = "$Id$";
48static const char rcsid[] = "$Id: yp_server.c,v 1.5 1997/03/15 06:06:06 wpaul Exp wpaul $";
49#endif /* not lint */
50
51int forked = 0;
52int children = 0;
53static char *master_string = "YP_MASTER_NAME";
54static char *order_string = "YP_LAST_MODIFIED";
55static int master_sz = sizeof("YP_MASTER_NAME") - 1;
56static int order_sz = sizeof("YP_LAST_MODIFIED") - 1;

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

300 argp->prog,argp->port); \
301 return(NULL);
302
303ypresp_xfr *
304ypproc_xfr_2_svc(ypreq_xfr *argp, struct svc_req *rqstp)
305{
306 static ypresp_xfr result;
307 struct sockaddr_in *rqhost;
49#endif /* not lint */
50
51int forked = 0;
52int children = 0;
53static char *master_string = "YP_MASTER_NAME";
54static char *order_string = "YP_LAST_MODIFIED";
55static int master_sz = sizeof("YP_MASTER_NAME") - 1;
56static int order_sz = sizeof("YP_LAST_MODIFIED") - 1;

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

300 argp->prog,argp->port); \
301 return(NULL);
302
303ypresp_xfr *
304ypproc_xfr_2_svc(ypreq_xfr *argp, struct svc_req *rqstp)
305{
306 static ypresp_xfr result;
307 struct sockaddr_in *rqhost;
308 ypresp_master *mres;
309 ypreq_nokey mreq;
308
309 result.transid = argp->transid;
310 rqhost = svc_getcaller(rqstp->rq_xprt);
311
310
311 result.transid = argp->transid;
312 rqhost = svc_getcaller(rqstp->rq_xprt);
313
314 /*
315 * The FreeBSD ypxfr(8) program will not talk to a ypserv(8)
316 * or rpc.ypxfrd(8) unless it's using a reserved port, but we
317 * may as well check that the process calling this procedure
318 * is also using one.
319 *
320 * yp_access() may also do a reserved port test, but only
321 * if the YP_SECURE flag is set in the map. For this procedure,
322 * the check should be unconditional.
323 */
324 if (ntohs(rqhost->sin_port) >= IPPORT_RESERVED) {
325 yp_error("ypxfr request from non-reserved port (%s:%d) -- \
326rejecting", inet_ntoa(rqhost->sin_addr), ntohs(rqhost->sin_port));
327 YPXFR_RETURN(YPXFR_REFUSED)
328 }
329
312#ifdef DB_CACHE
313 if (yp_access(argp->map_parms.map,
314 argp->map_parms.domain, (struct svc_req *)rqstp)) {
315#else
316 if (yp_access(argp->map_parms.map, (struct svc_req *)rqstp)) {
317#endif
330#ifdef DB_CACHE
331 if (yp_access(argp->map_parms.map,
332 argp->map_parms.domain, (struct svc_req *)rqstp)) {
333#else
334 if (yp_access(argp->map_parms.map, (struct svc_req *)rqstp)) {
335#endif
318 YPXFR_RETURN(YPXFR_REFUSED);
336 YPXFR_RETURN(YPXFR_REFUSED)
319 }
320
337 }
338
339
321 if (argp->map_parms.domain == NULL) {
340 if (argp->map_parms.domain == NULL) {
322 YPXFR_RETURN(YPXFR_BADARGS);
341 YPXFR_RETURN(YPXFR_BADARGS)
323 }
324
325 if (yp_validdomain(argp->map_parms.domain)) {
342 }
343
344 if (yp_validdomain(argp->map_parms.domain)) {
326 YPXFR_RETURN(YPXFR_NODOM);
345 YPXFR_RETURN(YPXFR_NODOM)
327 }
328
346 }
347
348 /*
349 * Determine the master host ourselves. The caller may
350 * be up to no good. This has the side effect of verifying
351 * that the requested map and domain actually exist.
352 */
353
354 mreq.domain = argp->map_parms.domain;
355 mreq.map = argp->map_parms.map;
356
357 mres = ypproc_master_2_svc(&mreq, rqstp);
358
359 if (mres->stat != YP_TRUE) {
360 yp_error("couldn't find master for map %s@%s",
361 argp->map_parms.map,
362 argp->map_parms.domain);
363 yp_error("host at %s (%s) may be pulling my leg",
364 argp->map_parms.peer,
365 inet_ntoa(rqhost->sin_addr));
366 YPXFR_RETURN(YPXFR_REFUSED)
367 }
368
329 switch(fork()) {
330 case 0:
331 {
332 char g[11], t[11], p[11];
333 char ypxfr_command[MAXPATHLEN + 2];
334
335 sprintf (ypxfr_command, "%sypxfr", _PATH_LIBEXEC);
336 sprintf (t, "%u", argp->transid);
337 sprintf (g, "%u", argp->prog);
338 sprintf (p, "%u", argp->port);
339 if (debug) {
340 close(0); close(1); close(2);
341 }
342 if (strcmp(yp_dir, _PATH_YP)) {
343 execl(ypxfr_command, "ypxfr",
344 "-d", argp->map_parms.domain,
369 switch(fork()) {
370 case 0:
371 {
372 char g[11], t[11], p[11];
373 char ypxfr_command[MAXPATHLEN + 2];
374
375 sprintf (ypxfr_command, "%sypxfr", _PATH_LIBEXEC);
376 sprintf (t, "%u", argp->transid);
377 sprintf (g, "%u", argp->prog);
378 sprintf (p, "%u", argp->port);
379 if (debug) {
380 close(0); close(1); close(2);
381 }
382 if (strcmp(yp_dir, _PATH_YP)) {
383 execl(ypxfr_command, "ypxfr",
384 "-d", argp->map_parms.domain,
345 "-h", argp->map_parms.peer,
385 "-h", mres->peer,
346 "-p", yp_dir, "-C", t,
347 g, inet_ntoa(rqhost->sin_addr),
348 p, argp->map_parms.map,
349 NULL);
350 } else {
351 execl(ypxfr_command, "ypxfr",
352 "-d", argp->map_parms.domain,
386 "-p", yp_dir, "-C", t,
387 g, inet_ntoa(rqhost->sin_addr),
388 p, argp->map_parms.map,
389 NULL);
390 } else {
391 execl(ypxfr_command, "ypxfr",
392 "-d", argp->map_parms.domain,
353 "-h", argp->map_parms.peer,
393 "-h", mres->peer,
354 "-C", t,
355 g, inet_ntoa(rqhost->sin_addr),
356 p, argp->map_parms.map,
357 NULL);
358 }
359 forked++;
360 yp_error("ypxfr execl(%s): %s", ypxfr_command, strerror(errno));
394 "-C", t,
395 g, inet_ntoa(rqhost->sin_addr),
396 p, argp->map_parms.map,
397 NULL);
398 }
399 forked++;
400 yp_error("ypxfr execl(%s): %s", ypxfr_command, strerror(errno));
361 YPXFR_RETURN(YPXFR_XFRERR);
401 YPXFR_RETURN(YPXFR_XFRERR)
362 break;
363 }
364 case -1:
365 yp_error("ypxfr fork(): %s", strerror(errno));
402 break;
403 }
404 case -1:
405 yp_error("ypxfr fork(): %s", strerror(errno));
366 YPXFR_RETURN(YPXFR_XFRERR);
406 YPXFR_RETURN(YPXFR_XFRERR)
367 break;
368 default:
369 result.xfrstat = YPXFR_SUCC;
370 children++;
371 forked = 0;
372 break;
373 }
374

--- 553 unchanged lines hidden ---
407 break;
408 default:
409 result.xfrstat = YPXFR_SUCC;
410 children++;
411 forked = 0;
412 break;
413 }
414

--- 553 unchanged lines hidden ---