Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/web/cgi.c

    r617 r745  
    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);
     
    319322
    320323#ifndef __OS2__
    321         pwd = Get_Pwnam_alloc(talloc_autofree_context(), user);
    322        
     324        pwd = Get_Pwnam_alloc(talloc_tos(), user);
    323325        if (!pwd) {
    324326                printf("%sCannot find user %s<br>%s\n", head, user, tail);
     
    332334                if (C_pass == NULL) {
    333335                        char *tmp_pass = NULL;
    334                         tmp_pass = generate_random_str(talloc_tos(), 16);
     336                        tmp_pass = generate_random_password(talloc_tos(),
     337                                                            16, 16);
    335338                        if (tmp_pass == NULL) {
    336339                                printf("%sFailed to create random nonce for "
     
    362365        fstring user, user_pass;
    363366        struct passwd *pass = NULL;
     367        const char *rhost;
     368        char addr[INET6_ADDRSTRLEN];
    364369
    365370        if (!strnequal(line,"Basic ", 6)) {
     
    389394         * Try and get the user from the UNIX password file.
    390395         */
    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
    394403        /*
    395404         * Validate the password they have given.
    396405         */
    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)) {
    401408                if (pass) {
    402409                        /*
    403410                         * Password was ok.
    404411                         */
    405                        
     412
    406413                        if ( initgroups(pass->pw_name, pass->pw_gid) != 0 )
    407414                                goto err;
    408415
    409416                        become_user_permanently(pass->pw_uid, pass->pw_gid);
    410                        
     417
    411418                        /* Save the users name */
    412419                        C_user = SMB_STRDUP(user);
     
    416423                }
    417424        }
    418        
     425
    419426err:
    420427        cgi_setup_error("401 Bad Authorization",
     
    539546
    540547
     548/* return true if the char* contains ip addrs only.  Used to avoid
     549name lookup calls */
     550
     551static 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 */
     586static 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}
    541629
    542630/**
Note: See TracChangeset for help on using the changeset viewer.