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"
36 struct gpfs_config_data
{
43 static int vfs_gpfs_kernel_flock(vfs_handle_struct
*handle
, files_struct
*fsp
,
44 uint32 share_mode
, uint32 access_mask
)
47 struct gpfs_config_data
*config
;
49 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
50 struct gpfs_config_data
,
53 START_PROFILE(syscall_kernel_flock
);
55 kernel_flock(fsp
->fh
->fd
, share_mode
, access_mask
);
57 if (config
->sharemodes
58 && !set_gpfs_sharemode(fsp
, access_mask
, fsp
->share_access
)) {
62 END_PROFILE(syscall_kernel_flock
);
67 static int vfs_gpfs_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
70 struct gpfs_config_data
*config
;
72 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
73 struct gpfs_config_data
,
76 if (config
->sharemodes
&& (fsp
->fh
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
77 set_gpfs_sharemode(fsp
, 0, 0);
80 return SMB_VFS_NEXT_CLOSE(handle
, fsp
);
83 static int vfs_gpfs_setlease(vfs_handle_struct
*handle
, files_struct
*fsp
,
86 struct gpfs_config_data
*config
;
89 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
90 struct gpfs_config_data
,
93 START_PROFILE(syscall_linux_setlease
);
95 if (linux_set_lease_sighandler(fsp
->fh
->fd
) == -1)
99 ret
= set_gpfs_lease(fsp
->fh
->fd
,leasetype
);
103 /* This must have come from GPFS not being available */
104 /* or some other error, hence call the default */
105 ret
= linux_setlease(fsp
->fh
->fd
, leasetype
);
108 END_PROFILE(syscall_linux_setlease
);
113 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct
*handle
,
121 char real_pathname
[PATH_MAX
+1];
125 mangled
= mangle_is_mangled(name
, handle
->conn
->params
);
127 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
128 mem_ctx
, found_name
);
131 full_path
= talloc_asprintf(talloc_tos(), "%s/%s", path
, name
);
132 if (full_path
== NULL
) {
137 buflen
= sizeof(real_pathname
) - 1;
139 result
= smbd_gpfs_get_realfilename_path(full_path
, real_pathname
,
142 TALLOC_FREE(full_path
);
144 if ((result
== -1) && (errno
== ENOSYS
)) {
145 return SMB_VFS_NEXT_GET_REAL_FILENAME(
146 handle
, path
, name
, mem_ctx
, found_name
);
150 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
156 * GPFS does not necessarily null-terminate the returned path
157 * but instead returns the buffer length in buflen.
160 if (buflen
< sizeof(real_pathname
)) {
161 real_pathname
[buflen
] = '\0';
163 real_pathname
[sizeof(real_pathname
)-1] = '\0';
166 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
167 path
, name
, real_pathname
));
169 name
= strrchr_m(real_pathname
, '/');
175 *found_name
= talloc_strdup(mem_ctx
, name
+1);
176 if (*found_name
== NULL
) {
184 static void gpfs_dumpacl(int level
, struct gpfs_acl
*gacl
)
189 DEBUG(0, ("gpfs acl is NULL\n"));
193 DEBUG(level
, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n",
194 gacl
->acl_nace
, gacl
->acl_type
, gacl
->acl_version
, gacl
->acl_level
, gacl
->acl_len
));
195 for(i
=0; i
<gacl
->acl_nace
; i
++)
197 struct gpfs_ace_v4
*gace
= gacl
->ace_v4
+ i
;
198 DEBUG(level
, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n",
199 i
, gace
->aceType
, gace
->aceFlags
, gace
->aceMask
,
200 gace
->aceIFlags
, gace
->aceWho
));
204 static struct gpfs_acl
*gpfs_getacl_alloc(const char *fname
, gpfs_aclType_t type
)
206 struct gpfs_acl
*acl
;
209 TALLOC_CTX
*mem_ctx
= talloc_tos();
211 acl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, len
);
219 acl
->acl_version
= 0;
220 acl
->acl_type
= type
;
222 ret
= smbd_gpfs_getacl((char *)fname
, GPFS_GETACL_STRUCT
| GPFS_ACL_SAMBA
, acl
);
223 if ((ret
!= 0) && (errno
== ENOSPC
)) {
224 struct gpfs_acl
*new_acl
= (struct gpfs_acl
*)TALLOC_SIZE(
225 mem_ctx
, acl
->acl_len
+ sizeof(struct gpfs_acl
));
226 if (new_acl
== NULL
) {
231 new_acl
->acl_len
= acl
->acl_len
;
232 new_acl
->acl_level
= acl
->acl_level
;
233 new_acl
->acl_version
= acl
->acl_version
;
234 new_acl
->acl_type
= acl
->acl_type
;
237 ret
= smbd_gpfs_getacl((char *)fname
, GPFS_GETACL_STRUCT
| GPFS_ACL_SAMBA
, acl
);
241 DEBUG(8, ("smbd_gpfs_getacl failed with %s\n",strerror(errno
)));
248 /* Tries to get nfs4 acls and returns SMB ACL allocated.
249 * On failure returns 1 if it got non-NFSv4 ACL to prompt
250 * retry with POSIX ACL checks.
251 * On failure returns -1 if there is system (GPFS) error, check errno.
252 * Returns 0 on success
254 static int gpfs_get_nfs4_acl(const char *fname
, SMB4ACL_T
**ppacl
)
257 struct gpfs_acl
*gacl
= NULL
;
258 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname
));
260 /* First get the real acl length */
261 gacl
= gpfs_getacl_alloc(fname
, 0);
263 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
264 fname
, strerror(errno
)));
268 if (gacl
->acl_type
!= GPFS_ACL_TYPE_NFS4
) {
269 DEBUG(10, ("Got non-nfsv4 acl\n"));
270 /* Retry with POSIX ACLs check */
274 *ppacl
= smb_create_smb4acl();
276 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
277 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
280 for (i
=0; i
<gacl
->acl_nace
; i
++) {
281 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[i
];
282 SMB_ACE4PROP_T smbace
;
283 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
284 "who: %d\n", gace
->aceType
, gace
->aceIFlags
,
285 gace
->aceFlags
, gace
->aceMask
, gace
->aceWho
));
288 if (gace
->aceIFlags
& ACE4_IFLAG_SPECIAL_ID
) {
289 smbace
.flags
|= SMB_ACE4_ID_SPECIAL
;
290 switch (gace
->aceWho
) {
291 case ACE4_SPECIAL_OWNER
:
292 smbace
.who
.special_id
= SMB_ACE4_WHO_OWNER
;
294 case ACE4_SPECIAL_GROUP
:
295 smbace
.who
.special_id
= SMB_ACE4_WHO_GROUP
;
297 case ACE4_SPECIAL_EVERYONE
:
298 smbace
.who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
301 DEBUG(8, ("invalid special gpfs id %d "
302 "ignored\n", gace
->aceWho
));
303 continue; /* don't add it */
306 if (gace
->aceFlags
& ACE4_FLAG_GROUP_ID
)
307 smbace
.who
.gid
= gace
->aceWho
;
309 smbace
.who
.uid
= gace
->aceWho
;
312 /* remove redundent deny entries */
313 if (i
> 0 && gace
->aceType
== SMB_ACE4_ACCESS_DENIED_ACE_TYPE
) {
314 struct gpfs_ace_v4
*prev
= &gacl
->ace_v4
[i
-1];
315 if (prev
->aceType
== SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
&&
316 prev
->aceFlags
== gace
->aceFlags
&&
317 prev
->aceIFlags
== gace
->aceIFlags
&&
318 (gace
->aceMask
& prev
->aceMask
) == 0 &&
319 gace
->aceWho
== prev
->aceWho
) {
320 /* its redundent - skip it */
325 smbace
.aceType
= gace
->aceType
;
326 smbace
.aceFlags
= gace
->aceFlags
;
327 smbace
.aceMask
= gace
->aceMask
;
328 smb_add_ace4(*ppacl
, &smbace
);
334 static NTSTATUS
gpfsacl_fget_nt_acl(vfs_handle_struct
*handle
,
335 files_struct
*fsp
, uint32 security_info
,
336 struct security_descriptor
**ppdesc
)
338 SMB4ACL_T
*pacl
= NULL
;
342 result
= gpfs_get_nfs4_acl(fsp
->fsp_name
->base_name
, &pacl
);
345 return smb_fget_nt_acl_nfs4(fsp
, security_info
, ppdesc
, pacl
);
348 DEBUG(10, ("retrying with posix acl...\n"));
349 return posix_fget_nt_acl(fsp
, security_info
, ppdesc
);
352 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
353 return map_nt_error_from_unix(errno
);
356 static NTSTATUS
gpfsacl_get_nt_acl(vfs_handle_struct
*handle
,
358 uint32 security_info
, struct security_descriptor
**ppdesc
)
360 SMB4ACL_T
*pacl
= NULL
;
364 result
= gpfs_get_nfs4_acl(name
, &pacl
);
367 return smb_get_nt_acl_nfs4(handle
->conn
, name
, security_info
, ppdesc
, pacl
);
370 DEBUG(10, ("retrying with posix acl...\n"));
371 return posix_get_nt_acl(handle
->conn
, name
, security_info
, ppdesc
);
374 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
375 return map_nt_error_from_unix(errno
);
378 static bool gpfsacl_process_smbacl(files_struct
*fsp
, SMB4ACL_T
*smbacl
)
381 gpfs_aclLen_t gacl_len
;
383 struct gpfs_acl
*gacl
;
384 TALLOC_CTX
*mem_ctx
= talloc_tos();
386 gacl_len
= sizeof(struct gpfs_acl
) +
387 (smb_get_naces(smbacl
)-1)*sizeof(gpfs_ace_v4_t
);
389 gacl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, gacl_len
);
391 DEBUG(0, ("talloc failed\n"));
396 gacl
->acl_len
= gacl_len
;
398 gacl
->acl_version
= GPFS_ACL_VERSION_NFS4
;
399 gacl
->acl_type
= GPFS_ACL_TYPE_NFS4
;
400 gacl
->acl_nace
= 0; /* change later... */
402 for (smbace
=smb_first_ace4(smbacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
403 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[gacl
->acl_nace
];
404 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
406 gace
->aceType
= aceprop
->aceType
;
407 gace
->aceFlags
= aceprop
->aceFlags
;
408 gace
->aceMask
= aceprop
->aceMask
;
411 * GPFS can't distinguish between WRITE and APPEND on
412 * files, so one being set without the other is an
413 * error. Sorry for the many ()'s :-)
416 if (!fsp
->is_directory
418 ((((gace
->aceMask
& ACE4_MASK_WRITE
) == 0)
419 && ((gace
->aceMask
& ACE4_MASK_APPEND
) != 0))
421 (((gace
->aceMask
& ACE4_MASK_WRITE
) != 0)
422 && ((gace
->aceMask
& ACE4_MASK_APPEND
) == 0)))
424 lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
425 "merge_writeappend", True
)) {
426 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
427 "WRITE^APPEND, setting WRITE|APPEND\n",
429 gace
->aceMask
|= ACE4_MASK_WRITE
|ACE4_MASK_APPEND
;
432 gace
->aceIFlags
= (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
) ? ACE4_IFLAG_SPECIAL_ID
: 0;
434 if (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
)
436 switch(aceprop
->who
.special_id
)
438 case SMB_ACE4_WHO_EVERYONE
:
439 gace
->aceWho
= ACE4_SPECIAL_EVERYONE
;
441 case SMB_ACE4_WHO_OWNER
:
442 gace
->aceWho
= ACE4_SPECIAL_OWNER
;
444 case SMB_ACE4_WHO_GROUP
:
445 gace
->aceWho
= ACE4_SPECIAL_GROUP
;
448 DEBUG(8, ("unsupported special_id %d\n", aceprop
->who
.special_id
));
449 continue; /* don't add it !!! */
452 /* just only for the type safety... */
453 if (aceprop
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)
454 gace
->aceWho
= aceprop
->who
.gid
;
456 gace
->aceWho
= aceprop
->who
.uid
;
462 ret
= smbd_gpfs_putacl(fsp
->fsp_name
->base_name
,
463 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gacl
);
465 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno
)));
466 gpfs_dumpacl(8, gacl
);
470 DEBUG(10, ("gpfs_putacl succeeded\n"));
474 static NTSTATUS
gpfsacl_set_nt_acl_internal(files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
476 struct gpfs_acl
*acl
;
477 NTSTATUS result
= NT_STATUS_ACCESS_DENIED
;
479 acl
= gpfs_getacl_alloc(fsp
->fsp_name
->base_name
, 0);
483 if (acl
->acl_version
&GPFS_ACL_VERSION_NFS4
)
485 if (lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
486 "refuse_dacl_protected", false)
487 && (psd
->type
&SEC_DESC_DACL_PROTECTED
)) {
488 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
489 return NT_STATUS_NOT_SUPPORTED
;
492 result
= smb_set_nt_acl_nfs4(
493 fsp
, security_info_sent
, psd
,
494 gpfsacl_process_smbacl
);
495 } else { /* assume POSIX ACL - by default... */
496 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
502 static NTSTATUS
gpfsacl_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
504 return gpfsacl_set_nt_acl_internal(fsp
, security_info_sent
, psd
);
507 static SMB_ACL_T
gpfs2smb_acl(const struct gpfs_acl
*pacl
)
512 result
= sys_acl_init(pacl
->acl_nace
);
513 if (result
== NULL
) {
518 result
->count
= pacl
->acl_nace
;
520 for (i
=0; i
<pacl
->acl_nace
; i
++) {
521 struct smb_acl_entry
*ace
= &result
->acl
[i
];
522 const struct gpfs_ace_v1
*g_ace
= &pacl
->ace_v1
[i
];
524 DEBUG(10, ("Converting type %d id %lu perm %x\n",
525 (int)g_ace
->ace_type
, (unsigned long)g_ace
->ace_who
,
526 (int)g_ace
->ace_perm
));
528 switch (g_ace
->ace_type
) {
530 ace
->a_type
= SMB_ACL_USER
;
531 ace
->uid
= (uid_t
)g_ace
->ace_who
;
533 case GPFS_ACL_USER_OBJ
:
534 ace
->a_type
= SMB_ACL_USER_OBJ
;
537 ace
->a_type
= SMB_ACL_GROUP
;
538 ace
->gid
= (gid_t
)g_ace
->ace_who
;
540 case GPFS_ACL_GROUP_OBJ
:
541 ace
->a_type
= SMB_ACL_GROUP_OBJ
;
544 ace
->a_type
= SMB_ACL_OTHER
;
547 ace
->a_type
= SMB_ACL_MASK
;
550 DEBUG(10, ("Got invalid ace_type: %d\n",
558 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_READ
) ?
560 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_WRITE
) ?
562 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_EXECUTE
) ?
565 DEBUGADD(10, ("Converted to %d perm %x\n",
566 ace
->a_type
, ace
->a_perm
));
572 static SMB_ACL_T
gpfsacl_get_posix_acl(const char *path
, gpfs_aclType_t type
)
574 struct gpfs_acl
*pacl
;
575 SMB_ACL_T result
= NULL
;
577 pacl
= gpfs_getacl_alloc(path
, type
);
580 DEBUG(10, ("gpfs_getacl failed for %s with %s\n",
581 path
, strerror(errno
)));
588 if (pacl
->acl_version
!= GPFS_ACL_VERSION_POSIX
) {
589 DEBUG(10, ("Got acl version %d, expected %d\n",
590 pacl
->acl_version
, GPFS_ACL_VERSION_POSIX
));
595 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
596 pacl
->acl_len
, pacl
->acl_level
, pacl
->acl_version
,
599 result
= gpfs2smb_acl(pacl
);
600 if (result
== NULL
) {
612 static SMB_ACL_T
gpfsacl_sys_acl_get_file(vfs_handle_struct
*handle
,
616 gpfs_aclType_t gpfs_type
;
619 case SMB_ACL_TYPE_ACCESS
:
620 gpfs_type
= GPFS_ACL_TYPE_ACCESS
;
622 case SMB_ACL_TYPE_DEFAULT
:
623 gpfs_type
= GPFS_ACL_TYPE_DEFAULT
;
626 DEBUG(0, ("Got invalid type: %d\n", type
));
627 smb_panic("exiting");
630 return gpfsacl_get_posix_acl(path_p
, gpfs_type
);
633 static SMB_ACL_T
gpfsacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
636 return gpfsacl_get_posix_acl(fsp
->fsp_name
->base_name
,
637 GPFS_ACL_TYPE_ACCESS
);
640 static struct gpfs_acl
*smb2gpfs_acl(const SMB_ACL_T pacl
,
644 struct gpfs_acl
*result
;
648 gpfs_ace_v1_t ace_v1
[1]; /* when GPFS_ACL_VERSION_POSIX */
649 gpfs_ace_v4_t ace_v4
[1]; /* when GPFS_ACL_VERSION_NFS4 */
652 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl
->count
));
654 len
= sizeof(struct gpfs_acl
) - sizeof(union gpfs_ace_union
) +
655 (pacl
->count
)*sizeof(gpfs_ace_v1_t
);
657 result
= (struct gpfs_acl
*)SMB_MALLOC(len
);
658 if (result
== NULL
) {
663 result
->acl_len
= len
;
664 result
->acl_level
= 0;
665 result
->acl_version
= GPFS_ACL_VERSION_POSIX
;
666 result
->acl_type
= (type
== SMB_ACL_TYPE_DEFAULT
) ?
667 GPFS_ACL_TYPE_DEFAULT
: GPFS_ACL_TYPE_ACCESS
;
668 result
->acl_nace
= pacl
->count
;
670 for (i
=0; i
<pacl
->count
; i
++) {
671 const struct smb_acl_entry
*ace
= &pacl
->acl
[i
];
672 struct gpfs_ace_v1
*g_ace
= &result
->ace_v1
[i
];
674 DEBUG(10, ("Converting type %d perm %x\n",
675 (int)ace
->a_type
, (int)ace
->a_perm
));
679 switch(ace
->a_type
) {
681 g_ace
->ace_type
= GPFS_ACL_USER
;
682 g_ace
->ace_who
= (gpfs_uid_t
)ace
->uid
;
684 case SMB_ACL_USER_OBJ
:
685 g_ace
->ace_type
= GPFS_ACL_USER_OBJ
;
686 g_ace
->ace_perm
|= ACL_PERM_CONTROL
;
690 g_ace
->ace_type
= GPFS_ACL_GROUP
;
691 g_ace
->ace_who
= (gpfs_uid_t
)ace
->gid
;
693 case SMB_ACL_GROUP_OBJ
:
694 g_ace
->ace_type
= GPFS_ACL_GROUP_OBJ
;
698 g_ace
->ace_type
= GPFS_ACL_MASK
;
699 g_ace
->ace_perm
= 0x8f;
703 g_ace
->ace_type
= GPFS_ACL_OTHER
;
707 DEBUG(10, ("Got invalid ace_type: %d\n", ace
->a_type
));
713 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_READ
) ?
715 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_WRITE
) ?
717 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_EXECUTE
) ?
718 ACL_PERM_EXECUTE
: 0;
720 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
721 g_ace
->ace_type
, g_ace
->ace_who
, g_ace
->ace_perm
));
727 static int gpfsacl_sys_acl_set_file(vfs_handle_struct
*handle
,
732 struct gpfs_acl
*gpfs_acl
;
735 gpfs_acl
= smb2gpfs_acl(theacl
, type
);
736 if (gpfs_acl
== NULL
) {
740 result
= smbd_gpfs_putacl((char *)name
, GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gpfs_acl
);
746 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
750 return gpfsacl_sys_acl_set_file(handle
, fsp
->fsp_name
->base_name
,
751 SMB_ACL_TYPE_ACCESS
, theacl
);
754 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
762 * Assumed: mode bits are shiftable and standard
763 * Output: the new aceMask field for an smb nfs4 ace
765 static uint32
gpfsacl_mask_filter(uint32 aceType
, uint32 aceMask
, uint32 rwx
)
767 const uint32 posix_nfs4map
[3] = {
768 SMB_ACE4_EXECUTE
, /* execute */
769 SMB_ACE4_WRITE_DATA
| SMB_ACE4_APPEND_DATA
, /* write; GPFS specific */
770 SMB_ACE4_READ_DATA
/* read */
773 uint32_t posix_mask
= 0x01;
778 nfs4_bits
= posix_nfs4map
[i
];
779 posix_bit
= rwx
& posix_mask
;
781 if (aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
) {
783 aceMask
|= nfs4_bits
;
785 aceMask
&= ~nfs4_bits
;
787 /* add deny bits when suitable */
789 aceMask
|= nfs4_bits
;
791 aceMask
&= ~nfs4_bits
;
792 } /* other ace types are unexpected */
800 static int gpfsacl_emu_chmod(const char *path
, mode_t mode
)
802 SMB4ACL_T
*pacl
= NULL
;
804 bool haveAllowEntry
[SMB_ACE4_WHO_EVERYONE
+ 1] = {False
, False
, False
, False
};
806 files_struct fake_fsp
; /* TODO: rationalize parametrization */
810 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path
, mode
));
812 result
= gpfs_get_nfs4_acl(path
, &pacl
);
816 if (mode
& ~(S_IRWXU
| S_IRWXG
| S_IRWXO
)) {
817 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode
, path
));
820 for (smbace
=smb_first_ace4(pacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
821 SMB_ACE4PROP_T
*ace
= smb_get_ace4(smbace
);
822 uint32_t specid
= ace
->who
.special_id
;
824 if (ace
->flags
&SMB_ACE4_ID_SPECIAL
&&
825 ace
->aceType
<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE
&&
826 specid
<= SMB_ACE4_WHO_EVERYONE
) {
830 if (ace
->aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
)
831 haveAllowEntry
[specid
] = True
;
833 /* mode >> 6 for @owner, mode >> 3 for @group,
834 * mode >> 0 for @everyone */
835 newMask
= gpfsacl_mask_filter(ace
->aceType
, ace
->aceMask
,
836 mode
>> ((SMB_ACE4_WHO_EVERYONE
- specid
) * 3));
837 if (ace
->aceMask
!=newMask
) {
838 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
839 path
, ace
->aceMask
, newMask
, specid
));
841 ace
->aceMask
= newMask
;
845 /* make sure we have at least ALLOW entries
846 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
849 for(i
= SMB_ACE4_WHO_OWNER
; i
<=SMB_ACE4_WHO_EVERYONE
; i
++) {
852 if (haveAllowEntry
[i
]==True
)
856 ace
.aceType
= SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
;
857 ace
.flags
|= SMB_ACE4_ID_SPECIAL
;
858 ace
.who
.special_id
= i
;
860 if (i
==SMB_ACE4_WHO_GROUP
) /* not sure it's necessary... */
861 ace
.aceFlags
|= SMB_ACE4_IDENTIFIER_GROUP
;
863 ace
.aceMask
= gpfsacl_mask_filter(ace
.aceType
, ace
.aceMask
,
864 mode
>> ((SMB_ACE4_WHO_EVERYONE
- i
) * 3));
866 /* don't add unnecessary aces */
870 /* we add it to the END - as windows expects allow aces */
871 smb_add_ace4(pacl
, &ace
);
872 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
873 path
, mode
, i
, ace
.aceMask
));
876 /* don't add complementary DENY ACEs here */
877 ZERO_STRUCT(fake_fsp
);
878 status
= create_synthetic_smb_fname(talloc_tos(), path
, NULL
, NULL
,
880 if (!NT_STATUS_IS_OK(status
)) {
881 errno
= map_errno_from_nt_status(status
);
885 if (gpfsacl_process_smbacl(&fake_fsp
, pacl
) == False
) {
886 TALLOC_FREE(fake_fsp
.fsp_name
);
890 TALLOC_FREE(fake_fsp
.fsp_name
);
891 return 0; /* ok for [f]chmod */
894 static int vfs_gpfs_chmod(vfs_handle_struct
*handle
, const char *path
, mode_t mode
)
896 struct smb_filename
*smb_fname_cpath
;
900 status
= create_synthetic_smb_fname(
901 talloc_tos(), path
, NULL
, NULL
, &smb_fname_cpath
);
903 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_cpath
) != 0) {
907 /* avoid chmod() if possible, to preserve acls */
908 if ((smb_fname_cpath
->st
.st_ex_mode
& ~S_IFMT
) == mode
) {
912 rc
= gpfsacl_emu_chmod(path
, mode
);
914 return SMB_VFS_NEXT_CHMOD(handle
, path
, mode
);
918 static int vfs_gpfs_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
923 if (SMB_VFS_NEXT_FSTAT(handle
, fsp
, &st
) != 0) {
927 /* avoid chmod() if possible, to preserve acls */
928 if ((st
.st_ex_mode
& ~S_IFMT
) == mode
) {
932 rc
= gpfsacl_emu_chmod(fsp
->fsp_name
->base_name
, mode
);
934 return SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
938 static int gpfs_set_xattr(struct vfs_handle_struct
*handle
, const char *path
,
939 const char *name
, const void *value
, size_t size
, int flags
){
940 struct xattr_DOSATTRIB dosattrib
;
941 enum ndr_err_code ndr_err
;
943 const char *attrstr
= value
;
944 unsigned int dosmode
=0;
945 struct gpfs_winattr attrs
;
948 DEBUG(10, ("gpfs_set_xattr: %s \n",path
));
950 /* Only handle DOS Attributes */
951 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
952 DEBUG(1, ("gpfs_set_xattr:name is %s\n",name
));
953 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
956 blob
.data
= (uint8_t *)attrstr
;
959 ndr_err
= ndr_pull_struct_blob(&blob
, talloc_tos(), &dosattrib
,
960 (ndr_pull_flags_fn_t
)ndr_pull_xattr_DOSATTRIB
);
962 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
963 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
964 "from EA on file %s: Error = %s\n",
965 path
, ndr_errstr(ndr_err
)));
969 if (dosattrib
.version
!= 3) {
970 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
971 "%d\n", (int)dosattrib
.version
));
974 if (!(dosattrib
.info
.info3
.valid_flags
& XATTR_DOSINFO_ATTRIB
)) {
975 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
976 "valid, ignoring\n"));
980 dosmode
= dosattrib
.info
.info3
.attrib
;
983 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
984 if (dosmode
& FILE_ATTRIBUTE_ARCHIVE
){
985 attrs
.winAttrs
|= GPFS_WINATTR_ARCHIVE
;
987 if (dosmode
& FILE_ATTRIBUTE_HIDDEN
){
988 attrs
.winAttrs
|= GPFS_WINATTR_HIDDEN
;
990 if (dosmode
& FILE_ATTRIBUTE_SYSTEM
){
991 attrs
.winAttrs
|= GPFS_WINATTR_SYSTEM
;
993 if (dosmode
& FILE_ATTRIBUTE_READONLY
){
994 attrs
.winAttrs
|= GPFS_WINATTR_READONLY
;
996 if (dosmode
& FILE_ATTRIBUTE_SPARSE
) {
997 attrs
.winAttrs
|= GPFS_WINATTR_SPARSE_FILE
;
1001 ret
= set_gpfs_winattrs(CONST_DISCARD(char *, path
),
1002 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1004 if (errno
== ENOSYS
) {
1005 return SMB_VFS_NEXT_SETXATTR(handle
, path
, name
, value
,
1009 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret
));
1013 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs
.winAttrs
));
1017 static ssize_t
gpfs_get_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1018 const char *name
, void *value
, size_t size
){
1019 char *attrstr
= value
;
1020 unsigned int dosmode
= 0;
1021 struct gpfs_winattr attrs
;
1024 DEBUG(10, ("gpfs_get_xattr: %s \n",path
));
1026 /* Only handle DOS Attributes */
1027 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1028 DEBUG(1, ("gpfs_get_xattr:name is %s\n",name
));
1029 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1032 ret
= get_gpfs_winattrs(CONST_DISCARD(char *, path
), &attrs
);
1034 if (errno
== ENOSYS
) {
1035 return SMB_VFS_NEXT_GETXATTR(handle
, path
, name
, value
,
1039 DEBUG(1, ("gpfs_get_xattr: Get GPFS attributes failed: "
1040 "%d (%s)\n", ret
, strerror(errno
)));
1044 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs
.winAttrs
));
1046 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1047 if (attrs
.winAttrs
& GPFS_WINATTR_ARCHIVE
){
1048 dosmode
|= FILE_ATTRIBUTE_ARCHIVE
;
1050 if (attrs
.winAttrs
& GPFS_WINATTR_HIDDEN
){
1051 dosmode
|= FILE_ATTRIBUTE_HIDDEN
;
1053 if (attrs
.winAttrs
& GPFS_WINATTR_SYSTEM
){
1054 dosmode
|= FILE_ATTRIBUTE_SYSTEM
;
1056 if (attrs
.winAttrs
& GPFS_WINATTR_READONLY
){
1057 dosmode
|= FILE_ATTRIBUTE_READONLY
;
1059 if (attrs
.winAttrs
& GPFS_WINATTR_SPARSE_FILE
) {
1060 dosmode
|= FILE_ATTRIBUTE_SPARSE
;
1063 snprintf(attrstr
, size
, "0x%2.2x",
1064 (unsigned int)(dosmode
& SAMBA_ATTRIBUTES_MASK
));
1065 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr
));
1069 static int vfs_gpfs_stat(struct vfs_handle_struct
*handle
,
1070 struct smb_filename
*smb_fname
)
1072 struct gpfs_winattr attrs
;
1077 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
1081 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &fname
);
1082 if (!NT_STATUS_IS_OK(status
)) {
1083 errno
= map_errno_from_nt_status(status
);
1086 ret
= get_gpfs_winattrs(CONST_DISCARD(char *, fname
), &attrs
);
1089 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1090 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1091 smb_fname
->st
.vfs_private
= attrs
.winAttrs
;
1096 static int vfs_gpfs_fstat(struct vfs_handle_struct
*handle
,
1097 struct files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
1099 struct gpfs_winattr attrs
;
1102 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
1106 if ((fsp
->fh
== NULL
) || (fsp
->fh
->fd
== -1)) {
1109 ret
= smbd_fget_gpfs_winattrs(fsp
->fh
->fd
, &attrs
);
1111 sbuf
->st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1112 sbuf
->st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1117 static int vfs_gpfs_lstat(struct vfs_handle_struct
*handle
,
1118 struct smb_filename
*smb_fname
)
1120 struct gpfs_winattr attrs
;
1125 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
1129 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1130 if (!NT_STATUS_IS_OK(status
)) {
1131 errno
= map_errno_from_nt_status(status
);
1134 ret
= get_gpfs_winattrs(CONST_DISCARD(char *, path
), &attrs
);
1137 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1138 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1139 smb_fname
->st
.vfs_private
= attrs
.winAttrs
;
1144 static int vfs_gpfs_ntimes(struct vfs_handle_struct
*handle
,
1145 const struct smb_filename
*smb_fname
,
1146 struct smb_file_time
*ft
)
1149 struct gpfs_winattr attrs
;
1154 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1156 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed\n"));
1160 if(null_timespec(ft
->create_time
)){
1161 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1165 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1166 if (!NT_STATUS_IS_OK(status
)) {
1167 errno
= map_errno_from_nt_status(status
);
1172 attrs
.creationTime
.tv_sec
= ft
->create_time
.tv_sec
;
1173 attrs
.creationTime
.tv_nsec
= ft
->create_time
.tv_nsec
;
1175 ret
= set_gpfs_winattrs(CONST_DISCARD(char *, path
),
1176 GPFS_WINATTR_SET_CREATION_TIME
, &attrs
);
1177 if(ret
== -1 && errno
!= ENOSYS
){
1178 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret
));
1185 static int vfs_gpfs_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1190 result
= smbd_gpfs_ftruncate(fsp
->fh
->fd
, len
);
1191 if ((result
== -1) && (errno
== ENOSYS
)) {
1192 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1197 static bool vfs_gpfs_is_offline(struct vfs_handle_struct
*handle
,
1198 const struct smb_filename
*fname
,
1199 SMB_STRUCT_STAT
*sbuf
)
1201 struct gpfs_winattr attrs
;
1205 status
= get_full_smb_filename(talloc_tos(), fname
, &path
);
1206 if (!NT_STATUS_IS_OK(status
)) {
1207 errno
= map_errno_from_nt_status(status
);
1211 if (VALID_STAT(*sbuf
)) {
1212 attrs
.winAttrs
= sbuf
->vfs_private
;
1215 ret
= get_gpfs_winattrs(path
, &attrs
);
1222 if ((attrs
.winAttrs
& GPFS_WINATTR_OFFLINE
) != 0) {
1223 DEBUG(10, ("%s is offline\n", path
));
1227 DEBUG(10, ("%s is online\n", path
));
1229 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1232 static bool vfs_gpfs_aio_force(struct vfs_handle_struct
*handle
,
1233 struct files_struct
*fsp
)
1235 return vfs_gpfs_is_offline(handle
, fsp
->fsp_name
, &fsp
->fsp_name
->st
);
1238 int vfs_gpfs_connect(struct vfs_handle_struct
*handle
, const char *service
,
1241 struct gpfs_config_data
*config
;
1243 smbd_gpfs_lib_init();
1245 int ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1251 config
= talloc_zero(handle
->conn
, struct gpfs_config_data
);
1253 SMB_VFS_NEXT_DISCONNECT(handle
);
1254 DEBUG(0, ("talloc_zero() failed\n")); return -1;
1257 config
->sharemodes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1258 "sharemodes", true);
1260 config
->leases
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1263 config
->hsm
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1266 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
1267 NULL
, struct gpfs_config_data
,
1273 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct
*handle
,
1274 enum timestamp_set_resolution
*p_ts_res
)
1276 struct gpfs_config_data
*config
;
1279 next
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
1281 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1282 struct gpfs_config_data
,
1286 next
|= FILE_SUPPORTS_REMOTE_STORAGE
;
1292 static struct vfs_fn_pointers vfs_gpfs_fns
= {
1293 .connect_fn
= vfs_gpfs_connect
,
1294 .fs_capabilities
= vfs_gpfs_capabilities
,
1295 .kernel_flock
= vfs_gpfs_kernel_flock
,
1296 .linux_setlease
= vfs_gpfs_setlease
,
1297 .get_real_filename
= vfs_gpfs_get_real_filename
,
1298 .fget_nt_acl
= gpfsacl_fget_nt_acl
,
1299 .get_nt_acl
= gpfsacl_get_nt_acl
,
1300 .fset_nt_acl
= gpfsacl_fset_nt_acl
,
1301 .sys_acl_get_file
= gpfsacl_sys_acl_get_file
,
1302 .sys_acl_get_fd
= gpfsacl_sys_acl_get_fd
,
1303 .sys_acl_set_file
= gpfsacl_sys_acl_set_file
,
1304 .sys_acl_set_fd
= gpfsacl_sys_acl_set_fd
,
1305 .sys_acl_delete_def_file
= gpfsacl_sys_acl_delete_def_file
,
1306 .chmod
= vfs_gpfs_chmod
,
1307 .fchmod
= vfs_gpfs_fchmod
,
1308 .close_fn
= vfs_gpfs_close
,
1309 .setxattr
= gpfs_set_xattr
,
1310 .getxattr
= gpfs_get_xattr
,
1311 .stat
= vfs_gpfs_stat
,
1312 .fstat
= vfs_gpfs_fstat
,
1313 .lstat
= vfs_gpfs_lstat
,
1314 .ntimes
= vfs_gpfs_ntimes
,
1315 .is_offline
= vfs_gpfs_is_offline
,
1316 .aio_force
= vfs_gpfs_aio_force
,
1317 .ftruncate
= vfs_gpfs_ftruncate
1320 NTSTATUS
vfs_gpfs_init(void);
1321 NTSTATUS
vfs_gpfs_init(void)
1325 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "gpfs",