]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
vfs_error_inject: Add new module
authorChristof Schmitt <cs@samba.org>
Fri, 8 Dec 2017 22:29:07 +0000 (15:29 -0700)
committerKarolin Seeger <kseeger@samba.org>
Tue, 2 Jan 2018 09:01:10 +0000 (10:01 +0100)
This module allow injecting errors in vfs calls. It only implements one
case (return ESTALE from chdir), but the idea is to extend this to more
vfs functions and more errors when needed.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13189

Signed-off-by: Christof Schmitt <cs@samba.org>
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
(cherry picked from commit 24623d53256c2424563709dedc19af1a106ccc73)

source3/modules/vfs_error_inject.c [new file with mode: 0644]
source3/modules/wscript_build
source3/wscript

diff --git a/source3/modules/vfs_error_inject.c b/source3/modules/vfs_error_inject.c
new file mode 100644 (file)
index 0000000..3196a2f
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ *  Unix SMB/CIFS implementation.
+ *  Samba VFS module for error injection in VFS calls
+ *  Copyright (C) Christof Schmitt 2017
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "includes.h"
+#include "smbd/smbd.h"
+
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_VFS
+
+struct unix_error_map {
+       const char *err_str;
+       int error;
+} unix_error_map_array[] = {
+       {       "ESTALE",       ESTALE  },
+};
+
+static int find_unix_error_from_string(const char *err_str)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(unix_error_map_array); i++) {
+               struct unix_error_map *m = &unix_error_map_array[i];
+
+               if (strequal(err_str, m->err_str)) {
+                       return m->error;
+               }
+       }
+
+       return 0;
+}
+
+static int inject_unix_error(const char *vfs_func, vfs_handle_struct *handle)
+{
+       const char *err_str;
+
+       err_str = lp_parm_const_string(SNUM(handle->conn),
+                                      "error_inject", vfs_func, NULL);
+
+       if (err_str != NULL) {
+               int error;
+
+               error = find_unix_error_from_string(err_str);
+               if (error != 0) {
+                       DBG_WARNING("Returning error %s for VFS function %s\n",
+                                   err_str, vfs_func);
+                       return error;
+               }
+
+               if (strequal(err_str, "panic")) {
+                       DBG_ERR("Panic in VFS function %s\n", vfs_func);
+                       smb_panic("error_inject");
+               }
+
+               DBG_ERR("Unknown error inject %s requested "
+                       "for vfs function %s\n", err_str, vfs_func);
+       }
+
+       return 0;
+}
+
+static int vfs_error_inject_chdir(vfs_handle_struct *handle, const char *path)
+{
+       int error;
+
+       error = inject_unix_error("chdir", handle);
+       if (error != 0) {
+               errno = error;
+               return -1;
+       }
+
+       return SMB_VFS_NEXT_CHDIR(handle, path);
+}
+
+static struct vfs_fn_pointers vfs_error_inject_fns = {
+       .chdir_fn = vfs_error_inject_chdir,
+};
+
+static_decl_vfs;
+NTSTATUS vfs_error_inject_init(void)
+{
+       return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "error_inject",
+                               &vfs_error_inject_fns);
+}
index 86ff3eb69d68f6e26e3e7625c032dea6f80cb779..ae28d76cf43cc2c6313939977460083912ee1618 100644 (file)
@@ -505,3 +505,10 @@ bld.SAMBA3_MODULE('vfs_fake_dfq',
                  init_function='',
                  internal_module=bld.SAMBA3_IS_STATIC_MODULE('vfs_fake_dfq'),
                  enabled=bld.SAMBA3_IS_ENABLED_MODULE('vfs_fake_dfq'))
+
+bld.SAMBA3_MODULE('vfs_error_inject',
+                 subsystem='vfs',
+                 source='vfs_error_inject.c',
+                 init_function='',
+                 internal_module=bld.SAMBA3_IS_STATIC_MODULE('vfs_error_inject'),
+                 enabled=bld.SAMBA3_IS_ENABLED_MODULE('vfs_error_inject'))
index b705406bb6e914fa2095d905d1643f99a85bfc79..33eb599ebf363a7536ce9428580acedb985edc59 100644 (file)
@@ -1694,6 +1694,7 @@ main() {
 
     if Options.options.enable_selftest or Options.options.developer:
         default_shared_modules.extend(TO_LIST('vfs_fake_acls vfs_nfs4acl_xattr'))
+        default_shared_modules.extend(TO_LIST('vfs_error_inject'))
 
     if conf.CONFIG_SET('AD_DC_BUILD_IS_ENABLED'):
         default_static_modules.extend(TO_LIST('pdb_samba_dsdb auth_samba4 vfs_dfs_samba4'))