Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 : Low-level sessionid.tdb access functions
4 : Copyright (C) Volker Lendecke 2010
5 :
6 : This program is free software; you can redistribute it and/or modify
7 : it under the terms of the GNU General Public License as published by
8 : the Free Software Foundation; either version 3 of the License, or
9 : (at your option) any later version.
10 :
11 : This program is distributed in the hope that it will be useful,
12 : but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : GNU General Public License for more details.
15 :
16 : You should have received a copy of the GNU General Public License
17 : along with this program. If not, see <http://www.gnu.org/licenses/>.
18 : */
19 :
20 : #include "includes.h"
21 : #include "system/filesys.h"
22 : #include "dbwrap/dbwrap.h"
23 : #include "dbwrap/dbwrap_open.h"
24 : #include "session.h"
25 : #include "util_tdb.h"
26 : #include "smbd/globals.h"
27 :
28 : struct sessionid_traverse_read_state {
29 : int (*fn)(const char *key, struct sessionid *session,
30 : void *private_data);
31 : void *private_data;
32 : };
33 :
34 12 : static int sessionid_traverse_read_fn(struct smbXsrv_session_global0 *global,
35 : void *private_data)
36 : {
37 12 : struct sessionid_traverse_read_state *state =
38 : (struct sessionid_traverse_read_state *)private_data;
39 12 : struct auth_session_info *session_info = global->auth_session_info;
40 42 : struct sessionid session = {
41 : .uid = -1,
42 : .gid = -1,
43 12 : .id_num = global->session_global_id,
44 12 : .connect_start = nt_time_to_unix(global->creation_time),
45 12 : .pid = global->channels[0].server_id,
46 12 : .connection_dialect = global->connection_dialect,
47 : };
48 :
49 12 : if (session_info != NULL) {
50 12 : session.uid = session_info->unix_token->uid;
51 12 : session.gid = session_info->unix_token->gid;
52 12 : strncpy(session.username,
53 12 : session_info->unix_info->unix_name,
54 : sizeof(fstring)-1);
55 : }
56 :
57 12 : strncpy(session.remote_machine,
58 12 : global->channels[0].remote_name,
59 : sizeof(fstring)-1);
60 12 : strncpy(session.hostname,
61 12 : global->channels[0].remote_address,
62 : sizeof(fstring)-1);
63 12 : strncpy(session.netbios_name,
64 12 : global->channels[0].remote_name,
65 : sizeof(fstring)-1);
66 12 : snprintf(session.id_str, sizeof(fstring)-1,
67 : "smb/%u", global->session_global_id);
68 12 : strncpy(session.ip_addr_str,
69 12 : global->channels[0].remote_address,
70 : sizeof(fstring)-1);
71 :
72 12 : session.encryption_flags = global->encryption_flags;
73 12 : session.cipher = global->channels[0].encryption_cipher;
74 12 : session.signing_flags = global->signing_flags;
75 12 : session.signing = global->channels[0].signing_algo;
76 :
77 12 : return state->fn(NULL, &session, state->private_data);
78 : }
79 :
80 12 : NTSTATUS sessionid_traverse_read(int (*fn)(const char *key,
81 : struct sessionid *session,
82 : void *private_data),
83 : void *private_data)
84 : {
85 : struct sessionid_traverse_read_state state;
86 : NTSTATUS status;
87 :
88 12 : state.fn = fn;
89 12 : state.private_data = private_data;
90 12 : status = smbXsrv_session_global_traverse(sessionid_traverse_read_fn,
91 : &state);
92 :
93 12 : return status;
94 : }
|