r24747: Add WINBINDD_DSGETDCNAME call.
authorGünther Deschner <gd@samba.org>
Tue, 28 Aug 2007 15:20:54 +0000 (15:20 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:30:17 +0000 (12:30 -0500)
Guenther
(This used to be commit 429496a4ccb5c4f4eda11f1b522629889b972c71)

source3/nsswitch/wbinfo.c
source3/nsswitch/winbindd.c
source3/nsswitch/winbindd_dual.c
source3/nsswitch/winbindd_misc.c
source3/nsswitch/winbindd_nss.h

index be51618820ba3fc3db07b6c823cb58315d768da2..5fa07222e27ed4655e4e7196fb2904295b5c6c0b 100644 (file)
@@ -500,6 +500,35 @@ static BOOL wbinfo_getdcname(const char *domain_name)
        return True;
 }
 
+/* Find a DC */
+static BOOL wbinfo_dsgetdcname(const char *domain_name, uint32_t flags)
+{
+       struct winbindd_request request;
+       struct winbindd_response response;
+
+       ZERO_STRUCT(request);
+       ZERO_STRUCT(response);
+
+       fstrcpy(request.domain_name, domain_name);
+       request.flags = flags;
+
+       request.flags |= DS_DIRECTORY_SERVICE_REQUIRED;
+
+       /* Send request */
+
+       if (winbindd_request_response(WINBINDD_DSGETDCNAME, &request, &response) !=
+           NSS_STATUS_SUCCESS) {
+               d_fprintf(stderr, "Could not find dc for %s\n", domain_name);
+               return False;
+       }
+
+       /* Display response */
+
+       d_printf("%s\n", response.data.dc_name);
+
+       return True;
+}
+
 /* Check trust account password */
 
 static BOOL wbinfo_check_secret(void)
@@ -1225,6 +1254,7 @@ enum {
        OPT_DOMAIN_NAME,
        OPT_SEQUENCE,
        OPT_GETDCNAME,
+       OPT_DSGETDCNAME,
        OPT_USERDOMGROUPS,
        OPT_USERSIDS,
        OPT_ALLOCATE_UID,
@@ -1284,6 +1314,7 @@ int main(int argc, char **argv, char **envp)
                { "set-auth-user", 0, POPT_ARG_STRING, &string_arg, OPT_SET_AUTH_USER, "Store user and password used by winbindd (root only)", "user%password" },
                { "getdcname", 0, POPT_ARG_STRING, &string_arg, OPT_GETDCNAME,
                  "Get a DC name for a foreign domain", "domainname" },
+               { "dsgetdcname", 0, POPT_ARG_STRING, &string_arg, OPT_DSGETDCNAME, "Find a DC for a domain", "domainname" },
                { "get-auth-user", 0, POPT_ARG_NONE, NULL, OPT_GET_AUTH_USER, "Retrieve user and password used by winbindd (root only)", NULL },
                { "ping", 'p', POPT_ARG_NONE, 0, 'p', "Ping winbindd to see if it is alive" },
                { "domain", 0, POPT_ARG_STRING, &opt_domain_name, OPT_DOMAIN_NAME, "Define to the domain to restrict operation", "domain" },
@@ -1540,6 +1571,11 @@ int main(int argc, char **argv, char **envp)
                                goto done;
                        }
                        break;
