s3-param Remove special case for global_myname(), rename to lp_netbios_name()
[metze/samba/wip.git] / source3 / nmbd / nmbd_elections.c
index 50e13729361e2ca39660c3b934eb315bba03004b..ac0d8735120c36c6b6c6c288223e58ed12079e42 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"
+#include "nmbd/nmbd.h"
+#include "smbprofile.h"
 
 /* Election parameters. */
 extern time_t StartupTime;
@@ -33,7 +34,7 @@ extern time_t StartupTime;
 static void send_election_dgram(struct subnet_record *subrec, const char *workgroup_name,
                                 uint32 criterion, int timeup,const char *server_name)
 {
-       pstring outbuf;
+       char outbuf[1024];
        unstring srv_name;
        char *p;
 
@@ -52,11 +53,11 @@ static void send_election_dgram(struct subnet_record *subrec, const char *workgr
        unstrcpy(srv_name, server_name);
        strupper_m(srv_name);
        /* The following call does UNIX -> DOS charset conversion. */
-       pstrcpy_base(p, srv_name, outbuf);
-       p = skip_string(p,1);
-  
+       push_ascii(p, srv_name, sizeof(outbuf)-PTR_DIFF(p,outbuf)-1, STR_TERMINATE);
+       p = skip_string(outbuf,sizeof(outbuf),p);
+
        send_mailslot(False, BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf),
-               global_myname(), 0,
+               lp_netbios_name(), 0,
                workgroup_name, 0x1e,
                subrec->bcast_ip, subrec->myip, DGRAM_PORT);
 }
@@ -131,9 +132,6 @@ void check_master_browser_exists(time_t t)
        struct subnet_record *subrec;
        const char *workgroup_name = lp_workgroup();
 
-       if (!lastrun)
-               lastrun = t;
-
        if (t < (lastrun + (CHECK_TIME_MST_BROWSE * 60)))
                return;
 
@@ -196,7 +194,7 @@ yet registered on subnet %s\n", nmb_namestr(&nmbname), subrec->subnet_name ));
                                }
 
                                send_election_dgram(subrec, work->work_group, work->ElectionCriterion,
-                                               t - StartupTime, global_myname());
+                                               t - StartupTime, lp_netbios_name());
              
                                if (work->ElectionCount++ >= 4) {
                                        /* Won election (4 packets were sent out uncontested. */
@@ -217,7 +215,7 @@ yet registered on subnet %s\n", nmb_namestr(&nmbname), subrec->subnet_name ));
   Determine if I win an election.
 ******************************************************************/
 
-static BOOL win_election(struct work_record *work, int version,
+static bool win_election(struct work_record *work, int version,
                          uint32 criterion, int timeup, const char *server_name)
 {  
        int mytimeup = time(NULL) - StartupTime;
@@ -233,7 +231,7 @@ static BOOL win_election(struct work_record *work, int version,
                        version, ELECTION_VERSION,
                        criterion, mycriterion,
                        timeup, mytimeup,
-                       server_name, global_myname()));
+                       server_name, lp_netbios_name()));
 
        if (version > ELECTION_VERSION)
                return(False);
@@ -250,7 +248,7 @@ static BOOL win_election(struct work_record *work, int version,
        if (timeup < mytimeup)
                return(True);
 
-       if (StrCaseCmp(global_myname(), server_name) > 0)
+       if (strcasecmp_m(lp_netbios_name(), server_name) > 0)
                return(False);
   
        return(True);
@@ -260,7 +258,7 @@ static BOOL win_election(struct work_record *work, int version,
   Process an incoming election datagram packet.
 ******************************************************************/
 
-void process_election(struct subnet_record *subrec, struct packet_struct *p, char *buf)
+void process_election(struct subnet_record *subrec, struct packet_struct *p, const char *buf)
 {
        struct dgram_packet *dgram = &p->packet.dgram;
        int version = CVAL(buf,0);
@@ -329,15 +327,17 @@ done:
   be done by run_elections().
 ***************************************************************************/
 
-BOOL check_elections(void)
+bool check_elections(void)
 {
        struct subnet_record *subrec;
-       BOOL run_any_election = False;
+       bool run_any_election = False;
 
        for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
                struct work_record *work;
                for (work = subrec->workgrouplist; work; work = work->next) {
-                       run_any_election |= work->RunningElection;
+                       if (work->RunningElection) {
+                               run_any_election = work->RunningElection;
+                       }
 
                        /* 
                         * Start an election if we have any chance of winning.
@@ -378,8 +378,11 @@ yet registered on subnet %s\n", nmb_namestr(&nmbname), subrec->subnet_name ));
  Process a internal Samba message forcing an election.
 ***************************************************************************/
 
-void nmbd_message_election(int msg_type, struct process_id src,
-                          void *buf, size_t len)
+void nmbd_message_election(struct messaging_context *msg,
+                          void *private_data,
+                          uint32_t msg_type,
+                          struct server_id server_id,
+                          DATA_BLOB *data)
 {
        struct subnet_record *subrec;