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
) {
70 * A named stream fsp will have the basefile open in the fsp
71 * fd, so lacking a distinct fd for the stream we have to skip
72 * kernel_flock and set_gpfs_sharemode for stream.
74 if (!is_ntfs_default_stream_smb_fname(fsp
->fsp_name
)) {
75 DEBUG(2,("%s: kernel_flock on stream\n", fsp_str_dbg(fsp
)));
79 START_PROFILE(syscall_kernel_flock
);
81 kernel_flock(fsp
->fh
->fd
, share_mode
, access_mask
);
83 if (!set_gpfs_sharemode(fsp
, access_mask
, fsp
->share_access
)) {
87 END_PROFILE(syscall_kernel_flock
);
92 static int vfs_gpfs_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
95 struct gpfs_config_data
*config
;
97 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
98 struct gpfs_config_data
,
101 if (config
->sharemodes
&& (fsp
->fh
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
102 set_gpfs_sharemode(fsp
, 0, 0);
105 return SMB_VFS_NEXT_CLOSE(handle
, fsp
);
108 static int vfs_gpfs_setlease(vfs_handle_struct
*handle
, files_struct
*fsp
,
111 struct gpfs_config_data
*config
;
114 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
115 struct gpfs_config_data
,
118 START_PROFILE(syscall_linux_setlease
);
120 if (linux_set_lease_sighandler(fsp
->fh
->fd
) == -1) {
125 START_PROFILE(syscall_linux_setlease
);
127 if (config
->leases
) {
129 * Ensure the lease owner is root to allow
130 * correct delivery of lease-break signals.
133 ret
= set_gpfs_lease(fsp
->fh
->fd
,leasetype
);
138 END_PROFILE(syscall_linux_setlease
);
143 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct
*handle
,
151 char real_pathname
[PATH_MAX
+1];
154 struct gpfs_config_data
*config
;
156 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
157 struct gpfs_config_data
,
160 if (!config
->getrealfilename
) {
161 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
162 mem_ctx
, found_name
);
165 mangled
= mangle_is_mangled(name
, handle
->conn
->params
);
167 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
168 mem_ctx
, found_name
);
171 full_path
= talloc_asprintf(talloc_tos(), "%s/%s", path
, name
);
172 if (full_path
== NULL
) {
177 buflen
= sizeof(real_pathname
) - 1;
179 result
= smbd_gpfs_get_realfilename_path(full_path
, real_pathname
,
182 TALLOC_FREE(full_path
);
184 if ((result
== -1) && (errno
== ENOSYS
)) {
185 return SMB_VFS_NEXT_GET_REAL_FILENAME(
186 handle
, path
, name
, mem_ctx
, found_name
);
190 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
196 * GPFS does not necessarily null-terminate the returned path
197 * but instead returns the buffer length in buflen.
200 if (buflen
< sizeof(real_pathname
)) {
201 real_pathname
[buflen
] = '\0';
203 real_pathname
[sizeof(real_pathname
)-1] = '\0';
206 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
207 path
, name
, real_pathname
));
209 name
= strrchr_m(real_pathname
, '/');
215 *found_name
= talloc_strdup(mem_ctx
, name
+1);
216 if (*found_name
== NULL
) {
224 static void gpfs_dumpacl(int level
, struct gpfs_acl
*gacl
)
229 DEBUG(0, ("gpfs acl is NULL\n"));
233 DEBUG(level
, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n",
234 gacl
->acl_nace
, gacl
->acl_type
, gacl
->acl_version
, gacl
->acl_level
, gacl
->acl_len
));
235 for(i
=0; i
<gacl
->acl_nace
; i
++)
237 struct gpfs_ace_v4
*gace
= gacl
->ace_v4
+ i
;
238 DEBUG(level
, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n",
239 i
, gace
->aceType
, gace
->aceFlags
, gace
->aceMask
,
240 gace
->aceIFlags
, gace
->aceWho
));
245 * get the ACL from GPFS, allocated on the specified mem_ctx
246 * internally retries when initial buffer was too small
248 * caller needs to cast result to either
249 * raw = yes: struct gpfs_opaque_acl
250 * raw = no: struct gpfs_acl
253 static void *vfs_gpfs_getacl(TALLOC_CTX
*mem_ctx
,
256 const gpfs_aclType_t type
)
267 aclbuf
= talloc_zero_size(mem_ctx
, size
);
268 if (aclbuf
== NULL
) {
274 struct gpfs_opaque_acl
*buf
= (struct gpfs_opaque_acl
*) aclbuf
;
275 buf
->acl_type
= type
;
276 flags
= GPFS_GETACL_NATIVE
;
277 len
= (unsigned int *) &(buf
->acl_buffer_len
);
278 struct_size
= sizeof(struct gpfs_opaque_acl
);
280 struct gpfs_acl
*buf
= (struct gpfs_acl
*) aclbuf
;
281 buf
->acl_type
= type
;
282 flags
= GPFS_GETACL_STRUCT
;
283 len
= &(buf
->acl_len
);
284 struct_size
= sizeof(struct gpfs_acl
);
287 /* set the length of the buffer as input value */
291 ret
= smbd_gpfs_getacl((char *)fname
, flags
, aclbuf
);
292 if ((ret
!= 0) && (errno
== ENOSPC
)) {
294 * get the size needed to accommodate the complete buffer
296 * the value returned only applies to the ACL blob in the
297 * struct so make sure to also have headroom for the first
298 * struct members by adding room for the complete struct
299 * (might be a few bytes too much then)
301 size
= *len
+ struct_size
;
303 DEBUG(10, ("Increasing ACL buffer size to %zu\n", size
));
308 DEBUG(5, ("smbd_gpfs_getacl failed with %s\n",
317 /* Tries to get nfs4 acls and returns SMB ACL allocated.
318 * On failure returns 1 if it got non-NFSv4 ACL to prompt
319 * retry with POSIX ACL checks.
320 * On failure returns -1 if there is system (GPFS) error, check errno.
321 * Returns 0 on success
323 static int gpfs_get_nfs4_acl(TALLOC_CTX
*mem_ctx
, const char *fname
, SMB4ACL_T
**ppacl
)
326 struct gpfs_acl
*gacl
= NULL
;
327 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname
));
330 gacl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(), fname
,
333 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
334 fname
, strerror(errno
)));
338 if (gacl
->acl_type
!= GPFS_ACL_TYPE_NFS4
) {
339 DEBUG(10, ("Got non-nfsv4 acl\n"));
340 /* Retry with POSIX ACLs check */
345 *ppacl
= smb_create_smb4acl(mem_ctx
);
347 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
348 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
351 for (i
=0; i
<gacl
->acl_nace
; i
++) {
352 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[i
];
353 SMB_ACE4PROP_T smbace
;
354 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
355 "who: %d\n", gace
->aceType
, gace
->aceIFlags
,
356 gace
->aceFlags
, gace
->aceMask
, gace
->aceWho
));
359 if (gace
->aceIFlags
& ACE4_IFLAG_SPECIAL_ID
) {
360 smbace
.flags
|= SMB_ACE4_ID_SPECIAL
;
361 switch (gace
->aceWho
) {
362 case ACE4_SPECIAL_OWNER
:
363 smbace
.who
.special_id
= SMB_ACE4_WHO_OWNER
;
365 case ACE4_SPECIAL_GROUP
:
366 smbace
.who
.special_id
= SMB_ACE4_WHO_GROUP
;
368 case ACE4_SPECIAL_EVERYONE
:
369 smbace
.who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
372 DEBUG(8, ("invalid special gpfs id %d "
373 "ignored\n", gace
->aceWho
));
374 continue; /* don't add it */
377 if (gace
->aceFlags
& ACE4_FLAG_GROUP_ID
)
378 smbace
.who
.gid
= gace
->aceWho
;
380 smbace
.who
.uid
= gace
->aceWho
;
383 /* remove redundant deny entries */
384 if (i
> 0 && gace
->aceType
== SMB_ACE4_ACCESS_DENIED_ACE_TYPE
) {
385 struct gpfs_ace_v4
*prev
= &gacl
->ace_v4
[i
-1];
386 if (prev
->aceType
== SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
&&
387 prev
->aceFlags
== gace
->aceFlags
&&
388 prev
->aceIFlags
== gace
->aceIFlags
&&
389 (gace
->aceMask
& prev
->aceMask
) == 0 &&
390 gace
->aceWho
== prev
->aceWho
) {
391 /* it's redundant - skip it */
396 smbace
.aceType
= gace
->aceType
;
397 smbace
.aceFlags
= gace
->aceFlags
;
398 smbace
.aceMask
= gace
->aceMask
;
399 smb_add_ace4(*ppacl
, &smbace
);
407 static NTSTATUS
gpfsacl_fget_nt_acl(vfs_handle_struct
*handle
,
408 files_struct
*fsp
, uint32 security_info
,
410 struct security_descriptor
**ppdesc
)
412 SMB4ACL_T
*pacl
= NULL
;
414 struct gpfs_config_data
*config
;
415 TALLOC_CTX
*frame
= talloc_stackframe();
420 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
421 struct gpfs_config_data
,
422 return NT_STATUS_INTERNAL_ERROR
);
425 status
= SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
431 result
= gpfs_get_nfs4_acl(frame
, fsp
->fsp_name
->base_name
, &pacl
);
434 status
= smb_fget_nt_acl_nfs4(fsp
, security_info
, mem_ctx
,
441 DEBUG(10, ("retrying with posix acl...\n"));
442 status
= posix_fget_nt_acl(fsp
, security_info
,
450 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
451 return map_nt_error_from_unix(errno
);
454 static NTSTATUS
gpfsacl_get_nt_acl(vfs_handle_struct
*handle
,
456 uint32 security_info
,
457 TALLOC_CTX
*mem_ctx
, struct security_descriptor
**ppdesc
)
459 SMB4ACL_T
*pacl
= NULL
;
461 struct gpfs_config_data
*config
;
462 TALLOC_CTX
*frame
= talloc_stackframe();
467 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
468 struct gpfs_config_data
,
469 return NT_STATUS_INTERNAL_ERROR
);
472 status
= SMB_VFS_NEXT_GET_NT_ACL(handle
, name
, security_info
,
478 result
= gpfs_get_nfs4_acl(frame
, name
, &pacl
);
481 status
= smb_get_nt_acl_nfs4(handle
->conn
, name
, security_info
,
482 mem_ctx
, ppdesc
, pacl
);
488 DEBUG(10, ("retrying with posix acl...\n"));
489 status
= posix_get_nt_acl(handle
->conn
, name
, security_info
,
495 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
497 return map_nt_error_from_unix(errno
);
500 static bool gpfsacl_process_smbacl(vfs_handle_struct
*handle
, files_struct
*fsp
, SMB4ACL_T
*smbacl
)
503 gpfs_aclLen_t gacl_len
;
505 struct gpfs_acl
*gacl
;
506 TALLOC_CTX
*mem_ctx
= talloc_tos();
508 gacl_len
= offsetof(gpfs_acl_t
, ace_v4
) + smb_get_naces(smbacl
) *
509 sizeof(gpfs_ace_v4_t
);
511 gacl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, gacl_len
);
513 DEBUG(0, ("talloc failed\n"));
518 gacl
->acl_len
= gacl_len
;
520 gacl
->acl_version
= GPFS_ACL_VERSION_NFS4
;
521 gacl
->acl_type
= GPFS_ACL_TYPE_NFS4
;
522 gacl
->acl_nace
= 0; /* change later... */
524 for (smbace
=smb_first_ace4(smbacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
525 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[gacl
->acl_nace
];
526 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
528 gace
->aceType
= aceprop
->aceType
;
529 gace
->aceFlags
= aceprop
->aceFlags
;
530 gace
->aceMask
= aceprop
->aceMask
;
533 * GPFS can't distinguish between WRITE and APPEND on
534 * files, so one being set without the other is an
535 * error. Sorry for the many ()'s :-)
538 if (!fsp
->is_directory
540 ((((gace
->aceMask
& ACE4_MASK_WRITE
) == 0)
541 && ((gace
->aceMask
& ACE4_MASK_APPEND
) != 0))
543 (((gace
->aceMask
& ACE4_MASK_WRITE
) != 0)
544 && ((gace
->aceMask
& ACE4_MASK_APPEND
) == 0)))
546 lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
547 "merge_writeappend", True
)) {
548 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
549 "WRITE^APPEND, setting WRITE|APPEND\n",
551 gace
->aceMask
|= ACE4_MASK_WRITE
|ACE4_MASK_APPEND
;
554 gace
->aceIFlags
= (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
) ? ACE4_IFLAG_SPECIAL_ID
: 0;
556 if (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
)
558 switch(aceprop
->who
.special_id
)
560 case SMB_ACE4_WHO_EVERYONE
:
561 gace
->aceWho
= ACE4_SPECIAL_EVERYONE
;
563 case SMB_ACE4_WHO_OWNER
:
564 gace
->aceWho
= ACE4_SPECIAL_OWNER
;
566 case SMB_ACE4_WHO_GROUP
:
567 gace
->aceWho
= ACE4_SPECIAL_GROUP
;
570 DEBUG(8, ("unsupported special_id %d\n", aceprop
->who
.special_id
));
571 continue; /* don't add it !!! */
574 /* just only for the type safety... */
575 if (aceprop
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)
576 gace
->aceWho
= aceprop
->who
.gid
;
578 gace
->aceWho
= aceprop
->who
.uid
;
584 ret
= smbd_gpfs_putacl(fsp
->fsp_name
->base_name
,
585 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gacl
);
587 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno
)));
588 gpfs_dumpacl(8, gacl
);
592 DEBUG(10, ("gpfs_putacl succeeded\n"));
596 static NTSTATUS
gpfsacl_set_nt_acl_internal(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
598 struct gpfs_acl
*acl
;
599 NTSTATUS result
= NT_STATUS_ACCESS_DENIED
;
601 acl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(),
602 fsp
->fsp_name
->base_name
,
605 return map_nt_error_from_unix(errno
);
608 if (acl
->acl_version
== GPFS_ACL_VERSION_NFS4
) {
609 if (lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
610 "refuse_dacl_protected", false)
611 && (psd
->type
&SEC_DESC_DACL_PROTECTED
)) {
612 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
614 return NT_STATUS_NOT_SUPPORTED
;
617 result
= smb_set_nt_acl_nfs4(handle
,
618 fsp
, security_info_sent
, psd
,
619 gpfsacl_process_smbacl
);
620 } else { /* assume POSIX ACL - by default... */
621 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
628 static NTSTATUS
gpfsacl_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
630 struct gpfs_config_data
*config
;
632 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
633 struct gpfs_config_data
,
634 return NT_STATUS_INTERNAL_ERROR
);
637 return SMB_VFS_NEXT_FSET_NT_ACL(handle
, fsp
, security_info_sent
, psd
);
640 return gpfsacl_set_nt_acl_internal(handle
, fsp
, security_info_sent
, psd
);
643 static SMB_ACL_T
gpfs2smb_acl(const struct gpfs_acl
*pacl
, TALLOC_CTX
*mem_ctx
)
648 result
= sys_acl_init(mem_ctx
);
649 if (result
== NULL
) {
654 result
->count
= pacl
->acl_nace
;
655 result
->acl
= talloc_realloc(result
, result
->acl
, struct smb_acl_entry
,
657 if (result
->acl
== NULL
) {
663 for (i
=0; i
<pacl
->acl_nace
; i
++) {
664 struct smb_acl_entry
*ace
= &result
->acl
[i
];
665 const struct gpfs_ace_v1
*g_ace
= &pacl
->ace_v1
[i
];
667 DEBUG(10, ("Converting type %d id %lu perm %x\n",
668 (int)g_ace
->ace_type
, (unsigned long)g_ace
->ace_who
,
669 (int)g_ace
->ace_perm
));
671 switch (g_ace
->ace_type
) {
673 ace
->a_type
= SMB_ACL_USER
;
674 ace
->info
.user
.uid
= (uid_t
)g_ace
->ace_who
;
676 case GPFS_ACL_USER_OBJ
:
677 ace
->a_type
= SMB_ACL_USER_OBJ
;
680 ace
->a_type
= SMB_ACL_GROUP
;
681 ace
->info
.group
.gid
= (gid_t
)g_ace
->ace_who
;
683 case GPFS_ACL_GROUP_OBJ
:
684 ace
->a_type
= SMB_ACL_GROUP_OBJ
;
687 ace
->a_type
= SMB_ACL_OTHER
;
690 ace
->a_type
= SMB_ACL_MASK
;
693 DEBUG(10, ("Got invalid ace_type: %d\n",
701 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_READ
) ?
703 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_WRITE
) ?
705 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_EXECUTE
) ?
708 DEBUGADD(10, ("Converted to %d perm %x\n",
709 ace
->a_type
, ace
->a_perm
));
715 static SMB_ACL_T
gpfsacl_get_posix_acl(const char *path
, gpfs_aclType_t type
,
718 struct gpfs_acl
*pacl
;
719 SMB_ACL_T result
= NULL
;
721 pacl
= vfs_gpfs_getacl(talloc_tos(), path
, false, type
);
724 DEBUG(10, ("vfs_gpfs_getacl failed for %s with %s\n",
725 path
, strerror(errno
)));
732 if (pacl
->acl_version
!= GPFS_ACL_VERSION_POSIX
) {
733 DEBUG(10, ("Got acl version %d, expected %d\n",
734 pacl
->acl_version
, GPFS_ACL_VERSION_POSIX
));
739 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
740 pacl
->acl_len
, pacl
->acl_level
, pacl
->acl_version
,
743 result
= gpfs2smb_acl(pacl
, mem_ctx
);
744 if (result
!= NULL
) {
759 static SMB_ACL_T
gpfsacl_sys_acl_get_file(vfs_handle_struct
*handle
,
764 gpfs_aclType_t gpfs_type
;
765 struct gpfs_config_data
*config
;
767 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
768 struct gpfs_config_data
,
772 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle
, path_p
,
777 case SMB_ACL_TYPE_ACCESS
:
778 gpfs_type
= GPFS_ACL_TYPE_ACCESS
;
780 case SMB_ACL_TYPE_DEFAULT
:
781 gpfs_type
= GPFS_ACL_TYPE_DEFAULT
;
784 DEBUG(0, ("Got invalid type: %d\n", type
));
785 smb_panic("exiting");
788 return gpfsacl_get_posix_acl(path_p
, gpfs_type
, mem_ctx
);
791 static SMB_ACL_T
gpfsacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
795 struct gpfs_config_data
*config
;
797 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
798 struct gpfs_config_data
,
802 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle
, fsp
, mem_ctx
);
805 return gpfsacl_get_posix_acl(fsp
->fsp_name
->base_name
,
806 GPFS_ACL_TYPE_ACCESS
, mem_ctx
);
809 static int gpfsacl_sys_acl_blob_get_file(vfs_handle_struct
*handle
,
812 char **blob_description
,
815 struct gpfs_config_data
*config
;
816 struct gpfs_opaque_acl
*acl
= NULL
;
820 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
821 struct gpfs_config_data
,
825 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle
, path_p
,
832 acl
= (struct gpfs_opaque_acl
*)
833 vfs_gpfs_getacl(mem_ctx
,
839 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
840 errno
, strerror(errno
)));
842 /* EINVAL means POSIX ACL, bail out on other cases */
843 if (errno
!= EINVAL
) {
852 * we only need the actual ACL blob here
853 * acl_version will always be NFS4 because we asked
855 * acl_type is only used for POSIX ACLs
857 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
858 aclblob
.length
= acl
->acl_buffer_len
;
860 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
861 if (!*blob_description
) {
867 result
= non_posix_sys_acl_blob_get_file_helper(handle
, path_p
,
875 /* fall back to POSIX ACL */
876 return posix_sys_acl_blob_get_file(handle
, path_p
, mem_ctx
,
877 blob_description
, blob
);
880 static int gpfsacl_sys_acl_blob_get_fd(vfs_handle_struct
*handle
,
883 char **blob_description
,
886 struct gpfs_config_data
*config
;
887 struct gpfs_opaque_acl
*acl
= NULL
;
891 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
892 struct gpfs_config_data
,
896 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle
, fsp
, mem_ctx
,
897 blob_description
, blob
);
901 acl
= (struct gpfs_opaque_acl
*) vfs_gpfs_getacl(mem_ctx
,
902 fsp
->fsp_name
->base_name
,
907 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
908 errno
, strerror(errno
)));
910 /* EINVAL means POSIX ACL, bail out on other cases */
911 if (errno
!= EINVAL
) {
920 * we only need the actual ACL blob here
921 * acl_version will always be NFS4 because we asked
923 * acl_type is only used for POSIX ACLs
925 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
926 aclblob
.length
= acl
->acl_buffer_len
;
928 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
929 if (!*blob_description
) {
935 result
= non_posix_sys_acl_blob_get_fd_helper(handle
, fsp
,
943 /* fall back to POSIX ACL */
944 return posix_sys_acl_blob_get_fd(handle
, fsp
, mem_ctx
,
945 blob_description
, blob
);
948 static struct gpfs_acl
*smb2gpfs_acl(const SMB_ACL_T pacl
,
952 struct gpfs_acl
*result
;
955 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl
->count
));
957 len
= offsetof(gpfs_acl_t
, ace_v1
) + (pacl
->count
) *
958 sizeof(gpfs_ace_v1_t
);
960 result
= (struct gpfs_acl
*)SMB_MALLOC(len
);
961 if (result
== NULL
) {
966 result
->acl_len
= len
;
967 result
->acl_level
= 0;
968 result
->acl_version
= GPFS_ACL_VERSION_POSIX
;
969 result
->acl_type
= (type
== SMB_ACL_TYPE_DEFAULT
) ?
970 GPFS_ACL_TYPE_DEFAULT
: GPFS_ACL_TYPE_ACCESS
;
971 result
->acl_nace
= pacl
->count
;
973 for (i
=0; i
<pacl
->count
; i
++) {
974 const struct smb_acl_entry
*ace
= &pacl
->acl
[i
];
975 struct gpfs_ace_v1
*g_ace
= &result
->ace_v1
[i
];
977 DEBUG(10, ("Converting type %d perm %x\n",
978 (int)ace
->a_type
, (int)ace
->a_perm
));
982 switch(ace
->a_type
) {
984 g_ace
->ace_type
= GPFS_ACL_USER
;
985 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.user
.uid
;
987 case SMB_ACL_USER_OBJ
:
988 g_ace
->ace_type
= GPFS_ACL_USER_OBJ
;
989 g_ace
->ace_perm
|= ACL_PERM_CONTROL
;
993 g_ace
->ace_type
= GPFS_ACL_GROUP
;
994 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.group
.gid
;
996 case SMB_ACL_GROUP_OBJ
:
997 g_ace
->ace_type
= GPFS_ACL_GROUP_OBJ
;
1001 g_ace
->ace_type
= GPFS_ACL_MASK
;
1002 g_ace
->ace_perm
= 0x8f;
1006 g_ace
->ace_type
= GPFS_ACL_OTHER
;
1010 DEBUG(10, ("Got invalid ace_type: %d\n", ace
->a_type
));
1016 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_READ
) ?
1018 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_WRITE
) ?
1020 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_EXECUTE
) ?
1021 ACL_PERM_EXECUTE
: 0;
1023 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
1024 g_ace
->ace_type
, g_ace
->ace_who
, g_ace
->ace_perm
));
1030 static int gpfsacl_sys_acl_set_file(vfs_handle_struct
*handle
,
1032 SMB_ACL_TYPE_T type
,
1035 struct gpfs_acl
*gpfs_acl
;
1037 struct gpfs_config_data
*config
;
1039 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1040 struct gpfs_config_data
,
1044 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle
, name
, type
, theacl
);
1047 gpfs_acl
= smb2gpfs_acl(theacl
, type
);
1048 if (gpfs_acl
== NULL
) {
1052 result
= smbd_gpfs_putacl((char *)name
, GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gpfs_acl
);
1054 SAFE_FREE(gpfs_acl
);
1058 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
1062 struct gpfs_config_data
*config
;
1064 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1065 struct gpfs_config_data
,
1069 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle
, fsp
, theacl
);
1072 return gpfsacl_sys_acl_set_file(handle
, fsp
->fsp_name
->base_name
,
1073 SMB_ACL_TYPE_ACCESS
, theacl
);
1076 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
1079 struct gpfs_config_data
*config
;
1081 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1082 struct gpfs_config_data
,
1086 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle
, path
);
1094 * Assumed: mode bits are shiftable and standard
1095 * Output: the new aceMask field for an smb nfs4 ace
1097 static uint32
gpfsacl_mask_filter(uint32 aceType
, uint32 aceMask
, uint32 rwx
)
1099 const uint32 posix_nfs4map
[3] = {
1100 SMB_ACE4_EXECUTE
, /* execute */
1101 SMB_ACE4_WRITE_DATA
| SMB_ACE4_APPEND_DATA
, /* write; GPFS specific */
1102 SMB_ACE4_READ_DATA
/* read */
1105 uint32_t posix_mask
= 0x01;
1109 for(i
=0; i
<3; i
++) {
1110 nfs4_bits
= posix_nfs4map
[i
];
1111 posix_bit
= rwx
& posix_mask
;
1113 if (aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
) {
1115 aceMask
|= nfs4_bits
;
1117 aceMask
&= ~nfs4_bits
;
1119 /* add deny bits when suitable */
1121 aceMask
|= nfs4_bits
;
1123 aceMask
&= ~nfs4_bits
;
1124 } /* other ace types are unexpected */
1132 static int gpfsacl_emu_chmod(vfs_handle_struct
*handle
,
1133 const char *path
, mode_t mode
)
1135 SMB4ACL_T
*pacl
= NULL
;
1137 bool haveAllowEntry
[SMB_ACE4_WHO_EVERYONE
+ 1] = {False
, False
, False
, False
};
1139 files_struct fake_fsp
; /* TODO: rationalize parametrization */
1141 TALLOC_CTX
*frame
= talloc_stackframe();
1144 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path
, mode
));
1146 result
= gpfs_get_nfs4_acl(frame
, path
, &pacl
);
1152 if (mode
& ~(S_IRWXU
| S_IRWXG
| S_IRWXO
)) {
1153 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode
, path
));
1156 for (smbace
=smb_first_ace4(pacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
1157 SMB_ACE4PROP_T
*ace
= smb_get_ace4(smbace
);
1158 uint32_t specid
= ace
->who
.special_id
;
1160 if (ace
->flags
&SMB_ACE4_ID_SPECIAL
&&
1161 ace
->aceType
<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE
&&
1162 specid
<= SMB_ACE4_WHO_EVERYONE
) {
1166 if (ace
->aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
)
1167 haveAllowEntry
[specid
] = True
;
1169 /* mode >> 6 for @owner, mode >> 3 for @group,
1170 * mode >> 0 for @everyone */
1171 newMask
= gpfsacl_mask_filter(ace
->aceType
, ace
->aceMask
,
1172 mode
>> ((SMB_ACE4_WHO_EVERYONE
- specid
) * 3));
1173 if (ace
->aceMask
!=newMask
) {
1174 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
1175 path
, ace
->aceMask
, newMask
, specid
));
1177 ace
->aceMask
= newMask
;
1181 /* make sure we have at least ALLOW entries
1182 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
1185 for(i
= SMB_ACE4_WHO_OWNER
; i
<=SMB_ACE4_WHO_EVERYONE
; i
++) {
1188 if (haveAllowEntry
[i
]==True
)
1192 ace
.aceType
= SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
;
1193 ace
.flags
|= SMB_ACE4_ID_SPECIAL
;
1194 ace
.who
.special_id
= i
;
1196 if (i
==SMB_ACE4_WHO_GROUP
) /* not sure it's necessary... */
1197 ace
.aceFlags
|= SMB_ACE4_IDENTIFIER_GROUP
;
1199 ace
.aceMask
= gpfsacl_mask_filter(ace
.aceType
, ace
.aceMask
,
1200 mode
>> ((SMB_ACE4_WHO_EVERYONE
- i
) * 3));
1202 /* don't add unnecessary aces */
1206 /* we add it to the END - as windows expects allow aces */
1207 smb_add_ace4(pacl
, &ace
);
1208 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1209 path
, mode
, i
, ace
.aceMask
));
1212 /* don't add complementary DENY ACEs here */
1213 ZERO_STRUCT(fake_fsp
);
1214 fake_fsp
.fsp_name
= synthetic_smb_fname(
1215 frame
, path
, NULL
, NULL
);
1216 if (fake_fsp
.fsp_name
== NULL
) {
1222 if (gpfsacl_process_smbacl(handle
, &fake_fsp
, pacl
) == False
) {
1228 return 0; /* ok for [f]chmod */
1231 static int vfs_gpfs_chmod(vfs_handle_struct
*handle
, const char *path
, mode_t mode
)
1233 struct smb_filename
*smb_fname_cpath
;
1236 smb_fname_cpath
= synthetic_smb_fname(talloc_tos(), path
, NULL
, NULL
);
1237 if (smb_fname_cpath
== NULL
) {
1242 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_cpath
) != 0) {
1246 /* avoid chmod() if possible, to preserve acls */
1247 if ((smb_fname_cpath
->st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1251 rc
= gpfsacl_emu_chmod(handle
, path
, mode
);
1253 return SMB_VFS_NEXT_CHMOD(handle
, path
, mode
);
1257 static int vfs_gpfs_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
1262 if (SMB_VFS_NEXT_FSTAT(handle
, fsp
, &st
) != 0) {
1266 /* avoid chmod() if possible, to preserve acls */
1267 if ((st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1271 rc
= gpfsacl_emu_chmod(handle
, fsp
->fsp_name
->base_name
,
1274 return SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
1278 static int gpfs_set_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1279 const char *name
, const void *value
, size_t size
, int flags
){
1280 struct xattr_DOSATTRIB dosattrib
;
1281 enum ndr_err_code ndr_err
;
1283 const char *attrstr
= value
;
1284 unsigned int dosmode
=0;
1285 struct gpfs_winattr attrs
;
1287 struct gpfs_config_data
*config
;
1289 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1290 struct gpfs_config_data
,
1293 if (!config
->winattr
) {
1294 DEBUG(10, ("gpfs_set_xattr:name is %s -> next\n",name
));
1295 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1298 DEBUG(10, ("gpfs_set_xattr: %s \n",path
));
1300 /* Only handle DOS Attributes */
1301 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1302 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name
));
1303 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1306 blob
.data
= (uint8_t *)attrstr
;
1309 ndr_err
= ndr_pull_struct_blob(&blob
, talloc_tos(), &dosattrib
,
1310 (ndr_pull_flags_fn_t
)ndr_pull_xattr_DOSATTRIB
);
1312 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1313 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
1314 "from EA on file %s: Error = %s\n",
1315 path
, ndr_errstr(ndr_err
)));
1319 if (dosattrib
.version
!= 3) {
1320 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
1321 "%d\n", (int)dosattrib
.version
));
1324 if (!(dosattrib
.info
.info3
.valid_flags
& XATTR_DOSINFO_ATTRIB
)) {
1325 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
1326 "valid, ignoring\n"));
1330 dosmode
= dosattrib
.info
.info3
.attrib
;
1333 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
1334 if (dosmode
& FILE_ATTRIBUTE_ARCHIVE
){
1335 attrs
.winAttrs
|= GPFS_WINATTR_ARCHIVE
;
1337 if (dosmode
& FILE_ATTRIBUTE_HIDDEN
){
1338 attrs
.winAttrs
|= GPFS_WINATTR_HIDDEN
;
1340 if (dosmode
& FILE_ATTRIBUTE_SYSTEM
){
1341 attrs
.winAttrs
|= GPFS_WINATTR_SYSTEM
;
1343 if (dosmode
& FILE_ATTRIBUTE_READONLY
){
1344 attrs
.winAttrs
|= GPFS_WINATTR_READONLY
;
1346 if (dosmode
& FILE_ATTRIBUTE_SPARSE
) {
1347 attrs
.winAttrs
|= GPFS_WINATTR_SPARSE_FILE
;
1351 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1352 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1354 if (errno
== ENOSYS
) {
1355 return SMB_VFS_NEXT_SETXATTR(handle
, path
, name
, value
,
1359 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret
));
1363 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs
.winAttrs
));
1367 static ssize_t
gpfs_get_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1368 const char *name
, void *value
, size_t size
){
1369 char *attrstr
= value
;
1370 unsigned int dosmode
= 0;
1371 struct gpfs_winattr attrs
;
1373 struct gpfs_config_data
*config
;
1375 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1376 struct gpfs_config_data
,
1379 if (!config
->winattr
) {
1380 DEBUG(10, ("gpfs_get_xattr:name is %s -> next\n",name
));
1381 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1384 DEBUG(10, ("gpfs_get_xattr: %s \n",path
));
1386 /* Only handle DOS Attributes */
1387 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1388 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name
));
1389 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1392 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1394 if (errno
== ENOSYS
) {
1395 return SMB_VFS_NEXT_GETXATTR(handle
, path
, name
, value
,
1399 DEBUG(1, ("gpfs_get_xattr: Get GPFS attributes failed: "
1400 "%d (%s)\n", ret
, strerror(errno
)));
1404 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs
.winAttrs
));
1406 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1407 if (attrs
.winAttrs
& GPFS_WINATTR_ARCHIVE
){
1408 dosmode
|= FILE_ATTRIBUTE_ARCHIVE
;
1410 if (attrs
.winAttrs
& GPFS_WINATTR_HIDDEN
){
1411 dosmode
|= FILE_ATTRIBUTE_HIDDEN
;
1413 if (attrs
.winAttrs
& GPFS_WINATTR_SYSTEM
){
1414 dosmode
|= FILE_ATTRIBUTE_SYSTEM
;
1416 if (attrs
.winAttrs
& GPFS_WINATTR_READONLY
){
1417 dosmode
|= FILE_ATTRIBUTE_READONLY
;
1419 if (attrs
.winAttrs
& GPFS_WINATTR_SPARSE_FILE
) {
1420 dosmode
|= FILE_ATTRIBUTE_SPARSE
;
1423 snprintf(attrstr
, size
, "0x%2.2x",
1424 (unsigned int)(dosmode
& SAMBA_ATTRIBUTES_MASK
));
1425 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr
));
1429 static int vfs_gpfs_stat(struct vfs_handle_struct
*handle
,
1430 struct smb_filename
*smb_fname
)
1432 struct gpfs_winattr attrs
;
1436 struct gpfs_config_data
*config
;
1438 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1439 struct gpfs_config_data
,
1442 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
1447 if (!config
->winattr
) {
1451 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &fname
);
1452 if (!NT_STATUS_IS_OK(status
)) {
1453 errno
= map_errno_from_nt_status(status
);
1456 ret
= get_gpfs_winattrs(discard_const_p(char, fname
), &attrs
);
1459 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1460 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1461 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1466 static int vfs_gpfs_fstat(struct vfs_handle_struct
*handle
,
1467 struct files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
1469 struct gpfs_winattr attrs
;
1471 struct gpfs_config_data
*config
;
1473 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1474 struct gpfs_config_data
,
1477 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
1481 if ((fsp
->fh
== NULL
) || (fsp
->fh
->fd
== -1)) {
1484 if (!config
->winattr
) {
1488 ret
= smbd_fget_gpfs_winattrs(fsp
->fh
->fd
, &attrs
);
1490 sbuf
->st_ex_calculated_birthtime
= false;
1491 sbuf
->st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1492 sbuf
->st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1497 static int vfs_gpfs_lstat(struct vfs_handle_struct
*handle
,
1498 struct smb_filename
*smb_fname
)
1500 struct gpfs_winattr attrs
;
1504 struct gpfs_config_data
*config
;
1506 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1507 struct gpfs_config_data
,
1510 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
1514 if (!config
->winattr
) {
1518 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1519 if (!NT_STATUS_IS_OK(status
)) {
1520 errno
= map_errno_from_nt_status(status
);
1523 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1526 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1527 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1528 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1533 static int vfs_gpfs_ntimes(struct vfs_handle_struct
*handle
,
1534 const struct smb_filename
*smb_fname
,
1535 struct smb_file_time
*ft
)
1538 struct gpfs_winattr attrs
;
1542 struct gpfs_config_data
*config
;
1544 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1545 struct gpfs_config_data
,
1548 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1550 /* don't complain if access was denied */
1551 if (errno
!= EPERM
&& errno
!= EACCES
) {
1552 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1553 "%s", strerror(errno
)));
1558 if(null_timespec(ft
->create_time
)){
1559 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1563 if (!config
->winattr
) {
1567 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1568 if (!NT_STATUS_IS_OK(status
)) {
1569 errno
= map_errno_from_nt_status(status
);
1574 attrs
.creationTime
.tv_sec
= ft
->create_time
.tv_sec
;
1575 attrs
.creationTime
.tv_nsec
= ft
->create_time
.tv_nsec
;
1577 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1578 GPFS_WINATTR_SET_CREATION_TIME
, &attrs
);
1579 if(ret
== -1 && errno
!= ENOSYS
){
1580 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret
));
1587 static int vfs_gpfs_fallocate(struct vfs_handle_struct
*handle
,
1588 struct files_struct
*fsp
, enum vfs_fallocate_mode mode
,
1589 off_t offset
, off_t len
)
1592 struct gpfs_config_data
*config
;
1594 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1595 struct gpfs_config_data
,
1598 if (!config
->prealloc
) {
1599 /* you should better not run fallocate() on GPFS at all */
1604 if (mode
== VFS_FALLOCATE_KEEP_SIZE
) {
1605 DEBUG(10, ("Unsupported VFS_FALLOCATE_KEEP_SIZE\n"));
1610 ret
= smbd_gpfs_prealloc(fsp
->fh
->fd
, offset
, len
);
1612 if (ret
== -1 && errno
!= ENOSYS
) {
1613 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno
)));
1614 } else if (ret
== -1 && errno
== ENOSYS
) {
1615 DEBUG(10, ("GPFS prealloc not supported.\n"));
1617 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1623 static int vfs_gpfs_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1627 struct gpfs_config_data
*config
;
1629 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1630 struct gpfs_config_data
,
1633 if (!config
->ftruncate
) {
1634 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1637 result
= smbd_gpfs_ftruncate(fsp
->fh
->fd
, len
);
1638 if ((result
== -1) && (errno
== ENOSYS
)) {
1639 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1644 static bool vfs_gpfs_is_offline(struct vfs_handle_struct
*handle
,
1645 const struct smb_filename
*fname
,
1646 SMB_STRUCT_STAT
*sbuf
)
1648 struct gpfs_winattr attrs
;
1651 struct gpfs_config_data
*config
;
1654 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1655 struct gpfs_config_data
,
1658 if (!config
->winattr
) {
1659 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1662 status
= get_full_smb_filename(talloc_tos(), fname
, &path
);
1663 if (!NT_STATUS_IS_OK(status
)) {
1664 errno
= map_errno_from_nt_status(status
);
1668 ret
= get_gpfs_winattrs(path
, &attrs
);
1674 if ((attrs
.winAttrs
& GPFS_WINATTR_OFFLINE
) != 0) {
1675 DEBUG(10, ("%s is offline\n", path
));
1679 DEBUG(10, ("%s is online\n", path
));
1681 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1684 static bool vfs_gpfs_aio_force(struct vfs_handle_struct
*handle
,
1685 struct files_struct
*fsp
)
1687 return vfs_gpfs_is_offline(handle
, fsp
->fsp_name
, &fsp
->fsp_name
->st
);
1690 static ssize_t
vfs_gpfs_sendfile(vfs_handle_struct
*handle
, int tofd
,
1691 files_struct
*fsp
, const DATA_BLOB
*hdr
,
1692 off_t offset
, size_t n
)
1694 if (SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
, &fsp
->fsp_name
->st
))
1699 return SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fsp
, hdr
, offset
, n
);
1702 static int vfs_gpfs_connect(struct vfs_handle_struct
*handle
,
1703 const char *service
, const char *user
)
1705 struct gpfs_config_data
*config
;
1708 smbd_gpfs_lib_init();
1710 config
= talloc_zero(handle
->conn
, struct gpfs_config_data
);
1712 DEBUG(0, ("talloc_zero() failed\n"));
1717 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1719 TALLOC_FREE(config
);
1723 config
->sharemodes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1724 "sharemodes", true);
1726 config
->leases
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1729 config
->hsm
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1732 config
->syncio
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1735 config
->winattr
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1738 config
->ftruncate
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1741 config
->getrealfilename
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1742 "getrealfilename", true);
1744 config
->dfreequota
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1745 "dfreequota", false);
1747 config
->prealloc
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1750 config
->acl
= lp_parm_bool(SNUM(handle
->conn
), "gpfs", "acl", true);
1752 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
1753 NULL
, struct gpfs_config_data
,
1756 if (config
->leases
) {
1758 * GPFS lease code is based on kernel oplock code
1759 * so make sure it is turned on
1761 if (!lp_kernel_oplocks(SNUM(handle
->conn
))) {
1762 DEBUG(5, ("Enabling kernel oplocks for "
1763 "gpfs:leases to work\n"));
1764 lp_do_parameter(SNUM(handle
->conn
), "kernel oplocks",
1769 * as the kernel does not properly support Level II oplocks
1770 * and GPFS leases code is based on kernel infrastructure, we
1771 * need to turn off Level II oplocks if gpfs:leases is enabled
1773 if (lp_level2_oplocks(SNUM(handle
->conn
))) {
1774 DEBUG(5, ("gpfs:leases are enabled, disabling "
1775 "Level II oplocks\n"));
1776 lp_do_parameter(SNUM(handle
->conn
), "level2 oplocks",
1784 static int vfs_gpfs_get_quotas(const char *path
, uid_t uid
, gid_t gid
,
1786 struct gpfs_quotaInfo
*qi_user
,
1787 struct gpfs_quotaInfo
*qi_group
,
1788 struct gpfs_quotaInfo
*qi_fset
)
1795 * We want to always use the directory to get the fileset id,
1796 * because files might have a share mode. We also do not want
1797 * to get the parent directory when there is already a
1798 * directory to avoid stepping in a different fileset. The
1799 * path passed here is currently either "." or a filename, so
1800 * this is ok. The proper solution would be having a way to
1801 * query the fileset id without opening the file.
1803 b
= parent_dirname(talloc_tos(), path
, &dir_path
, NULL
);
1809 DEBUG(10, ("path %s, directory %s\n", path
, dir_path
));
1811 err
= get_gpfs_fset_id(dir_path
, fset_id
);
1813 DEBUG(0, ("Get fset id failed path %s, dir %s, errno %d.\n",
1814 path
, dir_path
, errno
));
1818 err
= get_gpfs_quota(path
, GPFS_USRQUOTA
, uid
, qi_user
);
1823 err
= get_gpfs_quota(path
, GPFS_GRPQUOTA
, gid
, qi_group
);
1828 err
= get_gpfs_quota(path
, GPFS_FILESETQUOTA
, *fset_id
, qi_fset
);
1836 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi
, time_t cur_time
,
1837 uint64_t *dfree
, uint64_t *dsize
)
1839 uint64_t usage
, limit
;
1842 * The quota reporting is done in units of 1024 byte blocks, but
1843 * sys_fsusage uses units of 512 byte blocks, adjust the block number
1844 * accordingly. Also filter possibly negative usage counts from gpfs.
1846 usage
= qi
.blockUsage
< 0 ? 0 : (uint64_t)qi
.blockUsage
* 2;
1847 limit
= (uint64_t)qi
.blockHardLimit
* 2;
1850 * When the grace time for the exceeded soft block quota has been
1851 * exceeded, the soft block quota becomes an additional hard limit.
1853 if (qi
.blockSoftLimit
&&
1854 qi
.blockGraceTime
&& cur_time
> qi
.blockGraceTime
) {
1855 /* report disk as full */
1857 *dsize
= MIN(*dsize
, usage
);
1860 if (!qi
.blockHardLimit
)
1863 if (usage
>= limit
) {
1864 /* report disk as full */
1866 *dsize
= MIN(*dsize
, usage
);
1869 /* limit has not been reached, determine "free space" */
1870 *dfree
= MIN(*dfree
, limit
- usage
);
1871 *dsize
= MIN(*dsize
, limit
);
1875 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct
*handle
, const char *path
,
1876 bool small_query
, uint64_t *bsize
,
1877 uint64_t *dfree
, uint64_t *dsize
)
1879 struct security_unix_token
*utok
;
1880 struct gpfs_quotaInfo qi_user
, qi_group
, qi_fset
;
1881 struct gpfs_config_data
*config
;
1885 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct gpfs_config_data
,
1886 return (uint64_t)-1);
1887 if (!config
->dfreequota
) {
1888 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1889 bsize
, dfree
, dsize
);
1892 err
= sys_fsusage(path
, dfree
, dsize
);
1894 DEBUG (0, ("Could not get fs usage, errno %d\n", errno
));
1895 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1896 bsize
, dfree
, dsize
);
1899 /* sys_fsusage returns units of 512 bytes */
1902 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
1903 (unsigned long long)*dfree
, (unsigned long long)*dsize
));
1905 utok
= handle
->conn
->session_info
->unix_token
;
1906 err
= vfs_gpfs_get_quotas(path
, utok
->uid
, utok
->gid
, &fset_id
,
1907 &qi_user
, &qi_group
, &qi_fset
);
1909 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1910 bsize
, dfree
, dsize
);
1913 cur_time
= time(NULL
);
1915 /* Adjust free space and size according to quota limits. */
1916 vfs_gpfs_disk_free_quota(qi_user
, cur_time
, dfree
, dsize
);
1917 vfs_gpfs_disk_free_quota(qi_group
, cur_time
, dfree
, dsize
);
1919 /* Id 0 indicates the default quota, not an actual quota */
1921 vfs_gpfs_disk_free_quota(qi_fset
, cur_time
, dfree
, dsize
);
1924 disk_norm(small_query
, bsize
, dfree
, dsize
);
1928 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct
*handle
,
1929 enum timestamp_set_resolution
*p_ts_res
)
1931 struct gpfs_config_data
*config
;
1934 next
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
1936 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1937 struct gpfs_config_data
,
1941 next
|= FILE_SUPPORTS_REMOTE_STORAGE
;
1946 static int vfs_gpfs_open(struct vfs_handle_struct
*handle
,
1947 struct smb_filename
*smb_fname
, files_struct
*fsp
,
1948 int flags
, mode_t mode
)
1950 struct gpfs_config_data
*config
;
1952 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1953 struct gpfs_config_data
,
1956 if (config
->syncio
) {
1959 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
1962 static ssize_t
vfs_gpfs_pread(vfs_handle_struct
*handle
, files_struct
*fsp
,
1963 void *data
, size_t n
, off_t offset
)
1968 was_offline
= SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
,
1969 &fsp
->fsp_name
->st
);
1971 ret
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
1973 if ((ret
!= -1) && was_offline
) {
1974 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
1975 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
1976 fsp
->fsp_name
->base_name
);
1982 struct vfs_gpfs_pread_state
{
1983 struct files_struct
*fsp
;
1989 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
);
1991 static struct tevent_req
*vfs_gpfs_pread_send(struct vfs_handle_struct
*handle
,
1992 TALLOC_CTX
*mem_ctx
,
1993 struct tevent_context
*ev
,
1994 struct files_struct
*fsp
,
1995 void *data
, size_t n
,
1998 struct tevent_req
*req
, *subreq
;
1999 struct vfs_gpfs_pread_state
*state
;
2001 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pread_state
);
2005 state
->was_offline
= SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
,
2006 &fsp
->fsp_name
->st
);
2008 subreq
= SMB_VFS_NEXT_PREAD_SEND(state
, ev
, handle
, fsp
, data
,
2010 if (tevent_req_nomem(subreq
, req
)) {
2011 return tevent_req_post(req
, ev
);
2013 tevent_req_set_callback(subreq
, vfs_gpfs_pread_done
, req
);
2017 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
)
2019 struct tevent_req
*req
= tevent_req_callback_data(
2020 subreq
, struct tevent_req
);
2021 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2022 req
, struct vfs_gpfs_pread_state
);
2024 state
->ret
= SMB_VFS_PREAD_RECV(subreq
, &state
->err
);
2025 TALLOC_FREE(subreq
);
2026 tevent_req_done(req
);
2029 static ssize_t
vfs_gpfs_pread_recv(struct tevent_req
*req
, int *err
)
2031 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2032 req
, struct vfs_gpfs_pread_state
);
2033 struct files_struct
*fsp
= state
->fsp
;
2035 if (tevent_req_is_unix_error(req
, err
)) {
2040 if ((state
->ret
!= -1) && state
->was_offline
) {
2041 DEBUG(10, ("sending notify\n"));
2042 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2043 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2044 fsp
->fsp_name
->base_name
);
2050 static ssize_t
vfs_gpfs_pwrite(vfs_handle_struct
*handle
, files_struct
*fsp
,
2051 const void *data
, size_t n
, off_t offset
)
2056 was_offline
= SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
,
2057 &fsp
->fsp_name
->st
);
2059 ret
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
2061 if ((ret
!= -1) && was_offline
) {
2062 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2063 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2064 fsp
->fsp_name
->base_name
);
2070 struct vfs_gpfs_pwrite_state
{
2071 struct files_struct
*fsp
;
2077 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
);
2079 static struct tevent_req
*vfs_gpfs_pwrite_send(
2080 struct vfs_handle_struct
*handle
,
2081 TALLOC_CTX
*mem_ctx
,
2082 struct tevent_context
*ev
,
2083 struct files_struct
*fsp
,
2084 const void *data
, size_t n
,
2087 struct tevent_req
*req
, *subreq
;
2088 struct vfs_gpfs_pwrite_state
*state
;
2090 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pwrite_state
);
2094 state
->was_offline
= SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
,
2095 &fsp
->fsp_name
->st
);
2097 subreq
= SMB_VFS_NEXT_PWRITE_SEND(state
, ev
, handle
, fsp
, data
,
2099 if (tevent_req_nomem(subreq
, req
)) {
2100 return tevent_req_post(req
, ev
);
2102 tevent_req_set_callback(subreq
, vfs_gpfs_pwrite_done
, req
);
2106 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
)
2108 struct tevent_req
*req
= tevent_req_callback_data(
2109 subreq
, struct tevent_req
);
2110 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2111 req
, struct vfs_gpfs_pwrite_state
);
2113 state
->ret
= SMB_VFS_PWRITE_RECV(subreq
, &state
->err
);
2114 TALLOC_FREE(subreq
);
2115 tevent_req_done(req
);
2118 static ssize_t
vfs_gpfs_pwrite_recv(struct tevent_req
*req
, int *err
)
2120 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2121 req
, struct vfs_gpfs_pwrite_state
);
2122 struct files_struct
*fsp
= state
->fsp
;
2124 if (tevent_req_is_unix_error(req
, err
)) {
2129 if ((state
->ret
!= -1) && state
->was_offline
) {
2130 DEBUG(10, ("sending notify\n"));
2131 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2132 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2133 fsp
->fsp_name
->base_name
);
2140 static struct vfs_fn_pointers vfs_gpfs_fns
= {
2141 .connect_fn
= vfs_gpfs_connect
,
2142 .disk_free_fn
= vfs_gpfs_disk_free
,
2143 .fs_capabilities_fn
= vfs_gpfs_capabilities
,
2144 .kernel_flock_fn
= vfs_gpfs_kernel_flock
,
2145 .linux_setlease_fn
= vfs_gpfs_setlease
,
2146 .get_real_filename_fn
= vfs_gpfs_get_real_filename
,
2147 .fget_nt_acl_fn
= gpfsacl_fget_nt_acl
,
2148 .get_nt_acl_fn
= gpfsacl_get_nt_acl
,
2149 .fset_nt_acl_fn
= gpfsacl_fset_nt_acl
,
2150 .sys_acl_get_file_fn
= gpfsacl_sys_acl_get_file
,
2151 .sys_acl_get_fd_fn
= gpfsacl_sys_acl_get_fd
,
2152 .sys_acl_blob_get_file_fn
= gpfsacl_sys_acl_blob_get_file
,
2153 .sys_acl_blob_get_fd_fn
= gpfsacl_sys_acl_blob_get_fd
,
2154 .sys_acl_set_file_fn
= gpfsacl_sys_acl_set_file
,
2155 .sys_acl_set_fd_fn
= gpfsacl_sys_acl_set_fd
,
2156 .sys_acl_delete_def_file_fn
= gpfsacl_sys_acl_delete_def_file
,
2157 .chmod_fn
= vfs_gpfs_chmod
,
2158 .fchmod_fn
= vfs_gpfs_fchmod
,
2159 .close_fn
= vfs_gpfs_close
,
2160 .setxattr_fn
= gpfs_set_xattr
,
2161 .getxattr_fn
= gpfs_get_xattr
,
2162 .stat_fn
= vfs_gpfs_stat
,
2163 .fstat_fn
= vfs_gpfs_fstat
,
2164 .lstat_fn
= vfs_gpfs_lstat
,
2165 .ntimes_fn
= vfs_gpfs_ntimes
,
2166 .is_offline_fn
= vfs_gpfs_is_offline
,
2167 .aio_force_fn
= vfs_gpfs_aio_force
,
2168 .sendfile_fn
= vfs_gpfs_sendfile
,
2169 .fallocate_fn
= vfs_gpfs_fallocate
,
2170 .open_fn
= vfs_gpfs_open
,
2171 .pread_fn
= vfs_gpfs_pread
,
2172 .pread_send_fn
= vfs_gpfs_pread_send
,
2173 .pread_recv_fn
= vfs_gpfs_pread_recv
,
2174 .pwrite_fn
= vfs_gpfs_pwrite
,
2175 .pwrite_send_fn
= vfs_gpfs_pwrite_send
,
2176 .pwrite_recv_fn
= vfs_gpfs_pwrite_recv
,
2177 .ftruncate_fn
= vfs_gpfs_ftruncate
2180 NTSTATUS
vfs_gpfs_init(void);
2181 NTSTATUS
vfs_gpfs_init(void)
2185 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "gpfs",