r23779: Change from v2 or later to v3 or later.
[sfrench/samba-autobuild/.git] / source / rpc_parse / parse_net.c
index 9e55d320be82a73ef303cd064cf5734f14a4f718..ec994f855f8287a4796bb380a22acd3711b50148 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,
@@ -479,15 +479,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);
@@ -506,11 +593,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))
@@ -560,7 +644,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;
@@ -1022,9 +1106,13 @@ static int init_dom_sid2s(TALLOC_CTX *ctx, const char *sids_str, DOM_SID2 **ppsi
                }
 
                /* 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)
+                               return 0;
+               } else {
+                       *ppsids = NULL;
+               }
 
                sids = *ppsids;
 
@@ -1066,10 +1154,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 +1170,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;
@@ -1287,6 +1375,21 @@ 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.
 ********************************************************************/
@@ -1506,9 +1609,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 +1629,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"));
@@ -1544,9 +1651,12 @@ void init_net_user_info3(TALLOC_CTX *ctx, NET_USER_INFO_3 *usr,
        if (acct_flags & ACB_NO_AUTH_DATA_REQD) {
                DEBUGADD(lvl,("\taccount has ACB_NO_AUTH_DATA_REQD set\n"));
        }
+       if (acct_flags & ACB_PWEXPIRED) {
+               DEBUGADD(lvl,("\taccount has ACB_PWEXPIRED set\n"));
+       }
 }
 
- void dump_user_flgs(uint32 user_flags) {
+static void dump_user_flgs(uint32 user_flags) {
 
        int lvl = 10;
        DEBUG(lvl,("dump_user_flgs\n"));
@@ -1562,6 +1672,12 @@ void init_net_user_info3(TALLOC_CTX *ctx, NET_USER_INFO_3 *usr,
        if (user_flags & LOGON_CACHED_ACCOUNT) {
                DEBUGADD(lvl,("\taccount has LOGON_CACHED_ACCOUNT\n"));
        }
+       if (user_flags & LOGON_PROFILE_PATH_RETURNED) {
+               DEBUGADD(lvl,("\taccount has LOGON_PROFILE_PATH_RETURNED\n"));
+       }
+       if (user_flags & LOGON_SERVER_TRUST_ACCOUNT) {
+               DEBUGADD(lvl,("\taccount has LOGON_SERVER_TRUST_ACCOUNT\n"));
+       }
 
 
 }
@@ -1702,29 +1818,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 */
@@ -1752,10 +1867,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)))
@@ -1888,6 +2008,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;
 
@@ -2463,13 +2586,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++)
                {
@@ -2490,13 +2619,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++)
                {
@@ -2576,13 +2711,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++)
                {
@@ -2591,13 +2732,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++)
                {
@@ -2907,7 +3054,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]))
@@ -2916,8 +3072,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))
@@ -3047,15 +3216,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++)
                        {
@@ -3065,15 +3238,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++)
                        {
@@ -3100,7 +3277,7 @@ makes a NET_Q_SAM_DELTAS structure.
 ********************************************************************/
 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"));
 
@@ -3111,8 +3288,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;
@@ -3177,15 +3353,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++)
                        {
@@ -3193,15 +3373,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++)
                        {
@@ -3229,8 +3413,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"));
@@ -3250,6 +3434,67 @@ 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.
 ********************************************************************/
@@ -3287,7 +3532,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;
        }
@@ -3303,7 +3548,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;
        }
@@ -3321,12 +3566,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)