Try again to fix up 'session request' name exchange. This time we actualy
[tprouty/samba.git] / source / libsmb / nmblib.c
index d38e2ff0ecf8f3a82e099e91c9effe35b08f7558..6ee05f010452c326d2d6b2b9914b7cc13f197db8 100644 (file)
@@ -25,7 +25,7 @@ int num_good_sends = 0;
 int num_good_receives = 0;
 
 static const struct opcode_names {
-       char *nmb_opcode_name;
+       const char *nmb_opcode_name;
        int opcode;
 } nmb_header_opcode_names[] = {
        {"Query",           0 },
@@ -57,7 +57,7 @@ static const char *lookup_opcode_name( int opcode )
 /****************************************************************************
   print out a res_rec structure
   ****************************************************************************/
-static void debug_nmb_res_rec(struct res_rec *res, char *hdr)
+static void debug_nmb_res_rec(struct res_rec *res, const char *hdr)
 {
   int i, j;
 
@@ -295,7 +295,7 @@ static int put_nmb_name(char *buf,int offset,struct nmb_name *name)
   if (name->scope[0]) {
     /* XXXX this scope handling needs testing */
     ret += strlen(name->scope) + 1;
-    pstrcpy(&buf[offset+1],name->scope);  
+    safe_strcpy(&buf[offset+1],name->scope,sizeof(name->scope));  
   
     p = &buf[offset+1];
     while ((p = strchr_m(p,'.'))) {
@@ -823,7 +823,7 @@ void make_nmb_name( struct nmb_name *n, const char *name, int type)
        push_ascii(n->name, name, 16, STR_TERMINATE|STR_UPPER);
        n->name_type = (unsigned int)type & 0xFF;
        StrnCpy( n->scope, global_scope(), 63 );
-       strupper( n->scope );
+       strupper_m( n->scope );
 }
 
 /*******************************************************************
@@ -1005,7 +1005,7 @@ struct packet_struct *receive_nmb_packet(int fd, int t, int trn_id)
   queue. The packet must be a reply packet and have the specified mailslot name
   The timeout is in milliseconds
   ***************************************************************************/
-struct packet_struct *receive_dgram_packet(int fd, int t, char *mailslot_name)
+struct packet_struct *receive_dgram_packet(int fd, int t, const char *mailslot_name)
 {
        struct packet_struct *p;
 
@@ -1024,7 +1024,7 @@ struct packet_struct *receive_dgram_packet(int fd, int t, char *mailslot_name)
 /****************************************************************************
  see if a datagram has the right mailslot name
 ***************************************************************************/
-BOOL match_mailslot_name(struct packet_struct *p, char *mailslot_name)
+BOOL match_mailslot_name(struct packet_struct *p, const char *mailslot_name)
 {
        struct dgram_packet *dgram = &p->packet.dgram;
        char *buf;
@@ -1129,12 +1129,14 @@ char *dns_to_netbios_name(char *dns_name)
 
 
 /****************************************************************************
-interpret the weird netbios "name". Return the name type
+interpret the weird netbios "name" into a unix fstring. Return the name type
 ****************************************************************************/
-static int name_interpret(char *in,char *out)
+static int name_interpret(char *in, fstring name)
 {
   int ret;
   int len = (*in++) / 2;
+  fstring out_string;
+  char *out = out_string;
 
   *out=0;
 
@@ -1150,8 +1152,8 @@ static int name_interpret(char *in,char *out)
       in += 2;
       out++;
     }
-  *out = 0;
   ret = out[-1];
+  out[-1] = 0;
 
 #ifdef NETBIOS_SCOPE
   /* Handle any scope names */
@@ -1165,6 +1167,8 @@ static int name_interpret(char *in,char *out)
       in += len;
     }
 #endif
+  pull_ascii(name, out_string, sizeof(fstring), sizeof(out_string), STR_TERMINATE);
+
   return(ret);
 }
 
@@ -1245,9 +1249,9 @@ static char *name_ptr(char *buf,int ofs)
 }  
 
 /****************************************************************************
-extract a netbios name from a buf
+extract a netbios name from a buf (into a unix string) return name type
 ****************************************************************************/
-int name_extract(char *buf,int ofs,char *name)
+int name_extract(char *buf,int ofs, fstring name)
 {
   char *p = name_ptr(buf,ofs);
   int d = PTR_DIFF(p,buf+ofs);