home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / security / portmap_3.shar.Z / portmap_3.shar / diffs_wrt_bsd < prev    next >
Encoding:
Text File  |  1993-11-20  |  7.5 KB  |  326 lines

  1. *** portmap.c.bsd    Sun May  3 22:39:52 1992
  2. --- portmap.c    Sun Nov 21 16:22:31 1993
  3. ***************
  4. *** 83,99 ****
  5.   #include <rpc/rpc.h>
  6.   #include <rpc/pmap_prot.h>
  7.   #include <stdio.h>
  8. - #include <stdlib.h>
  9. - #include <string.h>
  10.   #include <syslog.h>
  11. - #include <unistd.h>
  12.   #include <netdb.h>
  13.   #include <sys/socket.h>
  14.   #include <sys/ioctl.h>
  15.   #include <sys/wait.h>
  16.   #include <sys/signal.h>
  17.   #include <sys/resource.h>
  18.   
  19.   void reg_service();
  20.   void reap();
  21.   static void callit();
  22. --- 83,115 ----
  23.   #include <rpc/rpc.h>
  24.   #include <rpc/pmap_prot.h>
  25.   #include <stdio.h>
  26.   #include <syslog.h>
  27.   #include <netdb.h>
  28.   #include <sys/socket.h>
  29.   #include <sys/ioctl.h>
  30.   #include <sys/wait.h>
  31.   #include <sys/signal.h>
  32. + #include <sys/time.h>
  33.   #include <sys/resource.h>
  34. + #ifdef SYSV40
  35. + #include <netinet/in.h>
  36. + #endif
  37.   
  38. + extern char *strerror();
  39. + extern char *malloc();
  40. + #ifndef LOG_PERROR
  41. + #define LOG_PERROR 0
  42. + #endif
  43. + #ifndef LOG_DAEMON
  44. + #define LOG_DAEMON 0
  45. + #endif
  46. + #ifndef svc_getcaller        /* SYSV4 */
  47. + #  define svc_getcaller svc_getrpccaller
  48. + #endif
  49.   void reg_service();
  50.   void reap();
  51.   static void callit();
  52. ***************
  53. *** 101,106 ****
  54. --- 117,124 ----
  55.   int debugging = 0;
  56.   extern int errno;
  57.   
  58. + #include "pmap_check.h"
  59.   main(argc, argv)
  60.       int argc;
  61.       char **argv;
  62. ***************
  63. *** 111,117 ****
  64.       int len = sizeof(struct sockaddr_in);
  65.       register struct pmaplist *pml;
  66.   
  67. !     while ((c = getopt(argc, argv, "d")) != EOF) {
  68.           switch (c) {
  69.   
  70.           case 'd':
  71. --- 129,135 ----
  72.       int len = sizeof(struct sockaddr_in);
  73.       register struct pmaplist *pml;
  74.   
  75. !     while ((c = getopt(argc, argv, "dv")) != EOF) {
  76.           switch (c) {
  77.   
  78.           case 'd':
  79. ***************
  80. *** 118,125 ****
  81.               debugging = 1;
  82.               break;
  83.   
  84.           default:
  85. !             (void) fprintf(stderr, "usage: %s [-d]\n", argv[0]);
  86.               exit(1);
  87.           }
  88.       }
  89. --- 136,149 ----
  90.               debugging = 1;
  91.               break;
  92.   
  93. +         case 'v':
  94. +             verboselog = 1;
  95. +             break;
  96.           default:
  97. !             (void) fprintf(stderr, "usage: %s [-dv]\n", argv[0]);
  98. !             (void) fprintf(stderr, "-d: debugging mode\n");
  99. !             (void) fprintf(stderr, "-v: verbose logging\n");
  100.               exit(1);
  101.           }
  102.       }
  103. ***************
  104. *** 129,136 ****
  105.           exit(1);
  106.       }
  107.   
  108.       openlog("portmap", debugging ? LOG_PID | LOG_PERROR : LOG_PID,
  109. !         LOG_DAEMON);
  110.   
  111.       if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
  112.           syslog(LOG_ERR, "cannot create udp socket: %m");
  113. --- 153,164 ----
  114.           exit(1);
  115.       }
  116.   
  117. + #ifdef LOG_MAIL
  118.       openlog("portmap", debugging ? LOG_PID | LOG_PERROR : LOG_PID,
  119. !         FACILITY);
  120. ! #else
  121. !     openlog("portmap", debugging ? LOG_PID | LOG_PERROR : LOG_PID);
  122. ! #endif
  123.   
  124.       if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
  125.           syslog(LOG_ERR, "cannot create udp socket: %m");
  126. ***************
  127. *** 182,188 ****
  128. --- 210,222 ----
  129.   
  130.       (void)svc_register(xprt, PMAPPROG, PMAPVERS, reg_service, FALSE);
  131.   
  132. +     /* additional initializations */
  133. +     check_startup();
  134. + #ifdef IGNORE_SIGCHLD            /* Lionel Cons <cons@dxcern.cern.ch> */
  135. +     (void)signal(SIGCHLD, SIG_IGN);
  136. + #else
  137.       (void)signal(SIGCHLD, reap);
  138. + #endif
  139.       svc_run();
  140.       syslog(LOG_ERR, "run_svc returned unexpectedly");
  141.       abort();
  142. ***************
  143. *** 230,235 ****
  144. --- 264,276 ----
  145.       int ans, port;
  146.       caddr_t t;
  147.       
  148. +     /*
  149. +      * Later wrappers change the logging severity on the fly. Reset to
  150. +      * defaults before handling the next request.
  151. +      */
  152. +     allow_severity = LOG_INFO;
  153. +     deny_severity = LOG_WARNING;
  154.       if (debugging)
  155.           (void) fprintf(stderr, "server: about do a switch\n");
  156.       switch (rqstp->rq_proc) {
  157. ***************
  158. *** 238,243 ****
  159. --- 279,286 ----
  160.           /*
  161.            * Null proc call
  162.            */
  163. +         /* remote host authorization check */
  164. +         check_default(svc_getcaller(xprt), rqstp->rq_proc, (u_long) 0);
  165.           if (!svc_sendreply(xprt, xdr_void, (caddr_t)0) && debugging) {
  166.               abort();
  167.           }
  168. ***************
  169. *** 250,255 ****
  170. --- 293,304 ----
  171.           if (!svc_getargs(xprt, xdr_pmap, ®))
  172.               svcerr_decode(xprt);
  173.           else {
  174. +             /* reject non-local requests, protect priv. ports */
  175. +             if (!check_setunset(svc_getcaller(xprt), 
  176. +                 rqstp->rq_proc, reg.pm_prog, reg.pm_port)) {
  177. +                 ans = 0;
  178. +                 goto done;
  179. +             } 
  180.               /*
  181.                * check to see if already used
  182.                * find_service returns a hit even if
  183. ***************
  184. *** 299,304 ****
  185. --- 348,357 ----
  186.               svcerr_decode(xprt);
  187.           else {
  188.               ans = 0;
  189. +             /* reject non-local requests */
  190. +             if (!check_setunset(svc_getcaller(xprt), 
  191. +                 rqstp->rq_proc, reg.pm_prog, (u_long) 0))
  192. +                 goto done;
  193.               for (prevpml = NULL, pml = pmaplist; pml != NULL; ) {
  194.                   if ((pml->pml_map.pm_prog != reg.pm_prog) ||
  195.                       (pml->pml_map.pm_vers != reg.pm_vers)) {
  196. ***************
  197. *** 308,313 ****
  198. --- 361,374 ----
  199.                       continue;
  200.                   }
  201.                   /* found it; pml moves forward, prevpml stays */
  202. +                 /* privileged port check */
  203. +                 if (!check_privileged_port(svc_getcaller(xprt), 
  204. +                     rqstp->rq_proc, 
  205. +                     reg.pm_prog, 
  206. +                     pml->pml_map.pm_port)) {
  207. +                     ans = 0;
  208. +                     break;
  209. +                 }
  210.                   ans = 1;
  211.                   t = (caddr_t)pml;
  212.                   pml = pml->pml_next;
  213. ***************
  214. *** 332,337 ****
  215. --- 393,405 ----
  216.           if (!svc_getargs(xprt, xdr_pmap, ®))
  217.               svcerr_decode(xprt);
  218.           else {
  219. +             /* remote host authorization check */
  220. +             if (!check_default(svc_getcaller(xprt), 
  221. +                 rqstp->rq_proc, 
  222. +                 reg.pm_prog)) {
  223. +                 ans = 0;
  224. +                 goto done;
  225. +             }
  226.               fnd = find_service(reg.pm_prog, reg.pm_vers, reg.pm_prot);
  227.               if (fnd)
  228.                   port = fnd->pml_map.pm_port;
  229. ***************
  230. *** 352,359 ****
  231.           if (!svc_getargs(xprt, xdr_void, NULL))
  232.               svcerr_decode(xprt);
  233.           else {
  234.               if ((!svc_sendreply(xprt, xdr_pmaplist,
  235. !                 (caddr_t)&pmaplist)) && debugging) {
  236.                   (void) fprintf(stderr, "svc_sendreply\n");
  237.                   abort();
  238.               }
  239. --- 420,435 ----
  240.           if (!svc_getargs(xprt, xdr_void, NULL))
  241.               svcerr_decode(xprt);
  242.           else {
  243. +             /* remote host authorization check */
  244. +             struct pmaplist *p;
  245. +             if (!check_default(svc_getcaller(xprt), 
  246. +                 rqstp->rq_proc, (u_long) 0)) {
  247. +                 p = 0;    /* send empty list */
  248. +             } else {
  249. +                 p = pmaplist;
  250. +             }
  251.               if ((!svc_sendreply(xprt, xdr_pmaplist,
  252. !                 (caddr_t)&p)) && debugging) {
  253.                   (void) fprintf(stderr, "svc_sendreply\n");
  254.                   abort();
  255.               }
  256. ***************
  257. *** 372,377 ****
  258. --- 448,455 ----
  259.           break;
  260.   
  261.       default:
  262. +         /* remote host authorization check */
  263. +         check_default(svc_getcaller(xprt), rqstp->rq_proc, (u_long) 0);
  264.           svcerr_noproc(xprt);
  265.           break;
  266.       }
  267. ***************
  268. *** 499,504 ****
  269. --- 577,586 ----
  270.       timeout.tv_usec = 0;
  271.       a.rmt_args.args = buf;
  272.       if (!svc_getargs(xprt, xdr_rmtcall_args, &a))
  273. +         return;
  274. +     /* host and service access control */
  275. +     if (!check_callit(svc_getcaller(xprt), 
  276. +         rqstp->rq_proc, a.rmt_prog, a.rmt_proc))
  277.           return;
  278.       if ((pml = find_service(a.rmt_prog, a.rmt_vers,
  279.           (u_long)IPPROTO_UDP)) == NULL)
  280. *** daemon.c.bsd    Sun May  3 22:45:10 1992
  281. --- daemon.c    Thu Jun 11 22:53:12 1992
  282. ***************
  283. *** 35,44 ****
  284.   static char sccsid[] = "@(#)daemon.c    5.3 (Berkeley) 12/28/90";
  285.   #endif /* LIBC_SCCS and not lint */
  286.   
  287. ! #include <sys/fcntl.h>
  288. ! #include <unistd.h>
  289. ! #include <paths.h>
  290.   
  291.   daemon(nochdir, noclose)
  292.       int nochdir, noclose;
  293.   {
  294. --- 35,50 ----
  295.   static char sccsid[] = "@(#)daemon.c    5.3 (Berkeley) 12/28/90";
  296.   #endif /* LIBC_SCCS and not lint */
  297.   
  298. ! #include <fcntl.h>
  299.   
  300. + /* From unistd.h */
  301. + #define STDIN_FILENO    0
  302. + #define STDOUT_FILENO    1
  303. + #define STDERR_FILENO    2
  304. + /* From paths.h */
  305. + #define _PATH_DEVNULL    "/dev/null"
  306.   daemon(nochdir, noclose)
  307.       int nochdir, noclose;
  308.   {
  309. ***************
  310. *** 62,65 ****
  311. --- 68,72 ----
  312.                   (void) close(devnull);
  313.           }
  314.       }
  315. +     return(0);
  316.   }
  317.