Skip to content

Commit 7d655d7

Browse files
committed
버전 - 1.17.10 업데이트
*) 기능 - "auth_delay" 지시문 추가 *) 스크립트 - 업데이트 구문 추가
1 parent 4948d6e commit 7d655d7

File tree

10 files changed

+120
-27
lines changed

10 files changed

+120
-27
lines changed

.DS_Store

0 Bytes
Binary file not shown.

CHANGES

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11

2+
Changes with nginx 1.17.10 14 Apr 2020
3+
4+
*) Feature: the "auth_delay" directive.
5+
6+
27
Changes with nginx 1.17.9 03 Mar 2020
38

49
*) Change: now nginx does not allow several "Host" request header lines.

CHANGES.ru

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11

2+
Изменения в nginx 1.17.10 14.04.2020
3+
4+
*) Добавление: директива auth_delay.
5+
6+
27
Изменения в nginx 1.17.9 03.03.2020
38

49
*) Изменение: теперь nginx не разрешает несколько строк "Host" в

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
오픈소스로 개발 된 소스를 HostLSH 서버에 맞게 수정하였으므로,<br>
88
HostLSH 서버 외에서는 사용하기에 부적합 할 수 있습니다.
99

10-
최근 버전 : 1.17.9
10+
최근 버전 : 1.17.10
1111

12-
# 설치방법
12+
# 설치방법 및 업데이트 방법
1313
```sh
14-
wget https://raw.githubusercontent.com/HanbitGaram/LSH_Nginx/master/install.sh && sh install.sh
14+
wget https://raw.githubusercontent.com/HanbitGaram/LSH_Nginx/master/install.sh -O install.sh && sh install.sh
1515
```
1616

1717
# 설치되는 경로

install.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ apt -y update
66
apt -y upgrade
77
apt-get -y install unzip gcc g++ openssl zlib1g-dev libpcre3 libpcre3-dev make git
88

9-
git clone https://github.com/HanbitGaram/LSH_Nginx.git
10-
cd LSH_Nginx
9+
mkdir /opt/
10+
git clone https://github.com/HanbitGaram/LSH_Nginx.git /opt/LSH_nginx
11+
git pull
12+
13+
cd /opt/LSH_nginx
1114

1215
./configure \
1316
--prefix=/usr/local/nginx \

src/.DS_Store

0 Bytes
Binary file not shown.

src/core/nginx.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#define _NGINX_H_INCLUDED_
1010

1111

12-
#define nginx_version 1017009
13-
#define NGINX_VERSION "1.17.9"
12+
#define nginx_version 1017010
13+
#define NGINX_VERSION "1.17.10"
1414
#define NGINX_VER "HostLSH SERVER/" NGINX_VERSION
1515

1616
#ifdef NGX_BUILD

src/http/modules/ngx_http_auth_basic_module.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ static ngx_int_t ngx_http_auth_basic_crypt_handler(ngx_http_request_t *r,
2525
ngx_str_t *passwd, ngx_str_t *realm);
2626
static ngx_int_t ngx_http_auth_basic_set_realm(ngx_http_request_t *r,
2727
ngx_str_t *realm);
28-
static void ngx_http_auth_basic_close(ngx_file_t *file);
2928
static void *ngx_http_auth_basic_create_loc_conf(ngx_conf_t *cf);
3029
static char *ngx_http_auth_basic_merge_loc_conf(ngx_conf_t *cf,
3130
void *parent, void *child);
@@ -177,8 +176,8 @@ ngx_http_auth_basic_handler(ngx_http_request_t *r)
177176
offset);
178177

179178
if (n == NGX_ERROR) {
180-
ngx_http_auth_basic_close(&file);
181-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
179+
rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
180+
goto cleanup;
182181
}
183182

184183
if (n == 0) {
@@ -219,12 +218,11 @@ ngx_http_auth_basic_handler(ngx_http_request_t *r)
219218
if (buf[i] == LF || buf[i] == CR || buf[i] == ':') {
220219
buf[i] = '\0';
221220

222-
ngx_http_auth_basic_close(&file);
223-
224221
pwd.len = i - passwd;
225222
pwd.data = &buf[passwd];
226223

227-
return ngx_http_auth_basic_crypt_handler(r, &pwd, &realm);
224+
rc = ngx_http_auth_basic_crypt_handler(r, &pwd, &realm);
225+
goto cleanup;
228226
}
229227

230228
break;
@@ -251,8 +249,6 @@ ngx_http_auth_basic_handler(ngx_http_request_t *r)
251249
offset += n;
252250
}
253251

