~ubuntu-branches/ubuntu/natty/openbsd-inetd/natty

« back to all changes in this revision

Viewing changes to debian/patches/discard_env

  • Committer: Bazaar Package Importer
  • Author(s): Marco d'Itri
  • Date: 2008-12-15 02:00:52 UTC
  • mfrom: (4.1.1 intrepid)
  • Revision ID: james.westby@ubuntu.com-20081215020052-gwpkva043fq6nb1s
Tags: 0.20080125-2
* Added dh_md5sums to debian/rules, since apparently people nowadays
  believe again that it is a good idea. (Closes: #484483)
* Fixed the init script to povide "openbsd-inetd" instead of "inetd".
  (Closes: #507119)
* Updated patches misc_portability and setproctitle with some missing
  prototypes.
* Updated patch misc_portability with missing arguments to two syslog(3)
  calls.
* Updated patch libwrap to fix a possibly uninitialized variable.
  The last three fixes are courtesy of Denis Zaitsev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--- a/inetd.c
 
2
+++ b/inetd.c
 
3
@@ -301,6 +301,7 @@ int bump_nofile(void);
 
4
 struct servtab *enter(struct servtab *);
 
5
 int    matchconf(struct servtab *, struct servtab *);
 
6
 int    dg_broadcast(struct in_addr *in);
 
7
+void   discard_stupid_environment(void);
 
8
 
 
9
 #define NUMINT (sizeof(intab) / sizeof(struct inent))
 
10
 char   *CONFIG = _PATH_INETDCONF;
 
11
@@ -333,6 +334,7 @@ main(int argc, char *argv[], char *envp[
 
12
 {
 
13
        fd_set *fdsrp = NULL;
 
14
        int readablen = 0, ch;
 
15
+       int keepenv = 0;
 
16
        struct servtab *sep;
 
17
        extern char *optarg;
 
18
        extern int optind;
 
19
@@ -342,11 +344,14 @@ main(int argc, char *argv[], char *envp[
 
20
 
 
21
        initsetproctitle(argc, argv, envp);
 
22
 
 
23
-       while ((ch = getopt(argc, argv, "dR:")) != -1)
 
24
+       while ((ch = getopt(argc, argv, "dER:")) != -1)
 
25
                switch (ch) {
 
26
                case 'd':
 
27
                        debug = 1;
 
28
                        break;
 
29
+               case 'E':
 
30
+                       keepenv = 1;
 
31
+                       break;
 
32
                case 'R': {     /* invocation rate */
 
33
                        char *p;
 
34
                        int val;
 
35
@@ -364,13 +369,17 @@ main(int argc, char *argv[], char *envp[
 
36
                case '?':
 
37
                default:
 
38
                        fprintf(stderr,
 
39
-                           "usage: %s [-d] [-R rate] [configuration file]\n",
 
40
+                           "usage: %s [-dE] [-R rate] [configuration file]\n",
 
41
                            progname);
 
42
                        exit(1);
 
43
                }
 
44
        argc -= optind;
 
45
        argv += optind;
 
46
 
 
47
+       /* This must be called _after_ initsetproctitle and arg parsing */
 
48
+       if (!keepenv)
 
49
+               discard_stupid_environment();
 
50
+
 
51
        uid = getuid();
 
52
        if (uid != 0)
 
53
                CONFIG = NULL;
 
54
@@ -2071,3 +2080,45 @@ spawn(struct servtab *sep, int ctrl)
 
55
        if (!sep->se_wait && sep->se_socktype == SOCK_STREAM)
 
56
                close(ctrl);
 
57
 }
 
58
+
 
59
+/* from netkit+USAGI */
 
60
+void
 
61
+discard_stupid_environment(void)
 
62
+{
 
63
+       static const char *const junk[] = {
 
64
+               /* these are prefixes */
 
65
+               "CVS",
 
66
+               "DISPLAY=",
 
67
+               "EDITOR=",
 
68
+               "GROUP=",
 
69
+               "HOME=",
 
70
+               "IFS=",
 
71
+               "LD_",
 
72
+               "LOGNAME=",
 
73
+               "MAIL=",
 
74
+               "PATH=",
 
75
+               "PRINTER=",
 
76
+               "PWD=",
 
77
+               "SHELL=",
 
78
+               "SHLVL=",
 
79
+               "SSH",
 
80
+               "TERM",
 
81
+               "TMP",
 
82
+               "USER=",
 
83
+               "VISUAL=",
 
84
+               NULL
 
85
+               };
 
86
+
 
87
+       int i, k = 0;
 
88
+
 
89
+       for (i = 0; __environ[i]; i++) {
 
90
+               int found = 0, j;
 
91
+
 
92
+               for (j = 0; junk[j]; j++)
 
93
+                       if (!strncmp(__environ[i], junk[j], strlen(junk[j])))
 
94
+                               found = 1;
 
95
+               if (!found)
 
96
+                       __environ[k++] = __environ[i];
 
97
+       }
 
98
+       __environ[k] = NULL;
 
99
+}
 
100
--- a/inetd.8
 
101
+++ b/inetd.8
 
102
@@ -38,6 +38,7 @@
 
103
 .Sh SYNOPSIS
 
104
 .Nm inetd
 
105
 .Op Fl d
 
106
+.Op Fl E
 
107
 .Op Fl R Ar rate
 
108
 .Op Ar configuration file
 
109
 .Sh DESCRIPTION
 
110
@@ -62,6 +63,13 @@ The options are as follows:
 
111
 .Bl -tag -width Ds
 
112
 .It Fl d
 
113
 Turns on debugging.
 
114
+.It Fl E
 
115
+Prevents
 
116
+.Nm inetd
 
117
+from laundering the environment.  Without this option a selection of
 
118
+potentially harmful environent variables, including
 
119
+.Pa PATH ,
 
120
+will be removed and not inherited by services.
 
121
 .It Fl R Ar rate
 
122
 Specify the maximum number of times a service can be invoked
 
123
 in one minute; the default is 256.