LCOV - code coverage report
Current view: top level - source4/smb_server - management.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 3 52 5.8 %
Date: 2021-09-23 10:06:22 Functions: 1 6 16.7 %

          Line data    Source code
       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 3 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, see <http://www.gnu.org/licenses/>.
      20             : */
      21             : 
      22             : #include "includes.h"
      23             : #include "smb_server/smb_server.h"
      24             : #include "samba/service_stream.h"
      25             : #include "lib/messaging/irpc.h"
      26             : #include "librpc/gen_ndr/ndr_irpc.h"
      27             : #include "auth/auth.h"
      28             : #include "lib/tsocket/tsocket.h"
      29             : 
      30             : /*
      31             :   return a list of open sessions
      32             : */
      33           0 : static NTSTATUS smbsrv_session_information(struct irpc_message *msg, 
      34             :                                            struct smbsrv_information *r)
      35             : {
      36           0 :         struct smbsrv_connection *smb_conn = talloc_get_type(msg->private_data,
      37             :                                              struct smbsrv_connection);
      38           0 :         struct tsocket_address *client_addr = smb_conn->connection->remote_address;
      39             :         char *client_addr_string;
      40           0 :         int i=0, count=0;
      41             :         struct smbsrv_session *sess;
      42             : 
      43             :         /* This is for debugging only! */
      44           0 :         client_addr_string = tsocket_address_string(client_addr, r);
      45           0 :         NT_STATUS_HAVE_NO_MEMORY(client_addr_string);
      46             : 
      47             :         /* count the number of sessions */
      48           0 :         for (sess=smb_conn->sessions.list; sess; sess=sess->next) {
      49           0 :                 count++;
      50             :         }
      51             : 
      52           0 :         r->out.info.sessions.num_sessions = count;
      53           0 :         r->out.info.sessions.sessions = talloc_array(r, struct smbsrv_session_info, count);
      54           0 :         NT_STATUS_HAVE_NO_MEMORY(r->out.info.sessions.sessions);
      55             : 
      56           0 :         for (sess=smb_conn->sessions.list; sess; sess=sess->next) {
      57           0 :                 struct smbsrv_session_info *info = &r->out.info.sessions.sessions[i];
      58             : 
      59           0 :                 info->client_ip    = client_addr_string;
      60             : 
      61           0 :                 info->vuid         = sess->vuid;
      62           0 :                 info->account_name = sess->session_info->info->account_name;
      63           0 :                 info->domain_name  = sess->session_info->info->domain_name;
      64             :                 
      65           0 :                 info->connect_time = timeval_to_nttime(&sess->statistics.connect_time);
      66           0 :                 info->auth_time    = timeval_to_nttime(&sess->statistics.auth_time);
      67           0 :                 info->last_use_time= timeval_to_nttime(&sess->statistics.last_request_time);
      68           0 :                 i++;
      69             :         }       
      70             : 
      71           0 :         return NT_STATUS_OK;
      72             : }
      73             : 
      74             : /*
      75             :   return a list of tree connects
      76             : */
      77           0 : static NTSTATUS smbsrv_tcon_information(struct irpc_message *msg, 
      78             :                                         struct smbsrv_information *r)
      79             : {
      80           0 :         struct smbsrv_connection *smb_conn = talloc_get_type(msg->private_data,
      81             :                                              struct smbsrv_connection);
      82           0 :         struct tsocket_address *client_addr = smb_conn->connection->remote_address;
      83             :         char *client_addr_string;
      84           0 :         int i=0, count=0;
      85             :         struct smbsrv_tcon *tcon;
      86             : 
      87             :         /* This is for debugging only! */
      88           0 :         client_addr_string = tsocket_address_string(client_addr, r);
      89           0 :         NT_STATUS_HAVE_NO_MEMORY(client_addr_string);
      90             : 
      91             :         /* count the number of tcons */
      92           0 :         for (tcon=smb_conn->smb_tcons.list; tcon; tcon=tcon->next) {
      93           0 :                 count++;
      94             :         }
      95             : 
      96           0 :         r->out.info.tcons.num_tcons = count;
      97           0 :         r->out.info.tcons.tcons = talloc_array(r, struct smbsrv_tcon_info, count);
      98           0 :         NT_STATUS_HAVE_NO_MEMORY(r->out.info.tcons.tcons);
      99             : 
     100           0 :         for (tcon=smb_conn->smb_tcons.list; tcon; tcon=tcon->next) {
     101           0 :                 struct smbsrv_tcon_info *info = &r->out.info.tcons.tcons[i];
     102             : 
     103           0 :                 info->client_ip    = client_addr_string;
     104             : 
     105           0 :                 info->tid          = tcon->tid;
     106           0 :                 info->share_name   = tcon->share_name;
     107           0 :                 info->connect_time = timeval_to_nttime(&tcon->statistics.connect_time);
     108           0 :                 info->last_use_time= timeval_to_nttime(&tcon->statistics.last_request_time);
     109           0 :                 i++;
     110             :         }
     111             : 
     112           0 :         return NT_STATUS_OK;
     113             : }
     114             : 
     115             : /*
     116             :   serve smbserver information via irpc
     117             : */
     118           0 : static NTSTATUS smbsrv_information(struct irpc_message *msg, 
     119             :                                    struct smbsrv_information *r)
     120             : {
     121           0 :         switch (r->in.level) {
     122           0 :         case SMBSRV_INFO_SESSIONS:
     123           0 :                 return smbsrv_session_information(msg, r);
     124           0 :         case SMBSRV_INFO_TCONS:
     125           0 :                 return smbsrv_tcon_information(msg, r);
     126             :         }
     127             : 
     128           0 :         return NT_STATUS_OK;
     129             : }
     130             : 
     131             : /*
     132             :   initialise irpc management calls on a connection
     133             : */
     134        2745 : void smbsrv_management_init(struct smbsrv_connection *smb_conn)
     135             : {
     136        2745 :         IRPC_REGISTER(smb_conn->connection->msg_ctx, irpc, SMBSRV_INFORMATION, 
     137             :                       smbsrv_information, smb_conn);
     138        2745 : }

Generated by: LCOV version 1.13