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 START_PROFILE(syscall_kernel_flock
);
66 kernel_flock(fsp
->fh
->fd
, share_mode
, access_mask
);
68 if (config
->sharemodes
69 && !set_gpfs_sharemode(fsp
, access_mask
, fsp
->share_access
)) {
73 END_PROFILE(syscall_kernel_flock
);
78 static int vfs_gpfs_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
81 struct gpfs_config_data
*config
;
83 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
84 struct gpfs_config_data
,
87 if (config
->sharemodes
&& (fsp
->fh
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
88 set_gpfs_sharemode(fsp
, 0, 0);
91 return SMB_VFS_NEXT_CLOSE(handle
, fsp
);
94 static int vfs_gpfs_setlease(vfs_handle_struct
*handle
, files_struct
*fsp
,
97 struct gpfs_config_data
*config
;
100 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
101 struct gpfs_config_data
,
104 if (linux_set_lease_sighandler(fsp
->fh
->fd
) == -1)
107 START_PROFILE(syscall_linux_setlease
);
109 if (config
->leases
) {
111 * Ensure the lease owner is root to allow
112 * correct delivery of lease-break signals.
115 ret
= set_gpfs_lease(fsp
->fh
->fd
,leasetype
);
119 END_PROFILE(syscall_linux_setlease
);
124 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct
*handle
,
132 char real_pathname
[PATH_MAX
+1];
135 struct gpfs_config_data
*config
;
137 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
138 struct gpfs_config_data
,
141 if (!config
->getrealfilename
) {
142 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
143 mem_ctx
, found_name
);
146 mangled
= mangle_is_mangled(name
, handle
->conn
->params
);
148 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
149 mem_ctx
, found_name
);
152 full_path
= talloc_asprintf(talloc_tos(), "%s/%s", path
, name
);
153 if (full_path
== NULL
) {
158 buflen
= sizeof(real_pathname
) - 1;
160 result
= smbd_gpfs_get_realfilename_path(full_path
, real_pathname
,
163 TALLOC_FREE(full_path
);
165 if ((result
== -1) && (errno
== ENOSYS
)) {
166 return SMB_VFS_NEXT_GET_REAL_FILENAME(
167 handle
, path
, name
, mem_ctx
, found_name
);
171 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
177 * GPFS does not necessarily null-terminate the returned path
178 * but instead returns the buffer length in buflen.
181 if (buflen
< sizeof(real_pathname
)) {
182 real_pathname
[buflen
] = '\0';
184 real_pathname
[sizeof(real_pathname
)-1] = '\0';
187 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
188 path
, name
, real_pathname
));
190 name
= strrchr_m(real_pathname
, '/');
196 *found_name
= talloc_strdup(mem_ctx
, name
+1);
197 if (*found_name
== NULL
) {
205 static void gpfs_dumpacl(int level
, struct gpfs_acl
*gacl
)
210 DEBUG(0, ("gpfs acl is NULL\n"));
214 DEBUG(level
, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n",
215 gacl
->acl_nace
, gacl
->acl_type
, gacl
->acl_version
, gacl
->acl_level
, gacl
->acl_len
));
216 for(i
=0; i
<gacl
->acl_nace
; i
++)
218 struct gpfs_ace_v4
*gace
= gacl
->ace_v4
+ i
;
219 DEBUG(level
, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n",
220 i
, gace
->aceType
, gace
->aceFlags
, gace
->aceMask
,
221 gace
->aceIFlags
, gace
->aceWho
));
225 static struct gpfs_acl
*gpfs_getacl_alloc(const char *fname
, gpfs_aclType_t type
)
227 struct gpfs_acl
*acl
;
230 TALLOC_CTX
*mem_ctx
= talloc_tos();
232 acl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, len
);
240 acl
->acl_version
= 0;
241 acl
->acl_type
= type
;
243 ret
= smbd_gpfs_getacl((char *)fname
, GPFS_GETACL_STRUCT
, acl
);
244 if ((ret
!= 0) && (errno
== ENOSPC
)) {
245 struct gpfs_acl
*new_acl
= (struct gpfs_acl
*)TALLOC_SIZE(
246 mem_ctx
, acl
->acl_len
+ sizeof(struct gpfs_acl
));
247 if (new_acl
== NULL
) {
252 new_acl
->acl_len
= acl
->acl_len
;
253 new_acl
->acl_level
= acl
->acl_level
;
254 new_acl
->acl_version
= acl
->acl_version
;
255 new_acl
->acl_type
= acl
->acl_type
;
258 ret
= smbd_gpfs_getacl((char *)fname
, GPFS_GETACL_STRUCT
, acl
);
262 DEBUG(8, ("smbd_gpfs_getacl failed with %s\n",strerror(errno
)));
269 /* Tries to get nfs4 acls and returns SMB ACL allocated.
270 * On failure returns 1 if it got non-NFSv4 ACL to prompt
271 * retry with POSIX ACL checks.
272 * On failure returns -1 if there is system (GPFS) error, check errno.
273 * Returns 0 on success
275 static int gpfs_get_nfs4_acl(const char *fname
, SMB4ACL_T
**ppacl
)
278 struct gpfs_acl
*gacl
= NULL
;
279 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname
));
281 /* First get the real acl length */
282 gacl
= gpfs_getacl_alloc(fname
, 0);
284 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
285 fname
, strerror(errno
)));
289 if (gacl
->acl_type
!= GPFS_ACL_TYPE_NFS4
) {
290 DEBUG(10, ("Got non-nfsv4 acl\n"));
291 /* Retry with POSIX ACLs check */
296 *ppacl
= smb_create_smb4acl();
298 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
299 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
302 for (i
=0; i
<gacl
->acl_nace
; i
++) {
303 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[i
];
304 SMB_ACE4PROP_T smbace
;
305 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
306 "who: %d\n", gace
->aceType
, gace
->aceIFlags
,
307 gace
->aceFlags
, gace
->aceMask
, gace
->aceWho
));
310 if (gace
->aceIFlags
& ACE4_IFLAG_SPECIAL_ID
) {
311 smbace
.flags
|= SMB_ACE4_ID_SPECIAL
;
312 switch (gace
->aceWho
) {
313 case ACE4_SPECIAL_OWNER
:
314 smbace
.who
.special_id
= SMB_ACE4_WHO_OWNER
;
316 case ACE4_SPECIAL_GROUP
:
317 smbace
.who
.special_id
= SMB_ACE4_WHO_GROUP
;
319 case ACE4_SPECIAL_EVERYONE
:
320 smbace
.who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
323 DEBUG(8, ("invalid special gpfs id %d "
324 "ignored\n", gace
->aceWho
));
325 continue; /* don't add it */
328 if (gace
->aceFlags
& ACE4_FLAG_GROUP_ID
)
329 smbace
.who
.gid
= gace
->aceWho
;
331 smbace
.who
.uid
= gace
->aceWho
;
334 /* remove redundent deny entries */
335 if (i
> 0 && gace
->aceType
== SMB_ACE4_ACCESS_DENIED_ACE_TYPE
) {
336 struct gpfs_ace_v4
*prev
= &gacl
->ace_v4
[i
-1];
337 if (prev
->aceType
== SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
&&
338 prev
->aceFlags
== gace
->aceFlags
&&
339 prev
->aceIFlags
== gace
->aceIFlags
&&
340 (gace
->aceMask
& prev
->aceMask
) == 0 &&
341 gace
->aceWho
== prev
->aceWho
) {
342 /* its redundent - skip it */
347 smbace
.aceType
= gace
->aceType
;
348 smbace
.aceFlags
= gace
->aceFlags
;
349 smbace
.aceMask
= gace
->aceMask
;
350 smb_add_ace4(*ppacl
, &smbace
);
356 static NTSTATUS
gpfsacl_fget_nt_acl(vfs_handle_struct
*handle
,
357 files_struct
*fsp
, uint32 security_info
,
359 struct security_descriptor
**ppdesc
)
361 SMB4ACL_T
*pacl
= NULL
;
363 struct gpfs_config_data
*config
;
367 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
368 struct gpfs_config_data
,
369 return NT_STATUS_INTERNAL_ERROR
);
372 return SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
376 result
= gpfs_get_nfs4_acl(fsp
->fsp_name
->base_name
, &pacl
);
379 return smb_fget_nt_acl_nfs4(fsp
, security_info
, mem_ctx
, ppdesc
, pacl
);
382 DEBUG(10, ("retrying with posix acl...\n"));
383 return posix_fget_nt_acl(fsp
, security_info
, mem_ctx
, ppdesc
);
386 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
387 return map_nt_error_from_unix(errno
);
390 static NTSTATUS
gpfsacl_get_nt_acl(vfs_handle_struct
*handle
,
392 uint32 security_info
,
393 TALLOC_CTX
*mem_ctx
, struct security_descriptor
**ppdesc
)
395 SMB4ACL_T
*pacl
= NULL
;
397 struct gpfs_config_data
*config
;
401 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
402 struct gpfs_config_data
,
403 return NT_STATUS_INTERNAL_ERROR
);
406 return SMB_VFS_NEXT_GET_NT_ACL(handle
, name
, security_info
,
410 result
= gpfs_get_nfs4_acl(name
, &pacl
);
413 return smb_get_nt_acl_nfs4(handle
->conn
, name
, security_info
,
414 mem_ctx
, ppdesc
, pacl
);
417 DEBUG(10, ("retrying with posix acl...\n"));
418 return posix_get_nt_acl(handle
->conn
, name
, security_info
,
422 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
423 return map_nt_error_from_unix(errno
);
426 static bool gpfsacl_process_smbacl(files_struct
*fsp
, SMB4ACL_T
*smbacl
)
429 gpfs_aclLen_t gacl_len
;
431 struct gpfs_acl
*gacl
;
432 TALLOC_CTX
*mem_ctx
= talloc_tos();
434 gacl_len
= offsetof(gpfs_acl_t
, ace_v4
) + smb_get_naces(smbacl
) *
435 sizeof(gpfs_ace_v4_t
);
437 gacl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, gacl_len
);
439 DEBUG(0, ("talloc failed\n"));
444 gacl
->acl_len
= gacl_len
;
446 gacl
->acl_version
= GPFS_ACL_VERSION_NFS4
;
447 gacl
->acl_type
= GPFS_ACL_TYPE_NFS4
;
448 gacl
->acl_nace
= 0; /* change later... */
450 for (smbace
=smb_first_ace4(smbacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
451 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[gacl
->acl_nace
];
452 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
454 gace
->aceType
= aceprop
->aceType
;
455 gace
->aceFlags
= aceprop
->aceFlags
;
456 gace
->aceMask
= aceprop
->aceMask
;
459 * GPFS can't distinguish between WRITE and APPEND on
460 * files, so one being set without the other is an
461 * error. Sorry for the many ()'s :-)
464 if (!fsp
->is_directory
466 ((((gace
->aceMask
& ACE4_MASK_WRITE
) == 0)
467 && ((gace
->aceMask
& ACE4_MASK_APPEND
) != 0))
469 (((gace
->aceMask
& ACE4_MASK_WRITE
) != 0)
470 && ((gace
->aceMask
& ACE4_MASK_APPEND
) == 0)))
472 lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
473 "merge_writeappend", True
)) {
474 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
475 "WRITE^APPEND, setting WRITE|APPEND\n",
477 gace
->aceMask
|= ACE4_MASK_WRITE
|ACE4_MASK_APPEND
;
480 gace
->aceIFlags
= (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
) ? ACE4_IFLAG_SPECIAL_ID
: 0;
482 if (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
)
484 switch(aceprop
->who
.special_id
)
486 case SMB_ACE4_WHO_EVERYONE
:
487 gace
->aceWho
= ACE4_SPECIAL_EVERYONE
;
489 case SMB_ACE4_WHO_OWNER
:
490 gace
->aceWho
= ACE4_SPECIAL_OWNER
;
492 case SMB_ACE4_WHO_GROUP
:
493 gace
->aceWho
= ACE4_SPECIAL_GROUP
;
496 DEBUG(8, ("unsupported special_id %d\n", aceprop
->who
.special_id
));
497 continue; /* don't add it !!! */
500 /* just only for the type safety... */
501 if (aceprop
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)
502 gace
->aceWho
= aceprop
->who
.gid
;
504 gace
->aceWho
= aceprop
->who
.uid
;
510 ret
= smbd_gpfs_putacl(fsp
->fsp_name
->base_name
,
511 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gacl
);
513 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno
)));
514 gpfs_dumpacl(8, gacl
);
518 DEBUG(10, ("gpfs_putacl succeeded\n"));
522 static NTSTATUS
gpfsacl_set_nt_acl_internal(files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
524 struct gpfs_acl
*acl
;
525 NTSTATUS result
= NT_STATUS_ACCESS_DENIED
;
527 acl
= gpfs_getacl_alloc(fsp
->fsp_name
->base_name
, 0);
531 if (acl
->acl_version
&GPFS_ACL_VERSION_NFS4
)
533 if (lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
534 "refuse_dacl_protected", false)
535 && (psd
->type
&SEC_DESC_DACL_PROTECTED
)) {
536 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
537 return NT_STATUS_NOT_SUPPORTED
;
540 result
= smb_set_nt_acl_nfs4(
541 fsp
, security_info_sent
, psd
,
542 gpfsacl_process_smbacl
);
543 } else { /* assume POSIX ACL - by default... */
544 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
550 static NTSTATUS
gpfsacl_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
552 struct gpfs_config_data
*config
;
554 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
555 struct gpfs_config_data
,
556 return NT_STATUS_INTERNAL_ERROR
);
559 return SMB_VFS_NEXT_FSET_NT_ACL(handle
, fsp
, security_info_sent
, psd
);
562 return gpfsacl_set_nt_acl_internal(fsp
, security_info_sent
, psd
);
565 static SMB_ACL_T
gpfs2smb_acl(const struct gpfs_acl
*pacl
, TALLOC_CTX
*mem_ctx
)
570 result
= sys_acl_init(mem_ctx
);
571 if (result
== NULL
) {
576 result
->count
= pacl
->acl_nace
;
577 result
->acl
= talloc_realloc(result
, result
->acl
, struct smb_acl_entry
,
579 if (result
->acl
== NULL
) {
585 for (i
=0; i
<pacl
->acl_nace
; i
++) {
586 struct smb_acl_entry
*ace
= &result
->acl
[i
];
587 const struct gpfs_ace_v1
*g_ace
= &pacl
->ace_v1
[i
];
589 DEBUG(10, ("Converting type %d id %lu perm %x\n",
590 (int)g_ace
->ace_type
, (unsigned long)g_ace
->ace_who
,
591 (int)g_ace
->ace_perm
));
593 switch (g_ace
->ace_type
) {
595 ace
->a_type
= SMB_ACL_USER
;
596 ace
->info
.user
.uid
= (uid_t
)g_ace
->ace_who
;
598 case GPFS_ACL_USER_OBJ
:
599 ace
->a_type
= SMB_ACL_USER_OBJ
;
602 ace
->a_type
= SMB_ACL_GROUP
;
603 ace
->info
.group
.gid
= (gid_t
)g_ace
->ace_who
;
605 case GPFS_ACL_GROUP_OBJ
:
606 ace
->a_type
= SMB_ACL_GROUP_OBJ
;
609 ace
->a_type
= SMB_ACL_OTHER
;
612 ace
->a_type
= SMB_ACL_MASK
;
615 DEBUG(10, ("Got invalid ace_type: %d\n",
623 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_READ
) ?
625 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_WRITE
) ?
627 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_EXECUTE
) ?
630 DEBUGADD(10, ("Converted to %d perm %x\n",
631 ace
->a_type
, ace
->a_perm
));
637 static SMB_ACL_T
gpfsacl_get_posix_acl(const char *path
, gpfs_aclType_t type
,
640 struct gpfs_acl
*pacl
;
641 SMB_ACL_T result
= NULL
;
643 pacl
= gpfs_getacl_alloc(path
, type
);
646 DEBUG(10, ("gpfs_getacl failed for %s with %s\n",
647 path
, strerror(errno
)));
654 if (pacl
->acl_version
!= GPFS_ACL_VERSION_POSIX
) {
655 DEBUG(10, ("Got acl version %d, expected %d\n",
656 pacl
->acl_version
, GPFS_ACL_VERSION_POSIX
));
661 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
662 pacl
->acl_len
, pacl
->acl_level
, pacl
->acl_version
,
665 result
= gpfs2smb_acl(pacl
, mem_ctx
);
666 if (result
!= NULL
) {
681 static SMB_ACL_T
gpfsacl_sys_acl_get_file(vfs_handle_struct
*handle
,
686 gpfs_aclType_t gpfs_type
;
687 struct gpfs_config_data
*config
;
689 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
690 struct gpfs_config_data
,
694 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle
, path_p
,
699 case SMB_ACL_TYPE_ACCESS
:
700 gpfs_type
= GPFS_ACL_TYPE_ACCESS
;
702 case SMB_ACL_TYPE_DEFAULT
:
703 gpfs_type
= GPFS_ACL_TYPE_DEFAULT
;
706 DEBUG(0, ("Got invalid type: %d\n", type
));
707 smb_panic("exiting");
710 return gpfsacl_get_posix_acl(path_p
, gpfs_type
, mem_ctx
);
713 static SMB_ACL_T
gpfsacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
717 struct gpfs_config_data
*config
;
719 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
720 struct gpfs_config_data
,
724 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle
, fsp
, mem_ctx
);
727 return gpfsacl_get_posix_acl(fsp
->fsp_name
->base_name
,
728 GPFS_ACL_TYPE_ACCESS
, mem_ctx
);
731 static struct gpfs_acl
*smb2gpfs_acl(const SMB_ACL_T pacl
,
735 struct gpfs_acl
*result
;
738 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl
->count
));
740 len
= offsetof(gpfs_acl_t
, ace_v1
) + (pacl
->count
) *
741 sizeof(gpfs_ace_v1_t
);
743 result
= (struct gpfs_acl
*)SMB_MALLOC(len
);
744 if (result
== NULL
) {
749 result
->acl_len
= len
;
750 result
->acl_level
= 0;
751 result
->acl_version
= GPFS_ACL_VERSION_POSIX
;
752 result
->acl_type
= (type
== SMB_ACL_TYPE_DEFAULT
) ?
753 GPFS_ACL_TYPE_DEFAULT
: GPFS_ACL_TYPE_ACCESS
;
754 result
->acl_nace
= pacl
->count
;
756 for (i
=0; i
<pacl
->count
; i
++) {
757 const struct smb_acl_entry
*ace
= &pacl
->acl
[i
];
758 struct gpfs_ace_v1
*g_ace
= &result
->ace_v1
[i
];
760 DEBUG(10, ("Converting type %d perm %x\n",
761 (int)ace
->a_type
, (int)ace
->a_perm
));
765 switch(ace
->a_type
) {
767 g_ace
->ace_type
= GPFS_ACL_USER
;
768 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.user
.uid
;
770 case SMB_ACL_USER_OBJ
:
771 g_ace
->ace_type
= GPFS_ACL_USER_OBJ
;
772 g_ace
->ace_perm
|= ACL_PERM_CONTROL
;
776 g_ace
->ace_type
= GPFS_ACL_GROUP
;
777 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.group
.gid
;
779 case SMB_ACL_GROUP_OBJ
:
780 g_ace
->ace_type
= GPFS_ACL_GROUP_OBJ
;
784 g_ace
->ace_type
= GPFS_ACL_MASK
;
785 g_ace
->ace_perm
= 0x8f;
789 g_ace
->ace_type
= GPFS_ACL_OTHER
;
793 DEBUG(10, ("Got invalid ace_type: %d\n", ace
->a_type
));
799 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_READ
) ?
801 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_WRITE
) ?
803 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_EXECUTE
) ?
804 ACL_PERM_EXECUTE
: 0;
806 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
807 g_ace
->ace_type
, g_ace
->ace_who
, g_ace
->ace_perm
));
813 static int gpfsacl_sys_acl_set_file(vfs_handle_struct
*handle
,
818 struct gpfs_acl
*gpfs_acl
;
820 struct gpfs_config_data
*config
;
822 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
823 struct gpfs_config_data
,
827 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle
, name
, type
, theacl
);
830 gpfs_acl
= smb2gpfs_acl(theacl
, type
);
831 if (gpfs_acl
== NULL
) {
835 result
= smbd_gpfs_putacl((char *)name
, GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gpfs_acl
);
841 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
845 struct gpfs_config_data
*config
;
847 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
848 struct gpfs_config_data
,
852 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle
, fsp
, theacl
);
855 return gpfsacl_sys_acl_set_file(handle
, fsp
->fsp_name
->base_name
,
856 SMB_ACL_TYPE_ACCESS
, theacl
);
859 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
862 struct gpfs_config_data
*config
;
864 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
865 struct gpfs_config_data
,
869 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle
, path
);
877 * Assumed: mode bits are shiftable and standard
878 * Output: the new aceMask field for an smb nfs4 ace
880 static uint32
gpfsacl_mask_filter(uint32 aceType
, uint32 aceMask
, uint32 rwx
)
882 const uint32 posix_nfs4map
[3] = {
883 SMB_ACE4_EXECUTE
, /* execute */
884 SMB_ACE4_WRITE_DATA
| SMB_ACE4_APPEND_DATA
, /* write; GPFS specific */
885 SMB_ACE4_READ_DATA
/* read */
888 uint32_t posix_mask
= 0x01;
893 nfs4_bits
= posix_nfs4map
[i
];
894 posix_bit
= rwx
& posix_mask
;
896 if (aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
) {
898 aceMask
|= nfs4_bits
;
900 aceMask
&= ~nfs4_bits
;
902 /* add deny bits when suitable */
904 aceMask
|= nfs4_bits
;
906 aceMask
&= ~nfs4_bits
;
907 } /* other ace types are unexpected */
915 static int gpfsacl_emu_chmod(const char *path
, mode_t mode
)
917 SMB4ACL_T
*pacl
= NULL
;
919 bool haveAllowEntry
[SMB_ACE4_WHO_EVERYONE
+ 1] = {False
, False
, False
, False
};
921 files_struct fake_fsp
; /* TODO: rationalize parametrization */
925 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path
, mode
));
927 result
= gpfs_get_nfs4_acl(path
, &pacl
);
931 if (mode
& ~(S_IRWXU
| S_IRWXG
| S_IRWXO
)) {
932 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode
, path
));
935 for (smbace
=smb_first_ace4(pacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
936 SMB_ACE4PROP_T
*ace
= smb_get_ace4(smbace
);
937 uint32_t specid
= ace
->who
.special_id
;
939 if (ace
->flags
&SMB_ACE4_ID_SPECIAL
&&
940 ace
->aceType
<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE
&&
941 specid
<= SMB_ACE4_WHO_EVERYONE
) {
945 if (ace
->aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
)
946 haveAllowEntry
[specid
] = True
;
948 /* mode >> 6 for @owner, mode >> 3 for @group,
949 * mode >> 0 for @everyone */
950 newMask
= gpfsacl_mask_filter(ace
->aceType
, ace
->aceMask
,
951 mode
>> ((SMB_ACE4_WHO_EVERYONE
- specid
) * 3));
952 if (ace
->aceMask
!=newMask
) {
953 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
954 path
, ace
->aceMask
, newMask
, specid
));
956 ace
->aceMask
= newMask
;
960 /* make sure we have at least ALLOW entries
961 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
964 for(i
= SMB_ACE4_WHO_OWNER
; i
<=SMB_ACE4_WHO_EVERYONE
; i
++) {
967 if (haveAllowEntry
[i
]==True
)
971 ace
.aceType
= SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
;
972 ace
.flags
|= SMB_ACE4_ID_SPECIAL
;
973 ace
.who
.special_id
= i
;
975 if (i
==SMB_ACE4_WHO_GROUP
) /* not sure it's necessary... */
976 ace
.aceFlags
|= SMB_ACE4_IDENTIFIER_GROUP
;
978 ace
.aceMask
= gpfsacl_mask_filter(ace
.aceType
, ace
.aceMask
,
979 mode
>> ((SMB_ACE4_WHO_EVERYONE
- i
) * 3));
981 /* don't add unnecessary aces */
985 /* we add it to the END - as windows expects allow aces */
986 smb_add_ace4(pacl
, &ace
);
987 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
988 path
, mode
, i
, ace
.aceMask
));
991 /* don't add complementary DENY ACEs here */
992 ZERO_STRUCT(fake_fsp
);
993 status
= create_synthetic_smb_fname(talloc_tos(), path
, NULL
, NULL
,
995 if (!NT_STATUS_IS_OK(status
)) {
996 errno
= map_errno_from_nt_status(status
);
1000 if (gpfsacl_process_smbacl(&fake_fsp
, pacl
) == False
) {
1001 TALLOC_FREE(fake_fsp
.fsp_name
);
1005 TALLOC_FREE(fake_fsp
.fsp_name
);
1006 return 0; /* ok for [f]chmod */
1009 static int vfs_gpfs_chmod(vfs_handle_struct
*handle
, const char *path
, mode_t mode
)
1011 struct smb_filename
*smb_fname_cpath
;
1015 status
= create_synthetic_smb_fname(
1016 talloc_tos(), path
, NULL
, NULL
, &smb_fname_cpath
);
1018 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_cpath
) != 0) {
1022 /* avoid chmod() if possible, to preserve acls */
1023 if ((smb_fname_cpath
->st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1027 rc
= gpfsacl_emu_chmod(path
, mode
);
1029 return SMB_VFS_NEXT_CHMOD(handle
, path
, mode
);
1033 static int vfs_gpfs_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
1038 if (SMB_VFS_NEXT_FSTAT(handle
, fsp
, &st
) != 0) {
1042 /* avoid chmod() if possible, to preserve acls */
1043 if ((st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1047 rc
= gpfsacl_emu_chmod(fsp
->fsp_name
->base_name
, mode
);
1049 return SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
1053 static int gpfs_set_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1054 const char *name
, const void *value
, size_t size
, int flags
){
1055 struct xattr_DOSATTRIB dosattrib
;
1056 enum ndr_err_code ndr_err
;
1058 const char *attrstr
= value
;
1059 unsigned int dosmode
=0;
1060 struct gpfs_winattr attrs
;
1062 struct gpfs_config_data
*config
;
1064 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1065 struct gpfs_config_data
,
1068 if (!config
->winattr
) {
1069 DEBUG(10, ("gpfs_set_xattr:name is %s -> next\n",name
));
1070 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1073 DEBUG(10, ("gpfs_set_xattr: %s \n",path
));
1075 /* Only handle DOS Attributes */
1076 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1077 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name
));
1078 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1081 blob
.data
= (uint8_t *)attrstr
;
1084 ndr_err
= ndr_pull_struct_blob(&blob
, talloc_tos(), &dosattrib
,
1085 (ndr_pull_flags_fn_t
)ndr_pull_xattr_DOSATTRIB
);
1087 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1088 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
1089 "from EA on file %s: Error = %s\n",
1090 path
, ndr_errstr(ndr_err
)));
1094 if (dosattrib
.version
!= 3) {
1095 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
1096 "%d\n", (int)dosattrib
.version
));
1099 if (!(dosattrib
.info
.info3
.valid_flags
& XATTR_DOSINFO_ATTRIB
)) {
1100 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
1101 "valid, ignoring\n"));
1105 dosmode
= dosattrib
.info
.info3
.attrib
;
1108 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
1109 if (dosmode
& FILE_ATTRIBUTE_ARCHIVE
){
1110 attrs
.winAttrs
|= GPFS_WINATTR_ARCHIVE
;
1112 if (dosmode
& FILE_ATTRIBUTE_HIDDEN
){
1113 attrs
.winAttrs
|= GPFS_WINATTR_HIDDEN
;
1115 if (dosmode
& FILE_ATTRIBUTE_SYSTEM
){
1116 attrs
.winAttrs
|= GPFS_WINATTR_SYSTEM
;
1118 if (dosmode
& FILE_ATTRIBUTE_READONLY
){
1119 attrs
.winAttrs
|= GPFS_WINATTR_READONLY
;
1121 if (dosmode
& FILE_ATTRIBUTE_SPARSE
) {
1122 attrs
.winAttrs
|= GPFS_WINATTR_SPARSE_FILE
;
1126 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1127 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1129 if (errno
== ENOSYS
) {
1130 return SMB_VFS_NEXT_SETXATTR(handle
, path
, name
, value
,
1134 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret
));
1138 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs
.winAttrs
));
1142 static ssize_t
gpfs_get_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1143 const char *name
, void *value
, size_t size
){
1144 char *attrstr
= value
;
1145 unsigned int dosmode
= 0;
1146 struct gpfs_winattr attrs
;
1148 struct gpfs_config_data
*config
;
1150 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1151 struct gpfs_config_data
,
1154 if (!config
->winattr
) {
1155 DEBUG(10, ("gpfs_get_xattr:name is %s -> next\n",name
));
1156 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1159 DEBUG(10, ("gpfs_get_xattr: %s \n",path
));
1161 /* Only handle DOS Attributes */
1162 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1163 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name
));
1164 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1167 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1169 if (errno
== ENOSYS
) {
1170 return SMB_VFS_NEXT_GETXATTR(handle
, path
, name
, value
,
1174 DEBUG(1, ("gpfs_get_xattr: Get GPFS attributes failed: "
1175 "%d (%s)\n", ret
, strerror(errno
)));
1179 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs
.winAttrs
));
1181 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1182 if (attrs
.winAttrs
& GPFS_WINATTR_ARCHIVE
){
1183 dosmode
|= FILE_ATTRIBUTE_ARCHIVE
;
1185 if (attrs
.winAttrs
& GPFS_WINATTR_HIDDEN
){
1186 dosmode
|= FILE_ATTRIBUTE_HIDDEN
;
1188 if (attrs
.winAttrs
& GPFS_WINATTR_SYSTEM
){
1189 dosmode
|= FILE_ATTRIBUTE_SYSTEM
;
1191 if (attrs
.winAttrs
& GPFS_WINATTR_READONLY
){
1192 dosmode
|= FILE_ATTRIBUTE_READONLY
;
1194 if (attrs
.winAttrs
& GPFS_WINATTR_SPARSE_FILE
) {
1195 dosmode
|= FILE_ATTRIBUTE_SPARSE
;
1198 snprintf(attrstr
, size
, "0x%2.2x",
1199 (unsigned int)(dosmode
& SAMBA_ATTRIBUTES_MASK
));
1200 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr
));
1204 static int vfs_gpfs_stat(struct vfs_handle_struct
*handle
,
1205 struct smb_filename
*smb_fname
)
1207 struct gpfs_winattr attrs
;
1211 struct gpfs_config_data
*config
;
1213 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1214 struct gpfs_config_data
,
1217 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
1222 if (!config
->winattr
) {
1226 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &fname
);
1227 if (!NT_STATUS_IS_OK(status
)) {
1228 errno
= map_errno_from_nt_status(status
);
1231 ret
= get_gpfs_winattrs(discard_const_p(char, fname
), &attrs
);
1234 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1235 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1236 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1237 smb_fname
->st
.vfs_private
= attrs
.winAttrs
;
1242 static int vfs_gpfs_fstat(struct vfs_handle_struct
*handle
,
1243 struct files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
1245 struct gpfs_winattr attrs
;
1247 struct gpfs_config_data
*config
;
1249 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1250 struct gpfs_config_data
,
1253 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
1257 if ((fsp
->fh
== NULL
) || (fsp
->fh
->fd
== -1)) {
1260 if (!config
->winattr
) {
1264 ret
= smbd_fget_gpfs_winattrs(fsp
->fh
->fd
, &attrs
);
1266 sbuf
->st_ex_calculated_birthtime
= false;
1267 sbuf
->st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1268 sbuf
->st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1273 static int vfs_gpfs_lstat(struct vfs_handle_struct
*handle
,
1274 struct smb_filename
*smb_fname
)
1276 struct gpfs_winattr attrs
;
1280 struct gpfs_config_data
*config
;
1282 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1283 struct gpfs_config_data
,
1286 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
1290 if (!config
->winattr
) {
1294 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1295 if (!NT_STATUS_IS_OK(status
)) {
1296 errno
= map_errno_from_nt_status(status
);
1299 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1302 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1303 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1304 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1305 smb_fname
->st
.vfs_private
= attrs
.winAttrs
;
1310 static int vfs_gpfs_ntimes(struct vfs_handle_struct
*handle
,
1311 const struct smb_filename
*smb_fname
,
1312 struct smb_file_time
*ft
)
1315 struct gpfs_winattr attrs
;
1319 struct gpfs_config_data
*config
;
1321 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1322 struct gpfs_config_data
,
1325 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1327 /* don't complain if access was denied */
1328 if (errno
!= EPERM
&& errno
!= EACCES
) {
1329 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1330 "%s", strerror(errno
)));
1335 if(null_timespec(ft
->create_time
)){
1336 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1340 if (!config
->winattr
) {
1344 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1345 if (!NT_STATUS_IS_OK(status
)) {
1346 errno
= map_errno_from_nt_status(status
);
1351 attrs
.creationTime
.tv_sec
= ft
->create_time
.tv_sec
;
1352 attrs
.creationTime
.tv_nsec
= ft
->create_time
.tv_nsec
;
1354 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1355 GPFS_WINATTR_SET_CREATION_TIME
, &attrs
);
1356 if(ret
== -1 && errno
!= ENOSYS
){
1357 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret
));
1364 static int vfs_gpfs_fallocate(struct vfs_handle_struct
*handle
,
1365 struct files_struct
*fsp
, enum vfs_fallocate_mode mode
,
1366 off_t offset
, off_t len
)
1369 struct gpfs_config_data
*config
;
1371 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1372 struct gpfs_config_data
,
1375 if (!config
->prealloc
) {
1376 /* you should better not run fallocate() on GPFS at all */
1381 if (mode
== VFS_FALLOCATE_KEEP_SIZE
) {
1382 DEBUG(10, ("Unsupported VFS_FALLOCATE_KEEP_SIZE\n"));
1387 ret
= smbd_gpfs_prealloc(fsp
->fh
->fd
, offset
, len
);
1389 if (ret
== -1 && errno
!= ENOSYS
) {
1390 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno
)));
1391 } else if (ret
== -1 && errno
== ENOSYS
) {
1392 DEBUG(10, ("GPFS prealloc not supported.\n"));
1394 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1400 static int vfs_gpfs_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1404 struct gpfs_config_data
*config
;
1406 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1407 struct gpfs_config_data
,
1410 if (!config
->ftruncate
) {
1411 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1414 result
= smbd_gpfs_ftruncate(fsp
->fh
->fd
, len
);
1415 if ((result
== -1) && (errno
== ENOSYS
)) {
1416 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1421 static bool vfs_gpfs_is_offline(struct vfs_handle_struct
*handle
,
1422 const struct smb_filename
*fname
,
1423 SMB_STRUCT_STAT
*sbuf
)
1425 struct gpfs_winattr attrs
;
1428 struct gpfs_config_data
*config
;
1430 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1431 struct gpfs_config_data
,
1434 if (!config
->winattr
) {
1435 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1438 status
= get_full_smb_filename(talloc_tos(), fname
, &path
);
1439 if (!NT_STATUS_IS_OK(status
)) {
1440 errno
= map_errno_from_nt_status(status
);
1444 if (VALID_STAT(*sbuf
)) {
1445 attrs
.winAttrs
= sbuf
->vfs_private
;
1448 ret
= get_gpfs_winattrs(path
, &attrs
);
1455 if ((attrs
.winAttrs
& GPFS_WINATTR_OFFLINE
) != 0) {
1456 DEBUG(10, ("%s is offline\n", path
));
1460 DEBUG(10, ("%s is online\n", path
));
1462 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1465 static bool vfs_gpfs_aio_force(struct vfs_handle_struct
*handle
,
1466 struct files_struct
*fsp
)
1468 return vfs_gpfs_is_offline(handle
, fsp
->fsp_name
, &fsp
->fsp_name
->st
);
1471 static ssize_t
vfs_gpfs_sendfile(vfs_handle_struct
*handle
, int tofd
,
1472 files_struct
*fsp
, const DATA_BLOB
*hdr
,
1473 off_t offset
, size_t n
)
1475 if ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0) {
1479 return SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fsp
, hdr
, offset
, n
);
1482 static int vfs_gpfs_connect(struct vfs_handle_struct
*handle
,
1483 const char *service
, const char *user
)
1485 struct gpfs_config_data
*config
;
1488 smbd_gpfs_lib_init();
1490 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1496 config
= talloc_zero(handle
->conn
, struct gpfs_config_data
);
1498 SMB_VFS_NEXT_DISCONNECT(handle
);
1499 DEBUG(0, ("talloc_zero() failed\n"));
1503 config
->sharemodes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1504 "sharemodes", true);
1506 config
->leases
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1509 config
->hsm
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1512 config
->syncio
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1515 config
->winattr
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1518 config
->ftruncate
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1521 config
->getrealfilename
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1522 "getrealfilename", true);
1524 config
->dfreequota
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1525 "dfreequota", false);
1527 config
->prealloc
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1530 config
->acl
= lp_parm_bool(SNUM(handle
->conn
), "gpfs", "acl", true);
1532 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
1533 NULL
, struct gpfs_config_data
,
1536 if (config
->leases
) {
1538 * GPFS lease code is based on kernel oplock code
1539 * so make sure it is turned on
1541 if (!lp_kernel_oplocks(SNUM(handle
->conn
))) {
1542 DEBUG(5, ("Enabling kernel oplocks for "
1543 "gpfs:leases to work\n"));
1544 lp_do_parameter(SNUM(handle
->conn
), "kernel oplocks",
1549 * as the kernel does not properly support Level II oplocks
1550 * and GPFS leases code is based on kernel infrastructure, we
1551 * need to turn off Level II oplocks if gpfs:leases is enabled
1553 if (lp_level2_oplocks(SNUM(handle
->conn
))) {
1554 DEBUG(5, ("gpfs:leases are enabled, disabling "
1555 "Level II oplocks\n"));
1556 lp_do_parameter(SNUM(handle
->conn
), "level2 oplocks",
1564 static int vfs_gpfs_get_quotas(const char *path
, uid_t uid
, gid_t gid
,
1566 struct gpfs_quotaInfo
*qi_user
,
1567 struct gpfs_quotaInfo
*qi_group
,
1568 struct gpfs_quotaInfo
*qi_fset
)
1575 * We want to always use the directory to get the fileset id,
1576 * because files might have a share mode. We also do not want
1577 * to get the parent directory when there is already a
1578 * directory to avoid stepping in a different fileset. The
1579 * path passed here is currently either "." or a filename, so
1580 * this is ok. The proper solution would be having a way to
1581 * query the fileset id without opening the file.
1583 b
= parent_dirname(talloc_tos(), path
, &dir_path
, NULL
);
1589 DEBUG(10, ("path %s, directory %s\n", path
, dir_path
));
1591 err
= get_gpfs_fset_id(dir_path
, fset_id
);
1593 DEBUG(0, ("Get fset id failed path %s, dir %s, errno %d.\n",
1594 path
, dir_path
, errno
));
1598 err
= get_gpfs_quota(path
, GPFS_USRQUOTA
, uid
, qi_user
);
1603 err
= get_gpfs_quota(path
, GPFS_GRPQUOTA
, gid
, qi_group
);
1608 err
= get_gpfs_quota(path
, GPFS_FILESETQUOTA
, *fset_id
, qi_fset
);
1616 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi
, time_t cur_time
,
1617 uint64_t *dfree
, uint64_t *dsize
)
1619 uint64_t usage
, limit
;
1622 * The quota reporting is done in units of 1024 byte blocks, but
1623 * sys_fsusage uses units of 512 byte blocks, adjust the block number
1624 * accordingly. Also filter possibly negative usage counts from gpfs.
1626 usage
= qi
.blockUsage
< 0 ? 0 : (uint64_t)qi
.blockUsage
* 2;
1627 limit
= (uint64_t)qi
.blockHardLimit
* 2;
1630 * When the grace time for the exceeded soft block quota has been
1631 * exceeded, the soft block quota becomes an additional hard limit.
1633 if (qi
.blockSoftLimit
&&
1634 qi
.blockGraceTime
&& cur_time
> qi
.blockGraceTime
) {
1635 /* report disk as full */
1637 *dsize
= MIN(*dsize
, usage
);
1640 if (!qi
.blockHardLimit
)
1643 if (usage
>= limit
) {
1644 /* report disk as full */
1646 *dsize
= MIN(*dsize
, usage
);
1649 /* limit has not been reached, determine "free space" */
1650 *dfree
= MIN(*dfree
, limit
- usage
);
1651 *dsize
= MIN(*dsize
, limit
);
1655 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct
*handle
, const char *path
,
1656 bool small_query
, uint64_t *bsize
,
1657 uint64_t *dfree
, uint64_t *dsize
)
1659 struct security_unix_token
*utok
;
1660 struct gpfs_quotaInfo qi_user
, qi_group
, qi_fset
;
1661 struct gpfs_config_data
*config
;
1665 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct gpfs_config_data
,
1666 return (uint64_t)-1);
1667 if (!config
->dfreequota
) {
1668 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1669 bsize
, dfree
, dsize
);
1672 err
= sys_fsusage(path
, dfree
, dsize
);
1674 DEBUG (0, ("Could not get fs usage, errno %d\n", errno
));
1675 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1676 bsize
, dfree
, dsize
);
1679 /* sys_fsusage returns units of 512 bytes */
1682 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
1683 (unsigned long long)*dfree
, (unsigned long long)*dsize
));
1685 utok
= handle
->conn
->session_info
->unix_token
;
1686 err
= vfs_gpfs_get_quotas(path
, utok
->uid
, utok
->gid
, &fset_id
,
1687 &qi_user
, &qi_group
, &qi_fset
);
1689 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1690 bsize
, dfree
, dsize
);
1693 cur_time
= time(NULL
);
1695 /* Adjust free space and size according to quota limits. */
1696 vfs_gpfs_disk_free_quota(qi_user
, cur_time
, dfree
, dsize
);
1697 vfs_gpfs_disk_free_quota(qi_group
, cur_time
, dfree
, dsize
);
1699 /* Id 0 indicates the default quota, not an actual quota */
1701 vfs_gpfs_disk_free_quota(qi_fset
, cur_time
, dfree
, dsize
);
1704 disk_norm(small_query
, bsize
, dfree
, dsize
);
1708 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct
*handle
,
1709 enum timestamp_set_resolution
*p_ts_res
)
1711 struct gpfs_config_data
*config
;
1714 next
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
1716 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1717 struct gpfs_config_data
,
1721 next
|= FILE_SUPPORTS_REMOTE_STORAGE
;
1726 static int vfs_gpfs_open(struct vfs_handle_struct
*handle
,
1727 struct smb_filename
*smb_fname
, files_struct
*fsp
,
1728 int flags
, mode_t mode
)
1730 struct gpfs_config_data
*config
;
1732 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1733 struct gpfs_config_data
,
1736 if (config
->syncio
) {
1739 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
1742 static ssize_t
vfs_gpfs_pread(vfs_handle_struct
*handle
, files_struct
*fsp
,
1743 void *data
, size_t n
, off_t offset
)
1747 ret
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
1749 DEBUG(10, ("vfs_private = %x\n",
1750 (unsigned int)fsp
->fsp_name
->st
.vfs_private
));
1753 ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0)) {
1754 fsp
->fsp_name
->st
.vfs_private
&= ~GPFS_WINATTR_OFFLINE
;
1755 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
1756 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
1757 fsp
->fsp_name
->base_name
);
1763 struct vfs_gpfs_pread_state
{
1764 struct files_struct
*fsp
;
1769 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
);
1771 static struct tevent_req
*vfs_gpfs_pread_send(struct vfs_handle_struct
*handle
,
1772 TALLOC_CTX
*mem_ctx
,
1773 struct tevent_context
*ev
,
1774 struct files_struct
*fsp
,
1775 void *data
, size_t n
,
1778 struct tevent_req
*req
, *subreq
;
1779 struct vfs_gpfs_pread_state
*state
;
1781 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pread_state
);
1786 subreq
= SMB_VFS_NEXT_PREAD_SEND(state
, ev
, handle
, fsp
, data
,
1788 if (tevent_req_nomem(subreq
, req
)) {
1789 return tevent_req_post(req
, ev
);
1791 tevent_req_set_callback(subreq
, vfs_gpfs_pread_done
, req
);
1795 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
)
1797 struct tevent_req
*req
= tevent_req_callback_data(
1798 subreq
, struct tevent_req
);
1799 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
1800 req
, struct vfs_gpfs_pread_state
);
1802 state
->ret
= SMB_VFS_PREAD_RECV(subreq
, &state
->err
);
1803 TALLOC_FREE(subreq
);
1804 tevent_req_done(req
);
1807 static ssize_t
vfs_gpfs_pread_recv(struct tevent_req
*req
, int *err
)
1809 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
1810 req
, struct vfs_gpfs_pread_state
);
1811 struct files_struct
*fsp
= state
->fsp
;
1813 if (tevent_req_is_unix_error(req
, err
)) {
1818 DEBUG(10, ("vfs_private = %x\n",
1819 (unsigned int)fsp
->fsp_name
->st
.vfs_private
));
1821 if ((state
->ret
!= -1) &&
1822 ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0)) {
1823 fsp
->fsp_name
->st
.vfs_private
&= ~GPFS_WINATTR_OFFLINE
;
1824 DEBUG(10, ("sending notify\n"));
1825 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
1826 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
1827 fsp
->fsp_name
->base_name
);
1833 static ssize_t
vfs_gpfs_pwrite(vfs_handle_struct
*handle
, files_struct
*fsp
,
1834 const void *data
, size_t n
, off_t offset
)
1838 ret
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
1840 DEBUG(10, ("vfs_private = %x\n",
1841 (unsigned int)fsp
->fsp_name
->st
.vfs_private
));
1844 ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0)) {
1845 fsp
->fsp_name
->st
.vfs_private
&= ~GPFS_WINATTR_OFFLINE
;
1846 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
1847 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
1848 fsp
->fsp_name
->base_name
);
1854 struct vfs_gpfs_pwrite_state
{
1855 struct files_struct
*fsp
;
1860 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
);
1862 static struct tevent_req
*vfs_gpfs_pwrite_send(
1863 struct vfs_handle_struct
*handle
,
1864 TALLOC_CTX
*mem_ctx
,
1865 struct tevent_context
*ev
,
1866 struct files_struct
*fsp
,
1867 const void *data
, size_t n
,
1870 struct tevent_req
*req
, *subreq
;
1871 struct vfs_gpfs_pwrite_state
*state
;
1873 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pwrite_state
);
1878 subreq
= SMB_VFS_NEXT_PWRITE_SEND(state
, ev
, handle
, fsp
, data
,
1880 if (tevent_req_nomem(subreq
, req
)) {
1881 return tevent_req_post(req
, ev
);
1883 tevent_req_set_callback(subreq
, vfs_gpfs_pwrite_done
, req
);
1887 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
)
1889 struct tevent_req
*req
= tevent_req_callback_data(
1890 subreq
, struct tevent_req
);
1891 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
1892 req
, struct vfs_gpfs_pwrite_state
);
1894 state
->ret
= SMB_VFS_PWRITE_RECV(subreq
, &state
->err
);
1895 TALLOC_FREE(subreq
);
1896 tevent_req_done(req
);
1899 static ssize_t
vfs_gpfs_pwrite_recv(struct tevent_req
*req
, int *err
)
1901 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
1902 req
, struct vfs_gpfs_pwrite_state
);
1903 struct files_struct
*fsp
= state
->fsp
;
1905 if (tevent_req_is_unix_error(req
, err
)) {
1910 DEBUG(10, ("vfs_private = %x\n",
1911 (unsigned int)fsp
->fsp_name
->st
.vfs_private
));
1913 if ((state
->ret
!= -1) &&
1914 ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0)) {
1915 fsp
->fsp_name
->st
.vfs_private
&= ~GPFS_WINATTR_OFFLINE
;
1916 DEBUG(10, ("sending notify\n"));
1917 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
1918 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
1919 fsp
->fsp_name
->base_name
);
1926 static struct vfs_fn_pointers vfs_gpfs_fns
= {
1927 .connect_fn
= vfs_gpfs_connect
,
1928 .disk_free_fn
= vfs_gpfs_disk_free
,
1929 .fs_capabilities_fn
= vfs_gpfs_capabilities
,
1930 .kernel_flock_fn
= vfs_gpfs_kernel_flock
,
1931 .linux_setlease_fn
= vfs_gpfs_setlease
,
1932 .get_real_filename_fn
= vfs_gpfs_get_real_filename
,
1933 .fget_nt_acl_fn
= gpfsacl_fget_nt_acl
,
1934 .get_nt_acl_fn
= gpfsacl_get_nt_acl
,
1935 .fset_nt_acl_fn
= gpfsacl_fset_nt_acl
,
1936 .sys_acl_get_file_fn
= gpfsacl_sys_acl_get_file
,
1937 .sys_acl_get_fd_fn
= gpfsacl_sys_acl_get_fd
,
1938 .sys_acl_set_file_fn
= gpfsacl_sys_acl_set_file
,
1939 .sys_acl_set_fd_fn
= gpfsacl_sys_acl_set_fd
,
1940 .sys_acl_delete_def_file_fn
= gpfsacl_sys_acl_delete_def_file
,
1941 .chmod_fn
= vfs_gpfs_chmod
,
1942 .fchmod_fn
= vfs_gpfs_fchmod
,
1943 .close_fn
= vfs_gpfs_close
,
1944 .setxattr_fn
= gpfs_set_xattr
,
1945 .getxattr_fn
= gpfs_get_xattr
,
1946 .stat_fn
= vfs_gpfs_stat
,
1947 .fstat_fn
= vfs_gpfs_fstat
,
1948 .lstat_fn
= vfs_gpfs_lstat
,
1949 .ntimes_fn
= vfs_gpfs_ntimes
,
1950 .is_offline_fn
= vfs_gpfs_is_offline
,
1951 .aio_force_fn
= vfs_gpfs_aio_force
,
1952 .sendfile_fn
= vfs_gpfs_sendfile
,
1953 .fallocate_fn
= vfs_gpfs_fallocate
,
1954 .open_fn
= vfs_gpfs_open
,
1955 .pread_fn
= vfs_gpfs_pread
,
1956 .pread_send_fn
= vfs_gpfs_pread_send
,
1957 .pread_recv_fn
= vfs_gpfs_pread_recv
,
1958 .pwrite_fn
= vfs_gpfs_pwrite
,
1959 .pwrite_send_fn
= vfs_gpfs_pwrite_send
,
1960 .pwrite_recv_fn
= vfs_gpfs_pwrite_recv
,
1961 .ftruncate_fn
= vfs_gpfs_ftruncate
1964 NTSTATUS
vfs_gpfs_init(void);
1965 NTSTATUS
vfs_gpfs_init(void)
1969 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "gpfs",