SAM database "set user info".
[samba.git] / source3 / rpc_parse / parse_misc.c
index ad268f60a47a4321005c4015ba96655d940d5f7e..64cbdef7169158b08a882ae6b1542388a0f778fe 100644 (file)
@@ -118,11 +118,11 @@ void smb_io_enum_hnd(char *desc,  ENUM_HND *hnd, prs_struct *ps, int depth)
 /*******************************************************************
 reads or writes a DOM_SID structure.
 ********************************************************************/
-void smb_io_dom_sid(char *desc,  DOM_SID *sid, prs_struct *ps, int depth)
+BOOL smb_io_dom_sid(char *desc,  DOM_SID *sid, prs_struct *ps, int depth)
 {
        int i;
 
-       if (sid == NULL) return;
+       if (sid == NULL) return False;
 
        prs_debug(ps, depth, desc, "smb_io_dom_sid");
        depth++;
@@ -143,68 +143,16 @@ void smb_io_dom_sid(char *desc,  DOM_SID *sid, prs_struct *ps, int depth)
        if (sid->num_auths > MAXSUBAUTHS) sid->num_auths = MAXSUBAUTHS;
 
        prs_uint32s(False, "sub_auths ", ps, depth, sid->sub_auths, sid->num_auths);
-}
-
-/*******************************************************************
-creates a DOM_SID structure.
-
-BIG NOTE: this function only does SIDS where the identauth is not >= 2^32 
-identauth >= 2^32 can be detected because it will be specified in hex
-
-********************************************************************/
-void make_dom_sid(DOM_SID *sid, char *str_sid)
-{
-       pstring domsid;
-       int identauth;
-       char *p;
-
-       if (sid == NULL) return;
-
-       if (domsid == NULL)
-       {
-               DEBUG(4,("netlogon domain SID: none\n"));
-               sid->sid_rev_num = 0;
-               sid->num_auths = 0;
-               return;
-       }
-               
-       pstrcpy(domsid, str_sid);
-
-       DEBUG(4,("make_dom_sid %d SID:  %s\n", __LINE__, domsid));
-
-       /* assume, but should check, that domsid starts "S-" */
-       p = strtok(domsid+2,"-");
-       sid->sid_rev_num = atoi(p);
-
-       /* identauth in decimal should be <  2^32 */
-       /* identauth in hex     should be >= 2^32 */
-       identauth = atoi(strtok(0,"-"));
 
-       DEBUG(4,("netlogon rev %d\n", sid->sid_rev_num));
-       DEBUG(4,("netlogon %s ia %d\n", p, identauth));
-
-       sid->id_auth[0] = 0;
-       sid->id_auth[1] = 0;
-       sid->id_auth[2] = (identauth & 0xff000000) >> 24;
-       sid->id_auth[3] = (identauth & 0x00ff0000) >> 16;
-       sid->id_auth[4] = (identauth & 0x0000ff00) >> 8;
-       sid->id_auth[5] = (identauth & 0x000000ff);
-
-       sid->num_auths = 0;
-
-       while ((p = strtok(0, "-")) != NULL && sid->num_auths < MAXSUBAUTHS)
-       {
-               sid->sub_auths[sid->num_auths++] = atoi(p);
-       }
-
-       DEBUG(4,("make_dom_sid: %d SID:  %s\n", __LINE__, domsid));
+       return True;
 }
+
 /*******************************************************************
 creates a DOM_SID2 structure.
 ********************************************************************/
 void make_dom_sid2(DOM_SID2 *sid2, DOM_SID *sid)
 {
-        sid_copy(&sid2->sid, sid);
+        sid2->sid = *sid;
        sid2->num_auths = sid2->sid.num_auths;
 }
 
@@ -256,14 +204,45 @@ void smb_io_strhdr(char *desc,  STRHDR *hdr, prs_struct *ps, int depth)
        if (hdr->str_str_len > MAX_STRINGLEN) hdr->str_str_len = MAX_STRINGLEN;
 }
 
