Mercurial > hg > nginx-quic
annotate src/os/win32/ngx_files.c @ 7186:6d2e92acb013
Contrib: vim syntax, update core module directives.
Removed non-existent directives and directive redefinitions.
author | Gena Makhomed <gmm@csdoc.com> |
---|---|
date | Thu, 28 Dec 2017 12:01:05 +0200 |
parents | 577628e6b6a6 |
children | 061ec464813f |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
6 |
42
cd035a94e0b6
nginx-0.0.1-2002-12-27-10:27:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
7 |
cd035a94e0b6
nginx-0.0.1-2002-12-27-10:27:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
8 #include <ngx_config.h> |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
42
diff
changeset
|
9 #include <ngx_core.h> |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
12 #define NGX_UTF16_BUFLEN 256 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
13 |
4673
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
14 static ngx_int_t ngx_win32_check_filename(u_char *name, u_short *u, |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
15 size_t len); |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
16 static u_short *ngx_utf8_to_utf16(u_short *utf16, u_char *utf8, size_t *len); |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
17 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
18 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
19 /* FILE_FLAG_BACKUP_SEMANTICS allows to obtain a handle to a directory */ |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
20 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
21 ngx_fd_t |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
22 ngx_open_file(u_char *name, u_long mode, u_long create, u_long access) |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
23 { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
24 size_t len; |
4673
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
25 u_short *u; |
3137
179f6dfcb7fe
preserve errno while ngx_free()
Igor Sysoev <igor@sysoev.ru>
parents:
2974
diff
changeset
|
26 ngx_fd_t fd; |
179f6dfcb7fe
preserve errno while ngx_free()
Igor Sysoev <igor@sysoev.ru>
parents:
2974
diff
changeset
|
27 ngx_err_t err; |
179f6dfcb7fe
preserve errno while ngx_free()
Igor Sysoev <igor@sysoev.ru>
parents:
2974
diff
changeset
|
28 u_short utf16[NGX_UTF16_BUFLEN]; |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
29 |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
30 len = NGX_UTF16_BUFLEN; |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
31 u = ngx_utf8_to_utf16(utf16, name, &len); |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
32 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
33 if (u == NULL) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
34 return INVALID_HANDLE_VALUE; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
35 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
36 |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
37 fd = INVALID_HANDLE_VALUE; |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
38 |
4673
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
39 if (create == NGX_FILE_OPEN |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
40 && ngx_win32_check_filename(name, u, len) != NGX_OK) |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
41 { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
42 goto failed; |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
43 } |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
44 |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
45 fd = CreateFileW(u, mode, |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
46 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
47 NULL, create, FILE_FLAG_BACKUP_SEMANTICS, NULL); |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
48 |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
49 failed: |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
50 |
4673
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
51 if (u != utf16) { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
52 err = ngx_errno; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
53 ngx_free(u); |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
54 ngx_set_errno(err); |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
55 } |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
56 |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
57 return fd; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
58 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
59 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
60 |
561 | 61 ssize_t |
62 ngx_read_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset) | |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
63 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
280
diff
changeset
|
64 u_long n; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
65 ngx_err_t err; |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
66 OVERLAPPED ovlp, *povlp; |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
67 |
3156 | 68 ovlp.Internal = 0; |
69 ovlp.InternalHigh = 0; | |
70 ovlp.Offset = (u_long) offset; | |
71 ovlp.OffsetHigh = (u_long) (offset >> 32); | |
72 ovlp.hEvent = NULL; | |
461 | 73 |
3156 | 74 povlp = &ovlp; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
75 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
76 if (ReadFile(file->fd, buf, size, &n, povlp) == 0) { |
2974
63f71723cd2a
handle Win32 ReadFile() EOF state in Unix way
Igor Sysoev <igor@sysoev.ru>
parents:
2901
diff
changeset
|
77 err = ngx_errno; |
63f71723cd2a
handle Win32 ReadFile() EOF state in Unix way
Igor Sysoev <igor@sysoev.ru>
parents:
2901
diff
changeset
|
78 |
63f71723cd2a
handle Win32 ReadFile() EOF state in Unix way
Igor Sysoev <igor@sysoev.ru>
parents:
2901
diff
changeset
|
79 if (err == ERROR_HANDLE_EOF) { |
63f71723cd2a
handle Win32 ReadFile() EOF state in Unix way
Igor Sysoev <igor@sysoev.ru>
parents:
2901
diff
changeset
|
80 return 0; |
63f71723cd2a
handle Win32 ReadFile() EOF state in Unix way
Igor Sysoev <igor@sysoev.ru>
parents:
2901
diff
changeset
|
81 } |
63f71723cd2a
handle Win32 ReadFile() EOF state in Unix way
Igor Sysoev <igor@sysoev.ru>
parents:
2901
diff
changeset
|
82 |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
3156
diff
changeset
|
83 ngx_log_error(NGX_LOG_ERR, file->log, err, |
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
3156
diff
changeset
|
84 "ReadFile() \"%s\" failed", file->name.data); |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
85 return NGX_ERROR; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
86 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
87 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
88 file->offset += n; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
89 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
90 return n; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
91 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
92 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
93 |
561 | 94 ssize_t |
95 ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset) | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
96 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
280
diff
changeset
|
97 u_long n; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
98 OVERLAPPED ovlp, *povlp; |
183
4c698194c56d
nginx-0.0.1-2003-11-13-19:16:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
99 |
3156 | 100 ovlp.Internal = 0; |
101 ovlp.InternalHigh = 0; | |
102 ovlp.Offset = (u_long) offset; | |
103 ovlp.OffsetHigh = (u_long) (offset >> 32); | |
104 ovlp.hEvent = NULL; | |
183
4c698194c56d
nginx-0.0.1-2003-11-13-19:16:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
105 |
3156 | 106 povlp = &ovlp; |
183
4c698194c56d
nginx-0.0.1-2003-11-13-19:16:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
107 |
4c698194c56d
nginx-0.0.1-2003-11-13-19:16:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
108 if (WriteFile(file->fd, buf, size, &n, povlp) == 0) { |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
3156
diff
changeset
|
109 ngx_log_error(NGX_LOG_ERR, file->log, ngx_errno, |
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
3156
diff
changeset
|
110 "WriteFile() \"%s\" failed", file->name.data); |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
111 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
112 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
113 |
3158 | 114 if (n != size) { |
115 ngx_log_error(NGX_LOG_CRIT, file->log, 0, | |
116 "WriteFile() \"%s\" has written only %ul of %uz", | |
117 file->name.data, n, size); | |
118 return NGX_ERROR; | |
119 } | |
120 | |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
121 file->offset += n; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
122 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
123 return n; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
124 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
125 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
126 |
561 | 127 ssize_t |
128 ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset, | |
129 ngx_pool_t *pool) | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
130 { |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
131 u_char *buf, *prev; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
132 size_t size; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
133 ssize_t total, n; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
134 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
135 total = 0; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
136 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
137 while (cl) { |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
138 buf = cl->buf->pos; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
139 prev = buf; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
140 size = 0; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
141 |
344
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
343
diff
changeset
|
142 /* coalesce the neighbouring bufs */ |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
143 |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
144 while (cl && prev == cl->buf->pos) { |
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
145 size += cl->buf->last - cl->buf->pos; |
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
146 prev = cl->buf->last; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
147 cl = cl->next; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
148 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
149 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
150 n = ngx_write_file(file, buf, size, offset); |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
151 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
152 if (n == NGX_ERROR) { |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
153 return NGX_ERROR; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
154 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
155 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
156 total += n; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
157 offset += n; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
158 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
159 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
160 return total; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
161 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
162 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
163 |
1634
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
164 ssize_t |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
165 ngx_read_fd(ngx_fd_t fd, void *buf, size_t size) |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
166 { |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
167 u_long n; |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
168 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
169 if (ReadFile(fd, buf, size, &n, NULL) != 0) { |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
170 return (size_t) n; |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
171 } |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
172 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
173 return -1; |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
174 } |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
175 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
176 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
177 ssize_t |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
178 ngx_write_fd(ngx_fd_t fd, void *buf, size_t size) |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
179 { |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
180 u_long n; |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
181 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
182 if (WriteFile(fd, buf, size, &n, NULL) != 0) { |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
183 return (size_t) n; |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
184 } |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
185 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
186 return -1; |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
187 } |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
188 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
189 |
2769
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
190 ssize_t |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
191 ngx_write_console(ngx_fd_t fd, void *buf, size_t size) |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
192 { |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
193 u_long n; |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
194 |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
195 (void) CharToOemBuff(buf, buf, size); |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
196 |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
197 if (WriteFile(fd, buf, size, &n, NULL) != 0) { |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
198 return (size_t) n; |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
199 } |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
200 |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
201 return -1; |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
202 } |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
203 |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
204 |
3382
6be1f25bae90
fix Win32 error messages when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
205 ngx_err_t |
1693
f4eb04fd8579
use malloc() in ngx_win32_rename_file, set crit level instead of error
Igor Sysoev <igor@sysoev.ru>
parents:
1634
diff
changeset
|
206 ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_log_t *log) |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
207 { |
499 | 208 u_char *name; |
3382
6be1f25bae90
fix Win32 error messages when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
209 ngx_err_t err; |
499 | 210 ngx_uint_t collision; |
211 ngx_atomic_uint_t num; | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
212 |
4017
4f4086cf1a07
Fix buffer overrun under Windows.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3651
diff
changeset
|
213 name = ngx_alloc(to->len + 1 + NGX_ATOMIC_T_LEN + 1 + sizeof("DELETE"), |
4f4086cf1a07
Fix buffer overrun under Windows.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3651
diff
changeset
|
214 log); |
501 | 215 if (name == NULL) { |
3382
6be1f25bae90
fix Win32 error messages when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
216 return NGX_ENOMEM; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
217 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
218 |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
219 ngx_memcpy(name, to->data, to->len); |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
220 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
221 collision = 0; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
222 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
223 /* mutex_lock() (per cache or single ?) */ |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
224 |
499 | 225 for ( ;; ) { |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
226 num = ngx_next_temp_number(collision); |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
227 |
2900
812445a822e3
add trailing zero to a file name
Igor Sysoev <igor@sysoev.ru>
parents:
2782
diff
changeset
|
228 ngx_sprintf(name + to->len, ".%0muA.DELETE%Z", num); |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
229 |
499 | 230 if (MoveFile((const char *) to->data, (const char *) name) != 0) { |
231 break; | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
232 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
233 |
499 | 234 collision = 1; |
235 | |
2901
17da2da3a8f5
fix logging in ngx_win32_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2900
diff
changeset
|
236 ngx_log_error(NGX_LOG_CRIT, log, ngx_errno, |
17da2da3a8f5
fix logging in ngx_win32_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2900
diff
changeset
|
237 "MoveFile() \"%s\" to \"%s\" failed", to->data, name); |
499 | 238 } |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
239 |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
240 if (MoveFile((const char *) from->data, (const char *) to->data) == 0) { |
3382
6be1f25bae90
fix Win32 error messages when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
241 err = ngx_errno; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
242 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
243 } else { |
3382
6be1f25bae90
fix Win32 error messages when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
244 err = 0; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
245 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
246 |
1051 | 247 if (DeleteFile((const char *) name) == 0) { |
2901
17da2da3a8f5
fix logging in ngx_win32_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2900
diff
changeset
|
248 ngx_log_error(NGX_LOG_CRIT, log, ngx_errno, |
17da2da3a8f5
fix logging in ngx_win32_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2900
diff
changeset
|
249 "DeleteFile() \"%s\" failed", name); |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
250 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
251 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
252 /* mutex_unlock() */ |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
253 |
1693
f4eb04fd8579
use malloc() in ngx_win32_rename_file, set crit level instead of error
Igor Sysoev <igor@sysoev.ru>
parents:
1634
diff
changeset
|
254 ngx_free(name); |
f4eb04fd8579
use malloc() in ngx_win32_rename_file, set crit level instead of error
Igor Sysoev <igor@sysoev.ru>
parents:
1634
diff
changeset
|
255 |
3382
6be1f25bae90
fix Win32 error messages when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
256 return err; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
257 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
258 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
259 |
561 | 260 ngx_int_t |
2462
90d5ddfedbb1
use GetFileAttributesEx() instead of GetFileAttributes()
Igor Sysoev <igor@sysoev.ru>
parents:
2459
diff
changeset
|
261 ngx_file_info(u_char *file, ngx_file_info_t *sb) |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
262 { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
263 size_t len; |
3138
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
264 long rc; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
265 u_short *u; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
266 ngx_err_t err; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
267 WIN32_FILE_ATTRIBUTE_DATA fa; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
268 u_short utf16[NGX_UTF16_BUFLEN]; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
269 |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
270 len = NGX_UTF16_BUFLEN; |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
271 |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
272 u = ngx_utf8_to_utf16(utf16, file, &len); |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
273 |
3138
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
274 if (u == NULL) { |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
275 return NGX_FILE_ERROR; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
276 } |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
277 |
4673
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
278 rc = NGX_FILE_ERROR; |
3138
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
279 |
4673
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
280 if (ngx_win32_check_filename(file, u, len) != NGX_OK) { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
281 goto failed; |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
282 } |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
283 |
4673
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
284 rc = GetFileAttributesExW(u, GetFileExInfoStandard, &fa); |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
285 |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
286 sb->dwFileAttributes = fa.dwFileAttributes; |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
287 sb->ftCreationTime = fa.ftCreationTime; |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
288 sb->ftLastAccessTime = fa.ftLastAccessTime; |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
289 sb->ftLastWriteTime = fa.ftLastWriteTime; |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
290 sb->nFileSizeHigh = fa.nFileSizeHigh; |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
291 sb->nFileSizeLow = fa.nFileSizeLow; |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
292 |
4673
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
293 failed: |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
294 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
295 if (u != utf16) { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
296 err = ngx_errno; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
297 ngx_free(u); |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
298 ngx_set_errno(err); |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
299 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
300 |
3138
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
301 return rc; |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
302 } |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
303 |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
304 |
561 | 305 ngx_int_t |
681 | 306 ngx_set_file_time(u_char *name, ngx_fd_t fd, time_t s) |
307 { | |
308 uint64_t intervals; | |
309 FILETIME ft; | |
310 | |
311 /* 116444736000000000 is commented in src/os/win32/ngx_time.c */ | |
312 | |
313 intervals = s * 10000000 + 116444736000000000; | |
314 | |
315 ft.dwLowDateTime = (DWORD) intervals; | |
316 ft.dwHighDateTime = (DWORD) (intervals >> 32); | |
317 | |
318 if (SetFileTime(fd, NULL, NULL, &ft) != 0) { | |
319 return NGX_OK; | |
320 } | |
321 | |
322 return NGX_ERROR; | |
323 } | |
324 | |
325 | |
3651 | 326 ngx_int_t |
327 ngx_create_file_mapping(ngx_file_mapping_t *fm) | |
328 { | |
329 LARGE_INTEGER size; | |
330 | |
331 fm->fd = ngx_open_file(fm->name, NGX_FILE_RDWR, NGX_FILE_TRUNCATE, | |
332 NGX_FILE_DEFAULT_ACCESS); | |
7086 | 333 |
3651 | 334 if (fm->fd == NGX_INVALID_FILE) { |
335 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
336 ngx_open_file_n " \"%s\" failed", fm->name); | |
337 return NGX_ERROR; | |
338 } | |
339 | |
340 fm->handle = NULL; | |
341 | |
342 size.QuadPart = fm->size; | |
343 | |
344 if (SetFilePointerEx(fm->fd, size, NULL, FILE_BEGIN) == 0) { | |
345 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
346 "SetFilePointerEx(\"%s\", %uz) failed", | |
347 fm->name, fm->size); | |
348 goto failed; | |
349 } | |
350 | |
351 if (SetEndOfFile(fm->fd) == 0) { | |
352 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
353 "SetEndOfFile() \"%s\" failed", fm->name); | |
354 goto failed; | |
355 } | |
356 | |
357 fm->handle = CreateFileMapping(fm->fd, NULL, PAGE_READWRITE, | |
358 (u_long) ((off_t) fm->size >> 32), | |
359 (u_long) ((off_t) fm->size & 0xffffffff), | |
360 NULL); | |
361 if (fm->handle == NULL) { | |
362 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
363 "CreateFileMapping(%s, %uz) failed", | |
364 fm->name, fm->size); | |
365 goto failed; | |
366 } | |
367 | |
368 fm->addr = MapViewOfFile(fm->handle, FILE_MAP_WRITE, 0, 0, 0); | |
369 | |
370 if (fm->addr != NULL) { | |
371 return NGX_OK; | |
372 } | |
373 | |
374 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
375 "MapViewOfFile(%uz) of file mapping \"%s\" failed", | |
376 fm->size, fm->name); | |
377 | |
378 failed: | |
379 | |
380 if (fm->handle) { | |
381 if (CloseHandle(fm->handle) == 0) { | |
382 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
383 "CloseHandle() of file mapping \"%s\" failed", | |
384 fm->name); | |
385 } | |
386 } | |
387 | |
388 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) { | |
389 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
390 ngx_close_file_n " \"%s\" failed", fm->name); | |
391 } | |
392 | |
393 return NGX_ERROR; | |
394 } | |
395 | |
396 | |
397 void | |
398 ngx_close_file_mapping(ngx_file_mapping_t *fm) | |
399 { | |
400 if (UnmapViewOfFile(fm->addr) == 0) { | |
401 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
402 "UnmapViewOfFile(%p) of file mapping \"%s\" failed", | |
403 fm->addr, &fm->name); | |
404 } | |
405 | |
406 if (CloseHandle(fm->handle) == 0) { | |
407 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
408 "CloseHandle() of file mapping \"%s\" failed", | |
409 &fm->name); | |
410 } | |
411 | |
412 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) { | |
413 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
414 ngx_close_file_n " \"%s\" failed", fm->name); | |
415 } | |
416 } | |
417 | |
418 | |
4564
13eb3193cd63
Fixed win32 build after realpath changes in r4559.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
419 u_char * |
2259 | 420 ngx_realpath(u_char *path, u_char *resolved) |
421 { | |
422 /* STUB */ | |
4564
13eb3193cd63
Fixed win32 build after realpath changes in r4559.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
423 return path; |
2259 | 424 } |
425 | |
426 | |
561 | 427 ngx_int_t |
428 ngx_open_dir(ngx_str_t *name, ngx_dir_t *dir) | |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
429 { |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
430 ngx_cpystrn(name->data + name->len, NGX_DIR_MASK, NGX_DIR_MASK_LEN + 1); |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
431 |
727 | 432 dir->dir = FindFirstFile((const char *) name->data, &dir->finddata); |
577 | 433 |
5749
a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5501
diff
changeset
|
434 name->data[name->len] = '\0'; |
a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5501
diff
changeset
|
435 |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
436 if (dir->dir == INVALID_HANDLE_VALUE) { |
577 | 437 return NGX_ERROR; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
438 } |
577 | 439 |
457 | 440 dir->valid_info = 1; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
441 dir->ready = 1; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
442 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
443 return NGX_OK; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
444 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
445 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
446 |
561 | 447 ngx_int_t |
448 ngx_read_dir(ngx_dir_t *dir) | |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
449 { |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
450 if (dir->ready) { |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
451 dir->ready = 0; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
452 return NGX_OK; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
453 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
454 |
727 | 455 if (FindNextFile(dir->dir, &dir->finddata) != 0) { |
3200
26784c34e8be
*) reset cached dirent.d_type after stat()
Igor Sysoev <igor@sysoev.ru>
parents:
3178
diff
changeset
|
456 dir->type = 1; |
681 | 457 return NGX_OK; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
458 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
459 |
681 | 460 return NGX_ERROR; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
461 } |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
462 |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
463 |
501 | 464 ngx_int_t |
5749
a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5501
diff
changeset
|
465 ngx_close_dir(ngx_dir_t *dir) |
a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5501
diff
changeset
|
466 { |
a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5501
diff
changeset
|
467 if (FindClose(dir->dir) == 0) { |
a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5501
diff
changeset
|
468 return NGX_ERROR; |
a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5501
diff
changeset
|
469 } |
a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5501
diff
changeset
|
470 |
a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5501
diff
changeset
|
471 return NGX_OK; |
a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5501
diff
changeset
|
472 } |
a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5501
diff
changeset
|
473 |
a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5501
diff
changeset
|
474 |
a680bf4dddd5
Win32: ngx_open_dir() and ngx_close_dir() fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5501
diff
changeset
|
475 ngx_int_t |
727 | 476 ngx_open_glob(ngx_glob_t *gl) |
477 { | |
2459 | 478 u_char *p; |
479 size_t len; | |
480 ngx_err_t err; | |
1632 | 481 |
727 | 482 gl->dir = FindFirstFile((const char *) gl->pattern, &gl->finddata); |
483 | |
484 if (gl->dir == INVALID_HANDLE_VALUE) { | |
1980 | 485 |
2459 | 486 err = ngx_errno; |
487 | |
488 if ((err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND) | |
489 && gl->test) | |
490 { | |
1980 | 491 gl->no_match = 1; |
492 return NGX_OK; | |
493 } | |
494 | |
727 | 495 return NGX_ERROR; |
496 } | |
497 | |
1632 | 498 for (p = gl->pattern; *p; p++) { |
499 if (*p == '/') { | |
500 gl->last = p + 1 - gl->pattern; | |
501 } | |
502 } | |
503 | |
504 len = ngx_strlen(gl->finddata.cFileName); | |
505 gl->name.len = gl->last + len; | |
506 | |
507 gl->name.data = ngx_alloc(gl->name.len + 1, gl->log); | |
508 if (gl->name.data == NULL) { | |
509 return NGX_ERROR; | |
510 } | |
511 | |
512 ngx_memcpy(gl->name.data, gl->pattern, gl->last); | |
513 ngx_cpystrn(gl->name.data + gl->last, (u_char *) gl->finddata.cFileName, | |
514 len + 1); | |
515 | |
727 | 516 gl->ready = 1; |
517 | |
518 return NGX_OK; | |
519 } | |
520 | |
521 | |
522 ngx_int_t | |
523 ngx_read_glob(ngx_glob_t *gl, ngx_str_t *name) | |
524 { | |
1632 | 525 size_t len; |
727 | 526 ngx_err_t err; |
527 | |
1980 | 528 if (gl->no_match) { |
529 return NGX_DONE; | |
530 } | |
531 | |
727 | 532 if (gl->ready) { |
1632 | 533 *name = gl->name; |
727 | 534 |
535 gl->ready = 0; | |
536 return NGX_OK; | |
537 } | |
538 | |
1632 | 539 ngx_free(gl->name.data); |
540 gl->name.data = NULL; | |
541 | |
727 | 542 if (FindNextFile(gl->dir, &gl->finddata) != 0) { |
1632 | 543 |
544 len = ngx_strlen(gl->finddata.cFileName); | |
545 gl->name.len = gl->last + len; | |
546 | |
547 gl->name.data = ngx_alloc(gl->name.len + 1, gl->log); | |
548 if (gl->name.data == NULL) { | |
549 return NGX_ERROR; | |
550 } | |
551 | |
552 ngx_memcpy(gl->name.data, gl->pattern, gl->last); | |
553 ngx_cpystrn(gl->name.data + gl->last, (u_char *) gl->finddata.cFileName, | |
554 len + 1); | |
555 | |
556 *name = gl->name; | |
727 | 557 |
558 return NGX_OK; | |
559 } | |
560 | |
561 err = ngx_errno; | |
562 | |
563 if (err == NGX_ENOMOREFILES) { | |
564 return NGX_DONE; | |
565 } | |
566 | |
567 ngx_log_error(NGX_LOG_ALERT, gl->log, err, | |
568 "FindNextFile(%s) failed", gl->pattern); | |
569 | |
570 return NGX_ERROR; | |
571 } | |
572 | |
573 | |
574 void | |
575 ngx_close_glob(ngx_glob_t *gl) | |
576 { | |
1632 | 577 if (gl->name.data) { |
578 ngx_free(gl->name.data); | |
579 } | |
580 | |
1980 | 581 if (gl->dir == INVALID_HANDLE_VALUE) { |
582 return; | |
583 } | |
584 | |
1632 | 585 if (FindClose(gl->dir) == 0) { |
727 | 586 ngx_log_error(NGX_LOG_ALERT, gl->log, ngx_errno, |
587 "FindClose(%s) failed", gl->pattern); | |
588 } | |
589 } | |
590 | |
591 | |
592 ngx_int_t | |
501 | 593 ngx_de_info(u_char *name, ngx_dir_t *dir) |
594 { | |
595 return NGX_OK; | |
596 } | |
597 | |
598 | |
599 ngx_int_t | |
600 ngx_de_link_info(u_char *name, ngx_dir_t *dir) | |
601 { | |
602 return NGX_OK; | |
603 } | |
604 | |
605 | |
561 | 606 ngx_int_t |
3178 | 607 ngx_read_ahead(ngx_fd_t fd, size_t n) |
608 { | |
609 return ~NGX_FILE_ERROR; | |
610 } | |
611 | |
612 | |
613 ngx_int_t | |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
614 ngx_directio_on(ngx_fd_t fd) |
2134
13652cba8633
fix building by bcc broken in r2130
Igor Sysoev <igor@sysoev.ru>
parents:
1980
diff
changeset
|
615 { |
3164
b1b1775698d5
uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents:
3158
diff
changeset
|
616 return ~NGX_FILE_ERROR; |
2134
13652cba8633
fix building by bcc broken in r2130
Igor Sysoev <igor@sysoev.ru>
parents:
1980
diff
changeset
|
617 } |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
618 |
2615 | 619 |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
620 ngx_int_t |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
621 ngx_directio_off(ngx_fd_t fd) |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
622 { |
3164
b1b1775698d5
uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents:
3158
diff
changeset
|
623 return ~NGX_FILE_ERROR; |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
624 } |
2615 | 625 |
626 | |
627 size_t | |
628 ngx_fs_bsize(u_char *name) | |
629 { | |
630 u_char root[4]; | |
631 u_long sc, bs, nfree, ncl; | |
632 | |
633 if (name[2] == ':') { | |
634 ngx_cpystrn(root, name, 4); | |
635 name = root; | |
636 } | |
637 | |
638 if (GetDiskFreeSpace((const char *) name, &sc, &bs, &nfree, &ncl) == 0) { | |
639 return 512; | |
640 } | |
641 | |
642 return sc * bs; | |
643 } | |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
644 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
645 |
4673
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
646 static ngx_int_t |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
647 ngx_win32_check_filename(u_char *name, u_short *u, size_t len) |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
648 { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
649 u_char *p, ch; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
650 u_long n; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
651 u_short *lu; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
652 ngx_err_t err; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
653 enum { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
654 sw_start = 0, |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
655 sw_normal, |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
656 sw_after_slash, |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
657 sw_after_colon, |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
658 sw_after_dot |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
659 } state; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
660 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
661 /* check for NTFS streams (":"), trailing dots and spaces */ |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
662 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
663 lu = NULL; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
664 state = sw_start; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
665 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
666 for (p = name; *p; p++) { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
667 ch = *p; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
668 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
669 switch (state) { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
670 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
671 case sw_start: |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
672 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
673 /* |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
674 * skip till first "/" to allow paths starting with drive and |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
675 * relative path, like "c:html/" |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
676 */ |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
677 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
678 if (ch == '/' || ch == '\\') { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
679 state = sw_after_slash; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
680 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
681 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
682 break; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
683 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
684 case sw_normal: |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
685 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
686 if (ch == ':') { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
687 state = sw_after_colon; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
688 break; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
689 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
690 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
691 if (ch == '.' || ch == ' ') { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
692 state = sw_after_dot; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
693 break; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
694 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
695 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
696 if (ch == '/' || ch == '\\') { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
697 state = sw_after_slash; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
698 break; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
699 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
700 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
701 break; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
702 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
703 case sw_after_slash: |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
704 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
705 if (ch == '/' || ch == '\\') { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
706 break; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
707 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
708 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
709 if (ch == '.') { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
710 break; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
711 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
712 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
713 if (ch == ':') { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
714 state = sw_after_colon; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
715 break; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
716 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
717 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
718 state = sw_normal; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
719 break; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
720 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
721 case sw_after_colon: |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
722 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
723 if (ch == '/' || ch == '\\') { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
724 state = sw_after_slash; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
725 break; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
726 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
727 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
728 goto invalid; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
729 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
730 case sw_after_dot: |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
731 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
732 if (ch == '/' || ch == '\\') { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
733 goto invalid; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
734 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
735 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
736 if (ch == ':') { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
737 goto invalid; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
738 } |
4703 | 739 |
4673
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
740 if (ch == '.' || ch == ' ') { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
741 break; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
742 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
743 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
744 state = sw_normal; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
745 break; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
746 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
747 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
748 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
749 if (state == sw_after_dot) { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
750 goto invalid; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
751 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
752 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
753 /* check if long name match */ |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
754 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
755 lu = malloc(len * 2); |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
756 if (lu == NULL) { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
757 return NGX_ERROR; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
758 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
759 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
760 n = GetLongPathNameW(u, lu, len); |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
761 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
762 if (n == 0) { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
763 goto failed; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
764 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
765 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
766 if (n != len - 1 || _wcsicmp(u, lu) != 0) { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
767 goto invalid; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
768 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
769 |
5437
dea321e5c021
Win32: plugged memory leak.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4703
diff
changeset
|
770 ngx_free(lu); |
dea321e5c021
Win32: plugged memory leak.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4703
diff
changeset
|
771 |
4673
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
772 return NGX_OK; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
773 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
774 invalid: |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
775 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
776 ngx_set_errno(NGX_ENOENT); |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
777 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
778 failed: |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
779 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
780 if (lu) { |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
781 err = ngx_errno; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
782 ngx_free(lu); |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
783 ngx_set_errno(err); |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
784 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
785 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
786 return NGX_ERROR; |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
787 } |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
788 |
dc6c658942a8
Win32: disallowed access to various non-canonical name variants.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
789 |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
790 static u_short * |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
791 ngx_utf8_to_utf16(u_short *utf16, u_char *utf8, size_t *len) |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
792 { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
793 u_char *p; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
794 u_short *u, *last; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
795 uint32_t n; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
796 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
797 p = utf8; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
798 u = utf16; |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
799 last = utf16 + *len; |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
800 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
801 while (u < last) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
802 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
803 if (*p < 0x80) { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
804 *u++ = (u_short) *p; |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
805 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
806 if (*p == 0) { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
807 *len = u - utf16; |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
808 return utf16; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
809 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
810 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
811 p++; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
812 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
813 continue; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
814 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
815 |
5501
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
816 if (u + 1 == last) { |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
817 *len = u - utf16; |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
818 break; |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
819 } |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
820 |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
821 n = ngx_utf8_decode(&p, 4); |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
822 |
5501
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
823 if (n > 0x10ffff) { |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
824 ngx_set_errno(NGX_EILSEQ); |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
825 return NULL; |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
826 } |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
827 |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
828 if (n > 0xffff) { |
5501
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
829 n -= 0x10000; |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
830 *u++ = (u_short) (0xd800 + (n >> 10)); |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
831 *u++ = (u_short) (0xdc00 + (n & 0x03ff)); |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
832 continue; |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
833 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
834 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
835 *u++ = (u_short) n; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
836 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
837 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
838 /* the given buffer is not enough, allocate a new one */ |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
839 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
840 u = malloc(((p - utf8) + ngx_strlen(p) + 1) * sizeof(u_short)); |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
841 if (u == NULL) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
842 return NULL; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
843 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
844 |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
845 ngx_memcpy(u, utf16, *len * 2); |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
846 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
847 utf16 = u; |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
848 u += *len; |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
849 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
850 for ( ;; ) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
851 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
852 if (*p < 0x80) { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
853 *u++ = (u_short) *p; |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
854 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
855 if (*p == 0) { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
856 *len = u - utf16; |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
857 return utf16; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
858 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
859 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
860 p++; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
861 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
862 continue; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
863 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
864 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
865 n = ngx_utf8_decode(&p, 4); |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
866 |
5501
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
867 if (n > 0x10ffff) { |
5785
fbdab7f38fd6
Style: use ngx_free() instead of free().
Tatsuhiko Kubo <cubicdaiya@gmail.com>
parents:
5749
diff
changeset
|
868 ngx_free(utf16); |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
869 ngx_set_errno(NGX_EILSEQ); |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
870 return NULL; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
871 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
872 |
5501
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
873 if (n > 0xffff) { |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
874 n -= 0x10000; |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
875 *u++ = (u_short) (0xd800 + (n >> 10)); |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
876 *u++ = (u_short) (0xdc00 + (n & 0x03ff)); |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
877 continue; |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
878 } |
1cd23ca84a9b
Win32: support for UTF-16 surrogate pairs (ticket #457).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5437
diff
changeset
|
879 |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
880 *u++ = (u_short) n; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
881 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
882 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
883 /* unreachable */ |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
884 } |