254-
ngx_http_auth_basic_close(&file);
255-
256252
if (state == sw_passwd) {
257253
pwd.len = i - passwd;
258254
pwd.data = ngx_pnalloc(r->pool, pwd.len + 1);
@@ -262,14 +258,26 @@ ngx_http_auth_basic_handler(ngx_http_request_t *r)
262258

263259
ngx_cpystrn(pwd.data, &buf[passwd], pwd.len + 1);
264260

265-
return ngx_http_auth_basic_crypt_handler(r, &pwd, &realm);
261+
rc = ngx_http_auth_basic_crypt_handler(r, &pwd, &realm);
262+
goto cleanup;
266263
}
267264

268265
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
269266
"user \"%V\" was not found in \"%s\"",
270267
&r->headers_in.user, user_file.data);
271268

272-
return ngx_http_auth_basic_set_realm(r, &realm);
269+
rc = ngx_http_auth_basic_set_realm(r, &realm);
270+
271+
cleanup:
272+
273+
if (ngx_close_file(file.fd) == NGX_FILE_ERROR) {
274+
ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno,
275+
ngx_close_file_n " \"%s\" failed", user_file.data);
276+
}
277+
278+
ngx_explicit_memzero(buf, NGX_HTTP_AUTH_BUF_SIZE);
279+
280+
return rc;
273281
}
274282

275283

@@ -338,15 +346,6 @@ ngx_http_auth_basic_set_realm(ngx_http_request_t *r, ngx_str_t *realm)
338346
return NGX_HTTP_UNAUTHORIZED;
339347
}
340348

341-
static void
342-
ngx_http_auth_basic_close(ngx_file_t *file)
343-
{
344-
if (ngx_close_file(file->fd) == NGX_FILE_ERROR) {
345-
ngx_log_error(NGX_LOG_ALERT, file->log, ngx_errno,
346-
ngx_close_file_n " \"%s\" failed", file->name.data);
347-
}
348-
}
349-
350349

351350
static void *
352351
ngx_http_auth_basic_create_loc_conf(ngx_conf_t *cf)

src/http/ngx_http_core_module.c

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ typedef struct {
2121
#define NGX_HTTP_REQUEST_BODY_FILE_CLEAN 2
2222

2323

24+
static ngx_int_t ngx_http_core_auth_delay(ngx_http_request_t *r);
25+
static void ngx_http_core_auth_delay_handler(ngx_http_request_t *r);
26+
2427
static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r);
2528
static ngx_int_t ngx_http_core_find_static_location(ngx_http_request_t *r,
2629
ngx_http_location_tree_node_t *node);
@@ -520,6 +523,13 @@ static ngx_command_t ngx_http_core_commands[] = {
520523
offsetof(ngx_http_core_loc_conf_t, satisfy),
521524
&ngx_http_core_satisfy },
522525

526+
{ ngx_string("auth_delay"),
527+
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
528+
ngx_conf_set_msec_slot,
529+
NGX_HTTP_LOC_CONF_OFFSET,
530+
offsetof(ngx_http_core_loc_conf_t, auth_delay),
531+
NULL },
532+
523533
{ ngx_string("internal"),
524534
NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
525535
ngx_http_core_internal,
@@ -1124,6 +1134,10 @@ ngx_http_core_access_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
11241134

11251135
/* rc == NGX_ERROR || rc == NGX_HTTP_... */
11261136

1137+
if (rc == NGX_HTTP_UNAUTHORIZED) {
1138+
return ngx_http_core_auth_delay(r);
1139+
}
1140+
11271141
ngx_http_finalize_request(r, rc);
11281142
return NGX_OK;
11291143
}
@@ -1141,12 +1155,17 @@ ngx_http_core_post_access_phase(ngx_http_request_t *r,
11411155
access_code = r->access_code;
11421156

11431157
if (access_code) {
1158+
r->access_code = 0;
1159+
11441160
if (access_code == NGX_HTTP_FORBIDDEN) {
11451161
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
11461162
"access forbidden by rule");
11471163
}
11481164

1149-
r->access_code = 0;
1165+
if (access_code == NGX_HTTP_UNAUTHORIZED) {
1166+
return ngx_http_core_auth_delay(r);
1167+
}
1168+
11501169
ngx_http_finalize_request(r, access_code);
11511170
return NGX_OK;
11521171
}
@@ -1156,6 +1175,65 @@ ngx_http_core_post_access_phase(ngx_http_request_t *r,
11561175
}
11571176

