RIP BOOL. Convert BOOL -> bool. I found a few interesting
[nivanova/samba-autobuild/.git] / source3 / nmbd / nmbd_elections.c
index 19b00f1f4d23177db114bdf9e55f8de33994c1c5..db32461f060f91a19bb0041ef0f97b6056ca33d3 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,
@@ -16,8 +16,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/>.
    
 */
 
@@ -34,7 +33,7 @@ static void send_election_dgram(struct subnet_record *subrec, const char *workgr
                                 uint32 criterion, int timeup,const char *server_name)
 {
        pstring outbuf;
-       fstring srv_name;
+       unstring srv_name;
        char *p;
 
        DEBUG(2,("send_election_dgram: Sending election packet for workgroup %s on subnet %s\n",
@@ -49,11 +48,11 @@ static void send_election_dgram(struct subnet_record *subrec, const char *workgr
        SIVAL(p,1,criterion);
        SIVAL(p,5,timeup*1000); /* ms - Despite what the spec says. */
        p += 13;
-       fstrcpy(srv_name, server_name);
+       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);
+       p = skip_string(outbuf,sizeof(outbuf),p);
   
        send_mailslot(False, BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf),
                global_myname(), 0,
@@ -70,8 +69,8 @@ static void check_for_master_browser_success(struct subnet_record *subrec,
                                  struct nmb_name *answer_name,
                                  struct in_addr answer_ip, struct res_rec *rrec)
 {
-       nstring aname;
-       pull_ascii_nstring(aname, answer_name->name);
+       unstring aname;
+       pull_ascii_nstring(aname, sizeof(aname), answer_name->name);
        DEBUG(3,("check_for_master_browser_success: Local master browser for workgroup %s exists at \
 IP %s (just checking).\n", aname, inet_ntoa(answer_ip) ));
 }
@@ -85,10 +84,10 @@ static void check_for_master_browser_fail( struct subnet_record *subrec,
                                            struct nmb_name *question_name,
                                            int fail_code)
 {
-       nstring workgroup_name;
+       unstring workgroup_name;
        struct work_record *work;
 
-       pull_ascii_nstring(workgroup_name,question_name->name);
+       pull_ascii_nstring(workgroup_name,sizeof(workgroup_name),question_name->name);
 
        work = find_workgroup_on_subnet(subrec, workgroup_name);
        if(work == NULL) {
@@ -97,7 +96,7 @@ static void check_for_master_browser_fail( struct subnet_record *subrec,
                return;
        }
 
-       if (strnequal(work->work_group, lp_workgroup(), sizeof(nstring)-1)) {
+       if (strequal(work->work_group, lp_workgroup())) {
 
                if (lp_local_master()) {
                        /* We have discovered that there is no local master
@@ -145,7 +144,7 @@ void check_master_browser_exists(time_t t)
                struct work_record *work;
 
                for (work = subrec->workgrouplist; work; work = work->next) {
-                       if (strnequal(work->work_group, workgroup_name, sizeof(nstring)-1) && !AM_LOCAL_MASTER_BROWSER(work)) {
+                       if (strequal(work->work_group, workgroup_name) && !AM_LOCAL_MASTER_BROWSER(work)) {
                                /* Do a name query for the local master browser on this net. */
                                query_name( subrec, work->work_group, 0x1d,
                                        check_for_master_browser_success,
@@ -166,13 +165,16 @@ void run_elections(time_t t)
   
        struct subnet_record *subrec;
   
+       START_PROFILE(run_elections);
+
        /* Send election packets once every 2 seconds - note */
-       if (lastime && (t - lastime < 2))
+       if (lastime && (t - lastime < 2)) {
+               END_PROFILE(run_elections);
                return;
+       }
   
        lastime = t;
   
-       START_PROFILE(run_elections);
        for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
                struct work_record *work;
 
@@ -214,7 +216,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;
@@ -263,14 +265,15 @@ void process_election(struct subnet_record *subrec, struct packet_struct *p, cha
        int version = CVAL(buf,0);
        uint32 criterion = IVAL(buf,1);
        int timeup = IVAL(buf,5)/1000;
-       nstring server_name;
+       unstring server_name;
        struct work_record *work;
-       nstring workgroup_name;
-
-       pull_ascii_nstring(server_name, buf+13);
-       pull_ascii_nstring(workgroup_name, dgram->dest_name.name);
+       unstring workgroup_name;
 
        START_PROFILE(election);
+
+       pull_ascii_nstring(server_name, sizeof(server_name), buf+13);
+       pull_ascii_nstring(workgroup_name, sizeof(workgroup_name), dgram->dest_name.name);
+
        server_name[15] = 0;  
 
        DEBUG(3,("process_election: Election request from %s at IP %s on subnet %s for workgroup %s.\n",
@@ -284,7 +287,7 @@ void process_election(struct subnet_record *subrec, struct packet_struct *p, cha
                goto done;
        }
 
-       if (!strnequal(work->work_group, lp_workgroup(), sizeof(nstring)-1)) {
+       if (!strequal(work->work_group, lp_workgroup())) {
                DEBUG(3,("process_election: ignoring election request for workgroup %s on subnet %s as this \
 is not my workgroup.\n", work->work_group, subrec->subnet_name ));
                goto done;
@@ -325,10 +328,10 @@ 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;
@@ -374,14 +377,18 @@ 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, pid_t 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;
 
        for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
                struct work_record *work;
                for (work = subrec->workgrouplist; work; work = work->next) {
-                       if (strnequal(work->work_group, lp_workgroup(), sizeof(nstring)-1)) {
+                       if (strequal(work->work_group, lp_workgroup())) {
                                work->needelection = True;
                                work->ElectionCount=0;
                                work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE;