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"
35 #define DBGC_CLASS DBGC_VFS
37 #ifndef GPFS_GETACL_NATIVE
38 #define GPFS_GETACL_NATIVE 0x00000004
41 struct gpfs_config_data
{
42 struct smbacl4_vfs_params nfs4_params
;
56 struct gpfs_fsp_extension
{
60 static inline unsigned int gpfs_acl_flags(gpfs_acl_t
*gacl
)
62 if (gacl
->acl_level
== GPFS_ACL_LEVEL_V4FLAGS
) {
63 return gacl
->v4Level1
.acl_flags
;
68 static inline gpfs_ace_v4_t
*gpfs_ace_ptr(gpfs_acl_t
*gacl
, unsigned int i
)
70 if (gacl
->acl_level
== GPFS_ACL_LEVEL_V4FLAGS
) {
71 return &gacl
->v4Level1
.ace_v4
[i
];
73 return &gacl
->ace_v4
[i
];
76 static bool set_gpfs_sharemode(files_struct
*fsp
, uint32_t access_mask
,
77 uint32_t share_access
)
79 unsigned int allow
= GPFS_SHARE_NONE
;
80 unsigned int deny
= GPFS_DENY_NONE
;
83 if ((fsp
== NULL
) || (fsp
->fh
== NULL
) || (fsp
->fh
->fd
< 0)) {
84 /* No real file, don't disturb */
88 allow
|= (access_mask
& (FILE_WRITE_DATA
|FILE_APPEND_DATA
)) ?
90 allow
|= (access_mask
& (FILE_READ_DATA
|FILE_EXECUTE
)) ?
93 if (allow
== GPFS_SHARE_NONE
) {
94 DEBUG(10, ("special case am=no_access:%x\n",access_mask
));
97 deny
|= (share_access
& FILE_SHARE_WRITE
) ?
99 deny
|= (share_access
& (FILE_SHARE_READ
)) ?
103 * GPFS_DENY_DELETE can only be set together with either
104 * GPFS_DENY_WRITE or GPFS_DENY_READ.
106 if (deny
& (GPFS_DENY_WRITE
|GPFS_DENY_READ
)) {
107 deny
|= (share_access
& (FILE_SHARE_DELETE
)) ?
108 0 : GPFS_DENY_DELETE
;
111 DEBUG(10, ("am=%x, allow=%d, sa=%x, deny=%d\n",
112 access_mask
, allow
, share_access
, deny
));
114 result
= gpfswrap_set_share(fsp
->fh
->fd
, allow
, deny
);
116 if (errno
== ENOSYS
) {
117 DEBUG(5, ("VFS module vfs_gpfs loaded, but gpfs "
118 "set_share function support not available. "
119 "Allowing access\n"));
122 DEBUG(10, ("gpfs_set_share failed: %s\n",
127 return (result
== 0);
130 static int vfs_gpfs_kernel_flock(vfs_handle_struct
*handle
, files_struct
*fsp
,
131 uint32_t share_mode
, uint32_t access_mask
)
134 struct gpfs_config_data
*config
;
137 START_PROFILE(syscall_kernel_flock
);
139 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
140 struct gpfs_config_data
,
143 if(!config
->sharemodes
) {
148 * A named stream fsp will have the basefile open in the fsp
149 * fd, so lacking a distinct fd for the stream we have to skip
150 * kernel_flock and set_gpfs_sharemode for stream.
152 if (is_ntfs_stream_smb_fname(fsp
->fsp_name
) &&
153 !is_ntfs_default_stream_smb_fname(fsp
->fsp_name
)) {
154 DEBUG(2,("%s: kernel_flock on stream\n", fsp_str_dbg(fsp
)));
158 kernel_flock(fsp
->fh
->fd
, share_mode
, access_mask
);
160 if (!set_gpfs_sharemode(fsp
, access_mask
, fsp
->share_access
)) {
164 END_PROFILE(syscall_kernel_flock
);
169 static int vfs_gpfs_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
172 struct gpfs_config_data
*config
;
174 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
175 struct gpfs_config_data
,
178 if (config
->sharemodes
&& (fsp
->fh
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
179 set_gpfs_sharemode(fsp
, 0, 0);
182 return SMB_VFS_NEXT_CLOSE(handle
, fsp
);
185 static int set_gpfs_lease(int fd
, int leasetype
)
187 int gpfs_type
= GPFS_LEASE_NONE
;
189 if (leasetype
== F_RDLCK
) {
190 gpfs_type
= GPFS_LEASE_READ
;
192 if (leasetype
== F_WRLCK
) {
193 gpfs_type
= GPFS_LEASE_WRITE
;
196 /* we unconditionally set CAP_LEASE, rather than looking for
197 -1/EACCES as there is a bug in some versions of
198 libgpfs_gpl.so which results in a leaked fd on /dev/ss0
199 each time we try this with the wrong capabilities set
201 linux_set_lease_capability();
202 return gpfswrap_set_lease(fd
, gpfs_type
);
205 static int vfs_gpfs_setlease(vfs_handle_struct
*handle
, files_struct
*fsp
,
208 struct gpfs_config_data
*config
;
211 START_PROFILE(syscall_linux_setlease
);
213 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
214 struct gpfs_config_data
,
217 if (linux_set_lease_sighandler(fsp
->fh
->fd
) == -1) {
222 if (config
->leases
) {
224 * Ensure the lease owner is root to allow
225 * correct delivery of lease-break signals.
228 ret
= set_gpfs_lease(fsp
->fh
->fd
,leasetype
);
233 END_PROFILE(syscall_linux_setlease
);
238 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct
*handle
,
245 char *full_path
= NULL
;
246 char *to_free
= NULL
;
247 char real_pathname
[PATH_MAX
+1], tmpbuf
[PATH_MAX
];
248 size_t full_path_len
;
251 struct gpfs_config_data
*config
;
253 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
254 struct gpfs_config_data
,
257 if (!config
->getrealfilename
) {
258 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
259 mem_ctx
, found_name
);
262 mangled
= mangle_is_mangled(name
, handle
->conn
->params
);
264 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
265 mem_ctx
, found_name
);
268 full_path_len
= full_path_tos(path
, name
, tmpbuf
, sizeof(tmpbuf
),
269 &full_path
, &to_free
);
270 if (full_path_len
== -1) {
275 buflen
= sizeof(real_pathname
) - 1;
277 result
= gpfswrap_get_realfilename_path(full_path
, real_pathname
,
280 TALLOC_FREE(to_free
);
282 if ((result
== -1) && (errno
== ENOSYS
)) {
283 return SMB_VFS_NEXT_GET_REAL_FILENAME(
284 handle
, path
, name
, mem_ctx
, found_name
);
288 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
294 * GPFS does not necessarily null-terminate the returned path
295 * but instead returns the buffer length in buflen.
298 if (buflen
< sizeof(real_pathname
)) {
299 real_pathname
[buflen
] = '\0';
301 real_pathname
[sizeof(real_pathname
)-1] = '\0';
304 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
305 path
, name
, real_pathname
));
307 name
= strrchr_m(real_pathname
, '/');
313 *found_name
= talloc_strdup(mem_ctx
, name
+1);
314 if (*found_name
== NULL
) {
322 static void sd2gpfs_control(uint16_t control
, struct gpfs_acl
*gacl
)
324 unsigned int gpfs_aclflags
= 0;
325 control
&= SEC_DESC_DACL_PROTECTED
| SEC_DESC_SACL_PROTECTED
|
326 SEC_DESC_DACL_AUTO_INHERITED
| SEC_DESC_SACL_AUTO_INHERITED
|
327 SEC_DESC_DACL_DEFAULTED
| SEC_DESC_SACL_DEFAULTED
|
328 SEC_DESC_DACL_PRESENT
| SEC_DESC_SACL_PRESENT
;
329 gpfs_aclflags
= control
<< 8;
330 if (!(control
& SEC_DESC_DACL_PRESENT
))
331 gpfs_aclflags
|= ACL4_FLAG_NULL_DACL
;
332 if (!(control
& SEC_DESC_SACL_PRESENT
))
333 gpfs_aclflags
|= ACL4_FLAG_NULL_SACL
;
334 gacl
->acl_level
= GPFS_ACL_LEVEL_V4FLAGS
;
335 gacl
->v4Level1
.acl_flags
= gpfs_aclflags
;
338 static uint16_t gpfs2sd_control(unsigned int gpfs_aclflags
)
340 uint16_t control
= gpfs_aclflags
>> 8;
341 control
&= SEC_DESC_DACL_PROTECTED
| SEC_DESC_SACL_PROTECTED
|
342 SEC_DESC_DACL_AUTO_INHERITED
| SEC_DESC_SACL_AUTO_INHERITED
|
343 SEC_DESC_DACL_DEFAULTED
| SEC_DESC_SACL_DEFAULTED
|
344 SEC_DESC_DACL_PRESENT
| SEC_DESC_SACL_PRESENT
;
345 control
|= SEC_DESC_SELF_RELATIVE
;
349 static void gpfs_dumpacl(int level
, struct gpfs_acl
*gacl
)
354 DEBUG(0, ("gpfs acl is NULL\n"));
358 DEBUG(level
, ("len: %d, level: %d, version: %d, nace: %d, "
360 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
361 gacl
->acl_nace
, gpfs_acl_flags(gacl
)));
363 for(i
=0; i
<gacl
->acl_nace
; i
++)
365 struct gpfs_ace_v4
*gace
= gpfs_ace_ptr(gacl
, i
);
366 DEBUG(level
, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, "
367 "iflags:0x%x, who:%u\n",
368 i
, gace
->aceType
, gace
->aceFlags
, gace
->aceMask
,
369 gace
->aceIFlags
, gace
->aceWho
));
373 static int gpfs_getacl_with_capability(const char *fname
, int flags
, void *buf
)
375 int ret
, saved_errno
;
377 set_effective_capability(DAC_OVERRIDE_CAPABILITY
);
379 ret
= gpfswrap_getacl(discard_const_p(char, fname
), flags
, buf
);
382 drop_effective_capability(DAC_OVERRIDE_CAPABILITY
);
389 * get the ACL from GPFS, allocated on the specified mem_ctx
390 * internally retries when initial buffer was too small
392 * caller needs to cast result to either
393 * raw = yes: struct gpfs_opaque_acl
394 * raw = no: struct gpfs_acl
397 static void *vfs_gpfs_getacl(TALLOC_CTX
*mem_ctx
,
400 const gpfs_aclType_t type
)
408 bool use_capability
= false;
412 aclbuf
= talloc_zero_size(mem_ctx
, size
);
413 if (aclbuf
== NULL
) {
419 struct gpfs_opaque_acl
*buf
= (struct gpfs_opaque_acl
*) aclbuf
;
420 buf
->acl_type
= type
;
421 flags
= GPFS_GETACL_NATIVE
;
422 len
= (unsigned int *) &(buf
->acl_buffer_len
);
423 struct_size
= sizeof(struct gpfs_opaque_acl
);
425 struct gpfs_acl
*buf
= (struct gpfs_acl
*) aclbuf
;
426 buf
->acl_type
= type
;
427 buf
->acl_level
= GPFS_ACL_LEVEL_V4FLAGS
;
428 flags
= GPFS_GETACL_STRUCT
;
429 len
= &(buf
->acl_len
);
430 /* reserve space for control flags in gpfs 3.5 and beyond */
431 struct_size
= sizeof(struct gpfs_acl
) + sizeof(unsigned int);
434 /* set the length of the buffer as input value */
437 if (use_capability
) {
438 ret
= gpfs_getacl_with_capability(fname
, flags
, aclbuf
);
440 ret
= gpfswrap_getacl(discard_const_p(char, fname
),
442 if ((ret
!= 0) && (errno
== EACCES
)) {
443 DBG_DEBUG("Retry with DAC capability for %s\n", fname
);
444 use_capability
= true;
445 ret
= gpfs_getacl_with_capability(fname
, flags
, aclbuf
);
449 if ((ret
!= 0) && (errno
== ENOSPC
)) {
451 * get the size needed to accommodate the complete buffer
453 * the value returned only applies to the ACL blob in the
454 * struct so make sure to also have headroom for the first
455 * struct members by adding room for the complete struct
456 * (might be a few bytes too much then)
458 size
= *len
+ struct_size
;
460 DEBUG(10, ("Increasing ACL buffer size to %zu\n", size
));
465 DEBUG(5, ("smbd_gpfs_getacl failed with %s\n",
474 /* Tries to get nfs4 acls and returns SMB ACL allocated.
475 * On failure returns 1 if it got non-NFSv4 ACL to prompt
476 * retry with POSIX ACL checks.
477 * On failure returns -1 if there is system (GPFS) error, check errno.
478 * Returns 0 on success
480 static int gpfs_get_nfs4_acl(TALLOC_CTX
*mem_ctx
, const char *fname
,
481 struct SMB4ACL_T
**ppacl
)
484 struct gpfs_acl
*gacl
= NULL
;
485 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname
));
488 gacl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(), fname
,
491 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
492 fname
, strerror(errno
)));
493 if (errno
== ENODATA
) {
495 * GPFS returns ENODATA for snapshot
496 * directories. Retry with POSIX ACLs check.
504 if (gacl
->acl_type
!= GPFS_ACL_TYPE_NFS4
) {
505 DEBUG(10, ("Got non-nfsv4 acl\n"));
506 /* Retry with POSIX ACLs check */
511 *ppacl
= smb_create_smb4acl(mem_ctx
);
513 if (gacl
->acl_level
== GPFS_ACL_LEVEL_V4FLAGS
) {
514 uint16_t control
= gpfs2sd_control(gpfs_acl_flags(gacl
));
515 smbacl4_set_controlflags(*ppacl
, control
);
518 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d, control: %x\n",
519 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
520 gacl
->acl_nace
, gpfs_acl_flags(gacl
)));
522 for (i
=0; i
<gacl
->acl_nace
; i
++) {
523 struct gpfs_ace_v4
*gace
= gpfs_ace_ptr(gacl
, i
);
524 SMB_ACE4PROP_T smbace
= { 0 };
525 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
526 "who: %d\n", gace
->aceType
, gace
->aceIFlags
,
527 gace
->aceFlags
, gace
->aceMask
, gace
->aceWho
));
529 if (gace
->aceIFlags
& ACE4_IFLAG_SPECIAL_ID
) {
530 smbace
.flags
|= SMB_ACE4_ID_SPECIAL
;
531 switch (gace
->aceWho
) {
532 case ACE4_SPECIAL_OWNER
:
533 smbace
.who
.special_id
= SMB_ACE4_WHO_OWNER
;
535 case ACE4_SPECIAL_GROUP
:
536 smbace
.who
.special_id
= SMB_ACE4_WHO_GROUP
;
538 case ACE4_SPECIAL_EVERYONE
:
539 smbace
.who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
542 DEBUG(8, ("invalid special gpfs id %d "
543 "ignored\n", gace
->aceWho
));
544 continue; /* don't add it */
547 if (gace
->aceFlags
& ACE4_FLAG_GROUP_ID
)
548 smbace
.who
.gid
= gace
->aceWho
;
550 smbace
.who
.uid
= gace
->aceWho
;
553 /* remove redundant deny entries */
554 if (i
> 0 && gace
->aceType
== SMB_ACE4_ACCESS_DENIED_ACE_TYPE
) {
555 struct gpfs_ace_v4
*prev
= gpfs_ace_ptr(gacl
, i
- 1);
556 if (prev
->aceType
== SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
&&
557 prev
->aceFlags
== gace
->aceFlags
&&
558 prev
->aceIFlags
== gace
->aceIFlags
&&
559 (gace
->aceMask
& prev
->aceMask
) == 0 &&
560 gace
->aceWho
== prev
->aceWho
) {
561 /* it's redundant - skip it */
566 smbace
.aceType
= gace
->aceType
;
567 smbace
.aceFlags
= gace
->aceFlags
;
568 smbace
.aceMask
= gace
->aceMask
;
569 smb_add_ace4(*ppacl
, &smbace
);
577 static NTSTATUS
gpfsacl_fget_nt_acl(vfs_handle_struct
*handle
,
578 files_struct
*fsp
, uint32_t security_info
,
580 struct security_descriptor
**ppdesc
)
582 struct SMB4ACL_T
*pacl
= NULL
;
584 struct gpfs_config_data
*config
;
585 TALLOC_CTX
*frame
= talloc_stackframe();
590 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
591 struct gpfs_config_data
,
592 return NT_STATUS_INTERNAL_ERROR
);
595 status
= SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
601 result
= gpfs_get_nfs4_acl(frame
, fsp
->fsp_name
->base_name
, &pacl
);
604 status
= smb_fget_nt_acl_nfs4(fsp
, &config
->nfs4_params
,
606 mem_ctx
, ppdesc
, pacl
);
612 DEBUG(10, ("retrying with posix acl...\n"));
613 status
= posix_fget_nt_acl(fsp
, security_info
,
621 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
622 return map_nt_error_from_unix(errno
);
625 static NTSTATUS
gpfsacl_get_nt_acl(vfs_handle_struct
*handle
,
626 const struct smb_filename
*smb_fname
,
627 uint32_t security_info
,
629 struct security_descriptor
**ppdesc
)
631 struct SMB4ACL_T
*pacl
= NULL
;
633 struct gpfs_config_data
*config
;
634 TALLOC_CTX
*frame
= talloc_stackframe();
639 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
640 struct gpfs_config_data
,
641 return NT_STATUS_INTERNAL_ERROR
);
644 status
= SMB_VFS_NEXT_GET_NT_ACL(handle
, smb_fname
,
651 result
= gpfs_get_nfs4_acl(frame
, smb_fname
->base_name
, &pacl
);
654 status
= smb_get_nt_acl_nfs4(handle
->conn
, smb_fname
,
655 &config
->nfs4_params
,
656 security_info
, mem_ctx
, ppdesc
,
663 DEBUG(10, ("retrying with posix acl...\n"));
664 status
= posix_get_nt_acl(handle
->conn
, smb_fname
,
665 security_info
, mem_ctx
, ppdesc
);
670 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
672 return map_nt_error_from_unix(errno
);
675 static struct gpfs_acl
*vfs_gpfs_smbacl2gpfsacl(TALLOC_CTX
*mem_ctx
,
677 struct SMB4ACL_T
*smbacl
,
680 struct gpfs_acl
*gacl
;
681 gpfs_aclLen_t gacl_len
;
682 struct SMB4ACE_T
*smbace
;
684 gacl_len
= offsetof(gpfs_acl_t
, ace_v4
) + sizeof(unsigned int)
685 + smb_get_naces(smbacl
) * sizeof(gpfs_ace_v4_t
);
687 gacl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, gacl_len
);
689 DEBUG(0, ("talloc failed\n"));
694 gacl
->acl_level
= GPFS_ACL_LEVEL_BASE
;
695 gacl
->acl_version
= GPFS_ACL_VERSION_NFS4
;
696 gacl
->acl_type
= GPFS_ACL_TYPE_NFS4
;
697 gacl
->acl_nace
= 0; /* change later... */
700 gacl
->acl_level
= GPFS_ACL_LEVEL_V4FLAGS
;
701 sd2gpfs_control(smbacl4_get_controlflags(smbacl
), gacl
);
704 for (smbace
=smb_first_ace4(smbacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
705 struct gpfs_ace_v4
*gace
= gpfs_ace_ptr(gacl
, gacl
->acl_nace
);
706 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
708 gace
->aceType
= aceprop
->aceType
;
709 gace
->aceFlags
= aceprop
->aceFlags
;
710 gace
->aceMask
= aceprop
->aceMask
;
713 * GPFS can't distinguish between WRITE and APPEND on
714 * files, so one being set without the other is an
715 * error. Sorry for the many ()'s :-)
718 if (!fsp
->is_directory
720 ((((gace
->aceMask
& ACE4_MASK_WRITE
) == 0)
721 && ((gace
->aceMask
& ACE4_MASK_APPEND
) != 0))
723 (((gace
->aceMask
& ACE4_MASK_WRITE
) != 0)
724 && ((gace
->aceMask
& ACE4_MASK_APPEND
) == 0)))
726 lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
727 "merge_writeappend", True
)) {
728 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
729 "WRITE^APPEND, setting WRITE|APPEND\n",
731 gace
->aceMask
|= ACE4_MASK_WRITE
|ACE4_MASK_APPEND
;
734 gace
->aceIFlags
= (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
) ? ACE4_IFLAG_SPECIAL_ID
: 0;
736 if (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
)
738 switch(aceprop
->who
.special_id
)
740 case SMB_ACE4_WHO_EVERYONE
:
741 gace
->aceWho
= ACE4_SPECIAL_EVERYONE
;
743 case SMB_ACE4_WHO_OWNER
:
744 gace
->aceWho
= ACE4_SPECIAL_OWNER
;
746 case SMB_ACE4_WHO_GROUP
:
747 gace
->aceWho
= ACE4_SPECIAL_GROUP
;
750 DEBUG(8, ("unsupported special_id %d\n", aceprop
->who
.special_id
));
751 continue; /* don't add it !!! */
754 /* just only for the type safety... */
755 if (aceprop
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)
756 gace
->aceWho
= aceprop
->who
.gid
;
758 gace
->aceWho
= aceprop
->who
.uid
;
763 gacl
->acl_len
= (char *)gpfs_ace_ptr(gacl
, gacl
->acl_nace
)
768 static bool gpfsacl_process_smbacl(vfs_handle_struct
*handle
,
770 struct SMB4ACL_T
*smbacl
)
773 struct gpfs_acl
*gacl
;
774 TALLOC_CTX
*mem_ctx
= talloc_tos();
776 gacl
= vfs_gpfs_smbacl2gpfsacl(mem_ctx
, fsp
, smbacl
, true);
777 if (gacl
== NULL
) { /* out of memory */
780 ret
= gpfswrap_putacl(fsp
->fsp_name
->base_name
,
781 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gacl
);
783 if ((ret
!= 0) && (errno
== EINVAL
)) {
784 DEBUG(10, ("Retry without nfs41 control flags\n"));
786 gacl
= vfs_gpfs_smbacl2gpfsacl(mem_ctx
, fsp
, smbacl
, false);
787 if (gacl
== NULL
) { /* out of memory */
790 ret
= gpfswrap_putacl(fsp
->fsp_name
->base_name
,
791 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
,
796 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno
)));
797 gpfs_dumpacl(8, gacl
);
801 DEBUG(10, ("gpfs_putacl succeeded\n"));
805 static NTSTATUS
gpfsacl_set_nt_acl_internal(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32_t security_info_sent
, const struct security_descriptor
*psd
)
807 struct gpfs_acl
*acl
;
808 NTSTATUS result
= NT_STATUS_ACCESS_DENIED
;
810 acl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(),
811 fsp
->fsp_name
->base_name
,
814 return map_nt_error_from_unix(errno
);
817 if (acl
->acl_version
== GPFS_ACL_VERSION_NFS4
) {
818 struct gpfs_config_data
*config
;
820 if (lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
821 "refuse_dacl_protected", false)
822 && (psd
->type
&SEC_DESC_DACL_PROTECTED
)) {
823 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
825 return NT_STATUS_NOT_SUPPORTED
;
828 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
829 struct gpfs_config_data
,
830 return NT_STATUS_INTERNAL_ERROR
);
832 result
= smb_set_nt_acl_nfs4(handle
,
833 fsp
, &config
->nfs4_params
, security_info_sent
, psd
,
834 gpfsacl_process_smbacl
);
835 } else { /* assume POSIX ACL - by default... */
836 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
843 static NTSTATUS
gpfsacl_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32_t security_info_sent
, const struct security_descriptor
*psd
)
845 struct gpfs_config_data
*config
;
847 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
848 struct gpfs_config_data
,
849 return NT_STATUS_INTERNAL_ERROR
);
852 return SMB_VFS_NEXT_FSET_NT_ACL(handle
, fsp
, security_info_sent
, psd
);
855 return gpfsacl_set_nt_acl_internal(handle
, fsp
, security_info_sent
, psd
);
858 static SMB_ACL_T
gpfs2smb_acl(const struct gpfs_acl
*pacl
, TALLOC_CTX
*mem_ctx
)
863 result
= sys_acl_init(mem_ctx
);
864 if (result
== NULL
) {
869 result
->count
= pacl
->acl_nace
;
870 result
->acl
= talloc_realloc(result
, result
->acl
, struct smb_acl_entry
,
872 if (result
->acl
== NULL
) {
878 for (i
=0; i
<pacl
->acl_nace
; i
++) {
879 struct smb_acl_entry
*ace
= &result
->acl
[i
];
880 const struct gpfs_ace_v1
*g_ace
= &pacl
->ace_v1
[i
];
882 DEBUG(10, ("Converting type %d id %lu perm %x\n",
883 (int)g_ace
->ace_type
, (unsigned long)g_ace
->ace_who
,
884 (int)g_ace
->ace_perm
));
886 switch (g_ace
->ace_type
) {
888 ace
->a_type
= SMB_ACL_USER
;
889 ace
->info
.user
.uid
= (uid_t
)g_ace
->ace_who
;
891 case GPFS_ACL_USER_OBJ
:
892 ace
->a_type
= SMB_ACL_USER_OBJ
;
895 ace
->a_type
= SMB_ACL_GROUP
;
896 ace
->info
.group
.gid
= (gid_t
)g_ace
->ace_who
;
898 case GPFS_ACL_GROUP_OBJ
:
899 ace
->a_type
= SMB_ACL_GROUP_OBJ
;
902 ace
->a_type
= SMB_ACL_OTHER
;
905 ace
->a_type
= SMB_ACL_MASK
;
908 DEBUG(10, ("Got invalid ace_type: %d\n",
916 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_READ
) ?
918 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_WRITE
) ?
920 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_EXECUTE
) ?
923 DEBUGADD(10, ("Converted to %d perm %x\n",
924 ace
->a_type
, ace
->a_perm
));
930 static SMB_ACL_T
gpfsacl_get_posix_acl(const char *path
, gpfs_aclType_t type
,
933 struct gpfs_acl
*pacl
;
934 SMB_ACL_T result
= NULL
;
936 pacl
= vfs_gpfs_getacl(talloc_tos(), path
, false, type
);
939 DEBUG(10, ("vfs_gpfs_getacl failed for %s with %s\n",
940 path
, strerror(errno
)));
947 if (pacl
->acl_version
!= GPFS_ACL_VERSION_POSIX
) {
948 DEBUG(10, ("Got acl version %d, expected %d\n",
949 pacl
->acl_version
, GPFS_ACL_VERSION_POSIX
));
954 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
955 pacl
->acl_len
, pacl
->acl_level
, pacl
->acl_version
,
958 result
= gpfs2smb_acl(pacl
, mem_ctx
);
959 if (result
!= NULL
) {
974 static SMB_ACL_T
gpfsacl_sys_acl_get_file(vfs_handle_struct
*handle
,
975 const struct smb_filename
*smb_fname
,
979 gpfs_aclType_t gpfs_type
;
980 struct gpfs_config_data
*config
;
982 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
983 struct gpfs_config_data
,
987 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle
, smb_fname
,
992 case SMB_ACL_TYPE_ACCESS
:
993 gpfs_type
= GPFS_ACL_TYPE_ACCESS
;
995 case SMB_ACL_TYPE_DEFAULT
:
996 gpfs_type
= GPFS_ACL_TYPE_DEFAULT
;
999 DEBUG(0, ("Got invalid type: %d\n", type
));
1000 smb_panic("exiting");
1003 return gpfsacl_get_posix_acl(smb_fname
->base_name
, gpfs_type
, mem_ctx
);
1006 static SMB_ACL_T
gpfsacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
1008 TALLOC_CTX
*mem_ctx
)
1010 struct gpfs_config_data
*config
;
1012 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1013 struct gpfs_config_data
,
1017 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle
, fsp
, mem_ctx
);
1020 return gpfsacl_get_posix_acl(fsp
->fsp_name
->base_name
,
1021 GPFS_ACL_TYPE_ACCESS
, mem_ctx
);
1024 static int gpfsacl_sys_acl_blob_get_file(vfs_handle_struct
*handle
,
1025 const struct smb_filename
*smb_fname
,
1026 TALLOC_CTX
*mem_ctx
,
1027 char **blob_description
,
1030 struct gpfs_config_data
*config
;
1031 struct gpfs_opaque_acl
*acl
= NULL
;
1034 const char *path_p
= smb_fname
->base_name
;
1036 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1037 struct gpfs_config_data
,
1041 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle
, smb_fname
,
1048 acl
= (struct gpfs_opaque_acl
*)
1049 vfs_gpfs_getacl(mem_ctx
,
1052 GPFS_ACL_TYPE_NFS4
);
1055 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
1056 errno
, strerror(errno
)));
1058 /* EINVAL means POSIX ACL, bail out on other cases */
1059 if (errno
!= EINVAL
) {
1066 * file has NFSv4 ACL
1068 * we only need the actual ACL blob here
1069 * acl_version will always be NFS4 because we asked
1071 * acl_type is only used for POSIX ACLs
1073 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
1074 aclblob
.length
= acl
->acl_buffer_len
;
1076 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
1077 if (!*blob_description
) {
1083 result
= non_posix_sys_acl_blob_get_file_helper(handle
, smb_fname
,
1091 /* fall back to POSIX ACL */
1092 return posix_sys_acl_blob_get_file(handle
, smb_fname
, mem_ctx
,
1093 blob_description
, blob
);
1096 static int gpfsacl_sys_acl_blob_get_fd(vfs_handle_struct
*handle
,
1098 TALLOC_CTX
*mem_ctx
,
1099 char **blob_description
,
1102 struct gpfs_config_data
*config
;
1103 struct gpfs_opaque_acl
*acl
= NULL
;
1107 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1108 struct gpfs_config_data
,
1112 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle
, fsp
, mem_ctx
,
1113 blob_description
, blob
);
1117 acl
= (struct gpfs_opaque_acl
*) vfs_gpfs_getacl(mem_ctx
,
1118 fsp
->fsp_name
->base_name
,
1120 GPFS_ACL_TYPE_NFS4
);
1123 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
1124 errno
, strerror(errno
)));
1126 /* EINVAL means POSIX ACL, bail out on other cases */
1127 if (errno
!= EINVAL
) {
1134 * file has NFSv4 ACL
1136 * we only need the actual ACL blob here
1137 * acl_version will always be NFS4 because we asked
1139 * acl_type is only used for POSIX ACLs
1141 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
1142 aclblob
.length
= acl
->acl_buffer_len
;
1144 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
1145 if (!*blob_description
) {
1151 result
= non_posix_sys_acl_blob_get_fd_helper(handle
, fsp
,
1159 /* fall back to POSIX ACL */
1160 return posix_sys_acl_blob_get_fd(handle
, fsp
, mem_ctx
,
1161 blob_description
, blob
);
1164 static struct gpfs_acl
*smb2gpfs_acl(const SMB_ACL_T pacl
,
1165 SMB_ACL_TYPE_T type
)
1168 struct gpfs_acl
*result
;
1171 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl
->count
));
1173 len
= offsetof(gpfs_acl_t
, ace_v1
) + (pacl
->count
) *
1174 sizeof(gpfs_ace_v1_t
);
1176 result
= (struct gpfs_acl
*)SMB_MALLOC(len
);
1177 if (result
== NULL
) {
1182 result
->acl_len
= len
;
1183 result
->acl_level
= 0;
1184 result
->acl_version
= GPFS_ACL_VERSION_POSIX
;
1185 result
->acl_type
= (type
== SMB_ACL_TYPE_DEFAULT
) ?
1186 GPFS_ACL_TYPE_DEFAULT
: GPFS_ACL_TYPE_ACCESS
;
1187 result
->acl_nace
= pacl
->count
;
1189 for (i
=0; i
<pacl
->count
; i
++) {
1190 const struct smb_acl_entry
*ace
= &pacl
->acl
[i
];
1191 struct gpfs_ace_v1
*g_ace
= &result
->ace_v1
[i
];
1193 DEBUG(10, ("Converting type %d perm %x\n",
1194 (int)ace
->a_type
, (int)ace
->a_perm
));
1196 g_ace
->ace_perm
= 0;
1198 switch(ace
->a_type
) {
1200 g_ace
->ace_type
= GPFS_ACL_USER
;
1201 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.user
.uid
;
1203 case SMB_ACL_USER_OBJ
:
1204 g_ace
->ace_type
= GPFS_ACL_USER_OBJ
;
1205 g_ace
->ace_perm
|= ACL_PERM_CONTROL
;
1209 g_ace
->ace_type
= GPFS_ACL_GROUP
;
1210 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.group
.gid
;
1212 case SMB_ACL_GROUP_OBJ
:
1213 g_ace
->ace_type
= GPFS_ACL_GROUP_OBJ
;
1217 g_ace
->ace_type
= GPFS_ACL_MASK
;
1218 g_ace
->ace_perm
= 0x8f;
1222 g_ace
->ace_type
= GPFS_ACL_OTHER
;
1226 DEBUG(10, ("Got invalid ace_type: %d\n", ace
->a_type
));
1232 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_READ
) ?
1234 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_WRITE
) ?
1236 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_EXECUTE
) ?
1237 ACL_PERM_EXECUTE
: 0;
1239 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
1240 g_ace
->ace_type
, g_ace
->ace_who
, g_ace
->ace_perm
));
1246 static int gpfsacl_sys_acl_set_file(vfs_handle_struct
*handle
,
1247 const struct smb_filename
*smb_fname
,
1248 SMB_ACL_TYPE_T type
,
1251 struct gpfs_acl
*gpfs_acl
;
1253 struct gpfs_config_data
*config
;
1255 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1256 struct gpfs_config_data
,
1260 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle
, smb_fname
,
1264 gpfs_acl
= smb2gpfs_acl(theacl
, type
);
1265 if (gpfs_acl
== NULL
) {
1269 result
= gpfswrap_putacl(discard_const_p(char, smb_fname
->base_name
),
1270 GPFS_PUTACL_STRUCT
|GPFS_ACL_SAMBA
, gpfs_acl
);
1272 SAFE_FREE(gpfs_acl
);
1276 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
1280 struct gpfs_config_data
*config
;
1282 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1283 struct gpfs_config_data
,
1287 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle
, fsp
, theacl
);
1290 return gpfsacl_sys_acl_set_file(handle
, fsp
->fsp_name
,
1291 SMB_ACL_TYPE_ACCESS
, theacl
);
1294 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
1295 const struct smb_filename
*smb_fname
)
1297 struct gpfs_config_data
*config
;
1299 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1300 struct gpfs_config_data
,
1304 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle
, smb_fname
);
1312 * Assumed: mode bits are shiftable and standard
1313 * Output: the new aceMask field for an smb nfs4 ace
1315 static uint32_t gpfsacl_mask_filter(uint32_t aceType
, uint32_t aceMask
, uint32_t rwx
)
1317 const uint32_t posix_nfs4map
[3] = {
1318 SMB_ACE4_EXECUTE
, /* execute */
1319 SMB_ACE4_WRITE_DATA
| SMB_ACE4_APPEND_DATA
, /* write; GPFS specific */
1320 SMB_ACE4_READ_DATA
/* read */
1323 uint32_t posix_mask
= 0x01;
1327 for(i
=0; i
<3; i
++) {
1328 nfs4_bits
= posix_nfs4map
[i
];
1329 posix_bit
= rwx
& posix_mask
;
1331 if (aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
) {
1333 aceMask
|= nfs4_bits
;
1335 aceMask
&= ~nfs4_bits
;
1337 /* add deny bits when suitable */
1339 aceMask
|= nfs4_bits
;
1341 aceMask
&= ~nfs4_bits
;
1342 } /* other ace types are unexpected */
1350 static int gpfsacl_emu_chmod(vfs_handle_struct
*handle
,
1351 const char *path
, mode_t mode
)
1353 struct SMB4ACL_T
*pacl
= NULL
;
1355 bool haveAllowEntry
[SMB_ACE4_WHO_EVERYONE
+ 1] = {False
, False
, False
, False
};
1357 files_struct fake_fsp
= { 0 }; /* TODO: rationalize parametrization */
1358 struct SMB4ACE_T
*smbace
;
1359 TALLOC_CTX
*frame
= talloc_stackframe();
1361 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path
, mode
));
1363 result
= gpfs_get_nfs4_acl(frame
, path
, &pacl
);
1369 if (mode
& ~(S_IRWXU
| S_IRWXG
| S_IRWXO
)) {
1370 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode
, path
));
1373 for (smbace
=smb_first_ace4(pacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
1374 SMB_ACE4PROP_T
*ace
= smb_get_ace4(smbace
);
1375 uint32_t specid
= ace
->who
.special_id
;
1377 if (ace
->flags
&SMB_ACE4_ID_SPECIAL
&&
1378 ace
->aceType
<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE
&&
1379 specid
<= SMB_ACE4_WHO_EVERYONE
) {
1383 if (ace
->aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
)
1384 haveAllowEntry
[specid
] = True
;
1386 /* mode >> 6 for @owner, mode >> 3 for @group,
1387 * mode >> 0 for @everyone */
1388 newMask
= gpfsacl_mask_filter(ace
->aceType
, ace
->aceMask
,
1389 mode
>> ((SMB_ACE4_WHO_EVERYONE
- specid
) * 3));
1390 if (ace
->aceMask
!=newMask
) {
1391 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
1392 path
, ace
->aceMask
, newMask
, specid
));
1394 ace
->aceMask
= newMask
;
1398 /* make sure we have at least ALLOW entries
1399 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
1402 for(i
= SMB_ACE4_WHO_OWNER
; i
<=SMB_ACE4_WHO_EVERYONE
; i
++) {
1403 SMB_ACE4PROP_T ace
= { 0 };
1405 if (haveAllowEntry
[i
]==True
)
1408 ace
.aceType
= SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
;
1409 ace
.flags
|= SMB_ACE4_ID_SPECIAL
;
1410 ace
.who
.special_id
= i
;
1412 if (i
==SMB_ACE4_WHO_GROUP
) /* not sure it's necessary... */
1413 ace
.aceFlags
|= SMB_ACE4_IDENTIFIER_GROUP
;
1415 ace
.aceMask
= gpfsacl_mask_filter(ace
.aceType
, ace
.aceMask
,
1416 mode
>> ((SMB_ACE4_WHO_EVERYONE
- i
) * 3));
1418 /* don't add unnecessary aces */
1422 /* we add it to the END - as windows expects allow aces */
1423 smb_add_ace4(pacl
, &ace
);
1424 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1425 path
, mode
, i
, ace
.aceMask
));
1428 /* don't add complementary DENY ACEs here */
1429 fake_fsp
.fsp_name
= synthetic_smb_fname(
1430 frame
, path
, NULL
, NULL
, 0);
1431 if (fake_fsp
.fsp_name
== NULL
) {
1437 if (gpfsacl_process_smbacl(handle
, &fake_fsp
, pacl
) == False
) {
1443 return 0; /* ok for [f]chmod */
1446 static int vfs_gpfs_chmod(vfs_handle_struct
*handle
,
1447 const struct smb_filename
*smb_fname
,
1450 struct smb_filename
*smb_fname_cpath
;
1453 smb_fname_cpath
= cp_smb_filename(talloc_tos(), smb_fname
);
1454 if (smb_fname_cpath
== NULL
) {
1459 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_cpath
) != 0) {
1460 TALLOC_FREE(smb_fname_cpath
);
1464 /* avoid chmod() if possible, to preserve acls */
1465 if ((smb_fname_cpath
->st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1466 TALLOC_FREE(smb_fname_cpath
);
1470 rc
= gpfsacl_emu_chmod(handle
, smb_fname
->base_name
, mode
);
1472 return SMB_VFS_NEXT_CHMOD(handle
, smb_fname
, mode
);
1474 TALLOC_FREE(smb_fname_cpath
);
1478 static int vfs_gpfs_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
1483 if (SMB_VFS_NEXT_FSTAT(handle
, fsp
, &st
) != 0) {
1487 /* avoid chmod() if possible, to preserve acls */
1488 if ((st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1492 rc
= gpfsacl_emu_chmod(handle
, fsp
->fsp_name
->base_name
,
1495 return SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
1499 static uint32_t vfs_gpfs_winattrs_to_dosmode(unsigned int winattrs
)
1501 uint32_t dosmode
= 0;
1503 if (winattrs
& GPFS_WINATTR_ARCHIVE
){
1504 dosmode
|= FILE_ATTRIBUTE_ARCHIVE
;
1506 if (winattrs
& GPFS_WINATTR_HIDDEN
){
1507 dosmode
|= FILE_ATTRIBUTE_HIDDEN
;
1509 if (winattrs
& GPFS_WINATTR_SYSTEM
){
1510 dosmode
|= FILE_ATTRIBUTE_SYSTEM
;
1512 if (winattrs
& GPFS_WINATTR_READONLY
){
1513 dosmode
|= FILE_ATTRIBUTE_READONLY
;
1515 if (winattrs
& GPFS_WINATTR_SPARSE_FILE
) {
1516 dosmode
|= FILE_ATTRIBUTE_SPARSE
;
1518 if (winattrs
& GPFS_WINATTR_OFFLINE
) {
1519 dosmode
|= FILE_ATTRIBUTE_OFFLINE
;
1525 static unsigned int vfs_gpfs_dosmode_to_winattrs(uint32_t dosmode
)
1527 unsigned int winattrs
= 0;
1529 if (dosmode
& FILE_ATTRIBUTE_ARCHIVE
){
1530 winattrs
|= GPFS_WINATTR_ARCHIVE
;
1532 if (dosmode
& FILE_ATTRIBUTE_HIDDEN
){
1533 winattrs
|= GPFS_WINATTR_HIDDEN
;
1535 if (dosmode
& FILE_ATTRIBUTE_SYSTEM
){
1536 winattrs
|= GPFS_WINATTR_SYSTEM
;
1538 if (dosmode
& FILE_ATTRIBUTE_READONLY
){
1539 winattrs
|= GPFS_WINATTR_READONLY
;
1541 if (dosmode
& FILE_ATTRIBUTE_SPARSE
) {
1542 winattrs
|= GPFS_WINATTR_SPARSE_FILE
;
1544 if (dosmode
& FILE_ATTRIBUTE_OFFLINE
) {
1545 winattrs
|= GPFS_WINATTR_OFFLINE
;
1551 static int get_dos_attr_with_capability(struct smb_filename
*smb_fname
,
1552 struct gpfs_winattr
*attr
)
1554 int saved_errno
= 0;
1558 * According to MS-FSA 2.1.5.1.2.1 "Algorithm to Check Access to an
1559 * Existing File" FILE_LIST_DIRECTORY on a directory implies
1560 * FILE_READ_ATTRIBUTES for directory entries. Being able to stat() a
1561 * file implies FILE_LIST_DIRECTORY for the directory containing the
1565 if (!VALID_STAT(smb_fname
->st
)) {
1567 * Safety net: dos_mode() already checks this, but as we set
1568 * DAC_OVERRIDE_CAPABILITY based on this, add an additional
1571 DBG_ERR("Rejecting DAC override, invalid stat [%s]\n",
1572 smb_fname_str_dbg(smb_fname
));
1577 set_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1579 ret
= gpfswrap_get_winattrs_path(smb_fname
->base_name
, attr
);
1581 saved_errno
= errno
;
1584 drop_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1586 if (saved_errno
!= 0) {
1587 errno
= saved_errno
;
1592 static NTSTATUS
vfs_gpfs_get_dos_attributes(struct vfs_handle_struct
*handle
,
1593 struct smb_filename
*smb_fname
,
1596 struct gpfs_config_data
*config
;
1597 struct gpfs_winattr attrs
= { };
1600 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1601 struct gpfs_config_data
,
1602 return NT_STATUS_INTERNAL_ERROR
);
1604 if (!config
->winattr
) {
1605 return SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle
,
1606 smb_fname
, dosmode
);
1609 ret
= gpfswrap_get_winattrs_path(smb_fname
->base_name
, &attrs
);
1610 if (ret
== -1 && errno
== ENOSYS
) {
1611 return SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle
, smb_fname
,
1614 if (ret
== -1 && errno
== EACCES
) {
1615 ret
= get_dos_attr_with_capability(smb_fname
, &attrs
);
1618 if (ret
== -1 && errno
== EBADF
) {
1620 * Returned for directory listings in gpfs root for
1621 * .. entry which steps out of gpfs.
1623 DBG_DEBUG("Getting winattrs for %s returned EBADF.\n",
1624 smb_fname
->base_name
);
1625 return map_nt_error_from_unix(errno
);
1626 } else if (ret
== -1) {
1627 DBG_WARNING("Getting winattrs failed for %s: %s\n",
1628 smb_fname
->base_name
, strerror(errno
));
1629 return map_nt_error_from_unix(errno
);
1632 *dosmode
|= vfs_gpfs_winattrs_to_dosmode(attrs
.winAttrs
);
1633 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1634 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1635 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1637 return NT_STATUS_OK
;
1640 static NTSTATUS
vfs_gpfs_fget_dos_attributes(struct vfs_handle_struct
*handle
,
1641 struct files_struct
*fsp
,
1644 struct gpfs_config_data
*config
;
1645 struct gpfs_winattr attrs
= { };
1648 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1649 struct gpfs_config_data
,
1650 return NT_STATUS_INTERNAL_ERROR
);
1652 if (!config
->winattr
) {
1653 return SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle
, fsp
, dosmode
);
1656 ret
= gpfswrap_get_winattrs(fsp
->fh
->fd
, &attrs
);
1657 if (ret
== -1 && errno
== ENOSYS
) {
1658 return SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle
, fsp
, dosmode
);
1661 if (ret
== -1 && errno
== EACCES
) {
1662 int saved_errno
= 0;
1665 * According to MS-FSA 2.1.5.1.2.1 "Algorithm to Check Access to
1666 * an Existing File" FILE_LIST_DIRECTORY on a directory implies
1667 * FILE_READ_ATTRIBUTES for directory entries. Being able to
1668 * open a file implies FILE_LIST_DIRECTORY.
1671 set_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1673 ret
= gpfswrap_get_winattrs(fsp
->fh
->fd
, &attrs
);
1675 saved_errno
= errno
;
1678 drop_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1680 if (saved_errno
!= 0) {
1681 errno
= saved_errno
;
1686 DBG_WARNING("Getting winattrs failed for %s: %s\n",
1687 fsp
->fsp_name
->base_name
, strerror(errno
));
1688 return map_nt_error_from_unix(errno
);
1691 *dosmode
|= vfs_gpfs_winattrs_to_dosmode(attrs
.winAttrs
);
1692 fsp
->fsp_name
->st
.st_ex_calculated_birthtime
= false;
1693 fsp
->fsp_name
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1694 fsp
->fsp_name
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1696 return NT_STATUS_OK
;
1699 static NTSTATUS
vfs_gpfs_set_dos_attributes(struct vfs_handle_struct
*handle
,
1700 const struct smb_filename
*smb_fname
,
1703 struct gpfs_config_data
*config
;
1704 struct gpfs_winattr attrs
= { };
1707 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1708 struct gpfs_config_data
,
1709 return NT_STATUS_INTERNAL_ERROR
);
1711 if (!config
->winattr
) {
1712 return SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle
,
1713 smb_fname
, dosmode
);
1716 attrs
.winAttrs
= vfs_gpfs_dosmode_to_winattrs(dosmode
);
1717 ret
= gpfswrap_set_winattrs_path(smb_fname
->base_name
,
1718 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1720 if (ret
== -1 && errno
== ENOSYS
) {
1721 return SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle
,
1722 smb_fname
, dosmode
);
1726 DBG_WARNING("Setting winattrs failed for %s: %s\n",
1727 smb_fname
->base_name
, strerror(errno
));
1728 return map_nt_error_from_unix(errno
);
1731 return NT_STATUS_OK
;
1734 static NTSTATUS
vfs_gpfs_fset_dos_attributes(struct vfs_handle_struct
*handle
,
1735 struct files_struct
*fsp
,
1738 struct gpfs_config_data
*config
;
1739 struct gpfs_winattr attrs
= { };
1742 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1743 struct gpfs_config_data
,
1744 return NT_STATUS_INTERNAL_ERROR
);
1746 if (!config
->winattr
) {
1747 return SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle
, fsp
, dosmode
);
1750 attrs
.winAttrs
= vfs_gpfs_dosmode_to_winattrs(dosmode
);
1751 ret
= gpfswrap_set_winattrs(fsp
->fh
->fd
,
1752 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1754 if (ret
== -1 && errno
== ENOSYS
) {
1755 return SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle
, fsp
, dosmode
);
1759 DBG_WARNING("Setting winattrs failed for %s: %s\n",
1760 fsp
->fsp_name
->base_name
, strerror(errno
));
1761 return map_nt_error_from_unix(errno
);
1764 return NT_STATUS_OK
;
1767 static int stat_with_capability(struct vfs_handle_struct
*handle
,
1768 struct smb_filename
*smb_fname
, int flag
)
1770 #if defined(HAVE_FSTATAT)
1774 const char *rel_name
= NULL
;
1778 b
= parent_dirname(talloc_tos(), smb_fname
->base_name
,
1779 &dir_name
, &rel_name
);
1785 fd
= open(dir_name
, O_RDONLY
, 0);
1786 TALLOC_FREE(dir_name
);
1791 set_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1792 ret
= fstatat(fd
, rel_name
, &st
, flag
);
1793 drop_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1798 init_stat_ex_from_stat(
1799 &smb_fname
->st
, &st
,
1800 lp_fake_directory_create_times(SNUM(handle
->conn
)));
1809 static int vfs_gpfs_stat(struct vfs_handle_struct
*handle
,
1810 struct smb_filename
*smb_fname
)
1813 struct gpfs_config_data
*config
;
1815 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1816 struct gpfs_config_data
,
1819 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
1820 if (ret
== -1 && errno
== EACCES
) {
1821 DEBUG(10, ("Trying stat with capability for %s\n",
1822 smb_fname
->base_name
));
1823 ret
= stat_with_capability(handle
, smb_fname
, 0);
1828 static int vfs_gpfs_lstat(struct vfs_handle_struct
*handle
,
1829 struct smb_filename
*smb_fname
)
1832 struct gpfs_config_data
*config
;
1834 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1835 struct gpfs_config_data
,
1838 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
1839 if (ret
== -1 && errno
== EACCES
) {
1840 DEBUG(10, ("Trying lstat with capability for %s\n",
1841 smb_fname
->base_name
));
1842 ret
= stat_with_capability(handle
, smb_fname
,
1843 AT_SYMLINK_NOFOLLOW
);
1848 static void timespec_to_gpfs_time(struct timespec ts
, gpfs_timestruc_t
*gt
,
1849 int idx
, int *flags
)
1851 if (!null_timespec(ts
)) {
1853 gt
[idx
].tv_sec
= ts
.tv_sec
;
1854 gt
[idx
].tv_nsec
= ts
.tv_nsec
;
1855 DEBUG(10, ("Setting GPFS time %d, flags 0x%x\n", idx
, *flags
));
1859 static int smbd_gpfs_set_times_path(char *path
, struct smb_file_time
*ft
)
1861 gpfs_timestruc_t gpfs_times
[4];
1865 ZERO_ARRAY(gpfs_times
);
1866 timespec_to_gpfs_time(ft
->atime
, gpfs_times
, 0, &flags
);
1867 timespec_to_gpfs_time(ft
->mtime
, gpfs_times
, 1, &flags
);
1868 /* No good mapping from LastChangeTime to ctime, not storing */
1869 timespec_to_gpfs_time(ft
->create_time
, gpfs_times
, 3, &flags
);
1872 DEBUG(10, ("nothing to do, return to avoid EINVAL\n"));
1876 rc
= gpfswrap_set_times_path(path
, flags
, gpfs_times
);
1878 if (rc
!= 0 && errno
!= ENOSYS
) {
1879 DEBUG(1,("gpfs_set_times() returned with error %s\n",
1886 static int vfs_gpfs_ntimes(struct vfs_handle_struct
*handle
,
1887 const struct smb_filename
*smb_fname
,
1888 struct smb_file_time
*ft
)
1891 struct gpfs_winattr attrs
;
1893 struct gpfs_config_data
*config
;
1895 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1896 struct gpfs_config_data
,
1899 /* Try to use gpfs_set_times if it is enabled and available */
1900 if (config
->settimes
) {
1901 ret
= smbd_gpfs_set_times_path(smb_fname
->base_name
, ft
);
1903 if (ret
== 0 || (ret
== -1 && errno
!= ENOSYS
)) {
1908 DEBUG(10,("gpfs_set_times() not available or disabled, "
1909 "use ntimes and winattr\n"));
1911 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1913 /* don't complain if access was denied */
1914 if (errno
!= EPERM
&& errno
!= EACCES
) {
1915 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1916 "%s", strerror(errno
)));
1921 if(null_timespec(ft
->create_time
)){
1922 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1926 if (!config
->winattr
) {
1931 attrs
.creationTime
.tv_sec
= ft
->create_time
.tv_sec
;
1932 attrs
.creationTime
.tv_nsec
= ft
->create_time
.tv_nsec
;
1934 ret
= gpfswrap_set_winattrs_path(smb_fname
->base_name
,
1935 GPFS_WINATTR_SET_CREATION_TIME
,
1937 if(ret
== -1 && errno
!= ENOSYS
){
1938 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret
));
1945 static int vfs_gpfs_fallocate(struct vfs_handle_struct
*handle
,
1946 struct files_struct
*fsp
, uint32_t mode
,
1947 off_t offset
, off_t len
)
1949 if (mode
== (VFS_FALLOCATE_FL_PUNCH_HOLE
|VFS_FALLOCATE_FL_KEEP_SIZE
) &&
1951 lp_strict_allocate(SNUM(fsp
->conn
))) {
1953 * This is from a ZERO_DATA request on a non-sparse
1954 * file. GPFS does not support FL_KEEP_SIZE and thus
1955 * cannot fill the whole again in the subsequent
1956 * fallocate(FL_KEEP_SIZE). Deny this FL_PUNCH_HOLE
1957 * call to not end up with a hole in a non-sparse
1964 return SMB_VFS_NEXT_FALLOCATE(handle
, fsp
, mode
, offset
, len
);
1967 static int vfs_gpfs_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1971 struct gpfs_config_data
*config
;
1973 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1974 struct gpfs_config_data
,
1977 if (!config
->ftruncate
) {
1978 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1981 result
= gpfswrap_ftruncate(fsp
->fh
->fd
, len
);
1982 if ((result
== -1) && (errno
== ENOSYS
)) {
1983 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1988 static bool vfs_gpfs_is_offline(struct vfs_handle_struct
*handle
,
1989 const struct smb_filename
*fname
,
1990 SMB_STRUCT_STAT
*sbuf
)
1992 struct gpfs_winattr attrs
;
1993 struct gpfs_config_data
*config
;
1996 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1997 struct gpfs_config_data
,
2000 if (!config
->winattr
) {
2004 ret
= gpfswrap_get_winattrs_path(fname
->base_name
, &attrs
);
2009 if ((attrs
.winAttrs
& GPFS_WINATTR_OFFLINE
) != 0) {
2010 DBG_DEBUG("%s is offline\n", fname
->base_name
);
2014 DBG_DEBUG("%s is online\n", fname
->base_name
);
2018 static bool vfs_gpfs_fsp_is_offline(struct vfs_handle_struct
*handle
,
2019 struct files_struct
*fsp
)
2021 struct gpfs_fsp_extension
*ext
;
2023 ext
= VFS_FETCH_FSP_EXTENSION(handle
, fsp
);
2026 * Something bad happened, always ask.
2028 return vfs_gpfs_is_offline(handle
, fsp
->fsp_name
,
2029 &fsp
->fsp_name
->st
);
2034 * As long as it's offline, ask.
2036 ext
->offline
= vfs_gpfs_is_offline(handle
, fsp
->fsp_name
,
2037 &fsp
->fsp_name
->st
);
2040 return ext
->offline
;
2043 static bool vfs_gpfs_aio_force(struct vfs_handle_struct
*handle
,
2044 struct files_struct
*fsp
)
2046 return vfs_gpfs_fsp_is_offline(handle
, fsp
);
2049 static ssize_t
vfs_gpfs_sendfile(vfs_handle_struct
*handle
, int tofd
,
2050 files_struct
*fsp
, const DATA_BLOB
*hdr
,
2051 off_t offset
, size_t n
)
2053 if (vfs_gpfs_fsp_is_offline(handle
, fsp
)) {
2057 return SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fsp
, hdr
, offset
, n
);
2060 static int vfs_gpfs_connect(struct vfs_handle_struct
*handle
,
2061 const char *service
, const char *user
)
2063 struct gpfs_config_data
*config
;
2067 gpfswrap_lib_init(0);
2069 config
= talloc_zero(handle
->conn
, struct gpfs_config_data
);
2071 DEBUG(0, ("talloc_zero() failed\n"));
2076 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
2078 TALLOC_FREE(config
);
2082 check_fstype
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2083 "check_fstype", true);
2085 if (check_fstype
&& !IS_IPC(handle
->conn
)) {
2086 const char *connectpath
= handle
->conn
->connectpath
;
2087 struct statfs buf
= { 0 };
2089 ret
= statfs(connectpath
, &buf
);
2091 DBG_ERR("statfs failed for share %s at path %s: %s\n",
2092 service
, connectpath
, strerror(errno
));
2093 TALLOC_FREE(config
);
2097 if (buf
.f_type
!= GPFS_SUPER_MAGIC
) {
2098 DBG_ERR("SMB share %s, path %s not in GPFS file system."
2099 " statfs magic: 0x%jx\n",
2102 (uintmax_t)buf
.f_type
);
2104 TALLOC_FREE(config
);
2109 ret
= smbacl4_get_vfs_params(handle
->conn
, &config
->nfs4_params
);
2111 TALLOC_FREE(config
);
2115 config
->sharemodes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2116 "sharemodes", true);
2118 config
->leases
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2121 config
->hsm
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2124 config
->syncio
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2127 config
->winattr
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2130 config
->ftruncate
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2133 config
->getrealfilename
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2134 "getrealfilename", true);
2136 config
->dfreequota
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2137 "dfreequota", false);
2139 config
->acl
= lp_parm_bool(SNUM(handle
->conn
), "gpfs", "acl", true);
2141 config
->settimes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2143 config
->recalls
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2146 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
2147 NULL
, struct gpfs_config_data
,
2150 if (config
->leases
) {
2152 * GPFS lease code is based on kernel oplock code
2153 * so make sure it is turned on
2155 if (!lp_kernel_oplocks(SNUM(handle
->conn
))) {
2156 DEBUG(5, ("Enabling kernel oplocks for "
2157 "gpfs:leases to work\n"));
2158 lp_do_parameter(SNUM(handle
->conn
), "kernel oplocks",
2163 * as the kernel does not properly support Level II oplocks
2164 * and GPFS leases code is based on kernel infrastructure, we
2165 * need to turn off Level II oplocks if gpfs:leases is enabled
2167 if (lp_level2_oplocks(SNUM(handle
->conn
))) {
2168 DEBUG(5, ("gpfs:leases are enabled, disabling "
2169 "Level II oplocks\n"));
2170 lp_do_parameter(SNUM(handle
->conn
), "level2 oplocks",
2176 * Unless we have an async implementation of get_dos_attributes turn
2179 lp_do_parameter(SNUM(handle
->conn
), "smbd:async dosmode", "false");
2184 static int get_gpfs_quota(const char *pathname
, int type
, int id
,
2185 struct gpfs_quotaInfo
*qi
)
2189 ret
= gpfswrap_quotactl(discard_const_p(char, pathname
),
2190 GPFS_QCMD(Q_GETQUOTA
, type
), id
, qi
);
2193 if (errno
== GPFS_E_NO_QUOTA_INST
) {
2194 DEBUG(10, ("Quotas disabled on GPFS filesystem.\n"));
2195 } else if (errno
!= ENOSYS
) {
2196 DEBUG(0, ("Get quota failed, type %d, id, %d, "
2197 "errno %d.\n", type
, id
, errno
));
2203 DEBUG(10, ("quota type %d, id %d, blk u:%lld h:%lld s:%lld gt:%u\n",
2204 type
, id
, qi
->blockUsage
, qi
->blockHardLimit
,
2205 qi
->blockSoftLimit
, qi
->blockGraceTime
));
2210 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi
, time_t cur_time
,
2211 uint64_t *dfree
, uint64_t *dsize
)
2213 uint64_t usage
, limit
;
2216 * The quota reporting is done in units of 1024 byte blocks, but
2217 * sys_fsusage uses units of 512 byte blocks, adjust the block number
2218 * accordingly. Also filter possibly negative usage counts from gpfs.
2220 usage
= qi
.blockUsage
< 0 ? 0 : (uint64_t)qi
.blockUsage
* 2;
2221 limit
= (uint64_t)qi
.blockHardLimit
* 2;
2224 * When the grace time for the exceeded soft block quota has been
2225 * exceeded, the soft block quota becomes an additional hard limit.
2227 if (qi
.blockSoftLimit
&&
2228 qi
.blockGraceTime
&& cur_time
> qi
.blockGraceTime
) {
2229 /* report disk as full */
2231 *dsize
= MIN(*dsize
, usage
);
2234 if (!qi
.blockHardLimit
)
2237 if (usage
>= limit
) {
2238 /* report disk as full */
2240 *dsize
= MIN(*dsize
, usage
);
2243 /* limit has not been reached, determine "free space" */
2244 *dfree
= MIN(*dfree
, limit
- usage
);
2245 *dsize
= MIN(*dsize
, limit
);
2249 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct
*handle
,
2250 const struct smb_filename
*smb_fname
,
2255 struct security_unix_token
*utok
;
2256 struct gpfs_quotaInfo qi_user
= { 0 }, qi_group
= { 0 };
2257 struct gpfs_config_data
*config
;
2261 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct gpfs_config_data
,
2262 return (uint64_t)-1);
2263 if (!config
->dfreequota
) {
2264 return SMB_VFS_NEXT_DISK_FREE(handle
, smb_fname
,
2265 bsize
, dfree
, dsize
);
2268 err
= sys_fsusage(smb_fname
->base_name
, dfree
, dsize
);
2270 DEBUG (0, ("Could not get fs usage, errno %d\n", errno
));
2271 return SMB_VFS_NEXT_DISK_FREE(handle
, smb_fname
,
2272 bsize
, dfree
, dsize
);
2275 /* sys_fsusage returns units of 512 bytes */
2278 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
2279 (unsigned long long)*dfree
, (unsigned long long)*dsize
));
2281 utok
= handle
->conn
->session_info
->unix_token
;
2283 err
= get_gpfs_quota(smb_fname
->base_name
,
2284 GPFS_USRQUOTA
, utok
->uid
, &qi_user
);
2286 return SMB_VFS_NEXT_DISK_FREE(handle
, smb_fname
,
2287 bsize
, dfree
, dsize
);
2290 err
= get_gpfs_quota(smb_fname
->base_name
,
2291 GPFS_GRPQUOTA
, utok
->gid
, &qi_group
);
2293 return SMB_VFS_NEXT_DISK_FREE(handle
, smb_fname
,
2294 bsize
, dfree
, dsize
);
2297 cur_time
= time(NULL
);
2299 /* Adjust free space and size according to quota limits. */
2300 vfs_gpfs_disk_free_quota(qi_user
, cur_time
, dfree
, dsize
);
2301 vfs_gpfs_disk_free_quota(qi_group
, cur_time
, dfree
, dsize
);
2306 static int vfs_gpfs_get_quota(vfs_handle_struct
*handle
,
2307 const struct smb_filename
*smb_fname
,
2308 enum SMB_QUOTA_TYPE qtype
,
2314 * User/group quota are being used for disk-free
2315 * determination, which in this module is done directly
2316 * by the disk-free function. It's important that this
2317 * module does not return wrong quota values by mistake,
2318 * which would modify the correct values set by disk-free.
2319 * User/group quota are also being used for processing
2320 * NT_TRANSACT_GET_USER_QUOTA in smb1 protocol, which is
2321 * currently not supported by this module.
2323 case SMB_USER_QUOTA_TYPE
:
2324 case SMB_GROUP_QUOTA_TYPE
:
2328 return SMB_VFS_NEXT_GET_QUOTA(handle
, smb_fname
,
2333 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct
*handle
,
2334 enum timestamp_set_resolution
*p_ts_res
)
2336 struct gpfs_config_data
*config
;
2339 next
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
2341 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2342 struct gpfs_config_data
,
2346 next
|= FILE_SUPPORTS_REMOTE_STORAGE
;
2351 static int vfs_gpfs_open(struct vfs_handle_struct
*handle
,
2352 struct smb_filename
*smb_fname
, files_struct
*fsp
,
2353 int flags
, mode_t mode
)
2355 struct gpfs_config_data
*config
;
2357 struct gpfs_fsp_extension
*ext
;
2359 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2360 struct gpfs_config_data
,
2363 if (config
->hsm
&& !config
->recalls
&&
2364 vfs_gpfs_fsp_is_offline(handle
, fsp
)) {
2365 DEBUG(10, ("Refusing access to offline file %s\n",
2371 if (config
->syncio
) {
2375 ext
= VFS_ADD_FSP_EXTENSION(handle
, fsp
, struct gpfs_fsp_extension
,
2383 * Assume the file is offline until gpfs tells us it's online.
2385 *ext
= (struct gpfs_fsp_extension
) { .offline
= true };
2387 ret
= SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
2389 VFS_REMOVE_FSP_EXTENSION(handle
, fsp
);
2394 static ssize_t
vfs_gpfs_pread(vfs_handle_struct
*handle
, files_struct
*fsp
,
2395 void *data
, size_t n
, off_t offset
)
2400 was_offline
= vfs_gpfs_fsp_is_offline(handle
, fsp
);
2402 ret
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
2404 if ((ret
!= -1) && was_offline
) {
2405 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2406 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2407 fsp
->fsp_name
->base_name
);
2413 struct vfs_gpfs_pread_state
{
2414 struct files_struct
*fsp
;
2417 struct vfs_aio_state vfs_aio_state
;
2420 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
);
2422 static struct tevent_req
*vfs_gpfs_pread_send(struct vfs_handle_struct
*handle
,
2423 TALLOC_CTX
*mem_ctx
,
2424 struct tevent_context
*ev
,
2425 struct files_struct
*fsp
,
2426 void *data
, size_t n
,
2429 struct tevent_req
*req
, *subreq
;
2430 struct vfs_gpfs_pread_state
*state
;
2432 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pread_state
);
2436 state
->was_offline
= vfs_gpfs_fsp_is_offline(handle
, fsp
);
2438 subreq
= SMB_VFS_NEXT_PREAD_SEND(state
, ev
, handle
, fsp
, data
,
2440 if (tevent_req_nomem(subreq
, req
)) {
2441 return tevent_req_post(req
, ev
);
2443 tevent_req_set_callback(subreq
, vfs_gpfs_pread_done
, req
);
2447 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
)
2449 struct tevent_req
*req
= tevent_req_callback_data(
2450 subreq
, struct tevent_req
);
2451 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2452 req
, struct vfs_gpfs_pread_state
);
2454 state
->ret
= SMB_VFS_PREAD_RECV(subreq
, &state
->vfs_aio_state
);
2455 TALLOC_FREE(subreq
);
2456 tevent_req_done(req
);
2459 static ssize_t
vfs_gpfs_pread_recv(struct tevent_req
*req
,
2460 struct vfs_aio_state
*vfs_aio_state
)
2462 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2463 req
, struct vfs_gpfs_pread_state
);
2464 struct files_struct
*fsp
= state
->fsp
;
2466 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
2469 *vfs_aio_state
= state
->vfs_aio_state
;
2471 if ((state
->ret
!= -1) && state
->was_offline
) {
2472 DEBUG(10, ("sending notify\n"));
2473 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2474 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2475 fsp
->fsp_name
->base_name
);
2481 static ssize_t
vfs_gpfs_pwrite(vfs_handle_struct
*handle
, files_struct
*fsp
,
2482 const void *data
, size_t n
, off_t offset
)
2487 was_offline
= vfs_gpfs_fsp_is_offline(handle
, fsp
);
2489 ret
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
2491 if ((ret
!= -1) && was_offline
) {
2492 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2493 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2494 fsp
->fsp_name
->base_name
);
2500 struct vfs_gpfs_pwrite_state
{
2501 struct files_struct
*fsp
;
2504 struct vfs_aio_state vfs_aio_state
;
2507 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
);
2509 static struct tevent_req
*vfs_gpfs_pwrite_send(
2510 struct vfs_handle_struct
*handle
,
2511 TALLOC_CTX
*mem_ctx
,
2512 struct tevent_context
*ev
,
2513 struct files_struct
*fsp
,
2514 const void *data
, size_t n
,
2517 struct tevent_req
*req
, *subreq
;
2518 struct vfs_gpfs_pwrite_state
*state
;
2520 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pwrite_state
);
2524 state
->was_offline
= vfs_gpfs_fsp_is_offline(handle
, fsp
);
2526 subreq
= SMB_VFS_NEXT_PWRITE_SEND(state
, ev
, handle
, fsp
, data
,
2528 if (tevent_req_nomem(subreq
, req
)) {
2529 return tevent_req_post(req
, ev
);
2531 tevent_req_set_callback(subreq
, vfs_gpfs_pwrite_done
, req
);
2535 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
)
2537 struct tevent_req
*req
= tevent_req_callback_data(
2538 subreq
, struct tevent_req
);
2539 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2540 req
, struct vfs_gpfs_pwrite_state
);
2542 state
->ret
= SMB_VFS_PWRITE_RECV(subreq
, &state
->vfs_aio_state
);
2543 TALLOC_FREE(subreq
);
2544 tevent_req_done(req
);
2547 static ssize_t
vfs_gpfs_pwrite_recv(struct tevent_req
*req
,
2548 struct vfs_aio_state
*vfs_aio_state
)
2550 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2551 req
, struct vfs_gpfs_pwrite_state
);
2552 struct files_struct
*fsp
= state
->fsp
;
2554 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
2557 *vfs_aio_state
= state
->vfs_aio_state
;
2559 if ((state
->ret
!= -1) && state
->was_offline
) {
2560 DEBUG(10, ("sending notify\n"));
2561 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2562 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2563 fsp
->fsp_name
->base_name
);
2570 static struct vfs_fn_pointers vfs_gpfs_fns
= {
2571 .connect_fn
= vfs_gpfs_connect
,
2572 .disk_free_fn
= vfs_gpfs_disk_free
,
2573 .get_quota_fn
= vfs_gpfs_get_quota
,
2574 .fs_capabilities_fn
= vfs_gpfs_capabilities
,
2575 .kernel_flock_fn
= vfs_gpfs_kernel_flock
,
2576 .linux_setlease_fn
= vfs_gpfs_setlease
,
2577 .get_real_filename_fn
= vfs_gpfs_get_real_filename
,
2578 .get_dos_attributes_fn
= vfs_gpfs_get_dos_attributes
,
2579 .get_dos_attributes_send_fn
= vfs_not_implemented_get_dos_attributes_send
,
2580 .get_dos_attributes_recv_fn
= vfs_not_implemented_get_dos_attributes_recv
,
2581 .fget_dos_attributes_fn
= vfs_gpfs_fget_dos_attributes
,
2582 .set_dos_attributes_fn
= vfs_gpfs_set_dos_attributes
,
2583 .fset_dos_attributes_fn
= vfs_gpfs_fset_dos_attributes
,
2584 .fget_nt_acl_fn
= gpfsacl_fget_nt_acl
,
2585 .get_nt_acl_fn
= gpfsacl_get_nt_acl
,
2586 .fset_nt_acl_fn
= gpfsacl_fset_nt_acl
,
2587 .sys_acl_get_file_fn
= gpfsacl_sys_acl_get_file
,
2588 .sys_acl_get_fd_fn
= gpfsacl_sys_acl_get_fd
,
2589 .sys_acl_blob_get_file_fn
= gpfsacl_sys_acl_blob_get_file
,
2590 .sys_acl_blob_get_fd_fn
= gpfsacl_sys_acl_blob_get_fd
,
2591 .sys_acl_set_file_fn
= gpfsacl_sys_acl_set_file
,
2592 .sys_acl_set_fd_fn
= gpfsacl_sys_acl_set_fd
,
2593 .sys_acl_delete_def_file_fn
= gpfsacl_sys_acl_delete_def_file
,
2594 .chmod_fn
= vfs_gpfs_chmod
,
2595 .fchmod_fn
= vfs_gpfs_fchmod
,
2596 .close_fn
= vfs_gpfs_close
,
2597 .stat_fn
= vfs_gpfs_stat
,
2598 .lstat_fn
= vfs_gpfs_lstat
,
2599 .ntimes_fn
= vfs_gpfs_ntimes
,
2600 .aio_force_fn
= vfs_gpfs_aio_force
,
2601 .sendfile_fn
= vfs_gpfs_sendfile
,
2602 .fallocate_fn
= vfs_gpfs_fallocate
,
2603 .open_fn
= vfs_gpfs_open
,
2604 .pread_fn
= vfs_gpfs_pread
,
2605 .pread_send_fn
= vfs_gpfs_pread_send
,
2606 .pread_recv_fn
= vfs_gpfs_pread_recv
,
2607 .pwrite_fn
= vfs_gpfs_pwrite
,
2608 .pwrite_send_fn
= vfs_gpfs_pwrite_send
,
2609 .pwrite_recv_fn
= vfs_gpfs_pwrite_recv
,
2610 .ftruncate_fn
= vfs_gpfs_ftruncate
2614 NTSTATUS
vfs_gpfs_init(TALLOC_CTX
*ctx
)
2618 ret
= gpfswrap_init();
2620 DEBUG(1, ("Could not initialize GPFS library wrapper\n"));
2623 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "gpfs",