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
)) ?
103 DEBUG(10, ("am=%x, allow=%d, sa=%x, deny=%d\n",
104 access_mask
, allow
, share_access
, deny
));
106 result
= gpfswrap_set_share(fsp
->fh
->fd
, allow
, deny
);
108 if (errno
== ENOSYS
) {
109 DEBUG(5, ("VFS module vfs_gpfs loaded, but gpfs "
110 "set_share function support not available. "
111 "Allowing access\n"));
114 DEBUG(10, ("gpfs_set_share failed: %s\n",
119 return (result
== 0);
122 static int vfs_gpfs_kernel_flock(vfs_handle_struct
*handle
, files_struct
*fsp
,
123 uint32_t share_mode
, uint32_t access_mask
)
126 struct gpfs_config_data
*config
;
129 START_PROFILE(syscall_kernel_flock
);
131 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
132 struct gpfs_config_data
,
135 if(!config
->sharemodes
) {
140 * A named stream fsp will have the basefile open in the fsp
141 * fd, so lacking a distinct fd for the stream we have to skip
142 * kernel_flock and set_gpfs_sharemode for stream.
144 if (is_ntfs_stream_smb_fname(fsp
->fsp_name
) &&
145 !is_ntfs_default_stream_smb_fname(fsp
->fsp_name
)) {
146 DEBUG(2,("%s: kernel_flock on stream\n", fsp_str_dbg(fsp
)));
150 kernel_flock(fsp
->fh
->fd
, share_mode
, access_mask
);
152 if (!set_gpfs_sharemode(fsp
, access_mask
, fsp
->share_access
)) {
156 END_PROFILE(syscall_kernel_flock
);
161 static int vfs_gpfs_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
164 struct gpfs_config_data
*config
;
166 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
167 struct gpfs_config_data
,
170 if (config
->sharemodes
&& (fsp
->fh
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
171 set_gpfs_sharemode(fsp
, 0, 0);
174 return SMB_VFS_NEXT_CLOSE(handle
, fsp
);
177 static int set_gpfs_lease(int fd
, int leasetype
)
179 int gpfs_type
= GPFS_LEASE_NONE
;
181 if (leasetype
== F_RDLCK
) {
182 gpfs_type
= GPFS_LEASE_READ
;
184 if (leasetype
== F_WRLCK
) {
185 gpfs_type
= GPFS_LEASE_WRITE
;
188 /* we unconditionally set CAP_LEASE, rather than looking for
189 -1/EACCES as there is a bug in some versions of
190 libgpfs_gpl.so which results in a leaked fd on /dev/ss0
191 each time we try this with the wrong capabilities set
193 linux_set_lease_capability();
194 return gpfswrap_set_lease(fd
, gpfs_type
);
197 static int vfs_gpfs_setlease(vfs_handle_struct
*handle
, files_struct
*fsp
,
200 struct gpfs_config_data
*config
;
203 START_PROFILE(syscall_linux_setlease
);
205 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
206 struct gpfs_config_data
,
209 if (linux_set_lease_sighandler(fsp
->fh
->fd
) == -1) {
214 if (config
->leases
) {
216 * Ensure the lease owner is root to allow
217 * correct delivery of lease-break signals.
220 ret
= set_gpfs_lease(fsp
->fh
->fd
,leasetype
);
225 END_PROFILE(syscall_linux_setlease
);
230 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct
*handle
,
238 char real_pathname
[PATH_MAX
+1];
241 struct gpfs_config_data
*config
;
243 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
244 struct gpfs_config_data
,
247 if (!config
->getrealfilename
) {
248 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
249 mem_ctx
, found_name
);
252 mangled
= mangle_is_mangled(name
, handle
->conn
->params
);
254 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
255 mem_ctx
, found_name
);
258 full_path
= talloc_asprintf(talloc_tos(), "%s/%s", path
, name
);
259 if (full_path
== NULL
) {
264 buflen
= sizeof(real_pathname
) - 1;
266 result
= gpfswrap_get_realfilename_path(full_path
, real_pathname
,
269 TALLOC_FREE(full_path
);
271 if ((result
== -1) && (errno
== ENOSYS
)) {
272 return SMB_VFS_NEXT_GET_REAL_FILENAME(
273 handle
, path
, name
, mem_ctx
, found_name
);
277 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
283 * GPFS does not necessarily null-terminate the returned path
284 * but instead returns the buffer length in buflen.
287 if (buflen
< sizeof(real_pathname
)) {
288 real_pathname
[buflen
] = '\0';
290 real_pathname
[sizeof(real_pathname
)-1] = '\0';
293 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
294 path
, name
, real_pathname
));
296 name
= strrchr_m(real_pathname
, '/');
302 *found_name
= talloc_strdup(mem_ctx
, name
+1);
303 if (*found_name
== NULL
) {
311 static void sd2gpfs_control(uint16_t control
, struct gpfs_acl
*gacl
)
313 unsigned int gpfs_aclflags
= 0;
314 control
&= SEC_DESC_DACL_PROTECTED
| SEC_DESC_SACL_PROTECTED
|
315 SEC_DESC_DACL_AUTO_INHERITED
| SEC_DESC_SACL_AUTO_INHERITED
|
316 SEC_DESC_DACL_DEFAULTED
| SEC_DESC_SACL_DEFAULTED
|
317 SEC_DESC_DACL_PRESENT
| SEC_DESC_SACL_PRESENT
;
318 gpfs_aclflags
= control
<< 8;
319 if (!(control
& SEC_DESC_DACL_PRESENT
))
320 gpfs_aclflags
|= ACL4_FLAG_NULL_DACL
;
321 if (!(control
& SEC_DESC_SACL_PRESENT
))
322 gpfs_aclflags
|= ACL4_FLAG_NULL_SACL
;
323 gacl
->acl_level
= GPFS_ACL_LEVEL_V4FLAGS
;
324 gacl
->v4Level1
.acl_flags
= gpfs_aclflags
;
327 static uint16_t gpfs2sd_control(unsigned int gpfs_aclflags
)
329 uint16_t control
= gpfs_aclflags
>> 8;
330 control
&= SEC_DESC_DACL_PROTECTED
| SEC_DESC_SACL_PROTECTED
|
331 SEC_DESC_DACL_AUTO_INHERITED
| SEC_DESC_SACL_AUTO_INHERITED
|
332 SEC_DESC_DACL_DEFAULTED
| SEC_DESC_SACL_DEFAULTED
|
333 SEC_DESC_DACL_PRESENT
| SEC_DESC_SACL_PRESENT
;
334 control
|= SEC_DESC_SELF_RELATIVE
;
338 static void gpfs_dumpacl(int level
, struct gpfs_acl
*gacl
)
343 DEBUG(0, ("gpfs acl is NULL\n"));
347 DEBUG(level
, ("len: %d, level: %d, version: %d, nace: %d, "
349 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
350 gacl
->acl_nace
, gpfs_acl_flags(gacl
)));
352 for(i
=0; i
<gacl
->acl_nace
; i
++)
354 struct gpfs_ace_v4
*gace
= gpfs_ace_ptr(gacl
, i
);
355 DEBUG(level
, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, "
356 "iflags:0x%x, who:%u\n",
357 i
, gace
->aceType
, gace
->aceFlags
, gace
->aceMask
,
358 gace
->aceIFlags
, gace
->aceWho
));
362 static int gpfs_getacl_with_capability(const char *fname
, int flags
, void *buf
)
364 int ret
, saved_errno
;
366 set_effective_capability(DAC_OVERRIDE_CAPABILITY
);
368 ret
= gpfswrap_getacl(discard_const_p(char, fname
), flags
, buf
);
371 drop_effective_capability(DAC_OVERRIDE_CAPABILITY
);
378 * get the ACL from GPFS, allocated on the specified mem_ctx
379 * internally retries when initial buffer was too small
381 * caller needs to cast result to either
382 * raw = yes: struct gpfs_opaque_acl
383 * raw = no: struct gpfs_acl
386 static void *vfs_gpfs_getacl(TALLOC_CTX
*mem_ctx
,
389 const gpfs_aclType_t type
)
397 bool use_capability
= false;
401 aclbuf
= talloc_zero_size(mem_ctx
, size
);
402 if (aclbuf
== NULL
) {
408 struct gpfs_opaque_acl
*buf
= (struct gpfs_opaque_acl
*) aclbuf
;
409 buf
->acl_type
= type
;
410 flags
= GPFS_GETACL_NATIVE
;
411 len
= (unsigned int *) &(buf
->acl_buffer_len
);
412 struct_size
= sizeof(struct gpfs_opaque_acl
);
414 struct gpfs_acl
*buf
= (struct gpfs_acl
*) aclbuf
;
415 buf
->acl_type
= type
;
416 buf
->acl_level
= GPFS_ACL_LEVEL_V4FLAGS
;
417 flags
= GPFS_GETACL_STRUCT
;
418 len
= &(buf
->acl_len
);
419 /* reserve space for control flags in gpfs 3.5 and beyond */
420 struct_size
= sizeof(struct gpfs_acl
) + sizeof(unsigned int);
423 /* set the length of the buffer as input value */
426 if (use_capability
) {
427 ret
= gpfs_getacl_with_capability(fname
, flags
, aclbuf
);
429 ret
= gpfswrap_getacl(discard_const_p(char, fname
),
431 if ((ret
!= 0) && (errno
== EACCES
)) {
432 DBG_DEBUG("Retry with DAC capability for %s\n", fname
);
433 use_capability
= true;
434 ret
= gpfs_getacl_with_capability(fname
, flags
, aclbuf
);
438 if ((ret
!= 0) && (errno
== ENOSPC
)) {
440 * get the size needed to accommodate the complete buffer
442 * the value returned only applies to the ACL blob in the
443 * struct so make sure to also have headroom for the first
444 * struct members by adding room for the complete struct
445 * (might be a few bytes too much then)
447 size
= *len
+ struct_size
;
449 DEBUG(10, ("Increasing ACL buffer size to %zu\n", size
));
454 DEBUG(5, ("smbd_gpfs_getacl failed with %s\n",
463 /* Tries to get nfs4 acls and returns SMB ACL allocated.
464 * On failure returns 1 if it got non-NFSv4 ACL to prompt
465 * retry with POSIX ACL checks.
466 * On failure returns -1 if there is system (GPFS) error, check errno.
467 * Returns 0 on success
469 static int gpfs_get_nfs4_acl(TALLOC_CTX
*mem_ctx
, const char *fname
,
470 struct SMB4ACL_T
**ppacl
)
473 struct gpfs_acl
*gacl
= NULL
;
474 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname
));
477 gacl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(), fname
,
480 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
481 fname
, strerror(errno
)));
482 if (errno
== ENODATA
) {
484 * GPFS returns ENODATA for snapshot
485 * directories. Retry with POSIX ACLs check.
493 if (gacl
->acl_type
!= GPFS_ACL_TYPE_NFS4
) {
494 DEBUG(10, ("Got non-nfsv4 acl\n"));
495 /* Retry with POSIX ACLs check */
500 *ppacl
= smb_create_smb4acl(mem_ctx
);
502 if (gacl
->acl_level
== GPFS_ACL_LEVEL_V4FLAGS
) {
503 uint16_t control
= gpfs2sd_control(gpfs_acl_flags(gacl
));
504 smbacl4_set_controlflags(*ppacl
, control
);
507 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d, control: %x\n",
508 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
509 gacl
->acl_nace
, gpfs_acl_flags(gacl
)));
511 for (i
=0; i
<gacl
->acl_nace
; i
++) {
512 struct gpfs_ace_v4
*gace
= gpfs_ace_ptr(gacl
, i
);
513 SMB_ACE4PROP_T smbace
= { 0 };
514 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
515 "who: %d\n", gace
->aceType
, gace
->aceIFlags
,
516 gace
->aceFlags
, gace
->aceMask
, gace
->aceWho
));
518 if (gace
->aceIFlags
& ACE4_IFLAG_SPECIAL_ID
) {
519 smbace
.flags
|= SMB_ACE4_ID_SPECIAL
;
520 switch (gace
->aceWho
) {
521 case ACE4_SPECIAL_OWNER
:
522 smbace
.who
.special_id
= SMB_ACE4_WHO_OWNER
;
524 case ACE4_SPECIAL_GROUP
:
525 smbace
.who
.special_id
= SMB_ACE4_WHO_GROUP
;
527 case ACE4_SPECIAL_EVERYONE
:
528 smbace
.who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
531 DEBUG(8, ("invalid special gpfs id %d "
532 "ignored\n", gace
->aceWho
));
533 continue; /* don't add it */
536 if (gace
->aceFlags
& ACE4_FLAG_GROUP_ID
)
537 smbace
.who
.gid
= gace
->aceWho
;
539 smbace
.who
.uid
= gace
->aceWho
;
542 /* remove redundant deny entries */
543 if (i
> 0 && gace
->aceType
== SMB_ACE4_ACCESS_DENIED_ACE_TYPE
) {
544 struct gpfs_ace_v4
*prev
= gpfs_ace_ptr(gacl
, i
- 1);
545 if (prev
->aceType
== SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
&&
546 prev
->aceFlags
== gace
->aceFlags
&&
547 prev
->aceIFlags
== gace
->aceIFlags
&&
548 (gace
->aceMask
& prev
->aceMask
) == 0 &&
549 gace
->aceWho
== prev
->aceWho
) {
550 /* it's redundant - skip it */
555 smbace
.aceType
= gace
->aceType
;
556 smbace
.aceFlags
= gace
->aceFlags
;
557 smbace
.aceMask
= gace
->aceMask
;
558 smb_add_ace4(*ppacl
, &smbace
);
566 static NTSTATUS
gpfsacl_fget_nt_acl(vfs_handle_struct
*handle
,
567 files_struct
*fsp
, uint32_t security_info
,
569 struct security_descriptor
**ppdesc
)
571 struct SMB4ACL_T
*pacl
= NULL
;
573 struct gpfs_config_data
*config
;
574 TALLOC_CTX
*frame
= talloc_stackframe();
579 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
580 struct gpfs_config_data
,
581 return NT_STATUS_INTERNAL_ERROR
);
584 status
= SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
590 result
= gpfs_get_nfs4_acl(frame
, fsp
->fsp_name
->base_name
, &pacl
);
593 status
= smb_fget_nt_acl_nfs4(fsp
, &config
->nfs4_params
,
595 mem_ctx
, ppdesc
, pacl
);
601 DEBUG(10, ("retrying with posix acl...\n"));
602 status
= posix_fget_nt_acl(fsp
, security_info
,
610 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
611 return map_nt_error_from_unix(errno
);
614 static NTSTATUS
gpfsacl_get_nt_acl(vfs_handle_struct
*handle
,
615 const struct smb_filename
*smb_fname
,
616 uint32_t security_info
,
618 struct security_descriptor
**ppdesc
)
620 struct SMB4ACL_T
*pacl
= NULL
;
622 struct gpfs_config_data
*config
;
623 TALLOC_CTX
*frame
= talloc_stackframe();
628 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
629 struct gpfs_config_data
,
630 return NT_STATUS_INTERNAL_ERROR
);
633 status
= SMB_VFS_NEXT_GET_NT_ACL(handle
, smb_fname
,
640 result
= gpfs_get_nfs4_acl(frame
, smb_fname
->base_name
, &pacl
);
643 status
= smb_get_nt_acl_nfs4(handle
->conn
, smb_fname
,
644 &config
->nfs4_params
,
645 security_info
, mem_ctx
, ppdesc
,
652 DEBUG(10, ("retrying with posix acl...\n"));
653 status
= posix_get_nt_acl(handle
->conn
, smb_fname
,
654 security_info
, mem_ctx
, ppdesc
);
659 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
661 return map_nt_error_from_unix(errno
);
664 static struct gpfs_acl
*vfs_gpfs_smbacl2gpfsacl(TALLOC_CTX
*mem_ctx
,
666 struct SMB4ACL_T
*smbacl
,
669 struct gpfs_acl
*gacl
;
670 gpfs_aclLen_t gacl_len
;
671 struct SMB4ACE_T
*smbace
;
673 gacl_len
= offsetof(gpfs_acl_t
, ace_v4
) + sizeof(unsigned int)
674 + smb_get_naces(smbacl
) * sizeof(gpfs_ace_v4_t
);
676 gacl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, gacl_len
);
678 DEBUG(0, ("talloc failed\n"));
683 gacl
->acl_level
= GPFS_ACL_LEVEL_BASE
;
684 gacl
->acl_version
= GPFS_ACL_VERSION_NFS4
;
685 gacl
->acl_type
= GPFS_ACL_TYPE_NFS4
;
686 gacl
->acl_nace
= 0; /* change later... */
689 gacl
->acl_level
= GPFS_ACL_LEVEL_V4FLAGS
;
690 sd2gpfs_control(smbacl4_get_controlflags(smbacl
), gacl
);
693 for (smbace
=smb_first_ace4(smbacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
694 struct gpfs_ace_v4
*gace
= gpfs_ace_ptr(gacl
, gacl
->acl_nace
);
695 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
697 gace
->aceType
= aceprop
->aceType
;
698 gace
->aceFlags
= aceprop
->aceFlags
;
699 gace
->aceMask
= aceprop
->aceMask
;
702 * GPFS can't distinguish between WRITE and APPEND on
703 * files, so one being set without the other is an
704 * error. Sorry for the many ()'s :-)
707 if (!fsp
->is_directory
709 ((((gace
->aceMask
& ACE4_MASK_WRITE
) == 0)
710 && ((gace
->aceMask
& ACE4_MASK_APPEND
) != 0))
712 (((gace
->aceMask
& ACE4_MASK_WRITE
) != 0)
713 && ((gace
->aceMask
& ACE4_MASK_APPEND
) == 0)))
715 lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
716 "merge_writeappend", True
)) {
717 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
718 "WRITE^APPEND, setting WRITE|APPEND\n",
720 gace
->aceMask
|= ACE4_MASK_WRITE
|ACE4_MASK_APPEND
;
723 gace
->aceIFlags
= (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
) ? ACE4_IFLAG_SPECIAL_ID
: 0;
725 if (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
)
727 switch(aceprop
->who
.special_id
)
729 case SMB_ACE4_WHO_EVERYONE
:
730 gace
->aceWho
= ACE4_SPECIAL_EVERYONE
;
732 case SMB_ACE4_WHO_OWNER
:
733 gace
->aceWho
= ACE4_SPECIAL_OWNER
;
735 case SMB_ACE4_WHO_GROUP
:
736 gace
->aceWho
= ACE4_SPECIAL_GROUP
;
739 DEBUG(8, ("unsupported special_id %d\n", aceprop
->who
.special_id
));
740 continue; /* don't add it !!! */
743 /* just only for the type safety... */
744 if (aceprop
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)
745 gace
->aceWho
= aceprop
->who
.gid
;
747 gace
->aceWho
= aceprop
->who
.uid
;
752 gacl
->acl_len
= (char *)gpfs_ace_ptr(gacl
, gacl
->acl_nace
)
757 static bool gpfsacl_process_smbacl(vfs_handle_struct
*handle
,
759 struct SMB4ACL_T
*smbacl
)
762 struct gpfs_acl
*gacl
;
763 TALLOC_CTX
*mem_ctx
= talloc_tos();
765 gacl
= vfs_gpfs_smbacl2gpfsacl(mem_ctx
, fsp
, smbacl
, true);
766 if (gacl
== NULL
) { /* out of memory */
769 ret
= gpfswrap_putacl(fsp
->fsp_name
->base_name
,
770 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gacl
);
772 if ((ret
!= 0) && (errno
== EINVAL
)) {
773 DEBUG(10, ("Retry without nfs41 control flags\n"));
775 gacl
= vfs_gpfs_smbacl2gpfsacl(mem_ctx
, fsp
, smbacl
, false);
776 if (gacl
== NULL
) { /* out of memory */
779 ret
= gpfswrap_putacl(fsp
->fsp_name
->base_name
,
780 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
,
785 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno
)));
786 gpfs_dumpacl(8, gacl
);
790 DEBUG(10, ("gpfs_putacl succeeded\n"));
794 static NTSTATUS
gpfsacl_set_nt_acl_internal(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32_t security_info_sent
, const struct security_descriptor
*psd
)
796 struct gpfs_acl
*acl
;
797 NTSTATUS result
= NT_STATUS_ACCESS_DENIED
;
799 acl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(),
800 fsp
->fsp_name
->base_name
,
803 return map_nt_error_from_unix(errno
);
806 if (acl
->acl_version
== GPFS_ACL_VERSION_NFS4
) {
807 struct gpfs_config_data
*config
;
809 if (lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
810 "refuse_dacl_protected", false)
811 && (psd
->type
&SEC_DESC_DACL_PROTECTED
)) {
812 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
814 return NT_STATUS_NOT_SUPPORTED
;
817 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
818 struct gpfs_config_data
,
819 return NT_STATUS_INTERNAL_ERROR
);
821 result
= smb_set_nt_acl_nfs4(handle
,
822 fsp
, &config
->nfs4_params
, security_info_sent
, psd
,
823 gpfsacl_process_smbacl
);
824 } else { /* assume POSIX ACL - by default... */
825 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
832 static NTSTATUS
gpfsacl_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32_t security_info_sent
, const struct security_descriptor
*psd
)
834 struct gpfs_config_data
*config
;
836 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
837 struct gpfs_config_data
,
838 return NT_STATUS_INTERNAL_ERROR
);
841 return SMB_VFS_NEXT_FSET_NT_ACL(handle
, fsp
, security_info_sent
, psd
);
844 return gpfsacl_set_nt_acl_internal(handle
, fsp
, security_info_sent
, psd
);
847 static SMB_ACL_T
gpfs2smb_acl(const struct gpfs_acl
*pacl
, TALLOC_CTX
*mem_ctx
)
852 result
= sys_acl_init(mem_ctx
);
853 if (result
== NULL
) {
858 result
->count
= pacl
->acl_nace
;
859 result
->acl
= talloc_realloc(result
, result
->acl
, struct smb_acl_entry
,
861 if (result
->acl
== NULL
) {
867 for (i
=0; i
<pacl
->acl_nace
; i
++) {
868 struct smb_acl_entry
*ace
= &result
->acl
[i
];
869 const struct gpfs_ace_v1
*g_ace
= &pacl
->ace_v1
[i
];
871 DEBUG(10, ("Converting type %d id %lu perm %x\n",
872 (int)g_ace
->ace_type
, (unsigned long)g_ace
->ace_who
,
873 (int)g_ace
->ace_perm
));
875 switch (g_ace
->ace_type
) {
877 ace
->a_type
= SMB_ACL_USER
;
878 ace
->info
.user
.uid
= (uid_t
)g_ace
->ace_who
;
880 case GPFS_ACL_USER_OBJ
:
881 ace
->a_type
= SMB_ACL_USER_OBJ
;
884 ace
->a_type
= SMB_ACL_GROUP
;
885 ace
->info
.group
.gid
= (gid_t
)g_ace
->ace_who
;
887 case GPFS_ACL_GROUP_OBJ
:
888 ace
->a_type
= SMB_ACL_GROUP_OBJ
;
891 ace
->a_type
= SMB_ACL_OTHER
;
894 ace
->a_type
= SMB_ACL_MASK
;
897 DEBUG(10, ("Got invalid ace_type: %d\n",
905 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_READ
) ?
907 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_WRITE
) ?
909 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_EXECUTE
) ?
912 DEBUGADD(10, ("Converted to %d perm %x\n",
913 ace
->a_type
, ace
->a_perm
));
919 static SMB_ACL_T
gpfsacl_get_posix_acl(const char *path
, gpfs_aclType_t type
,
922 struct gpfs_acl
*pacl
;
923 SMB_ACL_T result
= NULL
;
925 pacl
= vfs_gpfs_getacl(talloc_tos(), path
, false, type
);
928 DEBUG(10, ("vfs_gpfs_getacl failed for %s with %s\n",
929 path
, strerror(errno
)));
936 if (pacl
->acl_version
!= GPFS_ACL_VERSION_POSIX
) {
937 DEBUG(10, ("Got acl version %d, expected %d\n",
938 pacl
->acl_version
, GPFS_ACL_VERSION_POSIX
));
943 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
944 pacl
->acl_len
, pacl
->acl_level
, pacl
->acl_version
,
947 result
= gpfs2smb_acl(pacl
, mem_ctx
);
948 if (result
!= NULL
) {
963 static SMB_ACL_T
gpfsacl_sys_acl_get_file(vfs_handle_struct
*handle
,
964 const struct smb_filename
*smb_fname
,
968 gpfs_aclType_t gpfs_type
;
969 struct gpfs_config_data
*config
;
971 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
972 struct gpfs_config_data
,
976 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle
, smb_fname
,
981 case SMB_ACL_TYPE_ACCESS
:
982 gpfs_type
= GPFS_ACL_TYPE_ACCESS
;
984 case SMB_ACL_TYPE_DEFAULT
:
985 gpfs_type
= GPFS_ACL_TYPE_DEFAULT
;
988 DEBUG(0, ("Got invalid type: %d\n", type
));
989 smb_panic("exiting");
992 return gpfsacl_get_posix_acl(smb_fname
->base_name
, gpfs_type
, mem_ctx
);
995 static SMB_ACL_T
gpfsacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
999 struct gpfs_config_data
*config
;
1001 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1002 struct gpfs_config_data
,
1006 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle
, fsp
, mem_ctx
);
1009 return gpfsacl_get_posix_acl(fsp
->fsp_name
->base_name
,
1010 GPFS_ACL_TYPE_ACCESS
, mem_ctx
);
1013 static int gpfsacl_sys_acl_blob_get_file(vfs_handle_struct
*handle
,
1014 const struct smb_filename
*smb_fname
,
1015 TALLOC_CTX
*mem_ctx
,
1016 char **blob_description
,
1019 struct gpfs_config_data
*config
;
1020 struct gpfs_opaque_acl
*acl
= NULL
;
1023 const char *path_p
= smb_fname
->base_name
;
1025 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1026 struct gpfs_config_data
,
1030 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle
, smb_fname
,
1037 acl
= (struct gpfs_opaque_acl
*)
1038 vfs_gpfs_getacl(mem_ctx
,
1041 GPFS_ACL_TYPE_NFS4
);
1044 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
1045 errno
, strerror(errno
)));
1047 /* EINVAL means POSIX ACL, bail out on other cases */
1048 if (errno
!= EINVAL
) {
1055 * file has NFSv4 ACL
1057 * we only need the actual ACL blob here
1058 * acl_version will always be NFS4 because we asked
1060 * acl_type is only used for POSIX ACLs
1062 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
1063 aclblob
.length
= acl
->acl_buffer_len
;
1065 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
1066 if (!*blob_description
) {
1072 result
= non_posix_sys_acl_blob_get_file_helper(handle
, smb_fname
,
1080 /* fall back to POSIX ACL */
1081 return posix_sys_acl_blob_get_file(handle
, smb_fname
, mem_ctx
,
1082 blob_description
, blob
);
1085 static int gpfsacl_sys_acl_blob_get_fd(vfs_handle_struct
*handle
,
1087 TALLOC_CTX
*mem_ctx
,
1088 char **blob_description
,
1091 struct gpfs_config_data
*config
;
1092 struct gpfs_opaque_acl
*acl
= NULL
;
1096 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1097 struct gpfs_config_data
,
1101 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle
, fsp
, mem_ctx
,
1102 blob_description
, blob
);
1106 acl
= (struct gpfs_opaque_acl
*) vfs_gpfs_getacl(mem_ctx
,
1107 fsp
->fsp_name
->base_name
,
1109 GPFS_ACL_TYPE_NFS4
);
1112 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
1113 errno
, strerror(errno
)));
1115 /* EINVAL means POSIX ACL, bail out on other cases */
1116 if (errno
!= EINVAL
) {
1123 * file has NFSv4 ACL
1125 * we only need the actual ACL blob here
1126 * acl_version will always be NFS4 because we asked
1128 * acl_type is only used for POSIX ACLs
1130 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
1131 aclblob
.length
= acl
->acl_buffer_len
;
1133 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
1134 if (!*blob_description
) {
1140 result
= non_posix_sys_acl_blob_get_fd_helper(handle
, fsp
,
1148 /* fall back to POSIX ACL */
1149 return posix_sys_acl_blob_get_fd(handle
, fsp
, mem_ctx
,
1150 blob_description
, blob
);
1153 static struct gpfs_acl
*smb2gpfs_acl(const SMB_ACL_T pacl
,
1154 SMB_ACL_TYPE_T type
)
1157 struct gpfs_acl
*result
;
1160 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl
->count
));
1162 len
= offsetof(gpfs_acl_t
, ace_v1
) + (pacl
->count
) *
1163 sizeof(gpfs_ace_v1_t
);
1165 result
= (struct gpfs_acl
*)SMB_MALLOC(len
);
1166 if (result
== NULL
) {
1171 result
->acl_len
= len
;
1172 result
->acl_level
= 0;
1173 result
->acl_version
= GPFS_ACL_VERSION_POSIX
;
1174 result
->acl_type
= (type
== SMB_ACL_TYPE_DEFAULT
) ?
1175 GPFS_ACL_TYPE_DEFAULT
: GPFS_ACL_TYPE_ACCESS
;
1176 result
->acl_nace
= pacl
->count
;
1178 for (i
=0; i
<pacl
->count
; i
++) {
1179 const struct smb_acl_entry
*ace
= &pacl
->acl
[i
];
1180 struct gpfs_ace_v1
*g_ace
= &result
->ace_v1
[i
];
1182 DEBUG(10, ("Converting type %d perm %x\n",
1183 (int)ace
->a_type
, (int)ace
->a_perm
));
1185 g_ace
->ace_perm
= 0;
1187 switch(ace
->a_type
) {
1189 g_ace
->ace_type
= GPFS_ACL_USER
;
1190 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.user
.uid
;
1192 case SMB_ACL_USER_OBJ
:
1193 g_ace
->ace_type
= GPFS_ACL_USER_OBJ
;
1194 g_ace
->ace_perm
|= ACL_PERM_CONTROL
;
1198 g_ace
->ace_type
= GPFS_ACL_GROUP
;
1199 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.group
.gid
;
1201 case SMB_ACL_GROUP_OBJ
:
1202 g_ace
->ace_type
= GPFS_ACL_GROUP_OBJ
;
1206 g_ace
->ace_type
= GPFS_ACL_MASK
;
1207 g_ace
->ace_perm
= 0x8f;
1211 g_ace
->ace_type
= GPFS_ACL_OTHER
;
1215 DEBUG(10, ("Got invalid ace_type: %d\n", ace
->a_type
));
1221 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_READ
) ?
1223 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_WRITE
) ?
1225 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_EXECUTE
) ?
1226 ACL_PERM_EXECUTE
: 0;
1228 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
1229 g_ace
->ace_type
, g_ace
->ace_who
, g_ace
->ace_perm
));
1235 static int gpfsacl_sys_acl_set_file(vfs_handle_struct
*handle
,
1236 const struct smb_filename
*smb_fname
,
1237 SMB_ACL_TYPE_T type
,
1240 struct gpfs_acl
*gpfs_acl
;
1242 struct gpfs_config_data
*config
;
1244 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1245 struct gpfs_config_data
,
1249 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle
, smb_fname
,
1253 gpfs_acl
= smb2gpfs_acl(theacl
, type
);
1254 if (gpfs_acl
== NULL
) {
1258 result
= gpfswrap_putacl(discard_const_p(char, smb_fname
->base_name
),
1259 GPFS_PUTACL_STRUCT
|GPFS_ACL_SAMBA
, gpfs_acl
);
1261 SAFE_FREE(gpfs_acl
);
1265 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
1269 struct gpfs_config_data
*config
;
1271 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1272 struct gpfs_config_data
,
1276 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle
, fsp
, theacl
);
1279 return gpfsacl_sys_acl_set_file(handle
, fsp
->fsp_name
,
1280 SMB_ACL_TYPE_ACCESS
, theacl
);
1283 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
1284 const struct smb_filename
*smb_fname
)
1286 struct gpfs_config_data
*config
;
1288 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1289 struct gpfs_config_data
,
1293 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle
, smb_fname
);
1301 * Assumed: mode bits are shiftable and standard
1302 * Output: the new aceMask field for an smb nfs4 ace
1304 static uint32_t gpfsacl_mask_filter(uint32_t aceType
, uint32_t aceMask
, uint32_t rwx
)
1306 const uint32_t posix_nfs4map
[3] = {
1307 SMB_ACE4_EXECUTE
, /* execute */
1308 SMB_ACE4_WRITE_DATA
| SMB_ACE4_APPEND_DATA
, /* write; GPFS specific */
1309 SMB_ACE4_READ_DATA
/* read */
1312 uint32_t posix_mask
= 0x01;
1316 for(i
=0; i
<3; i
++) {
1317 nfs4_bits
= posix_nfs4map
[i
];
1318 posix_bit
= rwx
& posix_mask
;
1320 if (aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
) {
1322 aceMask
|= nfs4_bits
;
1324 aceMask
&= ~nfs4_bits
;
1326 /* add deny bits when suitable */
1328 aceMask
|= nfs4_bits
;
1330 aceMask
&= ~nfs4_bits
;
1331 } /* other ace types are unexpected */
1339 static int gpfsacl_emu_chmod(vfs_handle_struct
*handle
,
1340 const char *path
, mode_t mode
)
1342 struct SMB4ACL_T
*pacl
= NULL
;
1344 bool haveAllowEntry
[SMB_ACE4_WHO_EVERYONE
+ 1] = {False
, False
, False
, False
};
1346 files_struct fake_fsp
= { 0 }; /* TODO: rationalize parametrization */
1347 struct SMB4ACE_T
*smbace
;
1348 TALLOC_CTX
*frame
= talloc_stackframe();
1350 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path
, mode
));
1352 result
= gpfs_get_nfs4_acl(frame
, path
, &pacl
);
1358 if (mode
& ~(S_IRWXU
| S_IRWXG
| S_IRWXO
)) {
1359 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode
, path
));
1362 for (smbace
=smb_first_ace4(pacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
1363 SMB_ACE4PROP_T
*ace
= smb_get_ace4(smbace
);
1364 uint32_t specid
= ace
->who
.special_id
;
1366 if (ace
->flags
&SMB_ACE4_ID_SPECIAL
&&
1367 ace
->aceType
<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE
&&
1368 specid
<= SMB_ACE4_WHO_EVERYONE
) {
1372 if (ace
->aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
)
1373 haveAllowEntry
[specid
] = True
;
1375 /* mode >> 6 for @owner, mode >> 3 for @group,
1376 * mode >> 0 for @everyone */
1377 newMask
= gpfsacl_mask_filter(ace
->aceType
, ace
->aceMask
,
1378 mode
>> ((SMB_ACE4_WHO_EVERYONE
- specid
) * 3));
1379 if (ace
->aceMask
!=newMask
) {
1380 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
1381 path
, ace
->aceMask
, newMask
, specid
));
1383 ace
->aceMask
= newMask
;
1387 /* make sure we have at least ALLOW entries
1388 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
1391 for(i
= SMB_ACE4_WHO_OWNER
; i
<=SMB_ACE4_WHO_EVERYONE
; i
++) {
1392 SMB_ACE4PROP_T ace
= { 0 };
1394 if (haveAllowEntry
[i
]==True
)
1397 ace
.aceType
= SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
;
1398 ace
.flags
|= SMB_ACE4_ID_SPECIAL
;
1399 ace
.who
.special_id
= i
;
1401 if (i
==SMB_ACE4_WHO_GROUP
) /* not sure it's necessary... */
1402 ace
.aceFlags
|= SMB_ACE4_IDENTIFIER_GROUP
;
1404 ace
.aceMask
= gpfsacl_mask_filter(ace
.aceType
, ace
.aceMask
,
1405 mode
>> ((SMB_ACE4_WHO_EVERYONE
- i
) * 3));
1407 /* don't add unnecessary aces */
1411 /* we add it to the END - as windows expects allow aces */
1412 smb_add_ace4(pacl
, &ace
);
1413 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1414 path
, mode
, i
, ace
.aceMask
));
1417 /* don't add complementary DENY ACEs here */
1418 fake_fsp
.fsp_name
= synthetic_smb_fname(
1419 frame
, path
, NULL
, NULL
, 0);
1420 if (fake_fsp
.fsp_name
== NULL
) {
1426 if (gpfsacl_process_smbacl(handle
, &fake_fsp
, pacl
) == False
) {
1432 return 0; /* ok for [f]chmod */
1435 static int vfs_gpfs_chmod(vfs_handle_struct
*handle
,
1436 const struct smb_filename
*smb_fname
,
1439 struct smb_filename
*smb_fname_cpath
;
1442 smb_fname_cpath
= cp_smb_filename(talloc_tos(), smb_fname
);
1443 if (smb_fname_cpath
== NULL
) {
1448 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_cpath
) != 0) {
1449 TALLOC_FREE(smb_fname_cpath
);
1453 /* avoid chmod() if possible, to preserve acls */
1454 if ((smb_fname_cpath
->st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1455 TALLOC_FREE(smb_fname_cpath
);
1459 rc
= gpfsacl_emu_chmod(handle
, smb_fname
->base_name
, mode
);
1461 return SMB_VFS_NEXT_CHMOD(handle
, smb_fname
, mode
);
1463 TALLOC_FREE(smb_fname_cpath
);
1467 static int vfs_gpfs_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
1472 if (SMB_VFS_NEXT_FSTAT(handle
, fsp
, &st
) != 0) {
1476 /* avoid chmod() if possible, to preserve acls */
1477 if ((st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1481 rc
= gpfsacl_emu_chmod(handle
, fsp
->fsp_name
->base_name
,
1484 return SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
1488 static uint32_t vfs_gpfs_winattrs_to_dosmode(unsigned int winattrs
)
1490 uint32_t dosmode
= 0;
1492 if (winattrs
& GPFS_WINATTR_ARCHIVE
){
1493 dosmode
|= FILE_ATTRIBUTE_ARCHIVE
;
1495 if (winattrs
& GPFS_WINATTR_HIDDEN
){
1496 dosmode
|= FILE_ATTRIBUTE_HIDDEN
;
1498 if (winattrs
& GPFS_WINATTR_SYSTEM
){
1499 dosmode
|= FILE_ATTRIBUTE_SYSTEM
;
1501 if (winattrs
& GPFS_WINATTR_READONLY
){
1502 dosmode
|= FILE_ATTRIBUTE_READONLY
;
1504 if (winattrs
& GPFS_WINATTR_SPARSE_FILE
) {
1505 dosmode
|= FILE_ATTRIBUTE_SPARSE
;
1507 if (winattrs
& GPFS_WINATTR_OFFLINE
) {
1508 dosmode
|= FILE_ATTRIBUTE_OFFLINE
;
1514 static unsigned int vfs_gpfs_dosmode_to_winattrs(uint32_t dosmode
)
1516 unsigned int winattrs
= 0;
1518 if (dosmode
& FILE_ATTRIBUTE_ARCHIVE
){
1519 winattrs
|= GPFS_WINATTR_ARCHIVE
;
1521 if (dosmode
& FILE_ATTRIBUTE_HIDDEN
){
1522 winattrs
|= GPFS_WINATTR_HIDDEN
;
1524 if (dosmode
& FILE_ATTRIBUTE_SYSTEM
){
1525 winattrs
|= GPFS_WINATTR_SYSTEM
;
1527 if (dosmode
& FILE_ATTRIBUTE_READONLY
){
1528 winattrs
|= GPFS_WINATTR_READONLY
;
1530 if (dosmode
& FILE_ATTRIBUTE_SPARSE
) {
1531 winattrs
|= GPFS_WINATTR_SPARSE_FILE
;
1533 if (dosmode
& FILE_ATTRIBUTE_OFFLINE
) {
1534 winattrs
|= GPFS_WINATTR_OFFLINE
;
1540 static int get_dos_attr_with_capability(struct smb_filename
*smb_fname
,
1541 struct gpfs_winattr
*attr
)
1543 int saved_errno
= 0;
1547 * According to MS-FSA 2.1.5.1.2.1 "Algorithm to Check Access to an
1548 * Existing File" FILE_LIST_DIRECTORY on a directory implies
1549 * FILE_READ_ATTRIBUTES for directory entries. Being able to stat() a
1550 * file implies FILE_LIST_DIRECTORY for the directory containing the
1554 if (!VALID_STAT(smb_fname
->st
)) {
1556 * Safety net: dos_mode() already checks this, but as we set
1557 * DAC_OVERRIDE_CAPABILITY based on this, add an additional
1560 DBG_ERR("Rejecting DAC override, invalid stat [%s]\n",
1561 smb_fname_str_dbg(smb_fname
));
1566 set_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1568 ret
= gpfswrap_get_winattrs_path(smb_fname
->base_name
, attr
);
1570 saved_errno
= errno
;
1573 drop_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1575 if (saved_errno
!= 0) {
1576 errno
= saved_errno
;
1581 static NTSTATUS
vfs_gpfs_get_dos_attributes(struct vfs_handle_struct
*handle
,
1582 struct smb_filename
*smb_fname
,
1585 struct gpfs_config_data
*config
;
1586 struct gpfs_winattr attrs
= { };
1589 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1590 struct gpfs_config_data
,
1591 return NT_STATUS_INTERNAL_ERROR
);
1593 if (!config
->winattr
) {
1594 return SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle
,
1595 smb_fname
, dosmode
);
1598 ret
= gpfswrap_get_winattrs_path(smb_fname
->base_name
, &attrs
);
1599 if (ret
== -1 && errno
== ENOSYS
) {
1600 return SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle
, smb_fname
,
1603 if (ret
== -1 && errno
== EACCES
) {
1604 ret
= get_dos_attr_with_capability(smb_fname
, &attrs
);
1607 DBG_WARNING("Getting winattrs failed for %s: %s\n",
1608 smb_fname
->base_name
, strerror(errno
));
1609 return map_nt_error_from_unix(errno
);
1612 *dosmode
|= vfs_gpfs_winattrs_to_dosmode(attrs
.winAttrs
);
1613 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1614 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1615 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1617 return NT_STATUS_OK
;
1620 static NTSTATUS
vfs_gpfs_fget_dos_attributes(struct vfs_handle_struct
*handle
,
1621 struct files_struct
*fsp
,
1624 struct gpfs_config_data
*config
;
1625 struct gpfs_winattr attrs
= { };
1628 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1629 struct gpfs_config_data
,
1630 return NT_STATUS_INTERNAL_ERROR
);
1632 if (!config
->winattr
) {
1633 return SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle
, fsp
, dosmode
);
1636 ret
= gpfswrap_get_winattrs(fsp
->fh
->fd
, &attrs
);
1637 if (ret
== -1 && errno
== ENOSYS
) {
1638 return SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle
, fsp
, dosmode
);
1641 if (ret
== -1 && errno
== EACCES
) {
1642 int saved_errno
= 0;
1645 * According to MS-FSA 2.1.5.1.2.1 "Algorithm to Check Access to
1646 * an Existing File" FILE_LIST_DIRECTORY on a directory implies
1647 * FILE_READ_ATTRIBUTES for directory entries. Being able to
1648 * open a file implies FILE_LIST_DIRECTORY.
1651 set_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1653 ret
= gpfswrap_get_winattrs(fsp
->fh
->fd
, &attrs
);
1655 saved_errno
= errno
;
1658 drop_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1660 if (saved_errno
!= 0) {
1661 errno
= saved_errno
;
1666 DBG_WARNING("Getting winattrs failed for %s: %s\n",
1667 fsp
->fsp_name
->base_name
, strerror(errno
));
1668 return map_nt_error_from_unix(errno
);
1671 *dosmode
|= vfs_gpfs_winattrs_to_dosmode(attrs
.winAttrs
);
1672 fsp
->fsp_name
->st
.st_ex_calculated_birthtime
= false;
1673 fsp
->fsp_name
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1674 fsp
->fsp_name
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1676 return NT_STATUS_OK
;
1679 static NTSTATUS
vfs_gpfs_set_dos_attributes(struct vfs_handle_struct
*handle
,
1680 const struct smb_filename
*smb_fname
,
1683 struct gpfs_config_data
*config
;
1684 struct gpfs_winattr attrs
= { };
1687 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1688 struct gpfs_config_data
,
1689 return NT_STATUS_INTERNAL_ERROR
);
1691 if (!config
->winattr
) {
1692 return SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle
,
1693 smb_fname
, dosmode
);
1696 attrs
.winAttrs
= vfs_gpfs_dosmode_to_winattrs(dosmode
);
1697 ret
= gpfswrap_set_winattrs_path(smb_fname
->base_name
,
1698 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1700 if (ret
== -1 && errno
== ENOSYS
) {
1701 return SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle
,
1702 smb_fname
, dosmode
);
1706 DBG_WARNING("Setting winattrs failed for %s: %s\n",
1707 smb_fname
->base_name
, strerror(errno
));
1708 return map_nt_error_from_unix(errno
);
1711 return NT_STATUS_OK
;
1714 static NTSTATUS
vfs_gpfs_fset_dos_attributes(struct vfs_handle_struct
*handle
,
1715 struct files_struct
*fsp
,
1718 struct gpfs_config_data
*config
;
1719 struct gpfs_winattr attrs
= { };
1722 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1723 struct gpfs_config_data
,
1724 return NT_STATUS_INTERNAL_ERROR
);
1726 if (!config
->winattr
) {
1727 return SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle
, fsp
, dosmode
);
1730 attrs
.winAttrs
= vfs_gpfs_dosmode_to_winattrs(dosmode
);
1731 ret
= gpfswrap_set_winattrs(fsp
->fh
->fd
,
1732 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1734 if (ret
== -1 && errno
== ENOSYS
) {
1735 return SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle
, fsp
, dosmode
);
1739 DBG_WARNING("Setting winattrs failed for %s: %s\n",
1740 fsp
->fsp_name
->base_name
, strerror(errno
));
1741 return map_nt_error_from_unix(errno
);
1744 return NT_STATUS_OK
;
1747 static int stat_with_capability(struct vfs_handle_struct
*handle
,
1748 struct smb_filename
*smb_fname
, int flag
)
1750 #if defined(HAVE_FSTATAT)
1754 const char *rel_name
= NULL
;
1758 b
= parent_dirname(talloc_tos(), smb_fname
->base_name
,
1759 &dir_name
, &rel_name
);
1765 fd
= open(dir_name
, O_RDONLY
, 0);
1766 TALLOC_FREE(dir_name
);
1771 set_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1772 ret
= fstatat(fd
, rel_name
, &st
, flag
);
1773 drop_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1778 init_stat_ex_from_stat(
1779 &smb_fname
->st
, &st
,
1780 lp_fake_directory_create_times(SNUM(handle
->conn
)));
1789 static int vfs_gpfs_stat(struct vfs_handle_struct
*handle
,
1790 struct smb_filename
*smb_fname
)
1793 struct gpfs_config_data
*config
;
1795 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1796 struct gpfs_config_data
,
1799 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
1800 if (ret
== -1 && errno
== EACCES
) {
1801 DEBUG(10, ("Trying stat with capability for %s\n",
1802 smb_fname
->base_name
));
1803 ret
= stat_with_capability(handle
, smb_fname
, 0);
1808 static int vfs_gpfs_lstat(struct vfs_handle_struct
*handle
,
1809 struct smb_filename
*smb_fname
)
1812 struct gpfs_config_data
*config
;
1814 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1815 struct gpfs_config_data
,
1818 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
1819 if (ret
== -1 && errno
== EACCES
) {
1820 DEBUG(10, ("Trying lstat with capability for %s\n",
1821 smb_fname
->base_name
));
1822 ret
= stat_with_capability(handle
, smb_fname
,
1823 AT_SYMLINK_NOFOLLOW
);
1828 static void timespec_to_gpfs_time(struct timespec ts
, gpfs_timestruc_t
*gt
,
1829 int idx
, int *flags
)
1831 if (!null_timespec(ts
)) {
1833 gt
[idx
].tv_sec
= ts
.tv_sec
;
1834 gt
[idx
].tv_nsec
= ts
.tv_nsec
;
1835 DEBUG(10, ("Setting GPFS time %d, flags 0x%x\n", idx
, *flags
));
1839 static int smbd_gpfs_set_times_path(char *path
, struct smb_file_time
*ft
)
1841 gpfs_timestruc_t gpfs_times
[4];
1845 ZERO_ARRAY(gpfs_times
);
1846 timespec_to_gpfs_time(ft
->atime
, gpfs_times
, 0, &flags
);
1847 timespec_to_gpfs_time(ft
->mtime
, gpfs_times
, 1, &flags
);
1848 /* No good mapping from LastChangeTime to ctime, not storing */
1849 timespec_to_gpfs_time(ft
->create_time
, gpfs_times
, 3, &flags
);
1852 DEBUG(10, ("nothing to do, return to avoid EINVAL\n"));
1856 rc
= gpfswrap_set_times_path(path
, flags
, gpfs_times
);
1858 if (rc
!= 0 && errno
!= ENOSYS
) {
1859 DEBUG(1,("gpfs_set_times() returned with error %s\n",
1866 static int vfs_gpfs_ntimes(struct vfs_handle_struct
*handle
,
1867 const struct smb_filename
*smb_fname
,
1868 struct smb_file_time
*ft
)
1871 struct gpfs_winattr attrs
;
1875 struct gpfs_config_data
*config
;
1877 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1878 struct gpfs_config_data
,
1881 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1882 if (!NT_STATUS_IS_OK(status
)) {
1883 errno
= map_errno_from_nt_status(status
);
1887 /* Try to use gpfs_set_times if it is enabled and available */
1888 if (config
->settimes
) {
1889 ret
= smbd_gpfs_set_times_path(path
, ft
);
1891 if (ret
== 0 || (ret
== -1 && errno
!= ENOSYS
)) {
1896 DEBUG(10,("gpfs_set_times() not available or disabled, "
1897 "use ntimes and winattr\n"));
1899 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1901 /* don't complain if access was denied */
1902 if (errno
!= EPERM
&& errno
!= EACCES
) {
1903 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1904 "%s", strerror(errno
)));
1909 if(null_timespec(ft
->create_time
)){
1910 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1914 if (!config
->winattr
) {
1919 attrs
.creationTime
.tv_sec
= ft
->create_time
.tv_sec
;
1920 attrs
.creationTime
.tv_nsec
= ft
->create_time
.tv_nsec
;
1922 ret
= gpfswrap_set_winattrs_path(discard_const_p(char, path
),
1923 GPFS_WINATTR_SET_CREATION_TIME
,
1925 if(ret
== -1 && errno
!= ENOSYS
){
1926 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret
));
1933 static int vfs_gpfs_fallocate(struct vfs_handle_struct
*handle
,
1934 struct files_struct
*fsp
, uint32_t mode
,
1935 off_t offset
, off_t len
)
1938 struct gpfs_config_data
*config
;
1940 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1941 struct gpfs_config_data
,
1944 if (!config
->prealloc
) {
1945 /* you should better not run fallocate() on GPFS at all */
1951 DEBUG(10, ("unmapped fallocate flags: %lx\n",
1952 (unsigned long)mode
));
1957 ret
= gpfswrap_prealloc(fsp
->fh
->fd
, offset
, len
);
1959 if (ret
== -1 && errno
!= ENOSYS
) {
1960 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno
)));
1961 } else if (ret
== -1 && errno
== ENOSYS
) {
1962 DEBUG(10, ("GPFS prealloc not supported.\n"));
1964 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1970 static int vfs_gpfs_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1974 struct gpfs_config_data
*config
;
1976 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1977 struct gpfs_config_data
,
1980 if (!config
->ftruncate
) {
1981 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1984 result
= gpfswrap_ftruncate(fsp
->fh
->fd
, len
);
1985 if ((result
== -1) && (errno
== ENOSYS
)) {
1986 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1991 static bool vfs_gpfs_is_offline(struct vfs_handle_struct
*handle
,
1992 const struct smb_filename
*fname
,
1993 SMB_STRUCT_STAT
*sbuf
)
1995 struct gpfs_winattr attrs
;
1998 struct gpfs_config_data
*config
;
2001 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2002 struct gpfs_config_data
,
2005 if (!config
->winattr
) {
2009 status
= get_full_smb_filename(talloc_tos(), fname
, &path
);
2010 if (!NT_STATUS_IS_OK(status
)) {
2014 ret
= gpfswrap_get_winattrs_path(path
, &attrs
);
2020 if ((attrs
.winAttrs
& GPFS_WINATTR_OFFLINE
) != 0) {
2021 DEBUG(10, ("%s is offline\n", path
));
2025 DEBUG(10, ("%s is online\n", path
));
2030 static bool vfs_gpfs_fsp_is_offline(struct vfs_handle_struct
*handle
,
2031 struct files_struct
*fsp
)
2033 struct gpfs_fsp_extension
*ext
;
2035 ext
= VFS_FETCH_FSP_EXTENSION(handle
, fsp
);
2038 * Something bad happened, always ask.
2040 return vfs_gpfs_is_offline(handle
, fsp
->fsp_name
,
2041 &fsp
->fsp_name
->st
);
2046 * As long as it's offline, ask.
2048 ext
->offline
= vfs_gpfs_is_offline(handle
, fsp
->fsp_name
,
2049 &fsp
->fsp_name
->st
);
2052 return ext
->offline
;
2055 static bool vfs_gpfs_aio_force(struct vfs_handle_struct
*handle
,
2056 struct files_struct
*fsp
)
2058 return vfs_gpfs_fsp_is_offline(handle
, fsp
);
2061 static ssize_t
vfs_gpfs_sendfile(vfs_handle_struct
*handle
, int tofd
,
2062 files_struct
*fsp
, const DATA_BLOB
*hdr
,
2063 off_t offset
, size_t n
)
2065 if (vfs_gpfs_fsp_is_offline(handle
, fsp
)) {
2069 return SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fsp
, hdr
, offset
, n
);
2072 static int vfs_gpfs_connect(struct vfs_handle_struct
*handle
,
2073 const char *service
, const char *user
)
2075 struct gpfs_config_data
*config
;
2078 gpfswrap_lib_init(0);
2080 config
= talloc_zero(handle
->conn
, struct gpfs_config_data
);
2082 DEBUG(0, ("talloc_zero() failed\n"));
2087 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
2089 TALLOC_FREE(config
);
2093 ret
= smbacl4_get_vfs_params(handle
->conn
, &config
->nfs4_params
);
2095 TALLOC_FREE(config
);
2099 config
->sharemodes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2100 "sharemodes", true);
2102 config
->leases
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2105 config
->hsm
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2108 config
->syncio
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2111 config
->winattr
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2114 config
->ftruncate
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2117 config
->getrealfilename
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2118 "getrealfilename", true);
2120 config
->dfreequota
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2121 "dfreequota", false);
2123 config
->prealloc
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2126 config
->acl
= lp_parm_bool(SNUM(handle
->conn
), "gpfs", "acl", true);
2128 config
->settimes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2130 config
->recalls
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2133 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
2134 NULL
, struct gpfs_config_data
,
2137 if (config
->leases
) {
2139 * GPFS lease code is based on kernel oplock code
2140 * so make sure it is turned on
2142 if (!lp_kernel_oplocks(SNUM(handle
->conn
))) {
2143 DEBUG(5, ("Enabling kernel oplocks for "
2144 "gpfs:leases to work\n"));
2145 lp_do_parameter(SNUM(handle
->conn
), "kernel oplocks",
2150 * as the kernel does not properly support Level II oplocks
2151 * and GPFS leases code is based on kernel infrastructure, we
2152 * need to turn off Level II oplocks if gpfs:leases is enabled
2154 if (lp_level2_oplocks(SNUM(handle
->conn
))) {
2155 DEBUG(5, ("gpfs:leases are enabled, disabling "
2156 "Level II oplocks\n"));
2157 lp_do_parameter(SNUM(handle
->conn
), "level2 oplocks",
2165 static int get_gpfs_quota(const char *pathname
, int type
, int id
,
2166 struct gpfs_quotaInfo
*qi
)
2170 ret
= gpfswrap_quotactl(discard_const_p(char, pathname
),
2171 GPFS_QCMD(Q_GETQUOTA
, type
), id
, qi
);
2174 if (errno
== GPFS_E_NO_QUOTA_INST
) {
2175 DEBUG(10, ("Quotas disabled on GPFS filesystem.\n"));
2176 } else if (errno
!= ENOSYS
) {
2177 DEBUG(0, ("Get quota failed, type %d, id, %d, "
2178 "errno %d.\n", type
, id
, errno
));
2184 DEBUG(10, ("quota type %d, id %d, blk u:%lld h:%lld s:%lld gt:%u\n",
2185 type
, id
, qi
->blockUsage
, qi
->blockHardLimit
,
2186 qi
->blockSoftLimit
, qi
->blockGraceTime
));
2191 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi
, time_t cur_time
,
2192 uint64_t *dfree
, uint64_t *dsize
)
2194 uint64_t usage
, limit
;
2197 * The quota reporting is done in units of 1024 byte blocks, but
2198 * sys_fsusage uses units of 512 byte blocks, adjust the block number
2199 * accordingly. Also filter possibly negative usage counts from gpfs.
2201 usage
= qi
.blockUsage
< 0 ? 0 : (uint64_t)qi
.blockUsage
* 2;
2202 limit
= (uint64_t)qi
.blockHardLimit
* 2;
2205 * When the grace time for the exceeded soft block quota has been
2206 * exceeded, the soft block quota becomes an additional hard limit.
2208 if (qi
.blockSoftLimit
&&
2209 qi
.blockGraceTime
&& cur_time
> qi
.blockGraceTime
) {
2210 /* report disk as full */
2212 *dsize
= MIN(*dsize
, usage
);
2215 if (!qi
.blockHardLimit
)
2218 if (usage
>= limit
) {
2219 /* report disk as full */
2221 *dsize
= MIN(*dsize
, usage
);
2224 /* limit has not been reached, determine "free space" */
2225 *dfree
= MIN(*dfree
, limit
- usage
);
2226 *dsize
= MIN(*dsize
, limit
);
2230 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct
*handle
,
2231 const struct smb_filename
*smb_fname
,
2236 struct security_unix_token
*utok
;
2237 struct gpfs_quotaInfo qi_user
= { 0 }, qi_group
= { 0 };
2238 struct gpfs_config_data
*config
;
2242 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct gpfs_config_data
,
2243 return (uint64_t)-1);
2244 if (!config
->dfreequota
) {
2245 return SMB_VFS_NEXT_DISK_FREE(handle
, smb_fname
,
2246 bsize
, dfree
, dsize
);
2249 err
= sys_fsusage(smb_fname
->base_name
, dfree
, dsize
);
2251 DEBUG (0, ("Could not get fs usage, errno %d\n", errno
));
2252 return SMB_VFS_NEXT_DISK_FREE(handle
, smb_fname
,
2253 bsize
, dfree
, dsize
);
2256 /* sys_fsusage returns units of 512 bytes */
2259 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
2260 (unsigned long long)*dfree
, (unsigned long long)*dsize
));
2262 utok
= handle
->conn
->session_info
->unix_token
;
2264 err
= get_gpfs_quota(smb_fname
->base_name
,
2265 GPFS_USRQUOTA
, utok
->uid
, &qi_user
);
2267 return SMB_VFS_NEXT_DISK_FREE(handle
, smb_fname
,
2268 bsize
, dfree
, dsize
);
2271 err
= get_gpfs_quota(smb_fname
->base_name
,
2272 GPFS_GRPQUOTA
, utok
->gid
, &qi_group
);
2274 return SMB_VFS_NEXT_DISK_FREE(handle
, smb_fname
,
2275 bsize
, dfree
, dsize
);
2278 cur_time
= time(NULL
);
2280 /* Adjust free space and size according to quota limits. */
2281 vfs_gpfs_disk_free_quota(qi_user
, cur_time
, dfree
, dsize
);
2282 vfs_gpfs_disk_free_quota(qi_group
, cur_time
, dfree
, dsize
);
2287 static int vfs_gpfs_get_quota(vfs_handle_struct
*handle
,
2288 const struct smb_filename
*smb_fname
,
2289 enum SMB_QUOTA_TYPE qtype
,
2295 * User/group quota are being used for disk-free
2296 * determination, which in this module is done directly
2297 * by the disk-free function. It's important that this
2298 * module does not return wrong quota values by mistake,
2299 * which would modify the correct values set by disk-free.
2300 * User/group quota are also being used for processing
2301 * NT_TRANSACT_GET_USER_QUOTA in smb1 protocol, which is
2302 * currently not supported by this module.
2304 case SMB_USER_QUOTA_TYPE
:
2305 case SMB_GROUP_QUOTA_TYPE
:
2309 return SMB_VFS_NEXT_GET_QUOTA(handle
, smb_fname
,
2314 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct
*handle
,
2315 enum timestamp_set_resolution
*p_ts_res
)
2317 struct gpfs_config_data
*config
;
2320 next
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
2322 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2323 struct gpfs_config_data
,
2327 next
|= FILE_SUPPORTS_REMOTE_STORAGE
;
2332 static int vfs_gpfs_open(struct vfs_handle_struct
*handle
,
2333 struct smb_filename
*smb_fname
, files_struct
*fsp
,
2334 int flags
, mode_t mode
)
2336 struct gpfs_config_data
*config
;
2338 struct gpfs_fsp_extension
*ext
;
2340 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2341 struct gpfs_config_data
,
2344 if (config
->hsm
&& !config
->recalls
&&
2345 vfs_gpfs_fsp_is_offline(handle
, fsp
)) {
2346 DEBUG(10, ("Refusing access to offline file %s\n",
2352 if (config
->syncio
) {
2356 ext
= VFS_ADD_FSP_EXTENSION(handle
, fsp
, struct gpfs_fsp_extension
,
2364 * Assume the file is offline until gpfs tells us it's online.
2366 *ext
= (struct gpfs_fsp_extension
) { .offline
= true };
2368 ret
= SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
2370 VFS_REMOVE_FSP_EXTENSION(handle
, fsp
);
2375 static ssize_t
vfs_gpfs_pread(vfs_handle_struct
*handle
, files_struct
*fsp
,
2376 void *data
, size_t n
, off_t offset
)
2381 was_offline
= vfs_gpfs_fsp_is_offline(handle
, fsp
);
2383 ret
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
2385 if ((ret
!= -1) && was_offline
) {
2386 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2387 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2388 fsp
->fsp_name
->base_name
);
2394 struct vfs_gpfs_pread_state
{
2395 struct files_struct
*fsp
;
2398 struct vfs_aio_state vfs_aio_state
;
2401 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
);
2403 static struct tevent_req
*vfs_gpfs_pread_send(struct vfs_handle_struct
*handle
,
2404 TALLOC_CTX
*mem_ctx
,
2405 struct tevent_context
*ev
,
2406 struct files_struct
*fsp
,
2407 void *data
, size_t n
,
2410 struct tevent_req
*req
, *subreq
;
2411 struct vfs_gpfs_pread_state
*state
;
2413 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pread_state
);
2417 state
->was_offline
= vfs_gpfs_fsp_is_offline(handle
, fsp
);
2419 subreq
= SMB_VFS_NEXT_PREAD_SEND(state
, ev
, handle
, fsp
, data
,
2421 if (tevent_req_nomem(subreq
, req
)) {
2422 return tevent_req_post(req
, ev
);
2424 tevent_req_set_callback(subreq
, vfs_gpfs_pread_done
, req
);
2428 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
)
2430 struct tevent_req
*req
= tevent_req_callback_data(
2431 subreq
, struct tevent_req
);
2432 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2433 req
, struct vfs_gpfs_pread_state
);
2435 state
->ret
= SMB_VFS_PREAD_RECV(subreq
, &state
->vfs_aio_state
);
2436 TALLOC_FREE(subreq
);
2437 tevent_req_done(req
);
2440 static ssize_t
vfs_gpfs_pread_recv(struct tevent_req
*req
,
2441 struct vfs_aio_state
*vfs_aio_state
)
2443 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2444 req
, struct vfs_gpfs_pread_state
);
2445 struct files_struct
*fsp
= state
->fsp
;
2447 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
2450 *vfs_aio_state
= state
->vfs_aio_state
;
2452 if ((state
->ret
!= -1) && state
->was_offline
) {
2453 DEBUG(10, ("sending notify\n"));
2454 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2455 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2456 fsp
->fsp_name
->base_name
);
2462 static ssize_t
vfs_gpfs_pwrite(vfs_handle_struct
*handle
, files_struct
*fsp
,
2463 const void *data
, size_t n
, off_t offset
)
2468 was_offline
= vfs_gpfs_fsp_is_offline(handle
, fsp
);
2470 ret
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
2472 if ((ret
!= -1) && was_offline
) {
2473 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2474 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2475 fsp
->fsp_name
->base_name
);
2481 struct vfs_gpfs_pwrite_state
{
2482 struct files_struct
*fsp
;
2485 struct vfs_aio_state vfs_aio_state
;
2488 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
);
2490 static struct tevent_req
*vfs_gpfs_pwrite_send(
2491 struct vfs_handle_struct
*handle
,
2492 TALLOC_CTX
*mem_ctx
,
2493 struct tevent_context
*ev
,
2494 struct files_struct
*fsp
,
2495 const void *data
, size_t n
,
2498 struct tevent_req
*req
, *subreq
;
2499 struct vfs_gpfs_pwrite_state
*state
;
2501 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pwrite_state
);
2505 state
->was_offline
= vfs_gpfs_fsp_is_offline(handle
, fsp
);
2507 subreq
= SMB_VFS_NEXT_PWRITE_SEND(state
, ev
, handle
, fsp
, data
,
2509 if (tevent_req_nomem(subreq
, req
)) {
2510 return tevent_req_post(req
, ev
);
2512 tevent_req_set_callback(subreq
, vfs_gpfs_pwrite_done
, req
);
2516 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
)
2518 struct tevent_req
*req
= tevent_req_callback_data(
2519 subreq
, struct tevent_req
);
2520 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2521 req
, struct vfs_gpfs_pwrite_state
);
2523 state
->ret
= SMB_VFS_PWRITE_RECV(subreq
, &state
->vfs_aio_state
);
2524 TALLOC_FREE(subreq
);
2525 tevent_req_done(req
);
2528 static ssize_t
vfs_gpfs_pwrite_recv(struct tevent_req
*req
,
2529 struct vfs_aio_state
*vfs_aio_state
)
2531 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2532 req
, struct vfs_gpfs_pwrite_state
);
2533 struct files_struct
*fsp
= state
->fsp
;
2535 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
2538 *vfs_aio_state
= state
->vfs_aio_state
;
2540 if ((state
->ret
!= -1) && state
->was_offline
) {
2541 DEBUG(10, ("sending notify\n"));
2542 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2543 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2544 fsp
->fsp_name
->base_name
);
2551 static struct vfs_fn_pointers vfs_gpfs_fns
= {
2552 .connect_fn
= vfs_gpfs_connect
,
2553 .disk_free_fn
= vfs_gpfs_disk_free
,
2554 .get_quota_fn
= vfs_gpfs_get_quota
,
2555 .fs_capabilities_fn
= vfs_gpfs_capabilities
,
2556 .kernel_flock_fn
= vfs_gpfs_kernel_flock
,
2557 .linux_setlease_fn
= vfs_gpfs_setlease
,
2558 .get_real_filename_fn
= vfs_gpfs_get_real_filename
,
2559 .get_dos_attributes_fn
= vfs_gpfs_get_dos_attributes
,
2560 .fget_dos_attributes_fn
= vfs_gpfs_fget_dos_attributes
,
2561 .set_dos_attributes_fn
= vfs_gpfs_set_dos_attributes
,
2562 .fset_dos_attributes_fn
= vfs_gpfs_fset_dos_attributes
,
2563 .fget_nt_acl_fn
= gpfsacl_fget_nt_acl
,
2564 .get_nt_acl_fn
= gpfsacl_get_nt_acl
,
2565 .fset_nt_acl_fn
= gpfsacl_fset_nt_acl
,
2566 .sys_acl_get_file_fn
= gpfsacl_sys_acl_get_file
,
2567 .sys_acl_get_fd_fn
= gpfsacl_sys_acl_get_fd
,
2568 .sys_acl_blob_get_file_fn
= gpfsacl_sys_acl_blob_get_file
,
2569 .sys_acl_blob_get_fd_fn
= gpfsacl_sys_acl_blob_get_fd
,
2570 .sys_acl_set_file_fn
= gpfsacl_sys_acl_set_file
,
2571 .sys_acl_set_fd_fn
= gpfsacl_sys_acl_set_fd
,
2572 .sys_acl_delete_def_file_fn
= gpfsacl_sys_acl_delete_def_file
,
2573 .chmod_fn
= vfs_gpfs_chmod
,
2574 .fchmod_fn
= vfs_gpfs_fchmod
,
2575 .close_fn
= vfs_gpfs_close
,
2576 .stat_fn
= vfs_gpfs_stat
,
2577 .lstat_fn
= vfs_gpfs_lstat
,
2578 .ntimes_fn
= vfs_gpfs_ntimes
,
2579 .aio_force_fn
= vfs_gpfs_aio_force
,
2580 .sendfile_fn
= vfs_gpfs_sendfile
,
2581 .fallocate_fn
= vfs_gpfs_fallocate
,
2582 .open_fn
= vfs_gpfs_open
,
2583 .pread_fn
= vfs_gpfs_pread
,
2584 .pread_send_fn
= vfs_gpfs_pread_send
,
2585 .pread_recv_fn
= vfs_gpfs_pread_recv
,
2586 .pwrite_fn
= vfs_gpfs_pwrite
,
2587 .pwrite_send_fn
= vfs_gpfs_pwrite_send
,
2588 .pwrite_recv_fn
= vfs_gpfs_pwrite_recv
,
2589 .ftruncate_fn
= vfs_gpfs_ftruncate
2592 NTSTATUS
vfs_gpfs_init(TALLOC_CTX
*);
2593 NTSTATUS
vfs_gpfs_init(TALLOC_CTX
*ctx
)
2597 ret
= gpfswrap_init();
2599 DEBUG(1, ("Could not initialize GPFS library wrapper\n"));
2602 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "gpfs",