Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (12 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

File:
1 edited

Legend:

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

    r414 r740  
    2222#include "includes.h"
    2323#include "auth/auth.h"
    24 #include "librpc/gen_ndr/lsa.h"
    25 #include "librpc/gen_ndr/samr.h"
    2624#include "librpc/gen_ndr/ndr_security.h"
    27 #include "lib/ldb/include/ldb.h"
    28 #include "lib/ldb/include/ldb_errors.h"
    29 #include "lib/ldb_wrap.h"
     25#include <ldb.h>
     26#include "ldb_wrap.h"
    3027#include "param/param.h"
    3128#include "winbind/idmap.h"
     
    10198        enum ndr_err_code ndr_err;
    10299
    103         ndr_err = ndr_push_struct_blob(&val, mem_ctx,
    104                                        lp_iconv_convenience(idmap_ctx->lp_ctx),
    105                                        sid,
     100        ndr_err = ndr_push_struct_blob(&val, mem_ctx, sid,
    106101                                       (ndr_push_flags_fn_t)ndr_push_dom_sid);
    107102
     
    138133        }
    139134
    140         ndr_err = ndr_pull_struct_blob(val, sid, NULL, sid,
     135        ndr_err = ndr_pull_struct_blob(val, sid, sid,
    141136                                       (ndr_pull_flags_fn_t)ndr_pull_dom_sid);
    142137        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     
    158153struct idmap_context *idmap_init(TALLOC_CTX *mem_ctx,
    159154                                 struct tevent_context *ev_ctx,
    160                 struct loadparm_context *lp_ctx)
     155                                 struct loadparm_context *lp_ctx)
    161156{
    162157        struct idmap_context *idmap_ctx;
     
    170165
    171166        idmap_ctx->ldb_ctx = ldb_wrap_connect(mem_ctx, ev_ctx, lp_ctx,
    172                                               lp_idmap_url(lp_ctx),
    173                                               system_session(mem_ctx, lp_ctx),
    174                                               NULL, 0, NULL);
     167                                              lpcfg_idmap_url(lp_ctx),
     168                                              system_session(lp_ctx),
     169                                              NULL, 0);
    175170        if (idmap_ctx->ldb_ctx == NULL) {
    176171                return NULL;
     
    203198 */
    204199
    205 NTSTATUS idmap_xid_to_sid(struct idmap_context *idmap_ctx, TALLOC_CTX *mem_ctx,
    206                 const struct unixid *unixid, struct dom_sid **sid)
     200static NTSTATUS idmap_xid_to_sid(struct idmap_context *idmap_ctx,
     201                                 TALLOC_CTX *mem_ctx,
     202                                 const struct unixid *unixid,
     203                                 struct dom_sid **sid)
    207204{
    208205        int ret;
     
    222219                        break;
    223220                default:
    224                         DEBUG(1, ("unixid->type must be type gid or uid\n"));
     221                        DEBUG(1, ("unixid->type must be type gid or uid (got %u) for lookup with id %lu\n",
     222                                  (unsigned)unixid->type, (unsigned long)unixid->id));
    225223                        status = NT_STATUS_NONE_MAPPED;
    226224                        goto failed;
     
    282280 * If no mapping exists, a new mapping will be created.
    283281 *
    284  * \todo Check if SIDs can be resolved if lp_idmap_trusted_only() == true
     282 * \todo Check if SIDs can be resolved if lpcfg_idmap_trusted_only() == true
    285283 * \todo Fix backwards compatibility for Samba3
    286284 *
     
    288286 * \param mem_ctx talloc context to use
    289287 * \param sid SID to map to an unixid struct
    290  * \param unixid pointer to a unixid struct pointer
     288 * \param unixid pointer to a unixid struct
    291289 * \return NT_STATUS_OK on success, NT_STATUS_INVALID_SID if the sid is not from
    292290 * a trusted domain and idmap trusted only = true, NT_STATUS_NONE_MAPPED if the
    293291 * mapping failed.
    294292 */
    295 NTSTATUS idmap_sid_to_xid(struct idmap_context *idmap_ctx, TALLOC_CTX *mem_ctx,
    296                 const struct dom_sid *sid, struct unixid **unixid)
     293static NTSTATUS idmap_sid_to_xid(struct idmap_context *idmap_ctx,
     294                                 TALLOC_CTX *mem_ctx,
     295                                 const struct dom_sid *sid,
     296                                 struct unixid *unixid)
    297297{
    298298        int ret;
     
    312312                DEBUG(6, ("This is a local unix uid, just calculate that.\n"));
    313313                status = dom_sid_split_rid(tmp_ctx, sid, NULL, &rid);
    314                 if (!NT_STATUS_IS_OK(status)) goto failed;
    315 
    316                 *unixid = talloc(mem_ctx, struct unixid);
    317                 if (*unixid == NULL) {
    318                         status = NT_STATUS_NO_MEMORY;
    319                         goto failed;
    320                 }
    321                 (*unixid)->id = rid;
    322                 (*unixid)->type = ID_TYPE_UID;
     314                if (!NT_STATUS_IS_OK(status)) {
     315                        talloc_free(tmp_ctx);
     316                        return status;
     317                }
     318
     319                unixid->id = rid;
     320                unixid->type = ID_TYPE_UID;
    323321
    324322                talloc_free(tmp_ctx);
     
    330328                DEBUG(6, ("This is a local unix gid, just calculate that.\n"));
    331329                status = dom_sid_split_rid(tmp_ctx, sid, NULL, &rid);
    332                 if (!NT_STATUS_IS_OK(status)) goto failed;
    333 
    334                 *unixid = talloc(mem_ctx, struct unixid);
    335                 if (*unixid == NULL) {
    336                         status = NT_STATUS_NO_MEMORY;
    337                         goto failed;
    338                 }
    339                 (*unixid)->id = rid;
    340                 (*unixid)->type = ID_TYPE_GID;
     330                if (!NT_STATUS_IS_OK(status)) {
     331                        talloc_free(tmp_ctx);
     332                        return status;
     333                }
     334
     335                unixid->id = rid;
     336                unixid->type = ID_TYPE_GID;
    341337
    342338                talloc_free(tmp_ctx);
     
    349345        if (ret != LDB_SUCCESS) {
    350346                DEBUG(1, ("Search failed: %s\n", ldb_errstring(ldb)));
    351                 status = NT_STATUS_NONE_MAPPED;
    352                 goto failed;
     347                talloc_free(tmp_ctx);
     348                return NT_STATUS_NONE_MAPPED;
    353349        }
    354350
     
    360356                if (new_xid == (uint32_t) -1) {
    361357                        DEBUG(1, ("Invalid xid mapping.\n"));
    362                         status = NT_STATUS_NONE_MAPPED;
    363                         goto failed;
     358                        talloc_free(tmp_ctx);
     359                        return NT_STATUS_NONE_MAPPED;
    364360                }
    365361
    366362                if (type == NULL) {
    367363                        DEBUG(1, ("Invalid type for mapping entry.\n"));
    368                         status = NT_STATUS_NONE_MAPPED;
    369                         goto failed;
    370                 }
    371 
    372                 *unixid = talloc(mem_ctx, struct unixid);
    373                 if (*unixid == NULL) {
    374                         status = NT_STATUS_NO_MEMORY;
    375                         goto failed;
    376                 }
    377 
    378                 (*unixid)->id = new_xid;
     364                        talloc_free(tmp_ctx);
     365                        return NT_STATUS_NONE_MAPPED;
     366                }
     367
     368                unixid->id = new_xid;
    379369
    380370                if (strcmp(type, "ID_TYPE_BOTH") == 0) {
    381                         (*unixid)->type = ID_TYPE_BOTH;
     371                        unixid->type = ID_TYPE_BOTH;
    382372                } else if (strcmp(type, "ID_TYPE_UID") == 0) {
    383                         (*unixid)->type = ID_TYPE_UID;
     373                        unixid->type = ID_TYPE_UID;
    384374                } else {
    385                         (*unixid)->type = ID_TYPE_GID;
     375                        unixid->type = ID_TYPE_GID;
    386376                }
    387377
     
    415405        }
    416406
    417         /*FIXME: if lp_idmap_trusted_only() == true, check if SID can be
     407        /*FIXME: if lpcfg_idmap_trusted_only() == true, check if SID can be
    418408         * resolved here. */
    419409
     
    606596        }
    607597
    608         *unixid = talloc(mem_ctx, struct unixid);
    609         if (*unixid == NULL) {
    610                 status = NT_STATUS_NO_MEMORY;
    611                 goto failed;
    612         }
    613 
    614         (*unixid)->id = new_xid;
    615         (*unixid)->type = ID_TYPE_BOTH;
     598        unixid->id = new_xid;
     599        unixid->type = ID_TYPE_BOTH;
    616600        talloc_free(tmp_ctx);
    617601        return NT_STATUS_OK;
     
    637621
    638622NTSTATUS idmap_xids_to_sids(struct idmap_context *idmap_ctx,
    639                             TALLOC_CTX *mem_ctx, int count,
    640                             struct id_mapping *id)
     623                            TALLOC_CTX *mem_ctx,
     624                            struct id_map **id)
    641625{
    642         int i;
    643         int error_count = 0;
    644 
    645         for (i = 0; i < count; ++i) {
    646                 id[i].status = idmap_xid_to_sid(idmap_ctx, mem_ctx,
    647                                                 id[i].unixid, &id[i].sid);
    648                 if (NT_STATUS_EQUAL(id[i].status, NT_STATUS_RETRY)) {
    649                         id[i].status = idmap_xid_to_sid(idmap_ctx, mem_ctx,
    650                                                         id[i].unixid,
    651                                                         &id[i].sid);
    652                 }
    653                 if (!NT_STATUS_IS_OK(id[i].status)) {
    654                         DEBUG(1, ("idmapping xid_to_sid failed for id[%d]\n", i));
     626        unsigned int i, error_count = 0;
     627        NTSTATUS status;
     628
     629        for (i = 0; id && id[i]; i++) {
     630                status = idmap_xid_to_sid(idmap_ctx, mem_ctx,
     631                                                &id[i]->xid, &id[i]->sid);
     632                if (NT_STATUS_EQUAL(status, NT_STATUS_RETRY)) {
     633                        status = idmap_xid_to_sid(idmap_ctx, mem_ctx,
     634                                                        &id[i]->xid,
     635                                                        &id[i]->sid);
     636                }
     637                if (!NT_STATUS_IS_OK(status)) {
     638                        DEBUG(1, ("idmapping xid_to_sid failed for id[%d]=%lu: %s\n",
     639                                  i, (unsigned long)id[i]->xid.id, nt_errstr(status)));
    655640                        error_count++;
    656                 }
    657         }
    658 
    659         if (error_count == count) {
     641                        id[i]->status = ID_UNMAPPED;
     642                } else {
     643                        id[i]->status = ID_MAPPED;
     644                }
     645        }
     646
     647        if (error_count == i) {
    660648                /* Mapping did not work at all. */
    661649                return NT_STATUS_NONE_MAPPED;
     
    682670
    683671NTSTATUS idmap_sids_to_xids(struct idmap_context *idmap_ctx,
    684                             TALLOC_CTX *mem_ctx, int count,
    685                             struct id_mapping *id)
     672                            TALLOC_CTX *mem_ctx,
     673                            struct id_map **id)
    686674{
    687         int i;
    688         int error_count = 0;
    689 
    690         for (i = 0; i < count; ++i) {
    691                 id[i].status = idmap_sid_to_xid(idmap_ctx, mem_ctx,
    692                                                 id[i].sid, &id[i].unixid);
    693                 if (NT_STATUS_EQUAL(id[i].status, NT_STATUS_RETRY)) {
    694                         id[i].status = idmap_sid_to_xid(idmap_ctx, mem_ctx,
    695                                                         id[i].sid,
    696                                                         &id[i].unixid);
    697                 }
    698                 if (!NT_STATUS_IS_OK(id[i].status)) {
    699                         DEBUG(1, ("idmapping sid_to_xid failed for id[%d]\n", i));
     675        unsigned int i, error_count = 0;
     676        NTSTATUS status;
     677
     678        for (i = 0; id && id[i]; i++) {
     679                status = idmap_sid_to_xid(idmap_ctx, mem_ctx,
     680                                          id[i]->sid, &id[i]->xid);
     681                if (NT_STATUS_EQUAL(status, NT_STATUS_RETRY)) {
     682                        status = idmap_sid_to_xid(idmap_ctx, mem_ctx,
     683                                                  id[i]->sid,
     684                                                  &id[i]->xid);
     685                }
     686                if (!NT_STATUS_IS_OK(status)) {
     687                        char *str = dom_sid_string(mem_ctx, id[i]->sid);
     688                        DEBUG(1, ("idmapping sid_to_xid failed for id[%d]=%s: %s\n",
     689                                  i, str, nt_errstr(status)));
     690                        talloc_free(str);
    700691                        error_count++;
    701                 }
    702         }
    703 
    704         if (error_count == count) {
     692                        id[i]->status = ID_UNMAPPED;
     693                } else {
     694                        id[i]->status = ID_MAPPED;
     695                }
     696        }
     697
     698        if (error_count == i) {
    705699                /* Mapping did not work at all. */
    706700                return NT_STATUS_NONE_MAPPED;
Note: See TracChangeset for help on using the changeset viewer.