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/winbindd/idmap_rid.c

    r414 r745  
    2121#include "includes.h"
    2222#include "winbindd.h"
     23#include "idmap.h"
     24#include "../libcli/security/dom_sid.h"
    2325
    2426#undef DBGC_CLASS
     
    2628
    2729struct idmap_rid_context {
    28         const char *domain_name;
    29         uint32_t low_id;
    30         uint32_t high_id;
    3130        uint32_t base_rid;
    3231};
     
    3736 *****************************************************************************/
    3837
    39 static NTSTATUS idmap_rid_initialize(struct idmap_domain *dom,
    40                                      const char *params)
     38static NTSTATUS idmap_rid_initialize(struct idmap_domain *dom)
    4139{
    4240        NTSTATUS ret;
    4341        struct idmap_rid_context *ctx;
    4442        char *config_option = NULL;
    45         const char *range;
    46         uid_t low_uid = 0;
    47         uid_t high_uid = 0;
    48         gid_t low_gid = 0;
    49         gid_t high_gid = 0;
    5043
    51         if ( (ctx = TALLOC_ZERO_P(dom, struct idmap_rid_context)) == NULL ) {
     44        ctx = TALLOC_ZERO_P(dom, struct idmap_rid_context);
     45        if (ctx == NULL) {
    5246                DEBUG(0, ("Out of memory!\n"));
    5347                return NT_STATUS_NO_MEMORY;
     
    6155        }
    6256
    63         range = lp_parm_const_string(-1, config_option, "range", NULL);
    64         if ( !range ||
    65             (sscanf(range, "%u - %u", &ctx->low_id, &ctx->high_id) != 2) ||
    66             (ctx->low_id > ctx->high_id))
    67         {
    68                 ctx->low_id = 0;
    69                 ctx->high_id = 0;
    70         }
     57        ctx->base_rid = lp_parm_int(-1, config_option, "base_rid", 0);
    7158
    72         /* lets see if the range is defined by the old idmap uid/idmap gid */
    73         if (!ctx->low_id && !ctx->high_id) {
    74                 if (lp_idmap_uid(&low_uid, &high_uid)) {
    75                         ctx->low_id = low_uid;
    76                         ctx->high_id = high_uid;
    77                 }
    78 
    79                 if (lp_idmap_gid(&low_gid, &high_gid)) {
    80                         if ((ctx->low_id != low_gid) ||
    81                             (ctx->high_id != high_uid)) {
    82                                 DEBUG(1, ("ERROR: idmap uid range must match idmap gid range\n"));
    83                                 ret = NT_STATUS_UNSUCCESSFUL;
    84                                 goto failed;
    85                         }
    86                 }
    87         }
    88 
    89         if (!ctx->low_id || !ctx->high_id) {
    90                 DEBUG(1, ("ERROR: Invalid configuration, ID range missing or invalid\n"));
    91                 ret = NT_STATUS_UNSUCCESSFUL;
    92                 goto failed;
    93         }
    94 
    95         ctx->base_rid = lp_parm_int(-1, config_option, "base_rid", 0);
    96         ctx->domain_name = talloc_strdup( ctx, dom->name );
    97        
    9859        dom->private_data = ctx;
    9960
     
    10667}
    10768
    108 static NTSTATUS idmap_rid_id_to_sid(TALLOC_CTX *memctx, struct idmap_rid_context *ctx, struct id_map *map)
     69static NTSTATUS idmap_rid_id_to_sid(struct idmap_domain *dom, struct id_map *map)
    10970{
    110         struct winbindd_domain *domain;
     71        struct winbindd_domain *domain;
     72        struct idmap_rid_context *ctx;
     73
     74        ctx = talloc_get_type(dom->private_data, struct idmap_rid_context);
    11175
    11276        /* apply filters before checking */
    113         if ((map->xid.id < ctx->low_id) || (map->xid.id > ctx->high_id)) {
     77        if (!idmap_unix_id_is_in_range(map->xid.id, dom)) {
    11478                DEBUG(5, ("Requested id (%u) out of range (%u - %u). Filtered!\n",
    115                                 map->xid.id, ctx->low_id, ctx->high_id));
     79                                map->xid.id, dom->low_id, dom->high_id));
    11680                return NT_STATUS_NONE_MAPPED;
    11781        }
    11882
    119         if ( (domain = find_domain_from_name_noinit(ctx->domain_name)) == NULL ) {
     83        domain = find_domain_from_name_noinit(dom->name);
     84        if (domain == NULL ) {
    12085                return NT_STATUS_NO_SUCH_DOMAIN;
    12186        }
    122        
    123         sid_compose(map->sid, &domain->sid, map->xid.id - ctx->low_id + ctx->base_rid);
     87
     88        sid_compose(map->sid, &domain->sid, map->xid.id - dom->low_id + ctx->base_rid);
    12489
    12590        /* We **really** should have some way of validating
     
    136101**********************************/
    137102
    138 static NTSTATUS idmap_rid_sid_to_id(TALLOC_CTX *memctx, struct idmap_rid_context *ctx, struct id_map *map)
     103static NTSTATUS idmap_rid_sid_to_id(struct idmap_domain *dom, struct id_map *map)
    139104{
    140105        uint32_t rid;
     106        struct idmap_rid_context *ctx;
     107
     108        ctx = talloc_get_type(dom->private_data, struct idmap_rid_context);
    141109
    142110        sid_peek_rid(map->sid, &rid);
    143         map->xid.id = rid - ctx->base_rid + ctx->low_id;
     111        map->xid.id = rid - ctx->base_rid + dom->low_id;
    144112
    145113        /* apply filters before returning result */
    146114
    147         if ((map->xid.id < ctx->low_id) || (map->xid.id > ctx->high_id)) {
     115        if (!idmap_unix_id_is_in_range(map->xid.id, dom)) {
    148116                DEBUG(5, ("Requested id (%u) out of range (%u - %u). Filtered!\n",
    149                                 map->xid.id, ctx->low_id, ctx->high_id));
     117                                map->xid.id, dom->low_id, dom->high_id));
    150118                map->status = ID_UNMAPPED;
    151119                return NT_STATUS_NONE_MAPPED;
    152120        }
    153 
    154         /* We **really** should have some way of validating
    155            the SID exists and is the correct type here.  But
    156            that is a deficiency in the idmap_rid design. */
    157121
    158122        map->status = ID_MAPPED;
     
    167131static NTSTATUS idmap_rid_unixids_to_sids(struct idmap_domain *dom, struct id_map **ids)
    168132{
    169         struct idmap_rid_context *ridctx;
    170         TALLOC_CTX *ctx;
    171133        NTSTATUS ret;
    172134        int i;
     
    176138                ids[i]->status = ID_UNKNOWN;
    177139        }
    178        
    179         ridctx = talloc_get_type(dom->private_data, struct idmap_rid_context);
    180 
    181         ctx = talloc_new(dom);
    182         if ( ! ctx) {
    183                 DEBUG(0, ("Out of memory!\n"));
    184                 return NT_STATUS_NO_MEMORY;
    185         }
    186140
    187141        for (i = 0; ids[i]; i++) {
    188142
    189                 ret = idmap_rid_id_to_sid(ctx, ridctx, ids[i]);
     143                ret = idmap_rid_id_to_sid(dom, ids[i]);
    190144
    191145                if (( ! NT_STATUS_IS_OK(ret)) &&
     
    196150        }
    197151
    198         talloc_free(ctx);
    199152        return NT_STATUS_OK;
    200153}
     
    206159static NTSTATUS idmap_rid_sids_to_unixids(struct idmap_domain *dom, struct id_map **ids)
    207160{
    208         struct idmap_rid_context *ridctx;
    209         TALLOC_CTX *ctx;
    210161        NTSTATUS ret;
    211162        int i;
     
    215166                ids[i]->status = ID_UNKNOWN;
    216167        }
    217        
    218         ridctx = talloc_get_type(dom->private_data, struct idmap_rid_context);
    219 
    220         ctx = talloc_new(dom);
    221         if ( ! ctx) {
    222                 DEBUG(0, ("Out of memory!\n"));
    223                 return NT_STATUS_NO_MEMORY;
    224         }
    225168
    226169        for (i = 0; ids[i]; i++) {
    227170
    228                 ret = idmap_rid_sid_to_id(ctx, ridctx, ids[i]);
     171                ret = idmap_rid_sid_to_id(dom, ids[i]);
    229172
    230173                if (( ! NT_STATUS_IS_OK(ret)) &&
     
    236179        }
    237180
    238         talloc_free(ctx);
    239         return NT_STATUS_OK;
    240 }
    241 
    242 static NTSTATUS idmap_rid_close(struct idmap_domain *dom)
    243 {
    244         if (dom->private_data) {
    245                 TALLOC_FREE(dom->private_data);
    246         }
    247181        return NT_STATUS_OK;
    248182}
     
    252186        .unixids_to_sids = idmap_rid_unixids_to_sids,
    253187        .sids_to_unixids = idmap_rid_sids_to_unixids,
    254         .close_fn = idmap_rid_close
    255188};
    256189
Note: See TracChangeset for help on using the changeset viewer.