2 Unix SMB/CIFS implementation.
3 Wrap gpfs calls in vfs functions.
5 Copyright (C) Christian Ambach <cambach1@de.ibm.com> 2006
7 Major code contributions by Chetan Shringarpure <chetan.sh@in.ibm.com>
8 and Gomati Mohanan <gomati.mohanan@in.ibm.com>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "smbd/smbd.h"
26 #include "librpc/gen_ndr/ndr_xattr.h"
27 #include "include/smbprofile.h"
28 #include "modules/non_posix_acls.h"
31 #define DBGC_CLASS DBGC_VFS
34 #include "nfs4_acls.h"
36 #include "system/filesys.h"
38 #include "lib/util/tevent_unix.h"
40 struct gpfs_config_data
{
54 static int vfs_gpfs_kernel_flock(vfs_handle_struct
*handle
, files_struct
*fsp
,
55 uint32 share_mode
, uint32 access_mask
)
58 struct gpfs_config_data
*config
;
61 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
62 struct gpfs_config_data
,
65 if(!config
->sharemodes
) {
70 * A named stream fsp will have the basefile open in the fsp
71 * fd, so lacking a distinct fd for the stream we have to skip
72 * kernel_flock and set_gpfs_sharemode for stream.
74 if (!is_ntfs_default_stream_smb_fname(fsp
->fsp_name
)) {
75 DEBUG(2,("%s: kernel_flock on stream\n", fsp_str_dbg(fsp
)));
79 START_PROFILE(syscall_kernel_flock
);
81 kernel_flock(fsp
->fh
->fd
, share_mode
, access_mask
);
83 if (!set_gpfs_sharemode(fsp
, access_mask
, fsp
->share_access
)) {
87 END_PROFILE(syscall_kernel_flock
);
92 static int vfs_gpfs_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
95 struct gpfs_config_data
*config
;
97 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
98 struct gpfs_config_data
,
101 if (config
->sharemodes
&& (fsp
->fh
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
102 set_gpfs_sharemode(fsp
, 0, 0);
105 return SMB_VFS_NEXT_CLOSE(handle
, fsp
);
108 static int vfs_gpfs_setlease(vfs_handle_struct
*handle
, files_struct
*fsp
,
111 struct gpfs_config_data
*config
;
114 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
115 struct gpfs_config_data
,
118 if (linux_set_lease_sighandler(fsp
->fh
->fd
) == -1)
121 START_PROFILE(syscall_linux_setlease
);
123 if (config
->leases
) {
125 * Ensure the lease owner is root to allow
126 * correct delivery of lease-break signals.
129 ret
= set_gpfs_lease(fsp
->fh
->fd
,leasetype
);
133 END_PROFILE(syscall_linux_setlease
);
138 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct
*handle
,
146 char real_pathname
[PATH_MAX
+1];
149 struct gpfs_config_data
*config
;
151 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
152 struct gpfs_config_data
,
155 if (!config
->getrealfilename
) {
156 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
157 mem_ctx
, found_name
);
160 mangled
= mangle_is_mangled(name
, handle
->conn
->params
);
162 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
163 mem_ctx
, found_name
);
166 full_path
= talloc_asprintf(talloc_tos(), "%s/%s", path
, name
);
167 if (full_path
== NULL
) {
172 buflen
= sizeof(real_pathname
) - 1;
174 result
= smbd_gpfs_get_realfilename_path(full_path
, real_pathname
,
177 TALLOC_FREE(full_path
);
179 if ((result
== -1) && (errno
== ENOSYS
)) {
180 return SMB_VFS_NEXT_GET_REAL_FILENAME(
181 handle
, path
, name
, mem_ctx
, found_name
);
185 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
191 * GPFS does not necessarily null-terminate the returned path
192 * but instead returns the buffer length in buflen.
195 if (buflen
< sizeof(real_pathname
)) {
196 real_pathname
[buflen
] = '\0';
198 real_pathname
[sizeof(real_pathname
)-1] = '\0';
201 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
202 path
, name
, real_pathname
));
204 name
= strrchr_m(real_pathname
, '/');
210 *found_name
= talloc_strdup(mem_ctx
, name
+1);
211 if (*found_name
== NULL
) {
219 static void gpfs_dumpacl(int level
, struct gpfs_acl
*gacl
)
224 DEBUG(0, ("gpfs acl is NULL\n"));
228 DEBUG(level
, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n",
229 gacl
->acl_nace
, gacl
->acl_type
, gacl
->acl_version
, gacl
->acl_level
, gacl
->acl_len
));
230 for(i
=0; i
<gacl
->acl_nace
; i
++)
232 struct gpfs_ace_v4
*gace
= gacl
->ace_v4
+ i
;
233 DEBUG(level
, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n",
234 i
, gace
->aceType
, gace
->aceFlags
, gace
->aceMask
,
235 gace
->aceIFlags
, gace
->aceWho
));
240 * get the ACL from GPFS, allocated on the specified mem_ctx
241 * internally retries when initial buffer was too small
243 * caller needs to cast result to either
244 * raw = yes: struct gpfs_opaque_acl
245 * raw = no: struct gpfs_acl
248 static void *vfs_gpfs_getacl(TALLOC_CTX
*mem_ctx
,
251 const gpfs_aclType_t type
)
262 aclbuf
= talloc_zero_size(mem_ctx
, size
);
263 if (aclbuf
== NULL
) {
269 struct gpfs_opaque_acl
*buf
= (struct gpfs_opaque_acl
*) aclbuf
;
270 buf
->acl_type
= type
;
271 flags
= GPFS_GETACL_NATIVE
;
272 len
= (unsigned int *) &(buf
->acl_buffer_len
);
273 struct_size
= sizeof(struct gpfs_opaque_acl
);
275 struct gpfs_acl
*buf
= (struct gpfs_acl
*) aclbuf
;
276 buf
->acl_type
= type
;
277 flags
= GPFS_GETACL_STRUCT
;
278 len
= &(buf
->acl_len
);
279 struct_size
= sizeof(struct gpfs_acl
);
282 /* set the length of the buffer as input value */
286 ret
= smbd_gpfs_getacl((char *)fname
, flags
, aclbuf
);
287 if ((ret
!= 0) && (errno
== ENOSPC
)) {
289 * get the size needed to accommodate the complete buffer
291 * the value returned only applies to the ACL blob in the
292 * struct so make sure to also have headroom for the first
293 * struct members by adding room for the complete struct
294 * (might be a few bytes too much then)
296 size
= *len
+ struct_size
;
298 DEBUG(10, ("Increasing ACL buffer size to %zu\n", size
));
303 DEBUG(5, ("smbd_gpfs_getacl failed with %s\n",
312 /* Tries to get nfs4 acls and returns SMB ACL allocated.
313 * On failure returns 1 if it got non-NFSv4 ACL to prompt
314 * retry with POSIX ACL checks.
315 * On failure returns -1 if there is system (GPFS) error, check errno.
316 * Returns 0 on success
318 static int gpfs_get_nfs4_acl(TALLOC_CTX
*mem_ctx
, const char *fname
, SMB4ACL_T
**ppacl
)
321 struct gpfs_acl
*gacl
= NULL
;
322 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname
));
325 gacl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(), fname
,
328 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
329 fname
, strerror(errno
)));
333 if (gacl
->acl_type
!= GPFS_ACL_TYPE_NFS4
) {
334 DEBUG(10, ("Got non-nfsv4 acl\n"));
335 /* Retry with POSIX ACLs check */
340 *ppacl
= smb_create_smb4acl(mem_ctx
);
342 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
343 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
346 for (i
=0; i
<gacl
->acl_nace
; i
++) {
347 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[i
];
348 SMB_ACE4PROP_T smbace
;
349 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
350 "who: %d\n", gace
->aceType
, gace
->aceIFlags
,
351 gace
->aceFlags
, gace
->aceMask
, gace
->aceWho
));
354 if (gace
->aceIFlags
& ACE4_IFLAG_SPECIAL_ID
) {
355 smbace
.flags
|= SMB_ACE4_ID_SPECIAL
;
356 switch (gace
->aceWho
) {
357 case ACE4_SPECIAL_OWNER
:
358 smbace
.who
.special_id
= SMB_ACE4_WHO_OWNER
;
360 case ACE4_SPECIAL_GROUP
:
361 smbace
.who
.special_id
= SMB_ACE4_WHO_GROUP
;
363 case ACE4_SPECIAL_EVERYONE
:
364 smbace
.who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
367 DEBUG(8, ("invalid special gpfs id %d "
368 "ignored\n", gace
->aceWho
));
369 continue; /* don't add it */
372 if (gace
->aceFlags
& ACE4_FLAG_GROUP_ID
)
373 smbace
.who
.gid
= gace
->aceWho
;
375 smbace
.who
.uid
= gace
->aceWho
;
378 /* remove redundant deny entries */
379 if (i
> 0 && gace
->aceType
== SMB_ACE4_ACCESS_DENIED_ACE_TYPE
) {
380 struct gpfs_ace_v4
*prev
= &gacl
->ace_v4
[i
-1];
381 if (prev
->aceType
== SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
&&
382 prev
->aceFlags
== gace
->aceFlags
&&
383 prev
->aceIFlags
== gace
->aceIFlags
&&
384 (gace
->aceMask
& prev
->aceMask
) == 0 &&
385 gace
->aceWho
== prev
->aceWho
) {
386 /* it's redundant - skip it */
391 smbace
.aceType
= gace
->aceType
;
392 smbace
.aceFlags
= gace
->aceFlags
;
393 smbace
.aceMask
= gace
->aceMask
;
394 smb_add_ace4(*ppacl
, &smbace
);
402 static NTSTATUS
gpfsacl_fget_nt_acl(vfs_handle_struct
*handle
,
403 files_struct
*fsp
, uint32 security_info
,
405 struct security_descriptor
**ppdesc
)
407 SMB4ACL_T
*pacl
= NULL
;
409 struct gpfs_config_data
*config
;
410 TALLOC_CTX
*frame
= talloc_stackframe();
415 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
416 struct gpfs_config_data
,
417 return NT_STATUS_INTERNAL_ERROR
);
420 status
= SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
426 result
= gpfs_get_nfs4_acl(frame
, fsp
->fsp_name
->base_name
, &pacl
);
429 status
= smb_fget_nt_acl_nfs4(fsp
, security_info
, mem_ctx
,
436 DEBUG(10, ("retrying with posix acl...\n"));
437 status
= posix_fget_nt_acl(fsp
, security_info
,
445 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
446 return map_nt_error_from_unix(errno
);
449 static NTSTATUS
gpfsacl_get_nt_acl(vfs_handle_struct
*handle
,
451 uint32 security_info
,
452 TALLOC_CTX
*mem_ctx
, struct security_descriptor
**ppdesc
)
454 SMB4ACL_T
*pacl
= NULL
;
456 struct gpfs_config_data
*config
;
457 TALLOC_CTX
*frame
= talloc_stackframe();
462 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
463 struct gpfs_config_data
,
464 return NT_STATUS_INTERNAL_ERROR
);
467 status
= SMB_VFS_NEXT_GET_NT_ACL(handle
, name
, security_info
,
473 result
= gpfs_get_nfs4_acl(frame
, name
, &pacl
);
476 status
= smb_get_nt_acl_nfs4(handle
->conn
, name
, security_info
,
477 mem_ctx
, ppdesc
, pacl
);
483 DEBUG(10, ("retrying with posix acl...\n"));
484 status
= posix_get_nt_acl(handle
->conn
, name
, security_info
,
490 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
492 return map_nt_error_from_unix(errno
);
495 static bool gpfsacl_process_smbacl(vfs_handle_struct
*handle
, files_struct
*fsp
, SMB4ACL_T
*smbacl
)
498 gpfs_aclLen_t gacl_len
;
500 struct gpfs_acl
*gacl
;
501 TALLOC_CTX
*mem_ctx
= talloc_tos();
503 gacl_len
= offsetof(gpfs_acl_t
, ace_v4
) + smb_get_naces(smbacl
) *
504 sizeof(gpfs_ace_v4_t
);
506 gacl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, gacl_len
);
508 DEBUG(0, ("talloc failed\n"));
513 gacl
->acl_len
= gacl_len
;
515 gacl
->acl_version
= GPFS_ACL_VERSION_NFS4
;
516 gacl
->acl_type
= GPFS_ACL_TYPE_NFS4
;
517 gacl
->acl_nace
= 0; /* change later... */
519 for (smbace
=smb_first_ace4(smbacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
520 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[gacl
->acl_nace
];
521 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
523 gace
->aceType
= aceprop
->aceType
;
524 gace
->aceFlags
= aceprop
->aceFlags
;
525 gace
->aceMask
= aceprop
->aceMask
;
528 * GPFS can't distinguish between WRITE and APPEND on
529 * files, so one being set without the other is an
530 * error. Sorry for the many ()'s :-)
533 if (!fsp
->is_directory
535 ((((gace
->aceMask
& ACE4_MASK_WRITE
) == 0)
536 && ((gace
->aceMask
& ACE4_MASK_APPEND
) != 0))
538 (((gace
->aceMask
& ACE4_MASK_WRITE
) != 0)
539 && ((gace
->aceMask
& ACE4_MASK_APPEND
) == 0)))
541 lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
542 "merge_writeappend", True
)) {
543 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
544 "WRITE^APPEND, setting WRITE|APPEND\n",
546 gace
->aceMask
|= ACE4_MASK_WRITE
|ACE4_MASK_APPEND
;
549 gace
->aceIFlags
= (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
) ? ACE4_IFLAG_SPECIAL_ID
: 0;
551 if (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
)
553 switch(aceprop
->who
.special_id
)
555 case SMB_ACE4_WHO_EVERYONE
:
556 gace
->aceWho
= ACE4_SPECIAL_EVERYONE
;
558 case SMB_ACE4_WHO_OWNER
:
559 gace
->aceWho
= ACE4_SPECIAL_OWNER
;
561 case SMB_ACE4_WHO_GROUP
:
562 gace
->aceWho
= ACE4_SPECIAL_GROUP
;
565 DEBUG(8, ("unsupported special_id %d\n", aceprop
->who
.special_id
));
566 continue; /* don't add it !!! */
569 /* just only for the type safety... */
570 if (aceprop
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)
571 gace
->aceWho
= aceprop
->who
.gid
;
573 gace
->aceWho
= aceprop
->who
.uid
;
579 ret
= smbd_gpfs_putacl(fsp
->fsp_name
->base_name
,
580 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gacl
);
582 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno
)));
583 gpfs_dumpacl(8, gacl
);
587 DEBUG(10, ("gpfs_putacl succeeded\n"));
591 static NTSTATUS
gpfsacl_set_nt_acl_internal(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
593 struct gpfs_acl
*acl
;
594 NTSTATUS result
= NT_STATUS_ACCESS_DENIED
;
596 acl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(),
597 fsp
->fsp_name
->base_name
,
600 return map_nt_error_from_unix(errno
);
603 if (acl
->acl_version
== GPFS_ACL_VERSION_NFS4
) {
604 if (lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
605 "refuse_dacl_protected", false)
606 && (psd
->type
&SEC_DESC_DACL_PROTECTED
)) {
607 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
609 return NT_STATUS_NOT_SUPPORTED
;
612 result
= smb_set_nt_acl_nfs4(handle
,
613 fsp
, security_info_sent
, psd
,
614 gpfsacl_process_smbacl
);
615 } else { /* assume POSIX ACL - by default... */
616 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
623 static NTSTATUS
gpfsacl_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
625 struct gpfs_config_data
*config
;
627 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
628 struct gpfs_config_data
,
629 return NT_STATUS_INTERNAL_ERROR
);
632 return SMB_VFS_NEXT_FSET_NT_ACL(handle
, fsp
, security_info_sent
, psd
);
635 return gpfsacl_set_nt_acl_internal(handle
, fsp
, security_info_sent
, psd
);
638 static SMB_ACL_T
gpfs2smb_acl(const struct gpfs_acl
*pacl
, TALLOC_CTX
*mem_ctx
)
643 result
= sys_acl_init(mem_ctx
);
644 if (result
== NULL
) {
649 result
->count
= pacl
->acl_nace
;
650 result
->acl
= talloc_realloc(result
, result
->acl
, struct smb_acl_entry
,
652 if (result
->acl
== NULL
) {
658 for (i
=0; i
<pacl
->acl_nace
; i
++) {
659 struct smb_acl_entry
*ace
= &result
->acl
[i
];
660 const struct gpfs_ace_v1
*g_ace
= &pacl
->ace_v1
[i
];
662 DEBUG(10, ("Converting type %d id %lu perm %x\n",
663 (int)g_ace
->ace_type
, (unsigned long)g_ace
->ace_who
,
664 (int)g_ace
->ace_perm
));
666 switch (g_ace
->ace_type
) {
668 ace
->a_type
= SMB_ACL_USER
;
669 ace
->info
.user
.uid
= (uid_t
)g_ace
->ace_who
;
671 case GPFS_ACL_USER_OBJ
:
672 ace
->a_type
= SMB_ACL_USER_OBJ
;
675 ace
->a_type
= SMB_ACL_GROUP
;
676 ace
->info
.group
.gid
= (gid_t
)g_ace
->ace_who
;
678 case GPFS_ACL_GROUP_OBJ
:
679 ace
->a_type
= SMB_ACL_GROUP_OBJ
;
682 ace
->a_type
= SMB_ACL_OTHER
;
685 ace
->a_type
= SMB_ACL_MASK
;
688 DEBUG(10, ("Got invalid ace_type: %d\n",
696 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_READ
) ?
698 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_WRITE
) ?
700 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_EXECUTE
) ?
703 DEBUGADD(10, ("Converted to %d perm %x\n",
704 ace
->a_type
, ace
->a_perm
));
710 static SMB_ACL_T
gpfsacl_get_posix_acl(const char *path
, gpfs_aclType_t type
,
713 struct gpfs_acl
*pacl
;
714 SMB_ACL_T result
= NULL
;
716 pacl
= vfs_gpfs_getacl(talloc_tos(), path
, false, type
);
719 DEBUG(10, ("vfs_gpfs_getacl failed for %s with %s\n",
720 path
, strerror(errno
)));
727 if (pacl
->acl_version
!= GPFS_ACL_VERSION_POSIX
) {
728 DEBUG(10, ("Got acl version %d, expected %d\n",
729 pacl
->acl_version
, GPFS_ACL_VERSION_POSIX
));
734 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
735 pacl
->acl_len
, pacl
->acl_level
, pacl
->acl_version
,
738 result
= gpfs2smb_acl(pacl
, mem_ctx
);
739 if (result
!= NULL
) {
754 static SMB_ACL_T
gpfsacl_sys_acl_get_file(vfs_handle_struct
*handle
,
759 gpfs_aclType_t gpfs_type
;
760 struct gpfs_config_data
*config
;
762 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
763 struct gpfs_config_data
,
767 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle
, path_p
,
772 case SMB_ACL_TYPE_ACCESS
:
773 gpfs_type
= GPFS_ACL_TYPE_ACCESS
;
775 case SMB_ACL_TYPE_DEFAULT
:
776 gpfs_type
= GPFS_ACL_TYPE_DEFAULT
;
779 DEBUG(0, ("Got invalid type: %d\n", type
));
780 smb_panic("exiting");
783 return gpfsacl_get_posix_acl(path_p
, gpfs_type
, mem_ctx
);
786 static SMB_ACL_T
gpfsacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
790 struct gpfs_config_data
*config
;
792 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
793 struct gpfs_config_data
,
797 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle
, fsp
, mem_ctx
);
800 return gpfsacl_get_posix_acl(fsp
->fsp_name
->base_name
,
801 GPFS_ACL_TYPE_ACCESS
, mem_ctx
);
804 static int gpfsacl_sys_acl_blob_get_file(vfs_handle_struct
*handle
,
807 char **blob_description
,
810 struct gpfs_config_data
*config
;
811 struct gpfs_opaque_acl
*acl
= NULL
;
815 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
816 struct gpfs_config_data
,
820 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle
, path_p
,
827 acl
= (struct gpfs_opaque_acl
*)
828 vfs_gpfs_getacl(mem_ctx
,
834 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
835 errno
, strerror(errno
)));
837 /* EINVAL means POSIX ACL, bail out on other cases */
838 if (errno
!= EINVAL
) {
847 * we only need the actual ACL blob here
848 * acl_version will always be NFS4 because we asked
850 * acl_type is only used for POSIX ACLs
852 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
853 aclblob
.length
= acl
->acl_buffer_len
;
855 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
856 if (!*blob_description
) {
862 result
= non_posix_sys_acl_blob_get_file_helper(handle
, path_p
,
870 /* fall back to POSIX ACL */
871 return posix_sys_acl_blob_get_file(handle
, path_p
, mem_ctx
,
872 blob_description
, blob
);
875 static int gpfsacl_sys_acl_blob_get_fd(vfs_handle_struct
*handle
,
878 char **blob_description
,
881 struct gpfs_config_data
*config
;
882 struct gpfs_opaque_acl
*acl
= NULL
;
886 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
887 struct gpfs_config_data
,
891 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle
, fsp
, mem_ctx
,
892 blob_description
, blob
);
896 acl
= (struct gpfs_opaque_acl
*) vfs_gpfs_getacl(mem_ctx
,
897 fsp
->fsp_name
->base_name
,
902 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
903 errno
, strerror(errno
)));
905 /* EINVAL means POSIX ACL, bail out on other cases */
906 if (errno
!= EINVAL
) {
915 * we only need the actual ACL blob here
916 * acl_version will always be NFS4 because we asked
918 * acl_type is only used for POSIX ACLs
920 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
921 aclblob
.length
= acl
->acl_buffer_len
;
923 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
924 if (!*blob_description
) {
930 result
= non_posix_sys_acl_blob_get_fd_helper(handle
, fsp
,
938 /* fall back to POSIX ACL */
939 return posix_sys_acl_blob_get_fd(handle
, fsp
, mem_ctx
,
940 blob_description
, blob
);
943 static struct gpfs_acl
*smb2gpfs_acl(const SMB_ACL_T pacl
,
947 struct gpfs_acl
*result
;
950 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl
->count
));
952 len
= offsetof(gpfs_acl_t
, ace_v1
) + (pacl
->count
) *
953 sizeof(gpfs_ace_v1_t
);
955 result
= (struct gpfs_acl
*)SMB_MALLOC(len
);
956 if (result
== NULL
) {
961 result
->acl_len
= len
;
962 result
->acl_level
= 0;
963 result
->acl_version
= GPFS_ACL_VERSION_POSIX
;
964 result
->acl_type
= (type
== SMB_ACL_TYPE_DEFAULT
) ?
965 GPFS_ACL_TYPE_DEFAULT
: GPFS_ACL_TYPE_ACCESS
;
966 result
->acl_nace
= pacl
->count
;
968 for (i
=0; i
<pacl
->count
; i
++) {
969 const struct smb_acl_entry
*ace
= &pacl
->acl
[i
];
970 struct gpfs_ace_v1
*g_ace
= &result
->ace_v1
[i
];
972 DEBUG(10, ("Converting type %d perm %x\n",
973 (int)ace
->a_type
, (int)ace
->a_perm
));
977 switch(ace
->a_type
) {
979 g_ace
->ace_type
= GPFS_ACL_USER
;
980 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.user
.uid
;
982 case SMB_ACL_USER_OBJ
:
983 g_ace
->ace_type
= GPFS_ACL_USER_OBJ
;
984 g_ace
->ace_perm
|= ACL_PERM_CONTROL
;
988 g_ace
->ace_type
= GPFS_ACL_GROUP
;
989 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.group
.gid
;
991 case SMB_ACL_GROUP_OBJ
:
992 g_ace
->ace_type
= GPFS_ACL_GROUP_OBJ
;
996 g_ace
->ace_type
= GPFS_ACL_MASK
;
997 g_ace
->ace_perm
= 0x8f;
1001 g_ace
->ace_type
= GPFS_ACL_OTHER
;
1005 DEBUG(10, ("Got invalid ace_type: %d\n", ace
->a_type
));
1011 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_READ
) ?
1013 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_WRITE
) ?
1015 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_EXECUTE
) ?
1016 ACL_PERM_EXECUTE
: 0;
1018 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
1019 g_ace
->ace_type
, g_ace
->ace_who
, g_ace
->ace_perm
));
1025 static int gpfsacl_sys_acl_set_file(vfs_handle_struct
*handle
,
1027 SMB_ACL_TYPE_T type
,
1030 struct gpfs_acl
*gpfs_acl
;
1032 struct gpfs_config_data
*config
;
1034 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1035 struct gpfs_config_data
,
1039 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle
, name
, type
, theacl
);
1042 gpfs_acl
= smb2gpfs_acl(theacl
, type
);
1043 if (gpfs_acl
== NULL
) {
1047 result
= smbd_gpfs_putacl((char *)name
, GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gpfs_acl
);
1049 SAFE_FREE(gpfs_acl
);
1053 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
1057 struct gpfs_config_data
*config
;
1059 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1060 struct gpfs_config_data
,
1064 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle
, fsp
, theacl
);
1067 return gpfsacl_sys_acl_set_file(handle
, fsp
->fsp_name
->base_name
,
1068 SMB_ACL_TYPE_ACCESS
, theacl
);
1071 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
1074 struct gpfs_config_data
*config
;
1076 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1077 struct gpfs_config_data
,
1081 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle
, path
);
1089 * Assumed: mode bits are shiftable and standard
1090 * Output: the new aceMask field for an smb nfs4 ace
1092 static uint32
gpfsacl_mask_filter(uint32 aceType
, uint32 aceMask
, uint32 rwx
)
1094 const uint32 posix_nfs4map
[3] = {
1095 SMB_ACE4_EXECUTE
, /* execute */
1096 SMB_ACE4_WRITE_DATA
| SMB_ACE4_APPEND_DATA
, /* write; GPFS specific */
1097 SMB_ACE4_READ_DATA
/* read */
1100 uint32_t posix_mask
= 0x01;
1104 for(i
=0; i
<3; i
++) {
1105 nfs4_bits
= posix_nfs4map
[i
];
1106 posix_bit
= rwx
& posix_mask
;
1108 if (aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
) {
1110 aceMask
|= nfs4_bits
;
1112 aceMask
&= ~nfs4_bits
;
1114 /* add deny bits when suitable */
1116 aceMask
|= nfs4_bits
;
1118 aceMask
&= ~nfs4_bits
;
1119 } /* other ace types are unexpected */
1127 static int gpfsacl_emu_chmod(vfs_handle_struct
*handle
,
1128 const char *path
, mode_t mode
)
1130 SMB4ACL_T
*pacl
= NULL
;
1132 bool haveAllowEntry
[SMB_ACE4_WHO_EVERYONE
+ 1] = {False
, False
, False
, False
};
1134 files_struct fake_fsp
; /* TODO: rationalize parametrization */
1136 TALLOC_CTX
*frame
= talloc_stackframe();
1139 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path
, mode
));
1141 result
= gpfs_get_nfs4_acl(frame
, path
, &pacl
);
1147 if (mode
& ~(S_IRWXU
| S_IRWXG
| S_IRWXO
)) {
1148 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode
, path
));
1151 for (smbace
=smb_first_ace4(pacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
1152 SMB_ACE4PROP_T
*ace
= smb_get_ace4(smbace
);
1153 uint32_t specid
= ace
->who
.special_id
;
1155 if (ace
->flags
&SMB_ACE4_ID_SPECIAL
&&
1156 ace
->aceType
<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE
&&
1157 specid
<= SMB_ACE4_WHO_EVERYONE
) {
1161 if (ace
->aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
)
1162 haveAllowEntry
[specid
] = True
;
1164 /* mode >> 6 for @owner, mode >> 3 for @group,
1165 * mode >> 0 for @everyone */
1166 newMask
= gpfsacl_mask_filter(ace
->aceType
, ace
->aceMask
,
1167 mode
>> ((SMB_ACE4_WHO_EVERYONE
- specid
) * 3));
1168 if (ace
->aceMask
!=newMask
) {
1169 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
1170 path
, ace
->aceMask
, newMask
, specid
));
1172 ace
->aceMask
= newMask
;
1176 /* make sure we have at least ALLOW entries
1177 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
1180 for(i
= SMB_ACE4_WHO_OWNER
; i
<=SMB_ACE4_WHO_EVERYONE
; i
++) {
1183 if (haveAllowEntry
[i
]==True
)
1187 ace
.aceType
= SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
;
1188 ace
.flags
|= SMB_ACE4_ID_SPECIAL
;
1189 ace
.who
.special_id
= i
;
1191 if (i
==SMB_ACE4_WHO_GROUP
) /* not sure it's necessary... */
1192 ace
.aceFlags
|= SMB_ACE4_IDENTIFIER_GROUP
;
1194 ace
.aceMask
= gpfsacl_mask_filter(ace
.aceType
, ace
.aceMask
,
1195 mode
>> ((SMB_ACE4_WHO_EVERYONE
- i
) * 3));
1197 /* don't add unnecessary aces */
1201 /* we add it to the END - as windows expects allow aces */
1202 smb_add_ace4(pacl
, &ace
);
1203 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1204 path
, mode
, i
, ace
.aceMask
));
1207 /* don't add complementary DENY ACEs here */
1208 ZERO_STRUCT(fake_fsp
);
1209 fake_fsp
.fsp_name
= synthetic_smb_fname(
1210 frame
, path
, NULL
, NULL
);
1211 if (fake_fsp
.fsp_name
== NULL
) {
1217 if (gpfsacl_process_smbacl(handle
, &fake_fsp
, pacl
) == False
) {
1223 return 0; /* ok for [f]chmod */
1226 static int vfs_gpfs_chmod(vfs_handle_struct
*handle
, const char *path
, mode_t mode
)
1228 struct smb_filename
*smb_fname_cpath
;
1231 smb_fname_cpath
= synthetic_smb_fname(talloc_tos(), path
, NULL
, NULL
);
1232 if (smb_fname_cpath
== NULL
) {
1237 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_cpath
) != 0) {
1241 /* avoid chmod() if possible, to preserve acls */
1242 if ((smb_fname_cpath
->st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1246 rc
= gpfsacl_emu_chmod(handle
, path
, mode
);
1248 return SMB_VFS_NEXT_CHMOD(handle
, path
, mode
);
1252 static int vfs_gpfs_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
1257 if (SMB_VFS_NEXT_FSTAT(handle
, fsp
, &st
) != 0) {
1261 /* avoid chmod() if possible, to preserve acls */
1262 if ((st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1266 rc
= gpfsacl_emu_chmod(handle
, fsp
->fsp_name
->base_name
,
1269 return SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
1273 static int gpfs_set_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1274 const char *name
, const void *value
, size_t size
, int flags
){
1275 struct xattr_DOSATTRIB dosattrib
;
1276 enum ndr_err_code ndr_err
;
1278 const char *attrstr
= value
;
1279 unsigned int dosmode
=0;
1280 struct gpfs_winattr attrs
;
1282 struct gpfs_config_data
*config
;
1284 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1285 struct gpfs_config_data
,
1288 if (!config
->winattr
) {
1289 DEBUG(10, ("gpfs_set_xattr:name is %s -> next\n",name
));
1290 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1293 DEBUG(10, ("gpfs_set_xattr: %s \n",path
));
1295 /* Only handle DOS Attributes */
1296 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1297 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name
));
1298 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1301 blob
.data
= (uint8_t *)attrstr
;
1304 ndr_err
= ndr_pull_struct_blob(&blob
, talloc_tos(), &dosattrib
,
1305 (ndr_pull_flags_fn_t
)ndr_pull_xattr_DOSATTRIB
);
1307 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1308 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
1309 "from EA on file %s: Error = %s\n",
1310 path
, ndr_errstr(ndr_err
)));
1314 if (dosattrib
.version
!= 3) {
1315 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
1316 "%d\n", (int)dosattrib
.version
));
1319 if (!(dosattrib
.info
.info3
.valid_flags
& XATTR_DOSINFO_ATTRIB
)) {
1320 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
1321 "valid, ignoring\n"));
1325 dosmode
= dosattrib
.info
.info3
.attrib
;
1328 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
1329 if (dosmode
& FILE_ATTRIBUTE_ARCHIVE
){
1330 attrs
.winAttrs
|= GPFS_WINATTR_ARCHIVE
;
1332 if (dosmode
& FILE_ATTRIBUTE_HIDDEN
){
1333 attrs
.winAttrs
|= GPFS_WINATTR_HIDDEN
;
1335 if (dosmode
& FILE_ATTRIBUTE_SYSTEM
){
1336 attrs
.winAttrs
|= GPFS_WINATTR_SYSTEM
;
1338 if (dosmode
& FILE_ATTRIBUTE_READONLY
){
1339 attrs
.winAttrs
|= GPFS_WINATTR_READONLY
;
1341 if (dosmode
& FILE_ATTRIBUTE_SPARSE
) {
1342 attrs
.winAttrs
|= GPFS_WINATTR_SPARSE_FILE
;
1346 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1347 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1349 if (errno
== ENOSYS
) {
1350 return SMB_VFS_NEXT_SETXATTR(handle
, path
, name
, value
,
1354 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret
));
1358 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs
.winAttrs
));
1362 static ssize_t
gpfs_get_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1363 const char *name
, void *value
, size_t size
){
1364 char *attrstr
= value
;
1365 unsigned int dosmode
= 0;
1366 struct gpfs_winattr attrs
;
1368 struct gpfs_config_data
*config
;
1370 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1371 struct gpfs_config_data
,
1374 if (!config
->winattr
) {
1375 DEBUG(10, ("gpfs_get_xattr:name is %s -> next\n",name
));
1376 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1379 DEBUG(10, ("gpfs_get_xattr: %s \n",path
));
1381 /* Only handle DOS Attributes */
1382 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1383 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name
));
1384 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1387 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1389 if (errno
== ENOSYS
) {
1390 return SMB_VFS_NEXT_GETXATTR(handle
, path
, name
, value
,
1394 DEBUG(1, ("gpfs_get_xattr: Get GPFS attributes failed: "
1395 "%d (%s)\n", ret
, strerror(errno
)));
1399 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs
.winAttrs
));
1401 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1402 if (attrs
.winAttrs
& GPFS_WINATTR_ARCHIVE
){
1403 dosmode
|= FILE_ATTRIBUTE_ARCHIVE
;
1405 if (attrs
.winAttrs
& GPFS_WINATTR_HIDDEN
){
1406 dosmode
|= FILE_ATTRIBUTE_HIDDEN
;
1408 if (attrs
.winAttrs
& GPFS_WINATTR_SYSTEM
){
1409 dosmode
|= FILE_ATTRIBUTE_SYSTEM
;
1411 if (attrs
.winAttrs
& GPFS_WINATTR_READONLY
){
1412 dosmode
|= FILE_ATTRIBUTE_READONLY
;
1414 if (attrs
.winAttrs
& GPFS_WINATTR_SPARSE_FILE
) {
1415 dosmode
|= FILE_ATTRIBUTE_SPARSE
;
1418 snprintf(attrstr
, size
, "0x%2.2x",
1419 (unsigned int)(dosmode
& SAMBA_ATTRIBUTES_MASK
));
1420 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr
));
1424 static int vfs_gpfs_stat(struct vfs_handle_struct
*handle
,
1425 struct smb_filename
*smb_fname
)
1427 struct gpfs_winattr attrs
;
1431 struct gpfs_config_data
*config
;
1433 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1434 struct gpfs_config_data
,
1437 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
1442 if (!config
->winattr
) {
1446 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &fname
);
1447 if (!NT_STATUS_IS_OK(status
)) {
1448 errno
= map_errno_from_nt_status(status
);
1451 ret
= get_gpfs_winattrs(discard_const_p(char, fname
), &attrs
);
1454 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1455 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1456 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1461 static int vfs_gpfs_fstat(struct vfs_handle_struct
*handle
,
1462 struct files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
1464 struct gpfs_winattr attrs
;
1466 struct gpfs_config_data
*config
;
1468 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1469 struct gpfs_config_data
,
1472 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
1476 if ((fsp
->fh
== NULL
) || (fsp
->fh
->fd
== -1)) {
1479 if (!config
->winattr
) {
1483 ret
= smbd_fget_gpfs_winattrs(fsp
->fh
->fd
, &attrs
);
1485 sbuf
->st_ex_calculated_birthtime
= false;
1486 sbuf
->st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1487 sbuf
->st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1492 static int vfs_gpfs_lstat(struct vfs_handle_struct
*handle
,
1493 struct smb_filename
*smb_fname
)
1495 struct gpfs_winattr attrs
;
1499 struct gpfs_config_data
*config
;
1501 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1502 struct gpfs_config_data
,
1505 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
1509 if (!config
->winattr
) {
1513 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1514 if (!NT_STATUS_IS_OK(status
)) {
1515 errno
= map_errno_from_nt_status(status
);
1518 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1521 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1522 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1523 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1528 static int vfs_gpfs_ntimes(struct vfs_handle_struct
*handle
,
1529 const struct smb_filename
*smb_fname
,
1530 struct smb_file_time
*ft
)
1533 struct gpfs_winattr attrs
;
1537 struct gpfs_config_data
*config
;
1539 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1540 struct gpfs_config_data
,
1543 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1545 /* don't complain if access was denied */
1546 if (errno
!= EPERM
&& errno
!= EACCES
) {
1547 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1548 "%s", strerror(errno
)));
1553 if(null_timespec(ft
->create_time
)){
1554 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1558 if (!config
->winattr
) {
1562 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1563 if (!NT_STATUS_IS_OK(status
)) {
1564 errno
= map_errno_from_nt_status(status
);
1569 attrs
.creationTime
.tv_sec
= ft
->create_time
.tv_sec
;
1570 attrs
.creationTime
.tv_nsec
= ft
->create_time
.tv_nsec
;
1572 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1573 GPFS_WINATTR_SET_CREATION_TIME
, &attrs
);
1574 if(ret
== -1 && errno
!= ENOSYS
){
1575 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret
));
1582 static int vfs_gpfs_fallocate(struct vfs_handle_struct
*handle
,
1583 struct files_struct
*fsp
, enum vfs_fallocate_mode mode
,
1584 off_t offset
, off_t len
)
1587 struct gpfs_config_data
*config
;
1589 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1590 struct gpfs_config_data
,
1593 if (!config
->prealloc
) {
1594 /* you should better not run fallocate() on GPFS at all */
1599 if (mode
== VFS_FALLOCATE_KEEP_SIZE
) {
1600 DEBUG(10, ("Unsupported VFS_FALLOCATE_KEEP_SIZE\n"));
1605 ret
= smbd_gpfs_prealloc(fsp
->fh
->fd
, offset
, len
);
1607 if (ret
== -1 && errno
!= ENOSYS
) {
1608 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno
)));
1609 } else if (ret
== -1 && errno
== ENOSYS
) {
1610 DEBUG(10, ("GPFS prealloc not supported.\n"));
1612 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1618 static int vfs_gpfs_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1622 struct gpfs_config_data
*config
;
1624 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1625 struct gpfs_config_data
,
1628 if (!config
->ftruncate
) {
1629 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1632 result
= smbd_gpfs_ftruncate(fsp
->fh
->fd
, len
);
1633 if ((result
== -1) && (errno
== ENOSYS
)) {
1634 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1639 static bool vfs_gpfs_is_offline(struct vfs_handle_struct
*handle
,
1640 const struct smb_filename
*fname
,
1641 SMB_STRUCT_STAT
*sbuf
)
1643 struct gpfs_winattr attrs
;
1646 struct gpfs_config_data
*config
;
1649 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1650 struct gpfs_config_data
,
1653 if (!config
->winattr
) {
1654 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1657 status
= get_full_smb_filename(talloc_tos(), fname
, &path
);
1658 if (!NT_STATUS_IS_OK(status
)) {
1659 errno
= map_errno_from_nt_status(status
);
1663 ret
= get_gpfs_winattrs(path
, &attrs
);
1669 if ((attrs
.winAttrs
& GPFS_WINATTR_OFFLINE
) != 0) {
1670 DEBUG(10, ("%s is offline\n", path
));
1674 DEBUG(10, ("%s is online\n", path
));
1676 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1679 static bool vfs_gpfs_aio_force(struct vfs_handle_struct
*handle
,
1680 struct files_struct
*fsp
)
1682 return vfs_gpfs_is_offline(handle
, fsp
->fsp_name
, &fsp
->fsp_name
->st
);
1685 static ssize_t
vfs_gpfs_sendfile(vfs_handle_struct
*handle
, int tofd
,
1686 files_struct
*fsp
, const DATA_BLOB
*hdr
,
1687 off_t offset
, size_t n
)
1689 if (SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
, &fsp
->fsp_name
->st
))
1694 return SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fsp
, hdr
, offset
, n
);
1697 static int vfs_gpfs_connect(struct vfs_handle_struct
*handle
,
1698 const char *service
, const char *user
)
1700 struct gpfs_config_data
*config
;
1703 smbd_gpfs_lib_init();
1705 config
= talloc_zero(handle
->conn
, struct gpfs_config_data
);
1707 DEBUG(0, ("talloc_zero() failed\n"));
1712 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1714 TALLOC_FREE(config
);
1718 config
->sharemodes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1719 "sharemodes", true);
1721 config
->leases
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1724 config
->hsm
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1727 config
->syncio
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1730 config
->winattr
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1733 config
->ftruncate
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1736 config
->getrealfilename
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1737 "getrealfilename", true);
1739 config
->dfreequota
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1740 "dfreequota", false);
1742 config
->prealloc
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1745 config
->acl
= lp_parm_bool(SNUM(handle
->conn
), "gpfs", "acl", true);
1747 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
1748 NULL
, struct gpfs_config_data
,
1751 if (config
->leases
) {
1753 * GPFS lease code is based on kernel oplock code
1754 * so make sure it is turned on
1756 if (!lp_kernel_oplocks(SNUM(handle
->conn
))) {
1757 DEBUG(5, ("Enabling kernel oplocks for "
1758 "gpfs:leases to work\n"));
1759 lp_do_parameter(SNUM(handle
->conn
), "kernel oplocks",
1764 * as the kernel does not properly support Level II oplocks
1765 * and GPFS leases code is based on kernel infrastructure, we
1766 * need to turn off Level II oplocks if gpfs:leases is enabled
1768 if (lp_level2_oplocks(SNUM(handle
->conn
))) {
1769 DEBUG(5, ("gpfs:leases are enabled, disabling "
1770 "Level II oplocks\n"));
1771 lp_do_parameter(SNUM(handle
->conn
), "level2 oplocks",
1779 static int vfs_gpfs_get_quotas(const char *path
, uid_t uid
, gid_t gid
,
1781 struct gpfs_quotaInfo
*qi_user
,
1782 struct gpfs_quotaInfo
*qi_group
,
1783 struct gpfs_quotaInfo
*qi_fset
)
1790 * We want to always use the directory to get the fileset id,
1791 * because files might have a share mode. We also do not want
1792 * to get the parent directory when there is already a
1793 * directory to avoid stepping in a different fileset. The
1794 * path passed here is currently either "." or a filename, so
1795 * this is ok. The proper solution would be having a way to
1796 * query the fileset id without opening the file.
1798 b
= parent_dirname(talloc_tos(), path
, &dir_path
, NULL
);
1804 DEBUG(10, ("path %s, directory %s\n", path
, dir_path
));
1806 err
= get_gpfs_fset_id(dir_path
, fset_id
);
1808 DEBUG(0, ("Get fset id failed path %s, dir %s, errno %d.\n",
1809 path
, dir_path
, errno
));
1813 err
= get_gpfs_quota(path
, GPFS_USRQUOTA
, uid
, qi_user
);
1818 err
= get_gpfs_quota(path
, GPFS_GRPQUOTA
, gid
, qi_group
);
1823 err
= get_gpfs_quota(path
, GPFS_FILESETQUOTA
, *fset_id
, qi_fset
);
1831 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi
, time_t cur_time
,
1832 uint64_t *dfree
, uint64_t *dsize
)
1834 uint64_t usage
, limit
;
1837 * The quota reporting is done in units of 1024 byte blocks, but
1838 * sys_fsusage uses units of 512 byte blocks, adjust the block number
1839 * accordingly. Also filter possibly negative usage counts from gpfs.
1841 usage
= qi
.blockUsage
< 0 ? 0 : (uint64_t)qi
.blockUsage
* 2;
1842 limit
= (uint64_t)qi
.blockHardLimit
* 2;
1845 * When the grace time for the exceeded soft block quota has been
1846 * exceeded, the soft block quota becomes an additional hard limit.
1848 if (qi
.blockSoftLimit
&&
1849 qi
.blockGraceTime
&& cur_time
> qi
.blockGraceTime
) {
1850 /* report disk as full */
1852 *dsize
= MIN(*dsize
, usage
);
1855 if (!qi
.blockHardLimit
)
1858 if (usage
>= limit
) {
1859 /* report disk as full */
1861 *dsize
= MIN(*dsize
, usage
);
1864 /* limit has not been reached, determine "free space" */
1865 *dfree
= MIN(*dfree
, limit
- usage
);
1866 *dsize
= MIN(*dsize
, limit
);
1870 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct
*handle
, const char *path
,
1871 bool small_query
, uint64_t *bsize
,
1872 uint64_t *dfree
, uint64_t *dsize
)
1874 struct security_unix_token
*utok
;
1875 struct gpfs_quotaInfo qi_user
, qi_group
, qi_fset
;
1876 struct gpfs_config_data
*config
;
1880 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct gpfs_config_data
,
1881 return (uint64_t)-1);
1882 if (!config
->dfreequota
) {
1883 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1884 bsize
, dfree
, dsize
);
1887 err
= sys_fsusage(path
, dfree
, dsize
);
1889 DEBUG (0, ("Could not get fs usage, errno %d\n", errno
));
1890 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1891 bsize
, dfree
, dsize
);
1894 /* sys_fsusage returns units of 512 bytes */
1897 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
1898 (unsigned long long)*dfree
, (unsigned long long)*dsize
));
1900 utok
= handle
->conn
->session_info
->unix_token
;
1901 err
= vfs_gpfs_get_quotas(path
, utok
->uid
, utok
->gid
, &fset_id
,
1902 &qi_user
, &qi_group
, &qi_fset
);
1904 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1905 bsize
, dfree
, dsize
);
1908 cur_time
= time(NULL
);
1910 /* Adjust free space and size according to quota limits. */
1911 vfs_gpfs_disk_free_quota(qi_user
, cur_time
, dfree
, dsize
);
1912 vfs_gpfs_disk_free_quota(qi_group
, cur_time
, dfree
, dsize
);
1914 /* Id 0 indicates the default quota, not an actual quota */
1916 vfs_gpfs_disk_free_quota(qi_fset
, cur_time
, dfree
, dsize
);
1919 disk_norm(small_query
, bsize
, dfree
, dsize
);
1923 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct
*handle
,
1924 enum timestamp_set_resolution
*p_ts_res
)
1926 struct gpfs_config_data
*config
;
1929 next
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
1931 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1932 struct gpfs_config_data
,
1936 next
|= FILE_SUPPORTS_REMOTE_STORAGE
;
1941 static int vfs_gpfs_open(struct vfs_handle_struct
*handle
,
1942 struct smb_filename
*smb_fname
, files_struct
*fsp
,
1943 int flags
, mode_t mode
)
1945 struct gpfs_config_data
*config
;
1947 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1948 struct gpfs_config_data
,
1951 if (config
->syncio
) {
1954 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
1957 static ssize_t
vfs_gpfs_pread(vfs_handle_struct
*handle
, files_struct
*fsp
,
1958 void *data
, size_t n
, off_t offset
)
1963 was_offline
= SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
,
1964 &fsp
->fsp_name
->st
);
1966 ret
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
1968 if ((ret
!= -1) && was_offline
) {
1969 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
1970 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
1971 fsp
->fsp_name
->base_name
);
1977 struct vfs_gpfs_pread_state
{
1978 struct files_struct
*fsp
;
1984 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
);
1986 static struct tevent_req
*vfs_gpfs_pread_send(struct vfs_handle_struct
*handle
,
1987 TALLOC_CTX
*mem_ctx
,
1988 struct tevent_context
*ev
,
1989 struct files_struct
*fsp
,
1990 void *data
, size_t n
,
1993 struct tevent_req
*req
, *subreq
;
1994 struct vfs_gpfs_pread_state
*state
;
1996 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pread_state
);
2000 state
->was_offline
= SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
,
2001 &fsp
->fsp_name
->st
);
2003 subreq
= SMB_VFS_NEXT_PREAD_SEND(state
, ev
, handle
, fsp
, data
,
2005 if (tevent_req_nomem(subreq
, req
)) {
2006 return tevent_req_post(req
, ev
);
2008 tevent_req_set_callback(subreq
, vfs_gpfs_pread_done
, req
);
2012 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
)
2014 struct tevent_req
*req
= tevent_req_callback_data(
2015 subreq
, struct tevent_req
);
2016 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2017 req
, struct vfs_gpfs_pread_state
);
2019 state
->ret
= SMB_VFS_PREAD_RECV(subreq
, &state
->err
);
2020 TALLOC_FREE(subreq
);
2021 tevent_req_done(req
);
2024 static ssize_t
vfs_gpfs_pread_recv(struct tevent_req
*req
, int *err
)
2026 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2027 req
, struct vfs_gpfs_pread_state
);
2028 struct files_struct
*fsp
= state
->fsp
;
2030 if (tevent_req_is_unix_error(req
, err
)) {
2035 if ((state
->ret
!= -1) && state
->was_offline
) {
2036 DEBUG(10, ("sending notify\n"));
2037 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2038 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2039 fsp
->fsp_name
->base_name
);
2045 static ssize_t
vfs_gpfs_pwrite(vfs_handle_struct
*handle
, files_struct
*fsp
,
2046 const void *data
, size_t n
, off_t offset
)
2051 was_offline
= SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
,
2052 &fsp
->fsp_name
->st
);
2054 ret
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
2056 if ((ret
!= -1) && was_offline
) {
2057 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2058 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2059 fsp
->fsp_name
->base_name
);
2065 struct vfs_gpfs_pwrite_state
{
2066 struct files_struct
*fsp
;
2072 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
);
2074 static struct tevent_req
*vfs_gpfs_pwrite_send(
2075 struct vfs_handle_struct
*handle
,
2076 TALLOC_CTX
*mem_ctx
,
2077 struct tevent_context
*ev
,
2078 struct files_struct
*fsp
,
2079 const void *data
, size_t n
,
2082 struct tevent_req
*req
, *subreq
;
2083 struct vfs_gpfs_pwrite_state
*state
;
2085 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pwrite_state
);
2089 state
->was_offline
= SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
,
2090 &fsp
->fsp_name
->st
);
2092 subreq
= SMB_VFS_NEXT_PWRITE_SEND(state
, ev
, handle
, fsp
, data
,
2094 if (tevent_req_nomem(subreq
, req
)) {
2095 return tevent_req_post(req
, ev
);
2097 tevent_req_set_callback(subreq
, vfs_gpfs_pwrite_done
, req
);
2101 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
)
2103 struct tevent_req
*req
= tevent_req_callback_data(
2104 subreq
, struct tevent_req
);
2105 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2106 req
, struct vfs_gpfs_pwrite_state
);
2108 state
->ret
= SMB_VFS_PWRITE_RECV(subreq
, &state
->err
);
2109 TALLOC_FREE(subreq
);
2110 tevent_req_done(req
);
2113 static ssize_t
vfs_gpfs_pwrite_recv(struct tevent_req
*req
, int *err
)
2115 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2116 req
, struct vfs_gpfs_pwrite_state
);
2117 struct files_struct
*fsp
= state
->fsp
;
2119 if (tevent_req_is_unix_error(req
, err
)) {
2124 if ((state
->ret
!= -1) && state
->was_offline
) {
2125 DEBUG(10, ("sending notify\n"));
2126 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2127 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2128 fsp
->fsp_name
->base_name
);
2135 static struct vfs_fn_pointers vfs_gpfs_fns
= {
2136 .connect_fn
= vfs_gpfs_connect
,
2137 .disk_free_fn
= vfs_gpfs_disk_free
,
2138 .fs_capabilities_fn
= vfs_gpfs_capabilities
,
2139 .kernel_flock_fn
= vfs_gpfs_kernel_flock
,
2140 .linux_setlease_fn
= vfs_gpfs_setlease
,
2141 .get_real_filename_fn
= vfs_gpfs_get_real_filename
,
2142 .fget_nt_acl_fn
= gpfsacl_fget_nt_acl
,
2143 .get_nt_acl_fn
= gpfsacl_get_nt_acl
,
2144 .fset_nt_acl_fn
= gpfsacl_fset_nt_acl
,
2145 .sys_acl_get_file_fn
= gpfsacl_sys_acl_get_file
,
2146 .sys_acl_get_fd_fn
= gpfsacl_sys_acl_get_fd
,
2147 .sys_acl_blob_get_file_fn
= gpfsacl_sys_acl_blob_get_file
,
2148 .sys_acl_blob_get_fd_fn
= gpfsacl_sys_acl_blob_get_fd
,
2149 .sys_acl_set_file_fn
= gpfsacl_sys_acl_set_file
,
2150 .sys_acl_set_fd_fn
= gpfsacl_sys_acl_set_fd
,
2151 .sys_acl_delete_def_file_fn
= gpfsacl_sys_acl_delete_def_file
,
2152 .chmod_fn
= vfs_gpfs_chmod
,
2153 .fchmod_fn
= vfs_gpfs_fchmod
,
2154 .close_fn
= vfs_gpfs_close
,
2155 .setxattr_fn
= gpfs_set_xattr
,
2156 .getxattr_fn
= gpfs_get_xattr
,
2157 .stat_fn
= vfs_gpfs_stat
,
2158 .fstat_fn
= vfs_gpfs_fstat
,
2159 .lstat_fn
= vfs_gpfs_lstat
,
2160 .ntimes_fn
= vfs_gpfs_ntimes
,
2161 .is_offline_fn
= vfs_gpfs_is_offline
,
2162 .aio_force_fn
= vfs_gpfs_aio_force
,
2163 .sendfile_fn
= vfs_gpfs_sendfile
,
2164 .fallocate_fn
= vfs_gpfs_fallocate
,
2165 .open_fn
= vfs_gpfs_open
,
2166 .pread_fn
= vfs_gpfs_pread
,
2167 .pread_send_fn
= vfs_gpfs_pread_send
,
2168 .pread_recv_fn
= vfs_gpfs_pread_recv
,
2169 .pwrite_fn
= vfs_gpfs_pwrite
,
2170 .pwrite_send_fn
= vfs_gpfs_pwrite_send
,
2171 .pwrite_recv_fn
= vfs_gpfs_pwrite_recv
,
2172 .ftruncate_fn
= vfs_gpfs_ftruncate
2175 NTSTATUS
vfs_gpfs_init(void);
2176 NTSTATUS
vfs_gpfs_init(void)
2180 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "gpfs",