Changeset 740 for vendor/current/source3/smbd/session.c
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/smbd/session.c
r414 r740 28 28 29 29 #include "includes.h" 30 #include "smbd/smbd.h" 30 31 #include "smbd/globals.h" 31 32 /******************************************************************** 33 ********************************************************************/ 34 35 static struct db_context *session_db_ctx(void) 36 { 37 if (session_db_ctx_ptr) 38 return session_db_ctx_ptr; 39 40 session_db_ctx_ptr = db_open(NULL, lock_path("sessionid.tdb"), 0, 41 TDB_CLEAR_IF_FIRST|TDB_DEFAULT, 42 O_RDWR | O_CREAT, 0644); 43 return session_db_ctx_ptr; 44 } 45 46 bool session_init(void) 47 { 48 if (session_db_ctx() == NULL) { 49 DEBUG(1,("session_init: failed to open sessionid tdb\n")); 50 return False; 51 } 52 53 return True; 54 } 32 #include "dbwrap.h" 33 #include "session.h" 34 #include "auth.h" 55 35 56 36 /******************************************************************** … … 58 38 ********************************************************************/ 59 39 60 bool session_claim(user_struct *vuser) 61 { 62 TDB_DATA key, data; 40 bool session_claim(struct smbd_server_connection *sconn, user_struct *vuser) 41 { 42 struct server_id pid = sconn_server_id(sconn); 43 TDB_DATA data; 63 44 int i = 0; 64 45 struct sessionid sessionid; 65 struct server_id pid = procid_self();66 46 fstring keystr; 67 const char * hostname;68 struct db_context *ctx;69 47 struct db_record *rec; 70 48 NTSTATUS status; 71 char addr[INET6_ADDRSTRLEN];72 49 73 50 vuser->session_keystr = NULL; … … 75 52 /* don't register sessions for the guest user - its just too 76 53 expensive to go through pam session code for browsing etc */ 77 if (vuser->se rver_info->guest) {54 if (vuser->session_info->guest) { 78 55 return True; 79 56 } 80 57 81 if (! (ctx = session_db_ctx())) {58 if (!sessionid_init()) { 82 59 return False; 83 60 } … … 99 76 100 77 snprintf(keystr, sizeof(keystr), "ID/%d", i); 101 key = string_term_tdb_data(keystr); 102 103 rec = ctx->fetch_locked(ctx, NULL, key); 104 78 79 rec = sessionid_fetch_record(NULL, keystr); 105 80 if (rec == NULL) { 106 81 DEBUG(1, ("Could not lock \"%s\"\n", keystr)); … … 140 115 snprintf(keystr, sizeof(keystr), "ID/%s/%u", 141 116 procid_str_static(&pid), vuser->vuid); 142 key = string_term_tdb_data(keystr); 143 144 rec = ctx->fetch_locked(ctx, NULL, key); 145 117 118 rec = sessionid_fetch_record(NULL, keystr); 146 119 if (rec == NULL) { 147 120 DEBUG(1, ("Could not lock \"%s\"\n", keystr)); … … 162 135 */ 163 136 164 hostname = client_name(get_client_fd()); 165 if (strcmp(hostname, "UNKNOWN") == 0) { 166 hostname = client_addr(get_client_fd(),addr,sizeof(addr)); 167 } 168 169 fstrcpy(sessionid.username, vuser->server_info->unix_name); 170 fstrcpy(sessionid.hostname, hostname); 137 fstrcpy(sessionid.username, vuser->session_info->unix_name); 138 fstrcpy(sessionid.hostname, sconn->client_id.name); 171 139 sessionid.id_num = i; /* Only valid for utmp sessions */ 172 140 sessionid.pid = pid; 173 sessionid.uid = vuser->se rver_info->utok.uid;174 sessionid.gid = vuser->se rver_info->utok.gid;141 sessionid.uid = vuser->session_info->utok.uid; 142 sessionid.gid = vuser->session_info->utok.gid; 175 143 fstrcpy(sessionid.remote_machine, get_remote_machine_name()); 176 fstrcpy(sessionid.ip_addr_str, 177 client_addr(get_client_fd(),addr,sizeof(addr))); 144 fstrcpy(sessionid.ip_addr_str, sconn->client_id.addr); 178 145 sessionid.connect_start = time(NULL); 179 146 … … 220 187 void session_yield(user_struct *vuser) 221 188 { 222 TDB_DATA key;223 189 struct sessionid sessionid; 224 struct db_context *ctx;225 190 struct db_record *rec; 226 227 if (!(ctx = session_db_ctx())) return;228 191 229 192 if (!vuser->session_keystr) { … … 231 194 } 232 195 233 key = string_term_tdb_data(vuser->session_keystr); 234 235 if (!(rec = ctx->fetch_locked(ctx, NULL, key))) { 196 rec = sessionid_fetch_record(NULL, vuser->session_keystr); 197 if (rec == NULL) { 236 198 return; 237 199 } … … 254 216 255 217 TALLOC_FREE(rec); 256 }257 258 /********************************************************************259 ********************************************************************/260 261 static bool session_traverse(int (*fn)(struct db_record *db,262 void *private_data),263 void *private_data)264 {265 struct db_context *ctx;266 267 if (!(ctx = session_db_ctx())) {268 DEBUG(3, ("No tdb opened\n"));269 return False;270 }271 272 ctx->traverse_read(ctx, fn, private_data);273 return True;274 218 } 275 219 … … 283 227 }; 284 228 285 static int gather_sessioninfo(struct db_record *rec, void *state) 286 { 287 struct session_list *sesslist = (struct session_list *) state; 288 const struct sessionid *current = 289 (const struct sessionid *) rec->value.dptr; 229 static int gather_sessioninfo(const char *key, struct sessionid *session, 230 void *private_data) 231 { 232 struct session_list *sesslist = (struct session_list *)private_data; 290 233 291 234 sesslist->sessions = TALLOC_REALLOC_ARRAY( … … 298 241 } 299 242 300 memcpy(&sesslist->sessions[sesslist->count], current,243 memcpy(&sesslist->sessions[sesslist->count], session, 301 244 sizeof(struct sessionid)); 302 245 303 246 sesslist->count++; 304 247 305 DEBUG(7, ("gather_sessioninfo session from %s@%s\n",306 current->username, current->remote_machine));248 DEBUG(7, ("gather_sessioninfo session from %s@%s\n", 249 session->username, session->remote_machine)); 307 250 308 251 return 0; … … 315 258 { 316 259 struct session_list sesslist; 260 int ret; 317 261 318 262 sesslist.mem_ctx = mem_ctx; 319 263 sesslist.count = 0; 320 264 sesslist.sessions = NULL; 321 322 if (!session_traverse(gather_sessioninfo, (void *) &sesslist)) { 265 266 ret = sessionid_traverse_read(gather_sessioninfo, (void *) &sesslist); 267 if (ret == -1) { 323 268 DEBUG(3, ("Session traverse failed\n")); 324 269 SAFE_FREE(sesslist.sessions);
Note:
See TracChangeset
for help on using the changeset viewer.