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;
63 struct gpfs_fsp_extension {
67 static inline unsigned int gpfs_acl_flags(gpfs_acl_t *gacl)
69 if (gacl->acl_level == GPFS_ACL_LEVEL_V4FLAGS) {
70 return gacl->v4Level1.acl_flags;
75 static inline gpfs_ace_v4_t *gpfs_ace_ptr(gpfs_acl_t *gacl, unsigned int i)
77 if (gacl->acl_level == GPFS_ACL_LEVEL_V4FLAGS) {
78 return &gacl->v4Level1.ace_v4[i];
80 return &gacl->ace_v4[i];
83 static unsigned int vfs_gpfs_access_mask_to_allow(uint32_t access_mask)
85 unsigned int allow = GPFS_SHARE_NONE;
87 if (access_mask & (FILE_WRITE_DATA|FILE_APPEND_DATA)) {
88 allow |= GPFS_SHARE_WRITE;
90 if (access_mask & (FILE_READ_DATA|FILE_EXECUTE)) {
91 allow |= GPFS_SHARE_READ;
97 static unsigned int vfs_gpfs_share_access_to_deny(uint32_t share_access)
99 unsigned int deny = GPFS_DENY_NONE;
101 if (!(share_access & FILE_SHARE_WRITE)) {
102 deny |= GPFS_DENY_WRITE;
104 if (!(share_access & FILE_SHARE_READ)) {
105 deny |= GPFS_DENY_READ;
109 * GPFS_DENY_DELETE can only be set together with either
110 * GPFS_DENY_WRITE or GPFS_DENY_READ.
112 if ((deny & (GPFS_DENY_WRITE|GPFS_DENY_READ)) &&
113 !(share_access & FILE_SHARE_DELETE)) {
114 deny |= GPFS_DENY_DELETE;
120 static int set_gpfs_sharemode(files_struct *fsp, uint32_t access_mask,
121 uint32_t share_access)
123 unsigned int allow = GPFS_SHARE_NONE;
124 unsigned int deny = GPFS_DENY_NONE;
127 if (access_mask == 0) {
128 DBG_DEBUG("Clearing file system share mode.\n");
130 allow = vfs_gpfs_access_mask_to_allow(access_mask);
131 deny = vfs_gpfs_share_access_to_deny(share_access);
133 DBG_DEBUG("access_mask=0x%x, allow=0x%x, share_access=0x%x, "
134 "deny=0x%x\n", access_mask, allow, share_access, deny);
136 result = gpfswrap_set_share(fsp_get_io_fd(fsp), allow, deny);
141 if (errno == EACCES) {
142 DBG_NOTICE("GPFS share mode denied for %s/%s.\n",
143 fsp->conn->connectpath,
144 fsp->fsp_name->base_name);
145 } else if (errno == EPERM) {
146 DBG_ERR("Samba requested GPFS sharemode for %s/%s, but the "
147 "GPFS file system is not configured accordingly. "
148 "Configure file system with mmchfs -D nfs4 or "
149 "set gpfs:sharemodes=no in Samba.\n",
150 fsp->conn->connectpath,
151 fsp->fsp_name->base_name);
153 DBG_ERR("gpfs_set_share failed: %s\n", strerror(errno));
159 static int vfs_gpfs_filesystem_sharemode(vfs_handle_struct *handle,
161 uint32_t share_access,
162 uint32_t access_mask)
165 struct gpfs_config_data *config;
168 SMB_VFS_HANDLE_GET_DATA(handle, config,
169 struct gpfs_config_data,
172 if(!config->sharemodes) {
177 * A named stream fsp will have the basefile open in the fsp
178 * fd, so lacking a distinct fd for the stream we have to skip
179 * set_gpfs_sharemode for stream.
181 if (is_named_stream(fsp->fsp_name)) {
182 DBG_NOTICE("Not requesting GPFS sharemode on stream: %s/%s\n",
183 fsp->conn->connectpath,
188 ret = set_gpfs_sharemode(fsp, access_mask, share_access);
193 static int vfs_gpfs_close(vfs_handle_struct *handle, files_struct *fsp)
196 struct gpfs_config_data *config;
198 SMB_VFS_HANDLE_GET_DATA(handle, config,
199 struct gpfs_config_data,
202 if (config->sharemodes &&
203 (fsp->fsp_flags.kernel_share_modes_taken))
206 * Always clear GPFS sharemode in case the actual
207 * close gets deferred due to outstanding POSIX locks
208 * (see fd_close_posix)
210 int ret = gpfswrap_set_share(fsp_get_io_fd(fsp), 0, 0);
212 DBG_ERR("Clearing GPFS sharemode on close failed for "
214 fsp->conn->connectpath,
215 fsp->fsp_name->base_name,
220 return SMB_VFS_NEXT_CLOSE(handle, fsp);
223 static int lease_type_to_gpfs(int leasetype)
225 if (leasetype == F_RDLCK) {
226 return GPFS_LEASE_READ;
229 if (leasetype == F_WRLCK) {
230 return GPFS_LEASE_WRITE;
233 return GPFS_LEASE_NONE;
236 static int vfs_gpfs_setlease(vfs_handle_struct *handle,
240 struct gpfs_config_data *config;
243 START_PROFILE(syscall_linux_setlease);
245 SMB_VFS_HANDLE_GET_DATA(handle, config,
246 struct gpfs_config_data,
249 ret = linux_set_lease_sighandler(fsp_get_io_fd(fsp));
254 if (config->leases) {
255 int gpfs_lease_type = lease_type_to_gpfs(leasetype);
259 * Ensure the lease owner is root to allow
260 * correct delivery of lease-break signals.
263 ret = gpfswrap_set_lease(fsp_get_io_fd(fsp), gpfs_lease_type);
269 if (saved_errno != 0) {
275 END_PROFILE(syscall_linux_setlease);
280 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct *handle,
281 const struct smb_filename *path,
287 char *full_path = NULL;
288 char *to_free = NULL;
289 char real_pathname[PATH_MAX+1], tmpbuf[PATH_MAX];
290 size_t full_path_len;
293 struct gpfs_config_data *config;
295 SMB_VFS_HANDLE_GET_DATA(handle, config,
296 struct gpfs_config_data,
299 if (!config->getrealfilename) {
300 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
301 mem_ctx, found_name);
304 mangled = mangle_is_mangled(name, handle->conn->params);
306 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
307 mem_ctx, found_name);
310 full_path_len = full_path_tos(path->base_name, name,
311 tmpbuf, sizeof(tmpbuf),
312 &full_path, &to_free);
313 if (full_path_len == -1) {
318 buflen = sizeof(real_pathname) - 1;
320 result = gpfswrap_get_realfilename_path(full_path, real_pathname,
323 TALLOC_FREE(to_free);
325 if ((result == -1) && (errno == ENOSYS)) {
326 return SMB_VFS_NEXT_GET_REAL_FILENAME(
327 handle, path, name, mem_ctx, found_name);
331 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
337 * GPFS does not necessarily null-terminate the returned path
338 * but instead returns the buffer length in buflen.
341 if (buflen < sizeof(real_pathname)) {
342 real_pathname[buflen] = '\0';
344 real_pathname[sizeof(real_pathname)-1] = '\0';
347 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
348 path->base_name, name, real_pathname));
350 name = strrchr_m(real_pathname, '/');
356 *found_name = talloc_strdup(mem_ctx, name+1);
357 if (*found_name == NULL) {
365 static void sd2gpfs_control(uint16_t control, struct gpfs_acl *gacl)
367 unsigned int gpfs_aclflags = 0;
368 control &= SEC_DESC_DACL_PROTECTED | SEC_DESC_SACL_PROTECTED |
369 SEC_DESC_DACL_AUTO_INHERITED | SEC_DESC_SACL_AUTO_INHERITED |
370 SEC_DESC_DACL_DEFAULTED | SEC_DESC_SACL_DEFAULTED |
371 SEC_DESC_DACL_PRESENT | SEC_DESC_SACL_PRESENT;
372 gpfs_aclflags = control << 8;
373 if (!(control & SEC_DESC_DACL_PRESENT))
374 gpfs_aclflags |= ACL4_FLAG_NULL_DACL;
375 if (!(control & SEC_DESC_SACL_PRESENT))
376 gpfs_aclflags |= ACL4_FLAG_NULL_SACL;
377 gacl->acl_level = GPFS_ACL_LEVEL_V4FLAGS;
378 gacl->v4Level1.acl_flags = gpfs_aclflags;
381 static uint16_t gpfs2sd_control(unsigned int gpfs_aclflags)
383 uint16_t control = gpfs_aclflags >> 8;
384 control &= SEC_DESC_DACL_PROTECTED | SEC_DESC_SACL_PROTECTED |
385 SEC_DESC_DACL_AUTO_INHERITED | SEC_DESC_SACL_AUTO_INHERITED |
386 SEC_DESC_DACL_DEFAULTED | SEC_DESC_SACL_DEFAULTED |
387 SEC_DESC_DACL_PRESENT | SEC_DESC_SACL_PRESENT;
388 control |= SEC_DESC_SELF_RELATIVE;
392 static void gpfs_dumpacl(int level, struct gpfs_acl *gacl)
397 DEBUG(0, ("gpfs acl is NULL\n"));
401 DEBUG(level, ("len: %d, level: %d, version: %d, nace: %d, "
403 gacl->acl_len, gacl->acl_level, gacl->acl_version,
404 gacl->acl_nace, gpfs_acl_flags(gacl)));
406 for(i=0; i<gacl->acl_nace; i++)
408 struct gpfs_ace_v4 *gace = gpfs_ace_ptr(gacl, i);
409 DEBUG(level, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, "
410 "iflags:0x%x, who:%u\n",
411 i, gace->aceType, gace->aceFlags, gace->aceMask,
412 gace->aceIFlags, gace->aceWho));
416 static int gpfs_getacl_with_capability(const char *fname, int flags, void *buf)
418 int ret, saved_errno;
420 set_effective_capability(DAC_OVERRIDE_CAPABILITY);
422 ret = gpfswrap_getacl(fname, flags, buf);
425 drop_effective_capability(DAC_OVERRIDE_CAPABILITY);
432 * get the ACL from GPFS, allocated on the specified mem_ctx
433 * internally retries when initial buffer was too small
435 * caller needs to cast result to either
436 * raw = yes: struct gpfs_opaque_acl
437 * raw = no: struct gpfs_acl
440 static void *vfs_gpfs_getacl(TALLOC_CTX *mem_ctx,
443 const gpfs_aclType_t type)
451 bool use_capability = false;
455 aclbuf = talloc_zero_size(mem_ctx, size);
456 if (aclbuf == NULL) {
462 struct gpfs_opaque_acl *buf = (struct gpfs_opaque_acl *) aclbuf;
463 buf->acl_type = type;
464 flags = GPFS_GETACL_NATIVE;
465 len = (unsigned int *) &(buf->acl_buffer_len);
466 struct_size = sizeof(struct gpfs_opaque_acl);
468 struct gpfs_acl *buf = (struct gpfs_acl *) aclbuf;
469 buf->acl_type = type;
470 buf->acl_level = GPFS_ACL_LEVEL_V4FLAGS;
471 flags = GPFS_GETACL_STRUCT;
472 len = &(buf->acl_len);
473 /* reserve space for control flags in gpfs 3.5 and beyond */
474 struct_size = sizeof(struct gpfs_acl) + sizeof(unsigned int);
477 /* set the length of the buffer as input value */
480 if (use_capability) {
481 ret = gpfs_getacl_with_capability(fname, flags, aclbuf);
483 ret = gpfswrap_getacl(fname, flags, aclbuf);
484 if ((ret != 0) && (errno == EACCES)) {
485 DBG_DEBUG("Retry with DAC capability for %s\n", fname);
486 use_capability = true;
487 ret = gpfs_getacl_with_capability(fname, flags, aclbuf);
491 if ((ret != 0) && (errno == ENOSPC)) {
493 * get the size needed to accommodate the complete buffer
495 * the value returned only applies to the ACL blob in the
496 * struct so make sure to also have headroom for the first
497 * struct members by adding room for the complete struct
498 * (might be a few bytes too much then)
500 size = *len + struct_size;
502 DEBUG(10, ("Increasing ACL buffer size to %zu\n", size));
507 DEBUG(5, ("smbd_gpfs_getacl failed with %s\n",
516 /* Tries to get nfs4 acls and returns SMB ACL allocated.
517 * On failure returns 1 if it got non-NFSv4 ACL to prompt
518 * retry with POSIX ACL checks.
519 * On failure returns -1 if there is system (GPFS) error, check errno.
520 * Returns 0 on success
522 static int gpfs_get_nfs4_acl(TALLOC_CTX *mem_ctx, const char *fname,
523 struct SMB4ACL_T **ppacl)
526 struct gpfs_acl *gacl = NULL;
527 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname));
530 gacl = (struct gpfs_acl*) vfs_gpfs_getacl(talloc_tos(), fname,
533 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
534 fname, strerror(errno)));
535 if (errno == ENODATA) {
537 * GPFS returns ENODATA for snapshot
538 * directories. Retry with POSIX ACLs check.
546 if (gacl->acl_type != GPFS_ACL_TYPE_NFS4) {
547 DEBUG(10, ("Got non-nfsv4 acl\n"));
548 /* Retry with POSIX ACLs check */
553 *ppacl = smb_create_smb4acl(mem_ctx);
555 if (gacl->acl_level == GPFS_ACL_LEVEL_V4FLAGS) {
556 uint16_t control = gpfs2sd_control(gpfs_acl_flags(gacl));
557 smbacl4_set_controlflags(*ppacl, control);
560 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d, control: %x\n",
561 gacl->acl_len, gacl->acl_level, gacl->acl_version,
562 gacl->acl_nace, gpfs_acl_flags(gacl)));
564 for (i=0; i<gacl->acl_nace; i++) {
565 struct gpfs_ace_v4 *gace = gpfs_ace_ptr(gacl, i);
566 SMB_ACE4PROP_T smbace = { 0 };
567 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
568 "who: %d\n", gace->aceType, gace->aceIFlags,
569 gace->aceFlags, gace->aceMask, gace->aceWho));
571 if (gace->aceIFlags & ACE4_IFLAG_SPECIAL_ID) {
572 smbace.flags |= SMB_ACE4_ID_SPECIAL;
573 switch (gace->aceWho) {
574 case ACE4_SPECIAL_OWNER:
575 smbace.who.special_id = SMB_ACE4_WHO_OWNER;
577 case ACE4_SPECIAL_GROUP:
578 smbace.who.special_id = SMB_ACE4_WHO_GROUP;
580 case ACE4_SPECIAL_EVERYONE:
581 smbace.who.special_id = SMB_ACE4_WHO_EVERYONE;
584 DEBUG(8, ("invalid special gpfs id %d "
585 "ignored\n", gace->aceWho));
586 continue; /* don't add it */
589 if (gace->aceFlags & ACE4_FLAG_GROUP_ID)
590 smbace.who.gid = gace->aceWho;
592 smbace.who.uid = gace->aceWho;
595 /* remove redundant deny entries */
596 if (i > 0 && gace->aceType == SMB_ACE4_ACCESS_DENIED_ACE_TYPE) {
597 struct gpfs_ace_v4 *prev = gpfs_ace_ptr(gacl, i - 1);
598 if (prev->aceType == SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE &&
599 prev->aceFlags == gace->aceFlags &&
600 prev->aceIFlags == gace->aceIFlags &&
601 (gace->aceMask & prev->aceMask) == 0 &&
602 gace->aceWho == prev->aceWho) {
603 /* it's redundant - skip it */
608 smbace.aceType = gace->aceType;
609 smbace.aceFlags = gace->aceFlags;
610 smbace.aceMask = gace->aceMask;
611 smb_add_ace4(*ppacl, &smbace);
619 static NTSTATUS gpfsacl_fget_nt_acl(vfs_handle_struct *handle,
620 files_struct *fsp, uint32_t security_info,
622 struct security_descriptor **ppdesc)
624 struct SMB4ACL_T *pacl = NULL;
626 struct gpfs_config_data *config;
627 TALLOC_CTX *frame = talloc_stackframe();
632 SMB_VFS_HANDLE_GET_DATA(handle, config,
633 struct gpfs_config_data,
634 return NT_STATUS_INTERNAL_ERROR);
637 status = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
643 result = gpfs_get_nfs4_acl(frame, fsp->fsp_name->base_name, &pacl);
646 status = smb_fget_nt_acl_nfs4(fsp, &config->nfs4_params,
648 mem_ctx, ppdesc, pacl);
654 DEBUG(10, ("retrying with posix acl...\n"));
655 status = posix_fget_nt_acl(fsp, security_info,
663 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
664 return map_nt_error_from_unix(errno);
667 static bool vfs_gpfs_nfs4_ace_to_gpfs_ace(SMB_ACE4PROP_T *nfs4_ace,
668 struct gpfs_ace_v4 *gace,
671 gace->aceType = nfs4_ace->aceType;
672 gace->aceFlags = nfs4_ace->aceFlags;
673 gace->aceMask = nfs4_ace->aceMask;
675 if (nfs4_ace->flags & SMB_ACE4_ID_SPECIAL) {
676 switch(nfs4_ace->who.special_id) {
677 case SMB_ACE4_WHO_EVERYONE:
678 gace->aceIFlags = ACE4_IFLAG_SPECIAL_ID;
679 gace->aceWho = ACE4_SPECIAL_EVERYONE;
681 case SMB_ACE4_WHO_OWNER:
683 * With GPFS it is not possible to deny ACL or
684 * attribute access to the owner. Setting an
685 * ACL with such an entry is not possible.
686 * Denying ACL or attribute access for the
687 * owner through a named ACL entry can be
688 * stored in an ACL, it is just not effective.
690 * Map this case to a named entry to allow at
691 * least setting this ACL, which will be
692 * enforced by the smbd permission check. Do
693 * not do this for an inheriting OWNER entry,
694 * as this represents a CREATOR OWNER ACE. The
695 * remaining limitation is that CREATOR OWNER
696 * cannot deny ACL or attribute access.
698 if (!nfs_ace_is_inherit(nfs4_ace) &&
700 SMB_ACE4_ACCESS_DENIED_ACE_TYPE &&
701 nfs4_ace->aceMask & (SMB_ACE4_READ_ATTRIBUTES|
702 SMB_ACE4_WRITE_ATTRIBUTES|
704 SMB_ACE4_WRITE_ACL)) {
706 gace->aceWho = owner_uid;
708 gace->aceIFlags = ACE4_IFLAG_SPECIAL_ID;
709 gace->aceWho = ACE4_SPECIAL_OWNER;
712 case SMB_ACE4_WHO_GROUP:
713 gace->aceIFlags = ACE4_IFLAG_SPECIAL_ID;
714 gace->aceWho = ACE4_SPECIAL_GROUP;
717 DBG_WARNING("Unsupported special_id %d\n",
718 nfs4_ace->who.special_id);
726 gace->aceWho = (nfs4_ace->aceFlags & SMB_ACE4_IDENTIFIER_GROUP) ?
727 nfs4_ace->who.gid : nfs4_ace->who.uid;
732 static struct gpfs_acl *vfs_gpfs_smbacl2gpfsacl(TALLOC_CTX *mem_ctx,
734 struct SMB4ACL_T *smbacl,
737 struct gpfs_acl *gacl;
738 gpfs_aclLen_t gacl_len;
739 struct SMB4ACE_T *smbace;
741 gacl_len = offsetof(gpfs_acl_t, ace_v4) + sizeof(unsigned int)
742 + smb_get_naces(smbacl) * sizeof(gpfs_ace_v4_t);
744 gacl = (struct gpfs_acl *)TALLOC_SIZE(mem_ctx, gacl_len);
746 DEBUG(0, ("talloc failed\n"));
751 gacl->acl_level = GPFS_ACL_LEVEL_BASE;
752 gacl->acl_version = GPFS_ACL_VERSION_NFS4;
753 gacl->acl_type = GPFS_ACL_TYPE_NFS4;
754 gacl->acl_nace = 0; /* change later... */
757 gacl->acl_level = GPFS_ACL_LEVEL_V4FLAGS;
758 sd2gpfs_control(smbacl4_get_controlflags(smbacl), gacl);
761 for (smbace=smb_first_ace4(smbacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
762 struct gpfs_ace_v4 *gace = gpfs_ace_ptr(gacl, gacl->acl_nace);
763 SMB_ACE4PROP_T *aceprop = smb_get_ace4(smbace);
766 add_ace = vfs_gpfs_nfs4_ace_to_gpfs_ace(aceprop, gace,
767 fsp->fsp_name->st.st_ex_uid);
774 gacl->acl_len = (char *)gpfs_ace_ptr(gacl, gacl->acl_nace)
779 static bool gpfsacl_process_smbacl(vfs_handle_struct *handle,
781 struct SMB4ACL_T *smbacl)
784 struct gpfs_acl *gacl;
785 TALLOC_CTX *mem_ctx = talloc_tos();
787 gacl = vfs_gpfs_smbacl2gpfsacl(mem_ctx, fsp, smbacl, true);
788 if (gacl == NULL) { /* out of memory */
791 ret = gpfswrap_putacl(fsp->fsp_name->base_name,
792 GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gacl);
794 if ((ret != 0) && (errno == EINVAL)) {
795 DEBUG(10, ("Retry without nfs41 control flags\n"));
797 gacl = vfs_gpfs_smbacl2gpfsacl(mem_ctx, fsp, smbacl, false);
798 if (gacl == NULL) { /* out of memory */
801 ret = gpfswrap_putacl(fsp->fsp_name->base_name,
802 GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA,
807 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno)));
808 gpfs_dumpacl(8, gacl);
812 DEBUG(10, ("gpfs_putacl succeeded\n"));
816 static NTSTATUS gpfsacl_set_nt_acl_internal(vfs_handle_struct *handle, files_struct *fsp, uint32_t security_info_sent, const struct security_descriptor *psd)
818 struct gpfs_acl *acl;
819 NTSTATUS result = NT_STATUS_ACCESS_DENIED;
821 acl = (struct gpfs_acl*) vfs_gpfs_getacl(talloc_tos(),
822 fsp->fsp_name->base_name,
825 return map_nt_error_from_unix(errno);
828 if (acl->acl_version == GPFS_ACL_VERSION_NFS4) {
829 struct gpfs_config_data *config;
831 if (lp_parm_bool(fsp->conn->params->service, "gpfs",
832 "refuse_dacl_protected", false)
833 && (psd->type&SEC_DESC_DACL_PROTECTED)) {
834 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
836 return NT_STATUS_NOT_SUPPORTED;
839 SMB_VFS_HANDLE_GET_DATA(handle, config,
840 struct gpfs_config_data,
841 return NT_STATUS_INTERNAL_ERROR);
843 result = smb_set_nt_acl_nfs4(handle,
844 fsp, &config->nfs4_params, security_info_sent, psd,
845 gpfsacl_process_smbacl);
846 } else { /* assume POSIX ACL - by default... */
847 result = set_nt_acl(fsp, security_info_sent, psd);
854 static NTSTATUS gpfsacl_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32_t security_info_sent, const struct security_descriptor *psd)
856 struct gpfs_config_data *config;
858 SMB_VFS_HANDLE_GET_DATA(handle, config,
859 struct gpfs_config_data,
860 return NT_STATUS_INTERNAL_ERROR);
863 return SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
866 return gpfsacl_set_nt_acl_internal(handle, fsp, security_info_sent, psd);
869 static SMB_ACL_T gpfs2smb_acl(const struct gpfs_acl *pacl, TALLOC_CTX *mem_ctx)
874 result = sys_acl_init(mem_ctx);
875 if (result == NULL) {
880 result->count = pacl->acl_nace;
881 result->acl = talloc_realloc(result, result->acl, struct smb_acl_entry,
883 if (result->acl == NULL) {
889 for (i=0; i<pacl->acl_nace; i++) {
890 struct smb_acl_entry *ace = &result->acl[i];
891 const struct gpfs_ace_v1 *g_ace = &pacl->ace_v1[i];
893 DEBUG(10, ("Converting type %d id %lu perm %x\n",
894 (int)g_ace->ace_type, (unsigned long)g_ace->ace_who,
895 (int)g_ace->ace_perm));
897 switch (g_ace->ace_type) {
899 ace->a_type = SMB_ACL_USER;
900 ace->info.user.uid = (uid_t)g_ace->ace_who;
902 case GPFS_ACL_USER_OBJ:
903 ace->a_type = SMB_ACL_USER_OBJ;
906 ace->a_type = SMB_ACL_GROUP;
907 ace->info.group.gid = (gid_t)g_ace->ace_who;
909 case GPFS_ACL_GROUP_OBJ:
910 ace->a_type = SMB_ACL_GROUP_OBJ;
913 ace->a_type = SMB_ACL_OTHER;
916 ace->a_type = SMB_ACL_MASK;
919 DEBUG(10, ("Got invalid ace_type: %d\n",
927 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_READ) ?
929 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_WRITE) ?
931 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_EXECUTE) ?
934 DEBUGADD(10, ("Converted to %d perm %x\n",
935 ace->a_type, ace->a_perm));
941 static SMB_ACL_T gpfsacl_get_posix_acl(const char *path, gpfs_aclType_t type,
944 struct gpfs_acl *pacl;
945 SMB_ACL_T result = NULL;
947 pacl = vfs_gpfs_getacl(talloc_tos(), path, false, type);
950 DEBUG(10, ("vfs_gpfs_getacl failed for %s with %s\n",
951 path, strerror(errno)));
958 if (pacl->acl_version != GPFS_ACL_VERSION_POSIX) {
959 DEBUG(10, ("Got acl version %d, expected %d\n",
960 pacl->acl_version, GPFS_ACL_VERSION_POSIX));
965 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
966 pacl->acl_len, pacl->acl_level, pacl->acl_version,
969 result = gpfs2smb_acl(pacl, mem_ctx);
970 if (result != NULL) {
985 static SMB_ACL_T gpfsacl_sys_acl_get_fd(vfs_handle_struct *handle,
990 gpfs_aclType_t gpfs_type;
991 struct gpfs_config_data *config;
993 SMB_VFS_HANDLE_GET_DATA(handle, config,
994 struct gpfs_config_data,
998 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, type, mem_ctx);
1002 case SMB_ACL_TYPE_ACCESS:
1003 gpfs_type = GPFS_ACL_TYPE_ACCESS;
1005 case SMB_ACL_TYPE_DEFAULT:
1006 gpfs_type = GPFS_ACL_TYPE_DEFAULT;
1009 DEBUG(0, ("Got invalid type: %d\n", type));
1010 smb_panic("exiting");
1012 return gpfsacl_get_posix_acl(fsp->fsp_name->base_name,
1013 gpfs_type, mem_ctx);
1016 static int gpfsacl_sys_acl_blob_get_fd(vfs_handle_struct *handle,
1018 TALLOC_CTX *mem_ctx,
1019 char **blob_description,
1022 struct gpfs_config_data *config;
1023 struct gpfs_opaque_acl *acl = NULL;
1027 SMB_VFS_HANDLE_GET_DATA(handle, config,
1028 struct gpfs_config_data,
1032 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx,
1033 blob_description, blob);
1037 acl = (struct gpfs_opaque_acl *) vfs_gpfs_getacl(mem_ctx,
1038 fsp->fsp_name->base_name,
1040 GPFS_ACL_TYPE_NFS4);
1043 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
1044 errno, strerror(errno)));
1046 /* EINVAL means POSIX ACL, bail out on other cases */
1047 if (errno != EINVAL) {
1054 * file has NFSv4 ACL
1056 * we only need the actual ACL blob here
1057 * acl_version will always be NFS4 because we asked
1059 * acl_type is only used for POSIX ACLs
1061 aclblob.data = (uint8_t*) acl->acl_var_data;
1062 aclblob.length = acl->acl_buffer_len;
1064 *blob_description = talloc_strdup(mem_ctx, "gpfs_nfs4_acl");
1065 if (!*blob_description) {
1071 result = non_posix_sys_acl_blob_get_fd_helper(handle, fsp,
1079 /* fall back to POSIX ACL */
1080 return posix_sys_acl_blob_get_fd(handle, fsp, mem_ctx,
1081 blob_description, blob);
1084 static struct gpfs_acl *smb2gpfs_acl(const SMB_ACL_T pacl,
1085 SMB_ACL_TYPE_T type)
1088 struct gpfs_acl *result;
1091 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl->count));
1093 len = offsetof(gpfs_acl_t, ace_v1) + (pacl->count) *
1094 sizeof(gpfs_ace_v1_t);
1096 result = (struct gpfs_acl *)SMB_MALLOC(len);
1097 if (result == NULL) {
1102 result->acl_len = len;
1103 result->acl_level = 0;
1104 result->acl_version = GPFS_ACL_VERSION_POSIX;
1105 result->acl_type = (type == SMB_ACL_TYPE_DEFAULT) ?
1106 GPFS_ACL_TYPE_DEFAULT : GPFS_ACL_TYPE_ACCESS;
1107 result->acl_nace = pacl->count;
1109 for (i=0; i<pacl->count; i++) {
1110 const struct smb_acl_entry *ace = &pacl->acl[i];
1111 struct gpfs_ace_v1 *g_ace = &result->ace_v1[i];
1113 DEBUG(10, ("Converting type %d perm %x\n",
1114 (int)ace->a_type, (int)ace->a_perm));
1116 g_ace->ace_perm = 0;
1118 switch(ace->a_type) {
1120 g_ace->ace_type = GPFS_ACL_USER;
1121 g_ace->ace_who = (gpfs_uid_t)ace->info.user.uid;
1123 case SMB_ACL_USER_OBJ:
1124 g_ace->ace_type = GPFS_ACL_USER_OBJ;
1125 g_ace->ace_perm |= ACL_PERM_CONTROL;
1129 g_ace->ace_type = GPFS_ACL_GROUP;
1130 g_ace->ace_who = (gpfs_uid_t)ace->info.group.gid;
1132 case SMB_ACL_GROUP_OBJ:
1133 g_ace->ace_type = GPFS_ACL_GROUP_OBJ;
1137 g_ace->ace_type = GPFS_ACL_MASK;
1138 g_ace->ace_perm = 0x8f;
1142 g_ace->ace_type = GPFS_ACL_OTHER;
1146 DEBUG(10, ("Got invalid ace_type: %d\n", ace->a_type));
1152 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_READ) ?
1154 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_WRITE) ?
1156 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_EXECUTE) ?
1157 ACL_PERM_EXECUTE : 0;
1159 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
1160 g_ace->ace_type, g_ace->ace_who, g_ace->ace_perm));
1166 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct *handle,
1168 SMB_ACL_TYPE_T type,
1171 struct gpfs_config_data *config;
1172 struct gpfs_acl *gpfs_acl = NULL;
1175 SMB_VFS_HANDLE_GET_DATA(handle, config,
1176 struct gpfs_config_data,
1180 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, type, theacl);
1183 gpfs_acl = smb2gpfs_acl(theacl, type);
1184 if (gpfs_acl == NULL) {
1189 * This is no longer a handle based call.
1191 result = gpfswrap_putacl(fsp->fsp_name->base_name,
1192 GPFS_PUTACL_STRUCT|GPFS_ACL_SAMBA,
1194 SAFE_FREE(gpfs_acl);
1198 static int gpfsacl_sys_acl_delete_def_fd(vfs_handle_struct *handle,
1201 struct gpfs_config_data *config;
1203 SMB_VFS_HANDLE_GET_DATA(handle, config,
1204 struct gpfs_config_data,
1208 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FD(handle, fsp);
1217 * Assumed: mode bits are shiftable and standard
1218 * Output: the new aceMask field for an smb nfs4 ace
1220 static uint32_t gpfsacl_mask_filter(uint32_t aceType, uint32_t aceMask, uint32_t rwx)
1222 const uint32_t posix_nfs4map[3] = {
1223 SMB_ACE4_EXECUTE, /* execute */
1224 SMB_ACE4_WRITE_DATA | SMB_ACE4_APPEND_DATA, /* write; GPFS specific */
1225 SMB_ACE4_READ_DATA /* read */
1228 uint32_t posix_mask = 0x01;
1232 for(i=0; i<3; i++) {
1233 nfs4_bits = posix_nfs4map[i];
1234 posix_bit = rwx & posix_mask;
1236 if (aceType==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE) {
1238 aceMask |= nfs4_bits;
1240 aceMask &= ~nfs4_bits;
1242 /* add deny bits when suitable */
1244 aceMask |= nfs4_bits;
1246 aceMask &= ~nfs4_bits;
1247 } /* other ace types are unexpected */
1255 static int gpfsacl_emu_chmod(vfs_handle_struct *handle,
1256 const struct smb_filename *fname, mode_t mode)
1258 char *path = fname->base_name;
1259 struct SMB4ACL_T *pacl = NULL;
1261 bool haveAllowEntry[SMB_ACE4_WHO_EVERYONE + 1] = {False, False, False, False};
1263 files_struct fake_fsp = { 0 }; /* TODO: rationalize parametrization */
1264 struct SMB4ACE_T *smbace;
1265 TALLOC_CTX *frame = talloc_stackframe();
1267 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path, mode));
1269 result = gpfs_get_nfs4_acl(frame, path, &pacl);
1275 if (mode & ~(S_IRWXU | S_IRWXG | S_IRWXO)) {
1276 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode, path));
1279 for (smbace=smb_first_ace4(pacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
1280 SMB_ACE4PROP_T *ace = smb_get_ace4(smbace);
1281 uint32_t specid = ace->who.special_id;
1283 if (ace->flags&SMB_ACE4_ID_SPECIAL &&
1284 ace->aceType<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE &&
1285 specid <= SMB_ACE4_WHO_EVERYONE) {
1289 if (ace->aceType==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE)
1290 haveAllowEntry[specid] = True;
1292 /* mode >> 6 for @owner, mode >> 3 for @group,
1293 * mode >> 0 for @everyone */
1294 newMask = gpfsacl_mask_filter(ace->aceType, ace->aceMask,
1295 mode >> ((SMB_ACE4_WHO_EVERYONE - specid) * 3));
1296 if (ace->aceMask!=newMask) {
1297 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
1298 path, ace->aceMask, newMask, specid));
1300 ace->aceMask = newMask;
1304 /* make sure we have at least ALLOW entries
1305 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
1308 for(i = SMB_ACE4_WHO_OWNER; i<=SMB_ACE4_WHO_EVERYONE; i++) {
1309 SMB_ACE4PROP_T ace = { 0 };
1311 if (haveAllowEntry[i]==True)
1314 ace.aceType = SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE;
1315 ace.flags |= SMB_ACE4_ID_SPECIAL;
1316 ace.who.special_id = i;
1318 if (i==SMB_ACE4_WHO_GROUP) /* not sure it's necessary... */
1319 ace.aceFlags |= SMB_ACE4_IDENTIFIER_GROUP;
1321 ace.aceMask = gpfsacl_mask_filter(ace.aceType, ace.aceMask,
1322 mode >> ((SMB_ACE4_WHO_EVERYONE - i) * 3));
1324 /* don't add unnecessary aces */
1328 /* we add it to the END - as windows expects allow aces */
1329 smb_add_ace4(pacl, &ace);
1330 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1331 path, mode, i, ace.aceMask));
1334 /* don't add complementary DENY ACEs here */
1335 fake_fsp.fsp_name = synthetic_smb_fname(frame,
1341 if (fake_fsp.fsp_name == NULL) {
1347 if (gpfsacl_process_smbacl(handle, &fake_fsp, pacl) == False) {
1353 return 0; /* ok for [f]chmod */
1356 static int vfs_gpfs_fchmod(vfs_handle_struct *handle, files_struct *fsp, mode_t mode)
1361 if (SMB_VFS_NEXT_FSTAT(handle, fsp, &st) != 0) {
1365 /* avoid chmod() if possible, to preserve acls */
1366 if ((st.st_ex_mode & ~S_IFMT) == mode) {
1370 rc = gpfsacl_emu_chmod(handle, fsp->fsp_name,
1373 return SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1377 static uint32_t vfs_gpfs_winattrs_to_dosmode(unsigned int winattrs)
1379 uint32_t dosmode = 0;
1381 if (winattrs & GPFS_WINATTR_ARCHIVE){
1382 dosmode |= FILE_ATTRIBUTE_ARCHIVE;
1384 if (winattrs & GPFS_WINATTR_HIDDEN){
1385 dosmode |= FILE_ATTRIBUTE_HIDDEN;
1387 if (winattrs & GPFS_WINATTR_SYSTEM){
1388 dosmode |= FILE_ATTRIBUTE_SYSTEM;
1390 if (winattrs & GPFS_WINATTR_READONLY){
1391 dosmode |= FILE_ATTRIBUTE_READONLY;
1393 if (winattrs & GPFS_WINATTR_SPARSE_FILE) {
1394 dosmode |= FILE_ATTRIBUTE_SPARSE;
1396 if (winattrs & GPFS_WINATTR_OFFLINE) {
1397 dosmode |= FILE_ATTRIBUTE_OFFLINE;
1403 static unsigned int vfs_gpfs_dosmode_to_winattrs(uint32_t dosmode)
1405 unsigned int winattrs = 0;
1407 if (dosmode & FILE_ATTRIBUTE_ARCHIVE){
1408 winattrs |= GPFS_WINATTR_ARCHIVE;
1410 if (dosmode & FILE_ATTRIBUTE_HIDDEN){
1411 winattrs |= GPFS_WINATTR_HIDDEN;
1413 if (dosmode & FILE_ATTRIBUTE_SYSTEM){
1414 winattrs |= GPFS_WINATTR_SYSTEM;
1416 if (dosmode & FILE_ATTRIBUTE_READONLY){
1417 winattrs |= GPFS_WINATTR_READONLY;
1419 if (dosmode & FILE_ATTRIBUTE_SPARSE) {
1420 winattrs |= GPFS_WINATTR_SPARSE_FILE;
1422 if (dosmode & FILE_ATTRIBUTE_OFFLINE) {
1423 winattrs |= GPFS_WINATTR_OFFLINE;
1429 static NTSTATUS vfs_gpfs_get_file_id(struct gpfs_iattr64 *iattr,
1432 uint8_t input[sizeof(gpfs_ino64_t) +
1433 sizeof(gpfs_gen64_t) +
1434 sizeof(gpfs_snapid64_t)];
1435 uint8_t digest[gnutls_hash_get_len(GNUTLS_DIG_SHA1)];
1438 DBG_DEBUG("ia_inode 0x%llx, ia_gen 0x%llx, ia_modsnapid 0x%llx\n",
1439 iattr->ia_inode, iattr->ia_gen, iattr->ia_modsnapid);
1442 0, iattr->ia_inode);
1444 sizeof(gpfs_ino64_t), iattr->ia_gen);
1446 sizeof(gpfs_ino64_t) + sizeof(gpfs_gen64_t), iattr->ia_modsnapid);
1448 GNUTLS_FIPS140_SET_LAX_MODE();
1449 rc = gnutls_hash_fast(GNUTLS_DIG_SHA1, input, sizeof(input), &digest);
1450 GNUTLS_FIPS140_SET_STRICT_MODE();
1453 return gnutls_error_to_ntstatus(rc,
1454 NT_STATUS_HASH_NOT_SUPPORTED);
1457 memcpy(fileid, &digest, sizeof(*fileid));
1458 DBG_DEBUG("file_id 0x%" PRIx64 "\n", *fileid);
1460 return NT_STATUS_OK;
1463 static struct timespec gpfs_timestruc64_to_timespec(struct gpfs_timestruc64 g)
1465 return (struct timespec) { .tv_sec = g.tv_sec, .tv_nsec = g.tv_nsec };
1468 static NTSTATUS vfs_gpfs_fget_dos_attributes(struct vfs_handle_struct *handle,
1469 struct files_struct *fsp,
1472 struct gpfs_config_data *config;
1473 int fd = fsp_get_pathref_fd(fsp);
1475 const char *p = NULL;
1476 struct gpfs_iattr64 iattr = { };
1477 unsigned int litemask;
1483 SMB_VFS_HANDLE_GET_DATA(handle, config,
1484 struct gpfs_config_data,
1485 return NT_STATUS_INTERNAL_ERROR);
1487 if (!config->winattr) {
1488 return SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1491 if (fsp->fsp_flags.is_pathref && !config->pathref_ok.gpfs_fstat_x) {
1492 if (fsp->fsp_flags.have_proc_fds) {
1493 p = sys_proc_fd_path(fd, buf, sizeof(buf));
1495 return NT_STATUS_NO_MEMORY;
1498 p = fsp->fsp_name->base_name;
1503 ret = gpfswrap_stat_x(p, &litemask, &iattr, sizeof(iattr));
1505 ret = gpfswrap_fstat_x(fd, &litemask, &iattr, sizeof(iattr));
1507 if (ret == -1 && errno == ENOSYS) {
1508 return SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1511 if (ret == -1 && errno == EACCES) {
1512 int saved_errno = 0;
1515 * According to MS-FSA 2.1.5.1.2.1 "Algorithm to Check Access to
1516 * an Existing File" FILE_LIST_DIRECTORY on a directory implies
1517 * FILE_READ_ATTRIBUTES for directory entries. Being able to
1518 * open a file implies FILE_LIST_DIRECTORY.
1521 set_effective_capability(DAC_OVERRIDE_CAPABILITY);
1524 ret = gpfswrap_stat_x(p,
1529 ret = gpfswrap_fstat_x(fd,
1535 saved_errno = errno;
1538 drop_effective_capability(DAC_OVERRIDE_CAPABILITY);
1540 if (saved_errno != 0) {
1541 errno = saved_errno;
1546 DBG_WARNING("Getting winattrs failed for %s: %s\n",
1547 fsp->fsp_name->base_name, strerror(errno));
1548 return map_nt_error_from_unix(errno);
1551 ZERO_STRUCT(file_id);
1552 status = vfs_gpfs_get_file_id(&iattr, &file_id);
1553 if (!NT_STATUS_IS_OK(status)) {
1557 ts = gpfs_timestruc64_to_timespec(iattr.ia_createtime);
1559 *dosmode |= vfs_gpfs_winattrs_to_dosmode(iattr.ia_winflags);
1560 update_stat_ex_create_time(&fsp->fsp_name->st, ts);
1561 update_stat_ex_file_id(&fsp->fsp_name->st, file_id);
1563 return NT_STATUS_OK;
1566 static NTSTATUS vfs_gpfs_fset_dos_attributes(struct vfs_handle_struct *handle,
1567 struct files_struct *fsp,
1570 struct gpfs_config_data *config;
1571 struct gpfs_winattr attrs = { };
1574 SMB_VFS_HANDLE_GET_DATA(handle, config,
1575 struct gpfs_config_data,
1576 return NT_STATUS_INTERNAL_ERROR);
1578 if (!config->winattr) {
1579 return SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1582 attrs.winAttrs = vfs_gpfs_dosmode_to_winattrs(dosmode);
1584 if (!fsp->fsp_flags.is_pathref) {
1585 ret = gpfswrap_set_winattrs(fsp_get_io_fd(fsp),
1586 GPFS_WINATTR_SET_ATTRS, &attrs);
1588 DBG_WARNING("Setting winattrs failed for %s: %s\n",
1589 fsp_str_dbg(fsp), strerror(errno));
1590 return map_nt_error_from_unix(errno);
1592 return NT_STATUS_OK;
1595 if (fsp->fsp_flags.have_proc_fds) {
1596 int fd = fsp_get_pathref_fd(fsp);
1597 const char *p = NULL;
1600 p = sys_proc_fd_path(fd, buf, sizeof(buf));
1602 return NT_STATUS_NO_MEMORY;
1605 ret = gpfswrap_set_winattrs_path(p,
1606 GPFS_WINATTR_SET_ATTRS,
1609 DBG_WARNING("Setting winattrs failed for [%s][%s]: %s\n",
1610 p, fsp_str_dbg(fsp), strerror(errno));
1611 return map_nt_error_from_unix(errno);
1613 return NT_STATUS_OK;
1617 * This is no longer a handle based call.
1619 ret = gpfswrap_set_winattrs_path(fsp->fsp_name->base_name,
1620 GPFS_WINATTR_SET_ATTRS,
1623 DBG_WARNING("Setting winattrs failed for [%s]: %s\n",
1624 fsp_str_dbg(fsp), strerror(errno));
1625 return map_nt_error_from_unix(errno);
1628 return NT_STATUS_OK;
1631 static int stat_with_capability(struct vfs_handle_struct *handle,
1632 struct smb_filename *smb_fname, int flag)
1636 struct smb_filename *dir_name = NULL;
1637 struct smb_filename *rel_name = NULL;
1641 status = SMB_VFS_PARENT_PATHNAME(handle->conn,
1646 if (!NT_STATUS_IS_OK(status)) {
1647 errno = map_errno_from_nt_status(status);
1651 fd = open(dir_name->base_name, O_RDONLY, 0);
1653 TALLOC_FREE(dir_name);
1657 set_effective_capability(DAC_OVERRIDE_CAPABILITY);
1658 ret = fstatat(fd, rel_name->base_name, &st, flag);
1659 drop_effective_capability(DAC_OVERRIDE_CAPABILITY);
1661 TALLOC_FREE(dir_name);
1665 init_stat_ex_from_stat(
1666 &smb_fname->st, &st,
1667 lp_fake_directory_create_times(SNUM(handle->conn)));
1673 static int vfs_gpfs_stat(struct vfs_handle_struct *handle,
1674 struct smb_filename *smb_fname)
1678 ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
1679 if (ret == -1 && errno == EACCES) {
1680 DEBUG(10, ("Trying stat with capability for %s\n",
1681 smb_fname->base_name));
1682 ret = stat_with_capability(handle, smb_fname, 0);
1687 static int vfs_gpfs_lstat(struct vfs_handle_struct *handle,
1688 struct smb_filename *smb_fname)
1692 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1693 if (ret == -1 && errno == EACCES) {
1694 DEBUG(10, ("Trying lstat with capability for %s\n",
1695 smb_fname->base_name));
1696 ret = stat_with_capability(handle, smb_fname,
1697 AT_SYMLINK_NOFOLLOW);
1702 static void timespec_to_gpfs_time(struct timespec ts, gpfs_timestruc_t *gt,
1703 int idx, int *flags)
1705 if (!is_omit_timespec(&ts)) {
1707 gt[idx].tv_sec = ts.tv_sec;
1708 gt[idx].tv_nsec = ts.tv_nsec;
1709 DEBUG(10, ("Setting GPFS time %d, flags 0x%x\n", idx, *flags));
1713 static int smbd_gpfs_set_times(struct files_struct *fsp,
1714 struct smb_file_time *ft)
1716 gpfs_timestruc_t gpfs_times[4];
1720 ZERO_ARRAY(gpfs_times);
1721 timespec_to_gpfs_time(ft->atime, gpfs_times, 0, &flags);
1722 timespec_to_gpfs_time(ft->mtime, gpfs_times, 1, &flags);
1723 /* No good mapping from LastChangeTime to ctime, not storing */
1724 timespec_to_gpfs_time(ft->create_time, gpfs_times, 3, &flags);
1727 DBG_DEBUG("nothing to do, return to avoid EINVAL\n");
1731 if (!fsp->fsp_flags.is_pathref) {
1732 rc = gpfswrap_set_times(fsp_get_io_fd(fsp), flags, gpfs_times);
1734 DBG_WARNING("gpfs_set_times(%s) failed: %s\n",
1735 fsp_str_dbg(fsp), strerror(errno));
1741 if (fsp->fsp_flags.have_proc_fds) {
1742 int fd = fsp_get_pathref_fd(fsp);
1743 const char *p = NULL;
1746 p = sys_proc_fd_path(fd, buf, sizeof(buf));
1751 rc = gpfswrap_set_times_path(buf, flags, gpfs_times);
1753 DBG_WARNING("gpfs_set_times_path(%s,%s) failed: %s\n",
1754 fsp_str_dbg(fsp), p, strerror(errno));
1760 * This is no longer a handle based call.
1763 rc = gpfswrap_set_times_path(fsp->fsp_name->base_name,
1767 DBG_WARNING("gpfs_set_times_path(%s) failed: %s\n",
1768 fsp_str_dbg(fsp), strerror(errno));
1773 static int vfs_gpfs_fntimes(struct vfs_handle_struct *handle,
1775 struct smb_file_time *ft)
1778 struct gpfs_winattr attrs;
1780 struct gpfs_config_data *config;
1782 SMB_VFS_HANDLE_GET_DATA(handle,
1784 struct gpfs_config_data,
1787 /* Try to use gpfs_set_times if it is enabled and available */
1788 if (config->settimes) {
1789 return smbd_gpfs_set_times(fsp, ft);
1792 DBG_DEBUG("gpfs_set_times() not available or disabled, "
1793 "use ntimes and winattr\n");
1795 ret = SMB_VFS_NEXT_FNTIMES(handle, fsp, ft);
1797 /* don't complain if access was denied */
1798 if (errno != EPERM && errno != EACCES) {
1799 DBG_WARNING("SMB_VFS_NEXT_FNTIMES failed: %s",
1805 if (is_omit_timespec(&ft->create_time)) {
1806 DBG_DEBUG("Create Time is NULL\n");
1810 if (!config->winattr) {
1815 attrs.creationTime.tv_sec = ft->create_time.tv_sec;
1816 attrs.creationTime.tv_nsec = ft->create_time.tv_nsec;
1818 if (!fsp->fsp_flags.is_pathref) {
1819 ret = gpfswrap_set_winattrs(fsp_get_io_fd(fsp),
1820 GPFS_WINATTR_SET_CREATION_TIME,
1822 if (ret == -1 && errno != ENOSYS) {
1823 DBG_WARNING("Set GPFS ntimes failed %d\n", ret);
1829 if (fsp->fsp_flags.have_proc_fds) {
1830 int fd = fsp_get_pathref_fd(fsp);
1831 const char *p = NULL;
1834 p = sys_proc_fd_path(fd, buf, sizeof(buf));
1839 ret = gpfswrap_set_winattrs_path(p,
1840 GPFS_WINATTR_SET_CREATION_TIME,
1842 if (ret == -1 && errno != ENOSYS) {
1843 DBG_WARNING("Set GPFS ntimes failed %d\n", ret);
1850 * This is no longer a handle based call.
1852 ret = gpfswrap_set_winattrs_path(fsp->fsp_name->base_name,
1853 GPFS_WINATTR_SET_CREATION_TIME,
1855 if (ret == -1 && errno != ENOSYS) {
1856 DBG_WARNING("Set GPFS ntimes failed %d\n", ret);
1863 static int vfs_gpfs_fallocate(struct vfs_handle_struct *handle,
1864 struct files_struct *fsp, uint32_t mode,
1865 off_t offset, off_t len)
1867 if (mode == (VFS_FALLOCATE_FL_PUNCH_HOLE|VFS_FALLOCATE_FL_KEEP_SIZE) &&
1868 !fsp->fsp_flags.is_sparse &&
1869 lp_strict_allocate(SNUM(fsp->conn))) {
1871 * This is from a ZERO_DATA request on a non-sparse
1872 * file. GPFS does not support FL_KEEP_SIZE and thus
1873 * cannot fill the whole again in the subsequent
1874 * fallocate(FL_KEEP_SIZE). Deny this FL_PUNCH_HOLE
1875 * call to not end up with a hole in a non-sparse
1882 return SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1885 static int vfs_gpfs_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1889 struct gpfs_config_data *config;
1891 SMB_VFS_HANDLE_GET_DATA(handle, config,
1892 struct gpfs_config_data,
1895 if (!config->ftruncate) {
1896 return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1899 result = gpfswrap_ftruncate(fsp_get_io_fd(fsp), len);
1900 if ((result == -1) && (errno == ENOSYS)) {
1901 return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1906 static bool vfs_gpfs_is_offline(struct vfs_handle_struct *handle,
1907 const struct smb_filename *fname,
1908 SMB_STRUCT_STAT *sbuf)
1910 struct gpfs_winattr attrs;
1911 struct gpfs_config_data *config;
1914 SMB_VFS_HANDLE_GET_DATA(handle, config,
1915 struct gpfs_config_data,
1918 if (!config->winattr) {
1922 ret = gpfswrap_get_winattrs_path(fname->base_name, &attrs);
1927 if ((attrs.winAttrs & GPFS_WINATTR_OFFLINE) != 0) {
1928 DBG_DEBUG("%s is offline\n", fname->base_name);
1932 DBG_DEBUG("%s is online\n", fname->base_name);
1936 static bool vfs_gpfs_fsp_is_offline(struct vfs_handle_struct *handle,
1937 struct files_struct *fsp)
1939 struct gpfs_fsp_extension *ext;
1941 ext = VFS_FETCH_FSP_EXTENSION(handle, fsp);
1944 * Something bad happened, always ask.
1946 return vfs_gpfs_is_offline(handle, fsp->fsp_name,
1947 &fsp->fsp_name->st);
1952 * As long as it's offline, ask.
1954 ext->offline = vfs_gpfs_is_offline(handle, fsp->fsp_name,
1955 &fsp->fsp_name->st);
1958 return ext->offline;
1961 static bool vfs_gpfs_aio_force(struct vfs_handle_struct *handle,
1962 struct files_struct *fsp)
1964 return vfs_gpfs_fsp_is_offline(handle, fsp);
1967 static ssize_t vfs_gpfs_sendfile(vfs_handle_struct *handle, int tofd,
1968 files_struct *fsp, const DATA_BLOB *hdr,
1969 off_t offset, size_t n)
1971 if (vfs_gpfs_fsp_is_offline(handle, fsp)) {
1975 return SMB_VFS_NEXT_SENDFILE(handle, tofd, fsp, hdr, offset, n);
1979 static int vfs_gpfs_check_pathref_fstat_x(struct gpfs_config_data *config,
1980 struct connection_struct *conn)
1982 struct gpfs_iattr64 iattr = {0};
1983 unsigned int litemask;
1988 fd = open(conn->connectpath, O_PATH);
1990 DBG_ERR("openat() of share with O_PATH failed: %s\n",
1995 ret = gpfswrap_fstat_x(fd, &litemask, &iattr, sizeof(iattr));
1998 config->pathref_ok.gpfs_fstat_x = true;
2002 saved_errno = errno;
2005 DBG_ERR("close failed: %s\n", strerror(errno));
2009 if (saved_errno != EBADF) {
2010 DBG_ERR("gpfswrap_fstat_x() of O_PATH handle failed: %s\n",
2011 strerror(saved_errno));
2019 static int vfs_gpfs_check_pathref(struct gpfs_config_data *config,
2020 struct connection_struct *conn)
2024 * This code path leaves all struct gpfs_config_data.pathref_ok members
2025 * initialized to false.
2031 ret = vfs_gpfs_check_pathref_fstat_x(config, conn);
2040 static int vfs_gpfs_connect(struct vfs_handle_struct *handle,
2041 const char *service, const char *user)
2043 struct gpfs_config_data *config;
2047 ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
2052 if (IS_IPC(handle->conn)) {
2056 gpfswrap_lib_init(0);
2058 config = talloc_zero(handle->conn, struct gpfs_config_data);
2060 DEBUG(0, ("talloc_zero() failed\n"));
2065 check_fstype = lp_parm_bool(SNUM(handle->conn), "gpfs",
2066 "check_fstype", true);
2069 const char *connectpath = handle->conn->connectpath;
2070 struct statfs buf = { 0 };
2072 ret = statfs(connectpath, &buf);
2074 DBG_ERR("statfs failed for share %s at path %s: %s\n",
2075 service, connectpath, strerror(errno));
2076 TALLOC_FREE(config);
2080 if (buf.f_type != GPFS_SUPER_MAGIC) {
2081 DBG_ERR("SMB share %s, path %s not in GPFS file system."
2082 " statfs magic: 0x%jx\n",
2085 (uintmax_t)buf.f_type);
2087 TALLOC_FREE(config);
2092 ret = smbacl4_get_vfs_params(handle->conn, &config->nfs4_params);
2094 TALLOC_FREE(config);
2098 config->sharemodes = lp_parm_bool(SNUM(handle->conn), "gpfs",
2099 "sharemodes", true);
2101 config->leases = lp_parm_bool(SNUM(handle->conn), "gpfs",
2104 config->hsm = lp_parm_bool(SNUM(handle->conn), "gpfs",
2107 config->syncio = lp_parm_bool(SNUM(handle->conn), "gpfs",
2110 config->winattr = lp_parm_bool(SNUM(handle->conn), "gpfs",
2113 config->ftruncate = lp_parm_bool(SNUM(handle->conn), "gpfs",
2116 config->getrealfilename = lp_parm_bool(SNUM(handle->conn), "gpfs",
2117 "getrealfilename", true);
2119 config->dfreequota = lp_parm_bool(SNUM(handle->conn), "gpfs",
2120 "dfreequota", false);
2122 config->acl = lp_parm_bool(SNUM(handle->conn), "gpfs", "acl", true);
2124 config->settimes = lp_parm_bool(SNUM(handle->conn), "gpfs",
2126 config->recalls = lp_parm_bool(SNUM(handle->conn), "gpfs",
2129 ret = vfs_gpfs_check_pathref(config, handle->conn);
2131 DBG_ERR("vfs_gpfs_check_pathref() on [%s] failed\n",
2132 handle->conn->connectpath);
2133 TALLOC_FREE(config);
2137 SMB_VFS_HANDLE_SET_DATA(handle, config,
2138 NULL, struct gpfs_config_data,
2141 if (config->leases) {
2143 * GPFS lease code is based on kernel oplock code
2144 * so make sure it is turned on
2146 if (!lp_kernel_oplocks(SNUM(handle->conn))) {
2147 DEBUG(5, ("Enabling kernel oplocks for "
2148 "gpfs:leases to work\n"));
2149 lp_do_parameter(SNUM(handle->conn), "kernel oplocks",
2154 * as the kernel does not properly support Level II oplocks
2155 * and GPFS leases code is based on kernel infrastructure, we
2156 * need to turn off Level II oplocks if gpfs:leases is enabled
2158 if (lp_level2_oplocks(SNUM(handle->conn))) {
2159 DEBUG(5, ("gpfs:leases are enabled, disabling "
2160 "Level II oplocks\n"));
2161 lp_do_parameter(SNUM(handle->conn), "level2 oplocks",
2167 * Unless we have an async implementation of get_dos_attributes turn
2170 lp_do_parameter(SNUM(handle->conn), "smbd async dosmode", "false");
2175 static int get_gpfs_quota(const char *pathname, int type, int id,
2176 struct gpfs_quotaInfo *qi)
2180 ret = gpfswrap_quotactl(pathname, GPFS_QCMD(Q_GETQUOTA, type), id, qi);
2183 if (errno == GPFS_E_NO_QUOTA_INST) {
2184 DEBUG(10, ("Quotas disabled on GPFS filesystem.\n"));
2185 } else if (errno != ENOSYS) {
2186 DEBUG(0, ("Get quota failed, type %d, id, %d, "
2187 "errno %d.\n", type, id, errno));
2193 DEBUG(10, ("quota type %d, id %d, blk u:%lld h:%lld s:%lld gt:%u\n",
2194 type, id, qi->blockUsage, qi->blockHardLimit,
2195 qi->blockSoftLimit, qi->blockGraceTime));
2200 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi, time_t cur_time,
2201 uint64_t *dfree, uint64_t *dsize)
2203 uint64_t usage, limit;
2206 * The quota reporting is done in units of 1024 byte blocks, but
2207 * sys_fsusage uses units of 512 byte blocks, adjust the block number
2208 * accordingly. Also filter possibly negative usage counts from gpfs.
2210 usage = qi.blockUsage < 0 ? 0 : (uint64_t)qi.blockUsage * 2;
2211 limit = (uint64_t)qi.blockHardLimit * 2;
2214 * When the grace time for the exceeded soft block quota has been
2215 * exceeded, the soft block quota becomes an additional hard limit.
2217 if (qi.blockSoftLimit &&
2218 qi.blockGraceTime && cur_time > qi.blockGraceTime) {
2219 /* report disk as full */
2221 *dsize = MIN(*dsize, usage);
2224 if (!qi.blockHardLimit)
2227 if (usage >= limit) {
2228 /* report disk as full */
2230 *dsize = MIN(*dsize, usage);
2233 /* limit has not been reached, determine "free space" */
2234 *dfree = MIN(*dfree, limit - usage);
2235 *dsize = MIN(*dsize, limit);
2239 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct *handle,
2240 const struct smb_filename *smb_fname,
2245 struct security_unix_token *utok;
2246 struct gpfs_quotaInfo qi_user = { 0 }, qi_group = { 0 };
2247 struct gpfs_config_data *config;
2251 SMB_VFS_HANDLE_GET_DATA(handle, config, struct gpfs_config_data,
2252 return (uint64_t)-1);
2253 if (!config->dfreequota) {
2254 return SMB_VFS_NEXT_DISK_FREE(handle, smb_fname,
2255 bsize, dfree, dsize);
2258 err = sys_fsusage(smb_fname->base_name, dfree, dsize);
2260 DEBUG (0, ("Could not get fs usage, errno %d\n", errno));
2261 return SMB_VFS_NEXT_DISK_FREE(handle, smb_fname,
2262 bsize, dfree, dsize);
2265 /* sys_fsusage returns units of 512 bytes */
2268 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
2269 (unsigned long long)*dfree, (unsigned long long)*dsize));
2271 utok = handle->conn->session_info->unix_token;
2273 err = get_gpfs_quota(smb_fname->base_name,
2274 GPFS_USRQUOTA, utok->uid, &qi_user);
2276 return SMB_VFS_NEXT_DISK_FREE(handle, smb_fname,
2277 bsize, dfree, dsize);
2281 * If new files created under this folder get this folder's
2282 * GID, then available space is governed by the quota of the
2283 * folder's GID, not the primary group of the creating user.
2285 if (VALID_STAT(smb_fname->st) &&
2286 S_ISDIR(smb_fname->st.st_ex_mode) &&
2287 smb_fname->st.st_ex_mode & S_ISGID) {
2289 err = get_gpfs_quota(smb_fname->base_name, GPFS_GRPQUOTA,
2290 smb_fname->st.st_ex_gid, &qi_group);
2294 err = get_gpfs_quota(smb_fname->base_name, GPFS_GRPQUOTA,
2295 utok->gid, &qi_group);
2299 return SMB_VFS_NEXT_DISK_FREE(handle, smb_fname,
2300 bsize, dfree, dsize);
2303 cur_time = time(NULL);
2305 /* Adjust free space and size according to quota limits. */
2306 vfs_gpfs_disk_free_quota(qi_user, cur_time, dfree, dsize);
2307 vfs_gpfs_disk_free_quota(qi_group, cur_time, dfree, dsize);
2312 static int vfs_gpfs_get_quota(vfs_handle_struct *handle,
2313 const struct smb_filename *smb_fname,
2314 enum SMB_QUOTA_TYPE qtype,
2320 * User/group quota are being used for disk-free
2321 * determination, which in this module is done directly
2322 * by the disk-free function. It's important that this
2323 * module does not return wrong quota values by mistake,
2324 * which would modify the correct values set by disk-free.
2325 * User/group quota are also being used for processing
2326 * NT_TRANSACT_GET_USER_QUOTA in smb1 protocol, which is
2327 * currently not supported by this module.
2329 case SMB_USER_QUOTA_TYPE:
2330 case SMB_GROUP_QUOTA_TYPE:
2334 return SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname,
2339 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct *handle,
2340 enum timestamp_set_resolution *p_ts_res)
2342 struct gpfs_config_data *config;
2345 next = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
2347 SMB_VFS_HANDLE_GET_DATA(handle, config,
2348 struct gpfs_config_data,
2352 next |= FILE_SUPPORTS_REMOTE_STORAGE;
2357 static int vfs_gpfs_openat(struct vfs_handle_struct *handle,
2358 const struct files_struct *dirfsp,
2359 const struct smb_filename *smb_fname,
2364 struct gpfs_config_data *config = NULL;
2365 struct gpfs_fsp_extension *ext = NULL;
2368 SMB_VFS_HANDLE_GET_DATA(handle, config,
2369 struct gpfs_config_data,
2372 if (config->hsm && !config->recalls &&
2373 vfs_gpfs_fsp_is_offline(handle, fsp))
2375 DBG_DEBUG("Refusing access to offline file %s\n",
2381 if (config->syncio) {
2385 ext = VFS_ADD_FSP_EXTENSION(handle, fsp, struct gpfs_fsp_extension,
2393 * Assume the file is offline until gpfs tells us it's online.
2395 *ext = (struct gpfs_fsp_extension) { .offline = true };
2397 ret = SMB_VFS_NEXT_OPENAT(handle, dirfsp, smb_fname, fsp, flags, mode);
2399 VFS_REMOVE_FSP_EXTENSION(handle, fsp);
2404 static ssize_t vfs_gpfs_pread(vfs_handle_struct *handle, files_struct *fsp,
2405 void *data, size_t n, off_t offset)
2410 was_offline = vfs_gpfs_fsp_is_offline(handle, fsp);
2412 ret = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
2414 if ((ret != -1) && was_offline) {
2415 notify_fname(handle->conn, NOTIFY_ACTION_MODIFIED,
2416 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2417 fsp->fsp_name->base_name);
2423 struct vfs_gpfs_pread_state {
2424 struct files_struct *fsp;
2427 struct vfs_aio_state vfs_aio_state;
2430 static void vfs_gpfs_pread_done(struct tevent_req *subreq);
2432 static struct tevent_req *vfs_gpfs_pread_send(struct vfs_handle_struct *handle,
2433 TALLOC_CTX *mem_ctx,
2434 struct tevent_context *ev,
2435 struct files_struct *fsp,
2436 void *data, size_t n,
2439 struct tevent_req *req, *subreq;
2440 struct vfs_gpfs_pread_state *state;
2442 req = tevent_req_create(mem_ctx, &state, struct vfs_gpfs_pread_state);
2446 state->was_offline = vfs_gpfs_fsp_is_offline(handle, fsp);
2448 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
2450 if (tevent_req_nomem(subreq, req)) {
2451 return tevent_req_post(req, ev);
2453 tevent_req_set_callback(subreq, vfs_gpfs_pread_done, req);
2457 static void vfs_gpfs_pread_done(struct tevent_req *subreq)
2459 struct tevent_req *req = tevent_req_callback_data(
2460 subreq, struct tevent_req);
2461 struct vfs_gpfs_pread_state *state = tevent_req_data(
2462 req, struct vfs_gpfs_pread_state);
2464 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
2465 TALLOC_FREE(subreq);
2466 tevent_req_done(req);
2469 static ssize_t vfs_gpfs_pread_recv(struct tevent_req *req,
2470 struct vfs_aio_state *vfs_aio_state)
2472 struct vfs_gpfs_pread_state *state = tevent_req_data(
2473 req, struct vfs_gpfs_pread_state);
2474 struct files_struct *fsp = state->fsp;
2476 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
2479 *vfs_aio_state = state->vfs_aio_state;
2481 if ((state->ret != -1) && state->was_offline) {
2482 DEBUG(10, ("sending notify\n"));
2483 notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
2484 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2485 fsp->fsp_name->base_name);
2491 static ssize_t vfs_gpfs_pwrite(vfs_handle_struct *handle, files_struct *fsp,
2492 const void *data, size_t n, off_t offset)
2497 was_offline = vfs_gpfs_fsp_is_offline(handle, fsp);
2499 ret = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
2501 if ((ret != -1) && was_offline) {
2502 notify_fname(handle->conn, NOTIFY_ACTION_MODIFIED,
2503 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2504 fsp->fsp_name->base_name);
2510 struct vfs_gpfs_pwrite_state {
2511 struct files_struct *fsp;
2514 struct vfs_aio_state vfs_aio_state;
2517 static void vfs_gpfs_pwrite_done(struct tevent_req *subreq);
2519 static struct tevent_req *vfs_gpfs_pwrite_send(
2520 struct vfs_handle_struct *handle,
2521 TALLOC_CTX *mem_ctx,
2522 struct tevent_context *ev,
2523 struct files_struct *fsp,
2524 const void *data, size_t n,
2527 struct tevent_req *req, *subreq;
2528 struct vfs_gpfs_pwrite_state *state;
2530 req = tevent_req_create(mem_ctx, &state, struct vfs_gpfs_pwrite_state);
2534 state->was_offline = vfs_gpfs_fsp_is_offline(handle, fsp);
2536 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
2538 if (tevent_req_nomem(subreq, req)) {
2539 return tevent_req_post(req, ev);
2541 tevent_req_set_callback(subreq, vfs_gpfs_pwrite_done, req);
2545 static void vfs_gpfs_pwrite_done(struct tevent_req *subreq)
2547 struct tevent_req *req = tevent_req_callback_data(
2548 subreq, struct tevent_req);
2549 struct vfs_gpfs_pwrite_state *state = tevent_req_data(
2550 req, struct vfs_gpfs_pwrite_state);
2552 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
2553 TALLOC_FREE(subreq);
2554 tevent_req_done(req);
2557 static ssize_t vfs_gpfs_pwrite_recv(struct tevent_req *req,
2558 struct vfs_aio_state *vfs_aio_state)
2560 struct vfs_gpfs_pwrite_state *state = tevent_req_data(
2561 req, struct vfs_gpfs_pwrite_state);
2562 struct files_struct *fsp = state->fsp;
2564 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
2567 *vfs_aio_state = state->vfs_aio_state;
2569 if ((state->ret != -1) && state->was_offline) {
2570 DEBUG(10, ("sending notify\n"));
2571 notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
2572 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2573 fsp->fsp_name->base_name);
2580 static struct vfs_fn_pointers vfs_gpfs_fns = {
2581 .connect_fn = vfs_gpfs_connect,
2582 .disk_free_fn = vfs_gpfs_disk_free,
2583 .get_quota_fn = vfs_gpfs_get_quota,
2584 .fs_capabilities_fn = vfs_gpfs_capabilities,
2585 .filesystem_sharemode_fn = vfs_gpfs_filesystem_sharemode,
2586 .linux_setlease_fn = vfs_gpfs_setlease,
2587 .get_real_filename_fn = vfs_gpfs_get_real_filename,
2588 .get_dos_attributes_send_fn = vfs_not_implemented_get_dos_attributes_send,
2589 .get_dos_attributes_recv_fn = vfs_not_implemented_get_dos_attributes_recv,
2590 .fget_dos_attributes_fn = vfs_gpfs_fget_dos_attributes,
2591 .fset_dos_attributes_fn = vfs_gpfs_fset_dos_attributes,
2592 .fget_nt_acl_fn = gpfsacl_fget_nt_acl,
2593 .fset_nt_acl_fn = gpfsacl_fset_nt_acl,
2594 .sys_acl_get_fd_fn = gpfsacl_sys_acl_get_fd,
2595 .sys_acl_blob_get_fd_fn = gpfsacl_sys_acl_blob_get_fd,
2596 .sys_acl_set_fd_fn = gpfsacl_sys_acl_set_fd,
2597 .sys_acl_delete_def_fd_fn = gpfsacl_sys_acl_delete_def_fd,
2598 .fchmod_fn = vfs_gpfs_fchmod,
2599 .close_fn = vfs_gpfs_close,
2600 .stat_fn = vfs_gpfs_stat,
2601 .lstat_fn = vfs_gpfs_lstat,
2602 .fntimes_fn = vfs_gpfs_fntimes,
2603 .aio_force_fn = vfs_gpfs_aio_force,
2604 .sendfile_fn = vfs_gpfs_sendfile,
2605 .fallocate_fn = vfs_gpfs_fallocate,
2606 .openat_fn = vfs_gpfs_openat,
2607 .pread_fn = vfs_gpfs_pread,
2608 .pread_send_fn = vfs_gpfs_pread_send,
2609 .pread_recv_fn = vfs_gpfs_pread_recv,
2610 .pwrite_fn = vfs_gpfs_pwrite,
2611 .pwrite_send_fn = vfs_gpfs_pwrite_send,
2612 .pwrite_recv_fn = vfs_gpfs_pwrite_recv,
2613 .ftruncate_fn = vfs_gpfs_ftruncate
2617 NTSTATUS vfs_gpfs_init(TALLOC_CTX *ctx)
2621 ret = gpfswrap_init();
2623 DEBUG(1, ("Could not initialize GPFS library wrapper\n"));
2626 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "gpfs",