Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/groupdb/mapping.c

    r740 r988  
    2828#include "lib/winbind_util.h"
    2929#include <tdb.h>
     30#include "groupdb/mapping_tdb.h"
    3031
    3132static const struct mapping_backend *backend;
     
    5152NTSTATUS add_initial_entry(gid_t gid, const char *sid, enum lsa_SidType sid_name_use, const char *nt_name, const char *comment)
    5253{
    53         GROUP_MAP map;
     54        NTSTATUS status;
     55        GROUP_MAP *map;
    5456
    5557        if(!init_group_mapping()) {
     
    5860        }
    5961
    60         map.gid=gid;
    61         if (!string_to_sid(&map.sid, sid)) {
     62        map = talloc_zero(NULL, GROUP_MAP);
     63        if (!map) {
     64                return NT_STATUS_NO_MEMORY;
     65        }
     66
     67        map->gid=gid;
     68        if (!string_to_sid(&map->sid, sid)) {
    6269                DEBUG(0, ("string_to_sid failed: %s", sid));
    63                 return NT_STATUS_UNSUCCESSFUL;
    64         }
    65 
    66         map.sid_name_use=sid_name_use;
    67         fstrcpy(map.nt_name, nt_name);
    68         fstrcpy(map.comment, comment);
    69 
    70         return pdb_add_group_mapping_entry(&map);
     70                status = NT_STATUS_UNSUCCESSFUL;
     71                goto done;
     72        }
     73
     74        map->sid_name_use=sid_name_use;
     75        map->nt_name = talloc_strdup(map, nt_name);
     76        if (!map->nt_name) {
     77                status = NT_STATUS_NO_MEMORY;
     78                goto done;
     79        }
     80
     81        if (comment) {
     82                map->comment = talloc_strdup(map, comment);
     83        } else {
     84                map->comment = talloc_strdup(map, "");
     85        }
     86        if (!map->comment) {
     87                status = NT_STATUS_NO_MEMORY;
     88                goto done;
     89        }
     90
     91        status = pdb_add_group_mapping_entry(map);
     92
     93done:
     94        TALLOC_FREE(map);
     95        return status;
    7196}
    7297
     
    128153
    129154        if ( !ret ) {
    130                 uint32 rid;
     155                uint32_t rid;
    131156
    132157                sid_peek_rid( &sid, &rid );
    133158
    134159                if ( rid == DOMAIN_RID_USERS ) {
    135                         fstrcpy( map->nt_name, "None" );
    136                         fstrcpy( map->comment, "Ordinary Users" );
     160                        map->nt_name = talloc_strdup(map, "None");
     161                        if (!map->nt_name) {
     162                                return false;
     163                        }
     164                        map->comment = talloc_strdup(map, "Ordinary Users");
     165                        if (!map->comment) {
     166                                return false;
     167                        }
    137168                        sid_copy( &map->sid, &sid );
    138169                        map->sid_name_use = SID_NAME_DOM_GRP;
     
    183214        /* defer to scripts */
    184215
    185         if ( *lp_addgroup_script() ) {
     216        if ( *lp_add_group_script(talloc_tos()) ) {
    186217                TALLOC_CTX *ctx = talloc_tos();
    187218
    188219                add_script = talloc_strdup(ctx,
    189                                         lp_addgroup_script());
     220                                        lp_add_group_script(ctx));
    190221                if (!add_script) {
    191222                        return -1;
     
    239270        /* defer to scripts */
    240271
    241         if ( *lp_delgroup_script() ) {
     272        if ( *lp_delete_group_script(talloc_tos()) ) {
    242273                TALLOC_CTX *ctx = talloc_tos();
    243274
    244275                del_script = talloc_strdup(ctx,
    245                                 lp_delgroup_script());
     276                                lp_delete_group_script(ctx));
    246277                if (!del_script) {
    247278                        return -1;
     
    274305        /* defer to scripts */
    275306
    276         if ( *lp_setprimarygroup_script() ) {
     307        if ( *lp_set_primary_group_script(talloc_tos()) ) {
    277308                TALLOC_CTX *ctx = talloc_tos();
    278309
    279310                add_script = talloc_strdup(ctx,
    280                                 lp_setprimarygroup_script());
     311                                lp_set_primary_group_script(ctx));
    281312                if (!add_script) {
    282313                        return -1;
     
    316347        /* defer to scripts */
    317348
    318         if ( *lp_addusertogroup_script() ) {
     349        if ( *lp_add_user_to_group_script(talloc_tos()) ) {
    319350                TALLOC_CTX *ctx = talloc_tos();
    320351
    321352                add_script = talloc_strdup(ctx,
    322                                 lp_addusertogroup_script());
     353                                lp_add_user_to_group_script(ctx));
    323354                if (!add_script) {
    324355                        return -1;
     
    356387        /* defer to scripts */
    357388
    358         if ( *lp_deluserfromgroup_script() ) {
     389        if ( *lp_delete_user_from_group_script(talloc_tos()) ) {
    359390                TALLOC_CTX *ctx = talloc_tos();
    360391
    361392                del_script = talloc_strdup(ctx,
    362                                 lp_deluserfromgroup_script());
     393                                lp_delete_user_from_group_script(ctx));
    363394                if (!del_script) {
    364395                        return -1;
     
    453484
    454485NTSTATUS pdb_default_enum_group_mapping(struct pdb_methods *methods,
    455                                            const struct dom_sid *sid, enum lsa_SidType sid_name_use,
    456                                            GROUP_MAP **pp_rmap, size_t *p_num_entries,
    457                                            bool unix_only)
     486                                        const struct dom_sid *sid,
     487                                        enum lsa_SidType sid_name_use,
     488                                        GROUP_MAP ***pp_rmap,
     489                                        size_t *p_num_entries,
     490                                        bool unix_only)
    458491{
    459492        if (!init_group_mapping()) {
     
    466499
    467500NTSTATUS pdb_default_create_alias(struct pdb_methods *methods,
    468                                   const char *name, uint32 *rid)
     501                                  const char *name, uint32_t *rid)
    469502{
    470503        struct dom_sid sid;
    471504        enum lsa_SidType type;
    472         uint32 new_rid;
     505        uint32_t new_rid;
    473506        gid_t gid;
    474507        bool exists;
    475         GROUP_MAP map;
     508        GROUP_MAP *map;
    476509        TALLOC_CTX *mem_ctx;
    477510        NTSTATUS status;
     
    486519        exists = lookup_name(mem_ctx, name, LOOKUP_NAME_LOCAL,
    487520                             NULL, NULL, &sid, &type);
    488         TALLOC_FREE(mem_ctx);
    489521
    490522        if (exists) {
    491                 return NT_STATUS_ALIAS_EXISTS;
     523                status = NT_STATUS_ALIAS_EXISTS;
     524                goto done;
    492525        }
    493526
    494527        if (!pdb_new_rid(&new_rid)) {
    495528                DEBUG(0, ("Could not allocate a RID.\n"));
    496                 return NT_STATUS_ACCESS_DENIED;
     529                status = NT_STATUS_ACCESS_DENIED;
     530                goto done;
    497531        }
    498532
     
    502536                DEBUG(3, ("Could not get a gid out of winbind - "
    503537                          "wasted a rid :-(\n"));
    504                 return NT_STATUS_ACCESS_DENIED;
     538                status = NT_STATUS_ACCESS_DENIED;
     539                goto done;
    505540        }
    506541
     
    508543                   name, (unsigned int)gid, (unsigned int)new_rid));
    509544
    510         map.gid = gid;
    511         sid_copy(&map.sid, &sid);
    512         map.sid_name_use = SID_NAME_ALIAS;
    513         fstrcpy(map.nt_name, name);
    514         fstrcpy(map.comment, "");
    515 
    516         status = pdb_add_group_mapping_entry(&map);
     545        map = talloc_zero(mem_ctx, GROUP_MAP);
     546        if (!map) {
     547                status = NT_STATUS_NO_MEMORY;
     548                goto done;
     549        }
     550
     551        map->gid = gid;
     552        sid_copy(&map->sid, &sid);
     553        map->sid_name_use = SID_NAME_ALIAS;
     554        map->nt_name = talloc_strdup(map, name);
     555        if (!map->nt_name) {
     556                status = NT_STATUS_NO_MEMORY;
     557                goto done;
     558        }
     559        map->comment = talloc_strdup(map, "");
     560        if (!map->comment) {
     561                status = NT_STATUS_NO_MEMORY;
     562                goto done;
     563        }
     564
     565        status = pdb_add_group_mapping_entry(map);
    517566
    518567        if (!NT_STATUS_IS_OK(status)) {
    519568                DEBUG(0, ("Could not add group mapping entry for alias %s "
    520569                          "(%s)\n", name, nt_errstr(status)));
    521                 return status;
     570                goto done;
    522571        }
    523572
    524573        *rid = new_rid;
    525574
    526         return NT_STATUS_OK;
     575done:
     576        TALLOC_FREE(mem_ctx);
     577        return status;
    527578}
    528579
     
    537588                                   struct acct_info *info)
    538589{
    539         GROUP_MAP map;
    540 
    541         if (!pdb_getgrsid(&map, *sid))
    542                 return NT_STATUS_NO_SUCH_ALIAS;
    543 
    544         if ((map.sid_name_use != SID_NAME_ALIAS) &&
    545             (map.sid_name_use != SID_NAME_WKN_GRP)) {
     590        NTSTATUS status = NT_STATUS_OK;
     591        GROUP_MAP *map;
     592
     593        map = talloc_zero(NULL, GROUP_MAP);
     594        if (!map) {
     595                return NT_STATUS_NO_MEMORY;
     596        }
     597
     598        if (!pdb_getgrsid(map, *sid)) {
     599                status = NT_STATUS_NO_SUCH_ALIAS;
     600                goto done;
     601        }
     602
     603        if ((map->sid_name_use != SID_NAME_ALIAS) &&
     604            (map->sid_name_use != SID_NAME_WKN_GRP)) {
    546605                DEBUG(2, ("%s is a %s, expected an alias\n",
    547606                          sid_string_dbg(sid),
    548                           sid_type_lookup(map.sid_name_use)));
    549                 return NT_STATUS_NO_SUCH_ALIAS;
    550         }
    551 
    552         fstrcpy(info->acct_name, map.nt_name);
    553         fstrcpy(info->acct_desc, map.comment);
    554         sid_peek_rid(&map.sid, &info->rid);
    555         return NT_STATUS_OK;
     607                          sid_type_lookup(map->sid_name_use)));
     608                status = NT_STATUS_NO_SUCH_ALIAS;
     609                goto done;
     610        }
     611
     612        info->acct_name = talloc_move(info, &map->nt_name);
     613        if (!info->acct_name) {
     614                status = NT_STATUS_NO_MEMORY;
     615                goto done;
     616        }
     617        info->acct_desc = talloc_move(info, &map->comment);
     618        if (!info->acct_desc) {
     619                status = NT_STATUS_NO_MEMORY;
     620                goto done;
     621        }
     622        sid_peek_rid(&map->sid, &info->rid);
     623
     624done:
     625        TALLOC_FREE(map);
     626        return status;
    556627}
    557628
     
    560631                                   struct acct_info *info)
    561632{
    562         GROUP_MAP map;
    563 
    564         if (!pdb_getgrsid(&map, *sid))
    565                 return NT_STATUS_NO_SUCH_ALIAS;
    566 
    567         fstrcpy(map.nt_name, info->acct_name);
    568         fstrcpy(map.comment, info->acct_desc);
    569 
    570         return pdb_update_group_mapping_entry(&map);
     633        NTSTATUS status = NT_STATUS_OK;
     634        GROUP_MAP *map;
     635
     636        map = talloc_zero(NULL, GROUP_MAP);
     637        if (!map) {
     638                return NT_STATUS_NO_MEMORY;
     639        }
     640
     641        if (!pdb_getgrsid(map, *sid)) {
     642                status = NT_STATUS_NO_SUCH_ALIAS;
     643                goto done;
     644        }
     645
     646        map->nt_name = talloc_strdup(map, info->acct_name);
     647        if (!map->nt_name) {
     648                status = NT_STATUS_NO_MEMORY;
     649                goto done;
     650        }
     651        map->comment = talloc_strdup(map, info->acct_desc);
     652        if (!map->comment) {
     653                status = NT_STATUS_NO_MEMORY;
     654                goto done;
     655        }
     656
     657        status = pdb_update_group_mapping_entry(map);
     658
     659done:
     660        TALLOC_FREE(map);
     661        return status;
    571662}
    572663
     
    608699                                       const struct dom_sid *members,
    609700                                       size_t num_members,
    610                                        uint32 **pp_alias_rids,
     701                                       uint32_t **pp_alias_rids,
    611702                                       size_t *p_num_alias_rids)
    612703{
     
    636727        }
    637728
    638         *pp_alias_rids = TALLOC_ARRAY(mem_ctx, uint32, num_alias_sids);
     729        *pp_alias_rids = talloc_array(mem_ctx, uint32_t, num_alias_sids);
    639730        if (*pp_alias_rids == NULL)
    640731                return NT_STATUS_NO_MEMORY;
     
    700791}
    701792
    702 /****************************************************************************
    703  These need to be redirected through pdb_interface.c
    704 ****************************************************************************/
    705 bool pdb_get_dom_grp_info(const struct dom_sid *sid, struct acct_info *info)
    706 {
    707         GROUP_MAP map;
    708         bool res;
    709 
    710         become_root();
    711         res = get_domain_group_from_sid(*sid, &map);
    712         unbecome_root();
    713 
    714         if (!res)
    715                 return False;
    716 
    717         fstrcpy(info->acct_name, map.nt_name);
    718         fstrcpy(info->acct_desc, map.comment);
    719         sid_peek_rid(sid, &info->rid);
    720         return True;
    721 }
    722 
    723 bool pdb_set_dom_grp_info(const struct dom_sid *sid, const struct acct_info *info)
    724 {
    725         GROUP_MAP map;
    726 
    727         if (!get_domain_group_from_sid(*sid, &map))
    728                 return False;
    729 
    730         fstrcpy(map.nt_name, info->acct_name);
    731         fstrcpy(map.comment, info->acct_desc);
    732 
    733         return NT_STATUS_IS_OK(pdb_update_group_mapping_entry(&map));
    734 }
    735 
    736 /********************************************************************
    737  Really just intended to be called by smbd
    738 ********************************************************************/
    739 
    740 NTSTATUS pdb_create_builtin_alias(uint32 rid)
     793/**
     794* @brief Add a new group mapping
     795*
     796* @param[in] gid gid to use to store the mapping. If gid is 0,
     797*                new gid will be allocated from winbind
     798*
     799* @return Normal NTSTATUS return
     800*/
     801NTSTATUS pdb_create_builtin_alias(uint32_t rid, gid_t gid)
    741802{
    742803        struct dom_sid sid;
    743804        enum lsa_SidType type;
    744         gid_t gid;
    745         GROUP_MAP map;
    746         TALLOC_CTX *mem_ctx;
     805        gid_t gidformap;
     806        GROUP_MAP *map;
    747807        NTSTATUS status;
    748808        const char *name = NULL;
    749         fstring groupname;
    750809
    751810        DEBUG(10, ("Trying to create builtin alias %d\n", rid));
     
    755814        }
    756815
    757         if ( (mem_ctx = talloc_new(NULL)) == NULL ) {
     816        /* use map as overall temp mem context */
     817        map = talloc_zero(NULL, GROUP_MAP);
     818        if (!map) {
    758819                return NT_STATUS_NO_MEMORY;
    759820        }
    760821
    761         if ( !lookup_sid(mem_ctx, &sid, NULL, &name, &type) ) {
    762                 TALLOC_FREE( mem_ctx );
    763                 return NT_STATUS_NO_SUCH_ALIAS;
    764         }
    765 
    766         /* validate RID so copy the name and move on */
    767 
    768         fstrcpy( groupname, name );
    769         TALLOC_FREE( mem_ctx );
    770 
    771         if (!winbind_allocate_gid(&gid)) {
    772                 DEBUG(3, ("pdb_create_builtin_alias: Could not get a gid out of winbind\n"));
    773                 return NT_STATUS_ACCESS_DENIED;
    774         }
    775 
    776         DEBUG(10,("Creating alias %s with gid %u\n", groupname, (unsigned int)gid));
    777 
    778         map.gid = gid;
    779         sid_copy(&map.sid, &sid);
    780         map.sid_name_use = SID_NAME_ALIAS;
    781         fstrcpy(map.nt_name, groupname);
    782         fstrcpy(map.comment, "");
    783 
    784         status = pdb_add_group_mapping_entry(&map);
     822        if (!lookup_sid(map, &sid, NULL, &name, &type)) {
     823                status = NT_STATUS_NO_SUCH_ALIAS;
     824                goto done;
     825        }
     826
     827        if (gid == 0) {
     828                if (!winbind_allocate_gid(&gidformap)) {
     829                        DEBUG(3, ("pdb_create_builtin_alias: Could not get a "
     830                                  "gid out of winbind\n"));
     831                        status = NT_STATUS_ACCESS_DENIED;
     832                        goto done;
     833                }
     834        } else {
     835                gidformap = gid;
     836        }
     837
     838        DEBUG(10, ("Creating alias %s with gid %u\n", name,
     839                   (unsigned) gidformap));
     840
     841        map->gid = gidformap;
     842        sid_copy(&map->sid, &sid);
     843        map->sid_name_use = SID_NAME_ALIAS;
     844        map->nt_name = talloc_strdup(map, name);
     845        if (!map->nt_name) {
     846                status = NT_STATUS_NO_MEMORY;
     847                goto done;
     848        }
     849        map->comment = talloc_strdup(map, "");
     850        if (!map->comment) {
     851                status = NT_STATUS_NO_MEMORY;
     852                goto done;
     853        }
     854
     855        status = pdb_add_group_mapping_entry(map);
    785856
    786857        if (!NT_STATUS_IS_OK(status)) {
     
    789860        }
    790861
     862done:
     863        TALLOC_FREE(map);
    791864        return status;
    792865}
Note: See TracChangeset for help on using the changeset viewer.