Changeset 740 for vendor/current/source3/lib/secdesc.c
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/lib/secdesc.c
r414 r740 22 22 23 23 #include "includes.h" 24 #include "../librpc/gen_ndr/ndr_security.h" 25 #include "../libcli/security/security.h" 26 27 #define ALL_SECURITY_INFORMATION (SECINFO_OWNER|SECINFO_GROUP|\ 28 SECINFO_DACL|SECINFO_SACL|\ 29 SECINFO_UNPROTECTED_SACL|\ 30 SECINFO_UNPROTECTED_DACL|\ 31 SECINFO_PROTECTED_SACL|\ 32 SECINFO_PROTECTED_DACL) 24 33 25 34 /* Map generic permissions to file object specific permissions */ … … 36 45 ********************************************************************/ 37 46 38 uint32_t get_sec_info(const SEC_DESC*sd)47 uint32_t get_sec_info(const struct security_descriptor *sd) 39 48 { 40 49 uint32_t sec_info = ALL_SECURITY_INFORMATION; … … 43 52 44 53 if (sd->owner_sid == NULL) { 45 sec_info &= ~ OWNER_SECURITY_INFORMATION;54 sec_info &= ~SECINFO_OWNER; 46 55 } 47 56 if (sd->group_sid == NULL) { 48 sec_info &= ~ GROUP_SECURITY_INFORMATION;57 sec_info &= ~SECINFO_GROUP; 49 58 } 50 59 if (sd->sacl == NULL) { 51 sec_info &= ~S ACL_SECURITY_INFORMATION;60 sec_info &= ~SECINFO_SACL; 52 61 } 53 62 if (sd->dacl == NULL) { 54 sec_info &= ~ DACL_SECURITY_INFORMATION;63 sec_info &= ~SECINFO_DACL; 55 64 } 56 65 … … 64 73 ********************************************************************/ 65 74 66 SEC_DESC_BUF *sec_desc_merge(TALLOC_CTX *ctx, SEC_DESC_BUF *new_sdb, SEC_DESC_BUF*old_sdb)67 { 68 DOM_SID*owner_sid, *group_sid;69 SEC_DESC_BUF*return_sdb;70 SEC_ACL*dacl, *sacl;71 SEC_DESC*psd = NULL;75 struct sec_desc_buf *sec_desc_merge_buf(TALLOC_CTX *ctx, struct sec_desc_buf *new_sdb, struct sec_desc_buf *old_sdb) 76 { 77 struct dom_sid *owner_sid, *group_sid; 78 struct sec_desc_buf *return_sdb; 79 struct security_acl *dacl, *sacl; 80 struct security_descriptor *psd = NULL; 72 81 uint16 secdesc_type; 73 82 size_t secdesc_size; … … 109 118 } 110 119 111 /******************************************************************* 112 Creates a SEC_DESC structure 113 ********************************************************************/ 114 115 SEC_DESC *make_sec_desc(TALLOC_CTX *ctx, 120 struct security_descriptor *sec_desc_merge(TALLOC_CTX *ctx, struct security_descriptor *new_sdb, struct security_descriptor *old_sdb) 121 { 122 struct dom_sid *owner_sid, *group_sid; 123 struct security_acl *dacl, *sacl; 124 struct security_descriptor *psd = NULL; 125 uint16 secdesc_type; 126 size_t secdesc_size; 127 128 /* Copy over owner and group sids. There seems to be no flag for 129 this so just check the pointer values. */ 130 131 owner_sid = new_sdb->owner_sid ? new_sdb->owner_sid : 132 old_sdb->owner_sid; 133 134 group_sid = new_sdb->group_sid ? new_sdb->group_sid : 135 old_sdb->group_sid; 136 137 secdesc_type = new_sdb->type; 138 139 /* Ignore changes to the system ACL. This has the effect of making 140 changes through the security tab audit button not sticking. 141 Perhaps in future Samba could implement these settings somehow. */ 142 143 sacl = NULL; 144 secdesc_type &= ~SEC_DESC_SACL_PRESENT; 145 146 /* Copy across discretionary ACL */ 147 148 if (secdesc_type & SEC_DESC_DACL_PRESENT) { 149 dacl = new_sdb->dacl; 150 } else { 151 dacl = old_sdb->dacl; 152 } 153 154 /* Create new security descriptor from bits */ 155 psd = make_sec_desc(ctx, new_sdb->revision, secdesc_type, 156 owner_sid, group_sid, sacl, dacl, &secdesc_size); 157 158 return psd; 159 } 160 161 /******************************************************************* 162 Creates a struct security_descriptor structure 163 ********************************************************************/ 164 165 #define SEC_DESC_HEADER_SIZE (2 * sizeof(uint16) + 4 * sizeof(uint32)) 166 167 struct security_descriptor *make_sec_desc(TALLOC_CTX *ctx, 116 168 enum security_descriptor_revision revision, 117 169 uint16 type, 118 const DOM_SID *owner_sid, const DOM_SID*grp_sid,119 SEC_ACL *sacl, SEC_ACL*dacl, size_t *sd_size)120 { 121 SEC_DESC*dst;170 const struct dom_sid *owner_sid, const struct dom_sid *grp_sid, 171 struct security_acl *sacl, struct security_acl *dacl, size_t *sd_size) 172 { 173 struct security_descriptor *dst; 122 174 uint32 offset = 0; 123 175 124 176 *sd_size = 0; 125 177 126 if(( dst = TALLOC_ZERO_P(ctx, SEC_DESC)) == NULL)178 if(( dst = TALLOC_ZERO_P(ctx, struct security_descriptor)) == NULL) 127 179 return NULL; 128 180 … … 140 192 dst->dacl = NULL; 141 193 142 if(owner_sid && ((dst->owner_sid = sid_dup_talloc(dst,owner_sid)) == NULL))194 if(owner_sid && ((dst->owner_sid = dom_sid_dup(dst,owner_sid)) == NULL)) 143 195 goto error_exit; 144 196 145 if(grp_sid && ((dst->group_sid = sid_dup_talloc(dst,grp_sid)) == NULL))197 if(grp_sid && ((dst->group_sid = dom_sid_dup(dst,grp_sid)) == NULL)) 146 198 goto error_exit; 147 199 … … 166 218 167 219 if (dst->owner_sid != NULL) { 168 offset += ndr_size_dom_sid(dst->owner_sid, NULL,0);220 offset += ndr_size_dom_sid(dst->owner_sid, 0); 169 221 } 170 222 171 223 if (dst->group_sid != NULL) { 172 offset += ndr_size_dom_sid(dst->group_sid, NULL,0);224 offset += ndr_size_dom_sid(dst->group_sid, 0); 173 225 } 174 226 … … 183 235 184 236 /******************************************************************* 185 Duplicate a SEC_DESC structure.186 ********************************************************************/ 187 188 SEC_DESC *dup_sec_desc(TALLOC_CTX *ctx, const SEC_DESC*src)237 Duplicate a struct security_descriptor structure. 238 ********************************************************************/ 239 240 struct security_descriptor *dup_sec_desc(TALLOC_CTX *ctx, const struct security_descriptor *src) 189 241 { 190 242 size_t dummy; … … 209 261 210 262 ndr_err = ndr_push_struct_blob( 211 &blob, mem_ctx, NULL,secdesc,263 &blob, mem_ctx, secdesc, 212 264 (ndr_push_flags_fn_t)ndr_push_security_descriptor); 213 265 … … 215 267 DEBUG(0, ("ndr_push_security_descriptor failed: %s\n", 216 268 ndr_errstr(ndr_err))); 217 return ndr_map_error2ntstatus(ndr_err); ;269 return ndr_map_error2ntstatus(ndr_err); 218 270 } 219 271 … … 235 287 236 288 ndr_err = ndr_push_struct_blob( 237 &blob, mem_ctx, NULL,secdesc_buf,289 &blob, mem_ctx, secdesc_buf, 238 290 (ndr_push_flags_fn_t)ndr_push_sec_desc_buf); 239 291 … … 241 293 DEBUG(0, ("ndr_push_sec_desc_buf failed: %s\n", 242 294 ndr_errstr(ndr_err))); 243 return ndr_map_error2ntstatus(ndr_err); ;295 return ndr_map_error2ntstatus(ndr_err); 244 296 } 245 297 … … 270 322 blob = data_blob_const(data, len); 271 323 272 ndr_err = ndr_pull_struct_blob( 273 &blob, result, NULL, result, 324 ndr_err = ndr_pull_struct_blob(&blob, result, result, 274 325 (ndr_pull_flags_fn_t)ndr_pull_security_descriptor); 275 326 … … 278 329 ndr_errstr(ndr_err))); 279 330 TALLOC_FREE(result); 280 return ndr_map_error2ntstatus(ndr_err); ;331 return ndr_map_error2ntstatus(ndr_err); 281 332 } 282 333 … … 307 358 blob = data_blob_const(data, len); 308 359 309 ndr_err = ndr_pull_struct_blob( 310 &blob, result, NULL, result, 360 ndr_err = ndr_pull_struct_blob(&blob, result, result, 311 361 (ndr_pull_flags_fn_t)ndr_pull_sec_desc_buf); 312 362 … … 315 365 ndr_errstr(ndr_err))); 316 366 TALLOC_FREE(result); 317 return ndr_map_error2ntstatus(ndr_err); ;367 return ndr_map_error2ntstatus(ndr_err); 318 368 } 319 369 … … 323 373 324 374 /******************************************************************* 325 Creates a SEC_DESCstructure with typical defaults.326 ********************************************************************/ 327 328 SEC_DESC *make_standard_sec_desc(TALLOC_CTX *ctx, const DOM_SID *owner_sid, const DOM_SID*grp_sid,329 SEC_ACL*dacl, size_t *sd_size)375 Creates a struct security_descriptor structure with typical defaults. 376 ********************************************************************/ 377 378 struct security_descriptor *make_standard_sec_desc(TALLOC_CTX *ctx, const struct dom_sid *owner_sid, const struct dom_sid *grp_sid, 379 struct security_acl *dacl, size_t *sd_size) 330 380 { 331 381 return make_sec_desc(ctx, SECURITY_DESCRIPTOR_REVISION_1, … … 335 385 336 386 /******************************************************************* 337 Creates a SEC_DESC_BUFstructure.338 ********************************************************************/ 339 340 SEC_DESC_BUF *make_sec_desc_buf(TALLOC_CTX *ctx, size_t len, SEC_DESC*sec_desc)341 { 342 SEC_DESC_BUF*dst;343 344 if((dst = TALLOC_ZERO_P(ctx, SEC_DESC_BUF)) == NULL)387 Creates a struct sec_desc_buf structure. 388 ********************************************************************/ 389 390 struct sec_desc_buf *make_sec_desc_buf(TALLOC_CTX *ctx, size_t len, struct security_descriptor *sec_desc) 391 { 392 struct sec_desc_buf *dst; 393 394 if((dst = TALLOC_ZERO_P(ctx, struct sec_desc_buf)) == NULL) 345 395 return NULL; 346 396 … … 356 406 357 407 /******************************************************************* 358 Duplicates a SEC_DESC_BUFstructure.359 ********************************************************************/ 360 361 SEC_DESC_BUF *dup_sec_desc_buf(TALLOC_CTX *ctx, SEC_DESC_BUF*src)408 Duplicates a struct sec_desc_buf structure. 409 ********************************************************************/ 410 411 struct sec_desc_buf *dup_sec_desc_buf(TALLOC_CTX *ctx, struct sec_desc_buf *src) 362 412 { 363 413 if(src == NULL) … … 368 418 369 419 /******************************************************************* 370 Add a new SID with its permissions to SEC_DESC.371 ********************************************************************/ 372 373 NTSTATUS sec_desc_add_sid(TALLOC_CTX *ctx, SEC_DESC **psd, DOM_SID*sid, uint32 mask, size_t *sd_size)374 { 375 SEC_DESC*sd = 0;376 SEC_ACL*dacl = 0;377 SEC_ACE*ace = 0;420 Add a new SID with its permissions to struct security_descriptor. 421 ********************************************************************/ 422 423 NTSTATUS sec_desc_add_sid(TALLOC_CTX *ctx, struct security_descriptor **psd, const struct dom_sid *sid, uint32 mask, size_t *sd_size) 424 { 425 struct security_descriptor *sd = 0; 426 struct security_acl *dacl = 0; 427 struct security_ace *ace = 0; 378 428 NTSTATUS status; 379 429 … … 401 451 402 452 /******************************************************************* 403 Modify a SID's permissions in a SEC_DESC.404 ********************************************************************/ 405 406 NTSTATUS sec_desc_mod_sid( SEC_DESC *sd, DOM_SID*sid, uint32 mask)453 Modify a SID's permissions in a struct security_descriptor. 454 ********************************************************************/ 455 456 NTSTATUS sec_desc_mod_sid(struct security_descriptor *sd, struct dom_sid *sid, uint32 mask) 407 457 { 408 458 NTSTATUS status; … … 420 470 421 471 /******************************************************************* 422 Delete a SID from a SEC_DESC.423 ********************************************************************/ 424 425 NTSTATUS sec_desc_del_sid(TALLOC_CTX *ctx, SEC_DESC **psd, DOM_SID*sid, size_t *sd_size)426 { 427 SEC_DESC*sd = 0;428 SEC_ACL*dacl = 0;429 SEC_ACE*ace = 0;472 Delete a SID from a struct security_descriptor. 473 ********************************************************************/ 474 475 NTSTATUS sec_desc_del_sid(TALLOC_CTX *ctx, struct security_descriptor **psd, struct dom_sid *sid, size_t *sd_size) 476 { 477 struct security_descriptor *sd = 0; 478 struct security_acl *dacl = 0; 479 struct security_ace *ace = 0; 430 480 NTSTATUS status; 431 481 … … 453 503 454 504 /* 455 * Determine if an ACEis inheritable505 * Determine if an struct security_ace is inheritable 456 506 */ 457 507 458 static bool is_inheritable_ace(const SEC_ACE*ace,508 static bool is_inheritable_ace(const struct security_ace *ace, 459 509 bool container) 460 510 { … … 480 530 */ 481 531 482 bool sd_has_inheritable_components(const SEC_DESC*parent_ctr, bool container)532 bool sd_has_inheritable_components(const struct security_descriptor *parent_ctr, bool container) 483 533 { 484 534 unsigned int i; 485 const SEC_ACL*the_acl = parent_ctr->dacl;535 const struct security_acl *the_acl = parent_ctr->dacl; 486 536 487 537 for (i = 0; i < the_acl->num_aces; i++) { 488 const SEC_ACE*ace = &the_acl->aces[i];538 const struct security_ace *ace = &the_acl->aces[i]; 489 539 490 540 if (is_inheritable_ace(ace, container)) { … … 500 550 501 551 NTSTATUS se_create_child_secdesc(TALLOC_CTX *ctx, 502 SEC_DESC**ppsd,552 struct security_descriptor **ppsd, 503 553 size_t *psize, 504 const SEC_DESC*parent_ctr,505 const DOM_SID*owner_sid,506 const DOM_SID*group_sid,554 const struct security_descriptor *parent_ctr, 555 const struct dom_sid *owner_sid, 556 const struct dom_sid *group_sid, 507 557 bool container) 508 558 { 509 SEC_ACL*new_dacl = NULL, *the_acl = NULL;510 SEC_ACE*new_ace_list = NULL;559 struct security_acl *new_dacl = NULL, *the_acl = NULL; 560 struct security_ace *new_ace_list = NULL; 511 561 unsigned int new_ace_list_ndx = 0, i; 512 562 … … 525 575 } 526 576 527 if (!(new_ace_list = TALLOC_ARRAY(ctx, SEC_ACE,577 if (!(new_ace_list = TALLOC_ARRAY(ctx, struct security_ace, 528 578 2*the_acl->num_aces))) { 529 579 return NT_STATUS_NO_MEMORY; … … 534 584 535 585 for (i = 0; i < the_acl->num_aces; i++) { 536 const SEC_ACE*ace = &the_acl->aces[i];537 SEC_ACE*new_ace = &new_ace_list[new_ace_list_ndx];538 const DOM_SID*ptrustee = &ace->trustee;539 const DOM_SID*creator = NULL;586 const struct security_ace *ace = &the_acl->aces[i]; 587 struct security_ace *new_ace = &new_ace_list[new_ace_list_ndx]; 588 const struct dom_sid *ptrustee = &ace->trustee; 589 const struct dom_sid *creator = NULL; 540 590 uint8 new_flags = ace->flags; 541 591 … … 559 609 560 610 /* The CREATOR sids are special when inherited */ 561 if ( sid_equal(ptrustee, &global_sid_Creator_Owner)) {611 if (dom_sid_equal(ptrustee, &global_sid_Creator_Owner)) { 562 612 creator = &global_sid_Creator_Owner; 563 613 ptrustee = owner_sid; 564 } else if ( sid_equal(ptrustee, &global_sid_Creator_Group)) {614 } else if (dom_sid_equal(ptrustee, &global_sid_Creator_Group)) { 565 615 creator = &global_sid_Creator_Group; 566 616 ptrustee = group_sid; … … 635 685 636 686 NTSTATUS se_create_child_secdesc_buf(TALLOC_CTX *ctx, 637 SEC_DESC_BUF**ppsdb,638 const SEC_DESC*parent_ctr,687 struct sec_desc_buf **ppsdb, 688 const struct security_descriptor *parent_ctr, 639 689 bool container) 640 690 { 641 691 NTSTATUS status; 642 692 size_t size = 0; 643 SEC_DESC*sd = NULL;693 struct security_descriptor *sd = NULL; 644 694 645 695 *ppsdb = NULL;
Note:
See TracChangeset
for help on using the changeset viewer.