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"
30 #define DBGC_CLASS DBGC_VFS
33 #include "nfs4_acls.h"
35 #include "system/filesys.h"
37 #include "lib/util/tevent_unix.h"
39 struct gpfs_config_data
{
53 static int vfs_gpfs_kernel_flock(vfs_handle_struct
*handle
, files_struct
*fsp
,
54 uint32 share_mode
, uint32 access_mask
)
57 struct gpfs_config_data
*config
;
60 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
61 struct gpfs_config_data
,
64 if(!config
->sharemodes
) {
68 START_PROFILE(syscall_kernel_flock
);
70 kernel_flock(fsp
->fh
->fd
, share_mode
, access_mask
);
72 if (!set_gpfs_sharemode(fsp
, access_mask
, fsp
->share_access
)) {
76 END_PROFILE(syscall_kernel_flock
);
81 static int vfs_gpfs_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
84 struct gpfs_config_data
*config
;
86 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
87 struct gpfs_config_data
,
90 if (config
->sharemodes
&& (fsp
->fh
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
91 set_gpfs_sharemode(fsp
, 0, 0);
94 return SMB_VFS_NEXT_CLOSE(handle
, fsp
);
97 static int vfs_gpfs_setlease(vfs_handle_struct
*handle
, files_struct
*fsp
,
100 struct gpfs_config_data
*config
;
103 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
104 struct gpfs_config_data
,
107 if (linux_set_lease_sighandler(fsp
->fh
->fd
) == -1)
110 START_PROFILE(syscall_linux_setlease
);
112 if (config
->leases
) {
113 ret
= set_gpfs_lease(fsp
->fh
->fd
,leasetype
);
116 END_PROFILE(syscall_linux_setlease
);
121 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct
*handle
,
129 char real_pathname
[PATH_MAX
+1];
132 struct gpfs_config_data
*config
;
134 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
135 struct gpfs_config_data
,
138 if (!config
->getrealfilename
) {
139 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
140 mem_ctx
, found_name
);
143 mangled
= mangle_is_mangled(name
, handle
->conn
->params
);
145 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
146 mem_ctx
, found_name
);
149 full_path
= talloc_asprintf(talloc_tos(), "%s/%s", path
, name
);
150 if (full_path
== NULL
) {
155 buflen
= sizeof(real_pathname
) - 1;
157 result
= smbd_gpfs_get_realfilename_path(full_path
, real_pathname
,
160 TALLOC_FREE(full_path
);
162 if ((result
== -1) && (errno
== ENOSYS
)) {
163 return SMB_VFS_NEXT_GET_REAL_FILENAME(
164 handle
, path
, name
, mem_ctx
, found_name
);
168 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
174 * GPFS does not necessarily null-terminate the returned path
175 * but instead returns the buffer length in buflen.
178 if (buflen
< sizeof(real_pathname
)) {
179 real_pathname
[buflen
] = '\0';
181 real_pathname
[sizeof(real_pathname
)-1] = '\0';
184 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
185 path
, name
, real_pathname
));
187 name
= strrchr_m(real_pathname
, '/');
193 *found_name
= talloc_strdup(mem_ctx
, name
+1);
194 if (*found_name
== NULL
) {
202 static void gpfs_dumpacl(int level
, struct gpfs_acl
*gacl
)
207 DEBUG(0, ("gpfs acl is NULL\n"));
211 DEBUG(level
, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n",
212 gacl
->acl_nace
, gacl
->acl_type
, gacl
->acl_version
, gacl
->acl_level
, gacl
->acl_len
));
213 for(i
=0; i
<gacl
->acl_nace
; i
++)
215 struct gpfs_ace_v4
*gace
= gacl
->ace_v4
+ i
;
216 DEBUG(level
, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n",
217 i
, gace
->aceType
, gace
->aceFlags
, gace
->aceMask
,
218 gace
->aceIFlags
, gace
->aceWho
));
222 static struct gpfs_acl
*gpfs_getacl_alloc(const char *fname
, gpfs_aclType_t type
)
224 struct gpfs_acl
*acl
;
227 TALLOC_CTX
*mem_ctx
= talloc_tos();
229 acl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, len
);
237 acl
->acl_version
= 0;
238 acl
->acl_type
= type
;
240 ret
= smbd_gpfs_getacl((char *)fname
, GPFS_GETACL_STRUCT
, acl
);
241 if ((ret
!= 0) && (errno
== ENOSPC
)) {
242 struct gpfs_acl
*new_acl
= (struct gpfs_acl
*)TALLOC_SIZE(
243 mem_ctx
, acl
->acl_len
+ sizeof(struct gpfs_acl
));
244 if (new_acl
== NULL
) {
249 new_acl
->acl_len
= acl
->acl_len
;
250 new_acl
->acl_level
= acl
->acl_level
;
251 new_acl
->acl_version
= acl
->acl_version
;
252 new_acl
->acl_type
= acl
->acl_type
;
255 ret
= smbd_gpfs_getacl((char *)fname
, GPFS_GETACL_STRUCT
, acl
);
259 DEBUG(8, ("smbd_gpfs_getacl failed with %s\n",strerror(errno
)));
266 /* Tries to get nfs4 acls and returns SMB ACL allocated.
267 * On failure returns 1 if it got non-NFSv4 ACL to prompt
268 * retry with POSIX ACL checks.
269 * On failure returns -1 if there is system (GPFS) error, check errno.
270 * Returns 0 on success
272 static int gpfs_get_nfs4_acl(const char *fname
, SMB4ACL_T
**ppacl
)
275 struct gpfs_acl
*gacl
= NULL
;
276 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname
));
278 /* First get the real acl length */
279 gacl
= gpfs_getacl_alloc(fname
, 0);
281 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
282 fname
, strerror(errno
)));
286 if (gacl
->acl_type
!= GPFS_ACL_TYPE_NFS4
) {
287 DEBUG(10, ("Got non-nfsv4 acl\n"));
288 /* Retry with POSIX ACLs check */
292 *ppacl
= smb_create_smb4acl();
294 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
295 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
298 for (i
=0; i
<gacl
->acl_nace
; i
++) {
299 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[i
];
300 SMB_ACE4PROP_T smbace
;
301 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
302 "who: %d\n", gace
->aceType
, gace
->aceIFlags
,
303 gace
->aceFlags
, gace
->aceMask
, gace
->aceWho
));
306 if (gace
->aceIFlags
& ACE4_IFLAG_SPECIAL_ID
) {
307 smbace
.flags
|= SMB_ACE4_ID_SPECIAL
;
308 switch (gace
->aceWho
) {
309 case ACE4_SPECIAL_OWNER
:
310 smbace
.who
.special_id
= SMB_ACE4_WHO_OWNER
;
312 case ACE4_SPECIAL_GROUP
:
313 smbace
.who
.special_id
= SMB_ACE4_WHO_GROUP
;
315 case ACE4_SPECIAL_EVERYONE
:
316 smbace
.who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
319 DEBUG(8, ("invalid special gpfs id %d "
320 "ignored\n", gace
->aceWho
));
321 continue; /* don't add it */
324 if (gace
->aceFlags
& ACE4_FLAG_GROUP_ID
)
325 smbace
.who
.gid
= gace
->aceWho
;
327 smbace
.who
.uid
= gace
->aceWho
;
330 /* remove redundent deny entries */
331 if (i
> 0 && gace
->aceType
== SMB_ACE4_ACCESS_DENIED_ACE_TYPE
) {
332 struct gpfs_ace_v4
*prev
= &gacl
->ace_v4
[i
-1];
333 if (prev
->aceType
== SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
&&
334 prev
->aceFlags
== gace
->aceFlags
&&
335 prev
->aceIFlags
== gace
->aceIFlags
&&
336 (gace
->aceMask
& prev
->aceMask
) == 0 &&
337 gace
->aceWho
== prev
->aceWho
) {
338 /* its redundent - skip it */
343 smbace
.aceType
= gace
->aceType
;
344 smbace
.aceFlags
= gace
->aceFlags
;
345 smbace
.aceMask
= gace
->aceMask
;
346 smb_add_ace4(*ppacl
, &smbace
);
352 static NTSTATUS
gpfsacl_fget_nt_acl(vfs_handle_struct
*handle
,
353 files_struct
*fsp
, uint32 security_info
,
355 struct security_descriptor
**ppdesc
)
357 SMB4ACL_T
*pacl
= NULL
;
359 struct gpfs_config_data
*config
;
363 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
364 struct gpfs_config_data
,
365 return NT_STATUS_INTERNAL_ERROR
);
368 return SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
372 result
= gpfs_get_nfs4_acl(fsp
->fsp_name
->base_name
, &pacl
);
375 return smb_fget_nt_acl_nfs4(fsp
, security_info
, mem_ctx
, ppdesc
, pacl
);
378 DEBUG(10, ("retrying with posix acl...\n"));
379 return posix_fget_nt_acl(fsp
, security_info
, mem_ctx
, ppdesc
);
382 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
383 return map_nt_error_from_unix(errno
);
386 static NTSTATUS
gpfsacl_get_nt_acl(vfs_handle_struct
*handle
,
388 uint32 security_info
,
389 TALLOC_CTX
*mem_ctx
, 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_GET_NT_ACL(handle
, name
, security_info
,
406 result
= gpfs_get_nfs4_acl(name
, &pacl
);
409 return smb_get_nt_acl_nfs4(handle
->conn
, name
, security_info
,
410 mem_ctx
, ppdesc
, pacl
);
413 DEBUG(10, ("retrying with posix acl...\n"));
414 return posix_get_nt_acl(handle
->conn
, name
, security_info
,
418 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
419 return map_nt_error_from_unix(errno
);
422 static bool gpfsacl_process_smbacl(files_struct
*fsp
, SMB4ACL_T
*smbacl
)
425 gpfs_aclLen_t gacl_len
;
427 struct gpfs_acl
*gacl
;
428 TALLOC_CTX
*mem_ctx
= talloc_tos();
430 gacl_len
= offsetof(gpfs_acl_t
, ace_v4
) + smb_get_naces(smbacl
) *
431 sizeof(gpfs_ace_v4_t
);
433 gacl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, gacl_len
);
435 DEBUG(0, ("talloc failed\n"));
440 gacl
->acl_len
= gacl_len
;
442 gacl
->acl_version
= GPFS_ACL_VERSION_NFS4
;
443 gacl
->acl_type
= GPFS_ACL_TYPE_NFS4
;
444 gacl
->acl_nace
= 0; /* change later... */
446 for (smbace
=smb_first_ace4(smbacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
447 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[gacl
->acl_nace
];
448 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
450 gace
->aceType
= aceprop
->aceType
;
451 gace
->aceFlags
= aceprop
->aceFlags
;
452 gace
->aceMask
= aceprop
->aceMask
;
455 * GPFS can't distinguish between WRITE and APPEND on
456 * files, so one being set without the other is an
457 * error. Sorry for the many ()'s :-)
460 if (!fsp
->is_directory
462 ((((gace
->aceMask
& ACE4_MASK_WRITE
) == 0)
463 && ((gace
->aceMask
& ACE4_MASK_APPEND
) != 0))
465 (((gace
->aceMask
& ACE4_MASK_WRITE
) != 0)
466 && ((gace
->aceMask
& ACE4_MASK_APPEND
) == 0)))
468 lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
469 "merge_writeappend", True
)) {
470 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
471 "WRITE^APPEND, setting WRITE|APPEND\n",
473 gace
->aceMask
|= ACE4_MASK_WRITE
|ACE4_MASK_APPEND
;
476 gace
->aceIFlags
= (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
) ? ACE4_IFLAG_SPECIAL_ID
: 0;
478 if (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
)
480 switch(aceprop
->who
.special_id
)
482 case SMB_ACE4_WHO_EVERYONE
:
483 gace
->aceWho
= ACE4_SPECIAL_EVERYONE
;
485 case SMB_ACE4_WHO_OWNER
:
486 gace
->aceWho
= ACE4_SPECIAL_OWNER
;
488 case SMB_ACE4_WHO_GROUP
:
489 gace
->aceWho
= ACE4_SPECIAL_GROUP
;
492 DEBUG(8, ("unsupported special_id %d\n", aceprop
->who
.special_id
));
493 continue; /* don't add it !!! */
496 /* just only for the type safety... */
497 if (aceprop
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)
498 gace
->aceWho
= aceprop
->who
.gid
;
500 gace
->aceWho
= aceprop
->who
.uid
;
506 ret
= smbd_gpfs_putacl(fsp
->fsp_name
->base_name
,
507 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gacl
);
509 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno
)));
510 gpfs_dumpacl(8, gacl
);
514 DEBUG(10, ("gpfs_putacl succeeded\n"));
518 static NTSTATUS
gpfsacl_set_nt_acl_internal(files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
520 struct gpfs_acl
*acl
;
521 NTSTATUS result
= NT_STATUS_ACCESS_DENIED
;
523 acl
= gpfs_getacl_alloc(fsp
->fsp_name
->base_name
, 0);
527 if (acl
->acl_version
&GPFS_ACL_VERSION_NFS4
)
529 if (lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
530 "refuse_dacl_protected", false)
531 && (psd
->type
&SEC_DESC_DACL_PROTECTED
)) {
532 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
533 return NT_STATUS_NOT_SUPPORTED
;
536 result
= smb_set_nt_acl_nfs4(
537 fsp
, security_info_sent
, psd
,
538 gpfsacl_process_smbacl
);
539 } else { /* assume POSIX ACL - by default... */
540 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
546 static NTSTATUS
gpfsacl_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
548 struct gpfs_config_data
*config
;
550 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
551 struct gpfs_config_data
,
552 return NT_STATUS_INTERNAL_ERROR
);
555 return SMB_VFS_NEXT_FSET_NT_ACL(handle
, fsp
, security_info_sent
, psd
);
558 return gpfsacl_set_nt_acl_internal(fsp
, security_info_sent
, psd
);
561 static SMB_ACL_T
gpfs2smb_acl(const struct gpfs_acl
*pacl
, TALLOC_CTX
*mem_ctx
)
566 result
= sys_acl_init(mem_ctx
);
567 if (result
== NULL
) {
572 result
->count
= pacl
->acl_nace
;
574 for (i
=0; i
<pacl
->acl_nace
; i
++) {
575 struct smb_acl_entry
*ace
= &result
->acl
[i
];
576 const struct gpfs_ace_v1
*g_ace
= &pacl
->ace_v1
[i
];
578 DEBUG(10, ("Converting type %d id %lu perm %x\n",
579 (int)g_ace
->ace_type
, (unsigned long)g_ace
->ace_who
,
580 (int)g_ace
->ace_perm
));
582 switch (g_ace
->ace_type
) {
584 ace
->a_type
= SMB_ACL_USER
;
585 ace
->info
.user
.uid
= (uid_t
)g_ace
->ace_who
;
587 case GPFS_ACL_USER_OBJ
:
588 ace
->a_type
= SMB_ACL_USER_OBJ
;
591 ace
->a_type
= SMB_ACL_GROUP
;
592 ace
->info
.group
.gid
= (gid_t
)g_ace
->ace_who
;
594 case GPFS_ACL_GROUP_OBJ
:
595 ace
->a_type
= SMB_ACL_GROUP_OBJ
;
598 ace
->a_type
= SMB_ACL_OTHER
;
601 ace
->a_type
= SMB_ACL_MASK
;
604 DEBUG(10, ("Got invalid ace_type: %d\n",
612 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_READ
) ?
614 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_WRITE
) ?
616 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_EXECUTE
) ?
619 DEBUGADD(10, ("Converted to %d perm %x\n",
620 ace
->a_type
, ace
->a_perm
));
626 static SMB_ACL_T
gpfsacl_get_posix_acl(const char *path
, gpfs_aclType_t type
,
629 struct gpfs_acl
*pacl
;
630 SMB_ACL_T result
= NULL
;
632 pacl
= gpfs_getacl_alloc(path
, type
);
635 DEBUG(10, ("gpfs_getacl failed for %s with %s\n",
636 path
, strerror(errno
)));
643 if (pacl
->acl_version
!= GPFS_ACL_VERSION_POSIX
) {
644 DEBUG(10, ("Got acl version %d, expected %d\n",
645 pacl
->acl_version
, GPFS_ACL_VERSION_POSIX
));
650 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
651 pacl
->acl_len
, pacl
->acl_level
, pacl
->acl_version
,
654 result
= gpfs2smb_acl(pacl
, mem_ctx
);
655 if (result
!= NULL
) {
667 static SMB_ACL_T
gpfsacl_sys_acl_get_file(vfs_handle_struct
*handle
,
672 gpfs_aclType_t gpfs_type
;
673 struct gpfs_config_data
*config
;
675 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
676 struct gpfs_config_data
,
680 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle
, path_p
,
685 case SMB_ACL_TYPE_ACCESS
:
686 gpfs_type
= GPFS_ACL_TYPE_ACCESS
;
688 case SMB_ACL_TYPE_DEFAULT
:
689 gpfs_type
= GPFS_ACL_TYPE_DEFAULT
;
692 DEBUG(0, ("Got invalid type: %d\n", type
));
693 smb_panic("exiting");
696 return gpfsacl_get_posix_acl(path_p
, gpfs_type
, mem_ctx
);
699 static SMB_ACL_T
gpfsacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
703 struct gpfs_config_data
*config
;
705 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
706 struct gpfs_config_data
,
710 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle
, fsp
, mem_ctx
);
713 return gpfsacl_get_posix_acl(fsp
->fsp_name
->base_name
,
714 GPFS_ACL_TYPE_ACCESS
, mem_ctx
);
717 static int gpfsacl_sys_acl_blob_get_file(vfs_handle_struct
*handle
,
720 char **blob_description
,
723 struct gpfs_config_data
*config
;
724 SMB4ACL_T
*pacl
= NULL
;
727 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
728 struct gpfs_config_data
,
732 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle
, path_p
,
738 result
= gpfs_get_nfs4_acl(path_p
, &pacl
);
740 /* We don't have a way to linearlise the NFS4 ACL
741 * right now, and it is much closer to the NT ACL
747 return posix_sys_acl_blob_get_file(handle
, path_p
, mem_ctx
,
748 blob_description
, blob
);
751 static int gpfsacl_sys_acl_blob_get_fd(vfs_handle_struct
*handle
,
754 char **blob_description
,
757 struct gpfs_config_data
*config
;
758 SMB4ACL_T
*pacl
= NULL
;
761 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
762 struct gpfs_config_data
,
766 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle
, fsp
, mem_ctx
,
767 blob_description
, blob
);
770 result
= gpfs_get_nfs4_acl(fsp
->fsp_name
->base_name
, &pacl
);
772 /* We don't have a way to linearlise the NFS4 ACL
773 * right now, and it is much closer to the NT ACL
779 return posix_sys_acl_blob_get_fd(handle
, fsp
, mem_ctx
,
780 blob_description
, blob
);
783 static struct gpfs_acl
*smb2gpfs_acl(const SMB_ACL_T pacl
,
787 struct gpfs_acl
*result
;
790 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl
->count
));
792 len
= offsetof(gpfs_acl_t
, ace_v1
) + (pacl
->count
) *
793 sizeof(gpfs_ace_v1_t
);
795 result
= (struct gpfs_acl
*)SMB_MALLOC(len
);
796 if (result
== NULL
) {
801 result
->acl_len
= len
;
802 result
->acl_level
= 0;
803 result
->acl_version
= GPFS_ACL_VERSION_POSIX
;
804 result
->acl_type
= (type
== SMB_ACL_TYPE_DEFAULT
) ?
805 GPFS_ACL_TYPE_DEFAULT
: GPFS_ACL_TYPE_ACCESS
;
806 result
->acl_nace
= pacl
->count
;
808 for (i
=0; i
<pacl
->count
; i
++) {
809 const struct smb_acl_entry
*ace
= &pacl
->acl
[i
];
810 struct gpfs_ace_v1
*g_ace
= &result
->ace_v1
[i
];
812 DEBUG(10, ("Converting type %d perm %x\n",
813 (int)ace
->a_type
, (int)ace
->a_perm
));
817 switch(ace
->a_type
) {
819 g_ace
->ace_type
= GPFS_ACL_USER
;
820 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.user
.uid
;
822 case SMB_ACL_USER_OBJ
:
823 g_ace
->ace_type
= GPFS_ACL_USER_OBJ
;
824 g_ace
->ace_perm
|= ACL_PERM_CONTROL
;
828 g_ace
->ace_type
= GPFS_ACL_GROUP
;
829 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.group
.gid
;
831 case SMB_ACL_GROUP_OBJ
:
832 g_ace
->ace_type
= GPFS_ACL_GROUP_OBJ
;
836 g_ace
->ace_type
= GPFS_ACL_MASK
;
837 g_ace
->ace_perm
= 0x8f;
841 g_ace
->ace_type
= GPFS_ACL_OTHER
;
845 DEBUG(10, ("Got invalid ace_type: %d\n", ace
->a_type
));
851 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_READ
) ?
853 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_WRITE
) ?
855 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_EXECUTE
) ?
856 ACL_PERM_EXECUTE
: 0;
858 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
859 g_ace
->ace_type
, g_ace
->ace_who
, g_ace
->ace_perm
));
865 static int gpfsacl_sys_acl_set_file(vfs_handle_struct
*handle
,
870 struct gpfs_acl
*gpfs_acl
;
872 struct gpfs_config_data
*config
;
874 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
875 struct gpfs_config_data
,
879 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle
, name
, type
, theacl
);
882 gpfs_acl
= smb2gpfs_acl(theacl
, type
);
883 if (gpfs_acl
== NULL
) {
887 result
= smbd_gpfs_putacl((char *)name
, GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gpfs_acl
);
893 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
897 struct gpfs_config_data
*config
;
899 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
900 struct gpfs_config_data
,
904 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle
, fsp
, theacl
);
907 return gpfsacl_sys_acl_set_file(handle
, fsp
->fsp_name
->base_name
,
908 SMB_ACL_TYPE_ACCESS
, theacl
);
911 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
914 struct gpfs_config_data
*config
;
916 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
917 struct gpfs_config_data
,
921 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle
, path
);
929 * Assumed: mode bits are shiftable and standard
930 * Output: the new aceMask field for an smb nfs4 ace
932 static uint32
gpfsacl_mask_filter(uint32 aceType
, uint32 aceMask
, uint32 rwx
)
934 const uint32 posix_nfs4map
[3] = {
935 SMB_ACE4_EXECUTE
, /* execute */
936 SMB_ACE4_WRITE_DATA
| SMB_ACE4_APPEND_DATA
, /* write; GPFS specific */
937 SMB_ACE4_READ_DATA
/* read */
940 uint32_t posix_mask
= 0x01;
945 nfs4_bits
= posix_nfs4map
[i
];
946 posix_bit
= rwx
& posix_mask
;
948 if (aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
) {
950 aceMask
|= nfs4_bits
;
952 aceMask
&= ~nfs4_bits
;
954 /* add deny bits when suitable */
956 aceMask
|= nfs4_bits
;
958 aceMask
&= ~nfs4_bits
;
959 } /* other ace types are unexpected */
967 static int gpfsacl_emu_chmod(const char *path
, mode_t mode
)
969 SMB4ACL_T
*pacl
= NULL
;
971 bool haveAllowEntry
[SMB_ACE4_WHO_EVERYONE
+ 1] = {False
, False
, False
, False
};
973 files_struct fake_fsp
; /* TODO: rationalize parametrization */
977 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path
, mode
));
979 result
= gpfs_get_nfs4_acl(path
, &pacl
);
983 if (mode
& ~(S_IRWXU
| S_IRWXG
| S_IRWXO
)) {
984 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode
, path
));
987 for (smbace
=smb_first_ace4(pacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
988 SMB_ACE4PROP_T
*ace
= smb_get_ace4(smbace
);
989 uint32_t specid
= ace
->who
.special_id
;
991 if (ace
->flags
&SMB_ACE4_ID_SPECIAL
&&
992 ace
->aceType
<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE
&&
993 specid
<= SMB_ACE4_WHO_EVERYONE
) {
997 if (ace
->aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
)
998 haveAllowEntry
[specid
] = True
;
1000 /* mode >> 6 for @owner, mode >> 3 for @group,
1001 * mode >> 0 for @everyone */
1002 newMask
= gpfsacl_mask_filter(ace
->aceType
, ace
->aceMask
,
1003 mode
>> ((SMB_ACE4_WHO_EVERYONE
- specid
) * 3));
1004 if (ace
->aceMask
!=newMask
) {
1005 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
1006 path
, ace
->aceMask
, newMask
, specid
));
1008 ace
->aceMask
= newMask
;
1012 /* make sure we have at least ALLOW entries
1013 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
1016 for(i
= SMB_ACE4_WHO_OWNER
; i
<=SMB_ACE4_WHO_EVERYONE
; i
++) {
1019 if (haveAllowEntry
[i
]==True
)
1023 ace
.aceType
= SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
;
1024 ace
.flags
|= SMB_ACE4_ID_SPECIAL
;
1025 ace
.who
.special_id
= i
;
1027 if (i
==SMB_ACE4_WHO_GROUP
) /* not sure it's necessary... */
1028 ace
.aceFlags
|= SMB_ACE4_IDENTIFIER_GROUP
;
1030 ace
.aceMask
= gpfsacl_mask_filter(ace
.aceType
, ace
.aceMask
,
1031 mode
>> ((SMB_ACE4_WHO_EVERYONE
- i
) * 3));
1033 /* don't add unnecessary aces */
1037 /* we add it to the END - as windows expects allow aces */
1038 smb_add_ace4(pacl
, &ace
);
1039 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1040 path
, mode
, i
, ace
.aceMask
));
1043 /* don't add complementary DENY ACEs here */
1044 ZERO_STRUCT(fake_fsp
);
1045 status
= create_synthetic_smb_fname(talloc_tos(), path
, NULL
, NULL
,
1046 &fake_fsp
.fsp_name
);
1047 if (!NT_STATUS_IS_OK(status
)) {
1048 errno
= map_errno_from_nt_status(status
);
1052 if (gpfsacl_process_smbacl(&fake_fsp
, pacl
) == False
) {
1053 TALLOC_FREE(fake_fsp
.fsp_name
);
1057 TALLOC_FREE(fake_fsp
.fsp_name
);
1058 return 0; /* ok for [f]chmod */
1061 static int vfs_gpfs_chmod(vfs_handle_struct
*handle
, const char *path
, mode_t mode
)
1063 struct smb_filename
*smb_fname_cpath
;
1067 status
= create_synthetic_smb_fname(
1068 talloc_tos(), path
, NULL
, NULL
, &smb_fname_cpath
);
1070 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_cpath
) != 0) {
1074 /* avoid chmod() if possible, to preserve acls */
1075 if ((smb_fname_cpath
->st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1079 rc
= gpfsacl_emu_chmod(path
, mode
);
1081 return SMB_VFS_NEXT_CHMOD(handle
, path
, mode
);
1085 static int vfs_gpfs_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
1090 if (SMB_VFS_NEXT_FSTAT(handle
, fsp
, &st
) != 0) {
1094 /* avoid chmod() if possible, to preserve acls */
1095 if ((st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1099 rc
= gpfsacl_emu_chmod(fsp
->fsp_name
->base_name
, mode
);
1101 return SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
1105 static int gpfs_set_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1106 const char *name
, const void *value
, size_t size
, int flags
){
1107 struct xattr_DOSATTRIB dosattrib
;
1108 enum ndr_err_code ndr_err
;
1110 const char *attrstr
= value
;
1111 unsigned int dosmode
=0;
1112 struct gpfs_winattr attrs
;
1114 struct gpfs_config_data
*config
;
1116 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1117 struct gpfs_config_data
,
1120 if (!config
->winattr
) {
1121 DEBUG(10, ("gpfs_set_xattr:name is %s -> next\n",name
));
1122 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1125 DEBUG(10, ("gpfs_set_xattr: %s \n",path
));
1127 /* Only handle DOS Attributes */
1128 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1129 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name
));
1130 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1133 blob
.data
= (uint8_t *)attrstr
;
1136 ndr_err
= ndr_pull_struct_blob(&blob
, talloc_tos(), &dosattrib
,
1137 (ndr_pull_flags_fn_t
)ndr_pull_xattr_DOSATTRIB
);
1139 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1140 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
1141 "from EA on file %s: Error = %s\n",
1142 path
, ndr_errstr(ndr_err
)));
1146 if (dosattrib
.version
!= 3) {
1147 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
1148 "%d\n", (int)dosattrib
.version
));
1151 if (!(dosattrib
.info
.info3
.valid_flags
& XATTR_DOSINFO_ATTRIB
)) {
1152 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
1153 "valid, ignoring\n"));
1157 dosmode
= dosattrib
.info
.info3
.attrib
;
1160 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
1161 if (dosmode
& FILE_ATTRIBUTE_ARCHIVE
){
1162 attrs
.winAttrs
|= GPFS_WINATTR_ARCHIVE
;
1164 if (dosmode
& FILE_ATTRIBUTE_HIDDEN
){
1165 attrs
.winAttrs
|= GPFS_WINATTR_HIDDEN
;
1167 if (dosmode
& FILE_ATTRIBUTE_SYSTEM
){
1168 attrs
.winAttrs
|= GPFS_WINATTR_SYSTEM
;
1170 if (dosmode
& FILE_ATTRIBUTE_READONLY
){
1171 attrs
.winAttrs
|= GPFS_WINATTR_READONLY
;
1173 if (dosmode
& FILE_ATTRIBUTE_SPARSE
) {
1174 attrs
.winAttrs
|= GPFS_WINATTR_SPARSE_FILE
;
1178 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1179 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1181 if (errno
== ENOSYS
) {
1182 return SMB_VFS_NEXT_SETXATTR(handle
, path
, name
, value
,
1186 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret
));
1190 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs
.winAttrs
));
1194 static ssize_t
gpfs_get_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1195 const char *name
, void *value
, size_t size
){
1196 char *attrstr
= value
;
1197 unsigned int dosmode
= 0;
1198 struct gpfs_winattr attrs
;
1200 struct gpfs_config_data
*config
;
1202 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1203 struct gpfs_config_data
,
1206 if (!config
->winattr
) {
1207 DEBUG(10, ("gpfs_get_xattr:name is %s -> next\n",name
));
1208 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1211 DEBUG(10, ("gpfs_get_xattr: %s \n",path
));
1213 /* Only handle DOS Attributes */
1214 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1215 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name
));
1216 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1219 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1221 if (errno
== ENOSYS
) {
1222 return SMB_VFS_NEXT_GETXATTR(handle
, path
, name
, value
,
1226 DEBUG(1, ("gpfs_get_xattr: Get GPFS attributes failed: "
1227 "%d (%s)\n", ret
, strerror(errno
)));
1231 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs
.winAttrs
));
1233 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1234 if (attrs
.winAttrs
& GPFS_WINATTR_ARCHIVE
){
1235 dosmode
|= FILE_ATTRIBUTE_ARCHIVE
;
1237 if (attrs
.winAttrs
& GPFS_WINATTR_HIDDEN
){
1238 dosmode
|= FILE_ATTRIBUTE_HIDDEN
;
1240 if (attrs
.winAttrs
& GPFS_WINATTR_SYSTEM
){
1241 dosmode
|= FILE_ATTRIBUTE_SYSTEM
;
1243 if (attrs
.winAttrs
& GPFS_WINATTR_READONLY
){
1244 dosmode
|= FILE_ATTRIBUTE_READONLY
;
1246 if (attrs
.winAttrs
& GPFS_WINATTR_SPARSE_FILE
) {
1247 dosmode
|= FILE_ATTRIBUTE_SPARSE
;
1250 snprintf(attrstr
, size
, "0x%2.2x",
1251 (unsigned int)(dosmode
& SAMBA_ATTRIBUTES_MASK
));
1252 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr
));
1256 static int vfs_gpfs_stat(struct vfs_handle_struct
*handle
,
1257 struct smb_filename
*smb_fname
)
1259 struct gpfs_winattr attrs
;
1263 struct gpfs_config_data
*config
;
1265 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1266 struct gpfs_config_data
,
1269 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
1274 if (!config
->winattr
) {
1278 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &fname
);
1279 if (!NT_STATUS_IS_OK(status
)) {
1280 errno
= map_errno_from_nt_status(status
);
1283 ret
= get_gpfs_winattrs(discard_const_p(char, fname
), &attrs
);
1286 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1287 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1288 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1289 smb_fname
->st
.vfs_private
= attrs
.winAttrs
;
1294 static int vfs_gpfs_fstat(struct vfs_handle_struct
*handle
,
1295 struct files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
1297 struct gpfs_winattr attrs
;
1299 struct gpfs_config_data
*config
;
1301 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1302 struct gpfs_config_data
,
1305 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
1309 if ((fsp
->fh
== NULL
) || (fsp
->fh
->fd
== -1)) {
1312 if (!config
->winattr
) {
1316 ret
= smbd_fget_gpfs_winattrs(fsp
->fh
->fd
, &attrs
);
1318 sbuf
->st_ex_calculated_birthtime
= false;
1319 sbuf
->st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1320 sbuf
->st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1325 static int vfs_gpfs_lstat(struct vfs_handle_struct
*handle
,
1326 struct smb_filename
*smb_fname
)
1328 struct gpfs_winattr attrs
;
1332 struct gpfs_config_data
*config
;
1334 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1335 struct gpfs_config_data
,
1338 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
1342 if (!config
->winattr
) {
1346 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1347 if (!NT_STATUS_IS_OK(status
)) {
1348 errno
= map_errno_from_nt_status(status
);
1351 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1354 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1355 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1356 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1357 smb_fname
->st
.vfs_private
= attrs
.winAttrs
;
1362 static int vfs_gpfs_ntimes(struct vfs_handle_struct
*handle
,
1363 const struct smb_filename
*smb_fname
,
1364 struct smb_file_time
*ft
)
1367 struct gpfs_winattr attrs
;
1371 struct gpfs_config_data
*config
;
1373 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1374 struct gpfs_config_data
,
1377 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1379 /* don't complain if access was denied */
1380 if (errno
!= EPERM
&& errno
!= EACCES
) {
1381 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1382 "%s", strerror(errno
)));
1387 if(null_timespec(ft
->create_time
)){
1388 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1392 if (!config
->winattr
) {
1396 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1397 if (!NT_STATUS_IS_OK(status
)) {
1398 errno
= map_errno_from_nt_status(status
);
1403 attrs
.creationTime
.tv_sec
= ft
->create_time
.tv_sec
;
1404 attrs
.creationTime
.tv_nsec
= ft
->create_time
.tv_nsec
;
1406 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1407 GPFS_WINATTR_SET_CREATION_TIME
, &attrs
);
1408 if(ret
== -1 && errno
!= ENOSYS
){
1409 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret
));
1416 static int vfs_gpfs_fallocate(struct vfs_handle_struct
*handle
,
1417 struct files_struct
*fsp
, enum vfs_fallocate_mode mode
,
1418 off_t offset
, off_t len
)
1421 struct gpfs_config_data
*config
;
1423 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1424 struct gpfs_config_data
,
1427 if (!config
->prealloc
) {
1428 /* you should better not run fallocate() on GPFS at all */
1433 if (mode
== VFS_FALLOCATE_KEEP_SIZE
) {
1434 DEBUG(10, ("Unsupported VFS_FALLOCATE_KEEP_SIZE\n"));
1439 ret
= smbd_gpfs_prealloc(fsp
->fh
->fd
, offset
, len
);
1441 if (ret
== -1 && errno
!= ENOSYS
) {
1442 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno
)));
1443 } else if (ret
== -1 && errno
== ENOSYS
) {
1444 DEBUG(10, ("GPFS prealloc not supported.\n"));
1446 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1452 static int vfs_gpfs_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1456 struct gpfs_config_data
*config
;
1458 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1459 struct gpfs_config_data
,
1462 if (!config
->ftruncate
) {
1463 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1466 result
= smbd_gpfs_ftruncate(fsp
->fh
->fd
, len
);
1467 if ((result
== -1) && (errno
== ENOSYS
)) {
1468 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1473 static bool vfs_gpfs_is_offline(struct vfs_handle_struct
*handle
,
1474 const struct smb_filename
*fname
,
1475 SMB_STRUCT_STAT
*sbuf
)
1477 struct gpfs_winattr attrs
;
1480 struct gpfs_config_data
*config
;
1482 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1483 struct gpfs_config_data
,
1486 if (!config
->winattr
) {
1487 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1490 status
= get_full_smb_filename(talloc_tos(), fname
, &path
);
1491 if (!NT_STATUS_IS_OK(status
)) {
1492 errno
= map_errno_from_nt_status(status
);
1496 if (VALID_STAT(*sbuf
)) {
1497 attrs
.winAttrs
= sbuf
->vfs_private
;
1500 ret
= get_gpfs_winattrs(path
, &attrs
);
1507 if ((attrs
.winAttrs
& GPFS_WINATTR_OFFLINE
) != 0) {
1508 DEBUG(10, ("%s is offline\n", path
));
1512 DEBUG(10, ("%s is online\n", path
));
1514 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1517 static bool vfs_gpfs_aio_force(struct vfs_handle_struct
*handle
,
1518 struct files_struct
*fsp
)
1520 return vfs_gpfs_is_offline(handle
, fsp
->fsp_name
, &fsp
->fsp_name
->st
);
1523 static ssize_t
vfs_gpfs_sendfile(vfs_handle_struct
*handle
, int tofd
,
1524 files_struct
*fsp
, const DATA_BLOB
*hdr
,
1525 off_t offset
, size_t n
)
1527 if ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0) {
1531 return SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fsp
, hdr
, offset
, n
);
1534 static int vfs_gpfs_connect(struct vfs_handle_struct
*handle
,
1535 const char *service
, const char *user
)
1537 struct gpfs_config_data
*config
;
1540 smbd_gpfs_lib_init();
1542 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1548 config
= talloc_zero(handle
->conn
, struct gpfs_config_data
);
1550 SMB_VFS_NEXT_DISCONNECT(handle
);
1551 DEBUG(0, ("talloc_zero() failed\n"));
1555 config
->sharemodes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1556 "sharemodes", true);
1558 config
->leases
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1561 config
->hsm
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1564 config
->syncio
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1567 config
->winattr
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1570 config
->ftruncate
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1573 config
->getrealfilename
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1574 "getrealfilename", true);
1576 config
->dfreequota
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1577 "dfreequota", false);
1579 config
->prealloc
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1582 config
->acl
= lp_parm_bool(SNUM(handle
->conn
), "gpfs", "acl", true);
1584 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
1585 NULL
, struct gpfs_config_data
,
1588 if (config
->leases
) {
1590 * GPFS lease code is based on kernel oplock code
1591 * so make sure it is turned on
1593 if (!lp_kernel_oplocks(SNUM(handle
->conn
))) {
1594 DEBUG(5, ("Enabling kernel oplocks for "
1595 "gpfs:leases to work\n"));
1596 lp_do_parameter(SNUM(handle
->conn
), "kernel oplocks",
1601 * as the kernel does not properly support Level II oplocks
1602 * and GPFS leases code is based on kernel infrastructure, we
1603 * need to turn off Level II oplocks if gpfs:leases is enabled
1605 if (lp_level2_oplocks(SNUM(handle
->conn
))) {
1606 DEBUG(5, ("gpfs:leases are enabled, disabling "
1607 "Level II oplocks\n"));
1608 lp_do_parameter(SNUM(handle
->conn
), "level2 oplocks",
1616 static int vfs_gpfs_get_quotas(const char *path
, uid_t uid
, gid_t gid
,
1618 struct gpfs_quotaInfo
*qi_user
,
1619 struct gpfs_quotaInfo
*qi_group
,
1620 struct gpfs_quotaInfo
*qi_fset
)
1627 * We want to always use the directory to get the fileset id,
1628 * because files might have a share mode. We also do not want
1629 * to get the parent directory when there is already a
1630 * directory to avoid stepping in a different fileset. The
1631 * path passed here is currently either "." or a filename, so
1632 * this is ok. The proper solution would be having a way to
1633 * query the fileset id without opening the file.
1635 b
= parent_dirname(talloc_tos(), path
, &dir_path
, NULL
);
1641 DEBUG(10, ("path %s, directory %s\n", path
, dir_path
));
1643 err
= get_gpfs_fset_id(dir_path
, fset_id
);
1645 DEBUG(0, ("Get fset id failed path %s, dir %s, errno %d.\n",
1646 path
, dir_path
, errno
));
1650 err
= get_gpfs_quota(path
, GPFS_USRQUOTA
, uid
, qi_user
);
1655 err
= get_gpfs_quota(path
, GPFS_GRPQUOTA
, gid
, qi_group
);
1660 err
= get_gpfs_quota(path
, GPFS_FILESETQUOTA
, *fset_id
, qi_fset
);
1668 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi
, time_t cur_time
,
1669 uint64_t *dfree
, uint64_t *dsize
)
1671 uint64_t usage
, limit
;
1674 * The quota reporting is done in units of 1024 byte blocks, but
1675 * sys_fsusage uses units of 512 byte blocks, adjust the block number
1676 * accordingly. Also filter possibly negative usage counts from gpfs.
1678 usage
= qi
.blockUsage
< 0 ? 0 : (uint64_t)qi
.blockUsage
* 2;
1679 limit
= (uint64_t)qi
.blockHardLimit
* 2;
1682 * When the grace time for the exceeded soft block quota has been
1683 * exceeded, the soft block quota becomes an additional hard limit.
1685 if (qi
.blockSoftLimit
&&
1686 qi
.blockGraceTime
&& cur_time
> qi
.blockGraceTime
) {
1687 /* report disk as full */
1689 *dsize
= MIN(*dsize
, usage
);
1692 if (!qi
.blockHardLimit
)
1695 if (usage
>= limit
) {
1696 /* report disk as full */
1698 *dsize
= MIN(*dsize
, usage
);
1701 /* limit has not been reached, determine "free space" */
1702 *dfree
= MIN(*dfree
, limit
- usage
);
1703 *dsize
= MIN(*dsize
, limit
);
1707 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct
*handle
, const char *path
,
1708 bool small_query
, uint64_t *bsize
,
1709 uint64_t *dfree
, uint64_t *dsize
)
1711 struct security_unix_token
*utok
;
1712 struct gpfs_quotaInfo qi_user
, qi_group
, qi_fset
;
1713 struct gpfs_config_data
*config
;
1717 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct gpfs_config_data
,
1718 return (uint64_t)-1);
1719 if (!config
->dfreequota
) {
1720 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1721 bsize
, dfree
, dsize
);
1724 err
= sys_fsusage(path
, dfree
, dsize
);
1726 DEBUG (0, ("Could not get fs usage, errno %d\n", errno
));
1727 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1728 bsize
, dfree
, dsize
);
1731 /* sys_fsusage returns units of 512 bytes */
1734 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
1735 (unsigned long long)*dfree
, (unsigned long long)*dsize
));
1737 utok
= handle
->conn
->session_info
->unix_token
;
1738 err
= vfs_gpfs_get_quotas(path
, utok
->uid
, utok
->gid
, &fset_id
,
1739 &qi_user
, &qi_group
, &qi_fset
);
1741 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1742 bsize
, dfree
, dsize
);
1745 cur_time
= time(NULL
);
1747 /* Adjust free space and size according to quota limits. */
1748 vfs_gpfs_disk_free_quota(qi_user
, cur_time
, dfree
, dsize
);
1749 vfs_gpfs_disk_free_quota(qi_group
, cur_time
, dfree
, dsize
);
1751 /* Id 0 indicates the default quota, not an actual quota */
1753 vfs_gpfs_disk_free_quota(qi_fset
, cur_time
, dfree
, dsize
);
1756 disk_norm(small_query
, bsize
, dfree
, dsize
);
1760 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct
*handle
,
1761 enum timestamp_set_resolution
*p_ts_res
)
1763 struct gpfs_config_data
*config
;
1766 next
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
1768 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1769 struct gpfs_config_data
,
1773 next
|= FILE_SUPPORTS_REMOTE_STORAGE
;
1778 static int vfs_gpfs_open(struct vfs_handle_struct
*handle
,
1779 struct smb_filename
*smb_fname
, files_struct
*fsp
,
1780 int flags
, mode_t mode
)
1782 struct gpfs_config_data
*config
;
1784 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1785 struct gpfs_config_data
,
1788 if (config
->syncio
) {
1791 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
1794 static ssize_t
vfs_gpfs_pread(vfs_handle_struct
*handle
, files_struct
*fsp
,
1795 void *data
, size_t n
, off_t offset
)
1799 ret
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
1801 DEBUG(10, ("vfs_private = %x\n",
1802 (unsigned int)fsp
->fsp_name
->st
.vfs_private
));
1805 ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0)) {
1806 fsp
->fsp_name
->st
.vfs_private
&= ~GPFS_WINATTR_OFFLINE
;
1807 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
1808 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
1809 fsp
->fsp_name
->base_name
);
1815 struct vfs_gpfs_pread_state
{
1816 struct files_struct
*fsp
;
1821 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
);
1823 static struct tevent_req
*vfs_gpfs_pread_send(struct vfs_handle_struct
*handle
,
1824 TALLOC_CTX
*mem_ctx
,
1825 struct tevent_context
*ev
,
1826 struct files_struct
*fsp
,
1827 void *data
, size_t n
,
1830 struct tevent_req
*req
, *subreq
;
1831 struct vfs_gpfs_pread_state
*state
;
1833 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pread_state
);
1838 subreq
= SMB_VFS_NEXT_PREAD_SEND(state
, ev
, handle
, fsp
, data
,
1840 if (tevent_req_nomem(subreq
, req
)) {
1841 return tevent_req_post(req
, ev
);
1843 tevent_req_set_callback(subreq
, vfs_gpfs_pread_done
, req
);
1847 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
)
1849 struct tevent_req
*req
= tevent_req_callback_data(
1850 subreq
, struct tevent_req
);
1851 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
1852 req
, struct vfs_gpfs_pread_state
);
1854 state
->ret
= SMB_VFS_PREAD_RECV(subreq
, &state
->err
);
1855 TALLOC_FREE(subreq
);
1856 tevent_req_done(req
);
1859 static ssize_t
vfs_gpfs_pread_recv(struct tevent_req
*req
, int *err
)
1861 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
1862 req
, struct vfs_gpfs_pread_state
);
1863 struct files_struct
*fsp
= state
->fsp
;
1865 if (tevent_req_is_unix_error(req
, err
)) {
1870 DEBUG(10, ("vfs_private = %x\n",
1871 (unsigned int)fsp
->fsp_name
->st
.vfs_private
));
1873 if ((state
->ret
!= -1) &&
1874 ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0)) {
1875 fsp
->fsp_name
->st
.vfs_private
&= ~GPFS_WINATTR_OFFLINE
;
1876 DEBUG(10, ("sending notify\n"));
1877 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
1878 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
1879 fsp
->fsp_name
->base_name
);
1885 static ssize_t
vfs_gpfs_pwrite(vfs_handle_struct
*handle
, files_struct
*fsp
,
1886 const void *data
, size_t n
, off_t offset
)
1890 ret
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
1892 DEBUG(10, ("vfs_private = %x\n",
1893 (unsigned int)fsp
->fsp_name
->st
.vfs_private
));
1896 ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0)) {
1897 fsp
->fsp_name
->st
.vfs_private
&= ~GPFS_WINATTR_OFFLINE
;
1898 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
1899 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
1900 fsp
->fsp_name
->base_name
);
1906 struct vfs_gpfs_pwrite_state
{
1907 struct files_struct
*fsp
;
1912 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
);
1914 static struct tevent_req
*vfs_gpfs_pwrite_send(
1915 struct vfs_handle_struct
*handle
,
1916 TALLOC_CTX
*mem_ctx
,
1917 struct tevent_context
*ev
,
1918 struct files_struct
*fsp
,
1919 const void *data
, size_t n
,
1922 struct tevent_req
*req
, *subreq
;
1923 struct vfs_gpfs_pwrite_state
*state
;
1925 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pwrite_state
);
1930 subreq
= SMB_VFS_NEXT_PWRITE_SEND(state
, ev
, handle
, fsp
, data
,
1932 if (tevent_req_nomem(subreq
, req
)) {
1933 return tevent_req_post(req
, ev
);
1935 tevent_req_set_callback(subreq
, vfs_gpfs_pwrite_done
, req
);
1939 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
)
1941 struct tevent_req
*req
= tevent_req_callback_data(
1942 subreq
, struct tevent_req
);
1943 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
1944 req
, struct vfs_gpfs_pwrite_state
);
1946 state
->ret
= SMB_VFS_PWRITE_RECV(subreq
, &state
->err
);
1947 TALLOC_FREE(subreq
);
1948 tevent_req_done(req
);
1951 static ssize_t
vfs_gpfs_pwrite_recv(struct tevent_req
*req
, int *err
)
1953 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
1954 req
, struct vfs_gpfs_pwrite_state
);
1955 struct files_struct
*fsp
= state
->fsp
;
1957 if (tevent_req_is_unix_error(req
, err
)) {
1962 DEBUG(10, ("vfs_private = %x\n",
1963 (unsigned int)fsp
->fsp_name
->st
.vfs_private
));
1965 if ((state
->ret
!= -1) &&
1966 ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0)) {
1967 fsp
->fsp_name
->st
.vfs_private
&= ~GPFS_WINATTR_OFFLINE
;
1968 DEBUG(10, ("sending notify\n"));
1969 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
1970 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
1971 fsp
->fsp_name
->base_name
);
1978 static struct vfs_fn_pointers vfs_gpfs_fns
= {
1979 .connect_fn
= vfs_gpfs_connect
,
1980 .disk_free_fn
= vfs_gpfs_disk_free
,
1981 .fs_capabilities_fn
= vfs_gpfs_capabilities
,
1982 .kernel_flock_fn
= vfs_gpfs_kernel_flock
,
1983 .linux_setlease_fn
= vfs_gpfs_setlease
,
1984 .get_real_filename_fn
= vfs_gpfs_get_real_filename
,
1985 .fget_nt_acl_fn
= gpfsacl_fget_nt_acl
,
1986 .get_nt_acl_fn
= gpfsacl_get_nt_acl
,
1987 .fset_nt_acl_fn
= gpfsacl_fset_nt_acl
,
1988 .sys_acl_get_file_fn
= gpfsacl_sys_acl_get_file
,
1989 .sys_acl_get_fd_fn
= gpfsacl_sys_acl_get_fd
,
1990 .sys_acl_blob_get_file_fn
= gpfsacl_sys_acl_blob_get_file
,
1991 .sys_acl_blob_get_fd_fn
= gpfsacl_sys_acl_blob_get_fd
,
1992 .sys_acl_set_file_fn
= gpfsacl_sys_acl_set_file
,
1993 .sys_acl_set_fd_fn
= gpfsacl_sys_acl_set_fd
,
1994 .sys_acl_delete_def_file_fn
= gpfsacl_sys_acl_delete_def_file
,
1995 .chmod_fn
= vfs_gpfs_chmod
,
1996 .fchmod_fn
= vfs_gpfs_fchmod
,
1997 .close_fn
= vfs_gpfs_close
,
1998 .setxattr_fn
= gpfs_set_xattr
,
1999 .getxattr_fn
= gpfs_get_xattr
,
2000 .stat_fn
= vfs_gpfs_stat
,
2001 .fstat_fn
= vfs_gpfs_fstat
,
2002 .lstat_fn
= vfs_gpfs_lstat
,
2003 .ntimes_fn
= vfs_gpfs_ntimes
,
2004 .is_offline_fn
= vfs_gpfs_is_offline
,
2005 .aio_force_fn
= vfs_gpfs_aio_force
,
2006 .sendfile_fn
= vfs_gpfs_sendfile
,
2007 .fallocate_fn
= vfs_gpfs_fallocate
,
2008 .open_fn
= vfs_gpfs_open
,
2009 .pread_fn
= vfs_gpfs_pread
,
2010 .pread_send_fn
= vfs_gpfs_pread_send
,
2011 .pread_recv_fn
= vfs_gpfs_pread_recv
,
2012 .pwrite_fn
= vfs_gpfs_pwrite
,
2013 .pwrite_send_fn
= vfs_gpfs_pwrite_send
,
2014 .pwrite_recv_fn
= vfs_gpfs_pwrite_recv
,
2015 .ftruncate_fn
= vfs_gpfs_ftruncate
2018 NTSTATUS
vfs_gpfs_init(void);
2019 NTSTATUS
vfs_gpfs_init(void)
2023 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "gpfs",