credentials.c:
[kai/samba.git] / source3 / smbparse.c
index d39f18de5f45ddfccf545311e78a50b3ae169b51..01438281ef146e4c67c0b9082720a86ff04f65c2 100644 (file)
@@ -2,7 +2,7 @@
    Unix SMB/Netbios implementation.
    Version 1.9.
    Samba utility functions
    Unix SMB/Netbios implementation.
    Version 1.9.
    Samba utility functions
-   Copyright (C) Luke Leighton 1996 - 1997
+   Copyright (C) Luke Leighton 1996 - 1997  Paul Ashton 1997
    
    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
    
    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
 extern int DEBUGLEVEL;
 
 
 extern int DEBUGLEVEL;
 
 
+/*******************************************************************
+reads or writes a UTIME type.
+********************************************************************/
+char* smb_io_utime(BOOL io, UTIME *t, char *q, char *base, int align)
+{
+       if (t == NULL) return NULL;
+
+       q = align_offset(q, base, align);
+       
+       RW_IVAL (io, q, t->time, 0); q += 4;
+
+       return q;
+}
+
 /*******************************************************************
 reads or writes an NTTIME structure.
 ********************************************************************/
 /*******************************************************************
 reads or writes an NTTIME structure.
 ********************************************************************/
@@ -42,7 +56,7 @@ char* smb_io_time(BOOL io, NTTIME *nttime, char *q, char *base, int align)
 /*******************************************************************
 reads or writes a DOM_SID structure.
 ********************************************************************/
 /*******************************************************************
 reads or writes a DOM_SID structure.
 ********************************************************************/
-char* smb_io_sid(BOOL io, DOM_SID *sid, char *q, char *base, int align)
+char* smb_io_dom_sid(BOOL io, DOM_SID *sid, char *q, char *base, int align)
 {
        int i;
 
 {
        int i;
 
@@ -222,6 +236,20 @@ char* smb_io_log_info(BOOL io, DOM_LOG_INFO *log, char *q, char *base, int align
        return q;
 }
 
        return q;
 }
 
+/*******************************************************************
+reads or writes a DOM_CHAL structure.
+********************************************************************/
+char* smb_io_chal(BOOL io, DOM_CHAL *chal, char *q, char *base, int align)
+{
+       if (chal == NULL) return NULL;
+
+       q = align_offset(q, base, align);
+       
+       RW_PCVAL(io, q, chal->data, 8); q += 8;
+
+       return q;
+}
+
 /*******************************************************************
 reads or writes a DOM_CRED structure.
 ********************************************************************/
 /*******************************************************************
 reads or writes a DOM_CRED structure.
 ********************************************************************/
@@ -231,8 +259,8 @@ char* smb_io_cred(BOOL io, DOM_CRED *cred, char *q, char *base, int align)
 
        q = align_offset(q, base, align);
        
 
        q = align_offset(q, base, align);
        
-       RW_PCVAL(io, q, cred->data, 8); q += 8;
-       RW_IVAL (io, q, cred->timestamp, 0); q += 4;
+       q = smb_io_chal (io, &(cred->challenge), q, base, align);
+       q = smb_io_utime(io, &(cred->timestamp), q, base, align);
 
        return q;
 }
 
        return q;
 }
@@ -268,9 +296,9 @@ char* smb_io_logon_id(BOOL io, DOM_LOGON_ID *log, char *q, char *base, int align
 }
 
 /*******************************************************************
 }
 
 /*******************************************************************
-reads or writes an RC4_OWF structure.
+reads or writes an ARC4_OWF structure.
 ********************************************************************/
 ********************************************************************/
