s3:winbind: Convert WINBINDD_REMOVE_MAPPING to the new API
authorVolker Lendecke <vl@samba.org>
Sun, 6 Sep 2009 12:59:41 +0000 (14:59 +0200)
committerVolker Lendecke <vl@samba.org>
Sun, 6 Sep 2009 23:28:32 +0000 (01:28 +0200)
15 files changed:
source3/Makefile.in
source3/librpc/gen_ndr/cli_wbint.c
source3/librpc/gen_ndr/cli_wbint.h
source3/librpc/gen_ndr/ndr_wbint.c
source3/librpc/gen_ndr/ndr_wbint.h
source3/librpc/gen_ndr/srv_wbint.c
source3/librpc/gen_ndr/srv_wbint.h
source3/librpc/gen_ndr/wbint.h
source3/librpc/idl/wbint.idl
source3/winbindd/winbindd.c
source3/winbindd/winbindd_dual_srv.c
source3/winbindd/winbindd_idmap.c
source3/winbindd/winbindd_proto.h
source3/winbindd/winbindd_remove_mapping.c [new file with mode: 0644]
source3/winbindd/winbindd_sid.c

index acf2a0f9f808f3019aaef41b277aca42790b3858..b2e33936b78702a57da42120be27edb5a603f94c 100644 (file)
@@ -1215,6 +1215,7 @@ WINBINDD_OBJ1 = \
                winbindd/winbindd_list_groups.o \
                winbindd/winbindd_check_machine_acct.o \
                winbindd/winbindd_set_mapping.o \
+               winbindd/winbindd_remove_mapping.o \
                auth/token_util.o \
                ../nsswitch/libwbclient/wb_reqtrans.o \
                smbd/connection.o
index fc4d13f7e7c0af65605a0ccc61223d4c645f41a0..4a303ee6d7118146426519114bcc8127e8e40d58 100644 (file)
@@ -3233,3 +3233,161 @@ NTSTATUS rpccli_wbint_SetMapping(struct rpc_pipe_client *cli,
        return r.out.result;
 }
 
