summaryrefslogtreecommitdiff
path: root/source4/libcli
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-02-12 01:00:15 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:09:45 -0500
commit7b8f58c37c7a975b93e20bd40b5195960fe22c6f (patch)
tree2fdb8f527feb2498dbb3551706ec9d17d3b41b89 /source4/libcli
parent49568fab37d3a8fc3727ec5972cecdaf35e904b5 (diff)
downloadsamba-7b8f58c37c7a975b93e20bd40b5195960fe22c6f.tar.gz
samba-7b8f58c37c7a975b93e20bd40b5195960fe22c6f.tar.bz2
samba-7b8f58c37c7a975b93e20bd40b5195960fe22c6f.zip
r5352: added a function nbt_name_string() that formats a nbt_name structure
as a human readable string. The format is designed to be able to be used as the DN for the WINS database as well, while coping with arbitrary bytes in the name (except nul bytes) (This used to be commit aac3090e3504ba07124a9d480322a98efb97175e)
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;
+}
+