s3:winbind: Add a lower-cost alternative to wbinfo -t: wbinfo --ping-dc
authorVolker Lendecke <vl@samba.org>
Mon, 21 Dec 2009 20:50:43 +0000 (21:50 +0100)
committerVolker Lendecke <vl@samba.org>
Mon, 21 Dec 2009 22:23:52 +0000 (23:23 +0100)
This just does a NULL RPC call through an existing NETLOGON connection. If
someone knows an operation that "just works" and does not return NOT_SUPPORTED,
please tell me :-)

17 files changed:
nsswitch/libwbclient/wbc_pam.c
nsswitch/libwbclient/wbclient.h
nsswitch/wbinfo.c
nsswitch/winbind_struct_protocol.h
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_ping_dc.c [new file with mode: 0644]
source3/winbindd/winbindd_proto.h

index 7a66a7fe82675c538bd058981b1b5c1875bfb49d..00863a0d54a85066ccd606adb2fd7a2e2692be20 100644 (file)
@@ -5,6 +5,7 @@
 
    Copyright (C) Gerald (Jerry) Carter 2007
    Copyright (C) Guenther Deschner 2008
 
    Copyright (C) Gerald (Jerry) Carter 2007
    Copyright (C) Guenther Deschner 2008
+   Copyright (C) Volker Lendecke 2009
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -570,6 +571,50 @@ wbcErr wbcChangeTrustCredentials(const char *domain,
        return wbc_status;
 }
 
        return wbc_status;
 }
 
+/*
+ * Trigger a no-op NETLOGON call. Lightweight version of
+ * wbcCheckTrustCredentials
+ */
+wbcErr wbcPingDc(const char *domain, struct wbcAuthErrorInfo **error)
+{
+       struct winbindd_request request;
+       struct winbindd_response response;
+       wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+
+       if (domain) {
+               /*
+                * the current protocol doesn't support
+                * specifying a domain
+                */
+               wbc_status = WBC_ERR_NOT_IMPLEMENTED;
+               BAIL_ON_WBC_ERROR(wbc_status);
+       }
+
+       ZERO_STRUCT(request);
+       ZERO_STRUCT(response);
+
+       /* Send request */
+
+       wbc_status = wbcRequestResponse(WINBINDD_PING_DC,
+                                       &request,
+                                       &response);
+       if (response.data.auth.nt_status != 0) {
+               if (error) {
+                       wbc_status = wbc_create_error_info(NULL,
+                                                          &response,
+                                                          error);
+                       BAIL_ON_WBC_ERROR(wbc_status);
+               }
+
+               wbc_status = WBC_ERR_AUTH_ERROR;
+               BAIL_ON_WBC_ERROR(wbc_status);
+       }
+       BAIL_ON_WBC_ERROR(wbc_status);
+
+ done:
+       return wbc_status;
+}
+
 /* Trigger an extended logoff notification to Winbind for a specific user */
 wbcErr wbcLogoffUserEx(const struct wbcLogoffUserParams *params,
                       struct wbcAuthErrorInfo **error)
 /* Trigger an extended logoff notification to Winbind for a specific user */
 wbcErr wbcLogoffUserEx(const struct wbcLogoffUserParams *params,
                       struct wbcAuthErrorInfo **error)
index eea71ab86bedfd8b8c3f91a1b55b8af4d04a40f6..33a4ace75c9b95f18a7469911e9276c0d2be05fe 100644 (file)
@@ -4,6 +4,7 @@
    Winbind client API
 
    Copyright (C) Gerald (Jerry) Carter 2007
    Winbind client API
 
    Copyright (C) Gerald (Jerry) Carter 2007
+   Copyright (C) Volker Lendecke 2009
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -1214,6 +1215,19 @@ wbcErr wbcCheckTrustCredentials(const char *domain,
 wbcErr wbcChangeTrustCredentials(const char *domain,
                                 struct wbcAuthErrorInfo **error);
 
 wbcErr wbcChangeTrustCredentials(const char *domain,
                                 struct wbcAuthErrorInfo **error);
 
+/**
+ * @brief Trigger a no-op call through the NETLOGON pipe. Low-cost
+ *        version of wbcCheckTrustCredentials
+ *
+ * @param *domain      The name of the domain, only NULL for the default domain is
+ *                     supported yet. Other values than NULL will result in
+ *                     WBC_ERR_NOT_IMPLEMENTED.
+ * @param error        Output details on WBC_ERR_AUTH_ERROR
+ *
+ * @return #wbcErr
+ **/
+wbcErr wbcPingDc(const char *domain, struct wbcAuthErrorInfo **error);
+
 /**********************************************************
  * Helper functions
  **********************************************************/
 /**********************************************************
  * Helper functions
  **********************************************************/
index d3d9250e81f2a8847216b0014cc466f0ec0261c7..45d8684bad9c0562aacd53ef1096bbb4fa844d21 100644 (file)
@@ -5,6 +5,7 @@
 
    Copyright (C) Tim Potter      2000-2003
    Copyright (C) Andrew Bartlett 2002-2007
 
    Copyright (C) Tim Potter      2000-2003
    Copyright (C) Andrew Bartlett 2002-2007
+   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
 
    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
@@ -779,6 +780,30 @@ static bool wbinfo_change_secret(const char *domain)
        return true;
 }
 
        return true;
 }
 
