perl 5.000
[p5sagit/p5-mst-13.2.git] / taint.c
CommitLineData
a0d0e21e 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
463ee0b2 7#include "EXTERN.h"
8#include "perl.h"
9
10void
11taint_not(s)
12char *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
79072805 20void
21taint_proper(f, s)
22char *f;
23char *s;
24{
463ee0b2 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 }
79072805 42 }
43}
44
45void
46taint_env()
47{
48 SV** svp;
49
463ee0b2 50 if (tainting) {
8990e307 51 MAGIC *mg = 0;
463ee0b2 52 svp = hv_fetch(GvHVn(envgv),"PATH",4,FALSE);
8990e307 53 if (!svp || *svp == &sv_undef || (mg = mg_find(*svp, 't'))) {
463ee0b2 54 tainted = 1;
8990e307 55 if (mg && MgTAINTEDDIR(mg))
a0d0e21e 56 taint_proper("Insecure directory in %s%s", "$ENV{PATH}");
463ee0b2 57 else
a0d0e21e 58 taint_proper("Insecure %s%s", "$ENV{PATH}");
463ee0b2 59 }
60 svp = hv_fetch(GvHVn(envgv),"IFS",3,FALSE);
61 if (svp && *svp != &sv_undef && mg_find(*svp, 't')) {
62 tainted = 1;
a0d0e21e 63 taint_proper("Insecure %s%s", "$ENV{IFS}");
463ee0b2 64 }
79072805 65 }
66}
67