summaryrefslogtreecommitdiff
path: root/source4/nbt_server
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-04-03 04:32:37 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:11:24 -0500
commita47cb58c2f6d34dd98e3dc2dd023a259ff501643 (patch)
tree7ce71f8ac40452570f110ec1895d3e5a65fafbd2 /source4/nbt_server
parentb9df3f5fe80087a55a45474a5a860aec2788a26d (diff)
downloadsamba-a47cb58c2f6d34dd98e3dc2dd023a259ff501643.tar.gz
samba-a47cb58c2f6d34dd98e3dc2dd023a259ff501643.tar.bz2
samba-a47cb58c2f6d34dd98e3dc2dd023a259ff501643.zip
r6184: the beginnings of the libcli/dgram/ library, and the dgram
server. Currently just listens on port 138 and parses the packets (using IDL like the rest of NBT). This allows me to develop the structures and test with real packets (This used to be commit 10d64a525349ff96695ad961a3cfeb5bc7c8844f)
Diffstat (limited to 'source4/nbt_server')
-rw-r--r--source4/nbt_server/interfaces.c48
-rw-r--r--source4/nbt_server/nbt_server.h2
-rw-r--r--source4/nbt_server/register.c12
3 files changed, 59 insertions, 3 deletions
diff --git a/source4/nbt_server/interfaces.c b/source4/nbt_server/interfaces.c
index bc01ac6d99..dfd4538321 100644
--- a/source4/nbt_server/interfaces.c
+++ b/source4/nbt_server/interfaces.c
@@ -63,6 +63,16 @@ static void nbtd_request_handler(struct nbt_name_socket *nbtsock,
}
+/*
+ receive an incoming dgram request
+*/
+static void dgram_request_handler(struct nbt_dgram_socket *dgmsock,
+ struct nbt_dgram_packet *packet,
+ const char *src_address, int src_port)
+{
+}
+
+
/*
find a registered name on an interface
@@ -93,7 +103,6 @@ static NTSTATUS nbtd_add_socket(struct nbtd_server *nbtsrv,
{
struct nbtd_interface *iface;
NTSTATUS status;
- struct nbt_name_socket *bcast_nbtsock;
/*
we actually create two sockets. One listens on the broadcast address
@@ -113,6 +122,10 @@ static NTSTATUS nbtd_add_socket(struct nbtd_server *nbtsrv,
iface->names = NULL;
if (strcmp(netmask, "0.0.0.0") != 0) {
+ struct nbt_name_socket *bcast_nbtsock;
+ struct nbt_dgram_socket *bcast_dgmsock;
+
+ /* listen for broadcasts on port 137 */
bcast_nbtsock = nbt_name_socket_init(iface, nbtsrv->task->event_ctx);
NT_STATUS_HAVE_NO_MEMORY(bcast_nbtsock);
@@ -125,10 +138,26 @@ static NTSTATUS nbtd_add_socket(struct nbtd_server *nbtsrv,
}
nbt_set_incoming_handler(bcast_nbtsock, nbtd_request_handler, iface);
+
+
+ /* listen for broadcasts on port 138 */
+ bcast_dgmsock = nbt_dgram_socket_init(iface, nbtsrv->task->event_ctx);
+ NT_STATUS_HAVE_NO_MEMORY(bcast_dgmsock);
+
+ status = socket_listen(bcast_dgmsock->sock, bcast, lp_dgram_port(), 0, 0);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(0,("Failed to bind to %s:%d - %s\n",
+ bcast, lp_dgram_port(), nt_errstr(status)));
+ talloc_free(iface);
+ return status;
+ }
+
+ dgram_set_incoming_handler(bcast_dgmsock, dgram_request_handler, iface);
}
+ /* listen for unicasts on port 137 */
iface->nbtsock = nbt_name_socket_init(iface, nbtsrv->task->event_ctx);
- NT_STATUS_HAVE_NO_MEMORY(iface->ip_address);
+ NT_STATUS_HAVE_NO_MEMORY(iface->nbtsock);
status = socket_listen(iface->nbtsock->sock, bind_address, lp_nbt_port(), 0, 0);
if (!NT_STATUS_IS_OK(status)) {
@@ -137,9 +166,22 @@ static NTSTATUS nbtd_add_socket(struct nbtd_server *nbtsrv,
talloc_free(iface);
return status;
}
-
nbt_set_incoming_handler(iface->nbtsock, nbtd_request_handler, iface);
+
+ /* listen for unicasts on port 138 */
+ iface->dgmsock = nbt_dgram_socket_init(iface, nbtsrv->task->event_ctx);
+ NT_STATUS_HAVE_NO_MEMORY(iface->dgmsock);
+
+ status = socket_listen(iface->dgmsock->sock, bind_address, lp_dgram_port(), 0, 0);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(0,("Failed to bind to %s:%d - %s\n",
+ address, lp_dgram_port(), nt_errstr(status)));
+ talloc_free(iface);
+ return status;
+ }
+ dgram_set_incoming_handler(iface->dgmsock, dgram_request_handler, iface);
+
if (strcmp(netmask, "0.0.0.0") == 0) {
DLIST_ADD(nbtsrv->bcast_interface, iface);
} else {
diff --git a/source4/nbt_server/nbt_server.h b/source4/nbt_server/nbt_server.h
index 6a7b14a546..e2b8584f5a 100644
--- a/source4/nbt_server/nbt_server.h
+++ b/source4/nbt_server/nbt_server.h
@@ -21,6 +21,7 @@
*/
#include "libcli/nbt/libnbt.h"
+#include "libcli/dgram/libdgram.h"
/*
a list of our registered names on each interface
@@ -47,6 +48,7 @@ struct nbtd_interface {
const char *bcast_address;
const char *netmask;
struct nbt_name_socket *nbtsock;
+ struct nbt_dgram_socket *dgmsock;
struct nbtd_iface_name *names;
};
diff --git a/source4/nbt_server/register.c b/source4/nbt_server/register.c
index bec316cdea..cd39ef4769 100644
--- a/source4/nbt_server/register.c
+++ b/source4/nbt_server/register.c
@@ -27,6 +27,7 @@
#include "smbd/service_task.h"
#include "libcli/raw/libcliraw.h"
#include "libcli/composite/composite.h"
+#include "librpc/gen_ndr/ndr_samr.h"
static void nbtd_start_refresh_timer(struct nbtd_iface_name *iname);
@@ -264,6 +265,17 @@ void nbtd_register_names(struct nbtd_server *nbtsrv)
aliases++;
}
+ switch (lp_server_role()) {
+ case ROLE_DOMAIN_PDC:
+ nbtd_register_name(nbtsrv, lp_workgroup(), NBT_NAME_PDC, nb_flags);
+ nbtd_register_name(nbtsrv, lp_workgroup(), NBT_NAME_LOGON, nb_flags);
+ break;
+ case ROLE_DOMAIN_BDC:
+ nbtd_register_name(nbtsrv, lp_workgroup(), NBT_NAME_LOGON, nb_flags);
+ default:
+ break;
+ }
+
nb_flags |= NBT_NM_GROUP;
nbtd_register_name(nbtsrv, lp_workgroup(), NBT_NAME_CLIENT, nb_flags);