summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/include/proto.h11
-rw-r--r--source3/include/smb.h8
-rw-r--r--source3/lib/util.c113
-rw-r--r--source3/smbparse.c27
4 files changed, 148 insertions, 11 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 8818b9b527..4ec4a42f2a 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -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);
diff --git a/source3/include/smb.h b/source3/include/smb.h
index 37474436ca..b999c13667 100644
--- a/source3/include/smb.h
+++ b/source3/include/smb.h
@@ -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 {
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 01e2dae154..c5cfdd99f7 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -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;
+}
+
diff --git a/source3/smbparse.c b/source3/smbparse.c
index bff1a1453a..d39f18de5f 100644
--- a/source3/smbparse.c
+++ b/source3/smbparse.c
@@ -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.
********************************************************************/