r9413: Bring Samba4 back up to date with lorikeet-heimdal.
[Samba/aatanasov.git] / source / smb_server / management.c
blob234adac4148f6a16d02dc569076f9b27fe101efb
1 /*
2 Unix SMB/CIFS implementation.
4 management calls for smb server
6 Copyright (C) Andrew Tridgell 2005
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.
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.
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.
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"
31 return a list of open sessions
33 static NTSTATUS smbsrv_session_information(struct irpc_message *msg,
34 struct smbsrv_information *r)
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;
40 /* count the number of sessions */
41 for (sess=smb_conn->sessions.list; sess; sess=sess->next) {
42 count++;
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);
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++;
59 return NT_STATUS_OK;
63 return a list of tree connects
65 static NTSTATUS smbsrv_tree_information(struct irpc_message *msg,
66 struct smbsrv_information *r)
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;
72 /* count the number of tcons */
73 for (tcon=smb_conn->tree.tcons; tcon; tcon=tcon->next) {
74 count++;
77 r->out.info.trees.num_trees = count;
78 r->out.info.trees.trees = talloc_array(r, struct smbsrv_tree_info, count);
79 NT_STATUS_HAVE_NO_MEMORY(r->out.info.trees.trees);
81 for (tcon=smb_conn->tree.tcons; tcon; tcon=tcon->next) {
82 struct smbsrv_tree_info *info = &r->out.info.trees.trees[i];
83 info->tid = tcon->tid;
84 info->share_name = lp_servicename(tcon->service);
85 info->connect_time = timeval_to_nttime(&tcon->connect_time);
86 info->client_ip = socket_get_peer_addr(smb_conn->connection->socket, r);
87 i++;
90 return NT_STATUS_OK;
94 serve smbserver information via irpc
96 static NTSTATUS smbsrv_information(struct irpc_message *msg,
97 struct smbsrv_information *r)
99 switch (r->in.level) {
100 case SMBSRV_INFO_SESSIONS:
101 return smbsrv_session_information(msg, r);
102 case SMBSRV_INFO_TREES:
103 return smbsrv_tree_information(msg, r);
106 return NT_STATUS_OK;
110 initialise irpc management calls on a connection
112 void smbsrv_management_init(struct smbsrv_connection *smb_conn)
114 IRPC_REGISTER(smb_conn->connection->msg_ctx, irpc, SMBSRV_INFORMATION,
115 smbsrv_information, smb_conn);