s3-param Remove special case for global_myname(), rename to lp_netbios_name()
[kai/samba.git] / source3 / nmbd / nmbd_incomingdgrams.c
index ec8aa370ce3e19edfa67fff4240ba721e0572e3f..582848c1fcf7858fb12dc1abd2a2166d6d6a68d9 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 "../librpc/gen_ndr/svcctl.h"
+#include "nmbd/nmbd.h"
+#include "smbprofile.h"
 
-extern BOOL found_lm_clients;
+extern bool found_lm_clients;
 
 #if 0
 
@@ -93,7 +95,7 @@ void tell_become_backup(void)
   Process an incoming host announcement packet.
 *******************************************************************/
 
-void process_host_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf)
+void process_host_announce(struct subnet_record *subrec, struct packet_struct *p, const char *buf)
 {
        struct dgram_packet *dgram = &p->packet.dgram;
        int ttl = IVAL(buf,1)/1000;
@@ -142,7 +144,7 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p
         * to be our primary workgroup name.
         */
 
-       if(strequal(work_name, global_myname()))
+       if(strequal(work_name, lp_netbios_name()))
                unstrcpy(work_name,lp_workgroup());
 
        /*
@@ -170,7 +172,7 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p
                        /* Update the record. */
                        servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY;
                        update_server_ttl( servrec, ttl);
-                       fstrcpy(servrec->serv.comment,comment);
+                       strlcpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment));
                }
        } else {
                /*
@@ -193,7 +195,7 @@ done:
   Process an incoming WORKGROUP announcement packet.
 *******************************************************************/
 
-void process_workgroup_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf)
+void process_workgroup_announce(struct subnet_record *subrec, struct packet_struct *p, const char *buf)
 {
        struct dgram_packet *dgram = &p->packet.dgram;
        int ttl = IVAL(buf,1)/1000;
@@ -250,7 +252,7 @@ done:
   Process an incoming local master browser announcement packet.
 *******************************************************************/
 
-void process_local_master_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf)
+void process_local_master_announce(struct subnet_record *subrec, struct packet_struct *p, const char *buf)
 {
        struct dgram_packet *dgram = &p->packet.dgram;
        int ttl = IVAL(buf,1)/1000;
@@ -258,7 +260,7 @@ void process_local_master_announce(struct subnet_record *subrec, struct packet_s
        uint32 servertype = IVAL(buf,23);
        fstring comment;
        unstring work_name;
-       struct work_record *work;
+       struct work_record *work = NULL;
        struct server_record *servrec;
        unstring source_name;
 
@@ -336,7 +338,7 @@ a local master browser for workgroup %s and we think we are master. Forcing elec
                        /* Update the record. */
                        servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY;
                        update_server_ttl(servrec, ttl);
-                       fstrcpy(servrec->serv.comment,comment);
+                       strlcpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment));
                }
        
                set_workgroup_local_master_browser_name( work, server_name );
@@ -345,7 +347,7 @@ a local master browser for workgroup %s and we think we are master. Forcing elec
                 * This server is announcing it is going down. Remove it from the
                 * workgroup.
                 */