-char* smb_io_rc4_owf(BOOL io, RC4_OWF *hash, char *q, char *base, int align)
+char* smb_io_arc4_owf(BOOL io, ARC4_OWF *hash, char *q, char *base, int align)
 {
        if (hash == NULL) return NULL;
 
 {
        if (hash == NULL) return NULL;
 
@@ -298,8 +326,8 @@ char* smb_io_id_info1(BOOL io, DOM_ID_INFO_1 *id, char *q, char *base, int align
        q = smb_io_unihdr(io, &(id->hdr_user_name     ), q, base, align);
        q = smb_io_unihdr(io, &(id->hdr_workgroup_name), q, base, align);
 
        q = smb_io_unihdr(io, &(id->hdr_user_name     ), q, base, align);
        q = smb_io_unihdr(io, &(id->hdr_workgroup_name), q, base, align);
 
-       q = smb_io_rc4_owf(io, &(id->rc4_lm_owf), q, base, align);
-       q = smb_io_rc4_owf(io, &(id->rc4_nt_owf), q, base, align);
+       q = smb_io_arc4_owf(io, &(id->arc4_lm_owf), q, base, align);
+       q = smb_io_arc4_owf(io, &(id->arc4_nt_owf), q, base, align);
 
        q = smb_io_unistr2(io, &(id->uni_domain_name   ), q, base, align);
        q = smb_io_unistr2(io, &(id->uni_user_name     ), q, base, align);
 
        q = smb_io_unistr2(io, &(id->uni_domain_name   ), q, base, align);
        q = smb_io_unistr2(io, &(id->uni_user_name     ), q, base, align);
@@ -379,6 +407,133 @@ char* smb_io_rpc_hdr(BOOL io, RPC_HDR *rpc, char *q, char *base, int align)
        return q;
 }
 
        return q;
 }
 
+/*******************************************************************
+reads or writes an LSA_POL_HND structure.
+********************************************************************/
+char* smb_io_pol_hnd(BOOL io, LSA_POL_HND *pol, char *q, char *base, int align)
+{
+       if (pol == NULL) return NULL;
+
+       q = align_offset(q, base, align);
+       
+       RW_PCVAL(io, q, pol->data, POL_HND_SIZE); q += POL_HND_SIZE;
+
+       return q;
+}
+
+/*******************************************************************
+reads or writes a dom query structure.
+********************************************************************/
+char* smb_io_dom_query_3(BOOL io, DOM_QUERY_3 *d_q, char *q, char *base, int align)
+{
+       return smb_io_dom_query(io, d_q, q, base, align);
+}
+
+/*******************************************************************
+reads or writes a dom query structure.
+********************************************************************/
+char* smb_io_dom_query_5(BOOL io, DOM_QUERY_3 *d_q, char *q, char *base, int align)
+{
+       return smb_io_dom_query(io, d_q, q, base, align);
+}
+
+/*******************************************************************
+reads or writes a dom query structure.
+********************************************************************/
+char* smb_io_dom_query(BOOL io, DOM_QUERY *d_q, char *q, char *base, int align)
+{
+       if (d_q == NULL) return NULL;
+
+       q = align_offset(q, base, align);
+       
+
+       RW_SVAL(io, q, d_q->uni_dom_max_len, 0); q += 2; /* domain name string length * 2 */
+       RW_SVAL(io, q, d_q->padding        , 0); q += 2; /* 2 padding bytes */
+       RW_SVAL(io, q, d_q->uni_dom_str_len, 0); q += 2; /* domain name string length * 2 */
+
+       RW_IVAL(io, q, d_q->buffer_dom_name, 0); q += 4; /* undocumented domain name string buffer pointer */
+       RW_IVAL(io, q, d_q->buffer_dom_sid , 0); q += 4; /* undocumented domain SID string buffer pointer */
+
+       if (d_q->buffer_dom_name != 0)
+       {
+               q = smb_io_unistr2(io, &(d_q->uni_domain_name), q, base, align); /* domain name (unicode string) */
+       }
+       if (d_q->buffer_dom_sid != 0)
+       {
+               q = smb_io_dom_sid(io, &(d_q->dom_sid), q, base, align); /* domain SID */
+       }
+
+       return q;
+}
+
+/*******************************************************************
+reads or writes a DOM_R_REF structure.
+********************************************************************/
+char* smb_io_dom_r_ref(BOOL io, DOM_R_REF *r_r, char *q, char *base, int align)
+{
+       int i;
+
+       if (r_r == NULL) return NULL;
+
+       q = align_offset(q, base, align);
+       
+       RW_IVAL(io, q, r_r->undoc_buffer, 0); q += 4; /* undocumented buffer pointer. */
+       RW_IVAL(io, q, r_r->num_ref_doms_1, 0); q += 4; /* num referenced domains? */
+       RW_IVAL(io, q, r_r->buffer_dom_name, 0); q += 4; /* undocumented domain name buffer pointer. */
+       RW_IVAL(io, q, r_r->max_entries, 0); q += 4; /* 32 - max number of entries */
+       RW_IVAL(io, q, r_r->num_ref_doms_2, 0); q += 4; /* 4 - num referenced domains? */
+
+       q = smb_io_unihdr2(io, &(r_r->hdr_dom_name), q, base, align); /* domain name unicode string header */
+
+       for (i = 0; i < r_r->num_ref_doms_1-1; i++)
+       {
+               q = smb_io_unihdr2(io, &(r_r->hdr_ref_dom[i]), q, base, align);
+       }
+
+       q = smb_io_unistr(io, &(r_r->uni_dom_name), q, base, align); /* domain name unicode string */
+
+       for (i = 0; i < r_r->num_ref_doms_2; i++)
+       {
+               q = smb_io_dom_sid(io, &(r_r->ref_dom[i]), q, base, align); /* referenced domain SIDs */
+       }
+       return q;
+}
+
+/*******************************************************************
+reads or writes a DOM_NAME structure.
+********************************************************************/
+char* smb_io_dom_name(BOOL io, DOM_NAME *name, char *q, char *base, int align)
+{
+       if (name == NULL) return NULL;
+
+       q = align_offset(q, base, align);
+       
+       RW_IVAL(io, q, name->uni_str_len, 0); q += 4;
+
+       /* don't know if len is specified by uni_str_len member... */
+       /* assume unicode string is unicode-null-terminated, instead */
+
+       q = smb_io_unistr(io, &(name->str), q, base, align);
+
+       return q;
+}
+
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+char* smb_io_neg_flags(BOOL io, NEG_FLAGS *neg, char *q, char *base, int align)
+{
+       if (neg == NULL) return NULL;
+
+       q = align_offset(q, base, align);
+       
+       RW_IVAL(io, q, neg->neg_flags, 0); q += 4;
+
+       return q;
+}
+
+
 #if 0
 /*******************************************************************
 reads or writes a structure.
 #if 0
 /*******************************************************************
 reads or writes a structure.