2 Unix SMB/CIFS implementation.
3 Wrap gpfs calls in vfs functions.
5 Copyright (C) Christian Ambach <cambach1@de.ibm.com> 2006
7 Major code contributions by Chetan Shringarpure <chetan.sh@in.ibm.com>
8 and Gomati Mohanan <gomati.mohanan@in.ibm.com>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "smbd/smbd.h"
26 #include "librpc/gen_ndr/ndr_xattr.h"
27 #include "include/smbprofile.h"
28 #include "modules/non_posix_acls.h"
31 #define DBGC_CLASS DBGC_VFS
34 #include "nfs4_acls.h"
36 #include "system/filesys.h"
38 #include "lib/util/tevent_unix.h"
40 struct gpfs_config_data
{
56 static int vfs_gpfs_kernel_flock(vfs_handle_struct
*handle
, files_struct
*fsp
,
57 uint32 share_mode
, uint32 access_mask
)
60 struct gpfs_config_data
*config
;
63 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
64 struct gpfs_config_data
,
67 if(!config
->sharemodes
) {
71 START_PROFILE(syscall_kernel_flock
);
73 kernel_flock(fsp
->fh
->fd
, share_mode
, access_mask
);
75 if (!set_gpfs_sharemode(fsp
, access_mask
, fsp
->share_access
)) {
79 END_PROFILE(syscall_kernel_flock
);
84 static int vfs_gpfs_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
87 struct gpfs_config_data
*config
;
89 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
90 struct gpfs_config_data
,
93 if (config
->sharemodes
&& (fsp
->fh
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
94 set_gpfs_sharemode(fsp
, 0, 0);
97 return SMB_VFS_NEXT_CLOSE(handle
, fsp
);
100 static int vfs_gpfs_setlease(vfs_handle_struct
*handle
, files_struct
*fsp
,
103 struct gpfs_config_data
*config
;
106 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
107 struct gpfs_config_data
,
110 if (linux_set_lease_sighandler(fsp
->fh
->fd
) == -1)
113 START_PROFILE(syscall_linux_setlease
);
115 if (config
->leases
) {
117 * Ensure the lease owner is root to allow
118 * correct delivery of lease-break signals.
121 ret
= set_gpfs_lease(fsp
->fh
->fd
,leasetype
);
125 END_PROFILE(syscall_linux_setlease
);
130 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct
*handle
,
138 char real_pathname
[PATH_MAX
+1];
141 struct gpfs_config_data
*config
;
143 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
144 struct gpfs_config_data
,
147 if (!config
->getrealfilename
) {
148 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
149 mem_ctx
, found_name
);
152 mangled
= mangle_is_mangled(name
, handle
->conn
->params
);
154 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
155 mem_ctx
, found_name
);
158 full_path
= talloc_asprintf(talloc_tos(), "%s/%s", path
, name
);
159 if (full_path
== NULL
) {
164 buflen
= sizeof(real_pathname
) - 1;
166 result
= smbd_gpfs_get_realfilename_path(full_path
, real_pathname
,
169 TALLOC_FREE(full_path
);
171 if ((result
== -1) && (errno
== ENOSYS
)) {
172 return SMB_VFS_NEXT_GET_REAL_FILENAME(
173 handle
, path
, name
, mem_ctx
, found_name
);
177 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
183 * GPFS does not necessarily null-terminate the returned path
184 * but instead returns the buffer length in buflen.
187 if (buflen
< sizeof(real_pathname
)) {
188 real_pathname
[buflen
] = '\0';
190 real_pathname
[sizeof(real_pathname
)-1] = '\0';
193 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
194 path
, name
, real_pathname
));
196 name
= strrchr_m(real_pathname
, '/');
202 *found_name
= talloc_strdup(mem_ctx
, name
+1);
203 if (*found_name
== NULL
) {
211 static void gpfs_dumpacl(int level
, struct gpfs_acl
*gacl
)
216 DEBUG(0, ("gpfs acl is NULL\n"));
220 DEBUG(level
, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n",
221 gacl
->acl_nace
, gacl
->acl_type
, gacl
->acl_version
, gacl
->acl_level
, gacl
->acl_len
));
222 for(i
=0; i
<gacl
->acl_nace
; i
++)
224 struct gpfs_ace_v4
*gace
= gacl
->ace_v4
+ i
;
225 DEBUG(level
, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n",
226 i
, gace
->aceType
, gace
->aceFlags
, gace
->aceMask
,
227 gace
->aceIFlags
, gace
->aceWho
));
232 * get the ACL from GPFS, allocated on the specified mem_ctx
233 * internally retries when initial buffer was too small
235 * caller needs to cast result to either
236 * raw = yes: struct gpfs_opaque_acl
237 * raw = no: struct gpfs_acl
240 static void *vfs_gpfs_getacl(TALLOC_CTX
*mem_ctx
,
243 const gpfs_aclType_t type
)
254 aclbuf
= talloc_zero_size(mem_ctx
, size
);
255 if (aclbuf
== NULL
) {
261 struct gpfs_opaque_acl
*buf
= (struct gpfs_opaque_acl
*) aclbuf
;
262 buf
->acl_type
= type
;
263 flags
= GPFS_GETACL_NATIVE
;
264 len
= (unsigned int *) &(buf
->acl_buffer_len
);
265 struct_size
= sizeof(struct gpfs_opaque_acl
);
267 struct gpfs_acl
*buf
= (struct gpfs_acl
*) aclbuf
;
268 buf
->acl_type
= type
;
269 flags
= GPFS_GETACL_STRUCT
;
270 len
= &(buf
->acl_len
);
271 struct_size
= sizeof(struct gpfs_acl
);
274 /* set the length of the buffer as input value */
278 ret
= smbd_gpfs_getacl((char *)fname
, flags
, aclbuf
);
279 if ((ret
!= 0) && (errno
== ENOSPC
)) {
281 * get the size needed to accommodate the complete buffer
283 * the value returned only applies to the ACL blob in the
284 * struct so make sure to also have headroom for the first
285 * struct members by adding room for the complete struct
286 * (might be a few bytes too much then)
288 size
= *len
+ struct_size
;
290 DEBUG(10, ("Increasing ACL buffer size to %zu\n", size
));
295 DEBUG(5, ("smbd_gpfs_getacl failed with %s\n",
304 /* Tries to get nfs4 acls and returns SMB ACL allocated.
305 * On failure returns 1 if it got non-NFSv4 ACL to prompt
306 * retry with POSIX ACL checks.
307 * On failure returns -1 if there is system (GPFS) error, check errno.
308 * Returns 0 on success
310 static int gpfs_get_nfs4_acl(TALLOC_CTX
*mem_ctx
, const char *fname
, SMB4ACL_T
**ppacl
)
313 struct gpfs_acl
*gacl
= NULL
;
314 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname
));
317 gacl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(), fname
,
320 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
321 fname
, strerror(errno
)));
325 if (gacl
->acl_type
!= GPFS_ACL_TYPE_NFS4
) {
326 DEBUG(10, ("Got non-nfsv4 acl\n"));
327 /* Retry with POSIX ACLs check */
332 *ppacl
= smb_create_smb4acl(mem_ctx
);
334 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
335 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
338 for (i
=0; i
<gacl
->acl_nace
; i
++) {
339 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[i
];
340 SMB_ACE4PROP_T smbace
;
341 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
342 "who: %d\n", gace
->aceType
, gace
->aceIFlags
,
343 gace
->aceFlags
, gace
->aceMask
, gace
->aceWho
));
346 if (gace
->aceIFlags
& ACE4_IFLAG_SPECIAL_ID
) {
347 smbace
.flags
|= SMB_ACE4_ID_SPECIAL
;
348 switch (gace
->aceWho
) {
349 case ACE4_SPECIAL_OWNER
:
350 smbace
.who
.special_id
= SMB_ACE4_WHO_OWNER
;
352 case ACE4_SPECIAL_GROUP
:
353 smbace
.who
.special_id
= SMB_ACE4_WHO_GROUP
;
355 case ACE4_SPECIAL_EVERYONE
:
356 smbace
.who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
359 DEBUG(8, ("invalid special gpfs id %d "
360 "ignored\n", gace
->aceWho
));
361 continue; /* don't add it */
364 if (gace
->aceFlags
& ACE4_FLAG_GROUP_ID
)
365 smbace
.who
.gid
= gace
->aceWho
;
367 smbace
.who
.uid
= gace
->aceWho
;
370 /* remove redundant deny entries */
371 if (i
> 0 && gace
->aceType
== SMB_ACE4_ACCESS_DENIED_ACE_TYPE
) {
372 struct gpfs_ace_v4
*prev
= &gacl
->ace_v4
[i
-1];
373 if (prev
->aceType
== SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
&&
374 prev
->aceFlags
== gace
->aceFlags
&&
375 prev
->aceIFlags
== gace
->aceIFlags
&&
376 (gace
->aceMask
& prev
->aceMask
) == 0 &&
377 gace
->aceWho
== prev
->aceWho
) {
378 /* it's redundant - skip it */
383 smbace
.aceType
= gace
->aceType
;
384 smbace
.aceFlags
= gace
->aceFlags
;
385 smbace
.aceMask
= gace
->aceMask
;
386 smb_add_ace4(*ppacl
, &smbace
);
394 static NTSTATUS
gpfsacl_fget_nt_acl(vfs_handle_struct
*handle
,
395 files_struct
*fsp
, uint32 security_info
,
397 struct security_descriptor
**ppdesc
)
399 SMB4ACL_T
*pacl
= NULL
;
401 struct gpfs_config_data
*config
;
402 TALLOC_CTX
*frame
= talloc_stackframe();
407 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
408 struct gpfs_config_data
,
409 return NT_STATUS_INTERNAL_ERROR
);
412 status
= SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
418 result
= gpfs_get_nfs4_acl(frame
, fsp
->fsp_name
->base_name
, &pacl
);
421 status
= smb_fget_nt_acl_nfs4(fsp
, security_info
, mem_ctx
,
428 DEBUG(10, ("retrying with posix acl...\n"));
429 status
= posix_fget_nt_acl(fsp
, security_info
,
437 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
438 return map_nt_error_from_unix(errno
);
441 static NTSTATUS
gpfsacl_get_nt_acl(vfs_handle_struct
*handle
,
443 uint32 security_info
,
444 TALLOC_CTX
*mem_ctx
, struct security_descriptor
**ppdesc
)
446 SMB4ACL_T
*pacl
= NULL
;
448 struct gpfs_config_data
*config
;
449 TALLOC_CTX
*frame
= talloc_stackframe();
454 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
455 struct gpfs_config_data
,
456 return NT_STATUS_INTERNAL_ERROR
);
459 status
= SMB_VFS_NEXT_GET_NT_ACL(handle
, name
, security_info
,
465 result
= gpfs_get_nfs4_acl(frame
, name
, &pacl
);
468 status
= smb_get_nt_acl_nfs4(handle
->conn
, name
, security_info
,
469 mem_ctx
, ppdesc
, pacl
);
475 DEBUG(10, ("retrying with posix acl...\n"));
476 status
= posix_get_nt_acl(handle
->conn
, name
, security_info
,
482 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
484 return map_nt_error_from_unix(errno
);
487 static bool gpfsacl_process_smbacl(vfs_handle_struct
*handle
, files_struct
*fsp
, SMB4ACL_T
*smbacl
)
490 gpfs_aclLen_t gacl_len
;
492 struct gpfs_acl
*gacl
;
493 TALLOC_CTX
*mem_ctx
= talloc_tos();
495 gacl_len
= offsetof(gpfs_acl_t
, ace_v4
) + smb_get_naces(smbacl
) *
496 sizeof(gpfs_ace_v4_t
);
498 gacl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, gacl_len
);
500 DEBUG(0, ("talloc failed\n"));
505 gacl
->acl_len
= gacl_len
;
507 gacl
->acl_version
= GPFS_ACL_VERSION_NFS4
;
508 gacl
->acl_type
= GPFS_ACL_TYPE_NFS4
;
509 gacl
->acl_nace
= 0; /* change later... */
511 for (smbace
=smb_first_ace4(smbacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
512 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[gacl
->acl_nace
];
513 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
515 gace
->aceType
= aceprop
->aceType
;
516 gace
->aceFlags
= aceprop
->aceFlags
;
517 gace
->aceMask
= aceprop
->aceMask
;
520 * GPFS can't distinguish between WRITE and APPEND on
521 * files, so one being set without the other is an
522 * error. Sorry for the many ()'s :-)
525 if (!fsp
->is_directory
527 ((((gace
->aceMask
& ACE4_MASK_WRITE
) == 0)
528 && ((gace
->aceMask
& ACE4_MASK_APPEND
) != 0))
530 (((gace
->aceMask
& ACE4_MASK_WRITE
) != 0)
531 && ((gace
->aceMask
& ACE4_MASK_APPEND
) == 0)))
533 lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
534 "merge_writeappend", True
)) {
535 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
536 "WRITE^APPEND, setting WRITE|APPEND\n",
538 gace
->aceMask
|= ACE4_MASK_WRITE
|ACE4_MASK_APPEND
;
541 gace
->aceIFlags
= (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
) ? ACE4_IFLAG_SPECIAL_ID
: 0;
543 if (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
)
545 switch(aceprop
->who
.special_id
)
547 case SMB_ACE4_WHO_EVERYONE
:
548 gace
->aceWho
= ACE4_SPECIAL_EVERYONE
;
550 case SMB_ACE4_WHO_OWNER
:
551 gace
->aceWho
= ACE4_SPECIAL_OWNER
;
553 case SMB_ACE4_WHO_GROUP
:
554 gace
->aceWho
= ACE4_SPECIAL_GROUP
;
557 DEBUG(8, ("unsupported special_id %d\n", aceprop
->who
.special_id
));
558 continue; /* don't add it !!! */
561 /* just only for the type safety... */
562 if (aceprop
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)
563 gace
->aceWho
= aceprop
->who
.gid
;
565 gace
->aceWho
= aceprop
->who
.uid
;
571 ret
= smbd_gpfs_putacl(fsp
->fsp_name
->base_name
,
572 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gacl
);
574 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno
)));
575 gpfs_dumpacl(8, gacl
);
579 DEBUG(10, ("gpfs_putacl succeeded\n"));
583 static NTSTATUS
gpfsacl_set_nt_acl_internal(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
585 struct gpfs_acl
*acl
;
586 NTSTATUS result
= NT_STATUS_ACCESS_DENIED
;
588 acl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(),
589 fsp
->fsp_name
->base_name
,
592 return map_nt_error_from_unix(errno
);
595 if (acl
->acl_version
== GPFS_ACL_VERSION_NFS4
) {
596 if (lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
597 "refuse_dacl_protected", false)
598 && (psd
->type
&SEC_DESC_DACL_PROTECTED
)) {
599 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
601 return NT_STATUS_NOT_SUPPORTED
;
604 result
= smb_set_nt_acl_nfs4(handle
,
605 fsp
, security_info_sent
, psd
,
606 gpfsacl_process_smbacl
);
607 } else { /* assume POSIX ACL - by default... */
608 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
615 static NTSTATUS
gpfsacl_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
617 struct gpfs_config_data
*config
;
619 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
620 struct gpfs_config_data
,
621 return NT_STATUS_INTERNAL_ERROR
);
624 return SMB_VFS_NEXT_FSET_NT_ACL(handle
, fsp
, security_info_sent
, psd
);
627 return gpfsacl_set_nt_acl_internal(handle
, fsp
, security_info_sent
, psd
);
630 static SMB_ACL_T
gpfs2smb_acl(const struct gpfs_acl
*pacl
, TALLOC_CTX
*mem_ctx
)
635 result
= sys_acl_init(mem_ctx
);
636 if (result
== NULL
) {
641 result
->count
= pacl
->acl_nace
;
642 result
->acl
= talloc_realloc(result
, result
->acl
, struct smb_acl_entry
,
644 if (result
->acl
== NULL
) {
650 for (i
=0; i
<pacl
->acl_nace
; i
++) {
651 struct smb_acl_entry
*ace
= &result
->acl
[i
];
652 const struct gpfs_ace_v1
*g_ace
= &pacl
->ace_v1
[i
];
654 DEBUG(10, ("Converting type %d id %lu perm %x\n",
655 (int)g_ace
->ace_type
, (unsigned long)g_ace
->ace_who
,
656 (int)g_ace
->ace_perm
));
658 switch (g_ace
->ace_type
) {
660 ace
->a_type
= SMB_ACL_USER
;
661 ace
->info
.user
.uid
= (uid_t
)g_ace
->ace_who
;
663 case GPFS_ACL_USER_OBJ
:
664 ace
->a_type
= SMB_ACL_USER_OBJ
;
667 ace
->a_type
= SMB_ACL_GROUP
;
668 ace
->info
.group
.gid
= (gid_t
)g_ace
->ace_who
;
670 case GPFS_ACL_GROUP_OBJ
:
671 ace
->a_type
= SMB_ACL_GROUP_OBJ
;
674 ace
->a_type
= SMB_ACL_OTHER
;
677 ace
->a_type
= SMB_ACL_MASK
;
680 DEBUG(10, ("Got invalid ace_type: %d\n",
688 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_READ
) ?
690 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_WRITE
) ?
692 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_EXECUTE
) ?
695 DEBUGADD(10, ("Converted to %d perm %x\n",
696 ace
->a_type
, ace
->a_perm
));
702 static SMB_ACL_T
gpfsacl_get_posix_acl(const char *path
, gpfs_aclType_t type
,
705 struct gpfs_acl
*pacl
;
706 SMB_ACL_T result
= NULL
;
708 pacl
= vfs_gpfs_getacl(talloc_tos(), path
, false, type
);
711 DEBUG(10, ("vfs_gpfs_getacl failed for %s with %s\n",
712 path
, strerror(errno
)));
719 if (pacl
->acl_version
!= GPFS_ACL_VERSION_POSIX
) {
720 DEBUG(10, ("Got acl version %d, expected %d\n",
721 pacl
->acl_version
, GPFS_ACL_VERSION_POSIX
));
726 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
727 pacl
->acl_len
, pacl
->acl_level
, pacl
->acl_version
,
730 result
= gpfs2smb_acl(pacl
, mem_ctx
);
731 if (result
!= NULL
) {
746 static SMB_ACL_T
gpfsacl_sys_acl_get_file(vfs_handle_struct
*handle
,
751 gpfs_aclType_t gpfs_type
;
752 struct gpfs_config_data
*config
;
754 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
755 struct gpfs_config_data
,
759 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle
, path_p
,
764 case SMB_ACL_TYPE_ACCESS
:
765 gpfs_type
= GPFS_ACL_TYPE_ACCESS
;
767 case SMB_ACL_TYPE_DEFAULT
:
768 gpfs_type
= GPFS_ACL_TYPE_DEFAULT
;
771 DEBUG(0, ("Got invalid type: %d\n", type
));
772 smb_panic("exiting");
775 return gpfsacl_get_posix_acl(path_p
, gpfs_type
, mem_ctx
);
778 static SMB_ACL_T
gpfsacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
782 struct gpfs_config_data
*config
;
784 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
785 struct gpfs_config_data
,
789 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle
, fsp
, mem_ctx
);
792 return gpfsacl_get_posix_acl(fsp
->fsp_name
->base_name
,
793 GPFS_ACL_TYPE_ACCESS
, mem_ctx
);
796 static int gpfsacl_sys_acl_blob_get_file(vfs_handle_struct
*handle
,
799 char **blob_description
,
802 struct gpfs_config_data
*config
;
803 struct gpfs_opaque_acl
*acl
= NULL
;
807 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
808 struct gpfs_config_data
,
812 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle
, path_p
,
819 acl
= (struct gpfs_opaque_acl
*)
820 vfs_gpfs_getacl(mem_ctx
,
826 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
827 errno
, strerror(errno
)));
829 /* EINVAL means POSIX ACL, bail out on other cases */
830 if (errno
!= EINVAL
) {
839 * we only need the actual ACL blob here
840 * acl_version will always be NFS4 because we asked
842 * acl_type is only used for POSIX ACLs
844 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
845 aclblob
.length
= acl
->acl_buffer_len
;
847 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
848 if (!*blob_description
) {
854 result
= non_posix_sys_acl_blob_get_file_helper(handle
, path_p
,
862 /* fall back to POSIX ACL */
863 return posix_sys_acl_blob_get_file(handle
, path_p
, mem_ctx
,
864 blob_description
, blob
);
867 static int gpfsacl_sys_acl_blob_get_fd(vfs_handle_struct
*handle
,
870 char **blob_description
,
873 struct gpfs_config_data
*config
;
874 struct gpfs_opaque_acl
*acl
= NULL
;
878 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
879 struct gpfs_config_data
,
883 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle
, fsp
, mem_ctx
,
884 blob_description
, blob
);
888 acl
= (struct gpfs_opaque_acl
*) vfs_gpfs_getacl(mem_ctx
,
889 fsp
->fsp_name
->base_name
,
894 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
895 errno
, strerror(errno
)));
897 /* EINVAL means POSIX ACL, bail out on other cases */
898 if (errno
!= EINVAL
) {
907 * we only need the actual ACL blob here
908 * acl_version will always be NFS4 because we asked
910 * acl_type is only used for POSIX ACLs
912 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
913 aclblob
.length
= acl
->acl_buffer_len
;
915 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
916 if (!*blob_description
) {
922 result
= non_posix_sys_acl_blob_get_fd_helper(handle
, fsp
,
930 /* fall back to POSIX ACL */
931 return posix_sys_acl_blob_get_fd(handle
, fsp
, mem_ctx
,
932 blob_description
, blob
);
935 static struct gpfs_acl
*smb2gpfs_acl(const SMB_ACL_T pacl
,
939 struct gpfs_acl
*result
;
942 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl
->count
));
944 len
= offsetof(gpfs_acl_t
, ace_v1
) + (pacl
->count
) *
945 sizeof(gpfs_ace_v1_t
);
947 result
= (struct gpfs_acl
*)SMB_MALLOC(len
);
948 if (result
== NULL
) {
953 result
->acl_len
= len
;
954 result
->acl_level
= 0;
955 result
->acl_version
= GPFS_ACL_VERSION_POSIX
;
956 result
->acl_type
= (type
== SMB_ACL_TYPE_DEFAULT
) ?
957 GPFS_ACL_TYPE_DEFAULT
: GPFS_ACL_TYPE_ACCESS
;
958 result
->acl_nace
= pacl
->count
;
960 for (i
=0; i
<pacl
->count
; i
++) {
961 const struct smb_acl_entry
*ace
= &pacl
->acl
[i
];
962 struct gpfs_ace_v1
*g_ace
= &result
->ace_v1
[i
];
964 DEBUG(10, ("Converting type %d perm %x\n",
965 (int)ace
->a_type
, (int)ace
->a_perm
));
969 switch(ace
->a_type
) {
971 g_ace
->ace_type
= GPFS_ACL_USER
;
972 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.user
.uid
;
974 case SMB_ACL_USER_OBJ
:
975 g_ace
->ace_type
= GPFS_ACL_USER_OBJ
;
976 g_ace
->ace_perm
|= ACL_PERM_CONTROL
;
980 g_ace
->ace_type
= GPFS_ACL_GROUP
;
981 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.group
.gid
;
983 case SMB_ACL_GROUP_OBJ
:
984 g_ace
->ace_type
= GPFS_ACL_GROUP_OBJ
;
988 g_ace
->ace_type
= GPFS_ACL_MASK
;
989 g_ace
->ace_perm
= 0x8f;
993 g_ace
->ace_type
= GPFS_ACL_OTHER
;
997 DEBUG(10, ("Got invalid ace_type: %d\n", ace
->a_type
));
1003 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_READ
) ?
1005 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_WRITE
) ?
1007 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_EXECUTE
) ?
1008 ACL_PERM_EXECUTE
: 0;
1010 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
1011 g_ace
->ace_type
, g_ace
->ace_who
, g_ace
->ace_perm
));
1017 static int gpfsacl_sys_acl_set_file(vfs_handle_struct
*handle
,
1019 SMB_ACL_TYPE_T type
,
1022 struct gpfs_acl
*gpfs_acl
;
1024 struct gpfs_config_data
*config
;
1026 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1027 struct gpfs_config_data
,
1031 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle
, name
, type
, theacl
);
1034 gpfs_acl
= smb2gpfs_acl(theacl
, type
);
1035 if (gpfs_acl
== NULL
) {
1039 result
= smbd_gpfs_putacl((char *)name
, GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gpfs_acl
);
1041 SAFE_FREE(gpfs_acl
);
1045 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
1049 struct gpfs_config_data
*config
;
1051 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1052 struct gpfs_config_data
,
1056 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle
, fsp
, theacl
);
1059 return gpfsacl_sys_acl_set_file(handle
, fsp
->fsp_name
->base_name
,
1060 SMB_ACL_TYPE_ACCESS
, theacl
);
1063 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
1066 struct gpfs_config_data
*config
;
1068 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1069 struct gpfs_config_data
,
1073 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle
, path
);
1081 * Assumed: mode bits are shiftable and standard
1082 * Output: the new aceMask field for an smb nfs4 ace
1084 static uint32
gpfsacl_mask_filter(uint32 aceType
, uint32 aceMask
, uint32 rwx
)
1086 const uint32 posix_nfs4map
[3] = {
1087 SMB_ACE4_EXECUTE
, /* execute */
1088 SMB_ACE4_WRITE_DATA
| SMB_ACE4_APPEND_DATA
, /* write; GPFS specific */
1089 SMB_ACE4_READ_DATA
/* read */
1092 uint32_t posix_mask
= 0x01;
1096 for(i
=0; i
<3; i
++) {
1097 nfs4_bits
= posix_nfs4map
[i
];
1098 posix_bit
= rwx
& posix_mask
;
1100 if (aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
) {
1102 aceMask
|= nfs4_bits
;
1104 aceMask
&= ~nfs4_bits
;
1106 /* add deny bits when suitable */
1108 aceMask
|= nfs4_bits
;
1110 aceMask
&= ~nfs4_bits
;
1111 } /* other ace types are unexpected */
1119 static int gpfsacl_emu_chmod(vfs_handle_struct
*handle
,
1120 const char *path
, mode_t mode
)
1122 SMB4ACL_T
*pacl
= NULL
;
1124 bool haveAllowEntry
[SMB_ACE4_WHO_EVERYONE
+ 1] = {False
, False
, False
, False
};
1126 files_struct fake_fsp
; /* TODO: rationalize parametrization */
1128 TALLOC_CTX
*frame
= talloc_stackframe();
1131 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path
, mode
));
1133 result
= gpfs_get_nfs4_acl(frame
, path
, &pacl
);
1139 if (mode
& ~(S_IRWXU
| S_IRWXG
| S_IRWXO
)) {
1140 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode
, path
));
1143 for (smbace
=smb_first_ace4(pacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
1144 SMB_ACE4PROP_T
*ace
= smb_get_ace4(smbace
);
1145 uint32_t specid
= ace
->who
.special_id
;
1147 if (ace
->flags
&SMB_ACE4_ID_SPECIAL
&&
1148 ace
->aceType
<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE
&&
1149 specid
<= SMB_ACE4_WHO_EVERYONE
) {
1153 if (ace
->aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
)
1154 haveAllowEntry
[specid
] = True
;
1156 /* mode >> 6 for @owner, mode >> 3 for @group,
1157 * mode >> 0 for @everyone */
1158 newMask
= gpfsacl_mask_filter(ace
->aceType
, ace
->aceMask
,
1159 mode
>> ((SMB_ACE4_WHO_EVERYONE
- specid
) * 3));
1160 if (ace
->aceMask
!=newMask
) {
1161 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
1162 path
, ace
->aceMask
, newMask
, specid
));
1164 ace
->aceMask
= newMask
;
1168 /* make sure we have at least ALLOW entries
1169 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
1172 for(i
= SMB_ACE4_WHO_OWNER
; i
<=SMB_ACE4_WHO_EVERYONE
; i
++) {
1175 if (haveAllowEntry
[i
]==True
)
1179 ace
.aceType
= SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
;
1180 ace
.flags
|= SMB_ACE4_ID_SPECIAL
;
1181 ace
.who
.special_id
= i
;
1183 if (i
==SMB_ACE4_WHO_GROUP
) /* not sure it's necessary... */
1184 ace
.aceFlags
|= SMB_ACE4_IDENTIFIER_GROUP
;
1186 ace
.aceMask
= gpfsacl_mask_filter(ace
.aceType
, ace
.aceMask
,
1187 mode
>> ((SMB_ACE4_WHO_EVERYONE
- i
) * 3));
1189 /* don't add unnecessary aces */
1193 /* we add it to the END - as windows expects allow aces */
1194 smb_add_ace4(pacl
, &ace
);
1195 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1196 path
, mode
, i
, ace
.aceMask
));
1199 /* don't add complementary DENY ACEs here */
1200 ZERO_STRUCT(fake_fsp
);
1201 fake_fsp
.fsp_name
= synthetic_smb_fname(
1202 frame
, path
, NULL
, NULL
);
1203 if (fake_fsp
.fsp_name
== NULL
) {
1209 if (gpfsacl_process_smbacl(handle
, &fake_fsp
, pacl
) == False
) {
1215 return 0; /* ok for [f]chmod */
1218 static int vfs_gpfs_chmod(vfs_handle_struct
*handle
, const char *path
, mode_t mode
)
1220 struct smb_filename
*smb_fname_cpath
;
1223 smb_fname_cpath
= synthetic_smb_fname(talloc_tos(), path
, NULL
, NULL
);
1224 if (smb_fname_cpath
== NULL
) {
1229 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_cpath
) != 0) {
1233 /* avoid chmod() if possible, to preserve acls */
1234 if ((smb_fname_cpath
->st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1238 rc
= gpfsacl_emu_chmod(handle
, path
, mode
);
1240 return SMB_VFS_NEXT_CHMOD(handle
, path
, mode
);
1244 static int vfs_gpfs_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
1249 if (SMB_VFS_NEXT_FSTAT(handle
, fsp
, &st
) != 0) {
1253 /* avoid chmod() if possible, to preserve acls */
1254 if ((st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1258 rc
= gpfsacl_emu_chmod(handle
, fsp
->fsp_name
->base_name
,
1261 return SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
1265 static int gpfs_set_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1266 const char *name
, const void *value
, size_t size
, int flags
){
1267 struct xattr_DOSATTRIB dosattrib
;
1268 enum ndr_err_code ndr_err
;
1270 const char *attrstr
= value
;
1271 unsigned int dosmode
=0;
1272 struct gpfs_winattr attrs
;
1274 struct gpfs_config_data
*config
;
1276 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1277 struct gpfs_config_data
,
1280 if (!config
->winattr
) {
1281 DEBUG(10, ("gpfs_set_xattr:name is %s -> next\n",name
));
1282 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1285 DEBUG(10, ("gpfs_set_xattr: %s \n",path
));
1287 /* Only handle DOS Attributes */
1288 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1289 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name
));
1290 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1293 blob
.data
= (uint8_t *)attrstr
;
1296 ndr_err
= ndr_pull_struct_blob(&blob
, talloc_tos(), &dosattrib
,
1297 (ndr_pull_flags_fn_t
)ndr_pull_xattr_DOSATTRIB
);
1299 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1300 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
1301 "from EA on file %s: Error = %s\n",
1302 path
, ndr_errstr(ndr_err
)));
1306 if (dosattrib
.version
!= 3) {
1307 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
1308 "%d\n", (int)dosattrib
.version
));
1311 if (!(dosattrib
.info
.info3
.valid_flags
& XATTR_DOSINFO_ATTRIB
)) {
1312 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
1313 "valid, ignoring\n"));
1317 dosmode
= dosattrib
.info
.info3
.attrib
;
1320 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
1321 if (dosmode
& FILE_ATTRIBUTE_ARCHIVE
){
1322 attrs
.winAttrs
|= GPFS_WINATTR_ARCHIVE
;
1324 if (dosmode
& FILE_ATTRIBUTE_HIDDEN
){
1325 attrs
.winAttrs
|= GPFS_WINATTR_HIDDEN
;
1327 if (dosmode
& FILE_ATTRIBUTE_SYSTEM
){
1328 attrs
.winAttrs
|= GPFS_WINATTR_SYSTEM
;
1330 if (dosmode
& FILE_ATTRIBUTE_READONLY
){
1331 attrs
.winAttrs
|= GPFS_WINATTR_READONLY
;
1333 if (dosmode
& FILE_ATTRIBUTE_SPARSE
) {
1334 attrs
.winAttrs
|= GPFS_WINATTR_SPARSE_FILE
;
1338 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1339 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1341 if (errno
== ENOSYS
) {
1342 return SMB_VFS_NEXT_SETXATTR(handle
, path
, name
, value
,
1346 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret
));
1350 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs
.winAttrs
));
1354 static ssize_t
gpfs_get_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1355 const char *name
, void *value
, size_t size
){
1356 char *attrstr
= value
;
1357 unsigned int dosmode
= 0;
1358 struct gpfs_winattr attrs
;
1360 struct gpfs_config_data
*config
;
1362 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1363 struct gpfs_config_data
,
1366 if (!config
->winattr
) {
1367 DEBUG(10, ("gpfs_get_xattr:name is %s -> next\n",name
));
1368 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1371 DEBUG(10, ("gpfs_get_xattr: %s \n",path
));
1373 /* Only handle DOS Attributes */
1374 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1375 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name
));
1376 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1379 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1381 if (errno
== ENOSYS
) {
1382 return SMB_VFS_NEXT_GETXATTR(handle
, path
, name
, value
,
1386 DEBUG(1, ("gpfs_get_xattr: Get GPFS attributes failed: "
1387 "%d (%s)\n", ret
, strerror(errno
)));
1391 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs
.winAttrs
));
1393 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1394 if (attrs
.winAttrs
& GPFS_WINATTR_ARCHIVE
){
1395 dosmode
|= FILE_ATTRIBUTE_ARCHIVE
;
1397 if (attrs
.winAttrs
& GPFS_WINATTR_HIDDEN
){
1398 dosmode
|= FILE_ATTRIBUTE_HIDDEN
;
1400 if (attrs
.winAttrs
& GPFS_WINATTR_SYSTEM
){
1401 dosmode
|= FILE_ATTRIBUTE_SYSTEM
;
1403 if (attrs
.winAttrs
& GPFS_WINATTR_READONLY
){
1404 dosmode
|= FILE_ATTRIBUTE_READONLY
;
1406 if (attrs
.winAttrs
& GPFS_WINATTR_SPARSE_FILE
) {
1407 dosmode
|= FILE_ATTRIBUTE_SPARSE
;
1410 snprintf(attrstr
, size
, "0x%2.2x",
1411 (unsigned int)(dosmode
& SAMBA_ATTRIBUTES_MASK
));
1412 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr
));
1416 #if defined(HAVE_FSTATAT)
1417 static int stat_with_capability(struct vfs_handle_struct
*handle
,
1418 struct smb_filename
*smb_fname
, int flag
)
1423 const char *rel_name
= NULL
;
1427 b
= parent_dirname(talloc_tos(), smb_fname
->base_name
,
1428 &dir_name
, &rel_name
);
1434 fd
= open(dir_name
, O_RDONLY
, 0);
1435 TALLOC_FREE(dir_name
);
1440 set_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1441 ret
= fstatat(fd
, rel_name
, &st
, flag
);
1442 drop_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1447 init_stat_ex_from_stat(
1448 &smb_fname
->st
, &st
,
1449 lp_fake_directory_create_times(SNUM(handle
->conn
)));
1456 static int vfs_gpfs_stat(struct vfs_handle_struct
*handle
,
1457 struct smb_filename
*smb_fname
)
1459 struct gpfs_winattr attrs
;
1463 struct gpfs_config_data
*config
;
1465 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1466 struct gpfs_config_data
,
1469 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
1470 #if defined(HAVE_FSTATAT)
1471 if (ret
== -1 && errno
== EACCES
) {
1472 DEBUG(10, ("Trying stat with capability for %s\n",
1473 smb_fname
->base_name
));
1474 ret
= stat_with_capability(handle
, smb_fname
, 0);
1481 if (!config
->winattr
) {
1485 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &fname
);
1486 if (!NT_STATUS_IS_OK(status
)) {
1487 errno
= map_errno_from_nt_status(status
);
1490 ret
= get_gpfs_winattrs(discard_const_p(char, fname
), &attrs
);
1493 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1494 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1495 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1496 smb_fname
->st
.vfs_private
= attrs
.winAttrs
;
1501 static int vfs_gpfs_fstat(struct vfs_handle_struct
*handle
,
1502 struct files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
1504 struct gpfs_winattr attrs
;
1506 struct gpfs_config_data
*config
;
1508 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1509 struct gpfs_config_data
,
1512 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
1516 if ((fsp
->fh
== NULL
) || (fsp
->fh
->fd
== -1)) {
1519 if (!config
->winattr
) {
1523 ret
= smbd_fget_gpfs_winattrs(fsp
->fh
->fd
, &attrs
);
1525 sbuf
->st_ex_calculated_birthtime
= false;
1526 sbuf
->st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1527 sbuf
->st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1532 static int vfs_gpfs_lstat(struct vfs_handle_struct
*handle
,
1533 struct smb_filename
*smb_fname
)
1535 struct gpfs_winattr attrs
;
1539 struct gpfs_config_data
*config
;
1541 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1542 struct gpfs_config_data
,
1545 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
1546 #if defined(HAVE_FSTATAT)
1547 if (ret
== -1 && errno
== EACCES
) {
1548 DEBUG(10, ("Trying lstat with capability for %s\n",
1549 smb_fname
->base_name
));
1550 ret
= stat_with_capability(handle
, smb_fname
,
1551 AT_SYMLINK_NOFOLLOW
);
1558 if (!config
->winattr
) {
1562 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1563 if (!NT_STATUS_IS_OK(status
)) {
1564 errno
= map_errno_from_nt_status(status
);
1567 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1570 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1571 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1572 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1573 smb_fname
->st
.vfs_private
= attrs
.winAttrs
;
1578 static int vfs_gpfs_ntimes(struct vfs_handle_struct
*handle
,
1579 const struct smb_filename
*smb_fname
,
1580 struct smb_file_time
*ft
)
1583 struct gpfs_winattr attrs
;
1587 struct gpfs_config_data
*config
;
1589 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1590 struct gpfs_config_data
,
1593 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1594 if (!NT_STATUS_IS_OK(status
)) {
1595 errno
= map_errno_from_nt_status(status
);
1599 /* Try to use gpfs_set_times if it is enabled and available */
1600 if (config
->settimes
) {
1601 ret
= smbd_gpfs_set_times_path(path
, ft
);
1603 if (ret
== 0 || (ret
== -1 && errno
!= ENOSYS
)) {
1608 DEBUG(10,("gpfs_set_times() not available or disabled, "
1609 "use ntimes and winattr\n"));
1611 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1613 /* don't complain if access was denied */
1614 if (errno
!= EPERM
&& errno
!= EACCES
) {
1615 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1616 "%s", strerror(errno
)));
1621 if(null_timespec(ft
->create_time
)){
1622 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1626 if (!config
->winattr
) {
1631 attrs
.creationTime
.tv_sec
= ft
->create_time
.tv_sec
;
1632 attrs
.creationTime
.tv_nsec
= ft
->create_time
.tv_nsec
;
1634 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1635 GPFS_WINATTR_SET_CREATION_TIME
, &attrs
);
1636 if(ret
== -1 && errno
!= ENOSYS
){
1637 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret
));
1644 static int vfs_gpfs_fallocate(struct vfs_handle_struct
*handle
,
1645 struct files_struct
*fsp
, enum vfs_fallocate_mode mode
,
1646 off_t offset
, off_t len
)
1649 struct gpfs_config_data
*config
;
1651 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1652 struct gpfs_config_data
,
1655 if (!config
->prealloc
) {
1656 /* you should better not run fallocate() on GPFS at all */
1661 if (mode
== VFS_FALLOCATE_KEEP_SIZE
) {
1662 DEBUG(10, ("Unsupported VFS_FALLOCATE_KEEP_SIZE\n"));
1667 ret
= smbd_gpfs_prealloc(fsp
->fh
->fd
, offset
, len
);
1669 if (ret
== -1 && errno
!= ENOSYS
) {
1670 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno
)));
1671 } else if (ret
== -1 && errno
== ENOSYS
) {
1672 DEBUG(10, ("GPFS prealloc not supported.\n"));
1674 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1680 static int vfs_gpfs_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1684 struct gpfs_config_data
*config
;
1686 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1687 struct gpfs_config_data
,
1690 if (!config
->ftruncate
) {
1691 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1694 result
= smbd_gpfs_ftruncate(fsp
->fh
->fd
, len
);
1695 if ((result
== -1) && (errno
== ENOSYS
)) {
1696 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1701 static bool vfs_gpfs_is_offline(struct vfs_handle_struct
*handle
,
1702 const struct smb_filename
*fname
,
1703 SMB_STRUCT_STAT
*sbuf
)
1705 struct gpfs_winattr attrs
;
1708 struct gpfs_config_data
*config
;
1710 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1711 struct gpfs_config_data
,
1714 if (!config
->winattr
) {
1715 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1718 status
= get_full_smb_filename(talloc_tos(), fname
, &path
);
1719 if (!NT_STATUS_IS_OK(status
)) {
1720 errno
= map_errno_from_nt_status(status
);
1724 if (VALID_STAT(*sbuf
)) {
1725 attrs
.winAttrs
= sbuf
->vfs_private
;
1728 ret
= get_gpfs_winattrs(path
, &attrs
);
1735 if ((attrs
.winAttrs
& GPFS_WINATTR_OFFLINE
) != 0) {
1736 DEBUG(10, ("%s is offline\n", path
));
1740 DEBUG(10, ("%s is online\n", path
));
1742 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1745 static bool vfs_gpfs_aio_force(struct vfs_handle_struct
*handle
,
1746 struct files_struct
*fsp
)
1748 return vfs_gpfs_is_offline(handle
, fsp
->fsp_name
, &fsp
->fsp_name
->st
);
1751 static ssize_t
vfs_gpfs_sendfile(vfs_handle_struct
*handle
, int tofd
,
1752 files_struct
*fsp
, const DATA_BLOB
*hdr
,
1753 off_t offset
, size_t n
)
1755 if ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0) {
1759 return SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fsp
, hdr
, offset
, n
);
1762 static int vfs_gpfs_connect(struct vfs_handle_struct
*handle
,
1763 const char *service
, const char *user
)
1765 struct gpfs_config_data
*config
;
1768 smbd_gpfs_lib_init();
1770 config
= talloc_zero(handle
->conn
, struct gpfs_config_data
);
1772 DEBUG(0, ("talloc_zero() failed\n"));
1777 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1779 TALLOC_FREE(config
);
1783 config
->sharemodes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1784 "sharemodes", true);
1786 config
->leases
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1789 config
->hsm
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1792 config
->syncio
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1795 config
->winattr
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1798 config
->ftruncate
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1801 config
->getrealfilename
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1802 "getrealfilename", true);
1804 config
->dfreequota
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1805 "dfreequota", false);
1807 config
->prealloc
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1810 config
->acl
= lp_parm_bool(SNUM(handle
->conn
), "gpfs", "acl", true);
1812 config
->settimes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1814 config
->recalls
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1817 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
1818 NULL
, struct gpfs_config_data
,
1821 if (config
->leases
) {
1823 * GPFS lease code is based on kernel oplock code
1824 * so make sure it is turned on
1826 if (!lp_kernel_oplocks(SNUM(handle
->conn
))) {
1827 DEBUG(5, ("Enabling kernel oplocks for "
1828 "gpfs:leases to work\n"));
1829 lp_do_parameter(SNUM(handle
->conn
), "kernel oplocks",
1834 * as the kernel does not properly support Level II oplocks
1835 * and GPFS leases code is based on kernel infrastructure, we
1836 * need to turn off Level II oplocks if gpfs:leases is enabled
1838 if (lp_level2_oplocks(SNUM(handle
->conn
))) {
1839 DEBUG(5, ("gpfs:leases are enabled, disabling "
1840 "Level II oplocks\n"));
1841 lp_do_parameter(SNUM(handle
->conn
), "level2 oplocks",
1849 static int vfs_gpfs_get_quotas(const char *path
, uid_t uid
, gid_t gid
,
1851 struct gpfs_quotaInfo
*qi_user
,
1852 struct gpfs_quotaInfo
*qi_group
,
1853 struct gpfs_quotaInfo
*qi_fset
)
1860 * We want to always use the directory to get the fileset id,
1861 * because files might have a share mode. We also do not want
1862 * to get the parent directory when there is already a
1863 * directory to avoid stepping in a different fileset. The
1864 * path passed here is currently either "." or a filename, so
1865 * this is ok. The proper solution would be having a way to
1866 * query the fileset id without opening the file.
1868 b
= parent_dirname(talloc_tos(), path
, &dir_path
, NULL
);
1874 DEBUG(10, ("path %s, directory %s\n", path
, dir_path
));
1876 err
= get_gpfs_fset_id(dir_path
, fset_id
);
1878 DEBUG(0, ("Get fset id failed path %s, dir %s, errno %d.\n",
1879 path
, dir_path
, errno
));
1883 err
= get_gpfs_quota(path
, GPFS_USRQUOTA
, uid
, qi_user
);
1888 err
= get_gpfs_quota(path
, GPFS_GRPQUOTA
, gid
, qi_group
);
1893 err
= get_gpfs_quota(path
, GPFS_FILESETQUOTA
, *fset_id
, qi_fset
);
1901 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi
, time_t cur_time
,
1902 uint64_t *dfree
, uint64_t *dsize
)
1904 uint64_t usage
, limit
;
1907 * The quota reporting is done in units of 1024 byte blocks, but
1908 * sys_fsusage uses units of 512 byte blocks, adjust the block number
1909 * accordingly. Also filter possibly negative usage counts from gpfs.
1911 usage
= qi
.blockUsage
< 0 ? 0 : (uint64_t)qi
.blockUsage
* 2;
1912 limit
= (uint64_t)qi
.blockHardLimit
* 2;
1915 * When the grace time for the exceeded soft block quota has been
1916 * exceeded, the soft block quota becomes an additional hard limit.
1918 if (qi
.blockSoftLimit
&&
1919 qi
.blockGraceTime
&& cur_time
> qi
.blockGraceTime
) {
1920 /* report disk as full */
1922 *dsize
= MIN(*dsize
, usage
);
1925 if (!qi
.blockHardLimit
)
1928 if (usage
>= limit
) {
1929 /* report disk as full */
1931 *dsize
= MIN(*dsize
, usage
);
1934 /* limit has not been reached, determine "free space" */
1935 *dfree
= MIN(*dfree
, limit
- usage
);
1936 *dsize
= MIN(*dsize
, limit
);
1940 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct
*handle
, const char *path
,
1941 bool small_query
, uint64_t *bsize
,
1942 uint64_t *dfree
, uint64_t *dsize
)
1944 struct security_unix_token
*utok
;
1945 struct gpfs_quotaInfo qi_user
, qi_group
, qi_fset
;
1946 struct gpfs_config_data
*config
;
1950 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct gpfs_config_data
,
1951 return (uint64_t)-1);
1952 if (!config
->dfreequota
) {
1953 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1954 bsize
, dfree
, dsize
);
1957 err
= sys_fsusage(path
, dfree
, dsize
);
1959 DEBUG (0, ("Could not get fs usage, errno %d\n", errno
));
1960 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1961 bsize
, dfree
, dsize
);
1964 /* sys_fsusage returns units of 512 bytes */
1967 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
1968 (unsigned long long)*dfree
, (unsigned long long)*dsize
));
1970 utok
= handle
->conn
->session_info
->unix_token
;
1971 err
= vfs_gpfs_get_quotas(path
, utok
->uid
, utok
->gid
, &fset_id
,
1972 &qi_user
, &qi_group
, &qi_fset
);
1974 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1975 bsize
, dfree
, dsize
);
1978 cur_time
= time(NULL
);
1980 /* Adjust free space and size according to quota limits. */
1981 vfs_gpfs_disk_free_quota(qi_user
, cur_time
, dfree
, dsize
);
1982 vfs_gpfs_disk_free_quota(qi_group
, cur_time
, dfree
, dsize
);
1984 /* Id 0 indicates the default quota, not an actual quota */
1986 vfs_gpfs_disk_free_quota(qi_fset
, cur_time
, dfree
, dsize
);
1989 disk_norm(small_query
, bsize
, dfree
, dsize
);
1993 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct
*handle
,
1994 enum timestamp_set_resolution
*p_ts_res
)
1996 struct gpfs_config_data
*config
;
1999 next
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
2001 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2002 struct gpfs_config_data
,
2006 next
|= FILE_SUPPORTS_REMOTE_STORAGE
;
2011 static int vfs_gpfs_open(struct vfs_handle_struct
*handle
,
2012 struct smb_filename
*smb_fname
, files_struct
*fsp
,
2013 int flags
, mode_t mode
)
2015 struct gpfs_config_data
*config
;
2017 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2018 struct gpfs_config_data
,
2021 if (config
->hsm
&& !config
->recalls
) {
2022 if (VALID_STAT(smb_fname
->st
) &&
2023 (smb_fname
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
)) {
2024 DEBUG(10, ("Refusing access to offline file %s\n",
2031 if (config
->syncio
) {
2034 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
2037 static ssize_t
vfs_gpfs_pread(vfs_handle_struct
*handle
, files_struct
*fsp
,
2038 void *data
, size_t n
, off_t offset
)
2042 ret
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
2044 DEBUG(10, ("vfs_private = %x\n",
2045 (unsigned int)fsp
->fsp_name
->st
.vfs_private
));
2048 ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0)) {
2049 fsp
->fsp_name
->st
.vfs_private
&= ~GPFS_WINATTR_OFFLINE
;
2050 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2051 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2052 fsp
->fsp_name
->base_name
);
2058 struct vfs_gpfs_pread_state
{
2059 struct files_struct
*fsp
;
2064 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
);
2066 static struct tevent_req
*vfs_gpfs_pread_send(struct vfs_handle_struct
*handle
,
2067 TALLOC_CTX
*mem_ctx
,
2068 struct tevent_context
*ev
,
2069 struct files_struct
*fsp
,
2070 void *data
, size_t n
,
2073 struct tevent_req
*req
, *subreq
;
2074 struct vfs_gpfs_pread_state
*state
;
2076 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pread_state
);
2081 subreq
= SMB_VFS_NEXT_PREAD_SEND(state
, ev
, handle
, fsp
, data
,
2083 if (tevent_req_nomem(subreq
, req
)) {
2084 return tevent_req_post(req
, ev
);
2086 tevent_req_set_callback(subreq
, vfs_gpfs_pread_done
, req
);
2090 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
)
2092 struct tevent_req
*req
= tevent_req_callback_data(
2093 subreq
, struct tevent_req
);
2094 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2095 req
, struct vfs_gpfs_pread_state
);
2097 state
->ret
= SMB_VFS_PREAD_RECV(subreq
, &state
->err
);
2098 TALLOC_FREE(subreq
);
2099 tevent_req_done(req
);
2102 static ssize_t
vfs_gpfs_pread_recv(struct tevent_req
*req
, int *err
)
2104 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2105 req
, struct vfs_gpfs_pread_state
);
2106 struct files_struct
*fsp
= state
->fsp
;
2108 if (tevent_req_is_unix_error(req
, err
)) {
2113 DEBUG(10, ("vfs_private = %x\n",
2114 (unsigned int)fsp
->fsp_name
->st
.vfs_private
));
2116 if ((state
->ret
!= -1) &&
2117 ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0)) {
2118 fsp
->fsp_name
->st
.vfs_private
&= ~GPFS_WINATTR_OFFLINE
;
2119 DEBUG(10, ("sending notify\n"));
2120 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2121 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2122 fsp
->fsp_name
->base_name
);
2128 static ssize_t
vfs_gpfs_pwrite(vfs_handle_struct
*handle
, files_struct
*fsp
,
2129 const void *data
, size_t n
, off_t offset
)
2133 ret
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
2135 DEBUG(10, ("vfs_private = %x\n",
2136 (unsigned int)fsp
->fsp_name
->st
.vfs_private
));
2139 ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0)) {
2140 fsp
->fsp_name
->st
.vfs_private
&= ~GPFS_WINATTR_OFFLINE
;
2141 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2142 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2143 fsp
->fsp_name
->base_name
);
2149 struct vfs_gpfs_pwrite_state
{
2150 struct files_struct
*fsp
;
2155 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
);
2157 static struct tevent_req
*vfs_gpfs_pwrite_send(
2158 struct vfs_handle_struct
*handle
,
2159 TALLOC_CTX
*mem_ctx
,
2160 struct tevent_context
*ev
,
2161 struct files_struct
*fsp
,
2162 const void *data
, size_t n
,
2165 struct tevent_req
*req
, *subreq
;
2166 struct vfs_gpfs_pwrite_state
*state
;
2168 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pwrite_state
);
2173 subreq
= SMB_VFS_NEXT_PWRITE_SEND(state
, ev
, handle
, fsp
, data
,
2175 if (tevent_req_nomem(subreq
, req
)) {
2176 return tevent_req_post(req
, ev
);
2178 tevent_req_set_callback(subreq
, vfs_gpfs_pwrite_done
, req
);
2182 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
)
2184 struct tevent_req
*req
= tevent_req_callback_data(
2185 subreq
, struct tevent_req
);
2186 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2187 req
, struct vfs_gpfs_pwrite_state
);
2189 state
->ret
= SMB_VFS_PWRITE_RECV(subreq
, &state
->err
);
2190 TALLOC_FREE(subreq
);
2191 tevent_req_done(req
);
2194 static ssize_t
vfs_gpfs_pwrite_recv(struct tevent_req
*req
, int *err
)
2196 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2197 req
, struct vfs_gpfs_pwrite_state
);
2198 struct files_struct
*fsp
= state
->fsp
;
2200 if (tevent_req_is_unix_error(req
, err
)) {
2205 DEBUG(10, ("vfs_private = %x\n",
2206 (unsigned int)fsp
->fsp_name
->st
.vfs_private
));
2208 if ((state
->ret
!= -1) &&
2209 ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0)) {
2210 fsp
->fsp_name
->st
.vfs_private
&= ~GPFS_WINATTR_OFFLINE
;
2211 DEBUG(10, ("sending notify\n"));
2212 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2213 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2214 fsp
->fsp_name
->base_name
);
2221 static struct vfs_fn_pointers vfs_gpfs_fns
= {
2222 .connect_fn
= vfs_gpfs_connect
,
2223 .disk_free_fn
= vfs_gpfs_disk_free
,
2224 .fs_capabilities_fn
= vfs_gpfs_capabilities
,
2225 .kernel_flock_fn
= vfs_gpfs_kernel_flock
,
2226 .linux_setlease_fn
= vfs_gpfs_setlease
,
2227 .get_real_filename_fn
= vfs_gpfs_get_real_filename
,
2228 .fget_nt_acl_fn
= gpfsacl_fget_nt_acl
,
2229 .get_nt_acl_fn
= gpfsacl_get_nt_acl
,
2230 .fset_nt_acl_fn
= gpfsacl_fset_nt_acl
,
2231 .sys_acl_get_file_fn
= gpfsacl_sys_acl_get_file
,
2232 .sys_acl_get_fd_fn
= gpfsacl_sys_acl_get_fd
,
2233 .sys_acl_blob_get_file_fn
= gpfsacl_sys_acl_blob_get_file
,
2234 .sys_acl_blob_get_fd_fn
= gpfsacl_sys_acl_blob_get_fd
,
2235 .sys_acl_set_file_fn
= gpfsacl_sys_acl_set_file
,
2236 .sys_acl_set_fd_fn
= gpfsacl_sys_acl_set_fd
,
2237 .sys_acl_delete_def_file_fn
= gpfsacl_sys_acl_delete_def_file
,
2238 .chmod_fn
= vfs_gpfs_chmod
,
2239 .fchmod_fn
= vfs_gpfs_fchmod
,
2240 .close_fn
= vfs_gpfs_close
,
2241 .setxattr_fn
= gpfs_set_xattr
,
2242 .getxattr_fn
= gpfs_get_xattr
,
2243 .stat_fn
= vfs_gpfs_stat
,
2244 .fstat_fn
= vfs_gpfs_fstat
,
2245 .lstat_fn
= vfs_gpfs_lstat
,
2246 .ntimes_fn
= vfs_gpfs_ntimes
,
2247 .is_offline_fn
= vfs_gpfs_is_offline
,
2248 .aio_force_fn
= vfs_gpfs_aio_force
,
2249 .sendfile_fn
= vfs_gpfs_sendfile
,
2250 .fallocate_fn
= vfs_gpfs_fallocate
,
2251 .open_fn
= vfs_gpfs_open
,
2252 .pread_fn
= vfs_gpfs_pread
,
2253 .pread_send_fn
= vfs_gpfs_pread_send
,
2254 .pread_recv_fn
= vfs_gpfs_pread_recv
,
2255 .pwrite_fn
= vfs_gpfs_pwrite
,
2256 .pwrite_send_fn
= vfs_gpfs_pwrite_send
,
2257 .pwrite_recv_fn
= vfs_gpfs_pwrite_recv
,
2258 .ftruncate_fn
= vfs_gpfs_ftruncate
2261 NTSTATUS
vfs_gpfs_init(void);
2262 NTSTATUS
vfs_gpfs_init(void)
2266 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "gpfs",