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
;
57 struct gpfs_fsp_extension
{
61 static inline unsigned int gpfs_acl_flags(gpfs_acl_t
*gacl
)
63 if (gacl
->acl_level
== GPFS_ACL_LEVEL_V4FLAGS
) {
64 return gacl
->v4Level1
.acl_flags
;
69 static inline gpfs_ace_v4_t
*gpfs_ace_ptr(gpfs_acl_t
*gacl
, unsigned int i
)
71 if (gacl
->acl_level
== GPFS_ACL_LEVEL_V4FLAGS
) {
72 return &gacl
->v4Level1
.ace_v4
[i
];
74 return &gacl
->ace_v4
[i
];
77 static bool set_gpfs_sharemode(files_struct
*fsp
, uint32_t access_mask
,
78 uint32_t share_access
)
80 unsigned int allow
= GPFS_SHARE_NONE
;
81 unsigned int deny
= GPFS_DENY_NONE
;
84 if ((fsp
== NULL
) || (fsp
->fh
== NULL
) || (fsp
->fh
->fd
< 0)) {
85 /* No real file, don't disturb */
89 allow
|= (access_mask
& (FILE_WRITE_DATA
|FILE_APPEND_DATA
)) ?
91 allow
|= (access_mask
& (FILE_READ_DATA
|FILE_EXECUTE
)) ?
94 if (allow
== GPFS_SHARE_NONE
) {
95 DEBUG(10, ("special case am=no_access:%x\n",access_mask
));
98 deny
|= (share_access
& FILE_SHARE_WRITE
) ?
100 deny
|= (share_access
& (FILE_SHARE_READ
)) ?
104 * GPFS_DENY_DELETE can only be set together with either
105 * GPFS_DENY_WRITE or GPFS_DENY_READ.
107 if (deny
& (GPFS_DENY_WRITE
|GPFS_DENY_READ
)) {
108 deny
|= (share_access
& (FILE_SHARE_DELETE
)) ?
109 0 : GPFS_DENY_DELETE
;
112 DEBUG(10, ("am=%x, allow=%d, sa=%x, deny=%d\n",
113 access_mask
, allow
, share_access
, deny
));
115 result
= gpfswrap_set_share(fsp
->fh
->fd
, allow
, deny
);
117 if (errno
== ENOSYS
) {
118 DEBUG(5, ("VFS module vfs_gpfs loaded, but gpfs "
119 "set_share function support not available. "
120 "Allowing access\n"));
123 DEBUG(10, ("gpfs_set_share failed: %s\n",
128 return (result
== 0);
131 static int vfs_gpfs_kernel_flock(vfs_handle_struct
*handle
, files_struct
*fsp
,
132 uint32_t share_mode
, uint32_t access_mask
)
135 struct gpfs_config_data
*config
;
138 START_PROFILE(syscall_kernel_flock
);
140 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
141 struct gpfs_config_data
,
144 if(!config
->sharemodes
) {
149 * A named stream fsp will have the basefile open in the fsp
150 * fd, so lacking a distinct fd for the stream we have to skip
151 * kernel_flock and set_gpfs_sharemode for stream.
153 if (is_ntfs_stream_smb_fname(fsp
->fsp_name
) &&
154 !is_ntfs_default_stream_smb_fname(fsp
->fsp_name
)) {
155 DEBUG(2,("%s: kernel_flock on stream\n", fsp_str_dbg(fsp
)));
159 kernel_flock(fsp
->fh
->fd
, share_mode
, access_mask
);
161 if (!set_gpfs_sharemode(fsp
, access_mask
, fsp
->share_access
)) {
165 END_PROFILE(syscall_kernel_flock
);
170 static int vfs_gpfs_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
173 struct gpfs_config_data
*config
;
175 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
176 struct gpfs_config_data
,
179 if (config
->sharemodes
&& (fsp
->fh
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
180 set_gpfs_sharemode(fsp
, 0, 0);
183 return SMB_VFS_NEXT_CLOSE(handle
, fsp
);
186 static int set_gpfs_lease(int fd
, int leasetype
)
188 int gpfs_type
= GPFS_LEASE_NONE
;
190 if (leasetype
== F_RDLCK
) {
191 gpfs_type
= GPFS_LEASE_READ
;
193 if (leasetype
== F_WRLCK
) {
194 gpfs_type
= GPFS_LEASE_WRITE
;
197 /* we unconditionally set CAP_LEASE, rather than looking for
198 -1/EACCES as there is a bug in some versions of
199 libgpfs_gpl.so which results in a leaked fd on /dev/ss0
200 each time we try this with the wrong capabilities set
202 linux_set_lease_capability();
203 return gpfswrap_set_lease(fd
, gpfs_type
);
206 static int vfs_gpfs_setlease(vfs_handle_struct
*handle
, files_struct
*fsp
,
209 struct gpfs_config_data
*config
;
212 START_PROFILE(syscall_linux_setlease
);
214 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
215 struct gpfs_config_data
,
218 if (linux_set_lease_sighandler(fsp
->fh
->fd
) == -1) {
223 if (config
->leases
) {
225 * Ensure the lease owner is root to allow
226 * correct delivery of lease-break signals.
229 ret
= set_gpfs_lease(fsp
->fh
->fd
,leasetype
);
234 END_PROFILE(syscall_linux_setlease
);
239 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct
*handle
,
246 char *full_path
= NULL
;
247 char *to_free
= NULL
;
248 char real_pathname
[PATH_MAX
+1], tmpbuf
[PATH_MAX
];
249 size_t full_path_len
;
252 struct gpfs_config_data
*config
;
254 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
255 struct gpfs_config_data
,
258 if (!config
->getrealfilename
) {
259 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
260 mem_ctx
, found_name
);
263 mangled
= mangle_is_mangled(name
, handle
->conn
->params
);
265 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
266 mem_ctx
, found_name
);
269 full_path_len
= full_path_tos(path
, name
, tmpbuf
, sizeof(tmpbuf
),
270 &full_path
, &to_free
);
271 if (full_path_len
== -1) {
276 buflen
= sizeof(real_pathname
) - 1;
278 result
= gpfswrap_get_realfilename_path(full_path
, real_pathname
,
281 TALLOC_FREE(to_free
);
283 if ((result
== -1) && (errno
== ENOSYS
)) {
284 return SMB_VFS_NEXT_GET_REAL_FILENAME(
285 handle
, path
, name
, mem_ctx
, found_name
);
289 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
295 * GPFS does not necessarily null-terminate the returned path
296 * but instead returns the buffer length in buflen.
299 if (buflen
< sizeof(real_pathname
)) {
300 real_pathname
[buflen
] = '\0';
302 real_pathname
[sizeof(real_pathname
)-1] = '\0';
305 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
306 path
, name
, real_pathname
));
308 name
= strrchr_m(real_pathname
, '/');
314 *found_name
= talloc_strdup(mem_ctx
, name
+1);
315 if (*found_name
== NULL
) {
323 static void sd2gpfs_control(uint16_t control
, struct gpfs_acl
*gacl
)
325 unsigned int gpfs_aclflags
= 0;
326 control
&= SEC_DESC_DACL_PROTECTED
| SEC_DESC_SACL_PROTECTED
|
327 SEC_DESC_DACL_AUTO_INHERITED
| SEC_DESC_SACL_AUTO_INHERITED
|
328 SEC_DESC_DACL_DEFAULTED
| SEC_DESC_SACL_DEFAULTED
|
329 SEC_DESC_DACL_PRESENT
| SEC_DESC_SACL_PRESENT
;
330 gpfs_aclflags
= control
<< 8;
331 if (!(control
& SEC_DESC_DACL_PRESENT
))
332 gpfs_aclflags
|= ACL4_FLAG_NULL_DACL
;
333 if (!(control
& SEC_DESC_SACL_PRESENT
))
334 gpfs_aclflags
|= ACL4_FLAG_NULL_SACL
;
335 gacl
->acl_level
= GPFS_ACL_LEVEL_V4FLAGS
;
336 gacl
->v4Level1
.acl_flags
= gpfs_aclflags
;
339 static uint16_t gpfs2sd_control(unsigned int gpfs_aclflags
)
341 uint16_t control
= gpfs_aclflags
>> 8;
342 control
&= SEC_DESC_DACL_PROTECTED
| SEC_DESC_SACL_PROTECTED
|
343 SEC_DESC_DACL_AUTO_INHERITED
| SEC_DESC_SACL_AUTO_INHERITED
|
344 SEC_DESC_DACL_DEFAULTED
| SEC_DESC_SACL_DEFAULTED
|
345 SEC_DESC_DACL_PRESENT
| SEC_DESC_SACL_PRESENT
;
346 control
|= SEC_DESC_SELF_RELATIVE
;
350 static void gpfs_dumpacl(int level
, struct gpfs_acl
*gacl
)
355 DEBUG(0, ("gpfs acl is NULL\n"));
359 DEBUG(level
, ("len: %d, level: %d, version: %d, nace: %d, "
361 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
362 gacl
->acl_nace
, gpfs_acl_flags(gacl
)));
364 for(i
=0; i
<gacl
->acl_nace
; i
++)
366 struct gpfs_ace_v4
*gace
= gpfs_ace_ptr(gacl
, i
);
367 DEBUG(level
, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, "
368 "iflags:0x%x, who:%u\n",
369 i
, gace
->aceType
, gace
->aceFlags
, gace
->aceMask
,
370 gace
->aceIFlags
, gace
->aceWho
));
374 static int gpfs_getacl_with_capability(const char *fname
, int flags
, void *buf
)
376 int ret
, saved_errno
;
378 set_effective_capability(DAC_OVERRIDE_CAPABILITY
);
380 ret
= gpfswrap_getacl(discard_const_p(char, fname
), flags
, buf
);
383 drop_effective_capability(DAC_OVERRIDE_CAPABILITY
);
390 * get the ACL from GPFS, allocated on the specified mem_ctx
391 * internally retries when initial buffer was too small
393 * caller needs to cast result to either
394 * raw = yes: struct gpfs_opaque_acl
395 * raw = no: struct gpfs_acl
398 static void *vfs_gpfs_getacl(TALLOC_CTX
*mem_ctx
,
401 const gpfs_aclType_t type
)
409 bool use_capability
= false;
413 aclbuf
= talloc_zero_size(mem_ctx
, size
);
414 if (aclbuf
== NULL
) {
420 struct gpfs_opaque_acl
*buf
= (struct gpfs_opaque_acl
*) aclbuf
;
421 buf
->acl_type
= type
;
422 flags
= GPFS_GETACL_NATIVE
;
423 len
= (unsigned int *) &(buf
->acl_buffer_len
);
424 struct_size
= sizeof(struct gpfs_opaque_acl
);
426 struct gpfs_acl
*buf
= (struct gpfs_acl
*) aclbuf
;
427 buf
->acl_type
= type
;
428 buf
->acl_level
= GPFS_ACL_LEVEL_V4FLAGS
;
429 flags
= GPFS_GETACL_STRUCT
;
430 len
= &(buf
->acl_len
);
431 /* reserve space for control flags in gpfs 3.5 and beyond */
432 struct_size
= sizeof(struct gpfs_acl
) + sizeof(unsigned int);
435 /* set the length of the buffer as input value */
438 if (use_capability
) {
439 ret
= gpfs_getacl_with_capability(fname
, flags
, aclbuf
);
441 ret
= gpfswrap_getacl(discard_const_p(char, fname
),
443 if ((ret
!= 0) && (errno
== EACCES
)) {
444 DBG_DEBUG("Retry with DAC capability for %s\n", fname
);
445 use_capability
= true;
446 ret
= gpfs_getacl_with_capability(fname
, flags
, aclbuf
);
450 if ((ret
!= 0) && (errno
== ENOSPC
)) {
452 * get the size needed to accommodate the complete buffer
454 * the value returned only applies to the ACL blob in the
455 * struct so make sure to also have headroom for the first
456 * struct members by adding room for the complete struct
457 * (might be a few bytes too much then)
459 size
= *len
+ struct_size
;
461 DEBUG(10, ("Increasing ACL buffer size to %zu\n", size
));
466 DEBUG(5, ("smbd_gpfs_getacl failed with %s\n",
475 /* Tries to get nfs4 acls and returns SMB ACL allocated.
476 * On failure returns 1 if it got non-NFSv4 ACL to prompt
477 * retry with POSIX ACL checks.
478 * On failure returns -1 if there is system (GPFS) error, check errno.
479 * Returns 0 on success
481 static int gpfs_get_nfs4_acl(TALLOC_CTX
*mem_ctx
, const char *fname
,
482 struct SMB4ACL_T
**ppacl
)
485 struct gpfs_acl
*gacl
= NULL
;
486 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname
));
489 gacl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(), fname
,
492 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
493 fname
, strerror(errno
)));
494 if (errno
== ENODATA
) {
496 * GPFS returns ENODATA for snapshot
497 * directories. Retry with POSIX ACLs check.
505 if (gacl
->acl_type
!= GPFS_ACL_TYPE_NFS4
) {
506 DEBUG(10, ("Got non-nfsv4 acl\n"));
507 /* Retry with POSIX ACLs check */
512 *ppacl
= smb_create_smb4acl(mem_ctx
);
514 if (gacl
->acl_level
== GPFS_ACL_LEVEL_V4FLAGS
) {
515 uint16_t control
= gpfs2sd_control(gpfs_acl_flags(gacl
));
516 smbacl4_set_controlflags(*ppacl
, control
);
519 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d, control: %x\n",
520 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
521 gacl
->acl_nace
, gpfs_acl_flags(gacl
)));
523 for (i
=0; i
<gacl
->acl_nace
; i
++) {
524 struct gpfs_ace_v4
*gace
= gpfs_ace_ptr(gacl
, i
);
525 SMB_ACE4PROP_T smbace
= { 0 };
526 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
527 "who: %d\n", gace
->aceType
, gace
->aceIFlags
,
528 gace
->aceFlags
, gace
->aceMask
, gace
->aceWho
));
530 if (gace
->aceIFlags
& ACE4_IFLAG_SPECIAL_ID
) {
531 smbace
.flags
|= SMB_ACE4_ID_SPECIAL
;
532 switch (gace
->aceWho
) {
533 case ACE4_SPECIAL_OWNER
:
534 smbace
.who
.special_id
= SMB_ACE4_WHO_OWNER
;
536 case ACE4_SPECIAL_GROUP
:
537 smbace
.who
.special_id
= SMB_ACE4_WHO_GROUP
;
539 case ACE4_SPECIAL_EVERYONE
:
540 smbace
.who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
543 DEBUG(8, ("invalid special gpfs id %d "
544 "ignored\n", gace
->aceWho
));
545 continue; /* don't add it */
548 if (gace
->aceFlags
& ACE4_FLAG_GROUP_ID
)
549 smbace
.who
.gid
= gace
->aceWho
;
551 smbace
.who
.uid
= gace
->aceWho
;
554 /* remove redundant deny entries */
555 if (i
> 0 && gace
->aceType
== SMB_ACE4_ACCESS_DENIED_ACE_TYPE
) {
556 struct gpfs_ace_v4
*prev
= gpfs_ace_ptr(gacl
, i
- 1);
557 if (prev
->aceType
== SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
&&
558 prev
->aceFlags
== gace
->aceFlags
&&
559 prev
->aceIFlags
== gace
->aceIFlags
&&
560 (gace
->aceMask
& prev
->aceMask
) == 0 &&
561 gace
->aceWho
== prev
->aceWho
) {
562 /* it's redundant - skip it */
567 smbace
.aceType
= gace
->aceType
;
568 smbace
.aceFlags
= gace
->aceFlags
;
569 smbace
.aceMask
= gace
->aceMask
;
570 smb_add_ace4(*ppacl
, &smbace
);
578 static NTSTATUS
gpfsacl_fget_nt_acl(vfs_handle_struct
*handle
,
579 files_struct
*fsp
, uint32_t security_info
,
581 struct security_descriptor
**ppdesc
)
583 struct SMB4ACL_T
*pacl
= NULL
;
585 struct gpfs_config_data
*config
;
586 TALLOC_CTX
*frame
= talloc_stackframe();
591 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
592 struct gpfs_config_data
,
593 return NT_STATUS_INTERNAL_ERROR
);
596 status
= SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
602 result
= gpfs_get_nfs4_acl(frame
, fsp
->fsp_name
->base_name
, &pacl
);
605 status
= smb_fget_nt_acl_nfs4(fsp
, &config
->nfs4_params
,
607 mem_ctx
, ppdesc
, pacl
);
613 DEBUG(10, ("retrying with posix acl...\n"));
614 status
= posix_fget_nt_acl(fsp
, security_info
,
622 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
623 return map_nt_error_from_unix(errno
);
626 static NTSTATUS
gpfsacl_get_nt_acl(vfs_handle_struct
*handle
,
627 const struct smb_filename
*smb_fname
,
628 uint32_t security_info
,
630 struct security_descriptor
**ppdesc
)
632 struct SMB4ACL_T
*pacl
= NULL
;
634 struct gpfs_config_data
*config
;
635 TALLOC_CTX
*frame
= talloc_stackframe();
640 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
641 struct gpfs_config_data
,
642 return NT_STATUS_INTERNAL_ERROR
);
645 status
= SMB_VFS_NEXT_GET_NT_ACL(handle
, smb_fname
,
652 result
= gpfs_get_nfs4_acl(frame
, smb_fname
->base_name
, &pacl
);
655 status
= smb_get_nt_acl_nfs4(handle
->conn
, smb_fname
,
656 &config
->nfs4_params
,
657 security_info
, mem_ctx
, ppdesc
,
664 DEBUG(10, ("retrying with posix acl...\n"));
665 status
= posix_get_nt_acl(handle
->conn
, smb_fname
,
666 security_info
, mem_ctx
, ppdesc
);
671 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
673 return map_nt_error_from_unix(errno
);
676 static struct gpfs_acl
*vfs_gpfs_smbacl2gpfsacl(TALLOC_CTX
*mem_ctx
,
678 struct SMB4ACL_T
*smbacl
,
681 struct gpfs_acl
*gacl
;
682 gpfs_aclLen_t gacl_len
;
683 struct SMB4ACE_T
*smbace
;
685 gacl_len
= offsetof(gpfs_acl_t
, ace_v4
) + sizeof(unsigned int)
686 + smb_get_naces(smbacl
) * sizeof(gpfs_ace_v4_t
);
688 gacl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, gacl_len
);
690 DEBUG(0, ("talloc failed\n"));
695 gacl
->acl_level
= GPFS_ACL_LEVEL_BASE
;
696 gacl
->acl_version
= GPFS_ACL_VERSION_NFS4
;
697 gacl
->acl_type
= GPFS_ACL_TYPE_NFS4
;
698 gacl
->acl_nace
= 0; /* change later... */
701 gacl
->acl_level
= GPFS_ACL_LEVEL_V4FLAGS
;
702 sd2gpfs_control(smbacl4_get_controlflags(smbacl
), gacl
);
705 for (smbace
=smb_first_ace4(smbacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
706 struct gpfs_ace_v4
*gace
= gpfs_ace_ptr(gacl
, gacl
->acl_nace
);
707 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
709 gace
->aceType
= aceprop
->aceType
;
710 gace
->aceFlags
= aceprop
->aceFlags
;
711 gace
->aceMask
= aceprop
->aceMask
;
714 * GPFS can't distinguish between WRITE and APPEND on
715 * files, so one being set without the other is an
716 * error. Sorry for the many ()'s :-)
719 if (!fsp
->is_directory
721 ((((gace
->aceMask
& ACE4_MASK_WRITE
) == 0)
722 && ((gace
->aceMask
& ACE4_MASK_APPEND
) != 0))
724 (((gace
->aceMask
& ACE4_MASK_WRITE
) != 0)
725 && ((gace
->aceMask
& ACE4_MASK_APPEND
) == 0)))
727 lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
728 "merge_writeappend", True
)) {
729 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
730 "WRITE^APPEND, setting WRITE|APPEND\n",
732 gace
->aceMask
|= ACE4_MASK_WRITE
|ACE4_MASK_APPEND
;
735 gace
->aceIFlags
= (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
) ? ACE4_IFLAG_SPECIAL_ID
: 0;
737 if (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
)
739 switch(aceprop
->who
.special_id
)
741 case SMB_ACE4_WHO_EVERYONE
:
742 gace
->aceWho
= ACE4_SPECIAL_EVERYONE
;
744 case SMB_ACE4_WHO_OWNER
:
745 gace
->aceWho
= ACE4_SPECIAL_OWNER
;
747 case SMB_ACE4_WHO_GROUP
:
748 gace
->aceWho
= ACE4_SPECIAL_GROUP
;
751 DEBUG(8, ("unsupported special_id %d\n", aceprop
->who
.special_id
));
752 continue; /* don't add it !!! */
755 /* just only for the type safety... */
756 if (aceprop
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)
757 gace
->aceWho
= aceprop
->who
.gid
;
759 gace
->aceWho
= aceprop
->who
.uid
;
764 gacl
->acl_len
= (char *)gpfs_ace_ptr(gacl
, gacl
->acl_nace
)
769 static bool gpfsacl_process_smbacl(vfs_handle_struct
*handle
,
771 struct SMB4ACL_T
*smbacl
)
774 struct gpfs_acl
*gacl
;
775 TALLOC_CTX
*mem_ctx
= talloc_tos();
777 gacl
= vfs_gpfs_smbacl2gpfsacl(mem_ctx
, fsp
, smbacl
, true);
778 if (gacl
== NULL
) { /* out of memory */
781 ret
= gpfswrap_putacl(fsp
->fsp_name
->base_name
,
782 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gacl
);
784 if ((ret
!= 0) && (errno
== EINVAL
)) {
785 DEBUG(10, ("Retry without nfs41 control flags\n"));
787 gacl
= vfs_gpfs_smbacl2gpfsacl(mem_ctx
, fsp
, smbacl
, false);
788 if (gacl
== NULL
) { /* out of memory */
791 ret
= gpfswrap_putacl(fsp
->fsp_name
->base_name
,
792 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
,
797 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno
)));
798 gpfs_dumpacl(8, gacl
);
802 DEBUG(10, ("gpfs_putacl succeeded\n"));
806 static NTSTATUS
gpfsacl_set_nt_acl_internal(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32_t security_info_sent
, const struct security_descriptor
*psd
)
808 struct gpfs_acl
*acl
;
809 NTSTATUS result
= NT_STATUS_ACCESS_DENIED
;
811 acl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(),
812 fsp
->fsp_name
->base_name
,
815 return map_nt_error_from_unix(errno
);
818 if (acl
->acl_version
== GPFS_ACL_VERSION_NFS4
) {
819 struct gpfs_config_data
*config
;
821 if (lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
822 "refuse_dacl_protected", false)
823 && (psd
->type
&SEC_DESC_DACL_PROTECTED
)) {
824 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
826 return NT_STATUS_NOT_SUPPORTED
;
829 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
830 struct gpfs_config_data
,
831 return NT_STATUS_INTERNAL_ERROR
);
833 result
= smb_set_nt_acl_nfs4(handle
,
834 fsp
, &config
->nfs4_params
, security_info_sent
, psd
,
835 gpfsacl_process_smbacl
);
836 } else { /* assume POSIX ACL - by default... */
837 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
844 static NTSTATUS
gpfsacl_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32_t security_info_sent
, const struct security_descriptor
*psd
)
846 struct gpfs_config_data
*config
;
848 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
849 struct gpfs_config_data
,
850 return NT_STATUS_INTERNAL_ERROR
);
853 return SMB_VFS_NEXT_FSET_NT_ACL(handle
, fsp
, security_info_sent
, psd
);
856 return gpfsacl_set_nt_acl_internal(handle
, fsp
, security_info_sent
, psd
);
859 static SMB_ACL_T
gpfs2smb_acl(const struct gpfs_acl
*pacl
, TALLOC_CTX
*mem_ctx
)
864 result
= sys_acl_init(mem_ctx
);
865 if (result
== NULL
) {
870 result
->count
= pacl
->acl_nace
;
871 result
->acl
= talloc_realloc(result
, result
->acl
, struct smb_acl_entry
,
873 if (result
->acl
== NULL
) {
879 for (i
=0; i
<pacl
->acl_nace
; i
++) {
880 struct smb_acl_entry
*ace
= &result
->acl
[i
];
881 const struct gpfs_ace_v1
*g_ace
= &pacl
->ace_v1
[i
];
883 DEBUG(10, ("Converting type %d id %lu perm %x\n",
884 (int)g_ace
->ace_type
, (unsigned long)g_ace
->ace_who
,
885 (int)g_ace
->ace_perm
));
887 switch (g_ace
->ace_type
) {
889 ace
->a_type
= SMB_ACL_USER
;
890 ace
->info
.user
.uid
= (uid_t
)g_ace
->ace_who
;
892 case GPFS_ACL_USER_OBJ
:
893 ace
->a_type
= SMB_ACL_USER_OBJ
;
896 ace
->a_type
= SMB_ACL_GROUP
;
897 ace
->info
.group
.gid
= (gid_t
)g_ace
->ace_who
;
899 case GPFS_ACL_GROUP_OBJ
:
900 ace
->a_type
= SMB_ACL_GROUP_OBJ
;
903 ace
->a_type
= SMB_ACL_OTHER
;
906 ace
->a_type
= SMB_ACL_MASK
;
909 DEBUG(10, ("Got invalid ace_type: %d\n",
917 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_READ
) ?
919 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_WRITE
) ?
921 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_EXECUTE
) ?
924 DEBUGADD(10, ("Converted to %d perm %x\n",
925 ace
->a_type
, ace
->a_perm
));
931 static SMB_ACL_T
gpfsacl_get_posix_acl(const char *path
, gpfs_aclType_t type
,
934 struct gpfs_acl
*pacl
;
935 SMB_ACL_T result
= NULL
;
937 pacl
= vfs_gpfs_getacl(talloc_tos(), path
, false, type
);
940 DEBUG(10, ("vfs_gpfs_getacl failed for %s with %s\n",
941 path
, strerror(errno
)));
948 if (pacl
->acl_version
!= GPFS_ACL_VERSION_POSIX
) {
949 DEBUG(10, ("Got acl version %d, expected %d\n",
950 pacl
->acl_version
, GPFS_ACL_VERSION_POSIX
));
955 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
956 pacl
->acl_len
, pacl
->acl_level
, pacl
->acl_version
,
959 result
= gpfs2smb_acl(pacl
, mem_ctx
);
960 if (result
!= NULL
) {
975 static SMB_ACL_T
gpfsacl_sys_acl_get_file(vfs_handle_struct
*handle
,
976 const struct smb_filename
*smb_fname
,
980 gpfs_aclType_t gpfs_type
;
981 struct gpfs_config_data
*config
;
983 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
984 struct gpfs_config_data
,
988 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle
, smb_fname
,
993 case SMB_ACL_TYPE_ACCESS
:
994 gpfs_type
= GPFS_ACL_TYPE_ACCESS
;
996 case SMB_ACL_TYPE_DEFAULT
:
997 gpfs_type
= GPFS_ACL_TYPE_DEFAULT
;
1000 DEBUG(0, ("Got invalid type: %d\n", type
));
1001 smb_panic("exiting");
1004 return gpfsacl_get_posix_acl(smb_fname
->base_name
, gpfs_type
, mem_ctx
);
1007 static SMB_ACL_T
gpfsacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
1009 TALLOC_CTX
*mem_ctx
)
1011 struct gpfs_config_data
*config
;
1013 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1014 struct gpfs_config_data
,
1018 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle
, fsp
, mem_ctx
);
1021 return gpfsacl_get_posix_acl(fsp
->fsp_name
->base_name
,
1022 GPFS_ACL_TYPE_ACCESS
, mem_ctx
);
1025 static int gpfsacl_sys_acl_blob_get_file(vfs_handle_struct
*handle
,
1026 const struct smb_filename
*smb_fname
,
1027 TALLOC_CTX
*mem_ctx
,
1028 char **blob_description
,
1031 struct gpfs_config_data
*config
;
1032 struct gpfs_opaque_acl
*acl
= NULL
;
1035 const char *path_p
= smb_fname
->base_name
;
1037 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1038 struct gpfs_config_data
,
1042 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle
, smb_fname
,
1049 acl
= (struct gpfs_opaque_acl
*)
1050 vfs_gpfs_getacl(mem_ctx
,
1053 GPFS_ACL_TYPE_NFS4
);
1056 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
1057 errno
, strerror(errno
)));
1059 /* EINVAL means POSIX ACL, bail out on other cases */
1060 if (errno
!= EINVAL
) {
1067 * file has NFSv4 ACL
1069 * we only need the actual ACL blob here
1070 * acl_version will always be NFS4 because we asked
1072 * acl_type is only used for POSIX ACLs
1074 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
1075 aclblob
.length
= acl
->acl_buffer_len
;
1077 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
1078 if (!*blob_description
) {
1084 result
= non_posix_sys_acl_blob_get_file_helper(handle
, smb_fname
,
1092 /* fall back to POSIX ACL */
1093 return posix_sys_acl_blob_get_file(handle
, smb_fname
, mem_ctx
,
1094 blob_description
, blob
);
1097 static int gpfsacl_sys_acl_blob_get_fd(vfs_handle_struct
*handle
,
1099 TALLOC_CTX
*mem_ctx
,
1100 char **blob_description
,
1103 struct gpfs_config_data
*config
;
1104 struct gpfs_opaque_acl
*acl
= NULL
;
1108 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1109 struct gpfs_config_data
,
1113 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle
, fsp
, mem_ctx
,
1114 blob_description
, blob
);
1118 acl
= (struct gpfs_opaque_acl
*) vfs_gpfs_getacl(mem_ctx
,
1119 fsp
->fsp_name
->base_name
,
1121 GPFS_ACL_TYPE_NFS4
);
1124 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
1125 errno
, strerror(errno
)));
1127 /* EINVAL means POSIX ACL, bail out on other cases */
1128 if (errno
!= EINVAL
) {
1135 * file has NFSv4 ACL
1137 * we only need the actual ACL blob here
1138 * acl_version will always be NFS4 because we asked
1140 * acl_type is only used for POSIX ACLs
1142 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
1143 aclblob
.length
= acl
->acl_buffer_len
;
1145 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
1146 if (!*blob_description
) {
1152 result
= non_posix_sys_acl_blob_get_fd_helper(handle
, fsp
,
1160 /* fall back to POSIX ACL */
1161 return posix_sys_acl_blob_get_fd(handle
, fsp
, mem_ctx
,
1162 blob_description
, blob
);
1165 static struct gpfs_acl
*smb2gpfs_acl(const SMB_ACL_T pacl
,
1166 SMB_ACL_TYPE_T type
)
1169 struct gpfs_acl
*result
;
1172 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl
->count
));
1174 len
= offsetof(gpfs_acl_t
, ace_v1
) + (pacl
->count
) *
1175 sizeof(gpfs_ace_v1_t
);
1177 result
= (struct gpfs_acl
*)SMB_MALLOC(len
);
1178 if (result
== NULL
) {
1183 result
->acl_len
= len
;
1184 result
->acl_level
= 0;
1185 result
->acl_version
= GPFS_ACL_VERSION_POSIX
;
1186 result
->acl_type
= (type
== SMB_ACL_TYPE_DEFAULT
) ?
1187 GPFS_ACL_TYPE_DEFAULT
: GPFS_ACL_TYPE_ACCESS
;
1188 result
->acl_nace
= pacl
->count
;
1190 for (i
=0; i
<pacl
->count
; i
++) {
1191 const struct smb_acl_entry
*ace
= &pacl
->acl
[i
];
1192 struct gpfs_ace_v1
*g_ace
= &result
->ace_v1
[i
];
1194 DEBUG(10, ("Converting type %d perm %x\n",
1195 (int)ace
->a_type
, (int)ace
->a_perm
));
1197 g_ace
->ace_perm
= 0;
1199 switch(ace
->a_type
) {
1201 g_ace
->ace_type
= GPFS_ACL_USER
;
1202 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.user
.uid
;
1204 case SMB_ACL_USER_OBJ
:
1205 g_ace
->ace_type
= GPFS_ACL_USER_OBJ
;
1206 g_ace
->ace_perm
|= ACL_PERM_CONTROL
;
1210 g_ace
->ace_type
= GPFS_ACL_GROUP
;
1211 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.group
.gid
;
1213 case SMB_ACL_GROUP_OBJ
:
1214 g_ace
->ace_type
= GPFS_ACL_GROUP_OBJ
;
1218 g_ace
->ace_type
= GPFS_ACL_MASK
;
1219 g_ace
->ace_perm
= 0x8f;
1223 g_ace
->ace_type
= GPFS_ACL_OTHER
;
1227 DEBUG(10, ("Got invalid ace_type: %d\n", ace
->a_type
));
1233 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_READ
) ?
1235 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_WRITE
) ?
1237 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_EXECUTE
) ?
1238 ACL_PERM_EXECUTE
: 0;
1240 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
1241 g_ace
->ace_type
, g_ace
->ace_who
, g_ace
->ace_perm
));
1247 static int gpfsacl_sys_acl_set_file(vfs_handle_struct
*handle
,
1248 const struct smb_filename
*smb_fname
,
1249 SMB_ACL_TYPE_T type
,
1252 struct gpfs_acl
*gpfs_acl
;
1254 struct gpfs_config_data
*config
;
1256 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1257 struct gpfs_config_data
,
1261 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle
, smb_fname
,
1265 gpfs_acl
= smb2gpfs_acl(theacl
, type
);
1266 if (gpfs_acl
== NULL
) {
1270 result
= gpfswrap_putacl(discard_const_p(char, smb_fname
->base_name
),
1271 GPFS_PUTACL_STRUCT
|GPFS_ACL_SAMBA
, gpfs_acl
);
1273 SAFE_FREE(gpfs_acl
);
1277 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
1281 struct gpfs_config_data
*config
;
1283 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1284 struct gpfs_config_data
,
1288 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle
, fsp
, theacl
);
1291 return gpfsacl_sys_acl_set_file(handle
, fsp
->fsp_name
,
1292 SMB_ACL_TYPE_ACCESS
, theacl
);
1295 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
1296 const struct smb_filename
*smb_fname
)
1298 struct gpfs_config_data
*config
;
1300 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1301 struct gpfs_config_data
,
1305 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle
, smb_fname
);
1313 * Assumed: mode bits are shiftable and standard
1314 * Output: the new aceMask field for an smb nfs4 ace
1316 static uint32_t gpfsacl_mask_filter(uint32_t aceType
, uint32_t aceMask
, uint32_t rwx
)
1318 const uint32_t posix_nfs4map
[3] = {
1319 SMB_ACE4_EXECUTE
, /* execute */
1320 SMB_ACE4_WRITE_DATA
| SMB_ACE4_APPEND_DATA
, /* write; GPFS specific */
1321 SMB_ACE4_READ_DATA
/* read */
1324 uint32_t posix_mask
= 0x01;
1328 for(i
=0; i
<3; i
++) {
1329 nfs4_bits
= posix_nfs4map
[i
];
1330 posix_bit
= rwx
& posix_mask
;
1332 if (aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
) {
1334 aceMask
|= nfs4_bits
;
1336 aceMask
&= ~nfs4_bits
;
1338 /* add deny bits when suitable */
1340 aceMask
|= nfs4_bits
;
1342 aceMask
&= ~nfs4_bits
;
1343 } /* other ace types are unexpected */
1351 static int gpfsacl_emu_chmod(vfs_handle_struct
*handle
,
1352 const char *path
, mode_t mode
)
1354 struct SMB4ACL_T
*pacl
= NULL
;
1356 bool haveAllowEntry
[SMB_ACE4_WHO_EVERYONE
+ 1] = {False
, False
, False
, False
};
1358 files_struct fake_fsp
= { 0 }; /* TODO: rationalize parametrization */
1359 struct SMB4ACE_T
*smbace
;
1360 TALLOC_CTX
*frame
= talloc_stackframe();
1362 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path
, mode
));
1364 result
= gpfs_get_nfs4_acl(frame
, path
, &pacl
);
1370 if (mode
& ~(S_IRWXU
| S_IRWXG
| S_IRWXO
)) {
1371 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode
, path
));
1374 for (smbace
=smb_first_ace4(pacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
1375 SMB_ACE4PROP_T
*ace
= smb_get_ace4(smbace
);
1376 uint32_t specid
= ace
->who
.special_id
;
1378 if (ace
->flags
&SMB_ACE4_ID_SPECIAL
&&
1379 ace
->aceType
<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE
&&
1380 specid
<= SMB_ACE4_WHO_EVERYONE
) {
1384 if (ace
->aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
)
1385 haveAllowEntry
[specid
] = True
;
1387 /* mode >> 6 for @owner, mode >> 3 for @group,
1388 * mode >> 0 for @everyone */
1389 newMask
= gpfsacl_mask_filter(ace
->aceType
, ace
->aceMask
,
1390 mode
>> ((SMB_ACE4_WHO_EVERYONE
- specid
) * 3));
1391 if (ace
->aceMask
!=newMask
) {
1392 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
1393 path
, ace
->aceMask
, newMask
, specid
));
1395 ace
->aceMask
= newMask
;
1399 /* make sure we have at least ALLOW entries
1400 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
1403 for(i
= SMB_ACE4_WHO_OWNER
; i
<=SMB_ACE4_WHO_EVERYONE
; i
++) {
1404 SMB_ACE4PROP_T ace
= { 0 };
1406 if (haveAllowEntry
[i
]==True
)
1409 ace
.aceType
= SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
;
1410 ace
.flags
|= SMB_ACE4_ID_SPECIAL
;
1411 ace
.who
.special_id
= i
;
1413 if (i
==SMB_ACE4_WHO_GROUP
) /* not sure it's necessary... */
1414 ace
.aceFlags
|= SMB_ACE4_IDENTIFIER_GROUP
;
1416 ace
.aceMask
= gpfsacl_mask_filter(ace
.aceType
, ace
.aceMask
,
1417 mode
>> ((SMB_ACE4_WHO_EVERYONE
- i
) * 3));
1419 /* don't add unnecessary aces */
1423 /* we add it to the END - as windows expects allow aces */
1424 smb_add_ace4(pacl
, &ace
);
1425 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1426 path
, mode
, i
, ace
.aceMask
));
1429 /* don't add complementary DENY ACEs here */
1430 fake_fsp
.fsp_name
= synthetic_smb_fname(
1431 frame
, path
, NULL
, NULL
, 0);
1432 if (fake_fsp
.fsp_name
== NULL
) {
1438 if (gpfsacl_process_smbacl(handle
, &fake_fsp
, pacl
) == False
) {
1444 return 0; /* ok for [f]chmod */
1447 static int vfs_gpfs_chmod(vfs_handle_struct
*handle
,
1448 const struct smb_filename
*smb_fname
,
1451 struct smb_filename
*smb_fname_cpath
;
1454 smb_fname_cpath
= cp_smb_filename(talloc_tos(), smb_fname
);
1455 if (smb_fname_cpath
== NULL
) {
1460 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_cpath
) != 0) {
1461 TALLOC_FREE(smb_fname_cpath
);
1465 /* avoid chmod() if possible, to preserve acls */
1466 if ((smb_fname_cpath
->st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1467 TALLOC_FREE(smb_fname_cpath
);
1471 rc
= gpfsacl_emu_chmod(handle
, smb_fname
->base_name
, mode
);
1473 return SMB_VFS_NEXT_CHMOD(handle
, smb_fname
, mode
);
1475 TALLOC_FREE(smb_fname_cpath
);
1479 static int vfs_gpfs_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
1484 if (SMB_VFS_NEXT_FSTAT(handle
, fsp
, &st
) != 0) {
1488 /* avoid chmod() if possible, to preserve acls */
1489 if ((st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1493 rc
= gpfsacl_emu_chmod(handle
, fsp
->fsp_name
->base_name
,
1496 return SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
1500 static uint32_t vfs_gpfs_winattrs_to_dosmode(unsigned int winattrs
)
1502 uint32_t dosmode
= 0;
1504 if (winattrs
& GPFS_WINATTR_ARCHIVE
){
1505 dosmode
|= FILE_ATTRIBUTE_ARCHIVE
;
1507 if (winattrs
& GPFS_WINATTR_HIDDEN
){
1508 dosmode
|= FILE_ATTRIBUTE_HIDDEN
;
1510 if (winattrs
& GPFS_WINATTR_SYSTEM
){
1511 dosmode
|= FILE_ATTRIBUTE_SYSTEM
;
1513 if (winattrs
& GPFS_WINATTR_READONLY
){
1514 dosmode
|= FILE_ATTRIBUTE_READONLY
;
1516 if (winattrs
& GPFS_WINATTR_SPARSE_FILE
) {
1517 dosmode
|= FILE_ATTRIBUTE_SPARSE
;
1519 if (winattrs
& GPFS_WINATTR_OFFLINE
) {
1520 dosmode
|= FILE_ATTRIBUTE_OFFLINE
;
1526 static unsigned int vfs_gpfs_dosmode_to_winattrs(uint32_t dosmode
)
1528 unsigned int winattrs
= 0;
1530 if (dosmode
& FILE_ATTRIBUTE_ARCHIVE
){
1531 winattrs
|= GPFS_WINATTR_ARCHIVE
;
1533 if (dosmode
& FILE_ATTRIBUTE_HIDDEN
){
1534 winattrs
|= GPFS_WINATTR_HIDDEN
;
1536 if (dosmode
& FILE_ATTRIBUTE_SYSTEM
){
1537 winattrs
|= GPFS_WINATTR_SYSTEM
;
1539 if (dosmode
& FILE_ATTRIBUTE_READONLY
){
1540 winattrs
|= GPFS_WINATTR_READONLY
;
1542 if (dosmode
& FILE_ATTRIBUTE_SPARSE
) {
1543 winattrs
|= GPFS_WINATTR_SPARSE_FILE
;
1545 if (dosmode
& FILE_ATTRIBUTE_OFFLINE
) {
1546 winattrs
|= GPFS_WINATTR_OFFLINE
;
1552 static int get_dos_attr_with_capability(struct smb_filename
*smb_fname
,
1553 struct gpfs_winattr
*attr
)
1555 int saved_errno
= 0;
1559 * According to MS-FSA 2.1.5.1.2.1 "Algorithm to Check Access to an
1560 * Existing File" FILE_LIST_DIRECTORY on a directory implies
1561 * FILE_READ_ATTRIBUTES for directory entries. Being able to stat() a
1562 * file implies FILE_LIST_DIRECTORY for the directory containing the
1566 if (!VALID_STAT(smb_fname
->st
)) {
1568 * Safety net: dos_mode() already checks this, but as we set
1569 * DAC_OVERRIDE_CAPABILITY based on this, add an additional
1572 DBG_ERR("Rejecting DAC override, invalid stat [%s]\n",
1573 smb_fname_str_dbg(smb_fname
));
1578 set_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1580 ret
= gpfswrap_get_winattrs_path(smb_fname
->base_name
, attr
);
1582 saved_errno
= errno
;
1585 drop_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1587 if (saved_errno
!= 0) {
1588 errno
= saved_errno
;
1593 static NTSTATUS
vfs_gpfs_get_dos_attributes(struct vfs_handle_struct
*handle
,
1594 struct smb_filename
*smb_fname
,
1597 struct gpfs_config_data
*config
;
1598 struct gpfs_winattr attrs
= { };
1601 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1602 struct gpfs_config_data
,
1603 return NT_STATUS_INTERNAL_ERROR
);
1605 if (!config
->winattr
) {
1606 return SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle
,
1607 smb_fname
, dosmode
);
1610 ret
= gpfswrap_get_winattrs_path(smb_fname
->base_name
, &attrs
);
1611 if (ret
== -1 && errno
== ENOSYS
) {
1612 return SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle
, smb_fname
,
1615 if (ret
== -1 && errno
== EACCES
) {
1616 ret
= get_dos_attr_with_capability(smb_fname
, &attrs
);
1619 if (ret
== -1 && errno
== EBADF
) {
1621 * Returned for directory listings in gpfs root for
1622 * .. entry which steps out of gpfs.
1624 DBG_DEBUG("Getting winattrs for %s returned EBADF.\n",
1625 smb_fname
->base_name
);
1626 return map_nt_error_from_unix(errno
);
1627 } else if (ret
== -1) {
1628 DBG_WARNING("Getting winattrs failed for %s: %s\n",
1629 smb_fname
->base_name
, strerror(errno
));
1630 return map_nt_error_from_unix(errno
);
1633 *dosmode
|= vfs_gpfs_winattrs_to_dosmode(attrs
.winAttrs
);
1634 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1635 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1636 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1638 return NT_STATUS_OK
;
1641 static NTSTATUS
vfs_gpfs_fget_dos_attributes(struct vfs_handle_struct
*handle
,
1642 struct files_struct
*fsp
,
1645 struct gpfs_config_data
*config
;
1646 struct gpfs_winattr attrs
= { };
1649 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1650 struct gpfs_config_data
,
1651 return NT_STATUS_INTERNAL_ERROR
);
1653 if (!config
->winattr
) {
1654 return SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle
, fsp
, dosmode
);
1657 ret
= gpfswrap_get_winattrs(fsp
->fh
->fd
, &attrs
);
1658 if (ret
== -1 && errno
== ENOSYS
) {
1659 return SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle
, fsp
, dosmode
);
1662 if (ret
== -1 && errno
== EACCES
) {
1663 int saved_errno
= 0;
1666 * According to MS-FSA 2.1.5.1.2.1 "Algorithm to Check Access to
1667 * an Existing File" FILE_LIST_DIRECTORY on a directory implies
1668 * FILE_READ_ATTRIBUTES for directory entries. Being able to
1669 * open a file implies FILE_LIST_DIRECTORY.
1672 set_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1674 ret
= gpfswrap_get_winattrs(fsp
->fh
->fd
, &attrs
);
1676 saved_errno
= errno
;
1679 drop_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1681 if (saved_errno
!= 0) {
1682 errno
= saved_errno
;
1687 DBG_WARNING("Getting winattrs failed for %s: %s\n",
1688 fsp
->fsp_name
->base_name
, strerror(errno
));
1689 return map_nt_error_from_unix(errno
);
1692 *dosmode
|= vfs_gpfs_winattrs_to_dosmode(attrs
.winAttrs
);
1693 fsp
->fsp_name
->st
.st_ex_calculated_birthtime
= false;
1694 fsp
->fsp_name
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1695 fsp
->fsp_name
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1697 return NT_STATUS_OK
;
1700 static NTSTATUS
vfs_gpfs_set_dos_attributes(struct vfs_handle_struct
*handle
,
1701 const struct smb_filename
*smb_fname
,
1704 struct gpfs_config_data
*config
;
1705 struct gpfs_winattr attrs
= { };
1708 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1709 struct gpfs_config_data
,
1710 return NT_STATUS_INTERNAL_ERROR
);
1712 if (!config
->winattr
) {
1713 return SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle
,
1714 smb_fname
, dosmode
);
1717 attrs
.winAttrs
= vfs_gpfs_dosmode_to_winattrs(dosmode
);
1718 ret
= gpfswrap_set_winattrs_path(smb_fname
->base_name
,
1719 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1721 if (ret
== -1 && errno
== ENOSYS
) {
1722 return SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle
,
1723 smb_fname
, dosmode
);
1727 DBG_WARNING("Setting winattrs failed for %s: %s\n",
1728 smb_fname
->base_name
, strerror(errno
));
1729 return map_nt_error_from_unix(errno
);
1732 return NT_STATUS_OK
;
1735 static NTSTATUS
vfs_gpfs_fset_dos_attributes(struct vfs_handle_struct
*handle
,
1736 struct files_struct
*fsp
,
1739 struct gpfs_config_data
*config
;
1740 struct gpfs_winattr attrs
= { };
1743 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1744 struct gpfs_config_data
,
1745 return NT_STATUS_INTERNAL_ERROR
);
1747 if (!config
->winattr
) {
1748 return SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle
, fsp
, dosmode
);
1751 attrs
.winAttrs
= vfs_gpfs_dosmode_to_winattrs(dosmode
);
1752 ret
= gpfswrap_set_winattrs(fsp
->fh
->fd
,
1753 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1755 if (ret
== -1 && errno
== ENOSYS
) {
1756 return SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle
, fsp
, dosmode
);
1760 DBG_WARNING("Setting winattrs failed for %s: %s\n",
1761 fsp
->fsp_name
->base_name
, strerror(errno
));
1762 return map_nt_error_from_unix(errno
);
1765 return NT_STATUS_OK
;
1768 static int stat_with_capability(struct vfs_handle_struct
*handle
,
1769 struct smb_filename
*smb_fname
, int flag
)
1771 #if defined(HAVE_FSTATAT)
1775 const char *rel_name
= NULL
;
1779 b
= parent_dirname(talloc_tos(), smb_fname
->base_name
,
1780 &dir_name
, &rel_name
);
1786 fd
= open(dir_name
, O_RDONLY
, 0);
1787 TALLOC_FREE(dir_name
);
1792 set_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1793 ret
= fstatat(fd
, rel_name
, &st
, flag
);
1794 drop_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1799 init_stat_ex_from_stat(
1800 &smb_fname
->st
, &st
,
1801 lp_fake_directory_create_times(SNUM(handle
->conn
)));
1810 static int vfs_gpfs_stat(struct vfs_handle_struct
*handle
,
1811 struct smb_filename
*smb_fname
)
1814 struct gpfs_config_data
*config
;
1816 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1817 struct gpfs_config_data
,
1820 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
1821 if (ret
== -1 && errno
== EACCES
) {
1822 DEBUG(10, ("Trying stat with capability for %s\n",
1823 smb_fname
->base_name
));
1824 ret
= stat_with_capability(handle
, smb_fname
, 0);
1829 static int vfs_gpfs_lstat(struct vfs_handle_struct
*handle
,
1830 struct smb_filename
*smb_fname
)
1833 struct gpfs_config_data
*config
;
1835 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1836 struct gpfs_config_data
,
1839 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
1840 if (ret
== -1 && errno
== EACCES
) {
1841 DEBUG(10, ("Trying lstat with capability for %s\n",
1842 smb_fname
->base_name
));
1843 ret
= stat_with_capability(handle
, smb_fname
,
1844 AT_SYMLINK_NOFOLLOW
);
1849 static void timespec_to_gpfs_time(struct timespec ts
, gpfs_timestruc_t
*gt
,
1850 int idx
, int *flags
)
1852 if (!null_timespec(ts
)) {
1854 gt
[idx
].tv_sec
= ts
.tv_sec
;
1855 gt
[idx
].tv_nsec
= ts
.tv_nsec
;
1856 DEBUG(10, ("Setting GPFS time %d, flags 0x%x\n", idx
, *flags
));
1860 static int smbd_gpfs_set_times_path(char *path
, struct smb_file_time
*ft
)
1862 gpfs_timestruc_t gpfs_times
[4];
1866 ZERO_ARRAY(gpfs_times
);
1867 timespec_to_gpfs_time(ft
->atime
, gpfs_times
, 0, &flags
);
1868 timespec_to_gpfs_time(ft
->mtime
, gpfs_times
, 1, &flags
);
1869 /* No good mapping from LastChangeTime to ctime, not storing */
1870 timespec_to_gpfs_time(ft
->create_time
, gpfs_times
, 3, &flags
);
1873 DEBUG(10, ("nothing to do, return to avoid EINVAL\n"));
1877 rc
= gpfswrap_set_times_path(path
, flags
, gpfs_times
);
1879 if (rc
!= 0 && errno
!= ENOSYS
) {
1880 DEBUG(1,("gpfs_set_times() returned with error %s\n",
1887 static int vfs_gpfs_ntimes(struct vfs_handle_struct
*handle
,
1888 const struct smb_filename
*smb_fname
,
1889 struct smb_file_time
*ft
)
1892 struct gpfs_winattr attrs
;
1894 struct gpfs_config_data
*config
;
1896 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1897 struct gpfs_config_data
,
1900 /* Try to use gpfs_set_times if it is enabled and available */
1901 if (config
->settimes
) {
1902 ret
= smbd_gpfs_set_times_path(smb_fname
->base_name
, ft
);
1904 if (ret
== 0 || (ret
== -1 && errno
!= ENOSYS
)) {
1909 DEBUG(10,("gpfs_set_times() not available or disabled, "
1910 "use ntimes and winattr\n"));
1912 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1914 /* don't complain if access was denied */
1915 if (errno
!= EPERM
&& errno
!= EACCES
) {
1916 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1917 "%s", strerror(errno
)));
1922 if(null_timespec(ft
->create_time
)){
1923 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1927 if (!config
->winattr
) {
1932 attrs
.creationTime
.tv_sec
= ft
->create_time
.tv_sec
;
1933 attrs
.creationTime
.tv_nsec
= ft
->create_time
.tv_nsec
;
1935 ret
= gpfswrap_set_winattrs_path(smb_fname
->base_name
,
1936 GPFS_WINATTR_SET_CREATION_TIME
,
1938 if(ret
== -1 && errno
!= ENOSYS
){
1939 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret
));
1946 static int vfs_gpfs_fallocate(struct vfs_handle_struct
*handle
,
1947 struct files_struct
*fsp
, uint32_t mode
,
1948 off_t offset
, off_t len
)
1951 struct gpfs_config_data
*config
;
1953 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1954 struct gpfs_config_data
,
1957 if (!config
->prealloc
) {
1958 /* you should better not run fallocate() on GPFS at all */
1964 DEBUG(10, ("unmapped fallocate flags: %lx\n",
1965 (unsigned long)mode
));
1970 ret
= gpfswrap_prealloc(fsp
->fh
->fd
, offset
, len
);
1972 if (ret
== -1 && errno
!= ENOSYS
) {
1973 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno
)));
1974 } else if (ret
== -1 && errno
== ENOSYS
) {
1975 DEBUG(10, ("GPFS prealloc not supported.\n"));
1977 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1983 static int vfs_gpfs_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1987 struct gpfs_config_data
*config
;
1989 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1990 struct gpfs_config_data
,
1993 if (!config
->ftruncate
) {
1994 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1997 result
= gpfswrap_ftruncate(fsp
->fh
->fd
, len
);
1998 if ((result
== -1) && (errno
== ENOSYS
)) {
1999 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
2004 static bool vfs_gpfs_is_offline(struct vfs_handle_struct
*handle
,
2005 const struct smb_filename
*fname
,
2006 SMB_STRUCT_STAT
*sbuf
)
2008 struct gpfs_winattr attrs
;
2009 struct gpfs_config_data
*config
;
2012 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2013 struct gpfs_config_data
,
2016 if (!config
->winattr
) {
2020 ret
= gpfswrap_get_winattrs_path(fname
->base_name
, &attrs
);
2025 if ((attrs
.winAttrs
& GPFS_WINATTR_OFFLINE
) != 0) {
2026 DBG_DEBUG("%s is offline\n", fname
->base_name
);
2030 DBG_DEBUG("%s is online\n", fname
->base_name
);
2034 static bool vfs_gpfs_fsp_is_offline(struct vfs_handle_struct
*handle
,
2035 struct files_struct
*fsp
)
2037 struct gpfs_fsp_extension
*ext
;
2039 ext
= VFS_FETCH_FSP_EXTENSION(handle
, fsp
);
2042 * Something bad happened, always ask.
2044 return vfs_gpfs_is_offline(handle
, fsp
->fsp_name
,
2045 &fsp
->fsp_name
->st
);
2050 * As long as it's offline, ask.
2052 ext
->offline
= vfs_gpfs_is_offline(handle
, fsp
->fsp_name
,
2053 &fsp
->fsp_name
->st
);
2056 return ext
->offline
;
2059 static bool vfs_gpfs_aio_force(struct vfs_handle_struct
*handle
,
2060 struct files_struct
*fsp
)
2062 return vfs_gpfs_fsp_is_offline(handle
, fsp
);
2065 static ssize_t
vfs_gpfs_sendfile(vfs_handle_struct
*handle
, int tofd
,
2066 files_struct
*fsp
, const DATA_BLOB
*hdr
,
2067 off_t offset
, size_t n
)
2069 if (vfs_gpfs_fsp_is_offline(handle
, fsp
)) {
2073 return SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fsp
, hdr
, offset
, n
);
2076 static int vfs_gpfs_connect(struct vfs_handle_struct
*handle
,
2077 const char *service
, const char *user
)
2079 struct gpfs_config_data
*config
;
2083 gpfswrap_lib_init(0);
2085 config
= talloc_zero(handle
->conn
, struct gpfs_config_data
);
2087 DEBUG(0, ("talloc_zero() failed\n"));
2092 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
2094 TALLOC_FREE(config
);
2098 check_fstype
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2099 "check_fstype", true);
2101 if (check_fstype
&& !IS_IPC(handle
->conn
)) {
2102 const char *connectpath
= handle
->conn
->connectpath
;
2103 struct statfs buf
= { 0 };
2105 ret
= statfs(connectpath
, &buf
);
2107 DBG_ERR("statfs failed for share %s at path %s: %s\n",
2108 service
, connectpath
, strerror(errno
));
2109 TALLOC_FREE(config
);
2113 if (buf
.f_type
!= GPFS_SUPER_MAGIC
) {
2114 DBG_ERR("SMB share %s, path %s not in GPFS file system."
2115 " statfs magic: 0x%lx\n",
2116 service
, connectpath
, buf
.f_type
);
2118 TALLOC_FREE(config
);
2123 ret
= smbacl4_get_vfs_params(handle
->conn
, &config
->nfs4_params
);
2125 TALLOC_FREE(config
);
2129 config
->sharemodes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2130 "sharemodes", true);
2132 config
->leases
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2135 config
->hsm
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2138 config
->syncio
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2141 config
->winattr
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2144 config
->ftruncate
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2147 config
->getrealfilename
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2148 "getrealfilename", true);
2150 config
->dfreequota
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2151 "dfreequota", false);
2153 config
->prealloc
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2156 config
->acl
= lp_parm_bool(SNUM(handle
->conn
), "gpfs", "acl", true);
2158 config
->settimes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2160 config
->recalls
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2163 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
2164 NULL
, struct gpfs_config_data
,
2167 if (config
->leases
) {
2169 * GPFS lease code is based on kernel oplock code
2170 * so make sure it is turned on
2172 if (!lp_kernel_oplocks(SNUM(handle
->conn
))) {
2173 DEBUG(5, ("Enabling kernel oplocks for "
2174 "gpfs:leases to work\n"));
2175 lp_do_parameter(SNUM(handle
->conn
), "kernel oplocks",
2180 * as the kernel does not properly support Level II oplocks
2181 * and GPFS leases code is based on kernel infrastructure, we
2182 * need to turn off Level II oplocks if gpfs:leases is enabled
2184 if (lp_level2_oplocks(SNUM(handle
->conn
))) {
2185 DEBUG(5, ("gpfs:leases are enabled, disabling "
2186 "Level II oplocks\n"));
2187 lp_do_parameter(SNUM(handle
->conn
), "level2 oplocks",
2193 * Unless we have an async implementation of get_dos_attributes turn
2196 lp_do_parameter(SNUM(handle
->conn
), "smbd:async dosmode", "false");
2201 static int get_gpfs_quota(const char *pathname
, int type
, int id
,
2202 struct gpfs_quotaInfo
*qi
)
2206 ret
= gpfswrap_quotactl(discard_const_p(char, pathname
),
2207 GPFS_QCMD(Q_GETQUOTA
, type
), id
, qi
);
2210 if (errno
== GPFS_E_NO_QUOTA_INST
) {
2211 DEBUG(10, ("Quotas disabled on GPFS filesystem.\n"));
2212 } else if (errno
!= ENOSYS
) {
2213 DEBUG(0, ("Get quota failed, type %d, id, %d, "
2214 "errno %d.\n", type
, id
, errno
));
2220 DEBUG(10, ("quota type %d, id %d, blk u:%lld h:%lld s:%lld gt:%u\n",
2221 type
, id
, qi
->blockUsage
, qi
->blockHardLimit
,
2222 qi
->blockSoftLimit
, qi
->blockGraceTime
));
2227 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi
, time_t cur_time
,
2228 uint64_t *dfree
, uint64_t *dsize
)
2230 uint64_t usage
, limit
;
2233 * The quota reporting is done in units of 1024 byte blocks, but
2234 * sys_fsusage uses units of 512 byte blocks, adjust the block number
2235 * accordingly. Also filter possibly negative usage counts from gpfs.
2237 usage
= qi
.blockUsage
< 0 ? 0 : (uint64_t)qi
.blockUsage
* 2;
2238 limit
= (uint64_t)qi
.blockHardLimit
* 2;
2241 * When the grace time for the exceeded soft block quota has been
2242 * exceeded, the soft block quota becomes an additional hard limit.
2244 if (qi
.blockSoftLimit
&&
2245 qi
.blockGraceTime
&& cur_time
> qi
.blockGraceTime
) {
2246 /* report disk as full */
2248 *dsize
= MIN(*dsize
, usage
);
2251 if (!qi
.blockHardLimit
)
2254 if (usage
>= limit
) {
2255 /* report disk as full */
2257 *dsize
= MIN(*dsize
, usage
);
2260 /* limit has not been reached, determine "free space" */
2261 *dfree
= MIN(*dfree
, limit
- usage
);
2262 *dsize
= MIN(*dsize
, limit
);
2266 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct
*handle
,
2267 const struct smb_filename
*smb_fname
,
2272 struct security_unix_token
*utok
;
2273 struct gpfs_quotaInfo qi_user
= { 0 }, qi_group
= { 0 };
2274 struct gpfs_config_data
*config
;
2278 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct gpfs_config_data
,
2279 return (uint64_t)-1);
2280 if (!config
->dfreequota
) {
2281 return SMB_VFS_NEXT_DISK_FREE(handle
, smb_fname
,
2282 bsize
, dfree
, dsize
);
2285 err
= sys_fsusage(smb_fname
->base_name
, dfree
, dsize
);
2287 DEBUG (0, ("Could not get fs usage, errno %d\n", errno
));
2288 return SMB_VFS_NEXT_DISK_FREE(handle
, smb_fname
,
2289 bsize
, dfree
, dsize
);
2292 /* sys_fsusage returns units of 512 bytes */
2295 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
2296 (unsigned long long)*dfree
, (unsigned long long)*dsize
));
2298 utok
= handle
->conn
->session_info
->unix_token
;
2300 err
= get_gpfs_quota(smb_fname
->base_name
,
2301 GPFS_USRQUOTA
, utok
->uid
, &qi_user
);
2303 return SMB_VFS_NEXT_DISK_FREE(handle
, smb_fname
,
2304 bsize
, dfree
, dsize
);
2307 err
= get_gpfs_quota(smb_fname
->base_name
,
2308 GPFS_GRPQUOTA
, utok
->gid
, &qi_group
);
2310 return SMB_VFS_NEXT_DISK_FREE(handle
, smb_fname
,
2311 bsize
, dfree
, dsize
);
2314 cur_time
= time(NULL
);
2316 /* Adjust free space and size according to quota limits. */
2317 vfs_gpfs_disk_free_quota(qi_user
, cur_time
, dfree
, dsize
);
2318 vfs_gpfs_disk_free_quota(qi_group
, cur_time
, dfree
, dsize
);
2323 static int vfs_gpfs_get_quota(vfs_handle_struct
*handle
,
2324 const struct smb_filename
*smb_fname
,
2325 enum SMB_QUOTA_TYPE qtype
,
2331 * User/group quota are being used for disk-free
2332 * determination, which in this module is done directly
2333 * by the disk-free function. It's important that this
2334 * module does not return wrong quota values by mistake,
2335 * which would modify the correct values set by disk-free.
2336 * User/group quota are also being used for processing
2337 * NT_TRANSACT_GET_USER_QUOTA in smb1 protocol, which is
2338 * currently not supported by this module.
2340 case SMB_USER_QUOTA_TYPE
:
2341 case SMB_GROUP_QUOTA_TYPE
:
2345 return SMB_VFS_NEXT_GET_QUOTA(handle
, smb_fname
,
2350 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct
*handle
,
2351 enum timestamp_set_resolution
*p_ts_res
)
2353 struct gpfs_config_data
*config
;
2356 next
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
2358 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2359 struct gpfs_config_data
,
2363 next
|= FILE_SUPPORTS_REMOTE_STORAGE
;
2368 static int vfs_gpfs_open(struct vfs_handle_struct
*handle
,
2369 struct smb_filename
*smb_fname
, files_struct
*fsp
,
2370 int flags
, mode_t mode
)
2372 struct gpfs_config_data
*config
;
2374 struct gpfs_fsp_extension
*ext
;
2376 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2377 struct gpfs_config_data
,
2380 if (config
->hsm
&& !config
->recalls
&&
2381 vfs_gpfs_fsp_is_offline(handle
, fsp
)) {
2382 DEBUG(10, ("Refusing access to offline file %s\n",
2388 if (config
->syncio
) {
2392 ext
= VFS_ADD_FSP_EXTENSION(handle
, fsp
, struct gpfs_fsp_extension
,
2400 * Assume the file is offline until gpfs tells us it's online.
2402 *ext
= (struct gpfs_fsp_extension
) { .offline
= true };
2404 ret
= SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
2406 VFS_REMOVE_FSP_EXTENSION(handle
, fsp
);
2411 static ssize_t
vfs_gpfs_pread(vfs_handle_struct
*handle
, files_struct
*fsp
,
2412 void *data
, size_t n
, off_t offset
)
2417 was_offline
= vfs_gpfs_fsp_is_offline(handle
, fsp
);
2419 ret
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
2421 if ((ret
!= -1) && was_offline
) {
2422 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2423 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2424 fsp
->fsp_name
->base_name
);
2430 struct vfs_gpfs_pread_state
{
2431 struct files_struct
*fsp
;
2434 struct vfs_aio_state vfs_aio_state
;
2437 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
);
2439 static struct tevent_req
*vfs_gpfs_pread_send(struct vfs_handle_struct
*handle
,
2440 TALLOC_CTX
*mem_ctx
,
2441 struct tevent_context
*ev
,
2442 struct files_struct
*fsp
,
2443 void *data
, size_t n
,
2446 struct tevent_req
*req
, *subreq
;
2447 struct vfs_gpfs_pread_state
*state
;
2449 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pread_state
);
2453 state
->was_offline
= vfs_gpfs_fsp_is_offline(handle
, fsp
);
2455 subreq
= SMB_VFS_NEXT_PREAD_SEND(state
, ev
, handle
, fsp
, data
,
2457 if (tevent_req_nomem(subreq
, req
)) {
2458 return tevent_req_post(req
, ev
);
2460 tevent_req_set_callback(subreq
, vfs_gpfs_pread_done
, req
);
2464 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
)
2466 struct tevent_req
*req
= tevent_req_callback_data(
2467 subreq
, struct tevent_req
);
2468 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2469 req
, struct vfs_gpfs_pread_state
);
2471 state
->ret
= SMB_VFS_PREAD_RECV(subreq
, &state
->vfs_aio_state
);
2472 TALLOC_FREE(subreq
);
2473 tevent_req_done(req
);
2476 static ssize_t
vfs_gpfs_pread_recv(struct tevent_req
*req
,
2477 struct vfs_aio_state
*vfs_aio_state
)
2479 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2480 req
, struct vfs_gpfs_pread_state
);
2481 struct files_struct
*fsp
= state
->fsp
;
2483 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
2486 *vfs_aio_state
= state
->vfs_aio_state
;
2488 if ((state
->ret
!= -1) && state
->was_offline
) {
2489 DEBUG(10, ("sending notify\n"));
2490 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2491 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2492 fsp
->fsp_name
->base_name
);
2498 static ssize_t
vfs_gpfs_pwrite(vfs_handle_struct
*handle
, files_struct
*fsp
,
2499 const void *data
, size_t n
, off_t offset
)
2504 was_offline
= vfs_gpfs_fsp_is_offline(handle
, fsp
);
2506 ret
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
2508 if ((ret
!= -1) && was_offline
) {
2509 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2510 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2511 fsp
->fsp_name
->base_name
);
2517 struct vfs_gpfs_pwrite_state
{
2518 struct files_struct
*fsp
;
2521 struct vfs_aio_state vfs_aio_state
;
2524 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
);
2526 static struct tevent_req
*vfs_gpfs_pwrite_send(
2527 struct vfs_handle_struct
*handle
,
2528 TALLOC_CTX
*mem_ctx
,
2529 struct tevent_context
*ev
,
2530 struct files_struct
*fsp
,
2531 const void *data
, size_t n
,
2534 struct tevent_req
*req
, *subreq
;
2535 struct vfs_gpfs_pwrite_state
*state
;
2537 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pwrite_state
);
2541 state
->was_offline
= vfs_gpfs_fsp_is_offline(handle
, fsp
);
2543 subreq
= SMB_VFS_NEXT_PWRITE_SEND(state
, ev
, handle
, fsp
, data
,
2545 if (tevent_req_nomem(subreq
, req
)) {
2546 return tevent_req_post(req
, ev
);
2548 tevent_req_set_callback(subreq
, vfs_gpfs_pwrite_done
, req
);
2552 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
)
2554 struct tevent_req
*req
= tevent_req_callback_data(
2555 subreq
, struct tevent_req
);
2556 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2557 req
, struct vfs_gpfs_pwrite_state
);
2559 state
->ret
= SMB_VFS_PWRITE_RECV(subreq
, &state
->vfs_aio_state
);
2560 TALLOC_FREE(subreq
);
2561 tevent_req_done(req
);
2564 static ssize_t
vfs_gpfs_pwrite_recv(struct tevent_req
*req
,
2565 struct vfs_aio_state
*vfs_aio_state
)
2567 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2568 req
, struct vfs_gpfs_pwrite_state
);
2569 struct files_struct
*fsp
= state
->fsp
;
2571 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
2574 *vfs_aio_state
= state
->vfs_aio_state
;
2576 if ((state
->ret
!= -1) && state
->was_offline
) {
2577 DEBUG(10, ("sending notify\n"));
2578 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2579 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2580 fsp
->fsp_name
->base_name
);
2587 static struct vfs_fn_pointers vfs_gpfs_fns
= {
2588 .connect_fn
= vfs_gpfs_connect
,
2589 .disk_free_fn
= vfs_gpfs_disk_free
,
2590 .get_quota_fn
= vfs_gpfs_get_quota
,
2591 .fs_capabilities_fn
= vfs_gpfs_capabilities
,
2592 .kernel_flock_fn
= vfs_gpfs_kernel_flock
,
2593 .linux_setlease_fn
= vfs_gpfs_setlease
,
2594 .get_real_filename_fn
= vfs_gpfs_get_real_filename
,
2595 .get_dos_attributes_fn
= vfs_gpfs_get_dos_attributes
,
2596 .get_dos_attributes_send_fn
= vfs_not_implemented_get_dos_attributes_send
,
2597 .get_dos_attributes_recv_fn
= vfs_not_implemented_get_dos_attributes_recv
,
2598 .fget_dos_attributes_fn
= vfs_gpfs_fget_dos_attributes
,
2599 .set_dos_attributes_fn
= vfs_gpfs_set_dos_attributes
,
2600 .fset_dos_attributes_fn
= vfs_gpfs_fset_dos_attributes
,
2601 .fget_nt_acl_fn
= gpfsacl_fget_nt_acl
,
2602 .get_nt_acl_fn
= gpfsacl_get_nt_acl
,
2603 .fset_nt_acl_fn
= gpfsacl_fset_nt_acl
,
2604 .sys_acl_get_file_fn
= gpfsacl_sys_acl_get_file
,
2605 .sys_acl_get_fd_fn
= gpfsacl_sys_acl_get_fd
,
2606 .sys_acl_blob_get_file_fn
= gpfsacl_sys_acl_blob_get_file
,
2607 .sys_acl_blob_get_fd_fn
= gpfsacl_sys_acl_blob_get_fd
,
2608 .sys_acl_set_file_fn
= gpfsacl_sys_acl_set_file
,
2609 .sys_acl_set_fd_fn
= gpfsacl_sys_acl_set_fd
,
2610 .sys_acl_delete_def_file_fn
= gpfsacl_sys_acl_delete_def_file
,
2611 .chmod_fn
= vfs_gpfs_chmod
,
2612 .fchmod_fn
= vfs_gpfs_fchmod
,
2613 .close_fn
= vfs_gpfs_close
,
2614 .stat_fn
= vfs_gpfs_stat
,
2615 .lstat_fn
= vfs_gpfs_lstat
,
2616 .ntimes_fn
= vfs_gpfs_ntimes
,
2617 .aio_force_fn
= vfs_gpfs_aio_force
,
2618 .sendfile_fn
= vfs_gpfs_sendfile
,
2619 .fallocate_fn
= vfs_gpfs_fallocate
,
2620 .open_fn
= vfs_gpfs_open
,
2621 .pread_fn
= vfs_gpfs_pread
,
2622 .pread_send_fn
= vfs_gpfs_pread_send
,
2623 .pread_recv_fn
= vfs_gpfs_pread_recv
,
2624 .pwrite_fn
= vfs_gpfs_pwrite
,
2625 .pwrite_send_fn
= vfs_gpfs_pwrite_send
,
2626 .pwrite_recv_fn
= vfs_gpfs_pwrite_recv
,
2627 .ftruncate_fn
= vfs_gpfs_ftruncate
2631 NTSTATUS
vfs_gpfs_init(TALLOC_CTX
*ctx
)
2635 ret
= gpfswrap_init();
2637 DEBUG(1, ("Could not initialize GPFS library wrapper\n"));
2640 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "gpfs",