diff options
author | Andrew Tridgell <tridge@samba.org> | 1999-12-13 13:27:58 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 1999-12-13 13:27:58 +0000 |
commit | 3db52feb1f3b2c07ce0b06ad4a7099fa6efe3fc7 (patch) | |
tree | 866dd15416c3d8554bb207709f433a87ad0c012d /source3/rpc_parse | |
parent | f6276724bafdb6145c0c7b565172d80cb04516ea (diff) | |
download | samba-3db52feb1f3b2c07ce0b06ad4a7099fa6efe3fc7.tar.gz samba-3db52feb1f3b2c07ce0b06ad4a7099fa6efe3fc7.tar.bz2 samba-3db52feb1f3b2c07ce0b06ad4a7099fa6efe3fc7.zip |
first pass at updating head branch to be to be the same as the SAMBA_2_0 branch
(This used to be commit 453a822a76780063dff23526c35408866d0c0154)
Diffstat (limited to 'source3/rpc_parse')
-rw-r--r-- | source3/rpc_parse/parse_lsa.c | 1047 | ||||
-rw-r--r-- | source3/rpc_parse/parse_misc.c | 1347 | ||||
-rw-r--r-- | source3/rpc_parse/parse_net.c | 1858 | ||||
-rw-r--r-- | source3/rpc_parse/parse_prs.c | 787 | ||||
-rw-r--r-- | source3/rpc_parse/parse_reg.c | 1353 | ||||
-rw-r--r-- | source3/rpc_parse/parse_rpc.c | 1084 | ||||
-rw-r--r-- | source3/rpc_parse/parse_samr.c | 6542 | ||||
-rw-r--r-- | source3/rpc_parse/parse_sec.c | 704 | ||||
-rw-r--r-- | source3/rpc_parse/parse_srv.c | 2234 | ||||
-rw-r--r-- | source3/rpc_parse/parse_wks.c | 131 |
10 files changed, 6961 insertions, 10126 deletions
diff --git a/source3/rpc_parse/parse_lsa.c b/source3/rpc_parse/parse_lsa.c index d3b895dc1a..771e7c31d4 100644 --- a/source3/rpc_parse/parse_lsa.c +++ b/source3/rpc_parse/parse_lsa.c @@ -2,9 +2,9 @@ * Unix SMB/Netbios implementation. * Version 1.9. * RPC Pipe client / server routines - * Copyright (C) Andrew Tridgell 1992-1999, - * Copyright (C) Luke Kenneth Casson Leighton 1996-1999, - * Copyright (C) Paul Ashton 1997-1999. + * Copyright (C) Andrew Tridgell 1992-1997, + * Copyright (C) Luke Kenneth Casson Leighton 1996-1997, + * Copyright (C) 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 @@ -26,93 +26,109 @@ extern int DEBUGLEVEL; +static BOOL lsa_io_trans_names(char *desc, LSA_TRANS_NAME_ENUM *trn, prs_struct *ps, int depth); + /******************************************************************* -creates a LSA_TRANS_NAME structure. + Inits a LSA_TRANS_NAME structure. ********************************************************************/ -BOOL make_lsa_trans_name(LSA_TRANS_NAME *trn, UNISTR2 *uni_name, + +void init_lsa_trans_name(LSA_TRANS_NAME *trn, UNISTR2 *uni_name, uint32 sid_name_use, char *name, uint32 idx) { int len_name = strlen(name); + if(len_name == 0) + len_name = 1; + trn->sid_name_use = sid_name_use; - make_uni_hdr(&(trn->hdr_name), len_name); - make_unistr2(uni_name, name, len_name); + init_uni_hdr(&trn->hdr_name, len_name); + init_unistr2(uni_name, name, len_name); trn->domain_idx = idx; - - return True; } /******************************************************************* -reads or writes a LSA_TRANS_NAME structure. + Reads or writes a LSA_TRANS_NAME structure. ********************************************************************/ + static BOOL lsa_io_trans_name(char *desc, LSA_TRANS_NAME *trn, prs_struct *ps, int depth) { - if (trn == NULL) return False; + if (trn == NULL) + return False; prs_debug(ps, depth, desc, "lsa_io_trans_name"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("sid_name_use", ps, depth, &(trn->sid_name_use)); - smb_io_unihdr ("hdr_name", &(trn->hdr_name), ps, depth); - prs_uint32("domain_idx ", ps, depth, &(trn->domain_idx )); + if(!prs_uint32("sid_name_use", ps, depth, &trn->sid_name_use)) + return False; + if(!smb_io_unihdr ("hdr_name", &trn->hdr_name, ps, depth)) + return False; + if(!prs_uint32("domain_idx ", ps, depth, &trn->domain_idx)) + return False; return True; } /******************************************************************* -reads or writes a DOM_R_REF structure. + Reads or writes a DOM_R_REF structure. ********************************************************************/ -static BOOL lsa_io_dom_r_ref(char *desc, DOM_R_REF *r_r, prs_struct *ps, int depth) + +static BOOL lsa_io_dom_r_ref(char *desc, DOM_R_REF *r_r, prs_struct *ps, int depth) { - uint32 i, s, n; + int i, s, n; - prs_debug(ps, depth, desc, "smb_io_dom_r_ref"); + prs_debug(ps, depth, desc, "lsa_io_dom_r_ref"); depth++; - if (r_r == NULL) return False; + if (r_r == NULL) + return False; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("num_ref_doms_1", ps, depth, &(r_r->num_ref_doms_1)); /* num referenced domains? */ - prs_uint32("ptr_ref_dom ", ps, depth, &(r_r->ptr_ref_dom )); /* undocumented buffer pointer. */ - prs_uint32("max_entries ", ps, depth, &(r_r->max_entries )); /* 32 - max number of entries */ + if(!prs_uint32("num_ref_doms_1", ps, depth, &r_r->num_ref_doms_1)) /* num referenced domains? */ + return False; + if(!prs_uint32("ptr_ref_dom ", ps, depth, &r_r->ptr_ref_dom)) /* undocumented buffer pointer. */ + return False; + if(!prs_uint32("max_entries ", ps, depth, &r_r->max_entries)) /* 32 - max number of entries */ + return False; SMB_ASSERT_ARRAY(r_r->hdr_ref_dom, r_r->num_ref_doms_1); - if (r_r->ptr_ref_dom != 0) - { - prs_uint32("num_ref_doms_2", ps, depth, &(r_r->num_ref_doms_2)); /* 4 - num referenced domains? */ + if (r_r->ptr_ref_dom != 0) { + if(!prs_uint32("num_ref_doms_2", ps, depth, &r_r->num_ref_doms_2)) /* 4 - num referenced domains? */ + return False; + SMB_ASSERT_ARRAY(r_r->ref_dom, r_r->num_ref_doms_2); - for (i = 0; i < r_r->num_ref_doms_1; i++) - { + for (i = 0; i < r_r->num_ref_doms_1; i++) { fstring t; slprintf(t, sizeof(t) - 1, "dom_ref[%d] ", i); - smb_io_unihdr(t, &(r_r->hdr_ref_dom[i].hdr_dom_name), ps, depth); + if(!smb_io_unihdr(t, &r_r->hdr_ref_dom[i].hdr_dom_name, ps, depth)) + return False; slprintf(t, sizeof(t) - 1, "sid_ptr[%d] ", i); - prs_uint32(t, ps, depth, &(r_r->hdr_ref_dom[i].ptr_dom_sid)); + if(!prs_uint32(t, ps, depth, &r_r->hdr_ref_dom[i].ptr_dom_sid)) + return False; } - for (i = 0, n = 0, s = 0; i < r_r->num_ref_doms_2; i++) - { + for (i = 0, n = 0, s = 0; i < r_r->num_ref_doms_2; i++) { fstring t; - if (r_r->hdr_ref_dom[i].hdr_dom_name.buffer != 0) - { + if (r_r->hdr_ref_dom[i].hdr_dom_name.buffer != 0) { slprintf(t, sizeof(t) - 1, "dom_ref[%d] ", i); - smb_io_unistr2(t, &(r_r->ref_dom[n].uni_dom_name), True, ps, depth); /* domain name unicode string */ - prs_align(ps); + if(!smb_io_unistr2(t, &r_r->ref_dom[n].uni_dom_name, True, ps, depth)) /* domain name unicode string */ + return False; n++; } - if (r_r->hdr_ref_dom[i].ptr_dom_sid != 0) - { + if (r_r->hdr_ref_dom[i].ptr_dom_sid != 0) { slprintf(t, sizeof(t) - 1, "sid_ptr[%d] ", i); - smb_io_dom_sid2("", &(r_r->ref_dom[s].ref_dom), ps, depth); /* referenced domain SIDs */ + if(!smb_io_dom_sid2("", &r_r->ref_dom[s].ref_dom, ps, depth)) /* referenced domain SIDs */ + return False; s++; } } @@ -121,55 +137,58 @@ static BOOL lsa_io_dom_r_ref(char *desc, DOM_R_REF *r_r, prs_struct *ps, int de return True; } - /******************************************************************* -makes an LSA_SEC_QOS structure. + Inits an LSA_SEC_QOS structure. ********************************************************************/ -BOOL make_lsa_sec_qos(LSA_SEC_QOS *qos, uint16 imp_lev, uint8 ctxt, uint8 eff, + +void init_lsa_sec_qos(LSA_SEC_QOS *qos, uint16 imp_lev, uint8 ctxt, uint8 eff, uint32 unknown) { - if (qos == NULL) return False; - - DEBUG(5,("make_lsa_sec_qos\n")); + DEBUG(5,("init_lsa_sec_qos\n")); qos->len = 0x0c; /* length of quality of service block, in bytes */ qos->sec_imp_level = imp_lev; qos->sec_ctxt_mode = ctxt; qos->effective_only = eff; qos->unknown = unknown; - - return True; } /******************************************************************* -reads or writes an LSA_SEC_QOS structure. + Reads or writes an LSA_SEC_QOS structure. ********************************************************************/ + static BOOL lsa_io_sec_qos(char *desc, LSA_SEC_QOS *qos, prs_struct *ps, int depth) { - int start; + uint32 start; - if (qos == NULL) return False; + if (qos == NULL) + return False; prs_debug(ps, depth, desc, "lsa_io_obj_qos"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - start = ps->offset; + start = prs_offset(ps); /* these pointers had _better_ be zero, because we don't know what they point to! */ - prs_uint32("len ", ps, depth, &(qos->len )); /* 0x18 - length (in bytes) inc. the length field. */ - prs_uint16("sec_imp_level ", ps, depth, &(qos->sec_imp_level )); - prs_uint8 ("sec_ctxt_mode ", ps, depth, &(qos->sec_ctxt_mode )); - prs_uint8 ("effective_only", ps, depth, &(qos->effective_only)); - prs_uint32("unknown ", ps, depth, &(qos->unknown )); - - if (qos->len != ps->offset - start) - { + if(!prs_uint32("len ", ps, depth, &qos->len)) /* 0x18 - length (in bytes) inc. the length field. */ + return False; + if(!prs_uint16("sec_imp_level ", ps, depth, &qos->sec_imp_level )) + return False; + if(!prs_uint8 ("sec_ctxt_mode ", ps, depth, &qos->sec_ctxt_mode )) + return False; + if(!prs_uint8 ("effective_only", ps, depth, &qos->effective_only)) + return False; + if(!prs_uint32("unknown ", ps, depth, &qos->unknown)) + return False; + + if (qos->len != prs_offset(ps) - start) { DEBUG(3,("lsa_io_sec_qos: length %x does not match size %x\n", - qos->len, ps->offset - start)); + qos->len, prs_offset(ps) - start)); } return True; @@ -177,12 +196,11 @@ static BOOL lsa_io_sec_qos(char *desc, LSA_SEC_QOS *qos, prs_struct *ps, int de /******************************************************************* -makes an LSA_OBJ_ATTR structure. + Inits an LSA_OBJ_ATTR structure. ********************************************************************/ -BOOL make_lsa_obj_attr(LSA_OBJ_ATTR *attr, uint32 attributes, LSA_SEC_QOS *qos) -{ - if (attr == NULL) return False; +void init_lsa_obj_attr(LSA_OBJ_ATTR *attr, uint32 attributes, LSA_SEC_QOS *qos) +{ DEBUG(5,("make_lsa_obj_attr\n")); attr->len = 0x18; /* length of object attribute block, in bytes */ @@ -191,55 +209,58 @@ BOOL make_lsa_obj_attr(LSA_OBJ_ATTR *attr, uint32 attributes, LSA_SEC_QOS *qos) attr->attributes = attributes; attr->ptr_sec_desc = 0; - if (qos != NULL) - { + if (qos != NULL) { attr->ptr_sec_qos = 1; attr->sec_qos = qos; - } - else - { + } else { attr->ptr_sec_qos = 0; attr->sec_qos = NULL; } - - return True; } /******************************************************************* -reads or writes an LSA_OBJ_ATTR structure. + Reads or writes an LSA_OBJ_ATTR structure. ********************************************************************/ -static BOOL lsa_io_obj_attr(char *desc, LSA_OBJ_ATTR *attr, prs_struct *ps, int depth) + +static BOOL lsa_io_obj_attr(char *desc, LSA_OBJ_ATTR *attr, prs_struct *ps, int depth) { - int start; + uint32 start; - if (attr == NULL) return False; + if (attr == NULL) + return False; prs_debug(ps, depth, desc, "lsa_io_obj_attr"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - start = ps->offset; + start = prs_offset(ps); /* these pointers had _better_ be zero, because we don't know what they point to! */ - prs_uint32("len ", ps, depth, &(attr->len )); /* 0x18 - length (in bytes) inc. the length field. */ - prs_uint32("ptr_root_dir", ps, depth, &(attr->ptr_root_dir)); /* 0 - root directory (pointer) */ - prs_uint32("ptr_obj_name", ps, depth, &(attr->ptr_obj_name)); /* 0 - object name (pointer) */ - prs_uint32("attributes ", ps, depth, &(attr->attributes )); /* 0 - attributes (undocumented) */ - prs_uint32("ptr_sec_desc", ps, depth, &(attr->ptr_sec_desc)); /* 0 - security descriptior (pointer) */ - prs_uint32("ptr_sec_qos ", ps, depth, &(attr->ptr_sec_qos )); /* security quality of service (pointer) */ - - if (attr->len != ps->offset - start) - { + if(!prs_uint32("len ", ps, depth, &attr->len)) /* 0x18 - length (in bytes) inc. the length field. */ + return False; + if(!prs_uint32("ptr_root_dir", ps, depth, &attr->ptr_root_dir)) /* 0 - root directory (pointer) */ + return False; + if(!prs_uint32("ptr_obj_name", ps, depth, &attr->ptr_obj_name)) /* 0 - object name (pointer) */ + return False; + if(!prs_uint32("attributes ", ps, depth, &attr->attributes)) /* 0 - attributes (undocumented) */ + return False; + if(!prs_uint32("ptr_sec_desc", ps, depth, &attr->ptr_sec_desc)) /* 0 - security descriptior (pointer) */ + return False; + if(!prs_uint32("ptr_sec_qos ", ps, depth, &attr->ptr_sec_qos )) /* security quality of service (pointer) */ + return False; + + if (attr->len != prs_offset(ps) - start) { DEBUG(3,("lsa_io_obj_attr: length %x does not match size %x\n", - attr->len, ps->offset - start)); + attr->len, prs_offset(ps) - start)); } - if (attr->ptr_sec_qos != 0 && attr->sec_qos != NULL) - { - lsa_io_sec_qos("sec_qos", attr->sec_qos, ps, depth); + if (attr->ptr_sec_qos != 0 && attr->sec_qos != NULL) { + if(!lsa_io_sec_qos("sec_qos", attr->sec_qos, ps, depth)) + return False; } return True; @@ -247,688 +268,515 @@ static BOOL lsa_io_obj_attr(char *desc, LSA_OBJ_ATTR *attr, prs_struct *ps, int /******************************************************************* -makes an LSA_Q_OPEN_POL structure. + Inits an LSA_Q_OPEN_POL structure. ********************************************************************/ -BOOL make_q_open_pol(LSA_Q_OPEN_POL *r_q, uint16 system_name, + +void init_q_open_pol(LSA_Q_OPEN_POL *r_q, uint16 system_name, uint32 attributes, uint32 desired_access, LSA_SEC_QOS *qos) { - if (r_q == NULL) return False; - DEBUG(5,("make_open_pol: attr:%d da:%d\n", attributes, desired_access)); r_q->ptr = 1; /* undocumented pointer */ if (qos == NULL) - { r_q->des_access = desired_access; - } r_q->system_name = system_name; - make_lsa_obj_attr(&(r_q->attr ), attributes, qos); - - return True; + init_lsa_obj_attr(&r_q->attr, attributes, qos); } /******************************************************************* -reads or writes an LSA_Q_OPEN_POL structure. + Reads or writes an LSA_Q_OPEN_POL structure. ********************************************************************/ -BOOL lsa_io_q_open_pol(char *desc, LSA_Q_OPEN_POL *r_q, prs_struct *ps, int depth) + +BOOL lsa_io_q_open_pol(char *desc, LSA_Q_OPEN_POL *r_q, prs_struct *ps, int depth) { - if (r_q == NULL) return False; + if (r_q == NULL) + return False; prs_debug(ps, depth, desc, "lsa_io_q_open_pol"); depth++; - prs_uint32("ptr ", ps, depth, &(r_q->ptr )); - prs_uint16("system_name", ps, depth, &(r_q->system_name )); - prs_align ( ps ); + if(!prs_uint32("ptr ", ps, depth, &r_q->ptr)) + return False; + if(!prs_uint16("system_name", ps, depth, &r_q->system_name)) + return False; + if(!prs_align( ps )) + return False; - lsa_io_obj_attr("", &(r_q->attr ), ps, depth); + if(!lsa_io_obj_attr("", &r_q->attr, ps, depth)) + return False; - if (r_q->attr.ptr_sec_qos == 0) - { - prs_uint32("des_access", ps, depth, &(r_q->des_access)); + if (r_q->attr.ptr_sec_qos == 0) { + if(!prs_uint32("des_access", ps, depth, &r_q->des_access)) + return False; } return True; } /******************************************************************* -reads or writes an LSA_R_OPEN_POL structure. + Reads or writes an LSA_R_OPEN_POL structure. ********************************************************************/ -BOOL lsa_io_r_open_pol(char *desc, LSA_R_OPEN_POL *r_p, prs_struct *ps, int depth) + +BOOL lsa_io_r_open_pol(char *desc, LSA_R_OPEN_POL *r_p, prs_struct *ps, int depth) { - if (r_p == NULL) return False; + if (r_p == NULL) + return False; prs_debug(ps, depth, desc, "lsa_io_r_open_pol"); depth++; - smb_io_pol_hnd("", &(r_p->pol), ps, depth); + if(!smb_io_pol_hnd("", &r_p->pol, ps, depth)) + return False; - prs_uint32("status", ps, depth, &(r_p->status)); + if(!prs_uint32("status", ps, depth, &r_p->status)) + return False; return True; } /******************************************************************* -makes an LSA_Q_OPEN_POL2 structure. + Inits an LSA_Q_OPEN_POL2 structure. ********************************************************************/ -BOOL make_q_open_pol2(LSA_Q_OPEN_POL2 *r_q, const char *server_name, + +void init_q_open_pol2(LSA_Q_OPEN_POL2 *r_q, char *server_name, uint32 attributes, uint32 desired_access, LSA_SEC_QOS *qos) { - if (r_q == NULL) return False; - DEBUG(5,("make_open_pol2: attr:%d da:%d\n", attributes, desired_access)); r_q->ptr = 1; /* undocumented pointer */ if (qos == NULL) - { r_q->des_access = desired_access; - } - make_unistr2 (&(r_q->uni_server_name), server_name, strlen(server_name)); - make_lsa_obj_attr(&(r_q->attr ), attributes, qos); - - return True; + init_unistr2(&r_q->uni_server_name, server_name, strlen(server_name)); + init_lsa_obj_attr(&r_q->attr, attributes, qos); } /******************************************************************* -reads or writes an LSA_Q_OPEN_POL2 structure. + Reads or writes an LSA_Q_OPEN_POL2 structure. ********************************************************************/ -BOOL lsa_io_q_open_pol2(char *desc, LSA_Q_OPEN_POL2 *r_q, prs_struct *ps, int depth) + +BOOL lsa_io_q_open_pol2(char *desc, LSA_Q_OPEN_POL2 *r_q, prs_struct *ps, int depth) { - if (r_q == NULL) return False; + if (r_q == NULL) + return False; prs_debug(ps, depth, desc, "lsa_io_q_open_pol2"); depth++; - prs_uint32("ptr ", ps, depth, &(r_q->ptr )); + if(!prs_uint32("ptr ", ps, depth, &r_q->ptr)) + return False; - smb_io_unistr2 ("", &(r_q->uni_server_name), r_q->ptr, ps, depth); - lsa_io_obj_attr("", &(r_q->attr ), ps, depth); + if(!smb_io_unistr2 ("", &r_q->uni_server_name, r_q->ptr, ps, depth)) + return False; + if(!lsa_io_obj_attr("", &r_q->attr, ps, depth)) + return False; - if (r_q->attr.ptr_sec_qos == 0) - { - prs_uint32("des_access", ps, depth, &(r_q->des_access)); + if (r_q->attr.ptr_sec_qos == 0) { + if(!prs_uint32("des_access", ps, depth, &r_q->des_access)) + return False; } return True; } /******************************************************************* -reads or writes an LSA_R_OPEN_POL2 structure. + Reads or writes an LSA_R_OPEN_POL2 structure. ********************************************************************/ -BOOL lsa_io_r_open_pol2(char *desc, LSA_R_OPEN_POL2 *r_p, prs_struct *ps, int depth) + +BOOL lsa_io_r_open_pol2(char *desc, LSA_R_OPEN_POL2 *r_p, prs_struct *ps, int depth) { - if (r_p == NULL) return False; + if (r_p == NULL) + return False; prs_debug(ps, depth, desc, "lsa_io_r_open_pol2"); depth++; - smb_io_pol_hnd("", &(r_p->pol), ps, depth); + if(!smb_io_pol_hnd("", &r_p->pol, ps, depth)) + return False; - prs_uint32("status", ps, depth, &(r_p->status)); - - return True; + if(!prs_uint32("status", ps, depth, &r_p->status)) + return False; return True; } /******************************************************************* -makes an LSA_Q_QUERY_INFO structure. + Inits an LSA_Q_QUERY_INFO structure. ********************************************************************/ -BOOL make_q_query(LSA_Q_QUERY_INFO *q_q, POLICY_HND *hnd, uint16 info_class) -{ - if (q_q == NULL || hnd == NULL) return False; +void init_q_query(LSA_Q_QUERY_INFO *q_q, POLICY_HND *hnd, uint16 info_class) +{ DEBUG(5,("make_q_query\n")); - memcpy(&(q_q->pol), hnd, sizeof(q_q->pol)); + memcpy(&q_q->pol, hnd, sizeof(q_q->pol)); q_q->info_class = info_class; - - return True; } /******************************************************************* -reads or writes an LSA_Q_QUERY_INFO structure. + Reads or writes an LSA_Q_QUERY_INFO structure. ********************************************************************/ -BOOL lsa_io_q_query(char *desc, LSA_Q_QUERY_INFO *q_q, prs_struct *ps, int depth) -{ - if (q_q == NULL) return False; - - prs_debug(ps, depth, desc, "lsa_io_q_query"); - depth++; - - smb_io_pol_hnd("", &(q_q->pol), ps, depth); - - prs_uint16("info_class", ps, depth, &(q_q->info_class)); - - return True; -} - -/******************************************************************* -makes an LSA_Q_OPEN_SECRET structure. -********************************************************************/ -BOOL make_q_open_secret(LSA_Q_OPEN_SECRET *q_o, const POLICY_HND *pol_hnd, - const char *secret_name, uint32 desired_access) -{ - int len = strlen(secret_name); - - if (q_o == NULL) return False; - - DEBUG(5,("make_q_open_secret")); - - memcpy(&(q_o->pol), pol_hnd, sizeof(q_o->pol)); - - make_uni_hdr(&(q_o->hdr_secret), len); - make_unistr2(&(q_o->uni_secret), secret_name, len); - - q_o->des_access = desired_access; - - return True; -} - -/******************************************************************* -reads or writes an LSA_Q_OPEN_SECRET structure. -********************************************************************/ -BOOL lsa_io_q_open_secret(char *desc, LSA_Q_OPEN_SECRET *q_o, prs_struct *ps, int depth) -{ - if (q_o == NULL) return False; - - prs_debug(ps, depth, desc, "lsa_io_q_open_secret"); - depth++; - - smb_io_pol_hnd("", &(q_o->pol), ps, depth); - - prs_align(ps); - smb_io_unihdr ("", &(q_o->hdr_secret), ps, depth); - smb_io_unistr2("", &(q_o->uni_secret), 1, ps, depth); - - prs_align(ps); - prs_uint32("des_access", ps, depth, &(q_o->des_access)); - - return True; -} - -/******************************************************************* -reads or writes an LSA_R_OPEN_SECRET structure. -********************************************************************/ -BOOL lsa_io_r_open_secret(char *desc, LSA_R_OPEN_SECRET *r_o, prs_struct *ps, int depth) -{ - if (r_o == NULL) return False; - - prs_debug(ps, depth, desc, "lsa_io_r_open_secret"); - depth++; - - smb_io_pol_hnd("", &(r_o->pol), ps, depth); - - prs_uint32("status", ps, depth, &(r_o->status)); - - return True; -} - -/******************************************************************* -reads or writes an LSA_SECRET_VALUE structure. -********************************************************************/ -BOOL lsa_io_secret_value(char *desc, LSA_SECRET_VALUE *value, prs_struct *ps, int depth) -{ - if (value == NULL) return False; - - prs_debug(ps, depth, desc, "lsa_io_secret_value"); - depth++; - - prs_align(ps); - prs_uint32("ptr_secret", ps, depth, &(value->ptr_secret)); - - if (value->ptr_secret != 0) - { - smb_io_strhdr2("hdr_secret", &(value->hdr_secret), ps, depth); - smb_io_string2("secret" , &(value->enc_secret), - value->hdr_secret.buffer, ps, depth); - } - - return True; -} - -/******************************************************************* -reads or writes an LSA_SECRET_INFO structure. -********************************************************************/ -BOOL lsa_io_secret_info(char *desc, LSA_SECRET_INFO *info, prs_struct *ps, int depth) -{ - if (info == NULL) return False; - - prs_debug(ps, depth, desc, "lsa_io_secret_info"); - depth++; - - prs_align(ps); - prs_uint32("ptr_value ", ps, depth, &(info->ptr_value )); - - if (info->ptr_value != 0) - { - lsa_io_secret_value("", &(info->value), ps, depth); - } - - prs_align(ps); - prs_uint32("ptr_update", ps, depth, &(info->ptr_update)); - - if (info->ptr_update != 0) - { - ps->align = 8; - prs_align(ps); - ps->align = 4; - - smb_io_time("last_update", &(info->last_update), ps, depth); - } - - return True; -} - -/******************************************************************* -makes an LSA_Q_QUERY_SECRET structure. -********************************************************************/ -BOOL make_q_query_secret(LSA_Q_QUERY_SECRET *q_q, POLICY_HND *pol) -{ - if (q_q == NULL) return False; - - DEBUG(5,("make_q_query_secret\n")); - - memcpy(&(q_q->pol), pol, sizeof(q_q->pol)); - - /* Want secret */ - q_q->info.ptr_value = 1; - q_q->info.value.ptr_secret = 0; - - /* Want last change time */ - q_q->info.ptr_update = 1; - - /* Don't care about old info */ - q_q->oldinfo.ptr_value = 0; - q_q->oldinfo.ptr_update = 0; - - return True; -} - -/******************************************************************* -reads or writes an LSA_Q_QUERY_SECRET structure. -********************************************************************/ -BOOL lsa_io_q_query_secret(char *desc, LSA_Q_QUERY_SECRET *q_q, prs_struct *ps, int depth) -{ - if (q_q == NULL) return False; - prs_debug(ps, depth, desc, "lsa_io_q_query_secret"); - depth++; - - smb_io_pol_hnd("", &(q_q->pol), ps, depth); - - lsa_io_secret_info("", &(q_q->info ), ps, depth); - lsa_io_secret_info("", &(q_q->oldinfo), ps, depth); - - return True; -} - -/******************************************************************* -reads or writes an LSA_Q_QUERY_SECRET structure. -********************************************************************/ -BOOL lsa_io_r_query_secret(char *desc, LSA_R_QUERY_SECRET *r_q, prs_struct *ps, int depth) +BOOL lsa_io_q_query(char *desc, LSA_Q_QUERY_INFO *q_q, prs_struct *ps, int depth) { - if (r_q == NULL) return False; + if (q_q == NULL) + return False; - prs_debug(ps, depth, desc, "lsa_io_r_query_secret"); + prs_debug(ps, depth, desc, "lsa_io_q_query"); depth++; - lsa_io_secret_info("", &(r_q->info ), ps, depth); - lsa_io_secret_info("", &(r_q->oldinfo), ps, depth); + if(!smb_io_pol_hnd("", &q_q->pol, ps, depth)) + return False; - prs_align(ps); - prs_uint32("status", ps, depth, &(r_q->status)); + if(!prs_uint16("info_class", ps, depth, &q_q->info_class)) + return False; return True; } /******************************************************************* -makes an LSA_Q_ENUM_TRUST_DOM structure. + Reads or writes an LSA_Q_ENUM_TRUST_DOM structure. ********************************************************************/ -BOOL make_q_enum_trust_dom(LSA_Q_ENUM_TRUST_DOM *q_e, - POLICY_HND *pol, - uint32 enum_context, uint32 preferred_len) -{ - if (q_e == NULL) return False; - - DEBUG(5,("make_q_enum_trust_dom\n")); - - memcpy(&(q_e->pol), pol, sizeof(q_e->pol)); - q_e->enum_context = enum_context; - q_e->preferred_len = preferred_len; - return True; -} - -/******************************************************************* -reads or writes an LSA_Q_ENUM_TRUST_DOM structure. -********************************************************************/ -BOOL lsa_io_q_enum_trust_dom(char *desc, LSA_Q_ENUM_TRUST_DOM *q_e, prs_struct *ps, int depth) +BOOL lsa_io_q_enum_trust_dom(char *desc, LSA_Q_ENUM_TRUST_DOM *q_e, prs_struct *ps, int depth) { - if (q_e == NULL) return False; + if (q_e == NULL) + return False; prs_debug(ps, depth, desc, "lsa_io_q_enum_trust_dom"); depth++; - smb_io_pol_hnd("", &(q_e->pol), ps, depth); + if(!smb_io_pol_hnd("", &q_e->pol, ps, depth)) + return False; - prs_uint32("enum_context ", ps, depth, &(q_e->enum_context )); - prs_uint32("preferred_len", ps, depth, &(q_e->preferred_len)); + if(!prs_uint32("enum_context ", ps, depth, &q_e->enum_context)) + return False; + if(!prs_uint32("preferred_len", ps, depth, &q_e->preferred_len)) + return False; return True; } /******************************************************************* -makes an LSA_R_ENUM_TRUST_DOM structure. + Inits an LSA_R_ENUM_TRUST_DOM structure. ********************************************************************/ -BOOL make_r_enum_trust_dom(LSA_R_ENUM_TRUST_DOM *r_e, - int32 enum_context, - char *domain_name, DOM_SID *domain_sid, - uint32 status) -{ - if (r_e == NULL) return False; +void init_r_enum_trust_dom(LSA_R_ENUM_TRUST_DOM *r_e, + uint32 enum_context, char *domain_name, DOM_SID *domain_sid, + uint32 status) +{ DEBUG(5,("make_r_enum_trust_dom\n")); r_e->enum_context = enum_context; - if (status == 0) - { + if (status == 0) { int len_domain_name = strlen(domain_name); r_e->num_domains = 1; r_e->ptr_enum_domains = 1; r_e->num_domains2 = 1; - make_uni_hdr2(&(r_e->hdr_domain_name[0]), len_domain_name); - make_unistr2 (&(r_e->uni_domain_name[0]), domain_name, len_domain_name); - make_dom_sid2(&(r_e->domain_sid[0]), domain_sid); - } - else - { + init_uni_hdr2(&r_e->hdr_domain_name, len_domain_name); + init_unistr2 (&r_e->uni_domain_name, domain_name, len_domain_name); + init_dom_sid2(&r_e->other_domain_sid, domain_sid); + } else { r_e->num_domains = 0; r_e->ptr_enum_domains = 0; } r_e->status = status; - - return True; } /******************************************************************* -reads or writes an LSA_R_ENUM_TRUST_DOM structure. + Reads or writes an LSA_R_ENUM_TRUST_DOM structure. ********************************************************************/ -BOOL lsa_io_r_enum_trust_dom(char *desc, LSA_R_ENUM_TRUST_DOM *r_e, prs_struct *ps, int depth) + +BOOL lsa_io_r_enum_trust_dom(char *desc, LSA_R_ENUM_TRUST_DOM *r_e, prs_struct *ps, int depth) { - if (r_e == NULL) return False; + if (r_e == NULL) + return False; prs_debug(ps, depth, desc, "lsa_io_r_enum_trust_dom"); depth++; - prs_uint32("enum_context ", ps, depth, &(r_e->enum_context )); - prs_uint32("num_domains ", ps, depth, &(r_e->num_domains )); - prs_uint32("ptr_enum_domains", ps, depth, &(r_e->ptr_enum_domains)); - - if (r_e->ptr_enum_domains != 0) - { - uint32 i; - prs_uint32("num_domains2", ps, depth, &(r_e->num_domains2)); - - for (i = 0; i < r_e->num_domains2; i++) - { + if(!prs_uint32("enum_context ", ps, depth, &r_e->enum_context)) + return False; + if(!prs_uint32("num_domains ", ps, depth, &r_e->num_domains)) + return False; + if(!prs_uint32("ptr_enum_domains", ps, depth, &r_e->ptr_enum_domains)) + return False; - smb_io_unihdr2 ("", &(r_e->hdr_domain_name[i]), ps, depth); - } - - for (i = 0; i < r_e->num_domains2; i++) - { - smb_io_unistr2 ("", &(r_e->uni_domain_name[i] ), r_e->hdr_domain_name[i].buffer, ps, depth); - prs_align(ps); - smb_io_dom_sid2("", &(r_e->domain_sid[i]), ps, depth); - } + if (r_e->ptr_enum_domains != 0) { + if(!prs_uint32("num_domains2", ps, depth, &r_e->num_domains2)) + return False; + if(!smb_io_unihdr2 ("", &r_e->hdr_domain_name, ps, depth)) + return False; + if(!smb_io_unistr2 ("", &r_e->uni_domain_name, r_e->hdr_domain_name.buffer, ps, depth)) + return False; + if(!smb_io_dom_sid2("", &r_e->other_domain_sid, ps, depth)) + return False; } - prs_uint32("status", ps, depth, &(r_e->status)); + if(!prs_uint32("status", ps, depth, &r_e->status)) + return False; return True; } /******************************************************************* -reads or writes an LSA_Q_QUERY_INFO structure. + Reads or writes an LSA_Q_QUERY_INFO structure. ********************************************************************/ -BOOL lsa_io_r_query(char *desc, LSA_R_QUERY_INFO *r_q, prs_struct *ps, int depth) + +BOOL lsa_io_r_query(char *desc, LSA_R_QUERY_INFO *r_q, prs_struct *ps, int depth) { - if (r_q == NULL) return False; + if (r_q == NULL) + return False; prs_debug(ps, depth, desc, "lsa_io_r_query"); depth++; - prs_uint32("undoc_buffer", ps, depth, &(r_q->undoc_buffer)); + if(!prs_uint32("undoc_buffer", ps, depth, &r_q->undoc_buffer)) + return False; - if (r_q->undoc_buffer != 0) - { - prs_uint16("info_class", ps, depth, &(r_q->info_class)); + if (r_q->undoc_buffer != 0) { + if(!prs_uint16("info_class", ps, depth, &r_q->info_class)) + return False; - switch (r_q->info_class) - { - case 3: - { - smb_io_dom_query_3("", &(r_q->dom.id3), ps, depth); - break; - } - case 5: - { - smb_io_dom_query_5("", &(r_q->dom.id3), ps, depth); - break; - } - default: - { - /* PANIC! */ - break; - } + switch (r_q->info_class) { + case 3: + if(!smb_io_dom_query_3("", &r_q->dom.id3, ps, depth)) + return False; + break; + case 5: + if(!smb_io_dom_query_5("", &r_q->dom.id3, ps, depth)) + return False; + break; + default: + /* PANIC! */ + break; } } - prs_uint32("status", ps, depth, &(r_q->status)); + if(!prs_uint32("status", ps, depth, &r_q->status)) + return False; return True; } /******************************************************************* -makes a LSA_SID_ENUM structure. + Inits a LSA_SID_ENUM structure. ********************************************************************/ -BOOL make_lsa_sid_enum(LSA_SID_ENUM *sen, uint32 num_entries, DOM_SID **sids) + +void init_lsa_sid_enum(LSA_SID_ENUM *sen, int num_entries, DOM_SID **sids) { - uint32 i, i2; - if (sen == NULL || sids == NULL) return False; + int i, i2; DEBUG(5,("make_lsa_sid_enum\n")); sen->num_entries = num_entries; - sen->ptr_sid_enum = num_entries != 0 ? 1 : 0; + sen->ptr_sid_enum = (num_entries != 0) ? 1 : 0; sen->num_entries2 = num_entries; SMB_ASSERT_ARRAY(sen->sid, sen->num_entries); - for (i = 0, i2 = 0; i < num_entries; i++) - { - if (sids[i] != NULL) - { + for (i = 0, i2 = 0; i < num_entries; i++) { + if (sids[i] != NULL) { sen->ptr_sid[i] = 1; - make_dom_sid2(&(sen->sid[i2]), sids[i]); + init_dom_sid2(&sen->sid[i2], sids[i]); i2++; - } - else - { + } else { sen->ptr_sid[i] = 0; } } - - return True; } /******************************************************************* -reads or writes a LSA_SID_ENUM structure. + Reads or writes a LSA_SID_ENUM structure. ********************************************************************/ + static BOOL lsa_io_sid_enum(char *desc, LSA_SID_ENUM *sen, prs_struct *ps, int depth) { - uint32 i; + int i; - if (sen == NULL) return False; + if (sen == NULL) + return False; prs_debug(ps, depth, desc, "lsa_io_sid_enum"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("num_entries ", ps, depth, &(sen->num_entries)); - prs_uint32("ptr_sid_enum", ps, depth, &(sen->ptr_sid_enum)); - prs_uint32("num_entries2", ps, depth, &(sen->num_entries2)); + if(!prs_uint32("num_entries ", ps, depth, &sen->num_entries)) + return False; + if(!prs_uint32("ptr_sid_enum", ps, depth, &sen->ptr_sid_enum)) + return False; + if(!prs_uint32("num_entries2", ps, depth, &sen->num_entries2)) + return False; SMB_ASSERT_ARRAY(sen->ptr_sid, sen->num_entries); - for (i = 0; i < sen->num_entries; i++) - { + for (i = 0; i < sen->num_entries; i++) { fstring temp; slprintf(temp, sizeof(temp) - 1, "ptr_sid[%d]", i); - prs_uint32(temp, ps, depth, &(sen->ptr_sid[i])); /* domain SID pointers to be looked up. */ + if(!prs_uint32(temp, ps, depth, &sen->ptr_sid[i])) /* domain SID pointers to be looked up. */ + return False; } SMB_ASSERT_ARRAY(sen->sid, sen->num_entries); - for (i = 0; i < sen->num_entries; i++) - { + for (i = 0; i < sen->num_entries; i++) { fstring temp; slprintf(temp, sizeof(temp) - 1, "sid[%d]", i); - smb_io_dom_sid2(temp, &(sen->sid[i]), ps, depth); /* domain SIDs to be looked up. */ + if(!smb_io_dom_sid2(temp, &sen->sid[i], ps, depth)) /* domain SIDs to be looked up. */ + return False; } return True; } /******************************************************************* -reads or writes a structure. + Inits an LSA_R_ENUM_TRUST_DOM structure. ********************************************************************/ -static BOOL lsa_io_trans_names(char *desc, LSA_TRANS_NAME_ENUM *trn, - prs_struct *ps, int depth) + +void init_q_lookup_sids(LSA_Q_LOOKUP_SIDS *q_l, POLICY_HND *hnd, + int num_sids, DOM_SID **sids, + uint16 level) { - uint32 i; + DEBUG(5,("make_r_enum_trust_dom\n")); - if (trn == NULL) return False; + memcpy(&q_l->pol, hnd, sizeof(q_l->pol)); + init_lsa_sid_enum(&q_l->sids, num_sids, sids); - prs_debug(ps, depth, desc, "lsa_io_trans_names"); - depth++; + q_l->names.num_entries = 0; + q_l->names.ptr_trans_names = 0; + q_l->names.num_entries2 = 0; - prs_align(ps); - - prs_uint32("num_entries ", ps, depth, &(trn->num_entries)); - prs_uint32("ptr_trans_names", ps, depth, &(trn->ptr_trans_names)); + q_l->level.value = level; +} - if (trn->ptr_trans_names != 0) - { - prs_uint32("num_entries2 ", ps, depth, &(trn->num_entries2)); - SMB_ASSERT_ARRAY(trn->name, trn->num_entries); +/******************************************************************* + Reads or writes a LSA_Q_LOOKUP_SIDS structure. +********************************************************************/ - for (i = 0; i < trn->num_entries2; i++) - { - fstring t; - slprintf(t, sizeof(t) - 1, "name[%d] ", i); +BOOL lsa_io_q_lookup_sids(char *desc, LSA_Q_LOOKUP_SIDS *q_s, prs_struct *ps, int depth) +{ + if (q_s == NULL) + return False; - lsa_io_trans_name(t, &(trn->name[i]), ps, depth); /* translated name */ + prs_debug(ps, depth, desc, "lsa_io_q_lookup_sids"); + depth++; - } - for (i = 0; i < trn->num_entries2; i++) - { - fstring t; - slprintf(t, sizeof(t) - 1, "name[%d] ", i); + if(!prs_align(ps)) + return False; + + if(!smb_io_pol_hnd("pol_hnd", &q_s->pol, ps, depth)) /* policy handle */ + return False; + if(!lsa_io_sid_enum("sids ", &q_s->sids, ps, depth)) /* sids to be looked up */ + return False; + if(!lsa_io_trans_names("names ", &q_s->names, ps, depth)) /* translated names */ + return False; + if(!smb_io_lookup_level("switch ", &q_s->level, ps, depth)) /* lookup level */ + return False; - smb_io_unistr2(t, &(trn->uni_name[i]), trn->name[i].hdr_name.buffer, ps, depth); - prs_align(ps); - } - } + if(!prs_uint32("mapped_count", ps, depth, &q_s->mapped_count)) + return False; return True; } /******************************************************************* -makes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL make_q_lookup_sids(LSA_Q_LOOKUP_SIDS *q_l, POLICY_HND *hnd, - int num_sids, DOM_SID **sids, - uint16 level) + +static BOOL lsa_io_trans_names(char *desc, LSA_TRANS_NAME_ENUM *trn, + prs_struct *ps, int depth) { - if (q_l == NULL) return False; + int i; - DEBUG(5,("make_q_lookup_sids\n")); + if (trn == NULL) + return False; - memcpy(&(q_l->pol), hnd, sizeof(q_l->pol)); - make_lsa_sid_enum(&(q_l->sids), num_sids, sids); + prs_debug(ps, depth, desc, "lsa_io_trans_names"); + depth++; - q_l->names.ptr_trans_names = 0; - q_l->names.num_entries = 0; + if(!prs_align(ps)) + return False; + + if(!prs_uint32("num_entries ", ps, depth, &trn->num_entries)) + return False; + if(!prs_uint32("ptr_trans_names", ps, depth, &trn->ptr_trans_names)) + return False; - q_l->level.value = level; - - return True; -} + if (trn->ptr_trans_names != 0) { + if(!prs_uint32("num_entries2 ", ps, depth, &trn->num_entries2)) + return False; + SMB_ASSERT_ARRAY(trn->name, trn->num_entries); -/******************************************************************* -reads or writes a LSA_Q_LOOKUP_SIDS structure. -********************************************************************/ -BOOL lsa_io_q_lookup_sids(char *desc, LSA_Q_LOOKUP_SIDS *q_s, prs_struct *ps, int depth) -{ - if (q_s == NULL) return False; + for (i = 0; i < trn->num_entries2; i++) { + fstring t; + slprintf(t, sizeof(t) - 1, "name[%d] ", i); - prs_debug(ps, depth, desc, "lsa_io_q_lookup_sids"); - depth++; + if(!lsa_io_trans_name(t, &trn->name[i], ps, depth)) /* translated name */ + return False; + } - prs_align(ps); - - smb_io_pol_hnd ("pol_hnd", &(q_s->pol), ps, depth); /* policy handle */ - lsa_io_sid_enum ("sids ", &(q_s->sids ), ps, depth); /* sids to be looked up */ - lsa_io_trans_names ("names ", &(q_s->names ), ps, depth); /* translated names */ - smb_io_lookup_level("switch ", &(q_s->level ), ps, depth); /* lookup level */ + for (i = 0; i < trn->num_entries2; i++) { + fstring t; + slprintf(t, sizeof(t) - 1, "name[%d] ", i); - prs_uint32("mapped_count", ps, depth, &(q_s->mapped_count)); + if(!smb_io_unistr2(t, &trn->uni_name[i], trn->name[i].hdr_name.buffer, ps, depth)) + return False; + if(!prs_align(ps)) + return False; + } + } return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL lsa_io_r_lookup_sids(char *desc, LSA_R_LOOKUP_SIDS *r_s, prs_struct *ps, int depth) + +BOOL lsa_io_r_lookup_sids(char *desc, LSA_R_LOOKUP_SIDS *r_s, prs_struct *ps, int depth) { - if (r_s == NULL) return False; + if (r_s == NULL) + return False; prs_debug(ps, depth, desc, "lsa_io_r_lookup_sids"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr_dom_ref", ps, depth, &(r_s->ptr_dom_ref)); + if(!prs_uint32("ptr_dom_ref", ps, depth, &r_s->ptr_dom_ref)) + return False; + if (r_s->ptr_dom_ref != 0) - { - lsa_io_dom_r_ref ("dom_ref", r_s->dom_ref, ps, depth); /* domain reference info */ - } - lsa_io_trans_names("names ", r_s->names , ps, depth); /* translated names */ + if(!lsa_io_dom_r_ref ("dom_ref", r_s->dom_ref, ps, depth)) /* domain reference info */ + return False; + + if(!lsa_io_trans_names("names ", r_s->names, ps, depth)) /* translated names */ + return False; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("mapped_count", ps, depth, &(r_s->mapped_count)); + if(!prs_uint32("mapped_count", ps, depth, &r_s->mapped_count)) + return False; - prs_uint32("status ", ps, depth, &(r_s->status)); + if(!prs_uint32("status ", ps, depth, &r_s->status)) + return False; return True; } @@ -936,73 +784,81 @@ BOOL lsa_io_r_lookup_sids(char *desc, LSA_R_LOOKUP_SIDS *r_s, prs_struct *ps, i /******************************************************************* makes a structure. ********************************************************************/ -BOOL make_q_lookup_names(LSA_Q_LOOKUP_NAMES *q_l, POLICY_HND *hnd, - uint32 num_names, char **names) + +void init_q_lookup_names(LSA_Q_LOOKUP_NAMES *q_l, POLICY_HND *hnd, + int num_names, char **names) { - uint32 i; - if (q_l == NULL) return False; + int i; - DEBUG(5,("make_q_lookup_names\n")); + DEBUG(5,("init_q_lookup_names\n")); - memcpy(&(q_l->pol), hnd, sizeof(q_l->pol)); + memcpy(&q_l->pol, hnd, sizeof(q_l->pol)); - q_l->num_entries = num_names; - q_l->num_entries2 = num_names; + q_l->num_entries = num_names; + q_l->num_entries2 = num_names; SMB_ASSERT_ARRAY(q_l->uni_name, q_l->num_entries); - for (i = 0; i < num_names; i++) - { - const char* name = names[i]; + for (i = 0; i < num_names; i++) { + char* name = names[i]; int len = strlen(name); - make_uni_hdr(&q_l->hdr_name[i], len); - make_unistr2(&q_l->uni_name[i], name, len); + init_uni_hdr(&q_l->hdr_name[i], len); + init_unistr2(&q_l->uni_name[i], name, len); } q_l->num_trans_entries = 0; q_l->ptr_trans_sids = 0; q_l->lookup_level = 1; q_l->mapped_count = 0; - - return True; } /******************************************************************* reads or writes a structure. ********************************************************************/ -BOOL lsa_io_q_lookup_names(char *desc, LSA_Q_LOOKUP_NAMES *q_r, prs_struct *ps, int depth) + +BOOL lsa_io_q_lookup_names(char *desc, LSA_Q_LOOKUP_NAMES *q_r, prs_struct *ps, int depth) { - uint32 i; + int i; - if (q_r == NULL) return False; + if (q_r == NULL) + return False; prs_debug(ps, depth, desc, "lsa_io_q_lookup_names"); depth++; - prs_align(ps); - - smb_io_pol_hnd("", &(q_r->pol), ps, depth); /* policy handle */ + if(!prs_align(ps)) + return False; + + if(!smb_io_pol_hnd("", &q_r->pol, ps, depth)) /* policy handle */ + return False; - prs_uint32("num_entries ", ps, depth, &(q_r->num_entries)); - prs_uint32("num_entries2 ", ps, depth, &(q_r->num_entries2)); + if(!prs_uint32("num_entries ", ps, depth, &q_r->num_entries)) + return False; + if(!prs_uint32("num_entries2 ", ps, depth, &q_r->num_entries2)) + return False; SMB_ASSERT_ARRAY(q_r->uni_name, q_r->num_entries); - for (i = 0; i < q_r->num_entries; i++) - { - smb_io_unihdr("hdr_name", &(q_r->hdr_name[i]), ps, depth); /* pointer names */ + for (i = 0; i < q_r->num_entries; i++) { + if(!smb_io_unihdr("hdr_name", &q_r->hdr_name[i], ps, depth)) /* pointer names */ + return False; } - for (i = 0; i < q_r->num_entries; i++) - { - smb_io_unistr2("dom_name", &(q_r->uni_name[i]), q_r->hdr_name[i].buffer, ps, depth); /* names to be looked up */ - prs_align(ps); + for (i = 0; i < q_r->num_entries; i++) { + if(!smb_io_unistr2("dom_name", &q_r->uni_name[i], q_r->hdr_name[i].buffer, ps, depth)) /* names to be looked up */ + return False; + if(!prs_align(ps)) + return False; } - prs_uint32("num_trans_entries ", ps, depth, &(q_r->num_trans_entries)); - prs_uint32("ptr_trans_sids ", ps, depth, &(q_r->ptr_trans_sids)); - prs_uint32("lookup_level ", ps, depth, &(q_r->lookup_level )); - prs_uint32("mapped_count ", ps, depth, &(q_r->mapped_count )); + if(!prs_uint32("num_trans_entries ", ps, depth, &q_r->num_trans_entries)) + return False; + if(!prs_uint32("ptr_trans_sids ", ps, depth, &q_r->ptr_trans_sids)) + return False; + if(!prs_uint32("lookup_level ", ps, depth, &q_r->lookup_level)) + return False; + if(!prs_uint32("mapped_count ", ps, depth, &q_r->mapped_count)) + return False; return True; } @@ -1010,93 +866,102 @@ BOOL lsa_io_q_lookup_names(char *desc, LSA_Q_LOOKUP_NAMES *q_r, prs_struct *ps, /******************************************************************* reads or writes a structure. ********************************************************************/ -BOOL lsa_io_r_lookup_names(char *desc, LSA_R_LOOKUP_NAMES *r_r, prs_struct *ps, int depth) + +BOOL lsa_io_r_lookup_names(char *desc, LSA_R_LOOKUP_NAMES *r_r, prs_struct *ps, int depth) { - uint32 i; + int i; - if (r_r == NULL) return False; + if (r_r == NULL) + return False; prs_debug(ps, depth, desc, "lsa_io_r_lookup_names"); depth++; - prs_align(ps); - - prs_uint32("ptr_dom_ref", ps, depth, &(r_r->ptr_dom_ref)); + if(!prs_align(ps)) + return False; + + if(!prs_uint32("ptr_dom_ref", ps, depth, &r_r->ptr_dom_ref)) + return False; + if (r_r->ptr_dom_ref != 0) - { - lsa_io_dom_r_ref("", r_r->dom_ref, ps, depth); - } + if(!lsa_io_dom_r_ref("", r_r->dom_ref, ps, depth)) + return False; - prs_uint32("num_entries", ps, depth, &(r_r->num_entries)); - prs_uint32("ptr_entries", ps, depth, &(r_r->ptr_entries)); + if(!prs_uint32("num_entries", ps, depth, &r_r->num_entries)) + return False; + if(!prs_uint32("ptr_entries", ps, depth, &r_r->ptr_entries)) + return False; - if (r_r->ptr_entries != 0) - { - prs_uint32("num_entries2", ps, depth, &(r_r->num_entries2)); + if (r_r->ptr_entries != 0) { + if(!prs_uint32("num_entries2", ps, depth, &r_r->num_entries2)) + return False; - if (r_r->num_entries2 != r_r->num_entries) - { + if (r_r->num_entries2 != r_r->num_entries) { /* RPC fault */ return False; } for (i = 0; i < r_r->num_entries2; i++) - { - smb_io_dom_rid2("", &(r_r->dom_rid[i]), ps, depth); /* domain RIDs being looked up */ - } + if(!smb_io_dom_rid2("", &r_r->dom_rid[i], ps, depth)) /* domain RIDs being looked up */ + return False; } - prs_uint32("mapped_count", ps, depth, &(r_r->mapped_count)); + if(!prs_uint32("mapped_count", ps, depth, &r_r->mapped_count)) + return False; - prs_uint32("status ", ps, depth, &(r_r->status)); + if(!prs_uint32("status ", ps, depth, &r_r->status)) + return False; return True; } /******************************************************************* -makes an LSA_Q_CLOSE structure. + Inits an LSA_Q_CLOSE structure. ********************************************************************/ -BOOL make_lsa_q_close(LSA_Q_CLOSE *q_c, POLICY_HND *hnd) -{ - if (q_c == NULL || hnd == NULL) return False; +void init_lsa_q_close(LSA_Q_CLOSE *q_c, POLICY_HND *hnd) +{ DEBUG(5,("make_lsa_q_close\n")); - memcpy(&(q_c->pol), hnd, sizeof(q_c->pol)); - - return True; + memcpy(&q_c->pol, hnd, sizeof(q_c->pol)); } /******************************************************************* -reads or writes an LSA_Q_CLOSE structure. + Reads or writes an LSA_Q_CLOSE structure. ********************************************************************/ -BOOL lsa_io_q_close(char *desc, LSA_Q_CLOSE *q_c, prs_struct *ps, int depth) + +BOOL lsa_io_q_close(char *desc, LSA_Q_CLOSE *q_c, prs_struct *ps, int depth) { - if (q_c == NULL) return False; + if (q_c == NULL) + return False; prs_debug(ps, depth, desc, "lsa_io_q_close"); depth++; - smb_io_pol_hnd("", &(q_c->pol), ps, depth); + if(!smb_io_pol_hnd("", &q_c->pol, ps, depth)) + return False; return True; } /******************************************************************* -reads or writes an LSA_R_CLOSE structure. + Reads or writes an LSA_R_CLOSE structure. ********************************************************************/ + BOOL lsa_io_r_close(char *desc, LSA_R_CLOSE *r_c, prs_struct *ps, int depth) { - if (r_c == NULL) return False; + if (r_c == NULL) + return False; prs_debug(ps, depth, desc, "lsa_io_r_close"); depth++; - smb_io_pol_hnd("", &(r_c->pol), ps, depth); + if(!smb_io_pol_hnd("", &r_c->pol, ps, depth)) + return False; - prs_uint32("status", ps, depth, &(r_c->status)); + if(!prs_uint32("status", ps, depth, &r_c->status)) + return False; return True; } - diff --git a/source3/rpc_parse/parse_misc.c b/source3/rpc_parse/parse_misc.c index b38f55983d..5277825767 100644 --- a/source3/rpc_parse/parse_misc.c +++ b/source3/rpc_parse/parse_misc.c @@ -1,4 +1,3 @@ - /* * Unix SMB/Netbios implementation. * Version 1.9. @@ -27,453 +26,487 @@ extern int DEBUGLEVEL; - /******************************************************************* -reads or writes a BIGINT structure. + Reads or writes a UTIME type. ********************************************************************/ -BOOL smb_io_bigint(char *desc, BIGINT *bigint, prs_struct *ps, int depth) -{ - if (bigint == NULL) return False; - prs_debug(ps, depth, desc, "smb_io_bigint"); - depth++; - - prs_align(ps); - - prs_uint32("low ", ps, depth, &(bigint->low )); - prs_uint32("high", ps, depth, &(bigint->high)); - - return True; -} - -/******************************************************************* -reads or writes a UTIME type. -********************************************************************/ -static BOOL smb_io_utime(char *desc, UTIME *t, prs_struct *ps, int depth) +static BOOL smb_io_utime(char *desc, UTIME *t, prs_struct *ps, int depth) { - if (t == NULL) return False; + if (t == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_utime"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32 ("time", ps, depth, &(t->time)); + if(!prs_uint32 ("time", ps, depth, &t->time)) + return False; return True; } /******************************************************************* -reads or writes an NTTIME structure. + Reads or writes an NTTIME structure. ********************************************************************/ -BOOL smb_io_time(char *desc, NTTIME *nttime, prs_struct *ps, int depth) + +BOOL smb_io_time(char *desc, NTTIME *nttime, prs_struct *ps, int depth) { - if (nttime == NULL) return False; + if (nttime == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_time"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("low ", ps, depth, &(nttime->low )); /* low part */ - prs_uint32("high", ps, depth, &(nttime->high)); /* high part */ + if(!prs_uint32("low ", ps, depth, &nttime->low)) /* low part */ + return False; + if(!prs_uint32("high", ps, depth, &nttime->high)) /* high part */ + return False; return True; } /******************************************************************* -reads or writes a LOOKUP_LEVEL structure. + Reads or writes a LOOKUP_LEVEL structure. ********************************************************************/ + BOOL smb_io_lookup_level(char *desc, LOOKUP_LEVEL *level, prs_struct *ps, int depth) { - if (level == NULL) return False; + if (level == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_lookup_level"); depth++; - prs_align(ps); - prs_uint16("value", ps, depth, &(level->value)); - prs_align(ps); + if(!prs_align(ps)) + return False; + if(!prs_uint16("value", ps, depth, &level->value)) + return False; + if(!prs_align(ps)) + return False; return True; } /******************************************************************* -gets an enumeration handle from an ENUM_HND structure. + Gets an enumeration handle from an ENUM_HND structure. ********************************************************************/ + uint32 get_enum_hnd(ENUM_HND *enh) { return (enh && enh->ptr_hnd != 0) ? enh->handle : 0; - - return True; } /******************************************************************* -makes an ENUM_HND structure. + Inits an ENUM_HND structure. ********************************************************************/ -BOOL make_enum_hnd(ENUM_HND *enh, uint32 hnd) -{ - if (enh == NULL) return False; +void init_enum_hnd(ENUM_HND *enh, uint32 hnd) +{ DEBUG(5,("smb_io_enum_hnd\n")); enh->ptr_hnd = (hnd != 0) ? 1 : 0; enh->handle = hnd; - - return True; } /******************************************************************* -reads or writes an ENUM_HND structure. + Reads or writes an ENUM_HND structure. ********************************************************************/ -BOOL smb_io_enum_hnd(char *desc, ENUM_HND *hnd, prs_struct *ps, int depth) + +BOOL smb_io_enum_hnd(char *desc, ENUM_HND *hnd, prs_struct *ps, int depth) { - if (hnd == NULL) return False; + if (hnd == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_enum_hnd"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr_hnd", ps, depth, &(hnd->ptr_hnd)); /* pointer */ - if (hnd->ptr_hnd != 0) - { - prs_uint32("handle ", ps, depth, &(hnd->handle )); /* enum handle */ + if(!prs_uint32("ptr_hnd", ps, depth, &hnd->ptr_hnd)) /* pointer */ + return False; + + if (hnd->ptr_hnd != 0) { + if(!prs_uint32("handle ", ps, depth, &hnd->handle )) /* enum handle */ + return False; } return True; } /******************************************************************* -reads or writes a DOM_SID structure. + Reads or writes a DOM_SID structure. ********************************************************************/ -BOOL 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 False; + if (sid == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_dom_sid"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint8 ("sid_rev_num", ps, depth, &(sid->sid_rev_num)); - prs_uint8 ("num_auths ", ps, depth, &(sid->num_auths)); + if(!prs_uint8 ("sid_rev_num", ps, depth, &sid->sid_rev_num)) + return False; + if(!prs_uint8 ("num_auths ", ps, depth, &sid->num_auths)) + return False; for (i = 0; i < 6; i++) { fstring tmp; slprintf(tmp, sizeof(tmp) - 1, "id_auth[%d] ", i); - prs_uint8 (tmp, ps, depth, &(sid->id_auth[i])); + if(!prs_uint8 (tmp, ps, depth, &sid->id_auth[i])) + return False; } /* oops! XXXX should really issue a warning here... */ - if (sid->num_auths > MAXSUBAUTHS) sid->num_auths = MAXSUBAUTHS; + if (sid->num_auths > MAXSUBAUTHS) + sid->num_auths = MAXSUBAUTHS; - prs_uint32s(False, "sub_auths ", ps, depth, sid->sub_auths, sid->num_auths); + if(!prs_uint32s(False, "sub_auths ", ps, depth, sid->sub_auths, sid->num_auths)) + return False; return True; } /******************************************************************* -creates a DOM_SID2 structure. + Inits 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 ********************************************************************/ -BOOL make_dom_sid2(DOM_SID2 *sid2, const DOM_SID *sid) + +void init_dom_sid(DOM_SID *sid, char *str_sid) { - sid_copy(&sid2->sid, sid); - sid2->num_auths = sid2->sid.num_auths; + pstring domsid; + int identauth; + char *p; - return True; -} + if (str_sid == NULL) + { + DEBUG(4,("netlogon domain SID: none\n")); + sid->sid_rev_num = 0; + sid->num_auths = 0; + return; + } + + pstrcpy(domsid, str_sid); -/******************************************************************* -reads or writes a DOM_SID2 structure. -********************************************************************/ -BOOL smb_io_dom_sid2(char *desc, DOM_SID2 *sid, prs_struct *ps, int depth) -{ - if (sid == NULL) return False; + DEBUG(4,("init_dom_sid %d SID: %s\n", __LINE__, domsid)); - prs_debug(ps, depth, desc, "smb_io_dom_sid2"); - depth++; + /* assume, but should check, that domsid starts "S-" */ + p = strtok(domsid+2,"-"); + sid->sid_rev_num = atoi(p); - prs_align(ps); - - prs_uint32("num_auths", ps, depth, &(sid->num_auths)); + /* identauth in decimal should be < 2^32 */ + /* identauth in hex should be >= 2^32 */ + identauth = atoi(strtok(0,"-")); - smb_io_dom_sid("sid", &(sid->sid), ps, depth); + DEBUG(4,("netlogon rev %d\n", sid->sid_rev_num)); + DEBUG(4,("netlogon %s ia %d\n", p, identauth)); - return True; + 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,("init_dom_sid: %d SID: %s\n", __LINE__, domsid)); } /******************************************************************* -creates a STRHDR structure. + Inits a DOM_SID2 structure. ********************************************************************/ -BOOL make_str_hdr(STRHDR *hdr, int max_len, int len, uint32 buffer) -{ - hdr->str_max_len = max_len; - hdr->str_str_len = len; - hdr->buffer = buffer; - return True; +void init_dom_sid2(DOM_SID2 *sid2, DOM_SID *sid) +{ + sid2->sid = *sid; + sid2->num_auths = sid2->sid.num_auths; } /******************************************************************* -reads or writes a STRHDR structure. + Reads or writes a DOM_SID2 structure. ********************************************************************/ -BOOL smb_io_strhdr(char *desc, STRHDR *hdr, prs_struct *ps, int depth) + +BOOL smb_io_dom_sid2(char *desc, DOM_SID2 *sid, prs_struct *ps, int depth) { - if (hdr == NULL) return False; + if (sid == NULL) + return False; - prs_debug(ps, depth, desc, "smb_io_strhdr"); + prs_debug(ps, depth, desc, "smb_io_dom_sid2"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint16("str_str_len", ps, depth, &(hdr->str_str_len)); - prs_uint16("str_max_len", ps, depth, &(hdr->str_max_len)); - prs_uint32("buffer ", ps, depth, &(hdr->buffer )); + if(!prs_uint32("num_auths", ps, depth, &sid->num_auths)) + return False; - /* 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; + if(!smb_io_dom_sid("sid", &sid->sid, ps, depth)) + return False; return True; } /******************************************************************* -creates a STRHDR2 structure. +creates a STRHDR structure. ********************************************************************/ -BOOL make_strhdr2(STRHDR2 *hdr, uint32 max_len, uint32 len, uint32 buffer) + +void init_str_hdr(STRHDR *hdr, int max_len, int len, uint32 buffer) { hdr->str_max_len = max_len; hdr->str_str_len = len; hdr->buffer = buffer; - - return True; } /******************************************************************* -reads or writes a STRHDR2 structure. + Reads or writes a STRHDR structure. ********************************************************************/ -BOOL smb_io_strhdr2(char *desc, STRHDR2 *hdr, prs_struct *ps, int depth) + +BOOL smb_io_strhdr(char *desc, STRHDR *hdr, prs_struct *ps, int depth) { - if (hdr == NULL) return False; + if (hdr == NULL) + return False; 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 )); + if(!prs_uint16("str_str_len", ps, depth, &hdr->str_str_len)) + return False; + if(!prs_uint16("str_max_len", ps, depth, &hdr->str_max_len)) + return False; + if(!prs_uint32("buffer ", ps, depth, &hdr->buffer)) + return False; /* 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; + 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; return True; } /******************************************************************* -creates a UNIHDR structure. + Inits a UNIHDR structure. ********************************************************************/ -BOOL make_uni_hdr(UNIHDR *hdr, int len) + +void init_uni_hdr(UNIHDR *hdr, int len) { hdr->uni_str_len = 2 * len; hdr->uni_max_len = 2 * len; hdr->buffer = len != 0 ? 1 : 0; - - return True; } /******************************************************************* -reads or writes a UNIHDR structure. + Reads or writes a UNIHDR structure. ********************************************************************/ -BOOL smb_io_unihdr(char *desc, UNIHDR *hdr, prs_struct *ps, int depth) + +BOOL smb_io_unihdr(char *desc, UNIHDR *hdr, prs_struct *ps, int depth) { - if (hdr == NULL) return False; + if (hdr == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_unihdr"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint16("uni_str_len", ps, depth, &(hdr->uni_str_len)); - prs_uint16("uni_max_len", ps, depth, &(hdr->uni_max_len)); - prs_uint32("buffer ", ps, depth, &(hdr->buffer )); + if(!prs_uint16("uni_str_len", ps, depth, &hdr->uni_str_len)) + return False; + if(!prs_uint16("uni_max_len", ps, depth, &hdr->uni_max_len)) + return False; + if(!prs_uint32("buffer ", ps, depth, &hdr->buffer)) + return False; /* oops! XXXX maybe issue a warning that this is happening... */ - if (hdr->uni_max_len > MAX_UNISTRLEN) hdr->uni_max_len = MAX_UNISTRLEN; - if (hdr->uni_str_len > MAX_UNISTRLEN) hdr->uni_str_len = MAX_UNISTRLEN; + if (hdr->uni_max_len > MAX_UNISTRLEN) + hdr->uni_max_len = MAX_UNISTRLEN; + if (hdr->uni_str_len > MAX_UNISTRLEN) + hdr->uni_str_len = MAX_UNISTRLEN; return True; } /******************************************************************* -creates a BUFHDR structure. + Inits a BUFHDR structure. ********************************************************************/ -BOOL make_buf_hdr(BUFHDR *hdr, int max_len, int len) + +void init_buf_hdr(BUFHDR *hdr, int max_len, int len) { hdr->buf_max_len = max_len; hdr->buf_len = len; - - return True; } /******************************************************************* - prs_uint16 wrapper. call this and it sets up a pointer to where the - uint16 should be stored, or gets the size if reading + prs_uint16 wrapper. Call this and it sets up a pointer to where the + uint16 should be stored, or gets the size if reading. ********************************************************************/ -BOOL smb_io_hdrbuf_pre(char *desc, BUFHDR *hdr, prs_struct *ps, int depth, uint32 *offset) + +BOOL smb_io_hdrbuf_pre(char *desc, BUFHDR *hdr, prs_struct *ps, int depth, uint32 *offset) { - (*offset) = ps->offset; - if (ps->io) - { + (*offset) = prs_offset(ps); + if (ps->io) { + /* reading. */ - smb_io_hdrbuf(desc, hdr, ps, depth); - } - else - { - ps->offset += sizeof(uint32) * 2; + + if(!smb_io_hdrbuf(desc, hdr, ps, depth)) + return False; + + } else { + + /* writing. */ + + if(!prs_set_offset(ps, prs_offset(ps) + (sizeof(uint32) * 2))) + return False; } return True; } /******************************************************************* - smb_io_hdrbuf wrapper. call this and it retrospectively stores the size. - does nothing on reading, as that is already handled by ...._pre() + smb_io_hdrbuf wrapper. Call this and it retrospectively stores the size. + Does nothing on reading, as that is already handled by ...._pre() ********************************************************************/ -BOOL smb_io_hdrbuf_post(char *desc, BUFHDR *hdr, prs_struct *ps, int depth, + +BOOL smb_io_hdrbuf_post(char *desc, BUFHDR *hdr, prs_struct *ps, int depth, uint32 ptr_hdrbuf, uint32 max_len, uint32 len) { - if (!ps->io) - { - /* storing: go back and do a retrospective job. i hate this */ - uint32 old_offset = ps->offset; + if (!ps->io) { + /* writing: go back and do a retrospective job. i hate this */ + + uint32 old_offset = prs_offset(ps); - make_buf_hdr(hdr, max_len, len); - ps->offset = ptr_hdrbuf; - smb_io_hdrbuf(desc, hdr, ps, depth); - ps->offset = old_offset; + init_buf_hdr(hdr, max_len, len); + if(!prs_set_offset(ps, ptr_hdrbuf)) + return False; + if(!smb_io_hdrbuf(desc, hdr, ps, depth)) + return False; + + if(!prs_set_offset(ps, old_offset)) + return False; } return True; } /******************************************************************* -reads or writes a BUFHDR structure. + Reads or writes a BUFHDR structure. ********************************************************************/ -BOOL smb_io_hdrbuf(char *desc, BUFHDR *hdr, prs_struct *ps, int depth) + +BOOL smb_io_hdrbuf(char *desc, BUFHDR *hdr, prs_struct *ps, int depth) { - if (hdr == NULL) return False; + if (hdr == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_hdrbuf"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("buf_max_len", ps, depth, &(hdr->buf_max_len)); - prs_uint32("buf_len ", ps, depth, &(hdr->buf_len )); + if(!prs_uint32("buf_max_len", ps, depth, &hdr->buf_max_len)) + return False; + if(!prs_uint32("buf_len ", ps, depth, &hdr->buf_len)) + return False; /* oops! XXXX maybe issue a warning that this is happening... */ - if (hdr->buf_max_len > MAX_BUFFERLEN) hdr->buf_max_len = MAX_BUFFERLEN; - if (hdr->buf_len > MAX_BUFFERLEN) hdr->buf_len = MAX_BUFFERLEN; + if (hdr->buf_max_len > MAX_BUFFERLEN) + hdr->buf_max_len = MAX_BUFFERLEN; + if (hdr->buf_len > MAX_BUFFERLEN) + hdr->buf_len = MAX_BUFFERLEN; return True; } /******************************************************************* -creates a BUFHDR2 structure. +creates a UNIHDR2 structure. ********************************************************************/ -BOOL make_bufhdr2(BUFHDR2 *hdr, uint32 info_level, uint32 length, uint32 buffer) -{ - hdr->info_level = info_level; - hdr->length = length; - hdr->buffer = buffer; - - return True; -} -/******************************************************************* -reads or writes a BUFHDR2 structure. -********************************************************************/ -BOOL smb_io_bufhdr2(char *desc, BUFHDR2 *hdr, prs_struct *ps, int depth) +void init_uni_hdr2(UNIHDR2 *hdr, int len) { - if (hdr == NULL) return False; - - prs_debug(ps, depth, desc, "smb_io_bufhdr2"); - depth++; - - prs_align(ps); - prs_uint32("info_level", ps, depth, &(hdr->info_level)); - prs_uint32("length ", ps, depth, &(hdr->length )); - prs_uint32("buffer ", ps, depth, &(hdr->buffer )); - - return True; + init_uni_hdr(&hdr->unihdr, len); + hdr->buffer = (len > 0) ? 1 : 0; } /******************************************************************* -creates a UNIHDR2 structure. + Reads or writes a UNIHDR2 structure. ********************************************************************/ -BOOL make_uni_hdr2(UNIHDR2 *hdr, int len) -{ - make_uni_hdr(&(hdr->unihdr), len); - hdr->buffer = len > 0 ? 1 : 0; - - return True; -} -/******************************************************************* -reads or writes a UNIHDR2 structure. -********************************************************************/ -BOOL smb_io_unihdr2(char *desc, UNIHDR2 *hdr2, prs_struct *ps, int depth) +BOOL smb_io_unihdr2(char *desc, UNIHDR2 *hdr2, prs_struct *ps, int depth) { - if (hdr2 == NULL) return False; + if (hdr2 == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_unihdr2"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_unihdr("hdr", &(hdr2->unihdr), ps, depth); - prs_uint32("buffer", ps, depth, &(hdr2->buffer)); + if(!smb_io_unihdr("hdr", &hdr2->unihdr, ps, depth)) + return False; + if(!prs_uint32("buffer", ps, depth, &hdr2->buffer)) + return False; return True; } /******************************************************************* -creates a UNISTR structure. + Inits a UNISTR structure. ********************************************************************/ -BOOL make_unistr(UNISTR *str, char *buf) -{ - ascii_to_unistr(str->buffer, buf, sizeof(str->buffer)-1); - return True; +void init_unistr(UNISTR *str, char *buf) +{ + /* store the string (null-terminated copy) */ + dos_struni2((char *)str->buffer, buf, sizeof(str->buffer)); } /******************************************************************* reads or writes a UNISTR structure. XXXX NOTE: UNISTR structures NEED to be null-terminated. ********************************************************************/ -BOOL smb_io_unistr(char *desc, UNISTR *uni, prs_struct *ps, int depth) + +BOOL smb_io_unistr(char *desc, UNISTR *uni, prs_struct *ps, int depth) { - if (uni == NULL) return False; + if (uni == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_unistr"); depth++; - prs_unistr("unistr", ps, depth, uni); + if(!prs_align(ps)) + return False; + if(!prs_unistr("unistr", ps, depth, uni)) + return False; return True; } /******************************************************************* -creates a BUFFER3 structure from a uint32 + Inits a BUFFER3 structure from a uint32 ********************************************************************/ -BOOL make_buffer3_uint32(BUFFER3 *str, uint32 val) + +void init_buffer3_uint32(BUFFER3 *str, uint32 val) { ZERO_STRUCTP(str); @@ -482,14 +515,13 @@ BOOL make_buffer3_uint32(BUFFER3 *str, uint32 val) str->buf_len = sizeof(uint32); SIVAL(str->buffer, 0, val); - - return True; } /******************************************************************* -creates a BUFFER3 structure. + Inits a BUFFER3 structure. ********************************************************************/ -BOOL make_buffer3_str(BUFFER3 *str, const char *buf, int len) + +void init_buffer3_str(BUFFER3 *str, char *buf, int len) { ZERO_STRUCTP(str); @@ -497,364 +529,238 @@ BOOL make_buffer3_str(BUFFER3 *str, const char *buf, int len) str->buf_max_len = len * 2; str->buf_len = len * 2; - /* store the string (little endian buffer) */ - ascii_to_unibuf((char*)str->buffer, buf, str->buf_len); - - return True; + /* store the string (null-terminated 8 bit chars into 16 bit chars) */ + dos_struni2((char *)str->buffer, buf, sizeof(str->buffer)); } /******************************************************************* -creates a BUFFER3 structure from a hex string. + Inits a BUFFER3 structure from a hex string. ********************************************************************/ -BOOL make_buffer3_hex(BUFFER3 *str, char *buf) + +void init_buffer3_hex(BUFFER3 *str, char *buf) { ZERO_STRUCTP(str); str->buf_max_len = str->buf_len = strhex_to_str((char *)str->buffer, sizeof(str->buffer), buf); - - return True; } /******************************************************************* -creates a BUFFER3 structure. + Inits a BUFFER3 structure. ********************************************************************/ -BOOL make_buffer3_bytes(BUFFER3 *str, uint8 *buf, int len) + +void init_buffer3_bytes(BUFFER3 *str, uint8 *buf, int len) { ZERO_STRUCTP(str); /* max buffer size (allocated size) */ str->buf_max_len = len; if (buf != NULL) - { memcpy(str->buffer, buf, MIN(str->buf_len, sizeof(str->buffer))); - } str->buf_len = buf != NULL ? len : 0; - - return True; } /******************************************************************* -reads or writes a BUFFER3 structure. - the uni_max_len member tells you how large the buffer is. - the uni_str_len member tells you how much of the buffer is really used. + Reads or writes a BUFFER3 structure. + the uni_max_len member tells you how large the buffer is. + the uni_str_len member tells you how much of the buffer is really used. ********************************************************************/ -BOOL smb_io_buffer3(char *desc, BUFFER3 *buf3, prs_struct *ps, int depth) -{ - if (buf3 == NULL) return False; - - prs_debug(ps, depth, desc, "smb_io_buffer3"); - depth++; - prs_align(ps); - - prs_uint32("uni_max_len", ps, depth, &(buf3->buf_max_len)); - if (buf3->buf_max_len > MAX_UNISTRLEN) buf3->buf_max_len = MAX_UNISTRLEN; - - prs_uint8s(True, "buffer ", ps, depth, buf3->buffer, buf3->buf_max_len); - - prs_uint32("buf_len ", ps, depth, &(buf3->buf_len)); - if (buf3->buf_len > MAX_UNISTRLEN) buf3->buf_len = MAX_UNISTRLEN; - - return True; -} - -/******************************************************************* -creates a BUFFER4 structure. -********************************************************************/ -BOOL make_buffer4_str(BUFFER4 *str, const char *buf, int len) +BOOL smb_io_buffer3(char *desc, BUFFER3 *buf3, prs_struct *ps, int depth) { - ZERO_STRUCTP(str); - - /* set up string lengths. */ - str->buf_len = len * 2; + if (buf3 == NULL) + return False; - /* store the string (little endian buffer) */ - ascii_to_unibuf((char*)str->buffer, buf, str->buf_len); - - return True; -} - -/******************************************************************* -reads or writes a BUFFER4 structure. -********************************************************************/ -BOOL smb_io_buffer4(char *desc, BUFFER4 *buf4, uint32 buffer, prs_struct *ps, int depth) -{ - if ((buf4 == NULL) || (buffer == 0)) return False; - - prs_debug(ps, depth, desc, "smb_io_buffer4"); + prs_debug(ps, depth, desc, "smb_io_buffer3"); depth++; - prs_align(ps); - prs_uint32("buf_len", ps, depth, &(buf4->buf_len)); - - if (buf4->buf_len > MAX_BUFFERLEN) - { - buf4->buf_len = MAX_BUFFERLEN; - } - - prs_uint8s(True, "buffer", ps, depth, buf4->buffer, buf4->buf_len); - - return True; -} - -/******************************************************************* -initialise a BUFFER5 structure. -********************************************************************/ -BOOL init_buffer5(BUFFER5 **str) -{ - BUFFER5 *buf5; - - buf5=(BUFFER5 *)malloc( sizeof(BUFFER5) ); - - buf5->buf_len=0; - buf5->buffer=NULL; - *str=buf5; - - return True; -} - -/******************************************************************* -clear a BUFFER5 structure. -********************************************************************/ -BOOL clear_buffer5(BUFFER5 **str) -{ - BUFFER5 *buf5; + if(!prs_align(ps)) + return False; - buf5=*str; - if (buf5->buffer != NULL ) - { - free(buf5->buffer); - } - free(buf5); - *str=NULL; + if(!prs_uint32("uni_max_len", ps, depth, &buf3->buf_max_len)) + return False; - return True; -} + if (buf3->buf_max_len > MAX_UNISTRLEN) + buf3->buf_max_len = MAX_UNISTRLEN; -/******************************************************************* -creates a BUFFER5 structure. -********************************************************************/ -BOOL make_buffer5(BUFFER5 *str, char *buf, int len) -{ + if(!prs_uint8s(True, "buffer ", ps, depth, buf3->buffer, buf3->buf_max_len)) + return False; - /* max buffer size (allocated size) */ - str->buf_len = len; - str->buffer = (uint16 *)malloc( sizeof(uint16) * len ); - ascii_to_unistr(str->buffer, buf, len); + if(!prs_uint32("buf_len ", ps, depth, &buf3->buf_len)) + return False; + if (buf3->buf_len > MAX_UNISTRLEN) + buf3->buf_len = MAX_UNISTRLEN; return True; } /******************************************************************* -reads or writes a BUFFER5 structure. -the buf_len member tells you how large the buffer is. + Inits a BUFFER2 structure. ********************************************************************/ -BOOL smb_io_buffer5(char *desc, BUFFER5 *buf5, prs_struct *ps, int depth) -{ - prs_debug(ps, depth, desc, "smb_io_buffer4"); - depth++; - - if (buf5 == NULL) return False; - - prs_align(ps); - prs_uint32("buf_len", ps, depth, &(buf5->buf_len)); - - /* reading: alloc the buffer first */ - if ( ps->io ) - { - buf5->buffer=(uint16 *)malloc( sizeof(uint16)*buf5->buf_len ); - } - - prs_uint16s(True, "buffer ", ps, depth, buf5->buffer, buf5->buf_len); - - return True; -} -/******************************************************************* -creates a BUFFER2 structure. -********************************************************************/ -BOOL make_buffer2_multi(BUFFER2 *str, char *const* const buf, uint32 num) +void init_buffer2(BUFFER2 *str, uint8 *buf, int len) { - int i; - char *dest = (char*)str->buffer; - size_t max_len = sizeof(str->buffer)-1; - ZERO_STRUCTP(str); - str->buf_max_len = 0; + /* max buffer size (allocated size) */ + str->buf_max_len = len; str->undoc = 0; + str->buf_len = buf != NULL ? len : 0; - for (i = 0; i < num && max_len > 0; i++) - { - size_t len = buf[i] != NULL ? strlen(buf[i]) : 0; - - str->buf_max_len += len * 2; - str->buf_len += len * 2; - - ascii_to_unibuf(dest, buf[i], max_len); - - dest += len * 2 + 2; - max_len -= len * 2 + 2; - } - - return True; + if (buf != NULL) + memcpy(str->buffer, buf, MIN(str->buf_len, sizeof(str->buffer))); } /******************************************************************* -creates a BUFFER2 structure. + Reads or writes a BUFFER2 structure. + the uni_max_len member tells you how large the buffer is. + the uni_str_len member tells you how much of the buffer is really used. ********************************************************************/ -BOOL make_buffer2(BUFFER2 *str, const char *buf, int len) -{ - ZERO_STRUCTP(str); - /* set up string lengths. */ - str->buf_max_len = str->buf_len = len * 2; - str->undoc = 0; - - /* store the string */ - ascii_to_unibuf((char*)str->buffer, buf, - MIN(str->buf_len, sizeof(str->buffer)-1)); - - return True; -} - -/******************************************************************* -reads or writes a BUFFER2 structure. - the uni_max_len member tells you how large the buffer is. - the uni_str_len member tells you how much of the buffer is really used. -********************************************************************/ -BOOL smb_io_buffer2(char *desc, BUFFER2 *buf2, uint32 buffer, prs_struct *ps, int depth) +BOOL smb_io_buffer2(char *desc, BUFFER2 *buf2, uint32 buffer, prs_struct *ps, int depth) { - if (buf2 == NULL) return False; + if (buf2 == NULL) + return False; + + if (buffer) { - if (buffer) - { prs_debug(ps, depth, desc, "smb_io_buffer2"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - 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)); + if(!prs_uint32("uni_max_len", ps, depth, &buf2->buf_max_len)) + return False; + if(!prs_uint32("undoc ", ps, depth, &buf2->undoc)) + return False; + if(!prs_uint32("buf_len ", ps, depth, &buf2->buf_len)) + return False; /* oops! XXXX maybe issue a warning that this is happening... */ - if (buf2->buf_max_len > MAX_UNISTRLEN) buf2->buf_max_len = MAX_UNISTRLEN; - if (buf2->buf_len > MAX_UNISTRLEN) buf2->buf_len = MAX_UNISTRLEN; + if (buf2->buf_max_len > MAX_UNISTRLEN) + buf2->buf_max_len = MAX_UNISTRLEN; + if (buf2->buf_len > MAX_UNISTRLEN) + buf2->buf_len = MAX_UNISTRLEN; /* buffer advanced by indicated length of string NOT by searching for null-termination */ - prs_buffer2(True, "buffer ", ps, depth, buf2); - } - else - { + + if(!prs_buffer2(True, "buffer ", ps, depth, buf2)) + return False; + + } else { + prs_debug(ps, depth, desc, "smb_io_buffer2 - NULL"); depth++; - bzero(buf2, sizeof(*buf2)); - } + memset((char *)buf2, '\0', sizeof(*buf2)); + } return True; } /******************************************************************* creates a UNISTR2 structure: sets up the buffer, too ********************************************************************/ -BOOL make_buf_unistr2(UNISTR2 *str, uint32 *ptr, const char *buf) + +void init_buf_unistr2(UNISTR2 *str, uint32 *ptr, char *buf) { - if (buf != NULL) - { + if (buf != NULL) { + *ptr = 1; - make_unistr2(str, buf, strlen(buf)+1); - } - else - { + init_unistr2(str, buf, strlen(buf)+1); + + } else { + *ptr = 0; - make_unistr2(str, "", 0); - } + init_unistr2(str, "", 0); - return True; + } } /******************************************************************* -creates a STRING2 structure. + Copies a UNISTR2 structure. ********************************************************************/ -BOOL make_string2(STRING2 *str, const char *buf, int len) -{ - /* set up string lengths. */ - str->str_max_len = len; - str->undoc = 0; - str->str_str_len = len; - /* store the string */ - if(len != 0) - { - memcpy(str->buffer, buf, len); - } +void copy_unistr2(UNISTR2 *str, UNISTR2 *from) +{ + /* set up string lengths. add one if string is not null-terminated */ + str->uni_max_len = from->uni_max_len; + str->undoc = from->undoc; + str->uni_str_len = from->uni_str_len; - return True; + /* copy the string */ + memcpy(str->buffer, from->buffer, sizeof(from->buffer)); } /******************************************************************* -creates a STRING2 structure: sets up the buffer, too + Creates a STRING2 structure. ********************************************************************/ -BOOL make_buf_string2(STRING2 *str, uint32 *ptr, const char *buf) + +void init_string2(STRING2 *str, char *buf, int len) { - if (buf != NULL) - { - *ptr = 1; - make_string2(str, buf, strlen(buf)+1); - } - else - { - *ptr = 0; - make_string2(str, "", 0); - } + /* set up string lengths. */ + str->str_max_len = len; + str->undoc = 0; + str->str_str_len = len; - return True; + /* store the string */ + if(len != 0) + memcpy(str->buffer, buf, len); } /******************************************************************* -reads or writes a STRING2 structure. -XXXX NOTE: STRING2 structures need NOT be null-terminated. - the str_str_len member tells you how long the string is; - the str_max_len member tells you how large the buffer is. + Reads or writes a STRING2 structure. + XXXX NOTE: STRING2 structures need NOT be null-terminated. + the str_str_len member tells you how long the string is; + the str_max_len member tells you how large the buffer is. ********************************************************************/ -BOOL smb_io_string2(char *desc, STRING2 *str2, uint32 buffer, prs_struct *ps, int depth) + +BOOL smb_io_string2(char *desc, STRING2 *str2, uint32 buffer, prs_struct *ps, int depth) { - if (str2 == NULL) return False; + if (str2 == NULL) + return False; + + if (buffer) { - if (buffer) - { prs_debug(ps, depth, desc, "smb_io_string2"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("str_max_len", ps, depth, &(str2->str_max_len)); - prs_uint32("undoc ", ps, depth, &(str2->undoc )); - prs_uint32("str_str_len", ps, depth, &(str2->str_str_len)); + if(!prs_uint32("str_max_len", ps, depth, &str2->str_max_len)) + return False; + if(!prs_uint32("undoc ", ps, depth, &str2->undoc)) + return False; + if(!prs_uint32("str_str_len", ps, depth, &str2->str_str_len)) + return False; /* oops! XXXX maybe issue a warning that this is happening... */ - if (str2->str_max_len > MAX_STRINGLEN) str2->str_max_len = MAX_STRINGLEN; - if (str2->str_str_len > MAX_STRINGLEN) str2->str_str_len = MAX_STRINGLEN; + if (str2->str_max_len > MAX_STRINGLEN) + str2->str_max_len = MAX_STRINGLEN; + if (str2->str_str_len > MAX_STRINGLEN) + str2->str_str_len = MAX_STRINGLEN; /* buffer advanced by indicated length of string NOT by searching for null-termination */ - prs_string2(True, "buffer ", ps, depth, str2); - } - else - { + if(!prs_string2(True, "buffer ", ps, depth, str2)) + return False; + + } else { + prs_debug(ps, depth, desc, "smb_io_string2 - NULL"); depth++; - bzero(str2, sizeof(*str2)); + memset((char *)str2, '\0', sizeof(*str2)); + } return True; } /******************************************************************* -creates a UNISTR2 structure. + Inits a UNISTR2 structure. ********************************************************************/ -BOOL make_unistr2(UNISTR2 *str, const char *buf, int len) + +void init_unistr2(UNISTR2 *str, char *buf, int len) { ZERO_STRUCTP(str); @@ -863,79 +769,93 @@ BOOL make_unistr2(UNISTR2 *str, const char *buf, int len) str->undoc = 0; str->uni_str_len = len; - /* store the string (wide chars) */ - ascii_to_unistr(str->buffer, buf, len); - - return True; + /* store the string (null-terminated 8 bit chars into 16 bit chars) */ + dos_struni2((char *)str->buffer, buf, sizeof(str->buffer)); } /******************************************************************* -reads or writes a UNISTR2 structure. -XXXX NOTE: UNISTR2 structures need NOT be null-terminated. - the uni_str_len member tells you how long the string is; - the uni_max_len member tells you how large the buffer is. + Reads or writes a UNISTR2 structure. + XXXX NOTE: UNISTR2 structures need NOT be null-terminated. + the uni_str_len member tells you how long the string is; + the uni_max_len member tells you how large the buffer is. ********************************************************************/ -BOOL smb_io_unistr2(char *desc, UNISTR2 *uni2, uint32 buffer, prs_struct *ps, int depth) + +BOOL smb_io_unistr2(char *desc, UNISTR2 *uni2, uint32 buffer, prs_struct *ps, int depth) { - if (uni2 == NULL) return False; + if (uni2 == NULL) + return False; + + if (buffer) { - if (buffer) - { prs_debug(ps, depth, desc, "smb_io_unistr2"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("uni_max_len", ps, depth, &(uni2->uni_max_len)); - prs_uint32("undoc ", ps, depth, &(uni2->undoc )); - prs_uint32("uni_str_len", ps, depth, &(uni2->uni_str_len)); + if(!prs_uint32("uni_max_len", ps, depth, &uni2->uni_max_len)) + return False; + if(!prs_uint32("undoc ", ps, depth, &uni2->undoc)) + return False; + if(!prs_uint32("uni_str_len", ps, depth, &uni2->uni_str_len)) + return False; /* oops! XXXX maybe issue a warning that this is happening... */ - if (uni2->uni_max_len > MAX_UNISTRLEN) uni2->uni_max_len = MAX_UNISTRLEN; - if (uni2->uni_str_len > MAX_UNISTRLEN) uni2->uni_str_len = MAX_UNISTRLEN; + if (uni2->uni_max_len > MAX_UNISTRLEN) + uni2->uni_max_len = MAX_UNISTRLEN; + if (uni2->uni_str_len > MAX_UNISTRLEN) + uni2->uni_str_len = MAX_UNISTRLEN; /* buffer advanced by indicated length of string NOT by searching for null-termination */ - prs_unistr2(True, "buffer ", ps, depth, uni2); - } - else - { + if(!prs_unistr2(True, "buffer ", ps, depth, uni2)) + return False; + + } else { + prs_debug(ps, depth, desc, "smb_io_unistr2 - NULL"); depth++; - bzero(uni2, sizeof(*uni2)); + memset((char *)uni2, '\0', sizeof(*uni2)); + } return True; } /******************************************************************* -creates a DOM_RID2 structure. + Inits a DOM_RID2 structure. ********************************************************************/ -BOOL make_dom_rid2(DOM_RID2 *rid2, uint32 rid, uint8 type, uint32 idx) + +void init_dom_rid2(DOM_RID2 *rid2, uint32 rid, uint8 type, uint32 idx) { rid2->type = type; rid2->rid = rid; rid2->rid_idx = idx; - - return True; } /******************************************************************* -reads or writes a DOM_RID2 structure. + Reads or writes a DOM_RID2 structure. ********************************************************************/ -BOOL smb_io_dom_rid2(char *desc, DOM_RID2 *rid2, prs_struct *ps, int depth) + +BOOL smb_io_dom_rid2(char *desc, DOM_RID2 *rid2, prs_struct *ps, int depth) { - if (rid2 == NULL) return False; + if (rid2 == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_dom_rid2"); depth++; - prs_align(ps); - - prs_uint8("type ", ps, depth, &(rid2->type)); - prs_align(ps); - prs_uint32("rid ", ps, depth, &(rid2->rid )); - prs_uint32("rid_idx", ps, depth, &(rid2->rid_idx )); + if(!prs_align(ps)) + return False; + + if(!prs_uint8("type ", ps, depth, &rid2->type)) + return False; + if(!prs_align(ps)) + return False; + if(!prs_uint32("rid ", ps, depth, &rid2->rid)) + return False; + if(!prs_uint32("rid_idx", ps, depth, &rid2->rid_idx)) + return False; return True; } @@ -943,414 +863,495 @@ BOOL smb_io_dom_rid2(char *desc, DOM_RID2 *rid2, prs_struct *ps, int depth) /******************************************************************* creates a DOM_RID3 structure. ********************************************************************/ -BOOL make_dom_rid3(DOM_RID3 *rid3, uint32 rid, uint8 type) -{ - rid3->rid = rid; - rid3->type1 = type; - rid3->ptr_type = 0x1; /* non-zero, basically. */ - rid3->type2 = 0x1; - rid3->unk = type; - return True; +void init_dom_rid3(DOM_RID3 *rid3, uint32 rid, uint8 type) +{ + rid3->rid = rid; + rid3->type1 = type; + rid3->ptr_type = 0x1; /* non-zero, basically. */ + rid3->type2 = 0x1; + rid3->unk = type; } /******************************************************************* reads or writes a DOM_RID3 structure. ********************************************************************/ -BOOL smb_io_dom_rid3(char *desc, DOM_RID3 *rid3, prs_struct *ps, int depth) + +BOOL smb_io_dom_rid3(char *desc, DOM_RID3 *rid3, prs_struct *ps, int depth) { - if (rid3 == NULL) return False; + if (rid3 == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_dom_rid3"); depth++; - prs_align(ps); - - prs_uint32("rid ", ps, depth, &(rid3->rid )); - 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 )); + if(!prs_align(ps)) + return False; + + if(!prs_uint32("rid ", ps, depth, &rid3->rid)) + return False; + if(!prs_uint32("type1 ", ps, depth, &rid3->type1)) + return False; + if(!prs_uint32("ptr_type", ps, depth, &rid3->ptr_type)) + return False; + if(!prs_uint32("type2 ", ps, depth, &rid3->type2)) + return False; + if(!prs_uint32("unk ", ps, depth, &rid3->unk)) + return False; return True; } /******************************************************************* -makes a DOM_CLNT_SRV structure. + Inits a DOM_RID4 structure. ********************************************************************/ -static BOOL make_clnt_srv(DOM_CLNT_SRV *log, - const char *logon_srv, - const char *comp_name) + +void init_dom_rid4(DOM_RID4 *rid4, uint16 unknown, uint16 attr, uint32 rid) { - if (log == NULL) return False; + rid4->unknown = unknown; + rid4->attr = attr; + rid4->rid = rid; +} - DEBUG(5,("make_clnt_srv: %d\n", __LINE__)); +/******************************************************************* + Inits a DOM_CLNT_SRV structure. +********************************************************************/ - if (logon_srv != NULL) - { +static void init_clnt_srv(DOM_CLNT_SRV *log, char *logon_srv, char *comp_name) +{ + DEBUG(5,("init_clnt_srv: %d\n", __LINE__)); + + if (logon_srv != NULL) { log->undoc_buffer = 1; - make_unistr2(&(log->uni_logon_srv), logon_srv, strlen(logon_srv)+1); - } - else - { + init_unistr2(&(log->uni_logon_srv), logon_srv, strlen(logon_srv)+1); + } else { log->undoc_buffer = 0; } - if (comp_name != NULL) - { + if (comp_name != NULL) { log->undoc_buffer2 = 1; - make_unistr2(&(log->uni_comp_name), comp_name, strlen(comp_name)+1); - } - else - { + init_unistr2(&(log->uni_comp_name), comp_name, strlen(comp_name)+1); + } else { log->undoc_buffer2 = 0; } - - return True; } /******************************************************************* -reads or writes a DOM_CLNT_SRV structure. + Inits or writes a DOM_CLNT_SRV structure. ********************************************************************/ -static BOOL smb_io_clnt_srv(char *desc, DOM_CLNT_SRV *log, prs_struct *ps, int depth) + +static BOOL smb_io_clnt_srv(char *desc, DOM_CLNT_SRV *log, prs_struct *ps, int depth) { - if (log == NULL) return False; + if (log == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_clnt_srv"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("undoc_buffer ", ps, depth, &(log->undoc_buffer )); - if (log->undoc_buffer != 0) - { - smb_io_unistr2("unistr2", &(log->uni_logon_srv), log->undoc_buffer, ps, depth); + if(!prs_uint32("undoc_buffer ", ps, depth, &log->undoc_buffer)) + return False; + + if (log->undoc_buffer != 0) { + if(!smb_io_unistr2("unistr2", &log->uni_logon_srv, log->undoc_buffer, ps, depth)) + return False; } - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("undoc_buffer2", ps, depth, &(log->undoc_buffer2)); - if (log->undoc_buffer2 != 0) - { - smb_io_unistr2("unistr2", &(log->uni_comp_name), log->undoc_buffer2, ps, depth); + if(!prs_uint32("undoc_buffer2", ps, depth, &log->undoc_buffer2)) + return False; + + if (log->undoc_buffer2 != 0) { + if(!smb_io_unistr2("unistr2", &log->uni_comp_name, log->undoc_buffer2, ps, depth)) + return False; } return True; } /******************************************************************* -makes a DOM_LOG_INFO structure. + Inits a DOM_LOG_INFO structure. ********************************************************************/ -BOOL 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 False; +void init_log_info(DOM_LOG_INFO *log, char *logon_srv, char *acct_name, + uint16 sec_chan, char *comp_name) +{ DEBUG(5,("make_log_info %d\n", __LINE__)); log->undoc_buffer = 1; - make_unistr2(&(log->uni_logon_srv), logon_srv, strlen(logon_srv)+1); - make_unistr2(&(log->uni_acct_name), acct_name, strlen(acct_name)+1); + init_unistr2(&log->uni_logon_srv, logon_srv, strlen(logon_srv)+1); + init_unistr2(&log->uni_acct_name, acct_name, strlen(acct_name)+1); log->sec_chan = sec_chan; - make_unistr2(&(log->uni_comp_name), comp_name, strlen(comp_name)+1); - - return True; + init_unistr2(&log->uni_comp_name, comp_name, strlen(comp_name)+1); } /******************************************************************* -reads or writes a DOM_LOG_INFO structure. + Reads or writes a DOM_LOG_INFO structure. ********************************************************************/ -BOOL smb_io_log_info(char *desc, DOM_LOG_INFO *log, prs_struct *ps, int depth) + +BOOL smb_io_log_info(char *desc, DOM_LOG_INFO *log, prs_struct *ps, int depth) { - if (log == NULL) return False; + if (log == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_log_info"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("undoc_buffer", ps, depth, &(log->undoc_buffer)); + if(!prs_uint32("undoc_buffer", ps, depth, &log->undoc_buffer)) + return False; - smb_io_unistr2("unistr2", &(log->uni_logon_srv), True, ps, depth); - smb_io_unistr2("unistr2", &(log->uni_acct_name), True, ps, depth); + if(!smb_io_unistr2("unistr2", &log->uni_logon_srv, True, ps, depth)) + return False; + if(!smb_io_unistr2("unistr2", &log->uni_acct_name, True, ps, depth)) + return False; - prs_uint16("sec_chan", ps, depth, &(log->sec_chan)); + if(!prs_uint16("sec_chan", ps, depth, &log->sec_chan)) + return False; - smb_io_unistr2("unistr2", &(log->uni_comp_name), True, ps, depth); + if(!smb_io_unistr2("unistr2", &log->uni_comp_name, True, ps, depth)) + return False; return True; } /******************************************************************* -reads or writes a DOM_CHAL structure. + Reads or writes a DOM_CHAL structure. ********************************************************************/ -BOOL smb_io_chal(char *desc, DOM_CHAL *chal, prs_struct *ps, int depth) + +BOOL smb_io_chal(char *desc, DOM_CHAL *chal, prs_struct *ps, int depth) { - if (chal == NULL) return False; + if (chal == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_chal"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint8s (False, "data", ps, depth, chal->data, 8); + if(!prs_uint8s (False, "data", ps, depth, chal->data, 8)) + return False; return True; } /******************************************************************* -reads or writes a DOM_CRED structure. + Reads or writes a DOM_CRED structure. ********************************************************************/ + BOOL smb_io_cred(char *desc, DOM_CRED *cred, prs_struct *ps, int depth) { - if (cred == NULL) return False; + if (cred == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_cred"); depth++; - prs_align(ps); - - smb_io_chal ("", &(cred->challenge), ps, depth); - smb_io_utime("", &(cred->timestamp), ps, depth); + if(!prs_align(ps)) + return False; + + if(!smb_io_chal ("", &cred->challenge, ps, depth)) + return False; + if(!smb_io_utime("", &cred->timestamp, ps, depth)) + return False; return True; } /******************************************************************* -makes a DOM_CLNT_INFO2 structure. + Inits a DOM_CLNT_INFO2 structure. ********************************************************************/ -BOOL make_clnt_info2(DOM_CLNT_INFO2 *clnt, - const char *logon_srv, const char *comp_name, + +void init_clnt_info2(DOM_CLNT_INFO2 *clnt, + char *logon_srv, char *comp_name, DOM_CRED *clnt_cred) { - if (clnt == NULL) return False; - DEBUG(5,("make_clnt_info: %d\n", __LINE__)); - make_clnt_srv(&(clnt->login), logon_srv, comp_name); + init_clnt_srv(&(clnt->login), logon_srv, comp_name); - if (clnt_cred != NULL) - { + if (clnt_cred != NULL) { clnt->ptr_cred = 1; memcpy(&(clnt->cred), clnt_cred, sizeof(clnt->cred)); - } - else - { + } else { clnt->ptr_cred = 0; } - - return True; } /******************************************************************* -reads or writes a DOM_CLNT_INFO2 structure. + Reads or writes a DOM_CLNT_INFO2 structure. ********************************************************************/ -BOOL smb_io_clnt_info2(char *desc, DOM_CLNT_INFO2 *clnt, prs_struct *ps, int depth) + +BOOL smb_io_clnt_info2(char *desc, DOM_CLNT_INFO2 *clnt, prs_struct *ps, int depth) { - if (clnt == NULL) return False; + if (clnt == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_clnt_info2"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_clnt_srv("", &(clnt->login), ps, depth); + if(!smb_io_clnt_srv("", &clnt->login, ps, depth)) + return False; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr_cred", ps, depth, &(clnt->ptr_cred)); - smb_io_cred ("", &(clnt->cred ), ps, depth); + if(!prs_uint32("ptr_cred", ps, depth, &clnt->ptr_cred)) + return False; + if(!smb_io_cred("", &clnt->cred, ps, depth)) + return False; return True; } /******************************************************************* -makes a DOM_CLNT_INFO structure. + Inits a DOM_CLNT_INFO structure. ********************************************************************/ -BOOL make_clnt_info(DOM_CLNT_INFO *clnt, - const char *logon_srv, const char *acct_name, - uint16 sec_chan, const char *comp_name, + +void init_clnt_info(DOM_CLNT_INFO *clnt, + char *logon_srv, char *acct_name, + uint16 sec_chan, char *comp_name, DOM_CRED *cred) { - if (clnt == NULL || cred == NULL) return False; - DEBUG(5,("make_clnt_info\n")); - make_log_info(&(clnt->login), logon_srv, acct_name, sec_chan, comp_name); - memcpy(&(clnt->cred), cred, sizeof(clnt->cred)); - - return True; + init_log_info(&clnt->login, logon_srv, acct_name, sec_chan, comp_name); + memcpy(&clnt->cred, cred, sizeof(clnt->cred)); } /******************************************************************* -reads or writes a DOM_CLNT_INFO structure. + Reads or writes a DOM_CLNT_INFO structure. ********************************************************************/ + BOOL smb_io_clnt_info(char *desc, DOM_CLNT_INFO *clnt, prs_struct *ps, int depth) { - if (clnt == NULL) return False; + if (clnt == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_clnt_info"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_log_info("", &(clnt->login), ps, depth); - smb_io_cred ("", &(clnt->cred ), ps, depth); + if(!smb_io_log_info("", &clnt->login, ps, depth)) + return False; + if(!smb_io_cred("", &clnt->cred, ps, depth)) + return False; return True; } /******************************************************************* -makes an OWF_INFO structure. + Inits a DOM_LOGON_ID structure. ********************************************************************/ -BOOL make_owf_info(OWF_INFO *hash, uint8 data[16]) + +void init_logon_id(DOM_LOGON_ID *log, uint32 log_id_low, uint32 log_id_high) { - if (hash == NULL) return False; + DEBUG(5,("make_logon_id: %d\n", __LINE__)); + + log->low = log_id_low; + log->high = log_id_high; +} + +/******************************************************************* + Reads or writes a DOM_LOGON_ID structure. +********************************************************************/ - DEBUG(5,("make_owf_info: %d\n", __LINE__)); +BOOL smb_io_logon_id(char *desc, DOM_LOGON_ID *log, prs_struct *ps, int depth) +{ + if (log == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_logon_id"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("low ", ps, depth, &log->low )) + return False; + if(!prs_uint32("high", ps, depth, &log->high)) + return False; + + return True; +} + +/******************************************************************* + Inits an OWF_INFO structure. +********************************************************************/ + +void init_owf_info(OWF_INFO *hash, uint8 data[16]) +{ + DEBUG(5,("init_owf_info: %d\n", __LINE__)); if (data != NULL) - { memcpy(hash->data, data, sizeof(hash->data)); - } else - { - bzero(hash->data, sizeof(hash->data)); - } - - return True; + memset((char *)hash->data, '\0', sizeof(hash->data)); } /******************************************************************* -reads or writes an OWF_INFO structure. + Reads or writes an OWF_INFO structure. ********************************************************************/ + BOOL smb_io_owf_info(char *desc, OWF_INFO *hash, prs_struct *ps, int depth) { - if (hash == NULL) return False; + if (hash == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_owf_info"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint8s (False, "data", ps, depth, hash->data, 16); + if(!prs_uint8s (False, "data", ps, depth, hash->data, 16)) + return False; return True; } /******************************************************************* -reads or writes a DOM_GID structure. + Reads or writes a DOM_GID structure. ********************************************************************/ + BOOL smb_io_gid(char *desc, DOM_GID *gid, prs_struct *ps, int depth) { - if (gid == NULL) return False; + if (gid == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_gid"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("g_rid", ps, depth, &(gid->g_rid)); - prs_uint32("attr ", ps, depth, &(gid->attr )); + if(!prs_uint32("g_rid", ps, depth, &gid->g_rid)) + return False; + if(!prs_uint32("attr ", ps, depth, &gid->attr)) + return False; return True; } /******************************************************************* -reads or writes an POLICY_HND structure. + Reads or writes an POLICY_HND structure. ********************************************************************/ -BOOL smb_io_pol_hnd(char *desc, POLICY_HND *pol, prs_struct *ps, int depth) + +BOOL smb_io_pol_hnd(char *desc, POLICY_HND *pol, prs_struct *ps, int depth) { - if (pol == NULL) return False; + if (pol == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_pol_hnd"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint8s (False, "data", ps, depth, pol->data, POL_HND_SIZE); + if(!prs_uint8s (False, "data", ps, depth, pol->data, POL_HND_SIZE)) + return False; return True; } /******************************************************************* -reads or writes a dom query structure. + Reads or writes a dom query structure. ********************************************************************/ -static BOOL smb_io_dom_query(char *desc, DOM_QUERY *d_q, prs_struct *ps, int depth) + +static BOOL smb_io_dom_query(char *desc, DOM_QUERY *d_q, prs_struct *ps, int depth) { - if (d_q == NULL) return False; + if (d_q == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_dom_query"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint16("uni_dom_max_len", ps, depth, &(d_q->uni_dom_max_len)); /* domain name string length * 2 */ - prs_uint16("uni_dom_str_len", ps, depth, &(d_q->uni_dom_str_len)); /* domain name string length * 2 */ - - prs_uint32("buffer_dom_name", ps, depth, &(d_q->buffer_dom_name)); /* undocumented domain name string buffer pointer */ - prs_uint32("buffer_dom_sid ", ps, depth, &(d_q->buffer_dom_sid )); /* undocumented domain SID string buffer pointer */ + if(!prs_uint16("uni_dom_max_len", ps, depth, &d_q->uni_dom_max_len)) /* domain name string length * 2 */ + return False; + if(!prs_uint16("uni_dom_str_len", ps, depth, &d_q->uni_dom_str_len)) /* domain name string length * 2 */ + return False; - smb_io_unistr2("unistr2", &(d_q->uni_domain_name), d_q->buffer_dom_name, ps, depth); /* domain name (unicode string) */ + if(!prs_uint32("buffer_dom_name", ps, depth, &d_q->buffer_dom_name)) /* undocumented domain name string buffer pointer */ + return False; + if(!prs_uint32("buffer_dom_sid ", ps, depth, &d_q->buffer_dom_sid)) /* undocumented domain SID string buffer pointer */ + return False; - prs_align(ps); + if(!smb_io_unistr2("unistr2", &d_q->uni_domain_name, d_q->buffer_dom_name, ps, depth)) /* domain name (unicode string) */ + return False; - if (d_q->buffer_dom_sid != 0) - { - smb_io_dom_sid2("", &(d_q->dom_sid), ps, depth); /* domain SID */ - } - else - { - bzero(&(d_q->dom_sid), sizeof(d_q->dom_sid)); + if(!prs_align(ps)) + return False; + + if (d_q->buffer_dom_sid != 0) { + if(!smb_io_dom_sid2("", &d_q->dom_sid, ps, depth)) /* domain SID */ + return False; + } else { + memset((char *)&d_q->dom_sid, '\0', sizeof(d_q->dom_sid)); } return True; } /******************************************************************* -reads or writes a dom query structure. + Reads or writes a dom query structure. ********************************************************************/ -BOOL smb_io_dom_query_3(char *desc, DOM_QUERY_3 *d_q, prs_struct *ps, int depth) -{ - smb_io_dom_query("", d_q, ps, depth); - return True; +BOOL smb_io_dom_query_3(char *desc, DOM_QUERY_3 *d_q, prs_struct *ps, int depth) +{ + return smb_io_dom_query("", d_q, ps, depth); } /******************************************************************* -reads or writes a dom query structure. + Reads or writes a dom query structure. ********************************************************************/ -BOOL smb_io_dom_query_5(char *desc, DOM_QUERY_3 *d_q, prs_struct *ps, int depth) -{ - smb_io_dom_query("", d_q, ps, depth); - return True; +BOOL smb_io_dom_query_5(char *desc, DOM_QUERY_3 *d_q, prs_struct *ps, int depth) +{ + return smb_io_dom_query("", d_q, ps, depth); } /******************************************************************* -reads or writes a UNISTR3 structure. + Reads or writes a UNISTR3 structure. ********************************************************************/ -BOOL smb_io_unistr3(char *desc, UNISTR3 *name, prs_struct *ps, int depth) + +BOOL smb_io_unistr3(char *desc, UNISTR3 *name, prs_struct *ps, int depth) { - if (name == NULL) return False; + if (name == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_unistr3"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("uni_str_len", ps, depth, &(name->uni_str_len)); + if(!prs_uint32("uni_str_len", ps, depth, &name->uni_str_len)) + return False; /* don't know if len is specified by uni_str_len member... */ /* assume unicode string is unicode-null-terminated, instead */ - prs_unistr3(True, "unistr", name, ps, depth); + if(!prs_unistr3(True, "unistr", name, ps, depth)) + return False; return True; } - diff --git a/source3/rpc_parse/parse_net.c b/source3/rpc_parse/parse_net.c index 277c2331b4..9588d1c53b 100644 --- a/source3/rpc_parse/parse_net.c +++ b/source3/rpc_parse/parse_net.c @@ -27,26 +27,31 @@ extern int DEBUGLEVEL; /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -static BOOL net_io_neg_flags(char *desc, NEG_FLAGS *neg, prs_struct *ps, int depth) + +static BOOL net_io_neg_flags(char *desc, NEG_FLAGS *neg, prs_struct *ps, int depth) { - if (neg == NULL) return False; + if (neg == NULL) + return False; prs_debug(ps, depth, desc, "net_io_neg_flags"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("neg_flags", ps, depth, &(neg->neg_flags)); + if(!prs_uint32("neg_flags", ps, depth, &neg->neg_flags)) + return False; return True; } /******************************************************************* -creates a NETLOGON_INFO_3 structure. + Inits a NETLOGON_INFO_3 structure. ********************************************************************/ -static BOOL make_netinfo_3(NETLOGON_INFO_3 *info, uint32 flags, uint32 logon_attempts) + +static void init_netinfo_3(NETLOGON_INFO_3 *info, uint32 flags, uint32 logon_attempts) { info->flags = flags; info->logon_attempts = logon_attempts; @@ -55,67 +60,80 @@ static BOOL make_netinfo_3(NETLOGON_INFO_3 *info, uint32 flags, uint32 logon_att info->reserved_3 = 0x0; info->reserved_4 = 0x0; info->reserved_5 = 0x0; - - return True; } /******************************************************************* -reads or writes a NETLOGON_INFO_3 structure. + Reads or writes a NETLOGON_INFO_3 structure. ********************************************************************/ + static BOOL net_io_netinfo_3(char *desc, NETLOGON_INFO_3 *info, prs_struct *ps, int depth) { - if (info == NULL) return False; + if (info == NULL) + return False; prs_debug(ps, depth, desc, "net_io_netinfo_3"); depth++; - prs_align(ps); - - prs_uint32("flags ", ps, depth, &(info->flags )); - prs_uint32("logon_attempts", ps, depth, &(info->logon_attempts)); - prs_uint32("reserved_1 ", ps, depth, &(info->reserved_1 )); - prs_uint32("reserved_2 ", ps, depth, &(info->reserved_2 )); - prs_uint32("reserved_3 ", ps, depth, &(info->reserved_3 )); - prs_uint32("reserved_4 ", ps, depth, &(info->reserved_4 )); - prs_uint32("reserved_5 ", ps, depth, &(info->reserved_5 )); + if(!prs_align(ps)) + return False; + + if(!prs_uint32("flags ", ps, depth, &info->flags)) + return False; + if(!prs_uint32("logon_attempts", ps, depth, &info->logon_attempts)) + return False; + if(!prs_uint32("reserved_1 ", ps, depth, &info->reserved_1)) + return False; + if(!prs_uint32("reserved_2 ", ps, depth, &info->reserved_2)) + return False; + if(!prs_uint32("reserved_3 ", ps, depth, &info->reserved_3)) + return False; + if(!prs_uint32("reserved_4 ", ps, depth, &info->reserved_4)) + return False; + if(!prs_uint32("reserved_5 ", ps, depth, &info->reserved_5)) + return False; return True; } /******************************************************************* -creates a NETLOGON_INFO_1 structure. + Inits a NETLOGON_INFO_1 structure. ********************************************************************/ -static BOOL make_netinfo_1(NETLOGON_INFO_1 *info, uint32 flags, uint32 pdc_status) + +static void init_netinfo_1(NETLOGON_INFO_1 *info, uint32 flags, uint32 pdc_status) { info->flags = flags; info->pdc_status = pdc_status; - - return True; } /******************************************************************* -reads or writes a NETLOGON_INFO_1 structure. + Reads or writes a NETLOGON_INFO_1 structure. ********************************************************************/ -static BOOL net_io_netinfo_1(char *desc, NETLOGON_INFO_1 *info, prs_struct *ps, int depth) + +static BOOL net_io_netinfo_1(char *desc, NETLOGON_INFO_1 *info, prs_struct *ps, int depth) { - if (info == NULL) return False; + if (info == NULL) + return False; prs_debug(ps, depth, desc, "net_io_netinfo_1"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("flags ", ps, depth, &(info->flags )); - prs_uint32("pdc_status", ps, depth, &(info->pdc_status)); + if(!prs_uint32("flags ", ps, depth, &info->flags)) + return False; + if(!prs_uint32("pdc_status", ps, depth, &info->pdc_status)) + return False; return True; } /******************************************************************* -creates a NETLOGON_INFO_2 structure. + Inits a NETLOGON_INFO_2 structure. ********************************************************************/ -static BOOL make_netinfo_2(NETLOGON_INFO_2 *info, uint32 flags, uint32 pdc_status, + +static void init_netinfo_2(NETLOGON_INFO_2 *info, uint32 flags, uint32 pdc_status, uint32 tc_status, char *trusted_dc_name) { int len_dc_name = strlen(trusted_dc_name); @@ -125,544 +143,499 @@ static BOOL make_netinfo_2(NETLOGON_INFO_2 *info, uint32 flags, uint32 pdc_statu info->tc_status = tc_status; if (trusted_dc_name != NULL) - { - make_unistr2(&(info->uni_trusted_dc_name), trusted_dc_name, len_dc_name+1); - } + init_unistr2(&(info->uni_trusted_dc_name), trusted_dc_name, len_dc_name+1); else - { - make_unistr2(&(info->uni_trusted_dc_name), "", 1); - } - - return True; + init_unistr2(&(info->uni_trusted_dc_name), "", 1); } /******************************************************************* -reads or writes a NETLOGON_INFO_2 structure. + Reads or writes a NETLOGON_INFO_2 structure. ********************************************************************/ -static BOOL net_io_netinfo_2(char *desc, NETLOGON_INFO_2 *info, prs_struct *ps, int depth) + +static BOOL net_io_netinfo_2(char *desc, NETLOGON_INFO_2 *info, prs_struct *ps, int depth) { - if (info == NULL) return False; + if (info == NULL) + return False; prs_debug(ps, depth, desc, "net_io_netinfo_2"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("flags ", ps, depth, &(info->flags )); - prs_uint32("pdc_status ", ps, depth, &(info->pdc_status )); - prs_uint32("ptr_trusted_dc_name", ps, depth, &(info->ptr_trusted_dc_name)); - prs_uint32("tc_status ", ps, depth, &(info->tc_status )); - - if (info->ptr_trusted_dc_name != 0) - { - smb_io_unistr2("unistr2", &(info->uni_trusted_dc_name), info->ptr_trusted_dc_name, ps, depth); + if(!prs_uint32("flags ", ps, depth, &info->flags)) + return False; + if(!prs_uint32("pdc_status ", ps, depth, &info->pdc_status)) + return False; + if(!prs_uint32("ptr_trusted_dc_name", ps, depth, &info->ptr_trusted_dc_name)) + return False; + if(!prs_uint32("tc_status ", ps, depth, &info->tc_status)) + return False; + + if (info->ptr_trusted_dc_name != 0) { + if(!smb_io_unistr2("unistr2", &info->uni_trusted_dc_name, info->ptr_trusted_dc_name, ps, depth)) + return False; } - prs_align(ps); + if(!prs_align(ps)) + return False; return True; } /******************************************************************* -makes an NET_Q_LOGON_CTRL2 structure. + Reads or writes an NET_Q_LOGON_CTRL2 structure. ********************************************************************/ -BOOL make_q_logon_ctrl2(NET_Q_LOGON_CTRL2 *q_l, - const char* srv_name, - uint32 function_code, - uint32 query_level, - uint32 switch_value) -{ - if (q_l == NULL) return False; - - DEBUG(5,("make_q_logon_ctrl2\n")); - - q_l->ptr = 1; - - make_unistr2(&(q_l->uni_server_name ), srv_name , strlen(srv_name )+1); - q_l->function_code = function_code; - q_l->query_level = query_level; - q_l->switch_value = switch_value; - - return True; -} - -/******************************************************************* -reads or writes an NET_Q_LOGON_CTRL2 structure. -********************************************************************/ -BOOL net_io_q_logon_ctrl2(char *desc, NET_Q_LOGON_CTRL2 *q_l, prs_struct *ps, int depth) +BOOL net_io_q_logon_ctrl2(char *desc, NET_Q_LOGON_CTRL2 *q_l, prs_struct *ps, int depth) { - if (q_l == NULL) return False; + if (q_l == NULL) + return False; prs_debug(ps, depth, desc, "net_io_q_logon_ctrl2"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr ", ps, depth, &(q_l->ptr )); + if(!prs_uint32("ptr ", ps, depth, &q_l->ptr)) + return False; - smb_io_unistr2 ("", &(q_l->uni_server_name), q_l->ptr, ps, depth); + if(!smb_io_unistr2 ("", &q_l->uni_server_name, q_l->ptr, ps, depth)) + return False; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("function_code", ps, depth, &(q_l->function_code)); - prs_uint32("query_level ", ps, depth, &(q_l->query_level )); - prs_uint32("switch_value ", ps, depth, &(q_l->switch_value )); + if(!prs_uint32("function_code", ps, depth, &q_l->function_code)) + return False; + if(!prs_uint32("query_level ", ps, depth, &q_l->query_level)) + return False; + if(!prs_uint32("switch_value ", ps, depth, &q_l->switch_value)) + return False; return True; } /******************************************************************* -makes an NET_R_LOGON_CTRL2 structure. + Inits an NET_R_LOGON_CTRL2 structure. ********************************************************************/ -BOOL make_r_logon_ctrl2(NET_R_LOGON_CTRL2 *r_l, uint32 query_level, + +void init_r_logon_ctrl2(NET_R_LOGON_CTRL2 *r_l, uint32 query_level, uint32 flags, uint32 pdc_status, uint32 logon_attempts, uint32 tc_status, char *trusted_domain_name) { - if (r_l == NULL) return False; - DEBUG(5,("make_r_logon_ctrl2\n")); r_l->switch_value = query_level; /* should only be 0x1 */ - switch (query_level) - { - case 1: - { - r_l->ptr = 1; /* undocumented pointer */ - make_netinfo_1(&(r_l->logon.info1), flags, pdc_status); - r_l->status = 0; - - break; - } - case 2: - { - r_l->ptr = 1; /* undocumented pointer */ - make_netinfo_2(&(r_l->logon.info2), flags, pdc_status, - tc_status, trusted_domain_name); - r_l->status = 0; - - break; - } - case 3: - { - r_l->ptr = 1; /* undocumented pointer */ - make_netinfo_3(&(r_l->logon.info3), flags, logon_attempts); - r_l->status = 0; - - break; - } - default: - { - DEBUG(2,("make_r_logon_ctrl2: unsupported switch value %d\n", - r_l->switch_value)); - r_l->ptr = 0; /* undocumented pointer */ - - /* take a guess at an error code... */ - r_l->status = NT_STATUS_INVALID_INFO_CLASS; - - break; - } + switch (query_level) { + case 1: + r_l->ptr = 1; /* undocumented pointer */ + init_netinfo_1(&r_l->logon.info1, flags, pdc_status); + r_l->status = 0; + break; + case 2: + r_l->ptr = 1; /* undocumented pointer */ + init_netinfo_2(&r_l->logon.info2, flags, pdc_status, + tc_status, trusted_domain_name); + r_l->status = 0; + break; + case 3: + r_l->ptr = 1; /* undocumented pointer */ + init_netinfo_3(&(r_l->logon.info3), flags, logon_attempts); + r_l->status = 0; + break; + default: + DEBUG(2,("init_r_logon_ctrl2: unsupported switch value %d\n", + r_l->switch_value)); + r_l->ptr = 0; /* undocumented pointer */ + + /* take a guess at an error code... */ + r_l->status = NT_STATUS_INVALID_INFO_CLASS; + break; } - - return True; } /******************************************************************* -reads or writes an NET_R_LOGON_CTRL2 structure. + Reads or writes an NET_R_LOGON_CTRL2 structure. ********************************************************************/ -BOOL net_io_r_logon_ctrl2(char *desc, NET_R_LOGON_CTRL2 *r_l, prs_struct *ps, int depth) + +BOOL net_io_r_logon_ctrl2(char *desc, NET_R_LOGON_CTRL2 *r_l, prs_struct *ps, int depth) { - if (r_l == NULL) return False; + if (r_l == NULL) + return False; prs_debug(ps, depth, desc, "net_io_r_logon_ctrl2"); depth++; - prs_uint32("switch_value ", ps, depth, &(r_l->switch_value )); - prs_uint32("ptr ", ps, depth, &(r_l->ptr )); - - if (r_l->ptr != 0) - { - switch (r_l->switch_value) - { - case 1: - { - net_io_netinfo_1("", &(r_l->logon.info1), ps, depth); - break; - } - case 2: - { - net_io_netinfo_2("", &(r_l->logon.info2), ps, depth); - break; - } - case 3: - { - net_io_netinfo_3("", &(r_l->logon.info3), ps, depth); - break; - } - default: - { - DEBUG(2,("net_io_r_logon_ctrl2: unsupported switch value %d\n", - r_l->switch_value)); - break; - } + if(!prs_uint32("switch_value ", ps, depth, &r_l->switch_value)) + return False; + if(!prs_uint32("ptr ", ps, depth, &r_l->ptr)) + return False; + + if (r_l->ptr != 0) { + switch (r_l->switch_value) { + case 1: + if(!net_io_netinfo_1("", &r_l->logon.info1, ps, depth)) + return False; + break; + case 2: + if(!net_io_netinfo_2("", &r_l->logon.info2, ps, depth)) + return False; + break; + case 3: + if(!net_io_netinfo_3("", &r_l->logon.info3, ps, depth)) + return False; + break; + default: + DEBUG(2,("net_io_r_logon_ctrl2: unsupported switch value %d\n", + r_l->switch_value)); + break; } } - prs_uint32("status ", ps, depth, &(r_l->status )); + if(!prs_uint32("status ", ps, depth, &r_l->status)) + return False; return True; } /******************************************************************* -makes an NET_R_TRUST_DOM_LIST structure. + Inits an NET_R_TRUST_DOM_LIST structure. ********************************************************************/ -BOOL make_r_trust_dom(NET_R_TRUST_DOM_LIST *r_t, - uint32 num_doms, char **dom_name) + +void init_r_trust_dom(NET_R_TRUST_DOM_LIST *r_t, + uint32 num_doms, char *dom_name) { - if (r_t == NULL) return False; + int i = 0; DEBUG(5,("make_r_trust_dom\n")); - make_buffer2_multi(&r_t->uni_trust_dom_name, - dom_name, num_doms); - if (num_doms == 0) - { - r_t->uni_trust_dom_name.buf_max_len = 0x2; - r_t->uni_trust_dom_name.buf_len = 0x2; + for (i = 0; i < MAX_TRUST_DOMS; i++) { + r_t->uni_trust_dom_name[i].uni_str_len = 0; + r_t->uni_trust_dom_name[i].uni_max_len = 0; + } + if (num_doms > MAX_TRUST_DOMS) + num_doms = MAX_TRUST_DOMS; + + for (i = 0; i < num_doms; i++) { + fstring domain_name; + fstrcpy(domain_name, dom_name); + strupper(domain_name); + init_unistr2(&r_t->uni_trust_dom_name[i], domain_name, strlen(domain_name)+1); + /* the use of UNISTR2 here is non-standard. */ + r_t->uni_trust_dom_name[i].undoc = 0x1; } - r_t->uni_trust_dom_name.undoc = 0x1; r_t->status = 0; - - return True; } /******************************************************************* -reads or writes an NET_R_TRUST_DOM_LIST structure. + Reads or writes an NET_R_TRUST_DOM_LIST structure. ********************************************************************/ -BOOL net_io_r_trust_dom(char *desc, NET_R_TRUST_DOM_LIST *r_t, prs_struct *ps, int depth) + +BOOL net_io_r_trust_dom(char *desc, NET_R_TRUST_DOM_LIST *r_t, prs_struct *ps, int depth) { - if (r_t == NULL) return False; + int i; + if (r_t == NULL) + return False; prs_debug(ps, depth, desc, "net_io_r_trust_dom"); depth++; - smb_io_buffer2("", &r_t->uni_trust_dom_name, True, ps, depth); - prs_align(ps); + for (i = 0; i < MAX_TRUST_DOMS; i++) { + if (r_t->uni_trust_dom_name[i].uni_str_len == 0) + break; + if(!smb_io_unistr2("", &r_t->uni_trust_dom_name[i], True, ps, depth)) + return False; + } - prs_uint32("status", ps, depth, &(r_t->status)); + if(!prs_uint32("status", ps, depth, &r_t->status)) + return False; return True; } /******************************************************************* -reads or writes an NET_Q_TRUST_DOM_LIST structure. + Reads or writes an NET_Q_TRUST_DOM_LIST structure. ********************************************************************/ -BOOL net_io_q_trust_dom(char *desc, NET_Q_TRUST_DOM_LIST *q_l, prs_struct *ps, int depth) + +BOOL net_io_q_trust_dom(char *desc, NET_Q_TRUST_DOM_LIST *q_l, prs_struct *ps, int depth) { - if (q_l == NULL) return False; + if (q_l == NULL) + return False; prs_debug(ps, depth, desc, "net_io_q_trust_dom"); depth++; - prs_uint32("ptr", ps, depth, &(q_l->ptr)); - smb_io_unistr2 ("name", &(q_l->uni_server_name), q_l->ptr, ps, depth); + if(!prs_uint32("ptr ", ps, depth, &q_l->ptr)) + return False; + if(!smb_io_unistr2 ("", &q_l->uni_server_name, q_l->ptr, ps, depth)) + return False; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("function_code", ps, depth, &(q_l->function_code)); + if(!prs_uint32("function_code", ps, depth, &q_l->function_code)) + return False; return True; } /******************************************************************* -makes an NET_Q_REQ_CHAL structure. + Inits an NET_Q_REQ_CHAL structure. ********************************************************************/ -BOOL make_q_req_chal(NET_Q_REQ_CHAL *q_c, - const char *logon_srv, const char *logon_clnt, + +void init_q_req_chal(NET_Q_REQ_CHAL *q_c, + char *logon_srv, char *logon_clnt, DOM_CHAL *clnt_chal) { - if (q_c == NULL) return False; - DEBUG(5,("make_q_req_chal: %d\n", __LINE__)); q_c->undoc_buffer = 1; /* don't know what this buffer is */ - make_unistr2(&(q_c->uni_logon_srv ), logon_srv , strlen(logon_srv )+1); - make_unistr2(&(q_c->uni_logon_clnt), logon_clnt, strlen(logon_clnt)+1); + init_unistr2(&q_c->uni_logon_srv, logon_srv , strlen(logon_srv )+1); + init_unistr2(&q_c->uni_logon_clnt, logon_clnt, strlen(logon_clnt)+1); memcpy(q_c->clnt_chal.data, clnt_chal->data, sizeof(clnt_chal->data)); DEBUG(5,("make_q_req_chal: %d\n", __LINE__)); - - return True; } /******************************************************************* -reads or writes an NET_Q_REQ_CHAL structure. + Reads or writes an NET_Q_REQ_CHAL structure. ********************************************************************/ + BOOL net_io_q_req_chal(char *desc, NET_Q_REQ_CHAL *q_c, prs_struct *ps, int depth) { int old_align; - if (q_c == NULL) return False; + + if (q_c == NULL) + return False; prs_debug(ps, depth, desc, "net_io_q_req_chal"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("undoc_buffer", ps, depth, &(q_c->undoc_buffer)); + if(!prs_uint32("undoc_buffer", ps, depth, &q_c->undoc_buffer)) + return False; - smb_io_unistr2("", &(q_c->uni_logon_srv ), True, ps, depth); /* logon server unicode string */ - smb_io_unistr2("", &(q_c->uni_logon_clnt), True, ps, depth); /* logon client unicode string */ + if(!smb_io_unistr2("", &q_c->uni_logon_srv, True, ps, depth)) /* logon server unicode string */ + return False; + if(!smb_io_unistr2("", &q_c->uni_logon_clnt, True, ps, depth)) /* logon client unicode string */ + return False; old_align = ps->align; ps->align = 0; /* client challenge is _not_ aligned after the unicode strings */ - smb_io_chal("", &(q_c->clnt_chal), ps, depth); /* client challenge */ + if(!smb_io_chal("", &q_c->clnt_chal, ps, depth)) { + /* client challenge */ + ps->align = old_align; + return False; + } ps->align = old_align; return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL net_io_r_req_chal(char *desc, NET_R_REQ_CHAL *r_c, prs_struct *ps, int depth) + +BOOL net_io_r_req_chal(char *desc, NET_R_REQ_CHAL *r_c, prs_struct *ps, int depth) { - if (r_c == NULL) return False; + if (r_c == NULL) + return False; prs_debug(ps, depth, desc, "net_io_r_req_chal"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_chal("", &(r_c->srv_chal), ps, depth); /* server challenge */ + if(!smb_io_chal("", &r_c->srv_chal, ps, depth)) /* server challenge */ + return False; - prs_uint32("status", ps, depth, &(r_c->status)); + if(!prs_uint32("status", ps, depth, &r_c->status)) + return False; return True; } -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL make_q_auth(NET_Q_AUTH *q_a, - const char *logon_srv, const char *acct_name, - uint16 sec_chan, const char *comp_name, - DOM_CHAL *clnt_chal) -{ - if (q_a == NULL) return False; - - DEBUG(5,("make_q_auth: %d\n", __LINE__)); - - make_log_info(&(q_a->clnt_id), logon_srv, acct_name, sec_chan, comp_name); - memcpy(q_a->clnt_chal.data, clnt_chal->data, sizeof(clnt_chal->data)); - - DEBUG(5,("make_q_auth: %d\n", __LINE__)); - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL net_io_q_auth(char *desc, NET_Q_AUTH *q_a, prs_struct *ps, int depth) -{ - int old_align; - if (q_a == NULL) return False; - - prs_debug(ps, depth, desc, "net_io_q_auth"); - depth++; - - prs_align(ps); - - smb_io_log_info ("", &(q_a->clnt_id), ps, depth); /* client identification info */ - /* client challenge is _not_ aligned */ - old_align = ps->align; - ps->align = 0; - smb_io_chal ("", &(q_a->clnt_chal), ps, depth); /* client-calculated credentials */ - ps->align = old_align; - - return True; -} /******************************************************************* -reads or writes a structure. + Inits a NET_Q_AUTH_2 struct. ********************************************************************/ -BOOL net_io_r_auth(char *desc, NET_R_AUTH *r_a, prs_struct *ps, int depth) -{ - if (r_a == NULL) return False; - - prs_debug(ps, depth, desc, "net_io_r_auth"); - depth++; - - prs_align(ps); - - smb_io_chal ("", &(r_a->srv_chal), ps, depth); /* server challenge */ - prs_uint32("status", ps, depth, &(r_a->status)); - - return True; -} -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL make_q_auth_2(NET_Q_AUTH_2 *q_a, - const char *logon_srv, const char *acct_name, - uint16 sec_chan, const char *comp_name, +void init_q_auth_2(NET_Q_AUTH_2 *q_a, + char *logon_srv, char *acct_name, uint16 sec_chan, char *comp_name, DOM_CHAL *clnt_chal, uint32 clnt_flgs) { - if (q_a == NULL) return False; - - DEBUG(5,("make_q_auth_2: %d\n", __LINE__)); + DEBUG(5,("init_q_auth_2: %d\n", __LINE__)); - make_log_info(&(q_a->clnt_id), logon_srv, acct_name, sec_chan, comp_name); + init_log_info(&q_a->clnt_id, logon_srv, acct_name, sec_chan, comp_name); memcpy(q_a->clnt_chal.data, clnt_chal->data, sizeof(clnt_chal->data)); q_a->clnt_flgs.neg_flags = clnt_flgs; - DEBUG(5,("make_q_auth_2: %d\n", __LINE__)); - - return True; + DEBUG(5,("init_q_auth_2: %d\n", __LINE__)); } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL net_io_q_auth_2(char *desc, NET_Q_AUTH_2 *q_a, prs_struct *ps, int depth) + +BOOL net_io_q_auth_2(char *desc, NET_Q_AUTH_2 *q_a, prs_struct *ps, int depth) { int old_align; - if (q_a == NULL) return False; + if (q_a == NULL) + return False; prs_debug(ps, depth, desc, "net_io_q_auth_2"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_log_info ("", &(q_a->clnt_id), ps, depth); /* client identification info */ + if(!smb_io_log_info ("", &q_a->clnt_id, ps, depth)) /* client identification info */ + return False; /* client challenge is _not_ aligned */ old_align = ps->align; ps->align = 0; - smb_io_chal ("", &(q_a->clnt_chal), ps, depth); /* client-calculated credentials */ + if(!smb_io_chal("", &q_a->clnt_chal, ps, depth)) { + /* client-calculated credentials */ + ps->align = old_align; + return False; + } ps->align = old_align; - net_io_neg_flags("", &(q_a->clnt_flgs), ps, depth); + if(!net_io_neg_flags("", &q_a->clnt_flgs, ps, depth)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL net_io_r_auth_2(char *desc, NET_R_AUTH_2 *r_a, prs_struct *ps, int depth) + +BOOL net_io_r_auth_2(char *desc, NET_R_AUTH_2 *r_a, prs_struct *ps, int depth) { - if (r_a == NULL) return False; + if (r_a == NULL) + return False; prs_debug(ps, depth, desc, "net_io_r_auth_2"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_chal ("", &(r_a->srv_chal), ps, depth); /* server challenge */ - net_io_neg_flags("", &(r_a->srv_flgs), ps, depth); + if(!smb_io_chal("", &r_a->srv_chal, ps, depth)) /* server challenge */ + return False; + if(!net_io_neg_flags("", &r_a->srv_flgs, ps, depth)) + return False; - prs_uint32("status", ps, depth, &(r_a->status)); + if(!prs_uint32("status", ps, depth, &r_a->status)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Inits a NET_Q_SRV_PWSET. ********************************************************************/ -BOOL make_q_srv_pwset(NET_Q_SRV_PWSET *q_s, - const char *logon_srv, const char *acct_name, - uint16 sec_chan, const char *comp_name, - DOM_CRED *cred, char nt_cypher[16]) -{ - if (q_s == NULL || cred == NULL) return False; +void init_q_srv_pwset(NET_Q_SRV_PWSET *q_s, char *logon_srv, char *acct_name, + uint16 sec_chan, char *comp_name, DOM_CRED *cred, char nt_cypher[16]) +{ DEBUG(5,("make_q_srv_pwset\n")); - make_clnt_info(&(q_s->clnt_id), logon_srv, acct_name, sec_chan, comp_name, cred); + init_clnt_info(&q_s->clnt_id, logon_srv, acct_name, sec_chan, comp_name, cred); memcpy(q_s->pwd, nt_cypher, sizeof(q_s->pwd)); - - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL net_io_q_srv_pwset(char *desc, NET_Q_SRV_PWSET *q_s, prs_struct *ps, int depth) + +BOOL net_io_q_srv_pwset(char *desc, NET_Q_SRV_PWSET *q_s, prs_struct *ps, int depth) { - if (q_s == NULL) return False; + if (q_s == NULL) + return False; prs_debug(ps, depth, desc, "net_io_q_srv_pwset"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_clnt_info("", &(q_s->clnt_id), ps, depth); /* client identification/authentication info */ - prs_uint8s (False, "pwd", ps, depth, q_s->pwd, 16); /* new password - undocumented */ + if(!smb_io_clnt_info("", &q_s->clnt_id, ps, depth)) /* client identification/authentication info */ + return False; + if(!prs_uint8s (False, "pwd", ps, depth, q_s->pwd, 16)) /* new password - undocumented */ + return False; return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL net_io_r_srv_pwset(char *desc, NET_R_SRV_PWSET *r_s, prs_struct *ps, int depth) + +BOOL net_io_r_srv_pwset(char *desc, NET_R_SRV_PWSET *r_s, prs_struct *ps, int depth) { - if (r_s == NULL) return False; + if (r_s == NULL) + return False; prs_debug(ps, depth, desc, "net_io_r_srv_pwset"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_cred("", &(r_s->srv_cred), ps, depth); /* server challenge */ + if(!smb_io_cred("", &r_s->srv_cred, ps, depth)) /* server challenge */ + return False; - prs_uint32("status", ps, depth, &(r_s->status)); + if(!prs_uint32("status", ps, depth, &r_s->status)) + return False; return True; } - /************************************************************************* - make DOM_SID2 array from a string containing multiple sids + Init DOM_SID2 array from a string containing multiple sids *************************************************************************/ -static int make_dom_sid2s(char *sids_str, DOM_SID2 *sids, int max_sids) + +static int init_dom_sid2s(char *sids_str, DOM_SID2 *sids, int max_sids) { char *ptr; pstring s2; - int count; + int count = 0; - DEBUG(4,("make_dom_sid2s: %s\n", sids_str ? sids_str:"")); + DEBUG(4,("init_dom_sid2s: %s\n", sids_str ? sids_str:"")); - if (sids_str == NULL || *sids_str == 0) return 0; - - for (count = 0, ptr = sids_str; - next_token(&ptr, s2, NULL, sizeof(s2)) && count < max_sids; - count++) - { - DOM_SID tmpsid; - string_to_sid(&tmpsid, s2); - make_dom_sid2(&sids[count], &tmpsid); + if(sids_str) { + for (count = 0, ptr = sids_str; + next_token(&ptr, s2, NULL, sizeof(s2)) && count < max_sids; count++) { + DOM_SID tmpsid; + string_to_sid(&tmpsid, s2); + init_dom_sid2(&sids[count], &tmpsid); + } } return count; - - return True; } /******************************************************************* -makes a NET_ID_INFO_1 structure. + Inits a NET_ID_INFO_1 structure. ********************************************************************/ -BOOL make_id_info1(NET_ID_INFO_1 *id, const char *domain_name, + +void init_id_info1(NET_ID_INFO_1 *id, char *domain_name, uint32 param_ctrl, uint32 log_id_low, uint32 log_id_high, - const char *user_name, const char *wksta_name, + char *user_name, char *wksta_name, char sess_key[16], unsigned char lm_cypher[16], unsigned char nt_cypher[16]) { @@ -673,30 +646,26 @@ BOOL make_id_info1(NET_ID_INFO_1 *id, const char *domain_name, unsigned char lm_owf[16]; unsigned char nt_owf[16]; - if (id == NULL) return False; - DEBUG(5,("make_id_info1: %d\n", __LINE__)); id->ptr_id_info1 = 1; - make_uni_hdr(&(id->hdr_domain_name), len_domain_name); + init_uni_hdr(&id->hdr_domain_name, len_domain_name); id->param_ctrl = param_ctrl; - id->logon_id.low = log_id_low; - id->logon_id.high = log_id_high; + init_logon_id(&id->logon_id, log_id_low, log_id_high); - make_uni_hdr(&(id->hdr_user_name ), len_user_name ); - make_uni_hdr(&(id->hdr_wksta_name ), len_wksta_name ); + init_uni_hdr(&id->hdr_user_name, len_user_name); + init_uni_hdr(&id->hdr_wksta_name, len_wksta_name); - if (lm_cypher && nt_cypher) - { + if (lm_cypher && nt_cypher) { unsigned char key[16]; #ifdef DEBUG_PASSWORD DEBUG(100,("lm cypher:")); - dump_data(100, lm_cypher, 16); + dump_data(100, (char *)lm_cypher, 16); DEBUG(100,("nt cypher:")); - dump_data(100, nt_cypher, 16); + dump_data(100, (char *)nt_cypher, 16); #endif memset(key, 0, 16); @@ -709,63 +678,77 @@ BOOL make_id_info1(NET_ID_INFO_1 *id, const char *domain_name, #ifdef DEBUG_PASSWORD DEBUG(100,("encrypt of lm owf password:")); - dump_data(100, lm_owf, 16); + dump_data(100, (char *)lm_owf, 16); DEBUG(100,("encrypt of nt owf password:")); - dump_data(100, nt_owf, 16); + dump_data(100, (char *)nt_owf, 16); #endif /* set up pointers to cypher blocks */ lm_cypher = lm_owf; nt_cypher = nt_owf; } - make_owf_info(&(id->lm_owf), lm_cypher); - make_owf_info(&(id->nt_owf), nt_cypher); - - make_unistr2(&(id->uni_domain_name), domain_name, len_domain_name); - make_unistr2(&(id->uni_user_name ), user_name , len_user_name ); - make_unistr2(&(id->uni_wksta_name ), wksta_name , len_wksta_name ); + init_owf_info(&id->lm_owf, lm_cypher); + init_owf_info(&id->nt_owf, nt_cypher); - return True; + init_unistr2(&id->uni_domain_name, domain_name, len_domain_name); + init_unistr2(&id->uni_user_name, user_name, len_user_name); + init_unistr2(&id->uni_wksta_name, wksta_name, len_wksta_name); } /******************************************************************* -reads or writes an NET_ID_INFO_1 structure. + Reads or writes an NET_ID_INFO_1 structure. ********************************************************************/ + static BOOL net_io_id_info1(char *desc, NET_ID_INFO_1 *id, prs_struct *ps, int depth) { - if (id == NULL) return False; + if (id == NULL) + return False; prs_debug(ps, depth, desc, "net_io_id_info1"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr_id_info1", ps, depth, &(id->ptr_id_info1)); + if(!prs_uint32("ptr_id_info1", ps, depth, &id->ptr_id_info1)) + return False; - if (id->ptr_id_info1 != 0) - { - smb_io_unihdr("unihdr", &(id->hdr_domain_name), ps, depth); + if (id->ptr_id_info1 != 0) { + if(!smb_io_unihdr("unihdr", &id->hdr_domain_name, ps, depth)) + return False; - prs_uint32("param_ctrl", ps, depth, &(id->param_ctrl)); - smb_io_bigint("", &(id->logon_id), ps, depth); + if(!prs_uint32("param_ctrl", ps, depth, &id->param_ctrl)) + return False; + if(!smb_io_logon_id("", &id->logon_id, ps, depth)) + return False; - smb_io_unihdr("unihdr", &(id->hdr_user_name ), ps, depth); - smb_io_unihdr("unihdr", &(id->hdr_wksta_name ), ps, depth); + if(!smb_io_unihdr("unihdr", &id->hdr_user_name, ps, depth)) + return False; + if(!smb_io_unihdr("unihdr", &id->hdr_wksta_name, ps, depth)) + return False; - smb_io_owf_info("", &(id->lm_owf), ps, depth); - smb_io_owf_info("", &(id->nt_owf), ps, depth); + if(!smb_io_owf_info("", &id->lm_owf, ps, depth)) + return False; + if(!smb_io_owf_info("", &id->nt_owf, ps, depth)) + return False; - smb_io_unistr2("unistr2", &(id->uni_domain_name), id->hdr_domain_name.buffer, ps, depth); - smb_io_unistr2("unistr2", &(id->uni_user_name ), id->hdr_user_name.buffer, ps, depth); - smb_io_unistr2("unistr2", &(id->uni_wksta_name ), id->hdr_wksta_name.buffer, ps, depth); + if(!smb_io_unistr2("unistr2", &id->uni_domain_name, + id->hdr_domain_name.buffer, ps, depth)) + return False; + if(!smb_io_unistr2("unistr2", &id->uni_user_name, + id->hdr_user_name.buffer, ps, depth)) + return False; + if(!smb_io_unistr2("unistr2", &id->uni_wksta_name, + id->hdr_wksta_name.buffer, ps, depth)) + return False; } return True; } /******************************************************************* -makes a NET_ID_INFO_2 structure. +Inits a NET_ID_INFO_2 structure. This is a network logon packet. The log_id parameters are what an NT server would generate for LUID once the @@ -779,10 +762,9 @@ checking for a logon as it doesn't export the password hashes to anyone who has compromised the secure channel. JRA. ********************************************************************/ -BOOL make_id_info2(NET_ID_INFO_2 *id, const char *domain_name, - uint32 param_ctrl, - uint32 log_id_low, uint32 log_id_high, - const char *user_name, const char *wksta_name, +void init_id_info2(NET_ID_INFO_2 *id, char *domain_name, + uint32 param_ctrl, uint32 log_id_low, uint32 log_id_high, + char *user_name, char *wksta_name, unsigned char lm_challenge[8], unsigned char lm_chal_resp[24], unsigned char nt_chal_resp[24]) @@ -790,87 +772,101 @@ BOOL make_id_info2(NET_ID_INFO_2 *id, const char *domain_name, int len_domain_name = strlen(domain_name); int len_user_name = strlen(user_name ); int len_wksta_name = strlen(wksta_name ); - int nt_chal_resp_len = ((nt_chal_resp != NULL) ? 24 : 0); + int nt_chal_resp_len = ((nt_chal_resp != NULL) ? 24 : 0); int lm_chal_resp_len = ((lm_chal_resp != NULL) ? 24 : 0); unsigned char lm_owf[24]; unsigned char nt_owf[24]; - if (id == NULL) return False; - - DEBUG(5,("make_id_info2: %d\n", __LINE__)); + DEBUG(5,("init_id_info2: %d\n", __LINE__)); id->ptr_id_info2 = 1; - make_uni_hdr(&(id->hdr_domain_name), len_domain_name); + init_uni_hdr(&id->hdr_domain_name, len_domain_name); id->param_ctrl = param_ctrl; - id->logon_id.low = log_id_low; - id->logon_id.high = log_id_high; + init_logon_id(&id->logon_id, log_id_low, log_id_high); - make_uni_hdr(&(id->hdr_user_name ), len_user_name ); - make_uni_hdr(&(id->hdr_wksta_name ), len_wksta_name ); + init_uni_hdr(&id->hdr_user_name, len_user_name); + init_uni_hdr(&id->hdr_wksta_name, len_wksta_name); - if (nt_chal_resp) - { + if (nt_chal_resp) { /* oops. can only send what-ever-it-is direct */ memcpy(nt_owf, nt_chal_resp, 24); nt_chal_resp = nt_owf; } - if (lm_chal_resp) - { + if (lm_chal_resp) { /* oops. can only send what-ever-it-is direct */ memcpy(lm_owf, lm_chal_resp, 24); lm_chal_resp = lm_owf; } memcpy(id->lm_chal, lm_challenge, sizeof(id->lm_chal)); - make_str_hdr(&(id->hdr_nt_chal_resp), 24, nt_chal_resp_len, nt_chal_resp != NULL ? 1 : 0); - make_str_hdr(&(id->hdr_lm_chal_resp), 24, lm_chal_resp_len, lm_chal_resp != NULL ? 1 : 0); - - make_unistr2(&(id->uni_domain_name), domain_name, len_domain_name); - make_unistr2(&(id->uni_user_name ), user_name , len_user_name ); - make_unistr2(&(id->uni_wksta_name ), wksta_name , len_wksta_name ); + init_str_hdr(&id->hdr_nt_chal_resp, 24, nt_chal_resp_len, (nt_chal_resp != NULL) ? 1 : 0); + init_str_hdr(&id->hdr_lm_chal_resp, 24, lm_chal_resp_len, (lm_chal_resp != NULL) ? 1 : 0); - make_string2(&(id->nt_chal_resp ), (char *)nt_chal_resp , nt_chal_resp_len); - make_string2(&(id->lm_chal_resp ), (char *)lm_chal_resp , lm_chal_resp_len); + init_unistr2(&id->uni_domain_name, domain_name, len_domain_name); + init_unistr2(&id->uni_user_name, user_name, len_user_name); + init_unistr2(&id->uni_wksta_name, wksta_name, len_wksta_name); - return True; + init_string2(&id->nt_chal_resp, (char *)nt_chal_resp, nt_chal_resp_len); + init_string2(&id->lm_chal_resp, (char *)lm_chal_resp, lm_chal_resp_len); } /******************************************************************* -reads or writes an NET_ID_INFO_2 structure. + Reads or writes an NET_ID_INFO_2 structure. ********************************************************************/ + static BOOL net_io_id_info2(char *desc, NET_ID_INFO_2 *id, prs_struct *ps, int depth) { - if (id == NULL) return False; + if (id == NULL) + return False; prs_debug(ps, depth, desc, "net_io_id_info2"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr_id_info2", ps, depth, &(id->ptr_id_info2)); + if(!prs_uint32("ptr_id_info2", ps, depth, &id->ptr_id_info2)) + return False; - if (id->ptr_id_info2 != 0) - { - smb_io_unihdr("unihdr", &(id->hdr_domain_name), ps, depth); + if (id->ptr_id_info2 != 0) { + if(!smb_io_unihdr("unihdr", &id->hdr_domain_name, ps, depth)) + return False; - prs_uint32("param_ctrl", ps, depth, &(id->param_ctrl)); - smb_io_bigint("", &(id->logon_id), ps, depth); + if(!prs_uint32("param_ctrl", ps, depth, &id->param_ctrl)) + return False; + if(!smb_io_logon_id("", &id->logon_id, ps, depth)) + return False; - smb_io_unihdr("unihdr", &(id->hdr_user_name ), ps, depth); - smb_io_unihdr("unihdr", &(id->hdr_wksta_name ), ps, depth); + if(!smb_io_unihdr("unihdr", &id->hdr_user_name, ps, depth)) + return False; + if(!smb_io_unihdr("unihdr", &id->hdr_wksta_name, ps, depth)) + return False; - prs_uint8s (False, "lm_chal", ps, depth, id->lm_chal, 8); /* lm 8 byte challenge */ + if(!prs_uint8s (False, "lm_chal", ps, depth, id->lm_chal, 8)) /* lm 8 byte challenge */ + return False; - smb_io_strhdr("hdr_nt_chal_resp", &(id->hdr_nt_chal_resp ), ps, depth); - smb_io_strhdr("hdr_lm_chal_resp", &(id->hdr_lm_chal_resp ), ps, depth); + if(!smb_io_strhdr("hdr_nt_chal_resp", &id->hdr_nt_chal_resp, ps, depth)) + return False; + if(!smb_io_strhdr("hdr_lm_chal_resp", &id->hdr_lm_chal_resp, ps, depth)) + return False; - smb_io_unistr2("uni_domain_name", &(id->uni_domain_name), id->hdr_domain_name .buffer, ps, depth); - smb_io_unistr2("uni_user_name ", &(id->uni_user_name ), id->hdr_user_name .buffer, ps, depth); - smb_io_unistr2("uni_wksta_name ", &(id->uni_wksta_name ), id->hdr_wksta_name .buffer, ps, depth); - smb_io_string2("nt_chal_resp" , &(id->nt_chal_resp) , id->hdr_nt_chal_resp.buffer, ps, depth); - smb_io_string2("lm_chal_resp" , &(id->lm_chal_resp) , id->hdr_lm_chal_resp.buffer, ps, depth); + if(!smb_io_unistr2("uni_domain_name", &id->uni_domain_name, + id->hdr_domain_name.buffer, ps, depth)) + return False; + if(!smb_io_unistr2("uni_user_name ", &id->uni_user_name, + id->hdr_user_name.buffer, ps, depth)) + return False; + if(!smb_io_unistr2("uni_wksta_name ", &id->uni_wksta_name, + id->hdr_wksta_name.buffer, ps, depth)) + return False; + if(!smb_io_string2("nt_chal_resp", &id->nt_chal_resp, + id->hdr_nt_chal_resp.buffer, ps, depth)) + return False; + if(!smb_io_string2("lm_chal_resp", &id->lm_chal_resp, + id->hdr_lm_chal_resp.buffer, ps, depth)) + return False; } return True; @@ -878,104 +874,103 @@ static BOOL net_io_id_info2(char *desc, NET_ID_INFO_2 *id, prs_struct *ps, int /******************************************************************* -makes a DOM_SAM_INFO structure. + Inits a DOM_SAM_INFO structure. ********************************************************************/ -BOOL make_sam_info(DOM_SAM_INFO *sam, - const char *logon_srv, const char *comp_name, - DOM_CRED *clnt_cred, + +void init_sam_info(DOM_SAM_INFO *sam, + char *logon_srv, char *comp_name, DOM_CRED *clnt_cred, DOM_CRED *rtn_cred, uint16 logon_level, NET_ID_INFO_CTR *ctr) { - if (sam == NULL) return False; - - DEBUG(5,("make_sam_info: %d\n", __LINE__)); + DEBUG(5,("init_sam_info: %d\n", __LINE__)); - make_clnt_info2(&(sam->client), logon_srv, comp_name, clnt_cred); + init_clnt_info2(&(sam->client), logon_srv, comp_name, clnt_cred); - if (rtn_cred != NULL) - { + if (rtn_cred != NULL) { sam->ptr_rtn_cred = 1; - memcpy(&(sam->rtn_cred), rtn_cred, sizeof(sam->rtn_cred)); - } - else - { + memcpy(&sam->rtn_cred, rtn_cred, sizeof(sam->rtn_cred)); + } else { sam->ptr_rtn_cred = 0; } sam->logon_level = logon_level; sam->ctr = ctr; - - return True; } /******************************************************************* -reads or writes a DOM_SAM_INFO structure. + Reads or writes a DOM_SAM_INFO structure. ********************************************************************/ -static BOOL net_io_id_info_ctr(char *desc, NET_ID_INFO_CTR *ctr, prs_struct *ps, int depth) + +static BOOL net_io_id_info_ctr(char *desc, NET_ID_INFO_CTR *ctr, prs_struct *ps, int depth) { - if (ctr == NULL) return False; + if (ctr == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_sam_info"); depth++; /* don't 4-byte align here! */ - prs_uint16("switch_value ", ps, depth, &(ctr->switch_value)); + if(!prs_uint16("switch_value ", ps, depth, &ctr->switch_value)) + return False; - switch (ctr->switch_value) - { - case 1: - { - net_io_id_info1("", &(ctr->auth.id1), ps, depth); - break; - } - case 2: - { - net_io_id_info2("", &(ctr->auth.id2), ps, depth); - break; - } - default: - { - /* PANIC! */ - DEBUG(4,("smb_io_sam_info: unknown switch_value!\n")); - break; - } + switch (ctr->switch_value) { + case 1: + if(!net_io_id_info1("", &ctr->auth.id1, ps, depth)) + return False; + break; + case 2: + if(!net_io_id_info2("", &ctr->auth.id2, ps, depth)) + return False; + break; + default: + /* PANIC! */ + DEBUG(4,("smb_io_sam_info: unknown switch_value!\n")); + break; } return True; } /******************************************************************* -reads or writes a DOM_SAM_INFO structure. -********************************************************************/ -static BOOL smb_io_sam_info(char *desc, DOM_SAM_INFO *sam, prs_struct *ps, int depth) + Reads or writes a DOM_SAM_INFO structure. + ********************************************************************/ + +static BOOL smb_io_sam_info(char *desc, DOM_SAM_INFO *sam, prs_struct *ps, int depth) { - if (sam == NULL) return False; + if (sam == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_sam_info"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_clnt_info2("", &(sam->client ), ps, depth); + if(!smb_io_clnt_info2("", &sam->client, ps, depth)) + return False; - prs_uint32("ptr_rtn_cred ", ps, depth, &(sam->ptr_rtn_cred)); - smb_io_cred ("", &(sam->rtn_cred), ps, depth); + if(!prs_uint32("ptr_rtn_cred ", ps, depth, &sam->ptr_rtn_cred)) + return False; + if(!smb_io_cred("", &sam->rtn_cred, ps, depth)) + return False; - prs_uint16("logon_level ", ps, depth, &(sam->logon_level )); + if(!prs_uint16("logon_level ", ps, depth, &sam->logon_level)) + return False; - if (sam->logon_level != 0 && sam->ctr != NULL) - { - net_io_id_info_ctr("logon_info", sam->ctr, ps, depth); + if (sam->logon_level != 0 && sam->ctr != NULL) { + if(!net_io_id_info_ctr("logon_info", sam->ctr, ps, depth)) + return False; } return True; } /************************************************************************* - make_net_user_info3 + Init *************************************************************************/ -BOOL make_net_user_info3(NET_USER_INFO_3 *usr, + +void init_net_user_info3(NET_USER_INFO_3 *usr, NTTIME *logon_time, NTTIME *logoff_time, @@ -1010,7 +1005,7 @@ BOOL make_net_user_info3(NET_USER_INFO_3 *usr, { /* only cope with one "other" sid, right now. */ /* need to count the number of space-delimited sids */ - uint32 i; + int i; int num_other_sids = 0; int len_user_name = strlen(user_name ); @@ -1023,6 +1018,8 @@ BOOL make_net_user_info3(NET_USER_INFO_3 *usr, int len_logon_srv = strlen(logon_srv); int len_logon_dom = strlen(logon_dom); + memset(usr, '\0', sizeof(*usr)); + usr->ptr_user_info = 1; /* yes, we're bothering to put USER_INFO data here */ usr->logon_time = *logon_time; @@ -1032,12 +1029,12 @@ BOOL make_net_user_info3(NET_USER_INFO_3 *usr, usr->pass_can_change_time = *pass_can_change_time; usr->pass_must_change_time = *pass_must_change_time; - make_uni_hdr(&(usr->hdr_user_name ), len_user_name ); - make_uni_hdr(&(usr->hdr_full_name ), len_full_name ); - make_uni_hdr(&(usr->hdr_logon_script), len_logon_script); - make_uni_hdr(&(usr->hdr_profile_path), len_profile_path); - make_uni_hdr(&(usr->hdr_home_dir ), len_home_dir ); - make_uni_hdr(&(usr->hdr_dir_drive ), len_dir_drive ); + init_uni_hdr(&usr->hdr_user_name, len_user_name); + init_uni_hdr(&usr->hdr_full_name, len_full_name); + init_uni_hdr(&usr->hdr_logon_script, len_logon_script); + init_uni_hdr(&usr->hdr_profile_path, len_profile_path); + init_uni_hdr(&usr->hdr_home_dir, len_home_dir); + init_uni_hdr(&usr->hdr_dir_drive, len_dir_drive); usr->logon_count = logon_count; usr->bad_pw_count = bad_pw_count; @@ -1049,835 +1046,274 @@ BOOL make_net_user_info3(NET_USER_INFO_3 *usr, usr->user_flgs = user_flgs; if (sess_key != NULL) - { memcpy(usr->user_sess_key, sess_key, sizeof(usr->user_sess_key)); - } else - { - bzero(usr->user_sess_key, sizeof(usr->user_sess_key)); - } + memset((char *)usr->user_sess_key, '\0', sizeof(usr->user_sess_key)); - make_uni_hdr(&(usr->hdr_logon_srv), len_logon_srv); - make_uni_hdr(&(usr->hdr_logon_dom), len_logon_dom); + init_uni_hdr(&usr->hdr_logon_srv, len_logon_srv); + init_uni_hdr(&usr->hdr_logon_dom, len_logon_dom); usr->buffer_dom_id = dom_sid ? 1 : 0; /* yes, we're bothering to put a domain SID in */ - bzero(usr->padding, sizeof(usr->padding)); + memset((char *)usr->padding, '\0', sizeof(usr->padding)); - num_other_sids = make_dom_sid2s(other_sids, usr->other_sids, LSA_MAX_SIDS); + num_other_sids = init_dom_sid2s(other_sids, usr->other_sids, LSA_MAX_SIDS); usr->num_other_sids = num_other_sids; - usr->buffer_other_sids = num_other_sids != 0 ? 1 : 0; + usr->buffer_other_sids = (num_other_sids != 0) ? 1 : 0; - make_unistr2(&(usr->uni_user_name ), user_name , len_user_name ); - make_unistr2(&(usr->uni_full_name ), full_name , len_full_name ); - make_unistr2(&(usr->uni_logon_script), logon_script, len_logon_script); - make_unistr2(&(usr->uni_profile_path), profile_path, len_profile_path); - make_unistr2(&(usr->uni_home_dir ), home_dir , len_home_dir ); - make_unistr2(&(usr->uni_dir_drive ), dir_drive , len_dir_drive ); + init_unistr2(&usr->uni_user_name, user_name, len_user_name); + init_unistr2(&usr->uni_full_name, full_name, len_full_name); + init_unistr2(&usr->uni_logon_script, logon_script, len_logon_script); + init_unistr2(&usr->uni_profile_path, profile_path, len_profile_path); + init_unistr2(&usr->uni_home_dir, home_dir, len_home_dir); + init_unistr2(&usr->uni_dir_drive, dir_drive, len_dir_drive); usr->num_groups2 = num_groups; SMB_ASSERT_ARRAY(usr->gids, num_groups); for (i = 0; i < num_groups; i++) - { usr->gids[i] = gids[i]; - } - make_unistr2(&(usr->uni_logon_srv), logon_srv, len_logon_srv); - make_unistr2(&(usr->uni_logon_dom), logon_dom, len_logon_dom); + init_unistr2(&usr->uni_logon_srv, logon_srv, len_logon_srv); + init_unistr2(&usr->uni_logon_dom, logon_dom, len_logon_dom); - make_dom_sid2(&(usr->dom_sid), dom_sid); + init_dom_sid2(&usr->dom_sid, dom_sid); /* "other" sids are set up above */ - - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -static BOOL net_io_user_info3(char *desc, NET_USER_INFO_3 *usr, prs_struct *ps, int depth) + +static BOOL net_io_user_info3(char *desc, NET_USER_INFO_3 *usr, prs_struct *ps, int depth) { - uint32 i; + int i; - if (usr == NULL) return False; + if (usr == NULL) + return False; prs_debug(ps, depth, desc, "lsa_io_lsa_user_info"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr_user_info ", ps, depth, &(usr->ptr_user_info)); - - if (usr->ptr_user_info != 0) - { - smb_io_time("time", &(usr->logon_time) , ps, depth); /* logon time */ - smb_io_time("time", &(usr->logoff_time) , ps, depth); /* logoff time */ - smb_io_time("time", &(usr->kickoff_time) , ps, depth); /* kickoff time */ - smb_io_time("time", &(usr->pass_last_set_time) , ps, depth); /* password last set time */ - smb_io_time("time", &(usr->pass_can_change_time) , ps, depth); /* password can change time */ - smb_io_time("time", &(usr->pass_must_change_time), ps, depth); /* password must change time */ - - smb_io_unihdr("unihdr", &(usr->hdr_user_name) , ps, depth); /* username unicode string header */ - smb_io_unihdr("unihdr", &(usr->hdr_full_name) , ps, depth); /* user's full name unicode string header */ - smb_io_unihdr("unihdr", &(usr->hdr_logon_script), ps, depth); /* logon script unicode string header */ - smb_io_unihdr("unihdr", &(usr->hdr_profile_path), ps, depth); /* profile path unicode string header */ - smb_io_unihdr("unihdr", &(usr->hdr_home_dir) , ps, depth); /* home directory unicode string header */ - smb_io_unihdr("unihdr", &(usr->hdr_dir_drive) , ps, depth); /* home directory drive unicode string header */ - - prs_uint16("logon_count ", ps, depth, &(usr->logon_count )); /* logon count */ - prs_uint16("bad_pw_count ", ps, depth, &(usr->bad_pw_count)); /* bad password count */ - - prs_uint32("user_id ", ps, depth, &(usr->user_id )); /* User ID */ - prs_uint32("group_id ", ps, depth, &(usr->group_id )); /* Group ID */ - prs_uint32("num_groups ", ps, depth, &(usr->num_groups )); /* num groups */ - prs_uint32("buffer_groups ", ps, depth, &(usr->buffer_groups)); /* undocumented buffer pointer to groups. */ - prs_uint32("user_flgs ", ps, depth, &(usr->user_flgs )); /* user flags */ - - prs_uint8s (False, "user_sess_key", ps, depth, usr->user_sess_key, 16); /* unused user session key */ - - smb_io_unihdr("unihdr", &(usr->hdr_logon_srv), ps, depth); /* logon server unicode string header */ - smb_io_unihdr("unihdr", &(usr->hdr_logon_dom), ps, depth); /* logon domain unicode string header */ - - prs_uint32("buffer_dom_id ", ps, depth, &(usr->buffer_dom_id)); /* undocumented logon domain id pointer */ - prs_uint8s (False, "padding ", ps, depth, usr->padding, 40); /* unused padding bytes? */ - - prs_uint32("num_other_sids", ps, depth, &(usr->num_other_sids)); /* 0 - num_sids */ - prs_uint32("buffer_other_sids", ps, depth, &(usr->buffer_other_sids)); /* NULL - undocumented pointer to SIDs. */ + if(!prs_uint32("ptr_user_info ", ps, depth, &usr->ptr_user_info)) + return False; + + if (usr->ptr_user_info == 0) + return True; + + if(!smb_io_time("time", &usr->logon_time, ps, depth)) /* logon time */ + return False; + if(!smb_io_time("time", &usr->logoff_time, ps, depth)) /* logoff time */ + return False; + if(!smb_io_time("time", &usr->kickoff_time, ps, depth)) /* kickoff time */ + return False; + if(!smb_io_time("time", &usr->pass_last_set_time, ps, depth)) /* password last set time */ + return False; + if(!smb_io_time("time", &usr->pass_can_change_time , ps, depth)) /* password can change time */ + return False; + if(!smb_io_time("time", &usr->pass_must_change_time, ps, depth)) /* password must change time */ + return False; + + if(!smb_io_unihdr("unihdr", &usr->hdr_user_name, ps, depth)) /* username unicode string header */ + return False; + if(!smb_io_unihdr("unihdr", &usr->hdr_full_name, ps, depth)) /* user's full name unicode string header */ + return False; + if(!smb_io_unihdr("unihdr", &usr->hdr_logon_script, ps, depth)) /* logon script unicode string header */ + return False; + if(!smb_io_unihdr("unihdr", &usr->hdr_profile_path, ps, depth)) /* profile path unicode string header */ + return False; + if(!smb_io_unihdr("unihdr", &usr->hdr_home_dir, ps, depth)) /* home directory unicode string header */ + return False; + if(!smb_io_unihdr("unihdr", &usr->hdr_dir_drive, ps, depth)) /* home directory drive unicode string header */ + return False; + + if(!prs_uint16("logon_count ", ps, depth, &usr->logon_count)) /* logon count */ + return False; + if(!prs_uint16("bad_pw_count ", ps, depth, &usr->bad_pw_count)) /* bad password count */ + return False; + + if(!prs_uint32("user_id ", ps, depth, &usr->user_id)) /* User ID */ + return False; + if(!prs_uint32("group_id ", ps, depth, &usr->group_id)) /* Group ID */ + return False; + if(!prs_uint32("num_groups ", ps, depth, &usr->num_groups)) /* num groups */ + return False; + if(!prs_uint32("buffer_groups ", ps, depth, &usr->buffer_groups)) /* undocumented buffer pointer to groups. */ + return False; + if(!prs_uint32("user_flgs ", ps, depth, &usr->user_flgs)) /* user flags */ + return False; + + if(!prs_uint8s(False, "user_sess_key", ps, depth, usr->user_sess_key, 16)) /* unused user session key */ + return False; + + if(!smb_io_unihdr("unihdr", &usr->hdr_logon_srv, ps, depth)) /* logon server unicode string header */ + return False; + if(!smb_io_unihdr("unihdr", &usr->hdr_logon_dom, ps, depth)) /* logon domain unicode string header */ + return False; + + if(!prs_uint32("buffer_dom_id ", ps, depth, &usr->buffer_dom_id)) /* undocumented logon domain id pointer */ + return False; + if(!prs_uint8s (False, "padding ", ps, depth, usr->padding, 40)) /* unused padding bytes? */ + return False; + + if(!prs_uint32("num_other_sids", ps, depth, &usr->num_other_sids)) /* 0 - num_sids */ + return False; + if(!prs_uint32("buffer_other_sids", ps, depth, &usr->buffer_other_sids)) /* NULL - undocumented pointer to SIDs. */ + return False; - smb_io_unistr2("unistr2", &(usr->uni_user_name) , usr->hdr_user_name .buffer, ps, depth); /* username unicode string */ - smb_io_unistr2("unistr2", &(usr->uni_full_name) , usr->hdr_full_name .buffer, ps, depth); /* user's full name unicode string */ - smb_io_unistr2("unistr2", &(usr->uni_logon_script), usr->hdr_logon_script.buffer, ps, depth); /* logon script unicode string */ - smb_io_unistr2("unistr2", &(usr->uni_profile_path), usr->hdr_profile_path.buffer, ps, depth); /* profile path unicode string */ - smb_io_unistr2("unistr2", &(usr->uni_home_dir) , usr->hdr_home_dir .buffer, ps, depth); /* home directory unicode string */ - smb_io_unistr2("unistr2", &(usr->uni_dir_drive) , usr->hdr_dir_drive .buffer, ps, depth); /* home directory drive unicode string */ - - prs_align(ps); - prs_uint32("num_groups2 ", ps, depth, &(usr->num_groups2)); /* num groups */ - SMB_ASSERT_ARRAY(usr->gids, usr->num_groups2); - for (i = 0; i < usr->num_groups2; i++) - { - smb_io_gid("", &(usr->gids[i]), ps, depth); /* group info */ - } + if(!smb_io_unistr2("unistr2", &usr->uni_user_name, usr->hdr_user_name.buffer, ps, depth)) /* username unicode string */ + return False; + if(!smb_io_unistr2("unistr2", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth)) /* user's full name unicode string */ + return False; + if(!smb_io_unistr2("unistr2", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth)) /* logon script unicode string */ + return False; + if(!smb_io_unistr2("unistr2", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth)) /* profile path unicode string */ + return False; + if(!smb_io_unistr2("unistr2", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth)) /* home directory unicode string */ + return False; + if(!smb_io_unistr2("unistr2", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth)) /* home directory drive unicode string */ + return False; + + if(!prs_align(ps)) + return False; + if(!prs_uint32("num_groups2 ", ps, depth, &usr->num_groups2)) /* num groups */ + return False; + SMB_ASSERT_ARRAY(usr->gids, usr->num_groups2); + for (i = 0; i < usr->num_groups2; i++) { + if(!smb_io_gid("", &usr->gids[i], ps, depth)) /* group info */ + return False; + } - smb_io_unistr2("unistr2", &( usr->uni_logon_srv), usr->hdr_logon_srv.buffer, ps, depth); /* logon server unicode string */ - smb_io_unistr2("unistr2", &( usr->uni_logon_dom), usr->hdr_logon_srv.buffer, ps, depth); /* logon domain unicode string */ + if(!smb_io_unistr2("unistr2", &usr->uni_logon_srv, usr->hdr_logon_srv.buffer, ps, depth)) /* logon server unicode string */ + return False; + if(!smb_io_unistr2("unistr2", &usr->uni_logon_dom, usr->hdr_logon_srv.buffer, ps, depth)) /* logon domain unicode string */ + return False; - smb_io_dom_sid2("", &(usr->dom_sid), ps, depth); /* domain SID */ + if(!smb_io_dom_sid2("", &usr->dom_sid, ps, depth)) /* domain SID */ + return False; - SMB_ASSERT_ARRAY(usr->other_sids, usr->num_other_sids); + SMB_ASSERT_ARRAY(usr->other_sids, usr->num_other_sids); - for (i = 0; i < usr->num_other_sids; i++) - { - smb_io_dom_sid2("", &(usr->other_sids[i]), ps, depth); /* other domain SIDs */ - } + for (i = 0; i < usr->num_other_sids; i++) { + if(!smb_io_dom_sid2("", &usr->other_sids[i], ps, depth)) /* other domain SIDs */ + return False; } return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL net_io_q_sam_logon(char *desc, NET_Q_SAM_LOGON *q_l, prs_struct *ps, int depth) + +BOOL net_io_q_sam_logon(char *desc, NET_Q_SAM_LOGON *q_l, prs_struct *ps, int depth) { - if (q_l == NULL) return False; + if (q_l == NULL) + return False; prs_debug(ps, depth, desc, "net_io_q_sam_logon"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_sam_info("", &(q_l->sam_id), ps, depth); /* domain SID */ - prs_uint16("validation_level", ps, depth, &(q_l->validation_level)); + if(!smb_io_sam_info("", &q_l->sam_id, ps, depth)) /* domain SID */ + return False; + if(!prs_uint16("validation_level", ps, depth, &q_l->validation_level)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL net_io_r_sam_logon(char *desc, NET_R_SAM_LOGON *r_l, prs_struct *ps, int depth) + +BOOL net_io_r_sam_logon(char *desc, NET_R_SAM_LOGON *r_l, prs_struct *ps, int depth) { - if (r_l == NULL) return False; + if (r_l == NULL) + return False; prs_debug(ps, depth, desc, "net_io_r_sam_logon"); depth++; - prs_uint32("buffer_creds", ps, depth, &(r_l->buffer_creds)); /* undocumented buffer pointer */ - smb_io_cred("", &(r_l->srv_creds), ps, depth); /* server credentials. server time stamp appears to be ignored. */ + if(!prs_uint32("buffer_creds", ps, depth, &r_l->buffer_creds)) /* undocumented buffer pointer */ + return False; + if(!smb_io_cred("", &r_l->srv_creds, ps, depth)) /* server credentials. server time stamp appears to be ignored. */ + return False; - prs_uint16("switch_value", ps, depth, &(r_l->switch_value)); - prs_align(ps); + if(!prs_uint16("switch_value", ps, depth, &r_l->switch_value)) + return False; + if(!prs_align(ps)) + return False; - if (r_l->switch_value != 0) - { - net_io_user_info3("", r_l->user, ps, depth); + if (r_l->switch_value != 0) { + if(!net_io_user_info3("", r_l->user, ps, depth)) + return False; } - prs_uint32("auth_resp ", ps, depth, &(r_l->auth_resp)); /* 1 - Authoritative response; 0 - Non-Auth? */ + if(!prs_uint32("auth_resp ", ps, depth, &r_l->auth_resp)) /* 1 - Authoritative response; 0 - Non-Auth? */ + return False; - prs_uint32("status ", ps, depth, &(r_l->status)); + if(!prs_uint32("status ", ps, depth, &r_l->status)) + return False; - prs_align(ps); + if(!prs_align(ps)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ + BOOL net_io_q_sam_logoff(char *desc, NET_Q_SAM_LOGOFF *q_l, prs_struct *ps, int depth) { - if (q_l == NULL) return False; + if (q_l == NULL) + return False; prs_debug(ps, depth, desc, "net_io_q_sam_logoff"); depth++; - prs_align(ps); - - smb_io_sam_info("", &(q_l->sam_id), ps, depth); /* domain SID */ - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL net_io_r_sam_logoff(char *desc, NET_R_SAM_LOGOFF *r_l, prs_struct *ps, int depth) -{ - if (r_l == NULL) return False; - - prs_debug(ps, depth, desc, "net_io_r_sam_logoff"); - depth++; - - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("buffer_creds", ps, depth, &(r_l->buffer_creds)); /* undocumented buffer pointer */ - smb_io_cred("", &(r_l->srv_creds), ps, depth); /* server credentials. server time stamp appears to be ignored. */ - - prs_uint32("status ", ps, depth, &(r_l->status)); + if(!smb_io_sam_info("", &q_l->sam_id, ps, depth)) /* domain SID */ + return False; return True; } /******************************************************************* -makes a NET_Q_SAM_SYNC structure. + Reads or writes a structure. ********************************************************************/ -BOOL make_q_sam_sync(NET_Q_SAM_SYNC *q_s, - const char *srv_name, - const char *cli_name, - DOM_CRED *cli_creds, uint32 database_id) -{ - if (q_s == NULL) return False; - - DEBUG(5,("make_q_sam_sync\n")); - - make_unistr2(&(q_s->uni_srv_name), srv_name, strlen(srv_name)+1); - make_unistr2(&(q_s->uni_cli_name), cli_name, strlen(cli_name)+1); - - memcpy(&(q_s->cli_creds), cli_creds, sizeof(q_s->cli_creds)); - memset(&(q_s->ret_creds), 0, sizeof(q_s->ret_creds)); - q_s->database_id = database_id; - q_s->restart_state = 0; - q_s->sync_context = 0; - q_s->max_size = 0xffff; - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL net_io_q_sam_sync(char *desc, NET_Q_SAM_SYNC *q_s, prs_struct *ps, int depth) +BOOL net_io_r_sam_logoff(char *desc, NET_R_SAM_LOGOFF *r_l, prs_struct *ps, int depth) { - if (q_s == NULL) return False; - - prs_debug(ps, depth, desc, "net_io_q_sam_sync"); - depth++; - - smb_io_unistr2("", &(q_s->uni_srv_name), True, ps, depth); - smb_io_unistr2("", &(q_s->uni_cli_name), True, ps, depth); - - smb_io_cred("", &(q_s->cli_creds), ps, depth); - smb_io_cred("", &(q_s->ret_creds), ps, depth); - - prs_uint32("database_id ", ps, depth, &(q_s->database_id )); - prs_uint32("restart_state", ps, depth, &(q_s->restart_state)); - prs_uint32("sync_context ", ps, depth, &(q_s->sync_context )); - - prs_uint32("max_size", ps, depth, &(q_s->max_size)); - - return True; -} - -/******************************************************************* -makes a SAM_DELTA_HDR structure. -********************************************************************/ -BOOL make_sam_delta_hdr(SAM_DELTA_HDR *delta, uint16 type, uint32 rid) -{ - if (delta == NULL) return False; - - DEBUG(5,("make_sam_delta_hdr\n")); - - delta->type2 = delta->type = type; - delta->target_rid = rid; - - delta->type3 = type; - delta->ptr_delta = 1; - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -static BOOL net_io_sam_delta_hdr(char *desc, SAM_DELTA_HDR *delta, prs_struct *ps, int depth) -{ - if (delta == NULL) return False; - - prs_debug(ps, depth, desc, "net_io_sam_delta_hdr"); - depth++; - - prs_uint16("type", ps, depth, &(delta->type )); - prs_uint16("type2", ps, depth, &(delta->type2 )); - prs_uint32("target_rid", ps, depth, &(delta->target_rid)); - - prs_uint32("type3", ps, depth, &(delta->type3 )); - prs_uint32("ptr_delta", ps, depth, &(delta->ptr_delta )); - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -static BOOL net_io_sam_domain_info(char *desc, SAM_DOMAIN_INFO *info, prs_struct *ps, int depth) -{ - if (info == NULL) return False; - - prs_debug(ps, depth, desc, "net_io_sam_domain_info"); - depth++; + if (r_l == NULL) + return False; - smb_io_unihdr("hdr_dom_name" , &(info->hdr_dom_name) , ps, depth); - smb_io_unihdr("hdr_oem_info" , &(info->hdr_oem_info) , ps, depth); - - smb_io_bigint("force_logoff" , &(info->force_logoff) , ps, depth); - prs_uint16("min_pwd_len" , ps, depth, &(info->min_pwd_len )); - prs_uint16("pwd_history_len" , ps, depth, &(info->pwd_history_len)); - smb_io_bigint("max_pwd_age" , &(info->max_pwd_age) , ps, depth); - smb_io_bigint("min_pwd_age" , &(info->min_pwd_age) , ps, depth); - smb_io_bigint("dom_mod_count", &(info->dom_mod_count), ps, depth); - smb_io_time("creation_time" , &(info->creation_time), ps, depth); - - smb_io_bufhdr2("hdr_sec_desc", &(info->hdr_sec_desc) , ps, depth); - smb_io_unihdr ("hdr_unknown" , &(info->hdr_unknown) , ps, depth); - ps->offset += 40; - - smb_io_unistr2("uni_dom_name", &(info->uni_dom_name), - info->hdr_dom_name.buffer, ps, depth); - smb_io_unistr2("buf_oem_info", &(info->buf_oem_info), - info->hdr_oem_info.buffer, ps, depth); - - smb_io_buffer4("buf_sec_desc", &(info->buf_sec_desc), - info->hdr_sec_desc.buffer, ps, depth); - smb_io_unistr2("buf_unknown" , &(info->buf_unknown ), - info->hdr_unknown .buffer, ps, depth); - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -static BOOL net_io_sam_group_info(char *desc, SAM_GROUP_INFO *info, prs_struct *ps, int depth) -{ - if (info == NULL) return False; - - prs_debug(ps, depth, desc, "net_io_sam_group_info"); - depth++; - - smb_io_unihdr ("hdr_grp_name", &(info->hdr_grp_name), ps, depth); - smb_io_gid ("gid", &(info->gid), ps, depth); - smb_io_unihdr ("hdr_grp_desc", &(info->hdr_grp_desc), ps, depth); - smb_io_bufhdr2("hdr_sec_desc", &(info->hdr_sec_desc), ps, depth); - ps->offset += 48; - - smb_io_unistr2("uni_grp_name", &(info->uni_grp_name), - info->hdr_grp_name.buffer, ps, depth); - smb_io_unistr2("uni_grp_desc", &(info->uni_grp_desc), - info->hdr_grp_desc.buffer, ps, depth); - smb_io_buffer4("buf_sec_desc", &(info->buf_sec_desc), - info->hdr_sec_desc.buffer, ps, depth); - - return True; -} - -/******************************************************************* -makes a SAM_ACCOUNT_INFO structure. -********************************************************************/ -BOOL make_sam_account_info(SAM_ACCOUNT_INFO *info, char *user_name, - char *full_name, uint32 user_rid, uint32 group_rid, - char *home_dir, char *dir_drive, char *logon_script, - char *acct_desc, uint32 acb_info, char *profile) -{ - int len_user_name = strlen(user_name); - int len_full_name = strlen(full_name); - int len_home_dir = strlen(home_dir); - int len_dir_drive = strlen(dir_drive); - int len_logon_script = strlen(logon_script); - int len_acct_desc = strlen(acct_desc); - int len_profile = strlen(profile); - - DEBUG(5,("make_sam_account_info\n")); - - make_uni_hdr(&(info->hdr_acct_name ), len_user_name ); - make_uni_hdr(&(info->hdr_full_name ), len_full_name ); - make_uni_hdr(&(info->hdr_home_dir ), len_home_dir ); - make_uni_hdr(&(info->hdr_dir_drive ), len_dir_drive ); - make_uni_hdr(&(info->hdr_logon_script), len_logon_script); - make_uni_hdr(&(info->hdr_acct_desc ), len_acct_desc ); - make_uni_hdr(&(info->hdr_profile ), len_profile ); - - /* not present */ - make_uni_hdr(&(info->hdr_workstations), 0); - make_uni_hdr(&(info->hdr_comment), 0); - make_uni_hdr(&(info->hdr_parameters), 0); - make_bufhdr2(&(info->hdr_sec_desc), 0, 0, 0); - - info->user_rid = user_rid; - info->group_rid = group_rid; - - init_nt_time(&(info->logon_time)); - init_nt_time(&(info->logoff_time)); - init_nt_time(&(info->pwd_last_set_time)); - init_nt_time(&(info->acct_expiry_time)); - - info->logon_divs = 0xA8; - info->ptr_logon_hrs = 0; /* Don't care right now */ - - info->bad_pwd_count = 0; - info->logon_count = 0; - info->acb_info = acb_info; - info->nt_pwd_present = 0; - info->lm_pwd_present = 0; - info->pwd_expired = 0; - info->country = 0; - info->codepage = 0; - - info->unknown1 = 0x4EC; - info->unknown2 = 0; - - make_unistr2(&(info->uni_acct_name), user_name, len_user_name+1); - make_unistr2(&(info->uni_full_name), full_name, len_full_name+1); - make_unistr2(&(info->uni_home_dir ), home_dir , len_home_dir +1); - make_unistr2(&(info->uni_dir_drive), dir_drive, len_dir_drive+1); - make_unistr2(&(info->uni_logon_script), logon_script, len_logon_script+1); - make_unistr2(&(info->uni_acct_desc), acct_desc, len_acct_desc+1); - make_unistr2(&(info->uni_profile ), profile , len_profile +1); - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -static BOOL net_io_sam_passwd_info(char *desc, SAM_PWD *pwd, - prs_struct *ps, int depth) -{ - if (pwd == NULL) return False; - - prs_debug(ps, depth, desc, "net_io_sam_passwd_info"); + prs_debug(ps, depth, desc, "net_io_r_sam_logoff"); depth++; - prs_uint32("unk_0 ", ps, depth, &(pwd->unk_0 )); - - smb_io_unihdr ("hdr_lm_pwd", &(pwd->hdr_lm_pwd), ps, depth); - prs_uint8s(False, "buf_lm_pwd", ps, depth, pwd->buf_lm_pwd, 16); + if(!prs_align(ps)) + return False; - smb_io_unihdr ("hdr_nt_pwd", &(pwd->hdr_nt_pwd), ps, depth); - prs_uint8s(False, "buf_nt_pwd", ps, depth, pwd->buf_nt_pwd, 16); - - smb_io_unihdr("", &(pwd->hdr_empty_lm), ps, depth); - smb_io_unihdr("", &(pwd->hdr_empty_nt), ps, depth); - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -static BOOL net_io_sam_account_info(char *desc, uint8 sess_key[16], - SAM_ACCOUNT_INFO *info, prs_struct *ps, int depth) -{ - BUFHDR2 hdr_priv_data; - uint32 i; - - if (info == NULL) return False; - - prs_debug(ps, depth, desc, "net_io_sam_account_info"); - depth++; - - smb_io_unihdr("hdr_acct_name", &(info->hdr_acct_name), ps, depth); - smb_io_unihdr("hdr_full_name", &(info->hdr_full_name), ps, depth); - - prs_uint32("user_rid ", ps, depth, &(info->user_rid )); - prs_uint32("group_rid", ps, depth, &(info->group_rid)); - - smb_io_unihdr("hdr_home_dir " , &(info->hdr_home_dir ), ps, depth); - smb_io_unihdr("hdr_dir_drive" , &(info->hdr_dir_drive), ps, depth); - smb_io_unihdr("hdr_logon_script", &(info->hdr_logon_script), ps, depth); - smb_io_unihdr("hdr_acct_desc" , &(info->hdr_acct_desc), ps, depth); - smb_io_unihdr("hdr_workstations", &(info->hdr_workstations), ps, depth); - - smb_io_time("logon_time" , &(info->logon_time ), ps, depth); - smb_io_time("logoff_time", &(info->logoff_time), ps, depth); - - prs_uint32("logon_divs ", ps, depth, &(info->logon_divs )); - prs_uint32("ptr_logon_hrs", ps, depth, &(info->ptr_logon_hrs)); - - prs_uint16("bad_pwd_count", ps, depth, &(info->bad_pwd_count)); - prs_uint16("logon_count" , ps, depth, &(info->logon_count )); - smb_io_time("pwd_last_set_time", &(info->pwd_last_set_time), ps, depth); - smb_io_time("acct_expiry_time" , &(info->acct_expiry_time ), ps, depth); - - prs_uint32("acb_info", ps, depth, &(info->acb_info)); - prs_uint8s(False, "nt_pwd", ps, depth, info->nt_pwd, 16); - prs_uint8s(False, "lm_pwd", ps, depth, info->lm_pwd, 16); - prs_uint8("lm_pwd_present", ps, depth, &(info->lm_pwd_present)); - prs_uint8("nt_pwd_present", ps, depth, &(info->nt_pwd_present)); - prs_uint8("pwd_expired" , ps, depth, &(info->pwd_expired )); - - smb_io_unihdr("hdr_comment" , &(info->hdr_comment ), ps, depth); - smb_io_unihdr("hdr_parameters", &(info->hdr_parameters), ps, depth); - prs_uint16("country" , ps, depth, &(info->country )); - prs_uint16("codepage", ps, depth, &(info->codepage)); - - smb_io_bufhdr2("hdr_priv_data", &(hdr_priv_data), ps, depth); - smb_io_bufhdr2("hdr_sec_desc" , &(info->hdr_sec_desc) , ps, depth); - smb_io_unihdr ("hdr_profile" , &(info->hdr_profile) , ps, depth); - - for (i = 0; i < 3; i++) - { - smb_io_unihdr("hdr_reserved", &(info->hdr_reserved[i]), ps, depth); - } - - for (i = 0; i < 4; i++) - { - prs_uint32("dw_reserved", ps, depth, &(info->dw_reserved[i])); - } - - smb_io_unistr2("uni_acct_name", &(info->uni_acct_name), - info->hdr_acct_name.buffer, ps, depth); - prs_align(ps); - smb_io_unistr2("uni_full_name", &(info->uni_full_name), - info->hdr_full_name.buffer, ps, depth); - prs_align(ps); - smb_io_unistr2("uni_home_dir ", &(info->uni_home_dir ), - info->hdr_home_dir .buffer, ps, depth); - prs_align(ps); - smb_io_unistr2("uni_dir_drive", &(info->uni_dir_drive), - info->hdr_dir_drive.buffer, ps, depth); - prs_align(ps); - smb_io_unistr2("uni_logon_script", &(info->uni_logon_script), - info->hdr_logon_script.buffer, ps, depth); - prs_align(ps); - smb_io_unistr2("uni_acct_desc", &(info->uni_acct_desc), - info->hdr_acct_desc.buffer, ps, depth); - prs_align(ps); - smb_io_unistr2("uni_workstations", &(info->uni_workstations), - info->hdr_workstations.buffer, ps, depth); - prs_align(ps); - - prs_uint32("unknown1", ps, depth, &(info->unknown1)); - prs_uint32("unknown2", ps, depth, &(info->unknown2)); - - smb_io_buffer4("buf_logon_hrs" , &(info->buf_logon_hrs ), - info->ptr_logon_hrs, ps, depth); - prs_align(ps); - smb_io_unistr2("uni_comment" , &(info->uni_comment ), - info->hdr_comment.buffer, ps, depth); - prs_align(ps); - smb_io_unistr2("uni_parameters", &(info->uni_parameters), - info->hdr_parameters.buffer, ps, depth); - prs_align(ps); - if (hdr_priv_data.buffer != 0) - { - int old_offset; - uint32 len = 0x44; - prs_uint32("pwd_len", ps, depth, &len); - old_offset = ps->offset; - if (len == 0x44) - { - if (ps->io) - { - /* reading */ - prs_hash1(ps, ps->offset, sess_key); - } - net_io_sam_passwd_info("pass", &(info->pass), ps, depth); - if (!ps->io) - { - /* writing */ - prs_hash1(ps, old_offset, sess_key); - } - } - ps->offset = old_offset + len; - } - smb_io_buffer4("buf_sec_desc" , &(info->buf_sec_desc ), - info->hdr_sec_desc.buffer, ps, depth); - prs_align(ps); - smb_io_unistr2("uni_profile" , &(info->uni_profile ), - info->hdr_profile.buffer, ps, depth); - prs_align(ps); - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -static BOOL net_io_sam_group_mem_info(char *desc, SAM_GROUP_MEM_INFO *info, prs_struct *ps, int depth) -{ - uint32 i; - fstring tmp; - - if (info == NULL) return False; - - prs_debug(ps, depth, desc, "net_io_sam_group_mem_info"); - depth++; - - prs_align(ps); - prs_uint32("ptr_rids ", ps, depth, &(info->ptr_rids )); - prs_uint32("ptr_attribs", ps, depth, &(info->ptr_attribs)); - prs_uint32("num_members", ps, depth, &(info->num_members)); - ps->offset += 16; - - if (info->ptr_rids != 0) - { - prs_uint32("num_members2", ps, depth, &(info->num_members2)); - if (info->num_members2 != info->num_members) - { - /* RPC fault */ - return False; - } - - SMB_ASSERT_ARRAY(info->rids, info->num_members2); - - for (i = 0; i < info->num_members2; i++) - { - slprintf(tmp, sizeof(tmp) - 1, "rids[%02d]", i); - prs_uint32(tmp, ps, depth, &(info->rids[i])); - } - } - - if (info->ptr_attribs != 0) - { - prs_uint32("num_members3", ps, depth, &(info->num_members3)); - if (info->num_members3 != info->num_members) - { - /* RPC fault */ - return False; - } - - SMB_ASSERT_ARRAY(info->attribs, info->num_members3); - - for (i = 0; i < info->num_members3; i++) - { - slprintf(tmp, sizeof(tmp) - 1, "attribs[%02d]", i); - prs_uint32(tmp, ps, depth, &(info->attribs[i])); - } - } - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -static BOOL net_io_sam_alias_info(char *desc, SAM_ALIAS_INFO *info, prs_struct *ps, int depth) -{ - if (info == NULL) return False; - - prs_debug(ps, depth, desc, "net_io_sam_alias_info"); - depth++; - - smb_io_unihdr ("hdr_als_name", &(info->hdr_als_name), ps, depth); - prs_uint32("als_rid", ps, depth, &(info->als_rid)); - smb_io_bufhdr2("hdr_sec_desc", &(info->hdr_sec_desc), ps, depth); - smb_io_unihdr ("hdr_als_desc", &(info->hdr_als_desc), ps, depth); - ps->offset += 40; - - smb_io_unistr2("uni_als_name", &(info->uni_als_name), - info->hdr_als_name.buffer, ps, depth); - smb_io_buffer4("buf_sec_desc", &(info->buf_sec_desc), - info->hdr_sec_desc.buffer, ps, depth); - smb_io_unistr2("uni_als_desc", &(info->uni_als_desc), - info->hdr_als_name.buffer, ps, depth); - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -static BOOL net_io_sam_alias_mem_info(char *desc, SAM_ALIAS_MEM_INFO *info, prs_struct *ps, int depth) -{ - uint32 i; - fstring tmp; - - if (info == NULL) return False; - - prs_debug(ps, depth, desc, "net_io_sam_alias_mem_info"); - depth++; - - prs_align(ps); - prs_uint32("num_members", ps, depth, &(info->num_members)); - prs_uint32("ptr_members", ps, depth, &(info->ptr_members)); - ps->offset += 16; - - if (info->ptr_members != 0) - { - prs_uint32("num_sids", ps, depth, &(info->num_sids)); - if (info->num_sids != info->num_members) - { - /* RPC fault */ - return False; - } - - SMB_ASSERT_ARRAY(info->ptr_sids, info->num_sids); - - for (i = 0; i < info->num_sids; i++) - { - slprintf(tmp, sizeof(tmp) - 1, "ptr_sids[%02d]", i); - prs_uint32(tmp, ps, depth, &(info->ptr_sids[i])); - } - - SMB_ASSERT_ARRAY(info->sids, info->num_sids); - - for (i = 0; i < info->num_sids; i++) - { - if (info->ptr_sids[i] != 0) - { - slprintf(tmp, sizeof(tmp) - 1, "sids[%02d]", i); - smb_io_dom_sid2(tmp, &(info->sids[i]), ps, depth); - } - } - } - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -static BOOL net_io_sam_delta_ctr(char *desc, uint8 sess_key[16], - SAM_DELTA_CTR *delta, uint16 type, - prs_struct *ps, int depth) -{ - if (delta == NULL) return False; - - prs_debug(ps, depth, desc, "net_io_sam_delta_ctr"); - depth++; - - switch (type) - { - case 1: - { - net_io_sam_domain_info("", &(delta->domain_info), - ps, depth); - break; - } - case 2: - { - net_io_sam_group_info("", &(delta->group_info), - ps, depth); - break; - } - case 5: - { - net_io_sam_account_info("", sess_key, - &(delta->account_info), - ps, depth); - break; - } - case 8: - { - net_io_sam_group_mem_info("", &(delta->grp_mem_info), - ps, depth); - break; - } - case 9: - { - net_io_sam_alias_info("", &(delta->alias_info), - ps, depth); - break; - } - case 0xC: - { - net_io_sam_alias_mem_info("", &(delta->als_mem_info), - ps, depth); - break; - } - default: - { - DEBUG(0, ("Replication error: Unknown delta type %x\n", type)); - break; - } - } - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL net_io_r_sam_sync(char *desc, uint8 sess_key[16], - NET_R_SAM_SYNC *r_s, prs_struct *ps, int depth) -{ - uint32 i; - - if (r_s == NULL) return False; - - prs_debug(ps, depth, desc, "net_io_r_sam_sync"); - depth++; - - smb_io_cred("", &(r_s->srv_creds), ps, depth); - prs_uint32("sync_context", ps, depth, &(r_s->sync_context)); - - prs_uint32("ptr_deltas", ps, depth, &(r_s->ptr_deltas)); - if (r_s->ptr_deltas != 0) - { - prs_uint32("num_deltas ", ps, depth, &(r_s->num_deltas )); - prs_uint32("ptr_deltas2", ps, depth, &(r_s->ptr_deltas2)); - if (r_s->ptr_deltas2 != 0) - { - prs_uint32("num_deltas2", ps, depth, &(r_s->num_deltas2)); - if (r_s->num_deltas2 != r_s->num_deltas) - { - /* RPC fault */ - return False; - } - - for (i = 0; i < r_s->num_deltas2; i++) - { - net_io_sam_delta_hdr("", &r_s->hdr_deltas[i], ps, depth); - } - - for (i = 0; i < r_s->num_deltas2; i++) - { - net_io_sam_delta_ctr("", sess_key, - &r_s->deltas[i], - r_s->hdr_deltas[i].type3, ps, depth); - } - } - } + if(!prs_uint32("buffer_creds", ps, depth, &r_l->buffer_creds)) /* undocumented buffer pointer */ + return False; + if(!smb_io_cred("", &r_l->srv_creds, ps, depth)) /* server credentials. server time stamp appears to be ignored. */ + return False; - prs_align(ps); - prs_uint32("status", ps, depth, &(r_s->status)); + if(!prs_uint32("status ", ps, depth, &r_l->status)) + return False; return True; } diff --git a/source3/rpc_parse/parse_prs.c b/source3/rpc_parse/parse_prs.c index d9c07e3885..f5f4eb67b8 100644 --- a/source3/rpc_parse/parse_prs.c +++ b/source3/rpc_parse/parse_prs.c @@ -2,8 +2,9 @@ Unix SMB/Netbios implementation. Version 1.9. Samba memory buffer functions - Copyright (C) Andrew Tridgell 1992-1999 - Copyright (C) Luke Kenneth Casson Leighton 1996-1999 + Copyright (C) Andrew Tridgell 1992-1997 + Copyright (C) Luke Kenneth Casson Leighton 1996-1997 + Copyright (C) Jeremy Allison 1999. 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 @@ -33,523 +34,567 @@ extern int DEBUGLEVEL; ********************************************************************/ void prs_debug(prs_struct *ps, int depth, char *desc, char *fn_name) { - DEBUG(5+depth, ("%s%06x %s %s\n", tab_depth(depth), ps->offset, fn_name, desc)); + DEBUG(5+depth, ("%s%06x %s %s\n", tab_depth(depth), ps->data_offset, fn_name, desc)); } /******************************************************************* - debug a parse structure + Initialise a parse structure - malloc the data if requested. ********************************************************************/ -void prs_debug_out(prs_struct *ps, char *msg, int level) + +BOOL prs_init(prs_struct *ps, uint32 size, uint8 align, BOOL io) { - DEBUG(level,("%s ps: io %s align %d offset %d err %d data %p len %d\n", - msg, BOOLSTR(ps->io), ps->align, ps->offset, ps->error, - ps->data, - ps->data != NULL ? mem_buf_len(ps->data) : 0)); + ZERO_STRUCTP(ps); + ps->io = io; + ps->bigendian_data = False; + ps->align = align; + ps->is_dynamic = False; + ps->data_offset = 0; + ps->buffer_size = 0; + ps->data_p = NULL; + + if (size != 0) { + ps->buffer_size = size; + if((ps->data_p = (char *)malloc((size_t)size)) == NULL) { + DEBUG(0,("prs_init: malloc fail for %u bytes.\n", (unsigned int)size)); + return False; + } + ps->is_dynamic = True; /* We own this memory. */ + } + + return True; } /******************************************************************* - initialise a parse structure + Delete the memory in a parse structure - if we own it. ********************************************************************/ -void prs_init(prs_struct *ps, uint32 size, - uint8 align, uint32 margin, - BOOL io) + +void prs_mem_free(prs_struct *ps) { - ps->io = io; - ps->align = align; - ps->offset = 0; - ps->error = False; + if(ps->is_dynamic && (ps->data_p != NULL)) + free(ps->data_p); + ps->is_dynamic = False; + ps->data_p = NULL; + ps->buffer_size = 0; + ps->data_offset = 0; +} - ps->data = NULL; - mem_buf_init(&(ps->data), margin); +/******************************************************************* + Hand some already allocated memory to a prs_struct. + ********************************************************************/ - if (size != 0) - { - mem_alloc_data(ps->data, size); - ps->data->offset.start = 0; - ps->data->offset.end = 0xffffffff; - } +void prs_give_memory(prs_struct *ps, char *buf, uint32 size, BOOL is_dynamic) +{ + ps->is_dynamic = is_dynamic; + ps->data_p = buf; + ps->buffer_size = size; } /******************************************************************* - copy a parse structure + Take some memory back from a prs_struct. ********************************************************************/ -BOOL prs_copy(prs_struct *ps, const prs_struct *from) + +char *prs_take_memory(prs_struct *ps, uint32 *psize) { - int len = mem_buf_len(from->data); - prs_init(ps, len, from->align, from->data->margin, from->io); - if (!mem_buf_copy(mem_data(&ps->data, 0), from->data, 0, len)) - { + char *ret = ps->data_p; + if(psize) + *psize = ps->buffer_size; + ps->is_dynamic = False; + prs_mem_free(ps); + return ret; +} + +/******************************************************************* + Attempt, if needed, to grow a data buffer. + Also depends on the data stream mode (io). + ********************************************************************/ + +BOOL prs_grow(prs_struct *ps, uint32 extra_space) +{ + uint32 new_size; + char *new_data; + + if(ps->data_offset + extra_space <= ps->buffer_size) + return True; + + /* + * We cannot grow the buffer if we're not reading + * into the prs_struct, or if we don't own the memory. + */ + + if(UNMARSHALLING(ps) || !ps->is_dynamic) { + DEBUG(0,("prs_grow: Buffer overflow - unable to expand buffer by %u bytes.\n", + (unsigned int)extra_space)); return False; } - ps->offset = len; - prs_link(NULL, ps, NULL); + + /* + * Decide how much extra space we really need. + */ + + extra_space -= (ps->buffer_size - ps->data_offset); + + if(ps->buffer_size == 0) { + + /* + * Ensure we have at least a PDU's length, or extra_space, whichever + * is greater. + */ + + new_size = MAX(MAX_PDU_FRAG_LEN,extra_space); + + if((new_data = malloc(new_size)) == NULL) { + DEBUG(0,("prs_grow: Malloc failure for size %u.\n", (unsigned int)new_size)); + return False; + } + memset(new_data, '\0', new_size ); + } else { + + /* + * If the current buffer size is bigger than the space needed, just + * double it, else add extra_space. + */ + + new_size = MAX(ps->buffer_size*2, ps->buffer_size + extra_space); + + if((new_data = Realloc(ps->data_p, new_size)) == NULL) { + DEBUG(0,("prs_grow: Realloc failure for size %u.\n", + (unsigned int)new_size)); + return False; + } + } + + ps->buffer_size = new_size; + ps->data_p = new_data; + return True; } /******************************************************************* - initialise a parse structure + Attempt to force a data buffer to grow by len bytes. + This is only used when appending more data onto a prs_struct + when reading an rpc reply, before unmarshalling it. ********************************************************************/ -void prs_mem_free(prs_struct *ps) + +BOOL prs_force_grow(prs_struct *ps, uint32 extra_space) { - mem_buf_free(&(ps->data)); + uint32 new_size = ps->buffer_size + extra_space; + char *new_data; + + if(!UNMARSHALLING(ps) || !ps->is_dynamic) { + DEBUG(0,("prs_force_grow: Buffer overflow - unable to expand buffer by %u bytes.\n", + (unsigned int)extra_space)); + return False; + } + + if((new_data = Realloc(ps->data_p, new_size)) == NULL) { + DEBUG(0,("prs_force_grow: Realloc failure for size %u.\n", + (unsigned int)new_size)); + return False; + } + + ps->buffer_size = new_size; + ps->data_p = new_data; + + return True; } /******************************************************************* - link one parsing structure to another + Get the data pointer (external interface). ********************************************************************/ -void prs_link(prs_struct *prev, prs_struct *ps, prs_struct *next) -{ - ps->data->offset.start = prev != NULL ? prev->data->offset.end : 0; - ps->data->offset.end = ps->data->offset.start + ps->offset; - ps->data->next = next != NULL ? next->data : NULL; - DEBUG(150,("prs_link: start %d end %d\n", - ps->data->offset.start, - ps->data->offset.end)); +char *prs_data_p(prs_struct *ps) +{ + return ps->data_p; } /******************************************************************* - align a pointer to a multiple of align_offset bytes. looks like it - will work for offsets of 0, 2 and 4... + Get the current data size (external interface). ********************************************************************/ -void prs_align(prs_struct *ps) + +uint32 prs_data_size(prs_struct *ps) { - int mod; - if (ps->error) return; - mod = ps->offset & (ps->align-1); - if (ps->align != 0 && mod != 0) - { - ps->offset += ps->align - mod; - } + return ps->buffer_size; } /******************************************************************* - attempt, if appropriate, to grow a data buffer. - - depends on the data stream mode (io) + Fetch the current offset (external interface). ********************************************************************/ -BOOL prs_grow(prs_struct *ps, uint32 new_size) + +uint32 prs_offset(prs_struct *ps) { - if (ps->error) return False; - return mem_grow_data(&(ps->data), ps->io, new_size, False); + return ps->data_offset; } /******************************************************************* - lengthens a buffer by len bytes and copies data into it. + Set the current offset (external interface). ********************************************************************/ -BOOL prs_append_data(prs_struct *ps, const char *data, int len) + +BOOL prs_set_offset(prs_struct *ps, uint32 offset) { - int prev_size = ps->data->data_used; - int new_size = prev_size + len; - char *to; + if(offset <= ps->data_offset) { + ps->data_offset = offset; + return True; + } - mem_realloc_data(ps->data, new_size); - to = mem_data(&ps->data, prev_size); - if (to == NULL || ps->data->data_used != new_size) - { + if(!prs_grow(ps, offset - ps->data_offset)) return False; - } - memcpy(to, data, len); + ps->data_offset = offset; return True; } /******************************************************************* - stream a uint8 + Append the data from one parse_struct into another. ********************************************************************/ -BOOL _prs_uint8(char *name, prs_struct *ps, int depth, uint8 *data8) + +BOOL prs_append_prs_data(prs_struct *dst, prs_struct *src) { - char *q; - if (ps->error) return False; - prs_grow(ps, ps->offset + 1); - q = mem_data(&(ps->data), ps->offset); - if (q == NULL) - { - ps->error = True; - prs_debug_out(ps, "_prs_uint8 error", 5); + if(!prs_grow(dst, prs_offset(src))) return False; - } - - DBG_RW_CVAL(name, depth, ps->offset, ps->io, q, *data8) - ps->offset += 1; + memcpy(&dst->data_p[dst->data_offset], prs_data_p(src), (size_t)prs_offset(src)); + dst->data_offset += prs_offset(src); return True; } /******************************************************************* - stream a uint16 + Append the data from a buffer into a parse_struct. ********************************************************************/ -BOOL _prs_uint16(char *name, prs_struct *ps, int depth, uint16 *data16) + +BOOL prs_append_data(prs_struct *dst, char *src, uint32 len) { - char *q; - if (ps->error) return False; - prs_grow(ps, ps->offset + 2); - q = mem_data(&(ps->data), ps->offset); - if (q == NULL) - { - ps->error = True; - prs_debug_out(ps, "_prs_uint16 error", 5); + if(!prs_grow(dst, len)) return False; - } - DBG_RW_SVAL(name, depth, ps->offset, ps->io, q, *data16) - ps->offset += 2; + memcpy(&dst->data_p[dst->data_offset], src, (size_t)len); + dst->data_offset += len; return True; } /******************************************************************* - hash a stream. + Set the data as big-endian (external interface). ********************************************************************/ -BOOL _prs_hash1(prs_struct *ps, uint32 offset, uint8 sess_key[16]) + +void prs_set_bigendian_data(prs_struct *ps) { - char *q; - if (ps->error) return False; - q = mem_data(&(ps->data), ps->offset); + ps->bigendian_data = True; +} + +/******************************************************************* + Align a the data_len to a multiple of align bytes - filling with + zeros. + ********************************************************************/ + +BOOL prs_align(prs_struct *ps) +{ + uint32 mod = ps->data_offset & (ps->align-1); + + if (ps->align != 0 && mod != 0) { + uint32 extra_space = (ps->align - mod); + if(!prs_grow(ps, extra_space)) + return False; + memset(&ps->data_p[ps->data_offset], '\0', (size_t)extra_space); + ps->data_offset += extra_space; + } + + return True; +} + +/******************************************************************* + Ensure we can read/write to a given offset. + ********************************************************************/ + +char *prs_mem_get(prs_struct *ps, uint32 extra_size) +{ + if(UNMARSHALLING(ps)) { + /* + * If reading, ensure that we can read the requested size item. + */ + if (ps->data_offset + extra_size > ps->buffer_size) { + DEBUG(0,("prs_mem_get: reading data of size %u would overrun buffer.\n", + (unsigned int)extra_size )); + return NULL; + } + } else { + /* + * Writing - grow the buffer if needed. + */ + if(!prs_grow(ps, extra_size)) + return False; + } + return &ps->data_p[ps->data_offset]; +} + +/******************************************************************* + Stream a uint8. + ********************************************************************/ + +BOOL prs_uint8(char *name, prs_struct *ps, int depth, uint8 *data8) +{ + char *q = prs_mem_get(ps, sizeof(uint8)); if (q == NULL) - { - ps->error = True; - prs_debug_out(ps, "_prs_hash1 error", 5); return False; - } -#ifdef DEBUG_PASSWORD - DEBUG(100,("prs_hash1\n")); - dump_data(100, sess_key, 16); - dump_data(100, q, 68); -#endif - SamOEMhash((uchar*)q, sess_key, 2); -#ifdef DEBUG_PASSWORD - dump_data(100, q, 68); -#endif + DBG_RW_CVAL(name, depth, ps->data_offset, ps->io, q, *data8) + ps->data_offset += sizeof(uint8); return True; } /******************************************************************* - stream a uint32 + Stream a uint16. ********************************************************************/ -BOOL _prs_uint32(char *name, prs_struct *ps, int depth, uint32 *data32) + +BOOL prs_uint16(char *name, prs_struct *ps, int depth, uint16 *data16) { - char *q; - if (ps->error) return False; - prs_grow(ps, ps->offset + 4); - q = mem_data(&(ps->data), ps->offset); + char *q = prs_mem_get(ps, sizeof(uint16)); if (q == NULL) - { - ps->error = True; - prs_debug_out(ps, "_prs_uint32 error", 5); return False; - } - DBG_RW_IVAL(name, depth, ps->offset, ps->io, q, *data32) - ps->offset += 4; + DBG_RW_SVAL(name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, *data16) + ps->data_offset += sizeof(uint16); return True; } - -/****************************************************************** - stream an array of uint8s. length is number of uint8s +/******************************************************************* + Stream a uint32. ********************************************************************/ -BOOL _prs_uint8s(BOOL charmode, char *name, prs_struct *ps, int depth, uint8 *data8s, int len) + +BOOL prs_uint32(char *name, prs_struct *ps, int depth, uint32 *data32) { - char *q; - int end_offset; - char *e; - if (ps->error) return False; - end_offset = ps->offset + len * sizeof(uint8); - prs_grow(ps, end_offset); - q = mem_data(&(ps->data), ps->offset); - e = mem_data(&(ps->data), end_offset-1); - - if (q == NULL || e == NULL) - { - ps->error = True; - prs_debug_out(ps, "_prs_uint8s error", 5); + char *q = prs_mem_get(ps, sizeof(uint32)); + if (q == NULL) return False; - } - DBG_RW_PCVAL(charmode, name, depth, ps->offset, ps->io, q, data8s, len) - ps->offset = end_offset; + DBG_RW_IVAL(name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, *data32) + ps->data_offset += sizeof(uint32); return True; } + /****************************************************************** - stream an array of uint16s. length is number of uint16s + Stream an array of uint8s. Length is number of uint8s. ********************************************************************/ -BOOL _prs_uint16s(BOOL charmode, char *name, prs_struct *ps, int depth, uint16 *data16s, int len) + +BOOL prs_uint8s(BOOL charmode, char *name, prs_struct *ps, int depth, uint8 *data8s, int len) { - char *q; - int end_offset; - char *e; - if (ps->error) return False; - end_offset = ps->offset + len * sizeof(uint16); - prs_grow(ps, end_offset); - q = mem_data(&(ps->data), ps->offset); - e = mem_data(&(ps->data), end_offset-1); - - if (q == NULL || e == NULL) - { - ps->error = True; - prs_debug_out(ps, "_prs_uint16s error", 5); + char *q = prs_mem_get(ps, len * sizeof(uint8)); + if (q == NULL) return False; - } - DBG_RW_PSVAL(charmode, name, depth, ps->offset, ps->io, q, data16s, len) - ps->offset = end_offset; + DBG_RW_PCVAL(charmode, name, depth, ps->data_offset, ps->io, q, data8s, len) + ps->data_offset += (len * sizeof(uint8)); return True; } /****************************************************************** - stream an array of uint32s. length is number of uint32s + Stream an array of uint32s. Length is number of uint32s. ********************************************************************/ -BOOL _prs_uint32s(BOOL charmode, char *name, prs_struct *ps, int depth, uint32 *data32s, int len) + +BOOL prs_uint32s(BOOL charmode, char *name, prs_struct *ps, int depth, uint32 *data32s, int len) { - char *q; - int end_offset; - char *e; - if (ps->error) return False; - end_offset = ps->offset + len * sizeof(uint32); - prs_grow(ps, end_offset); - q = mem_data(&(ps->data), ps->offset); - e = mem_data(&(ps->data), end_offset-1); - - if (q == NULL || e == NULL) - { - ps->error = True; - prs_debug_out(ps, "_prs_uint32s error", 5); + char *q = prs_mem_get(ps, len * sizeof(uint32)); + if (q == NULL) return False; - } - DBG_RW_PIVAL(charmode, name, depth, ps->offset, ps->io, q, data32s, len) - ps->offset = end_offset; + DBG_RW_PIVAL(charmode, name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, data32s, len) + ps->data_offset += (len * sizeof(uint32)); return True; } /****************************************************************** - stream a "not" unicode string, length/buffer specified separately, - in byte chars + Stream a "not" unicode string, length/buffer specified separately, + in byte chars. String is in little-endian format. ********************************************************************/ -BOOL _prs_buffer2(BOOL charmode, char *name, prs_struct *ps, int depth, BUFFER2 *str) + +BOOL prs_buffer2(BOOL charmode, char *name, prs_struct *ps, int depth, BUFFER2 *str) { - char *q; - int end_offset; - char *e; - if (ps->error) return False; - end_offset = ps->offset + str->buf_len * sizeof(uint8); - prs_grow(ps, end_offset); - q = mem_data(&(ps->data), ps->offset); - e = mem_data(&(ps->data), end_offset-1); - - if (q == NULL || e == NULL) - { - ps->error = True; - prs_debug_out(ps, "_prs_buffer2 error", 5); + char *p = (char *)str->buffer; + char *q = prs_mem_get(ps, str->buf_len); + if (q == NULL) return False; - } - DBG_RW_PCVAL(charmode, name, depth, ps->offset, ps->io, q, str->buffer, str->buf_len) - ps->offset = end_offset; + /* If we're using big-endian, reverse to get little-endian. */ + if(ps->bigendian_data) + DBG_RW_PSVAL(charmode, name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, p, str->buf_len/2) + else + DBG_RW_PCVAL(charmode, name, depth, ps->data_offset, ps->io, q, p, str->buf_len) + ps->data_offset += str->buf_len; return True; } /****************************************************************** - stream a string, length/buffer specified separately, + Stream a string, length/buffer specified separately, in uint8 chars. ********************************************************************/ -BOOL _prs_string2(BOOL charmode, char *name, prs_struct *ps, int depth, STRING2 *str) + +BOOL prs_string2(BOOL charmode, char *name, prs_struct *ps, int depth, STRING2 *str) { - char *q; - int end_offset; - char *e; - if (ps->error) return False; - end_offset = ps->offset + str->str_str_len * sizeof(uint8); - prs_grow(ps, end_offset); - q = mem_data(&(ps->data), ps->offset); - e = mem_data(&(ps->data), end_offset-1); - - if (q == NULL || e == NULL) - { - ps->error = True; - prs_debug_out(ps, "_prs_string2 error", 5); + char *q = prs_mem_get(ps, str->str_str_len * sizeof(uint8)); + if (q == NULL) return False; - } - DBG_RW_PCVAL(charmode, name, depth, ps->offset, ps->io, q, str->buffer, str->str_max_len) - ps->offset = end_offset; + DBG_RW_PCVAL(charmode, name, depth, ps->data_offset, ps->io, q, str->buffer, str->str_max_len) + ps->data_offset += (str->str_str_len * sizeof(uint8)); return True; } /****************************************************************** - stream a unicode string, length/buffer specified separately, - in uint16 chars. + Stream a unicode string, length/buffer specified separately, + in uint16 chars. We use DBG_RW_PCVAL, not DBG_RW_PSVAL here + as the unicode string is already in little-endian format. ********************************************************************/ -BOOL _prs_unistr2(BOOL charmode, char *name, prs_struct *ps, int depth, UNISTR2 *str) + +BOOL prs_unistr2(BOOL charmode, char *name, prs_struct *ps, int depth, UNISTR2 *str) { - char *q; - int end_offset; - char *e; - if (ps->error) return False; - end_offset = ps->offset + str->uni_str_len * sizeof(uint16); - prs_grow(ps, end_offset); - q = mem_data(&(ps->data), ps->offset); - e = mem_data(&(ps->data), end_offset-1); - - if (q == NULL || e == NULL) - { - ps->error = True; - prs_debug_out(ps, "_prs_unistr2 error", 5); + char *p = (char *)str->buffer; + char *q = prs_mem_get(ps, str->uni_str_len * sizeof(uint16)); + if (q == NULL) return False; - } - DBG_RW_PSVAL(charmode, name, depth, ps->offset, ps->io, q, str->buffer, str->uni_str_len) - ps->offset = end_offset; + /* If we're using big-endian, reverse to get little-endian. */ + if(ps->bigendian_data) + DBG_RW_PSVAL(charmode, name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, p, str->uni_str_len) + else + DBG_RW_PCVAL(charmode, name, depth, ps->data_offset, ps->io, q, p, str->uni_str_len * 2) + ps->data_offset += (str->uni_str_len * sizeof(uint16)); return True; } /****************************************************************** - stream a unicode string, length/buffer specified separately, - in uint16 chars. + Stream a unicode string, length/buffer specified separately, + in uint16 chars. We use DBG_RW_PCVAL, not DBG_RW_PSVAL here + as the unicode string is already in little-endian format. ********************************************************************/ -BOOL _prs_unistr3(BOOL charmode, char *name, UNISTR3 *str, prs_struct *ps, int depth) + +BOOL prs_unistr3(BOOL charmode, char *name, UNISTR3 *str, prs_struct *ps, int depth) { - char *q; - int end_offset; - char *e; - if (ps->error) return False; - end_offset = ps->offset + str->uni_str_len * sizeof(uint16); - prs_grow(ps, end_offset); - q = mem_data(&(ps->data), ps->offset); - e = mem_data(&(ps->data), end_offset-1); - - if (q == NULL || e == NULL) - { - ps->error = True; - prs_debug_out(ps, "_prs_unistr3 error", 5); + char *p = (char *)str->str.buffer; + char *q = prs_mem_get(ps, str->uni_str_len * sizeof(uint16)); + if (q == NULL) return False; - } - DBG_RW_PSVAL(charmode, name, depth, ps->offset, ps->io, q, str->str.buffer, str->uni_str_len) - ps->offset = end_offset; + /* If we're using big-endian, reverse to get little-endian. */ + if(ps->bigendian_data) + DBG_RW_PSVAL(charmode, name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, p, str->uni_str_len) + else + DBG_RW_PCVAL(charmode, name, depth, ps->data_offset, ps->io, q, p, str->uni_str_len * 2) + ps->data_offset += (str->uni_str_len * sizeof(uint16)); return True; } /******************************************************************* - stream a unicode null-terminated string + Stream a unicode null-terminated string. As the string is already + in little-endian format then do it as a stream of bytes. ********************************************************************/ -BOOL _prs_unistr(char *name, prs_struct *ps, int depth, UNISTR *str) + +BOOL prs_unistr(char *name, prs_struct *ps, int depth, UNISTR *str) { - int i = -1; + int len = 0; + unsigned char *p = (unsigned char *)str->buffer; uint8 *start; - if (ps->error) return False; - start = (uint8*)mem_data(&(ps->data), ps->offset); + char *q; + + for(len = 0; len < (sizeof(str->buffer) / sizeof(str->buffer[0])) && + str->buffer[len] != 0; len++) + ; - do + q = prs_mem_get(ps, len*2); + if (q == NULL) + return False; + + start = (uint8*)q; + + len = 0; + do { - char *q; - i++; - prs_grow(ps, ps->offset + i*2); - q = mem_data(&(ps->data), ps->offset + i*2); - if (q == NULL) - { - ps->error = True; - prs_debug_out(ps, "_prs_unistr error", 5); - return False; + if(ps->bigendian_data) { + RW_SVAL(ps->io, ps->bigendian_data, q, *p, 0) + p += 2; + q += 2; + } else { + RW_CVAL(ps->io, q, *p, 0); + p++; + q++; + RW_CVAL(ps->io, q, *p, 0); + p++; + q++; } - RW_SVAL(ps->io, q, str->buffer[i],0); - } - while ((((size_t)i) < sizeof(str->buffer) / sizeof(str->buffer[0])) && - (str->buffer[i] != 0)); - + len++; + } while ((len < (sizeof(str->buffer) / sizeof(str->buffer[0]))) && + (str->buffer[len] != 0)); - ps->offset += (i+1)*2; + ps->data_offset += len*2; - dump_data(5+depth, (char *)start, i * 2); + dump_data(5+depth, (char *)start, len * 2); return True; } /******************************************************************* - stream a null-terminated string. len is strlen, and therefore does + Stream a null-terminated string. len is strlen, and therefore does not include the null-termination character. - - len == 0 indicates variable length string - (up to max size of pstring - 1024 chars). - ********************************************************************/ -BOOL _prs_string(char *name, prs_struct *ps, int depth, char *str, uint16 len, uint16 max_buf_size) + +BOOL prs_string(char *name, prs_struct *ps, int depth, char *str, int len, int max_buf_size) { - int i = -1; /* start off at zero after 1st i++ */ + char *q; uint8 *start; - if (ps->error) return False; - start = (uint8*)mem_data(&(ps->data), ps->offset); + int i; - DEBUG(120,("_prs_string: string %s len %d max %d\n", - str, len, max_buf_size)); + len = MIN(len, (max_buf_size-1)); - DEBUG(10,("%s%04x %s: ", tab_depth(depth), ps->offset, name != NULL ? name : "")); + q = prs_mem_get(ps, len+1); + if (q == NULL) + return False; - do - { - char *q; - i++; - - prs_grow(ps, ps->offset + i); - q = mem_data(&(ps->data), ps->offset + i); - if (q == NULL) - { - ps->error = True; - prs_debug_out(ps, "_prs_string error", 5); - return False; - } + start = (uint8*)q; - if (i < len || len == 0) - { - RW_CVAL(ps->io, q, str[i], 0); - } - else - { - uint8 dummy = 0; - RW_CVAL(ps->io, q, dummy,0); - } + for(i = 0; i < len; i++) { + RW_CVAL(ps->io, q, str[i],0); + q++; + } - } while (i < max_buf_size && (len == 0 ? str[i] != 0 : i < len) ); + /* The terminating null. */ + str[i] = '\0'; - DEBUG(120,("_prs_string: string %s len %d max %d\n", - str, len, max_buf_size)); + if (MARSHALLING(ps)) { + RW_CVAL(ps->io, q, str[i], 0); + } - ps->offset += i+1; + ps->data_offset += len+1; - dump_data(5+depth, (char *)start, i); + dump_data(5+depth, (char *)start, len); return True; } /******************************************************************* - prs_uint16 wrapper. call this and it sets up a pointer to where the - uint16 should be stored, or gets the size if reading + prs_uint16 wrapper. Call this and it sets up a pointer to where the + uint16 should be stored, or gets the size if reading. ********************************************************************/ -BOOL _prs_uint16_pre(char *name, prs_struct *ps, int depth, uint16 *data16, uint32 *offset) + +BOOL prs_uint16_pre(char *name, prs_struct *ps, int depth, uint16 *data16, uint32 *offset) { - if (ps->error) return False; - (*offset) = ps->offset; - if (ps->io) - { + (*offset) = ps->data_offset; + if (UNMARSHALLING(ps)) { /* reading. */ - return _prs_uint16(name, ps, depth, data16); - } - else - { - ps->offset += sizeof(uint16); + return prs_uint16(name, ps, depth, data16); + } else { + char *q = prs_mem_get(ps, sizeof(uint16)); + if(q ==NULL) + return False; + ps->data_offset += sizeof(uint16); } return True; } @@ -558,43 +603,42 @@ BOOL _prs_uint16_pre(char *name, prs_struct *ps, int depth, uint16 *data16, uint prs_uint16 wrapper. call this and it retrospectively stores the size. does nothing on reading, as that is already handled by ...._pre() ********************************************************************/ -BOOL _prs_uint16_post(char *name, prs_struct *ps, int depth, uint16 *data16, + +BOOL prs_uint16_post(char *name, prs_struct *ps, int depth, uint16 *data16, uint32 ptr_uint16, uint32 start_offset) { - if (ps->error) return False; - if (!ps->io) - { - /* storing: go back and do a retrospective job. i hate this */ - uint16 data_size = ps->offset - start_offset; - uint32 old_offset = ps->offset; - - ps->offset = ptr_uint16; - prs_uint16(name, ps, depth, &data_size); - ps->offset = old_offset; - } - else - { - ps->offset = start_offset + (*data16); + if (MARSHALLING(ps)) { + /* + * Writing - temporarily move the offset pointer. + */ + uint16 data_size = ps->data_offset - start_offset; + uint32 old_offset = ps->data_offset; + + ps->data_offset = ptr_uint16; + if(!prs_uint16(name, ps, depth, &data_size)) { + ps->data_offset = old_offset; + return False; + } + ps->data_offset = old_offset; + } else { + ps->data_offset = start_offset + (uint32)(*data16); } return True; } /******************************************************************* - prs_uint32 wrapper. call this and it sets up a pointer to where the - uint32 should be stored, or gets the size if reading + prs_uint32 wrapper. Call this and it sets up a pointer to where the + uint32 should be stored, or gets the size if reading. ********************************************************************/ -BOOL _prs_uint32_pre(char *name, prs_struct *ps, int depth, uint32 *data32, uint32 *offset) + +BOOL prs_uint32_pre(char *name, prs_struct *ps, int depth, uint32 *data32, uint32 *offset) { - if (ps->error) return False; - (*offset) = ps->offset; - if (ps->io) - { + (*offset) = ps->data_offset; + if (UNMARSHALLING(ps)) { /* reading. */ - return _prs_uint32(name, ps, depth, data32); - } - else - { - ps->offset += sizeof(uint32); + return prs_uint32(name, ps, depth, data32); + } else { + ps->data_offset += sizeof(uint32); } return True; } @@ -603,18 +647,21 @@ BOOL _prs_uint32_pre(char *name, prs_struct *ps, int depth, uint32 *data32, uint prs_uint32 wrapper. call this and it retrospectively stores the size. does nothing on reading, as that is already handled by ...._pre() ********************************************************************/ -BOOL _prs_uint32_post(char *name, prs_struct *ps, int depth, uint32 *data32, + +BOOL prs_uint32_post(char *name, prs_struct *ps, int depth, uint32 *data32, uint32 ptr_uint32, uint32 data_size) { - if (ps->error) return False; - if (!ps->io) - { - /* storing: go back and do a retrospective job. i hate this */ - uint32 old_offset = ps->offset; - ps->offset = ptr_uint32; - prs_uint32(name, ps, depth, &data_size); - ps->offset = old_offset; + if (MARSHALLING(ps)) { + /* + * Writing - temporarily move the offset pointer. + */ + uint32 old_offset = ps->data_offset; + ps->data_offset = ptr_uint32; + if(!prs_uint32(name, ps, depth, &data_size)) { + ps->data_offset = old_offset; + return False; + } + ps->data_offset = old_offset; } return True; } - diff --git a/source3/rpc_parse/parse_reg.c b/source3/rpc_parse/parse_reg.c index 9f446cc86a..23262279a4 100644 --- a/source3/rpc_parse/parse_reg.c +++ b/source3/rpc_parse/parse_reg.c @@ -2,9 +2,9 @@ * Unix SMB/Netbios implementation. * Version 1.9. * RPC Pipe client / server routines - * Copyright (C) Andrew Tridgell 1992-1999, - * Copyright (C) Luke Kenneth Casson Leighton 1996-1999, - * Copyright (C) Paul Ashton 1997-1999. + * Copyright (C) Andrew Tridgell 1992-1997, + * Copyright (C) Luke Kenneth Casson Leighton 1996-1997, + * Copyright (C) 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 @@ -28,95 +28,43 @@ extern int DEBUGLEVEL; /******************************************************************* -creates a structure. + Inits a structure. ********************************************************************/ -BOOL make_reg_q_open_hkcr(REG_Q_OPEN_HKCR *q_o, - uint16 unknown_0, uint32 level) -{ - q_o->ptr = 1; - q_o->unknown_0 = unknown_0; - q_o->unknown_1 = 0x0; /* random - changes */ - q_o->level = level; - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL reg_io_q_open_hkcr(char *desc, REG_Q_OPEN_HKCR *r_q, prs_struct *ps, int depth) -{ - if (r_q == NULL) return False; - - prs_debug(ps, depth, desc, "reg_io_q_open_hkcr"); - depth++; - - prs_align(ps); - - prs_uint32("ptr ", ps, depth, &(r_q->ptr )); - if (r_q->ptr != 0) - { - prs_uint16("unknown_0", ps, depth, &(r_q->unknown_0)); - prs_uint16("unknown_1", ps, depth, &(r_q->unknown_1)); - prs_uint32("level ", ps, depth, &(r_q->level )); - } - - return True; -} - - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL reg_io_r_open_hkcr(char *desc, REG_R_OPEN_HKCR *r_r, prs_struct *ps, int depth) -{ - if (r_r == NULL) return False; - - prs_debug(ps, depth, desc, "reg_io_r_open_hkcr"); - depth++; - prs_align(ps); - - smb_io_pol_hnd("", &(r_r->pol), ps, depth); - - prs_uint32("status", ps, depth, &(r_r->status)); - - return True; -} - - -/******************************************************************* -creates a structure. -********************************************************************/ -BOOL make_reg_q_open_hklm(REG_Q_OPEN_HKLM *q_o, +void init_reg_q_open_hklm(REG_Q_OPEN_HKLM *q_o, uint16 unknown_0, uint32 level) { q_o->ptr = 1; q_o->unknown_0 = unknown_0; q_o->unknown_1 = 0x0; /* random - changes */ q_o->level = level; - - return True; } /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_q_open_hklm(char *desc, REG_Q_OPEN_HKLM *r_q, prs_struct *ps, int depth) { - if (r_q == NULL) return False; + if (r_q == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_q_open_hklm"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - prs_uint32("ptr ", ps, depth, &(r_q->ptr )); - if (r_q->ptr != 0) - { - prs_uint16("unknown_0", ps, depth, &(r_q->unknown_0)); - prs_uint16("unknown_1", ps, depth, &(r_q->unknown_1)); - prs_uint32("level ", ps, depth, &(r_q->level )); + if(!prs_uint32("ptr ", ps, depth, &r_q->ptr)) + return False; + + if (r_q->ptr != 0) { + if(!prs_uint16("unknown_0", ps, depth, &r_q->unknown_0)) + return False; + if(!prs_uint16("unknown_1", ps, depth, &r_q->unknown_1)) + return False; + if(!prs_uint32("level ", ps, depth, &r_q->level)) + return False; } return True; @@ -126,64 +74,75 @@ BOOL reg_io_q_open_hklm(char *desc, REG_Q_OPEN_HKLM *r_q, prs_struct *ps, int d /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_r_open_hklm(char *desc, REG_R_OPEN_HKLM *r_r, prs_struct *ps, int depth) { - if (r_r == NULL) return False; + if (r_r == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_r_open_hklm"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - smb_io_pol_hnd("", &(r_r->pol), ps, depth); + if(!smb_io_pol_hnd("", &r_r->pol, ps, depth)) + return False; - prs_uint32("status", ps, depth, &(r_r->status)); + if(!prs_uint32("status", ps, depth, &r_r->status)) + return False; return True; } /******************************************************************* -creates a structure. + Inits a structure. ********************************************************************/ -BOOL make_reg_q_flush_key(REG_Q_FLUSH_KEY *q_u, POLICY_HND *pol) -{ - memcpy(&(q_u->pol), pol, sizeof(q_u->pol)); - return True; +void init_reg_q_flush_key(REG_Q_FLUSH_KEY *q_u, POLICY_HND *pol) +{ + memcpy(&q_u->pol, pol, sizeof(q_u->pol)); } /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_q_flush_key(char *desc, REG_Q_FLUSH_KEY *r_q, prs_struct *ps, int depth) { - if (r_q == NULL) return False; + if (r_q == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_q_flush_key"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - smb_io_pol_hnd("", &(r_q->pol), ps, depth); + if(!smb_io_pol_hnd("", &r_q->pol, ps, depth)) + return False; return True; } - /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_r_flush_key(char *desc, REG_R_FLUSH_KEY *r_r, prs_struct *ps, int depth) { - if (r_r == NULL) return False; + if (r_r == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_r_flush_key"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - prs_uint32("status", ps, depth, &(r_r->status)); + if(!prs_uint32("status", ps, depth, &r_r->status)) + return False; return True; } @@ -191,167 +150,197 @@ BOOL reg_io_r_flush_key(char *desc, REG_R_FLUSH_KEY *r_r, prs_struct *ps, int d /******************************************************************* reads or writes SEC_DESC_BUF and SEC_DATA structures. ********************************************************************/ -static BOOL reg_io_hdrbuf_sec(uint32 ptr, uint32 *ptr3, BUFHDR *hdr_sec, - SEC_DESC_BUF *data, prs_struct *ps, int depth) + +static BOOL reg_io_hdrbuf_sec(uint32 ptr, uint32 *ptr3, BUFHDR *hdr_sec, SEC_DESC_BUF *data, prs_struct *ps, int depth) { - if (ptr != 0) - { + if (ptr != 0) { uint32 hdr_offset; uint32 old_offset; - smb_io_hdrbuf_pre("hdr_sec", hdr_sec, ps, depth, &hdr_offset); - old_offset = ps->offset; - if (ptr3 != NULL) - { - prs_uint32("ptr3", ps, depth, ptr3); + if(!smb_io_hdrbuf_pre("hdr_sec", hdr_sec, ps, depth, &hdr_offset)) + return False; + + old_offset = prs_offset(ps); + + if (ptr3 != NULL) { + if(!prs_uint32("ptr3", ps, depth, ptr3)) + return False; } - if (ptr3 == NULL || *ptr3 != 0) - { - sec_io_desc_buf("data ", data , ps, depth); + + if (ptr3 == NULL || *ptr3 != 0) { + if(!sec_io_desc_buf("data ", &data, ps, depth)) /* JRA - this line is probably wrong... */ + return False; } - smb_io_hdrbuf_post("hdr_sec", hdr_sec, ps, depth, hdr_offset, - data->max_len, data->len); - ps->offset = old_offset + data->len + sizeof(uint32) * ((ptr3 != NULL) ? 5 : 3); - prs_align(ps); + + if(!smb_io_hdrbuf_post("hdr_sec", hdr_sec, ps, depth, hdr_offset, + data->max_len, data->len)) + return False; + if(!prs_set_offset(ps, old_offset + data->len + sizeof(uint32) * ((ptr3 != NULL) ? 5 : 3))) + return False; + + if(prs_align(ps)) + return False; } return True; } - /******************************************************************* -creates a structure. + Inits a structure. ********************************************************************/ -BOOL make_reg_q_create_key(REG_Q_CREATE_KEY *q_c, POLICY_HND *hnd, - char *key_name, char *key_class, - SEC_ACCESS *sam_access, - SEC_DESC_BUF *sec_buf, - int sec_len, SEC_DESC *sec) + +void init_reg_q_create_key(REG_Q_CREATE_KEY *q_c, POLICY_HND *hnd, + char *name, char *class, SEC_ACCESS *sam_access, + SEC_DESC_BUF *sec_buf) { - int len_name = key_name != NULL ? strlen(key_name ) + 1: 0; - int len_class = key_class != NULL ? strlen(key_class) + 1: 0; + int len_name = name != NULL ? strlen(name ) + 1: 0; + int len_class = class != NULL ? strlen(class) + 1: 0; ZERO_STRUCTP(q_c); - memcpy(&(q_c->pnt_pol), hnd, sizeof(q_c->pnt_pol)); + memcpy(&q_c->pnt_pol, hnd, sizeof(q_c->pnt_pol)); - make_uni_hdr(&(q_c->hdr_name), len_name); - make_unistr2(&(q_c->uni_name), key_name, len_name); + init_uni_hdr(&q_c->hdr_name, len_name); + init_unistr2(&q_c->uni_name, name, len_name); - make_uni_hdr(&(q_c->hdr_class), len_class); - make_unistr2(&(q_c->uni_class), key_class, len_class); + init_uni_hdr(&q_c->hdr_class, len_class); + init_unistr2(&q_c->uni_class, class, len_class); q_c->reserved = 0x00000000; - memcpy(&(q_c->sam_access), sam_access, sizeof(q_c->sam_access)); + memcpy(&q_c->sam_access, sam_access, sizeof(q_c->sam_access)); q_c->ptr1 = 1; q_c->sec_info = DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION; q_c->data = sec_buf; q_c->ptr2 = 1; - make_buf_hdr(&(q_c->hdr_sec), sec_len, sec_len); + init_buf_hdr(&q_c->hdr_sec, sec_buf->len, sec_buf->len); q_c->ptr3 = 1; - make_sec_desc_buf(q_c->data, sec_len, sec); - q_c->unknown_2 = 0x00000000; - - return True; } /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_q_create_key(char *desc, REG_Q_CREATE_KEY *r_q, prs_struct *ps, int depth) { - if (r_q == NULL) return False; + if (r_q == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_q_create_key"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - smb_io_pol_hnd("", &(r_q->pnt_pol), ps, depth); - - smb_io_unihdr ("", &(r_q->hdr_name), ps, depth); - smb_io_unistr2("", &(r_q->uni_name), r_q->hdr_name.buffer, ps, depth); - prs_align(ps); - - smb_io_unihdr ("", &(r_q->hdr_class), ps, depth); - smb_io_unistr2("", &(r_q->uni_class), r_q->hdr_class.buffer, ps, depth); - prs_align(ps); - - prs_uint32("reserved", ps, depth, &(r_q->reserved)); - sec_io_access("sam_access", &r_q->sam_access, ps, depth); - - prs_uint32("ptr1", ps, depth, &(r_q->ptr1)); - if (r_q->ptr1 != 0) - { - prs_uint32("sec_info", ps, depth, &(r_q->sec_info)); + if(!smb_io_pol_hnd("", &r_q->pnt_pol, ps, depth)) + return False; + + if(!smb_io_unihdr ("", &r_q->hdr_name, ps, depth)) + return False; + if(!smb_io_unistr2("", &r_q->uni_name, r_q->hdr_name.buffer, ps, depth)) + return False; + if(prs_align(ps)) + return False; + + if(!smb_io_unihdr ("", &r_q->hdr_class, ps, depth)) + return False; + if(!smb_io_unistr2("", &r_q->uni_class, r_q->hdr_class.buffer, ps, depth)) + return False; + if(prs_align(ps)) + return False; + + if(!prs_uint32("reserved", ps, depth, &r_q->reserved)) + return False; + if(!sec_io_access("sam_access", &r_q->sam_access, ps, depth)) + return False; + + if(!prs_uint32("ptr1", ps, depth, &r_q->ptr1)) + return False; + + if (r_q->ptr1 != 0) { + if(!prs_uint32("sec_info", ps, depth, &r_q->sec_info)) + return False; } - prs_uint32("ptr2", ps, depth, &(r_q->ptr2)); - reg_io_hdrbuf_sec(r_q->ptr2, &r_q->ptr3, &r_q->hdr_sec, r_q->data, ps, depth); + if(!prs_uint32("ptr2", ps, depth, &r_q->ptr2)) + return False; + if(!reg_io_hdrbuf_sec(r_q->ptr2, &r_q->ptr3, &r_q->hdr_sec, r_q->data, ps, depth)) + return False; - prs_uint32("unknown_2", ps, depth, &(r_q->unknown_2)); + if(!prs_uint32("unknown_2", ps, depth, &r_q->unknown_2)) + return False; return True; } - /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_r_create_key(char *desc, REG_R_CREATE_KEY *r_r, prs_struct *ps, int depth) { - if (r_r == NULL) return False; + if (r_r == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_r_create_key"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - smb_io_pol_hnd("", &(r_r->key_pol), ps, depth); - prs_uint32("unknown", ps, depth, &(r_r->unknown)); + if(!smb_io_pol_hnd("", &r_r->key_pol, ps, depth)) + return False; + if(!prs_uint32("unknown", ps, depth, &r_r->unknown)) + return False; - prs_uint32("status", ps, depth, &(r_r->status)); + if(!prs_uint32("status", ps, depth, &r_r->status)) + return False; return True; } /******************************************************************* -creates a structure. + Inits a structure. ********************************************************************/ -BOOL make_reg_q_delete_val(REG_Q_DELETE_VALUE *q_c, POLICY_HND *hnd, + +void init_reg_q_delete_val(REG_Q_DELETE_VALUE *q_c, POLICY_HND *hnd, char *name) { int len_name = name != NULL ? strlen(name ) + 1: 0; ZERO_STRUCTP(q_c); - memcpy(&(q_c->pnt_pol), hnd, sizeof(q_c->pnt_pol)); - - make_uni_hdr(&(q_c->hdr_name), len_name); - make_unistr2(&(q_c->uni_name), name, len_name); + memcpy(&q_c->pnt_pol, hnd, sizeof(q_c->pnt_pol)); - return True; + init_uni_hdr(&q_c->hdr_name, len_name); + init_unistr2(&q_c->uni_name, name, len_name); } /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_q_delete_val(char *desc, REG_Q_DELETE_VALUE *r_q, prs_struct *ps, int depth) { - if (r_q == NULL) return False; + if (r_q == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_q_delete_val"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - smb_io_pol_hnd("", &(r_q->pnt_pol), ps, depth); + if(!smb_io_pol_hnd("", &r_q->pnt_pol, ps, depth)) + return False; - smb_io_unihdr ("", &(r_q->hdr_name), ps, depth); - smb_io_unistr2("", &(r_q->uni_name), r_q->hdr_name.buffer, ps, depth); - prs_align(ps); + if(!smb_io_unihdr ("", &r_q->hdr_name, ps, depth)) + return False; + if(!smb_io_unistr2("", &r_q->uni_name, r_q->hdr_name.buffer, ps, depth)) + return False; + if(prs_align(ps)) + return False; return True; } @@ -360,112 +349,127 @@ BOOL reg_io_q_delete_val(char *desc, REG_Q_DELETE_VALUE *r_q, prs_struct *ps, i /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_r_delete_val(char *desc, REG_R_DELETE_VALUE *r_r, prs_struct *ps, int depth) { - if (r_r == NULL) return False; + if (r_r == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_r_delete_val"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - prs_uint32("status", ps, depth, &(r_r->status)); + if(!prs_uint32("status", ps, depth, &r_r->status)) + return False; return True; } - /******************************************************************* -creates a structure. + Inits a structure. ********************************************************************/ -BOOL make_reg_q_delete_key(REG_Q_DELETE_KEY *q_c, POLICY_HND *hnd, + +void init_reg_q_delete_key(REG_Q_DELETE_KEY *q_c, POLICY_HND *hnd, char *name) { int len_name = name != NULL ? strlen(name ) + 1: 0; ZERO_STRUCTP(q_c); - memcpy(&(q_c->pnt_pol), hnd, sizeof(q_c->pnt_pol)); + memcpy(&q_c->pnt_pol, hnd, sizeof(q_c->pnt_pol)); - make_uni_hdr(&(q_c->hdr_name), len_name); - make_unistr2(&(q_c->uni_name), name, len_name); - - return True; + init_uni_hdr(&q_c->hdr_name, len_name); + init_unistr2(&q_c->uni_name, name, len_name); } /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_q_delete_key(char *desc, REG_Q_DELETE_KEY *r_q, prs_struct *ps, int depth) { - if (r_q == NULL) return False; + if (r_q == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_q_delete_key"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - smb_io_pol_hnd("", &(r_q->pnt_pol), ps, depth); + if(!smb_io_pol_hnd("", &r_q->pnt_pol, ps, depth)) + return False; - smb_io_unihdr ("", &(r_q->hdr_name), ps, depth); - smb_io_unistr2("", &(r_q->uni_name), r_q->hdr_name.buffer, ps, depth); - prs_align(ps); + if(!smb_io_unihdr ("", &r_q->hdr_name, ps, depth)) + return False; + if(!smb_io_unistr2("", &r_q->uni_name, r_q->hdr_name.buffer, ps, depth)) + return False; + if(prs_align(ps)) + return False; return True; } - /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_r_delete_key(char *desc, REG_R_DELETE_KEY *r_r, prs_struct *ps, int depth) { - if (r_r == NULL) return False; + if (r_r == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_r_delete_key"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - prs_uint32("status", ps, depth, &(r_r->status)); + if(!prs_uint32("status", ps, depth, &r_r->status)) + return False; return True; } - /******************************************************************* -creates a structure. + Inits a structure. ********************************************************************/ -BOOL make_reg_q_query_key(REG_Q_QUERY_KEY *q_o, POLICY_HND *hnd, + +void init_reg_q_query_key(REG_Q_QUERY_KEY *q_o, POLICY_HND *hnd, uint32 max_class_len) { ZERO_STRUCTP(q_o); - memcpy(&(q_o->pol), hnd, sizeof(q_o->pol)); - q_o->hdr_class.uni_str_len = 0; - q_o->hdr_class.uni_max_len = max_class_len * 2; - q_o->hdr_class.buffer = max_class_len > 0 ? 1 : 0; + memcpy(&q_o->pol, hnd, sizeof(q_o->pol)); + init_uni_hdr(&q_o->hdr_class, max_class_len); q_o->uni_class.uni_max_len = max_class_len; - - return True; } /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_q_query_key(char *desc, REG_Q_QUERY_KEY *r_q, prs_struct *ps, int depth) { - if (r_q == NULL) return False; + if (r_q == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_q_query_key"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - smb_io_pol_hnd("", &(r_q->pol), ps, depth); - smb_io_unihdr ("", &(r_q->hdr_class), ps, depth); - smb_io_unistr2("", &(r_q->uni_class), r_q->hdr_class.buffer, ps, depth); + if(!smb_io_pol_hnd("", &r_q->pol, ps, depth)) + return False; + if(!smb_io_unihdr ("", &r_q->hdr_class, ps, depth)) + return False; + if(!smb_io_unistr2("", &r_q->uni_class, r_q->hdr_class.buffer, ps, depth)) + return False; - prs_align(ps); + if(prs_align(ps)) + return False; return True; } @@ -474,168 +478,198 @@ BOOL reg_io_q_query_key(char *desc, REG_Q_QUERY_KEY *r_q, prs_struct *ps, int d /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_r_query_key(char *desc, REG_R_QUERY_KEY *r_r, prs_struct *ps, int depth) { - if (r_r == NULL) return False; + if (r_r == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_r_query_key"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - smb_io_unihdr ("", &(r_r->hdr_class), ps, depth); - smb_io_unistr2("", &(r_r->uni_class), r_r->hdr_class.buffer, ps, depth); - - prs_align(ps); - - prs_uint32("num_subkeys ", ps, depth, &(r_r->num_subkeys )); - prs_uint32("max_subkeylen ", ps, depth, &(r_r->max_subkeylen )); - prs_uint32("mak_subkeysize", ps, depth, &(r_r->max_subkeysize)); - prs_uint32("num_values ", ps, depth, &(r_r->num_values )); - prs_uint32("max_valnamelen", ps, depth, &(r_r->max_valnamelen)); - prs_uint32("max_valbufsize", ps, depth, &(r_r->max_valbufsize)); - prs_uint32("sec_desc ", ps, depth, &(r_r->sec_desc )); - smb_io_time("mod_time ", &(r_r->mod_time), ps, depth); + if(!smb_io_unihdr ("", &r_r->hdr_class, ps, depth)) + return False; + if(!smb_io_unistr2("", &r_r->uni_class, r_r->hdr_class.buffer, ps, depth)) + return False; + + if(prs_align(ps)) + return False; + + if(!prs_uint32("num_subkeys ", ps, depth, &r_r->num_subkeys)) + return False; + if(!prs_uint32("max_subkeylen ", ps, depth, &r_r->max_subkeylen)) + return False; + if(!prs_uint32("mak_subkeysize", ps, depth, &r_r->max_subkeysize)) + return False; + if(!prs_uint32("num_values ", ps, depth, &r_r->num_values)) + return False; + if(!prs_uint32("max_valnamelen", ps, depth, &r_r->max_valnamelen)) + return False; + if(!prs_uint32("max_valbufsize", ps, depth, &r_r->max_valbufsize)) + return False; + if(!prs_uint32("sec_desc ", ps, depth, &r_r->sec_desc)) + return False; + if(!smb_io_time("mod_time ", &r_r->mod_time, ps, depth)) + return False; - prs_uint32("status", ps, depth, &(r_r->status)); + if(!prs_uint32("status", ps, depth, &r_r->status)) + return False; return True; } - /******************************************************************* -creates a structure. + Inits a structure. ********************************************************************/ -BOOL make_reg_q_unk_1a(REG_Q_UNK_1A *q_o, POLICY_HND *hnd) -{ - memcpy(&(q_o->pol), hnd, sizeof(q_o->pol)); - return True; +void init_reg_q_unk_1a(REG_Q_UNK_1A *q_o, POLICY_HND *hnd) +{ + memcpy(&q_o->pol, hnd, sizeof(q_o->pol)); } /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_q_unk_1a(char *desc, REG_Q_UNK_1A *r_q, prs_struct *ps, int depth) { - if (r_q == NULL) return False; + if (r_q == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_q_unk_1a"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - smb_io_pol_hnd("", &(r_q->pol), ps, depth); + if(!smb_io_pol_hnd("", &r_q->pol, ps, depth)) + return False; return True; } - /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_r_unk_1a(char *desc, REG_R_UNK_1A *r_r, prs_struct *ps, int depth) { - if (r_r == NULL) return False; + if (r_r == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_r_unk_1a"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - prs_uint32("unknown", ps, depth, &(r_r->unknown)); - prs_uint32("status" , ps, depth, &(r_r->status )); + if(!prs_uint32("unknown", ps, depth, &r_r->unknown)) + return False; + if(!prs_uint32("status" , ps, depth, &r_r->status)) + return False; return True; } - /******************************************************************* -creates a structure. + Inits a structure. ********************************************************************/ -BOOL make_reg_q_open_hku(REG_Q_OPEN_HKU *q_o, + +void init_reg_q_open_hku(REG_Q_OPEN_HKU *q_o, uint16 unknown_0, uint32 level) { q_o->ptr = 1; q_o->unknown_0 = unknown_0; q_o->unknown_1 = 0x0; /* random - changes */ q_o->level = level; - - return True; } /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_q_open_hku(char *desc, REG_Q_OPEN_HKU *r_q, prs_struct *ps, int depth) { - if (r_q == NULL) return False; + if (r_q == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_q_open_hku"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - prs_uint32("ptr ", ps, depth, &(r_q->ptr )); - if (r_q->ptr != 0) - { - prs_uint16("unknown_0", ps, depth, &(r_q->unknown_0)); - prs_uint16("unknown_1", ps, depth, &(r_q->unknown_1)); - prs_uint32("level ", ps, depth, &(r_q->level )); + if(!prs_uint32("ptr ", ps, depth, &r_q->ptr)) + return False; + if (r_q->ptr != 0) { + if(!prs_uint16("unknown_0", ps, depth, &r_q->unknown_0)) + return False; + if(!prs_uint16("unknown_1", ps, depth, &r_q->unknown_1)) + return False; + if(!prs_uint32("level ", ps, depth, &r_q->level)) + return False; } return True; } - /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_r_open_hku(char *desc, REG_R_OPEN_HKU *r_r, prs_struct *ps, int depth) { - if (r_r == NULL) return False; + if (r_r == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_r_open_hku"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - smb_io_pol_hnd("", &(r_r->pol), ps, depth); + if(!smb_io_pol_hnd("", &r_r->pol, ps, depth)) + return False; - prs_uint32("status", ps, depth, &(r_r->status)); + if(!prs_uint32("status", ps, depth, &r_r->status)) + return False; return True; } - /******************************************************************* -makes an REG_Q_CLOSE structure. + Inits an REG_Q_CLOSE structure. ********************************************************************/ -BOOL make_reg_q_close(REG_Q_CLOSE *q_c, POLICY_HND *hnd) -{ - if (q_c == NULL || hnd == NULL) return False; - DEBUG(5,("make_reg_q_close\n")); - - memcpy(&(q_c->pol), hnd, sizeof(q_c->pol)); +void init_reg_q_close(REG_Q_CLOSE *q_c, POLICY_HND *hnd) +{ + DEBUG(5,("init_reg_q_close\n")); - return True; + memcpy(&q_c->pol, hnd, sizeof(q_c->pol)); } /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_q_close(char *desc, REG_Q_CLOSE *q_u, prs_struct *ps, int depth) { - if (q_u == NULL) return False; + if (q_u == NULL) + return False; - prs_debug(ps, depth, desc, "reg_io_q_close"); + prs_debug(ps, depth, desc, "reg_io_q_unknown_1"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - smb_io_pol_hnd("", &(q_u->pol), ps, depth); - prs_align(ps); + if(!smb_io_pol_hnd("", &q_u->pol, ps, depth)) + return False; + if(prs_align(ps)) + return False; return True; } @@ -643,19 +677,25 @@ BOOL reg_io_q_close(char *desc, REG_Q_CLOSE *q_u, prs_struct *ps, int depth) /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_r_close(char *desc, REG_R_CLOSE *r_u, prs_struct *ps, int depth) { - if (r_u == NULL) return False; + if (r_u == NULL) + return False; - prs_debug(ps, depth, desc, "reg_io_r_close"); + prs_debug(ps, depth, desc, "reg_io_r_unknown_1"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - smb_io_pol_hnd("", &(r_u->pol), ps, depth); - prs_align(ps); + if(!smb_io_pol_hnd("", &r_u->pol, ps, depth)) + return False; + if(prs_align(ps)) + return False; - prs_uint32("status", ps, depth, &(r_u->status)); + if(!prs_uint32("status", ps, depth, &r_u->status)) + return False; return True; } @@ -663,41 +703,43 @@ BOOL reg_io_r_close(char *desc, REG_R_CLOSE *r_u, prs_struct *ps, int depth) /******************************************************************* makes a structure. ********************************************************************/ -BOOL make_reg_q_set_key_sec(REG_Q_SET_KEY_SEC *q_i, POLICY_HND *pol, - uint32 sec_info, - uint32 buf_len, SEC_DESC *sec_desc) -{ - if (q_i == NULL) return False; - memcpy(&(q_i->pol), pol, sizeof(q_i->pol)); +void init_reg_q_set_key_sec(REG_Q_SET_KEY_SEC *q_i, POLICY_HND *pol, SEC_DESC_BUF *sec_desc_buf) +{ + memcpy(&q_i->pol, pol, sizeof(q_i->pol)); - q_i->sec_info = sec_info; + q_i->sec_info = DACL_SECURITY_INFORMATION; q_i->ptr = 1; - make_buf_hdr(&(q_i->hdr_sec), buf_len, buf_len); - make_sec_desc_buf(q_i->data, buf_len, sec_desc); - - return True; + init_buf_hdr(&q_i->hdr_sec, sec_desc_buf->len, sec_desc_buf->len); + q_i->data = sec_desc_buf; } /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_q_set_key_sec(char *desc, REG_Q_SET_KEY_SEC *r_q, prs_struct *ps, int depth) { - if (r_q == NULL) return False; + if (r_q == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_q_set_key_sec"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - smb_io_pol_hnd("", &(r_q->pol), ps, depth); + if(!smb_io_pol_hnd("", &r_q->pol, ps, depth)) + return False; - prs_uint32("sec_info", ps, depth, &(r_q->sec_info)); - prs_uint32("ptr ", ps, depth, &(r_q->ptr )); + if(!prs_uint32("sec_info", ps, depth, &r_q->sec_info)) + return False; + if(!prs_uint32("ptr ", ps, depth, &r_q->ptr)) + return False; - reg_io_hdrbuf_sec(r_q->ptr, NULL, &r_q->hdr_sec, r_q->data, ps, depth); + if(!reg_io_hdrbuf_sec(r_q->ptr, NULL, &r_q->hdr_sec, r_q->data, ps, depth)) + return False; return True; } @@ -705,16 +747,20 @@ BOOL reg_io_q_set_key_sec(char *desc, REG_Q_SET_KEY_SEC *r_q, prs_struct *ps, i /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_r_set_key_sec(char *desc, REG_R_SET_KEY_SEC *r_q, prs_struct *ps, int depth) { - if (r_q == NULL) return False; + if (r_q == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_r_set_key_sec"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - prs_uint32("status", ps, depth, &(r_q->status)); + if(!prs_uint32("status", ps, depth, &r_q->status)) + return False; return True; } @@ -723,46 +769,47 @@ BOOL reg_io_r_set_key_sec(char *desc, REG_R_SET_KEY_SEC *r_q, prs_struct *ps, in /******************************************************************* makes a structure. ********************************************************************/ -BOOL make_reg_q_get_key_sec(REG_Q_GET_KEY_SEC *q_i, POLICY_HND *pol, - uint32 sec_info, - uint32 buf_len, SEC_DESC_BUF *sec_buf) -{ - if (q_i == NULL) return False; - memcpy(&(q_i->pol), pol, sizeof(q_i->pol)); +void init_reg_q_get_key_sec(REG_Q_GET_KEY_SEC *q_i, POLICY_HND *pol, + uint32 sec_buf_size, SEC_DESC_BUF *psdb) +{ + memcpy(&q_i->pol, pol, sizeof(q_i->pol)); - q_i->sec_info = sec_info; + q_i->sec_info = OWNER_SECURITY_INFORMATION | + GROUP_SECURITY_INFORMATION | + DACL_SECURITY_INFORMATION; - q_i->ptr = sec_buf != NULL ? 1 : 0; - q_i->data = sec_buf; + q_i->ptr = psdb != NULL ? 1 : 0; + q_i->data = psdb; - if (sec_buf != NULL) - { - make_buf_hdr(&(q_i->hdr_sec), buf_len, 0); - make_sec_desc_buf(q_i->data, buf_len, NULL); - } - - return True; + init_buf_hdr(&q_i->hdr_sec, sec_buf_size, 0); } /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_q_get_key_sec(char *desc, REG_Q_GET_KEY_SEC *r_q, prs_struct *ps, int depth) { - if (r_q == NULL) return False; + if (r_q == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_q_get_key_sec"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - smb_io_pol_hnd("", &(r_q->pol), ps, depth); + if(!smb_io_pol_hnd("", &r_q->pol, ps, depth)) + return False; - prs_uint32("sec_info", ps, depth, &(r_q->sec_info)); - prs_uint32("ptr ", ps, depth, &(r_q->ptr )); + if(!prs_uint32("sec_info", ps, depth, &r_q->sec_info)) + return False; + if(!prs_uint32("ptr ", ps, depth, &r_q->ptr)) + return False; - reg_io_hdrbuf_sec(r_q->ptr, NULL, &r_q->hdr_sec, r_q->data, ps, depth); + if(!reg_io_hdrbuf_sec(r_q->ptr, NULL, &r_q->hdr_sec, r_q->data, ps, depth)) + return False; return True; } @@ -771,196 +818,217 @@ BOOL reg_io_q_get_key_sec(char *desc, REG_Q_GET_KEY_SEC *r_q, prs_struct *ps, i /******************************************************************* makes a structure. ********************************************************************/ - void make_reg_r_get_key_sec(REG_R_GET_KEY_SEC *r_i, POLICY_HND *pol, + void init_reg_r_get_key_sec(REG_R_GET_KEY_SEC *r_i, POLICY_HND *pol, uint32 buf_len, uint8 *buf, uint32 status) { - if (r_i == NULL) return False; - r_i->ptr = 1; - make_buf_hdr(&(r_i->hdr_sec), buf_len, buf_len); - make_sec_desc_buf(r_i->data, buf_len, 1); + init_buf_hdr(&r_i->hdr_sec, buf_len, buf_len); + init_sec_desc_buf(r_i->data, buf_len, 1); r_i->status = status; /* 0x0000 0000 or 0x0000 007a */ - - return True; } #endif /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_r_get_key_sec(char *desc, REG_R_GET_KEY_SEC *r_q, prs_struct *ps, int depth) { - if (r_q == NULL) return False; + if (r_q == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_r_get_key_sec"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - prs_uint32("ptr ", ps, depth, &(r_q->ptr )); - - if (r_q->ptr != 0) - { - smb_io_hdrbuf("", &(r_q->hdr_sec), ps, depth); - sec_io_desc_buf("", r_q->data, ps, depth); - - prs_align(ps); + if(!prs_uint32("ptr ", ps, depth, &r_q->ptr)) + return False; + + if (r_q->ptr != 0) { + if(!smb_io_hdrbuf("", &r_q->hdr_sec, ps, depth)) + return False; + if(!sec_io_desc_buf("", &r_q->data, ps, depth)) + return False; + if(prs_align(ps)) + return False; } - prs_uint32("status", ps, depth, &(r_q->status)); + if(!prs_uint32("status", ps, depth, &r_q->status)) + return False; return True; } - /******************************************************************* makes a structure. ********************************************************************/ -BOOL make_reg_q_info(REG_Q_INFO *q_i, POLICY_HND *pol, const char *val_name, - uint8 major, uint8 minor) -{ - int len_type = val_name != NULL ? strlen(val_name) + 1 : 0; - if (q_i == NULL) return False; - - memcpy(&(q_i->pol), pol, sizeof(q_i->pol)); - - make_uni_hdr(&(q_i->hdr_val), len_type); - make_unistr2(&(q_i->uni_val), val_name, len_type); +void init_reg_q_info(REG_Q_INFO *q_i, POLICY_HND *pol, char *product_type, + time_t unix_time, uint8 major, uint8 minor) +{ + int len_type = strlen(product_type); - q_i->ptr_type = 1; - q_i->type = 0x77872314; + memcpy(&q_i->pol, pol, sizeof(q_i->pol)); - q_i->ptr_uni_type = 0x1; - q_i->uni_type.buf_max_len = 0x104; - q_i->uni_type.buf_len = 0x0; - q_i->uni_type.undoc = 0; + init_uni_hdr(&q_i->hdr_type, len_type); + init_unistr2(&q_i->uni_type, product_type, len_type); - q_i->ptr_max_len = 1; - q_i->buf_max_len = 0x104; + q_i->ptr1 = 1; + unix_to_nt_time(&q_i->time, unix_time); + q_i->major_version1 = major; + q_i->minor_version1 = minor; + memset(q_i->pad1, 0, sizeof(q_i->pad1)); - q_i->ptr_len = 1; - q_i->buf_len = 0x0; + q_i->ptr2 = 1; + q_i->major_version2 = major; + q_i->minor_version2 = minor; + memset(q_i->pad2, 0, sizeof(q_i->pad2)); - return True; + q_i->ptr3 = 1; + q_i->unknown = 0x00000000; } /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_q_info(char *desc, REG_Q_INFO *r_q, prs_struct *ps, int depth) { - if (r_q == NULL) return False; + if (r_q == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_q_info"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - smb_io_pol_hnd("", &(r_q->pol), ps, depth); - smb_io_unihdr ("", &(r_q->hdr_val), ps, depth); - smb_io_unistr2("", &(r_q->uni_val), r_q->hdr_val.buffer, ps, depth); - - prs_align(ps); + if(!smb_io_pol_hnd("", &r_q->pol, ps, depth)) + return False; + if(!smb_io_unihdr ("", &r_q->hdr_type, ps, depth)) + return False; + if(!smb_io_unistr2("", &r_q->uni_type, r_q->hdr_type.buffer, ps, depth)) + return False; + + if(prs_align(ps)) + return False; - prs_uint32("ptr_type", ps, depth, &(r_q->ptr_type)); - if (r_q->ptr_type != 0) - { - prs_uint32("type", ps, depth, &(r_q->type)); + if(!prs_uint32("ptr1", ps, depth, &r_q->ptr1)) + return False; + + if (r_q->ptr1 != 0) { + if(!smb_io_time("", &r_q->time, ps, depth)) + return False; + if(!prs_uint8 ("major_version1", ps, depth, &r_q->major_version1)) + return False; + if(!prs_uint8 ("minor_version1", ps, depth, &r_q->minor_version1)) + return False; + if(!prs_uint8s(False, "pad1", ps, depth, r_q->pad1, sizeof(r_q->pad1))) + return False; } - prs_uint32("ptr_uni_type", ps, depth, &(r_q->ptr_uni_type)); - - smb_io_buffer2("uni_type", &(r_q->uni_type), r_q->ptr_uni_type, ps, depth); - prs_align(ps); + if(!prs_uint32("ptr2", ps, depth, &r_q->ptr2)) + return False; - prs_uint32("ptr_max_len", ps, depth, &(r_q->ptr_max_len)); - if (r_q->ptr_max_len != 0) - { - prs_uint32("buf_max_len", ps, depth, &(r_q->buf_max_len)); + if (r_q->ptr2 != 0) { + if(!prs_uint8 ("major_version2", ps, depth, &r_q->major_version2)) + return False; + if(!prs_uint8 ("minor_version2", ps, depth, &r_q->minor_version2)) + return False; + if(!prs_uint8s(False, "pad2", ps, depth, r_q->pad2, sizeof(r_q->pad2))) + return False; } - prs_uint32("ptr_len", ps, depth, &(r_q->ptr_len)); - if (r_q->ptr_len != 0) - { - prs_uint32("buf_len", ps, depth, &(r_q->buf_len)); + if(!prs_uint32("ptr3", ps, depth, &r_q->ptr3)) + return False; + + if (r_q->ptr3 != 0) { + if(!prs_uint32("unknown", ps, depth, &r_q->unknown)) + return False; } return True; } - /******************************************************************* -creates a structure. + Inits a structure. ********************************************************************/ -BOOL make_reg_r_info(REG_R_INFO *r_r, - uint32 *type, BUFFER2 *buf, + +void init_reg_r_info(REG_R_INFO *r_r, + uint32 level, char *os_type, + uint32 unknown_0, uint32 unknown_1, uint32 status) { - if (r_r == NULL) return False; + uint8 buf[512]; + int len = dos_struni2((char *)buf, os_type, sizeof(buf)); - r_r->ptr_type = type != NULL ? 1 : 0; - r_r->type = type; + r_r->ptr1 = 1; + r_r->level = level; - r_r->ptr_uni_type = buf != NULL ? 1 : 0; - r_r->uni_type = buf; + r_r->ptr_type = 1; + init_buffer2(&r_r->uni_type, buf, len*2); - if (buf != NULL) - { - r_r->ptr_max_len = 1; - r_r->buf_max_len = r_r->uni_type->buf_max_len; + r_r->ptr2 = 1; + r_r->unknown_0 = unknown_0; - r_r->ptr_len = 1; - r_r->buf_len = r_r->uni_type->buf_len; - } - else - { - r_r->ptr_max_len = 0; - r_r->ptr_len = 0; - } - - r_r->status = status; + r_r->ptr3 = 1; + r_r->unknown_1 = unknown_1; - return True; + r_r->status = status; } /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_r_info(char *desc, REG_R_INFO *r_r, prs_struct *ps, int depth) { - if (r_r == NULL) return False; + if (r_r == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_r_info"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - prs_uint32("ptr_type", ps, depth, &(r_r->ptr_type)); - if (r_r->ptr_type != 0) - { - prs_uint32("type", ps, depth, r_r->type); - } + if(!prs_uint32("ptr1", ps, depth, &r_r->ptr1)) + return False; + + if (r_r->ptr1 != 0) { + if(!prs_uint32("level", ps, depth, &r_r->level)) + return False; + if(!prs_uint32("ptr_type", ps, depth, &r_r->ptr_type)) + return False; + + if(!smb_io_buffer2("uni_type", &r_r->uni_type, r_r->ptr_type, ps, depth)) + return False; + if(prs_align(ps)) + return False; + + if(!prs_uint32("ptr2", ps, depth, &r_r->ptr2)) + return False; + + if (r_r->ptr2 != 0) { + if(!prs_uint32("unknown_0", ps, depth, &r_r->unknown_0)) + return False; + } - prs_uint32("ptr_uni_type", ps, depth, &(r_r->ptr_uni_type)); - smb_io_buffer2("uni_type", r_r->uni_type, r_r->ptr_uni_type, ps, depth); - prs_align(ps); + if(!prs_uint32("ptr3", ps, depth, &r_r->ptr3)) + return False; - prs_uint32("ptr_max_len", ps, depth, &(r_r->ptr_max_len)); - if (r_r->ptr_max_len != 0) - { - prs_uint32("buf_max_len", ps, depth, &(r_r->buf_max_len)); - } + if (r_r->ptr3 != 0) { + if(!prs_uint32("unknown_1", ps, depth, &r_r->unknown_1)) + return False; + } - prs_uint32("ptr_len", ps, depth, &(r_r->ptr_len)); - if (r_r->ptr_len != 0) - { - prs_uint32("buf_len", ps, depth, &(r_r->buf_len)); } - - prs_uint32("status", ps, depth, &(r_r->status)); + if(!prs_uint32("status", ps, depth, &r_r->status)) + return False; return True; } @@ -968,20 +1036,17 @@ BOOL reg_io_r_info(char *desc, REG_R_INFO *r_r, prs_struct *ps, int depth) /******************************************************************* makes a structure. ********************************************************************/ -BOOL make_reg_q_enum_val(REG_Q_ENUM_VALUE *q_i, POLICY_HND *pol, + +void init_reg_q_enum_val(REG_Q_ENUM_VALUE *q_i, POLICY_HND *pol, uint32 val_idx, uint32 max_val_len, uint32 max_buf_len) { - if (q_i == NULL) return False; - ZERO_STRUCTP(q_i); - memcpy(&(q_i->pol), pol, sizeof(q_i->pol)); + memcpy(&q_i->pol, pol, sizeof(q_i->pol)); q_i->val_index = val_idx; - q_i->hdr_name.uni_str_len = 0; - q_i->hdr_name.uni_max_len = max_val_len * 2; - q_i->hdr_name.buffer = max_val_len > 0 ? 1 : 0; + init_uni_hdr(&q_i->hdr_name, max_val_len); q_i->uni_name.uni_max_len = max_val_len; q_i->ptr_type = 1; @@ -995,49 +1060,61 @@ BOOL make_reg_q_enum_val(REG_Q_ENUM_VALUE *q_i, POLICY_HND *pol, q_i->ptr2 = 1; q_i->len_value2 = 0; - - return True; } /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_q_enum_val(char *desc, REG_Q_ENUM_VALUE *q_q, prs_struct *ps, int depth) { - if (q_q == NULL) return False; + if (q_q == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_q_enum_val"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - smb_io_pol_hnd("", &(q_q->pol), ps, depth); + if(!smb_io_pol_hnd("", &q_q->pol, ps, depth)) + return False; - prs_uint32("val_index", ps, depth, &(q_q->val_index)); - smb_io_unihdr ("hdr_name", &(q_q->hdr_name), ps, depth); - smb_io_unistr2("uni_name", &(q_q->uni_name), q_q->hdr_name.buffer, ps, depth); - prs_align(ps); - - prs_uint32("ptr_type", ps, depth, &(q_q->ptr_type)); - - if (q_q->ptr_type != 0) - { - prs_uint32("type", ps, depth, &(q_q->type)); + if(!prs_uint32("val_index", ps, depth, &q_q->val_index)) + return False; + if(!smb_io_unihdr ("hdr_name", &q_q->hdr_name, ps, depth)) + return False; + if(!smb_io_unistr2("uni_name", &q_q->uni_name, q_q->hdr_name.buffer, ps, depth)) + return False; + if(prs_align(ps)) + return False; + + if(!prs_uint32("ptr_type", ps, depth, &q_q->ptr_type)) + return False; + + if (q_q->ptr_type != 0) { + if(!prs_uint32("type", ps, depth, &q_q->type)) + return False; } - prs_uint32("ptr_value", ps, depth, &(q_q->ptr_value)); - smb_io_buffer2("buf_value", &(q_q->buf_value), q_q->ptr_value, ps, depth); - prs_align(ps); - - prs_uint32("ptr1", ps, depth, &(q_q->ptr1)); - if (q_q->ptr1 != 0) - { - prs_uint32("len_value1", ps, depth, &(q_q->len_value1)); + if(!prs_uint32("ptr_value", ps, depth, &q_q->ptr_value)) + return False; + if(!smb_io_buffer2("buf_value", &q_q->buf_value, q_q->ptr_value, ps, depth)) + return False; + if(prs_align(ps)) + return False; + + if(!prs_uint32("ptr1", ps, depth, &q_q->ptr1)) + return False; + if (q_q->ptr1 != 0) { + if(!prs_uint32("len_value1", ps, depth, &q_q->len_value1)) + return False; } - prs_uint32("ptr2", ps, depth, &(q_q->ptr2)); - if (q_q->ptr2 != 0) - { - prs_uint32("len_value2", ps, depth, &(q_q->len_value2)); + if(!prs_uint32("ptr2", ps, depth, &q_q->ptr2)) + return False; + if (q_q->ptr2 != 0) { + if(!prs_uint32("len_value2", ps, depth, &q_q->len_value2)) + return False; } return True; @@ -1046,43 +1123,56 @@ BOOL reg_io_q_enum_val(char *desc, REG_Q_ENUM_VALUE *q_q, prs_struct *ps, int d /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_r_enum_val(char *desc, REG_R_ENUM_VALUE *r_q, prs_struct *ps, int depth) { - if (r_q == NULL) return False; + if (r_q == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_r_enum_val"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - smb_io_unihdr ("hdr_name", &(r_q->hdr_name), ps, depth); - smb_io_unistr2("uni_name", &(r_q->uni_name), r_q->hdr_name.buffer, ps, depth); - prs_align(ps); - - prs_uint32("ptr_type", ps, depth, &(r_q->ptr_type)); - - if (r_q->ptr_type != 0) - { - prs_uint32("type", ps, depth, &(r_q->type)); + if(!smb_io_unihdr ("hdr_name", &r_q->hdr_name, ps, depth)) + return False; + if(!smb_io_unistr2("uni_name", &r_q->uni_name, r_q->hdr_name.buffer, ps, depth)) + return False; + if(prs_align(ps)) + return False; + + if(!prs_uint32("ptr_type", ps, depth, &r_q->ptr_type)) + return False; + + if (r_q->ptr_type != 0) { + if(!prs_uint32("type", ps, depth, &r_q->type)) + return False; } - prs_uint32("ptr_value", ps, depth, &(r_q->ptr_value)); - smb_io_buffer2("buf_value", r_q->buf_value, r_q->ptr_value, ps, depth); - prs_align(ps); - - prs_uint32("ptr1", ps, depth, &(r_q->ptr1)); - if (r_q->ptr1 != 0) - { - prs_uint32("len_value1", ps, depth, &(r_q->len_value1)); + if(!prs_uint32("ptr_value", ps, depth, &r_q->ptr_value)) + return False; + if(!smb_io_buffer2("buf_value", r_q->buf_value, r_q->ptr_value, ps, depth)) + return False; + if(prs_align(ps)) + return False; + + if(!prs_uint32("ptr1", ps, depth, &r_q->ptr1)) + return False; + if (r_q->ptr1 != 0) { + if(!prs_uint32("len_value1", ps, depth, &r_q->len_value1)) + return False; } - prs_uint32("ptr2", ps, depth, &(r_q->ptr2)); - if (r_q->ptr2 != 0) - { - prs_uint32("len_value2", ps, depth, &(r_q->len_value2)); + if(!prs_uint32("ptr2", ps, depth, &r_q->ptr2)) + return False; + if (r_q->ptr2 != 0) { + if(!prs_uint32("len_value2", ps, depth, &r_q->len_value2)) + return False; } - prs_uint32("status", ps, depth, &(r_q->status)); + if(!prs_uint32("status", ps, depth, &r_q->status)) + return False; return True; } @@ -1090,48 +1180,55 @@ BOOL reg_io_r_enum_val(char *desc, REG_R_ENUM_VALUE *r_q, prs_struct *ps, int d /******************************************************************* makes a structure. ********************************************************************/ -BOOL make_reg_q_create_val(REG_Q_CREATE_VALUE *q_i, POLICY_HND *pol, + +void init_reg_q_create_val(REG_Q_CREATE_VALUE *q_i, POLICY_HND *pol, char *val_name, uint32 type, BUFFER3 *val) { int val_len = strlen(val_name) + 1; - if (q_i == NULL) return False; - ZERO_STRUCTP(q_i); - memcpy(&(q_i->pol), pol, sizeof(q_i->pol)); + memcpy(&q_i->pol, pol, sizeof(q_i->pol)); - make_uni_hdr(&q_i->hdr_name, val_len); - make_unistr2(&(q_i->uni_name), val_name, val_len); + init_uni_hdr(&q_i->hdr_name, val_len); + init_unistr2(&q_i->uni_name, val_name, val_len); q_i->type = type; q_i->buf_value = val; - - return True; } /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_q_create_val(char *desc, REG_Q_CREATE_VALUE *q_q, prs_struct *ps, int depth) { - if (q_q == NULL) return False; + if (q_q == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_q_create_val"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - smb_io_pol_hnd("", &(q_q->pol), ps, depth); + if(!smb_io_pol_hnd("", &q_q->pol, ps, depth)) + return False; - smb_io_unihdr ("hdr_name", &(q_q->hdr_name), ps, depth); - smb_io_unistr2("uni_name", &(q_q->uni_name), q_q->hdr_name.buffer, ps, depth); - prs_align(ps); - - prs_uint32("type", ps, depth, &(q_q->type)); - smb_io_buffer3("buf_value", q_q->buf_value, ps, depth); - prs_align(ps); + if(!smb_io_unihdr ("hdr_name", &q_q->hdr_name, ps, depth)) + return False; + if(!smb_io_unistr2("uni_name", &q_q->uni_name, q_q->hdr_name.buffer, ps, depth)) + return False; + if(prs_align(ps)) + return False; + + if(!prs_uint32("type", ps, depth, &q_q->type)) + return False; + if(!smb_io_buffer3("buf_value", q_q->buf_value, ps, depth)) + return False; + if(prs_align(ps)) + return False; return True; } @@ -1139,16 +1236,20 @@ BOOL reg_io_q_create_val(char *desc, REG_Q_CREATE_VALUE *q_q, prs_struct *ps, i /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_r_create_val(char *desc, REG_R_CREATE_VALUE *r_q, prs_struct *ps, int depth) { - if (r_q == NULL) return False; + if (r_q == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_r_create_val"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - prs_uint32("status", ps, depth, &(r_q->status)); + if(!prs_uint32("status", ps, depth, &r_q->status)) + return False; return True; } @@ -1156,11 +1257,10 @@ BOOL reg_io_r_create_val(char *desc, REG_R_CREATE_VALUE *r_q, prs_struct *ps, i /******************************************************************* makes a structure. ********************************************************************/ -BOOL make_reg_q_enum_key(REG_Q_ENUM_KEY *q_i, POLICY_HND *pol, uint32 key_idx) -{ - if (q_i == NULL) return False; - memcpy(&(q_i->pol), pol, sizeof(q_i->pol)); +void init_reg_q_enum_key(REG_Q_ENUM_KEY *q_i, POLICY_HND *pol, uint32 key_idx) +{ + memcpy(&q_i->pol, pol, sizeof(q_i->pol)); q_i->key_index = key_idx; q_i->key_name_len = 0; @@ -1174,49 +1274,58 @@ BOOL make_reg_q_enum_key(REG_Q_ENUM_KEY *q_i, POLICY_HND *pol, uint32 key_idx) memset(q_i->pad2, 0, sizeof(q_i->pad2)); q_i->ptr3 = 1; - init_nt_time(&(q_i->time)); /* ignored ? */ - - return True; + unix_to_nt_time(&q_i->time, 0); /* current time? */ } /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_q_enum_key(char *desc, REG_Q_ENUM_KEY *q_q, prs_struct *ps, int depth) { - if (q_q == NULL) return False; + if (q_q == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_q_enum_key"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - smb_io_pol_hnd("", &(q_q->pol), ps, depth); + if(!smb_io_pol_hnd("", &q_q->pol, ps, depth)) + return False; - prs_uint32("key_index", ps, depth, &(q_q->key_index)); - prs_uint16("key_name_len", ps, depth, &(q_q->key_name_len)); - prs_uint16("unknown_1", ps, depth, &(q_q->unknown_1)); - - prs_uint32("ptr1", ps, depth, &(q_q->ptr1)); - - if (q_q->ptr1 != 0) - { - prs_uint32("unknown_2", ps, depth, &(q_q->unknown_2)); - prs_uint8s(False, "pad1", ps, depth, q_q->pad1, sizeof(q_q->pad1)); + if(!prs_uint32("key_index", ps, depth, &q_q->key_index)) + return False; + if(!prs_uint16("key_name_len", ps, depth, &q_q->key_name_len)) + return False; + if(!prs_uint16("unknown_1", ps, depth, &q_q->unknown_1)) + return False; + + if(!prs_uint32("ptr1", ps, depth, &q_q->ptr1)) + return False; + + if (q_q->ptr1 != 0) { + if(!prs_uint32("unknown_2", ps, depth, &q_q->unknown_2)) + return False; + if(!prs_uint8s(False, "pad1", ps, depth, q_q->pad1, sizeof(q_q->pad1))) + return False; } - prs_uint32("ptr2", ps, depth, &(q_q->ptr2)); + if(!prs_uint32("ptr2", ps, depth, &q_q->ptr2)) + return False; - if (q_q->ptr2 != 0) - { - prs_uint8s(False, "pad2", ps, depth, q_q->pad2, sizeof(q_q->pad2)); + if (q_q->ptr2 != 0) { + if(!prs_uint8s(False, "pad2", ps, depth, q_q->pad2, sizeof(q_q->pad2))) + return False; } - prs_uint32("ptr3", ps, depth, &(q_q->ptr3)); + if(!prs_uint32("ptr3", ps, depth, &q_q->ptr3)) + return False; - if (q_q->ptr3 != 0) - { - smb_io_time("", &(q_q->time), ps, depth); + if (q_q->ptr3 != 0) { + if(!smb_io_time("", &q_q->time, ps, depth)) + return False; } return True; @@ -1225,193 +1334,141 @@ BOOL reg_io_q_enum_key(char *desc, REG_Q_ENUM_KEY *q_q, prs_struct *ps, int dep /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_r_enum_key(char *desc, REG_R_ENUM_KEY *r_q, prs_struct *ps, int depth) { - if (r_q == NULL) return False; + if (r_q == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_r_enum_key"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - prs_uint16("key_name_len", ps, depth, &(r_q->key_name_len)); - prs_uint16("unknown_1", ps, depth, &(r_q->unknown_1)); - - prs_uint32("ptr1", ps, depth, &(r_q->ptr1)); - - if (r_q->ptr1 != 0) - { - prs_uint32("unknown_2", ps, depth, &(r_q->unknown_2)); - prs_uint32("unknown_3", ps, depth, &(r_q->unknown_3)); - smb_io_unistr3("key_name", &(r_q->key_name), ps, depth); - prs_align(ps); + if(!prs_uint16("key_name_len", ps, depth, &r_q->key_name_len)) + return False; + if(!prs_uint16("unknown_1", ps, depth, &r_q->unknown_1)) + return False; + + if(!prs_uint32("ptr1", ps, depth, &r_q->ptr1)) + return False; + + if (r_q->ptr1 != 0) { + if(!prs_uint32("unknown_2", ps, depth, &r_q->unknown_2)) + return False; + if(!prs_uint32("unknown_3", ps, depth, &r_q->unknown_3)) + return False; + if(!smb_io_unistr3("key_name", &r_q->key_name, ps, depth)) + return False; + if(prs_align(ps)) + return False; } - prs_uint32("ptr2", ps, depth, &(r_q->ptr2)); + if(!prs_uint32("ptr2", ps, depth, &r_q->ptr2)) + return False; - if (r_q->ptr2 != 0) - { - prs_uint8s(False, "pad2", ps, depth, r_q->pad2, sizeof(r_q->pad2)); + if (r_q->ptr2 != 0) { + if(!prs_uint8s(False, "pad2", ps, depth, r_q->pad2, sizeof(r_q->pad2))) + return False; } - prs_uint32("ptr3", ps, depth, &(r_q->ptr3)); + if(!prs_uint32("ptr3", ps, depth, &r_q->ptr3)) + return False; - if (r_q->ptr3 != 0) - { - smb_io_time("", &(r_q->time), ps, depth); + if (r_q->ptr3 != 0) { + if(!smb_io_time("", &r_q->time, ps, depth)) + return False; } - prs_uint32("status", ps, depth, &(r_q->status)); + if(!prs_uint32("status", ps, depth, &r_q->status)) + return False; return True; } - /******************************************************************* makes a structure. ********************************************************************/ -BOOL make_reg_q_open_entry(REG_Q_OPEN_ENTRY *r_q, POLICY_HND *pol, + +void init_reg_q_open_entry(REG_Q_OPEN_ENTRY *r_q, POLICY_HND *pol, char *key_name, uint32 unk) { int len_name = strlen(key_name)+1; - if (r_q == NULL) return False; - - memcpy(&(r_q->pol), pol, sizeof(r_q->pol)); + memcpy(&r_q->pol, pol, sizeof(r_q->pol)); - make_uni_hdr(&(r_q->hdr_name), len_name); - make_unistr2(&(r_q->uni_name), key_name, len_name); + init_uni_hdr(&r_q->hdr_name, len_name); + init_unistr2(&r_q->uni_name, key_name, len_name); r_q->unknown_0 = 0x00000000; r_q->unknown_1 = unk; - - return True; } /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_q_open_entry(char *desc, REG_Q_OPEN_ENTRY *r_q, prs_struct *ps, int depth) { - if (r_q == NULL) return False; + if (r_q == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_q_entry"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - smb_io_pol_hnd("", &(r_q->pol), ps, depth); - smb_io_unihdr ("", &(r_q->hdr_name), ps, depth); - smb_io_unistr2("", &(r_q->uni_name), r_q->hdr_name.buffer, ps, depth); - - prs_align(ps); + if(!smb_io_pol_hnd("", &r_q->pol, ps, depth)) + return False; + if(!smb_io_unihdr ("", &r_q->hdr_name, ps, depth)) + return False; + if(!smb_io_unistr2("", &r_q->uni_name, r_q->hdr_name.buffer, ps, depth)) + return False; + + if(prs_align(ps)) + return False; - prs_uint32("unknown_0", ps, depth, &(r_q->unknown_0)); - prs_uint32("unknown_1", ps, depth, &(r_q->unknown_1)); + if(!prs_uint32("unknown_0", ps, depth, &r_q->unknown_0)) + return False; + if(!prs_uint32("unknown_1", ps, depth, &r_q->unknown_1)) + return False; return True; } - /******************************************************************* -creates a structure. + Inits a structure. ********************************************************************/ -BOOL make_reg_r_open_entry(REG_R_OPEN_ENTRY *r_r, + +void init_reg_r_open_entry(REG_R_OPEN_ENTRY *r_r, POLICY_HND *pol, uint32 status) { - if (r_r == NULL) return False; - - memcpy(&(r_r->pol), pol, sizeof(r_r->pol)); + memcpy(&r_r->pol, pol, sizeof(r_r->pol)); r_r->status = status; - - return True; } /******************************************************************* reads or writes a structure. ********************************************************************/ + BOOL reg_io_r_open_entry(char *desc, REG_R_OPEN_ENTRY *r_r, prs_struct *ps, int depth) { - if (r_r == NULL) return False; + if (r_r == NULL) + return False; prs_debug(ps, depth, desc, "reg_io_r_open_entry"); depth++; - prs_align(ps); + if(prs_align(ps)) + return False; - smb_io_pol_hnd("", &(r_r->pol), ps, depth); + if(!smb_io_pol_hnd("", &r_r->pol, ps, depth)) + return False; - prs_uint32("status", ps, depth, &(r_r->status)); + if(!prs_uint32("status", ps, depth, &r_r->status)) + return False; return True; } - -/******************************************************************* -makes a structure. -********************************************************************/ -BOOL make_reg_q_shutdown(REG_Q_SHUTDOWN *q_i, - const char *msg, uint32 timeout, uint16 flags) -{ - int len = strlen(msg) + 1; - - if (q_i == NULL) return False; - - ZERO_STRUCTP(q_i); - - q_i->ptr_0 = 1; - q_i->ptr_1 = 1; - q_i->ptr_2 = 1; - - make_uni_hdr(&q_i->hdr_msg, len); - make_unistr2(&(q_i->uni_msg), msg, len); - - q_i->timeout = timeout; - q_i->flags = flags; - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL reg_io_q_shutdown(char *desc, REG_Q_SHUTDOWN *q_q, prs_struct *ps, int depth) -{ - if (q_q == NULL) return False; - - prs_debug(ps, depth, desc, "reg_io_q_shutdown"); - depth++; - - prs_align(ps); - - prs_uint32("ptr_0", ps, depth, &(q_q->ptr_0)); - prs_uint32("ptr_1", ps, depth, &(q_q->ptr_1)); - prs_uint32("ptr_2", ps, depth, &(q_q->ptr_2)); - - smb_io_unihdr ("hdr_msg", &(q_q->hdr_msg), ps, depth); - smb_io_unistr2("uni_msg", &(q_q->uni_msg), q_q->hdr_msg.buffer, ps, depth); - prs_align(ps); - - prs_uint32("timeout", ps, depth, &(q_q->timeout)); - prs_uint16("flags ", ps, depth, &(q_q->flags )); - prs_align(ps); - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL reg_io_r_shutdown(char *desc, REG_R_SHUTDOWN *r_q, prs_struct *ps, int depth) -{ - if (r_q == NULL) return False; - - prs_debug(ps, depth, desc, "reg_io_r_shutdown"); - depth++; - - prs_align(ps); - - prs_uint32("status", ps, depth, &(r_q->status)); - - return True; -} - diff --git a/source3/rpc_parse/parse_rpc.c b/source3/rpc_parse/parse_rpc.c index ac6ea8ea7e..d4ea84628a 100644 --- a/source3/rpc_parse/parse_rpc.c +++ b/source3/rpc_parse/parse_rpc.c @@ -3,9 +3,10 @@ * Unix SMB/Netbios implementation. * Version 1.9. * RPC Pipe client / server routines - * Copyright (C) Andrew Tridgell 1992-1999, - * Copyright (C) Luke Kenneth Casson Leighton 1996-1999, - * Copyright (C) Paul Ashton 1997-1999. + * Copyright (C) Andrew Tridgell 1992-1997, + * Copyright (C) Luke Kenneth Casson Leighton 1996-1997, + * Copyright (C) Paul Ashton 1997. + * Copyright (C) Jeremy Allison 1999. * * 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 @@ -32,501 +33,476 @@ extern int DEBUGLEVEL; interface/version dce/rpc pipe identification ********************************************************************/ -#define TRANS_SYNT_V2 \ -{ \ - { \ - 0x04, 0x5d, 0x88, 0x8a, \ - 0xeb, 0x1c, 0xc9, 0x11, \ - 0x9f, 0xe8, 0x08, 0x00, \ - 0x2b, 0x10, 0x48, 0x60 \ - }, 0x02 \ -} \ - -#define SYNT_SVCCTL_V2 \ -{ \ - { \ - 0x81, 0xbb, 0x7a, 0x36, \ - 0x44, 0x98, 0xf1, 0x35, \ - 0xad, 0x32, 0x98, 0xf0, \ - 0x38, 0x00, 0x10, 0x03 \ - }, 0x02 \ -} \ - -#define SYNT_BROWSER_V0 \ -{ \ - { \ - 0x98, 0xd0, 0xff, 0x6b, \ - 0x12, 0xa1, 0x10, 0x36, \ - 0x98, 0x33, 0x01, 0x28, \ - 0x92, 0x02, 0x01, 0x62 \ - }, 0x00 \ -} \ - -#define SYNT_NETLOGON_V2 \ -{ \ - { \ - 0x04, 0x5d, 0x88, 0x8a, \ - 0xeb, 0x1c, 0xc9, 0x11, \ - 0x9f, 0xe8, 0x08, 0x00, \ - 0x2b, 0x10, 0x48, 0x60 \ - }, 0x02 \ -} \ - -#define SYNT_WKSSVC_V1 \ -{ \ - { \ - 0x98, 0xd0, 0xff, 0x6b, \ - 0x12, 0xa1, 0x10, 0x36, \ - 0x98, 0x33, 0x46, 0xc3, \ - 0xf8, 0x7e, 0x34, 0x5a \ - }, 0x01 \ -} \ - -#define SYNT_SRVSVC_V3 \ -{ \ - { \ - 0xc8, 0x4f, 0x32, 0x4b, \ - 0x70, 0x16, 0xd3, 0x01, \ - 0x12, 0x78, 0x5a, 0x47, \ - 0xbf, 0x6e, 0xe1, 0x88 \ - }, 0x03 \ -} \ - -#define SYNT_LSARPC_V0 \ -{ \ - { \ - 0x78, 0x57, 0x34, 0x12, \ - 0x34, 0x12, 0xcd, 0xab, \ - 0xef, 0x00, 0x01, 0x23, \ - 0x45, 0x67, 0x89, 0xab \ - }, 0x00 \ -} \ - -#define SYNT_SAMR_V1 \ -{ \ - { \ - 0x78, 0x57, 0x34, 0x12, \ - 0x34, 0x12, 0xcd, 0xab, \ - 0xef, 0x00, 0x01, 0x23, \ - 0x45, 0x67, 0x89, 0xac \ - }, 0x01 \ -} \ - -#define SYNT_NETLOGON_V1 \ -{ \ - { \ - 0x78, 0x56, 0x34, 0x12, \ - 0x34, 0x12, 0xcd, 0xab, \ - 0xef, 0x00, 0x01, 0x23, \ - 0x45, 0x67, 0xcf, 0xfb \ - }, 0x01 \ -} \ - -#define SYNT_WINREG_V1 \ -{ \ - { \ - 0x01, 0xd0, 0x8c, 0x33, \ - 0x44, 0x22, 0xf1, 0x31, \ - 0xaa, 0xaa, 0x90, 0x00, \ - 0x38, 0x00, 0x10, 0x03 \ - }, 0x01 \ -} \ - -#define SYNT_ATSVC_V1 \ -{ \ - { \ - 0x82, 0x06, 0xf7, 0x1f, \ - 0x51, 0x0a, 0xe8, 0x30, \ - 0x07, 0x6d, 0x74, 0x0b, \ - 0xe8, 0xce, 0xe9, 0x8b \ - }, 0x01 \ -} \ - -#define SYNT_SPOOLSS_V1 \ -{ \ - { \ - 0x78, 0x56, 0x34, 0x12, \ - 0x34, 0x12, 0xcd, 0xab, \ - 0xef, 0x00, 0x01, 0x23, \ - 0x45, 0x67, 0x89, 0xab \ - }, 0x01 \ -} \ - -#define SYNT_NONE_V0 \ -{ \ - { \ - 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00 \ - }, 0x00 \ -} \ - -#define SYNT_EVENTLOG_V0 \ -{ \ - { \ - 0xdc, 0x3f, 0x27, 0x82, \ - 0x2a, 0xe3, 0xc3, 0x18, \ - 0x3f, 0x78, 0x82, 0x79, \ - 0x29, 0xdc, 0x23, 0xea \ - }, 0x00 \ -} - \ +#define TRANS_SYNT_V2 \ +{ \ + { \ + 0x8a885d04, 0x1ceb, 0x11c9, \ + { 0x9f, 0xe8, 0x08, 0x00, \ + 0x2b, 0x10, 0x48, 0x60 } \ + }, 0x02 \ +} + +#define SYNT_NETLOGON_V2 \ +{ \ + { \ + 0x8a885d04, 0x1ceb, 0x11c9, \ + { 0x9f, 0xe8, 0x08, 0x00, \ + 0x2b, 0x10, 0x48, 0x60 } \ + }, 0x02 \ +} + +#define SYNT_WKSSVC_V1 \ +{ \ + { \ + 0x6bffd098, 0xa112, 0x3610, \ + { 0x98, 0x33, 0x46, 0xc3, \ + 0xf8, 0x7e, 0x34, 0x5a } \ + }, 0x01 \ +} + +#define SYNT_SRVSVC_V3 \ +{ \ + { \ + 0x4b324fc8, 0x1670, 0x01d3, \ + { 0x12, 0x78, 0x5a, 0x47, \ + 0xbf, 0x6e, 0xe1, 0x88 } \ + }, 0x03 \ +} + +#define SYNT_LSARPC_V0 \ +{ \ + { \ + 0x12345778, 0x1234, 0xabcd, \ + { 0xef, 0x00, 0x01, 0x23, \ + 0x45, 0x67, 0x89, 0xab } \ + }, 0x00 \ +} + +#define SYNT_SAMR_V1 \ +{ \ + { \ + 0x12345778, 0x1234, 0xabcd, \ + { 0xef, 0x00, 0x01, 0x23, \ + 0x45, 0x67, 0x89, 0xac } \ + }, 0x01 \ +} + +#define SYNT_NETLOGON_V1 \ +{ \ + { \ + 0x12345678, 0x1234, 0xabcd, \ + { 0xef, 0x00, 0x01, 0x23, \ + 0x45, 0x67, 0xcf, 0xfb } \ + }, 0x01 \ +} + +#define SYNT_WINREG_V1 \ +{ \ + { \ + 0x338cd001, 0x2244, 0x31f1, \ + { 0xaa, 0xaa, 0x90, 0x00, \ + 0x38, 0x00, 0x10, 0x03 } \ + }, 0x01 \ +} + +#define SYNT_NONE_V0 \ +{ \ + { \ + 0x0, 0x0, 0x0, \ + { 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00 } \ + }, 0x00 \ +} + +/* pipe string names */ +#define PIPE_SRVSVC "\\PIPE\\srvsvc" +#define PIPE_SAMR "\\PIPE\\samr" +#define PIPE_WINREG "\\PIPE\\winreg" +#define PIPE_WKSSVC "\\PIPE\\wkssvc" +#define PIPE_NETLOGON "\\PIPE\\NETLOGON" +#define PIPE_NTLSA "\\PIPE\\ntlsa" +#define PIPE_NTSVCS "\\PIPE\\ntsvcs" +#define PIPE_LSASS "\\PIPE\\lsass" +#define PIPE_LSARPC "\\PIPE\\lsarpc" + struct pipe_id_info pipe_names [] = { /* client pipe , abstract syntax , server pipe , transfer syntax */ { PIPE_LSARPC , SYNT_LSARPC_V0 , PIPE_LSASS , TRANS_SYNT_V2 }, - { PIPE_BROWSER , SYNT_BROWSER_V0 , PIPE_NTSVCS , TRANS_SYNT_V2 }, { PIPE_SAMR , SYNT_SAMR_V1 , PIPE_LSASS , TRANS_SYNT_V2 }, { PIPE_NETLOGON, SYNT_NETLOGON_V1, PIPE_LSASS , TRANS_SYNT_V2 }, { PIPE_SRVSVC , SYNT_SRVSVC_V3 , PIPE_NTSVCS , TRANS_SYNT_V2 }, - { PIPE_SVCCTL , SYNT_SVCCTL_V2 , PIPE_NTSVCS , TRANS_SYNT_V2 }, { PIPE_WKSSVC , SYNT_WKSSVC_V1 , PIPE_NTSVCS , TRANS_SYNT_V2 }, { PIPE_WINREG , SYNT_WINREG_V1 , PIPE_WINREG , TRANS_SYNT_V2 }, - { PIPE_ATSVC , SYNT_ATSVC_V1 , PIPE_ATSVC , TRANS_SYNT_V2 }, - { PIPE_SPOOLSS , SYNT_SPOOLSS_V1 , PIPE_SPOOLSS , TRANS_SYNT_V2 }, - { PIPE_EVENTLOG, SYNT_EVENTLOG_V0, PIPE_EVENTLOG , TRANS_SYNT_V2 }, { NULL , SYNT_NONE_V0 , NULL , SYNT_NONE_V0 } }; /******************************************************************* -creates an RPC_HDR structure. + Inits an RPC_HDR structure. ********************************************************************/ -BOOL make_rpc_hdr(RPC_HDR *hdr, enum RPC_PKT_TYPE pkt_type, uint8 flags, + +void init_rpc_hdr(RPC_HDR *hdr, enum RPC_PKT_TYPE pkt_type, uint8 flags, uint32 call_id, int data_len, int auth_len) { - if (hdr == NULL) return False; - hdr->major = 5; /* RPC version 5 */ hdr->minor = 0; /* minor version 0 */ hdr->pkt_type = pkt_type; /* RPC packet type */ hdr->flags = flags; /* dce/rpc flags */ - hdr->pack_type = 0x10; /* packed data representation */ + hdr->pack_type[0] = 0x10; /* little-endian data representation */ + hdr->pack_type[1] = 0; /* packed data representation */ + hdr->pack_type[2] = 0; /* packed data representation */ + hdr->pack_type[3] = 0; /* packed data representation */ hdr->frag_len = data_len; /* fragment length, fill in later */ hdr->auth_len = auth_len; /* authentication length */ hdr->call_id = call_id; /* call identifier - match incoming RPC */ - - return True; } /******************************************************************* -reads or writes an RPC_HDR structure. + Reads or writes an RPC_HDR structure. ********************************************************************/ + BOOL smb_io_rpc_hdr(char *desc, RPC_HDR *rpc, prs_struct *ps, int depth) { - if (rpc == NULL) return False; + if (rpc == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_rpc_hdr"); depth++; - prs_uint8 ("major ", ps, depth, &(rpc->major)); - prs_uint8 ("minor ", ps, depth, &(rpc->minor)); - prs_uint8 ("pkt_type ", ps, depth, &(rpc->pkt_type)); - prs_uint8 ("flags ", ps, depth, &(rpc->flags)); - prs_uint32("pack_type ", ps, depth, &(rpc->pack_type)); - prs_uint16("frag_len ", ps, depth, &(rpc->frag_len)); - prs_uint16("auth_len ", ps, depth, &(rpc->auth_len)); - prs_uint32("call_id ", ps, depth, &(rpc->call_id)); - - return True; -} + if(!prs_uint8 ("major ", ps, depth, &rpc->major)) + return False; -/******************************************************************* -reads or writes an RPC_HDR_FAULT structure. -********************************************************************/ -BOOL smb_io_rpc_hdr_fault(char *desc, RPC_HDR_FAULT *rpc, prs_struct *ps, int depth) -{ - if (rpc == NULL) return False; + if(!prs_uint8 ("minor ", ps, depth, &rpc->minor)) + return False; + if(!prs_uint8 ("pkt_type ", ps, depth, &rpc->pkt_type)) + return False; + if(!prs_uint8 ("flags ", ps, depth, &rpc->flags)) + return False; + if(!prs_uint8("pack_type0", ps, depth, &rpc->pack_type[0])) + return False; + if(!prs_uint8("pack_type1", ps, depth, &rpc->pack_type[1])) + return False; + if(!prs_uint8("pack_type2", ps, depth, &rpc->pack_type[2])) + return False; + if(!prs_uint8("pack_type3", ps, depth, &rpc->pack_type[3])) + return False; - prs_debug(ps, depth, desc, "smb_io_rpc_hdr_fault"); - depth++; + /* + * If reading and pack_type[0] == 0 then the data is in big-endian + * format. Set the flag in the prs_struct to specify reverse-endainness. + */ - prs_uint32("status ", ps, depth, &(rpc->status )); - prs_uint32("reserved", ps, depth, &(rpc->reserved)); + if (ps->io && rpc->pack_type[0] == 0) { + DEBUG(10,("smb_io_rpc_hdr: PDU data format is big-endian. Setting flag.\n")); + prs_set_bigendian_data(ps); + } + if(!prs_uint16("frag_len ", ps, depth, &rpc->frag_len)) + return False; + if(!prs_uint16("auth_len ", ps, depth, &rpc->auth_len)) + return False; + if(!prs_uint32("call_id ", ps, depth, &rpc->call_id)) + return False; return True; } /******************************************************************* -reads or writes an RPC_IFACE structure. + Reads or writes an RPC_IFACE structure. ********************************************************************/ -static BOOL smb_io_rpc_iface(char *desc, RPC_IFACE *ifc, prs_struct *ps, int depth) + +static BOOL smb_io_rpc_iface(char *desc, RPC_IFACE *ifc, prs_struct *ps, int depth) { - if (ifc == NULL) return False; + if (ifc == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_rpc_iface"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; + + if(!prs_uint32 ("data ", ps, depth, &ifc->uuid.time_low)) + return False; + if(!prs_uint16 ("data ", ps, depth, &ifc->uuid.time_mid)) + return False; + if(!prs_uint16 ("data ", ps, depth, &ifc->uuid.time_hi_and_version)) + return False; - prs_uint8s (False, "data ", ps, depth, ifc->data, sizeof(ifc->data)); - prs_uint32 ( "version", ps, depth, &(ifc->version)); + if(!prs_uint8s (False, "data ", ps, depth, ifc->uuid.remaining, sizeof(ifc->uuid.remaining))) + return False; + if(!prs_uint32 ( "version", ps, depth, &(ifc->version))) + return False; return True; } /******************************************************************* -creates an RPC_ADDR_STR structure. - -The name can be null (RPC Alter-Context) + Inits an RPC_ADDR_STR structure. ********************************************************************/ -static BOOL make_rpc_addr_str(RPC_ADDR_STR *str, const char *name) -{ - if (str == NULL ) return False; - if (name == NULL) - { - str->len = 1; - fstrcpy(str->str, ""); - } - else - { - str->len = strlen(name) + 1; - fstrcpy(str->str, name); - } - return True; +static void init_rpc_addr_str(RPC_ADDR_STR *str, char *name) +{ + str->len = strlen(name) + 1; + fstrcpy(str->str, name); } /******************************************************************* -reads or writes an RPC_ADDR_STR structure. + Reads or writes an RPC_ADDR_STR structure. ********************************************************************/ + static BOOL smb_io_rpc_addr_str(char *desc, RPC_ADDR_STR *str, prs_struct *ps, int depth) { - if (str == NULL) return False; + if (str == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_rpc_addr_str"); depth++; - prs_align(ps); - - prs_uint16 ( "len", ps, depth, &(str->len)); - prs_uint8s (True, "str", ps, depth, (uchar*)str->str, str->len); + if(!prs_align(ps)) + return False; + if(!prs_uint16 ( "len", ps, depth, &str->len)) + return False; + if(!prs_uint8s (True, "str", ps, depth, (uchar*)str->str, MIN(str->len, sizeof(str->str)) )) + return False; return True; } /******************************************************************* -creates an RPC_HDR_BBA structure. + Inits an RPC_HDR_BBA structure. ********************************************************************/ -static BOOL make_rpc_hdr_bba(RPC_HDR_BBA *bba, uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid) -{ - if (bba == NULL) return False; +static void init_rpc_hdr_bba(RPC_HDR_BBA *bba, uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid) +{ bba->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */ bba->max_rsize = max_rsize; /* max receive fragment size (0x1630) */ bba->assoc_gid = assoc_gid; /* associated group id (0x0) */ - - return True; } /******************************************************************* -reads or writes an RPC_HDR_BBA structure. + Reads or writes an RPC_HDR_BBA structure. ********************************************************************/ + static BOOL smb_io_rpc_hdr_bba(char *desc, RPC_HDR_BBA *rpc, prs_struct *ps, int depth) { - if (rpc == NULL) return False; + if (rpc == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_rpc_hdr_bba"); depth++; - prs_uint16("max_tsize", ps, depth, &(rpc->max_tsize)); - prs_uint16("max_rsize", ps, depth, &(rpc->max_rsize)); - prs_uint32("assoc_gid", ps, depth, &(rpc->assoc_gid)); - + if(!prs_uint16("max_tsize", ps, depth, &rpc->max_tsize)) + return False; + if(!prs_uint16("max_rsize", ps, depth, &rpc->max_rsize)) + return False; + if(!prs_uint32("assoc_gid", ps, depth, &rpc->assoc_gid)) + return False; return True; } /******************************************************************* -creates an RPC_HDR_RB structure. + Inits an RPC_HDR_RB structure. ********************************************************************/ -BOOL make_rpc_hdr_rb(RPC_HDR_RB *rpc, + +void init_rpc_hdr_rb(RPC_HDR_RB *rpc, uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid, uint32 num_elements, uint16 context_id, uint8 num_syntaxes, RPC_IFACE *abstract, RPC_IFACE *transfer) { - if (rpc == NULL) return False; - - make_rpc_hdr_bba(&(rpc->bba), max_tsize, max_rsize, assoc_gid); + init_rpc_hdr_bba(&rpc->bba, max_tsize, max_rsize, assoc_gid); rpc->num_elements = num_elements ; /* the number of elements (0x1) */ rpc->context_id = context_id ; /* presentation context identifier (0x0) */ rpc->num_syntaxes = num_syntaxes ; /* the number of syntaxes (has always been 1?)(0x1) */ /* num and vers. of interface client is using */ - memcpy(&(rpc->abstract), abstract, sizeof(rpc->abstract)); + rpc->abstract = *abstract; /* num and vers. of interface to use for replies */ - memcpy(&(rpc->transfer), transfer, sizeof(rpc->transfer)); - - return True; + rpc->transfer = *transfer; } /******************************************************************* -reads or writes an RPC_HDR_RB structure. + Reads or writes an RPC_HDR_RB structure. ********************************************************************/ -BOOL smb_io_rpc_hdr_rb(char *desc, RPC_HDR_RB *rpc, prs_struct *ps, int depth) + +BOOL smb_io_rpc_hdr_rb(char *desc, RPC_HDR_RB *rpc, prs_struct *ps, int depth) { - if (rpc == NULL) return False; + if (rpc == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_rpc_hdr_rb"); depth++; - smb_io_rpc_hdr_bba("", &(rpc->bba), ps, depth); + if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth)) + return False; - prs_uint32("num_elements", ps, depth, &(rpc->num_elements)); - prs_uint16("context_id ", ps, depth, &(rpc->context_id )); - prs_uint8 ("num_syntaxes", ps, depth, &(rpc->num_syntaxes)); + if(!prs_uint32("num_elements", ps, depth, &rpc->num_elements)) + return False; + if(!prs_uint16("context_id ", ps, depth, &rpc->context_id )) + return False; + if(!prs_uint8 ("num_syntaxes", ps, depth, &rpc->num_syntaxes)) + return False; - smb_io_rpc_iface("", &(rpc->abstract), ps, depth); - smb_io_rpc_iface("", &(rpc->transfer), ps, depth); + if(!smb_io_rpc_iface("", &rpc->abstract, ps, depth)) + return False; + if(!smb_io_rpc_iface("", &rpc->transfer, ps, depth)) + return False; return True; } /******************************************************************* -creates an RPC_RESULTS structure. - -lkclXXXX only one reason at the moment! + Inits an RPC_RESULTS structure. + lkclXXXX only one reason at the moment! ********************************************************************/ -static BOOL make_rpc_results(RPC_RESULTS *res, + +static void init_rpc_results(RPC_RESULTS *res, uint8 num_results, uint16 result, uint16 reason) { - if (res == NULL) return False; - res->num_results = num_results; /* the number of results (0x01) */ res->result = result ; /* result (0x00 = accept) */ res->reason = reason ; /* reason (0x00 = no reason specified) */ - - return True; } /******************************************************************* -reads or writes an RPC_RESULTS structure. - -lkclXXXX only one reason at the moment! + Reads or writes an RPC_RESULTS structure. + lkclXXXX only one reason at the moment! ********************************************************************/ -static BOOL smb_io_rpc_results(char *desc, RPC_RESULTS *res, prs_struct *ps, int depth) + +static BOOL smb_io_rpc_results(char *desc, RPC_RESULTS *res, prs_struct *ps, int depth) { - if (res == NULL) return False; + if (res == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_rpc_results"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint8 ("num_results", ps, depth, &(res->num_results)); + if(!prs_uint8 ("num_results", ps, depth, &res->num_results)) + return False; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint16("result ", ps, depth, &(res->result )); - prs_uint16("reason ", ps, depth, &(res->reason )); - + if(!prs_uint16("result ", ps, depth, &res->result)) + return False; + if(!prs_uint16("reason ", ps, depth, &res->reason)) + return False; return True; } /******************************************************************* -creates an RPC_HDR_BA structure. + Init an RPC_HDR_BA structure. -lkclXXXX only one reason at the moment! -jfm: nope two ! The pipe_addr can be NULL ! + lkclXXXX only one reason at the moment! ********************************************************************/ -BOOL make_rpc_hdr_ba(RPC_HDR_BA *rpc, + +void init_rpc_hdr_ba(RPC_HDR_BA *rpc, uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid, - const char *pipe_addr, + char *pipe_addr, uint8 num_results, uint16 result, uint16 reason, RPC_IFACE *transfer) { - if (rpc == NULL || transfer == NULL) return False; - - make_rpc_hdr_bba (&(rpc->bba ), max_tsize, max_rsize, assoc_gid); - make_rpc_addr_str(&(rpc->addr), pipe_addr); - make_rpc_results (&(rpc->res ), num_results, result, reason); + init_rpc_hdr_bba (&rpc->bba, max_tsize, max_rsize, assoc_gid); + init_rpc_addr_str(&rpc->addr, pipe_addr); + init_rpc_results (&rpc->res, num_results, result, reason); /* the transfer syntax from the request */ - memcpy(&(rpc->transfer), transfer, sizeof(rpc->transfer)); - - return True; + memcpy(&rpc->transfer, transfer, sizeof(rpc->transfer)); } /******************************************************************* -reads or writes an RPC_HDR_BA structure. + Reads or writes an RPC_HDR_BA structure. ********************************************************************/ -BOOL smb_io_rpc_hdr_ba(char *desc, RPC_HDR_BA *rpc, prs_struct *ps, int depth) + +BOOL smb_io_rpc_hdr_ba(char *desc, RPC_HDR_BA *rpc, prs_struct *ps, int depth) { - if (rpc == NULL) return False; + if (rpc == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_rpc_hdr_ba"); depth++; - smb_io_rpc_hdr_bba ("", &(rpc->bba) , ps, depth); - smb_io_rpc_addr_str("", &(rpc->addr) , ps, depth); - smb_io_rpc_results ("", &(rpc->res) , ps, depth); - smb_io_rpc_iface ("", &(rpc->transfer), ps, depth); - + if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth)) + return False; + if(!smb_io_rpc_addr_str("", &rpc->addr, ps, depth)) + return False; + if(!smb_io_rpc_results("", &rpc->res, ps, depth)) + return False; + if(!smb_io_rpc_iface("", &rpc->transfer, ps, depth)) + return False; return True; } /******************************************************************* -creates an RPC_HDR_REQ structure. + Init an RPC_HDR_REQ structure. ********************************************************************/ -BOOL make_rpc_hdr_req(RPC_HDR_REQ *hdr, uint32 alloc_hint, uint16 opnum) -{ - if (hdr == NULL) return False; +void init_rpc_hdr_req(RPC_HDR_REQ *hdr, uint32 alloc_hint, uint16 opnum) +{ hdr->alloc_hint = alloc_hint; /* allocation hint */ hdr->context_id = 0; /* presentation context identifier */ hdr->opnum = opnum; /* opnum */ - - return True; } /******************************************************************* -reads or writes an RPC_HDR_REQ structure. + Reads or writes an RPC_HDR_REQ structure. ********************************************************************/ -BOOL smb_io_rpc_hdr_req(char *desc, RPC_HDR_REQ *rpc, prs_struct *ps, int depth) + +BOOL smb_io_rpc_hdr_req(char *desc, RPC_HDR_REQ *rpc, prs_struct *ps, int depth) { - if (rpc == NULL) return False; + if (rpc == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_rpc_hdr_req"); depth++; - prs_uint32("alloc_hint", ps, depth, &(rpc->alloc_hint)); - prs_uint16("context_id", ps, depth, &(rpc->context_id)); - prs_uint16("opnum ", ps, depth, &(rpc->opnum)); - + if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint)) + return False; + if(!prs_uint16("context_id", ps, depth, &rpc->context_id)) + return False; + if(!prs_uint16("opnum ", ps, depth, &rpc->opnum)) + return False; return True; } /******************************************************************* -reads or writes an RPC_HDR_RESP structure. + Reads or writes an RPC_HDR_RESP structure. ********************************************************************/ -BOOL smb_io_rpc_hdr_resp(char *desc, RPC_HDR_RESP *rpc, prs_struct *ps, int depth) + +BOOL smb_io_rpc_hdr_resp(char *desc, RPC_HDR_RESP *rpc, prs_struct *ps, int depth) { - if (rpc == NULL) return False; + if (rpc == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_rpc_hdr_resp"); depth++; - prs_uint32("alloc_hint", ps, depth, &(rpc->alloc_hint)); - prs_uint16("context_id", ps, depth, &(rpc->context_id)); - prs_uint8 ("cancel_ct ", ps, depth, &(rpc->cancel_count)); - prs_uint8 ("reserved ", ps, depth, &(rpc->reserved)); - + if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint)) + return False; + if(!prs_uint16("context_id", ps, depth, &rpc->context_id)) + return False; + if(!prs_uint8 ("cancel_ct ", ps, depth, &rpc->cancel_count)) + return False; + if(!prs_uint8 ("reserved ", ps, depth, &rpc->reserved)) + return False; return True; } /******************************************************************* -creates an RPC_HDR_AUTHA structure. + Init an RPC_HDR_AUTHA structure. ********************************************************************/ -BOOL make_rpc_hdr_autha(RPC_HDR_AUTHA *rai, + +void init_rpc_hdr_autha(RPC_HDR_AUTHA *rai, uint16 max_tsize, uint16 max_rsize, uint8 auth_type, uint8 auth_level, uint8 stub_type_len) { - if (rai == NULL) return False; - rai->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */ rai->max_rsize = max_rsize; /* max receive fragment size (0x1630) */ @@ -536,194 +512,228 @@ BOOL make_rpc_hdr_autha(RPC_HDR_AUTHA *rai, rai->padding = 0; /* padding 0x00 */ rai->unknown = 0x0014a0c0; /* non-zero pointer to something */ - - return True; } /******************************************************************* -reads or writes an RPC_HDR_AUTHA structure. + Reads or writes an RPC_HDR_AUTHA structure. ********************************************************************/ + BOOL smb_io_rpc_hdr_autha(char *desc, RPC_HDR_AUTHA *rai, prs_struct *ps, int depth) { - if (rai == NULL) return False; + if (rai == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_rpc_hdr_autha"); depth++; - prs_uint16("max_tsize ", ps, depth, &(rai->max_tsize)); - prs_uint16("max_rsize ", ps, depth, &(rai->max_rsize)); + if(!prs_uint16("max_tsize ", ps, depth, &rai->max_tsize)) + return False; + if(!prs_uint16("max_rsize ", ps, depth, &rai->max_rsize)) + return False; - prs_uint8 ("auth_type ", ps, depth, &(rai->auth_type )); /* 0x0a nt lm ssp */ - prs_uint8 ("auth_level ", ps, depth, &(rai->auth_level ));/* 0x06 */ - prs_uint8 ("stub_type_len", ps, depth, &(rai->stub_type_len)); - prs_uint8 ("padding ", ps, depth, &(rai->padding )); + if(!prs_uint8 ("auth_type ", ps, depth, &rai->auth_type)) /* 0x0a nt lm ssp */ + return False; + if(!prs_uint8 ("auth_level ", ps, depth, &rai->auth_level)) /* 0x06 */ + return False; + if(!prs_uint8 ("stub_type_len", ps, depth, &rai->stub_type_len)) + return False; + if(!prs_uint8 ("padding ", ps, depth, &rai->padding)) + return False; - prs_uint32("unknown ", ps, depth, &(rai->unknown )); /* 0x0014a0c0 */ + if(!prs_uint32("unknown ", ps, depth, &rai->unknown)) /* 0x0014a0c0 */ + return False; return True; } /******************************************************************* -checks an RPC_HDR_AUTH structure. + Checks an RPC_HDR_AUTH structure. ********************************************************************/ + BOOL rpc_hdr_auth_chk(RPC_HDR_AUTH *rai) { - return ((rai->auth_type == 0x0a || rai->auth_type == 0x44) && - rai->auth_level == 0x06); - - return True; + return (rai->auth_type == NTLMSSP_AUTH_TYPE && rai->auth_level == NTLMSSP_AUTH_LEVEL); } /******************************************************************* -creates an RPC_HDR_AUTH structure. + Inits an RPC_HDR_AUTH structure. ********************************************************************/ -BOOL make_rpc_hdr_auth(RPC_HDR_AUTH *rai, + +void init_rpc_hdr_auth(RPC_HDR_AUTH *rai, uint8 auth_type, uint8 auth_level, uint8 stub_type_len, uint32 ptr) { - if (rai == NULL) return False; - rai->auth_type = auth_type; /* nt lm ssp 0x0a */ rai->auth_level = auth_level; /* 0x06 */ rai->stub_type_len = stub_type_len; /* 0x00 */ rai->padding = 0; /* padding 0x00 */ rai->unknown = ptr; /* non-zero pointer to something */ - - return True; } /******************************************************************* -reads or writes an RPC_HDR_AUTH structure. + Reads or writes an RPC_HDR_AUTH structure. ********************************************************************/ + BOOL smb_io_rpc_hdr_auth(char *desc, RPC_HDR_AUTH *rai, prs_struct *ps, int depth) { - if (rai == NULL) return False; + if (rai == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_rpc_hdr_auth"); depth++; - prs_uint8 ("auth_type ", ps, depth, &(rai->auth_type )); /* 0x0a nt lm ssp */ - prs_uint8 ("auth_level ", ps, depth, &(rai->auth_level ));/* 0x06 */ - prs_uint8 ("stub_type_len", ps, depth, &(rai->stub_type_len)); - prs_uint8 ("padding ", ps, depth, &(rai->padding )); + if(!prs_align(ps)) + return False; + + if(!prs_uint8 ("auth_type ", ps, depth, &rai->auth_type)) /* 0x0a nt lm ssp */ + return False; + if(!prs_uint8 ("auth_level ", ps, depth, &rai->auth_level)) /* 0x06 */ + return False; + if(!prs_uint8 ("stub_type_len", ps, depth, &rai->stub_type_len)) + return False; + if(!prs_uint8 ("padding ", ps, depth, &rai->padding)) + return False; - prs_uint32("unknown ", ps, depth, &(rai->unknown )); /* 0x0014a0c0 */ + if(!prs_uint32("unknown ", ps, depth, &rai->unknown)) /* 0x0014a0c0 */ + return False; return True; } /******************************************************************* -checks an RPC_AUTH_NTLMSSP_VERIFIER structure. + Checks an RPC_AUTH_VERIFIER structure. ********************************************************************/ -BOOL rpc_auth_ntlmssp_verifier_chk(RPC_AUTH_NTLMSSP_VERIFIER *rav, + +BOOL rpc_auth_verifier_chk(RPC_AUTH_VERIFIER *rav, char *signature, uint32 msg_type) { return (strequal(rav->signature, signature) && rav->msg_type == msg_type); - - return True; } /******************************************************************* -creates an RPC_AUTH_NTLMSSP_VERIFIER structure. + Inits an RPC_AUTH_VERIFIER structure. ********************************************************************/ -BOOL make_rpc_auth_ntlmssp_verifier(RPC_AUTH_NTLMSSP_VERIFIER *rav, + +void init_rpc_auth_verifier(RPC_AUTH_VERIFIER *rav, char *signature, uint32 msg_type) { - if (rav == NULL) return False; - fstrcpy(rav->signature, signature); /* "NTLMSSP" */ rav->msg_type = msg_type; /* NTLMSSP_MESSAGE_TYPE */ - - return True; } /******************************************************************* -reads or writes an RPC_AUTH_NTLMSSP_VERIFIER structure. + Reads or writes an RPC_AUTH_VERIFIER structure. ********************************************************************/ -BOOL smb_io_rpc_auth_ntlmssp_verifier(char *desc, RPC_AUTH_NTLMSSP_VERIFIER *rav, prs_struct *ps, int depth) + +BOOL smb_io_rpc_auth_verifier(char *desc, RPC_AUTH_VERIFIER *rav, prs_struct *ps, int depth) { - if (rav == NULL) return False; + if (rav == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_rpc_auth_verifier"); depth++; - prs_string("signature", ps, depth, rav->signature, 0, sizeof(rav->signature)); /* "NTLMSSP" */ - prs_uint32("msg_type ", ps, depth, &(rav->msg_type )); /* NTLMSSP_MESSAGE_TYPE */ + /* "NTLMSSP" */ + if(!prs_string("signature", ps, depth, rav->signature, strlen("NTLMSSP"), + sizeof(rav->signature))) + return False; + if(!prs_uint32("msg_type ", ps, depth, &rav->msg_type)) /* NTLMSSP_MESSAGE_TYPE */ + return False; return True; } /******************************************************************* -creates an RPC_AUTH_NTLMSSP_NEG structure. + Inits an RPC_AUTH_NTLMSSP_NEG structure. ********************************************************************/ -BOOL make_rpc_auth_ntlmssp_neg(RPC_AUTH_NTLMSSP_NEG *neg, + +void init_rpc_auth_ntlmssp_neg(RPC_AUTH_NTLMSSP_NEG *neg, uint32 neg_flgs, fstring myname, fstring domain) { int len_myname = strlen(myname); int len_domain = strlen(domain); - if (neg == NULL) return False; - neg->neg_flgs = neg_flgs ; /* 0x00b2b3 */ - make_str_hdr(&neg->hdr_domain, len_domain, len_domain, 0x20 + len_myname); - make_str_hdr(&neg->hdr_myname, len_myname, len_myname, 0x20); + init_str_hdr(&neg->hdr_domain, len_domain, len_domain, 0x20 + len_myname); + init_str_hdr(&neg->hdr_myname, len_myname, len_myname, 0x20); fstrcpy(neg->myname, myname); fstrcpy(neg->domain, domain); - - return True; } /******************************************************************* -reads or writes an RPC_AUTH_NTLMSSP_NEG structure. - -*** lkclXXXX HACK ALERT! *** + Reads or writes an RPC_AUTH_NTLMSSP_NEG structure. + *** lkclXXXX HACK ALERT! *** ********************************************************************/ + BOOL smb_io_rpc_auth_ntlmssp_neg(char *desc, RPC_AUTH_NTLMSSP_NEG *neg, prs_struct *ps, int depth) { - if (neg == NULL) return False; + if (neg == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_neg"); depth++; - prs_uint32("neg_flgs ", ps, depth, &(neg->neg_flgs)); + if(!prs_uint32("neg_flgs ", ps, depth, &neg->neg_flgs)) + return False; - if (ps->io) - { + if (ps->io) { uint32 old_offset; + uint32 old_neg_flags = neg->neg_flgs; /* reading */ ZERO_STRUCTP(neg); - smb_io_strhdr("hdr_domain", &(neg->hdr_domain), ps, depth); - smb_io_strhdr("hdr_myname", &(neg->hdr_myname), ps, depth); + neg->neg_flgs = old_neg_flags; + + if(!smb_io_strhdr("hdr_domain", &neg->hdr_domain, ps, depth)) + return False; + if(!smb_io_strhdr("hdr_myname", &neg->hdr_myname, ps, depth)) + return False; + + old_offset = prs_offset(ps); - old_offset = ps->offset; + /* lkclXXXX HACK! */ + if(!prs_set_offset(ps, neg->hdr_myname.buffer + 0x50)) + return False; - ps->offset = neg->hdr_myname .buffer + 0x50; /* lkclXXXX HACK! */ - prs_uint8s(True , "myname", ps, depth, (uint8*)neg->myname , MIN(neg->hdr_myname .str_str_len, sizeof(neg->myname ))); - old_offset += neg->hdr_myname .str_str_len; + if(!prs_uint8s(True, "myname", ps, depth, (uint8*)neg->myname, + MIN(neg->hdr_myname.str_str_len, sizeof(neg->myname)))) + return False; + + old_offset += neg->hdr_myname.str_str_len; + + /* lkclXXXX HACK! */ + if(!prs_set_offset(ps, neg->hdr_domain.buffer + 0x50)) + return False; + + if(!prs_uint8s(True, "domain", ps, depth, (uint8*)neg->domain, + MIN(neg->hdr_domain.str_str_len, sizeof(neg->domain )))) + return False; - ps->offset = neg->hdr_domain .buffer + 0x50; /* lkclXXXX HACK! */ - prs_uint8s(True , "domain", ps, depth, (uint8*)neg->domain , MIN(neg->hdr_domain .str_str_len, sizeof(neg->domain ))); old_offset += neg->hdr_domain .str_str_len; - ps->offset = old_offset; - } - else - { + if(!prs_set_offset(ps, old_offset)) + return False; + } else { /* writing */ - smb_io_strhdr("hdr_domain", &(neg->hdr_domain), ps, depth); - smb_io_strhdr("hdr_myname", &(neg->hdr_myname), ps, depth); - - prs_uint8s(True , "myname", ps, depth, (uint8*)neg->myname , MIN(neg->hdr_myname .str_str_len, sizeof(neg->myname ))); - prs_uint8s(True , "domain", ps, depth, (uint8*)neg->domain , MIN(neg->hdr_domain .str_str_len, sizeof(neg->domain ))); + if(!smb_io_strhdr("hdr_domain", &neg->hdr_domain, ps, depth)) + return False; + if(!smb_io_strhdr("hdr_myname", &neg->hdr_myname, ps, depth)) + return False; + + if(!prs_uint8s(True, "myname", ps, depth, (uint8*)neg->myname, + MIN(neg->hdr_myname.str_str_len, sizeof(neg->myname)))) + return False; + if(!prs_uint8s(True, "domain", ps, depth, (uint8*)neg->domain, + MIN(neg->hdr_domain.str_str_len, sizeof(neg->domain )))) + return False; } return True; @@ -732,76 +742,72 @@ BOOL smb_io_rpc_auth_ntlmssp_neg(char *desc, RPC_AUTH_NTLMSSP_NEG *neg, prs_stru /******************************************************************* creates an RPC_AUTH_NTLMSSP_CHAL structure. ********************************************************************/ -BOOL make_rpc_auth_ntlmssp_chal(RPC_AUTH_NTLMSSP_CHAL *chl, + +void init_rpc_auth_ntlmssp_chal(RPC_AUTH_NTLMSSP_CHAL *chl, uint32 neg_flags, uint8 challenge[8]) { - if (chl == NULL) return False; - chl->unknown_1 = 0x0; chl->unknown_2 = 0x00000028; chl->neg_flags = neg_flags; /* 0x0082b1 */ memcpy(chl->challenge, challenge, sizeof(chl->challenge)); - bzero (chl->reserved , sizeof(chl->reserved)); - - return True; + memset((char *)chl->reserved , '\0', sizeof(chl->reserved)); } /******************************************************************* -reads or writes an RPC_AUTH_NTLMSSP_CHAL structure. + Reads or writes an RPC_AUTH_NTLMSSP_CHAL structure. ********************************************************************/ + BOOL smb_io_rpc_auth_ntlmssp_chal(char *desc, RPC_AUTH_NTLMSSP_CHAL *chl, prs_struct *ps, int depth) { - if (chl == NULL) return False; + if (chl == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_chal"); depth++; - prs_uint32("unknown_1", ps, depth, &(chl->unknown_1)); /* 0x0000 0000 */ - prs_uint32("unknown_2", ps, depth, &(chl->unknown_2)); /* 0x0000 b2b3 */ - prs_uint32("neg_flags", ps, depth, &(chl->neg_flags)); /* 0x0000 82b1 */ + if(!prs_uint32("unknown_1", ps, depth, &chl->unknown_1)) /* 0x0000 0000 */ + return False; + if(!prs_uint32("unknown_2", ps, depth, &chl->unknown_2)) /* 0x0000 b2b3 */ + return False; + if(!prs_uint32("neg_flags", ps, depth, &chl->neg_flags)) /* 0x0000 82b1 */ + return False; - prs_uint8s (False, "challenge", ps, depth, chl->challenge, sizeof(chl->challenge)); - prs_uint8s (False, "reserved ", ps, depth, chl->reserved , sizeof(chl->reserved )); + if(!prs_uint8s (False, "challenge", ps, depth, chl->challenge, sizeof(chl->challenge))) + return False; + if(!prs_uint8s (False, "reserved ", ps, depth, chl->reserved , sizeof(chl->reserved ))) + return False; return True; } /******************************************************************* -creates an RPC_AUTH_NTLMSSP_RESP structure. - -*** lkclXXXX FUDGE! HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) *** -*** lkclXXXX the actual offset is at the start of the auth verifier *** + Inits an RPC_AUTH_NTLMSSP_RESP structure. + *** lkclXXXX FUDGE! HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) *** + *** lkclXXXX the actual offset is at the start of the auth verifier *** ********************************************************************/ -BOOL make_rpc_auth_ntlmssp_resp(RPC_AUTH_NTLMSSP_RESP *rsp, - uchar lm_resp[24], - uchar *nt_resp, size_t nt_len, + +void init_rpc_auth_ntlmssp_resp(RPC_AUTH_NTLMSSP_RESP *rsp, + uchar lm_resp[24], uchar nt_resp[24], char *domain, char *user, char *wks, uint32 neg_flags) { uint32 offset; int dom_len = strlen(domain); - int wks_len = strlen(wks ); - int usr_len = strlen(user ); - int lm_len = nt_len != 0 ? (lm_resp != NULL ? 24 : 0) : 1; + int wks_len = strlen(wks); + int usr_len = strlen(user); + int lm_len = (lm_resp != NULL) ? 24 : 0; + int nt_len = (nt_resp != NULL) ? 24 : 0; DEBUG(5,("make_rpc_auth_ntlmssp_resp\n")); - if (rsp == NULL) return False; - #ifdef DEBUG_PASSWORD DEBUG(100,("lm_resp\n")); - if (lm_resp != NULL) - { - dump_data(100, lm_resp, lm_len); - } + dump_data(100, (char *)lm_resp, 24); DEBUG(100,("nt_resp\n")); - if (nt_resp != NULL) - { - dump_data(100, nt_resp, nt_len); - } + dump_data(100, (char *)nt_resp, 24); #endif DEBUG(6,("dom: %s user: %s wks: %s neg_flgs: 0x%x\n", @@ -816,153 +822,190 @@ BOOL make_rpc_auth_ntlmssp_resp(RPC_AUTH_NTLMSSP_RESP *rsp, usr_len *= 2; } - make_str_hdr(&rsp->hdr_domain , dom_len, dom_len, offset); + init_str_hdr(&rsp->hdr_domain, dom_len, dom_len, offset); offset += dom_len; - make_str_hdr(&rsp->hdr_usr , usr_len, usr_len, offset); + init_str_hdr(&rsp->hdr_usr, usr_len, usr_len, offset); offset += usr_len; - make_str_hdr(&rsp->hdr_wks , wks_len, wks_len, offset); + init_str_hdr(&rsp->hdr_wks, wks_len, wks_len, offset); offset += wks_len; - make_str_hdr(&rsp->hdr_lm_resp, lm_len , lm_len , offset); + init_str_hdr(&rsp->hdr_lm_resp, lm_len, lm_len, offset); offset += lm_len; - make_str_hdr(&rsp->hdr_nt_resp, nt_len , nt_len , offset); + init_str_hdr(&rsp->hdr_nt_resp, nt_len, nt_len, offset); offset += nt_len; - make_str_hdr(&rsp->hdr_sess_key, 0, 0, offset); + init_str_hdr(&rsp->hdr_sess_key, 0, 0, offset); rsp->neg_flags = neg_flags; - if (lm_resp != NULL && lm_len != 1) - { - memcpy(rsp->lm_resp, lm_resp, lm_len); - } - else - { - rsp->lm_resp[0] = 0; - } - if (nt_resp != NULL) - { - memcpy(rsp->nt_resp, nt_resp, nt_len); - } - else - { - rsp->nt_resp[0] = 0; - } + memcpy(rsp->lm_resp, lm_resp, 24); + memcpy(rsp->nt_resp, nt_resp, 24); - if (IS_BITS_SET_ALL(neg_flags, NTLMSSP_NEGOTIATE_UNICODE)) - { - ascii_to_unibuf(rsp->domain, domain, sizeof(rsp->domain)-2); - ascii_to_unibuf(rsp->user , user , sizeof(rsp->user )-2); - ascii_to_unibuf(rsp->wks , wks , sizeof(rsp->wks )-2); - } - else - { + if (IS_BITS_SET_ALL(neg_flags, NTLMSSP_NEGOTIATE_UNICODE)) { + dos_struni2(rsp->domain, domain, sizeof(rsp->domain)); + dos_struni2(rsp->user, user, sizeof(rsp->user)); + dos_struni2(rsp->wks, wks, sizeof(rsp->wks)); + } else { fstrcpy(rsp->domain, domain); - fstrcpy(rsp->user , user ); - fstrcpy(rsp->wks , wks ); + fstrcpy(rsp->user, user); + fstrcpy(rsp->wks, wks); } rsp->sess_key[0] = 0; - - return True; } /******************************************************************* -reads or writes an RPC_AUTH_NTLMSSP_RESP structure. - -*** lkclXXXX FUDGE! HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) *** -*** lkclXXXX the actual offset is at the start of the auth verifier *** + Reads or writes an RPC_AUTH_NTLMSSP_RESP structure. + *** lkclXXXX FUDGE! HAVE TO MANUALLY SPECIFY OFFSET HERE (0x1c bytes) *** + *** lkclXXXX the actual offset is at the start of the auth verifier *** ********************************************************************/ + BOOL smb_io_rpc_auth_ntlmssp_resp(char *desc, RPC_AUTH_NTLMSSP_RESP *rsp, prs_struct *ps, int depth) { - if (rsp == NULL) return False; + if (rsp == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_resp"); depth++; - if (ps->io) - { + if (ps->io) { uint32 old_offset; /* reading */ ZERO_STRUCTP(rsp); - smb_io_strhdr("hdr_lm_resp ", &rsp->hdr_lm_resp , ps, depth); - smb_io_strhdr("hdr_nt_resp ", &rsp->hdr_nt_resp , ps, depth); - smb_io_strhdr("hdr_domain ", &rsp->hdr_domain , ps, depth); - smb_io_strhdr("hdr_user ", &rsp->hdr_usr , ps, depth); - smb_io_strhdr("hdr_wks ", &rsp->hdr_wks , ps, depth); - smb_io_strhdr("hdr_sess_key", &rsp->hdr_sess_key, ps, depth); + if(!smb_io_strhdr("hdr_lm_resp ", &rsp->hdr_lm_resp, ps, depth)) + return False; + if(!smb_io_strhdr("hdr_nt_resp ", &rsp->hdr_nt_resp, ps, depth)) + return False; + if(!smb_io_strhdr("hdr_domain ", &rsp->hdr_domain, ps, depth)) + return False; + if(!smb_io_strhdr("hdr_user ", &rsp->hdr_usr, ps, depth)) + return False; + if(!smb_io_strhdr("hdr_wks ", &rsp->hdr_wks, ps, depth)) + return False; + if(!smb_io_strhdr("hdr_sess_key", &rsp->hdr_sess_key, ps, depth)) + return False; + + if(!prs_uint32("neg_flags", ps, depth, &rsp->neg_flags)) /* 0x0000 82b1 */ + return False; + + old_offset = prs_offset(ps); - prs_uint32("neg_flags", ps, depth, &(rsp->neg_flags)); /* 0x0000 82b1 */ + if(!prs_set_offset(ps, rsp->hdr_domain.buffer + 0x1c)) + return False; - old_offset = ps->offset; + if(!prs_uint8s(True , "domain ", ps, depth, (uint8*)rsp->domain, + MIN(rsp->hdr_domain.str_str_len, sizeof(rsp->domain)))) + return False; - ps->offset = rsp->hdr_domain .buffer + 0x1c; - prs_uint8s(True , "domain ", ps, depth, (uint8*)rsp->domain , MIN(rsp->hdr_domain .str_str_len, sizeof(rsp->domain ))); - old_offset += rsp->hdr_domain .str_str_len; + old_offset += rsp->hdr_domain.str_str_len; - ps->offset = rsp->hdr_usr .buffer + 0x1c; - prs_uint8s(True , "user ", ps, depth, (uint8*)rsp->user , MIN(rsp->hdr_usr .str_str_len, sizeof(rsp->user ))); - old_offset += rsp->hdr_usr .str_str_len; + if(!prs_set_offset(ps, rsp->hdr_usr.buffer + 0x1c)) + return False; - ps->offset = rsp->hdr_wks .buffer + 0x1c; - prs_uint8s(True , "wks ", ps, depth, (uint8*)rsp->wks , MIN(rsp->hdr_wks .str_str_len, sizeof(rsp->wks ))); - old_offset += rsp->hdr_wks .str_str_len; + if(!prs_uint8s(True , "user ", ps, depth, (uint8*)rsp->user, + MIN(rsp->hdr_usr.str_str_len, sizeof(rsp->user)))) + return False; - ps->offset = rsp->hdr_lm_resp .buffer + 0x1c; - prs_uint8s(False, "lm_resp ", ps, depth, (uint8*)rsp->lm_resp , MIN(rsp->hdr_lm_resp .str_str_len, sizeof(rsp->lm_resp ))); - old_offset += rsp->hdr_lm_resp .str_str_len; + old_offset += rsp->hdr_usr.str_str_len; - ps->offset = rsp->hdr_nt_resp .buffer + 0x1c; - prs_uint8s(False, "nt_resp ", ps, depth, (uint8*)rsp->nt_resp , MIN(rsp->hdr_nt_resp .str_str_len, sizeof(rsp->nt_resp ))); - old_offset += rsp->hdr_nt_resp .str_str_len; + if(!prs_set_offset(ps, rsp->hdr_wks.buffer + 0x1c)) + return False; + + if(!prs_uint8s(True, "wks ", ps, depth, (uint8*)rsp->wks, + MIN(rsp->hdr_wks.str_str_len, sizeof(rsp->wks)))) + return False; + + old_offset += rsp->hdr_wks.str_str_len; + + if(!prs_set_offset(ps, rsp->hdr_lm_resp.buffer + 0x1c)) + return False; + + if(!prs_uint8s(False, "lm_resp ", ps, depth, (uint8*)rsp->lm_resp, + MIN(rsp->hdr_lm_resp.str_str_len, sizeof(rsp->lm_resp )))) + return False; + + old_offset += rsp->hdr_lm_resp.str_str_len; + + if(!prs_set_offset(ps, rsp->hdr_nt_resp.buffer + 0x1c)) + return False; + + if(!prs_uint8s(False, "nt_resp ", ps, depth, (uint8*)rsp->nt_resp, + MIN(rsp->hdr_nt_resp.str_str_len, sizeof(rsp->nt_resp )))) + return False; + + old_offset += rsp->hdr_nt_resp.str_str_len; + + if (rsp->hdr_sess_key.str_str_len != 0) { + + if(!prs_set_offset(ps, rsp->hdr_sess_key.buffer + 0x1c)) + return False; - if (rsp->hdr_sess_key.str_str_len != 0) - { - ps->offset = rsp->hdr_sess_key.buffer + 0x1c; old_offset += rsp->hdr_sess_key.str_str_len; - prs_uint8s(False, "sess_key", ps, depth, (uint8*)rsp->sess_key, MIN(rsp->hdr_sess_key.str_str_len, sizeof(rsp->sess_key))); + + if(!prs_uint8s(False, "sess_key", ps, depth, (uint8*)rsp->sess_key, + MIN(rsp->hdr_sess_key.str_str_len, sizeof(rsp->sess_key)))) + return False; } - ps->offset = old_offset; - } - else - { + if(!prs_set_offset(ps, old_offset)) + return False; + } else { /* writing */ - smb_io_strhdr("hdr_lm_resp ", &rsp->hdr_lm_resp , ps, depth); - smb_io_strhdr("hdr_nt_resp ", &rsp->hdr_nt_resp , ps, depth); - smb_io_strhdr("hdr_domain ", &rsp->hdr_domain , ps, depth); - smb_io_strhdr("hdr_user ", &rsp->hdr_usr , ps, depth); - smb_io_strhdr("hdr_wks ", &rsp->hdr_wks , ps, depth); - smb_io_strhdr("hdr_sess_key", &rsp->hdr_sess_key, ps, depth); - - prs_uint32("neg_flags", ps, depth, &(rsp->neg_flags)); /* 0x0000 82b1 */ - - prs_uint8s(True , "domain ", ps, depth, (uint8*)rsp->domain , MIN(rsp->hdr_domain .str_str_len, sizeof(rsp->domain ))); - prs_uint8s(True , "user ", ps, depth, (uint8*)rsp->user , MIN(rsp->hdr_usr .str_str_len, sizeof(rsp->user ))); - prs_uint8s(True , "wks ", ps, depth, (uint8*)rsp->wks , MIN(rsp->hdr_wks .str_str_len, sizeof(rsp->wks ))); - prs_uint8s(False, "lm_resp ", ps, depth, (uint8*)rsp->lm_resp , MIN(rsp->hdr_lm_resp .str_str_len, sizeof(rsp->lm_resp ))); - prs_uint8s(False, "nt_resp ", ps, depth, (uint8*)rsp->nt_resp , MIN(rsp->hdr_nt_resp .str_str_len, sizeof(rsp->nt_resp ))); - prs_uint8s(False, "sess_key", ps, depth, (uint8*)rsp->sess_key, MIN(rsp->hdr_sess_key.str_str_len, sizeof(rsp->sess_key))); + if(!smb_io_strhdr("hdr_lm_resp ", &rsp->hdr_lm_resp, ps, depth)) + return False; + if(!smb_io_strhdr("hdr_nt_resp ", &rsp->hdr_nt_resp, ps, depth)) + return False; + if(!smb_io_strhdr("hdr_domain ", &rsp->hdr_domain, ps, depth)) + return False; + if(!smb_io_strhdr("hdr_user ", &rsp->hdr_usr, ps, depth)) + return False; + if(!smb_io_strhdr("hdr_wks ", &rsp->hdr_wks, ps, depth)) + return False; + if(!smb_io_strhdr("hdr_sess_key", &rsp->hdr_sess_key, ps, depth)) + return False; + + if(!prs_uint32("neg_flags", ps, depth, &rsp->neg_flags)) /* 0x0000 82b1 */ + return False; + + if(!prs_uint8s(True , "domain ", ps, depth, (uint8*)rsp->domain, + MIN(rsp->hdr_domain.str_str_len, sizeof(rsp->domain)))) + return False; + + if(!prs_uint8s(True , "user ", ps, depth, (uint8*)rsp->user, + MIN(rsp->hdr_usr.str_str_len, sizeof(rsp->user)))) + return False; + + if(!prs_uint8s(True , "wks ", ps, depth, (uint8*)rsp->wks, + MIN(rsp->hdr_wks.str_str_len, sizeof(rsp->wks)))) + return False; + if(!prs_uint8s(False, "lm_resp ", ps, depth, (uint8*)rsp->lm_resp, + MIN(rsp->hdr_lm_resp .str_str_len, sizeof(rsp->lm_resp)))) + return False; + if(!prs_uint8s(False, "nt_resp ", ps, depth, (uint8*)rsp->nt_resp, + MIN(rsp->hdr_nt_resp .str_str_len, sizeof(rsp->nt_resp )))) + return False; + if(!prs_uint8s(False, "sess_key", ps, depth, (uint8*)rsp->sess_key, + MIN(rsp->hdr_sess_key.str_str_len, sizeof(rsp->sess_key)))) + return False; } return True; } /******************************************************************* -checks an RPC_AUTH_NTLMSSP_CHK structure. + Checks an RPC_AUTH_NTLMSSP_CHK structure. ********************************************************************/ + BOOL rpc_auth_ntlmssp_chk(RPC_AUTH_NTLMSSP_CHK *chk, uint32 crc32, uint32 seq_num) { if (chk == NULL) - { return False; - } if (chk->crc32 != crc32 || chk->ver != NTLMSSP_SIGN_VERSION || @@ -975,41 +1018,44 @@ BOOL rpc_auth_ntlmssp_chk(RPC_AUTH_NTLMSSP_CHK *chk, uint32 crc32, uint32 seq_nu return False; } return True; - - return True; } /******************************************************************* -creates an RPC_AUTH_NTLMSSP_CHK structure. + Inits an RPC_AUTH_NTLMSSP_CHK structure. ********************************************************************/ -BOOL make_rpc_auth_ntlmssp_chk(RPC_AUTH_NTLMSSP_CHK *chk, + +void init_rpc_auth_ntlmssp_chk(RPC_AUTH_NTLMSSP_CHK *chk, uint32 ver, uint32 crc32, uint32 seq_num) { - if (chk == NULL) return False; - - chk->ver = ver ; + chk->ver = ver; chk->reserved = 0x0; - chk->crc32 = crc32 ; - chk->seq_num = seq_num ; - - return True; + chk->crc32 = crc32; + chk->seq_num = seq_num; } /******************************************************************* -reads or writes an RPC_AUTH_NTLMSSP_CHK structure. + Reads or writes an RPC_AUTH_NTLMSSP_CHK structure. ********************************************************************/ + BOOL smb_io_rpc_auth_ntlmssp_chk(char *desc, RPC_AUTH_NTLMSSP_CHK *chk, prs_struct *ps, int depth) { - if (chk == NULL) return False; + if (chk == NULL) + return False; prs_debug(ps, depth, desc, "smb_io_rpc_auth_ntlmssp_chk"); depth++; - prs_uint32("ver ", ps, depth, &(chk->ver )); - prs_uint32("reserved", ps, depth, &(chk->reserved)); - prs_uint32("crc32 ", ps, depth, &(chk->crc32 )); - prs_uint32("seq_num ", ps, depth, &(chk->seq_num )); + if(!prs_align(ps)) + return False; + + if(!prs_uint32("ver ", ps, depth, &chk->ver)) + return False; + if(!prs_uint32("reserved", ps, depth, &chk->reserved)) + return False; + if(!prs_uint32("crc32 ", ps, depth, &chk->crc32)) + return False; + if(!prs_uint32("seq_num ", ps, depth, &chk->seq_num)) + return False; return True; } - diff --git a/source3/rpc_parse/parse_samr.c b/source3/rpc_parse/parse_samr.c index cedfbdebd3..effe329376 100644 --- a/source3/rpc_parse/parse_samr.c +++ b/source3/rpc_parse/parse_samr.c @@ -2,9 +2,9 @@ * Unix SMB/Netbios implementation. * Version 1.9. * RPC Pipe client / server routines - * Copyright (C) Andrew Tridgell 1992-1999, - * Copyright (C) Luke Kenneth Casson Leighton 1996-1999, - * Copyright (C) Paul Ashton 1997-1999. + * Copyright (C) Andrew Tridgell 1992-1997, + * Copyright (C) Luke Kenneth Casson Leighton 1996-1997, + * Copyright (C) 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 @@ -28,444 +28,314 @@ extern int DEBUGLEVEL; /******************************************************************* -makes a SAMR_Q_CLOSE_HND structure. + Inits a SAMR_Q_CLOSE_HND structure. ********************************************************************/ -BOOL make_samr_q_close_hnd(SAMR_Q_CLOSE_HND *q_c, POLICY_HND *hnd) -{ - if (q_c == NULL || hnd == NULL) return False; - - DEBUG(5,("make_samr_q_close_hnd\n")); - memcpy(&(q_c->pol), hnd, sizeof(q_c->pol)); +void init_samr_q_close_hnd(SAMR_Q_CLOSE_HND *q_c, POLICY_HND *hnd) +{ + DEBUG(5,("init_samr_q_close_hnd\n")); - return True; + memcpy(&q_c->pol, hnd, sizeof(q_c->pol)); } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ + BOOL samr_io_q_close_hnd(char *desc, SAMR_Q_CLOSE_HND *q_u, prs_struct *ps, int depth) { - if (q_u == NULL) return False; + if (q_u == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_q_close_hnd"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_pol_hnd("pol", &(q_u->pol), ps, depth); - prs_align(ps); + if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth)) + return False; + if(!prs_align(ps)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ + BOOL samr_io_r_close_hnd(char *desc, SAMR_R_CLOSE_HND *r_u, prs_struct *ps, int depth) { - if (r_u == NULL) return False; + if (r_u == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_r_close_hnd"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_pol_hnd("pol", &(r_u->pol), ps, depth); - prs_align(ps); + if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth)) + return False; + if(!prs_align(ps)) + return False; - prs_uint32("status", ps, depth, &(r_u->status)); + if(!prs_uint32("status", ps, depth, &r_u->status)) + return False; return True; } -/******************************************************************* -makes a SAMR_Q_LOOKUP_DOMAIN structure. -********************************************************************/ -BOOL make_samr_q_lookup_domain(SAMR_Q_LOOKUP_DOMAIN *q_u, - POLICY_HND *pol, const char *dom_name) -{ - int len_name = strlen(dom_name); - - if (q_u == NULL) return False; - - DEBUG(5,("make_samr_q_lookup_domain\n")); - - memcpy(&(q_u->connect_pol), pol, sizeof(*pol)); - - make_uni_hdr(&(q_u->hdr_domain), len_name); - make_unistr2(&(q_u->uni_domain), dom_name, len_name); - - return True; -} /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL samr_io_q_lookup_domain(char *desc, SAMR_Q_LOOKUP_DOMAIN *q_u, prs_struct *ps, int depth) -{ - if (q_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_q_lookup_domain"); - depth++; - - prs_align(ps); - smb_io_pol_hnd("connect_pol", &(q_u->connect_pol), ps, depth); - prs_align(ps); - - smb_io_unihdr("hdr_domain", &(q_u->hdr_domain), ps, depth); - smb_io_unistr2("uni_domain", &(q_u->uni_domain), - q_u->hdr_domain.buffer, ps, depth); - prs_align(ps); - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_r_lookup_domain(char *desc, SAMR_R_LOOKUP_DOMAIN *r_u, prs_struct *ps, int depth) -{ - if (r_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_r_lookup_domain"); - depth++; - - prs_align(ps); - - prs_uint32("ptr", ps, depth, &(r_u->ptr_sid)); - - if (r_u->ptr_sid != 0) - { - smb_io_dom_sid2("sid", &(r_u->dom_sid), ps, depth); - prs_align(ps); - } - - prs_uint32("status", ps, depth, &(r_u->status)); - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL make_samr_q_open_domain(SAMR_Q_OPEN_DOMAIN *q_u, - const POLICY_HND *connect_pol, uint32 flags, - const DOM_SID *sid) +void init_samr_q_open_domain(SAMR_Q_OPEN_DOMAIN *q_u, + POLICY_HND *connect_pol, uint32 rid, + DOM_SID *sid) { - if (q_u == NULL) return False; - - DEBUG(5,("samr_make_samr_q_open_domain\n")); + DEBUG(5,("samr_init_q_open_domain\n")); memcpy(&q_u->connect_pol, connect_pol, sizeof(q_u->connect_pol)); - q_u->flags = flags; - make_dom_sid2(&(q_u->dom_sid), sid); - - return True; + q_u->rid = rid; + init_dom_sid2(&q_u->dom_sid, sid); } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL samr_io_q_open_domain(char *desc, SAMR_Q_OPEN_DOMAIN *q_u, prs_struct *ps, int depth) + +BOOL samr_io_q_open_domain(char *desc, SAMR_Q_OPEN_DOMAIN *q_u, prs_struct *ps, int depth) { - if (q_u == NULL) return False; + if (q_u == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_q_open_domain"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_pol_hnd("connect_pol", &(q_u->connect_pol), ps, depth); - prs_align(ps); + if(!smb_io_pol_hnd("connect_pol", &q_u->connect_pol, ps, depth)) + return False; + if(!prs_align(ps)) + return False; - prs_uint32("flags", ps, depth, &(q_u->flags)); + if(!prs_uint32("rid", ps, depth, &q_u->rid)) + return False; - smb_io_dom_sid2("sid", &(q_u->dom_sid), ps, depth); - prs_align(ps); + if(!smb_io_dom_sid2("sid", &q_u->dom_sid, ps, depth)) + return False; + if(!prs_align(ps)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL samr_io_r_open_domain(char *desc, SAMR_R_OPEN_DOMAIN *r_u, prs_struct *ps, int depth) + +BOOL samr_io_r_open_domain(char *desc, SAMR_R_OPEN_DOMAIN *r_u, prs_struct *ps, int depth) { - if (r_u == NULL) return False; + if (r_u == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_r_open_domain"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_pol_hnd("domain_pol", &(r_u->domain_pol), ps, depth); - prs_align(ps); + if(!smb_io_pol_hnd("domain_pol", &r_u->domain_pol, ps, depth)) + return False; + if(!prs_align(ps)) + return False; - prs_uint32("status", ps, depth, &(r_u->status)); + if(!prs_uint32("status", ps, depth, &r_u->status)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL make_samr_q_unknown_2c(SAMR_Q_UNKNOWN_2C *q_u, POLICY_HND *user_pol) -{ - if (q_u == NULL) return False; - DEBUG(5,("samr_make_samr_q_unknown_2c\n")); +void init_samr_q_unknown_2c(SAMR_Q_UNKNOWN_2C *q_u, POLICY_HND *user_pol) +{ + DEBUG(5,("samr_init_q_unknown_2c\n")); memcpy(&q_u->user_pol, user_pol, sizeof(q_u->user_pol)); - - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ + BOOL samr_io_q_unknown_2c(char *desc, SAMR_Q_UNKNOWN_2C *q_u, prs_struct *ps, int depth) { - if (q_u == NULL) return False; + if (q_u == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_q_unknown_2c"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_pol_hnd("user_pol", &(q_u->user_pol), ps, depth); - prs_align(ps); + if(!smb_io_pol_hnd("user_pol", &q_u->user_pol, ps, depth)) + return False; + if(!prs_align(ps)) + return False; return True; } /******************************************************************* -makes a structure. + Inits a structure. ********************************************************************/ -BOOL make_samr_r_unknown_2c(SAMR_R_UNKNOWN_2C *q_u, uint32 status) -{ - if (q_u == NULL) return False; - DEBUG(5,("samr_make_r_unknown_2c\n")); +void init_samr_r_unknown_2c(SAMR_R_UNKNOWN_2C *q_u, uint32 status) +{ + DEBUG(5,("samr_init_r_unknown_2c\n")); - q_u->unknown_0 = 0x00150000; + q_u->unknown_0 = 0x00160000; q_u->unknown_1 = 0x00000000; q_u->status = status; - - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ + BOOL samr_io_r_unknown_2c(char *desc, SAMR_R_UNKNOWN_2C *r_u, prs_struct *ps, int depth) { - if (r_u == NULL) return False; + if (r_u == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_r_unknown_2c"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("unknown_0", ps, depth, &(r_u->unknown_0)); - prs_uint32("unknown_1", ps, depth, &(r_u->unknown_1)); - prs_uint32("status ", ps, depth, &(r_u->status )); + if(!prs_uint32("unknown_0", ps, depth, &r_u->unknown_0)) + return False; + if(!prs_uint32("unknown_1", ps, depth, &r_u->unknown_1)) + return False; + if(!prs_uint32("status ", ps, depth, &r_u->status)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Inits a SAMR_Q_UNKNOWN_3 structure. ********************************************************************/ -BOOL make_samr_q_unknown_3(SAMR_Q_UNKNOWN_3 *q_u, + +void init_samr_q_unknown_3(SAMR_Q_UNKNOWN_3 *q_u, POLICY_HND *user_pol, uint16 switch_value) { - if (q_u == NULL) return False; - - DEBUG(5,("samr_make_samr_q_unknown_3\n")); + DEBUG(5,("samr_init_q_unknown_3\n")); memcpy(&q_u->user_pol, user_pol, sizeof(q_u->user_pol)); q_u->switch_value = switch_value; - - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ + BOOL samr_io_q_unknown_3(char *desc, SAMR_Q_UNKNOWN_3 *q_u, prs_struct *ps, int depth) { - if (q_u == NULL) return False; + if (q_u == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_q_unknown_3"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_pol_hnd("user_pol", &(q_u->user_pol), ps, depth); - prs_align(ps); + if(!smb_io_pol_hnd("user_pol", &q_u->user_pol, ps, depth)) + return False; - prs_uint16("switch_value", ps, depth, &(q_u->switch_value)); - prs_align(ps); + if(!prs_align(ps)) + return False; + + if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value)) + return False; + if(!prs_align(ps)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Inits a SAMR_Q_QUERY_DOMAIN_INFO structure. ********************************************************************/ -BOOL make_samr_q_query_dom_info(SAMR_Q_QUERY_DOMAIN_INFO *q_u, + +void init_samr_q_query_dom_info(SAMR_Q_QUERY_DOMAIN_INFO *q_u, POLICY_HND *domain_pol, uint16 switch_value) { - if (q_u == NULL) return False; - - DEBUG(5,("samr_make_samr_q_query_dom_info\n")); + DEBUG(5,("init_samr_q_query_dom_info\n")); memcpy(&q_u->domain_pol, domain_pol, sizeof(q_u->domain_pol)); q_u->switch_value = switch_value; - - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ + BOOL samr_io_q_query_dom_info(char *desc, SAMR_Q_QUERY_DOMAIN_INFO *q_u, prs_struct *ps, int depth) { - if (q_u == NULL) return False; + if (q_u == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_q_query_dom_info"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_pol_hnd("domain_pol", &(q_u->domain_pol), ps, depth); - prs_align(ps); - - prs_uint16("switch_value", ps, depth, &(q_u->switch_value)); - prs_align(ps); + if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth)) + return False; + if(!prs_align(ps)) + return False; - return True; -} + if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value)) + return False; + if(!prs_align(ps)) + return False; -/******************************************************************* -makes a structure. -********************************************************************/ -BOOL make_unk_info3(SAM_UNK_INFO_3 *u_3) -{ - if (u_3 == NULL) return False; - - u_3->unknown_0 = 0x00000000; - u_3->unknown_1 = 0x80000000; - return True; } /******************************************************************* -reads or writes a structure. + Inits a structure. ********************************************************************/ -BOOL sam_io_unk_info3(char *desc, SAM_UNK_INFO_3 *u_3, prs_struct *ps, int depth) -{ - if (u_3 == NULL) return False; - - prs_debug(ps, depth, desc, "sam_io_unk_info3"); - depth++; - prs_uint32("unknown_0", ps, depth, &u_3->unknown_0); /* 0x0000 0000 */ - prs_uint32("unknown_1", ps, depth, &u_3->unknown_1); /* 0x8000 0000 */ - - prs_align(ps); - - - return True; -} - -/******************************************************************* -makes a structure. -********************************************************************/ -BOOL make_unk_info6(SAM_UNK_INFO_6 *u_6) -{ - if (u_6 == NULL) return False; - - u_6->unknown_0 = 0x00000000; - u_6->ptr_0 = 1; - memset(u_6->padding, 0, sizeof(u_6->padding)); /* 12 bytes zeros */ - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL sam_io_unk_info6(char *desc, SAM_UNK_INFO_6 *u_6, prs_struct *ps, int depth) -{ - if (u_6 == NULL) return False; - - prs_debug(ps, depth, desc, "sam_io_unk_info6"); - depth++; - - prs_uint32("unknown_0", ps, depth, &u_6->unknown_0); /* 0x0000 0000 */ - prs_uint32("ptr_0", ps, depth, &u_6->ptr_0); /* pointer to unknown structure */ - prs_uint8s(False, "padding", ps, depth, u_6->padding, sizeof(u_6->padding)); /* 12 bytes zeros */ - - prs_align(ps); - - - return True; -} - -/******************************************************************* -makes a structure. -********************************************************************/ -BOOL make_unk_info7(SAM_UNK_INFO_7 *u_7) -{ - if (u_7 == NULL) return False; - - u_7->unknown_0 = 0x0003; - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL sam_io_unk_info7(char *desc, SAM_UNK_INFO_7 *u_7, prs_struct *ps, int depth) -{ - if (u_7 == NULL) return False; - - prs_debug(ps, depth, desc, "sam_io_unk_info7"); - depth++; - - prs_uint16("unknown_0", ps, depth, &u_7->unknown_0); /* 0x0003 */ - prs_align(ps); - - - return True; -} - -/******************************************************************* -makes a structure. -********************************************************************/ -BOOL make_unk_info2(SAM_UNK_INFO_2 *u_2, char *domain, char *server) +void init_unk_info2(SAM_UNK_INFO_2 *u_2, char *domain, char *server) { int len_domain = strlen(domain); int len_server = strlen(server); - if (u_2 == NULL) return False; - u_2->unknown_0 = 0x00000000; u_2->unknown_1 = 0x80000000; u_2->unknown_2 = 0x00000000; u_2->ptr_0 = 1; - make_uni_hdr(&(u_2->hdr_domain), len_domain); - make_uni_hdr(&(u_2->hdr_server), len_server); + init_uni_hdr(&u_2->hdr_domain, len_domain); + init_uni_hdr(&u_2->hdr_server, len_server); u_2->seq_num = 0x10000000; u_2->unknown_3 = 0x00000000; @@ -473,221 +343,177 @@ BOOL make_unk_info2(SAM_UNK_INFO_2 *u_2, char *domain, char *server) u_2->unknown_4 = 0x00000001; u_2->unknown_5 = 0x00000003; u_2->unknown_6 = 0x00000001; - u_2->num_domain_usrs = MAX_SAM_ENTRIES; - u_2->num_domain_grps = MAX_SAM_ENTRIES; - u_2->num_local_grps = MAX_SAM_ENTRIES; + u_2->num_domain_usrs = 0x00000008; + u_2->num_domain_grps = 0x00000003; + u_2->num_local_grps = 0x00000003; memset(u_2->padding, 0, sizeof(u_2->padding)); /* 12 bytes zeros */ - make_unistr2(&u_2->uni_domain, domain, len_domain); - make_unistr2(&u_2->uni_server, server, len_server); - - return True; + init_unistr2(&u_2->uni_domain, domain, len_domain); + init_unistr2(&u_2->uni_server, server, len_server); } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ + BOOL sam_io_unk_info2(char *desc, SAM_UNK_INFO_2 *u_2, prs_struct *ps, int depth) { - if (u_2 == NULL) return False; + if (u_2 == NULL) + return False; prs_debug(ps, depth, desc, "sam_io_unk_info2"); depth++; - prs_uint32("unknown_0", ps, depth, &u_2->unknown_0); /* 0x0000 0000 */ - prs_uint32("unknown_1", ps, depth, &u_2->unknown_1); /* 0x8000 0000 */ - prs_uint32("unknown_2", ps, depth, &u_2->unknown_2); /* 0x0000 0000 */ + if(!prs_uint32("unknown_0", ps, depth, &u_2->unknown_0)) /* 0x0000 0000 */ + return False; + if(!prs_uint32("unknown_1", ps, depth, &u_2->unknown_1)) /* 0x8000 0000 */ + return False; + if(!prs_uint32("unknown_2", ps, depth, &u_2->unknown_2)) /* 0x0000 0000 */ + return False; - prs_uint32("ptr_0", ps, depth, &u_2->ptr_0); /* pointer to unknown structure */ - smb_io_unihdr("hdr_domain", &u_2->hdr_domain, ps, depth); /* domain name unicode header */ - smb_io_unihdr("hdr_server", &u_2->hdr_server, ps, depth); /* server name unicode header */ + if(!prs_uint32("ptr_0", ps, depth, &u_2->ptr_0)) /* pointer to unknown structure */ + return False; + if(!smb_io_unihdr("hdr_domain", &u_2->hdr_domain, ps, depth)) /* domain name unicode header */ + return False; + if(!smb_io_unihdr("hdr_server", &u_2->hdr_server, ps, depth)) /* server name unicode header */ + return False; /* put all the data in here, at the moment, including what the above pointer is referring to */ - prs_uint32("seq_num ", ps, depth, &u_2->seq_num ); /* 0x0000 0099 or 0x1000 0000 */ - prs_uint32("unknown_3 ", ps, depth, &u_2->unknown_3 ); /* 0x0000 0000 */ + if(!prs_uint32("seq_num ", ps, depth, &u_2->seq_num )) /* 0x0000 0099 or 0x1000 0000 */ + return False; + if(!prs_uint32("unknown_3 ", ps, depth, &u_2->unknown_3 )) /* 0x0000 0000 */ + return False; - prs_uint32("unknown_4 ", ps, depth, &u_2->unknown_4 ); /* 0x0000 0001 */ - prs_uint32("unknown_5 ", ps, depth, &u_2->unknown_5 ); /* 0x0000 0003 */ - prs_uint32("unknown_6 ", ps, depth, &u_2->unknown_6 ); /* 0x0000 0001 */ - prs_uint32("num_domain_usrs ", ps, depth, &u_2->num_domain_usrs ); /* 0x0000 0008 */ - prs_uint32("num_domain_grps", ps, depth, &u_2->num_domain_grps); /* 0x0000 0003 */ - prs_uint32("num_local_grps", ps, depth, &u_2->num_local_grps); /* 0x0000 0003 */ - - prs_uint8s(False, "padding", ps, depth, u_2->padding, sizeof(u_2->padding)); /* 12 bytes zeros */ - - smb_io_unistr2( "uni_domain", &u_2->uni_domain, u_2->hdr_domain.buffer, ps, depth); /* domain name unicode string */ - prs_align(ps); - smb_io_unistr2( "uni_server", &u_2->uni_server, u_2->hdr_server.buffer, ps, depth); /* server name unicode string */ + if(!prs_uint32("unknown_4 ", ps, depth, &u_2->unknown_4 )) /* 0x0000 0001 */ + return False; + if(!prs_uint32("unknown_5 ", ps, depth, &u_2->unknown_5 )) /* 0x0000 0003 */ + return False; + if(!prs_uint32("unknown_6 ", ps, depth, &u_2->unknown_6 )) /* 0x0000 0001 */ + return False; + if(!prs_uint32("num_domain_usrs ", ps, depth, &u_2->num_domain_usrs )) /* 0x0000 0008 */ + return False; + if(!prs_uint32("num_domain_grps", ps, depth, &u_2->num_domain_grps)) /* 0x0000 0003 */ + return False; + if(!prs_uint32("num_local_grps", ps, depth, &u_2->num_local_grps)) /* 0x0000 0003 */ + return False; - prs_align(ps); - - - return True; -} + if(!prs_uint8s(False, "padding", ps, depth, u_2->padding, sizeof(u_2->padding))) /* 12 bytes zeros */ + return False; -/******************************************************************* -makes a structure. -********************************************************************/ -BOOL make_unk_info1(SAM_UNK_INFO_1 *u_1) -{ - if (u_1 == NULL) return False; + if(!smb_io_unistr2( "uni_domain", &u_2->uni_domain, u_2->hdr_domain.buffer, ps, depth)) /* domain name unicode string */ + return False; + if(!smb_io_unistr2( "uni_server", &u_2->uni_server, u_2->hdr_server.buffer, ps, depth)) /* server name unicode string */ + return False; - memset(u_1->padding, 0, sizeof(u_1->padding)); /* 12 bytes zeros */ - u_1->unknown_1 = 0x80000000; - u_1->unknown_2 = 0x00000000; + if(!prs_align(ps)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Inits a SAMR_R_QUERY_DOMAIN_INFO structure. ********************************************************************/ -BOOL sam_io_unk_info1(char *desc, SAM_UNK_INFO_1 *u_1, prs_struct *ps, int depth) -{ - if (u_1 == NULL) return False; - - prs_debug(ps, depth, desc, "sam_io_unk_info1"); - depth++; - - prs_uint8s(False, "padding", ps, depth, u_1->padding, sizeof(u_1->padding)); /* 12 bytes zeros */ - - prs_uint32("unknown_1", ps, depth, &u_1->unknown_1); /* 0x8000 0000 */ - prs_uint32("unknown_2", ps, depth, &u_1->unknown_2); /* 0x0000 0000 */ - - prs_align(ps); - return True; -} - -/******************************************************************* -makes a SAMR_R_QUERY_DOMAIN_INFO structure. -********************************************************************/ -BOOL make_samr_r_query_dom_info(SAMR_R_QUERY_DOMAIN_INFO *r_u, +void init_samr_r_query_dom_info(SAMR_R_QUERY_DOMAIN_INFO *r_u, uint16 switch_value, SAM_UNK_CTR *ctr, uint32 status) { - if (r_u == NULL || ctr == NULL) return False; - - DEBUG(5,("make_samr_r_query_dom_info\n")); + DEBUG(5,("init_samr_r_query_dom_info\n")); r_u->ptr_0 = 0; r_u->switch_value = 0; r_u->status = status; /* return status */ - if (status == 0) - { + if (status == 0) { r_u->switch_value = switch_value; r_u->ptr_0 = 1; r_u->ctr = ctr; } - - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ + BOOL samr_io_r_query_dom_info(char *desc, SAMR_R_QUERY_DOMAIN_INFO *r_u, prs_struct *ps, int depth) { - if (r_u == NULL) return False; + if (r_u == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_r_query_dom_info"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr_0 ", ps, depth, &(r_u->ptr_0)); + if(!prs_uint32("ptr_0 ", ps, depth, &r_u->ptr_0)) + return False; + if(!prs_uint16("switch_value", ps, depth, &r_u->switch_value)) + return False; + if(!prs_align(ps)) + return False; - if (r_u->ptr_0 != 0 && r_u->ctr != NULL) - { - prs_uint16("switch_value", ps, depth, &(r_u->switch_value)); - prs_align(ps); - - switch (r_u->switch_value) - { - case 0x07: - { - sam_io_unk_info7("unk_inf7", &r_u->ctr->info.inf7, ps, depth); - break; - } - case 0x06: - { - sam_io_unk_info6("unk_inf6", &r_u->ctr->info.inf6, ps, depth); - break; - } - case 0x03: - { - sam_io_unk_info3("unk_inf3", &r_u->ctr->info.inf3, ps, depth); - break; - } - case 0x02: - { - sam_io_unk_info2("unk_inf2", &r_u->ctr->info.inf2, ps, depth); - break; - } - case 0x01: - { - sam_io_unk_info1("unk_inf1", &r_u->ctr->info.inf1, ps, depth); - break; - } - default: - { - DEBUG(3,("samr_io_r_query_dom_info: unknown switch level 0x%x\n", - r_u->switch_value)); - r_u->status = 0xC0000000|NT_STATUS_INVALID_INFO_CLASS; + if (r_u->ptr_0 != 0 && r_u->ctr != NULL) { + switch (r_u->switch_value) { + case 0x02: + if(!sam_io_unk_info2("unk_inf2", &r_u->ctr->info.inf2, ps, depth)) return False; - } + break; + default: + DEBUG(3,("samr_io_r_query_dom_info: unknown switch level 0x%x\n", + r_u->switch_value)); + return False; } } - prs_uint32("status ", ps, depth, &(r_u->status)); - return True; } /******************************************************************* - makes a DOM_SID3 structure. - - calculate length by adding up the size of the components. + Inits a DOM_SID3 structure. + Calculate length by adding up the size of the components. ********************************************************************/ -BOOL make_dom_sid3(DOM_SID3 *sid3, uint16 unk_0, uint16 unk_1, DOM_SID *sid) -{ - if (sid3 == NULL) return False; - sid3->sid = *sid; +void init_dom_sid3(DOM_SID3 *sid3, uint16 unk_0, uint16 unk_1, DOM_SID *sid) +{ + sid3->sid = *sid; sid3->len = 2 + 8 + sid3->sid.num_auths * 4; - - return True; } /******************************************************************* -reads or writes a SAM_SID3 structure. + Reads or writes a SAM_SID3 structure. -this one's odd, because the length (in bytes) is specified at the beginning. -the length _includes_ the length of the length, too :-) + this one's odd, because the length (in bytes) is specified at the beginning. + the length _includes_ the length of the length, too :-) ********************************************************************/ + static BOOL sam_io_dom_sid3(char *desc, DOM_SID3 *sid3, prs_struct *ps, int depth) { - if (sid3 == NULL) return False; + if (sid3 == NULL) + return False; prs_debug(ps, depth, desc, "sam_io_dom_sid3"); depth++; - prs_uint16("len", ps, depth, &(sid3->len)); - prs_align(ps); - smb_io_dom_sid("", &(sid3->sid), ps, depth); + if(!prs_uint16("len", ps, depth, &sid3->len)) + return False; + if(!prs_align(ps)) + return False; + if(!smb_io_dom_sid("", &sid3->sid, ps, depth)) + return False; return True; } /******************************************************************* -makes a SAMR_R_UNKNOWN3 structure. + Inits a SAMR_R_UNKNOWN3 structure. unknown_2 : 0x0001 unknown_3 : 0x8004 @@ -698,7 +524,8 @@ unknown_6 : 0x0002 unknown_7 : 0x5800 or 0x0070 ********************************************************************/ -static BOOL make_sam_sid_stuff(SAM_SID_STUFF *stf, + +static void init_sam_sid_stuff(SAM_SID_STUFF *stf, uint16 unknown_2, uint16 unknown_3, uint32 unknown_4, uint16 unknown_6, uint16 unknown_7, int num_sid3s, DOM_SID3 sid3[MAX_SAM_SIDS]) @@ -706,7 +533,7 @@ static BOOL make_sam_sid_stuff(SAM_SID_STUFF *stf, stf->unknown_2 = unknown_2; stf->unknown_3 = unknown_3; - bzero(stf->padding1, sizeof(stf->padding1)); + memset((char *)stf->padding1, '\0', sizeof(stf->padding1)); stf->unknown_4 = unknown_4; stf->unknown_5 = unknown_4; @@ -719,77 +546,81 @@ static BOOL make_sam_sid_stuff(SAM_SID_STUFF *stf, stf->padding2 = 0x0000; memcpy(stf->sid, sid3, sizeof(DOM_SID3) * num_sid3s); - - return True; } /******************************************************************* -reads or writes a SAM_SID_STUFF structure. + Reads or writes a SAM_SID_STUFF structure. ********************************************************************/ + static BOOL sam_io_sid_stuff(char *desc, SAM_SID_STUFF *stf, prs_struct *ps, int depth) { - uint32 i; + int i; - if (stf == NULL) return False; + if (stf == NULL) + return False; - DEBUG(5,("make_sam_sid_stuff\n")); + DEBUG(5,("init_sam_sid_stuff\n")); - prs_uint16("unknown_2", ps, depth, &(stf->unknown_2)); - prs_uint16("unknown_3", ps, depth, &(stf->unknown_3)); + if(!prs_uint16("unknown_2", ps, depth, &stf->unknown_2)) + return False; + if(!prs_uint16("unknown_3", ps, depth, &stf->unknown_3)) + return False; - prs_uint8s(False, "padding1", ps, depth, stf->padding1, sizeof(stf->padding1)); + if(!prs_uint8s(False, "padding1", ps, depth, stf->padding1, sizeof(stf->padding1))) + return False; - prs_uint32("unknown_4", ps, depth, &(stf->unknown_4)); - prs_uint32("unknown_5", ps, depth, &(stf->unknown_5)); - prs_uint16("unknown_6", ps, depth, &(stf->unknown_6)); - prs_uint16("unknown_7", ps, depth, &(stf->unknown_7)); - - prs_uint32("num_sids ", ps, depth, &(stf->num_sids )); - prs_uint16("padding2 ", ps, depth, &(stf->padding2 )); + if(!prs_uint32("unknown_4", ps, depth, &stf->unknown_4)) + return False; + if(!prs_uint32("unknown_5", ps, depth, &stf->unknown_5)) + return False; + if(!prs_uint16("unknown_6", ps, depth, &stf->unknown_6)) + return False; + if(!prs_uint16("unknown_7", ps, depth, &stf->unknown_7)) + return False; + + if(!prs_uint32("num_sids ", ps, depth, &stf->num_sids )) + return False; + if(!prs_uint16("padding2 ", ps, depth, &stf->padding2 )) + return False; SMB_ASSERT_ARRAY(stf->sid, stf->num_sids); - for (i = 0; i < stf->num_sids; i++) - { - sam_io_dom_sid3("", &(stf->sid[i]), ps, depth); + for (i = 0; i < stf->num_sids; i++) { + if(!sam_io_dom_sid3("", &(stf->sid[i]), ps, depth)) + return False; } return True; } /******************************************************************* -reads or writes a SAMR_R_UNKNOWN3 structure. + Inits or writes a SAMR_R_UNKNOWN3 structure. ********************************************************************/ -BOOL make_samr_r_unknown_3(SAMR_R_UNKNOWN_3 *r_u, + +void init_samr_r_unknown_3(SAMR_R_UNKNOWN_3 *r_u, uint16 unknown_2, uint16 unknown_3, uint32 unknown_4, uint16 unknown_6, uint16 unknown_7, int num_sid3s, DOM_SID3 sid3[MAX_SAM_SIDS], uint32 status) { - if (r_u == NULL) return False; - - DEBUG(5,("samr_make_r_unknown_3\n")); + DEBUG(5,("samr_init_r_unknown_3\n")); r_u->ptr_0 = 0; r_u->ptr_1 = 0; - if (status == 0x0) - { + if (status == 0x0) { r_u->ptr_0 = 1; r_u->ptr_1 = 1; - make_sam_sid_stuff(&(r_u->sid_stuff), unknown_2, unknown_3, + init_sam_sid_stuff(&(r_u->sid_stuff), unknown_2, unknown_3, unknown_4, unknown_6, unknown_7, num_sid3s, sid3); } r_u->status = status; - - return True; } - /******************************************************************* -reads or writes a SAMR_R_UNKNOWN_3 structure. + Reads or writes a SAMR_R_UNKNOWN_3 structure. this one's odd, because the daft buggers use a different mechanism for writing out the array of sids. they put the number of sids in @@ -800,4006 +631,1956 @@ is put at the beginning of the data stream. wierd. ********************************************************************/ + BOOL samr_io_r_unknown_3(char *desc, SAMR_R_UNKNOWN_3 *r_u, prs_struct *ps, int depth) { int ptr_len0=0; int ptr_len1=0; int ptr_sid_stuff = 0; - if (r_u == NULL) return False; + if (r_u == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_r_unknown_3"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr_0 ", ps, depth, &(r_u->ptr_0 )); + if(!prs_uint32("ptr_0 ", ps, depth, &r_u->ptr_0)) + return False; - if (ps->io) - { + if (ps->io) { /* reading. do the length later */ - prs_uint32("sid_stuff_len0", ps, depth, &(r_u->sid_stuff_len0)); - } - else - { + if(!prs_uint32("sid_stuff_len0", ps, depth, &r_u->sid_stuff_len0)) + return False; + } else { /* storing */ - ptr_len0 = ps->offset; ps->offset += 4; + ptr_len0 = prs_offset(ps); + if(!prs_set_offset(ps, ptr_len0 + 4)) + return False; } - if (r_u->ptr_0 != 0) - { - prs_uint32("ptr_1 ", ps, depth, &(r_u->ptr_1 )); - if (ps->io) - { + if (r_u->ptr_0 != 0) { + if(!prs_uint32("ptr_1 ", ps, depth, &r_u->ptr_1)) + return False; + if (ps->io) { /* reading. do the length later */ - prs_uint32("sid_stuff_len1", ps, depth, &(r_u->sid_stuff_len1)); - } - else - { + if(!prs_uint32("sid_stuff_len1", ps, depth, &r_u->sid_stuff_len1)) + return False; + } else { /* storing */ - ptr_len1 = ps->offset; ps->offset += 4; + ptr_len1 = prs_offset(ps); + if(!prs_set_offset(ps, ptr_len1 + 4)) + return False; } - if (r_u->ptr_1 != 0) - { - ptr_sid_stuff = ps->offset; - sam_io_sid_stuff("", &(r_u->sid_stuff), ps, depth); + if (r_u->ptr_1 != 0) { + ptr_sid_stuff = prs_offset(ps); + if(!sam_io_sid_stuff("", &r_u->sid_stuff, ps, depth)) + return False; } } - if (!(ps->io)) /* storing not reading. do the length, now. */ - { - if (ptr_sid_stuff != 0) - { - uint32 sid_stuff_len = ps->offset - ptr_sid_stuff; - int old_len = ps->offset; + if (!(ps->io)) { + /* storing not reading. do the length, now. */ - ps->offset = ptr_len0; - prs_uint32("sid_stuff_len0", ps, depth, &sid_stuff_len); + if (ptr_sid_stuff != 0) { + int old_len = prs_offset(ps); + uint32 sid_stuff_len = old_len - ptr_sid_stuff; - ps->offset = ptr_len1; - prs_uint32("sid_stuff_len1", ps, depth, &sid_stuff_len); + if(!prs_set_offset(ps, ptr_len0)) + return False; + if(!prs_uint32("sid_stuff_len0", ps, depth, &sid_stuff_len)) + return False; + + if(!prs_set_offset(ps, ptr_len1)) + return False; + if(!prs_uint32("sid_stuff_len1", ps, depth, &sid_stuff_len)) + return False; - ps->offset = old_len; + if(!prs_set_offset(ps, old_len)) + return False; } } - prs_uint32("status", ps, depth, &(r_u->status)); + if(!prs_uint32("status", ps, depth, &r_u->status)) + return False; return True; } /******************************************************************* -reads or writes a SAM_STR1 structure. + Reads or writes a SAM_STR1 structure. ********************************************************************/ -static BOOL sam_io_sam_str1(char *desc, SAM_STR1 *sam, uint32 acct_buf, uint32 name_buf, uint32 desc_buf, prs_struct *ps, int depth) + +static BOOL sam_io_sam_str1(char *desc, SAM_STR1 *sam, uint32 acct_buf, + uint32 name_buf, uint32 desc_buf, prs_struct *ps, int depth) { - if (sam == NULL) return False; + if (sam == NULL) + return False; prs_debug(ps, depth, desc, "sam_io_sam_str1"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_unistr2("unistr2", &(sam->uni_acct_name), acct_buf, ps, depth); /* account name unicode string */ - prs_align(ps); - smb_io_unistr2("unistr2", &(sam->uni_full_name), name_buf, ps, depth); /* full name unicode string */ - prs_align(ps); - smb_io_unistr2("unistr2", &(sam->uni_acct_desc), desc_buf, ps, depth); /* account desc unicode string */ - prs_align(ps); + if(!smb_io_unistr2("unistr2", &sam->uni_acct_name, acct_buf, ps, depth)) /* account name unicode string */ + return False; + if(!smb_io_unistr2("unistr2", &sam->uni_full_name, name_buf, ps, depth)) /* full name unicode string */ + return False; + if(!smb_io_unistr2("unistr2", &sam->uni_acct_desc, desc_buf, ps, depth)) /* account description unicode string */ + return False; return True; } /******************************************************************* -makes a SAM_ENTRY1 structure. + Inits a SAM_ENTRY1 structure. ********************************************************************/ -static BOOL make_sam_entry1(SAM_ENTRY1 *sam, uint32 user_idx, + +static void init_sam_entry1(SAM_ENTRY1 *sam, uint32 user_idx, uint32 len_sam_name, uint32 len_sam_full, uint32 len_sam_desc, uint32 rid_user, uint16 acb_info) { - if (sam == NULL) return False; - - DEBUG(5,("make_sam_entry1\n")); + DEBUG(5,("init_sam_entry1\n")); sam->user_idx = user_idx; sam->rid_user = rid_user; sam->acb_info = acb_info; sam->pad = 0; - make_uni_hdr(&(sam->hdr_acct_name), len_sam_name); - make_uni_hdr(&(sam->hdr_user_name), len_sam_full); - make_uni_hdr(&(sam->hdr_user_desc), len_sam_desc); - - return True; + init_uni_hdr(&sam->hdr_acct_name, len_sam_name); + init_uni_hdr(&sam->hdr_user_name, len_sam_full); + init_uni_hdr(&sam->hdr_user_desc, len_sam_desc); } /******************************************************************* -reads or writes a SAM_ENTRY1 structure. + Reads or writes a SAM_ENTRY1 structure. ********************************************************************/ + static BOOL sam_io_sam_entry1(char *desc, SAM_ENTRY1 *sam, prs_struct *ps, int depth) { - if (sam == NULL) return False; + if (sam == NULL) + return False; prs_debug(ps, depth, desc, "sam_io_sam_entry1"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("user_idx ", ps, depth, &(sam->user_idx )); + if(!prs_uint32("user_idx ", ps, depth, &sam->user_idx)) + return False; - prs_uint32("rid_user ", ps, depth, &(sam->rid_user )); - prs_uint16("acb_info ", ps, depth, &(sam->acb_info )); - prs_uint16("pad ", ps, depth, &(sam->pad )); + if(!prs_uint32("rid_user ", ps, depth, &sam->rid_user)) + return False; + if(!prs_uint16("acb_info ", ps, depth, &sam->acb_info)) + return False; + if(!prs_uint16("pad ", ps, depth, &sam->pad)) + return False; - smb_io_unihdr("unihdr", &(sam->hdr_acct_name), ps, depth); /* account name unicode string header */ - smb_io_unihdr("unihdr", &(sam->hdr_user_name), ps, depth); /* account name unicode string header */ - smb_io_unihdr("unihdr", &(sam->hdr_user_desc), ps, depth); /* account name unicode string header */ + if(!smb_io_unihdr("unihdr", &sam->hdr_acct_name, ps, depth)) /* account name unicode string header */ + return False; + if(!smb_io_unihdr("unihdr", &sam->hdr_user_name, ps, depth)) /* account name unicode string header */ + return False; + if(!smb_io_unihdr("unihdr", &sam->hdr_user_desc, ps, depth)) /* account name unicode string header */ + return False; return True; } /******************************************************************* -reads or writes a SAM_STR2 structure. + Reads or writes a SAM_STR2 structure. ********************************************************************/ + static BOOL sam_io_sam_str2(char *desc, SAM_STR2 *sam, uint32 acct_buf, uint32 desc_buf, prs_struct *ps, int depth) { - if (sam == NULL) return False; + if (sam == NULL) + return False; prs_debug(ps, depth, desc, "sam_io_sam_str2"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_unistr2("unistr2", &(sam->uni_srv_name), acct_buf, ps, depth); /* account name unicode string */ - prs_align(ps); - smb_io_unistr2("unistr2", &(sam->uni_srv_desc), desc_buf, ps, depth); /* account desc unicode string */ - prs_align(ps); + if(!smb_io_unistr2("unistr2", &sam->uni_srv_name, acct_buf, ps, depth)) /* account name unicode string */ + return False; + if(!smb_io_unistr2("unistr2", &sam->uni_srv_desc, desc_buf, ps, depth)) /* account description unicode string */ + return False; return True; } /******************************************************************* -makes a SAM_ENTRY2 structure. + Inits a SAM_ENTRY2 structure. ********************************************************************/ -static BOOL make_sam_entry2(SAM_ENTRY2 *sam, uint32 user_idx, + +static void init_sam_entry2(SAM_ENTRY2 *sam, uint32 user_idx, uint32 len_sam_name, uint32 len_sam_desc, uint32 rid_user, uint16 acb_info) { - if (sam == NULL) return False; - - DEBUG(5,("make_sam_entry2\n")); + DEBUG(5,("init_sam_entry2\n")); sam->user_idx = user_idx; sam->rid_user = rid_user; sam->acb_info = acb_info; sam->pad = 0; - make_uni_hdr(&(sam->hdr_srv_name), len_sam_name); - make_uni_hdr(&(sam->hdr_srv_desc), len_sam_desc); - - return True; + init_uni_hdr(&sam->hdr_srv_name, len_sam_name); + init_uni_hdr(&sam->hdr_srv_desc, len_sam_desc); } /******************************************************************* -reads or writes a SAM_ENTRY2 structure. + Reads or writes a SAM_ENTRY2 structure. ********************************************************************/ + static BOOL sam_io_sam_entry2(char *desc, SAM_ENTRY2 *sam, prs_struct *ps, int depth) { - if (sam == NULL) return False; + if (sam == NULL) + return False; prs_debug(ps, depth, desc, "sam_io_sam_entry2"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("user_idx ", ps, depth, &(sam->user_idx )); + if(!prs_uint32("user_idx ", ps, depth, &sam->user_idx)) + return False; - prs_uint32("rid_user ", ps, depth, &(sam->rid_user )); - prs_uint16("acb_info ", ps, depth, &(sam->acb_info )); - prs_uint16("pad ", ps, depth, &(sam->pad )); + if(!prs_uint32("rid_user ", ps, depth, &sam->rid_user)) + return False; + if(!prs_uint16("acb_info ", ps, depth, &sam->acb_info)) + return False; + if(!prs_uint16("pad ", ps, depth, &sam->pad)) + return False; - smb_io_unihdr("unihdr", &(sam->hdr_srv_name), ps, depth); /* account name unicode string header */ - smb_io_unihdr("unihdr", &(sam->hdr_srv_desc), ps, depth); /* account name unicode string header */ + if(!smb_io_unihdr("unihdr", &sam->hdr_srv_name, ps, depth)) /* account name unicode string header */ + return False; + if(!smb_io_unihdr("unihdr", &sam->hdr_srv_desc, ps, depth)) /* account name unicode string header */ + return False; return True; } /******************************************************************* -reads or writes a SAM_STR3 structure. + Reads or writes a SAM_STR3 structure. ********************************************************************/ + static BOOL sam_io_sam_str3(char *desc, SAM_STR3 *sam, uint32 acct_buf, uint32 desc_buf, prs_struct *ps, int depth) { - if (sam == NULL) return False; + if (sam == NULL) + return False; prs_debug(ps, depth, desc, "sam_io_sam_str3"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_unistr2("unistr2", &(sam->uni_grp_name), acct_buf, ps, depth); /* account name unicode string */ - prs_align(ps); - smb_io_unistr2("unistr2", &(sam->uni_grp_desc), desc_buf, ps, depth); /* account desc unicode string */ - prs_align(ps); + if(!smb_io_unistr2("unistr2", &sam->uni_grp_name, acct_buf, ps, depth)) /* account name unicode string */ + return False; + if(!smb_io_unistr2("unistr2", &sam->uni_grp_desc, desc_buf, ps, depth)) /* account description unicode string */ + return False; return True; } /******************************************************************* -makes a SAM_ENTRY3 structure. + Inits a SAM_ENTRY3 structure. ********************************************************************/ -static BOOL make_sam_entry3(SAM_ENTRY3 *sam, uint32 grp_idx, + +static void init_sam_entry3(SAM_ENTRY3 *sam, uint32 grp_idx, uint32 len_grp_name, uint32 len_grp_desc, uint32 rid_grp) { - if (sam == NULL) return False; - - DEBUG(5,("make_sam_entry3\n")); + DEBUG(5,("init_sam_entry3\n")); sam->grp_idx = grp_idx; sam->rid_grp = rid_grp; sam->attr = 0x07; /* group rid attributes - gets ignored by nt 4.0 */ - make_uni_hdr(&(sam->hdr_grp_name), len_grp_name); - make_uni_hdr(&(sam->hdr_grp_desc), len_grp_desc); - - return True; + init_uni_hdr(&sam->hdr_grp_name, len_grp_name); + init_uni_hdr(&sam->hdr_grp_desc, len_grp_desc); } /******************************************************************* -reads or writes a SAM_ENTRY3 structure. + Reads or writes a SAM_ENTRY3 structure. ********************************************************************/ + static BOOL sam_io_sam_entry3(char *desc, SAM_ENTRY3 *sam, prs_struct *ps, int depth) { - if (sam == NULL) return False; + if (sam == NULL) + return False; prs_debug(ps, depth, desc, "sam_io_sam_entry3"); depth++; - prs_align(ps); - - prs_uint32("grp_idx", ps, depth, &(sam->grp_idx)); - - prs_uint32("rid_grp", ps, depth, &(sam->rid_grp)); - prs_uint32("attr ", ps, depth, &(sam->attr )); - - smb_io_unihdr("unihdr", &(sam->hdr_grp_name), ps, depth); /* account name unicode string header */ - smb_io_unihdr("unihdr", &(sam->hdr_grp_desc), ps, depth); /* account name unicode string header */ - - return True; -} - -/******************************************************************* -makes a SAM_ENTRY4 structure. -********************************************************************/ -static BOOL make_sam_entry4(SAM_ENTRY4 *sam, uint32 user_idx, - uint32 len_acct_name) -{ - if (sam == NULL) return False; - - DEBUG(5,("make_sam_entry4\n")); - - sam->user_idx = user_idx; - make_str_hdr(&(sam->hdr_acct_name), len_acct_name, len_acct_name, - len_acct_name != 0); - - return True; -} - -/******************************************************************* -reads or writes a SAM_ENTRY4 structure. -********************************************************************/ -static BOOL sam_io_sam_entry4(char *desc, SAM_ENTRY4 *sam, prs_struct *ps, int depth) -{ - if (sam == NULL) return False; - - prs_debug(ps, depth, desc, "sam_io_sam_entry4"); - depth++; - - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("user_idx", ps, depth, &(sam->user_idx)); - smb_io_strhdr("strhdr", &(sam->hdr_acct_name), ps, depth); + if(!prs_uint32("grp_idx", ps, depth, &sam->grp_idx)) + return False; - return True; -} - -/******************************************************************* -makes a SAM_ENTRY5 structure. -********************************************************************/ -static BOOL make_sam_entry5(SAM_ENTRY5 *sam, uint32 grp_idx, - uint32 len_grp_name) -{ - if (sam == NULL) return False; + if(!prs_uint32("rid_grp", ps, depth, &sam->rid_grp)) + return False; + if(!prs_uint32("attr ", ps, depth, &sam->attr)) + return False; - DEBUG(5,("make_sam_entry5\n")); - - sam->grp_idx = grp_idx; - make_str_hdr(&(sam->hdr_grp_name), len_grp_name, len_grp_name, - len_grp_name != 0); + if(!smb_io_unihdr("unihdr", &sam->hdr_grp_name, ps, depth)) /* account name unicode string header */ + return False; + if(!smb_io_unihdr("unihdr", &sam->hdr_grp_desc, ps, depth)) /* account name unicode string header */ + return False; return True; } /******************************************************************* -reads or writes a SAM_ENTRY5 structure. + Inits a SAM_ENTRY structure. ********************************************************************/ -static BOOL sam_io_sam_entry5(char *desc, SAM_ENTRY5 *sam, prs_struct *ps, int depth) -{ - if (sam == NULL) return False; - - prs_debug(ps, depth, desc, "sam_io_sam_entry5"); - depth++; - - prs_align(ps); - - prs_uint32("grp_idx", ps, depth, &(sam->grp_idx)); - smb_io_strhdr("strhdr", &(sam->hdr_grp_name), ps, depth); - - return True; -} -/******************************************************************* -makes a SAM_ENTRY structure. -********************************************************************/ -static BOOL make_sam_entry(SAM_ENTRY *sam, uint32 len_sam_name, uint32 rid) +static void init_sam_entry(SAM_ENTRY *sam, uint32 len_sam_name, uint32 rid) { - if (sam == NULL) return False; - - DEBUG(10,("make_sam_entry: %d %d\n", len_sam_name, rid)); + DEBUG(5,("init_sam_entry\n")); sam->rid = rid; - make_uni_hdr(&(sam->hdr_name), len_sam_name); - - return True; + init_uni_hdr(&sam->hdr_name, len_sam_name); } /******************************************************************* -reads or writes a SAM_ENTRY structure. + Reads or writes a SAM_ENTRY structure. ********************************************************************/ + static BOOL sam_io_sam_entry(char *desc, SAM_ENTRY *sam, prs_struct *ps, int depth) { - if (sam == NULL) return False; + if (sam == NULL) + return False; prs_debug(ps, depth, desc, "sam_io_sam_entry"); depth++; - prs_align(ps); - prs_uint32("rid", ps, depth, &(sam->rid )); - smb_io_unihdr("unihdr", &(sam->hdr_name), ps, depth); /* account name unicode string header */ + if(!prs_align(ps)) + return False; + if(!prs_uint32("rid", ps, depth, &sam->rid)) + return False; + if(!smb_io_unihdr("unihdr", &sam->hdr_name, ps, depth)) /* account name unicode string header */ + return False; return True; } /******************************************************************* -makes a SAMR_Q_ENUM_DOM_USERS structure. + Inits a SAMR_Q_ENUM_DOM_USERS structure. ********************************************************************/ -BOOL make_samr_q_enum_dom_users(SAMR_Q_ENUM_DOM_USERS *q_e, POLICY_HND *pol, - uint32 start_idx, + +void init_samr_q_enum_dom_users(SAMR_Q_ENUM_DOM_USERS *q_e, POLICY_HND *pol, + uint16 req_num_entries, uint16 unk_0, uint16 acb_mask, uint16 unk_1, uint32 size) { - if (q_e == NULL || pol == NULL) return False; + DEBUG(5,("init_q_enum_dom_users\n")); - DEBUG(5,("make_samr_q_enum_dom_users\n")); + memcpy(&q_e->pol, pol, sizeof(*pol)); - memcpy(&(q_e->pol), pol, sizeof(*pol)); - - q_e->start_idx = start_idx; /* zero indicates lots */ + q_e->req_num_entries = req_num_entries; /* zero indicates lots */ + q_e->unknown_0 = unk_0; /* this gets returned in the response */ q_e->acb_mask = acb_mask; q_e->unknown_1 = unk_1; q_e->max_size = size; - - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ + BOOL samr_io_q_enum_dom_users(char *desc, SAMR_Q_ENUM_DOM_USERS *q_e, prs_struct *ps, int depth) { - if (q_e == NULL) return False; + if (q_e == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_q_enum_dom_users"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); - prs_align(ps); + if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth)) + return False; + if(!prs_align(ps)) + return False; - prs_uint32("start_idx", ps, depth, &(q_e->start_idx)); - prs_uint16("acb_mask ", ps, depth, &(q_e->acb_mask )); - prs_uint16("unknown_1", ps, depth, &(q_e->unknown_1)); + if(!prs_uint16("req_num_entries", ps, depth, &q_e->req_num_entries)) + return False; + if(!prs_uint16("unknown_0 ", ps, depth, &q_e->unknown_0)) + return False; - prs_uint32("max_size ", ps, depth, &(q_e->max_size )); + if(!prs_uint16("acb_mask ", ps, depth, &q_e->acb_mask)) + return False; + if(!prs_uint16("unknown_1 ", ps, depth, &q_e->unknown_1)) + return False; - prs_align(ps); + if(!prs_uint32("max_size ", ps, depth, &q_e->max_size)) + return False; + + if(!prs_align(ps)) + return False; return True; } /******************************************************************* -makes a SAMR_R_ENUM_DOM_USERS structure. + Inits a SAMR_R_ENUM_DOM_USERS structure. ********************************************************************/ -BOOL make_samr_r_enum_dom_users(SAMR_R_ENUM_DOM_USERS *r_u, - uint32 next_idx, + +void init_samr_r_enum_dom_users(SAMR_R_ENUM_DOM_USERS *r_u, + uint16 total_num_entries, uint16 unk_0, uint32 num_sam_entries, SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES], uint32 status) { - uint32 i; + int i; - if (r_u == NULL) return False; + DEBUG(5,("init_samr_r_enum_dom_users\n")); - DEBUG(5,("make_samr_r_enum_dom_users\n")); + if (num_sam_entries >= MAX_SAM_ENTRIES) { + num_sam_entries = MAX_SAM_ENTRIES; + DEBUG(5,("limiting number of entries to %d\n", + num_sam_entries)); + } - r_u->next_idx = next_idx; - r_u->sam = NULL; - r_u->uni_acct_name = NULL; + r_u->total_num_entries = total_num_entries; + r_u->unknown_0 = unk_0; - if (num_sam_entries != 0) - { + if (total_num_entries > 0) { r_u->ptr_entries1 = 1; r_u->ptr_entries2 = 1; r_u->num_entries2 = num_sam_entries; r_u->num_entries3 = num_sam_entries; - r_u->sam = (SAM_ENTRY*)Realloc(NULL, r_u->num_entries2 * sizeof(r_u->sam[0])); - r_u->uni_acct_name = (UNISTR2*)Realloc(NULL, r_u->num_entries2 * sizeof(r_u->uni_acct_name[0])); + SMB_ASSERT_ARRAY(r_u->sam, num_sam_entries); + SMB_ASSERT_ARRAY(r_u->uni_acct_name, num_sam_entries); - if (r_u->sam == NULL || r_u->uni_acct_name == NULL) - { - DEBUG(0,("NULL pointers in SAMR_R_QUERY_DISPINFO\n")); - return False; - } - - for (i = 0; i < num_sam_entries; i++) - { - make_sam_entry(&(r_u->sam[i]), + for (i = 0; i < num_sam_entries; i++) { + init_sam_entry(&(r_u->sam[i]), pass[i].uni_user_name.uni_str_len, pass[i].user_rid); - copy_unistr2(&(r_u->uni_acct_name[i]), &(pass[i].uni_user_name)); + copy_unistr2(&r_u->uni_acct_name[i], &(pass[i].uni_user_name)); } r_u->num_entries4 = num_sam_entries; - } - else - { + } else { r_u->ptr_entries1 = 0; r_u->num_entries2 = num_sam_entries; r_u->ptr_entries2 = 1; } r_u->status = status; - - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL samr_io_r_enum_dom_users(char *desc, SAMR_R_ENUM_DOM_USERS *r_u, prs_struct *ps, int depth) + +BOOL samr_io_r_enum_dom_users(char *desc, SAMR_R_ENUM_DOM_USERS *r_u, prs_struct *ps, int depth) { - uint32 i; + int i; - if (r_u == NULL) return False; + if (r_u == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_r_enum_dom_users"); depth++; - prs_align(ps); - - prs_uint32("next_idx ", ps, depth, &(r_u->next_idx )); - prs_uint32("ptr_entries1", ps, depth, &(r_u->ptr_entries1)); + if(!prs_align(ps)) + return False; - if (r_u->ptr_entries1 != 0) - { - prs_uint32("num_entries2", ps, depth, &(r_u->num_entries2)); - prs_uint32("ptr_entries2", ps, depth, &(r_u->ptr_entries2)); - prs_uint32("num_entries3", ps, depth, &(r_u->num_entries3)); + if(!prs_uint16("total_num_entries", ps, depth, &r_u->total_num_entries)) + return False; + if(!prs_uint16("unknown_0 ", ps, depth, &r_u->unknown_0)) + return False; + if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1)) + return False; - if (ps->io) - { - r_u->sam = (SAM_ENTRY*)Realloc(NULL, r_u->num_entries2 * sizeof(r_u->sam[0])); - r_u->uni_acct_name = (UNISTR2*)Realloc(NULL, r_u->num_entries2 * sizeof(r_u->uni_acct_name[0])); - } - - if ((r_u->sam == NULL || r_u->uni_acct_name == NULL) && r_u->num_entries2 != 0) - { - DEBUG(0,("NULL pointers in SAMR_R_ENUM_DOM_USERS\n")); - r_u->num_entries4 = 0; - r_u->status = 0xC0000000|NT_STATUS_MEMORY_NOT_ALLOCATED; + if (r_u->total_num_entries != 0 && r_u->ptr_entries1 != 0) { + if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2)) + return False; + if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2)) + return False; + if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3)) return False; - } - for (i = 0; i < r_u->num_entries2; i++) - { - sam_io_sam_entry("", &(r_u->sam[i]), ps, depth); - } + SMB_ASSERT_ARRAY(r_u->sam, r_u->num_entries2); - for (i = 0; i < r_u->num_entries2; i++) - { - smb_io_unistr2("", &(r_u->uni_acct_name[i]), r_u->sam[i].hdr_name.buffer, ps, depth); - prs_align(ps); + for (i = 0; i < r_u->num_entries2; i++) { + if(!sam_io_sam_entry("", &r_u->sam[i], ps, depth)) + return False; } - prs_align(ps); - - } - - prs_uint32("num_entries4", ps, depth, &(r_u->num_entries4)); - prs_uint32("status", ps, depth, &(r_u->status)); - - return True; -} - -/******************************************************************* -makes a SAMR_Q_QUERY_DISPINFO structure. -********************************************************************/ -BOOL make_samr_q_query_dispinfo(SAMR_Q_QUERY_DISPINFO *q_e, POLICY_HND *pol, - uint16 switch_level, uint32 start_idx, - uint32 max_entries) -{ - if (q_e == NULL || pol == NULL) return False; - - DEBUG(5,("make_samr_q_query_dispinfo\n")); - - memcpy(&(q_e->domain_pol), pol, sizeof(*pol)); - - q_e->switch_level = switch_level; - - q_e->start_idx = start_idx; - q_e->max_entries = max_entries; - q_e->max_size = 0xffff; /* Not especially useful */ - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_q_query_dispinfo(char *desc, SAMR_Q_QUERY_DISPINFO *q_e, prs_struct *ps, int depth) -{ - if (q_e == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_q_query_dispinfo"); - depth++; - - prs_align(ps); - - smb_io_pol_hnd("domain_pol", &(q_e->domain_pol), ps, depth); - prs_align(ps); - - prs_uint16("switch_level", ps, depth, &(q_e->switch_level)); - prs_align(ps); - - prs_uint32("start_idx ", ps, depth, &(q_e->start_idx )); - prs_uint32("max_entries ", ps, depth, &(q_e->max_entries )); - prs_uint32("max_size ", ps, depth, &(q_e->max_size )); - - return True; -} - - -/******************************************************************* -makes a SAM_DISPINFO_1 structure. -********************************************************************/ -BOOL make_sam_dispinfo_1(SAM_DISPINFO_1 *sam, uint32 *num_entries, - uint32 *data_size, uint32 start_idx, - SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES]) -{ - uint32 len_sam_name, len_sam_full, len_sam_desc; - uint32 max_entries, max_data_size; - uint32 dsize = 0; - uint32 i; - - if (sam == NULL || num_entries == NULL || data_size == NULL) return False; - - DEBUG(5,("make_sam_dispinfo_1\n")); - - max_entries = *num_entries; - max_data_size = *data_size; + SMB_ASSERT_ARRAY(r_u->uni_acct_name, r_u->num_entries2); - for (i = 0; (i < max_entries) && (dsize < max_data_size); i++) - { - len_sam_name = pass[i].uni_user_name.uni_str_len; - len_sam_full = pass[i].uni_full_name.uni_str_len; - len_sam_desc = pass[i].uni_acct_desc.uni_str_len; - - make_sam_entry1(&(sam->sam[i]), start_idx + i + 1, - len_sam_name, len_sam_full, len_sam_desc, - pass[i].user_rid, pass[i].acb_info); - - copy_unistr2(&(sam->str[i].uni_acct_name), &(pass[i].uni_user_name)); - copy_unistr2(&(sam->str[i].uni_full_name), &(pass[i].uni_full_name)); - copy_unistr2(&(sam->str[i].uni_acct_desc), &(pass[i].uni_acct_desc)); - - dsize += sizeof(SAM_ENTRY1); - dsize += len_sam_name + len_sam_full + len_sam_desc; - } - - *num_entries = i; - *data_size = dsize; - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -static BOOL sam_io_sam_dispinfo_1(char *desc, SAM_DISPINFO_1 *sam, uint32 num_entries, prs_struct *ps, int depth) -{ - uint32 i; - - if (sam == NULL) return False; - - prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_1"); - depth++; - - prs_align(ps); - - SMB_ASSERT_ARRAY(sam->sam, num_entries); - - for (i = 0; i < num_entries; i++) - { - sam_io_sam_entry1("", &(sam->sam[i]), ps, depth); - } - - for (i = 0; i < num_entries; i++) - { - sam_io_sam_str1 ("", &(sam->str[i]), - sam->sam[i].hdr_acct_name.buffer, - sam->sam[i].hdr_user_name.buffer, - sam->sam[i].hdr_user_desc.buffer, - ps, depth); - } - - return True; -} - - -/******************************************************************* -makes a SAM_DISPINFO_2 structure. -********************************************************************/ -BOOL make_sam_dispinfo_2(SAM_DISPINFO_2 *sam, uint32 *num_entries, - uint32 *data_size, uint32 start_idx, - SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES]) -{ - uint32 len_sam_name, len_sam_desc; - uint32 max_entries, max_data_size; - uint32 dsize = 0; - uint32 i; - - if (sam == NULL || num_entries == NULL || data_size == NULL) return False; - - DEBUG(5,("make_sam_dispinfo_2\n")); - - max_entries = *num_entries; - max_data_size = *data_size; - - for (i = 0; (i < max_entries) && (dsize < max_data_size); i++) - { - len_sam_name = pass[i].uni_user_name.uni_str_len; - len_sam_desc = pass[i].uni_acct_desc.uni_str_len; - - make_sam_entry2(&(sam->sam[i]), start_idx + i + 1, - len_sam_name, len_sam_desc, - pass[i].user_rid, pass[i].acb_info); + for (i = 0; i < r_u->num_entries2; i++) { + if(!smb_io_unistr2("", &r_u->uni_acct_name[i], + r_u->sam[i].hdr_name.buffer, ps, depth)) + return False; + } - copy_unistr2(&(sam->str[i].uni_srv_name), &(pass[i].uni_user_name)); - copy_unistr2(&(sam->str[i].uni_srv_desc), &(pass[i].uni_acct_desc)); + if(!prs_align(ps)) + return False; - dsize += sizeof(SAM_ENTRY2); - dsize += len_sam_name + len_sam_desc; + if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4)) + return False; } - *num_entries = i; - *data_size = dsize; + if(!prs_uint32("status", ps, depth, &r_u->status)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Inits a SAMR_Q_ENUM_DOM_ALIASES structure. ********************************************************************/ -static BOOL sam_io_sam_dispinfo_2(char *desc, SAM_DISPINFO_2 *sam, uint32 num_entries, prs_struct *ps, int depth) -{ - uint32 i; - - if (sam == NULL) return False; - - prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_2"); - depth++; - - prs_align(ps); - - SMB_ASSERT_ARRAY(sam->sam, num_entries); - - for (i = 0; i < num_entries; i++) - { - sam_io_sam_entry2("", &(sam->sam[i]), ps, depth); - } - for (i = 0; i < num_entries; i++) - { - sam_io_sam_str2 ("", &(sam->str[i]), - sam->sam[i].hdr_srv_name.buffer, - sam->sam[i].hdr_srv_desc.buffer, - ps, depth); - } - - return True; -} - - -/******************************************************************* -makes a SAM_DISPINFO_3 structure. -********************************************************************/ -BOOL make_sam_dispinfo_3(SAM_DISPINFO_3 *sam, uint32 *num_entries, - uint32 *data_size, uint32 start_idx, - DOMAIN_GRP *grp) +void init_samr_q_enum_dom_aliases(SAMR_Q_ENUM_DOM_ALIASES *q_e, POLICY_HND *pol, uint32 size) { - uint32 len_sam_name, len_sam_desc; - uint32 max_entries, max_data_size; - uint32 dsize = 0; - uint32 i; + DEBUG(5,("init_q_enum_dom_aliases\n")); - if (sam == NULL || num_entries == NULL || data_size == NULL) return False; + memcpy(&q_e->pol, pol, sizeof(*pol)); - DEBUG(5,("make_sam_dispinfo_3\n")); - - max_entries = *num_entries; - max_data_size = *data_size; - - for (i = 0; (i < max_entries) && (dsize < max_data_size); i++) - { - len_sam_name = strlen(grp[i].name); - len_sam_desc = strlen(grp[i].comment); - - make_sam_entry3(&(sam->sam[i]), start_idx + i + 1, - len_sam_name, len_sam_desc, - grp[i].rid); - - make_unistr2(&(sam->str[i].uni_grp_name), grp[i].name , len_sam_name); - make_unistr2(&(sam->str[i].uni_grp_desc), grp[i].comment, len_sam_desc); - - dsize += sizeof(SAM_ENTRY3); - dsize += (len_sam_name + len_sam_desc) * 2; - } - - *num_entries = i; - *data_size = dsize; - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -static BOOL sam_io_sam_dispinfo_3(char *desc, SAM_DISPINFO_3 *sam, uint32 num_entries, prs_struct *ps, int depth) -{ - uint32 i; - - if (sam == NULL) return False; - - prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_3"); - depth++; - - prs_align(ps); - - SMB_ASSERT_ARRAY(sam->sam, num_entries); - - for (i = 0; i < num_entries; i++) - { - sam_io_sam_entry3("", &(sam->sam[i]), ps, depth); - } - - for (i = 0; i < num_entries; i++) - { - sam_io_sam_str3 ("", &(sam->str[i]), - sam->sam[i].hdr_grp_name.buffer, - sam->sam[i].hdr_grp_desc.buffer, - ps, depth); - } - - return True; + q_e->unknown_0 = 0; + q_e->max_size = size; } /******************************************************************* -makes a SAM_DISPINFO_4 structure. + Reads or writes a structure. ********************************************************************/ -BOOL make_sam_dispinfo_4(SAM_DISPINFO_4 *sam, uint32 *num_entries, - uint32 *data_size, uint32 start_idx, - SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES]) -{ - fstring sam_name; - uint32 len_sam_name; - uint32 max_entries, max_data_size; - uint32 dsize = 0; - uint32 i; - - if (sam == NULL || num_entries == NULL || data_size == NULL) return False; - DEBUG(5,("make_sam_dispinfo_4\n")); - - max_entries = *num_entries; - max_data_size = *data_size; - - for (i = 0; (i < max_entries) && (dsize < max_data_size); i++) - { - len_sam_name = pass[i].uni_user_name.uni_str_len; - - make_sam_entry4(&(sam->sam[i]), start_idx + i + 1, - len_sam_name); - - unistr2_to_ascii(sam_name, &(pass[i].uni_user_name), sizeof(sam_name)); - make_string2(&(sam->str[i].acct_name), sam_name, len_sam_name); - - dsize += sizeof(SAM_ENTRY4); - dsize += len_sam_name; - } - - *num_entries = i; - *data_size = dsize; - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -static BOOL sam_io_sam_dispinfo_4(char *desc, SAM_DISPINFO_4 *sam, uint32 num_entries, prs_struct *ps, int depth) +BOOL samr_io_q_enum_dom_aliases(char *desc, SAMR_Q_ENUM_DOM_ALIASES *q_e, prs_struct *ps, int depth) { - uint32 i; - - if (sam == NULL) return False; + if (q_e == NULL) + return False; - prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_4"); + prs_debug(ps, depth, desc, "samr_io_q_enum_dom_aliases"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - SMB_ASSERT_ARRAY(sam->sam, num_entries); + if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth)) + return False; + if(!prs_align(ps)) + return False; - for (i = 0; i < num_entries; i++) - { - sam_io_sam_entry4("", &(sam->sam[i]), ps, depth); - } + if(!prs_uint32("unknown_0", ps, depth, &q_e->unknown_0)) + return False; + if(!prs_uint32("max_size ", ps, depth, &q_e->max_size )) + return False; - for (i = 0; i < num_entries; i++) - { - smb_io_string2("acct_name", &(sam->str[i].acct_name), - sam->sam[i].hdr_acct_name.buffer, ps, depth); - } + if(!prs_align(ps)) + return False; return True; } /******************************************************************* -makes a SAM_DISPINFO_5 structure. + Inits a SAMR_R_ENUM_DOM_ALIASES structure. ********************************************************************/ -BOOL make_sam_dispinfo_5(SAM_DISPINFO_5 *sam, uint32 *num_entries, - uint32 *data_size, uint32 start_idx, - DOMAIN_GRP *grp) -{ - uint32 len_sam_name; - uint32 max_entries, max_data_size; - uint32 dsize = 0; - uint32 i; - - if (sam == NULL || num_entries == NULL || data_size == NULL) return False; - - DEBUG(5,("make_sam_dispinfo_5\n")); - - max_entries = *num_entries; - max_data_size = *data_size; - - for (i = 0; (i < max_entries) && (dsize < max_data_size); i++) - { - len_sam_name = strlen(grp[i].name); - - make_sam_entry5(&(sam->sam[i]), start_idx + i + 1, - len_sam_name); - - make_string2(&(sam->str[i].grp_name), grp[i].name, - len_sam_name); - - dsize += sizeof(SAM_ENTRY5); - dsize += len_sam_name; - } - - *num_entries = i; - *data_size = dsize; - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -static BOOL sam_io_sam_dispinfo_5(char *desc, SAM_DISPINFO_5 *sam, uint32 num_entries, prs_struct *ps, int depth) +void init_samr_r_enum_dom_aliases(SAMR_R_ENUM_DOM_ALIASES *r_u, + uint32 num_sam_entries, SAM_USER_INFO_21 grps[MAX_SAM_ENTRIES], + uint32 status) { - uint32 i; - - if (sam == NULL) return False; - - prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_5"); - depth++; + int i; - prs_align(ps); - - SMB_ASSERT_ARRAY(sam->sam, num_entries); + DEBUG(5,("init_samr_r_enum_dom_aliases\n")); - for (i = 0; i < num_entries; i++) - { - sam_io_sam_entry5("", &(sam->sam[i]), ps, depth); + if (num_sam_entries >= MAX_SAM_ENTRIES) { + num_sam_entries = MAX_SAM_ENTRIES; + DEBUG(5,("limiting number of entries to %d\n", + num_sam_entries)); } - for (i = 0; i < num_entries; i++) - { - smb_io_string2("grp_name", &(sam->str[i].grp_name), - sam->sam[i].hdr_grp_name.buffer, ps, depth); - } - - return True; -} - - -/******************************************************************* -makes a SAMR_R_QUERY_DISPINFO structure. -********************************************************************/ -BOOL make_samr_r_query_dispinfo(SAMR_R_QUERY_DISPINFO *r_u, - uint32 num_entries, uint32 data_size, - uint16 switch_level, SAM_DISPINFO_CTR *ctr, - uint32 status) -{ - if (r_u == NULL) return False; - - DEBUG(5,("make_samr_r_query_dispinfo: level %d\n", switch_level)); - - r_u->total_size = 0; /* not calculated */ - r_u->data_size = data_size; - - r_u->switch_level = switch_level; - r_u->num_entries = num_entries; - r_u->ptr_entries = 1; - r_u->num_entries2 = num_entries; - r_u->ctr = ctr; - - r_u->status = status; + r_u->num_entries = num_sam_entries; - return True; -} - - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_r_query_dispinfo(char *desc, SAMR_R_QUERY_DISPINFO *r_u, prs_struct *ps, int depth) -{ - if (r_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_r_query_dispinfo"); - depth++; + if (num_sam_entries > 0) { + r_u->ptr_entries = 1; + r_u->num_entries2 = num_sam_entries; + r_u->ptr_entries2 = 1; + r_u->num_entries3 = num_sam_entries; - prs_align(ps); + SMB_ASSERT_ARRAY(r_u->sam, num_sam_entries); - prs_uint32("total_size ", ps, depth, &(r_u->total_size )); - prs_uint32("data_size ", ps, depth, &(r_u->data_size )); - prs_uint16("switch_level", ps, depth, &(r_u->switch_level)); - prs_align(ps); + for (i = 0; i < num_sam_entries; i++) { + init_sam_entry(&r_u->sam[i], + grps[i].uni_user_name.uni_str_len, + grps[i].user_rid); - prs_uint32("num_entries ", ps, depth, &(r_u->num_entries )); - prs_uint32("ptr_entries ", ps, depth, &(r_u->ptr_entries )); - prs_uint32("num_entries2", ps, depth, &(r_u->num_entries2)); - - switch (r_u->switch_level) - { - case 0x1: - { - sam_io_sam_dispinfo_1("users", r_u->ctr->sam.info1, r_u->num_entries, ps, depth); - break; - } - case 0x2: - { - sam_io_sam_dispinfo_2("servers", r_u->ctr->sam.info2, r_u->num_entries, ps, depth); - break; + copy_unistr2(&r_u->uni_grp_name[i], &(grps[i].uni_user_name)); } - case 0x3: - { - sam_io_sam_dispinfo_3("groups", r_u->ctr->sam.info3, r_u->num_entries, ps, depth); - break; - } - case 0x4: - { - sam_io_sam_dispinfo_4("user list", r_u->ctr->sam.info4,r_u->num_entries, ps, depth); - break; - } - case 0x5: - { - sam_io_sam_dispinfo_5("group list", r_u->ctr->sam.info5, r_u->num_entries, ps, depth); - break; - } - default: - { - DEBUG(5,("samr_io_r_query_dispinfo: unknown switch value\n")); - break; - } - } - - prs_align(ps); - prs_align(ps); - prs_uint32("status", ps, depth, &(r_u->status)); - - return True; -} - - -/******************************************************************* -makes a SAMR_Q_OPEN_GROUP structure. -********************************************************************/ -BOOL make_samr_q_open_group(SAMR_Q_OPEN_GROUP *q_c, - const POLICY_HND *hnd, uint32 unk, uint32 rid) -{ - if (q_c == NULL || hnd == NULL) return False; - - DEBUG(5,("make_samr_q_open_group\n")); - - memcpy(&(q_c->domain_pol), hnd, sizeof(q_c->domain_pol)); - q_c->unknown = unk; - q_c->rid_group = rid; - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_q_open_group(char *desc, SAMR_Q_OPEN_GROUP *q_u, prs_struct *ps, int depth) -{ - if (q_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_q_open_group"); - depth++; - - prs_align(ps); - - smb_io_pol_hnd("domain_pol", &(q_u->domain_pol), ps, depth); - - prs_uint32("unknown ", ps, depth, &(q_u->unknown )); - prs_uint32("rid_group", ps, depth, &(q_u->rid_group)); - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_r_open_group(char *desc, SAMR_R_OPEN_GROUP *r_u, prs_struct *ps, int depth) -{ - if (r_u == NULL) return False; - prs_debug(ps, depth, desc, "samr_io_r_open_group"); - depth++; - - prs_align(ps); - - smb_io_pol_hnd("pol", &(r_u->pol), ps, depth); - prs_align(ps); - - prs_uint32("status", ps, depth, &(r_u->status)); - - return True; -} - - -/******************************************************************* -makes a GROUP_INFO1 structure. -********************************************************************/ -BOOL make_samr_group_info1(GROUP_INFO1 *gr1, - char *acct_name, char *acct_desc, - uint32 num_members) -{ - int desc_len = acct_desc != NULL ? strlen(acct_desc) : 0; - int acct_len = acct_name != NULL ? strlen(acct_name) : 0; - if (gr1 == NULL) return False; - - DEBUG(5,("make_samr_group_info1\n")); - - make_uni_hdr(&(gr1->hdr_acct_name), acct_len); - - gr1->unknown_1 = 0x3; - gr1->num_members = num_members; - - make_uni_hdr(&(gr1->hdr_acct_desc), desc_len); - - make_unistr2(&(gr1->uni_acct_name), acct_name, acct_len); - make_unistr2(&(gr1->uni_acct_desc), acct_desc, desc_len); - - return True; -} - - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_group_info1(char *desc, GROUP_INFO1 *gr1, prs_struct *ps, int depth) -{ - if (gr1 == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_group_info1"); - depth++; - - prs_align(ps); - - smb_io_unihdr ("hdr_acct_name", &(gr1->hdr_acct_name) , ps, depth); - - prs_uint32("unknown_1", ps, depth, &(gr1->unknown_1)); - prs_uint32("num_members", ps, depth, &(gr1->num_members)); - - smb_io_unihdr ("hdr_acct_desc", &(gr1->hdr_acct_desc) , ps, depth); - - smb_io_unistr2("uni_acct_name", &(gr1->uni_acct_name), gr1->hdr_acct_name.buffer, ps, depth); - prs_align(ps); - - smb_io_unistr2("uni_acct_desc", &(gr1->uni_acct_desc), gr1->hdr_acct_desc.buffer, ps, depth); - prs_align(ps); - - return True; -} - -/******************************************************************* -makes a GROUP_INFO4 structure. -********************************************************************/ -BOOL make_samr_group_info4(GROUP_INFO4 *gr4, const char *acct_desc) -{ - int acct_len = acct_desc != NULL ? strlen(acct_desc) : 0; - if (gr4 == NULL) return False; - - DEBUG(5,("make_samr_group_info4\n")); - - make_uni_hdr(&(gr4->hdr_acct_desc), acct_len); - make_unistr2(&(gr4->uni_acct_desc), acct_desc, acct_len); - - return True; -} - - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_group_info4(char *desc, GROUP_INFO4 *gr4, prs_struct *ps, int depth) -{ - if (gr4 == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_group_info4"); - depth++; - - prs_align(ps); - - smb_io_unihdr ("hdr_acct_desc", &(gr4->hdr_acct_desc) , ps, depth); - smb_io_unistr2("uni_acct_desc", &(gr4->uni_acct_desc), gr4->hdr_acct_desc.buffer, ps, depth); - prs_align(ps); - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_group_info_ctr(char *desc, GROUP_INFO_CTR *ctr, prs_struct *ps, int depth) -{ - if (ctr == NULL) return False; - - prs_debug(ps, depth, desc, "samr_group_info_ctr"); - depth++; - - prs_uint16("switch_value1", ps, depth, &(ctr->switch_value1)); - prs_uint16("switch_value2", ps, depth, &(ctr->switch_value2)); - - switch (ctr->switch_value1) - { - case 1: - { - samr_io_group_info1("group_info1", &(ctr->group.info1), ps, depth); - break; - } - case 4: - { - samr_io_group_info4("group_info4", &(ctr->group.info4), ps, depth); - break; - } - default: - { - DEBUG(4,("samr_group_info_ctr: unsupported switch level\n")); - break; - } + r_u->num_entries4 = num_sam_entries; + } else { + r_u->ptr_entries = 0; } - prs_align(ps); - - return True; -} - - -/******************************************************************* -makes a SAMR_Q_CREATE_DOM_GROUP structure. -********************************************************************/ -BOOL make_samr_q_create_dom_group(SAMR_Q_CREATE_DOM_GROUP *q_e, - POLICY_HND *pol, - const char *acct_desc) -{ - int acct_len = acct_desc != NULL ? strlen(acct_desc) : 0; - if (q_e == NULL || pol == NULL) return False; - - DEBUG(5,("make_samr_q_create_dom_group\n")); - - memcpy(&(q_e->pol), pol, sizeof(*pol)); - - make_uni_hdr(&(q_e->hdr_acct_desc), acct_len); - make_unistr2(&(q_e->uni_acct_desc), acct_desc, acct_len); - - q_e->unknown_1 = 0x0002; - q_e->unknown_2 = 0x0001; - - return True; -} - - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_q_create_dom_group(char *desc, SAMR_Q_CREATE_DOM_GROUP *q_e, prs_struct *ps, int depth) -{ - if (q_e == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_q_create_dom_group"); - depth++; - - prs_align(ps); - - smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); - prs_align(ps); - - smb_io_unihdr ("hdr_acct_desc", &(q_e->hdr_acct_desc), ps, depth); - smb_io_unistr2("uni_acct_desc", &(q_e->uni_acct_desc), q_e->hdr_acct_desc.buffer, ps, depth); - prs_align(ps); - - prs_uint16("unknown_1", ps, depth, &(q_e->unknown_1)); - prs_uint16("unknown_2", ps, depth, &(q_e->unknown_2)); - - return True; -} - - -/******************************************************************* -makes a SAMR_R_CREATE_DOM_GROUP structure. -********************************************************************/ -BOOL make_samr_r_create_dom_group(SAMR_R_CREATE_DOM_GROUP *r_u, POLICY_HND *pol, - uint32 rid, uint32 status) -{ - if (r_u == NULL) return False; - - DEBUG(5,("make_samr_r_create_dom_group\n")); - - memcpy(&(r_u->pol), pol, sizeof(*pol)); - - r_u->rid = rid ; r_u->status = status; - - return True; } - /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL samr_io_r_create_dom_group(char *desc, SAMR_R_CREATE_DOM_GROUP *r_u, prs_struct *ps, int depth) -{ - if (r_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_r_create_dom_group"); - depth++; - - prs_align(ps); - smb_io_pol_hnd("pol", &(r_u->pol), ps, depth); - prs_align(ps); - - prs_uint32("rid ", ps, depth, &(r_u->rid )); - prs_uint32("status", ps, depth, &(r_u->status)); - - return True; -} - -/******************************************************************* -makes a SAMR_Q_DELETE_DOM_GROUP structure. -********************************************************************/ -BOOL make_samr_q_delete_dom_group(SAMR_Q_DELETE_DOM_GROUP *q_c, POLICY_HND *hnd) -{ - if (q_c == NULL || hnd == NULL) return False; - - DEBUG(5,("make_samr_q_delete_dom_group\n")); - - memcpy(&(q_c->group_pol), hnd, sizeof(q_c->group_pol)); - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_q_delete_dom_group(char *desc, SAMR_Q_DELETE_DOM_GROUP *q_u, prs_struct *ps, int depth) -{ - if (q_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_q_delete_dom_group"); - depth++; - - prs_align(ps); - - smb_io_pol_hnd("group_pol", &(q_u->group_pol), ps, depth); - - return True; -} - -/******************************************************************* -makes a SAMR_R_DELETE_DOM_GROUP structure. -********************************************************************/ -BOOL make_samr_r_delete_dom_group(SAMR_R_DELETE_DOM_GROUP *r_u, - uint32 status) +BOOL samr_io_r_enum_dom_aliases(char *desc, SAMR_R_ENUM_DOM_ALIASES *r_u, prs_struct *ps, int depth) { - if (r_u == NULL) return False; - - DEBUG(5,("make_samr_r_delete_dom_group\n")); + int i; - r_u->status = status; + if (r_u == NULL) + return False; - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_r_delete_dom_group(char *desc, SAMR_R_DELETE_DOM_GROUP *r_u, prs_struct *ps, int depth) -{ - if (r_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_r_delete_dom_group"); + prs_debug(ps, depth, desc, "samr_io_r_enum_dom_aliases"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("status", ps, depth, &(r_u->status)); + if(!prs_uint32("num_entries", ps, depth, &r_u->num_entries)) + return False; + if(!prs_uint32("ptr_entries", ps, depth, &r_u->ptr_entries)) + return False; - return True; -} + if (r_u->num_entries != 0 && r_u->ptr_entries != 0) { + if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2)) + return False; + if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2)) + return False; + if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3)) + return False; + SMB_ASSERT_ARRAY(r_u->sam, r_u->num_entries); + for (i = 0; i < r_u->num_entries; i++) { + if(!sam_io_sam_entry("", &r_u->sam[i], ps, depth)) + return False; + } -/******************************************************************* -makes a SAMR_Q_DEL_GROUPMEM structure. -********************************************************************/ -BOOL make_samr_q_del_groupmem(SAMR_Q_DEL_GROUPMEM *q_e, - POLICY_HND *pol, - uint32 rid) -{ - if (q_e == NULL || pol == NULL) return False; + for (i = 0; i < r_u->num_entries; i++) { + if(!smb_io_unistr2("", &r_u->uni_grp_name[i], r_u->sam[i].hdr_name.buffer, ps, depth)) + return False; + } - DEBUG(5,("make_samr_q_del_groupmem\n")); + if(!prs_align(ps)) + return False; - memcpy(&(q_e->pol), pol, sizeof(*pol)); + if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4)) + return False; + } - q_e->rid = rid; + if(!prs_uint32("status", ps, depth, &r_u->status)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Inits a SAMR_Q_QUERY_DISPINFO structure. ********************************************************************/ -BOOL samr_io_q_del_groupmem(char *desc, SAMR_Q_DEL_GROUPMEM *q_e, prs_struct *ps, int depth) -{ - if (q_e == NULL) return False; - prs_debug(ps, depth, desc, "samr_io_q_del_groupmem"); - depth++; - - prs_align(ps); - - smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); - prs_align(ps); - - prs_uint32("rid ", ps, depth, &(q_e->rid)); - - return True; -} - - -/******************************************************************* -makes a SAMR_R_DEL_GROUPMEM structure. -********************************************************************/ -BOOL make_samr_r_del_groupmem(SAMR_R_DEL_GROUPMEM *r_u, POLICY_HND *pol, - uint32 status) +void init_samr_q_query_dispinfo(SAMR_Q_QUERY_DISPINFO *q_e, POLICY_HND *pol, + uint16 switch_level, uint32 start_idx, uint32 size) { - if (r_u == NULL) return False; - - DEBUG(5,("make_samr_r_del_groupmem\n")); + DEBUG(5,("init_q_query_dispinfo\n")); - r_u->status = status; - - return True; -} + memcpy(&q_e->pol, pol, sizeof(*pol)); + q_e->switch_level = switch_level; -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_r_del_groupmem(char *desc, SAMR_R_DEL_GROUPMEM *r_u, prs_struct *ps, int depth) -{ - if (r_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_r_del_groupmem"); - depth++; - - prs_align(ps); - - prs_uint32("status", ps, depth, &(r_u->status)); - - return True; + q_e->unknown_0 = 0; + q_e->start_idx = start_idx; + q_e->unknown_1 = 0x000007d0; + q_e->max_size = size; } - /******************************************************************* -makes a SAMR_Q_ADD_GROUPMEM structure. + Reads or writes a structure. ********************************************************************/ -BOOL make_samr_q_add_groupmem(SAMR_Q_ADD_GROUPMEM *q_e, - POLICY_HND *pol, - uint32 rid) -{ - if (q_e == NULL || pol == NULL) return False; - - DEBUG(5,("make_samr_q_add_groupmem\n")); - - memcpy(&(q_e->pol), pol, sizeof(*pol)); - - q_e->rid = rid; - q_e->unknown = 0x0005; - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_q_add_groupmem(char *desc, SAMR_Q_ADD_GROUPMEM *q_e, prs_struct *ps, int depth) +BOOL samr_io_q_query_dispinfo(char *desc, SAMR_Q_QUERY_DISPINFO *q_e, prs_struct *ps, int depth) { - if (q_e == NULL) return False; + if (q_e == NULL) + return False; - prs_debug(ps, depth, desc, "samr_io_q_add_groupmem"); + prs_debug(ps, depth, desc, "samr_io_q_query_dispinfo"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); - prs_align(ps); + if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth)) + return False; + if(!prs_align(ps)) + return False; - prs_uint32("rid ", ps, depth, &(q_e->rid)); - prs_uint32("unknown", ps, depth, &(q_e->unknown)); - - return True; -} + if(!prs_uint16("switch_level", ps, depth, &q_e->switch_level)) + return False; + if(!prs_uint16("unknown_0 ", ps, depth, &q_e->unknown_0)) + return False; + if(!prs_uint32("start_idx ", ps, depth, &q_e->start_idx)) + return False; + if(!prs_uint32("unknown_1 ", ps, depth, &q_e->unknown_1)) + return False; + if(!prs_uint32("max_size ", ps, depth, &q_e->max_size)) + return False; - -/******************************************************************* -makes a SAMR_R_ADD_GROUPMEM structure. -********************************************************************/ -BOOL make_samr_r_add_groupmem(SAMR_R_ADD_GROUPMEM *r_u, POLICY_HND *pol, - uint32 status) -{ - if (r_u == NULL) return False; - - DEBUG(5,("make_samr_r_add_groupmem\n")); - - r_u->status = status; + if(!prs_align(ps)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Inits a SAM_INFO_2 structure. ********************************************************************/ -BOOL samr_io_r_add_groupmem(char *desc, SAMR_R_ADD_GROUPMEM *r_u, prs_struct *ps, int depth) -{ - if (r_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_r_add_groupmem"); - depth++; - - prs_align(ps); - - prs_uint32("status", ps, depth, &(r_u->status)); - - return True; -} - - -/******************************************************************* -makes a SAMR_Q_SET_GROUPINFO structure. -********************************************************************/ -BOOL make_samr_q_set_groupinfo(SAMR_Q_SET_GROUPINFO *q_e, - POLICY_HND *pol, GROUP_INFO_CTR *ctr) -{ - if (q_e == NULL || pol == NULL) return False; - - DEBUG(5,("make_samr_q_set_groupinfo\n")); - - memcpy(&(q_e->pol), pol, sizeof(*pol)); - q_e->ctr = ctr; - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_q_set_groupinfo(char *desc, SAMR_Q_SET_GROUPINFO *q_e, prs_struct *ps, int depth) +void init_sam_info_2(SAM_INFO_2 *sam, uint32 acb_mask, + uint32 start_idx, uint32 num_sam_entries, + SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES]) { - if (q_e == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_q_set_groupinfo"); - depth++; - - prs_align(ps); - - smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); - prs_align(ps); + int i; + int entries_added; - samr_group_info_ctr("ctr", q_e->ctr, ps, depth); + DEBUG(5,("init_sam_info_2\n")); - return True; -} + if (num_sam_entries >= MAX_SAM_ENTRIES) { + num_sam_entries = MAX_SAM_ENTRIES; + DEBUG(5,("limiting number of entries to %d\n", + num_sam_entries)); + } + for (i = start_idx, entries_added = 0; i < num_sam_entries; i++) { + if (IS_BITS_SET_ALL(pass[i].acb_info, acb_mask)) { + init_sam_entry2(&sam->sam[entries_added], + start_idx + entries_added + 1, + pass[i].uni_user_name.uni_str_len, + pass[i].uni_acct_desc.uni_str_len, + pass[i].user_rid, + pass[i].acb_info); -/******************************************************************* -makes a SAMR_R_SET_GROUPINFO structure. -********************************************************************/ -BOOL make_samr_r_set_groupinfo(SAMR_R_SET_GROUPINFO *r_u, - uint32 status) -{ - if (r_u == NULL) return False; + copy_unistr2(&sam->str[entries_added].uni_srv_name, &pass[i].uni_user_name); + copy_unistr2(&sam->str[entries_added].uni_srv_desc, &pass[i].uni_acct_desc); - DEBUG(5,("make_samr_r_set_groupinfo\n")); - - r_u->status = status; + entries_added++; + } - return True; + sam->num_entries = entries_added; + sam->ptr_entries = 1; + sam->num_entries2 = entries_added; + } } - /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL samr_io_r_set_groupinfo(char *desc, SAMR_R_SET_GROUPINFO *r_u, prs_struct *ps, int depth) -{ - if (r_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_r_set_groupinfo"); - depth++; - - prs_align(ps); - - prs_uint32("status", ps, depth, &(r_u->status)); - return True; -} - -/******************************************************************* -makes a SAMR_Q_QUERY_GROUPINFO structure. -********************************************************************/ -BOOL make_samr_q_query_groupinfo(SAMR_Q_QUERY_GROUPINFO *q_e, - POLICY_HND *pol, - uint16 switch_level) +static BOOL sam_io_sam_info_2(char *desc, SAM_INFO_2 *sam, prs_struct *ps, int depth) { - if (q_e == NULL || pol == NULL) return False; - - DEBUG(5,("make_samr_q_query_groupinfo\n")); - - memcpy(&(q_e->pol), pol, sizeof(*pol)); - - q_e->switch_level = switch_level; - - return True; -} + int i; + if (sam == NULL) + return False; -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_q_query_groupinfo(char *desc, SAMR_Q_QUERY_GROUPINFO *q_e, prs_struct *ps, int depth) -{ - if (q_e == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_q_query_groupinfo"); + prs_debug(ps, depth, desc, "sam_io_sam_info_2"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); - prs_align(ps); - - prs_uint16("switch_level", ps, depth, &(q_e->switch_level)); - - return True; -} + if(!prs_uint32("num_entries ", ps, depth, &sam->num_entries)) + return False; + if(!prs_uint32("ptr_entries ", ps, depth, &sam->ptr_entries)) + return False; + if(!prs_uint32("num_entries2 ", ps, depth, &sam->num_entries2)) + return False; -/******************************************************************* -makes a SAMR_R_QUERY_GROUPINFO structure. -********************************************************************/ -BOOL make_samr_r_query_groupinfo(SAMR_R_QUERY_GROUPINFO *r_u, GROUP_INFO_CTR *ctr, - uint32 status) -{ - if (r_u == NULL) return False; + SMB_ASSERT_ARRAY(sam->sam, sam->num_entries); - DEBUG(5,("make_samr_r_query_groupinfo\n")); - - r_u->ptr = (status == 0x0 && ctr != NULL) ? 1 : 0; - r_u->ctr = ctr; - r_u->status = status; - - return True; -} - - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_r_query_groupinfo(char *desc, SAMR_R_QUERY_GROUPINFO *r_u, prs_struct *ps, int depth) -{ - if (r_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_r_query_groupinfo"); - depth++; - - prs_align(ps); - - prs_uint32("ptr", ps, depth, &(r_u->ptr)); - - if (r_u->ptr != 0) - { - samr_group_info_ctr("ctr", r_u->ctr, ps, depth); + for (i = 0; i < sam->num_entries; i++) { + if(!sam_io_sam_entry2("", &sam->sam[i], ps, depth)) + return False; } - prs_uint32("status", ps, depth, &(r_u->status)); + for (i = 0; i < sam->num_entries; i++) { + if(!sam_io_sam_str2 ("", &sam->str[i], + sam->sam[i].hdr_srv_name.buffer, + sam->sam[i].hdr_srv_desc.buffer, + ps, depth)) + return False; + } return True; } - /******************************************************************* -makes a SAMR_Q_QUERY_GROUPMEM structure. + Inits a SAM_INFO_1 structure. ********************************************************************/ -BOOL make_samr_q_query_groupmem(SAMR_Q_QUERY_GROUPMEM *q_c, POLICY_HND *hnd) -{ - if (q_c == NULL || hnd == NULL) return False; - - DEBUG(5,("make_samr_q_query_groupmem\n")); - memcpy(&(q_c->group_pol), hnd, sizeof(q_c->group_pol)); - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_q_query_groupmem(char *desc, SAMR_Q_QUERY_GROUPMEM *q_u, prs_struct *ps, int depth) +void init_sam_info_1(SAM_INFO_1 *sam, uint32 acb_mask, + uint32 start_idx, uint32 num_sam_entries, + SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES]) { - if (q_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_q_query_groupmem"); - depth++; - - prs_align(ps); + int i; + int entries_added; - smb_io_pol_hnd("group_pol", &(q_u->group_pol), ps, depth); + DEBUG(5,("init_sam_info_1\n")); - return True; -} - -/******************************************************************* -makes a SAMR_R_QUERY_GROUPMEM structure. -********************************************************************/ -BOOL make_samr_r_query_groupmem(SAMR_R_QUERY_GROUPMEM *r_u, - uint32 num_entries, uint32 *rid, uint32 *attr, uint32 status) -{ - if (r_u == NULL) return False; - - DEBUG(5,("make_samr_r_query_groupmem\n")); - - if (status == 0x0) - { - r_u->ptr = 1; - r_u->num_entries = num_entries; - - r_u->ptr_attrs = attr != NULL ? 1 : 0; - r_u->ptr_rids = rid != NULL ? 1 : 0; - - r_u->num_rids = num_entries; - r_u->rid = rid; - - r_u->num_attrs = num_entries; - r_u->attr = attr; - } - else - { - r_u->ptr = 0; - r_u->num_entries = 0; + if (num_sam_entries >= MAX_SAM_ENTRIES) { + num_sam_entries = MAX_SAM_ENTRIES; + DEBUG(5,("limiting number of entries to %d\n", + num_sam_entries)); } - r_u->status = status; - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_r_query_groupmem(char *desc, SAMR_R_QUERY_GROUPMEM *r_u, prs_struct *ps, int depth) -{ - uint32 i; - - if (r_u == NULL) return False; + for (i = start_idx, entries_added = 0; i < num_sam_entries; i++) { + if (IS_BITS_SET_ALL(pass[i].acb_info, acb_mask)) { + init_sam_entry1(&sam->sam[entries_added], + start_idx + entries_added + 1, + pass[i].uni_user_name.uni_str_len, + pass[i].uni_full_name.uni_str_len, + pass[i].uni_acct_desc.uni_str_len, + pass[i].user_rid, + pass[i].acb_info); - prs_debug(ps, depth, desc, "samr_io_r_query_groupmem"); - depth++; - - prs_align(ps); - - prs_uint32("ptr", ps, depth, &(r_u->ptr)); - prs_uint32("num_entries ", ps, depth, &(r_u->num_entries)); - - if (r_u->ptr != 0) - { - prs_uint32("ptr_rids ", ps, depth, &(r_u->ptr_rids )); - prs_uint32("ptr_attrs", ps, depth, &(r_u->ptr_attrs)); + copy_unistr2(&sam->str[entries_added].uni_acct_name, &pass[i].uni_user_name); + copy_unistr2(&sam->str[entries_added].uni_full_name, &pass[i].uni_full_name); + copy_unistr2(&sam->str[entries_added].uni_acct_desc, &pass[i].uni_acct_desc); - if (r_u->ptr_rids != 0) - { - prs_uint32("num_rids", ps, depth, &(r_u->num_rids)); - if (r_u->num_rids != 0) - { - r_u->rid = (uint32*)Realloc(r_u->rid, - sizeof(r_u->rid[0]) * - r_u->num_rids); - if (r_u->rid == NULL) - { - samr_free_r_query_groupmem(r_u); - return False; - } - } - for (i = 0; i < r_u->num_rids; i++) - { - prs_uint32("", ps, depth, &(r_u->rid[i])); - } - } - - if (r_u->ptr_attrs != 0) - { - prs_uint32("num_attrs", ps, depth, &(r_u->num_attrs)); - - if (r_u->num_attrs != 0) - { - r_u->attr = (uint32*)Realloc(r_u->attr, - sizeof(r_u->attr[0]) * - r_u->num_attrs); - if (r_u->attr == NULL) - { - samr_free_r_query_groupmem(r_u); - return False; - } - } - for (i = 0; i < r_u->num_attrs; i++) - { - prs_uint32("", ps, depth, &(r_u->attr[i])); - } + entries_added++; } } - prs_uint32("status", ps, depth, &(r_u->status)); - - if (!ps->io) - { - /* storing. memory no longer needed */ - samr_free_r_query_groupmem(r_u); - } - - return True; + sam->num_entries = entries_added; + sam->ptr_entries = 1; + sam->num_entries2 = entries_added; } - /******************************************************************* -frees a structure. + Reads or writes a structure. ********************************************************************/ -void samr_free_r_query_groupmem(SAMR_R_QUERY_GROUPMEM *r_u) -{ - if (r_u->rid != NULL) - { - free(r_u->rid); - r_u->rid = NULL; - } - if (r_u->attr != NULL) - { - free(r_u->attr); - r_u->attr = NULL; - } -} -/******************************************************************* -makes a SAMR_Q_QUERY_USERGROUPS structure. -********************************************************************/ -BOOL make_samr_q_query_usergroups(SAMR_Q_QUERY_USERGROUPS *q_u, - POLICY_HND *hnd) +static BOOL sam_io_sam_info_1(char *desc, SAM_INFO_1 *sam, prs_struct *ps, int depth) { - if (q_u == NULL || hnd == NULL) return False; - - DEBUG(5,("make_samr_q_query_usergroups\n")); - - memcpy(&(q_u->pol), hnd, sizeof(q_u->pol)); + int i; - return True; -} - - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_q_query_usergroups(char *desc, SAMR_Q_QUERY_USERGROUPS *q_u, prs_struct *ps, int depth) -{ - if (q_u == NULL) return False; + if (sam == NULL) + return False; - prs_debug(ps, depth, desc, "samr_io_q_query_usergroups"); + prs_debug(ps, depth, desc, "sam_io_sam_info_1"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_pol_hnd("pol", &(q_u->pol), ps, depth); - prs_align(ps); + if(!prs_uint32("num_entries ", ps, depth, &sam->num_entries)) + return False; + if(!prs_uint32("ptr_entries ", ps, depth, &sam->ptr_entries)) + return False; - return True; -} + if(!prs_uint32("num_entries2 ", ps, depth, &sam->num_entries2)) + return False; -/******************************************************************* -makes a SAMR_R_QUERY_USERGROUPS structure. -********************************************************************/ -BOOL make_samr_r_query_usergroups(SAMR_R_QUERY_USERGROUPS *r_u, - uint32 num_gids, DOM_GID *gid, uint32 status) -{ - if (r_u == NULL) return False; - - DEBUG(5,("make_samr_r_query_usergroups\n")); + SMB_ASSERT_ARRAY(sam->sam, sam->num_entries); - if (status == 0x0) - { - r_u->ptr_0 = 1; - r_u->num_entries = num_gids; - r_u->ptr_1 = (num_gids != 0) ? 1 : 0; - r_u->num_entries2 = num_gids; - - r_u->gid = gid; - } - else - { - r_u->ptr_0 = 0; - r_u->num_entries = 0; - r_u->ptr_1 = 0; + for (i = 0; i < sam->num_entries; i++) { + if(!sam_io_sam_entry1("", &sam->sam[i], ps, depth)) + return False; } - r_u->status = status; - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_r_query_usergroups(char *desc, SAMR_R_QUERY_USERGROUPS *r_u, prs_struct *ps, int depth) -{ - uint32 i; - if (r_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_r_query_usergroups"); - depth++; - - prs_align(ps); - - prs_uint32("ptr_0 ", ps, depth, &(r_u->ptr_0 )); - - if (r_u->ptr_0 != 0) - { - prs_uint32("num_entries ", ps, depth, &(r_u->num_entries)); - prs_uint32("ptr_1 ", ps, depth, &(r_u->ptr_1 )); - - if (r_u->num_entries != 0) - { - prs_uint32("num_entries2", ps, depth, &(r_u->num_entries2)); - - r_u->gid = (DOM_GID*)malloc(r_u->num_entries2 * sizeof(r_u->gid[0])); - if (r_u->gid == NULL) - { - return False; - } - - for (i = 0; i < r_u->num_entries2; i++) - { - smb_io_gid("", &(r_u->gid[i]), ps, depth); - } - } + for (i = 0; i < sam->num_entries; i++) { + if(!sam_io_sam_str1 ("", &sam->str[i], + sam->sam[i].hdr_acct_name.buffer, + sam->sam[i].hdr_user_name.buffer, + sam->sam[i].hdr_user_desc.buffer, + ps, depth)) + return False; } - prs_uint32("status", ps, depth, &(r_u->status)); - - return True; -} - - -/******************************************************************* -makes a SAMR_Q_ENUM_DOMAINS structure. -********************************************************************/ -BOOL make_samr_q_enum_domains(SAMR_Q_ENUM_DOMAINS *q_e, POLICY_HND *pol, - uint32 start_idx, uint32 size) -{ - if (q_e == NULL || pol == NULL) return False; - - DEBUG(5,("make_samr_q_enum_domains\n")); - - memcpy(&(q_e->pol), pol, sizeof(*pol)); - - q_e->start_idx = start_idx; - q_e->max_size = size; return True; } - /******************************************************************* -reads or writes a structure. + Inits a SAMR_R_QUERY_DISPINFO structure. ********************************************************************/ -BOOL samr_io_q_enum_domains(char *desc, SAMR_Q_ENUM_DOMAINS *q_e, prs_struct *ps, int depth) -{ - if (q_e == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_q_enum_domains"); - depth++; - - prs_align(ps); - smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); - prs_align(ps); - - prs_uint32("start_idx", ps, depth, &(q_e->start_idx)); - prs_uint32("max_size ", ps, depth, &(q_e->max_size )); - - prs_align(ps); - - return True; -} - - -/******************************************************************* -makes a SAMR_R_ENUM_DOMAINS structure. -********************************************************************/ -BOOL make_samr_r_enum_domains(SAMR_R_ENUM_DOMAINS *r_u, - uint32 next_idx, - uint32 num_sam_entries, char **doms, uint32 status) +void init_samr_r_query_dispinfo(SAMR_R_QUERY_DISPINFO *r_u, + uint16 switch_level, SAM_INFO_CTR *ctr, uint32 status) { - uint32 i; - - if (r_u == NULL) return False; - - DEBUG(5,("make_samr_r_enum_domains\n")); - - r_u->next_idx = next_idx; - r_u->sam = NULL; - r_u->uni_dom_name = NULL; - - if (num_sam_entries != 0) - { - r_u->ptr_entries1 = 1; - r_u->ptr_entries2 = 1; - r_u->num_entries2 = num_sam_entries; - r_u->num_entries3 = num_sam_entries; - - r_u->sam = (SAM_ENTRY*)Realloc(NULL, r_u->num_entries2 * sizeof(r_u->sam[0])); - r_u->uni_dom_name = (UNISTR2*)Realloc(NULL, r_u->num_entries2 * sizeof(r_u->uni_dom_name[0])); + DEBUG(5,("init_samr_r_query_dispinfo\n")); - if (r_u->sam == NULL || r_u->uni_dom_name == NULL) - { - DEBUG(0,("NULL pointers in SAMR_R_ENUM_DOMAINS\n")); - return False; - } - - for (i = 0; i < num_sam_entries; i++) - { - int acct_name_len = doms[i] != NULL ? strlen(doms[i]) : 0; - - make_sam_entry(&(r_u->sam[i]), acct_name_len, 0); - make_unistr2(&(r_u->uni_dom_name[i]), doms[i], acct_name_len); - } - - r_u->num_entries4 = num_sam_entries; - } - else - { - r_u->ptr_entries1 = 0; - r_u->num_entries2 = num_sam_entries; - r_u->ptr_entries2 = 1; + if (status == 0x0) { + r_u->unknown_0 = 0x0000001; + r_u->unknown_1 = 0x0000001; + } else { + r_u->unknown_0 = 0x0; + r_u->unknown_1 = 0x0; } + r_u->switch_level = switch_level; + r_u->ctr = ctr; r_u->status = status; - - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL samr_io_r_enum_domains(char *desc, SAMR_R_ENUM_DOMAINS *r_u, prs_struct *ps, int depth) -{ - uint32 i; - if (r_u == NULL) return False; +BOOL samr_io_r_query_dispinfo(char *desc, SAMR_R_QUERY_DISPINFO *r_u, prs_struct *ps, int depth) +{ + if (r_u == NULL) + return False; - prs_debug(ps, depth, desc, "samr_io_r_enum_domains"); + prs_debug(ps, depth, desc, "samr_io_r_query_dispinfo"); depth++; - prs_align(ps); - - prs_uint32("next_idx ", ps, depth, &(r_u->next_idx )); - prs_uint32("ptr_entries1", ps, depth, &(r_u->ptr_entries1)); + if(!prs_align(ps)) + return False; - if (r_u->ptr_entries1 != 0) - { - prs_uint32("num_entries2", ps, depth, &(r_u->num_entries2)); - prs_uint32("ptr_entries2", ps, depth, &(r_u->ptr_entries2)); - prs_uint32("num_entries3", ps, depth, &(r_u->num_entries3)); + if(!prs_uint32("unknown_0 ", ps, depth, &r_u->unknown_0)) + return False; + if(!prs_uint32("unknown_1 ", ps, depth, &r_u->unknown_1)) + return False; + if(!prs_uint16("switch_level ", ps, depth, &r_u->switch_level)) + return False; - if (ps->io) - { - r_u->sam = (SAM_ENTRY*)Realloc(NULL, r_u->num_entries2 * sizeof(r_u->sam[0])); - r_u->uni_dom_name = (UNISTR2*)Realloc(NULL, r_u->num_entries2 * sizeof(r_u->uni_dom_name[0])); - } + if(!prs_align(ps)) + return False; - if ((r_u->sam == NULL || r_u->uni_dom_name == NULL) && r_u->num_entries2 != 0) - { - DEBUG(0,("NULL pointers in SAMR_R_ENUM_DOMAINS\n")); - r_u->num_entries4 = 0; - r_u->status = 0xC0000000|NT_STATUS_MEMORY_NOT_ALLOCATED; + switch (r_u->switch_level) { + case 0x1: + if(!sam_io_sam_info_1("users", r_u->ctr->sam.info1, ps, depth)) return False; - } - - for (i = 0; i < r_u->num_entries2; i++) - { - fstring tmp; - slprintf(tmp, sizeof(tmp)-1, "dom[%d]", i); - sam_io_sam_entry(tmp, &(r_u->sam[i]), ps, depth); - } - - for (i = 0; i < r_u->num_entries2; i++) - { - fstring tmp; - slprintf(tmp, sizeof(tmp)-1, "dom[%d]", i); - smb_io_unistr2(tmp, &(r_u->uni_dom_name[i]), r_u->sam[i].hdr_name.buffer, ps, depth); - prs_align(ps); - } - - prs_align(ps); - + break; + case 0x2: + if(!sam_io_sam_info_2("servers", r_u->ctr->sam.info2, ps, depth)) + return False; + break; + default: + DEBUG(5,("samr_io_r_query_dispinfo: unknown switch value\n")); + break; } - prs_uint32("num_entries4", ps, depth, &(r_u->num_entries4)); - prs_uint32("status", ps, depth, &(r_u->status)); + if(!prs_uint32("status", ps, depth, &r_u->status)) + return False; return True; } /******************************************************************* -makes a SAMR_Q_ENUM_DOM_GROUPS structure. + Inits a SAMR_Q_ENUM_DOM_GROUPS structure. ********************************************************************/ -BOOL make_samr_q_enum_dom_groups(SAMR_Q_ENUM_DOM_GROUPS *q_e, POLICY_HND *pol, - uint32 start_idx, uint32 size) + +void init_samr_q_enum_dom_groups(SAMR_Q_ENUM_DOM_GROUPS *q_e, POLICY_HND *pol, + uint16 switch_level, uint32 start_idx, uint32 size) { - if (q_e == NULL || pol == NULL) return False; + DEBUG(5,("init_q_enum_dom_groups\n")); - DEBUG(5,("make_samr_q_enum_dom_groups\n")); + memcpy(&q_e->pol, pol, sizeof(*pol)); - memcpy(&(q_e->pol), pol, sizeof(*pol)); + q_e->switch_level = switch_level; + q_e->unknown_0 = 0; q_e->start_idx = start_idx; - q_e->max_size = size; - - return True; + q_e->unknown_1 = 0x000007d0; + q_e->max_size = size; } - /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL samr_io_q_enum_dom_groups(char *desc, SAMR_Q_ENUM_DOM_GROUPS *q_e, prs_struct *ps, int depth) + +BOOL samr_io_q_enum_dom_groups(char *desc, SAMR_Q_ENUM_DOM_GROUPS *q_e, prs_struct *ps, int depth) { - if (q_e == NULL) return False; + if (q_e == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_q_enum_dom_groups"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); - prs_align(ps); + if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth)) + return False; + if(!prs_align(ps)) + return False; - prs_uint32("start_idx", ps, depth, &(q_e->start_idx)); - prs_uint32("max_size ", ps, depth, &(q_e->max_size )); + if(!prs_uint16("switch_level", ps, depth, &q_e->switch_level)) + return False; + if(!prs_uint16("unknown_0 ", ps, depth, &q_e->unknown_0)) + return False; + if(!prs_uint32("start_idx ", ps, depth, &q_e->start_idx)) + return False; + if(!prs_uint32("unknown_1 ", ps, depth, &q_e->unknown_1)) + return False; + if(!prs_uint32("max_size ", ps, depth, &q_e->max_size)) + return False; - prs_align(ps); + if(!prs_align(ps)) + return False; return True; } /******************************************************************* -makes a SAMR_R_ENUM_DOM_GROUPS structure. + Inits a SAMR_R_ENUM_DOM_GROUPS structure. ********************************************************************/ -BOOL make_samr_r_enum_dom_groups(SAMR_R_ENUM_DOM_GROUPS *r_u, - uint32 next_idx, - uint32 num_sam_entries, DOMAIN_GRP *grps, uint32 status) + +void init_samr_r_enum_dom_groups(SAMR_R_ENUM_DOM_GROUPS *r_u, + uint32 start_idx, uint32 num_sam_entries, + SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES], + uint32 status) { - uint32 i; + int i; + int entries_added; - if (r_u == NULL) return False; + DEBUG(5,("init_samr_r_enum_dom_groups\n")); - DEBUG(5,("make_samr_r_enum_dom_groups\n")); + if (num_sam_entries >= MAX_SAM_ENTRIES) { + num_sam_entries = MAX_SAM_ENTRIES; + DEBUG(5,("limiting number of entries to %d\n", + num_sam_entries)); + } - r_u->next_idx = next_idx; - r_u->sam = NULL; - r_u->uni_grp_name = NULL; + if (status == 0x0) { + for (i = start_idx, entries_added = 0; i < num_sam_entries; i++) { + init_sam_entry3(&r_u->sam[entries_added], + start_idx + entries_added + 1, + pass[i].uni_user_name.uni_str_len, + pass[i].uni_acct_desc.uni_str_len, + pass[i].user_rid); - if (num_sam_entries != 0) - { - r_u->ptr_entries1 = 1; - r_u->ptr_entries2 = 1; - r_u->num_entries2 = num_sam_entries; - r_u->num_entries3 = num_sam_entries; + copy_unistr2(&r_u->str[entries_added].uni_grp_name, + &pass[i].uni_user_name); + copy_unistr2(&r_u->str[entries_added].uni_grp_desc, + &pass[i].uni_acct_desc); - r_u->sam = (SAM_ENTRY*)Realloc(NULL, r_u->num_entries2 * sizeof(r_u->sam[0])); - r_u->uni_grp_name = (UNISTR2*)Realloc(NULL, r_u->num_entries2 * sizeof(r_u->uni_grp_name[0])); - - if (r_u->sam == NULL || r_u->uni_grp_name == NULL) - { - DEBUG(0,("NULL pointers in SAMR_R_ENUM_DOM_GROUPS\n")); - return False; + entries_added++; } - for (i = 0; i < num_sam_entries; i++) - { - int acct_name_len = strlen(grps[i].name); - - make_sam_entry(&(r_u->sam[i]), - acct_name_len, - grps[i].rid); - - make_unistr2(&(r_u->uni_grp_name[i]), grps[i].name, acct_name_len); + if (entries_added > 0) { + r_u->unknown_0 = 0x0000492; + r_u->unknown_1 = 0x000049a; + } else { + r_u->unknown_0 = 0x0; + r_u->unknown_1 = 0x0; } - - r_u->num_entries4 = num_sam_entries; - } - else - { - r_u->ptr_entries1 = 0; - r_u->num_entries2 = num_sam_entries; - r_u->ptr_entries2 = 1; + r_u->switch_level = 3; + r_u->num_entries = entries_added; + r_u->ptr_entries = 1; + r_u->num_entries2 = entries_added; + } else { + r_u->switch_level = 0; } r_u->status = status; - - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL samr_io_r_enum_dom_groups(char *desc, SAMR_R_ENUM_DOM_GROUPS *r_u, prs_struct *ps, int depth) + +BOOL samr_io_r_enum_dom_groups(char *desc, SAMR_R_ENUM_DOM_GROUPS *r_u, prs_struct *ps, int depth) { - uint32 i; + int i; - if (r_u == NULL) return False; + if (r_u == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_r_enum_dom_groups"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("next_idx ", ps, depth, &(r_u->next_idx )); - prs_uint32("ptr_entries1", ps, depth, &(r_u->ptr_entries1)); + if(!prs_uint32("unknown_0 ", ps, depth, &r_u->unknown_0)) + return False; + if(!prs_uint32("unknown_1 ", ps, depth, &r_u->unknown_1)) + return False; + if(!prs_uint32("switch_level ", ps, depth, &r_u->switch_level)) + return False; - if (r_u->ptr_entries1 != 0) - { - prs_uint32("num_entries2", ps, depth, &(r_u->num_entries2)); - prs_uint32("ptr_entries2", ps, depth, &(r_u->ptr_entries2)); - prs_uint32("num_entries3", ps, depth, &(r_u->num_entries3)); - - if (ps->io) - { - r_u->sam = (SAM_ENTRY*)Realloc(NULL, r_u->num_entries2 * sizeof(r_u->sam[0])); - r_u->uni_grp_name = (UNISTR2*)Realloc(NULL, r_u->num_entries2 * sizeof(r_u->uni_grp_name[0])); - } - - if ((r_u->sam == NULL || r_u->uni_grp_name == NULL) && r_u->num_entries2 != 0) - { - DEBUG(0,("NULL pointers in SAMR_R_ENUM_DOM_GROUPS\n")); - r_u->num_entries4 = 0; - r_u->status = 0xC0000000|NT_STATUS_MEMORY_NOT_ALLOCATED; + if (r_u->switch_level != 0) { + if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries)) return False; - } - - for (i = 0; i < r_u->num_entries2; i++) - { - sam_io_sam_entry("", &(r_u->sam[i]), ps, depth); - } - - for (i = 0; i < r_u->num_entries2; i++) - { - smb_io_unistr2("", &(r_u->uni_grp_name[i]), r_u->sam[i].hdr_name.buffer, ps, depth); - prs_align(ps); - } - - prs_align(ps); - - } - - prs_uint32("num_entries4", ps, depth, &(r_u->num_entries4)); - prs_uint32("status", ps, depth, &(r_u->status)); - - return True; -} - -/******************************************************************* -makes a SAMR_Q_ENUM_DOM_ALIASES structure. -********************************************************************/ -BOOL make_samr_q_enum_dom_aliases(SAMR_Q_ENUM_DOM_ALIASES *q_e, POLICY_HND *pol, - uint32 start_idx, uint32 size) -{ - if (q_e == NULL || pol == NULL) return False; - - DEBUG(5,("make_samr_q_enum_dom_aliases\n")); - - memcpy(&(q_e->pol), pol, sizeof(*pol)); - - q_e->start_idx = start_idx; - q_e->max_size = size; - - return True; -} - - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_q_enum_dom_aliases(char *desc, SAMR_Q_ENUM_DOM_ALIASES *q_e, prs_struct *ps, int depth) -{ - if (q_e == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_q_enum_dom_aliases"); - depth++; - - prs_align(ps); - - smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); - prs_align(ps); - - prs_uint32("start_idx", ps, depth, &(q_e->start_idx)); - prs_uint32("max_size ", ps, depth, &(q_e->max_size )); - - prs_align(ps); - - return True; -} - - -/******************************************************************* -makes a SAMR_R_ENUM_DOM_ALIASES structure. -********************************************************************/ -BOOL make_samr_r_enum_dom_aliases(SAMR_R_ENUM_DOM_ALIASES *r_u, - uint32 next_idx, - uint32 num_sam_entries, LOCAL_GRP *alss, uint32 status) -{ - uint32 i; - - if (r_u == NULL) return False; - - DEBUG(5,("make_samr_r_enum_dom_aliases\n")); - - r_u->next_idx = next_idx; - r_u->sam = NULL; - r_u->uni_grp_name = NULL; - - if (num_sam_entries != 0) - { - r_u->ptr_entries1 = 1; - r_u->ptr_entries2 = 1; - r_u->num_entries2 = num_sam_entries; - r_u->num_entries3 = num_sam_entries; - - r_u->sam = (SAM_ENTRY*)Realloc(NULL, r_u->num_entries2 * sizeof(r_u->sam[0])); - r_u->uni_grp_name = (UNISTR2*)Realloc(NULL, r_u->num_entries2 * sizeof(r_u->uni_grp_name[0])); - - if (r_u->sam == NULL || r_u->uni_grp_name == NULL) - { - DEBUG(0,("NULL pointers in SAMR_R_ENUM_DOM_ALIASES\n")); + if(!prs_uint32("ptr_entries ", ps, depth, &r_u->ptr_entries)) return False; - } - - for (i = 0; i < num_sam_entries; i++) - { - int acct_name_len = strlen(alss[i].name); - - make_sam_entry(&(r_u->sam[i]), - acct_name_len, - alss[i].rid); - - make_unistr2(&(r_u->uni_grp_name[i]), alss[i].name, acct_name_len); - } - - r_u->num_entries4 = num_sam_entries; - } - else - { - r_u->ptr_entries1 = 0; - r_u->num_entries2 = num_sam_entries; - r_u->ptr_entries2 = 1; - } - - r_u->status = status; - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_r_enum_dom_aliases(char *desc, SAMR_R_ENUM_DOM_ALIASES *r_u, prs_struct *ps, int depth) -{ - uint32 i; - - if (r_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_r_enum_dom_aliases"); - depth++; - - prs_align(ps); - - prs_uint32("next_idx ", ps, depth, &(r_u->next_idx )); - prs_uint32("ptr_entries1", ps, depth, &(r_u->ptr_entries1)); - - if (r_u->ptr_entries1 != 0) - { - prs_uint32("num_entries2", ps, depth, &(r_u->num_entries2)); - prs_uint32("ptr_entries2", ps, depth, &(r_u->ptr_entries2)); - prs_uint32("num_entries3", ps, depth, &(r_u->num_entries3)); - - if (ps->io) - { - r_u->sam = (SAM_ENTRY*)Realloc(NULL, r_u->num_entries2 * sizeof(r_u->sam[0])); - r_u->uni_grp_name = (UNISTR2*)Realloc(NULL, r_u->num_entries2 * sizeof(r_u->uni_grp_name[0])); - } - - if ((r_u->sam == NULL || r_u->uni_grp_name == NULL) && r_u->num_entries2 != 0) - { - DEBUG(0,("NULL pointers in SAMR_R_ENUM_DOM_ALIASES\n")); - r_u->num_entries4 = 0; - r_u->status = 0xC0000000|NT_STATUS_MEMORY_NOT_ALLOCATED; + if(!prs_uint32("num_entries2 ", ps, depth, &r_u->num_entries2)) return False; - } - for (i = 0; i < r_u->num_entries2; i++) - { - sam_io_sam_entry("", &(r_u->sam[i]), ps, depth); - } + SMB_ASSERT_ARRAY(r_u->sam, r_u->num_entries); - for (i = 0; i < r_u->num_entries2; i++) - { - smb_io_unistr2("", &(r_u->uni_grp_name[i]), r_u->sam[i].hdr_name.buffer, ps, depth); - prs_align(ps); + for (i = 0; i < r_u->num_entries; i++) { + if(!sam_io_sam_entry3("", &r_u->sam[i], ps, depth)) + return False; } - prs_align(ps); - - } - - prs_uint32("num_entries4", ps, depth, &(r_u->num_entries4)); - prs_uint32("status", ps, depth, &(r_u->status)); - - return True; -} - - -/******************************************************************* -makes a ALIAS_INFO3 structure. -********************************************************************/ -BOOL make_samr_alias_info3(ALIAS_INFO3 *al3, const char *acct_desc) -{ - int acct_len = acct_desc != NULL ? strlen(acct_desc) : 0; - if (al3 == NULL) return False; - - DEBUG(5,("make_samr_alias_info3\n")); - - make_uni_hdr(&(al3->hdr_acct_desc), acct_len); - make_unistr2(&(al3->uni_acct_desc), acct_desc, acct_len); - - return True; -} - - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_alias_info3(char *desc, ALIAS_INFO3 *al3, prs_struct *ps, int depth) -{ - if (al3 == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_alias_info3"); - depth++; - - prs_align(ps); - - smb_io_unihdr ("hdr_acct_desc", &(al3->hdr_acct_desc) , ps, depth); - smb_io_unistr2("uni_acct_desc", &(al3->uni_acct_desc), al3->hdr_acct_desc.buffer, ps, depth); - prs_align(ps); - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_alias_info_ctr(char *desc, ALIAS_INFO_CTR *ctr, prs_struct *ps, int depth) -{ - if (ctr == NULL) return False; - - prs_debug(ps, depth, desc, "samr_alias_info_ctr"); - depth++; - - prs_uint16("switch_value1", ps, depth, &(ctr->switch_value1)); - prs_uint16("switch_value2", ps, depth, &(ctr->switch_value2)); - - switch (ctr->switch_value1) - { - case 3: - { - samr_io_alias_info3("alias_info3", &(ctr->alias.info3), ps, depth); - break; - } - default: - { - DEBUG(4,("samr_alias_info_ctr: unsupported switch level\n")); - break; + for (i = 0; i < r_u->num_entries; i++) { + if(!sam_io_sam_str3 ("", &r_u->str[i], + r_u->sam[i].hdr_grp_name.buffer, + r_u->sam[i].hdr_grp_desc.buffer, + ps, depth)) + return False; } } - prs_align(ps); + if(!prs_uint32("status", ps, depth, &r_u->status)) + return False; return True; } - /******************************************************************* -makes a SAMR_Q_QUERY_ALIASINFO structure. + Inits a SAMR_Q_QUERY_ALIASINFO structure. ********************************************************************/ -BOOL make_samr_q_query_aliasinfo(SAMR_Q_QUERY_ALIASINFO *q_e, + +void init_samr_q_query_aliasinfo(SAMR_Q_QUERY_ALIASINFO *q_e, POLICY_HND *pol, uint16 switch_level) { - if (q_e == NULL || pol == NULL) return False; - - DEBUG(5,("make_samr_q_query_aliasinfo\n")); + DEBUG(5,("init_q_query_aliasinfo\n")); - memcpy(&(q_e->pol), pol, sizeof(*pol)); + memcpy(&q_e->pol, pol, sizeof(*pol)); q_e->switch_level = switch_level; - - return True; } - /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ + BOOL samr_io_q_query_aliasinfo(char *desc, SAMR_Q_QUERY_ALIASINFO *q_e, prs_struct *ps, int depth) { - if (q_e == NULL) return False; + if (q_e == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_q_query_aliasinfo"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); - prs_align(ps); + if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth)) + return False; + if(!prs_align(ps)) + return False; - prs_uint16("switch_level", ps, depth, &(q_e->switch_level)); + if(!prs_uint16("switch_level", ps, depth, &q_e->switch_level)) + return False; return True; } - /******************************************************************* -makes a SAMR_R_QUERY_ALIASINFO structure. + Inits a SAMR_R_QUERY_ALIASINFO structure. ********************************************************************/ -BOOL make_samr_r_query_aliasinfo(SAMR_R_QUERY_ALIASINFO *r_u, ALIAS_INFO_CTR *ctr, + +void init_samr_r_query_aliasinfo(SAMR_R_QUERY_ALIASINFO *r_u, + uint16 switch_value, char *acct_desc, uint32 status) { - if (r_u == NULL) return False; - - DEBUG(5,("make_samr_r_query_aliasinfo\n")); - - r_u->ptr = (status == 0x0 && ctr != NULL) ? 1 : 0; - r_u->ctr = ctr; - r_u->status = status; + DEBUG(5,("init_samr_r_query_aliasinfo\n")); - return True; -} + r_u->ptr = 0; + if (status == 0) { + r_u->switch_value = switch_value; -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_r_query_aliasinfo(char *desc, SAMR_R_QUERY_ALIASINFO *r_u, prs_struct *ps, int depth) -{ - if (r_u == NULL) return False; + switch (switch_value) { + case 3: + { + int acct_len = acct_desc ? strlen(acct_desc) : 0; - prs_debug(ps, depth, desc, "samr_io_r_query_aliasinfo"); - depth++; + r_u->ptr = 1; - prs_align(ps); + init_uni_hdr(&r_u->alias.info3.hdr_acct_desc, acct_len); + init_unistr2(&r_u->alias.info3.uni_acct_desc, acct_desc, acct_len); - prs_uint32("ptr", ps, depth, &(r_u->ptr)); - - if (r_u->ptr != 0) - { - samr_alias_info_ctr("ctr", r_u->ctr, ps, depth); + break; + } + default: + DEBUG(4,("init_samr_r_query_aliasinfo: unsupported switch level\n")); + break; + } } - prs_uint32("status", ps, depth, &(r_u->status)); - - return True; + r_u->status = status; } - /******************************************************************* -makes a SAMR_Q_SET_ALIASINFO structure. + Reads or writes a structure. ********************************************************************/ -BOOL make_samr_q_set_aliasinfo(SAMR_Q_SET_ALIASINFO *q_u, POLICY_HND *hnd, - ALIAS_INFO_CTR *ctr) -{ - if (q_u == NULL) return False; - - DEBUG(5,("make_samr_q_set_aliasinfo\n")); - - memcpy(&(q_u->alias_pol), hnd, sizeof(q_u->alias_pol)); - q_u->ctr = ctr; - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_q_set_aliasinfo(char *desc, SAMR_Q_SET_ALIASINFO *q_u, prs_struct *ps, int depth) +BOOL samr_io_r_query_aliasinfo(char *desc, SAMR_R_QUERY_ALIASINFO *r_u, prs_struct *ps, int depth) { - if (q_u == NULL) return False; + if (r_u == NULL) + return False; - prs_debug(ps, depth, desc, "samr_io_q_set_aliasinfo"); + prs_debug(ps, depth, desc, "samr_io_r_query_aliasinfo"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_pol_hnd("alias_pol", &(q_u->alias_pol), ps, depth); - samr_alias_info_ctr("ctr", q_u->ctr, ps, depth); - - return True; -} + if(!prs_uint32("ptr ", ps, depth, &r_u->ptr)) + return False; + + if (r_u->ptr != 0) { + if(!prs_uint16("switch_value", ps, depth, &r_u->switch_value)) + return False; + if(!prs_align(ps)) + return False; -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_r_set_aliasinfo(char *desc, SAMR_R_SET_ALIASINFO *r_u, prs_struct *ps, int depth) -{ - if (r_u == NULL) return False; + if (r_u->switch_value != 0) { + switch (r_u->switch_value) { + case 3: + if(!smb_io_unihdr ("", &r_u->alias.info3.hdr_acct_desc, ps, depth)) + return False; + if(!smb_io_unistr2("", &r_u->alias.info3.uni_acct_desc, + r_u->alias.info3.hdr_acct_desc.buffer, ps, depth)) + return False; + break; + default: + DEBUG(4,("samr_io_r_query_aliasinfo: unsupported switch level\n")); + break; + } + } + } - prs_debug(ps, depth, desc, "samr_io_r_set_aliasinfo"); - depth++; + if(!prs_align(ps)) + return False; - prs_align(ps); - prs_uint32("status", ps, depth, &(r_u->status)); + if(!prs_uint32("status", ps, depth, &r_u->status)) + return False; return True; } - - /******************************************************************* -makes a SAMR_Q_QUERY_USERALIASES structure. + Reads or writes a SAMR_Q_LOOKUP_IDS structure. ********************************************************************/ -BOOL make_samr_q_query_useraliases(SAMR_Q_QUERY_USERALIASES *q_u, - const POLICY_HND *hnd, - uint32 *ptr_sid, DOM_SID2 *sid) -{ - if (q_u == NULL || hnd == NULL) return False; - - DEBUG(5,("make_samr_q_query_useraliases\n")); - - memcpy(&(q_u->pol), hnd, sizeof(q_u->pol)); - - q_u->num_sids1 = 1; - q_u->ptr = 1; - q_u->num_sids2 = 1; - - q_u->ptr_sid = ptr_sid; - q_u->sid = sid; - - return True; -} -/******************************************************************* -reads or writes a SAMR_Q_QUERY_USERALIASES structure. -********************************************************************/ -BOOL samr_io_q_query_useraliases(char *desc, SAMR_Q_QUERY_USERALIASES *q_u, prs_struct *ps, int depth) +BOOL samr_io_q_lookup_ids(char *desc, SAMR_Q_LOOKUP_IDS *q_u, prs_struct *ps, int depth) { fstring tmp; - uint32 i; + int i; - if (q_u == NULL) return False; + if (q_u == NULL) + return False; - prs_debug(ps, depth, desc, "samr_io_q_query_useraliases"); + prs_debug(ps, depth, desc, "samr_io_q_lookup_ids"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_pol_hnd("pol", &(q_u->pol), ps, depth); - prs_align(ps); + if(!smb_io_pol_hnd("pol", &(q_u->pol), ps, depth)) + return False; + if(!prs_align(ps)) + return False; - prs_uint32("num_sids1", ps, depth, &(q_u->num_sids1)); - prs_uint32("ptr ", ps, depth, &(q_u->ptr )); - prs_uint32("num_sids2", ps, depth, &(q_u->num_sids2)); - - if (q_u->num_sids2 != 0) - { - q_u->ptr_sid = (uint32*)Realloc(q_u->ptr_sid, - sizeof(q_u->ptr_sid[0]) * q_u->num_sids2); - if (q_u->ptr_sid == NULL) - { - samr_free_q_query_useraliases(q_u); - return False; - } + if(!prs_uint32("num_sids1", ps, depth, &q_u->num_sids1)) + return False; + if(!prs_uint32("ptr ", ps, depth, &q_u->ptr)) + return False; + if(!prs_uint32("num_sids2", ps, depth, &q_u->num_sids2)) + return False; - q_u->sid = (DOM_SID2*)Realloc(q_u->sid, - sizeof(q_u->sid[0]) * q_u->num_sids2); - if (q_u->sid == NULL) - { - samr_free_q_query_useraliases(q_u); - return False; - } - } + SMB_ASSERT_ARRAY(q_u->ptr_sid, q_u->num_sids2); - for (i = 0; i < q_u->num_sids2; i++) - { + for (i = 0; i < q_u->num_sids2; i++) { slprintf(tmp, sizeof(tmp) - 1, "ptr[%02d]", i); - prs_uint32(tmp, ps, depth, &(q_u->ptr_sid[i])); + if(!prs_uint32(tmp, ps, depth, &q_u->ptr_sid[i])) + return False; } - for (i = 0; i < q_u->num_sids2; i++) - { - if (q_u->ptr_sid[i] != 0) - { + for (i = 0; i < q_u->num_sids2; i++) { + if (q_u->ptr_sid[i] != 0) { slprintf(tmp, sizeof(tmp)-1, "sid[%02d]", i); - smb_io_dom_sid2(tmp, &(q_u->sid[i]), ps, depth); + if(!smb_io_dom_sid2(tmp, &q_u->sid[i], ps, depth)) + return False; } } - prs_align(ps); + if(!prs_align(ps)) + return False; - if (!ps->io) - { - /* storing. memory no longer needed */ - samr_free_q_query_useraliases(q_u); - } return True; } /******************************************************************* -frees memory in a SAMR_Q_QUERY_USERALIASES structure. + Inits a SAMR_R_LOOKUP_IDS structure. ********************************************************************/ -void samr_free_q_query_useraliases(SAMR_Q_QUERY_USERALIASES *q_u) -{ - if (q_u->ptr_sid == NULL) - { - free(q_u->ptr_sid); - q_u->ptr_sid = NULL; - } - if (q_u->sid == NULL) - { - free(q_u->sid); - q_u->sid = NULL; - } -} - -/******************************************************************* -makes a SAMR_R_QUERY_USERALIASES structure. -********************************************************************/ -BOOL make_samr_r_query_useraliases(SAMR_R_QUERY_USERALIASES *r_u, +void init_samr_r_lookup_ids(SAMR_R_LOOKUP_IDS *r_u, uint32 num_rids, uint32 *rid, uint32 status) { - if (r_u == NULL) return False; + int i; - DEBUG(5,("make_samr_r_query_useraliases\n")); + DEBUG(5,("init_samr_r_lookup_ids\n")); - if (status == 0x0) - { + if (status == 0x0) { r_u->num_entries = num_rids; r_u->ptr = 1; r_u->num_entries2 = num_rids; - r_u->rid = rid; - } - else - { + SMB_ASSERT_ARRAY(r_u->rid, num_rids); + + for (i = 0; i < num_rids; i++) { + r_u->rid[i] = rid[i]; + } + } else { r_u->num_entries = 0; r_u->ptr = 0; r_u->num_entries2 = 0; } r_u->status = status; - - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL samr_io_r_query_useraliases(char *desc, SAMR_R_QUERY_USERALIASES *r_u, prs_struct *ps, int depth) + +BOOL samr_io_r_lookup_ids(char *desc, SAMR_R_LOOKUP_IDS *r_u, prs_struct *ps, int depth) { fstring tmp; - uint32 i; - if (r_u == NULL) return False; + int i; - prs_debug(ps, depth, desc, "samr_io_r_query_useraliases"); + if (r_u == NULL) + return False; + + prs_debug(ps, depth, desc, "samr_io_r_lookup_ids"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("num_entries", ps, depth, &(r_u->num_entries)); - prs_uint32("ptr ", ps, depth, &(r_u->ptr )); - prs_uint32("num_entries2", ps, depth, &(r_u->num_entries2)); - - if (r_u->num_entries != 0) - { - r_u->rid = (uint32*)Realloc(r_u->rid, - sizeof(r_u->rid[0]) * r_u->num_entries); - if (r_u->rid == NULL) - { - samr_free_r_query_useraliases(r_u); - return False; - } + if(!prs_uint32("num_entries", ps, depth, &r_u->num_entries)) + return False; + if(!prs_uint32("ptr ", ps, depth, &r_u->ptr)) + return False; + if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2)) + return False; + + if (r_u->num_entries != 0) { + SMB_ASSERT_ARRAY(r_u->rid, r_u->num_entries2); - for (i = 0; i < r_u->num_entries2; i++) - { + for (i = 0; i < r_u->num_entries2; i++) { slprintf(tmp, sizeof(tmp)-1, "rid[%02d]", i); - prs_uint32(tmp, ps, depth, &(r_u->rid[i])); + if(!prs_uint32(tmp, ps, depth, &r_u->rid[i])) + return False; } } - prs_uint32("status", ps, depth, &(r_u->status)); + if(!prs_uint32("status", ps, depth, &r_u->status)) + return False; - if (!ps->io) - { - /* storing. memory no longer needed */ - samr_free_r_query_useraliases(r_u); - } return True; } /******************************************************************* -frees memory in a SAMR_R_QUERY_USERALIASES structure. + Reads or writes a structure. ********************************************************************/ -void samr_free_r_query_useraliases(SAMR_R_QUERY_USERALIASES *r_u) -{ - if (r_u->rid == NULL) - { - free(r_u->rid); - r_u->rid = NULL; - } -} -/******************************************************************* -makes a SAMR_Q_OPEN_ALIAS structure. -********************************************************************/ -BOOL make_samr_q_open_alias(SAMR_Q_OPEN_ALIAS *q_u, const POLICY_HND *pol, - uint32 unknown_0, uint32 rid) -{ - if (q_u == NULL) return False; - - DEBUG(5,("make_samr_q_open_alias\n")); - - memcpy(&(q_u->dom_pol), pol, sizeof(q_u->dom_pol)); - - /* example values: 0x0000 0008 */ - q_u->unknown_0 = unknown_0; - - q_u->rid_alias = rid; - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_q_open_alias(char *desc, SAMR_Q_OPEN_ALIAS *q_u, prs_struct *ps, int depth) +BOOL samr_io_q_lookup_names(char *desc, SAMR_Q_LOOKUP_NAMES *q_u, prs_struct *ps, int depth) { - if (q_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_q_open_alias"); - depth++; - - prs_align(ps); - - smb_io_pol_hnd("dom_pol", &(q_u->dom_pol), ps, depth); + int i; - prs_uint32("unknown_0", ps, depth, &(q_u->unknown_0)); - prs_uint32("rid_alias", ps, depth, &(q_u->rid_alias)); + if (q_u == NULL) + return False; - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_r_open_alias(char *desc, SAMR_R_OPEN_ALIAS *r_u, prs_struct *ps, int depth) -{ - if (r_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_r_open_alias"); + prs_debug(ps, depth, desc, "samr_io_q_lookup_names"); depth++; prs_align(ps); - smb_io_pol_hnd("pol", &(r_u->pol), ps, depth); - prs_align(ps); - - prs_uint32("status", ps, depth, &(r_u->status)); + if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth)) + return False; + if(!prs_align(ps)) + return False; - return True; -} + if(!prs_uint32("num_names1", ps, depth, &q_u->num_names1)) + return False; + if(!prs_uint32("flags ", ps, depth, &q_u->flags)) + return False; + if(!prs_uint32("ptr ", ps, depth, &q_u->ptr)) + return False; + if(!prs_uint32("num_names2", ps, depth, &q_u->num_names2)) + return False; -/******************************************************************* -makes a SAMR_Q_LOOKUP_RIDS structure. -********************************************************************/ -BOOL make_samr_q_lookup_rids(SAMR_Q_LOOKUP_RIDS *q_u, - const POLICY_HND *pol, uint32 flags, - uint32 num_rids, uint32 *rid) -{ - if (q_u == NULL) return False; - - DEBUG(5,("make_samr_r_unknwon_12\n")); - - memcpy(&(q_u->pol), pol, sizeof(*pol)); - - q_u->num_rids1 = num_rids; - q_u->flags = flags; - q_u->ptr = 0; - q_u->num_rids2 = num_rids; - q_u->rid = rid; - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_q_lookup_rids(char *desc, SAMR_Q_LOOKUP_RIDS *q_u, prs_struct *ps, int depth) -{ - uint32 i; - fstring tmp; - - if (q_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_q_lookup_rids"); - depth++; - - prs_align(ps); - - smb_io_pol_hnd("pol", &(q_u->pol), ps, depth); - prs_align(ps); + SMB_ASSERT_ARRAY(q_u->hdr_name, q_u->num_names2); - prs_uint32("num_rids1", ps, depth, &(q_u->num_rids1)); - prs_uint32("flags ", ps, depth, &(q_u->flags )); - prs_uint32("ptr ", ps, depth, &(q_u->ptr )); - prs_uint32("num_rids2", ps, depth, &(q_u->num_rids2)); - - if (q_u->num_rids2 != 0) - { - q_u->rid = (uint32*)Realloc(q_u->rid, sizeof(q_u->rid[0]) * - q_u->num_rids2); - if (q_u->rid == NULL) - { - samr_free_q_lookup_rids(q_u); + for (i = 0; i < q_u->num_names2; i++) { + if(!smb_io_unihdr ("", &q_u->hdr_name[i], ps, depth)) return False; - } - } - - for (i = 0; i < q_u->num_rids2; i++) - { - slprintf(tmp, sizeof(tmp) - 1, "rid[%02d] ", i); - prs_uint32(tmp, ps, depth, &(q_u->rid[i])); } - - prs_align(ps); - - if (!ps->io) - { - /* storing. don't need memory any more */ - samr_free_q_lookup_rids(q_u); + for (i = 0; i < q_u->num_names2; i++) { + if(!smb_io_unistr2("", &q_u->uni_name[i], q_u->hdr_name[i].buffer, ps, depth)) + return False; } return True; } -/******************************************************************* -frees a structure. -********************************************************************/ -void samr_free_q_lookup_rids(SAMR_Q_LOOKUP_RIDS *q_u) -{ - if (q_u->rid != NULL) - { - free(q_u->rid); - q_u->rid = NULL; - } -} - /******************************************************************* -makes a SAMR_R_LOOKUP_RIDS structure. + Inits a SAMR_R_LOOKUP_NAMES structure. ********************************************************************/ -BOOL make_samr_r_lookup_rids(SAMR_R_LOOKUP_RIDS *r_u, - uint32 num_names, fstring *name, uint8 *type, - uint32 status) -{ - uint32 i; - if (r_u == NULL || name == NULL || type == NULL) return False; - DEBUG(5,("make_samr_r_lookup_rids\n")); +void init_samr_r_lookup_names(SAMR_R_LOOKUP_NAMES *r_u, + uint32 num_rids, uint32 *rid, uint8 *type, uint32 status) +{ + int i; - if (status == 0x0) - { - r_u->num_names1 = num_names; - r_u->ptr_names = 1; - r_u->num_names2 = num_names; + DEBUG(5,("init_samr_r_lookup_names\n")); - r_u->num_types1 = num_names; + if (status == 0x0) { + r_u->num_types1 = num_rids; r_u->ptr_types = 1; - r_u->num_types2 = num_names; + r_u->num_types2 = num_rids; - if (num_names != 0) - { - r_u->hdr_name = (UNIHDR*)malloc(num_names * sizeof(r_u->hdr_name[0])); - if (r_u->hdr_name == NULL) - { - samr_free_r_lookup_rids(r_u); - return False; - } - r_u->uni_name = (UNISTR2*)malloc(num_names * sizeof(r_u->uni_name[0])); - if (r_u->uni_name == NULL) - { - samr_free_r_lookup_rids(r_u); - return False; - } - r_u->type = (uint32*)malloc(r_u->num_types2 * sizeof(r_u->type[0])); - if (r_u->type == NULL) - { - samr_free_r_lookup_rids(r_u); - return False; - } - } + r_u->num_rids1 = num_rids; + r_u->ptr_rids = 1; + r_u->num_rids2 = num_rids; + + SMB_ASSERT_ARRAY(r_u->rid, num_rids); - for (i = 0; i < num_names; i++) - { - int len = name[i] != NULL ? strlen(name[i]) : 0; - DEBUG(10,("name[%d]:%s\ttype:%d\n", - i, name[i], type[i])); - make_uni_hdr(&(r_u->hdr_name[i]), len); - make_unistr2(&(r_u->uni_name[i]), name[i], len); + for (i = 0; i < num_rids; i++) { + r_u->rid [i] = rid [i]; r_u->type[i] = type[i]; } - } - else - { - r_u->num_names1 = num_names; - r_u->ptr_names = 0; - r_u->num_names2 = num_names; - - r_u->num_types1 = num_names; + } else { + r_u->num_types1 = 0; r_u->ptr_types = 0; - r_u->num_types2 = num_names; + r_u->num_types2 = 0; + + r_u->num_rids1 = 0; + r_u->ptr_rids = 0; + r_u->num_rids2 = 0; } r_u->status = status; - - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL samr_io_r_lookup_rids(char *desc, SAMR_R_LOOKUP_RIDS *r_u, prs_struct *ps, int depth) + +BOOL samr_io_r_lookup_names(char *desc, SAMR_R_LOOKUP_NAMES *r_u, prs_struct *ps, int depth) { - uint32 i; + int i; fstring tmp; - if (r_u == NULL) return False; - prs_debug(ps, depth, desc, "samr_io_r_lookup_rids"); + if (r_u == NULL) + return False; + + prs_debug(ps, depth, desc, "samr_io_r_lookup_names"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("num_names1", ps, depth, &(r_u->num_names1)); - prs_uint32("ptr_names ", ps, depth, &(r_u->ptr_names )); - prs_uint32("num_names2", ps, depth, &(r_u->num_names2)); + if(!prs_uint32("num_rids1", ps, depth, &r_u->num_rids1)) + return False; + if(!prs_uint32("ptr_rids ", ps, depth, &r_u->ptr_rids )) + return False; - if (r_u->ptr_names != 0 && r_u->num_names1 != 0) - { - r_u->hdr_name = (UNIHDR*)Realloc(r_u->hdr_name, - r_u->num_names2 * sizeof(r_u->hdr_name[0])); - if (r_u->hdr_name == NULL) - { + if (r_u->ptr_rids != 0) { + if(!prs_uint32("num_rids2", ps, depth, &r_u->num_rids2)) return False; - } - r_u->uni_name = (UNISTR2*)Realloc(r_u->uni_name, - r_u->num_names2 * sizeof(r_u->uni_name[0])); - if (r_u->uni_name == NULL) - { - free(r_u->hdr_name); + if (r_u->num_rids2 != r_u->num_rids1) { + /* RPC fault */ return False; } - for (i = 0; i < r_u->num_names2; i++) - { - slprintf(tmp, sizeof(tmp) - 1, "hdr[%02d] ", i); - smb_io_unihdr ("", &(r_u->hdr_name[i]), ps, depth); - } - for (i = 0; i < r_u->num_names2; i++) - { - slprintf(tmp, sizeof(tmp) - 1, "str[%02d] ", i); - smb_io_unistr2("", &(r_u->uni_name[i]), r_u->hdr_name[i].buffer, ps, depth); - prs_align(ps); + + for (i = 0; i < r_u->num_rids2; i++) { + slprintf(tmp, sizeof(tmp) - 1, "rid[%02d] ", i); + if(!prs_uint32(tmp, ps, depth, &r_u->rid[i])) + return False; } } - prs_align(ps); + if(!prs_uint32("num_types1", ps, depth, &r_u->num_types1)) + return False; + if(!prs_uint32("ptr_types ", ps, depth, &r_u->ptr_types)) + return False; - prs_uint32("num_types1", ps, depth, &(r_u->num_types1)); - prs_uint32("ptr_types ", ps, depth, &(r_u->ptr_types )); - prs_uint32("num_types2", ps, depth, &(r_u->num_types2)); - - if (r_u->ptr_types != 0 && r_u->num_types1 != 0) - { - r_u->type = (uint32*)Realloc(r_u->type, r_u->num_types2 * - sizeof(r_u->type[0])); - if (r_u->type == NULL) - { - if (r_u->uni_name != NULL) - { - free(r_u->uni_name); - } - if (r_u->hdr_name != NULL) - { - free(r_u->hdr_name); - } + if (r_u->ptr_types != 0) { + if(!prs_uint32("num_types2", ps, depth, &r_u->num_types2)) + return False; + + if (r_u->num_types2 != r_u->num_types1) { + /* RPC fault */ return False; } - for (i = 0; i < r_u->num_types2; i++) - { + for (i = 0; i < r_u->num_types2; i++) { slprintf(tmp, sizeof(tmp) - 1, "type[%02d] ", i); - prs_uint32(tmp, ps, depth, &(r_u->type[i])); + if(!prs_uint32(tmp, ps, depth, &r_u->type[i])) + return False; } } - prs_uint32("status", ps, depth, &(r_u->status)); - - if (!ps->io) - { - /* storing. don't need memory any more */ - samr_free_r_lookup_rids(r_u); - } - - return True; -} - -/******************************************************************* -frees a structure. -********************************************************************/ -void samr_free_r_lookup_rids(SAMR_R_LOOKUP_RIDS *r_u) -{ - if (r_u->uni_name != NULL) - { - free(r_u->uni_name); - r_u->uni_name = NULL; - } - if (r_u->hdr_name != NULL) - { - free(r_u->hdr_name); - r_u->hdr_name = NULL; - } - if (r_u->type != NULL) - { - free(r_u->type); - r_u->type = NULL; - } -} - -/******************************************************************* -makes a SAMR_Q_OPEN_ALIAS structure. -********************************************************************/ -BOOL make_samr_q_delete_alias(SAMR_Q_DELETE_DOM_ALIAS *q_u, POLICY_HND *hnd) -{ - if (q_u == NULL) return False; - - DEBUG(5,("make_samr_q_delete_alias\n")); - - memcpy(&(q_u->alias_pol), hnd, sizeof(q_u->alias_pol)); - - return True; -} - - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_q_delete_alias(char *desc, SAMR_Q_DELETE_DOM_ALIAS *q_u, prs_struct *ps, int depth) -{ - if (q_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_q_delete_alias"); - depth++; - - prs_align(ps); - - smb_io_pol_hnd("alias_pol", &(q_u->alias_pol), ps, depth); - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_r_delete_alias(char *desc, SAMR_R_DELETE_DOM_ALIAS *r_u, prs_struct *ps, int depth) -{ - if (r_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_r_delete_alias"); - depth++; - - prs_align(ps); - - smb_io_pol_hnd("pol", &(r_u->pol), ps, depth); - prs_uint32("status", ps, depth, &(r_u->status)); - - return True; -} - - -/******************************************************************* -makes a SAMR_Q_CREATE_DOM_ALIAS structure. -********************************************************************/ -BOOL make_samr_q_create_dom_alias(SAMR_Q_CREATE_DOM_ALIAS *q_u, POLICY_HND *hnd, - const char *acct_desc) -{ - int acct_len = acct_desc != NULL ? strlen(acct_desc) : 0; - if (q_u == NULL) return False; - - DEBUG(5,("make_samr_q_create_dom_alias\n")); - - memcpy(&(q_u->dom_pol), hnd, sizeof(q_u->dom_pol)); - - make_uni_hdr(&(q_u->hdr_acct_desc), acct_len); - make_unistr2(&(q_u->uni_acct_desc), acct_desc, acct_len); - - q_u->unknown_1 = 0x001f; - q_u->unknown_2 = 0x000f; - - return True; -} - - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_q_create_dom_alias(char *desc, SAMR_Q_CREATE_DOM_ALIAS *q_u, prs_struct *ps, int depth) -{ - if (q_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_q_create_dom_alias"); - depth++; - - prs_align(ps); - - smb_io_pol_hnd("dom_pol", &(q_u->dom_pol), ps, depth); - - smb_io_unihdr ("hdr_acct_desc", &(q_u->hdr_acct_desc) , ps, depth); - smb_io_unistr2("uni_acct_desc", &(q_u->uni_acct_desc), q_u->hdr_acct_desc.buffer, ps, depth); - prs_align(ps); - - prs_uint16("unknown_1", ps, depth, &(q_u->unknown_1)); - prs_uint16("unknown_2", ps, depth, &(q_u->unknown_2)); - - return True; -} - -/******************************************************************* -makes a SAMR_R_CREATE_DOM_ALIAS structure. -********************************************************************/ -BOOL make_samr_r_create_dom_alias(SAMR_R_CREATE_DOM_ALIAS *r_u, POLICY_HND *pol, - uint32 rid, uint32 status) -{ - if (r_u == NULL) return False; - - DEBUG(5,("make_samr_r_create_dom_alias\n")); - - memcpy(&(r_u->alias_pol), pol, sizeof(*pol)); - r_u->rid = rid ; - r_u->status = status; - - return True; -} - - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_r_create_dom_alias(char *desc, SAMR_R_CREATE_DOM_ALIAS *r_u, prs_struct *ps, int depth) -{ - if (r_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_r_create_dom_alias"); - depth++; - - prs_align(ps); - - smb_io_pol_hnd("alias_pol", &(r_u->alias_pol), ps, depth); - prs_uint32("rid", ps, depth, &(r_u->rid)); - - prs_uint32("status", ps, depth, &(r_u->status)); - - return True; -} - - - -/******************************************************************* -makes a SAMR_Q_ADD_ALIASMEM structure. -********************************************************************/ -BOOL make_samr_q_add_aliasmem(SAMR_Q_ADD_ALIASMEM *q_u, POLICY_HND *hnd, - DOM_SID *sid) -{ - if (q_u == NULL) return False; - - DEBUG(5,("make_samr_q_add_aliasmem\n")); - - memcpy(&(q_u->alias_pol), hnd, sizeof(q_u->alias_pol)); - make_dom_sid2(&q_u->sid, sid); - - return True; -} - - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_q_add_aliasmem(char *desc, SAMR_Q_ADD_ALIASMEM *q_u, prs_struct *ps, int depth) -{ - if (q_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_q_add_aliasmem"); - depth++; - - prs_align(ps); - - smb_io_pol_hnd ("alias_pol", &(q_u->alias_pol), ps, depth); - smb_io_dom_sid2("sid ", &(q_u->sid ), ps, depth); - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_r_add_aliasmem(char *desc, SAMR_R_ADD_ALIASMEM *r_u, prs_struct *ps, int depth) -{ - if (r_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_r_add_aliasmem"); - depth++; - - prs_align(ps); - - prs_uint32("status", ps, depth, &(r_u->status)); - - return True; -} - - -/******************************************************************* -makes a SAMR_Q_DEL_ALIASMEM structure. -********************************************************************/ -BOOL make_samr_q_del_aliasmem(SAMR_Q_DEL_ALIASMEM *q_u, POLICY_HND *hnd, - DOM_SID *sid) -{ - if (q_u == NULL) return False; - - DEBUG(5,("make_samr_q_del_aliasmem\n")); - - memcpy(&(q_u->alias_pol), hnd, sizeof(q_u->alias_pol)); - make_dom_sid2(&q_u->sid, sid); + if(!prs_uint32("status", ps, depth, &r_u->status)) + return False; return True; } - /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL samr_io_q_del_aliasmem(char *desc, SAMR_Q_DEL_ALIASMEM *q_u, prs_struct *ps, int depth) -{ - if (q_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_q_del_aliasmem"); - depth++; - - prs_align(ps); - smb_io_pol_hnd("alias_pol", &(q_u->alias_pol), ps, depth); - smb_io_dom_sid2("sid ", &(q_u->sid ), ps, depth); - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_r_del_aliasmem(char *desc, SAMR_R_DEL_ALIASMEM *r_u, prs_struct *ps, int depth) +BOOL samr_io_q_unknown_12(char *desc, SAMR_Q_UNKNOWN_12 *q_u, prs_struct *ps, int depth) { - if (r_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_r_del_aliasmem"); - depth++; - - prs_align(ps); - - prs_uint32("status", ps, depth, &(r_u->status)); - - return True; -} - -/******************************************************************* -makes a SAMR_Q_DELETE_DOM_ALIAS structure. -********************************************************************/ -BOOL make_samr_q_delete_dom_alias(SAMR_Q_DELETE_DOM_ALIAS *q_c, POLICY_HND *hnd) -{ - if (q_c == NULL || hnd == NULL) return False; - - DEBUG(5,("make_samr_q_delete_dom_alias\n")); - - memcpy(&(q_c->alias_pol), hnd, sizeof(q_c->alias_pol)); - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_q_delete_dom_alias(char *desc, SAMR_Q_DELETE_DOM_ALIAS *q_u, prs_struct *ps, int depth) -{ - if (q_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_q_delete_dom_alias"); - depth++; - - prs_align(ps); - - smb_io_pol_hnd("alias_pol", &(q_u->alias_pol), ps, depth); - - return True; -} - -/******************************************************************* -makes a SAMR_R_DELETE_DOM_ALIAS structure. -********************************************************************/ -BOOL make_samr_r_delete_dom_alias(SAMR_R_DELETE_DOM_ALIAS *r_u, - uint32 status) -{ - if (r_u == NULL) return False; - - DEBUG(5,("make_samr_r_delete_dom_alias\n")); - - r_u->status = status; - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_r_delete_dom_alias(char *desc, SAMR_R_DELETE_DOM_ALIAS *r_u, prs_struct *ps, int depth) -{ - if (r_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_r_delete_dom_alias"); - depth++; - - prs_align(ps); - - prs_uint32("status", ps, depth, &(r_u->status)); - - return True; -} - - -/******************************************************************* -makes a SAMR_Q_QUERY_ALIASMEM structure. -********************************************************************/ -BOOL make_samr_q_query_aliasmem(SAMR_Q_QUERY_ALIASMEM *q_c, - const POLICY_HND *hnd) -{ - if (q_c == NULL || hnd == NULL) return False; - - DEBUG(5,("make_samr_q_query_aliasmem\n")); - - memcpy(&(q_c->alias_pol), hnd, sizeof(q_c->alias_pol)); - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_q_query_aliasmem(char *desc, SAMR_Q_QUERY_ALIASMEM *q_u, prs_struct *ps, int depth) -{ - if (q_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_q_query_aliasmem"); - depth++; - - prs_align(ps); - - smb_io_pol_hnd("alias_pol", &(q_u->alias_pol), ps, depth); - - return True; -} - -/******************************************************************* -makes a SAMR_R_QUERY_ALIASMEM structure. -********************************************************************/ -BOOL make_samr_r_query_aliasmem(SAMR_R_QUERY_ALIASMEM *r_u, - uint32 num_sids, DOM_SID2 *sid, uint32 status) -{ - if (r_u == NULL) return False; - - DEBUG(5,("make_samr_r_query_aliasmem\n")); - - if (status == 0x0) - { - r_u->num_sids = num_sids; - r_u->ptr = (num_sids != 0) ? 1 : 0; - r_u->num_sids1 = num_sids; - - r_u->sid = sid; - } - else - { - r_u->ptr = 0; - r_u->num_sids = 0; - } - - r_u->status = status; - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_r_query_aliasmem(char *desc, SAMR_R_QUERY_ALIASMEM *r_u, prs_struct *ps, int depth) -{ - uint32 i; - uint32 ptr_sid[MAX_LOOKUP_SIDS]; + int i; + fstring tmp; - if (r_u == NULL) return False; + if (q_u == NULL) + return False; - prs_debug(ps, depth, desc, "samr_io_r_query_aliasmem"); + prs_debug(ps, depth, desc, "samr_io_q_unknown_12"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("num_sids ", ps, depth, &(r_u->num_sids)); - prs_uint32("ptr", ps, depth, &(r_u->ptr)); + if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth)) + return False; + if(!prs_align(ps)) + return False; - if (r_u->ptr != 0) - { - SMB_ASSERT_ARRAY(ptr_sid, r_u->num_sids); + if(!prs_uint32("num_gids1", ps, depth, &q_u->num_gids1)) + return False; + if(!prs_uint32("rid ", ps, depth, &q_u->rid)) + return False; + if(!prs_uint32("ptr ", ps, depth, &q_u->ptr)) + return False; + if(!prs_uint32("num_gids2", ps, depth, &q_u->num_gids2)) + return False; - if (r_u->num_sids != 0) - { - prs_uint32("num_sids1", ps, depth, &(r_u->num_sids1)); + SMB_ASSERT_ARRAY(q_u->gid, q_u->num_gids2); - for (i = 0; i < r_u->num_sids1; i++) - { - ptr_sid[i] = 1; - prs_uint32("", ps, depth, &(ptr_sid[i])); - } - for (i = 0; i < r_u->num_sids1; i++) - { - if (ptr_sid[i] != 0) - { - smb_io_dom_sid2("", &(r_u->sid[i]), ps, depth); - } - } - } + for (i = 0; i < q_u->num_gids2; i++) { + slprintf(tmp, sizeof(tmp) - 1, "gid[%02d] ", i); + if(!prs_uint32(tmp, ps, depth, &q_u->gid[i])) + return False; } - prs_uint32("status", ps, depth, &(r_u->status)); - - return True; -} - -/******************************************************************* -makes a SAMR_Q_LOOKUP_NAMES structure. -********************************************************************/ -BOOL make_samr_q_lookup_names(SAMR_Q_LOOKUP_NAMES *q_u, - POLICY_HND *pol, uint32 flags, - uint32 num_names, char **name) -{ - uint32 i; - if (q_u == NULL) return False; - - DEBUG(5,("make_samr_q_lookup_names\n")); - memcpy(&(q_u->pol), pol, sizeof(*pol)); - - q_u->num_names1 = num_names; - q_u->flags = flags; - q_u->ptr = 0; - q_u->num_names2 = num_names; - - for (i = 0; i < num_names; i++) - { - int len_name = name[i] != NULL ? strlen(name[i]) : 0; - make_uni_hdr(&(q_u->hdr_name[i]), len_name); /* unicode header for user_name */ - make_unistr2(&(q_u->uni_name[i]), name[i], len_name); /* unicode string for machine account */ - } + if(!prs_align(ps)) + return False; return True; } - /******************************************************************* -reads or writes a structure. + Inits a SAMR_R_UNKNOWN_12 structure. ********************************************************************/ -BOOL samr_io_q_lookup_names(char *desc, SAMR_Q_LOOKUP_NAMES *q_u, prs_struct *ps, int depth) -{ - uint32 i; - - if (q_u == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_q_lookup_names"); - depth++; - - prs_align(ps); - - smb_io_pol_hnd("pol", &(q_u->pol), ps, depth); - prs_align(ps); - - prs_uint32("num_names1", ps, depth, &(q_u->num_names1)); - prs_uint32("flags ", ps, depth, &(q_u->flags )); - prs_uint32("ptr ", ps, depth, &(q_u->ptr )); - prs_uint32("num_names2", ps, depth, &(q_u->num_names2)); - SMB_ASSERT_ARRAY(q_u->hdr_name, q_u->num_names2); - - for (i = 0; i < q_u->num_names2; i++) - { - smb_io_unihdr ("", &(q_u->hdr_name[i]), ps, depth); - } - for (i = 0; i < q_u->num_names2; i++) - { - smb_io_unistr2("", &(q_u->uni_name[i]), q_u->hdr_name[i].buffer, ps, depth); - prs_align(ps); - } - - prs_align(ps); - - return True; -} - - -/******************************************************************* -makes a SAMR_R_LOOKUP_NAMES structure. -********************************************************************/ -BOOL make_samr_r_lookup_names(SAMR_R_LOOKUP_NAMES *r_u, - uint32 num_rids, uint32 *rid, uint8 *type, uint32 status) +void init_samr_r_unknown_12(SAMR_R_UNKNOWN_12 *r_u, + uint32 num_aliases, fstring *als_name, uint32 *num_als_usrs, + uint32 status) { - uint32 i; - if (r_u == NULL) return False; + int i; - DEBUG(5,("make_samr_r_lookup_names\n")); + DEBUG(5,("init_samr_r_unknown_12\n")); - if (status == 0x0) - { - r_u->num_types1 = num_rids; - r_u->ptr_types = 1; - r_u->num_types2 = num_rids; + if (status == 0x0) { + r_u->num_aliases1 = num_aliases; + r_u->ptr_aliases = 1; + r_u->num_aliases2 = num_aliases; - r_u->num_rids1 = num_rids; - r_u->ptr_rids = 1; - r_u->num_rids2 = num_rids; + r_u->num_als_usrs1 = num_aliases; + r_u->ptr_als_usrs = 1; + r_u->num_als_usrs2 = num_aliases; - SMB_ASSERT_ARRAY(r_u->rid, num_rids); + SMB_ASSERT_ARRAY(r_u->hdr_als_name, num_aliases); - for (i = 0; i < num_rids; i++) - { - r_u->rid [i] = rid [i]; - r_u->type[i] = type[i]; + for (i = 0; i < num_aliases; i++) { + int als_len = als_name[i] != NULL ? strlen(als_name[i]) : 0; + init_uni_hdr(&r_u->hdr_als_name[i], als_len); + init_unistr2(&r_u->uni_als_name[i], als_name[i], als_len); + r_u->num_als_usrs[i] = num_als_usrs[i]; } - } - else - { - r_u->num_types1 = 0; - r_u->ptr_types = 0; - r_u->num_types2 = 0; + } else { + r_u->num_aliases1 = num_aliases; + r_u->ptr_aliases = 0; + r_u->num_aliases2 = num_aliases; - r_u->num_rids1 = 0; - r_u->ptr_rids = 0; - r_u->num_rids2 = 0; + r_u->num_als_usrs1 = num_aliases; + r_u->ptr_als_usrs = 0; + r_u->num_als_usrs2 = num_aliases; } r_u->status = status; - - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL samr_io_r_lookup_names(char *desc, SAMR_R_LOOKUP_NAMES *r_u, prs_struct *ps, int depth) + +BOOL samr_io_r_unknown_12(char *desc, SAMR_R_UNKNOWN_12 *r_u, prs_struct *ps, int depth) { - uint32 i; + int i; fstring tmp; - if (r_u == NULL) return False; + if (r_u == NULL) + return False; - prs_debug(ps, depth, desc, "samr_io_r_lookup_names"); + prs_debug(ps, depth, desc, "samr_io_r_unknown_12"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("num_rids1", ps, depth, &(r_u->num_rids1)); - prs_uint32("ptr_rids ", ps, depth, &(r_u->ptr_rids )); + if(!prs_uint32("num_aliases1", ps, depth, &r_u->num_aliases1)) + return False; + if(!prs_uint32("ptr_aliases ", ps, depth, &r_u->ptr_aliases )) + return False; + if(!prs_uint32("num_aliases2", ps, depth, &r_u->num_aliases2)) + return False; - if (r_u->ptr_rids != 0) - { - prs_uint32("num_rids2", ps, depth, &(r_u->num_rids2)); + if (r_u->ptr_aliases != 0 && r_u->num_aliases1 != 0) { + SMB_ASSERT_ARRAY(r_u->hdr_als_name, r_u->num_aliases2); - if (r_u->num_rids2 != r_u->num_rids1) - { - /* RPC fault */ - return False; + for (i = 0; i < r_u->num_aliases2; i++) { + slprintf(tmp, sizeof(tmp) - 1, "als_hdr[%02d] ", i); + if(!smb_io_unihdr ("", &r_u->hdr_als_name[i], ps, depth)) + return False; } - - for (i = 0; i < r_u->num_rids2; i++) - { - slprintf(tmp, sizeof(tmp) - 1, "rid[%02d] ", i); - prs_uint32(tmp, ps, depth, &(r_u->rid[i])); + for (i = 0; i < r_u->num_aliases2; i++) { + slprintf(tmp, sizeof(tmp) - 1, "als_str[%02d] ", i); + if(!smb_io_unistr2("", &r_u->uni_als_name[i], r_u->hdr_als_name[i].buffer, ps, depth)) + return False; } } - prs_uint32("num_types1", ps, depth, &(r_u->num_types1)); - prs_uint32("ptr_types ", ps, depth, &(r_u->ptr_types )); + if(!prs_align(ps)) + return False; - if (r_u->ptr_types != 0) - { - prs_uint32("num_types2", ps, depth, &(r_u->num_types2)); + if(!prs_uint32("num_als_usrs1", ps, depth, &r_u->num_als_usrs1)) + return False; + if(!prs_uint32("ptr_als_usrs ", ps, depth, &r_u->ptr_als_usrs)) + return False; + if(!prs_uint32("num_als_usrs2", ps, depth, &r_u->num_als_usrs2)) + return False; - if (r_u->num_types2 != r_u->num_types1) - { - /* RPC fault */ - return False; - } + if (r_u->ptr_als_usrs != 0 && r_u->num_als_usrs1 != 0) { + SMB_ASSERT_ARRAY(r_u->num_als_usrs, r_u->num_als_usrs2); - for (i = 0; i < r_u->num_types2; i++) - { - slprintf(tmp, sizeof(tmp) - 1, "type[%02d] ", i); - prs_uint32(tmp, ps, depth, &(r_u->type[i])); + for (i = 0; i < r_u->num_als_usrs2; i++) { + slprintf(tmp, sizeof(tmp) - 1, "als_usrs[%02d] ", i); + if(!prs_uint32(tmp, ps, depth, &r_u->num_als_usrs[i])) + return False; } } - prs_uint32("status", ps, depth, &(r_u->status)); + if(!prs_uint32("status", ps, depth, &r_u->status)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Inits a SAMR_Q_OPEN_USER struct. ********************************************************************/ -BOOL make_samr_q_open_user(SAMR_Q_OPEN_USER *q_u, - const POLICY_HND *pol, + +void init_samr_q_open_user(SAMR_Q_OPEN_USER *q_u, + POLICY_HND *pol, uint32 unk_0, uint32 rid) { - if (q_u == NULL) return False; - - DEBUG(5,("samr_make_samr_q_open_user\n")); + DEBUG(5,("samr_init_q_open_user\n")); memcpy(&q_u->domain_pol, pol, sizeof(q_u->domain_pol)); q_u->unknown_0 = unk_0; q_u->user_rid = rid; - - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ + BOOL samr_io_q_open_user(char *desc, SAMR_Q_OPEN_USER *q_u, prs_struct *ps, int depth) { - if (q_u == NULL) return False; + if (q_u == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_q_open_user"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_pol_hnd("domain_pol", &(q_u->domain_pol), ps, depth); - prs_align(ps); + if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth)) + return False; + if(!prs_align(ps)) + return False; - prs_uint32("unknown_0", ps, depth, &(q_u->unknown_0)); - prs_uint32("user_rid ", ps, depth, &(q_u->user_rid )); + if(!prs_uint32("unknown_0", ps, depth, &q_u->unknown_0)) + return False; + if(!prs_uint32("user_rid ", ps, depth, &q_u->user_rid)) + return False; - prs_align(ps); + if(!prs_align(ps)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ + BOOL samr_io_r_open_user(char *desc, SAMR_R_OPEN_USER *r_u, prs_struct *ps, int depth) { - if (r_u == NULL) return False; + if (r_u == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_r_open_user"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_pol_hnd("user_pol", &(r_u->user_pol), ps, depth); - prs_align(ps); + if(!smb_io_pol_hnd("user_pol", &r_u->user_pol, ps, depth)) + return False; + if(!prs_align(ps)) + return False; - prs_uint32("status", ps, depth, &(r_u->status)); + if(!prs_uint32("status", ps, depth, &r_u->status)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Inits a SAMR_Q_QUERY_USERGROUPS structure. ********************************************************************/ -BOOL make_samr_q_create_user(SAMR_Q_CREATE_USER *q_u, - POLICY_HND *pol, - const char *name, - uint16 acb_info, uint32 unk_1) -{ - int len_name; - if (q_u == NULL) return False; - len_name = strlen(name); - - DEBUG(5,("samr_make_samr_q_create_user\n")); - - memcpy(&q_u->domain_pol, pol, sizeof(q_u->domain_pol)); - - make_uni_hdr(&(q_u->hdr_name), len_name); - make_unistr2(&(q_u->uni_name), name, len_name); - q_u->acb_info = acb_info; - q_u->unknown_1 = unk_1; +void init_samr_q_query_usergroups(SAMR_Q_QUERY_USERGROUPS *q_u, + POLICY_HND *hnd) +{ + DEBUG(5,("init_samr_q_query_usergroups\n")); - return True; + memcpy(&q_u->pol, hnd, sizeof(q_u->pol)); } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL samr_io_q_create_user(char *desc, SAMR_Q_CREATE_USER *q_u, prs_struct *ps, int depth) + +BOOL samr_io_q_query_usergroups(char *desc, SAMR_Q_QUERY_USERGROUPS *q_u, prs_struct *ps, int depth) { - if (q_u == NULL) return False; + if (q_u == NULL) + return False; - prs_debug(ps, depth, desc, "samr_io_q_create_user"); + prs_debug(ps, depth, desc, "samr_io_q_query_usergroups"); depth++; - prs_align(ps); - - smb_io_pol_hnd("domain_pol", &(q_u->domain_pol), ps, depth); - prs_align(ps); - - smb_io_unihdr ("unihdr", &(q_u->hdr_name), ps, depth); - smb_io_unistr2("unistr2", &(q_u->uni_name), q_u->hdr_name.buffer, ps, depth); - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint16("acb_info", ps, depth, &(q_u->acb_info)); - prs_align(ps); - prs_uint32("unknown_1", ps, depth, &(q_u->unknown_1)); - - prs_align(ps); + if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth)) + return False; + if(!prs_align(ps)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Inits a SAMR_R_QUERY_USERGROUPS structure. ********************************************************************/ -BOOL make_samr_r_create_user(SAMR_R_CREATE_USER *r_u, - POLICY_HND *user_pol, - uint32 unk_0, uint32 user_rid, - uint32 status) + +void init_samr_r_query_usergroups(SAMR_R_QUERY_USERGROUPS *r_u, + uint32 num_gids, DOM_GID *gid, uint32 status) { - if (r_u == NULL) return False; + DEBUG(5,("init_samr_r_query_usergroups\n")); - DEBUG(5,("samr_make_samr_r_create_user\n")); + if (status == 0x0) { + r_u->ptr_0 = 1; + r_u->num_entries = num_gids; + r_u->ptr_1 = 1; + r_u->num_entries2 = num_gids; - memcpy(&r_u->user_pol, user_pol, sizeof(r_u->user_pol)); - - r_u->unknown_0 = unk_0; - r_u->user_rid = user_rid; - r_u->status = status; + r_u->gid = gid; + } else { + r_u->ptr_0 = 0; + r_u->num_entries = 0; + r_u->ptr_1 = 0; + } - return True; + r_u->status = status; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL samr_io_r_create_user(char *desc, SAMR_R_CREATE_USER *r_u, prs_struct *ps, int depth) + +BOOL samr_io_r_query_usergroups(char *desc, SAMR_R_QUERY_USERGROUPS *r_u, prs_struct *ps, int depth) { - if (r_u == NULL) return False; + int i; - prs_debug(ps, depth, desc, "samr_io_r_create_user"); + if (r_u == NULL) + return False; + + prs_debug(ps, depth, desc, "samr_io_r_query_usergroups"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_pol_hnd("user_pol", &(r_u->user_pol), ps, depth); - prs_align(ps); + if(!prs_uint32("ptr_0 ", ps, depth, &r_u->ptr_0)) + return False; + + if (r_u->ptr_0 != 0) { + if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries)) + return False; + if(!prs_uint32("ptr_1 ", ps, depth, &r_u->ptr_1)) + return False; - prs_uint32("unknown_0", ps, depth, &(r_u->unknown_0)); - prs_uint32("user_rid ", ps, depth, &(r_u->user_rid )); - prs_uint32("status", ps, depth, &(r_u->status)); + if (r_u->num_entries != 0) { + if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2)) + return False; + + for (i = 0; i < r_u->num_entries2; i++) { + if(!smb_io_gid("", &r_u->gid[i], ps, depth)) + return False; + } + } + } + + if(!prs_uint32("status", ps, depth, &r_u->status)) + return False; return True; } /******************************************************************* -makes a SAMR_Q_QUERY_USERINFO structure. + Inits a SAMR_Q_QUERY_USERINFO structure. ********************************************************************/ -BOOL make_samr_q_query_userinfo(SAMR_Q_QUERY_USERINFO *q_u, + +void init_samr_q_query_userinfo(SAMR_Q_QUERY_USERINFO *q_u, POLICY_HND *hnd, uint16 switch_value) { - if (q_u == NULL || hnd == NULL) return False; + DEBUG(5,("init_samr_q_query_userinfo\n")); - DEBUG(5,("make_samr_q_query_userinfo\n")); - - memcpy(&(q_u->pol), hnd, sizeof(q_u->pol)); + memcpy(&q_u->pol, hnd, sizeof(q_u->pol)); q_u->switch_value = switch_value; - - return True; } - /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ + BOOL samr_io_q_query_userinfo(char *desc, SAMR_Q_QUERY_USERINFO *q_u, prs_struct *ps, int depth) { - if (q_u == NULL) return False; + if (q_u == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_q_query_userinfo"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_pol_hnd("pol", &(q_u->pol), ps, depth); - prs_align(ps); + if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth)) + return False; + if(!prs_align(ps)) + return False; - prs_uint16("switch_value", ps, depth, &(q_u->switch_value)); /* 0x0015 or 0x0011 */ - - prs_align(ps); + if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value)) /* 0x0015 or 0x0011 */ + return False; return True; } /******************************************************************* -reads or writes a LOGON_HRS structure. + Reads or writes a LOGON_HRS structure. ********************************************************************/ + static BOOL sam_io_logon_hrs(char *desc, LOGON_HRS *hrs, prs_struct *ps, int depth) { - if (hrs == NULL) return False; + if (hrs == NULL) + return False; prs_debug(ps, depth, desc, "sam_io_logon_hrs"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32 ( "len ", ps, depth, &(hrs->len )); + if(!prs_uint32 ( "len ", ps, depth, &hrs->len)) + return False; - if (hrs->len > 64) - { + if (hrs->len > 64) { DEBUG(5,("sam_io_logon_hrs: truncating length\n")); hrs->len = 64; } - prs_uint8s (False, "hours", ps, depth, hrs->hours, hrs->len); + if(!prs_uint8s (False, "hours", ps, depth, hrs->hours, hrs->len)) + return False; return True; } /******************************************************************* -makes a SAM_USER_INFO_10 structure. + Inits a SAM_USER_INFO_10 structure. ********************************************************************/ -BOOL make_sam_user_info10(SAM_USER_INFO_10 *usr, + +void init_sam_user_info10(SAM_USER_INFO_10 *usr, uint32 acb_info) { - if (usr == NULL) return False; - - DEBUG(5,("make_sam_user_info10\n")); + DEBUG(5,("init_sam_user_info10\n")); usr->acb_info = acb_info; - - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ + BOOL sam_io_user_info10(char *desc, SAM_USER_INFO_10 *usr, prs_struct *ps, int depth) { - if (usr == NULL) return False; + if (usr == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_r_user_info10"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("acb_info", ps, depth, &(usr->acb_info)); + if(!prs_uint32("acb_info", ps, depth, &usr->acb_info)) + return False; return True; } /******************************************************************* -makes a SAM_USER_INFO_11 structure. + Inits a SAM_USER_INFO_11 structure. ********************************************************************/ -BOOL make_sam_user_info11(SAM_USER_INFO_11 *usr, + +void init_sam_user_info11(SAM_USER_INFO_11 *usr, NTTIME *expiry, char *mach_acct, uint32 rid_user, @@ -4808,27 +2589,26 @@ BOOL make_sam_user_info11(SAM_USER_INFO_11 *usr, { int len_mach_acct; - if (usr == NULL || expiry == NULL || mach_acct == NULL) return False; - DEBUG(5,("make_sam_user_info11\n")); + DEBUG(5,("init_sam_user_info11\n")); len_mach_acct = strlen(mach_acct); - memcpy(&(usr->expiry),expiry, sizeof(usr->expiry)); /* expiry time or something? */ - bzero(usr->padding_1, sizeof(usr->padding_1)); /* 0 - padding 24 bytes */ + memcpy(&usr->expiry,expiry, sizeof(usr->expiry)); /* expiry time or something? */ + memset((char *)usr->padding_1, '\0', sizeof(usr->padding_1)); /* 0 - padding 24 bytes */ - make_uni_hdr(&(usr->hdr_mach_acct), len_mach_acct); /* unicode header for machine account */ + init_uni_hdr(&usr->hdr_mach_acct, len_mach_acct); /* unicode header for machine account */ usr->padding_2 = 0; /* 0 - padding 4 bytes */ usr->ptr_1 = 1; /* pointer */ - bzero(usr->padding_3, sizeof(usr->padding_3)); /* 0 - padding 32 bytes */ + memset((char *)usr->padding_3, '\0', sizeof(usr->padding_3)); /* 0 - padding 32 bytes */ usr->padding_4 = 0; /* 0 - padding 4 bytes */ usr->ptr_2 = 1; /* pointer */ usr->padding_5 = 0; /* 0 - padding 4 bytes */ usr->ptr_3 = 1; /* pointer */ - bzero(usr->padding_6, sizeof(usr->padding_6)); /* 0 - padding 32 bytes */ + memset((char *)usr->padding_6, '\0', sizeof(usr->padding_6)); /* 0 - padding 32 bytes */ usr->rid_user = rid_user; usr->rid_group = rid_group; @@ -4839,433 +2619,99 @@ BOOL make_sam_user_info11(SAM_USER_INFO_11 *usr, usr->unknown_4 = 0x003f; /* 0x003f - 16 bit unknown */ usr->unknown_5 = 0x003c; /* 0x003c - 16 bit unknown */ - bzero(usr->padding_7, sizeof(usr->padding_7)); /* 0 - padding 16 bytes */ + memset((char *)usr->padding_7, '\0', sizeof(usr->padding_7)); /* 0 - padding 16 bytes */ usr->padding_8 = 0; /* 0 - padding 4 bytes */ - make_unistr2(&(usr->uni_mach_acct), mach_acct, len_mach_acct); /* unicode string for machine account */ - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL sam_io_user_info11(char *desc, SAM_USER_INFO_11 *usr, prs_struct *ps, int depth) -{ - if (usr == NULL) return False; - - prs_debug(ps, depth, desc, "samr_io_r_unknown_11"); - depth++; - - prs_align(ps); - - prs_uint8s (False, "padding_0", ps, depth, usr->padding_0, sizeof(usr->padding_0)); - - smb_io_time("time", &(usr->expiry), ps, depth); - - prs_uint8s (False, "padding_1", ps, depth, usr->padding_1, sizeof(usr->padding_1)); - - smb_io_unihdr ("unihdr", &(usr->hdr_mach_acct), ps, depth); - prs_uint32( "padding_2", ps, depth, &(usr->padding_2)); - - prs_uint32( "ptr_1 ", ps, depth, &(usr->ptr_1 )); - prs_uint8s (False, "padding_3", ps, depth, usr->padding_3, sizeof(usr->padding_3)); - prs_uint32( "padding_4", ps, depth, &(usr->padding_4)); - - prs_uint32( "ptr_2 ", ps, depth, &(usr->ptr_2 )); - prs_uint32( "padding_5", ps, depth, &(usr->padding_5)); - - prs_uint32( "ptr_3 ", ps, depth, &(usr->ptr_3 )); - prs_uint8s (False, "padding_6", ps, depth, usr->padding_6, sizeof(usr->padding_6)); - - prs_uint32( "rid_user ", ps, depth, &(usr->rid_user )); - prs_uint32( "rid_group", ps, depth, &(usr->rid_group)); - prs_uint16( "acct_ctrl", ps, depth, &(usr->acct_ctrl)); - prs_uint16( "unknown_3", ps, depth, &(usr->unknown_3)); - prs_uint16( "unknown_4", ps, depth, &(usr->unknown_4)); - prs_uint16( "unknown_5", ps, depth, &(usr->unknown_5)); - - prs_uint8s (False, "padding_7", ps, depth, usr->padding_7, sizeof(usr->padding_7)); - prs_uint32( "padding_8", ps, depth, &(usr->padding_8)); - - smb_io_unistr2("unistr2", &(usr->uni_mach_acct), True, ps, depth); - prs_align(ps); - - prs_uint8s (False, "padding_9", ps, depth, usr->padding_9, sizeof(usr->padding_9)); + init_unistr2(&usr->uni_mach_acct, mach_acct, len_mach_acct); /* unicode string for machine account */ - return True; -} - -/************************************************************************* - make_sam_user_infoa - - unknown_3 = 0x09f8 27fa - unknown_5 = 0x0001 0000 - unknown_6 = 0x0000 04ec - - *************************************************************************/ -BOOL make_sam_user_info24(SAM_USER_INFO_24 *usr, - char newpass[516], uint16 passlen) -{ - memcpy(usr->pass, newpass, sizeof(usr->pass)); - usr->unk_0 = passlen; - - return True; + memset((char *)usr->padding_9, '\0', sizeof(usr->padding_9)); /* 0 - padding 48 bytes */ } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -static BOOL sam_io_user_info24(char *desc, SAM_USER_INFO_24 *usr, prs_struct *ps, int depth) -{ - if (usr == NULL) return False; - prs_debug(ps, depth, desc, "sam_io_user_info24"); - depth++; - - prs_align(ps); - - prs_uint8s (False, "password", ps, depth, usr->pass, sizeof(usr->pass)); - prs_uint16("unk_0", ps, depth, &(usr->unk_0)); /* unknown */ - prs_align(ps); - - return True; -} - - -/************************************************************************* - make_sam_user_info23 - - unknown_3 = 0x09f8 27fa - unknown_5 = 0x0001 0000 - unknown_6 = 0x0000 04ec - - *************************************************************************/ -BOOL make_sam_user_info23W(SAM_USER_INFO_23 *usr, - - NTTIME *logon_time, /* all zeros */ - NTTIME *logoff_time, /* all zeros */ - NTTIME *kickoff_time, /* all zeros */ - NTTIME *pass_last_set_time, /* all zeros */ - NTTIME *pass_can_change_time, /* all zeros */ - NTTIME *pass_must_change_time, /* all zeros */ - - UNISTR2 *user_name, /* NULL */ - UNISTR2 *full_name, - UNISTR2 *home_dir, - UNISTR2 *dir_drive, - UNISTR2 *log_scr, - UNISTR2 *prof_path, - UNISTR2 *desc, - UNISTR2 *wkstas, - UNISTR2 *unk_str, - UNISTR2 *mung_dial, - - uint32 user_rid, /* 0x0000 0000 */ - uint32 group_rid, - uint16 acb_info, - - uint32 unknown_3, - uint16 logon_divs, - LOGON_HRS *hrs, - uint32 unknown_5, - char newpass[516], - uint32 unknown_6) -{ - int len_user_name = user_name != NULL ? user_name->uni_str_len : 0; - int len_full_name = full_name != NULL ? full_name->uni_str_len : 0; - int len_home_dir = home_dir != NULL ? home_dir ->uni_str_len : 0; - int len_dir_drive = dir_drive != NULL ? dir_drive->uni_str_len : 0; - int len_logon_script = log_scr != NULL ? log_scr ->uni_str_len : 0; - int len_profile_path = prof_path != NULL ? prof_path->uni_str_len : 0; - int len_description = desc != NULL ? desc ->uni_str_len : 0; - int len_workstations = wkstas != NULL ? wkstas ->uni_str_len : 0; - int len_unknown_str = unk_str != NULL ? unk_str ->uni_str_len : 0; - int len_munged_dial = mung_dial != NULL ? mung_dial->uni_str_len : 0; - - usr->logon_time = *logon_time; /* all zeros */ - usr->logoff_time = *logoff_time; /* all zeros */ - usr->kickoff_time = *kickoff_time; /* all zeros */ - usr->pass_last_set_time = *pass_last_set_time; /* all zeros */ - usr->pass_can_change_time = *pass_can_change_time; /* all zeros */ - usr->pass_must_change_time = *pass_must_change_time; /* all zeros */ - - make_uni_hdr(&(usr->hdr_user_name ), len_user_name ); /* NULL */ - make_uni_hdr(&(usr->hdr_full_name ), len_full_name ); - make_uni_hdr(&(usr->hdr_home_dir ), len_home_dir ); - make_uni_hdr(&(usr->hdr_dir_drive ), len_dir_drive ); - make_uni_hdr(&(usr->hdr_logon_script), len_logon_script); - make_uni_hdr(&(usr->hdr_profile_path), len_profile_path); - make_uni_hdr(&(usr->hdr_acct_desc ), len_description ); - make_uni_hdr(&(usr->hdr_workstations), len_workstations); - make_uni_hdr(&(usr->hdr_unknown_str ), len_unknown_str ); - make_uni_hdr(&(usr->hdr_munged_dial ), len_munged_dial ); - - bzero(usr->nt_pwd, sizeof(usr->nt_pwd)); - bzero(usr->lm_pwd, sizeof(usr->lm_pwd)); - - usr->user_rid = user_rid; /* 0x0000 0000 */ - usr->group_rid = group_rid; - usr->acb_info = acb_info; - usr->unknown_3 = unknown_3; /* 09f8 27fa */ - - usr->logon_divs = logon_divs; /* should be 168 (hours/week) */ - usr->ptr_logon_hrs = hrs ? 1 : 0; - - bzero(usr->padding1, sizeof(usr->padding1)); - - usr->unknown_5 = unknown_5; /* 0x0001 0000 */ - - memcpy(usr->pass, newpass, sizeof(usr->pass)); - - copy_unistr2(&(usr->uni_user_name ), user_name); - copy_unistr2(&(usr->uni_full_name ), full_name); - copy_unistr2(&(usr->uni_home_dir ), home_dir ); - copy_unistr2(&(usr->uni_dir_drive ), dir_drive); - copy_unistr2(&(usr->uni_logon_script), log_scr ); - copy_unistr2(&(usr->uni_profile_path), prof_path); - copy_unistr2(&(usr->uni_acct_desc ), desc ); - copy_unistr2(&(usr->uni_workstations), wkstas ); - copy_unistr2(&(usr->uni_unknown_str ), unk_str ); - copy_unistr2(&(usr->uni_munged_dial ), mung_dial); - - usr->unknown_6 = unknown_6; /* 0x0000 04ec */ - usr->padding4 = 0; - - if (hrs) - { - memcpy(&(usr->logon_hrs), hrs, sizeof(usr->logon_hrs)); - } - else - { - memset(&(usr->logon_hrs), 0xff, sizeof(usr->logon_hrs)); - } - - return True; -} - -/************************************************************************* - make_sam_user_info23 - - unknown_3 = 0x09f8 27fa - unknown_5 = 0x0001 0000 - unknown_6 = 0x0000 04ec - - *************************************************************************/ -BOOL make_sam_user_info23A(SAM_USER_INFO_23 *usr, - - NTTIME *logon_time, /* all zeros */ - NTTIME *logoff_time, /* all zeros */ - NTTIME *kickoff_time, /* all zeros */ - NTTIME *pass_last_set_time, /* all zeros */ - NTTIME *pass_can_change_time, /* all zeros */ - NTTIME *pass_must_change_time, /* all zeros */ - - char *user_name, /* NULL */ - char *full_name, - char *home_dir, - char *dir_drive, - char *log_scr, - char *prof_path, - char *desc, - char *wkstas, - char *unk_str, - char *mung_dial, - - uint32 user_rid, /* 0x0000 0000 */ - uint32 group_rid, - uint16 acb_info, - - uint32 unknown_3, - uint16 logon_divs, - LOGON_HRS *hrs, - uint32 unknown_5, - char newpass[516], - uint32 unknown_6) -{ - int len_user_name = user_name != NULL ? strlen(user_name) : 0; - int len_full_name = full_name != NULL ? strlen(full_name) : 0; - int len_home_dir = home_dir != NULL ? strlen(home_dir ) : 0; - int len_dir_drive = dir_drive != NULL ? strlen(dir_drive) : 0; - int len_logon_script = log_scr != NULL ? strlen(log_scr ) : 0; - int len_profile_path = prof_path != NULL ? strlen(prof_path) : 0; - int len_description = desc != NULL ? strlen(desc ) : 0; - int len_workstations = wkstas != NULL ? strlen(wkstas ) : 0; - int len_unknown_str = unk_str != NULL ? strlen(unk_str ) : 0; - int len_munged_dial = mung_dial != NULL ? strlen(mung_dial) : 0; - - usr->logon_time = *logon_time; /* all zeros */ - usr->logoff_time = *logoff_time; /* all zeros */ - usr->kickoff_time = *kickoff_time; /* all zeros */ - usr->pass_last_set_time = *pass_last_set_time; /* all zeros */ - usr->pass_can_change_time = *pass_can_change_time; /* all zeros */ - usr->pass_must_change_time = *pass_must_change_time; /* all zeros */ - - make_uni_hdr(&(usr->hdr_user_name ), len_user_name ); /* NULL */ - make_uni_hdr(&(usr->hdr_full_name ), len_full_name ); - make_uni_hdr(&(usr->hdr_home_dir ), len_home_dir ); - make_uni_hdr(&(usr->hdr_dir_drive ), len_dir_drive ); - make_uni_hdr(&(usr->hdr_logon_script), len_logon_script); - make_uni_hdr(&(usr->hdr_profile_path), len_profile_path); - make_uni_hdr(&(usr->hdr_acct_desc ), len_description ); - make_uni_hdr(&(usr->hdr_workstations), len_workstations); - make_uni_hdr(&(usr->hdr_unknown_str ), len_unknown_str ); - make_uni_hdr(&(usr->hdr_munged_dial ), len_munged_dial ); - - bzero(usr->nt_pwd, sizeof(usr->nt_pwd)); - bzero(usr->lm_pwd, sizeof(usr->lm_pwd)); - - usr->user_rid = user_rid; /* 0x0000 0000 */ - usr->group_rid = group_rid; - usr->acb_info = acb_info; - usr->unknown_3 = unknown_3; /* 09f8 27fa */ - - usr->logon_divs = logon_divs; /* should be 168 (hours/week) */ - usr->ptr_logon_hrs = hrs ? 1 : 0; - - bzero(usr->padding1, sizeof(usr->padding1)); - - usr->unknown_5 = unknown_5; /* 0x0001 0000 */ - - memcpy(usr->pass, newpass, sizeof(usr->pass)); - - make_unistr2(&(usr->uni_user_name ), user_name , len_user_name ); /* NULL */ - make_unistr2(&(usr->uni_full_name ), full_name , len_full_name ); - make_unistr2(&(usr->uni_home_dir ), home_dir , len_home_dir ); - make_unistr2(&(usr->uni_dir_drive ), dir_drive , len_dir_drive ); - make_unistr2(&(usr->uni_logon_script), log_scr, len_logon_script); - make_unistr2(&(usr->uni_profile_path), prof_path, len_profile_path); - make_unistr2(&(usr->uni_acct_desc ), desc , len_description ); - make_unistr2(&(usr->uni_workstations), wkstas, len_workstations); - make_unistr2(&(usr->uni_unknown_str ), unk_str , len_unknown_str ); - make_unistr2(&(usr->uni_munged_dial ), mung_dial , len_munged_dial ); - - usr->unknown_6 = unknown_6; /* 0x0000 04ec */ - usr->padding4 = 0; - - if (hrs) - { - memcpy(&(usr->logon_hrs), hrs, sizeof(usr->logon_hrs)); - } - else - { - memset(&(usr->logon_hrs), 0xff, sizeof(usr->logon_hrs)); - } - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -static BOOL sam_io_user_info16(char *desc, SAM_USER_INFO_16 *usr, prs_struct *ps, int depth) -{ - if (usr == NULL) return False; - - prs_debug(ps, depth, desc, "sam_io_user_info16"); - depth++; - - prs_align(ps); - - prs_uint16("acb_info", ps, depth, &(usr->acb_info)); - prs_align(ps); - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -static BOOL sam_io_user_info23(char *desc, SAM_USER_INFO_23 *usr, prs_struct *ps, int depth) +BOOL sam_io_user_info11(char *desc, SAM_USER_INFO_11 *usr, prs_struct *ps, int depth) { - if (usr == NULL) return False; - - prs_debug(ps, depth, desc, "sam_io_user_info23"); - depth++; - - prs_align(ps); + if (usr == NULL) + return False; + + prs_debug(ps, depth, desc, "samr_io_r_unknown_24"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint8s (False, "padding_0", ps, depth, usr->padding_0, sizeof(usr->padding_0))) + return False; + + if(!smb_io_time("time", &(usr->expiry), ps, depth)) + return False; + + if(!prs_uint8s (False, "padding_1", ps, depth, usr->padding_1, sizeof(usr->padding_1))) + return False; + + if(!smb_io_unihdr ("unihdr", &usr->hdr_mach_acct, ps, depth)) + return False; + if(!prs_uint32( "padding_2", ps, depth, &usr->padding_2)) + return False; + + if(!prs_uint32( "ptr_1 ", ps, depth, &usr->ptr_1)) + return False; + if(!prs_uint8s (False, "padding_3", ps, depth, usr->padding_3, sizeof(usr->padding_3))) + return False; + if(!prs_uint32( "padding_4", ps, depth, &usr->padding_4)) + return False; + + if(!prs_uint32( "ptr_2 ", ps, depth, &usr->ptr_2)) + return False; + if(!prs_uint32( "padding_5", ps, depth, &usr->padding_5)) + return False; + + if(!prs_uint32( "ptr_3 ", ps, depth, &usr->ptr_3)) + return False; + if(!prs_uint8s(False, "padding_6", ps, depth, usr->padding_6, sizeof(usr->padding_6))) + return False; + + if(!prs_uint32( "rid_user ", ps, depth, &usr->rid_user)) + return False; + if(!prs_uint32( "rid_group", ps, depth, &usr->rid_group)) + return False; + if(!prs_uint16( "acct_ctrl", ps, depth, &usr->acct_ctrl)) + return False; + if(!prs_uint16( "unknown_3", ps, depth, &usr->unknown_3)) + return False; + if(!prs_uint16( "unknown_4", ps, depth, &usr->unknown_4)) + return False; + if(!prs_uint16( "unknown_5", ps, depth, &usr->unknown_5)) + return False; + + if(!prs_uint8s (False, "padding_7", ps, depth, usr->padding_7, sizeof(usr->padding_7))) + return False; + if(!prs_uint32( "padding_8", ps, depth, &usr->padding_8)) + return False; - smb_io_time("logon_time ", &(usr->logon_time) , ps, depth); - smb_io_time("logoff_time ", &(usr->logoff_time) , ps, depth); - smb_io_time("kickoff_time ", &(usr->kickoff_time) , ps, depth); - smb_io_time("pass_last_set_time ", &(usr->pass_last_set_time) , ps, depth); - smb_io_time("pass_can_change_time ", &(usr->pass_can_change_time) , ps, depth); - smb_io_time("pass_must_change_time", &(usr->pass_must_change_time), ps, depth); - - smb_io_unihdr("hdr_user_name ", &(usr->hdr_user_name) , ps, depth); /* username unicode string header */ - smb_io_unihdr("hdr_full_name ", &(usr->hdr_full_name) , ps, depth); /* user's full name unicode string header */ - smb_io_unihdr("hdr_home_dir ", &(usr->hdr_home_dir) , ps, depth); /* home directory unicode string header */ - smb_io_unihdr("hdr_dir_drive ", &(usr->hdr_dir_drive) , ps, depth); /* home directory drive */ - smb_io_unihdr("hdr_logon_script", &(usr->hdr_logon_script), ps, depth); /* logon script unicode string header */ - smb_io_unihdr("hdr_profile_path", &(usr->hdr_profile_path), ps, depth); /* profile path unicode string header */ - smb_io_unihdr("hdr_acct_desc ", &(usr->hdr_acct_desc ) , ps, depth); /* account desc */ - smb_io_unihdr("hdr_workstations", &(usr->hdr_workstations), ps, depth); /* wkstas user can log on from */ - smb_io_unihdr("hdr_unknown_str ", &(usr->hdr_unknown_str ), ps, depth); /* unknown string */ - smb_io_unihdr("hdr_munged_dial ", &(usr->hdr_munged_dial ), ps, depth); /* wkstas user can log on from */ - - prs_uint8s (False, "lm_pwd ", ps, depth, usr->lm_pwd , sizeof(usr->lm_pwd )); - prs_uint8s (False, "nt_pwd ", ps, depth, usr->nt_pwd , sizeof(usr->nt_pwd )); - - prs_uint32("user_rid ", ps, depth, &(usr->user_rid )); /* User ID */ - prs_uint32("group_rid ", ps, depth, &(usr->group_rid )); /* Group ID */ - prs_uint16("acb_info ", ps, depth, &(usr->acb_info )); /* Group ID */ - prs_align(ps); - - prs_uint32("unknown_3 ", ps, depth, &(usr->unknown_3 )); - prs_uint16("logon_divs ", ps, depth, &(usr->logon_divs )); /* logon divisions per week */ - prs_align(ps); - prs_uint32("ptr_logon_hrs ", ps, depth, &(usr->ptr_logon_hrs)); - prs_uint8s (False, "padding1 ", ps, depth, usr->padding1, sizeof(usr->padding1)); - prs_uint32("unknown_5 ", ps, depth, &(usr->unknown_5 )); - - prs_uint8s (False, "password ", ps, depth, usr->pass, sizeof(usr->pass)); - - /* here begins pointed-to data */ + if(!smb_io_unistr2("unistr2", &usr->uni_mach_acct, True, ps, depth)) + return False; + if(!prs_align(ps)) + return False; - smb_io_unistr2("uni_user_name ", &(usr->uni_user_name) , usr->hdr_user_name .buffer, ps, depth); /* username unicode string */ - prs_align(ps); - smb_io_unistr2("uni_full_name ", &(usr->uni_full_name) , usr->hdr_full_name .buffer, ps, depth); /* user's full name unicode string */ - prs_align(ps); - smb_io_unistr2("uni_home_dir ", &(usr->uni_home_dir) , usr->hdr_home_dir .buffer, ps, depth); /* home directory unicode string */ - prs_align(ps); - smb_io_unistr2("uni_dir_drive ", &(usr->uni_dir_drive) , usr->hdr_dir_drive .buffer, ps, depth); /* home directory drive unicode string */ - prs_align(ps); - smb_io_unistr2("uni_logon_script", &(usr->uni_logon_script), usr->hdr_logon_script.buffer, ps, depth); /* logon script unicode string */ - prs_align(ps); - smb_io_unistr2("uni_profile_path", &(usr->uni_profile_path), usr->hdr_profile_path.buffer, ps, depth); /* profile path unicode string */ - prs_align(ps); - smb_io_unistr2("uni_acct_desc ", &(usr->uni_acct_desc ), usr->hdr_acct_desc .buffer, ps, depth); /* user desc unicode string */ - prs_align(ps); - smb_io_unistr2("uni_workstations", &(usr->uni_workstations), usr->hdr_workstations.buffer, ps, depth); /* worksations user can log on from */ - prs_align(ps); - smb_io_unistr2("uni_unknown_str ", &(usr->uni_unknown_str ), usr->hdr_unknown_str .buffer, ps, depth); /* unknown string */ - prs_align(ps); - smb_io_unistr2("uni_munged_dial ", &(usr->uni_munged_dial ), usr->hdr_munged_dial .buffer, ps, depth); /* worksations user can log on from */ - prs_align(ps); - - prs_uint32("unknown_6 ", ps, depth, &(usr->unknown_6 )); - prs_uint32("padding4 ", ps, depth, &(usr->padding4 )); - - if (usr->ptr_logon_hrs) - { - sam_io_logon_hrs("logon_hrs", &(usr->logon_hrs) , ps, depth); - prs_align(ps); - } + if(!prs_uint8s(False, "padding_9", ps, depth, usr->padding_9, sizeof(usr->padding_9))) + return False; return True; } - /************************************************************************* - make_sam_user_info21 + init_sam_user_info21 unknown_3 = 0x00ff ffff unknown_5 = 0x0002 0000 unknown_6 = 0x0000 04ec *************************************************************************/ -BOOL make_sam_user_info21(SAM_USER_INFO_21 *usr, +void init_sam_user_info21(SAM_USER_INFO_21 *usr, NTTIME *logon_time, NTTIME *logoff_time, NTTIME *kickoff_time, @@ -5277,12 +2723,12 @@ BOOL make_sam_user_info21(SAM_USER_INFO_21 *usr, char *full_name, char *home_dir, char *dir_drive, - char *log_scr, - char *prof_path, - char *desc, - char *wkstas, - char *unk_str, - char *mung_dial, + char *logon_script, + char *profile_path, + char *description, + char *workstations, + char *unknown_str, + char *munged_dial, uint32 user_rid, uint32 group_rid, @@ -5294,16 +2740,16 @@ BOOL make_sam_user_info21(SAM_USER_INFO_21 *usr, uint32 unknown_5, uint32 unknown_6) { - int len_user_name = user_name != NULL ? strlen(user_name) : 0; - int len_full_name = full_name != NULL ? strlen(full_name) : 0; - int len_home_dir = home_dir != NULL ? strlen(home_dir ) : 0; - int len_dir_drive = dir_drive != NULL ? strlen(dir_drive) : 0; - int len_logon_script = log_scr != NULL ? strlen(log_scr ) : 0; - int len_profile_path = prof_path != NULL ? strlen(prof_path) : 0; - int len_description = desc != NULL ? strlen(desc ) : 0; - int len_workstations = wkstas != NULL ? strlen(wkstas ) : 0; - int len_unknown_str = unk_str != NULL ? strlen(unk_str ) : 0; - int len_munged_dial = mung_dial != NULL ? strlen(mung_dial) : 0; + int len_user_name = user_name != NULL ? strlen(user_name ) : 0; + int len_full_name = full_name != NULL ? strlen(full_name ) : 0; + int len_home_dir = home_dir != NULL ? strlen(home_dir ) : 0; + int len_dir_drive = dir_drive != NULL ? strlen(dir_drive ) : 0; + int len_logon_script = logon_script != NULL ? strlen(logon_script) : 0; + int len_profile_path = profile_path != NULL ? strlen(profile_path) : 0; + int len_description = description != NULL ? strlen(description ) : 0; + int len_workstations = workstations != NULL ? strlen(workstations) : 0; + int len_unknown_str = unknown_str != NULL ? strlen(unknown_str ) : 0; + int len_munged_dial = munged_dial != NULL ? strlen(munged_dial ) : 0; usr->logon_time = *logon_time; usr->logoff_time = *logoff_time; @@ -5312,19 +2758,19 @@ BOOL make_sam_user_info21(SAM_USER_INFO_21 *usr, usr->pass_can_change_time = *pass_can_change_time; usr->pass_must_change_time = *pass_must_change_time; - make_uni_hdr(&(usr->hdr_user_name ), len_user_name ); - make_uni_hdr(&(usr->hdr_full_name ), len_full_name ); - make_uni_hdr(&(usr->hdr_home_dir ), len_home_dir ); - make_uni_hdr(&(usr->hdr_dir_drive ), len_dir_drive ); - make_uni_hdr(&(usr->hdr_logon_script), len_logon_script); - make_uni_hdr(&(usr->hdr_profile_path), len_profile_path); - make_uni_hdr(&(usr->hdr_acct_desc ), len_description ); - make_uni_hdr(&(usr->hdr_workstations), len_workstations); - make_uni_hdr(&(usr->hdr_unknown_str ), len_unknown_str ); - make_uni_hdr(&(usr->hdr_munged_dial ), len_munged_dial ); + init_uni_hdr(&usr->hdr_user_name, len_user_name); + init_uni_hdr(&usr->hdr_full_name, len_full_name); + init_uni_hdr(&usr->hdr_home_dir, len_home_dir); + init_uni_hdr(&usr->hdr_dir_drive, len_dir_drive); + init_uni_hdr(&usr->hdr_logon_script, len_logon_script); + init_uni_hdr(&usr->hdr_profile_path, len_profile_path); + init_uni_hdr(&usr->hdr_acct_desc, len_description); + init_uni_hdr(&usr->hdr_workstations, len_workstations); + init_uni_hdr(&usr->hdr_unknown_str, len_unknown_str); + init_uni_hdr(&usr->hdr_munged_dial, len_munged_dial); - bzero(usr->nt_pwd, sizeof(usr->nt_pwd)); - bzero(usr->lm_pwd, sizeof(usr->lm_pwd)); + memset((char *)usr->nt_pwd, '\0', sizeof(usr->nt_pwd)); + memset((char *)usr->lm_pwd, '\0', sizeof(usr->lm_pwd)); usr->user_rid = user_rid; usr->group_rid = group_rid; @@ -5335,807 +2781,659 @@ BOOL make_sam_user_info21(SAM_USER_INFO_21 *usr, usr->ptr_logon_hrs = hrs ? 1 : 0; usr->unknown_5 = unknown_5; /* 0x0002 0000 */ - bzero(usr->padding1, sizeof(usr->padding1)); + memset((char *)usr->padding1, '\0', sizeof(usr->padding1)); - make_unistr2(&(usr->uni_user_name ), user_name , len_user_name ); - make_unistr2(&(usr->uni_full_name ), full_name , len_full_name ); - make_unistr2(&(usr->uni_home_dir ), home_dir , len_home_dir ); - make_unistr2(&(usr->uni_dir_drive ), dir_drive , len_dir_drive ); - make_unistr2(&(usr->uni_logon_script), log_scr, len_logon_script); - make_unistr2(&(usr->uni_profile_path), prof_path, len_profile_path); - make_unistr2(&(usr->uni_acct_desc ), desc , len_description ); - make_unistr2(&(usr->uni_workstations), wkstas, len_workstations); - make_unistr2(&(usr->uni_unknown_str ), unk_str , len_unknown_str ); - make_unistr2(&(usr->uni_munged_dial ), mung_dial , len_munged_dial ); + init_unistr2(&usr->uni_user_name, user_name, len_user_name); + init_unistr2(&usr->uni_full_name, full_name, len_full_name); + init_unistr2(&usr->uni_home_dir, home_dir, len_home_dir); + init_unistr2(&usr->uni_dir_drive, dir_drive, len_dir_drive); + init_unistr2(&usr->uni_logon_script, logon_script, len_logon_script); + init_unistr2(&usr->uni_profile_path, profile_path, len_profile_path); + init_unistr2(&usr->uni_acct_desc, description, len_description); + init_unistr2(&usr->uni_workstations, workstations, len_workstations); + init_unistr2(&usr->uni_unknown_str, unknown_str, len_unknown_str); + init_unistr2(&usr->uni_munged_dial, munged_dial, len_munged_dial); usr->unknown_6 = unknown_6; /* 0x0000 04ec */ usr->padding4 = 0; if (hrs) - { memcpy(&(usr->logon_hrs), hrs, sizeof(usr->logon_hrs)); - } else - { memset(&(usr->logon_hrs), 0xff, sizeof(usr->logon_hrs)); - } - - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ + static BOOL sam_io_user_info21(char *desc, SAM_USER_INFO_21 *usr, prs_struct *ps, int depth) { - if (usr == NULL) return False; + if (usr == NULL) + return False; - prs_debug(ps, depth, desc, "sam_io_user_info21"); + prs_debug(ps, depth, desc, "lsa_io_user_info"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_time("logon_time ", &(usr->logon_time) , ps, depth); - smb_io_time("logoff_time ", &(usr->logoff_time) , ps, depth); - smb_io_time("kickoff_time ", &(usr->kickoff_time) , ps, depth); - smb_io_time("pass_last_set_time ", &(usr->pass_last_set_time) , ps, depth); - smb_io_time("pass_can_change_time ", &(usr->pass_can_change_time) , ps, depth); - smb_io_time("pass_must_change_time", &(usr->pass_must_change_time), ps, depth); - - smb_io_unihdr("hdr_user_name ", &(usr->hdr_user_name) , ps, depth); /* username unicode string header */ - smb_io_unihdr("hdr_full_name ", &(usr->hdr_full_name) , ps, depth); /* user's full name unicode string header */ - smb_io_unihdr("hdr_home_dir ", &(usr->hdr_home_dir) , ps, depth); /* home directory unicode string header */ - smb_io_unihdr("hdr_dir_drive ", &(usr->hdr_dir_drive) , ps, depth); /* home directory drive */ - smb_io_unihdr("hdr_logon_script", &(usr->hdr_logon_script), ps, depth); /* logon script unicode string header */ - smb_io_unihdr("hdr_profile_path", &(usr->hdr_profile_path), ps, depth); /* profile path unicode string header */ - smb_io_unihdr("hdr_acct_desc ", &(usr->hdr_acct_desc ) , ps, depth); /* account desc */ - smb_io_unihdr("hdr_workstations", &(usr->hdr_workstations), ps, depth); /* wkstas user can log on from */ - smb_io_unihdr("hdr_unknown_str ", &(usr->hdr_unknown_str ), ps, depth); /* unknown string */ - smb_io_unihdr("hdr_munged_dial ", &(usr->hdr_munged_dial ), ps, depth); /* wkstas user can log on from */ - - prs_uint8s (False, "lm_pwd ", ps, depth, usr->lm_pwd , sizeof(usr->lm_pwd )); - prs_uint8s (False, "nt_pwd ", ps, depth, usr->nt_pwd , sizeof(usr->nt_pwd )); - - prs_uint32("user_rid ", ps, depth, &(usr->user_rid )); /* User ID */ - prs_uint32("group_rid ", ps, depth, &(usr->group_rid )); /* Group ID */ - prs_uint16("acb_info ", ps, depth, &(usr->acb_info )); /* Group ID */ - prs_align(ps); - - prs_uint32("unknown_3 ", ps, depth, &(usr->unknown_3 )); - prs_uint16("logon_divs ", ps, depth, &(usr->logon_divs )); /* logon divisions per week */ - prs_align(ps); - prs_uint32("ptr_logon_hrs ", ps, depth, &(usr->ptr_logon_hrs)); - prs_uint32("unknown_5 ", ps, depth, &(usr->unknown_5 )); - - prs_uint8s (False, "padding1 ", ps, depth, usr->padding1, sizeof(usr->padding1)); + if(!smb_io_time("logon_time ", &usr->logon_time, ps, depth)) + return False; + if(!smb_io_time("logoff_time ", &usr->logoff_time, ps, depth)) + return False; + if(!smb_io_time("kickoff_time ", &usr->kickoff_time, ps, depth)) + return False; + if(!smb_io_time("pass_last_set_time ", &usr->pass_last_set_time, ps, depth)) + return False; + if(!smb_io_time("pass_can_change_time ", &usr->pass_can_change_time, ps, depth)) + return False; + if(!smb_io_time("pass_must_change_time", &usr->pass_must_change_time, ps, depth)) + return False; + + if(!smb_io_unihdr("hdr_user_name ", &usr->hdr_user_name, ps, depth)) /* username unicode string header */ + return False; + if(!smb_io_unihdr("hdr_full_name ", &usr->hdr_full_name, ps, depth)) /* user's full name unicode string header */ + return False; + if(!smb_io_unihdr("hdr_home_dir ", &usr->hdr_home_dir, ps, depth)) /* home directory unicode string header */ + return False; + if(!smb_io_unihdr("hdr_dir_drive ", &usr->hdr_dir_drive, ps, depth)) /* home directory drive */ + return False; + if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth)) /* logon script unicode string header */ + return False; + if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth)) /* profile path unicode string header */ + return False; + if(!smb_io_unihdr("hdr_acct_desc ", &usr->hdr_acct_desc, ps, depth)) /* account description */ + return False; + if(!smb_io_unihdr("hdr_workstations", &usr->hdr_workstations, ps, depth)) /* workstations user can log on from */ + return False; + if(!smb_io_unihdr("hdr_unknown_str ", &usr->hdr_unknown_str, ps, depth)) /* unknown string */ + return False; + if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth)) /* workstations user can log on from */ + return False; + + if(!prs_uint8s (False, "lm_pwd ", ps, depth, usr->lm_pwd, sizeof(usr->lm_pwd))) + return False; + if(!prs_uint8s (False, "nt_pwd ", ps, depth, usr->nt_pwd, sizeof(usr->nt_pwd))) + return False; + + if(!prs_uint32("user_rid ", ps, depth, &usr->user_rid)) /* User ID */ + return False; + if(!prs_uint32("group_rid ", ps, depth, &usr->group_rid)) /* Group ID */ + return False; + if(!prs_uint16("acb_info ", ps, depth, &usr->acb_info)) /* Group ID */ + return False; + if(!prs_align(ps)) + return False; + + if(!prs_uint32("unknown_3 ", ps, depth, &usr->unknown_3)) + return False; + if(!prs_uint16("logon_divs ", ps, depth, &usr->logon_divs)) /* logon divisions per week */ + return False; + if(!prs_align(ps)) + return False; + if(!prs_uint32("ptr_logon_hrs ", ps, depth, &usr->ptr_logon_hrs)) + return False; + if(!prs_uint32("unknown_5 ", ps, depth, &usr->unknown_5)) + return False; + + if(!prs_uint8s (False, "padding1 ", ps, depth, usr->padding1, sizeof(usr->padding1))) + return False; /* here begins pointed-to data */ - smb_io_unistr2("uni_user_name ", &(usr->uni_user_name) , usr->hdr_user_name .buffer, ps, depth); /* username unicode string */ - prs_align(ps); - smb_io_unistr2("uni_full_name ", &(usr->uni_full_name) , usr->hdr_full_name .buffer, ps, depth); /* user's full name unicode string */ - prs_align(ps); - smb_io_unistr2("uni_home_dir ", &(usr->uni_home_dir) , usr->hdr_home_dir .buffer, ps, depth); /* home directory unicode string */ - prs_align(ps); - smb_io_unistr2("uni_dir_drive ", &(usr->uni_dir_drive) , usr->hdr_dir_drive .buffer, ps, depth); /* home directory drive unicode string */ - prs_align(ps); - smb_io_unistr2("uni_logon_script", &(usr->uni_logon_script), usr->hdr_logon_script.buffer, ps, depth); /* logon script unicode string */ - prs_align(ps); - smb_io_unistr2("uni_profile_path", &(usr->uni_profile_path), usr->hdr_profile_path.buffer, ps, depth); /* profile path unicode string */ - prs_align(ps); - smb_io_unistr2("uni_acct_desc ", &(usr->uni_acct_desc ), usr->hdr_acct_desc .buffer, ps, depth); /* user desc unicode string */ - prs_align(ps); - smb_io_unistr2("uni_workstations", &(usr->uni_workstations), usr->hdr_workstations.buffer, ps, depth); /* worksations user can log on from */ - prs_align(ps); - smb_io_unistr2("uni_unknown_str ", &(usr->uni_unknown_str ), usr->hdr_unknown_str .buffer, ps, depth); /* unknown string */ - prs_align(ps); - smb_io_unistr2("uni_munged_dial ", &(usr->uni_munged_dial ), usr->hdr_munged_dial .buffer, ps, depth); /* worksations user can log on from */ - prs_align(ps); - - prs_uint32("unknown_6 ", ps, depth, &(usr->unknown_6 )); - prs_uint32("padding4 ", ps, depth, &(usr->padding4 )); - - if (usr->ptr_logon_hrs) - { - sam_io_logon_hrs("logon_hrs", &(usr->logon_hrs) , ps, depth); - prs_align(ps); + if(!smb_io_unistr2("uni_user_name ", &usr->uni_user_name, usr->hdr_user_name.buffer, ps, depth)) /* username unicode string */ + return False; + if(!smb_io_unistr2("uni_full_name ", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth)) /* user's full name unicode string */ + return False; + if(!smb_io_unistr2("uni_home_dir ", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth)) /* home directory unicode string */ + return False; + if(!smb_io_unistr2("uni_dir_drive ", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth)) /* home directory drive unicode string */ + return False; + if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth)) /* logon script unicode string */ + return False; + if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth)) /* profile path unicode string */ + return False; + if(!smb_io_unistr2("uni_acct_desc ", &usr->uni_acct_desc, usr->hdr_acct_desc.buffer, ps, depth)) /* user description unicode string */ + return False; + if(!smb_io_unistr2("uni_workstations", &usr->uni_workstations, usr->hdr_workstations.buffer, ps, depth)) /* worksations user can log on from */ + return False; + if(!smb_io_unistr2("uni_unknown_str ", &usr->uni_unknown_str, usr->hdr_unknown_str .buffer, ps, depth)) /* unknown string */ + return False; + if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial, usr->hdr_munged_dial .buffer, ps, depth)) /* worksations user can log on from */ + return False; + + if(!prs_uint32("unknown_6 ", ps, depth, &usr->unknown_6)) + return False; + if(!prs_uint32("padding4 ", ps, depth, &usr->padding4)) + return False; + + if (usr->ptr_logon_hrs) { + if(!sam_io_logon_hrs("logon_hrs", &usr->logon_hrs, ps, depth)) + return False; + if(!prs_align(ps)) + return False; } return True; } - /******************************************************************* -makes a SAMR_R_QUERY_USERINFO structure. + Inits a SAMR_R_QUERY_USERINFO structure. ********************************************************************/ -BOOL make_samr_r_query_userinfo(SAMR_R_QUERY_USERINFO *r_u, + +void init_samr_r_query_userinfo(SAMR_R_QUERY_USERINFO *r_u, uint16 switch_value, void *info, uint32 status) - { - if (r_u == NULL || info == NULL) return False; - - DEBUG(5,("make_samr_r_query_userinfo\n")); + DEBUG(5,("init_samr_r_query_userinfo\n")); r_u->ptr = 0; r_u->switch_value = 0; - if (status == 0) - { + if (status == 0) { r_u->switch_value = switch_value; - switch (switch_value) - { - case 0x10: - { - r_u->ptr = 1; - r_u->info.id10 = (SAM_USER_INFO_10*)info; - - break; - } - - case 0x11: - { - r_u->ptr = 1; - r_u->info.id11 = (SAM_USER_INFO_11*)info; - - break; - } - - case 21: - { - r_u->ptr = 1; - r_u->info.id21 = (SAM_USER_INFO_21*)info; - - break; - } - - case 23: - { - r_u->ptr = 1; - r_u->info.id23 = (SAM_USER_INFO_23*)info; - - break; - } + switch (switch_value) { + case 0x10: + r_u->ptr = 1; + r_u->info.id10 = (SAM_USER_INFO_10*)info; + break; - case 24: - { - r_u->ptr = 1; - r_u->info.id24 = (SAM_USER_INFO_24*)info; + case 0x11: + r_u->ptr = 1; + r_u->info.id11 = (SAM_USER_INFO_11*)info; + break; - break; - } + case 21: + r_u->ptr = 1; + r_u->info.id21 = (SAM_USER_INFO_21*)info; + break; - default: - { - DEBUG(4,("make_samr_r_query_userinfo: unsupported switch level\n")); - break; - } + default: + DEBUG(4,("init_samr_r_query_aliasinfo: unsupported switch level\n")); + break; } } r_u->status = status; /* return status */ - - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ + BOOL samr_io_r_query_userinfo(char *desc, SAMR_R_QUERY_USERINFO *r_u, prs_struct *ps, int depth) { - if (r_u == NULL) return False; + if (r_u == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_r_query_userinfo"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr ", ps, depth, &(r_u->ptr )); - prs_uint16("switch_value", ps, depth, &(r_u->switch_value)); - prs_align(ps); + if(!prs_uint32("ptr ", ps, depth, &r_u->ptr)) + return False; + if(!prs_uint16("switch_value", ps, depth, &r_u->switch_value)) + return False; + if(!prs_align(ps)) + return False; - if (r_u->ptr != 0 && r_u->switch_value != 0 && r_u->info.id != NULL) - { - switch (r_u->switch_value) - { - case 0x10: - { - if (r_u->info.id10 != NULL) - { - sam_io_user_info10("", r_u->info.id10, ps, depth); - } - else - { - DEBUG(2,("samr_io_r_query_userinfo: info pointer not initialised\n")); + if (r_u->ptr != 0 && r_u->switch_value != 0) { + switch (r_u->switch_value) { + case 0x10: + if (r_u->info.id10 != NULL) { + if(!sam_io_user_info10("", r_u->info.id10, ps, depth)) return False; - } - break; + } else { + DEBUG(2,("samr_io_r_query_userinfo: info pointer not initialised\n")); + return False; } + break; /* - case 0x11: - { - if (r_u->info.id11 != NULL) - { - sam_io_user_info11("", r_u->info.id11, ps, depth); - } - else - { - DEBUG(2,("samr_io_r_query_userinfo: info pointer not initialised\n")); - return False; - } - break; - } -*/ - case 21: - { - if (r_u->info.id21 != NULL) - { - sam_io_user_info21("", r_u->info.id21, ps, depth); - } - else - { - DEBUG(2,("samr_io_r_query_userinfo: info pointer not initialised\n")); - return False; - } - break; - } - case 23: - { - if (r_u->info.id23 != NULL) - { - sam_io_user_info23("", r_u->info.id23, ps, depth); - } - else - { - DEBUG(2,("samr_io_r_query_userinfo: info pointer not initialised\n")); - return False; - } - break; - } - case 24: - { - if (r_u->info.id24 != NULL) - { - sam_io_user_info24("", r_u->info.id24, ps, depth); - } - else - { - DEBUG(2,("samr_io_r_query_userinfo: info pointer not initialised\n")); + case 0x11: + if (r_u->info.id11 != NULL) { + if(!sam_io_user_info11("", r_u->info.id11, ps, depth)) return False; - } - break; - } - default: - { - DEBUG(2,("samr_io_r_query_userinfo: unknown switch level\n")); - break; - } - - } - } - - prs_uint32("status", ps, depth, &(r_u->status)); - - return True; -} - -/******************************************************************* -makes a SAMR_Q_SET_USERINFO structure. -********************************************************************/ -BOOL make_samr_q_set_userinfo(SAMR_Q_SET_USERINFO *q_u, - POLICY_HND *hnd, - uint16 switch_value, void *info) -{ - if (q_u == NULL || hnd == NULL) return False; - - DEBUG(5,("make_samr_q_set_userinfo\n")); - - memcpy(&(q_u->pol), hnd, sizeof(q_u->pol)); - q_u->switch_value = switch_value; - q_u->switch_value2 = switch_value; - q_u->info.id = info; - - switch (switch_value) - { - case 0x18: - { - uchar sess_key[16]; - if (!cli_get_usr_sesskey(hnd, sess_key)) - { + } else { + DEBUG(2,("samr_io_r_query_userinfo: info pointer not initialised\n")); return False; } - SamOEMhash(q_u->info.id24->pass, sess_key, 1); -#ifdef DEBUG_PASSWORD - dump_data(100, sess_key, 16); - dump_data(100, q_u->info.id24->pass, 516); -#endif break; - } - case 0x17: - { - uchar sess_key[16]; - if (!cli_get_usr_sesskey(hnd, sess_key)) - { +*/ + case 21: + if (r_u->info.id21 != NULL) { + if(!sam_io_user_info21("", r_u->info.id21, ps, depth)) + return False; + } else { + DEBUG(2,("samr_io_r_query_userinfo: info pointer not initialised\n")); return False; } - SamOEMhash(q_u->info.id23->pass, sess_key, 1); -#ifdef DEBUG_PASSWORD - dump_data(100, sess_key, 16); - dump_data(100, q_u->info.id23->pass, 516); -#endif break; - } default: - { - DEBUG(4,("make_samr_q_set_userinfo: unsupported switch level\n")); - return False; + DEBUG(2,("samr_io_r_query_userinfo: unknown switch level\n")); + break; } } + if(!prs_uint32("status", ps, depth, &r_u->status)) + return False; + return True; } - /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL samr_io_q_set_userinfo(char *desc, SAMR_Q_SET_USERINFO *q_u, prs_struct *ps, int depth) + +BOOL samr_io_q_unknown_32(char *desc, SAMR_Q_UNKNOWN_32 *q_u, prs_struct *ps, int depth) { - if (q_u == NULL) return False; + if (q_u == NULL) + return False; - prs_debug(ps, depth, desc, "samr_io_q_set_userinfo"); + prs_debug(ps, depth, desc, "samr_io_q_unknown_32"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_pol_hnd("pol", &(q_u->pol), ps, depth); - prs_align(ps); + if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth)) + return False; + if(!prs_align(ps)) + return False; - prs_uint16("switch_value ", ps, depth, &(q_u->switch_value )); - prs_uint16("switch_value2", ps, depth, &(q_u->switch_value2)); + if(!smb_io_unihdr ("", &q_u->hdr_mach_acct, ps, depth)) + return False; + if(!smb_io_unistr2("", &q_u->uni_mach_acct, q_u->hdr_mach_acct.buffer, ps, depth)) + return False; - prs_align(ps); - - switch (q_u->switch_value) - { - case 0: - { - break; - } - case 24: - { - if (ps->io) - { - /* reading */ - q_u->info.id = (SAM_USER_INFO_24*)Realloc(NULL, - sizeof(*q_u->info.id24)); - } - if (q_u->info.id == NULL) - { - DEBUG(2,("samr_io_q_query_userinfo: info pointer not initialised\n")); - return False; - } - sam_io_user_info24("", q_u->info.id24, ps, depth); - break; - } - case 23: - { - if (ps->io) - { - /* reading */ - q_u->info.id = (SAM_USER_INFO_23*)Realloc(NULL, - sizeof(*q_u->info.id23)); - } - if (q_u->info.id == NULL) - { - DEBUG(2,("samr_io_q_query_userinfo: info pointer not initialised\n")); - return False; - } - sam_io_user_info23("", q_u->info.id23, ps, depth); - break; - } - default: - { - DEBUG(2,("samr_io_q_query_userinfo: unknown switch level\n")); - break; - } - - } - prs_align(ps); + if(!prs_align(ps)) + return False; - if (!ps->io) - { - /* writing */ - free_samr_q_set_userinfo(q_u); - } + if(!prs_uint32("acct_ctrl", ps, depth, &q_u->acct_ctrl)) + return False; + if(!prs_uint16("unknown_1", ps, depth, &q_u->unknown_1)) + return False; + if(!prs_uint16("unknown_2", ps, depth, &q_u->unknown_2)) + return False; return True; } /******************************************************************* -frees a structure. + Reads or writes a structure. ********************************************************************/ -void free_samr_q_set_userinfo(SAMR_Q_SET_USERINFO *q_u) -{ - if (q_u->info.id == NULL) - { - free(q_u->info.id); - } - q_u->info.id = NULL; -} -/******************************************************************* -makes a SAMR_R_SET_USERINFO structure. -********************************************************************/ -BOOL make_samr_r_set_userinfo(SAMR_R_SET_USERINFO *r_u, uint32 status) - +BOOL samr_io_r_unknown_32(char *desc, SAMR_R_UNKNOWN_32 *r_u, prs_struct *ps, int depth) { - if (r_u == NULL) return False; + if (r_u == NULL) + return False; - DEBUG(5,("make_samr_r_set_userinfo\n")); + prs_debug(ps, depth, desc, "samr_io_r_unknown_32"); + depth++; - r_u->status = status; /* return status */ + if(!prs_align(ps)) + return False; + + if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth)) + return False; + if(!prs_align(ps)) + return False; + + if(!prs_uint32("status", ps, depth, &r_u->status)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Inits a SAMR_Q_CONNECT structure. ********************************************************************/ -BOOL samr_io_r_set_userinfo(char *desc, SAMR_R_SET_USERINFO *r_u, prs_struct *ps, int depth) -{ - if (r_u == NULL) return False; - prs_debug(ps, depth, desc, "samr_io_r_set_userinfo"); - depth++; +void init_samr_q_connect(SAMR_Q_CONNECT *q_u, + char *srv_name, uint32 unknown_0) +{ + int len_srv_name = strlen(srv_name); - prs_align(ps); + DEBUG(5,("init_q_connect\n")); - prs_uint32("status", ps, depth, &(r_u->status)); + /* make PDC server name \\server */ + q_u->ptr_srv_name = len_srv_name > 0 ? 1 : 0; + init_unistr2(&q_u->uni_srv_name, srv_name, len_srv_name+1); - return True; + /* example values: 0x0000 0002 */ + q_u->unknown_0 = unknown_0; } /******************************************************************* -makes a SAMR_Q_SET_USERINFO2 structure. + Reads or writes a structure. ********************************************************************/ -BOOL make_samr_q_set_userinfo2(SAMR_Q_SET_USERINFO2 *q_u, - POLICY_HND *hnd, - uint16 switch_value, void *info) + +BOOL samr_io_q_connect(char *desc, SAMR_Q_CONNECT *q_u, prs_struct *ps, int depth) { - if (q_u == NULL || hnd == NULL) return False; + if (q_u == NULL) + return False; - DEBUG(5,("make_samr_q_set_userinfo2\n")); + prs_debug(ps, depth, desc, "samr_io_q_connect"); + depth++; - memcpy(&(q_u->pol), hnd, sizeof(q_u->pol)); - q_u->switch_value = switch_value; - q_u->switch_value2 = switch_value; - q_u->info.id = info; + if(!prs_align(ps)) + return False; - switch (switch_value) - { - case 0x10: - { - break; - } - default: - { - DEBUG(4,("make_samr_q_set_userinfo2: unsupported switch level\n")); - return False; - } - } + if(!prs_uint32("ptr_srv_name", ps, depth, &q_u->ptr_srv_name)) + return False; + if(!smb_io_unistr2("", &q_u->uni_srv_name, q_u->ptr_srv_name, ps, depth)) + return False; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("unknown_0 ", ps, depth, &q_u->unknown_0)) + return False; return True; } - /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL samr_io_q_set_userinfo2(char *desc, SAMR_Q_SET_USERINFO2 *q_u, prs_struct *ps, int depth) + +BOOL samr_io_r_connect(char *desc, SAMR_R_CONNECT *r_u, prs_struct *ps, int depth) { - if (q_u == NULL) return False; + if (r_u == NULL) + return False; - prs_debug(ps, depth, desc, "samr_io_q_set_userinfo2"); + prs_debug(ps, depth, desc, "samr_io_r_connect"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_pol_hnd("pol", &(q_u->pol), ps, depth); - prs_align(ps); + if(!smb_io_pol_hnd("connect_pol", &r_u->connect_pol, ps, depth)) + return False; + if(!prs_align(ps)) + return False; - prs_uint16("switch_value ", ps, depth, &(q_u->switch_value )); - prs_uint16("switch_value2", ps, depth, &(q_u->switch_value2)); - - prs_align(ps); - - switch (q_u->switch_value) - { - case 0: - { - break; - } - case 16: - { - if (ps->io) - { - /* reading */ - q_u->info.id = (SAM_USER_INFO_16*)Realloc(NULL, - sizeof(*q_u->info.id16)); - } - if (q_u->info.id == NULL) - { - DEBUG(2,("samr_io_q_query_userinfo2: info pointer not initialised\n")); - return False; - } - sam_io_user_info16("", q_u->info.id16, ps, depth); - break; - } - default: - { - DEBUG(2,("samr_io_q_query_userinfo2: unknown switch level\n")); - break; - } - - } - prs_align(ps); - - if (!ps->io) - { - /* writing */ - free_samr_q_set_userinfo2(q_u); - } + if(!prs_uint32("status", ps, depth, &r_u->status)) + return False; return True; } /******************************************************************* -frees a structure. + Inits a SAMR_Q_CONNECT_ANON structure. ********************************************************************/ -void free_samr_q_set_userinfo2(SAMR_Q_SET_USERINFO2 *q_u) + +void init_samr_q_connect_anon(SAMR_Q_CONNECT_ANON *q_u) { - if (q_u->info.id == NULL) - { - free(q_u->info.id); - } - q_u->info.id = NULL; + DEBUG(5,("init_q_connect_anon\n")); + + q_u->ptr = 1; + q_u->unknown_0 = 0x5c; /* server name (?!!) */ + q_u->unknown_1 = 0x01; + q_u->unknown_2 = 0x20; } + /******************************************************************* -makes a SAMR_R_SET_USERINFO2 structure. + Reads or writes a structure. ********************************************************************/ -BOOL make_samr_r_set_userinfo2(SAMR_R_SET_USERINFO2 *r_u, - uint32 status) + +BOOL samr_io_q_connect_anon(char *desc, SAMR_Q_CONNECT_ANON *q_u, prs_struct *ps, int depth) { - if (r_u == NULL) return False; + if (q_u == NULL) + return False; - DEBUG(5,("make_samr_r_set_userinfo2\n")); + prs_debug(ps, depth, desc, "samr_io_q_connect_anon"); + depth++; - r_u->status = status; /* return status */ + if(!prs_align(ps)) + return False; + + if(!prs_uint32("ptr ", ps, depth, &q_u->ptr)) + return False; + if(!prs_uint16("unknown_0", ps, depth, &q_u->unknown_0)) + return False; + if(!prs_uint16("unknown_1", ps, depth, &q_u->unknown_1)) + return False; + if(!prs_uint32("unknown_2", ps, depth, &q_u->unknown_2)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL samr_io_r_set_userinfo2(char *desc, SAMR_R_SET_USERINFO2 *r_u, prs_struct *ps, int depth) + +BOOL samr_io_r_connect_anon(char *desc, SAMR_R_CONNECT_ANON *r_u, prs_struct *ps, int depth) { - if (r_u == NULL) return False; + if (r_u == NULL) + return False; - prs_debug(ps, depth, desc, "samr_io_r_set_userinfo2"); + prs_debug(ps, depth, desc, "samr_io_r_connect_anon"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; + + if(!smb_io_pol_hnd("connect_pol", &r_u->connect_pol, ps, depth)) + return False; + if(!prs_align(ps)) + return False; - prs_uint32("status", ps, depth, &(r_u->status)); + if(!prs_uint32("status", ps, depth, &r_u->status)) + return False; return True; } /******************************************************************* -makes a SAMR_Q_CONNECT structure. + Inits a SAMR_Q_OPEN_ALIAS structure. ********************************************************************/ -BOOL make_samr_q_connect(SAMR_Q_CONNECT *q_u, - const char *srv_name, uint32 unknown_0) +void init_samr_q_open_alias(SAMR_Q_OPEN_ALIAS *q_u, + uint32 unknown_0, uint32 rid) { - int len_srv_name = strlen(srv_name); + DEBUG(5,("init_q_open_alias\n")); - if (q_u == NULL) return False; - - DEBUG(5,("make_samr_q_connect\n")); - - /* make PDC server name \\server */ - q_u->ptr_srv_name = len_srv_name > 0 ? 1 : 0; - make_unistr2(&(q_u->uni_srv_name), srv_name, len_srv_name+1); - - /* example values: 0x0000 0002 */ + /* example values: 0x0000 0008 */ q_u->unknown_0 = unknown_0; - return True; + q_u->rid_alias = rid; } - /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL samr_io_q_connect(char *desc, SAMR_Q_CONNECT *q_u, prs_struct *ps, int depth) + +BOOL samr_io_q_open_alias(char *desc, SAMR_Q_OPEN_ALIAS *q_u, prs_struct *ps, int depth) { - if (q_u == NULL) return False; + if (q_u == NULL) + return False; - prs_debug(ps, depth, desc, "samr_io_q_connect"); + prs_debug(ps, depth, desc, "samr_io_q_open_alias"); depth++; - prs_align(ps); - - prs_uint32("ptr_srv_name", ps, depth, &(q_u->ptr_srv_name)); - smb_io_unistr2("", &(q_u->uni_srv_name), q_u->ptr_srv_name, ps, depth); - - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("unknown_0 ", ps, depth, &(q_u->unknown_0 )); + if(!prs_uint32("unknown_0", ps, depth, &q_u->unknown_0)) + return False; + if(!prs_uint32("rid_alias", ps, depth, &q_u->rid_alias)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL samr_io_r_connect(char *desc, SAMR_R_CONNECT *r_u, prs_struct *ps, int depth) + +BOOL samr_io_r_open_alias(char *desc, SAMR_R_OPEN_ALIAS *r_u, prs_struct *ps, int depth) { - if (r_u == NULL) return False; + if (r_u == NULL) + return False; - prs_debug(ps, depth, desc, "samr_io_r_connect"); + prs_debug(ps, depth, desc, "samr_io_r_open_alias"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_pol_hnd("connect_pol", &(r_u->connect_pol), ps, depth); - prs_align(ps); + if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth)) + return False; + if(!prs_align(ps)) + return False; - prs_uint32("status", ps, depth, &(r_u->status)); + if(!prs_uint32("status", ps, depth, &r_u->status)) + return False; return True; } /******************************************************************* -makes a SAMR_Q_CONNECT_ANON structure. + Inits a SAMR_Q_UNKNOWN_12 structure. ********************************************************************/ -BOOL make_samr_q_connect_anon(SAMR_Q_CONNECT_ANON *q_u) -{ - if (q_u == NULL) return False; - - DEBUG(5,("make_samr_q_connect_anon\n")); - q_u->ptr = 1; - q_u->unknown_0 = 0x5c; /* server name (?!!) */ - q_u->unknown_1 = 0x01; - q_u->unknown_2 = 0x20; - - return True; -} - - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL samr_io_q_connect_anon(char *desc, SAMR_Q_CONNECT_ANON *q_u, prs_struct *ps, int depth) +void init_samr_q_unknown_12(SAMR_Q_UNKNOWN_12 *q_u, + POLICY_HND *pol, uint32 rid, + uint32 num_gids, uint32 *gid) { - if (q_u == NULL) return False; + int i; - prs_debug(ps, depth, desc, "samr_io_q_connect_anon"); - depth++; + DEBUG(5,("init_samr_r_unknwon_12\n")); - prs_align(ps); + memcpy(&q_u->pol, pol, sizeof(*pol)); - prs_uint32("ptr ", ps, depth, &(q_u->ptr )); - prs_uint16("unknown_0", ps, depth, &(q_u->unknown_0)); - prs_uint16("unknown_1", ps, depth, &(q_u->unknown_1)); - prs_uint32("unknown_2", ps, depth, &(q_u->unknown_2)); + q_u->num_gids1 = num_gids; + q_u->rid = rid; + q_u->ptr = 0; + q_u->num_gids2 = num_gids; - return True; + for (i = 0; i < num_gids; i++) { + q_u->gid[i] = gid[i]; + } } /******************************************************************* -reads or writes a structure. + Inits a SAMR_Q_UNKNOWN_21 structure. ********************************************************************/ -BOOL samr_io_r_connect_anon(char *desc, SAMR_R_CONNECT_ANON *r_u, prs_struct *ps, int depth) + +void init_samr_q_unknown_21(SAMR_Q_UNKNOWN_21 *q_c, + POLICY_HND *hnd, uint16 unk_1, uint16 unk_2) { - if (r_u == NULL) return False; + DEBUG(5,("init_samr_q_unknown_21\n")); - prs_debug(ps, depth, desc, "samr_io_r_connect_anon"); - depth++; + memcpy(&q_c->group_pol, hnd, sizeof(q_c->group_pol)); + q_c->unknown_1 = unk_1; + q_c->unknown_2 = unk_2; +} - prs_align(ps); - smb_io_pol_hnd("connect_pol", &(r_u->connect_pol), ps, depth); - prs_align(ps); +/******************************************************************* + Inits a SAMR_Q_UNKNOWN_13 structure. +********************************************************************/ - prs_uint32("status", ps, depth, &(r_u->status)); +void init_samr_q_unknown_13(SAMR_Q_UNKNOWN_13 *q_c, + POLICY_HND *hnd, uint16 unk_1, uint16 unk_2) +{ + DEBUG(5,("init_samr_q_unknown_13\n")); - return True; + memcpy(&q_c->alias_pol, hnd, sizeof(q_c->alias_pol)); + q_c->unknown_1 = unk_1; + q_c->unknown_2 = unk_2; } /******************************************************************* -makes a SAMR_Q_UNKNOWN_38 structure. + Inits a SAMR_Q_UNKNOWN_38 structure. ********************************************************************/ -BOOL make_samr_q_unknown_38(SAMR_Q_UNKNOWN_38 *q_u, char *srv_name) +void init_samr_q_unknown_38(SAMR_Q_UNKNOWN_38 *q_u, char *srv_name) { int len_srv_name = strlen(srv_name); - if (q_u == NULL) return False; - - DEBUG(5,("make_samr_q_unknown_38\n")); + DEBUG(5,("init_q_unknown_38\n")); q_u->ptr = 1; - make_uni_hdr(&(q_u->hdr_srv_name), len_srv_name); - make_unistr2(&(q_u->uni_srv_name), srv_name, len_srv_name); - + init_uni_hdr(&q_u->hdr_srv_name, len_srv_name); + init_unistr2(&q_u->uni_srv_name, srv_name, len_srv_name); - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ + BOOL samr_io_q_unknown_38(char *desc, SAMR_Q_UNKNOWN_38 *q_u, prs_struct *ps, int depth) { - if (q_u == NULL) return False; + if (q_u == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_q_unknown_38"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr", ps, depth, &(q_u->ptr)); - if (q_u->ptr != 0) - { - smb_io_unihdr ("", &(q_u->hdr_srv_name), ps, depth); - smb_io_unistr2("", &(q_u->uni_srv_name), q_u->hdr_srv_name.buffer, ps, depth); - prs_align(ps); + if(!prs_uint32("ptr", ps, depth, &q_u->ptr)) + return False; + + if (q_u->ptr != 0) { + if(!smb_io_unihdr ("", &q_u->hdr_srv_name, ps, depth)) + return False; + if(!smb_io_unistr2("", &q_u->uni_srv_name, q_u->hdr_srv_name.buffer, ps, depth)) + return False; } return True; } /******************************************************************* -makes a SAMR_R_UNKNOWN_38 structure. + Inits a SAMR_R_UNKNOWN_38 structure. ********************************************************************/ -BOOL make_samr_r_unknown_38(SAMR_R_UNKNOWN_38 *r_u) -{ - if (r_u == NULL) return False; - DEBUG(5,("make_r_unknown_38\n")); +void init_samr_r_unknown_38(SAMR_R_UNKNOWN_38 *r_u) +{ + DEBUG(5,("init_r_unknown_38\n")); r_u->unk_0 = 0; r_u->unk_1 = 0; r_u->unk_2 = 0; r_u->unk_3 = 0; - - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ + BOOL samr_io_r_unknown_38(char *desc, SAMR_R_UNKNOWN_38 *r_u, prs_struct *ps, int depth) { - if (r_u == NULL) return False; + if (r_u == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_r_unknown_38"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint16("unk_0", ps, depth, &(r_u->unk_0)); - prs_align(ps); - prs_uint16("unk_1", ps, depth, &(r_u->unk_1)); - prs_align(ps); - prs_uint16("unk_2", ps, depth, &(r_u->unk_2)); - prs_align(ps); - prs_uint16("unk_3", ps, depth, &(r_u->unk_3)); - prs_align(ps); + if(!prs_uint16("unk_0", ps, depth, &r_u->unk_0)) + return False; + if(!prs_align(ps)) + return False; + if(!prs_uint16("unk_1", ps, depth, &r_u->unk_1)) + return False; + if(!prs_align(ps)) + return False; + if(!prs_uint16("unk_2", ps, depth, &r_u->unk_2)) + return False; + if(!prs_align(ps)) + return False; + if(!prs_uint16("unk_3", ps, depth, &r_u->unk_3)) + return False; + if(!prs_align(ps)) + return False; return True; } @@ -6143,69 +3441,74 @@ BOOL samr_io_r_unknown_38(char *desc, SAMR_R_UNKNOWN_38 *r_u, prs_struct *ps, i /******************************************************************* make a SAMR_ENC_PASSWD structure. ********************************************************************/ -BOOL make_enc_passwd(SAMR_ENC_PASSWD *pwd, char pass[512]) -{ - if (pwd == NULL) return False; +void init_enc_passwd(SAMR_ENC_PASSWD *pwd, char pass[512]) +{ pwd->ptr = 1; memcpy(pwd->pass, pass, sizeof(pwd->pass)); - - return True; } /******************************************************************* -reads or writes a SAMR_ENC_PASSWD structure. + Reads or writes a SAMR_ENC_PASSWD structure. ********************************************************************/ + BOOL samr_io_enc_passwd(char *desc, SAMR_ENC_PASSWD *pwd, prs_struct *ps, int depth) { - if (pwd == NULL) return False; + if (pwd == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_enc_passwd"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr", ps, depth, &(pwd->ptr)); - prs_uint8s(False, "pwd", ps, depth, pwd->pass, sizeof(pwd->pass)); + if(!prs_uint32("ptr", ps, depth, &pwd->ptr)) + return False; + if(!prs_uint8s(False, "pwd", ps, depth, pwd->pass, sizeof(pwd->pass))) + return False; return True; } /******************************************************************* -makes a SAMR_ENC_HASH structure. + Inits a SAMR_ENC_HASH structure. ********************************************************************/ -BOOL make_enc_hash(SAMR_ENC_HASH *hsh, uchar hash[16]) -{ - if (hsh == NULL) return False; +void init_enc_hash(SAMR_ENC_HASH *hsh, uchar hash[16]) +{ hsh->ptr = 1; memcpy(hsh->hash, hash, sizeof(hsh->hash)); - - return True; } /******************************************************************* -reads or writes a SAMR_ENC_HASH structure. + Reads or writes a SAMR_ENC_HASH structure. ********************************************************************/ + BOOL samr_io_enc_hash(char *desc, SAMR_ENC_HASH *hsh, prs_struct *ps, int depth) { - if (hsh == NULL) return False; + if (hsh == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_enc_hash"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr ", ps, depth, &(hsh->ptr)); - prs_uint8s(False, "hash", ps, depth, hsh->hash, sizeof(hsh->hash)); + if(!prs_uint32("ptr ", ps, depth, &hsh->ptr)) + return False; + if(!prs_uint8s(False, "hash", ps, depth, hsh->hash, sizeof(hsh->hash))) + return False; return True; } /******************************************************************* -makes a SAMR_R_UNKNOWN_38 structure. + Inits a SAMR_R_UNKNOWN_38 structure. ********************************************************************/ -BOOL make_samr_q_chgpasswd_user(SAMR_Q_CHGPASSWD_USER *q_u, + +void init_samr_q_chgpasswd_user(SAMR_Q_CHGPASSWD_USER *q_u, char *dest_host, char *user_name, char nt_newpass[516], uchar nt_oldhash[16], char lm_newpass[516], uchar lm_oldhash[16]) @@ -6213,89 +3516,94 @@ BOOL make_samr_q_chgpasswd_user(SAMR_Q_CHGPASSWD_USER *q_u, int len_dest_host = strlen(dest_host); int len_user_name = strlen(user_name); - if (q_u == NULL) return False; - - DEBUG(5,("make_samr_q_chgpasswd_user\n")); + DEBUG(5,("init_samr_q_chgpasswd_user\n")); q_u->ptr_0 = 1; - make_uni_hdr(&(q_u->hdr_dest_host), len_dest_host); - make_unistr2(&(q_u->uni_dest_host), dest_host, len_dest_host); - make_uni_hdr(&(q_u->hdr_user_name), len_user_name); - make_unistr2(&(q_u->uni_user_name), user_name, len_user_name); + init_uni_hdr(&q_u->hdr_dest_host, len_dest_host); + init_unistr2(&q_u->uni_dest_host, dest_host, len_dest_host); + init_uni_hdr(&q_u->hdr_user_name, len_user_name); + init_unistr2(&q_u->uni_user_name, user_name, len_user_name); - make_enc_passwd(&(q_u->nt_newpass), nt_newpass); - make_enc_hash (&(q_u->nt_oldhash), nt_oldhash); + init_enc_passwd(&q_u->nt_newpass, nt_newpass); + init_enc_hash(&q_u->nt_oldhash, nt_oldhash); q_u->unknown = 0x01; - make_enc_passwd(&(q_u->lm_newpass), lm_newpass); - make_enc_hash (&(q_u->lm_oldhash), lm_oldhash); - - return True; + init_enc_passwd(&q_u->lm_newpass, lm_newpass); + init_enc_hash (&q_u->lm_oldhash, lm_oldhash); } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ + BOOL samr_io_q_chgpasswd_user(char *desc, SAMR_Q_CHGPASSWD_USER *q_u, prs_struct *ps, int depth) { - if (q_u == NULL) return False; + if (q_u == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_q_chgpasswd_user"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr_0", ps, depth, &(q_u->ptr_0)); + if(!prs_uint32("ptr_0", ps, depth, &q_u->ptr_0)) + return False; - smb_io_unihdr ("", &(q_u->hdr_dest_host), ps, depth); - smb_io_unistr2("", &(q_u->uni_dest_host), q_u->hdr_dest_host.buffer, ps, depth); - prs_align(ps); + if(!smb_io_unihdr ("", &q_u->hdr_dest_host, ps, depth)) + return False; + if(!smb_io_unistr2("", &q_u->uni_dest_host, q_u->hdr_dest_host.buffer, ps, depth)) + return False; + if(!smb_io_unihdr ("", &q_u->hdr_user_name, ps, depth)) + return False; + if(!smb_io_unistr2("", &q_u->uni_user_name, q_u->hdr_user_name.buffer, ps, depth)) + return False; - smb_io_unihdr ("", &(q_u->hdr_user_name), ps, depth); - smb_io_unistr2("", &(q_u->uni_user_name), q_u->hdr_user_name.buffer, ps, depth); - prs_align(ps); + if(!samr_io_enc_passwd("nt_newpass", &q_u->nt_newpass, ps, depth)) + return False; + if(!samr_io_enc_hash ("nt_oldhash", &q_u->nt_oldhash, ps, depth)) + return False; - samr_io_enc_passwd("nt_newpass", &(q_u->nt_newpass), ps, depth); - samr_io_enc_hash ("nt_oldhash", &(q_u->nt_oldhash), ps, depth); + if(!prs_uint32("unknown", ps, depth, &q_u->unknown)) + return False; - prs_uint32("unknown", ps, depth, &(q_u->unknown)); - - samr_io_enc_passwd("lm_newpass", &(q_u->lm_newpass), ps, depth); - samr_io_enc_hash ("lm_oldhash", &(q_u->lm_oldhash), ps, depth); + if(!samr_io_enc_passwd("lm_newpass", &q_u->lm_newpass, ps, depth)) + return False; + if(!samr_io_enc_hash("lm_oldhash", &q_u->lm_oldhash, ps, depth)) + return False; return True; } /******************************************************************* -makes a SAMR_R_CHGPASSWD_USER structure. + Inits a SAMR_R_CHGPASSWD_USER structure. ********************************************************************/ -BOOL make_samr_r_chgpasswd_user(SAMR_R_CHGPASSWD_USER *r_u, uint32 status) -{ - if (r_u == NULL) return False; - DEBUG(5,("make_r_chgpasswd_user\n")); +void init_samr_r_chgpasswd_user(SAMR_R_CHGPASSWD_USER *r_u, uint32 status) +{ + DEBUG(5,("init_r_chgpasswd_user\n")); r_u->status = status; - - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ + BOOL samr_io_r_chgpasswd_user(char *desc, SAMR_R_CHGPASSWD_USER *r_u, prs_struct *ps, int depth) { - if (r_u == NULL) return False; + if (r_u == NULL) + return False; prs_debug(ps, depth, desc, "samr_io_r_chgpasswd_user"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("status", ps, depth, &(r_u->status)); + if(!prs_uint32("status", ps, depth, &r_u->status)) + return False; return True; } - - diff --git a/source3/rpc_parse/parse_sec.c b/source3/rpc_parse/parse_sec.c index d4f4f8185f..541949e51e 100644 --- a/source3/rpc_parse/parse_sec.c +++ b/source3/rpc_parse/parse_sec.c @@ -2,10 +2,10 @@ * Unix SMB/Netbios implementation. * Version 1.9. * RPC Pipe client / server routines - * Copyright (C) Andrew Tridgell 1992-1999, - * Copyright (C) Jeremy R. Allison 1995-1999 - * Copyright (C) Luke Kenneth Casson Leighton 1996-1999, - * Copyright (C) Paul Ashton 1997-1999. + * Copyright (C) Andrew Tridgell 1992-1998, + * Copyright (C) Jeremy R. Allison 1995-1998 + * Copyright (C) Luke Kenneth Casson Leighton 1996-1998, + * Copyright (C) Paul Ashton 1997-1998. * * 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 @@ -27,505 +27,593 @@ extern int DEBUGLEVEL; +#define SD_HEADER_SIZE 0x14 /******************************************************************* -makes a structure. + Sets up a SEC_ACCESS structure. ********************************************************************/ -BOOL make_sec_access(SEC_ACCESS *t, uint32 mask) + +void init_sec_access(SEC_ACCESS *t, uint32 mask) { t->mask = mask; - - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a SEC_ACCESS structure. ********************************************************************/ + BOOL sec_io_access(char *desc, SEC_ACCESS *t, prs_struct *ps, int depth) { - if (t == NULL) return False; + if (t == NULL) + return False; prs_debug(ps, depth, desc, "sec_io_access"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("mask", ps, depth, &(t->mask)); + if(!prs_uint32("mask", ps, depth, &(t->mask))) + return False; return True; } /******************************************************************* -makes a structure. + Sets up a SEC_ACE structure. ********************************************************************/ -BOOL make_sec_ace(SEC_ACE *t, DOM_SID *sid, uint8 type, SEC_ACCESS mask, uint8 flag) + +void init_sec_ace(SEC_ACE *t, DOM_SID *sid, uint8 type, SEC_ACCESS mask, uint8 flag) { t->type = type; t->flags = flag; t->size = sid_size(sid) + 8; t->info = mask; + ZERO_STRUCTP(&t->sid); sid_copy(&t->sid, sid); - - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a SEC_ACE structure. ********************************************************************/ -BOOL sec_io_ace(char *desc, SEC_ACE *t, prs_struct *ps, int depth) + +BOOL sec_io_ace(char *desc, SEC_ACE *psa, prs_struct *ps, int depth) { uint32 old_offset; uint32 offset_ace_size; - if (t == NULL) return False; + + if (psa == NULL) + return False; prs_debug(ps, depth, desc, "sec_io_ace"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - old_offset = ps->offset; + old_offset = prs_offset(ps); + + if(!prs_uint8("type ", ps, depth, &psa->type)) + return False; + + if(!prs_uint8("flags", ps, depth, &psa->flags)) + return False; - prs_uint8 ("type ", ps, depth, &(t->type)); - prs_uint8 ("flags", ps, depth, &(t->flags)); - prs_uint16_pre("size ", ps, depth, &(t->size ), &offset_ace_size); + if(!prs_uint16_pre("size ", ps, depth, &psa->size, &offset_ace_size)) + return False; + + if(!sec_io_access("info ", &psa->info, ps, depth)) + return False; - sec_io_access ("info ", &t->info, ps, depth); - prs_align(ps); - smb_io_dom_sid("sid ", &t->sid , ps, depth); - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint16_post("size ", ps, depth, &t->size, offset_ace_size, old_offset); + if(!smb_io_dom_sid("sid ", &psa->sid , ps, depth)) + return False; + + if(!prs_uint16_post("size ", ps, depth, &psa->size, offset_ace_size, old_offset)) + return False; return True; } /******************************************************************* -makes a structure. + Create a SEC_ACL structure. ********************************************************************/ -BOOL make_sec_acl(SEC_ACL *t, uint16 revision, int num_aces, SEC_ACE *ace) + +SEC_ACL *make_sec_acl(uint16 revision, int num_aces, SEC_ACE *ace_list) { + SEC_ACL *dst; int i; - t->revision = revision; - t->num_aces = num_aces; - t->size = 4; - t->ace = ace; - - for (i = 0; i < num_aces; i++) - { - t->size += ace[i].size; + + if((dst = (SEC_ACL *)malloc(sizeof(SEC_ACL))) == NULL) + return NULL; + + ZERO_STRUCTP(dst); + + dst->revision = revision; + dst->num_aces = num_aces; + dst->size = 8; + + if((dst->ace_list = (SEC_ACE *)malloc( sizeof(SEC_ACE) * num_aces )) == NULL) { + free_sec_acl(&dst); + return NULL; } - return True; + for (i = 0; i < num_aces; i++) { + dst->ace_list[i] = ace_list[i]; /* Structure copy. */ + dst->size += ace_list[i].size; + } + + return dst; } /******************************************************************* -frees a structure. + Duplicate a SEC_ACL structure. ********************************************************************/ -void free_sec_acl(SEC_ACL *t) + +SEC_ACL *dup_sec_acl( SEC_ACL *src) { - if (t->ace != NULL) - { - free(t->ace); - } + if(src == NULL) + return NULL; + + return make_sec_acl( src->revision, src->num_aces, src->ace_list); } /******************************************************************* -reads or writes a structure. + Delete a SEC_ACL structure. +********************************************************************/ + +void free_sec_acl(SEC_ACL **ppsa) +{ + SEC_ACL *psa; -first of the xx_io_xx functions that allocates its data structures + if(ppsa == NULL || *ppsa == NULL) + return; + + psa = *ppsa; + if (psa->ace_list != NULL) + free(psa->ace_list); + + free(psa); + *ppsa = NULL; +} + +/******************************************************************* + Reads or writes a SEC_ACL structure. + + First of the xx_io_xx functions that allocates its data structures for you as it reads them. ********************************************************************/ -BOOL sec_io_acl(char *desc, SEC_ACL *t, prs_struct *ps, int depth) + +BOOL sec_io_acl(char *desc, SEC_ACL **ppsa, prs_struct *ps, int depth) { - uint32 i; + int i; uint32 old_offset; uint32 offset_acl_size; + SEC_ACL *psa; - if (t == NULL) return False; + if (ppsa == NULL) + return False; + + psa = *ppsa; + + if(UNMARSHALLING(ps) && psa == NULL) { + /* + * This is a read and we must allocate the stuct to read into. + */ + if((psa = (SEC_ACL *)malloc(sizeof(SEC_ACL))) == NULL) + return False; + ZERO_STRUCTP(psa); + *ppsa = psa; + } prs_debug(ps, depth, desc, "sec_io_acl"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - old_offset = ps->offset; + old_offset = prs_offset(ps); - prs_uint16("revision", ps, depth, &(t->revision)); - prs_uint16_pre("size ", ps, depth, &(t->size ), &offset_acl_size); - prs_uint32("num_aces ", ps, depth, &(t->num_aces )); + if(!prs_uint16("revision", ps, depth, &psa->revision)) + return False; - if (ps->io && t->num_aces != 0) - { - /* reading */ - t->ace = (SEC_ACE*)malloc(sizeof(t->ace[0]) * t->num_aces); - ZERO_STRUCTP(t->ace); - } + if(!prs_uint16_pre("size ", ps, depth, &psa->size, &offset_acl_size)) + return False; - if (t->ace == NULL && t->num_aces != 0) - { - DEBUG(0,("INVALID ACL\n")); - ps->offset = 0xfffffffe; + if(!prs_uint32("num_aces ", ps, depth, &psa->num_aces)) return False; + + if (UNMARSHALLING(ps) && psa->num_aces != 0) { + /* reading */ + if((psa->ace_list = malloc(sizeof(psa->ace_list[0]) * psa->num_aces)) == NULL) + return False; + ZERO_STRUCTP(psa->ace_list); } - for (i = 0; i < MIN(t->num_aces, MAX_SEC_ACES); i++) - { + for (i = 0; i < psa->num_aces; i++) { fstring tmp; - slprintf(tmp, sizeof(tmp)-1, "ace[%02d]: ", i); - sec_io_ace(tmp, &t->ace[i], ps, depth); + slprintf(tmp, sizeof(tmp)-1, "ace_list[%02d]: ", i); + if(!sec_io_ace(tmp, &psa->ace_list[i], ps, depth)) + return False; } - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint16_post("size ", ps, depth, &t->size , offset_acl_size, old_offset); + if(!prs_uint16_post("size ", ps, depth, &psa->size, offset_acl_size, old_offset)) + return False; return True; } - /******************************************************************* -makes a structure + Creates a SEC_DESC structure ********************************************************************/ -int make_sec_desc(SEC_DESC *t, uint16 revision, uint16 type, + +SEC_DESC *make_sec_desc(uint16 revision, uint16 type, DOM_SID *owner_sid, DOM_SID *grp_sid, - SEC_ACL *sacl, SEC_ACL *dacl) + SEC_ACL *sacl, SEC_ACL *dacl, size_t *sec_desc_size) { + SEC_DESC *dst; uint32 offset; - t->revision = revision; - t->type = type; + *sec_desc_size = 0; + + if(( dst = (SEC_DESC *)malloc(sizeof(SEC_DESC))) == NULL) + return NULL; + + ZERO_STRUCTP(dst); + + dst->revision = revision; + dst->type = type; + + dst->off_owner_sid = 0; + dst->off_grp_sid = 0; + dst->off_sacl = 0; + dst->off_dacl = 0; + + if(owner_sid && ((dst->owner_sid = sid_dup(owner_sid)) == NULL)) + goto error_exit; - t->off_owner_sid = 0; - t->off_grp_sid = 0; - t->off_sacl = 0; - t->off_dacl = 0; + if(grp_sid && ((dst->grp_sid = sid_dup(grp_sid)) == NULL)) + goto error_exit; - t->dacl = dacl; - t->sacl = sacl; - t->owner_sid = owner_sid; - t->grp_sid = grp_sid; + if(sacl && ((dst->sacl = dup_sec_acl(sacl)) == NULL)) + goto error_exit; + if(dacl && ((dst->dacl = dup_sec_acl(dacl)) == NULL)) + goto error_exit; + offset = 0x0; - if (dacl != NULL) - { + /* + * Work out the linearization sizes. + */ + + if (dst->owner_sid != NULL) { + if (offset == 0) - { - offset = 0x14; - } - t->off_dacl = offset; - offset += dacl->size; + offset = SD_HEADER_SIZE; + + dst->off_owner_sid = offset; + offset += ((sid_size(dst->owner_sid) + 3) & ~3); } - if (sacl != NULL) - { + if (dst->grp_sid != NULL) { + if (offset == 0) - { - offset = 0x14; - } - t->off_dacl = offset; - offset += dacl->size; + offset = SD_HEADER_SIZE; + + dst->off_grp_sid = offset; + offset += ((sid_size(dst->grp_sid) + 3) & ~3); } - if (owner_sid != NULL) - { + if (dst->sacl != NULL) { + if (offset == 0) - { - offset = 0x14; - } - t->off_owner_sid = offset; - offset += sid_size(owner_sid); + offset = SD_HEADER_SIZE; + + dst->off_sacl = offset; + offset += ((sacl->size + 3) & ~3); } - if (grp_sid != NULL) - { + if (dst->dacl != NULL) { + if (offset == 0) - { - offset = 0x14; - } - t->off_grp_sid = offset; - offset += sid_size(grp_sid); + offset = SD_HEADER_SIZE; + + dst->off_dacl = offset; + offset += ((dacl->size + 3) & ~3); } - return (offset == 0) ? 0x14 : offset; + *sec_desc_size = (size_t)((offset == 0) ? SD_HEADER_SIZE : offset); + return dst; + +error_exit: + + *sec_desc_size = 0; + free_sec_desc(&dst); + return NULL; } +/******************************************************************* + Duplicate a SEC_DESC structure. +********************************************************************/ + +SEC_DESC *dup_sec_desc( SEC_DESC *src) +{ + size_t dummy; + + if(src == NULL) + return NULL; + + return make_sec_desc( src->revision, src->type, + src->owner_sid, src->grp_sid, src->sacl, + src->dacl, &dummy); +} /******************************************************************* -frees a structure + Deletes a SEC_DESC structure ********************************************************************/ -void free_sec_desc(SEC_DESC *t) + +void free_sec_desc(SEC_DESC **ppsd) { - if (t->dacl != NULL) - { - free_sec_acl(t->dacl); - } + SEC_DESC *psd; - if (t->sacl != NULL) - { - free_sec_acl(t->dacl); + if(ppsd == NULL || *ppsd == NULL) + return; - } + psd = *ppsd; - if (t->owner_sid != NULL) - { - free(t->owner_sid); - } + free_sec_acl(&psd->dacl); + free_sec_acl(&psd->dacl); + free(psd->owner_sid); + free(psd->grp_sid); + free(psd); + *ppsd = NULL; +} - if (t->grp_sid != NULL) - { - free(t->grp_sid); - } +/******************************************************************* + Creates a SEC_DESC structure with typical defaults. +********************************************************************/ + +SEC_DESC *make_standard_sec_desc(DOM_SID *owner_sid, DOM_SID *grp_sid, + SEC_ACL *dacl, size_t *sec_desc_size) +{ + return make_sec_desc(1, SEC_DESC_SELF_RELATIVE|SEC_DESC_DACL_PRESENT, + owner_sid, grp_sid, NULL, dacl, sec_desc_size); } /******************************************************************* -reads or writes a structure. + Reads or writes a SEC_DESC structure. + If reading and the *ppsd = NULL, allocates the structure. ********************************************************************/ -static BOOL sec_io_desc(char *desc, SEC_DESC *t, prs_struct *ps, int depth) + +BOOL sec_io_desc(char *desc, SEC_DESC **ppsd, prs_struct *ps, int depth) { -#if 0 - uint32 off_owner_sid; - uint32 off_grp_sid ; - uint32 off_sacl ; - uint32 off_dacl ; -#endif uint32 old_offset; uint32 max_offset = 0; /* after we're done, move offset to end */ + SEC_DESC *psd; + + if (ppsd == NULL) + return False; - if (t == NULL) return False; + psd = *ppsd; + + if(UNMARSHALLING(ps) && psd == NULL) { + if((psd = (SEC_DESC *)malloc(sizeof(SEC_DESC))) == NULL) + return False; + ZERO_STRUCTP(psd); + *ppsd = psd; + } prs_debug(ps, depth, desc, "sec_io_desc"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; /* start of security descriptor stored for back-calc offset purposes */ - old_offset = ps->offset; - - prs_uint16("revision ", ps, depth, &(t->revision )); - prs_uint16("type ", ps, depth, &(t->type )); - - prs_uint32("off_owner_sid", ps, depth, &(t->off_owner_sid)); - prs_uint32("off_grp_sid ", ps, depth, &(t->off_grp_sid )); - prs_uint32("off_sacl ", ps, depth, &(t->off_sacl )); - prs_uint32("off_dacl ", ps, depth, &(t->off_dacl )); -#if 0 - prs_uint32_pre("off_owner_sid", ps, depth, &(t->off_owner_sid), &off_owner_sid); - prs_uint32_pre("off_grp_sid ", ps, depth, &(t->off_grp_sid ), &off_grp_sid ); - prs_uint32_pre("off_sacl ", ps, depth, &(t->off_sacl ), &off_sacl ); - prs_uint32_pre("off_dacl ", ps, depth, &(t->off_dacl ), &off_dacl ); -#endif - max_offset = MAX(max_offset, ps->offset); - - if (IS_BITS_SET_ALL(t->type, SEC_DESC_DACL_PRESENT)) - { -#if 0 - prs_uint32_post("off_dacl ", ps, depth, &(t->off_dacl ), off_dacl , ps->offset - old_offset); -#endif - ps->offset = old_offset + t->off_dacl; - if (ps->io) - { - /* reading */ - t->dacl = (SEC_ACL*)malloc(sizeof(*t->dacl)); - ZERO_STRUCTP(t->dacl); - } + old_offset = prs_offset(ps); - if (t->dacl == NULL) - { - DEBUG(0,("INVALID DACL\n")); - ps->offset = 0xfffffffe; - return False; - } + if(!prs_uint16("revision ", ps, depth, &psd->revision)) + return False; - sec_io_acl ("dacl" , t->dacl , ps, depth); - prs_align(ps); - } -#if 0 - else - { - prs_uint32_post("off_dacl ", ps, depth, &(t->off_dacl ), off_dacl , 0); - } -#endif - - max_offset = MAX(max_offset, ps->offset); - - if (IS_BITS_SET_ALL(t->type, SEC_DESC_SACL_PRESENT)) - { -#if 0 - prs_uint32_post("off_sacl ", ps, depth, &(t->off_sacl ), off_sacl , ps->offset - old_offset); -#endif - ps->offset = old_offset + t->off_sacl; - if (ps->io) - { - /* reading */ - t->sacl = (SEC_ACL*)malloc(sizeof(*t->sacl)); - ZERO_STRUCTP(t->sacl); - } + if(!prs_uint16("type ", ps, depth, &psd->type)) + return False; - if (t->sacl == NULL) - { - DEBUG(0,("INVALID SACL\n")); - ps->offset = 0xfffffffe; - return False; - } + if(!prs_uint32("off_owner_sid", ps, depth, &psd->off_owner_sid)) + return False; - sec_io_acl ("sacl" , t->sacl , ps, depth); - prs_align(ps); - } -#if 0 - else - { - prs_uint32_post("off_sacl ", ps, depth, &(t->off_sacl ), off_sacl , 0); - } -#endif - - max_offset = MAX(max_offset, ps->offset); - -#if 0 - prs_uint32_post("off_owner_sid", ps, depth, &(t->off_owner_sid), off_owner_sid, ps->offset - old_offset); -#endif - if (t->off_owner_sid != 0) - { - if (ps->io) - { - ps->offset = old_offset + t->off_owner_sid; - } - if (ps->io) - { + if(!prs_uint32("off_grp_sid ", ps, depth, &psd->off_grp_sid)) + return False; + + if(!prs_uint32("off_sacl ", ps, depth, &psd->off_sacl)) + return False; + + if(!prs_uint32("off_dacl ", ps, depth, &psd->off_dacl)) + return False; + + max_offset = MAX(max_offset, prs_offset(ps)); + + if (psd->off_owner_sid != 0) { + + if (UNMARSHALLING(ps)) { + if(!prs_set_offset(ps, old_offset + psd->off_owner_sid)) + return False; /* reading */ - t->owner_sid = (DOM_SID*)malloc(sizeof(*t->owner_sid)); - ZERO_STRUCTP(t->owner_sid); + if((psd->owner_sid = malloc(sizeof(*psd->owner_sid))) == NULL) + return False; + ZERO_STRUCTP(psd->owner_sid); } - if (t->owner_sid == NULL) - { - DEBUG(0,("INVALID OWNER SID\n")); - ps->offset = 0xfffffffe; + if(!smb_io_dom_sid("owner_sid ", psd->owner_sid , ps, depth)) + return False; + if(!prs_align(ps)) return False; - } - - smb_io_dom_sid("owner_sid ", t->owner_sid , ps, depth); - prs_align(ps); } - max_offset = MAX(max_offset, ps->offset); + max_offset = MAX(max_offset, prs_offset(ps)); -#if 0 - prs_uint32_post("off_grp_sid ", ps, depth, &(t->off_grp_sid ), off_grp_sid , ps->offset - old_offset); -#endif - if (t->off_grp_sid != 0) - { - if (ps->io) - { - ps->offset = old_offset + t->off_grp_sid; + if (psd->off_grp_sid != 0) { - } - if (ps->io) - { + if (UNMARSHALLING(ps)) { /* reading */ - t->grp_sid = (DOM_SID*)malloc(sizeof(*t->grp_sid)); - ZERO_STRUCTP(t->grp_sid); + if(!prs_set_offset(ps, old_offset + psd->off_grp_sid)) + return False; + if((psd->grp_sid = malloc(sizeof(*psd->grp_sid))) == NULL) + return False; + ZERO_STRUCTP(psd->grp_sid); } - if (t->grp_sid == NULL) - { - DEBUG(0,("INVALID GROUP SID\n")); - ps->offset = 0xfffffffe; + if(!smb_io_dom_sid("grp_sid", psd->grp_sid, ps, depth)) return False; - } + if(!prs_align(ps)) + return False; + } + + max_offset = MAX(max_offset, prs_offset(ps)); - smb_io_dom_sid("grp_sid", t->grp_sid, ps, depth); - prs_align(ps); + if (IS_BITS_SET_ALL(psd->type, SEC_DESC_SACL_PRESENT) && psd->off_sacl) { + if(!prs_set_offset(ps, old_offset + psd->off_sacl)) + return False; + if(!sec_io_acl("sacl", &psd->sacl, ps, depth)) + return False; + if(!prs_align(ps)) + return False; } - max_offset = MAX(max_offset, ps->offset); + max_offset = MAX(max_offset, prs_offset(ps)); + + if (IS_BITS_SET_ALL(psd->type, SEC_DESC_DACL_PRESENT) && psd->off_dacl != 0) { + if(!prs_set_offset(ps, old_offset + psd->off_dacl)) + return False; + if(!sec_io_acl("dacl", &psd->dacl, ps, depth)) + return False; + if(!prs_align(ps)) + return False; + } - ps->offset = max_offset; + max_offset = MAX(max_offset, prs_offset(ps)); + if(!prs_set_offset(ps, max_offset)) + return False; return True; } /******************************************************************* -creates a SEC_DESC_BUF structure. + Creates a SEC_DESC_BUF structure. ********************************************************************/ -BOOL make_sec_desc_buf(SEC_DESC_BUF *buf, int len, SEC_DESC *data) + +SEC_DESC_BUF *make_sec_desc_buf(int len, SEC_DESC *sec_desc) { - ZERO_STRUCTP(buf); + SEC_DESC_BUF *dst; + + if((dst = (SEC_DESC_BUF *)malloc(sizeof(SEC_DESC_BUF))) == NULL) + return NULL; + + ZERO_STRUCTP(dst); /* max buffer size (allocated size) */ - buf->max_len = len; - buf->undoc = 0; - buf->len = data != NULL ? len : 0; - buf->sec = data; + dst->max_len = len; + dst->len = len; - return True; + if(sec_desc && ((dst->sec = dup_sec_desc(sec_desc)) == NULL)) { + free_sec_desc_buf(&dst); + return NULL; + } + + return dst; } /******************************************************************* -frees a SEC_DESC_BUF structure. + Duplicates a SEC_DESC_BUF structure. ********************************************************************/ -void free_sec_desc_buf(SEC_DESC_BUF *buf) + +SEC_DESC_BUF *dup_sec_desc_buf(SEC_DESC_BUF *src) { - if (buf->sec != NULL) - { - free_sec_desc(buf->sec); - free(buf->sec); - } + if(src == NULL) + return NULL; + + return make_sec_desc_buf( src->len, src->sec); +} + +/******************************************************************* + Deletes a SEC_DESC_BUF structure. +********************************************************************/ + +void free_sec_desc_buf(SEC_DESC_BUF **ppsdb) +{ + SEC_DESC_BUF *psdb; + + if(ppsdb == NULL || *ppsdb == NULL) + return; + + psdb = *ppsdb; + free_sec_desc(&psdb->sec); + free(psdb); + *ppsdb = NULL; } /******************************************************************* -reads or writes a SEC_DESC_BUF structure. + Reads or writes a SEC_DESC_BUF structure. ********************************************************************/ -BOOL sec_io_desc_buf(char *desc, SEC_DESC_BUF *sec, prs_struct *ps, int depth) + +BOOL sec_io_desc_buf(char *desc, SEC_DESC_BUF **ppsdb, prs_struct *ps, int depth) { uint32 off_len; uint32 off_max_len; uint32 old_offset; uint32 size; + SEC_DESC_BUF *psdb; + + if (ppsdb == NULL) + return False; - if (sec == NULL) return False; + psdb = *ppsdb; + + if (UNMARSHALLING(ps) && psdb == NULL) { + if((psdb = (SEC_DESC_BUF *)malloc(sizeof(SEC_DESC_BUF))) == NULL) + return False; + ZERO_STRUCTP(psdb); + *ppsdb = psdb; + } prs_debug(ps, depth, desc, "sec_io_desc_buf"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32_pre("max_len", ps, depth, &(sec->max_len), &off_max_len); - prs_uint32 ("undoc ", ps, depth, &(sec->undoc )); - prs_uint32_pre("len ", ps, depth, &(sec->len ), &off_len); + if(!prs_uint32_pre("max_len", ps, depth, &psdb->max_len, &off_max_len)) + return False; - old_offset = ps->offset; + if(!prs_uint32 ("undoc ", ps, depth, &psdb->undoc)) + return False; - if (sec->len != 0 && ps->io) - { - /* reading */ - sec->sec = (SEC_DESC*)malloc(sizeof(*sec->sec)); - ZERO_STRUCTP(sec->sec); + if(!prs_uint32_pre("len ", ps, depth, &psdb->len, &off_len)) + return False; - if (sec->sec == NULL) - { - DEBUG(0,("INVALID SEC_DESC\n")); - ps->offset = 0xfffffffe; - return False; - } - } + old_offset = prs_offset(ps); /* reading, length is non-zero; writing, descriptor is non-NULL */ - if ((sec->len != 0 || (!ps->io)) && sec->sec != NULL) - { - sec_io_desc("sec ", sec->sec, ps, depth); + if ((psdb->len != 0 || MARSHALLING(ps)) && psdb->sec != NULL) { + if(!sec_io_desc("sec ", &psdb->sec, ps, depth)) + return False; } - prs_align(ps); - - size = ps->offset - old_offset; - prs_uint32_post("max_len", ps, depth, &(sec->max_len), off_max_len, size == 0 ? sec->max_len : size + 8); - prs_uint32_post("len ", ps, depth, &(sec->len ), off_len , size == 0 ? 0 : size + 8); + size = prs_offset(ps) - old_offset; + if(!prs_uint32_post("max_len", ps, depth, &psdb->max_len, off_max_len, size == 0 ? psdb->max_len : size)) + return False; + + if(!prs_uint32_post("len ", ps, depth, &psdb->len, off_len, size)) + return False; return True; } - diff --git a/source3/rpc_parse/parse_srv.c b/source3/rpc_parse/parse_srv.c index 63d27c8c91..8997b05e0b 100644 --- a/source3/rpc_parse/parse_srv.c +++ b/source3/rpc_parse/parse_srv.c @@ -3,9 +3,10 @@ * Unix SMB/Netbios implementation. * Version 1.9. * RPC Pipe client / server routines - * Copyright (C) Andrew Tridgell 1992-1999, - * Copyright (C) Luke Kenneth Casson Leighton 1996-1999, - * Copyright (C) Paul Ashton 1997-1999. + * Copyright (C) Andrew Tridgell 1992-1997, + * Copyright (C) Luke Kenneth Casson Leighton 1996-1997, + * Copyright (C) Paul Ashton 1997. + * Copyright (C) Jeremy Allison 1999. * * 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 @@ -27,39 +28,37 @@ extern int DEBUGLEVEL; - /******************************************************************* - makes a SH_INFO_1_STR structure + Inits a SH_INFO_1_STR structure ********************************************************************/ -BOOL make_srv_share_info1_str(SH_INFO_1_STR *sh1, char *net_name, char *remark) -{ - if (sh1 == NULL) return False; - - DEBUG(5,("make_srv_share_info1_str\n")); - make_unistr2(&(sh1->uni_netname), net_name, strlen(net_name)+1); - make_unistr2(&(sh1->uni_remark ), remark , strlen(remark )+1); +void init_srv_share_info1_str(SH_INFO_1_STR *sh1, char *net_name, char *remark) +{ + DEBUG(5,("init_srv_share_info1_str\n")); - return True; + init_unistr2(&sh1->uni_netname, net_name, strlen(net_name)+1); + init_unistr2(&sh1->uni_remark, remark, strlen(remark)+1); } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -static BOOL srv_io_share_info1_str(char *desc, SH_INFO_1_STR *sh1, prs_struct *ps, int depth) + +static BOOL srv_io_share_info1_str(char *desc, SH_INFO_1_STR *sh1, prs_struct *ps, int depth) { - if (sh1 == NULL) return False; + if (sh1 == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_share_info1_str"); depth++; - prs_align(ps); - - smb_io_unistr2("", &(sh1->uni_netname), True, ps, depth); - prs_align(ps); - smb_io_unistr2("", &(sh1->uni_remark ), True, ps, depth); - prs_align(ps); + if(!prs_align(ps)) + return False; + if(!smb_io_unistr2("", &sh1->uni_netname, True, ps, depth)) + return False; + if(!smb_io_unistr2("", &sh1->uni_remark, True, ps, depth)) + return False; return True; } @@ -67,612 +66,768 @@ static BOOL srv_io_share_info1_str(char *desc, SH_INFO_1_STR *sh1, prs_struct * /******************************************************************* makes a SH_INFO_1 structure ********************************************************************/ -BOOL make_srv_share_info1(SH_INFO_1 *sh1, char *net_name, uint32 type, char *remark) -{ - if (sh1 == NULL) return False; - DEBUG(5,("make_srv_share_info1: %s %8x %s\n", net_name, type, remark)); +void init_srv_share_info1(SH_INFO_1 *sh1, char *net_name, uint32 type, char *remark) +{ + DEBUG(5,("init_srv_share_info1: %s %8x %s\n", net_name, type, remark)); - sh1->ptr_netname = net_name != NULL ? 1 : 0; + sh1->ptr_netname = (net_name != NULL) ? 1 : 0; sh1->type = type; - sh1->ptr_remark = remark != NULL ? 1 : 0; - - return True; + sh1->ptr_remark = (remark != NULL) ? 1 : 0; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -static BOOL srv_io_share_info1(char *desc, SH_INFO_1 *sh1, prs_struct *ps, int depth) + +static BOOL srv_io_share_info1(char *desc, SH_INFO_1 *sh1, prs_struct *ps, int depth) { - if (sh1 == NULL) return False; + if (sh1 == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_share_info1"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr_netname", ps, depth, &(sh1->ptr_netname)); - prs_uint32("type ", ps, depth, &(sh1->type )); - prs_uint32("ptr_remark ", ps, depth, &(sh1->ptr_remark)); + if(!prs_uint32("ptr_netname", ps, depth, &sh1->ptr_netname)) + return False; + if(!prs_uint32("type ", ps, depth, &sh1->type)) + return False; + if(!prs_uint32("ptr_remark ", ps, depth, &sh1->ptr_remark)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Inits a SH_INFO_2_STR structure ********************************************************************/ -static BOOL srv_io_srv_share_info_1(char *desc, SRV_SHARE_INFO_1 *ctr, prs_struct *ps, int depth) -{ - if (ctr == NULL) return False; - prs_debug(ps, depth, desc, "srv_io_share_1_ctr"); - depth++; - - prs_align(ps); - - prs_uint32("num_entries_read", ps, depth, &(ctr->num_entries_read)); - prs_uint32("ptr_share_info", ps, depth, &(ctr->ptr_share_info)); - - if (ctr->ptr_share_info != 0) - { - uint32 i; - uint32 num_entries = ctr->num_entries_read; - if (num_entries > MAX_SHARE_ENTRIES) - { - num_entries = MAX_SHARE_ENTRIES; /* report this! */ - } - - prs_uint32("num_entries_read2", ps, depth, &(ctr->num_entries_read2)); - - SMB_ASSERT_ARRAY(ctr->info_1, num_entries); - - for (i = 0; i < num_entries; i++) - { - srv_io_share_info1("", &(ctr->info_1[i]), ps, depth); - } - - for (i = 0; i < num_entries; i++) - { - srv_io_share_info1_str("", &(ctr->info_1_str[i]), ps, depth); - } - - prs_align(ps); - } - - return True; -} - -/******************************************************************* - makes a SH_INFO_2_STR structure -********************************************************************/ -BOOL make_srv_share_info2_str(SH_INFO_2_STR *sh2, +void init_srv_share_info2_str(SH_INFO_2_STR *sh2, char *net_name, char *remark, - char *path, char *pass) + char *path, char *passwd) { - if (sh2 == NULL) return False; - - DEBUG(5,("make_srv_share_info2_str\n")); + DEBUG(5,("init_srv_share_info2_str\n")); - make_unistr2(&(sh2->uni_netname), net_name, strlen(net_name)+1); - make_unistr2(&(sh2->uni_remark ), remark , strlen(remark )+1); - make_unistr2(&(sh2->uni_path ), path , strlen(path )+1); - make_unistr2(&(sh2->uni_passwd ), pass , strlen(pass )+1); - - return True; + init_unistr2(&sh2->uni_netname, net_name, strlen(net_name)+1); + init_unistr2(&sh2->uni_remark, remark, strlen(remark)+1); + init_unistr2(&sh2->uni_path, path, strlen(path)+1); + init_unistr2(&sh2->uni_passwd, passwd, strlen(passwd)+1); } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -static BOOL srv_io_share_info2_str(char *desc, SH_INFO_2_STR *ss2, SH_INFO_2 *sh2, prs_struct *ps, int depth) + +static BOOL srv_io_share_info2_str(char *desc, SH_INFO_2_STR *sh2, prs_struct *ps, int depth) { - if (ss2 == NULL) return False; + if (sh2 == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_share_info2_str"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_unistr2("", &(ss2->uni_netname), sh2->ptr_netname, ps, depth); - prs_align(ps); - smb_io_unistr2("", &(ss2->uni_remark ), sh2->ptr_remark , ps, depth); - prs_align(ps); - smb_io_unistr2("", &(ss2->uni_path ), sh2->ptr_path , ps, depth); - prs_align(ps); - smb_io_unistr2("", &(ss2->uni_passwd ), sh2->ptr_passwd , ps, depth); - prs_align(ps); + if(!smb_io_unistr2("", &sh2->uni_netname, True, ps, depth)) + return False; + if(!smb_io_unistr2("", &sh2->uni_remark, True, ps, depth)) + return False; + if(!smb_io_unistr2("", &sh2->uni_path, True, ps, depth)) + return False; + if(!smb_io_unistr2("", &sh2->uni_passwd, True, ps, depth)) + return False; return True; } /******************************************************************* - makes a SH_INFO_2 structure + Inits a SH_INFO_2 structure ********************************************************************/ -BOOL make_srv_share_info2(SH_INFO_2 *sh2, + +void init_srv_share_info2(SH_INFO_2 *sh2, char *net_name, uint32 type, char *remark, uint32 perms, uint32 max_uses, uint32 num_uses, - char *path, char *pass) + char *path, char *passwd) { - if (sh2 == NULL) return False; - - DEBUG(5,("make_srv_share_info2: %s %8x %s\n", net_name, type, remark)); + DEBUG(5,("init_srv_share_info2: %s %8x %s\n", net_name, type, remark)); - sh2->ptr_netname = net_name != NULL ? 1 : 0; + sh2->ptr_netname = (net_name != NULL) ? 1 : 0; sh2->type = type; - sh2->ptr_remark = remark != NULL ? 1 : 0; + sh2->ptr_remark = (remark != NULL) ? 1 : 0; sh2->perms = perms; sh2->max_uses = max_uses; sh2->num_uses = num_uses; sh2->type = type; - sh2->ptr_path = path != NULL ? 1 : 0; - sh2->ptr_passwd = pass != NULL ? 1 : 0; - - return True; + sh2->ptr_path = (path != NULL) ? 1 : 0; + sh2->ptr_passwd = (passwd != NULL) ? 1 : 0; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -static BOOL srv_io_share_info2(char *desc, SH_INFO_2 *sh2, prs_struct *ps, int depth) + +static BOOL srv_io_share_info2(char *desc, SH_INFO_2 *sh2, prs_struct *ps, int depth) { - if (sh2 == NULL) return False; + if (sh2 == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_share_info2"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr_netname", ps, depth, &(sh2->ptr_netname)); - prs_uint32("type ", ps, depth, &(sh2->type )); - prs_uint32("ptr_remark ", ps, depth, &(sh2->ptr_remark )); - prs_uint32("perms ", ps, depth, &(sh2->perms )); - prs_uint32("max_uses ", ps, depth, &(sh2->max_uses )); - prs_uint32("num_uses ", ps, depth, &(sh2->num_uses )); - prs_uint32("ptr_path ", ps, depth, &(sh2->ptr_path )); - prs_uint32("ptr_passwd ", ps, depth, &(sh2->ptr_passwd )); + if(!prs_uint32("ptr_netname", ps, depth, &sh2->ptr_netname)) + return False; + if(!prs_uint32("type ", ps, depth, &sh2->type)) + return False; + if(!prs_uint32("ptr_remark ", ps, depth, &sh2->ptr_remark)) + return False; + if(!prs_uint32("perms ", ps, depth, &sh2->perms)) + return False; + if(!prs_uint32("max_uses ", ps, depth, &sh2->max_uses)) + return False; + if(!prs_uint32("num_uses ", ps, depth, &sh2->num_uses)) + return False; + if(!prs_uint32("ptr_path ", ps, depth, &sh2->ptr_path)) + return False; + if(!prs_uint32("ptr_passwd ", ps, depth, &sh2->ptr_passwd)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -static BOOL srv_io_srv_share_info_2(char *desc, SRV_SHARE_INFO_2 *ctr, prs_struct *ps, int depth) + +static BOOL srv_io_srv_share_ctr(char *desc, SRV_SHARE_INFO_CTR *ctr, prs_struct *ps, int depth) { - if (ctr == NULL) return False; + if (ctr == NULL) + return False; - prs_debug(ps, depth, desc, "srv_io_share_2_ctr"); + prs_debug(ps, depth, desc, "srv_io_srv_share_ctr"); depth++; - prs_align(ps); + if (UNMARSHALLING(ps)) { + memset(ctr, '\0', sizeof(SRV_SHARE_INFO_CTR)); + } + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("info_level", ps, depth, &ctr->info_level)) + return False; + + if (ctr->info_level == 0) + return True; + + if(!prs_uint32("switch_value", ps, depth, &ctr->switch_value)) + return False; + if(!prs_uint32("ptr_share_info", ps, depth, &ctr->ptr_share_info)) + return False; + + if (ctr->ptr_share_info == 0) + return True; + + if(!prs_uint32("num_entries", ps, depth, &ctr->num_entries)) + return False; + if(!prs_uint32("ptr_entries", ps, depth, &ctr->ptr_entries)) + return False; - prs_uint32("num_entries_read", ps, depth, &(ctr->num_entries_read)); - prs_uint32("ptr_share_info", ps, depth, &(ctr->ptr_share_info)); + if (ctr->ptr_entries == 0) { + if (ctr->num_entries == 0) + return True; + else + return False; + } + + if(!prs_uint32("num_entries2", ps, depth, &ctr->num_entries2)) + return False; - if (ctr->ptr_share_info != 0) + if (ctr->num_entries2 != ctr->num_entries) + return False; + + switch (ctr->switch_value) { + case 1: { - uint32 i; - uint32 num_entries = ctr->num_entries_read; - if (num_entries > MAX_SHARE_ENTRIES) - { - num_entries = MAX_SHARE_ENTRIES; /* report this! */ + SRV_SHARE_INFO_1 *info1 = ctr->share.info1; + int num_entries = ctr->num_entries; + int i; + + if (UNMARSHALLING(ps)) { + if (!(info1 = malloc(num_entries * sizeof(SRV_SHARE_INFO_1)))) + return False; + memset(info1, '\0', num_entries * sizeof(SRV_SHARE_INFO_1)); + ctr->share.info1 = info1; + } + + for (i = 0; i < num_entries; i++) { + if(!srv_io_share_info1("", &info1[i].info_1, ps, depth)) + return False; } - prs_uint32("num_entries_read2", ps, depth, &(ctr->num_entries_read2)); + for (i = 0; i < num_entries; i++) { + if(!srv_io_share_info1_str("", &info1[i].info_1_str, ps, depth)) + return False; + } - SMB_ASSERT_ARRAY(ctr->info_2, num_entries); + break; + } + + case 2: + { + SRV_SHARE_INFO_2 *info2 = ctr->share.info2; + int num_entries = ctr->num_entries; + int i; - for (i = 0; i < num_entries; i++) - { - if (!srv_io_share_info2("", &(ctr->info_2[i]), ps, depth)) return False; + if (UNMARSHALLING(ps)) { + if (!(info2 = malloc(num_entries * sizeof(SRV_SHARE_INFO_2)))) + return False; + memset(info2, '\0', num_entries * sizeof(SRV_SHARE_INFO_2)); + ctr->share.info2 = info2; } - for (i = 0; i < num_entries; i++) - { - if (!srv_io_share_info2_str("", &(ctr->info_2_str[i]), &(ctr->info_2[i]), ps, depth)) return False; + for (i = 0; i < num_entries; i++) { + if(!srv_io_share_info2("", &info2[i].info_2, ps, depth)) + return False; } - prs_align(ps); + for (i = 0; i < num_entries; i++) { + if(!srv_io_share_info2_str("", &info2[i].info_2_str, ps, depth)) + return False; + } + + break; + } + + default: + DEBUG(5,("%s no share info at switch_value %d\n", + tab_depth(depth), ctr->switch_value)); + break; } return True; } /******************************************************************* -reads or writes a structure. + Frees a SRV_SHARE_INFO_CTR structure. ********************************************************************/ -static BOOL srv_io_srv_share_ctr(char *desc, SRV_SHARE_INFO_CTR *ctr, prs_struct *ps, int depth) -{ - if (ctr == NULL) return False; - prs_debug(ps, depth, desc, "srv_io_srv_share_ctr"); - depth++; +void free_srv_share_info_ctr(SRV_SHARE_INFO_CTR *ctr) +{ + if(!ctr) + return; + if(ctr->share.info) + free(ctr->share.info); + memset(ctr, '\0', sizeof(SRV_SHARE_INFO_CTR)); +} - prs_align(ps); +/******************************************************************* + Frees a SRV_Q_NET_SHARE_ENUM structure. +********************************************************************/ - prs_uint32("switch_value", ps, depth, &(ctr->switch_value)); - prs_uint32("ptr_share_ctr", ps, depth, &(ctr->ptr_share_ctr)); +void free_srv_q_net_share_enum(SRV_Q_NET_SHARE_ENUM *q_n) +{ + if(!q_n) + return; + free_srv_share_info_ctr(&q_n->ctr); + memset(q_n, '\0', sizeof(SRV_Q_NET_SHARE_ENUM)); +} - if (ctr->ptr_share_ctr != 0) - { - switch (ctr->switch_value) - { - case 2: - { - srv_io_srv_share_info_2("", &(ctr->share.info2), ps, depth); - break; - } - case 1: - { - srv_io_srv_share_info_1("", &(ctr->share.info1), ps, depth); - break; - } - default: - { - DEBUG(5,("%s no share info at switch_value %d\n", - tab_depth(depth), ctr->switch_value)); - break; - } - } - } +/******************************************************************* + Frees a SRV_R_NET_SHARE_ENUM structure. +********************************************************************/ - return True; +void free_srv_r_net_share_enum(SRV_R_NET_SHARE_ENUM *r_n) +{ + if(!r_n) + return; + free_srv_share_info_ctr(&r_n->ctr); + memset(r_n, '\0', sizeof(SRV_R_NET_SHARE_ENUM)); } /******************************************************************* -reads or writes a structure. + Inits a SRV_Q_NET_SHARE_ENUM structure. ********************************************************************/ -BOOL make_srv_q_net_share_enum(SRV_Q_NET_SHARE_ENUM *q_n, - const char *srv_name, - uint32 share_level, SRV_SHARE_INFO_CTR *ctr, - uint32 preferred_len, - ENUM_HND *hnd) -{ - if (q_n == NULL || ctr == NULL || hnd == NULL) return False; - q_n->ctr = ctr; +void init_srv_q_net_share_enum(SRV_Q_NET_SHARE_ENUM *q_n, + char *srv_name, uint32 info_level, + uint32 preferred_len, ENUM_HND *hnd) +{ - DEBUG(5,("make_q_net_share_enum\n")); + DEBUG(5,("init_q_net_share_enum\n")); - make_buf_unistr2(&(q_n->uni_srv_name), &(q_n->ptr_srv_name), srv_name); + init_buf_unistr2(&q_n->uni_srv_name, &q_n->ptr_srv_name, srv_name); - q_n->share_level = share_level; + q_n->ctr.info_level = q_n->ctr.switch_value = info_level; + q_n->ctr.ptr_share_info = 0; q_n->preferred_len = preferred_len; - memcpy(&(q_n->enum_hnd), hnd, sizeof(*hnd)); - - return True; + memcpy(&q_n->enum_hnd, hnd, sizeof(*hnd)); } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL srv_io_q_net_share_enum(char *desc, SRV_Q_NET_SHARE_ENUM *q_n, prs_struct *ps, int depth) + +BOOL srv_io_q_net_share_enum(char *desc, SRV_Q_NET_SHARE_ENUM *q_n, prs_struct *ps, int depth) { - if (q_n == NULL) return False; + if (q_n == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_q_net_share_enum"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr_srv_name", ps, depth, &(q_n->ptr_srv_name)); - smb_io_unistr2("", &(q_n->uni_srv_name), True, ps, depth); + if(!prs_uint32("ptr_srv_name", ps, depth, &q_n->ptr_srv_name)) + return False; + if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth)) + return False; - prs_align(ps); + if(!srv_io_srv_share_ctr("share_ctr", &q_n->ctr, ps, depth)) + return False; - prs_uint32("share_level", ps, depth, &(q_n->share_level )); - - if (((int)q_n->share_level) != -1) - { - srv_io_srv_share_ctr("share_ctr", q_n->ctr, ps, depth); - } + if(!prs_align(ps)) + return False; - prs_uint32("preferred_len", ps, depth, &(q_n->preferred_len)); + if(!prs_uint32("preferred_len", ps, depth, &q_n->preferred_len)) + return False; - smb_io_enum_hnd("enum_hnd", &(q_n->enum_hnd), ps, depth); + if(!smb_io_enum_hnd("enum_hnd", &q_n->enum_hnd, ps, depth)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL srv_io_r_net_share_enum(char *desc, SRV_R_NET_SHARE_ENUM *r_n, prs_struct *ps, int depth) + +BOOL srv_io_r_net_share_enum(char *desc, SRV_R_NET_SHARE_ENUM *r_n, prs_struct *ps, int depth) { - if (r_n == NULL) return False; + if (r_n == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_r_net_share_enum"); depth++; - prs_align(ps); - - prs_uint32("share_level", ps, depth, &(r_n->share_level)); + if(!srv_io_srv_share_ctr("share_ctr", &r_n->ctr, ps, depth)) + return False; - if (r_n->share_level != 0) - { - srv_io_srv_share_ctr("share_ctr", r_n->ctr, ps, depth); - } + if(!prs_align(ps)) + return False; - prs_uint32("total_entries", ps, depth, &(r_n->total_entries)); - smb_io_enum_hnd("enum_hnd", &(r_n->enum_hnd), ps, depth); - prs_uint32("status ", ps, depth, &(r_n->status)); + if(!prs_uint32("total_entries", ps, depth, &r_n->total_entries)) + return False; + if(!smb_io_enum_hnd("enum_hnd", &r_n->enum_hnd, ps, depth)) + return False; + if(!prs_uint32("status ", ps, depth, &r_n->status)) + return False; return True; } /******************************************************************* - makes a SESS_INFO_0_STR structure + Frees a SRV_Q_NET_SHARE_GET_INFO structure. +********************************************************************/ + +void free_srv_q_net_share_get_info(SRV_Q_NET_SHARE_GET_INFO *q_n) +{ + if(!q_n) + return; + memset(q_n, '\0', sizeof(SRV_Q_NET_SHARE_GET_INFO)); +} + +/******************************************************************* + Frees a SRV_R_NET_SHARE_GET_INFO structure. +********************************************************************/ + +void free_srv_r_net_share_get_info(SRV_R_NET_SHARE_GET_INFO *r_n) +{ + if(!r_n) + return; + memset(r_n, '\0', sizeof(SRV_R_NET_SHARE_GET_INFO)); +} + +/******************************************************************* + Reads or writes a structure. ********************************************************************/ -BOOL make_srv_sess_info0_str(SESS_INFO_0_STR *ss0, char *name) + +BOOL srv_io_q_net_share_get_info(char *desc, SRV_Q_NET_SHARE_GET_INFO *q_n, prs_struct *ps, int depth) { - if (ss0 == NULL) return False; + if (q_n == NULL) + return False; + + prs_debug(ps, depth, desc, "srv_io_q_net_share_get_info"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("ptr_srv_name", ps, depth, &q_n->ptr_srv_name)) + return False; + if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth)) + return False; + + if(!smb_io_unistr2("", &q_n->uni_share_name, True, ps, depth)) + return False; - DEBUG(5,("make_srv_sess_info0_str\n")); + if(!prs_align(ps)) + return False; - make_unistr2(&(ss0->uni_name), name, strlen(name)+1); + if(!prs_uint32("info_level", ps, depth, &q_n->info_level)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -static BOOL srv_io_sess_info0_str(char *desc, SESS_INFO_0_STR *ss0, -const SESS_INFO_0 *si0, prs_struct *ps, int depth) + +BOOL srv_io_r_net_share_get_info(char *desc, SRV_R_NET_SHARE_GET_INFO *r_n, prs_struct *ps, int depth) { - if (ss0 == NULL) return False; + if (r_n == NULL) + return False; - prs_debug(ps, depth, desc, "srv_io_sess_info0_str"); + prs_debug(ps, depth, desc, "srv_io_r_net_share_get_info"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_unistr2("", &(ss0->uni_name), si0->ptr_name, ps, depth); + if(!prs_uint32("switch_value ", ps, depth, &r_n->switch_value )) + return False; + + if(!prs_uint32("ptr_share_ctr", ps, depth, &r_n->ptr_share_ctr)) + return False; + + if (r_n->ptr_share_ctr != 0) { + switch (r_n->switch_value) { + case 1: + if(!srv_io_share_info1("", &r_n->share.info1.info_1, ps, depth)) + return False; + + if(!srv_io_share_info1_str("", &r_n->share.info1.info_1_str, ps, depth)) + return False; + + break; + case 2: + if(!srv_io_share_info2("", &r_n->share.info2.info_2, ps, depth)) + return False; + + if(!srv_io_share_info2_str("", &r_n->share.info2.info_2_str, ps, depth)) + return False; + + break; + default: + DEBUG(5,("%s no share info at switch_value %d\n", + tab_depth(depth), r_n->switch_value)); + break; + } + } + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("status", ps, depth, &r_n->status)) + return False; return True; } /******************************************************************* - makes a SESS_INFO_0 structure + Inits a SESS_INFO_0_STR structure +********************************************************************/ + +void init_srv_sess_info0_str(SESS_INFO_0_STR *ss0, char *name) +{ + DEBUG(5,("init_srv_sess_info0_str\n")); + + init_unistr2(&ss0->uni_name, name, strlen(name)+1); +} + +/******************************************************************* + Reads or writes a structure. ********************************************************************/ -BOOL make_srv_sess_info0(SESS_INFO_0 *ss0, char *name) + +static BOOL srv_io_sess_info0_str(char *desc, SESS_INFO_0_STR *ss0, prs_struct *ps, int depth) { - if (ss0 == NULL) return False; + if (ss0 == NULL) + return False; - DEBUG(5,("make_srv_sess_info0: %s\n", name)); + prs_debug(ps, depth, desc, "srv_io_sess_info0_str"); + depth++; - ss0->ptr_name = name != NULL ? 1 : 0; + if(!prs_align(ps)) + return False; + + if(!smb_io_unistr2("", &ss0->uni_name, True, ps, depth)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Inits a SESS_INFO_0 structure ********************************************************************/ -static BOOL srv_io_sess_info0(char *desc, SESS_INFO_0 *ss0, prs_struct *ps, int depth) + +void init_srv_sess_info0(SESS_INFO_0 *ss0, char *name) +{ + DEBUG(5,("init_srv_sess_info0: %s\n", name)); + + ss0->ptr_name = (name != NULL) ? 1 : 0; +} + +/******************************************************************* + Reads or writes a structure. +********************************************************************/ + +static BOOL srv_io_sess_info0(char *desc, SESS_INFO_0 *ss0, prs_struct *ps, int depth) { - if (ss0 == NULL) return False; + if (ss0 == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_sess_info0"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr_name", ps, depth, &(ss0->ptr_name)); + if(!prs_uint32("ptr_name", ps, depth, &ss0->ptr_name)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -static BOOL srv_io_srv_sess_info_0(char *desc, SRV_SESS_INFO_0 *ss0, prs_struct *ps, int depth) + +static BOOL srv_io_srv_sess_info_0(char *desc, SRV_SESS_INFO_0 *ss0, prs_struct *ps, int depth) { - if (ss0 == NULL) return False; + if (ss0 == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_srv_sess_info_0"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("num_entries_read", ps, depth, &(ss0->num_entries_read)); - prs_uint32("ptr_sess_info", ps, depth, &(ss0->ptr_sess_info)); + if(!prs_uint32("num_entries_read", ps, depth, &ss0->num_entries_read)) + return False; + if(!prs_uint32("ptr_sess_info", ps, depth, &ss0->ptr_sess_info)) + return False; - if (ss0->ptr_sess_info != 0) - { - uint32 i; - uint32 num_entries = ss0->num_entries_read; - if (num_entries > MAX_SESS_ENTRIES) - { + if (ss0->ptr_sess_info != 0) { + int i; + int num_entries = ss0->num_entries_read; + + if (num_entries > MAX_SESS_ENTRIES) { num_entries = MAX_SESS_ENTRIES; /* report this! */ } - prs_uint32("num_entries_read2", ps, depth, &(ss0->num_entries_read2)); + if(!prs_uint32("num_entries_read2", ps, depth, &ss0->num_entries_read2)) + return False; SMB_ASSERT_ARRAY(ss0->info_0, num_entries); - for (i = 0; i < num_entries; i++) - { - srv_io_sess_info0("", &(ss0->info_0[i]), ps, depth); + for (i = 0; i < num_entries; i++) { + if(!srv_io_sess_info0("", &ss0->info_0[i], ps, depth)) + return False; } - for (i = 0; i < num_entries; i++) - { - srv_io_sess_info0_str("", &(ss0->info_0_str[i]), - &(ss0->info_0[i]), - ps, depth); + for (i = 0; i < num_entries; i++) { + if(!srv_io_sess_info0_str("", &ss0->info_0_str[i], ps, depth)) + return False; } - prs_align(ps); + if(!prs_align(ps)) + return False; } return True; } /******************************************************************* - makes a SESS_INFO_1_STR structure + Inits a SESS_INFO_1_STR structure ********************************************************************/ -BOOL make_srv_sess_info1_str(SESS_INFO_1_STR *ss1, char *name, char *user) -{ - if (ss1 == NULL) return False; - - DEBUG(5,("make_srv_sess_info1_str\n")); - make_unistr2(&(ss1->uni_name), name, strlen(name)+1); - make_unistr2(&(ss1->uni_user), name, strlen(user)+1); +void init_srv_sess_info1_str(SESS_INFO_1_STR *ss1, char *name, char *user) +{ + DEBUG(5,("init_srv_sess_info1_str\n")); - return True; + init_unistr2(&ss1->uni_name, name, strlen(name)+1); + init_unistr2(&ss1->uni_user, name, strlen(user)+1); } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -static BOOL srv_io_sess_info1_str(char *desc, SESS_INFO_1_STR *ss1, - SESS_INFO_1 *si1, - prs_struct *ps, int depth) + +static BOOL srv_io_sess_info1_str(char *desc, SESS_INFO_1_STR *ss1, prs_struct *ps, int depth) { - if (ss1 == NULL) return False; + if (ss1 == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_sess_info1_str"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_unistr2("", &(ss1->uni_name), si1->ptr_name, ps, depth); - smb_io_unistr2("", &(ss1->uni_user), si1->ptr_user, ps, depth); + if(!smb_io_unistr2("", &ss1->uni_name, True, ps, depth)) + return False; + if(!smb_io_unistr2("", &(ss1->uni_user), True, ps, depth)) + return False; return True; } /******************************************************************* - makes a SESS_INFO_1 structure + Inits a SESS_INFO_1 structure ********************************************************************/ -BOOL make_srv_sess_info1(SESS_INFO_1 *ss1, + +void init_srv_sess_info1(SESS_INFO_1 *ss1, char *name, char *user, uint32 num_opens, uint32 open_time, uint32 idle_time, uint32 user_flags) { - if (ss1 == NULL) return False; - - DEBUG(5,("make_srv_sess_info1: %s\n", name)); + DEBUG(5,("init_srv_sess_info1: %s\n", name)); - ss1->ptr_name = name != NULL ? 1 : 0; - ss1->ptr_user = user != NULL ? 1 : 0; + ss1->ptr_name = (name != NULL) ? 1 : 0; + ss1->ptr_user = (user != NULL) ? 1 : 0; ss1->num_opens = num_opens; ss1->open_time = open_time; ss1->idle_time = idle_time; ss1->user_flags = user_flags; - - return True; } /******************************************************************* reads or writes a structure. ********************************************************************/ -static BOOL srv_io_sess_info1(char *desc, SESS_INFO_1 *ss1, prs_struct *ps, int depth) + +static BOOL srv_io_sess_info1(char *desc, SESS_INFO_1 *ss1, prs_struct *ps, int depth) { - if (ss1 == NULL) return False; + if (ss1 == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_sess_info1"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr_name ", ps, depth, &(ss1->ptr_name )); - prs_uint32("ptr_user ", ps, depth, &(ss1->ptr_user )); + if(!prs_uint32("ptr_name ", ps, depth, &ss1->ptr_name)) + return False; + if(!prs_uint32("ptr_user ", ps, depth, &ss1->ptr_user)) + return False; - prs_uint32("num_opens ", ps, depth, &(ss1->num_opens )); - prs_uint32("open_time ", ps, depth, &(ss1->open_time )); - prs_uint32("idle_time ", ps, depth, &(ss1->idle_time )); - prs_uint32("user_flags", ps, depth, &(ss1->user_flags)); + if(!prs_uint32("num_opens ", ps, depth, &ss1->num_opens)) + return False; + if(!prs_uint32("open_time ", ps, depth, &ss1->open_time)) + return False; + if(!prs_uint32("idle_time ", ps, depth, &ss1->idle_time)) + return False; + if(!prs_uint32("user_flags", ps, depth, &ss1->user_flags)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -static BOOL srv_io_srv_sess_info_1(char *desc, SRV_SESS_INFO_1 *ss1, prs_struct *ps, int depth) + +static BOOL srv_io_srv_sess_info_1(char *desc, SRV_SESS_INFO_1 *ss1, prs_struct *ps, int depth) { - if (ss1 == NULL) return False; + if (ss1 == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_srv_sess_info_1"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("num_entries_read", ps, depth, &(ss1->num_entries_read)); - prs_uint32("ptr_sess_info", ps, depth, &(ss1->ptr_sess_info)); + if(!prs_uint32("num_entries_read", ps, depth, &ss1->num_entries_read)) + return False; + if(!prs_uint32("ptr_sess_info", ps, depth, &ss1->ptr_sess_info)) + return False; - if (ss1->ptr_sess_info != 0) - { - uint32 i; - uint32 num_entries = ss1->num_entries_read; - if (num_entries > MAX_SESS_ENTRIES) - { + if (ss1->ptr_sess_info != 0) { + int i; + int num_entries = ss1->num_entries_read; + + if (num_entries > MAX_SESS_ENTRIES) { num_entries = MAX_SESS_ENTRIES; /* report this! */ } - prs_uint32("num_entries_read2", ps, depth, &(ss1->num_entries_read2)); + if(!prs_uint32("num_entries_read2", ps, depth, &ss1->num_entries_read2)) + return False; SMB_ASSERT_ARRAY(ss1->info_1, num_entries); - for (i = 0; i < num_entries; i++) - { - srv_io_sess_info1("", &(ss1->info_1[i]), ps, depth); + for (i = 0; i < num_entries; i++) { + if(!srv_io_sess_info1("", &ss1->info_1[i], ps, depth)) + return False; } - for (i = 0; i < num_entries; i++) - { - srv_io_sess_info1_str("", &(ss1->info_1_str[i]), - &(ss1->info_1[i]), - ps, depth); + for (i = 0; i < num_entries; i++) { + if(!srv_io_sess_info1_str("", &ss1->info_1_str[i], ps, depth)) + return False; } - prs_align(ps); + if(!prs_align(ps)) + return False; } return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -static BOOL srv_io_srv_sess_ctr(char *desc, SRV_SESS_INFO_CTR *ctr, prs_struct *ps, int depth) + +static BOOL srv_io_srv_sess_ctr(char *desc, SRV_SESS_INFO_CTR *ctr, prs_struct *ps, int depth) { - if (ctr == NULL) return False; + if (ctr == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_srv_sess_ctr"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("switch_value", ps, depth, &(ctr->switch_value)); - prs_uint32("ptr_sess_ctr", ps, depth, &(ctr->ptr_sess_ctr)); + if(!prs_uint32("switch_value", ps, depth, &ctr->switch_value)) + return False; + if(!prs_uint32("ptr_sess_ctr", ps, depth, &ctr->ptr_sess_ctr)) + return False; - if (ctr->ptr_sess_ctr != 0) - { - switch (ctr->switch_value) - { - case 0: - { - srv_io_srv_sess_info_0("", &(ctr->sess.info0), ps, depth); - break; - } - case 1: - { - srv_io_srv_sess_info_1("", &(ctr->sess.info1), ps, depth); - break; - } - default: - { - DEBUG(5,("%s no session info at switch_value %d\n", - tab_depth(depth), ctr->switch_value)); - break; - } + if (ctr->ptr_sess_ctr != 0) { + switch (ctr->switch_value) { + case 0: + if(!srv_io_srv_sess_info_0("", &ctr->sess.info0, ps, depth)) + return False; + break; + case 1: + if(!srv_io_srv_sess_info_1("", &ctr->sess.info1, ps, depth)) + return False; + break; + default: + DEBUG(5,("%s no session info at switch_value %d\n", + tab_depth(depth), ctr->switch_value)); + break; } } @@ -680,211 +835,229 @@ static BOOL srv_io_srv_sess_ctr(char *desc, SRV_SESS_INFO_CTR *ctr, prs_struct } /******************************************************************* -reads or writes a structure. + Inits a SRV_Q_NET_SESS_ENUM structure. ********************************************************************/ -BOOL make_srv_q_net_sess_enum(SRV_Q_NET_SESS_ENUM *q_n, - const char *srv_name, const char *qual_name, - char *user_name, + +void init_srv_q_net_sess_enum(SRV_Q_NET_SESS_ENUM *q_n, + char *srv_name, char *qual_name, uint32 sess_level, SRV_SESS_INFO_CTR *ctr, uint32 preferred_len, ENUM_HND *hnd) { - if (q_n == NULL || ctr == NULL || hnd == NULL) return False; - q_n->ctr = ctr; - DEBUG(5,("make_q_net_sess_enum\n")); + DEBUG(5,("init_q_net_sess_enum\n")); - make_buf_unistr2(&(q_n->uni_srv_name), &(q_n->ptr_srv_name), srv_name); - make_buf_unistr2(&(q_n->uni_qual_name), &(q_n->ptr_qual_name), qual_name); - make_buf_unistr2(&(q_n->uni_user_name), &(q_n->ptr_user_name), user_name); + init_buf_unistr2(&q_n->uni_srv_name, &q_n->ptr_srv_name, srv_name); + init_buf_unistr2(&q_n->uni_qual_name, &q_n->ptr_qual_name, qual_name); q_n->sess_level = sess_level; q_n->preferred_len = preferred_len; - memcpy(&(q_n->enum_hnd), hnd, sizeof(*hnd)); - - return True; + memcpy(&q_n->enum_hnd, hnd, sizeof(*hnd)); } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL srv_io_q_net_sess_enum(char *desc, SRV_Q_NET_SESS_ENUM *q_n, prs_struct *ps, int depth) + +BOOL srv_io_q_net_sess_enum(char *desc, SRV_Q_NET_SESS_ENUM *q_n, prs_struct *ps, int depth) { - if (q_n == NULL) return False; + if (q_n == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_q_net_sess_enum"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr_srv_name", ps, depth, &(q_n->ptr_srv_name)); - smb_io_unistr2("", &(q_n->uni_srv_name), True, ps, depth); + if(!prs_uint32("ptr_srv_name", ps, depth, &q_n->ptr_srv_name)) + return False; + if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth)) + return False; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr_qual_name", ps, depth, &(q_n->ptr_qual_name)); - smb_io_unistr2("", &(q_n->uni_qual_name), q_n->ptr_qual_name, ps, depth); - prs_align(ps); + if(!prs_uint32("ptr_qual_name", ps, depth, &q_n->ptr_qual_name)) + return False; + if(!smb_io_unistr2("", &q_n->uni_qual_name, q_n->ptr_qual_name, ps, depth)) + return False; - prs_uint32("ptr_user_name", ps, depth, &(q_n->ptr_user_name)); - smb_io_unistr2("", &(q_n->uni_user_name), q_n->ptr_user_name, ps, depth); - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("sess_level", ps, depth, &(q_n->sess_level )); + if(!prs_uint32("sess_level", ps, depth, &q_n->sess_level)) + return False; - if (((int)q_n->sess_level) != -1) - { - srv_io_srv_sess_ctr("sess_ctr", q_n->ctr, ps, depth); + if (q_n->sess_level != -1) { + if(!srv_io_srv_sess_ctr("sess_ctr", q_n->ctr, ps, depth)) + return False; } - prs_uint32("preferred_len", ps, depth, &(q_n->preferred_len)); + if(!prs_uint32("preferred_len", ps, depth, &q_n->preferred_len)) + return False; - smb_io_enum_hnd("enum_hnd", &(q_n->enum_hnd), ps, depth); + if(!smb_io_enum_hnd("enum_hnd", &q_n->enum_hnd, ps, depth)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL srv_io_r_net_sess_enum(char *desc, SRV_R_NET_SESS_ENUM *r_n, prs_struct *ps, int depth) + +BOOL srv_io_r_net_sess_enum(char *desc, SRV_R_NET_SESS_ENUM *r_n, prs_struct *ps, int depth) { - if (r_n == NULL) return False; + if (r_n == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_r_net_sess_enum"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("sess_level", ps, depth, &(r_n->sess_level)); + if(!prs_uint32("sess_level", ps, depth, &r_n->sess_level)) + return False; - if (((int)r_n->sess_level) != -1) - { - srv_io_srv_sess_ctr("sess_ctr", r_n->ctr, ps, depth); + if (r_n->sess_level != -1) { + if(!srv_io_srv_sess_ctr("sess_ctr", r_n->ctr, ps, depth)) + return False; } - prs_uint32("total_entries", ps, depth, &(r_n->total_entries)); - smb_io_enum_hnd("enum_hnd", &(r_n->enum_hnd), ps, depth); - prs_uint32("status ", ps, depth, &(r_n->status)); + if(!prs_uint32("total_entries", ps, depth, &r_n->total_entries)) + return False; + if(!smb_io_enum_hnd("enum_hnd", &r_n->enum_hnd, ps, depth)) + return False; + if(!prs_uint32("status ", ps, depth, &r_n->status)) + return False; return True; } /******************************************************************* - makes a CONN_INFO_0 structure + Inits a CONN_INFO_0 structure ********************************************************************/ -BOOL make_srv_conn_info0(CONN_INFO_0 *ss0, uint32 id) -{ - if (ss0 == NULL) return False; - DEBUG(5,("make_srv_conn_info0\n")); +void init_srv_conn_info0(CONN_INFO_0 *ss0, uint32 id) +{ + DEBUG(5,("init_srv_conn_info0\n")); ss0->id = id; - - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -static BOOL srv_io_conn_info0(char *desc, CONN_INFO_0 *ss0, prs_struct *ps, int depth) + +static BOOL srv_io_conn_info0(char *desc, CONN_INFO_0 *ss0, prs_struct *ps, int depth) { - if (ss0 == NULL) return False; + if (ss0 == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_conn_info0"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("id", ps, depth, &(ss0->id)); + if(!prs_uint32("id", ps, depth, &ss0->id)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -static BOOL srv_io_srv_conn_info_0(char *desc, SRV_CONN_INFO_0 *ss0, prs_struct *ps, int depth) + +static BOOL srv_io_srv_conn_info_0(char *desc, SRV_CONN_INFO_0 *ss0, prs_struct *ps, int depth) { - if (ss0 == NULL) return False; + if (ss0 == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_srv_conn_info_0"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("num_entries_read", ps, depth, &(ss0->num_entries_read)); - prs_uint32("ptr_conn_info", ps, depth, &(ss0->ptr_conn_info)); + if(!prs_uint32("num_entries_read", ps, depth, &ss0->num_entries_read)) + return False; + if(!prs_uint32("ptr_conn_info", ps, depth, &ss0->ptr_conn_info)) + return False; - if (ss0->ptr_conn_info != 0) - { - uint32 i; - uint32 num_entries = ss0->num_entries_read; - if (num_entries > MAX_CONN_ENTRIES) - { + if (ss0->ptr_conn_info != 0) { + int i; + int num_entries = ss0->num_entries_read; + + if (num_entries > MAX_CONN_ENTRIES) { num_entries = MAX_CONN_ENTRIES; /* report this! */ } - prs_uint32("num_entries_read2", ps, depth, &(ss0->num_entries_read2)); + if(!prs_uint32("num_entries_read2", ps, depth, &ss0->num_entries_read2)) + return False; - for (i = 0; i < num_entries; i++) - { - srv_io_conn_info0("", &(ss0->info_0[i]), ps, depth); + for (i = 0; i < num_entries; i++) { + if(!srv_io_conn_info0("", &ss0->info_0[i], ps, depth)) + return False; } - prs_align(ps); + if(!prs_align(ps)) + return False; } return True; } /******************************************************************* - makes a CONN_INFO_1_STR structure + Inits a CONN_INFO_1_STR structure ********************************************************************/ -BOOL make_srv_conn_info1_str(CONN_INFO_1_STR *ss1, char *usr_name, char *net_name) -{ - if (ss1 == NULL) return False; - - DEBUG(5,("make_srv_conn_info1_str\n")); - make_unistr2(&(ss1->uni_usr_name), usr_name, strlen(usr_name)+1); - make_unistr2(&(ss1->uni_net_name), net_name, strlen(net_name)+1); +void init_srv_conn_info1_str(CONN_INFO_1_STR *ss1, char *usr_name, char *net_name) +{ + DEBUG(5,("init_srv_conn_info1_str\n")); - return True; + init_unistr2(&ss1->uni_usr_name, usr_name, strlen(usr_name)+1); + init_unistr2(&ss1->uni_net_name, net_name, strlen(net_name)+1); } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -static BOOL srv_io_conn_info1_str(char *desc, CONN_INFO_1_STR *ss1, - CONN_INFO_1 *ci1, prs_struct *ps, int depth) + +static BOOL srv_io_conn_info1_str(char *desc, CONN_INFO_1_STR *ss1, prs_struct *ps, int depth) { - if (ss1 == NULL) return False; + if (ss1 == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_conn_info1_str"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_unistr2("", &(ss1->uni_usr_name), ci1->ptr_usr_name, ps, depth); - smb_io_unistr2("", &(ss1->uni_net_name), ci1->ptr_net_name, ps, depth); + if(!smb_io_unistr2("", &ss1->uni_usr_name, True, ps, depth)) + return False; + if(!smb_io_unistr2("", &ss1->uni_net_name, True, ps, depth)) + return False; return True; } /******************************************************************* - makes a CONN_INFO_1 structure + Inits a CONN_INFO_1 structure ********************************************************************/ -BOOL make_srv_conn_info1(CONN_INFO_1 *ss1, + +void init_srv_conn_info1(CONN_INFO_1 *ss1, uint32 id, uint32 type, uint32 num_opens, uint32 num_users, uint32 open_time, char *usr_name, char *net_name) { - if (ss1 == NULL) return False; - - DEBUG(5,("make_srv_conn_info1: %s %s\n", usr_name, net_name)); + DEBUG(5,("init_srv_conn_info1: %s %s\n", usr_name, net_name)); ss1->id = id ; ss1->type = type ; @@ -892,115 +1065,126 @@ BOOL make_srv_conn_info1(CONN_INFO_1 *ss1, ss1->num_users = num_users; ss1->open_time = open_time; - ss1->ptr_usr_name = usr_name != NULL ? 1 : 0; - ss1->ptr_net_name = net_name != NULL ? 1 : 0; - - return True; + ss1->ptr_usr_name = (usr_name != NULL) ? 1 : 0; + ss1->ptr_net_name = (net_name != NULL) ? 1 : 0; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -static BOOL srv_io_conn_info1(char *desc, CONN_INFO_1 *ss1, prs_struct *ps, int depth) + +static BOOL srv_io_conn_info1(char *desc, CONN_INFO_1 *ss1, prs_struct *ps, int depth) { - if (ss1 == NULL) return False; + if (ss1 == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_conn_info1"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("id ", ps, depth, &(ss1->id )); - prs_uint32("type ", ps, depth, &(ss1->type )); - prs_uint32("num_opens ", ps, depth, &(ss1->num_opens )); - prs_uint32("num_users ", ps, depth, &(ss1->num_users )); - prs_uint32("open_time ", ps, depth, &(ss1->open_time )); + if(!prs_uint32("id ", ps, depth, &ss1->id)) + return False; + if(!prs_uint32("type ", ps, depth, &ss1->type)) + return False; + if(!prs_uint32("num_opens ", ps, depth, &ss1->num_opens)) + return False; + if(!prs_uint32("num_users ", ps, depth, &ss1->num_users)) + return False; + if(!prs_uint32("open_time ", ps, depth, &ss1->open_time)) + return False; - prs_uint32("ptr_usr_name", ps, depth, &(ss1->ptr_usr_name)); - prs_uint32("ptr_net_name", ps, depth, &(ss1->ptr_net_name)); + if(!prs_uint32("ptr_usr_name", ps, depth, &ss1->ptr_usr_name)) + return False; + if(!prs_uint32("ptr_net_name", ps, depth, &ss1->ptr_net_name)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -static BOOL srv_io_srv_conn_info_1(char *desc, SRV_CONN_INFO_1 *ss1, prs_struct *ps, int depth) + +static BOOL srv_io_srv_conn_info_1(char *desc, SRV_CONN_INFO_1 *ss1, prs_struct *ps, int depth) { - if (ss1 == NULL) return False; + if (ss1 == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_srv_conn_info_1"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("num_entries_read", ps, depth, &(ss1->num_entries_read)); - prs_uint32("ptr_conn_info", ps, depth, &(ss1->ptr_conn_info)); + if(!prs_uint32("num_entries_read", ps, depth, &ss1->num_entries_read)) + return False; + if(!prs_uint32("ptr_conn_info", ps, depth, &ss1->ptr_conn_info)) + return False; - if (ss1->ptr_conn_info != 0) - { - uint32 i; - uint32 num_entries = ss1->num_entries_read; - if (num_entries > MAX_CONN_ENTRIES) - { + if (ss1->ptr_conn_info != 0) { + int i; + int num_entries = ss1->num_entries_read; + + if (num_entries > MAX_CONN_ENTRIES) { num_entries = MAX_CONN_ENTRIES; /* report this! */ } - prs_uint32("num_entries_read2", ps, depth, &(ss1->num_entries_read2)); + if(!prs_uint32("num_entries_read2", ps, depth, &ss1->num_entries_read2)) + return False; - for (i = 0; i < num_entries; i++) - { - srv_io_conn_info1("", &(ss1->info_1[i]), ps, depth); + for (i = 0; i < num_entries; i++) { + if(!srv_io_conn_info1("", &ss1->info_1[i], ps, depth)) + return False; } - for (i = 0; i < num_entries; i++) - { - srv_io_conn_info1_str("", &(ss1->info_1_str[i]), - &(ss1->info_1[i]), - ps, depth); + for (i = 0; i < num_entries; i++) { + if(!srv_io_conn_info1_str("", &ss1->info_1_str[i], ps, depth)) + return False; } - prs_align(ps); + if(!prs_align(ps)) + return False; } return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -static BOOL srv_io_srv_conn_ctr(char *desc, SRV_CONN_INFO_CTR *ctr, prs_struct *ps, int depth) + +static BOOL srv_io_srv_conn_ctr(char *desc, SRV_CONN_INFO_CTR *ctr, prs_struct *ps, int depth) { - if (ctr == NULL) return False; + if (ctr == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_srv_conn_ctr"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("switch_value", ps, depth, &(ctr->switch_value)); - prs_uint32("ptr_conn_ctr", ps, depth, &(ctr->ptr_conn_ctr)); + if(!prs_uint32("switch_value", ps, depth, &ctr->switch_value)) + return False; + if(!prs_uint32("ptr_conn_ctr", ps, depth, &ctr->ptr_conn_ctr)) + return False; - if (ctr->ptr_conn_ctr != 0) - { - switch (ctr->switch_value) - { - case 0: - { - srv_io_srv_conn_info_0("", &(ctr->conn.info0), ps, depth); - break; - } - case 1: - { - srv_io_srv_conn_info_1("", &(ctr->conn.info1), ps, depth); - break; - } - default: - { - DEBUG(5,("%s no connection info at switch_value %d\n", - tab_depth(depth), ctr->switch_value)); - break; - } + if (ctr->ptr_conn_ctr != 0) { + switch (ctr->switch_value) { + case 0: + if(!srv_io_srv_conn_info_0("", &ctr->conn.info0, ps, depth)) + return False; + break; + case 1: + if(!srv_io_srv_conn_info_1("", &ctr->conn.info1, ps, depth)) + return False; + break; + default: + DEBUG(5,("%s no connection info at switch_value %d\n", + tab_depth(depth), ctr->switch_value)); + break; } } @@ -1008,540 +1192,269 @@ static BOOL srv_io_srv_conn_ctr(char *desc, SRV_CONN_INFO_CTR *ctr, prs_struct } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL make_srv_q_net_conn_enum(SRV_Q_NET_CONN_ENUM *q_n, - const char *srv_name, const char *qual_name, + +void init_srv_q_net_conn_enum(SRV_Q_NET_CONN_ENUM *q_n, + char *srv_name, char *qual_name, uint32 conn_level, SRV_CONN_INFO_CTR *ctr, uint32 preferred_len, ENUM_HND *hnd) { - if (q_n == NULL || ctr == NULL || hnd == NULL) return False; + DEBUG(5,("init_q_net_conn_enum\n")); q_n->ctr = ctr; - DEBUG(5,("make_q_net_conn_enum\n")); - - make_buf_unistr2(&(q_n->uni_srv_name ), &(q_n->ptr_srv_name ), srv_name ); - make_buf_unistr2(&(q_n->uni_qual_name), &(q_n->ptr_qual_name), qual_name); + init_buf_unistr2(&q_n->uni_srv_name, &q_n->ptr_srv_name, srv_name ); + init_buf_unistr2(&q_n->uni_qual_name, &q_n->ptr_qual_name, qual_name); q_n->conn_level = conn_level; q_n->preferred_len = preferred_len; - memcpy(&(q_n->enum_hnd), hnd, sizeof(*hnd)); - - return True; + memcpy(&q_n->enum_hnd, hnd, sizeof(*hnd)); } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL srv_io_q_net_conn_enum(char *desc, SRV_Q_NET_CONN_ENUM *q_n, prs_struct *ps, int depth) + +BOOL srv_io_q_net_conn_enum(char *desc, SRV_Q_NET_CONN_ENUM *q_n, prs_struct *ps, int depth) { - if (q_n == NULL) return False; + if (q_n == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_q_net_conn_enum"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr_srv_name ", ps, depth, &(q_n->ptr_srv_name)); - smb_io_unistr2("", &(q_n->uni_srv_name), q_n->ptr_srv_name, ps, depth); + if(!prs_uint32("ptr_srv_name ", ps, depth, &q_n->ptr_srv_name)) + return False; + if(!smb_io_unistr2("", &q_n->uni_srv_name, q_n->ptr_srv_name, ps, depth)) + return False; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr_qual_name", ps, depth, &(q_n->ptr_qual_name)); - smb_io_unistr2("", &(q_n->uni_qual_name), q_n->ptr_qual_name, ps, depth); + if(!prs_uint32("ptr_qual_name", ps, depth, &q_n->ptr_qual_name)) + return False; + if(!smb_io_unistr2("", &q_n->uni_qual_name, q_n->ptr_qual_name, ps, depth)) + return False; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("conn_level", ps, depth, &(q_n->conn_level )); + if(!prs_uint32("conn_level", ps, depth, &q_n->conn_level)) + return False; - if (((int)q_n->conn_level) != -1) - { - srv_io_srv_conn_ctr("conn_ctr", q_n->ctr, ps, depth); + if (q_n->conn_level != -1) { + if(!srv_io_srv_conn_ctr("conn_ctr", q_n->ctr, ps, depth)) + return False; } - prs_uint32("preferred_len", ps, depth, &(q_n->preferred_len)); + if(!prs_uint32("preferred_len", ps, depth, &q_n->preferred_len)) + return False; - smb_io_enum_hnd("enum_hnd", &(q_n->enum_hnd), ps, depth); + if(!smb_io_enum_hnd("enum_hnd", &q_n->enum_hnd, ps, depth)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ + BOOL srv_io_r_net_conn_enum(char *desc, SRV_R_NET_CONN_ENUM *r_n, prs_struct *ps, int depth) { - if (r_n == NULL) return False; + if (r_n == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_r_net_conn_enum"); depth++; - prs_align(ps); - - prs_uint32("conn_level", ps, depth, &(r_n->conn_level)); - - if (((int)r_n->conn_level) != -1) - { - srv_io_srv_conn_ctr("conn_ctr", r_n->ctr, ps, depth); - } - - prs_uint32("total_entries", ps, depth, &(r_n->total_entries)); - smb_io_enum_hnd("enum_hnd", &(r_n->enum_hnd), ps, depth); - prs_uint32("status ", ps, depth, &(r_n->status)); - - return True; -} - -/******************************************************************* - makes a TPRT_INFO_0_STR structure -********************************************************************/ -BOOL make_srv_tprt_info0_str(TPRT_INFO_0_STR *tp0, - char *trans_name, - char *trans_addr, uint32 trans_addr_len, - char *addr_name) -{ - if (tp0 == NULL) return False; - - DEBUG(5,("make_srv_tprt_info0_str\n")); - - make_unistr2(&(tp0->uni_trans_name), trans_name, strlen(trans_name)+1); - make_buffer4_str(&(tp0->buf_trans_addr), trans_addr, trans_addr_len); - make_unistr2(&(tp0->uni_addr_name ), addr_name, strlen(addr_name)+1); - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -static BOOL srv_io_tprt_info0_str(char *desc, TPRT_INFO_0_STR *tp0, - TPRT_INFO_0 *ti0, - prs_struct *ps, int depth) -{ - if (tp0 == NULL) return False; - - prs_debug(ps, depth, desc, "srv_io_tprt_info0_str"); - depth++; - - prs_align(ps); - - smb_io_unistr2("", &(tp0->uni_trans_name), ti0->ptr_trans_name, ps, depth); - smb_io_buffer4("", &(tp0->buf_trans_addr), ti0->ptr_trans_addr, ps, depth); - smb_io_unistr2("", &(tp0->uni_addr_name ), ti0->ptr_addr_name, ps, depth); - - return True; -} - -/******************************************************************* - makes a TPRT_INFO_0 structure -********************************************************************/ -BOOL make_srv_tprt_info0(TPRT_INFO_0 *tp0, - uint32 num_vcs, uint32 trans_addr_len, - char *trans_name, char *trans_addr, - char *addr_name) -{ - if (tp0 == NULL) return False; - - DEBUG(5,("make_srv_tprt_info0: %s %s\n", trans_name, addr_name)); - - tp0->num_vcs = num_vcs; - tp0->ptr_trans_name = trans_name != NULL ? 1 : 0; - tp0->ptr_trans_addr = trans_addr != NULL ? 1 : 0; - tp0->trans_addr_len = trans_addr_len; - tp0->ptr_addr_name = addr_name != NULL ? 1 : 0; - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -static BOOL srv_io_tprt_info0(char *desc, TPRT_INFO_0 *tp0, prs_struct *ps, int depth) -{ - if (tp0 == NULL) return False; - - prs_debug(ps, depth, desc, "srv_io_tprt_info0"); - depth++; - - prs_align(ps); - - prs_uint32("num_vcs ", ps, depth, &(tp0->num_vcs )); - prs_uint32("ptr_trans_name", ps, depth, &(tp0->ptr_trans_name)); - prs_uint32("ptr_trans_addr", ps, depth, &(tp0->ptr_trans_addr)); - prs_uint32("trans_addr_len", ps, depth, &(tp0->trans_addr_len)); - prs_uint32("ptr_addr_name ", ps, depth, &(tp0->ptr_addr_name )); - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -static BOOL srv_io_srv_tprt_info_0(char *desc, SRV_TPRT_INFO_0 *tp0, prs_struct *ps, int depth) -{ - if (tp0 == NULL) return False; - - prs_debug(ps, depth, desc, "srv_io_srv_tprt_info_0"); - depth++; - - prs_align(ps); - - prs_uint32("num_entries_read", ps, depth, &(tp0->num_entries_read)); - prs_uint32("ptr_tprt_info", ps, depth, &(tp0->ptr_tprt_info)); - - if (tp0->ptr_tprt_info != 0) - { - uint32 i; - uint32 num_entries = tp0->num_entries_read; - - prs_uint32("num_entries_read2", ps, depth, &(tp0->num_entries_read2)); - - if (ps->io) - { - /* reading */ - tp0->info_0 = (TPRT_INFO_0*)malloc(num_entries * - sizeof(tp0->info_0[0])); - - tp0->info_0_str = (TPRT_INFO_0_STR*)malloc(num_entries * - sizeof(tp0->info_0_str[0])); - - if (tp0->info_0 == NULL || tp0->info_0_str == NULL) - { - free_srv_tprt_info_0(tp0); - return False; - } - } - - for (i = 0; i < num_entries; i++) - { - srv_io_tprt_info0("", &(tp0->info_0[i]), ps, depth); - } - - for (i = 0; i < num_entries; i++) - { - srv_io_tprt_info0_str("", &(tp0->info_0_str[i]), - &(tp0->info_0[i]), - ps, depth); - } - - prs_align(ps); - } - - if (!ps->io) - { - /* writing */ - free_srv_tprt_info_0(tp0); - } - - return True; -} - -/******************************************************************* -frees a structure. -********************************************************************/ -void free_srv_tprt_info_0(SRV_TPRT_INFO_0 *tp0) -{ - if (tp0->info_0 != NULL) - { - free(tp0->info_0); - tp0->info_0 = NULL; - } - if (tp0->info_0_str != NULL) - { - free(tp0->info_0_str); - tp0->info_0_str = NULL; - } -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -static BOOL srv_io_srv_tprt_ctr(char *desc, SRV_TPRT_INFO_CTR *ctr, prs_struct *ps, int depth) -{ - if (ctr == NULL) return False; - - prs_debug(ps, depth, desc, "srv_io_srv_tprt_ctr"); - depth++; - - prs_align(ps); - - prs_uint32("switch_value", ps, depth, &(ctr->switch_value)); - prs_uint32("ptr_tprt_ctr", ps, depth, &(ctr->ptr_tprt_ctr)); - - if (ctr->ptr_tprt_ctr != 0) - { - switch (ctr->switch_value) - { - case 0: - { - srv_io_srv_tprt_info_0("", &(ctr->tprt.info0), ps, depth); - break; - } - default: - { - DEBUG(5,("%s no transport info at switch_value %d\n", - tab_depth(depth), ctr->switch_value)); - break; - } - } - } + if(!prs_align(ps)) + return False; - return True; -} + if(!prs_uint32("conn_level", ps, depth, &r_n->conn_level)) + return False; -/******************************************************************* -reads or writes a structure. -********************************************************************/ -void free_srv_tprt_ctr(SRV_TPRT_INFO_CTR *ctr) -{ - switch (ctr->switch_value) - { - case 0: - { - free_srv_tprt_info_0(&(ctr->tprt.info0)); - break; - } - default: - { - DEBUG(5,("no transport info at switch_value %d\n", - ctr->switch_value)); - break; - } + if (r_n->conn_level != -1) { + if(!srv_io_srv_conn_ctr("conn_ctr", r_n->ctr, ps, depth)) + return False; } -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL make_srv_q_net_tprt_enum(SRV_Q_NET_TPRT_ENUM *q_n, - const char *srv_name, - uint32 tprt_level, SRV_TPRT_INFO_CTR *ctr, - uint32 preferred_len, - ENUM_HND *hnd) -{ - if (q_n == NULL || ctr == NULL || hnd == NULL) return False; - - q_n->ctr = ctr; - - DEBUG(5,("make_q_net_tprt_enum\n")); - - make_buf_unistr2(&(q_n->uni_srv_name ), &(q_n->ptr_srv_name ), srv_name ); - q_n->tprt_level = tprt_level; - q_n->preferred_len = preferred_len; - - memcpy(&(q_n->enum_hnd), hnd, sizeof(*hnd)); + if(!prs_uint32("total_entries", ps, depth, &r_n->total_entries)) + return False; + if(!smb_io_enum_hnd("enum_hnd", &r_n->enum_hnd, ps, depth)) + return False; + if(!prs_uint32("status ", ps, depth, &r_n->status)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Inits a FILE_INFO_3_STR structure ********************************************************************/ -BOOL srv_io_q_net_tprt_enum(char *desc, SRV_Q_NET_TPRT_ENUM *q_n, prs_struct *ps, int depth) -{ - if (q_n == NULL) return False; - - prs_debug(ps, depth, desc, "srv_io_q_net_tprt_enum"); - depth++; - - prs_align(ps); - - prs_uint32("ptr_srv_name ", ps, depth, &(q_n->ptr_srv_name)); - smb_io_unistr2("", &(q_n->uni_srv_name), q_n->ptr_srv_name, ps, depth); - - prs_align(ps); - prs_uint32("tprt_level", ps, depth, &(q_n->tprt_level )); - - if (((int)q_n->tprt_level) != -1) - { - srv_io_srv_tprt_ctr("tprt_ctr", q_n->ctr, ps, depth); - } - - prs_uint32("preferred_len", ps, depth, &(q_n->preferred_len)); - - smb_io_enum_hnd("enum_hnd", &(q_n->enum_hnd), ps, depth); - - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -BOOL srv_io_r_net_tprt_enum(char *desc, SRV_R_NET_TPRT_ENUM *r_n, prs_struct *ps, int depth) +void init_srv_file_info3_str(FILE_INFO_3_STR *fi3, char *user_name, char *path_name) { - if (r_n == NULL) return False; - - prs_debug(ps, depth, desc, "srv_io_r_net_tprt_enum"); - depth++; - - prs_align(ps); - - prs_uint32("tprt_level", ps, depth, &(r_n->tprt_level)); + DEBUG(5,("init_srv_file_info3_str\n")); - if (((int)r_n->tprt_level) != -1) - { - srv_io_srv_tprt_ctr("tprt_ctr", r_n->ctr, ps, depth); - } - - prs_uint32("total_entries", ps, depth, &(r_n->total_entries)); - smb_io_enum_hnd("enum_hnd", &(r_n->enum_hnd), ps, depth); - prs_uint32("status ", ps, depth, &(r_n->status)); - - return True; + init_unistr2(&fi3->uni_path_name, path_name, strlen(path_name)+1); + init_unistr2(&fi3->uni_user_name, user_name, strlen(user_name)+1); } /******************************************************************* - makes a FILE_INFO_3_STR structure + Reads or writes a structure. ********************************************************************/ -BOOL make_srv_file_info3_str(FILE_INFO_3_STR *fi3, char *user_name, char *path_name) -{ - if (fi3 == NULL) return False; - - DEBUG(5,("make_srv_file_info3_str\n")); - - make_unistr2(&(fi3->uni_path_name), path_name, strlen(path_name)+1); - make_unistr2(&(fi3->uni_user_name), user_name, strlen(user_name)+1); - return True; -} - -/******************************************************************* -reads or writes a structure. -********************************************************************/ -static BOOL srv_io_file_info3_str(char *desc, FILE_INFO_3_STR *sh1, prs_struct *ps, int depth) +static BOOL srv_io_file_info3_str(char *desc, FILE_INFO_3_STR *sh1, prs_struct *ps, int depth) { - if (sh1 == NULL) return False; + if (sh1 == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_file_info3_str"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_unistr2("", &(sh1->uni_path_name), True, ps, depth); - smb_io_unistr2("", &(sh1->uni_user_name), True, ps, depth); + if(!smb_io_unistr2("", &sh1->uni_path_name, True, ps, depth)) + return False; + if(!smb_io_unistr2("", &sh1->uni_user_name, True, ps, depth)) + return False; return True; } /******************************************************************* - makes a FILE_INFO_3 structure + Inits a FILE_INFO_3 structure ********************************************************************/ -BOOL make_srv_file_info3(FILE_INFO_3 *fl3, + +void init_srv_file_info3(FILE_INFO_3 *fl3, uint32 id, uint32 perms, uint32 num_locks, char *path_name, char *user_name) { - if (fl3 == NULL) return False; - - DEBUG(5,("make_srv_file_info3: %s %s\n", path_name, user_name)); + DEBUG(5,("init_srv_file_info3: %s %s\n", path_name, user_name)); fl3->id = id; fl3->perms = perms; fl3->num_locks = num_locks; - fl3->ptr_path_name = path_name != NULL ? 1 : 0; - fl3->ptr_user_name = user_name != NULL ? 1 : 0; - - return True; + fl3->ptr_path_name = (path_name != NULL) ? 1 : 0; + fl3->ptr_user_name = (user_name != NULL) ? 1 : 0; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -static BOOL srv_io_file_info3(char *desc, FILE_INFO_3 *fl3, prs_struct *ps, int depth) + +static BOOL srv_io_file_info3(char *desc, FILE_INFO_3 *fl3, prs_struct *ps, int depth) { - if (fl3 == NULL) return False; + if (fl3 == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_file_info3"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("id ", ps, depth, &(fl3->id )); - prs_uint32("perms ", ps, depth, &(fl3->perms )); - prs_uint32("num_locks ", ps, depth, &(fl3->num_locks )); - prs_uint32("ptr_path_name", ps, depth, &(fl3->ptr_path_name)); - prs_uint32("ptr_user_name", ps, depth, &(fl3->ptr_user_name)); + if(!prs_uint32("id ", ps, depth, &fl3->id)) + return False; + if(!prs_uint32("perms ", ps, depth, &fl3->perms)) + return False; + if(!prs_uint32("num_locks ", ps, depth, &fl3->num_locks)) + return False; + if(!prs_uint32("ptr_path_name", ps, depth, &fl3->ptr_path_name)) + return False; + if(!prs_uint32("ptr_user_name", ps, depth, &fl3->ptr_user_name)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -static BOOL srv_io_srv_file_info_3(char *desc, SRV_FILE_INFO_3 *fl3, prs_struct *ps, int depth) + +static BOOL srv_io_srv_file_info_3(char *desc, SRV_FILE_INFO_3 *fl3, prs_struct *ps, int depth) { - if (fl3 == NULL) return False; + if (fl3 == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_file_3_fl3"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("num_entries_read", ps, depth, &(fl3->num_entries_read)); - prs_uint32("ptr_file_fl3", ps, depth, &(fl3->ptr_file_info)); - if (fl3->ptr_file_info != 0) - { - uint32 i; - uint32 num_entries = fl3->num_entries_read; + if(!prs_uint32("num_entries_read", ps, depth, &fl3->num_entries_read)) + return False; + if(!prs_uint32("ptr_file_fl3", ps, depth, &fl3->ptr_file_info)) + return False; + + if (fl3->ptr_file_info != 0) { + int i; + int num_entries = fl3->num_entries_read; - if (num_entries > MAX_FILE_ENTRIES) - { + if (num_entries > MAX_FILE_ENTRIES) { num_entries = MAX_FILE_ENTRIES; /* report this! */ } - prs_uint32("num_entries_read2", ps, depth, &(fl3->num_entries_read2)); + if(!prs_uint32("num_entries_read2", ps, depth, &fl3->num_entries_read2)) + return False; - for (i = 0; i < num_entries; i++) - { - srv_io_file_info3("", &(fl3->info_3[i]), ps, depth); + for (i = 0; i < num_entries; i++) { + if(!srv_io_file_info3("", &fl3->info_3[i], ps, depth)) + return False; } - for (i = 0; i < num_entries; i++) - { - srv_io_file_info3_str("", &(fl3->info_3_str[i]), ps, depth); + for (i = 0; i < num_entries; i++) { + if(!srv_io_file_info3_str("", &fl3->info_3_str[i], ps, depth)) + return False; } - prs_align(ps); + if(!prs_align(ps)) + return False; } return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -static BOOL srv_io_srv_file_ctr(char *desc, SRV_FILE_INFO_CTR *ctr, prs_struct *ps, int depth) + +static BOOL srv_io_srv_file_ctr(char *desc, SRV_FILE_INFO_CTR *ctr, prs_struct *ps, int depth) { - if (ctr == NULL) return False; + if (ctr == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_srv_file_ctr"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("switch_value", ps, depth, &(ctr->switch_value)); - prs_uint32("ptr_file_ctr", ps, depth, &(ctr->ptr_file_ctr)); + if(!prs_uint32("switch_value", ps, depth, &ctr->switch_value)) + return False; + if(!prs_uint32("ptr_file_ctr", ps, depth, &ctr->ptr_file_ctr)) + return False; - if (ctr->ptr_file_ctr != 0) - { - switch (ctr->switch_value) - { - case 3: - { - srv_io_srv_file_info_3("", &(ctr->file.info3), ps, depth); - break; - } - default: - { - DEBUG(5,("%s no file info at switch_value %d\n", - tab_depth(depth), ctr->switch_value)); - break; - } + if (ctr->ptr_file_ctr != 0) { + switch (ctr->switch_value) { + case 3: + if(!srv_io_srv_file_info_3("", &ctr->file.info3, ps, depth)) + return False; + break; + default: + DEBUG(5,("%s no file info at switch_value %d\n", + tab_depth(depth), ctr->switch_value)); + break; } } @@ -1549,164 +1462,184 @@ static BOOL srv_io_srv_file_ctr(char *desc, SRV_FILE_INFO_CTR *ctr, prs_struct } /******************************************************************* -reads or writes a structure. + Inits a SRV_Q_NET_FILE_ENUM structure. ********************************************************************/ -BOOL make_srv_q_net_file_enum(SRV_Q_NET_FILE_ENUM *q_n, - const char *srv_name, const char *qual_name, - uint32 file_id, + +void init_srv_q_net_file_enum(SRV_Q_NET_FILE_ENUM *q_n, + char *srv_name, char *qual_name, uint32 file_level, SRV_FILE_INFO_CTR *ctr, uint32 preferred_len, ENUM_HND *hnd) { - if (q_n == NULL || ctr == NULL || hnd == NULL) return False; + DEBUG(5,("init_q_net_file_enum\n")); q_n->ctr = ctr; - DEBUG(5,("make_q_net_file_enum\n")); - - make_buf_unistr2(&(q_n->uni_srv_name), &(q_n->ptr_srv_name), srv_name); - make_buf_unistr2(&(q_n->uni_qual_name), &(q_n->ptr_qual_name), qual_name); + init_buf_unistr2(&q_n->uni_srv_name, &q_n->ptr_srv_name, srv_name); + init_buf_unistr2(&q_n->uni_qual_name, &q_n->ptr_qual_name, qual_name); - q_n->file_id = file_id; q_n->file_level = file_level; q_n->preferred_len = preferred_len; - memcpy(&(q_n->enum_hnd), hnd, sizeof(*hnd)); - - return True; + memcpy(&q_n->enum_hnd, hnd, sizeof(*hnd)); } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL srv_io_q_net_file_enum(char *desc, SRV_Q_NET_FILE_ENUM *q_n, prs_struct *ps, int depth) + +BOOL srv_io_q_net_file_enum(char *desc, SRV_Q_NET_FILE_ENUM *q_n, prs_struct *ps, int depth) { - if (q_n == NULL) return False; + if (q_n == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_q_net_file_enum"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr_srv_name", ps, depth, &(q_n->ptr_srv_name)); - smb_io_unistr2("", &(q_n->uni_srv_name), True, ps, depth); + if(!prs_uint32("ptr_srv_name", ps, depth, &q_n->ptr_srv_name)) + return False; + if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth)) + return False; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr_qual_name", ps, depth, &(q_n->ptr_qual_name)); - smb_io_unistr2("", &(q_n->uni_qual_name), q_n->ptr_qual_name, ps, depth); + if(!prs_uint32("ptr_qual_name", ps, depth, &q_n->ptr_qual_name)) + return False; + if(!smb_io_unistr2("", &q_n->uni_qual_name, q_n->ptr_qual_name, ps, depth)) + return False; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("file_id ", ps, depth, &(q_n->file_id )); - prs_uint32("file_level", ps, depth, &(q_n->file_level)); + if(!prs_uint32("file_level", ps, depth, &q_n->file_level)) + return False; - if (((int)q_n->file_level) != -1) - { - srv_io_srv_file_ctr("file_ctr", q_n->ctr, ps, depth); + if (q_n->file_level != -1) { + if(!srv_io_srv_file_ctr("file_ctr", q_n->ctr, ps, depth)) + return False; } - prs_uint32("preferred_len", ps, depth, &(q_n->preferred_len)); + if(!prs_uint32("preferred_len", ps, depth, &q_n->preferred_len)) + return False; - smb_io_enum_hnd("enum_hnd", &(q_n->enum_hnd), ps, depth); + if(!smb_io_enum_hnd("enum_hnd", &q_n->enum_hnd, ps, depth)) + return False; return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL srv_io_r_net_file_enum(char *desc, SRV_R_NET_FILE_ENUM *r_n, prs_struct *ps, int depth) + +BOOL srv_io_r_net_file_enum(char *desc, SRV_R_NET_FILE_ENUM *r_n, prs_struct *ps, int depth) { - if (r_n == NULL) return False; + if (r_n == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_r_net_file_enum"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("file_level", ps, depth, &(r_n->file_level)); + if(!prs_uint32("file_level", ps, depth, &r_n->file_level)) + return False; - if (r_n->file_level != 0) - { - srv_io_srv_file_ctr("file_ctr", r_n->ctr, ps, depth); + if (r_n->file_level != 0) { + if(!srv_io_srv_file_ctr("file_ctr", r_n->ctr, ps, depth)) + return False; } - prs_uint32("total_entries", ps, depth, &(r_n->total_entries)); - smb_io_enum_hnd("enum_hnd", &(r_n->enum_hnd), ps, depth); - prs_uint32("status ", ps, depth, &(r_n->status)); + if(!prs_uint32("total_entries", ps, depth, &r_n->total_entries)) + return False; + if(!smb_io_enum_hnd("enum_hnd", &r_n->enum_hnd, ps, depth)) + return False; + if(!prs_uint32("status ", ps, depth, &r_n->status)) + return False; return True; } /******************************************************************* - makes a SRV_INFO_101 structure. + Inits a SRV_INFO_101 structure. ********************************************************************/ -BOOL make_srv_info_101(SRV_INFO_101 *sv101, uint32 platform_id, char *name, + +void init_srv_info_101(SRV_INFO_101 *sv101, uint32 platform_id, char *name, uint32 ver_major, uint32 ver_minor, uint32 srv_type, char *comment) { - if (sv101 == NULL) return False; - - DEBUG(5,("make_srv_info_101\n")); + DEBUG(5,("init_srv_info_101\n")); sv101->platform_id = platform_id; - make_buf_unistr2(&(sv101->uni_name ), &(sv101->ptr_name ) , name ); + init_buf_unistr2(&sv101->uni_name, &sv101->ptr_name, name); sv101->ver_major = ver_major; sv101->ver_minor = ver_minor; sv101->srv_type = srv_type; - make_buf_unistr2(&(sv101->uni_comment ), &(sv101->ptr_comment) , comment ); - - return True; + init_buf_unistr2(&sv101->uni_comment, &sv101->ptr_comment, comment); } - /******************************************************************* - reads or writes a SRV_INFO_101 structure. + Reads or writes a SRV_INFO_101 structure. ********************************************************************/ -static BOOL srv_io_info_101(char *desc, SRV_INFO_101 *sv101, prs_struct *ps, int depth) + +static BOOL srv_io_info_101(char *desc, SRV_INFO_101 *sv101, prs_struct *ps, int depth) { - if (sv101 == NULL) return False; + if (sv101 == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_info_101"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("platform_id ", ps, depth, &(sv101->platform_id )); - prs_uint32("ptr_name ", ps, depth, &(sv101->ptr_name )); - prs_uint32("ver_major ", ps, depth, &(sv101->ver_major )); - prs_uint32("ver_minor ", ps, depth, &(sv101->ver_minor )); - prs_uint32("srv_type ", ps, depth, &(sv101->srv_type )); - prs_uint32("ptr_comment ", ps, depth, &(sv101->ptr_comment )); + if(!prs_uint32("platform_id ", ps, depth, &sv101->platform_id)) + return False; + if(!prs_uint32("ptr_name ", ps, depth, &sv101->ptr_name)) + return False; + if(!prs_uint32("ver_major ", ps, depth, &sv101->ver_major)) + return False; + if(!prs_uint32("ver_minor ", ps, depth, &sv101->ver_minor)) + return False; + if(!prs_uint32("srv_type ", ps, depth, &sv101->srv_type)) + return False; + if(!prs_uint32("ptr_comment ", ps, depth, &sv101->ptr_comment)) + return False; - prs_align(ps); + if(!prs_align(ps)) + return False; - smb_io_unistr2("uni_name ", &(sv101->uni_name ), True, ps, depth); - smb_io_unistr2("uni_comment ", &(sv101->uni_comment ), True, ps, depth); + if(!smb_io_unistr2("uni_name ", &sv101->uni_name, True, ps, depth)) + return False; + if(!smb_io_unistr2("uni_comment ", &sv101->uni_comment, True, ps, depth)) + return False; return True; } /******************************************************************* - makes a SRV_INFO_102 structure. + Inits a SRV_INFO_102 structure. ********************************************************************/ -BOOL make_srv_info_102(SRV_INFO_102 *sv102, uint32 platform_id, char *name, + +void init_srv_info_102(SRV_INFO_102 *sv102, uint32 platform_id, char *name, char *comment, uint32 ver_major, uint32 ver_minor, uint32 srv_type, uint32 users, uint32 disc, uint32 hidden, uint32 announce, uint32 ann_delta, uint32 licenses, char *usr_path) { - if (sv102 == NULL) return False; - - DEBUG(5,("make_srv_info_102\n")); + DEBUG(5,("init_srv_info_102\n")); sv102->platform_id = platform_id; - make_buf_unistr2(&(sv102->uni_name ), &(sv102->ptr_name ), name ); + init_buf_unistr2(&sv102->uni_name, &sv102->ptr_name, name); sv102->ver_major = ver_major; sv102->ver_minor = ver_minor; sv102->srv_type = srv_type; - make_buf_unistr2(&(sv102->uni_comment ), &(sv102->ptr_comment ), comment ); + init_buf_unistr2(&sv102->uni_comment, &sv102->ptr_comment, comment); /* same as 101 up to here */ @@ -1716,250 +1649,277 @@ BOOL make_srv_info_102(SRV_INFO_102 *sv102, uint32 platform_id, char *name, sv102->announce = announce; sv102->ann_delta =ann_delta; sv102->licenses = licenses; - make_buf_unistr2(&(sv102->uni_usr_path), &(sv102->ptr_usr_path), usr_path); - - return True; + init_buf_unistr2(&sv102->uni_usr_path, &sv102->ptr_usr_path, usr_path); } /******************************************************************* - reads or writes a SRV_INFO_102 structure. + Reads or writes a SRV_INFO_102 structure. ********************************************************************/ -static BOOL srv_io_info_102(char *desc, SRV_INFO_102 *sv102, prs_struct *ps, int depth) + +static BOOL srv_io_info_102(char *desc, SRV_INFO_102 *sv102, prs_struct *ps, int depth) { - if (sv102 == NULL) return False; + if (sv102 == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_info102"); depth++; - prs_align(ps); - - prs_uint32("platform_id ", ps, depth, &(sv102->platform_id )); - prs_uint32("ptr_name ", ps, depth, &(sv102->ptr_name )); - prs_uint32("ver_major ", ps, depth, &(sv102->ver_major )); - prs_uint32("ver_minor ", ps, depth, &(sv102->ver_minor )); - prs_uint32("srv_type ", ps, depth, &(sv102->srv_type )); - prs_uint32("ptr_comment ", ps, depth, &(sv102->ptr_comment )); + if(!prs_align(ps)) + return False; + + if(!prs_uint32("platform_id ", ps, depth, &sv102->platform_id)) + return False; + if(!prs_uint32("ptr_name ", ps, depth, &sv102->ptr_name)) + return False; + if(!prs_uint32("ver_major ", ps, depth, &sv102->ver_major)) + return False; + if(!prs_uint32("ver_minor ", ps, depth, &sv102->ver_minor)) + return False; + if(!prs_uint32("srv_type ", ps, depth, &sv102->srv_type)) + return False; + if(!prs_uint32("ptr_comment ", ps, depth, &sv102->ptr_comment)) + return False; /* same as 101 up to here */ - prs_uint32("users ", ps, depth, &(sv102->users )); - prs_uint32("disc ", ps, depth, &(sv102->disc )); - prs_uint32("hidden ", ps, depth, &(sv102->hidden )); - prs_uint32("announce ", ps, depth, &(sv102->announce )); - prs_uint32("ann_delta ", ps, depth, &(sv102->ann_delta )); - prs_uint32("licenses ", ps, depth, &(sv102->licenses )); - prs_uint32("ptr_usr_path", ps, depth, &(sv102->ptr_usr_path)); - - smb_io_unistr2("uni_name ", &(sv102->uni_name ), True, ps, depth); - prs_align(ps); - smb_io_unistr2("uni_comment ", &(sv102->uni_comment ), True, ps, depth); - prs_align(ps); - smb_io_unistr2("uni_usr_path", &(sv102->uni_usr_path), True, ps, depth); - - return True; -} - -/******************************************************************* - reads or writes a SRV_INFO_102 structure. + if(!prs_uint32("users ", ps, depth, &sv102->users)) + return False; + if(!prs_uint32("disc ", ps, depth, &sv102->disc)) + return False; + if(!prs_uint32("hidden ", ps, depth, &sv102->hidden)) + return False; + if(!prs_uint32("announce ", ps, depth, &sv102->announce)) + return False; + if(!prs_uint32("ann_delta ", ps, depth, &sv102->ann_delta)) + return False; + if(!prs_uint32("licenses ", ps, depth, &sv102->licenses)) + return False; + if(!prs_uint32("ptr_usr_path", ps, depth, &sv102->ptr_usr_path)) + return False; + + if(!smb_io_unistr2("uni_name ", &sv102->uni_name, True, ps, depth)) + return False; + if(!prs_align(ps)) + return False; + if(!smb_io_unistr2("uni_comment ", &sv102->uni_comment, True, ps, depth)) + return False; + if(!prs_align(ps)) + return False; + if(!smb_io_unistr2("uni_usr_path", &sv102->uni_usr_path, True, ps, depth)) + return False; + + return True; +} + +/******************************************************************* + Reads or writes a SRV_INFO_102 structure. ********************************************************************/ -static BOOL srv_io_info_ctr(char *desc, SRV_INFO_CTR *ctr, prs_struct *ps, int depth) + +static BOOL srv_io_info_ctr(char *desc, SRV_INFO_CTR *ctr, prs_struct *ps, int depth) { - if (ctr == NULL) return False; + if (ctr == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_info_ctr"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("switch_value", ps, depth, &(ctr->switch_value)); - prs_uint32("ptr_srv_ctr ", ps, depth, &(ctr->ptr_srv_ctr )); + if(!prs_uint32("switch_value", ps, depth, &ctr->switch_value)) + return False; + if(!prs_uint32("ptr_srv_ctr ", ps, depth, &ctr->ptr_srv_ctr)) + return False; - if (ctr->ptr_srv_ctr != 0 && ctr->switch_value != 0 && ctr != NULL) - { - switch (ctr->switch_value) - { - case 101: - { - srv_io_info_101("sv101", &(ctr->srv.sv101), ps, depth); - break; - } - case 102: - { - srv_io_info_102("sv102", &(ctr->srv.sv102), ps, depth); - break; - } - default: - { - DEBUG(5,("%s no server info at switch_value %d\n", - tab_depth(depth), ctr->switch_value)); - break; - } + if (ctr->ptr_srv_ctr != 0 && ctr->switch_value != 0 && ctr != NULL) { + switch (ctr->switch_value) { + case 101: + if(!srv_io_info_101("sv101", &ctr->srv.sv101, ps, depth)) + return False; + break; + case 102: + if(!srv_io_info_102("sv102", &ctr->srv.sv102, ps, depth)) + return False; + break; + default: + DEBUG(5,("%s no server info at switch_value %d\n", + tab_depth(depth), ctr->switch_value)); + break; } - prs_align(ps); + if(!prs_align(ps)) + return False; } return True; } /******************************************************************* - makes a SRV_Q_NET_SRV_GET_INFO structure. + Inits a SRV_Q_NET_SRV_GET_INFO structure. ********************************************************************/ -BOOL make_srv_q_net_srv_get_info(SRV_Q_NET_SRV_GET_INFO *srv, + +void init_srv_q_net_srv_get_info(SRV_Q_NET_SRV_GET_INFO *srv, char *server_name, uint32 switch_value) { - if (srv == NULL) return False; + DEBUG(5,("init_srv_q_net_srv_get_info\n")); - DEBUG(5,("make_srv_q_net_srv_get_info\n")); - - make_buf_unistr2(&(srv->uni_srv_name), &(srv->ptr_srv_name), server_name); + init_buf_unistr2(&srv->uni_srv_name, &srv->ptr_srv_name, server_name); srv->switch_value = switch_value; - - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL srv_io_q_net_srv_get_info(char *desc, SRV_Q_NET_SRV_GET_INFO *q_n, prs_struct *ps, int depth) + +BOOL srv_io_q_net_srv_get_info(char *desc, SRV_Q_NET_SRV_GET_INFO *q_n, prs_struct *ps, int depth) { - if (q_n == NULL) return False; + if (q_n == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_q_net_srv_get_info"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr_srv_name ", ps, depth, &(q_n->ptr_srv_name)); - smb_io_unistr2("", &(q_n->uni_srv_name), True, ps, depth); + if(!prs_uint32("ptr_srv_name ", ps, depth, &q_n->ptr_srv_name)) + return False; + if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth)) + return False; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("switch_value ", ps, depth, &(q_n->switch_value)); + if(!prs_uint32("switch_value ", ps, depth, &q_n->switch_value)) + return False; return True; } /******************************************************************* - makes a SRV_R_NET_SRV_GET_INFO structure. + Inits a SRV_R_NET_SRV_GET_INFO structure. ********************************************************************/ -BOOL make_srv_r_net_srv_get_info(SRV_R_NET_SRV_GET_INFO *srv, + +void init_srv_r_net_srv_get_info(SRV_R_NET_SRV_GET_INFO *srv, uint32 switch_value, SRV_INFO_CTR *ctr, uint32 status) { - if (srv == NULL) return False; - - DEBUG(5,("make_srv_r_net_srv_get_info\n")); + DEBUG(5,("init_srv_r_net_srv_get_info\n")); srv->ctr = ctr; - if (status == 0x0) - { + if (status == 0x0) { srv->ctr->switch_value = switch_value; srv->ctr->ptr_srv_ctr = 1; - } - else - { + } else { srv->ctr->switch_value = 0; srv->ctr->ptr_srv_ctr = 0; } srv->status = status; - - return True; } /******************************************************************* - reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL srv_io_r_net_srv_get_info(char *desc, SRV_R_NET_SRV_GET_INFO *r_n, prs_struct *ps, int depth) + +BOOL srv_io_r_net_srv_get_info(char *desc, SRV_R_NET_SRV_GET_INFO *r_n, prs_struct *ps, int depth) { - if (r_n == NULL) return False; + if (r_n == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_r_net_srv_get_info"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - srv_io_info_ctr("ctr", r_n->ctr, ps, depth); + if(!srv_io_info_ctr("ctr", r_n->ctr, ps, depth)) + return False; - prs_uint32("status ", ps, depth, &(r_n->status )); + if(!prs_uint32("status ", ps, depth, &r_n->status)) + return False; return True; } -/******************************************************************* - makes a SRV_Q_NET_REMOTE_TOD structure. - ********************************************************************/ -BOOL make_srv_q_net_remote_tod(SRV_Q_NET_REMOTE_TOD *q_t, char *server_name) -{ - if (q_t == NULL) return False; - - DEBUG(5,("make_srv_q_net_remote_tod\n")); - - make_buf_unistr2(&(q_t->uni_srv_name), &(q_t->ptr_srv_name), server_name); - - return True; -} /******************************************************************* - reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL srv_io_q_net_remote_tod(char *desc, SRV_Q_NET_REMOTE_TOD *q_n, prs_struct *ps, int depth) + +BOOL srv_io_q_net_remote_tod(char *desc, SRV_Q_NET_REMOTE_TOD *q_n, prs_struct *ps, int depth) { - if (q_n == NULL) return False; + if (q_n == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_q_net_remote_tod"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr_srv_name ", ps, depth, &(q_n->ptr_srv_name)); - smb_io_unistr2("", &(q_n->uni_srv_name), True, ps, depth); + if(!prs_uint32("ptr_srv_name ", ps, depth, &q_n->ptr_srv_name)) + return False; + if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth)) + return False; return True; } /******************************************************************* - reads or writes a TIME_OF_DAY_INFO structure. + Reads or writes a TIME_OF_DAY_INFO structure. ********************************************************************/ -static BOOL srv_io_time_of_day_info(char *desc, TIME_OF_DAY_INFO *tod, prs_struct *ps, int depth) + +static BOOL srv_io_time_of_day_info(char *desc, TIME_OF_DAY_INFO *tod, prs_struct *ps, int depth) { - if (tod == NULL) return False; + if (tod == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_time_of_day_info"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("elapsedt ", ps, depth, &(tod->elapsedt )); - prs_uint32("msecs ", ps, depth, &(tod->msecs )); - prs_uint32("hours ", ps, depth, &(tod->hours )); - prs_uint32("mins ", ps, depth, &(tod->mins )); - prs_uint32("secs ", ps, depth, &(tod->secs )); - prs_uint32("hunds ", ps, depth, &(tod->hunds )); - prs_uint32("timezone ", ps, depth, &(tod->zone )); - prs_uint32("tintervals ", ps, depth, &(tod->tintervals)); - prs_uint32("day ", ps, depth, &(tod->day )); - prs_uint32("month ", ps, depth, &(tod->month )); - prs_uint32("year ", ps, depth, &(tod->year )); - prs_uint32("weekday ", ps, depth, &(tod->weekday )); - - - return True; -} - -/******************************************************************* - makes a TIME_OF_DAY_INFO structure. + if(!prs_uint32("elapsedt ", ps, depth, &tod->elapsedt)) + return False; + if(!prs_uint32("msecs ", ps, depth, &tod->msecs)) + return False; + if(!prs_uint32("hours ", ps, depth, &tod->hours)) + return False; + if(!prs_uint32("mins ", ps, depth, &tod->mins)) + return False; + if(!prs_uint32("secs ", ps, depth, &tod->secs)) + return False; + if(!prs_uint32("hunds ", ps, depth, &tod->hunds)) + return False; + if(!prs_uint32("timezone ", ps, depth, &tod->zone)) + return False; + if(!prs_uint32("tintervals ", ps, depth, &tod->tintervals)) + return False; + if(!prs_uint32("day ", ps, depth, &tod->day)) + return False; + if(!prs_uint32("month ", ps, depth, &tod->month)) + return False; + if(!prs_uint32("year ", ps, depth, &tod->year)) + return False; + if(!prs_uint32("weekday ", ps, depth, &tod->weekday)) + return False; + + return True; +} + +/******************************************************************* + Inits a TIME_OF_DAY_INFO structure. ********************************************************************/ -BOOL make_time_of_day_info(TIME_OF_DAY_INFO *tod, uint32 elapsedt, uint32 msecs, + +void init_time_of_day_info(TIME_OF_DAY_INFO *tod, uint32 elapsedt, uint32 msecs, uint32 hours, uint32 mins, uint32 secs, uint32 hunds, uint32 zone, uint32 tintervals, uint32 day, uint32 month, uint32 year, uint32 weekday) { - if (tod == NULL) return False; - - DEBUG(5,("make_time_of_day_info\n")); + DEBUG(5,("init_time_of_day_info\n")); tod->elapsedt = elapsedt; tod->msecs = msecs; @@ -1973,28 +1933,32 @@ BOOL make_time_of_day_info(TIME_OF_DAY_INFO *tod, uint32 elapsedt, uint32 msecs, tod->month = month; tod->year = year; tod->weekday = weekday; - - return True; } /******************************************************************* - reads or writes a structure. + Reads or writes a structure. ********************************************************************/ + BOOL srv_io_r_net_remote_tod(char *desc, SRV_R_NET_REMOTE_TOD *r_n, prs_struct *ps, int depth) { - if (r_n == NULL) return False; + if (r_n == NULL) + return False; prs_debug(ps, depth, desc, "srv_io_r_net_remote_tod"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr_srv_tod ", ps, depth, &(r_n->ptr_srv_tod)); + if(!prs_uint32("ptr_srv_tod ", ps, depth, &r_n->ptr_srv_tod)) + return False; - srv_io_time_of_day_info("tod", r_n->tod, ps, depth); + if(!srv_io_time_of_day_info("tod", r_n->tod, ps, depth)) + return False; - prs_uint32("status ", ps, depth, &(r_n->status)); + if(!prs_uint32("status ", ps, depth, &r_n->status)) + return False; return True; } diff --git a/source3/rpc_parse/parse_wks.c b/source3/rpc_parse/parse_wks.c index 91409e2eec..7357e3d2f3 100644 --- a/source3/rpc_parse/parse_wks.c +++ b/source3/rpc_parse/parse_wks.c @@ -3,9 +3,9 @@ * Unix SMB/Netbios implementation. * Version 1.9. * RPC Pipe client / server routines - * Copyright (C) Andrew Tridgell 1992-1999, - * Copyright (C) Luke Kenneth Casson Leighton 1996-1999, - * Copyright (C) Paul Ashton 1997-1999. + * Copyright (C) Andrew Tridgell 1992-1997, + * Copyright (C) Luke Kenneth Casson Leighton 1996-1997, + * Copyright (C) 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 @@ -28,38 +28,44 @@ extern int DEBUGLEVEL; /******************************************************************* - make_wks_q_query_info + Init ********************************************************************/ -BOOL make_wks_q_query_info(WKS_Q_QUERY_INFO *q_u, + +void init_wks_q_query_info(WKS_Q_QUERY_INFO *q_u, char *server, uint16 switch_value) { - DEBUG(5,("make_wks_q_query_info\n")); + DEBUG(5,("init_wks_q_query_info\n")); - make_buf_unistr2(&(q_u->uni_srv_name), &(q_u->ptr_srv_name), server); + init_buf_unistr2(&q_u->uni_srv_name, &q_u->ptr_srv_name, server); q_u->switch_value = switch_value; - - - return True; } /******************************************************************* -reads or writes a WKS_Q_QUERY_INFO structure. + Reads or writes a WKS_Q_QUERY_INFO structure. ********************************************************************/ + BOOL wks_io_q_query_info(char *desc, WKS_Q_QUERY_INFO *q_u, prs_struct *ps, int depth) { - if (q_u == NULL) return False; + if (q_u == NULL) + return False; prs_debug(ps, depth, desc, "wks_io_q_query_info"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint32("ptr_srv_name", ps, depth, &(q_u->ptr_srv_name)); - smb_io_unistr2("", &(q_u->uni_srv_name), q_u->ptr_srv_name, ps, depth); - prs_align(ps); + if(!prs_uint32("ptr_srv_name", ps, depth, &q_u->ptr_srv_name)) + return False; + if(!smb_io_unistr2("", &q_u->uni_srv_name, q_u->ptr_srv_name, ps, depth)) + return False; + if(!prs_align(ps)) + return False; - prs_uint16("switch_value", ps, depth, &(q_u->switch_value)); - prs_align(ps); + if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value)) + return False; + if(!prs_align(ps)) + return False; return True; } @@ -67,60 +73,72 @@ BOOL wks_io_q_query_info(char *desc, WKS_Q_QUERY_INFO *q_u, prs_struct *ps, int /******************************************************************* wks_info_100 ********************************************************************/ -BOOL make_wks_info_100(WKS_INFO_100 *inf, + +void init_wks_info_100(WKS_INFO_100 *inf, uint32 platform_id, uint32 ver_major, uint32 ver_minor, char *my_name, char *domain_name) { - DEBUG(5,("WKS_INFO_100: %d\n", __LINE__)); + DEBUG(5,("Init WKS_INFO_100: %d\n", __LINE__)); inf->platform_id = platform_id; /* 0x0000 01f4 - unknown */ inf->ver_major = ver_major; /* os major version */ inf->ver_minor = ver_minor; /* os minor version */ - make_buf_unistr2(&(inf->uni_compname), &(inf->ptr_compname), my_name ); - make_buf_unistr2(&(inf->uni_lan_grp ), &(inf->ptr_lan_grp ), domain_name); - - return True; + init_buf_unistr2(&inf->uni_compname, &inf->ptr_compname, my_name ); + init_buf_unistr2(&inf->uni_lan_grp, &inf->ptr_lan_grp, domain_name); } /******************************************************************* -reads or writes a WKS_INFO_100 structure. + Reads or writes a WKS_INFO_100 structure. ********************************************************************/ + static BOOL wks_io_wks_info_100(char *desc, WKS_INFO_100 *inf, prs_struct *ps, int depth) { - if (inf == NULL) return False; + if (inf == NULL) + return False; prs_debug(ps, depth, desc, "wks_io_wks_info_100"); depth++; - prs_align(ps); - - prs_uint32("platform_id ", ps, depth, &(inf->platform_id )); /* 0x0000 01f4 - unknown */ - prs_uint32("ptr_compname", ps, depth, &(inf->ptr_compname)); /* pointer to computer name */ - prs_uint32("ptr_lan_grp ", ps, depth, &(inf->ptr_lan_grp )); /* pointer to LAN group name */ - prs_uint32("ver_major ", ps, depth, &(inf->ver_major )); /* 4 - major os version */ - prs_uint32("ver_minor ", ps, depth, &(inf->ver_minor )); /* 0 - minor os version */ - - smb_io_unistr2("", &(inf->uni_compname), inf->ptr_compname, ps, depth); - prs_align(ps); - - smb_io_unistr2("", &(inf->uni_lan_grp ), inf->ptr_lan_grp , ps, depth); - prs_align(ps); + if(!prs_align(ps)) + return False; + + if(!prs_uint32("platform_id ", ps, depth, &inf->platform_id)) /* 0x0000 01f4 - unknown */ + return False; + if(!prs_uint32("ptr_compname", ps, depth, &inf->ptr_compname)) /* pointer to computer name */ + return False; + if(!prs_uint32("ptr_lan_grp ", ps, depth, &inf->ptr_lan_grp)) /* pointer to LAN group name */ + return False; + if(!prs_uint32("ver_major ", ps, depth, &inf->ver_major)) /* 4 - major os version */ + return False; + if(!prs_uint32("ver_minor ", ps, depth, &inf->ver_minor)) /* 0 - minor os version */ + return False; + + if(!smb_io_unistr2("", &inf->uni_compname, inf->ptr_compname, ps, depth)) + return False; + if(!prs_align(ps)) + return False; + + if(!smb_io_unistr2("", &inf->uni_lan_grp, inf->ptr_lan_grp , ps, depth)) + return False; + if(!prs_align(ps)) + return False; return True; } /******************************************************************* - make_wks_r_query_info + Inits WKS_R_QUERY_INFO. only supports info level 100 at the moment. ********************************************************************/ -BOOL make_wks_r_query_info(WKS_R_QUERY_INFO *r_u, + +void init_wks_r_query_info(WKS_R_QUERY_INFO *r_u, uint32 switch_value, WKS_INFO_100 *wks100, int status) { - DEBUG(5,("make_wks_r_unknown_0: %d\n", __LINE__)); + DEBUG(5,("init_wks_r_unknown_0: %d\n", __LINE__)); r_u->switch_value = switch_value; /* same as in request */ @@ -128,30 +146,35 @@ BOOL make_wks_r_query_info(WKS_R_QUERY_INFO *r_u, r_u->wks100 = wks100; r_u->status = status; - - return True; } /******************************************************************* -reads or writes a structure. + Reads or writes a structure. ********************************************************************/ -BOOL wks_io_r_query_info(char *desc, WKS_R_QUERY_INFO *r_u, prs_struct *ps, int depth) + +BOOL wks_io_r_query_info(char *desc, WKS_R_QUERY_INFO *r_u, prs_struct *ps, int depth) { - if (r_u == NULL) return False; + if (r_u == NULL) + return False; prs_debug(ps, depth, desc, "wks_io_r_query_info"); depth++; - prs_align(ps); + if(!prs_align(ps)) + return False; - prs_uint16("switch_value", ps, depth, &(r_u->switch_value)); /* level 100 (0x64) */ - prs_align(ps); + if(!prs_uint16("switch_value", ps, depth, &r_u->switch_value)) /* level 100 (0x64) */ + return False; + if(!prs_align(ps)) + return False; - prs_uint32("ptr_1 ", ps, depth, &(r_u->ptr_1 )); /* pointer 1 */ - wks_io_wks_info_100("inf", r_u->wks100, ps, depth); + if(!prs_uint32("ptr_1 ", ps, depth, &r_u->ptr_1)) /* pointer 1 */ + return False; + if(!wks_io_wks_info_100("inf", r_u->wks100, ps, depth)) + return False; - prs_uint32("status ", ps, depth, &(r_u->status)); + if(!prs_uint32("status ", ps, depth, &r_u->status)) + return False; return True; } - |