Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/smbd/connection.c

    r740 r988  
    2121#include "smbd/smbd.h"
    2222#include "smbd/globals.h"
    23 #include "dbwrap.h"
     23#include "dbwrap/dbwrap.h"
    2424#include "auth.h"
    25 
    26 /****************************************************************************
    27  Delete a connection record.
    28 ****************************************************************************/
    29 
    30 bool yield_connection(connection_struct *conn, const char *name)
    31 {
    32         struct db_record *rec;
    33         NTSTATUS status;
    34 
    35         DEBUG(3,("Yielding connection to %s\n",name));
    36 
    37         rec = connections_fetch_entry(talloc_tos(), conn, name);
    38         if (rec == NULL) {
    39                 DEBUG(0, ("connections_fetch_entry failed\n"));
    40                 return False;
    41         }
    42 
    43         status = rec->delete_rec(rec);
    44         if (!NT_STATUS_IS_OK(status)) {
    45                 DEBUG( NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND) ? 3 : 0,
    46                        ("deleting connection record returned %s\n",
    47                         nt_errstr(status)));
    48         }
    49 
    50         TALLOC_FREE(rec);
    51         return NT_STATUS_IS_OK(status);
    52 }
     25#include "../lib/tsocket/tsocket.h"
     26#include "messages.h"
     27#include "lib/conn_tdb.h"
    5328
    5429struct count_stat {
    5530        int curr_connections;
    5631        const char *name;
    57         bool Clear;
     32        bool verify;
    5833};
    5934
     
    6237****************************************************************************/
    6338
    64 static int count_fn(struct db_record *rec,
    65                     const struct connections_key *ckey,
    66                     const struct connections_data *crec,
     39static int count_fn(struct smbXsrv_tcon_global0 *tcon,
    6740                    void *udp)
    6841{
    6942        struct count_stat *cs = (struct count_stat *)udp;
    7043
    71         if (crec->cnum == -1) {
     44        if (cs->verify && !process_exists(tcon->server_id)) {
    7245                return 0;
    7346        }
    7447
    75         /* If the pid was not found delete the entry from connections.tdb */
    76 
    77         if (cs->Clear && !process_exists(crec->pid) && (errno == ESRCH)) {
    78                 NTSTATUS status;
    79                 DEBUG(2,("pid %s doesn't exist - deleting connections %d [%s]\n",
    80                          procid_str_static(&crec->pid), crec->cnum,
    81                          crec->servicename));
    82 
    83                 status = rec->delete_rec(rec);
    84                 if (!NT_STATUS_IS_OK(status)) {
    85                         DEBUG(0,("count_fn: tdb_delete failed with error %s\n",
    86                                  nt_errstr(status)));
    87                 }
    88                 return 0;
     48        if (strequal(tcon->share_name, cs->name)) {
     49                cs->curr_connections++;
    8950        }
    90 
    91         if (strequal(crec->servicename, cs->name))
    92                 cs->curr_connections++;
    9351
    9452        return 0;
     
    9957****************************************************************************/
    10058
    101 int count_current_connections( const char *sharename, bool clear  )
     59int count_current_connections(const char *sharename, bool verify)
    10260{
    10361        struct count_stat cs;
     62        NTSTATUS status;
    10463
    10564        cs.curr_connections = 0;
    10665        cs.name = sharename;
    107         cs.Clear = clear;
     66        cs.verify = verify;
    10867
    10968        /*
     
    11271         */
    11372
    114         if (connections_forall(count_fn, &cs) == -1) {
     73        status = smbXsrv_tcon_global_traverse(count_fn, &cs);
     74
     75        if (!NT_STATUS_IS_OK(status)) {
    11576                DEBUG(0,("count_current_connections: traverse of "
    116                          "connections.tdb failed\n"));
    117                 return False;
     77                         "smbXsrv_tcon_global.tdb failed - %s\n",
     78                         nt_errstr(status)));
     79                return 0;
    11880        }
    11981
     
    12183}
    12284
    123 /****************************************************************************
    124  Claim an entry in the connections database.
    125 ****************************************************************************/
     85bool connections_snum_used(struct smbd_server_connection *unused, int snum)
     86{
     87        int active;
    12688
    127 bool claim_connection(connection_struct *conn, const char *name)
    128 {
    129         struct db_record *rec;
    130         struct connections_data crec;
    131         TDB_DATA dbuf;
    132         NTSTATUS status;
    133 
    134         DEBUG(5,("claiming [%s]\n", name));
    135 
    136         if (!(rec = connections_fetch_entry(talloc_tos(), conn, name))) {
    137                 DEBUG(0, ("connections_fetch_entry failed\n"));
    138                 return False;
     89        active = count_current_connections(lp_servicename(talloc_tos(), snum),
     90                                           true);
     91        if (active > 0) {
     92                return true;
    13993        }
    14094
    141         /* fill in the crec */
    142         ZERO_STRUCT(crec);
    143         crec.magic = 0x280267;
    144         crec.pid = sconn_server_id(conn->sconn);
    145         crec.cnum = conn->cnum;
    146         crec.uid = conn->session_info->utok.uid;
    147         crec.gid = conn->session_info->utok.gid;
    148         strlcpy(crec.servicename, lp_servicename(SNUM(conn)),
    149                 sizeof(crec.servicename));
    150         crec.start = time(NULL);
    151 
    152         strlcpy(crec.machine,get_remote_machine_name(),sizeof(crec.machine));
    153         strlcpy(crec.addr, conn->sconn->client_id.addr, sizeof(crec.addr));
    154 
    155         dbuf.dptr = (uint8 *)&crec;
    156         dbuf.dsize = sizeof(crec);
    157 
    158         status = rec->store(rec, dbuf, TDB_REPLACE);
    159 
    160         TALLOC_FREE(rec);
    161 
    162         if (!NT_STATUS_IS_OK(status)) {
    163                 DEBUG(0,("claim_connection: tdb_store failed with error %s.\n",
    164                          nt_errstr(status)));
    165                 return False;
    166         }
    167 
    168         return True;
     95        return false;
    16996}
Note: See TracChangeset for help on using the changeset viewer.