2 * Unix SMB/CIFS implementation.
3 * Samba VFS module for GPFS filesystem
4 * Copyright (C) Christian Ambach <cambach1@de.ibm.com> 2006
5 * Copyright (C) Christof Schmitt 2015
6 * Major code contributions by Chetan Shringarpure <chetan.sh@in.ibm.com>
7 * and Gomati Mohanan <gomati.mohanan@in.ibm.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, see <http://www.gnu.org/licenses/>.
24 #include "smbd/smbd.h"
25 #include "include/smbprofile.h"
26 #include "modules/non_posix_acls.h"
27 #include "libcli/security/security.h"
28 #include "nfs4_acls.h"
29 #include "system/filesys.h"
31 #include "lib/util/tevent_unix.h"
32 #include "lib/util/gpfswrap.h"
34 #include <gnutls/gnutls.h>
35 #include <gnutls/crypto.h>
36 #include "lib/crypto/gnutls_helpers.h"
39 #define DBGC_CLASS DBGC_VFS
41 #ifndef GPFS_GETACL_NATIVE
42 #define GPFS_GETACL_NATIVE 0x00000004
45 struct gpfs_config_data {
46 struct smbacl4_vfs_params nfs4_params;
60 struct gpfs_fsp_extension {
64 static inline unsigned int gpfs_acl_flags(gpfs_acl_t *gacl)
66 if (gacl->acl_level == GPFS_ACL_LEVEL_V4FLAGS) {
67 return gacl->v4Level1.acl_flags;
72 static inline gpfs_ace_v4_t *gpfs_ace_ptr(gpfs_acl_t *gacl, unsigned int i)
74 if (gacl->acl_level == GPFS_ACL_LEVEL_V4FLAGS) {
75 return &gacl->v4Level1.ace_v4[i];
77 return &gacl->ace_v4[i];
80 static bool set_gpfs_sharemode(files_struct *fsp, uint32_t access_mask,
81 uint32_t share_access)
83 unsigned int allow = GPFS_SHARE_NONE;
84 unsigned int deny = GPFS_DENY_NONE;
87 if ((fsp == NULL) || (fsp->fh == NULL) || (fsp->fh->fd < 0)) {
88 /* No real file, don't disturb */
92 allow |= (access_mask & (FILE_WRITE_DATA|FILE_APPEND_DATA)) ?
94 allow |= (access_mask & (FILE_READ_DATA|FILE_EXECUTE)) ?
97 if (allow == GPFS_SHARE_NONE) {
98 DEBUG(10, ("special case am=no_access:%x\n",access_mask));
101 deny |= (share_access & FILE_SHARE_WRITE) ?
103 deny |= (share_access & (FILE_SHARE_READ)) ?
107 * GPFS_DENY_DELETE can only be set together with either
108 * GPFS_DENY_WRITE or GPFS_DENY_READ.
110 if (deny & (GPFS_DENY_WRITE|GPFS_DENY_READ)) {
111 deny |= (share_access & (FILE_SHARE_DELETE)) ?
112 0 : GPFS_DENY_DELETE;
115 DEBUG(10, ("am=%x, allow=%d, sa=%x, deny=%d\n",
116 access_mask, allow, share_access, deny));
118 result = gpfswrap_set_share(fsp->fh->fd, allow, deny);
120 if (errno == ENOSYS) {
121 DEBUG(5, ("VFS module vfs_gpfs loaded, but gpfs "
122 "set_share function support not available. "
123 "Allowing access\n"));
126 DEBUG(10, ("gpfs_set_share failed: %s\n",
131 return (result == 0);
134 static int vfs_gpfs_kernel_flock(vfs_handle_struct *handle, files_struct *fsp,
135 uint32_t share_mode, uint32_t access_mask)
138 struct gpfs_config_data *config;
141 START_PROFILE(syscall_kernel_flock);
143 SMB_VFS_HANDLE_GET_DATA(handle, config,
144 struct gpfs_config_data,
147 if(!config->sharemodes) {
152 * A named stream fsp will have the basefile open in the fsp
153 * fd, so lacking a distinct fd for the stream we have to skip
154 * kernel_flock and set_gpfs_sharemode for stream.
156 if (is_named_stream(fsp->fsp_name)) {
157 DEBUG(2,("%s: kernel_flock on stream\n", fsp_str_dbg(fsp)));
161 kernel_flock(fsp->fh->fd, share_mode, access_mask);
163 if (!set_gpfs_sharemode(fsp, access_mask, share_mode)) {
167 END_PROFILE(syscall_kernel_flock);
172 static int vfs_gpfs_close(vfs_handle_struct *handle, files_struct *fsp)
175 struct gpfs_config_data *config;
177 SMB_VFS_HANDLE_GET_DATA(handle, config,
178 struct gpfs_config_data,
181 if (config->sharemodes && (fsp->fh != NULL) && (fsp->fh->fd != -1)) {
182 set_gpfs_sharemode(fsp, 0, 0);
185 return SMB_VFS_NEXT_CLOSE(handle, fsp);
188 static int set_gpfs_lease(int fd, int leasetype)
190 int gpfs_type = GPFS_LEASE_NONE;
192 if (leasetype == F_RDLCK) {
193 gpfs_type = GPFS_LEASE_READ;
195 if (leasetype == F_WRLCK) {
196 gpfs_type = GPFS_LEASE_WRITE;
199 /* we unconditionally set CAP_LEASE, rather than looking for
200 -1/EACCES as there is a bug in some versions of
201 libgpfs_gpl.so which results in a leaked fd on /dev/ss0
202 each time we try this with the wrong capabilities set
204 linux_set_lease_capability();
205 return gpfswrap_set_lease(fd, gpfs_type);
208 static int vfs_gpfs_setlease(vfs_handle_struct *handle, files_struct *fsp,
211 struct gpfs_config_data *config;
214 START_PROFILE(syscall_linux_setlease);
216 SMB_VFS_HANDLE_GET_DATA(handle, config,
217 struct gpfs_config_data,
220 if (linux_set_lease_sighandler(fsp->fh->fd) == -1) {
225 if (config->leases) {
227 * Ensure the lease owner is root to allow
228 * correct delivery of lease-break signals.
231 ret = set_gpfs_lease(fsp->fh->fd,leasetype);
236 END_PROFILE(syscall_linux_setlease);
241 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct *handle,
248 char *full_path = NULL;
249 char *to_free = NULL;
250 char real_pathname[PATH_MAX+1], tmpbuf[PATH_MAX];
251 size_t full_path_len;
254 struct gpfs_config_data *config;
256 SMB_VFS_HANDLE_GET_DATA(handle, config,
257 struct gpfs_config_data,
260 if (!config->getrealfilename) {
261 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
262 mem_ctx, found_name);
265 mangled = mangle_is_mangled(name, handle->conn->params);
267 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
268 mem_ctx, found_name);
271 full_path_len = full_path_tos(path, name, tmpbuf, sizeof(tmpbuf),
272 &full_path, &to_free);
273 if (full_path_len == -1) {
278 buflen = sizeof(real_pathname) - 1;
280 result = gpfswrap_get_realfilename_path(full_path, real_pathname,
283 TALLOC_FREE(to_free);
285 if ((result == -1) && (errno == ENOSYS)) {
286 return SMB_VFS_NEXT_GET_REAL_FILENAME(
287 handle, path, name, mem_ctx, found_name);
291 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
297 * GPFS does not necessarily null-terminate the returned path
298 * but instead returns the buffer length in buflen.
301 if (buflen < sizeof(real_pathname)) {
302 real_pathname[buflen] = '\0';
304 real_pathname[sizeof(real_pathname)-1] = '\0';
307 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
308 path, name, real_pathname));
310 name = strrchr_m(real_pathname, '/');
316 *found_name = talloc_strdup(mem_ctx, name+1);
317 if (*found_name == NULL) {
325 static void sd2gpfs_control(uint16_t control, struct gpfs_acl *gacl)
327 unsigned int gpfs_aclflags = 0;
328 control &= SEC_DESC_DACL_PROTECTED | SEC_DESC_SACL_PROTECTED |
329 SEC_DESC_DACL_AUTO_INHERITED | SEC_DESC_SACL_AUTO_INHERITED |
330 SEC_DESC_DACL_DEFAULTED | SEC_DESC_SACL_DEFAULTED |
331 SEC_DESC_DACL_PRESENT | SEC_DESC_SACL_PRESENT;
332 gpfs_aclflags = control << 8;
333 if (!(control & SEC_DESC_DACL_PRESENT))
334 gpfs_aclflags |= ACL4_FLAG_NULL_DACL;
335 if (!(control & SEC_DESC_SACL_PRESENT))
336 gpfs_aclflags |= ACL4_FLAG_NULL_SACL;
337 gacl->acl_level = GPFS_ACL_LEVEL_V4FLAGS;
338 gacl->v4Level1.acl_flags = gpfs_aclflags;
341 static uint16_t gpfs2sd_control(unsigned int gpfs_aclflags)
343 uint16_t control = gpfs_aclflags >> 8;
344 control &= SEC_DESC_DACL_PROTECTED | SEC_DESC_SACL_PROTECTED |
345 SEC_DESC_DACL_AUTO_INHERITED | SEC_DESC_SACL_AUTO_INHERITED |
346 SEC_DESC_DACL_DEFAULTED | SEC_DESC_SACL_DEFAULTED |
347 SEC_DESC_DACL_PRESENT | SEC_DESC_SACL_PRESENT;
348 control |= SEC_DESC_SELF_RELATIVE;
352 static void gpfs_dumpacl(int level, struct gpfs_acl *gacl)
357 DEBUG(0, ("gpfs acl is NULL\n"));
361 DEBUG(level, ("len: %d, level: %d, version: %d, nace: %d, "
363 gacl->acl_len, gacl->acl_level, gacl->acl_version,
364 gacl->acl_nace, gpfs_acl_flags(gacl)));
366 for(i=0; i<gacl->acl_nace; i++)
368 struct gpfs_ace_v4 *gace = gpfs_ace_ptr(gacl, i);
369 DEBUG(level, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, "
370 "iflags:0x%x, who:%u\n",
371 i, gace->aceType, gace->aceFlags, gace->aceMask,
372 gace->aceIFlags, gace->aceWho));
376 static int gpfs_getacl_with_capability(const char *fname, int flags, void *buf)
378 int ret, saved_errno;
380 set_effective_capability(DAC_OVERRIDE_CAPABILITY);
382 ret = gpfswrap_getacl(discard_const_p(char, fname), flags, buf);
385 drop_effective_capability(DAC_OVERRIDE_CAPABILITY);
392 * get the ACL from GPFS, allocated on the specified mem_ctx
393 * internally retries when initial buffer was too small
395 * caller needs to cast result to either
396 * raw = yes: struct gpfs_opaque_acl
397 * raw = no: struct gpfs_acl
400 static void *vfs_gpfs_getacl(TALLOC_CTX *mem_ctx,
403 const gpfs_aclType_t type)
411 bool use_capability = false;
415 aclbuf = talloc_zero_size(mem_ctx, size);
416 if (aclbuf == NULL) {
422 struct gpfs_opaque_acl *buf = (struct gpfs_opaque_acl *) aclbuf;
423 buf->acl_type = type;
424 flags = GPFS_GETACL_NATIVE;
425 len = (unsigned int *) &(buf->acl_buffer_len);
426 struct_size = sizeof(struct gpfs_opaque_acl);
428 struct gpfs_acl *buf = (struct gpfs_acl *) aclbuf;
429 buf->acl_type = type;
430 buf->acl_level = GPFS_ACL_LEVEL_V4FLAGS;
431 flags = GPFS_GETACL_STRUCT;
432 len = &(buf->acl_len);
433 /* reserve space for control flags in gpfs 3.5 and beyond */
434 struct_size = sizeof(struct gpfs_acl) + sizeof(unsigned int);
437 /* set the length of the buffer as input value */
440 if (use_capability) {
441 ret = gpfs_getacl_with_capability(fname, flags, aclbuf);
443 ret = gpfswrap_getacl(discard_const_p(char, fname),
445 if ((ret != 0) && (errno == EACCES)) {
446 DBG_DEBUG("Retry with DAC capability for %s\n", fname);
447 use_capability = true;
448 ret = gpfs_getacl_with_capability(fname, flags, aclbuf);
452 if ((ret != 0) && (errno == ENOSPC)) {
454 * get the size needed to accommodate the complete buffer
456 * the value returned only applies to the ACL blob in the
457 * struct so make sure to also have headroom for the first
458 * struct members by adding room for the complete struct
459 * (might be a few bytes too much then)
461 size = *len + struct_size;
463 DEBUG(10, ("Increasing ACL buffer size to %zu\n", size));
468 DEBUG(5, ("smbd_gpfs_getacl failed with %s\n",
477 /* Tries to get nfs4 acls and returns SMB ACL allocated.
478 * On failure returns 1 if it got non-NFSv4 ACL to prompt
479 * retry with POSIX ACL checks.
480 * On failure returns -1 if there is system (GPFS) error, check errno.
481 * Returns 0 on success
483 static int gpfs_get_nfs4_acl(TALLOC_CTX *mem_ctx, const char *fname,
484 struct SMB4ACL_T **ppacl)
487 struct gpfs_acl *gacl = NULL;
488 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname));
491 gacl = (struct gpfs_acl*) vfs_gpfs_getacl(talloc_tos(), fname,
494 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
495 fname, strerror(errno)));
496 if (errno == ENODATA) {
498 * GPFS returns ENODATA for snapshot
499 * directories. Retry with POSIX ACLs check.
507 if (gacl->acl_type != GPFS_ACL_TYPE_NFS4) {
508 DEBUG(10, ("Got non-nfsv4 acl\n"));
509 /* Retry with POSIX ACLs check */
514 *ppacl = smb_create_smb4acl(mem_ctx);
516 if (gacl->acl_level == GPFS_ACL_LEVEL_V4FLAGS) {
517 uint16_t control = gpfs2sd_control(gpfs_acl_flags(gacl));
518 smbacl4_set_controlflags(*ppacl, control);
521 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d, control: %x\n",
522 gacl->acl_len, gacl->acl_level, gacl->acl_version,
523 gacl->acl_nace, gpfs_acl_flags(gacl)));
525 for (i=0; i<gacl->acl_nace; i++) {
526 struct gpfs_ace_v4 *gace = gpfs_ace_ptr(gacl, i);
527 SMB_ACE4PROP_T smbace = { 0 };
528 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
529 "who: %d\n", gace->aceType, gace->aceIFlags,
530 gace->aceFlags, gace->aceMask, gace->aceWho));
532 if (gace->aceIFlags & ACE4_IFLAG_SPECIAL_ID) {
533 smbace.flags |= SMB_ACE4_ID_SPECIAL;
534 switch (gace->aceWho) {
535 case ACE4_SPECIAL_OWNER:
536 smbace.who.special_id = SMB_ACE4_WHO_OWNER;
538 case ACE4_SPECIAL_GROUP:
539 smbace.who.special_id = SMB_ACE4_WHO_GROUP;
541 case ACE4_SPECIAL_EVERYONE:
542 smbace.who.special_id = SMB_ACE4_WHO_EVERYONE;
545 DEBUG(8, ("invalid special gpfs id %d "
546 "ignored\n", gace->aceWho));
547 continue; /* don't add it */
550 if (gace->aceFlags & ACE4_FLAG_GROUP_ID)
551 smbace.who.gid = gace->aceWho;
553 smbace.who.uid = gace->aceWho;
556 /* remove redundant deny entries */
557 if (i > 0 && gace->aceType == SMB_ACE4_ACCESS_DENIED_ACE_TYPE) {
558 struct gpfs_ace_v4 *prev = gpfs_ace_ptr(gacl, i - 1);
559 if (prev->aceType == SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE &&
560 prev->aceFlags == gace->aceFlags &&
561 prev->aceIFlags == gace->aceIFlags &&
562 (gace->aceMask & prev->aceMask) == 0 &&
563 gace->aceWho == prev->aceWho) {
564 /* it's redundant - skip it */
569 smbace.aceType = gace->aceType;
570 smbace.aceFlags = gace->aceFlags;
571 smbace.aceMask = gace->aceMask;
572 smb_add_ace4(*ppacl, &smbace);
580 static NTSTATUS gpfsacl_fget_nt_acl(vfs_handle_struct *handle,
581 files_struct *fsp, uint32_t security_info,
583 struct security_descriptor **ppdesc)
585 struct SMB4ACL_T *pacl = NULL;
587 struct gpfs_config_data *config;
588 TALLOC_CTX *frame = talloc_stackframe();
593 SMB_VFS_HANDLE_GET_DATA(handle, config,
594 struct gpfs_config_data,
595 return NT_STATUS_INTERNAL_ERROR);
598 status = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
604 result = gpfs_get_nfs4_acl(frame, fsp->fsp_name->base_name, &pacl);
607 status = smb_fget_nt_acl_nfs4(fsp, &config->nfs4_params,
609 mem_ctx, ppdesc, pacl);
615 DEBUG(10, ("retrying with posix acl...\n"));
616 status = posix_fget_nt_acl(fsp, security_info,
624 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
625 return map_nt_error_from_unix(errno);
628 static NTSTATUS gpfsacl_get_nt_acl(vfs_handle_struct *handle,
629 const struct smb_filename *smb_fname,
630 uint32_t security_info,
632 struct security_descriptor **ppdesc)
634 struct SMB4ACL_T *pacl = NULL;
636 struct gpfs_config_data *config;
637 TALLOC_CTX *frame = talloc_stackframe();
642 SMB_VFS_HANDLE_GET_DATA(handle, config,
643 struct gpfs_config_data,
644 return NT_STATUS_INTERNAL_ERROR);
647 status = SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname,
654 result = gpfs_get_nfs4_acl(frame, smb_fname->base_name, &pacl);
657 status = smb_get_nt_acl_nfs4(handle->conn, smb_fname,
658 &config->nfs4_params,
659 security_info, mem_ctx, ppdesc,
666 DEBUG(10, ("retrying with posix acl...\n"));
667 status = posix_get_nt_acl(handle->conn, smb_fname,
668 security_info, mem_ctx, ppdesc);
673 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
675 return map_nt_error_from_unix(errno);
678 static bool vfs_gpfs_nfs4_ace_to_gpfs_ace(SMB_ACE4PROP_T *nfs4_ace,
679 struct gpfs_ace_v4 *gace,
682 gace->aceType = nfs4_ace->aceType;
683 gace->aceFlags = nfs4_ace->aceFlags;
684 gace->aceMask = nfs4_ace->aceMask;
686 if (nfs4_ace->flags & SMB_ACE4_ID_SPECIAL) {
687 switch(nfs4_ace->who.special_id) {
688 case SMB_ACE4_WHO_EVERYONE:
689 gace->aceIFlags = ACE4_IFLAG_SPECIAL_ID;
690 gace->aceWho = ACE4_SPECIAL_EVERYONE;
692 case SMB_ACE4_WHO_OWNER:
694 * With GPFS it is not possible to deny ACL or
695 * attribute access to the owner. Setting an
696 * ACL with such an entry is not possible.
697 * Denying ACL or attribute access for the
698 * owner through a named ACL entry can be
699 * stored in an ACL, it is just not effective.
701 * Map this case to a named entry to allow at
702 * least setting this ACL, which will be
703 * enforced by the smbd permission check. Do
704 * not do this for an inheriting OWNER entry,
705 * as this represents a CREATOR OWNER ACE. The
706 * remaining limitation is that CREATOR OWNER
707 * cannot deny ACL or attribute access.
709 if (!nfs_ace_is_inherit(nfs4_ace) &&
711 SMB_ACE4_ACCESS_DENIED_ACE_TYPE &&
712 nfs4_ace->aceMask & (SMB_ACE4_READ_ATTRIBUTES|
713 SMB_ACE4_WRITE_ATTRIBUTES|
715 SMB_ACE4_WRITE_ACL)) {
717 gace->aceWho = owner_uid;
719 gace->aceIFlags = ACE4_IFLAG_SPECIAL_ID;
720 gace->aceWho = ACE4_SPECIAL_OWNER;
723 case SMB_ACE4_WHO_GROUP:
724 gace->aceIFlags = ACE4_IFLAG_SPECIAL_ID;
725 gace->aceWho = ACE4_SPECIAL_GROUP;
728 DBG_WARNING("Unsupported special_id %d\n",
729 nfs4_ace->who.special_id);
737 gace->aceWho = (nfs4_ace->aceFlags & SMB_ACE4_IDENTIFIER_GROUP) ?
738 nfs4_ace->who.gid : nfs4_ace->who.uid;
743 static struct gpfs_acl *vfs_gpfs_smbacl2gpfsacl(TALLOC_CTX *mem_ctx,
745 struct SMB4ACL_T *smbacl,
748 struct gpfs_acl *gacl;
749 gpfs_aclLen_t gacl_len;
750 struct SMB4ACE_T *smbace;
752 gacl_len = offsetof(gpfs_acl_t, ace_v4) + sizeof(unsigned int)
753 + smb_get_naces(smbacl) * sizeof(gpfs_ace_v4_t);
755 gacl = (struct gpfs_acl *)TALLOC_SIZE(mem_ctx, gacl_len);
757 DEBUG(0, ("talloc failed\n"));
762 gacl->acl_level = GPFS_ACL_LEVEL_BASE;
763 gacl->acl_version = GPFS_ACL_VERSION_NFS4;
764 gacl->acl_type = GPFS_ACL_TYPE_NFS4;
765 gacl->acl_nace = 0; /* change later... */
768 gacl->acl_level = GPFS_ACL_LEVEL_V4FLAGS;
769 sd2gpfs_control(smbacl4_get_controlflags(smbacl), gacl);
772 for (smbace=smb_first_ace4(smbacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
773 struct gpfs_ace_v4 *gace = gpfs_ace_ptr(gacl, gacl->acl_nace);
774 SMB_ACE4PROP_T *aceprop = smb_get_ace4(smbace);
777 add_ace = vfs_gpfs_nfs4_ace_to_gpfs_ace(aceprop, gace,
778 fsp->fsp_name->st.st_ex_uid);
785 gacl->acl_len = (char *)gpfs_ace_ptr(gacl, gacl->acl_nace)
790 static bool gpfsacl_process_smbacl(vfs_handle_struct *handle,
792 struct SMB4ACL_T *smbacl)
795 struct gpfs_acl *gacl;
796 TALLOC_CTX *mem_ctx = talloc_tos();
798 gacl = vfs_gpfs_smbacl2gpfsacl(mem_ctx, fsp, smbacl, true);
799 if (gacl == NULL) { /* out of memory */
802 ret = gpfswrap_putacl(fsp->fsp_name->base_name,
803 GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gacl);
805 if ((ret != 0) && (errno == EINVAL)) {
806 DEBUG(10, ("Retry without nfs41 control flags\n"));
808 gacl = vfs_gpfs_smbacl2gpfsacl(mem_ctx, fsp, smbacl, false);
809 if (gacl == NULL) { /* out of memory */
812 ret = gpfswrap_putacl(fsp->fsp_name->base_name,
813 GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA,
818 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno)));
819 gpfs_dumpacl(8, gacl);
823 DEBUG(10, ("gpfs_putacl succeeded\n"));
827 static NTSTATUS gpfsacl_set_nt_acl_internal(vfs_handle_struct *handle, files_struct *fsp, uint32_t security_info_sent, const struct security_descriptor *psd)
829 struct gpfs_acl *acl;
830 NTSTATUS result = NT_STATUS_ACCESS_DENIED;
832 acl = (struct gpfs_acl*) vfs_gpfs_getacl(talloc_tos(),
833 fsp->fsp_name->base_name,
836 return map_nt_error_from_unix(errno);
839 if (acl->acl_version == GPFS_ACL_VERSION_NFS4) {
840 struct gpfs_config_data *config;
842 if (lp_parm_bool(fsp->conn->params->service, "gpfs",
843 "refuse_dacl_protected", false)
844 && (psd->type&SEC_DESC_DACL_PROTECTED)) {
845 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
847 return NT_STATUS_NOT_SUPPORTED;
850 SMB_VFS_HANDLE_GET_DATA(handle, config,
851 struct gpfs_config_data,
852 return NT_STATUS_INTERNAL_ERROR);
854 result = smb_set_nt_acl_nfs4(handle,
855 fsp, &config->nfs4_params, security_info_sent, psd,
856 gpfsacl_process_smbacl);
857 } else { /* assume POSIX ACL - by default... */
858 result = set_nt_acl(fsp, security_info_sent, psd);
865 static NTSTATUS gpfsacl_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32_t security_info_sent, const struct security_descriptor *psd)
867 struct gpfs_config_data *config;
869 SMB_VFS_HANDLE_GET_DATA(handle, config,
870 struct gpfs_config_data,
871 return NT_STATUS_INTERNAL_ERROR);
874 return SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
877 return gpfsacl_set_nt_acl_internal(handle, fsp, security_info_sent, psd);
880 static SMB_ACL_T gpfs2smb_acl(const struct gpfs_acl *pacl, TALLOC_CTX *mem_ctx)
885 result = sys_acl_init(mem_ctx);
886 if (result == NULL) {
891 result->count = pacl->acl_nace;
892 result->acl = talloc_realloc(result, result->acl, struct smb_acl_entry,
894 if (result->acl == NULL) {
900 for (i=0; i<pacl->acl_nace; i++) {
901 struct smb_acl_entry *ace = &result->acl[i];
902 const struct gpfs_ace_v1 *g_ace = &pacl->ace_v1[i];
904 DEBUG(10, ("Converting type %d id %lu perm %x\n",
905 (int)g_ace->ace_type, (unsigned long)g_ace->ace_who,
906 (int)g_ace->ace_perm));
908 switch (g_ace->ace_type) {
910 ace->a_type = SMB_ACL_USER;
911 ace->info.user.uid = (uid_t)g_ace->ace_who;
913 case GPFS_ACL_USER_OBJ:
914 ace->a_type = SMB_ACL_USER_OBJ;
917 ace->a_type = SMB_ACL_GROUP;
918 ace->info.group.gid = (gid_t)g_ace->ace_who;
920 case GPFS_ACL_GROUP_OBJ:
921 ace->a_type = SMB_ACL_GROUP_OBJ;
924 ace->a_type = SMB_ACL_OTHER;
927 ace->a_type = SMB_ACL_MASK;
930 DEBUG(10, ("Got invalid ace_type: %d\n",
938 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_READ) ?
940 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_WRITE) ?
942 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_EXECUTE) ?
945 DEBUGADD(10, ("Converted to %d perm %x\n",
946 ace->a_type, ace->a_perm));
952 static SMB_ACL_T gpfsacl_get_posix_acl(const char *path, gpfs_aclType_t type,
955 struct gpfs_acl *pacl;
956 SMB_ACL_T result = NULL;
958 pacl = vfs_gpfs_getacl(talloc_tos(), path, false, type);
961 DEBUG(10, ("vfs_gpfs_getacl failed for %s with %s\n",
962 path, strerror(errno)));
969 if (pacl->acl_version != GPFS_ACL_VERSION_POSIX) {
970 DEBUG(10, ("Got acl version %d, expected %d\n",
971 pacl->acl_version, GPFS_ACL_VERSION_POSIX));
976 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
977 pacl->acl_len, pacl->acl_level, pacl->acl_version,
980 result = gpfs2smb_acl(pacl, mem_ctx);
981 if (result != NULL) {
996 static SMB_ACL_T gpfsacl_sys_acl_get_file(vfs_handle_struct *handle,
997 const struct smb_filename *smb_fname,
1001 gpfs_aclType_t gpfs_type;
1002 struct gpfs_config_data *config;
1004 SMB_VFS_HANDLE_GET_DATA(handle, config,
1005 struct gpfs_config_data,
1009 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, smb_fname,
1014 case SMB_ACL_TYPE_ACCESS:
1015 gpfs_type = GPFS_ACL_TYPE_ACCESS;
1017 case SMB_ACL_TYPE_DEFAULT:
1018 gpfs_type = GPFS_ACL_TYPE_DEFAULT;
1021 DEBUG(0, ("Got invalid type: %d\n", type));
1022 smb_panic("exiting");
1025 return gpfsacl_get_posix_acl(smb_fname->base_name, gpfs_type, mem_ctx);
1028 static SMB_ACL_T gpfsacl_sys_acl_get_fd(vfs_handle_struct *handle,
1030 TALLOC_CTX *mem_ctx)
1032 struct gpfs_config_data *config;
1034 SMB_VFS_HANDLE_GET_DATA(handle, config,
1035 struct gpfs_config_data,
1039 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
1042 return gpfsacl_get_posix_acl(fsp->fsp_name->base_name,
1043 GPFS_ACL_TYPE_ACCESS, mem_ctx);
1046 static int gpfsacl_sys_acl_blob_get_file(vfs_handle_struct *handle,
1047 const struct smb_filename *smb_fname,
1048 TALLOC_CTX *mem_ctx,
1049 char **blob_description,
1052 struct gpfs_config_data *config;
1053 struct gpfs_opaque_acl *acl = NULL;
1056 const char *path_p = smb_fname->base_name;
1058 SMB_VFS_HANDLE_GET_DATA(handle, config,
1059 struct gpfs_config_data,
1063 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, smb_fname,
1070 acl = (struct gpfs_opaque_acl *)
1071 vfs_gpfs_getacl(mem_ctx,
1074 GPFS_ACL_TYPE_NFS4);
1077 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
1078 errno, strerror(errno)));
1080 /* EINVAL means POSIX ACL, bail out on other cases */
1081 if (errno != EINVAL) {
1088 * file has NFSv4 ACL
1090 * we only need the actual ACL blob here
1091 * acl_version will always be NFS4 because we asked
1093 * acl_type is only used for POSIX ACLs
1095 aclblob.data = (uint8_t*) acl->acl_var_data;
1096 aclblob.length = acl->acl_buffer_len;
1098 *blob_description = talloc_strdup(mem_ctx, "gpfs_nfs4_acl");
1099 if (!*blob_description) {
1105 result = non_posix_sys_acl_blob_get_file_helper(handle, smb_fname,
1113 /* fall back to POSIX ACL */
1114 return posix_sys_acl_blob_get_file(handle, smb_fname, mem_ctx,
1115 blob_description, blob);
1118 static int gpfsacl_sys_acl_blob_get_fd(vfs_handle_struct *handle,
1120 TALLOC_CTX *mem_ctx,
1121 char **blob_description,
1124 struct gpfs_config_data *config;
1125 struct gpfs_opaque_acl *acl = NULL;
1129 SMB_VFS_HANDLE_GET_DATA(handle, config,
1130 struct gpfs_config_data,
1134 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx,
1135 blob_description, blob);
1139 acl = (struct gpfs_opaque_acl *) vfs_gpfs_getacl(mem_ctx,
1140 fsp->fsp_name->base_name,
1142 GPFS_ACL_TYPE_NFS4);
1145 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
1146 errno, strerror(errno)));
1148 /* EINVAL means POSIX ACL, bail out on other cases */
1149 if (errno != EINVAL) {
1156 * file has NFSv4 ACL
1158 * we only need the actual ACL blob here
1159 * acl_version will always be NFS4 because we asked
1161 * acl_type is only used for POSIX ACLs
1163 aclblob.data = (uint8_t*) acl->acl_var_data;
1164 aclblob.length = acl->acl_buffer_len;
1166 *blob_description = talloc_strdup(mem_ctx, "gpfs_nfs4_acl");
1167 if (!*blob_description) {
1173 result = non_posix_sys_acl_blob_get_fd_helper(handle, fsp,
1181 /* fall back to POSIX ACL */
1182 return posix_sys_acl_blob_get_fd(handle, fsp, mem_ctx,
1183 blob_description, blob);
1186 static struct gpfs_acl *smb2gpfs_acl(const SMB_ACL_T pacl,
1187 SMB_ACL_TYPE_T type)
1190 struct gpfs_acl *result;
1193 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl->count));
1195 len = offsetof(gpfs_acl_t, ace_v1) + (pacl->count) *
1196 sizeof(gpfs_ace_v1_t);
1198 result = (struct gpfs_acl *)SMB_MALLOC(len);
1199 if (result == NULL) {
1204 result->acl_len = len;
1205 result->acl_level = 0;
1206 result->acl_version = GPFS_ACL_VERSION_POSIX;
1207 result->acl_type = (type == SMB_ACL_TYPE_DEFAULT) ?
1208 GPFS_ACL_TYPE_DEFAULT : GPFS_ACL_TYPE_ACCESS;
1209 result->acl_nace = pacl->count;
1211 for (i=0; i<pacl->count; i++) {
1212 const struct smb_acl_entry *ace = &pacl->acl[i];
1213 struct gpfs_ace_v1 *g_ace = &result->ace_v1[i];
1215 DEBUG(10, ("Converting type %d perm %x\n",
1216 (int)ace->a_type, (int)ace->a_perm));
1218 g_ace->ace_perm = 0;
1220 switch(ace->a_type) {
1222 g_ace->ace_type = GPFS_ACL_USER;
1223 g_ace->ace_who = (gpfs_uid_t)ace->info.user.uid;
1225 case SMB_ACL_USER_OBJ:
1226 g_ace->ace_type = GPFS_ACL_USER_OBJ;
1227 g_ace->ace_perm |= ACL_PERM_CONTROL;
1231 g_ace->ace_type = GPFS_ACL_GROUP;
1232 g_ace->ace_who = (gpfs_uid_t)ace->info.group.gid;
1234 case SMB_ACL_GROUP_OBJ:
1235 g_ace->ace_type = GPFS_ACL_GROUP_OBJ;
1239 g_ace->ace_type = GPFS_ACL_MASK;
1240 g_ace->ace_perm = 0x8f;
1244 g_ace->ace_type = GPFS_ACL_OTHER;
1248 DEBUG(10, ("Got invalid ace_type: %d\n", ace->a_type));
1254 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_READ) ?
1256 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_WRITE) ?
1258 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_EXECUTE) ?
1259 ACL_PERM_EXECUTE : 0;
1261 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
1262 g_ace->ace_type, g_ace->ace_who, g_ace->ace_perm));
1268 static int gpfsacl_sys_acl_set_file(vfs_handle_struct *handle,
1269 const struct smb_filename *smb_fname,
1270 SMB_ACL_TYPE_T type,
1273 struct gpfs_acl *gpfs_acl;
1275 struct gpfs_config_data *config;
1277 SMB_VFS_HANDLE_GET_DATA(handle, config,
1278 struct gpfs_config_data,
1282 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, smb_fname,
1286 gpfs_acl = smb2gpfs_acl(theacl, type);
1287 if (gpfs_acl == NULL) {
1291 result = gpfswrap_putacl(discard_const_p(char, smb_fname->base_name),
1292 GPFS_PUTACL_STRUCT|GPFS_ACL_SAMBA, gpfs_acl);
1294 SAFE_FREE(gpfs_acl);
1298 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct *handle,
1302 struct gpfs_config_data *config;
1304 SMB_VFS_HANDLE_GET_DATA(handle, config,
1305 struct gpfs_config_data,
1309 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
1312 return gpfsacl_sys_acl_set_file(handle, fsp->fsp_name,
1313 SMB_ACL_TYPE_ACCESS, theacl);
1316 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct *handle,
1317 const struct smb_filename *smb_fname)
1319 struct gpfs_config_data *config;
1321 SMB_VFS_HANDLE_GET_DATA(handle, config,
1322 struct gpfs_config_data,
1326 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, smb_fname);
1334 * Assumed: mode bits are shiftable and standard
1335 * Output: the new aceMask field for an smb nfs4 ace
1337 static uint32_t gpfsacl_mask_filter(uint32_t aceType, uint32_t aceMask, uint32_t rwx)
1339 const uint32_t posix_nfs4map[3] = {
1340 SMB_ACE4_EXECUTE, /* execute */
1341 SMB_ACE4_WRITE_DATA | SMB_ACE4_APPEND_DATA, /* write; GPFS specific */
1342 SMB_ACE4_READ_DATA /* read */
1345 uint32_t posix_mask = 0x01;
1349 for(i=0; i<3; i++) {
1350 nfs4_bits = posix_nfs4map[i];
1351 posix_bit = rwx & posix_mask;
1353 if (aceType==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE) {
1355 aceMask |= nfs4_bits;
1357 aceMask &= ~nfs4_bits;
1359 /* add deny bits when suitable */
1361 aceMask |= nfs4_bits;
1363 aceMask &= ~nfs4_bits;
1364 } /* other ace types are unexpected */
1372 static int gpfsacl_emu_chmod(vfs_handle_struct *handle,
1373 const char *path, mode_t mode)
1375 struct SMB4ACL_T *pacl = NULL;
1377 bool haveAllowEntry[SMB_ACE4_WHO_EVERYONE + 1] = {False, False, False, False};
1379 files_struct fake_fsp = { 0 }; /* TODO: rationalize parametrization */
1380 struct SMB4ACE_T *smbace;
1381 TALLOC_CTX *frame = talloc_stackframe();
1383 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path, mode));
1385 result = gpfs_get_nfs4_acl(frame, path, &pacl);
1391 if (mode & ~(S_IRWXU | S_IRWXG | S_IRWXO)) {
1392 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode, path));
1395 for (smbace=smb_first_ace4(pacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
1396 SMB_ACE4PROP_T *ace = smb_get_ace4(smbace);
1397 uint32_t specid = ace->who.special_id;
1399 if (ace->flags&SMB_ACE4_ID_SPECIAL &&
1400 ace->aceType<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE &&
1401 specid <= SMB_ACE4_WHO_EVERYONE) {
1405 if (ace->aceType==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE)
1406 haveAllowEntry[specid] = True;
1408 /* mode >> 6 for @owner, mode >> 3 for @group,
1409 * mode >> 0 for @everyone */
1410 newMask = gpfsacl_mask_filter(ace->aceType, ace->aceMask,
1411 mode >> ((SMB_ACE4_WHO_EVERYONE - specid) * 3));
1412 if (ace->aceMask!=newMask) {
1413 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
1414 path, ace->aceMask, newMask, specid));
1416 ace->aceMask = newMask;
1420 /* make sure we have at least ALLOW entries
1421 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
1424 for(i = SMB_ACE4_WHO_OWNER; i<=SMB_ACE4_WHO_EVERYONE; i++) {
1425 SMB_ACE4PROP_T ace = { 0 };
1427 if (haveAllowEntry[i]==True)
1430 ace.aceType = SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE;
1431 ace.flags |= SMB_ACE4_ID_SPECIAL;
1432 ace.who.special_id = i;
1434 if (i==SMB_ACE4_WHO_GROUP) /* not sure it's necessary... */
1435 ace.aceFlags |= SMB_ACE4_IDENTIFIER_GROUP;
1437 ace.aceMask = gpfsacl_mask_filter(ace.aceType, ace.aceMask,
1438 mode >> ((SMB_ACE4_WHO_EVERYONE - i) * 3));
1440 /* don't add unnecessary aces */
1444 /* we add it to the END - as windows expects allow aces */
1445 smb_add_ace4(pacl, &ace);
1446 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1447 path, mode, i, ace.aceMask));
1450 /* don't add complementary DENY ACEs here */
1451 fake_fsp.fsp_name = synthetic_smb_fname(
1452 frame, path, NULL, NULL, 0);
1453 if (fake_fsp.fsp_name == NULL) {
1459 if (gpfsacl_process_smbacl(handle, &fake_fsp, pacl) == False) {
1465 return 0; /* ok for [f]chmod */
1468 static int vfs_gpfs_chmod(vfs_handle_struct *handle,
1469 const struct smb_filename *smb_fname,
1472 struct smb_filename *smb_fname_cpath;
1475 smb_fname_cpath = cp_smb_filename(talloc_tos(), smb_fname);
1476 if (smb_fname_cpath == NULL) {
1481 if (SMB_VFS_NEXT_STAT(handle, smb_fname_cpath) != 0) {
1482 TALLOC_FREE(smb_fname_cpath);
1486 /* avoid chmod() if possible, to preserve acls */
1487 if ((smb_fname_cpath->st.st_ex_mode & ~S_IFMT) == mode) {
1488 TALLOC_FREE(smb_fname_cpath);
1492 rc = gpfsacl_emu_chmod(handle, smb_fname->base_name, mode);
1494 return SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
1496 TALLOC_FREE(smb_fname_cpath);
1500 static int vfs_gpfs_fchmod(vfs_handle_struct *handle, files_struct *fsp, mode_t mode)
1505 if (SMB_VFS_NEXT_FSTAT(handle, fsp, &st) != 0) {
1509 /* avoid chmod() if possible, to preserve acls */
1510 if ((st.st_ex_mode & ~S_IFMT) == mode) {
1514 rc = gpfsacl_emu_chmod(handle, fsp->fsp_name->base_name,
1517 return SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1521 static uint32_t vfs_gpfs_winattrs_to_dosmode(unsigned int winattrs)
1523 uint32_t dosmode = 0;
1525 if (winattrs & GPFS_WINATTR_ARCHIVE){
1526 dosmode |= FILE_ATTRIBUTE_ARCHIVE;
1528 if (winattrs & GPFS_WINATTR_HIDDEN){
1529 dosmode |= FILE_ATTRIBUTE_HIDDEN;
1531 if (winattrs & GPFS_WINATTR_SYSTEM){
1532 dosmode |= FILE_ATTRIBUTE_SYSTEM;
1534 if (winattrs & GPFS_WINATTR_READONLY){
1535 dosmode |= FILE_ATTRIBUTE_READONLY;
1537 if (winattrs & GPFS_WINATTR_SPARSE_FILE) {
1538 dosmode |= FILE_ATTRIBUTE_SPARSE;
1540 if (winattrs & GPFS_WINATTR_OFFLINE) {
1541 dosmode |= FILE_ATTRIBUTE_OFFLINE;
1547 static unsigned int vfs_gpfs_dosmode_to_winattrs(uint32_t dosmode)
1549 unsigned int winattrs = 0;
1551 if (dosmode & FILE_ATTRIBUTE_ARCHIVE){
1552 winattrs |= GPFS_WINATTR_ARCHIVE;
1554 if (dosmode & FILE_ATTRIBUTE_HIDDEN){
1555 winattrs |= GPFS_WINATTR_HIDDEN;
1557 if (dosmode & FILE_ATTRIBUTE_SYSTEM){
1558 winattrs |= GPFS_WINATTR_SYSTEM;
1560 if (dosmode & FILE_ATTRIBUTE_READONLY){
1561 winattrs |= GPFS_WINATTR_READONLY;
1563 if (dosmode & FILE_ATTRIBUTE_SPARSE) {
1564 winattrs |= GPFS_WINATTR_SPARSE_FILE;
1566 if (dosmode & FILE_ATTRIBUTE_OFFLINE) {
1567 winattrs |= GPFS_WINATTR_OFFLINE;
1573 static int get_dos_attr_with_capability(struct smb_filename *smb_fname,
1574 unsigned int *litemask,
1575 struct gpfs_iattr64 *iattr)
1577 int saved_errno = 0;
1581 * According to MS-FSA 2.1.5.1.2.1 "Algorithm to Check Access to an
1582 * Existing File" FILE_LIST_DIRECTORY on a directory implies
1583 * FILE_READ_ATTRIBUTES for directory entries. Being able to stat() a
1584 * file implies FILE_LIST_DIRECTORY for the directory containing the
1588 if (!VALID_STAT(smb_fname->st)) {
1590 * Safety net: dos_mode() already checks this, but as we set
1591 * DAC_OVERRIDE_CAPABILITY based on this, add an additional
1594 DBG_ERR("Rejecting DAC override, invalid stat [%s]\n",
1595 smb_fname_str_dbg(smb_fname));
1600 set_effective_capability(DAC_OVERRIDE_CAPABILITY);
1602 ret = gpfswrap_stat_x(smb_fname->base_name, litemask,
1603 iattr, sizeof(*iattr));
1605 saved_errno = errno;
1608 drop_effective_capability(DAC_OVERRIDE_CAPABILITY);
1610 if (saved_errno != 0) {
1611 errno = saved_errno;
1616 static NTSTATUS vfs_gpfs_get_file_id(struct gpfs_iattr64 *iattr,
1619 uint8_t input[sizeof(gpfs_ino64_t) +
1620 sizeof(gpfs_gen64_t) +
1621 sizeof(gpfs_snapid64_t)];
1622 uint8_t digest[gnutls_hash_get_len(GNUTLS_DIG_SHA1)];
1625 DBG_DEBUG("ia_inode 0x%llx, ia_gen 0x%llx, ia_modsnapid 0x%llx\n",
1626 iattr->ia_inode, iattr->ia_gen, iattr->ia_modsnapid);
1629 0, iattr->ia_inode);
1631 sizeof(gpfs_ino64_t), iattr->ia_gen);
1633 sizeof(gpfs_ino64_t) + sizeof(gpfs_gen64_t), iattr->ia_modsnapid);
1635 GNUTLS_FIPS140_SET_LAX_MODE();
1636 rc = gnutls_hash_fast(GNUTLS_DIG_SHA1, input, sizeof(input), &digest);
1637 GNUTLS_FIPS140_SET_STRICT_MODE();
1640 return gnutls_error_to_ntstatus(rc,
1641 NT_STATUS_HASH_NOT_SUPPORTED);
1644 memcpy(fileid, &digest, sizeof(*fileid));
1645 DBG_DEBUG("file_id 0x%" PRIx64 "\n", *fileid);
1647 return NT_STATUS_OK;
1650 static struct timespec gpfs_timestruc64_to_timespec(struct gpfs_timestruc64 g)
1652 return (struct timespec) { .tv_sec = g.tv_sec, .tv_nsec = g.tv_nsec };
1655 static NTSTATUS vfs_gpfs_get_dos_attributes(struct vfs_handle_struct *handle,
1656 struct smb_filename *smb_fname,
1659 struct gpfs_config_data *config;
1660 struct gpfs_iattr64 iattr = { };
1661 unsigned int litemask = 0;
1667 SMB_VFS_HANDLE_GET_DATA(handle, config,
1668 struct gpfs_config_data,
1669 return NT_STATUS_INTERNAL_ERROR);
1671 if (!config->winattr) {
1672 return SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
1673 smb_fname, dosmode);
1676 ret = gpfswrap_stat_x(smb_fname->base_name, &litemask,
1677 &iattr, sizeof(iattr));
1678 if (ret == -1 && errno == ENOSYS) {
1679 return SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle, smb_fname,
1682 if (ret == -1 && errno == EACCES) {
1683 ret = get_dos_attr_with_capability(smb_fname, &litemask,
1687 if (ret == -1 && errno == EBADF) {
1689 * Returned for directory listings in gpfs root for
1690 * .. entry which steps out of gpfs.
1692 DBG_DEBUG("Getting winattrs for %s returned EBADF.\n",
1693 smb_fname->base_name);
1694 return map_nt_error_from_unix(errno);
1695 } else if (ret == -1) {
1696 DBG_WARNING("Getting winattrs failed for %s: %s\n",
1697 smb_fname->base_name, strerror(errno));
1698 return map_nt_error_from_unix(errno);
1701 status = vfs_gpfs_get_file_id(&iattr, &file_id);
1702 if (!NT_STATUS_IS_OK(status)) {
1706 ts = gpfs_timestruc64_to_timespec(iattr.ia_createtime);
1708 *dosmode |= vfs_gpfs_winattrs_to_dosmode(iattr.ia_winflags);
1709 update_stat_ex_create_time(&smb_fname->st, ts);
1710 update_stat_ex_file_id(&smb_fname->st, file_id);
1712 return NT_STATUS_OK;
1715 static NTSTATUS vfs_gpfs_fget_dos_attributes(struct vfs_handle_struct *handle,
1716 struct files_struct *fsp,
1719 struct gpfs_config_data *config;
1720 struct gpfs_iattr64 iattr = { };
1721 unsigned int litemask;
1727 SMB_VFS_HANDLE_GET_DATA(handle, config,
1728 struct gpfs_config_data,
1729 return NT_STATUS_INTERNAL_ERROR);
1731 if (!config->winattr) {
1732 return SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1735 ret = gpfswrap_fstat_x(fsp->fh->fd, &litemask, &iattr, sizeof(iattr));
1736 if (ret == -1 && errno == ENOSYS) {
1737 return SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1740 if (ret == -1 && errno == EACCES) {
1741 int saved_errno = 0;
1744 * According to MS-FSA 2.1.5.1.2.1 "Algorithm to Check Access to
1745 * an Existing File" FILE_LIST_DIRECTORY on a directory implies
1746 * FILE_READ_ATTRIBUTES for directory entries. Being able to
1747 * open a file implies FILE_LIST_DIRECTORY.
1750 set_effective_capability(DAC_OVERRIDE_CAPABILITY);
1752 ret = gpfswrap_fstat_x(fsp->fh->fd, &litemask,
1753 &iattr, sizeof(iattr));
1755 saved_errno = errno;
1758 drop_effective_capability(DAC_OVERRIDE_CAPABILITY);
1760 if (saved_errno != 0) {
1761 errno = saved_errno;
1766 DBG_WARNING("Getting winattrs failed for %s: %s\n",
1767 fsp->fsp_name->base_name, strerror(errno));
1768 return map_nt_error_from_unix(errno);
1771 status = vfs_gpfs_get_file_id(&iattr, &file_id);
1772 if (!NT_STATUS_IS_OK(status)) {
1776 ts = gpfs_timestruc64_to_timespec(iattr.ia_createtime);
1778 *dosmode |= vfs_gpfs_winattrs_to_dosmode(iattr.ia_winflags);
1779 update_stat_ex_create_time(&fsp->fsp_name->st, ts);
1780 update_stat_ex_file_id(&fsp->fsp_name->st, file_id);
1782 return NT_STATUS_OK;
1785 static NTSTATUS vfs_gpfs_set_dos_attributes(struct vfs_handle_struct *handle,
1786 const struct smb_filename *smb_fname,
1789 struct gpfs_config_data *config;
1790 struct gpfs_winattr attrs = { };
1793 SMB_VFS_HANDLE_GET_DATA(handle, config,
1794 struct gpfs_config_data,
1795 return NT_STATUS_INTERNAL_ERROR);
1797 if (!config->winattr) {
1798 return SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
1799 smb_fname, dosmode);
1802 attrs.winAttrs = vfs_gpfs_dosmode_to_winattrs(dosmode);
1803 ret = gpfswrap_set_winattrs_path(smb_fname->base_name,
1804 GPFS_WINATTR_SET_ATTRS, &attrs);
1806 if (ret == -1 && errno == ENOSYS) {
1807 return SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
1808 smb_fname, dosmode);
1812 DBG_WARNING("Setting winattrs failed for %s: %s\n",
1813 smb_fname->base_name, strerror(errno));
1814 return map_nt_error_from_unix(errno);
1817 return NT_STATUS_OK;
1820 static NTSTATUS vfs_gpfs_fset_dos_attributes(struct vfs_handle_struct *handle,
1821 struct files_struct *fsp,
1824 struct gpfs_config_data *config;
1825 struct gpfs_winattr attrs = { };
1828 SMB_VFS_HANDLE_GET_DATA(handle, config,
1829 struct gpfs_config_data,
1830 return NT_STATUS_INTERNAL_ERROR);
1832 if (!config->winattr) {
1833 return SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1836 attrs.winAttrs = vfs_gpfs_dosmode_to_winattrs(dosmode);
1837 ret = gpfswrap_set_winattrs(fsp->fh->fd,
1838 GPFS_WINATTR_SET_ATTRS, &attrs);
1840 if (ret == -1 && errno == ENOSYS) {
1841 return SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1845 DBG_WARNING("Setting winattrs failed for %s: %s\n",
1846 fsp->fsp_name->base_name, strerror(errno));
1847 return map_nt_error_from_unix(errno);
1850 return NT_STATUS_OK;
1853 static int stat_with_capability(struct vfs_handle_struct *handle,
1854 struct smb_filename *smb_fname, int flag)
1856 #if defined(HAVE_FSTATAT)
1860 const char *rel_name = NULL;
1864 b = parent_dirname(talloc_tos(), smb_fname->base_name,
1865 &dir_name, &rel_name);
1871 fd = open(dir_name, O_RDONLY, 0);
1872 TALLOC_FREE(dir_name);
1877 set_effective_capability(DAC_OVERRIDE_CAPABILITY);
1878 ret = fstatat(fd, rel_name, &st, flag);
1879 drop_effective_capability(DAC_OVERRIDE_CAPABILITY);
1884 init_stat_ex_from_stat(
1885 &smb_fname->st, &st,
1886 lp_fake_directory_create_times(SNUM(handle->conn)));
1895 static int vfs_gpfs_stat(struct vfs_handle_struct *handle,
1896 struct smb_filename *smb_fname)
1899 struct gpfs_config_data *config;
1901 SMB_VFS_HANDLE_GET_DATA(handle, config,
1902 struct gpfs_config_data,
1905 ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
1906 if (ret == -1 && errno == EACCES) {
1907 DEBUG(10, ("Trying stat with capability for %s\n",
1908 smb_fname->base_name));
1909 ret = stat_with_capability(handle, smb_fname, 0);
1914 static int vfs_gpfs_lstat(struct vfs_handle_struct *handle,
1915 struct smb_filename *smb_fname)
1918 struct gpfs_config_data *config;
1920 SMB_VFS_HANDLE_GET_DATA(handle, config,
1921 struct gpfs_config_data,
1924 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1925 if (ret == -1 && errno == EACCES) {
1926 DEBUG(10, ("Trying lstat with capability for %s\n",
1927 smb_fname->base_name));
1928 ret = stat_with_capability(handle, smb_fname,
1929 AT_SYMLINK_NOFOLLOW);
1934 static void timespec_to_gpfs_time(struct timespec ts, gpfs_timestruc_t *gt,
1935 int idx, int *flags)
1937 if (!null_timespec(ts)) {
1939 gt[idx].tv_sec = ts.tv_sec;
1940 gt[idx].tv_nsec = ts.tv_nsec;
1941 DEBUG(10, ("Setting GPFS time %d, flags 0x%x\n", idx, *flags));
1945 static int smbd_gpfs_set_times_path(char *path, struct smb_file_time *ft)
1947 gpfs_timestruc_t gpfs_times[4];
1951 ZERO_ARRAY(gpfs_times);
1952 timespec_to_gpfs_time(ft->atime, gpfs_times, 0, &flags);
1953 timespec_to_gpfs_time(ft->mtime, gpfs_times, 1, &flags);
1954 /* No good mapping from LastChangeTime to ctime, not storing */
1955 timespec_to_gpfs_time(ft->create_time, gpfs_times, 3, &flags);
1958 DEBUG(10, ("nothing to do, return to avoid EINVAL\n"));
1962 rc = gpfswrap_set_times_path(path, flags, gpfs_times);
1964 if (rc != 0 && errno != ENOSYS) {
1965 DEBUG(1,("gpfs_set_times() returned with error %s\n",
1972 static int vfs_gpfs_ntimes(struct vfs_handle_struct *handle,
1973 const struct smb_filename *smb_fname,
1974 struct smb_file_time *ft)
1977 struct gpfs_winattr attrs;
1979 struct gpfs_config_data *config;
1981 SMB_VFS_HANDLE_GET_DATA(handle, config,
1982 struct gpfs_config_data,
1985 /* Try to use gpfs_set_times if it is enabled and available */
1986 if (config->settimes) {
1987 ret = smbd_gpfs_set_times_path(smb_fname->base_name, ft);
1989 if (ret == 0 || (ret == -1 && errno != ENOSYS)) {
1994 DEBUG(10,("gpfs_set_times() not available or disabled, "
1995 "use ntimes and winattr\n"));
1997 ret = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1999 /* don't complain if access was denied */
2000 if (errno != EPERM && errno != EACCES) {
2001 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
2002 "%s", strerror(errno)));
2007 if(null_timespec(ft->create_time)){
2008 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
2012 if (!config->winattr) {
2017 attrs.creationTime.tv_sec = ft->create_time.tv_sec;
2018 attrs.creationTime.tv_nsec = ft->create_time.tv_nsec;
2020 ret = gpfswrap_set_winattrs_path(smb_fname->base_name,
2021 GPFS_WINATTR_SET_CREATION_TIME,
2023 if(ret == -1 && errno != ENOSYS){
2024 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret));
2031 static int vfs_gpfs_fallocate(struct vfs_handle_struct *handle,
2032 struct files_struct *fsp, uint32_t mode,
2033 off_t offset, off_t len)
2035 if (mode == (VFS_FALLOCATE_FL_PUNCH_HOLE|VFS_FALLOCATE_FL_KEEP_SIZE) &&
2037 lp_strict_allocate(SNUM(fsp->conn))) {
2039 * This is from a ZERO_DATA request on a non-sparse
2040 * file. GPFS does not support FL_KEEP_SIZE and thus
2041 * cannot fill the whole again in the subsequent
2042 * fallocate(FL_KEEP_SIZE). Deny this FL_PUNCH_HOLE
2043 * call to not end up with a hole in a non-sparse
2050 return SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
2053 static int vfs_gpfs_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
2057 struct gpfs_config_data *config;
2059 SMB_VFS_HANDLE_GET_DATA(handle, config,
2060 struct gpfs_config_data,
2063 if (!config->ftruncate) {
2064 return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
2067 result = gpfswrap_ftruncate(fsp->fh->fd, len);
2068 if ((result == -1) && (errno == ENOSYS)) {
2069 return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
2074 static bool vfs_gpfs_is_offline(struct vfs_handle_struct *handle,
2075 const struct smb_filename *fname,
2076 SMB_STRUCT_STAT *sbuf)
2078 struct gpfs_winattr attrs;
2079 struct gpfs_config_data *config;
2082 SMB_VFS_HANDLE_GET_DATA(handle, config,
2083 struct gpfs_config_data,
2086 if (!config->winattr) {
2090 ret = gpfswrap_get_winattrs_path(fname->base_name, &attrs);
2095 if ((attrs.winAttrs & GPFS_WINATTR_OFFLINE) != 0) {
2096 DBG_DEBUG("%s is offline\n", fname->base_name);
2100 DBG_DEBUG("%s is online\n", fname->base_name);
2104 static bool vfs_gpfs_fsp_is_offline(struct vfs_handle_struct *handle,
2105 struct files_struct *fsp)
2107 struct gpfs_fsp_extension *ext;
2109 ext = VFS_FETCH_FSP_EXTENSION(handle, fsp);
2112 * Something bad happened, always ask.
2114 return vfs_gpfs_is_offline(handle, fsp->fsp_name,
2115 &fsp->fsp_name->st);
2120 * As long as it's offline, ask.
2122 ext->offline = vfs_gpfs_is_offline(handle, fsp->fsp_name,
2123 &fsp->fsp_name->st);
2126 return ext->offline;
2129 static bool vfs_gpfs_aio_force(struct vfs_handle_struct *handle,
2130 struct files_struct *fsp)
2132 return vfs_gpfs_fsp_is_offline(handle, fsp);
2135 static ssize_t vfs_gpfs_sendfile(vfs_handle_struct *handle, int tofd,
2136 files_struct *fsp, const DATA_BLOB *hdr,
2137 off_t offset, size_t n)
2139 if (vfs_gpfs_fsp_is_offline(handle, fsp)) {
2143 return SMB_VFS_NEXT_SENDFILE(handle, tofd, fsp, hdr, offset, n);
2146 static int vfs_gpfs_connect(struct vfs_handle_struct *handle,
2147 const char *service, const char *user)
2149 struct gpfs_config_data *config;
2153 gpfswrap_lib_init(0);
2155 config = talloc_zero(handle->conn, struct gpfs_config_data);
2157 DEBUG(0, ("talloc_zero() failed\n"));
2162 ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
2164 TALLOC_FREE(config);
2168 check_fstype = lp_parm_bool(SNUM(handle->conn), "gpfs",
2169 "check_fstype", true);
2171 if (check_fstype && !IS_IPC(handle->conn)) {
2172 const char *connectpath = handle->conn->connectpath;
2173 struct statfs buf = { 0 };
2175 ret = statfs(connectpath, &buf);
2177 DBG_ERR("statfs failed for share %s at path %s: %s\n",
2178 service, connectpath, strerror(errno));
2179 TALLOC_FREE(config);
2183 if (buf.f_type != GPFS_SUPER_MAGIC) {
2184 DBG_ERR("SMB share %s, path %s not in GPFS file system."
2185 " statfs magic: 0x%jx\n",
2188 (uintmax_t)buf.f_type);
2190 TALLOC_FREE(config);
2195 ret = smbacl4_get_vfs_params(handle->conn, &config->nfs4_params);
2197 TALLOC_FREE(config);
2201 config->sharemodes = lp_parm_bool(SNUM(handle->conn), "gpfs",
2202 "sharemodes", true);
2204 config->leases = lp_parm_bool(SNUM(handle->conn), "gpfs",
2207 config->hsm = lp_parm_bool(SNUM(handle->conn), "gpfs",
2210 config->syncio = lp_parm_bool(SNUM(handle->conn), "gpfs",
2213 config->winattr = lp_parm_bool(SNUM(handle->conn), "gpfs",
2216 config->ftruncate = lp_parm_bool(SNUM(handle->conn), "gpfs",
2219 config->getrealfilename = lp_parm_bool(SNUM(handle->conn), "gpfs",
2220 "getrealfilename", true);
2222 config->dfreequota = lp_parm_bool(SNUM(handle->conn), "gpfs",
2223 "dfreequota", false);
2225 config->acl = lp_parm_bool(SNUM(handle->conn), "gpfs", "acl", true);
2227 config->settimes = lp_parm_bool(SNUM(handle->conn), "gpfs",
2229 config->recalls = lp_parm_bool(SNUM(handle->conn), "gpfs",
2232 SMB_VFS_HANDLE_SET_DATA(handle, config,
2233 NULL, struct gpfs_config_data,
2236 if (config->leases) {
2238 * GPFS lease code is based on kernel oplock code
2239 * so make sure it is turned on
2241 if (!lp_kernel_oplocks(SNUM(handle->conn))) {
2242 DEBUG(5, ("Enabling kernel oplocks for "
2243 "gpfs:leases to work\n"));
2244 lp_do_parameter(SNUM(handle->conn), "kernel oplocks",
2249 * as the kernel does not properly support Level II oplocks
2250 * and GPFS leases code is based on kernel infrastructure, we
2251 * need to turn off Level II oplocks if gpfs:leases is enabled
2253 if (lp_level2_oplocks(SNUM(handle->conn))) {
2254 DEBUG(5, ("gpfs:leases are enabled, disabling "
2255 "Level II oplocks\n"));
2256 lp_do_parameter(SNUM(handle->conn), "level2 oplocks",
2262 * Unless we have an async implementation of get_dos_attributes turn
2265 lp_do_parameter(SNUM(handle->conn), "smbd async dosmode", "false");
2270 static int get_gpfs_quota(const char *pathname, int type, int id,
2271 struct gpfs_quotaInfo *qi)
2275 ret = gpfswrap_quotactl(discard_const_p(char, pathname),
2276 GPFS_QCMD(Q_GETQUOTA, type), id, qi);
2279 if (errno == GPFS_E_NO_QUOTA_INST) {
2280 DEBUG(10, ("Quotas disabled on GPFS filesystem.\n"));
2281 } else if (errno != ENOSYS) {
2282 DEBUG(0, ("Get quota failed, type %d, id, %d, "
2283 "errno %d.\n", type, id, errno));
2289 DEBUG(10, ("quota type %d, id %d, blk u:%lld h:%lld s:%lld gt:%u\n",
2290 type, id, qi->blockUsage, qi->blockHardLimit,
2291 qi->blockSoftLimit, qi->blockGraceTime));
2296 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi, time_t cur_time,
2297 uint64_t *dfree, uint64_t *dsize)
2299 uint64_t usage, limit;
2302 * The quota reporting is done in units of 1024 byte blocks, but
2303 * sys_fsusage uses units of 512 byte blocks, adjust the block number
2304 * accordingly. Also filter possibly negative usage counts from gpfs.
2306 usage = qi.blockUsage < 0 ? 0 : (uint64_t)qi.blockUsage * 2;
2307 limit = (uint64_t)qi.blockHardLimit * 2;
2310 * When the grace time for the exceeded soft block quota has been
2311 * exceeded, the soft block quota becomes an additional hard limit.
2313 if (qi.blockSoftLimit &&
2314 qi.blockGraceTime && cur_time > qi.blockGraceTime) {
2315 /* report disk as full */
2317 *dsize = MIN(*dsize, usage);
2320 if (!qi.blockHardLimit)
2323 if (usage >= limit) {
2324 /* report disk as full */
2326 *dsize = MIN(*dsize, usage);
2329 /* limit has not been reached, determine "free space" */
2330 *dfree = MIN(*dfree, limit - usage);
2331 *dsize = MIN(*dsize, limit);
2335 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct *handle,
2336 const struct smb_filename *smb_fname,
2341 struct security_unix_token *utok;
2342 struct gpfs_quotaInfo qi_user = { 0 }, qi_group = { 0 };
2343 struct gpfs_config_data *config;
2347 SMB_VFS_HANDLE_GET_DATA(handle, config, struct gpfs_config_data,
2348 return (uint64_t)-1);
2349 if (!config->dfreequota) {
2350 return SMB_VFS_NEXT_DISK_FREE(handle, smb_fname,
2351 bsize, dfree, dsize);
2354 err = sys_fsusage(smb_fname->base_name, dfree, dsize);
2356 DEBUG (0, ("Could not get fs usage, errno %d\n", errno));
2357 return SMB_VFS_NEXT_DISK_FREE(handle, smb_fname,
2358 bsize, dfree, dsize);
2361 /* sys_fsusage returns units of 512 bytes */
2364 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
2365 (unsigned long long)*dfree, (unsigned long long)*dsize));
2367 utok = handle->conn->session_info->unix_token;
2369 err = get_gpfs_quota(smb_fname->base_name,
2370 GPFS_USRQUOTA, utok->uid, &qi_user);
2372 return SMB_VFS_NEXT_DISK_FREE(handle, smb_fname,
2373 bsize, dfree, dsize);
2377 * If new files created under this folder get this folder's
2378 * GID, then available space is governed by the quota of the
2379 * folder's GID, not the primary group of the creating user.
2381 if (VALID_STAT(smb_fname->st) &&
2382 S_ISDIR(smb_fname->st.st_ex_mode) &&
2383 smb_fname->st.st_ex_mode & S_ISGID) {
2385 err = get_gpfs_quota(smb_fname->base_name, GPFS_GRPQUOTA,
2386 smb_fname->st.st_ex_gid, &qi_group);
2390 err = get_gpfs_quota(smb_fname->base_name, GPFS_GRPQUOTA,
2391 utok->gid, &qi_group);
2395 return SMB_VFS_NEXT_DISK_FREE(handle, smb_fname,
2396 bsize, dfree, dsize);
2399 cur_time = time(NULL);
2401 /* Adjust free space and size according to quota limits. */
2402 vfs_gpfs_disk_free_quota(qi_user, cur_time, dfree, dsize);
2403 vfs_gpfs_disk_free_quota(qi_group, cur_time, dfree, dsize);
2408 static int vfs_gpfs_get_quota(vfs_handle_struct *handle,
2409 const struct smb_filename *smb_fname,
2410 enum SMB_QUOTA_TYPE qtype,
2416 * User/group quota are being used for disk-free
2417 * determination, which in this module is done directly
2418 * by the disk-free function. It's important that this
2419 * module does not return wrong quota values by mistake,
2420 * which would modify the correct values set by disk-free.
2421 * User/group quota are also being used for processing
2422 * NT_TRANSACT_GET_USER_QUOTA in smb1 protocol, which is
2423 * currently not supported by this module.
2425 case SMB_USER_QUOTA_TYPE:
2426 case SMB_GROUP_QUOTA_TYPE:
2430 return SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname,
2435 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct *handle,
2436 enum timestamp_set_resolution *p_ts_res)
2438 struct gpfs_config_data *config;
2441 next = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
2443 SMB_VFS_HANDLE_GET_DATA(handle, config,
2444 struct gpfs_config_data,
2448 next |= FILE_SUPPORTS_REMOTE_STORAGE;
2453 static int vfs_gpfs_open(struct vfs_handle_struct *handle,
2454 struct smb_filename *smb_fname, files_struct *fsp,
2455 int flags, mode_t mode)
2457 struct gpfs_config_data *config;
2459 struct gpfs_fsp_extension *ext;
2461 SMB_VFS_HANDLE_GET_DATA(handle, config,
2462 struct gpfs_config_data,
2465 if (config->hsm && !config->recalls &&
2466 vfs_gpfs_fsp_is_offline(handle, fsp)) {
2467 DEBUG(10, ("Refusing access to offline file %s\n",
2473 if (config->syncio) {
2477 ext = VFS_ADD_FSP_EXTENSION(handle, fsp, struct gpfs_fsp_extension,
2485 * Assume the file is offline until gpfs tells us it's online.
2487 *ext = (struct gpfs_fsp_extension) { .offline = true };
2489 ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
2491 VFS_REMOVE_FSP_EXTENSION(handle, fsp);
2496 static ssize_t vfs_gpfs_pread(vfs_handle_struct *handle, files_struct *fsp,
2497 void *data, size_t n, off_t offset)
2502 was_offline = vfs_gpfs_fsp_is_offline(handle, fsp);
2504 ret = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
2506 if ((ret != -1) && was_offline) {
2507 notify_fname(handle->conn, NOTIFY_ACTION_MODIFIED,
2508 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2509 fsp->fsp_name->base_name);
2515 struct vfs_gpfs_pread_state {
2516 struct files_struct *fsp;
2519 struct vfs_aio_state vfs_aio_state;
2522 static void vfs_gpfs_pread_done(struct tevent_req *subreq);
2524 static struct tevent_req *vfs_gpfs_pread_send(struct vfs_handle_struct *handle,
2525 TALLOC_CTX *mem_ctx,
2526 struct tevent_context *ev,
2527 struct files_struct *fsp,
2528 void *data, size_t n,
2531 struct tevent_req *req, *subreq;
2532 struct vfs_gpfs_pread_state *state;
2534 req = tevent_req_create(mem_ctx, &state, struct vfs_gpfs_pread_state);
2538 state->was_offline = vfs_gpfs_fsp_is_offline(handle, fsp);
2540 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
2542 if (tevent_req_nomem(subreq, req)) {
2543 return tevent_req_post(req, ev);
2545 tevent_req_set_callback(subreq, vfs_gpfs_pread_done, req);
2549 static void vfs_gpfs_pread_done(struct tevent_req *subreq)
2551 struct tevent_req *req = tevent_req_callback_data(
2552 subreq, struct tevent_req);
2553 struct vfs_gpfs_pread_state *state = tevent_req_data(
2554 req, struct vfs_gpfs_pread_state);
2556 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
2557 TALLOC_FREE(subreq);
2558 tevent_req_done(req);
2561 static ssize_t vfs_gpfs_pread_recv(struct tevent_req *req,
2562 struct vfs_aio_state *vfs_aio_state)
2564 struct vfs_gpfs_pread_state *state = tevent_req_data(
2565 req, struct vfs_gpfs_pread_state);
2566 struct files_struct *fsp = state->fsp;
2568 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
2571 *vfs_aio_state = state->vfs_aio_state;
2573 if ((state->ret != -1) && state->was_offline) {
2574 DEBUG(10, ("sending notify\n"));
2575 notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
2576 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2577 fsp->fsp_name->base_name);
2583 static ssize_t vfs_gpfs_pwrite(vfs_handle_struct *handle, files_struct *fsp,
2584 const void *data, size_t n, off_t offset)
2589 was_offline = vfs_gpfs_fsp_is_offline(handle, fsp);
2591 ret = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
2593 if ((ret != -1) && was_offline) {
2594 notify_fname(handle->conn, NOTIFY_ACTION_MODIFIED,
2595 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2596 fsp->fsp_name->base_name);
2602 struct vfs_gpfs_pwrite_state {
2603 struct files_struct *fsp;
2606 struct vfs_aio_state vfs_aio_state;
2609 static void vfs_gpfs_pwrite_done(struct tevent_req *subreq);
2611 static struct tevent_req *vfs_gpfs_pwrite_send(
2612 struct vfs_handle_struct *handle,
2613 TALLOC_CTX *mem_ctx,
2614 struct tevent_context *ev,
2615 struct files_struct *fsp,
2616 const void *data, size_t n,
2619 struct tevent_req *req, *subreq;
2620 struct vfs_gpfs_pwrite_state *state;
2622 req = tevent_req_create(mem_ctx, &state, struct vfs_gpfs_pwrite_state);
2626 state->was_offline = vfs_gpfs_fsp_is_offline(handle, fsp);
2628 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
2630 if (tevent_req_nomem(subreq, req)) {
2631 return tevent_req_post(req, ev);
2633 tevent_req_set_callback(subreq, vfs_gpfs_pwrite_done, req);
2637 static void vfs_gpfs_pwrite_done(struct tevent_req *subreq)
2639 struct tevent_req *req = tevent_req_callback_data(
2640 subreq, struct tevent_req);
2641 struct vfs_gpfs_pwrite_state *state = tevent_req_data(
2642 req, struct vfs_gpfs_pwrite_state);
2644 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
2645 TALLOC_FREE(subreq);
2646 tevent_req_done(req);
2649 static ssize_t vfs_gpfs_pwrite_recv(struct tevent_req *req,
2650 struct vfs_aio_state *vfs_aio_state)
2652 struct vfs_gpfs_pwrite_state *state = tevent_req_data(
2653 req, struct vfs_gpfs_pwrite_state);
2654 struct files_struct *fsp = state->fsp;
2656 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
2659 *vfs_aio_state = state->vfs_aio_state;
2661 if ((state->ret != -1) && state->was_offline) {
2662 DEBUG(10, ("sending notify\n"));
2663 notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
2664 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2665 fsp->fsp_name->base_name);
2672 static struct vfs_fn_pointers vfs_gpfs_fns = {
2673 .connect_fn = vfs_gpfs_connect,
2674 .disk_free_fn = vfs_gpfs_disk_free,
2675 .get_quota_fn = vfs_gpfs_get_quota,
2676 .fs_capabilities_fn = vfs_gpfs_capabilities,
2677 .kernel_flock_fn = vfs_gpfs_kernel_flock,
2678 .linux_setlease_fn = vfs_gpfs_setlease,
2679 .get_real_filename_fn = vfs_gpfs_get_real_filename,
2680 .get_dos_attributes_fn = vfs_gpfs_get_dos_attributes,
2681 .get_dos_attributes_send_fn = vfs_not_implemented_get_dos_attributes_send,
2682 .get_dos_attributes_recv_fn = vfs_not_implemented_get_dos_attributes_recv,
2683 .fget_dos_attributes_fn = vfs_gpfs_fget_dos_attributes,
2684 .set_dos_attributes_fn = vfs_gpfs_set_dos_attributes,
2685 .fset_dos_attributes_fn = vfs_gpfs_fset_dos_attributes,
2686 .fget_nt_acl_fn = gpfsacl_fget_nt_acl,
2687 .get_nt_acl_fn = gpfsacl_get_nt_acl,
2688 .fset_nt_acl_fn = gpfsacl_fset_nt_acl,
2689 .sys_acl_get_file_fn = gpfsacl_sys_acl_get_file,
2690 .sys_acl_get_fd_fn = gpfsacl_sys_acl_get_fd,
2691 .sys_acl_blob_get_file_fn = gpfsacl_sys_acl_blob_get_file,
2692 .sys_acl_blob_get_fd_fn = gpfsacl_sys_acl_blob_get_fd,
2693 .sys_acl_set_file_fn = gpfsacl_sys_acl_set_file,
2694 .sys_acl_set_fd_fn = gpfsacl_sys_acl_set_fd,
2695 .sys_acl_delete_def_file_fn = gpfsacl_sys_acl_delete_def_file,
2696 .chmod_fn = vfs_gpfs_chmod,
2697 .fchmod_fn = vfs_gpfs_fchmod,
2698 .close_fn = vfs_gpfs_close,
2699 .stat_fn = vfs_gpfs_stat,
2700 .lstat_fn = vfs_gpfs_lstat,
2701 .ntimes_fn = vfs_gpfs_ntimes,
2702 .aio_force_fn = vfs_gpfs_aio_force,
2703 .sendfile_fn = vfs_gpfs_sendfile,
2704 .fallocate_fn = vfs_gpfs_fallocate,
2705 .open_fn = vfs_gpfs_open,
2706 .pread_fn = vfs_gpfs_pread,
2707 .pread_send_fn = vfs_gpfs_pread_send,
2708 .pread_recv_fn = vfs_gpfs_pread_recv,
2709 .pwrite_fn = vfs_gpfs_pwrite,
2710 .pwrite_send_fn = vfs_gpfs_pwrite_send,
2711 .pwrite_recv_fn = vfs_gpfs_pwrite_recv,
2712 .ftruncate_fn = vfs_gpfs_ftruncate
2716 NTSTATUS vfs_gpfs_init(TALLOC_CTX *ctx)
2720 ret = gpfswrap_init();
2722 DEBUG(1, ("Could not initialize GPFS library wrapper\n"));
2725 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "gpfs",