+struct rpccli_wbint_RemoveMapping_state {
+       struct wbint_RemoveMapping orig;
+       struct wbint_RemoveMapping tmp;
+       TALLOC_CTX *out_mem_ctx;
+       NTSTATUS (*dispatch_recv)(struct tevent_req *req, TALLOC_CTX *mem_ctx);
+};
+
+static void rpccli_wbint_RemoveMapping_done(struct tevent_req *subreq);
+
+struct tevent_req *rpccli_wbint_RemoveMapping_send(TALLOC_CTX *mem_ctx,
+                                                  struct tevent_context *ev,
+                                                  struct rpc_pipe_client *cli,
+                                                  struct dom_sid *_sid /* [in] [ref] */,
+                                                  enum wbint_IdType _type /* [in]  */,
+                                                  uint64_t _id /* [in]  */)
+{
+       struct tevent_req *req;
+       struct rpccli_wbint_RemoveMapping_state *state;
+       struct tevent_req *subreq;
+
+       req = tevent_req_create(mem_ctx, &state,
+                               struct rpccli_wbint_RemoveMapping_state);
+       if (req == NULL) {
+               return NULL;
+       }
+       state->out_mem_ctx = NULL;
+       state->dispatch_recv = cli->dispatch_recv;
+
+       /* In parameters */
+       state->orig.in.sid = _sid;
+       state->orig.in.type = _type;
+       state->orig.in.id = _id;
+
+       /* Out parameters */
+
+       /* Result */
+       ZERO_STRUCT(state->orig.out.result);
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_IN_DEBUG(wbint_RemoveMapping, &state->orig);
+       }
+
+       /* make a temporary copy, that we pass to the dispatch function */
+       state->tmp = state->orig;
+
+       subreq = cli->dispatch_send(state, ev, cli,
+                                   &ndr_table_wbint,
+                                   NDR_WBINT_REMOVEMAPPING,
+                                   &state->tmp);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, rpccli_wbint_RemoveMapping_done, req);
+       return req;
+}
+
+static void rpccli_wbint_RemoveMapping_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct rpccli_wbint_RemoveMapping_state *state = tevent_req_data(
+               req, struct rpccli_wbint_RemoveMapping_state);
+       NTSTATUS status;
+       TALLOC_CTX *mem_ctx;
+
+       if (state->out_mem_ctx) {
+               mem_ctx = state->out_mem_ctx;
+       } else {
+               mem_ctx = state;
+       }
+
+       status = state->dispatch_recv(subreq, mem_ctx);
+       TALLOC_FREE(subreq);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return;
+       }
+
+       /* Copy out parameters */
+
+       /* Copy result */
+       state->orig.out.result = state->tmp.out.result;
+
+       /* Reset temporary structure */
+       ZERO_STRUCT(state->tmp);
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_OUT_DEBUG(wbint_RemoveMapping, &state->orig);
+       }
+
+       tevent_req_done(req);
+}
+
+NTSTATUS rpccli_wbint_RemoveMapping_recv(struct tevent_req *req,
+                                        TALLOC_CTX *mem_ctx,
+                                        NTSTATUS *result)
+{
+       struct rpccli_wbint_RemoveMapping_state *state = tevent_req_data(
+               req, struct rpccli_wbint_RemoveMapping_state);
+       NTSTATUS status;
+
+       if (tevent_req_is_nterror(req, &status)) {
+               tevent_req_received(req);
+               return status;
+       }
+
+       /* Steal possbile out parameters to the callers context */
+       talloc_steal(mem_ctx, state->out_mem_ctx);
+
+       /* Return result */
+       *result = state->orig.out.result;
+
+       tevent_req_received(req);
+       return NT_STATUS_OK;
+}
+
+NTSTATUS rpccli_wbint_RemoveMapping(struct rpc_pipe_client *cli,
+                                   TALLOC_CTX *mem_ctx,
+                                   struct dom_sid *sid /* [in] [ref] */,
+                                   enum wbint_IdType type /* [in]  */,
+                                   uint64_t id /* [in]  */)
+{
+       struct wbint_RemoveMapping r;
+       NTSTATUS status;
+
+       /* In parameters */
+       r.in.sid = sid;
+       r.in.type = type;
+       r.in.id = id;
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_IN_DEBUG(wbint_RemoveMapping, &r);
+       }
+
+       status = cli->dispatch(cli,
+                               mem_ctx,
+                               &ndr_table_wbint,
+                               NDR_WBINT_REMOVEMAPPING,
+                               &r);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_OUT_DEBUG(wbint_RemoveMapping, &r);
+       }
+
+       if (NT_STATUS_IS_ERR(status)) {
+               return status;
+       }
+
+       /* Return variables */
+
+       /* Return result */
+       return r.out.result;
+}
+
index e9408b44f93bcd89be1ce7726296c80951aebfce..e75f9b517c32f5bd409789749e2c7b65cfeec539 100644 (file)
@@ -254,4 +254,18 @@ NTSTATUS rpccli_wbint_SetMapping(struct rpc_pipe_client *cli,
                                 struct dom_sid *sid /* [in] [ref] */,
                                 enum wbint_IdType type /* [in]  */,
                                 uint64_t id /* [in]  */);
+struct tevent_req *rpccli_wbint_RemoveMapping_send(TALLOC_CTX *mem_ctx,
+                                                  struct tevent_context *ev,
+                                                  struct rpc_pipe_client *cli,
+                                                  struct dom_sid *_sid /* [in] [ref] */,
+                                                  enum wbint_IdType _type /* [in]  */,
+                                                  uint64_t _id /* [in]  */);
+NTSTATUS rpccli_wbint_RemoveMapping_recv(struct tevent_req *req,
+                                        TALLOC_CTX *mem_ctx,
+                                        NTSTATUS *result);
+NTSTATUS rpccli_wbint_RemoveMapping(struct rpc_pipe_client *cli,
+                                   TALLOC_CTX *mem_ctx,
+                                   struct dom_sid *sid /* [in] [ref] */,
+                                   enum wbint_IdType type /* [in]  */,
+                                   uint64_t id /* [in]  */);
 #endif /* __CLI_WBINT__ */
