2 Unix SMB/CIFS implementation.
3 Wrap gpfs calls in vfs functions.
5 Copyright (C) Christian Ambach <cambach1@de.ibm.com> 2006
7 Major code contributions by Chetan Shringarpure <chetan.sh@in.ibm.com>
8 and Gomati Mohanan <gomati.mohanan@in.ibm.com>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "smbd/smbd.h"
26 #include "librpc/gen_ndr/ndr_xattr.h"
27 #include "include/smbprofile.h"
30 #define DBGC_CLASS DBGC_VFS
33 #include "nfs4_acls.h"
35 #include "system/filesys.h"
37 struct gpfs_config_data {
47 static int vfs_gpfs_kernel_flock(vfs_handle_struct *handle, files_struct *fsp,
48 uint32 share_mode, uint32 access_mask)
51 struct gpfs_config_data *config;
53 SMB_VFS_HANDLE_GET_DATA(handle, config,
54 struct gpfs_config_data,
57 START_PROFILE(syscall_kernel_flock);
59 kernel_flock(fsp->fh->fd, share_mode, access_mask);
61 if (config->sharemodes
62 && !set_gpfs_sharemode(fsp, access_mask, fsp->share_access)) {
66 END_PROFILE(syscall_kernel_flock);
71 static int vfs_gpfs_close(vfs_handle_struct *handle, files_struct *fsp)
74 struct gpfs_config_data *config;
76 SMB_VFS_HANDLE_GET_DATA(handle, config,
77 struct gpfs_config_data,
80 if (config->sharemodes && (fsp->fh != NULL) && (fsp->fh->fd != -1)) {
81 set_gpfs_sharemode(fsp, 0, 0);
84 return SMB_VFS_NEXT_CLOSE(handle, fsp);
87 static int vfs_gpfs_setlease(vfs_handle_struct *handle, files_struct *fsp,
90 struct gpfs_config_data *config;
93 SMB_VFS_HANDLE_GET_DATA(handle, config,
94 struct gpfs_config_data,
97 START_PROFILE(syscall_linux_setlease);
99 if (linux_set_lease_sighandler(fsp->fh->fd) == -1)
102 if (config->leases) {
103 ret = set_gpfs_lease(fsp->fh->fd,leasetype);
107 /* This must have come from GPFS not being available */
108 /* or some other error, hence call the default */
109 ret = linux_setlease(fsp->fh->fd, leasetype);
112 END_PROFILE(syscall_linux_setlease);
117 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct *handle,
125 char real_pathname[PATH_MAX+1];
129 mangled = mangle_is_mangled(name, handle->conn->params);
131 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
132 mem_ctx, found_name);
135 full_path = talloc_asprintf(talloc_tos(), "%s/%s", path, name);
136 if (full_path == NULL) {
141 buflen = sizeof(real_pathname) - 1;
143 result = smbd_gpfs_get_realfilename_path(full_path, real_pathname,
146 TALLOC_FREE(full_path);
148 if ((result == -1) && (errno == ENOSYS)) {
149 return SMB_VFS_NEXT_GET_REAL_FILENAME(
150 handle, path, name, mem_ctx, found_name);
154 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
160 * GPFS does not necessarily null-terminate the returned path
161 * but instead returns the buffer length in buflen.
164 if (buflen < sizeof(real_pathname)) {
165 real_pathname[buflen] = '\0';
167 real_pathname[sizeof(real_pathname)-1] = '\0';
170 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
171 path, name, real_pathname));
173 name = strrchr_m(real_pathname, '/');
179 *found_name = talloc_strdup(mem_ctx, name+1);
180 if (*found_name == NULL) {
188 static void gpfs_dumpacl(int level, struct gpfs_acl *gacl)
193 DEBUG(0, ("gpfs acl is NULL\n"));
197 DEBUG(level, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n",
198 gacl->acl_nace, gacl->acl_type, gacl->acl_version, gacl->acl_level, gacl->acl_len));
199 for(i=0; i<gacl->acl_nace; i++)
201 struct gpfs_ace_v4 *gace = gacl->ace_v4 + i;
202 DEBUG(level, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n",
203 i, gace->aceType, gace->aceFlags, gace->aceMask,
204 gace->aceIFlags, gace->aceWho));
208 static struct gpfs_acl *gpfs_getacl_alloc(const char *fname, gpfs_aclType_t type)
210 struct gpfs_acl *acl;
213 TALLOC_CTX *mem_ctx = talloc_tos();
215 acl = (struct gpfs_acl *)TALLOC_SIZE(mem_ctx, len);
223 acl->acl_version = 0;
224 acl->acl_type = type;
226 ret = smbd_gpfs_getacl((char *)fname, GPFS_GETACL_STRUCT | GPFS_ACL_SAMBA, acl);
227 if ((ret != 0) && (errno == ENOSPC)) {
228 struct gpfs_acl *new_acl = (struct gpfs_acl *)TALLOC_SIZE(
229 mem_ctx, acl->acl_len + sizeof(struct gpfs_acl));
230 if (new_acl == NULL) {
235 new_acl->acl_len = acl->acl_len;
236 new_acl->acl_level = acl->acl_level;
237 new_acl->acl_version = acl->acl_version;
238 new_acl->acl_type = acl->acl_type;
241 ret = smbd_gpfs_getacl((char *)fname, GPFS_GETACL_STRUCT | GPFS_ACL_SAMBA, acl);
245 DEBUG(8, ("smbd_gpfs_getacl failed with %s\n",strerror(errno)));
252 /* Tries to get nfs4 acls and returns SMB ACL allocated.
253 * On failure returns 1 if it got non-NFSv4 ACL to prompt
254 * retry with POSIX ACL checks.
255 * On failure returns -1 if there is system (GPFS) error, check errno.
256 * Returns 0 on success
258 static int gpfs_get_nfs4_acl(const char *fname, SMB4ACL_T **ppacl)
261 struct gpfs_acl *gacl = NULL;
262 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname));
264 /* First get the real acl length */
265 gacl = gpfs_getacl_alloc(fname, 0);
267 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
268 fname, strerror(errno)));
272 if (gacl->acl_type != GPFS_ACL_TYPE_NFS4) {
273 DEBUG(10, ("Got non-nfsv4 acl\n"));
274 /* Retry with POSIX ACLs check */
278 *ppacl = smb_create_smb4acl();
280 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
281 gacl->acl_len, gacl->acl_level, gacl->acl_version,
284 for (i=0; i<gacl->acl_nace; i++) {
285 struct gpfs_ace_v4 *gace = &gacl->ace_v4[i];
286 SMB_ACE4PROP_T smbace;
287 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
288 "who: %d\n", gace->aceType, gace->aceIFlags,
289 gace->aceFlags, gace->aceMask, gace->aceWho));
292 if (gace->aceIFlags & ACE4_IFLAG_SPECIAL_ID) {
293 smbace.flags |= SMB_ACE4_ID_SPECIAL;
294 switch (gace->aceWho) {
295 case ACE4_SPECIAL_OWNER:
296 smbace.who.special_id = SMB_ACE4_WHO_OWNER;
298 case ACE4_SPECIAL_GROUP:
299 smbace.who.special_id = SMB_ACE4_WHO_GROUP;
301 case ACE4_SPECIAL_EVERYONE:
302 smbace.who.special_id = SMB_ACE4_WHO_EVERYONE;
305 DEBUG(8, ("invalid special gpfs id %d "
306 "ignored\n", gace->aceWho));
307 continue; /* don't add it */
310 if (gace->aceFlags & ACE4_FLAG_GROUP_ID)
311 smbace.who.gid = gace->aceWho;
313 smbace.who.uid = gace->aceWho;
316 /* remove redundent deny entries */
317 if (i > 0 && gace->aceType == SMB_ACE4_ACCESS_DENIED_ACE_TYPE) {
318 struct gpfs_ace_v4 *prev = &gacl->ace_v4[i-1];
319 if (prev->aceType == SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE &&
320 prev->aceFlags == gace->aceFlags &&
321 prev->aceIFlags == gace->aceIFlags &&
322 (gace->aceMask & prev->aceMask) == 0 &&
323 gace->aceWho == prev->aceWho) {
324 /* its redundent - skip it */
329 smbace.aceType = gace->aceType;
330 smbace.aceFlags = gace->aceFlags;
331 smbace.aceMask = gace->aceMask;
332 smb_add_ace4(*ppacl, &smbace);
338 static NTSTATUS gpfsacl_fget_nt_acl(vfs_handle_struct *handle,
339 files_struct *fsp, uint32 security_info,
340 struct security_descriptor **ppdesc)
342 SMB4ACL_T *pacl = NULL;
346 result = gpfs_get_nfs4_acl(fsp->fsp_name->base_name, &pacl);
349 return smb_fget_nt_acl_nfs4(fsp, security_info, ppdesc, pacl);
352 DEBUG(10, ("retrying with posix acl...\n"));
353 return posix_fget_nt_acl(fsp, security_info, ppdesc);
356 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
357 return map_nt_error_from_unix(errno);
360 static NTSTATUS gpfsacl_get_nt_acl(vfs_handle_struct *handle,
362 uint32 security_info, struct security_descriptor **ppdesc)
364 SMB4ACL_T *pacl = NULL;
368 result = gpfs_get_nfs4_acl(name, &pacl);
371 return smb_get_nt_acl_nfs4(handle->conn, name, security_info, ppdesc, pacl);
374 DEBUG(10, ("retrying with posix acl...\n"));
375 return posix_get_nt_acl(handle->conn, name, security_info, ppdesc);
378 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
379 return map_nt_error_from_unix(errno);
382 static bool gpfsacl_process_smbacl(files_struct *fsp, SMB4ACL_T *smbacl)
385 gpfs_aclLen_t gacl_len;
387 struct gpfs_acl *gacl;
388 TALLOC_CTX *mem_ctx = talloc_tos();
390 gacl_len = sizeof(struct gpfs_acl) +
391 (smb_get_naces(smbacl)-1)*sizeof(gpfs_ace_v4_t);
393 gacl = (struct gpfs_acl *)TALLOC_SIZE(mem_ctx, gacl_len);
395 DEBUG(0, ("talloc failed\n"));
400 gacl->acl_len = gacl_len;
402 gacl->acl_version = GPFS_ACL_VERSION_NFS4;
403 gacl->acl_type = GPFS_ACL_TYPE_NFS4;
404 gacl->acl_nace = 0; /* change later... */
406 for (smbace=smb_first_ace4(smbacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
407 struct gpfs_ace_v4 *gace = &gacl->ace_v4[gacl->acl_nace];
408 SMB_ACE4PROP_T *aceprop = smb_get_ace4(smbace);
410 gace->aceType = aceprop->aceType;
411 gace->aceFlags = aceprop->aceFlags;
412 gace->aceMask = aceprop->aceMask;
415 * GPFS can't distinguish between WRITE and APPEND on
416 * files, so one being set without the other is an
417 * error. Sorry for the many ()'s :-)
420 if (!fsp->is_directory
422 ((((gace->aceMask & ACE4_MASK_WRITE) == 0)
423 && ((gace->aceMask & ACE4_MASK_APPEND) != 0))
425 (((gace->aceMask & ACE4_MASK_WRITE) != 0)
426 && ((gace->aceMask & ACE4_MASK_APPEND) == 0)))
428 lp_parm_bool(fsp->conn->params->service, "gpfs",
429 "merge_writeappend", True)) {
430 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
431 "WRITE^APPEND, setting WRITE|APPEND\n",
433 gace->aceMask |= ACE4_MASK_WRITE|ACE4_MASK_APPEND;
436 gace->aceIFlags = (aceprop->flags&SMB_ACE4_ID_SPECIAL) ? ACE4_IFLAG_SPECIAL_ID : 0;
438 if (aceprop->flags&SMB_ACE4_ID_SPECIAL)
440 switch(aceprop->who.special_id)
442 case SMB_ACE4_WHO_EVERYONE:
443 gace->aceWho = ACE4_SPECIAL_EVERYONE;
445 case SMB_ACE4_WHO_OWNER:
446 gace->aceWho = ACE4_SPECIAL_OWNER;
448 case SMB_ACE4_WHO_GROUP:
449 gace->aceWho = ACE4_SPECIAL_GROUP;
452 DEBUG(8, ("unsupported special_id %d\n", aceprop->who.special_id));
453 continue; /* don't add it !!! */
456 /* just only for the type safety... */
457 if (aceprop->aceFlags&SMB_ACE4_IDENTIFIER_GROUP)
458 gace->aceWho = aceprop->who.gid;
460 gace->aceWho = aceprop->who.uid;
466 ret = smbd_gpfs_putacl(fsp->fsp_name->base_name,
467 GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gacl);
469 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno)));
470 gpfs_dumpacl(8, gacl);
474 DEBUG(10, ("gpfs_putacl succeeded\n"));
478 static NTSTATUS gpfsacl_set_nt_acl_internal(files_struct *fsp, uint32 security_info_sent, const struct security_descriptor *psd)
480 struct gpfs_acl *acl;
481 NTSTATUS result = NT_STATUS_ACCESS_DENIED;
483 acl = gpfs_getacl_alloc(fsp->fsp_name->base_name, 0);
487 if (acl->acl_version&GPFS_ACL_VERSION_NFS4)
489 if (lp_parm_bool(fsp->conn->params->service, "gpfs",
490 "refuse_dacl_protected", false)
491 && (psd->type&SEC_DESC_DACL_PROTECTED)) {
492 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
493 return NT_STATUS_NOT_SUPPORTED;
496 result = smb_set_nt_acl_nfs4(
497 fsp, security_info_sent, psd,
498 gpfsacl_process_smbacl);
499 } else { /* assume POSIX ACL - by default... */
500 result = set_nt_acl(fsp, security_info_sent, psd);
506 static NTSTATUS gpfsacl_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const struct security_descriptor *psd)
508 return gpfsacl_set_nt_acl_internal(fsp, security_info_sent, psd);
511 static SMB_ACL_T gpfs2smb_acl(const struct gpfs_acl *pacl)
516 result = sys_acl_init(pacl->acl_nace);
517 if (result == NULL) {
522 result->count = pacl->acl_nace;
524 for (i=0; i<pacl->acl_nace; i++) {
525 struct smb_acl_entry *ace = &result->acl[i];
526 const struct gpfs_ace_v1 *g_ace = &pacl->ace_v1[i];
528 DEBUG(10, ("Converting type %d id %lu perm %x\n",
529 (int)g_ace->ace_type, (unsigned long)g_ace->ace_who,
530 (int)g_ace->ace_perm));
532 switch (g_ace->ace_type) {
534 ace->a_type = SMB_ACL_USER;
535 ace->uid = (uid_t)g_ace->ace_who;
537 case GPFS_ACL_USER_OBJ:
538 ace->a_type = SMB_ACL_USER_OBJ;
541 ace->a_type = SMB_ACL_GROUP;
542 ace->gid = (gid_t)g_ace->ace_who;
544 case GPFS_ACL_GROUP_OBJ:
545 ace->a_type = SMB_ACL_GROUP_OBJ;
548 ace->a_type = SMB_ACL_OTHER;
551 ace->a_type = SMB_ACL_MASK;
554 DEBUG(10, ("Got invalid ace_type: %d\n",
562 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_READ) ?
564 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_WRITE) ?
566 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_EXECUTE) ?
569 DEBUGADD(10, ("Converted to %d perm %x\n",
570 ace->a_type, ace->a_perm));
576 static SMB_ACL_T gpfsacl_get_posix_acl(const char *path, gpfs_aclType_t type)
578 struct gpfs_acl *pacl;
579 SMB_ACL_T result = NULL;
581 pacl = gpfs_getacl_alloc(path, type);
584 DEBUG(10, ("gpfs_getacl failed for %s with %s\n",
585 path, strerror(errno)));
592 if (pacl->acl_version != GPFS_ACL_VERSION_POSIX) {
593 DEBUG(10, ("Got acl version %d, expected %d\n",
594 pacl->acl_version, GPFS_ACL_VERSION_POSIX));
599 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
600 pacl->acl_len, pacl->acl_level, pacl->acl_version,
603 result = gpfs2smb_acl(pacl);
604 if (result == NULL) {
616 static SMB_ACL_T gpfsacl_sys_acl_get_file(vfs_handle_struct *handle,
620 gpfs_aclType_t gpfs_type;
623 case SMB_ACL_TYPE_ACCESS:
624 gpfs_type = GPFS_ACL_TYPE_ACCESS;
626 case SMB_ACL_TYPE_DEFAULT:
627 gpfs_type = GPFS_ACL_TYPE_DEFAULT;
630 DEBUG(0, ("Got invalid type: %d\n", type));
631 smb_panic("exiting");
634 return gpfsacl_get_posix_acl(path_p, gpfs_type);
637 static SMB_ACL_T gpfsacl_sys_acl_get_fd(vfs_handle_struct *handle,
640 return gpfsacl_get_posix_acl(fsp->fsp_name->base_name,
641 GPFS_ACL_TYPE_ACCESS);
644 static struct gpfs_acl *smb2gpfs_acl(const SMB_ACL_T pacl,
648 struct gpfs_acl *result;
652 gpfs_ace_v1_t ace_v1[1]; /* when GPFS_ACL_VERSION_POSIX */
653 gpfs_ace_v4_t ace_v4[1]; /* when GPFS_ACL_VERSION_NFS4 */
656 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl->count));
658 len = sizeof(struct gpfs_acl) - sizeof(union gpfs_ace_union) +
659 (pacl->count)*sizeof(gpfs_ace_v1_t);
661 result = (struct gpfs_acl *)SMB_MALLOC(len);
662 if (result == NULL) {
667 result->acl_len = len;
668 result->acl_level = 0;
669 result->acl_version = GPFS_ACL_VERSION_POSIX;
670 result->acl_type = (type == SMB_ACL_TYPE_DEFAULT) ?
671 GPFS_ACL_TYPE_DEFAULT : GPFS_ACL_TYPE_ACCESS;
672 result->acl_nace = pacl->count;
674 for (i=0; i<pacl->count; i++) {
675 const struct smb_acl_entry *ace = &pacl->acl[i];
676 struct gpfs_ace_v1 *g_ace = &result->ace_v1[i];
678 DEBUG(10, ("Converting type %d perm %x\n",
679 (int)ace->a_type, (int)ace->a_perm));
683 switch(ace->a_type) {
685 g_ace->ace_type = GPFS_ACL_USER;
686 g_ace->ace_who = (gpfs_uid_t)ace->uid;
688 case SMB_ACL_USER_OBJ:
689 g_ace->ace_type = GPFS_ACL_USER_OBJ;
690 g_ace->ace_perm |= ACL_PERM_CONTROL;
694 g_ace->ace_type = GPFS_ACL_GROUP;
695 g_ace->ace_who = (gpfs_uid_t)ace->gid;
697 case SMB_ACL_GROUP_OBJ:
698 g_ace->ace_type = GPFS_ACL_GROUP_OBJ;
702 g_ace->ace_type = GPFS_ACL_MASK;
703 g_ace->ace_perm = 0x8f;
707 g_ace->ace_type = GPFS_ACL_OTHER;
711 DEBUG(10, ("Got invalid ace_type: %d\n", ace->a_type));
717 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_READ) ?
719 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_WRITE) ?
721 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_EXECUTE) ?
722 ACL_PERM_EXECUTE : 0;
724 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
725 g_ace->ace_type, g_ace->ace_who, g_ace->ace_perm));
731 static int gpfsacl_sys_acl_set_file(vfs_handle_struct *handle,
736 struct gpfs_acl *gpfs_acl;
739 gpfs_acl = smb2gpfs_acl(theacl, type);
740 if (gpfs_acl == NULL) {
744 result = smbd_gpfs_putacl((char *)name, GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gpfs_acl);
750 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct *handle,
754 return gpfsacl_sys_acl_set_file(handle, fsp->fsp_name->base_name,
755 SMB_ACL_TYPE_ACCESS, theacl);
758 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct *handle,
766 * Assumed: mode bits are shiftable and standard
767 * Output: the new aceMask field for an smb nfs4 ace
769 static uint32 gpfsacl_mask_filter(uint32 aceType, uint32 aceMask, uint32 rwx)
771 const uint32 posix_nfs4map[3] = {
772 SMB_ACE4_EXECUTE, /* execute */
773 SMB_ACE4_WRITE_DATA | SMB_ACE4_APPEND_DATA, /* write; GPFS specific */
774 SMB_ACE4_READ_DATA /* read */
777 uint32_t posix_mask = 0x01;
782 nfs4_bits = posix_nfs4map[i];
783 posix_bit = rwx & posix_mask;
785 if (aceType==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE) {
787 aceMask |= nfs4_bits;
789 aceMask &= ~nfs4_bits;
791 /* add deny bits when suitable */
793 aceMask |= nfs4_bits;
795 aceMask &= ~nfs4_bits;
796 } /* other ace types are unexpected */
804 static int gpfsacl_emu_chmod(const char *path, mode_t mode)
806 SMB4ACL_T *pacl = NULL;
808 bool haveAllowEntry[SMB_ACE4_WHO_EVERYONE + 1] = {False, False, False, False};
810 files_struct fake_fsp; /* TODO: rationalize parametrization */
814 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path, mode));
816 result = gpfs_get_nfs4_acl(path, &pacl);
820 if (mode & ~(S_IRWXU | S_IRWXG | S_IRWXO)) {
821 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode, path));
824 for (smbace=smb_first_ace4(pacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
825 SMB_ACE4PROP_T *ace = smb_get_ace4(smbace);
826 uint32_t specid = ace->who.special_id;
828 if (ace->flags&SMB_ACE4_ID_SPECIAL &&
829 ace->aceType<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE &&
830 specid <= SMB_ACE4_WHO_EVERYONE) {
834 if (ace->aceType==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE)
835 haveAllowEntry[specid] = True;
837 /* mode >> 6 for @owner, mode >> 3 for @group,
838 * mode >> 0 for @everyone */
839 newMask = gpfsacl_mask_filter(ace->aceType, ace->aceMask,
840 mode >> ((SMB_ACE4_WHO_EVERYONE - specid) * 3));
841 if (ace->aceMask!=newMask) {
842 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
843 path, ace->aceMask, newMask, specid));
845 ace->aceMask = newMask;
849 /* make sure we have at least ALLOW entries
850 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
853 for(i = SMB_ACE4_WHO_OWNER; i<=SMB_ACE4_WHO_EVERYONE; i++) {
856 if (haveAllowEntry[i]==True)
860 ace.aceType = SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE;
861 ace.flags |= SMB_ACE4_ID_SPECIAL;
862 ace.who.special_id = i;
864 if (i==SMB_ACE4_WHO_GROUP) /* not sure it's necessary... */
865 ace.aceFlags |= SMB_ACE4_IDENTIFIER_GROUP;
867 ace.aceMask = gpfsacl_mask_filter(ace.aceType, ace.aceMask,
868 mode >> ((SMB_ACE4_WHO_EVERYONE - i) * 3));
870 /* don't add unnecessary aces */
874 /* we add it to the END - as windows expects allow aces */
875 smb_add_ace4(pacl, &ace);
876 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
877 path, mode, i, ace.aceMask));
880 /* don't add complementary DENY ACEs here */
881 ZERO_STRUCT(fake_fsp);
882 status = create_synthetic_smb_fname(talloc_tos(), path, NULL, NULL,
884 if (!NT_STATUS_IS_OK(status)) {
885 errno = map_errno_from_nt_status(status);
889 if (gpfsacl_process_smbacl(&fake_fsp, pacl) == False) {
890 TALLOC_FREE(fake_fsp.fsp_name);
894 TALLOC_FREE(fake_fsp.fsp_name);
895 return 0; /* ok for [f]chmod */
898 static int vfs_gpfs_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
900 struct smb_filename *smb_fname_cpath;
904 status = create_synthetic_smb_fname(
905 talloc_tos(), path, NULL, NULL, &smb_fname_cpath);
907 if (SMB_VFS_NEXT_STAT(handle, smb_fname_cpath) != 0) {
911 /* avoid chmod() if possible, to preserve acls */
912 if ((smb_fname_cpath->st.st_ex_mode & ~S_IFMT) == mode) {
916 rc = gpfsacl_emu_chmod(path, mode);
918 return SMB_VFS_NEXT_CHMOD(handle, path, mode);
922 static int vfs_gpfs_fchmod(vfs_handle_struct *handle, files_struct *fsp, mode_t mode)
927 if (SMB_VFS_NEXT_FSTAT(handle, fsp, &st) != 0) {
931 /* avoid chmod() if possible, to preserve acls */
932 if ((st.st_ex_mode & ~S_IFMT) == mode) {
936 rc = gpfsacl_emu_chmod(fsp->fsp_name->base_name, mode);
938 return SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
942 static int gpfs_set_xattr(struct vfs_handle_struct *handle, const char *path,
943 const char *name, const void *value, size_t size, int flags){
944 struct xattr_DOSATTRIB dosattrib;
945 enum ndr_err_code ndr_err;
947 const char *attrstr = value;
948 unsigned int dosmode=0;
949 struct gpfs_winattr attrs;
951 struct gpfs_config_data *config;
953 SMB_VFS_HANDLE_GET_DATA(handle, config,
954 struct gpfs_config_data,
957 if (!config->winattr) {
958 DEBUG(10, ("gpfs_set_xattr:name is %s -> next\n",name));
959 return SMB_VFS_NEXT_SETXATTR(handle,path,name,value,size,flags);
962 DEBUG(10, ("gpfs_set_xattr: %s \n",path));
964 /* Only handle DOS Attributes */
965 if (strcmp(name,SAMBA_XATTR_DOS_ATTRIB) != 0){
966 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name));
967 return SMB_VFS_NEXT_SETXATTR(handle,path,name,value,size,flags);
970 blob.data = (uint8_t *)attrstr;
973 ndr_err = ndr_pull_struct_blob(&blob, talloc_tos(), &dosattrib,
974 (ndr_pull_flags_fn_t)ndr_pull_xattr_DOSATTRIB);
976 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
977 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
978 "from EA on file %s: Error = %s\n",
979 path, ndr_errstr(ndr_err)));
983 if (dosattrib.version != 3) {
984 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
985 "%d\n", (int)dosattrib.version));
988 if (!(dosattrib.info.info3.valid_flags & XATTR_DOSINFO_ATTRIB)) {
989 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
990 "valid, ignoring\n"));
994 dosmode = dosattrib.info.info3.attrib;
997 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
998 if (dosmode & FILE_ATTRIBUTE_ARCHIVE){
999 attrs.winAttrs |= GPFS_WINATTR_ARCHIVE;
1001 if (dosmode & FILE_ATTRIBUTE_HIDDEN){
1002 attrs.winAttrs |= GPFS_WINATTR_HIDDEN;
1004 if (dosmode & FILE_ATTRIBUTE_SYSTEM){
1005 attrs.winAttrs |= GPFS_WINATTR_SYSTEM;
1007 if (dosmode & FILE_ATTRIBUTE_READONLY){
1008 attrs.winAttrs |= GPFS_WINATTR_READONLY;
1010 if (dosmode & FILE_ATTRIBUTE_SPARSE) {
1011 attrs.winAttrs |= GPFS_WINATTR_SPARSE_FILE;
1015 ret = set_gpfs_winattrs(discard_const_p(char, path),
1016 GPFS_WINATTR_SET_ATTRS, &attrs);
1018 if (errno == ENOSYS) {
1019 return SMB_VFS_NEXT_SETXATTR(handle, path, name, value,
1023 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret));
1027 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs.winAttrs));
1031 static ssize_t gpfs_get_xattr(struct vfs_handle_struct *handle, const char *path,
1032 const char *name, void *value, size_t size){
1033 char *attrstr = value;
1034 unsigned int dosmode = 0;
1035 struct gpfs_winattr attrs;
1037 struct gpfs_config_data *config;
1039 SMB_VFS_HANDLE_GET_DATA(handle, config,
1040 struct gpfs_config_data,
1043 if (!config->winattr) {
1044 DEBUG(10, ("gpfs_get_xattr:name is %s -> next\n",name));
1045 return SMB_VFS_NEXT_GETXATTR(handle,path,name,value,size);
1048 DEBUG(10, ("gpfs_get_xattr: %s \n",path));
1050 /* Only handle DOS Attributes */
1051 if (strcmp(name,SAMBA_XATTR_DOS_ATTRIB) != 0){
1052 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name));
1053 return SMB_VFS_NEXT_GETXATTR(handle,path,name,value,size);
1056 ret = get_gpfs_winattrs(discard_const_p(char, path), &attrs);
1058 if (errno == ENOSYS) {
1059 return SMB_VFS_NEXT_GETXATTR(handle, path, name, value,
1063 DEBUG(1, ("gpfs_get_xattr: Get GPFS attributes failed: "
1064 "%d (%s)\n", ret, strerror(errno)));
1068 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs.winAttrs));
1070 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1071 if (attrs.winAttrs & GPFS_WINATTR_ARCHIVE){
1072 dosmode |= FILE_ATTRIBUTE_ARCHIVE;
1074 if (attrs.winAttrs & GPFS_WINATTR_HIDDEN){
1075 dosmode |= FILE_ATTRIBUTE_HIDDEN;
1077 if (attrs.winAttrs & GPFS_WINATTR_SYSTEM){
1078 dosmode |= FILE_ATTRIBUTE_SYSTEM;
1080 if (attrs.winAttrs & GPFS_WINATTR_READONLY){
1081 dosmode |= FILE_ATTRIBUTE_READONLY;
1083 if (attrs.winAttrs & GPFS_WINATTR_SPARSE_FILE) {
1084 dosmode |= FILE_ATTRIBUTE_SPARSE;
1087 snprintf(attrstr, size, "0x%2.2x",
1088 (unsigned int)(dosmode & SAMBA_ATTRIBUTES_MASK));
1089 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr));
1093 static int vfs_gpfs_stat(struct vfs_handle_struct *handle,
1094 struct smb_filename *smb_fname)
1096 struct gpfs_winattr attrs;
1100 struct gpfs_config_data *config;
1102 SMB_VFS_HANDLE_GET_DATA(handle, config,
1103 struct gpfs_config_data,
1106 ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
1111 if (!config->winattr) {
1115 status = get_full_smb_filename(talloc_tos(), smb_fname, &fname);
1116 if (!NT_STATUS_IS_OK(status)) {
1117 errno = map_errno_from_nt_status(status);
1120 ret = get_gpfs_winattrs(discard_const_p(char, fname), &attrs);
1123 smb_fname->st.st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
1124 smb_fname->st.st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
1125 smb_fname->st.vfs_private = attrs.winAttrs;
1130 static int vfs_gpfs_fstat(struct vfs_handle_struct *handle,
1131 struct files_struct *fsp, SMB_STRUCT_STAT *sbuf)
1133 struct gpfs_winattr attrs;
1135 struct gpfs_config_data *config;
1137 SMB_VFS_HANDLE_GET_DATA(handle, config,
1138 struct gpfs_config_data,
1141 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1145 if ((fsp->fh == NULL) || (fsp->fh->fd == -1)) {
1148 if (!config->winattr) {
1152 ret = smbd_fget_gpfs_winattrs(fsp->fh->fd, &attrs);
1154 sbuf->st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
1155 sbuf->st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
1160 static int vfs_gpfs_lstat(struct vfs_handle_struct *handle,
1161 struct smb_filename *smb_fname)
1163 struct gpfs_winattr attrs;
1167 struct gpfs_config_data *config;
1169 SMB_VFS_HANDLE_GET_DATA(handle, config,
1170 struct gpfs_config_data,
1173 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1177 if (!config->winattr) {
1181 status = get_full_smb_filename(talloc_tos(), smb_fname, &path);
1182 if (!NT_STATUS_IS_OK(status)) {
1183 errno = map_errno_from_nt_status(status);
1186 ret = get_gpfs_winattrs(discard_const_p(char, path), &attrs);
1189 smb_fname->st.st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
1190 smb_fname->st.st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
1191 smb_fname->st.vfs_private = attrs.winAttrs;
1196 static int vfs_gpfs_ntimes(struct vfs_handle_struct *handle,
1197 const struct smb_filename *smb_fname,
1198 struct smb_file_time *ft)
1201 struct gpfs_winattr attrs;
1205 struct gpfs_config_data *config;
1207 SMB_VFS_HANDLE_GET_DATA(handle, config,
1208 struct gpfs_config_data,
1211 ret = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1213 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed\n"));
1217 if(null_timespec(ft->create_time)){
1218 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1222 if (!config->winattr) {
1226 status = get_full_smb_filename(talloc_tos(), smb_fname, &path);
1227 if (!NT_STATUS_IS_OK(status)) {
1228 errno = map_errno_from_nt_status(status);
1233 attrs.creationTime.tv_sec = ft->create_time.tv_sec;
1234 attrs.creationTime.tv_nsec = ft->create_time.tv_nsec;
1236 ret = set_gpfs_winattrs(discard_const_p(char, path),
1237 GPFS_WINATTR_SET_CREATION_TIME, &attrs);
1238 if(ret == -1 && errno != ENOSYS){
1239 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret));
1246 static int vfs_gpfs_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1250 struct gpfs_config_data *config;
1252 SMB_VFS_HANDLE_GET_DATA(handle, config,
1253 struct gpfs_config_data,
1256 if (!config->ftruncate) {
1257 return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1260 result = smbd_gpfs_ftruncate(fsp->fh->fd, len);
1261 if ((result == -1) && (errno == ENOSYS)) {
1262 return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1267 static bool vfs_gpfs_is_offline(struct vfs_handle_struct *handle,
1268 const struct smb_filename *fname,
1269 SMB_STRUCT_STAT *sbuf)
1271 struct gpfs_winattr attrs;
1274 struct gpfs_config_data *config;
1276 SMB_VFS_HANDLE_GET_DATA(handle, config,
1277 struct gpfs_config_data,
1280 if (!config->winattr) {
1281 return SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
1284 status = get_full_smb_filename(talloc_tos(), fname, &path);
1285 if (!NT_STATUS_IS_OK(status)) {
1286 errno = map_errno_from_nt_status(status);
1290 if (VALID_STAT(*sbuf)) {
1291 attrs.winAttrs = sbuf->vfs_private;
1294 ret = get_gpfs_winattrs(path, &attrs);
1301 if ((attrs.winAttrs & GPFS_WINATTR_OFFLINE) != 0) {
1302 DEBUG(10, ("%s is offline\n", path));
1306 DEBUG(10, ("%s is online\n", path));
1308 return SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
1311 static bool vfs_gpfs_aio_force(struct vfs_handle_struct *handle,
1312 struct files_struct *fsp)
1314 return vfs_gpfs_is_offline(handle, fsp->fsp_name, &fsp->fsp_name->st);
1317 static ssize_t vfs_gpfs_sendfile(vfs_handle_struct *handle, int tofd,
1318 files_struct *fsp, const DATA_BLOB *hdr,
1319 SMB_OFF_T offset, size_t n)
1321 if ((fsp->fsp_name->st.vfs_private & GPFS_WINATTR_OFFLINE) != 0) {
1325 return SMB_VFS_NEXT_SENDFILE(handle, tofd, fsp, hdr, offset, n);
1328 int vfs_gpfs_connect(struct vfs_handle_struct *handle, const char *service,
1331 struct gpfs_config_data *config;
1333 smbd_gpfs_lib_init();
1335 int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
1341 config = talloc_zero(handle->conn, struct gpfs_config_data);
1343 SMB_VFS_NEXT_DISCONNECT(handle);
1344 DEBUG(0, ("talloc_zero() failed\n"));
1348 config->sharemodes = lp_parm_bool(SNUM(handle->conn), "gpfs",
1349 "sharemodes", true);
1351 config->leases = lp_parm_bool(SNUM(handle->conn), "gpfs",
1354 config->hsm = lp_parm_bool(SNUM(handle->conn), "gpfs",
1357 config->syncio = lp_parm_bool(SNUM(handle->conn), "gpfs",
1360 config->winattr = lp_parm_bool(SNUM(handle->conn), "gpfs",
1363 config->ftruncate = lp_parm_bool(SNUM(handle->conn), "gpfs",
1366 SMB_VFS_HANDLE_SET_DATA(handle, config,
1367 NULL, struct gpfs_config_data,
1373 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct *handle,
1374 enum timestamp_set_resolution *p_ts_res)
1376 struct gpfs_config_data *config;
1379 next = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
1381 SMB_VFS_HANDLE_GET_DATA(handle, config,
1382 struct gpfs_config_data,
1386 next |= FILE_SUPPORTS_REMOTE_STORAGE;
1391 static int vfs_gpfs_open(struct vfs_handle_struct *handle,
1392 struct smb_filename *smb_fname, files_struct *fsp,
1393 int flags, mode_t mode)
1395 struct gpfs_config_data *config;
1397 SMB_VFS_HANDLE_GET_DATA(handle, config,
1398 struct gpfs_config_data,
1401 if (config->syncio) {
1404 return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
1408 static struct vfs_fn_pointers vfs_gpfs_fns = {
1409 .connect_fn = vfs_gpfs_connect,
1410 .fs_capabilities_fn = vfs_gpfs_capabilities,
1411 .kernel_flock_fn = vfs_gpfs_kernel_flock,
1412 .linux_setlease_fn = vfs_gpfs_setlease,
1413 .get_real_filename_fn = vfs_gpfs_get_real_filename,
1414 .fget_nt_acl_fn = gpfsacl_fget_nt_acl,
1415 .get_nt_acl_fn = gpfsacl_get_nt_acl,
1416 .fset_nt_acl_fn = gpfsacl_fset_nt_acl,
1417 .sys_acl_get_file_fn = gpfsacl_sys_acl_get_file,
1418 .sys_acl_get_fd_fn = gpfsacl_sys_acl_get_fd,
1419 .sys_acl_set_file_fn = gpfsacl_sys_acl_set_file,
1420 .sys_acl_set_fd_fn = gpfsacl_sys_acl_set_fd,
1421 .sys_acl_delete_def_file_fn = gpfsacl_sys_acl_delete_def_file,
1422 .chmod_fn = vfs_gpfs_chmod,
1423 .fchmod_fn = vfs_gpfs_fchmod,
1424 .close_fn = vfs_gpfs_close,
1425 .setxattr_fn = gpfs_set_xattr,
1426 .getxattr_fn = gpfs_get_xattr,
1427 .stat_fn = vfs_gpfs_stat,
1428 .fstat_fn = vfs_gpfs_fstat,
1429 .lstat_fn = vfs_gpfs_lstat,
1430 .ntimes_fn = vfs_gpfs_ntimes,
1431 .is_offline_fn = vfs_gpfs_is_offline,
1432 .aio_force_fn = vfs_gpfs_aio_force,
1433 .sendfile_fn = vfs_gpfs_sendfile,
1434 .open_fn = vfs_gpfs_open,
1435 .ftruncate_fn = vfs_gpfs_ftruncate
1438 NTSTATUS vfs_gpfs_init(void);
1439 NTSTATUS vfs_gpfs_init(void)
1443 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "gpfs",