summaryrefslogtreecommitdiff
path: root/source4/libcli
diff options
context:
space:
mode:
Diffstat (limited to 'source4/libcli')
-rw-r--r--source4/libcli/nbt/nameregister.c5
-rw-r--r--source4/libcli/nbt/nbtname.c57
2 files changed, 59 insertions, 3 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;
+}
+