s3-spoolss: make some of the command hooks static.
[kai/samba.git] / source3 / nmbd / nmbd_become_dmb.c
index 46d37fbb817801bc59887c4ca8ebf94f6020fd96..827d56cb0624393511d82a678fb6b30b2c320de2 100644 (file)
@@ -7,7 +7,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,
    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/>.
    
 */
 
 #include "includes.h"
 
-extern struct in_addr allones_ip;
-
 extern uint16 samba_nb_type; /* Samba's NetBIOS type. */
 
 static void become_domain_master_browser_bcast(const char *);
@@ -37,11 +34,11 @@ static void become_domain_master_fail(struct subnet_record *subrec,
                                       struct response_record *rrec,
                                       struct nmb_name *fail_name)
 {
-       nstring failname;
+       unstring failname;
        struct work_record *work;
        struct server_record *servrec;
 
-       pull_ascii_nstring(failname, fail_name->name);
+       pull_ascii_nstring(failname, sizeof(failname), fail_name->name);
        work = find_workgroup_on_subnet(subrec, failname);
        if(!work) {
                DEBUG(0,("become_domain_master_fail: Error - cannot find \
@@ -80,11 +77,11 @@ static void become_domain_master_stage2(struct subnet_record *subrec,
                                         uint16 nb_flags,
                                         int ttl, struct in_addr registered_ip)
 {
-       nstring regname;
+       unstring regname;
        struct work_record *work;
        struct server_record *servrec;
 
-       pull_ascii_nstring(regname, registered_name->name);
+       pull_ascii_nstring(regname, sizeof(regname), registered_name->name);
        work = find_workgroup_on_subnet( subrec, regname);
 
        if(!work) {
@@ -120,6 +117,7 @@ in workgroup %s on subnet %s\n",
        if( subrec == unicast_subnet ) {
                struct nmb_name nmbname;
                struct in_addr my_first_ip;
+               const struct in_addr *nip;
 
                /* Put our name and first IP address into the 
                   workgroup struct as domain master browser. This
@@ -129,8 +127,16 @@ in workgroup %s on subnet %s\n",
                make_nmb_name(&nmbname, global_myname(), 0x20);
 
                work->dmb_name = nmbname;
-               /* Pick the first interface ip address as the domain master browser ip. */
-               my_first_ip = *iface_n_ip(0);
+
+               /* Pick the first interface IPv4 address as the domain master
+                * browser ip. */
+               nip = first_ipv4_iface();
+               if (!nip) {
+                       DEBUG(0,("become_domain_master_stage2: "
+                               "Error. get_interface returned NULL\n"));
+                       return;
+               }
+               my_first_ip = *nip;
 
                putip((char *)&work->dmb_addr, &my_first_ip);
 
@@ -197,11 +203,13 @@ workgroup %s on subnet %s\n", wg_name, subrec->subnet_name));
 
 static void become_domain_master_query_success(struct subnet_record *subrec,
                         struct userdata_struct *userdata,
-                        struct nmb_name *nmbname, struct in_addr ip, 
+                        struct nmb_name *nmbname, struct in_addr ip,
                         struct res_rec *rrec)
 {
-       nstring name;
-       pull_ascii_nstring(name, nmbname->name);
+       unstring name;
+       struct in_addr allones_ip;
+
+       pull_ascii_nstring(name, sizeof(name), nmbname->name);
 
        /* If the given ip is not ours, then we can't become a domain
                controler as the name is already registered.
@@ -210,7 +218,9 @@ static void become_domain_master_query_success(struct subnet_record *subrec,
        /* BUG note. Samba 1.9.16p11 servers seem to return the broadcast
                address or zero ip for this query. Pretend this is ok. */
 
-       if(ismyip(ip) || ip_equal(allones_ip, ip) || is_zero_ip(ip)) {
+       allones_ip.s_addr = htonl(INADDR_BROADCAST);
+
+       if(ismyip_v4(ip) || ip_equal_v4(allones_ip, ip) || is_zero_ip_v4(ip)) {
                if( DEBUGLVL( 3 ) ) {
                        dbgtext( "become_domain_master_query_success():\n" );
                        dbgtext( "Our address (%s) ", inet_ntoa(ip) );
@@ -241,7 +251,7 @@ static void become_domain_master_query_fail(struct subnet_record *subrec,
                                     struct response_record *rrec,
                                     struct nmb_name *question_name, int fail_code)
 {
-       nstring name;
+       unstring name;
 
        /* If the query was unicast, and the error is not NAM_ERR (name didn't exist),
                then this is a failure. Otherwise, not finding the name is what we want. */
@@ -254,7 +264,7 @@ querying WINS server for name %s.\n",
        }
 
        /* Otherwise - not having the name allows us to register it. */
-       pull_ascii_nstring(name, question_name->name);
+       pull_ascii_nstring(name, sizeof(name), question_name->name);
        become_domain_master_stage1(subrec, name);
 }