Changeset 745 for trunk/server/source3/web/cgi.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source3/web/cgi.c
r617 r745 2 2 some simple CGI helper routines 3 3 Copyright (C) Andrew Tridgell 1997-1998 4 4 5 5 This program is free software; you can redistribute it and/or modify 6 6 it under the terms of the GNU General Public License as published by 7 7 the Free Software Foundation; either version 3 of the License, or 8 8 (at your option) any later version. 9 9 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU General Public License for more details. 14 14 15 15 You should have received a copy of the GNU General Public License 16 16 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 19 19 20 20 #include "includes.h" 21 #include "system/passwd.h" 22 #include "system/filesys.h" 21 23 #include "web/swat_proto.h" 24 #include "intl/lang_tdb.h" 25 #include "auth.h" 22 26 #include "secrets.h" 23 #include "../lib/util/util.h"24 27 25 28 #define MAX_VARIABLES 10000 … … 57 60 while ((*cl)) { 58 61 int c; 59 62 60 63 if (i == len) { 61 64 char *ret2; … … 66 69 ret = ret2; 67 70 } 68 71 69 72 c = fgetc(f); 70 73 (*cl)--; … … 74 77 break; 75 78 } 76 79 77 80 if (c == '\r') continue; 78 81 … … 82 85 83 86 } 84 87 85 88 if (ret) { 86 89 ret[i] = 0; … … 136 139 p = strchr_m(line,'='); 137 140 if (!p) continue; 138 141 139 142 *p = 0; 140 143 141 144 variables[num_variables].name = SMB_STRDUP(line); 142 145 variables[num_variables].value = SMB_STRDUP(p+1); 143 146 144 147 SAFE_FREE(line); 145 148 146 149 if (!variables[num_variables].name || 147 150 !variables[num_variables].value) … … 158 161 variables[num_variables].value); 159 162 #endif 160 163 161 164 num_variables++; 162 165 if (num_variables == MAX_VARIABLES) break; … … 173 176 p = strchr_m(tok,'='); 174 177 if (!p) continue; 175 178 176 179 *p = 0; 177 180 178 181 variables[num_variables].name = SMB_STRDUP(tok); 179 182 variables[num_variables].value = SMB_STRDUP(p+1); … … 319 322 320 323 #ifndef __OS2__ 321 pwd = Get_Pwnam_alloc(talloc_autofree_context(), user); 322 324 pwd = Get_Pwnam_alloc(talloc_tos(), user); 323 325 if (!pwd) { 324 326 printf("%sCannot find user %s<br>%s\n", head, user, tail); … … 332 334 if (C_pass == NULL) { 333 335 char *tmp_pass = NULL; 334 tmp_pass = generate_random_str(talloc_tos(), 16); 336 tmp_pass = generate_random_password(talloc_tos(), 337 16, 16); 335 338 if (tmp_pass == NULL) { 336 339 printf("%sFailed to create random nonce for " … … 362 365 fstring user, user_pass; 363 366 struct passwd *pass = NULL; 367 const char *rhost; 368 char addr[INET6_ADDRSTRLEN]; 364 369 365 370 if (!strnequal(line,"Basic ", 6)) { … … 389 394 * Try and get the user from the UNIX password file. 390 395 */ 391 392 pass = Get_Pwnam_alloc(talloc_autofree_context(), user); 393 396 397 pass = Get_Pwnam_alloc(talloc_tos(), user); 398 399 rhost = client_name(1); 400 if (strequal(rhost,"UNKNOWN")) 401 rhost = client_addr(1, addr, sizeof(addr)); 402 394 403 /* 395 404 * Validate the password they have given. 396 405 */ 397 398 if NT_STATUS_IS_OK(pass_check(pass, user, user_pass, 399 strlen(user_pass), NULL, False)) { 400 406 407 if NT_STATUS_IS_OK(pass_check(pass, user, rhost, user_pass, false)) { 401 408 if (pass) { 402 409 /* 403 410 * Password was ok. 404 411 */ 405 412 406 413 if ( initgroups(pass->pw_name, pass->pw_gid) != 0 ) 407 414 goto err; 408 415 409 416 become_user_permanently(pass->pw_uid, pass->pw_gid); 410 417 411 418 /* Save the users name */ 412 419 C_user = SMB_STRDUP(user); … … 416 423 } 417 424 } 418 425 419 426 err: 420 427 cgi_setup_error("401 Bad Authorization", … … 539 546 540 547 548 /* return true if the char* contains ip addrs only. Used to avoid 549 name lookup calls */ 550 551 static bool only_ipaddrs_in_list(const char **list) 552 { 553 bool only_ip = true; 554 555 if (!list) { 556 return true; 557 } 558 559 for (; *list ; list++) { 560 /* factor out the special strings */ 561 if (strequal(*list, "ALL") || strequal(*list, "FAIL") || 562 strequal(*list, "EXCEPT")) { 563 continue; 564 } 565 566 if (!is_ipaddress(*list)) { 567 /* 568 * If we failed, make sure that it was not because 569 * the token was a network/netmask pair. Only 570 * network/netmask pairs have a '/' in them. 571 */ 572 if ((strchr_m(*list, '/')) == NULL) { 573 only_ip = false; 574 DEBUG(3,("only_ipaddrs_in_list: list has " 575 "non-ip address (%s)\n", 576 *list)); 577 break; 578 } 579 } 580 } 581 582 return only_ip; 583 } 584 585 /* return true if access should be allowed to a service for a socket */ 586 static bool check_access(int sock, const char **allow_list, 587 const char **deny_list) 588 { 589 bool ret = false; 590 bool only_ip = false; 591 char addr[INET6_ADDRSTRLEN]; 592 593 if ((!deny_list || *deny_list==0) && (!allow_list || *allow_list==0)) { 594 return true; 595 } 596 597 /* Bypass name resolution calls if the lists 598 * only contain IP addrs */ 599 if (only_ipaddrs_in_list(allow_list) && 600 only_ipaddrs_in_list(deny_list)) { 601 only_ip = true; 602 DEBUG (3, ("check_access: no hostnames " 603 "in host allow/deny list.\n")); 604 ret = allow_access(deny_list, 605 allow_list, 606 "", 607 get_peer_addr(sock,addr,sizeof(addr))); 608 } else { 609 DEBUG (3, ("check_access: hostnames in " 610 "host allow/deny list.\n")); 611 ret = allow_access(deny_list, 612 allow_list, 613 get_peer_name(sock,true), 614 get_peer_addr(sock,addr,sizeof(addr))); 615 } 616 617 if (ret) { 618 DEBUG(2,("Allowed connection from %s (%s)\n", 619 only_ip ? "" : get_peer_name(sock,true), 620 get_peer_addr(sock,addr,sizeof(addr)))); 621 } else { 622 DEBUG(0,("Denied connection from %s (%s)\n", 623 only_ip ? "" : get_peer_name(sock,true), 624 get_peer_addr(sock,addr,sizeof(addr)))); 625 } 626 627 return(ret); 628 } 541 629 542 630 /**
Note:
See TracChangeset
for help on using the changeset viewer.