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 deleted
39 edited
5 copied

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source4/winbind/idmap.c

    r414 r745  
    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;
  • trunk/server/source4/winbind/idmap.h

    r414 r745  
    2020*/
    2121
    22 #ifndef _IDMAP_H_
    23 #define _IDMAP_H_
     22#ifndef _WINBIND_IDMAP_H_
     23#define _WINBIND_IDMAP_H_
    2424
    25 #include "librpc/gen_ndr/winbind.h"
     25#include "librpc/gen_ndr/idmap.h"
    2626
    2727struct idmap_context {
  • trunk/server/source4/winbind/wb_async_helpers.c

    r414 r745  
    2222
    2323#include "includes.h"
     24#include <tevent.h>
    2425#include "libcli/composite/composite.h"
    2526#include "winbind/wb_async_helpers.h"
    2627
    27 #include "lib/messaging/irpc.h"
    28 #include "librpc/gen_ndr/irpc.h"
    29 #include "auth/credentials/credentials.h"
    3028#include "libcli/security/security.h"
    31 #include "libcli/auth/libcli_auth.h"
    32 #include "librpc/gen_ndr/ndr_netlogon_c.h"
    3329#include "librpc/gen_ndr/ndr_lsa_c.h"
    3430#include "librpc/gen_ndr/ndr_samr_c.h"
    3531
    36 #include "winbind/wb_helper.h"
    3732
    3833struct lsa_lookupsids_state {
    3934        struct composite_context *ctx;
    40         int num_sids;
     35        uint32_t num_sids;
    4136        struct lsa_LookupSids r;
    4237        struct lsa_SidArray sids;
     
    4742};
    4843
    49 static void lsa_lookupsids_recv_names(struct rpc_request *req);
     44static void lsa_lookupsids_recv_names(struct tevent_req *subreq);
    5045
    5146struct composite_context *wb_lsa_lookupsids_send(TALLOC_CTX *mem_ctx,
    5247                                                 struct dcerpc_pipe *lsa_pipe,
    5348                                                 struct policy_handle *handle,
    54                                                  int num_sids,
     49                                                 uint32_t num_sids,
    5550                                                 const struct dom_sid **sids)
    5651{
    5752        struct composite_context *result;
    58         struct rpc_request *req;
    5953        struct lsa_lookupsids_state *state;
    60         int i;
     54        uint32_t i;
     55        struct tevent_req *subreq;
    6156
    6257        result = composite_create(mem_ctx, lsa_pipe->conn->event_ctx);
     
    9590        state->r.out.domains = &state->domains;
    9691
    97         req = dcerpc_lsa_LookupSids_send(lsa_pipe, state, &state->r);
    98         if (req == NULL) goto failed;
    99 
    100         req->async.callback = lsa_lookupsids_recv_names;
    101         req->async.private_data = state;
     92        subreq = dcerpc_lsa_LookupSids_r_send(state,
     93                                              result->event_ctx,
     94                                              lsa_pipe->binding_handle,
     95                                              &state->r);
     96        if (subreq == NULL) goto failed;
     97        tevent_req_set_callback(subreq, lsa_lookupsids_recv_names, state);
     98
    10299        return result;
    103100
     
    107104}
    108105
    109 static void lsa_lookupsids_recv_names(struct rpc_request *req)
     106static void lsa_lookupsids_recv_names(struct tevent_req *subreq)
    110107{
    111108        struct lsa_lookupsids_state *state =
    112                 talloc_get_type(req->async.private_data,
    113                                 struct lsa_lookupsids_state);
    114         int i;
    115 
    116         state->ctx->status = dcerpc_ndr_request_recv(req);
     109                tevent_req_callback_data(subreq,
     110                struct lsa_lookupsids_state);
     111        uint32_t i;
     112
     113        state->ctx->status = dcerpc_lsa_LookupSids_r_recv(subreq, state);
     114        TALLOC_FREE(subreq);
    117115        if (!composite_is_ok(state->ctx)) return;
    118116        state->ctx->status = state->r.out.result;
     
    196194};
    197195
    198 static void lsa_lookupnames_recv_sids(struct rpc_request *req);
     196static void lsa_lookupnames_recv_sids(struct tevent_req *subreq);
    199197
    200198struct composite_context *wb_lsa_lookupnames_send(TALLOC_CTX *mem_ctx,
    201199                                                  struct dcerpc_pipe *lsa_pipe,
    202200                                                  struct policy_handle *handle,
    203                                                   int num_names,
     201                                                  uint32_t num_names,
    204202                                                  const char **names)
    205203{
    206204        struct composite_context *result;
    207         struct rpc_request *req;
    208205        struct lsa_lookupnames_state *state;
     206        struct tevent_req *subreq;
    209207
    210208        struct lsa_String *lsa_names;
    211         int i;
     209        uint32_t i;
    212210
    213211        result = composite_create(mem_ctx, lsa_pipe->conn->event_ctx);
     
    244242        state->r.out.domains = &state->domains;
    245243
    246         req = dcerpc_lsa_LookupNames_send(lsa_pipe, state, &state->r);
    247         if (req == NULL) goto failed;
    248 
    249         req->async.callback = lsa_lookupnames_recv_sids;
    250         req->async.private_data = state;
     244        subreq = dcerpc_lsa_LookupNames_r_send(state,
     245                                               result->event_ctx,
     246                                               lsa_pipe->binding_handle,
     247                                               &state->r);
     248        if (subreq == NULL) goto failed;
     249        tevent_req_set_callback(subreq, lsa_lookupnames_recv_sids, state);
     250
    251251        return result;
    252252
     
    256256}
    257257
    258 static void lsa_lookupnames_recv_sids(struct rpc_request *req)
     258static void lsa_lookupnames_recv_sids(struct tevent_req *subreq)
    259259{
    260260        struct lsa_lookupnames_state *state =
    261                 talloc_get_type(req->async.private_data,
    262                                 struct lsa_lookupnames_state);
    263         int i;
    264 
    265         state->ctx->status = dcerpc_ndr_request_recv(req);
     261                tevent_req_callback_data(subreq,
     262                struct lsa_lookupnames_state);
     263        uint32_t i;
     264
     265        state->ctx->status = dcerpc_lsa_LookupNames_r_recv(subreq, state);
     266        TALLOC_FREE(subreq);
    266267        if (!composite_is_ok(state->ctx)) return;
    267268        state->ctx->status = state->r.out.result;
     
    323324        struct dcerpc_pipe *samr_pipe;
    324325
    325         int num_rids;
     326        uint32_t num_rids;
    326327        uint32_t *rids;
    327328
     
    334335};
    335336
    336 static void samr_usergroups_recv_open(struct rpc_request *req);
    337 static void samr_usergroups_recv_groups(struct rpc_request *req);
    338 static void samr_usergroups_recv_close(struct rpc_request *req);
     337static void samr_usergroups_recv_open(struct tevent_req *subreq);
     338static void samr_usergroups_recv_groups(struct tevent_req *subreq);
     339static void samr_usergroups_recv_close(struct tevent_req *subreq);
    339340
    340341struct composite_context *wb_samr_userdomgroups_send(TALLOC_CTX *mem_ctx,
     
    344345{
    345346        struct composite_context *result;
    346         struct rpc_request *req;
    347347        struct samr_getuserdomgroups_state *state;
     348        struct tevent_req *subreq;
    348349
    349350        result = composite_create(mem_ctx, samr_pipe->conn->event_ctx);
     
    365366        state->o.out.user_handle = state->user_handle;
    366367
    367         req = dcerpc_samr_OpenUser_send(state->samr_pipe, state, &state->o);
    368         if (req == NULL) goto failed;
    369 
    370         req->async.callback = samr_usergroups_recv_open;
    371         req->async.private_data = state;
     368        subreq = dcerpc_samr_OpenUser_r_send(state,
     369                                             result->event_ctx,
     370                                             state->samr_pipe->binding_handle,
     371                                             &state->o);
     372        if (subreq == NULL) goto failed;
     373        tevent_req_set_callback(subreq, samr_usergroups_recv_open, state);
     374
    372375        return result;
    373376
     
    377380}
    378381                                             
    379 static void samr_usergroups_recv_open(struct rpc_request *req)
     382static void samr_usergroups_recv_open(struct tevent_req *subreq)
    380383{
    381384        struct samr_getuserdomgroups_state *state =
    382                 talloc_get_type(req->async.private_data,
    383                                 struct samr_getuserdomgroups_state);
    384 
    385         state->ctx->status = dcerpc_ndr_request_recv(req);
     385                tevent_req_callback_data(subreq,
     386                struct samr_getuserdomgroups_state);
     387
     388        state->ctx->status = dcerpc_samr_OpenUser_r_recv(subreq, state);
     389        TALLOC_FREE(subreq);
    386390        if (!composite_is_ok(state->ctx)) return;
    387391        state->ctx->status = state->o.out.result;
     
    391395        state->g.out.rids = &state->rid_array;
    392396
    393         req = dcerpc_samr_GetGroupsForUser_send(state->samr_pipe, state,
    394                                                 &state->g);
    395         composite_continue_rpc(state->ctx, req, samr_usergroups_recv_groups,
    396                                state);
    397 }
    398 
    399 static void samr_usergroups_recv_groups(struct rpc_request *req)
     397        subreq = dcerpc_samr_GetGroupsForUser_r_send(state,
     398                                                     state->ctx->event_ctx,
     399                                                     state->samr_pipe->binding_handle,
     400                                                     &state->g);
     401        if (composite_nomem(subreq, state->ctx)) return;
     402        tevent_req_set_callback(subreq, samr_usergroups_recv_groups, state);
     403}
     404
     405static void samr_usergroups_recv_groups(struct tevent_req *subreq)
    400406{
    401407        struct samr_getuserdomgroups_state *state =
    402                 talloc_get_type(req->async.private_data,
    403                                 struct samr_getuserdomgroups_state);
    404 
    405         state->ctx->status = dcerpc_ndr_request_recv(req);
     408                tevent_req_callback_data(subreq,
     409                struct samr_getuserdomgroups_state);
     410
     411        state->ctx->status = dcerpc_samr_GetGroupsForUser_r_recv(subreq, state);
     412        TALLOC_FREE(subreq);
    406413        if (!composite_is_ok(state->ctx)) return;
    407414        state->ctx->status = state->g.out.result;
     
    411418        state->c.out.handle = state->user_handle;
    412419
    413         req = dcerpc_samr_Close_send(state->samr_pipe, state, &state->c);
    414         composite_continue_rpc(state->ctx, req, samr_usergroups_recv_close,
    415                                state);
    416 }
    417 
    418 static void samr_usergroups_recv_close(struct rpc_request *req)
     420        subreq = dcerpc_samr_Close_r_send(state,
     421                                          state->ctx->event_ctx,
     422                                          state->samr_pipe->binding_handle,
     423                                          &state->c);
     424        if (composite_nomem(subreq, state->ctx)) return;
     425        tevent_req_set_callback(subreq, samr_usergroups_recv_close, state);
     426}
     427
     428static void samr_usergroups_recv_close(struct tevent_req *subreq)
    419429{
    420430        struct samr_getuserdomgroups_state *state =
    421                 talloc_get_type(req->async.private_data,
    422                                 struct samr_getuserdomgroups_state);
    423 
    424         state->ctx->status = dcerpc_ndr_request_recv(req);
     431                tevent_req_callback_data(subreq,
     432                struct samr_getuserdomgroups_state);
     433
     434        state->ctx->status = dcerpc_samr_Close_r_recv(subreq, state);
     435        TALLOC_FREE(subreq);
    425436        if (!composite_is_ok(state->ctx)) return;
    426437        state->ctx->status = state->c.out.result;
     
    432443NTSTATUS wb_samr_userdomgroups_recv(struct composite_context *ctx,
    433444                                    TALLOC_CTX *mem_ctx,
    434                                     int *num_rids, uint32_t **rids)
     445                                    uint32_t *num_rids, uint32_t **rids)
    435446{
    436447        struct samr_getuserdomgroups_state *state =
     
    438449                                struct samr_getuserdomgroups_state);
    439450
    440         int i;
     451        uint32_t i;
    441452        NTSTATUS status = composite_wait(ctx);
    442453        if (!NT_STATUS_IS_OK(status)) goto done;
  • trunk/server/source4/winbind/wb_cmd_getdcname.c

    r414 r745  
    3535
    3636static void getdcname_recv_domain(struct composite_context *ctx);
    37 static void getdcname_recv_dcname(struct rpc_request *req);
     37static void getdcname_recv_dcname(struct tevent_req *subreq);
    3838
    3939struct composite_context *wb_cmd_getdcname_send(TALLOC_CTX *mem_ctx,
     
    7373                                struct cmd_getdcname_state);
    7474        struct wbsrv_domain *domain;
    75         struct rpc_request *req;
     75        struct tevent_req *subreq;
    7676
    7777        state->ctx->status = wb_sid2domain_recv(ctx, &domain);
     
    8484        state->g.out.dcname = talloc(state, const char *);
    8585
    86         req = dcerpc_netr_GetAnyDCName_send(domain->netlogon_pipe, state,
    87                                             &state->g);
    88         if (composite_nomem(req, state->ctx)) return;
     86        subreq = dcerpc_netr_GetAnyDCName_r_send(state,
     87                                                 state->ctx->event_ctx,
     88                                                 domain->netlogon_pipe->binding_handle,
     89                                                 &state->g);
     90        if (composite_nomem(subreq, state->ctx)) return;
    8991
    90         composite_continue_rpc(state->ctx, req, getdcname_recv_dcname, state);
     92        tevent_req_set_callback(subreq, getdcname_recv_dcname, state);
    9193}
    9294
    93 static void getdcname_recv_dcname(struct rpc_request *req)
     95static void getdcname_recv_dcname(struct tevent_req *subreq)
    9496{
    9597        struct cmd_getdcname_state *state =
    96                 talloc_get_type(req->async.private_data,
    97                                 struct cmd_getdcname_state);
     98                tevent_req_callback_data(subreq,
     99                struct cmd_getdcname_state);
    98100
    99         state->ctx->status = dcerpc_ndr_request_recv(req);
     101        state->ctx->status = dcerpc_netr_GetAnyDCName_r_recv(subreq, state);
     102        TALLOC_FREE(subreq);
    100103        if (!composite_is_ok(state->ctx)) return;
    101104        state->ctx->status = werror_to_ntstatus(state->g.out.result);
     
    112115                talloc_get_type(c->private_data, struct cmd_getdcname_state);
    113116        NTSTATUS status = composite_wait(c);
     117        if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_DOMAIN)) {
     118                /* special case: queried DC is PDC */
     119                state->g.out.dcname = &state->g.in.logon_server;
     120                status = NT_STATUS_OK;
     121        }
    114122        if (NT_STATUS_IS_OK(status)) {
    115123                const char *p = *(state->g.out.dcname);
  • trunk/server/source4/winbind/wb_cmd_getgrgid.c

    r414 r745  
    2323#include "libcli/composite/composite.h"
    2424#include "winbind/wb_server.h"
    25 #include "winbind/wb_async_helpers.h"
    26 #include "winbind/wb_helper.h"
    2725#include "smbd/service_task.h"
    28 #include "libnet/libnet_proto.h"
    29 #include "param/param.h"
    30 #include "libcli/security/proto.h"
    31 #include "auth/credentials/credentials.h"
    3226
    3327struct cmd_getgrgid_state {
     
    137131        DEBUG(5, ("cmd_getgrgid_recv_group_info called\n"));
    138132
    139         gr = talloc(state, struct winbindd_gr);
     133        gr = talloc_zero(state, struct winbindd_gr);
    140134        if (composite_nomem(gr, state->ctx)) return;
    141135
  • trunk/server/source4/winbind/wb_cmd_getgrnam.c

    r414 r745  
    2323#include "libcli/composite/composite.h"
    2424#include "winbind/wb_server.h"
    25 #include "winbind/wb_async_helpers.h"
    26 #include "param/param.h"
    2725#include "winbind/wb_helper.h"
    2826#include "smbd/service_task.h"
    29 #include "libnet/libnet_proto.h"
    30 #include "libcli/security/proto.h"
    3127
    3228struct cmd_getgrnam_state {
  • trunk/server/source4/winbind/wb_cmd_getpwent.c

    r414 r745  
    2323#include "libcli/composite/composite.h"
    2424#include "winbind/wb_server.h"
    25 #include "winbind/wb_async_helpers.h"
    26 #include "winbind/wb_helper.h"
    2725#include "smbd/service_task.h"
    28 #include "libnet/libnet_proto.h"
    2926
    3027struct cmd_getpwent_state {
  • trunk/server/source4/winbind/wb_cmd_getpwnam.c

    r414 r745  
    2323#include "libcli/composite/composite.h"
    2424#include "winbind/wb_server.h"
    25 #include "winbind/wb_async_helpers.h"
    2625#include "param/param.h"
    2726#include "winbind/wb_helper.h"
    2827#include "smbd/service_task.h"
    29 #include "libnet/libnet_proto.h"
    3028#include "libcli/security/security.h"
    3129
     
    127125        WBSRV_SAMBA3_SET_STRING(pw->pw_gecos, user_info->out.full_name);
    128126        WBSRV_SAMBA3_SET_STRING(pw->pw_dir,
    129                 lp_template_homedir(state->service->task->lp_ctx));
     127                lpcfg_template_homedir(state->service->task->lp_ctx));
    130128        all_string_sub(pw->pw_dir, "%WORKGROUP%", state->workgroup_name,
    131129                        sizeof(fstring) - 1);
     
    133131                        sizeof(fstring) - 1);
    134132        WBSRV_SAMBA3_SET_STRING(pw->pw_shell,
    135                 lp_template_shell(state->service->task->lp_ctx));
     133                lpcfg_template_shell(state->service->task->lp_ctx));
    136134
    137135        state->group_sid = dom_sid_dup(state, user_info->out.primary_group_sid);
  • trunk/server/source4/winbind/wb_cmd_getpwuid.c

    r414 r745  
    2323#include "libcli/composite/composite.h"
    2424#include "winbind/wb_server.h"
    25 #include "winbind/wb_async_helpers.h"
    26 #include "winbind/wb_helper.h"
    2725#include "smbd/service_task.h"
    28 #include "libnet/libnet_proto.h"
    2926#include "param/param.h"
    30 #include "libcli/security/proto.h"
    31 #include "auth/credentials/credentials.h"
    3227
    3328struct cmd_getpwuid_state {
     
    151146        WBSRV_SAMBA3_SET_STRING(pw->pw_gecos, user_info->out.full_name);
    152147        WBSRV_SAMBA3_SET_STRING(pw->pw_dir,
    153                 lp_template_homedir(state->service->task->lp_ctx));
     148                lpcfg_template_homedir(state->service->task->lp_ctx));
    154149        all_string_sub(pw->pw_dir, "%WORKGROUP%", state->workgroup,
    155150                        sizeof(fstring) - 1);
     
    157152                        sizeof(fstring) - 1);
    158153        WBSRV_SAMBA3_SET_STRING(pw->pw_shell,
    159                                 lp_template_shell(state->service->task->lp_ctx));
     154                                lpcfg_template_shell(state->service->task->lp_ctx));
    160155
    161156        pw->pw_uid = state->uid;
  • trunk/server/source4/winbind/wb_cmd_list_groups.c

    r414 r745  
    2323#include "libcli/composite/composite.h"
    2424#include "winbind/wb_server.h"
    25 #include "winbind/wb_async_helpers.h"
    26 #include "winbind/wb_helper.h"
    2725#include "smbd/service_task.h"
    28 #include "libnet/libnet_proto.h"
    2926
    3027struct cmd_list_groups_state {
     
    3633        uint32_t resume_index;
    3734        char *result;
     35        uint32_t num_groups;
    3836};
    3937
     
    5957        state->service = service;
    6058        state->resume_index = 0;
     59        state->num_groups = 0;
    6160        state->result = talloc_strdup(state, "");
    6261        if (composite_nomem(state->result, state->ctx)) return result;
     
    9392        if (!composite_is_ok(state->ctx)) return;
    9493
     94        /* we use this entry also for context purposes (libnet_GroupList) */
    9595        state->domain = domain;
    9696
    9797        /* If this is non-null, we've looked up the domain given in the winbind
    98          * request, otherwise we'll just use the default name.*/
     98         * request, otherwise we'll just use the default name .*/
    9999        if (state->domain_name == NULL) {
    100100                state->domain_name = talloc_strdup(state,
    101                                 domain->libnet_ctx->samr.name);
     101                                                   state->domain->libnet_ctx->samr.name);
    102102                if (composite_nomem(state->domain_name, state->ctx)) return;
    103103        }
     
    114114        group_list->in.resume_index = state->resume_index;
    115115
    116         ctx = libnet_GroupList_send(domain->libnet_ctx, state, group_list,NULL);
     116        ctx = libnet_GroupList_send(state->domain->libnet_ctx, state,
     117                                    group_list, NULL);
    117118
    118119        composite_continue(state->ctx, ctx, cmd_list_groups_recv_group_list,
    119                         state);
     120                           state);
    120121}
    121122
     
    137138        /* If NTSTATUS is neither OK nor MORE_ENTRIES, something broke */
    138139        if (!NT_STATUS_IS_OK(status) &&
    139              !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
     140            !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES) &&
     141            !NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
    140142                composite_error(state->ctx, status);
    141143                return;
     
    146148                          group_list->out.groups[i].groupname));
    147149                state->result = talloc_asprintf_append_buffer(state->result,
    148                                         "%s,",
    149                                         group_list->out.groups[i].groupname);
     150                                                              "%s,",
     151                                                              group_list->out.groups[i].groupname);
     152                state->num_groups++;
    150153        }
    151154
     
    153156         * So we'll trim off the trailing ',' and are done.*/
    154157        if (NT_STATUS_IS_OK(status)) {
    155                 int str_len = strlen(state->result);
     158                size_t str_len = strlen(state->result);
    156159                DEBUG(5, ("list_GroupList_recv returned NT_STATUS_OK\n"));
    157                 state->result[str_len - 1] = '\0';
     160                if (str_len > 0) {
     161                        state->result[str_len - 1] = '\0';
     162                }
    158163                composite_done(state->ctx);
    159164                return;
     
    172177
    173178        ctx = libnet_GroupList_send(state->domain->libnet_ctx, state,group_list,
    174                         NULL);
     179                                    NULL);
    175180
    176181        composite_continue(state->ctx, ctx, cmd_list_groups_recv_group_list,
    177                         state);
     182                           state);
    178183}
    179184
    180185NTSTATUS wb_cmd_list_groups_recv(struct composite_context *ctx,
    181186                TALLOC_CTX *mem_ctx, uint32_t *extra_data_len,
    182                 char **extra_data)
     187                char **extra_data, uint32_t *num_groups)
    183188{
    184189        NTSTATUS status = composite_wait(ctx);
     
    192197                *extra_data_len = strlen(state->result);
    193198                *extra_data = talloc_steal(mem_ctx, state->result);
     199                *num_groups = state->num_groups;
    194200        }
    195201
  • trunk/server/source4/winbind/wb_cmd_list_trustdom.c

    r414 r745  
    3434        struct dcerpc_pipe *lsa_pipe;
    3535        struct policy_handle *lsa_policy;
    36         int num_domains;
     36        uint32_t num_domains;
    3737        struct wb_dom_info **domains;
    3838
     
    4444static void cmd_list_trustdoms_recv_domain(struct composite_context *ctx);
    4545static void cmd_list_trustdoms_recv_lsa(struct composite_context *ctx);
    46 static void cmd_list_trustdoms_recv_doms(struct rpc_request *req);
     46static void cmd_list_trustdoms_recv_doms(struct tevent_req *subreq);
    4747
    4848struct composite_context *wb_cmd_list_trustdoms_send(TALLOC_CTX *mem_ctx,
     
    9595                talloc_get_type(ctx->async.private_data,
    9696                                struct cmd_list_trustdom_state);
    97         struct rpc_request *req;
     97        struct tevent_req *subreq;
    9898
    9999        state->ctx->status = wb_init_lsa_recv(ctx, state,
     
    115115        state->r.out.domains = &state->domainlist;
    116116
    117         req = dcerpc_lsa_EnumTrustDom_send(state->lsa_pipe, state, &state->r);
    118         composite_continue_rpc(state->ctx, req, cmd_list_trustdoms_recv_doms,
    119                                state);
    120 }
    121 
    122 static void cmd_list_trustdoms_recv_doms(struct rpc_request *req)
     117        subreq = dcerpc_lsa_EnumTrustDom_r_send(state,
     118                                                state->ctx->event_ctx,
     119                                                state->lsa_pipe->binding_handle,
     120                                                &state->r);
     121        if (composite_nomem(subreq, state->ctx)) return;
     122        tevent_req_set_callback(subreq, cmd_list_trustdoms_recv_doms, state);
     123}
     124
     125static void cmd_list_trustdoms_recv_doms(struct tevent_req *subreq)
    123126{
    124127        struct cmd_list_trustdom_state *state =
    125                 talloc_get_type(req->async.private_data,
    126                                 struct cmd_list_trustdom_state);
    127         int i, old_num_domains;
    128 
    129         state->ctx->status = dcerpc_ndr_request_recv(req);
     128                tevent_req_callback_data(subreq,
     129                struct cmd_list_trustdom_state);
     130        uint32_t i, old_num_domains;
     131
     132        state->ctx->status = dcerpc_lsa_EnumTrustDom_r_recv(subreq, state);
     133        TALLOC_FREE(subreq);
    130134        if (!composite_is_ok(state->ctx)) return;
    131135        state->ctx->status = state->r.out.result;
     
    148152
    149153        for (i=0; i<state->r.out.domains->count; i++) {
    150                 int j = i+old_num_domains;
     154                uint32_t j = i+old_num_domains;
    151155                state->domains[j] = talloc(state->domains,
    152156                                           struct wb_dom_info);
     
    174178        state->r.out.domains = &state->domainlist;
    175179       
    176         req = dcerpc_lsa_EnumTrustDom_send(state->lsa_pipe, state, &state->r);
    177         composite_continue_rpc(state->ctx, req, cmd_list_trustdoms_recv_doms,
    178                                state);
     180        subreq = dcerpc_lsa_EnumTrustDom_r_send(state,
     181                                                state->ctx->event_ctx,
     182                                                state->lsa_pipe->binding_handle,
     183                                                &state->r);
     184        if (composite_nomem(subreq, state->ctx)) return;
     185        tevent_req_set_callback(subreq, cmd_list_trustdoms_recv_doms, state);
    179186}
    180187
    181188NTSTATUS wb_cmd_list_trustdoms_recv(struct composite_context *ctx,
    182189                                    TALLOC_CTX *mem_ctx,
    183                                     int *num_domains,
     190                                    uint32_t *num_domains,
    184191                                    struct wb_dom_info ***domains)
    185192{
  • trunk/server/source4/winbind/wb_cmd_list_users.c

    r414 r745  
    2323#include "libcli/composite/composite.h"
    2424#include "winbind/wb_server.h"
    25 #include "winbind/wb_async_helpers.h"
    26 #include "winbind/wb_helper.h"
    2725#include "smbd/service_task.h"
    28 #include "libnet/libnet_proto.h"
    2926
    3027struct cmd_list_users_state {
     
    3633        uint32_t resume_index;
    3734        char *result;
     35        uint32_t num_users;
    3836};
    3937
     
    5957        state->service = service;
    6058        state->resume_index = 0;
     59        state->num_users = 0;
    6160        state->result = talloc_strdup(state, "");
    6261        if (composite_nomem(state->result, state->ctx)) return result;
     
    137136        /* If NTSTATUS is neither OK nor MORE_ENTRIES, something broke */
    138137        if (!NT_STATUS_IS_OK(status) &&
    139              !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
     138            !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES) &&
     139            !NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
    140140                composite_error(state->ctx, status);
    141141                return;
     
    146146                state->result = talloc_asprintf_append_buffer(state->result, "%s,",
    147147                                        user_list->out.users[i].username);
     148                state->num_users++;
    148149        }
    149150
     
    178179NTSTATUS wb_cmd_list_users_recv(struct composite_context *ctx,
    179180                TALLOC_CTX *mem_ctx, uint32_t *extra_data_len,
    180                 char **extra_data)
     181                char **extra_data, uint32_t *num_users)
    181182{
    182183        NTSTATUS status = composite_wait(ctx);
     
    190191                *extra_data_len = strlen(state->result);
    191192                *extra_data = talloc_steal(mem_ctx, state->result);
     193                *num_users = state->num_users;
    192194        }
    193195
  • trunk/server/source4/winbind/wb_cmd_lookupname.c

    r414 r745  
    2323#include "libcli/composite/composite.h"
    2424#include "winbind/wb_server.h"
    25 #include "winbind/wb_async_helpers.h"
    2625#include "winbind/wb_helper.h"
    2726#include "smbd/service_task.h"
  • trunk/server/source4/winbind/wb_cmd_lookupsid.c

    r414 r745  
    4343        struct cmd_lookupsid_state *state;
    4444
    45 
     45        DEBUG(5, ("wb_cmd_lookupsid_send called\n"));
    4646        result = composite_create(mem_ctx, service->task->event_ctx);
    4747        if (result == NULL) goto failed;
  • trunk/server/source4/winbind/wb_cmd_setpwent.c

    r414 r745  
    2323#include "libcli/composite/composite.h"
    2424#include "winbind/wb_server.h"
    25 #include "winbind/wb_async_helpers.h"
    26 #include "winbind/wb_helper.h"
    2725#include "smbd/service_task.h"
    28 #include "libnet/libnet_proto.h"
    2926
    3027struct cmd_setpwent_state {
     
    3431
    3532        struct wbsrv_pwent *result;
     33        char *domain_name;
    3634};
    3735
     
    8482        if (composite_nomem(user_list, state->ctx)) return;
    8583
     84        state->domain_name = talloc_strdup(state,
     85                        domain->libnet_ctx->samr.name);
    8686        user_list->in.domain_name = talloc_strdup(state,
    8787                        domain->libnet_ctx->samr.name);
     
    9797                        NULL);
    9898
     99        state->result->page_index = -1;
    99100        composite_continue(state->ctx, ctx, cmd_setpwent_recv_user_list, state);
    100101}
     
    105106                        ctx->async.private_data, struct cmd_setpwent_state);
    106107        struct libnet_UserList *user_list;
    107 
     108        struct libnet_UserList *user_list_send;
    108109        DEBUG(5, ("cmd_setpwent_recv_user_list called\n"));
    109110
     
    112113
    113114        state->ctx->status = libnet_UserList_recv(ctx, state->result,
    114                         user_list);
    115         if (!composite_is_ok(state->ctx)) return;
     115                                                  user_list);
     116        if (NT_STATUS_IS_OK(state->ctx->status) ||
     117                NT_STATUS_EQUAL(state->ctx->status, STATUS_MORE_ENTRIES)) {
     118                if (state->result->page_index == -1) { /* First run*/
     119                        state->result->user_list = user_list;
     120                        state->result->page_index = 0;
     121                        state->result->libnet_ctx = state->libnet_ctx;
     122                } else {
     123                        int i, cnt = state->result->user_list->out.count
     124                                                        + user_list->out.count;
     125                        struct userlist *tmp;
     126                        tmp = state->result->user_list->out.users;
     127                        state->result->user_list->out.users = talloc_realloc(state->result,
     128                                                                             tmp, struct userlist,
     129                                                                             cnt);
     130                        tmp = state->result->user_list->out.users;
     131                        for(i=0;i<user_list->out.count;i++ ) {
     132                                tmp[state->result->user_list->out.count + i].username
     133                                        = talloc_strdup(state->result, user_list->out.users[i].username);
     134                        }
     135                        state->result->user_list->out.count = cnt;
     136                        talloc_free(user_list);
     137                }
    116138
    117         state->result->user_list = user_list;
    118         state->result->page_index = 0;
    119         state->result->libnet_ctx = state->libnet_ctx;
    120 
    121         composite_done(state->ctx);
     139                if (NT_STATUS_IS_OK(state->ctx->status) ) {
     140                        composite_done(state->ctx);
     141                } else {
     142                        user_list_send = talloc(state->result, struct libnet_UserList);
     143                        if (composite_nomem(user_list_send, state->ctx)) return;
     144                        user_list_send->in.domain_name =  talloc_strdup(state, state->domain_name);
     145                        user_list_send->in.resume_index = user_list->out.resume_index;
     146                        user_list_send->in.page_size = 128;
     147                        ctx = libnet_UserList_send(state->libnet_ctx, state->result, user_list_send, NULL);
     148                        composite_continue(state->ctx, ctx, cmd_setpwent_recv_user_list, state);
     149                }
     150        } else {
     151                composite_error(state->ctx, state->ctx->status);
     152        }
     153        return;
    122154}
    123155
  • trunk/server/source4/winbind/wb_cmd_userdomgroups.c

    r414 r745  
    3131        struct dom_sid *dom_sid;
    3232        uint32_t user_rid;
    33         int num_rids;
     33        uint32_t num_rids;
    3434        uint32_t *rids;
    3535};
     
    105105NTSTATUS wb_cmd_userdomgroups_recv(struct composite_context *c,
    106106                                   TALLOC_CTX *mem_ctx,
    107                                    int *num_sids, struct dom_sid ***sids)
     107                                   uint32_t *num_sids, struct dom_sid ***sids)
    108108{
    109109        struct cmd_userdomgroups_state *state =
    110110                talloc_get_type(c->private_data,
    111111                                struct cmd_userdomgroups_state);
    112         int i;
     112        uint32_t i;
    113113        NTSTATUS status;
    114114
     
    140140                              struct wbsrv_service *service,
    141141                              const struct dom_sid *sid,
    142                               int *num_sids, struct dom_sid ***sids)
     142                              uint32_t *num_sids, struct dom_sid ***sids)
    143143{
    144144        struct composite_context *c =
  • trunk/server/source4/winbind/wb_cmd_usersids.c

    r414 r745  
    3535        struct wbsrv_service *service;
    3636        struct dom_sid *user_sid;
    37         int num_domgroups;
     37        uint32_t num_domgroups;
    3838        struct dom_sid **domgroups;
    3939
     
    4242        struct samr_GetAliasMembership r;
    4343
    44         int num_sids;
     44        uint32_t num_sids;
    4545        struct dom_sid **sids;
    4646};
     
    4848static void usersids_recv_domgroups(struct composite_context *ctx);
    4949static void usersids_recv_domain(struct composite_context *ctx);
    50 static void usersids_recv_aliases(struct rpc_request *req);
     50static void usersids_recv_aliases(struct tevent_req *subreq);
    5151
    5252struct composite_context *wb_cmd_usersids_send(TALLOC_CTX *mem_ctx,
     
    103103                talloc_get_type(ctx->async.private_data,
    104104                                struct cmd_usersids_state);
    105         struct rpc_request *req;
     105        struct tevent_req *subreq;
    106106        struct wbsrv_domain *domain;
    107         int i;
     107        uint32_t i;
    108108
    109109        state->ctx->status = wb_sid2domain_recv(ctx, &domain);
     
    127127        state->r.out.rids = &state->rids;
    128128
    129         req = dcerpc_samr_GetAliasMembership_send(domain->libnet_ctx->samr.pipe, state,
    130                                                   &state->r);
    131         composite_continue_rpc(state->ctx, req, usersids_recv_aliases, state);
     129        subreq = dcerpc_samr_GetAliasMembership_r_send(state,
     130                                                       state->ctx->event_ctx,
     131                                                       domain->libnet_ctx->samr.pipe->binding_handle,
     132                                                       &state->r);
     133        if (composite_nomem(subreq, state->ctx)) return;
     134        tevent_req_set_callback(subreq, usersids_recv_aliases, state);
    132135}
    133136
    134 static void usersids_recv_aliases(struct rpc_request *req)
     137static void usersids_recv_aliases(struct tevent_req *subreq)
    135138{
    136139        struct cmd_usersids_state *state =
    137                 talloc_get_type(req->async.private_data,
    138                                 struct cmd_usersids_state);
    139         int i;
     140                tevent_req_callback_data(subreq,
     141                struct cmd_usersids_state);
     142        uint32_t i;
    140143
    141         state->ctx->status = dcerpc_ndr_request_recv(req);
     144        state->ctx->status = dcerpc_samr_GetAliasMembership_r_recv(subreq, state);
     145        TALLOC_FREE(subreq);
    142146        if (!composite_is_ok(state->ctx)) return;
    143147        state->ctx->status = state->r.out.result;
     
    169173NTSTATUS wb_cmd_usersids_recv(struct composite_context *ctx,
    170174                              TALLOC_CTX *mem_ctx,
    171                               int *num_sids, struct dom_sid ***sids)
     175                              uint32_t *num_sids, struct dom_sid ***sids)
    172176{
    173177        NTSTATUS status = composite_wait(ctx);
     
    185189NTSTATUS wb_cmd_usersids(TALLOC_CTX *mem_ctx, struct wbsrv_service *service,
    186190                         const struct dom_sid *sid,
    187                          int *num_sids, struct dom_sid ***sids)
     191                         uint32_t *num_sids, struct dom_sid ***sids)
    188192{
    189193        struct composite_context *c =
  • trunk/server/source4/winbind/wb_connect_lsa.c

    r414 r745  
    2525#include "libcli/composite/composite.h"
    2626
    27 #include "libcli/raw/libcliraw.h"
    2827#include "librpc/gen_ndr/ndr_lsa_c.h"
    2928#include "winbind/wb_server.h"
     
    4544
    4645static void init_lsa_recv_pipe(struct composite_context *ctx);
    47 static void init_lsa_recv_openpol(struct rpc_request *req);
     46static void init_lsa_recv_openpol(struct tevent_req *subreq);
    4847
    4948struct composite_context *wb_init_lsa_send(TALLOC_CTX *mem_ctx,
     
    7877static void init_lsa_recv_pipe(struct composite_context *ctx)
    7978{
    80         struct rpc_request *req;
    8179        struct init_lsa_state *state =
    8280                talloc_get_type(ctx->async.private_data,
    8381                                struct init_lsa_state);
     82        struct tevent_req *subreq;
    8483
    8584        state->ctx->status = dcerpc_secondary_auth_connection_recv(ctx, state,
     
    9897        state->openpolicy.out.handle = state->handle;
    9998
    100         req = dcerpc_lsa_OpenPolicy2_send(state->lsa_pipe, state,
    101                                           &state->openpolicy);
    102         composite_continue_rpc(state->ctx, req, init_lsa_recv_openpol, state);
     99        subreq = dcerpc_lsa_OpenPolicy2_r_send(state,
     100                                               state->ctx->event_ctx,
     101                                               state->lsa_pipe->binding_handle,
     102                                               &state->openpolicy);
     103        if (composite_nomem(subreq, state->ctx)) return;
     104        tevent_req_set_callback(subreq, init_lsa_recv_openpol, state);
    103105}
    104106
    105 static void init_lsa_recv_openpol(struct rpc_request *req)
     107static void init_lsa_recv_openpol(struct tevent_req *subreq)
    106108{
    107109        struct init_lsa_state *state =
    108                 talloc_get_type(req->async.private_data,
    109                                 struct init_lsa_state);
     110                tevent_req_callback_data(subreq,
     111                struct init_lsa_state);
    110112
    111         state->ctx->status = dcerpc_ndr_request_recv(req);
     113        state->ctx->status = dcerpc_lsa_OpenPolicy2_r_recv(subreq, state);
     114        TALLOC_FREE(subreq);
    112115        if (!composite_is_ok(state->ctx)) return;
    113116        state->ctx->status = state->openpolicy.out.result;
  • trunk/server/source4/winbind/wb_connect_sam.c

    r414 r745  
    2424#include "libcli/composite/composite.h"
    2525
    26 #include "libcli/raw/libcliraw.h"
    2726#include "libcli/security/security.h"
    2827#include "librpc/gen_ndr/ndr_samr_c.h"
     
    4645
    4746static void connect_samr_recv_pipe(struct composite_context *ctx);
    48 static void connect_samr_recv_conn(struct rpc_request *req);
    49 static void connect_samr_recv_open(struct rpc_request *req);
     47static void connect_samr_recv_conn(struct tevent_req *subreq);
     48static void connect_samr_recv_open(struct tevent_req *subreq);
    5049
    5150struct composite_context *wb_connect_samr_send(TALLOC_CTX *mem_ctx,
     
    8382static void connect_samr_recv_pipe(struct composite_context *ctx)
    8483{
    85         struct rpc_request *req;
    8684        struct connect_samr_state *state =
    8785                talloc_get_type(ctx->async.private_data,
    8886                                struct connect_samr_state);
     87        struct tevent_req *subreq;
    8988
    9089        state->ctx->status = dcerpc_secondary_auth_connection_recv(ctx, state,
     
    101100        state->c.out.connect_handle = state->connect_handle;
    102101
    103         req = dcerpc_samr_Connect2_send(state->samr_pipe, state, &state->c);
    104         composite_continue_rpc(state->ctx, req, connect_samr_recv_conn, state);
    105         return;
     102        subreq = dcerpc_samr_Connect2_r_send(state,
     103                                             state->ctx->event_ctx,
     104                                             state->samr_pipe->binding_handle,
     105                                             &state->c);
     106        if (composite_nomem(subreq, state->ctx)) return;
     107        tevent_req_set_callback(subreq, connect_samr_recv_conn, state);
    106108}
    107109
    108 static void connect_samr_recv_conn(struct rpc_request *req)
     110static void connect_samr_recv_conn(struct tevent_req *subreq)
    109111{
    110112        struct connect_samr_state *state =
    111                 talloc_get_type(req->async.private_data,
    112                                 struct connect_samr_state);
     113                tevent_req_callback_data(subreq,
     114                struct connect_samr_state);
    113115
    114         state->ctx->status = dcerpc_ndr_request_recv(req);
     116        state->ctx->status = dcerpc_samr_Connect2_r_recv(subreq, state);
     117        TALLOC_FREE(subreq);
    115118        if (!composite_is_ok(state->ctx)) return;
    116119        state->ctx->status = state->c.out.result;
     
    125128        state->o.out.domain_handle = state->domain_handle;
    126129
    127         req = dcerpc_samr_OpenDomain_send(state->samr_pipe, state, &state->o);
    128         composite_continue_rpc(state->ctx, req,
    129                                connect_samr_recv_open, state);
     130        subreq = dcerpc_samr_OpenDomain_r_send(state,
     131                                               state->ctx->event_ctx,
     132                                               state->samr_pipe->binding_handle,
     133                                               &state->o);
     134        if (composite_nomem(subreq, state->ctx)) return;
     135        tevent_req_set_callback(subreq, connect_samr_recv_open, state);
    130136}
    131137
    132 static void connect_samr_recv_open(struct rpc_request *req)
     138static void connect_samr_recv_open(struct tevent_req *subreq)
    133139{
    134140        struct connect_samr_state *state =
    135                 talloc_get_type(req->async.private_data,
    136                                 struct connect_samr_state);
     141                tevent_req_callback_data(subreq,
     142                struct connect_samr_state);
    137143
    138         state->ctx->status = dcerpc_ndr_request_recv(req);
     144        state->ctx->status = dcerpc_samr_OpenDomain_r_recv(subreq, state);
     145        TALLOC_FREE(subreq);
    139146        if (!composite_is_ok(state->ctx)) return;
    140147        state->ctx->status = state->o.out.result;
  • trunk/server/source4/winbind/wb_dom_info.c

    r414 r745  
    2727#include "winbind/wb_server.h"
    2828#include "smbd/service_task.h"
    29 #include "librpc/gen_ndr/ndr_irpc.h"
    30 #include "librpc/gen_ndr/samr.h"
    31 #include "lib/messaging/irpc.h"
    32 #include "libcli/finddcs.h"
    33 #include "param/param.h"
     29#include "libcli/finddc.h"
    3430
    3531struct get_dom_info_state {
     
    3834};
    3935
    40 static void get_dom_info_recv_addrs(struct composite_context *ctx);
     36static void get_dom_info_recv_addrs(struct tevent_req *req);
    4137
    4238struct composite_context *wb_get_dom_info_send(TALLOC_CTX *mem_ctx,
    4339                                               struct wbsrv_service *service,
    4440                                               const char *domain_name,
     41                                               const char *dns_domain_name,
    4542                                               const struct dom_sid *sid)
    4643{
    47         struct composite_context *result, *ctx;
     44        struct composite_context *result;
     45        struct tevent_req *req;
    4846        struct get_dom_info_state *state;
    4947        struct dom_sid *dom_sid;
     48        struct finddcs finddcs_io;
     49
     50        DEBUG(5, ("wb_get_dom_info_send called\n"));
    5051        result = composite_create(mem_ctx, service->task->event_ctx);
    5152        if (result == NULL) goto failed;
     
    6869        if (dom_sid == NULL) goto failed;
    6970
    70         ctx = finddcs_send(mem_ctx, lp_netbios_name(service->task->lp_ctx),
    71                            lp_nbt_port(service->task->lp_ctx),
    72                            domain_name, NBT_NAME_LOGON,
    73                            dom_sid,
    74                            lp_iconv_convenience(service->task->lp_ctx),
    75                            lp_resolve_context(service->task->lp_ctx),
    76                            service->task->event_ctx,
    77                            service->task->msg_ctx);
    78         if (ctx == NULL) goto failed;
     71        ZERO_STRUCT(finddcs_io);
     72        finddcs_io.in.domain_name      = dns_domain_name;
     73        finddcs_io.in.domain_sid       = dom_sid;
     74        finddcs_io.in.minimum_dc_flags = NBT_SERVER_LDAP | NBT_SERVER_DS;
     75        if (service->sec_channel_type == SEC_CHAN_RODC) {
     76                finddcs_io.in.minimum_dc_flags |= NBT_SERVER_WRITABLE;
     77        }
    7978
    80         composite_continue(state->ctx, ctx, get_dom_info_recv_addrs, state);
     79        req = finddcs_cldap_send(mem_ctx, &finddcs_io,
     80                                 lpcfg_resolve_context(service->task->lp_ctx),
     81                                 service->task->event_ctx);
     82        if (req == NULL) goto failed;
     83
     84        tevent_req_set_callback(req, get_dom_info_recv_addrs, state);
     85
    8186        return result;
    8287
     
    8691}
    8792
    88 static void get_dom_info_recv_addrs(struct composite_context *ctx)
     93static void get_dom_info_recv_addrs(struct tevent_req *req)
    8994{
    90         struct get_dom_info_state *state =
    91                 talloc_get_type(ctx->async.private_data,
    92                                 struct get_dom_info_state);
     95        struct get_dom_info_state *state = tevent_req_callback_data(req, struct get_dom_info_state);
     96        struct finddcs finddcs_io;
    9397
    94         state->ctx->status = finddcs_recv(ctx, state->info,
    95                                           &state->info->num_dcs,
    96                                           &state->info->dcs);
     98        state->info->dc = talloc(state->info, struct nbt_dc_name);
     99
     100        state->ctx->status = finddcs_cldap_recv(req, state->info, &finddcs_io);
    97101        if (!composite_is_ok(state->ctx)) return;
     102
     103        if (finddcs_io.out.netlogon.ntver != NETLOGON_NT_VERSION_5EX) {
     104                /* the finddcs code should have mapped the response to
     105                   the type we want */
     106                DEBUG(0,(__location__ ": unexpected ntver 0x%08x in finddcs response\n",
     107                         finddcs_io.out.netlogon.ntver));
     108                state->ctx->status = NT_STATUS_UNEXPECTED_NETWORK_ERROR;
     109                if (!composite_is_ok(state->ctx)) return;
     110        }
     111
     112        state->info->dc->address = finddcs_io.out.address;
     113        state->info->dc->name    = finddcs_io.out.netlogon.data.nt5_ex.pdc_dns_name;
    98114
    99115        composite_done(state->ctx);
     
    118134                         struct wbsrv_service *service,
    119135                         const char *domain_name,
     136                         const char *dns_domain_name,
    120137                         const struct dom_sid *sid,
    121138                         struct wb_dom_info **result)
    122139{
    123140        struct composite_context *ctx =
    124                 wb_get_dom_info_send(mem_ctx, service, domain_name, sid);
     141                wb_get_dom_info_send(mem_ctx, service, domain_name, dns_domain_name, sid);
    125142        return wb_get_dom_info_recv(ctx, mem_ctx, result);
    126143}
  • trunk/server/source4/winbind/wb_dom_info_trusted.c

    r414 r745  
    2828#include "librpc/gen_ndr/ndr_netlogon_c.h"
    2929#include "libcli/libcli.h"
    30 #include "param/param.h"
    3130
    3231struct trusted_dom_info_state {
     
    4241
    4342static void trusted_dom_info_recv_domain(struct composite_context *ctx);
    44 static void trusted_dom_info_recv_dsr(struct rpc_request *req);
    45 static void trusted_dom_info_recv_dcname(struct rpc_request *req);
     43static void trusted_dom_info_recv_dsr(struct tevent_req *subreq);
     44static void trusted_dom_info_recv_dcname(struct tevent_req *subreq);
    4645static void trusted_dom_info_recv_dcaddr(struct composite_context *ctx);
    4746
     
    9089                talloc_get_type(ctx->async.private_data,
    9190                                struct trusted_dom_info_state);
    92         struct rpc_request *req;
     91        struct tevent_req *subreq;
    9392
    9493        state->ctx->status = wb_sid2domain_recv(ctx, &state->my_domain);
     
    108107        if (composite_nomem(state->d.out.info, state->ctx)) return;
    109108
    110         req = dcerpc_netr_DsRGetDCName_send(state->my_domain->netlogon_pipe,
    111                                             state, &state->d);
    112         composite_continue_rpc(state->ctx, req, trusted_dom_info_recv_dsr,
    113                                state);
     109        subreq = dcerpc_netr_DsRGetDCName_r_send(state,
     110                                                 state->ctx->event_ctx,
     111                                                 state->my_domain->netlogon_pipe->binding_handle,
     112                                                 &state->d);
     113        if (composite_nomem(subreq, state->ctx)) return;
     114        tevent_req_set_callback(subreq, trusted_dom_info_recv_dsr, state);
    114115}
    115116
     
    118119 */
    119120
    120 static void trusted_dom_info_recv_dsr(struct rpc_request *req)
    121 {
    122         struct trusted_dom_info_state *state =
    123                 talloc_get_type(req->async.private_data,
    124                                 struct trusted_dom_info_state);
    125 
    126         state->ctx->status = dcerpc_ndr_request_recv(req);
     121static void trusted_dom_info_recv_dsr(struct tevent_req *subreq)
     122{
     123        struct trusted_dom_info_state *state =
     124                tevent_req_callback_data(subreq,
     125                struct trusted_dom_info_state);
     126
     127        state->ctx->status = dcerpc_netr_DsRGetDCName_r_recv(subreq, state);
     128        TALLOC_FREE(subreq);
    127129        if (!NT_STATUS_IS_OK(state->ctx->status)) {
    128                 DEBUG(9, ("dcerpc_ndr_request_recv returned %s\n",
     130                DEBUG(9, ("dcerpc_netr_DsRGetDCName_recv returned %s\n",
    129131                          nt_errstr(state->ctx->status)));
    130132                goto fallback;
     
    140142
    141143        /* Hey, that was easy! */
    142         state->info->num_dcs = 1;
    143         state->info->dcs = talloc(state->info, struct nbt_dc_name);
    144         state->info->dcs[0].name = talloc_steal(state->info,
     144        state->info->dc = talloc(state->info, struct nbt_dc_name);
     145        state->info->dc->name = talloc_steal(state->info,
    145146                                            (*state->d.out.info)->dc_unc);
    146         if (*state->info->dcs[0].name == '\\') state->info->dcs[0].name++;
    147         if (*state->info->dcs[0].name == '\\') state->info->dcs[0].name++;
    148 
    149         state->info->dcs[0].address = talloc_steal(state->info,
     147        if (*state->info->dc->name == '\\') state->info->dc->name++;
     148        if (*state->info->dc->name == '\\') state->info->dc->name++;
     149
     150        state->info->dc->address = talloc_steal(state->info,
    150151                                               (*state->d.out.info)->dc_address);
    151         if (*state->info->dcs[0].address == '\\') state->info->dcs[0].address++;
    152         if (*state->info->dcs[0].address == '\\') state->info->dcs[0].address++;
     152        if (*state->info->dc->address == '\\') state->info->dc->address++;
     153        if (*state->info->dc->address == '\\') state->info->dc->address++;
    153154
    154155        state->info->dns_name = talloc_steal(state->info,
     
    166167        state->g.out.dcname = talloc(state, const char *);
    167168
    168         req = dcerpc_netr_GetAnyDCName_send(state->my_domain->netlogon_pipe,
    169                                             state, &state->g);
    170         if (composite_nomem(req, state->ctx)) return;
    171 
    172         composite_continue_rpc(state->ctx, req, trusted_dom_info_recv_dcname,
    173                                state);
    174 }
    175 
    176 static void trusted_dom_info_recv_dcname(struct rpc_request *req)
    177 {
    178         struct trusted_dom_info_state *state =
    179                 talloc_get_type(req->async.private_data,
    180                                 struct trusted_dom_info_state);
     169        subreq = dcerpc_netr_GetAnyDCName_r_send(state,
     170                                                 state->ctx->event_ctx,
     171                                                 state->my_domain->netlogon_pipe->binding_handle,
     172                                                 &state->g);
     173        if (composite_nomem(subreq, state->ctx)) return;
     174
     175        tevent_req_set_callback(subreq, trusted_dom_info_recv_dcname, state);
     176}
     177
     178static void trusted_dom_info_recv_dcname(struct tevent_req *subreq)
     179{
     180        struct trusted_dom_info_state *state =
     181                tevent_req_callback_data(subreq,
     182                struct trusted_dom_info_state);
    181183        struct composite_context *ctx;
    182184        struct nbt_name name;
    183185
    184         state->ctx->status = dcerpc_ndr_request_recv(req);
     186        state->ctx->status = dcerpc_netr_GetAnyDCName_r_recv(subreq, state);
     187        TALLOC_FREE(subreq);
    185188        if (!composite_is_ok(state->ctx)) return;
    186189        state->ctx->status = werror_to_ntstatus(state->g.out.result);
     
    188191
    189192        /* Hey, that was easy! */
    190         state->info->num_dcs = 1;
    191         state->info->dcs = talloc(state->info, struct nbt_dc_name);
    192         state->info->dcs[0].name = talloc_steal(state->info,
     193        state->info->dc = talloc(state->info, struct nbt_dc_name);
     194        state->info->dc->name = talloc_steal(state->info,
    193195                                            *(state->g.out.dcname));
    194         if (*state->info->dcs[0].name == '\\') state->info->dcs[0].name++;
    195         if (*state->info->dcs[0].name == '\\') state->info->dcs[0].name++;
     196        if (*state->info->dc->name == '\\') state->info->dc->name++;
     197        if (*state->info->dc->name == '\\') state->info->dc->name++;
    196198       
    197         make_nbt_name(&name, state->info->dcs[0].name, 0x20);
    198         ctx = resolve_name_send(lp_resolve_context(state->service->task->lp_ctx), state,
     199        make_nbt_name(&name, state->info->dc->name, 0x20);
     200        ctx = resolve_name_send(lpcfg_resolve_context(state->service->task->lp_ctx), state,
    199201                                &name, state->service->task->event_ctx);
    200202
     
    210212
    211213        state->ctx->status = resolve_name_recv(ctx, state->info,
    212                                                &state->info->dcs[0].address);
     214                                               &state->info->dc->address);
    213215        if (!composite_is_ok(state->ctx)) return;
    214216
  • trunk/server/source4/winbind/wb_gid2sid.c

    r414 r745  
    2424#include "winbind/wb_server.h"
    2525#include "smbd/service_task.h"
    26 #include "winbind/wb_helper.h"
    27 #include "libcli/security/proto.h"
    28 #include "winbind/idmap.h"
    2926
    3027struct gid2sid_state {
     
    4138        struct composite_context *result, *ctx;
    4239        struct gid2sid_state *state;
    43         struct unixid *unixid;
    44         struct id_mapping *ids;
     40        struct id_map *ids;
    4541
    4642        DEBUG(5, ("wb_gid2sid_send called\n"));
     
    5652        state->service = service;
    5753
    58         unixid = talloc(result, struct unixid);
    59         if (composite_nomem(unixid, result)) return result;
    60         unixid->id = gid;
    61         unixid->type = ID_TYPE_GID;
    62 
    63         ids = talloc(result, struct id_mapping);
     54        ids = talloc(result, struct id_map);
    6455        if (composite_nomem(ids, result)) return result;
    65         ids->unixid = unixid;
     56        ids->xid.id = gid;
     57        ids->xid.type = ID_TYPE_GID;
    6658        ids->sid = NULL;
    6759
     
    7769        struct gid2sid_state *state = talloc_get_type(ctx->async.private_data,
    7870                                                      struct gid2sid_state);
    79         struct id_mapping *ids = NULL;
     71        struct id_map *ids = NULL;
    8072        state->ctx->status = wb_xids2sids_recv(ctx, &ids);
    8173        if (!composite_is_ok(state->ctx)) return;
    8274
    83         if (!NT_STATUS_IS_OK(ids->status)) {
    84                 composite_error(state->ctx, ids->status);
     75        if (ids->status != ID_MAPPED) {
     76                composite_error(state->ctx, NT_STATUS_UNSUCCESSFUL);
    8577                return;
    8678        }
  • trunk/server/source4/winbind/wb_init_domain.c

    r414 r745  
    2323#include "includes.h"
    2424#include "libcli/composite/composite.h"
    25 #include "libcli/smb_composite/smb_composite.h"
    2625#include "winbind/wb_server.h"
    27 #include "winbind/wb_async_helpers.h"
    28 #include "winbind/wb_helper.h"
    2926#include "smbd/service_task.h"
    3027#include "librpc/gen_ndr/ndr_netlogon.h"
     
    3330#include "libcli/libcli.h"
    3431
    35 #include "libcli/auth/credentials.h"
    3632#include "libcli/security/security.h"
    3733
    38 #include "libcli/ldap/ldap_client.h"
    3934
    4035#include "auth/credentials/credentials.h"
     
    7671static void init_domain_recv_netlogonpipe(struct composite_context *ctx);
    7772static void init_domain_recv_lsa_pipe(struct composite_context *ctx);
    78 static void init_domain_recv_lsa_policy(struct rpc_request *req);
    79 static void init_domain_recv_queryinfo(struct rpc_request *req);
     73static void init_domain_recv_lsa_policy(struct tevent_req *subreq);
     74static void init_domain_recv_queryinfo(struct tevent_req *subreq);
    8075static void init_domain_recv_samr(struct composite_context *ctx);
    8176
     
    134129        if (state->domain->info == NULL) goto failed;
    135130
    136         /* Caller should check, but to be safe: */
    137         if (dom_info->num_dcs < 1) {
    138                 goto failed;
    139         }
    140        
    141         /* For now, we just pick the first.  The next step will be to
    142          * walk the entire list.  Also need to fix finddcs() to return
    143          * the entire list */
    144         state->domain->dc_name = dom_info->dcs[0].name;
    145         state->domain->dc_address = dom_info->dcs[0].address;
     131        state->domain->dc_name = dom_info->dc->name;
     132        state->domain->dc_address = dom_info->dc->address;
    146133
    147134        state->domain->libnet_ctx = libnet_context_init(service->task->event_ctx,
     
    164151
    165152        if ((!cli_credentials_is_anonymous(state->domain->libnet_ctx->cred)) &&
    166             ((lp_server_role(service->task->lp_ctx) == ROLE_DOMAIN_MEMBER) ||
    167              (lp_server_role(service->task->lp_ctx) == ROLE_DOMAIN_CONTROLLER)) &&
     153            ((lpcfg_server_role(service->task->lp_ctx) == ROLE_DOMAIN_MEMBER) ||
     154             (lpcfg_server_role(service->task->lp_ctx) == ROLE_DOMAIN_CONTROLLER)) &&
    168155            (dom_sid_equal(state->domain->info->sid,
    169156                           state->service->primary_sid))) {
     
    171158
    172159                /* For debugging, it can be a real pain if all the traffic is encrypted */
    173                 if (lp_winbind_sealed_pipes(service->task->lp_ctx)) {
     160                if (lpcfg_winbind_sealed_pipes(service->task->lp_ctx)) {
    174161                        state->domain->netlogon_binding->flags |= (DCERPC_SIGN | DCERPC_SEAL );
    175162                } else {
     
    217204
    218205        /* For debugging, it can be a real pain if all the traffic is encrypted */
    219         if (lp_winbind_sealed_pipes(state->service->task->lp_ctx)) {
     206        if (lpcfg_winbind_sealed_pipes(state->service->task->lp_ctx)) {
    220207                state->domain->lsa_binding->flags |= (DCERPC_SIGN | DCERPC_SEAL );
    221208        } else {
     
    270257static void init_domain_recv_lsa_pipe(struct composite_context *ctx)
    271258{
    272         struct rpc_request *req;
    273259        struct init_domain_state *state =
    274260                talloc_get_type(ctx->async.private_data,
    275261                                struct init_domain_state);
     262        struct tevent_req *subreq;
    276263
    277264        state->ctx->status = dcerpc_secondary_auth_connection_recv(ctx, state->domain,
     
    300287        state->lsa_openpolicy.out.handle = &state->domain->libnet_ctx->lsa.handle;
    301288
    302         req = dcerpc_lsa_OpenPolicy2_send(state->domain->libnet_ctx->lsa.pipe, state,
    303                                           &state->lsa_openpolicy);
    304 
    305         composite_continue_rpc(state->ctx, req, init_domain_recv_lsa_policy, state);
     289        subreq = dcerpc_lsa_OpenPolicy2_r_send(state,
     290                                               state->ctx->event_ctx,
     291                                               state->domain->libnet_ctx->lsa.pipe->binding_handle,
     292                                               &state->lsa_openpolicy);
     293        if (composite_nomem(subreq, state->ctx)) return;
     294        tevent_req_set_callback(subreq, init_domain_recv_lsa_policy, state);
    306295}
    307296
     
    309298 * obtain some basic information about the domain */
    310299
    311 static void init_domain_recv_lsa_policy(struct rpc_request *req)
     300static void init_domain_recv_lsa_policy(struct tevent_req *subreq)
    312301{
    313302        struct init_domain_state *state =
    314                 talloc_get_type(req->async.private_data,
    315                                 struct init_domain_state);
    316 
    317         state->ctx->status = dcerpc_ndr_request_recv(req);
     303                tevent_req_callback_data(subreq,
     304                struct init_domain_state);
     305
     306        state->ctx->status = dcerpc_lsa_OpenPolicy2_r_recv(subreq, state);
     307        TALLOC_FREE(subreq);
    318308        if ((!NT_STATUS_IS_OK(state->ctx->status)
    319309              || !NT_STATUS_IS_OK(state->lsa_openpolicy.out.result))) {
     
    335325        state->queryinfo.out.info = &state->info;
    336326
    337         req = dcerpc_lsa_QueryInfoPolicy_send(state->domain->libnet_ctx->lsa.pipe, state,
    338                                               &state->queryinfo);
    339         composite_continue_rpc(state->ctx, req,
    340                                init_domain_recv_queryinfo, state);
    341 }
    342 
    343 static void init_domain_recv_queryinfo(struct rpc_request *req)
     327        subreq = dcerpc_lsa_QueryInfoPolicy_r_send(state,
     328                                                   state->ctx->event_ctx,
     329                                                   state->domain->libnet_ctx->lsa.pipe->binding_handle,
     330                                                   &state->queryinfo);
     331        if (composite_nomem(subreq, state->ctx)) return;
     332        tevent_req_set_callback(subreq, init_domain_recv_queryinfo, state);
     333}
     334
     335static void init_domain_recv_queryinfo(struct tevent_req *subreq)
    344336{
    345337        struct init_domain_state *state =
    346                 talloc_get_type(req->async.private_data, struct init_domain_state);
     338                tevent_req_callback_data(subreq,
     339                struct init_domain_state);
    347340        struct lsa_DomainInfo *dominfo;
    348341        struct composite_context *ctx;
    349342
    350         state->ctx->status = dcerpc_ndr_request_recv(req);
     343        state->ctx->status = dcerpc_lsa_QueryInfoPolicy_r_recv(subreq, state);
     344        TALLOC_FREE(subreq);
    351345        if (!composite_is_ok(state->ctx)) return;
    352346        state->ctx->status = state->queryinfo.out.result;
  • trunk/server/source4/winbind/wb_irpc.c

    r414 r745  
    2323#include "lib/messaging/irpc.h"
    2424#include "libcli/composite/composite.h"
    25 #include "libcli/security/proto.h"
    2625#include "librpc/gen_ndr/ndr_winbind.h"
    2726#include "smbd/service_task.h"
     
    6968
    7069        status = wb_sam_logon_recv(ctx, s, s->req);
     70
     71        irpc_send_reply(s->msg, status);
     72}
     73
     74struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state {
     75        struct irpc_message *msg;
     76        struct winbind_DsrUpdateReadOnlyServerDnsRecords *req;
     77};
     78
     79static void wb_irpc_DsrUpdateReadOnlyServerDnsRecords_callback(struct composite_context *ctx);
     80
     81static NTSTATUS wb_irpc_DsrUpdateReadOnlyServerDnsRecords(struct irpc_message *msg,
     82                                 struct winbind_DsrUpdateReadOnlyServerDnsRecords *req)
     83{
     84        struct wbsrv_service *service = talloc_get_type(msg->private_data,
     85                                        struct wbsrv_service);
     86        struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state *s;
     87        struct composite_context *ctx;
     88
     89        DEBUG(5, ("wb_irpc_DsrUpdateReadOnlyServerDnsRecords called\n"));
     90
     91        s = talloc(msg, struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state);
     92        NT_STATUS_HAVE_NO_MEMORY(s);
     93
     94        s->msg = msg;
     95        s->req = req;
     96
     97        ctx = wb_update_rodc_dns_send(msg, service, req);
     98        NT_STATUS_HAVE_NO_MEMORY(ctx);
     99
     100        ctx->async.fn = wb_irpc_DsrUpdateReadOnlyServerDnsRecords_callback;
     101        ctx->async.private_data = s;
     102
     103        msg->defer_reply = true;
     104        return NT_STATUS_OK;
     105}
     106
     107static void wb_irpc_DsrUpdateReadOnlyServerDnsRecords_callback(struct composite_context *ctx)
     108{
     109        struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state *s = talloc_get_type(ctx->async.private_data,
     110                                           struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state);
     111        NTSTATUS status;
     112
     113        DEBUG(5, ("wb_irpc_DsrUpdateReadOnlyServerDnsRecords_callback called\n"));
     114
     115        status = wb_update_rodc_dns_recv(ctx, s, s->req);
    71116
    72117        irpc_send_reply(s->msg, status);
     
    87132                                        struct wbsrv_service);
    88133        struct wb_irpc_get_idmap_state *s;
    89         struct composite_context *ctx;
     134        struct composite_context *ctx = NULL;
    90135
    91136        DEBUG(5, ("wb_irpc_get_idmap called\n"));
     
    151196        NT_STATUS_NOT_OK_RETURN(status);
    152197
     198        status = IRPC_REGISTER(service->task->msg_ctx, winbind, WINBIND_DSRUPDATEREADONLYSERVERDNSRECORDS,
     199                               wb_irpc_DsrUpdateReadOnlyServerDnsRecords, service);
     200        NT_STATUS_NOT_OK_RETURN(status);
     201
    153202        status = IRPC_REGISTER(service->task->msg_ctx, winbind, WINBIND_GET_IDMAP,
    154203                               wb_irpc_get_idmap, service);
  • trunk/server/source4/winbind/wb_name2domain.c

    r414 r745  
    2525#include "smbd/service_task.h"
    2626#include "winbind/wb_helper.h"
    27 #include "param/param.h"
    2827
    2928struct name2domain_state {
  • trunk/server/source4/winbind/wb_pam_auth.c

    r414 r745  
    2828#include "libcli/auth/libcli_auth.h"
    2929#include "librpc/gen_ndr/ndr_netlogon.h"
    30 #include "librpc/gen_ndr/ndr_netlogon_c.h"
    3130#include "librpc/gen_ndr/winbind.h"
    3231#include "param/param.h"
     
    144143
    145144        ndr_err = ndr_push_struct_blob(
    146                 &tmp_blob, state, lp_iconv_convenience(state->lp_ctx),
    147                 state->req->out.validation.sam3,
     145                &tmp_blob, state, state->req->out.validation.sam3,
    148146                (ndr_push_flags_fn_t)ndr_push_netr_SamInfo3);
    149147        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     
    180178        state->unix_username = talloc_asprintf(state, "%s%s%s",
    181179                                               state->domain_name,
    182                                                lp_winbind_separator(state->lp_ctx),
     180                                               lpcfg_winbind_separator(state->lp_ctx),
    183181                                               state->user_name);
    184182        if (composite_nomem(state->unix_username, state->ctx)) return;
     
    222220        DATA_BLOB chal, nt_resp, lm_resp, names_blob;
    223221        int flags = CLI_CRED_NTLM_AUTH;
    224         if (lp_client_lanman_auth(service->task->lp_ctx)) {
     222        if (lpcfg_client_lanman_auth(service->task->lp_ctx)) {
    225223                flags |= CLI_CRED_LANMAN_AUTH;
    226224        }
    227225
    228         if (lp_client_ntlmv2_auth(service->task->lp_ctx)) {
     226        if (lpcfg_client_ntlmv2_auth(service->task->lp_ctx)) {
    229227                flags |= CLI_CRED_NTLMv2_AUTH;
    230228        }
     
    261259}
    262260
    263 NTSTATUS wb_cmd_pam_auth_recv(struct composite_context *c)
    264 {
    265        struct pam_auth_crap_state *state =
    266                talloc_get_type(c->private_data, struct pam_auth_crap_state);
    267        NTSTATUS status = composite_wait(c);
    268        talloc_free(state);
    269        return status;
    270 }
     261NTSTATUS wb_cmd_pam_auth_recv(struct composite_context *c,
     262                              TALLOC_CTX *mem_ctx,
     263                              DATA_BLOB *info3,
     264                              struct netr_UserSessionKey *user_session_key,
     265                              struct netr_LMSessionKey *lm_key,
     266                              char **unix_username)
     267{
     268        struct pam_auth_crap_state *state =
     269                talloc_get_type(c->private_data, struct pam_auth_crap_state);
     270        NTSTATUS status = composite_wait(c);
     271        if (NT_STATUS_IS_OK(status)) {
     272                if (info3) {
     273                        info3->length = state->info3.length;
     274                        info3->data = talloc_steal(mem_ctx, state->info3.data);
     275                }
     276                if (user_session_key) {
     277                        *user_session_key = state->user_session_key;
     278                }
     279                if (lm_key) {
     280                        *lm_key = state->lm_key;
     281                }
     282                if (unix_username) {
     283                        *unix_username = talloc_steal(mem_ctx, state->unix_username);
     284                }
     285        }
     286        talloc_free(state);
     287        return status;
     288}
  • trunk/server/source4/winbind/wb_sam_logon.c

    r414 r745  
    2828#include "auth/credentials/credentials.h"
    2929#include "libcli/auth/libcli_auth.h"
    30 #include "librpc/gen_ndr/ndr_netlogon.h"
    3130#include "librpc/gen_ndr/ndr_netlogon_c.h"
    3231#include "librpc/gen_ndr/winbind.h"
     
    4544
    4645static void wb_sam_logon_recv_domain(struct composite_context *ctx);
    47 static void wb_sam_logon_recv_samlogon(struct rpc_request *req);
     46static void wb_sam_logon_recv_samlogon(struct tevent_req *subreq);
    4847
    4948/*
     
    8079        struct wb_sam_logon_state *s = talloc_get_type(creq->async.private_data,
    8180                                       struct wb_sam_logon_state);
    82         struct rpc_request *req;
    8381        struct wbsrv_domain *domain;
     82        struct tevent_req *subreq;
    8483
    8584        s->ctx->status = wb_sid2domain_recv(creq, &domain);
     
    115114        if (composite_nomem(s->r_mem_ctx, s->ctx)) return;
    116115
    117         req = dcerpc_netr_LogonSamLogon_send(domain->netlogon_pipe, s->r_mem_ctx, &s->r);
    118         composite_continue_rpc(s->ctx, req, wb_sam_logon_recv_samlogon, s);
     116        subreq = dcerpc_netr_LogonSamLogon_r_send(s,
     117                                                  s->ctx->event_ctx,
     118                                                  domain->netlogon_pipe->binding_handle,
     119                                                  &s->r);
     120        if (composite_nomem(subreq, s->ctx)) return;
     121        tevent_req_set_callback(subreq, wb_sam_logon_recv_samlogon, s);
    119122}
    120123
     
    124127   Check the SamLogon reply and decrypt the session keys
    125128*/
    126 static void wb_sam_logon_recv_samlogon(struct rpc_request *req)
     129static void wb_sam_logon_recv_samlogon(struct tevent_req *subreq)
    127130{
    128         struct wb_sam_logon_state *s = talloc_get_type(req->async.private_data,
     131        struct wb_sam_logon_state *s = tevent_req_callback_data(subreq,
    129132                                       struct wb_sam_logon_state);
    130133
    131         s->ctx->status = dcerpc_ndr_request_recv(req);
     134        s->ctx->status = dcerpc_netr_LogonSamLogon_r_recv(subreq, s->r_mem_ctx);
     135        TALLOC_FREE(subreq);
    132136        if (!composite_is_ok(s->ctx)) return;
    133137
  • trunk/server/source4/winbind/wb_samba3_cmd.c

    r414 r745  
    2424#include "includes.h"
    2525#include "winbind/wb_server.h"
    26 #include "winbind/wb_async_helpers.h"
    2726#include "param/param.h"
    2827#include "winbind/wb_helper.h"
    2928#include "libcli/composite/composite.h"
    3029#include "version.h"
    31 #include "librpc/gen_ndr/netlogon.h"
     30#include "librpc/gen_ndr/ndr_netlogon.h"
    3231#include "libcli/security/security.h"
    33 #include "auth/ntlm/pam_errors.h"
     32#include "../libcli/auth/pam_errors.h"
    3433#include "auth/credentials/credentials.h"
    3534#include "smbd/service_task.h"
     35
     36/*
     37  support the old Samba3 TXT form of the info3
     38 */
     39static NTSTATUS wb_samba3_append_info3_as_txt(TALLOC_CTX *mem_ctx,
     40                                              struct wbsrv_samba3_call *s3call,
     41                                              DATA_BLOB info3b)
     42{
     43        struct netr_SamInfo3 *info3;
     44        char *ex;
     45        uint32_t i;
     46        enum ndr_err_code ndr_err;
     47
     48        info3 = talloc(mem_ctx, struct netr_SamInfo3);
     49        NT_STATUS_HAVE_NO_MEMORY(info3);
     50
     51        /* The Samba3 protocol has a redundent 4 bytes at the start */
     52        info3b.data += 4;
     53        info3b.length -= 4;
     54
     55        ndr_err = ndr_pull_struct_blob(&info3b,
     56                                       mem_ctx,
     57                                       info3,
     58                                       (ndr_pull_flags_fn_t)ndr_pull_netr_SamInfo3);
     59        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     60                return ndr_map_error2ntstatus(ndr_err);
     61        }
     62
     63        s3call->response->data.auth.info3.logon_time =
     64                nt_time_to_unix(info3->base.last_logon);
     65        s3call->response->data.auth.info3.logoff_time =
     66                nt_time_to_unix(info3->base.last_logoff);
     67        s3call->response->data.auth.info3.kickoff_time =
     68                nt_time_to_unix(info3->base.acct_expiry);
     69        s3call->response->data.auth.info3.pass_last_set_time =
     70                nt_time_to_unix(info3->base.last_password_change);
     71        s3call->response->data.auth.info3.pass_can_change_time =
     72                nt_time_to_unix(info3->base.allow_password_change);
     73        s3call->response->data.auth.info3.pass_must_change_time =
     74                nt_time_to_unix(info3->base.force_password_change);
     75
     76        s3call->response->data.auth.info3.logon_count = info3->base.logon_count;
     77        s3call->response->data.auth.info3.bad_pw_count = info3->base.bad_password_count;
     78
     79        s3call->response->data.auth.info3.user_rid = info3->base.rid;
     80        s3call->response->data.auth.info3.group_rid = info3->base.primary_gid;
     81        fstrcpy(s3call->response->data.auth.info3.dom_sid, dom_sid_string(mem_ctx, info3->base.domain_sid));
     82
     83        s3call->response->data.auth.info3.num_groups = info3->base.groups.count;
     84        s3call->response->data.auth.info3.user_flgs = info3->base.user_flags;
     85
     86        s3call->response->data.auth.info3.acct_flags = info3->base.acct_flags;
     87        s3call->response->data.auth.info3.num_other_sids = info3->sidcount;
     88
     89        fstrcpy(s3call->response->data.auth.info3.user_name,
     90                info3->base.account_name.string);
     91        fstrcpy(s3call->response->data.auth.info3.full_name,
     92                info3->base.full_name.string);
     93        fstrcpy(s3call->response->data.auth.info3.logon_script,
     94                info3->base.logon_script.string);
     95        fstrcpy(s3call->response->data.auth.info3.profile_path,
     96                info3->base.profile_path.string);
     97        fstrcpy(s3call->response->data.auth.info3.home_dir,
     98                info3->base.home_directory.string);
     99        fstrcpy(s3call->response->data.auth.info3.dir_drive,
     100                info3->base.home_drive.string);
     101
     102        fstrcpy(s3call->response->data.auth.info3.logon_srv,
     103                info3->base.logon_server.string);
     104        fstrcpy(s3call->response->data.auth.info3.logon_dom,
     105                info3->base.domain.string);
     106
     107        ex = talloc_strdup(mem_ctx, "");
     108        NT_STATUS_HAVE_NO_MEMORY(ex);
     109
     110        for (i=0; i < info3->base.groups.count; i++) {
     111                ex = talloc_asprintf_append_buffer(ex, "0x%08X:0x%08X\n",
     112                                                   info3->base.groups.rids[i].rid,
     113                                                   info3->base.groups.rids[i].attributes);
     114                NT_STATUS_HAVE_NO_MEMORY(ex);
     115        }
     116
     117        for (i=0; i < info3->sidcount; i++) {
     118                char *sid;
     119
     120                sid = dom_sid_string(mem_ctx, info3->sids[i].sid);
     121                NT_STATUS_HAVE_NO_MEMORY(sid);
     122
     123                ex = talloc_asprintf_append_buffer(ex, "%s:0x%08X\n",
     124                                                   sid,
     125                                                   info3->sids[i].attributes);
     126                NT_STATUS_HAVE_NO_MEMORY(ex);
     127
     128                talloc_free(sid);
     129        }
     130
     131        s3call->response->extra_data.data = ex;
     132        s3call->response->length += talloc_get_size(ex);
     133
     134        return NT_STATUS_OK;
     135}
    36136
    37137/*
     
    42142                                             struct wbsrv_samba3_call *s3call)
    43143{
    44         struct winbindd_response *resp = &s3call->response;
     144        struct winbindd_response *resp = s3call->response;
    45145        if (!NT_STATUS_IS_OK(status)) {
    46146                resp->result = WINBINDD_ERROR;
     
    67167                                        struct wbsrv_samba3_call *s3call)
    68168{
    69         struct winbindd_response *resp = &s3call->response;
     169        struct winbindd_response *resp = s3call->response;
    70170        if (NT_STATUS_IS_OK(status)) {
    71171                resp->result = WINBINDD_OK;
     
    83183NTSTATUS wbsrv_samba3_interface_version(struct wbsrv_samba3_call *s3call)
    84184{
    85         s3call->response.result                 = WINBINDD_OK;
    86         s3call->response.data.interface_version = WINBIND_INTERFACE_VERSION;
     185        s3call->response->result                        = WINBINDD_OK;
     186        s3call->response->data.interface_version        = WINBIND_INTERFACE_VERSION;
    87187        return NT_STATUS_OK;
    88188}
     
    90190NTSTATUS wbsrv_samba3_info(struct wbsrv_samba3_call *s3call)
    91191{
    92         s3call->response.result                 = WINBINDD_OK;
    93         s3call->response.data.info.winbind_separator = *lp_winbind_separator(s3call->wbconn->lp_ctx);
    94         WBSRV_SAMBA3_SET_STRING(s3call->response.data.info.samba_version,
     192        s3call->response->result                        = WINBINDD_OK;
     193        s3call->response->data.info.winbind_separator = *lpcfg_winbind_separator(s3call->wbconn->lp_ctx);
     194        WBSRV_SAMBA3_SET_STRING(s3call->response->data.info.samba_version,
    95195                                SAMBA_VERSION_STRING);
    96196        return NT_STATUS_OK;
     
    99199NTSTATUS wbsrv_samba3_domain_name(struct wbsrv_samba3_call *s3call)
    100200{
    101         s3call->response.result                 = WINBINDD_OK;
    102         WBSRV_SAMBA3_SET_STRING(s3call->response.data.domain_name,
    103                                 lp_workgroup(s3call->wbconn->lp_ctx));
     201        s3call->response->result                        = WINBINDD_OK;
     202        WBSRV_SAMBA3_SET_STRING(s3call->response->data.domain_name,
     203                                lpcfg_workgroup(s3call->wbconn->lp_ctx));
    104204        return NT_STATUS_OK;
    105205}
     
    107207NTSTATUS wbsrv_samba3_netbios_name(struct wbsrv_samba3_call *s3call)
    108208{
    109         s3call->response.result                 = WINBINDD_OK;
    110         WBSRV_SAMBA3_SET_STRING(s3call->response.data.netbios_name,
    111                                 lp_netbios_name(s3call->wbconn->lp_ctx));
     209        s3call->response->result                        = WINBINDD_OK;
     210        WBSRV_SAMBA3_SET_STRING(s3call->response->data.netbios_name,
     211                                lpcfg_netbios_name(s3call->wbconn->lp_ctx));
    112212        return NT_STATUS_OK;
    113213}
     
    115215NTSTATUS wbsrv_samba3_priv_pipe_dir(struct wbsrv_samba3_call *s3call)
    116216{
    117         const char *path = s3call->wbconn->listen_socket->service->priv_socket_path;
    118         s3call->response.result          = WINBINDD_OK;
    119         s3call->response.extra_data.data = discard_const(path);
    120 
    121         s3call->response.length += strlen(path) + 1;
     217        struct loadparm_context *lp_ctx = s3call->wbconn->listen_socket->service->task->lp_ctx;
     218        const char *priv_socket_dir = lpcfg_winbindd_privileged_socket_directory(lp_ctx);
     219
     220        s3call->response->result                 = WINBINDD_OK;
     221        s3call->response->extra_data.data = discard_const(priv_socket_dir);
     222
     223        s3call->response->length += strlen(priv_socket_dir) + 1;
    122224        return NT_STATUS_OK;
    123225}
     
    125227NTSTATUS wbsrv_samba3_ping(struct wbsrv_samba3_call *s3call)
    126228{
    127         s3call->response.result                 = WINBINDD_OK;
     229        s3call->response->result                        = WINBINDD_OK;
    128230        return NT_STATUS_OK;
    129231}
     
    132234{
    133235        DEBUG(5, ("wbsrv_samba3_domain_info called, stub\n"));
    134         s3call->response.result = WINBINDD_OK;
    135         fstrcpy(s3call->response.data.domain_info.name,
    136                 s3call->request.domain_name);
    137         fstrcpy(s3call->response.data.domain_info.alt_name,
    138                 s3call->request.domain_name);
    139         fstrcpy(s3call->response.data.domain_info.sid, "S-1-2-3-4");
    140         s3call->response.data.domain_info.native_mode = false;
    141         s3call->response.data.domain_info.active_directory = false;
    142         s3call->response.data.domain_info.primary = false;
     236        s3call->response->result = WINBINDD_OK;
     237        fstrcpy(s3call->response->data.domain_info.name,
     238                s3call->request->domain_name);
     239        fstrcpy(s3call->response->data.domain_info.alt_name,
     240                s3call->request->domain_name);
     241        fstrcpy(s3call->response->data.domain_info.sid, "S-1-2-3-4");
     242        s3call->response->data.domain_info.native_mode = false;
     243        s3call->response->data.domain_info.active_directory = false;
     244        s3call->response->data.domain_info.primary = false;
    143245
    144246        return NT_STATUS_OK;
     
    197299        NTSTATUS status;
    198300
    199         status = wb_cmd_pam_auth_recv(ctx);
     301        status = wb_cmd_pam_auth_recv(ctx, s3call, NULL, NULL, NULL, NULL);
    200302
    201303        if (!NT_STATUS_IS_OK(status)) goto done;
     
    221323
    222324        ctx = wb_cmd_getdcname_send(s3call, service,
    223                                     s3call->request.domain_name);
     325                                    s3call->request->domain_name);
    224326        NT_STATUS_HAVE_NO_MEMORY(ctx);
    225327
     
    241343        if (!NT_STATUS_IS_OK(status)) goto done;
    242344
    243         s3call->response.result = WINBINDD_OK;
    244         WBSRV_SAMBA3_SET_STRING(s3call->response.data.dc_name, dcname);
     345        s3call->response->result = WINBINDD_OK;
     346        WBSRV_SAMBA3_SET_STRING(s3call->response->data.dc_name, dcname);
    245347
    246348 done:
     
    261363        DEBUG(5, ("wbsrv_samba3_userdomgroups called\n"));
    262364
    263         sid = dom_sid_parse_talloc(s3call, s3call->request.data.sid);
     365        sid = dom_sid_parse_talloc(s3call, s3call->request->data.sid);
    264366        if (sid == NULL) {
    265367                DEBUG(5, ("Could not parse sid %s\n",
    266                           s3call->request.data.sid));
     368                          s3call->request->data.sid));
    267369                return NT_STATUS_NO_MEMORY;
    268370        }
     
    283385                talloc_get_type(ctx->async.private_data,
    284386                                struct wbsrv_samba3_call);
    285         int i, num_sids;
     387        uint32_t i, num_sids;
    286388        struct dom_sid **sids;
    287389        char *sids_string;
     
    307409        }
    308410
    309         s3call->response.result = WINBINDD_OK;
    310         s3call->response.extra_data.data = sids_string;
    311         s3call->response.length += strlen(sids_string)+1;
    312         s3call->response.data.num_entries = num_sids;
     411        s3call->response->result = WINBINDD_OK;
     412        s3call->response->extra_data.data = sids_string;
     413        s3call->response->length += strlen(sids_string)+1;
     414        s3call->response->data.num_entries = num_sids;
    313415
    314416 done:
     
    328430        DEBUG(5, ("wbsrv_samba3_usersids called\n"));
    329431
    330         sid = dom_sid_parse_talloc(s3call, s3call->request.data.sid);
     432        sid = dom_sid_parse_talloc(s3call, s3call->request->data.sid);
    331433        if (sid == NULL) {
    332434                DEBUG(5, ("Could not parse sid %s\n",
    333                           s3call->request.data.sid));
     435                          s3call->request->data.sid));
    334436                return NT_STATUS_NO_MEMORY;
    335437        }
     
    350452                talloc_get_type(ctx->async.private_data,
    351453                                struct wbsrv_samba3_call);
    352         int i, num_sids;
     454        uint32_t i, num_sids;
    353455        struct dom_sid **sids;
    354456        char *sids_string;
     
    373475        }
    374476
    375         s3call->response.result = WINBINDD_OK;
    376         s3call->response.extra_data.data = sids_string;
    377         s3call->response.length += strlen(sids_string);
    378         s3call->response.data.num_entries = num_sids;
     477        s3call->response->result = WINBINDD_OK;
     478        s3call->response->extra_data.data = sids_string;
     479        s3call->response->length += strlen(sids_string);
     480        s3call->response->data.num_entries = num_sids;
    379481
    380482        /* Hmmmm. Nasty protocol -- who invented the zeros between the
     
    407509
    408510        ctx = wb_cmd_lookupname_send(s3call, service,
    409                                      s3call->request.data.name.dom_name,
    410                                      s3call->request.data.name.name);
     511                                     s3call->request->data.name.dom_name,
     512                                     s3call->request->data.name.name);
    411513        NT_STATUS_HAVE_NO_MEMORY(ctx);
    412514
     
    429531        if (!NT_STATUS_IS_OK(status)) goto done;
    430532
    431         s3call->response.result = WINBINDD_OK;
    432         s3call->response.data.sid.type = sid->type;
    433         WBSRV_SAMBA3_SET_STRING(s3call->response.data.sid.sid,
     533        s3call->response->result = WINBINDD_OK;
     534        s3call->response->data.sid.type = sid->type;
     535        WBSRV_SAMBA3_SET_STRING(s3call->response->data.sid.sid,
    434536                                dom_sid_string(s3call, sid->sid));
    435537
     
    453555        DEBUG(5, ("wbsrv_samba3_lookupsid called\n"));
    454556
    455         sid = dom_sid_parse_talloc(s3call, s3call->request.data.sid);
     557        sid = dom_sid_parse_talloc(s3call, s3call->request->data.sid);
    456558        if (sid == NULL) {
    457559                DEBUG(5, ("Could not parse sid %s\n",
    458                           s3call->request.data.sid));
     560                          s3call->request->data.sid));
    459561                return NT_STATUS_NO_MEMORY;
    460562        }
     
    481583        if (!NT_STATUS_IS_OK(status)) goto done;
    482584
    483         s3call->response.result = WINBINDD_OK;
    484         s3call->response.data.name.type = sid->type;
    485         WBSRV_SAMBA3_SET_STRING(s3call->response.data.name.dom_name,
     585        s3call->response->result = WINBINDD_OK;
     586        s3call->response->data.name.type = sid->type;
     587        WBSRV_SAMBA3_SET_STRING(s3call->response->data.name.dom_name,
    486588                                sid->domain);
    487         WBSRV_SAMBA3_SET_STRING(s3call->response.data.name.name, sid->name);
     589        WBSRV_SAMBA3_SET_STRING(s3call->response->data.name.name, sid->name);
    488590
    489591 done:
    490592        wbsrv_samba3_async_epilogue(status, s3call);
     593}
     594
     595/*
     596  This is a stub function in order to limit error message in the pam_winbind module
     597*/
     598NTSTATUS wbsrv_samba3_pam_logoff(struct wbsrv_samba3_call *s3call)
     599{
     600        NTSTATUS status;
     601        struct winbindd_response *resp = s3call->response;
     602
     603        status = NT_STATUS_OK;
     604
     605        DEBUG(5, ("wbsrv_samba3_pam_logoff called\n"));
     606        DEBUG(10, ("Winbind logoff not implemented\n"));
     607        resp->result = WINBINDD_OK;
     608
     609        WBSRV_SAMBA3_SET_STRING(resp->data.auth.nt_status_string,
     610                                nt_errstr(status));
     611        WBSRV_SAMBA3_SET_STRING(resp->data.auth.error_string,
     612                                get_friendly_nt_error_msg(status));
     613
     614        resp->data.auth.pam_error = nt_status_to_pam(status);
     615        resp->data.auth.nt_status = NT_STATUS_V(status);
     616        DEBUG(5, ("wbsrv_samba3_pam_logoff called\n"));
     617
     618        return NT_STATUS_OK;
    491619}
    492620
     
    512640        DEBUG(5, ("wbsrv_samba3_pam_auth_crap called\n"));
    513641
    514         chal.data       = s3call->request.data.auth_crap.chal;
    515         chal.length     = sizeof(s3call->request.data.auth_crap.chal);
    516         nt_resp.data    = (uint8_t *)s3call->request.data.auth_crap.nt_resp;
    517         nt_resp.length  = s3call->request.data.auth_crap.nt_resp_len;
    518         lm_resp.data    = (uint8_t *)s3call->request.data.auth_crap.lm_resp;
    519         lm_resp.length  = s3call->request.data.auth_crap.lm_resp_len;
     642        chal.data       = s3call->request->data.auth_crap.chal;
     643        chal.length     = sizeof(s3call->request->data.auth_crap.chal);
     644        nt_resp.data    = (uint8_t *)s3call->request->data.auth_crap.nt_resp;
     645        nt_resp.length  = s3call->request->data.auth_crap.nt_resp_len;
     646        lm_resp.data    = (uint8_t *)s3call->request->data.auth_crap.lm_resp;
     647        lm_resp.length  = s3call->request->data.auth_crap.lm_resp_len;
    520648
    521649        ctx = wb_cmd_pam_auth_crap_send(
    522650                s3call, service,
    523                 s3call->request.data.auth_crap.logon_parameters,
    524                 s3call->request.data.auth_crap.domain,
    525                 s3call->request.data.auth_crap.user,
    526                 s3call->request.data.auth_crap.workstation,
     651                s3call->request->data.auth_crap.logon_parameters,
     652                s3call->request->data.auth_crap.domain,
     653                s3call->request->data.auth_crap.user,
     654                s3call->request->data.auth_crap.workstation,
    527655                chal, nt_resp, lm_resp);
    528656        NT_STATUS_HAVE_NO_MEMORY(ctx);
     
    549677        if (!NT_STATUS_IS_OK(status)) goto done;
    550678
    551         if (s3call->request.flags & WBFLAG_PAM_USER_SESSION_KEY) {
    552                 memcpy(s3call->response.data.auth.user_session_key,
     679        if (s3call->request->flags & WBFLAG_PAM_USER_SESSION_KEY) {
     680                memcpy(s3call->response->data.auth.user_session_key,
    553681                       &user_session_key.key,
    554                        sizeof(s3call->response.data.auth.user_session_key));
    555         }
    556 
    557         if (s3call->request.flags & WBFLAG_PAM_INFO3_NDR) {
    558                 s3call->response.extra_data.data = info3.data;
    559                 s3call->response.length += info3.length;
    560         }
    561 
    562         if (s3call->request.flags & WBFLAG_PAM_LMKEY) {
    563                 memcpy(s3call->response.data.auth.first_8_lm_hash,
     682                       sizeof(s3call->response->data.auth.user_session_key));
     683        }
     684
     685        if (s3call->request->flags & WBFLAG_PAM_INFO3_TEXT) {
     686                status = wb_samba3_append_info3_as_txt(ctx, s3call, info3);
     687                if (!NT_STATUS_IS_OK(status)) {
     688                        DEBUG(10,("Failed to append INFO3 (TXT): %s\n",
     689                                  nt_errstr(status)));
     690                        goto done;
     691                }
     692        }
     693
     694        if (s3call->request->flags & WBFLAG_PAM_INFO3_NDR) {
     695                s3call->response->extra_data.data = info3.data;
     696                s3call->response->length += info3.length;
     697        }
     698
     699        if (s3call->request->flags & WBFLAG_PAM_LMKEY) {
     700                memcpy(s3call->response->data.auth.first_8_lm_hash,
    564701                       lm_key.key,
    565                        sizeof(s3call->response.data.auth.first_8_lm_hash));
     702                       sizeof(s3call->response->data.auth.first_8_lm_hash));
    566703        }
    567704       
    568         if (s3call->request.flags & WBFLAG_PAM_UNIX_NAME) {
    569                 s3call->response.extra_data.data = unix_username;
    570                 s3call->response.length += strlen(unix_username)+1;
     705        if (s3call->request->flags & WBFLAG_PAM_UNIX_NAME) {
     706                WBSRV_SAMBA3_SET_STRING(s3call->response->data.auth.unix_username,unix_username);
    571707        }
    572708
     
    593729
    594730        if (!wb_samba3_split_username(s3call, s3call->wbconn->lp_ctx,
    595                                  s3call->request.data.auth.user,
     731                                 s3call->request->data.auth.user,
    596732                                 &domain, &user)) {
    597733                return NT_STATUS_NO_SUCH_USER;
     
    606742        cli_credentials_set_username(credentials, user, CRED_SPECIFIED);
    607743
    608         cli_credentials_set_password(credentials, s3call->request.data.auth.pass, CRED_SPECIFIED);
     744        cli_credentials_set_password(credentials, s3call->request->data.auth.pass, CRED_SPECIFIED);
    609745
    610746        ctx = wb_cmd_pam_auth_send(s3call, service, credentials);
     
    623759                                struct wbsrv_samba3_call);
    624760        NTSTATUS status;
    625 
    626         status = wb_cmd_pam_auth_recv(ctx);
     761        DATA_BLOB info3;
     762        struct netr_UserSessionKey user_session_key;
     763        struct netr_LMSessionKey lm_key;
     764        char *unix_username;
     765
     766        status = wb_cmd_pam_auth_recv(ctx, s3call, &info3,
     767                                      &user_session_key, &lm_key, &unix_username);
    627768
    628769        if (!NT_STATUS_IS_OK(status)) goto done;
     770
     771        if (s3call->request->flags & WBFLAG_PAM_USER_SESSION_KEY) {
     772                memcpy(s3call->response->data.auth.user_session_key,
     773                       &user_session_key.key,
     774                       sizeof(s3call->response->data.auth.user_session_key));
     775        }
     776
     777        if (s3call->request->flags & WBFLAG_PAM_INFO3_TEXT) {
     778                status = wb_samba3_append_info3_as_txt(ctx, s3call, info3);
     779                if (!NT_STATUS_IS_OK(status)) {
     780                        DEBUG(10,("Failed to append INFO3 (TXT): %s\n",
     781                                  nt_errstr(status)));
     782                        goto done;
     783                }
     784        }
     785
     786        if (s3call->request->flags & WBFLAG_PAM_INFO3_NDR) {
     787                s3call->response->extra_data.data = info3.data;
     788                s3call->response->length += info3.length;
     789        }
     790
     791        if (s3call->request->flags & WBFLAG_PAM_LMKEY) {
     792                memcpy(s3call->response->data.auth.first_8_lm_hash,
     793                       lm_key.key,
     794                       sizeof(s3call->response->data.auth.first_8_lm_hash));
     795        }
     796       
     797        if (s3call->request->flags & WBFLAG_PAM_UNIX_NAME) {
     798                WBSRV_SAMBA3_SET_STRING(s3call->response->data.auth.unix_username,unix_username);
     799        }
     800       
    629801
    630802 done:
     
    660832                talloc_get_type(ctx->async.private_data,
    661833                                struct wbsrv_samba3_call);
    662         int i, num_domains;
     834        uint32_t i, num_domains;
    663835        struct wb_dom_info **domains;
    664836        NTSTATUS status;
     
    687859        }
    688860
    689         s3call->response.result = WINBINDD_OK;
     861        s3call->response->result = WINBINDD_OK;
    690862        if (num_domains > 0) {
    691                 s3call->response.extra_data.data = result;
    692                 s3call->response.length += strlen(result)+1;
     863                s3call->response->extra_data.data = result;
     864                s3call->response->length += strlen(result)+1;
     865                s3call->response->data.num_entries = num_domains;
    693866        }
    694867
     
    708881
    709882        ctx = wb_cmd_list_groups_send(s3call, service,
    710                                       s3call->request.domain_name);
     883                                      s3call->request->domain_name);
    711884        NT_STATUS_HAVE_NO_MEMORY(ctx);
    712885
     
    724897        uint32_t extra_data_len;
    725898        char *extra_data;
     899        uint32_t num_groups;
    726900        NTSTATUS status;
    727901
     
    729903
    730904        status = wb_cmd_list_groups_recv(ctx, s3call, &extra_data_len,
    731                         &extra_data);
     905                        &extra_data, &num_groups);
    732906
    733907        if (NT_STATUS_IS_OK(status)) {
    734                 s3call->response.extra_data.data = extra_data;
    735                 s3call->response.length += extra_data_len;
     908                s3call->response->extra_data.data = extra_data;
     909                s3call->response->length += extra_data_len;
    736910                if (extra_data) {
    737                         s3call->response.length += 1;
     911                        s3call->response->length += 1;
     912                        s3call->response->data.num_entries = num_groups;
    738913                }
    739914        }
     
    755930
    756931        ctx = wb_cmd_list_users_send(s3call, service,
    757                         s3call->request.domain_name);
     932                        s3call->request->domain_name);
    758933        NT_STATUS_HAVE_NO_MEMORY(ctx);
    759934
     
    771946        uint32_t extra_data_len;
    772947        char *extra_data;
     948        uint32_t num_users;
    773949        NTSTATUS status;
    774950
     
    776952
    777953        status = wb_cmd_list_users_recv(ctx, s3call, &extra_data_len,
    778                         &extra_data);
     954                        &extra_data, &num_users);
    779955
    780956        if (NT_STATUS_IS_OK(status)) {
    781                 s3call->response.extra_data.data = extra_data;
    782                 s3call->response.length += extra_data_len;
     957                s3call->response->extra_data.data = extra_data;
     958                s3call->response->length += extra_data_len;
    783959                if (extra_data) {
    784                         s3call->response.length += 1;
     960                        s3call->response->length += 1;
     961                        s3call->response->data.num_entries = num_users;
    785962                }
    786963        }
     
    802979
    803980        ctx = wb_cmd_getpwnam_send(s3call, service,
    804                         s3call->request.data.username);
     981                        s3call->request->data.username);
    805982        NT_STATUS_HAVE_NO_MEMORY(ctx);
    806983
     
    8231000        status = wb_cmd_getpwnam_recv(ctx, s3call, &pw);
    8241001        if(NT_STATUS_IS_OK(status))
    825                 s3call->response.data.pw = *pw;
     1002                s3call->response->data.pw = *pw;
    8261003
    8271004        wbsrv_samba3_async_epilogue(status, s3call);
     
    8381015
    8391016        ctx = wb_cmd_getpwuid_send(s3call, service,
    840                         s3call->request.data.uid);
     1017                        s3call->request->data.uid);
    8411018        NT_STATUS_HAVE_NO_MEMORY(ctx);
    8421019
     
    8591036        status = wb_cmd_getpwuid_recv(ctx, s3call, &pw);
    8601037        if (NT_STATUS_IS_OK(status))
    861                 s3call->response.data.pw = *pw;
     1038                s3call->response->data.pw = *pw;
    8621039
    8631040        wbsrv_samba3_async_epilogue(status, s3call);
     
    9171094
    9181095        ctx = wb_cmd_getpwent_send(s3call, service, pwent,
    919                         s3call->request.data.num_entries);
     1096                        s3call->request->data.num_entries);
    9201097        NT_STATUS_HAVE_NO_MEMORY(ctx);
    9211098
     
    9411118                uint32_t extra_len = sizeof(struct winbindd_pw) * num_users;
    9421119
    943                 s3call->response.data.num_entries = num_users;
    944                 s3call->response.extra_data.data = pw;
    945                 s3call->response.length += extra_len;
     1120                s3call->response->data.num_entries = num_users;
     1121                s3call->response->extra_data.data = pw;
     1122                s3call->response->length += extra_len;
    9461123        }
    9471124
     
    9591136
    9601137        s3call->wbconn->protocol_private_data = NULL;
    961         s3call->response.result = WINBINDD_OK;
     1138        s3call->response->result = WINBINDD_OK;
    9621139        return NT_STATUS_OK;
    9631140}
     
    9751152
    9761153        ctx = wb_cmd_getgrnam_send(s3call, service,
    977                         s3call->request.data.groupname);
     1154                        s3call->request->data.groupname);
    9781155        NT_STATUS_HAVE_NO_MEMORY(ctx);
    9791156
     
    9961173        status = wb_cmd_getgrnam_recv(ctx, s3call, &gr);
    9971174        if(NT_STATUS_IS_OK(status))
    998                 s3call->response.data.gr = *gr;
     1175                s3call->response->data.gr = *gr;
    9991176
    10001177        wbsrv_samba3_async_epilogue(status, s3call);
     
    10111188
    10121189        ctx = wb_cmd_getgrgid_send(s3call, service,
    1013                         s3call->request.data.gid);
     1190                        s3call->request->data.gid);
    10141191        NT_STATUS_HAVE_NO_MEMORY(ctx);
    10151192
     
    10321209        status = wb_cmd_getgrgid_recv(ctx, s3call, &gr);
    10331210        if (NT_STATUS_IS_OK(status))
    1034                 s3call->response.data.gr = *gr;
    1035 
    1036         wbsrv_samba3_async_epilogue(status, s3call);
    1037 }
     1211                s3call->response->data.gr = *gr;
     1212
     1213        wbsrv_samba3_async_epilogue(status, s3call);
     1214}
     1215
     1216static void getgroups_recv(struct composite_context *ctx);
    10381217
    10391218NTSTATUS wbsrv_samba3_getgroups(struct wbsrv_samba3_call *s3call)
    10401219{
     1220        struct composite_context *ctx;
     1221        struct wbsrv_service *service = s3call->wbconn->listen_socket->service;
     1222
    10411223        DEBUG(5, ("wbsrv_samba3_getgroups called\n"));
    1042         s3call->response.result = WINBINDD_ERROR;
    1043         return NT_STATUS_OK;
    1044 }
     1224        /* S3 code do the same so why not ... */
     1225        s3call->request->data.username[sizeof(s3call->request->data.username)-1]='\0';
     1226        ctx = wb_cmd_getgroups_send(s3call, service, s3call->request->data.username);
     1227        NT_STATUS_HAVE_NO_MEMORY(ctx);
     1228
     1229        ctx->async.fn = getgroups_recv;
     1230        ctx->async.private_data = s3call;
     1231        s3call->flags |= WBSRV_CALL_FLAGS_REPLY_ASYNC;
     1232        return NT_STATUS_OK;
     1233}
     1234
     1235static void getgroups_recv(struct composite_context *ctx)
     1236{
     1237        struct wbsrv_samba3_call *s3call =
     1238                talloc_get_type(ctx->async.private_data,
     1239                                struct wbsrv_samba3_call);
     1240        gid_t *gids;
     1241        uint32_t num_groups;
     1242        NTSTATUS status;
     1243        DEBUG(5, ("getgroups_recv called\n"));
     1244
     1245        status = wb_cmd_getgroups_recv(ctx, s3call, &gids, &num_groups);
     1246        if (NT_STATUS_IS_OK(status)) {
     1247                uint32_t extra_len = sizeof(gid_t) * num_groups;
     1248
     1249                s3call->response->data.num_entries = num_groups;
     1250                s3call->response->extra_data.data = gids;
     1251                s3call->response->length += extra_len;
     1252        } else {
     1253                s3call->response->result = WINBINDD_ERROR;
     1254        }
     1255
     1256        wbsrv_samba3_async_epilogue(status, s3call);
     1257}
     1258
     1259static void setgrent_recv(struct composite_context *ctx);
    10451260
    10461261NTSTATUS wbsrv_samba3_setgrent(struct wbsrv_samba3_call *s3call)
    10471262{
     1263        struct composite_context *ctx;
     1264        struct wbsrv_service *service = s3call->wbconn->listen_socket->service;
     1265
    10481266        DEBUG(5, ("wbsrv_samba3_setgrent called\n"));
    1049         s3call->response.result = WINBINDD_OK;
    1050         return NT_STATUS_OK;
    1051 }
     1267
     1268        ctx = wb_cmd_setgrent_send(s3call, service);
     1269        NT_STATUS_HAVE_NO_MEMORY(ctx);
     1270
     1271        ctx->async.fn = setgrent_recv;
     1272        ctx->async.private_data = s3call;
     1273        s3call->flags |= WBSRV_CALL_FLAGS_REPLY_ASYNC;
     1274        return NT_STATUS_OK;
     1275}
     1276
     1277static void setgrent_recv(struct composite_context *ctx)
     1278{
     1279        struct wbsrv_samba3_call *s3call =
     1280                talloc_get_type(ctx->async.private_data,
     1281                                struct wbsrv_samba3_call);
     1282        NTSTATUS status;
     1283        struct wbsrv_grent *grent;
     1284
     1285        DEBUG(5, ("setpwent_recv called\n"));
     1286
     1287        status = wb_cmd_setgrent_recv(ctx, s3call->wbconn, &grent);
     1288        if (NT_STATUS_IS_OK(status)) {
     1289                s3call->wbconn->protocol_private_data = grent;
     1290        }
     1291
     1292        wbsrv_samba3_async_epilogue(status, s3call);
     1293}
     1294
     1295static void getgrent_recv(struct composite_context *ctx);
    10521296
    10531297NTSTATUS wbsrv_samba3_getgrent(struct wbsrv_samba3_call *s3call)
    10541298{
     1299        struct composite_context *ctx;
     1300        struct wbsrv_service *service = s3call->wbconn->listen_socket->service;
     1301        struct wbsrv_grent *grent;
     1302
    10551303        DEBUG(5, ("wbsrv_samba3_getgrent called\n"));
    1056         s3call->response.result = WINBINDD_ERROR;
    1057         return NT_STATUS_OK;
     1304
     1305        NT_STATUS_HAVE_NO_MEMORY(s3call->wbconn->protocol_private_data);
     1306
     1307        grent = talloc_get_type(s3call->wbconn->protocol_private_data,
     1308                        struct wbsrv_grent);
     1309        NT_STATUS_HAVE_NO_MEMORY(grent);
     1310
     1311        ctx = wb_cmd_getgrent_send(s3call, service, grent,
     1312                        s3call->request->data.num_entries);
     1313        NT_STATUS_HAVE_NO_MEMORY(ctx);
     1314
     1315        ctx->async.fn = getgrent_recv;
     1316        ctx->async.private_data = s3call;
     1317        s3call->flags |= WBSRV_CALL_FLAGS_REPLY_ASYNC;
     1318        return NT_STATUS_OK;
     1319}
     1320
     1321static void getgrent_recv(struct composite_context *ctx)
     1322{
     1323        struct wbsrv_samba3_call *s3call =
     1324                talloc_get_type(ctx->async.private_data,
     1325                                struct wbsrv_samba3_call);
     1326        NTSTATUS status;
     1327        struct winbindd_gr *gr;
     1328        uint32_t num_groups;
     1329
     1330        DEBUG(5, ("getgrent_recv called\n"));
     1331
     1332        status = wb_cmd_getgrent_recv(ctx, s3call, &gr, &num_groups);
     1333        if (NT_STATUS_IS_OK(status)) {
     1334                uint32_t extra_len = sizeof(struct winbindd_gr) * num_groups;
     1335
     1336                s3call->response->data.num_entries = num_groups;
     1337                s3call->response->extra_data.data = gr;
     1338                s3call->response->length += extra_len;
     1339        }
     1340
     1341        wbsrv_samba3_async_epilogue(status, s3call);
    10581342}
    10591343
     
    10611345{
    10621346        DEBUG(5, ("wbsrv_samba3_endgrent called\n"));
    1063         s3call->response.result = WINBINDD_OK;
     1347        s3call->response->result = WINBINDD_OK;
    10641348        return NT_STATUS_OK;
    10651349}
     
    10761360        DEBUG(5, ("wbsrv_samba3_sid2uid called\n"));
    10771361
    1078         sid = dom_sid_parse_talloc(s3call, s3call->request.data.sid);
     1362        sid = dom_sid_parse_talloc(s3call, s3call->request->data.sid);
    10791363        NT_STATUS_HAVE_NO_MEMORY(sid);
    10801364
     
    10981382        DEBUG(5, ("sid2uid_recv called\n"));
    10991383
    1100         status = wb_sid2uid_recv(ctx, &s3call->response.data.uid);
     1384        status = wb_sid2uid_recv(ctx, &s3call->response->data.uid);
    11011385
    11021386        wbsrv_samba3_async_epilogue(status, s3call);
     
    11141398        DEBUG(5, ("wbsrv_samba3_sid2gid called\n"));
    11151399
    1116         sid = dom_sid_parse_talloc(s3call, s3call->request.data.sid);
     1400        sid = dom_sid_parse_talloc(s3call, s3call->request->data.sid);
    11171401        NT_STATUS_HAVE_NO_MEMORY(sid);
    11181402
     
    11361420        DEBUG(5, ("sid2gid_recv called\n"));
    11371421
    1138         status = wb_sid2gid_recv(ctx, &s3call->response.data.gid);
     1422        status = wb_sid2gid_recv(ctx, &s3call->response->data.gid);
    11391423
    11401424        wbsrv_samba3_async_epilogue(status, s3call);
     
    11511435        DEBUG(5, ("wbsrv_samba3_uid2sid called\n"));
    11521436
    1153         ctx = wb_uid2sid_send(s3call, service, s3call->request.data.uid);
     1437        ctx = wb_uid2sid_send(s3call, service, s3call->request->data.uid);
    11541438        NT_STATUS_HAVE_NO_MEMORY(ctx);
    11551439
     
    11821466                /* But we assume this worked, so we'll set the string. Work
    11831467                 * done. */
    1184                 WBSRV_SAMBA3_SET_STRING(s3call->response.data.sid.sid, sid_str);
    1185                 s3call->response.data.sid.type = SID_NAME_USER;
     1468                WBSRV_SAMBA3_SET_STRING(s3call->response->data.sid.sid, sid_str);
     1469                s3call->response->data.sid.type = SID_NAME_USER;
    11861470        }
    11871471
     
    11991483        DEBUG(5, ("wbsrv_samba3_gid2sid called\n"));
    12001484
    1201         ctx = wb_gid2sid_send(s3call, service, s3call->request.data.gid);
     1485        ctx = wb_gid2sid_send(s3call, service, s3call->request->data.gid);
    12021486        NT_STATUS_HAVE_NO_MEMORY(ctx);
    12031487
     
    12271511                        wbsrv_samba3_async_epilogue(NT_STATUS_NO_MEMORY,s3call);
    12281512
    1229                 WBSRV_SAMBA3_SET_STRING(s3call->response.data.sid.sid, sid_str);
    1230                 s3call->response.data.sid.type = SID_NAME_DOMAIN;
    1231         }
    1232 
    1233         wbsrv_samba3_async_epilogue(status, s3call);
    1234 }
    1235 
     1513                WBSRV_SAMBA3_SET_STRING(s3call->response->data.sid.sid, sid_str);
     1514                s3call->response->data.sid.type = SID_NAME_DOMAIN;
     1515        }
     1516
     1517        wbsrv_samba3_async_epilogue(status, s3call);
     1518}
     1519
  • trunk/server/source4/winbind/wb_samba3_protocol.c

    r414 r745  
    2424#include "smbd/service_stream.h"
    2525#include "lib/stream/packet.h"
     26#include "lib/tsocket/tsocket.h"
    2627
    2728/*
     
    4445
    4546
    46 NTSTATUS wbsrv_samba3_pull_request(DATA_BLOB blob, struct wbsrv_connection *wbconn,
    47                                    struct wbsrv_samba3_call **_call)
    48 {
    49         struct wbsrv_samba3_call *call;
    50 
    51         if (blob.length != sizeof(call->request)) {
     47NTSTATUS wbsrv_samba3_pull_request(struct wbsrv_samba3_call *call)
     48{
     49        if (call->in.length != sizeof(*call->request)) {
    5250                DEBUG(0,("wbsrv_samba3_pull_request: invalid blob length %lu should be %lu\n"
    5351                         " make sure you use the correct winbind client tools!\n",
    54                          (long)blob.length, (long)sizeof(call->request)));
     52                         (long)call->in.length, (long)sizeof(*call->request)));
    5553                return NT_STATUS_INVALID_PARAMETER;
    5654        }
    5755
    58         call = talloc_zero(wbconn, struct wbsrv_samba3_call);
    59         NT_STATUS_HAVE_NO_MEMORY(call);
     56        call->request = talloc_zero(call, struct winbindd_request);
     57        NT_STATUS_HAVE_NO_MEMORY(call->request);
    6058
    6159        /* the packet layout is the same as the in memory layout of the request, so just copy it */
    62         memcpy(&call->request, blob.data, sizeof(call->request));
    63 
    64         call->wbconn = wbconn;
    65         call->event_ctx = call->wbconn->conn->event.ctx;
    66        
    67         *_call = call;
     60        memcpy(call->request, call->in.data, sizeof(*call->request));
     61
    6862        return NT_STATUS_OK;
    6963}
     
    7165NTSTATUS wbsrv_samba3_handle_call(struct wbsrv_samba3_call *s3call)
    7266{
    73         DEBUG(10, ("Got winbind samba3 request %d\n", s3call->request.cmd));
    74 
    75         s3call->response.length = sizeof(s3call->response);
    76 
    77         switch(s3call->request.cmd) {
     67        DEBUG(10, ("Got winbind samba3 request %d\n", s3call->request->cmd));
     68
     69        s3call->response = talloc_zero(s3call, struct winbindd_response);
     70        NT_STATUS_HAVE_NO_MEMORY(s3call->request);
     71
     72        s3call->response->length = sizeof(*s3call->response);
     73
     74        switch(s3call->request->cmd) {
    7875        case WINBINDD_INTERFACE_VERSION:
    7976                return wbsrv_samba3_interface_version(s3call);
     
    179176                return wbsrv_samba3_domain_info(s3call);
    180177
     178        case WINBINDD_PAM_LOGOFF:
     179                return wbsrv_samba3_pam_logoff(s3call);
     180
    181181        /* Unimplemented commands */
    182 
    183182        case WINBINDD_GETPWSID:
    184183        case WINBINDD_PAM_CHAUTHTOK:
    185         case WINBINDD_PAM_LOGOFF:
    186184        case WINBINDD_PAM_CHNG_PSWD_AUTH_CRAP:
    187185        case WINBINDD_LOOKUPRIDS:
     
    189187        case WINBINDD_ALLOCATE_UID:
    190188        case WINBINDD_ALLOCATE_GID:
    191         case WINBINDD_SET_MAPPING:
    192         case WINBINDD_REMOVE_MAPPING:
    193         case WINBINDD_SET_HWM:
    194189        case WINBINDD_SHOW_SEQUENCE:
    195190        case WINBINDD_WINS_BYIP:
     
    200195        case WINBINDD_INIT_CONNECTION:
    201196        case WINBINDD_DUAL_SIDS2XIDS:
    202         case WINBINDD_DUAL_SET_MAPPING:
    203         case WINBINDD_DUAL_REMOVE_MAPPING:
    204         case WINBINDD_DUAL_SET_HWM:
    205197        case WINBINDD_DUAL_USERINFO:
    206198        case WINBINDD_DUAL_GETSIDALIASES:
     
    209201        case WINBINDD_NUM_CMDS:
    210202                DEBUG(10, ("Unimplemented winbind samba3 request %d\n",
    211                            s3call->request.cmd));
     203                           s3call->request->cmd));
    212204                break;
    213205        }
    214206
    215         s3call->response.result = WINBINDD_ERROR;
     207        s3call->response->result = WINBINDD_ERROR;
    216208        return NT_STATUS_OK;
    217209}
    218210
    219 static NTSTATUS wbsrv_samba3_push_reply(struct wbsrv_samba3_call *call, TALLOC_CTX *mem_ctx, DATA_BLOB *_blob)
    220 {
    221         DATA_BLOB blob;
     211static NTSTATUS wbsrv_samba3_push_reply(struct wbsrv_samba3_call *call)
     212{
    222213        uint8_t *extra_data;
    223214        size_t extra_data_len = 0;
    224215
    225         extra_data = (uint8_t *)call->response.extra_data.data;
     216        extra_data = (uint8_t *)call->response->extra_data.data;
    226217        if (extra_data != NULL) {
    227                 extra_data_len = call->response.length -
    228                         sizeof(call->response);
    229         }
    230 
    231         blob = data_blob_talloc(mem_ctx, NULL, call->response.length);
    232         NT_STATUS_HAVE_NO_MEMORY(blob.data);
     218                extra_data_len = call->response->length -
     219                        sizeof(*call->response);
     220        }
     221
     222        call->out = data_blob_talloc(call, NULL, call->response->length);
     223        NT_STATUS_HAVE_NO_MEMORY(call->out.data);
    233224
    234225        /* don't push real pointer values into sockets */
    235226        if (extra_data) {
    236                 call->response.extra_data.data = (void *)0xFFFFFFFF;
    237         }
    238         memcpy(blob.data, &call->response, sizeof(call->response));
     227                call->response->extra_data.data = (void *)0xFFFFFFFF;
     228        }
     229
     230        memcpy(call->out.data, call->response, sizeof(*call->response));
    239231        /* set back the pointer */
    240         call->response.extra_data.data = extra_data;
     232        call->response->extra_data.data = extra_data;
    241233
    242234        if (extra_data) {
    243                 memcpy(blob.data + sizeof(call->response), extra_data, extra_data_len);
    244         }
    245 
    246         *_blob = blob;
     235                memcpy(call->out.data + sizeof(*call->response),
     236                       extra_data,
     237                       extra_data_len);
     238        }
     239
    247240        return NT_STATUS_OK;
    248241}
     242
     243static void wbsrv_samba3_send_reply_done(struct tevent_req *subreq);
    249244
    250245/*
     
    256251NTSTATUS wbsrv_samba3_send_reply(struct wbsrv_samba3_call *call)
    257252{
    258         struct wbsrv_connection *wbconn = call->wbconn;
    259         DATA_BLOB rep;
     253        struct wbsrv_connection *wbsrv_conn = call->wbconn;
     254        struct tevent_req *subreq;
    260255        NTSTATUS status;
    261256
    262         status = wbsrv_samba3_push_reply(call, call, &rep);
     257        status = wbsrv_samba3_push_reply(call);
    263258        NT_STATUS_NOT_OK_RETURN(status);
    264259
    265         status = packet_send(call->wbconn->packet, rep);
    266        
     260        call->out_iov[0].iov_base = (char *) call->out.data;
     261        call->out_iov[0].iov_len = call->out.length;
     262
     263        subreq = tstream_writev_queue_send(call,
     264                                           wbsrv_conn->conn->event.ctx,
     265                                           wbsrv_conn->tstream,
     266                                           wbsrv_conn->send_queue,
     267                                           call->out_iov, 1);
     268        if (subreq == NULL) {
     269                wbsrv_terminate_connection(wbsrv_conn, "wbsrv_call_loop: "
     270                                "no memory for tstream_writev_queue_send");
     271                return NT_STATUS_NO_MEMORY;
     272        }
     273        tevent_req_set_callback(subreq, wbsrv_samba3_send_reply_done, call);
     274
     275        return status;
     276}
     277
     278static void wbsrv_samba3_send_reply_done(struct tevent_req *subreq)
     279{
     280        struct wbsrv_samba3_call *call = tevent_req_callback_data(subreq,
     281                        struct wbsrv_samba3_call);
     282        int sys_errno;
     283        int rc;
     284
     285        rc = tstream_writev_queue_recv(subreq, &sys_errno);
     286        TALLOC_FREE(subreq);
     287        if (rc == -1) {
     288                const char *reason;
     289
     290                reason = talloc_asprintf(call, "wbsrv_samba3_send_reply_done: "
     291                                         "tstream_writev_queue_recv() - %d:%s",
     292                                         sys_errno, strerror(sys_errno));
     293                if (reason == NULL) {
     294                        reason = "wbsrv_samba3_send_reply_done: "
     295                                 "tstream_writev_queue_recv() failed";
     296                }
     297
     298                wbsrv_terminate_connection(call->wbconn, reason);
     299                return;
     300        }
     301
    267302        talloc_free(call);
    268 
    269         if (!NT_STATUS_IS_OK(status)) {
    270                 wbsrv_terminate_connection(wbconn,
    271                                            "failed to packet_send winbindd reply");
    272                 return status;
    273         }
    274         /* the call isn't needed any more */
    275         return status;
    276 }
    277 
    278 NTSTATUS wbsrv_samba3_process(void *private_data, DATA_BLOB blob)
     303}
     304
     305NTSTATUS wbsrv_samba3_process(struct wbsrv_samba3_call *call)
    279306{
    280307        NTSTATUS status;
    281         struct wbsrv_connection *wbconn = talloc_get_type(private_data,
    282                                                           struct wbsrv_connection);
    283         struct wbsrv_samba3_call *call;
    284         status = wbsrv_samba3_pull_request(blob, wbconn, &call);
     308
     309        status = wbsrv_samba3_pull_request(call);
    285310       
    286311        if (!NT_STATUS_IS_OK(status)) {
    287312                return status;
    288313        }
    289        
     314
    290315        status = wbsrv_samba3_handle_call(call);
    291316
  • trunk/server/source4/winbind/wb_server.c

    r414 r745  
    33   Main winbindd server routines
    44
    5    Copyright (C) Stefan Metzmacher      2005
     5   Copyright (C) Stefan Metzmacher      2005-2008
    66   Copyright (C) Andrew Tridgell        2005
     7   Copyright (C) Andrew Bartlett <abartlet@samba.org> 2010
    78   
    89   This program is free software; you can redistribute it and/or modify
     
    2122
    2223#include "includes.h"
    23 #include "lib/socket/socket.h"
    24 #include "../lib/util/dlinklist.h"
    25 #include "lib/events/events.h"
    26 #include "smbd/service_task.h"
    2724#include "smbd/process_model.h"
    28 #include "smbd/service_stream.h"
    29 #include "nsswitch/winbind_nss_config.h"
    3025#include "winbind/wb_server.h"
    3126#include "lib/stream/packet.h"
    32 #include "smbd/service.h"
     27#include "lib/tsocket/tsocket.h"
     28#include "libcli/util/tstream.h"
     29#include "param/param.h"
    3330#include "param/secrets.h"
    34 #include "param/param.h"
    3531
    3632void wbsrv_terminate_connection(struct wbsrv_connection *wbconn, const char *reason)
     
    3935}
    4036
     37static void wbsrv_call_loop(struct tevent_req *subreq)
     38{
     39        struct wbsrv_connection *wbsrv_conn = tevent_req_callback_data(subreq,
     40                                      struct wbsrv_connection);
     41        struct wbsrv_samba3_call *call;
     42        NTSTATUS status;
     43
     44        call = talloc_zero(wbsrv_conn, struct wbsrv_samba3_call);
     45        if (call == NULL) {
     46                wbsrv_terminate_connection(wbsrv_conn, "wbsrv_call_loop: "
     47                                "no memory for wbsrv_samba3_call");
     48                return;
     49        }
     50        call->wbconn = wbsrv_conn;
     51
     52        status = tstream_read_pdu_blob_recv(subreq,
     53                                            call,
     54                                            &call->in);
     55        TALLOC_FREE(subreq);
     56        if (!NT_STATUS_IS_OK(status)) {
     57                const char *reason;
     58
     59                reason = talloc_asprintf(call, "wbsrv_call_loop: "
     60                                         "tstream_read_pdu_blob_recv() - %s",
     61                                         nt_errstr(status));
     62                if (!reason) {
     63                        reason = nt_errstr(status);
     64                }
     65
     66                wbsrv_terminate_connection(wbsrv_conn, reason);
     67                return;
     68        }
     69
     70        DEBUG(10,("Received winbind TCP packet of length %lu from %s\n",
     71                 (long) call->in.length,
     72                 tsocket_address_string(wbsrv_conn->conn->remote_address, call)));
     73
     74        status = wbsrv_samba3_process(call);
     75        if (!NT_STATUS_IS_OK(status)) {
     76                const char *reason;
     77
     78                reason = talloc_asprintf(call, "wbsrv_call_loop: "
     79                                         "tstream_read_pdu_blob_recv() - %s",
     80                                         nt_errstr(status));
     81                if (!reason) {
     82                        reason = nt_errstr(status);
     83                }
     84
     85                wbsrv_terminate_connection(wbsrv_conn, reason);
     86                return;
     87        }
     88
     89        /*
     90         * The winbind pdu's has the length as 4 byte (initial_read_size),
     91         * wbsrv_samba3_packet_full_request provides the pdu length then.
     92         */
     93        subreq = tstream_read_pdu_blob_send(wbsrv_conn,
     94                                            wbsrv_conn->conn->event.ctx,
     95                                            wbsrv_conn->tstream,
     96                                            4, /* initial_read_size */
     97                                            wbsrv_samba3_packet_full_request,
     98                                            wbsrv_conn);
     99        if (subreq == NULL) {
     100                wbsrv_terminate_connection(wbsrv_conn, "wbsrv_call_loop: "
     101                                "no memory for tstream_read_pdu_blob_send");
     102                return;
     103        }
     104        tevent_req_set_callback(subreq, wbsrv_call_loop, wbsrv_conn);
     105}
     106
     107static void wbsrv_accept(struct stream_connection *conn)
     108{
     109        struct wbsrv_listen_socket *wbsrv_socket = talloc_get_type(conn->private_data,
     110                                                                   struct wbsrv_listen_socket);
     111        struct wbsrv_connection *wbsrv_conn;
     112        struct tevent_req *subreq;
     113        int rc;
     114
     115        wbsrv_conn = talloc_zero(conn, struct wbsrv_connection);
     116        if (wbsrv_conn == NULL) {
     117                stream_terminate_connection(conn, "wbsrv_accept: out of memory");
     118                return;
     119        }
     120
     121        wbsrv_conn->send_queue = tevent_queue_create(conn, "wbsrv_accept");
     122        if (wbsrv_conn->send_queue == NULL) {
     123                stream_terminate_connection(conn,
     124                                "wbsrv_accept: out of memory");
     125                return;
     126        }
     127
     128        TALLOC_FREE(conn->event.fde);
     129
     130        rc = tstream_bsd_existing_socket(wbsrv_conn,
     131                        socket_get_fd(conn->socket),
     132                        &wbsrv_conn->tstream);
     133        if (rc < 0) {
     134                stream_terminate_connection(conn,
     135                                "wbsrv_accept: out of memory");
     136                return;
     137        }
     138
     139        wbsrv_conn->conn = conn;
     140        wbsrv_conn->listen_socket = wbsrv_socket;
     141        wbsrv_conn->lp_ctx = wbsrv_socket->service->task->lp_ctx;
     142        conn->private_data = wbsrv_conn;
     143
     144        /*
     145         * The winbind pdu's has the length as 4 byte (initial_read_size),
     146         * wbsrv_samba3_packet_full_request provides the pdu length then.
     147         */
     148        subreq = tstream_read_pdu_blob_send(wbsrv_conn,
     149                                            wbsrv_conn->conn->event.ctx,
     150                                            wbsrv_conn->tstream,
     151                                            4, /* initial_read_size */
     152                                            wbsrv_samba3_packet_full_request,
     153                                            wbsrv_conn);
     154        if (subreq == NULL) {
     155                wbsrv_terminate_connection(wbsrv_conn, "wbsrv_accept: "
     156                                "no memory for tstream_read_pdu_blob_send");
     157                return;
     158        }
     159        tevent_req_set_callback(subreq, wbsrv_call_loop, wbsrv_conn);
     160}
     161
    41162/*
    42   called on a tcp recv error
    43 */
    44 static void wbsrv_recv_error(void *private_data, NTSTATUS status)
    45 {
    46         struct wbsrv_connection *wbconn = talloc_get_type(private_data, struct wbsrv_connection);
    47         wbsrv_terminate_connection(wbconn, nt_errstr(status));
    48 }
    49 
    50 static void wbsrv_accept(struct stream_connection *conn)
    51 {
    52         struct wbsrv_listen_socket *listen_socket = talloc_get_type(conn->private_data,
    53                                                                     struct wbsrv_listen_socket);
    54         struct wbsrv_connection *wbconn;
    55 
    56         wbconn = talloc_zero(conn, struct wbsrv_connection);
    57         if (!wbconn) {
    58                 stream_terminate_connection(conn, "wbsrv_accept: out of memory");
    59                 return;
    60         }
    61         wbconn->conn          = conn;
    62         wbconn->listen_socket = listen_socket;
    63         wbconn->lp_ctx        = listen_socket->service->task->lp_ctx;
    64         conn->private_data    = wbconn;
    65 
    66         wbconn->packet = packet_init(wbconn);
    67         if (wbconn->packet == NULL) {
    68                 wbsrv_terminate_connection(wbconn, "wbsrv_accept: out of memory");
    69                 return;
    70         }
    71         packet_set_private(wbconn->packet, wbconn);
    72         packet_set_socket(wbconn->packet, conn->socket);
    73         packet_set_callback(wbconn->packet, wbsrv_samba3_process);
    74         packet_set_full_request(wbconn->packet, wbsrv_samba3_packet_full_request);
    75         packet_set_error_handler(wbconn->packet, wbsrv_recv_error);
    76         packet_set_event_context(wbconn->packet, conn->event.ctx);
    77         packet_set_fde(wbconn->packet, conn->event.fde);
    78         packet_set_serialise(wbconn->packet);
    79 }
    80 
    81 /*
    82   receive some data on a winbind connection
     163  called on a tcp recv
    83164*/
    84165static void wbsrv_recv(struct stream_connection *conn, uint16_t flags)
    85166{
    86         struct wbsrv_connection *wbconn = talloc_get_type(conn->private_data,
    87                                                           struct wbsrv_connection);
    88         packet_recv(wbconn->packet);
    89 
     167        struct wbsrv_connection *wbsrv_conn = talloc_get_type(conn->private_data,
     168                                                        struct wbsrv_connection);
     169        wbsrv_terminate_connection(wbsrv_conn, "wbsrv_recv: called");
    90170}
    91171
     
    95175static void wbsrv_send(struct stream_connection *conn, uint16_t flags)
    96176{
    97         struct wbsrv_connection *wbconn = talloc_get_type(conn->private_data,
    98                                                           struct wbsrv_connection);
    99         packet_queue_run(wbconn->packet);
     177        struct wbsrv_connection *wbsrv_conn = talloc_get_type(conn->private_data,
     178                                                        struct wbsrv_connection);
     179        /* this should never be triggered! */
     180        wbsrv_terminate_connection(wbsrv_conn, "wbsrv_send: called");
    100181}
    101182
     
    117198        struct wbsrv_service *service;
    118199        struct wbsrv_listen_socket *listen_socket;
     200        char *errstring;
     201        struct dom_sid *primary_sid;
    119202
    120203        task_server_set_title(task, "task[winbind]");
     
    123206           ask for the single process model ops and pass these to the
    124207           stream_setup_socket() call. */
    125         model_ops = process_model_startup(task->event_ctx, "single");
     208        model_ops = process_model_startup("single");
    126209        if (!model_ops) {
    127210                task_server_terminate(task,
     
    131214
    132215        /* Make sure the directory for the Samba3 socket exists, and is of the correct permissions */
    133         if (!directory_create_or_exist(lp_winbindd_socket_directory(task->lp_ctx), geteuid(), 0755)) {
     216        if (!directory_create_or_exist(lpcfg_winbindd_socket_directory(task->lp_ctx), geteuid(), 0755)) {
    134217                task_server_terminate(task,
    135218                                      "Cannot create winbindd pipe directory", true);
     
    138221
    139222        /* Make sure the directory for the Samba3 socket exists, and is of the correct permissions */
    140         if (!directory_create_or_exist(lp_winbindd_privileged_socket_directory(task->lp_ctx), geteuid(), 0750)) {
     223        if (!directory_create_or_exist(lpcfg_winbindd_privileged_socket_directory(task->lp_ctx), geteuid(), 0750)) {
    141224                task_server_terminate(task,
    142225                                      "Cannot create winbindd privileged pipe directory", true);
     
    148231        service->task   = task;
    149232
    150         status = wbsrv_setup_domains(service);
    151         if (!NT_STATUS_IS_OK(status)) {
    152                 task_server_terminate(task, nt_errstr(status), true);
    153                 return;
    154         }
     233
     234        /* Find the primary SID, depending if we are a standalone
     235         * server (what good is winbind in this case, but anyway...),
     236         * or are in a domain as a member or a DC */
     237        switch (lpcfg_server_role(service->task->lp_ctx)) {
     238        case ROLE_STANDALONE:
     239                primary_sid = secrets_get_domain_sid(service,
     240                                                     service->task->lp_ctx,
     241                                                     lpcfg_netbios_name(service->task->lp_ctx),
     242                                                     &service->sec_channel_type,
     243                                                     &errstring);
     244                if (!primary_sid) {
     245                        char *message = talloc_asprintf(task,
     246                                                        "Cannot start Winbind (standalone configuration): %s: "
     247                                                        "Have you provisioned this server (%s) or changed it's name?",
     248                                                        errstring, lpcfg_netbios_name(service->task->lp_ctx));
     249                        task_server_terminate(task, message, true);
     250                        return;
     251                }
     252                break;
     253        case ROLE_DOMAIN_MEMBER:
     254                primary_sid = secrets_get_domain_sid(service,
     255                                                     service->task->lp_ctx,
     256                                                     lpcfg_workgroup(service->task->lp_ctx),
     257                                                     &service->sec_channel_type,
     258                                                     &errstring);
     259                if (!primary_sid) {
     260                        char *message = talloc_asprintf(task, "Cannot start Winbind (domain member): %s: "
     261                                                        "Have you joined the %s domain?",
     262                                                        errstring, lpcfg_workgroup(service->task->lp_ctx));
     263                        task_server_terminate(task, message, true);
     264                        return;
     265                }
     266                break;
     267        case ROLE_DOMAIN_CONTROLLER:
     268                primary_sid = secrets_get_domain_sid(service,
     269                                                     service->task->lp_ctx,
     270                                                     lpcfg_workgroup(service->task->lp_ctx),
     271                                                     &service->sec_channel_type,
     272                                                     &errstring);
     273                if (!primary_sid) {
     274                        char *message = talloc_asprintf(task, "Cannot start Winbind (domain controller): %s: "
     275                                                        "Have you provisioned the %s domain?",
     276                                                        errstring, lpcfg_workgroup(service->task->lp_ctx));
     277                        task_server_terminate(task, message, true);
     278                        return;
     279                }
     280                break;
     281        }
     282        service->primary_sid = primary_sid;
    155283
    156284        service->idmap_ctx = idmap_init(service, task->event_ctx, task->lp_ctx);
     
    159287                return;
    160288        }
     289
     290        service->priv_pipe_dir = lpcfg_winbindd_privileged_socket_directory(task->lp_ctx);
     291        service->pipe_dir = lpcfg_winbindd_socket_directory(task->lp_ctx);
    161292
    162293        /* setup the unprivileged samba3 socket */
     
    164295        if (!listen_socket) goto nomem;
    165296        listen_socket->socket_path      = talloc_asprintf(listen_socket, "%s/%s",
    166                                                           lp_winbindd_socket_directory(task->lp_ctx),
    167                                                           WINBINDD_SAMBA3_SOCKET);
     297                                                          service->pipe_dir,
     298                                                          WINBINDD_SOCKET_NAME);
    168299        if (!listen_socket->socket_path) goto nomem;
    169300        listen_socket->service          = service;
    170301        listen_socket->privileged       = false;
    171         status = stream_setup_socket(task->event_ctx, task->lp_ctx, model_ops,
     302        status = stream_setup_socket(task, task->event_ctx, task->lp_ctx, model_ops,
    172303                                     &wbsrv_ops, "unix",
    173304                                     listen_socket->socket_path, &port,
    174                                      lp_socket_options(task->lp_ctx),
     305                                     lpcfg_socket_options(task->lp_ctx),
    175306                                     listen_socket);
    176307        if (!NT_STATUS_IS_OK(status)) goto listen_failed;
     
    180311        if (!listen_socket) goto nomem;
    181312        listen_socket->socket_path
    182                 = service->priv_socket_path
    183313                = talloc_asprintf(listen_socket, "%s/%s",
    184                                                           lp_winbindd_privileged_socket_directory(task->lp_ctx),
    185                                                           WINBINDD_SAMBA3_SOCKET);
    186         if (!listen_socket->socket_path) goto nomem;
     314                                  service->priv_pipe_dir,
     315                                  WINBINDD_SOCKET_NAME);
    187316        if (!listen_socket->socket_path) goto nomem;
    188317        listen_socket->service          = service;
    189318        listen_socket->privileged       = true;
    190         status = stream_setup_socket(task->event_ctx, task->lp_ctx, model_ops,
     319        status = stream_setup_socket(task, task->event_ctx, task->lp_ctx, model_ops,
    191320                                     &wbsrv_ops, "unix",
    192321                                     listen_socket->socket_path, &port,
    193                                      lp_socket_options(task->lp_ctx),
     322                                     lpcfg_socket_options(task->lp_ctx),
    194323                                     listen_socket);
    195324        if (!NT_STATUS_IS_OK(status)) goto listen_failed;
  • trunk/server/source4/winbind/wb_server.h

    r414 r745  
    2525#include "libnet/libnet.h"
    2626
    27 #define WINBINDD_SAMBA3_SOCKET "pipe"
    28 /* the privileged socket is in smbd_tmp_dir() */
    29 #define WINBINDD_SAMBA3_PRIVILEGED_SOCKET "winbind_pipe"
    30 
    3127/* this struct stores global data for the winbind task */
    3228struct wbsrv_service {
     
    3430
    3531        const struct dom_sid *primary_sid;
     32        enum netr_SchannelType sec_channel_type;
    3633        struct wbsrv_domain *domains;
    3734        struct idmap_context *idmap_ctx;
    38 
    39         const char *priv_socket_path;
     35        const char *priv_pipe_dir;
     36        const char *pipe_dir;
    4037};
    4138
     
    5249        const char *dns_name;
    5350        const struct dom_sid *sid;
    54 
    55         int num_dcs;
    56         struct nbt_dc_name *dcs;
     51        struct nbt_dc_name *dc;
    5752};
    5853
     
    10196        uint32_t pending_calls;
    10297
    103         struct packet_context *packet;
     98        struct tstream_context *tstream;
     99
     100        struct tevent_queue *send_queue;
    104101
    105102        struct loadparm_context *lp_ctx;
     
    107104
    108105#define WBSRV_SAMBA3_SET_STRING(dest, src) do { \
     106        memset(dest, 0, sizeof(dest));\
    109107        safe_strcpy(dest, src, sizeof(dest)-1);\
    110108} while(0)
     
    116114        /* Current UserList structure, contains 1+ user structs */
    117115        struct libnet_UserList *user_list;
     116
     117        /* Index of the next user struct in the current UserList struct */
     118        uint32_t page_index;
     119
     120        /* The libnet_ctx to use for the libnet_UserList call */
     121        struct libnet_context *libnet_ctx;
     122};
     123/*
     124  state of a grent query
     125*/
     126struct wbsrv_grent {
     127        /* Current UserList structure, contains 1+ user structs */
     128        struct libnet_GroupList *group_list;
    118129
    119130        /* Index of the next user struct in the current UserList struct */
     
    149160        struct wbsrv_connection *wbconn;
    150161
    151         /* the backend should use this event context */
    152         struct tevent_context *event_ctx;
    153 
    154162        /* here the backend can store stuff like composite_context's ... */
    155163        void *private_data;
    156164
    157165        /* the request structure of the samba3 protocol */
    158         struct winbindd_request request;
     166        struct winbindd_request *request;
    159167       
    160168        /* the response structure of the samba3 protocol*/
    161         struct winbindd_response response;
     169        struct winbindd_response *response;
     170
     171        DATA_BLOB in;
     172        DATA_BLOB out;
     173        struct iovec out_iov[1];
    162174};
    163175
     
    165177struct netr_UserSessionKey;
    166178struct winbind_SamLogon;
     179struct winbind_DsrUpdateReadOnlyServerDnsRecords;
    167180
    168181#include "winbind/wb_async_helpers.h"
  • trunk/server/source4/winbind/wb_sid2domain.c

    r414 r745  
    2424#include "winbind/wb_server.h"
    2525#include "smbd/service_task.h"
    26 #include "winbind/wb_async_helpers.h"
    2726#include "libcli/security/security.h"
    2827#include "../lib/util/dlinklist.h"
     
    6463        struct composite_context *result, *ctx;
    6564        struct sid2domain_state *state;
    66 
     65        DEBUG(5, ("wb_sid2domain_send called\n"));
    6766        result = composite_create(mem_ctx, service->task->event_ctx);
    6867        if (result == NULL) goto failed;
     
    8685        if (dom_sid_equal(service->primary_sid, sid) ||
    8786            dom_sid_in_domain(service->primary_sid, sid)) {
    88                 ctx = wb_get_dom_info_send(state, service, lp_workgroup(service->task->lp_ctx),
     87                ctx = wb_get_dom_info_send(state, service,
     88                                           lpcfg_workgroup(service->task->lp_ctx),
     89                                           lpcfg_realm(service->task->lp_ctx),
    8990                                           service->primary_sid);
    9091                if (ctx == NULL) goto failed;
  • trunk/server/source4/winbind/wb_sid2gid.c

    r414 r745  
    2424#include "winbind/wb_server.h"
    2525#include "smbd/service_task.h"
    26 #include "winbind/wb_helper.h"
    2726#include "libcli/security/security.h"
    28 #include "winbind/idmap.h"
    2927
    3028struct sid2gid_state {
     
    4139        struct composite_context *result, *ctx;
    4240        struct sid2gid_state *state;
    43         struct id_mapping *ids;
     41        struct id_map *ids;
    4442
    4543        DEBUG(5, ("wb_sid2gid_send called\n"));
     
    5553        state->service = service;
    5654
    57         ids = talloc(result, struct id_mapping);
     55        ids = talloc(result, struct id_map);
    5856        if (composite_nomem(ids, result)) return result;
    5957
     
    7371                                                      struct sid2gid_state);
    7472
    75         struct id_mapping *ids = NULL;
     73        struct id_map *ids = NULL;
    7674
    7775        state->ctx->status = wb_sids2xids_recv(ctx, &ids);
    7876        if (!composite_is_ok(state->ctx)) return;
    7977
    80         if (!NT_STATUS_IS_OK(ids->status)) {
    81                 composite_error(state->ctx, ids->status);
     78        if (ids->status != ID_MAPPED) {
     79                composite_error(state->ctx, NT_STATUS_UNSUCCESSFUL);
    8280                return;
    8381        }
    8482
    85         if (ids->unixid->type == ID_TYPE_BOTH ||
    86             ids->unixid->type == ID_TYPE_GID) {
    87                 state->gid = ids->unixid->id;
     83        if (ids->xid.type == ID_TYPE_BOTH ||
     84            ids->xid.type == ID_TYPE_GID) {
     85                state->gid = ids->xid.id;
    8886                composite_done(state->ctx);
    8987        } else {
  • trunk/server/source4/winbind/wb_sid2uid.c

    r414 r745  
    2424#include "winbind/wb_server.h"
    2525#include "smbd/service_task.h"
    26 #include "winbind/wb_helper.h"
    2726#include "libcli/security/security.h"
    28 #include "winbind/idmap.h"
    2927
    3028struct sid2uid_state {
     
    4139        struct composite_context *result, *ctx;
    4240        struct sid2uid_state *state;
    43         struct id_mapping *ids;
     41        struct id_map *ids;
    4442
    4543        DEBUG(5, ("wb_sid2uid_send called\n"));
     
    5553        state->service = service;
    5654
    57         ids = talloc(result, struct id_mapping);
     55        ids = talloc(result, struct id_map);
    5856        if (composite_nomem(ids, result)) return result;
    5957
     
    7371                                                      struct sid2uid_state);
    7472
    75         struct id_mapping *ids = NULL;
     73        struct id_map *ids = NULL;
    7674
    7775        state->ctx->status = wb_sids2xids_recv(ctx, &ids);
    7876        if (!composite_is_ok(state->ctx)) return;
    7977
    80         if (!NT_STATUS_IS_OK(ids->status)) {
    81                 composite_error(state->ctx, ids->status);
     78        if (ids->status != ID_MAPPED) {
     79                composite_error(state->ctx, NT_STATUS_UNSUCCESSFUL);
    8280                return;
    8381        }
    8482
    85         if (ids->unixid->type == ID_TYPE_BOTH ||
    86             ids->unixid->type == ID_TYPE_UID) {
    87                 state->uid = ids->unixid->id;
     83        if (ids->xid.type == ID_TYPE_BOTH ||
     84            ids->xid.type == ID_TYPE_UID) {
     85                state->uid = ids->xid.id;
    8886                composite_done(state->ctx);
    8987        } else {
  • trunk/server/source4/winbind/wb_sids2xids.c

    r414 r745  
    2424#include "winbind/wb_server.h"
    2525#include "smbd/service_task.h"
    26 #include "winbind/wb_helper.h"
    27 #include "libcli/security/proto.h"
    28 #include "winbind/idmap.h"
    2926
    3027struct sids2xids_state {
    3128        struct composite_context *ctx;
    3229        struct wbsrv_service *service;
    33         struct id_mapping *ids;
     30        struct id_map *ids;
    3431        int count;
    3532};
     
    3734struct composite_context *wb_sids2xids_send(TALLOC_CTX *mem_ctx,
    3835                                            struct wbsrv_service *service,
    39                                             int count, struct id_mapping *ids)
     36                                            unsigned int count, struct id_map *ids)
    4037{
    4138        struct composite_context *result;
    4239        struct sids2xids_state *state;
     40        struct id_map **pointer_array;
     41        unsigned int i;
    4342
    4443        DEBUG(5, ("wb_sids2xids_send called\n"));
     
    5655        state->ids = ids;
    5756
     57        /* We need to convert between calling conventions here - the
     58         * values are filled in by reference, so we just need to
     59         * provide pointers to them */
     60        pointer_array = talloc_array(state, struct id_map *, count+1);
     61        if (composite_nomem(pointer_array, result)) return result;
     62
     63        for (i=0; i < count; i++) {
     64                pointer_array[i] = &ids[i];
     65        }
     66        pointer_array[i] = NULL;
     67
    5868        state->ctx->status = idmap_sids_to_xids(service->idmap_ctx, mem_ctx,
    59                                                 count, state->ids);
     69                                                pointer_array);
    6070        if (!composite_is_ok(state->ctx)) return result;
    6171
     
    6575
    6676NTSTATUS wb_sids2xids_recv(struct composite_context *ctx,
    67                            struct id_mapping **ids)
     77                           struct id_map **ids)
    6878{
    6979        NTSTATUS status = composite_wait(ctx);
     
    7383        DEBUG(5, ("wb_sids2xids_recv called\n"));
    7484
     85        /* We don't have to mess with pointer_array on the way out, as
     86         * the results are filled into the pointers the caller
     87         * supplied */
    7588        *ids = state->ids;
    7689
  • trunk/server/source4/winbind/wb_uid2sid.c

    r414 r745  
    2424#include "winbind/wb_server.h"
    2525#include "smbd/service_task.h"
    26 #include "winbind/wb_helper.h"
    27 #include "libcli/security/proto.h"
    28 #include "winbind/idmap.h"
    2926
    3027struct uid2sid_state {
     
    4138        struct composite_context *result, *ctx;
    4239        struct uid2sid_state *state;
    43         struct unixid *unixid;
    44         struct id_mapping *ids;
     40        struct id_map *ids;
    4541
    4642        DEBUG(5, ("wb_uid2sid_send called\n"));
     
    5652        state->service = service;
    5753
    58         unixid = talloc(result, struct unixid);
    59         if (composite_nomem(unixid, result)) return result;
    60         unixid->id = uid;
    61         unixid->type = ID_TYPE_UID;
    62 
    63         ids = talloc(result, struct id_mapping);
     54        ids = talloc(result, struct id_map);
    6455        if (composite_nomem(ids, result)) return result;
    65         ids->unixid = unixid;
    6656        ids->sid = NULL;
     57        ids->xid.id = uid;
     58        ids->xid.type = ID_TYPE_UID;
    6759
    6860        ctx = wb_xids2sids_send(result, service, 1, ids);
     
    7769        struct uid2sid_state *state = talloc_get_type(ctx->async.private_data,
    7870                                                      struct uid2sid_state);
    79         struct id_mapping *ids = NULL;
     71        struct id_map *ids = NULL;
    8072
    8173        state->ctx->status = wb_xids2sids_recv(ctx, &ids);
    8274        if (!composite_is_ok(state->ctx)) return;
    8375
    84         if (!NT_STATUS_IS_OK(ids->status)) {
    85                 composite_error(state->ctx, ids->status);
     76        if (ids->status != ID_MAPPED) {
     77                composite_error(state->ctx, NT_STATUS_UNSUCCESSFUL);
    8678                return;
    8779        }
  • trunk/server/source4/winbind/wb_utils.c

    r414 r745  
    3232                                 char **domain, char **user)
    3333{
    34         char *p = strchr(domuser, *lp_winbind_separator(lp_ctx));
     34        char *p = strchr(domuser, *lpcfg_winbind_separator(lp_ctx));
    3535
    3636        if (p == NULL) {
    37                 *domain = talloc_strdup(mem_ctx, lp_workgroup(lp_ctx));
     37                *domain = talloc_strdup(mem_ctx, lpcfg_workgroup(lp_ctx));
    3838        } else {
    3939                *domain = talloc_strndup(mem_ctx, domuser,
  • trunk/server/source4/winbind/wb_xids2sids.c

    r414 r745  
    2424#include "winbind/wb_server.h"
    2525#include "smbd/service_task.h"
    26 #include "winbind/wb_helper.h"
    27 #include "libcli/security/proto.h"
    28 #include "winbind/idmap.h"
    2926
    3027struct xids2sids_state {
    3128        struct composite_context *ctx;
    3229        struct wbsrv_service *service;
    33         struct id_mapping *ids;
     30        struct id_map *ids;
    3431        int count;
    3532};
     
    3734struct composite_context *wb_xids2sids_send(TALLOC_CTX *mem_ctx,
    3835                                            struct wbsrv_service *service,
    39                                             int count, struct id_mapping *ids)
     36                                            unsigned int count, struct id_map *ids)
    4037{
    4138        struct composite_context *result;
    4239        struct xids2sids_state *state;
     40        struct id_map **pointer_array;
     41        unsigned int i;
    4342
    4443        DEBUG(5, ("wb_xids2sids_send called\n"));
     
    5655        state->ids = ids;
    5756
     57        /* We need to convert between calling conventions here - the
     58         * values are filled in by reference, so we just need to
     59         * provide pointers to them */
     60        pointer_array = talloc_array(state, struct id_map *, count+1);
     61        if (composite_nomem(pointer_array, result)) return result;
     62
     63        for (i=0; i < count; i++) {
     64                pointer_array[i] = &ids[i];
     65        }
     66        pointer_array[i] = NULL;
     67
    5868        state->ctx->status = idmap_xids_to_sids(service->idmap_ctx, mem_ctx,
    59                                                 count, state->ids);
     69                                                pointer_array);
    6070        if (!composite_is_ok(state->ctx)) return result;
    6171
     
    6575
    6676NTSTATUS wb_xids2sids_recv(struct composite_context *ctx,
    67                            struct id_mapping **ids)
     77                           struct id_map **ids)
    6878{
    6979        NTSTATUS status = composite_wait(ctx);
     
    7383        DEBUG(5, ("wb_xids2sids_recv called.\n"));
    7484
     85        /* We don't have to mess with pointer_array on the way out, as
     86         * the results are filled into the pointers the caller
     87         * supplied */
    7588        *ids = state->ids;
    7689
Note: See TracChangeset for help on using the changeset viewer.