diff options
author | Andrew Bartlett <abartlet@samba.org> | 2009-11-03 14:15:07 +1100 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2009-11-04 14:58:25 +1100 |
commit | b5ce97511aa33aa439a371f114ba7bb0cf822a16 (patch) | |
tree | 25c721f6a44c88fbbbe9d9dede3ebf6784dbaa12 /libcli | |
parent | 5a8f21cb88e7579c12b3d97299f355bb64957a87 (diff) | |
download | samba-b5ce97511aa33aa439a371f114ba7bb0cf822a16.tar.gz samba-b5ce97511aa33aa439a371f114ba7bb0cf822a16.tar.xz samba-b5ce97511aa33aa439a371f114ba7bb0cf822a16.zip |
libcli/nbt Move more of lmhosts lookup into common code
This aims to eventually share this with Samba4.
Andrew Bartlett
Diffstat (limited to 'libcli')
-rw-r--r-- | libcli/nbt/libnbt.h | 6 | ||||
-rw-r--r-- | libcli/nbt/lmhosts.c | 79 |
2 files changed, 85 insertions, 0 deletions
diff --git a/libcli/nbt/libnbt.h b/libcli/nbt/libnbt.h index 2abcb569713..6d6a4a4696b 100644 --- a/libcli/nbt/libnbt.h +++ b/libcli/nbt/libnbt.h @@ -360,4 +360,10 @@ bool getlmhostsent(TALLOC_CTX *ctx, XFILE *fp, char **pp_name, int *name_type, struct sockaddr_storage *pss); void endlmhosts(XFILE *fp); +NTSTATUS resolve_lmhosts_file_as_sockaddr(const char *lmhosts_file, + const char *name, int name_type, + TALLOC_CTX *mem_ctx, + struct sockaddr_storage **return_iplist, + int *return_count); + #endif /* __LIBNBT_H__ */ diff --git a/libcli/nbt/lmhosts.c b/libcli/nbt/lmhosts.c index 11703a27e80..317ccc556c7 100644 --- a/libcli/nbt/lmhosts.c +++ b/libcli/nbt/lmhosts.c @@ -155,3 +155,82 @@ void endlmhosts(XFILE *fp) x_fclose(fp); } +/******************************************************** + Resolve via "lmhosts" method. +*********************************************************/ + +NTSTATUS resolve_lmhosts_file_as_sockaddr(const char *lmhosts_file, + const char *name, int name_type, + TALLOC_CTX *mem_ctx, + struct sockaddr_storage **return_iplist, + int *return_count) +{ + /* + * "lmhosts" means parse the local lmhosts file. + */ + + XFILE *fp; + char *lmhost_name = NULL; + int name_type2; + struct sockaddr_storage return_ss; + NTSTATUS status = NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND; + TALLOC_CTX *ctx = NULL; + + *return_iplist = NULL; + *return_count = 0; + + DEBUG(3,("resolve_lmhosts: " + "Attempting lmhosts lookup for name %s<0x%x>\n", + name, name_type)); + + fp = startlmhosts(lmhosts_file); + + if ( fp == NULL ) + return NT_STATUS_NO_SUCH_FILE; + + ctx = talloc_new(mem_ctx); + if (!ctx) { + endlmhosts(fp); + return NT_STATUS_NO_MEMORY; + } + + while (getlmhostsent(ctx, fp, &lmhost_name, &name_type2, &return_ss)) { + + if (!strequal(name, lmhost_name)) { + TALLOC_FREE(lmhost_name); + continue; + } + + if ((name_type2 != -1) && (name_type != name_type2)) { + TALLOC_FREE(lmhost_name); + continue; + } + + *return_iplist = talloc_realloc(ctx, (*return_iplist), + struct sockaddr_storage, + (*return_count)+1); + + if ((*return_iplist) == NULL) { + TALLOC_FREE(ctx); + endlmhosts(fp); + DEBUG(3,("resolve_lmhosts: talloc_realloc fail !\n")); + return NT_STATUS_NO_MEMORY; + } + + (*return_iplist)[*return_count] = return_ss; + *return_count += 1; + + /* we found something */ + status = NT_STATUS_OK; + + /* Multiple names only for DC lookup */ + if (name_type != 0x1c) + break; + } + + talloc_steal(mem_ctx, *return_iplist); + TALLOC_FREE(ctx); + endlmhosts(fp); + return status; +} + |