LCOV - code coverage report
Current view: top level - source3/modules - vfs_dfs_samba4.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 37 53 69.8 %
Date: 2021-09-23 10:06:22 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*
       2             :  * VFS module to alter the algorithm to calculate
       3             :  * the struct file_id used as key for the share mode
       4             :  * and byte range locking db's.
       5             :  *
       6             :  * Copyright (C) 2007, Stefan Metzmacher
       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 "smbd/smbd.h"
      24             : #include "smbd/globals.h"
      25             : #include "system/filesys.h"
      26             : #include "source3/include/msdfs.h"
      27             : #include "librpc/gen_ndr/ndr_dfsblobs.h"
      28             : #include "source4/lib/events/events.h"
      29             : #include "source4/auth/session.h"
      30             : #include "lib/param/param.h"
      31             : #include "source4/dsdb/samdb/samdb.h"
      32             : #include "dfs_server/dfs_server_ad.h"
      33             : 
      34             : static int vfs_dfs_samba4_debug_level = DBGC_VFS;
      35             : 
      36             : #undef DBGC_CLASS
      37             : #define DBGC_CLASS vfs_dfs_samba4_debug_level
      38             : 
      39             : struct dfs_samba4_handle_data {
      40             :         struct tevent_context *ev;
      41             :         struct loadparm_context *lp_ctx;
      42             :         struct ldb_context *sam_ctx;
      43             : };
      44             : 
      45       11779 : static int dfs_samba4_connect(struct vfs_handle_struct *handle,
      46             :                               const char *service, const char *user)
      47             : {
      48             :         struct dfs_samba4_handle_data *data;
      49       11779 :         int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
      50             : 
      51       11779 :         if (ret < 0) {
      52           0 :                 return ret;
      53             :         }
      54             : 
      55       11779 :         data = talloc_zero(handle->conn, struct dfs_samba4_handle_data);
      56       11779 :         if (!data) {
      57           0 :                 DEBUG(0, ("talloc_zero() failed\n"));
      58           0 :                 SMB_VFS_NEXT_DISCONNECT(handle);
      59           0 :                 return -1;
      60             :         }
      61             : 
      62       11779 :         data->ev = s4_event_context_init(data);
      63       11779 :         if (!data->ev) {
      64           0 :                 DEBUG(0, ("s4_event_context_init failed\n"));
      65           0 :                 SMB_VFS_NEXT_DISCONNECT(handle);
      66           0 :                 return -1;
      67             :         }
      68             : 
      69       11779 :         data->lp_ctx = loadparm_init_s3(data, loadparm_s3_helpers());
      70       11779 :         if (data->lp_ctx == NULL) {
      71           0 :                 DEBUG(0, ("loadparm_init_s3 failed\n"));
      72           0 :                 SMB_VFS_NEXT_DISCONNECT(handle);
      73           0 :                 return -1;
      74             :         }
      75             : 
      76       11779 :         data->sam_ctx = samdb_connect(data,
      77             :                                       data->ev,
      78             :                                       data->lp_ctx,
      79             :                                       system_session(data->lp_ctx),
      80             :                                       NULL,
      81             :                                       0);
      82       11779 :         if (!data->sam_ctx) {
      83           0 :                 DEBUG(0, ("samdb_connect failed\n"));
      84           0 :                 SMB_VFS_NEXT_DISCONNECT(handle);
      85           0 :                 return -1;
      86             :         }
      87             : 
      88       11779 :         SMB_VFS_HANDLE_SET_DATA(handle, data, NULL,
      89             :                                 struct dfs_samba4_handle_data,
      90             :                                 return -1);
      91             : 
      92       11779 :         DEBUG(10,("dfs_samba4: connect to service[%s]\n",
      93             :                   service));
      94             : 
      95       11160 :         return 0;
      96             : }
      97             : 
      98       11779 : static void dfs_samba4_disconnect(struct vfs_handle_struct *handle)
      99             : {
     100        7718 :         const struct loadparm_substitution *lp_sub =
     101        4061 :                 loadparm_s3_global_substitution();
     102             : 
     103       11779 :         DEBUG(10,("dfs_samba4_disconnect() connect to service[%s].\n",
     104             :                   lp_servicename(talloc_tos(), lp_sub, SNUM(handle->conn))));
     105             : 
     106       11779 :         SMB_VFS_NEXT_DISCONNECT(handle);
     107       11779 : }
     108             : 
     109         290 : static NTSTATUS dfs_samba4_get_referrals(struct vfs_handle_struct *handle,
     110             :                                          struct dfs_GetDFSReferral *r)
     111             : {
     112             :         struct dfs_samba4_handle_data *data;
     113             :         NTSTATUS status;
     114             : 
     115         290 :         SMB_VFS_HANDLE_GET_DATA(handle, data,
     116             :                                 struct dfs_samba4_handle_data,
     117             :                                 return NT_STATUS_INTERNAL_ERROR);
     118             : 
     119         290 :         DEBUG(8, ("dfs_samba4: Requested DFS name: %s utf16-length: %u\n",
     120             :                    r->in.req.servername,
     121             :                    (unsigned int)strlen_m(r->in.req.servername)*2));
     122             : 
     123         290 :         status = dfs_server_ad_get_referrals(data->lp_ctx,
     124             :                                              data->sam_ctx,
     125         290 :                                              handle->conn->sconn->remote_address,
     126             :                                              r);
     127         290 :         if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
     128         258 :                 return SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
     129             :         }
     130          32 :         if (!NT_STATUS_IS_OK(status)) {
     131           4 :                 return status;
     132             :         }
     133             : 
     134          28 :         return NT_STATUS_OK;
     135             : }
     136             : 
     137             : static struct vfs_fn_pointers vfs_dfs_samba4_fns = {
     138             :         .connect_fn = dfs_samba4_connect,
     139             :         .disconnect_fn = dfs_samba4_disconnect,
     140             :         .get_dfs_referrals_fn = dfs_samba4_get_referrals,
     141             : };
     142             : 
     143             : static_decl_vfs;
     144        8917 : NTSTATUS vfs_dfs_samba4_init(TALLOC_CTX *ctx)
     145             : {
     146             :         NTSTATUS ret;
     147             : 
     148        8917 :         ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "dfs_samba4",
     149             :                                &vfs_dfs_samba4_fns);
     150        8917 :         if (!NT_STATUS_IS_OK(ret)) {
     151           0 :                 return ret;
     152             :         }
     153             : 
     154        8917 :         vfs_dfs_samba4_debug_level = debug_add_class("dfs_samba4");
     155        8917 :         if (vfs_dfs_samba4_debug_level == -1) {
     156           0 :                 vfs_dfs_samba4_debug_level = DBGC_VFS;
     157           0 :                 DEBUG(0, ("vfs_dfs_samba4: Couldn't register custom debugging class!\n"));
     158             :         } else {
     159        8917 :                 DEBUG(10, ("vfs_dfs_samba4: Debug class number of 'fileid': %d\n",
     160             :                       vfs_dfs_samba4_debug_level));
     161             :         }
     162             : 
     163        8917 :         return ret;
     164             : }

Generated by: LCOV version 1.13