summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/client/clientutil.c2
-rw-r--r--source3/include/proto.h2
-rw-r--r--source3/libsmb/clientgen.c2
-rw-r--r--source3/libsmb/namequery.c321
-rw-r--r--source3/rpc_client/cli_netlogon.c2
-rw-r--r--source3/smbd/password.c4
-rw-r--r--source3/smbwrapper/smbw.c8
-rw-r--r--source3/utils/smbpasswd.c2
8 files changed, 186 insertions, 157 deletions
diff --git a/source3/client/clientutil.c b/source3/client/clientutil.c
index 8b61567485..efa836dede 100644
--- a/source3/client/clientutil.c
+++ b/source3/client/clientutil.c
@@ -928,7 +928,7 @@ BOOL cli_open_sockets(int port )
if (!have_ip)
{
- if(!resolve_name( host, &dest_ip))
+ if(!resolve_name( host, &dest_ip, 0x20))
{
DEBUG(0,("cli_open_sockets: Unknown host %s.\n",host));
return False;
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 86792a2245..f89b7a7ff5 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -447,7 +447,7 @@ struct in_addr *name_query(int fd,char *name,int name_type, BOOL bcast,BOOL recu
FILE *startlmhosts(char *fname);
BOOL getlmhostsent( FILE *fp, char *name, int *name_type, struct in_addr *ipaddr);
void endlmhosts(FILE *fp);
-BOOL resolve_name(char *name, struct in_addr *return_ip);
+BOOL resolve_name(char *name, struct in_addr *return_ip, int name_type);
BOOL find_master(char *group, struct in_addr *master_ip);
/*The following definitions come from libsmb/nmblib.c */
diff --git a/source3/libsmb/clientgen.c b/source3/libsmb/clientgen.c
index 6b07eb65b3..100e90160d 100644
--- a/source3/libsmb/clientgen.c
+++ b/source3/libsmb/clientgen.c
@@ -2196,7 +2196,7 @@ BOOL cli_connect(struct cli_state *cli, char *host, struct in_addr *ip)
fstrcpy(cli->desthost, host);
if (!ip || ip_equal(*ip, ipzero)) {
- if (!resolve_name( cli->desthost, &dest_ip)) {
+ if (!resolve_name( cli->desthost, &dest_ip, 0x20)) {
return False;
}
} else {
diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c
index a9da735f36..22fb59a27d 100644
--- a/source3/libsmb/namequery.c
+++ b/source3/libsmb/namequery.c
@@ -414,13 +414,161 @@ void endlmhosts(FILE *fp)
fclose(fp);
}
+
+
+/********************************************************
+resolve via "bcast" method
+*********************************************************/
+static BOOL resolve_bcast(char *name, struct in_addr *return_ip, int name_type)
+{
+ int sock, i;
+
+ /*
+ * "bcast" means do a broadcast lookup on all the local interfaces.
+ */
+
+ DEBUG(3,("resolve_name: Attempting broadcast lookup for name %s<0x20>\n", name));
+
+ sock = open_socket_in( SOCK_DGRAM, 0, 3,
+ interpret_addr(lp_socket_address()) );
+
+ if (sock != -1) {
+ struct in_addr *iplist = NULL;
+ int count;
+ int num_interfaces = iface_count();
+ set_socket_options(sock,"SO_BROADCAST");
+ /*
+ * Lookup the name on all the interfaces, return on
+ * the first successful match.
+ */
+ for( i = 0; i < num_interfaces; i++) {
+ struct in_addr sendto_ip;
+ /* Done this way to fix compiler error on IRIX 5.x */
+ sendto_ip = *iface_bcast(*iface_n_ip(i));
+ iplist = name_query(sock, name, name_type, True,
+ False, sendto_ip, &count, NULL);
+ if(iplist != NULL) {
+ *return_ip = iplist[0];
+ free((char *)iplist);
+ close(sock);
+ return True;
+ }
+ }
+ close(sock);
+ }
+
+ return False;
+}
+
+
+
+/********************************************************
+resolve via "wins" method
+*********************************************************/
+static BOOL resolve_wins(char *name, struct in_addr *return_ip, int name_type)
+{
+ int sock;
+ struct in_addr wins_ip;
+ BOOL wins_ismyip;
+
+ /*
+ * "wins" means do a unicast lookup to the WINS server.
+ * Ignore if there is no WINS server specified or if the
+ * WINS server is one of our interfaces (if we're being
+ * called from within nmbd - we can't do this call as we
+ * would then block).
+ */
+
+ DEBUG(3,("resolve_name: Attempting wins lookup for name %s<0x20>\n", name));
+
+ if(!*lp_wins_server()) {
+ DEBUG(3,("resolve_name: WINS server resolution selected and no WINS server present.\n"));
+ return False;
+ }
+
+ wins_ip = *interpret_addr2(lp_wins_server());
+ wins_ismyip = ismyip(wins_ip);
+
+ if((wins_ismyip && !global_in_nmbd) || !wins_ismyip) {
+ sock = open_socket_in( SOCK_DGRAM, 0, 3,
+ interpret_addr(lp_socket_address()) );
+
+ if (sock != -1) {
+ struct in_addr *iplist = NULL;
+ int count;
+ iplist = name_query(sock, name, name_type, False,
+ True, wins_ip, &count, NULL);
+ if(iplist != NULL) {
+ *return_ip = iplist[0];
+ free((char *)iplist);
+ close(sock);
+ return True;
+ }
+ close(sock);
+ }
+ }
+
+ return False;
+}
+
+
+/********************************************************
+resolve via "lmhosts" method
+*********************************************************/
+static BOOL resolve_lmhosts(char *name, struct in_addr *return_ip, int name_type)
+{
+ /*
+ * "lmhosts" means parse the local lmhosts file.
+ */
+
+ FILE *fp;
+ pstring lmhost_name;
+ int name_type2;
+
+ DEBUG(3,("resolve_name: Attempting lmhosts lookup for name %s\n", name));
+
+ fp = startlmhosts( LMHOSTSFILE );
+ if(fp) {
+ while (getlmhostsent(fp, lmhost_name, &name_type2, return_ip)) {
+ if (strequal(name, lmhost_name) &&
+ name_type == name_type2) {
+ endlmhosts(fp);
+ return True;
+ }
+ }
+ endlmhosts(fp);
+ }
+ return False;
+}
+
+
+/********************************************************
+resolve via "hosts" method
+*********************************************************/
+static BOOL resolve_hosts(char *name, struct in_addr *return_ip)
+{
+ /*
+ * "host" means do a localhost, or dns lookup.
+ */
+ struct hostent *hp;
+
+ DEBUG(3,("resolve_name: Attempting host lookup for name %s\n", name));
+
+ if (((hp = Get_Hostbyname(name)) != NULL) && (hp->h_addr != NULL)) {
+ putip((char *)return_ip,(char *)hp->h_addr);
+ return True;
+ }
+ return False;
+}
+
+
/********************************************************
Resolve a name into an IP address. Use this function if
the string is either an IP address, DNS or host name
or NetBIOS name. This uses the name switch in the
smb.conf to determine the order of name resolution.
*********************************************************/
-BOOL resolve_name(char *name, struct in_addr *return_ip)
+BOOL resolve_name(char *name, struct in_addr *return_ip, int name_type)
{
int i;
BOOL pure_address = True;
@@ -452,122 +600,27 @@ BOOL resolve_name(char *name, struct in_addr *return_ip)
if (!ptr || !*ptr) ptr = "host";
while (next_token(&ptr, tok, LIST_SEP, sizeof(tok))) {
- if(strequal(tok, "host") || strequal(tok, "hosts")) {
-
- /*
- * "host" means do a localhost, or dns lookup.
- */
-
- struct hostent *hp;
-
- DEBUG(3,("resolve_name: Attempting host lookup for name %s\n", name));
-
- if (((hp = Get_Hostbyname(name)) != NULL) && (hp->h_addr != NULL)) {
- putip((char *)return_ip,(char *)hp->h_addr);
- return True;
- }
-
- } else if(strequal( tok, "lmhosts")) {
-
- /*
- * "lmhosts" means parse the local lmhosts file.
- */
-
- FILE *fp;
- pstring lmhost_name;
- int name_type;
-
- DEBUG(3,("resolve_name: Attempting lmhosts lookup for name %s\n", name));
-
- fp = startlmhosts( LMHOSTSFILE );
- if(fp) {
- while( getlmhostsent(fp, lmhost_name, &name_type, return_ip ) ) {
- if( strequal(name, lmhost_name )) {
- endlmhosts(fp);
- return True;
- }
- }
- endlmhosts(fp);
- }
-
- } else if(strequal( tok, "wins")) {
-
- int sock;
-
- /*
- * "wins" means do a unicast lookup to the WINS server.
- * Ignore if there is no WINS server specified or if the
- * WINS server is one of our interfaces (if we're being
- * called from within nmbd - we can't do this call as we
- * would then block).
- */
-
- DEBUG(3,("resolve_name: Attempting wins lookup for name %s<0x20>\n", name));
-
- if(*lp_wins_server()) {
- struct in_addr wins_ip = *interpret_addr2(lp_wins_server());
- BOOL wins_ismyip = ismyip(wins_ip);
-
- if((wins_ismyip && !global_in_nmbd) || !wins_ismyip) {
- sock = open_socket_in( SOCK_DGRAM, 0, 3,
- interpret_addr(lp_socket_address()) );
-
- if (sock != -1) {
- struct in_addr *iplist = NULL;
- int count;
- iplist = name_query(sock, name, 0x20, False, True, wins_ip, &count, NULL);
- if(iplist != NULL) {
- *return_ip = iplist[0];
- free((char *)iplist);
- close(sock);
- return True;
- }
- close(sock);
- }
- }
- } else {
- DEBUG(3,("resolve_name: WINS server resolution selected and no WINS server present.\n"));
- }
- } else if(strequal( tok, "bcast")) {
-
- int sock;
-
- /*
- * "bcast" means do a broadcast lookup on all the local interfaces.
- */
-
- DEBUG(3,("resolve_name: Attempting broadcast lookup for name %s<0x20>\n", name));
-
- sock = open_socket_in( SOCK_DGRAM, 0, 3,
- interpret_addr(lp_socket_address()) );
-
- if (sock != -1) {
- struct in_addr *iplist = NULL;
- int count;
- int num_interfaces = iface_count();
- set_socket_options(sock,"SO_BROADCAST");
- /*
- * Lookup the name on all the interfaces, return on
- * the first successful match.
- */
- for( i = 0; i < num_interfaces; i++) {
- struct in_addr sendto_ip;
- /* Done this way to fix compiler error on IRIX 5.x */
- sendto_ip = *iface_bcast(*iface_n_ip(i));
- iplist = name_query(sock, name, 0x20, True, False, sendto_ip, &count, NULL);
- if(iplist != NULL) {
- *return_ip = iplist[0];
- free((char *)iplist);
- close(sock);
- return True;
- }
- }
- close(sock);
- }
-
- } else {
- DEBUG(0,("resolve_name: unknown name switch type %s\n", tok));
- }
+ if((strequal(tok, "host") || strequal(tok, "hosts"))) {
+ if (name_type == 0x20 && resolve_hosts(name, return_ip)) {
+ return True;
+ }
+ } else if(strequal( tok, "lmhosts")) {
+ if (resolve_lmhosts(name, return_ip, name_type)) {
+ return True;
+ }
+ } else if(strequal( tok, "wins")) {
+ /* don't resolve 1D via WINS */
+ if (name_type != 0x1D &&
+ resolve_wins(name, return_ip, name_type)) {
+ return True;
+ }
+ } else if(strequal( tok, "bcast")) {
+ if (resolve_bcast(name, return_ip, name_type)) {
+ return True;
+ }
+ } else {
+ DEBUG(0,("resolve_name: unknown name switch type %s\n", tok));
+ }
}
return False;
@@ -576,39 +629,11 @@ BOOL resolve_name(char *name, struct in_addr *return_ip)
/********************************************************
-find the IP address of the master browser for a workgroup
+find the IP address of the master browser or DMB for a workgroup
*********************************************************/
BOOL find_master(char *group, struct in_addr *master_ip)
{
- int sock;
- struct in_addr *iplist = NULL;
- int count, i;
- int num_interfaces = iface_count();
-
- sock = open_socket_in( SOCK_DGRAM, 0, 3,
- interpret_addr(lp_socket_address()) );
+ if (resolve_name(group, master_ip, 0x1D)) return True;
- if (sock == -1) return False;
-
- set_socket_options(sock,"SO_BROADCAST");
-
- /*
- * Lookup the name on all the interfaces, return on
- * the first successful match.
- */
- for( i = 0; i < num_interfaces; i++) {
- struct in_addr sendto_ip;
- /* Done this way to fix compiler error on IRIX 5.x */
- sendto_ip = *iface_bcast(*iface_n_ip(i));
- iplist = name_query(sock, group, 0x1D, True, False,
- sendto_ip, &count, NULL);
- if(iplist != NULL) {
- *master_ip = iplist[0];
- free((char *)iplist);
- close(sock);
- return True;
- }
- }
- close(sock);
- return False;
+ return resolve_name(group, master_ip, 0x1B);
}
diff --git a/source3/rpc_client/cli_netlogon.c b/source3/rpc_client/cli_netlogon.c
index 9af2a05f27..2671bac773 100644
--- a/source3/rpc_client/cli_netlogon.c
+++ b/source3/rpc_client/cli_netlogon.c
@@ -484,7 +484,7 @@ static BOOL modify_trust_password( char *domain, char *remote_machine,
return False;
}
- if(!resolve_name( remote_machine, &cli.dest_ip)) {
+ if(!resolve_name( remote_machine, &cli.dest_ip, 0x20)) {
DEBUG(0,("modify_trust_password: Can't resolve address for %s\n", remote_machine));
return False;
}
diff --git a/source3/smbd/password.c b/source3/smbd/password.c
index 5a7e20e47e..0ba4f1b7bf 100644
--- a/source3/smbd/password.c
+++ b/source3/smbd/password.c
@@ -945,7 +945,7 @@ struct cli_state *server_cryptkey(void)
standard_sub_basic(desthost);
strupper(desthost);
- if(!resolve_name( desthost, &dest_ip)) {
+ if(!resolve_name( desthost, &dest_ip, 0x20)) {
DEBUG(1,("server_cryptkey: Can't resolve address for %s\n",desthost));
continue;
}
@@ -1232,7 +1232,7 @@ machine %s in domain %s.\n", global_myname, global_myworkgroup ));
standard_sub_basic(remote_machine);
strupper(remote_machine);
- if(!resolve_name( remote_machine, &dest_ip)) {
+ if(!resolve_name( remote_machine, &dest_ip, 0x20)) {
DEBUG(1,("domain_client_validate: Can't resolve address for %s\n", remote_machine));
continue;
}
diff --git a/source3/smbwrapper/smbw.c b/source3/smbwrapper/smbw.c
index 650d0a08f5..e76b42692e 100644
--- a/source3/smbwrapper/smbw.c
+++ b/source3/smbwrapper/smbw.c
@@ -373,8 +373,9 @@ struct smbw_server *smbw_server(char *server, char *share)
make_nmb_name(&calling, global_myname, 0x0, "");
make_nmb_name(&called , server, 0x20, "");
- again:
- if ((p=strchr(server_n,'#'))) {
+ DEBUG(5,("server_n=[%s] server=[%s]\n", server_n, server));
+
+ if ((p=strchr(server_n,'#')) && strcmp(p+1,"1D")==0) {
struct in_addr ip;
fstrcpy(group, server_n);
p = strchr(group,'#');
@@ -387,6 +388,9 @@ struct smbw_server *smbw_server(char *server, char *share)
server_n = group;
}
+ DEBUG(5,(" -> server_n=[%s] server=[%s]\n", server_n, server));
+
+ again:
/* have to open a new connection */
if (!cli_initialise(&c) || !cli_connect(&c, server_n, NULL)) {
errno = ENOENT;
diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c
index 5ea0854230..bce5d7512f 100644
--- a/source3/utils/smbpasswd.c
+++ b/source3/utils/smbpasswd.c
@@ -461,7 +461,7 @@ int main(int argc, char **argv)
struct cli_state cli;
struct in_addr ip;
- if(!resolve_name( remote_machine, &ip)) {
+ if(!resolve_name( remote_machine, &ip, 0x20)) {
fprintf(stderr, "%s: unable to find an IP address for machine %s.\n",
prog_name, remote_machine );
exit(1);