Mercurial > hg > nginx-quic
annotate src/http/ngx_http_postpone_filter_module.c @ 4487:a786c85e8268
Disable symlinks: don't allow creating or truncating a file via a symlink in
the last path component if "if_not_owner" parameter is used.
To prevent race condition we have to open a file before checking its owner and
there's no way to change access flags for already opened file descriptor, so
we disable symlinks for the last path component at all if flags allow creating
or truncating the file.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Tue, 21 Feb 2012 15:04:41 +0000 |
parents | d620f497c50f |
children | 586969d972b9 |
rev | line source |
---|---|
509 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4412 | 4 * Copyright (C) Nginx, Inc. |
509 | 5 */ |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 #include <ngx_http.h> | |
11 | |
12 | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
13 static ngx_int_t ngx_http_postpone_filter_add(ngx_http_request_t *r, |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
14 ngx_chain_t *in); |
681 | 15 static ngx_int_t ngx_http_postpone_filter_init(ngx_conf_t *cf); |
509 | 16 |
17 | |
18 static ngx_http_module_t ngx_http_postpone_filter_module_ctx = { | |
19 NULL, /* preconfiguration */ | |
681 | 20 ngx_http_postpone_filter_init, /* postconfiguration */ |
509 | 21 |
22 NULL, /* create main configuration */ | |
23 NULL, /* init main configuration */ | |
24 | |
25 NULL, /* create server configuration */ | |
26 NULL, /* merge server configuration */ | |
27 | |
28 NULL, /* create location configuration */ | |
29 NULL /* merge location configuration */ | |
30 }; | |
31 | |
32 | |
33 ngx_module_t ngx_http_postpone_filter_module = { | |
34 NGX_MODULE_V1, | |
35 &ngx_http_postpone_filter_module_ctx, /* module context */ | |
36 NULL, /* module directives */ | |
37 NGX_HTTP_MODULE, /* module type */ | |
541 | 38 NULL, /* init master */ |
681 | 39 NULL, /* init module */ |
541 | 40 NULL, /* init process */ |
41 NULL, /* init thread */ | |
42 NULL, /* exit thread */ | |
43 NULL, /* exit process */ | |
44 NULL, /* exit master */ | |
45 NGX_MODULE_V1_PADDING | |
509 | 46 }; |
47 | |
48 | |
49 static ngx_http_output_body_filter_pt ngx_http_next_filter; | |
50 | |
51 | |
52 static ngx_int_t | |
53 ngx_http_postpone_filter(ngx_http_request_t *r, ngx_chain_t *in) | |
54 { | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
55 ngx_connection_t *c; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
56 ngx_http_postponed_request_t *pr; |
509 | 57 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
58 c = r->connection; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
59 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
60 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0, |
583 | 61 "http postpone filter \"%V?%V\" %p", &r->uri, &r->args, in); |
527 | 62 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
63 if (r != c->data) { |
509 | 64 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
65 if (in) { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
66 ngx_http_postpone_filter_add(r, in); |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
67 return NGX_OK; |
509 | 68 } |
69 | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
70 #if 0 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
71 /* TODO: SSI may pass NULL */ |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
72 ngx_log_error(NGX_LOG_ALERT, c->log, 0, |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
73 "http postpone filter NULL inactive request", |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
74 &r->uri, &r->args); |
641 | 75 #endif |
76 | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
77 return NGX_OK; |
583 | 78 } |
79 | |
80 if (r->postponed == NULL) { | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
81 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
82 if (in || c->buffered) { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
83 return ngx_http_next_filter(r->main, in); |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
84 } |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
85 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
86 return NGX_OK; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
87 } |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
88 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
89 if (in) { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
90 ngx_http_postpone_filter_add(r, in); |
583 | 91 } |
92 | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
93 do { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
94 pr = r->postponed; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
95 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
96 if (pr->request) { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
97 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
98 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
99 "http postpone filter wake \"%V?%V\"", |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
100 &pr->request->uri, &pr->request->args); |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
101 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
102 r->postponed = pr->next; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
103 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
104 c->data = pr->request; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
105 |
3064 | 106 return ngx_http_post_request(pr->request, NULL); |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
107 } |
583 | 108 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
109 if (pr->out == NULL) { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
110 ngx_log_error(NGX_LOG_ALERT, c->log, 0, |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
111 "http postpone filter NULL output", |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
112 &r->uri, &r->args); |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
113 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
114 } else { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
115 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
116 "http postpone filter output \"%V?%V\"", |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
117 &r->uri, &r->args); |
509 | 118 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
119 if (ngx_http_next_filter(r->main, pr->out) == NGX_ERROR) { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
120 return NGX_ERROR; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
121 } |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
122 } |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
123 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
124 r->postponed = pr->next; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
125 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
126 } while (r->postponed); |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
127 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
128 return NGX_OK; |
509 | 129 } |
130 | |
131 | |
132 static ngx_int_t | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
133 ngx_http_postpone_filter_add(ngx_http_request_t *r, ngx_chain_t *in) |
583 | 134 { |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
135 ngx_http_postponed_request_t *pr, **ppr; |
583 | 136 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
137 if (r->postponed) { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
138 for (pr = r->postponed; pr->next; pr = pr->next) { /* void */ } |
583 | 139 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
140 if (pr->request == NULL) { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
141 goto found; |
583 | 142 } |
143 | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
144 ppr = &pr->next; |
583 | 145 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
146 } else { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
147 ppr = &r->postponed; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
148 } |
595 | 149 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
150 pr = ngx_palloc(r->pool, sizeof(ngx_http_postponed_request_t)); |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
151 if (pr == NULL) { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
152 return NGX_ERROR; |
583 | 153 } |
2066
2bb4441a8c28
fix bug when inactive subrequest is truncated,
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
154 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
155 *ppr = pr; |
2066
2bb4441a8c28
fix bug when inactive subrequest is truncated,
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
156 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
157 pr->request = NULL; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
158 pr->out = NULL; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
159 pr->next = NULL; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
160 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
161 found: |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
162 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
163 if (ngx_chain_add_copy(r->pool, &pr->out, in) == NGX_OK) { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
164 return NGX_OK; |
2066
2bb4441a8c28
fix bug when inactive subrequest is truncated,
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
165 } |
2bb4441a8c28
fix bug when inactive subrequest is truncated,
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
166 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2295
diff
changeset
|
167 return NGX_ERROR; |
583 | 168 } |
169 | |
170 | |
171 static ngx_int_t | |
681 | 172 ngx_http_postpone_filter_init(ngx_conf_t *cf) |
509 | 173 { |
174 ngx_http_next_filter = ngx_http_top_body_filter; | |
175 ngx_http_top_body_filter = ngx_http_postpone_filter; | |
176 | |
177 return NGX_OK; | |
178 } |