2 Unix SMB/Netbios implementation.
3 VFS module to get and set posix acls
4 Copyright (C) Jim McDonough <jmcd@us.ibm.com> 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/>.
22 SMB_ACL_T
aixacl_to_smbacl(struct acl
*file_acl
)
24 struct acl_entry
*acl_entry
;
27 struct smb_acl_t
*result
= SMB_MALLOC_P(struct smb_acl_t
);
28 struct smb_acl_entry
*ace
;
36 /* Point to the first acl entry in the acl */
37 acl_entry
= file_acl
->acl_ext
;
41 DEBUG(10,("acl_entry is %p\n",(void *)acl_entry
));
42 DEBUG(10,("acl_last(file_acl) id %p\n",(void *)acl_last(file_acl
)));
44 /* Check if the extended acl bit is on. *
45 * If it isn't, do not show the *
46 * contents of the acl since AIX intends *
47 * the extended info to remain unused */
49 if(file_acl
->acl_mode
& S_IXACL
){
50 /* while we are not pointing to the very end */
51 while(acl_entry
< acl_last(file_acl
)) {
52 /* before we malloc anything, make sure this is */
53 /* a valid acl entry and one that we want to map */
54 idp
= id_nxt(acl_entry
->ace_id
);
55 if((acl_entry
->ace_type
== ACC_SPECIFY
||
56 (acl_entry
->ace_type
== ACC_PERMIT
)) && (idp
!= id_last(acl_entry
))) {
57 acl_entry
= acl_nxt(acl_entry
);
61 idp
= acl_entry
->ace_id
;
62 DEBUG(10,("idp->id_data is %d\n",idp
->id_data
[0]));
64 result
= SMB_REALLOC(result
, sizeof(struct smb_acl_t
) +
65 (sizeof(struct smb_acl_entry
) *
68 DEBUG(0, ("SMB_REALLOC failed\n"));
74 DEBUG(10,("idp->id_type is %d\n",idp
->id_type
));
75 ace
= &result
->acl
[result
->count
];
77 ace
->a_type
= idp
->id_type
;
81 ace
->uid
= idp
->id_data
[0];
82 DEBUG(10,("case ACEID_USER ace->uid is %d\n",ace
->uid
));
83 ace
->a_type
= SMB_ACL_USER
;
88 ace
->gid
= idp
->id_data
[0];
89 DEBUG(10,("case ACEID_GROUP ace->gid is %d\n",ace
->gid
));
90 ace
->a_type
= SMB_ACL_GROUP
;
96 /* The access in the acl entries must be left shifted by *
97 * three bites, because they will ultimately be compared *
98 * to S_IRUSR, S_IWUSR, and S_IXUSR. */
100 switch(acl_entry
->ace_type
){
103 ace
->a_perm
= acl_entry
->ace_access
;
105 DEBUG(10,("ace->a_perm is %d\n",ace
->a_perm
));
108 /* Since there is no way to return a DENY acl entry *
109 * change to PERMIT and then shift. */
110 DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry
->ace_access
));
111 ace
->a_perm
= ~acl_entry
->ace_access
& 7;
112 DEBUG(10,("ace->a_perm is %d\n",ace
->a_perm
));
116 DEBUG(0, ("unknown ace->type\n"));
122 ace
->a_perm
|= (ace
->a_perm
& S_IRUSR
) ? SMB_ACL_READ
: 0;
123 ace
->a_perm
|= (ace
->a_perm
& S_IWUSR
) ? SMB_ACL_WRITE
: 0;
124 ace
->a_perm
|= (ace
->a_perm
& S_IXUSR
) ? SMB_ACL_EXECUTE
: 0;
125 DEBUG(10,("ace->a_perm is %d\n",ace
->a_perm
));
127 DEBUG(10,("acl_entry = %p\n",(void *)acl_entry
));
128 DEBUG(10,("The ace_type is %d\n",acl_entry
->ace_type
));
130 acl_entry
= acl_nxt(acl_entry
);
132 } /* end of if enabled */
134 /* Since owner, group, other acl entries are not *
135 * part of the acl entries in an acl, they must *
136 * be dummied up to become part of the list. */
138 for( i
= 1; i
< 4; i
++) {
139 DEBUG(10,("i is %d\n",i
));
141 result
= SMB_REALLOC(result
, sizeof(struct smb_acl_t
) +
142 (sizeof(struct smb_acl_entry
) *
144 if (result
== NULL
) {
145 DEBUG(0, ("SMB_REALLOC failed\n"));
147 DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno
));
151 ace
= &result
->acl
[result
->count
];
155 DEBUG(10,("ace->uid = %d\n",ace
->uid
));
159 ace
->a_perm
= file_acl
->g_access
<< 6;
160 ace
->a_type
= SMB_ACL_GROUP_OBJ
;
164 ace
->a_perm
= file_acl
->o_access
<< 6;
165 ace
->a_type
= SMB_ACL_OTHER
;
169 ace
->a_perm
= file_acl
->u_access
<< 6;
170 ace
->a_type
= SMB_ACL_USER_OBJ
;
177 ace
->a_perm
|= ((ace
->a_perm
& S_IRUSR
) ? SMB_ACL_READ
: 0);
178 ace
->a_perm
|= ((ace
->a_perm
& S_IWUSR
) ? SMB_ACL_WRITE
: 0);
179 ace
->a_perm
|= ((ace
->a_perm
& S_IXUSR
) ? SMB_ACL_EXECUTE
: 0);
181 memcpy(&result
->acl
[result
->count
],ace
,sizeof(struct smb_acl_entry
));
183 DEBUG(10,("ace->a_perm = %d\n",ace
->a_perm
));
184 DEBUG(10,("ace->a_type = %d\n",ace
->a_type
));
193 static ushort
aixacl_smb_to_aixperm(SMB_ACL_PERM_T a_perm
)
195 ushort ret
= (ushort
)0;
196 if (a_perm
& SMB_ACL_READ
)
198 if (a_perm
& SMB_ACL_WRITE
)
200 if (a_perm
& SMB_ACL_EXECUTE
)
205 struct acl
*aixacl_smb_to_aixacl(SMB_ACL_TYPE_T acltype
, SMB_ACL_T theacl
)
207 struct smb_acl_entry
*smb_entry
= NULL
;
208 struct acl
*file_acl
= NULL
;
209 struct acl
*file_acl_temp
= NULL
;
210 struct acl_entry
*acl_entry
= NULL
;
211 struct ace_id
*ace_id
= NULL
;
212 unsigned int id_type
;
213 unsigned int acl_length
;
216 DEBUG(10,("Entering aixacl_smb_to_aixacl\n"));
217 /* AIX has no default ACL */
218 if(acltype
== SMB_ACL_TYPE_DEFAULT
)
222 file_acl
= (struct acl
*)SMB_MALLOC(BUFSIZ
);
223 if(file_acl
== NULL
) {
225 DEBUG(0,("Error in aixacl_smb_to_aixacl is %d\n",errno
));
229 memset(file_acl
,0,BUFSIZ
);
231 file_acl
->acl_len
= ACL_SIZ
;
232 file_acl
->acl_mode
= S_IXACL
;
234 for(i
=0; i
<theacl
->count
; i
++ ) {
235 smb_entry
= &(theacl
->acl
[i
]);
236 id_type
= smb_entry
->a_type
;
237 DEBUG(10,("The id_type is %d\n",id_type
));
240 case SMB_ACL_USER_OBJ
:
241 file_acl
->u_access
= aixacl_smb_to_aixperm(smb_entry
->a_perm
);
243 case SMB_ACL_GROUP_OBJ
:
244 file_acl
->g_access
= aixacl_smb_to_aixperm(smb_entry
->a_perm
);
247 file_acl
->o_access
= aixacl_smb_to_aixperm(smb_entry
->a_perm
);
252 break; /* process this */
254 break; /* process this */
255 default: /* abnormal case */
256 DEBUG(10,("The id_type is unknown !\n"));
260 if((file_acl
->acl_len
+ sizeof(struct acl_entry
)) > acl_length
) {
261 acl_length
+= sizeof(struct acl_entry
);
262 file_acl_temp
= (struct acl
*)SMB_MALLOC(acl_length
);
263 if(file_acl_temp
== NULL
) {
266 DEBUG(0,("Error in aixacl_smb_to_aixacl is %d\n",errno
));
270 memcpy(file_acl_temp
,file_acl
,file_acl
->acl_len
);
272 file_acl
= file_acl_temp
;
275 acl_entry
= (struct acl_entry
*)((char *)file_acl
+ file_acl
->acl_len
);
276 file_acl
->acl_len
+= sizeof(struct acl_entry
);
277 acl_entry
->ace_len
= sizeof(struct acl_entry
); /* contains 1 ace_id */
278 acl_entry
->ace_access
= aixacl_smb_to_aixperm(smb_entry
->a_perm
);
280 /* In order to use this, we'll need to wait until we can get denies */
281 /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
282 acl_entry->ace_type = ACC_SPECIFY; */
284 acl_entry
->ace_type
= ACC_SPECIFY
;
286 ace_id
= acl_entry
->ace_id
;
288 ace_id
->id_type
= (smb_entry
->a_type
==SMB_ACL_GROUP
) ? ACEID_GROUP
: ACEID_USER
;
289 DEBUG(10,("The id type is %d\n",ace_id
->id_type
));
290 ace_id
->id_len
= sizeof(struct ace_id
); /* contains 1 id_data */
291 ace_id
->id_data
[0] = (smb_entry
->a_type
==SMB_ACL_GROUP
) ? smb_entry
->gid
: smb_entry
->uid
;