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_ad.c

    r414 r745  
    1010 * Copyright (C) Gerald (Jerry) Carter 2004-2007
    1111 * Copyright (C) Luke Howard 2001-2004
    12  * Copyright (C) Michael Adam 2008
     12 * Copyright (C) Michael Adam 2008,2010
    1313 *
    1414 * This program is free software; you can redistribute it and/or modify
     
    2828#include "includes.h"
    2929#include "winbindd.h"
     30#include "../libds/common/flags.h"
     31#include "ads.h"
     32#include "libads/ldap_schema.h"
     33#include "nss_info.h"
     34#include "secrets.h"
     35#include "idmap.h"
     36#include "../libcli/ldap/ldap_ndr.h"
     37#include "../libcli/security/security.h"
    3038
    3139#undef DBGC_CLASS
     
    4452
    4553struct idmap_ad_context {
    46         uint32_t filter_low_id;
    47         uint32_t filter_high_id;
    4854        ADS_STRUCT *ads;
    4955        struct posix_schema *ad_schema;
     
    95101                        ads_kdestroy(WINBIND_CCACHE_NAME);
    96102                        ctx->ads = NULL;
    97                         TALLOC_FREE( ctx->ad_schema );
    98103                }
    99104        }
     
    138143
    139144        get_dc_name(dom->name, realm, dc_name, &dc_ip );
    140        
     145
    141146        status = ads_connect(ads);
    142147        if (!ADS_ERR_OK(status)) {
    143                 DEBUG(1, ("ad_idmap_init: failed to connect to AD\n"));
     148                DEBUG(1, ("ad_idmap_cached_connection_internal: failed to "
     149                          "connect to AD\n"));
    144150                ads_destroy(&ads);
    145151                return status;
     
    181187             (ctx->ad_map_type ==  WB_POSIX_MAP_RFC2307) )
    182188        {
    183                 status = ads_check_posix_schema_mapping(NULL, ctx->ads, ctx->ad_map_type, &ctx->ad_schema);
     189                status = ads_check_posix_schema_mapping(
     190                        ctx, ctx->ads, ctx->ad_map_type, &ctx->ad_schema);
    184191                if ( !ADS_ERR_OK(status) ) {
    185192                        DEBUG(2,("ad_idmap_cached_connection: Failed to obtain schema details!\n"));
    186193                }
    187194        }
    188        
     195
    189196        return status;
     197}
     198
     199static int idmap_ad_context_destructor(struct idmap_ad_context *ctx)
     200{
     201        if (ctx->ads != NULL) {
     202                /* we own this ADS_STRUCT so make sure it goes away */
     203                ctx->ads->is_mine = True;
     204                ads_destroy( &ctx->ads );
     205                ctx->ads = NULL;
     206        }
     207        return 0;
    190208}
    191209
     
    193211 ***********************************************************************/
    194212
    195 static NTSTATUS idmap_ad_initialize(struct idmap_domain *dom,
    196                                     const char *params)
     213static NTSTATUS idmap_ad_initialize(struct idmap_domain *dom)
    197214{
    198215        struct idmap_ad_context *ctx;
    199216        char *config_option;
    200         const char *range = NULL;
    201217        const char *schema_mode = NULL;
    202218
    203         if ( (ctx = TALLOC_ZERO_P(dom, struct idmap_ad_context)) == NULL ) {
     219        ctx = TALLOC_ZERO_P(dom, struct idmap_ad_context);
     220        if (ctx == NULL) {
    204221                DEBUG(0, ("Out of memory!\n"));
    205222                return NT_STATUS_NO_MEMORY;
    206223        }
    207 
    208         if ( (config_option = talloc_asprintf(ctx, "idmap config %s", dom->name)) == NULL ) {
     224        talloc_set_destructor(ctx, idmap_ad_context_destructor);
     225
     226        config_option = talloc_asprintf(ctx, "idmap config %s", dom->name);
     227        if (config_option == NULL) {
    209228                DEBUG(0, ("Out of memory!\n"));
    210229                talloc_free(ctx);
    211230                return NT_STATUS_NO_MEMORY;
    212         }
    213 
    214         /* load ranges */
    215         range = lp_parm_const_string(-1, config_option, "range", NULL);
    216         if (range && range[0]) {
    217                 if ((sscanf(range, "%u - %u", &ctx->filter_low_id, &ctx->filter_high_id) != 2) ||
    218                     (ctx->filter_low_id > ctx->filter_high_id)) {
    219                         DEBUG(1, ("ERROR: invalid filter range [%s]", range));
    220                         ctx->filter_low_id = 0;
    221                         ctx->filter_high_id = 0;
    222                 }
    223231        }
    224232
     
    268276 ***********************************************************************/
    269277
    270 static struct id_map *find_map_by_sid(struct id_map **maps, DOM_SID *sid)
     278static struct id_map *find_map_by_sid(struct id_map **maps, struct dom_sid *sid)
    271279{
    272280        int i;
    273281
    274282        for (i = 0; maps[i] && i<IDMAP_AD_MAX_IDS; i++) {
    275                 if (sid_equal(maps[i]->sid, sid)) {
     283                if (dom_sid_equal(maps[i]->sid, sid)) {
    276284                        return maps[i];
    277285                }
     
    309317                ids[i]->status = ID_UNKNOWN;
    310318        }
    311        
     319
    312320        /* Only do query if we are online */
    313321        if (idmap_is_offline()) {
     
    352360                        CHECK_ALLOC_DONE(u_filter);
    353361                        break;
    354                                
     362
    355363                case ID_TYPE_GID:
    356364                        if ( ! g_filter) {
     
    401409        entry = res;
    402410        for (i = 0; (i < count) && entry; i++) {
    403                 DOM_SID sid;
     411                struct dom_sid sid;
    404412                enum id_type type;
    405413                struct id_map *map;
     
    454462                }
    455463
    456                 if ((id == 0) ||
    457                     (ctx->filter_low_id && (id < ctx->filter_low_id)) ||
    458                     (ctx->filter_high_id && (id > ctx->filter_high_id))) {
     464                if (!idmap_unix_id_is_in_range(id, dom)) {
    459465                        DEBUG(5, ("Requested id (%u) out of range (%u - %u). Filtered!\n",
    460                                 id, ctx->filter_low_id, ctx->filter_high_id));
     466                                id, dom->low_id, dom->high_id));
    461467                        continue;
    462468                }
     
    563569                                 ATYPE_NORMAL_ACCOUNT, ATYPE_WORKSTATION_TRUST, ATYPE_INTERDOMAIN_TRUST,
    564570                                 ATYPE_SECURITY_GLOBAL_GROUP, ATYPE_SECURITY_LOCAL_GROUP);
    565                
     571
    566572        CHECK_ALLOC_DONE(filter);
    567573
     
    571577                ids[idx]->status = ID_UNKNOWN;
    572578
    573                 sidstr = sid_binstring(talloc_tos(), ids[idx]->sid);
     579                sidstr = ldap_encode_ndr_dom_sid(talloc_tos(), ids[idx]->sid);
    574580                filter = talloc_asprintf_append_buffer(filter, "(objectSid=%s)", sidstr);
    575                        
     581
    576582                TALLOC_FREE(sidstr);
    577583                CHECK_ALLOC_DONE(filter);
     
    594600        entry = res;   
    595601        for (i = 0; (i < count) && entry; i++) {
    596                 DOM_SID sid;
     602                struct dom_sid sid;
    597603                enum id_type type;
    598604                struct id_map *map;
     
    652658                        continue;
    653659                }
    654                 if ((id == 0) ||
    655                     (ctx->filter_low_id && (id < ctx->filter_low_id)) ||
    656                     (ctx->filter_high_id && (id > ctx->filter_high_id))) {
     660                if (!idmap_unix_id_is_in_range(id, dom)) {
    657661                        DEBUG(5, ("Requested id (%u) out of range (%u - %u). Filtered!\n",
    658                                 id, ctx->filter_low_id, ctx->filter_high_id));
     662                                id, dom->low_id, dom->high_id));
    659663                        continue;
    660664                }
     
    680684        ret = NT_STATUS_OK;
    681685
    682         /* mark all unknwoni/expired ones as unmapped */
     686        /* mark all unknown/expired ones as unmapped */
    683687        for (i = 0; ids[i]; i++) {
    684688                if (ids[i]->status != ID_MAPPED)
     
    689693        talloc_free(memctx);
    690694        return ret;
    691 }
    692 
    693 /************************************************************************
    694  ***********************************************************************/
    695 
    696 static NTSTATUS idmap_ad_close(struct idmap_domain *dom)
    697 {
    698         struct idmap_ad_context * ctx;
    699 
    700         ctx = talloc_get_type(dom->private_data, struct idmap_ad_context);
    701 
    702         if (ctx->ads != NULL) {
    703                 /* we own this ADS_STRUCT so make sure it goes away */
    704                 ctx->ads->is_mine = True;
    705                 ads_destroy( &ctx->ads );
    706                 ctx->ads = NULL;
    707         }
    708 
    709         TALLOC_FREE( ctx->ad_schema );
    710        
    711         return NT_STATUS_OK;
    712695}
    713696
     
    819802
    820803static NTSTATUS nss_ad_get_info( struct nss_domain_entry *e,
    821                                   const DOM_SID *sid,
     804                                  const struct dom_sid *sid,
    822805                                  TALLOC_CTX *mem_ctx,
    823                                   ADS_STRUCT *ads,
    824                                   LDAPMessage *msg,
    825806                                  const char **homedir,
    826807                                  const char **shell,
     
    866847        }
    867848
    868         /* See if we can use the ADS connection struct swe were given */
    869 
    870         if (ads) {
    871                 DEBUG(10, ("nss_ad_get_info: using given ads connection and "
    872                            "LDAP message (%p)\n", msg));
    873 
    874                 *homedir = ads_pull_string( ads, mem_ctx, msg, ctx->ad_schema->posix_homedir_attr );
    875                 *shell   = ads_pull_string( ads, mem_ctx, msg, ctx->ad_schema->posix_shell_attr );
    876                 *gecos   = ads_pull_string( ads, mem_ctx, msg, ctx->ad_schema->posix_gecos_attr );
    877 
    878                 if (gid) {
    879                         if ( !ads_pull_uint32(ads, msg, ctx->ad_schema->posix_gidnumber_attr, gid ) )
    880                                 *gid = (uint32)-1;
    881                 }
    882 
    883                 nt_status = NT_STATUS_OK;
    884                 goto done;
    885         }
    886 
    887849        /* Have to do our own query */
    888850
     
    895857        attrs[3] = ctx->ad_schema->posix_gidnumber_attr;
    896858
    897         sidstr = sid_binstring(mem_ctx, sid);
     859        sidstr = ldap_encode_ndr_dom_sid(mem_ctx, sid);
    898860        filter = talloc_asprintf(mem_ctx, "(objectSid=%s)", sidstr);
    899861        TALLOC_FREE(sidstr);
     
    10951057}
    10961058
    1097 
    1098 /************************************************************************
    1099  ***********************************************************************/
    1100 
    1101 static NTSTATUS nss_ad_close( void )
    1102 {
    1103         /* nothing to do.  All memory is free()'d by the idmap close_fn() */
    1104 
    1105         return NT_STATUS_OK;
    1106 }
    1107 
    11081059/************************************************************************
    11091060 Function dispatch tables for the idmap and nss plugins
     
    11141065        .unixids_to_sids = idmap_ad_unixids_to_sids,
    11151066        .sids_to_unixids = idmap_ad_sids_to_unixids,
    1116         .close_fn        = idmap_ad_close
    11171067};
    11181068
    11191069/* The SFU and RFC2307 NSS plugins share everything but the init
    11201070   function which sets the intended schema model to use */
    1121  
     1071
    11221072static struct nss_info_methods nss_rfc2307_methods = {
    11231073        .init           = nss_rfc2307_init,
     
    11251075        .map_to_alias   = nss_ad_map_to_alias,
    11261076        .map_from_alias = nss_ad_map_from_alias,
    1127         .close_fn       = nss_ad_close
    11281077};
    11291078
     
    11331082        .map_to_alias   = nss_ad_map_to_alias,
    11341083        .map_from_alias = nss_ad_map_from_alias,
    1135         .close_fn       = nss_ad_close
    11361084};
    11371085
     
    11411089        .map_to_alias   = nss_ad_map_to_alias,
    11421090        .map_from_alias = nss_ad_map_from_alias,
    1143         .close_fn       = nss_ad_close
    11441091};
    11451092
     
    11661113                        return status_idmap_ad;         
    11671114        }
    1168        
     1115
    11691116        if ( !NT_STATUS_IS_OK( status_nss_rfc2307 ) ) {
    11701117                status_nss_rfc2307 = smb_register_idmap_nss(SMB_NSS_INFO_INTERFACE_VERSION,
Note: See TracChangeset for help on using the changeset viewer.