LCOV - code coverage report
Current view: top level - source3/lib - sessionid_tdb.c (source / functions) Hit Total Coverage
Test: coverage report for master 70ed9daf Lines: 32 34 94.1 %
Date: 2024-01-11 09:59:51 Functions: 2 2 100.0 %

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

Generated by: LCOV version 1.14