comparison src/http/modules/ngx_http_dav_module.c @ 1804:d457a1576532

several changes in server_name: *) server_name_in_redirect directive and removal of the '*' stub *) use server address in redirect if host can not be detected *) ngx_http_server_addr() *) allow wildcard and regex names to be a main server_name *) DAV Destination header is tested against Host header
author Igor Sysoev <igor@sysoev.ru>
date Sat, 29 Dec 2007 15:30:39 +0000
parents 7405719e4848
children d3f80e0be8fa
comparison
equal deleted inserted replaced
1803:7405719e4848 1804:d457a1576532
489 489
490 490
491 static ngx_int_t 491 static ngx_int_t
492 ngx_http_dav_copy_move_handler(ngx_http_request_t *r) 492 ngx_http_dav_copy_move_handler(ngx_http_request_t *r)
493 { 493 {
494 u_char *p, *host, *last, ch; 494 u_char *p, *desthost, *last, ch;
495 size_t root; 495 size_t len, root;
496 ngx_err_t err; 496 ngx_err_t err;
497 ngx_int_t rc, depth; 497 ngx_int_t rc, depth;
498 ngx_uint_t overwrite, slash; 498 ngx_uint_t overwrite, slash;
499 ngx_str_t path, uri; 499 ngx_str_t path, uri;
500 ngx_tree_ctx_t tree; 500 ngx_tree_ctx_t tree;
501 ngx_file_info_t fi; 501 ngx_file_info_t fi;
502 ngx_table_elt_t *dest, *over; 502 ngx_table_elt_t *host, *dest, *over;
503 ngx_http_dav_copy_ctx_t copy; 503 ngx_http_dav_copy_ctx_t copy;
504 504
505 if (r->headers_in.content_length_n > 0) { 505 if (r->headers_in.content_length_n > 0) {
506 return NGX_HTTP_UNSUPPORTED_MEDIA_TYPE; 506 return NGX_HTTP_UNSUPPORTED_MEDIA_TYPE;
507 } 507 }
512 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, 512 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
513 "client sent no \"Destination\" header"); 513 "client sent no \"Destination\" header");
514 return NGX_HTTP_BAD_REQUEST; 514 return NGX_HTTP_BAD_REQUEST;
515 } 515 }
516 516
517 if (dest->value.len < sizeof("http://") - 1 + r->server_name.len + 1) { 517 host = r->headers_in.host;
518 goto invalid_destination; 518
519 if (host == NULL) {
520 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
521 "client sent no \"Host\" header");
522 return NGX_HTTP_BAD_REQUEST;
519 } 523 }
520 524
521 #if (NGX_HTTP_SSL) 525 #if (NGX_HTTP_SSL)
522 526
523 if (r->connection->ssl) { 527 if (r->connection->ssl) {
525 != 0) 529 != 0)
526 { 530 {
527 goto invalid_destination; 531 goto invalid_destination;
528 } 532 }
529 533
530 host = dest->value.data + sizeof("https://") - 1; 534 desthost = dest->value.data + sizeof("https://") - 1;
531 535
532 } else 536 } else
533 #endif 537 #endif
534 { 538 {
535 if (ngx_strncmp(dest->value.data, "http://", sizeof("http://") - 1) 539 if (ngx_strncmp(dest->value.data, "http://", sizeof("http://") - 1)
536 != 0) 540 != 0)
537 { 541 {
538 goto invalid_destination; 542 goto invalid_destination;
539 } 543 }
540 544
541 host = dest->value.data + sizeof("http://") - 1; 545 desthost = dest->value.data + sizeof("http://") - 1;
542 } 546 }
543 547
544 if (ngx_strncmp(host, r->server_name.data, r->server_name.len) != 0) { 548 len = r->headers_in.host_name_len;
549
550 if (ngx_strncmp(desthost, host->value.data, len) != 0) {
545 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, 551 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
546 "Destination URI \"%V\" is handled by " 552 "Destination URI \"%V\" is handled by "
547 "different repository than the source URI", 553 "different repository than the source URI",
548 &dest->value); 554 &dest->value);
549 555
550 return NGX_HTTP_BAD_REQUEST; 556 return NGX_HTTP_BAD_REQUEST;
551 } 557 }
552 558
553 last = dest->value.data + dest->value.len; 559 last = dest->value.data + dest->value.len;
554 560
555 for (p = host + r->server_name.len; p < last; p++) { 561 for (p = desthost + len; p < last; p++) {
556 if (*p == '/') { 562 if (*p == '/') {
557 goto destination_done; 563 goto destination_done;
558 } 564 }
559 } 565 }
560 566