s3-vfs: Use the system. namespace for fake ACLs
[kai/samba.git] / source3 / modules / vfs_fileid.c
index 5954a10ddb71fa0724b49430ec0220d6d5fc9f35..25048e767de233e671c75ebcf140d10233dab13a 100644 (file)
@@ -20,6 +20,8 @@
  */
 
 #include "includes.h"
+#include "smbd/smbd.h"
+#include "system/filesys.h"
 
 static int vfs_fileid_debug_level = DBGC_VFS;
 
@@ -64,7 +66,7 @@ static void fileid_load_mount_entries(struct fileid_handle_data *data)
                        m->mnt_fsname += 5;
                }
 
-               data->mount_entries = TALLOC_REALLOC_ARRAY(data,
+               data->mount_entries = talloc_realloc(data,
                                                           data->mount_entries,
                                                           struct fileid_mount_entry,
                                                           data->num_mount_entries+1);
@@ -142,7 +144,7 @@ static uint64_t fileid_device_mapping_fsname(struct fileid_handle_data *data,
        if (!m) return dev;
 
        if (m->devid == (uint64_t)-1) {
-               m->devid = fileid_uint64_hash((uint8_t *)m->mnt_fsname,
+               m->devid = fileid_uint64_hash((const uint8_t *)m->mnt_fsname,
                                              strlen(m->mnt_fsname));
        }
 
@@ -181,22 +183,35 @@ static int fileid_connect(struct vfs_handle_struct *handle,
 {
        struct fileid_handle_data *data;
        const char *algorithm;
+       int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
 
-       data = talloc_zero(handle->conn->mem_ctx, struct fileid_handle_data);
+       if (ret < 0) {
+               return ret;
+       }
+
+       data = talloc_zero(handle->conn, struct fileid_handle_data);
        if (!data) {
+               SMB_VFS_NEXT_DISCONNECT(handle);
                DEBUG(0, ("talloc_zero() failed\n"));
                return -1;
        }
 
-       data->device_mapping_fn = fileid_device_mapping_fsid;
+       /*
+        * "fileid:mapping" is only here as fallback for old setups
+        * "fileid:algorithm" is the option new setups should use
+        */
        algorithm = lp_parm_const_string(SNUM(handle->conn),
-                                        "fileid", "algorithm",
+                                        "fileid", "mapping",
                                         "fsname");
+       algorithm = lp_parm_const_string(SNUM(handle->conn),
+                                        "fileid", "algorithm",
+                                        algorithm);
        if (strcmp("fsname", algorithm) == 0) {
                data->device_mapping_fn = fileid_device_mapping_fsname;
        } else if (strcmp("fsid", algorithm) == 0) {
                data->device_mapping_fn = fileid_device_mapping_fsid;
        } else {
+               SMB_VFS_NEXT_DISCONNECT(handle);
                DEBUG(0,("fileid_connect(): unknown algorithm[%s]\n", algorithm));
                return -1;
        }
@@ -208,19 +223,19 @@ static int fileid_connect(struct vfs_handle_struct *handle,
        DEBUG(10, ("fileid_connect(): connect to service[%s] with algorithm[%s]\n",
                service, algorithm));
 
-       return SMB_VFS_NEXT_CONNECT(handle, service, user);
+       return 0;
 }
 
 static void fileid_disconnect(struct vfs_handle_struct *handle)
 {
        DEBUG(10,("fileid_disconnect() connect to service[%s].\n",
-               lp_servicename(SNUM(handle->conn))));
+                 lp_servicename(talloc_tos(), SNUM(handle->conn))));
 
        SMB_VFS_NEXT_DISCONNECT(handle);
 }
 
 static struct file_id fileid_file_id_create(struct vfs_handle_struct *handle,
-                                           SMB_DEV_T dev, SMB_INO_T inode)
+                                           const SMB_STRUCT_STAT *sbuf)
 {
        struct fileid_handle_data *data;
        struct file_id id;
@@ -231,39 +246,16 @@ static struct file_id fileid_file_id_create(struct vfs_handle_struct *handle,
                                struct fileid_handle_data,
                                return id);
 
-       id.devid        = data->device_mapping_fn(data, dev);
-       id.inode        = inode;
+       id.devid        = data->device_mapping_fn(data, sbuf->st_ex_dev);
+       id.inode        = sbuf->st_ex_ino;
 
        return id;
 }
 
-static vfs_op_tuple fileid_ops[] = {
-
-       /* Disk operations */
-       {
-               SMB_VFS_OP(fileid_connect),
-               SMB_VFS_OP_CONNECT,
-               SMB_VFS_LAYER_TRANSPARENT
-       },
-       {
-               SMB_VFS_OP(fileid_disconnect),
-               SMB_VFS_OP_DISCONNECT,
-               SMB_VFS_LAYER_TRANSPARENT
-       },
-
-       /* File operations */
-       {
-               SMB_VFS_OP(fileid_file_id_create),
-               SMB_VFS_OP_FILE_ID_CREATE,
-               SMB_VFS_LAYER_OPAQUE
-       },
-
-       /* End marker */
-       {
-               SMB_VFS_OP(NULL),
-               SMB_VFS_OP_NOOP,
-               SMB_VFS_LAYER_NOOP
-       }
+static struct vfs_fn_pointers vfs_fileid_fns = {
+       .connect_fn = fileid_connect,
+       .disconnect_fn = fileid_disconnect,
+       .file_id_create_fn = fileid_file_id_create
 };
 
 NTSTATUS vfs_fileid_init(void);
@@ -271,7 +263,8 @@ NTSTATUS vfs_fileid_init(void)
 {
        NTSTATUS ret;
 
-       ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "fileid", fileid_ops);
+       ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "fileid",
+                              &vfs_fileid_fns);
        if (!NT_STATUS_IS_OK(ret)) {
                return ret;
        }