Use separate make variables for libutil and libcrypto.
[samba.git] / source3 / nmbd / nmbd_winsproxy.c
index 75319724616d4c9d5e4283e75947e72815578f83..ff80c15ffff4ecbf9c29312918e848e0c1837c37 100644 (file)
@@ -6,7 +6,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -15,8 +15,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
 */
 
@@ -33,7 +32,7 @@ static void wins_proxy_name_query_request_success( struct subnet_record *subrec,
        unstring name;
        struct packet_struct *original_packet;
        struct subnet_record *orig_broadcast_subnet;
-       struct name_record *namerec;
+       struct name_record *namerec = NULL;
        uint16 nb_flags;
        int num_ips;
        int i;
@@ -47,9 +46,14 @@ static void wins_proxy_name_query_request_success( struct subnet_record *subrec,
        memcpy( (char *)&original_packet, &userdata->data[sizeof(struct subnet_record *)],
                        sizeof(struct packet_struct *) );
 
-       nb_flags = get_nb_flags( rrec->rdata );
+       if (rrec) {
+               nb_flags = get_nb_flags( rrec->rdata );
+               num_ips = rrec->rdlength / 6;
+       } else {
+               nb_flags = 0;
+               num_ips = 0;
+       }
 
-       num_ips = rrec->rdlength / 6;
        if(num_ips == 0) {
                DEBUG(0,("wins_proxy_name_query_request_success: Invalid number of IP records (0) \
 returned for name %s.\n", nmb_namestr(nmbname) ));
@@ -64,22 +68,34 @@ returned for name %s.\n", nmb_namestr(nmbname) ));
                        return;
                }
 
-               for(i = 0; i < num_ips; i++)
+               for(i = 0; i < num_ips; i++) {
                        putip( (char *)&iplist[i], (char *)&rrec->rdata[ (i*6) + 2]);
+               }
        }
 
        /* Add the queried name to the original subnet as a WINS_PROXY_NAME. */
 
-       if(rrec == PERMANENT_TTL)
+       if(rrec->ttl == PERMANENT_TTL) {
                ttl = lp_max_ttl();
+       }
 
        pull_ascii_nstring(name, sizeof(name), nmbname->name);
-       namerec = add_name_to_subnet( orig_broadcast_subnet, name,
+       add_name_to_subnet( orig_broadcast_subnet, name,
                                        nmbname->name_type, nb_flags, ttl,
                                        WINS_PROXY_NAME, num_ips, iplist );
 
-       if(iplist != &ip)
+       if(iplist != &ip) {
                SAFE_FREE(iplist);
+       }
+
+       namerec = find_name_on_subnet(orig_broadcast_subnet, nmbname, FIND_ANY_NAME);
+       if (!namerec) {
+               DEBUG(0,("wins_proxy_name_query_request_success: failed to add "
+                       "name %s to subnet %s !\n",
+                       name,
+                       orig_broadcast_subnet->subnet_name ));
+               return;
+       }
 
        /*
         * Check that none of the IP addresses we are returning is on the
@@ -91,7 +107,7 @@ returned for name %s.\n", nmb_namestr(nmbname) ));
 
        if(namerec && original_packet->packet.nmb.header.nm_flags.bcast) {
                for( i = 0; i < namerec->data.num_ips; i++) {
-                       if( same_net( namerec->data.ip[i], orig_broadcast_subnet->myip,
+                       if( same_net_v4( namerec->data.ip[i], orig_broadcast_subnet->myip,
                                        orig_broadcast_subnet->mask_ip ) ) {
                                DEBUG( 5, ( "wins_proxy_name_query_request_success: name %s is a WINS \
 proxy name and is also on the same subnet (%s) as the requestor. \