diff options
author | Andrew Tridgell <tridge@samba.org> | 2005-01-21 11:18:56 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:09:03 -0500 |
commit | 2383787f199c51cdc202a3cef5822a9fe6b8774c (patch) | |
tree | 52419b4e736f5ae1727561a3c9831e899edb35c5 /source4/libcli/raw | |
parent | f1aaef3015864f9323711127a4964a8eceff6a52 (diff) | |
download | samba-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/raw')
-rw-r--r-- | source4/libcli/raw/clisocket.c | 16 | ||||
-rw-r--r-- | source4/libcli/raw/clitransport.c | 47 | ||||
-rw-r--r-- | source4/libcli/raw/libcliraw.h | 3 |
3 files changed, 42 insertions, 24 deletions
diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 0edb95e1a1..e981049535 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -326,10 +326,11 @@ resolve a hostname and connect ****************************************************************************/ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, int port) { - int name_type = 0x20; - struct ipv4_addr ip; - char *name, *p; + int name_type = NBT_NAME_SERVER; + const char *address; NTSTATUS status; + struct nbt_name nbt_name; + char *name, *p; name = talloc_strdup(sock, host); @@ -339,13 +340,18 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in *p = 0; } - if (!resolve_name(name, name, &ip, name_type)) { + nbt_name.name = name; + nbt_name.type = name_type; + nbt_name.scope = NULL; + + status = resolve_name(&nbt_name, sock, &address); + if (!NT_STATUS_IS_OK(status)) { return False; } sock->hostname = name; - status = smbcli_sock_connect(sock, sys_inet_ntoa(ip), port); + status = smbcli_sock_connect(sock, address, port); return NT_STATUS_IS_OK(status); } diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index e6d40639c6..918f18fa40 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -145,41 +145,52 @@ static void smbcli_transport_write_disable(struct smbcli_transport *transport) send a session request */ struct smbcli_request *smbcli_transport_connect_send(struct smbcli_transport *transport, - struct nmb_name *calling, - struct nmb_name *called) + struct nbt_name *calling, + struct nbt_name *called) { uint8_t *p; - int len = NBT_HDR_SIZE; struct smbcli_request *req; + DATA_BLOB calling_blob, called_blob; + TALLOC_CTX *tmp_ctx = talloc_new(transport); + NTSTATUS status; - if (called) { - transport->called = *called; - } + status = nbt_name_dup(transport, called, &transport->called); + if (!NT_STATUS_IS_OK(status)) goto failed; + + status = nbt_name_to_blob(tmp_ctx, &calling_blob, calling); + if (!NT_STATUS_IS_OK(status)) goto failed; + + status = nbt_name_to_blob(tmp_ctx, &called_blob, called); + if (!NT_STATUS_IS_OK(status)) goto failed; /* allocate output buffer */ req = smbcli_request_setup_nonsmb(transport, - NBT_HDR_SIZE + 2*nbt_mangled_name_len()); - if (req == NULL) return NULL; + NBT_HDR_SIZE + + calling_blob.length + called_blob.length); + if (req == NULL) goto failed; /* put in the destination name */ p = req->out.buffer + NBT_HDR_SIZE; - name_mangle(called->name, (char *)p, called->name_type); - len += name_len((char *)p); + memcpy(p, called_blob.data, called_blob.length); + p += called_blob.length; - /* and my name */ - p = req->out.buffer+len; - name_mangle(calling->name, (char *)p, calling->name_type); - len += name_len((char *)p); + memcpy(p, calling_blob.data, calling_blob.length); + p += calling_blob.length; - _smb_setlen(req->out.buffer,len-4); + _smb_setlen(req->out.buffer, PTR_DIFF(p, req->out.buffer)-4); SCVAL(req->out.buffer,0,0x81); if (!smbcli_request_send(req)) { smbcli_request_destroy(req); - return NULL; + goto failed; } + talloc_free(tmp_ctx); return req; + +failed: + talloc_free(tmp_ctx); + return NULL; } /* @@ -237,8 +248,8 @@ NTSTATUS smbcli_transport_connect_recv(struct smbcli_request *req) send a session request (if needed) */ BOOL smbcli_transport_connect(struct smbcli_transport *transport, - struct nmb_name *calling, - struct nmb_name *called) + struct nbt_name *calling, + struct nbt_name *called) { struct smbcli_request *req; NTSTATUS status; diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index 4047a5d369..d7414a237e 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -21,6 +21,7 @@ */ #include "request.h" +#include "librpc/gen_ndr/ndr_nbt.h" struct smbcli_tree; /* forward declare */ struct smbcli_request; /* forward declare */ @@ -151,7 +152,7 @@ struct smbcli_transport { /* remember the called name - some sub-protocols require us to know the server name */ - struct nmb_name called; + struct nbt_name called; /* a buffer for partially received SMB packets. */ struct { |