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
{
55 static int vfs_gpfs_kernel_flock(vfs_handle_struct
*handle
, files_struct
*fsp
,
56 uint32 share_mode
, uint32 access_mask
)
59 struct gpfs_config_data
*config
;
62 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
63 struct gpfs_config_data
,
66 if(!config
->sharemodes
) {
70 START_PROFILE(syscall_kernel_flock
);
72 kernel_flock(fsp
->fh
->fd
, share_mode
, access_mask
);
74 if (!set_gpfs_sharemode(fsp
, access_mask
, fsp
->share_access
)) {
78 END_PROFILE(syscall_kernel_flock
);
83 static int vfs_gpfs_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
86 struct gpfs_config_data
*config
;
88 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
89 struct gpfs_config_data
,
92 if (config
->sharemodes
&& (fsp
->fh
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
93 set_gpfs_sharemode(fsp
, 0, 0);
96 return SMB_VFS_NEXT_CLOSE(handle
, fsp
);
99 static int vfs_gpfs_setlease(vfs_handle_struct
*handle
, files_struct
*fsp
,
102 struct gpfs_config_data
*config
;
105 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
106 struct gpfs_config_data
,
109 if (linux_set_lease_sighandler(fsp
->fh
->fd
) == -1)
112 START_PROFILE(syscall_linux_setlease
);
114 if (config
->leases
) {
116 * Ensure the lease owner is root to allow
117 * correct delivery of lease-break signals.
120 ret
= set_gpfs_lease(fsp
->fh
->fd
,leasetype
);
124 END_PROFILE(syscall_linux_setlease
);
129 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct
*handle
,
137 char real_pathname
[PATH_MAX
+1];
140 struct gpfs_config_data
*config
;
142 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
143 struct gpfs_config_data
,
146 if (!config
->getrealfilename
) {
147 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
148 mem_ctx
, found_name
);
151 mangled
= mangle_is_mangled(name
, handle
->conn
->params
);
153 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
154 mem_ctx
, found_name
);
157 full_path
= talloc_asprintf(talloc_tos(), "%s/%s", path
, name
);
158 if (full_path
== NULL
) {
163 buflen
= sizeof(real_pathname
) - 1;
165 result
= smbd_gpfs_get_realfilename_path(full_path
, real_pathname
,
168 TALLOC_FREE(full_path
);
170 if ((result
== -1) && (errno
== ENOSYS
)) {
171 return SMB_VFS_NEXT_GET_REAL_FILENAME(
172 handle
, path
, name
, mem_ctx
, found_name
);
176 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
182 * GPFS does not necessarily null-terminate the returned path
183 * but instead returns the buffer length in buflen.
186 if (buflen
< sizeof(real_pathname
)) {
187 real_pathname
[buflen
] = '\0';
189 real_pathname
[sizeof(real_pathname
)-1] = '\0';
192 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
193 path
, name
, real_pathname
));
195 name
= strrchr_m(real_pathname
, '/');
201 *found_name
= talloc_strdup(mem_ctx
, name
+1);
202 if (*found_name
== NULL
) {
210 static void gpfs_dumpacl(int level
, struct gpfs_acl
*gacl
)
215 DEBUG(0, ("gpfs acl is NULL\n"));
219 DEBUG(level
, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n",
220 gacl
->acl_nace
, gacl
->acl_type
, gacl
->acl_version
, gacl
->acl_level
, gacl
->acl_len
));
221 for(i
=0; i
<gacl
->acl_nace
; i
++)
223 struct gpfs_ace_v4
*gace
= gacl
->ace_v4
+ i
;
224 DEBUG(level
, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n",
225 i
, gace
->aceType
, gace
->aceFlags
, gace
->aceMask
,
226 gace
->aceIFlags
, gace
->aceWho
));
231 * get the ACL from GPFS, allocated on the specified mem_ctx
232 * internally retries when initial buffer was too small
234 * caller needs to cast result to either
235 * raw = yes: struct gpfs_opaque_acl
236 * raw = no: struct gpfs_acl
239 static void *vfs_gpfs_getacl(TALLOC_CTX
*mem_ctx
,
242 const gpfs_aclType_t type
)
253 aclbuf
= talloc_zero_size(mem_ctx
, size
);
254 if (aclbuf
== NULL
) {
260 struct gpfs_opaque_acl
*buf
= (struct gpfs_opaque_acl
*) aclbuf
;
261 buf
->acl_type
= type
;
262 flags
= GPFS_GETACL_NATIVE
;
263 len
= (unsigned int *) &(buf
->acl_buffer_len
);
264 struct_size
= sizeof(struct gpfs_opaque_acl
);
266 struct gpfs_acl
*buf
= (struct gpfs_acl
*) aclbuf
;
267 buf
->acl_type
= type
;
268 flags
= GPFS_GETACL_STRUCT
;
269 len
= &(buf
->acl_len
);
270 struct_size
= sizeof(struct gpfs_acl
);
273 /* set the length of the buffer as input value */
277 ret
= smbd_gpfs_getacl((char *)fname
, flags
, aclbuf
);
278 if ((ret
!= 0) && (errno
== ENOSPC
)) {
280 * get the size needed to accommodate the complete buffer
282 * the value returned only applies to the ACL blob in the
283 * struct so make sure to also have headroom for the first
284 * struct members by adding room for the complete struct
285 * (might be a few bytes too much then)
287 size
= *len
+ struct_size
;
289 DEBUG(10, ("Increasing ACL buffer size to %zu\n", size
));
294 DEBUG(5, ("smbd_gpfs_getacl failed with %s\n",
303 /* Tries to get nfs4 acls and returns SMB ACL allocated.
304 * On failure returns 1 if it got non-NFSv4 ACL to prompt
305 * retry with POSIX ACL checks.
306 * On failure returns -1 if there is system (GPFS) error, check errno.
307 * Returns 0 on success
309 static int gpfs_get_nfs4_acl(TALLOC_CTX
*mem_ctx
, const char *fname
, SMB4ACL_T
**ppacl
)
312 struct gpfs_acl
*gacl
= NULL
;
313 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname
));
316 gacl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(), fname
,
319 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
320 fname
, strerror(errno
)));
324 if (gacl
->acl_type
!= GPFS_ACL_TYPE_NFS4
) {
325 DEBUG(10, ("Got non-nfsv4 acl\n"));
326 /* Retry with POSIX ACLs check */
331 *ppacl
= smb_create_smb4acl(mem_ctx
);
333 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
334 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
337 for (i
=0; i
<gacl
->acl_nace
; i
++) {
338 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[i
];
339 SMB_ACE4PROP_T smbace
;
340 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
341 "who: %d\n", gace
->aceType
, gace
->aceIFlags
,
342 gace
->aceFlags
, gace
->aceMask
, gace
->aceWho
));
345 if (gace
->aceIFlags
& ACE4_IFLAG_SPECIAL_ID
) {
346 smbace
.flags
|= SMB_ACE4_ID_SPECIAL
;
347 switch (gace
->aceWho
) {
348 case ACE4_SPECIAL_OWNER
:
349 smbace
.who
.special_id
= SMB_ACE4_WHO_OWNER
;
351 case ACE4_SPECIAL_GROUP
:
352 smbace
.who
.special_id
= SMB_ACE4_WHO_GROUP
;
354 case ACE4_SPECIAL_EVERYONE
:
355 smbace
.who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
358 DEBUG(8, ("invalid special gpfs id %d "
359 "ignored\n", gace
->aceWho
));
360 continue; /* don't add it */
363 if (gace
->aceFlags
& ACE4_FLAG_GROUP_ID
)
364 smbace
.who
.gid
= gace
->aceWho
;
366 smbace
.who
.uid
= gace
->aceWho
;
369 /* remove redundant deny entries */
370 if (i
> 0 && gace
->aceType
== SMB_ACE4_ACCESS_DENIED_ACE_TYPE
) {
371 struct gpfs_ace_v4
*prev
= &gacl
->ace_v4
[i
-1];
372 if (prev
->aceType
== SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
&&
373 prev
->aceFlags
== gace
->aceFlags
&&
374 prev
->aceIFlags
== gace
->aceIFlags
&&
375 (gace
->aceMask
& prev
->aceMask
) == 0 &&
376 gace
->aceWho
== prev
->aceWho
) {
377 /* it's redundant - skip it */
382 smbace
.aceType
= gace
->aceType
;
383 smbace
.aceFlags
= gace
->aceFlags
;
384 smbace
.aceMask
= gace
->aceMask
;
385 smb_add_ace4(*ppacl
, &smbace
);
393 static NTSTATUS
gpfsacl_fget_nt_acl(vfs_handle_struct
*handle
,
394 files_struct
*fsp
, uint32 security_info
,
396 struct security_descriptor
**ppdesc
)
398 SMB4ACL_T
*pacl
= NULL
;
400 struct gpfs_config_data
*config
;
401 TALLOC_CTX
*frame
= talloc_stackframe();
406 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
407 struct gpfs_config_data
,
408 return NT_STATUS_INTERNAL_ERROR
);
411 status
= SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
417 result
= gpfs_get_nfs4_acl(frame
, fsp
->fsp_name
->base_name
, &pacl
);
420 status
= smb_fget_nt_acl_nfs4(fsp
, security_info
, mem_ctx
,
427 DEBUG(10, ("retrying with posix acl...\n"));
428 status
= posix_fget_nt_acl(fsp
, security_info
,
436 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
437 return map_nt_error_from_unix(errno
);
440 static NTSTATUS
gpfsacl_get_nt_acl(vfs_handle_struct
*handle
,
442 uint32 security_info
,
443 TALLOC_CTX
*mem_ctx
, struct security_descriptor
**ppdesc
)
445 SMB4ACL_T
*pacl
= NULL
;
447 struct gpfs_config_data
*config
;
448 TALLOC_CTX
*frame
= talloc_stackframe();
453 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
454 struct gpfs_config_data
,
455 return NT_STATUS_INTERNAL_ERROR
);
458 status
= SMB_VFS_NEXT_GET_NT_ACL(handle
, name
, security_info
,
464 result
= gpfs_get_nfs4_acl(frame
, name
, &pacl
);
467 status
= smb_get_nt_acl_nfs4(handle
->conn
, name
, security_info
,
468 mem_ctx
, ppdesc
, pacl
);
474 DEBUG(10, ("retrying with posix acl...\n"));
475 status
= posix_get_nt_acl(handle
->conn
, name
, security_info
,
481 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
483 return map_nt_error_from_unix(errno
);
486 static bool gpfsacl_process_smbacl(vfs_handle_struct
*handle
, files_struct
*fsp
, SMB4ACL_T
*smbacl
)
489 gpfs_aclLen_t gacl_len
;
491 struct gpfs_acl
*gacl
;
492 TALLOC_CTX
*mem_ctx
= talloc_tos();
494 gacl_len
= offsetof(gpfs_acl_t
, ace_v4
) + smb_get_naces(smbacl
) *
495 sizeof(gpfs_ace_v4_t
);
497 gacl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, gacl_len
);
499 DEBUG(0, ("talloc failed\n"));
504 gacl
->acl_len
= gacl_len
;
506 gacl
->acl_version
= GPFS_ACL_VERSION_NFS4
;
507 gacl
->acl_type
= GPFS_ACL_TYPE_NFS4
;
508 gacl
->acl_nace
= 0; /* change later... */
510 for (smbace
=smb_first_ace4(smbacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
511 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[gacl
->acl_nace
];
512 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
514 gace
->aceType
= aceprop
->aceType
;
515 gace
->aceFlags
= aceprop
->aceFlags
;
516 gace
->aceMask
= aceprop
->aceMask
;
519 * GPFS can't distinguish between WRITE and APPEND on
520 * files, so one being set without the other is an
521 * error. Sorry for the many ()'s :-)
524 if (!fsp
->is_directory
526 ((((gace
->aceMask
& ACE4_MASK_WRITE
) == 0)
527 && ((gace
->aceMask
& ACE4_MASK_APPEND
) != 0))
529 (((gace
->aceMask
& ACE4_MASK_WRITE
) != 0)
530 && ((gace
->aceMask
& ACE4_MASK_APPEND
) == 0)))
532 lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
533 "merge_writeappend", True
)) {
534 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
535 "WRITE^APPEND, setting WRITE|APPEND\n",
537 gace
->aceMask
|= ACE4_MASK_WRITE
|ACE4_MASK_APPEND
;
540 gace
->aceIFlags
= (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
) ? ACE4_IFLAG_SPECIAL_ID
: 0;
542 if (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
)
544 switch(aceprop
->who
.special_id
)
546 case SMB_ACE4_WHO_EVERYONE
:
547 gace
->aceWho
= ACE4_SPECIAL_EVERYONE
;
549 case SMB_ACE4_WHO_OWNER
:
550 gace
->aceWho
= ACE4_SPECIAL_OWNER
;
552 case SMB_ACE4_WHO_GROUP
:
553 gace
->aceWho
= ACE4_SPECIAL_GROUP
;
556 DEBUG(8, ("unsupported special_id %d\n", aceprop
->who
.special_id
));
557 continue; /* don't add it !!! */
560 /* just only for the type safety... */
561 if (aceprop
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)
562 gace
->aceWho
= aceprop
->who
.gid
;
564 gace
->aceWho
= aceprop
->who
.uid
;
570 ret
= smbd_gpfs_putacl(fsp
->fsp_name
->base_name
,
571 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gacl
);
573 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno
)));
574 gpfs_dumpacl(8, gacl
);
578 DEBUG(10, ("gpfs_putacl succeeded\n"));
582 static NTSTATUS
gpfsacl_set_nt_acl_internal(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
584 struct gpfs_acl
*acl
;
585 NTSTATUS result
= NT_STATUS_ACCESS_DENIED
;
587 acl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(),
588 fsp
->fsp_name
->base_name
,
591 return map_nt_error_from_unix(errno
);
594 if (acl
->acl_version
== GPFS_ACL_VERSION_NFS4
) {
595 if (lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
596 "refuse_dacl_protected", false)
597 && (psd
->type
&SEC_DESC_DACL_PROTECTED
)) {
598 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
600 return NT_STATUS_NOT_SUPPORTED
;
603 result
= smb_set_nt_acl_nfs4(handle
,
604 fsp
, security_info_sent
, psd
,
605 gpfsacl_process_smbacl
);
606 } else { /* assume POSIX ACL - by default... */
607 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
614 static NTSTATUS
gpfsacl_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
616 struct gpfs_config_data
*config
;
618 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
619 struct gpfs_config_data
,
620 return NT_STATUS_INTERNAL_ERROR
);
623 return SMB_VFS_NEXT_FSET_NT_ACL(handle
, fsp
, security_info_sent
, psd
);
626 return gpfsacl_set_nt_acl_internal(handle
, fsp
, security_info_sent
, psd
);
629 static SMB_ACL_T
gpfs2smb_acl(const struct gpfs_acl
*pacl
, TALLOC_CTX
*mem_ctx
)
634 result
= sys_acl_init(mem_ctx
);
635 if (result
== NULL
) {
640 result
->count
= pacl
->acl_nace
;
641 result
->acl
= talloc_realloc(result
, result
->acl
, struct smb_acl_entry
,
643 if (result
->acl
== NULL
) {
649 for (i
=0; i
<pacl
->acl_nace
; i
++) {
650 struct smb_acl_entry
*ace
= &result
->acl
[i
];
651 const struct gpfs_ace_v1
*g_ace
= &pacl
->ace_v1
[i
];
653 DEBUG(10, ("Converting type %d id %lu perm %x\n",
654 (int)g_ace
->ace_type
, (unsigned long)g_ace
->ace_who
,
655 (int)g_ace
->ace_perm
));
657 switch (g_ace
->ace_type
) {
659 ace
->a_type
= SMB_ACL_USER
;
660 ace
->info
.user
.uid
= (uid_t
)g_ace
->ace_who
;
662 case GPFS_ACL_USER_OBJ
:
663 ace
->a_type
= SMB_ACL_USER_OBJ
;
666 ace
->a_type
= SMB_ACL_GROUP
;
667 ace
->info
.group
.gid
= (gid_t
)g_ace
->ace_who
;
669 case GPFS_ACL_GROUP_OBJ
:
670 ace
->a_type
= SMB_ACL_GROUP_OBJ
;
673 ace
->a_type
= SMB_ACL_OTHER
;
676 ace
->a_type
= SMB_ACL_MASK
;
679 DEBUG(10, ("Got invalid ace_type: %d\n",
687 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_READ
) ?
689 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_WRITE
) ?
691 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_EXECUTE
) ?
694 DEBUGADD(10, ("Converted to %d perm %x\n",
695 ace
->a_type
, ace
->a_perm
));
701 static SMB_ACL_T
gpfsacl_get_posix_acl(const char *path
, gpfs_aclType_t type
,
704 struct gpfs_acl
*pacl
;
705 SMB_ACL_T result
= NULL
;
707 pacl
= vfs_gpfs_getacl(talloc_tos(), path
, false, type
);
710 DEBUG(10, ("vfs_gpfs_getacl failed for %s with %s\n",
711 path
, strerror(errno
)));
718 if (pacl
->acl_version
!= GPFS_ACL_VERSION_POSIX
) {
719 DEBUG(10, ("Got acl version %d, expected %d\n",
720 pacl
->acl_version
, GPFS_ACL_VERSION_POSIX
));
725 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
726 pacl
->acl_len
, pacl
->acl_level
, pacl
->acl_version
,
729 result
= gpfs2smb_acl(pacl
, mem_ctx
);
730 if (result
!= NULL
) {
745 static SMB_ACL_T
gpfsacl_sys_acl_get_file(vfs_handle_struct
*handle
,
750 gpfs_aclType_t gpfs_type
;
751 struct gpfs_config_data
*config
;
753 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
754 struct gpfs_config_data
,
758 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle
, path_p
,
763 case SMB_ACL_TYPE_ACCESS
:
764 gpfs_type
= GPFS_ACL_TYPE_ACCESS
;
766 case SMB_ACL_TYPE_DEFAULT
:
767 gpfs_type
= GPFS_ACL_TYPE_DEFAULT
;
770 DEBUG(0, ("Got invalid type: %d\n", type
));
771 smb_panic("exiting");
774 return gpfsacl_get_posix_acl(path_p
, gpfs_type
, mem_ctx
);
777 static SMB_ACL_T
gpfsacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
781 struct gpfs_config_data
*config
;
783 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
784 struct gpfs_config_data
,
788 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle
, fsp
, mem_ctx
);
791 return gpfsacl_get_posix_acl(fsp
->fsp_name
->base_name
,
792 GPFS_ACL_TYPE_ACCESS
, mem_ctx
);
795 static int gpfsacl_sys_acl_blob_get_file(vfs_handle_struct
*handle
,
798 char **blob_description
,
801 struct gpfs_config_data
*config
;
802 struct gpfs_opaque_acl
*acl
= NULL
;
806 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
807 struct gpfs_config_data
,
811 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle
, path_p
,
818 acl
= (struct gpfs_opaque_acl
*)
819 vfs_gpfs_getacl(mem_ctx
,
825 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
826 errno
, strerror(errno
)));
828 /* EINVAL means POSIX ACL, bail out on other cases */
829 if (errno
!= EINVAL
) {
838 * we only need the actual ACL blob here
839 * acl_version will always be NFS4 because we asked
841 * acl_type is only used for POSIX ACLs
843 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
844 aclblob
.length
= acl
->acl_buffer_len
;
846 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
847 if (!*blob_description
) {
853 result
= non_posix_sys_acl_blob_get_file_helper(handle
, path_p
,
861 /* fall back to POSIX ACL */
862 return posix_sys_acl_blob_get_file(handle
, path_p
, mem_ctx
,
863 blob_description
, blob
);
866 static int gpfsacl_sys_acl_blob_get_fd(vfs_handle_struct
*handle
,
869 char **blob_description
,
872 struct gpfs_config_data
*config
;
873 struct gpfs_opaque_acl
*acl
= NULL
;
877 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
878 struct gpfs_config_data
,
882 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle
, fsp
, mem_ctx
,
883 blob_description
, blob
);
887 acl
= (struct gpfs_opaque_acl
*) vfs_gpfs_getacl(mem_ctx
,
888 fsp
->fsp_name
->base_name
,
893 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
894 errno
, strerror(errno
)));
896 /* EINVAL means POSIX ACL, bail out on other cases */
897 if (errno
!= EINVAL
) {
906 * we only need the actual ACL blob here
907 * acl_version will always be NFS4 because we asked
909 * acl_type is only used for POSIX ACLs
911 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
912 aclblob
.length
= acl
->acl_buffer_len
;
914 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
915 if (!*blob_description
) {
921 result
= non_posix_sys_acl_blob_get_fd_helper(handle
, fsp
,
929 /* fall back to POSIX ACL */
930 return posix_sys_acl_blob_get_fd(handle
, fsp
, mem_ctx
,
931 blob_description
, blob
);
934 static struct gpfs_acl
*smb2gpfs_acl(const SMB_ACL_T pacl
,
938 struct gpfs_acl
*result
;
941 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl
->count
));
943 len
= offsetof(gpfs_acl_t
, ace_v1
) + (pacl
->count
) *
944 sizeof(gpfs_ace_v1_t
);
946 result
= (struct gpfs_acl
*)SMB_MALLOC(len
);
947 if (result
== NULL
) {
952 result
->acl_len
= len
;
953 result
->acl_level
= 0;
954 result
->acl_version
= GPFS_ACL_VERSION_POSIX
;
955 result
->acl_type
= (type
== SMB_ACL_TYPE_DEFAULT
) ?
956 GPFS_ACL_TYPE_DEFAULT
: GPFS_ACL_TYPE_ACCESS
;
957 result
->acl_nace
= pacl
->count
;
959 for (i
=0; i
<pacl
->count
; i
++) {
960 const struct smb_acl_entry
*ace
= &pacl
->acl
[i
];
961 struct gpfs_ace_v1
*g_ace
= &result
->ace_v1
[i
];
963 DEBUG(10, ("Converting type %d perm %x\n",
964 (int)ace
->a_type
, (int)ace
->a_perm
));
968 switch(ace
->a_type
) {
970 g_ace
->ace_type
= GPFS_ACL_USER
;
971 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.user
.uid
;
973 case SMB_ACL_USER_OBJ
:
974 g_ace
->ace_type
= GPFS_ACL_USER_OBJ
;
975 g_ace
->ace_perm
|= ACL_PERM_CONTROL
;
979 g_ace
->ace_type
= GPFS_ACL_GROUP
;
980 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.group
.gid
;
982 case SMB_ACL_GROUP_OBJ
:
983 g_ace
->ace_type
= GPFS_ACL_GROUP_OBJ
;
987 g_ace
->ace_type
= GPFS_ACL_MASK
;
988 g_ace
->ace_perm
= 0x8f;
992 g_ace
->ace_type
= GPFS_ACL_OTHER
;
996 DEBUG(10, ("Got invalid ace_type: %d\n", ace
->a_type
));
1002 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_READ
) ?
1004 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_WRITE
) ?
1006 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_EXECUTE
) ?
1007 ACL_PERM_EXECUTE
: 0;
1009 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
1010 g_ace
->ace_type
, g_ace
->ace_who
, g_ace
->ace_perm
));
1016 static int gpfsacl_sys_acl_set_file(vfs_handle_struct
*handle
,
1018 SMB_ACL_TYPE_T type
,
1021 struct gpfs_acl
*gpfs_acl
;
1023 struct gpfs_config_data
*config
;
1025 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1026 struct gpfs_config_data
,
1030 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle
, name
, type
, theacl
);
1033 gpfs_acl
= smb2gpfs_acl(theacl
, type
);
1034 if (gpfs_acl
== NULL
) {
1038 result
= smbd_gpfs_putacl((char *)name
, GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gpfs_acl
);
1040 SAFE_FREE(gpfs_acl
);
1044 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
1048 struct gpfs_config_data
*config
;
1050 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1051 struct gpfs_config_data
,
1055 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle
, fsp
, theacl
);
1058 return gpfsacl_sys_acl_set_file(handle
, fsp
->fsp_name
->base_name
,
1059 SMB_ACL_TYPE_ACCESS
, theacl
);
1062 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
1065 struct gpfs_config_data
*config
;
1067 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1068 struct gpfs_config_data
,
1072 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle
, path
);
1080 * Assumed: mode bits are shiftable and standard
1081 * Output: the new aceMask field for an smb nfs4 ace
1083 static uint32
gpfsacl_mask_filter(uint32 aceType
, uint32 aceMask
, uint32 rwx
)
1085 const uint32 posix_nfs4map
[3] = {
1086 SMB_ACE4_EXECUTE
, /* execute */
1087 SMB_ACE4_WRITE_DATA
| SMB_ACE4_APPEND_DATA
, /* write; GPFS specific */
1088 SMB_ACE4_READ_DATA
/* read */
1091 uint32_t posix_mask
= 0x01;
1095 for(i
=0; i
<3; i
++) {
1096 nfs4_bits
= posix_nfs4map
[i
];
1097 posix_bit
= rwx
& posix_mask
;
1099 if (aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
) {
1101 aceMask
|= nfs4_bits
;
1103 aceMask
&= ~nfs4_bits
;
1105 /* add deny bits when suitable */
1107 aceMask
|= nfs4_bits
;
1109 aceMask
&= ~nfs4_bits
;
1110 } /* other ace types are unexpected */
1118 static int gpfsacl_emu_chmod(vfs_handle_struct
*handle
,
1119 const char *path
, mode_t mode
)
1121 SMB4ACL_T
*pacl
= NULL
;
1123 bool haveAllowEntry
[SMB_ACE4_WHO_EVERYONE
+ 1] = {False
, False
, False
, False
};
1125 files_struct fake_fsp
; /* TODO: rationalize parametrization */
1127 TALLOC_CTX
*frame
= talloc_stackframe();
1130 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path
, mode
));
1132 result
= gpfs_get_nfs4_acl(frame
, path
, &pacl
);
1138 if (mode
& ~(S_IRWXU
| S_IRWXG
| S_IRWXO
)) {
1139 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode
, path
));
1142 for (smbace
=smb_first_ace4(pacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
1143 SMB_ACE4PROP_T
*ace
= smb_get_ace4(smbace
);
1144 uint32_t specid
= ace
->who
.special_id
;
1146 if (ace
->flags
&SMB_ACE4_ID_SPECIAL
&&
1147 ace
->aceType
<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE
&&
1148 specid
<= SMB_ACE4_WHO_EVERYONE
) {
1152 if (ace
->aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
)
1153 haveAllowEntry
[specid
] = True
;
1155 /* mode >> 6 for @owner, mode >> 3 for @group,
1156 * mode >> 0 for @everyone */
1157 newMask
= gpfsacl_mask_filter(ace
->aceType
, ace
->aceMask
,
1158 mode
>> ((SMB_ACE4_WHO_EVERYONE
- specid
) * 3));
1159 if (ace
->aceMask
!=newMask
) {
1160 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
1161 path
, ace
->aceMask
, newMask
, specid
));
1163 ace
->aceMask
= newMask
;
1167 /* make sure we have at least ALLOW entries
1168 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
1171 for(i
= SMB_ACE4_WHO_OWNER
; i
<=SMB_ACE4_WHO_EVERYONE
; i
++) {
1174 if (haveAllowEntry
[i
]==True
)
1178 ace
.aceType
= SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
;
1179 ace
.flags
|= SMB_ACE4_ID_SPECIAL
;
1180 ace
.who
.special_id
= i
;
1182 if (i
==SMB_ACE4_WHO_GROUP
) /* not sure it's necessary... */
1183 ace
.aceFlags
|= SMB_ACE4_IDENTIFIER_GROUP
;
1185 ace
.aceMask
= gpfsacl_mask_filter(ace
.aceType
, ace
.aceMask
,
1186 mode
>> ((SMB_ACE4_WHO_EVERYONE
- i
) * 3));
1188 /* don't add unnecessary aces */
1192 /* we add it to the END - as windows expects allow aces */
1193 smb_add_ace4(pacl
, &ace
);
1194 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1195 path
, mode
, i
, ace
.aceMask
));
1198 /* don't add complementary DENY ACEs here */
1199 ZERO_STRUCT(fake_fsp
);
1200 fake_fsp
.fsp_name
= synthetic_smb_fname(
1201 frame
, path
, NULL
, NULL
);
1202 if (fake_fsp
.fsp_name
== NULL
) {
1208 if (gpfsacl_process_smbacl(handle
, &fake_fsp
, pacl
) == False
) {
1214 return 0; /* ok for [f]chmod */
1217 static int vfs_gpfs_chmod(vfs_handle_struct
*handle
, const char *path
, mode_t mode
)
1219 struct smb_filename
*smb_fname_cpath
;
1222 smb_fname_cpath
= synthetic_smb_fname(talloc_tos(), path
, NULL
, NULL
);
1223 if (smb_fname_cpath
== NULL
) {
1228 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_cpath
) != 0) {
1232 /* avoid chmod() if possible, to preserve acls */
1233 if ((smb_fname_cpath
->st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1237 rc
= gpfsacl_emu_chmod(handle
, path
, mode
);
1239 return SMB_VFS_NEXT_CHMOD(handle
, path
, mode
);
1243 static int vfs_gpfs_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
1248 if (SMB_VFS_NEXT_FSTAT(handle
, fsp
, &st
) != 0) {
1252 /* avoid chmod() if possible, to preserve acls */
1253 if ((st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1257 rc
= gpfsacl_emu_chmod(handle
, fsp
->fsp_name
->base_name
,
1260 return SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
1264 static int gpfs_set_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1265 const char *name
, const void *value
, size_t size
, int flags
){
1266 struct xattr_DOSATTRIB dosattrib
;
1267 enum ndr_err_code ndr_err
;
1269 const char *attrstr
= value
;
1270 unsigned int dosmode
=0;
1271 struct gpfs_winattr attrs
;
1273 struct gpfs_config_data
*config
;
1275 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1276 struct gpfs_config_data
,
1279 if (!config
->winattr
) {
1280 DEBUG(10, ("gpfs_set_xattr:name is %s -> next\n",name
));
1281 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1284 DEBUG(10, ("gpfs_set_xattr: %s \n",path
));
1286 /* Only handle DOS Attributes */
1287 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1288 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name
));
1289 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1292 blob
.data
= (uint8_t *)attrstr
;
1295 ndr_err
= ndr_pull_struct_blob(&blob
, talloc_tos(), &dosattrib
,
1296 (ndr_pull_flags_fn_t
)ndr_pull_xattr_DOSATTRIB
);
1298 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1299 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
1300 "from EA on file %s: Error = %s\n",
1301 path
, ndr_errstr(ndr_err
)));
1305 if (dosattrib
.version
!= 3) {
1306 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
1307 "%d\n", (int)dosattrib
.version
));
1310 if (!(dosattrib
.info
.info3
.valid_flags
& XATTR_DOSINFO_ATTRIB
)) {
1311 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
1312 "valid, ignoring\n"));
1316 dosmode
= dosattrib
.info
.info3
.attrib
;
1319 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
1320 if (dosmode
& FILE_ATTRIBUTE_ARCHIVE
){
1321 attrs
.winAttrs
|= GPFS_WINATTR_ARCHIVE
;
1323 if (dosmode
& FILE_ATTRIBUTE_HIDDEN
){
1324 attrs
.winAttrs
|= GPFS_WINATTR_HIDDEN
;
1326 if (dosmode
& FILE_ATTRIBUTE_SYSTEM
){
1327 attrs
.winAttrs
|= GPFS_WINATTR_SYSTEM
;
1329 if (dosmode
& FILE_ATTRIBUTE_READONLY
){
1330 attrs
.winAttrs
|= GPFS_WINATTR_READONLY
;
1332 if (dosmode
& FILE_ATTRIBUTE_SPARSE
) {
1333 attrs
.winAttrs
|= GPFS_WINATTR_SPARSE_FILE
;
1337 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1338 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1340 if (errno
== ENOSYS
) {
1341 return SMB_VFS_NEXT_SETXATTR(handle
, path
, name
, value
,
1345 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret
));
1349 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs
.winAttrs
));
1353 static ssize_t
gpfs_get_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1354 const char *name
, void *value
, size_t size
){
1355 char *attrstr
= value
;
1356 unsigned int dosmode
= 0;
1357 struct gpfs_winattr attrs
;
1359 struct gpfs_config_data
*config
;
1361 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1362 struct gpfs_config_data
,
1365 if (!config
->winattr
) {
1366 DEBUG(10, ("gpfs_get_xattr:name is %s -> next\n",name
));
1367 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1370 DEBUG(10, ("gpfs_get_xattr: %s \n",path
));
1372 /* Only handle DOS Attributes */
1373 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1374 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name
));
1375 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1378 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1380 if (errno
== ENOSYS
) {
1381 return SMB_VFS_NEXT_GETXATTR(handle
, path
, name
, value
,
1385 DEBUG(1, ("gpfs_get_xattr: Get GPFS attributes failed: "
1386 "%d (%s)\n", ret
, strerror(errno
)));
1390 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs
.winAttrs
));
1392 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1393 if (attrs
.winAttrs
& GPFS_WINATTR_ARCHIVE
){
1394 dosmode
|= FILE_ATTRIBUTE_ARCHIVE
;
1396 if (attrs
.winAttrs
& GPFS_WINATTR_HIDDEN
){
1397 dosmode
|= FILE_ATTRIBUTE_HIDDEN
;
1399 if (attrs
.winAttrs
& GPFS_WINATTR_SYSTEM
){
1400 dosmode
|= FILE_ATTRIBUTE_SYSTEM
;
1402 if (attrs
.winAttrs
& GPFS_WINATTR_READONLY
){
1403 dosmode
|= FILE_ATTRIBUTE_READONLY
;
1405 if (attrs
.winAttrs
& GPFS_WINATTR_SPARSE_FILE
) {
1406 dosmode
|= FILE_ATTRIBUTE_SPARSE
;
1409 snprintf(attrstr
, size
, "0x%2.2x",
1410 (unsigned int)(dosmode
& SAMBA_ATTRIBUTES_MASK
));
1411 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr
));
1415 #if defined(HAVE_FSTATAT)
1416 static int stat_with_capability(struct vfs_handle_struct
*handle
,
1417 struct smb_filename
*smb_fname
, int flag
)
1422 const char *rel_name
= NULL
;
1426 b
= parent_dirname(talloc_tos(), smb_fname
->base_name
,
1427 &dir_name
, &rel_name
);
1433 fd
= open(dir_name
, O_RDONLY
, 0);
1434 TALLOC_FREE(dir_name
);
1439 set_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1440 ret
= fstatat(fd
, rel_name
, &st
, flag
);
1441 drop_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1446 init_stat_ex_from_stat(
1447 &smb_fname
->st
, &st
,
1448 lp_fake_dir_create_times(SNUM(handle
->conn
)));
1455 static int vfs_gpfs_stat(struct vfs_handle_struct
*handle
,
1456 struct smb_filename
*smb_fname
)
1458 struct gpfs_winattr attrs
;
1462 struct gpfs_config_data
*config
;
1464 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1465 struct gpfs_config_data
,
1468 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
1469 #if defined(HAVE_FSTATAT)
1470 if (ret
== -1 && errno
== EACCES
) {
1471 DEBUG(10, ("Trying stat with capability for %s\n",
1472 smb_fname
->base_name
));
1473 ret
= stat_with_capability(handle
, smb_fname
, 0);
1480 if (!config
->winattr
) {
1484 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &fname
);
1485 if (!NT_STATUS_IS_OK(status
)) {
1486 errno
= map_errno_from_nt_status(status
);
1489 ret
= get_gpfs_winattrs(discard_const_p(char, fname
), &attrs
);
1492 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1493 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1494 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1495 smb_fname
->st
.vfs_private
= attrs
.winAttrs
;
1500 static int vfs_gpfs_fstat(struct vfs_handle_struct
*handle
,
1501 struct files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
1503 struct gpfs_winattr attrs
;
1505 struct gpfs_config_data
*config
;
1507 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1508 struct gpfs_config_data
,
1511 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
1515 if ((fsp
->fh
== NULL
) || (fsp
->fh
->fd
== -1)) {
1518 if (!config
->winattr
) {
1522 ret
= smbd_fget_gpfs_winattrs(fsp
->fh
->fd
, &attrs
);
1524 sbuf
->st_ex_calculated_birthtime
= false;
1525 sbuf
->st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1526 sbuf
->st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1531 static int vfs_gpfs_lstat(struct vfs_handle_struct
*handle
,
1532 struct smb_filename
*smb_fname
)
1534 struct gpfs_winattr attrs
;
1538 struct gpfs_config_data
*config
;
1540 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1541 struct gpfs_config_data
,
1544 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
1545 #if defined(HAVE_FSTATAT)
1546 if (ret
== -1 && errno
== EACCES
) {
1547 DEBUG(10, ("Trying lstat with capability for %s\n",
1548 smb_fname
->base_name
));
1549 ret
= stat_with_capability(handle
, smb_fname
,
1550 AT_SYMLINK_NOFOLLOW
);
1557 if (!config
->winattr
) {
1561 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1562 if (!NT_STATUS_IS_OK(status
)) {
1563 errno
= map_errno_from_nt_status(status
);
1566 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1569 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1570 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1571 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1572 smb_fname
->st
.vfs_private
= attrs
.winAttrs
;
1577 static int vfs_gpfs_ntimes(struct vfs_handle_struct
*handle
,
1578 const struct smb_filename
*smb_fname
,
1579 struct smb_file_time
*ft
)
1582 struct gpfs_winattr attrs
;
1586 struct gpfs_config_data
*config
;
1588 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1589 struct gpfs_config_data
,
1592 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1593 if (!NT_STATUS_IS_OK(status
)) {
1594 errno
= map_errno_from_nt_status(status
);
1598 /* Try to use gpfs_set_times if it is enabled and available */
1599 if (config
->settimes
) {
1600 ret
= smbd_gpfs_set_times_path(path
, ft
);
1602 if (ret
== 0 || (ret
== -1 && errno
!= ENOSYS
)) {
1607 DEBUG(10,("gpfs_set_times() not available or disabled, "
1608 "use ntimes and winattr\n"));
1610 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1612 /* don't complain if access was denied */
1613 if (errno
!= EPERM
&& errno
!= EACCES
) {
1614 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1615 "%s", strerror(errno
)));
1620 if(null_timespec(ft
->create_time
)){
1621 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1625 if (!config
->winattr
) {
1630 attrs
.creationTime
.tv_sec
= ft
->create_time
.tv_sec
;
1631 attrs
.creationTime
.tv_nsec
= ft
->create_time
.tv_nsec
;
1633 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1634 GPFS_WINATTR_SET_CREATION_TIME
, &attrs
);
1635 if(ret
== -1 && errno
!= ENOSYS
){
1636 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret
));
1643 static int vfs_gpfs_fallocate(struct vfs_handle_struct
*handle
,
1644 struct files_struct
*fsp
, enum vfs_fallocate_mode mode
,
1645 off_t offset
, off_t len
)
1648 struct gpfs_config_data
*config
;
1650 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1651 struct gpfs_config_data
,
1654 if (!config
->prealloc
) {
1655 /* you should better not run fallocate() on GPFS at all */
1660 if (mode
== VFS_FALLOCATE_KEEP_SIZE
) {
1661 DEBUG(10, ("Unsupported VFS_FALLOCATE_KEEP_SIZE\n"));
1666 ret
= smbd_gpfs_prealloc(fsp
->fh
->fd
, offset
, len
);
1668 if (ret
== -1 && errno
!= ENOSYS
) {
1669 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno
)));
1670 } else if (ret
== -1 && errno
== ENOSYS
) {
1671 DEBUG(10, ("GPFS prealloc not supported.\n"));
1673 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1679 static int vfs_gpfs_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1683 struct gpfs_config_data
*config
;
1685 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1686 struct gpfs_config_data
,
1689 if (!config
->ftruncate
) {
1690 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1693 result
= smbd_gpfs_ftruncate(fsp
->fh
->fd
, len
);
1694 if ((result
== -1) && (errno
== ENOSYS
)) {
1695 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1700 static bool vfs_gpfs_is_offline(struct vfs_handle_struct
*handle
,
1701 const struct smb_filename
*fname
,
1702 SMB_STRUCT_STAT
*sbuf
)
1704 struct gpfs_winattr attrs
;
1707 struct gpfs_config_data
*config
;
1709 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1710 struct gpfs_config_data
,
1713 if (!config
->winattr
) {
1714 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1717 status
= get_full_smb_filename(talloc_tos(), fname
, &path
);
1718 if (!NT_STATUS_IS_OK(status
)) {
1719 errno
= map_errno_from_nt_status(status
);
1723 if (VALID_STAT(*sbuf
)) {
1724 attrs
.winAttrs
= sbuf
->vfs_private
;
1727 ret
= get_gpfs_winattrs(path
, &attrs
);
1734 if ((attrs
.winAttrs
& GPFS_WINATTR_OFFLINE
) != 0) {
1735 DEBUG(10, ("%s is offline\n", path
));
1739 DEBUG(10, ("%s is online\n", path
));
1741 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1744 static bool vfs_gpfs_aio_force(struct vfs_handle_struct
*handle
,
1745 struct files_struct
*fsp
)
1747 return vfs_gpfs_is_offline(handle
, fsp
->fsp_name
, &fsp
->fsp_name
->st
);
1750 static ssize_t
vfs_gpfs_sendfile(vfs_handle_struct
*handle
, int tofd
,
1751 files_struct
*fsp
, const DATA_BLOB
*hdr
,
1752 off_t offset
, size_t n
)
1754 if ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0) {
1758 return SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fsp
, hdr
, offset
, n
);
1761 static int vfs_gpfs_connect(struct vfs_handle_struct
*handle
,
1762 const char *service
, const char *user
)
1764 struct gpfs_config_data
*config
;
1767 smbd_gpfs_lib_init();
1769 config
= talloc_zero(handle
->conn
, struct gpfs_config_data
);
1771 DEBUG(0, ("talloc_zero() failed\n"));
1776 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1778 TALLOC_FREE(config
);
1782 config
->sharemodes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1783 "sharemodes", true);
1785 config
->leases
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1788 config
->hsm
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1791 config
->syncio
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1794 config
->winattr
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1797 config
->ftruncate
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1800 config
->getrealfilename
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1801 "getrealfilename", true);
1803 config
->dfreequota
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1804 "dfreequota", false);
1806 config
->prealloc
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1809 config
->acl
= lp_parm_bool(SNUM(handle
->conn
), "gpfs", "acl", true);
1811 config
->settimes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1814 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
1815 NULL
, struct gpfs_config_data
,
1818 if (config
->leases
) {
1820 * GPFS lease code is based on kernel oplock code
1821 * so make sure it is turned on
1823 if (!lp_kernel_oplocks(SNUM(handle
->conn
))) {
1824 DEBUG(5, ("Enabling kernel oplocks for "
1825 "gpfs:leases to work\n"));
1826 lp_do_parameter(SNUM(handle
->conn
), "kernel oplocks",
1831 * as the kernel does not properly support Level II oplocks
1832 * and GPFS leases code is based on kernel infrastructure, we
1833 * need to turn off Level II oplocks if gpfs:leases is enabled
1835 if (lp_level2_oplocks(SNUM(handle
->conn
))) {
1836 DEBUG(5, ("gpfs:leases are enabled, disabling "
1837 "Level II oplocks\n"));
1838 lp_do_parameter(SNUM(handle
->conn
), "level2 oplocks",
1846 static int vfs_gpfs_get_quotas(const char *path
, uid_t uid
, gid_t gid
,
1848 struct gpfs_quotaInfo
*qi_user
,
1849 struct gpfs_quotaInfo
*qi_group
,
1850 struct gpfs_quotaInfo
*qi_fset
)
1857 * We want to always use the directory to get the fileset id,
1858 * because files might have a share mode. We also do not want
1859 * to get the parent directory when there is already a
1860 * directory to avoid stepping in a different fileset. The
1861 * path passed here is currently either "." or a filename, so
1862 * this is ok. The proper solution would be having a way to
1863 * query the fileset id without opening the file.
1865 b
= parent_dirname(talloc_tos(), path
, &dir_path
, NULL
);
1871 DEBUG(10, ("path %s, directory %s\n", path
, dir_path
));
1873 err
= get_gpfs_fset_id(dir_path
, fset_id
);
1875 DEBUG(0, ("Get fset id failed path %s, dir %s, errno %d.\n",
1876 path
, dir_path
, errno
));
1880 err
= get_gpfs_quota(path
, GPFS_USRQUOTA
, uid
, qi_user
);
1885 err
= get_gpfs_quota(path
, GPFS_GRPQUOTA
, gid
, qi_group
);
1890 err
= get_gpfs_quota(path
, GPFS_FILESETQUOTA
, *fset_id
, qi_fset
);
1898 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi
, time_t cur_time
,
1899 uint64_t *dfree
, uint64_t *dsize
)
1901 uint64_t usage
, limit
;
1904 * The quota reporting is done in units of 1024 byte blocks, but
1905 * sys_fsusage uses units of 512 byte blocks, adjust the block number
1906 * accordingly. Also filter possibly negative usage counts from gpfs.
1908 usage
= qi
.blockUsage
< 0 ? 0 : (uint64_t)qi
.blockUsage
* 2;
1909 limit
= (uint64_t)qi
.blockHardLimit
* 2;
1912 * When the grace time for the exceeded soft block quota has been
1913 * exceeded, the soft block quota becomes an additional hard limit.
1915 if (qi
.blockSoftLimit
&&
1916 qi
.blockGraceTime
&& cur_time
> qi
.blockGraceTime
) {
1917 /* report disk as full */
1919 *dsize
= MIN(*dsize
, usage
);
1922 if (!qi
.blockHardLimit
)
1925 if (usage
>= limit
) {
1926 /* report disk as full */
1928 *dsize
= MIN(*dsize
, usage
);
1931 /* limit has not been reached, determine "free space" */
1932 *dfree
= MIN(*dfree
, limit
- usage
);
1933 *dsize
= MIN(*dsize
, limit
);
1937 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct
*handle
, const char *path
,
1938 bool small_query
, uint64_t *bsize
,
1939 uint64_t *dfree
, uint64_t *dsize
)
1941 struct security_unix_token
*utok
;
1942 struct gpfs_quotaInfo qi_user
, qi_group
, qi_fset
;
1943 struct gpfs_config_data
*config
;
1947 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct gpfs_config_data
,
1948 return (uint64_t)-1);
1949 if (!config
->dfreequota
) {
1950 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1951 bsize
, dfree
, dsize
);
1954 err
= sys_fsusage(path
, dfree
, dsize
);
1956 DEBUG (0, ("Could not get fs usage, errno %d\n", errno
));
1957 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1958 bsize
, dfree
, dsize
);
1961 /* sys_fsusage returns units of 512 bytes */
1964 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
1965 (unsigned long long)*dfree
, (unsigned long long)*dsize
));
1967 utok
= handle
->conn
->session_info
->unix_token
;
1968 err
= vfs_gpfs_get_quotas(path
, utok
->uid
, utok
->gid
, &fset_id
,
1969 &qi_user
, &qi_group
, &qi_fset
);
1971 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1972 bsize
, dfree
, dsize
);
1975 cur_time
= time(NULL
);
1977 /* Adjust free space and size according to quota limits. */
1978 vfs_gpfs_disk_free_quota(qi_user
, cur_time
, dfree
, dsize
);
1979 vfs_gpfs_disk_free_quota(qi_group
, cur_time
, dfree
, dsize
);
1981 /* Id 0 indicates the default quota, not an actual quota */
1983 vfs_gpfs_disk_free_quota(qi_fset
, cur_time
, dfree
, dsize
);
1986 disk_norm(small_query
, bsize
, dfree
, dsize
);
1990 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct
*handle
,
1991 enum timestamp_set_resolution
*p_ts_res
)
1993 struct gpfs_config_data
*config
;
1996 next
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
1998 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1999 struct gpfs_config_data
,
2003 next
|= FILE_SUPPORTS_REMOTE_STORAGE
;
2008 static int vfs_gpfs_open(struct vfs_handle_struct
*handle
,
2009 struct smb_filename
*smb_fname
, files_struct
*fsp
,
2010 int flags
, mode_t mode
)
2012 struct gpfs_config_data
*config
;
2014 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2015 struct gpfs_config_data
,
2018 if (config
->syncio
) {
2021 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
2024 static ssize_t
vfs_gpfs_pread(vfs_handle_struct
*handle
, files_struct
*fsp
,
2025 void *data
, size_t n
, off_t offset
)
2029 ret
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
2031 DEBUG(10, ("vfs_private = %x\n",
2032 (unsigned int)fsp
->fsp_name
->st
.vfs_private
));
2035 ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0)) {
2036 fsp
->fsp_name
->st
.vfs_private
&= ~GPFS_WINATTR_OFFLINE
;
2037 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2038 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2039 fsp
->fsp_name
->base_name
);
2045 struct vfs_gpfs_pread_state
{
2046 struct files_struct
*fsp
;
2051 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
);
2053 static struct tevent_req
*vfs_gpfs_pread_send(struct vfs_handle_struct
*handle
,
2054 TALLOC_CTX
*mem_ctx
,
2055 struct tevent_context
*ev
,
2056 struct files_struct
*fsp
,
2057 void *data
, size_t n
,
2060 struct tevent_req
*req
, *subreq
;
2061 struct vfs_gpfs_pread_state
*state
;
2063 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pread_state
);
2068 subreq
= SMB_VFS_NEXT_PREAD_SEND(state
, ev
, handle
, fsp
, data
,
2070 if (tevent_req_nomem(subreq
, req
)) {
2071 return tevent_req_post(req
, ev
);
2073 tevent_req_set_callback(subreq
, vfs_gpfs_pread_done
, req
);
2077 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
)
2079 struct tevent_req
*req
= tevent_req_callback_data(
2080 subreq
, struct tevent_req
);
2081 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2082 req
, struct vfs_gpfs_pread_state
);
2084 state
->ret
= SMB_VFS_PREAD_RECV(subreq
, &state
->err
);
2085 TALLOC_FREE(subreq
);
2086 tevent_req_done(req
);
2089 static ssize_t
vfs_gpfs_pread_recv(struct tevent_req
*req
, int *err
)
2091 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2092 req
, struct vfs_gpfs_pread_state
);
2093 struct files_struct
*fsp
= state
->fsp
;
2095 if (tevent_req_is_unix_error(req
, err
)) {
2100 DEBUG(10, ("vfs_private = %x\n",
2101 (unsigned int)fsp
->fsp_name
->st
.vfs_private
));
2103 if ((state
->ret
!= -1) &&
2104 ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0)) {
2105 fsp
->fsp_name
->st
.vfs_private
&= ~GPFS_WINATTR_OFFLINE
;
2106 DEBUG(10, ("sending notify\n"));
2107 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2108 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2109 fsp
->fsp_name
->base_name
);
2115 static ssize_t
vfs_gpfs_pwrite(vfs_handle_struct
*handle
, files_struct
*fsp
,
2116 const void *data
, size_t n
, off_t offset
)
2120 ret
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
2122 DEBUG(10, ("vfs_private = %x\n",
2123 (unsigned int)fsp
->fsp_name
->st
.vfs_private
));
2126 ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0)) {
2127 fsp
->fsp_name
->st
.vfs_private
&= ~GPFS_WINATTR_OFFLINE
;
2128 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2129 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2130 fsp
->fsp_name
->base_name
);
2136 struct vfs_gpfs_pwrite_state
{
2137 struct files_struct
*fsp
;
2142 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
);
2144 static struct tevent_req
*vfs_gpfs_pwrite_send(
2145 struct vfs_handle_struct
*handle
,
2146 TALLOC_CTX
*mem_ctx
,
2147 struct tevent_context
*ev
,
2148 struct files_struct
*fsp
,
2149 const void *data
, size_t n
,
2152 struct tevent_req
*req
, *subreq
;
2153 struct vfs_gpfs_pwrite_state
*state
;
2155 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pwrite_state
);
2160 subreq
= SMB_VFS_NEXT_PWRITE_SEND(state
, ev
, handle
, fsp
, data
,
2162 if (tevent_req_nomem(subreq
, req
)) {
2163 return tevent_req_post(req
, ev
);
2165 tevent_req_set_callback(subreq
, vfs_gpfs_pwrite_done
, req
);
2169 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
)
2171 struct tevent_req
*req
= tevent_req_callback_data(
2172 subreq
, struct tevent_req
);
2173 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2174 req
, struct vfs_gpfs_pwrite_state
);
2176 state
->ret
= SMB_VFS_PWRITE_RECV(subreq
, &state
->err
);
2177 TALLOC_FREE(subreq
);
2178 tevent_req_done(req
);
2181 static ssize_t
vfs_gpfs_pwrite_recv(struct tevent_req
*req
, int *err
)
2183 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2184 req
, struct vfs_gpfs_pwrite_state
);
2185 struct files_struct
*fsp
= state
->fsp
;
2187 if (tevent_req_is_unix_error(req
, err
)) {
2192 DEBUG(10, ("vfs_private = %x\n",
2193 (unsigned int)fsp
->fsp_name
->st
.vfs_private
));
2195 if ((state
->ret
!= -1) &&
2196 ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0)) {
2197 fsp
->fsp_name
->st
.vfs_private
&= ~GPFS_WINATTR_OFFLINE
;
2198 DEBUG(10, ("sending notify\n"));
2199 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2200 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2201 fsp
->fsp_name
->base_name
);
2208 static struct vfs_fn_pointers vfs_gpfs_fns
= {
2209 .connect_fn
= vfs_gpfs_connect
,
2210 .disk_free_fn
= vfs_gpfs_disk_free
,
2211 .fs_capabilities_fn
= vfs_gpfs_capabilities
,
2212 .kernel_flock_fn
= vfs_gpfs_kernel_flock
,
2213 .linux_setlease_fn
= vfs_gpfs_setlease
,
2214 .get_real_filename_fn
= vfs_gpfs_get_real_filename
,
2215 .fget_nt_acl_fn
= gpfsacl_fget_nt_acl
,
2216 .get_nt_acl_fn
= gpfsacl_get_nt_acl
,
2217 .fset_nt_acl_fn
= gpfsacl_fset_nt_acl
,
2218 .sys_acl_get_file_fn
= gpfsacl_sys_acl_get_file
,
2219 .sys_acl_get_fd_fn
= gpfsacl_sys_acl_get_fd
,
2220 .sys_acl_blob_get_file_fn
= gpfsacl_sys_acl_blob_get_file
,
2221 .sys_acl_blob_get_fd_fn
= gpfsacl_sys_acl_blob_get_fd
,
2222 .sys_acl_set_file_fn
= gpfsacl_sys_acl_set_file
,
2223 .sys_acl_set_fd_fn
= gpfsacl_sys_acl_set_fd
,
2224 .sys_acl_delete_def_file_fn
= gpfsacl_sys_acl_delete_def_file
,
2225 .chmod_fn
= vfs_gpfs_chmod
,
2226 .fchmod_fn
= vfs_gpfs_fchmod
,
2227 .close_fn
= vfs_gpfs_close
,
2228 .setxattr_fn
= gpfs_set_xattr
,
2229 .getxattr_fn
= gpfs_get_xattr
,
2230 .stat_fn
= vfs_gpfs_stat
,
2231 .fstat_fn
= vfs_gpfs_fstat
,
2232 .lstat_fn
= vfs_gpfs_lstat
,
2233 .ntimes_fn
= vfs_gpfs_ntimes
,
2234 .is_offline_fn
= vfs_gpfs_is_offline
,
2235 .aio_force_fn
= vfs_gpfs_aio_force
,
2236 .sendfile_fn
= vfs_gpfs_sendfile
,
2237 .fallocate_fn
= vfs_gpfs_fallocate
,
2238 .open_fn
= vfs_gpfs_open
,
2239 .pread_fn
= vfs_gpfs_pread
,
2240 .pread_send_fn
= vfs_gpfs_pread_send
,
2241 .pread_recv_fn
= vfs_gpfs_pread_recv
,
2242 .pwrite_fn
= vfs_gpfs_pwrite
,
2243 .pwrite_send_fn
= vfs_gpfs_pwrite_send
,
2244 .pwrite_recv_fn
= vfs_gpfs_pwrite_recv
,
2245 .ftruncate_fn
= vfs_gpfs_ftruncate
2248 NTSTATUS
vfs_gpfs_init(void);
2249 NTSTATUS
vfs_gpfs_init(void)
2253 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "gpfs",