proto.h:
authorLuke Leighton <lkcl@samba.org>
Sat, 4 Oct 1997 16:51:43 +0000 (16:51 +0000)
committerLuke Leighton <lkcl@samba.org>
Sat, 4 Oct 1997 16:51:43 +0000 (16:51 +0000)
- recreated, as usual.

smb.h:

- added RPC_HDR structure - the 18 byte MSRPC header

smbparse.c:

- added smb_io_rpc_hdr() function to read/write the RPC_HDR structure.

util.c:

- added align2, align4, align_offset functions.
- added skip_unicode_string, unistrcpy, unistrncpy functions.
- modified unistrcpy and unistrncpy to return the number of unicode
  characters returned, effectively making skip_unicode_string redundant.
(This used to be commit b0ad811cda3dcffed5b24104229813cdb17b014f)

source3/include/proto.h
source3/include/smb.h
source3/lib/util.c
source3/smbparse.c

index 8818b9b52742cea0044d24eaf34067f61e3b84c3..4ec4a42f2aa7cffdc3e416182dd1f96459d238c3 100644 (file)
@@ -565,7 +565,9 @@ void sync_browse_lists(struct subnet_record *d, struct work_record *work,
 
 /*The following definitions come from  params.c  */
 
-BOOL pm_process(char *pszFileName,BOOL (*sfunc)(char *),BOOL (*pfunc)(char *,char *));
+BOOL pm_process( char *FileName,
+                 BOOL (*sfunc)(char *),
+                 BOOL (*pfunc)(char *, char *) );
 
 /*The following definitions come from  password.c  */
 
@@ -986,5 +988,12 @@ void file_unlock(int fd);
 BOOL is_myname(char *s);
 void set_remote_arch(enum remote_arch_types type);
 enum remote_arch_types get_remote_arch();
+char *skip_unicode_string(char *buf,int n);
+char *unistr(char *buf);
+int unistrncpy(char *dst, char *src, int len);
+int unistrcpy(char *dst, char *src);
 void fstrcpy(char *dest, char *src);
 void pstrcpy(char *dest, char *src);
+char *align4(char *q, char *base);
+char *align2(char *q, char *base);
+char *align_offset(char *q, char *base, int align_offset);
index 37474436cacbdbe02f1182569223ff866efe0ac2..b999c136677739485c10200aafec55998e4716ec 100644 (file)
@@ -80,6 +80,10 @@ typedef short int16;
 typedef int int32;
 #endif
 
+#ifndef uint8
+typedef unsigned char uint8;
+#endif
+
 #ifndef uint16
 typedef unsigned short uint16;
 #endif
@@ -416,7 +420,7 @@ typedef struct gid_info
 
 } DOM_GID;
 
-/* RPC_HEADER - ms rpc header */
+/* RPC_HDR - ms rpc header */
 typedef struct rpc_hdr_info
 {
   uint8  major; /* 5 - RPC major version */
@@ -431,7 +435,7 @@ typedef struct rpc_hdr_info
   uint16 context_id; /* 0 - presentation context identifier */
   uint8  cancel_count; /* 0 - cancel count */
   uint8  reserved; /* 0 - reserved */
-} RPC_HEADER;
+} RPC_HDR;
 
 
 struct smb_passwd {
index 01e2dae154c8103561d97c90a6084a15de07fd8b..c5cfdd99f75f2a8c7a00152a70b4ca7a3fde0538 100644 (file)
@@ -4182,6 +4182,80 @@ enum remote_arch_types get_remote_arch()
   return ra_type;
 }
 
