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/smbd/posix_acls.c

    r599 r745  
    2121
    2222#include "includes.h"
    23 
    24 extern struct current_user current_user;
     23#include "smbd/smbd.h"
     24#include "system/filesys.h"
     25#include "../libcli/security/security.h"
     26#include "trans2.h"
     27#include "passdb/lookup_sid.h"
     28#include "auth.h"
     29
    2530extern const struct generic_mapping file_generic_mapping;
    2631
     
    4550        SMB_ACL_TAG_T type;
    4651        mode_t perms; /* Only use S_I(R|W|X)USR mode bits here. */
    47         DOM_SID trustee;
     52        struct dom_sid trustee;
    4853        enum ace_owner owner_type;
    4954        enum ace_attribute attr;
     
    443448                paie->ace_flags = SEC_ACE_FLAG_INHERITED_ACE;
    444449                if (!get_pai_owner_type(paie, entry_offset)) {
     450                        SAFE_FREE(paie);
    445451                        return NULL;
    446452                }
     
    477483
    478484        paiv->sd_type = (CVAL(buf,PAI_V1_FLAG_OFFSET) == PAI_V1_ACL_FLAG_PROTECTED) ?
    479                         SE_DESC_DACL_PROTECTED : 0;
     485                        SEC_DESC_DACL_PROTECTED : 0;
    480486
    481487        paiv->num_entries = SVAL(buf,PAI_V1_NUM_ENTRIES_OFFSET);
     
    521527
    522528                if (!get_pai_owner_type(paie, entry_offset+1)) {
     529                        SAFE_FREE(paie);
    523530                        return NULL;
    524531                }
     
    907914****************************************************************************/
    908915
    909 void create_file_sids(const SMB_STRUCT_STAT *psbuf, DOM_SID *powner_sid, DOM_SID *pgroup_sid)
     916void create_file_sids(const SMB_STRUCT_STAT *psbuf, struct dom_sid *powner_sid, struct dom_sid *pgroup_sid)
    910917{
    911918        uid_to_sid( powner_sid, psbuf->st_ex_uid );
     
    946953
    947954                        if (!dir_acl) {
    948                                 can_merge = (sid_equal(&curr_ace->trustee, &curr_ace_outer->trustee) &&
     955                                can_merge = (dom_sid_equal(&curr_ace->trustee, &curr_ace_outer->trustee) &&
    949956                                                (curr_ace->attr == curr_ace_outer->attr));
    950957                        } else {
    951                                 can_merge = (sid_equal(&curr_ace->trustee, &curr_ace_outer->trustee) &&
     958                                can_merge = (dom_sid_equal(&curr_ace->trustee, &curr_ace_outer->trustee) &&
    952959                                                (curr_ace->type == curr_ace_outer->type) &&
    953960                                                (curr_ace->attr == curr_ace_outer->attr));
     
    9981005                         */
    9991006
    1000                         if (sid_equal(&curr_ace->trustee, &curr_ace_outer->trustee) &&
     1007                        if (dom_sid_equal(&curr_ace->trustee, &curr_ace_outer->trustee) &&
    10011008                                (curr_ace_outer->attr == DENY_ACE) && (curr_ace->attr == ALLOW_ACE)) {
    10021009
     
    11661173
    11671174/****************************************************************************
    1168  Unpack a SEC_DESC into a UNIX owner and group.
    1169 ****************************************************************************/
    1170 
    1171 NTSTATUS unpack_nt_owners(int snum, uid_t *puser, gid_t *pgrp, uint32 security_info_sent, const SEC_DESC *psd)
    1172 {
    1173         DOM_SID owner_sid;
    1174         DOM_SID grp_sid;
     1175 Unpack a struct security_descriptor into a UNIX owner and group.
     1176****************************************************************************/
     1177
     1178NTSTATUS unpack_nt_owners(struct connection_struct *conn,
     1179                        uid_t *puser, gid_t *pgrp,
     1180                        uint32 security_info_sent, const struct
     1181                        security_descriptor *psd)
     1182{
     1183        struct dom_sid owner_sid;
     1184        struct dom_sid grp_sid;
    11751185
    11761186        *puser = (uid_t)-1;
     
    11961206         */
    11971207
    1198         if (security_info_sent & OWNER_SECURITY_INFORMATION) {
     1208        if (security_info_sent & SECINFO_OWNER) {
    11991209                sid_copy(&owner_sid, psd->owner_sid);
    12001210                if (!sid_to_uid(&owner_sid, puser)) {
    1201                         if (lp_force_unknown_acl_user(snum)) {
     1211                        if (lp_force_unknown_acl_user(SNUM(conn))) {
    12021212                                /* this allows take ownership to work
    12031213                                 * reasonably */
    1204                                 *puser = current_user.ut.uid;
     1214                                *puser = get_current_uid(conn);
    12051215                        } else {
    12061216                                DEBUG(3,("unpack_nt_owners: unable to validate"
     
    12191229         */
    12201230
    1221         if (security_info_sent & GROUP_SECURITY_INFORMATION) {
     1231        if (security_info_sent & SECINFO_GROUP) {
    12221232                sid_copy(&grp_sid, psd->group_sid);
    12231233                if (!sid_to_gid( &grp_sid, pgrp)) {
    1224                         if (lp_force_unknown_acl_user(snum)) {
     1234                        if (lp_force_unknown_acl_user(SNUM(conn))) {
    12251235                                /* this allows take group ownership to work
    12261236                                 * reasonably */
    1227                                 *pgrp = current_user.ut.gid;
     1237                                *pgrp = get_current_gid(conn);
    12281238                        } else {
    12291239                                DEBUG(3,("unpack_nt_owners: unable to validate"
     
    12901300****************************************************************************/
    12911301
    1292 static bool uid_entry_in_group( canon_ace *uid_ace, canon_ace *group_ace )
     1302static bool uid_entry_in_group(connection_struct *conn, canon_ace *uid_ace, canon_ace *group_ace )
    12931303{
    12941304        const char *u_name = NULL;
     
    12961306        /* "Everyone" always matches every uid. */
    12971307
    1298         if (sid_equal(&group_ace->trustee, &global_sid_World))
     1308        if (dom_sid_equal(&group_ace->trustee, &global_sid_World))
    12991309                return True;
    13001310
     
    13031313         * and don't need to do the complex user_in_group_sid() call
    13041314         */
    1305         if (uid_ace->unix_ug.uid == current_user.ut.uid) {
     1315        if (uid_ace->unix_ug.uid == get_current_uid(conn)) {
     1316                const struct security_unix_token *curr_utok = NULL;
    13061317                size_t i;
    13071318
    1308                 if (group_ace->unix_ug.gid == current_user.ut.gid) {
     1319                if (group_ace->unix_ug.gid == get_current_gid(conn)) {
    13091320                        return True;
    13101321                }
    13111322
    1312                 for (i=0; i < current_user.ut.ngroups; i++) {
    1313                         if (group_ace->unix_ug.gid == current_user.ut.groups[i]) {
     1323                curr_utok = get_current_utok(conn);
     1324                for (i=0; i < curr_utok->ngroups; i++) {
     1325                        if (group_ace->unix_ug.gid == curr_utok->groups[i]) {
    13141326                                return True;
    13151327                        }
     
    13421354****************************************************************************/
    13431355
    1344 static bool ensure_canon_entry_valid(canon_ace **pp_ace,
     1356static bool ensure_canon_entry_valid(connection_struct *conn, canon_ace **pp_ace,
    13451357                                     const struct share_params *params,
    13461358                                     const bool is_directory,
    1347                                                         const DOM_SID *pfile_owner_sid,
    1348                                                         const DOM_SID *pfile_grp_sid,
     1359                                                        const struct dom_sid *pfile_owner_sid,
     1360                                                        const struct dom_sid *pfile_grp_sid,
    13491361                                                        const SMB_STRUCT_STAT *pst,
    13501362                                                        bool setting_acl)
     
    14081420                        for (pace_iter = *pp_ace; pace_iter; pace_iter = pace_iter->next) {
    14091421                                if (pace_iter->type == SMB_ACL_GROUP_OBJ || pace_iter->type == SMB_ACL_GROUP) {
    1410                                         if (uid_entry_in_group(pace, pace_iter)) {
     1422                                        if (uid_entry_in_group(conn, pace, pace_iter)) {
    14111423                                                pace->perms |= pace_iter->perms;
    14121424                                                group_matched = True;
     
    14871499****************************************************************************/
    14881500
    1489 static void check_owning_objs(canon_ace *ace, DOM_SID *pfile_owner_sid, DOM_SID *pfile_grp_sid)
     1501static void check_owning_objs(canon_ace *ace, struct dom_sid *pfile_owner_sid, struct dom_sid *pfile_grp_sid)
    14901502{
    14911503        bool got_user_obj, got_group_obj;
     
    15101522        for (i=0, current_ace = ace; i < entries; i++, current_ace = current_ace->next) {
    15111523                if (!got_user_obj && current_ace->owner_type == UID_ACE &&
    1512                                 sid_equal(&current_ace->trustee, pfile_owner_sid)) {
     1524                                dom_sid_equal(&current_ace->trustee, pfile_owner_sid)) {
    15131525                        current_ace->type = SMB_ACL_USER_OBJ;
    15141526                        got_user_obj = True;
    15151527                }
    15161528                if (!got_group_obj && current_ace->owner_type == GID_ACE &&
    1517                                 sid_equal(&current_ace->trustee, pfile_grp_sid)) {
     1529                                dom_sid_equal(&current_ace->trustee, pfile_grp_sid)) {
    15181530                        current_ace->type = SMB_ACL_GROUP_OBJ;
    15191531                        got_group_obj = True;
     
    15461558
    15471559        if (ace->type == SMB_ACL_USER_OBJ &&
    1548                         !(sid_equal(&ace->trustee, &global_sid_Creator_Owner))) {
     1560                        !(dom_sid_equal(&ace->trustee, &global_sid_Creator_Owner))) {
    15491561                canon_ace *dup_ace = dup_canon_ace(ace);
    15501562
     
    15571569
    15581570        if (ace->type == SMB_ACL_GROUP_OBJ &&
    1559                         !(sid_equal(&ace->trustee, &global_sid_Creator_Group))) {
     1571                        !(dom_sid_equal(&ace->trustee, &global_sid_Creator_Group))) {
    15601572                canon_ace *dup_ace = dup_canon_ace(ace);
    15611573
     
    15711583
    15721584/****************************************************************************
    1573  Unpack a SEC_DESC into two canonical ace lists.
     1585 Unpack a struct security_descriptor into two canonical ace lists.
    15741586****************************************************************************/
    15751587
    15761588static bool create_canon_ace_lists(files_struct *fsp,
    15771589                                        const SMB_STRUCT_STAT *pst,
    1578                                         DOM_SID *pfile_owner_sid,
    1579                                         DOM_SID *pfile_grp_sid,
     1590                                        struct dom_sid *pfile_owner_sid,
     1591                                        struct dom_sid *pfile_grp_sid,
    15801592                                        canon_ace **ppfile_ace,
    15811593                                        canon_ace **ppdir_ace,
    1582                                         const SEC_ACL *dacl)
     1594                                        const struct security_acl *dacl)
    15831595{
    15841596        bool all_aces_are_inherit_only = (fsp->is_directory ? True : False);
     
    15981610
    15991611        for(i = 0; i < dacl->num_aces; i++) {
    1600                 SEC_ACE *psa = &dacl->aces[i];
     1612                struct security_ace *psa = &dacl->aces[i];
    16011613
    16021614                if((psa->type != SEC_ACE_TYPE_ACCESS_ALLOWED) && (psa->type != SEC_ACE_TYPE_ACCESS_DENIED)) {
     
    16351647
    16361648        for(i = 0; i < dacl->num_aces; i++) {
    1637                 SEC_ACE *psa1 = &dacl->aces[i];
     1649                struct security_ace *psa1 = &dacl->aces[i];
    16381650
    16391651                for (j = i + 1; j < dacl->num_aces; j++) {
    1640                         SEC_ACE *psa2 = &dacl->aces[j];
     1652                        struct security_ace *psa2 = &dacl->aces[j];
    16411653
    16421654                        if (psa1->access_mask != psa2->access_mask)
    16431655                                continue;
    16441656
    1645                         if (!sid_equal(&psa1->trustee, &psa2->trustee))
     1657                        if (!dom_sid_equal(&psa1->trustee, &psa2->trustee))
    16461658                                continue;
    16471659
     
    16661678
    16671679        for(i = 0; i < dacl->num_aces; i++) {
    1668                 SEC_ACE *psa = &dacl->aces[i];
     1680                struct security_ace *psa = &dacl->aces[i];
    16691681
    16701682                /*
    1671                  * Create a cannon_ace entry representing this NT DACL ACE.
     1683                 * Create a canon_ace entry representing this NT DACL ACE.
    16721684                 */
    16731685
     
    16891701                 */
    16901702
    1691                 if( sid_equal(&current_ace->trustee, &global_sid_World)) {
     1703                if( dom_sid_equal(&current_ace->trustee, &global_sid_World)) {
    16921704                        current_ace->owner_type = WORLD_ACE;
    16931705                        current_ace->unix_ug.world = -1;
    16941706                        current_ace->type = SMB_ACL_OTHER;
    1695                 } else if (sid_equal(&current_ace->trustee, &global_sid_Creator_Owner)) {
     1707                } else if (dom_sid_equal(&current_ace->trustee, &global_sid_Creator_Owner)) {
    16961708                        current_ace->owner_type = UID_ACE;
    16971709                        current_ace->unix_ug.uid = pst->st_ex_uid;
     
    17061718                        psa->flags |= SEC_ACE_FLAG_INHERIT_ONLY;
    17071719
    1708                 } else if (sid_equal(&current_ace->trustee, &global_sid_Creator_Group)) {
     1720                } else if (dom_sid_equal(&current_ace->trustee, &global_sid_Creator_Group)) {
    17091721                        current_ace->owner_type = GID_ACE;
    17101722                        current_ace->unix_ug.gid = pst->st_ex_gid;
     
    17531765                                        "unknown or foreign SID %s\n",
    17541766                                        sid_string_dbg(&psa->trustee)));
    1755                                         SAFE_FREE(current_ace);
     1767                                SAFE_FREE(current_ace);
    17561768                                continue;
    17571769                        }
     
    20662078****************************************************************************/
    20672079
    2068 static void process_deny_list( canon_ace **pp_ace_list )
     2080static void process_deny_list(connection_struct *conn, canon_ace **pp_ace_list )
    20692081{
    20702082        canon_ace *ace_list = *pp_ace_list;
     
    20902102                }
    20912103
    2092                 if (!sid_equal(&curr_ace->trustee, &global_sid_World))
     2104                if (!dom_sid_equal(&curr_ace->trustee, &global_sid_World))
    20932105                        continue;
    20942106
     
    21032115                         */
    21042116
    2105                         canon_ace *prev_entry = curr_ace->prev;
     2117                        canon_ace *prev_entry = DLIST_PREV(curr_ace);
    21062118
    21072119                        free_canon_ace_list( curr_ace );
    21082120                        if (prev_entry)
    2109                                 prev_entry->next = NULL;
     2121                                DLIST_REMOVE(ace_list, prev_entry);
    21102122                        else {
    21112123                                /* We deleted the entire list. */
     
    21712183                                continue;
    21722184
    2173                         if (uid_entry_in_group( curr_ace, allow_ace_p))
     2185                        if (uid_entry_in_group(conn, curr_ace, allow_ace_p))
    21742186                                new_perms |= allow_ace_p->perms;
    21752187                }
     
    22152227                        /* Mask off the deny group perms. */
    22162228
    2217                         if (uid_entry_in_group( allow_ace_p, curr_ace))
     2229                        if (uid_entry_in_group(conn, allow_ace_p, curr_ace))
    22182230                                allow_ace_p->perms &= ~curr_ace->perms;
    22192231                }
     
    22652277                        /* OR in the group perms. */
    22662278
    2267                         if (uid_entry_in_group( curr_ace, allow_ace_p))
     2279                        if (uid_entry_in_group(conn, curr_ace, allow_ace_p))
    22682280                                curr_ace->perms |= allow_ace_p->perms;
    22692281                }
     
    23132325
    23142326/****************************************************************************
    2315  Unpack a SEC_DESC into two canonical ace lists. We don't depend on this
     2327 Unpack a struct security_descriptor into two canonical ace lists. We don't depend on this
    23162328 succeeding.
    23172329****************************************************************************/
     
    23192331static bool unpack_canon_ace(files_struct *fsp,
    23202332                                const SMB_STRUCT_STAT *pst,
    2321                                 DOM_SID *pfile_owner_sid,
    2322                                 DOM_SID *pfile_grp_sid,
     2333                                struct dom_sid *pfile_owner_sid,
     2334                                struct dom_sid *pfile_grp_sid,
    23232335                                canon_ace **ppfile_ace,
    23242336                                canon_ace **ppdir_ace,
    23252337                                uint32 security_info_sent,
    2326                                 const SEC_DESC *psd)
     2338                                const struct security_descriptor *psd)
    23272339{
    23282340        SMB_STRUCT_STAT st;
     
    23422354         */
    23432355
    2344         if(!(security_info_sent & DACL_SECURITY_INFORMATION) || !psd->dacl)
     2356        if(!(security_info_sent & SECINFO_DACL) || !psd->dacl)
    23452357                return True;
    23462358
     
    23772389
    23782390        print_canon_ace_list( "file ace - before deny", file_ace);
    2379         process_deny_list( &file_ace);
     2391        process_deny_list(fsp->conn, &file_ace);
    23802392
    23812393        print_canon_ace_list( "dir ace - before deny", dir_ace);
    2382         process_deny_list( &dir_ace);
     2394        process_deny_list(fsp->conn, &dir_ace);
    23832395
    23842396        /*
     
    23992411        st.st_ex_mode = create_default_mode(fsp, False);
    24002412
    2401         if (!ensure_canon_entry_valid(&file_ace, fsp->conn->params,
     2413        if (!ensure_canon_entry_valid(fsp->conn, &file_ace, fsp->conn->params,
    24022414                        fsp->is_directory, pfile_owner_sid, pfile_grp_sid, &st, True)) {
    24032415                free_canon_ace_list(file_ace);
     
    24162428        st.st_ex_mode = create_default_mode(fsp, True);
    24172429
    2418         if (dir_ace && !ensure_canon_entry_valid(&dir_ace, fsp->conn->params,
     2430        if (dir_ace && !ensure_canon_entry_valid(fsp->conn, &dir_ace, fsp->conn->params,
    24192431                        fsp->is_directory, pfile_owner_sid, pfile_grp_sid, &st, True)) {
    24202432                free_canon_ace_list(file_ace);
     
    24982510                                   const char *fname, SMB_ACL_T posix_acl,
    24992511                                   const SMB_STRUCT_STAT *psbuf,
    2500                                    const DOM_SID *powner, const DOM_SID *pgroup, struct pai_val *pal, SMB_ACL_TYPE_T the_acl_type)
     2512                                   const struct dom_sid *powner, const struct dom_sid *pgroup, struct pai_val *pal, SMB_ACL_TYPE_T the_acl_type)
    25012513{
    25022514        mode_t acl_mask = (S_IRUSR|S_IWUSR|S_IXUSR);
     
    25112523                SMB_ACL_TAG_T tagtype;
    25122524                SMB_ACL_PERMSET_T permset;
    2513                 DOM_SID sid;
     2525                struct dom_sid sid;
    25142526                posix_id unix_ug;
    25152527                enum ace_owner owner_type;
     
    26012613         */
    26022614
    2603         if (!ensure_canon_entry_valid(&l_head, conn->params,
     2615        if (!ensure_canon_entry_valid(conn, &l_head, conn->params,
    26042616                                      S_ISDIR(psbuf->st_ex_mode), powner, pgroup,
    26052617                                      psbuf, False))
     
    26452657****************************************************************************/
    26462658
    2647 bool current_user_in_group(gid_t gid)
     2659bool current_user_in_group(connection_struct *conn, gid_t gid)
    26482660{
    26492661        int i;
    2650 
    2651         for (i = 0; i < current_user.ut.ngroups; i++) {
    2652                 if (current_user.ut.groups[i] == gid) {
     2662        const struct security_unix_token *utok = get_current_utok(conn);
     2663
     2664        for (i = 0; i < utok->ngroups; i++) {
     2665                if (utok->groups[i] == gid) {
    26532666                        return True;
    26542667                }
     
    26712684        /* file primary group == user primary or supplementary group */
    26722685        if (lp_acl_group_control(SNUM(conn)) &&
    2673             current_user_in_group(smb_fname->st.st_ex_gid)) {
     2686            current_user_in_group(conn, smb_fname->st.st_ex_gid)) {
    26742687                return true;
    26752688        }
     
    30693082****************************************************************************/
    30703083
    3071 static size_t merge_default_aces( SEC_ACE *nt_ace_list, size_t num_aces)
     3084static size_t merge_default_aces( struct security_ace *nt_ace_list, size_t num_aces)
    30723085{
    30733086        size_t i, j;
     
    30843097                                (nt_ace_list[i].size == nt_ace_list[j].size) &&
    30853098                                (nt_ace_list[i].access_mask == nt_ace_list[j].access_mask) &&
    3086                                 sid_equal(&nt_ace_list[i].trustee, &nt_ace_list[j].trustee) &&
     3099                                dom_sid_equal(&nt_ace_list[i].trustee, &nt_ace_list[j].trustee) &&
    30873100                                (i_inh == j_inh) &&
    30883101                                (i_flags_ni == 0) &&
     
    31013114                                        if (num_aces - i - 1 > 0)
    31023115                                                memmove(&nt_ace_list[i], &nt_ace_list[i+1], (num_aces-i-1) *
    3103                                                                 sizeof(SEC_ACE));
     3116                                                                sizeof(struct security_ace));
    31043117
    31053118                                        DEBUG(10,("merge_default_aces: Merging zero access ACE %u onto ACE %u.\n",
     
    31153128                                        if (num_aces - j - 1 > 0)
    31163129                                                memmove(&nt_ace_list[j], &nt_ace_list[j+1], (num_aces-j-1) *
    3117                                                                 sizeof(SEC_ACE));
     3130                                                                sizeof(struct security_ace));
    31183131
    31193132                                        DEBUG(10,("merge_default_aces: Merging ACE %u onto ACE %u.\n",
     
    31403153 */
    31413154
    3142 static void add_or_replace_ace(SEC_ACE *nt_ace_list, size_t *num_aces,
    3143                                 const DOM_SID *sid, enum security_ace_type type,
     3155static void add_or_replace_ace(struct security_ace *nt_ace_list, size_t *num_aces,
     3156                                const struct dom_sid *sid, enum security_ace_type type,
    31443157                                uint32_t mask, uint8_t flags)
    31453158{
     
    31483161        /* first search for a duplicate */
    31493162        for (i = 0; i < *num_aces; i++) {
    3150                 if (sid_equal(&nt_ace_list[i].trustee, sid) &&
     3163                if (dom_sid_equal(&nt_ace_list[i].trustee, sid) &&
    31513164                    (nt_ace_list[i].flags == flags)) break;
    31523165        }
     
    31793192                                      SMB_ACL_T def_acl,
    31803193                                      uint32_t security_info,
    3181                                       SEC_DESC **ppdesc)
    3182 {
    3183         DOM_SID owner_sid;
    3184         DOM_SID group_sid;
     3194                                      struct security_descriptor **ppdesc)
     3195{
     3196        struct dom_sid owner_sid;
     3197        struct dom_sid group_sid;
    31853198        size_t sd_size = 0;
    3186         SEC_ACL *psa = NULL;
     3199        struct security_acl *psa = NULL;
    31873200        size_t num_acls = 0;
    31883201        size_t num_def_acls = 0;
     
    31903203        canon_ace *file_ace = NULL;
    31913204        canon_ace *dir_ace = NULL;
    3192         SEC_ACE *nt_ace_list = NULL;
     3205        struct security_ace *nt_ace_list = NULL;
    31933206        size_t num_profile_acls = 0;
    3194         DOM_SID orig_owner_sid;
    3195         SEC_DESC *psd = NULL;
     3207        struct dom_sid orig_owner_sid;
     3208        struct security_descriptor *psd = NULL;
    31963209        int i;
    31973210
     
    32103223        }
    32113224
    3212         if ((security_info & DACL_SECURITY_INFORMATION) && !(security_info & PROTECTED_DACL_SECURITY_INFORMATION)) {
     3225        if ((security_info & SECINFO_DACL) && !(security_info & SECINFO_PROTECTED_DACL)) {
    32133226
    32143227                /*
     
    33023315
    33033316                        /* Allocate the ace list. */
    3304                         if ((nt_ace_list = SMB_MALLOC_ARRAY(SEC_ACE,num_acls + num_profile_acls + num_def_acls)) == NULL) {
     3317                        if ((nt_ace_list = SMB_MALLOC_ARRAY(struct security_ace,num_acls + num_profile_acls + num_def_acls)) == NULL) {
    33053318                                DEBUG(0,("get_nt_acl: Unable to malloc space for nt_ace_list.\n"));
    33063319                                goto done;
    33073320                        }
    33083321
    3309                         memset(nt_ace_list, '\0', (num_acls + num_def_acls) * sizeof(SEC_ACE) );
     3322                        memset(nt_ace_list, '\0', (num_acls + num_def_acls) * sizeof(struct security_ace) );
    33103323
    33113324                        /*
     
    33713384                        if (lp_profile_acls(SNUM(conn))) {
    33723385                                for (i = 0; i < num_aces; i++) {
    3373                                         if (sid_equal(&nt_ace_list[i].trustee, &owner_sid)) {
     3386                                        if (dom_sid_equal(&nt_ace_list[i].trustee, &owner_sid)) {
    33743387                                                add_or_replace_ace(nt_ace_list, &num_aces,
    33753388                                                                   &orig_owner_sid,
     
    33893402                        }
    33903403                }
    3391         } /* security_info & DACL_SECURITY_INFORMATION */
     3404        } /* security_info & SECINFO_DACL */
    33923405
    33933406        psd = make_standard_sec_desc( talloc_tos(),
    3394                         (security_info & OWNER_SECURITY_INFORMATION) ? &owner_sid : NULL,
    3395                         (security_info & GROUP_SECURITY_INFORMATION) ? &group_sid : NULL,
     3407                        (security_info & SECINFO_OWNER) ? &owner_sid : NULL,
     3408                        (security_info & SECINFO_GROUP) ? &group_sid : NULL,
    33963409                        psa,
    33973410                        &sd_size);
     
    34423455
    34433456NTSTATUS posix_fget_nt_acl(struct files_struct *fsp, uint32_t security_info,
    3444                            SEC_DESC **ppdesc)
     3457                           struct security_descriptor **ppdesc)
    34453458{
    34463459        SMB_STRUCT_STAT sbuf;
     
    34753488
    34763489NTSTATUS posix_get_nt_acl(struct connection_struct *conn, const char *name,
    3477                           uint32_t security_info, SEC_DESC **ppdesc)
     3490                          uint32_t security_info, struct security_descriptor **ppdesc)
    34783491{
    34793492        SMB_ACL_T posix_acl = NULL;
     
    35213534
    35223535  1) If we have root privileges, then it will just work.
    3523   2) If we have SeTakeOwnershipPrivilege we can change the user to the current user.
    3524   3) If we have SeRestorePrivilege we can change the user to any other user.
     3536  2) If we have SeRestorePrivilege we can change the user + group to any other user.
     3537  3) If we have SeTakeOwnershipPrivilege we can change the user to the current user.
    35253538  4) If we have write permission to the file and dos_filemodes is set
    35263539     then allow chown to the currently authenticated user.
    35273540****************************************************************************/
    35283541
    3529 int try_chown(connection_struct *conn, struct smb_filename *smb_fname,
    3530               uid_t uid, gid_t gid)
    3531 {
    3532         int ret;
    3533         files_struct *fsp;
    3534 
    3535         if(!CAN_WRITE(conn)) {
    3536                 return -1;
     3542NTSTATUS try_chown(files_struct *fsp, uid_t uid, gid_t gid)
     3543{
     3544        NTSTATUS status;
     3545
     3546        if(!CAN_WRITE(fsp->conn)) {
     3547                return NT_STATUS_MEDIA_WRITE_PROTECTED;
    35373548        }
    35383549
    35393550        /* Case (1). */
    3540         /* try the direct way first */
    3541         if (lp_posix_pathnames()) {
    3542                 ret = SMB_VFS_LCHOWN(conn, smb_fname->base_name, uid, gid);
    3543         } else {
    3544                 ret = SMB_VFS_CHOWN(conn, smb_fname->base_name, uid, gid);
    3545         }
    3546 
    3547         if (ret == 0)
    3548                 return 0;
     3551        status = vfs_chown_fsp(fsp, uid, gid);
     3552        if (NT_STATUS_IS_OK(status)) {
     3553                return status;
     3554        }
    35493555
    35503556        /* Case (2) / (3) */
    35513557        if (lp_enable_privileges()) {
    3552 
    3553                 bool has_take_ownership_priv = user_has_privileges(current_user.nt_user_token,
    3554                                                               &se_take_ownership);
    3555                 bool has_restore_priv = user_has_privileges(current_user.nt_user_token,
    3556                                                        &se_restore);
    3557 
    3558                 /* Case (2) */
    3559                 if ( ( has_take_ownership_priv && ( uid == current_user.ut.uid ) ) ||
    3560                 /* Case (3) */
    3561                      ( has_restore_priv ) ) {
    3562 
     3558                bool has_take_ownership_priv = security_token_has_privilege(
     3559                                                get_current_nttok(fsp->conn),
     3560                                                SEC_PRIV_TAKE_OWNERSHIP);
     3561                bool has_restore_priv = security_token_has_privilege(
     3562                                                get_current_nttok(fsp->conn),
     3563                                                SEC_PRIV_RESTORE);
     3564
     3565                if (has_restore_priv) {
     3566                        ; /* Case (2) */
     3567                } else if (has_take_ownership_priv) {
     3568                        /* Case (3) */
     3569                        if (uid == get_current_uid(fsp->conn)) {
     3570                                gid = (gid_t)-1;
     3571                        } else {
     3572                                has_take_ownership_priv = false;
     3573                        }
     3574                }
     3575
     3576                if (has_take_ownership_priv || has_restore_priv) {
    35633577                        become_root();
    3564                         /* Keep the current file gid the same - take ownership doesn't imply group change. */
    3565                         if (lp_posix_pathnames()) {
    3566                                 ret = SMB_VFS_LCHOWN(conn, smb_fname->base_name, uid,
    3567                                                     (gid_t)-1);
    3568                         } else {
    3569                                 ret = SMB_VFS_CHOWN(conn, smb_fname->base_name, uid,
    3570                                                     (gid_t)-1);
    3571                         }
     3578                        status = vfs_chown_fsp(fsp, uid, gid);
    35723579                        unbecome_root();
    3573                         return ret;
     3580                        return status;
    35743581                }
    35753582        }
    35763583
    35773584        /* Case (4). */
    3578         if (!lp_dos_filemode(SNUM(conn))) {
    3579                 errno = EPERM;
    3580                 return -1;
     3585        if (!lp_dos_filemode(SNUM(fsp->conn))) {
     3586                return NT_STATUS_ACCESS_DENIED;
    35813587        }
    35823588
     
    35853591           a local SID on the users workstation
    35863592        */
    3587         if (uid != current_user.ut.uid) {
    3588                 errno = EPERM;
    3589                 return -1;
    3590         }
    3591 
    3592         if (lp_posix_pathnames()) {
    3593                 ret = SMB_VFS_LSTAT(conn, smb_fname);
    3594         } else {
    3595                 ret = SMB_VFS_STAT(conn, smb_fname);
    3596         }
    3597 
    3598         if (ret == -1) {
    3599                 return -1;
    3600         }
    3601 
    3602         if (!NT_STATUS_IS_OK(open_file_fchmod(conn, smb_fname, &fsp))) {
    3603                 return -1;
     3593        if (uid != get_current_uid(fsp->conn)) {
     3594                return NT_STATUS_ACCESS_DENIED;
    36043595        }
    36053596
    36063597        become_root();
    36073598        /* Keep the current file gid the same. */
    3608         if (fsp->fh->fd == -1) {
    3609                 if (lp_posix_pathnames()) {
    3610                         ret = SMB_VFS_LCHOWN(conn, smb_fname->base_name, uid,
    3611                                             (gid_t)-1);
    3612                 } else {
    3613                         ret = SMB_VFS_CHOWN(conn, smb_fname->base_name, uid,
    3614                                             (gid_t)-1);
    3615                 }
    3616         } else {
    3617                 ret = SMB_VFS_FCHOWN(fsp, uid, (gid_t)-1);
    3618         }
     3599        status = vfs_chown_fsp(fsp, uid, (gid_t)-1);
    36193600        unbecome_root();
    36203601
    3621         close_file(NULL, fsp, NORMAL_CLOSE);
    3622 
    3623         return ret;
     3602        return status;
    36243603}
    36253604
     
    36323611
    36333612NTSTATUS append_parent_acl(files_struct *fsp,
    3634                                 const SEC_DESC *pcsd,
    3635                                 SEC_DESC **pp_new_sd)
     3613                                const struct security_descriptor *pcsd,
     3614                                struct security_descriptor **pp_new_sd)
    36363615{
    36373616        struct smb_filename *smb_dname = NULL;
    3638         SEC_DESC *parent_sd = NULL;
     3617        struct security_descriptor *parent_sd = NULL;
    36393618        files_struct *parent_fsp = NULL;
    36403619        TALLOC_CTX *mem_ctx = talloc_tos();
    36413620        char *parent_name = NULL;
    3642         SEC_ACE *new_ace = NULL;
     3621        struct security_ace *new_ace = NULL;
    36433622        unsigned int num_aces = pcsd->dacl->num_aces;
    36443623        NTSTATUS status;
    36453624        int info;
    36463625        unsigned int i, j;
    3647         SEC_DESC *psd = dup_sec_desc(talloc_tos(), pcsd);
     3626        struct security_descriptor *psd = dup_sec_desc(talloc_tos(), pcsd);
    36483627        bool is_dacl_protected = (pcsd->type & SEC_DESC_DACL_PROTECTED);
    36493628
     
    36863665
    36873666        status = SMB_VFS_GET_NT_ACL(parent_fsp->conn, smb_dname->base_name,
    3688                                     DACL_SECURITY_INFORMATION, &parent_sd );
     3667                                    SECINFO_DACL, &parent_sd );
    36893668
    36903669        close_file(NULL, parent_fsp, NORMAL_CLOSE);
     
    37093688        num_aces += parent_sd->dacl->num_aces;
    37103689
    3711         if((new_ace = TALLOC_ZERO_ARRAY(mem_ctx, SEC_ACE,
     3690        if((new_ace = TALLOC_ZERO_ARRAY(mem_ctx, struct security_ace,
    37123691                                        num_aces)) == NULL) {
    37133692                return NT_STATUS_NO_MEMORY;
     
    37263705        /* Finally append any inherited ACEs. */
    37273706        for (j = 0; j < parent_sd->dacl->num_aces; j++) {
    3728                 SEC_ACE *se = &parent_sd->dacl->aces[j];
     3707                struct security_ace *se = &parent_sd->dacl->aces[j];
    37293708
    37303709                if (fsp->is_directory) {
     
    37623741                        unsigned int k;
    37633742                        for (k = 0; k < psd->dacl->num_aces; k++) {
    3764                                 if (sid_equal(&psd->dacl->aces[k].trustee,
     3743                                if (dom_sid_equal(&psd->dacl->aces[k].trustee,
    37653744                                                &se->trustee)) {
    37663745                                        break;
     
    38173796        psd->dacl->aces = new_ace;
    38183797        psd->dacl->num_aces = i;
    3819         psd->type &= ~(SE_DESC_DACL_AUTO_INHERITED|
    3820                          SE_DESC_DACL_AUTO_INHERIT_REQ);
     3798        psd->type &= ~(SEC_DESC_DACL_AUTO_INHERITED|
     3799                         SEC_DESC_DACL_AUTO_INHERIT_REQ);
    38213800
    38223801        *pp_new_sd = psd;
     
    38293808 description of the following NT ACL.
    38303809 This should be the only external function needed for the UNIX style set ACL.
    3831 ****************************************************************************/
    3832 
    3833 NTSTATUS set_nt_acl(files_struct *fsp, uint32 security_info_sent, const SEC_DESC *psd_orig)
     3810 We make a copy of psd_orig as internal functions modify the elements inside
     3811 it, even though it's a const pointer.
     3812****************************************************************************/
     3813
     3814NTSTATUS set_nt_acl(files_struct *fsp, uint32 security_info_sent, const struct security_descriptor *psd_orig)
    38343815{
    38353816        connection_struct *conn = fsp->conn;
    38363817        uid_t user = (uid_t)-1;
    38373818        gid_t grp = (gid_t)-1;
    3838         DOM_SID file_owner_sid;
    3839         DOM_SID file_grp_sid;
     3819        struct dom_sid file_owner_sid;
     3820        struct dom_sid file_grp_sid;
    38403821        canon_ace *file_ace_list = NULL;
    38413822        canon_ace *dir_ace_list = NULL;
     
    38463827        bool acl_set_support = false;
    38473828        bool ret = false;
    3848         SEC_DESC *psd = NULL;
     3829        struct security_descriptor *psd = NULL;
    38493830
    38503831        DEBUG(10,("set_nt_acl: called for file %s\n",
     
    38893870        }
    38903871
    3891         status = unpack_nt_owners( SNUM(conn), &user, &grp, security_info_sent, psd);
     3872        status = unpack_nt_owners( conn, &user, &grp, security_info_sent, psd);
    38923873        if (!NT_STATUS_IS_OK(status)) {
    38933874                return status;
     
    39073888                         (unsigned int)grp));
    39083889
    3909                 if(try_chown(fsp->conn, fsp->fsp_name, user, grp) == -1) {
     3890                status = try_chown(fsp, user, grp);
     3891                if(!NT_STATUS_IS_OK(status)) {
    39103892                        DEBUG(3,("set_nt_acl: chown %s, %u, %u failed. Error "
    3911                                  "= %s.\n", fsp_str_dbg(fsp),
    3912                                  (unsigned int)user, (unsigned int)grp,
    3913                                  strerror(errno)));
    3914                         if (errno == EPERM) {
    3915                                 return NT_STATUS_INVALID_OWNER;
    3916                         }
    3917                         return map_nt_error_from_unix(errno);
     3893                                "= %s.\n", fsp_str_dbg(fsp),
     3894                                (unsigned int)user,
     3895                                (unsigned int)grp,
     3896                                nt_errstr(status)));
     3897                        return status;
    39183898                }
    39193899
     
    39423922                        (psd->type & SEC_DESC_DACL_PRESENT) &&
    39433923                        (psd->dacl == NULL)) {
    3944                 SEC_ACE ace[3];
     3924                struct security_ace ace[3];
    39453925
    39463926                /* We can't have NULL DACL in POSIX.
     
    39923972         */
    39933973
    3994         if(!(security_info_sent & DACL_SECURITY_INFORMATION) || (psd->dacl == NULL)) {
     3974        if(!(security_info_sent & SECINFO_DACL) || (psd->dacl == NULL)) {
    39953975                free_canon_ace_list(file_ace_list);
    39963976                free_canon_ace_list(dir_ace_list);
     
    47574737********************************************************************/
    47584738
    4759 SEC_DESC *get_nt_acl_no_snum( TALLOC_CTX *ctx, const char *fname)
    4760 {
    4761         SEC_DESC *psd, *ret_sd;
     4739struct security_descriptor *get_nt_acl_no_snum( TALLOC_CTX *ctx, const char *fname)
     4740{
     4741        struct security_descriptor *psd, *ret_sd;
    47624742        connection_struct *conn;
    47634743        files_struct finfo;
     
    48024782        }
    48034783
    4804         if (!NT_STATUS_IS_OK(SMB_VFS_FGET_NT_ACL( &finfo, DACL_SECURITY_INFORMATION, &psd))) {
     4784        if (!NT_STATUS_IS_OK(SMB_VFS_FGET_NT_ACL( &finfo, SECINFO_DACL, &psd))) {
    48054785                DEBUG(0,("get_nt_acl_no_snum: get_nt_acl returned zero.\n"));
    48064786                TALLOC_FREE(finfo.fsp_name);
     
    48224802                                        const char *name,
    48234803                                        SMB_STRUCT_STAT *psbuf,
    4824                                         SEC_DESC **ppdesc)
     4804                                        struct security_descriptor **ppdesc)
    48254805{
    48264806        struct dom_sid owner_sid, group_sid;
    48274807        size_t size = 0;
    4828         SEC_ACE aces[4];
     4808        struct security_ace aces[4];
    48294809        uint32_t access_mask = 0;
    48304810        mode_t mode = psbuf->st_ex_mode;
    4831         SEC_ACL *new_dacl = NULL;
     4811        struct security_acl *new_dacl = NULL;
    48324812        int idx = 0;
    48334813
Note: See TracChangeset for help on using the changeset viewer.