Changeset 988 for vendor/current/source3/smbd/connection.c
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/smbd/connection.c
r740 r988 21 21 #include "smbd/smbd.h" 22 22 #include "smbd/globals.h" 23 #include "dbwrap .h"23 #include "dbwrap/dbwrap.h" 24 24 #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" 53 28 54 29 struct count_stat { 55 30 int curr_connections; 56 31 const char *name; 57 bool Clear;32 bool verify; 58 33 }; 59 34 … … 62 37 ****************************************************************************/ 63 38 64 static int count_fn(struct db_record *rec, 65 const struct connections_key *ckey, 66 const struct connections_data *crec, 39 static int count_fn(struct smbXsrv_tcon_global0 *tcon, 67 40 void *udp) 68 41 { 69 42 struct count_stat *cs = (struct count_stat *)udp; 70 43 71 if (c rec->cnum == -1) {44 if (cs->verify && !process_exists(tcon->server_id)) { 72 45 return 0; 73 46 } 74 47 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++; 89 50 } 90 91 if (strequal(crec->servicename, cs->name))92 cs->curr_connections++;93 51 94 52 return 0; … … 99 57 ****************************************************************************/ 100 58 101 int count_current_connections( const char *sharename, bool clear)59 int count_current_connections(const char *sharename, bool verify) 102 60 { 103 61 struct count_stat cs; 62 NTSTATUS status; 104 63 105 64 cs.curr_connections = 0; 106 65 cs.name = sharename; 107 cs. Clear = clear;66 cs.verify = verify; 108 67 109 68 /* … … 112 71 */ 113 72 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)) { 115 76 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; 118 80 } 119 81 … … 121 83 } 122 84 123 /**************************************************************************** 124 Claim an entry in the connections database. 125 ****************************************************************************/ 85 bool connections_snum_used(struct smbd_server_connection *unused, int snum) 86 { 87 int active; 126 88 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; 139 93 } 140 94 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; 169 96 }
Note:
See TracChangeset
for help on using the changeset viewer.