LCOV - code coverage report
Current view: top level - source3/modules - vfs_dfs_samba4.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 40 59 67.8 %
Date: 2024-04-21 15:09:00 Functions: 4 4 100.0 %

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

Generated by: LCOV version 1.14