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

Location:
vendor/current/source3/groupdb
Files:
1 added
1 deleted
3 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}
  • vendor/current/source3/groupdb/mapping.h

    r740 r988  
    4646        bool (*group_map_remove)(const struct dom_sid *sid);
    4747        bool (*enum_group_mapping)(const struct dom_sid *domsid, enum lsa_SidType sid_name_use,
    48                                    GROUP_MAP **pp_rmap,
     48                                   GROUP_MAP ***pp_rmap,
    4949                                   size_t *p_num_entries, bool unix_only);
    5050        NTSTATUS (*one_alias_membership)(const struct dom_sid *member,
  • vendor/current/source3/groupdb/mapping_tdb.c

    r740 r988  
    2525#include "passdb.h"
    2626#include "groupdb/mapping.h"
    27 #include "dbwrap.h"
     27#include "dbwrap/dbwrap.h"
     28#include "dbwrap/dbwrap_open.h"
    2829#include "util_tdb.h"
    2930#include "../libcli/security/security.h"
     31#include "groupdb/mapping_tdb.h"
    3032
    3133static struct db_context *db; /* used for driver files */
     
    3335static bool enum_group_mapping(const struct dom_sid *domsid,
    3436                               enum lsa_SidType sid_name_use,
    35                                GROUP_MAP **pp_rmap,
     37                               GROUP_MAP ***pp_rmap,
    3638                               size_t *p_num_entries,
    3739                               bool unix_only);
     
    4547static bool init_group_mapping(void)
    4648{
    47         const char *ldb_path;
     49        char *tdb_path;
     50        char *ldb_path;
    4851
    4952        if (db != NULL) {
     
    5154        }
    5255
    53         db = db_open(NULL, state_path("group_mapping.tdb"), 0,
    54                            TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
     56        tdb_path = state_path("group_mapping.tdb");
     57        if (tdb_path == NULL) {
     58                return false;
     59        }
     60        db = db_open(NULL, tdb_path, 0,
     61                     TDB_DEFAULT, O_RDWR|O_CREAT, 0600,
     62                     DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);
    5563        if (db == NULL) {
    5664                DEBUG(0, ("Failed to open group mapping database: %s\n",
    5765                          strerror(errno)));
     66                talloc_free(tdb_path);
    5867                return false;
    5968        }
    6069
    6170        ldb_path = state_path("group_mapping.ldb");
     71        if (ldb_path == NULL) {
     72                talloc_free(tdb_path);
     73                return false;
     74        }
    6275        if (file_exist(ldb_path) && !mapping_switch(ldb_path)) {
    63                 unlink(state_path("group_mapping.tdb"));
     76                unlink(tdb_path);
     77                talloc_free(tdb_path);
     78                talloc_free(ldb_path);
    6479                return false;
    6580
     
    87102                }
    88103
    89                 /* if its an unknown version we remove everthing in the db */
     104                /* if its an unknown version we remove everything in the db */
    90105
    91106                if (vers_id != DATABASE_VERSION_V2) {
     
    112127#endif
    113128        }
     129        talloc_free(tdb_path);
     130        talloc_free(ldb_path);
    114131        return true;
    115132}
     
    117134static char *group_mapping_key(TALLOC_CTX *mem_ctx, const struct dom_sid *sid)
    118135{
    119         char *sidstr, *result;
    120 
    121         sidstr = sid_string_talloc(talloc_tos(), sid);
    122         if (sidstr == NULL) {
     136        char sidstr[DOM_SID_STR_BUFLEN];
     137        int len;
     138
     139        len = dom_sid_string_buf(sid, sidstr, sizeof(sidstr));
     140        if (len >= sizeof(sidstr)) {
    123141                return NULL;
    124142        }
    125143
    126         result = talloc_asprintf(mem_ctx, "%s%s", GROUP_PREFIX, sidstr);
    127 
    128         TALLOC_FREE(sidstr);
    129         return result;
     144        return talloc_asprintf(mem_ctx, "%s%s", GROUP_PREFIX, sidstr);
    130145}
    131146
     
    146161                map->gid, map->sid_name_use, map->nt_name, map->comment);
    147162
    148         buf = TALLOC_ARRAY(key, char, len);
     163        buf = talloc_array(key, char, len);
    149164        if (!buf) {
    150165                TALLOC_FREE(key);
    151166                return false;
    152167        }
    153         len = tdb_pack((uint8 *)buf, len, "ddff", map->gid,
     168        len = tdb_pack((uint8_t *)buf, len, "ddff", map->gid,
    154169                       map->sid_name_use, map->nt_name, map->comment);
    155170
     
    173188        char *key;
    174189        int ret = 0;
     190        NTSTATUS status;
     191        fstring nt_name;
     192        fstring comment;
    175193
    176194        /* the key is the SID, retrieving is direct */
     
    181199        }
    182200
    183         dbuf = dbwrap_fetch_bystring(db, key, key);
    184         if (dbuf.dptr == NULL) {
     201        status = dbwrap_fetch_bystring(db, key, key, &dbuf);
     202        if (!NT_STATUS_IS_OK(status)) {
    185203                TALLOC_FREE(key);
    186204                return false;
     
    189207        ret = tdb_unpack(dbuf.dptr, dbuf.dsize, "ddff",
    190208                        &map->gid, &map->sid_name_use,
    191                         &map->nt_name, &map->comment);
     209                        &nt_name, &comment);
    192210
    193211        TALLOC_FREE(key);
     
    200218        sid_copy(&map->sid, &sid);
    201219
     220        map->nt_name = talloc_strdup(map, nt_name);
     221        if (!map->nt_name) {
     222                return false;
     223        }
     224        map->comment = talloc_strdup(map, comment);
     225        if (!map->comment) {
     226                return false;
     227        }
     228
    202229        return true;
    203230}
     
    205232static bool dbrec2map(const struct db_record *rec, GROUP_MAP *map)
    206233{
    207         if ((rec->key.dsize < strlen(GROUP_PREFIX))
    208             || (strncmp((char *)rec->key.dptr, GROUP_PREFIX,
     234        TDB_DATA key = dbwrap_record_get_key(rec);
     235        TDB_DATA value = dbwrap_record_get_value(rec);
     236        int ret = 0;
     237        fstring nt_name;
     238        fstring comment;
     239
     240        if ((key.dsize < strlen(GROUP_PREFIX))
     241            || (strncmp((char *)key.dptr, GROUP_PREFIX,
    209242                        GROUP_PREFIX_LEN) != 0)) {
    210243                return False;
    211244        }
    212245
    213         if (!string_to_sid(&map->sid, (const char *)rec->key.dptr
     246        if (!string_to_sid(&map->sid, (const char *)key.dptr
    214247                           + GROUP_PREFIX_LEN)) {
    215248                return False;
    216249        }
    217250
    218         return tdb_unpack(rec->value.dptr, rec->value.dsize, "ddff",
    219                           &map->gid, &map->sid_name_use, &map->nt_name,
    220                           &map->comment) != -1;
     251        ret = tdb_unpack(value.dptr, value.dsize, "ddff",
     252                          &map->gid, &map->sid_name_use,
     253                          &nt_name, &comment);
     254
     255        if (ret == -1) {
     256                DEBUG(3, ("dbrec2map: tdb_unpack failure\n"));
     257                return false;
     258        }
     259
     260        map->nt_name = talloc_strdup(map, nt_name);
     261        if (!map->nt_name) {
     262                return false;
     263        }
     264        map->comment = talloc_strdup(map, comment);
     265        if (!map->comment) {
     266                return false;
     267        }
     268
     269        return true;
    221270}
    222271
     
    266315        state.map = map;
    267316
    268         db->traverse_read(db, find_map, (void *)&state);
     317        dbwrap_traverse_read(db, find_map, (void *)&state, NULL);
    269318
    270319        return state.found;
     
    283332        state.map = map;
    284333
    285         db->traverse_read(db, find_map, (void *)&state);
     334        dbwrap_traverse_read(db, find_map, (void *)&state, NULL);
    286335
    287336        return state.found;
     
    318367
    319368        size_t num_maps;
    320         GROUP_MAP *maps;
     369        GROUP_MAP **maps;
    321370};
    322371
     
    324373{
    325374        struct enum_map_state *state = (struct enum_map_state *)private_data;
    326         GROUP_MAP map;
    327         GROUP_MAP *tmp;
    328 
    329         if (!dbrec2map(rec, &map)) {
     375        GROUP_MAP *map;
     376        GROUP_MAP **tmp;
     377
     378        map = talloc_zero(NULL, GROUP_MAP);
     379        if (!map) {
     380                DEBUG(0, ("Unable to allocate group map!\n"));
     381                return 1;
     382        }
     383
     384        if (!dbrec2map(rec, map)) {
     385                TALLOC_FREE(map);
    330386                return 0;
    331387        }
    332388        /* list only the type or everything if UNKNOWN */
    333389        if (state->sid_name_use != SID_NAME_UNKNOWN
    334             && state->sid_name_use != map.sid_name_use) {
     390            && state->sid_name_use != map->sid_name_use) {
    335391                DEBUG(11,("enum_group_mapping: group %s is not of the "
    336                           "requested type\n", map.nt_name));
     392                          "requested type\n", map->nt_name));
     393                TALLOC_FREE(map);
    337394                return 0;
    338395        }
    339396
    340         if ((state->unix_only == ENUM_ONLY_MAPPED) && (map.gid == -1)) {
     397        if ((state->unix_only == ENUM_ONLY_MAPPED) && (map->gid == -1)) {
    341398                DEBUG(11,("enum_group_mapping: group %s is non mapped\n",
    342                           map.nt_name));
     399                          map->nt_name));
     400                TALLOC_FREE(map);
    343401                return 0;
    344402        }
    345403
    346404        if ((state->domsid != NULL) &&
    347             (dom_sid_compare_domain(state->domsid, &map.sid) != 0)) {
     405            (dom_sid_compare_domain(state->domsid, &map->sid) != 0)) {
    348406                DEBUG(11,("enum_group_mapping: group %s is not in domain\n",
    349                           sid_string_dbg(&map.sid)));
     407                          sid_string_dbg(&map->sid)));
     408                TALLOC_FREE(map);
    350409                return 0;
    351410        }
    352411
    353         if (!(tmp = SMB_REALLOC_ARRAY(state->maps, GROUP_MAP,
    354                                       state->num_maps+1))) {
     412        tmp = talloc_realloc(NULL, state->maps, GROUP_MAP *,
     413                                        state->num_maps + 1);
     414        if (!tmp) {
    355415                DEBUG(0,("enum_group_mapping: Unable to enlarge group "
    356416                         "map!\n"));
     417                TALLOC_FREE(map);
    357418                return 1;
    358419        }
    359420
    360421        state->maps = tmp;
    361         state->maps[state->num_maps] = map;
     422        state->maps[state->num_maps] = talloc_move(state->maps, &map);
    362423        state->num_maps++;
    363424        return 0;
     
    366427static bool enum_group_mapping(const struct dom_sid *domsid,
    367428                               enum lsa_SidType sid_name_use,
    368                                GROUP_MAP **pp_rmap,
     429                               GROUP_MAP ***pp_rmap,
    369430                               size_t *p_num_entries, bool unix_only)
    370431{
    371432        struct enum_map_state state;
     433        NTSTATUS status;
    372434
    373435        state.domsid = domsid;
     
    377439        state.maps = NULL;
    378440
    379         if (db->traverse_read(db, collect_map, (void *)&state) < 0) {
     441        status = dbwrap_traverse_read(db, collect_map, (void *)&state, NULL);
     442        if (!NT_STATUS_IS_OK(status)) {
     443                TALLOC_FREE(state.maps);
    380444                return false;
    381445        }
     
    404468                 sid_to_fstring(tmp, member));
    405469
    406         dbuf = dbwrap_fetch_bystring(db, frame, key);
    407         if (dbuf.dptr == NULL) {
     470        status = dbwrap_fetch_bystring(db, frame, key, &dbuf);
     471        if (!NT_STATUS_IS_OK(status)) {
    408472                TALLOC_FREE(frame);
    409473                return NT_STATUS_OK;
     
    472536static NTSTATUS add_aliasmem(const struct dom_sid *alias, const struct dom_sid *member)
    473537{
    474         GROUP_MAP map;
     538        GROUP_MAP *map;
    475539        char *key;
    476540        fstring string_sid;
     
    478542        struct db_record *rec;
    479543        NTSTATUS status;
    480 
    481         if (!get_group_map_from_sid(*alias, &map))
     544        TDB_DATA value;
     545
     546        map = talloc_zero(talloc_tos(), GROUP_MAP);
     547        if (!map) {
     548                return NT_STATUS_NO_MEMORY;
     549        }
     550
     551        if (!get_group_map_from_sid(*alias, map)) {
     552                TALLOC_FREE(map);
    482553                return NT_STATUS_NO_SUCH_ALIAS;
    483 
    484         if ( (map.sid_name_use != SID_NAME_ALIAS) &&
    485              (map.sid_name_use != SID_NAME_WKN_GRP) )
     554        }
     555
     556        if ((map->sid_name_use != SID_NAME_ALIAS) &&
     557            (map->sid_name_use != SID_NAME_WKN_GRP)) {
     558                TALLOC_FREE(map);
    486559                return NT_STATUS_NO_SUCH_ALIAS;
     560        }
     561
     562        TALLOC_FREE(map);
    487563
    488564        if (is_aliasmem(alias, member))
     
    497573        }
    498574
    499         if (db->transaction_start(db) != 0) {
     575        if (dbwrap_transaction_start(db) != 0) {
    500576                DEBUG(0, ("transaction_start failed\n"));
    501577                return NT_STATUS_INTERNAL_DB_CORRUPTION;
    502578        }
    503579
    504         rec = db->fetch_locked(db, key, string_term_tdb_data(key));
     580        rec = dbwrap_fetch_locked(db, key, string_term_tdb_data(key));
    505581
    506582        if (rec == NULL) {
     
    511587        }
    512588
     589        value = dbwrap_record_get_value(rec);
     590
    513591        sid_to_fstring(string_sid, alias);
    514592
    515         if (rec->value.dptr != NULL) {
     593        if (value.dptr != NULL) {
    516594                new_memberstring = talloc_asprintf(
    517                         key, "%s %s", (char *)(rec->value.dptr), string_sid);
     595                        key, "%s %s", (char *)(value.dptr), string_sid);
    518596        } else {
    519597                new_memberstring = talloc_strdup(key, string_sid);
     
    526604        }
    527605
    528         status = rec->store(rec, string_term_tdb_data(new_memberstring), 0);
     606        status = dbwrap_record_store(rec, string_term_tdb_data(new_memberstring), 0);
    529607
    530608        TALLOC_FREE(key);
     
    535613        }
    536614
    537         if (db->transaction_commit(db) != 0) {
     615        if (dbwrap_transaction_commit(db) != 0) {
    538616                DEBUG(0, ("transaction_commit failed\n"));
    539617                status = NT_STATUS_INTERNAL_DB_CORRUPTION;
     
    544622
    545623 cancel:
    546         if (db->transaction_cancel(db) != 0) {
     624        if (dbwrap_transaction_cancel(db) != 0) {
    547625                smb_panic("transaction_cancel failed");
    548626        }
     
    564642        char *alias_string;
    565643        TALLOC_CTX *frame;
    566 
    567         if (strncmp((const char *)rec->key.dptr, MEMBEROF_PREFIX,
     644        TDB_DATA key = dbwrap_record_get_key(rec);
     645        TDB_DATA value = dbwrap_record_get_value(rec);
     646
     647        if (strncmp((const char *)key.dptr, MEMBEROF_PREFIX,
    568648                    MEMBEROF_PREFIX_LEN) != 0)
    569649                return 0;
    570650
    571         p = (const char *)rec->value.dptr;
     651        p = (const char *)value.dptr;
    572652
    573653        frame = talloc_stackframe();
     
    588668                 * member. Add that. */
    589669
    590                 member_string = strchr((const char *)rec->key.dptr, '/');
     670                member_string = strchr((const char *)key.dptr, '/');
    591671
    592672                /* Above we tested for MEMBEROF_PREFIX which includes the
     
    617697                              struct dom_sid **sids, size_t *num)
    618698{
    619         GROUP_MAP map;
     699        GROUP_MAP *map;
    620700        struct aliasmem_state state;
    621701
    622         if (!get_group_map_from_sid(*alias, &map))
     702        map = talloc_zero(talloc_tos(), GROUP_MAP);
     703        if (!map) {
     704                return NT_STATUS_NO_MEMORY;
     705        }
     706
     707        if (!get_group_map_from_sid(*alias, map)) {
     708                TALLOC_FREE(map);
    623709                return NT_STATUS_NO_SUCH_ALIAS;
    624 
    625         if ( (map.sid_name_use != SID_NAME_ALIAS) &&
    626              (map.sid_name_use != SID_NAME_WKN_GRP) )
     710        }
     711
     712        if ((map->sid_name_use != SID_NAME_ALIAS) &&
     713            (map->sid_name_use != SID_NAME_WKN_GRP)) {
     714                TALLOC_FREE(map);
    627715                return NT_STATUS_NO_SUCH_ALIAS;
     716        }
     717
     718        TALLOC_FREE(map);
    628719
    629720        *sids = NULL;
     
    635726        state.mem_ctx = mem_ctx;
    636727
    637         db->traverse_read(db, collect_aliasmem, &state);
     728        dbwrap_traverse_read(db, collect_aliasmem, &state, NULL);
    638729        return NT_STATUS_OK;
    639730}
     
    649740        fstring sid_string;
    650741
    651         if (db->transaction_start(db) != 0) {
     742        if (dbwrap_transaction_start(db) != 0) {
    652743                DEBUG(0, ("transaction_start failed\n"));
    653744                return NT_STATUS_INTERNAL_DB_CORRUPTION;
     
    724815        }
    725816
    726         if (db->transaction_commit(db) != 0) {
     817        if (dbwrap_transaction_commit(db) != 0) {
    727818                DEBUG(0, ("transaction_commit failed\n"));
    728819                status = NT_STATUS_INTERNAL_DB_CORRUPTION;
     
    733824
    734825 cancel:
    735         if (db->transaction_cancel(db) != 0) {
     826        if (dbwrap_transaction_cancel(db) != 0) {
    736827                smb_panic("transaction_cancel failed");
    737828        }
     
    762853{
    763854        TALLOC_CTX *tmp_ctx = talloc_tos();
    764         GROUP_MAP map;
     855        GROUP_MAP *map = NULL;
    765856        uint8_t *p;
    766857        uint32_t format;
     
    827918        }
    828919
    829         ZERO_STRUCT(map);
     920        map = talloc_zero(NULL, GROUP_MAP);
     921        if (!map) {
     922                errno = ENOMEM;
     923                goto failed;
     924        }
    830925
    831926        for (i = 0; i < num_el; i++) {
     
    850945
    851946                num_vals = pull_uint32(p, 0);
    852                 if (StrCaseCmp(name, "member") == 0) {
     947                if (strcasecmp_m(name, "member") == 0) {
    853948                        num_mem = num_vals;
    854949                        members = talloc_array(tmp_ctx, struct dom_sid, num_mem);
     
    883978                        /* we ignore unknown or uninteresting attributes
    884979                         * (objectclass, etc.) */
    885                         if (StrCaseCmp(name, "gidNumber") == 0) {
    886                                 map.gid = strtoul(val, &q, 10);
     980                        if (strcasecmp_m(name, "gidNumber") == 0) {
     981                                map->gid = strtoul(val, &q, 10);
    887982                                if (*q) {
    888983                                        errno = EIO;
    889984                                        goto failed;
    890985                                }
    891                         } else if (StrCaseCmp(name, "sid") == 0) {
    892                                 if (!string_to_sid(&map.sid, val)) {
     986                        } else if (strcasecmp_m(name, "sid") == 0) {
     987                                if (!string_to_sid(&map->sid, val)) {
    893988                                        errno = EIO;
    894989                                        goto failed;
    895990                                }
    896                         } else if (StrCaseCmp(name, "sidNameUse") == 0) {
    897                                 map.sid_name_use = strtoul(val, &q, 10);
     991                        } else if (strcasecmp_m(name, "sidNameUse") == 0) {
     992                                map->sid_name_use = strtoul(val, &q, 10);
    898993                                if (*q) {
    899994                                        errno = EIO;
    900995                                        goto failed;
    901996                                }
    902                         } else if (StrCaseCmp(name, "ntname") == 0) {
    903                                 strlcpy(map.nt_name, val,
    904                                         sizeof(map.nt_name));
    905                         } else if (StrCaseCmp(name, "comment") == 0) {
    906                                 strlcpy(map.comment, val,
    907                                         sizeof(map.comment));
    908                         } else if (StrCaseCmp(name, "member") == 0) {
     997                        } else if (strcasecmp_m(name, "ntname") == 0) {
     998                                map->nt_name = talloc_strdup(map, val);
     999                                if (!map->nt_name) {
     1000                                        errno = ENOMEM;
     1001                                        goto failed;
     1002                                }
     1003                        } else if (strcasecmp_m(name, "comment") == 0) {
     1004                                map->comment = talloc_strdup(map, val);
     1005                                if (!map->comment) {
     1006                                        errno = ENOMEM;
     1007                                        goto failed;
     1008                                }
     1009                        } else if (strcasecmp_m(name, "member") == 0) {
    9091010                                if (!string_to_sid(&members[j], val)) {
    9101011                                        errno = EIO;
     
    9191020        }
    9201021
    921         if (!add_mapping_entry(&map, 0)) {
     1022        if (map->nt_name == NULL) {
     1023                errno = EIO;
     1024                goto failed;
     1025        }
     1026
     1027        if (map->comment == NULL) {
     1028                map->comment = talloc_strdup(map, "");
     1029        }
     1030        if (map->comment == NULL) {
     1031                errno = ENOMEM;
     1032                goto failed;
     1033        }
     1034
     1035        if (!add_mapping_entry(map, 0)) {
    9221036                errno = EIO;
    9231037                goto failed;
     
    9271041                for (j = 0; j < num_mem; j++) {
    9281042                        NTSTATUS status;
    929                         status = add_aliasmem(&map.sid, &members[j]);
     1043                        status = add_aliasmem(&map->sid, &members[j]);
    9301044                        if (!NT_STATUS_IS_OK(status)) {
    9311045                                errno = EIO;
     
    9401054        }
    9411055
     1056        TALLOC_FREE(map);
    9421057        return 0;
    9431058
    9441059failed:
     1060        TALLOC_FREE(map);
    9451061        return -1;
    9461062}
     
    9611077         * conversion */
    9621078        ret = tdb_traverse(ltdb, convert_ldb_record, NULL);
    963         if (ret == -1) goto failed;
     1079        if (ret < 0) goto failed;
    9641080
    9651081        if (ltdb) {
Note: See TracChangeset for help on using the changeset viewer.