11581177

1178+
static ngx_int_t
1179+
ngx_http_core_auth_delay(ngx_http_request_t *r)
1180+
{
1181+
ngx_http_core_loc_conf_t *clcf;
1182+
1183+
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1184+
1185+
if (clcf->auth_delay == 0) {
1186+
ngx_http_finalize_request(r, NGX_HTTP_UNAUTHORIZED);
1187+
return NGX_OK;
1188+
}
1189+
1190+
ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
1191+
"delaying unauthorized request");
1192+
1193+
if (ngx_handle_read_event(r->connection->read, 0) != NGX_OK) {
1194+
return NGX_HTTP_INTERNAL_SERVER_ERROR;
1195+
}
1196+
1197+
r->read_event_handler = ngx_http_test_reading;
1198+
r->write_event_handler = ngx_http_core_auth_delay_handler;
1199+
1200+
r->connection->write->delayed = 1;
1201+
ngx_add_timer(r->connection->write, clcf->auth_delay);
1202+
1203+
/*
1204+
* trigger an additional event loop iteration
1205+
* to ensure constant-time processing
1206+
*/
1207+
1208+
ngx_post_event(r->connection->write, &ngx_posted_next_events);
1209+
1210+
return NGX_OK;
1211+
}
1212+
1213+
1214+
static void
1215+
ngx_http_core_auth_delay_handler(ngx_http_request_t *r)
1216+
{
1217+
ngx_event_t *wev;
1218+
1219+
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1220+
"auth delay handler");
1221+
1222+
wev = r->connection->write;
1223+
1224+
if (wev->delayed) {
1225+
1226+
if (ngx_handle_write_event(wev, 0) != NGX_OK) {
1227+
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1228+
}
1229+
1230+
return;
1231+
}
1232+
1233+
ngx_http_finalize_request(r, NGX_HTTP_UNAUTHORIZED);
1234+
}
1235+
1236+
11591237
ngx_int_t
11601238
ngx_http_core_content_phase(ngx_http_request_t *r,
11611239
ngx_http_phase_handler_t *ph)
@@ -3394,6 +3472,7 @@ ngx_http_core_create_loc_conf(ngx_conf_t *cf)
33943472
clcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE;
33953473
clcf->client_body_timeout = NGX_CONF_UNSET_MSEC;
33963474
clcf->satisfy = NGX_CONF_UNSET_UINT;
3475+
clcf->auth_delay = NGX_CONF_UNSET_MSEC;
33973476
clcf->if_modified_since = NGX_CONF_UNSET_UINT;
33983477
clcf->max_ranges = NGX_CONF_UNSET_UINT;
33993478
clcf->client_body_in_file_only = NGX_CONF_UNSET_UINT;
@@ -3609,6 +3688,7 @@ ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
36093688
|NGX_HTTP_KEEPALIVE_DISABLE_MSIE6));
36103689
ngx_conf_merge_uint_value(conf->satisfy, prev->satisfy,
36113690
NGX_HTTP_SATISFY_ALL);
3691+
ngx_conf_merge_msec_value(conf->auth_delay, prev->auth_delay, 0);
36123692
ngx_conf_merge_uint_value(conf->if_modified_since, prev->if_modified_since,
36133693
NGX_HTTP_IMS_EXACT);
36143694
ngx_conf_merge_uint_value(conf->max_ranges, prev->max_ranges,

src/http/ngx_http_core_module.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ struct ngx_http_core_loc_conf_s {
363363
ngx_msec_t lingering_time; /* lingering_time */
364364
ngx_msec_t lingering_timeout; /* lingering_timeout */
365365
ngx_msec_t resolver_timeout; /* resolver_timeout */
366+
ngx_msec_t auth_delay; /* auth_delay */
366367

367368
ngx_resolver_t *resolver; /* resolver */
368369

0 commit comments

Comments
 (0)