~ubuntu-branches/debian/wheezy/apache2/wheezy

« back to all changes in this revision

Viewing changes to debian/patches/202_suexec-custom

  • Committer: Package Import Robot
  • Author(s): Stefan Fritsch, Stefan Fritsch, Arno Töll
  • Date: 2011-12-29 12:09:14 UTC
  • Revision ID: package-import@ubuntu.com-20111229120914-hv1j5bee6zhw8bjf
Tags: 2.2.21-4
[ Stefan Fritsch ]

* Security: Fix broken patch for CVE-2011-3607 (Integer overflow in
  ap_pregsub).
* Optimize debian/rules again to improve build time by doing most work in a
  single parallelized "build-%" target.

[ Arno Töll ]

* Fix "Suggest removing DefaultType from apache2.conf" change the DefaultType
  from text/plain to None. This lets the browser guess a proper MIME type
  instead of being forced to treat a given file according to our default type
  (Closes: #440058)
* Fix "add pre-rotate hook to logrotate script" execute scripts in
  /etc/logrotate.d/httpd-prerotate if available (Closes: #590096).
* Fix "Hide /icons index" Disables indexes on the icon directory. By upgrading
  to Debian's 3.0/quilt source format also images don't need to be generated
  at build time anymore. Hence, the icon date can no longer lead to
  information disclosure (Closes: #649888).
* Upgrade package to 3.0/quilt.
  + Remove uuencoded images, keep them in their binary format in debian/icons
  + Upgrade to quilt from dpatch and refresh all patches by keeping all hunks
    unchanged. Remove the `001_branding' patch by supplying -DPLATFORM at
    build time where needed Move the 200_cp_suexec.dpatch patch and
    202_suexec-custom.dpatch patch to debian/rules. 200_cp_suexec.dpatch was a
    script, not a patch which is not supported by quilt.
* Rewrite debian/rules and base it on dh(1).
  + use overrides where possible, replace some debhelper calls by our own
    implementation where needed. That's required since the Apache package is
    compiled in parts several times for each MPM once.
  + move some install operations to the their respective .install files
  + Support dpkg-buildflags now, which also enables by default hardening
    flags. Thus, remove them from their explicit appearance in debian/rules
  + Remove DEB_BUILD_OPTIONS legacy support. It comes for free when using
    dh(1)/dpkg-buildflags(1).
* Push debhelper compatibility to 8
* Remove unused Lintian overrides for the Debian source package remove and
  redundant priorities in debian/control.
* Add myself to Uploaders

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh /usr/share/dpatch/dpatch-run
 
2
## 202_suexec-custom.dpatch by Stefan Fritsch <sf@debian.org>
 
3
##
 
4
## All lines beginning with `## DP:' are a description of the patch.
 
5
## DP: the actual patch to make suexec-custom read a config file
 
6
 
 
7
@DPATCH@
 
8
--- a/support/suexec-custom.c
 
9
+++ b/support/suexec-custom.c
 
10
@@ -29,6 +29,7 @@
 
11
  *
 
12
  *
 
13
  */
 
14
+#define SUEXEC_CONFIG_DIR "/etc/apache2/suexec/"
 
15
 
 
16
 #include "apr.h"
 
17
 #include "ap_config.h"
 
18
@@ -39,6 +40,7 @@
 
19
 #include <sys/types.h>
 
20
 #include <string.h>
 
21
 #include <time.h>
 
22
+#include <ctype.h>
 
23
 #if APR_HAVE_UNISTD_H
 
24
 #include <unistd.h>
 
25
 #endif
 
26
@@ -203,6 +205,26 @@
 
27
     return;
 
28
 }
 
29
 
 
30
+static int read_line(char *buf, FILE *file) {
 
31
+    char *p;
 
32
+    p = fgets(buf, AP_MAXPATH+1, file);
 
33
+    if (!p) return 0;
 
34
+    if (*p == '\0') return 1;
 
35
+
 
36
+    p = buf;
 
37
+    while (*p)
 
38
+        p++;
 
39
+    p--;
 
40
+
 
41
+    /* remove trailing space and slash */
 
42
+    while ( isspace(*p) && p >= buf )
 
43
+        *p-- = '\0';
 
44
+    while ( *p == '/' && p >= buf )
 
45
+        *p-- = '\0';
 
46
+
 
47
+    return 1;
 
48
+}
 
49
+
 
50
 static void clean_env(void)
 
51
 {
 
52
     char pathbuf[512];
 
53
@@ -266,6 +288,10 @@
 
54
     struct stat dir_info;   /* directory info holder     */
 
55
     struct stat prg_info;   /* program info holder       */
 
56
     int cwdh;               /* handle to cwd             */
 
57
+    char *suexec_docroot        = NULL;
 
58
+    char *suexec_userdir_suffix = NULL;
 
59
+    char *filename              = NULL;
 
60
+    FILE *configfile;
 
61
 
 
62
     /*
 
63
      * Start with a "clean" environment
 
64
@@ -296,15 +322,10 @@
 
65
             || (! strcmp(AP_HTTPD_USER, pw->pw_name)))
 
66
 #endif /* _OSD_POSIX */
 
67
         ) {
 
68
-#ifdef AP_DOC_ROOT
 
69
-        fprintf(stderr, " -D AP_DOC_ROOT=\"%s\"\n", AP_DOC_ROOT);
 
70
-#endif
 
71
+       fprintf(stderr, " -D SUEXEC_CONFIG_DIR=%s\n", SUEXEC_CONFIG_DIR);
 
72
 #ifdef AP_GID_MIN
 
73
         fprintf(stderr, " -D AP_GID_MIN=%d\n", AP_GID_MIN);
 
74
 #endif
 
75
-#ifdef AP_HTTPD_USER
 
76
-        fprintf(stderr, " -D AP_HTTPD_USER=\"%s\"\n", AP_HTTPD_USER);
 
77
-#endif
 
78
 #ifdef AP_LOG_EXEC
 
79
         fprintf(stderr, " -D AP_LOG_EXEC=\"%s\"\n", AP_LOG_EXEC);
 
80
 #endif
 
81
@@ -317,9 +338,6 @@
 
82
 #ifdef AP_UID_MIN
 
83
         fprintf(stderr, " -D AP_UID_MIN=%d\n", AP_UID_MIN);
 
84
 #endif
 
85
-#ifdef AP_USERDIR_SUFFIX
 
86
-        fprintf(stderr, " -D AP_USERDIR_SUFFIX=\"%s\"\n", AP_USERDIR_SUFFIX);
 
87
-#endif
 
88
         exit(0);
 
89
     }
 
90
     /*
 
91
@@ -334,23 +352,6 @@
 
92
     target_gname = argv[2];
 
93
     cmd = argv[3];
 
94
 
 
95
-    /*
 
96
-     * Check to see if the user running this program
 
97
-     * is the user allowed to do so as defined in
 
98
-     * suexec.h.  If not the allowed user, error out.
 
99
-     */
 
100
-#ifdef _OSD_POSIX
 
101
-    /* User name comparisons are case insensitive on BS2000/OSD */
 
102
-    if (strcasecmp(AP_HTTPD_USER, pw->pw_name)) {
 
103
-        log_err("user mismatch (%s instead of %s)\n", pw->pw_name, AP_HTTPD_USER);
 
104
-        exit(103);
 
105
-    }
 
106
-#else  /*_OSD_POSIX*/
 
107
-    if (strcmp(AP_HTTPD_USER, pw->pw_name)) {
 
108
-        log_err("user mismatch (%s instead of %s)\n", pw->pw_name, AP_HTTPD_USER);
 
109
-        exit(103);
 
110
-    }
 
111
-#endif /*_OSD_POSIX*/
 
112
 
 
113
     /*
 
114
      * Check for a leading '/' (absolute path) in the command to be executed,
 
115
@@ -375,6 +376,63 @@
 
116
     }
 
117
 
 
118
     /*
 
119
+     * Check to see if the user running this program
 
120
+     * is the user allowed to do so as defined in
 
121
+     * SUEXEC_CONFIG_DIR/username
 
122
+     * If not, error out.
 
123
+     */
 
124
+    filename = malloc(AP_MAXPATH+1);
 
125
+    suexec_docroot = malloc(AP_MAXPATH+1);
 
126
+    suexec_userdir_suffix = malloc(AP_MAXPATH+1);
 
127
+    if (!filename || !suexec_docroot || !suexec_userdir_suffix) {
 
128
+        log_err("malloc failed\n");
 
129
+       exit(120);
 
130
+    }
 
131
+
 
132
+    strncpy(filename, SUEXEC_CONFIG_DIR, AP_MAXPATH);
 
133
+    strncat(filename, pw->pw_name, AP_MAXPATH);
 
134
+    filename[AP_MAXPATH] = '\0';
 
135
+
 
136
+    configfile = fopen(filename, "r");
 
137
+    if (!configfile) {
 
138
+       log_err("User %s not allowed: Could not open config file %s\n", pw->pw_name, filename);
 
139
+       exit(123);
 
140
+    }
 
141
+
 
142
+    if (!read_line(suexec_docroot, configfile)) {
 
143
+       log_err("Could not read docroot from %s\n", filename);
 
144
+       exit(124);
 
145
+    }
 
146
+
 
147
+    if (!read_line(suexec_userdir_suffix, configfile)) {
 
148
+       log_err("Could not read userdir suffix from %s\n", filename);
 
149
+       exit(125);
 
150
+    }
 
151
+
 
152
+    fclose(configfile);
 
153
+
 
154
+    if (userdir) {
 
155
+        if ( !isalnum(*suexec_userdir_suffix) && suexec_userdir_suffix[0] != '.') {
 
156
+               log_err("userdir suffix disabled in %s\n", filename);
 
157
+               exit(126);
 
158
+       }
 
159
+    }
 
160
+    else {
 
161
+       if (suexec_docroot[0] != '/') {
 
162
+               log_err("docroot disabled in %s\n", filename);
 
163
+               exit(127);
 
164
+       }
 
165
+
 
166
+       if (suexec_docroot[1] == '/' ||
 
167
+           suexec_docroot[1] == '.' ||
 
168
+           suexec_docroot[1] == '\0' )
 
169
+       {
 
170
+               log_err("invalid docroot %s in %s\n", suexec_docroot, filename);
 
171
+               exit(128);
 
172
+       }
 
173
+    }
 
174
+    
 
175
+    /*
 
176
      * Error out if the target username is invalid.
 
177
      */
 
178
     if (strspn(target_uname, "1234567890") != strlen(target_uname)) {
 
179
@@ -508,7 +566,7 @@
 
180
 
 
181
     if (userdir) {
 
182
         if (((chdir(target_homedir)) != 0) ||
 
183
-            ((chdir(AP_USERDIR_SUFFIX)) != 0) ||
 
184
+            ((chdir(suexec_userdir_suffix)) != 0) ||
 
185
             ((getcwd(dwd, AP_MAXPATH)) == NULL) ||
 
186
             ((fchdir(cwdh)) != 0)) {
 
187
             log_err("cannot get docroot information (%s)\n", target_homedir);
 
188
@@ -516,10 +574,10 @@
 
189
         }
 
190
     }
 
191
     else {
 
192
-        if (((chdir(AP_DOC_ROOT)) != 0) ||
 
193
+        if (((chdir(suexec_docroot)) != 0) ||
 
194
             ((getcwd(dwd, AP_MAXPATH)) == NULL) ||
 
195
             ((fchdir(cwdh)) != 0)) {
 
196
-            log_err("cannot get docroot information (%s)\n", AP_DOC_ROOT);
 
197
+            log_err("cannot get docroot information (%s)\n", suexec_docroot);
 
198
             exit(113);
 
199
         }
 
200
     }