| 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/ndr_netlogon_c.h"
|
|---|
| 23 | #include "librpc/gen_ndr/libnetapi.h"
|
|---|
| 24 | #include "lib/netapi/netapi.h"
|
|---|
| 25 | #include "lib/netapi/netapi_private.h"
|
|---|
| 26 | #include "lib/netapi/libnetapi.h"
|
|---|
| 27 |
|
|---|
| 28 | /********************************************************************
|
|---|
| 29 | ********************************************************************/
|
|---|
| 30 |
|
|---|
| 31 | WERROR NetGetDCName_l(struct libnetapi_ctx *ctx,
|
|---|
| 32 | struct NetGetDCName *r)
|
|---|
| 33 | {
|
|---|
| 34 | LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGetDCName);
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | /********************************************************************
|
|---|
| 38 | ********************************************************************/
|
|---|
| 39 |
|
|---|
| 40 | WERROR NetGetDCName_r(struct libnetapi_ctx *ctx,
|
|---|
| 41 | struct NetGetDCName *r)
|
|---|
| 42 | {
|
|---|
| 43 | NTSTATUS status;
|
|---|
| 44 | WERROR werr;
|
|---|
| 45 | struct dcerpc_binding_handle *b;
|
|---|
| 46 |
|
|---|
| 47 | werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
|
|---|
| 48 | &ndr_table_netlogon.syntax_id,
|
|---|
| 49 | &b);
|
|---|
| 50 | if (!W_ERROR_IS_OK(werr)) {
|
|---|
| 51 | goto done;
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | status = dcerpc_netr_GetDcName(b, talloc_tos(),
|
|---|
| 55 | r->in.server_name,
|
|---|
| 56 | r->in.domain_name,
|
|---|
| 57 | (const char **)r->out.buffer,
|
|---|
| 58 | &werr);
|
|---|
| 59 |
|
|---|
| 60 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 61 | werr = ntstatus_to_werror(status);
|
|---|
| 62 | }
|
|---|
| 63 | done:
|
|---|
| 64 |
|
|---|
| 65 | return werr;
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | /********************************************************************
|
|---|
| 69 | ********************************************************************/
|
|---|
| 70 |
|
|---|
| 71 | WERROR NetGetAnyDCName_l(struct libnetapi_ctx *ctx,
|
|---|
| 72 | struct NetGetAnyDCName *r)
|
|---|
| 73 | {
|
|---|
| 74 | LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGetAnyDCName);
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | /********************************************************************
|
|---|
| 78 | ********************************************************************/
|
|---|
| 79 |
|
|---|
| 80 | WERROR NetGetAnyDCName_r(struct libnetapi_ctx *ctx,
|
|---|
| 81 | struct NetGetAnyDCName *r)
|
|---|
| 82 | {
|
|---|
| 83 | NTSTATUS status;
|
|---|
| 84 | WERROR werr;
|
|---|
| 85 | struct dcerpc_binding_handle *b;
|
|---|
| 86 |
|
|---|
| 87 | werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
|
|---|
| 88 | &ndr_table_netlogon.syntax_id,
|
|---|
| 89 | &b);
|
|---|
| 90 | if (!W_ERROR_IS_OK(werr)) {
|
|---|
| 91 | goto done;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | status = dcerpc_netr_GetAnyDCName(b, talloc_tos(),
|
|---|
| 95 | r->in.server_name,
|
|---|
| 96 | r->in.domain_name,
|
|---|
| 97 | (const char **)r->out.buffer,
|
|---|
| 98 | &werr);
|
|---|
| 99 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 100 | werr = ntstatus_to_werror(status);
|
|---|
| 101 | goto done;
|
|---|
| 102 | }
|
|---|
| 103 | done:
|
|---|
| 104 |
|
|---|
| 105 | return werr;
|
|---|
| 106 |
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | /********************************************************************
|
|---|
| 110 | ********************************************************************/
|
|---|
| 111 |
|
|---|
| 112 | WERROR DsGetDcName_l(struct libnetapi_ctx *ctx,
|
|---|
| 113 | struct DsGetDcName *r)
|
|---|
| 114 | {
|
|---|
| 115 | NTSTATUS status;
|
|---|
| 116 | struct libnetapi_private_ctx *priv;
|
|---|
| 117 |
|
|---|
| 118 | priv = talloc_get_type_abort(ctx->private_data,
|
|---|
| 119 | struct libnetapi_private_ctx);
|
|---|
| 120 |
|
|---|
| 121 | status = dsgetdcname(ctx,
|
|---|
| 122 | priv->msg_ctx,
|
|---|
| 123 | r->in.domain_name,
|
|---|
| 124 | r->in.domain_guid,
|
|---|
| 125 | r->in.site_name,
|
|---|
| 126 | r->in.flags,
|
|---|
| 127 | (struct netr_DsRGetDCNameInfo **)r->out.dc_info);
|
|---|
| 128 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 129 | libnetapi_set_error_string(ctx,
|
|---|
| 130 | "failed to find DC: %s",
|
|---|
| 131 | get_friendly_nt_error_msg(status));
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | return ntstatus_to_werror(status);
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | /********************************************************************
|
|---|
| 138 | ********************************************************************/
|
|---|
| 139 |
|
|---|
| 140 | WERROR DsGetDcName_r(struct libnetapi_ctx *ctx,
|
|---|
| 141 | struct DsGetDcName *r)
|
|---|
| 142 | {
|
|---|
| 143 | WERROR werr;
|
|---|
| 144 | NTSTATUS status = NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND;
|
|---|
| 145 | struct dcerpc_binding_handle *b;
|
|---|
| 146 |
|
|---|
| 147 | werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
|
|---|
| 148 | &ndr_table_netlogon.syntax_id,
|
|---|
| 149 | &b);
|
|---|
| 150 | if (!W_ERROR_IS_OK(werr)) {
|
|---|
| 151 | goto done;
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | status = dcerpc_netr_DsRGetDCNameEx(b,
|
|---|
| 155 | ctx,
|
|---|
| 156 | r->in.server_name,
|
|---|
| 157 | r->in.domain_name,
|
|---|
| 158 | r->in.domain_guid,
|
|---|
| 159 | r->in.site_name,
|
|---|
| 160 | r->in.flags,
|
|---|
| 161 | (struct netr_DsRGetDCNameInfo **)r->out.dc_info,
|
|---|
| 162 | &werr);
|
|---|
| 163 | if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(werr)) {
|
|---|
| 164 | goto done;
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | status = dcerpc_netr_DsRGetDCName(b,
|
|---|
| 168 | ctx,
|
|---|
| 169 | r->in.server_name,
|
|---|
| 170 | r->in.domain_name,
|
|---|
| 171 | r->in.domain_guid,
|
|---|
| 172 | NULL,
|
|---|
| 173 | r->in.flags,
|
|---|
| 174 | (struct netr_DsRGetDCNameInfo **)r->out.dc_info,
|
|---|
| 175 | &werr);
|
|---|
| 176 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 177 | werr = ntstatus_to_werror(status);
|
|---|
| 178 | goto done;
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | done:
|
|---|
| 182 | return werr;
|
|---|
| 183 | }
|
|---|