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:
7 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/**
  • trunk/server/source3/web/diagnose.c

    r414 r745  
    33   diagnosis tools for web admin
    44   Copyright (C) Andrew Tridgell 1998
    5    
     5
    66   This program is free software; you can redistribute it and/or modify
    77   it under the terms of the GNU General Public License as published by
    88   the Free Software Foundation; either version 3 of the License, or
    99   (at your option) any later version.
    10    
     10
    1111   This program is distributed in the hope that it will be useful,
    1212   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1313   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1414   GNU General Public License for more details.
    15    
     15
    1616   You should have received a copy of the GNU General Public License
    1717   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2020#include "includes.h"
    2121#include "web/swat_proto.h"
     22#include "lib/winbind_util.h"
     23#include "libsmb/libsmb.h"
    2224
    2325#ifdef WITH_WINBIND
     
    3638{
    3739        struct in_addr loopback_ip;
    38         int fd, count, flags;
     40        int count;
    3941        struct sockaddr_storage *ss_list;
    4042        struct sockaddr_storage ss;
     43        NTSTATUS status;
    4144
    4245        loopback_ip.s_addr = htonl(INADDR_LOOPBACK);
    4346        in_addr_to_sockaddr_storage(&ss, loopback_ip);
    4447
    45         if ((fd = open_socket_in(SOCK_DGRAM, 0, 3,
    46                                  &ss, True)) != -1) {
    47                 if ((ss_list = name_query(fd, "__SAMBA__", 0,
    48                                           True, True, &ss,
    49                                           &count, &flags, NULL)) != NULL) {
    50                         SAFE_FREE(ss_list);
    51                         close(fd);
    52                         return True;
    53                 }
    54                 close (fd);
     48        status = name_query("__SAMBA__", 0,
     49                            True, True, &ss,
     50                            talloc_tos(), &ss_list, &count,
     51                            NULL);
     52        if (NT_STATUS_IS_OK(status)) {
     53                TALLOC_FREE(ss_list);
     54                return True;
    5555        }
    5656
  • trunk/server/source3/web/neg_lang.c

    r414 r745  
    2121#include "includes.h"
    2222#include "web/swat_proto.h"
     23#include "intl/lang_tdb.h"
    2324
    2425/*
     
    5253};
    5354
    54 static int qsort_cmp_list(const void *x, const void *y) {
    55         struct pri_list *a = (struct pri_list *)x;
    56         struct pri_list *b = (struct pri_list *)y;
     55static int qsort_cmp_list(struct pri_list *a, struct pri_list *b)
     56{
    5757        if (a->pri > b->pri) return -1;
    5858        if (a->pri < b->pri) return 1;
     
    102102        TALLOC_FREE(lang_list);
    103103
    104         qsort(pl, lang_num, sizeof(struct pri_list), &qsort_cmp_list);
     104        TYPESAFE_QSORT(pl, lang_num, qsort_cmp_list);
    105105
    106106        /* it's not an error to not initialise - we just fall back to
  • trunk/server/source3/web/startstop.c

    r454 r745  
    4747           is closed, therefore we use spawn() */
    4848        SWAT_HELPER(start, smbd)       
    49 #else   
     49#else
    5050        if (fork()) {
    5151                return;
     
    5353
    5454        if (asprintf(&binfile, "%s/smbd", get_dyn_SBINDIR()) > 0) {
    55                 become_daemon(true, false);
     55                become_daemon(true, false, false);
    5656                execl(binfile, binfile, "-D", NULL);
    5757        }
     
    7373           is closed, therefore we use spawn() */
    7474        SWAT_HELPER(start, nmbd)
    75 #else   
     75#else
    7676        if (fork()) {
    7777                return;
     
    7979
    8080        if (asprintf(&binfile, "%s/nmbd", get_dyn_SBINDIR()) > 0) {
    81                 become_daemon(true, false);
     81                become_daemon(true, false, false);
    8282                execl(binfile, binfile, "-D", NULL);
    8383        }
     
    9999           is closed, therefore we use spawn() */
    100100        SWAT_HELPER(start, winbindd)
    101 #else   
     101#else
    102102        if (fork()) {
    103103                return;
     
    105105
    106106        if (asprintf(&binfile, "%s/winbindd", get_dyn_SBINDIR()) > 0) {
    107                 become_daemon(true, false);
     107                become_daemon(true, false, false);
    108108                execl(binfile, binfile, NULL);
    109109        }
  • trunk/server/source3/web/statuspage.c

    r617 r745  
    2020#include "includes.h"
    2121#include "web/swat_proto.h"
     22#include "libcli/security/security.h"
     23#include "locking/proto.h"
    2224
    2325#define _(x) lang_msg_rotate(talloc_tos(),x)
     
    124126{
    125127        char           *utf8_fname;
     128        char           *utf8_sharepath;
    126129        int deny_mode;
    127130        size_t converted_size;
     
    173176
    174177        push_utf8_talloc(talloc_tos(), &utf8_fname, fname, &converted_size);
    175         printf("<td>%s</td><td>%s</td></tr>\n",
    176                utf8_fname,tstring(talloc_tos(),e->time.tv_sec));
     178        push_utf8_talloc(talloc_tos(), &utf8_sharepath, sharepath,
     179                         &converted_size);
     180        printf("<td>%s</td><td>%s</td><td>%s</td></tr>\n",
     181               utf8_sharepath,utf8_fname,tstring(talloc_tos(),e->time.tv_sec));
    177182        TALLOC_FREE(utf8_fname);
    178183}
     
    180185
    181186/* kill off any connections chosen by the user */
    182 static int traverse_fn1(struct db_record *rec,
    183                         const struct connections_key *key,
     187static int traverse_fn1(const struct connections_key *key,
    184188                        const struct connections_data *crec,
    185189                        void *private_data)
     
    197201
    198202/* traversal fn for showing machine connections */
    199 static int traverse_fn2(struct db_record *rec,
    200                         const struct connections_key *key,
     203static int traverse_fn2(const struct connections_key *key,
    201204                        const struct connections_data *crec,
    202205                        void *private_data)
     
    222225
    223226/* traversal fn for showing share connections */
    224 static int traverse_fn3(struct db_record *rec,
    225                         const struct connections_key *key,
     227static int traverse_fn3(const struct connections_key *key,
    226228                        const struct connections_data *crec,
    227229                        void *private_data)
     
    328330        }
    329331
    330         connections_forall(traverse_fn1, NULL);
     332        connections_forall_read(traverse_fn1, NULL);
    331333
    332334        initPid2Machine ();
     
    420422        printf("</tr>\n");
    421423
    422         connections_forall(traverse_fn2, NULL);
     424        connections_forall_read(traverse_fn2, NULL);
    423425
    424426        printf("</table><p>\n");
     
    429431                _("Share"), _("User"), _("Group"), _("PID"), _("Client"), _("Date"));
    430432
    431         connections_forall(traverse_fn3, NULL);
     433        connections_forall_read(traverse_fn3, NULL);
    432434
    433435        printf("</table><p>\n");
     
    435437        printf("<h3>%s</h3>\n", _("Open Files"));
    436438        printf("<table border=1>\n");
    437         printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n",
    438                 _("PID"), _("UID"), _("Sharing"), _("R/W"), _("Oplock"), _("File"), _("Date"));
     439        printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n",
     440                _("PID"), _("UID"), _("Sharing"), _("R/W"), _("Oplock"), _("Share"), _("File"), _("Date"));
    439441
    440442        locking_init_readonly();
  • trunk/server/source3/web/swat.c

    r617 r745  
    55   Copyright (C) Andrew Tridgell 1997-2002
    66   Copyright (C) John H Terpstra 2002
    7    
     7
    88   This program is free software; you can redistribute it and/or modify
    99   it under the terms of the GNU General Public License as published by
    1010   the Free Software Foundation; either version 3 of the License, or
    1111   (at your option) any later version.
    12    
     12
    1313   This program is distributed in the hope that it will be useful,
    1414   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1515   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1616   GNU General Public License for more details.
    17    
     17
    1818   You should have received a copy of the GNU General Public License
    1919   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2929
    3030#include "includes.h"
     31#include "system/filesys.h"
     32#include "popt_common.h"
    3133#include "web/swat_proto.h"
     34#include "printing/pcap.h"
     35#include "printing/load.h"
     36#include "passdb.h"
     37#include "intl/lang_tdb.h"
    3238#include "../lib/crypto/md5.h"
    3339
     
    122128
    123129        while (*str) {
    124                 if (*str != ' ') *p++ = toupper_ascii(*str);
     130                if (*str != ' ') *p++ = toupper_m(*str);
    125131                ++str;
    126132        }
     
    169175
    170176                snprintf(tmp, sizeof(tmp), "%02x", token[i]);
    171                 strncat(token_str, tmp, sizeof(tmp));
     177                strlcat(token_str, tmp, sizeof(tmp));
    172178        }
    173179}
     
    193199        const char *token = cgi_variable_nonull(XSRF_TOKEN);
    194200        const char *time_str = cgi_variable_nonull(XSRF_TIME);
     201        char *p = NULL;
     202        long long xsrf_time_ll = 0;
    195203        time_t xsrf_time = 0;
    196204        time_t now = time(NULL);
    197205
    198         if (sizeof(time_t) == sizeof(int)) {
    199                 xsrf_time = atoi(time_str);
    200         } else if (sizeof(time_t) == sizeof(long)) {
    201                 xsrf_time = atol(time_str);
    202         } else if (sizeof(time_t) == sizeof(long long)) {
    203                 xsrf_time = atoll(time_str);
    204         }
     206        errno = 0;
     207        xsrf_time_ll = strtoll(time_str, &p, 10);
     208        if (errno != 0) {
     209                return false;
     210        }
     211        if (p == NULL) {
     212                return false;
     213        }
     214        if (PTR_DIFF(p, time_str) > strlen(time_str)) {
     215                return false;
     216        }
     217        if (xsrf_time_ll > _TYPE_MAXIMUM(time_t)) {
     218                return false;
     219        }
     220        if (xsrf_time_ll < _TYPE_MINIMUM(time_t)) {
     221                return false;
     222        }
     223        xsrf_time = xsrf_time_ll;
    205224
    206225        if (abs(now - xsrf_time) > XSRF_TIMEOUT) {
     
    492511
    493512                if ((parm_filter & FLAG_WIZARD) && !(parm->flags & FLAG_WIZARD)) continue;
    494                
     513
    495514                if ((parm_filter & FLAG_ADVANCED) && !(parm->flags & FLAG_ADVANCED)) continue;
    496                
     515
    497516                if (heading && heading != last_heading) {
    498517                        printf("<tr><td></td></tr><tr><td><b><u>%s</u></b></td></tr>\n", _(heading));
     
    521540        fprintf(f, "# from %s (%s)\n", cgi_remote_host(), cgi_remote_addr());
    522541        fprintf(f, "# Date: %s\n\n", current_timestring(ctx, False));
    523        
     542
    524543        lp_dump(f, show_defaults, iNumNonAutoPrintServices);
    525544
     
    565584        }
    566585        iNumNonAutoPrintServices = lp_numservices();
    567         pcap_cache_reload(&load_printers);
     586        if (pcap_cache_loaded()) {
     587                load_printers(server_event_context(),
     588                              server_messaging_context());
     589        }
    568590
    569591        return 1;
     
    631653{
    632654        char *p;
    633        
     655
    634656        if ((p = cgi_user_name()) && strcmp(p, "root")) {
    635657                printf(_("Logged in as <b>%s</b>"), p);
     
    745767        printf("<input type=reset name=\"Reset Values\" value=\"Reset\">\n");
    746768        printf("<p>\n");
    747        
     769
    748770        printf("<table>\n");
    749771        show_parameters(GLOBAL_SECTION_SNUM, 1, parm_filter, 0);
     
    797819                /* Plain text passwords are too badly broken - use encrypted passwords only */
    798820                lp_do_parameter( GLOBAL_SECTION_SNUM, "encrypt passwords", "Yes");
    799                
     821
    800822                switch ( SerType ){
    801823                        case 0:
     
    909931                for(i = 0; wins_servers[i]; i++) printf("%s ", wins_servers[i]);
    910932        }
    911        
     933
    912934        printf("\"></td></tr>\n");
    913935        if (winstype == 3) {
     
    919941        printf("<td><input type=radio name=\"HomeExpo\" value=\"0\" %s> No</td>", (have_home == -1 ) ? "checked" : "");
    920942        printf("<td></td></tr>\n");
    921        
     943
    922944        /* Enable this when we are ready ....
    923945         * printf("<tr><td><b>%s:&nbsp;</b></td>\n", _("Is Print Server"));
     
    926948         * printf("<td></td></tr>\n");
    927949         */
    928        
     950
    929951        printf("</table></center>");
    930952        printf("<hr>");
     
    11251147                return False;
    11261148        }
    1127        
     1149
    11281150        if (remote_machine != NULL) {
    11291151                ret = remote_password_change(remote_machine, user_name,
     
    11391161                return False;
    11401162        }
    1141        
     1163
    11421164        ret = local_password_change(user_name, local_flags, new_passwd,
    11431165                                        &err_str, &msg_str);
     
    12221244        local_flags |= (cgi_variable(ENABLE_USER_FLAG) ? LOCAL_ENABLE_USER : 0);
    12231245        local_flags |= (cgi_variable(DISABLE_USER_FLAG) ? LOCAL_DISABLE_USER : 0);
    1224        
    12251246
    12261247        rslt = change_password(host,
     
    12371258                }
    12381259        }
    1239        
     1260
    12401261        return;
    12411262}
     
    15271548        BlockSignals(True,SIGPIPE);
    15281549
    1529         dbf = x_fopen("/dev/null", O_WRONLY, 0);
    1530         if (!dbf) dbf = x_stderr;
     1550        debug_set_logfile("/dev/null");
    15311551
    15321552        /* we don't want stderr screwing us up */
    15331553        close(2);
    15341554        open("/dev/null", O_WRONLY);
    1535 
     1555        setup_logging("swat", DEBUG_FILE);
     1556
     1557        load_case_tables();
     1558       
    15361559        pc = poptGetContext("swat", argc, (const char **) argv, long_options, 0);
    15371560
     
    15421565        poptFreeContext(pc);
    15431566
    1544         load_case_tables();
    1545 
    1546         setup_logging(argv[0],False);
     1567        /* This should set a more apporiate log file */
    15471568        load_config(True);
     1569        reopen_logs();
    15481570        load_interfaces();
    15491571        iNumNonAutoPrintServices = lp_numservices();
    1550         pcap_cache_reload(&load_printers);
     1572        if (pcap_cache_loaded()) {
     1573                load_printers(server_event_context(),
     1574                              server_messaging_context());
     1575        }
    15511576
    15521577#ifndef __OS2__
    15531578        cgi_setup(get_dyn_SWATDIR(), !demo_mode);
    1554 #else
    1555 
     1579#else
    15561580#if 0
    15571581        debug_set_logfile("swat.log"); // this produces a logfile in the dir where swat.exe is located.
    15581582#endif
    1559 
    15601583        fstring path;
    15611584        fstrcpy(path, getcwd(NULL, _MAX_PATH));
Note: See TracChangeset for help on using the changeset viewer.