Author: tridge
Date: 2005-11-14 01:50:55 +0000 (Mon, 14 Nov 2005)
New Revision: 11711

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=11711

Log:

fixed the nbt server to use the right interface for outgoing requests


Modified:
   branches/SAMBA_4_0/source/nbt_server/interfaces.c
   branches/SAMBA_4_0/source/nbt_server/irpc.c


Changeset:
Modified: branches/SAMBA_4_0/source/nbt_server/interfaces.c
===================================================================
--- branches/SAMBA_4_0/source/nbt_server/interfaces.c   2005-11-14 01:50:26 UTC 
(rev 11710)
+++ branches/SAMBA_4_0/source/nbt_server/interfaces.c   2005-11-14 01:50:55 UTC 
(rev 11711)
@@ -286,3 +286,27 @@
        talloc_free(ret);
        return NULL;
 }
+
+
+/*
+  find the interface to use for sending a outgoing request
+*/
+struct nbtd_interface *nbtd_find_interface(struct nbtd_server *nbtd_server,
+                                          const char *address)
+{
+       struct nbtd_interface *iface;
+       /* try to find a exact match */
+       for (iface=nbtd_server->interfaces;iface;iface=iface->next) {
+               if (iface_same_net(address, iface->ip_address, iface->netmask)) 
{
+                       return iface;
+               }
+       }
+
+       /* no exact match, if we have the broadcast interface, use that */
+       if (nbtd_server->bcast_interface) {
+               return nbtd_server->bcast_interface;
+       }
+
+       /* fallback to first interface */
+       return nbtd_server->interfaces;
+}

Modified: branches/SAMBA_4_0/source/nbt_server/irpc.c
===================================================================
--- branches/SAMBA_4_0/source/nbt_server/irpc.c 2005-11-14 01:50:26 UTC (rev 
11710)
+++ branches/SAMBA_4_0/source/nbt_server/irpc.c 2005-11-14 01:50:55 UTC (rev 
11711)
@@ -115,11 +115,10 @@
 {
        struct nbtd_server *server =
                talloc_get_type(msg->private, struct nbtd_server);
-
+       struct nbtd_interface *iface = nbtd_find_interface(server, 
req->in.ip_address);
        struct getdc_state *s;
        struct nbt_ntlogon_packet p;
        struct nbt_ntlogon_sam_logon *r;
-       struct nbt_dgram_socket *sock;
        struct nbt_name src, dst;
        struct nbt_peer_socket dest;
        struct dgram_mailslot_handler *handler;
@@ -127,15 +126,13 @@
 
        DEBUG(0, ("nbtd_getdcname called\n"));
 
-       sock = server->interfaces[0].dgmsock;
-
        s = talloc(msg, struct getdc_state);
         NT_STATUS_HAVE_NO_MEMORY(s);
 
        s->msg = msg;
        s->req = req;
        
-       handler = dgram_mailslot_temp(sock, NBT_MAILSLOT_GETDC,
+       handler = dgram_mailslot_temp(iface->dgmsock, NBT_MAILSLOT_GETDC,
                                      getdc_recv_ntlogon_reply, s);
         NT_STATUS_HAVE_NO_MEMORY(handler);
        
@@ -157,7 +154,7 @@
 
        dest.addr = req->in.ip_address;
        dest.port = 138;
-       status = dgram_mailslot_ntlogon_send(sock, DGRAM_DIRECT_GROUP,
+       status = dgram_mailslot_ntlogon_send(iface->dgmsock, DGRAM_DIRECT_GROUP,
                                             &dst, &dest,
                                             &src, &p);
        if (!NT_STATUS_IS_OK(status)) {

Reply via email to