2 Unix SMB/CIFS implementation.
3 Low-level connections.tdb access functions
4 Copyright (C) Volker Lendecke 2007
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.
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.
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/>.
21 #include "system/filesys.h"
22 #include "smbd/globals.h"
23 #include "source3/smbd/smbXsrv_session.h"
24 #include "dbwrap/dbwrap.h"
25 #include "dbwrap/dbwrap_open.h"
26 #include "dbwrap/dbwrap_rbt.h"
30 #include "lib/util/string_wrappers.h"
32 struct connections_forall_state
{
33 struct db_context
*session_by_pid
;
34 int (*fn
)(const struct connections_data
*data
,
40 struct connections_forall_session
{
48 uint8_t signing_flags
;
51 static int collect_sessions_fn(struct smbXsrv_session_global0
*global
,
52 void *connections_forall_state
)
55 struct connections_forall_state
*state
=
56 (struct connections_forall_state
*)connections_forall_state
;
58 uint32_t id
= global
->session_global_id
;
59 struct connections_forall_session sess
;
61 if (global
->auth_session_info
== NULL
) {
65 sess
.uid
= global
->auth_session_info
->unix_token
->uid
;
66 sess
.gid
= global
->auth_session_info
->unix_token
->gid
;
68 fstrcpy(sess
.machine
, global
->channels
[0].remote_name
);
69 fstrcpy(sess
.addr
, global
->channels
[0].remote_address
);
70 sess
.cipher
= global
->channels
[0].encryption_cipher
;
71 sess
.signing
= global
->channels
[0].signing_algo
;
72 sess
.dialect
= global
->connection_dialect
;
73 sess
.signing_flags
= global
->signing_flags
;
75 status
= dbwrap_store(state
->session_by_pid
,
76 make_tdb_data((void*)&id
, sizeof(id
)),
77 make_tdb_data((void*)&sess
, sizeof(sess
)),
79 if (!NT_STATUS_IS_OK(status
)) {
80 DEBUG(0, ("Failed to store record: %s\n", nt_errstr(status
)));
85 static int traverse_tcon_fn(struct smbXsrv_tcon_global0
*global
,
86 void *connections_forall_state
)
89 struct connections_forall_state
*state
=
90 (struct connections_forall_state
*)connections_forall_state
;
92 struct connections_data data
;
94 uint32_t sess_id
= global
->session_global_id
;
95 struct connections_forall_session sess
= {
100 TDB_DATA val
= tdb_null
;
103 * Note: that share_name is defined as array without a pointer.
104 * that's why it's always a valid pointer here.
106 if (strlen(global
->share_name
) == 0) {
108 * when a smbXsrv_tcon is created it's created
109 * with empty share_name first in order to allocate
110 * an id, before filling in the details.
115 status
= dbwrap_fetch(state
->session_by_pid
, state
,
116 make_tdb_data((void*)&sess_id
, sizeof(sess_id
)),
118 if (NT_STATUS_IS_OK(status
)) {
119 memcpy((uint8_t *)&sess
, val
.dptr
, val
.dsize
);
124 data
.pid
= global
->server_id
;
125 data
.cnum
= global
->tcon_global_id
;
126 data
.sess_id
= sess_id
;
127 fstrcpy(data
.servicename
, global
->share_name
);
130 fstrcpy(data
.addr
, sess
.addr
);
131 fstrcpy(data
.machine
, sess
.machine
);
132 data
.start
= global
->creation_time
;
133 data
.encryption_flags
= global
->encryption_flags
;
134 data
.cipher
= sess
.cipher
;
135 data
.dialect
= sess
.dialect
;
136 data
.signing
= sess
.signing
;
137 data
.signing_flags
= global
->signing_flags
;
141 return state
->fn(&data
, state
->private_data
);
144 int connections_forall_read(int (*fn
)(const struct connections_data
*data
,
148 TALLOC_CTX
*frame
= talloc_stackframe();
149 struct connections_forall_state
*state
=
150 talloc_zero(talloc_tos(), struct connections_forall_state
);
154 state
->session_by_pid
= db_open_rbt(state
);
156 state
->private_data
= private_data
;
157 status
= smbXsrv_session_global_traverse(collect_sessions_fn
, state
);
158 if (!NT_STATUS_IS_OK(status
)) {
159 DEBUG(0, ("Failed to traverse sessions: %s\n",
164 status
= smbXsrv_tcon_global_traverse(traverse_tcon_fn
, state
);
165 if (!NT_STATUS_IS_OK(status
)) {
166 DEBUG(0, ("Failed to traverse tree connects: %s\n",