+/*******************************************************************
+creates a STRHDR2 structure.
+********************************************************************/
+void make_strhdr2(STRHDR2 *hdr, uint32 max_len, uint32 len, uint32 buffer)
+{
+       hdr->str_max_len = max_len;
+       hdr->str_str_len = len;
+       hdr->buffer      = buffer;
+}
+
+/*******************************************************************
+reads or writes a STRHDR2 structure.
+********************************************************************/
+void smb_io_strhdr2(char *desc, STRHDR2 *hdr, prs_struct *ps, int depth)
+{
+       if (hdr == NULL) return;
+
+       prs_debug(ps, depth, desc, "smb_io_strhdr");
+       depth++;
+
+       prs_align(ps);
+       
+       prs_uint32("str_str_len", ps, depth, &(hdr->str_str_len));
+       prs_uint32("str_max_len", ps, depth, &(hdr->str_max_len));
+       prs_uint32("buffer     ", ps, depth, &(hdr->buffer     ));
+
+       /* oops! XXXX maybe issue a warning that this is happening... */
+       if (hdr->str_max_len > MAX_STRINGLEN) hdr->str_max_len = MAX_STRINGLEN;
+       if (hdr->str_str_len > MAX_STRINGLEN) hdr->str_str_len = MAX_STRINGLEN;
+}
+
 /*******************************************************************
 creates a UNIHDR structure.
 ********************************************************************/
-void make_uni_hdr(UNIHDR *hdr, int max_len, int len, uint32 buffer)
+void make_uni_hdr(UNIHDR *hdr, int len)
 {
        hdr->uni_str_len = 2 * len;
-       hdr->uni_max_len = 2 * max_len;
-       hdr->buffer      = buffer;
+       hdr->uni_max_len = 2 * len;
+       hdr->buffer      = len != 0 ? 1 : 0;
 }
 
 /*******************************************************************
@@ -355,9 +334,9 @@ void smb_io_hdrbuf(char *desc,  BUFHDR *hdr, prs_struct *ps, int depth)
 /*******************************************************************
 creates a UNIHDR2 structure.
 ********************************************************************/
-void make_uni_hdr2(UNIHDR2 *hdr, int max_len, int len, uint16 terminate)
+void make_uni_hdr2(UNIHDR2 *hdr, int len)
 {
-       make_uni_hdr(&(hdr->unihdr), max_len, len, terminate);
+       make_uni_hdr(&(hdr->unihdr), len);
        hdr->buffer = len > 0 ? 1 : 0;
 }
 
@@ -382,8 +361,7 @@ creates a UNISTR structure.
 ********************************************************************/
 void make_unistr(UNISTR *str, char *buf)
 {
-       /* store the string (null-terminated copy) */
-       struni2(str->buffer, buf);
+       ascii_to_unistr(str->buffer, buf, sizeof(str->buffer)-1);
 }
 
 /*******************************************************************
@@ -397,7 +375,6 @@ void smb_io_unistr(char *desc,  UNISTR *uni, prs_struct *ps, int depth)
        prs_debug(ps, depth, desc, "smb_io_unistr");
        depth++;
 
-       prs_align(ps);
        prs_unistr("unistr", ps, depth, uni);
 }
 
@@ -426,8 +403,8 @@ void make_buffer3_str(BUFFER3 *str, char *buf, int len)
        str->buf_max_len = len * 2;
        str->buf_len     = len * 2;
 
-       /* store the string (null-terminated 8 bit chars into 16 bit chars) */
-       struni2((uint16*)str->buffer, buf);
+       /* store the string (little endian buffer) */
+       ascii_to_unibuf(str->buffer, buf, str->buf_len);
 }
 
 /*******************************************************************
@@ -481,19 +458,17 @@ void smb_io_buffer3(char *desc,  BUFFER3 *buf3, prs_struct *ps, int depth)
 /*******************************************************************
 creates a BUFFER2 structure.
 ********************************************************************/
