#include "librpc/gen_ndr/ndr_xattr.h"
#include "include/smbprofile.h"
#include "modules/non_posix_acls.h"
+#include "libcli/security/security.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_VFS
#include "auth.h"
#include "lib/util/tevent_unix.h"
+#ifndef GPFS_GETACL_NATIVE
+#define GPFS_GETACL_NATIVE 0x00000004
+#endif
+
struct gpfs_config_data {
bool sharemodes;
bool leases;
return &gacl->ace_v4[i];
}
+static bool set_gpfs_sharemode(files_struct *fsp, uint32 access_mask,
+ uint32 share_access)
+{
+ unsigned int allow = GPFS_SHARE_NONE;
+ unsigned int deny = GPFS_DENY_NONE;
+ int result;
+
+ if ((fsp == NULL) || (fsp->fh == NULL) || (fsp->fh->fd < 0)) {
+ /* No real file, don't disturb */
+ return True;
+ }
+
+ allow |= (access_mask & (FILE_WRITE_DATA|FILE_APPEND_DATA|
+ DELETE_ACCESS)) ? GPFS_SHARE_WRITE : 0;
+ allow |= (access_mask & (FILE_READ_DATA|FILE_EXECUTE)) ?
+ GPFS_SHARE_READ : 0;
+
+ if (allow == GPFS_SHARE_NONE) {
+ DEBUG(10, ("special case am=no_access:%x\n",access_mask));
+ }
+ else {
+ deny |= (share_access & FILE_SHARE_WRITE) ?
+ 0 : GPFS_DENY_WRITE;
+ deny |= (share_access & (FILE_SHARE_READ)) ?
+ 0 : GPFS_DENY_READ;
+ }
+ DEBUG(10, ("am=%x, allow=%d, sa=%x, deny=%d\n",
+ access_mask, allow, share_access, deny));
+
+ result = gpfswrap_set_share(fsp->fh->fd, allow, deny);
+ if (result != 0) {
+ if (errno == ENOSYS) {
+ DEBUG(5, ("VFS module vfs_gpfs loaded, but gpfs "
+ "set_share function support not available. "
+ "Allowing access\n"));
+ return True;
+ } else {
+ DEBUG(10, ("gpfs_set_share failed: %s\n",
+ strerror(errno)));
+ }
+ }
+
+ return (result == 0);
+}
+
static int vfs_gpfs_kernel_flock(vfs_handle_struct *handle, files_struct *fsp,
uint32 share_mode, uint32 access_mask)
{
return SMB_VFS_NEXT_CLOSE(handle, fsp);
}
+static int set_gpfs_lease(int fd, int leasetype)
+{
+ int gpfs_type = GPFS_LEASE_NONE;
+
+ if (leasetype == F_RDLCK) {
+ gpfs_type = GPFS_LEASE_READ;
+ }
+ if (leasetype == F_WRLCK) {
+ gpfs_type = GPFS_LEASE_WRITE;
+ }
+
+ /* we unconditionally set CAP_LEASE, rather than looking for
+ -1/EACCES as there is a bug in some versions of
+ libgpfs_gpl.so which results in a leaked fd on /dev/ss0
+ each time we try this with the wrong capabilities set
+ */
+ linux_set_lease_capability();
+ return gpfswrap_set_lease(fd, gpfs_type);
+}
+
static int vfs_gpfs_setlease(vfs_handle_struct *handle, files_struct *fsp,
int leasetype)
{
return 0;
}
+static void timespec_to_gpfs_time(struct timespec ts, gpfs_timestruc_t *gt,
+ int idx, int *flags)
+{
+ if (!null_timespec(ts)) {
+ *flags |= 1 << idx;
+ gt[idx].tv_sec = ts.tv_sec;
+ gt[idx].tv_nsec = ts.tv_nsec;
+ DEBUG(10, ("Setting GPFS time %d, flags 0x%x\n", idx, *flags));
+ }
+}
+
+static int smbd_gpfs_set_times_path(char *path, struct smb_file_time *ft)
+{
+ gpfs_timestruc_t gpfs_times[4];
+ int flags = 0;
+ int rc;
+
+ ZERO_ARRAY(gpfs_times);
+ timespec_to_gpfs_time(ft->atime, gpfs_times, 0, &flags);
+ timespec_to_gpfs_time(ft->mtime, gpfs_times, 1, &flags);
+ /* No good mapping from LastChangeTime to ctime, not storing */
+ timespec_to_gpfs_time(ft->create_time, gpfs_times, 3, &flags);
+
+ if (!flags) {
+ DEBUG(10, ("nothing to do, return to avoid EINVAL\n"));
+ return 0;
+ }
+
+ rc = gpfswrap_set_times_path(path, flags, gpfs_times);
+
+ if (rc != 0 && errno != ENOSYS) {
+ DEBUG(1,("gpfs_set_times() returned with error %s\n",
+ strerror(errno)));
+ }
+
+ return rc;
+}
+
static int vfs_gpfs_ntimes(struct vfs_handle_struct *handle,
const struct smb_filename *smb_fname,
struct smb_file_time *ft)
return -1;
}
- ret = smbd_gpfs_prealloc(fsp->fh->fd, offset, len);
+ ret = gpfswrap_prealloc(fsp->fh->fd, offset, len);
if (ret == -1 && errno != ENOSYS) {
DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno)));
return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
}
- result = smbd_gpfs_ftruncate(fsp->fh->fd, len);
+ result = gpfswrap_ftruncate(fsp->fh->fd, len);
if ((result == -1) && (errno == ENOSYS)) {
return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
}
struct gpfs_config_data *config;
int ret;
- smbd_gpfs_lib_init();
+ gpfswrap_lib_init(0);
config = talloc_zero(handle->conn, struct gpfs_config_data);
if (!config) {
return 0;
}
+static int get_gpfs_fset_id(const char *pathname, int *fset_id)
+{
+ int err, fd, errno_fcntl;
+
+ struct {
+ gpfsFcntlHeader_t hdr;
+ gpfsGetFilesetName_t fsn;
+ } arg;
+
+ arg.hdr.totalLength = sizeof(arg);
+ arg.hdr.fcntlVersion = GPFS_FCNTL_CURRENT_VERSION;
+ arg.hdr.fcntlReserved = 0;
+ arg.fsn.structLen = sizeof(arg.fsn);
+ arg.fsn.structType = GPFS_FCNTL_GET_FILESETNAME;
+
+ fd = open(pathname, O_RDONLY);
+ if (fd == -1) {
+ DEBUG(1, ("Could not open %s: %s\n",
+ pathname, strerror(errno)));
+ return fd;
+ }
+
+ err = gpfswrap_fcntl(fd, &arg);
+ errno_fcntl = errno;
+ close(fd);
+
+ if (err) {
+ errno = errno_fcntl;
+ if (errno != ENOSYS) {
+ DEBUG(1, ("GPFS_FCNTL_GET_FILESETNAME for %s failed: "
+ "%s\n", pathname, strerror(errno)));
+ }
+ return err;
+ }
+
+ err = gpfswrap_getfilesetid(discard_const_p(char, pathname),
+ arg.fsn.buffer, fset_id);
+ if (err && errno != ENOSYS) {
+ DEBUG(1, ("gpfs_getfilesetid for %s failed: %s\n",
+ pathname, strerror(errno)));
+ }
+ return err;
+}
+
+static int get_gpfs_quota(const char *pathname, int type, int id,
+ struct gpfs_quotaInfo *qi)
+{
+ int ret;
+
+ ZERO_STRUCTP(qi);
+ ret = gpfswrap_quotactl(discard_const_p(char, pathname),
+ GPFS_QCMD(Q_GETQUOTA, type), id, qi);
+
+ if (ret) {
+ if (errno == GPFS_E_NO_QUOTA_INST) {
+ DEBUG(10, ("Quotas disabled on GPFS filesystem.\n"));
+ } else if (errno != ENOSYS) {
+ DEBUG(0, ("Get quota failed, type %d, id, %d, "
+ "errno %d.\n", type, id, errno));
+ }
+
+ return ret;
+ }
+
+ DEBUG(10, ("quota type %d, id %d, blk u:%lld h:%lld s:%lld gt:%u\n",
+ type, id, qi->blockUsage, qi->blockHardLimit,
+ qi->blockSoftLimit, qi->blockGraceTime));
+
+ return ret;
+}
+
static int vfs_gpfs_get_quotas(const char *path, uid_t uid, gid_t gid,
int *fset_id,
struct gpfs_quotaInfo *qi_user,