Changeset 988 for vendor/current/source3/lib/sysacls.c
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/lib/sysacls.c
r740 r988 1 /* 1 /* 2 2 Unix SMB/CIFS implementation. 3 3 Samba system utilities for ACL support. … … 5 5 Copyright (C) Volker Lendecke 2006 6 6 Copyright (C) Michael Adam 2006,2008 7 7 8 8 This program is free software; you can redistribute it and/or modify 9 9 it under the terms of the GNU General Public License as published by 10 10 the Free Software Foundation; either version 3 of the License, or 11 11 (at your option) any later version. 12 12 13 13 This program is distributed in the hope that it will be useful, 14 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 16 GNU General Public License for more details. 17 17 18 18 You should have received a copy of the GNU General Public License 19 19 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 31 31 #endif 32 32 33 #if defined(HAVE_SOLARIS_ ACLS) || defined(HAVE_UNIXWARE_ACLS)33 #if defined(HAVE_SOLARIS_UNIXWARE_ACLS) 34 34 #include "modules/vfs_solarisacl.h" 35 35 #endif … … 37 37 #if defined(HAVE_HPUX_ACLS) 38 38 #include "modules/vfs_hpuxacl.h" 39 #endif40 41 #if defined(HAVE_IRIX_ACLS)42 #include "modules/vfs_irixacl.h"43 39 #endif 44 40 … … 108 104 { 109 105 if (entry_d->a_type == SMB_ACL_USER) { 110 return &entry_d-> uid;111 106 return &entry_d->info.user.uid; 107 } 112 108 113 109 if (entry_d->a_type == SMB_ACL_GROUP) { 114 return &entry_d-> gid;110 return &entry_d->info.group.gid; 115 111 } 116 112 117 113 errno = EINVAL; 118 114 return NULL; 119 115 } 120 116 … … 132 128 errno = EINVAL; 133 129 return -1; 134 135 130 } 131 136 132 if (permset_d == NULL) { 137 133 errno = EINVAL; … … 140 136 141 137 *permset_d |= perm; 142 138 143 139 return 0; 144 140 } … … 149 145 } 150 146 151 char *sys_acl_to_text( SMB_ACL_Tacl_d, ssize_t *len_p)147 char *sys_acl_to_text(const struct smb_acl_t *acl_d, ssize_t *len_p) 152 148 { 153 149 int i; … … 188 184 tag = tagbuf; 189 185 break; 190 186 191 187 case SMB_ACL_USER: 192 id = uidtoname(ap->uid); 188 id = uidtoname(ap->info.user.uid); 189 /* FALL TROUGH */ 193 190 case SMB_ACL_USER_OBJ: 194 191 tag = "user"; … … 196 193 197 194 case SMB_ACL_GROUP: 198 if ((gr = getgrgid(ap-> gid)) == NULL) {195 if ((gr = getgrgid(ap->info.group.gid)) == NULL) { 199 196 slprintf(idbuf, sizeof(idbuf)-1, "%ld", 200 (long)ap-> gid);197 (long)ap->info.group.gid); 201 198 id = idbuf; 202 199 } else { 203 200 id = gr->gr_name; 204 201 } 202 /* FALL TROUGH */ 205 203 case SMB_ACL_GROUP_OBJ: 206 204 tag = "group"; … … 234 232 maxlen += nbytes + 20 * (acl_d->count - i); 235 233 if ((text = (char *)SMB_REALLOC(text, maxlen)) == NULL) { 236 errno = ENOMEM;234 errno = ENOMEM; 237 235 return NULL; 236 } 238 237 } 239 } 240 241 slprintf(&text[len], nbytes -1, "%s:%s:%s\n", tag, id, perms);242 len += nbytes - 1;238 239 240 slprintf(&text[len], nbytes, "%s:%s:%s\n", tag, id, perms); 241 len += (nbytes - 1); 243 242 } 244 243 … … 249 248 } 250 249 251 SMB_ACL_T sys_acl_init( int count)250 SMB_ACL_T sys_acl_init(TALLOC_CTX *mem_ctx) 252 251 { 253 252 SMB_ACL_T a; 254 253 255 if (count < 0) { 256 errno = EINVAL; 257 return NULL; 258 } 259 260 /* 261 * note that since the definition of the structure pointed 262 * to by the SMB_ACL_T includes the first element of the 263 * acl[] array, this actually allocates an ACL with room 264 * for (count+1) entries 265 */ 266 if ((a = (struct smb_acl_t *)SMB_MALLOC( 267 sizeof(struct smb_acl_t) + 268 count * sizeof(struct smb_acl_entry))) == NULL) { 254 if ((a = talloc(mem_ctx, struct smb_acl_t)) == NULL) { 269 255 errno = ENOMEM; 270 256 return NULL; 271 257 } 272 273 a->size = count + 1; 258 274 259 a->count = 0; 275 260 a->next = -1; 276 261 262 a->acl = talloc_array(a, struct smb_acl_entry, 0); 263 if (!a->acl) { 264 TALLOC_FREE(a); 265 errno = ENOMEM; 266 return NULL; 267 } 268 277 269 return a; 278 270 } … … 282 274 SMB_ACL_T acl_d; 283 275 SMB_ACL_ENTRY_T entry_d; 276 struct smb_acl_entry *acl; 284 277 285 278 if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) { … … 288 281 } 289 282 290 if (acl_d->count >= acl_d->size) { 291 errno = ENOSPC; 292 return -1; 293 } 294 295 entry_d = &acl_d->acl[acl_d->count++]; 283 acl = talloc_realloc(acl_d, acl_d->acl, struct smb_acl_entry, acl_d->count+1); 284 if (!acl) { 285 errno = ENOMEM; 286 return -1; 287 } 288 acl_d->acl = acl; 289 entry_d = &acl_d->acl[acl_d->count]; 296 290 entry_d->a_type = SMB_ACL_TAG_INVALID; 297 entry_d->uid = -1;298 entry_d->gid = -1;299 291 entry_d->a_perm = 0; 300 292 *entry_p = entry_d; 301 293 294 acl_d->count++; 302 295 return 0; 303 296 } … … 325 318 { 326 319 if (entry_d->a_type == SMB_ACL_USER) { 327 entry_d-> uid = *((uid_t *)qual_p);320 entry_d->info.user.uid = *((uid_t *)qual_p); 328 321 return 0; 329 322 } 330 323 if (entry_d->a_type == SMB_ACL_GROUP) { 331 entry_d-> gid = *((gid_t *)qual_p);324 entry_d->info.group.gid = *((gid_t *)qual_p); 332 325 return 0; 333 326 } … … 345 338 346 339 entry_d->a_perm = *permset_d; 347 340 348 341 return 0; 349 342 } … … 352 345 { 353 346 SAFE_FREE(text); 354 return 0;355 }356 357 int sys_acl_free_acl(SMB_ACL_T acl_d)358 {359 SAFE_FREE(acl_d);360 return 0;361 }362 363 int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)364 {365 347 return 0; 366 348 } … … 377 359 * statically-bound acl vfs module, but they are replacable. 378 360 */ 379 361 380 362 #if defined(HAVE_POSIX_ACLS) 381 382 SMB_ACL_T sys_acl_get_file(vfs_handle_struct *handle, 383 const char *path_p, SMB_ACL_TYPE_T type )384 { 385 return posixacl_sys_acl_get_file(handle, path_p, type );386 } 387 388 SMB_ACL_T sys_acl_get_fd(vfs_handle_struct *handle, files_struct *fsp )389 { 390 return posixacl_sys_acl_get_fd(handle, fsp );391 } 392 363 364 SMB_ACL_T sys_acl_get_file(vfs_handle_struct *handle, 365 const char *path_p, SMB_ACL_TYPE_T type, TALLOC_CTX *mem_ctx) 366 { 367 return posixacl_sys_acl_get_file(handle, path_p, type, mem_ctx); 368 } 369 370 SMB_ACL_T sys_acl_get_fd(vfs_handle_struct *handle, files_struct *fsp, TALLOC_CTX *mem_ctx) 371 { 372 return posixacl_sys_acl_get_fd(handle, fsp, mem_ctx); 373 } 374 393 375 int sys_acl_set_file(vfs_handle_struct *handle, 394 376 const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d) … … 396 378 return posixacl_sys_acl_set_file(handle, name, type, acl_d); 397 379 } 398 380 399 381 int sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp, 400 382 SMB_ACL_T acl_d) … … 412 394 413 395 SMB_ACL_T sys_acl_get_file(vfs_handle_struct *handle, 414 const char *path_p, SMB_ACL_TYPE_T type) 415 { 416 return aixacl_sys_acl_get_file(handle, path_p, type); 417 } 418 419 SMB_ACL_T sys_acl_get_fd(vfs_handle_struct *handle, files_struct *fsp) 420 { 421 return aixacl_sys_acl_get_fd(handle, fsp); 396 const char *path_p, SMB_ACL_TYPE_T type, 397 TALLOC_CTX *mem_ctx) 398 { 399 return aixacl_sys_acl_get_file(handle, path_p, type, mem_ctx); 400 } 401 402 SMB_ACL_T sys_acl_get_fd(vfs_handle_struct *handle, files_struct *fsp, 403 TALLOC_CTX *mem_ctx) 404 { 405 return aixacl_sys_acl_get_fd(handle, fsp, mem_ctx); 422 406 } 423 407 … … 441 425 442 426 #elif defined(HAVE_TRU64_ACLS) 443 427 444 428 SMB_ACL_T sys_acl_get_file(vfs_handle_struct *handle, 445 const char *path_p, SMB_ACL_TYPE_T type) 446 { 447 return tru64acl_sys_acl_get_file(handle, path_p, type); 448 } 449 450 SMB_ACL_T sys_acl_get_fd(vfs_handle_struct *handle, files_struct *fsp) 451 { 452 return tru64acl_sys_acl_get_fd(handle, fsp); 429 const char *path_p, SMB_ACL_TYPE_T type, 430 TALLOC_CTX *mem_ctx) 431 { 432 return tru64acl_sys_acl_get_file(handle, path_p, type, 433 mem_ctx); 434 } 435 436 SMB_ACL_T sys_acl_get_fd(vfs_handle_struct *handle, files_struct *fsp, 437 TALLOC_CTX *mem_ctx) 438 { 439 return tru64acl_sys_acl_get_fd(handle, fsp, mem_ctx); 453 440 } 454 441 … … 471 458 } 472 459 473 #elif defined(HAVE_SOLARIS_ ACLS) || defined(HAVE_UNIXWARE_ACLS)460 #elif defined(HAVE_SOLARIS_UNIXWARE_ACLS) 474 461 475 462 SMB_ACL_T sys_acl_get_file(vfs_handle_struct *handle, 476 const char *path_p, SMB_ACL_TYPE_T type) 477 { 478 return solarisacl_sys_acl_get_file(handle, path_p, type); 479 } 480 481 SMB_ACL_T sys_acl_get_fd(vfs_handle_struct *handle, files_struct *fsp) 482 { 483 return solarisacl_sys_acl_get_fd(handle, fsp); 463 const char *path_p, SMB_ACL_TYPE_T type, 464 TALLOC_CTX *mem_ctx) 465 { 466 return solarisacl_sys_acl_get_file(handle, path_p, type, 467 mem_ctx); 468 } 469 470 SMB_ACL_T sys_acl_get_fd(vfs_handle_struct *handle, files_struct *fsp, 471 TALLOC_CTX *mem_ctx) 472 { 473 return solarisacl_sys_acl_get_fd(handle, fsp, 474 mem_ctx); 484 475 } 485 476 … … 505 496 506 497 SMB_ACL_T sys_acl_get_file(vfs_handle_struct *handle, 507 const char *path_p, SMB_ACL_TYPE_T type) 508 { 509 return hpuxacl_sys_acl_get_file(handle, path_p, type); 510 } 511 512 SMB_ACL_T sys_acl_get_fd(vfs_handle_struct *handle, files_struct *fsp) 513 { 514 return hpuxacl_sys_acl_get_fd(handle, fsp); 498 const char *path_p, SMB_ACL_TYPE_T type, 499 TALLOC_CTX *mem_ctx) 500 { 501 return hpuxacl_sys_acl_get_file(handle, path_p, type, mem_ctx); 502 } 503 504 SMB_ACL_T sys_acl_get_fd(vfs_handle_struct *handle, files_struct *fsp, 505 TALLOC_CTX *mem_ctx) 506 { 507 return hpuxacl_sys_acl_get_fd(handle, fsp, mem_ctx); 515 508 } 516 509 … … 533 526 } 534 527 535 #el if defined(HAVE_IRIX_ACLS)528 #else /* No ACLs. */ 536 529 537 530 SMB_ACL_T sys_acl_get_file(vfs_handle_struct *handle, 538 const char *path_p, SMB_ACL_TYPE_T type) 539 { 540 return irixacl_sys_acl_get_file(handle, path_p, type); 541 } 542 543 SMB_ACL_T sys_acl_get_fd(vfs_handle_struct *handle, files_struct *fsp) 544 { 545 return irixacl_sys_acl_get_fd(handle, fsp); 546 } 547 548 int sys_acl_set_file(vfs_handle_struct *handle, 549 const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d) 550 { 551 return irixacl_sys_acl_set_file(handle, name, type, acl_d); 552 } 553 554 int sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp, 555 SMB_ACL_T acl_d) 556 { 557 return irixacl_sys_acl_set_fd(handle, fsp, acl_d); 558 } 559 560 int sys_acl_delete_def_file(vfs_handle_struct *handle, 561 const char *path) 562 { 563 return irixacl_sys_acl_delete_def_file(handle, path); 564 } 565 566 #else /* No ACLs. */ 567 568 SMB_ACL_T sys_acl_get_file(vfs_handle_struct *handle, 569 const char *path_p, SMB_ACL_TYPE_T type) 531 const char *path_p, SMB_ACL_TYPE_T type, 532 TALLOC_CTX *mem_ctx) 570 533 { 571 534 #ifdef ENOTSUP … … 577 540 } 578 541 579 SMB_ACL_T sys_acl_get_fd(vfs_handle_struct *handle, files_struct *fsp) 542 SMB_ACL_T sys_acl_get_fd(vfs_handle_struct *handle, files_struct *fsp, 543 TALLOC_CTX *mem_ctx) 580 544 { 581 545 #ifdef ENOTSUP
Note:
See TracChangeset
for help on using the changeset viewer.