summaryrefslogtreecommitdiff
path: root/source4/libcli/nbt/nbtname.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-01-21 11:18:56 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:09:03 -0500
commit2383787f199c51cdc202a3cef5822a9fe6b8774c (patch)
tree52419b4e736f5ae1727561a3c9831e899edb35c5 /source4/libcli/nbt/nbtname.c
parentf1aaef3015864f9323711127a4964a8eceff6a52 (diff)
downloadsamba-2383787f199c51cdc202a3cef5822a9fe6b8774c.tar.gz
samba-2383787f199c51cdc202a3cef5822a9fe6b8774c.tar.bz2
samba-2383787f199c51cdc202a3cef5822a9fe6b8774c.zip
r4891: - added a generic resolve_name() async interface in libcli/resolve/,
which will eventually try all resolution methods setup in smb.conf - only resolution backend at the moment is bcast, which does a parallel broadcast to all configured network interfaces, and takes the first reply that comes in (this nicely demonstrates how to do parallel requests using the async APIs) - converted all the existing code to use the new resolve_name() api - removed all the old nmb code (yay!) (This used to be commit 239c310f255e43dd2d1c2433f666c9faaacbdce3)
Diffstat (limited to 'source4/libcli/nbt/nbtname.c')
-rw-r--r--source4/libcli/nbt/nbtname.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/source4/libcli/nbt/nbtname.c b/source4/libcli/nbt/nbtname.c
index c2da1a0ab4..8c46379f0b 100644
--- a/source4/libcli/nbt/nbtname.c
+++ b/source4/libcli/nbt/nbtname.c
@@ -283,3 +283,57 @@ NTSTATUS ndr_push_nbt_name(struct ndr_push *ndr, int ndr_flags, struct nbt_name
return NT_STATUS_OK;
}
+
+
+/*
+ copy a nbt name structure
+*/
+NTSTATUS nbt_name_dup(TALLOC_CTX *mem_ctx, struct nbt_name *name, struct nbt_name *newname)
+{
+ *newname = *name;
+ newname->name = talloc_strdup(mem_ctx, newname->name);
+ NT_STATUS_HAVE_NO_MEMORY(newname->name);
+ newname->scope = talloc_strdup(mem_ctx, newname->scope);
+ if (name->scope) {
+ NT_STATUS_HAVE_NO_MEMORY(newname->scope);
+ }
+ return NT_STATUS_OK;
+}
+
+/*
+ push a nbt name into a blob
+*/
+NTSTATUS nbt_name_to_blob(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, struct nbt_name *name)
+{
+ return ndr_push_struct_blob(blob, mem_ctx, name,
+ (ndr_push_flags_fn_t)ndr_push_nbt_name);
+}
+
+/*
+ choose a name to use when calling a server in a NBT session request.
+ we use heuristics to see if the name we have been given is a IP
+ address, or a too-long name. If it is then use *SMBSERVER, or a
+ truncated name
+*/
+void nbt_choose_called_name(TALLOC_CTX *mem_ctx,
+ struct nbt_name *n, const char *name, int type)
+{
+ n->scope = NULL;
+ n->type = type;
+
+ if (is_ipaddress(name)) {
+ n->name = "*SMBSERVER";
+ return;
+ }
+ if (strlen(name) > 15) {
+ const char *p = strchr(name, '.');
+ if (p - name > 15) {
+ n->name = "*SMBSERVER";
+ return;
+ }
+ n->name = talloc_strndup(mem_ctx, name, PTR_DIFF(p, name));
+ return;
+ }
+
+ n->name = talloc_strdup(mem_ctx, name);
+}