-void make_buffer2(BUFFER2 *str, uint8 *buf, int len)
+void make_buffer2(BUFFER2 *str, const char *buf, int len)
 {
        ZERO_STRUCTP(str);
 
-       /* max buffer size (allocated size) */
+       /* set up string lengths. */
        str->buf_max_len = len;
        str->undoc       = 0;
-       str->buf_len = buf != NULL ? len : 0;
+       str->buf_len     = len;
 
-       if (buf != NULL)
-       {
-               memcpy(str->buffer, buf, MIN(str->buf_len, sizeof(str->buffer)));
-       }
+       /* store the string (wide chars) */
+       ascii_to_unistr(str->buffer, buf, len);
 }
 
 /*******************************************************************
@@ -512,7 +487,7 @@ void smb_io_buffer2(char *desc,  BUFFER2 *buf2, uint32 buffer, prs_struct *ps, i
 
                prs_align(ps);
                
-               prs_uint32("uni_max_len", ps, depth, &(buf2->buf_max_len));
+               prs_uint32("buf_max_len", ps, depth, &(buf2->buf_max_len));
                prs_uint32("undoc      ", ps, depth, &(buf2->undoc      ));
                prs_uint32("buf_len    ", ps, depth, &(buf2->buf_len));
 
@@ -618,7 +593,7 @@ void smb_io_string2(char *desc,  STRING2 *str2, uint32 buffer, prs_struct *ps, i
 /*******************************************************************
 creates a UNISTR2 structure.
 ********************************************************************/
-void make_unistr2(UNISTR2 *str, char *buf, int len)
+void make_unistr2(UNISTR2 *str, const char *buf, int len)
 {
        ZERO_STRUCTP(str);
 
@@ -627,8 +602,8 @@ void make_unistr2(UNISTR2 *str, char *buf, int len)
        str->undoc       = 0;
        str->uni_str_len = len;
 
-       /* store the string (null-terminated 8 bit chars into 16 bit chars) */
-       struni2(str->buffer, buf);
+       /* store the string (wide chars) */
+       ascii_to_unistr(str->buffer, buf, len);
 }
 
 /*******************************************************************
@@ -671,11 +646,11 @@ void smb_io_unistr2(char *desc,  UNISTR2 *uni2, uint32 buffer, prs_struct *ps, i
 /*******************************************************************
 creates a DOM_RID2 structure.
 ********************************************************************/
-void make_dom_rid2(DOM_RID2 *rid2, uint32 rid, uint8 type)
+void make_dom_rid2(DOM_RID2 *rid2, uint32 rid, uint8 type, uint32 idx)
 {
        rid2->type    = type;
        rid2->rid     = rid;
-       rid2->rid_idx = 0;
+       rid2->rid_idx = idx;
 }
 
 /*******************************************************************
@@ -705,6 +680,7 @@ void make_dom_rid3(DOM_RID3 *rid3, uint32 rid, uint8 type)
        rid3->type1    = type;
        rid3->ptr_type = 0x1; /* non-zero, basically. */
        rid3->type2    = 0x1;
+       rid3->unk      = type;
 }
 
 /*******************************************************************
@@ -723,19 +699,9 @@ void smb_io_dom_rid3(char *desc,  DOM_RID3 *rid3, prs_struct *ps, int depth)
        prs_uint32("type1   ", ps, depth, &(rid3->type1   ));
        prs_uint32("ptr_type", ps, depth, &(rid3->ptr_type));
        prs_uint32("type2   ", ps, depth, &(rid3->type2   ));
+       prs_uint32("unk     ", ps, depth, &(rid3->unk     ));
 }
 
-/*******************************************************************
-creates a DOM_RID4 structure.
-********************************************************************/
-void make_dom_rid4(DOM_RID4 *rid4, uint16 unknown, uint16 attr, uint32 rid)
-{
-       rid4->unknown = unknown;
-       rid4->attr    = attr;
-       rid4->rid     = rid;
-}
-
-
 /*******************************************************************
 makes a DOM_CLNT_SRV structure.
 ********************************************************************/
@@ -796,8 +762,9 @@ static void smb_io_clnt_srv(char *desc,  DOM_CLNT_SRV *log, prs_struct *ps, int
 /*******************************************************************
 makes a DOM_LOG_INFO structure.
 ********************************************************************/
-void make_log_info(DOM_LOG_INFO *log, char *logon_srv, char *acct_name,
-               uint16 sec_chan, char *comp_name)
+void make_log_info(DOM_LOG_INFO *log,
+               const char *logon_srv, const char *acct_name,
+               uint16 sec_chan, const char *comp_name)
 {
        if (log == NULL) return;
 
@@ -1103,4 +1070,3 @@ void smb_io_unistr3(char *desc,  UNISTR3 *name, prs_struct *ps, int depth)
        prs_unistr3(True, "unistr", name, ps, depth);
 }
 
-