| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#include "rsync.h" |
| 25 |
#include "sysacls.h" |
| 26 |
|
| 27 |
#ifdef SUPPORT_ACLS |
| 28 |
|
| 29 |
#ifdef DEBUG |
| 30 |
#undef DEBUG |
| 31 |
#endif |
| 32 |
#define DEBUG(x, y) |
| 33 |
|
| 34 |
void SAFE_FREE(void *mem) |
| 35 |
{ |
| 36 |
if (mem) |
| 37 |
free(mem); |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
#if defined(HAVE_POSIX_ACLS) |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
| 69 |
{ |
| 70 |
return acl_get_entry(the_acl, entry_id, entry_p); |
| 71 |
} |
| 72 |
|
| 73 |
int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) |
| 74 |
{ |
| 75 |
return acl_get_tag_type(entry_d, tag_type_p); |
| 76 |
} |
| 77 |
|
| 78 |
SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) |
| 79 |
{ |
| 80 |
return acl_get_file(path_p, type); |
| 81 |
} |
| 82 |
|
| 83 |
#if 0 |
| 84 |
SMB_ACL_T sys_acl_get_fd(int fd) |
| 85 |
{ |
| 86 |
return acl_get_fd(fd); |
| 87 |
} |
| 88 |
#endif |
| 89 |
|
| 90 |
#if defined(HAVE_ACL_GET_PERM_NP) |
| 91 |
#define acl_get_perm(p, b) acl_get_perm_np(p, b) |
| 92 |
#endif |
| 93 |
|
| 94 |
int sys_acl_get_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T *tag_type_p, uint32 *bits_p, id_t *u_g_id_p) |
| 95 |
{ |
| 96 |
acl_permset_t permset; |
| 97 |
|
| 98 |
if (acl_get_tag_type(entry, tag_type_p) != 0 |
| 99 |
|| acl_get_permset(entry, &permset) != 0) |
| 100 |
return -1; |
| 101 |
|
| 102 |
*bits_p = (acl_get_perm(permset, ACL_READ) ? 4 : 0) |
| 103 |
| (acl_get_perm(permset, ACL_WRITE) ? 2 : 0) |
| 104 |
| (acl_get_perm(permset, ACL_EXECUTE) ? 1 : 0); |
| 105 |
|
| 106 |
if (*tag_type_p == SMB_ACL_USER || *tag_type_p == SMB_ACL_GROUP) { |
| 107 |
void *qual; |
| 108 |
if ((qual = acl_get_qualifier(entry)) == NULL) |
| 109 |
return -1; |
| 110 |
*u_g_id_p = *(id_t*)qual; |
| 111 |
acl_free(qual); |
| 112 |
} |
| 113 |
|
| 114 |
return 0; |
| 115 |
} |
| 116 |
|
| 117 |
SMB_ACL_T sys_acl_init(int count) |
| 118 |
{ |
| 119 |
return acl_init(count); |
| 120 |
} |
| 121 |
|
| 122 |
int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) |
| 123 |
{ |
| 124 |
return acl_create_entry(pacl, pentry); |
| 125 |
} |
| 126 |
|
| 127 |
int sys_acl_set_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tag_type, uint32 bits, id_t u_g_id) |
| 128 |
{ |
| 129 |
if (acl_set_tag_type(entry, tag_type) != 0) |
| 130 |
return -1; |
| 131 |
|
| 132 |
if (tag_type == SMB_ACL_USER || tag_type == SMB_ACL_GROUP) { |
| 133 |
if (acl_set_qualifier(entry, (void*)&u_g_id) != 0) |
| 134 |
return -1; |
| 135 |
} |
| 136 |
|
| 137 |
return sys_acl_set_access_bits(entry, bits); |
| 138 |
} |
| 139 |
|
| 140 |
int sys_acl_set_access_bits(SMB_ACL_ENTRY_T entry, uint32 bits) |
| 141 |
{ |
| 142 |
acl_permset_t permset; |
| 143 |
int rc; |
| 144 |
if ((rc = acl_get_permset(entry, &permset)) != 0) |
| 145 |
return rc; |
| 146 |
acl_clear_perms(permset); |
| 147 |
if (bits & 4) |
| 148 |
acl_add_perm(permset, ACL_READ); |
| 149 |
if (bits & 2) |
| 150 |
acl_add_perm(permset, ACL_WRITE); |
| 151 |
if (bits & 1) |
| 152 |
acl_add_perm(permset, ACL_EXECUTE); |
| 153 |
return acl_set_permset(entry, permset); |
| 154 |
} |
| 155 |
|
| 156 |
int sys_acl_valid(SMB_ACL_T theacl) |
| 157 |
{ |
| 158 |
return acl_valid(theacl); |
| 159 |
} |
| 160 |
|
| 161 |
int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) |
| 162 |
{ |
| 163 |
return acl_set_file(name, acltype, theacl); |
| 164 |
} |
| 165 |
|
| 166 |
#if 0 |
| 167 |
int sys_acl_set_fd(int fd, SMB_ACL_T theacl) |
| 168 |
{ |
| 169 |
return acl_set_fd(fd, theacl); |
| 170 |
} |
| 171 |
#endif |
| 172 |
|
| 173 |
int sys_acl_delete_def_file(const char *name) |
| 174 |
{ |
| 175 |
return acl_delete_def_file(name); |
| 176 |
} |
| 177 |
|
| 178 |
int sys_acl_free_acl(SMB_ACL_T the_acl) |
| 179 |
{ |
| 180 |
return acl_free(the_acl); |
| 181 |
} |
| 182 |
|
| 183 |
#ifdef HAVE_LIBACL_AT |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
SMB_ACL_T sys_acl_get_file_at(int dirfd, const char *path_p, int at_flags, SMB_ACL_TYPE_T type) |
| 188 |
{ |
| 189 |
return acl_get_file_at(dirfd, path_p, at_flags, type); |
| 190 |
} |
| 191 |
|
| 192 |
int sys_acl_set_file_at(int dirfd, const char *path_p, int at_flags, SMB_ACL_TYPE_T type, SMB_ACL_T theacl) |
| 193 |
{ |
| 194 |
return acl_set_file_at(dirfd, path_p, at_flags, type, theacl); |
| 195 |
} |
| 196 |
|
| 197 |
int sys_acl_delete_def_file_at(int dirfd, const char *path_p, int at_flags) |
| 198 |
{ |
| 199 |
return acl_delete_def_file_at(dirfd, path_p, at_flags); |
| 200 |
} |
| 201 |
#endif |
| 202 |
|
| 203 |
#elif defined(HAVE_TRU64_ACLS) |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
| 215 |
{ |
| 216 |
SMB_ACL_ENTRY_T entry; |
| 217 |
|
| 218 |
if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) { |
| 219 |
return -1; |
| 220 |
} |
| 221 |
|
| 222 |
errno = 0; |
| 223 |
if ((entry = acl_get_entry(the_acl)) != NULL) { |
| 224 |
*entry_p = entry; |
| 225 |
return 1; |
| 226 |
} |
| 227 |
|
| 228 |
return errno ? -1 : 0; |
| 229 |
} |
| 230 |
|
| 231 |
int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) |
| 232 |
{ |
| 233 |
return acl_get_tag_type(entry_d, tag_type_p); |
| 234 |
} |
| 235 |
|
| 236 |
SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) |
| 237 |
{ |
| 238 |
return acl_get_file((char *)path_p, type); |
| 239 |
} |
| 240 |
|
| 241 |
#if 0 |
| 242 |
SMB_ACL_T sys_acl_get_fd(int fd) |
| 243 |
{ |
| 244 |
return acl_get_fd(fd, ACL_TYPE_ACCESS); |
| 245 |
} |
| 246 |
#endif |
| 247 |
|
| 248 |
int sys_acl_get_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T *tag_type_p, uint32 *bits_p, id_t *u_g_id_p) |
| 249 |
{ |
| 250 |
acl_permset_t permset; |
| 251 |
|
| 252 |
if (acl_get_tag_type(entry, tag_type_p) != 0 |
| 253 |
|| acl_get_permset(entry, &permset) != 0) |
| 254 |
return -1; |
| 255 |
|
| 256 |
*bits_p = *permset & 7; |
| 257 |
|
| 258 |
if (*tag_type_p == SMB_ACL_USER || *tag_type_p == SMB_ACL_GROUP) { |
| 259 |
void *qual; |
| 260 |
if ((qual = acl_get_qualifier(entry)) == NULL) |
| 261 |
return -1; |
| 262 |
*u_g_id_p = *(id_t*)qual; |
| 263 |
acl_free_qualifier(qual, *tag_type_p); |
| 264 |
} |
| 265 |
|
| 266 |
return 0; |
| 267 |
} |
| 268 |
|
| 269 |
SMB_ACL_T sys_acl_init(int count) |
| 270 |
{ |
| 271 |
return acl_init(count); |
| 272 |
} |
| 273 |
|
| 274 |
int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) |
| 275 |
{ |
| 276 |
SMB_ACL_ENTRY_T entry; |
| 277 |
|
| 278 |
if ((entry = acl_create_entry(pacl)) == NULL) { |
| 279 |
return -1; |
| 280 |
} |
| 281 |
|
| 282 |
*pentry = entry; |
| 283 |
return 0; |
| 284 |
} |
| 285 |
|
| 286 |
int sys_acl_set_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tag_type, uint32 bits, id_t u_g_id) |
| 287 |
{ |
| 288 |
if (acl_set_tag_type(entry, tag_type) != 0) |
| 289 |
return -1; |
| 290 |
|
| 291 |
if (tag_type == SMB_ACL_USER || tag_type == SMB_ACL_GROUP) { |
| 292 |
if (acl_set_qualifier(entry, (void*)&u_g_id) != 0) |
| 293 |
return -1; |
| 294 |
} |
| 295 |
|
| 296 |
return sys_acl_set_access_bits(entry, bits); |
| 297 |
} |
| 298 |
|
| 299 |
int sys_acl_set_access_bits(SMB_ACL_ENTRY_T entry, uint32 bits) |
| 300 |
{ |
| 301 |
acl_permset_t permset; |
| 302 |
int rc; |
| 303 |
if ((rc = acl_get_permset(entry, &permset)) != 0) |
| 304 |
return rc; |
| 305 |
*permset = bits & 7; |
| 306 |
return acl_set_permset(entry, permset); |
| 307 |
} |
| 308 |
|
| 309 |
int sys_acl_valid(SMB_ACL_T theacl) |
| 310 |
{ |
| 311 |
acl_entry_t entry; |
| 312 |
|
| 313 |
return acl_valid(theacl, &entry); |
| 314 |
} |
| 315 |
|
| 316 |
int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) |
| 317 |
{ |
| 318 |
return acl_set_file((char *)name, acltype, theacl); |
| 319 |
} |
| 320 |
|
| 321 |
#if 0 |
| 322 |
int sys_acl_set_fd(int fd, SMB_ACL_T theacl) |
| 323 |
{ |
| 324 |
return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl); |
| 325 |
} |
| 326 |
#endif |
| 327 |
|
| 328 |
int sys_acl_delete_def_file(const char *name) |
| 329 |
{ |
| 330 |
return acl_delete_def_file((char *)name); |
| 331 |
} |
| 332 |
|
| 333 |
int sys_acl_free_acl(SMB_ACL_T the_acl) |
| 334 |
{ |
| 335 |
return acl_free(the_acl); |
| 336 |
} |
| 337 |
|
| 338 |
#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS) |
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
#if defined(HAVE_UNIXWARE_ACLS) |
| 365 |
|
| 366 |
#define SETACL ACL_SET |
| 367 |
#define GETACL ACL_GET |
| 368 |
#define GETACLCNT ACL_CNT |
| 369 |
|
| 370 |
#endif |
| 371 |
|
| 372 |
|
| 373 |
int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
| 374 |
{ |
| 375 |
if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) { |
| 376 |
errno = EINVAL; |
| 377 |
return -1; |
| 378 |
} |
| 379 |
|
| 380 |
if (entry_p == NULL) { |
| 381 |
errno = EINVAL; |
| 382 |
return -1; |
| 383 |
} |
| 384 |
|
| 385 |
if (entry_id == SMB_ACL_FIRST_ENTRY) { |
| 386 |
acl_d->next = 0; |
| 387 |
} |
| 388 |
|
| 389 |
if (acl_d->next < 0) { |
| 390 |
errno = EINVAL; |
| 391 |
return -1; |
| 392 |
} |
| 393 |
|
| 394 |
if (acl_d->next >= acl_d->count) { |
| 395 |
return 0; |
| 396 |
} |
| 397 |
|
| 398 |
*entry_p = &acl_d->acl[acl_d->next++]; |
| 399 |
|
| 400 |
return 1; |
| 401 |
} |
| 402 |
|
| 403 |
int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p) |
| 404 |
{ |
| 405 |
*type_p = entry_d->a_type; |
| 406 |
|
| 407 |
return 0; |
| 408 |
} |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
#define INITIAL_ACL_SIZE 16 |
| 423 |
|
| 424 |
SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) |
| 425 |
{ |
| 426 |
SMB_ACL_T acl_d; |
| 427 |
int count; |
| 428 |
int naccess; |
| 429 |
int ndefault; |
| 430 |
|
| 431 |
if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { |
| 432 |
errno = EINVAL; |
| 433 |
return NULL; |
| 434 |
} |
| 435 |
|
| 436 |
count = INITIAL_ACL_SIZE; |
| 437 |
if ((acl_d = sys_acl_init(count)) == NULL) { |
| 438 |
return NULL; |
| 439 |
} |
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0 |
| 450 |
&& errno == ENOSPC) { |
| 451 |
|
| 452 |
sys_acl_free_acl(acl_d); |
| 453 |
|
| 454 |
if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) { |
| 455 |
return NULL; |
| 456 |
} |
| 457 |
|
| 458 |
if ((acl_d = sys_acl_init(count)) == NULL) { |
| 459 |
return NULL; |
| 460 |
} |
| 461 |
} |
| 462 |
|
| 463 |
if (count < 0) { |
| 464 |
sys_acl_free_acl(acl_d); |
| 465 |
return NULL; |
| 466 |
} |
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
for (naccess = 0; naccess < count; naccess++) { |
| 476 |
if (acl_d->acl[naccess].a_type & ACL_DEFAULT) |
| 477 |
break; |
| 478 |
} |
| 479 |
ndefault = count - naccess; |
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
if (type == SMB_ACL_TYPE_DEFAULT) { |
| 487 |
int i, j; |
| 488 |
|
| 489 |
for (i = 0, j = naccess; i < ndefault; i++, j++) { |
| 490 |
acl_d->acl[i] = acl_d->acl[j]; |
| 491 |
acl_d->acl[i].a_type &= ~ACL_DEFAULT; |
| 492 |
} |
| 493 |
|
| 494 |
acl_d->count = ndefault; |
| 495 |
} else { |
| 496 |
acl_d->count = naccess; |
| 497 |
} |
| 498 |
|
| 499 |
return acl_d; |
| 500 |
} |
| 501 |
|
| 502 |
#ifdef HAVE_SOLARIS_ACLS |
| 503 |
|
| 504 |
|
| 505 |
SMB_ACL_T sys_acl_get_fd_type(int fd, SMB_ACL_TYPE_T type) |
| 506 |
{ |
| 507 |
SMB_ACL_T acl_d; |
| 508 |
int count; |
| 509 |
int naccess; |
| 510 |
int ndefault; |
| 511 |
|
| 512 |
if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { |
| 513 |
errno = EINVAL; |
| 514 |
return NULL; |
| 515 |
} |
| 516 |
|
| 517 |
count = INITIAL_ACL_SIZE; |
| 518 |
if ((acl_d = sys_acl_init(count)) == NULL) { |
| 519 |
return NULL; |
| 520 |
} |
| 521 |
|
| 522 |
while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0 |
| 523 |
&& errno == ENOSPC) { |
| 524 |
|
| 525 |
sys_acl_free_acl(acl_d); |
| 526 |
|
| 527 |
if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) { |
| 528 |
return NULL; |
| 529 |
} |
| 530 |
|
| 531 |
if ((acl_d = sys_acl_init(count)) == NULL) { |
| 532 |
return NULL; |
| 533 |
} |
| 534 |
} |
| 535 |
|
| 536 |
if (count < 0) { |
| 537 |
sys_acl_free_acl(acl_d); |
| 538 |
return NULL; |
| 539 |
} |
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
for (naccess = 0; naccess < count; naccess++) { |
| 545 |
if (acl_d->acl[naccess].a_type & ACL_DEFAULT) |
| 546 |
break; |
| 547 |
} |
| 548 |
ndefault = count - naccess; |
| 549 |
|
| 550 |
if (type == SMB_ACL_TYPE_DEFAULT) { |
| 551 |
int i, j; |
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
for (i = 0, j = naccess; i < ndefault; i++, j++) { |
| 559 |
acl_d->acl[i] = acl_d->acl[j]; |
| 560 |
acl_d->acl[i].a_type &= ~ACL_DEFAULT; |
| 561 |
} |
| 562 |
|
| 563 |
acl_d->count = ndefault; |
| 564 |
} else { |
| 565 |
acl_d->count = naccess; |
| 566 |
} |
| 567 |
|
| 568 |
return acl_d; |
| 569 |
} |
| 570 |
|
| 571 |
SMB_ACL_T sys_acl_get_fd(int fd) |
| 572 |
{ |
| 573 |
return sys_acl_get_fd_type(fd, SMB_ACL_TYPE_ACCESS); |
| 574 |
} |
| 575 |
#endif |
| 576 |
|
| 577 |
int sys_acl_get_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T *tag_type_p, uint32 *bits_p, id_t *u_g_id_p) |
| 578 |
{ |
| 579 |
*tag_type_p = entry->a_type; |
| 580 |
|
| 581 |
*bits_p = entry->a_perm; |
| 582 |
|
| 583 |
if (*tag_type_p == SMB_ACL_USER || *tag_type_p == SMB_ACL_GROUP) |
| 584 |
*u_g_id_p = entry->a_id; |
| 585 |
|
| 586 |
return 0; |
| 587 |
} |
| 588 |
|
| 589 |
SMB_ACL_T sys_acl_init(int count) |
| 590 |
{ |
| 591 |
SMB_ACL_T a; |
| 592 |
|
| 593 |
if (count < 0) { |
| 594 |
errno = EINVAL; |
| 595 |
return NULL; |
| 596 |
} |
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof a[0] + count * sizeof (struct acl))) == NULL) { |
| 605 |
errno = ENOMEM; |
| 606 |
return NULL; |
| 607 |
} |
| 608 |
|
| 609 |
a->size = count + 1; |
| 610 |
a->count = 0; |
| 611 |
a->next = -1; |
| 612 |
|
| 613 |
return a; |
| 614 |
} |
| 615 |
|
| 616 |
|
| 617 |
int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p) |
| 618 |
{ |
| 619 |
SMB_ACL_T acl_d; |
| 620 |
SMB_ACL_ENTRY_T entry_d; |
| 621 |
|
| 622 |
if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) { |
| 623 |
errno = EINVAL; |
| 624 |
return -1; |
| 625 |
} |
| 626 |
|
| 627 |
if (acl_d->count >= acl_d->size) { |
| 628 |
errno = ENOSPC; |
| 629 |
return -1; |
| 630 |
} |
| 631 |
|
| 632 |
entry_d = &acl_d->acl[acl_d->count++]; |
| 633 |
entry_d->a_type = 0; |
| 634 |
entry_d->a_id = -1; |
| 635 |
entry_d->a_perm = 0; |
| 636 |
*entry_p = entry_d; |
| 637 |
|
| 638 |
return 0; |
| 639 |
} |
| 640 |
|
| 641 |
int sys_acl_set_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tag_type, uint32 bits, id_t u_g_id) |
| 642 |
{ |
| 643 |
entry->a_type = tag_type; |
| 644 |
|
| 645 |
if (tag_type == SMB_ACL_USER || tag_type == SMB_ACL_GROUP) |
| 646 |
entry->a_id = u_g_id; |
| 647 |
|
| 648 |
entry->a_perm = bits; |
| 649 |
|
| 650 |
return 0; |
| 651 |
} |
| 652 |
|
| 653 |
int sys_acl_set_access_bits(SMB_ACL_ENTRY_T entry_d, uint32 bits) |
| 654 |
{ |
| 655 |
entry_d->a_perm = bits; |
| 656 |
return 0; |
| 657 |
} |
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
static int acl_sort(SMB_ACL_T acl_d) |
| 677 |
{ |
| 678 |
int fixmask = (acl_d->count <= 4); |
| 679 |
|
| 680 |
if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) { |
| 681 |
errno = EINVAL; |
| 682 |
return -1; |
| 683 |
} |
| 684 |
return 0; |
| 685 |
} |
| 686 |
|
| 687 |
int sys_acl_valid(SMB_ACL_T acl_d) |
| 688 |
{ |
| 689 |
return acl_sort(acl_d); |
| 690 |
} |
| 691 |
|
| 692 |
int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d) |
| 693 |
{ |
| 694 |
struct stat s; |
| 695 |
struct acl *acl_p; |
| 696 |
int acl_count; |
| 697 |
struct acl *acl_buf = NULL; |
| 698 |
int ret; |
| 699 |
|
| 700 |
if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { |
| 701 |
errno = EINVAL; |
| 702 |
return -1; |
| 703 |
} |
| 704 |
|
| 705 |
if (acl_sort(acl_d) != 0) { |
| 706 |
return -1; |
| 707 |
} |
| 708 |
|
| 709 |
acl_p = &acl_d->acl[0]; |
| 710 |
acl_count = acl_d->count; |
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
if (stat(name, &s) != 0) { |
| 718 |
return -1; |
| 719 |
} |
| 720 |
if (S_ISDIR(s.st_mode)) { |
| 721 |
SMB_ACL_T acc_acl; |
| 722 |
SMB_ACL_T def_acl; |
| 723 |
SMB_ACL_T tmp_acl; |
| 724 |
int i; |
| 725 |
|
| 726 |
if (type == SMB_ACL_TYPE_ACCESS) { |
| 727 |
acc_acl = acl_d; |
| 728 |
def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT); |
| 729 |
|
| 730 |
} else { |
| 731 |
def_acl = acl_d; |
| 732 |
acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS); |
| 733 |
} |
| 734 |
|
| 735 |
if (tmp_acl == NULL) { |
| 736 |
return -1; |
| 737 |
} |
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
acl_count = acc_acl->count + def_acl->count; |
| 743 |
acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count); |
| 744 |
|
| 745 |
if (acl_buf == NULL) { |
| 746 |
sys_acl_free_acl(tmp_acl); |
| 747 |
errno = ENOMEM; |
| 748 |
return -1; |
| 749 |
} |
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
memcpy(&acl_buf[0], &acc_acl->acl[0], |
| 755 |
acc_acl->count * sizeof acl_buf[0]); |
| 756 |
|
| 757 |
memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0], |
| 758 |
def_acl->count * sizeof acl_buf[0]); |
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
for (i = acc_acl->count; i < acl_count; i++) { |
| 764 |
acl_buf[i].a_type |= ACL_DEFAULT; |
| 765 |
} |
| 766 |
|
| 767 |
sys_acl_free_acl(tmp_acl); |
| 768 |
|
| 769 |
} else if (type != SMB_ACL_TYPE_ACCESS) { |
| 770 |
errno = EINVAL; |
| 771 |
return -1; |
| 772 |
} |
| 773 |
|
| 774 |
ret = acl(name, SETACL, acl_count, acl_p); |
| 775 |
|
| 776 |
SAFE_FREE(acl_buf); |
| 777 |
|
| 778 |
return ret; |
| 779 |
} |
| 780 |
|
| 781 |
#ifdef HAVE_SOLARIS_ACLS |
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
int sys_acl_set_fd_type(int fd, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d) |
| 787 |
{ |
| 788 |
struct stat s; |
| 789 |
struct acl *acl_p; |
| 790 |
int acl_count; |
| 791 |
struct acl *acl_buf = NULL; |
| 792 |
int ret; |
| 793 |
|
| 794 |
if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { |
| 795 |
errno = EINVAL; |
| 796 |
return -1; |
| 797 |
} |
| 798 |
|
| 799 |
if (acl_sort(acl_d) != 0) { |
| 800 |
return -1; |
| 801 |
} |
| 802 |
|
| 803 |
acl_p = &acl_d->acl[0]; |
| 804 |
acl_count = acl_d->count; |
| 805 |
|
| 806 |
if (fstat(fd, &s) != 0) { |
| 807 |
return -1; |
| 808 |
} |
| 809 |
if (S_ISDIR(s.st_mode)) { |
| 810 |
SMB_ACL_T acc_acl; |
| 811 |
SMB_ACL_T def_acl; |
| 812 |
SMB_ACL_T tmp_acl; |
| 813 |
int i; |
| 814 |
|
| 815 |
if (type == SMB_ACL_TYPE_ACCESS) { |
| 816 |
acc_acl = acl_d; |
| 817 |
def_acl = tmp_acl = sys_acl_get_fd_type(fd, SMB_ACL_TYPE_DEFAULT); |
| 818 |
} else { |
| 819 |
def_acl = acl_d; |
| 820 |
acc_acl = tmp_acl = sys_acl_get_fd_type(fd, SMB_ACL_TYPE_ACCESS); |
| 821 |
} |
| 822 |
|
| 823 |
if (tmp_acl == NULL) { |
| 824 |
return -1; |
| 825 |
} |
| 826 |
|
| 827 |
acl_count = acc_acl->count + def_acl->count; |
| 828 |
acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count); |
| 829 |
|
| 830 |
if (acl_buf == NULL) { |
| 831 |
sys_acl_free_acl(tmp_acl); |
| 832 |
errno = ENOMEM; |
| 833 |
return -1; |
| 834 |
} |
| 835 |
|
| 836 |
|
| 837 |
memcpy(&acl_buf[0], &acc_acl->acl[0], |
| 838 |
acc_acl->count * sizeof acl_buf[0]); |
| 839 |
memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0], |
| 840 |
def_acl->count * sizeof acl_buf[0]); |
| 841 |
|
| 842 |
for (i = acc_acl->count; i < acl_count; i++) { |
| 843 |
acl_buf[i].a_type |= ACL_DEFAULT; |
| 844 |
} |
| 845 |
|
| 846 |
sys_acl_free_acl(tmp_acl); |
| 847 |
|
| 848 |
} else if (type != SMB_ACL_TYPE_ACCESS) { |
| 849 |
errno = EINVAL; |
| 850 |
return -1; |
| 851 |
} |
| 852 |
|
| 853 |
ret = facl(fd, SETACL, acl_count, acl_p); |
| 854 |
|
| 855 |
SAFE_FREE(acl_buf); |
| 856 |
|
| 857 |
return ret; |
| 858 |
} |
| 859 |
|
| 860 |
int sys_acl_set_fd(int fd, SMB_ACL_T acl_d) |
| 861 |
{ |
| 862 |
return sys_acl_set_fd_type(fd, SMB_ACL_TYPE_ACCESS, acl_d); |
| 863 |
} |
| 864 |
|
| 865 |
int sys_acl_delete_def_fd(int fd) |
| 866 |
{ |
| 867 |
SMB_ACL_T acl_d; |
| 868 |
int ret; |
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
if ((acl_d = sys_acl_get_fd_type(fd, SMB_ACL_TYPE_ACCESS)) == NULL) { |
| 875 |
return -1; |
| 876 |
} |
| 877 |
|
| 878 |
ret = facl(fd, SETACL, acl_d->count, acl_d->acl); |
| 879 |
|
| 880 |
sys_acl_free_acl(acl_d); |
| 881 |
|
| 882 |
return ret; |
| 883 |
} |
| 884 |
#endif |
| 885 |
|
| 886 |
int sys_acl_delete_def_file(const char *path) |
| 887 |
{ |
| 888 |
SMB_ACL_T acl_d; |
| 889 |
int ret; |
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) { |
| 896 |
return -1; |
| 897 |
} |
| 898 |
|
| 899 |
ret = acl(path, SETACL, acl_d->count, acl_d->acl); |
| 900 |
|
| 901 |
sys_acl_free_acl(acl_d); |
| 902 |
|
| 903 |
return ret; |
| 904 |
} |
| 905 |
|
| 906 |
int sys_acl_free_acl(SMB_ACL_T acl_d) |
| 907 |
{ |
| 908 |
SAFE_FREE(acl_d); |
| 909 |
return 0; |
| 910 |
} |
| 911 |
|
| 912 |
#elif defined(HAVE_HPUX_ACLS) |
| 913 |
|
| 914 |
#ifdef HAVE_DL_H |
| 915 |
#include <dl.h> |
| 916 |
#endif |
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
#ifdef __TANDEM |
| 945 |
inline int do_acl(const char *path_p, int cmd, int nentries, struct acl *aclbufp) |
| 946 |
{ |
| 947 |
return acl((char*)path_p, cmd, nentries, aclbufp); |
| 948 |
} |
| 949 |
#define acl(p,c,n,a) do_acl(p,c,n,a) |
| 950 |
#endif |
| 951 |
|
| 952 |
static BOOL hpux_acl_call_presence(void) |
| 953 |
{ |
| 954 |
#ifndef __TANDEM |
| 955 |
shl_t handle = NULL; |
| 956 |
void *value; |
| 957 |
int ret_val=0; |
| 958 |
static BOOL already_checked=0; |
| 959 |
|
| 960 |
if (already_checked) |
| 961 |
return True; |
| 962 |
|
| 963 |
ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value); |
| 964 |
|
| 965 |
if (ret_val != 0) { |
| 966 |
DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n", |
| 967 |
ret_val, errno, strerror(errno))); |
| 968 |
DEBUG(5, ("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n")); |
| 969 |
return False; |
| 970 |
} |
| 971 |
|
| 972 |
DEBUG(10, ("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n")); |
| 973 |
|
| 974 |
already_checked = True; |
| 975 |
#endif |
| 976 |
return True; |
| 977 |
} |
| 978 |
|
| 979 |
int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
| 980 |
{ |
| 981 |
if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) { |
| 982 |
errno = EINVAL; |
| 983 |
return -1; |
| 984 |
} |
| 985 |
|
| 986 |
if (entry_p == NULL) { |
| 987 |
errno = EINVAL; |
| 988 |
return -1; |
| 989 |
} |
| 990 |
|
| 991 |
if (entry_id == SMB_ACL_FIRST_ENTRY) { |
| 992 |
acl_d->next = 0; |
| 993 |
} |
| 994 |
|
| 995 |
if (acl_d->next < 0) { |
| 996 |
errno = EINVAL; |
| 997 |
return -1; |
| 998 |
} |
| 999 |
|
| 1000 |
if (acl_d->next >= acl_d->count) { |
| 1001 |
return 0; |
| 1002 |
} |
| 1003 |
|
| 1004 |
*entry_p = &acl_d->acl[acl_d->next++]; |
| 1005 |
|
| 1006 |
return 1; |
| 1007 |
} |
| 1008 |
|
| 1009 |
int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p) |
| 1010 |
{ |
| 1011 |
*type_p = entry_d->a_type; |
| 1012 |
|
| 1013 |
return 0; |
| 1014 |
} |
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
#define INITIAL_ACL_SIZE 16 |
| 1029 |
|
| 1030 |
#ifndef NACLENTRIES |
| 1031 |
#define NACLENTRIES 0 |
| 1032 |
#endif |
| 1033 |
|
| 1034 |
SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) |
| 1035 |
{ |
| 1036 |
SMB_ACL_T acl_d; |
| 1037 |
int count; |
| 1038 |
int naccess; |
| 1039 |
int ndefault; |
| 1040 |
|
| 1041 |
if (hpux_acl_call_presence() == False) { |
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
return NULL; |
| 1046 |
} |
| 1047 |
|
| 1048 |
if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { |
| 1049 |
errno = EINVAL; |
| 1050 |
return NULL; |
| 1051 |
} |
| 1052 |
|
| 1053 |
count = INITIAL_ACL_SIZE; |
| 1054 |
if ((acl_d = sys_acl_init(count)) == NULL) { |
| 1055 |
return NULL; |
| 1056 |
} |
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) { |
| 1067 |
|
| 1068 |
sys_acl_free_acl(acl_d); |
| 1069 |
|
| 1070 |
if ((count = acl(path_p, ACL_CNT, NACLENTRIES, NULL)) < 0) { |
| 1071 |
return NULL; |
| 1072 |
} |
| 1073 |
|
| 1074 |
if ((acl_d = sys_acl_init(count)) == NULL) { |
| 1075 |
return NULL; |
| 1076 |
} |
| 1077 |
} |
| 1078 |
|
| 1079 |
if (count < 0) { |
| 1080 |
sys_acl_free_acl(acl_d); |
| 1081 |
return NULL; |
| 1082 |
} |
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
for (naccess = 0; naccess < count; naccess++) { |
| 1092 |
if (acl_d->acl[naccess].a_type & ACL_DEFAULT) |
| 1093 |
break; |
| 1094 |
} |
| 1095 |
ndefault = count - naccess; |
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
if (type == SMB_ACL_TYPE_DEFAULT) { |
| 1103 |
int i, j; |
| 1104 |
|
| 1105 |
for (i = 0, j = naccess; i < ndefault; i++, j++) { |
| 1106 |
acl_d->acl[i] = acl_d->acl[j]; |
| 1107 |
acl_d->acl[i].a_type &= ~ACL_DEFAULT; |
| 1108 |
} |
| 1109 |
|
| 1110 |
acl_d->count = ndefault; |
| 1111 |
} else { |
| 1112 |
acl_d->count = naccess; |
| 1113 |
} |
| 1114 |
|
| 1115 |
return acl_d; |
| 1116 |
} |
| 1117 |
|
| 1118 |
#if 0 |
| 1119 |
SMB_ACL_T sys_acl_get_fd(int fd) |
| 1120 |
{ |
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
files_struct *fsp = file_find_fd(fd); |
| 1126 |
|
| 1127 |
if (fsp == NULL) { |
| 1128 |
errno = EBADF; |
| 1129 |
return NULL; |
| 1130 |
} |
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS); |
| 1138 |
} |
| 1139 |
#endif |
| 1140 |
|
| 1141 |
int sys_acl_get_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T *tag_type_p, uint32 *bits_p, id_t *u_g_id_p) |
| 1142 |
{ |
| 1143 |
*tag_type_p = entry->a_type; |
| 1144 |
|
| 1145 |
*bits_p = entry->a_perm; |
| 1146 |
|
| 1147 |
if (*tag_type_p == SMB_ACL_USER || *tag_type_p == SMB_ACL_GROUP) |
| 1148 |
*u_g_id_p = entry->a_id; |
| 1149 |
|
| 1150 |
return 0; |
| 1151 |
} |
| 1152 |
|
| 1153 |
SMB_ACL_T sys_acl_init(int count) |
| 1154 |
{ |
| 1155 |
SMB_ACL_T a; |
| 1156 |
|
| 1157 |
if (count < 0) { |
| 1158 |
errno = EINVAL; |
| 1159 |
return NULL; |
| 1160 |
} |
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof a[0] + count * sizeof (struct acl))) == NULL) { |
| 1169 |
errno = ENOMEM; |
| 1170 |
return NULL; |
| 1171 |
} |
| 1172 |
|
| 1173 |
a->size = count + 1; |
| 1174 |
a->count = 0; |
| 1175 |
a->next = -1; |
| 1176 |
|
| 1177 |
return a; |
| 1178 |
} |
| 1179 |
|
| 1180 |
|
| 1181 |
int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p) |
| 1182 |
{ |
| 1183 |
SMB_ACL_T acl_d; |
| 1184 |
SMB_ACL_ENTRY_T entry_d; |
| 1185 |
|
| 1186 |
if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) { |
| 1187 |
errno = EINVAL; |
| 1188 |
return -1; |
| 1189 |
} |
| 1190 |
|
| 1191 |
if (acl_d->count >= acl_d->size) { |
| 1192 |
errno = ENOSPC; |
| 1193 |
return -1; |
| 1194 |
} |
| 1195 |
|
| 1196 |
entry_d = &acl_d->acl[acl_d->count++]; |
| 1197 |
entry_d->a_type = 0; |
| 1198 |
entry_d->a_id = -1; |
| 1199 |
entry_d->a_perm = 0; |
| 1200 |
*entry_p = entry_d; |
| 1201 |
|
| 1202 |
return 0; |
| 1203 |
} |
| 1204 |
|
| 1205 |
int sys_acl_set_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tag_type, uint32 bits, id_t u_g_id) |
| 1206 |
{ |
| 1207 |
entry->a_type = tag_type; |
| 1208 |
|
| 1209 |
if (tag_type == SMB_ACL_USER || tag_type == SMB_ACL_GROUP) |
| 1210 |
entry->a_id = u_g_id; |
| 1211 |
|
| 1212 |
entry->a_perm = bits; |
| 1213 |
|
| 1214 |
return 0; |
| 1215 |
} |
| 1216 |
|
| 1217 |
int sys_acl_set_access_bits(SMB_ACL_ENTRY_T entry_d, uint32 bits) |
| 1218 |
{ |
| 1219 |
entry_d->a_perm = bits; |
| 1220 |
|
| 1221 |
return 0; |
| 1222 |
} |
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
struct hpux_acl_types { |
| 1227 |
int n_user; |
| 1228 |
int n_def_user; |
| 1229 |
int n_user_obj; |
| 1230 |
int n_def_user_obj; |
| 1231 |
|
| 1232 |
int n_group; |
| 1233 |
int n_def_group; |
| 1234 |
int n_group_obj; |
| 1235 |
int n_def_group_obj; |
| 1236 |
|
| 1237 |
int n_other; |
| 1238 |
int n_other_obj; |
| 1239 |
int n_def_other_obj; |
| 1240 |
|
| 1241 |
int n_class_obj; |
| 1242 |
int n_def_class_obj; |
| 1243 |
|
| 1244 |
int n_illegal_obj; |
| 1245 |
}; |
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
static void hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count) |
| 1263 |
{ |
| 1264 |
int i; |
| 1265 |
|
| 1266 |
memset(acl_type_count, 0, sizeof (struct hpux_acl_types)); |
| 1267 |
|
| 1268 |
for (i = 0; i < acl_count; i++) { |
| 1269 |
switch (aclp[i].a_type) { |
| 1270 |
case USER: |
| 1271 |
acl_type_count->n_user++; |
| 1272 |
break; |
| 1273 |
case USER_OBJ: |
| 1274 |
acl_type_count->n_user_obj++; |
| 1275 |
break; |
| 1276 |
case DEF_USER_OBJ: |
| 1277 |
acl_type_count->n_def_user_obj++; |
| 1278 |
break; |
| 1279 |
case GROUP: |
| 1280 |
acl_type_count->n_group++; |
| 1281 |
break; |
| 1282 |
case GROUP_OBJ: |
| 1283 |
acl_type_count->n_group_obj++; |
| 1284 |
break; |
| 1285 |
case DEF_GROUP_OBJ: |
| 1286 |
acl_type_count->n_def_group_obj++; |
| 1287 |
break; |
| 1288 |
case OTHER_OBJ: |
| 1289 |
acl_type_count->n_other_obj++; |
| 1290 |
break; |
| 1291 |
case DEF_OTHER_OBJ: |
| 1292 |
acl_type_count->n_def_other_obj++; |
| 1293 |
break; |
| 1294 |
case CLASS_OBJ: |
| 1295 |
acl_type_count->n_class_obj++; |
| 1296 |
break; |
| 1297 |
case DEF_CLASS_OBJ: |
| 1298 |
acl_type_count->n_def_class_obj++; |
| 1299 |
break; |
| 1300 |
case DEF_USER: |
| 1301 |
acl_type_count->n_def_user++; |
| 1302 |
break; |
| 1303 |
case DEF_GROUP: |
| 1304 |
acl_type_count->n_def_group++; |
| 1305 |
break; |
| 1306 |
default: |
| 1307 |
acl_type_count->n_illegal_obj++; |
| 1308 |
break; |
| 1309 |
} |
| 1310 |
} |
| 1311 |
} |
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1) |
| 1319 |
{ |
| 1320 |
struct acl temp_acl; |
| 1321 |
|
| 1322 |
temp_acl.a_type = aclp0->a_type; |
| 1323 |
temp_acl.a_id = aclp0->a_id; |
| 1324 |
temp_acl.a_perm = aclp0->a_perm; |
| 1325 |
|
| 1326 |
aclp0->a_type = aclp1->a_type; |
| 1327 |
aclp0->a_id = aclp1->a_id; |
| 1328 |
aclp0->a_perm = aclp1->a_perm; |
| 1329 |
|
| 1330 |
aclp1->a_type = temp_acl.a_type; |
| 1331 |
aclp1->a_id = temp_acl.a_id; |
| 1332 |
aclp1->a_perm = temp_acl.a_perm; |
| 1333 |
} |
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
static BOOL hpux_prohibited_duplicate_type(int acl_type) |
| 1350 |
{ |
| 1351 |
switch (acl_type) { |
| 1352 |
case USER: |
| 1353 |
case GROUP: |
| 1354 |
case DEF_USER: |
| 1355 |
case DEF_GROUP: |
| 1356 |
return True; |
| 1357 |
default: |
| 1358 |
return False; |
| 1359 |
} |
| 1360 |
} |
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
static int hpux_get_needed_class_perm(struct acl *aclp) |
| 1371 |
{ |
| 1372 |
switch (aclp->a_type) { |
| 1373 |
case USER: |
| 1374 |
case GROUP_OBJ: |
| 1375 |
case GROUP: |
| 1376 |
case DEF_USER_OBJ: |
| 1377 |
case DEF_USER: |
| 1378 |
case DEF_GROUP_OBJ: |
| 1379 |
case DEF_GROUP: |
| 1380 |
case DEF_CLASS_OBJ: |
| 1381 |
case DEF_OTHER_OBJ: |
| 1382 |
return aclp->a_perm; |
| 1383 |
default: |
| 1384 |
return 0; |
| 1385 |
} |
| 1386 |
} |
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp) |
| 1410 |
{ |
| 1411 |
#if !defined(HAVE_HPUX_ACLSORT) |
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
struct hpux_acl_types acl_obj_count; |
| 1420 |
int n_class_obj_perm = 0; |
| 1421 |
int i, j; |
| 1422 |
|
| 1423 |
if (!acl_count) { |
| 1424 |
DEBUG(10, ("Zero acl count passed. Returning Success\n")); |
| 1425 |
return 0; |
| 1426 |
} |
| 1427 |
|
| 1428 |
if (aclp == NULL) { |
| 1429 |
DEBUG(0, ("Null ACL pointer in hpux_acl_sort. Returning Failure. \n")); |
| 1430 |
return -1; |
| 1431 |
} |
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
hpux_count_obj(acl_count, aclp, &acl_obj_count); |
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
if (acl_obj_count.n_user_obj != 1 |
| 1442 |
|| acl_obj_count.n_group_obj != 1 |
| 1443 |
|| acl_obj_count.n_class_obj != 1 |
| 1444 |
|| acl_obj_count.n_other_obj != 1) { |
| 1445 |
DEBUG(0, ("hpux_acl_sort: More than one entry or no entries for \ |
| 1446 |
USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n")); |
| 1447 |
return -1; |
| 1448 |
} |
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
if (acl_obj_count.n_def_user_obj > 1 || acl_obj_count.n_def_group_obj > 1 |
| 1454 |
|| acl_obj_count.n_def_other_obj > 1 || acl_obj_count.n_def_class_obj > 1) { |
| 1455 |
DEBUG(0, ("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \ |
| 1456 |
or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n")); |
| 1457 |
return -1; |
| 1458 |
} |
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
for (i = 0; i < acl_count; i++) { |
| 1472 |
for (j = i+1; j < acl_count; j++) { |
| 1473 |
if (aclp[i].a_type > aclp[j].a_type) { |
| 1474 |
|
| 1475 |
hpux_swap_acl_entries((aclp+i), (aclp+j)); |
| 1476 |
} else if (aclp[i].a_type == aclp[j].a_type) { |
| 1477 |
|
| 1478 |
if (aclp[i].a_id > aclp[j].a_id) { |
| 1479 |
hpux_swap_acl_entries((aclp+i), (aclp+j)); |
| 1480 |
} else if (aclp[i].a_id == aclp[j].a_id) { |
| 1481 |
|
| 1482 |
if (hpux_prohibited_duplicate_type(aclp[i].a_type)) { |
| 1483 |
DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n", |
| 1484 |
aclp[i].a_type, aclp[i].a_id)); |
| 1485 |
return -1; |
| 1486 |
} |
| 1487 |
} |
| 1488 |
} |
| 1489 |
} |
| 1490 |
} |
| 1491 |
|
| 1492 |
|
| 1493 |
if (calclass) { |
| 1494 |
int n_class_obj_index = -1; |
| 1495 |
|
| 1496 |
for (i = 0;i < acl_count; i++) { |
| 1497 |
n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i)); |
| 1498 |
if (aclp[i].a_type == CLASS_OBJ) |
| 1499 |
n_class_obj_index = i; |
| 1500 |
} |
| 1501 |
aclp[n_class_obj_index].a_perm = n_class_obj_perm; |
| 1502 |
} |
| 1503 |
|
| 1504 |
return 0; |
| 1505 |
#else |
| 1506 |
return aclsort(acl_count, calclass, aclp); |
| 1507 |
#endif |
| 1508 |
} |
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
static int acl_sort(SMB_ACL_T acl_d) |
| 1528 |
{ |
| 1529 |
int fixmask = (acl_d->count <= 4); |
| 1530 |
|
| 1531 |
if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) { |
| 1532 |
errno = EINVAL; |
| 1533 |
return -1; |
| 1534 |
} |
| 1535 |
return 0; |
| 1536 |
} |
| 1537 |
|
| 1538 |
int sys_acl_valid(SMB_ACL_T acl_d) |
| 1539 |
{ |
| 1540 |
return acl_sort(acl_d); |
| 1541 |
} |
| 1542 |
|
| 1543 |
int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d) |
| 1544 |
{ |
| 1545 |
struct stat s; |
| 1546 |
struct acl *acl_p; |
| 1547 |
int acl_count; |
| 1548 |
struct acl *acl_buf = NULL; |
| 1549 |
int ret; |
| 1550 |
|
| 1551 |
if (hpux_acl_call_presence() == False) { |
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
errno=ENOSYS; |
| 1556 |
return -1; |
| 1557 |
} |
| 1558 |
|
| 1559 |
if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { |
| 1560 |
errno = EINVAL; |
| 1561 |
return -1; |
| 1562 |
} |
| 1563 |
|
| 1564 |
if (acl_sort(acl_d) != 0) { |
| 1565 |
return -1; |
| 1566 |
} |
| 1567 |
|
| 1568 |
acl_p = &acl_d->acl[0]; |
| 1569 |
acl_count = acl_d->count; |
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
if (stat(name, &s) != 0) { |
| 1577 |
return -1; |
| 1578 |
} |
| 1579 |
if (S_ISDIR(s.st_mode)) { |
| 1580 |
SMB_ACL_T acc_acl; |
| 1581 |
SMB_ACL_T def_acl; |
| 1582 |
SMB_ACL_T tmp_acl; |
| 1583 |
int i; |
| 1584 |
|
| 1585 |
if (type == SMB_ACL_TYPE_ACCESS) { |
| 1586 |
acc_acl = acl_d; |
| 1587 |
def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT); |
| 1588 |
|
| 1589 |
} else { |
| 1590 |
def_acl = acl_d; |
| 1591 |
acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS); |
| 1592 |
} |
| 1593 |
|
| 1594 |
if (tmp_acl == NULL) { |
| 1595 |
return -1; |
| 1596 |
} |
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
acl_count = acc_acl->count + def_acl->count; |
| 1602 |
acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count); |
| 1603 |
|
| 1604 |
if (acl_buf == NULL) { |
| 1605 |
sys_acl_free_acl(tmp_acl); |
| 1606 |
errno = ENOMEM; |
| 1607 |
return -1; |
| 1608 |
} |
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
|
| 1613 |
memcpy(&acl_buf[0], &acc_acl->acl[0], |
| 1614 |
acc_acl->count * sizeof acl_buf[0]); |
| 1615 |
|
| 1616 |
memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0], |
| 1617 |
def_acl->count * sizeof acl_buf[0]); |
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
for (i = acc_acl->count; i < acl_count; i++) { |
| 1623 |
acl_buf[i].a_type |= ACL_DEFAULT; |
| 1624 |
} |
| 1625 |
|
| 1626 |
sys_acl_free_acl(tmp_acl); |
| 1627 |
|
| 1628 |
} else if (type != SMB_ACL_TYPE_ACCESS) { |
| 1629 |
errno = EINVAL; |
| 1630 |
return -1; |
| 1631 |
} |
| 1632 |
|
| 1633 |
ret = acl(name, ACL_SET, acl_count, acl_p); |
| 1634 |
|
| 1635 |
if (acl_buf) { |
| 1636 |
free(acl_buf); |
| 1637 |
} |
| 1638 |
|
| 1639 |
return ret; |
| 1640 |
} |
| 1641 |
|
| 1642 |
#if 0 |
| 1643 |
int sys_acl_set_fd(int fd, SMB_ACL_T acl_d) |
| 1644 |
{ |
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
files_struct *fsp = file_find_fd(fd); |
| 1650 |
|
| 1651 |
if (fsp == NULL) { |
| 1652 |
errno = EBADF; |
| 1653 |
return NULL; |
| 1654 |
} |
| 1655 |
|
| 1656 |
if (acl_sort(acl_d) != 0) { |
| 1657 |
return -1; |
| 1658 |
} |
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d); |
| 1666 |
} |
| 1667 |
#endif |
| 1668 |
|
| 1669 |
int sys_acl_delete_def_file(const char *path) |
| 1670 |
{ |
| 1671 |
SMB_ACL_T acl_d; |
| 1672 |
int ret; |
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) { |
| 1679 |
return -1; |
| 1680 |
} |
| 1681 |
|
| 1682 |
ret = acl(path, ACL_SET, acl_d->count, acl_d->acl); |
| 1683 |
|
| 1684 |
sys_acl_free_acl(acl_d); |
| 1685 |
|
| 1686 |
return ret; |
| 1687 |
} |
| 1688 |
|
| 1689 |
int sys_acl_free_acl(SMB_ACL_T acl_d) |
| 1690 |
{ |
| 1691 |
free(acl_d); |
| 1692 |
return 0; |
| 1693 |
} |
| 1694 |
|
| 1695 |
#elif defined(HAVE_IRIX_ACLS) |
| 1696 |
|
| 1697 |
int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
| 1698 |
{ |
| 1699 |
if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) { |
| 1700 |
errno = EINVAL; |
| 1701 |
return -1; |
| 1702 |
} |
| 1703 |
|
| 1704 |
if (entry_p == NULL) { |
| 1705 |
errno = EINVAL; |
| 1706 |
return -1; |
| 1707 |
} |
| 1708 |
|
| 1709 |
if (entry_id == SMB_ACL_FIRST_ENTRY) { |
| 1710 |
acl_d->next = 0; |
| 1711 |
} |
| 1712 |
|
| 1713 |
if (acl_d->next < 0) { |
| 1714 |
errno = EINVAL; |
| 1715 |
return -1; |
| 1716 |
} |
| 1717 |
|
| 1718 |
if (acl_d->next >= acl_d->aclp->acl_cnt) { |
| 1719 |
return 0; |
| 1720 |
} |
| 1721 |
|
| 1722 |
*entry_p = &acl_d->aclp->acl_entry[acl_d->next++]; |
| 1723 |
|
| 1724 |
return 1; |
| 1725 |
} |
| 1726 |
|
| 1727 |
int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p) |
| 1728 |
{ |
| 1729 |
*type_p = entry_d->ae_tag; |
| 1730 |
|
| 1731 |
return 0; |
| 1732 |
} |
| 1733 |
|
| 1734 |
SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) |
| 1735 |
{ |
| 1736 |
SMB_ACL_T a; |
| 1737 |
|
| 1738 |
if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) { |
| 1739 |
errno = ENOMEM; |
| 1740 |
return NULL; |
| 1741 |
} |
| 1742 |
if ((a->aclp = acl_get_file(path_p, type)) == NULL) { |
| 1743 |
SAFE_FREE(a); |
| 1744 |
return NULL; |
| 1745 |
} |
| 1746 |
a->next = -1; |
| 1747 |
a->freeaclp = True; |
| 1748 |
return a; |
| 1749 |
} |
| 1750 |
|
| 1751 |
#if 0 |
| 1752 |
SMB_ACL_T sys_acl_get_fd(int fd) |
| 1753 |
{ |
| 1754 |
SMB_ACL_T a; |
| 1755 |
|
| 1756 |
if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) { |
| 1757 |
errno = ENOMEM; |
| 1758 |
return NULL; |
| 1759 |
} |
| 1760 |
if ((a->aclp = acl_get_fd(fd)) == NULL) { |
| 1761 |
SAFE_FREE(a); |
| 1762 |
return NULL; |
| 1763 |
} |
| 1764 |
a->next = -1; |
| 1765 |
a->freeaclp = True; |
| 1766 |
return a; |
| 1767 |
} |
| 1768 |
#endif |
| 1769 |
|
| 1770 |
int sys_acl_get_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T *tag_type_p, uint32 *bits_p, id_t *u_g_id_p) |
| 1771 |
{ |
| 1772 |
*tag_type_p = entry->ae_tag; |
| 1773 |
|
| 1774 |
*bits_p = entry->ae_perm; |
| 1775 |
|
| 1776 |
if (*tag_type_p == SMB_ACL_USER || *tag_type_p == SMB_ACL_GROUP) |
| 1777 |
*u_g_id_p = entry->ae_id; |
| 1778 |
|
| 1779 |
return 0; |
| 1780 |
} |
| 1781 |
|
| 1782 |
SMB_ACL_T sys_acl_init(int count) |
| 1783 |
{ |
| 1784 |
SMB_ACL_T a; |
| 1785 |
|
| 1786 |
if (count < 0) { |
| 1787 |
errno = EINVAL; |
| 1788 |
return NULL; |
| 1789 |
} |
| 1790 |
|
| 1791 |
if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof a[0] + sizeof (struct acl))) == NULL) { |
| 1792 |
errno = ENOMEM; |
| 1793 |
return NULL; |
| 1794 |
} |
| 1795 |
|
| 1796 |
a->next = -1; |
| 1797 |
a->freeaclp = False; |
| 1798 |
a->aclp = (struct acl *)((char *)a + sizeof a[0]); |
| 1799 |
a->aclp->acl_cnt = 0; |
| 1800 |
|
| 1801 |
return a; |
| 1802 |
} |
| 1803 |
|
| 1804 |
|
| 1805 |
int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p) |
| 1806 |
{ |
| 1807 |
SMB_ACL_T acl_d; |
| 1808 |
SMB_ACL_ENTRY_T entry_d; |
| 1809 |
|
| 1810 |
if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) { |
| 1811 |
errno = EINVAL; |
| 1812 |
return -1; |
| 1813 |
} |
| 1814 |
|
| 1815 |
if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) { |
| 1816 |
errno = ENOSPC; |
| 1817 |
return -1; |
| 1818 |
} |
| 1819 |
|
| 1820 |
entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++]; |
| 1821 |
entry_d->ae_tag = 0; |
| 1822 |
entry_d->ae_id = 0; |
| 1823 |
entry_d->ae_perm = 0; |
| 1824 |
*entry_p = entry_d; |
| 1825 |
|
| 1826 |
return 0; |
| 1827 |
} |
| 1828 |
|
| 1829 |
int sys_acl_set_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tag_type, uint32 bits, id_t u_g_id) |
| 1830 |
{ |
| 1831 |
entry->ae_tag = tag_type; |
| 1832 |
|
| 1833 |
if (tag_type == SMB_ACL_USER || tag_type == SMB_ACL_GROUP) |
| 1834 |
entry->ae_id = u_g_id; |
| 1835 |
|
| 1836 |
entry->ae_perm = bits; |
| 1837 |
|
| 1838 |
return 0; |
| 1839 |
} |
| 1840 |
|
| 1841 |
int sys_acl_set_access_bits(SMB_ACL_ENTRY_T entry_d, uint32 bits) |
| 1842 |
{ |
| 1843 |
entry_d->ae_perm = bits; |
| 1844 |
|
| 1845 |
return 0; |
| 1846 |
} |
| 1847 |
|
| 1848 |
int sys_acl_valid(SMB_ACL_T acl_d) |
| 1849 |
{ |
| 1850 |
return acl_valid(acl_d->aclp); |
| 1851 |
} |
| 1852 |
|
| 1853 |
int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d) |
| 1854 |
{ |
| 1855 |
return acl_set_file(name, type, acl_d->aclp); |
| 1856 |
} |
| 1857 |
|
| 1858 |
#if 0 |
| 1859 |
int sys_acl_set_fd(int fd, SMB_ACL_T acl_d) |
| 1860 |
{ |
| 1861 |
return acl_set_fd(fd, acl_d->aclp); |
| 1862 |
} |
| 1863 |
#endif |
| 1864 |
|
| 1865 |
int sys_acl_delete_def_file(const char *name) |
| 1866 |
{ |
| 1867 |
return acl_delete_def_file(name); |
| 1868 |
} |
| 1869 |
|
| 1870 |
int sys_acl_free_acl(SMB_ACL_T acl_d) |
| 1871 |
{ |
| 1872 |
if (acl_d->freeaclp) { |
| 1873 |
acl_free(acl_d->aclp); |
| 1874 |
} |
| 1875 |
acl_free(acl_d); |
| 1876 |
return 0; |
| 1877 |
} |
| 1878 |
|
| 1879 |
#elif defined(HAVE_AIX_ACLS) |
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
int sys_acl_get_entry(SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
| 1884 |
{ |
| 1885 |
struct acl_entry_link *link; |
| 1886 |
int keep_going; |
| 1887 |
|
| 1888 |
if (entry_id == SMB_ACL_FIRST_ENTRY) |
| 1889 |
theacl->count = 0; |
| 1890 |
else if (entry_id != SMB_ACL_NEXT_ENTRY) { |
| 1891 |
errno = EINVAL; |
| 1892 |
return -1; |
| 1893 |
} |
| 1894 |
|
| 1895 |
DEBUG(10, ("This is the count: %d\n", theacl->count)); |
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
if (theacl->count == -1) |
| 1901 |
return 0; |
| 1902 |
|
| 1903 |
link = theacl; |
| 1904 |
|
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
for (keep_going = 0; keep_going < theacl->count; keep_going++) |
| 1909 |
link = link->nextp; |
| 1910 |
|
| 1911 |
*entry_p = link->entryp; |
| 1912 |
|
| 1913 |
#if 0 |
| 1914 |
{ |
| 1915 |
struct new_acl_entry *entry = *entry_p; |
| 1916 |
DEBUG(10, ("*entry_p is %lx\n", (long)entry)); |
| 1917 |
DEBUG(10, ("*entry_p->ace_access is %d\n", entry->ace_access)); |
| 1918 |
} |
| 1919 |
#endif |
| 1920 |
|
| 1921 |
|
| 1922 |
theacl->count++; |
| 1923 |
if (link->nextp == NULL) |
| 1924 |
theacl->count = -1; |
| 1925 |
|
| 1926 |
return 1; |
| 1927 |
} |
| 1928 |
|
| 1929 |
int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) |
| 1930 |
{ |
| 1931 |
|
| 1932 |
|
| 1933 |
*tag_type_p = -1; |
| 1934 |
DEBUG(10, ("the tagtype is %d\n", entry_d->ace_id->id_type)); |
| 1935 |
|
| 1936 |
|
| 1937 |
|
| 1938 |
switch (entry_d->ace_id->id_type) { |
| 1939 |
case ACEID_USER: |
| 1940 |
*tag_type_p = SMB_ACL_USER; |
| 1941 |
break; |
| 1942 |
case ACEID_GROUP: |
| 1943 |
*tag_type_p = SMB_ACL_GROUP; |
| 1944 |
break; |
| 1945 |
|
| 1946 |
case SMB_ACL_USER_OBJ: |
| 1947 |
case SMB_ACL_GROUP_OBJ: |
| 1948 |
case SMB_ACL_OTHER: |
| 1949 |
*tag_type_p = entry_d->ace_id->id_type; |
| 1950 |
break; |
| 1951 |
|
| 1952 |
default: |
| 1953 |
return -1; |
| 1954 |
} |
| 1955 |
|
| 1956 |
return 0; |
| 1957 |
} |
| 1958 |
|
| 1959 |
SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) |
| 1960 |
{ |
| 1961 |
struct acl *file_acl = (struct acl *)NULL; |
| 1962 |
struct acl_entry *acl_entry; |
| 1963 |
struct new_acl_entry *new_acl_entry; |
| 1964 |
struct ace_id *idp; |
| 1965 |
struct acl_entry_link *acl_entry_link; |
| 1966 |
struct acl_entry_link *acl_entry_link_head; |
| 1967 |
int i; |
| 1968 |
int rc = 0; |
| 1969 |
|
| 1970 |
|
| 1971 |
if (type == SMB_ACL_TYPE_DEFAULT) { |
| 1972 |
#ifdef ENOTSUP |
| 1973 |
errno = ENOTSUP; |
| 1974 |
#else |
| 1975 |
errno = ENOSYS; |
| 1976 |
#endif |
| 1977 |
return NULL; |
| 1978 |
} |
| 1979 |
|
| 1980 |
|
| 1981 |
|
| 1982 |
DEBUG(10, ("Entering sys_acl_get_file\n")); |
| 1983 |
DEBUG(10, ("path_p is %s\n", path_p)); |
| 1984 |
|
| 1985 |
file_acl = (struct acl *)SMB_MALLOC(BUFSIZ); |
| 1986 |
|
| 1987 |
if (file_acl == NULL) { |
| 1988 |
errno=ENOMEM; |
| 1989 |
DEBUG(0, ("Error in AIX sys_acl_get_file: %d\n", errno)); |
| 1990 |
return NULL; |
| 1991 |
} |
| 1992 |
|
| 1993 |
memset(file_acl, 0, BUFSIZ); |
| 1994 |
|
| 1995 |
rc = statacl((char *)path_p, 0, file_acl, BUFSIZ); |
| 1996 |
if (rc == -1) { |
| 1997 |
DEBUG(0, ("statacl returned %d with errno %d\n", rc, errno)); |
| 1998 |
SAFE_FREE(file_acl); |
| 1999 |
return NULL; |
| 2000 |
} |
| 2001 |
|
| 2002 |
DEBUG(10, ("Got facl and returned it\n")); |
| 2003 |
|
| 2004 |
|
| 2005 |
acl_entry = file_acl->acl_ext; |
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 2012 |
acl_entry_link_head = acl_entry_link = sys_acl_init(0); |
| 2013 |
if (acl_entry_link_head == NULL) |
| 2014 |
return NULL; |
| 2015 |
|
| 2016 |
acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
| 2017 |
if (acl_entry_link->entryp == NULL) { |
| 2018 |
SAFE_FREE(file_acl); |
| 2019 |
errno = ENOMEM; |
| 2020 |
DEBUG(0, ("Error in AIX sys_acl_get_file is %d\n", errno)); |
| 2021 |
return NULL; |
| 2022 |
} |
| 2023 |
|
| 2024 |
DEBUG(10, ("acl_entry is %d\n", acl_entry)); |
| 2025 |
DEBUG(10, ("acl_last(file_acl) id %d\n", acl_last(file_acl))); |
| 2026 |
|
| 2027 |
|
| 2028 |
|
| 2029 |
|
| 2030 |
|
| 2031 |
|
| 2032 |
if (file_acl->acl_mode & S_IXACL){ |
| 2033 |
|
| 2034 |
while (acl_entry < acl_last(file_acl)) { |
| 2035 |
|
| 2036 |
|
| 2037 |
idp = id_nxt(acl_entry->ace_id); |
| 2038 |
if ((acl_entry->ace_type == ACC_SPECIFY || acl_entry->ace_type == ACC_PERMIT) |
| 2039 |
&& idp != id_last(acl_entry)) { |
| 2040 |
acl_entry = acl_nxt(acl_entry); |
| 2041 |
continue; |
| 2042 |
} |
| 2043 |
|
| 2044 |
idp = acl_entry->ace_id; |
| 2045 |
|
| 2046 |
|
| 2047 |
|
| 2048 |
|
| 2049 |
|
| 2050 |
if (acl_entry_link_head->count != 0) { |
| 2051 |
acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link); |
| 2052 |
|
| 2053 |
if (acl_entry_link->nextp == NULL) { |
| 2054 |
SAFE_FREE(file_acl); |
| 2055 |
errno = ENOMEM; |
| 2056 |
DEBUG(0, ("Error in AIX sys_acl_get_file is %d\n", errno)); |
| 2057 |
return NULL; |
| 2058 |
} |
| 2059 |
|
| 2060 |
acl_entry_link->nextp->prevp = acl_entry_link; |
| 2061 |
acl_entry_link = acl_entry_link->nextp; |
| 2062 |
acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
| 2063 |
if (acl_entry_link->entryp == NULL) { |
| 2064 |
SAFE_FREE(file_acl); |
| 2065 |
errno = ENOMEM; |
| 2066 |
DEBUG(0, ("Error in AIX sys_acl_get_file is %d\n", errno)); |
| 2067 |
return NULL; |
| 2068 |
} |
| 2069 |
acl_entry_link->nextp = NULL; |
| 2070 |
} |
| 2071 |
|
| 2072 |
acl_entry_link->entryp->ace_len = acl_entry->ace_len; |
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
acl_entry_link->entryp->ace_type = acl_entry->ace_type; |
| 2078 |
|
| 2079 |
acl_entry_link->entryp->ace_access = acl_entry->ace_access; |
| 2080 |
|
| 2081 |
memcpy(acl_entry_link->entryp->ace_id, idp, sizeof (struct ace_id)); |
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
|
| 2087 |
switch (acl_entry->ace_type){ |
| 2088 |
case ACC_PERMIT: |
| 2089 |
case ACC_SPECIFY: |
| 2090 |
acl_entry_link->entryp->ace_access = acl_entry->ace_access; |
| 2091 |
acl_entry_link->entryp->ace_access <<= 6; |
| 2092 |
acl_entry_link_head->count++; |
| 2093 |
break; |
| 2094 |
case ACC_DENY: |
| 2095 |
|
| 2096 |
|
| 2097 |
DEBUG(10, ("acl_entry->ace_access is %d\n", acl_entry->ace_access)); |
| 2098 |
acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7; |
| 2099 |
DEBUG(10, ("acl_entry_link->entryp->ace_access is %d\n", acl_entry_link->entryp->ace_access)); |
| 2100 |
acl_entry_link->entryp->ace_access <<= 6; |
| 2101 |
acl_entry_link_head->count++; |
| 2102 |
break; |
| 2103 |
default: |
| 2104 |
return 0; |
| 2105 |
} |
| 2106 |
|
| 2107 |
DEBUG(10, ("acl_entry = %d\n", acl_entry)); |
| 2108 |
DEBUG(10, ("The ace_type is %d\n", acl_entry->ace_type)); |
| 2109 |
|
| 2110 |
acl_entry = acl_nxt(acl_entry); |
| 2111 |
} |
| 2112 |
} |
| 2113 |
|
| 2114 |
|
| 2115 |
|
| 2116 |
|
| 2117 |
|
| 2118 |
for (i = 1; i < 4; i++) { |
| 2119 |
DEBUG(10, ("i is %d\n", i)); |
| 2120 |
if (acl_entry_link_head->count != 0) { |
| 2121 |
acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link); |
| 2122 |
if (acl_entry_link->nextp == NULL) { |
| 2123 |
SAFE_FREE(file_acl); |
| 2124 |
errno = ENOMEM; |
| 2125 |
DEBUG(0, ("Error in AIX sys_acl_get_file is %d\n", errno)); |
| 2126 |
return NULL; |
| 2127 |
} |
| 2128 |
|
| 2129 |
acl_entry_link->nextp->prevp = acl_entry_link; |
| 2130 |
acl_entry_link = acl_entry_link->nextp; |
| 2131 |
acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
| 2132 |
if (acl_entry_link->entryp == NULL) { |
| 2133 |
SAFE_FREE(file_acl); |
| 2134 |
errno = ENOMEM; |
| 2135 |
DEBUG(0, ("Error in AIX sys_acl_get_file is %d\n", errno)); |
| 2136 |
return NULL; |
| 2137 |
} |
| 2138 |
} |
| 2139 |
|
| 2140 |
acl_entry_link->nextp = NULL; |
| 2141 |
|
| 2142 |
new_acl_entry = acl_entry_link->entryp; |
| 2143 |
idp = new_acl_entry->ace_id; |
| 2144 |
|
| 2145 |
new_acl_entry->ace_len = sizeof (struct acl_entry); |
| 2146 |
new_acl_entry->ace_type = ACC_PERMIT; |
| 2147 |
idp->id_len = sizeof (struct ace_id); |
| 2148 |
DEBUG(10, ("idp->id_len = %d\n", idp->id_len)); |
| 2149 |
memset(idp->id_data, 0, sizeof (uid_t)); |
| 2150 |
|
| 2151 |
switch (i) { |
| 2152 |
case 2: |
| 2153 |
new_acl_entry->ace_access = file_acl->g_access << 6; |
| 2154 |
idp->id_type = SMB_ACL_GROUP_OBJ; |
| 2155 |
break; |
| 2156 |
|
| 2157 |
case 3: |
| 2158 |
new_acl_entry->ace_access = file_acl->o_access << 6; |
| 2159 |
idp->id_type = SMB_ACL_OTHER; |
| 2160 |
break; |
| 2161 |
|
| 2162 |
case 1: |
| 2163 |
new_acl_entry->ace_access = file_acl->u_access << 6; |
| 2164 |
idp->id_type = SMB_ACL_USER_OBJ; |
| 2165 |
break; |
| 2166 |
|
| 2167 |
default: |
| 2168 |
return NULL; |
| 2169 |
|
| 2170 |
} |
| 2171 |
|
| 2172 |
acl_entry_link_head->count++; |
| 2173 |
DEBUG(10, ("new_acl_entry->ace_access = %d\n", new_acl_entry->ace_access)); |
| 2174 |
} |
| 2175 |
|
| 2176 |
acl_entry_link_head->count = 0; |
| 2177 |
SAFE_FREE(file_acl); |
| 2178 |
|
| 2179 |
return acl_entry_link_head; |
| 2180 |
} |
| 2181 |
|
| 2182 |
#if 0 |
| 2183 |
SMB_ACL_T sys_acl_get_fd(int fd) |
| 2184 |
{ |
| 2185 |
struct acl *file_acl = (struct acl *)NULL; |
| 2186 |
struct acl_entry *acl_entry; |
| 2187 |
struct new_acl_entry *new_acl_entry; |
| 2188 |
struct ace_id *idp; |
| 2189 |
struct acl_entry_link *acl_entry_link; |
| 2190 |
struct acl_entry_link *acl_entry_link_head; |
| 2191 |
int i; |
| 2192 |
int rc = 0; |
| 2193 |
|
| 2194 |
|
| 2195 |
|
| 2196 |
DEBUG(10, ("Entering sys_acl_get_fd\n")); |
| 2197 |
DEBUG(10, ("fd is %d\n", fd)); |
| 2198 |
file_acl = (struct acl *)SMB_MALLOC(BUFSIZ); |
| 2199 |
|
| 2200 |
if (file_acl == NULL) { |
| 2201 |
errno=ENOMEM; |
| 2202 |
DEBUG(0, ("Error in sys_acl_get_fd is %d\n", errno)); |
| 2203 |
return NULL; |
| 2204 |
} |
| 2205 |
|
| 2206 |
memset(file_acl, 0, BUFSIZ); |
| 2207 |
|
| 2208 |
rc = fstatacl(fd, 0, file_acl, BUFSIZ); |
| 2209 |
if (rc == -1) { |
| 2210 |
DEBUG(0, ("The fstatacl call returned %d with errno %d\n", rc, errno)); |
| 2211 |
SAFE_FREE(file_acl); |
| 2212 |
return NULL; |
| 2213 |
} |
| 2214 |
|
| 2215 |
DEBUG(10, ("Got facl and returned it\n")); |
| 2216 |
|
| 2217 |
|
| 2218 |
|
| 2219 |
acl_entry = file_acl->acl_ext; |
| 2220 |
|
| 2221 |
|
| 2222 |
|
| 2223 |
|
| 2224 |
|
| 2225 |
acl_entry_link_head = acl_entry_link = sys_acl_init(0); |
| 2226 |
if (acl_entry_link_head == NULL){ |
| 2227 |
SAFE_FREE(file_acl); |
| 2228 |
return NULL; |
| 2229 |
} |
| 2230 |
|
| 2231 |
acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
| 2232 |
|
| 2233 |
if (acl_entry_link->entryp == NULL) { |
| 2234 |
errno = ENOMEM; |
| 2235 |
DEBUG(0, ("Error in sys_acl_get_fd is %d\n", errno)); |
| 2236 |
SAFE_FREE(file_acl); |
| 2237 |
return NULL; |
| 2238 |
} |
| 2239 |
|
| 2240 |
DEBUG(10, ("acl_entry is %d\n", acl_entry)); |
| 2241 |
DEBUG(10, ("acl_last(file_acl) id %d\n", acl_last(file_acl))); |
| 2242 |
|
| 2243 |
|
| 2244 |
|
| 2245 |
|
| 2246 |
|
| 2247 |
|
| 2248 |
if (file_acl->acl_mode & S_IXACL){ |
| 2249 |
|
| 2250 |
while (acl_entry < acl_last(file_acl)) { |
| 2251 |
|
| 2252 |
|
| 2253 |
|
| 2254 |
idp = id_nxt(acl_entry->ace_id); |
| 2255 |
if ((acl_entry->ace_type == ACC_SPECIFY || |
| 2256 |
(acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) { |
| 2257 |
acl_entry = acl_nxt(acl_entry); |
| 2258 |
continue; |
| 2259 |
} |
| 2260 |
|
| 2261 |
idp = acl_entry->ace_id; |
| 2262 |
|
| 2263 |
|
| 2264 |
|
| 2265 |
|
| 2266 |
|
| 2267 |
if (acl_entry_link_head->count != 0) { |
| 2268 |
acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link); |
| 2269 |
if (acl_entry_link->nextp == NULL) { |
| 2270 |
errno = ENOMEM; |
| 2271 |
DEBUG(0, ("Error in sys_acl_get_fd is %d\n", errno)); |
| 2272 |
SAFE_FREE(file_acl); |
| 2273 |
return NULL; |
| 2274 |
} |
| 2275 |
acl_entry_link->nextp->prevp = acl_entry_link; |
| 2276 |
acl_entry_link = acl_entry_link->nextp; |
| 2277 |
acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
| 2278 |
if (acl_entry_link->entryp == NULL) { |
| 2279 |
errno = ENOMEM; |
| 2280 |
DEBUG(0, ("Error in sys_acl_get_fd is %d\n", errno)); |
| 2281 |
SAFE_FREE(file_acl); |
| 2282 |
return NULL; |
| 2283 |
} |
| 2284 |
|
| 2285 |
acl_entry_link->nextp = NULL; |
| 2286 |
} |
| 2287 |
|
| 2288 |
acl_entry_link->entryp->ace_len = acl_entry->ace_len; |
| 2289 |
|
| 2290 |
|
| 2291 |
|
| 2292 |
|
| 2293 |
acl_entry_link->entryp->ace_type = acl_entry->ace_type; |
| 2294 |
acl_entry_link->entryp->ace_access = acl_entry->ace_access; |
| 2295 |
|
| 2296 |
memcpy(acl_entry_link->entryp->ace_id, idp, sizeof (struct ace_id)); |
| 2297 |
|
| 2298 |
|
| 2299 |
|
| 2300 |
|
| 2301 |
|
| 2302 |
switch (acl_entry->ace_type){ |
| 2303 |
case ACC_PERMIT: |
| 2304 |
case ACC_SPECIFY: |
| 2305 |
acl_entry_link->entryp->ace_access = acl_entry->ace_access; |
| 2306 |
acl_entry_link->entryp->ace_access <<= 6; |
| 2307 |
acl_entry_link_head->count++; |
| 2308 |
break; |
| 2309 |
case ACC_DENY: |
| 2310 |
|
| 2311 |
|
| 2312 |
DEBUG(10, ("acl_entry->ace_access is %d\n", acl_entry->ace_access)); |
| 2313 |
acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7; |
| 2314 |
DEBUG(10, ("acl_entry_link->entryp->ace_access is %d\n", acl_entry_link->entryp->ace_access)); |
| 2315 |
acl_entry_link->entryp->ace_access <<= 6; |
| 2316 |
acl_entry_link_head->count++; |
| 2317 |
break; |
| 2318 |
default: |
| 2319 |
return 0; |
| 2320 |
} |
| 2321 |
|
| 2322 |
DEBUG(10, ("acl_entry = %d\n", acl_entry)); |
| 2323 |
DEBUG(10, ("The ace_type is %d\n", acl_entry->ace_type)); |
| 2324 |
|
| 2325 |
acl_entry = acl_nxt(acl_entry); |
| 2326 |
} |
| 2327 |
} |
| 2328 |
|
| 2329 |
|
| 2330 |
|
| 2331 |
|
| 2332 |
|
| 2333 |
for (i = 1; i < 4; i++) { |
| 2334 |
DEBUG(10, ("i is %d\n", i)); |
| 2335 |
if (acl_entry_link_head->count != 0){ |
| 2336 |
acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link); |
| 2337 |
if (acl_entry_link->nextp == NULL) { |
| 2338 |
errno = ENOMEM; |
| 2339 |
DEBUG(0, ("Error in sys_acl_get_fd is %d\n", errno)); |
| 2340 |
SAFE_FREE(file_acl); |
| 2341 |
return NULL; |
| 2342 |
} |
| 2343 |
|
| 2344 |
acl_entry_link->nextp->prevp = acl_entry_link; |
| 2345 |
acl_entry_link = acl_entry_link->nextp; |
| 2346 |
acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
| 2347 |
|
| 2348 |
if (acl_entry_link->entryp == NULL) { |
| 2349 |
SAFE_FREE(file_acl); |
| 2350 |
errno = ENOMEM; |
| 2351 |
DEBUG(0, ("Error in sys_acl_get_fd is %d\n", errno)); |
| 2352 |
return NULL; |
| 2353 |
} |
| 2354 |
} |
| 2355 |
|
| 2356 |
acl_entry_link->nextp = NULL; |
| 2357 |
|
| 2358 |
new_acl_entry = acl_entry_link->entryp; |
| 2359 |
idp = new_acl_entry->ace_id; |
| 2360 |
|
| 2361 |
new_acl_entry->ace_len = sizeof (struct acl_entry); |
| 2362 |
new_acl_entry->ace_type = ACC_PERMIT; |
| 2363 |
idp->id_len = sizeof (struct ace_id); |
| 2364 |
DEBUG(10, ("idp->id_len = %d\n", idp->id_len)); |
| 2365 |
memset(idp->id_data, 0, sizeof (uid_t)); |
| 2366 |
|
| 2367 |
switch (i) { |
| 2368 |
case 2: |
| 2369 |
new_acl_entry->ace_access = file_acl->g_access << 6; |
| 2370 |
idp->id_type = SMB_ACL_GROUP_OBJ; |
| 2371 |
break; |
| 2372 |
|
| 2373 |
case 3: |
| 2374 |
new_acl_entry->ace_access = file_acl->o_access << 6; |
| 2375 |
idp->id_type = SMB_ACL_OTHER; |
| 2376 |
break; |
| 2377 |
|
| 2378 |
case 1: |
| 2379 |
new_acl_entry->ace_access = file_acl->u_access << 6; |
| 2380 |
idp->id_type = SMB_ACL_USER_OBJ; |
| 2381 |
break; |
| 2382 |
|
| 2383 |
default: |
| 2384 |
return NULL; |
| 2385 |
} |
| 2386 |
|
| 2387 |
acl_entry_link_head->count++; |
| 2388 |
DEBUG(10, ("new_acl_entry->ace_access = %d\n", new_acl_entry->ace_access)); |
| 2389 |
} |
| 2390 |
|
| 2391 |
acl_entry_link_head->count = 0; |
| 2392 |
SAFE_FREE(file_acl); |
| 2393 |
|
| 2394 |
return acl_entry_link_head; |
| 2395 |
} |
| 2396 |
#endif |
| 2397 |
|
| 2398 |
int sys_acl_get_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T *tag_type_p, uint32 *bits_p, id_t *u_g_id_p) |
| 2399 |
{ |
| 2400 |
uint *permset; |
| 2401 |
|
| 2402 |
if (sys_acl_get_tag_type(entry, tag_type_p) != 0) |
| 2403 |
return -1; |
| 2404 |
|
| 2405 |
if (*tag_type_p == SMB_ACL_USER || *tag_type_p == SMB_ACL_GROUP) |
| 2406 |
memcpy(u_g_id_p, entry->ace_id->id_data, sizeof (id_t)); |
| 2407 |
|
| 2408 |
permset = &entry->ace_access; |
| 2409 |
|
| 2410 |
DEBUG(10, ("*permset is %d\n", *permset)); |
| 2411 |
*bits_p = (*permset & S_IRUSR ? 4 : 0) |
| 2412 |
| (*permset & S_IWUSR ? 2 : 0) |
| 2413 |
| (*permset & S_IXUSR ? 1 : 0); |
| 2414 |
|
| 2415 |
return 0; |
| 2416 |
} |
| 2417 |
|
| 2418 |
SMB_ACL_T sys_acl_init(int count) |
| 2419 |
{ |
| 2420 |
struct acl_entry_link *theacl = NULL; |
| 2421 |
|
| 2422 |
if (count < 0) { |
| 2423 |
errno = EINVAL; |
| 2424 |
return NULL; |
| 2425 |
} |
| 2426 |
|
| 2427 |
DEBUG(10, ("Entering sys_acl_init\n")); |
| 2428 |
|
| 2429 |
theacl = SMB_MALLOC_P(struct acl_entry_link); |
| 2430 |
if (theacl == NULL) { |
| 2431 |
errno = ENOMEM; |
| 2432 |
DEBUG(0, ("Error in sys_acl_init is %d\n", errno)); |
| 2433 |
return NULL; |
| 2434 |
} |
| 2435 |
|
| 2436 |
theacl->count = 0; |
| 2437 |
theacl->nextp = NULL; |
| 2438 |
theacl->prevp = NULL; |
| 2439 |
theacl->entryp = NULL; |
| 2440 |
DEBUG(10, ("Exiting sys_acl_init\n")); |
| 2441 |
return theacl; |
| 2442 |
} |
| 2443 |
|
| 2444 |
int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) |
| 2445 |
{ |
| 2446 |
struct acl_entry_link *theacl; |
| 2447 |
struct acl_entry_link *acl_entryp; |
| 2448 |
struct acl_entry_link *temp_entry = NULL; |
| 2449 |
int counting; |
| 2450 |
|
| 2451 |
DEBUG(10, ("Entering the sys_acl_create_entry\n")); |
| 2452 |
|
| 2453 |
theacl = acl_entryp = *pacl; |
| 2454 |
|
| 2455 |
|
| 2456 |
|
| 2457 |
for (counting = 0; counting < theacl->count; counting++){ |
| 2458 |
DEBUG(10, ("The acl_entryp is %d\n", acl_entryp)); |
| 2459 |
temp_entry = acl_entryp; |
| 2460 |
acl_entryp = acl_entryp->nextp; |
| 2461 |
} |
| 2462 |
|
| 2463 |
if (theacl->count != 0){ |
| 2464 |
temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link); |
| 2465 |
if (acl_entryp == NULL) { |
| 2466 |
errno = ENOMEM; |
| 2467 |
DEBUG(0, ("Error in sys_acl_create_entry is %d\n", errno)); |
| 2468 |
return -1; |
| 2469 |
} |
| 2470 |
|
| 2471 |
DEBUG(10, ("The acl_entryp is %d\n", acl_entryp)); |
| 2472 |
acl_entryp->prevp = temp_entry; |
| 2473 |
DEBUG(10, ("The acl_entryp->prevp is %d\n", acl_entryp->prevp)); |
| 2474 |
} |
| 2475 |
|
| 2476 |
*pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry); |
| 2477 |
if (*pentry == NULL) { |
| 2478 |
errno = ENOMEM; |
| 2479 |
DEBUG(0, ("Error in sys_acl_create_entry is %d\n", errno)); |
| 2480 |
return -1; |
| 2481 |
} |
| 2482 |
|
| 2483 |
memset(*pentry, 0, sizeof (struct new_acl_entry)); |
| 2484 |
acl_entryp->entryp->ace_len = sizeof (struct acl_entry); |
| 2485 |
acl_entryp->entryp->ace_type = ACC_PERMIT; |
| 2486 |
acl_entryp->entryp->ace_id->id_len = sizeof (struct ace_id); |
| 2487 |
acl_entryp->nextp = NULL; |
| 2488 |
theacl->count++; |
| 2489 |
DEBUG(10, ("Exiting sys_acl_create_entry\n")); |
| 2490 |
return 0; |
| 2491 |
} |
| 2492 |
|
| 2493 |
int sys_acl_set_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tag_type, uint32 bits, id_t u_g_id) |
| 2494 |
{ |
| 2495 |
entry->ace_id->id_type = tag_type; |
| 2496 |
DEBUG(10, ("The tag type is %d\n", entry->ace_id->id_type)); |
| 2497 |
|
| 2498 |
if (tag_type == SMB_ACL_USER || tag_type == SMB_ACL_GROUP) |
| 2499 |
memcpy(entry->ace_id->id_data, &u_g_id, sizeof (id_t)); |
| 2500 |
|
| 2501 |
entry->ace_access = bits; |
| 2502 |
DEBUG(10, ("entry->ace_access = %d\n", entry->ace_access)); |
| 2503 |
|
| 2504 |
return 0; |
| 2505 |
} |
| 2506 |
|
| 2507 |
int sys_acl_set_access_bits(SMB_ACL_ENTRY_T entry, uint32 bits) |
| 2508 |
{ |
| 2509 |
DEBUG(10, ("Starting AIX sys_acl_set_permset\n")); |
| 2510 |
entry->ace_access = bits; |
| 2511 |
DEBUG(10, ("entry->ace_access = %d\n", entry->ace_access)); |
| 2512 |
DEBUG(10, ("Ending AIX sys_acl_set_permset\n")); |
| 2513 |
return 0; |
| 2514 |
} |
| 2515 |
|
| 2516 |
int sys_acl_valid(SMB_ACL_T theacl) |
| 2517 |
{ |
| 2518 |
int user_obj = 0; |
| 2519 |
int group_obj = 0; |
| 2520 |
int other_obj = 0; |
| 2521 |
struct acl_entry_link *acl_entry; |
| 2522 |
|
| 2523 |
for (acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) { |
| 2524 |
user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ); |
| 2525 |
group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ); |
| 2526 |
other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER); |
| 2527 |
} |
| 2528 |
|
| 2529 |
DEBUG(10, ("user_obj=%d, group_obj=%d, other_obj=%d\n", user_obj, group_obj, other_obj)); |
| 2530 |
|
| 2531 |
if (user_obj != 1 || group_obj != 1 || other_obj != 1) |
| 2532 |
return -1; |
| 2533 |
|
| 2534 |
return 0; |
| 2535 |
} |
| 2536 |
|
| 2537 |
int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) |
| 2538 |
{ |
| 2539 |
struct acl_entry_link *acl_entry_link = NULL; |
| 2540 |
struct acl *file_acl = NULL; |
| 2541 |
struct acl *file_acl_temp = NULL; |
| 2542 |
struct acl_entry *acl_entry = NULL; |
| 2543 |
struct ace_id *ace_id = NULL; |
| 2544 |
uint id_type; |
| 2545 |
uint user_id; |
| 2546 |
uint acl_length; |
| 2547 |
uint rc; |
| 2548 |
|
| 2549 |
DEBUG(10, ("Entering sys_acl_set_file\n")); |
| 2550 |
DEBUG(10, ("File name is %s\n", name)); |
| 2551 |
|
| 2552 |
|
| 2553 |
if (acltype == SMB_ACL_TYPE_DEFAULT) |
| 2554 |
return 0; |
| 2555 |
|
| 2556 |
acl_length = BUFSIZ; |
| 2557 |
file_acl = (struct acl *)SMB_MALLOC(BUFSIZ); |
| 2558 |
|
| 2559 |
if (file_acl == NULL) { |
| 2560 |
errno = ENOMEM; |
| 2561 |
DEBUG(0, ("Error in sys_acl_set_file is %d\n", errno)); |
| 2562 |
return -1; |
| 2563 |
} |
| 2564 |
|
| 2565 |
memset(file_acl, 0, BUFSIZ); |
| 2566 |
|
| 2567 |
file_acl->acl_len = ACL_SIZ; |
| 2568 |
file_acl->acl_mode = S_IXACL; |
| 2569 |
|
| 2570 |
for (acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) { |
| 2571 |
acl_entry_link->entryp->ace_access >>= 6; |
| 2572 |
id_type = acl_entry_link->entryp->ace_id->id_type; |
| 2573 |
|
| 2574 |
switch (id_type) { |
| 2575 |
case SMB_ACL_USER_OBJ: |
| 2576 |
file_acl->u_access = acl_entry_link->entryp->ace_access; |
| 2577 |
continue; |
| 2578 |
case SMB_ACL_GROUP_OBJ: |
| 2579 |
file_acl->g_access = acl_entry_link->entryp->ace_access; |
| 2580 |
continue; |
| 2581 |
case SMB_ACL_OTHER: |
| 2582 |
file_acl->o_access = acl_entry_link->entryp->ace_access; |
| 2583 |
continue; |
| 2584 |
case SMB_ACL_MASK: |
| 2585 |
continue; |
| 2586 |
} |
| 2587 |
|
| 2588 |
if ((file_acl->acl_len + sizeof (struct acl_entry)) > acl_length) { |
| 2589 |
acl_length += sizeof (struct acl_entry); |
| 2590 |
file_acl_temp = (struct acl *)SMB_MALLOC(acl_length); |
| 2591 |
if (file_acl_temp == NULL) { |
| 2592 |
SAFE_FREE(file_acl); |
| 2593 |
errno = ENOMEM; |
| 2594 |
DEBUG(0, ("Error in sys_acl_set_file is %d\n", errno)); |
| 2595 |
return -1; |
| 2596 |
} |
| 2597 |
|
| 2598 |
memcpy(file_acl_temp, file_acl, file_acl->acl_len); |
| 2599 |
SAFE_FREE(file_acl); |
| 2600 |
file_acl = file_acl_temp; |
| 2601 |
} |
| 2602 |
|
| 2603 |
acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len); |
| 2604 |
file_acl->acl_len += sizeof (struct acl_entry); |
| 2605 |
acl_entry->ace_len = acl_entry_link->entryp->ace_len; |
| 2606 |
acl_entry->ace_access = acl_entry_link->entryp->ace_access; |
| 2607 |
|
| 2608 |
|
| 2609 |
|
| 2610 |
|
| 2611 |
|
| 2612 |
acl_entry->ace_type = ACC_SPECIFY; |
| 2613 |
|
| 2614 |
ace_id = acl_entry->ace_id; |
| 2615 |
|
| 2616 |
ace_id->id_type = acl_entry_link->entryp->ace_id->id_type; |
| 2617 |
DEBUG(10, ("The id type is %d\n", ace_id->id_type)); |
| 2618 |
ace_id->id_len = acl_entry_link->entryp->ace_id->id_len; |
| 2619 |
memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof (uid_t)); |
| 2620 |
memcpy(acl_entry->ace_id->id_data, &user_id, sizeof (uid_t)); |
| 2621 |
} |
| 2622 |
|
| 2623 |
rc = chacl((char*)name, file_acl, file_acl->acl_len); |
| 2624 |
DEBUG(10, ("errno is %d\n", errno)); |
| 2625 |
DEBUG(10, ("return code is %d\n", rc)); |
| 2626 |
SAFE_FREE(file_acl); |
| 2627 |
DEBUG(10, ("Exiting the sys_acl_set_file\n")); |
| 2628 |
return rc; |
| 2629 |
} |
| 2630 |
|
| 2631 |
#if 0 |
| 2632 |
int sys_acl_set_fd(int fd, SMB_ACL_T theacl) |
| 2633 |
{ |
| 2634 |
struct acl_entry_link *acl_entry_link = NULL; |
| 2635 |
struct acl *file_acl = NULL; |
| 2636 |
struct acl *file_acl_temp = NULL; |
| 2637 |
struct acl_entry *acl_entry = NULL; |
| 2638 |
struct ace_id *ace_id = NULL; |
| 2639 |
uint id_type; |
| 2640 |
uint user_id; |
| 2641 |
uint acl_length; |
| 2642 |
uint rc; |
| 2643 |
|
| 2644 |
DEBUG(10, ("Entering sys_acl_set_fd\n")); |
| 2645 |
acl_length = BUFSIZ; |
| 2646 |
file_acl = (struct acl *)SMB_MALLOC(BUFSIZ); |
| 2647 |
|
| 2648 |
if (file_acl == NULL) { |
| 2649 |
errno = ENOMEM; |
| 2650 |
DEBUG(0, ("Error in sys_acl_set_fd is %d\n", errno)); |
| 2651 |
return -1; |
| 2652 |
} |
| 2653 |
|
| 2654 |
memset(file_acl, 0, BUFSIZ); |
| 2655 |
|
| 2656 |
file_acl->acl_len = ACL_SIZ; |
| 2657 |
file_acl->acl_mode = S_IXACL; |
| 2658 |
|
| 2659 |
for (acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) { |
| 2660 |
acl_entry_link->entryp->ace_access >>= 6; |
| 2661 |
id_type = acl_entry_link->entryp->ace_id->id_type; |
| 2662 |
DEBUG(10, ("The id_type is %d\n", id_type)); |
| 2663 |
|
| 2664 |
switch (id_type) { |
| 2665 |
case SMB_ACL_USER_OBJ: |
| 2666 |
file_acl->u_access = acl_entry_link->entryp->ace_access; |
| 2667 |
continue; |
| 2668 |
case SMB_ACL_GROUP_OBJ: |
| 2669 |
file_acl->g_access = acl_entry_link->entryp->ace_access; |
| 2670 |
continue; |
| 2671 |
case SMB_ACL_OTHER: |
| 2672 |
file_acl->o_access = acl_entry_link->entryp->ace_access; |
| 2673 |
continue; |
| 2674 |
case SMB_ACL_MASK: |
| 2675 |
continue; |
| 2676 |
} |
| 2677 |
|
| 2678 |
if ((file_acl->acl_len + sizeof (struct acl_entry)) > acl_length) { |
| 2679 |
acl_length += sizeof (struct acl_entry); |
| 2680 |
file_acl_temp = (struct acl *)SMB_MALLOC(acl_length); |
| 2681 |
if (file_acl_temp == NULL) { |
| 2682 |
SAFE_FREE(file_acl); |
| 2683 |
errno = ENOMEM; |
| 2684 |
DEBUG(0, ("Error in sys_acl_set_fd is %d\n", errno)); |
| 2685 |
return -1; |
| 2686 |
} |
| 2687 |
|
| 2688 |
memcpy(file_acl_temp, file_acl, file_acl->acl_len); |
| 2689 |
SAFE_FREE(file_acl); |
| 2690 |
file_acl = file_acl_temp; |
| 2691 |
} |
| 2692 |
|
| 2693 |
acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len); |
| 2694 |
file_acl->acl_len += sizeof (struct acl_entry); |
| 2695 |
acl_entry->ace_len = acl_entry_link->entryp->ace_len; |
| 2696 |
acl_entry->ace_access = acl_entry_link->entryp->ace_access; |
| 2697 |
|
| 2698 |
|
| 2699 |
|
| 2700 |
|
| 2701 |
|
| 2702 |
acl_entry->ace_type = ACC_SPECIFY; |
| 2703 |
|
| 2704 |
ace_id = acl_entry->ace_id; |
| 2705 |
|
| 2706 |
ace_id->id_type = acl_entry_link->entryp->ace_id->id_type; |
| 2707 |
DEBUG(10, ("The id type is %d\n", ace_id->id_type)); |
| 2708 |
ace_id->id_len = acl_entry_link->entryp->ace_id->id_len; |
| 2709 |
memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof (uid_t)); |
| 2710 |
memcpy(ace_id->id_data, &user_id, sizeof (uid_t)); |
| 2711 |
} |
| 2712 |
|
| 2713 |
rc = fchacl(fd, file_acl, file_acl->acl_len); |
| 2714 |
DEBUG(10, ("errno is %d\n", errno)); |
| 2715 |
DEBUG(10, ("return code is %d\n", rc)); |
| 2716 |
SAFE_FREE(file_acl); |
| 2717 |
DEBUG(10, ("Exiting sys_acl_set_fd\n")); |
| 2718 |
return rc; |
| 2719 |
} |
| 2720 |
#endif |
| 2721 |
|
| 2722 |
int sys_acl_delete_def_file(UNUSED(const char *name)) |
| 2723 |
{ |
| 2724 |
|
| 2725 |
return 0; |
| 2726 |
} |
| 2727 |
|
| 2728 |
int sys_acl_free_acl(SMB_ACL_T posix_acl) |
| 2729 |
{ |
| 2730 |
struct acl_entry_link *acl_entry_link; |
| 2731 |
|
| 2732 |
for (acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) { |
| 2733 |
SAFE_FREE(acl_entry_link->prevp->entryp); |
| 2734 |
SAFE_FREE(acl_entry_link->prevp); |
| 2735 |
} |
| 2736 |
|
| 2737 |
SAFE_FREE(acl_entry_link->prevp->entryp); |
| 2738 |
SAFE_FREE(acl_entry_link->prevp); |
| 2739 |
SAFE_FREE(acl_entry_link->entryp); |
| 2740 |
SAFE_FREE(acl_entry_link); |
| 2741 |
|
| 2742 |
return 0; |
| 2743 |
} |
| 2744 |
|
| 2745 |
#elif defined(HAVE_OSX_ACLS) |
| 2746 |
|
| 2747 |
#define OSX_BROKEN_GETENTRY |
| 2748 |
|
| 2749 |
#include <membership.h> |
| 2750 |
|
| 2751 |
int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
| 2752 |
{ |
| 2753 |
int ret = acl_get_entry(the_acl, entry_id, entry_p); |
| 2754 |
#ifdef OSX_BROKEN_GETENTRY |
| 2755 |
if (ret == 0) |
| 2756 |
ret = 1; |
| 2757 |
else if (ret == -1 && errno == 22) |
| 2758 |
ret = 0; |
| 2759 |
#endif |
| 2760 |
return ret; |
| 2761 |
} |
| 2762 |
|
| 2763 |
SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) |
| 2764 |
{ |
| 2765 |
if (type == ACL_TYPE_DEFAULT) { |
| 2766 |
errno = ENOTSUP; |
| 2767 |
return NULL; |
| 2768 |
} |
| 2769 |
errno = 0; |
| 2770 |
return acl_get_file(path_p, type); |
| 2771 |
} |
| 2772 |
|
| 2773 |
#if 0 |
| 2774 |
SMB_ACL_T sys_acl_get_fd(int fd) |
| 2775 |
{ |
| 2776 |
return acl_get_fd(fd); |
| 2777 |
} |
| 2778 |
#endif |
| 2779 |
|
| 2780 |
int sys_acl_get_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T *tag_type_p, uint32 *bits_p, id_t *u_g_id_p) |
| 2781 |
{ |
| 2782 |
uuid_t *uup; |
| 2783 |
acl_tag_t tag; |
| 2784 |
acl_flagset_t flagset; |
| 2785 |
acl_permset_t permset; |
| 2786 |
uint32 bits, fb, bb, pb; |
| 2787 |
int id_type = -1; |
| 2788 |
int rc; |
| 2789 |
|
| 2790 |
if (acl_get_tag_type(entry, &tag) != 0 |
| 2791 |
|| acl_get_flagset_np(entry, &flagset) != 0 |
| 2792 |
|| acl_get_permset(entry, &permset) != 0 |
| 2793 |
|| (uup = acl_get_qualifier(entry)) == NULL) |
| 2794 |
return -1; |
| 2795 |
|
| 2796 |
rc = mbr_uuid_to_id(*uup, u_g_id_p, &id_type); |
| 2797 |
acl_free(uup); |
| 2798 |
if (rc != 0) |
| 2799 |
return rc; |
| 2800 |
|
| 2801 |
if (id_type == ID_TYPE_UID) |
| 2802 |
*tag_type_p = SMB_ACL_USER; |
| 2803 |
else |
| 2804 |
*tag_type_p = SMB_ACL_GROUP; |
| 2805 |
|
| 2806 |
bits = tag == ACL_EXTENDED_ALLOW ? 1 : 0; |
| 2807 |
|
| 2808 |
for (fb = (1u<<4), bb = (1u<<1); bb < (1u<<12); fb *= 2, bb *= 2) { |
| 2809 |
if (acl_get_flag_np(flagset, fb) == 1) |
| 2810 |
bits |= bb; |
| 2811 |
} |
| 2812 |
|
| 2813 |
for (pb = (1u<<1), bb = (1u<<12); bb < (1u<<25); pb *= 2, bb *= 2) { |
| 2814 |
if (acl_get_perm_np(permset, pb) == 1) |
| 2815 |
bits |= bb; |
| 2816 |
} |
| 2817 |
|
| 2818 |
*bits_p = bits; |
| 2819 |
|
| 2820 |
return 0; |
| 2821 |
} |
| 2822 |
|
| 2823 |
SMB_ACL_T sys_acl_init(int count) |
| 2824 |
{ |
| 2825 |
return acl_init(count); |
| 2826 |
} |
| 2827 |
|
| 2828 |
int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) |
| 2829 |
{ |
| 2830 |
return acl_create_entry(pacl, pentry); |
| 2831 |
} |
| 2832 |
|
| 2833 |
int sys_acl_set_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tag_type, uint32 bits, id_t u_g_id) |
| 2834 |
{ |
| 2835 |
acl_flagset_t flagset; |
| 2836 |
acl_permset_t permset; |
| 2837 |
uint32 fb, bb, pb; |
| 2838 |
int is_user = tag_type == SMB_ACL_USER; |
| 2839 |
uuid_t uu; |
| 2840 |
int rc; |
| 2841 |
|
| 2842 |
tag_type = bits & 1 ? ACL_EXTENDED_ALLOW : ACL_EXTENDED_DENY; |
| 2843 |
|
| 2844 |
if (acl_get_flagset_np(entry, &flagset) != 0 |
| 2845 |
|| acl_get_permset(entry, &permset) != 0) |
| 2846 |
return -1; |
| 2847 |
|
| 2848 |
acl_clear_flags_np(flagset); |
| 2849 |
acl_clear_perms(permset); |
| 2850 |
|
| 2851 |
for (fb = (1u<<4), bb = (1u<<1); bb < (1u<<12); fb *= 2, bb *= 2) { |
| 2852 |
if (bits & bb) |
| 2853 |
acl_add_flag_np(flagset, fb); |
| 2854 |
} |
| 2855 |
|
| 2856 |
for (pb = (1u<<1), bb = (1u<<12); bb < (1u<<25); pb *= 2, bb *= 2) { |
| 2857 |
if (bits & bb) |
| 2858 |
acl_add_perm(permset, pb); |
| 2859 |
} |
| 2860 |
|
| 2861 |
if (is_user) |
| 2862 |
rc = mbr_uid_to_uuid(u_g_id, uu); |
| 2863 |
else |
| 2864 |
rc = mbr_gid_to_uuid(u_g_id, uu); |
| 2865 |
if (rc != 0) |
| 2866 |
return rc; |
| 2867 |
|
| 2868 |
if (acl_set_tag_type(entry, tag_type) != 0 |
| 2869 |
|| acl_set_qualifier(entry, &uu) != 0 |
| 2870 |
|| acl_set_permset(entry, permset) != 0 |
| 2871 |
|| acl_set_flagset_np(entry, flagset) != 0) |
| 2872 |
return -1; |
| 2873 |
|
| 2874 |
return 0; |
| 2875 |
} |
| 2876 |
|
| 2877 |
#if 0 |
| 2878 |
int sys_acl_set_access_bits(SMB_ACL_ENTRY_T entry, uint32 bits) |
| 2879 |
{ |
| 2880 |
return -1; |
| 2881 |
} |
| 2882 |
#endif |
| 2883 |
|
| 2884 |
int sys_acl_valid(SMB_ACL_T theacl) |
| 2885 |
{ |
| 2886 |
return acl_valid(theacl); |
| 2887 |
} |
| 2888 |
|
| 2889 |
int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) |
| 2890 |
{ |
| 2891 |
return acl_set_file(name, acltype, theacl); |
| 2892 |
} |
| 2893 |
|
| 2894 |
#if 0 |
| 2895 |
int sys_acl_set_fd(int fd, SMB_ACL_T theacl) |
| 2896 |
{ |
| 2897 |
return acl_set_fd(fd, theacl); |
| 2898 |
} |
| 2899 |
#endif |
| 2900 |
|
| 2901 |
int sys_acl_delete_def_file(const char *name) |
| 2902 |
{ |
| 2903 |
return acl_delete_def_file(name); |
| 2904 |
} |
| 2905 |
|
| 2906 |
int sys_acl_free_acl(SMB_ACL_T the_acl) |
| 2907 |
{ |
| 2908 |
return acl_free(the_acl); |
| 2909 |
} |
| 2910 |
|
| 2911 |
#else |
| 2912 |
|
| 2913 |
#error No ACL functions defined for this platform! |
| 2914 |
|
| 2915 |
#endif |
| 2916 |
|
| 2917 |
|
| 2918 |
|
| 2919 |
|
| 2920 |
|
| 2921 |
|
| 2922 |
int no_acl_syscall_error(int err) |
| 2923 |
{ |
| 2924 |
#ifdef HAVE_OSX_ACLS |
| 2925 |
if (err == ENOENT) |
| 2926 |
return 1; |
| 2927 |
#endif |
| 2928 |
#if defined(ENOSYS) |
| 2929 |
if (err == ENOSYS) { |
| 2930 |
return 1; |
| 2931 |
} |
| 2932 |
#endif |
| 2933 |
#if defined(ENOTSUP) |
| 2934 |
if (err == ENOTSUP) { |
| 2935 |
return 1; |
| 2936 |
} |
| 2937 |
#endif |
| 2938 |
if (err == EINVAL) { |
| 2939 |
|
| 2940 |
|
| 2941 |
return 1; |
| 2942 |
} |
| 2943 |
return 0; |
| 2944 |
} |
| 2945 |
|
| 2946 |
#endif |