index cac05cc72c66d57379fc3c74be50f5e7c0be0e73..40e06b1c0a9d37bde70697f3b8554cc667d2a3c0 100644 (file)
@@ -2241,6 +2241,69 @@ _PUBLIC_ void ndr_print_wbint_SetMapping(struct ndr_print *ndr, const char *name
        ndr->depth--;
 }
 
+static enum ndr_err_code ndr_push_wbint_RemoveMapping(struct ndr_push *ndr, int flags, const struct wbint_RemoveMapping *r)
+{
+       if (flags & NDR_IN) {
+               if (r->in.sid == NULL) {
+                       return ndr_push_error(ndr, NDR_ERR_INVALID_POINTER, "NULL [ref] pointer");
+               }
+               NDR_CHECK(ndr_push_dom_sid(ndr, NDR_SCALARS, r->in.sid));
+               NDR_CHECK(ndr_push_wbint_IdType(ndr, NDR_SCALARS, r->in.type));
+               NDR_CHECK(ndr_push_hyper(ndr, NDR_SCALARS, r->in.id));
+       }
+       if (flags & NDR_OUT) {
+               NDR_CHECK(ndr_push_NTSTATUS(ndr, NDR_SCALARS, r->out.result));
+       }
+       return NDR_ERR_SUCCESS;
+}
+
+static enum ndr_err_code ndr_pull_wbint_RemoveMapping(struct ndr_pull *ndr, int flags, struct wbint_RemoveMapping *r)
+{
+       TALLOC_CTX *_mem_save_sid_0;
+       if (flags & NDR_IN) {
+               if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) {
+                       NDR_PULL_ALLOC(ndr, r->in.sid);
+               }
+               _mem_save_sid_0 = NDR_PULL_GET_MEM_CTX(ndr);
+               NDR_PULL_SET_MEM_CTX(ndr, r->in.sid, LIBNDR_FLAG_REF_ALLOC);
+               NDR_CHECK(ndr_pull_dom_sid(ndr, NDR_SCALARS, r->in.sid));
+               NDR_PULL_SET_MEM_CTX(ndr, _mem_save_sid_0, LIBNDR_FLAG_REF_ALLOC);
+               NDR_CHECK(ndr_pull_wbint_IdType(ndr, NDR_SCALARS, &r->in.type));
+               NDR_CHECK(ndr_pull_hyper(ndr, NDR_SCALARS, &r->in.id));
+       }
+       if (flags & NDR_OUT) {
+               NDR_CHECK(ndr_pull_NTSTATUS(ndr, NDR_SCALARS, &r->out.result));
+       }
+       return NDR_ERR_SUCCESS;
+}
+
+_PUBLIC_ void ndr_print_wbint_RemoveMapping(struct ndr_print *ndr, const char *name, int flags, const struct wbint_RemoveMapping *r)
+{
+       ndr_print_struct(ndr, name, "wbint_RemoveMapping");
+       ndr->depth++;
+       if (flags & NDR_SET_VALUES) {
+               ndr->flags |= LIBNDR_PRINT_SET_VALUES;
+       }
+       if (flags & NDR_IN) {
+               ndr_print_struct(ndr, "in", "wbint_RemoveMapping");
+               ndr->depth++;
+               ndr_print_ptr(ndr, "sid", r->in.sid);
+               ndr->depth++;
+               ndr_print_dom_sid(ndr, "sid", r->in.sid);
+               ndr->depth--;
+               ndr_print_wbint_IdType(ndr, "type", r->in.type);
+               ndr_print_hyper(ndr, "id", r->in.id);
+               ndr->depth--;
+       }
+       if (flags & NDR_OUT) {
+               ndr_print_struct(ndr, "out", "wbint_RemoveMapping");
+               ndr->depth++;
+               ndr_print_NTSTATUS(ndr, "result", r->out.result);
+               ndr->depth--;
+       }
+       ndr->depth--;
+}
+
 static const struct ndr_interface_call wbint_calls[] = {
        {
                "wbint_Ping",
@@ -2402,6 +2465,14 @@ static const struct ndr_interface_call wbint_calls[] = {
                (ndr_print_function_t) ndr_print_wbint_SetMapping,
                false,
        },
+       {
+               "wbint_RemoveMapping",
+               sizeof(struct wbint_RemoveMapping),
+               (ndr_push_flags_fn_t) ndr_push_wbint_RemoveMapping,
+               (ndr_pull_flags_fn_t) ndr_pull_wbint_RemoveMapping,
+               (ndr_print_function_t) ndr_print_wbint_RemoveMapping,
+               false,
+       },
        { NULL, 0, NULL, NULL, NULL, false }
 };
 
@@ -2431,7 +2502,7 @@ const struct ndr_interface_table ndr_table_wbint = {
                NDR_WBINT_VERSION
        },
        .helpstring     = NDR_WBINT_HELPSTRING,
-       .num_calls      = 20,
+       .num_calls      = 21,
        .calls          = wbint_calls,
        .endpoints      = &wbint_endpoints,
        .authservices   = &wbint_authservices
index bff66acbe454d6ea5a8b9fa049489098666d6df0..17fd6ecbce79cf6fc67c894f10eea67cd3e88b35 100644 (file)
@@ -51,7 +51,9 @@ extern const struct ndr_interface_table ndr_table_wbint;
 
 #define NDR_WBINT_SETMAPPING (0x13)
 
-#define NDR_WBINT_CALL_COUNT (20)
+#define NDR_WBINT_REMOVEMAPPING (0x14)
+
+#define NDR_WBINT_CALL_COUNT (21)
 enum ndr_err_code ndr_push_wbint_userinfo(struct ndr_push *ndr, int ndr_flags, const struct wbint_userinfo *r);
 enum ndr_err_code ndr_pull_wbint_userinfo(struct ndr_pull *ndr, int ndr_flags, struct wbint_userinfo *r);
 void ndr_print_wbint_userinfo(struct ndr_print *ndr, const char *name, const struct wbint_userinfo *r);
@@ -93,4 +95,5 @@ void ndr_print_wbint_DsGetDcName(struct ndr_print *ndr, const char *name, int fl
 void ndr_print_wbint_LookupRids(struct ndr_print *ndr, const char *name, int flags, const struct wbint_LookupRids *r);
 void ndr_print_wbint_CheckMachineAccount(struct ndr_print *ndr, const char *name, int flags, const struct wbint_CheckMachineAccount *r);
 void ndr_print_wbint_SetMapping(struct ndr_print *ndr, const char *name, int flags, const struct wbint_SetMapping *r);
+void ndr_print_wbint_RemoveMapping(struct ndr_print *ndr, const char *name, int flags, const struct wbint_RemoveMapping *r);
 #endif /* _HEADER_NDR_wbint */
index e55d19cd0fa5d4d58a3e0f94e14e6a68e619b4ef..1aaf0a5bf8b6544cee6a55548f0443852f727ee5 100644 (file)
@@ -1610,6 +1610,79 @@ static bool api_wbint_SetMapping(pipes_struct *p)
        return true;
 }
 
+static bool api_wbint_RemoveMapping(pipes_struct *p)
+{
+       const struct ndr_interface_call *call;
+       struct ndr_pull *pull;
+       struct ndr_push *push;
+       enum ndr_err_code ndr_err;
+       DATA_BLOB blob;
+       struct wbint_RemoveMapping *r;
+
+       call = &ndr_table_wbint.calls[NDR_WBINT_REMOVEMAPPING];
+
+       r = talloc(talloc_tos(), struct wbint_RemoveMapping);
+       if (r == NULL) {
+               return false;
+       }
+
+       if (!prs_data_blob(&p->in_data.data, &blob, r)) {
+               talloc_free(r);
+               return false;
+       }
+
+       pull = ndr_pull_init_blob(&blob, r, NULL);
+       if (pull == NULL) {
+               talloc_free(r);
+               return false;
+       }
+
+       pull->flags |= LIBNDR_FLAG_REF_ALLOC;
+       ndr_err = call->ndr_pull(pull, NDR_IN, r);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               talloc_free(r);
+               return false;
+       }
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_IN_DEBUG(wbint_RemoveMapping, r);
+       }
+
+       r->out.result = _wbint_RemoveMapping(p, r);
+
+       if (p->rng_fault_state) {
+               talloc_free(r);
+               /* Return true here, srv_pipe_hnd.c will take care */
+               return true;
+       }
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_OUT_DEBUG(wbint_RemoveMapping, r);
+       }
+
+       push = ndr_push_init_ctx(r, NULL);
+       if (push == NULL) {
+               talloc_free(r);
+               return false;
+       }
+
+       ndr_err = call->ndr_push(push, NDR_OUT, r);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               talloc_free(r);
+               return false;
+       }
+
+       blob = ndr_push_blob(push);
+       if (!prs_copy_data_in(&p->out_data.rdata, (const char *)blob.data, (uint32_t)blob.length)) {
+               talloc_free(r);
+               return false;
+       }
+
+       talloc_free(r);
+
+       return true;
+}
+
 
 /* Tables */
 static struct api_struct api_wbint_cmds[] = 
