- modified resolve_name() to take a name_type
authorAndrew Tridgell <tridge@samba.org>
Sun, 4 Oct 1998 12:00:40 +0000 (12:00 +0000)
committerAndrew Tridgell <tridge@samba.org>
Sun, 4 Oct 1998 12:00:40 +0000 (12:00 +0000)
- cleaned up resolve_name() (split into separate functions for each resolver)
- if can't find local master then use #1B name
- support listing of foreign workgroups in /smb/
(This used to be commit a4e607c17d1119925c9d0e1d05e0fe81e9a2d1aa)

source3/client/clientutil.c
source3/include/proto.h
source3/libsmb/clientgen.c
source3/libsmb/namequery.c
source3/rpc_client/cli_netlogon.c
source3/smbd/password.c
source3/smbwrapper/smbw.c
source3/utils/smbpasswd.c

index 8b61567485b99d950e6739971f1e983390821fac..efa836dede54064d9aa6371ada3fe46ae140872d 100644 (file)
@@ -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;
index 86792a224577b3691a97806fdcc8980313acf35f..f89b7a7ff51f8d6a69f7b269b913afccad24cbf7 100644 (file)
@@ -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  */
index 6b07eb65b335196947eea4464cdfb5f781043dd6..100e90160d1d0e78a7931331f7d0e260f41ac953 100644 (file)
@@ -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 {
index a9da735f362cd9bffcf8c7a9534154350a31d826..22fb59a27d9f057aa0e12d03dbfcabecdb1fdf15 100644 (file)
@@ -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);
 }
index 9af2a05f27cd37d89467e94f89f1b330165120aa..2671bac7737249c3e050d447e58ce32fbfb8b899 100644 (file)
@@ -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;
   }
index 5a7e20e47edf6e2da45a04b0e8a99012adabbdc6..0ba4f1b7bf478466dbc69b40afa949993f6a9fb0 100644 (file)
@@ -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;
     }   
index 650d0a08f584f04e1c5f661f35358a285799e556..e76b42692eb91d58cbed390c70e150cce53e139a 100644 (file)
@@ -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;
index 5ea08542302810e151c1adcf07a79cccb465ac19..bce5d7512fd0a304f30eb31f29960ae59e722a5c 100644 (file)
@@ -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);