+
+/*******************************************************************
+skip past some unicode strings in a buffer
+********************************************************************/
+char *skip_unicode_string(char *buf,int n)
+{
+  while (n--)
+  {
+    while (*buf)
+      buf += 2;
+    buf += 2;
+  }
+  return(buf);
+}
+
+/*******************************************************************
+Return a ascii version of a unicode string
+Hack alert: uses fixed buffer and only handles ascii strings
+********************************************************************/
+#define MAXUNI 1024
+char *unistr(char *buf)
+{
+       static char lbufs[8][MAXUNI];
+       static int nexti;
+       char *lbuf = lbufs[nexti];
+       char *p;
+       nexti = (nexti+1)%8;
+       for (p = lbuf; *buf && p -lbuf < MAXUNI-2; p++, buf += 2)
+               *p = *buf;
+       *p = 0;
+       return lbuf;
+}
+
+/*******************************************************************
+strncpy for unicode strings
+********************************************************************/
+int unistrncpy(char *dst, char *src, int len)
+{
+       int num_wchars = 0;
+
+       while (*src && len > 0)
+       {
+               *dst++ = *src++;
+               *dst++ = *src++;
+               len--;
+               num_wchars++;
+       }
+       *dst++ = 0;
+       *dst++ = 0;
+
+       return num_wchars;
+}
+
+
+/*******************************************************************
+strcpy for unicode strings.  returns length (in num of wide chars)
+********************************************************************/
+int unistrcpy(char *dst, char *src)
+{
+       int num_wchars = 0;
+
+       while (*src)
+       {
+               *dst++ = *src++;
+               *dst++ = *src++;
+               num_wchars++;
+       }
+       *dst++ = 0;
+       *dst++ = 0;
+
+       return num_wchars;
+}
+
+
 /*******************************************************************
 safe string copy into a fstring
 ********************************************************************/
@@ -4231,3 +4305,42 @@ void pstrcpy(char *dest, char *src)
              strlen(src)));
     }
 }  
+
+
+/*******************************************************************
+align a pointer to a multiple of 4 bytes
+********************************************************************/
+char *align4(char *q, char *base)
+{
+       if ((q - base) & 3)
+       {
+               q += 4 - ((q - base) & 3);
+       }
+       return q;
+}
+
+/*******************************************************************
+align a pointer to a multiple of 2 bytes
+********************************************************************/
+char *align2(char *q, char *base)
+{
+       if ((q - base) & 1)
+       {
+               q++;
+       }
+       return q;
+}
+
+/*******************************************************************
+align a pointer to a multiple of align_offset bytes.  looks like it
+will work for offsets of 0, 2 and 4...
+********************************************************************/
+char *align_offset(char *q, char *base, int align_offset)
+{
+       if (align_offset != 0 && ((q - base) & (align_offset-1)))
+       {
+               q += align_offset - ((q - base) & (align_offset));
+       }
+       return q;
+}
+
index bff1a1453a47cfd608fede0d6bf90fe88e3821f4..d39f18de5f45ddfccf545311e78a50b3ae169b51 100644 (file)
@@ -354,21 +354,32 @@ char* smb_io_gid(BOOL io, DOM_GID *gid, char *q, char *base, int align)
        return q;
 }
 
-#if 0
 /*******************************************************************
-reads or writes a structure.
+reads or writes an RPC_HDR structure.
 ********************************************************************/
- char* smb_io_(BOOL io, *, char *q, char *base, int align)
+char* smb_io_rpc_hdr(BOOL io, RPC_HDR *rpc, char *q, char *base, int align)
 {
-       if (== NULL) return NULL;
-
-       q = align_offset(q, base, align);
-       
-       RW_IVAL(io, q, , 0); q += 4;
+       if (rpc == NULL) return NULL;
+
+       /* reserved should be zero: enforce it */
+       rpc->reserved = 0;
+
+       RW_CVAL(io, q, rpc->major, 0); q++;
+       RW_CVAL(io, q, rpc->minor, 0); q++;
+       RW_CVAL(io, q, rpc->pkt_type, 0); q++;
+       RW_CVAL(io, q, rpc->frag, 0); q++;
+       RW_IVAL(io, q, rpc->pack_type, 0); q += 4;
+       RW_SVAL(io, q, rpc->frag_len, 0); q += 2;
+       RW_SVAL(io, q, rpc->auth_len, 0); q += 2;
+       RW_IVAL(io, q, rpc->call_id, 0); q += 4;
+       RW_SVAL(io, q, rpc->alloc_hint, 0); q += 2;
+       RW_CVAL(io, q, rpc->context_id, 0); q++;
+       RW_CVAL(io, q, rpc->reserved, 0); q++;
 
        return q;
 }
 
+#if 0
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/