Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/web/cgi.c

    r615 r740  
    22   some simple CGI helper routines
    33   Copyright (C) Andrew Tridgell 1997-1998
    4    
     4
    55   This program is free software; you can redistribute it and/or modify
    66   it under the terms of the GNU General Public License as published by
    77   the Free Software Foundation; either version 3 of the License, or
    88   (at your option) any later version.
    9    
     9
    1010   This program is distributed in the hope that it will be useful,
    1111   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1212   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1313   GNU General Public License for more details.
    14    
     14
    1515   You should have received a copy of the GNU General Public License
    1616   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    1919
    2020#include "includes.h"
     21#include "system/passwd.h"
     22#include "system/filesys.h"
    2123#include "web/swat_proto.h"
     24#include "intl/lang_tdb.h"
     25#include "auth.h"
    2226#include "secrets.h"
    23 #include "../lib/util/util.h"
    2427
    2528#define MAX_VARIABLES 10000
     
    5760        while ((*cl)) {
    5861                int c;
    59        
     62
    6063                if (i == len) {
    6164                        char *ret2;
     
    6669                        ret = ret2;
    6770                }
    68        
     71
    6972                c = fgetc(f);
    7073                (*cl)--;
     
    7477                        break;
    7578                }
    76                
     79
    7780                if (c == '\r') continue;
    7881
     
    8285
    8386        }
    84        
     87
    8588        if (ret) {
    8689                ret[i] = 0;
     
    136139                        p = strchr_m(line,'=');
    137140                        if (!p) continue;
    138                        
     141
    139142                        *p = 0;
    140                        
     143
    141144                        variables[num_variables].name = SMB_STRDUP(line);
    142145                        variables[num_variables].value = SMB_STRDUP(p+1);
    143146
    144147                        SAFE_FREE(line);
    145                        
     148
    146149                        if (!variables[num_variables].name ||
    147150                            !variables[num_variables].value)
     
    158161                               variables[num_variables].value);
    159162#endif
    160                        
     163
    161164                        num_variables++;
    162165                        if (num_variables == MAX_VARIABLES) break;
     
    173176                        p = strchr_m(tok,'=');
    174177                        if (!p) continue;
    175                        
     178
    176179                        *p = 0;
    177                        
     180
    178181                        variables[num_variables].name = SMB_STRDUP(tok);
    179182                        variables[num_variables].value = SMB_STRDUP(p+1);
     
    318321        }
    319322
    320         pwd = Get_Pwnam_alloc(talloc_autofree_context(), user);
     323        pwd = Get_Pwnam_alloc(talloc_tos(), user);
    321324        if (!pwd) {
    322325                printf("%sCannot find user %s<br>%s\n", head, user, tail);
     
    330333                if (C_pass == NULL) {
    331334                        char *tmp_pass = NULL;
    332                         tmp_pass = generate_random_str(talloc_tos(), 16);
     335                        tmp_pass = generate_random_password(talloc_tos(),
     336                                                            16, 16);
    333337                        if (tmp_pass == NULL) {
    334338                                printf("%sFailed to create random nonce for "
     
    359363        fstring user, user_pass;
    360364        struct passwd *pass = NULL;
     365        const char *rhost;
     366        char addr[INET6_ADDRSTRLEN];
    361367
    362368        if (!strnequal(line,"Basic ", 6)) {
     
    386392         * Try and get the user from the UNIX password file.
    387393         */
    388        
    389         pass = Get_Pwnam_alloc(talloc_autofree_context(), user);
    390        
     394
     395        pass = Get_Pwnam_alloc(talloc_tos(), user);
     396
     397        rhost = client_name(1);
     398        if (strequal(rhost,"UNKNOWN"))
     399                rhost = client_addr(1, addr, sizeof(addr));
     400
    391401        /*
    392402         * Validate the password they have given.
    393403         */
    394        
    395         if NT_STATUS_IS_OK(pass_check(pass, user, user_pass,
    396                       strlen(user_pass), NULL, False)) {
    397                
     404
     405        if NT_STATUS_IS_OK(pass_check(pass, user, rhost, user_pass, false)) {
    398406                if (pass) {
    399407                        /*
    400408                         * Password was ok.
    401409                         */
    402                        
     410
    403411                        if ( initgroups(pass->pw_name, pass->pw_gid) != 0 )
    404412                                goto err;
    405413
    406414                        become_user_permanently(pass->pw_uid, pass->pw_gid);
    407                        
     415
    408416                        /* Save the users name */
    409417                        C_user = SMB_STRDUP(user);
     
    413421                }
    414422        }
    415        
     423
    416424err:
    417425        cgi_setup_error("401 Bad Authorization",
     
    536544
    537545
     546/* return true if the char* contains ip addrs only.  Used to avoid
     547name lookup calls */
     548
     549static bool only_ipaddrs_in_list(const char **list)
     550{
     551        bool only_ip = true;
     552
     553        if (!list) {
     554                return true;
     555        }
     556
     557        for (; *list ; list++) {
     558                /* factor out the special strings */
     559                if (strequal(*list, "ALL") || strequal(*list, "FAIL") ||
     560                    strequal(*list, "EXCEPT")) {
     561                        continue;
     562                }
     563
     564                if (!is_ipaddress(*list)) {
     565                        /*
     566                         * If we failed, make sure that it was not because
     567                         * the token was a network/netmask pair. Only
     568                         * network/netmask pairs have a '/' in them.
     569                         */
     570                        if ((strchr_m(*list, '/')) == NULL) {
     571                                only_ip = false;
     572                                DEBUG(3,("only_ipaddrs_in_list: list has "
     573                                        "non-ip address (%s)\n",
     574                                        *list));
     575                                break;
     576                        }
     577                }
     578        }
     579
     580        return only_ip;
     581}
     582
     583/* return true if access should be allowed to a service for a socket */
     584static bool check_access(int sock, const char **allow_list,
     585                         const char **deny_list)
     586{
     587        bool ret = false;
     588        bool only_ip = false;
     589        char addr[INET6_ADDRSTRLEN];
     590
     591        if ((!deny_list || *deny_list==0) && (!allow_list || *allow_list==0)) {
     592                return true;
     593        }
     594
     595        /* Bypass name resolution calls if the lists
     596         * only contain IP addrs */
     597        if (only_ipaddrs_in_list(allow_list) &&
     598            only_ipaddrs_in_list(deny_list)) {
     599                only_ip = true;
     600                DEBUG (3, ("check_access: no hostnames "
     601                           "in host allow/deny list.\n"));
     602                ret = allow_access(deny_list,
     603                                   allow_list,
     604                                   "",
     605                                   get_peer_addr(sock,addr,sizeof(addr)));
     606        } else {
     607                DEBUG (3, ("check_access: hostnames in "
     608                           "host allow/deny list.\n"));
     609                ret = allow_access(deny_list,
     610                                   allow_list,
     611                                   get_peer_name(sock,true),
     612                                   get_peer_addr(sock,addr,sizeof(addr)));
     613        }
     614
     615        if (ret) {
     616                DEBUG(2,("Allowed connection from %s (%s)\n",
     617                         only_ip ? "" : get_peer_name(sock,true),
     618                         get_peer_addr(sock,addr,sizeof(addr))));
     619        } else {
     620                DEBUG(0,("Denied connection from %s (%s)\n",
     621                         only_ip ? "" : get_peer_name(sock,true),
     622                         get_peer_addr(sock,addr,sizeof(addr))));
     623        }
     624
     625        return(ret);
     626}
    538627
    539628/**
Note: See TracChangeset for help on using the changeset viewer.