2 Unix SMB/CIFS implementation.
3 Wrap gpfs calls in vfs functions.
5 Copyright (C) Christian Ambach <cambach1@de.ibm.com> 2006
7 Major code contributions by Chetan Shringarpure <chetan.sh@in.ibm.com>
8 and Gomati Mohanan <gomati.mohanan@in.ibm.com>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "smbd/smbd.h"
26 #include "librpc/gen_ndr/ndr_xattr.h"
27 #include "include/smbprofile.h"
30 #define DBGC_CLASS DBGC_VFS
33 #include "nfs4_acls.h"
35 #include "system/filesys.h"
37 #include "lib/util/tevent_unix.h"
39 struct gpfs_config_data
{
53 static int vfs_gpfs_kernel_flock(vfs_handle_struct
*handle
, files_struct
*fsp
,
54 uint32 share_mode
, uint32 access_mask
)
57 struct gpfs_config_data
*config
;
60 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
61 struct gpfs_config_data
,
64 if(!config
->sharemodes
) {
68 START_PROFILE(syscall_kernel_flock
);
70 kernel_flock(fsp
->fh
->fd
, share_mode
, access_mask
);
72 if (!set_gpfs_sharemode(fsp
, access_mask
, fsp
->share_access
)) {
76 END_PROFILE(syscall_kernel_flock
);
81 static int vfs_gpfs_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
84 struct gpfs_config_data
*config
;
86 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
87 struct gpfs_config_data
,
90 if (config
->sharemodes
&& (fsp
->fh
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
91 set_gpfs_sharemode(fsp
, 0, 0);
94 return SMB_VFS_NEXT_CLOSE(handle
, fsp
);
97 static int vfs_gpfs_setlease(vfs_handle_struct
*handle
, files_struct
*fsp
,
100 struct gpfs_config_data
*config
;
103 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
104 struct gpfs_config_data
,
107 if (linux_set_lease_sighandler(fsp
->fh
->fd
) == -1)
110 START_PROFILE(syscall_linux_setlease
);
112 if (config
->leases
) {
113 ret
= set_gpfs_lease(fsp
->fh
->fd
,leasetype
);
116 END_PROFILE(syscall_linux_setlease
);
121 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct
*handle
,
129 char real_pathname
[PATH_MAX
+1];
132 struct gpfs_config_data
*config
;
134 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
135 struct gpfs_config_data
,
138 if (!config
->getrealfilename
) {
139 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
140 mem_ctx
, found_name
);
143 mangled
= mangle_is_mangled(name
, handle
->conn
->params
);
145 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
146 mem_ctx
, found_name
);
149 full_path
= talloc_asprintf(talloc_tos(), "%s/%s", path
, name
);
150 if (full_path
== NULL
) {
155 buflen
= sizeof(real_pathname
) - 1;
157 result
= smbd_gpfs_get_realfilename_path(full_path
, real_pathname
,
160 TALLOC_FREE(full_path
);
162 if ((result
== -1) && (errno
== ENOSYS
)) {
163 return SMB_VFS_NEXT_GET_REAL_FILENAME(
164 handle
, path
, name
, mem_ctx
, found_name
);
168 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
174 * GPFS does not necessarily null-terminate the returned path
175 * but instead returns the buffer length in buflen.
178 if (buflen
< sizeof(real_pathname
)) {
179 real_pathname
[buflen
] = '\0';
181 real_pathname
[sizeof(real_pathname
)-1] = '\0';
184 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
185 path
, name
, real_pathname
));
187 name
= strrchr_m(real_pathname
, '/');
193 *found_name
= talloc_strdup(mem_ctx
, name
+1);
194 if (*found_name
== NULL
) {
202 static void gpfs_dumpacl(int level
, struct gpfs_acl
*gacl
)
207 DEBUG(0, ("gpfs acl is NULL\n"));
211 DEBUG(level
, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n",
212 gacl
->acl_nace
, gacl
->acl_type
, gacl
->acl_version
, gacl
->acl_level
, gacl
->acl_len
));
213 for(i
=0; i
<gacl
->acl_nace
; i
++)
215 struct gpfs_ace_v4
*gace
= gacl
->ace_v4
+ i
;
216 DEBUG(level
, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n",
217 i
, gace
->aceType
, gace
->aceFlags
, gace
->aceMask
,
218 gace
->aceIFlags
, gace
->aceWho
));
222 static struct gpfs_acl
*gpfs_getacl_alloc(const char *fname
, gpfs_aclType_t type
)
224 struct gpfs_acl
*acl
;
227 TALLOC_CTX
*mem_ctx
= talloc_tos();
229 acl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, len
);
237 acl
->acl_version
= 0;
238 acl
->acl_type
= type
;
240 ret
= smbd_gpfs_getacl((char *)fname
, GPFS_GETACL_STRUCT
, acl
);
241 if ((ret
!= 0) && (errno
== ENOSPC
)) {
242 struct gpfs_acl
*new_acl
= (struct gpfs_acl
*)TALLOC_SIZE(
243 mem_ctx
, acl
->acl_len
+ sizeof(struct gpfs_acl
));
244 if (new_acl
== NULL
) {
249 new_acl
->acl_len
= acl
->acl_len
;
250 new_acl
->acl_level
= acl
->acl_level
;
251 new_acl
->acl_version
= acl
->acl_version
;
252 new_acl
->acl_type
= acl
->acl_type
;
255 ret
= smbd_gpfs_getacl((char *)fname
, GPFS_GETACL_STRUCT
, acl
);
259 DEBUG(8, ("smbd_gpfs_getacl failed with %s\n",strerror(errno
)));
266 /* Tries to get nfs4 acls and returns SMB ACL allocated.
267 * On failure returns 1 if it got non-NFSv4 ACL to prompt
268 * retry with POSIX ACL checks.
269 * On failure returns -1 if there is system (GPFS) error, check errno.
270 * Returns 0 on success
272 static int gpfs_get_nfs4_acl(const char *fname
, SMB4ACL_T
**ppacl
)
275 struct gpfs_acl
*gacl
= NULL
;
276 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname
));
278 /* First get the real acl length */
279 gacl
= gpfs_getacl_alloc(fname
, 0);
281 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
282 fname
, strerror(errno
)));
286 if (gacl
->acl_type
!= GPFS_ACL_TYPE_NFS4
) {
287 DEBUG(10, ("Got non-nfsv4 acl\n"));
288 /* Retry with POSIX ACLs check */
292 *ppacl
= smb_create_smb4acl();
294 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
295 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
298 for (i
=0; i
<gacl
->acl_nace
; i
++) {
299 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[i
];
300 SMB_ACE4PROP_T smbace
;
301 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
302 "who: %d\n", gace
->aceType
, gace
->aceIFlags
,
303 gace
->aceFlags
, gace
->aceMask
, gace
->aceWho
));
306 if (gace
->aceIFlags
& ACE4_IFLAG_SPECIAL_ID
) {
307 smbace
.flags
|= SMB_ACE4_ID_SPECIAL
;
308 switch (gace
->aceWho
) {
309 case ACE4_SPECIAL_OWNER
:
310 smbace
.who
.special_id
= SMB_ACE4_WHO_OWNER
;
312 case ACE4_SPECIAL_GROUP
:
313 smbace
.who
.special_id
= SMB_ACE4_WHO_GROUP
;
315 case ACE4_SPECIAL_EVERYONE
:
316 smbace
.who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
319 DEBUG(8, ("invalid special gpfs id %d "
320 "ignored\n", gace
->aceWho
));
321 continue; /* don't add it */
324 if (gace
->aceFlags
& ACE4_FLAG_GROUP_ID
)
325 smbace
.who
.gid
= gace
->aceWho
;
327 smbace
.who
.uid
= gace
->aceWho
;
330 /* remove redundent deny entries */
331 if (i
> 0 && gace
->aceType
== SMB_ACE4_ACCESS_DENIED_ACE_TYPE
) {
332 struct gpfs_ace_v4
*prev
= &gacl
->ace_v4
[i
-1];
333 if (prev
->aceType
== SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
&&
334 prev
->aceFlags
== gace
->aceFlags
&&
335 prev
->aceIFlags
== gace
->aceIFlags
&&
336 (gace
->aceMask
& prev
->aceMask
) == 0 &&
337 gace
->aceWho
== prev
->aceWho
) {
338 /* its redundent - skip it */
343 smbace
.aceType
= gace
->aceType
;
344 smbace
.aceFlags
= gace
->aceFlags
;
345 smbace
.aceMask
= gace
->aceMask
;
346 smb_add_ace4(*ppacl
, &smbace
);
352 static NTSTATUS
gpfsacl_fget_nt_acl(vfs_handle_struct
*handle
,
353 files_struct
*fsp
, uint32 security_info
,
355 struct security_descriptor
**ppdesc
)
357 SMB4ACL_T
*pacl
= NULL
;
359 struct gpfs_config_data
*config
;
363 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
364 struct gpfs_config_data
,
365 return NT_STATUS_INTERNAL_ERROR
);
368 return SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
, ppdesc
);
371 result
= gpfs_get_nfs4_acl(fsp
->fsp_name
->base_name
, &pacl
);
374 return smb_fget_nt_acl_nfs4(fsp
, security_info
, mem_ctx
, ppdesc
, pacl
);
377 DEBUG(10, ("retrying with posix acl...\n"));
378 return posix_fget_nt_acl(fsp
, security_info
, mem_ctx
, ppdesc
);
381 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
382 return map_nt_error_from_unix(errno
);
385 static NTSTATUS
gpfsacl_get_nt_acl(vfs_handle_struct
*handle
,
387 uint32 security_info
,
388 TALLOC_CTX
*mem_ctx
, struct security_descriptor
**ppdesc
)
390 SMB4ACL_T
*pacl
= NULL
;
392 struct gpfs_config_data
*config
;
396 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
397 struct gpfs_config_data
,
398 return NT_STATUS_INTERNAL_ERROR
);
401 return SMB_VFS_NEXT_GET_NT_ACL(handle
, name
, security_info
, ppdesc
);
404 result
= gpfs_get_nfs4_acl(name
, &pacl
);
407 return smb_get_nt_acl_nfs4(handle
->conn
, name
, security_info
,
408 mem_ctx
, ppdesc
, pacl
);
411 DEBUG(10, ("retrying with posix acl...\n"));
412 return posix_get_nt_acl(handle
->conn
, name
, security_info
,
416 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
417 return map_nt_error_from_unix(errno
);
420 static bool gpfsacl_process_smbacl(files_struct
*fsp
, SMB4ACL_T
*smbacl
)
423 gpfs_aclLen_t gacl_len
;
425 struct gpfs_acl
*gacl
;
426 TALLOC_CTX
*mem_ctx
= talloc_tos();
428 gacl_len
= offsetof(gpfs_acl_t
, ace_v4
) + smb_get_naces(smbacl
) *
429 sizeof(gpfs_ace_v4_t
);
431 gacl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, gacl_len
);
433 DEBUG(0, ("talloc failed\n"));
438 gacl
->acl_len
= gacl_len
;
440 gacl
->acl_version
= GPFS_ACL_VERSION_NFS4
;
441 gacl
->acl_type
= GPFS_ACL_TYPE_NFS4
;
442 gacl
->acl_nace
= 0; /* change later... */
444 for (smbace
=smb_first_ace4(smbacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
445 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[gacl
->acl_nace
];
446 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
448 gace
->aceType
= aceprop
->aceType
;
449 gace
->aceFlags
= aceprop
->aceFlags
;
450 gace
->aceMask
= aceprop
->aceMask
;
453 * GPFS can't distinguish between WRITE and APPEND on
454 * files, so one being set without the other is an
455 * error. Sorry for the many ()'s :-)
458 if (!fsp
->is_directory
460 ((((gace
->aceMask
& ACE4_MASK_WRITE
) == 0)
461 && ((gace
->aceMask
& ACE4_MASK_APPEND
) != 0))
463 (((gace
->aceMask
& ACE4_MASK_WRITE
) != 0)
464 && ((gace
->aceMask
& ACE4_MASK_APPEND
) == 0)))
466 lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
467 "merge_writeappend", True
)) {
468 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
469 "WRITE^APPEND, setting WRITE|APPEND\n",
471 gace
->aceMask
|= ACE4_MASK_WRITE
|ACE4_MASK_APPEND
;
474 gace
->aceIFlags
= (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
) ? ACE4_IFLAG_SPECIAL_ID
: 0;
476 if (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
)
478 switch(aceprop
->who
.special_id
)
480 case SMB_ACE4_WHO_EVERYONE
:
481 gace
->aceWho
= ACE4_SPECIAL_EVERYONE
;
483 case SMB_ACE4_WHO_OWNER
:
484 gace
->aceWho
= ACE4_SPECIAL_OWNER
;
486 case SMB_ACE4_WHO_GROUP
:
487 gace
->aceWho
= ACE4_SPECIAL_GROUP
;
490 DEBUG(8, ("unsupported special_id %d\n", aceprop
->who
.special_id
));
491 continue; /* don't add it !!! */
494 /* just only for the type safety... */
495 if (aceprop
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)
496 gace
->aceWho
= aceprop
->who
.gid
;
498 gace
->aceWho
= aceprop
->who
.uid
;
504 ret
= smbd_gpfs_putacl(fsp
->fsp_name
->base_name
,
505 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gacl
);
507 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno
)));
508 gpfs_dumpacl(8, gacl
);
512 DEBUG(10, ("gpfs_putacl succeeded\n"));
516 static NTSTATUS
gpfsacl_set_nt_acl_internal(files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
518 struct gpfs_acl
*acl
;
519 NTSTATUS result
= NT_STATUS_ACCESS_DENIED
;
521 acl
= gpfs_getacl_alloc(fsp
->fsp_name
->base_name
, 0);
525 if (acl
->acl_version
&GPFS_ACL_VERSION_NFS4
)
527 if (lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
528 "refuse_dacl_protected", false)
529 && (psd
->type
&SEC_DESC_DACL_PROTECTED
)) {
530 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
531 return NT_STATUS_NOT_SUPPORTED
;
534 result
= smb_set_nt_acl_nfs4(
535 fsp
, security_info_sent
, psd
,
536 gpfsacl_process_smbacl
);
537 } else { /* assume POSIX ACL - by default... */
538 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
544 static NTSTATUS
gpfsacl_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
546 struct gpfs_config_data
*config
;
548 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
549 struct gpfs_config_data
,
550 return NT_STATUS_INTERNAL_ERROR
);
553 return SMB_VFS_NEXT_FSET_NT_ACL(handle
, fsp
, security_info_sent
, psd
);
556 return gpfsacl_set_nt_acl_internal(fsp
, security_info_sent
, psd
);
559 static SMB_ACL_T
gpfs2smb_acl(const struct gpfs_acl
*pacl
, TALLOC_CTX
*mem_ctx
)
564 result
= sys_acl_init(mem_ctx
);
565 if (result
== NULL
) {
570 result
->count
= pacl
->acl_nace
;
572 for (i
=0; i
<pacl
->acl_nace
; i
++) {
573 struct smb_acl_entry
*ace
= &result
->acl
[i
];
574 const struct gpfs_ace_v1
*g_ace
= &pacl
->ace_v1
[i
];
576 DEBUG(10, ("Converting type %d id %lu perm %x\n",
577 (int)g_ace
->ace_type
, (unsigned long)g_ace
->ace_who
,
578 (int)g_ace
->ace_perm
));
580 switch (g_ace
->ace_type
) {
582 ace
->a_type
= SMB_ACL_USER
;
583 ace
->info
.user
.uid
= (uid_t
)g_ace
->ace_who
;
585 case GPFS_ACL_USER_OBJ
:
586 ace
->a_type
= SMB_ACL_USER_OBJ
;
589 ace
->a_type
= SMB_ACL_GROUP
;
590 ace
->info
.group
.gid
= (gid_t
)g_ace
->ace_who
;
592 case GPFS_ACL_GROUP_OBJ
:
593 ace
->a_type
= SMB_ACL_GROUP_OBJ
;
596 ace
->a_type
= SMB_ACL_OTHER
;
599 ace
->a_type
= SMB_ACL_MASK
;
602 DEBUG(10, ("Got invalid ace_type: %d\n",
610 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_READ
) ?
612 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_WRITE
) ?
614 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_EXECUTE
) ?
617 DEBUGADD(10, ("Converted to %d perm %x\n",
618 ace
->a_type
, ace
->a_perm
));
624 static SMB_ACL_T
gpfsacl_get_posix_acl(const char *path
, gpfs_aclType_t type
,
627 struct gpfs_acl
*pacl
;
628 SMB_ACL_T result
= NULL
;
630 pacl
= gpfs_getacl_alloc(path
, type
);
633 DEBUG(10, ("gpfs_getacl failed for %s with %s\n",
634 path
, strerror(errno
)));
641 if (pacl
->acl_version
!= GPFS_ACL_VERSION_POSIX
) {
642 DEBUG(10, ("Got acl version %d, expected %d\n",
643 pacl
->acl_version
, GPFS_ACL_VERSION_POSIX
));
648 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
649 pacl
->acl_len
, pacl
->acl_level
, pacl
->acl_version
,
652 result
= gpfs2smb_acl(pacl
, mem_ctx
);
653 if (result
!= NULL
) {
665 static SMB_ACL_T
gpfsacl_sys_acl_get_file(vfs_handle_struct
*handle
,
670 gpfs_aclType_t gpfs_type
;
671 struct gpfs_config_data
*config
;
673 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
674 struct gpfs_config_data
,
678 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle
, path_p
,
683 case SMB_ACL_TYPE_ACCESS
:
684 gpfs_type
= GPFS_ACL_TYPE_ACCESS
;
686 case SMB_ACL_TYPE_DEFAULT
:
687 gpfs_type
= GPFS_ACL_TYPE_DEFAULT
;
690 DEBUG(0, ("Got invalid type: %d\n", type
));
691 smb_panic("exiting");
694 return gpfsacl_get_posix_acl(path_p
, gpfs_type
, mem_ctx
);
697 static SMB_ACL_T
gpfsacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
701 struct gpfs_config_data
*config
;
703 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
704 struct gpfs_config_data
,
708 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle
, fsp
, mem_ctx
);
711 return gpfsacl_get_posix_acl(fsp
->fsp_name
->base_name
,
712 GPFS_ACL_TYPE_ACCESS
, mem_ctx
);
715 static int gpfsacl_sys_acl_blob_get_file(vfs_handle_struct
*handle
, const char *path_p
,
717 char **blob_description
,
720 struct gpfs_config_data
*config
;
722 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
723 struct gpfs_config_data
,
727 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle
, path_p
, mem_ctx
, blob_description
, blob
);
730 result
= gpfs_get_nfs4_acl(name
, &pacl
);
732 /* We don't have a way to linearlise the NFS4 ACL
733 * right now, and it is much closer to the NT ACL
739 return posix_sys_acl_blob_get_file(handle
, path_p
, mem_ctx
,
740 blob_description
, blob
);
743 static int gpfsacl_sys_acl_blob_get_fd(vfs_handle_struct
*handle
, files_struct
*fsp
,
745 char **blob_description
,
748 struct gpfs_config_data
*config
;
750 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
751 struct gpfs_config_data
,
755 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle
, fsp
, mem_ctx
, blob_description
, blob
);
758 result
= gpfs_get_nfs4_acl(fsp
->fsp_name
->base_name
, &pacl
);
760 /* We don't have a way to linearlise the NFS4 ACL
761 * right now, and it is much closer to the NT ACL
767 return posix_sys_acl_blob_get_fd(handle
, fsp
, mem_ctx
,
768 blob_description
, blob
);
771 static struct gpfs_acl
*smb2gpfs_acl(const SMB_ACL_T pacl
,
775 struct gpfs_acl
*result
;
778 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl
->count
));
780 len
= offsetof(gpfs_acl_t
, ace_v1
) + (pacl
->count
) *
781 sizeof(gpfs_ace_v1_t
);
783 result
= (struct gpfs_acl
*)SMB_MALLOC(len
);
784 if (result
== NULL
) {
789 result
->acl_len
= len
;
790 result
->acl_level
= 0;
791 result
->acl_version
= GPFS_ACL_VERSION_POSIX
;
792 result
->acl_type
= (type
== SMB_ACL_TYPE_DEFAULT
) ?
793 GPFS_ACL_TYPE_DEFAULT
: GPFS_ACL_TYPE_ACCESS
;
794 result
->acl_nace
= pacl
->count
;
796 for (i
=0; i
<pacl
->count
; i
++) {
797 const struct smb_acl_entry
*ace
= &pacl
->acl
[i
];
798 struct gpfs_ace_v1
*g_ace
= &result
->ace_v1
[i
];
800 DEBUG(10, ("Converting type %d perm %x\n",
801 (int)ace
->a_type
, (int)ace
->a_perm
));
805 switch(ace
->a_type
) {
807 g_ace
->ace_type
= GPFS_ACL_USER
;
808 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.user
.uid
;
810 case SMB_ACL_USER_OBJ
:
811 g_ace
->ace_type
= GPFS_ACL_USER_OBJ
;
812 g_ace
->ace_perm
|= ACL_PERM_CONTROL
;
816 g_ace
->ace_type
= GPFS_ACL_GROUP
;
817 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.group
.gid
;
819 case SMB_ACL_GROUP_OBJ
:
820 g_ace
->ace_type
= GPFS_ACL_GROUP_OBJ
;
824 g_ace
->ace_type
= GPFS_ACL_MASK
;
825 g_ace
->ace_perm
= 0x8f;
829 g_ace
->ace_type
= GPFS_ACL_OTHER
;
833 DEBUG(10, ("Got invalid ace_type: %d\n", ace
->a_type
));
839 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_READ
) ?
841 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_WRITE
) ?
843 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_EXECUTE
) ?
844 ACL_PERM_EXECUTE
: 0;
846 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
847 g_ace
->ace_type
, g_ace
->ace_who
, g_ace
->ace_perm
));
853 static int gpfsacl_sys_acl_set_file(vfs_handle_struct
*handle
,
858 struct gpfs_acl
*gpfs_acl
;
860 struct gpfs_config_data
*config
;
862 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
863 struct gpfs_config_data
,
867 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle
, name
, type
, theacl
);
870 gpfs_acl
= smb2gpfs_acl(theacl
, type
);
871 if (gpfs_acl
== NULL
) {
875 result
= smbd_gpfs_putacl((char *)name
, GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gpfs_acl
);
881 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
885 struct gpfs_config_data
*config
;
887 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
888 struct gpfs_config_data
,
892 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle
, fsp
, theacl
);
895 return gpfsacl_sys_acl_set_file(handle
, fsp
->fsp_name
->base_name
,
896 SMB_ACL_TYPE_ACCESS
, theacl
);
899 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
902 struct gpfs_config_data
*config
;
904 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
905 struct gpfs_config_data
,
909 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle
, path
);
917 * Assumed: mode bits are shiftable and standard
918 * Output: the new aceMask field for an smb nfs4 ace
920 static uint32
gpfsacl_mask_filter(uint32 aceType
, uint32 aceMask
, uint32 rwx
)
922 const uint32 posix_nfs4map
[3] = {
923 SMB_ACE4_EXECUTE
, /* execute */
924 SMB_ACE4_WRITE_DATA
| SMB_ACE4_APPEND_DATA
, /* write; GPFS specific */
925 SMB_ACE4_READ_DATA
/* read */
928 uint32_t posix_mask
= 0x01;
933 nfs4_bits
= posix_nfs4map
[i
];
934 posix_bit
= rwx
& posix_mask
;
936 if (aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
) {
938 aceMask
|= nfs4_bits
;
940 aceMask
&= ~nfs4_bits
;
942 /* add deny bits when suitable */
944 aceMask
|= nfs4_bits
;
946 aceMask
&= ~nfs4_bits
;
947 } /* other ace types are unexpected */
955 static int gpfsacl_emu_chmod(const char *path
, mode_t mode
)
957 SMB4ACL_T
*pacl
= NULL
;
959 bool haveAllowEntry
[SMB_ACE4_WHO_EVERYONE
+ 1] = {False
, False
, False
, False
};
961 files_struct fake_fsp
; /* TODO: rationalize parametrization */
965 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path
, mode
));
967 result
= gpfs_get_nfs4_acl(path
, &pacl
);
971 if (mode
& ~(S_IRWXU
| S_IRWXG
| S_IRWXO
)) {
972 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode
, path
));
975 for (smbace
=smb_first_ace4(pacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
976 SMB_ACE4PROP_T
*ace
= smb_get_ace4(smbace
);
977 uint32_t specid
= ace
->who
.special_id
;
979 if (ace
->flags
&SMB_ACE4_ID_SPECIAL
&&
980 ace
->aceType
<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE
&&
981 specid
<= SMB_ACE4_WHO_EVERYONE
) {
985 if (ace
->aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
)
986 haveAllowEntry
[specid
] = True
;
988 /* mode >> 6 for @owner, mode >> 3 for @group,
989 * mode >> 0 for @everyone */
990 newMask
= gpfsacl_mask_filter(ace
->aceType
, ace
->aceMask
,
991 mode
>> ((SMB_ACE4_WHO_EVERYONE
- specid
) * 3));
992 if (ace
->aceMask
!=newMask
) {
993 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
994 path
, ace
->aceMask
, newMask
, specid
));
996 ace
->aceMask
= newMask
;
1000 /* make sure we have at least ALLOW entries
1001 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
1004 for(i
= SMB_ACE4_WHO_OWNER
; i
<=SMB_ACE4_WHO_EVERYONE
; i
++) {
1007 if (haveAllowEntry
[i
]==True
)
1011 ace
.aceType
= SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
;
1012 ace
.flags
|= SMB_ACE4_ID_SPECIAL
;
1013 ace
.who
.special_id
= i
;
1015 if (i
==SMB_ACE4_WHO_GROUP
) /* not sure it's necessary... */
1016 ace
.aceFlags
|= SMB_ACE4_IDENTIFIER_GROUP
;
1018 ace
.aceMask
= gpfsacl_mask_filter(ace
.aceType
, ace
.aceMask
,
1019 mode
>> ((SMB_ACE4_WHO_EVERYONE
- i
) * 3));
1021 /* don't add unnecessary aces */
1025 /* we add it to the END - as windows expects allow aces */
1026 smb_add_ace4(pacl
, &ace
);
1027 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1028 path
, mode
, i
, ace
.aceMask
));
1031 /* don't add complementary DENY ACEs here */
1032 ZERO_STRUCT(fake_fsp
);
1033 status
= create_synthetic_smb_fname(talloc_tos(), path
, NULL
, NULL
,
1034 &fake_fsp
.fsp_name
);
1035 if (!NT_STATUS_IS_OK(status
)) {
1036 errno
= map_errno_from_nt_status(status
);
1040 if (gpfsacl_process_smbacl(&fake_fsp
, pacl
) == False
) {
1041 TALLOC_FREE(fake_fsp
.fsp_name
);
1045 TALLOC_FREE(fake_fsp
.fsp_name
);
1046 return 0; /* ok for [f]chmod */
1049 static int vfs_gpfs_chmod(vfs_handle_struct
*handle
, const char *path
, mode_t mode
)
1051 struct smb_filename
*smb_fname_cpath
;
1055 status
= create_synthetic_smb_fname(
1056 talloc_tos(), path
, NULL
, NULL
, &smb_fname_cpath
);
1058 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_cpath
) != 0) {
1062 /* avoid chmod() if possible, to preserve acls */
1063 if ((smb_fname_cpath
->st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1067 rc
= gpfsacl_emu_chmod(path
, mode
);
1069 return SMB_VFS_NEXT_CHMOD(handle
, path
, mode
);
1073 static int vfs_gpfs_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
1078 if (SMB_VFS_NEXT_FSTAT(handle
, fsp
, &st
) != 0) {
1082 /* avoid chmod() if possible, to preserve acls */
1083 if ((st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1087 rc
= gpfsacl_emu_chmod(fsp
->fsp_name
->base_name
, mode
);
1089 return SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
1093 static int gpfs_set_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1094 const char *name
, const void *value
, size_t size
, int flags
){
1095 struct xattr_DOSATTRIB dosattrib
;
1096 enum ndr_err_code ndr_err
;
1098 const char *attrstr
= value
;
1099 unsigned int dosmode
=0;
1100 struct gpfs_winattr attrs
;
1102 struct gpfs_config_data
*config
;
1104 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1105 struct gpfs_config_data
,
1108 if (!config
->winattr
) {
1109 DEBUG(10, ("gpfs_set_xattr:name is %s -> next\n",name
));
1110 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1113 DEBUG(10, ("gpfs_set_xattr: %s \n",path
));
1115 /* Only handle DOS Attributes */
1116 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1117 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name
));
1118 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1121 blob
.data
= (uint8_t *)attrstr
;
1124 ndr_err
= ndr_pull_struct_blob(&blob
, talloc_tos(), &dosattrib
,
1125 (ndr_pull_flags_fn_t
)ndr_pull_xattr_DOSATTRIB
);
1127 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1128 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
1129 "from EA on file %s: Error = %s\n",
1130 path
, ndr_errstr(ndr_err
)));
1134 if (dosattrib
.version
!= 3) {
1135 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
1136 "%d\n", (int)dosattrib
.version
));
1139 if (!(dosattrib
.info
.info3
.valid_flags
& XATTR_DOSINFO_ATTRIB
)) {
1140 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
1141 "valid, ignoring\n"));
1145 dosmode
= dosattrib
.info
.info3
.attrib
;
1148 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
1149 if (dosmode
& FILE_ATTRIBUTE_ARCHIVE
){
1150 attrs
.winAttrs
|= GPFS_WINATTR_ARCHIVE
;
1152 if (dosmode
& FILE_ATTRIBUTE_HIDDEN
){
1153 attrs
.winAttrs
|= GPFS_WINATTR_HIDDEN
;
1155 if (dosmode
& FILE_ATTRIBUTE_SYSTEM
){
1156 attrs
.winAttrs
|= GPFS_WINATTR_SYSTEM
;
1158 if (dosmode
& FILE_ATTRIBUTE_READONLY
){
1159 attrs
.winAttrs
|= GPFS_WINATTR_READONLY
;
1161 if (dosmode
& FILE_ATTRIBUTE_SPARSE
) {
1162 attrs
.winAttrs
|= GPFS_WINATTR_SPARSE_FILE
;
1166 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1167 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1169 if (errno
== ENOSYS
) {
1170 return SMB_VFS_NEXT_SETXATTR(handle
, path
, name
, value
,
1174 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret
));
1178 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs
.winAttrs
));
1182 static ssize_t
gpfs_get_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1183 const char *name
, void *value
, size_t size
){
1184 char *attrstr
= value
;
1185 unsigned int dosmode
= 0;
1186 struct gpfs_winattr attrs
;
1188 struct gpfs_config_data
*config
;
1190 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1191 struct gpfs_config_data
,
1194 if (!config
->winattr
) {
1195 DEBUG(10, ("gpfs_get_xattr:name is %s -> next\n",name
));
1196 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1199 DEBUG(10, ("gpfs_get_xattr: %s \n",path
));
1201 /* Only handle DOS Attributes */
1202 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1203 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name
));
1204 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1207 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1209 if (errno
== ENOSYS
) {
1210 return SMB_VFS_NEXT_GETXATTR(handle
, path
, name
, value
,
1214 DEBUG(1, ("gpfs_get_xattr: Get GPFS attributes failed: "
1215 "%d (%s)\n", ret
, strerror(errno
)));
1219 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs
.winAttrs
));
1221 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1222 if (attrs
.winAttrs
& GPFS_WINATTR_ARCHIVE
){
1223 dosmode
|= FILE_ATTRIBUTE_ARCHIVE
;
1225 if (attrs
.winAttrs
& GPFS_WINATTR_HIDDEN
){
1226 dosmode
|= FILE_ATTRIBUTE_HIDDEN
;
1228 if (attrs
.winAttrs
& GPFS_WINATTR_SYSTEM
){
1229 dosmode
|= FILE_ATTRIBUTE_SYSTEM
;
1231 if (attrs
.winAttrs
& GPFS_WINATTR_READONLY
){
1232 dosmode
|= FILE_ATTRIBUTE_READONLY
;
1234 if (attrs
.winAttrs
& GPFS_WINATTR_SPARSE_FILE
) {
1235 dosmode
|= FILE_ATTRIBUTE_SPARSE
;
1238 snprintf(attrstr
, size
, "0x%2.2x",
1239 (unsigned int)(dosmode
& SAMBA_ATTRIBUTES_MASK
));
1240 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr
));
1244 static int vfs_gpfs_stat(struct vfs_handle_struct
*handle
,
1245 struct smb_filename
*smb_fname
)
1247 struct gpfs_winattr attrs
;
1251 struct gpfs_config_data
*config
;
1253 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1254 struct gpfs_config_data
,
1257 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
1262 if (!config
->winattr
) {
1266 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &fname
);
1267 if (!NT_STATUS_IS_OK(status
)) {
1268 errno
= map_errno_from_nt_status(status
);
1271 ret
= get_gpfs_winattrs(discard_const_p(char, fname
), &attrs
);
1274 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1275 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1276 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1277 smb_fname
->st
.vfs_private
= attrs
.winAttrs
;
1282 static int vfs_gpfs_fstat(struct vfs_handle_struct
*handle
,
1283 struct files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
1285 struct gpfs_winattr attrs
;
1287 struct gpfs_config_data
*config
;
1289 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1290 struct gpfs_config_data
,
1293 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
1297 if ((fsp
->fh
== NULL
) || (fsp
->fh
->fd
== -1)) {
1300 if (!config
->winattr
) {
1304 ret
= smbd_fget_gpfs_winattrs(fsp
->fh
->fd
, &attrs
);
1306 sbuf
->st_ex_calculated_birthtime
= false;
1307 sbuf
->st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1308 sbuf
->st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1313 static int vfs_gpfs_lstat(struct vfs_handle_struct
*handle
,
1314 struct smb_filename
*smb_fname
)
1316 struct gpfs_winattr attrs
;
1320 struct gpfs_config_data
*config
;
1322 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1323 struct gpfs_config_data
,
1326 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
1330 if (!config
->winattr
) {
1334 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1335 if (!NT_STATUS_IS_OK(status
)) {
1336 errno
= map_errno_from_nt_status(status
);
1339 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1342 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1343 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1344 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1345 smb_fname
->st
.vfs_private
= attrs
.winAttrs
;
1350 static int vfs_gpfs_ntimes(struct vfs_handle_struct
*handle
,
1351 const struct smb_filename
*smb_fname
,
1352 struct smb_file_time
*ft
)
1355 struct gpfs_winattr attrs
;
1359 struct gpfs_config_data
*config
;
1361 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1362 struct gpfs_config_data
,
1365 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1367 /* don't complain if access was denied */
1368 if (errno
!= EPERM
&& errno
!= EACCES
) {
1369 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1370 "%s", strerror(errno
)));
1375 if(null_timespec(ft
->create_time
)){
1376 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1380 if (!config
->winattr
) {
1384 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1385 if (!NT_STATUS_IS_OK(status
)) {
1386 errno
= map_errno_from_nt_status(status
);
1391 attrs
.creationTime
.tv_sec
= ft
->create_time
.tv_sec
;
1392 attrs
.creationTime
.tv_nsec
= ft
->create_time
.tv_nsec
;
1394 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1395 GPFS_WINATTR_SET_CREATION_TIME
, &attrs
);
1396 if(ret
== -1 && errno
!= ENOSYS
){
1397 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret
));
1404 static int vfs_gpfs_fallocate(struct vfs_handle_struct
*handle
,
1405 struct files_struct
*fsp
, enum vfs_fallocate_mode mode
,
1406 off_t offset
, off_t len
)
1409 struct gpfs_config_data
*config
;
1411 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1412 struct gpfs_config_data
,
1415 if (!config
->prealloc
) {
1416 /* you should better not run fallocate() on GPFS at all */
1421 if (mode
== VFS_FALLOCATE_KEEP_SIZE
) {
1422 DEBUG(10, ("Unsupported VFS_FALLOCATE_KEEP_SIZE\n"));
1427 ret
= smbd_gpfs_prealloc(fsp
->fh
->fd
, offset
, len
);
1429 if (ret
== -1 && errno
!= ENOSYS
) {
1430 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno
)));
1431 } else if (ret
== -1 && errno
== ENOSYS
) {
1432 DEBUG(10, ("GPFS prealloc not supported.\n"));
1434 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1440 static int vfs_gpfs_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1444 struct gpfs_config_data
*config
;
1446 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1447 struct gpfs_config_data
,
1450 if (!config
->ftruncate
) {
1451 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1454 result
= smbd_gpfs_ftruncate(fsp
->fh
->fd
, len
);
1455 if ((result
== -1) && (errno
== ENOSYS
)) {
1456 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1461 static bool vfs_gpfs_is_offline(struct vfs_handle_struct
*handle
,
1462 const struct smb_filename
*fname
,
1463 SMB_STRUCT_STAT
*sbuf
)
1465 struct gpfs_winattr attrs
;
1468 struct gpfs_config_data
*config
;
1470 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1471 struct gpfs_config_data
,
1474 if (!config
->winattr
) {
1475 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1478 status
= get_full_smb_filename(talloc_tos(), fname
, &path
);
1479 if (!NT_STATUS_IS_OK(status
)) {
1480 errno
= map_errno_from_nt_status(status
);
1484 if (VALID_STAT(*sbuf
)) {
1485 attrs
.winAttrs
= sbuf
->vfs_private
;
1488 ret
= get_gpfs_winattrs(path
, &attrs
);
1495 if ((attrs
.winAttrs
& GPFS_WINATTR_OFFLINE
) != 0) {
1496 DEBUG(10, ("%s is offline\n", path
));
1500 DEBUG(10, ("%s is online\n", path
));
1502 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1505 static bool vfs_gpfs_aio_force(struct vfs_handle_struct
*handle
,
1506 struct files_struct
*fsp
)
1508 return vfs_gpfs_is_offline(handle
, fsp
->fsp_name
, &fsp
->fsp_name
->st
);
1511 static ssize_t
vfs_gpfs_sendfile(vfs_handle_struct
*handle
, int tofd
,
1512 files_struct
*fsp
, const DATA_BLOB
*hdr
,
1513 off_t offset
, size_t n
)
1515 if ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0) {
1519 return SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fsp
, hdr
, offset
, n
);
1522 static int vfs_gpfs_connect(struct vfs_handle_struct
*handle
,
1523 const char *service
, const char *user
)
1525 struct gpfs_config_data
*config
;
1528 smbd_gpfs_lib_init();
1530 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1536 config
= talloc_zero(handle
->conn
, struct gpfs_config_data
);
1538 SMB_VFS_NEXT_DISCONNECT(handle
);
1539 DEBUG(0, ("talloc_zero() failed\n"));
1543 config
->sharemodes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1544 "sharemodes", true);
1546 config
->leases
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1549 config
->hsm
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1552 config
->syncio
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1555 config
->winattr
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1558 config
->ftruncate
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1561 config
->getrealfilename
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1562 "getrealfilename", true);
1564 config
->dfreequota
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1565 "dfreequota", false);
1567 config
->prealloc
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1570 config
->acl
= lp_parm_bool(SNUM(handle
->conn
), "gpfs", "acl", true);
1572 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
1573 NULL
, struct gpfs_config_data
,
1576 if (config
->leases
) {
1578 * GPFS lease code is based on kernel oplock code
1579 * so make sure it is turned on
1581 if (!lp_kernel_oplocks(SNUM(handle
->conn
))) {
1582 DEBUG(5, ("Enabling kernel oplocks for "
1583 "gpfs:leases to work\n"));
1584 lp_do_parameter(SNUM(handle
->conn
), "kernel oplocks",
1589 * as the kernel does not properly support Level II oplocks
1590 * and GPFS leases code is based on kernel infrastructure, we
1591 * need to turn off Level II oplocks if gpfs:leases is enabled
1593 if (lp_level2_oplocks(SNUM(handle
->conn
))) {
1594 DEBUG(5, ("gpfs:leases are enabled, disabling "
1595 "Level II oplocks\n"));
1596 lp_do_parameter(SNUM(handle
->conn
), "level2 oplocks",
1604 static int vfs_gpfs_get_quotas(const char *path
, uid_t uid
, gid_t gid
,
1606 struct gpfs_quotaInfo
*qi_user
,
1607 struct gpfs_quotaInfo
*qi_group
,
1608 struct gpfs_quotaInfo
*qi_fset
)
1615 * We want to always use the directory to get the fileset id,
1616 * because files might have a share mode. We also do not want
1617 * to get the parent directory when there is already a
1618 * directory to avoid stepping in a different fileset. The
1619 * path passed here is currently either "." or a filename, so
1620 * this is ok. The proper solution would be having a way to
1621 * query the fileset id without opening the file.
1623 b
= parent_dirname(talloc_tos(), path
, &dir_path
, NULL
);
1629 DEBUG(10, ("path %s, directory %s\n", path
, dir_path
));
1631 err
= get_gpfs_fset_id(dir_path
, fset_id
);
1633 DEBUG(0, ("Get fset id failed path %s, dir %s, errno %d.\n",
1634 path
, dir_path
, errno
));
1638 err
= get_gpfs_quota(path
, GPFS_USRQUOTA
, uid
, qi_user
);
1643 err
= get_gpfs_quota(path
, GPFS_GRPQUOTA
, gid
, qi_group
);
1648 err
= get_gpfs_quota(path
, GPFS_FILESETQUOTA
, *fset_id
, qi_fset
);
1656 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi
, time_t cur_time
,
1657 uint64_t *dfree
, uint64_t *dsize
)
1659 uint64_t usage
, limit
;
1662 * The quota reporting is done in units of 1024 byte blocks, but
1663 * sys_fsusage uses units of 512 byte blocks, adjust the block number
1664 * accordingly. Also filter possibly negative usage counts from gpfs.
1666 usage
= qi
.blockUsage
< 0 ? 0 : (uint64_t)qi
.blockUsage
* 2;
1667 limit
= (uint64_t)qi
.blockHardLimit
* 2;
1670 * When the grace time for the exceeded soft block quota has been
1671 * exceeded, the soft block quota becomes an additional hard limit.
1673 if (qi
.blockSoftLimit
&&
1674 qi
.blockGraceTime
&& cur_time
> qi
.blockGraceTime
) {
1675 /* report disk as full */
1677 *dsize
= MIN(*dsize
, usage
);
1680 if (!qi
.blockHardLimit
)
1683 if (usage
>= limit
) {
1684 /* report disk as full */
1686 *dsize
= MIN(*dsize
, usage
);
1689 /* limit has not been reached, determine "free space" */
1690 *dfree
= MIN(*dfree
, limit
- usage
);
1691 *dsize
= MIN(*dsize
, limit
);
1695 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct
*handle
, const char *path
,
1696 bool small_query
, uint64_t *bsize
,
1697 uint64_t *dfree
, uint64_t *dsize
)
1699 struct security_unix_token
*utok
;
1700 struct gpfs_quotaInfo qi_user
, qi_group
, qi_fset
;
1701 struct gpfs_config_data
*config
;
1705 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct gpfs_config_data
,
1706 return (uint64_t)-1);
1707 if (!config
->dfreequota
) {
1708 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1709 bsize
, dfree
, dsize
);
1712 err
= sys_fsusage(path
, dfree
, dsize
);
1714 DEBUG (0, ("Could not get fs usage, errno %d\n", errno
));
1715 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1716 bsize
, dfree
, dsize
);
1719 /* sys_fsusage returns units of 512 bytes */
1722 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
1723 (unsigned long long)*dfree
, (unsigned long long)*dsize
));
1725 utok
= handle
->conn
->session_info
->unix_token
;
1726 err
= vfs_gpfs_get_quotas(path
, utok
->uid
, utok
->gid
, &fset_id
,
1727 &qi_user
, &qi_group
, &qi_fset
);
1729 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1730 bsize
, dfree
, dsize
);
1733 cur_time
= time(NULL
);
1735 /* Adjust free space and size according to quota limits. */
1736 vfs_gpfs_disk_free_quota(qi_user
, cur_time
, dfree
, dsize
);
1737 vfs_gpfs_disk_free_quota(qi_group
, cur_time
, dfree
, dsize
);
1739 /* Id 0 indicates the default quota, not an actual quota */
1741 vfs_gpfs_disk_free_quota(qi_fset
, cur_time
, dfree
, dsize
);
1744 disk_norm(small_query
, bsize
, dfree
, dsize
);
1748 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct
*handle
,
1749 enum timestamp_set_resolution
*p_ts_res
)
1751 struct gpfs_config_data
*config
;
1754 next
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
1756 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1757 struct gpfs_config_data
,
1761 next
|= FILE_SUPPORTS_REMOTE_STORAGE
;
1766 static int vfs_gpfs_open(struct vfs_handle_struct
*handle
,
1767 struct smb_filename
*smb_fname
, files_struct
*fsp
,
1768 int flags
, mode_t mode
)
1770 struct gpfs_config_data
*config
;
1772 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1773 struct gpfs_config_data
,
1776 if (config
->syncio
) {
1779 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
1782 static ssize_t
vfs_gpfs_pread(vfs_handle_struct
*handle
, files_struct
*fsp
,
1783 void *data
, size_t n
, off_t offset
)
1787 ret
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
1789 DEBUG(10, ("vfs_private = %x\n",
1790 (unsigned int)fsp
->fsp_name
->st
.vfs_private
));
1793 ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0)) {
1794 fsp
->fsp_name
->st
.vfs_private
&= ~GPFS_WINATTR_OFFLINE
;
1795 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
1796 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
1797 fsp
->fsp_name
->base_name
);
1803 struct vfs_gpfs_pread_state
{
1804 struct files_struct
*fsp
;
1809 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
);
1811 static struct tevent_req
*vfs_gpfs_pread_send(struct vfs_handle_struct
*handle
,
1812 TALLOC_CTX
*mem_ctx
,
1813 struct tevent_context
*ev
,
1814 struct files_struct
*fsp
,
1815 void *data
, size_t n
,
1818 struct tevent_req
*req
, *subreq
;
1819 struct vfs_gpfs_pread_state
*state
;
1821 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pread_state
);
1826 subreq
= SMB_VFS_NEXT_PREAD_SEND(state
, ev
, handle
, fsp
, data
,
1828 if (tevent_req_nomem(subreq
, req
)) {
1829 return tevent_req_post(req
, ev
);
1831 tevent_req_set_callback(subreq
, vfs_gpfs_pread_done
, req
);
1835 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
)
1837 struct tevent_req
*req
= tevent_req_callback_data(
1838 subreq
, struct tevent_req
);
1839 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
1840 req
, struct vfs_gpfs_pread_state
);
1842 state
->ret
= SMB_VFS_PREAD_RECV(subreq
, &state
->err
);
1843 TALLOC_FREE(subreq
);
1844 tevent_req_done(req
);
1847 static ssize_t
vfs_gpfs_pread_recv(struct tevent_req
*req
, int *err
)
1849 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
1850 req
, struct vfs_gpfs_pread_state
);
1851 struct files_struct
*fsp
= state
->fsp
;
1853 if (tevent_req_is_unix_error(req
, err
)) {
1858 DEBUG(10, ("vfs_private = %x\n",
1859 (unsigned int)fsp
->fsp_name
->st
.vfs_private
));
1861 if ((state
->ret
!= -1) &&
1862 ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0)) {
1863 fsp
->fsp_name
->st
.vfs_private
&= ~GPFS_WINATTR_OFFLINE
;
1864 DEBUG(10, ("sending notify\n"));
1865 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
1866 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
1867 fsp
->fsp_name
->base_name
);
1873 static ssize_t
vfs_gpfs_pwrite(vfs_handle_struct
*handle
, files_struct
*fsp
,
1874 const void *data
, size_t n
, off_t offset
)
1878 ret
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
1880 DEBUG(10, ("vfs_private = %x\n",
1881 (unsigned int)fsp
->fsp_name
->st
.vfs_private
));
1884 ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0)) {
1885 fsp
->fsp_name
->st
.vfs_private
&= ~GPFS_WINATTR_OFFLINE
;
1886 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
1887 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
1888 fsp
->fsp_name
->base_name
);
1894 struct vfs_gpfs_pwrite_state
{
1895 struct files_struct
*fsp
;
1900 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
);
1902 static struct tevent_req
*vfs_gpfs_pwrite_send(
1903 struct vfs_handle_struct
*handle
,
1904 TALLOC_CTX
*mem_ctx
,
1905 struct tevent_context
*ev
,
1906 struct files_struct
*fsp
,
1907 const void *data
, size_t n
,
1910 struct tevent_req
*req
, *subreq
;
1911 struct vfs_gpfs_pwrite_state
*state
;
1913 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pwrite_state
);
1918 subreq
= SMB_VFS_NEXT_PWRITE_SEND(state
, ev
, handle
, fsp
, data
,
1920 if (tevent_req_nomem(subreq
, req
)) {
1921 return tevent_req_post(req
, ev
);
1923 tevent_req_set_callback(subreq
, vfs_gpfs_pwrite_done
, req
);
1927 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
)
1929 struct tevent_req
*req
= tevent_req_callback_data(
1930 subreq
, struct tevent_req
);
1931 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
1932 req
, struct vfs_gpfs_pwrite_state
);
1934 state
->ret
= SMB_VFS_PWRITE_RECV(subreq
, &state
->err
);
1935 TALLOC_FREE(subreq
);
1936 tevent_req_done(req
);
1939 static ssize_t
vfs_gpfs_pwrite_recv(struct tevent_req
*req
, int *err
)
1941 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
1942 req
, struct vfs_gpfs_pwrite_state
);
1943 struct files_struct
*fsp
= state
->fsp
;
1945 if (tevent_req_is_unix_error(req
, err
)) {
1950 DEBUG(10, ("vfs_private = %x\n",
1951 (unsigned int)fsp
->fsp_name
->st
.vfs_private
));
1953 if ((state
->ret
!= -1) &&
1954 ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0)) {
1955 fsp
->fsp_name
->st
.vfs_private
&= ~GPFS_WINATTR_OFFLINE
;
1956 DEBUG(10, ("sending notify\n"));
1957 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
1958 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
1959 fsp
->fsp_name
->base_name
);
1966 static struct vfs_fn_pointers vfs_gpfs_fns
= {
1967 .connect_fn
= vfs_gpfs_connect
,
1968 .disk_free_fn
= vfs_gpfs_disk_free
,
1969 .fs_capabilities_fn
= vfs_gpfs_capabilities
,
1970 .kernel_flock_fn
= vfs_gpfs_kernel_flock
,
1971 .linux_setlease_fn
= vfs_gpfs_setlease
,
1972 .get_real_filename_fn
= vfs_gpfs_get_real_filename
,
1973 .fget_nt_acl_fn
= gpfsacl_fget_nt_acl
,
1974 .get_nt_acl_fn
= gpfsacl_get_nt_acl
,
1975 .fset_nt_acl_fn
= gpfsacl_fset_nt_acl
,
1976 .sys_acl_get_file_fn
= gpfsacl_sys_acl_get_file
,
1977 .sys_acl_get_fd_fn
= gpfsacl_sys_acl_get_fd
,
1978 .sys_acl_blob_get_file_fn
= gpfsacl_sys_acl_blob_get_file
,
1979 .sys_acl_blob_get_fd_fn
= gpfsacl_sys_acl_blob_get_fd
,
1980 .sys_acl_set_file_fn
= gpfsacl_sys_acl_set_file
,
1981 .sys_acl_set_fd_fn
= gpfsacl_sys_acl_set_fd
,
1982 .sys_acl_delete_def_file_fn
= gpfsacl_sys_acl_delete_def_file
,
1983 .chmod_fn
= vfs_gpfs_chmod
,
1984 .fchmod_fn
= vfs_gpfs_fchmod
,
1985 .close_fn
= vfs_gpfs_close
,
1986 .setxattr_fn
= gpfs_set_xattr
,
1987 .getxattr_fn
= gpfs_get_xattr
,
1988 .stat_fn
= vfs_gpfs_stat
,
1989 .fstat_fn
= vfs_gpfs_fstat
,
1990 .lstat_fn
= vfs_gpfs_lstat
,
1991 .ntimes_fn
= vfs_gpfs_ntimes
,
1992 .is_offline_fn
= vfs_gpfs_is_offline
,
1993 .aio_force_fn
= vfs_gpfs_aio_force
,
1994 .sendfile_fn
= vfs_gpfs_sendfile
,
1995 .fallocate_fn
= vfs_gpfs_fallocate
,
1996 .open_fn
= vfs_gpfs_open
,
1997 .pread_fn
= vfs_gpfs_pread
,
1998 .pread_send_fn
= vfs_gpfs_pread_send
,
1999 .pread_recv_fn
= vfs_gpfs_pread_recv
,
2000 .pwrite_fn
= vfs_gpfs_pwrite
,
2001 .pwrite_send_fn
= vfs_gpfs_pwrite_send
,
2002 .pwrite_recv_fn
= vfs_gpfs_pwrite_recv
,
2003 .ftruncate_fn
= vfs_gpfs_ftruncate
2006 NTSTATUS
vfs_gpfs_init(void);
2007 NTSTATUS
vfs_gpfs_init(void)
2011 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "gpfs",