~ubuntu-branches/ubuntu/natty/lighttpd/natty

« back to all changes in this revision

Viewing changes to src/mod_cgi.c

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Krzyżaniak (eloy)
  • Date: 2009-10-30 17:37:29 UTC
  • mto: (6.1.4 squeeze)
  • mto: This revision was merged to the branch mainline in revision 50.
  • Revision ID: james.westby@ubuntu.com-20091030173729-ehmsdiba9nkcd0j7
Tags: upstream-1.4.24
Import upstream version 1.4.24

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "server.h"
 
2
#include "stat_cache.h"
 
3
#include "keyvalue.h"
 
4
#include "log.h"
 
5
#include "connections.h"
 
6
#include "joblist.h"
 
7
#include "http_chunk.h"
 
8
 
 
9
#include "plugin.h"
 
10
 
1
11
#include <sys/types.h>
 
12
 
2
13
#ifdef __WIN32
3
 
#include <winsock2.h>
 
14
# include <winsock2.h>
4
15
#else
5
 
#include <sys/socket.h>
6
 
#include <sys/wait.h>
7
 
#include <sys/mman.h>
8
 
 
9
 
#include <netinet/in.h>
10
 
 
11
 
#include <arpa/inet.h>
 
16
# include <sys/socket.h>
 
17
# include <sys/wait.h>
 
18
# include <sys/mman.h>
 
19
# include <netinet/in.h>
 
20
# include <arpa/inet.h>
12
21
#endif
13
22
 
14
23
#include <unistd.h>
23
32
#include <stdio.h>
24
33
#include <fcntl.h>
25
34
 
26
 
#include "server.h"
27
 
#include "stat_cache.h"
28
 
#include "keyvalue.h"
29
 
#include "log.h"
30
 
#include "connections.h"
31
 
#include "joblist.h"
32
 
#include "http_chunk.h"
33
 
 
34
 
#include "plugin.h"
35
 
 
36
35
#ifdef HAVE_SYS_FILIO_H
37
36
# include <sys/filio.h>
38
37
#endif
56
55
 
57
56
typedef struct {
58
57
        array *cgi;
 
58
        unsigned short execute_x_only;
59
59
} plugin_config;
60
60
 
61
61
typedef struct {
151
151
 
152
152
        config_values_t cv[] = {
153
153
                { "cgi.assign",                  NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },       /* 0 */
 
154
                { "cgi.execute-x-only",          NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION },     /* 1 */
154
155
                { NULL,                          NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET}
155
156
        };
156
157
 
165
166
                assert(s);
166
167
 
167
168
                s->cgi    = array_init();
 
169
                s->execute_x_only = 0;
168
170
 
169
171
                cv[0].destination = s->cgi;
 
172
                cv[1].destination = &(s->execute_x_only);
170
173
 
171
174
                p->config_storage[i] = s;
172
175
 
580
583
#if 0
581
584
                                log_error_write(srv, __FILE__, __LINE__, "sd", "(debug) cgi exited fine, pid:", pid);
582
585
#endif
583
 
                                pid = 0;
584
 
 
585
586
                                return HANDLER_GO_ON;
586
587
                        } else {
587
588
                                log_error_write(srv, __FILE__, __LINE__, "sd", "cgi died, pid:", pid);
588
 
                                pid = 0;
589
589
                                return HANDLER_GO_ON;
590
590
                        }
591
591
                }
1005
1005
                        args[i++] = cgi_handler->ptr;
1006
1006
                }
1007
1007
                args[i++] = con->physical.path->ptr;
1008
 
                args[i++] = NULL;
 
1008
                args[i  ] = NULL;
1009
1009
 
1010
1010
                /* search for the last / */
1011
1011
                if (NULL != (c = strrchr(con->physical.path->ptr, '/'))) {
1018
1018
                        *c = '/';
1019
1019
                }
1020
1020
 
1021
 
                openDevNull(STDERR_FILENO);
1022
 
 
1023
1021
                /* we don't need the client socket */
1024
1022
                for (i = 3; i < 256; i++) {
1025
1023
                        if (i != srv->errorlog_fd) close(i);
1198
1196
 
1199
1197
                        if (buffer_is_equal_string(du->key, CONST_STR_LEN("cgi.assign"))) {
1200
1198
                                PATCH(cgi);
 
1199
                        } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("cgi.execute-x-only"))) {
 
1200
                                PATCH(execute_x_only);
1201
1201
                        }
1202
1202
                }
1203
1203
        }
1220
1220
 
1221
1221
        if (HANDLER_ERROR == stat_cache_get_entry(srv, con, con->physical.path, &sce)) return HANDLER_GO_ON;
1222
1222
        if (!S_ISREG(sce->st.st_mode)) return HANDLER_GO_ON;
 
1223
        if (p->conf.execute_x_only == 1 && (sce->st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) == 0) return HANDLER_GO_ON;
1223
1224
 
1224
1225
        s_len = fn->used - 1;
1225
1226