mirror of
https://github.com/samba-team/samba.git
synced 2025-02-26 21:57:41 +03:00
nbt_server: Factor out dgram sending from reply construction
Separation of concerns. Only one call to dgram_mailslot_netlogon_reply, which does the UDP send. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
This commit is contained in:
parent
f604c98ac2
commit
724349090c
@ -36,20 +36,21 @@
|
|||||||
/*
|
/*
|
||||||
reply to a GETDC request
|
reply to a GETDC request
|
||||||
*/
|
*/
|
||||||
static void nbtd_netlogon_getdc(struct nbtd_interface *iface,
|
static NTSTATUS nbtd_netlogon_getdc(struct nbtd_interface *iface,
|
||||||
struct nbt_dgram_packet *packet,
|
struct nbt_dgram_packet *packet,
|
||||||
const struct socket_address *src,
|
const struct socket_address *src,
|
||||||
struct nbt_netlogon_packet *netlogon)
|
struct nbt_netlogon_packet *netlogon,
|
||||||
|
TALLOC_CTX *mem_ctx,
|
||||||
|
struct nbt_netlogon_response **presponse)
|
||||||
{
|
{
|
||||||
struct nbt_name *name = &packet->data.msg.dest_name;
|
struct nbt_name *name = &packet->data.msg.dest_name;
|
||||||
struct nbtd_interface *reply_iface = nbtd_find_reply_iface(iface, src->addr, false);
|
|
||||||
struct nbt_netlogon_response_from_pdc *pdc;
|
struct nbt_netlogon_response_from_pdc *pdc;
|
||||||
struct ldb_context *samctx;
|
struct ldb_context *samctx;
|
||||||
struct nbt_netlogon_response netlogon_response;
|
struct nbt_netlogon_response *response;
|
||||||
|
|
||||||
/* only answer getdc requests on the PDC or LOGON names */
|
/* only answer getdc requests on the PDC or LOGON names */
|
||||||
if (name->type != NBT_NAME_PDC && name->type != NBT_NAME_LOGON) {
|
if (name->type != NBT_NAME_PDC && name->type != NBT_NAME_LOGON) {
|
||||||
return;
|
return NT_STATUS_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
samctx = iface->nbtsrv->sam_ctx;
|
samctx = iface->nbtsrv->sam_ctx;
|
||||||
@ -57,59 +58,75 @@ static void nbtd_netlogon_getdc(struct nbtd_interface *iface,
|
|||||||
if (lpcfg_server_role(iface->nbtsrv->task->lp_ctx) != ROLE_ACTIVE_DIRECTORY_DC
|
if (lpcfg_server_role(iface->nbtsrv->task->lp_ctx) != ROLE_ACTIVE_DIRECTORY_DC
|
||||||
|| !samdb_is_pdc(samctx)) {
|
|| !samdb_is_pdc(samctx)) {
|
||||||
DEBUG(2, ("Not a PDC, so not processing LOGON_PRIMARY_QUERY\n"));
|
DEBUG(2, ("Not a PDC, so not processing LOGON_PRIMARY_QUERY\n"));
|
||||||
return;
|
return NT_STATUS_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcasecmp_m(name->name, lpcfg_workgroup(iface->nbtsrv->task->lp_ctx)) != 0) {
|
if (strcasecmp_m(name->name, lpcfg_workgroup(iface->nbtsrv->task->lp_ctx)) != 0) {
|
||||||
DEBUG(5,("GetDC requested for a domian %s that we don't host\n", name->name));
|
DEBUG(5,("GetDC requested for a domian %s that we don't host\n", name->name));
|
||||||
return;
|
return NT_STATUS_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* setup a GETDC reply */
|
/* setup a GETDC reply */
|
||||||
ZERO_STRUCT(netlogon_response);
|
response = talloc_zero(mem_ctx, struct nbt_netlogon_response);
|
||||||
netlogon_response.response_type = NETLOGON_GET_PDC;
|
if (response == NULL) {
|
||||||
pdc = &netlogon_response.data.get_pdc;
|
return NT_STATUS_NO_MEMORY;
|
||||||
|
}
|
||||||
|
response->response_type = NETLOGON_GET_PDC;
|
||||||
|
pdc = &response->data.get_pdc;
|
||||||
|
|
||||||
pdc->command = NETLOGON_RESPONSE_FROM_PDC;
|
pdc->command = NETLOGON_RESPONSE_FROM_PDC;
|
||||||
pdc->pdc_name = lpcfg_netbios_name(iface->nbtsrv->task->lp_ctx);
|
|
||||||
|
pdc->pdc_name = talloc_strdup(
|
||||||
|
response, lpcfg_netbios_name(iface->nbtsrv->task->lp_ctx));
|
||||||
|
if (pdc->pdc_name == NULL) {
|
||||||
|
TALLOC_FREE(response);
|
||||||
|
return NT_STATUS_NO_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
pdc->unicode_pdc_name = pdc->pdc_name;
|
pdc->unicode_pdc_name = pdc->pdc_name;
|
||||||
pdc->domain_name = lpcfg_workgroup(iface->nbtsrv->task->lp_ctx);
|
|
||||||
|
pdc->domain_name = talloc_strdup(
|
||||||
|
response, lpcfg_workgroup(iface->nbtsrv->task->lp_ctx));
|
||||||
|
if (pdc->domain_name == NULL) {
|
||||||
|
TALLOC_FREE(response);
|
||||||
|
return NT_STATUS_NO_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
pdc->nt_version = 1;
|
pdc->nt_version = 1;
|
||||||
pdc->lmnt_token = 0xFFFF;
|
pdc->lmnt_token = 0xFFFF;
|
||||||
pdc->lm20_token = 0xFFFF;
|
pdc->lm20_token = 0xFFFF;
|
||||||
|
|
||||||
dgram_mailslot_netlogon_reply(reply_iface->dgmsock,
|
*presponse = response;
|
||||||
packet,
|
return NT_STATUS_OK;
|
||||||
lpcfg_netbios_name(iface->nbtsrv->task->lp_ctx),
|
|
||||||
netlogon->req.pdc.mailslot_name,
|
|
||||||
&netlogon_response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
reply to a ADS style GETDC request
|
reply to a ADS style GETDC request
|
||||||
*/
|
*/
|
||||||
static void nbtd_netlogon_samlogon(struct nbtd_interface *iface,
|
static NTSTATUS nbtd_netlogon_samlogon(
|
||||||
|
struct nbtd_interface *iface,
|
||||||
struct nbt_dgram_packet *packet,
|
struct nbt_dgram_packet *packet,
|
||||||
const struct socket_address *src,
|
const struct socket_address *src,
|
||||||
struct nbt_netlogon_packet *netlogon)
|
struct nbt_netlogon_packet *netlogon,
|
||||||
|
TALLOC_CTX *mem_ctx,
|
||||||
|
struct nbt_netlogon_response **presponse)
|
||||||
{
|
{
|
||||||
struct nbt_name *name = &packet->data.msg.dest_name;
|
struct nbt_name *name = &packet->data.msg.dest_name;
|
||||||
struct nbtd_interface *reply_iface = nbtd_find_reply_iface(iface, src->addr, false);
|
|
||||||
struct ldb_context *samctx;
|
struct ldb_context *samctx;
|
||||||
|
struct nbtd_interface *reply_iface = nbtd_find_reply_iface(iface, src->addr, false);
|
||||||
const char *my_ip = reply_iface->ip_address;
|
const char *my_ip = reply_iface->ip_address;
|
||||||
struct dom_sid *sid;
|
struct dom_sid *sid;
|
||||||
struct nbt_netlogon_response netlogon_response;
|
struct nbt_netlogon_response *response;
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
|
|
||||||
if (!my_ip) {
|
if (!my_ip) {
|
||||||
DEBUG(0, ("Could not obtain own IP address for datagram socket\n"));
|
DEBUG(0, ("Could not obtain own IP address for datagram socket\n"));
|
||||||
return;
|
return NT_STATUS_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* only answer getdc requests on the PDC or LOGON names */
|
/* only answer getdc requests on the PDC or LOGON names */
|
||||||
if (name->type != NBT_NAME_PDC && name->type != NBT_NAME_LOGON) {
|
if (name->type != NBT_NAME_PDC && name->type != NBT_NAME_LOGON) {
|
||||||
return;
|
return NT_STATUS_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
samctx = iface->nbtsrv->sam_ctx;
|
samctx = iface->nbtsrv->sam_ctx;
|
||||||
@ -120,25 +137,29 @@ static void nbtd_netlogon_samlogon(struct nbtd_interface *iface,
|
|||||||
sid = NULL;
|
sid = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = fill_netlogon_samlogon_response(samctx, packet, NULL, name->name, sid, NULL,
|
response = talloc_zero(mem_ctx, struct nbt_netlogon_response);
|
||||||
netlogon->req.logon.user_name, netlogon->req.logon.acct_control, src->addr,
|
if (response == NULL) {
|
||||||
netlogon->req.logon.nt_version, iface->nbtsrv->task->lp_ctx, &netlogon_response.data.samlogon, false);
|
return NT_STATUS_NO_MEMORY;
|
||||||
|
}
|
||||||
|
response->response_type = NETLOGON_SAMLOGON;
|
||||||
|
|
||||||
|
status = fill_netlogon_samlogon_response(
|
||||||
|
samctx, response, NULL, name->name, sid, NULL,
|
||||||
|
netlogon->req.logon.user_name,
|
||||||
|
netlogon->req.logon.acct_control, src->addr,
|
||||||
|
netlogon->req.logon.nt_version, iface->nbtsrv->task->lp_ctx,
|
||||||
|
&response->data.samlogon, false);
|
||||||
if (!NT_STATUS_IS_OK(status)) {
|
if (!NT_STATUS_IS_OK(status)) {
|
||||||
DEBUG(2,("NBT netlogon query failed domain=%s sid=%s version=%d - %s\n",
|
DEBUG(2,("NBT netlogon query failed domain=%s sid=%s version=%d - %s\n",
|
||||||
name->name, dom_sid_string(packet, sid), netlogon->req.logon.nt_version, nt_errstr(status)));
|
name->name, dom_sid_string(packet, sid), netlogon->req.logon.nt_version, nt_errstr(status)));
|
||||||
return;
|
TALLOC_FREE(response);
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
netlogon_response.response_type = NETLOGON_SAMLOGON;
|
*presponse = response;
|
||||||
|
return NT_STATUS_OK;
|
||||||
dgram_mailslot_netlogon_reply(reply_iface->dgmsock,
|
|
||||||
packet,
|
|
||||||
lpcfg_netbios_name(iface->nbtsrv->task->lp_ctx),
|
|
||||||
netlogon->req.logon.mailslot_name,
|
|
||||||
&netlogon_response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
handle incoming netlogon mailslot requests
|
handle incoming netlogon mailslot requests
|
||||||
*/
|
*/
|
||||||
@ -151,8 +172,11 @@ void nbtd_mailslot_netlogon_handler(struct dgram_mailslot_handler *dgmslot,
|
|||||||
talloc_get_type(dgmslot->private_data, struct nbtd_interface);
|
talloc_get_type(dgmslot->private_data, struct nbtd_interface);
|
||||||
struct nbt_netlogon_packet *netlogon =
|
struct nbt_netlogon_packet *netlogon =
|
||||||
talloc(dgmslot, struct nbt_netlogon_packet);
|
talloc(dgmslot, struct nbt_netlogon_packet);
|
||||||
|
struct nbtd_interface *reply_iface = nbtd_find_reply_iface(
|
||||||
|
iface, src->addr, false);
|
||||||
struct nbtd_iface_name *iname;
|
struct nbtd_iface_name *iname;
|
||||||
struct nbt_name *name = &packet->data.msg.dest_name;
|
struct nbt_name *name = &packet->data.msg.dest_name;
|
||||||
|
struct nbt_netlogon_response *response;
|
||||||
|
|
||||||
if (netlogon == NULL) goto failed;
|
if (netlogon == NULL) goto failed;
|
||||||
|
|
||||||
@ -173,18 +197,28 @@ void nbtd_mailslot_netlogon_handler(struct dgram_mailslot_handler *dgmslot,
|
|||||||
|
|
||||||
switch (netlogon->command) {
|
switch (netlogon->command) {
|
||||||
case LOGON_PRIMARY_QUERY:
|
case LOGON_PRIMARY_QUERY:
|
||||||
nbtd_netlogon_getdc(iface, packet, src, netlogon);
|
status = nbtd_netlogon_getdc(iface, packet, src, netlogon,
|
||||||
|
netlogon, &response);
|
||||||
break;
|
break;
|
||||||
case LOGON_SAM_LOGON_REQUEST:
|
case LOGON_SAM_LOGON_REQUEST:
|
||||||
nbtd_netlogon_samlogon(iface, packet, src, netlogon);
|
status = nbtd_netlogon_samlogon(iface, packet, src, netlogon,
|
||||||
|
netlogon, &response);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
DEBUG(2,("unknown netlogon op %d from %s:%d\n",
|
DEBUG(2,("unknown netlogon op %d from %s:%d\n",
|
||||||
netlogon->command, src->addr, src->port));
|
netlogon->command, src->addr, src->port));
|
||||||
NDR_PRINT_DEBUG(nbt_netlogon_packet, netlogon);
|
NDR_PRINT_DEBUG(nbt_netlogon_packet, netlogon);
|
||||||
|
status = NT_STATUS_NOT_SUPPORTED;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (NT_STATUS_IS_OK(status)) {
|
||||||
|
dgram_mailslot_netlogon_reply(
|
||||||
|
reply_iface->dgmsock, packet,
|
||||||
|
lpcfg_netbios_name(iface->nbtsrv->task->lp_ctx),
|
||||||
|
netlogon->req.logon.mailslot_name, response);
|
||||||
|
}
|
||||||
|
|
||||||
talloc_free(netlogon);
|
talloc_free(netlogon);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user