Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/libsmb/libsmb_xattr.c

    r414 r745  
    88   Copyright (C) Derrell Lipman 2003-2008
    99   Copyright (C) Jeremy Allison 2007, 2008
    10    
     10
    1111   This program is free software; you can redistribute it and/or modify
    1212   it under the terms of the GNU General Public License as published by
    1313   the Free Software Foundation; either version 3 of the License, or
    1414   (at your option) any later version.
    15    
     15
    1616   This program is distributed in the hope that it will be useful,
    1717   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1818   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1919   GNU General Public License for more details.
    20    
     20
    2121   You should have received a copy of the GNU General Public License
    2222   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2424
    2525#include "includes.h"
     26#include "libsmb/libsmb.h"
    2627#include "libsmbclient.h"
    2728#include "libsmb_internal.h"
    28 
     29#include "../librpc/gen_ndr/ndr_lsa.h"
     30#include "rpc_client/rpc_client.h"
     31#include "rpc_client/cli_lsarpc.h"
     32#include "../libcli/security/security.h"
    2933
    3034/*
     
    3539{
    3640        struct rpc_pipe_client *pipe_hnd;
    37        
     41
    3842        for (pipe_hnd = ipc_cli->pipe_list;
    3943             pipe_hnd;
    4044             pipe_hnd = pipe_hnd->next) {
    41                
    4245                if (ndr_syntax_id_equal(&pipe_hnd->abstract_syntax,
    4346                                        &ndr_table_lsarpc.syntax_id)) {
     
    4548                }
    4649        }
    47        
    4850        return NULL;
    4951}
     
    5658
    5759static int
    58 ace_compare(SEC_ACE *ace1,
    59             SEC_ACE *ace2)
     60ace_compare(struct security_ace *ace1,
     61            struct security_ace *ace2)
    6062{
    6163        bool b1;
    6264        bool b2;
    63        
     65
    6466        /* If the ACEs are equal, we have nothing more to do. */
    6567        if (sec_ace_equal(ace1, ace2)) {
    6668                return 0;
    6769        }
    68        
     70
    6971        /* Inherited follow non-inherited */
    7072        b1 = ((ace1->flags & SEC_ACE_FLAG_INHERITED_ACE) != 0);
     
    7375                return (b1 ? 1 : -1);
    7476        }
    75        
     77
    7678        /*
    7779         * What shall we do with AUDITs and ALARMs?  It's undefined.  We'll
     
    8991                return (b1 ? 1 : -1);
    9092        }
    91        
     93
    9294        /* Allowed ACEs follow denied ACEs */
    9395        b1 = (ace1->type == SEC_ACE_TYPE_ACCESS_ALLOWED ||
     
    98100                return (b1 ? 1 : -1);
    99101        }
    100        
     102
    101103        /*
    102104         * ACEs applying to an entity's object follow those applying to the
     
    110112                return (b1 ? 1 : -1);
    111113        }
    112        
     114
    113115        /*
    114116         * If we get this far, the ACEs are similar as far as the
     
    117119         * just seems reasonable.
    118120         */
    119        
     121
    120122        if (ace1->type != ace2->type) {
    121123                return ace2->type - ace1->type;
    122124        }
    123        
    124         if (sid_compare(&ace1->trustee, &ace2->trustee)) {
    125                 return sid_compare(&ace1->trustee, &ace2->trustee);
    126         }
    127        
     125
     126        if (dom_sid_compare(&ace1->trustee, &ace2->trustee)) {
     127                return dom_sid_compare(&ace1->trustee, &ace2->trustee);
     128        }
     129
    128130        if (ace1->flags != ace2->flags) {
    129131                return ace1->flags - ace2->flags;
    130132        }
    131        
     133
    132134        if (ace1->access_mask != ace2->access_mask) {
    133135                return ace1->access_mask - ace2->access_mask;
    134136        }
    135        
     137
    136138        if (ace1->size != ace2->size) {
    137139                return ace1->size - ace2->size;
    138140        }
    139        
    140         return memcmp(ace1, ace2, sizeof(SEC_ACE));
     141
     142        return memcmp(ace1, ace2, sizeof(struct security_ace));
    141143}
    142144
    143145
    144146static void
    145 sort_acl(SEC_ACL *the_acl)
     147sort_acl(struct security_acl *the_acl)
    146148{
    147149        uint32 i;
    148150        if (!the_acl) return;
    149        
    150         qsort(the_acl->aces, the_acl->num_aces, sizeof(the_acl->aces[0]),
    151               QSORT_CAST ace_compare);
    152        
     151
     152        TYPESAFE_QSORT(the_acl->aces, the_acl->num_aces, ace_compare);
     153
    153154        for (i=1;i<the_acl->num_aces;) {
    154155                if (sec_ace_equal(&the_acl->aces[i-1], &the_acl->aces[i])) {
     
    170171                      fstring str,
    171172                      bool numeric,
    172                       DOM_SID *sid)
     173                      struct dom_sid *sid)
    173174{
    174175        char **domains = NULL;
     
    177178        struct rpc_pipe_client *pipe_hnd = find_lsa_pipe_hnd(ipc_cli);
    178179        TALLOC_CTX *ctx;
    179        
     180
    180181        sid_to_fstring(str, sid);
    181        
     182
    182183        if (numeric) {
    183184                return;     /* no lookup desired */
    184185        }
    185        
     186
    186187        if (!pipe_hnd) {
    187188                return;
    188189        }
    189        
     190
    190191        /* Ask LSA to convert the sid to a name */
    191        
     192
    192193        ctx = talloc_stackframe();
    193        
     194
    194195        if (!NT_STATUS_IS_OK(rpccli_lsa_lookup_sids(pipe_hnd, ctx,
    195196                                                    pol, 1, sid, &domains,
     
    199200                return;
    200201        }
    201        
     202
    202203        /* Converted OK */
    203        
     204
    204205        slprintf(str, sizeof(fstring) - 1, "%s%s%s",
    205206                 domains[0], lp_winbind_separator(),
     
    214215                      struct policy_handle *pol,
    215216                      bool numeric,
    216                       DOM_SID *sid,
     217                      struct dom_sid *sid,
    217218                      const char *str)
    218219{
    219220        enum lsa_SidType *types = NULL;
    220         DOM_SID *sids = NULL;
     221        struct dom_sid *sids = NULL;
    221222        bool result = True;
    222223        TALLOC_CTX *ctx = NULL;
    223224        struct rpc_pipe_client *pipe_hnd = find_lsa_pipe_hnd(ipc_cli);
    224        
     225
    225226        if (!pipe_hnd) {
    226227                return False;
    227228        }
    228        
     229
    229230        if (numeric) {
    230231                if (strncmp(str, "S-", 2) == 0) {
    231232                        return string_to_sid(sid, str);
    232233                }
    233                
     234
    234235                result = False;
    235236                goto done;
    236237        }
    237        
     238
    238239        ctx = talloc_stackframe();
    239240        if (!NT_STATUS_IS_OK(rpccli_lsa_lookup_names(pipe_hnd, ctx,
     
    244245                goto done;
    245246        }
    246        
     247
    247248        sid_copy(sid, &sids[0]);
    248249done:
    249        
    250250        TALLOC_FREE(ctx);
    251251        return result;
     
    253253
    254254
    255 /* parse an ACE in the same format as print_ace() */
     255/* parse an struct security_ace in the same format as print_ace() */
    256256static bool
    257257parse_ace(struct cli_state *ipc_cli,
    258258          struct policy_handle *pol,
    259           SEC_ACE *ace,
     259          struct security_ace *ace,
    260260          bool numeric,
    261261          char *str)
     
    267267        unsigned int aflags;
    268268        unsigned int amask;
    269         DOM_SID sid;
     269        struct dom_sid sid;
    270270        uint32_t mask;
    271271        const struct perm_value *v;
     
    275275        };
    276276        TALLOC_CTX *frame = talloc_stackframe();
    277        
     277
    278278        /* These values discovered by inspection */
    279279        static const struct perm_value special_values[] = {
     
    286286                { "", 0 },
    287287        };
    288        
     288
    289289        static const struct perm_value standard_values[] = {
    290290                { "READ",   0x001200a9 },
     
    293293                { "", 0 },
    294294        };
    295        
    296        
     295
    297296        ZERO_STRUCTP(ace);
    298297        p = strchr_m(str,':');
     
    304303        p++;
    305304        /* Try to parse numeric form */
    306        
     305
    307306        if (sscanf(p, "%i/%i/%i", &atype, &aflags, &amask) == 3 &&
    308307            convert_string_to_sid(ipc_cli, pol, numeric, &sid, str)) {
    309308                goto done;
    310309        }
    311        
     310
    312311        /* Try to parse text form */
    313        
     312
    314313        if (!convert_string_to_sid(ipc_cli, pol, numeric, &sid, str)) {
    315314                TALLOC_FREE(frame);
    316315                return false;
    317316        }
    318        
     317
    319318        cp = p;
    320319        if (!next_token_talloc(frame, &cp, &tok, "/")) {
     
    322321                return false;
    323322        }
    324        
     323
    325324        if (StrnCaseCmp(tok, "ALLOWED", strlen("ALLOWED")) == 0) {
    326325                atype = SEC_ACE_TYPE_ACCESS_ALLOWED;
     
    331330                return false;
    332331        }
    333        
     332
    334333        /* Only numeric form accepted for flags at present */
    335        
     334
    336335        if (!(next_token_talloc(frame, &cp, &tok, "/") &&
    337336              sscanf(tok, "%i", &aflags))) {
     
    339338                return false;
    340339        }
    341        
     340
    342341        if (!next_token_talloc(frame, &cp, &tok, "/")) {
    343342                TALLOC_FREE(frame);
    344343                return false;
    345344        }
    346        
     345
    347346        if (strncmp(tok, "0x", 2) == 0) {
    348347                if (sscanf(tok, "%i", &amask) != 1) {
     
    352351                goto done;
    353352        }
    354        
     353
    355354        for (v = standard_values; v->perm; v++) {
    356355                if (strcmp(tok, v->perm) == 0) {
     
    359358                }
    360359        }
    361        
     360
    362361        p = tok;
    363        
     362
    364363        while(*p) {
    365364                bool found = False;
    366                
     365
    367366                for (v = special_values; v->perm; v++) {
    368367                        if (v->perm[0] == *p) {
     
    371370                        }
    372371                }
    373                
     372
    374373                if (!found) {
    375374                        TALLOC_FREE(frame);
     
    378377                p++;
    379378        }
    380        
     379
    381380        if (*p) {
    382381                TALLOC_FREE(frame);
    383382                return false;
    384383        }
    385        
     384
    386385done:
    387386        mask = amask;
     
    391390}
    392391
    393 /* add an ACE to a list of ACEs in a SEC_ACL */
     392/* add an struct security_ace to a list of struct security_aces in a struct security_acl */
    394393static bool
    395 add_ace(SEC_ACL **the_acl,
    396         SEC_ACE *ace,
     394add_ace(struct security_acl **the_acl,
     395        struct security_ace *ace,
    397396        TALLOC_CTX *ctx)
    398397{
    399         SEC_ACL *newacl;
    400         SEC_ACE *aces;
    401        
     398        struct security_acl *newacl;
     399        struct security_ace *aces;
     400
    402401        if (! *the_acl) {
    403402                (*the_acl) = make_sec_acl(ctx, 3, 1, ace);
    404403                return True;
    405404        }
    406        
    407         if ((aces = SMB_CALLOC_ARRAY(SEC_ACE,
     405
     406        if ((aces = SMB_CALLOC_ARRAY(struct security_ace,
    408407                                     1+(*the_acl)->num_aces)) == NULL) {
    409408                return False;
    410409        }
    411         memcpy(aces, (*the_acl)->aces, (*the_acl)->num_aces * sizeof(SEC_ACE));
    412         memcpy(aces+(*the_acl)->num_aces, ace, sizeof(SEC_ACE));
     410        memcpy(aces, (*the_acl)->aces, (*the_acl)->num_aces * sizeof(struct security_ace));
     411        memcpy(aces+(*the_acl)->num_aces, ace, sizeof(struct security_ace));
    413412        newacl = make_sec_acl(ctx, (*the_acl)->revision,
    414413                              1+(*the_acl)->num_aces, aces);
     
    420419
    421420/* parse a ascii version of a security descriptor */
    422 static SEC_DESC *
     421static struct security_descriptor *
    423422sec_desc_parse(TALLOC_CTX *ctx,
    424423               struct cli_state *ipc_cli,
     
    429428        const char *p = str;
    430429        char *tok;
    431         SEC_DESC *ret = NULL;
     430        struct security_descriptor *ret = NULL;
    432431        size_t sd_size;
    433         DOM_SID *group_sid=NULL;
    434         DOM_SID *owner_sid=NULL;
    435         SEC_ACL *dacl=NULL;
     432        struct dom_sid *group_sid=NULL;
     433        struct dom_sid *owner_sid=NULL;
     434        struct security_acl *dacl=NULL;
    436435        int revision=1;
    437        
     436
    438437        while (next_token_talloc(ctx, &p, &tok, "\t,\r\n")) {
    439                
     438
    440439                if (StrnCaseCmp(tok,"REVISION:", 9) == 0) {
    441440                        revision = strtol(tok+9, NULL, 16);
    442441                        continue;
    443442                }
    444                
     443
    445444                if (StrnCaseCmp(tok,"OWNER:", 6) == 0) {
    446445                        if (owner_sid) {
     
    448447                                goto done;
    449448                        }
    450                         owner_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
     449                        owner_sid = SMB_CALLOC_ARRAY(struct dom_sid, 1);
    451450                        if (!owner_sid ||
    452451                            !convert_string_to_sid(ipc_cli, pol,
     
    458457                        continue;
    459458                }
    460                
     459
    461460                if (StrnCaseCmp(tok,"OWNER+:", 7) == 0) {
    462461                        if (owner_sid) {
     
    464463                                goto done;
    465464                        }
    466                         owner_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
     465                        owner_sid = SMB_CALLOC_ARRAY(struct dom_sid, 1);
    467466                        if (!owner_sid ||
    468467                            !convert_string_to_sid(ipc_cli, pol,
     
    474473                        continue;
    475474                }
    476                
     475
    477476                if (StrnCaseCmp(tok,"GROUP:", 6) == 0) {
    478477                        if (group_sid) {
     
    480479                                goto done;
    481480                        }
    482                         group_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
     481                        group_sid = SMB_CALLOC_ARRAY(struct dom_sid, 1);
    483482                        if (!group_sid ||
    484483                            !convert_string_to_sid(ipc_cli, pol,
     
    490489                        continue;
    491490                }
    492                
     491
    493492                if (StrnCaseCmp(tok,"GROUP+:", 7) == 0) {
    494493                        if (group_sid) {
     
    496495                                goto done;
    497496                        }
    498                         group_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
     497                        group_sid = SMB_CALLOC_ARRAY(struct dom_sid, 1);
    499498                        if (!group_sid ||
    500499                            !convert_string_to_sid(ipc_cli, pol,
     
    506505                        continue;
    507506                }
    508                
     507
    509508                if (StrnCaseCmp(tok,"ACL:", 4) == 0) {
    510                         SEC_ACE ace;
     509                        struct security_ace ace;
    511510                        if (!parse_ace(ipc_cli, pol, &ace, numeric, tok+4)) {
    512511                                DEBUG(5, ("Failed to parse ACL %s\n", tok));
     
    519518                        continue;
    520519                }
    521                
     520
    522521                if (StrnCaseCmp(tok,"ACL+:", 5) == 0) {
    523                         SEC_ACE ace;
     522                        struct security_ace ace;
    524523                        if (!parse_ace(ipc_cli, pol, &ace, False, tok+5)) {
    525524                                DEBUG(5, ("Failed to parse ACL %s\n", tok));
     
    532531                        continue;
    533532                }
    534                
     533
    535534                DEBUG(5, ("Failed to parse security descriptor\n"));
    536535                goto done;
    537536        }
    538        
     537
    539538        ret = make_sec_desc(ctx, revision, SEC_DESC_SELF_RELATIVE,
    540539                            owner_sid, group_sid, NULL, dacl, &sd_size);
    541        
     540
    542541done:
    543542        SAFE_FREE(group_sid);
    544543        SAFE_FREE(owner_sid);
    545        
    546544        return ret;
    547545}
     
    563561        SMB_INO_T inode = 0;
    564562        DOS_ATTR_DESC *ret;
    565        
     563
    566564        ret = TALLOC_P(ctx, DOS_ATTR_DESC);
    567565        if (!ret) {
     
    569567                return NULL;
    570568        }
    571        
     569
    572570        /* Obtain the DOS attributes */
    573571        if (!SMBC_getatr(context, srv, CONST_DISCARD(char *, filename),
     
    582580                return NULL;
    583581        }
    584        
     582
    585583        ret->mode = mode;
    586584        ret->size = size;
     
    590588        ret->change_time = convert_timespec_to_time_t(change_time_ts);
    591589        ret->inode = inode;
    592        
     590
    593591        return ret;
    594592}
     
    612610                const char * change_time_attr;
    613611        } attr_strings;
    614        
     612
    615613        /* Determine whether to use old-style or new-style attribute names */
    616614        if (context->internal->full_time_names) {
     
    627625                attr_strings.change_time_attr = "C_TIME";
    628626        }
    629        
     627
    630628        /* if this is to set the entire ACL... */
    631629        if (*str == '*') {
     
    637635                }
    638636        }
    639        
     637
    640638        frame = talloc_stackframe();
    641639        while (next_token_talloc(frame, &p, &tok, "\t,\r\n")) {
     
    652650                        continue;
    653651                }
    654                
     652
    655653                if (StrnCaseCmp(tok, "SIZE:", 5) == 0) {
    656654                        dad->size = (SMB_OFF_T)atof(tok+5);
    657655                        continue;
    658656                }
    659                
     657
    660658                n = strlen(attr_strings.access_time_attr);
    661659                if (StrnCaseCmp(tok, attr_strings.access_time_attr, n) == 0) {
     
    663661                        continue;
    664662                }
    665                
     663
    666664                n = strlen(attr_strings.change_time_attr);
    667665                if (StrnCaseCmp(tok, attr_strings.change_time_attr, n) == 0) {
     
    669667                        continue;
    670668                }
    671                
     669
    672670                n = strlen(attr_strings.write_time_attr);
    673671                if (StrnCaseCmp(tok, attr_strings.write_time_attr, n) == 0) {
     
    675673                        continue;
    676674                }
    677                
     675
    678676                if (attr_strings.create_time_attr != NULL) {
    679677                        n = strlen(attr_strings.create_time_attr);
     
    685683                        }
    686684                }
    687                
     685
    688686                if (StrnCaseCmp(tok, "INODE:", 6) == 0) {
    689687                        dad->inode = (SMB_INO_T)atof(tok+6);
     
    732730        bool determine_size = (bufsize == 0);
    733731        uint16_t fnum;
    734         SEC_DESC *sd;
     732        struct security_descriptor *sd;
    735733        fstring sidstr;
    736734        fstring name_sandbox;
     
    762760                const char * change_time_attr;
    763761        } excl_attr_strings;
    764        
     762
    765763        /* Determine whether to use old-style or new-style attribute names */
    766764        if (context->internal->full_time_names) {
     
    770768                attr_strings.write_time_attr = "WRITE_TIME";
    771769                attr_strings.change_time_attr = "CHANGE_TIME";
    772                
     770
    773771                excl_attr_strings.create_time_attr = "CREATE_TIME";
    774772                excl_attr_strings.access_time_attr = "ACCESS_TIME";
     
    781779                attr_strings.write_time_attr = "M_TIME";
    782780                attr_strings.change_time_attr = "C_TIME";
    783                
     781
    784782                excl_attr_strings.create_time_attr = NULL;
    785783                excl_attr_strings.access_time_attr = "dos_attr.A_TIME";
     
    787785                excl_attr_strings.change_time_attr = "dos_attr.C_TIME";
    788786        }
    789        
     787
    790788        /* Copy name so we can strip off exclusions (if any are specified) */
    791789        strncpy(name_sandbox, attr_name, sizeof(name_sandbox) - 1);
    792        
     790
    793791        /* Ensure name is null terminated */
    794792        name_sandbox[sizeof(name_sandbox) - 1] = '\0';
    795        
     793
    796794        /* Play in the sandbox */
    797795        name = name_sandbox;
    798        
     796
    799797        /* If there are any exclusions, point to them and mask them from name */
    800798        if ((pExclude = strchr(name, '!')) != NULL)
     
    802800                *pExclude++ = '\0';
    803801        }
    804        
     802
    805803        all = (StrnCaseCmp(name, "system.*", 8) == 0);
    806804        all_nt = (StrnCaseCmp(name, "system.nt_sec_desc.*", 20) == 0);
     
    810808        some_dos = (StrnCaseCmp(name, "system.dos_attr.", 16) == 0);
    811809        numeric = (* (name + strlen(name) - 1) != '+');
    812        
     810
    813811        /* Look for exclusions from "all" requests */
    814812        if (all || all_nt || all_dos) {
    815                
    816813                /* Exclusions are delimited by '!' */
    817814                for (;
    818815                     pExclude != NULL;
    819816                     pExclude = (p == NULL ? NULL : p + 1)) {
    820                        
     817
    821818                        /* Find end of this exclusion name */
    822819                        if ((p = strchr(pExclude, '!')) != NULL)
     
    824821                                *p = '\0';
    825822                        }
    826                        
     823
    827824                        /* Which exclusion name is this? */
    828825                        if (StrCaseCmp(pExclude,
     
    878875                }
    879876        }
    880        
     877
    881878        n_used = 0;
    882        
     879
    883880        /*
    884881         * If we are (possibly) talking to an NT or new system and some NT
     
    951948                                }
    952949                        }
    953                        
     950
    954951                        if (!determine_size && n > bufsize) {
    955952                                errno = ERANGE;
     
    961958                        n = 0;
    962959                }
    963                
     960
    964961                if (! exclude_nt_owner) {
    965962                        /* Get owner and group sid */
     
    972969                                fstrcpy(sidstr, "");
    973970                        }
    974                        
     971
    975972                        if (all || all_nt) {
    976973                                if (determine_size) {
     
    999996                                }
    1000997                        }
    1001                        
     998
    1002999                        if (!determine_size && n > bufsize) {
    10031000                                errno = ERANGE;
     
    10091006                        n = 0;
    10101007                }
    1011                
     1008
    10121009                if (! exclude_nt_group) {
    10131010                        if (sd->group_sid) {
     
    10181015                                fstrcpy(sidstr, "");
    10191016                        }
    1020                        
     1017
    10211018                        if (all || all_nt) {
    10221019                                if (determine_size) {
     
    10451042                                }
    10461043                        }
    1047                        
     1044
    10481045                        if (!determine_size && n > bufsize) {
    10491046                                errno = ERANGE;
     
    10551052                        n = 0;
    10561053                }
    1057                
     1054
    10581055                if (! exclude_nt_acl) {
    10591056                        /* Add aces to value buffer  */
    10601057                        for (i = 0; sd->dacl && i < sd->dacl->num_aces; i++) {
    1061                                
    1062                                 SEC_ACE *ace = &sd->dacl->aces[i];
     1058
     1059                                struct security_ace *ace = &sd->dacl->aces[i];
    10631060                                convert_sid_to_string(ipc_cli, pol,
    10641061                                                      sidstr, numeric,
    10651062                                                      &ace->trustee);
    1066                                
     1063
    10671064                                if (all || all_nt) {
    10681065                                        if (determine_size) {
     
    11471144                        }
    11481145                }
    1149                
     1146
    11501147                /* Restore name pointer to its original value */
    11511148                name -= 19;
    11521149        }
    1153        
     1150
    11541151        if (all || some_dos) {
    11551152                /* Point to the portion after "system.dos_attr." */
    11561153                name += 16;     /* if (all) this will be invalid but unused */
    1157                
     1154
    11581155                /* Obtain the DOS attributes */
    11591156                if (!SMBC_getatr(context, srv, filename, &mode, &size,
     
    11631160                                 &change_time_ts,
    11641161                                 &ino)) {
    1165                        
     1162
    11661163                        errno = SMBC_errno(context, srv->cli);
    11671164                        return -1;
    1168                        
    1169                 }
    1170                
     1165                }
     1166
    11711167                create_time = convert_timespec_to_time_t(create_time_ts);
    11721168                access_time = convert_timespec_to_time_t(access_time_ts);
    11731169                write_time = convert_timespec_to_time_t(write_time_ts);
    11741170                change_time = convert_timespec_to_time_t(change_time_ts);
    1175                
     1171
    11761172                if (! exclude_dos_mode) {
    11771173                        if (all || all_dos) {
     
    12111207                                }
    12121208                        }
    1213                        
     1209
    12141210                        if (!determine_size && n > bufsize) {
    12151211                                errno = ERANGE;
     
    12211217                        n = 0;
    12221218                }
    1223                
     1219
    12241220                if (! exclude_dos_size) {
    12251221                        if (all || all_dos) {
     
    12561252                                }
    12571253                        }
    1258                        
     1254
    12591255                        if (!determine_size && n > bufsize) {
    12601256                                errno = ERANGE;
     
    12661262                        n = 0;
    12671263                }
    1268                
     1264
    12691265                if (! exclude_dos_create_time &&
    12701266                    attr_strings.create_time_attr != NULL) {
     
    12991295                                }
    13001296                        }
    1301                        
     1297
    13021298                        if (!determine_size && n > bufsize) {
    13031299                                errno = ERANGE;
     
    13091305                        n = 0;
    13101306                }
    1311                
     1307
    13121308                if (! exclude_dos_access_time) {
    13131309                        if (all || all_dos) {
     
    13411337                                }
    13421338                        }
    1343                        
     1339
    13441340                        if (!determine_size && n > bufsize) {
    13451341                                errno = ERANGE;
     
    13511347                        n = 0;
    13521348                }
    1353                
     1349
    13541350                if (! exclude_dos_write_time) {
    13551351                        if (all || all_dos) {
     
    13831379                                }
    13841380                        }
    1385                        
     1381
    13861382                        if (!determine_size && n > bufsize) {
    13871383                                errno = ERANGE;
     
    13931389                        n = 0;
    13941390                }
    1395                
     1391
    13961392                if (! exclude_dos_change_time) {
    13971393                        if (all || all_dos) {
     
    14251421                                }
    14261422                        }
    1427                        
     1423
    14281424                        if (!determine_size && n > bufsize) {
    14291425                                errno = ERANGE;
     
    14351431                        n = 0;
    14361432                }
    1437                
     1433
    14381434                if (! exclude_dos_inode) {
    14391435                        if (all || all_dos) {
     
    14701466                                }
    14711467                        }
    1472                        
     1468
    14731469                        if (!determine_size && n > bufsize) {
    14741470                                errno = ERANGE;
     
    14801476                        n = 0;
    14811477                }
    1482                
     1478
    14831479                /* Restore name pointer to its original value */
    14841480                name -= 16;
    14851481        }
    1486        
     1482
    14871483        if (n_used == 0) {
    14881484                errno = ENOATTR;
    14891485                return -1;
    14901486        }
    1491        
     1487
    14921488        return n_used;
    14931489}
     
    15091505        uint16_t fnum = (uint16_t)-1;
    15101506        int err = 0;
    1511         SEC_DESC *sd = NULL, *old;
    1512         SEC_ACL *dacl = NULL;
    1513         DOM_SID *owner_sid = NULL;
    1514         DOM_SID *group_sid = NULL;
     1507        struct security_descriptor *sd = NULL, *old;
     1508        struct security_acl *dacl = NULL;
     1509        struct dom_sid *owner_sid = NULL;
     1510        struct dom_sid *group_sid = NULL;
    15151511        uint32 i, j;
    15161512        size_t sd_size;
     
    15201516        char *targetpath = NULL;
    15211517        struct cli_state *targetcli = NULL;
     1518        NTSTATUS status;
    15221519
    15231520        /* the_acl will be null for REMOVE_ALL operations */
     
    15261523                           p > the_acl &&
    15271524                           p[-1] != '+');
    1528                
     1525
    15291526                /* if this is to set the entire ACL... */
    15301527                if (*the_acl == '*') {
     
    15321529                        the_acl = p + 1;
    15331530                }
    1534                
     1531
    15351532                sd = sec_desc_parse(ctx, ipc_cli, pol, numeric, the_acl);
    1536                
    15371533                if (!sd) {
    15381534                        errno = EINVAL;
     
    15401536                }
    15411537        }
    1542        
     1538
    15431539        /* SMBC_XATTR_MODE_REMOVE_ALL is the only caller
    15441540           that doesn't deref sd */
    1545        
     1541
    15461542        if (!sd && (mode != SMBC_XATTR_MODE_REMOVE_ALL)) {
    15471543                errno = EINVAL;
     
    16021598                                }
    16031599                        }
    1604                        
     1600
    16051601                        if (!found) {
    16061602                                err = ENOATTR;
     
    16101606                }
    16111607                break;
    1612                
     1608
    16131609        case SMBC_XATTR_MODE_ADD:
    16141610                for (i=0;sd->dacl && i<sd->dacl->num_aces;i++) {
    16151611                        bool found = False;
    1616                        
     1612
    16171613                        for (j=0;old->dacl && j<old->dacl->num_aces;j++) {
    1618                                 if (sid_equal(&sd->dacl->aces[i].trustee,
     1614                                if (dom_sid_equal(&sd->dacl->aces[i].trustee,
    16191615                                              &old->dacl->aces[j].trustee)) {
    16201616                                        if (!(flags & SMBC_XATTR_FLAG_CREATE)) {
     
    16281624                                }
    16291625                        }
    1630                        
     1626
    16311627                        if (!found && (flags & SMBC_XATTR_FLAG_REPLACE)) {
    16321628                                err = ENOATTR;
     
    16341630                                goto failed;
    16351631                        }
    1636                        
     1632
    16371633                        for (i=0;sd->dacl && i<sd->dacl->num_aces;i++) {
    16381634                                add_ace(&old->dacl, &sd->dacl->aces[i], ctx);
     
    16411637                dacl = old->dacl;
    16421638                break;
    1643                
     1639
    16441640        case SMBC_XATTR_MODE_SET:
    16451641                old = sd;
     
    16481644                dacl = old->dacl;
    16491645                break;
    1650                
     1646
    16511647        case SMBC_XATTR_MODE_CHOWN:
    16521648                owner_sid = sd->owner_sid;
    16531649                break;
    1654                
     1650
    16551651        case SMBC_XATTR_MODE_CHGRP:
    16561652                group_sid = sd->group_sid;
    16571653                break;
    16581654        }
    1659        
     1655
    16601656        /* Denied ACE entries must come before allowed ones */
    16611657        sort_acl(old->dacl);
    1662        
     1658
    16631659        /* Create new security descriptor and set it */
    16641660        sd = make_sec_desc(ctx, old->revision, SEC_DESC_SELF_RELATIVE,
    16651661                           owner_sid, group_sid, NULL, dacl, &sd_size);
    1666        
     1662
    16671663        if (!NT_STATUS_IS_OK(cli_ntcreate(targetcli, targetpath, 0,
    16681664                             WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS, 0,
     
    16731669                return -1;
    16741670        }
    1675        
    1676         if (!cli_set_secdesc(targetcli, fnum, sd)) {
     1671
     1672        status = cli_set_secdesc(targetcli, fnum, sd);
     1673        if (!NT_STATUS_IS_OK(status)) {
    16771674                DEBUG(5, ("ERROR: secdesc set failed: %s\n",
    1678                         cli_errstr(targetcli)));
     1675                          nt_errstr(status)));
    16791676                ret = -1;
    16801677        }
    1681        
     1678
    16821679        /* Clean up */
    1683        
     1680
    16841681failed:
    16851682        cli_close(targetcli, fnum);
    1686        
     1683
    16871684        if (err != 0) {
    16881685                errno = err;
    16891686        }
    1690        
     1687
    16911688        return ret;
    16921689}
     
    17191716        } attr_strings;
    17201717        TALLOC_CTX *frame = talloc_stackframe();
    1721        
     1718
    17221719        if (!context || !context->internal->initialized) {
    1723                
    17241720                errno = EINVAL;  /* Best I can think of ... */
    17251721                TALLOC_FREE(frame);
    17261722                return -1;
    17271723        }
    1728        
     1724
    17291725        if (!fname) {
    17301726                errno = EINVAL;
     
    17321728                return -1;
    17331729        }
    1734        
     1730
    17351731        DEBUG(4, ("smbc_setxattr(%s, %s, %.*s)\n",
    17361732                  fname, name, (int) size, (const char*)value));
    1737        
     1733
    17381734        if (SMBC_parse_path(frame,
    17391735                            context,
     
    17501746                return -1;
    17511747        }
    1752        
     1748
    17531749        if (!user || user[0] == (char)0) {
    17541750                user = talloc_strdup(frame, smbc_getUser(context));
     
    17591755                }
    17601756        }
    1761        
     1757
    17621758        srv = SMBC_server(frame, context, True,
    17631759                          server, share, &workgroup, &user, &password);
     
    17661762                return -1;  /* errno set by SMBC_server */
    17671763        }
    1768        
     1764
    17691765        if (! srv->no_nt_session) {
    17701766                ipc_srv = SMBC_attr_server(frame, context, server, share,
     
    17761772                ipc_srv = NULL;
    17771773        }
    1778        
     1774
    17791775        /*
    17801776         * Are they asking to set the entire set of known attributes?
     
    17921788                        return -1;
    17931789                }
    1794                
     1790
    17951791                if (ipc_srv) {
    17961792                        ret = cacl_set(context, talloc_tos(), srv->cli,
     
    18041800                        ret = 0;
    18051801                }
    1806                
     1802
    18071803                /* get a DOS Attribute Descriptor with current attributes */
    18081804                dad = dos_attr_query(context, talloc_tos(), path, srv);
     
    18101806                        /* Overwrite old with new, using what was provided */
    18111807                        dos_attr_parse(context, dad, srv, namevalue);
    1812                        
     1808
    18131809                        /* Set the new DOS attributes */
    18141810                        if (! SMBC_setatr(context, srv, path,
     
    18181814                                          dad->change_time,
    18191815                                          dad->mode)) {
    1820                                
     1816
    18211817                                /* cause failure if NT failed too */
    18221818                                dad = NULL;
    18231819                        }
    18241820                }
    1825                
     1821
    18261822                /* we only fail if both NT and DOS sets failed */
    18271823                if (ret < 0 && ! dad) {
     
    18311827                        ret = 0;
    18321828                }
    1833                
     1829
    18341830                TALLOC_FREE(frame);
    18351831                return ret;
    18361832        }
    1837        
     1833
    18381834        /*
    18391835         * Are they asking to set an access control element or to set
     
    18451841            StrnCaseCmp(name, "system.nt_sec_desc.acl", 22) == 0 ||
    18461842            StrnCaseCmp(name, "system.nt_sec_desc.acl+", 23) == 0) {
    1847                
     1843
    18481844                /* Yup. */
    18491845                char *namevalue =
    18501846                        talloc_asprintf(talloc_tos(), "%s:%s",
    18511847                                        name+19, (const char *) value);
    1852                
     1848
    18531849                if (! ipc_srv) {
    18541850                        ret = -1; /* errno set by SMBC_server() */
     
    18691865                return ret;
    18701866        }
    1871        
     1867
    18721868        /*
    18731869         * Are they asking to set the owner?
     
    18751871        if (StrCaseCmp(name, "system.nt_sec_desc.owner") == 0 ||
    18761872            StrCaseCmp(name, "system.nt_sec_desc.owner+") == 0) {
    1877                
     1873
    18781874                /* Yup. */
    18791875                char *namevalue =
    18801876                        talloc_asprintf(talloc_tos(), "%s:%s",
    18811877                                        name+19, (const char *) value);
    1882                
     1878
    18831879                if (! ipc_srv) {
    18841880                        ret = -1; /* errno set by SMBC_server() */
     
    18951891                return ret;
    18961892        }
    1897        
     1893
    18981894        /*
    18991895         * Are they asking to set the group?
     
    19011897        if (StrCaseCmp(name, "system.nt_sec_desc.group") == 0 ||
    19021898            StrCaseCmp(name, "system.nt_sec_desc.group+") == 0) {
    1903                
     1899
    19041900                /* Yup. */
    19051901                char *namevalue =
    19061902                        talloc_asprintf(talloc_tos(), "%s:%s",
    19071903                                        name+19, (const char *) value);
    1908                
     1904
    19091905                if (! ipc_srv) {
    19101906                        /* errno set by SMBC_server() */
     
    19221918                return ret;
    19231919        }
    1924        
     1920
    19251921        /* Determine whether to use old-style or new-style attribute names */
    19261922        if (context->internal->full_time_names) {
     
    19371933                attr_strings.change_time_attr = "system.dos_attr.C_TIME";
    19381934        }
    1939        
     1935
    19401936        /*
    19411937         * Are they asking to set a DOS attribute?
     
    19481944            StrCaseCmp(name, attr_strings.write_time_attr) == 0 ||
    19491945            StrCaseCmp(name, attr_strings.change_time_attr) == 0) {
    1950                
     1946
    19511947                /* get a DOS Attribute Descriptor with current attributes */
    19521948                dad = dos_attr_query(context, talloc_tos(), path, srv);
     
    19611957                                /* Overwrite old with provided new params */
    19621958                                dos_attr_parse(context, dad, srv, namevalue);
    1963                                
     1959
    19641960                                /* Set the new DOS attributes */
    19651961                                ret2 = SMBC_setatr(context, srv, path,
     
    19691965                                                   dad->change_time,
    19701966                                                   dad->mode);
    1971                                
     1967
    19721968                                /* ret2 has True (success) / False (failure) */
    19731969                                if (ret2) {
     
    19801976                        ret = -1;
    19811977                }
    1982                
     1978
    19831979                TALLOC_FREE(frame);
    19841980                return ret;
    19851981        }
    1986        
     1982
    19871983        /* Unsupported attribute name */
    19881984        errno = EINVAL;
     
    20142010        } attr_strings;
    20152011        TALLOC_CTX *frame = talloc_stackframe();
    2016        
     2012
    20172013        if (!context || !context->internal->initialized) {
    2018                
    20192014                errno = EINVAL;  /* Best I can think of ... */
    20202015                TALLOC_FREE(frame);
    20212016                return -1;
    20222017        }
    2023        
     2018
    20242019        if (!fname) {
    20252020                errno = EINVAL;
     
    20272022                return -1;
    20282023        }
    2029        
     2024
    20302025        DEBUG(4, ("smbc_getxattr(%s, %s)\n", fname, name));
    2031        
     2026
    20322027        if (SMBC_parse_path(frame,
    20332028                            context,
     
    20442039                return -1;
    20452040        }
    2046        
     2041
    20472042        if (!user || user[0] == (char)0) {
    20482043                user = talloc_strdup(frame, smbc_getUser(context));
     
    20532048                }
    20542049        }
    2055        
     2050
    20562051        srv = SMBC_server(frame, context, True,
    20572052                          server, share, &workgroup, &user, &password);
     
    20602055                return -1;  /* errno set by SMBC_server */
    20612056        }
    2062        
     2057
    20632058        if (! srv->no_nt_session) {
    20642059                ipc_srv = SMBC_attr_server(frame, context, server, share,
     
    20702065                ipc_srv = NULL;
    20712066        }
    2072        
     2067
    20732068        /* Determine whether to use old-style or new-style attribute names */
    20742069        if (context->internal->full_time_names) {
     
    20852080                attr_strings.change_time_attr = "system.dos_attr.C_TIME";
    20862081        }
    2087        
     2082
    20882083        /* Are they requesting a supported attribute? */
    20892084        if (StrCaseCmp(name, "system.*") == 0 ||
     
    21122107            StrCaseCmp(name, attr_strings.change_time_attr) == 0 ||
    21132108            StrCaseCmp(name, "system.dos_attr.inode") == 0) {
    2114                
     2109
    21152110                /* Yup. */
    21162111                char *filename = (char *) name;
     
    21272122                return ret;
    21282123        }
    2129        
     2124
    21302125        /* Unsupported attribute name */
    21312126        errno = EINVAL;
     
    21502145        char *path = NULL;
    21512146        TALLOC_CTX *frame = talloc_stackframe();
    2152        
     2147
    21532148        if (!context || !context->internal->initialized) {
    2154                
    21552149                errno = EINVAL;  /* Best I can think of ... */
    21562150                TALLOC_FREE(frame);
    21572151                return -1;
    21582152        }
    2159        
     2153
    21602154        if (!fname) {
    21612155                errno = EINVAL;
     
    21632157                return -1;
    21642158        }
    2165        
     2159
    21662160        DEBUG(4, ("smbc_removexattr(%s, %s)\n", fname, name));
    2167        
     2161
    21682162        if (SMBC_parse_path(frame,
    21692163                            context,
     
    21802174                return -1;
    21812175        }
    2182        
     2176
    21832177        if (!user || user[0] == (char)0) {
    21842178                user = talloc_strdup(frame, smbc_getUser(context));
     
    21892183                }
    21902184        }
    2191        
     2185
    21922186        srv = SMBC_server(frame, context, True,
    21932187                          server, share, &workgroup, &user, &password);
     
    21962190                return -1;  /* errno set by SMBC_server */
    21972191        }
    2198        
     2192
    21992193        if (! srv->no_nt_session) {
    22002194                ipc_srv = SMBC_attr_server(frame, context, server, share,
     
    22062200                ipc_srv = NULL;
    22072201        }
    2208        
     2202
    22092203        if (! ipc_srv) {
    22102204                TALLOC_FREE(frame);
    22112205                return -1; /* errno set by SMBC_attr_server */
    22122206        }
    2213        
     2207
    22142208        /* Are they asking to set the entire ACL? */
    22152209        if (StrCaseCmp(name, "system.nt_sec_desc.*") == 0 ||
    22162210            StrCaseCmp(name, "system.nt_sec_desc.*+") == 0) {
    2217                
     2211
    22182212                /* Yup. */
    22192213                ret = cacl_set(context, talloc_tos(), srv->cli,
     
    22232217                return ret;
    22242218        }
    2225        
     2219
    22262220        /*
    22272221         * Are they asking to remove one or more spceific security descriptor
     
    22352229            StrnCaseCmp(name, "system.nt_sec_desc.acl", 22) == 0 ||
    22362230            StrnCaseCmp(name, "system.nt_sec_desc.acl+", 23) == 0) {
    2237                
     2231
    22382232                /* Yup. */
    22392233                ret = cacl_set(context, talloc_tos(), srv->cli,
     
    22442238                return ret;
    22452239        }
    2246        
     2240
    22472241        /* Unsupported attribute name */
    22482242        errno = EINVAL;
     
    23032297                ;
    23042298        const char * supported;
    2305        
     2299
    23062300        if (context->internal->full_time_names) {
    23072301                supported = supported_new;
     
    23112305                retsize = sizeof(supported_old);
    23122306        }
    2313        
     2307
    23142308        if (size == 0) {
    23152309                return retsize;
    23162310        }
    2317        
     2311
    23182312        if (retsize > size) {
    23192313                errno = ERANGE;
    23202314                return -1;
    23212315        }
    2322        
     2316
    23232317        /* this can't be strcpy() because there are embedded null characters */
    23242318        memcpy(list, supported, retsize);
Note: See TracChangeset for help on using the changeset viewer.