Changeset 1588 for trunk/server/common/oursrc/httpdmods/mod_vhost_ldap.c
- Timestamp:
- Jul 17, 2010, 3:53:11 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/common/oursrc/httpdmods/mod_vhost_ldap.c
r1463 r1588 32 32 #include "apr_version.h" 33 33 #include "apr_ldap.h" 34 #include "apr_reslist.h" 34 35 #include "apr_strings.h" 35 #include "apr_ reslist.h"36 #include "apr_tables.h" 36 37 #include "util_ldap.h" 38 #include "util_script.h" 37 39 38 40 #if !defined(APU_HAS_LDAP) && !defined(APR_HAS_LDAP) … … 51 53 #define MIN_GID 100 52 54 const char USERDIR[] = "web_scripts"; 55 56 #define MAX_FAILURES 5 53 57 54 58 module AP_MODULE_DECLARE_DATA vhost_ldap_module; … … 122 126 { 123 127 module **m; 124 128 125 129 /* Stolen from modules/generators/mod_cgid.c */ 126 130 total_modules = 0; 127 131 for (m = ap_preloaded_modules; *m != NULL; m++) 128 132 total_modules++; 129 133 130 134 /* make sure that mod_ldap (util_ldap) is loaded */ … … 433 437 { 434 438 mod_vhost_ldap_request_t *reqc; 435 apr_table_t *e;436 439 int failures = 0; 437 440 const char **vals = NULL; … … 439 442 mod_vhost_ldap_config_t *conf = 440 443 (mod_vhost_ldap_config_t *)ap_get_module_config(r->server->module_config, &vhost_ldap_module); 441 core_server_config * 442 (core_server_config *)ap_get_module_config(r->server->module_config, &core_module);444 core_server_config *core = 445 (core_server_config *)ap_get_module_config(r->server->module_config, &core_module); 443 446 util_ldap_connection_t *ldc = NULL; 444 447 int result = 0; … … 447 450 const char *hostname = NULL; 448 451 int is_fallback = 0; 452 int sleep0 = 0; 453 int sleep1 = 1; 454 int sleep; 455 struct berval hostnamebv, shostnamebv; 449 456 450 457 reqc = … … 469 476 ap_log_rerror(APLOG_MARK, APLOG_WARNING|APLOG_NOERRNO, 0, r, 470 477 "[mod_vhost_ldap.c] translate: no conf->host - weird...?"); 471 return DECLINED;478 return HTTP_INTERNAL_SERVER_ERROR; 472 479 } 473 480 474 481 hostname = r->hostname; 475 482 if (hostname == NULL || hostname[0] == '\0') 476 483 goto null; 477 484 478 485 fallback: 479 486 480 487 ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r, 481 "[mod_vhost_ldap.c]: translating %s", r->uri);482 483 struct berval hostnamebv, shostnamebv; 488 "[mod_vhost_ldap.c]: translating hostname [%s], uri [%s]", 489 hostname, r->uri); 490 484 491 ber_str2bv(hostname, 0, 0, &hostnamebv); 485 492 if (ldap_bv2escaped_filter_value(&hostnamebv, &shostnamebv) != 0) … … 494 501 495 502 /* sanity check - if server is down, retry it up to 5 times */ 496 if (result == LDAP_SERVER_DOWN) { 497 if (failures++ <= 5) { 503 if (AP_LDAP_IS_SERVER_DOWN(result) || 504 (result == LDAP_TIMEOUT) || 505 (result == LDAP_CONNECT_ERROR)) { 506 sleep = sleep0 + sleep1; 507 ap_log_rerror(APLOG_MARK, APLOG_WARNING|APLOG_NOERRNO, 0, r, 508 "[mod_vhost_ldap.c]: lookup failure, retry number #[%d], sleeping for [%d] seconds", 509 failures, sleep); 510 if (failures++ < MAX_FAILURES) { 511 /* Back-off exponentially */ 512 apr_sleep(apr_time_from_sec(sleep)); 513 sleep0 = sleep1; 514 sleep1 = sleep; 498 515 goto start_over; 499 } 500 } 501 502 if ((result == LDAP_NO_SUCH_OBJECT)) { 516 } else { 517 return HTTP_GATEWAY_TIME_OUT; 518 } 519 } 520 521 if (result == LDAP_NO_SUCH_OBJECT) { 503 522 if (strcmp(hostname, "*") != 0) { 504 523 if (strncmp(hostname, "*.", 2) == 0) … … 513 532 } 514 533 515 534 null: 516 535 if (conf->fallback && (is_fallback++ <= 0)) { 517 536 ap_log_rerror(APLOG_MARK, APLOG_NOTICE|APLOG_NOERRNO, 0, r, … … 528 547 hostname); 529 548 530 return DECLINED;549 return HTTP_BAD_REQUEST; 531 550 } 532 551 … … 537 556 "translate failed; virtual host %s; URI %s [%s]", 538 557 hostname, r->uri, ldap_err2string(result)); 539 return DECLINED;558 return HTTP_INTERNAL_SERVER_ERROR; 540 559 } 541 560 … … 584 603 "[mod_vhost_ldap.c] translate: " 585 604 "translate failed; ServerName or DocumentRoot not defined"); 586 return DECLINED;605 return HTTP_INTERNAL_SERVER_ERROR; 587 606 } 588 607 589 608 cgi = NULL; 590 609 591 610 #if 0 592 611 if (reqc->cgiroot) { … … 597 616 } 598 617 if (cgi) { 599 r->filename = apr_pstrcat (r->pool, reqc->cgiroot, cgi + strlen("cgi-bin"), NULL); 600 r->handler = "cgi-script"; 601 apr_table_setn(r->notes, "alias-forced-type", r->handler); 618 /* Set exact filename for CGI script */ 619 cgi = apr_pstrcat(r->pool, reqc->cgiroot, cgi + strlen("cgi-bin"), NULL); 620 if ((cgi = ap_server_root_relative(r->pool, cgi))) { 621 ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r, 622 "[mod_vhost_ldap.c]: ap_document_root is: %s", 623 ap_document_root(r)); 624 r->filename = cgi; 625 r->handler = "cgi-script"; 626 apr_table_setn(r->notes, "alias-forced-type", r->handler); 627 } 602 628 #endif 603 629 /* This is a quick, dirty hack. I should be shot for taking 6.170 … … 624 650 } 625 651 } else if (r->uri[0] == '/') { 626 r->filename = apr_pstrcat (r->pool, reqc->docroot, r->uri, NULL); 652 /* we don't set r->filename here, and let other modules do it 653 * this allows other modules (mod_rewrite.c) to work as usual 654 */ 655 /* r->filename = apr_pstrcat (r->pool, reqc->docroot, r->uri, NULL); */ 627 656 } else { 657 /* We don't handle non-file requests here */ 628 658 return DECLINED; 629 659 } 630 660 631 if ((r->server = apr_pmemdup(r->pool, r->server, 632 sizeof(*r->server))) == NULL) 661 if ((r->server = apr_pmemdup(r->pool, r->server, sizeof(*r->server))) == NULL) { 662 ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r, 663 "[mod_vhost_ldap.c] translate: " 664 "translate failed; Unable to copy r->server structure"); 633 665 return HTTP_INTERNAL_SERVER_ERROR; 666 } 634 667 635 668 r->server->server_hostname = reqc->name; … … 639 672 } 640 673 641 // set environment variables 642 e = r->subprocess_env; 643 apr_table_addn (e, "SERVER_ROOT", reqc->docroot); 644 645 if ((r->server->module_config = 646 apr_pmemdup(r->pool, r->server->module_config, 647 sizeof(void *) * 648 (total_modules + DYNAMIC_MODULE_LIMIT))) == NULL) 649 return HTTP_INTERNAL_SERVER_ERROR; 650 651 if ((core = apr_pmemdup(r->pool, core, sizeof(*core))) == NULL) 652 return HTTP_INTERNAL_SERVER_ERROR; 674 if ((r->server->module_config = apr_pmemdup(r->pool, r->server->module_config, 675 sizeof(void *) * 676 (total_modules + DYNAMIC_MODULE_LIMIT))) == NULL) { 677 ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r, 678 "[mod_vhost_ldap.c] translate: " 679 "translate failed; Unable to copy r->server->module_config structure"); 680 return HTTP_INTERNAL_SERVER_ERROR; 681 } 682 683 if ((core = apr_pmemdup(r->pool, core, sizeof(*core))) == NULL) { 684 ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r, 685 "[mod_vhost_ldap.c] translate: " 686 "translate failed; Unable to copy r->core structure"); 687 return HTTP_INTERNAL_SERVER_ERROR; 688 } 653 689 ap_set_module_config(r->server->module_config, &core_module, core); 654 690 655 core->ap_document_root = reqc->docroot; 656 657 ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r, 658 "[mod_vhost_ldap.c]: translated to %s", r->filename); 659 660 return OK; 691 /* Stolen from server/core.c */ 692 693 /* Make it absolute, relative to ServerRoot */ 694 reqc->docroot = ap_server_root_relative(r->pool, reqc->docroot); 695 696 if (reqc->docroot == NULL) { 697 ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, 698 "[mod_vhost_ldap.c] set_document_root: DocumentRoot must be a directory"); 699 700 return HTTP_INTERNAL_SERVER_ERROR; 701 } 702 703 /* TODO: ap_configtestonly && ap_docrootcheck && */ 704 if (apr_filepath_merge((char**)&core->ap_document_root, NULL, reqc->docroot, 705 APR_FILEPATH_TRUENAME, r->pool) != APR_SUCCESS 706 || !ap_is_directory(r->pool, reqc->docroot)) { 707 708 ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, 709 "[mod_vhost_ldap.c] set_document_root: Warning: DocumentRoot [%s] does not exist", 710 reqc->docroot); 711 core->ap_document_root = reqc->docroot; 712 } 713 714 /* Hack to allow post-processing by other modules (mod_rewrite, mod_alias) */ 715 return DECLINED; 661 716 } 662 717 … … 706 761 mod_vhost_ldap_register_hooks (apr_pool_t * p) 707 762 { 763 764 /* 765 * Run before mod_rewrite 766 */ 767 static const char * const aszRewrite[]={ "mod_rewrite.c", NULL }; 768 708 769 ap_hook_post_config(mod_vhost_ldap_post_config, NULL, NULL, APR_HOOK_MIDDLE); 709 ap_hook_translate_name(mod_vhost_ldap_translate_name, NULL, NULL, APR_HOOK_MIDDLE);770 ap_hook_translate_name(mod_vhost_ldap_translate_name, NULL, aszRewrite, APR_HOOK_FIRST); 710 771 #ifdef HAVE_UNIX_SUEXEC 711 772 ap_hook_get_suexec_identity(mod_vhost_ldap_get_suexec_id_doer, NULL, NULL, APR_HOOK_MIDDLE);
Note: See TracChangeset
for help on using the changeset viewer.