/src/samba/source3/lib/sessionid_tdb.c
Line | Count | Source |
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 | | #include "source3/smbd/smbXsrv_session.h" |
28 | | #include "../libcli/security/session.h" |
29 | | |
30 | | struct sessionid_traverse_read_state { |
31 | | int (*fn)(const char *key, struct sessionid *session, |
32 | | void *private_data); |
33 | | void *private_data; |
34 | | }; |
35 | | |
36 | | static int sessionid_traverse_read_fn(struct smbXsrv_session_global *global, |
37 | | void *private_data) |
38 | 0 | { |
39 | 0 | struct sessionid_traverse_read_state *state = |
40 | 0 | (struct sessionid_traverse_read_state *)private_data; |
41 | 0 | struct auth_session_info *session_info = global->auth_session_info; |
42 | 0 | struct sessionid session = { |
43 | 0 | .uid = -1, |
44 | 0 | .gid = -1, |
45 | 0 | .id_num = global->session_global_id, |
46 | 0 | .connect_start = nt_time_to_unix(global->creation_time), |
47 | 0 | .pid = global->channels[0].server_id, |
48 | 0 | .connection_dialect = global->connection_dialect, |
49 | 0 | .global = global, |
50 | 0 | }; |
51 | |
|
52 | 0 | if (session_info != NULL) { |
53 | 0 | enum security_user_level ul; |
54 | |
|
55 | 0 | session.uid = session_info->unix_token->uid; |
56 | 0 | session.gid = session_info->unix_token->gid; |
57 | 0 | strncpy(session.username, |
58 | 0 | session_info->unix_info->unix_name, |
59 | 0 | sizeof(fstring)-1); |
60 | |
|
61 | 0 | ul = security_session_user_level(session_info, NULL); |
62 | 0 | if (ul >= SECURITY_USER) { |
63 | 0 | session.authenticated = true; |
64 | 0 | } |
65 | 0 | } |
66 | |
|
67 | 0 | strncpy(session.remote_machine, |
68 | 0 | global->channels[0].remote_name, |
69 | 0 | sizeof(fstring)-1); |
70 | 0 | strncpy(session.hostname, |
71 | 0 | global->channels[0].remote_address, |
72 | 0 | sizeof(fstring)-1); |
73 | 0 | strncpy(session.netbios_name, |
74 | 0 | global->channels[0].remote_name, |
75 | 0 | sizeof(fstring)-1); |
76 | 0 | snprintf(session.id_str, sizeof(fstring)-1, |
77 | 0 | "smb/%u", global->session_global_id); |
78 | 0 | strncpy(session.ip_addr_str, |
79 | 0 | global->channels[0].remote_address, |
80 | 0 | sizeof(fstring)-1); |
81 | |
|
82 | 0 | session.encryption_flags = global->encryption_flags; |
83 | 0 | session.cipher = global->channels[0].encryption_cipher; |
84 | 0 | session.signing_flags = global->signing_flags; |
85 | 0 | session.signing = global->channels[0].signing_algo; |
86 | |
|
87 | 0 | return state->fn(NULL, &session, state->private_data); |
88 | 0 | } |
89 | | |
90 | | NTSTATUS sessionid_traverse_read(int (*fn)(const char *key, |
91 | | struct sessionid *session, |
92 | | void *private_data), |
93 | | void *private_data) |
94 | 0 | { |
95 | 0 | struct sessionid_traverse_read_state state; |
96 | 0 | NTSTATUS status; |
97 | |
|
98 | 0 | state.fn = fn; |
99 | 0 | state.private_data = private_data; |
100 | 0 | status = smbXsrv_session_global_traverse(sessionid_traverse_read_fn, |
101 | 0 | &state); |
102 | |
|
103 | 0 | return status; |
104 | 0 | } |