WERROR NetGetAnyDCName_r(struct libnetapi_ctx *ctx,
                         struct NetGetAnyDCName *r)
{
    struct cli_state *cli = NULL;
    struct rpc_pipe_client *pipe_cli = NULL;
    NTSTATUS status;
    WERROR werr;

    werr = libnetapi_open_pipe(ctx, r->in.server_name,
                               &ndr_table_netlogon.syntax_id,
                               &cli,
                               &pipe_cli);
    if (!W_ERROR_IS_OK(werr)) {
        goto done;
    }

    status = rpccli_netr_GetAnyDCName(pipe_cli, ctx,
                                      r->in.server_name,
                                      r->in.domain_name,
                                      (const char **)r->out.buffer,
                                      &werr);
    if (!NT_STATUS_IS_OK(status)) {
        goto done;
    }
done:

    return werr;

}
Ejemplo n.º 2
0
enum winbindd_result winbindd_dual_getdcname(struct winbindd_domain *domain,
					     struct winbindd_cli_state *state)
{
	const char *dcname_slash = NULL;
	const char *p;
	struct rpc_pipe_client *netlogon_pipe;
	NTSTATUS result;
	WERROR werr;
	unsigned int orig_timeout;
	struct winbindd_domain *req_domain;

	state->request->domain_name
		[sizeof(state->request->domain_name)-1] = '\0';

	DEBUG(3, ("[%5lu]: Get DC name for %s\n", (unsigned long)state->pid,
		  state->request->domain_name));

	result = cm_connect_netlogon(domain, &netlogon_pipe);

	if (!NT_STATUS_IS_OK(result)) {
		DEBUG(1, ("Can't contact the NETLOGON pipe\n"));
		return WINBINDD_ERROR;
	}

	/* This call can take a long time - allow the server to time out.
	   35 seconds should do it. */

	orig_timeout = rpccli_set_timeout(netlogon_pipe, 35000);

	req_domain = find_domain_from_name_noinit(state->request->domain_name);
	if (req_domain == domain) {
		result = rpccli_netr_GetDcName(netlogon_pipe,
					       state->mem_ctx,
					       domain->dcname,
					       state->request->domain_name,
					       &dcname_slash,
					       &werr);
	} else {
		result = rpccli_netr_GetAnyDCName(netlogon_pipe,
						  state->mem_ctx,
						  domain->dcname,
						  state->request->domain_name,
						  &dcname_slash,
						  &werr);
	}
	/* And restore our original timeout. */
	rpccli_set_timeout(netlogon_pipe, orig_timeout);

	if (!NT_STATUS_IS_OK(result)) {
		DEBUG(5,("Error requesting DCname for domain %s: %s\n",
			state->request->domain_name, nt_errstr(result)));
		return WINBINDD_ERROR;
	}

	if (!W_ERROR_IS_OK(werr)) {
		DEBUG(5, ("Error requesting DCname for domain %s: %s\n",
			state->request->domain_name, win_errstr(werr)));
		return WINBINDD_ERROR;
	}

	p = dcname_slash;
	if (*p == '\\') {
		p+=1;
	}
	if (*p == '\\') {
		p+=1;
	}

	fstrcpy(state->response->data.dc_name, p);
	return WINBINDD_OK;
}