Mercurial > hg > nginx-quic
annotate src/core/ngx_open_file_cache.h @ 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 | 7033faf6dc3c |
children | 47ece8818978 |
rev | line source |
---|---|
1453 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4412 | 4 * Copyright (C) Nginx, Inc. |
1453 | 5 */ |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 | |
11 | |
12 #ifndef _NGX_OPEN_FILE_CACHE_H_INCLUDED_ | |
13 #define _NGX_OPEN_FILE_CACHE_H_INCLUDED_ | |
14 | |
15 | |
2277 | 16 #define NGX_OPEN_FILE_DIRECTIO_OFF NGX_MAX_OFF_T_VALUE |
17 | |
18 | |
1453 | 19 typedef struct { |
20 ngx_fd_t fd; | |
21 ngx_file_uniq_t uniq; | |
22 time_t mtime; | |
23 off_t size; | |
3899
e7cd13b7f759
Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents:
3178
diff
changeset
|
24 off_t fs_size; |
2129 | 25 off_t directio; |
3178 | 26 size_t read_ahead; |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2277
diff
changeset
|
27 |
1453 | 28 ngx_err_t err; |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2277
diff
changeset
|
29 char *failed; |
1453 | 30 |
1767
c42431762903
open_file_cache_retest > open_file_cache_valid
Igor Sysoev <igor@sysoev.ru>
parents:
1765
diff
changeset
|
31 time_t valid; |
1453 | 32 |
1772 | 33 ngx_uint_t min_uses; |
34 | |
4477
7033faf6dc3c
Added disable_symlinks directive.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
35 #if (NGX_HAVE_OPENAT) |
7033faf6dc3c
Added disable_symlinks directive.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
36 unsigned disable_symlinks:2; |
7033faf6dc3c
Added disable_symlinks directive.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
37 #endif |
7033faf6dc3c
Added disable_symlinks directive.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
38 |
1453 | 39 unsigned test_dir:1; |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2277
diff
changeset
|
40 unsigned test_only:1; |
2072 | 41 unsigned log:1; |
1453 | 42 unsigned errors:1; |
1457 | 43 unsigned events:1; |
1453 | 44 |
45 unsigned is_dir:1; | |
46 unsigned is_file:1; | |
47 unsigned is_link:1; | |
48 unsigned is_exec:1; | |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
49 unsigned is_directio:1; |
1453 | 50 } ngx_open_file_info_t; |
51 | |
52 | |
53 typedef struct ngx_cached_open_file_s ngx_cached_open_file_t; | |
54 | |
55 struct ngx_cached_open_file_s { | |
56 ngx_rbtree_node_t node; | |
1765 | 57 ngx_queue_t queue; |
1453 | 58 |
59 u_char *name; | |
60 time_t created; | |
61 time_t accessed; | |
62 | |
63 ngx_fd_t fd; | |
64 ngx_file_uniq_t uniq; | |
65 time_t mtime; | |
66 off_t size; | |
67 ngx_err_t err; | |
68 | |
1772 | 69 uint32_t uses; |
70 | |
4477
7033faf6dc3c
Added disable_symlinks directive.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
71 #if (NGX_HAVE_OPENAT) |
7033faf6dc3c
Added disable_symlinks directive.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
72 unsigned disable_symlinks:2; |
7033faf6dc3c
Added disable_symlinks directive.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
73 #endif |
7033faf6dc3c
Added disable_symlinks directive.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
74 |
1453 | 75 unsigned count:24; |
76 unsigned close:1; | |
1775 | 77 unsigned use_event:1; |
1453 | 78 |
79 unsigned is_dir:1; | |
80 unsigned is_file:1; | |
81 unsigned is_link:1; | |
82 unsigned is_exec:1; | |
2246
987831d73bd8
cache directio flag in open file cache
Igor Sysoev <igor@sysoev.ru>
parents:
2231
diff
changeset
|
83 unsigned is_directio:1; |
1453 | 84 |
85 ngx_event_t *event; | |
86 }; | |
87 | |
88 | |
89 typedef struct { | |
90 ngx_rbtree_t rbtree; | |
1761 | 91 ngx_rbtree_node_t sentinel; |
1765 | 92 ngx_queue_t expire_queue; |
1453 | 93 |
94 ngx_uint_t current; | |
95 ngx_uint_t max; | |
96 time_t inactive; | |
97 } ngx_open_file_cache_t; | |
98 | |
99 | |
100 typedef struct { | |
101 ngx_open_file_cache_t *cache; | |
102 ngx_cached_open_file_t *file; | |
1772 | 103 ngx_uint_t min_uses; |
1453 | 104 ngx_log_t *log; |
105 } ngx_open_file_cache_cleanup_t; | |
106 | |
107 | |
108 typedef struct { | |
109 | |
110 /* ngx_connection_t stub to allow use c->fd as event ident */ | |
111 void *data; | |
112 ngx_event_t *read; | |
113 ngx_event_t *write; | |
114 ngx_fd_t fd; | |
115 | |
116 ngx_cached_open_file_t *file; | |
117 ngx_open_file_cache_t *cache; | |
118 } ngx_open_file_cache_event_t; | |
119 | |
120 | |
121 ngx_open_file_cache_t *ngx_open_file_cache_init(ngx_pool_t *pool, | |
122 ngx_uint_t max, time_t inactive); | |
123 ngx_int_t ngx_open_cached_file(ngx_open_file_cache_t *cache, ngx_str_t *name, | |
124 ngx_open_file_info_t *of, ngx_pool_t *pool); | |
125 | |
126 | |
127 #endif /* _NGX_OPEN_FILE_CACHE_H_INCLUDED_ */ |