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 unsigned int vfs_gpfs_access_mask_to_allow(uint32_t access_mask)
82 unsigned int allow = GPFS_SHARE_NONE;
84 if (access_mask & (FILE_WRITE_DATA|FILE_APPEND_DATA)) {
85 allow |= GPFS_SHARE_WRITE;
87 if (access_mask & (FILE_READ_DATA|FILE_EXECUTE)) {
88 allow |= GPFS_SHARE_READ;
94 static unsigned int vfs_gpfs_share_access_to_deny(uint32_t share_access)
96 unsigned int deny = GPFS_DENY_NONE;
98 if (!(share_access & FILE_SHARE_WRITE)) {
99 deny |= GPFS_DENY_WRITE;
101 if (!(share_access & FILE_SHARE_READ)) {
102 deny |= GPFS_DENY_READ;
106 * GPFS_DENY_DELETE can only be set together with either
107 * GPFS_DENY_WRITE or GPFS_DENY_READ.
109 if ((deny & (GPFS_DENY_WRITE|GPFS_DENY_READ)) &&
110 !(share_access & FILE_SHARE_DELETE)) {
111 deny |= GPFS_DENY_DELETE;
117 static int set_gpfs_sharemode(files_struct *fsp, uint32_t access_mask,
118 uint32_t share_access)
120 unsigned int allow = GPFS_SHARE_NONE;
121 unsigned int deny = GPFS_DENY_NONE;
124 if (access_mask == 0) {
125 DBG_DEBUG("Clearing file system share mode.\n");
127 allow = vfs_gpfs_access_mask_to_allow(access_mask);
128 deny = vfs_gpfs_share_access_to_deny(share_access);
130 DBG_DEBUG("access_mask=0x%x, allow=0x%x, share_access=0x%x, "
131 "deny=0x%x\n", access_mask, allow, share_access, deny);
133 result = gpfswrap_set_share(fsp->fh->fd, allow, deny);
138 if (errno == EACCES) {
139 DBG_NOTICE("GPFS share mode denied for %s/%s.\n",
140 fsp->conn->connectpath,
141 fsp->fsp_name->base_name);
142 } else if (errno == EPERM) {
143 DBG_ERR("Samba requested GPFS sharemode for %s/%s, but the "
144 "GPFS file system is not configured accordingly. "
145 "Configure file system with mmchfs -D nfs4 or "
146 "set gpfs:sharemodes=no in Samba.\n",
147 fsp->conn->connectpath,
148 fsp->fsp_name->base_name);
150 DBG_ERR("gpfs_set_share failed: %s\n", strerror(errno));
156 static int vfs_gpfs_kernel_flock(vfs_handle_struct *handle, files_struct *fsp,
157 uint32_t share_access, uint32_t access_mask)
160 struct gpfs_config_data *config;
163 START_PROFILE(syscall_kernel_flock);
165 SMB_VFS_HANDLE_GET_DATA(handle, config,
166 struct gpfs_config_data,
169 if(!config->sharemodes) {
174 * A named stream fsp will have the basefile open in the fsp
175 * fd, so lacking a distinct fd for the stream we have to skip
176 * kernel_flock and set_gpfs_sharemode for stream.
178 if (is_named_stream(fsp->fsp_name)) {
179 DBG_NOTICE("Not requesting GPFS sharemode on stream: %s/%s\n",
180 fsp->conn->connectpath,
185 kernel_flock(fsp->fh->fd, share_access, access_mask);
187 ret = set_gpfs_sharemode(fsp, access_mask, share_access);
189 END_PROFILE(syscall_kernel_flock);
194 static int vfs_gpfs_close(vfs_handle_struct *handle, files_struct *fsp)
197 struct gpfs_config_data *config;
199 SMB_VFS_HANDLE_GET_DATA(handle, config,
200 struct gpfs_config_data,
203 if (config->sharemodes && fsp->kernel_share_modes_taken) {
205 * Always clear GPFS sharemode in case the actual
206 * close gets deferred due to outstanding POSIX locks
207 * (see fd_close_posix)
209 int ret = gpfswrap_set_share(fsp->fh->fd, 0, 0);
211 DBG_ERR("Clearing GPFS sharemode on close failed for "
213 fsp->conn->connectpath,
214 fsp->fsp_name->base_name,
219 return SMB_VFS_NEXT_CLOSE(handle, fsp);
222 static int lease_type_to_gpfs(int leasetype)
224 if (leasetype == F_RDLCK) {
225 return GPFS_LEASE_READ;
228 if (leasetype == F_WRLCK) {
229 return GPFS_LEASE_WRITE;
232 return GPFS_LEASE_NONE;
235 static int vfs_gpfs_setlease(vfs_handle_struct *handle,
239 struct gpfs_config_data *config;
242 START_PROFILE(syscall_linux_setlease);
244 SMB_VFS_HANDLE_GET_DATA(handle, config,
245 struct gpfs_config_data,
248 ret = linux_set_lease_sighandler(fsp->fh->fd);
253 if (config->leases) {
254 int gpfs_lease_type = lease_type_to_gpfs(leasetype);
258 * Ensure the lease owner is root to allow
259 * correct delivery of lease-break signals.
262 ret = gpfswrap_set_lease(fsp->fh->fd, gpfs_lease_type);
268 if (saved_errno != 0) {
274 END_PROFILE(syscall_linux_setlease);
279 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct *handle,
286 char *full_path = NULL;
287 char *to_free = NULL;
288 char real_pathname[PATH_MAX+1], tmpbuf[PATH_MAX];
289 size_t full_path_len;
292 struct gpfs_config_data *config;
294 SMB_VFS_HANDLE_GET_DATA(handle, config,
295 struct gpfs_config_data,
298 if (!config->getrealfilename) {
299 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
300 mem_ctx, found_name);
303 mangled = mangle_is_mangled(name, handle->conn->params);
305 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
306 mem_ctx, found_name);
309 full_path_len = full_path_tos(path, name, tmpbuf, sizeof(tmpbuf),
310 &full_path, &to_free);
311 if (full_path_len == -1) {
316 buflen = sizeof(real_pathname) - 1;
318 result = gpfswrap_get_realfilename_path(full_path, real_pathname,
321 TALLOC_FREE(to_free);
323 if ((result == -1) && (errno == ENOSYS)) {
324 return SMB_VFS_NEXT_GET_REAL_FILENAME(
325 handle, path, name, mem_ctx, found_name);
329 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
335 * GPFS does not necessarily null-terminate the returned path
336 * but instead returns the buffer length in buflen.
339 if (buflen < sizeof(real_pathname)) {
340 real_pathname[buflen] = '\0';
342 real_pathname[sizeof(real_pathname)-1] = '\0';
345 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
346 path, name, real_pathname));
348 name = strrchr_m(real_pathname, '/');
354 *found_name = talloc_strdup(mem_ctx, name+1);
355 if (*found_name == NULL) {
363 static void sd2gpfs_control(uint16_t control, struct gpfs_acl *gacl)
365 unsigned int gpfs_aclflags = 0;
366 control &= SEC_DESC_DACL_PROTECTED | SEC_DESC_SACL_PROTECTED |
367 SEC_DESC_DACL_AUTO_INHERITED | SEC_DESC_SACL_AUTO_INHERITED |
368 SEC_DESC_DACL_DEFAULTED | SEC_DESC_SACL_DEFAULTED |
369 SEC_DESC_DACL_PRESENT | SEC_DESC_SACL_PRESENT;
370 gpfs_aclflags = control << 8;
371 if (!(control & SEC_DESC_DACL_PRESENT))
372 gpfs_aclflags |= ACL4_FLAG_NULL_DACL;
373 if (!(control & SEC_DESC_SACL_PRESENT))
374 gpfs_aclflags |= ACL4_FLAG_NULL_SACL;
375 gacl->acl_level = GPFS_ACL_LEVEL_V4FLAGS;
376 gacl->v4Level1.acl_flags = gpfs_aclflags;
379 static uint16_t gpfs2sd_control(unsigned int gpfs_aclflags)
381 uint16_t control = gpfs_aclflags >> 8;
382 control &= SEC_DESC_DACL_PROTECTED | SEC_DESC_SACL_PROTECTED |
383 SEC_DESC_DACL_AUTO_INHERITED | SEC_DESC_SACL_AUTO_INHERITED |
384 SEC_DESC_DACL_DEFAULTED | SEC_DESC_SACL_DEFAULTED |
385 SEC_DESC_DACL_PRESENT | SEC_DESC_SACL_PRESENT;
386 control |= SEC_DESC_SELF_RELATIVE;
390 static void gpfs_dumpacl(int level, struct gpfs_acl *gacl)
395 DEBUG(0, ("gpfs acl is NULL\n"));
399 DEBUG(level, ("len: %d, level: %d, version: %d, nace: %d, "
401 gacl->acl_len, gacl->acl_level, gacl->acl_version,
402 gacl->acl_nace, gpfs_acl_flags(gacl)));
404 for(i=0; i<gacl->acl_nace; i++)
406 struct gpfs_ace_v4 *gace = gpfs_ace_ptr(gacl, i);
407 DEBUG(level, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, "
408 "iflags:0x%x, who:%u\n",
409 i, gace->aceType, gace->aceFlags, gace->aceMask,
410 gace->aceIFlags, gace->aceWho));
414 static int gpfs_getacl_with_capability(const char *fname, int flags, void *buf)
416 int ret, saved_errno;
418 set_effective_capability(DAC_OVERRIDE_CAPABILITY);
420 ret = gpfswrap_getacl(fname, flags, buf);
423 drop_effective_capability(DAC_OVERRIDE_CAPABILITY);
430 * get the ACL from GPFS, allocated on the specified mem_ctx
431 * internally retries when initial buffer was too small
433 * caller needs to cast result to either
434 * raw = yes: struct gpfs_opaque_acl
435 * raw = no: struct gpfs_acl
438 static void *vfs_gpfs_getacl(TALLOC_CTX *mem_ctx,
441 const gpfs_aclType_t type)
449 bool use_capability = false;
453 aclbuf = talloc_zero_size(mem_ctx, size);
454 if (aclbuf == NULL) {
460 struct gpfs_opaque_acl *buf = (struct gpfs_opaque_acl *) aclbuf;
461 buf->acl_type = type;
462 flags = GPFS_GETACL_NATIVE;
463 len = (unsigned int *) &(buf->acl_buffer_len);
464 struct_size = sizeof(struct gpfs_opaque_acl);
466 struct gpfs_acl *buf = (struct gpfs_acl *) aclbuf;
467 buf->acl_type = type;
468 buf->acl_level = GPFS_ACL_LEVEL_V4FLAGS;
469 flags = GPFS_GETACL_STRUCT;
470 len = &(buf->acl_len);
471 /* reserve space for control flags in gpfs 3.5 and beyond */
472 struct_size = sizeof(struct gpfs_acl) + sizeof(unsigned int);
475 /* set the length of the buffer as input value */
478 if (use_capability) {
479 ret = gpfs_getacl_with_capability(fname, flags, aclbuf);
481 ret = gpfswrap_getacl(fname, flags, aclbuf);
482 if ((ret != 0) && (errno == EACCES)) {
483 DBG_DEBUG("Retry with DAC capability for %s\n", fname);
484 use_capability = true;
485 ret = gpfs_getacl_with_capability(fname, flags, aclbuf);
489 if ((ret != 0) && (errno == ENOSPC)) {
491 * get the size needed to accommodate the complete buffer
493 * the value returned only applies to the ACL blob in the
494 * struct so make sure to also have headroom for the first
495 * struct members by adding room for the complete struct
496 * (might be a few bytes too much then)
498 size = *len + struct_size;
500 DEBUG(10, ("Increasing ACL buffer size to %zu\n", size));
505 DEBUG(5, ("smbd_gpfs_getacl failed with %s\n",
514 /* Tries to get nfs4 acls and returns SMB ACL allocated.
515 * On failure returns 1 if it got non-NFSv4 ACL to prompt
516 * retry with POSIX ACL checks.
517 * On failure returns -1 if there is system (GPFS) error, check errno.
518 * Returns 0 on success
520 static int gpfs_get_nfs4_acl(TALLOC_CTX *mem_ctx, const char *fname,
521 struct SMB4ACL_T **ppacl)
524 struct gpfs_acl *gacl = NULL;
525 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname));
528 gacl = (struct gpfs_acl*) vfs_gpfs_getacl(talloc_tos(), fname,
531 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
532 fname, strerror(errno)));
533 if (errno == ENODATA) {
535 * GPFS returns ENODATA for snapshot
536 * directories. Retry with POSIX ACLs check.
544 if (gacl->acl_type != GPFS_ACL_TYPE_NFS4) {
545 DEBUG(10, ("Got non-nfsv4 acl\n"));
546 /* Retry with POSIX ACLs check */
551 *ppacl = smb_create_smb4acl(mem_ctx);
553 if (gacl->acl_level == GPFS_ACL_LEVEL_V4FLAGS) {
554 uint16_t control = gpfs2sd_control(gpfs_acl_flags(gacl));
555 smbacl4_set_controlflags(*ppacl, control);
558 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d, control: %x\n",
559 gacl->acl_len, gacl->acl_level, gacl->acl_version,
560 gacl->acl_nace, gpfs_acl_flags(gacl)));
562 for (i=0; i<gacl->acl_nace; i++) {
563 struct gpfs_ace_v4 *gace = gpfs_ace_ptr(gacl, i);
564 SMB_ACE4PROP_T smbace = { 0 };
565 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
566 "who: %d\n", gace->aceType, gace->aceIFlags,
567 gace->aceFlags, gace->aceMask, gace->aceWho));
569 if (gace->aceIFlags & ACE4_IFLAG_SPECIAL_ID) {
570 smbace.flags |= SMB_ACE4_ID_SPECIAL;
571 switch (gace->aceWho) {
572 case ACE4_SPECIAL_OWNER:
573 smbace.who.special_id = SMB_ACE4_WHO_OWNER;
575 case ACE4_SPECIAL_GROUP:
576 smbace.who.special_id = SMB_ACE4_WHO_GROUP;
578 case ACE4_SPECIAL_EVERYONE:
579 smbace.who.special_id = SMB_ACE4_WHO_EVERYONE;
582 DEBUG(8, ("invalid special gpfs id %d "
583 "ignored\n", gace->aceWho));
584 continue; /* don't add it */
587 if (gace->aceFlags & ACE4_FLAG_GROUP_ID)
588 smbace.who.gid = gace->aceWho;
590 smbace.who.uid = gace->aceWho;
593 /* remove redundant deny entries */
594 if (i > 0 && gace->aceType == SMB_ACE4_ACCESS_DENIED_ACE_TYPE) {
595 struct gpfs_ace_v4 *prev = gpfs_ace_ptr(gacl, i - 1);
596 if (prev->aceType == SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE &&
597 prev->aceFlags == gace->aceFlags &&
598 prev->aceIFlags == gace->aceIFlags &&
599 (gace->aceMask & prev->aceMask) == 0 &&
600 gace->aceWho == prev->aceWho) {
601 /* it's redundant - skip it */
606 smbace.aceType = gace->aceType;
607 smbace.aceFlags = gace->aceFlags;
608 smbace.aceMask = gace->aceMask;
609 smb_add_ace4(*ppacl, &smbace);
617 static NTSTATUS gpfsacl_fget_nt_acl(vfs_handle_struct *handle,
618 files_struct *fsp, uint32_t security_info,
620 struct security_descriptor **ppdesc)
622 struct SMB4ACL_T *pacl = NULL;
624 struct gpfs_config_data *config;
625 TALLOC_CTX *frame = talloc_stackframe();
630 SMB_VFS_HANDLE_GET_DATA(handle, config,
631 struct gpfs_config_data,
632 return NT_STATUS_INTERNAL_ERROR);
635 status = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
641 result = gpfs_get_nfs4_acl(frame, fsp->fsp_name->base_name, &pacl);
644 status = smb_fget_nt_acl_nfs4(fsp, &config->nfs4_params,
646 mem_ctx, ppdesc, pacl);
652 DEBUG(10, ("retrying with posix acl...\n"));
653 status = posix_fget_nt_acl(fsp, security_info,
661 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
662 return map_nt_error_from_unix(errno);
665 static NTSTATUS gpfsacl_get_nt_acl(vfs_handle_struct *handle,
666 const struct smb_filename *smb_fname,
667 uint32_t security_info,
669 struct security_descriptor **ppdesc)
671 struct SMB4ACL_T *pacl = NULL;
673 struct gpfs_config_data *config;
674 TALLOC_CTX *frame = talloc_stackframe();
679 SMB_VFS_HANDLE_GET_DATA(handle, config,
680 struct gpfs_config_data,
681 return NT_STATUS_INTERNAL_ERROR);
684 status = SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname,
691 result = gpfs_get_nfs4_acl(frame, smb_fname->base_name, &pacl);
694 status = smb_get_nt_acl_nfs4(handle->conn, smb_fname,
695 &config->nfs4_params,
696 security_info, mem_ctx, ppdesc,
703 DEBUG(10, ("retrying with posix acl...\n"));
704 status = posix_get_nt_acl(handle->conn, smb_fname,
705 security_info, mem_ctx, ppdesc);
710 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
712 return map_nt_error_from_unix(errno);
715 static bool vfs_gpfs_nfs4_ace_to_gpfs_ace(SMB_ACE4PROP_T *nfs4_ace,
716 struct gpfs_ace_v4 *gace,
719 gace->aceType = nfs4_ace->aceType;
720 gace->aceFlags = nfs4_ace->aceFlags;
721 gace->aceMask = nfs4_ace->aceMask;
723 if (nfs4_ace->flags & SMB_ACE4_ID_SPECIAL) {
724 switch(nfs4_ace->who.special_id) {
725 case SMB_ACE4_WHO_EVERYONE:
726 gace->aceIFlags = ACE4_IFLAG_SPECIAL_ID;
727 gace->aceWho = ACE4_SPECIAL_EVERYONE;
729 case SMB_ACE4_WHO_OWNER:
731 * With GPFS it is not possible to deny ACL or
732 * attribute access to the owner. Setting an
733 * ACL with such an entry is not possible.
734 * Denying ACL or attribute access for the
735 * owner through a named ACL entry can be
736 * stored in an ACL, it is just not effective.
738 * Map this case to a named entry to allow at
739 * least setting this ACL, which will be
740 * enforced by the smbd permission check. Do
741 * not do this for an inheriting OWNER entry,
742 * as this represents a CREATOR OWNER ACE. The
743 * remaining limitation is that CREATOR OWNER
744 * cannot deny ACL or attribute access.
746 if (!nfs_ace_is_inherit(nfs4_ace) &&
748 SMB_ACE4_ACCESS_DENIED_ACE_TYPE &&
749 nfs4_ace->aceMask & (SMB_ACE4_READ_ATTRIBUTES|
750 SMB_ACE4_WRITE_ATTRIBUTES|
752 SMB_ACE4_WRITE_ACL)) {
754 gace->aceWho = owner_uid;
756 gace->aceIFlags = ACE4_IFLAG_SPECIAL_ID;
757 gace->aceWho = ACE4_SPECIAL_OWNER;
760 case SMB_ACE4_WHO_GROUP:
761 gace->aceIFlags = ACE4_IFLAG_SPECIAL_ID;
762 gace->aceWho = ACE4_SPECIAL_GROUP;
765 DBG_WARNING("Unsupported special_id %d\n",
766 nfs4_ace->who.special_id);
774 gace->aceWho = (nfs4_ace->aceFlags & SMB_ACE4_IDENTIFIER_GROUP) ?
775 nfs4_ace->who.gid : nfs4_ace->who.uid;
780 static struct gpfs_acl *vfs_gpfs_smbacl2gpfsacl(TALLOC_CTX *mem_ctx,
782 struct SMB4ACL_T *smbacl,
785 struct gpfs_acl *gacl;
786 gpfs_aclLen_t gacl_len;
787 struct SMB4ACE_T *smbace;
789 gacl_len = offsetof(gpfs_acl_t, ace_v4) + sizeof(unsigned int)
790 + smb_get_naces(smbacl) * sizeof(gpfs_ace_v4_t);
792 gacl = (struct gpfs_acl *)TALLOC_SIZE(mem_ctx, gacl_len);
794 DEBUG(0, ("talloc failed\n"));
799 gacl->acl_level = GPFS_ACL_LEVEL_BASE;
800 gacl->acl_version = GPFS_ACL_VERSION_NFS4;
801 gacl->acl_type = GPFS_ACL_TYPE_NFS4;
802 gacl->acl_nace = 0; /* change later... */
805 gacl->acl_level = GPFS_ACL_LEVEL_V4FLAGS;
806 sd2gpfs_control(smbacl4_get_controlflags(smbacl), gacl);
809 for (smbace=smb_first_ace4(smbacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
810 struct gpfs_ace_v4 *gace = gpfs_ace_ptr(gacl, gacl->acl_nace);
811 SMB_ACE4PROP_T *aceprop = smb_get_ace4(smbace);
814 add_ace = vfs_gpfs_nfs4_ace_to_gpfs_ace(aceprop, gace,
815 fsp->fsp_name->st.st_ex_uid);
822 gacl->acl_len = (char *)gpfs_ace_ptr(gacl, gacl->acl_nace)
827 static bool gpfsacl_process_smbacl(vfs_handle_struct *handle,
829 struct SMB4ACL_T *smbacl)
832 struct gpfs_acl *gacl;
833 TALLOC_CTX *mem_ctx = talloc_tos();
835 gacl = vfs_gpfs_smbacl2gpfsacl(mem_ctx, fsp, smbacl, true);
836 if (gacl == NULL) { /* out of memory */
839 ret = gpfswrap_putacl(fsp->fsp_name->base_name,
840 GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gacl);
842 if ((ret != 0) && (errno == EINVAL)) {
843 DEBUG(10, ("Retry without nfs41 control flags\n"));
845 gacl = vfs_gpfs_smbacl2gpfsacl(mem_ctx, fsp, smbacl, false);
846 if (gacl == NULL) { /* out of memory */
849 ret = gpfswrap_putacl(fsp->fsp_name->base_name,
850 GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA,
855 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno)));
856 gpfs_dumpacl(8, gacl);
860 DEBUG(10, ("gpfs_putacl succeeded\n"));
864 static NTSTATUS gpfsacl_set_nt_acl_internal(vfs_handle_struct *handle, files_struct *fsp, uint32_t security_info_sent, const struct security_descriptor *psd)
866 struct gpfs_acl *acl;
867 NTSTATUS result = NT_STATUS_ACCESS_DENIED;
869 acl = (struct gpfs_acl*) vfs_gpfs_getacl(talloc_tos(),
870 fsp->fsp_name->base_name,
873 return map_nt_error_from_unix(errno);
876 if (acl->acl_version == GPFS_ACL_VERSION_NFS4) {
877 struct gpfs_config_data *config;
879 if (lp_parm_bool(fsp->conn->params->service, "gpfs",
880 "refuse_dacl_protected", false)
881 && (psd->type&SEC_DESC_DACL_PROTECTED)) {
882 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
884 return NT_STATUS_NOT_SUPPORTED;
887 SMB_VFS_HANDLE_GET_DATA(handle, config,
888 struct gpfs_config_data,
889 return NT_STATUS_INTERNAL_ERROR);
891 result = smb_set_nt_acl_nfs4(handle,
892 fsp, &config->nfs4_params, security_info_sent, psd,
893 gpfsacl_process_smbacl);
894 } else { /* assume POSIX ACL - by default... */
895 result = set_nt_acl(fsp, security_info_sent, psd);
902 static NTSTATUS gpfsacl_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32_t security_info_sent, const struct security_descriptor *psd)
904 struct gpfs_config_data *config;
906 SMB_VFS_HANDLE_GET_DATA(handle, config,
907 struct gpfs_config_data,
908 return NT_STATUS_INTERNAL_ERROR);
911 return SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
914 return gpfsacl_set_nt_acl_internal(handle, fsp, security_info_sent, psd);
917 static SMB_ACL_T gpfs2smb_acl(const struct gpfs_acl *pacl, TALLOC_CTX *mem_ctx)
922 result = sys_acl_init(mem_ctx);
923 if (result == NULL) {
928 result->count = pacl->acl_nace;
929 result->acl = talloc_realloc(result, result->acl, struct smb_acl_entry,
931 if (result->acl == NULL) {
937 for (i=0; i<pacl->acl_nace; i++) {
938 struct smb_acl_entry *ace = &result->acl[i];
939 const struct gpfs_ace_v1 *g_ace = &pacl->ace_v1[i];
941 DEBUG(10, ("Converting type %d id %lu perm %x\n",
942 (int)g_ace->ace_type, (unsigned long)g_ace->ace_who,
943 (int)g_ace->ace_perm));
945 switch (g_ace->ace_type) {
947 ace->a_type = SMB_ACL_USER;
948 ace->info.user.uid = (uid_t)g_ace->ace_who;
950 case GPFS_ACL_USER_OBJ:
951 ace->a_type = SMB_ACL_USER_OBJ;
954 ace->a_type = SMB_ACL_GROUP;
955 ace->info.group.gid = (gid_t)g_ace->ace_who;
957 case GPFS_ACL_GROUP_OBJ:
958 ace->a_type = SMB_ACL_GROUP_OBJ;
961 ace->a_type = SMB_ACL_OTHER;
964 ace->a_type = SMB_ACL_MASK;
967 DEBUG(10, ("Got invalid ace_type: %d\n",
975 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_READ) ?
977 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_WRITE) ?
979 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_EXECUTE) ?
982 DEBUGADD(10, ("Converted to %d perm %x\n",
983 ace->a_type, ace->a_perm));
989 static SMB_ACL_T gpfsacl_get_posix_acl(const char *path, gpfs_aclType_t type,
992 struct gpfs_acl *pacl;
993 SMB_ACL_T result = NULL;
995 pacl = vfs_gpfs_getacl(talloc_tos(), path, false, type);
998 DEBUG(10, ("vfs_gpfs_getacl failed for %s with %s\n",
999 path, strerror(errno)));
1006 if (pacl->acl_version != GPFS_ACL_VERSION_POSIX) {
1007 DEBUG(10, ("Got acl version %d, expected %d\n",
1008 pacl->acl_version, GPFS_ACL_VERSION_POSIX));
1013 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
1014 pacl->acl_len, pacl->acl_level, pacl->acl_version,
1017 result = gpfs2smb_acl(pacl, mem_ctx);
1018 if (result != NULL) {
1028 TALLOC_FREE(result);
1033 static SMB_ACL_T gpfsacl_sys_acl_get_file(vfs_handle_struct *handle,
1034 const struct smb_filename *smb_fname,
1035 SMB_ACL_TYPE_T type,
1036 TALLOC_CTX *mem_ctx)
1038 gpfs_aclType_t gpfs_type;
1039 struct gpfs_config_data *config;
1041 SMB_VFS_HANDLE_GET_DATA(handle, config,
1042 struct gpfs_config_data,
1046 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, smb_fname,
1051 case SMB_ACL_TYPE_ACCESS:
1052 gpfs_type = GPFS_ACL_TYPE_ACCESS;
1054 case SMB_ACL_TYPE_DEFAULT:
1055 gpfs_type = GPFS_ACL_TYPE_DEFAULT;
1058 DEBUG(0, ("Got invalid type: %d\n", type));
1059 smb_panic("exiting");
1062 return gpfsacl_get_posix_acl(smb_fname->base_name, gpfs_type, mem_ctx);
1065 static SMB_ACL_T gpfsacl_sys_acl_get_fd(vfs_handle_struct *handle,
1067 TALLOC_CTX *mem_ctx)
1069 struct gpfs_config_data *config;
1071 SMB_VFS_HANDLE_GET_DATA(handle, config,
1072 struct gpfs_config_data,
1076 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
1079 return gpfsacl_get_posix_acl(fsp->fsp_name->base_name,
1080 GPFS_ACL_TYPE_ACCESS, mem_ctx);
1083 static int gpfsacl_sys_acl_blob_get_file(vfs_handle_struct *handle,
1084 const struct smb_filename *smb_fname,
1085 TALLOC_CTX *mem_ctx,
1086 char **blob_description,
1089 struct gpfs_config_data *config;
1090 struct gpfs_opaque_acl *acl = NULL;
1093 const char *path_p = smb_fname->base_name;
1095 SMB_VFS_HANDLE_GET_DATA(handle, config,
1096 struct gpfs_config_data,
1100 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, smb_fname,
1107 acl = (struct gpfs_opaque_acl *)
1108 vfs_gpfs_getacl(mem_ctx,
1111 GPFS_ACL_TYPE_NFS4);
1114 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
1115 errno, strerror(errno)));
1117 /* EINVAL means POSIX ACL, bail out on other cases */
1118 if (errno != EINVAL) {
1125 * file has NFSv4 ACL
1127 * we only need the actual ACL blob here
1128 * acl_version will always be NFS4 because we asked
1130 * acl_type is only used for POSIX ACLs
1132 aclblob.data = (uint8_t*) acl->acl_var_data;
1133 aclblob.length = acl->acl_buffer_len;
1135 *blob_description = talloc_strdup(mem_ctx, "gpfs_nfs4_acl");
1136 if (!*blob_description) {
1142 result = non_posix_sys_acl_blob_get_file_helper(handle, smb_fname,
1150 /* fall back to POSIX ACL */
1151 return posix_sys_acl_blob_get_file(handle, smb_fname, mem_ctx,
1152 blob_description, blob);
1155 static int gpfsacl_sys_acl_blob_get_fd(vfs_handle_struct *handle,
1157 TALLOC_CTX *mem_ctx,
1158 char **blob_description,
1161 struct gpfs_config_data *config;
1162 struct gpfs_opaque_acl *acl = NULL;
1166 SMB_VFS_HANDLE_GET_DATA(handle, config,
1167 struct gpfs_config_data,
1171 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx,
1172 blob_description, blob);
1176 acl = (struct gpfs_opaque_acl *) vfs_gpfs_getacl(mem_ctx,
1177 fsp->fsp_name->base_name,
1179 GPFS_ACL_TYPE_NFS4);
1182 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
1183 errno, strerror(errno)));
1185 /* EINVAL means POSIX ACL, bail out on other cases */
1186 if (errno != EINVAL) {
1193 * file has NFSv4 ACL
1195 * we only need the actual ACL blob here
1196 * acl_version will always be NFS4 because we asked
1198 * acl_type is only used for POSIX ACLs
1200 aclblob.data = (uint8_t*) acl->acl_var_data;
1201 aclblob.length = acl->acl_buffer_len;
1203 *blob_description = talloc_strdup(mem_ctx, "gpfs_nfs4_acl");
1204 if (!*blob_description) {
1210 result = non_posix_sys_acl_blob_get_fd_helper(handle, fsp,
1218 /* fall back to POSIX ACL */
1219 return posix_sys_acl_blob_get_fd(handle, fsp, mem_ctx,
1220 blob_description, blob);
1223 static struct gpfs_acl *smb2gpfs_acl(const SMB_ACL_T pacl,
1224 SMB_ACL_TYPE_T type)
1227 struct gpfs_acl *result;
1230 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl->count));
1232 len = offsetof(gpfs_acl_t, ace_v1) + (pacl->count) *
1233 sizeof(gpfs_ace_v1_t);
1235 result = (struct gpfs_acl *)SMB_MALLOC(len);
1236 if (result == NULL) {
1241 result->acl_len = len;
1242 result->acl_level = 0;
1243 result->acl_version = GPFS_ACL_VERSION_POSIX;
1244 result->acl_type = (type == SMB_ACL_TYPE_DEFAULT) ?
1245 GPFS_ACL_TYPE_DEFAULT : GPFS_ACL_TYPE_ACCESS;
1246 result->acl_nace = pacl->count;
1248 for (i=0; i<pacl->count; i++) {
1249 const struct smb_acl_entry *ace = &pacl->acl[i];
1250 struct gpfs_ace_v1 *g_ace = &result->ace_v1[i];
1252 DEBUG(10, ("Converting type %d perm %x\n",
1253 (int)ace->a_type, (int)ace->a_perm));
1255 g_ace->ace_perm = 0;
1257 switch(ace->a_type) {
1259 g_ace->ace_type = GPFS_ACL_USER;
1260 g_ace->ace_who = (gpfs_uid_t)ace->info.user.uid;
1262 case SMB_ACL_USER_OBJ:
1263 g_ace->ace_type = GPFS_ACL_USER_OBJ;
1264 g_ace->ace_perm |= ACL_PERM_CONTROL;
1268 g_ace->ace_type = GPFS_ACL_GROUP;
1269 g_ace->ace_who = (gpfs_uid_t)ace->info.group.gid;
1271 case SMB_ACL_GROUP_OBJ:
1272 g_ace->ace_type = GPFS_ACL_GROUP_OBJ;
1276 g_ace->ace_type = GPFS_ACL_MASK;
1277 g_ace->ace_perm = 0x8f;
1281 g_ace->ace_type = GPFS_ACL_OTHER;
1285 DEBUG(10, ("Got invalid ace_type: %d\n", ace->a_type));
1291 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_READ) ?
1293 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_WRITE) ?
1295 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_EXECUTE) ?
1296 ACL_PERM_EXECUTE : 0;
1298 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
1299 g_ace->ace_type, g_ace->ace_who, g_ace->ace_perm));
1305 static int gpfsacl_sys_acl_set_file(vfs_handle_struct *handle,
1306 const struct smb_filename *smb_fname,
1307 SMB_ACL_TYPE_T type,
1310 struct gpfs_acl *gpfs_acl;
1312 struct gpfs_config_data *config;
1314 SMB_VFS_HANDLE_GET_DATA(handle, config,
1315 struct gpfs_config_data,
1319 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, smb_fname,
1323 gpfs_acl = smb2gpfs_acl(theacl, type);
1324 if (gpfs_acl == NULL) {
1328 result = gpfswrap_putacl(discard_const_p(char, smb_fname->base_name),
1329 GPFS_PUTACL_STRUCT|GPFS_ACL_SAMBA, gpfs_acl);
1331 SAFE_FREE(gpfs_acl);
1335 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct *handle,
1339 struct gpfs_config_data *config;
1341 SMB_VFS_HANDLE_GET_DATA(handle, config,
1342 struct gpfs_config_data,
1346 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
1349 return gpfsacl_sys_acl_set_file(handle, fsp->fsp_name,
1350 SMB_ACL_TYPE_ACCESS, theacl);
1353 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct *handle,
1354 const struct smb_filename *smb_fname)
1356 struct gpfs_config_data *config;
1358 SMB_VFS_HANDLE_GET_DATA(handle, config,
1359 struct gpfs_config_data,
1363 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, smb_fname);
1371 * Assumed: mode bits are shiftable and standard
1372 * Output: the new aceMask field for an smb nfs4 ace
1374 static uint32_t gpfsacl_mask_filter(uint32_t aceType, uint32_t aceMask, uint32_t rwx)
1376 const uint32_t posix_nfs4map[3] = {
1377 SMB_ACE4_EXECUTE, /* execute */
1378 SMB_ACE4_WRITE_DATA | SMB_ACE4_APPEND_DATA, /* write; GPFS specific */
1379 SMB_ACE4_READ_DATA /* read */
1382 uint32_t posix_mask = 0x01;
1386 for(i=0; i<3; i++) {
1387 nfs4_bits = posix_nfs4map[i];
1388 posix_bit = rwx & posix_mask;
1390 if (aceType==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE) {
1392 aceMask |= nfs4_bits;
1394 aceMask &= ~nfs4_bits;
1396 /* add deny bits when suitable */
1398 aceMask |= nfs4_bits;
1400 aceMask &= ~nfs4_bits;
1401 } /* other ace types are unexpected */
1409 static int gpfsacl_emu_chmod(vfs_handle_struct *handle,
1410 const char *path, mode_t mode)
1412 struct SMB4ACL_T *pacl = NULL;
1414 bool haveAllowEntry[SMB_ACE4_WHO_EVERYONE + 1] = {False, False, False, False};
1416 files_struct fake_fsp = { 0 }; /* TODO: rationalize parametrization */
1417 struct SMB4ACE_T *smbace;
1418 TALLOC_CTX *frame = talloc_stackframe();
1420 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path, mode));
1422 result = gpfs_get_nfs4_acl(frame, path, &pacl);
1428 if (mode & ~(S_IRWXU | S_IRWXG | S_IRWXO)) {
1429 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode, path));
1432 for (smbace=smb_first_ace4(pacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
1433 SMB_ACE4PROP_T *ace = smb_get_ace4(smbace);
1434 uint32_t specid = ace->who.special_id;
1436 if (ace->flags&SMB_ACE4_ID_SPECIAL &&
1437 ace->aceType<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE &&
1438 specid <= SMB_ACE4_WHO_EVERYONE) {
1442 if (ace->aceType==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE)
1443 haveAllowEntry[specid] = True;
1445 /* mode >> 6 for @owner, mode >> 3 for @group,
1446 * mode >> 0 for @everyone */
1447 newMask = gpfsacl_mask_filter(ace->aceType, ace->aceMask,
1448 mode >> ((SMB_ACE4_WHO_EVERYONE - specid) * 3));
1449 if (ace->aceMask!=newMask) {
1450 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
1451 path, ace->aceMask, newMask, specid));
1453 ace->aceMask = newMask;
1457 /* make sure we have at least ALLOW entries
1458 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
1461 for(i = SMB_ACE4_WHO_OWNER; i<=SMB_ACE4_WHO_EVERYONE; i++) {
1462 SMB_ACE4PROP_T ace = { 0 };
1464 if (haveAllowEntry[i]==True)
1467 ace.aceType = SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE;
1468 ace.flags |= SMB_ACE4_ID_SPECIAL;
1469 ace.who.special_id = i;
1471 if (i==SMB_ACE4_WHO_GROUP) /* not sure it's necessary... */
1472 ace.aceFlags |= SMB_ACE4_IDENTIFIER_GROUP;
1474 ace.aceMask = gpfsacl_mask_filter(ace.aceType, ace.aceMask,
1475 mode >> ((SMB_ACE4_WHO_EVERYONE - i) * 3));
1477 /* don't add unnecessary aces */
1481 /* we add it to the END - as windows expects allow aces */
1482 smb_add_ace4(pacl, &ace);
1483 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1484 path, mode, i, ace.aceMask));
1487 /* don't add complementary DENY ACEs here */
1488 fake_fsp.fsp_name = synthetic_smb_fname(
1489 frame, path, NULL, NULL, 0);
1490 if (fake_fsp.fsp_name == NULL) {
1496 if (gpfsacl_process_smbacl(handle, &fake_fsp, pacl) == False) {
1502 return 0; /* ok for [f]chmod */
1505 static int vfs_gpfs_chmod(vfs_handle_struct *handle,
1506 const struct smb_filename *smb_fname,
1509 struct smb_filename *smb_fname_cpath;
1512 smb_fname_cpath = cp_smb_filename(talloc_tos(), smb_fname);
1513 if (smb_fname_cpath == NULL) {
1518 if (SMB_VFS_NEXT_STAT(handle, smb_fname_cpath) != 0) {
1519 TALLOC_FREE(smb_fname_cpath);
1523 /* avoid chmod() if possible, to preserve acls */
1524 if ((smb_fname_cpath->st.st_ex_mode & ~S_IFMT) == mode) {
1525 TALLOC_FREE(smb_fname_cpath);
1529 rc = gpfsacl_emu_chmod(handle, smb_fname->base_name, mode);
1531 return SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
1533 TALLOC_FREE(smb_fname_cpath);
1537 static int vfs_gpfs_fchmod(vfs_handle_struct *handle, files_struct *fsp, mode_t mode)
1542 if (SMB_VFS_NEXT_FSTAT(handle, fsp, &st) != 0) {
1546 /* avoid chmod() if possible, to preserve acls */
1547 if ((st.st_ex_mode & ~S_IFMT) == mode) {
1551 rc = gpfsacl_emu_chmod(handle, fsp->fsp_name->base_name,
1554 return SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1558 static uint32_t vfs_gpfs_winattrs_to_dosmode(unsigned int winattrs)
1560 uint32_t dosmode = 0;
1562 if (winattrs & GPFS_WINATTR_ARCHIVE){
1563 dosmode |= FILE_ATTRIBUTE_ARCHIVE;
1565 if (winattrs & GPFS_WINATTR_HIDDEN){
1566 dosmode |= FILE_ATTRIBUTE_HIDDEN;
1568 if (winattrs & GPFS_WINATTR_SYSTEM){
1569 dosmode |= FILE_ATTRIBUTE_SYSTEM;
1571 if (winattrs & GPFS_WINATTR_READONLY){
1572 dosmode |= FILE_ATTRIBUTE_READONLY;
1574 if (winattrs & GPFS_WINATTR_SPARSE_FILE) {
1575 dosmode |= FILE_ATTRIBUTE_SPARSE;
1577 if (winattrs & GPFS_WINATTR_OFFLINE) {
1578 dosmode |= FILE_ATTRIBUTE_OFFLINE;
1584 static unsigned int vfs_gpfs_dosmode_to_winattrs(uint32_t dosmode)
1586 unsigned int winattrs = 0;
1588 if (dosmode & FILE_ATTRIBUTE_ARCHIVE){
1589 winattrs |= GPFS_WINATTR_ARCHIVE;
1591 if (dosmode & FILE_ATTRIBUTE_HIDDEN){
1592 winattrs |= GPFS_WINATTR_HIDDEN;
1594 if (dosmode & FILE_ATTRIBUTE_SYSTEM){
1595 winattrs |= GPFS_WINATTR_SYSTEM;
1597 if (dosmode & FILE_ATTRIBUTE_READONLY){
1598 winattrs |= GPFS_WINATTR_READONLY;
1600 if (dosmode & FILE_ATTRIBUTE_SPARSE) {
1601 winattrs |= GPFS_WINATTR_SPARSE_FILE;
1603 if (dosmode & FILE_ATTRIBUTE_OFFLINE) {
1604 winattrs |= GPFS_WINATTR_OFFLINE;
1610 static int get_dos_attr_with_capability(struct smb_filename *smb_fname,
1611 unsigned int *litemask,
1612 struct gpfs_iattr64 *iattr)
1614 int saved_errno = 0;
1618 * According to MS-FSA 2.1.5.1.2.1 "Algorithm to Check Access to an
1619 * Existing File" FILE_LIST_DIRECTORY on a directory implies
1620 * FILE_READ_ATTRIBUTES for directory entries. Being able to stat() a
1621 * file implies FILE_LIST_DIRECTORY for the directory containing the
1625 if (!VALID_STAT(smb_fname->st)) {
1627 * Safety net: dos_mode() already checks this, but as we set
1628 * DAC_OVERRIDE_CAPABILITY based on this, add an additional
1631 DBG_ERR("Rejecting DAC override, invalid stat [%s]\n",
1632 smb_fname_str_dbg(smb_fname));
1637 set_effective_capability(DAC_OVERRIDE_CAPABILITY);
1639 ret = gpfswrap_stat_x(smb_fname->base_name, litemask,
1640 iattr, sizeof(*iattr));
1642 saved_errno = errno;
1645 drop_effective_capability(DAC_OVERRIDE_CAPABILITY);
1647 if (saved_errno != 0) {
1648 errno = saved_errno;
1653 static NTSTATUS vfs_gpfs_get_file_id(struct gpfs_iattr64 *iattr,
1656 uint8_t input[sizeof(gpfs_ino64_t) +
1657 sizeof(gpfs_gen64_t) +
1658 sizeof(gpfs_snapid64_t)];
1659 uint8_t digest[gnutls_hash_get_len(GNUTLS_DIG_SHA1)];
1662 DBG_DEBUG("ia_inode 0x%llx, ia_gen 0x%llx, ia_modsnapid 0x%llx\n",
1663 iattr->ia_inode, iattr->ia_gen, iattr->ia_modsnapid);
1666 0, iattr->ia_inode);
1668 sizeof(gpfs_ino64_t), iattr->ia_gen);
1670 sizeof(gpfs_ino64_t) + sizeof(gpfs_gen64_t), iattr->ia_modsnapid);
1672 GNUTLS_FIPS140_SET_LAX_MODE();
1673 rc = gnutls_hash_fast(GNUTLS_DIG_SHA1, input, sizeof(input), &digest);
1674 GNUTLS_FIPS140_SET_STRICT_MODE();
1677 return gnutls_error_to_ntstatus(rc,
1678 NT_STATUS_HASH_NOT_SUPPORTED);
1681 memcpy(fileid, &digest, sizeof(*fileid));
1682 DBG_DEBUG("file_id 0x%" PRIx64 "\n", *fileid);
1684 return NT_STATUS_OK;
1687 static struct timespec gpfs_timestruc64_to_timespec(struct gpfs_timestruc64 g)
1689 return (struct timespec) { .tv_sec = g.tv_sec, .tv_nsec = g.tv_nsec };
1692 static NTSTATUS vfs_gpfs_get_dos_attributes(struct vfs_handle_struct *handle,
1693 struct smb_filename *smb_fname,
1696 struct gpfs_config_data *config;
1697 struct gpfs_iattr64 iattr = { };
1698 unsigned int litemask = 0;
1704 SMB_VFS_HANDLE_GET_DATA(handle, config,
1705 struct gpfs_config_data,
1706 return NT_STATUS_INTERNAL_ERROR);
1708 if (!config->winattr) {
1709 return SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
1710 smb_fname, dosmode);
1713 ret = gpfswrap_stat_x(smb_fname->base_name, &litemask,
1714 &iattr, sizeof(iattr));
1715 if (ret == -1 && errno == ENOSYS) {
1716 return SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle, smb_fname,
1719 if (ret == -1 && errno == EACCES) {
1720 ret = get_dos_attr_with_capability(smb_fname, &litemask,
1724 if (ret == -1 && errno == EBADF) {
1726 * Returned for directory listings in gpfs root for
1727 * .. entry which steps out of gpfs.
1729 DBG_DEBUG("Getting winattrs for %s returned EBADF.\n",
1730 smb_fname->base_name);
1731 return map_nt_error_from_unix(errno);
1732 } else if (ret == -1) {
1733 DBG_WARNING("Getting winattrs failed for %s: %s\n",
1734 smb_fname->base_name, strerror(errno));
1735 return map_nt_error_from_unix(errno);
1738 status = vfs_gpfs_get_file_id(&iattr, &file_id);
1739 if (!NT_STATUS_IS_OK(status)) {
1743 ts = gpfs_timestruc64_to_timespec(iattr.ia_createtime);
1745 *dosmode |= vfs_gpfs_winattrs_to_dosmode(iattr.ia_winflags);
1746 update_stat_ex_create_time(&smb_fname->st, ts);
1747 update_stat_ex_file_id(&smb_fname->st, file_id);
1749 return NT_STATUS_OK;
1752 static NTSTATUS vfs_gpfs_fget_dos_attributes(struct vfs_handle_struct *handle,
1753 struct files_struct *fsp,
1756 struct gpfs_config_data *config;
1757 struct gpfs_iattr64 iattr = { };
1758 unsigned int litemask;
1764 SMB_VFS_HANDLE_GET_DATA(handle, config,
1765 struct gpfs_config_data,
1766 return NT_STATUS_INTERNAL_ERROR);
1768 if (!config->winattr) {
1769 return SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1772 ret = gpfswrap_fstat_x(fsp->fh->fd, &litemask, &iattr, sizeof(iattr));
1773 if (ret == -1 && errno == ENOSYS) {
1774 return SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1777 if (ret == -1 && errno == EACCES) {
1778 int saved_errno = 0;
1781 * According to MS-FSA 2.1.5.1.2.1 "Algorithm to Check Access to
1782 * an Existing File" FILE_LIST_DIRECTORY on a directory implies
1783 * FILE_READ_ATTRIBUTES for directory entries. Being able to
1784 * open a file implies FILE_LIST_DIRECTORY.
1787 set_effective_capability(DAC_OVERRIDE_CAPABILITY);
1789 ret = gpfswrap_fstat_x(fsp->fh->fd, &litemask,
1790 &iattr, sizeof(iattr));
1792 saved_errno = errno;
1795 drop_effective_capability(DAC_OVERRIDE_CAPABILITY);
1797 if (saved_errno != 0) {
1798 errno = saved_errno;
1803 DBG_WARNING("Getting winattrs failed for %s: %s\n",
1804 fsp->fsp_name->base_name, strerror(errno));
1805 return map_nt_error_from_unix(errno);
1808 status = vfs_gpfs_get_file_id(&iattr, &file_id);
1809 if (!NT_STATUS_IS_OK(status)) {
1813 ts = gpfs_timestruc64_to_timespec(iattr.ia_createtime);
1815 *dosmode |= vfs_gpfs_winattrs_to_dosmode(iattr.ia_winflags);
1816 update_stat_ex_create_time(&fsp->fsp_name->st, ts);
1817 update_stat_ex_file_id(&fsp->fsp_name->st, file_id);
1819 return NT_STATUS_OK;
1822 static NTSTATUS vfs_gpfs_set_dos_attributes(struct vfs_handle_struct *handle,
1823 const struct smb_filename *smb_fname,
1826 struct gpfs_config_data *config;
1827 struct gpfs_winattr attrs = { };
1830 SMB_VFS_HANDLE_GET_DATA(handle, config,
1831 struct gpfs_config_data,
1832 return NT_STATUS_INTERNAL_ERROR);
1834 if (!config->winattr) {
1835 return SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
1836 smb_fname, dosmode);
1839 attrs.winAttrs = vfs_gpfs_dosmode_to_winattrs(dosmode);
1840 ret = gpfswrap_set_winattrs_path(smb_fname->base_name,
1841 GPFS_WINATTR_SET_ATTRS, &attrs);
1843 if (ret == -1 && errno == ENOSYS) {
1844 return SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
1845 smb_fname, dosmode);
1849 DBG_WARNING("Setting winattrs failed for %s: %s\n",
1850 smb_fname->base_name, strerror(errno));
1851 return map_nt_error_from_unix(errno);
1854 return NT_STATUS_OK;
1857 static NTSTATUS vfs_gpfs_fset_dos_attributes(struct vfs_handle_struct *handle,
1858 struct files_struct *fsp,
1861 struct gpfs_config_data *config;
1862 struct gpfs_winattr attrs = { };
1865 SMB_VFS_HANDLE_GET_DATA(handle, config,
1866 struct gpfs_config_data,
1867 return NT_STATUS_INTERNAL_ERROR);
1869 if (!config->winattr) {
1870 return SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1873 attrs.winAttrs = vfs_gpfs_dosmode_to_winattrs(dosmode);
1874 ret = gpfswrap_set_winattrs(fsp->fh->fd,
1875 GPFS_WINATTR_SET_ATTRS, &attrs);
1877 if (ret == -1 && errno == ENOSYS) {
1878 return SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1882 DBG_WARNING("Setting winattrs failed for %s: %s\n",
1883 fsp->fsp_name->base_name, strerror(errno));
1884 return map_nt_error_from_unix(errno);
1887 return NT_STATUS_OK;
1890 static int stat_with_capability(struct vfs_handle_struct *handle,
1891 struct smb_filename *smb_fname, int flag)
1893 #if defined(HAVE_FSTATAT)
1897 const char *rel_name = NULL;
1901 b = parent_dirname(talloc_tos(), smb_fname->base_name,
1902 &dir_name, &rel_name);
1908 fd = open(dir_name, O_RDONLY, 0);
1909 TALLOC_FREE(dir_name);
1914 set_effective_capability(DAC_OVERRIDE_CAPABILITY);
1915 ret = fstatat(fd, rel_name, &st, flag);
1916 drop_effective_capability(DAC_OVERRIDE_CAPABILITY);
1921 init_stat_ex_from_stat(
1922 &smb_fname->st, &st,
1923 lp_fake_directory_create_times(SNUM(handle->conn)));
1932 static int vfs_gpfs_stat(struct vfs_handle_struct *handle,
1933 struct smb_filename *smb_fname)
1936 struct gpfs_config_data *config;
1938 SMB_VFS_HANDLE_GET_DATA(handle, config,
1939 struct gpfs_config_data,
1942 ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
1943 if (ret == -1 && errno == EACCES) {
1944 DEBUG(10, ("Trying stat with capability for %s\n",
1945 smb_fname->base_name));
1946 ret = stat_with_capability(handle, smb_fname, 0);
1951 static int vfs_gpfs_lstat(struct vfs_handle_struct *handle,
1952 struct smb_filename *smb_fname)
1955 struct gpfs_config_data *config;
1957 SMB_VFS_HANDLE_GET_DATA(handle, config,
1958 struct gpfs_config_data,
1961 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1962 if (ret == -1 && errno == EACCES) {
1963 DEBUG(10, ("Trying lstat with capability for %s\n",
1964 smb_fname->base_name));
1965 ret = stat_with_capability(handle, smb_fname,
1966 AT_SYMLINK_NOFOLLOW);
1971 static void timespec_to_gpfs_time(struct timespec ts, gpfs_timestruc_t *gt,
1972 int idx, int *flags)
1974 if (!is_omit_timespec(&ts)) {
1976 gt[idx].tv_sec = ts.tv_sec;
1977 gt[idx].tv_nsec = ts.tv_nsec;
1978 DEBUG(10, ("Setting GPFS time %d, flags 0x%x\n", idx, *flags));
1982 static int smbd_gpfs_set_times_path(char *path, struct smb_file_time *ft)
1984 gpfs_timestruc_t gpfs_times[4];
1988 ZERO_ARRAY(gpfs_times);
1989 timespec_to_gpfs_time(ft->atime, gpfs_times, 0, &flags);
1990 timespec_to_gpfs_time(ft->mtime, gpfs_times, 1, &flags);
1991 /* No good mapping from LastChangeTime to ctime, not storing */
1992 timespec_to_gpfs_time(ft->create_time, gpfs_times, 3, &flags);
1995 DEBUG(10, ("nothing to do, return to avoid EINVAL\n"));
1999 rc = gpfswrap_set_times_path(path, flags, gpfs_times);
2001 if (rc != 0 && errno != ENOSYS) {
2002 DEBUG(1,("gpfs_set_times() returned with error %s\n",
2009 static int vfs_gpfs_ntimes(struct vfs_handle_struct *handle,
2010 const struct smb_filename *smb_fname,
2011 struct smb_file_time *ft)
2014 struct gpfs_winattr attrs;
2016 struct gpfs_config_data *config;
2018 SMB_VFS_HANDLE_GET_DATA(handle, config,
2019 struct gpfs_config_data,
2022 /* Try to use gpfs_set_times if it is enabled and available */
2023 if (config->settimes) {
2024 ret = smbd_gpfs_set_times_path(smb_fname->base_name, ft);
2026 if (ret == 0 || (ret == -1 && errno != ENOSYS)) {
2031 DEBUG(10,("gpfs_set_times() not available or disabled, "
2032 "use ntimes and winattr\n"));
2034 ret = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
2036 /* don't complain if access was denied */
2037 if (errno != EPERM && errno != EACCES) {
2038 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
2039 "%s", strerror(errno)));
2044 if (is_omit_timespec(&ft->create_time)){
2045 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
2049 if (!config->winattr) {
2054 attrs.creationTime.tv_sec = ft->create_time.tv_sec;
2055 attrs.creationTime.tv_nsec = ft->create_time.tv_nsec;
2057 ret = gpfswrap_set_winattrs_path(smb_fname->base_name,
2058 GPFS_WINATTR_SET_CREATION_TIME,
2060 if(ret == -1 && errno != ENOSYS){
2061 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret));
2068 static int vfs_gpfs_fallocate(struct vfs_handle_struct *handle,
2069 struct files_struct *fsp, uint32_t mode,
2070 off_t offset, off_t len)
2072 if (mode == (VFS_FALLOCATE_FL_PUNCH_HOLE|VFS_FALLOCATE_FL_KEEP_SIZE) &&
2074 lp_strict_allocate(SNUM(fsp->conn))) {
2076 * This is from a ZERO_DATA request on a non-sparse
2077 * file. GPFS does not support FL_KEEP_SIZE and thus
2078 * cannot fill the whole again in the subsequent
2079 * fallocate(FL_KEEP_SIZE). Deny this FL_PUNCH_HOLE
2080 * call to not end up with a hole in a non-sparse
2087 return SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
2090 static int vfs_gpfs_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
2094 struct gpfs_config_data *config;
2096 SMB_VFS_HANDLE_GET_DATA(handle, config,
2097 struct gpfs_config_data,
2100 if (!config->ftruncate) {
2101 return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
2104 result = gpfswrap_ftruncate(fsp->fh->fd, len);
2105 if ((result == -1) && (errno == ENOSYS)) {
2106 return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
2111 static bool vfs_gpfs_is_offline(struct vfs_handle_struct *handle,
2112 const struct smb_filename *fname,
2113 SMB_STRUCT_STAT *sbuf)
2115 struct gpfs_winattr attrs;
2116 struct gpfs_config_data *config;
2119 SMB_VFS_HANDLE_GET_DATA(handle, config,
2120 struct gpfs_config_data,
2123 if (!config->winattr) {
2127 ret = gpfswrap_get_winattrs_path(fname->base_name, &attrs);
2132 if ((attrs.winAttrs & GPFS_WINATTR_OFFLINE) != 0) {
2133 DBG_DEBUG("%s is offline\n", fname->base_name);
2137 DBG_DEBUG("%s is online\n", fname->base_name);
2141 static bool vfs_gpfs_fsp_is_offline(struct vfs_handle_struct *handle,
2142 struct files_struct *fsp)
2144 struct gpfs_fsp_extension *ext;
2146 ext = VFS_FETCH_FSP_EXTENSION(handle, fsp);
2149 * Something bad happened, always ask.
2151 return vfs_gpfs_is_offline(handle, fsp->fsp_name,
2152 &fsp->fsp_name->st);
2157 * As long as it's offline, ask.
2159 ext->offline = vfs_gpfs_is_offline(handle, fsp->fsp_name,
2160 &fsp->fsp_name->st);
2163 return ext->offline;
2166 static bool vfs_gpfs_aio_force(struct vfs_handle_struct *handle,
2167 struct files_struct *fsp)
2169 return vfs_gpfs_fsp_is_offline(handle, fsp);
2172 static ssize_t vfs_gpfs_sendfile(vfs_handle_struct *handle, int tofd,
2173 files_struct *fsp, const DATA_BLOB *hdr,
2174 off_t offset, size_t n)
2176 if (vfs_gpfs_fsp_is_offline(handle, fsp)) {
2180 return SMB_VFS_NEXT_SENDFILE(handle, tofd, fsp, hdr, offset, n);
2183 static int vfs_gpfs_connect(struct vfs_handle_struct *handle,
2184 const char *service, const char *user)
2186 struct gpfs_config_data *config;
2190 gpfswrap_lib_init(0);
2192 config = talloc_zero(handle->conn, struct gpfs_config_data);
2194 DEBUG(0, ("talloc_zero() failed\n"));
2199 ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
2201 TALLOC_FREE(config);
2205 check_fstype = lp_parm_bool(SNUM(handle->conn), "gpfs",
2206 "check_fstype", true);
2208 if (check_fstype && !IS_IPC(handle->conn)) {
2209 const char *connectpath = handle->conn->connectpath;
2210 struct statfs buf = { 0 };
2212 ret = statfs(connectpath, &buf);
2214 DBG_ERR("statfs failed for share %s at path %s: %s\n",
2215 service, connectpath, strerror(errno));
2216 TALLOC_FREE(config);
2220 if (buf.f_type != GPFS_SUPER_MAGIC) {
2221 DBG_ERR("SMB share %s, path %s not in GPFS file system."
2222 " statfs magic: 0x%jx\n",
2225 (uintmax_t)buf.f_type);
2227 TALLOC_FREE(config);
2232 ret = smbacl4_get_vfs_params(handle->conn, &config->nfs4_params);
2234 TALLOC_FREE(config);
2238 config->sharemodes = lp_parm_bool(SNUM(handle->conn), "gpfs",
2239 "sharemodes", true);
2241 config->leases = lp_parm_bool(SNUM(handle->conn), "gpfs",
2244 config->hsm = lp_parm_bool(SNUM(handle->conn), "gpfs",
2247 config->syncio = lp_parm_bool(SNUM(handle->conn), "gpfs",
2250 config->winattr = lp_parm_bool(SNUM(handle->conn), "gpfs",
2253 config->ftruncate = lp_parm_bool(SNUM(handle->conn), "gpfs",
2256 config->getrealfilename = lp_parm_bool(SNUM(handle->conn), "gpfs",
2257 "getrealfilename", true);
2259 config->dfreequota = lp_parm_bool(SNUM(handle->conn), "gpfs",
2260 "dfreequota", false);
2262 config->acl = lp_parm_bool(SNUM(handle->conn), "gpfs", "acl", true);
2264 config->settimes = lp_parm_bool(SNUM(handle->conn), "gpfs",
2266 config->recalls = lp_parm_bool(SNUM(handle->conn), "gpfs",
2269 SMB_VFS_HANDLE_SET_DATA(handle, config,
2270 NULL, struct gpfs_config_data,
2273 if (config->leases) {
2275 * GPFS lease code is based on kernel oplock code
2276 * so make sure it is turned on
2278 if (!lp_kernel_oplocks(SNUM(handle->conn))) {
2279 DEBUG(5, ("Enabling kernel oplocks for "
2280 "gpfs:leases to work\n"));
2281 lp_do_parameter(SNUM(handle->conn), "kernel oplocks",
2286 * as the kernel does not properly support Level II oplocks
2287 * and GPFS leases code is based on kernel infrastructure, we
2288 * need to turn off Level II oplocks if gpfs:leases is enabled
2290 if (lp_level2_oplocks(SNUM(handle->conn))) {
2291 DEBUG(5, ("gpfs:leases are enabled, disabling "
2292 "Level II oplocks\n"));
2293 lp_do_parameter(SNUM(handle->conn), "level2 oplocks",
2299 * Unless we have an async implementation of get_dos_attributes turn
2302 lp_do_parameter(SNUM(handle->conn), "smbd async dosmode", "false");
2307 static int get_gpfs_quota(const char *pathname, int type, int id,
2308 struct gpfs_quotaInfo *qi)
2312 ret = gpfswrap_quotactl(discard_const_p(char, pathname),
2313 GPFS_QCMD(Q_GETQUOTA, type), id, qi);
2316 if (errno == GPFS_E_NO_QUOTA_INST) {
2317 DEBUG(10, ("Quotas disabled on GPFS filesystem.\n"));
2318 } else if (errno != ENOSYS) {
2319 DEBUG(0, ("Get quota failed, type %d, id, %d, "
2320 "errno %d.\n", type, id, errno));
2326 DEBUG(10, ("quota type %d, id %d, blk u:%lld h:%lld s:%lld gt:%u\n",
2327 type, id, qi->blockUsage, qi->blockHardLimit,
2328 qi->blockSoftLimit, qi->blockGraceTime));
2333 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi, time_t cur_time,
2334 uint64_t *dfree, uint64_t *dsize)
2336 uint64_t usage, limit;
2339 * The quota reporting is done in units of 1024 byte blocks, but
2340 * sys_fsusage uses units of 512 byte blocks, adjust the block number
2341 * accordingly. Also filter possibly negative usage counts from gpfs.
2343 usage = qi.blockUsage < 0 ? 0 : (uint64_t)qi.blockUsage * 2;
2344 limit = (uint64_t)qi.blockHardLimit * 2;
2347 * When the grace time for the exceeded soft block quota has been
2348 * exceeded, the soft block quota becomes an additional hard limit.
2350 if (qi.blockSoftLimit &&
2351 qi.blockGraceTime && cur_time > qi.blockGraceTime) {
2352 /* report disk as full */
2354 *dsize = MIN(*dsize, usage);
2357 if (!qi.blockHardLimit)
2360 if (usage >= limit) {
2361 /* report disk as full */
2363 *dsize = MIN(*dsize, usage);
2366 /* limit has not been reached, determine "free space" */
2367 *dfree = MIN(*dfree, limit - usage);
2368 *dsize = MIN(*dsize, limit);
2372 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct *handle,
2373 const struct smb_filename *smb_fname,
2378 struct security_unix_token *utok;
2379 struct gpfs_quotaInfo qi_user = { 0 }, qi_group = { 0 };
2380 struct gpfs_config_data *config;
2384 SMB_VFS_HANDLE_GET_DATA(handle, config, struct gpfs_config_data,
2385 return (uint64_t)-1);
2386 if (!config->dfreequota) {
2387 return SMB_VFS_NEXT_DISK_FREE(handle, smb_fname,
2388 bsize, dfree, dsize);
2391 err = sys_fsusage(smb_fname->base_name, dfree, dsize);
2393 DEBUG (0, ("Could not get fs usage, errno %d\n", errno));
2394 return SMB_VFS_NEXT_DISK_FREE(handle, smb_fname,
2395 bsize, dfree, dsize);
2398 /* sys_fsusage returns units of 512 bytes */
2401 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
2402 (unsigned long long)*dfree, (unsigned long long)*dsize));
2404 utok = handle->conn->session_info->unix_token;
2406 err = get_gpfs_quota(smb_fname->base_name,
2407 GPFS_USRQUOTA, utok->uid, &qi_user);
2409 return SMB_VFS_NEXT_DISK_FREE(handle, smb_fname,
2410 bsize, dfree, dsize);
2414 * If new files created under this folder get this folder's
2415 * GID, then available space is governed by the quota of the
2416 * folder's GID, not the primary group of the creating user.
2418 if (VALID_STAT(smb_fname->st) &&
2419 S_ISDIR(smb_fname->st.st_ex_mode) &&
2420 smb_fname->st.st_ex_mode & S_ISGID) {
2422 err = get_gpfs_quota(smb_fname->base_name, GPFS_GRPQUOTA,
2423 smb_fname->st.st_ex_gid, &qi_group);
2427 err = get_gpfs_quota(smb_fname->base_name, GPFS_GRPQUOTA,
2428 utok->gid, &qi_group);
2432 return SMB_VFS_NEXT_DISK_FREE(handle, smb_fname,
2433 bsize, dfree, dsize);
2436 cur_time = time(NULL);
2438 /* Adjust free space and size according to quota limits. */
2439 vfs_gpfs_disk_free_quota(qi_user, cur_time, dfree, dsize);
2440 vfs_gpfs_disk_free_quota(qi_group, cur_time, dfree, dsize);
2445 static int vfs_gpfs_get_quota(vfs_handle_struct *handle,
2446 const struct smb_filename *smb_fname,
2447 enum SMB_QUOTA_TYPE qtype,
2453 * User/group quota are being used for disk-free
2454 * determination, which in this module is done directly
2455 * by the disk-free function. It's important that this
2456 * module does not return wrong quota values by mistake,
2457 * which would modify the correct values set by disk-free.
2458 * User/group quota are also being used for processing
2459 * NT_TRANSACT_GET_USER_QUOTA in smb1 protocol, which is
2460 * currently not supported by this module.
2462 case SMB_USER_QUOTA_TYPE:
2463 case SMB_GROUP_QUOTA_TYPE:
2467 return SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname,
2472 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct *handle,
2473 enum timestamp_set_resolution *p_ts_res)
2475 struct gpfs_config_data *config;
2478 next = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
2480 SMB_VFS_HANDLE_GET_DATA(handle, config,
2481 struct gpfs_config_data,
2485 next |= FILE_SUPPORTS_REMOTE_STORAGE;
2490 static int vfs_gpfs_open(struct vfs_handle_struct *handle,
2491 struct smb_filename *smb_fname, files_struct *fsp,
2492 int flags, mode_t mode)
2494 struct gpfs_config_data *config;
2496 struct gpfs_fsp_extension *ext;
2498 SMB_VFS_HANDLE_GET_DATA(handle, config,
2499 struct gpfs_config_data,
2502 if (config->hsm && !config->recalls &&
2503 vfs_gpfs_fsp_is_offline(handle, fsp)) {
2504 DEBUG(10, ("Refusing access to offline file %s\n",
2510 if (config->syncio) {
2514 ext = VFS_ADD_FSP_EXTENSION(handle, fsp, struct gpfs_fsp_extension,
2522 * Assume the file is offline until gpfs tells us it's online.
2524 *ext = (struct gpfs_fsp_extension) { .offline = true };
2526 ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
2528 VFS_REMOVE_FSP_EXTENSION(handle, fsp);
2533 static ssize_t vfs_gpfs_pread(vfs_handle_struct *handle, files_struct *fsp,
2534 void *data, size_t n, off_t offset)
2539 was_offline = vfs_gpfs_fsp_is_offline(handle, fsp);
2541 ret = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
2543 if ((ret != -1) && was_offline) {
2544 notify_fname(handle->conn, NOTIFY_ACTION_MODIFIED,
2545 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2546 fsp->fsp_name->base_name);
2552 struct vfs_gpfs_pread_state {
2553 struct files_struct *fsp;
2556 struct vfs_aio_state vfs_aio_state;
2559 static void vfs_gpfs_pread_done(struct tevent_req *subreq);
2561 static struct tevent_req *vfs_gpfs_pread_send(struct vfs_handle_struct *handle,
2562 TALLOC_CTX *mem_ctx,
2563 struct tevent_context *ev,
2564 struct files_struct *fsp,
2565 void *data, size_t n,
2568 struct tevent_req *req, *subreq;
2569 struct vfs_gpfs_pread_state *state;
2571 req = tevent_req_create(mem_ctx, &state, struct vfs_gpfs_pread_state);
2575 state->was_offline = vfs_gpfs_fsp_is_offline(handle, fsp);
2577 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
2579 if (tevent_req_nomem(subreq, req)) {
2580 return tevent_req_post(req, ev);
2582 tevent_req_set_callback(subreq, vfs_gpfs_pread_done, req);
2586 static void vfs_gpfs_pread_done(struct tevent_req *subreq)
2588 struct tevent_req *req = tevent_req_callback_data(
2589 subreq, struct tevent_req);
2590 struct vfs_gpfs_pread_state *state = tevent_req_data(
2591 req, struct vfs_gpfs_pread_state);
2593 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
2594 TALLOC_FREE(subreq);
2595 tevent_req_done(req);
2598 static ssize_t vfs_gpfs_pread_recv(struct tevent_req *req,
2599 struct vfs_aio_state *vfs_aio_state)
2601 struct vfs_gpfs_pread_state *state = tevent_req_data(
2602 req, struct vfs_gpfs_pread_state);
2603 struct files_struct *fsp = state->fsp;
2605 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
2608 *vfs_aio_state = state->vfs_aio_state;
2610 if ((state->ret != -1) && state->was_offline) {
2611 DEBUG(10, ("sending notify\n"));
2612 notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
2613 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2614 fsp->fsp_name->base_name);
2620 static ssize_t vfs_gpfs_pwrite(vfs_handle_struct *handle, files_struct *fsp,
2621 const void *data, size_t n, off_t offset)
2626 was_offline = vfs_gpfs_fsp_is_offline(handle, fsp);
2628 ret = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
2630 if ((ret != -1) && was_offline) {
2631 notify_fname(handle->conn, NOTIFY_ACTION_MODIFIED,
2632 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2633 fsp->fsp_name->base_name);
2639 struct vfs_gpfs_pwrite_state {
2640 struct files_struct *fsp;
2643 struct vfs_aio_state vfs_aio_state;
2646 static void vfs_gpfs_pwrite_done(struct tevent_req *subreq);
2648 static struct tevent_req *vfs_gpfs_pwrite_send(
2649 struct vfs_handle_struct *handle,
2650 TALLOC_CTX *mem_ctx,
2651 struct tevent_context *ev,
2652 struct files_struct *fsp,
2653 const void *data, size_t n,
2656 struct tevent_req *req, *subreq;
2657 struct vfs_gpfs_pwrite_state *state;
2659 req = tevent_req_create(mem_ctx, &state, struct vfs_gpfs_pwrite_state);
2663 state->was_offline = vfs_gpfs_fsp_is_offline(handle, fsp);
2665 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
2667 if (tevent_req_nomem(subreq, req)) {
2668 return tevent_req_post(req, ev);
2670 tevent_req_set_callback(subreq, vfs_gpfs_pwrite_done, req);
2674 static void vfs_gpfs_pwrite_done(struct tevent_req *subreq)
2676 struct tevent_req *req = tevent_req_callback_data(
2677 subreq, struct tevent_req);
2678 struct vfs_gpfs_pwrite_state *state = tevent_req_data(
2679 req, struct vfs_gpfs_pwrite_state);
2681 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
2682 TALLOC_FREE(subreq);
2683 tevent_req_done(req);
2686 static ssize_t vfs_gpfs_pwrite_recv(struct tevent_req *req,
2687 struct vfs_aio_state *vfs_aio_state)
2689 struct vfs_gpfs_pwrite_state *state = tevent_req_data(
2690 req, struct vfs_gpfs_pwrite_state);
2691 struct files_struct *fsp = state->fsp;
2693 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
2696 *vfs_aio_state = state->vfs_aio_state;
2698 if ((state->ret != -1) && state->was_offline) {
2699 DEBUG(10, ("sending notify\n"));
2700 notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
2701 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2702 fsp->fsp_name->base_name);
2709 static struct vfs_fn_pointers vfs_gpfs_fns = {
2710 .connect_fn = vfs_gpfs_connect,
2711 .disk_free_fn = vfs_gpfs_disk_free,
2712 .get_quota_fn = vfs_gpfs_get_quota,
2713 .fs_capabilities_fn = vfs_gpfs_capabilities,
2714 .kernel_flock_fn = vfs_gpfs_kernel_flock,
2715 .linux_setlease_fn = vfs_gpfs_setlease,
2716 .get_real_filename_fn = vfs_gpfs_get_real_filename,
2717 .get_dos_attributes_fn = vfs_gpfs_get_dos_attributes,
2718 .get_dos_attributes_send_fn = vfs_not_implemented_get_dos_attributes_send,
2719 .get_dos_attributes_recv_fn = vfs_not_implemented_get_dos_attributes_recv,
2720 .fget_dos_attributes_fn = vfs_gpfs_fget_dos_attributes,
2721 .set_dos_attributes_fn = vfs_gpfs_set_dos_attributes,
2722 .fset_dos_attributes_fn = vfs_gpfs_fset_dos_attributes,
2723 .fget_nt_acl_fn = gpfsacl_fget_nt_acl,
2724 .get_nt_acl_fn = gpfsacl_get_nt_acl,
2725 .fset_nt_acl_fn = gpfsacl_fset_nt_acl,
2726 .sys_acl_get_file_fn = gpfsacl_sys_acl_get_file,
2727 .sys_acl_get_fd_fn = gpfsacl_sys_acl_get_fd,
2728 .sys_acl_blob_get_file_fn = gpfsacl_sys_acl_blob_get_file,
2729 .sys_acl_blob_get_fd_fn = gpfsacl_sys_acl_blob_get_fd,
2730 .sys_acl_set_file_fn = gpfsacl_sys_acl_set_file,
2731 .sys_acl_set_fd_fn = gpfsacl_sys_acl_set_fd,
2732 .sys_acl_delete_def_file_fn = gpfsacl_sys_acl_delete_def_file,
2733 .chmod_fn = vfs_gpfs_chmod,
2734 .fchmod_fn = vfs_gpfs_fchmod,
2735 .close_fn = vfs_gpfs_close,
2736 .stat_fn = vfs_gpfs_stat,
2737 .lstat_fn = vfs_gpfs_lstat,
2738 .ntimes_fn = vfs_gpfs_ntimes,
2739 .aio_force_fn = vfs_gpfs_aio_force,
2740 .sendfile_fn = vfs_gpfs_sendfile,
2741 .fallocate_fn = vfs_gpfs_fallocate,
2742 .open_fn = vfs_gpfs_open,
2743 .pread_fn = vfs_gpfs_pread,
2744 .pread_send_fn = vfs_gpfs_pread_send,
2745 .pread_recv_fn = vfs_gpfs_pread_recv,
2746 .pwrite_fn = vfs_gpfs_pwrite,
2747 .pwrite_send_fn = vfs_gpfs_pwrite_send,
2748 .pwrite_recv_fn = vfs_gpfs_pwrite_recv,
2749 .ftruncate_fn = vfs_gpfs_ftruncate
2753 NTSTATUS vfs_gpfs_init(TALLOC_CTX *ctx)
2757 ret = gpfswrap_init();
2759 DEBUG(1, ("Could not initialize GPFS library wrapper\n"));
2762 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "gpfs",