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 "librpc/gen_ndr/ndr_xattr.h"
26 #include "include/smbprofile.h"
27 #include "modules/non_posix_acls.h"
28 #include "libcli/security/security.h"
29 #include "nfs4_acls.h"
30 #include "system/filesys.h"
32 #include "lib/util/tevent_unix.h"
33 #include "lib/util/gpfswrap.h"
36 #define DBGC_CLASS DBGC_VFS
38 #ifndef GPFS_GETACL_NATIVE
39 #define GPFS_GETACL_NATIVE 0x00000004
42 struct gpfs_config_data
{
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
|
90 DELETE_ACCESS
)) ? GPFS_SHARE_WRITE
: 0;
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
));
363 * get the ACL from GPFS, allocated on the specified mem_ctx
364 * internally retries when initial buffer was too small
366 * caller needs to cast result to either
367 * raw = yes: struct gpfs_opaque_acl
368 * raw = no: struct gpfs_acl
371 static void *vfs_gpfs_getacl(TALLOC_CTX
*mem_ctx
,
374 const gpfs_aclType_t type
)
385 aclbuf
= talloc_zero_size(mem_ctx
, size
);
386 if (aclbuf
== NULL
) {
392 struct gpfs_opaque_acl
*buf
= (struct gpfs_opaque_acl
*) aclbuf
;
393 buf
->acl_type
= type
;
394 flags
= GPFS_GETACL_NATIVE
;
395 len
= (unsigned int *) &(buf
->acl_buffer_len
);
396 struct_size
= sizeof(struct gpfs_opaque_acl
);
398 struct gpfs_acl
*buf
= (struct gpfs_acl
*) aclbuf
;
399 buf
->acl_type
= type
;
400 buf
->acl_level
= GPFS_ACL_LEVEL_V4FLAGS
;
401 flags
= GPFS_GETACL_STRUCT
;
402 len
= &(buf
->acl_len
);
403 /* reserve space for control flags in gpfs 3.5 and beyond */
404 struct_size
= sizeof(struct gpfs_acl
) + sizeof(unsigned int);
407 /* set the length of the buffer as input value */
411 ret
= gpfswrap_getacl(discard_const_p(char, fname
), flags
, aclbuf
);
412 if ((ret
!= 0) && (errno
== ENOSPC
)) {
414 * get the size needed to accommodate the complete buffer
416 * the value returned only applies to the ACL blob in the
417 * struct so make sure to also have headroom for the first
418 * struct members by adding room for the complete struct
419 * (might be a few bytes too much then)
421 size
= *len
+ struct_size
;
423 DEBUG(10, ("Increasing ACL buffer size to %zu\n", size
));
428 DEBUG(5, ("smbd_gpfs_getacl failed with %s\n",
437 /* Tries to get nfs4 acls and returns SMB ACL allocated.
438 * On failure returns 1 if it got non-NFSv4 ACL to prompt
439 * retry with POSIX ACL checks.
440 * On failure returns -1 if there is system (GPFS) error, check errno.
441 * Returns 0 on success
443 static int gpfs_get_nfs4_acl(TALLOC_CTX
*mem_ctx
, const char *fname
,
444 struct SMB4ACL_T
**ppacl
)
447 struct gpfs_acl
*gacl
= NULL
;
448 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname
));
451 gacl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(), fname
,
454 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
455 fname
, strerror(errno
)));
456 if (errno
== ENODATA
) {
458 * GPFS returns ENODATA for snapshot
459 * directories. Retry with POSIX ACLs check.
467 if (gacl
->acl_type
!= GPFS_ACL_TYPE_NFS4
) {
468 DEBUG(10, ("Got non-nfsv4 acl\n"));
469 /* Retry with POSIX ACLs check */
474 *ppacl
= smb_create_smb4acl(mem_ctx
);
476 if (gacl
->acl_level
== GPFS_ACL_LEVEL_V4FLAGS
) {
477 uint16_t control
= gpfs2sd_control(gpfs_acl_flags(gacl
));
478 smbacl4_set_controlflags(*ppacl
, control
);
481 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d, control: %x\n",
482 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
483 gacl
->acl_nace
, gpfs_acl_flags(gacl
)));
485 for (i
=0; i
<gacl
->acl_nace
; i
++) {
486 struct gpfs_ace_v4
*gace
= gpfs_ace_ptr(gacl
, i
);
487 SMB_ACE4PROP_T smbace
= { 0 };
488 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
489 "who: %d\n", gace
->aceType
, gace
->aceIFlags
,
490 gace
->aceFlags
, gace
->aceMask
, gace
->aceWho
));
492 if (gace
->aceIFlags
& ACE4_IFLAG_SPECIAL_ID
) {
493 smbace
.flags
|= SMB_ACE4_ID_SPECIAL
;
494 switch (gace
->aceWho
) {
495 case ACE4_SPECIAL_OWNER
:
496 smbace
.who
.special_id
= SMB_ACE4_WHO_OWNER
;
498 case ACE4_SPECIAL_GROUP
:
499 smbace
.who
.special_id
= SMB_ACE4_WHO_GROUP
;
501 case ACE4_SPECIAL_EVERYONE
:
502 smbace
.who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
505 DEBUG(8, ("invalid special gpfs id %d "
506 "ignored\n", gace
->aceWho
));
507 continue; /* don't add it */
510 if (gace
->aceFlags
& ACE4_FLAG_GROUP_ID
)
511 smbace
.who
.gid
= gace
->aceWho
;
513 smbace
.who
.uid
= gace
->aceWho
;
516 /* remove redundant deny entries */
517 if (i
> 0 && gace
->aceType
== SMB_ACE4_ACCESS_DENIED_ACE_TYPE
) {
518 struct gpfs_ace_v4
*prev
= gpfs_ace_ptr(gacl
, i
- 1);
519 if (prev
->aceType
== SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
&&
520 prev
->aceFlags
== gace
->aceFlags
&&
521 prev
->aceIFlags
== gace
->aceIFlags
&&
522 (gace
->aceMask
& prev
->aceMask
) == 0 &&
523 gace
->aceWho
== prev
->aceWho
) {
524 /* it's redundant - skip it */
529 smbace
.aceType
= gace
->aceType
;
530 smbace
.aceFlags
= gace
->aceFlags
;
531 smbace
.aceMask
= gace
->aceMask
;
532 smb_add_ace4(*ppacl
, &smbace
);
540 static NTSTATUS
gpfsacl_fget_nt_acl(vfs_handle_struct
*handle
,
541 files_struct
*fsp
, uint32_t security_info
,
543 struct security_descriptor
**ppdesc
)
545 struct SMB4ACL_T
*pacl
= NULL
;
547 struct gpfs_config_data
*config
;
548 TALLOC_CTX
*frame
= talloc_stackframe();
553 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
554 struct gpfs_config_data
,
555 return NT_STATUS_INTERNAL_ERROR
);
558 status
= SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
564 result
= gpfs_get_nfs4_acl(frame
, fsp
->fsp_name
->base_name
, &pacl
);
567 status
= smb_fget_nt_acl_nfs4(fsp
, security_info
, mem_ctx
,
574 DEBUG(10, ("retrying with posix acl...\n"));
575 status
= posix_fget_nt_acl(fsp
, security_info
,
583 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
584 return map_nt_error_from_unix(errno
);
587 static NTSTATUS
gpfsacl_get_nt_acl(vfs_handle_struct
*handle
,
589 uint32_t security_info
,
590 TALLOC_CTX
*mem_ctx
, struct security_descriptor
**ppdesc
)
592 struct SMB4ACL_T
*pacl
= NULL
;
594 struct gpfs_config_data
*config
;
595 TALLOC_CTX
*frame
= talloc_stackframe();
600 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
601 struct gpfs_config_data
,
602 return NT_STATUS_INTERNAL_ERROR
);
605 status
= SMB_VFS_NEXT_GET_NT_ACL(handle
, name
, security_info
,
611 result
= gpfs_get_nfs4_acl(frame
, name
, &pacl
);
614 status
= smb_get_nt_acl_nfs4(handle
->conn
, name
, security_info
,
615 mem_ctx
, ppdesc
, pacl
);
621 DEBUG(10, ("retrying with posix acl...\n"));
622 status
= posix_get_nt_acl(handle
->conn
, name
, security_info
,
628 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
630 return map_nt_error_from_unix(errno
);
633 static struct gpfs_acl
*vfs_gpfs_smbacl2gpfsacl(TALLOC_CTX
*mem_ctx
,
635 struct SMB4ACL_T
*smbacl
,
638 struct gpfs_acl
*gacl
;
639 gpfs_aclLen_t gacl_len
;
640 struct SMB4ACE_T
*smbace
;
642 gacl_len
= offsetof(gpfs_acl_t
, ace_v4
) + sizeof(unsigned int)
643 + smb_get_naces(smbacl
) * sizeof(gpfs_ace_v4_t
);
645 gacl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, gacl_len
);
647 DEBUG(0, ("talloc failed\n"));
652 gacl
->acl_level
= GPFS_ACL_LEVEL_BASE
;
653 gacl
->acl_version
= GPFS_ACL_VERSION_NFS4
;
654 gacl
->acl_type
= GPFS_ACL_TYPE_NFS4
;
655 gacl
->acl_nace
= 0; /* change later... */
658 gacl
->acl_level
= GPFS_ACL_LEVEL_V4FLAGS
;
659 sd2gpfs_control(smbacl4_get_controlflags(smbacl
), gacl
);
662 for (smbace
=smb_first_ace4(smbacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
663 struct gpfs_ace_v4
*gace
= gpfs_ace_ptr(gacl
, gacl
->acl_nace
);
664 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
666 gace
->aceType
= aceprop
->aceType
;
667 gace
->aceFlags
= aceprop
->aceFlags
;
668 gace
->aceMask
= aceprop
->aceMask
;
671 * GPFS can't distinguish between WRITE and APPEND on
672 * files, so one being set without the other is an
673 * error. Sorry for the many ()'s :-)
676 if (!fsp
->is_directory
678 ((((gace
->aceMask
& ACE4_MASK_WRITE
) == 0)
679 && ((gace
->aceMask
& ACE4_MASK_APPEND
) != 0))
681 (((gace
->aceMask
& ACE4_MASK_WRITE
) != 0)
682 && ((gace
->aceMask
& ACE4_MASK_APPEND
) == 0)))
684 lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
685 "merge_writeappend", True
)) {
686 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
687 "WRITE^APPEND, setting WRITE|APPEND\n",
689 gace
->aceMask
|= ACE4_MASK_WRITE
|ACE4_MASK_APPEND
;
692 gace
->aceIFlags
= (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
) ? ACE4_IFLAG_SPECIAL_ID
: 0;
694 if (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
)
696 switch(aceprop
->who
.special_id
)
698 case SMB_ACE4_WHO_EVERYONE
:
699 gace
->aceWho
= ACE4_SPECIAL_EVERYONE
;
701 case SMB_ACE4_WHO_OWNER
:
702 gace
->aceWho
= ACE4_SPECIAL_OWNER
;
704 case SMB_ACE4_WHO_GROUP
:
705 gace
->aceWho
= ACE4_SPECIAL_GROUP
;
708 DEBUG(8, ("unsupported special_id %d\n", aceprop
->who
.special_id
));
709 continue; /* don't add it !!! */
712 /* just only for the type safety... */
713 if (aceprop
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)
714 gace
->aceWho
= aceprop
->who
.gid
;
716 gace
->aceWho
= aceprop
->who
.uid
;
721 gacl
->acl_len
= (char *)gpfs_ace_ptr(gacl
, gacl
->acl_nace
)
726 static bool gpfsacl_process_smbacl(vfs_handle_struct
*handle
,
728 struct SMB4ACL_T
*smbacl
)
731 struct gpfs_acl
*gacl
;
732 TALLOC_CTX
*mem_ctx
= talloc_tos();
734 gacl
= vfs_gpfs_smbacl2gpfsacl(mem_ctx
, fsp
, smbacl
, true);
735 if (gacl
== NULL
) { /* out of memory */
738 ret
= gpfswrap_putacl(fsp
->fsp_name
->base_name
,
739 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gacl
);
741 if ((ret
!= 0) && (errno
== EINVAL
)) {
742 DEBUG(10, ("Retry without nfs41 control flags\n"));
744 gacl
= vfs_gpfs_smbacl2gpfsacl(mem_ctx
, fsp
, smbacl
, false);
745 if (gacl
== NULL
) { /* out of memory */
748 ret
= gpfswrap_putacl(fsp
->fsp_name
->base_name
,
749 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
,
754 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno
)));
755 gpfs_dumpacl(8, gacl
);
759 DEBUG(10, ("gpfs_putacl succeeded\n"));
763 static NTSTATUS
gpfsacl_set_nt_acl_internal(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32_t security_info_sent
, const struct security_descriptor
*psd
)
765 struct gpfs_acl
*acl
;
766 NTSTATUS result
= NT_STATUS_ACCESS_DENIED
;
768 acl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(),
769 fsp
->fsp_name
->base_name
,
772 return map_nt_error_from_unix(errno
);
775 if (acl
->acl_version
== GPFS_ACL_VERSION_NFS4
) {
776 if (lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
777 "refuse_dacl_protected", false)
778 && (psd
->type
&SEC_DESC_DACL_PROTECTED
)) {
779 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
781 return NT_STATUS_NOT_SUPPORTED
;
784 result
= smb_set_nt_acl_nfs4(handle
,
785 fsp
, security_info_sent
, psd
,
786 gpfsacl_process_smbacl
);
787 } else { /* assume POSIX ACL - by default... */
788 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
795 static NTSTATUS
gpfsacl_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32_t security_info_sent
, const struct security_descriptor
*psd
)
797 struct gpfs_config_data
*config
;
799 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
800 struct gpfs_config_data
,
801 return NT_STATUS_INTERNAL_ERROR
);
804 return SMB_VFS_NEXT_FSET_NT_ACL(handle
, fsp
, security_info_sent
, psd
);
807 return gpfsacl_set_nt_acl_internal(handle
, fsp
, security_info_sent
, psd
);
810 static SMB_ACL_T
gpfs2smb_acl(const struct gpfs_acl
*pacl
, TALLOC_CTX
*mem_ctx
)
815 result
= sys_acl_init(mem_ctx
);
816 if (result
== NULL
) {
821 result
->count
= pacl
->acl_nace
;
822 result
->acl
= talloc_realloc(result
, result
->acl
, struct smb_acl_entry
,
824 if (result
->acl
== NULL
) {
830 for (i
=0; i
<pacl
->acl_nace
; i
++) {
831 struct smb_acl_entry
*ace
= &result
->acl
[i
];
832 const struct gpfs_ace_v1
*g_ace
= &pacl
->ace_v1
[i
];
834 DEBUG(10, ("Converting type %d id %lu perm %x\n",
835 (int)g_ace
->ace_type
, (unsigned long)g_ace
->ace_who
,
836 (int)g_ace
->ace_perm
));
838 switch (g_ace
->ace_type
) {
840 ace
->a_type
= SMB_ACL_USER
;
841 ace
->info
.user
.uid
= (uid_t
)g_ace
->ace_who
;
843 case GPFS_ACL_USER_OBJ
:
844 ace
->a_type
= SMB_ACL_USER_OBJ
;
847 ace
->a_type
= SMB_ACL_GROUP
;
848 ace
->info
.group
.gid
= (gid_t
)g_ace
->ace_who
;
850 case GPFS_ACL_GROUP_OBJ
:
851 ace
->a_type
= SMB_ACL_GROUP_OBJ
;
854 ace
->a_type
= SMB_ACL_OTHER
;
857 ace
->a_type
= SMB_ACL_MASK
;
860 DEBUG(10, ("Got invalid ace_type: %d\n",
868 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_READ
) ?
870 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_WRITE
) ?
872 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_EXECUTE
) ?
875 DEBUGADD(10, ("Converted to %d perm %x\n",
876 ace
->a_type
, ace
->a_perm
));
882 static SMB_ACL_T
gpfsacl_get_posix_acl(const char *path
, gpfs_aclType_t type
,
885 struct gpfs_acl
*pacl
;
886 SMB_ACL_T result
= NULL
;
888 pacl
= vfs_gpfs_getacl(talloc_tos(), path
, false, type
);
891 DEBUG(10, ("vfs_gpfs_getacl failed for %s with %s\n",
892 path
, strerror(errno
)));
899 if (pacl
->acl_version
!= GPFS_ACL_VERSION_POSIX
) {
900 DEBUG(10, ("Got acl version %d, expected %d\n",
901 pacl
->acl_version
, GPFS_ACL_VERSION_POSIX
));
906 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
907 pacl
->acl_len
, pacl
->acl_level
, pacl
->acl_version
,
910 result
= gpfs2smb_acl(pacl
, mem_ctx
);
911 if (result
!= NULL
) {
926 static SMB_ACL_T
gpfsacl_sys_acl_get_file(vfs_handle_struct
*handle
,
931 gpfs_aclType_t gpfs_type
;
932 struct gpfs_config_data
*config
;
934 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
935 struct gpfs_config_data
,
939 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle
, path_p
,
944 case SMB_ACL_TYPE_ACCESS
:
945 gpfs_type
= GPFS_ACL_TYPE_ACCESS
;
947 case SMB_ACL_TYPE_DEFAULT
:
948 gpfs_type
= GPFS_ACL_TYPE_DEFAULT
;
951 DEBUG(0, ("Got invalid type: %d\n", type
));
952 smb_panic("exiting");
955 return gpfsacl_get_posix_acl(path_p
, gpfs_type
, mem_ctx
);
958 static SMB_ACL_T
gpfsacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
962 struct gpfs_config_data
*config
;
964 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
965 struct gpfs_config_data
,
969 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle
, fsp
, mem_ctx
);
972 return gpfsacl_get_posix_acl(fsp
->fsp_name
->base_name
,
973 GPFS_ACL_TYPE_ACCESS
, mem_ctx
);
976 static int gpfsacl_sys_acl_blob_get_file(vfs_handle_struct
*handle
,
979 char **blob_description
,
982 struct gpfs_config_data
*config
;
983 struct gpfs_opaque_acl
*acl
= NULL
;
987 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
988 struct gpfs_config_data
,
992 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle
, path_p
,
999 acl
= (struct gpfs_opaque_acl
*)
1000 vfs_gpfs_getacl(mem_ctx
,
1003 GPFS_ACL_TYPE_NFS4
);
1006 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
1007 errno
, strerror(errno
)));
1009 /* EINVAL means POSIX ACL, bail out on other cases */
1010 if (errno
!= EINVAL
) {
1017 * file has NFSv4 ACL
1019 * we only need the actual ACL blob here
1020 * acl_version will always be NFS4 because we asked
1022 * acl_type is only used for POSIX ACLs
1024 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
1025 aclblob
.length
= acl
->acl_buffer_len
;
1027 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
1028 if (!*blob_description
) {
1034 result
= non_posix_sys_acl_blob_get_file_helper(handle
, path_p
,
1042 /* fall back to POSIX ACL */
1043 return posix_sys_acl_blob_get_file(handle
, path_p
, mem_ctx
,
1044 blob_description
, blob
);
1047 static int gpfsacl_sys_acl_blob_get_fd(vfs_handle_struct
*handle
,
1049 TALLOC_CTX
*mem_ctx
,
1050 char **blob_description
,
1053 struct gpfs_config_data
*config
;
1054 struct gpfs_opaque_acl
*acl
= NULL
;
1058 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1059 struct gpfs_config_data
,
1063 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle
, fsp
, mem_ctx
,
1064 blob_description
, blob
);
1068 acl
= (struct gpfs_opaque_acl
*) vfs_gpfs_getacl(mem_ctx
,
1069 fsp
->fsp_name
->base_name
,
1071 GPFS_ACL_TYPE_NFS4
);
1074 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
1075 errno
, strerror(errno
)));
1077 /* EINVAL means POSIX ACL, bail out on other cases */
1078 if (errno
!= EINVAL
) {
1085 * file has NFSv4 ACL
1087 * we only need the actual ACL blob here
1088 * acl_version will always be NFS4 because we asked
1090 * acl_type is only used for POSIX ACLs
1092 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
1093 aclblob
.length
= acl
->acl_buffer_len
;
1095 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
1096 if (!*blob_description
) {
1102 result
= non_posix_sys_acl_blob_get_fd_helper(handle
, fsp
,
1110 /* fall back to POSIX ACL */
1111 return posix_sys_acl_blob_get_fd(handle
, fsp
, mem_ctx
,
1112 blob_description
, blob
);
1115 static struct gpfs_acl
*smb2gpfs_acl(const SMB_ACL_T pacl
,
1116 SMB_ACL_TYPE_T type
)
1119 struct gpfs_acl
*result
;
1122 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl
->count
));
1124 len
= offsetof(gpfs_acl_t
, ace_v1
) + (pacl
->count
) *
1125 sizeof(gpfs_ace_v1_t
);
1127 result
= (struct gpfs_acl
*)SMB_MALLOC(len
);
1128 if (result
== NULL
) {
1133 result
->acl_len
= len
;
1134 result
->acl_level
= 0;
1135 result
->acl_version
= GPFS_ACL_VERSION_POSIX
;
1136 result
->acl_type
= (type
== SMB_ACL_TYPE_DEFAULT
) ?
1137 GPFS_ACL_TYPE_DEFAULT
: GPFS_ACL_TYPE_ACCESS
;
1138 result
->acl_nace
= pacl
->count
;
1140 for (i
=0; i
<pacl
->count
; i
++) {
1141 const struct smb_acl_entry
*ace
= &pacl
->acl
[i
];
1142 struct gpfs_ace_v1
*g_ace
= &result
->ace_v1
[i
];
1144 DEBUG(10, ("Converting type %d perm %x\n",
1145 (int)ace
->a_type
, (int)ace
->a_perm
));
1147 g_ace
->ace_perm
= 0;
1149 switch(ace
->a_type
) {
1151 g_ace
->ace_type
= GPFS_ACL_USER
;
1152 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.user
.uid
;
1154 case SMB_ACL_USER_OBJ
:
1155 g_ace
->ace_type
= GPFS_ACL_USER_OBJ
;
1156 g_ace
->ace_perm
|= ACL_PERM_CONTROL
;
1160 g_ace
->ace_type
= GPFS_ACL_GROUP
;
1161 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.group
.gid
;
1163 case SMB_ACL_GROUP_OBJ
:
1164 g_ace
->ace_type
= GPFS_ACL_GROUP_OBJ
;
1168 g_ace
->ace_type
= GPFS_ACL_MASK
;
1169 g_ace
->ace_perm
= 0x8f;
1173 g_ace
->ace_type
= GPFS_ACL_OTHER
;
1177 DEBUG(10, ("Got invalid ace_type: %d\n", ace
->a_type
));
1183 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_READ
) ?
1185 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_WRITE
) ?
1187 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_EXECUTE
) ?
1188 ACL_PERM_EXECUTE
: 0;
1190 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
1191 g_ace
->ace_type
, g_ace
->ace_who
, g_ace
->ace_perm
));
1197 static int gpfsacl_sys_acl_set_file(vfs_handle_struct
*handle
,
1199 SMB_ACL_TYPE_T type
,
1202 struct gpfs_acl
*gpfs_acl
;
1204 struct gpfs_config_data
*config
;
1206 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1207 struct gpfs_config_data
,
1211 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle
, name
, type
, theacl
);
1214 gpfs_acl
= smb2gpfs_acl(theacl
, type
);
1215 if (gpfs_acl
== NULL
) {
1219 result
= gpfswrap_putacl(discard_const_p(char, name
),
1220 GPFS_PUTACL_STRUCT
|GPFS_ACL_SAMBA
, gpfs_acl
);
1222 SAFE_FREE(gpfs_acl
);
1226 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
1230 struct gpfs_config_data
*config
;
1232 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1233 struct gpfs_config_data
,
1237 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle
, fsp
, theacl
);
1240 return gpfsacl_sys_acl_set_file(handle
, fsp
->fsp_name
->base_name
,
1241 SMB_ACL_TYPE_ACCESS
, theacl
);
1244 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
1247 struct gpfs_config_data
*config
;
1249 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1250 struct gpfs_config_data
,
1254 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle
, path
);
1262 * Assumed: mode bits are shiftable and standard
1263 * Output: the new aceMask field for an smb nfs4 ace
1265 static uint32_t gpfsacl_mask_filter(uint32_t aceType
, uint32_t aceMask
, uint32_t rwx
)
1267 const uint32_t posix_nfs4map
[3] = {
1268 SMB_ACE4_EXECUTE
, /* execute */
1269 SMB_ACE4_WRITE_DATA
| SMB_ACE4_APPEND_DATA
, /* write; GPFS specific */
1270 SMB_ACE4_READ_DATA
/* read */
1273 uint32_t posix_mask
= 0x01;
1277 for(i
=0; i
<3; i
++) {
1278 nfs4_bits
= posix_nfs4map
[i
];
1279 posix_bit
= rwx
& posix_mask
;
1281 if (aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
) {
1283 aceMask
|= nfs4_bits
;
1285 aceMask
&= ~nfs4_bits
;
1287 /* add deny bits when suitable */
1289 aceMask
|= nfs4_bits
;
1291 aceMask
&= ~nfs4_bits
;
1292 } /* other ace types are unexpected */
1300 static int gpfsacl_emu_chmod(vfs_handle_struct
*handle
,
1301 const char *path
, mode_t mode
)
1303 struct SMB4ACL_T
*pacl
= NULL
;
1305 bool haveAllowEntry
[SMB_ACE4_WHO_EVERYONE
+ 1] = {False
, False
, False
, False
};
1307 files_struct fake_fsp
= { 0 }; /* TODO: rationalize parametrization */
1308 struct SMB4ACE_T
*smbace
;
1309 TALLOC_CTX
*frame
= talloc_stackframe();
1311 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path
, mode
));
1313 result
= gpfs_get_nfs4_acl(frame
, path
, &pacl
);
1319 if (mode
& ~(S_IRWXU
| S_IRWXG
| S_IRWXO
)) {
1320 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode
, path
));
1323 for (smbace
=smb_first_ace4(pacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
1324 SMB_ACE4PROP_T
*ace
= smb_get_ace4(smbace
);
1325 uint32_t specid
= ace
->who
.special_id
;
1327 if (ace
->flags
&SMB_ACE4_ID_SPECIAL
&&
1328 ace
->aceType
<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE
&&
1329 specid
<= SMB_ACE4_WHO_EVERYONE
) {
1333 if (ace
->aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
)
1334 haveAllowEntry
[specid
] = True
;
1336 /* mode >> 6 for @owner, mode >> 3 for @group,
1337 * mode >> 0 for @everyone */
1338 newMask
= gpfsacl_mask_filter(ace
->aceType
, ace
->aceMask
,
1339 mode
>> ((SMB_ACE4_WHO_EVERYONE
- specid
) * 3));
1340 if (ace
->aceMask
!=newMask
) {
1341 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
1342 path
, ace
->aceMask
, newMask
, specid
));
1344 ace
->aceMask
= newMask
;
1348 /* make sure we have at least ALLOW entries
1349 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
1352 for(i
= SMB_ACE4_WHO_OWNER
; i
<=SMB_ACE4_WHO_EVERYONE
; i
++) {
1353 SMB_ACE4PROP_T ace
= { 0 };
1355 if (haveAllowEntry
[i
]==True
)
1358 ace
.aceType
= SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
;
1359 ace
.flags
|= SMB_ACE4_ID_SPECIAL
;
1360 ace
.who
.special_id
= i
;
1362 if (i
==SMB_ACE4_WHO_GROUP
) /* not sure it's necessary... */
1363 ace
.aceFlags
|= SMB_ACE4_IDENTIFIER_GROUP
;
1365 ace
.aceMask
= gpfsacl_mask_filter(ace
.aceType
, ace
.aceMask
,
1366 mode
>> ((SMB_ACE4_WHO_EVERYONE
- i
) * 3));
1368 /* don't add unnecessary aces */
1372 /* we add it to the END - as windows expects allow aces */
1373 smb_add_ace4(pacl
, &ace
);
1374 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1375 path
, mode
, i
, ace
.aceMask
));
1378 /* don't add complementary DENY ACEs here */
1379 fake_fsp
.fsp_name
= synthetic_smb_fname(
1380 frame
, path
, NULL
, NULL
);
1381 if (fake_fsp
.fsp_name
== NULL
) {
1387 if (gpfsacl_process_smbacl(handle
, &fake_fsp
, pacl
) == False
) {
1393 return 0; /* ok for [f]chmod */
1396 static int vfs_gpfs_chmod(vfs_handle_struct
*handle
, const char *path
, mode_t mode
)
1398 struct smb_filename
*smb_fname_cpath
;
1401 smb_fname_cpath
= synthetic_smb_fname(talloc_tos(), path
, NULL
, NULL
);
1402 if (smb_fname_cpath
== NULL
) {
1407 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_cpath
) != 0) {
1411 /* avoid chmod() if possible, to preserve acls */
1412 if ((smb_fname_cpath
->st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1416 rc
= gpfsacl_emu_chmod(handle
, path
, mode
);
1418 return SMB_VFS_NEXT_CHMOD(handle
, path
, mode
);
1422 static int vfs_gpfs_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
1427 if (SMB_VFS_NEXT_FSTAT(handle
, fsp
, &st
) != 0) {
1431 /* avoid chmod() if possible, to preserve acls */
1432 if ((st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1436 rc
= gpfsacl_emu_chmod(handle
, fsp
->fsp_name
->base_name
,
1439 return SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
1443 static int gpfs_set_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1444 const char *name
, const void *value
, size_t size
, int flags
){
1445 struct xattr_DOSATTRIB dosattrib
;
1446 enum ndr_err_code ndr_err
;
1448 unsigned int dosmode
=0;
1449 struct gpfs_winattr attrs
;
1451 struct gpfs_config_data
*config
;
1453 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1454 struct gpfs_config_data
,
1457 if (!config
->winattr
) {
1458 DEBUG(10, ("gpfs_set_xattr:name is %s -> next\n",name
));
1459 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1462 DEBUG(10, ("gpfs_set_xattr: %s \n",path
));
1464 /* Only handle DOS Attributes */
1465 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1466 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name
));
1467 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1470 blob
.data
= discard_const_p(uint8_t, value
);
1473 ndr_err
= ndr_pull_struct_blob(&blob
, talloc_tos(), &dosattrib
,
1474 (ndr_pull_flags_fn_t
)ndr_pull_xattr_DOSATTRIB
);
1476 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1477 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
1478 "from EA on file %s: Error = %s\n",
1479 path
, ndr_errstr(ndr_err
)));
1483 if (dosattrib
.version
!= 3) {
1484 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
1485 "%d\n", (int)dosattrib
.version
));
1488 if (!(dosattrib
.info
.info3
.valid_flags
& XATTR_DOSINFO_ATTRIB
)) {
1489 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
1490 "valid, ignoring\n"));
1494 dosmode
= dosattrib
.info
.info3
.attrib
;
1497 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
1498 if (dosmode
& FILE_ATTRIBUTE_ARCHIVE
){
1499 attrs
.winAttrs
|= GPFS_WINATTR_ARCHIVE
;
1501 if (dosmode
& FILE_ATTRIBUTE_HIDDEN
){
1502 attrs
.winAttrs
|= GPFS_WINATTR_HIDDEN
;
1504 if (dosmode
& FILE_ATTRIBUTE_SYSTEM
){
1505 attrs
.winAttrs
|= GPFS_WINATTR_SYSTEM
;
1507 if (dosmode
& FILE_ATTRIBUTE_READONLY
){
1508 attrs
.winAttrs
|= GPFS_WINATTR_READONLY
;
1510 if (dosmode
& FILE_ATTRIBUTE_SPARSE
) {
1511 attrs
.winAttrs
|= GPFS_WINATTR_SPARSE_FILE
;
1515 ret
= gpfswrap_set_winattrs_path(discard_const_p(char, path
),
1516 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1518 if (errno
== ENOSYS
) {
1519 return SMB_VFS_NEXT_SETXATTR(handle
, path
, name
, value
,
1523 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret
));
1527 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs
.winAttrs
));
1531 static ssize_t
gpfs_get_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1532 const char *name
, void *value
, size_t size
){
1533 char *attrstr
= value
;
1534 unsigned int dosmode
= 0;
1535 struct gpfs_winattr attrs
;
1537 struct gpfs_config_data
*config
;
1539 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1540 struct gpfs_config_data
,
1543 if (!config
->winattr
) {
1544 DEBUG(10, ("gpfs_get_xattr:name is %s -> next\n",name
));
1545 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1548 DEBUG(10, ("gpfs_get_xattr: %s \n",path
));
1550 /* Only handle DOS Attributes */
1551 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1552 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name
));
1553 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1556 ret
= gpfswrap_get_winattrs_path(discard_const_p(char, path
), &attrs
);
1560 if (errno
== ENOSYS
) {
1561 return SMB_VFS_NEXT_GETXATTR(handle
, path
, name
, value
,
1565 if (errno
!= EPERM
&& errno
!= EACCES
) {
1570 DEBUG(dbg_lvl
, ("gpfs_get_xattr: Get GPFS attributes failed: "
1571 "%d (%s)\n", ret
, strerror(errno
)));
1575 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs
.winAttrs
));
1577 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1578 if (attrs
.winAttrs
& GPFS_WINATTR_ARCHIVE
){
1579 dosmode
|= FILE_ATTRIBUTE_ARCHIVE
;
1581 if (attrs
.winAttrs
& GPFS_WINATTR_HIDDEN
){
1582 dosmode
|= FILE_ATTRIBUTE_HIDDEN
;
1584 if (attrs
.winAttrs
& GPFS_WINATTR_SYSTEM
){
1585 dosmode
|= FILE_ATTRIBUTE_SYSTEM
;
1587 if (attrs
.winAttrs
& GPFS_WINATTR_READONLY
){
1588 dosmode
|= FILE_ATTRIBUTE_READONLY
;
1590 if (attrs
.winAttrs
& GPFS_WINATTR_SPARSE_FILE
) {
1591 dosmode
|= FILE_ATTRIBUTE_SPARSE
;
1594 snprintf(attrstr
, size
, "0x%2.2x",
1595 (unsigned int)(dosmode
& SAMBA_ATTRIBUTES_MASK
));
1596 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr
));
1600 #if defined(HAVE_FSTATAT)
1601 static int stat_with_capability(struct vfs_handle_struct
*handle
,
1602 struct smb_filename
*smb_fname
, int flag
)
1607 const char *rel_name
= NULL
;
1611 b
= parent_dirname(talloc_tos(), smb_fname
->base_name
,
1612 &dir_name
, &rel_name
);
1618 fd
= open(dir_name
, O_RDONLY
, 0);
1619 TALLOC_FREE(dir_name
);
1624 set_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1625 ret
= fstatat(fd
, rel_name
, &st
, flag
);
1626 drop_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1631 init_stat_ex_from_stat(
1632 &smb_fname
->st
, &st
,
1633 lp_fake_directory_create_times(SNUM(handle
->conn
)));
1640 static int vfs_gpfs_stat(struct vfs_handle_struct
*handle
,
1641 struct smb_filename
*smb_fname
)
1643 struct gpfs_winattr attrs
;
1647 struct gpfs_config_data
*config
;
1649 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1650 struct gpfs_config_data
,
1653 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
1654 #if defined(HAVE_FSTATAT)
1655 if (ret
== -1 && errno
== EACCES
) {
1656 DEBUG(10, ("Trying stat with capability for %s\n",
1657 smb_fname
->base_name
));
1658 ret
= stat_with_capability(handle
, smb_fname
, 0);
1665 if (!config
->winattr
) {
1669 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &fname
);
1670 if (!NT_STATUS_IS_OK(status
)) {
1671 errno
= map_errno_from_nt_status(status
);
1674 ret
= gpfswrap_get_winattrs_path(discard_const_p(char, fname
), &attrs
);
1677 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1678 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1679 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1684 static int vfs_gpfs_fstat(struct vfs_handle_struct
*handle
,
1685 struct files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
1687 struct gpfs_winattr attrs
;
1689 struct gpfs_config_data
*config
;
1691 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1692 struct gpfs_config_data
,
1695 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
1699 if ((fsp
->fh
== NULL
) || (fsp
->fh
->fd
== -1)) {
1702 if (!config
->winattr
) {
1706 ret
= gpfswrap_get_winattrs(fsp
->fh
->fd
, &attrs
);
1708 sbuf
->st_ex_calculated_birthtime
= false;
1709 sbuf
->st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1710 sbuf
->st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1715 static int vfs_gpfs_lstat(struct vfs_handle_struct
*handle
,
1716 struct smb_filename
*smb_fname
)
1718 struct gpfs_winattr attrs
;
1722 struct gpfs_config_data
*config
;
1724 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1725 struct gpfs_config_data
,
1728 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
1729 #if defined(HAVE_FSTATAT)
1730 if (ret
== -1 && errno
== EACCES
) {
1731 DEBUG(10, ("Trying lstat with capability for %s\n",
1732 smb_fname
->base_name
));
1733 ret
= stat_with_capability(handle
, smb_fname
,
1734 AT_SYMLINK_NOFOLLOW
);
1741 if (!config
->winattr
) {
1745 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1746 if (!NT_STATUS_IS_OK(status
)) {
1747 errno
= map_errno_from_nt_status(status
);
1750 ret
= gpfswrap_get_winattrs_path(discard_const_p(char, path
), &attrs
);
1753 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1754 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1755 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1760 static void timespec_to_gpfs_time(struct timespec ts
, gpfs_timestruc_t
*gt
,
1761 int idx
, int *flags
)
1763 if (!null_timespec(ts
)) {
1765 gt
[idx
].tv_sec
= ts
.tv_sec
;
1766 gt
[idx
].tv_nsec
= ts
.tv_nsec
;
1767 DEBUG(10, ("Setting GPFS time %d, flags 0x%x\n", idx
, *flags
));
1771 static int smbd_gpfs_set_times_path(char *path
, struct smb_file_time
*ft
)
1773 gpfs_timestruc_t gpfs_times
[4];
1777 ZERO_ARRAY(gpfs_times
);
1778 timespec_to_gpfs_time(ft
->atime
, gpfs_times
, 0, &flags
);
1779 timespec_to_gpfs_time(ft
->mtime
, gpfs_times
, 1, &flags
);
1780 /* No good mapping from LastChangeTime to ctime, not storing */
1781 timespec_to_gpfs_time(ft
->create_time
, gpfs_times
, 3, &flags
);
1784 DEBUG(10, ("nothing to do, return to avoid EINVAL\n"));
1788 rc
= gpfswrap_set_times_path(path
, flags
, gpfs_times
);
1790 if (rc
!= 0 && errno
!= ENOSYS
) {
1791 DEBUG(1,("gpfs_set_times() returned with error %s\n",
1798 static int vfs_gpfs_ntimes(struct vfs_handle_struct
*handle
,
1799 const struct smb_filename
*smb_fname
,
1800 struct smb_file_time
*ft
)
1803 struct gpfs_winattr attrs
;
1807 struct gpfs_config_data
*config
;
1809 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1810 struct gpfs_config_data
,
1813 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1814 if (!NT_STATUS_IS_OK(status
)) {
1815 errno
= map_errno_from_nt_status(status
);
1819 /* Try to use gpfs_set_times if it is enabled and available */
1820 if (config
->settimes
) {
1821 ret
= smbd_gpfs_set_times_path(path
, ft
);
1823 if (ret
== 0 || (ret
== -1 && errno
!= ENOSYS
)) {
1828 DEBUG(10,("gpfs_set_times() not available or disabled, "
1829 "use ntimes and winattr\n"));
1831 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1833 /* don't complain if access was denied */
1834 if (errno
!= EPERM
&& errno
!= EACCES
) {
1835 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1836 "%s", strerror(errno
)));
1841 if(null_timespec(ft
->create_time
)){
1842 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1846 if (!config
->winattr
) {
1851 attrs
.creationTime
.tv_sec
= ft
->create_time
.tv_sec
;
1852 attrs
.creationTime
.tv_nsec
= ft
->create_time
.tv_nsec
;
1854 ret
= gpfswrap_set_winattrs_path(discard_const_p(char, path
),
1855 GPFS_WINATTR_SET_CREATION_TIME
,
1857 if(ret
== -1 && errno
!= ENOSYS
){
1858 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret
));
1865 static int vfs_gpfs_fallocate(struct vfs_handle_struct
*handle
,
1866 struct files_struct
*fsp
, uint32_t mode
,
1867 off_t offset
, off_t len
)
1870 struct gpfs_config_data
*config
;
1872 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1873 struct gpfs_config_data
,
1876 if (!config
->prealloc
) {
1877 /* you should better not run fallocate() on GPFS at all */
1883 DEBUG(10, ("unmapped fallocate flags: %lx\n",
1884 (unsigned long)mode
));
1889 ret
= gpfswrap_prealloc(fsp
->fh
->fd
, offset
, len
);
1891 if (ret
== -1 && errno
!= ENOSYS
) {
1892 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno
)));
1893 } else if (ret
== -1 && errno
== ENOSYS
) {
1894 DEBUG(10, ("GPFS prealloc not supported.\n"));
1896 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1902 static int vfs_gpfs_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1906 struct gpfs_config_data
*config
;
1908 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1909 struct gpfs_config_data
,
1912 if (!config
->ftruncate
) {
1913 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1916 result
= gpfswrap_ftruncate(fsp
->fh
->fd
, len
);
1917 if ((result
== -1) && (errno
== ENOSYS
)) {
1918 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1923 static bool vfs_gpfs_is_offline(struct vfs_handle_struct
*handle
,
1924 const struct smb_filename
*fname
,
1925 SMB_STRUCT_STAT
*sbuf
)
1927 struct gpfs_winattr attrs
;
1930 struct gpfs_config_data
*config
;
1933 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1934 struct gpfs_config_data
,
1937 if (!config
->winattr
) {
1938 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1941 status
= get_full_smb_filename(talloc_tos(), fname
, &path
);
1942 if (!NT_STATUS_IS_OK(status
)) {
1943 errno
= map_errno_from_nt_status(status
);
1947 ret
= gpfswrap_get_winattrs_path(path
, &attrs
);
1953 if ((attrs
.winAttrs
& GPFS_WINATTR_OFFLINE
) != 0) {
1954 DEBUG(10, ("%s is offline\n", path
));
1958 DEBUG(10, ("%s is online\n", path
));
1960 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1963 static bool vfs_gpfs_fsp_is_offline(struct vfs_handle_struct
*handle
,
1964 struct files_struct
*fsp
)
1966 struct gpfs_fsp_extension
*ext
;
1968 ext
= VFS_FETCH_FSP_EXTENSION(handle
, fsp
);
1971 * Something bad happened, always ask.
1973 return vfs_gpfs_is_offline(handle
, fsp
->fsp_name
,
1974 &fsp
->fsp_name
->st
);
1979 * As long as it's offline, ask.
1981 ext
->offline
= vfs_gpfs_is_offline(handle
, fsp
->fsp_name
,
1982 &fsp
->fsp_name
->st
);
1985 return ext
->offline
;
1988 static bool vfs_gpfs_aio_force(struct vfs_handle_struct
*handle
,
1989 struct files_struct
*fsp
)
1991 return vfs_gpfs_fsp_is_offline(handle
, fsp
);
1994 static ssize_t
vfs_gpfs_sendfile(vfs_handle_struct
*handle
, int tofd
,
1995 files_struct
*fsp
, const DATA_BLOB
*hdr
,
1996 off_t offset
, size_t n
)
1998 if (vfs_gpfs_fsp_is_offline(handle
, fsp
)) {
2002 return SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fsp
, hdr
, offset
, n
);
2005 static int vfs_gpfs_connect(struct vfs_handle_struct
*handle
,
2006 const char *service
, const char *user
)
2008 struct gpfs_config_data
*config
;
2011 gpfswrap_lib_init(0);
2013 config
= talloc_zero(handle
->conn
, struct gpfs_config_data
);
2015 DEBUG(0, ("talloc_zero() failed\n"));
2020 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
2022 TALLOC_FREE(config
);
2026 config
->sharemodes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2027 "sharemodes", true);
2029 config
->leases
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2032 config
->hsm
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2035 config
->syncio
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2038 config
->winattr
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2041 config
->ftruncate
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2044 config
->getrealfilename
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2045 "getrealfilename", true);
2047 config
->dfreequota
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2048 "dfreequota", false);
2050 config
->prealloc
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2053 config
->acl
= lp_parm_bool(SNUM(handle
->conn
), "gpfs", "acl", true);
2055 config
->settimes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2057 config
->recalls
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2060 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
2061 NULL
, struct gpfs_config_data
,
2064 if (config
->leases
) {
2066 * GPFS lease code is based on kernel oplock code
2067 * so make sure it is turned on
2069 if (!lp_kernel_oplocks(SNUM(handle
->conn
))) {
2070 DEBUG(5, ("Enabling kernel oplocks for "
2071 "gpfs:leases to work\n"));
2072 lp_do_parameter(SNUM(handle
->conn
), "kernel oplocks",
2077 * as the kernel does not properly support Level II oplocks
2078 * and GPFS leases code is based on kernel infrastructure, we
2079 * need to turn off Level II oplocks if gpfs:leases is enabled
2081 if (lp_level2_oplocks(SNUM(handle
->conn
))) {
2082 DEBUG(5, ("gpfs:leases are enabled, disabling "
2083 "Level II oplocks\n"));
2084 lp_do_parameter(SNUM(handle
->conn
), "level2 oplocks",
2092 static int get_gpfs_quota(const char *pathname
, int type
, int id
,
2093 struct gpfs_quotaInfo
*qi
)
2097 ret
= gpfswrap_quotactl(discard_const_p(char, pathname
),
2098 GPFS_QCMD(Q_GETQUOTA
, type
), id
, qi
);
2101 if (errno
== GPFS_E_NO_QUOTA_INST
) {
2102 DEBUG(10, ("Quotas disabled on GPFS filesystem.\n"));
2103 } else if (errno
!= ENOSYS
) {
2104 DEBUG(0, ("Get quota failed, type %d, id, %d, "
2105 "errno %d.\n", type
, id
, errno
));
2111 DEBUG(10, ("quota type %d, id %d, blk u:%lld h:%lld s:%lld gt:%u\n",
2112 type
, id
, qi
->blockUsage
, qi
->blockHardLimit
,
2113 qi
->blockSoftLimit
, qi
->blockGraceTime
));
2118 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi
, time_t cur_time
,
2119 uint64_t *dfree
, uint64_t *dsize
)
2121 uint64_t usage
, limit
;
2124 * The quota reporting is done in units of 1024 byte blocks, but
2125 * sys_fsusage uses units of 512 byte blocks, adjust the block number
2126 * accordingly. Also filter possibly negative usage counts from gpfs.
2128 usage
= qi
.blockUsage
< 0 ? 0 : (uint64_t)qi
.blockUsage
* 2;
2129 limit
= (uint64_t)qi
.blockHardLimit
* 2;
2132 * When the grace time for the exceeded soft block quota has been
2133 * exceeded, the soft block quota becomes an additional hard limit.
2135 if (qi
.blockSoftLimit
&&
2136 qi
.blockGraceTime
&& cur_time
> qi
.blockGraceTime
) {
2137 /* report disk as full */
2139 *dsize
= MIN(*dsize
, usage
);
2142 if (!qi
.blockHardLimit
)
2145 if (usage
>= limit
) {
2146 /* report disk as full */
2148 *dsize
= MIN(*dsize
, usage
);
2151 /* limit has not been reached, determine "free space" */
2152 *dfree
= MIN(*dfree
, limit
- usage
);
2153 *dsize
= MIN(*dsize
, limit
);
2157 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct
*handle
, const char *path
,
2159 uint64_t *dfree
, uint64_t *dsize
)
2161 struct security_unix_token
*utok
;
2162 struct gpfs_quotaInfo qi_user
= { 0 }, qi_group
= { 0 };
2163 struct gpfs_config_data
*config
;
2167 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct gpfs_config_data
,
2168 return (uint64_t)-1);
2169 if (!config
->dfreequota
) {
2170 return SMB_VFS_NEXT_DISK_FREE(handle
, path
,
2171 bsize
, dfree
, dsize
);
2174 err
= sys_fsusage(path
, dfree
, dsize
);
2176 DEBUG (0, ("Could not get fs usage, errno %d\n", errno
));
2177 return SMB_VFS_NEXT_DISK_FREE(handle
, path
,
2178 bsize
, dfree
, dsize
);
2181 /* sys_fsusage returns units of 512 bytes */
2184 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
2185 (unsigned long long)*dfree
, (unsigned long long)*dsize
));
2187 utok
= handle
->conn
->session_info
->unix_token
;
2189 err
= get_gpfs_quota(path
, GPFS_USRQUOTA
, utok
->uid
, &qi_user
);
2191 return SMB_VFS_NEXT_DISK_FREE(handle
, path
,
2192 bsize
, dfree
, dsize
);
2195 err
= get_gpfs_quota(path
, GPFS_GRPQUOTA
, utok
->gid
, &qi_group
);
2197 return SMB_VFS_NEXT_DISK_FREE(handle
, path
,
2198 bsize
, dfree
, dsize
);
2201 cur_time
= time(NULL
);
2203 /* Adjust free space and size according to quota limits. */
2204 vfs_gpfs_disk_free_quota(qi_user
, cur_time
, dfree
, dsize
);
2205 vfs_gpfs_disk_free_quota(qi_group
, cur_time
, dfree
, dsize
);
2210 static int vfs_gpfs_get_quota(vfs_handle_struct
*handle
, const char *path
,
2211 enum SMB_QUOTA_TYPE qtype
, unid_t id
,
2216 * User/group quota are being used for disk-free
2217 * determination, which in this module is done directly
2218 * by the disk-free function. It's important that this
2219 * module does not return wrong quota values by mistake,
2220 * which would modify the correct values set by disk-free.
2221 * User/group quota are also being used for processing
2222 * NT_TRANSACT_GET_USER_QUOTA in smb1 protocol, which is
2223 * currently not supported by this module.
2225 case SMB_USER_QUOTA_TYPE
:
2226 case SMB_GROUP_QUOTA_TYPE
:
2230 return SMB_VFS_NEXT_GET_QUOTA(handle
, path
, qtype
, id
, dq
);
2234 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct
*handle
,
2235 enum timestamp_set_resolution
*p_ts_res
)
2237 struct gpfs_config_data
*config
;
2240 next
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
2242 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2243 struct gpfs_config_data
,
2247 next
|= FILE_SUPPORTS_REMOTE_STORAGE
;
2252 static int vfs_gpfs_open(struct vfs_handle_struct
*handle
,
2253 struct smb_filename
*smb_fname
, files_struct
*fsp
,
2254 int flags
, mode_t mode
)
2256 struct gpfs_config_data
*config
;
2258 struct gpfs_fsp_extension
*ext
;
2260 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2261 struct gpfs_config_data
,
2264 if (config
->hsm
&& !config
->recalls
&&
2265 vfs_gpfs_fsp_is_offline(handle
, fsp
)) {
2266 DEBUG(10, ("Refusing access to offline file %s\n",
2272 if (config
->syncio
) {
2276 ext
= VFS_ADD_FSP_EXTENSION(handle
, fsp
, struct gpfs_fsp_extension
,
2284 * Assume the file is offline until gpfs tells us it's online.
2286 *ext
= (struct gpfs_fsp_extension
) { .offline
= true };
2288 ret
= SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
2290 VFS_REMOVE_FSP_EXTENSION(handle
, fsp
);
2295 static ssize_t
vfs_gpfs_pread(vfs_handle_struct
*handle
, files_struct
*fsp
,
2296 void *data
, size_t n
, off_t offset
)
2301 was_offline
= vfs_gpfs_fsp_is_offline(handle
, fsp
);
2303 ret
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
2305 if ((ret
!= -1) && was_offline
) {
2306 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2307 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2308 fsp
->fsp_name
->base_name
);
2314 struct vfs_gpfs_pread_state
{
2315 struct files_struct
*fsp
;
2321 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
);
2323 static struct tevent_req
*vfs_gpfs_pread_send(struct vfs_handle_struct
*handle
,
2324 TALLOC_CTX
*mem_ctx
,
2325 struct tevent_context
*ev
,
2326 struct files_struct
*fsp
,
2327 void *data
, size_t n
,
2330 struct tevent_req
*req
, *subreq
;
2331 struct vfs_gpfs_pread_state
*state
;
2333 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pread_state
);
2337 state
->was_offline
= vfs_gpfs_fsp_is_offline(handle
, fsp
);
2339 subreq
= SMB_VFS_NEXT_PREAD_SEND(state
, ev
, handle
, fsp
, data
,
2341 if (tevent_req_nomem(subreq
, req
)) {
2342 return tevent_req_post(req
, ev
);
2344 tevent_req_set_callback(subreq
, vfs_gpfs_pread_done
, req
);
2348 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
)
2350 struct tevent_req
*req
= tevent_req_callback_data(
2351 subreq
, struct tevent_req
);
2352 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2353 req
, struct vfs_gpfs_pread_state
);
2355 state
->ret
= SMB_VFS_PREAD_RECV(subreq
, &state
->err
);
2356 TALLOC_FREE(subreq
);
2357 tevent_req_done(req
);
2360 static ssize_t
vfs_gpfs_pread_recv(struct tevent_req
*req
, int *err
)
2362 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2363 req
, struct vfs_gpfs_pread_state
);
2364 struct files_struct
*fsp
= state
->fsp
;
2366 if (tevent_req_is_unix_error(req
, err
)) {
2371 if ((state
->ret
!= -1) && state
->was_offline
) {
2372 DEBUG(10, ("sending notify\n"));
2373 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2374 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2375 fsp
->fsp_name
->base_name
);
2381 static ssize_t
vfs_gpfs_pwrite(vfs_handle_struct
*handle
, files_struct
*fsp
,
2382 const void *data
, size_t n
, off_t offset
)
2387 was_offline
= vfs_gpfs_fsp_is_offline(handle
, fsp
);
2389 ret
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
2391 if ((ret
!= -1) && was_offline
) {
2392 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2393 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2394 fsp
->fsp_name
->base_name
);
2400 struct vfs_gpfs_pwrite_state
{
2401 struct files_struct
*fsp
;
2407 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
);
2409 static struct tevent_req
*vfs_gpfs_pwrite_send(
2410 struct vfs_handle_struct
*handle
,
2411 TALLOC_CTX
*mem_ctx
,
2412 struct tevent_context
*ev
,
2413 struct files_struct
*fsp
,
2414 const void *data
, size_t n
,
2417 struct tevent_req
*req
, *subreq
;
2418 struct vfs_gpfs_pwrite_state
*state
;
2420 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pwrite_state
);
2424 state
->was_offline
= vfs_gpfs_fsp_is_offline(handle
, fsp
);
2426 subreq
= SMB_VFS_NEXT_PWRITE_SEND(state
, ev
, handle
, fsp
, data
,
2428 if (tevent_req_nomem(subreq
, req
)) {
2429 return tevent_req_post(req
, ev
);
2431 tevent_req_set_callback(subreq
, vfs_gpfs_pwrite_done
, req
);
2435 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
)
2437 struct tevent_req
*req
= tevent_req_callback_data(
2438 subreq
, struct tevent_req
);
2439 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2440 req
, struct vfs_gpfs_pwrite_state
);
2442 state
->ret
= SMB_VFS_PWRITE_RECV(subreq
, &state
->err
);
2443 TALLOC_FREE(subreq
);
2444 tevent_req_done(req
);
2447 static ssize_t
vfs_gpfs_pwrite_recv(struct tevent_req
*req
, int *err
)
2449 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2450 req
, struct vfs_gpfs_pwrite_state
);
2451 struct files_struct
*fsp
= state
->fsp
;
2453 if (tevent_req_is_unix_error(req
, err
)) {
2458 if ((state
->ret
!= -1) && state
->was_offline
) {
2459 DEBUG(10, ("sending notify\n"));
2460 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2461 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2462 fsp
->fsp_name
->base_name
);
2469 static struct vfs_fn_pointers vfs_gpfs_fns
= {
2470 .connect_fn
= vfs_gpfs_connect
,
2471 .disk_free_fn
= vfs_gpfs_disk_free
,
2472 .get_quota_fn
= vfs_gpfs_get_quota
,
2473 .fs_capabilities_fn
= vfs_gpfs_capabilities
,
2474 .kernel_flock_fn
= vfs_gpfs_kernel_flock
,
2475 .linux_setlease_fn
= vfs_gpfs_setlease
,
2476 .get_real_filename_fn
= vfs_gpfs_get_real_filename
,
2477 .fget_nt_acl_fn
= gpfsacl_fget_nt_acl
,
2478 .get_nt_acl_fn
= gpfsacl_get_nt_acl
,
2479 .fset_nt_acl_fn
= gpfsacl_fset_nt_acl
,
2480 .sys_acl_get_file_fn
= gpfsacl_sys_acl_get_file
,
2481 .sys_acl_get_fd_fn
= gpfsacl_sys_acl_get_fd
,
2482 .sys_acl_blob_get_file_fn
= gpfsacl_sys_acl_blob_get_file
,
2483 .sys_acl_blob_get_fd_fn
= gpfsacl_sys_acl_blob_get_fd
,
2484 .sys_acl_set_file_fn
= gpfsacl_sys_acl_set_file
,
2485 .sys_acl_set_fd_fn
= gpfsacl_sys_acl_set_fd
,
2486 .sys_acl_delete_def_file_fn
= gpfsacl_sys_acl_delete_def_file
,
2487 .chmod_fn
= vfs_gpfs_chmod
,
2488 .fchmod_fn
= vfs_gpfs_fchmod
,
2489 .close_fn
= vfs_gpfs_close
,
2490 .setxattr_fn
= gpfs_set_xattr
,
2491 .getxattr_fn
= gpfs_get_xattr
,
2492 .stat_fn
= vfs_gpfs_stat
,
2493 .fstat_fn
= vfs_gpfs_fstat
,
2494 .lstat_fn
= vfs_gpfs_lstat
,
2495 .ntimes_fn
= vfs_gpfs_ntimes
,
2496 .is_offline_fn
= vfs_gpfs_is_offline
,
2497 .aio_force_fn
= vfs_gpfs_aio_force
,
2498 .sendfile_fn
= vfs_gpfs_sendfile
,
2499 .fallocate_fn
= vfs_gpfs_fallocate
,
2500 .open_fn
= vfs_gpfs_open
,
2501 .pread_fn
= vfs_gpfs_pread
,
2502 .pread_send_fn
= vfs_gpfs_pread_send
,
2503 .pread_recv_fn
= vfs_gpfs_pread_recv
,
2504 .pwrite_fn
= vfs_gpfs_pwrite
,
2505 .pwrite_send_fn
= vfs_gpfs_pwrite_send
,
2506 .pwrite_recv_fn
= vfs_gpfs_pwrite_recv
,
2507 .ftruncate_fn
= vfs_gpfs_ftruncate
2510 NTSTATUS
vfs_gpfs_init(void);
2511 NTSTATUS
vfs_gpfs_init(void)
2515 ret
= gpfswrap_init();
2517 DEBUG(1, ("Could not initialize GPFS library wrapper\n"));
2520 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "gpfs",