home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / MacPerl 5.0.3 / MacPerl Source ƒ / Perl5 / taint.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-26  |  1.4 KB  |  68 lines  |  [TEXT/MPS ]

  1. /*
  2.  * "...we will have peace, when you and all your works have perished--and
  3.  * the works of your dark master to whom you would deliver us.  You are a
  4.  * liar, Saruman, and a corrupter of men's hearts."  --Theoden
  5.  */
  6.  
  7. #include "EXTERN.h"
  8. #include "perl.h"
  9.  
  10. void
  11. taint_not(s)
  12. char *s;
  13. {
  14.     if (euid != uid)
  15.         croak("No %s allowed while running setuid", s);
  16.     if (egid != gid)
  17.         croak("No %s allowed while running setgid", s);
  18. }
  19.  
  20. void
  21. taint_proper(f, s)
  22. char *f;
  23. char *s;
  24. {
  25.     if (tainting) {
  26.     DEBUG_u(fprintf(stderr,"%s %d %d %d\n",s,tainted,uid, euid));
  27.     if (tainted) {
  28.         char *ug = 0;
  29.         if (euid != uid)
  30.         ug = " while running setuid";
  31.         else if (egid != gid)
  32.         ug = " while running setgid";
  33.         else if (tainting)
  34.         ug = " while running with -T switch";
  35.         if (ug) {
  36.         if (!unsafe)
  37.             croak(f, s, ug);
  38.         else if (dowarn)
  39.             warn(f, s, ug);
  40.         }
  41.     }
  42.     }
  43. }
  44.  
  45. void
  46. taint_env()
  47. {
  48.     SV** svp;
  49.  
  50.     if (tainting) {
  51.     MAGIC *mg = 0;
  52.     svp = hv_fetch(GvHVn(envgv),"PATH",4,FALSE);
  53.     if (!svp || *svp == &sv_undef || (mg = mg_find(*svp, 't'))) {
  54.         tainted = 1;
  55.         if (mg && MgTAINTEDDIR(mg))
  56.         taint_proper("Insecure directory in %s%s", "$ENV{PATH}");
  57.         else
  58.         taint_proper("Insecure %s%s", "$ENV{PATH}");
  59.     }
  60.     svp = hv_fetch(GvHVn(envgv),"IFS",3,FALSE);
  61.     if (svp && *svp != &sv_undef && mg_find(*svp, 't')) {
  62.         tainted = 1;
  63.         taint_proper("Insecure %s%s", "$ENV{IFS}");
  64.     }
  65.     }
  66. }
  67.  
  68.