@@ -1634,6 +1707,7 @@ static struct api_struct api_wbint_cmds[] =
        {"WBINT_LOOKUPRIDS", NDR_WBINT_LOOKUPRIDS, api_wbint_LookupRids},
        {"WBINT_CHECKMACHINEACCOUNT", NDR_WBINT_CHECKMACHINEACCOUNT, api_wbint_CheckMachineAccount},
        {"WBINT_SETMAPPING", NDR_WBINT_SETMAPPING, api_wbint_SetMapping},
+       {"WBINT_REMOVEMAPPING", NDR_WBINT_REMOVEMAPPING, api_wbint_RemoveMapping},
 };
 
 void wbint_get_pipe_fns(struct api_struct **fns, int *n_fns)
@@ -1893,6 +1967,12 @@ NTSTATUS rpc_wbint_dispatch(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, co
                        return NT_STATUS_OK;
                }
 
+               case NDR_WBINT_REMOVEMAPPING: {
+                       struct wbint_RemoveMapping *r = (struct wbint_RemoveMapping *)_r;
+                       r->out.result = _wbint_RemoveMapping(cli->pipes_struct, r);
+                       return NT_STATUS_OK;
+               }
+
                default:
                        return NT_STATUS_NOT_IMPLEMENTED;
        }
index b74bb11ded93961324a158bf043fcea692ecdfed..f26c44ba0d1b0979fc396644256ffa0b82845a43 100644 (file)
@@ -21,6 +21,7 @@ NTSTATUS _wbint_DsGetDcName(pipes_struct *p, struct wbint_DsGetDcName *r);
 NTSTATUS _wbint_LookupRids(pipes_struct *p, struct wbint_LookupRids *r);
 NTSTATUS _wbint_CheckMachineAccount(pipes_struct *p, struct wbint_CheckMachineAccount *r);
 NTSTATUS _wbint_SetMapping(pipes_struct *p, struct wbint_SetMapping *r);
