-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathstatic-glibc-nginx.patch
248 lines (231 loc) · 6.5 KB
/
static-glibc-nginx.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
diff --git a/src/core/nginx.c b/src/core/nginx.c
index 3213527..f61aed7 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -1030,29 +1030,10 @@ ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
#if !(NGX_WIN32)
if (ccf->user == (uid_t) NGX_CONF_UNSET_UINT && geteuid() == 0) {
- struct group *grp;
- struct passwd *pwd;
-
- ngx_set_errno(0);
- pwd = getpwnam(NGX_USER);
- if (pwd == NULL) {
- ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
- "getpwnam(\"" NGX_USER "\") failed");
- return NGX_CONF_ERROR;
- }
-
- ccf->username = NGX_USER;
- ccf->user = pwd->pw_uid;
-
- ngx_set_errno(0);
- grp = getgrnam(NGX_GROUP);
- if (grp == NULL) {
- ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
- "getgrnam(\"" NGX_GROUP "\") failed");
- return NGX_CONF_ERROR;
- }
-
- ccf->group = grp->gr_gid;
+ ngx_set_errno(ENOSYS);
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+ "getpwnam(\"" NGX_USER "\") disabled for static build");
+ return NGX_CONF_ERROR;
}
@@ -1122,9 +1103,6 @@ ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_core_conf_t *ccf = conf;
- char *group;
- struct passwd *pwd;
- struct group *grp;
ngx_str_t *value;
if (ccf->user != (uid_t) NGX_CONF_UNSET_UINT) {
@@ -1143,29 +1121,10 @@ ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ccf->username = (char *) value[1].data;
- ngx_set_errno(0);
- pwd = getpwnam((const char *) value[1].data);
- if (pwd == NULL) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno,
- "getpwnam(\"%s\") failed", value[1].data);
- return NGX_CONF_ERROR;
- }
-
- ccf->user = pwd->pw_uid;
-
- group = (char *) ((cf->args->nelts == 2) ? value[1].data : value[2].data);
-
- ngx_set_errno(0);
- grp = getgrnam(group);
- if (grp == NULL) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno,
- "getgrnam(\"%s\") failed", group);
- return NGX_CONF_ERROR;
- }
-
- ccf->group = grp->gr_gid;
-
- return NGX_CONF_OK;
+ ngx_set_errno(ENOSYS);
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno,
+ "getpwnam(\"%s\") disabled for static build", value[1].data);
+ return NGX_CONF_ERROR;
#endif
}
diff --git a/src/core/ngx_inet.c b/src/core/ngx_inet.c
index 96a04fd..4ab2f7f 100644
--- a/src/core/ngx_inet.c
+++ b/src/core/ngx_inet.c
@@ -1111,95 +1111,9 @@
}
-#if (NGX_HAVE_GETADDRINFO && NGX_HAVE_INET6)
-
-ngx_int_t
-ngx_inet_resolve_host(ngx_pool_t *pool, ngx_url_t *u)
-{
- u_char *host;
- ngx_uint_t n;
- struct addrinfo hints, *res, *rp;
-
- host = ngx_alloc(u->host.len + 1, pool->log);
- if (host == NULL) {
- return NGX_ERROR;
- }
-
- (void) ngx_cpystrn(host, u->host.data, u->host.len + 1);
-
- ngx_memzero(&hints, sizeof(struct addrinfo));
- hints.ai_family = AF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
-#ifdef AI_ADDRCONFIG
- hints.ai_flags = AI_ADDRCONFIG;
-#endif
-
- if (getaddrinfo((char *) host, NULL, &hints, &res) != 0) {
- u->err = "host not found";
- ngx_free(host);
- return NGX_ERROR;
- }
-
- ngx_free(host);
-
- for (n = 0, rp = res; rp != NULL; rp = rp->ai_next) {
-
- switch (rp->ai_family) {
-
- case AF_INET:
- case AF_INET6:
- break;
-
- default:
- continue;
- }
-
- n++;
- }
-
- if (n == 0) {
- u->err = "host not found";
- goto failed;
- }
-
- /* MP: ngx_shared_palloc() */
-
- for (rp = res; rp != NULL; rp = rp->ai_next) {
-
- switch (rp->ai_family) {
-
- case AF_INET:
- case AF_INET6:
- break;
-
- default:
- continue;
- }
-
- if (ngx_inet_add_addr(pool, u, rp->ai_addr, rp->ai_addrlen, n)
- != NGX_OK)
- {
- goto failed;
- }
- }
-
- freeaddrinfo(res);
- return NGX_OK;
-
-failed:
-
- freeaddrinfo(res);
- return NGX_ERROR;
-}
-
-#else /* !NGX_HAVE_GETADDRINFO || !NGX_HAVE_INET6 */
-
ngx_int_t
ngx_inet_resolve_host(ngx_pool_t *pool, ngx_url_t *u)
{
- u_char *host;
- ngx_uint_t i, n;
- struct hostent *h;
struct sockaddr_in sin;
/* AF_INET only */
@@ -1210,37 +1124,8 @@
sin.sin_addr.s_addr = ngx_inet_addr(u->host.data, u->host.len);
if (sin.sin_addr.s_addr == INADDR_NONE) {
- host = ngx_alloc(u->host.len + 1, pool->log);
- if (host == NULL) {
- return NGX_ERROR;
- }
-
- (void) ngx_cpystrn(host, u->host.data, u->host.len + 1);
-
- h = gethostbyname((char *) host);
-
- ngx_free(host);
-
- if (h == NULL || h->h_addr_list[0] == NULL) {
- u->err = "host not found";
- return NGX_ERROR;
- }
-
- for (n = 0; h->h_addr_list[n] != NULL; n++) { /* void */ }
-
- /* MP: ngx_shared_palloc() */
-
- for (i = 0; i < n; i++) {
- sin.sin_addr.s_addr = *(in_addr_t *) (h->h_addr_list[i]);
-
- if (ngx_inet_add_addr(pool, u, (struct sockaddr *) &sin,
- sizeof(struct sockaddr_in), n)
- != NGX_OK)
- {
- return NGX_ERROR;
- }
- }
-
+ u->err = "gethostbyname disabled for static build";
+ return NGX_ERROR;
} else {
/* MP: ngx_shared_palloc() */
@@ -1256,8 +1141,6 @@
return NGX_OK;
}
-#endif /* NGX_HAVE_GETADDRINFO && NGX_HAVE_INET6 */
-
static ngx_int_t
ngx_inet_add_addr(ngx_pool_t *pool, ngx_url_t *u, struct sockaddr *sockaddr,
diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c
index 5817a2c..8262993 100644
--- a/src/os/unix/ngx_process_cycle.c
+++ b/src/os/unix/ngx_process_cycle.c
@@ -833,12 +833,6 @@ ngx_worker_process_init(ngx_cycle_t *cycle, ngx_int_t worker)
exit(2);
}
- if (initgroups(ccf->username, ccf->group) == -1) {
- ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
- "initgroups(%s, %d) failed",
- ccf->username, ccf->group);
- }
-
#if (NGX_HAVE_PR_SET_KEEPCAPS && NGX_HAVE_CAPABILITIES)
if (ccf->transparent && ccf->user) {
if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) == -1) {