Ignore:
Timestamp:
May 26, 2009, 9:44:50 AM (16 years ago)
Author:
Herwig Bauernfeind
Message:

Update 3.2 branch to 3.2.6

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/samba-3.2.x/source/utils/smbcacls.c

    r141 r228  
    2424#include "includes.h"
    2525
    26 static int test_args = False;
     26static int test_args;
    2727
    2828#define CREATE_ACCESS_READ READ_CONTROL_ACCESS
     
    3030/* numeric is set when the user wants numeric SIDs and ACEs rather
    3131   than going via LSA calls to resolve them */
    32 static int numeric = False;
     32static int numeric;
    3333
    3434enum acl_mode {SMB_ACL_SET, SMB_ACL_DELETE, SMB_ACL_MODIFY, SMB_ACL_ADD };
     
    182182        }
    183183
    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        }
    187190}
    188191
     
    199202}
    200203
     204static 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}
    201263
    202264/* print an ACE on a FILE, using either numeric or ascii representation */
     
    213275
    214276        if (numeric) {
    215                 fprintf(f, "%d/%d/0x%08x",
     277                fprintf(f, "%d/0x%x/0x%08x",
    216278                        ace->type, ace->flags, ace->access_mask);
    217279                return;
     
    228290        }
    229291
    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);
    233293
    234294        /* Standard permissions */
     
    266326}
    267327
     328static 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}
    268359
    269360/* parse an ACE in the same format as print_ace() */
     
    338429        /* Only numeric form accepted for flags at present */
    339430
    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",
    343433                        orig_str, tok);
    344434                SAFE_FREE(str);
    345435                TALLOC_FREE(frame);
    346436                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                }
    347463        }
    348464
     
    509625
    510626        fprintf(f, "REVISION:%d\n", sd->revision);
     627        fprintf(f, "CONTROL:0x%x\n", sd->type);
    511628
    512629        /* Print owner and group sid */
     
    629746
    630747
    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" */
    635755
    636756static int ace_compare(SEC_ACE *ace1, SEC_ACE *ace2)
    637757{
    638         if (sec_ace_equal(ace1, ace2)) 
     758        if (sec_ace_equal(ace1, ace2))
    639759                return 0;
    640760
    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)
    642772                return ace2->type - ace1->type;
    643773
    644         if (sid_compare(&ace1->trustee, &ace2->trustee)) 
     774        if (sid_compare(&ace1->trustee, &ace2->trustee))
    645775                return sid_compare(&ace1->trustee, &ace2->trustee);
    646776
    647         if (ace1->flags != ace2->flags) 
     777        if (ace1->flags != ace2->flags)
    648778                return ace1->flags - ace2->flags;
    649779
    650         if (ace1->access_mask != ace2->access_mask) 
     780        if (ace1->access_mask != ace2->access_mask)
    651781                return ace1->access_mask - ace2->access_mask;
    652782
    653         if (ace1->size != ace2->size) 
     783        if (ace1->size != ace2->size)
    654784                return ace1->size - ace2->size;
    655785
     
    680810set the ACLs on a file given an ascii description
    681811*******************************************************/
     812
    682813static int cacl_set(struct cli_state *cli, char *filename,
    683814                    char *the_acl, enum acl_mode mode)
     
    733864
    734865                        if (!found) {
    735                                 printf("ACL for ACE:"); 
     866                                printf("ACL for ACE:");
    736867                                print_ace(cli, stdout, &sd->dacl->aces[i]);
    737868                                printf(" not found\n");
     
    765896                }
    766897
    767                 if (sd->group_sid) { 
     898                if (sd->group_sid) {
    768899                        old->group_sid = sd->group_sid;
    769900                }
     
    828959        uint32_t flags = 0;
    829960
    830         zero_addr(&ss);
     961        zero_sockaddr(&ss);
    831962
    832963        if (get_cmdline_auth_info_use_kerberos()) {
     
    8981029                { "chown", 'C', POPT_ARG_STRING, NULL, 'C', "Change ownership of a file", "USERNAME" },
    8991030                { "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"},
    9021033                POPT_COMMON_SAMBA
    9031034                POPT_COMMON_CONNECTION
Note: See TracChangeset for help on using the changeset viewer.