| 1 | /*
|
|---|
| 2 | * Unix SMB/CIFS implementation.
|
|---|
| 3 | * NetApi GetDC Support
|
|---|
| 4 | * Copyright (C) Guenther Deschner 2007
|
|---|
| 5 | *
|
|---|
| 6 | * This program is free software; you can redistribute it and/or modify
|
|---|
| 7 | * it under the terms of the GNU General Public License as published by
|
|---|
| 8 | * the Free Software Foundation; either version 3 of the License, or
|
|---|
| 9 | * (at your option) any later version.
|
|---|
| 10 | *
|
|---|
| 11 | * This program is distributed in the hope that it will be useful,
|
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 14 | * GNU General Public License for more details.
|
|---|
| 15 | *
|
|---|
| 16 | * You should have received a copy of the GNU General Public License
|
|---|
| 17 | * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|---|
| 18 | */
|
|---|
| 19 |
|
|---|
| 20 | #include "includes.h"
|
|---|
| 21 |
|
|---|
| 22 | #include "librpc/gen_ndr/libnetapi.h"
|
|---|
| 23 | #include "lib/netapi/netapi.h"
|
|---|
| 24 | #include "lib/netapi/netapi_private.h"
|
|---|
| 25 | #include "lib/netapi/libnetapi.h"
|
|---|
| 26 | #include "libnet/libnet.h"
|
|---|
| 27 |
|
|---|
| 28 | /********************************************************************
|
|---|
| 29 | ********************************************************************/
|
|---|
| 30 |
|
|---|
| 31 | WERROR NetGetDCName_l(struct libnetapi_ctx *ctx,
|
|---|
| 32 | struct NetGetDCName *r)
|
|---|
| 33 | {
|
|---|
| 34 | return WERR_NOT_SUPPORTED;
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | /********************************************************************
|
|---|
| 38 | ********************************************************************/
|
|---|
| 39 |
|
|---|
| 40 | WERROR NetGetDCName_r(struct libnetapi_ctx *ctx,
|
|---|
| 41 | struct NetGetDCName *r)
|
|---|
| 42 | {
|
|---|
| 43 | struct cli_state *cli = NULL;
|
|---|
| 44 | struct rpc_pipe_client *pipe_cli = NULL;
|
|---|
| 45 | NTSTATUS status;
|
|---|
| 46 | WERROR werr;
|
|---|
| 47 |
|
|---|
| 48 | werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli);
|
|---|
| 49 | if (!W_ERROR_IS_OK(werr)) {
|
|---|
| 50 | goto done;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | werr = libnetapi_open_pipe(ctx, cli, PI_NETLOGON, &pipe_cli);
|
|---|
| 54 | if (!W_ERROR_IS_OK(werr)) {
|
|---|
| 55 | goto done;
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | status = rpccli_netr_GetDcName(pipe_cli, ctx,
|
|---|
| 59 | r->in.server_name,
|
|---|
| 60 | r->in.domain_name,
|
|---|
| 61 | (const char **)r->out.buffer,
|
|---|
| 62 | &werr);
|
|---|
| 63 |
|
|---|
| 64 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 65 | werr = ntstatus_to_werror(status);
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | done:
|
|---|
| 69 |
|
|---|
| 70 | return werr;
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | /********************************************************************
|
|---|
| 74 | ********************************************************************/
|
|---|
| 75 |
|
|---|
| 76 | WERROR NetGetAnyDCName_l(struct libnetapi_ctx *ctx,
|
|---|
| 77 | struct NetGetAnyDCName *r)
|
|---|
| 78 | {
|
|---|
| 79 | return WERR_NOT_SUPPORTED;
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | /********************************************************************
|
|---|
| 83 | ********************************************************************/
|
|---|
| 84 |
|
|---|
| 85 | WERROR NetGetAnyDCName_r(struct libnetapi_ctx *ctx,
|
|---|
| 86 | struct NetGetAnyDCName *r)
|
|---|
| 87 | {
|
|---|
| 88 | struct cli_state *cli = NULL;
|
|---|
| 89 | struct rpc_pipe_client *pipe_cli = NULL;
|
|---|
| 90 | NTSTATUS status;
|
|---|
| 91 | WERROR werr;
|
|---|
| 92 |
|
|---|
| 93 | werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli);
|
|---|
| 94 | if (!W_ERROR_IS_OK(werr)) {
|
|---|
| 95 | goto done;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | werr = libnetapi_open_pipe(ctx, cli, PI_NETLOGON, &pipe_cli);
|
|---|
| 99 | if (!W_ERROR_IS_OK(werr)) {
|
|---|
| 100 | goto done;
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | status = rpccli_netr_GetAnyDCName(pipe_cli, ctx,
|
|---|
| 104 | r->in.server_name,
|
|---|
| 105 | r->in.domain_name,
|
|---|
| 106 | (const char **)r->out.buffer,
|
|---|
| 107 | &werr);
|
|---|
| 108 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 109 | goto done;
|
|---|
| 110 | }
|
|---|
| 111 | done:
|
|---|
| 112 |
|
|---|
| 113 | return werr;
|
|---|
| 114 |
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | /********************************************************************
|
|---|
| 118 | ********************************************************************/
|
|---|
| 119 |
|
|---|
| 120 | WERROR DsGetDcName_l(struct libnetapi_ctx *ctx,
|
|---|
| 121 | struct DsGetDcName *r)
|
|---|
| 122 | {
|
|---|
| 123 | NTSTATUS status;
|
|---|
| 124 |
|
|---|
| 125 | status = dsgetdcname(ctx,
|
|---|
| 126 | NULL,
|
|---|
| 127 | r->in.domain_name,
|
|---|
| 128 | r->in.domain_guid,
|
|---|
| 129 | r->in.site_name,
|
|---|
| 130 | r->in.flags,
|
|---|
| 131 | (struct netr_DsRGetDCNameInfo **)r->out.dc_info);
|
|---|
| 132 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 133 | libnetapi_set_error_string(ctx,
|
|---|
| 134 | "failed to find DC: %s",
|
|---|
| 135 | get_friendly_nt_error_msg(status));
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | return ntstatus_to_werror(status);
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | /********************************************************************
|
|---|
| 142 | ********************************************************************/
|
|---|
| 143 |
|
|---|
| 144 | WERROR DsGetDcName_r(struct libnetapi_ctx *ctx,
|
|---|
| 145 | struct DsGetDcName *r)
|
|---|
| 146 | {
|
|---|
| 147 | WERROR werr;
|
|---|
| 148 | NTSTATUS status = NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND;
|
|---|
| 149 | struct cli_state *cli = NULL;
|
|---|
| 150 | struct rpc_pipe_client *pipe_cli = NULL;
|
|---|
| 151 |
|
|---|
| 152 | werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli);
|
|---|
| 153 | if (!W_ERROR_IS_OK(werr)) {
|
|---|
| 154 | goto done;
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | werr = libnetapi_open_pipe(ctx, cli, PI_NETLOGON, &pipe_cli);
|
|---|
| 158 | if (!W_ERROR_IS_OK(werr)) {
|
|---|
| 159 | goto done;
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | status = rpccli_netr_DsRGetDCName(pipe_cli,
|
|---|
| 163 | ctx,
|
|---|
| 164 | r->in.server_name,
|
|---|
| 165 | r->in.domain_name,
|
|---|
| 166 | r->in.domain_guid,
|
|---|
| 167 | NULL,
|
|---|
| 168 | r->in.flags,
|
|---|
| 169 | (struct netr_DsRGetDCNameInfo **)r->out.dc_info,
|
|---|
| 170 | &werr);
|
|---|
| 171 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 172 | werr = ntstatus_to_werror(status);
|
|---|
| 173 | goto done;
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 | done:
|
|---|
| 177 | return werr;
|
|---|
| 178 | }
|
|---|