2 * Convert JFS2 NFS4/AIXC acls to NT acls and vice versa.
4 * Copyright (C) Volker Lendecke, 2006
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "nfs4_acls.h"
24 #define DBGC_CLASS DBGC_VFS
26 #define AIXACL2_MODULE_NAME "aixacl2"
28 extern struct current_user current_user
;
29 extern int try_chown(connection_struct
*conn
, const char *fname
, uid_t uid
, gid_t gid
);
30 extern bool unpack_nt_owners(int snum
, uid_t
*puser
, gid_t
*pgrp
,
31 uint32 security_info_sent
, SEC_DESC
*psd
);
33 extern SMB_ACL_T
aixacl_to_smbacl( struct acl
*file_acl
);
34 extern struct acl
*aixacl_smb_to_aixacl(SMB_ACL_TYPE_T acltype
, SMB_ACL_T theacl
);
36 typedef union aixjfs2_acl_t
{
37 nfs4_acl_int_t jfs2_acl
[1];
38 aixc_acl_t aixc_acl
[1];
41 static int32_t aixacl2_getlen(AIXJFS2_ACL_T
*acl
, acl_type_t
*type
)
45 if(type
->u64
== ACL_NFS4
) {
46 len
= acl
->jfs2_acl
[0].aclLength
;
49 if(type
->u64
== ACL_AIXC
) {
50 len
= acl
->aixc_acl
[0].acl_len
;
52 DEBUG(0,("aixacl2_getlen:unknown type:%d\n",type
->u64
));
56 DEBUG(10,("aixacl2_getlen:%d\n",len
));
60 static AIXJFS2_ACL_T
*aixjfs2_getacl_alloc(const char *fname
, acl_type_t
*type
)
69 mem_ctx
= talloc_tos();
70 acl
= (AIXJFS2_ACL_T
*)TALLOC_SIZE(mem_ctx
, len
);
76 if(type
->u64
== ACL_ANY
) {
77 ctl_flag
= ctl_flag
| GET_ACLINFO_ONLY
;
80 ret
= aclx_get((char *)fname
, ctl_flag
, type
, acl
, &len
, &mode
);
81 if ((ret
!= 0) && (errno
== ENOSPC
)) {
82 len
= aixacl2_getlen(acl
, type
) + sizeof(AIXJFS2_ACL_T
);
83 DEBUG(10,("aixjfs2_getacl_alloc - acl_len:%d\n",len
));
85 acl
= (AIXJFS2_ACL_T
*)TALLOC_SIZE(mem_ctx
, len
);
91 ret
= aclx_get((char *)fname
, ctl_flag
, type
, acl
, &len
, &mode
);
94 DEBUG(8, ("aclx_get failed with %s\n", strerror(errno
)));
101 static bool aixjfs2_get_nfs4_acl(const char *name
,
102 SMB4ACL_T
**ppacl
, bool *pretryPosix
)
106 AIXJFS2_ACL_T
*pacl
= NULL
;
107 nfs4_acl_int_t
*jfs2_acl
= NULL
;
108 nfs4_ace_int_t
*jfs2_ace
= NULL
;
111 DEBUG(10,("jfs2 get_nt_acl invoked for %s\n", name
));
113 memset(&type
, 0, sizeof(acl_type_t
));
116 pacl
= aixjfs2_getacl_alloc(name
, &type
);
118 DEBUG(9, ("aixjfs2_getacl_alloc failed for %s with %s\n",
119 name
, strerror(errno
)));
125 jfs2_acl
= &pacl
->jfs2_acl
[0];
126 DEBUG(10, ("len: %d, version: %d, nace: %d, type: 0x%x\n",
127 jfs2_acl
->aclLength
, jfs2_acl
->aclVersion
, jfs2_acl
->aclEntryN
, type
.u64
));
129 *ppacl
= smb_create_smb4acl();
133 jfs2_ace
= &jfs2_acl
->aclEntry
[0];
134 for (i
=0; i
<jfs2_acl
->aclEntryN
; i
++) {
135 SMB_ACE4PROP_T aceprop
;
137 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
138 "who: %d, aclLen: %d\n", jfs2_ace
->aceType
, jfs2_ace
->flags
,
139 jfs2_ace
->aceFlags
, jfs2_ace
->aceMask
, jfs2_ace
->aceWho
.id
, jfs2_ace
->entryLen
));
141 aceprop
.aceType
= jfs2_ace
->aceType
;
142 aceprop
.aceFlags
= jfs2_ace
->aceFlags
;
143 aceprop
.aceMask
= jfs2_ace
->aceMask
;
144 aceprop
.flags
= (jfs2_ace
->flags
&ACE4_ID_SPECIAL
) ? SMB_ACE4_ID_SPECIAL
: 0;
146 /* don't care it's real content is only 16 or 32 bit */
147 aceprop
.who
.id
= jfs2_ace
->aceWho
.id
;
149 if (smb_add_ace4(*ppacl
, &aceprop
)==NULL
)
152 /* iterate to the next jfs2 ace */
153 jfs2_ace
= (nfs4_ace_int_t
*)(((char *)jfs2_ace
) + jfs2_ace
->entryLen
);
156 DEBUG(10,("jfs2 get_nt_acl finished successfully\n"));
161 static NTSTATUS
aixjfs2_fget_nt_acl(vfs_handle_struct
*handle
,
162 files_struct
*fsp
, int fd
, uint32 security_info
,
165 SMB4ACL_T
*pacl
= NULL
;
167 bool retryPosix
= False
;
170 result
= aixjfs2_get_nfs4_acl(fsp
->fsp_name
, &pacl
, &retryPosix
);
173 DEBUG(10, ("retrying with posix acl...\n"));
174 return posix_fget_nt_acl(fsp
, security_info
, ppdesc
);
177 return NT_STATUS_ACCESS_DENIED
;
179 return smb_fget_nt_acl_nfs4(fsp
, security_info
, ppdesc
, pacl
);
182 static NTSTATUS
aixjfs2_get_nt_acl(vfs_handle_struct
*handle
,
183 files_struct
*fsp
, const char *name
,
184 uint32 security_info
, SEC_DESC
**ppdesc
)
186 SMB4ACL_T
*pacl
= NULL
;
188 bool retryPosix
= False
;
191 result
= aixjfs2_get_nfs4_acl(name
, &pacl
, &retryPosix
);
194 DEBUG(10, ("retrying with posix acl...\n"));
195 return posix_get_nt_acl(handle
->conn
, name security_info
,
199 return NT_STATUS_ACCESS_DENIED
;
201 return smb_get_nt_acl_nfs4(handle
->conn
, name
, security_info
, ppdesc
,
205 static SMB_ACL_T
aixjfs2_get_posix_acl(const char *path
, acl_type_t type
)
209 SMB_ACL_T result
= NULL
;
212 acl
= aixjfs2_getacl_alloc(path
, &type
);
215 DEBUG(10, ("aixjfs2_getacl failed for %s with %s\n",
216 path
, strerror(errno
)));
223 pacl
= &acl
->aixc_acl
[0];
224 DEBUG(10, ("len: %d, mode: %d\n",
225 pacl
->acl_len
, pacl
->acl_mode
));
227 result
= aixacl_to_smbacl(pacl
);
228 if (result
== NULL
) {
239 SMB_ACL_T
aixjfs2_sys_acl_get_file(vfs_handle_struct
*handle
,
243 acl_type_t aixjfs2_type
;
246 case SMB_ACL_TYPE_ACCESS
:
247 aixjfs2_type
.u64
= ACL_AIXC
;
249 case SMB_ACL_TYPE_DEFAULT
:
250 DEBUG(0, ("Got AIX JFS2 unsupported type: %d\n", type
));
253 DEBUG(0, ("Got invalid type: %d\n", type
));
254 smb_panic("exiting");
257 return aixjfs2_get_posix_acl(path_p
, aixjfs2_type
);
260 SMB_ACL_T
aixjfs2_sys_acl_get_fd(vfs_handle_struct
*handle
,
264 acl_type_t aixjfs2_type
;
265 aixjfs2_type
.u64
= ACL_AIXC
;
267 return aixjfs2_get_posix_acl(fsp
->fsp_name
, aixjfs2_type
);
271 * Test whether we have that aclType support on the given path
273 static int aixjfs2_query_acl_support(
276 acl_type_t
*pacl_type_info
279 acl_types_list_t acl_type_list
;
280 size_t acl_type_list_len
= sizeof(acl_types_list_t
);
283 memset(&acl_type_list
, 0, sizeof(acl_type_list
));
285 if (aclx_gettypes(filepath
, &acl_type_list
, &acl_type_list_len
)) {
286 DEBUG(2, ("aclx_gettypes failed with error %s for %s\n",
287 strerror(errno
), filepath
));
291 for(i
=0; i
<acl_type_list
.num_entries
; i
++) {
292 if (acl_type_list
.entries
[i
].u64
==aclType
) {
293 memcpy(pacl_type_info
, acl_type_list
.entries
+ i
, sizeof(acl_type_t
));
294 DEBUG(10, ("found %s ACL support for %s\n",
295 pacl_type_info
->acl_type
, filepath
));
300 return 1; /* haven't found that ACL type. */
303 static bool aixjfs2_process_smbacl(files_struct
*fsp
, SMB4ACL_T
*smbacl
)
307 nfs4_acl_int_t
*jfs2acl
;
309 uint32 aclLen
, naces
;
313 DEBUG(10, ("jfs2_process_smbacl invoked on %s\n", fsp
->fsp_name
));
315 /* no need to be freed which is alloced with mem_ctx */
316 mem_ctx
= talloc_tos();
318 entryLen
= sizeof(nfs4_ace_int_t
);
320 entryLen
= entryLen
+ 4 - (entryLen
%4);
322 naces
= smb_get_naces(smbacl
);
323 aclLen
= ACL_V4_SIZ
+ naces
* entryLen
;
324 jfs2acl
= (nfs4_acl_int_t
*)TALLOC_SIZE(mem_ctx
, aclLen
);
326 DEBUG(0, ("TALLOC_SIZE failed\n"));
331 jfs2acl
->aclLength
= ACL_V4_SIZ
;
332 jfs2acl
->aclVersion
= NFS4_ACL_INT_STRUCT_VERSION
;
333 jfs2acl
->aclEntryN
= 0;
335 for(smbace
= smb_first_ace4(smbacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
))
337 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
338 nfs4_ace_int_t
*jfs2_ace
= (nfs4_ace_int_t
*)(((char *)jfs2acl
) + jfs2acl
->aclLength
);
340 memset(jfs2_ace
, 0, entryLen
);
341 jfs2_ace
->entryLen
= entryLen
; /* won't store textual "who" */
342 jfs2_ace
->aceType
= aceprop
->aceType
; /* only ACCES|DENY supported by jfs2 */
343 jfs2_ace
->aceFlags
= aceprop
->aceFlags
;
344 jfs2_ace
->aceMask
= aceprop
->aceMask
;
345 jfs2_ace
->flags
= (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
) ? ACE4_ID_SPECIAL
: 0;
347 /* don't care it's real content is only 16 or 32 bit */
348 jfs2_ace
->aceWho
.id
= aceprop
->who
.id
;
350 /* iterate to the next jfs2 ace */
351 jfs2acl
->aclLength
+= jfs2_ace
->entryLen
;
352 jfs2acl
->aclEntryN
++;
354 SMB_ASSERT(jfs2acl
->aclEntryN
==naces
);
356 /* Don't query it (again) */
357 memset(&acltype
, 0, sizeof(acl_type_t
));
358 acltype
.u64
= ACL_NFS4
;
360 /* won't set S_ISUID - the only one JFS2/NFS4 accepts */
363 SET_ACL
, /* set only the ACL, not mode bits */
364 acltype
, /* not a pointer !!! */
367 0 /* don't set here mode bits */
370 DEBUG(8, ("aclx_put failed with %s\n", strerror(errno
)));
374 DEBUG(10, ("jfs2_process_smbacl succeeded.\n"));
378 static NTSTATUS
aixjfs2_set_nt_acl_common(files_struct
*fsp
, uint32 security_info_sent
, SEC_DESC
*psd
)
380 acl_type_t acl_type_info
;
381 NTSTATUS result
= NT_STATUS_ACCESS_DENIED
;
384 rc
= aixjfs2_query_acl_support(
391 result
= smb_set_nt_acl_nfs4(
392 fsp
, security_info_sent
, psd
,
393 aixjfs2_process_smbacl
);
394 } else if (rc
==1) { /* assume POSIX ACL - by default... */
395 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
397 result
= map_nt_error_from_unix(errno
); /* query failed */
402 NTSTATUS
aixjfs2_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, int fd
, uint32 security_info_sent
, SEC_DESC
*psd
)
404 return aixjfs2_set_nt_acl_common(fsp
, security_info_sent
, psd
);
407 NTSTATUS
aixjfs2_set_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, const char *name
, uint32 security_info_sent
, SEC_DESC
*psd
)
409 return aixjfs2_set_nt_acl_common(fsp
, security_info_sent
, psd
);
412 int aixjfs2_sys_acl_set_file(vfs_handle_struct
*handle
,
417 struct acl
*acl_aixc
;
418 acl_type_t acl_type_info
;
421 DEBUG(10, ("aixjfs2_sys_acl_set_file invoked for %s", name
));
423 rc
= aixjfs2_query_acl_support((char *)name
, ACL_AIXC
, &acl_type_info
);
425 DEBUG(8, ("jfs2_set_nt_acl: AIXC support not found\n"));
429 acl_aixc
= aixacl_smb_to_aixacl(type
, theacl
);
435 SET_ACL
, /* set only the ACL, not mode bits */
442 DEBUG(2, ("aclx_put failed with %s for %s\n",
443 strerror(errno
), name
));
450 int aixjfs2_sys_acl_set_fd(vfs_handle_struct
*handle
,
452 int fd
, SMB_ACL_T theacl
)
454 struct acl
*acl_aixc
;
455 acl_type_t acl_type_info
;
458 DEBUG(10, ("aixjfs2_sys_acl_set_fd invoked for %s", fsp
->fsp_name
));
460 rc
= aixjfs2_query_acl_support(fsp
->fsp_name
, ACL_AIXC
, &acl_type_info
);
462 DEBUG(8, ("jfs2_set_nt_acl: AIXC support not found\n"));
466 acl_aixc
= aixacl_smb_to_aixacl(SMB_ACL_TYPE_ACCESS
, theacl
);
472 SET_ACL
, /* set only the ACL, not mode bits */
479 DEBUG(2, ("aclx_fput failed with %s for %s\n",
480 strerror(errno
), fsp
->fsp_name
));
487 int aixjfs2_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
490 /* Not available under AIXC ACL */
491 /* Don't report here any error otherwise */
492 /* upper layer will break the normal execution */
497 /* VFS operations structure */
499 static vfs_op_tuple aixjfs2_ops
[] =
501 {SMB_VFS_OP(aixjfs2_fget_nt_acl
),
502 SMB_VFS_OP_FGET_NT_ACL
,
503 SMB_VFS_LAYER_TRANSPARENT
},
505 {SMB_VFS_OP(aixjfs2_get_nt_acl
),
506 SMB_VFS_OP_GET_NT_ACL
,
507 SMB_VFS_LAYER_TRANSPARENT
},
509 {SMB_VFS_OP(aixjfs2_fset_nt_acl
),
510 SMB_VFS_OP_FSET_NT_ACL
,
511 SMB_VFS_LAYER_TRANSPARENT
},
513 {SMB_VFS_OP(aixjfs2_set_nt_acl
),
514 SMB_VFS_OP_SET_NT_ACL
,
515 SMB_VFS_LAYER_TRANSPARENT
},
517 {SMB_VFS_OP(aixjfs2_sys_acl_get_file
),
518 SMB_VFS_OP_SYS_ACL_GET_FILE
,
519 SMB_VFS_LAYER_TRANSPARENT
},
521 {SMB_VFS_OP(aixjfs2_sys_acl_get_fd
),
522 SMB_VFS_OP_SYS_ACL_GET_FD
,
523 SMB_VFS_LAYER_TRANSPARENT
},
525 {SMB_VFS_OP(aixjfs2_sys_acl_set_file
),
526 SMB_VFS_OP_SYS_ACL_SET_FILE
,
527 SMB_VFS_LAYER_TRANSPARENT
},
529 {SMB_VFS_OP(aixjfs2_sys_acl_set_fd
),
530 SMB_VFS_OP_SYS_ACL_SET_FD
,
531 SMB_VFS_LAYER_TRANSPARENT
},
533 {SMB_VFS_OP(aixjfs2_sys_acl_delete_def_file
),
534 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE
,
535 SMB_VFS_LAYER_TRANSPARENT
},
542 NTSTATUS
vfs_aixacl2_init(void);
543 NTSTATUS
vfs_aixacl2_init(void)
545 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, AIXACL2_MODULE_NAME
,