2 Unix SMB/CIFS implementation.
3 Wrap gpfs calls in vfs functions.
5 Copyright (C) Christian Ambach <cambach1@de.ibm.com> 2006
7 Major code contributions by Chetan Shringarpure <chetan.sh@in.ibm.com>
8 and Gomati Mohanan <gomati.mohanan@in.ibm.com>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "smbd/smbd.h"
26 #include "librpc/gen_ndr/ndr_xattr.h"
27 #include "include/smbprofile.h"
28 #include "modules/non_posix_acls.h"
31 #define DBGC_CLASS DBGC_VFS
34 #include "nfs4_acls.h"
36 #include "system/filesys.h"
38 #include "lib/util/tevent_unix.h"
40 struct gpfs_config_data
{
54 static int vfs_gpfs_kernel_flock(vfs_handle_struct
*handle
, files_struct
*fsp
,
55 uint32 share_mode
, uint32 access_mask
)
58 struct gpfs_config_data
*config
;
61 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
62 struct gpfs_config_data
,
65 if(!config
->sharemodes
) {
69 START_PROFILE(syscall_kernel_flock
);
71 kernel_flock(fsp
->fh
->fd
, share_mode
, access_mask
);
73 if (!set_gpfs_sharemode(fsp
, access_mask
, fsp
->share_access
)) {
77 END_PROFILE(syscall_kernel_flock
);
82 static int vfs_gpfs_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
85 struct gpfs_config_data
*config
;
87 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
88 struct gpfs_config_data
,
91 if (config
->sharemodes
&& (fsp
->fh
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
92 set_gpfs_sharemode(fsp
, 0, 0);
95 return SMB_VFS_NEXT_CLOSE(handle
, fsp
);
98 static int vfs_gpfs_setlease(vfs_handle_struct
*handle
, files_struct
*fsp
,
101 struct gpfs_config_data
*config
;
104 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
105 struct gpfs_config_data
,
108 if (linux_set_lease_sighandler(fsp
->fh
->fd
) == -1)
111 START_PROFILE(syscall_linux_setlease
);
113 if (config
->leases
) {
115 * Ensure the lease owner is root to allow
116 * correct delivery of lease-break signals.
119 ret
= set_gpfs_lease(fsp
->fh
->fd
,leasetype
);
123 END_PROFILE(syscall_linux_setlease
);
128 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct
*handle
,
136 char real_pathname
[PATH_MAX
+1];
139 struct gpfs_config_data
*config
;
141 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
142 struct gpfs_config_data
,
145 if (!config
->getrealfilename
) {
146 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
147 mem_ctx
, found_name
);
150 mangled
= mangle_is_mangled(name
, handle
->conn
->params
);
152 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
153 mem_ctx
, found_name
);
156 full_path
= talloc_asprintf(talloc_tos(), "%s/%s", path
, name
);
157 if (full_path
== NULL
) {
162 buflen
= sizeof(real_pathname
) - 1;
164 result
= smbd_gpfs_get_realfilename_path(full_path
, real_pathname
,
167 TALLOC_FREE(full_path
);
169 if ((result
== -1) && (errno
== ENOSYS
)) {
170 return SMB_VFS_NEXT_GET_REAL_FILENAME(
171 handle
, path
, name
, mem_ctx
, found_name
);
175 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
181 * GPFS does not necessarily null-terminate the returned path
182 * but instead returns the buffer length in buflen.
185 if (buflen
< sizeof(real_pathname
)) {
186 real_pathname
[buflen
] = '\0';
188 real_pathname
[sizeof(real_pathname
)-1] = '\0';
191 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
192 path
, name
, real_pathname
));
194 name
= strrchr_m(real_pathname
, '/');
200 *found_name
= talloc_strdup(mem_ctx
, name
+1);
201 if (*found_name
== NULL
) {
209 static void gpfs_dumpacl(int level
, struct gpfs_acl
*gacl
)
214 DEBUG(0, ("gpfs acl is NULL\n"));
218 DEBUG(level
, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n",
219 gacl
->acl_nace
, gacl
->acl_type
, gacl
->acl_version
, gacl
->acl_level
, gacl
->acl_len
));
220 for(i
=0; i
<gacl
->acl_nace
; i
++)
222 struct gpfs_ace_v4
*gace
= gacl
->ace_v4
+ i
;
223 DEBUG(level
, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n",
224 i
, gace
->aceType
, gace
->aceFlags
, gace
->aceMask
,
225 gace
->aceIFlags
, gace
->aceWho
));
230 * get the ACL from GPFS, allocated on the specified mem_ctx
231 * internally retries when initial buffer was too small
233 * caller needs to cast result to either
234 * raw = yes: struct gpfs_opaque_acl
235 * raw = no: struct gpfs_acl
238 static void *vfs_gpfs_getacl(TALLOC_CTX
*mem_ctx
,
241 const gpfs_aclType_t type
)
252 aclbuf
= talloc_zero_size(mem_ctx
, size
);
253 if (aclbuf
== NULL
) {
259 struct gpfs_opaque_acl
*buf
= (struct gpfs_opaque_acl
*) aclbuf
;
260 buf
->acl_type
= type
;
261 flags
= GPFS_GETACL_NATIVE
;
262 len
= (unsigned int *) &(buf
->acl_buffer_len
);
263 struct_size
= sizeof(struct gpfs_opaque_acl
);
265 struct gpfs_acl
*buf
= (struct gpfs_acl
*) aclbuf
;
266 buf
->acl_type
= type
;
267 flags
= GPFS_GETACL_STRUCT
;
268 len
= &(buf
->acl_len
);
269 struct_size
= sizeof(struct gpfs_acl
);
272 /* set the length of the buffer as input value */
276 ret
= smbd_gpfs_getacl((char *)fname
, flags
, aclbuf
);
277 if ((ret
!= 0) && (errno
== ENOSPC
)) {
279 * get the size needed to accommodate the complete buffer
281 * the value returned only applies to the ACL blob in the
282 * struct so make sure to also have headroom for the first
283 * struct members by adding room for the complete struct
284 * (might be a few bytes too much then)
286 size
= *len
+ struct_size
;
288 DEBUG(10, ("Increasing ACL buffer size to %zu\n", size
));
293 DEBUG(5, ("smbd_gpfs_getacl failed with %s\n",
302 /* Tries to get nfs4 acls and returns SMB ACL allocated.
303 * On failure returns 1 if it got non-NFSv4 ACL to prompt
304 * retry with POSIX ACL checks.
305 * On failure returns -1 if there is system (GPFS) error, check errno.
306 * Returns 0 on success
308 static int gpfs_get_nfs4_acl(TALLOC_CTX
*mem_ctx
, const char *fname
, SMB4ACL_T
**ppacl
)
311 struct gpfs_acl
*gacl
= NULL
;
312 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname
));
315 gacl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(), fname
,
318 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
319 fname
, strerror(errno
)));
323 if (gacl
->acl_type
!= GPFS_ACL_TYPE_NFS4
) {
324 DEBUG(10, ("Got non-nfsv4 acl\n"));
325 /* Retry with POSIX ACLs check */
330 *ppacl
= smb_create_smb4acl(mem_ctx
);
332 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
333 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
336 for (i
=0; i
<gacl
->acl_nace
; i
++) {
337 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[i
];
338 SMB_ACE4PROP_T smbace
;
339 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
340 "who: %d\n", gace
->aceType
, gace
->aceIFlags
,
341 gace
->aceFlags
, gace
->aceMask
, gace
->aceWho
));
344 if (gace
->aceIFlags
& ACE4_IFLAG_SPECIAL_ID
) {
345 smbace
.flags
|= SMB_ACE4_ID_SPECIAL
;
346 switch (gace
->aceWho
) {
347 case ACE4_SPECIAL_OWNER
:
348 smbace
.who
.special_id
= SMB_ACE4_WHO_OWNER
;
350 case ACE4_SPECIAL_GROUP
:
351 smbace
.who
.special_id
= SMB_ACE4_WHO_GROUP
;
353 case ACE4_SPECIAL_EVERYONE
:
354 smbace
.who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
357 DEBUG(8, ("invalid special gpfs id %d "
358 "ignored\n", gace
->aceWho
));
359 continue; /* don't add it */
362 if (gace
->aceFlags
& ACE4_FLAG_GROUP_ID
)
363 smbace
.who
.gid
= gace
->aceWho
;
365 smbace
.who
.uid
= gace
->aceWho
;
368 /* remove redundant deny entries */
369 if (i
> 0 && gace
->aceType
== SMB_ACE4_ACCESS_DENIED_ACE_TYPE
) {
370 struct gpfs_ace_v4
*prev
= &gacl
->ace_v4
[i
-1];
371 if (prev
->aceType
== SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
&&
372 prev
->aceFlags
== gace
->aceFlags
&&
373 prev
->aceIFlags
== gace
->aceIFlags
&&
374 (gace
->aceMask
& prev
->aceMask
) == 0 &&
375 gace
->aceWho
== prev
->aceWho
) {
376 /* it's redundant - skip it */
381 smbace
.aceType
= gace
->aceType
;
382 smbace
.aceFlags
= gace
->aceFlags
;
383 smbace
.aceMask
= gace
->aceMask
;
384 smb_add_ace4(*ppacl
, &smbace
);
392 static NTSTATUS
gpfsacl_fget_nt_acl(vfs_handle_struct
*handle
,
393 files_struct
*fsp
, uint32 security_info
,
395 struct security_descriptor
**ppdesc
)
397 SMB4ACL_T
*pacl
= NULL
;
399 struct gpfs_config_data
*config
;
400 TALLOC_CTX
*frame
= talloc_stackframe();
405 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
406 struct gpfs_config_data
,
407 return NT_STATUS_INTERNAL_ERROR
);
410 status
= SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
416 result
= gpfs_get_nfs4_acl(frame
, fsp
->fsp_name
->base_name
, &pacl
);
419 status
= smb_fget_nt_acl_nfs4(fsp
, security_info
, mem_ctx
,
426 DEBUG(10, ("retrying with posix acl...\n"));
427 status
= posix_fget_nt_acl(fsp
, security_info
,
435 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
436 return map_nt_error_from_unix(errno
);
439 static NTSTATUS
gpfsacl_get_nt_acl(vfs_handle_struct
*handle
,
441 uint32 security_info
,
442 TALLOC_CTX
*mem_ctx
, struct security_descriptor
**ppdesc
)
444 SMB4ACL_T
*pacl
= NULL
;
446 struct gpfs_config_data
*config
;
447 TALLOC_CTX
*frame
= talloc_stackframe();
452 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
453 struct gpfs_config_data
,
454 return NT_STATUS_INTERNAL_ERROR
);
457 status
= SMB_VFS_NEXT_GET_NT_ACL(handle
, name
, security_info
,
463 result
= gpfs_get_nfs4_acl(frame
, name
, &pacl
);
466 status
= smb_get_nt_acl_nfs4(handle
->conn
, name
, security_info
,
467 mem_ctx
, ppdesc
, pacl
);
473 DEBUG(10, ("retrying with posix acl...\n"));
474 status
= posix_get_nt_acl(handle
->conn
, name
, security_info
,
480 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
482 return map_nt_error_from_unix(errno
);
485 static bool gpfsacl_process_smbacl(vfs_handle_struct
*handle
, files_struct
*fsp
, SMB4ACL_T
*smbacl
)
488 gpfs_aclLen_t gacl_len
;
490 struct gpfs_acl
*gacl
;
491 TALLOC_CTX
*mem_ctx
= talloc_tos();
493 gacl_len
= offsetof(gpfs_acl_t
, ace_v4
) + smb_get_naces(smbacl
) *
494 sizeof(gpfs_ace_v4_t
);
496 gacl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, gacl_len
);
498 DEBUG(0, ("talloc failed\n"));
503 gacl
->acl_len
= gacl_len
;
505 gacl
->acl_version
= GPFS_ACL_VERSION_NFS4
;
506 gacl
->acl_type
= GPFS_ACL_TYPE_NFS4
;
507 gacl
->acl_nace
= 0; /* change later... */
509 for (smbace
=smb_first_ace4(smbacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
510 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[gacl
->acl_nace
];
511 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
513 gace
->aceType
= aceprop
->aceType
;
514 gace
->aceFlags
= aceprop
->aceFlags
;
515 gace
->aceMask
= aceprop
->aceMask
;
518 * GPFS can't distinguish between WRITE and APPEND on
519 * files, so one being set without the other is an
520 * error. Sorry for the many ()'s :-)
523 if (!fsp
->is_directory
525 ((((gace
->aceMask
& ACE4_MASK_WRITE
) == 0)
526 && ((gace
->aceMask
& ACE4_MASK_APPEND
) != 0))
528 (((gace
->aceMask
& ACE4_MASK_WRITE
) != 0)
529 && ((gace
->aceMask
& ACE4_MASK_APPEND
) == 0)))
531 lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
532 "merge_writeappend", True
)) {
533 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
534 "WRITE^APPEND, setting WRITE|APPEND\n",
536 gace
->aceMask
|= ACE4_MASK_WRITE
|ACE4_MASK_APPEND
;
539 gace
->aceIFlags
= (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
) ? ACE4_IFLAG_SPECIAL_ID
: 0;
541 if (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
)
543 switch(aceprop
->who
.special_id
)
545 case SMB_ACE4_WHO_EVERYONE
:
546 gace
->aceWho
= ACE4_SPECIAL_EVERYONE
;
548 case SMB_ACE4_WHO_OWNER
:
549 gace
->aceWho
= ACE4_SPECIAL_OWNER
;
551 case SMB_ACE4_WHO_GROUP
:
552 gace
->aceWho
= ACE4_SPECIAL_GROUP
;
555 DEBUG(8, ("unsupported special_id %d\n", aceprop
->who
.special_id
));
556 continue; /* don't add it !!! */
559 /* just only for the type safety... */
560 if (aceprop
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)
561 gace
->aceWho
= aceprop
->who
.gid
;
563 gace
->aceWho
= aceprop
->who
.uid
;
569 ret
= smbd_gpfs_putacl(fsp
->fsp_name
->base_name
,
570 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gacl
);
572 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno
)));
573 gpfs_dumpacl(8, gacl
);
577 DEBUG(10, ("gpfs_putacl succeeded\n"));
581 static NTSTATUS
gpfsacl_set_nt_acl_internal(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
583 struct gpfs_acl
*acl
;
584 NTSTATUS result
= NT_STATUS_ACCESS_DENIED
;
586 acl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(),
587 fsp
->fsp_name
->base_name
,
590 return map_nt_error_from_unix(errno
);
593 if (acl
->acl_version
== GPFS_ACL_VERSION_NFS4
) {
594 if (lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
595 "refuse_dacl_protected", false)
596 && (psd
->type
&SEC_DESC_DACL_PROTECTED
)) {
597 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
599 return NT_STATUS_NOT_SUPPORTED
;
602 result
= smb_set_nt_acl_nfs4(handle
,
603 fsp
, security_info_sent
, psd
,
604 gpfsacl_process_smbacl
);
605 } else { /* assume POSIX ACL - by default... */
606 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
613 static NTSTATUS
gpfsacl_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
615 struct gpfs_config_data
*config
;
617 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
618 struct gpfs_config_data
,
619 return NT_STATUS_INTERNAL_ERROR
);
622 return SMB_VFS_NEXT_FSET_NT_ACL(handle
, fsp
, security_info_sent
, psd
);
625 return gpfsacl_set_nt_acl_internal(handle
, fsp
, security_info_sent
, psd
);
628 static SMB_ACL_T
gpfs2smb_acl(const struct gpfs_acl
*pacl
, TALLOC_CTX
*mem_ctx
)
633 result
= sys_acl_init(mem_ctx
);
634 if (result
== NULL
) {
639 result
->count
= pacl
->acl_nace
;
640 result
->acl
= talloc_realloc(result
, result
->acl
, struct smb_acl_entry
,
642 if (result
->acl
== NULL
) {
648 for (i
=0; i
<pacl
->acl_nace
; i
++) {
649 struct smb_acl_entry
*ace
= &result
->acl
[i
];
650 const struct gpfs_ace_v1
*g_ace
= &pacl
->ace_v1
[i
];
652 DEBUG(10, ("Converting type %d id %lu perm %x\n",
653 (int)g_ace
->ace_type
, (unsigned long)g_ace
->ace_who
,
654 (int)g_ace
->ace_perm
));
656 switch (g_ace
->ace_type
) {
658 ace
->a_type
= SMB_ACL_USER
;
659 ace
->info
.user
.uid
= (uid_t
)g_ace
->ace_who
;
661 case GPFS_ACL_USER_OBJ
:
662 ace
->a_type
= SMB_ACL_USER_OBJ
;
665 ace
->a_type
= SMB_ACL_GROUP
;
666 ace
->info
.group
.gid
= (gid_t
)g_ace
->ace_who
;
668 case GPFS_ACL_GROUP_OBJ
:
669 ace
->a_type
= SMB_ACL_GROUP_OBJ
;
672 ace
->a_type
= SMB_ACL_OTHER
;
675 ace
->a_type
= SMB_ACL_MASK
;
678 DEBUG(10, ("Got invalid ace_type: %d\n",
686 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_READ
) ?
688 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_WRITE
) ?
690 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_EXECUTE
) ?
693 DEBUGADD(10, ("Converted to %d perm %x\n",
694 ace
->a_type
, ace
->a_perm
));
700 static SMB_ACL_T
gpfsacl_get_posix_acl(const char *path
, gpfs_aclType_t type
,
703 struct gpfs_acl
*pacl
;
704 SMB_ACL_T result
= NULL
;
706 pacl
= vfs_gpfs_getacl(talloc_tos(), path
, false, type
);
709 DEBUG(10, ("vfs_gpfs_getacl failed for %s with %s\n",
710 path
, strerror(errno
)));
717 if (pacl
->acl_version
!= GPFS_ACL_VERSION_POSIX
) {
718 DEBUG(10, ("Got acl version %d, expected %d\n",
719 pacl
->acl_version
, GPFS_ACL_VERSION_POSIX
));
724 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
725 pacl
->acl_len
, pacl
->acl_level
, pacl
->acl_version
,
728 result
= gpfs2smb_acl(pacl
, mem_ctx
);
729 if (result
!= NULL
) {
744 static SMB_ACL_T
gpfsacl_sys_acl_get_file(vfs_handle_struct
*handle
,
749 gpfs_aclType_t gpfs_type
;
750 struct gpfs_config_data
*config
;
752 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
753 struct gpfs_config_data
,
757 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle
, path_p
,
762 case SMB_ACL_TYPE_ACCESS
:
763 gpfs_type
= GPFS_ACL_TYPE_ACCESS
;
765 case SMB_ACL_TYPE_DEFAULT
:
766 gpfs_type
= GPFS_ACL_TYPE_DEFAULT
;
769 DEBUG(0, ("Got invalid type: %d\n", type
));
770 smb_panic("exiting");
773 return gpfsacl_get_posix_acl(path_p
, gpfs_type
, mem_ctx
);
776 static SMB_ACL_T
gpfsacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
780 struct gpfs_config_data
*config
;
782 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
783 struct gpfs_config_data
,
787 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle
, fsp
, mem_ctx
);
790 return gpfsacl_get_posix_acl(fsp
->fsp_name
->base_name
,
791 GPFS_ACL_TYPE_ACCESS
, mem_ctx
);
794 static int gpfsacl_sys_acl_blob_get_file(vfs_handle_struct
*handle
,
797 char **blob_description
,
800 struct gpfs_config_data
*config
;
801 struct gpfs_opaque_acl
*acl
= NULL
;
805 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
806 struct gpfs_config_data
,
810 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle
, path_p
,
817 acl
= (struct gpfs_opaque_acl
*)
818 vfs_gpfs_getacl(mem_ctx
,
824 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
825 errno
, strerror(errno
)));
827 /* EINVAL means POSIX ACL, bail out on other cases */
828 if (errno
!= EINVAL
) {
837 * we only need the actual ACL blob here
838 * acl_version will always be NFS4 because we asked
840 * acl_type is only used for POSIX ACLs
842 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
843 aclblob
.length
= acl
->acl_buffer_len
;
845 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
846 if (!*blob_description
) {
852 result
= non_posix_sys_acl_blob_get_file_helper(handle
, path_p
,
860 /* fall back to POSIX ACL */
861 return posix_sys_acl_blob_get_file(handle
, path_p
, mem_ctx
,
862 blob_description
, blob
);
865 static int gpfsacl_sys_acl_blob_get_fd(vfs_handle_struct
*handle
,
868 char **blob_description
,
871 struct gpfs_config_data
*config
;
872 struct gpfs_opaque_acl
*acl
= NULL
;
876 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
877 struct gpfs_config_data
,
881 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle
, fsp
, mem_ctx
,
882 blob_description
, blob
);
886 acl
= (struct gpfs_opaque_acl
*) vfs_gpfs_getacl(mem_ctx
,
887 fsp
->fsp_name
->base_name
,
892 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
893 errno
, strerror(errno
)));
895 /* EINVAL means POSIX ACL, bail out on other cases */
896 if (errno
!= EINVAL
) {
905 * we only need the actual ACL blob here
906 * acl_version will always be NFS4 because we asked
908 * acl_type is only used for POSIX ACLs
910 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
911 aclblob
.length
= acl
->acl_buffer_len
;
913 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
914 if (!*blob_description
) {
920 result
= non_posix_sys_acl_blob_get_fd_helper(handle
, fsp
,
928 /* fall back to POSIX ACL */
929 return posix_sys_acl_blob_get_fd(handle
, fsp
, mem_ctx
,
930 blob_description
, blob
);
933 static struct gpfs_acl
*smb2gpfs_acl(const SMB_ACL_T pacl
,
937 struct gpfs_acl
*result
;
940 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl
->count
));
942 len
= offsetof(gpfs_acl_t
, ace_v1
) + (pacl
->count
) *
943 sizeof(gpfs_ace_v1_t
);
945 result
= (struct gpfs_acl
*)SMB_MALLOC(len
);
946 if (result
== NULL
) {
951 result
->acl_len
= len
;
952 result
->acl_level
= 0;
953 result
->acl_version
= GPFS_ACL_VERSION_POSIX
;
954 result
->acl_type
= (type
== SMB_ACL_TYPE_DEFAULT
) ?
955 GPFS_ACL_TYPE_DEFAULT
: GPFS_ACL_TYPE_ACCESS
;
956 result
->acl_nace
= pacl
->count
;
958 for (i
=0; i
<pacl
->count
; i
++) {
959 const struct smb_acl_entry
*ace
= &pacl
->acl
[i
];
960 struct gpfs_ace_v1
*g_ace
= &result
->ace_v1
[i
];
962 DEBUG(10, ("Converting type %d perm %x\n",
963 (int)ace
->a_type
, (int)ace
->a_perm
));
967 switch(ace
->a_type
) {
969 g_ace
->ace_type
= GPFS_ACL_USER
;
970 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.user
.uid
;
972 case SMB_ACL_USER_OBJ
:
973 g_ace
->ace_type
= GPFS_ACL_USER_OBJ
;
974 g_ace
->ace_perm
|= ACL_PERM_CONTROL
;
978 g_ace
->ace_type
= GPFS_ACL_GROUP
;
979 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.group
.gid
;
981 case SMB_ACL_GROUP_OBJ
:
982 g_ace
->ace_type
= GPFS_ACL_GROUP_OBJ
;
986 g_ace
->ace_type
= GPFS_ACL_MASK
;
987 g_ace
->ace_perm
= 0x8f;
991 g_ace
->ace_type
= GPFS_ACL_OTHER
;
995 DEBUG(10, ("Got invalid ace_type: %d\n", ace
->a_type
));
1001 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_READ
) ?
1003 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_WRITE
) ?
1005 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_EXECUTE
) ?
1006 ACL_PERM_EXECUTE
: 0;
1008 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
1009 g_ace
->ace_type
, g_ace
->ace_who
, g_ace
->ace_perm
));
1015 static int gpfsacl_sys_acl_set_file(vfs_handle_struct
*handle
,
1017 SMB_ACL_TYPE_T type
,
1020 struct gpfs_acl
*gpfs_acl
;
1022 struct gpfs_config_data
*config
;
1024 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1025 struct gpfs_config_data
,
1029 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle
, name
, type
, theacl
);
1032 gpfs_acl
= smb2gpfs_acl(theacl
, type
);
1033 if (gpfs_acl
== NULL
) {
1037 result
= smbd_gpfs_putacl((char *)name
, GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gpfs_acl
);
1039 SAFE_FREE(gpfs_acl
);
1043 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
1047 struct gpfs_config_data
*config
;
1049 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1050 struct gpfs_config_data
,
1054 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle
, fsp
, theacl
);
1057 return gpfsacl_sys_acl_set_file(handle
, fsp
->fsp_name
->base_name
,
1058 SMB_ACL_TYPE_ACCESS
, theacl
);
1061 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
1064 struct gpfs_config_data
*config
;
1066 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1067 struct gpfs_config_data
,
1071 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle
, path
);
1079 * Assumed: mode bits are shiftable and standard
1080 * Output: the new aceMask field for an smb nfs4 ace
1082 static uint32
gpfsacl_mask_filter(uint32 aceType
, uint32 aceMask
, uint32 rwx
)
1084 const uint32 posix_nfs4map
[3] = {
1085 SMB_ACE4_EXECUTE
, /* execute */
1086 SMB_ACE4_WRITE_DATA
| SMB_ACE4_APPEND_DATA
, /* write; GPFS specific */
1087 SMB_ACE4_READ_DATA
/* read */
1090 uint32_t posix_mask
= 0x01;
1094 for(i
=0; i
<3; i
++) {
1095 nfs4_bits
= posix_nfs4map
[i
];
1096 posix_bit
= rwx
& posix_mask
;
1098 if (aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
) {
1100 aceMask
|= nfs4_bits
;
1102 aceMask
&= ~nfs4_bits
;
1104 /* add deny bits when suitable */
1106 aceMask
|= nfs4_bits
;
1108 aceMask
&= ~nfs4_bits
;
1109 } /* other ace types are unexpected */
1117 static int gpfsacl_emu_chmod(vfs_handle_struct
*handle
,
1118 const char *path
, mode_t mode
)
1120 SMB4ACL_T
*pacl
= NULL
;
1122 bool haveAllowEntry
[SMB_ACE4_WHO_EVERYONE
+ 1] = {False
, False
, False
, False
};
1124 files_struct fake_fsp
; /* TODO: rationalize parametrization */
1126 TALLOC_CTX
*frame
= talloc_stackframe();
1129 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path
, mode
));
1131 result
= gpfs_get_nfs4_acl(frame
, path
, &pacl
);
1137 if (mode
& ~(S_IRWXU
| S_IRWXG
| S_IRWXO
)) {
1138 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode
, path
));
1141 for (smbace
=smb_first_ace4(pacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
1142 SMB_ACE4PROP_T
*ace
= smb_get_ace4(smbace
);
1143 uint32_t specid
= ace
->who
.special_id
;
1145 if (ace
->flags
&SMB_ACE4_ID_SPECIAL
&&
1146 ace
->aceType
<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE
&&
1147 specid
<= SMB_ACE4_WHO_EVERYONE
) {
1151 if (ace
->aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
)
1152 haveAllowEntry
[specid
] = True
;
1154 /* mode >> 6 for @owner, mode >> 3 for @group,
1155 * mode >> 0 for @everyone */
1156 newMask
= gpfsacl_mask_filter(ace
->aceType
, ace
->aceMask
,
1157 mode
>> ((SMB_ACE4_WHO_EVERYONE
- specid
) * 3));
1158 if (ace
->aceMask
!=newMask
) {
1159 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
1160 path
, ace
->aceMask
, newMask
, specid
));
1162 ace
->aceMask
= newMask
;
1166 /* make sure we have at least ALLOW entries
1167 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
1170 for(i
= SMB_ACE4_WHO_OWNER
; i
<=SMB_ACE4_WHO_EVERYONE
; i
++) {
1173 if (haveAllowEntry
[i
]==True
)
1177 ace
.aceType
= SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
;
1178 ace
.flags
|= SMB_ACE4_ID_SPECIAL
;
1179 ace
.who
.special_id
= i
;
1181 if (i
==SMB_ACE4_WHO_GROUP
) /* not sure it's necessary... */
1182 ace
.aceFlags
|= SMB_ACE4_IDENTIFIER_GROUP
;
1184 ace
.aceMask
= gpfsacl_mask_filter(ace
.aceType
, ace
.aceMask
,
1185 mode
>> ((SMB_ACE4_WHO_EVERYONE
- i
) * 3));
1187 /* don't add unnecessary aces */
1191 /* we add it to the END - as windows expects allow aces */
1192 smb_add_ace4(pacl
, &ace
);
1193 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1194 path
, mode
, i
, ace
.aceMask
));
1197 /* don't add complementary DENY ACEs here */
1198 ZERO_STRUCT(fake_fsp
);
1199 fake_fsp
.fsp_name
= synthetic_smb_fname(
1200 frame
, path
, NULL
, NULL
);
1201 if (fake_fsp
.fsp_name
== NULL
) {
1207 if (gpfsacl_process_smbacl(handle
, &fake_fsp
, pacl
) == False
) {
1213 return 0; /* ok for [f]chmod */
1216 static int vfs_gpfs_chmod(vfs_handle_struct
*handle
, const char *path
, mode_t mode
)
1218 struct smb_filename
*smb_fname_cpath
;
1221 smb_fname_cpath
= synthetic_smb_fname(talloc_tos(), path
, NULL
, NULL
);
1222 if (smb_fname_cpath
== NULL
) {
1227 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_cpath
) != 0) {
1231 /* avoid chmod() if possible, to preserve acls */
1232 if ((smb_fname_cpath
->st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1236 rc
= gpfsacl_emu_chmod(handle
, path
, mode
);
1238 return SMB_VFS_NEXT_CHMOD(handle
, path
, mode
);
1242 static int vfs_gpfs_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
1247 if (SMB_VFS_NEXT_FSTAT(handle
, fsp
, &st
) != 0) {
1251 /* avoid chmod() if possible, to preserve acls */
1252 if ((st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1256 rc
= gpfsacl_emu_chmod(handle
, fsp
->fsp_name
->base_name
,
1259 return SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
1263 static int gpfs_set_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1264 const char *name
, const void *value
, size_t size
, int flags
){
1265 struct xattr_DOSATTRIB dosattrib
;
1266 enum ndr_err_code ndr_err
;
1268 const char *attrstr
= value
;
1269 unsigned int dosmode
=0;
1270 struct gpfs_winattr attrs
;
1272 struct gpfs_config_data
*config
;
1274 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1275 struct gpfs_config_data
,
1278 if (!config
->winattr
) {
1279 DEBUG(10, ("gpfs_set_xattr:name is %s -> next\n",name
));
1280 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1283 DEBUG(10, ("gpfs_set_xattr: %s \n",path
));
1285 /* Only handle DOS Attributes */
1286 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1287 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name
));
1288 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1291 blob
.data
= (uint8_t *)attrstr
;
1294 ndr_err
= ndr_pull_struct_blob(&blob
, talloc_tos(), &dosattrib
,
1295 (ndr_pull_flags_fn_t
)ndr_pull_xattr_DOSATTRIB
);
1297 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1298 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
1299 "from EA on file %s: Error = %s\n",
1300 path
, ndr_errstr(ndr_err
)));
1304 if (dosattrib
.version
!= 3) {
1305 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
1306 "%d\n", (int)dosattrib
.version
));
1309 if (!(dosattrib
.info
.info3
.valid_flags
& XATTR_DOSINFO_ATTRIB
)) {
1310 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
1311 "valid, ignoring\n"));
1315 dosmode
= dosattrib
.info
.info3
.attrib
;
1318 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
1319 if (dosmode
& FILE_ATTRIBUTE_ARCHIVE
){
1320 attrs
.winAttrs
|= GPFS_WINATTR_ARCHIVE
;
1322 if (dosmode
& FILE_ATTRIBUTE_HIDDEN
){
1323 attrs
.winAttrs
|= GPFS_WINATTR_HIDDEN
;
1325 if (dosmode
& FILE_ATTRIBUTE_SYSTEM
){
1326 attrs
.winAttrs
|= GPFS_WINATTR_SYSTEM
;
1328 if (dosmode
& FILE_ATTRIBUTE_READONLY
){
1329 attrs
.winAttrs
|= GPFS_WINATTR_READONLY
;
1331 if (dosmode
& FILE_ATTRIBUTE_SPARSE
) {
1332 attrs
.winAttrs
|= GPFS_WINATTR_SPARSE_FILE
;
1336 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1337 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1339 if (errno
== ENOSYS
) {
1340 return SMB_VFS_NEXT_SETXATTR(handle
, path
, name
, value
,
1344 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret
));
1348 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs
.winAttrs
));
1352 static ssize_t
gpfs_get_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1353 const char *name
, void *value
, size_t size
){
1354 char *attrstr
= value
;
1355 unsigned int dosmode
= 0;
1356 struct gpfs_winattr attrs
;
1358 struct gpfs_config_data
*config
;
1360 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1361 struct gpfs_config_data
,
1364 if (!config
->winattr
) {
1365 DEBUG(10, ("gpfs_get_xattr:name is %s -> next\n",name
));
1366 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1369 DEBUG(10, ("gpfs_get_xattr: %s \n",path
));
1371 /* Only handle DOS Attributes */
1372 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1373 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name
));
1374 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1377 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1379 if (errno
== ENOSYS
) {
1380 return SMB_VFS_NEXT_GETXATTR(handle
, path
, name
, value
,
1384 DEBUG(1, ("gpfs_get_xattr: Get GPFS attributes failed: "
1385 "%d (%s)\n", ret
, strerror(errno
)));
1389 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs
.winAttrs
));
1391 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1392 if (attrs
.winAttrs
& GPFS_WINATTR_ARCHIVE
){
1393 dosmode
|= FILE_ATTRIBUTE_ARCHIVE
;
1395 if (attrs
.winAttrs
& GPFS_WINATTR_HIDDEN
){
1396 dosmode
|= FILE_ATTRIBUTE_HIDDEN
;
1398 if (attrs
.winAttrs
& GPFS_WINATTR_SYSTEM
){
1399 dosmode
|= FILE_ATTRIBUTE_SYSTEM
;
1401 if (attrs
.winAttrs
& GPFS_WINATTR_READONLY
){
1402 dosmode
|= FILE_ATTRIBUTE_READONLY
;
1404 if (attrs
.winAttrs
& GPFS_WINATTR_SPARSE_FILE
) {
1405 dosmode
|= FILE_ATTRIBUTE_SPARSE
;
1408 snprintf(attrstr
, size
, "0x%2.2x",
1409 (unsigned int)(dosmode
& SAMBA_ATTRIBUTES_MASK
));
1410 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr
));
1414 static int vfs_gpfs_stat(struct vfs_handle_struct
*handle
,
1415 struct smb_filename
*smb_fname
)
1417 struct gpfs_winattr attrs
;
1421 struct gpfs_config_data
*config
;
1423 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1424 struct gpfs_config_data
,
1427 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
1432 if (!config
->winattr
) {
1436 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &fname
);
1437 if (!NT_STATUS_IS_OK(status
)) {
1438 errno
= map_errno_from_nt_status(status
);
1441 ret
= get_gpfs_winattrs(discard_const_p(char, fname
), &attrs
);
1444 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1445 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1446 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1451 static int vfs_gpfs_fstat(struct vfs_handle_struct
*handle
,
1452 struct files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
1454 struct gpfs_winattr attrs
;
1456 struct gpfs_config_data
*config
;
1458 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1459 struct gpfs_config_data
,
1462 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
1466 if ((fsp
->fh
== NULL
) || (fsp
->fh
->fd
== -1)) {
1469 if (!config
->winattr
) {
1473 ret
= smbd_fget_gpfs_winattrs(fsp
->fh
->fd
, &attrs
);
1475 sbuf
->st_ex_calculated_birthtime
= false;
1476 sbuf
->st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1477 sbuf
->st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1482 static int vfs_gpfs_lstat(struct vfs_handle_struct
*handle
,
1483 struct smb_filename
*smb_fname
)
1485 struct gpfs_winattr attrs
;
1489 struct gpfs_config_data
*config
;
1491 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1492 struct gpfs_config_data
,
1495 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
1499 if (!config
->winattr
) {
1503 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1504 if (!NT_STATUS_IS_OK(status
)) {
1505 errno
= map_errno_from_nt_status(status
);
1508 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1511 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1512 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1513 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1518 static int vfs_gpfs_ntimes(struct vfs_handle_struct
*handle
,
1519 const struct smb_filename
*smb_fname
,
1520 struct smb_file_time
*ft
)
1523 struct gpfs_winattr attrs
;
1527 struct gpfs_config_data
*config
;
1529 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1530 struct gpfs_config_data
,
1533 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1535 /* don't complain if access was denied */
1536 if (errno
!= EPERM
&& errno
!= EACCES
) {
1537 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1538 "%s", strerror(errno
)));
1543 if(null_timespec(ft
->create_time
)){
1544 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1548 if (!config
->winattr
) {
1552 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1553 if (!NT_STATUS_IS_OK(status
)) {
1554 errno
= map_errno_from_nt_status(status
);
1559 attrs
.creationTime
.tv_sec
= ft
->create_time
.tv_sec
;
1560 attrs
.creationTime
.tv_nsec
= ft
->create_time
.tv_nsec
;
1562 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1563 GPFS_WINATTR_SET_CREATION_TIME
, &attrs
);
1564 if(ret
== -1 && errno
!= ENOSYS
){
1565 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret
));
1572 static int vfs_gpfs_fallocate(struct vfs_handle_struct
*handle
,
1573 struct files_struct
*fsp
, enum vfs_fallocate_mode mode
,
1574 off_t offset
, off_t len
)
1577 struct gpfs_config_data
*config
;
1579 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1580 struct gpfs_config_data
,
1583 if (!config
->prealloc
) {
1584 /* you should better not run fallocate() on GPFS at all */
1589 if (mode
== VFS_FALLOCATE_KEEP_SIZE
) {
1590 DEBUG(10, ("Unsupported VFS_FALLOCATE_KEEP_SIZE\n"));
1595 ret
= smbd_gpfs_prealloc(fsp
->fh
->fd
, offset
, len
);
1597 if (ret
== -1 && errno
!= ENOSYS
) {
1598 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno
)));
1599 } else if (ret
== -1 && errno
== ENOSYS
) {
1600 DEBUG(10, ("GPFS prealloc not supported.\n"));
1602 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1608 static int vfs_gpfs_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1612 struct gpfs_config_data
*config
;
1614 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1615 struct gpfs_config_data
,
1618 if (!config
->ftruncate
) {
1619 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1622 result
= smbd_gpfs_ftruncate(fsp
->fh
->fd
, len
);
1623 if ((result
== -1) && (errno
== ENOSYS
)) {
1624 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1629 static bool vfs_gpfs_is_offline(struct vfs_handle_struct
*handle
,
1630 const struct smb_filename
*fname
,
1631 SMB_STRUCT_STAT
*sbuf
)
1633 struct gpfs_winattr attrs
;
1636 struct gpfs_config_data
*config
;
1639 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1640 struct gpfs_config_data
,
1643 if (!config
->winattr
) {
1644 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1647 status
= get_full_smb_filename(talloc_tos(), fname
, &path
);
1648 if (!NT_STATUS_IS_OK(status
)) {
1649 errno
= map_errno_from_nt_status(status
);
1653 ret
= get_gpfs_winattrs(path
, &attrs
);
1659 if ((attrs
.winAttrs
& GPFS_WINATTR_OFFLINE
) != 0) {
1660 DEBUG(10, ("%s is offline\n", path
));
1664 DEBUG(10, ("%s is online\n", path
));
1666 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1669 static bool vfs_gpfs_aio_force(struct vfs_handle_struct
*handle
,
1670 struct files_struct
*fsp
)
1672 return vfs_gpfs_is_offline(handle
, fsp
->fsp_name
, &fsp
->fsp_name
->st
);
1675 static ssize_t
vfs_gpfs_sendfile(vfs_handle_struct
*handle
, int tofd
,
1676 files_struct
*fsp
, const DATA_BLOB
*hdr
,
1677 off_t offset
, size_t n
)
1679 if (SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
, &fsp
->fsp_name
->st
))
1684 return SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fsp
, hdr
, offset
, n
);
1687 static int vfs_gpfs_connect(struct vfs_handle_struct
*handle
,
1688 const char *service
, const char *user
)
1690 struct gpfs_config_data
*config
;
1693 smbd_gpfs_lib_init();
1695 config
= talloc_zero(handle
->conn
, struct gpfs_config_data
);
1697 DEBUG(0, ("talloc_zero() failed\n"));
1702 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1704 TALLOC_FREE(config
);
1708 config
->sharemodes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1709 "sharemodes", true);
1711 config
->leases
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1714 config
->hsm
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1717 config
->syncio
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1720 config
->winattr
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1723 config
->ftruncate
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1726 config
->getrealfilename
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1727 "getrealfilename", true);
1729 config
->dfreequota
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1730 "dfreequota", false);
1732 config
->prealloc
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1735 config
->acl
= lp_parm_bool(SNUM(handle
->conn
), "gpfs", "acl", true);
1737 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
1738 NULL
, struct gpfs_config_data
,
1741 if (config
->leases
) {
1743 * GPFS lease code is based on kernel oplock code
1744 * so make sure it is turned on
1746 if (!lp_kernel_oplocks(SNUM(handle
->conn
))) {
1747 DEBUG(5, ("Enabling kernel oplocks for "
1748 "gpfs:leases to work\n"));
1749 lp_do_parameter(SNUM(handle
->conn
), "kernel oplocks",
1754 * as the kernel does not properly support Level II oplocks
1755 * and GPFS leases code is based on kernel infrastructure, we
1756 * need to turn off Level II oplocks if gpfs:leases is enabled
1758 if (lp_level2_oplocks(SNUM(handle
->conn
))) {
1759 DEBUG(5, ("gpfs:leases are enabled, disabling "
1760 "Level II oplocks\n"));
1761 lp_do_parameter(SNUM(handle
->conn
), "level2 oplocks",
1769 static int vfs_gpfs_get_quotas(const char *path
, uid_t uid
, gid_t gid
,
1771 struct gpfs_quotaInfo
*qi_user
,
1772 struct gpfs_quotaInfo
*qi_group
,
1773 struct gpfs_quotaInfo
*qi_fset
)
1780 * We want to always use the directory to get the fileset id,
1781 * because files might have a share mode. We also do not want
1782 * to get the parent directory when there is already a
1783 * directory to avoid stepping in a different fileset. The
1784 * path passed here is currently either "." or a filename, so
1785 * this is ok. The proper solution would be having a way to
1786 * query the fileset id without opening the file.
1788 b
= parent_dirname(talloc_tos(), path
, &dir_path
, NULL
);
1794 DEBUG(10, ("path %s, directory %s\n", path
, dir_path
));
1796 err
= get_gpfs_fset_id(dir_path
, fset_id
);
1798 DEBUG(0, ("Get fset id failed path %s, dir %s, errno %d.\n",
1799 path
, dir_path
, errno
));
1803 err
= get_gpfs_quota(path
, GPFS_USRQUOTA
, uid
, qi_user
);
1808 err
= get_gpfs_quota(path
, GPFS_GRPQUOTA
, gid
, qi_group
);
1813 err
= get_gpfs_quota(path
, GPFS_FILESETQUOTA
, *fset_id
, qi_fset
);
1821 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi
, time_t cur_time
,
1822 uint64_t *dfree
, uint64_t *dsize
)
1824 uint64_t usage
, limit
;
1827 * The quota reporting is done in units of 1024 byte blocks, but
1828 * sys_fsusage uses units of 512 byte blocks, adjust the block number
1829 * accordingly. Also filter possibly negative usage counts from gpfs.
1831 usage
= qi
.blockUsage
< 0 ? 0 : (uint64_t)qi
.blockUsage
* 2;
1832 limit
= (uint64_t)qi
.blockHardLimit
* 2;
1835 * When the grace time for the exceeded soft block quota has been
1836 * exceeded, the soft block quota becomes an additional hard limit.
1838 if (qi
.blockSoftLimit
&&
1839 qi
.blockGraceTime
&& cur_time
> qi
.blockGraceTime
) {
1840 /* report disk as full */
1842 *dsize
= MIN(*dsize
, usage
);
1845 if (!qi
.blockHardLimit
)
1848 if (usage
>= limit
) {
1849 /* report disk as full */
1851 *dsize
= MIN(*dsize
, usage
);
1854 /* limit has not been reached, determine "free space" */
1855 *dfree
= MIN(*dfree
, limit
- usage
);
1856 *dsize
= MIN(*dsize
, limit
);
1860 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct
*handle
, const char *path
,
1861 bool small_query
, uint64_t *bsize
,
1862 uint64_t *dfree
, uint64_t *dsize
)
1864 struct security_unix_token
*utok
;
1865 struct gpfs_quotaInfo qi_user
, qi_group
, qi_fset
;
1866 struct gpfs_config_data
*config
;
1870 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct gpfs_config_data
,
1871 return (uint64_t)-1);
1872 if (!config
->dfreequota
) {
1873 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1874 bsize
, dfree
, dsize
);
1877 err
= sys_fsusage(path
, dfree
, dsize
);
1879 DEBUG (0, ("Could not get fs usage, errno %d\n", errno
));
1880 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1881 bsize
, dfree
, dsize
);
1884 /* sys_fsusage returns units of 512 bytes */
1887 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
1888 (unsigned long long)*dfree
, (unsigned long long)*dsize
));
1890 utok
= handle
->conn
->session_info
->unix_token
;
1891 err
= vfs_gpfs_get_quotas(path
, utok
->uid
, utok
->gid
, &fset_id
,
1892 &qi_user
, &qi_group
, &qi_fset
);
1894 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1895 bsize
, dfree
, dsize
);
1898 cur_time
= time(NULL
);
1900 /* Adjust free space and size according to quota limits. */
1901 vfs_gpfs_disk_free_quota(qi_user
, cur_time
, dfree
, dsize
);
1902 vfs_gpfs_disk_free_quota(qi_group
, cur_time
, dfree
, dsize
);
1904 /* Id 0 indicates the default quota, not an actual quota */
1906 vfs_gpfs_disk_free_quota(qi_fset
, cur_time
, dfree
, dsize
);
1909 disk_norm(small_query
, bsize
, dfree
, dsize
);
1913 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct
*handle
,
1914 enum timestamp_set_resolution
*p_ts_res
)
1916 struct gpfs_config_data
*config
;
1919 next
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
1921 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1922 struct gpfs_config_data
,
1926 next
|= FILE_SUPPORTS_REMOTE_STORAGE
;
1931 static int vfs_gpfs_open(struct vfs_handle_struct
*handle
,
1932 struct smb_filename
*smb_fname
, files_struct
*fsp
,
1933 int flags
, mode_t mode
)
1935 struct gpfs_config_data
*config
;
1937 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1938 struct gpfs_config_data
,
1941 if (config
->syncio
) {
1944 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
1947 static ssize_t
vfs_gpfs_pread(vfs_handle_struct
*handle
, files_struct
*fsp
,
1948 void *data
, size_t n
, off_t offset
)
1953 was_offline
= SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
,
1954 &fsp
->fsp_name
->st
);
1956 ret
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
1958 if ((ret
!= -1) && was_offline
) {
1959 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
1960 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
1961 fsp
->fsp_name
->base_name
);
1967 struct vfs_gpfs_pread_state
{
1968 struct files_struct
*fsp
;
1974 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
);
1976 static struct tevent_req
*vfs_gpfs_pread_send(struct vfs_handle_struct
*handle
,
1977 TALLOC_CTX
*mem_ctx
,
1978 struct tevent_context
*ev
,
1979 struct files_struct
*fsp
,
1980 void *data
, size_t n
,
1983 struct tevent_req
*req
, *subreq
;
1984 struct vfs_gpfs_pread_state
*state
;
1986 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pread_state
);
1990 state
->was_offline
= SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
,
1991 &fsp
->fsp_name
->st
);
1993 subreq
= SMB_VFS_NEXT_PREAD_SEND(state
, ev
, handle
, fsp
, data
,
1995 if (tevent_req_nomem(subreq
, req
)) {
1996 return tevent_req_post(req
, ev
);
1998 tevent_req_set_callback(subreq
, vfs_gpfs_pread_done
, req
);
2002 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
)
2004 struct tevent_req
*req
= tevent_req_callback_data(
2005 subreq
, struct tevent_req
);
2006 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2007 req
, struct vfs_gpfs_pread_state
);
2009 state
->ret
= SMB_VFS_PREAD_RECV(subreq
, &state
->err
);
2010 TALLOC_FREE(subreq
);
2011 tevent_req_done(req
);
2014 static ssize_t
vfs_gpfs_pread_recv(struct tevent_req
*req
, int *err
)
2016 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2017 req
, struct vfs_gpfs_pread_state
);
2018 struct files_struct
*fsp
= state
->fsp
;
2020 if (tevent_req_is_unix_error(req
, err
)) {
2025 if ((state
->ret
!= -1) && state
->was_offline
) {
2026 DEBUG(10, ("sending notify\n"));
2027 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2028 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2029 fsp
->fsp_name
->base_name
);
2035 static ssize_t
vfs_gpfs_pwrite(vfs_handle_struct
*handle
, files_struct
*fsp
,
2036 const void *data
, size_t n
, off_t offset
)
2041 was_offline
= SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
,
2042 &fsp
->fsp_name
->st
);
2044 ret
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
2046 if ((ret
!= -1) && was_offline
) {
2047 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2048 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2049 fsp
->fsp_name
->base_name
);
2055 struct vfs_gpfs_pwrite_state
{
2056 struct files_struct
*fsp
;
2062 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
);
2064 static struct tevent_req
*vfs_gpfs_pwrite_send(
2065 struct vfs_handle_struct
*handle
,
2066 TALLOC_CTX
*mem_ctx
,
2067 struct tevent_context
*ev
,
2068 struct files_struct
*fsp
,
2069 const void *data
, size_t n
,
2072 struct tevent_req
*req
, *subreq
;
2073 struct vfs_gpfs_pwrite_state
*state
;
2075 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pwrite_state
);
2079 state
->was_offline
= SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
,
2080 &fsp
->fsp_name
->st
);
2082 subreq
= SMB_VFS_NEXT_PWRITE_SEND(state
, ev
, handle
, fsp
, data
,
2084 if (tevent_req_nomem(subreq
, req
)) {
2085 return tevent_req_post(req
, ev
);
2087 tevent_req_set_callback(subreq
, vfs_gpfs_pwrite_done
, req
);
2091 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
)
2093 struct tevent_req
*req
= tevent_req_callback_data(
2094 subreq
, struct tevent_req
);
2095 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2096 req
, struct vfs_gpfs_pwrite_state
);
2098 state
->ret
= SMB_VFS_PWRITE_RECV(subreq
, &state
->err
);
2099 TALLOC_FREE(subreq
);
2100 tevent_req_done(req
);
2103 static ssize_t
vfs_gpfs_pwrite_recv(struct tevent_req
*req
, int *err
)
2105 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2106 req
, struct vfs_gpfs_pwrite_state
);
2107 struct files_struct
*fsp
= state
->fsp
;
2109 if (tevent_req_is_unix_error(req
, err
)) {
2114 if ((state
->ret
!= -1) && state
->was_offline
) {
2115 DEBUG(10, ("sending notify\n"));
2116 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2117 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2118 fsp
->fsp_name
->base_name
);
2125 static struct vfs_fn_pointers vfs_gpfs_fns
= {
2126 .connect_fn
= vfs_gpfs_connect
,
2127 .disk_free_fn
= vfs_gpfs_disk_free
,
2128 .fs_capabilities_fn
= vfs_gpfs_capabilities
,
2129 .kernel_flock_fn
= vfs_gpfs_kernel_flock
,
2130 .linux_setlease_fn
= vfs_gpfs_setlease
,
2131 .get_real_filename_fn
= vfs_gpfs_get_real_filename
,
2132 .fget_nt_acl_fn
= gpfsacl_fget_nt_acl
,
2133 .get_nt_acl_fn
= gpfsacl_get_nt_acl
,
2134 .fset_nt_acl_fn
= gpfsacl_fset_nt_acl
,
2135 .sys_acl_get_file_fn
= gpfsacl_sys_acl_get_file
,
2136 .sys_acl_get_fd_fn
= gpfsacl_sys_acl_get_fd
,
2137 .sys_acl_blob_get_file_fn
= gpfsacl_sys_acl_blob_get_file
,
2138 .sys_acl_blob_get_fd_fn
= gpfsacl_sys_acl_blob_get_fd
,
2139 .sys_acl_set_file_fn
= gpfsacl_sys_acl_set_file
,
2140 .sys_acl_set_fd_fn
= gpfsacl_sys_acl_set_fd
,
2141 .sys_acl_delete_def_file_fn
= gpfsacl_sys_acl_delete_def_file
,
2142 .chmod_fn
= vfs_gpfs_chmod
,
2143 .fchmod_fn
= vfs_gpfs_fchmod
,
2144 .close_fn
= vfs_gpfs_close
,
2145 .setxattr_fn
= gpfs_set_xattr
,
2146 .getxattr_fn
= gpfs_get_xattr
,
2147 .stat_fn
= vfs_gpfs_stat
,
2148 .fstat_fn
= vfs_gpfs_fstat
,
2149 .lstat_fn
= vfs_gpfs_lstat
,
2150 .ntimes_fn
= vfs_gpfs_ntimes
,
2151 .is_offline_fn
= vfs_gpfs_is_offline
,
2152 .aio_force_fn
= vfs_gpfs_aio_force
,
2153 .sendfile_fn
= vfs_gpfs_sendfile
,
2154 .fallocate_fn
= vfs_gpfs_fallocate
,
2155 .open_fn
= vfs_gpfs_open
,
2156 .pread_fn
= vfs_gpfs_pread
,
2157 .pread_send_fn
= vfs_gpfs_pread_send
,
2158 .pread_recv_fn
= vfs_gpfs_pread_recv
,
2159 .pwrite_fn
= vfs_gpfs_pwrite
,
2160 .pwrite_send_fn
= vfs_gpfs_pwrite_send
,
2161 .pwrite_recv_fn
= vfs_gpfs_pwrite_recv
,
2162 .ftruncate_fn
= vfs_gpfs_ftruncate
2165 NTSTATUS
vfs_gpfs_init(void);
2166 NTSTATUS
vfs_gpfs_init(void)
2170 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "gpfs",