summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
Diffstat (limited to 'source4')
-rw-r--r--source4/libcli/nbt/nameregister.c5
-rw-r--r--source4/libcli/nbt/nbtname.c57
-rw-r--r--source4/nbt_server/defense.c5
-rw-r--r--source4/nbt_server/nodestatus.c8
-rw-r--r--source4/nbt_server/packet.c13
-rw-r--r--source4/nbt_server/query.c4
-rw-r--r--source4/nbt_server/register.c26
-rw-r--r--source4/nbt_server/winsclient.c29
-rw-r--r--source4/nbt_server/winsserver.c1
-rw-r--r--source4/torture/nbt/wins.c7
10 files changed, 108 insertions, 47 deletions
diff --git a/source4/libcli/nbt/nameregister.c b/source4/libcli/nbt/nameregister.c
index 9c1db38529..276b8e4ac3 100644
--- a/source4/libcli/nbt/nameregister.c
+++ b/source4/libcli/nbt/nameregister.c
@@ -185,10 +185,9 @@ static void name_register_bcast_handler(struct nbt_name_request *req)
} else {
c->state = SMBCLI_REQUEST_ERROR;
c->status = NT_STATUS_CONFLICTING_ADDRESSES;
- DEBUG(3,("Name registration conflict from %s for %s<%02x> with ip %s - rcode %d\n",
+ DEBUG(3,("Name registration conflict from %s for %s with ip %s - rcode %d\n",
state->io->out.reply_from,
- state->io->out.name.name,
- state->io->out.name.type,
+ nbt_name_string(state, &state->io->out.name),
state->io->out.reply_addr,
state->io->out.rcode));
}
diff --git a/source4/libcli/nbt/nbtname.c b/source4/libcli/nbt/nbtname.c
index 0d2840e0b5..da5205d818 100644
--- a/source4/libcli/nbt/nbtname.c
+++ b/source4/libcli/nbt/nbtname.c
@@ -25,6 +25,7 @@
*/
#include "includes.h"
+#include "system/iconv.h"
#include "librpc/gen_ndr/ndr_nbt.h"
/* don't allow an unlimited number of name components */
@@ -320,3 +321,59 @@ void nbt_choose_called_name(TALLOC_CTX *mem_ctx,
n->name = talloc_strdup(mem_ctx, name);
}
+
+
+/*
+ escape a string into a form containing only a small set of characters,
+ the rest is hex encoded. This is similar to URL encoding
+*/
+static const char *nbt_hex_encode(TALLOC_CTX *mem_ctx, const char *s)
+{
+ int i, len;
+ char *ret;
+ const char *valid_chars = "_-.$@";
+
+ for (len=i=0;s[i];i++,len++) {
+ if (!isalnum(s[i]) && !strchr(valid_chars, s[i])) {
+ len += 2;
+ }
+ }
+
+ ret = talloc_array(mem_ctx, char, len+1);
+ if (ret == NULL) return NULL;
+
+ for (len=i=0;s[i];i++) {
+ if (isalnum(s[i]) || strchr(valid_chars, s[i])) {
+ ret[len++] = s[i];
+ } else {
+ snprintf(&ret[len], 3, "%02x", s[i]);
+ len += 3;
+ }
+ }
+ ret[len] = 0;
+
+ return ret;
+}
+
+
+/*
+ form a string for a NBT name
+*/
+const char *nbt_name_string(TALLOC_CTX *mem_ctx, const struct nbt_name *name)
+{
+ TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
+ const char *ret;
+ if (name->scope) {
+ ret = talloc_asprintf(mem_ctx, "%s<%02x>-%s",
+ nbt_hex_encode(tmp_ctx, name->name),
+ name->type,
+ nbt_hex_encode(tmp_ctx, name->scope));
+ } else {
+ ret = talloc_asprintf(mem_ctx, "%s<%02x>",
+ nbt_hex_encode(tmp_ctx, name->name),
+ name->type);
+ }
+ talloc_free(tmp_ctx);
+ return ret;
+}
+
diff --git a/source4/nbt_server/defense.c b/source4/nbt_server/defense.c
index bce72d805f..00e0e740af 100644
--- a/source4/nbt_server/defense.c
+++ b/source4/nbt_server/defense.c
@@ -57,8 +57,9 @@ void nbtd_request_defense(struct nbt_name_socket *nbtsock,
iname = nbtd_find_iname(iface, name, NBT_NM_ACTIVE);
if (iname != NULL && !(iname->nb_flags & NBT_NM_GROUP)) {
- DEBUG(2,("Defending name %s<%02x> on %s against %s\n",
- name->name, name->type, iface->bcast_address, src_address));
+ DEBUG(2,("Defending name %s on %s against %s\n",
+ nbt_name_string(packet, name),
+ iface->bcast_address, src_address));
nbtd_negative_name_registration_reply(nbtsock, packet,
src_address, src_port);
} else {
diff --git a/source4/nbt_server/nodestatus.c b/source4/nbt_server/nodestatus.c
index 5b79bf315f..7f8e6d4a24 100644
--- a/source4/nbt_server/nodestatus.c
+++ b/source4/nbt_server/nodestatus.c
@@ -82,8 +82,8 @@ static void nbtd_node_status_reply(struct nbt_name_socket *nbtsock,
it could lead to giving attackers too much information */
ZERO_STRUCT(packet->answers[0].rdata.status.statistics);
- DEBUG(7,("Sending node status reply for %s<%02x> to %s:%d\n",
- name->name, name->type, src_address, src_port));
+ DEBUG(7,("Sending node status reply for %s to %s:%d\n",
+ nbt_name_string(packet, name), src_address, src_port));
nbt_name_reply_send(nbtsock, src_address, src_port, packet);
@@ -113,8 +113,8 @@ void nbtd_query_status(struct nbt_name_socket *nbtsock,
iname = nbtd_find_iname(iface, name, NBT_NM_ACTIVE);
if (iname == NULL) {
- DEBUG(7,("Node status query for %s<%02x> from %s - not found on %s\n",
- name->name, name->type, src_address, iface->ip_address));
+ DEBUG(7,("Node status query for %s from %s - not found on %s\n",
+ nbt_name_string(packet, name), src_address, iface->ip_address));
return;
}
diff --git a/source4/nbt_server/packet.c b/source4/nbt_server/packet.c
index edca4ecb00..e6eec27fdc 100644
--- a/source4/nbt_server/packet.c
+++ b/source4/nbt_server/packet.c
@@ -128,8 +128,8 @@ void nbtd_name_query_reply(struct nbt_name_socket *nbtsock,
if (addr->ipaddr == NULL) goto failed;
}
- DEBUG(7,("Sending name query reply for %s<%02x> at %s to %s:%d\n",
- name->name, name->type, addresses[0], src_address, src_port));
+ DEBUG(7,("Sending name query reply for %s at %s to %s:%d\n",
+ nbt_name_string(packet, name), addresses[0], src_address, src_port));
nbt_name_reply_send(nbtsock, src_address, src_port, packet);
@@ -168,8 +168,8 @@ void nbtd_negative_name_query_reply(struct nbt_name_socket *nbtsock,
packet->answers[0].ttl = 0;
ZERO_STRUCT(packet->answers[0].rdata);
- DEBUG(7,("Sending negative name query reply for %s<%02x> to %s:%d\n",
- name->name, name->type, src_address, src_port));
+ DEBUG(7,("Sending negative name query reply for %s to %s:%d\n",
+ nbt_name_string(packet, name), src_address, src_port));
nbt_name_reply_send(nbtsock, src_address, src_port, packet);
@@ -209,12 +209,11 @@ void nbtd_negative_name_registration_reply(struct nbt_name_socket *nbtsock,
packet->answers[0].ttl = 0;
packet->answers[0].rdata = request_packet->additional[0].rdata;
- DEBUG(7,("Sending negative name registration reply for %s<%02x> to %s:%d\n",
- name->name, name->type, src_address, src_port));
+ DEBUG(7,("Sending negative name registration reply for %s to %s:%d\n",
+ nbt_name_string(packet, name), src_address, src_port));
nbt_name_reply_send(nbtsock, src_address, src_port, packet);
failed:
talloc_free(packet);
}
-
diff --git a/source4/nbt_server/query.c b/source4/nbt_server/query.c
index cc14a762da..c51a146adf 100644
--- a/source4/nbt_server/query.c
+++ b/source4/nbt_server/query.c
@@ -79,8 +79,8 @@ void nbtd_request_query(struct nbt_name_socket *nbtsock,
ignore it for now */
if (!(iname->nb_flags & NBT_NM_ACTIVE) &&
(packet->operation & NBT_FLAG_BROADCAST)) {
- DEBUG(7,("Query for %s<%02x> from %s - name not active yet on %s\n",
- name->name, name->type, src_address, iface->ip_address));
+ DEBUG(7,("Query for %s from %s - name not active yet on %s\n",
+ nbt_name_string(packet, name), src_address, iface->ip_address));
return;
}
diff --git a/source4/nbt_server/register.c b/source4/nbt_server/register.c
index c28ba0764c..bec316cdea 100644
--- a/source4/nbt_server/register.c
+++ b/source4/nbt_server/register.c
@@ -44,8 +44,9 @@ static void refresh_completion_handler(struct nbt_name_request *req)
status = nbt_name_refresh_recv(req, tmp_ctx, &io);
if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
- DEBUG(4,("Refreshed name %s<%02x> on %s\n",
- iname->name.name, iname->name.type, iname->iface->ip_address));
+ DEBUG(4,("Refreshed name %s on %s\n",
+ nbt_name_string(tmp_ctx, &iname->name),
+ iname->iface->ip_address));
iname->registration_time = timeval_current();
nbtd_start_refresh_timer(iname);
talloc_free(tmp_ctx);
@@ -56,13 +57,14 @@ static void refresh_completion_handler(struct nbt_name_request *req)
iname->nb_flags &= ~NBT_NM_ACTIVE;
if (NT_STATUS_IS_OK(status)) {
- DEBUG(1,("Name conflict from %s refreshing name %s<%02x> on %s - %s\n",
- io.out.reply_addr, iname->name.name, iname->name.type,
+ DEBUG(1,("Name conflict from %s refreshing name %s on %s - %s\n",
+ io.out.reply_addr, nbt_name_string(tmp_ctx, &iname->name),
iname->iface->ip_address,
nt_errstr(nbt_rcode_to_ntstatus(io.out.rcode))));
} else {
- DEBUG(1,("Error refreshing name %s<%02x> on %s - %s\n",
- iname->name.name, iname->name.type, iname->iface->ip_address,
+ DEBUG(1,("Error refreshing name %s on %s - %s\n",
+ nbt_name_string(tmp_ctx, &iname->name),
+ iname->iface->ip_address,
nt_errstr(status)));
}
@@ -130,14 +132,17 @@ static void nbtd_register_handler(struct composite_context *req)
struct nbtd_iface_name *iname = talloc_get_type(req->async.private,
struct nbtd_iface_name);
NTSTATUS status;
+ TALLOC_CTX *tmp_ctx = talloc_new(iname);
status = nbt_name_register_bcast_recv(req);
if (NT_STATUS_IS_OK(status)) {
/* good - nobody complained about our registration */
iname->nb_flags |= NBT_NM_ACTIVE;
- DEBUG(3,("Registered %s<%02x> on interface %s\n",
- iname->name.name, iname->name.type, iname->iface->bcast_address));
+ DEBUG(3,("Registered %s on interface %s\n",
+ nbt_name_string(tmp_ctx, &iname->name),
+ iname->iface->bcast_address));
iname->registration_time = timeval_current();
+ talloc_free(tmp_ctx);
nbtd_start_refresh_timer(iname);
return;
}
@@ -145,9 +150,10 @@ static void nbtd_register_handler(struct composite_context *req)
/* someone must have replied with an objection! */
iname->nb_flags |= NBT_NM_CONFLICT;
- DEBUG(1,("Error registering %s<%02x> on interface %s - %s\n",
- iname->name.name, iname->name.type, iname->iface->bcast_address,
+ DEBUG(1,("Error registering %s on interface %s - %s\n",
+ nbt_name_string(tmp_ctx, &iname->name), iname->iface->bcast_address,
nt_errstr(status)));
+ talloc_free(tmp_ctx);
}
diff --git a/source4/nbt_server/winsclient.c b/source4/nbt_server/winsclient.c
index e941d77e28..cfb68a3aaf 100644
--- a/source4/nbt_server/winsclient.c
+++ b/source4/nbt_server/winsclient.c
@@ -66,30 +66,31 @@ static void nbtd_wins_refresh_handler(struct composite_context *c)
if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
/* our WINS server is dead - start registration over
from scratch */
- DEBUG(2,("Failed to refresh %s<%02x> with WINS server %s\n",
- iname->name.name, iname->name.type, iname->wins_server));
+ DEBUG(2,("Failed to refresh %s with WINS server %s\n",
+ nbt_name_string(tmp_ctx, &iname->name), iname->wins_server));
+ talloc_free(tmp_ctx);
nbtd_winsclient_register(iname);
return;
}
if (!NT_STATUS_IS_OK(status)) {
- DEBUG(1,("Name refresh failure with WINS for %s<%02x> - %s\n",
- iname->name.name, iname->name.type, nt_errstr(status)));
+ DEBUG(1,("Name refresh failure with WINS for %s - %s\n",
+ nbt_name_string(tmp_ctx, &iname->name), nt_errstr(status)));
talloc_free(tmp_ctx);
return;
}
if (io.out.rcode != 0) {
- DEBUG(1,("WINS server %s rejected name refresh of %s<%02x> - %s\n",
- io.out.wins_server, iname->name.name, iname->name.type,
+ DEBUG(1,("WINS server %s rejected name refresh of %s - %s\n",
+ io.out.wins_server, nbt_name_string(tmp_ctx, &iname->name),
nt_errstr(nbt_rcode_to_ntstatus(io.out.rcode))));
iname->nb_flags |= NBT_NM_CONFLICT;
talloc_free(tmp_ctx);
return;
}
- DEBUG(4,("Refreshed name %s<%02x> with WINS server %s\n",
- iname->name.name, iname->name.type, iname->wins_server));
+ DEBUG(4,("Refreshed name %s with WINS server %s\n",
+ nbt_name_string(tmp_ctx, &iname->name), iname->wins_server));
/* success - start a periodic name refresh */
iname->nb_flags |= NBT_NM_ACTIVE;
if (iname->wins_server) {
@@ -167,15 +168,15 @@ static void nbtd_wins_register_handler(struct composite_context *c)
}
if (!NT_STATUS_IS_OK(status)) {
- DEBUG(1,("Name register failure with WINS for %s<%02x> - %s\n",
- iname->name.name, iname->name.type, nt_errstr(status)));
+ DEBUG(1,("Name register failure with WINS for %s - %s\n",
+ nbt_name_string(tmp_ctx, &iname->name), nt_errstr(status)));
talloc_free(tmp_ctx);
return;
}
if (io.out.rcode != 0) {
- DEBUG(1,("WINS server %s rejected name register of %s<%02x> - %s\n",
- io.out.wins_server, iname->name.name, iname->name.type,
+ DEBUG(1,("WINS server %s rejected name register of %s - %s\n",
+ io.out.wins_server, nbt_name_string(tmp_ctx, &iname->name),
nt_errstr(nbt_rcode_to_ntstatus(io.out.rcode))));
iname->nb_flags |= NBT_NM_CONFLICT;
talloc_free(tmp_ctx);
@@ -196,8 +197,8 @@ static void nbtd_wins_register_handler(struct composite_context *c)
nbtd_wins_refresh,
iname);
- DEBUG(3,("Registered %s<%02x> with WINS server %s\n",
- iname->name.name, iname->name.type, iname->wins_server));
+ DEBUG(3,("Registered %s with WINS server %s\n",
+ nbt_name_string(tmp_ctx, &iname->name), iname->wins_server));
talloc_free(tmp_ctx);
}
diff --git a/source4/nbt_server/winsserver.c b/source4/nbt_server/winsserver.c
index c7720b6ec7..22cfee415c 100644
--- a/source4/nbt_server/winsserver.c
+++ b/source4/nbt_server/winsserver.c
@@ -24,6 +24,7 @@
#include "nbt_server/nbt_server.h"
+
static void nbtd_winsserver_query(struct nbt_name_socket *nbtsock,
struct nbt_name_packet *packet,
const char *src_address, int src_port)
diff --git a/source4/torture/nbt/wins.c b/source4/torture/nbt/wins.c
index 3b5338147b..afbe91f6ec 100644
--- a/source4/torture/nbt/wins.c
+++ b/source4/torture/nbt/wins.c
@@ -65,11 +65,8 @@ static BOOL nbt_test_wins_name(TALLOC_CTX *mem_ctx, const char *address,
the right IP */
socket_listen(nbtsock->sock, myaddress, 0, 0, 0);
- printf("Testing name registration to WINS with name %s<%02x> at %s\n",
- name->name, name->type, myaddress);
- if (name->scope) {
- printf("scope is %s\n", name->scope);
- }
+ printf("Testing name registration to WINS with name %s at %s\n",
+ nbt_name_string(mem_ctx, name), myaddress);
printf("release the name\n");
release.in.name = *name;