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/source4/winbind
Files:
1 added
38 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source4/winbind/idmap.c

    r740 r988  
    55
    66   Copyright (C) Kai Blin 2008
     7   Copyright (C) Andrew Bartlett 2012
    78
    89   This program is free software; you can redistribute it and/or modify
     
    2930#include "libcli/security/security.h"
    3031#include "libcli/ldap/ldap_ndr.h"
     32#include "dsdb/samdb/samdb.h"
     33#include "../libds/common/flags.h"
    3134
    3235/**
     
    165168
    166169        idmap_ctx->ldb_ctx = ldb_wrap_connect(mem_ctx, ev_ctx, lp_ctx,
    167                                               lpcfg_idmap_url(lp_ctx),
     170                                              "idmap.ldb",
    168171                                              system_session(lp_ctx),
    169172                                              NULL, 0);
     
    179182        idmap_ctx->unix_users_sid = dom_sid_parse_talloc(mem_ctx, "S-1-22-1");
    180183        if (idmap_ctx->unix_users_sid == NULL) {
     184                return NULL;
     185        }
     186       
     187        idmap_ctx->samdb = samdb_connect(idmap_ctx, ev_ctx, lp_ctx, system_session(lp_ctx), 0);
     188        if (idmap_ctx->samdb == NULL) {
     189                DEBUG(0, ("Failed to load sam.ldb in idmap_init\n"));
    181190                return NULL;
    182191        }
     
    200209static NTSTATUS idmap_xid_to_sid(struct idmap_context *idmap_ctx,
    201210                                 TALLOC_CTX *mem_ctx,
    202                                  const struct unixid *unixid,
     211                                 struct unixid *unixid,
    203212                                 struct dom_sid **sid)
    204213{
     
    207216        struct ldb_context *ldb = idmap_ctx->ldb_ctx;
    208217        struct ldb_result *res = NULL;
     218        struct ldb_message *msg;
    209219        struct dom_sid *unix_sid, *new_sid;
    210220        TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
    211221        const char *id_type;
    212222
     223        const char *sam_attrs[] = {"objectSid", NULL};
     224       
     225        /*
     226         * First check against our local DB, to see if this user has a
     227         * mapping there.  This means that the Samba4 AD DC behaves
     228         * much like a winbindd member server running idmap_ad
     229         */
     230       
    213231        switch (unixid->type) {
    214232                case ID_TYPE_UID:
     233                        if (lpcfg_parm_bool(idmap_ctx->lp_ctx, NULL, "idmap_ldb", "use rfc2307", false)) {
     234                                ret = dsdb_search_one(idmap_ctx->samdb, tmp_ctx, &msg,
     235                                                      ldb_get_default_basedn(idmap_ctx->samdb),
     236                                                      LDB_SCOPE_SUBTREE,
     237                                                      sam_attrs, 0,
     238                                                      "(&(|(sAMaccountType=%u)(sAMaccountType=%u)(sAMaccountType=%u))"
     239                                                      "(uidNumber=%u)(objectSid=*))",
     240                                                      ATYPE_ACCOUNT, ATYPE_WORKSTATION_TRUST, ATYPE_INTERDOMAIN_TRUST, unixid->id);
     241                        } else {
     242                                /* If we are not to use the rfc2307 attributes, we just emulate a non-match */
     243                                ret = LDB_ERR_NO_SUCH_OBJECT;
     244                        }
     245
     246                        if (ret == LDB_ERR_CONSTRAINT_VIOLATION) {
     247                                DEBUG(1, ("Search for uidNumber=%lu gave duplicate results, failing to map to a SID!\n",
     248                                          (unsigned long)unixid->id));
     249                                status = NT_STATUS_NONE_MAPPED;
     250                                goto failed;
     251                        } else if (ret == LDB_SUCCESS) {
     252                                *sid = samdb_result_dom_sid(mem_ctx, msg, "objectSid");
     253                                if (*sid == NULL) {
     254                                        DEBUG(1, ("Search for uidNumber=%lu did not return an objectSid!\n",
     255                                                  (unsigned long)unixid->id));
     256                                        status = NT_STATUS_NONE_MAPPED;
     257                                        goto failed;
     258                                }
     259                                talloc_free(tmp_ctx);
     260                                return NT_STATUS_OK;
     261                        } else if (ret != LDB_ERR_NO_SUCH_OBJECT) {
     262                                DEBUG(1, ("Search for uidNumber=%lu gave '%s', failing to map to a SID!\n",
     263                                          (unsigned long)unixid->id, ldb_errstring(idmap_ctx->samdb)));
     264                                status = NT_STATUS_NONE_MAPPED;
     265                                goto failed;
     266                        }
     267
    215268                        id_type = "ID_TYPE_UID";
    216269                        break;
    217270                case ID_TYPE_GID:
     271                        if (lpcfg_parm_bool(idmap_ctx->lp_ctx, NULL, "idmap_ldb", "use rfc2307", false)) {
     272                                ret = dsdb_search_one(idmap_ctx->samdb, tmp_ctx, &msg,
     273                                                      ldb_get_default_basedn(idmap_ctx->samdb),
     274                                                      LDB_SCOPE_SUBTREE,
     275                                                      sam_attrs, 0,
     276                                                      "(&(|(sAMaccountType=%u)(sAMaccountType=%u))(gidNumber=%u))",
     277                                                      ATYPE_SECURITY_GLOBAL_GROUP, ATYPE_SECURITY_LOCAL_GROUP,
     278                                                      unixid->id);
     279                        } else {
     280                                /* If we are not to use the rfc2307 attributes, we just emulate a non-match */
     281                                ret = LDB_ERR_NO_SUCH_OBJECT;
     282                        }
     283                        if (ret == LDB_ERR_CONSTRAINT_VIOLATION) {
     284                                DEBUG(1, ("Search for gidNumber=%lu gave duplicate results, failing to map to a SID!\n",
     285                                          (unsigned long)unixid->id));
     286                                status = NT_STATUS_NONE_MAPPED;
     287                                goto failed;
     288                        } else if (ret == LDB_SUCCESS) {
     289                                *sid = samdb_result_dom_sid(mem_ctx, msg, "objectSid");
     290                                if (*sid == NULL) {
     291                                        DEBUG(1, ("Search for gidNumber=%lu did not return an objectSid!\n",
     292                                                  (unsigned long)unixid->id));
     293                                        status = NT_STATUS_NONE_MAPPED;
     294                                        goto failed;
     295                                }
     296                                talloc_free(tmp_ctx);
     297                                return NT_STATUS_OK;
     298                        } else if (ret != LDB_ERR_NO_SUCH_OBJECT) {
     299                                DEBUG(1, ("Search for gidNumber=%lu gave '%s', failing to map to a SID!\n",
     300                                          (unsigned long)unixid->id, ldb_errstring(idmap_ctx->samdb)));
     301                                status = NT_STATUS_NONE_MAPPED;
     302                                goto failed;
     303                        }
     304
    218305                        id_type = "ID_TYPE_GID";
    219306                        break;
     
    235322
    236323        if (res->count == 1) {
     324                const char *type = ldb_msg_find_attr_as_string(res->msgs[0],
     325                                                               "type", NULL);
     326
    237327                *sid = idmap_msg_get_dom_sid(mem_ctx, res->msgs[0],
    238328                                             "objectSid");
     
    242332                        goto failed;
    243333                }
     334
     335                if (type == NULL) {
     336                        DEBUG(1, ("Invalid type for mapping entry.\n"));
     337                        talloc_free(tmp_ctx);
     338                        return NT_STATUS_NONE_MAPPED;
     339                }
     340
     341                if (strcmp(type, "ID_TYPE_BOTH") == 0) {
     342                        unixid->type = ID_TYPE_BOTH;
     343                } else if (strcmp(type, "ID_TYPE_UID") == 0) {
     344                        unixid->type = ID_TYPE_UID;
     345                } else {
     346                        unixid->type = ID_TYPE_GID;
     347                }
     348
    244349                talloc_free(tmp_ctx);
    245350                return NT_STATUS_OK;
     
    279384 *
    280385 * If no mapping exists, a new mapping will be created.
    281  *
    282  * \todo Check if SIDs can be resolved if lpcfg_idmap_trusted_only() == true
    283  * \todo Fix backwards compatibility for Samba3
    284386 *
    285387 * \param idmap_ctx idmap context to use
     
    300402        struct ldb_context *ldb = idmap_ctx->ldb_ctx;
    301403        struct ldb_dn *dn;
    302         struct ldb_message *hwm_msg, *map_msg;
     404        struct ldb_message *hwm_msg, *map_msg, *sam_msg;
    303405        struct ldb_result *res = NULL;
    304         int trans;
     406        int trans = -1;
    305407        uint32_t low, high, hwm, new_xid;
    306408        char *sid_string, *unixid_string, *hwm_string;
    307409        bool hwm_entry_exists;
    308410        TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
     411        const char *sam_attrs[] = {"uidNumber", "gidNumber", "samAccountType", NULL};
    309412
    310413        if (dom_sid_in_domain(idmap_ctx->unix_users_sid, sid)) {
     
    338441                talloc_free(tmp_ctx);
    339442                return NT_STATUS_OK;
    340          }
     443        }
     444
     445        /*
     446         * First check against our local DB, to see if this user has a
     447         * mapping there.  This means that the Samba4 AD DC behaves
     448         * much like a winbindd member server running idmap_ad
     449         */
     450       
     451        if (lpcfg_parm_bool(idmap_ctx->lp_ctx, NULL, "idmap_ldb", "use rfc2307", false)) {
     452                ret = dsdb_search_one(idmap_ctx->samdb, tmp_ctx, &sam_msg,
     453                                      ldb_get_default_basedn(idmap_ctx->samdb),
     454                                      LDB_SCOPE_SUBTREE, sam_attrs, 0,
     455                                      "(&(objectSid=%s)"
     456                                      "(|(sAMaccountType=%u)(sAMaccountType=%u)(sAMaccountType=%u)"
     457                                      "(sAMaccountType=%u)(sAMaccountType=%u))"
     458                                      "(|(uidNumber=*)(gidNumber=*)))",
     459                                      dom_sid_string(tmp_ctx, sid),
     460                                      ATYPE_ACCOUNT, ATYPE_WORKSTATION_TRUST, ATYPE_INTERDOMAIN_TRUST,
     461                                      ATYPE_SECURITY_GLOBAL_GROUP, ATYPE_SECURITY_LOCAL_GROUP);
     462        } else {
     463                /* If we are not to use the rfc2307 attributes, we just emulate a non-match */
     464                ret = LDB_ERR_NO_SUCH_OBJECT;
     465        }
     466
     467        if (ret == LDB_ERR_CONSTRAINT_VIOLATION) {
     468                DEBUG(1, ("Search for objectSid=%s gave duplicate results, failing to map to a unix ID!\n",
     469                          dom_sid_string(tmp_ctx, sid)));
     470                status = NT_STATUS_NONE_MAPPED;
     471                goto failed;
     472        } else if (ret == LDB_SUCCESS) {
     473                uint32_t account_type = ldb_msg_find_attr_as_uint(sam_msg, "sAMaccountType", 0);
     474                if ((account_type == ATYPE_ACCOUNT) ||
     475                    (account_type == ATYPE_WORKSTATION_TRUST ) ||
     476                    (account_type == ATYPE_INTERDOMAIN_TRUST ))
     477                {
     478                        const struct ldb_val *v = ldb_msg_find_ldb_val(sam_msg, "uidNumber");
     479                        if (v) {
     480                                unixid->type = ID_TYPE_UID;
     481                                unixid->id = ldb_msg_find_attr_as_uint(sam_msg, "uidNumber", -1);
     482                                talloc_free(tmp_ctx);
     483                                return NT_STATUS_OK;
     484                        }
     485
     486                } else if ((account_type == ATYPE_SECURITY_GLOBAL_GROUP) ||
     487                           (account_type == ATYPE_SECURITY_LOCAL_GROUP))
     488                {
     489                        const struct ldb_val *v = ldb_msg_find_ldb_val(sam_msg, "gidNumber");
     490                        if (v) {
     491                                unixid->type = ID_TYPE_GID;
     492                                unixid->id = ldb_msg_find_attr_as_uint(sam_msg, "gidNumber", -1);
     493                                talloc_free(tmp_ctx);
     494                                return NT_STATUS_OK;
     495                        }
     496                }
     497        } else if (ret != LDB_ERR_NO_SUCH_OBJECT) {
     498                DEBUG(1, ("Search for objectSid=%s gave '%s', failing to map to a SID!\n",
     499                          dom_sid_string(tmp_ctx, sid), ldb_errstring(idmap_ctx->samdb)));
     500
     501                status = NT_STATUS_NONE_MAPPED;
     502                goto failed;
     503        }
    341504
    342505        ret = ldb_search(ldb, tmp_ctx, &res, NULL, LDB_SCOPE_SUBTREE,
     
    404567                goto failed;
    405568        }
    406 
    407         /*FIXME: if lpcfg_idmap_trusted_only() == true, check if SID can be
    408          * resolved here. */
    409569
    410570        ret = idmap_get_bounds(idmap_ctx, &low, &high);
  • vendor/current/source4/winbind/idmap.h

    r740 r988  
    3030        struct dom_sid *unix_groups_sid;
    3131        struct dom_sid *unix_users_sid;
     32        struct ldb_context *samdb;
    3233};
    3334
  • vendor/current/source4/winbind/wb_async_helpers.c

    r860 r988  
    3030#include "librpc/gen_ndr/ndr_samr_c.h"
    3131
     32#include "winbind/wb_helper.h"
     33
    3234
    3335struct lsa_lookupsids_state {
     
    4547
    4648struct composite_context *wb_lsa_lookupsids_send(TALLOC_CTX *mem_ctx,
    47                                                  struct dcerpc_pipe *lsa_pipe,
     49                                                 struct tevent_context *ev,
     50                                                 struct dcerpc_binding_handle *lsa_binding,
    4851                                                 struct policy_handle *handle,
    4952                                                 uint32_t num_sids,
     
    5558        struct tevent_req *subreq;
    5659
    57         result = composite_create(mem_ctx, lsa_pipe->conn->event_ctx);
     60        result = composite_create(mem_ctx, ev);
    5861        if (result == NULL) goto failed;
    5962
     
    9093        state->r.out.domains = &state->domains;
    9194
    92         subreq = dcerpc_lsa_LookupSids_r_send(state,
    93                                               result->event_ctx,
    94                                               lsa_pipe->binding_handle,
     95        subreq = dcerpc_lsa_LookupSids_r_send(state, ev,
     96                                              lsa_binding,
    9597                                              &state->r);
    9698        if (subreq == NULL) goto failed;
     
    208210
    209211struct composite_context *wb_lsa_lookupnames_send(TALLOC_CTX *mem_ctx,
    210                                                   struct dcerpc_pipe *lsa_pipe,
     212                                                  struct tevent_context *ev,
     213                                                  struct dcerpc_binding_handle *lsa_binding,
    211214                                                  struct policy_handle *handle,
    212215                                                  uint32_t num_names,
     
    220223        uint32_t i;
    221224
    222         result = composite_create(mem_ctx, lsa_pipe->conn->event_ctx);
     225        result = composite_create(mem_ctx, ev);
    223226        if (result == NULL) goto failed;
    224227
     
    253256        state->r.out.domains = &state->domains;
    254257
    255         subreq = dcerpc_lsa_LookupNames_r_send(state,
    256                                                result->event_ctx,
    257                                                lsa_pipe->binding_handle,
     258        subreq = dcerpc_lsa_LookupNames_r_send(state, ev,
     259                                               lsa_binding,
    258260                                               &state->r);
    259261        if (subreq == NULL) goto failed;
     
    344346struct samr_getuserdomgroups_state {
    345347        struct composite_context *ctx;
    346         struct dcerpc_pipe *samr_pipe;
     348        struct dcerpc_binding_handle *samr_binding;
    347349
    348350        uint32_t num_rids;
     
    362364
    363365struct composite_context *wb_samr_userdomgroups_send(TALLOC_CTX *mem_ctx,
    364                                                      struct dcerpc_pipe *samr_pipe,
     366                                                     struct tevent_context *ev,
     367                                                     struct dcerpc_binding_handle *samr_binding,
    365368                                                     struct policy_handle *domain_handle,
    366369                                                     uint32_t rid)
     
    370373        struct tevent_req *subreq;
    371374
    372         result = composite_create(mem_ctx, samr_pipe->conn->event_ctx);
     375        result = composite_create(mem_ctx, ev);
    373376        if (result == NULL) goto failed;
    374377
     
    378381        state->ctx = result;
    379382
    380         state->samr_pipe = samr_pipe;
     383        state->samr_binding = samr_binding;
    381384
    382385        state->user_handle = talloc(state, struct policy_handle);
     
    389392
    390393        subreq = dcerpc_samr_OpenUser_r_send(state,
    391                                              result->event_ctx,
    392                                              state->samr_pipe->binding_handle,
     394                                             state->ctx->event_ctx,
     395                                             state->samr_binding,
    393396                                             &state->o);
    394397        if (subreq == NULL) goto failed;
     
    419422        subreq = dcerpc_samr_GetGroupsForUser_r_send(state,
    420423                                                     state->ctx->event_ctx,
    421                                                      state->samr_pipe->binding_handle,
     424                                                     state->samr_binding,
    422425                                                     &state->g);
    423426        if (composite_nomem(subreq, state->ctx)) return;
     
    442445        subreq = dcerpc_samr_Close_r_send(state,
    443446                                          state->ctx->event_ctx,
    444                                           state->samr_pipe->binding_handle,
     447                                          state->samr_binding,
    445448                                          &state->c);
    446449        if (composite_nomem(subreq, state->ctx)) return;
  • vendor/current/source4/winbind/wb_async_helpers.h

    r414 r988  
    2323#define __WB_ASYNC_HELPERS_H__
    2424
     25struct dcerpc_pipe;
     26struct dcerpc_binding_handle;
     27
    2528#include "librpc/gen_ndr/lsa.h"
    2629
  • vendor/current/source4/winbind/wb_utils.c

    r740 r988  
    2222#include "includes.h"
    2323#include "param/param.h"
     24#include "libcli/security/dom_sid.h"
     25#include "winbind/wb_async_helpers.h"
     26#include "winbind/wb_helper.h"
    2427
    2528
  • vendor/current/source4/winbind/wscript_build

    r740 r988  
    22
    33
    4 bld.SAMBA_MODULE('service_winbind',
    5         source='wb_server.c wb_irpc.c wb_samba3_protocol.c wb_samba3_cmd.c wb_init_domain.c wb_dom_info.c wb_dom_info_trusted.c wb_sid2domain.c wb_name2domain.c wb_sids2xids.c wb_xids2sids.c wb_gid2sid.c wb_sid2uid.c wb_sid2gid.c wb_uid2sid.c wb_connect_lsa.c wb_connect_sam.c wb_cmd_lookupname.c wb_cmd_lookupsid.c wb_cmd_getdcname.c wb_cmd_getgrnam.c wb_cmd_getgrgid.c wb_cmd_getpwnam.c wb_cmd_getpwuid.c wb_cmd_userdomgroups.c wb_cmd_usersids.c wb_cmd_list_groups.c wb_cmd_list_trustdom.c wb_cmd_list_users.c wb_cmd_setpwent.c wb_cmd_getpwent.c wb_cmd_getgrent.c wb_cmd_setgrent.c wb_cmd_getgroups.c wb_pam_auth.c wb_sam_logon.c wb_update_rodc_dns.c',
    6         autoproto='wb_proto.h',
     4bld.SAMBA_MODULE('service_winbindd',
     5        source='winbindd.c',
    76        subsystem='service',
    8         init_function='server_service_winbind_init',
    9         deps='WB_HELPER IDMAP NDR_WINBIND process_model RPC_NDR_LSA dcerpc-samr PAM_ERRORS cli-ldap samba-net LIBSAMBA_TSOCKET',
     7        init_function='server_service_winbindd_init',
     8        deps='process_model UTIL_RUNCMD',
    109        internal_module=False,
    1110        )
     
    2524        )
    2625
    27 bld.SAMBA_BINARY('wbinfo',
    28         source='../../nsswitch/wbinfo.c',
    29         deps='samba-util LIBCLI_AUTH popt POPT_SAMBA winbind-client wbclient tevent UTIL_TEVENT LIBASYNC_REQ security ndr NDR_SECURITY'
    30         )
Note: See TracChangeset for help on using the changeset viewer.