Changeset 1605 for trunk/server/common/oursrc/httpdmods
- Timestamp:
- Aug 26, 2010, 4:28:45 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/common/oursrc/httpdmods/mod_vhost_ldap.c
r1604 r1605 400 400 } 401 401 402 static int reconfigure_directive(apr_pool_t *p, 403 server_rec *s, 404 const char *dir, 405 const char *args) 406 { 407 ap_directive_t dir_s = { .directive = dir, .args = args, .next = NULL, 408 .line_num = 0, .filename = "VhostLDAPConf" }; 409 return ap_process_config_tree(s, &dir_s, p, p); 410 } 411 402 412 command_rec mod_vhost_ldap_cmds[] = { 403 413 AP_INIT_TAKE1("VhostLDAPURL", mod_vhost_ldap_parse_url, NULL, RSRC_CONF, … … 438 448 server_rec *server; 439 449 const char *error; 450 int code; 440 451 mod_vhost_ldap_request_t *reqc; 441 452 int failures = 0; … … 444 455 mod_vhost_ldap_config_t *conf = 445 456 (mod_vhost_ldap_config_t *)ap_get_module_config(r->server->module_config, &vhost_ldap_module); 446 core_server_config *core;447 457 util_ldap_connection_t *ldc = NULL; 448 458 int result = 0; 449 459 const char *dn = NULL; 450 char *cgi;451 460 const char *hostname = NULL; 452 461 int is_fallback = 0; … … 463 472 return HTTP_INTERNAL_SERVER_ERROR; 464 473 } 465 466 core = core_module.create_server_config(r->pool, server);467 ap_set_module_config(server->module_config, &core_module, core);468 474 469 475 reqc = … … 536 542 hostname += 2; 537 543 hostname += strcspn(hostname, "."); 538 hostname = apr_pstrcat(r->pool, "*", hostname, NULL);544 hostname = apr_pstrcat(r->pool, "*", hostname, (const char *)NULL); 539 545 ap_log_rerror(APLOG_MARK, APLOG_NOTICE|APLOG_NOERRNO, 0, r, 540 546 "[mod_vhost_ldap.c] translate: " … … 579 585 for (i = 0; attributes[i]; i++) { 580 586 587 const char *directive; 581 588 char *val = apr_pstrdup (r->pool, vals[i]); 589 /* These do not correspond to any real directives */ 590 if (strcasecmp (attributes[i], "apacheSuexecUid") == 0) { 591 reqc->uid = val; 592 continue; 593 } 594 else if (strcasecmp (attributes[i], "apacheSuexecGid") == 0) { 595 reqc->gid = val; 596 continue; 597 } 598 582 599 if (strcasecmp (attributes[i], "apacheServerName") == 0) { 583 600 reqc->name = val; 601 directive = "ServerName"; 584 602 } 585 603 else if (strcasecmp (attributes[i], "apacheServerAdmin") == 0) { 586 604 reqc->admin = val; 605 directive = "ServerAdmin"; 587 606 } 588 607 else if (strcasecmp (attributes[i], "apacheDocumentRoot") == 0) { 589 608 reqc->docroot = val; 609 directive = "DocumentRoot"; 590 610 } 591 611 else if (strcasecmp (attributes[i], "apacheScriptAlias") == 0) { 612 if (val != NULL) { 613 /* Hack to deal with current apacheScriptAlias lagout */ 614 if (strlen(val) > 0 && val[strlen(val) - 1] == '/') 615 val = apr_pstrcat(r->pool, "/cgi-bin/ ", val, (const char *)NULL); 616 else 617 val = apr_pstrcat(r->pool, "/cgi-bin/ ", val, "/", (const char *)NULL); 618 directive = "ScriptAlias"; 619 } 592 620 reqc->cgiroot = val; 593 621 } 594 else if (strcasecmp (attributes[i], "apacheSuexecUid") == 0) { 595 reqc->uid = val;596 } 597 else if (strcasecmp (attributes[i], "apacheSuexecGid") == 0) { 598 reqc->gid = val;599 }622 623 if (val == NULL) 624 continue; 625 626 if ((code = reconfigure_directive(r->pool, server, directive, val)) != 0) 627 return code; 600 628 } 601 629 } … … 618 646 } 619 647 620 cgi = NULL; 621 622 if (reqc->cgiroot) { 623 cgi = strstr(r->uri, "cgi-bin/"); 624 if (cgi && (cgi != r->uri + strspn(r->uri, "/"))) { 625 cgi = NULL; 626 } 627 } 628 if (cgi) { 629 /* Set exact filename for CGI script */ 630 cgi = apr_pstrcat(r->pool, reqc->cgiroot, cgi + strlen("cgi-bin"), NULL); 631 if ((cgi = ap_server_root_relative(r->pool, cgi))) { 632 ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r, 633 "[mod_vhost_ldap.c]: ap_document_root is: %s", 634 ap_document_root(r)); 635 r->filename = cgi; 636 r->handler = "cgi-script"; 637 apr_table_setn(r->notes, "alias-forced-type", r->handler); 638 ret = OK; 639 } 640 } else if (strncmp(r->uri, "/~", 2) == 0) { 641 /* This is a quick, dirty hack. I should be shot for taking 6.170 642 * this term and being willing to write a quick, dirty hack. */ 648 if (reqc->uid != NULL) { 643 649 char *username; 644 uid_t uid = (uid_t)atoll(reqc->uid); 650 char *userdir_val; 651 uid_t uid = (uid_t) atoll(reqc->uid); 652 653 if ((code = reconfigure_directive(r->pool, server, "UserDir", USERDIR)) != 0) 654 return code; 655 656 /* Deal with ~ expansion */ 657 if ((code = reconfigure_directive(r->pool, server, "UserDir", "disabled")) != 0) 658 return code; 659 645 660 if (apr_uid_name_get(&username, uid, r->pool) != APR_SUCCESS) { 646 661 ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r, 647 662 "could not get username for uid %d", uid); 648 return DECLINED;663 return HTTP_INTERNAL_SERVER_ERROR; 649 664 } 650 if (strncmp(r->uri + 2, username, strlen(username)) == 0 && 651 (r->uri[2 + strlen(username)] == '/' || 652 r->uri[2 + strlen(username)] == '\0')) { 653 char *homedir; 654 if (apr_uid_homepath_get(&homedir, username, r->pool) != APR_SUCCESS) { 655 ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r, 656 "could not get home directory for user %s", username); 657 return DECLINED; 658 } 659 r->filename = apr_pstrcat(r->pool, homedir, "/", USERDIR, r->uri + 2 + strlen(username), NULL); 660 ret = OK; 661 } 662 } else if (r->uri[0] == '/') { 663 /* we don't set r->filename here, and let other modules do it 664 * this allows other modules (mod_rewrite.c) to work as usual 665 */ 666 /* r->filename = apr_pstrcat (r->pool, reqc->docroot, r->uri, NULL); */ 667 } else { 668 /* We don't handle non-file requests here */ 669 return DECLINED; 670 } 671 672 server->server_hostname = reqc->name; 673 674 if (reqc->admin) { 675 server->server_admin = reqc->admin; 676 } 677 678 /* Stolen from server/core.c */ 679 680 /* Make it absolute, relative to ServerRoot */ 681 reqc->docroot = ap_server_root_relative(r->pool, reqc->docroot); 682 683 if (reqc->docroot == NULL) { 684 ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, 685 "[mod_vhost_ldap.c] set_document_root: DocumentRoot must be a directory"); 686 687 return HTTP_INTERNAL_SERVER_ERROR; 688 } 689 690 /* TODO: ap_configtestonly && ap_docrootcheck && */ 691 if (apr_filepath_merge((char**)&core->ap_document_root, NULL, reqc->docroot, 692 APR_FILEPATH_TRUENAME, r->pool) != APR_SUCCESS 693 || !ap_is_directory(r->pool, reqc->docroot)) { 694 695 ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, 696 "[mod_vhost_ldap.c] set_document_root: Warning: DocumentRoot [%s] does not exist", 697 reqc->docroot); 698 core->ap_document_root = reqc->docroot; 665 666 userdir_val = apr_pstrcat(r->pool, "enabled ", username, (const char *)NULL); 667 668 if ((code = reconfigure_directive(r->pool, server, "UserDir", userdir_val)) != 0) 669 return code; 699 670 } 700 671
Note: See TracChangeset
for help on using the changeset viewer.