} 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));
}
*/
#include "includes.h"
+#include "system/iconv.h"
#include "librpc/gen_ndr/ndr_nbt.h"
/* don't allow an unlimited number of name components */
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;
+}
+
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 {
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);
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;
}
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);
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);
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);
}
-
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;
}
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);
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)));
}
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;
}
/* 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);
}
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) {
}
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);
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);
}
#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)
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;