00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "includes.h"
00022
00023
00024
00025 static struct smb_acl_t *tru64_acl_to_smb_acl(const struct acl *tru64_acl);
00026 static BOOL tru64_ace_to_smb_ace(acl_entry_t tru64_ace,
00027 struct smb_acl_entry *smb_ace);
00028 static acl_t smb_acl_to_tru64_acl(const SMB_ACL_T smb_acl);
00029 static acl_tag_t smb_tag_to_tru64(SMB_ACL_TAG_T smb_tag);
00030 static SMB_ACL_TAG_T tru64_tag_to_smb(acl_tag_t tru64_tag);
00031 static acl_perm_t smb_permset_to_tru64(SMB_ACL_PERM_T smb_permset);
00032 static SMB_ACL_PERM_T tru64_permset_to_smb(const acl_perm_t tru64_permset);
00033
00034
00035
00036
00037 SMB_ACL_T tru64acl_sys_acl_get_file(vfs_handle_struct *handle,
00038 const char *path_p,
00039 SMB_ACL_TYPE_T type)
00040 {
00041 struct smb_acl_t *result;
00042 acl_type_t the_acl_type;
00043 acl_t tru64_acl;
00044
00045 DEBUG(10, ("Hi! This is tru64acl_sys_acl_get_file.\n"));
00046
00047 switch(type) {
00048 case SMB_ACL_TYPE_ACCESS:
00049 the_acl_type = ACL_TYPE_ACCESS;
00050 break;
00051 case SMB_ACL_TYPE_DEFAULT:
00052 the_acl_type = ACL_TYPE_DEFAULT;
00053 break;
00054 default:
00055 errno = EINVAL;
00056 return NULL;
00057 }
00058
00059 tru64_acl = acl_get_file((char *)path_p, the_acl_type);
00060
00061 if (tru64_acl == NULL) {
00062 return NULL;
00063 }
00064
00065 result = tru64_acl_to_smb_acl(tru64_acl);
00066 acl_free(tru64_acl);
00067 return result;
00068 }
00069
00070 SMB_ACL_T tru64acl_sys_acl_get_fd(vfs_handle_struct *handle,
00071 files_struct *fsp,
00072 int fd)
00073 {
00074 struct smb_acl_t *result;
00075 acl_t tru64_acl = acl_get_fd(fd, ACL_TYPE_ACCESS);
00076
00077 if (tru64_acl == NULL) {
00078 return NULL;
00079 }
00080
00081 result = tru64_acl_to_smb_acl(tru64_acl);
00082 acl_free(tru64_acl);
00083 return result;
00084 }
00085
00086 int tru64acl_sys_acl_set_file(vfs_handle_struct *handle,
00087 const char *name,
00088 SMB_ACL_TYPE_T type,
00089 SMB_ACL_T theacl)
00090 {
00091 int res;
00092 acl_type_t the_acl_type;
00093 acl_t tru64_acl;
00094
00095 DEBUG(10, ("tru64acl_sys_acl_set_file called with name %s, type %d\n",
00096 name, type));
00097
00098 switch(type) {
00099 case SMB_ACL_TYPE_ACCESS:
00100 DEBUGADD(10, ("got acl type ACL_TYPE_ACCESS\n"));
00101 the_acl_type = ACL_TYPE_ACCESS;
00102 break;
00103 case SMB_ACL_TYPE_DEFAULT:
00104 DEBUGADD(10, ("got acl type ACL_TYPE_DEFAULT\n"));
00105 the_acl_type = ACL_TYPE_DEFAULT;
00106 break;
00107 default:
00108 DEBUGADD(10, ("invalid acl type\n"));
00109 errno = EINVAL;
00110 goto fail;
00111 }
00112
00113 tru64_acl = smb_acl_to_tru64_acl(theacl);
00114 if (tru64_acl == NULL) {
00115 DEBUG(10, ("smb_acl_to_tru64_acl failed!\n"));
00116 goto fail;
00117 }
00118 DEBUG(10, ("got tru64 acl...\n"));
00119 res = acl_set_file((char *)name, the_acl_type, tru64_acl);
00120 acl_free(tru64_acl);
00121 if (res != 0) {
00122 DEBUG(10, ("acl_set_file failed: %s\n", strerror(errno)));
00123 goto fail;
00124 }
00125 return res;
00126 fail:
00127 DEBUG(1, ("tru64acl_sys_acl_set_file failed!\n"));
00128 return -1;
00129 }
00130
00131 int tru64acl_sys_acl_set_fd(vfs_handle_struct *handle,
00132 files_struct *fsp,
00133 int fd, SMB_ACL_T theacl)
00134 {
00135 int res;
00136 acl_t tru64_acl = smb_acl_to_tru64_acl(theacl);
00137 if (tru64_acl == NULL) {
00138 return -1;
00139 }
00140 res = acl_set_fd(fd, ACL_TYPE_ACCESS, tru64_acl);
00141 acl_free(tru64_acl);
00142 return res;
00143
00144 }
00145
00146 int tru64acl_sys_acl_delete_def_file(vfs_handle_struct *handle,
00147 const char *path)
00148 {
00149 return acl_delete_def_file((char *)path);
00150 }
00151
00152
00153
00154
00155 static struct smb_acl_t *tru64_acl_to_smb_acl(const struct acl *tru64_acl)
00156 {
00157 struct smb_acl_t *result;
00158 acl_entry_t entry;
00159
00160 DEBUG(10, ("Hi! This is tru64_acl_to_smb_acl.\n"));
00161
00162 if ((result = SMB_MALLOC_P(struct smb_acl_t)) == NULL) {
00163 DEBUG(0, ("SMB_MALLOC_P failed in tru64_acl_to_smb_acl\n"));
00164 errno = ENOMEM;
00165 goto fail;
00166 }
00167 ZERO_STRUCTP(result);
00168 if (acl_first_entry((struct acl *)tru64_acl) != 0) {
00169 DEBUG(10, ("acl_first_entry failed: %s\n", strerror(errno)));
00170 goto fail;
00171 }
00172 while ((entry = acl_get_entry((struct acl *)tru64_acl)) != NULL) {
00173 result = SMB_REALLOC(result, sizeof(struct smb_acl_t) +
00174 (sizeof(struct smb_acl_entry) *
00175 (result->count + 1)));
00176 if (result == NULL) {
00177 DEBUG(0, ("SMB_REALLOC failed in tru64_acl_to_smb_acl\n"));
00178 errno = ENOMEM;
00179 goto fail;
00180 }
00181
00182 if (!tru64_ace_to_smb_ace(entry, &result->acl[result->count])) {
00183 SAFE_FREE(result);
00184 goto fail;
00185 }
00186 result->count += 1;
00187 }
00188 return result;
00189
00190 fail:
00191 if (result != NULL) {
00192 SAFE_FREE(result);
00193 }
00194 DEBUG(1, ("tru64_acl_to_smb_acl failed!\n"));
00195 return NULL;
00196 }
00197
00198 static BOOL tru64_ace_to_smb_ace(acl_entry_t tru64_ace,
00199 struct smb_acl_entry *smb_ace)
00200 {
00201 acl_tag_t tru64_tag;
00202 acl_permset_t permset;
00203 SMB_ACL_TAG_T smb_tag_type;
00204 SMB_ACL_PERM_T smb_permset;
00205 void *qualifier;
00206
00207 if (acl_get_tag_type(tru64_ace, &tru64_tag) != 0) {
00208 DEBUG(0, ("acl_get_tag_type failed: %s\n", strerror(errno)));
00209 return False;
00210 }
00211
00212
00213
00214 smb_tag_type = tru64_tag_to_smb(tru64_tag);
00215 if (smb_tag_type == 0) {
00216 DEBUG(3, ("invalid tag type given: %d\n", tru64_tag));
00217 return False;
00218 }
00219 if (sys_acl_set_tag_type(smb_ace, smb_tag_type) != 0) {
00220 DEBUG(3, ("sys_acl_set_tag_type failed: %s\n",
00221 strerror(errno)));
00222 return False;
00223 }
00224 qualifier = acl_get_qualifier(tru64_ace);
00225 if (qualifier != NULL) {
00226 if (sys_acl_set_qualifier(smb_ace, qualifier) != 0) {
00227 DEBUG(3, ("sys_acl_set_qualifier failed\n"));
00228 return False;
00229 }
00230 }
00231 if (acl_get_permset(tru64_ace, &permset) != 0) {
00232 DEBUG(3, ("acl_get_permset failed: %s\n", strerror(errno)));
00233 return False;
00234 }
00235 smb_permset = tru64_permset_to_smb(*permset);
00236 if (sys_acl_set_permset(smb_ace, &smb_permset) != 0) {
00237 DEBUG(3, ("sys_acl_set_permset failed: %s\n", strerror(errno)));
00238 return False;
00239 }
00240 return True;
00241 }
00242
00243 static acl_t smb_acl_to_tru64_acl(const SMB_ACL_T smb_acl)
00244 {
00245 acl_t result;
00246 acl_entry_t tru64_entry;
00247 int i;
00248 char *acl_text;
00249 ssize_t acl_text_len;
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261 DEBUG(10, ("Hi! This is smb_acl_to_tru64_acl.\n"));
00262
00263 result = acl_init(1);
00264
00265 if (result == NULL) {
00266 DEBUG(3, ("acl_init failed!\n"));
00267 goto fail;
00268 }
00269
00270 DEBUGADD(10, ("parsing acl entries...\n"));
00271 for (i = 0; i < smb_acl->count; i++) {
00272
00273 const struct smb_acl_entry *smb_entry = &smb_acl->acl[i];
00274 acl_tag_t tru64_tag;
00275 acl_perm_t tru64_permset;
00276
00277 tru64_tag = smb_tag_to_tru64(smb_entry->a_type);
00278 if (tru64_tag == -1) {
00279 DEBUG(3, ("smb_tag_to_tru64 failed!\n"));
00280 goto fail;
00281 }
00282
00283 if (tru64_tag == ACL_MASK) {
00284 DEBUGADD(10, (" - acl type ACL_MASK: not implemented on Tru64 ==> skipping\n"));
00285 continue;
00286 }
00287
00288 tru64_entry = acl_create_entry(&result);
00289 if (tru64_entry == NULL) {
00290 DEBUG(3, ("acl_create_entry failed: %s\n",
00291 strerror(errno)));
00292 goto fail;
00293 }
00294
00295 if (acl_set_tag_type(tru64_entry, tru64_tag) != 0) {
00296 DEBUG(3, ("acl_set_tag_type(%d) failed: %s\n",
00297 strerror(errno)));
00298 goto fail;
00299 }
00300
00301 switch (smb_entry->a_type) {
00302 case SMB_ACL_USER:
00303 if (acl_set_qualifier(tru64_entry,
00304 (int *)&smb_entry->uid) != 0)
00305 {
00306 DEBUG(3, ("acl_set_qualifier failed: %s\n",
00307 strerror(errno)));
00308 goto fail;
00309 }
00310 DEBUGADD(10, (" - setting uid to %d\n", smb_entry->uid));
00311 break;
00312 case SMB_ACL_GROUP:
00313 if (acl_set_qualifier(tru64_entry,
00314 (int *)&smb_entry->gid) != 0)
00315 {
00316 DEBUG(3, ("acl_set_qualifier failed: %s\n",
00317 strerror(errno)));
00318 goto fail;
00319 }
00320 DEBUGADD(10, (" - setting gid to %d\n", smb_entry->gid));
00321 break;
00322 default:
00323 break;
00324 }
00325
00326 tru64_permset = smb_permset_to_tru64(smb_entry->a_perm);
00327 if (tru64_permset == -1) {
00328 DEBUG(3, ("smb_permset_to_tru64 failed!\n"));
00329 goto fail;
00330 }
00331 DEBUGADD(10, (" - setting perms to %0d\n", tru64_permset));
00332 if (acl_set_permset(tru64_entry, &tru64_permset) != 0)
00333 {
00334 DEBUG(3, ("acl_set_permset failed: %s\n", strerror(errno)));
00335 goto fail;
00336 }
00337 }
00338 DEBUGADD(10, ("done parsing acl entries\n"));
00339
00340 tru64_entry = NULL;
00341 if (acl_valid(result, &tru64_entry) != 0) {
00342 DEBUG(1, ("smb_acl_to_tru64_acl: ACL is invalid (%s)\n",
00343 strerror(errno)));
00344 if (tru64_entry != NULL) {
00345 DEBUGADD(1, ("the acl contains duplicate entries\n"));
00346 }
00347 goto fail;
00348 }
00349 DEBUGADD(10, ("acl is valid\n"));
00350
00351 acl_text = acl_to_text(result, &acl_text_len);
00352 if (acl_text == NULL) {
00353 DEBUG(3, ("acl_to_text failed: %s\n", strerror(errno)));
00354 goto fail;
00355 }
00356 DEBUG(1, ("acl_text: %s\n", acl_text));
00357 free(acl_text);
00358
00359 return result;
00360
00361 fail:
00362 if (result != NULL) {
00363 acl_free(result);
00364 }
00365 DEBUG(1, ("smb_acl_to_tru64_acl failed!\n"));
00366 return NULL;
00367 }
00368
00369 static acl_tag_t smb_tag_to_tru64(SMB_ACL_TAG_T smb_tag)
00370 {
00371 acl_tag_t result;
00372 switch (smb_tag) {
00373 case SMB_ACL_USER:
00374 result = ACL_USER;
00375 DEBUGADD(10, ("got acl type ACL_USER\n"));
00376 break;
00377 case SMB_ACL_USER_OBJ:
00378 result = ACL_USER_OBJ;
00379 DEBUGADD(10, ("got acl type ACL_USER_OBJ\n"));
00380 break;
00381 case SMB_ACL_GROUP:
00382 result = ACL_GROUP;
00383 DEBUGADD(10, ("got acl type ACL_GROUP\n"));
00384 break;
00385 case SMB_ACL_GROUP_OBJ:
00386 result = ACL_GROUP_OBJ;
00387 DEBUGADD(10, ("got acl type ACL_GROUP_OBJ\n"));
00388 break;
00389 case SMB_ACL_OTHER:
00390 result = ACL_OTHER;
00391 DEBUGADD(10, ("got acl type ACL_OTHER\n"));
00392 break;
00393 case SMB_ACL_MASK:
00394 result = ACL_MASK;
00395 DEBUGADD(10, ("got acl type ACL_MASK\n"));
00396 break;
00397 default:
00398 DEBUG(1, ("Unknown tag type %d\n", smb_tag));
00399 result = -1;
00400 }
00401 return result;
00402 }
00403
00404
00405 static SMB_ACL_TAG_T tru64_tag_to_smb(acl_tag_t tru64_tag)
00406 {
00407 SMB_ACL_TAG_T smb_tag_type;
00408 switch(tru64_tag) {
00409 case ACL_USER:
00410 smb_tag_type = SMB_ACL_USER;
00411 DEBUGADD(10, ("got smb acl tag type SMB_ACL_USER\n"));
00412 break;
00413 case ACL_USER_OBJ:
00414 smb_tag_type = SMB_ACL_USER_OBJ;
00415 DEBUGADD(10, ("got smb acl tag type SMB_ACL_USER_OBJ\n"));
00416 break;
00417 case ACL_GROUP:
00418 smb_tag_type = SMB_ACL_GROUP;
00419 DEBUGADD(10, ("got smb acl tag type SMB_ACL_GROUP\n"));
00420 break;
00421 case ACL_GROUP_OBJ:
00422 smb_tag_type = SMB_ACL_GROUP_OBJ;
00423 DEBUGADD(10, ("got smb acl tag type SMB_ACL_GROUP_OBJ\n"));
00424 break;
00425 case ACL_OTHER:
00426 smb_tag_type = SMB_ACL_OTHER;
00427 DEBUGADD(10, ("got smb acl tag type SMB_ACL_OTHER\n"));
00428 break;
00429 case ACL_MASK:
00430 smb_tag_type = SMB_ACL_MASK;
00431 DEBUGADD(10, ("got smb acl tag type SMB_ACL_MASK\n"));
00432 break;
00433 default:
00434 DEBUG(0, ("Unknown tag type %d\n", (unsigned int)tru64_tag));
00435 smb_tag_type = 0;
00436 }
00437 return smb_tag_type;
00438 }
00439
00440 static acl_perm_t smb_permset_to_tru64(SMB_ACL_PERM_T smb_permset)
00441 {
00442
00443
00444
00445
00446 acl_perm_t tru64_permset = 0;
00447 if (acl_clear_perm(&tru64_permset) != 0) {
00448 DEBUG(5, ("acl_clear_perm failed: %s\n", strerror(errno)));
00449 return -1;
00450 }
00451
00452
00453 tru64_permset |= ((smb_permset & SMB_ACL_READ) ? ACL_READ : 0);
00454 tru64_permset |= ((smb_permset & SMB_ACL_WRITE) ? ACL_WRITE : 0);
00455 tru64_permset |= ((smb_permset & SMB_ACL_EXECUTE) ? ACL_EXECUTE : 0);
00456 return tru64_permset;
00457 }
00458
00459 static SMB_ACL_PERM_T tru64_permset_to_smb(const acl_perm_t tru64_permset)
00460 {
00461 SMB_ACL_PERM_T smb_permset = 0;
00462 smb_permset |= ((tru64_permset & ACL_READ) ? SMB_ACL_READ : 0);
00463 smb_permset |= ((tru64_permset & ACL_WRITE) ? SMB_ACL_WRITE : 0);
00464 smb_permset |= ((tru64_permset & ACL_EXECUTE) ? SMB_ACL_EXECUTE : 0);
00465 return smb_permset;
00466 }
00467
00468
00469
00470
00471 static vfs_op_tuple tru64acl_op_tuples[] = {
00472
00473 {SMB_VFS_OP(tru64acl_sys_acl_get_file),
00474 SMB_VFS_OP_SYS_ACL_GET_FILE,
00475 SMB_VFS_LAYER_TRANSPARENT},
00476
00477 {SMB_VFS_OP(tru64acl_sys_acl_get_fd),
00478 SMB_VFS_OP_SYS_ACL_GET_FD,
00479 SMB_VFS_LAYER_TRANSPARENT},
00480
00481 {SMB_VFS_OP(tru64acl_sys_acl_set_file),
00482 SMB_VFS_OP_SYS_ACL_SET_FILE,
00483 SMB_VFS_LAYER_TRANSPARENT},
00484
00485 {SMB_VFS_OP(tru64acl_sys_acl_set_fd),
00486 SMB_VFS_OP_SYS_ACL_SET_FD,
00487 SMB_VFS_LAYER_TRANSPARENT},
00488
00489 {SMB_VFS_OP(tru64acl_sys_acl_delete_def_file),
00490 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
00491 SMB_VFS_LAYER_TRANSPARENT},
00492
00493 {SMB_VFS_OP(NULL),
00494 SMB_VFS_OP_NOOP,
00495 SMB_VFS_LAYER_NOOP}
00496 };
00497
00498 NTSTATUS vfs_tru64acl_init(void);
00499 NTSTATUS vfs_tru64acl_init(void)
00500 {
00501 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "tru64acl",
00502 tru64acl_op_tuples);
00503 }
00504
00505