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 static inline unsigned int gpfs_acl_flags(gpfs_acl_t
*gacl
)
59 if (gacl
->acl_level
== GPFS_ACL_LEVEL_V4FLAGS
) {
60 return gacl
->v4Level1
.acl_flags
;
65 static inline gpfs_ace_v4_t
*gpfs_ace_ptr(gpfs_acl_t
*gacl
, unsigned int i
)
67 if (gacl
->acl_level
== GPFS_ACL_LEVEL_V4FLAGS
) {
68 return &gacl
->v4Level1
.ace_v4
[i
];
70 return &gacl
->ace_v4
[i
];
73 static bool set_gpfs_sharemode(files_struct
*fsp
, uint32_t access_mask
,
74 uint32_t share_access
)
76 unsigned int allow
= GPFS_SHARE_NONE
;
77 unsigned int deny
= GPFS_DENY_NONE
;
80 if ((fsp
== NULL
) || (fsp
->fh
== NULL
) || (fsp
->fh
->fd
< 0)) {
81 /* No real file, don't disturb */
85 allow
|= (access_mask
& (FILE_WRITE_DATA
|FILE_APPEND_DATA
|
86 DELETE_ACCESS
)) ? GPFS_SHARE_WRITE
: 0;
87 allow
|= (access_mask
& (FILE_READ_DATA
|FILE_EXECUTE
)) ?
90 if (allow
== GPFS_SHARE_NONE
) {
91 DEBUG(10, ("special case am=no_access:%x\n",access_mask
));
94 deny
|= (share_access
& FILE_SHARE_WRITE
) ?
96 deny
|= (share_access
& (FILE_SHARE_READ
)) ?
99 DEBUG(10, ("am=%x, allow=%d, sa=%x, deny=%d\n",
100 access_mask
, allow
, share_access
, deny
));
102 result
= gpfswrap_set_share(fsp
->fh
->fd
, allow
, deny
);
104 if (errno
== ENOSYS
) {
105 DEBUG(5, ("VFS module vfs_gpfs loaded, but gpfs "
106 "set_share function support not available. "
107 "Allowing access\n"));
110 DEBUG(10, ("gpfs_set_share failed: %s\n",
115 return (result
== 0);
118 static int vfs_gpfs_kernel_flock(vfs_handle_struct
*handle
, files_struct
*fsp
,
119 uint32_t share_mode
, uint32_t access_mask
)
122 struct gpfs_config_data
*config
;
125 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
126 struct gpfs_config_data
,
129 if(!config
->sharemodes
) {
134 * A named stream fsp will have the basefile open in the fsp
135 * fd, so lacking a distinct fd for the stream we have to skip
136 * kernel_flock and set_gpfs_sharemode for stream.
138 if (!is_ntfs_default_stream_smb_fname(fsp
->fsp_name
)) {
139 DEBUG(2,("%s: kernel_flock on stream\n", fsp_str_dbg(fsp
)));
143 START_PROFILE(syscall_kernel_flock
);
145 kernel_flock(fsp
->fh
->fd
, share_mode
, access_mask
);
147 if (!set_gpfs_sharemode(fsp
, access_mask
, fsp
->share_access
)) {
151 END_PROFILE(syscall_kernel_flock
);
156 static int vfs_gpfs_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
159 struct gpfs_config_data
*config
;
161 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
162 struct gpfs_config_data
,
165 if (config
->sharemodes
&& (fsp
->fh
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
166 set_gpfs_sharemode(fsp
, 0, 0);
169 return SMB_VFS_NEXT_CLOSE(handle
, fsp
);
172 static int set_gpfs_lease(int fd
, int leasetype
)
174 int gpfs_type
= GPFS_LEASE_NONE
;
176 if (leasetype
== F_RDLCK
) {
177 gpfs_type
= GPFS_LEASE_READ
;
179 if (leasetype
== F_WRLCK
) {
180 gpfs_type
= GPFS_LEASE_WRITE
;
183 /* we unconditionally set CAP_LEASE, rather than looking for
184 -1/EACCES as there is a bug in some versions of
185 libgpfs_gpl.so which results in a leaked fd on /dev/ss0
186 each time we try this with the wrong capabilities set
188 linux_set_lease_capability();
189 return gpfswrap_set_lease(fd
, gpfs_type
);
192 static int vfs_gpfs_setlease(vfs_handle_struct
*handle
, files_struct
*fsp
,
195 struct gpfs_config_data
*config
;
198 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
199 struct gpfs_config_data
,
202 START_PROFILE(syscall_linux_setlease
);
204 if (linux_set_lease_sighandler(fsp
->fh
->fd
) == -1) {
209 if (config
->leases
) {
211 * Ensure the lease owner is root to allow
212 * correct delivery of lease-break signals.
215 ret
= set_gpfs_lease(fsp
->fh
->fd
,leasetype
);
220 END_PROFILE(syscall_linux_setlease
);
225 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct
*handle
,
233 char real_pathname
[PATH_MAX
+1];
236 struct gpfs_config_data
*config
;
238 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
239 struct gpfs_config_data
,
242 if (!config
->getrealfilename
) {
243 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
244 mem_ctx
, found_name
);
247 mangled
= mangle_is_mangled(name
, handle
->conn
->params
);
249 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
250 mem_ctx
, found_name
);
253 full_path
= talloc_asprintf(talloc_tos(), "%s/%s", path
, name
);
254 if (full_path
== NULL
) {
259 buflen
= sizeof(real_pathname
) - 1;
261 result
= gpfswrap_get_realfilename_path(full_path
, real_pathname
,
264 TALLOC_FREE(full_path
);
266 if ((result
== -1) && (errno
== ENOSYS
)) {
267 return SMB_VFS_NEXT_GET_REAL_FILENAME(
268 handle
, path
, name
, mem_ctx
, found_name
);
272 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
278 * GPFS does not necessarily null-terminate the returned path
279 * but instead returns the buffer length in buflen.
282 if (buflen
< sizeof(real_pathname
)) {
283 real_pathname
[buflen
] = '\0';
285 real_pathname
[sizeof(real_pathname
)-1] = '\0';
288 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
289 path
, name
, real_pathname
));
291 name
= strrchr_m(real_pathname
, '/');
297 *found_name
= talloc_strdup(mem_ctx
, name
+1);
298 if (*found_name
== NULL
) {
306 static void sd2gpfs_control(uint16_t control
, struct gpfs_acl
*gacl
)
308 unsigned int gpfs_aclflags
= 0;
309 control
&= SEC_DESC_DACL_PROTECTED
| SEC_DESC_SACL_PROTECTED
|
310 SEC_DESC_DACL_AUTO_INHERITED
| SEC_DESC_SACL_AUTO_INHERITED
|
311 SEC_DESC_DACL_DEFAULTED
| SEC_DESC_SACL_DEFAULTED
|
312 SEC_DESC_DACL_PRESENT
| SEC_DESC_SACL_PRESENT
;
313 gpfs_aclflags
= control
<< 8;
314 if (!(control
& SEC_DESC_DACL_PRESENT
))
315 gpfs_aclflags
|= ACL4_FLAG_NULL_DACL
;
316 if (!(control
& SEC_DESC_SACL_PRESENT
))
317 gpfs_aclflags
|= ACL4_FLAG_NULL_SACL
;
318 gacl
->acl_level
= GPFS_ACL_LEVEL_V4FLAGS
;
319 gacl
->v4Level1
.acl_flags
= gpfs_aclflags
;
322 static uint16_t gpfs2sd_control(unsigned int gpfs_aclflags
)
324 uint16_t control
= gpfs_aclflags
>> 8;
325 control
&= SEC_DESC_DACL_PROTECTED
| SEC_DESC_SACL_PROTECTED
|
326 SEC_DESC_DACL_AUTO_INHERITED
| SEC_DESC_SACL_AUTO_INHERITED
|
327 SEC_DESC_DACL_DEFAULTED
| SEC_DESC_SACL_DEFAULTED
|
328 SEC_DESC_DACL_PRESENT
| SEC_DESC_SACL_PRESENT
;
329 control
|= SEC_DESC_SELF_RELATIVE
;
333 static void gpfs_dumpacl(int level
, struct gpfs_acl
*gacl
)
338 DEBUG(0, ("gpfs acl is NULL\n"));
342 DEBUG(level
, ("len: %d, level: %d, version: %d, nace: %d, "
344 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
345 gacl
->acl_nace
, gpfs_acl_flags(gacl
)));
347 for(i
=0; i
<gacl
->acl_nace
; i
++)
349 struct gpfs_ace_v4
*gace
= gpfs_ace_ptr(gacl
, i
);
350 DEBUG(level
, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, "
351 "iflags:0x%x, who:%u\n",
352 i
, gace
->aceType
, gace
->aceFlags
, gace
->aceMask
,
353 gace
->aceIFlags
, gace
->aceWho
));
358 * get the ACL from GPFS, allocated on the specified mem_ctx
359 * internally retries when initial buffer was too small
361 * caller needs to cast result to either
362 * raw = yes: struct gpfs_opaque_acl
363 * raw = no: struct gpfs_acl
366 static void *vfs_gpfs_getacl(TALLOC_CTX
*mem_ctx
,
369 const gpfs_aclType_t type
)
380 aclbuf
= talloc_zero_size(mem_ctx
, size
);
381 if (aclbuf
== NULL
) {
387 struct gpfs_opaque_acl
*buf
= (struct gpfs_opaque_acl
*) aclbuf
;
388 buf
->acl_type
= type
;
389 flags
= GPFS_GETACL_NATIVE
;
390 len
= (unsigned int *) &(buf
->acl_buffer_len
);
391 struct_size
= sizeof(struct gpfs_opaque_acl
);
393 struct gpfs_acl
*buf
= (struct gpfs_acl
*) aclbuf
;
394 buf
->acl_type
= type
;
395 buf
->acl_level
= GPFS_ACL_LEVEL_V4FLAGS
;
396 flags
= GPFS_GETACL_STRUCT
;
397 len
= &(buf
->acl_len
);
398 /* reserve space for control flags in gpfs 3.5 and beyond */
399 struct_size
= sizeof(struct gpfs_acl
) + sizeof(unsigned int);
402 /* set the length of the buffer as input value */
406 ret
= gpfswrap_getacl(discard_const_p(char, fname
), flags
, aclbuf
);
407 if ((ret
!= 0) && (errno
== ENOSPC
)) {
409 * get the size needed to accommodate the complete buffer
411 * the value returned only applies to the ACL blob in the
412 * struct so make sure to also have headroom for the first
413 * struct members by adding room for the complete struct
414 * (might be a few bytes too much then)
416 size
= *len
+ struct_size
;
418 DEBUG(10, ("Increasing ACL buffer size to %zu\n", size
));
423 DEBUG(5, ("smbd_gpfs_getacl failed with %s\n",
432 /* Tries to get nfs4 acls and returns SMB ACL allocated.
433 * On failure returns 1 if it got non-NFSv4 ACL to prompt
434 * retry with POSIX ACL checks.
435 * On failure returns -1 if there is system (GPFS) error, check errno.
436 * Returns 0 on success
438 static int gpfs_get_nfs4_acl(TALLOC_CTX
*mem_ctx
, const char *fname
,
439 struct SMB4ACL_T
**ppacl
)
442 struct gpfs_acl
*gacl
= NULL
;
443 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname
));
446 gacl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(), fname
,
449 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
450 fname
, strerror(errno
)));
451 if (errno
== ENODATA
) {
453 * GPFS returns ENODATA for snapshot
454 * directories. Retry with POSIX ACLs check.
462 if (gacl
->acl_type
!= GPFS_ACL_TYPE_NFS4
) {
463 DEBUG(10, ("Got non-nfsv4 acl\n"));
464 /* Retry with POSIX ACLs check */
469 *ppacl
= smb_create_smb4acl(mem_ctx
);
471 if (gacl
->acl_level
== GPFS_ACL_LEVEL_V4FLAGS
) {
472 uint16_t control
= gpfs2sd_control(gpfs_acl_flags(gacl
));
473 smbacl4_set_controlflags(*ppacl
, control
);
476 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d, control: %x\n",
477 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
478 gacl
->acl_nace
, gpfs_acl_flags(gacl
)));
480 for (i
=0; i
<gacl
->acl_nace
; i
++) {
481 struct gpfs_ace_v4
*gace
= gpfs_ace_ptr(gacl
, i
);
482 SMB_ACE4PROP_T smbace
= { 0 };
483 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
484 "who: %d\n", gace
->aceType
, gace
->aceIFlags
,
485 gace
->aceFlags
, gace
->aceMask
, gace
->aceWho
));
487 if (gace
->aceIFlags
& ACE4_IFLAG_SPECIAL_ID
) {
488 smbace
.flags
|= SMB_ACE4_ID_SPECIAL
;
489 switch (gace
->aceWho
) {
490 case ACE4_SPECIAL_OWNER
:
491 smbace
.who
.special_id
= SMB_ACE4_WHO_OWNER
;
493 case ACE4_SPECIAL_GROUP
:
494 smbace
.who
.special_id
= SMB_ACE4_WHO_GROUP
;
496 case ACE4_SPECIAL_EVERYONE
:
497 smbace
.who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
500 DEBUG(8, ("invalid special gpfs id %d "
501 "ignored\n", gace
->aceWho
));
502 continue; /* don't add it */
505 if (gace
->aceFlags
& ACE4_FLAG_GROUP_ID
)
506 smbace
.who
.gid
= gace
->aceWho
;
508 smbace
.who
.uid
= gace
->aceWho
;
511 /* remove redundant deny entries */
512 if (i
> 0 && gace
->aceType
== SMB_ACE4_ACCESS_DENIED_ACE_TYPE
) {
513 struct gpfs_ace_v4
*prev
= gpfs_ace_ptr(gacl
, i
- 1);
514 if (prev
->aceType
== SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
&&
515 prev
->aceFlags
== gace
->aceFlags
&&
516 prev
->aceIFlags
== gace
->aceIFlags
&&
517 (gace
->aceMask
& prev
->aceMask
) == 0 &&
518 gace
->aceWho
== prev
->aceWho
) {
519 /* it's redundant - skip it */
524 smbace
.aceType
= gace
->aceType
;
525 smbace
.aceFlags
= gace
->aceFlags
;
526 smbace
.aceMask
= gace
->aceMask
;
527 smb_add_ace4(*ppacl
, &smbace
);
535 static NTSTATUS
gpfsacl_fget_nt_acl(vfs_handle_struct
*handle
,
536 files_struct
*fsp
, uint32_t security_info
,
538 struct security_descriptor
**ppdesc
)
540 struct SMB4ACL_T
*pacl
= NULL
;
542 struct gpfs_config_data
*config
;
543 TALLOC_CTX
*frame
= talloc_stackframe();
548 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
549 struct gpfs_config_data
,
550 return NT_STATUS_INTERNAL_ERROR
);
553 status
= SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
559 result
= gpfs_get_nfs4_acl(frame
, fsp
->fsp_name
->base_name
, &pacl
);
562 status
= smb_fget_nt_acl_nfs4(fsp
, security_info
, mem_ctx
,
569 DEBUG(10, ("retrying with posix acl...\n"));
570 status
= posix_fget_nt_acl(fsp
, security_info
,
578 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
579 return map_nt_error_from_unix(errno
);
582 static NTSTATUS
gpfsacl_get_nt_acl(vfs_handle_struct
*handle
,
584 uint32_t security_info
,
585 TALLOC_CTX
*mem_ctx
, struct security_descriptor
**ppdesc
)
587 struct SMB4ACL_T
*pacl
= NULL
;
589 struct gpfs_config_data
*config
;
590 TALLOC_CTX
*frame
= talloc_stackframe();
595 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
596 struct gpfs_config_data
,
597 return NT_STATUS_INTERNAL_ERROR
);
600 status
= SMB_VFS_NEXT_GET_NT_ACL(handle
, name
, security_info
,
606 result
= gpfs_get_nfs4_acl(frame
, name
, &pacl
);
609 status
= smb_get_nt_acl_nfs4(handle
->conn
, name
, security_info
,
610 mem_ctx
, ppdesc
, pacl
);
616 DEBUG(10, ("retrying with posix acl...\n"));
617 status
= posix_get_nt_acl(handle
->conn
, name
, security_info
,
623 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
625 return map_nt_error_from_unix(errno
);
628 static struct gpfs_acl
*vfs_gpfs_smbacl2gpfsacl(TALLOC_CTX
*mem_ctx
,
630 struct SMB4ACL_T
*smbacl
,
633 struct gpfs_acl
*gacl
;
634 gpfs_aclLen_t gacl_len
;
635 struct SMB4ACE_T
*smbace
;
637 gacl_len
= offsetof(gpfs_acl_t
, ace_v4
) + sizeof(unsigned int)
638 + smb_get_naces(smbacl
) * sizeof(gpfs_ace_v4_t
);
640 gacl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, gacl_len
);
642 DEBUG(0, ("talloc failed\n"));
647 gacl
->acl_level
= GPFS_ACL_LEVEL_BASE
;
648 gacl
->acl_version
= GPFS_ACL_VERSION_NFS4
;
649 gacl
->acl_type
= GPFS_ACL_TYPE_NFS4
;
650 gacl
->acl_nace
= 0; /* change later... */
653 gacl
->acl_level
= GPFS_ACL_LEVEL_V4FLAGS
;
654 sd2gpfs_control(smbacl4_get_controlflags(smbacl
), gacl
);
657 for (smbace
=smb_first_ace4(smbacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
658 struct gpfs_ace_v4
*gace
= gpfs_ace_ptr(gacl
, gacl
->acl_nace
);
659 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
661 gace
->aceType
= aceprop
->aceType
;
662 gace
->aceFlags
= aceprop
->aceFlags
;
663 gace
->aceMask
= aceprop
->aceMask
;
666 * GPFS can't distinguish between WRITE and APPEND on
667 * files, so one being set without the other is an
668 * error. Sorry for the many ()'s :-)
671 if (!fsp
->is_directory
673 ((((gace
->aceMask
& ACE4_MASK_WRITE
) == 0)
674 && ((gace
->aceMask
& ACE4_MASK_APPEND
) != 0))
676 (((gace
->aceMask
& ACE4_MASK_WRITE
) != 0)
677 && ((gace
->aceMask
& ACE4_MASK_APPEND
) == 0)))
679 lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
680 "merge_writeappend", True
)) {
681 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
682 "WRITE^APPEND, setting WRITE|APPEND\n",
684 gace
->aceMask
|= ACE4_MASK_WRITE
|ACE4_MASK_APPEND
;
687 gace
->aceIFlags
= (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
) ? ACE4_IFLAG_SPECIAL_ID
: 0;
689 if (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
)
691 switch(aceprop
->who
.special_id
)
693 case SMB_ACE4_WHO_EVERYONE
:
694 gace
->aceWho
= ACE4_SPECIAL_EVERYONE
;
696 case SMB_ACE4_WHO_OWNER
:
697 gace
->aceWho
= ACE4_SPECIAL_OWNER
;
699 case SMB_ACE4_WHO_GROUP
:
700 gace
->aceWho
= ACE4_SPECIAL_GROUP
;
703 DEBUG(8, ("unsupported special_id %d\n", aceprop
->who
.special_id
));
704 continue; /* don't add it !!! */
707 /* just only for the type safety... */
708 if (aceprop
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)
709 gace
->aceWho
= aceprop
->who
.gid
;
711 gace
->aceWho
= aceprop
->who
.uid
;
716 gacl
->acl_len
= (char *)gpfs_ace_ptr(gacl
, gacl
->acl_nace
)
721 static bool gpfsacl_process_smbacl(vfs_handle_struct
*handle
,
723 struct SMB4ACL_T
*smbacl
)
726 struct gpfs_acl
*gacl
;
727 TALLOC_CTX
*mem_ctx
= talloc_tos();
729 gacl
= vfs_gpfs_smbacl2gpfsacl(mem_ctx
, fsp
, smbacl
, true);
730 if (gacl
== NULL
) { /* out of memory */
733 ret
= gpfswrap_putacl(fsp
->fsp_name
->base_name
,
734 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gacl
);
736 if ((ret
!= 0) && (errno
== EINVAL
)) {
737 DEBUG(10, ("Retry without nfs41 control flags\n"));
739 gacl
= vfs_gpfs_smbacl2gpfsacl(mem_ctx
, fsp
, smbacl
, false);
740 if (gacl
== NULL
) { /* out of memory */
743 ret
= gpfswrap_putacl(fsp
->fsp_name
->base_name
,
744 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
,
749 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno
)));
750 gpfs_dumpacl(8, gacl
);
754 DEBUG(10, ("gpfs_putacl succeeded\n"));
758 static NTSTATUS
gpfsacl_set_nt_acl_internal(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32_t security_info_sent
, const struct security_descriptor
*psd
)
760 struct gpfs_acl
*acl
;
761 NTSTATUS result
= NT_STATUS_ACCESS_DENIED
;
763 acl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(),
764 fsp
->fsp_name
->base_name
,
767 return map_nt_error_from_unix(errno
);
770 if (acl
->acl_version
== GPFS_ACL_VERSION_NFS4
) {
771 if (lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
772 "refuse_dacl_protected", false)
773 && (psd
->type
&SEC_DESC_DACL_PROTECTED
)) {
774 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
776 return NT_STATUS_NOT_SUPPORTED
;
779 result
= smb_set_nt_acl_nfs4(handle
,
780 fsp
, security_info_sent
, psd
,
781 gpfsacl_process_smbacl
);
782 } else { /* assume POSIX ACL - by default... */
783 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
790 static NTSTATUS
gpfsacl_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32_t security_info_sent
, const struct security_descriptor
*psd
)
792 struct gpfs_config_data
*config
;
794 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
795 struct gpfs_config_data
,
796 return NT_STATUS_INTERNAL_ERROR
);
799 return SMB_VFS_NEXT_FSET_NT_ACL(handle
, fsp
, security_info_sent
, psd
);
802 return gpfsacl_set_nt_acl_internal(handle
, fsp
, security_info_sent
, psd
);
805 static SMB_ACL_T
gpfs2smb_acl(const struct gpfs_acl
*pacl
, TALLOC_CTX
*mem_ctx
)
810 result
= sys_acl_init(mem_ctx
);
811 if (result
== NULL
) {
816 result
->count
= pacl
->acl_nace
;
817 result
->acl
= talloc_realloc(result
, result
->acl
, struct smb_acl_entry
,
819 if (result
->acl
== NULL
) {
825 for (i
=0; i
<pacl
->acl_nace
; i
++) {
826 struct smb_acl_entry
*ace
= &result
->acl
[i
];
827 const struct gpfs_ace_v1
*g_ace
= &pacl
->ace_v1
[i
];
829 DEBUG(10, ("Converting type %d id %lu perm %x\n",
830 (int)g_ace
->ace_type
, (unsigned long)g_ace
->ace_who
,
831 (int)g_ace
->ace_perm
));
833 switch (g_ace
->ace_type
) {
835 ace
->a_type
= SMB_ACL_USER
;
836 ace
->info
.user
.uid
= (uid_t
)g_ace
->ace_who
;
838 case GPFS_ACL_USER_OBJ
:
839 ace
->a_type
= SMB_ACL_USER_OBJ
;
842 ace
->a_type
= SMB_ACL_GROUP
;
843 ace
->info
.group
.gid
= (gid_t
)g_ace
->ace_who
;
845 case GPFS_ACL_GROUP_OBJ
:
846 ace
->a_type
= SMB_ACL_GROUP_OBJ
;
849 ace
->a_type
= SMB_ACL_OTHER
;
852 ace
->a_type
= SMB_ACL_MASK
;
855 DEBUG(10, ("Got invalid ace_type: %d\n",
863 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_READ
) ?
865 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_WRITE
) ?
867 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_EXECUTE
) ?
870 DEBUGADD(10, ("Converted to %d perm %x\n",
871 ace
->a_type
, ace
->a_perm
));
877 static SMB_ACL_T
gpfsacl_get_posix_acl(const char *path
, gpfs_aclType_t type
,
880 struct gpfs_acl
*pacl
;
881 SMB_ACL_T result
= NULL
;
883 pacl
= vfs_gpfs_getacl(talloc_tos(), path
, false, type
);
886 DEBUG(10, ("vfs_gpfs_getacl failed for %s with %s\n",
887 path
, strerror(errno
)));
894 if (pacl
->acl_version
!= GPFS_ACL_VERSION_POSIX
) {
895 DEBUG(10, ("Got acl version %d, expected %d\n",
896 pacl
->acl_version
, GPFS_ACL_VERSION_POSIX
));
901 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
902 pacl
->acl_len
, pacl
->acl_level
, pacl
->acl_version
,
905 result
= gpfs2smb_acl(pacl
, mem_ctx
);
906 if (result
!= NULL
) {
921 static SMB_ACL_T
gpfsacl_sys_acl_get_file(vfs_handle_struct
*handle
,
926 gpfs_aclType_t gpfs_type
;
927 struct gpfs_config_data
*config
;
929 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
930 struct gpfs_config_data
,
934 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle
, path_p
,
939 case SMB_ACL_TYPE_ACCESS
:
940 gpfs_type
= GPFS_ACL_TYPE_ACCESS
;
942 case SMB_ACL_TYPE_DEFAULT
:
943 gpfs_type
= GPFS_ACL_TYPE_DEFAULT
;
946 DEBUG(0, ("Got invalid type: %d\n", type
));
947 smb_panic("exiting");
950 return gpfsacl_get_posix_acl(path_p
, gpfs_type
, mem_ctx
);
953 static SMB_ACL_T
gpfsacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
957 struct gpfs_config_data
*config
;
959 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
960 struct gpfs_config_data
,
964 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle
, fsp
, mem_ctx
);
967 return gpfsacl_get_posix_acl(fsp
->fsp_name
->base_name
,
968 GPFS_ACL_TYPE_ACCESS
, mem_ctx
);
971 static int gpfsacl_sys_acl_blob_get_file(vfs_handle_struct
*handle
,
974 char **blob_description
,
977 struct gpfs_config_data
*config
;
978 struct gpfs_opaque_acl
*acl
= NULL
;
982 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
983 struct gpfs_config_data
,
987 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle
, path_p
,
994 acl
= (struct gpfs_opaque_acl
*)
995 vfs_gpfs_getacl(mem_ctx
,
1001 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
1002 errno
, strerror(errno
)));
1004 /* EINVAL means POSIX ACL, bail out on other cases */
1005 if (errno
!= EINVAL
) {
1012 * file has NFSv4 ACL
1014 * we only need the actual ACL blob here
1015 * acl_version will always be NFS4 because we asked
1017 * acl_type is only used for POSIX ACLs
1019 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
1020 aclblob
.length
= acl
->acl_buffer_len
;
1022 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
1023 if (!*blob_description
) {
1029 result
= non_posix_sys_acl_blob_get_file_helper(handle
, path_p
,
1037 /* fall back to POSIX ACL */
1038 return posix_sys_acl_blob_get_file(handle
, path_p
, mem_ctx
,
1039 blob_description
, blob
);
1042 static int gpfsacl_sys_acl_blob_get_fd(vfs_handle_struct
*handle
,
1044 TALLOC_CTX
*mem_ctx
,
1045 char **blob_description
,
1048 struct gpfs_config_data
*config
;
1049 struct gpfs_opaque_acl
*acl
= NULL
;
1053 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1054 struct gpfs_config_data
,
1058 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle
, fsp
, mem_ctx
,
1059 blob_description
, blob
);
1063 acl
= (struct gpfs_opaque_acl
*) vfs_gpfs_getacl(mem_ctx
,
1064 fsp
->fsp_name
->base_name
,
1066 GPFS_ACL_TYPE_NFS4
);
1069 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
1070 errno
, strerror(errno
)));
1072 /* EINVAL means POSIX ACL, bail out on other cases */
1073 if (errno
!= EINVAL
) {
1080 * file has NFSv4 ACL
1082 * we only need the actual ACL blob here
1083 * acl_version will always be NFS4 because we asked
1085 * acl_type is only used for POSIX ACLs
1087 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
1088 aclblob
.length
= acl
->acl_buffer_len
;
1090 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
1091 if (!*blob_description
) {
1097 result
= non_posix_sys_acl_blob_get_fd_helper(handle
, fsp
,
1105 /* fall back to POSIX ACL */
1106 return posix_sys_acl_blob_get_fd(handle
, fsp
, mem_ctx
,
1107 blob_description
, blob
);
1110 static struct gpfs_acl
*smb2gpfs_acl(const SMB_ACL_T pacl
,
1111 SMB_ACL_TYPE_T type
)
1114 struct gpfs_acl
*result
;
1117 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl
->count
));
1119 len
= offsetof(gpfs_acl_t
, ace_v1
) + (pacl
->count
) *
1120 sizeof(gpfs_ace_v1_t
);
1122 result
= (struct gpfs_acl
*)SMB_MALLOC(len
);
1123 if (result
== NULL
) {
1128 result
->acl_len
= len
;
1129 result
->acl_level
= 0;
1130 result
->acl_version
= GPFS_ACL_VERSION_POSIX
;
1131 result
->acl_type
= (type
== SMB_ACL_TYPE_DEFAULT
) ?
1132 GPFS_ACL_TYPE_DEFAULT
: GPFS_ACL_TYPE_ACCESS
;
1133 result
->acl_nace
= pacl
->count
;
1135 for (i
=0; i
<pacl
->count
; i
++) {
1136 const struct smb_acl_entry
*ace
= &pacl
->acl
[i
];
1137 struct gpfs_ace_v1
*g_ace
= &result
->ace_v1
[i
];
1139 DEBUG(10, ("Converting type %d perm %x\n",
1140 (int)ace
->a_type
, (int)ace
->a_perm
));
1142 g_ace
->ace_perm
= 0;
1144 switch(ace
->a_type
) {
1146 g_ace
->ace_type
= GPFS_ACL_USER
;
1147 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.user
.uid
;
1149 case SMB_ACL_USER_OBJ
:
1150 g_ace
->ace_type
= GPFS_ACL_USER_OBJ
;
1151 g_ace
->ace_perm
|= ACL_PERM_CONTROL
;
1155 g_ace
->ace_type
= GPFS_ACL_GROUP
;
1156 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.group
.gid
;
1158 case SMB_ACL_GROUP_OBJ
:
1159 g_ace
->ace_type
= GPFS_ACL_GROUP_OBJ
;
1163 g_ace
->ace_type
= GPFS_ACL_MASK
;
1164 g_ace
->ace_perm
= 0x8f;
1168 g_ace
->ace_type
= GPFS_ACL_OTHER
;
1172 DEBUG(10, ("Got invalid ace_type: %d\n", ace
->a_type
));
1178 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_READ
) ?
1180 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_WRITE
) ?
1182 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_EXECUTE
) ?
1183 ACL_PERM_EXECUTE
: 0;
1185 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
1186 g_ace
->ace_type
, g_ace
->ace_who
, g_ace
->ace_perm
));
1192 static int gpfsacl_sys_acl_set_file(vfs_handle_struct
*handle
,
1194 SMB_ACL_TYPE_T type
,
1197 struct gpfs_acl
*gpfs_acl
;
1199 struct gpfs_config_data
*config
;
1201 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1202 struct gpfs_config_data
,
1206 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle
, name
, type
, theacl
);
1209 gpfs_acl
= smb2gpfs_acl(theacl
, type
);
1210 if (gpfs_acl
== NULL
) {
1214 result
= gpfswrap_putacl(discard_const_p(char, name
),
1215 GPFS_PUTACL_STRUCT
|GPFS_ACL_SAMBA
, gpfs_acl
);
1217 SAFE_FREE(gpfs_acl
);
1221 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
1225 struct gpfs_config_data
*config
;
1227 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1228 struct gpfs_config_data
,
1232 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle
, fsp
, theacl
);
1235 return gpfsacl_sys_acl_set_file(handle
, fsp
->fsp_name
->base_name
,
1236 SMB_ACL_TYPE_ACCESS
, theacl
);
1239 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
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_DELETE_DEF_FILE(handle
, path
);
1257 * Assumed: mode bits are shiftable and standard
1258 * Output: the new aceMask field for an smb nfs4 ace
1260 static uint32_t gpfsacl_mask_filter(uint32_t aceType
, uint32_t aceMask
, uint32_t rwx
)
1262 const uint32_t posix_nfs4map
[3] = {
1263 SMB_ACE4_EXECUTE
, /* execute */
1264 SMB_ACE4_WRITE_DATA
| SMB_ACE4_APPEND_DATA
, /* write; GPFS specific */
1265 SMB_ACE4_READ_DATA
/* read */
1268 uint32_t posix_mask
= 0x01;
1272 for(i
=0; i
<3; i
++) {
1273 nfs4_bits
= posix_nfs4map
[i
];
1274 posix_bit
= rwx
& posix_mask
;
1276 if (aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
) {
1278 aceMask
|= nfs4_bits
;
1280 aceMask
&= ~nfs4_bits
;
1282 /* add deny bits when suitable */
1284 aceMask
|= nfs4_bits
;
1286 aceMask
&= ~nfs4_bits
;
1287 } /* other ace types are unexpected */
1295 static int gpfsacl_emu_chmod(vfs_handle_struct
*handle
,
1296 const char *path
, mode_t mode
)
1298 struct SMB4ACL_T
*pacl
= NULL
;
1300 bool haveAllowEntry
[SMB_ACE4_WHO_EVERYONE
+ 1] = {False
, False
, False
, False
};
1302 files_struct fake_fsp
= { 0 }; /* TODO: rationalize parametrization */
1303 struct SMB4ACE_T
*smbace
;
1304 TALLOC_CTX
*frame
= talloc_stackframe();
1306 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path
, mode
));
1308 result
= gpfs_get_nfs4_acl(frame
, path
, &pacl
);
1314 if (mode
& ~(S_IRWXU
| S_IRWXG
| S_IRWXO
)) {
1315 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode
, path
));
1318 for (smbace
=smb_first_ace4(pacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
1319 SMB_ACE4PROP_T
*ace
= smb_get_ace4(smbace
);
1320 uint32_t specid
= ace
->who
.special_id
;
1322 if (ace
->flags
&SMB_ACE4_ID_SPECIAL
&&
1323 ace
->aceType
<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE
&&
1324 specid
<= SMB_ACE4_WHO_EVERYONE
) {
1328 if (ace
->aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
)
1329 haveAllowEntry
[specid
] = True
;
1331 /* mode >> 6 for @owner, mode >> 3 for @group,
1332 * mode >> 0 for @everyone */
1333 newMask
= gpfsacl_mask_filter(ace
->aceType
, ace
->aceMask
,
1334 mode
>> ((SMB_ACE4_WHO_EVERYONE
- specid
) * 3));
1335 if (ace
->aceMask
!=newMask
) {
1336 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
1337 path
, ace
->aceMask
, newMask
, specid
));
1339 ace
->aceMask
= newMask
;
1343 /* make sure we have at least ALLOW entries
1344 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
1347 for(i
= SMB_ACE4_WHO_OWNER
; i
<=SMB_ACE4_WHO_EVERYONE
; i
++) {
1348 SMB_ACE4PROP_T ace
= { 0 };
1350 if (haveAllowEntry
[i
]==True
)
1353 ace
.aceType
= SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
;
1354 ace
.flags
|= SMB_ACE4_ID_SPECIAL
;
1355 ace
.who
.special_id
= i
;
1357 if (i
==SMB_ACE4_WHO_GROUP
) /* not sure it's necessary... */
1358 ace
.aceFlags
|= SMB_ACE4_IDENTIFIER_GROUP
;
1360 ace
.aceMask
= gpfsacl_mask_filter(ace
.aceType
, ace
.aceMask
,
1361 mode
>> ((SMB_ACE4_WHO_EVERYONE
- i
) * 3));
1363 /* don't add unnecessary aces */
1367 /* we add it to the END - as windows expects allow aces */
1368 smb_add_ace4(pacl
, &ace
);
1369 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1370 path
, mode
, i
, ace
.aceMask
));
1373 /* don't add complementary DENY ACEs here */
1374 fake_fsp
.fsp_name
= synthetic_smb_fname(
1375 frame
, path
, NULL
, NULL
);
1376 if (fake_fsp
.fsp_name
== NULL
) {
1382 if (gpfsacl_process_smbacl(handle
, &fake_fsp
, pacl
) == False
) {
1388 return 0; /* ok for [f]chmod */
1391 static int vfs_gpfs_chmod(vfs_handle_struct
*handle
, const char *path
, mode_t mode
)
1393 struct smb_filename
*smb_fname_cpath
;
1396 smb_fname_cpath
= synthetic_smb_fname(talloc_tos(), path
, NULL
, NULL
);
1397 if (smb_fname_cpath
== NULL
) {
1402 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_cpath
) != 0) {
1406 /* avoid chmod() if possible, to preserve acls */
1407 if ((smb_fname_cpath
->st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1411 rc
= gpfsacl_emu_chmod(handle
, path
, mode
);
1413 return SMB_VFS_NEXT_CHMOD(handle
, path
, mode
);
1417 static int vfs_gpfs_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
1422 if (SMB_VFS_NEXT_FSTAT(handle
, fsp
, &st
) != 0) {
1426 /* avoid chmod() if possible, to preserve acls */
1427 if ((st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1431 rc
= gpfsacl_emu_chmod(handle
, fsp
->fsp_name
->base_name
,
1434 return SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
1438 static int gpfs_set_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1439 const char *name
, const void *value
, size_t size
, int flags
){
1440 struct xattr_DOSATTRIB dosattrib
;
1441 enum ndr_err_code ndr_err
;
1443 unsigned int dosmode
=0;
1444 struct gpfs_winattr attrs
;
1446 struct gpfs_config_data
*config
;
1448 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1449 struct gpfs_config_data
,
1452 if (!config
->winattr
) {
1453 DEBUG(10, ("gpfs_set_xattr:name is %s -> next\n",name
));
1454 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1457 DEBUG(10, ("gpfs_set_xattr: %s \n",path
));
1459 /* Only handle DOS Attributes */
1460 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1461 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name
));
1462 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1465 blob
.data
= discard_const_p(uint8_t, value
);
1468 ndr_err
= ndr_pull_struct_blob(&blob
, talloc_tos(), &dosattrib
,
1469 (ndr_pull_flags_fn_t
)ndr_pull_xattr_DOSATTRIB
);
1471 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1472 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
1473 "from EA on file %s: Error = %s\n",
1474 path
, ndr_errstr(ndr_err
)));
1478 if (dosattrib
.version
!= 3) {
1479 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
1480 "%d\n", (int)dosattrib
.version
));
1483 if (!(dosattrib
.info
.info3
.valid_flags
& XATTR_DOSINFO_ATTRIB
)) {
1484 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
1485 "valid, ignoring\n"));
1489 dosmode
= dosattrib
.info
.info3
.attrib
;
1492 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
1493 if (dosmode
& FILE_ATTRIBUTE_ARCHIVE
){
1494 attrs
.winAttrs
|= GPFS_WINATTR_ARCHIVE
;
1496 if (dosmode
& FILE_ATTRIBUTE_HIDDEN
){
1497 attrs
.winAttrs
|= GPFS_WINATTR_HIDDEN
;
1499 if (dosmode
& FILE_ATTRIBUTE_SYSTEM
){
1500 attrs
.winAttrs
|= GPFS_WINATTR_SYSTEM
;
1502 if (dosmode
& FILE_ATTRIBUTE_READONLY
){
1503 attrs
.winAttrs
|= GPFS_WINATTR_READONLY
;
1505 if (dosmode
& FILE_ATTRIBUTE_SPARSE
) {
1506 attrs
.winAttrs
|= GPFS_WINATTR_SPARSE_FILE
;
1510 ret
= gpfswrap_set_winattrs_path(discard_const_p(char, path
),
1511 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1513 if (errno
== ENOSYS
) {
1514 return SMB_VFS_NEXT_SETXATTR(handle
, path
, name
, value
,
1518 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret
));
1522 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs
.winAttrs
));
1526 static ssize_t
gpfs_get_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1527 const char *name
, void *value
, size_t size
){
1528 char *attrstr
= value
;
1529 unsigned int dosmode
= 0;
1530 struct gpfs_winattr attrs
;
1532 struct gpfs_config_data
*config
;
1534 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1535 struct gpfs_config_data
,
1538 if (!config
->winattr
) {
1539 DEBUG(10, ("gpfs_get_xattr:name is %s -> next\n",name
));
1540 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1543 DEBUG(10, ("gpfs_get_xattr: %s \n",path
));
1545 /* Only handle DOS Attributes */
1546 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1547 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name
));
1548 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1551 ret
= gpfswrap_get_winattrs_path(discard_const_p(char, path
), &attrs
);
1555 if (errno
== ENOSYS
) {
1556 return SMB_VFS_NEXT_GETXATTR(handle
, path
, name
, value
,
1560 if (errno
!= EPERM
&& errno
!= EACCES
) {
1565 DEBUG(dbg_lvl
, ("gpfs_get_xattr: Get GPFS attributes failed: "
1566 "%d (%s)\n", ret
, strerror(errno
)));
1570 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs
.winAttrs
));
1572 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1573 if (attrs
.winAttrs
& GPFS_WINATTR_ARCHIVE
){
1574 dosmode
|= FILE_ATTRIBUTE_ARCHIVE
;
1576 if (attrs
.winAttrs
& GPFS_WINATTR_HIDDEN
){
1577 dosmode
|= FILE_ATTRIBUTE_HIDDEN
;
1579 if (attrs
.winAttrs
& GPFS_WINATTR_SYSTEM
){
1580 dosmode
|= FILE_ATTRIBUTE_SYSTEM
;
1582 if (attrs
.winAttrs
& GPFS_WINATTR_READONLY
){
1583 dosmode
|= FILE_ATTRIBUTE_READONLY
;
1585 if (attrs
.winAttrs
& GPFS_WINATTR_SPARSE_FILE
) {
1586 dosmode
|= FILE_ATTRIBUTE_SPARSE
;
1589 snprintf(attrstr
, size
, "0x%2.2x",
1590 (unsigned int)(dosmode
& SAMBA_ATTRIBUTES_MASK
));
1591 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr
));
1595 #if defined(HAVE_FSTATAT)
1596 static int stat_with_capability(struct vfs_handle_struct
*handle
,
1597 struct smb_filename
*smb_fname
, int flag
)
1602 const char *rel_name
= NULL
;
1606 b
= parent_dirname(talloc_tos(), smb_fname
->base_name
,
1607 &dir_name
, &rel_name
);
1613 fd
= open(dir_name
, O_RDONLY
, 0);
1614 TALLOC_FREE(dir_name
);
1619 set_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1620 ret
= fstatat(fd
, rel_name
, &st
, flag
);
1621 drop_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1626 init_stat_ex_from_stat(
1627 &smb_fname
->st
, &st
,
1628 lp_fake_directory_create_times(SNUM(handle
->conn
)));
1635 static int vfs_gpfs_stat(struct vfs_handle_struct
*handle
,
1636 struct smb_filename
*smb_fname
)
1638 struct gpfs_winattr attrs
;
1642 struct gpfs_config_data
*config
;
1644 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1645 struct gpfs_config_data
,
1648 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
1649 #if defined(HAVE_FSTATAT)
1650 if (ret
== -1 && errno
== EACCES
) {
1651 DEBUG(10, ("Trying stat with capability for %s\n",
1652 smb_fname
->base_name
));
1653 ret
= stat_with_capability(handle
, smb_fname
, 0);
1660 if (!config
->winattr
) {
1664 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &fname
);
1665 if (!NT_STATUS_IS_OK(status
)) {
1666 errno
= map_errno_from_nt_status(status
);
1669 ret
= gpfswrap_get_winattrs_path(discard_const_p(char, fname
), &attrs
);
1672 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1673 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1674 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1679 static int vfs_gpfs_fstat(struct vfs_handle_struct
*handle
,
1680 struct files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
1682 struct gpfs_winattr attrs
;
1684 struct gpfs_config_data
*config
;
1686 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1687 struct gpfs_config_data
,
1690 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
1694 if ((fsp
->fh
== NULL
) || (fsp
->fh
->fd
== -1)) {
1697 if (!config
->winattr
) {
1701 ret
= gpfswrap_get_winattrs(fsp
->fh
->fd
, &attrs
);
1703 sbuf
->st_ex_calculated_birthtime
= false;
1704 sbuf
->st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1705 sbuf
->st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1710 static int vfs_gpfs_lstat(struct vfs_handle_struct
*handle
,
1711 struct smb_filename
*smb_fname
)
1713 struct gpfs_winattr attrs
;
1717 struct gpfs_config_data
*config
;
1719 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1720 struct gpfs_config_data
,
1723 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
1724 #if defined(HAVE_FSTATAT)
1725 if (ret
== -1 && errno
== EACCES
) {
1726 DEBUG(10, ("Trying lstat with capability for %s\n",
1727 smb_fname
->base_name
));
1728 ret
= stat_with_capability(handle
, smb_fname
,
1729 AT_SYMLINK_NOFOLLOW
);
1736 if (!config
->winattr
) {
1740 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1741 if (!NT_STATUS_IS_OK(status
)) {
1742 errno
= map_errno_from_nt_status(status
);
1745 ret
= gpfswrap_get_winattrs_path(discard_const_p(char, path
), &attrs
);
1748 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1749 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1750 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1755 static void timespec_to_gpfs_time(struct timespec ts
, gpfs_timestruc_t
*gt
,
1756 int idx
, int *flags
)
1758 if (!null_timespec(ts
)) {
1760 gt
[idx
].tv_sec
= ts
.tv_sec
;
1761 gt
[idx
].tv_nsec
= ts
.tv_nsec
;
1762 DEBUG(10, ("Setting GPFS time %d, flags 0x%x\n", idx
, *flags
));
1766 static int smbd_gpfs_set_times_path(char *path
, struct smb_file_time
*ft
)
1768 gpfs_timestruc_t gpfs_times
[4];
1772 ZERO_ARRAY(gpfs_times
);
1773 timespec_to_gpfs_time(ft
->atime
, gpfs_times
, 0, &flags
);
1774 timespec_to_gpfs_time(ft
->mtime
, gpfs_times
, 1, &flags
);
1775 /* No good mapping from LastChangeTime to ctime, not storing */
1776 timespec_to_gpfs_time(ft
->create_time
, gpfs_times
, 3, &flags
);
1779 DEBUG(10, ("nothing to do, return to avoid EINVAL\n"));
1783 rc
= gpfswrap_set_times_path(path
, flags
, gpfs_times
);
1785 if (rc
!= 0 && errno
!= ENOSYS
) {
1786 DEBUG(1,("gpfs_set_times() returned with error %s\n",
1793 static int vfs_gpfs_ntimes(struct vfs_handle_struct
*handle
,
1794 const struct smb_filename
*smb_fname
,
1795 struct smb_file_time
*ft
)
1798 struct gpfs_winattr attrs
;
1802 struct gpfs_config_data
*config
;
1804 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1805 struct gpfs_config_data
,
1808 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1809 if (!NT_STATUS_IS_OK(status
)) {
1810 errno
= map_errno_from_nt_status(status
);
1814 /* Try to use gpfs_set_times if it is enabled and available */
1815 if (config
->settimes
) {
1816 ret
= smbd_gpfs_set_times_path(path
, ft
);
1818 if (ret
== 0 || (ret
== -1 && errno
!= ENOSYS
)) {
1823 DEBUG(10,("gpfs_set_times() not available or disabled, "
1824 "use ntimes and winattr\n"));
1826 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1828 /* don't complain if access was denied */
1829 if (errno
!= EPERM
&& errno
!= EACCES
) {
1830 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1831 "%s", strerror(errno
)));
1836 if(null_timespec(ft
->create_time
)){
1837 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1841 if (!config
->winattr
) {
1846 attrs
.creationTime
.tv_sec
= ft
->create_time
.tv_sec
;
1847 attrs
.creationTime
.tv_nsec
= ft
->create_time
.tv_nsec
;
1849 ret
= gpfswrap_set_winattrs_path(discard_const_p(char, path
),
1850 GPFS_WINATTR_SET_CREATION_TIME
,
1852 if(ret
== -1 && errno
!= ENOSYS
){
1853 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret
));
1860 static int vfs_gpfs_fallocate(struct vfs_handle_struct
*handle
,
1861 struct files_struct
*fsp
, uint32_t mode
,
1862 off_t offset
, off_t len
)
1865 struct gpfs_config_data
*config
;
1867 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1868 struct gpfs_config_data
,
1871 if (!config
->prealloc
) {
1872 /* you should better not run fallocate() on GPFS at all */
1878 DEBUG(10, ("unmapped fallocate flags: %lx\n",
1879 (unsigned long)mode
));
1884 ret
= gpfswrap_prealloc(fsp
->fh
->fd
, offset
, len
);
1886 if (ret
== -1 && errno
!= ENOSYS
) {
1887 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno
)));
1888 } else if (ret
== -1 && errno
== ENOSYS
) {
1889 DEBUG(10, ("GPFS prealloc not supported.\n"));
1891 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1897 static int vfs_gpfs_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1901 struct gpfs_config_data
*config
;
1903 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1904 struct gpfs_config_data
,
1907 if (!config
->ftruncate
) {
1908 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1911 result
= gpfswrap_ftruncate(fsp
->fh
->fd
, len
);
1912 if ((result
== -1) && (errno
== ENOSYS
)) {
1913 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1918 static bool vfs_gpfs_is_offline(struct vfs_handle_struct
*handle
,
1919 const struct smb_filename
*fname
,
1920 SMB_STRUCT_STAT
*sbuf
)
1922 struct gpfs_winattr attrs
;
1925 struct gpfs_config_data
*config
;
1928 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1929 struct gpfs_config_data
,
1932 if (!config
->winattr
) {
1933 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1936 status
= get_full_smb_filename(talloc_tos(), fname
, &path
);
1937 if (!NT_STATUS_IS_OK(status
)) {
1938 errno
= map_errno_from_nt_status(status
);
1942 ret
= gpfswrap_get_winattrs_path(path
, &attrs
);
1948 if ((attrs
.winAttrs
& GPFS_WINATTR_OFFLINE
) != 0) {
1949 DEBUG(10, ("%s is offline\n", path
));
1953 DEBUG(10, ("%s is online\n", path
));
1955 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1958 static bool vfs_gpfs_fsp_is_offline(struct vfs_handle_struct
*handle
,
1959 struct files_struct
*fsp
)
1961 return vfs_gpfs_is_offline(handle
, fsp
->fsp_name
, &fsp
->fsp_name
->st
);
1964 static bool vfs_gpfs_aio_force(struct vfs_handle_struct
*handle
,
1965 struct files_struct
*fsp
)
1967 return vfs_gpfs_fsp_is_offline(handle
, fsp
);
1970 static ssize_t
vfs_gpfs_sendfile(vfs_handle_struct
*handle
, int tofd
,
1971 files_struct
*fsp
, const DATA_BLOB
*hdr
,
1972 off_t offset
, size_t n
)
1974 if (vfs_gpfs_fsp_is_offline(handle
, fsp
)) {
1978 return SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fsp
, hdr
, offset
, n
);
1981 static int vfs_gpfs_connect(struct vfs_handle_struct
*handle
,
1982 const char *service
, const char *user
)
1984 struct gpfs_config_data
*config
;
1987 gpfswrap_lib_init(0);
1989 config
= talloc_zero(handle
->conn
, struct gpfs_config_data
);
1991 DEBUG(0, ("talloc_zero() failed\n"));
1996 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1998 TALLOC_FREE(config
);
2002 config
->sharemodes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2003 "sharemodes", true);
2005 config
->leases
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2008 config
->hsm
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2011 config
->syncio
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2014 config
->winattr
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2017 config
->ftruncate
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2020 config
->getrealfilename
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2021 "getrealfilename", true);
2023 config
->dfreequota
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2024 "dfreequota", false);
2026 config
->prealloc
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2029 config
->acl
= lp_parm_bool(SNUM(handle
->conn
), "gpfs", "acl", true);
2031 config
->settimes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2033 config
->recalls
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2036 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
2037 NULL
, struct gpfs_config_data
,
2040 if (config
->leases
) {
2042 * GPFS lease code is based on kernel oplock code
2043 * so make sure it is turned on
2045 if (!lp_kernel_oplocks(SNUM(handle
->conn
))) {
2046 DEBUG(5, ("Enabling kernel oplocks for "
2047 "gpfs:leases to work\n"));
2048 lp_do_parameter(SNUM(handle
->conn
), "kernel oplocks",
2053 * as the kernel does not properly support Level II oplocks
2054 * and GPFS leases code is based on kernel infrastructure, we
2055 * need to turn off Level II oplocks if gpfs:leases is enabled
2057 if (lp_level2_oplocks(SNUM(handle
->conn
))) {
2058 DEBUG(5, ("gpfs:leases are enabled, disabling "
2059 "Level II oplocks\n"));
2060 lp_do_parameter(SNUM(handle
->conn
), "level2 oplocks",
2068 static int get_gpfs_quota(const char *pathname
, int type
, int id
,
2069 struct gpfs_quotaInfo
*qi
)
2073 ret
= gpfswrap_quotactl(discard_const_p(char, pathname
),
2074 GPFS_QCMD(Q_GETQUOTA
, type
), id
, qi
);
2077 if (errno
== GPFS_E_NO_QUOTA_INST
) {
2078 DEBUG(10, ("Quotas disabled on GPFS filesystem.\n"));
2079 } else if (errno
!= ENOSYS
) {
2080 DEBUG(0, ("Get quota failed, type %d, id, %d, "
2081 "errno %d.\n", type
, id
, errno
));
2087 DEBUG(10, ("quota type %d, id %d, blk u:%lld h:%lld s:%lld gt:%u\n",
2088 type
, id
, qi
->blockUsage
, qi
->blockHardLimit
,
2089 qi
->blockSoftLimit
, qi
->blockGraceTime
));
2094 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi
, time_t cur_time
,
2095 uint64_t *dfree
, uint64_t *dsize
)
2097 uint64_t usage
, limit
;
2100 * The quota reporting is done in units of 1024 byte blocks, but
2101 * sys_fsusage uses units of 512 byte blocks, adjust the block number
2102 * accordingly. Also filter possibly negative usage counts from gpfs.
2104 usage
= qi
.blockUsage
< 0 ? 0 : (uint64_t)qi
.blockUsage
* 2;
2105 limit
= (uint64_t)qi
.blockHardLimit
* 2;
2108 * When the grace time for the exceeded soft block quota has been
2109 * exceeded, the soft block quota becomes an additional hard limit.
2111 if (qi
.blockSoftLimit
&&
2112 qi
.blockGraceTime
&& cur_time
> qi
.blockGraceTime
) {
2113 /* report disk as full */
2115 *dsize
= MIN(*dsize
, usage
);
2118 if (!qi
.blockHardLimit
)
2121 if (usage
>= limit
) {
2122 /* report disk as full */
2124 *dsize
= MIN(*dsize
, usage
);
2127 /* limit has not been reached, determine "free space" */
2128 *dfree
= MIN(*dfree
, limit
- usage
);
2129 *dsize
= MIN(*dsize
, limit
);
2133 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct
*handle
, const char *path
,
2135 uint64_t *dfree
, uint64_t *dsize
)
2137 struct security_unix_token
*utok
;
2138 struct gpfs_quotaInfo qi_user
= { 0 }, qi_group
= { 0 };
2139 struct gpfs_config_data
*config
;
2143 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct gpfs_config_data
,
2144 return (uint64_t)-1);
2145 if (!config
->dfreequota
) {
2146 return SMB_VFS_NEXT_DISK_FREE(handle
, path
,
2147 bsize
, dfree
, dsize
);
2150 err
= sys_fsusage(path
, dfree
, dsize
);
2152 DEBUG (0, ("Could not get fs usage, errno %d\n", errno
));
2153 return SMB_VFS_NEXT_DISK_FREE(handle
, path
,
2154 bsize
, dfree
, dsize
);
2157 /* sys_fsusage returns units of 512 bytes */
2160 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
2161 (unsigned long long)*dfree
, (unsigned long long)*dsize
));
2163 utok
= handle
->conn
->session_info
->unix_token
;
2165 err
= get_gpfs_quota(path
, GPFS_USRQUOTA
, utok
->uid
, &qi_user
);
2167 return SMB_VFS_NEXT_DISK_FREE(handle
, path
,
2168 bsize
, dfree
, dsize
);
2171 err
= get_gpfs_quota(path
, GPFS_GRPQUOTA
, utok
->gid
, &qi_group
);
2173 return SMB_VFS_NEXT_DISK_FREE(handle
, path
,
2174 bsize
, dfree
, dsize
);
2177 cur_time
= time(NULL
);
2179 /* Adjust free space and size according to quota limits. */
2180 vfs_gpfs_disk_free_quota(qi_user
, cur_time
, dfree
, dsize
);
2181 vfs_gpfs_disk_free_quota(qi_group
, cur_time
, dfree
, dsize
);
2183 disk_norm(bsize
, dfree
, dsize
);
2187 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct
*handle
,
2188 enum timestamp_set_resolution
*p_ts_res
)
2190 struct gpfs_config_data
*config
;
2193 next
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
2195 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2196 struct gpfs_config_data
,
2200 next
|= FILE_SUPPORTS_REMOTE_STORAGE
;
2205 static int vfs_gpfs_open(struct vfs_handle_struct
*handle
,
2206 struct smb_filename
*smb_fname
, files_struct
*fsp
,
2207 int flags
, mode_t mode
)
2209 struct gpfs_config_data
*config
;
2211 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2212 struct gpfs_config_data
,
2215 if (config
->hsm
&& !config
->recalls
&&
2216 vfs_gpfs_fsp_is_offline(handle
, fsp
)) {
2217 DEBUG(10, ("Refusing access to offline file %s\n",
2223 if (config
->syncio
) {
2226 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
2229 static ssize_t
vfs_gpfs_pread(vfs_handle_struct
*handle
, files_struct
*fsp
,
2230 void *data
, size_t n
, off_t offset
)
2235 was_offline
= vfs_gpfs_fsp_is_offline(handle
, fsp
);
2237 ret
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
2239 if ((ret
!= -1) && was_offline
) {
2240 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2241 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2242 fsp
->fsp_name
->base_name
);
2248 struct vfs_gpfs_pread_state
{
2249 struct files_struct
*fsp
;
2255 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
);
2257 static struct tevent_req
*vfs_gpfs_pread_send(struct vfs_handle_struct
*handle
,
2258 TALLOC_CTX
*mem_ctx
,
2259 struct tevent_context
*ev
,
2260 struct files_struct
*fsp
,
2261 void *data
, size_t n
,
2264 struct tevent_req
*req
, *subreq
;
2265 struct vfs_gpfs_pread_state
*state
;
2267 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pread_state
);
2271 state
->was_offline
= vfs_gpfs_fsp_is_offline(handle
, fsp
);
2273 subreq
= SMB_VFS_NEXT_PREAD_SEND(state
, ev
, handle
, fsp
, data
,
2275 if (tevent_req_nomem(subreq
, req
)) {
2276 return tevent_req_post(req
, ev
);
2278 tevent_req_set_callback(subreq
, vfs_gpfs_pread_done
, req
);
2282 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
)
2284 struct tevent_req
*req
= tevent_req_callback_data(
2285 subreq
, struct tevent_req
);
2286 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2287 req
, struct vfs_gpfs_pread_state
);
2289 state
->ret
= SMB_VFS_PREAD_RECV(subreq
, &state
->err
);
2290 TALLOC_FREE(subreq
);
2291 tevent_req_done(req
);
2294 static ssize_t
vfs_gpfs_pread_recv(struct tevent_req
*req
, int *err
)
2296 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2297 req
, struct vfs_gpfs_pread_state
);
2298 struct files_struct
*fsp
= state
->fsp
;
2300 if (tevent_req_is_unix_error(req
, err
)) {
2305 if ((state
->ret
!= -1) && state
->was_offline
) {
2306 DEBUG(10, ("sending notify\n"));
2307 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2308 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2309 fsp
->fsp_name
->base_name
);
2315 static ssize_t
vfs_gpfs_pwrite(vfs_handle_struct
*handle
, files_struct
*fsp
,
2316 const void *data
, size_t n
, off_t offset
)
2321 was_offline
= vfs_gpfs_fsp_is_offline(handle
, fsp
);
2323 ret
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
2325 if ((ret
!= -1) && was_offline
) {
2326 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2327 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2328 fsp
->fsp_name
->base_name
);
2334 struct vfs_gpfs_pwrite_state
{
2335 struct files_struct
*fsp
;
2341 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
);
2343 static struct tevent_req
*vfs_gpfs_pwrite_send(
2344 struct vfs_handle_struct
*handle
,
2345 TALLOC_CTX
*mem_ctx
,
2346 struct tevent_context
*ev
,
2347 struct files_struct
*fsp
,
2348 const void *data
, size_t n
,
2351 struct tevent_req
*req
, *subreq
;
2352 struct vfs_gpfs_pwrite_state
*state
;
2354 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pwrite_state
);
2358 state
->was_offline
= vfs_gpfs_fsp_is_offline(handle
, fsp
);
2360 subreq
= SMB_VFS_NEXT_PWRITE_SEND(state
, ev
, handle
, fsp
, data
,
2362 if (tevent_req_nomem(subreq
, req
)) {
2363 return tevent_req_post(req
, ev
);
2365 tevent_req_set_callback(subreq
, vfs_gpfs_pwrite_done
, req
);
2369 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
)
2371 struct tevent_req
*req
= tevent_req_callback_data(
2372 subreq
, struct tevent_req
);
2373 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2374 req
, struct vfs_gpfs_pwrite_state
);
2376 state
->ret
= SMB_VFS_PWRITE_RECV(subreq
, &state
->err
);
2377 TALLOC_FREE(subreq
);
2378 tevent_req_done(req
);
2381 static ssize_t
vfs_gpfs_pwrite_recv(struct tevent_req
*req
, int *err
)
2383 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2384 req
, struct vfs_gpfs_pwrite_state
);
2385 struct files_struct
*fsp
= state
->fsp
;
2387 if (tevent_req_is_unix_error(req
, err
)) {
2392 if ((state
->ret
!= -1) && state
->was_offline
) {
2393 DEBUG(10, ("sending notify\n"));
2394 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2395 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2396 fsp
->fsp_name
->base_name
);
2403 static struct vfs_fn_pointers vfs_gpfs_fns
= {
2404 .connect_fn
= vfs_gpfs_connect
,
2405 .disk_free_fn
= vfs_gpfs_disk_free
,
2406 .fs_capabilities_fn
= vfs_gpfs_capabilities
,
2407 .kernel_flock_fn
= vfs_gpfs_kernel_flock
,
2408 .linux_setlease_fn
= vfs_gpfs_setlease
,
2409 .get_real_filename_fn
= vfs_gpfs_get_real_filename
,
2410 .fget_nt_acl_fn
= gpfsacl_fget_nt_acl
,
2411 .get_nt_acl_fn
= gpfsacl_get_nt_acl
,
2412 .fset_nt_acl_fn
= gpfsacl_fset_nt_acl
,
2413 .sys_acl_get_file_fn
= gpfsacl_sys_acl_get_file
,
2414 .sys_acl_get_fd_fn
= gpfsacl_sys_acl_get_fd
,
2415 .sys_acl_blob_get_file_fn
= gpfsacl_sys_acl_blob_get_file
,
2416 .sys_acl_blob_get_fd_fn
= gpfsacl_sys_acl_blob_get_fd
,
2417 .sys_acl_set_file_fn
= gpfsacl_sys_acl_set_file
,
2418 .sys_acl_set_fd_fn
= gpfsacl_sys_acl_set_fd
,
2419 .sys_acl_delete_def_file_fn
= gpfsacl_sys_acl_delete_def_file
,
2420 .chmod_fn
= vfs_gpfs_chmod
,
2421 .fchmod_fn
= vfs_gpfs_fchmod
,
2422 .close_fn
= vfs_gpfs_close
,
2423 .setxattr_fn
= gpfs_set_xattr
,
2424 .getxattr_fn
= gpfs_get_xattr
,
2425 .stat_fn
= vfs_gpfs_stat
,
2426 .fstat_fn
= vfs_gpfs_fstat
,
2427 .lstat_fn
= vfs_gpfs_lstat
,
2428 .ntimes_fn
= vfs_gpfs_ntimes
,
2429 .is_offline_fn
= vfs_gpfs_is_offline
,
2430 .aio_force_fn
= vfs_gpfs_aio_force
,
2431 .sendfile_fn
= vfs_gpfs_sendfile
,
2432 .fallocate_fn
= vfs_gpfs_fallocate
,
2433 .open_fn
= vfs_gpfs_open
,
2434 .pread_fn
= vfs_gpfs_pread
,
2435 .pread_send_fn
= vfs_gpfs_pread_send
,
2436 .pread_recv_fn
= vfs_gpfs_pread_recv
,
2437 .pwrite_fn
= vfs_gpfs_pwrite
,
2438 .pwrite_send_fn
= vfs_gpfs_pwrite_send
,
2439 .pwrite_recv_fn
= vfs_gpfs_pwrite_recv
,
2440 .ftruncate_fn
= vfs_gpfs_ftruncate
2443 NTSTATUS
vfs_gpfs_init(void);
2444 NTSTATUS
vfs_gpfs_init(void)
2448 ret
= gpfswrap_init();
2450 DEBUG(1, ("Could not initialize GPFS library wrapper\n"));
2453 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "gpfs",