+               case OPT_DSGETDCNAME:
+                       if (!wbinfo_dsgetdcname(string_arg, 0)) {
+                               goto done;
+                       }
+                       break;
                case OPT_SEPARATOR: {
                        const char sep = winbind_separator_int(True);
                        if ( !sep ) {
index f89d86172a162b88b6fadf972d48f8850f7b65bb..3bf054eb4fff4d884558724d338516ecc653423d 100644 (file)
@@ -282,6 +282,7 @@ static struct winbindd_dispatch_table {
        { WINBINDD_PRIV_PIPE_DIR, winbindd_priv_pipe_dir,
          "WINBINDD_PRIV_PIPE_DIR" },
        { WINBINDD_GETDCNAME, winbindd_getdcname, "GETDCNAME" },
+       { WINBINDD_DSGETDCNAME, winbindd_dsgetdcname, "DSGETDCNAME" },
 
        /* Credential cache access */
        { WINBINDD_CCACHE_NTLMAUTH, winbindd_ccache_ntlm_auth, "NTLMAUTH" },
index 8009bee9d458013f3d54af7a1cdab804855a51c6..c6cafe79ec1fe5244c3642d340bf72e444a5e1d1 100644 (file)
@@ -423,6 +423,7 @@ static struct winbindd_child_dispatch_table child_dispatch_table[] = {
        { WINBINDD_LIST_TRUSTDOM,        winbindd_dual_list_trusted_domains,  "LIST_TRUSTDOM" },
        { WINBINDD_INIT_CONNECTION,      winbindd_dual_init_connection,       "INIT_CONNECTION" },
        { WINBINDD_GETDCNAME,            winbindd_dual_getdcname,             "GETDCNAME" },
+       { WINBINDD_DSGETDCNAME,          winbindd_dual_dsgetdcname,           "DSGETDCNAME" },
        { WINBINDD_SHOW_SEQUENCE,        winbindd_dual_show_sequence,         "SHOW_SEQUENCE" },
        { WINBINDD_PAM_AUTH,             winbindd_dual_pam_auth,              "PAM_AUTH" },
        { WINBINDD_PAM_AUTH_CRAP,        winbindd_dual_pam_auth_crap,         "AUTH_CRAP" },
index 35554cf954e25f1f3e02040d590de5c21fcf34a6..8f1e6536196a94e0f0c7d13c28ce441b0f1a3ec3 100644 (file)
@@ -270,6 +270,42 @@ enum winbindd_result winbindd_dual_getdcname(struct winbindd_domain *domain,
        return WINBINDD_OK;
 }
 
+void winbindd_dsgetdcname(struct winbindd_cli_state *state)
+{
+       state->request.domain_name
+               [sizeof(state->request.domain_name)-1] = '\0';
+
+       DEBUG(3, ("[%5lu]: DsGetDcName for %s\n", (unsigned long)state->pid,
+                 state->request.domain_name));
+
+       sendto_domain(state, find_our_domain());
+}
+
+enum winbindd_result winbindd_dual_dsgetdcname(struct winbindd_domain *domain,
+                                              struct winbindd_cli_state *state)
+{
+       NTSTATUS result;
+       struct DS_DOMAIN_CONTROLLER_INFO *info = NULL;
+
+       state->request.domain_name
+               [sizeof(state->request.domain_name)-1] = '\0';
+
+       DEBUG(3, ("[%5lu]: DsGetDcName for %s\n", (unsigned long)state->pid,
+                 state->request.domain_name));
+
+       result = DsGetDcName(state->mem_ctx, NULL, state->request.domain_name,
+                            NULL, NULL, state->request.flags, &info);
+
+       if (!NT_STATUS_IS_OK(result)) {
+               return WINBINDD_ERROR;
+       }
+
+       fstrcpy(state->response.data.dc_name, info->domain_controller_name);
+
+       return WINBINDD_OK;
+}
+
+
 struct sequence_state {
        TALLOC_CTX *mem_ctx;
        struct winbindd_cli_state *cli_state;
index 4b045a27963be9ce2299086daca3f96149a1ceef..46f78ffbe665312fa323103c0822b58189f48ca8 100644 (file)
@@ -123,6 +123,7 @@ enum winbindd_cmd {
        WINBINDD_DOMAIN_INFO,   /* Most of what we know from
                                   struct winbindd_domain */
        WINBINDD_GETDCNAME,     /* Issue a GetDCName Request */
+       WINBINDD_DSGETDCNAME,   /* Issue a DsGetDCName Request */
 
        WINBINDD_SHOW_SEQUENCE, /* display sequence numbers of domains */