+NTSTATUS _wbint_RemoveMapping(pipes_struct *p, struct wbint_RemoveMapping *r);
 void wbint_get_pipe_fns(struct api_struct **fns, int *n_fns);
 NTSTATUS rpc_wbint_dispatch(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, const struct ndr_interface_table *table, uint32_t opnum, void *r);
 void _wbint_Ping(pipes_struct *p, struct wbint_Ping *r);
@@ -43,5 +44,6 @@ NTSTATUS _wbint_DsGetDcName(pipes_struct *p, struct wbint_DsGetDcName *r);
 NTSTATUS _wbint_LookupRids(pipes_struct *p, struct wbint_LookupRids *r);
 NTSTATUS _wbint_CheckMachineAccount(pipes_struct *p, struct wbint_CheckMachineAccount *r);
 NTSTATUS _wbint_SetMapping(pipes_struct *p, struct wbint_SetMapping *r);
+NTSTATUS _wbint_RemoveMapping(pipes_struct *p, struct wbint_RemoveMapping *r);
 NTSTATUS rpc_wbint_init(void);
 #endif /* __SRV_WBINT__ */
index 4be5e46afbbff6cb0e3fd200b0cc20b986421787..dc4fc0c117ac853456ba3de1dae1a84a6e3f78f0 100644 (file)
@@ -307,4 +307,18 @@ struct wbint_SetMapping {
 
 };
 
