Remove more redundant lsa parsing functions.
[bbaumbach/samba-autobuild/.git] / source / rpc_parse / parse_net.c
index e168f5abbd3a565fa7ae9052ff8929c1d58bdf51..65607a4ac896a31c9b9d5f77a306b2817aea89c5 100644 (file)
@@ -4,11 +4,11 @@
  *  Copyright (C) Andrew Tridgell              1992-1997,
  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
  *  Copyright (C) Paul Ashton                       1997.
- *  Copyright (C) Jean Franรงois Micouleau           2002.
+ *  Copyright (C) Jean Francois Micouleau           2002.
  *
  *  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
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation; either version 3 of the License, or
  *  (at your option) any later version.
  *  
  *  This program is distributed in the hope that it will be useful,
@@ -17,8 +17,7 @@
  *  GNU General Public License for more details.
  *  
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "includes.h"
@@ -30,7 +29,7 @@
  Reads or writes a structure.
 ********************************************************************/
 
-static BOOL net_io_neg_flags(const char *desc, NEG_FLAGS *neg, prs_struct *ps, int depth)
+static bool net_io_neg_flags(const char *desc, NEG_FLAGS *neg, prs_struct *ps, int depth)
 {
        if (neg == NULL)
                return False;
@@ -66,7 +65,7 @@ static void init_netinfo_3(NETLOGON_INFO_3 *info, uint32 flags, uint32 logon_att
  Reads or writes a NETLOGON_INFO_3 structure.
 ********************************************************************/
 
-static BOOL net_io_netinfo_3(const char *desc,  NETLOGON_INFO_3 *info, prs_struct *ps, int depth)
+static bool net_io_netinfo_3(const char *desc,  NETLOGON_INFO_3 *info, prs_struct *ps, int depth)
 {
        if (info == NULL)
                return False;
@@ -110,7 +109,7 @@ static void init_netinfo_1(NETLOGON_INFO_1 *info, uint32 flags, uint32 pdc_statu
  Reads or writes a NETLOGON_INFO_1 structure.
 ********************************************************************/
 
-static BOOL net_io_netinfo_1(const char *desc, NETLOGON_INFO_1 *info, prs_struct *ps, int depth)
+static bool net_io_netinfo_1(const char *desc, NETLOGON_INFO_1 *info, prs_struct *ps, int depth)
 {
        if (info == NULL)
                return False;
@@ -151,7 +150,7 @@ static void init_netinfo_2(NETLOGON_INFO_2 *info, uint32 flags, uint32 pdc_statu
  Reads or writes a NETLOGON_INFO_2 structure.
 ********************************************************************/
 
-static BOOL net_io_netinfo_2(const char *desc, NETLOGON_INFO_2 *info, prs_struct *ps, int depth)
+static bool net_io_netinfo_2(const char *desc, NETLOGON_INFO_2 *info, prs_struct *ps, int depth)
 {
        if (info == NULL)
                return False;
@@ -182,7 +181,7 @@ static BOOL net_io_netinfo_2(const char *desc, NETLOGON_INFO_2 *info, prs_struct
        return True;
 }
 
-static BOOL net_io_ctrl_data_info_5(const char *desc, CTRL_DATA_INFO_5 *info, prs_struct *ps, int depth)
+static bool net_io_ctrl_data_info_5(const char *desc, CTRL_DATA_INFO_5 *info, prs_struct *ps, int depth)
 {
        if (info == NULL)
                return False;
@@ -204,7 +203,7 @@ static BOOL net_io_ctrl_data_info_5(const char *desc, CTRL_DATA_INFO_5 *info, pr
        return True;
 }
 
-static BOOL net_io_ctrl_data_info_6(const char *desc, CTRL_DATA_INFO_6 *info, prs_struct *ps, int depth)
+static bool net_io_ctrl_data_info_6(const char *desc, CTRL_DATA_INFO_6 *info, prs_struct *ps, int depth)
 {
        if (info == NULL)
                return False;
@@ -230,7 +229,7 @@ static BOOL net_io_ctrl_data_info_6(const char *desc, CTRL_DATA_INFO_6 *info, pr
  Reads or writes an NET_Q_LOGON_CTRL2 structure.
 ********************************************************************/
 
-BOOL net_io_q_logon_ctrl2(const char *desc, NET_Q_LOGON_CTRL2 *q_l, prs_struct *ps, int depth)
+bool net_io_q_logon_ctrl2(const char *desc, NET_Q_LOGON_CTRL2 *q_l, prs_struct *ps, int depth)
 {
        if (q_l == NULL)
                return False;
@@ -332,7 +331,7 @@ void init_net_r_logon_ctrl2(NET_R_LOGON_CTRL2 *r_l, uint32 query_level,
  Reads or writes an NET_R_LOGON_CTRL2 structure.
 ********************************************************************/
 
-BOOL net_io_r_logon_ctrl2(const char *desc, NET_R_LOGON_CTRL2 *r_l, prs_struct *ps, int depth)
+bool net_io_r_logon_ctrl2(const char *desc, NET_R_LOGON_CTRL2 *r_l, prs_struct *ps, int depth)
 {
        if (r_l == NULL)
                return False;
@@ -376,7 +375,7 @@ BOOL net_io_r_logon_ctrl2(const char *desc, NET_R_LOGON_CTRL2 *r_l, prs_struct *
  Reads or writes an NET_Q_LOGON_CTRL structure.
 ********************************************************************/
 
-BOOL net_io_q_logon_ctrl(const char *desc, NET_Q_LOGON_CTRL *q_l, prs_struct *ps, 
+bool net_io_q_logon_ctrl(const char *desc, NET_Q_LOGON_CTRL *q_l, prs_struct *ps, 
                         int depth)
 {
        prs_debug(ps, depth, desc, "net_io_q_logon_ctrl");
@@ -449,7 +448,7 @@ void init_net_r_logon_ctrl(NET_R_LOGON_CTRL *r_l, uint32 query_level,
  Reads or writes an NET_R_LOGON_CTRL structure.
 ********************************************************************/
 
-BOOL net_io_r_logon_ctrl(const char *desc, NET_R_LOGON_CTRL *r_l, prs_struct *ps, 
+bool net_io_r_logon_ctrl(const char *desc, NET_R_LOGON_CTRL *r_l, prs_struct *ps, 
                         int depth)
 {
        prs_debug(ps, depth, desc, "net_io_r_logon_ctrl");
@@ -479,15 +478,102 @@ BOOL net_io_r_logon_ctrl(const char *desc, NET_R_LOGON_CTRL *r_l, prs_struct *ps
        return True;
 }
 
+/*******************************************************************
+ Inits an NET_R_GETANYDCNAME structure.
+********************************************************************/
+void init_net_q_getanydcname(NET_Q_GETANYDCNAME *r_t, const char *logon_server,
+                            const char *domainname)
+{
+       DEBUG(5,("init_q_getanydcname\n"));
+
+       r_t->ptr_logon_server = (logon_server != NULL);
+       init_unistr2(&r_t->uni_logon_server, logon_server, UNI_STR_TERMINATE);
+       r_t->ptr_domainname = (domainname != NULL);
+       init_unistr2(&r_t->uni_domainname, domainname, UNI_STR_TERMINATE);
+}
+
+/*******************************************************************
+ Reads or writes an NET_Q_GETANYDCNAME structure.
+********************************************************************/
+
+bool net_io_q_getanydcname(const char *desc, NET_Q_GETANYDCNAME *r_t, prs_struct *ps,
+                          int depth)
+{
+       if (r_t == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "net_io_q_getanydcname");
+       depth++;
+
+       if (!prs_uint32("ptr_logon_server", ps, depth, &r_t->ptr_logon_server))
+               return False;
+
+       if (!smb_io_unistr2("logon_server", &r_t->uni_logon_server,
+                           r_t->ptr_logon_server, ps, depth))
+               return False;
+
+       if (!prs_align(ps))
+               return False;
+
+       if (!prs_uint32("ptr_domainname", ps, depth, &r_t->ptr_domainname))
+               return False;
+
+       if (!smb_io_unistr2("domainname", &r_t->uni_domainname,
+                           r_t->ptr_domainname, ps, depth))
+               return False;
+
+       return True;
+}
+
+
+/*******************************************************************
+ Inits an NET_R_GETANYDCNAME structure.
+********************************************************************/
+void init_net_r_getanydcname(NET_R_GETANYDCNAME *r_t, const char *dcname)
+{
+       DEBUG(5,("init_r_getanydcname\n"));
+
+       init_unistr2(&r_t->uni_dcname, dcname, UNI_STR_TERMINATE);
+}
+
+/*******************************************************************
+ Reads or writes an NET_R_GETANYDCNAME structure.
+********************************************************************/
+
+bool net_io_r_getanydcname(const char *desc, NET_R_GETANYDCNAME *r_t, prs_struct *ps,
+                          int depth)
+{
+       if (r_t == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "net_io_r_getanydcname");
+       depth++;
+
+       if (!prs_uint32("ptr_dcname", ps, depth, &r_t->ptr_dcname))
+               return False;
+
+       if (!smb_io_unistr2("dcname", &r_t->uni_dcname,
+                           r_t->ptr_dcname, ps, depth))
+               return False;
+
+       if (!prs_align(ps))
+               return False;
+
+       if (!prs_werror("status", ps, depth, &r_t->status))
+               return False;
+
+       return True;
+}
+
+
 /*******************************************************************
  Inits an NET_R_GETDCNAME structure.
 ********************************************************************/
 void init_net_q_getdcname(NET_Q_GETDCNAME *r_t, const char *logon_server,
                          const char *domainname)
 {
-       DEBUG(5,("init_r_getdcname\n"));
+       DEBUG(5,("init_q_getdcname\n"));
 
-       r_t->ptr_logon_server = (logon_server != NULL);
        init_unistr2(&r_t->uni_logon_server, logon_server, UNI_STR_TERMINATE);
        r_t->ptr_domainname = (domainname != NULL);
        init_unistr2(&r_t->uni_domainname, domainname, UNI_STR_TERMINATE);
@@ -497,7 +583,7 @@ void init_net_q_getdcname(NET_Q_GETDCNAME *r_t, const char *logon_server,
  Reads or writes an NET_Q_GETDCNAME structure.
 ********************************************************************/
 
-BOOL net_io_q_getdcname(const char *desc, NET_Q_GETDCNAME *r_t, prs_struct *ps,
+bool net_io_q_getdcname(const char *desc, NET_Q_GETDCNAME *r_t, prs_struct *ps,
                        int depth)
 {
        if (r_t == NULL)
@@ -506,11 +592,8 @@ BOOL net_io_q_getdcname(const char *desc, NET_Q_GETDCNAME *r_t, prs_struct *ps,
        prs_debug(ps, depth, desc, "net_io_q_getdcname");
        depth++;
 
-       if (!prs_uint32("ptr_logon_server", ps, depth, &r_t->ptr_logon_server))
-               return False;
-
        if (!smb_io_unistr2("logon_server", &r_t->uni_logon_server,
-                           r_t->ptr_logon_server, ps, depth))
+                           1, ps, depth))
                return False;
 
        if (!prs_align(ps))
@@ -541,7 +624,7 @@ void init_net_r_getdcname(NET_R_GETDCNAME *r_t, const char *dcname)
  Reads or writes an NET_R_GETDCNAME structure.
 ********************************************************************/
 
-BOOL net_io_r_getdcname(const char *desc, NET_R_GETDCNAME *r_t, prs_struct *ps,
+bool net_io_r_getdcname(const char *desc, NET_R_GETDCNAME *r_t, prs_struct *ps,
                        int depth)
 {
        if (r_t == NULL)
@@ -560,7 +643,7 @@ BOOL net_io_r_getdcname(const char *desc, NET_R_GETDCNAME *r_t, prs_struct *ps,
        if (!prs_align(ps))
                return False;
 
-       if (!prs_ntstatus("status", ps, depth, &r_t->status))
+       if (!prs_werror("status", ps, depth, &r_t->status))
                return False;
 
        return True;
@@ -600,7 +683,7 @@ void init_r_trust_dom(NET_R_TRUST_DOM_LIST *r_t,
  Reads or writes an NET_R_TRUST_DOM_LIST structure.
 ********************************************************************/
 
-BOOL net_io_r_trust_dom(const char *desc, NET_R_TRUST_DOM_LIST *r_t, prs_struct *ps, int depth)
+bool net_io_r_trust_dom(const char *desc, NET_R_TRUST_DOM_LIST *r_t, prs_struct *ps, int depth)
 {
        uint32 value;
 
@@ -652,7 +735,7 @@ BOOL net_io_r_trust_dom(const char *desc, NET_R_TRUST_DOM_LIST *r_t, prs_struct
  Reads or writes an NET_Q_TRUST_DOM_LIST structure.
 ********************************************************************/
 
-BOOL net_io_q_trust_dom(const char *desc, NET_Q_TRUST_DOM_LIST *q_l, prs_struct *ps, int depth)
+bool net_io_q_trust_dom(const char *desc, NET_Q_TRUST_DOM_LIST *q_l, prs_struct *ps, int depth)
 {
        if (q_l == NULL)
                 return False;
@@ -692,7 +775,7 @@ void init_q_req_chal(NET_Q_REQ_CHAL *q_c,
  Reads or writes an NET_Q_REQ_CHAL structure.
 ********************************************************************/
 
-BOOL net_io_q_req_chal(const char *desc,  NET_Q_REQ_CHAL *q_c, prs_struct *ps, int depth)
+bool net_io_q_req_chal(const char *desc,  NET_Q_REQ_CHAL *q_c, prs_struct *ps, int depth)
 {
        if (q_c == NULL)
                return False;
@@ -721,7 +804,7 @@ BOOL net_io_q_req_chal(const char *desc,  NET_Q_REQ_CHAL *q_c, prs_struct *ps, i
  Reads or writes a structure.
 ********************************************************************/
 
-BOOL net_io_r_req_chal(const char *desc, NET_R_REQ_CHAL *r_c, prs_struct *ps, int depth)
+bool net_io_r_req_chal(const char *desc, NET_R_REQ_CHAL *r_c, prs_struct *ps, int depth)
 {
        if (r_c == NULL)
                return False;
@@ -746,7 +829,7 @@ BOOL net_io_r_req_chal(const char *desc, NET_R_REQ_CHAL *r_c, prs_struct *ps, in
  Reads or writes a structure.
 ********************************************************************/
 
-BOOL net_io_q_auth(const char *desc, NET_Q_AUTH *q_a, prs_struct *ps, int depth)
+bool net_io_q_auth(const char *desc, NET_Q_AUTH *q_a, prs_struct *ps, int depth)
 {
        if (q_a == NULL)
                return False;
@@ -769,7 +852,7 @@ BOOL net_io_q_auth(const char *desc, NET_Q_AUTH *q_a, prs_struct *ps, int depth)
  Reads or writes a structure.
 ********************************************************************/
 
-BOOL net_io_r_auth(const char *desc, NET_R_AUTH *r_a, prs_struct *ps, int depth)
+bool net_io_r_auth(const char *desc, NET_R_AUTH *r_a, prs_struct *ps, int depth)
 {
        if (r_a == NULL)
                return False;
@@ -810,7 +893,7 @@ void init_q_auth_2(NET_Q_AUTH_2 *q_a,
  Reads or writes a structure.
 ********************************************************************/
 
-BOOL net_io_q_auth_2(const char *desc, NET_Q_AUTH_2 *q_a, prs_struct *ps, int depth)
+bool net_io_q_auth_2(const char *desc, NET_Q_AUTH_2 *q_a, prs_struct *ps, int depth)
 {
        if (q_a == NULL)
                return False;
@@ -835,7 +918,7 @@ BOOL net_io_q_auth_2(const char *desc, NET_Q_AUTH_2 *q_a, prs_struct *ps, int de
  Reads or writes a structure.
 ********************************************************************/
 
-BOOL net_io_r_auth_2(const char *desc, NET_R_AUTH_2 *r_a, prs_struct *ps, int depth)
+bool net_io_r_auth_2(const char *desc, NET_R_AUTH_2 *r_a, prs_struct *ps, int depth)
 {
        if (r_a == NULL)
                return False;
@@ -878,7 +961,7 @@ void init_q_auth_3(NET_Q_AUTH_3 *q_a,
  Reads or writes a structure.
 ********************************************************************/
 
-BOOL net_io_q_auth_3(const char *desc, NET_Q_AUTH_3 *q_a, prs_struct *ps, int depth)
+bool net_io_q_auth_3(const char *desc, NET_Q_AUTH_3 *q_a, prs_struct *ps, int depth)
 {
        if (q_a == NULL)
                return False;
@@ -903,7 +986,7 @@ BOOL net_io_q_auth_3(const char *desc, NET_Q_AUTH_3 *q_a, prs_struct *ps, int de
  Reads or writes a structure.
 ********************************************************************/
 
-BOOL net_io_r_auth_3(const char *desc, NET_R_AUTH_3 *r_a, prs_struct *ps, int depth)
+bool net_io_r_auth_3(const char *desc, NET_R_AUTH_3 *r_a, prs_struct *ps, int depth)
 {
        if (r_a == NULL)
                return False;
@@ -953,7 +1036,7 @@ void init_q_srv_pwset(NET_Q_SRV_PWSET *q_s,
  Reads or writes a structure.
 ********************************************************************/
 
-BOOL net_io_q_srv_pwset(const char *desc, NET_Q_SRV_PWSET *q_s, prs_struct *ps, int depth)
+bool net_io_q_srv_pwset(const char *desc, NET_Q_SRV_PWSET *q_s, prs_struct *ps, int depth)
 {
        if (q_s == NULL)
                return False;
@@ -976,7 +1059,7 @@ BOOL net_io_q_srv_pwset(const char *desc, NET_Q_SRV_PWSET *q_s, prs_struct *ps,
  Reads or writes a structure.
 ********************************************************************/
 
-BOOL net_io_r_srv_pwset(const char *desc, NET_R_SRV_PWSET *r_s, prs_struct *ps, int depth)
+bool net_io_r_srv_pwset(const char *desc, NET_R_SRV_PWSET *r_s, prs_struct *ps, int depth)
 {
        if (r_s == NULL)
                return False;
@@ -1003,7 +1086,7 @@ BOOL net_io_r_srv_pwset(const char *desc, NET_R_SRV_PWSET *r_s, prs_struct *ps,
 static int init_dom_sid2s(TALLOC_CTX *ctx, const char *sids_str, DOM_SID2 **ppsids)
 {
        const char *ptr;
-       pstring s2;
+       char *s2;
        int count = 0;
 
        DEBUG(4,("init_dom_sid2s: %s\n", sids_str ? sids_str:""));
@@ -1013,22 +1096,31 @@ static int init_dom_sid2s(TALLOC_CTX *ctx, const char *sids_str, DOM_SID2 **ppsi
        if(sids_str) {
                int number;
                DOM_SID2 *sids;
+               TALLOC_CTX *frame = talloc_stackframe();
 
                /* Count the number of valid SIDs. */
-               for (count = 0, ptr = sids_str; next_token(&ptr, s2, NULL, sizeof(s2)); ) {
+               for (count = 0, ptr = sids_str;
+                               next_token_talloc(frame,&ptr, &s2, NULL); ) {
                        DOM_SID tmpsid;
                        if (string_to_sid(&tmpsid, s2))
                                count++;
                }
 
                /* Now allocate space for them. */
-               *ppsids = TALLOC_ZERO_ARRAY(ctx, DOM_SID2, count);
-               if (*ppsids == NULL)
-                       return 0;
+               if (count) {
+                       *ppsids = TALLOC_ZERO_ARRAY(ctx, DOM_SID2, count);
+                       if (*ppsids == NULL) {
+                               TALLOC_FREE(frame);
+                               return 0;
+                       }
+               } else {
+                       *ppsids = NULL;
+               }
 
                sids = *ppsids;
 
-               for (number = 0, ptr = sids_str; next_token(&ptr, s2, NULL, sizeof(s2)); ) {
+               for (number = 0, ptr = sids_str;
+                               next_token_talloc(frame, &ptr, &s2, NULL); ) {
                        DOM_SID tmpsid;
                        if (string_to_sid(&tmpsid, s2)) {
                                /* count only valid sids */
@@ -1036,6 +1128,7 @@ static int init_dom_sid2s(TALLOC_CTX *ctx, const char *sids_str, DOM_SID2 **ppsi
                                number++;
                        }
                }
+               TALLOC_FREE(frame);
        }
 
        return count;
@@ -1066,10 +1159,10 @@ void init_id_info1(NET_ID_INFO_1 *id, const char *domain_name,
                unsigned char key[16];
 #ifdef DEBUG_PASSWORD
                DEBUG(100,("lm cypher:"));
-               dump_data(100, (char *)lm_cypher, 16);
+               dump_data(100, lm_cypher, 16);
 
                DEBUG(100,("nt cypher:"));
-               dump_data(100, (char *)nt_cypher, 16);
+               dump_data(100, nt_cypher, 16);
 #endif
 
                memset(key, 0, 16);
@@ -1082,10 +1175,10 @@ void init_id_info1(NET_ID_INFO_1 *id, const char *domain_name,
 
 #ifdef DEBUG_PASSWORD
                DEBUG(100,("encrypt of lm owf password:"));
-               dump_data(100, (char *)lm_owf, 16);
+               dump_data(100, lm_owf, 16);
 
                DEBUG(100,("encrypt of nt owf password:"));
-               dump_data(100, (char *)nt_owf, 16);
+               dump_data(100, nt_owf, 16);
 #endif
                /* set up pointers to cypher blocks */
                lm_cypher = lm_owf;
@@ -1107,7 +1200,7 @@ void init_id_info1(NET_ID_INFO_1 *id, const char *domain_name,
  Reads or writes an NET_ID_INFO_1 structure.
 ********************************************************************/
 
-static BOOL net_io_id_info1(const char *desc,  NET_ID_INFO_1 *id, prs_struct *ps, int depth)
+static bool net_io_id_info1(const char *desc,  NET_ID_INFO_1 *id, prs_struct *ps, int depth)
 {
        if (id == NULL)
                return False;
@@ -1205,7 +1298,7 @@ void init_id_info2(NET_ID_INFO_2 * id, const char *domain_name,
  Reads or writes an NET_ID_INFO_2 structure.
 ********************************************************************/
 
-static BOOL net_io_id_info2(const char *desc,  NET_ID_INFO_2 *id, prs_struct *ps, int depth)
+static bool net_io_id_info2(const char *desc,  NET_ID_INFO_2 *id, prs_struct *ps, int depth)
 {
        if (id == NULL)
                return False;
@@ -1287,11 +1380,26 @@ void init_sam_info(DOM_SAM_INFO *sam,
        sam->ctr          = ctr;
 }
 
+/*******************************************************************
+ Inits a DOM_SAM_INFO structure.
+********************************************************************/
+
+void init_sam_info_ex(DOM_SAM_INFO_EX *sam,
+                     const char *logon_srv, const char *comp_name,
+                     uint16 logon_level, NET_ID_INFO_CTR *ctr)
+{
+       DEBUG(5,("init_sam_info_ex: %d\n", __LINE__));
+
+       init_clnt_srv(&sam->client, logon_srv, comp_name);
+       sam->logon_level  = logon_level;
+       sam->ctr          = ctr;
+}
+
 /*******************************************************************
  Reads or writes a DOM_SAM_INFO structure.
 ********************************************************************/
 
-static BOOL net_io_id_info_ctr(const char *desc, NET_ID_INFO_CTR **pp_ctr, prs_struct *ps, int depth)
+static bool net_io_id_info_ctr(const char *desc, NET_ID_INFO_CTR **pp_ctr, prs_struct *ps, int depth)
 {
        NET_ID_INFO_CTR *ctr = *pp_ctr;
 
@@ -1334,7 +1442,7 @@ static BOOL net_io_id_info_ctr(const char *desc, NET_ID_INFO_CTR **pp_ctr, prs_s
  Reads or writes a DOM_SAM_INFO structure.
  ********************************************************************/
 
-static BOOL smb_io_sam_info(const char *desc, DOM_SAM_INFO *sam, prs_struct *ps, int depth)
+static bool smb_io_sam_info(const char *desc, DOM_SAM_INFO *sam, prs_struct *ps, int depth)
 {
        if (sam == NULL)
                return False;
@@ -1370,7 +1478,7 @@ static BOOL smb_io_sam_info(const char *desc, DOM_SAM_INFO *sam, prs_struct *ps,
  Reads or writes a DOM_SAM_INFO_EX structure.
  ********************************************************************/
 
-static BOOL smb_io_sam_info_ex(const char *desc, DOM_SAM_INFO_EX *sam, prs_struct *ps, int depth)
+static bool smb_io_sam_info_ex(const char *desc, DOM_SAM_INFO_EX *sam, prs_struct *ps, int depth)
 {
        if (sam == NULL)
                return False;
@@ -1506,9 +1614,13 @@ void init_net_user_info3(TALLOC_CTX *ctx, NET_USER_INFO_3 *usr,
 
        usr->num_groups2 = num_groups;
 
-       usr->gids = TALLOC_ZERO_ARRAY(ctx,DOM_GID,num_groups);
-       if (usr->gids == NULL && num_groups>0)
-               return;
+       if (num_groups) {
+               usr->gids = TALLOC_ZERO_ARRAY(ctx,DOM_GID,num_groups);
+               if (usr->gids == NULL)
+                       return;
+       } else {
+               usr->gids = NULL;
+       }
 
        for (i = 0; i < num_groups; i++) 
                usr->gids[i] = gids[i]; 
@@ -1522,7 +1634,7 @@ void init_net_user_info3(TALLOC_CTX *ctx, NET_USER_INFO_3 *usr,
        /* "other" sids are set up above */
 }
 
- void dump_acct_flags(uint32 acct_flags) {
+static void dump_acct_flags(uint32 acct_flags) {
 
        int lvl = 10;
        DEBUG(lvl,("dump_acct_flags\n"));
@@ -1549,7 +1661,7 @@ void init_net_user_info3(TALLOC_CTX *ctx, NET_USER_INFO_3 *usr,
        }
 }
 
- void dump_user_flgs(uint32 user_flags) {
+static void dump_user_flgs(uint32 user_flags) {
 
        int lvl = 10;
        DEBUG(lvl,("dump_user_flgs\n"));
@@ -1583,8 +1695,8 @@ void init_net_user_info3(TALLOC_CTX *ctx, NET_USER_INFO_3 *usr,
  Jacobsen at HP. JRA.
 ********************************************************************/
 
-BOOL net_io_user_info3(const char *desc, NET_USER_INFO_3 *usr, prs_struct *ps, 
-                      int depth, uint16 validation_level, BOOL kerb_validation_level)
+bool net_io_user_info3(const char *desc, NET_USER_INFO_3 *usr, prs_struct *ps, 
+                      int depth, uint16 validation_level, bool kerb_validation_level)
 {
        unsigned int i;
 
@@ -1711,29 +1823,28 @@ BOOL net_io_user_info3(const char *desc, NET_USER_INFO_3 *usr, prs_struct *ps,
        if(!prs_align(ps))
                return False;
 
-       if (usr->num_groups > 0) {
-
-               if(!prs_uint32("num_groups2   ", ps, depth, &usr->num_groups2))        /* num groups2 */
-                       return False;
-
-               if (usr->num_groups != usr->num_groups2) {
-                       DEBUG(3,("net_io_user_info3: num_groups mismatch! (%d != %d)\n", 
-                       usr->num_groups, usr->num_groups2));
-                       return False;
-               }
+       if(!prs_uint32("num_groups2   ", ps, depth, &usr->num_groups2))        /* num groups2 */
+               return False;
 
+       if (usr->num_groups != usr->num_groups2) {
+               DEBUG(3,("net_io_user_info3: num_groups mismatch! (%d != %d)\n", 
+                        usr->num_groups, usr->num_groups2));
+               return False;
+       }
 
-               if (UNMARSHALLING(ps)) {
+       if (UNMARSHALLING(ps)) {
+               if (usr->num_groups) {
                        usr->gids = PRS_ALLOC_MEM(ps, DOM_GID, usr->num_groups);
                        if (usr->gids == NULL)
                                return False;
+               } else {
+                       usr->gids = NULL;
                }
+       }
 
-               for (i = 0; i < usr->num_groups; i++) {
-                       if(!smb_io_gid("", &usr->gids[i], ps, depth)) /* group info */
-                               return False;
-               }
-               
+       for (i = 0; i < usr->num_groups; i++) {
+               if(!smb_io_gid("", &usr->gids[i], ps, depth)) /* group info */
+                       return False;
        }
 
        if(!smb_io_unistr2("uni_logon_srv", &usr->uni_logon_srv, usr->hdr_logon_srv.buffer, ps, depth)) /* logon server unicode string */
@@ -1761,10 +1872,15 @@ BOOL net_io_user_info3(const char *desc, NET_USER_INFO_3 *usr, prs_struct *ps,
                        return False;
 
                if (UNMARSHALLING(ps)) {
-                       usr->other_sids = PRS_ALLOC_MEM(ps, DOM_SID2, usr->num_other_sids);
-                       usr->other_sids_attrib =
-                               PRS_ALLOC_MEM(ps, uint32, usr->num_other_sids);
-                                                              
+                       if (usr->num_other_sids) {
+                               usr->other_sids = PRS_ALLOC_MEM(ps, DOM_SID2, usr->num_other_sids);
+                               usr->other_sids_attrib =
+                                       PRS_ALLOC_MEM(ps, uint32, usr->num_other_sids);
+                       } else {
+                               usr->other_sids = NULL;
+                               usr->other_sids_attrib = NULL;
+                       }
+
                        if ((num_other_sids != 0) &&
                            ((usr->other_sids == NULL) ||
                             (usr->other_sids_attrib == NULL)))
@@ -1804,7 +1920,7 @@ BOOL net_io_user_info3(const char *desc, NET_USER_INFO_3 *usr, prs_struct *ps,
  Reads or writes a structure.
 ********************************************************************/
 
-BOOL net_io_q_sam_logon(const char *desc, NET_Q_SAM_LOGON *q_l, prs_struct *ps, int depth)
+bool net_io_q_sam_logon(const char *desc, NET_Q_SAM_LOGON *q_l, prs_struct *ps, int depth)
 {
        if (q_l == NULL)
                return False;
@@ -1831,7 +1947,7 @@ BOOL net_io_q_sam_logon(const char *desc, NET_Q_SAM_LOGON *q_l, prs_struct *ps,
  Reads or writes a structure.
 ********************************************************************/
 
-BOOL net_io_r_sam_logon(const char *desc, NET_R_SAM_LOGON *r_l, prs_struct *ps, int depth)
+bool net_io_r_sam_logon(const char *desc, NET_R_SAM_LOGON *r_l, prs_struct *ps, int depth)
 {
        if (r_l == NULL)
                return False;
@@ -1877,7 +1993,7 @@ BOOL net_io_r_sam_logon(const char *desc, NET_R_SAM_LOGON *r_l, prs_struct *ps,
  Reads or writes a structure.
 ********************************************************************/
 
-BOOL net_io_q_sam_logon_ex(const char *desc, NET_Q_SAM_LOGON_EX *q_l, prs_struct *ps, int depth)
+bool net_io_q_sam_logon_ex(const char *desc, NET_Q_SAM_LOGON_EX *q_l, prs_struct *ps, int depth)
 {
        if (q_l == NULL)
                return False;
@@ -1897,6 +2013,9 @@ BOOL net_io_q_sam_logon_ex(const char *desc, NET_Q_SAM_LOGON_EX *q_l, prs_struct
        if(!prs_uint16("validation_level", ps, depth, &q_l->validation_level))
                return False;
 
+       if (!prs_align(ps))
+               return False;
+
        if(!prs_uint32("flags  ", ps, depth, &q_l->flags))
                return False;
 
@@ -1907,7 +2026,7 @@ BOOL net_io_q_sam_logon_ex(const char *desc, NET_Q_SAM_LOGON_EX *q_l, prs_struct
  Reads or writes a structure.
 ********************************************************************/
 
-BOOL net_io_r_sam_logon_ex(const char *desc, NET_R_SAM_LOGON_EX *r_l, prs_struct *ps, int depth)
+bool net_io_r_sam_logon_ex(const char *desc, NET_R_SAM_LOGON_EX *r_l, prs_struct *ps, int depth)
 {
        if (r_l == NULL)
                return False;
@@ -1950,7 +2069,7 @@ BOOL net_io_r_sam_logon_ex(const char *desc, NET_R_SAM_LOGON_EX *r_l, prs_struct
  Reads or writes a structure.
 ********************************************************************/
 
-BOOL net_io_q_sam_logoff(const char *desc,  NET_Q_SAM_LOGOFF *q_l, prs_struct *ps, int depth)
+bool net_io_q_sam_logoff(const char *desc,  NET_Q_SAM_LOGOFF *q_l, prs_struct *ps, int depth)
 {
        if (q_l == NULL)
                return False;
@@ -1971,7 +2090,7 @@ BOOL net_io_q_sam_logoff(const char *desc,  NET_Q_SAM_LOGOFF *q_l, prs_struct *p
  Reads or writes a structure.
 ********************************************************************/
 
-BOOL net_io_r_sam_logoff(const char *desc, NET_R_SAM_LOGOFF *r_l, prs_struct *ps, int depth)
+bool net_io_r_sam_logoff(const char *desc, NET_R_SAM_LOGOFF *r_l, prs_struct *ps, int depth)
 {
        if (r_l == NULL)
                return False;
@@ -1996,7 +2115,7 @@ BOOL net_io_r_sam_logoff(const char *desc, NET_R_SAM_LOGOFF *r_l, prs_struct *ps
 /*******************************************************************
 makes a NET_Q_SAM_SYNC structure.
 ********************************************************************/
-BOOL init_net_q_sam_sync(NET_Q_SAM_SYNC * q_s, const char *srv_name,
+bool init_net_q_sam_sync(NET_Q_SAM_SYNC * q_s, const char *srv_name,
                          const char *cli_name, DOM_CRED *cli_creds, 
                          DOM_CRED *ret_creds, uint32 database_id, 
                         uint32 next_rid)
@@ -2025,7 +2144,7 @@ BOOL init_net_q_sam_sync(NET_Q_SAM_SYNC * q_s, const char *srv_name,
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-BOOL net_io_q_sam_sync(const char *desc, NET_Q_SAM_SYNC * q_s, prs_struct *ps,
+bool net_io_q_sam_sync(const char *desc, NET_Q_SAM_SYNC * q_s, prs_struct *ps,
                       int depth)
 {
        prs_debug(ps, depth, desc, "net_io_q_sam_sync");
@@ -2057,7 +2176,7 @@ BOOL net_io_q_sam_sync(const char *desc, NET_Q_SAM_SYNC * q_s, prs_struct *ps,
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-static BOOL net_io_sam_delta_hdr(const char *desc, SAM_DELTA_HDR * delta,
+static bool net_io_sam_delta_hdr(const char *desc, SAM_DELTA_HDR * delta,
                                 prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "net_io_sam_delta_hdr");
@@ -2087,7 +2206,7 @@ static BOOL net_io_sam_delta_hdr(const char *desc, SAM_DELTA_HDR * delta,
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-static BOOL net_io_sam_delta_mod_count(const char *desc, SAM_DELTA_MOD_COUNT *info,
+static bool net_io_sam_delta_mod_count(const char *desc, SAM_DELTA_MOD_COUNT *info,
                                    prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "net_io_sam_delta_stamp");
@@ -2111,7 +2230,7 @@ static BOOL net_io_sam_delta_mod_count(const char *desc, SAM_DELTA_MOD_COUNT *in
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-static BOOL net_io_sam_domain_info(const char *desc, SAM_DOMAIN_INFO * info,
+static bool net_io_sam_domain_info(const char *desc, SAM_DOMAIN_INFO * info,
                                   prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "net_io_sam_domain_info");
@@ -2187,7 +2306,7 @@ static BOOL net_io_sam_domain_info(const char *desc, SAM_DOMAIN_INFO * info,
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-static BOOL net_io_sam_group_info(const char *desc, SAM_GROUP_INFO * info,
+static bool net_io_sam_group_info(const char *desc, SAM_GROUP_INFO * info,
                                  prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "net_io_sam_group_info");
@@ -2221,7 +2340,7 @@ static BOOL net_io_sam_group_info(const char *desc, SAM_GROUP_INFO * info,
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-static BOOL net_io_sam_passwd_info(const char *desc, SAM_PWD * pwd,
+static bool net_io_sam_passwd_info(const char *desc, SAM_PWD * pwd,
                                   prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "net_io_sam_passwd_info");
@@ -2251,7 +2370,7 @@ static BOOL net_io_sam_passwd_info(const char *desc, SAM_PWD * pwd,
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-static BOOL net_io_sam_account_info(const char *desc, SAM_ACCOUNT_INFO *info,
+static bool net_io_sam_account_info(const char *desc, SAM_ACCOUNT_INFO *info,
                                prs_struct *ps, int depth)
 {
        BUFHDR2 hdr_priv_data;
@@ -2439,7 +2558,7 @@ static BOOL net_io_sam_account_info(const char *desc, SAM_ACCOUNT_INFO *info,
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-static BOOL net_io_sam_group_mem_info(const char *desc, SAM_GROUP_MEM_INFO * info,
+static bool net_io_sam_group_mem_info(const char *desc, SAM_GROUP_MEM_INFO * info,
                                      prs_struct *ps, int depth)
 {
        uint32 i;
@@ -2472,13 +2591,19 @@ static BOOL net_io_sam_group_mem_info(const char *desc, SAM_GROUP_MEM_INFO * inf
                        return False;
                }
 
-                info->rids = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_members2);
-
-                if (info->rids == NULL) {
-                        DEBUG(0, ("out of memory allocating %d rids\n",
-                                  info->num_members2));
-                        return False;
-                }
+               if (UNMARSHALLING(ps)) {
+                       if (info->num_members2) {
+                               info->rids = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_members2);
+
+                               if (info->rids == NULL) {
+                                       DEBUG(0, ("out of memory allocating %d rids\n",
+                                               info->num_members2));
+                                       return False;
+                               }
+                       } else {
+                               info->rids = NULL;
+                       }
+               }
 
                for (i = 0; i < info->num_members2; i++)
                {
@@ -2499,13 +2624,19 @@ static BOOL net_io_sam_group_mem_info(const char *desc, SAM_GROUP_MEM_INFO * inf
                        return False;
                }
 
-                info->attribs = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_members3);
-
-                if (info->attribs == NULL) {
-                        DEBUG(0, ("out of memory allocating %d attribs\n",
-                                  info->num_members3));
-                        return False;
-                }
+               if (UNMARSHALLING(ps)) {
+                       if (info->num_members3) {
+                               info->attribs = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_members3);
+
+                               if (info->attribs == NULL) {
+                                       DEBUG(0, ("out of memory allocating %d attribs\n",
+                                               info->num_members3));
+                                       return False;
+                               }
+                       } else {
+                               info->attribs = NULL;
+                       }
+               }       
 
                for (i = 0; i < info->num_members3; i++)
                {
@@ -2521,7 +2652,7 @@ static BOOL net_io_sam_group_mem_info(const char *desc, SAM_GROUP_MEM_INFO * inf
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-static BOOL net_io_sam_alias_info(const char *desc, SAM_ALIAS_INFO * info,
+static bool net_io_sam_alias_info(const char *desc, SAM_ALIAS_INFO * info,
                                  prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "net_io_sam_alias_info");
@@ -2556,7 +2687,7 @@ static BOOL net_io_sam_alias_info(const char *desc, SAM_ALIAS_INFO * info,
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-static BOOL net_io_sam_alias_mem_info(const char *desc, SAM_ALIAS_MEM_INFO * info,
+static bool net_io_sam_alias_mem_info(const char *desc, SAM_ALIAS_MEM_INFO * info,
                                      prs_struct *ps, int depth)
 {
        uint32 i;
@@ -2585,13 +2716,19 @@ static BOOL net_io_sam_alias_mem_info(const char *desc, SAM_ALIAS_MEM_INFO * inf
                        return False;
                }
 
-                info->ptr_sids = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_sids);
+               if (UNMARSHALLING(ps)) {
+                       if (info->num_sids) {
+                               info->ptr_sids = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_sids);
                 
-                if (info->ptr_sids == NULL) {
-                        DEBUG(0, ("out of memory allocating %d ptr_sids\n",
-                                  info->num_sids));
-                        return False;
-                }
+                               if (info->ptr_sids == NULL) {
+                                       DEBUG(0, ("out of memory allocating %d ptr_sids\n",
+                                               info->num_sids));
+                                       return False;
+                               }
+                       } else {
+                               info->ptr_sids = NULL;
+                       }
+               }
 
                for (i = 0; i < info->num_sids; i++)
                {
@@ -2600,13 +2737,19 @@ static BOOL net_io_sam_alias_mem_info(const char *desc, SAM_ALIAS_MEM_INFO * inf
                                 return False;
                }
 
-                info->sids = TALLOC_ARRAY(ps->mem_ctx, DOM_SID2, info->num_sids);
-
-                if (info->sids == NULL) {
-                        DEBUG(0, ("error allocating %d sids\n",
-                                  info->num_sids));
-                        return False;
-                }
+               if (UNMARSHALLING(ps)) {
+                       if (info->num_sids) {
+                               info->sids = TALLOC_ARRAY(ps->mem_ctx, DOM_SID2, info->num_sids);
+
+                               if (info->sids == NULL) {
+                                       DEBUG(0, ("error allocating %d sids\n",
+                                               info->num_sids));
+                                       return False;
+                               }
+                       } else {
+                               info->sids = NULL;
+                       }
+               }
 
                for (i = 0; i < info->num_sids; i++)
                {
@@ -2627,7 +2770,7 @@ static BOOL net_io_sam_alias_mem_info(const char *desc, SAM_ALIAS_MEM_INFO * inf
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-static BOOL net_io_sam_policy_info(const char *desc, SAM_DELTA_POLICY *info,
+static bool net_io_sam_policy_info(const char *desc, SAM_DELTA_POLICY *info,
                                      prs_struct *ps, int depth)
 {
        unsigned int i;
@@ -2716,7 +2859,7 @@ static BOOL net_io_sam_policy_info(const char *desc, SAM_DELTA_POLICY *info,
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-static BOOL net_io_sam_trustdoms_info(const char *desc, SAM_DELTA_TRUSTDOMS *info,
+static bool net_io_sam_trustdoms_info(const char *desc, SAM_DELTA_TRUSTDOMS *info,
                                      prs_struct *ps, int depth)
 {
        int i;
@@ -2770,7 +2913,7 @@ static BOOL net_io_sam_trustdoms_info(const char *desc, SAM_DELTA_TRUSTDOMS *inf
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-static BOOL net_io_sam_secret_info(const char *desc, SAM_DELTA_SECRET *info,
+static bool net_io_sam_secret_info(const char *desc, SAM_DELTA_SECRET *info,
                                   prs_struct *ps, int depth)
 {
        int i;
@@ -2859,7 +3002,7 @@ static BOOL net_io_sam_secret_info(const char *desc, SAM_DELTA_SECRET *info,
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-static BOOL net_io_sam_privs_info(const char *desc, SAM_DELTA_PRIVS *info,
+static bool net_io_sam_privs_info(const char *desc, SAM_DELTA_PRIVS *info,
                                      prs_struct *ps, int depth)
 {
        unsigned int i;
@@ -2916,7 +3059,16 @@ static BOOL net_io_sam_privs_info(const char *desc, SAM_DELTA_PRIVS *info,
        if(!prs_uint32("attribute_count", ps, depth, &info->attribute_count))
                 return False;
 
-       info->attributes = TALLOC_ARRAY(ps->mem_ctx, uint32, info->attribute_count);
+       if (UNMARSHALLING(ps)) {
+               if (info->attribute_count) {
+                       info->attributes = TALLOC_ARRAY(ps->mem_ctx, uint32, info->attribute_count);
+                       if (!info->attributes) {
+                               return False;
+                       }
+               } else {
+                       info->attributes = NULL;
+               }
+       }
 
        for (i=0; i<info->attribute_count; i++)
                if(!prs_uint32("attributes", ps, depth, &info->attributes[i]))
@@ -2925,8 +3077,21 @@ static BOOL net_io_sam_privs_info(const char *desc, SAM_DELTA_PRIVS *info,
        if(!prs_uint32("privlist_count", ps, depth, &info->privlist_count))
                 return False;
 
-       info->hdr_privslist = TALLOC_ARRAY(ps->mem_ctx, UNIHDR, info->privlist_count);
-       info->uni_privslist = TALLOC_ARRAY(ps->mem_ctx, UNISTR2, info->privlist_count);
+       if (UNMARSHALLING(ps)) {
+               if (info->privlist_count) {
+                       info->hdr_privslist = TALLOC_ARRAY(ps->mem_ctx, UNIHDR, info->privlist_count);
+                       info->uni_privslist = TALLOC_ARRAY(ps->mem_ctx, UNISTR2, info->privlist_count);
+                       if (!info->hdr_privslist) {
+                               return False;
+                       }
+                       if (!info->uni_privslist) {
+                               return False;
+                       }
+               } else {
+                       info->hdr_privslist = NULL;
+                       info->uni_privslist = NULL;
+               }
+       }
 
        for (i=0; i<info->privlist_count; i++)
                if(!smb_io_unihdr("hdr_privslist", &info->hdr_privslist[i], ps, depth))
@@ -2945,7 +3110,7 @@ static BOOL net_io_sam_privs_info(const char *desc, SAM_DELTA_PRIVS *info,
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-static BOOL net_io_sam_delta_ctr(const char *desc,
+static bool net_io_sam_delta_ctr(const char *desc,
                                 SAM_DELTA_CTR * delta, uint16 type,
                                 prs_struct *ps, int depth)
 {
@@ -3023,7 +3188,7 @@ static BOOL net_io_sam_delta_ctr(const char *desc,
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-BOOL net_io_r_sam_sync(const char *desc,
+bool net_io_r_sam_sync(const char *desc,
                       NET_R_SAM_SYNC * r_s, prs_struct *ps, int depth)
 {
        uint32 i;
@@ -3056,15 +3221,19 @@ BOOL net_io_r_sam_sync(const char *desc,
                                return False;
                        }
 
-                        if (r_s->num_deltas2 > 0) {
-                                r_s->hdr_deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_HDR, r_s->num_deltas2);
-                                if (r_s->hdr_deltas == NULL) {
-                                        DEBUG(0, ("error tallocating memory "
-                                                  "for %d delta headers\n", 
-                                                  r_s->num_deltas2));
-                                        return False;
-                                }
-                        }
+                       if (UNMARSHALLING(ps)) {
+                               if (r_s->num_deltas2) {
+                                       r_s->hdr_deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_HDR, r_s->num_deltas2);
+                                       if (r_s->hdr_deltas == NULL) {
+                                               DEBUG(0, ("error tallocating memory "
+                                                       "for %d delta headers\n", 
+                                                       r_s->num_deltas2));
+                                               return False;
+                                       }
+                               } else {
+                                       r_s->hdr_deltas = NULL;
+                               }
+                       }
 
                        for (i = 0; i < r_s->num_deltas2; i++)
                        {
@@ -3074,15 +3243,19 @@ BOOL net_io_r_sam_sync(const char *desc,
                                         return False;
                        }
 
-                        if (r_s->num_deltas2 > 0) {
-                                r_s->deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_CTR, r_s->num_deltas2);
-                                if (r_s->deltas == NULL) {
-                                        DEBUG(0, ("error tallocating memory "
-                                                  "for %d deltas\n", 
-                                                  r_s->num_deltas2));
-                                        return False;
-                                }
-                        }
+                       if (UNMARSHALLING(ps)) {
+                               if (r_s->num_deltas2) {
+                                       r_s->deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_CTR, r_s->num_deltas2);
+                                       if (r_s->deltas == NULL) {
+                                               DEBUG(0, ("error tallocating memory "
+                                                       "for %d deltas\n", 
+                                                       r_s->num_deltas2));
+                                               return False;
+                                       }
+                               } else {
+                                       r_s->deltas = NULL;
+                               }
+                       }
 
                        for (i = 0; i < r_s->num_deltas2; i++)
                        {
@@ -3107,9 +3280,9 @@ BOOL net_io_r_sam_sync(const char *desc,
 /*******************************************************************
 makes a NET_Q_SAM_DELTAS structure.
 ********************************************************************/
-BOOL init_net_q_sam_deltas(NET_Q_SAM_DELTAS *q_s, const char *srv_name, 
+bool init_net_q_sam_deltas(NET_Q_SAM_DELTAS *q_s, const char *srv_name, 
                            const char *cli_name, DOM_CRED *cli_creds, 
-                           uint32 database_id, UINT64_S dom_mod_count)
+                           uint32 database_id, uint64 dom_mod_count)
 {
        DEBUG(5, ("init_net_q_sam_deltas\n"));
 
@@ -3120,8 +3293,7 @@ BOOL init_net_q_sam_deltas(NET_Q_SAM_DELTAS *q_s, const char *srv_name,
        memset(&q_s->ret_creds, 0, sizeof(q_s->ret_creds));
 
        q_s->database_id = database_id;
-        q_s->dom_mod_count.low = dom_mod_count.low;
-        q_s->dom_mod_count.high = dom_mod_count.high;
+    q_s->dom_mod_count = dom_mod_count;
        q_s->max_size = 0xffff;
 
        return True;
@@ -3130,7 +3302,7 @@ BOOL init_net_q_sam_deltas(NET_Q_SAM_DELTAS *q_s, const char *srv_name,
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-BOOL net_io_q_sam_deltas(const char *desc, NET_Q_SAM_DELTAS *q_s, prs_struct *ps,
+bool net_io_q_sam_deltas(const char *desc, NET_Q_SAM_DELTAS *q_s, prs_struct *ps,
                          int depth)
 {
        prs_debug(ps, depth, desc, "net_io_q_sam_deltas");
@@ -3159,7 +3331,7 @@ BOOL net_io_q_sam_deltas(const char *desc, NET_Q_SAM_DELTAS *q_s, prs_struct *ps
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-BOOL net_io_r_sam_deltas(const char *desc,
+bool net_io_r_sam_deltas(const char *desc,
                          NET_R_SAM_DELTAS *r_s, prs_struct *ps, int depth)
 {
         unsigned int i;
@@ -3186,15 +3358,19 @@ BOOL net_io_r_sam_deltas(const char *desc,
 
                if (r_s->ptr_deltas != 0)
                {
-                        if (r_s->num_deltas > 0) {
-                                r_s->hdr_deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_HDR, r_s->num_deltas);
-                                if (r_s->hdr_deltas == NULL) {
-                                        DEBUG(0, ("error tallocating memory "
-                                                  "for %d delta headers\n", 
-                                                  r_s->num_deltas));
-                                        return False;
-                                }
-                        }
+                       if (UNMARSHALLING(ps)) {
+                               if (r_s->num_deltas) {
+                                       r_s->hdr_deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_HDR, r_s->num_deltas);
+                                       if (r_s->hdr_deltas == NULL) {
+                                               DEBUG(0, ("error tallocating memory "
+                                                       "for %d delta headers\n", 
+                                                       r_s->num_deltas));
+                                               return False;
+                                       }
+                               } else {
+                                       r_s->hdr_deltas = NULL;
+                               }
+                       }
 
                        for (i = 0; i < r_s->num_deltas; i++)
                        {
@@ -3202,15 +3378,19 @@ BOOL net_io_r_sam_deltas(const char *desc,
                                                       ps, depth);
                        }
                         
-                        if (r_s->num_deltas > 0) {
-                                r_s->deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_CTR, r_s->num_deltas);
-                                if (r_s->deltas == NULL) {
-                                        DEBUG(0, ("error tallocating memory "
-                                                  "for %d deltas\n", 
-                                                  r_s->num_deltas));
-                                        return False;
-                                }
-                        }
+                       if (UNMARSHALLING(ps)) {
+                               if (r_s->num_deltas) {
+                                       r_s->deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_CTR, r_s->num_deltas);
+                                       if (r_s->deltas == NULL) {
+                                               DEBUG(0, ("error tallocating memory "
+                                                       "for %d deltas\n", 
+                                                       r_s->num_deltas));
+                                               return False;
+                                       }
+                               } else {
+                                       r_s->deltas = NULL;
+                               }
+                       }
 
                        for (i = 0; i < r_s->num_deltas; i++)
                        {
@@ -3238,8 +3418,8 @@ BOOL net_io_r_sam_deltas(const char *desc,
 
 void init_net_q_dsr_getdcname(NET_Q_DSR_GETDCNAME *r_t, const char *server_unc,
                              const char *domain_name,
-                             struct uuid *domain_guid,
-                             struct uuid *site_guid,
+                             struct GUID *domain_guid,
+                             struct GUID *site_guid,
                              uint32_t flags)
 {
        DEBUG(5, ("init_net_q_dsr_getdcname\n"));
@@ -3259,11 +3439,72 @@ void init_net_q_dsr_getdcname(NET_Q_DSR_GETDCNAME *r_t, const char *server_unc,
        r_t->flags = flags;
 }
 
+/*******************************************************************
+ Inits a NET_Q_DSR_GETDCNAMEEX structure.
+********************************************************************/
+
+void init_net_q_dsr_getdcnameex(NET_Q_DSR_GETDCNAMEEX *r_t, const char *server_unc,
+                               const char *domain_name,
+                               struct GUID *domain_guid,
+                               const char *site_name,
+                               uint32_t flags)
+{
+       DEBUG(5, ("init_net_q_dsr_getdcnameex\n"));
+
+       r_t->ptr_server_unc = (server_unc != NULL);
+       init_unistr2(&r_t->uni_server_unc, server_unc, UNI_STR_TERMINATE);
+
+       r_t->ptr_domain_name = (domain_name != NULL);
+       init_unistr2(&r_t->uni_domain_name, domain_name, UNI_STR_TERMINATE);
+
+       r_t->ptr_domain_guid = (domain_guid != NULL);
+       r_t->domain_guid = domain_guid;
+
+       r_t->ptr_site_name = (site_name != NULL);
+       init_unistr2(&r_t->uni_site_name, site_name, UNI_STR_TERMINATE);
+
+       r_t->flags = flags;
+}
+
+/*******************************************************************
+ Inits a NET_Q_DSR_GETDCNAMEEX2 structure.
+********************************************************************/
+
+void init_net_q_dsr_getdcnameex2(NET_Q_DSR_GETDCNAMEEX2 *r_t, const char *server_unc,
+                                const char *domain_name,
+                                const char *client_account,
+                                uint32 mask,
+                                struct GUID *domain_guid,
+                                const char *site_name,
+                                uint32_t flags)
+{
+       DEBUG(5, ("init_net_q_dsr_getdcnameex2\n"));
+
+       r_t->ptr_server_unc = (server_unc != NULL);
+       init_unistr2(&r_t->uni_server_unc, server_unc, UNI_STR_TERMINATE);
+
+       r_t->ptr_client_account = (client_account != NULL);
+       init_unistr2(&r_t->uni_client_account, client_account, UNI_STR_TERMINATE);
+
+       r_t->mask = mask;
+
+       r_t->ptr_domain_name = (domain_name != NULL);
+       init_unistr2(&r_t->uni_domain_name, domain_name, UNI_STR_TERMINATE);
+
+       r_t->ptr_domain_guid = (domain_guid != NULL);
+       r_t->domain_guid = domain_guid;
+
+       r_t->ptr_site_name = (site_name != NULL);
+       init_unistr2(&r_t->uni_site_name, site_name, UNI_STR_TERMINATE);
+
+       r_t->flags = flags;
+}
+
 /*******************************************************************
  Reads or writes an NET_Q_DSR_GETDCNAME structure.
 ********************************************************************/
 
-BOOL net_io_q_dsr_getdcname(const char *desc, NET_Q_DSR_GETDCNAME *r_t,
+bool net_io_q_dsr_getdcname(const char *desc, NET_Q_DSR_GETDCNAME *r_t,
                            prs_struct *ps, int depth)
 {
        if (r_t == NULL)
@@ -3296,7 +3537,7 @@ BOOL net_io_q_dsr_getdcname(const char *desc, NET_Q_DSR_GETDCNAME *r_t,
                return False;
 
        if (UNMARSHALLING(ps) && (r_t->ptr_domain_guid)) {
-               r_t->domain_guid = PRS_ALLOC_MEM(ps, struct uuid, 1);
+               r_t->domain_guid = PRS_ALLOC_MEM(ps, struct GUID, 1);
                if (r_t->domain_guid == NULL)
                        return False;
        }
@@ -3312,7 +3553,7 @@ BOOL net_io_q_dsr_getdcname(const char *desc, NET_Q_DSR_GETDCNAME *r_t,
                return False;
 
        if (UNMARSHALLING(ps) && (r_t->ptr_site_guid)) {
-               r_t->site_guid = PRS_ALLOC_MEM(ps, struct uuid, 1);
+               r_t->site_guid = PRS_ALLOC_MEM(ps, struct GUID, 1);
                if (r_t->site_guid == NULL)
                        return False;
        }
@@ -3330,12 +3571,160 @@ BOOL net_io_q_dsr_getdcname(const char *desc, NET_Q_DSR_GETDCNAME *r_t,
        return True;
 }
 
+/*******************************************************************
+ Reads or writes an NET_Q_DSR_GETDCNAMEEX structure.
+********************************************************************/
+
+bool net_io_q_dsr_getdcnameex(const char *desc, NET_Q_DSR_GETDCNAMEEX *r_t,
+                             prs_struct *ps, int depth)
+{
+       if (r_t == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "net_io_q_dsr_getdcnameex");
+       depth++;
+
+       if (!prs_uint32("ptr_server_unc", ps, depth, &r_t->ptr_server_unc))
+               return False;
+
+       if (!smb_io_unistr2("server_unc", &r_t->uni_server_unc,
+                           r_t->ptr_server_unc, ps, depth))
+               return False;
+
+       if (!prs_align(ps))
+               return False;
+
+       if (!prs_uint32("ptr_domain_name", ps, depth, &r_t->ptr_domain_name))
+               return False;
+
+       if (!smb_io_unistr2("domain_name", &r_t->uni_domain_name,
+                           r_t->ptr_domain_name, ps, depth))
+               return False;
+
+       if (!prs_align(ps))
+               return False;
+
+       if (!prs_uint32("ptr_domain_guid", ps, depth, &r_t->ptr_domain_guid))
+               return False;
+
+       if (UNMARSHALLING(ps) && (r_t->ptr_domain_guid)) {
+               r_t->domain_guid = PRS_ALLOC_MEM(ps, struct GUID, 1);
+               if (r_t->domain_guid == NULL)
+                       return False;
+       }
+
+       if ((r_t->ptr_domain_guid) &&
+           (!smb_io_uuid("domain_guid", r_t->domain_guid, ps, depth)))
+               return False;
+
+       if (!prs_align(ps))
+               return False;
+
+       if (!prs_uint32("ptr_site_name", ps, depth, &r_t->ptr_site_name))
+               return False;
+
+       if (!smb_io_unistr2("site_name", &r_t->uni_site_name,
+                           r_t->ptr_site_name, ps, depth))
+               return False;
+
+       if (!prs_align(ps))
+               return False;
+
+       if (!prs_uint32("flags", ps, depth, &r_t->flags))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+ Reads or writes an NET_Q_DSR_GETDCNAMEEX2 structure.
+********************************************************************/
+
+bool net_io_q_dsr_getdcnameex2(const char *desc, NET_Q_DSR_GETDCNAMEEX2 *r_t,
+                              prs_struct *ps, int depth)
+{
+       if (r_t == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "net_io_q_dsr_getdcnameex2");
+       depth++;
+
+       if (!prs_uint32("ptr_server_unc", ps, depth, &r_t->ptr_server_unc))
+               return False;
+
+       if (!smb_io_unistr2("server_unc", &r_t->uni_server_unc,
+                           r_t->ptr_server_unc, ps, depth))
+               return False;
+
+       if (!prs_align(ps))
+               return False;
+
+       if (!prs_uint32("ptr_client_account", ps, depth, &r_t->ptr_client_account))
+               return False;
+
+       if (!smb_io_unistr2("client_account", &r_t->uni_client_account,
+                           r_t->ptr_client_account, ps, depth))
+               return False;
+
+       if (!prs_align(ps))
+               return False;
+
+       if (!prs_uint32("mask", ps, depth, &r_t->mask))
+               return False;
+
+       if (!prs_align(ps))
+               return False;
+
+       if (!prs_uint32("ptr_domain_name", ps, depth, &r_t->ptr_domain_name))
+               return False;
+
+       if (!smb_io_unistr2("domain_name", &r_t->uni_domain_name,
+                           r_t->ptr_domain_name, ps, depth))
+               return False;
+
+       if (!prs_align(ps))
+               return False;
+
+       if (!prs_uint32("ptr_domain_guid", ps, depth, &r_t->ptr_domain_guid))
+               return False;
+
+       if (UNMARSHALLING(ps) && (r_t->ptr_domain_guid)) {
+               r_t->domain_guid = PRS_ALLOC_MEM(ps, struct GUID, 1);
+               if (r_t->domain_guid == NULL)
+                       return False;
+       }
+
+       if ((r_t->ptr_domain_guid) &&
+           (!smb_io_uuid("domain_guid", r_t->domain_guid, ps, depth)))
+               return False;
+
+       if (!prs_align(ps))
+               return False;
+
+       if (!prs_uint32("ptr_site_name", ps, depth, &r_t->ptr_site_name))
+               return False;
+
+       if (!smb_io_unistr2("site_name", &r_t->uni_site_name,
+                           r_t->ptr_site_name, ps, depth))
+               return False;
+
+       if (!prs_align(ps))
+               return False;
+
+       if (!prs_uint32("flags", ps, depth, &r_t->flags))
+               return False;
+
+       return True;
+}
+
+
+
 /*******************************************************************
  Inits a NET_R_DSR_GETDCNAME structure.
 ********************************************************************/
 void init_net_r_dsr_getdcname(NET_R_DSR_GETDCNAME *r_t, const char *dc_unc,
                              const char *dc_address, int32 dc_address_type,
-                             struct uuid domain_guid, const char *domain_name,
+                             struct GUID domain_guid, const char *domain_name,
                              const char *forest_name, uint32 dc_flags,
                              const char *dc_site_name,
                              const char *client_site_name)
@@ -3371,7 +3760,7 @@ void init_net_r_dsr_getdcname(NET_R_DSR_GETDCNAME *r_t, const char *dc_unc,
  Reads or writes an NET_R_DSR_GETDCNAME structure.
 ********************************************************************/
 
-BOOL net_io_r_dsr_getdcname(const char *desc, NET_R_DSR_GETDCNAME *r_t,
+bool net_io_r_dsr_getdcname(const char *desc, NET_R_DSR_GETDCNAME *r_t,
                            prs_struct *ps, int depth)
 {
        uint32 info_ptr = 1;
@@ -3484,7 +3873,7 @@ void init_net_q_dsr_getsitename(NET_Q_DSR_GETSITENAME *r_t, const char *computer
  Reads or writes an NET_Q_DSR_GETSITENAME structure.
 ********************************************************************/
 
-BOOL net_io_q_dsr_getsitename(const char *desc, NET_Q_DSR_GETSITENAME *r_t,
+bool net_io_q_dsr_getsitename(const char *desc, NET_Q_DSR_GETSITENAME *r_t,
                              prs_struct *ps, int depth)
 {
        if (r_t == NULL)
@@ -3510,7 +3899,7 @@ BOOL net_io_q_dsr_getsitename(const char *desc, NET_Q_DSR_GETSITENAME *r_t,
  Reads or writes an NET_R_DSR_GETSITENAME structure.
 ********************************************************************/
 
-BOOL net_io_r_dsr_getsitename(const char *desc, NET_R_DSR_GETSITENAME *r_t,
+bool net_io_r_dsr_getsitename(const char *desc, NET_R_DSR_GETSITENAME *r_t,
                              prs_struct *ps, int depth)
 {
        if (r_t == NULL)