s4:kdc: Implement KDC plugin hardware authentication policy
[samba.git] / source3 / modules / vfs_gpfs.c
index 93748eab54c01a86428e46b1ff94142c36f930b8..a8b4e38ff88c00c61285258f92c4f4a67de152a2 100644 (file)
@@ -1446,7 +1446,7 @@ static NTSTATUS vfs_gpfs_fget_dos_attributes(struct vfs_handle_struct *handle,
 {
        struct gpfs_config_data *config;
        int fd = fsp_get_pathref_fd(fsp);
-       char buf[PATH_MAX];
+       struct sys_proc_fd_path_buf buf;
        const char *p = NULL;
        struct gpfs_iattr64 iattr = { };
        unsigned int litemask = 0;
@@ -1463,10 +1463,7 @@ static NTSTATUS vfs_gpfs_fget_dos_attributes(struct vfs_handle_struct *handle,
 
        if (fsp->fsp_flags.is_pathref && !config->pathref_ok.gpfs_fstat_x) {
                if (fsp->fsp_flags.have_proc_fds) {
-                       p = sys_proc_fd_path(fd, buf, sizeof(buf));
-                       if (p == NULL) {
-                               return NT_STATUS_NO_MEMORY;
-                       }
+                       p = sys_proc_fd_path(fd, &buf);
                } else {
                        p = fsp->fsp_name->base_name;
                }
@@ -1560,20 +1557,17 @@ static NTSTATUS vfs_gpfs_fset_dos_attributes(struct vfs_handle_struct *handle,
 
        if (fsp->fsp_flags.have_proc_fds) {
                int fd = fsp_get_pathref_fd(fsp);
-               const char *p = NULL;
-               char buf[PATH_MAX];
-
-               p = sys_proc_fd_path(fd, buf, sizeof(buf));
-               if (p == NULL) {
-                       return NT_STATUS_NO_MEMORY;
-               }
+               struct sys_proc_fd_path_buf buf;
 
-               ret = gpfswrap_set_winattrs_path(p,
+               ret = gpfswrap_set_winattrs_path(sys_proc_fd_path(fd, &buf),
                                                 GPFS_WINATTR_SET_ATTRS,
                                                 &attrs);
                if (ret == -1) {
-                       DBG_WARNING("Setting winattrs failed for [%s][%s]: %s\n",
-                                   p, fsp_str_dbg(fsp), strerror(errno));
+                       DBG_WARNING("Setting winattrs failed for "
+                                   "[%s][%s]: %s\n",
+                                   buf.buf,
+                                   fsp_str_dbg(fsp),
+                                   strerror(errno));
                        return map_nt_error_from_unix(errno);
                }
                return NT_STATUS_OK;
@@ -1594,76 +1588,6 @@ static NTSTATUS vfs_gpfs_fset_dos_attributes(struct vfs_handle_struct *handle,
        return NT_STATUS_OK;
 }
 
-static int stat_with_capability(struct vfs_handle_struct *handle,
-                               struct smb_filename *smb_fname, int flag)
-{
-       bool fake_dctime = lp_fake_directory_create_times(SNUM(handle->conn));
-       int fd = -1;
-       NTSTATUS status;
-       struct smb_filename *dir_name = NULL;
-       struct smb_filename *rel_name = NULL;
-       int ret = -1;
-
-       status = SMB_VFS_PARENT_PATHNAME(handle->conn,
-                                        talloc_tos(),
-                                        smb_fname,
-                                        &dir_name,
-                                        &rel_name);
-       if (!NT_STATUS_IS_OK(status)) {
-               errno = map_errno_from_nt_status(status);
-               return -1;
-       }
-
-       fd = open(dir_name->base_name, O_RDONLY, 0);
-       if (fd == -1) {
-               TALLOC_FREE(dir_name);
-               return -1;
-       }
-
-       set_effective_capability(DAC_OVERRIDE_CAPABILITY);
-       ret = sys_fstatat(fd,
-                               rel_name->base_name,
-                               &smb_fname->st,
-                               flag,
-                               fake_dctime);
-
-       drop_effective_capability(DAC_OVERRIDE_CAPABILITY);
-
-       TALLOC_FREE(dir_name);
-       close(fd);
-
-       return ret;
-}
-
-static int vfs_gpfs_stat(struct vfs_handle_struct *handle,
-                        struct smb_filename *smb_fname)
-{
-       int ret;
-
-       ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
-       if (ret == -1 && errno == EACCES) {
-               DEBUG(10, ("Trying stat with capability for %s\n",
-                          smb_fname->base_name));
-               ret = stat_with_capability(handle, smb_fname, 0);
-       }
-       return ret;
-}
-
-static int vfs_gpfs_lstat(struct vfs_handle_struct *handle,
-                         struct smb_filename *smb_fname)
-{
-       int ret;
-
-       ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
-       if (ret == -1 && errno == EACCES) {
-               DEBUG(10, ("Trying lstat with capability for %s\n",
-                          smb_fname->base_name));
-               ret = stat_with_capability(handle, smb_fname,
-                                          AT_SYMLINK_NOFOLLOW);
-       }
-       return ret;
-}
-
 static int timespec_to_gpfs_time(
        struct timespec ts, gpfs_timestruc_t *gt, int idx, int *flags)
 {
@@ -1728,18 +1652,16 @@ static int smbd_gpfs_set_times(struct files_struct *fsp,
 
        if (fsp->fsp_flags.have_proc_fds) {
                int fd = fsp_get_pathref_fd(fsp);
-               const char *p = NULL;
-               char buf[PATH_MAX];
+               struct sys_proc_fd_path_buf buf;
 
-               p = sys_proc_fd_path(fd, buf, sizeof(buf));
-               if (p == NULL) {
-                       return -1;
-               }
-
-               rc = gpfswrap_set_times_path(buf, flags, gpfs_times);
+               rc = gpfswrap_set_times_path(sys_proc_fd_path(fd, &buf),
+                                            flags,
+                                            gpfs_times);
                if (rc != 0) {
                        DBG_WARNING("gpfs_set_times_path(%s,%s) failed: %s\n",
-                                   fsp_str_dbg(fsp), p, strerror(errno));
+                                   fsp_str_dbg(fsp),
+                                   buf.buf,
+                                   strerror(errno));
                }
                return rc;
        }
@@ -1784,7 +1706,7 @@ static int vfs_gpfs_fntimes(struct vfs_handle_struct *handle,
        if (ret == -1) {
                /* don't complain if access was denied */
                if (errno != EPERM && errno != EACCES) {
-                       DBG_WARNING("SMB_VFS_NEXT_FNTIMES failed: %s",
+                       DBG_WARNING("SMB_VFS_NEXT_FNTIMES failed: %s\n",
                                    strerror(errno));
                }
                return -1;
@@ -1816,17 +1738,12 @@ static int vfs_gpfs_fntimes(struct vfs_handle_struct *handle,
 
        if (fsp->fsp_flags.have_proc_fds) {
                int fd = fsp_get_pathref_fd(fsp);
-               const char *p = NULL;
-               char buf[PATH_MAX];
+               struct sys_proc_fd_path_buf buf;
 
-               p = sys_proc_fd_path(fd, buf, sizeof(buf));
-               if (p == NULL) {
-                       return -1;
-               }
-
-               ret = gpfswrap_set_winattrs_path(p,
-                                                GPFS_WINATTR_SET_CREATION_TIME,
-                                                &attrs);
+               ret = gpfswrap_set_winattrs_path(
+                       sys_proc_fd_path(fd, &buf),
+                       GPFS_WINATTR_SET_CREATION_TIME,
+                       &attrs);
                if (ret == -1 && errno != ENOSYS) {
                        DBG_WARNING("Set GPFS ntimes failed %d\n", ret);
                        return -1;
@@ -2041,7 +1958,18 @@ static int vfs_gpfs_connect(struct vfs_handle_struct *handle,
                return 0;
        }
 
-       gpfswrap_lib_init(0);
+       ret = gpfswrap_init();
+       if (ret < 0) {
+               DBG_ERR("Could not load GPFS library.\n");
+               return ret;
+       }
+
+       ret = gpfswrap_lib_init(0);
+       if (ret < 0) {
+               DBG_ERR("Could not open GPFS device file: %s\n",
+                       strerror(errno));
+               return ret;
+       }
 
        ret = gpfswrap_register_cifs_export();
        if (ret < 0) {
@@ -2592,8 +2520,10 @@ static struct vfs_fn_pointers vfs_gpfs_fns = {
        .sys_acl_delete_def_fd_fn = gpfsacl_sys_acl_delete_def_fd,
        .fchmod_fn = vfs_gpfs_fchmod,
        .close_fn = vfs_gpfs_close,
-       .stat_fn = vfs_gpfs_stat,
-       .lstat_fn = vfs_gpfs_lstat,
+       .stat_fn = nfs4_acl_stat,
+       .fstat_fn = nfs4_acl_fstat,
+       .lstat_fn = nfs4_acl_lstat,
+       .fstatat_fn = nfs4_acl_fstatat,
        .fntimes_fn = vfs_gpfs_fntimes,
        .aio_force_fn = vfs_gpfs_aio_force,
        .sendfile_fn = vfs_gpfs_sendfile,
@@ -2611,13 +2541,6 @@ static struct vfs_fn_pointers vfs_gpfs_fns = {
 static_decl_vfs;
 NTSTATUS vfs_gpfs_init(TALLOC_CTX *ctx)
 {
-       int ret;
-
-       ret = gpfswrap_init();
-       if (ret != 0) {
-               DEBUG(1, ("Could not initialize GPFS library wrapper\n"));
-       }
-
        return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "gpfs",
                                &vfs_gpfs_fns);
 }