Changeset 228 for branches/samba-3.2.x/source/utils/smbcacls.c
- Timestamp:
- May 26, 2009, 9:44:50 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/samba-3.2.x/source/utils/smbcacls.c
r141 r228 24 24 #include "includes.h" 25 25 26 static int test_args = False;26 static int test_args; 27 27 28 28 #define CREATE_ACCESS_READ READ_CONTROL_ACCESS … … 30 30 /* numeric is set when the user wants numeric SIDs and ACEs rather 31 31 than going via LSA calls to resolve them */ 32 static int numeric = False;32 static int numeric; 33 33 34 34 enum acl_mode {SMB_ACL_SET, SMB_ACL_DELETE, SMB_ACL_MODIFY, SMB_ACL_ADD }; … … 182 182 } 183 183 184 slprintf(str, sizeof(fstring) - 1, "%s%s%s", 185 domain, lp_winbind_separator(), name); 186 184 if (*domain) { 185 slprintf(str, sizeof(fstring) - 1, "%s%s%s", 186 domain, lp_winbind_separator(), name); 187 } else { 188 fstrcpy(str, name); 189 } 187 190 } 188 191 … … 199 202 } 200 203 204 static void print_ace_flags(FILE *f, uint8_t flags) 205 { 206 char *str = talloc_strdup(NULL, ""); 207 208 if (!str) { 209 goto out; 210 } 211 212 if (flags & SEC_ACE_FLAG_OBJECT_INHERIT) { 213 str = talloc_asprintf(str, "%s%s", 214 str, "OI|"); 215 if (!str) { 216 goto out; 217 } 218 } 219 if (flags & SEC_ACE_FLAG_CONTAINER_INHERIT) { 220 str = talloc_asprintf(str, "%s%s", 221 str, "CI|"); 222 if (!str) { 223 goto out; 224 } 225 } 226 if (flags & SEC_ACE_FLAG_NO_PROPAGATE_INHERIT) { 227 str = talloc_asprintf(str, "%s%s", 228 str, "NP|"); 229 if (!str) { 230 goto out; 231 } 232 } 233 if (flags & SEC_ACE_FLAG_INHERIT_ONLY) { 234 str = talloc_asprintf(str, "%s%s", 235 str, "IO|"); 236 if (!str) { 237 goto out; 238 } 239 } 240 if (flags & SEC_ACE_FLAG_INHERITED_ACE) { 241 str = talloc_asprintf(str, "%s%s", 242 str, "I|"); 243 if (!str) { 244 goto out; 245 } 246 } 247 /* Ignore define SEC_ACE_FLAG_SUCCESSFUL_ACCESS ( 0x40 ) 248 and SEC_ACE_FLAG_FAILED_ACCESS ( 0x80 ) as they're 249 audit ace flags. */ 250 251 if (str[strlen(str)-1] == '|') { 252 str[strlen(str)-1] = '\0'; 253 fprintf(f, "/%s/", str); 254 } else { 255 fprintf(f, "/0x%x/", flags); 256 } 257 TALLOC_FREE(str); 258 return; 259 260 out: 261 fprintf(f, "/0x%x/", flags); 262 } 201 263 202 264 /* print an ACE on a FILE, using either numeric or ascii representation */ … … 213 275 214 276 if (numeric) { 215 fprintf(f, "%d/ %d/0x%08x",277 fprintf(f, "%d/0x%x/0x%08x", 216 278 ace->type, ace->flags, ace->access_mask); 217 279 return; … … 228 290 } 229 291 230 /* Not sure what flags can be set in a file ACL */ 231 232 fprintf(f, "/%d/", ace->flags); 292 print_ace_flags(f, ace->flags); 233 293 234 294 /* Standard permissions */ … … 266 326 } 267 327 328 static bool parse_ace_flags(const char *str, unsigned int *pflags) 329 { 330 const char *p = str; 331 *pflags = 0; 332 333 while (*p) { 334 if (strnequal(p, "OI", 2)) { 335 *pflags |= SEC_ACE_FLAG_OBJECT_INHERIT; 336 p += 2; 337 } else if (strnequal(p, "CI", 2)) { 338 *pflags |= SEC_ACE_FLAG_CONTAINER_INHERIT; 339 p += 2; 340 } else if (strnequal(p, "NP", 2)) { 341 *pflags |= SEC_ACE_FLAG_NO_PROPAGATE_INHERIT; 342 p += 2; 343 } else if (strnequal(p, "IO", 2)) { 344 *pflags |= SEC_ACE_FLAG_INHERIT_ONLY; 345 p += 2; 346 } else if (*p == 'I') { 347 *pflags |= SEC_ACE_FLAG_INHERITED_ACE; 348 p += 1; 349 } else if (*p) { 350 return false; 351 } 352 353 if (*p != '|' && *p != '\0') { 354 return false; 355 } 356 } 357 return true; 358 } 268 359 269 360 /* parse an ACE in the same format as print_ace() */ … … 338 429 /* Only numeric form accepted for flags at present */ 339 430 340 if (!(next_token_talloc(frame, &cp, &tok, "/") && 341 sscanf(tok, "%i", &aflags))) { 342 printf("ACE '%s': bad integer flags entry at '%s'\n", 431 if (!next_token_talloc(frame, &cp, &tok, "/")) { 432 printf("ACE '%s': bad flags entry at '%s'\n", 343 433 orig_str, tok); 344 434 SAFE_FREE(str); 345 435 TALLOC_FREE(frame); 346 436 return False; 437 } 438 439 if (tok[0] < '0' || tok[0] > '9') { 440 if (!parse_ace_flags(tok, &aflags)) { 441 printf("ACE '%s': bad named flags entry at '%s'\n", 442 orig_str, tok); 443 SAFE_FREE(str); 444 TALLOC_FREE(frame); 445 return False; 446 } 447 } else if (strnequal(tok, "0x", 2)) { 448 if (!sscanf(tok, "%x", &aflags)) { 449 printf("ACE '%s': bad hex flags entry at '%s'\n", 450 orig_str, tok); 451 SAFE_FREE(str); 452 TALLOC_FREE(frame); 453 return False; 454 } 455 } else { 456 if (!sscanf(tok, "%i", &aflags)) { 457 printf("ACE '%s': bad integer flags entry at '%s'\n", 458 orig_str, tok); 459 SAFE_FREE(str); 460 TALLOC_FREE(frame); 461 return False; 462 } 347 463 } 348 464 … … 509 625 510 626 fprintf(f, "REVISION:%d\n", sd->revision); 627 fprintf(f, "CONTROL:0x%x\n", sd->type); 511 628 512 629 /* Print owner and group sid */ … … 629 746 630 747 631 /* The MSDN is contradictory over the ordering of ACE entries in an ACL. 632 However NT4 gives a "The information may have been modified by a 633 computer running Windows NT 5.0" if denied ACEs do not appear before 634 allowed ACEs. */ 748 /* The MSDN is contradictory over the ordering of ACE entries in an 749 ACL. However NT4 gives a "The information may have been modified 750 by a computer running Windows NT 5.0" if denied ACEs do not appear 751 before allowed ACEs. At 752 http://technet.microsoft.com/en-us/library/cc781716.aspx the 753 canonical order is specified as "Explicit Deny, Explicit Allow, 754 Inherited ACEs unchanged" */ 635 755 636 756 static int ace_compare(SEC_ACE *ace1, SEC_ACE *ace2) 637 757 { 638 if (sec_ace_equal(ace1, ace2)) 758 if (sec_ace_equal(ace1, ace2)) 639 759 return 0; 640 760 641 if (ace1->type != ace2->type) 761 if ((ace1->flags & SEC_ACE_FLAG_INHERITED_ACE) && 762 !(ace2->flags & SEC_ACE_FLAG_INHERITED_ACE)) 763 return 1; 764 if (!(ace1->flags & SEC_ACE_FLAG_INHERITED_ACE) && 765 (ace2->flags & SEC_ACE_FLAG_INHERITED_ACE)) 766 return -1; 767 if ((ace1->flags & SEC_ACE_FLAG_INHERITED_ACE) && 768 (ace2->flags & SEC_ACE_FLAG_INHERITED_ACE)) 769 return ace1 - ace2; 770 771 if (ace1->type != ace2->type) 642 772 return ace2->type - ace1->type; 643 773 644 if (sid_compare(&ace1->trustee, &ace2->trustee)) 774 if (sid_compare(&ace1->trustee, &ace2->trustee)) 645 775 return sid_compare(&ace1->trustee, &ace2->trustee); 646 776 647 if (ace1->flags != ace2->flags) 777 if (ace1->flags != ace2->flags) 648 778 return ace1->flags - ace2->flags; 649 779 650 if (ace1->access_mask != ace2->access_mask) 780 if (ace1->access_mask != ace2->access_mask) 651 781 return ace1->access_mask - ace2->access_mask; 652 782 653 if (ace1->size != ace2->size) 783 if (ace1->size != ace2->size) 654 784 return ace1->size - ace2->size; 655 785 … … 680 810 set the ACLs on a file given an ascii description 681 811 *******************************************************/ 812 682 813 static int cacl_set(struct cli_state *cli, char *filename, 683 814 char *the_acl, enum acl_mode mode) … … 733 864 734 865 if (!found) { 735 printf("ACL for ACE:"); 866 printf("ACL for ACE:"); 736 867 print_ace(cli, stdout, &sd->dacl->aces[i]); 737 868 printf(" not found\n"); … … 765 896 } 766 897 767 if (sd->group_sid) { 898 if (sd->group_sid) { 768 899 old->group_sid = sd->group_sid; 769 900 } … … 828 959 uint32_t flags = 0; 829 960 830 zero_ addr(&ss);961 zero_sockaddr(&ss); 831 962 832 963 if (get_cmdline_auth_info_use_kerberos()) { … … 898 1029 { "chown", 'C', POPT_ARG_STRING, NULL, 'C', "Change ownership of a file", "USERNAME" }, 899 1030 { "chgrp", 'G', POPT_ARG_STRING, NULL, 'G', "Change group ownership of a file", "GROUPNAME" }, 900 { "numeric", 0, POPT_ARG_NONE, &numeric, True, "Don't resolve sids or masks to names" },901 { "test-args", 't', POPT_ARG_NONE, &test_args, True, "Test arguments"},1031 { "numeric", 0, POPT_ARG_NONE, &numeric, 1, "Don't resolve sids or masks to names" }, 1032 { "test-args", 't', POPT_ARG_NONE, &test_args, 1, "Test arguments"}, 902 1033 POPT_COMMON_SAMBA 903 1034 POPT_COMMON_CONNECTION
Note:
See TracChangeset
for help on using the changeset viewer.