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