+
+struct wbint_RemoveMapping {
+       struct {
+               struct dom_sid *sid;/* [ref] */
+               enum wbint_IdType type;
+               uint64_t id;
+       } in;
+
+       struct {
+               NTSTATUS result;
+       } out;
+
+};
+
 #endif /* _HEADER_wbint */
index 642d7f6636dcbb187753edd20eebfc716958e4e2..764d122c6045145d32e3a9c3ab420bfb72ae53aa 100644 (file)
@@ -158,4 +158,10 @@ interface wbint
        [in] wbint_IdType type,
        [in] hyper id
        );
+
+    NTSTATUS wbint_RemoveMapping(
+       [in] dom_sid *sid,
+       [in] wbint_IdType type,
+       [in] hyper id
+       );
 }
\ No newline at end of file
index b29c646631ad901b98ed1d2500290387b7e9b787..f0dc62ef12b8614ca16053c70bb875cdbff4ba7c 100644 (file)
@@ -440,7 +440,6 @@ static struct winbindd_dispatch_table {
 
        /* Lookup related functions */
 
-       { WINBINDD_REMOVE_MAPPING, winbindd_remove_mapping, "REMOVE_MAPPING" },
        { WINBINDD_SET_HWM, winbindd_set_hwm, "SET_HWMS" },
 
        /* Miscellaneous */
@@ -548,6 +547,8 @@ static struct winbindd_async_dispatch_table async_priv_table[] = {
          winbindd_allocate_gid_send, winbindd_allocate_gid_recv },
        { WINBINDD_SET_MAPPING, "SET_MAPPING",
          winbindd_set_mapping_send, winbindd_set_mapping_recv },
+       { WINBINDD_REMOVE_MAPPING, "SET_MAPPING",
+         winbindd_remove_mapping_send, winbindd_remove_mapping_recv },
 
        { 0, NULL, NULL, NULL }
 };
index 2a6f7ce99dbbc9913a94c3cc96eb96e66e21f53a..222fd835af03e510b77e4754ba363c2c716cb2fc 100644 (file)
@@ -469,3 +469,25 @@ NTSTATUS _wbint_SetMapping(pipes_struct *p, struct wbint_SetMapping *r)
 
        return idmap_set_mapping(&map);
 }
+
+NTSTATUS _wbint_RemoveMapping(pipes_struct *p, struct wbint_RemoveMapping *r)
+{
+       struct id_map map;
+
+       map.sid = r->in.sid;
+       map.xid.id = r->in.id;
+       map.status = ID_MAPPED;
+
+       switch (r->in.type) {
+       case WBINT_ID_TYPE_UID:
+               map.xid.type = ID_TYPE_UID;
+               break;
+       case WBINT_ID_TYPE_GID:
+               map.xid.type = ID_TYPE_GID;
+               break;
+       default:
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       return idmap_remove_mapping(&map);
+}
index a59907243f571471fd8b0c7072f9929554e6ffee..423afe174de1e3d5cd8734c0c69961f8cabd4754 100644 (file)
@@ -45,65 +45,6 @@ struct winbindd_child *idmap_child(void)
        return &static_idmap_child;
 }
 
-static void winbindd_remove_mapping_recv(TALLOC_CTX *mem_ctx, bool success,
-                                  struct winbindd_response *response,
-                                  void *c, void *private_data)
-{
-       void (*cont)(void *priv, bool succ) = (void (*)(void *, bool))c;
-
-       if (!success) {
-               DEBUG(5, ("Could not trigger idmap_remove_mapping\n"));
-               cont(private_data, False);
-               return;
-       }
-
-       if (response->result != WINBINDD_OK) {
-               DEBUG(5, ("idmap_remove_mapping returned an error\n"));
-               cont(private_data, False);
-               return;
-       }
-
-       cont(private_data, True);
-}
-
-void winbindd_remove_mapping_async(TALLOC_CTX *mem_ctx,
-                            const struct id_map *map,
-                            void (*cont)(void *private_data, bool success),
-                            void *private_data)
-{
-       struct winbindd_request request;
-       ZERO_STRUCT(request);
-       request.cmd = WINBINDD_DUAL_REMOVE_MAPPING;
-       request.data.dual_idmapset.id = map->xid.id;
-       request.data.dual_idmapset.type = map->xid.type;
-       sid_to_fstring(request.data.dual_idmapset.sid, map->sid);
-
-       do_async(mem_ctx, idmap_child(), &request, winbindd_remove_mapping_recv,
-                (void *)cont, private_data);
-}
-
-enum winbindd_result winbindd_dual_remove_mapping(
-                                           struct winbindd_domain *domain,
-                                           struct winbindd_cli_state *state)
-{
-       struct id_map map;
-       DOM_SID sid;
-       NTSTATUS result;
-
-       DEBUG(3, ("[%5lu]: dual_idmapremove\n", (unsigned long)state->pid));
-
-       if (!string_to_sid(&sid, state->request->data.dual_idmapset.sid))
-               return WINBINDD_ERROR;
-
-       map.sid = &sid;
-       map.xid.id = state->request->data.dual_idmapset.id;
-       map.xid.type = state->request->data.dual_idmapset.type;
-       map.status = ID_MAPPED;
-
-       result = idmap_remove_mapping(&map);
-       return NT_STATUS_IS_OK(result) ? WINBINDD_OK : WINBINDD_ERROR;
-}
-
 static void winbindd_set_hwm_recv(TALLOC_CTX *mem_ctx, bool success,
                                   struct winbindd_response *response,
                                   void *c, void *private_data)