+/* Check DC connection */
+
+static bool wbinfo_ping_dc(void)
+{
+       wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+       struct wbcAuthErrorInfo *error = NULL;
+
+       wbc_status = wbcPingDc(NULL, &error);
+
+       d_printf("checking the NETLOGON dc connection %s\n",
+                WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
+
+       if (wbc_status == WBC_ERR_AUTH_ERROR) {
+               d_fprintf(stderr, "error code was %s (0x%x)\n",
+                         error->nt_string, error->nt_status);
+               wbcFreeMemory(error);
+       }
+       if (!WBC_ERROR_IS_OK(wbc_status)) {
+               return false;
+       }
+
+       return true;
+}
+
 /* Convert uid to sid */
 
 static bool wbinfo_uid_to_sid(uid_t uid)
 /* Convert uid to sid */
 
 static bool wbinfo_uid_to_sid(uid_t uid)
@@ -1710,6 +1735,7 @@ enum {
        OPT_VERBOSE,
        OPT_ONLINESTATUS,
        OPT_CHANGE_USER_PASSWORD,
        OPT_VERBOSE,
        OPT_ONLINESTATUS,
        OPT_CHANGE_USER_PASSWORD,
+       OPT_PING_DC,
        OPT_SID_TO_FULLNAME,
        OPT_NTLMV2,
        OPT_LANMAN
        OPT_SID_TO_FULLNAME,
        OPT_NTLMV2,
        OPT_LANMAN
@@ -1759,6 +1785,8 @@ int main(int argc, char **argv, char **envp)
                { "remove-gid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_REMOVE_GID_MAPPING, "Remove gid to sid mapping in idmap", "GID,SID" },
                { "check-secret", 't', POPT_ARG_NONE, 0, 't', "Check shared secret" },
                { "change-secret", 'c', POPT_ARG_NONE, 0, 'c', "Change shared secret" },
                { "remove-gid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_REMOVE_GID_MAPPING, "Remove gid to sid mapping in idmap", "GID,SID" },
                { "check-secret", 't', POPT_ARG_NONE, 0, 't', "Check shared secret" },
                { "change-secret", 'c', POPT_ARG_NONE, 0, 'c', "Change shared secret" },
+               { "ping-dc", 0, POPT_ARG_NONE, 0, OPT_PING_DC,
+                 "Check the NETLOGON connection" },
                { "trusted-domains", 'm', POPT_ARG_NONE, 0, 'm', "List trusted domains" },
                { "all-domains", 0, POPT_ARG_NONE, 0, OPT_LIST_ALL_DOMAINS, "List all domains (trusted and own domain)" },
                { "own-domain", 0, POPT_ARG_NONE, 0, OPT_LIST_OWN_DOMAIN, "List own domain" },
                { "trusted-domains", 'm', POPT_ARG_NONE, 0, 'm', "List trusted domains" },
                { "all-domains", 0, POPT_ARG_NONE, 0, OPT_LIST_ALL_DOMAINS, "List all domains (trusted and own domain)" },
                { "own-domain", 0, POPT_ARG_NONE, 0, OPT_LIST_OWN_DOMAIN, "List own domain" },
@@ -1995,6 +2023,12 @@ int main(int argc, char **argv, char **envp)
                                goto done;
                        }
                        break;
                                goto done;
                        }
                        break;
+               case OPT_PING_DC:
+                       if (!wbinfo_ping_dc()) {
+                               d_fprintf(stderr, "Could not ping our DC\n");
+                               goto done;
+                       }
+                       break;
                case 'm':
                        if (!wbinfo_list_domains(false, verbose)) {
                                d_fprintf(stderr,
                case 'm':
                        if (!wbinfo_list_domains(false, verbose)) {
                                d_fprintf(stderr,
index 3056e25905e49bc1a0abb35072e9343a31775a7a..4d27d5283c81e9b43b0632ee5a0831263d897147 100644 (file)
@@ -47,8 +47,9 @@ typedef char fstring[FSTRING_LEN];
 /* Update this when you change the interface.
  * 21: added WINBINDD_GETPWSID
  *     added WINBINDD_GETSIDALIASES
 /* Update this when you change the interface.
  * 21: added WINBINDD_GETPWSID
  *     added WINBINDD_GETSIDALIASES
+ * 22: added WINBINDD_PING_DC
  */
  */
-#define WINBIND_INTERFACE_VERSION 21
+#define WINBIND_INTERFACE_VERSION 22
 
 /* Have to deal with time_t being 4 or 8 bytes due to structure alignment.
    On a 64bit Linux box, we have to support a constant structure size
 
 /* Have to deal with time_t being 4 or 8 bytes due to structure alignment.
    On a 64bit Linux box, we have to support a constant structure size
@@ -119,6 +120,7 @@ enum winbindd_cmd {
 
        WINBINDD_CHECK_MACHACC,     /* Check machine account pw works */
        WINBINDD_CHANGE_MACHACC,    /* Change machine account pw */
 
        WINBINDD_CHECK_MACHACC,     /* Check machine account pw works */
        WINBINDD_CHANGE_MACHACC,    /* Change machine account pw */
+       WINBINDD_PING_DC,           /* Ping the DC through NETLOGON */
        WINBINDD_PING,              /* Just tell me winbind is running */
        WINBINDD_INFO,              /* Various bit of info.  Currently just tidbits */
        WINBINDD_DOMAIN_NAME,       /* The domain this winbind server is a member of (lp_workgroup()) */
        WINBINDD_PING,              /* Just tell me winbind is running */
        WINBINDD_INFO,              /* Various bit of info.  Currently just tidbits */
        WINBINDD_DOMAIN_NAME,       /* The domain this winbind server is a member of (lp_workgroup()) */
index 071cb8cf94e567340e8f141d4c929fb1c68c70ff..59ffa24e277ffb06fe91a36e0996f2ac0739c1dc 100644 (file)
@@ -1225,6 +1225,7 @@ WINBINDD_OBJ1 = \
                winbindd/winbindd_list_groups.o \
                winbindd/winbindd_check_machine_acct.o \
                winbindd/winbindd_change_machine_acct.o \
                winbindd/winbindd_list_groups.o \
                winbindd/winbindd_check_machine_acct.o \
                winbindd/winbindd_change_machine_acct.o \
+               winbindd/winbindd_ping_dc.o \
                winbindd/winbindd_set_mapping.o \
                winbindd/winbindd_remove_mapping.o \
                winbindd/winbindd_set_hwm.o \
                winbindd/winbindd_set_mapping.o \
                winbindd/winbindd_remove_mapping.o \
                winbindd/winbindd_set_hwm.o \
index 3115a20d9df9f3bbbadc4fdf2d1cd745461d0d15..592b27b50dbf7dd138e5dbb18a02181b40a73a2d 100644 (file)
@@ -2901,6 +2901,136 @@ NTSTATUS rpccli_wbint_ChangeMachineAccount(struct rpc_pipe_client *cli,
        return r.out.result;
 }
 
        return r.out.result;
 }
 
+struct rpccli_wbint_PingDc_state {
+       struct wbint_PingDc orig;
+       struct wbint_PingDc tmp;
+       TALLOC_CTX *out_mem_ctx;
+       NTSTATUS (*dispatch_recv)(struct tevent_req *req, TALLOC_CTX *mem_ctx);
+};
+
+static void rpccli_wbint_PingDc_done(struct tevent_req *subreq);
+
+struct tevent_req *rpccli_wbint_PingDc_send(TALLOC_CTX *mem_ctx,
+                                           struct tevent_context *ev,
+                                           struct rpc_pipe_client *cli)
+{
+       struct tevent_req *req;
+       struct rpccli_wbint_PingDc_state *state;
+       struct tevent_req *subreq;
+
+       req = tevent_req_create(mem_ctx, &state,
+                               struct rpccli_wbint_PingDc_state);
+       if (req == NULL) {
+               return NULL;
+       }
+       state->out_mem_ctx = NULL;
+       state->dispatch_recv = cli->dispatch_recv;
+
+       /* In parameters */
+
+       /* Out parameters */
+
+       /* Result */
+       ZERO_STRUCT(state->orig.out.result);
+
+       /* 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_PINGDC,
+                                   &state->tmp);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, rpccli_wbint_PingDc_done, req);
+       return req;
+}
+
+static void rpccli_wbint_PingDc_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct rpccli_wbint_PingDc_state *state = tevent_req_data(
+               req, struct rpccli_wbint_PingDc_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);
+
+       tevent_req_done(req);
+}
+
+NTSTATUS rpccli_wbint_PingDc_recv(struct tevent_req *req,
+                                 TALLOC_CTX *mem_ctx,
+                                 NTSTATUS *result)
+{
+       struct rpccli_wbint_PingDc_state *state = tevent_req_data(
+               req, struct rpccli_wbint_PingDc_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_PingDc(struct rpc_pipe_client *cli,
+                            TALLOC_CTX *mem_ctx)
+{
+       struct wbint_PingDc r;
+       NTSTATUS status;
+
+       /* In parameters */
+
+       status = cli->dispatch(cli,
+                               mem_ctx,
+                               &ndr_table_wbint,
+                               NDR_WBINT_PINGDC,
+                               &r);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       if (NT_STATUS_IS_ERR(status)) {
+               return status;
+       }
+
+       /* Return variables */
+
+       /* Return result */
+       return r.out.result;
+}
+
 struct rpccli_wbint_SetMapping_state {
        struct wbint_SetMapping orig;
        struct wbint_SetMapping tmp;
 struct rpccli_wbint_SetMapping_state {
        struct wbint_SetMapping orig;
        struct wbint_SetMapping tmp;
index b08ef3fef14af297c7ca591502c7a7fe7438deb3..4528d43efc2eb46013268fc36716f814f7af409c 100644 (file)
@@ -248,6 +248,14 @@ NTSTATUS rpccli_wbint_ChangeMachineAccount_recv(struct tevent_req *req,
                                                NTSTATUS *result);
 NTSTATUS rpccli_wbint_ChangeMachineAccount(struct rpc_pipe_client *cli,
                                           TALLOC_CTX *mem_ctx);
                                                NTSTATUS *result);
 NTSTATUS rpccli_wbint_ChangeMachineAccount(struct rpc_pipe_client *cli,
                                           TALLOC_CTX *mem_ctx);
+struct tevent_req *rpccli_wbint_PingDc_send(TALLOC_CTX *mem_ctx,
+                                           struct tevent_context *ev,
+                                           struct rpc_pipe_client *cli);
+NTSTATUS rpccli_wbint_PingDc_recv(struct tevent_req *req,
+                                 TALLOC_CTX *mem_ctx,
+                                 NTSTATUS *result);
+NTSTATUS rpccli_wbint_PingDc(struct rpc_pipe_client *cli,
+                            TALLOC_CTX *mem_ctx);
 struct tevent_req *rpccli_wbint_SetMapping_send(TALLOC_CTX *mem_ctx,
                                                struct tevent_context *ev,
                                                struct rpc_pipe_client *cli,
 struct tevent_req *rpccli_wbint_SetMapping_send(TALLOC_CTX *mem_ctx,
                                                struct tevent_context *ev,
                                                struct rpc_pipe_client *cli,
index 97b29761ee3c47ab39b6de5da6837c101bfbb9d1..50f781cc208c43f646d35ce7c4beb9d22ce2b3f7 100644 (file)
@@ -2232,6 +2232,47 @@ _PUBLIC_ void ndr_print_wbint_ChangeMachineAccount(struct ndr_print *ndr, const
        ndr->depth--;
 }
 
        ndr->depth--;
 }
 
+static enum ndr_err_code ndr_push_wbint_PingDc(struct ndr_push *ndr, int flags, const struct wbint_PingDc *r)
+{
+       if (flags & NDR_IN) {
+       }
+       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_PingDc(struct ndr_pull *ndr, int flags, struct wbint_PingDc *r)
+{
+       if (flags & NDR_IN) {
+       }
+       if (flags & NDR_OUT) {
+               NDR_CHECK(ndr_pull_NTSTATUS(ndr, NDR_SCALARS, &r->out.result));
+       }
+       return NDR_ERR_SUCCESS;
+}
+
+_PUBLIC_ void ndr_print_wbint_PingDc(struct ndr_print *ndr, const char *name, int flags, const struct wbint_PingDc *r)
+{
+       ndr_print_struct(ndr, name, "wbint_PingDc");
+       ndr->depth++;
+       if (flags & NDR_SET_VALUES) {
+               ndr->flags |= LIBNDR_PRINT_SET_VALUES;
+       }
+       if (flags & NDR_IN) {
+               ndr_print_struct(ndr, "in", "wbint_PingDc");
+               ndr->depth++;
+               ndr->depth--;
+       }
+       if (flags & NDR_OUT) {
+               ndr_print_struct(ndr, "out", "wbint_PingDc");
+               ndr->depth++;
+               ndr_print_NTSTATUS(ndr, "result", r->out.result);
+               ndr->depth--;
+       }
+       ndr->depth--;
+}
+
 static enum ndr_err_code ndr_push_wbint_SetMapping(struct ndr_push *ndr, int flags, const struct wbint_SetMapping *r)
 {
        if (flags & NDR_IN) {
 static enum ndr_err_code ndr_push_wbint_SetMapping(struct ndr_push *ndr, int flags, const struct wbint_SetMapping *r)
 {
        if (flags & NDR_IN) {
@@ -2566,6 +2607,14 @@ static const struct ndr_interface_call wbint_calls[] = {
                (ndr_print_function_t) ndr_print_wbint_ChangeMachineAccount,
                false,
        },
                (ndr_print_function_t) ndr_print_wbint_ChangeMachineAccount,
                false,
        },
+       {
+               "wbint_PingDc",
+               sizeof(struct wbint_PingDc),
+               (ndr_push_flags_fn_t) ndr_push_wbint_PingDc,
+               (ndr_pull_flags_fn_t) ndr_pull_wbint_PingDc,
+               (ndr_print_function_t) ndr_print_wbint_PingDc,
+               false,
+       },
        {
                "wbint_SetMapping",
                sizeof(struct wbint_SetMapping),
        {
                "wbint_SetMapping",
                sizeof(struct wbint_SetMapping),
@@ -2619,7 +2668,7 @@ const struct ndr_interface_table ndr_table_wbint = {
                NDR_WBINT_VERSION
        },
        .helpstring     = NDR_WBINT_HELPSTRING,
                NDR_WBINT_VERSION
        },
        .helpstring     = NDR_WBINT_HELPSTRING,
-       .num_calls      = 23,
+       .num_calls      = 24,
        .calls          = wbint_calls,
        .endpoints      = &wbint_endpoints,
        .authservices   = &wbint_authservices
        .calls          = wbint_calls,
        .endpoints      = &wbint_endpoints,
        .authservices   = &wbint_authservices
index e163ff367478fef84fff6579e8f9db6ecaa064ae..4a381ccfb238dbf3dc8bec11cf2ad53cb8b705fe 100644 (file)
@@ -51,13 +51,15 @@ extern const struct ndr_interface_table ndr_table_wbint;
 
 #define NDR_WBINT_CHANGEMACHINEACCOUNT (0x13)
 
 
 #define NDR_WBINT_CHANGEMACHINEACCOUNT (0x13)
 
-#define NDR_WBINT_SETMAPPING (0x14)
+#define NDR_WBINT_PINGDC (0x14)
 
 
-#define NDR_WBINT_REMOVEMAPPING (0x15)
+#define NDR_WBINT_SETMAPPING (0x15)
 
 
-#define NDR_WBINT_SETHWM (0x16)
+#define NDR_WBINT_REMOVEMAPPING (0x16)
 
 
-#define NDR_WBINT_CALL_COUNT (23)
+#define NDR_WBINT_SETHWM (0x17)
+
+#define NDR_WBINT_CALL_COUNT (24)
 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);
 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);
@@ -99,6 +101,7 @@ 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_ChangeMachineAccount(struct ndr_print *ndr, const char *name, int flags, const struct wbint_ChangeMachineAccount *r);
 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_ChangeMachineAccount(struct ndr_print *ndr, const char *name, int flags, const struct wbint_ChangeMachineAccount *r);
+void ndr_print_wbint_PingDc(struct ndr_print *ndr, const char *name, int flags, const struct wbint_PingDc *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);
 void ndr_print_wbint_SetHWM(struct ndr_print *ndr, const char *name, int flags, const struct wbint_SetHWM *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);
 void ndr_print_wbint_SetHWM(struct ndr_print *ndr, const char *name, int flags, const struct wbint_SetHWM *r);
index 0f39cd93e19d0e5335ae944f8a587d169c67c270..efd9be6b7a5519c126679366f0b705878d5b71f6 100644 (file)
@@ -1610,6 +1610,79 @@ static bool api_wbint_ChangeMachineAccount(pipes_struct *p)
        return true;
 }
 
        return true;
 }
 
+static bool api_wbint_PingDc(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_PingDc *r;
+
+       call = &ndr_table_wbint.calls[NDR_WBINT_PINGDC];
+
+       r = talloc(talloc_tos(), struct wbint_PingDc);
+       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_PingDc, r);
+       }
+
+       r->out.result = _wbint_PingDc(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_PingDc, 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;
+}
+
 static bool api_wbint_SetMapping(pipes_struct *p)
 {
        const struct ndr_interface_call *call;
 static bool api_wbint_SetMapping(pipes_struct *p)
 {
        const struct ndr_interface_call *call;
@@ -1853,6 +1926,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_CHANGEMACHINEACCOUNT", NDR_WBINT_CHANGEMACHINEACCOUNT, api_wbint_ChangeMachineAccount},
        {"WBINT_LOOKUPRIDS", NDR_WBINT_LOOKUPRIDS, api_wbint_LookupRids},
        {"WBINT_CHECKMACHINEACCOUNT", NDR_WBINT_CHECKMACHINEACCOUNT, api_wbint_CheckMachineAccount},
        {"WBINT_CHANGEMACHINEACCOUNT", NDR_WBINT_CHANGEMACHINEACCOUNT, api_wbint_ChangeMachineAccount},
+       {"WBINT_PINGDC", NDR_WBINT_PINGDC, api_wbint_PingDc},
        {"WBINT_SETMAPPING", NDR_WBINT_SETMAPPING, api_wbint_SetMapping},
        {"WBINT_REMOVEMAPPING", NDR_WBINT_REMOVEMAPPING, api_wbint_RemoveMapping},
        {"WBINT_SETHWM", NDR_WBINT_SETHWM, api_wbint_SetHWM},
        {"WBINT_SETMAPPING", NDR_WBINT_SETMAPPING, api_wbint_SetMapping},
        {"WBINT_REMOVEMAPPING", NDR_WBINT_REMOVEMAPPING, api_wbint_RemoveMapping},
        {"WBINT_SETHWM", NDR_WBINT_SETHWM, api_wbint_SetHWM},
@@ -2115,6 +2189,12 @@ NTSTATUS rpc_wbint_dispatch(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, co
                        return NT_STATUS_OK;
                }
 
                        return NT_STATUS_OK;
                }
 
+               case NDR_WBINT_PINGDC: {
+                       struct wbint_PingDc *r = (struct wbint_PingDc *)_r;
+                       r->out.result = _wbint_PingDc(cli->pipes_struct, r);
+                       return NT_STATUS_OK;
+               }
+
                case NDR_WBINT_SETMAPPING: {
                        struct wbint_SetMapping *r = (struct wbint_SetMapping *)_r;
                        r->out.result = _wbint_SetMapping(cli->pipes_struct, r);
                case NDR_WBINT_SETMAPPING: {
                        struct wbint_SetMapping *r = (struct wbint_SetMapping *)_r;
                        r->out.result = _wbint_SetMapping(cli->pipes_struct, r);
index c8c04fb3cc6b4712b5d390b2b19f1aeb82c741d8..716f1ac9d14abd4cf1c195d2805e007b51e57e2e 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_ChangeMachineAccount(pipes_struct *p, struct wbint_ChangeMachineAccount *r);
 NTSTATUS _wbint_LookupRids(pipes_struct *p, struct wbint_LookupRids *r);
 NTSTATUS _wbint_CheckMachineAccount(pipes_struct *p, struct wbint_CheckMachineAccount *r);
 NTSTATUS _wbint_ChangeMachineAccount(pipes_struct *p, struct wbint_ChangeMachineAccount *r);
+NTSTATUS _wbint_PingDc(pipes_struct *p, struct wbint_PingDc *r);
 NTSTATUS _wbint_SetMapping(pipes_struct *p, struct wbint_SetMapping *r);
 NTSTATUS _wbint_RemoveMapping(pipes_struct *p, struct wbint_RemoveMapping *r);
 NTSTATUS _wbint_SetHWM(pipes_struct *p, struct wbint_SetHWM *r);
 NTSTATUS _wbint_SetMapping(pipes_struct *p, struct wbint_SetMapping *r);
 NTSTATUS _wbint_RemoveMapping(pipes_struct *p, struct wbint_RemoveMapping *r);
 NTSTATUS _wbint_SetHWM(pipes_struct *p, struct wbint_SetHWM *r);
@@ -46,6 +47,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_ChangeMachineAccount(pipes_struct *p, struct wbint_ChangeMachineAccount *r);
 NTSTATUS _wbint_LookupRids(pipes_struct *p, struct wbint_LookupRids *r);
 NTSTATUS _wbint_CheckMachineAccount(pipes_struct *p, struct wbint_CheckMachineAccount *r);
 NTSTATUS _wbint_ChangeMachineAccount(pipes_struct *p, struct wbint_ChangeMachineAccount *r);
+NTSTATUS _wbint_PingDc(pipes_struct *p, struct wbint_PingDc *r);
 NTSTATUS _wbint_SetMapping(pipes_struct *p, struct wbint_SetMapping *r);
 NTSTATUS _wbint_RemoveMapping(pipes_struct *p, struct wbint_RemoveMapping *r);
 NTSTATUS _wbint_SetHWM(pipes_struct *p, struct wbint_SetHWM *r);
 NTSTATUS _wbint_SetMapping(pipes_struct *p, struct wbint_SetMapping *r);
 NTSTATUS _wbint_RemoveMapping(pipes_struct *p, struct wbint_RemoveMapping *r);
 NTSTATUS _wbint_SetHWM(pipes_struct *p, struct wbint_SetHWM *r);
index 962a87ea2640525ee7776d4e2deb67c1eb1ada29..96b7800624f10173b85a6c4b58b24b1461de51c9 100644 (file)
@@ -303,6 +303,14 @@ struct wbint_ChangeMachineAccount {
 };
 
 
 };
 
 
+struct wbint_PingDc {
+       struct {
+               NTSTATUS result;
+       } out;
+
+};
+
+
 struct wbint_SetMapping {
        struct {
                struct dom_sid *sid;/* [ref] */
 struct wbint_SetMapping {
        struct {
                struct dom_sid *sid;/* [ref] */
index e44f179723d3801a404fa7300ae809a367d46467..432d59e08616400d1a44b219baa99909412bdcd5 100644 (file)
@@ -150,6 +150,9 @@ interface wbint
     NTSTATUS wbint_ChangeMachineAccount(
        );
 
     NTSTATUS wbint_ChangeMachineAccount(
        );
 
+    NTSTATUS wbint_PingDc(
+       );
+
     typedef [public] enum {
        WBINT_ID_TYPE_NOT_SPECIFIED,
        WBINT_ID_TYPE_UID,
     typedef [public] enum {
        WBINT_ID_TYPE_NOT_SPECIFIED,
        WBINT_ID_TYPE_UID,
index e09374c5cb1842baf5e2f5200e2c1fba9047f90c..597957d9d69df27412ae58fc4a124d628e18d87d 100644 (file)
@@ -532,6 +532,8 @@ static struct winbindd_async_dispatch_table async_nonpriv_table[] = {
          winbindd_list_groups_send, winbindd_list_groups_recv },
        { WINBINDD_CHECK_MACHACC, "CHECK_MACHACC",
          winbindd_check_machine_acct_send, winbindd_check_machine_acct_recv },
          winbindd_list_groups_send, winbindd_list_groups_recv },
        { WINBINDD_CHECK_MACHACC, "CHECK_MACHACC",
          winbindd_check_machine_acct_send, winbindd_check_machine_acct_recv },
+       { WINBINDD_PING_DC, "PING_DC",
+         winbindd_ping_dc_send, winbindd_ping_dc_recv },
 
        { 0, NULL, NULL, NULL }
 };
 
        { 0, NULL, NULL, NULL }
 };
index cecbb61051509960ff6b0990132515a6b28eb9f4..b247d5a233f0325f99f38797d478d90ca36280db 100644 (file)
@@ -510,6 +510,54 @@ again:
        return status;
 }
 
        return status;
 }
 
+NTSTATUS _wbint_PingDc(pipes_struct *p, struct wbint_PingDc *r)
+{
+       NTSTATUS status;
+       struct winbindd_domain *domain;
+       struct rpc_pipe_client *netlogon_pipe;
+       union netr_CONTROL_QUERY_INFORMATION info;
+       WERROR werr;
+       fstring logon_server;
+
+       domain = wb_child_domain();
+       if (domain == NULL) {
+               return NT_STATUS_REQUEST_NOT_ACCEPTED;
+       }
+
+       status = cm_connect_netlogon(domain, &netlogon_pipe);
+        if (!NT_STATUS_IS_OK(status)) {
+                DEBUG(3, ("could not open handle to NETLOGON pipe\n"));
+               return status;
+        }
+
+       fstr_sprintf(logon_server, "\\\\%s", domain->dcname);
+
+       /*
+        * This provokes a WERR_NOT_SUPPORTED error message. This is
+        * documented in the wspp docs. I could not get a successful
+        * call to work, but the main point here is testing that the
+        * netlogon pipe works.
+        */
+       status = rpccli_netr_LogonControl(netlogon_pipe, p->mem_ctx,
+                                         logon_server, NETLOGON_CONTROL_QUERY,
+                                         2, &info, &werr);
+
+       if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
+               DEBUG(2, ("rpccli_netr_LogonControl timed out\n"));
+               invalidate_cm_connection(&domain->conn);
+               return status;
+       }
+
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_CTL_FILE_NOT_SUPPORTED)) {
+               DEBUG(2, ("rpccli_netr_LogonControl returned %s, expected "
+                         "NT_STATUS_CTL_FILE_NOT_SUPPORTED\n",
+                         nt_errstr(status)));
+               return status;
+       }
+
+       DEBUG(5, ("winbindd_dual_ping_dc succeeded\n"));
+       return NT_STATUS_OK;
+}
 
 NTSTATUS _wbint_SetMapping(pipes_struct *p, struct wbint_SetMapping *r)
 {
 
 NTSTATUS _wbint_SetMapping(pipes_struct *p, struct wbint_SetMapping *r)
 {
diff --git a/source3/winbindd/winbindd_ping_dc.c b/source3/winbindd/winbindd_ping_dc.c
new file mode 100644 (file)
index 0000000..e06e589
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+   Unix SMB/CIFS implementation.
+   async implementation of WINBINDD_PING_DC
+   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_ping_dc_state {
+       uint8_t dummy;
+};
+
+static void winbindd_ping_dc_done(struct tevent_req *subreq);
+
+struct tevent_req *winbindd_ping_dc_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_ping_dc_state *state;
+       struct winbindd_domain *domain;
+
+       req = tevent_req_create(mem_ctx, &state,
+                               struct winbindd_ping_dc_state);
+       if (req == NULL) {
+               return NULL;
+       }
+
+       if (request->domain_name[0] == '\0') {
+               /* preserve old behavior, when no domain name is given */
+               domain = find_our_domain();
+       } else {
+               domain = find_domain_from_name(request->domain_name);
+       }
+       if (domain == NULL) {
+               tevent_req_nterror(req, NT_STATUS_NO_SUCH_DOMAIN);
+               return tevent_req_post(req, ev);
+       }
+       if (domain->internal) {
+               /*
+                * Internal domains are passdb based, we can always
+                * contact them.
+                */
+               tevent_req_done(req);
+               return tevent_req_post(req, ev);
+       }
+
+       subreq = rpccli_wbint_PingDc_send(state, ev, domain->child.rpccli);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, winbindd_ping_dc_done, req);
+       return req;
+}
+
+static void winbindd_ping_dc_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct winbindd_ping_dc_state *state = tevent_req_data(
+               req, struct winbindd_ping_dc_state);
+       NTSTATUS status, result;
+
+       status = rpccli_wbint_PingDc_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;
+       }
+       tevent_req_done(req);
+}
+
+NTSTATUS winbindd_ping_dc_recv(struct tevent_req *req,
+                              struct winbindd_response *presp)
+{
+       return tevent_req_simple_recv_ntstatus(req);
+}
index 5a03f5d3b8a527d06fbb684dcc9415a0e5d5220f..fab31ba60b7e6e76934e48fa07e78fc2dabe6ab7 100644 (file)
@@ -848,6 +848,13 @@ struct tevent_req *winbindd_check_machine_acct_send(TALLOC_CTX *mem_ctx,
 NTSTATUS winbindd_check_machine_acct_recv(struct tevent_req *req,
                                          struct winbindd_response *presp);
 
 NTSTATUS winbindd_check_machine_acct_recv(struct tevent_req *req,
                                          struct winbindd_response *presp);
 
+struct tevent_req *winbindd_ping_dc_send(TALLOC_CTX *mem_ctx,
+                                        struct tevent_context *ev,
+                                        struct winbindd_cli_state *cli,
+                                        struct winbindd_request *request);
+NTSTATUS winbindd_ping_dc_recv(struct tevent_req *req,
+                              struct winbindd_response *presp);
+
 struct tevent_req *winbindd_change_machine_acct_send(TALLOC_CTX *mem_ctx,
                                                     struct tevent_context *ev,
                                                     struct winbindd_cli_state *cli,
 struct tevent_req *winbindd_change_machine_acct_send(TALLOC_CTX *mem_ctx,
                                                     struct tevent_context *ev,
                                                     struct winbindd_cli_state *cli,