s3-registry: Check return code of push_reg_sz().
[kai/samba.git] / source3 / nmbd / nmbd_incomingrequests.c
index 956d0ab1e9192e73aa7ee3ddb97f55a45de5dee5..562c388ee2990e0212b9162184297bf86b11f5a2 100644 (file)
@@ -25,6 +25,7 @@
 */
 
 #include "includes.h"
+#include "nmbd/nmbd.h"
 
 /****************************************************************************
 Send a name release response.
@@ -58,9 +59,9 @@ void process_name_release_request(struct subnet_record *subrec,
        struct in_addr owner_ip;
        struct nmb_name *question = &nmb->question.question_name;
        unstring qname;
-       BOOL bcast = nmb->header.nm_flags.bcast;
+       bool bcast = nmb->header.nm_flags.bcast;
        uint16 nb_flags = get_nb_flags(nmb->additional->rdata);
-       BOOL group = (nb_flags & NB_GROUP) ? True : False;
+       bool group = (nb_flags & NB_GROUP) ? True : False;
        struct name_record *namerec;
        int rcode = 0;
   
@@ -88,7 +89,7 @@ subnet %s from owner IP %s\n",
                subrec->subnet_name, inet_ntoa(owner_ip)));
   
        /* If someone is releasing a broadcast group name, just ignore it. */
-       if( group && !ismyip(owner_ip) )
+       if( group && !ismyip_v4(owner_ip) )
                return;
 
        /*
@@ -98,7 +99,7 @@ subnet %s from owner IP %s\n",
         */
 
        pull_ascii_nstring(qname, sizeof(qname), question->name);