-               if(!is_myname(server_name) && (work != NULL) &&
+               if(!is_myname(server_name) &&
                                ((servrec = find_server_in_workgroup( work, server_name))!=NULL)) {
                        remove_server_from_workgroup( work, servrec);
                }
@@ -365,7 +367,7 @@ done:
 ******************************************************************/
 
 void process_master_browser_announce(struct subnet_record *subrec, 
-                                     struct packet_struct *p,char *buf)
+                                     struct packet_struct *p,const char *buf)
 {
        unstring local_master_name;
        struct work_record *work;
@@ -416,7 +418,7 @@ done:
   Process an incoming LanMan host announcement packet.
 *******************************************************************/
 
-void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf, int len)
+void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct *p, const char *buf, int len)
 {
        struct dgram_packet *dgram = &p->packet.dgram;
        uint32 servertype = IVAL(buf,1);
@@ -429,13 +431,13 @@ void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct
        unstring work_name;
        unstring source_name;
        fstring comment;
-       char *s = get_safe_str_ptr(buf,len,buf,9);
+       char *s = get_safe_str_ptr(buf,len,discard_const_p(char, buf),9);
 
        START_PROFILE(lm_host_announce);
        if (!s) {
                goto done;
        }
-       s = skip_string(buf,len,s,1);
+       s = skip_string(buf,len,s);
        if (!s) {
                goto done;
        }
@@ -482,7 +484,7 @@ originate from OS/2 Warp client. Ignoring packet.\n"));
         * not needed in the LanMan announce code, but it won't hurt.
         */
 
-       if(strequal(work_name, global_myname()))
+       if(strequal(work_name, lp_netbios_name()))
                unstrcpy(work_name,lp_workgroup());
 
        /*
@@ -510,7 +512,7 @@ originate from OS/2 Warp client. Ignoring packet.\n"));
                        /* Update the record. */
                        servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY;
                        update_server_ttl( servrec, ttl);
-                       fstrcpy(servrec->serv.comment,comment);
+                       strlcpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment));
                }
        } else {
                /*
@@ -535,13 +537,13 @@ done:
   Send a backup list response.
 *****************************************************************************/
 
-static void send_backup_list_response(struct subnet_record *subrec, 
+static void send_backup_list_response(struct subnet_record *subrec,
                                      struct work_record *work,
                                      struct nmb_name *send_to_name,
                                      unsigned char max_number_requested,
                                      uint32 token, struct in_addr sendto_ip,
                                      int port)
-{                     
+{
        char outbuf[1024];
        char *p, *countptr;
        unsigned int count = 0;
@@ -555,9 +557,9 @@ static void send_backup_list_response(struct subnet_record *subrec,
 
        DEBUG(3,("send_backup_list_response: sending backup list for workgroup %s to %s IP %s\n",
                work->work_group, nmb_namestr(send_to_name), inet_ntoa(sendto_ip)));
-  
+
        p = outbuf;
-  
+
        SCVAL(p,0,ANN_GetBackupListResp); /* Backup list response opcode. */
        p++;
 
@@ -566,15 +568,15 @@ static void send_backup_list_response(struct subnet_record *subrec,
 
        SIVAL(p,0,token); /* The sender's unique info. */
        p += 4;
-  
+
        /* We always return at least one name - our own. */
        count = 1;
-       unstrcpy(myname, global_myname());
+       unstrcpy(myname, lp_netbios_name());
        strupper_m(myname);
        myname[15]='\0';
-       push_pstring_base(p, myname, outbuf);
+       push_ascii(p, myname, sizeof(outbuf)-PTR_DIFF(p,outbuf)-1, STR_TERMINATE);
 
-       p = skip_string(outbuf,sizeof(outbuf),p,1);
+       p = skip_string(outbuf,sizeof(outbuf),p);
 
        /* Look for backup browsers in this workgroup. */
 
@@ -597,7 +599,7 @@ static void send_backup_list_response(struct subnet_record *subrec,
     if(count >= (unsigned int)max_number_requested)
       break;
 
-    if(strnequal(servrec->serv.name, global_myname(),15))
+    if(strnequal(servrec->serv.name, lp_netbios_name(),15))
       continue;
 
     if(!(servrec->serv.type & SV_TYPE_BACKUP_BROWSER))
@@ -610,7 +612,7 @@ static void send_backup_list_response(struct subnet_record *subrec,
     DEBUG(5,("send_backup_list_response: Adding server %s number %d\n",
               p, count));
 
-    p = skip_string(outbuf,sizeof(outbuf),p,1);
+    p = skip_string(outbuf,sizeof(outbuf),p);
   }
 #endif
 
@@ -623,7 +625,7 @@ static void send_backup_list_response(struct subnet_record *subrec,
 
        send_mailslot(True, BROWSE_MAILSLOT,
                outbuf,PTR_DIFF(p,outbuf),
-               global_myname(), 0, 
+               lp_netbios_name(), 0,
                send_to_namestr,0,
                sendto_ip, subrec->myip, port);
 }
@@ -639,7 +641,7 @@ static void send_backup_list_response(struct subnet_record *subrec,
 ********************************************************************/
 
 void process_get_backup_list_request(struct subnet_record *subrec,
-                                     struct packet_struct *p,char *buf)
+                                     struct packet_struct *p,const char *buf)
 {
        struct dgram_packet *dgram = &p->packet.dgram;
        struct work_record *work;
@@ -722,7 +724,7 @@ done:
 ******************************************************************/
 
 void process_reset_browser(struct subnet_record *subrec,
-                                  struct packet_struct *p,char *buf)
+                                  struct packet_struct *p,const char *buf)
 {
        struct dgram_packet *dgram = &p->packet.dgram;
        int state = CVAL(buf,0);
@@ -774,7 +776,7 @@ request from %s IP %s state=0x%X\n",
   announcement is needed soon.
 ******************************************************************/
 
-void process_announce_request(struct subnet_record *subrec, struct packet_struct *p, char *buf)
+void process_announce_request(struct subnet_record *subrec, struct packet_struct *p, const char *buf)
 {
        struct dgram_packet *dgram = &p->packet.dgram;
        struct work_record *work;
@@ -815,7 +817,7 @@ done:
   through the "lm announce" parameter in smb.conf)
 ******************************************************************/
 
-void process_lm_announce_request(struct subnet_record *subrec, struct packet_struct *p, char *buf, int len)
+void process_lm_announce_request(struct subnet_record *subrec, struct packet_struct *p, const char *buf, int len)
 {
        struct dgram_packet *dgram = &p->packet.dgram;
        unstring workgroup_name;