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
{
54 static int vfs_gpfs_kernel_flock(vfs_handle_struct
*handle
, files_struct
*fsp
,
55 uint32 share_mode
, uint32 access_mask
)
58 struct gpfs_config_data
*config
;
61 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
62 struct gpfs_config_data
,
65 if(!config
->sharemodes
) {
69 START_PROFILE(syscall_kernel_flock
);
71 kernel_flock(fsp
->fh
->fd
, share_mode
, access_mask
);
73 if (!set_gpfs_sharemode(fsp
, access_mask
, fsp
->share_access
)) {
77 END_PROFILE(syscall_kernel_flock
);
82 static int vfs_gpfs_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
85 struct gpfs_config_data
*config
;
87 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
88 struct gpfs_config_data
,
91 if (config
->sharemodes
&& (fsp
->fh
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
92 set_gpfs_sharemode(fsp
, 0, 0);
95 return SMB_VFS_NEXT_CLOSE(handle
, fsp
);
98 static int vfs_gpfs_setlease(vfs_handle_struct
*handle
, files_struct
*fsp
,
101 struct gpfs_config_data
*config
;
104 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
105 struct gpfs_config_data
,
108 if (linux_set_lease_sighandler(fsp
->fh
->fd
) == -1)
111 START_PROFILE(syscall_linux_setlease
);
113 if (config
->leases
) {
114 ret
= set_gpfs_lease(fsp
->fh
->fd
,leasetype
);
117 END_PROFILE(syscall_linux_setlease
);
122 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct
*handle
,
130 char real_pathname
[PATH_MAX
+1];
133 struct gpfs_config_data
*config
;
135 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
136 struct gpfs_config_data
,
139 if (!config
->getrealfilename
) {
140 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
141 mem_ctx
, found_name
);
144 mangled
= mangle_is_mangled(name
, handle
->conn
->params
);
146 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
147 mem_ctx
, found_name
);
150 full_path
= talloc_asprintf(talloc_tos(), "%s/%s", path
, name
);
151 if (full_path
== NULL
) {
156 buflen
= sizeof(real_pathname
) - 1;
158 result
= smbd_gpfs_get_realfilename_path(full_path
, real_pathname
,
161 TALLOC_FREE(full_path
);
163 if ((result
== -1) && (errno
== ENOSYS
)) {
164 return SMB_VFS_NEXT_GET_REAL_FILENAME(
165 handle
, path
, name
, mem_ctx
, found_name
);
169 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
175 * GPFS does not necessarily null-terminate the returned path
176 * but instead returns the buffer length in buflen.
179 if (buflen
< sizeof(real_pathname
)) {
180 real_pathname
[buflen
] = '\0';
182 real_pathname
[sizeof(real_pathname
)-1] = '\0';
185 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
186 path
, name
, real_pathname
));
188 name
= strrchr_m(real_pathname
, '/');
194 *found_name
= talloc_strdup(mem_ctx
, name
+1);
195 if (*found_name
== NULL
) {
203 static void gpfs_dumpacl(int level
, struct gpfs_acl
*gacl
)
208 DEBUG(0, ("gpfs acl is NULL\n"));
212 DEBUG(level
, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n",
213 gacl
->acl_nace
, gacl
->acl_type
, gacl
->acl_version
, gacl
->acl_level
, gacl
->acl_len
));
214 for(i
=0; i
<gacl
->acl_nace
; i
++)
216 struct gpfs_ace_v4
*gace
= gacl
->ace_v4
+ i
;
217 DEBUG(level
, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n",
218 i
, gace
->aceType
, gace
->aceFlags
, gace
->aceMask
,
219 gace
->aceIFlags
, gace
->aceWho
));
224 * get the ACL from GPFS, allocated on the specified mem_ctx
225 * internally retries when initial buffer was too small
227 * caller needs to cast result to either
228 * raw = yes: struct gpfs_opaque_acl
229 * raw = no: struct gpfs_acl
232 static void *vfs_gpfs_getacl(TALLOC_CTX
*mem_ctx
,
235 const gpfs_aclType_t type
)
246 aclbuf
= talloc_zero_size(mem_ctx
, size
);
247 if (aclbuf
== NULL
) {
253 struct gpfs_opaque_acl
*buf
= (struct gpfs_opaque_acl
*) aclbuf
;
254 buf
->acl_type
= type
;
255 flags
= GPFS_GETACL_NATIVE
;
256 len
= (unsigned int *) &(buf
->acl_buffer_len
);
257 struct_size
= sizeof(struct gpfs_opaque_acl
);
259 struct gpfs_acl
*buf
= (struct gpfs_acl
*) aclbuf
;
260 buf
->acl_type
= type
;
261 flags
= GPFS_GETACL_STRUCT
;
262 len
= &(buf
->acl_len
);
263 struct_size
= sizeof(struct gpfs_acl
);
266 /* set the length of the buffer as input value */
270 ret
= smbd_gpfs_getacl((char *)fname
, flags
, aclbuf
);
271 if ((ret
!= 0) && (errno
== ENOSPC
)) {
273 * get the size needed to accommodate the complete buffer
275 * the value returned only applies to the ACL blob in the
276 * struct so make sure to also have headroom for the first
277 * struct members by adding room for the complete struct
278 * (might be a few bytes too much then)
280 size
= *len
+ struct_size
;
282 DEBUG(10, ("Increasing ACL buffer size to %zu\n", size
));
287 DEBUG(5, ("smbd_gpfs_getacl failed with %s\n",
296 /* Tries to get nfs4 acls and returns SMB ACL allocated.
297 * On failure returns 1 if it got non-NFSv4 ACL to prompt
298 * retry with POSIX ACL checks.
299 * On failure returns -1 if there is system (GPFS) error, check errno.
300 * Returns 0 on success
302 static int gpfs_get_nfs4_acl(const char *fname
, SMB4ACL_T
**ppacl
)
305 struct gpfs_acl
*gacl
= NULL
;
306 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname
));
309 gacl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(), fname
,
312 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
313 fname
, strerror(errno
)));
317 if (gacl
->acl_type
!= GPFS_ACL_TYPE_NFS4
) {
318 DEBUG(10, ("Got non-nfsv4 acl\n"));
319 /* Retry with POSIX ACLs check */
324 *ppacl
= smb_create_smb4acl();
326 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
327 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
330 for (i
=0; i
<gacl
->acl_nace
; i
++) {
331 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[i
];
332 SMB_ACE4PROP_T smbace
;
333 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
334 "who: %d\n", gace
->aceType
, gace
->aceIFlags
,
335 gace
->aceFlags
, gace
->aceMask
, gace
->aceWho
));
338 if (gace
->aceIFlags
& ACE4_IFLAG_SPECIAL_ID
) {
339 smbace
.flags
|= SMB_ACE4_ID_SPECIAL
;
340 switch (gace
->aceWho
) {
341 case ACE4_SPECIAL_OWNER
:
342 smbace
.who
.special_id
= SMB_ACE4_WHO_OWNER
;
344 case ACE4_SPECIAL_GROUP
:
345 smbace
.who
.special_id
= SMB_ACE4_WHO_GROUP
;
347 case ACE4_SPECIAL_EVERYONE
:
348 smbace
.who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
351 DEBUG(8, ("invalid special gpfs id %d "
352 "ignored\n", gace
->aceWho
));
353 continue; /* don't add it */
356 if (gace
->aceFlags
& ACE4_FLAG_GROUP_ID
)
357 smbace
.who
.gid
= gace
->aceWho
;
359 smbace
.who
.uid
= gace
->aceWho
;
362 /* remove redundant deny entries */
363 if (i
> 0 && gace
->aceType
== SMB_ACE4_ACCESS_DENIED_ACE_TYPE
) {
364 struct gpfs_ace_v4
*prev
= &gacl
->ace_v4
[i
-1];
365 if (prev
->aceType
== SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
&&
366 prev
->aceFlags
== gace
->aceFlags
&&
367 prev
->aceIFlags
== gace
->aceIFlags
&&
368 (gace
->aceMask
& prev
->aceMask
) == 0 &&
369 gace
->aceWho
== prev
->aceWho
) {
370 /* it's redundant - skip it */
375 smbace
.aceType
= gace
->aceType
;
376 smbace
.aceFlags
= gace
->aceFlags
;
377 smbace
.aceMask
= gace
->aceMask
;
378 smb_add_ace4(*ppacl
, &smbace
);
386 static NTSTATUS
gpfsacl_fget_nt_acl(vfs_handle_struct
*handle
,
387 files_struct
*fsp
, uint32 security_info
,
389 struct security_descriptor
**ppdesc
)
391 SMB4ACL_T
*pacl
= NULL
;
393 struct gpfs_config_data
*config
;
397 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
398 struct gpfs_config_data
,
399 return NT_STATUS_INTERNAL_ERROR
);
402 return SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
406 result
= gpfs_get_nfs4_acl(fsp
->fsp_name
->base_name
, &pacl
);
409 return smb_fget_nt_acl_nfs4(fsp
, security_info
, mem_ctx
, ppdesc
, pacl
);
412 DEBUG(10, ("retrying with posix acl...\n"));
413 return posix_fget_nt_acl(fsp
, security_info
, mem_ctx
, ppdesc
);
416 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
417 return map_nt_error_from_unix(errno
);
420 static NTSTATUS
gpfsacl_get_nt_acl(vfs_handle_struct
*handle
,
422 uint32 security_info
,
423 TALLOC_CTX
*mem_ctx
, struct security_descriptor
**ppdesc
)
425 SMB4ACL_T
*pacl
= NULL
;
427 struct gpfs_config_data
*config
;
431 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
432 struct gpfs_config_data
,
433 return NT_STATUS_INTERNAL_ERROR
);
436 return SMB_VFS_NEXT_GET_NT_ACL(handle
, name
, security_info
,
440 result
= gpfs_get_nfs4_acl(name
, &pacl
);
443 return smb_get_nt_acl_nfs4(handle
->conn
, name
, security_info
,
444 mem_ctx
, ppdesc
, pacl
);
447 DEBUG(10, ("retrying with posix acl...\n"));
448 return posix_get_nt_acl(handle
->conn
, name
, security_info
,
452 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
453 return map_nt_error_from_unix(errno
);
456 static bool gpfsacl_process_smbacl(files_struct
*fsp
, SMB4ACL_T
*smbacl
)
459 gpfs_aclLen_t gacl_len
;
461 struct gpfs_acl
*gacl
;
462 TALLOC_CTX
*mem_ctx
= talloc_tos();
464 gacl_len
= offsetof(gpfs_acl_t
, ace_v4
) + smb_get_naces(smbacl
) *
465 sizeof(gpfs_ace_v4_t
);
467 gacl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, gacl_len
);
469 DEBUG(0, ("talloc failed\n"));
474 gacl
->acl_len
= gacl_len
;
476 gacl
->acl_version
= GPFS_ACL_VERSION_NFS4
;
477 gacl
->acl_type
= GPFS_ACL_TYPE_NFS4
;
478 gacl
->acl_nace
= 0; /* change later... */
480 for (smbace
=smb_first_ace4(smbacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
481 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[gacl
->acl_nace
];
482 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
484 gace
->aceType
= aceprop
->aceType
;
485 gace
->aceFlags
= aceprop
->aceFlags
;
486 gace
->aceMask
= aceprop
->aceMask
;
489 * GPFS can't distinguish between WRITE and APPEND on
490 * files, so one being set without the other is an
491 * error. Sorry for the many ()'s :-)
494 if (!fsp
->is_directory
496 ((((gace
->aceMask
& ACE4_MASK_WRITE
) == 0)
497 && ((gace
->aceMask
& ACE4_MASK_APPEND
) != 0))
499 (((gace
->aceMask
& ACE4_MASK_WRITE
) != 0)
500 && ((gace
->aceMask
& ACE4_MASK_APPEND
) == 0)))
502 lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
503 "merge_writeappend", True
)) {
504 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
505 "WRITE^APPEND, setting WRITE|APPEND\n",
507 gace
->aceMask
|= ACE4_MASK_WRITE
|ACE4_MASK_APPEND
;
510 gace
->aceIFlags
= (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
) ? ACE4_IFLAG_SPECIAL_ID
: 0;
512 if (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
)
514 switch(aceprop
->who
.special_id
)
516 case SMB_ACE4_WHO_EVERYONE
:
517 gace
->aceWho
= ACE4_SPECIAL_EVERYONE
;
519 case SMB_ACE4_WHO_OWNER
:
520 gace
->aceWho
= ACE4_SPECIAL_OWNER
;
522 case SMB_ACE4_WHO_GROUP
:
523 gace
->aceWho
= ACE4_SPECIAL_GROUP
;
526 DEBUG(8, ("unsupported special_id %d\n", aceprop
->who
.special_id
));
527 continue; /* don't add it !!! */
530 /* just only for the type safety... */
531 if (aceprop
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)
532 gace
->aceWho
= aceprop
->who
.gid
;
534 gace
->aceWho
= aceprop
->who
.uid
;
540 ret
= smbd_gpfs_putacl(fsp
->fsp_name
->base_name
,
541 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gacl
);
543 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno
)));
544 gpfs_dumpacl(8, gacl
);
548 DEBUG(10, ("gpfs_putacl succeeded\n"));
552 static NTSTATUS
gpfsacl_set_nt_acl_internal(files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
554 struct gpfs_acl
*acl
;
555 NTSTATUS result
= NT_STATUS_ACCESS_DENIED
;
557 acl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(),
558 fsp
->fsp_name
->base_name
,
561 return map_nt_error_from_unix(errno
);
564 if (acl
->acl_version
== GPFS_ACL_VERSION_NFS4
) {
565 if (lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
566 "refuse_dacl_protected", false)
567 && (psd
->type
&SEC_DESC_DACL_PROTECTED
)) {
568 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
570 return NT_STATUS_NOT_SUPPORTED
;
573 result
= smb_set_nt_acl_nfs4(
574 fsp
, security_info_sent
, psd
,
575 gpfsacl_process_smbacl
);
576 } else { /* assume POSIX ACL - by default... */
577 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
584 static NTSTATUS
gpfsacl_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
586 struct gpfs_config_data
*config
;
588 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
589 struct gpfs_config_data
,
590 return NT_STATUS_INTERNAL_ERROR
);
593 return SMB_VFS_NEXT_FSET_NT_ACL(handle
, fsp
, security_info_sent
, psd
);
596 return gpfsacl_set_nt_acl_internal(fsp
, security_info_sent
, psd
);
599 static SMB_ACL_T
gpfs2smb_acl(const struct gpfs_acl
*pacl
, TALLOC_CTX
*mem_ctx
)
604 result
= sys_acl_init(mem_ctx
);
605 if (result
== NULL
) {
610 result
->count
= pacl
->acl_nace
;
611 result
->acl
= talloc_realloc(result
, result
->acl
, struct smb_acl_entry
,
613 if (result
->acl
== NULL
) {
619 for (i
=0; i
<pacl
->acl_nace
; i
++) {
620 struct smb_acl_entry
*ace
= &result
->acl
[i
];
621 const struct gpfs_ace_v1
*g_ace
= &pacl
->ace_v1
[i
];
623 DEBUG(10, ("Converting type %d id %lu perm %x\n",
624 (int)g_ace
->ace_type
, (unsigned long)g_ace
->ace_who
,
625 (int)g_ace
->ace_perm
));
627 switch (g_ace
->ace_type
) {
629 ace
->a_type
= SMB_ACL_USER
;
630 ace
->info
.user
.uid
= (uid_t
)g_ace
->ace_who
;
632 case GPFS_ACL_USER_OBJ
:
633 ace
->a_type
= SMB_ACL_USER_OBJ
;
636 ace
->a_type
= SMB_ACL_GROUP
;
637 ace
->info
.group
.gid
= (gid_t
)g_ace
->ace_who
;
639 case GPFS_ACL_GROUP_OBJ
:
640 ace
->a_type
= SMB_ACL_GROUP_OBJ
;
643 ace
->a_type
= SMB_ACL_OTHER
;
646 ace
->a_type
= SMB_ACL_MASK
;
649 DEBUG(10, ("Got invalid ace_type: %d\n",
657 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_READ
) ?
659 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_WRITE
) ?
661 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_EXECUTE
) ?
664 DEBUGADD(10, ("Converted to %d perm %x\n",
665 ace
->a_type
, ace
->a_perm
));
671 static SMB_ACL_T
gpfsacl_get_posix_acl(const char *path
, gpfs_aclType_t type
,
674 struct gpfs_acl
*pacl
;
675 SMB_ACL_T result
= NULL
;
677 pacl
= vfs_gpfs_getacl(talloc_tos(), path
, false, type
);
680 DEBUG(10, ("vfs_gpfs_getacl failed for %s with %s\n",
681 path
, strerror(errno
)));
688 if (pacl
->acl_version
!= GPFS_ACL_VERSION_POSIX
) {
689 DEBUG(10, ("Got acl version %d, expected %d\n",
690 pacl
->acl_version
, GPFS_ACL_VERSION_POSIX
));
695 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
696 pacl
->acl_len
, pacl
->acl_level
, pacl
->acl_version
,
699 result
= gpfs2smb_acl(pacl
, mem_ctx
);
700 if (result
!= NULL
) {
715 static SMB_ACL_T
gpfsacl_sys_acl_get_file(vfs_handle_struct
*handle
,
720 gpfs_aclType_t gpfs_type
;
721 struct gpfs_config_data
*config
;
723 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
724 struct gpfs_config_data
,
728 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle
, path_p
,
733 case SMB_ACL_TYPE_ACCESS
:
734 gpfs_type
= GPFS_ACL_TYPE_ACCESS
;
736 case SMB_ACL_TYPE_DEFAULT
:
737 gpfs_type
= GPFS_ACL_TYPE_DEFAULT
;
740 DEBUG(0, ("Got invalid type: %d\n", type
));
741 smb_panic("exiting");
744 return gpfsacl_get_posix_acl(path_p
, gpfs_type
, mem_ctx
);
747 static SMB_ACL_T
gpfsacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
751 struct gpfs_config_data
*config
;
753 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
754 struct gpfs_config_data
,
758 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle
, fsp
, mem_ctx
);
761 return gpfsacl_get_posix_acl(fsp
->fsp_name
->base_name
,
762 GPFS_ACL_TYPE_ACCESS
, mem_ctx
);
765 static int gpfsacl_sys_acl_blob_get_file(vfs_handle_struct
*handle
,
768 char **blob_description
,
771 struct gpfs_config_data
*config
;
772 struct gpfs_opaque_acl
*acl
= NULL
;
776 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
777 struct gpfs_config_data
,
781 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle
, path_p
,
788 acl
= (struct gpfs_opaque_acl
*)
789 vfs_gpfs_getacl(mem_ctx
,
795 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
796 errno
, strerror(errno
)));
798 /* EINVAL means POSIX ACL, bail out on other cases */
799 if (errno
!= EINVAL
) {
808 * we only need the actual ACL blob here
809 * acl_version will always be NFS4 because we asked
811 * acl_type is only used for POSIX ACLs
813 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
814 aclblob
.length
= acl
->acl_buffer_len
;
816 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
817 if (!*blob_description
) {
823 result
= non_posix_sys_acl_blob_get_file_helper(handle
, path_p
,
831 /* fall back to POSIX ACL */
832 return posix_sys_acl_blob_get_file(handle
, path_p
, mem_ctx
,
833 blob_description
, blob
);
836 static int gpfsacl_sys_acl_blob_get_fd(vfs_handle_struct
*handle
,
839 char **blob_description
,
842 struct gpfs_config_data
*config
;
843 struct gpfs_opaque_acl
*acl
= NULL
;
847 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
848 struct gpfs_config_data
,
852 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle
, fsp
, mem_ctx
,
853 blob_description
, blob
);
857 acl
= (struct gpfs_opaque_acl
*) vfs_gpfs_getacl(mem_ctx
,
858 fsp
->fsp_name
->base_name
,
863 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
864 errno
, strerror(errno
)));
866 /* EINVAL means POSIX ACL, bail out on other cases */
867 if (errno
!= EINVAL
) {
876 * we only need the actual ACL blob here
877 * acl_version will always be NFS4 because we asked
879 * acl_type is only used for POSIX ACLs
881 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
882 aclblob
.length
= acl
->acl_buffer_len
;
884 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
885 if (!*blob_description
) {
891 result
= non_posix_sys_acl_blob_get_fd_helper(handle
, fsp
,
899 /* fall back to POSIX ACL */
900 return posix_sys_acl_blob_get_fd(handle
, fsp
, mem_ctx
,
901 blob_description
, blob
);
904 static struct gpfs_acl
*smb2gpfs_acl(const SMB_ACL_T pacl
,
908 struct gpfs_acl
*result
;
911 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl
->count
));
913 len
= offsetof(gpfs_acl_t
, ace_v1
) + (pacl
->count
) *
914 sizeof(gpfs_ace_v1_t
);
916 result
= (struct gpfs_acl
*)SMB_MALLOC(len
);
917 if (result
== NULL
) {
922 result
->acl_len
= len
;
923 result
->acl_level
= 0;
924 result
->acl_version
= GPFS_ACL_VERSION_POSIX
;
925 result
->acl_type
= (type
== SMB_ACL_TYPE_DEFAULT
) ?
926 GPFS_ACL_TYPE_DEFAULT
: GPFS_ACL_TYPE_ACCESS
;
927 result
->acl_nace
= pacl
->count
;
929 for (i
=0; i
<pacl
->count
; i
++) {
930 const struct smb_acl_entry
*ace
= &pacl
->acl
[i
];
931 struct gpfs_ace_v1
*g_ace
= &result
->ace_v1
[i
];
933 DEBUG(10, ("Converting type %d perm %x\n",
934 (int)ace
->a_type
, (int)ace
->a_perm
));
938 switch(ace
->a_type
) {
940 g_ace
->ace_type
= GPFS_ACL_USER
;
941 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.user
.uid
;
943 case SMB_ACL_USER_OBJ
:
944 g_ace
->ace_type
= GPFS_ACL_USER_OBJ
;
945 g_ace
->ace_perm
|= ACL_PERM_CONTROL
;
949 g_ace
->ace_type
= GPFS_ACL_GROUP
;
950 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.group
.gid
;
952 case SMB_ACL_GROUP_OBJ
:
953 g_ace
->ace_type
= GPFS_ACL_GROUP_OBJ
;
957 g_ace
->ace_type
= GPFS_ACL_MASK
;
958 g_ace
->ace_perm
= 0x8f;
962 g_ace
->ace_type
= GPFS_ACL_OTHER
;
966 DEBUG(10, ("Got invalid ace_type: %d\n", ace
->a_type
));
972 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_READ
) ?
974 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_WRITE
) ?
976 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_EXECUTE
) ?
977 ACL_PERM_EXECUTE
: 0;
979 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
980 g_ace
->ace_type
, g_ace
->ace_who
, g_ace
->ace_perm
));
986 static int gpfsacl_sys_acl_set_file(vfs_handle_struct
*handle
,
991 struct gpfs_acl
*gpfs_acl
;
993 struct gpfs_config_data
*config
;
995 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
996 struct gpfs_config_data
,
1000 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle
, name
, type
, theacl
);
1003 gpfs_acl
= smb2gpfs_acl(theacl
, type
);
1004 if (gpfs_acl
== NULL
) {
1008 result
= smbd_gpfs_putacl((char *)name
, GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gpfs_acl
);
1010 SAFE_FREE(gpfs_acl
);
1014 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
1018 struct gpfs_config_data
*config
;
1020 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1021 struct gpfs_config_data
,
1025 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle
, fsp
, theacl
);
1028 return gpfsacl_sys_acl_set_file(handle
, fsp
->fsp_name
->base_name
,
1029 SMB_ACL_TYPE_ACCESS
, theacl
);
1032 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
1035 struct gpfs_config_data
*config
;
1037 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1038 struct gpfs_config_data
,
1042 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle
, path
);
1050 * Assumed: mode bits are shiftable and standard
1051 * Output: the new aceMask field for an smb nfs4 ace
1053 static uint32
gpfsacl_mask_filter(uint32 aceType
, uint32 aceMask
, uint32 rwx
)
1055 const uint32 posix_nfs4map
[3] = {
1056 SMB_ACE4_EXECUTE
, /* execute */
1057 SMB_ACE4_WRITE_DATA
| SMB_ACE4_APPEND_DATA
, /* write; GPFS specific */
1058 SMB_ACE4_READ_DATA
/* read */
1061 uint32_t posix_mask
= 0x01;
1065 for(i
=0; i
<3; i
++) {
1066 nfs4_bits
= posix_nfs4map
[i
];
1067 posix_bit
= rwx
& posix_mask
;
1069 if (aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
) {
1071 aceMask
|= nfs4_bits
;
1073 aceMask
&= ~nfs4_bits
;
1075 /* add deny bits when suitable */
1077 aceMask
|= nfs4_bits
;
1079 aceMask
&= ~nfs4_bits
;
1080 } /* other ace types are unexpected */
1088 static int gpfsacl_emu_chmod(const char *path
, mode_t mode
)
1090 SMB4ACL_T
*pacl
= NULL
;
1092 bool haveAllowEntry
[SMB_ACE4_WHO_EVERYONE
+ 1] = {False
, False
, False
, False
};
1094 files_struct fake_fsp
; /* TODO: rationalize parametrization */
1098 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path
, mode
));
1100 result
= gpfs_get_nfs4_acl(path
, &pacl
);
1104 if (mode
& ~(S_IRWXU
| S_IRWXG
| S_IRWXO
)) {
1105 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode
, path
));
1108 for (smbace
=smb_first_ace4(pacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
1109 SMB_ACE4PROP_T
*ace
= smb_get_ace4(smbace
);
1110 uint32_t specid
= ace
->who
.special_id
;
1112 if (ace
->flags
&SMB_ACE4_ID_SPECIAL
&&
1113 ace
->aceType
<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE
&&
1114 specid
<= SMB_ACE4_WHO_EVERYONE
) {
1118 if (ace
->aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
)
1119 haveAllowEntry
[specid
] = True
;
1121 /* mode >> 6 for @owner, mode >> 3 for @group,
1122 * mode >> 0 for @everyone */
1123 newMask
= gpfsacl_mask_filter(ace
->aceType
, ace
->aceMask
,
1124 mode
>> ((SMB_ACE4_WHO_EVERYONE
- specid
) * 3));
1125 if (ace
->aceMask
!=newMask
) {
1126 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
1127 path
, ace
->aceMask
, newMask
, specid
));
1129 ace
->aceMask
= newMask
;
1133 /* make sure we have at least ALLOW entries
1134 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
1137 for(i
= SMB_ACE4_WHO_OWNER
; i
<=SMB_ACE4_WHO_EVERYONE
; i
++) {
1140 if (haveAllowEntry
[i
]==True
)
1144 ace
.aceType
= SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
;
1145 ace
.flags
|= SMB_ACE4_ID_SPECIAL
;
1146 ace
.who
.special_id
= i
;
1148 if (i
==SMB_ACE4_WHO_GROUP
) /* not sure it's necessary... */
1149 ace
.aceFlags
|= SMB_ACE4_IDENTIFIER_GROUP
;
1151 ace
.aceMask
= gpfsacl_mask_filter(ace
.aceType
, ace
.aceMask
,
1152 mode
>> ((SMB_ACE4_WHO_EVERYONE
- i
) * 3));
1154 /* don't add unnecessary aces */
1158 /* we add it to the END - as windows expects allow aces */
1159 smb_add_ace4(pacl
, &ace
);
1160 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1161 path
, mode
, i
, ace
.aceMask
));
1164 /* don't add complementary DENY ACEs here */
1165 ZERO_STRUCT(fake_fsp
);
1166 status
= create_synthetic_smb_fname(talloc_tos(), path
, NULL
, NULL
,
1167 &fake_fsp
.fsp_name
);
1168 if (!NT_STATUS_IS_OK(status
)) {
1169 errno
= map_errno_from_nt_status(status
);
1173 if (gpfsacl_process_smbacl(&fake_fsp
, pacl
) == False
) {
1174 TALLOC_FREE(fake_fsp
.fsp_name
);
1178 TALLOC_FREE(fake_fsp
.fsp_name
);
1179 return 0; /* ok for [f]chmod */
1182 static int vfs_gpfs_chmod(vfs_handle_struct
*handle
, const char *path
, mode_t mode
)
1184 struct smb_filename
*smb_fname_cpath
;
1188 status
= create_synthetic_smb_fname(
1189 talloc_tos(), path
, NULL
, NULL
, &smb_fname_cpath
);
1191 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_cpath
) != 0) {
1195 /* avoid chmod() if possible, to preserve acls */
1196 if ((smb_fname_cpath
->st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1200 rc
= gpfsacl_emu_chmod(path
, mode
);
1202 return SMB_VFS_NEXT_CHMOD(handle
, path
, mode
);
1206 static int vfs_gpfs_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
1211 if (SMB_VFS_NEXT_FSTAT(handle
, fsp
, &st
) != 0) {
1215 /* avoid chmod() if possible, to preserve acls */
1216 if ((st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1220 rc
= gpfsacl_emu_chmod(fsp
->fsp_name
->base_name
, mode
);
1222 return SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
1226 static int gpfs_set_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1227 const char *name
, const void *value
, size_t size
, int flags
){
1228 struct xattr_DOSATTRIB dosattrib
;
1229 enum ndr_err_code ndr_err
;
1231 const char *attrstr
= value
;
1232 unsigned int dosmode
=0;
1233 struct gpfs_winattr attrs
;
1235 struct gpfs_config_data
*config
;
1237 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1238 struct gpfs_config_data
,
1241 if (!config
->winattr
) {
1242 DEBUG(10, ("gpfs_set_xattr:name is %s -> next\n",name
));
1243 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1246 DEBUG(10, ("gpfs_set_xattr: %s \n",path
));
1248 /* Only handle DOS Attributes */
1249 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1250 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name
));
1251 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1254 blob
.data
= (uint8_t *)attrstr
;
1257 ndr_err
= ndr_pull_struct_blob(&blob
, talloc_tos(), &dosattrib
,
1258 (ndr_pull_flags_fn_t
)ndr_pull_xattr_DOSATTRIB
);
1260 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1261 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
1262 "from EA on file %s: Error = %s\n",
1263 path
, ndr_errstr(ndr_err
)));
1267 if (dosattrib
.version
!= 3) {
1268 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
1269 "%d\n", (int)dosattrib
.version
));
1272 if (!(dosattrib
.info
.info3
.valid_flags
& XATTR_DOSINFO_ATTRIB
)) {
1273 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
1274 "valid, ignoring\n"));
1278 dosmode
= dosattrib
.info
.info3
.attrib
;
1281 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
1282 if (dosmode
& FILE_ATTRIBUTE_ARCHIVE
){
1283 attrs
.winAttrs
|= GPFS_WINATTR_ARCHIVE
;
1285 if (dosmode
& FILE_ATTRIBUTE_HIDDEN
){
1286 attrs
.winAttrs
|= GPFS_WINATTR_HIDDEN
;
1288 if (dosmode
& FILE_ATTRIBUTE_SYSTEM
){
1289 attrs
.winAttrs
|= GPFS_WINATTR_SYSTEM
;
1291 if (dosmode
& FILE_ATTRIBUTE_READONLY
){
1292 attrs
.winAttrs
|= GPFS_WINATTR_READONLY
;
1294 if (dosmode
& FILE_ATTRIBUTE_SPARSE
) {
1295 attrs
.winAttrs
|= GPFS_WINATTR_SPARSE_FILE
;
1299 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1300 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1302 if (errno
== ENOSYS
) {
1303 return SMB_VFS_NEXT_SETXATTR(handle
, path
, name
, value
,
1307 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret
));
1311 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs
.winAttrs
));
1315 static ssize_t
gpfs_get_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1316 const char *name
, void *value
, size_t size
){
1317 char *attrstr
= value
;
1318 unsigned int dosmode
= 0;
1319 struct gpfs_winattr attrs
;
1321 struct gpfs_config_data
*config
;
1323 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1324 struct gpfs_config_data
,
1327 if (!config
->winattr
) {
1328 DEBUG(10, ("gpfs_get_xattr:name is %s -> next\n",name
));
1329 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1332 DEBUG(10, ("gpfs_get_xattr: %s \n",path
));
1334 /* Only handle DOS Attributes */
1335 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1336 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name
));
1337 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1340 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1342 if (errno
== ENOSYS
) {
1343 return SMB_VFS_NEXT_GETXATTR(handle
, path
, name
, value
,
1347 DEBUG(1, ("gpfs_get_xattr: Get GPFS attributes failed: "
1348 "%d (%s)\n", ret
, strerror(errno
)));
1352 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs
.winAttrs
));
1354 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1355 if (attrs
.winAttrs
& GPFS_WINATTR_ARCHIVE
){
1356 dosmode
|= FILE_ATTRIBUTE_ARCHIVE
;
1358 if (attrs
.winAttrs
& GPFS_WINATTR_HIDDEN
){
1359 dosmode
|= FILE_ATTRIBUTE_HIDDEN
;
1361 if (attrs
.winAttrs
& GPFS_WINATTR_SYSTEM
){
1362 dosmode
|= FILE_ATTRIBUTE_SYSTEM
;
1364 if (attrs
.winAttrs
& GPFS_WINATTR_READONLY
){
1365 dosmode
|= FILE_ATTRIBUTE_READONLY
;
1367 if (attrs
.winAttrs
& GPFS_WINATTR_SPARSE_FILE
) {
1368 dosmode
|= FILE_ATTRIBUTE_SPARSE
;
1371 snprintf(attrstr
, size
, "0x%2.2x",
1372 (unsigned int)(dosmode
& SAMBA_ATTRIBUTES_MASK
));
1373 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr
));
1377 static int vfs_gpfs_stat(struct vfs_handle_struct
*handle
,
1378 struct smb_filename
*smb_fname
)
1380 struct gpfs_winattr attrs
;
1384 struct gpfs_config_data
*config
;
1386 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1387 struct gpfs_config_data
,
1390 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
1395 if (!config
->winattr
) {
1399 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &fname
);
1400 if (!NT_STATUS_IS_OK(status
)) {
1401 errno
= map_errno_from_nt_status(status
);
1404 ret
= get_gpfs_winattrs(discard_const_p(char, fname
), &attrs
);
1407 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1408 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1409 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1410 smb_fname
->st
.vfs_private
= attrs
.winAttrs
;
1415 static int vfs_gpfs_fstat(struct vfs_handle_struct
*handle
,
1416 struct files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
1418 struct gpfs_winattr attrs
;
1420 struct gpfs_config_data
*config
;
1422 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1423 struct gpfs_config_data
,
1426 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
1430 if ((fsp
->fh
== NULL
) || (fsp
->fh
->fd
== -1)) {
1433 if (!config
->winattr
) {
1437 ret
= smbd_fget_gpfs_winattrs(fsp
->fh
->fd
, &attrs
);
1439 sbuf
->st_ex_calculated_birthtime
= false;
1440 sbuf
->st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1441 sbuf
->st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1446 static int vfs_gpfs_lstat(struct vfs_handle_struct
*handle
,
1447 struct smb_filename
*smb_fname
)
1449 struct gpfs_winattr attrs
;
1453 struct gpfs_config_data
*config
;
1455 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1456 struct gpfs_config_data
,
1459 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
1463 if (!config
->winattr
) {
1467 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1468 if (!NT_STATUS_IS_OK(status
)) {
1469 errno
= map_errno_from_nt_status(status
);
1472 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1475 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1476 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1477 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1478 smb_fname
->st
.vfs_private
= attrs
.winAttrs
;
1483 static int vfs_gpfs_ntimes(struct vfs_handle_struct
*handle
,
1484 const struct smb_filename
*smb_fname
,
1485 struct smb_file_time
*ft
)
1488 struct gpfs_winattr attrs
;
1492 struct gpfs_config_data
*config
;
1494 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1495 struct gpfs_config_data
,
1498 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1500 /* don't complain if access was denied */
1501 if (errno
!= EPERM
&& errno
!= EACCES
) {
1502 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1503 "%s", strerror(errno
)));
1508 if(null_timespec(ft
->create_time
)){
1509 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1513 if (!config
->winattr
) {
1517 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1518 if (!NT_STATUS_IS_OK(status
)) {
1519 errno
= map_errno_from_nt_status(status
);
1524 attrs
.creationTime
.tv_sec
= ft
->create_time
.tv_sec
;
1525 attrs
.creationTime
.tv_nsec
= ft
->create_time
.tv_nsec
;
1527 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1528 GPFS_WINATTR_SET_CREATION_TIME
, &attrs
);
1529 if(ret
== -1 && errno
!= ENOSYS
){
1530 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret
));
1537 static int vfs_gpfs_fallocate(struct vfs_handle_struct
*handle
,
1538 struct files_struct
*fsp
, enum vfs_fallocate_mode mode
,
1539 off_t offset
, off_t len
)
1542 struct gpfs_config_data
*config
;
1544 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1545 struct gpfs_config_data
,
1548 if (!config
->prealloc
) {
1549 /* you should better not run fallocate() on GPFS at all */
1554 if (mode
== VFS_FALLOCATE_KEEP_SIZE
) {
1555 DEBUG(10, ("Unsupported VFS_FALLOCATE_KEEP_SIZE\n"));
1560 ret
= smbd_gpfs_prealloc(fsp
->fh
->fd
, offset
, len
);
1562 if (ret
== -1 && errno
!= ENOSYS
) {
1563 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno
)));
1564 } else if (ret
== -1 && errno
== ENOSYS
) {
1565 DEBUG(10, ("GPFS prealloc not supported.\n"));
1567 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1573 static int vfs_gpfs_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1577 struct gpfs_config_data
*config
;
1579 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1580 struct gpfs_config_data
,
1583 if (!config
->ftruncate
) {
1584 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1587 result
= smbd_gpfs_ftruncate(fsp
->fh
->fd
, len
);
1588 if ((result
== -1) && (errno
== ENOSYS
)) {
1589 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1594 static bool vfs_gpfs_is_offline(struct vfs_handle_struct
*handle
,
1595 const struct smb_filename
*fname
,
1596 SMB_STRUCT_STAT
*sbuf
)
1598 struct gpfs_winattr attrs
;
1601 struct gpfs_config_data
*config
;
1603 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1604 struct gpfs_config_data
,
1607 if (!config
->winattr
) {
1608 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1611 status
= get_full_smb_filename(talloc_tos(), fname
, &path
);
1612 if (!NT_STATUS_IS_OK(status
)) {
1613 errno
= map_errno_from_nt_status(status
);
1617 if (VALID_STAT(*sbuf
)) {
1618 attrs
.winAttrs
= sbuf
->vfs_private
;
1621 ret
= get_gpfs_winattrs(path
, &attrs
);
1628 if ((attrs
.winAttrs
& GPFS_WINATTR_OFFLINE
) != 0) {
1629 DEBUG(10, ("%s is offline\n", path
));
1633 DEBUG(10, ("%s is online\n", path
));
1635 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1638 static bool vfs_gpfs_aio_force(struct vfs_handle_struct
*handle
,
1639 struct files_struct
*fsp
)
1641 return vfs_gpfs_is_offline(handle
, fsp
->fsp_name
, &fsp
->fsp_name
->st
);
1644 static ssize_t
vfs_gpfs_sendfile(vfs_handle_struct
*handle
, int tofd
,
1645 files_struct
*fsp
, const DATA_BLOB
*hdr
,
1646 off_t offset
, size_t n
)
1648 if ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0) {
1652 return SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fsp
, hdr
, offset
, n
);
1655 static int vfs_gpfs_connect(struct vfs_handle_struct
*handle
,
1656 const char *service
, const char *user
)
1658 struct gpfs_config_data
*config
;
1661 smbd_gpfs_lib_init();
1663 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1669 config
= talloc_zero(handle
->conn
, struct gpfs_config_data
);
1671 SMB_VFS_NEXT_DISCONNECT(handle
);
1672 DEBUG(0, ("talloc_zero() failed\n"));
1676 config
->sharemodes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1677 "sharemodes", true);
1679 config
->leases
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1682 config
->hsm
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1685 config
->syncio
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1688 config
->winattr
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1691 config
->ftruncate
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1694 config
->getrealfilename
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1695 "getrealfilename", true);
1697 config
->dfreequota
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1698 "dfreequota", false);
1700 config
->prealloc
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1703 config
->acl
= lp_parm_bool(SNUM(handle
->conn
), "gpfs", "acl", true);
1705 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
1706 NULL
, struct gpfs_config_data
,
1709 if (config
->leases
) {
1711 * GPFS lease code is based on kernel oplock code
1712 * so make sure it is turned on
1714 if (!lp_kernel_oplocks(SNUM(handle
->conn
))) {
1715 DEBUG(5, ("Enabling kernel oplocks for "
1716 "gpfs:leases to work\n"));
1717 lp_do_parameter(SNUM(handle
->conn
), "kernel oplocks",
1722 * as the kernel does not properly support Level II oplocks
1723 * and GPFS leases code is based on kernel infrastructure, we
1724 * need to turn off Level II oplocks if gpfs:leases is enabled
1726 if (lp_level2_oplocks(SNUM(handle
->conn
))) {
1727 DEBUG(5, ("gpfs:leases are enabled, disabling "
1728 "Level II oplocks\n"));
1729 lp_do_parameter(SNUM(handle
->conn
), "level2 oplocks",
1737 static int vfs_gpfs_get_quotas(const char *path
, uid_t uid
, gid_t gid
,
1739 struct gpfs_quotaInfo
*qi_user
,
1740 struct gpfs_quotaInfo
*qi_group
,
1741 struct gpfs_quotaInfo
*qi_fset
)
1748 * We want to always use the directory to get the fileset id,
1749 * because files might have a share mode. We also do not want
1750 * to get the parent directory when there is already a
1751 * directory to avoid stepping in a different fileset. The
1752 * path passed here is currently either "." or a filename, so
1753 * this is ok. The proper solution would be having a way to
1754 * query the fileset id without opening the file.
1756 b
= parent_dirname(talloc_tos(), path
, &dir_path
, NULL
);
1762 DEBUG(10, ("path %s, directory %s\n", path
, dir_path
));
1764 err
= get_gpfs_fset_id(dir_path
, fset_id
);
1766 DEBUG(0, ("Get fset id failed path %s, dir %s, errno %d.\n",
1767 path
, dir_path
, errno
));
1771 err
= get_gpfs_quota(path
, GPFS_USRQUOTA
, uid
, qi_user
);
1776 err
= get_gpfs_quota(path
, GPFS_GRPQUOTA
, gid
, qi_group
);
1781 err
= get_gpfs_quota(path
, GPFS_FILESETQUOTA
, *fset_id
, qi_fset
);
1789 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi
, time_t cur_time
,
1790 uint64_t *dfree
, uint64_t *dsize
)
1792 uint64_t usage
, limit
;
1795 * The quota reporting is done in units of 1024 byte blocks, but
1796 * sys_fsusage uses units of 512 byte blocks, adjust the block number
1797 * accordingly. Also filter possibly negative usage counts from gpfs.
1799 usage
= qi
.blockUsage
< 0 ? 0 : (uint64_t)qi
.blockUsage
* 2;
1800 limit
= (uint64_t)qi
.blockHardLimit
* 2;
1803 * When the grace time for the exceeded soft block quota has been
1804 * exceeded, the soft block quota becomes an additional hard limit.
1806 if (qi
.blockSoftLimit
&&
1807 qi
.blockGraceTime
&& cur_time
> qi
.blockGraceTime
) {
1808 /* report disk as full */
1810 *dsize
= MIN(*dsize
, usage
);
1813 if (!qi
.blockHardLimit
)
1816 if (usage
>= limit
) {
1817 /* report disk as full */
1819 *dsize
= MIN(*dsize
, usage
);
1822 /* limit has not been reached, determine "free space" */
1823 *dfree
= MIN(*dfree
, limit
- usage
);
1824 *dsize
= MIN(*dsize
, limit
);
1828 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct
*handle
, const char *path
,
1829 bool small_query
, uint64_t *bsize
,
1830 uint64_t *dfree
, uint64_t *dsize
)
1832 struct security_unix_token
*utok
;
1833 struct gpfs_quotaInfo qi_user
, qi_group
, qi_fset
;
1834 struct gpfs_config_data
*config
;
1838 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct gpfs_config_data
,
1839 return (uint64_t)-1);
1840 if (!config
->dfreequota
) {
1841 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1842 bsize
, dfree
, dsize
);
1845 err
= sys_fsusage(path
, dfree
, dsize
);
1847 DEBUG (0, ("Could not get fs usage, errno %d\n", errno
));
1848 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1849 bsize
, dfree
, dsize
);
1852 /* sys_fsusage returns units of 512 bytes */
1855 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
1856 (unsigned long long)*dfree
, (unsigned long long)*dsize
));
1858 utok
= handle
->conn
->session_info
->unix_token
;
1859 err
= vfs_gpfs_get_quotas(path
, utok
->uid
, utok
->gid
, &fset_id
,
1860 &qi_user
, &qi_group
, &qi_fset
);
1862 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1863 bsize
, dfree
, dsize
);
1866 cur_time
= time(NULL
);
1868 /* Adjust free space and size according to quota limits. */
1869 vfs_gpfs_disk_free_quota(qi_user
, cur_time
, dfree
, dsize
);
1870 vfs_gpfs_disk_free_quota(qi_group
, cur_time
, dfree
, dsize
);
1872 /* Id 0 indicates the default quota, not an actual quota */
1874 vfs_gpfs_disk_free_quota(qi_fset
, cur_time
, dfree
, dsize
);
1877 disk_norm(small_query
, bsize
, dfree
, dsize
);
1881 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct
*handle
,
1882 enum timestamp_set_resolution
*p_ts_res
)
1884 struct gpfs_config_data
*config
;
1887 next
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
1889 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1890 struct gpfs_config_data
,
1894 next
|= FILE_SUPPORTS_REMOTE_STORAGE
;
1899 static int vfs_gpfs_open(struct vfs_handle_struct
*handle
,
1900 struct smb_filename
*smb_fname
, files_struct
*fsp
,
1901 int flags
, mode_t mode
)
1903 struct gpfs_config_data
*config
;
1905 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1906 struct gpfs_config_data
,
1909 if (config
->syncio
) {
1912 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
1915 static ssize_t
vfs_gpfs_pread(vfs_handle_struct
*handle
, files_struct
*fsp
,
1916 void *data
, size_t n
, off_t offset
)
1920 ret
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
1922 DEBUG(10, ("vfs_private = %x\n",
1923 (unsigned int)fsp
->fsp_name
->st
.vfs_private
));
1926 ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0)) {
1927 fsp
->fsp_name
->st
.vfs_private
&= ~GPFS_WINATTR_OFFLINE
;
1928 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
1929 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
1930 fsp
->fsp_name
->base_name
);
1936 struct vfs_gpfs_pread_state
{
1937 struct files_struct
*fsp
;
1942 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
);
1944 static struct tevent_req
*vfs_gpfs_pread_send(struct vfs_handle_struct
*handle
,
1945 TALLOC_CTX
*mem_ctx
,
1946 struct tevent_context
*ev
,
1947 struct files_struct
*fsp
,
1948 void *data
, size_t n
,
1951 struct tevent_req
*req
, *subreq
;
1952 struct vfs_gpfs_pread_state
*state
;
1954 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pread_state
);
1959 subreq
= SMB_VFS_NEXT_PREAD_SEND(state
, ev
, handle
, fsp
, data
,
1961 if (tevent_req_nomem(subreq
, req
)) {
1962 return tevent_req_post(req
, ev
);
1964 tevent_req_set_callback(subreq
, vfs_gpfs_pread_done
, req
);
1968 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
)
1970 struct tevent_req
*req
= tevent_req_callback_data(
1971 subreq
, struct tevent_req
);
1972 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
1973 req
, struct vfs_gpfs_pread_state
);
1975 state
->ret
= SMB_VFS_PREAD_RECV(subreq
, &state
->err
);
1976 TALLOC_FREE(subreq
);
1977 tevent_req_done(req
);
1980 static ssize_t
vfs_gpfs_pread_recv(struct tevent_req
*req
, int *err
)
1982 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
1983 req
, struct vfs_gpfs_pread_state
);
1984 struct files_struct
*fsp
= state
->fsp
;
1986 if (tevent_req_is_unix_error(req
, err
)) {
1991 DEBUG(10, ("vfs_private = %x\n",
1992 (unsigned int)fsp
->fsp_name
->st
.vfs_private
));
1994 if ((state
->ret
!= -1) &&
1995 ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0)) {
1996 fsp
->fsp_name
->st
.vfs_private
&= ~GPFS_WINATTR_OFFLINE
;
1997 DEBUG(10, ("sending notify\n"));
1998 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
1999 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2000 fsp
->fsp_name
->base_name
);
2006 static ssize_t
vfs_gpfs_pwrite(vfs_handle_struct
*handle
, files_struct
*fsp
,
2007 const void *data
, size_t n
, off_t offset
)
2011 ret
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
2013 DEBUG(10, ("vfs_private = %x\n",
2014 (unsigned int)fsp
->fsp_name
->st
.vfs_private
));
2017 ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0)) {
2018 fsp
->fsp_name
->st
.vfs_private
&= ~GPFS_WINATTR_OFFLINE
;
2019 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2020 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2021 fsp
->fsp_name
->base_name
);
2027 struct vfs_gpfs_pwrite_state
{
2028 struct files_struct
*fsp
;
2033 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
);
2035 static struct tevent_req
*vfs_gpfs_pwrite_send(
2036 struct vfs_handle_struct
*handle
,
2037 TALLOC_CTX
*mem_ctx
,
2038 struct tevent_context
*ev
,
2039 struct files_struct
*fsp
,
2040 const void *data
, size_t n
,
2043 struct tevent_req
*req
, *subreq
;
2044 struct vfs_gpfs_pwrite_state
*state
;
2046 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pwrite_state
);
2051 subreq
= SMB_VFS_NEXT_PWRITE_SEND(state
, ev
, handle
, fsp
, data
,
2053 if (tevent_req_nomem(subreq
, req
)) {
2054 return tevent_req_post(req
, ev
);
2056 tevent_req_set_callback(subreq
, vfs_gpfs_pwrite_done
, req
);
2060 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
)
2062 struct tevent_req
*req
= tevent_req_callback_data(
2063 subreq
, struct tevent_req
);
2064 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2065 req
, struct vfs_gpfs_pwrite_state
);
2067 state
->ret
= SMB_VFS_PWRITE_RECV(subreq
, &state
->err
);
2068 TALLOC_FREE(subreq
);
2069 tevent_req_done(req
);
2072 static ssize_t
vfs_gpfs_pwrite_recv(struct tevent_req
*req
, int *err
)
2074 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2075 req
, struct vfs_gpfs_pwrite_state
);
2076 struct files_struct
*fsp
= state
->fsp
;
2078 if (tevent_req_is_unix_error(req
, err
)) {
2083 DEBUG(10, ("vfs_private = %x\n",
2084 (unsigned int)fsp
->fsp_name
->st
.vfs_private
));
2086 if ((state
->ret
!= -1) &&
2087 ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0)) {
2088 fsp
->fsp_name
->st
.vfs_private
&= ~GPFS_WINATTR_OFFLINE
;
2089 DEBUG(10, ("sending notify\n"));
2090 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2091 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2092 fsp
->fsp_name
->base_name
);
2099 static struct vfs_fn_pointers vfs_gpfs_fns
= {
2100 .connect_fn
= vfs_gpfs_connect
,
2101 .disk_free_fn
= vfs_gpfs_disk_free
,
2102 .fs_capabilities_fn
= vfs_gpfs_capabilities
,
2103 .kernel_flock_fn
= vfs_gpfs_kernel_flock
,
2104 .linux_setlease_fn
= vfs_gpfs_setlease
,
2105 .get_real_filename_fn
= vfs_gpfs_get_real_filename
,
2106 .fget_nt_acl_fn
= gpfsacl_fget_nt_acl
,
2107 .get_nt_acl_fn
= gpfsacl_get_nt_acl
,
2108 .fset_nt_acl_fn
= gpfsacl_fset_nt_acl
,
2109 .sys_acl_get_file_fn
= gpfsacl_sys_acl_get_file
,
2110 .sys_acl_get_fd_fn
= gpfsacl_sys_acl_get_fd
,
2111 .sys_acl_blob_get_file_fn
= gpfsacl_sys_acl_blob_get_file
,
2112 .sys_acl_blob_get_fd_fn
= gpfsacl_sys_acl_blob_get_fd
,
2113 .sys_acl_set_file_fn
= gpfsacl_sys_acl_set_file
,
2114 .sys_acl_set_fd_fn
= gpfsacl_sys_acl_set_fd
,
2115 .sys_acl_delete_def_file_fn
= gpfsacl_sys_acl_delete_def_file
,
2116 .chmod_fn
= vfs_gpfs_chmod
,
2117 .fchmod_fn
= vfs_gpfs_fchmod
,
2118 .close_fn
= vfs_gpfs_close
,
2119 .setxattr_fn
= gpfs_set_xattr
,
2120 .getxattr_fn
= gpfs_get_xattr
,
2121 .stat_fn
= vfs_gpfs_stat
,
2122 .fstat_fn
= vfs_gpfs_fstat
,
2123 .lstat_fn
= vfs_gpfs_lstat
,
2124 .ntimes_fn
= vfs_gpfs_ntimes
,
2125 .is_offline_fn
= vfs_gpfs_is_offline
,
2126 .aio_force_fn
= vfs_gpfs_aio_force
,
2127 .sendfile_fn
= vfs_gpfs_sendfile
,
2128 .fallocate_fn
= vfs_gpfs_fallocate
,
2129 .open_fn
= vfs_gpfs_open
,
2130 .pread_fn
= vfs_gpfs_pread
,
2131 .pread_send_fn
= vfs_gpfs_pread_send
,
2132 .pread_recv_fn
= vfs_gpfs_pread_recv
,
2133 .pwrite_fn
= vfs_gpfs_pwrite
,
2134 .pwrite_send_fn
= vfs_gpfs_pwrite_send
,
2135 .pwrite_recv_fn
= vfs_gpfs_pwrite_recv
,
2136 .ftruncate_fn
= vfs_gpfs_ftruncate
2139 NTSTATUS
vfs_gpfs_init(void);
2140 NTSTATUS
vfs_gpfs_init(void)
2144 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "gpfs",