Add vfs_ring.
[Samba.git] / source3 / modules / vfs_ring.c
blob325e57e9a3016574ffc283c17773f84e271186c2
1 /*
2 * VFS module implementing get_real_filename for Scality SOFS
4 * Copyright (C) 2016, Jean-Marc Saffroy <jm@scality.com>
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.
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.
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/>.
20 #include "includes.h"
21 #include "smbd/smbd.h"
23 #define DBG 10
25 #define GRFN_PREFIX "scal.grfn."
26 #define GRFN_PREFIX_LEN (sizeof(GRFN_PREFIX)-1)
28 static int vfs_ring_get_real_filename(struct vfs_handle_struct *handle,
29 const char *path,
30 const char *name,
31 TALLOC_CTX *mem_ctx,
32 char **found_name)
34 bool mangled;
35 char attr_name [NAME_MAX+1];
36 char attr_value[NAME_MAX+1];
37 int rc;
38 const struct smb_filename *smb_fname = NULL;
40 if (!strcmp(path, ""))
41 path = ".";
43 smb_fname = synthetic_smb_fname(talloc_tos(),
44 path,
45 NULL,
46 NULL,
47 0);
48 if (smb_fname == NULL) {
49 errno = ENOMEM;
50 return -1;
53 DEBUG(DBG, ("vfs_ring_get_real_filename: under \"%s\" lookup \"%s\"\n",
54 path, name));
56 mangled = mangle_is_mangled(name, handle->conn->params);
57 if (mangled) {
58 return SMB_VFS_NEXT_GET_REAL_FILENAME(
59 handle, path, name, mem_ctx, found_name);
62 if (strlen(name) > NAME_MAX - GRFN_PREFIX_LEN) {
63 errno = ENAMETOOLONG;
64 return -1;
67 strncpy(attr_name, GRFN_PREFIX, sizeof(attr_name));
68 strncpy(attr_name + GRFN_PREFIX_LEN, name,
69 sizeof(attr_name) - GRFN_PREFIX_LEN);
71 rc = SMB_VFS_NEXT_GETXATTR(handle, smb_fname, attr_name,
72 attr_value, sizeof(attr_value));
73 if (rc < 0) {
74 DEBUG(DBG, ("vfs_ring_get_real_filename: getxattr(\"%s\",\"%s\") -> %s\n",
75 path, name, strerror(errno)));
76 if (errno == EOPNOTSUPP)
77 return SMB_VFS_NEXT_GET_REAL_FILENAME(
78 handle, path, name, mem_ctx, found_name);
79 if (errno == ENOATTR)
80 errno = ENOENT;
81 return -1;
84 attr_value[rc] = 0;
85 *found_name = talloc_strdup(mem_ctx, attr_value);
86 if (*found_name == NULL) {
87 errno = ENOMEM;
88 return -1;
91 DEBUG(DBG, ("vfs_ring_get_real_filename: under \"%s\" found \"%s\" as \"%s\"\n",
92 path, name, *found_name));
94 return 0;
97 static struct vfs_fn_pointers vfs_ring_fns = {
98 .get_real_filename_fn = vfs_ring_get_real_filename,
101 NTSTATUS vfs_ring_init(TALLOC_CTX *);
102 NTSTATUS vfs_ring_init(TALLOC_CTX *ctx)
104 NTSTATUS ret;
106 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "ring",
107 &vfs_ring_fns);
108 if (!NT_STATUS_IS_OK(ret)) {
109 return ret;
112 return ret;