-       if( !group && !ismyip(owner_ip) && strequal(qname, lp_workgroup()) && 
+       if( !group && !ismyip_v4(owner_ip) && strequal(qname, lp_workgroup()) && 
                        ((question->name_type == 0x0) || (question->name_type == 0x1e))) {
                DEBUG(6,("process_name_release_request: FTP OnNet bug workaround. Ignoring \
 group release name %s from IP %s on subnet %s with no group bit set.\n",
@@ -153,7 +154,7 @@ void process_name_refresh_request(struct subnet_record *subrec,
 {    
        struct nmb_packet *nmb = &p->packet.nmb;
        struct nmb_name *question = &nmb->question.question_name;
-       BOOL bcast = nmb->header.nm_flags.bcast;
+       bool bcast = nmb->header.nm_flags.bcast;
        struct in_addr from_ip;
   
        putip((char *)&from_ip,&nmb->additional->rdata[2]);
@@ -190,9 +191,9 @@ void process_name_registration_request(struct subnet_record *subrec,
 {
        struct nmb_packet *nmb = &p->packet.nmb;
        struct nmb_name *question = &nmb->question.question_name;
-       BOOL bcast = nmb->header.nm_flags.bcast;
+       bool bcast = nmb->header.nm_flags.bcast;
        uint16 nb_flags = get_nb_flags(nmb->additional->rdata);
-       BOOL group = (nb_flags & NB_GROUP) ? True : False;
+       bool group = (nb_flags & NB_GROUP) ? True : False;
        struct name_record *namerec = NULL;
        int ttl = nmb->additional->ttl;
        struct in_addr from_ip;
@@ -289,14 +290,14 @@ static int status_compare(char *n1,char *n2)
                ;
        for (l2=0;l2<15 && n2[l2] && n2[l2] != ' ';l2++)
                ;
-       l3 = strlen(global_myname());
+       l3 = strlen(lp_netbios_name());
 
-       if ((l1==l3) && strncmp(n1,global_myname(),l3) == 0 && 
-                       (l2!=l3 || strncmp(n2,global_myname(),l3) != 0))
+       if ((l1==l3) && strncmp(n1,lp_netbios_name(),l3) == 0 &&
+                       (l2!=l3 || strncmp(n2,lp_netbios_name(),l3) != 0))
                return -1;
 
-       if ((l2==l3) && strncmp(n2,global_myname(),l3) == 0 && 
-                       (l1!=l3 || strncmp(n1,global_myname(),l3) != 0))
+       if ((l2==l3) && strncmp(n2,lp_netbios_name(),l3) == 0 &&
+                       (l1!=l3 || strncmp(n1,lp_netbios_name(),l3) != 0))
                return 1;
 
        return memcmp(n1,n2,sizeof(name1));
@@ -314,14 +315,14 @@ void process_node_status_request(struct subnet_record *subrec, struct packet_str
        char rdata[MAX_DGRAM_SIZE];
        char *countptr, *buf, *bufend, *buf0;
        int names_added,i;
-       struct name_record *namerec;
+       struct name_record *namerec = NULL;
 
        pull_ascii_nstring(qname, sizeof(qname), nmb->question.question_name.name);
 
        DEBUG(3,("process_node_status_request: status request for name %s from IP %s on \
 subnet %s.\n", nmb_namestr(&nmb->question.question_name), inet_ntoa(p->ip), subrec->subnet_name));
 
-       if((namerec = find_name_on_subnet(subrec, &nmb->question.question_name, FIND_SELF_NAME)) == 0) {
+       if(find_name_on_subnet(subrec, &nmb->question.question_name, FIND_SELF_NAME) == 0) {
                DEBUG(1,("process_node_status_request: status request for name %s from IP %s on \
 subnet %s - name not found.\n", nmb_namestr(&nmb->question.question_name),
                        inet_ntoa(p->ip), subrec->subnet_name));
@@ -331,7 +332,7 @@ subnet %s - name not found.\n", nmb_namestr(&nmb->question.question_name),
  
        /* this is not an exact calculation. the 46 is for the stats buffer
                and the 60 is to leave room for the header etc */
-       bufend = &rdata[MAX_DGRAM_SIZE] - (18 + 46 + 60);
+       bufend = &rdata[MAX_DGRAM_SIZE-1] - (18 + 46 + 60);
        countptr = buf = rdata;
        buf += 1;
        buf0 = buf;
@@ -346,7 +347,10 @@ subnet %s - name not found.\n", nmb_namestr(&nmb->question.question_name),
                        unstring name;
 
                        pull_ascii_nstring(name, sizeof(name), namerec->name.name);
-                       strupper_m(name);
+                       if (!strupper_m(name)) {
+                               DEBUG(2,("strupper_m %s failed\n", name));
+                               return;
+                       }
                        if (!strequal(name,"*") &&
                                        !strequal(name,"__SAMBA__") &&
                                        (name_type < 0x1b || name_type >= 0x20 || 
@@ -373,6 +377,8 @@ subnet %s - name not found.\n", nmb_namestr(&nmb->question.question_name),
 
                /* Remove duplicate names. */
                if (names_added > 1) {
+                       /* TODO: should use a real type and
+                          TYPESAFE_QSORT() */
                        qsort( buf0, names_added, 18, QSORT_CAST status_compare );
                }
 
@@ -439,12 +445,12 @@ void process_name_query_request(struct subnet_record *subrec, struct packet_stru
        struct nmb_packet *nmb = &p->packet.nmb;
        struct nmb_name *question = &nmb->question.question_name;
        int name_type = question->name_type;
-       BOOL bcast = nmb->header.nm_flags.bcast;
+       bool bcast = nmb->header.nm_flags.bcast;
        int ttl=0;
        int rcode = 0;
        char *prdata = NULL;
        char rdata[6];
-       BOOL success = False;
+       bool success = False;
        struct name_record *namerec = NULL;
        int reply_data_len = 0;
        int i;
@@ -497,7 +503,7 @@ void process_name_query_request(struct subnet_record *subrec, struct packet_stru
                        
                        if (namerec->data.source == WINS_PROXY_NAME) {
                                for( i = 0; i < namerec->data.num_ips; i++) {
-                                       if (same_net(namerec->data.ip[i], subrec->myip, subrec->mask_ip)) {
+                                       if (same_net_v4(namerec->data.ip[i], subrec->myip, subrec->mask_ip)) {
                                                DEBUG(5,("process_name_query_request: name %s is a WINS proxy name and is also on the same subnet (%s) as the requestor. Not replying.\n", 
                                                         nmb_namestr(&namerec->name), subrec->subnet_name ));
                                                return;