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 struct gpfs_config_data
{
45 static int vfs_gpfs_kernel_flock(vfs_handle_struct
*handle
, files_struct
*fsp
,
46 uint32 share_mode
, uint32 access_mask
)
49 struct gpfs_config_data
*config
;
51 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
52 struct gpfs_config_data
,
55 START_PROFILE(syscall_kernel_flock
);
57 kernel_flock(fsp
->fh
->fd
, share_mode
, access_mask
);
59 if (config
->sharemodes
60 && !set_gpfs_sharemode(fsp
, access_mask
, fsp
->share_access
)) {
64 END_PROFILE(syscall_kernel_flock
);
69 static int vfs_gpfs_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
72 struct gpfs_config_data
*config
;
74 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
75 struct gpfs_config_data
,
78 if (config
->sharemodes
&& (fsp
->fh
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
79 set_gpfs_sharemode(fsp
, 0, 0);
82 return SMB_VFS_NEXT_CLOSE(handle
, fsp
);
85 static int vfs_gpfs_setlease(vfs_handle_struct
*handle
, files_struct
*fsp
,
88 struct gpfs_config_data
*config
;
91 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
92 struct gpfs_config_data
,
95 START_PROFILE(syscall_linux_setlease
);
97 if (linux_set_lease_sighandler(fsp
->fh
->fd
) == -1)
100 if (config
->leases
) {
101 ret
= set_gpfs_lease(fsp
->fh
->fd
,leasetype
);
105 /* This must have come from GPFS not being available */
106 /* or some other error, hence call the default */
107 ret
= linux_setlease(fsp
->fh
->fd
, leasetype
);
110 END_PROFILE(syscall_linux_setlease
);
115 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct
*handle
,
123 char real_pathname
[PATH_MAX
+1];
127 mangled
= mangle_is_mangled(name
, handle
->conn
->params
);
129 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
130 mem_ctx
, found_name
);
133 full_path
= talloc_asprintf(talloc_tos(), "%s/%s", path
, name
);
134 if (full_path
== NULL
) {
139 buflen
= sizeof(real_pathname
) - 1;
141 result
= smbd_gpfs_get_realfilename_path(full_path
, real_pathname
,
144 TALLOC_FREE(full_path
);
146 if ((result
== -1) && (errno
== ENOSYS
)) {
147 return SMB_VFS_NEXT_GET_REAL_FILENAME(
148 handle
, path
, name
, mem_ctx
, found_name
);
152 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
158 * GPFS does not necessarily null-terminate the returned path
159 * but instead returns the buffer length in buflen.
162 if (buflen
< sizeof(real_pathname
)) {
163 real_pathname
[buflen
] = '\0';
165 real_pathname
[sizeof(real_pathname
)-1] = '\0';
168 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
169 path
, name
, real_pathname
));
171 name
= strrchr_m(real_pathname
, '/');
177 *found_name
= talloc_strdup(mem_ctx
, name
+1);
178 if (*found_name
== NULL
) {
186 static void gpfs_dumpacl(int level
, struct gpfs_acl
*gacl
)
191 DEBUG(0, ("gpfs acl is NULL\n"));
195 DEBUG(level
, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n",
196 gacl
->acl_nace
, gacl
->acl_type
, gacl
->acl_version
, gacl
->acl_level
, gacl
->acl_len
));
197 for(i
=0; i
<gacl
->acl_nace
; i
++)
199 struct gpfs_ace_v4
*gace
= gacl
->ace_v4
+ i
;
200 DEBUG(level
, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n",
201 i
, gace
->aceType
, gace
->aceFlags
, gace
->aceMask
,
202 gace
->aceIFlags
, gace
->aceWho
));
206 static struct gpfs_acl
*gpfs_getacl_alloc(const char *fname
, gpfs_aclType_t type
)
208 struct gpfs_acl
*acl
;
211 TALLOC_CTX
*mem_ctx
= talloc_tos();
213 acl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, len
);
221 acl
->acl_version
= 0;
222 acl
->acl_type
= type
;
224 ret
= smbd_gpfs_getacl((char *)fname
, GPFS_GETACL_STRUCT
| GPFS_ACL_SAMBA
, acl
);
225 if ((ret
!= 0) && (errno
== ENOSPC
)) {
226 struct gpfs_acl
*new_acl
= (struct gpfs_acl
*)TALLOC_SIZE(
227 mem_ctx
, acl
->acl_len
+ sizeof(struct gpfs_acl
));
228 if (new_acl
== NULL
) {
233 new_acl
->acl_len
= acl
->acl_len
;
234 new_acl
->acl_level
= acl
->acl_level
;
235 new_acl
->acl_version
= acl
->acl_version
;
236 new_acl
->acl_type
= acl
->acl_type
;
239 ret
= smbd_gpfs_getacl((char *)fname
, GPFS_GETACL_STRUCT
| GPFS_ACL_SAMBA
, acl
);
243 DEBUG(8, ("smbd_gpfs_getacl failed with %s\n",strerror(errno
)));
250 /* Tries to get nfs4 acls and returns SMB ACL allocated.
251 * On failure returns 1 if it got non-NFSv4 ACL to prompt
252 * retry with POSIX ACL checks.
253 * On failure returns -1 if there is system (GPFS) error, check errno.
254 * Returns 0 on success
256 static int gpfs_get_nfs4_acl(const char *fname
, SMB4ACL_T
**ppacl
)
259 struct gpfs_acl
*gacl
= NULL
;
260 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname
));
262 /* First get the real acl length */
263 gacl
= gpfs_getacl_alloc(fname
, 0);
265 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
266 fname
, strerror(errno
)));
270 if (gacl
->acl_type
!= GPFS_ACL_TYPE_NFS4
) {
271 DEBUG(10, ("Got non-nfsv4 acl\n"));
272 /* Retry with POSIX ACLs check */
276 *ppacl
= smb_create_smb4acl();
278 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
279 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
282 for (i
=0; i
<gacl
->acl_nace
; i
++) {
283 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[i
];
284 SMB_ACE4PROP_T smbace
;
285 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
286 "who: %d\n", gace
->aceType
, gace
->aceIFlags
,
287 gace
->aceFlags
, gace
->aceMask
, gace
->aceWho
));
290 if (gace
->aceIFlags
& ACE4_IFLAG_SPECIAL_ID
) {
291 smbace
.flags
|= SMB_ACE4_ID_SPECIAL
;
292 switch (gace
->aceWho
) {
293 case ACE4_SPECIAL_OWNER
:
294 smbace
.who
.special_id
= SMB_ACE4_WHO_OWNER
;
296 case ACE4_SPECIAL_GROUP
:
297 smbace
.who
.special_id
= SMB_ACE4_WHO_GROUP
;
299 case ACE4_SPECIAL_EVERYONE
:
300 smbace
.who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
303 DEBUG(8, ("invalid special gpfs id %d "
304 "ignored\n", gace
->aceWho
));
305 continue; /* don't add it */
308 if (gace
->aceFlags
& ACE4_FLAG_GROUP_ID
)
309 smbace
.who
.gid
= gace
->aceWho
;
311 smbace
.who
.uid
= gace
->aceWho
;
314 /* remove redundent deny entries */
315 if (i
> 0 && gace
->aceType
== SMB_ACE4_ACCESS_DENIED_ACE_TYPE
) {
316 struct gpfs_ace_v4
*prev
= &gacl
->ace_v4
[i
-1];
317 if (prev
->aceType
== SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
&&
318 prev
->aceFlags
== gace
->aceFlags
&&
319 prev
->aceIFlags
== gace
->aceIFlags
&&
320 (gace
->aceMask
& prev
->aceMask
) == 0 &&
321 gace
->aceWho
== prev
->aceWho
) {
322 /* its redundent - skip it */
327 smbace
.aceType
= gace
->aceType
;
328 smbace
.aceFlags
= gace
->aceFlags
;
329 smbace
.aceMask
= gace
->aceMask
;
330 smb_add_ace4(*ppacl
, &smbace
);
336 static NTSTATUS
gpfsacl_fget_nt_acl(vfs_handle_struct
*handle
,
337 files_struct
*fsp
, uint32 security_info
,
338 struct security_descriptor
**ppdesc
)
340 SMB4ACL_T
*pacl
= NULL
;
344 result
= gpfs_get_nfs4_acl(fsp
->fsp_name
->base_name
, &pacl
);
347 return smb_fget_nt_acl_nfs4(fsp
, security_info
, ppdesc
, pacl
);
350 DEBUG(10, ("retrying with posix acl...\n"));
351 return posix_fget_nt_acl(fsp
, security_info
, ppdesc
);
354 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
355 return map_nt_error_from_unix(errno
);
358 static NTSTATUS
gpfsacl_get_nt_acl(vfs_handle_struct
*handle
,
360 uint32 security_info
, struct security_descriptor
**ppdesc
)
362 SMB4ACL_T
*pacl
= NULL
;
366 result
= gpfs_get_nfs4_acl(name
, &pacl
);
369 return smb_get_nt_acl_nfs4(handle
->conn
, name
, security_info
, ppdesc
, pacl
);
372 DEBUG(10, ("retrying with posix acl...\n"));
373 return posix_get_nt_acl(handle
->conn
, name
, security_info
, ppdesc
);
376 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
377 return map_nt_error_from_unix(errno
);
380 static bool gpfsacl_process_smbacl(files_struct
*fsp
, SMB4ACL_T
*smbacl
)
383 gpfs_aclLen_t gacl_len
;
385 struct gpfs_acl
*gacl
;
386 TALLOC_CTX
*mem_ctx
= talloc_tos();
388 gacl_len
= sizeof(struct gpfs_acl
) +
389 (smb_get_naces(smbacl
)-1)*sizeof(gpfs_ace_v4_t
);
391 gacl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, gacl_len
);
393 DEBUG(0, ("talloc failed\n"));
398 gacl
->acl_len
= gacl_len
;
400 gacl
->acl_version
= GPFS_ACL_VERSION_NFS4
;
401 gacl
->acl_type
= GPFS_ACL_TYPE_NFS4
;
402 gacl
->acl_nace
= 0; /* change later... */
404 for (smbace
=smb_first_ace4(smbacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
405 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[gacl
->acl_nace
];
406 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
408 gace
->aceType
= aceprop
->aceType
;
409 gace
->aceFlags
= aceprop
->aceFlags
;
410 gace
->aceMask
= aceprop
->aceMask
;
413 * GPFS can't distinguish between WRITE and APPEND on
414 * files, so one being set without the other is an
415 * error. Sorry for the many ()'s :-)
418 if (!fsp
->is_directory
420 ((((gace
->aceMask
& ACE4_MASK_WRITE
) == 0)
421 && ((gace
->aceMask
& ACE4_MASK_APPEND
) != 0))
423 (((gace
->aceMask
& ACE4_MASK_WRITE
) != 0)
424 && ((gace
->aceMask
& ACE4_MASK_APPEND
) == 0)))
426 lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
427 "merge_writeappend", True
)) {
428 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
429 "WRITE^APPEND, setting WRITE|APPEND\n",
431 gace
->aceMask
|= ACE4_MASK_WRITE
|ACE4_MASK_APPEND
;
434 gace
->aceIFlags
= (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
) ? ACE4_IFLAG_SPECIAL_ID
: 0;
436 if (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
)
438 switch(aceprop
->who
.special_id
)
440 case SMB_ACE4_WHO_EVERYONE
:
441 gace
->aceWho
= ACE4_SPECIAL_EVERYONE
;
443 case SMB_ACE4_WHO_OWNER
:
444 gace
->aceWho
= ACE4_SPECIAL_OWNER
;
446 case SMB_ACE4_WHO_GROUP
:
447 gace
->aceWho
= ACE4_SPECIAL_GROUP
;
450 DEBUG(8, ("unsupported special_id %d\n", aceprop
->who
.special_id
));
451 continue; /* don't add it !!! */
454 /* just only for the type safety... */
455 if (aceprop
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)
456 gace
->aceWho
= aceprop
->who
.gid
;
458 gace
->aceWho
= aceprop
->who
.uid
;
464 ret
= smbd_gpfs_putacl(fsp
->fsp_name
->base_name
,
465 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gacl
);
467 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno
)));
468 gpfs_dumpacl(8, gacl
);
472 DEBUG(10, ("gpfs_putacl succeeded\n"));
476 static NTSTATUS
gpfsacl_set_nt_acl_internal(files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
478 struct gpfs_acl
*acl
;
479 NTSTATUS result
= NT_STATUS_ACCESS_DENIED
;
481 acl
= gpfs_getacl_alloc(fsp
->fsp_name
->base_name
, 0);
485 if (acl
->acl_version
&GPFS_ACL_VERSION_NFS4
)
487 if (lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
488 "refuse_dacl_protected", false)
489 && (psd
->type
&SEC_DESC_DACL_PROTECTED
)) {
490 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
491 return NT_STATUS_NOT_SUPPORTED
;
494 result
= smb_set_nt_acl_nfs4(
495 fsp
, security_info_sent
, psd
,
496 gpfsacl_process_smbacl
);
497 } else { /* assume POSIX ACL - by default... */
498 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
504 static NTSTATUS
gpfsacl_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
506 return gpfsacl_set_nt_acl_internal(fsp
, security_info_sent
, psd
);
509 static SMB_ACL_T
gpfs2smb_acl(const struct gpfs_acl
*pacl
)
514 result
= sys_acl_init(pacl
->acl_nace
);
515 if (result
== NULL
) {
520 result
->count
= pacl
->acl_nace
;
522 for (i
=0; i
<pacl
->acl_nace
; i
++) {
523 struct smb_acl_entry
*ace
= &result
->acl
[i
];
524 const struct gpfs_ace_v1
*g_ace
= &pacl
->ace_v1
[i
];
526 DEBUG(10, ("Converting type %d id %lu perm %x\n",
527 (int)g_ace
->ace_type
, (unsigned long)g_ace
->ace_who
,
528 (int)g_ace
->ace_perm
));
530 switch (g_ace
->ace_type
) {
532 ace
->a_type
= SMB_ACL_USER
;
533 ace
->uid
= (uid_t
)g_ace
->ace_who
;
535 case GPFS_ACL_USER_OBJ
:
536 ace
->a_type
= SMB_ACL_USER_OBJ
;
539 ace
->a_type
= SMB_ACL_GROUP
;
540 ace
->gid
= (gid_t
)g_ace
->ace_who
;
542 case GPFS_ACL_GROUP_OBJ
:
543 ace
->a_type
= SMB_ACL_GROUP_OBJ
;
546 ace
->a_type
= SMB_ACL_OTHER
;
549 ace
->a_type
= SMB_ACL_MASK
;
552 DEBUG(10, ("Got invalid ace_type: %d\n",
560 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_READ
) ?
562 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_WRITE
) ?
564 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_EXECUTE
) ?
567 DEBUGADD(10, ("Converted to %d perm %x\n",
568 ace
->a_type
, ace
->a_perm
));
574 static SMB_ACL_T
gpfsacl_get_posix_acl(const char *path
, gpfs_aclType_t type
)
576 struct gpfs_acl
*pacl
;
577 SMB_ACL_T result
= NULL
;
579 pacl
= gpfs_getacl_alloc(path
, type
);
582 DEBUG(10, ("gpfs_getacl failed for %s with %s\n",
583 path
, strerror(errno
)));
590 if (pacl
->acl_version
!= GPFS_ACL_VERSION_POSIX
) {
591 DEBUG(10, ("Got acl version %d, expected %d\n",
592 pacl
->acl_version
, GPFS_ACL_VERSION_POSIX
));
597 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
598 pacl
->acl_len
, pacl
->acl_level
, pacl
->acl_version
,
601 result
= gpfs2smb_acl(pacl
);
602 if (result
== NULL
) {
614 static SMB_ACL_T
gpfsacl_sys_acl_get_file(vfs_handle_struct
*handle
,
618 gpfs_aclType_t gpfs_type
;
621 case SMB_ACL_TYPE_ACCESS
:
622 gpfs_type
= GPFS_ACL_TYPE_ACCESS
;
624 case SMB_ACL_TYPE_DEFAULT
:
625 gpfs_type
= GPFS_ACL_TYPE_DEFAULT
;
628 DEBUG(0, ("Got invalid type: %d\n", type
));
629 smb_panic("exiting");
632 return gpfsacl_get_posix_acl(path_p
, gpfs_type
);
635 static SMB_ACL_T
gpfsacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
638 return gpfsacl_get_posix_acl(fsp
->fsp_name
->base_name
,
639 GPFS_ACL_TYPE_ACCESS
);
642 static struct gpfs_acl
*smb2gpfs_acl(const SMB_ACL_T pacl
,
646 struct gpfs_acl
*result
;
650 gpfs_ace_v1_t ace_v1
[1]; /* when GPFS_ACL_VERSION_POSIX */
651 gpfs_ace_v4_t ace_v4
[1]; /* when GPFS_ACL_VERSION_NFS4 */
654 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl
->count
));
656 len
= sizeof(struct gpfs_acl
) - sizeof(union gpfs_ace_union
) +
657 (pacl
->count
)*sizeof(gpfs_ace_v1_t
);
659 result
= (struct gpfs_acl
*)SMB_MALLOC(len
);
660 if (result
== NULL
) {
665 result
->acl_len
= len
;
666 result
->acl_level
= 0;
667 result
->acl_version
= GPFS_ACL_VERSION_POSIX
;
668 result
->acl_type
= (type
== SMB_ACL_TYPE_DEFAULT
) ?
669 GPFS_ACL_TYPE_DEFAULT
: GPFS_ACL_TYPE_ACCESS
;
670 result
->acl_nace
= pacl
->count
;
672 for (i
=0; i
<pacl
->count
; i
++) {
673 const struct smb_acl_entry
*ace
= &pacl
->acl
[i
];
674 struct gpfs_ace_v1
*g_ace
= &result
->ace_v1
[i
];
676 DEBUG(10, ("Converting type %d perm %x\n",
677 (int)ace
->a_type
, (int)ace
->a_perm
));
681 switch(ace
->a_type
) {
683 g_ace
->ace_type
= GPFS_ACL_USER
;
684 g_ace
->ace_who
= (gpfs_uid_t
)ace
->uid
;
686 case SMB_ACL_USER_OBJ
:
687 g_ace
->ace_type
= GPFS_ACL_USER_OBJ
;
688 g_ace
->ace_perm
|= ACL_PERM_CONTROL
;
692 g_ace
->ace_type
= GPFS_ACL_GROUP
;
693 g_ace
->ace_who
= (gpfs_uid_t
)ace
->gid
;
695 case SMB_ACL_GROUP_OBJ
:
696 g_ace
->ace_type
= GPFS_ACL_GROUP_OBJ
;
700 g_ace
->ace_type
= GPFS_ACL_MASK
;
701 g_ace
->ace_perm
= 0x8f;
705 g_ace
->ace_type
= GPFS_ACL_OTHER
;
709 DEBUG(10, ("Got invalid ace_type: %d\n", ace
->a_type
));
715 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_READ
) ?
717 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_WRITE
) ?
719 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_EXECUTE
) ?
720 ACL_PERM_EXECUTE
: 0;
722 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
723 g_ace
->ace_type
, g_ace
->ace_who
, g_ace
->ace_perm
));
729 static int gpfsacl_sys_acl_set_file(vfs_handle_struct
*handle
,
734 struct gpfs_acl
*gpfs_acl
;
737 gpfs_acl
= smb2gpfs_acl(theacl
, type
);
738 if (gpfs_acl
== NULL
) {
742 result
= smbd_gpfs_putacl((char *)name
, GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gpfs_acl
);
748 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
752 return gpfsacl_sys_acl_set_file(handle
, fsp
->fsp_name
->base_name
,
753 SMB_ACL_TYPE_ACCESS
, theacl
);
756 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
764 * Assumed: mode bits are shiftable and standard
765 * Output: the new aceMask field for an smb nfs4 ace
767 static uint32
gpfsacl_mask_filter(uint32 aceType
, uint32 aceMask
, uint32 rwx
)
769 const uint32 posix_nfs4map
[3] = {
770 SMB_ACE4_EXECUTE
, /* execute */
771 SMB_ACE4_WRITE_DATA
| SMB_ACE4_APPEND_DATA
, /* write; GPFS specific */
772 SMB_ACE4_READ_DATA
/* read */
775 uint32_t posix_mask
= 0x01;
780 nfs4_bits
= posix_nfs4map
[i
];
781 posix_bit
= rwx
& posix_mask
;
783 if (aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
) {
785 aceMask
|= nfs4_bits
;
787 aceMask
&= ~nfs4_bits
;
789 /* add deny bits when suitable */
791 aceMask
|= nfs4_bits
;
793 aceMask
&= ~nfs4_bits
;
794 } /* other ace types are unexpected */
802 static int gpfsacl_emu_chmod(const char *path
, mode_t mode
)
804 SMB4ACL_T
*pacl
= NULL
;
806 bool haveAllowEntry
[SMB_ACE4_WHO_EVERYONE
+ 1] = {False
, False
, False
, False
};
808 files_struct fake_fsp
; /* TODO: rationalize parametrization */
812 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path
, mode
));
814 result
= gpfs_get_nfs4_acl(path
, &pacl
);
818 if (mode
& ~(S_IRWXU
| S_IRWXG
| S_IRWXO
)) {
819 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode
, path
));
822 for (smbace
=smb_first_ace4(pacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
823 SMB_ACE4PROP_T
*ace
= smb_get_ace4(smbace
);
824 uint32_t specid
= ace
->who
.special_id
;
826 if (ace
->flags
&SMB_ACE4_ID_SPECIAL
&&
827 ace
->aceType
<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE
&&
828 specid
<= SMB_ACE4_WHO_EVERYONE
) {
832 if (ace
->aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
)
833 haveAllowEntry
[specid
] = True
;
835 /* mode >> 6 for @owner, mode >> 3 for @group,
836 * mode >> 0 for @everyone */
837 newMask
= gpfsacl_mask_filter(ace
->aceType
, ace
->aceMask
,
838 mode
>> ((SMB_ACE4_WHO_EVERYONE
- specid
) * 3));
839 if (ace
->aceMask
!=newMask
) {
840 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
841 path
, ace
->aceMask
, newMask
, specid
));
843 ace
->aceMask
= newMask
;
847 /* make sure we have at least ALLOW entries
848 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
851 for(i
= SMB_ACE4_WHO_OWNER
; i
<=SMB_ACE4_WHO_EVERYONE
; i
++) {
854 if (haveAllowEntry
[i
]==True
)
858 ace
.aceType
= SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
;
859 ace
.flags
|= SMB_ACE4_ID_SPECIAL
;
860 ace
.who
.special_id
= i
;
862 if (i
==SMB_ACE4_WHO_GROUP
) /* not sure it's necessary... */
863 ace
.aceFlags
|= SMB_ACE4_IDENTIFIER_GROUP
;
865 ace
.aceMask
= gpfsacl_mask_filter(ace
.aceType
, ace
.aceMask
,
866 mode
>> ((SMB_ACE4_WHO_EVERYONE
- i
) * 3));
868 /* don't add unnecessary aces */
872 /* we add it to the END - as windows expects allow aces */
873 smb_add_ace4(pacl
, &ace
);
874 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
875 path
, mode
, i
, ace
.aceMask
));
878 /* don't add complementary DENY ACEs here */
879 ZERO_STRUCT(fake_fsp
);
880 status
= create_synthetic_smb_fname(talloc_tos(), path
, NULL
, NULL
,
882 if (!NT_STATUS_IS_OK(status
)) {
883 errno
= map_errno_from_nt_status(status
);
887 if (gpfsacl_process_smbacl(&fake_fsp
, pacl
) == False
) {
888 TALLOC_FREE(fake_fsp
.fsp_name
);
892 TALLOC_FREE(fake_fsp
.fsp_name
);
893 return 0; /* ok for [f]chmod */
896 static int vfs_gpfs_chmod(vfs_handle_struct
*handle
, const char *path
, mode_t mode
)
898 struct smb_filename
*smb_fname_cpath
;
902 status
= create_synthetic_smb_fname(
903 talloc_tos(), path
, NULL
, NULL
, &smb_fname_cpath
);
905 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_cpath
) != 0) {
909 /* avoid chmod() if possible, to preserve acls */
910 if ((smb_fname_cpath
->st
.st_ex_mode
& ~S_IFMT
) == mode
) {
914 rc
= gpfsacl_emu_chmod(path
, mode
);
916 return SMB_VFS_NEXT_CHMOD(handle
, path
, mode
);
920 static int vfs_gpfs_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
925 if (SMB_VFS_NEXT_FSTAT(handle
, fsp
, &st
) != 0) {
929 /* avoid chmod() if possible, to preserve acls */
930 if ((st
.st_ex_mode
& ~S_IFMT
) == mode
) {
934 rc
= gpfsacl_emu_chmod(fsp
->fsp_name
->base_name
, mode
);
936 return SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
940 static int gpfs_set_xattr(struct vfs_handle_struct
*handle
, const char *path
,
941 const char *name
, const void *value
, size_t size
, int flags
){
942 struct xattr_DOSATTRIB dosattrib
;
943 enum ndr_err_code ndr_err
;
945 const char *attrstr
= value
;
946 unsigned int dosmode
=0;
947 struct gpfs_winattr attrs
;
950 DEBUG(10, ("gpfs_set_xattr: %s \n",path
));
952 /* Only handle DOS Attributes */
953 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
954 DEBUG(1, ("gpfs_set_xattr:name is %s\n",name
));
955 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
958 blob
.data
= (uint8_t *)attrstr
;
961 ndr_err
= ndr_pull_struct_blob(&blob
, talloc_tos(), &dosattrib
,
962 (ndr_pull_flags_fn_t
)ndr_pull_xattr_DOSATTRIB
);
964 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
965 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
966 "from EA on file %s: Error = %s\n",
967 path
, ndr_errstr(ndr_err
)));
971 if (dosattrib
.version
!= 3) {
972 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
973 "%d\n", (int)dosattrib
.version
));
976 if (!(dosattrib
.info
.info3
.valid_flags
& XATTR_DOSINFO_ATTRIB
)) {
977 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
978 "valid, ignoring\n"));
982 dosmode
= dosattrib
.info
.info3
.attrib
;
985 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
986 if (dosmode
& FILE_ATTRIBUTE_ARCHIVE
){
987 attrs
.winAttrs
|= GPFS_WINATTR_ARCHIVE
;
989 if (dosmode
& FILE_ATTRIBUTE_HIDDEN
){
990 attrs
.winAttrs
|= GPFS_WINATTR_HIDDEN
;
992 if (dosmode
& FILE_ATTRIBUTE_SYSTEM
){
993 attrs
.winAttrs
|= GPFS_WINATTR_SYSTEM
;
995 if (dosmode
& FILE_ATTRIBUTE_READONLY
){
996 attrs
.winAttrs
|= GPFS_WINATTR_READONLY
;
998 if (dosmode
& FILE_ATTRIBUTE_SPARSE
) {
999 attrs
.winAttrs
|= GPFS_WINATTR_SPARSE_FILE
;
1003 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1004 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1006 if (errno
== ENOSYS
) {
1007 return SMB_VFS_NEXT_SETXATTR(handle
, path
, name
, value
,
1011 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret
));
1015 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs
.winAttrs
));
1019 static ssize_t
gpfs_get_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1020 const char *name
, void *value
, size_t size
){
1021 char *attrstr
= value
;
1022 unsigned int dosmode
= 0;
1023 struct gpfs_winattr attrs
;
1026 DEBUG(10, ("gpfs_get_xattr: %s \n",path
));
1028 /* Only handle DOS Attributes */
1029 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1030 DEBUG(1, ("gpfs_get_xattr:name is %s\n",name
));
1031 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1034 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1036 if (errno
== ENOSYS
) {
1037 return SMB_VFS_NEXT_GETXATTR(handle
, path
, name
, value
,
1041 DEBUG(1, ("gpfs_get_xattr: Get GPFS attributes failed: "
1042 "%d (%s)\n", ret
, strerror(errno
)));
1046 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs
.winAttrs
));
1048 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1049 if (attrs
.winAttrs
& GPFS_WINATTR_ARCHIVE
){
1050 dosmode
|= FILE_ATTRIBUTE_ARCHIVE
;
1052 if (attrs
.winAttrs
& GPFS_WINATTR_HIDDEN
){
1053 dosmode
|= FILE_ATTRIBUTE_HIDDEN
;
1055 if (attrs
.winAttrs
& GPFS_WINATTR_SYSTEM
){
1056 dosmode
|= FILE_ATTRIBUTE_SYSTEM
;
1058 if (attrs
.winAttrs
& GPFS_WINATTR_READONLY
){
1059 dosmode
|= FILE_ATTRIBUTE_READONLY
;
1061 if (attrs
.winAttrs
& GPFS_WINATTR_SPARSE_FILE
) {
1062 dosmode
|= FILE_ATTRIBUTE_SPARSE
;
1065 snprintf(attrstr
, size
, "0x%2.2x",
1066 (unsigned int)(dosmode
& SAMBA_ATTRIBUTES_MASK
));
1067 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr
));
1071 static int vfs_gpfs_stat(struct vfs_handle_struct
*handle
,
1072 struct smb_filename
*smb_fname
)
1074 struct gpfs_winattr attrs
;
1079 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
1083 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &fname
);
1084 if (!NT_STATUS_IS_OK(status
)) {
1085 errno
= map_errno_from_nt_status(status
);
1088 ret
= get_gpfs_winattrs(discard_const_p(char, fname
), &attrs
);
1091 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1092 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1093 smb_fname
->st
.vfs_private
= attrs
.winAttrs
;
1098 static int vfs_gpfs_fstat(struct vfs_handle_struct
*handle
,
1099 struct files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
1101 struct gpfs_winattr attrs
;
1104 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
1108 if ((fsp
->fh
== NULL
) || (fsp
->fh
->fd
== -1)) {
1111 ret
= smbd_fget_gpfs_winattrs(fsp
->fh
->fd
, &attrs
);
1113 sbuf
->st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1114 sbuf
->st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1119 static int vfs_gpfs_lstat(struct vfs_handle_struct
*handle
,
1120 struct smb_filename
*smb_fname
)
1122 struct gpfs_winattr attrs
;
1127 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
1131 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1132 if (!NT_STATUS_IS_OK(status
)) {
1133 errno
= map_errno_from_nt_status(status
);
1136 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1139 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1140 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1141 smb_fname
->st
.vfs_private
= attrs
.winAttrs
;
1146 static int vfs_gpfs_ntimes(struct vfs_handle_struct
*handle
,
1147 const struct smb_filename
*smb_fname
,
1148 struct smb_file_time
*ft
)
1151 struct gpfs_winattr attrs
;
1156 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1158 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed\n"));
1162 if(null_timespec(ft
->create_time
)){
1163 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1167 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1168 if (!NT_STATUS_IS_OK(status
)) {
1169 errno
= map_errno_from_nt_status(status
);
1174 attrs
.creationTime
.tv_sec
= ft
->create_time
.tv_sec
;
1175 attrs
.creationTime
.tv_nsec
= ft
->create_time
.tv_nsec
;
1177 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1178 GPFS_WINATTR_SET_CREATION_TIME
, &attrs
);
1179 if(ret
== -1 && errno
!= ENOSYS
){
1180 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret
));
1187 static int vfs_gpfs_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1192 result
= smbd_gpfs_ftruncate(fsp
->fh
->fd
, len
);
1193 if ((result
== -1) && (errno
== ENOSYS
)) {
1194 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1199 static bool vfs_gpfs_is_offline(struct vfs_handle_struct
*handle
,
1200 const struct smb_filename
*fname
,
1201 SMB_STRUCT_STAT
*sbuf
)
1203 struct gpfs_winattr attrs
;
1207 status
= get_full_smb_filename(talloc_tos(), fname
, &path
);
1208 if (!NT_STATUS_IS_OK(status
)) {
1209 errno
= map_errno_from_nt_status(status
);
1213 if (VALID_STAT(*sbuf
)) {
1214 attrs
.winAttrs
= sbuf
->vfs_private
;
1217 ret
= get_gpfs_winattrs(path
, &attrs
);
1224 if ((attrs
.winAttrs
& GPFS_WINATTR_OFFLINE
) != 0) {
1225 DEBUG(10, ("%s is offline\n", path
));
1229 DEBUG(10, ("%s is online\n", path
));
1231 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1234 static bool vfs_gpfs_aio_force(struct vfs_handle_struct
*handle
,
1235 struct files_struct
*fsp
)
1237 return vfs_gpfs_is_offline(handle
, fsp
->fsp_name
, &fsp
->fsp_name
->st
);
1240 static ssize_t
vfs_gpfs_sendfile(vfs_handle_struct
*handle
, int tofd
,
1241 files_struct
*fsp
, const DATA_BLOB
*hdr
,
1242 SMB_OFF_T offset
, size_t n
)
1244 if ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0) {
1248 return SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fsp
, hdr
, offset
, n
);
1251 int vfs_gpfs_connect(struct vfs_handle_struct
*handle
, const char *service
,
1254 struct gpfs_config_data
*config
;
1256 smbd_gpfs_lib_init();
1258 int ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1264 config
= talloc_zero(handle
->conn
, struct gpfs_config_data
);
1266 SMB_VFS_NEXT_DISCONNECT(handle
);
1267 DEBUG(0, ("talloc_zero() failed\n")); return -1;
1270 config
->sharemodes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1271 "sharemodes", true);
1273 config
->leases
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1276 config
->hsm
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1279 config
->syncio
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1282 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
1283 NULL
, struct gpfs_config_data
,
1289 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct
*handle
,
1290 enum timestamp_set_resolution
*p_ts_res
)
1292 struct gpfs_config_data
*config
;
1295 next
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
1297 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1298 struct gpfs_config_data
,
1302 next
|= FILE_SUPPORTS_REMOTE_STORAGE
;
1307 static int vfs_gpfs_open(struct vfs_handle_struct
*handle
,
1308 struct smb_filename
*smb_fname
, files_struct
*fsp
,
1309 int flags
, mode_t mode
)
1311 struct gpfs_config_data
*config
;
1313 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1314 struct gpfs_config_data
,
1317 if (config
->syncio
) {
1320 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
1324 static struct vfs_fn_pointers vfs_gpfs_fns
= {
1325 .connect_fn
= vfs_gpfs_connect
,
1326 .fs_capabilities
= vfs_gpfs_capabilities
,
1327 .kernel_flock
= vfs_gpfs_kernel_flock
,
1328 .linux_setlease
= vfs_gpfs_setlease
,
1329 .get_real_filename
= vfs_gpfs_get_real_filename
,
1330 .fget_nt_acl
= gpfsacl_fget_nt_acl
,
1331 .get_nt_acl
= gpfsacl_get_nt_acl
,
1332 .fset_nt_acl
= gpfsacl_fset_nt_acl
,
1333 .sys_acl_get_file
= gpfsacl_sys_acl_get_file
,
1334 .sys_acl_get_fd
= gpfsacl_sys_acl_get_fd
,
1335 .sys_acl_set_file
= gpfsacl_sys_acl_set_file
,
1336 .sys_acl_set_fd
= gpfsacl_sys_acl_set_fd
,
1337 .sys_acl_delete_def_file
= gpfsacl_sys_acl_delete_def_file
,
1338 .chmod
= vfs_gpfs_chmod
,
1339 .fchmod
= vfs_gpfs_fchmod
,
1340 .close_fn
= vfs_gpfs_close
,
1341 .setxattr
= gpfs_set_xattr
,
1342 .getxattr
= gpfs_get_xattr
,
1343 .stat
= vfs_gpfs_stat
,
1344 .fstat
= vfs_gpfs_fstat
,
1345 .lstat
= vfs_gpfs_lstat
,
1346 .ntimes
= vfs_gpfs_ntimes
,
1347 .is_offline
= vfs_gpfs_is_offline
,
1348 .aio_force
= vfs_gpfs_aio_force
,
1349 .sendfile
= vfs_gpfs_sendfile
,
1350 .open_fn
= vfs_gpfs_open
,
1351 .ftruncate
= vfs_gpfs_ftruncate
1354 NTSTATUS
vfs_gpfs_init(void);
1355 NTSTATUS
vfs_gpfs_init(void)
1359 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "gpfs",