@@ -478,10 +419,6 @@ static const struct winbindd_child_dispatch_table idmap_dispatch_table[] = {
                .name           = "DUAL_GID2SID",
                .struct_cmd     = WINBINDD_DUAL_GID2SID,
                .struct_fn      = winbindd_dual_gid2sid,
-       },{
-               .name           = "DUAL_REMOVE_MAPPING",
-               .struct_cmd     = WINBINDD_DUAL_REMOVE_MAPPING,
-               .struct_fn      = winbindd_dual_remove_mapping,
        },{
                .name           = "DUAL_SET_HWMS",
                .struct_cmd     = WINBINDD_DUAL_SET_HWM,
index 1b99935be13635539bbbfe93a33a2d2018a63431..c5b7d9d4149ffa9a8265d1539b097455159cfbc4 100644 (file)
@@ -976,4 +976,11 @@ struct tevent_req *winbindd_set_mapping_send(TALLOC_CTX *mem_ctx,
 NTSTATUS winbindd_set_mapping_recv(struct tevent_req *req,
                                   struct winbindd_response *response);
 
+struct tevent_req *winbindd_remove_mapping_send(TALLOC_CTX *mem_ctx,
+                                               struct tevent_context *ev,
+                                               struct winbindd_cli_state *cli,
+                                               struct winbindd_request *request);
+NTSTATUS winbindd_remove_mapping_recv(struct tevent_req *req,
+                                     struct winbindd_response *response);
+
 #endif /*  _WINBINDD_PROTO_H_  */
diff --git a/source3/winbindd/winbindd_remove_mapping.c b/source3/winbindd/winbindd_remove_mapping.c
new file mode 100644 (file)
index 0000000..e94f6c2
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+   Unix SMB/CIFS implementation.
+   async implementation of WINBINDD_REMOVE_MAPPING
+   Copyright (C) Volker Lendecke 2009
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "winbindd.h"
+#include "librpc/gen_ndr/cli_wbint.h"
+
+struct winbindd_remove_mapping_state {
+       struct dom_sid sid;
+};
+
+static void winbindd_remove_mapping_done(struct tevent_req *subreq);
+
+struct tevent_req *winbindd_remove_mapping_send(TALLOC_CTX *mem_ctx,
+                                               struct tevent_context *ev,
+                                               struct winbindd_cli_state *cli,
+                                               struct winbindd_request *request)
+{
+       struct tevent_req *req, *subreq;
+       struct winbindd_remove_mapping_state *state;
+       struct winbindd_child *child;
+       enum id_type type;
+
+       req = tevent_req_create(mem_ctx, &state,
+                               struct winbindd_remove_mapping_state);
+       if (req == NULL) {
+               return NULL;
+       }
+
+       /* Ensure null termination */
+       request->data.dual_idmapset.sid[
+               sizeof(request->data.dual_idmapset.sid)-1]='\0';
+
+       DEBUG(3, ("set_mapping %s\n", request->data.dual_idmapset.sid));
+
+       if (!string_to_sid(&state->sid, request->data.dual_idmapset.sid)) {
+               DEBUG(5, ("%s not a SID\n", request->data.dual_idmapset.sid));
+               tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
+               return tevent_req_post(req, ev);
+       }
+
+       switch (request->data.dual_idmapset.type) {
+       case ID_TYPE_UID:
+               type = WBINT_ID_TYPE_UID;
+               break;
+       case ID_TYPE_GID:
+               type = WBINT_ID_TYPE_GID;
+               break;
+       default:
+               tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
+               return tevent_req_post(req, ev);
+       }
+
+       child = idmap_child();
+
+       subreq = rpccli_wbint_RemoveMapping_send(
+               state, ev, child->rpccli, &state->sid, type,
+               request->data.dual_idmapset.id);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, winbindd_remove_mapping_done, req);
+       return req;
+}
+
+static void winbindd_remove_mapping_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct winbindd_remove_mapping_state *state = tevent_req_data(
+               req, struct winbindd_remove_mapping_state);
+       NTSTATUS status, result;
+
+       status = rpccli_wbint_RemoveMapping_recv(subreq, state, &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return;
+       }
+       if (!NT_STATUS_IS_OK(result)) {
+               tevent_req_nterror(req, result);
+               return;
+       }
+       return tevent_req_done(req);
+}
+
+NTSTATUS winbindd_remove_mapping_recv(struct tevent_req *req,
+                                     struct winbindd_response *response)
+{
+       return tevent_req_simple_recv_ntstatus(req);
+}
index 5c9bb4dba9fcca73b4ce00fa2d6d67de03ff8f38..bc058b4c4210884f8134e5285325973e3bb7fa73 100644 (file)
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_WINBIND
 
-static void remove_mapping_recv(void *private_data, bool success)
-{
-       struct winbindd_cli_state *state =
-               talloc_get_type_abort(private_data, struct winbindd_cli_state);
-
-       if (!success) {
-               DEBUG(5, ("Could not remove sid mapping\n"));
-               request_error(state);
-               return;
-       }
-
-       request_ok(state);
-}
-
-void winbindd_remove_mapping(struct winbindd_cli_state *state)
-{
-       struct id_map map;
-       DOM_SID sid;
-
-       DEBUG(3, ("[%5lu]: remove id map\n", (unsigned long)state->pid));
-
-       if ( ! state->privileged) {
-               DEBUG(0, ("Only root is allowed to remove mappings!\n"));
-               request_error(state);
-               return;
-       }
-
-       if (!string_to_sid(&sid, state->request->data.dual_idmapset.sid)) {
-               DEBUG(1, ("Could not get convert sid %s from string\n",
-                         state->request->data.sid));
-               request_error(state);
-               return;
-       }
-
-       map.sid = &sid;
-       map.xid.id = state->request->data.dual_idmapset.id;
-       map.xid.type = state->request->data.dual_idmapset.type;
-
-       winbindd_remove_mapping_async(state->mem_ctx, &map,
-                       remove_mapping_recv, state);
-}
-
 static void set_hwm_recv(void *private_data, bool success)
 {
        struct winbindd_cli_state *state =