r11782: - make the TID 32bit in the smbsrv_tcon structure, as SMB2 uses
[samba.git] / source4 / smb_server / management.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    management calls for smb server
5
6    Copyright (C) Andrew Tridgell 2005
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24 #include "smb_server/smb_server.h"
25 #include "smbd/service_stream.h"
26 #include "lib/messaging/irpc.h"
27 #include "librpc/gen_ndr/ndr_irpc.h"
28 #include "auth/auth.h"
29
30 /*
31   return a list of open sessions
32 */
33 static NTSTATUS smbsrv_session_information(struct irpc_message *msg, 
34                                            struct smbsrv_information *r)
35 {
36         struct smbsrv_connection *smb_conn = talloc_get_type(msg->private, struct smbsrv_connection);
37         int i=0, count=0;
38         struct smbsrv_session *sess;
39
40         /* count the number of sessions */
41         for (sess=smb_conn->sessions.list; sess; sess=sess->next) {
42                 count++;
43         }
44
45         r->out.info.sessions.num_sessions = count;
46         r->out.info.sessions.sessions = talloc_array(r, struct smbsrv_session_info, count);
47         NT_STATUS_HAVE_NO_MEMORY(r->out.info.sessions.sessions);
48
49         for (sess=smb_conn->sessions.list; sess; sess=sess->next) {
50                 struct smbsrv_session_info *info = &r->out.info.sessions.sessions[i];
51                 info->vuid         = sess->vuid;
52                 info->account_name = sess->session_info->server_info->account_name;
53                 info->domain_name  = sess->session_info->server_info->domain_name;
54                 info->connect_time = timeval_to_nttime(&sess->connect_time);
55                 info->client_ip    = socket_get_peer_addr(smb_conn->connection->socket, r);
56                 i++;
57         }       
58
59         return NT_STATUS_OK;
60 }
61
62 /*
63   return a list of tree connects
64 */
65 static NTSTATUS smbsrv_tcon_information(struct irpc_message *msg, 
66                                         struct smbsrv_information *r)
67 {
68         struct smbsrv_connection *smb_conn = talloc_get_type(msg->private, struct smbsrv_connection);
69         int i=0, count=0;
70         struct smbsrv_tcon *tcon;
71
72         /* count the number of tcons */
73         for (tcon=smb_conn->tcons.list; tcon; tcon=tcon->next) {
74                 count++;
75         }
76
77         r->out.info.tcons.num_tcons = count;
78         r->out.info.tcons.tcons = talloc_array(r, struct smbsrv_tcon_info, count);
79         NT_STATUS_HAVE_NO_MEMORY(r->out.info.tcons.tcons);
80
81         for (tcon=smb_conn->tcons.list; tcon; tcon=tcon->next) {
82                 struct smbsrv_tcon_info *info = &r->out.info.tcons.tcons[i];
83                 info->tid          = tcon->tid;
84                 info->share_name   = lp_servicename(tcon->service);
85                 info->connect_time = timeval_to_nttime(&tcon->statistics.connect_time);
86                 info->client_ip    = socket_get_peer_addr(smb_conn->connection->socket, r);
87                 i++;
88         }
89
90         return NT_STATUS_OK;
91 }
92
93 /*
94   serve smbserver information via irpc
95 */
96 static NTSTATUS smbsrv_information(struct irpc_message *msg, 
97                                    struct smbsrv_information *r)
98 {
99         switch (r->in.level) {
100         case SMBSRV_INFO_SESSIONS:
101                 return smbsrv_session_information(msg, r);
102         case SMBSRV_INFO_TCONS:
103                 return smbsrv_tcon_information(msg, r);
104         }
105
106         return NT_STATUS_OK;
107 }
108
109 /*
110   initialise irpc management calls on a connection
111 */
112 void smbsrv_management_init(struct smbsrv_connection *smb_conn)
113 {
114         IRPC_REGISTER(smb_conn->connection->msg_ctx, irpc, SMBSRV_INFORMATION, 
115                       smbsrv_information, smb_conn);
116 }