s3-libads: Use the configured LDAP page size.
[obnox/samba/samba-obnox.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
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 static int sessionid_traverse_read_fn(struct smbXsrv_session_global0 *global,
35                                       void *private_data)
36 {
37         struct sessionid_traverse_read_state *state =
38                 (struct sessionid_traverse_read_state *)private_data;
39         struct auth_session_info *session_info = global->auth_session_info;
40         struct sessionid session = {
41                 .uid = -1,
42                 .gid = -1,
43                 .id_num = global->session_global_id,
44                 .connect_start = nt_time_to_unix(global->creation_time),
45                 .pid = global->channels[0].server_id,
46         };
47
48         switch(global->connection_dialect){
49         case SMB2_DIALECT_REVISION_000:
50                 fstrcpy(session.protocol_ver, "NT1");
51                 break;
52         case SMB2_DIALECT_REVISION_202:
53                 fstrcpy(session.protocol_ver, "SMB2_02");
54                 break;
55         case SMB2_DIALECT_REVISION_210:
56                 fstrcpy(session.protocol_ver, "SMB2_10");
57                 break;
58         case SMB2_DIALECT_REVISION_222:
59                 fstrcpy(session.protocol_ver, "SMB2_22");
60                 break;
61         case SMB2_DIALECT_REVISION_224:
62                 fstrcpy(session.protocol_ver, "SMB2_24");
63                 break;
64         case SMB3_DIALECT_REVISION_300:
65                 fstrcpy(session.protocol_ver, "SMB3_00");
66                 break;
67         case SMB3_DIALECT_REVISION_302:
68                 fstrcpy(session.protocol_ver, "SMB3_02");
69                 break;
70         case SMB3_DIALECT_REVISION_310:
71                 fstrcpy(session.protocol_ver, "SMB3_10");
72                 break;
73         case SMB3_DIALECT_REVISION_311:
74                 fstrcpy(session.protocol_ver, "SMB3_11");
75                 break;
76         default:
77                 fstr_sprintf(session.protocol_ver, "Unknown (0x%04x)",
78                              global->connection_dialect);
79                 break;
80         }
81
82         if (session_info != NULL) {
83                 session.uid = session_info->unix_token->uid;
84                 session.gid = session_info->unix_token->gid;
85                 strncpy(session.username,
86                         session_info->unix_info->unix_name,
87                         sizeof(fstring)-1);
88         }
89
90         strncpy(session.remote_machine,
91                 global->channels[0].remote_name,
92                 sizeof(fstring)-1);
93         strncpy(session.hostname,
94                 global->channels[0].remote_address,
95                 sizeof(fstring)-1);
96         strncpy(session.netbios_name,
97                 global->channels[0].remote_name,
98                 sizeof(fstring)-1);
99         snprintf(session.id_str, sizeof(fstring)-1,
100                  "smb/%u", global->session_global_id);
101         strncpy(session.ip_addr_str,
102                 global->channels[0].remote_address,
103                 sizeof(fstring)-1);
104
105         return state->fn(NULL, &session, state->private_data);
106 }
107
108 NTSTATUS sessionid_traverse_read(int (*fn)(const char *key,
109                                           struct sessionid *session,
110                                           void *private_data),
111                                  void *private_data)
112 {
113         struct sessionid_traverse_read_state state;
114         NTSTATUS status;
115
116         state.fn = fn;
117         state.private_data = private_data;
118         status = smbXsrv_session_global_traverse(sessionid_traverse_read_fn,
119                                                  &state);
120
121         return status;
122 }