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 2 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, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #define DBGC_CLASS DBGC_VFS
33 #include "nfs4_acls.h"
36 static int vfs_gpfs_kernel_flock(vfs_handle_struct
*handle
, files_struct
*fsp
,
37 int fd
, uint32 share_mode
)
40 START_PROFILE(syscall_kernel_flock
);
42 kernel_flock(fsp
->fh
->fd
, share_mode
);
44 if (!set_gpfs_sharemode(fsp
, fsp
->access_mask
, fsp
->share_access
)) {
50 END_PROFILE(syscall_kernel_flock
);
55 static void gpfs_dumpacl(int level
, struct gpfs_acl
*gacl
)
60 DEBUG(0, ("gpfs acl is NULL\n"));
64 DEBUG(level
, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n",
65 gacl
->acl_nace
, gacl
->acl_type
, gacl
->acl_version
, gacl
->acl_level
, gacl
->acl_len
));
66 for(i
=0; i
<gacl
->acl_nace
; i
++)
68 struct gpfs_ace_v4
*gace
= gacl
->ace_v4
+ i
;
69 DEBUG(level
, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n",
70 i
, gace
->aceType
, gace
->aceFlags
, gace
->aceMask
,
71 gace
->aceIFlags
, gace
->aceWho
));
75 static struct gpfs_acl
*gpfs_getacl_alloc(const char *fname
, gpfs_aclType_t type
)
80 TALLOC_CTX
*mem_ctx
= main_loop_talloc_get();
82 acl
= (struct gpfs_acl
*)talloc_size(mem_ctx
, len
);
93 ret
= smbd_gpfs_getacl((char *)fname
, GPFS_GETACL_STRUCT
| GPFS_ACL_SAMBA
, acl
);
94 if ((ret
!= 0) && (errno
== ENOSPC
)) {
95 struct gpfs_acl
*new_acl
= (struct gpfs_acl
*)talloc_size(
96 mem_ctx
, acl
->acl_len
+ sizeof(struct gpfs_acl
));
97 if (new_acl
== NULL
) {
102 new_acl
->acl_len
= acl
->acl_len
;
103 new_acl
->acl_level
= acl
->acl_level
;
104 new_acl
->acl_version
= acl
->acl_version
;
105 new_acl
->acl_type
= acl
->acl_type
;
108 ret
= smbd_gpfs_getacl((char *)fname
, GPFS_GETACL_STRUCT
| GPFS_ACL_SAMBA
, acl
);
112 DEBUG(8, ("smbd_gpfs_getacl failed with %s\n",strerror(errno
)));
119 static BOOL
gpfs_get_nfs4_acl(struct files_struct
*fsp
, SMB4ACL_T
**ppacl
, BOOL
*pretryPosix
)
123 struct gpfs_acl
*gacl
= NULL
;
125 mem_ctx
= main_loop_talloc_get();
127 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fsp
->fsp_name
));
129 /* First get the real acl length */
130 gacl
= gpfs_getacl_alloc(fsp
->fsp_name
, GPFS_ACL_TYPE_NFS4
);
132 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
133 fsp
->fsp_name
, strerror(errno
)));
137 if (gacl
->acl_type
!= GPFS_ACL_TYPE_NFS4
) {
138 DEBUG(10, ("Got non-nfsv4 acl\n"));
143 *ppacl
= smb_create_smb4acl();
145 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
146 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
149 for (i
=0; i
<gacl
->acl_nace
; i
++) {
150 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[i
];
151 SMB_ACE4PROP_T smbace
;
152 memset(&smbace
, 0, sizeof(SMB4ACE_T
));
154 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
155 "who: %d\n", gace
->aceType
, gace
->aceIFlags
,
156 gace
->aceFlags
, gace
->aceMask
, gace
->aceWho
));
158 if (gace
->aceIFlags
& ACE4_IFLAG_SPECIAL_ID
) {
159 smbace
.flags
|= SMB_ACE4_ID_SPECIAL
;
160 switch (gace
->aceWho
) {
161 case ACE4_SPECIAL_OWNER
:
162 smbace
.who
.special_id
= SMB_ACE4_WHO_OWNER
;
164 case ACE4_SPECIAL_GROUP
:
165 smbace
.who
.special_id
= SMB_ACE4_WHO_GROUP
;
167 case ACE4_SPECIAL_EVERYONE
:
168 smbace
.who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
171 DEBUG(8, ("invalid special gpfs id %d "
172 "ignored\n", gace
->aceWho
));
173 continue; /* don't add it */
176 if (gace
->aceFlags
& ACE4_FLAG_GROUP_ID
)
177 smbace
.who
.gid
= gace
->aceWho
;
179 smbace
.who
.uid
= gace
->aceWho
;
182 smbace
.aceType
= gace
->aceType
;
183 smbace
.aceFlags
= gace
->aceFlags
;
184 smbace
.aceMask
= gace
->aceMask
;
185 smbace
.flags
= (gace
->aceIFlags
&ACE4_IFLAG_SPECIAL_ID
) ? SMB_ACE4_ID_SPECIAL
: 0;
187 smb_add_ace4(*ppacl
, &smbace
);
193 static size_t gpfsacl_get_nt_acl_common(files_struct
*fsp
,
194 uint32 security_info
, SEC_DESC
**ppdesc
)
196 SMB4ACL_T
*pacl
= NULL
;
198 BOOL retryPosix
= False
;
201 result
= gpfs_get_nfs4_acl(fsp
, &pacl
, &retryPosix
);
204 DEBUG(10, ("retrying with posix acl...\n"));
205 return get_nt_acl(fsp
, security_info
, ppdesc
);
210 return smb_get_nt_acl_nfs4(fsp
, security_info
, ppdesc
, pacl
);
213 size_t gpfsacl_fget_nt_acl(vfs_handle_struct
*handle
,
214 files_struct
*fsp
, int fd
, uint32 security_info
,
217 return gpfsacl_get_nt_acl_common(fsp
, security_info
, ppdesc
);
220 size_t gpfsacl_get_nt_acl(vfs_handle_struct
*handle
,
221 files_struct
*fsp
, const char *name
,
222 uint32 security_info
, SEC_DESC
**ppdesc
)
224 return gpfsacl_get_nt_acl_common(fsp
, security_info
, ppdesc
);
227 static BOOL
gpfsacl_process_smbacl(files_struct
*fsp
, SMB4ACL_T
*smbacl
)
230 gpfs_aclLen_t gacl_len
;
232 struct gpfs_acl
*gacl
;
233 TALLOC_CTX
*mem_ctx
= main_loop_talloc_get();
235 gacl_len
= sizeof(struct gpfs_acl
) +
236 (smb_get_naces(smbacl
)-1)*sizeof(gpfs_ace_v4_t
);
238 gacl
= talloc_size(mem_ctx
, gacl_len
);
240 DEBUG(0, ("talloc failed\n"));
245 gacl
->acl_len
= gacl_len
;
247 gacl
->acl_version
= GPFS_ACL_VERSION_NFS4
;
248 gacl
->acl_type
= GPFS_ACL_TYPE_NFS4
;
249 gacl
->acl_nace
= 0; /* change later... */
251 for (smbace
=smb_first_ace4(smbacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
252 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[gacl
->acl_nace
];
253 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
255 gace
->aceType
= aceprop
->aceType
;
256 gace
->aceFlags
= aceprop
->aceFlags
;
257 gace
->aceMask
= aceprop
->aceMask
;
258 gace
->aceIFlags
= (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
) ? ACE4_IFLAG_SPECIAL_ID
: 0;
260 if (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
)
262 switch(aceprop
->who
.special_id
)
264 case SMB_ACE4_WHO_EVERYONE
:
265 gace
->aceWho
= ACE4_SPECIAL_EVERYONE
;
267 case SMB_ACE4_WHO_OWNER
:
268 gace
->aceWho
= ACE4_SPECIAL_OWNER
;
270 case SMB_ACE4_WHO_GROUP
:
271 gace
->aceWho
= ACE4_SPECIAL_GROUP
;
274 DEBUG(8, ("unsupported special_id %d\n", aceprop
->who
.special_id
));
275 continue; /* don't add it !!! */
278 /* just only for the type safety... */
279 if (aceprop
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)
280 gace
->aceWho
= aceprop
->who
.gid
;
282 gace
->aceWho
= aceprop
->who
.uid
;
288 ret
= smbd_gpfs_putacl(fsp
->fsp_name
, GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gacl
);
290 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno
)));
291 gpfs_dumpacl(8, gacl
);
295 DEBUG(10, ("gpfs_putacl succeeded\n"));
299 static BOOL
gpfsacl_set_nt_acl_internal(files_struct
*fsp
, uint32 security_info_sent
, SEC_DESC
*psd
)
301 struct gpfs_acl
*acl
;
304 acl
= gpfs_getacl_alloc(fsp
->fsp_name
, GPFS_ACL_TYPE_ACCESS
);
308 if (acl
->acl_version
&GPFS_ACL_VERSION_NFS4
)
310 result
= smb_set_nt_acl_nfs4(
311 fsp
, security_info_sent
, psd
,
312 gpfsacl_process_smbacl
);
313 } else { /* assume POSIX ACL - by default... */
314 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
320 static BOOL
gpfsacl_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, int fd
, uint32 security_info_sent
, SEC_DESC
*psd
)
322 return gpfsacl_set_nt_acl_internal(fsp
, security_info_sent
, psd
);
325 static BOOL
gpfsacl_set_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, char *name
, uint32 security_info_sent
, SEC_DESC
*psd
)
327 return gpfsacl_set_nt_acl_internal(fsp
, security_info_sent
, psd
);
330 static SMB_ACL_T
gpfs2smb_acl(const struct gpfs_acl
*pacl
)
335 result
= sys_acl_init(pacl
->acl_nace
);
336 if (result
== NULL
) {
341 result
->count
= pacl
->acl_nace
;
343 for (i
=0; i
<pacl
->acl_nace
; i
++) {
344 struct smb_acl_entry
*ace
= &result
->acl
[i
];
345 const struct gpfs_ace_v1
*g_ace
= &pacl
->ace_v1
[i
];
347 DEBUG(10, ("Converting type %d id %lu perm %x\n",
348 (int)g_ace
->ace_type
, (unsigned long)g_ace
->ace_who
,
349 (int)g_ace
->ace_perm
));
351 switch (g_ace
->ace_type
) {
353 ace
->a_type
= SMB_ACL_USER
;
354 ace
->uid
= (uid_t
)g_ace
->ace_who
;
356 case GPFS_ACL_USER_OBJ
:
357 ace
->a_type
= SMB_ACL_USER_OBJ
;
360 ace
->a_type
= SMB_ACL_GROUP
;
361 ace
->gid
= (gid_t
)g_ace
->ace_who
;
363 case GPFS_ACL_GROUP_OBJ
:
364 ace
->a_type
= SMB_ACL_GROUP_OBJ
;
367 ace
->a_type
= SMB_ACL_OTHER
;
370 ace
->a_type
= SMB_ACL_MASK
;
373 DEBUG(10, ("Got invalid ace_type: %d\n",
381 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_READ
) ?
383 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_WRITE
) ?
385 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_EXECUTE
) ?
388 DEBUGADD(10, ("Converted to %d perm %x\n",
389 ace
->a_type
, ace
->a_perm
));
395 static SMB_ACL_T
gpfsacl_get_posix_acl(const char *path
, gpfs_aclType_t type
)
397 struct gpfs_acl
*pacl
;
398 SMB_ACL_T result
= NULL
;
400 pacl
= gpfs_getacl_alloc(path
, type
);
403 DEBUG(10, ("gpfs_getacl failed for %s with %s\n",
404 path
, strerror(errno
)));
411 if (pacl
->acl_version
!= GPFS_ACL_VERSION_POSIX
) {
412 DEBUG(10, ("Got acl version %d, expected %d\n",
413 pacl
->acl_version
, GPFS_ACL_VERSION_POSIX
));
418 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
419 pacl
->acl_len
, pacl
->acl_level
, pacl
->acl_version
,
422 result
= gpfs2smb_acl(pacl
);
423 if (result
== NULL
) {
435 SMB_ACL_T
gpfsacl_sys_acl_get_file(vfs_handle_struct
*handle
,
440 gpfs_aclType_t gpfs_type
;
443 case SMB_ACL_TYPE_ACCESS
:
444 gpfs_type
= GPFS_ACL_TYPE_ACCESS
;
446 case SMB_ACL_TYPE_DEFAULT
:
447 gpfs_type
= GPFS_ACL_TYPE_DEFAULT
;
450 DEBUG(0, ("Got invalid type: %d\n", type
));
451 smb_panic("exiting");
454 return gpfsacl_get_posix_acl(path_p
, gpfs_type
);
457 SMB_ACL_T
gpfsacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
461 return gpfsacl_get_posix_acl(fsp
->fsp_name
, GPFS_ACL_TYPE_ACCESS
);
464 static struct gpfs_acl
*smb2gpfs_acl(const SMB_ACL_T pacl
,
468 struct gpfs_acl
*result
;
472 gpfs_ace_v1_t ace_v1
[1]; /* when GPFS_ACL_VERSION_POSIX */
473 gpfs_ace_v4_t ace_v4
[1]; /* when GPFS_ACL_VERSION_NFS4 */
476 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl
->count
));
478 len
= sizeof(struct gpfs_acl
) - sizeof(union gpfs_ace_union
) +
479 (pacl
->count
)*sizeof(gpfs_ace_v1_t
);
481 result
= SMB_MALLOC(len
);
482 if (result
== NULL
) {
487 result
->acl_len
= len
;
488 result
->acl_level
= 0;
489 result
->acl_version
= GPFS_ACL_VERSION_POSIX
;
490 result
->acl_type
= (type
== SMB_ACL_TYPE_DEFAULT
) ?
491 GPFS_ACL_TYPE_DEFAULT
: GPFS_ACL_TYPE_ACCESS
;
492 result
->acl_nace
= pacl
->count
;
494 for (i
=0; i
<pacl
->count
; i
++) {
495 const struct smb_acl_entry
*ace
= &pacl
->acl
[i
];
496 struct gpfs_ace_v1
*g_ace
= &result
->ace_v1
[i
];
498 DEBUG(10, ("Converting type %d perm %x\n",
499 (int)ace
->a_type
, (int)ace
->a_perm
));
503 switch(ace
->a_type
) {
505 g_ace
->ace_type
= GPFS_ACL_USER
;
506 g_ace
->ace_who
= (gpfs_uid_t
)ace
->uid
;
508 case SMB_ACL_USER_OBJ
:
509 g_ace
->ace_type
= GPFS_ACL_USER_OBJ
;
510 g_ace
->ace_perm
|= ACL_PERM_CONTROL
;
514 g_ace
->ace_type
= GPFS_ACL_GROUP
;
515 g_ace
->ace_who
= (gpfs_uid_t
)ace
->gid
;
517 case SMB_ACL_GROUP_OBJ
:
518 g_ace
->ace_type
= GPFS_ACL_GROUP_OBJ
;
522 g_ace
->ace_type
= GPFS_ACL_MASK
;
523 g_ace
->ace_perm
= 0x8f;
527 g_ace
->ace_type
= GPFS_ACL_OTHER
;
531 DEBUG(10, ("Got invalid ace_type: %d\n", ace
->a_type
));
537 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_READ
) ?
539 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_WRITE
) ?
541 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_EXECUTE
) ?
542 ACL_PERM_EXECUTE
: 0;
544 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
545 g_ace
->ace_type
, g_ace
->ace_who
, g_ace
->ace_perm
));
551 int gpfsacl_sys_acl_set_file(vfs_handle_struct
*handle
,
557 struct gpfs_acl
*gpfs_acl
;
560 gpfs_acl
= smb2gpfs_acl(theacl
, type
);
561 if (gpfs_acl
== NULL
) {
565 result
= smbd_gpfs_putacl((char *)name
, GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gpfs_acl
);
571 int gpfsacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
573 int fd
, SMB_ACL_T theacl
)
579 int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
587 /* VFS operations structure */
589 static vfs_op_tuple gpfs_op_tuples
[] = {
591 {SMB_VFS_OP(vfs_gpfs_kernel_flock
),
592 SMB_VFS_OP_KERNEL_FLOCK
,
593 SMB_VFS_LAYER_OPAQUE
},
595 {SMB_VFS_OP(gpfsacl_fget_nt_acl
),
596 SMB_VFS_OP_FGET_NT_ACL
,
597 SMB_VFS_LAYER_TRANSPARENT
},
599 {SMB_VFS_OP(gpfsacl_get_nt_acl
),
600 SMB_VFS_OP_GET_NT_ACL
,
601 SMB_VFS_LAYER_TRANSPARENT
},
603 {SMB_VFS_OP(gpfsacl_fset_nt_acl
),
604 SMB_VFS_OP_FSET_NT_ACL
,
605 SMB_VFS_LAYER_TRANSPARENT
},
607 {SMB_VFS_OP(gpfsacl_set_nt_acl
),
608 SMB_VFS_OP_SET_NT_ACL
,
609 SMB_VFS_LAYER_TRANSPARENT
},
611 {SMB_VFS_OP(gpfsacl_sys_acl_get_file
),
612 SMB_VFS_OP_SYS_ACL_GET_FILE
,
613 SMB_VFS_LAYER_TRANSPARENT
},
615 {SMB_VFS_OP(gpfsacl_sys_acl_get_fd
),
616 SMB_VFS_OP_SYS_ACL_GET_FD
,
617 SMB_VFS_LAYER_TRANSPARENT
},
619 {SMB_VFS_OP(gpfsacl_sys_acl_set_file
),
620 SMB_VFS_OP_SYS_ACL_SET_FILE
,
621 SMB_VFS_LAYER_TRANSPARENT
},
623 {SMB_VFS_OP(gpfsacl_sys_acl_set_fd
),
624 SMB_VFS_OP_SYS_ACL_SET_FD
,
625 SMB_VFS_LAYER_TRANSPARENT
},
627 {SMB_VFS_OP(gpfsacl_sys_acl_delete_def_file
),
628 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE
,
629 SMB_VFS_LAYER_TRANSPARENT
},
638 NTSTATUS
vfs_gpfs_init(void);
639 NTSTATUS
vfs_gpfs_init(void)
643 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "gpfs",