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
{
44 static int vfs_gpfs_kernel_flock(vfs_handle_struct
*handle
, files_struct
*fsp
,
45 uint32 share_mode
, uint32 access_mask
)
48 struct gpfs_config_data
*config
;
50 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
51 struct gpfs_config_data
,
54 START_PROFILE(syscall_kernel_flock
);
56 kernel_flock(fsp
->fh
->fd
, share_mode
, access_mask
);
58 if (config
->sharemodes
59 && !set_gpfs_sharemode(fsp
, access_mask
, fsp
->share_access
)) {
63 END_PROFILE(syscall_kernel_flock
);
68 static int vfs_gpfs_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
71 struct gpfs_config_data
*config
;
73 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
74 struct gpfs_config_data
,
77 if (config
->sharemodes
&& (fsp
->fh
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
78 set_gpfs_sharemode(fsp
, 0, 0);
81 return SMB_VFS_NEXT_CLOSE(handle
, fsp
);
84 static int vfs_gpfs_setlease(vfs_handle_struct
*handle
, files_struct
*fsp
,
87 struct gpfs_config_data
*config
;
90 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
91 struct gpfs_config_data
,
94 START_PROFILE(syscall_linux_setlease
);
96 if (linux_set_lease_sighandler(fsp
->fh
->fd
) == -1)
100 ret
= set_gpfs_lease(fsp
->fh
->fd
,leasetype
);
104 /* This must have come from GPFS not being available */
105 /* or some other error, hence call the default */
106 ret
= linux_setlease(fsp
->fh
->fd
, leasetype
);
109 END_PROFILE(syscall_linux_setlease
);
114 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct
*handle
,
122 char real_pathname
[PATH_MAX
+1];
126 mangled
= mangle_is_mangled(name
, handle
->conn
->params
);
128 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
129 mem_ctx
, found_name
);
132 full_path
= talloc_asprintf(talloc_tos(), "%s/%s", path
, name
);
133 if (full_path
== NULL
) {
138 buflen
= sizeof(real_pathname
) - 1;
140 result
= smbd_gpfs_get_realfilename_path(full_path
, real_pathname
,
143 TALLOC_FREE(full_path
);
145 if ((result
== -1) && (errno
== ENOSYS
)) {
146 return SMB_VFS_NEXT_GET_REAL_FILENAME(
147 handle
, path
, name
, mem_ctx
, found_name
);
151 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
157 * GPFS does not necessarily null-terminate the returned path
158 * but instead returns the buffer length in buflen.
161 if (buflen
< sizeof(real_pathname
)) {
162 real_pathname
[buflen
] = '\0';
164 real_pathname
[sizeof(real_pathname
)-1] = '\0';
167 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
168 path
, name
, real_pathname
));
170 name
= strrchr_m(real_pathname
, '/');
176 *found_name
= talloc_strdup(mem_ctx
, name
+1);
177 if (*found_name
== NULL
) {
185 static void gpfs_dumpacl(int level
, struct gpfs_acl
*gacl
)
190 DEBUG(0, ("gpfs acl is NULL\n"));
194 DEBUG(level
, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n",
195 gacl
->acl_nace
, gacl
->acl_type
, gacl
->acl_version
, gacl
->acl_level
, gacl
->acl_len
));
196 for(i
=0; i
<gacl
->acl_nace
; i
++)
198 struct gpfs_ace_v4
*gace
= gacl
->ace_v4
+ i
;
199 DEBUG(level
, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n",
200 i
, gace
->aceType
, gace
->aceFlags
, gace
->aceMask
,
201 gace
->aceIFlags
, gace
->aceWho
));
205 static struct gpfs_acl
*gpfs_getacl_alloc(const char *fname
, gpfs_aclType_t type
)
207 struct gpfs_acl
*acl
;
210 TALLOC_CTX
*mem_ctx
= talloc_tos();
212 acl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, len
);
220 acl
->acl_version
= 0;
221 acl
->acl_type
= type
;
223 ret
= smbd_gpfs_getacl((char *)fname
, GPFS_GETACL_STRUCT
| GPFS_ACL_SAMBA
, acl
);
224 if ((ret
!= 0) && (errno
== ENOSPC
)) {
225 struct gpfs_acl
*new_acl
= (struct gpfs_acl
*)TALLOC_SIZE(
226 mem_ctx
, acl
->acl_len
+ sizeof(struct gpfs_acl
));
227 if (new_acl
== NULL
) {
232 new_acl
->acl_len
= acl
->acl_len
;
233 new_acl
->acl_level
= acl
->acl_level
;
234 new_acl
->acl_version
= acl
->acl_version
;
235 new_acl
->acl_type
= acl
->acl_type
;
238 ret
= smbd_gpfs_getacl((char *)fname
, GPFS_GETACL_STRUCT
| GPFS_ACL_SAMBA
, acl
);
242 DEBUG(8, ("smbd_gpfs_getacl failed with %s\n",strerror(errno
)));
249 /* Tries to get nfs4 acls and returns SMB ACL allocated.
250 * On failure returns 1 if it got non-NFSv4 ACL to prompt
251 * retry with POSIX ACL checks.
252 * On failure returns -1 if there is system (GPFS) error, check errno.
253 * Returns 0 on success
255 static int gpfs_get_nfs4_acl(const char *fname
, SMB4ACL_T
**ppacl
)
258 struct gpfs_acl
*gacl
= NULL
;
259 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname
));
261 /* First get the real acl length */
262 gacl
= gpfs_getacl_alloc(fname
, 0);
264 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
265 fname
, strerror(errno
)));
269 if (gacl
->acl_type
!= GPFS_ACL_TYPE_NFS4
) {
270 DEBUG(10, ("Got non-nfsv4 acl\n"));
271 /* Retry with POSIX ACLs check */
275 *ppacl
= smb_create_smb4acl();
277 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
278 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
281 for (i
=0; i
<gacl
->acl_nace
; i
++) {
282 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[i
];
283 SMB_ACE4PROP_T smbace
;
284 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
285 "who: %d\n", gace
->aceType
, gace
->aceIFlags
,
286 gace
->aceFlags
, gace
->aceMask
, gace
->aceWho
));
289 if (gace
->aceIFlags
& ACE4_IFLAG_SPECIAL_ID
) {
290 smbace
.flags
|= SMB_ACE4_ID_SPECIAL
;
291 switch (gace
->aceWho
) {
292 case ACE4_SPECIAL_OWNER
:
293 smbace
.who
.special_id
= SMB_ACE4_WHO_OWNER
;
295 case ACE4_SPECIAL_GROUP
:
296 smbace
.who
.special_id
= SMB_ACE4_WHO_GROUP
;
298 case ACE4_SPECIAL_EVERYONE
:
299 smbace
.who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
302 DEBUG(8, ("invalid special gpfs id %d "
303 "ignored\n", gace
->aceWho
));
304 continue; /* don't add it */
307 if (gace
->aceFlags
& ACE4_FLAG_GROUP_ID
)
308 smbace
.who
.gid
= gace
->aceWho
;
310 smbace
.who
.uid
= gace
->aceWho
;
313 /* remove redundent deny entries */
314 if (i
> 0 && gace
->aceType
== SMB_ACE4_ACCESS_DENIED_ACE_TYPE
) {
315 struct gpfs_ace_v4
*prev
= &gacl
->ace_v4
[i
-1];
316 if (prev
->aceType
== SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
&&
317 prev
->aceFlags
== gace
->aceFlags
&&
318 prev
->aceIFlags
== gace
->aceIFlags
&&
319 (gace
->aceMask
& prev
->aceMask
) == 0 &&
320 gace
->aceWho
== prev
->aceWho
) {
321 /* its redundent - skip it */
326 smbace
.aceType
= gace
->aceType
;
327 smbace
.aceFlags
= gace
->aceFlags
;
328 smbace
.aceMask
= gace
->aceMask
;
329 smb_add_ace4(*ppacl
, &smbace
);
335 static NTSTATUS
gpfsacl_fget_nt_acl(vfs_handle_struct
*handle
,
336 files_struct
*fsp
, uint32 security_info
,
337 struct security_descriptor
**ppdesc
)
339 SMB4ACL_T
*pacl
= NULL
;
343 result
= gpfs_get_nfs4_acl(fsp
->fsp_name
->base_name
, &pacl
);
346 return smb_fget_nt_acl_nfs4(fsp
, security_info
, ppdesc
, pacl
);
349 DEBUG(10, ("retrying with posix acl...\n"));
350 return posix_fget_nt_acl(fsp
, security_info
, ppdesc
);
353 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
354 return map_nt_error_from_unix(errno
);
357 static NTSTATUS
gpfsacl_get_nt_acl(vfs_handle_struct
*handle
,
359 uint32 security_info
, struct security_descriptor
**ppdesc
)
361 SMB4ACL_T
*pacl
= NULL
;
365 result
= gpfs_get_nfs4_acl(name
, &pacl
);
368 return smb_get_nt_acl_nfs4(handle
->conn
, name
, security_info
, ppdesc
, pacl
);
371 DEBUG(10, ("retrying with posix acl...\n"));
372 return posix_get_nt_acl(handle
->conn
, name
, security_info
, ppdesc
);
375 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
376 return map_nt_error_from_unix(errno
);
379 static bool gpfsacl_process_smbacl(files_struct
*fsp
, SMB4ACL_T
*smbacl
)
382 gpfs_aclLen_t gacl_len
;
384 struct gpfs_acl
*gacl
;
385 TALLOC_CTX
*mem_ctx
= talloc_tos();
387 gacl_len
= sizeof(struct gpfs_acl
) +
388 (smb_get_naces(smbacl
)-1)*sizeof(gpfs_ace_v4_t
);
390 gacl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, gacl_len
);
392 DEBUG(0, ("talloc failed\n"));
397 gacl
->acl_len
= gacl_len
;
399 gacl
->acl_version
= GPFS_ACL_VERSION_NFS4
;
400 gacl
->acl_type
= GPFS_ACL_TYPE_NFS4
;
401 gacl
->acl_nace
= 0; /* change later... */
403 for (smbace
=smb_first_ace4(smbacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
404 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[gacl
->acl_nace
];
405 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
407 gace
->aceType
= aceprop
->aceType
;
408 gace
->aceFlags
= aceprop
->aceFlags
;
409 gace
->aceMask
= aceprop
->aceMask
;
412 * GPFS can't distinguish between WRITE and APPEND on
413 * files, so one being set without the other is an
414 * error. Sorry for the many ()'s :-)
417 if (!fsp
->is_directory
419 ((((gace
->aceMask
& ACE4_MASK_WRITE
) == 0)
420 && ((gace
->aceMask
& ACE4_MASK_APPEND
) != 0))
422 (((gace
->aceMask
& ACE4_MASK_WRITE
) != 0)
423 && ((gace
->aceMask
& ACE4_MASK_APPEND
) == 0)))
425 lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
426 "merge_writeappend", True
)) {
427 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
428 "WRITE^APPEND, setting WRITE|APPEND\n",
430 gace
->aceMask
|= ACE4_MASK_WRITE
|ACE4_MASK_APPEND
;
433 gace
->aceIFlags
= (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
) ? ACE4_IFLAG_SPECIAL_ID
: 0;
435 if (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
)
437 switch(aceprop
->who
.special_id
)
439 case SMB_ACE4_WHO_EVERYONE
:
440 gace
->aceWho
= ACE4_SPECIAL_EVERYONE
;
442 case SMB_ACE4_WHO_OWNER
:
443 gace
->aceWho
= ACE4_SPECIAL_OWNER
;
445 case SMB_ACE4_WHO_GROUP
:
446 gace
->aceWho
= ACE4_SPECIAL_GROUP
;
449 DEBUG(8, ("unsupported special_id %d\n", aceprop
->who
.special_id
));
450 continue; /* don't add it !!! */
453 /* just only for the type safety... */
454 if (aceprop
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)
455 gace
->aceWho
= aceprop
->who
.gid
;
457 gace
->aceWho
= aceprop
->who
.uid
;
463 ret
= smbd_gpfs_putacl(fsp
->fsp_name
->base_name
,
464 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gacl
);
466 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno
)));
467 gpfs_dumpacl(8, gacl
);
471 DEBUG(10, ("gpfs_putacl succeeded\n"));
475 static NTSTATUS
gpfsacl_set_nt_acl_internal(files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
477 struct gpfs_acl
*acl
;
478 NTSTATUS result
= NT_STATUS_ACCESS_DENIED
;
480 acl
= gpfs_getacl_alloc(fsp
->fsp_name
->base_name
, 0);
484 if (acl
->acl_version
&GPFS_ACL_VERSION_NFS4
)
486 if (lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
487 "refuse_dacl_protected", false)
488 && (psd
->type
&SEC_DESC_DACL_PROTECTED
)) {
489 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
490 return NT_STATUS_NOT_SUPPORTED
;
493 result
= smb_set_nt_acl_nfs4(
494 fsp
, security_info_sent
, psd
,
495 gpfsacl_process_smbacl
);
496 } else { /* assume POSIX ACL - by default... */
497 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
503 static NTSTATUS
gpfsacl_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
505 return gpfsacl_set_nt_acl_internal(fsp
, security_info_sent
, psd
);
508 static SMB_ACL_T
gpfs2smb_acl(const struct gpfs_acl
*pacl
)
513 result
= sys_acl_init(pacl
->acl_nace
);
514 if (result
== NULL
) {
519 result
->count
= pacl
->acl_nace
;
521 for (i
=0; i
<pacl
->acl_nace
; i
++) {
522 struct smb_acl_entry
*ace
= &result
->acl
[i
];
523 const struct gpfs_ace_v1
*g_ace
= &pacl
->ace_v1
[i
];
525 DEBUG(10, ("Converting type %d id %lu perm %x\n",
526 (int)g_ace
->ace_type
, (unsigned long)g_ace
->ace_who
,
527 (int)g_ace
->ace_perm
));
529 switch (g_ace
->ace_type
) {
531 ace
->a_type
= SMB_ACL_USER
;
532 ace
->uid
= (uid_t
)g_ace
->ace_who
;
534 case GPFS_ACL_USER_OBJ
:
535 ace
->a_type
= SMB_ACL_USER_OBJ
;
538 ace
->a_type
= SMB_ACL_GROUP
;
539 ace
->gid
= (gid_t
)g_ace
->ace_who
;
541 case GPFS_ACL_GROUP_OBJ
:
542 ace
->a_type
= SMB_ACL_GROUP_OBJ
;
545 ace
->a_type
= SMB_ACL_OTHER
;
548 ace
->a_type
= SMB_ACL_MASK
;
551 DEBUG(10, ("Got invalid ace_type: %d\n",
559 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_READ
) ?
561 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_WRITE
) ?
563 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_EXECUTE
) ?
566 DEBUGADD(10, ("Converted to %d perm %x\n",
567 ace
->a_type
, ace
->a_perm
));
573 static SMB_ACL_T
gpfsacl_get_posix_acl(const char *path
, gpfs_aclType_t type
)
575 struct gpfs_acl
*pacl
;
576 SMB_ACL_T result
= NULL
;
578 pacl
= gpfs_getacl_alloc(path
, type
);
581 DEBUG(10, ("gpfs_getacl failed for %s with %s\n",
582 path
, strerror(errno
)));
589 if (pacl
->acl_version
!= GPFS_ACL_VERSION_POSIX
) {
590 DEBUG(10, ("Got acl version %d, expected %d\n",
591 pacl
->acl_version
, GPFS_ACL_VERSION_POSIX
));
596 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
597 pacl
->acl_len
, pacl
->acl_level
, pacl
->acl_version
,
600 result
= gpfs2smb_acl(pacl
);
601 if (result
== NULL
) {
613 static SMB_ACL_T
gpfsacl_sys_acl_get_file(vfs_handle_struct
*handle
,
617 gpfs_aclType_t gpfs_type
;
620 case SMB_ACL_TYPE_ACCESS
:
621 gpfs_type
= GPFS_ACL_TYPE_ACCESS
;
623 case SMB_ACL_TYPE_DEFAULT
:
624 gpfs_type
= GPFS_ACL_TYPE_DEFAULT
;
627 DEBUG(0, ("Got invalid type: %d\n", type
));
628 smb_panic("exiting");
631 return gpfsacl_get_posix_acl(path_p
, gpfs_type
);
634 static SMB_ACL_T
gpfsacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
637 return gpfsacl_get_posix_acl(fsp
->fsp_name
->base_name
,
638 GPFS_ACL_TYPE_ACCESS
);
641 static struct gpfs_acl
*smb2gpfs_acl(const SMB_ACL_T pacl
,
645 struct gpfs_acl
*result
;
649 gpfs_ace_v1_t ace_v1
[1]; /* when GPFS_ACL_VERSION_POSIX */
650 gpfs_ace_v4_t ace_v4
[1]; /* when GPFS_ACL_VERSION_NFS4 */
653 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl
->count
));
655 len
= sizeof(struct gpfs_acl
) - sizeof(union gpfs_ace_union
) +
656 (pacl
->count
)*sizeof(gpfs_ace_v1_t
);
658 result
= (struct gpfs_acl
*)SMB_MALLOC(len
);
659 if (result
== NULL
) {
664 result
->acl_len
= len
;
665 result
->acl_level
= 0;
666 result
->acl_version
= GPFS_ACL_VERSION_POSIX
;
667 result
->acl_type
= (type
== SMB_ACL_TYPE_DEFAULT
) ?
668 GPFS_ACL_TYPE_DEFAULT
: GPFS_ACL_TYPE_ACCESS
;
669 result
->acl_nace
= pacl
->count
;
671 for (i
=0; i
<pacl
->count
; i
++) {
672 const struct smb_acl_entry
*ace
= &pacl
->acl
[i
];
673 struct gpfs_ace_v1
*g_ace
= &result
->ace_v1
[i
];
675 DEBUG(10, ("Converting type %d perm %x\n",
676 (int)ace
->a_type
, (int)ace
->a_perm
));
680 switch(ace
->a_type
) {
682 g_ace
->ace_type
= GPFS_ACL_USER
;
683 g_ace
->ace_who
= (gpfs_uid_t
)ace
->uid
;
685 case SMB_ACL_USER_OBJ
:
686 g_ace
->ace_type
= GPFS_ACL_USER_OBJ
;
687 g_ace
->ace_perm
|= ACL_PERM_CONTROL
;
691 g_ace
->ace_type
= GPFS_ACL_GROUP
;
692 g_ace
->ace_who
= (gpfs_uid_t
)ace
->gid
;
694 case SMB_ACL_GROUP_OBJ
:
695 g_ace
->ace_type
= GPFS_ACL_GROUP_OBJ
;
699 g_ace
->ace_type
= GPFS_ACL_MASK
;
700 g_ace
->ace_perm
= 0x8f;
704 g_ace
->ace_type
= GPFS_ACL_OTHER
;
708 DEBUG(10, ("Got invalid ace_type: %d\n", ace
->a_type
));
714 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_READ
) ?
716 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_WRITE
) ?
718 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_EXECUTE
) ?
719 ACL_PERM_EXECUTE
: 0;
721 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
722 g_ace
->ace_type
, g_ace
->ace_who
, g_ace
->ace_perm
));
728 static int gpfsacl_sys_acl_set_file(vfs_handle_struct
*handle
,
733 struct gpfs_acl
*gpfs_acl
;
736 gpfs_acl
= smb2gpfs_acl(theacl
, type
);
737 if (gpfs_acl
== NULL
) {
741 result
= smbd_gpfs_putacl((char *)name
, GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gpfs_acl
);
747 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
751 return gpfsacl_sys_acl_set_file(handle
, fsp
->fsp_name
->base_name
,
752 SMB_ACL_TYPE_ACCESS
, theacl
);
755 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
763 * Assumed: mode bits are shiftable and standard
764 * Output: the new aceMask field for an smb nfs4 ace
766 static uint32
gpfsacl_mask_filter(uint32 aceType
, uint32 aceMask
, uint32 rwx
)
768 const uint32 posix_nfs4map
[3] = {
769 SMB_ACE4_EXECUTE
, /* execute */
770 SMB_ACE4_WRITE_DATA
| SMB_ACE4_APPEND_DATA
, /* write; GPFS specific */
771 SMB_ACE4_READ_DATA
/* read */
774 uint32_t posix_mask
= 0x01;
779 nfs4_bits
= posix_nfs4map
[i
];
780 posix_bit
= rwx
& posix_mask
;
782 if (aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
) {
784 aceMask
|= nfs4_bits
;
786 aceMask
&= ~nfs4_bits
;
788 /* add deny bits when suitable */
790 aceMask
|= nfs4_bits
;
792 aceMask
&= ~nfs4_bits
;
793 } /* other ace types are unexpected */
801 static int gpfsacl_emu_chmod(const char *path
, mode_t mode
)
803 SMB4ACL_T
*pacl
= NULL
;
805 bool haveAllowEntry
[SMB_ACE4_WHO_EVERYONE
+ 1] = {False
, False
, False
, False
};
807 files_struct fake_fsp
; /* TODO: rationalize parametrization */
811 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path
, mode
));
813 result
= gpfs_get_nfs4_acl(path
, &pacl
);
817 if (mode
& ~(S_IRWXU
| S_IRWXG
| S_IRWXO
)) {
818 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode
, path
));
821 for (smbace
=smb_first_ace4(pacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
822 SMB_ACE4PROP_T
*ace
= smb_get_ace4(smbace
);
823 uint32_t specid
= ace
->who
.special_id
;
825 if (ace
->flags
&SMB_ACE4_ID_SPECIAL
&&
826 ace
->aceType
<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE
&&
827 specid
<= SMB_ACE4_WHO_EVERYONE
) {
831 if (ace
->aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
)
832 haveAllowEntry
[specid
] = True
;
834 /* mode >> 6 for @owner, mode >> 3 for @group,
835 * mode >> 0 for @everyone */
836 newMask
= gpfsacl_mask_filter(ace
->aceType
, ace
->aceMask
,
837 mode
>> ((SMB_ACE4_WHO_EVERYONE
- specid
) * 3));
838 if (ace
->aceMask
!=newMask
) {
839 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
840 path
, ace
->aceMask
, newMask
, specid
));
842 ace
->aceMask
= newMask
;
846 /* make sure we have at least ALLOW entries
847 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
850 for(i
= SMB_ACE4_WHO_OWNER
; i
<=SMB_ACE4_WHO_EVERYONE
; i
++) {
853 if (haveAllowEntry
[i
]==True
)
857 ace
.aceType
= SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
;
858 ace
.flags
|= SMB_ACE4_ID_SPECIAL
;
859 ace
.who
.special_id
= i
;
861 if (i
==SMB_ACE4_WHO_GROUP
) /* not sure it's necessary... */
862 ace
.aceFlags
|= SMB_ACE4_IDENTIFIER_GROUP
;
864 ace
.aceMask
= gpfsacl_mask_filter(ace
.aceType
, ace
.aceMask
,
865 mode
>> ((SMB_ACE4_WHO_EVERYONE
- i
) * 3));
867 /* don't add unnecessary aces */
871 /* we add it to the END - as windows expects allow aces */
872 smb_add_ace4(pacl
, &ace
);
873 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
874 path
, mode
, i
, ace
.aceMask
));
877 /* don't add complementary DENY ACEs here */
878 ZERO_STRUCT(fake_fsp
);
879 status
= create_synthetic_smb_fname(talloc_tos(), path
, NULL
, NULL
,
881 if (!NT_STATUS_IS_OK(status
)) {
882 errno
= map_errno_from_nt_status(status
);
886 if (gpfsacl_process_smbacl(&fake_fsp
, pacl
) == False
) {
887 TALLOC_FREE(fake_fsp
.fsp_name
);
891 TALLOC_FREE(fake_fsp
.fsp_name
);
892 return 0; /* ok for [f]chmod */
895 static int vfs_gpfs_chmod(vfs_handle_struct
*handle
, const char *path
, mode_t mode
)
897 struct smb_filename
*smb_fname_cpath
;
901 status
= create_synthetic_smb_fname(
902 talloc_tos(), path
, NULL
, NULL
, &smb_fname_cpath
);
904 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_cpath
) != 0) {
908 /* avoid chmod() if possible, to preserve acls */
909 if ((smb_fname_cpath
->st
.st_ex_mode
& ~S_IFMT
) == mode
) {
913 rc
= gpfsacl_emu_chmod(path
, mode
);
915 return SMB_VFS_NEXT_CHMOD(handle
, path
, mode
);
919 static int vfs_gpfs_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
924 if (SMB_VFS_NEXT_FSTAT(handle
, fsp
, &st
) != 0) {
928 /* avoid chmod() if possible, to preserve acls */
929 if ((st
.st_ex_mode
& ~S_IFMT
) == mode
) {
933 rc
= gpfsacl_emu_chmod(fsp
->fsp_name
->base_name
, mode
);
935 return SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
939 static int gpfs_set_xattr(struct vfs_handle_struct
*handle
, const char *path
,
940 const char *name
, const void *value
, size_t size
, int flags
){
941 struct xattr_DOSATTRIB dosattrib
;
942 enum ndr_err_code ndr_err
;
944 const char *attrstr
= value
;
945 unsigned int dosmode
=0;
946 struct gpfs_winattr attrs
;
949 DEBUG(10, ("gpfs_set_xattr: %s \n",path
));
951 /* Only handle DOS Attributes */
952 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
953 DEBUG(1, ("gpfs_set_xattr:name is %s\n",name
));
954 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
957 blob
.data
= (uint8_t *)attrstr
;
960 ndr_err
= ndr_pull_struct_blob(&blob
, talloc_tos(), &dosattrib
,
961 (ndr_pull_flags_fn_t
)ndr_pull_xattr_DOSATTRIB
);
963 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
964 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
965 "from EA on file %s: Error = %s\n",
966 path
, ndr_errstr(ndr_err
)));
970 if (dosattrib
.version
!= 3) {
971 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
972 "%d\n", (int)dosattrib
.version
));
975 if (!(dosattrib
.info
.info3
.valid_flags
& XATTR_DOSINFO_ATTRIB
)) {
976 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
977 "valid, ignoring\n"));
981 dosmode
= dosattrib
.info
.info3
.attrib
;
984 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
985 if (dosmode
& FILE_ATTRIBUTE_ARCHIVE
){
986 attrs
.winAttrs
|= GPFS_WINATTR_ARCHIVE
;
988 if (dosmode
& FILE_ATTRIBUTE_HIDDEN
){
989 attrs
.winAttrs
|= GPFS_WINATTR_HIDDEN
;
991 if (dosmode
& FILE_ATTRIBUTE_SYSTEM
){
992 attrs
.winAttrs
|= GPFS_WINATTR_SYSTEM
;
994 if (dosmode
& FILE_ATTRIBUTE_READONLY
){
995 attrs
.winAttrs
|= GPFS_WINATTR_READONLY
;
997 if (dosmode
& FILE_ATTRIBUTE_SPARSE
) {
998 attrs
.winAttrs
|= GPFS_WINATTR_SPARSE_FILE
;
1002 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1003 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1005 if (errno
== ENOSYS
) {
1006 return SMB_VFS_NEXT_SETXATTR(handle
, path
, name
, value
,
1010 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret
));
1014 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs
.winAttrs
));
1018 static ssize_t
gpfs_get_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1019 const char *name
, void *value
, size_t size
){
1020 char *attrstr
= value
;
1021 unsigned int dosmode
= 0;
1022 struct gpfs_winattr attrs
;
1025 DEBUG(10, ("gpfs_get_xattr: %s \n",path
));
1027 /* Only handle DOS Attributes */
1028 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1029 DEBUG(1, ("gpfs_get_xattr:name is %s\n",name
));
1030 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1033 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1035 if (errno
== ENOSYS
) {
1036 return SMB_VFS_NEXT_GETXATTR(handle
, path
, name
, value
,
1040 DEBUG(1, ("gpfs_get_xattr: Get GPFS attributes failed: "
1041 "%d (%s)\n", ret
, strerror(errno
)));
1045 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs
.winAttrs
));
1047 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1048 if (attrs
.winAttrs
& GPFS_WINATTR_ARCHIVE
){
1049 dosmode
|= FILE_ATTRIBUTE_ARCHIVE
;
1051 if (attrs
.winAttrs
& GPFS_WINATTR_HIDDEN
){
1052 dosmode
|= FILE_ATTRIBUTE_HIDDEN
;
1054 if (attrs
.winAttrs
& GPFS_WINATTR_SYSTEM
){
1055 dosmode
|= FILE_ATTRIBUTE_SYSTEM
;
1057 if (attrs
.winAttrs
& GPFS_WINATTR_READONLY
){
1058 dosmode
|= FILE_ATTRIBUTE_READONLY
;
1060 if (attrs
.winAttrs
& GPFS_WINATTR_SPARSE_FILE
) {
1061 dosmode
|= FILE_ATTRIBUTE_SPARSE
;
1064 snprintf(attrstr
, size
, "0x%2.2x",
1065 (unsigned int)(dosmode
& SAMBA_ATTRIBUTES_MASK
));
1066 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr
));
1070 static int vfs_gpfs_stat(struct vfs_handle_struct
*handle
,
1071 struct smb_filename
*smb_fname
)
1073 struct gpfs_winattr attrs
;
1078 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
1082 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &fname
);
1083 if (!NT_STATUS_IS_OK(status
)) {
1084 errno
= map_errno_from_nt_status(status
);
1087 ret
= get_gpfs_winattrs(discard_const_p(char, fname
), &attrs
);
1090 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1091 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1092 smb_fname
->st
.vfs_private
= attrs
.winAttrs
;
1097 static int vfs_gpfs_fstat(struct vfs_handle_struct
*handle
,
1098 struct files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
1100 struct gpfs_winattr attrs
;
1103 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
1107 if ((fsp
->fh
== NULL
) || (fsp
->fh
->fd
== -1)) {
1110 ret
= smbd_fget_gpfs_winattrs(fsp
->fh
->fd
, &attrs
);
1112 sbuf
->st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1113 sbuf
->st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1118 static int vfs_gpfs_lstat(struct vfs_handle_struct
*handle
,
1119 struct smb_filename
*smb_fname
)
1121 struct gpfs_winattr attrs
;
1126 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
1130 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1131 if (!NT_STATUS_IS_OK(status
)) {
1132 errno
= map_errno_from_nt_status(status
);
1135 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1138 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1139 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1140 smb_fname
->st
.vfs_private
= attrs
.winAttrs
;
1145 static int vfs_gpfs_ntimes(struct vfs_handle_struct
*handle
,
1146 const struct smb_filename
*smb_fname
,
1147 struct smb_file_time
*ft
)
1150 struct gpfs_winattr attrs
;
1155 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1157 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed\n"));
1161 if(null_timespec(ft
->create_time
)){
1162 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1166 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1167 if (!NT_STATUS_IS_OK(status
)) {
1168 errno
= map_errno_from_nt_status(status
);
1173 attrs
.creationTime
.tv_sec
= ft
->create_time
.tv_sec
;
1174 attrs
.creationTime
.tv_nsec
= ft
->create_time
.tv_nsec
;
1176 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1177 GPFS_WINATTR_SET_CREATION_TIME
, &attrs
);
1178 if(ret
== -1 && errno
!= ENOSYS
){
1179 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret
));
1186 static int vfs_gpfs_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1191 result
= smbd_gpfs_ftruncate(fsp
->fh
->fd
, len
);
1192 if ((result
== -1) && (errno
== ENOSYS
)) {
1193 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1198 static bool vfs_gpfs_is_offline(struct vfs_handle_struct
*handle
,
1199 const struct smb_filename
*fname
,
1200 SMB_STRUCT_STAT
*sbuf
)
1202 struct gpfs_winattr attrs
;
1206 status
= get_full_smb_filename(talloc_tos(), fname
, &path
);
1207 if (!NT_STATUS_IS_OK(status
)) {
1208 errno
= map_errno_from_nt_status(status
);
1212 if (VALID_STAT(*sbuf
)) {
1213 attrs
.winAttrs
= sbuf
->vfs_private
;
1216 ret
= get_gpfs_winattrs(path
, &attrs
);
1223 if ((attrs
.winAttrs
& GPFS_WINATTR_OFFLINE
) != 0) {
1224 DEBUG(10, ("%s is offline\n", path
));
1228 DEBUG(10, ("%s is online\n", path
));
1230 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1233 static bool vfs_gpfs_aio_force(struct vfs_handle_struct
*handle
,
1234 struct files_struct
*fsp
)
1236 return vfs_gpfs_is_offline(handle
, fsp
->fsp_name
, &fsp
->fsp_name
->st
);
1239 static ssize_t
vfs_gpfs_sendfile(vfs_handle_struct
*handle
, int tofd
,
1240 files_struct
*fsp
, const DATA_BLOB
*hdr
,
1241 SMB_OFF_T offset
, size_t n
)
1243 if ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0) {
1247 return SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fsp
, hdr
, offset
, n
);
1250 int vfs_gpfs_connect(struct vfs_handle_struct
*handle
, const char *service
,
1253 struct gpfs_config_data
*config
;
1255 smbd_gpfs_lib_init();
1257 int ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1263 config
= talloc_zero(handle
->conn
, struct gpfs_config_data
);
1265 SMB_VFS_NEXT_DISCONNECT(handle
);
1266 DEBUG(0, ("talloc_zero() failed\n")); return -1;
1269 config
->sharemodes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1270 "sharemodes", true);
1272 config
->leases
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1275 config
->hsm
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1278 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
1279 NULL
, struct gpfs_config_data
,
1285 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct
*handle
,
1286 enum timestamp_set_resolution
*p_ts_res
)
1288 struct gpfs_config_data
*config
;
1291 next
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
1293 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1294 struct gpfs_config_data
,
1298 next
|= FILE_SUPPORTS_REMOTE_STORAGE
;
1303 static int vfs_gpfs_open(struct vfs_handle_struct
*handle
,
1304 struct smb_filename
*smb_fname
, files_struct
*fsp
,
1305 int flags
, mode_t mode
)
1307 if (lp_parm_bool(fsp
->conn
->params
->service
, "gpfs", "syncio",
1311 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
1315 static struct vfs_fn_pointers vfs_gpfs_fns
= {
1316 .connect_fn
= vfs_gpfs_connect
,
1317 .fs_capabilities
= vfs_gpfs_capabilities
,
1318 .kernel_flock
= vfs_gpfs_kernel_flock
,
1319 .linux_setlease
= vfs_gpfs_setlease
,
1320 .get_real_filename
= vfs_gpfs_get_real_filename
,
1321 .fget_nt_acl
= gpfsacl_fget_nt_acl
,
1322 .get_nt_acl
= gpfsacl_get_nt_acl
,
1323 .fset_nt_acl
= gpfsacl_fset_nt_acl
,
1324 .sys_acl_get_file
= gpfsacl_sys_acl_get_file
,
1325 .sys_acl_get_fd
= gpfsacl_sys_acl_get_fd
,
1326 .sys_acl_set_file
= gpfsacl_sys_acl_set_file
,
1327 .sys_acl_set_fd
= gpfsacl_sys_acl_set_fd
,
1328 .sys_acl_delete_def_file
= gpfsacl_sys_acl_delete_def_file
,
1329 .chmod
= vfs_gpfs_chmod
,
1330 .fchmod
= vfs_gpfs_fchmod
,
1331 .close_fn
= vfs_gpfs_close
,
1332 .setxattr
= gpfs_set_xattr
,
1333 .getxattr
= gpfs_get_xattr
,
1334 .stat
= vfs_gpfs_stat
,
1335 .fstat
= vfs_gpfs_fstat
,
1336 .lstat
= vfs_gpfs_lstat
,
1337 .ntimes
= vfs_gpfs_ntimes
,
1338 .is_offline
= vfs_gpfs_is_offline
,
1339 .aio_force
= vfs_gpfs_aio_force
,
1340 .sendfile
= vfs_gpfs_sendfile
,
1341 .open_fn
= vfs_gpfs_open
,
1342 .ftruncate
= vfs_gpfs_ftruncate
1345 NTSTATUS
vfs_gpfs_init(void);
1346 NTSTATUS
vfs_gpfs_init(void)
1350 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "gpfs",