r10656: BIG merge from trunk. Features not copied over
[samba.git] / source / rpc_parse / parse_net.c
index 53f660fcc3389233375fdecade715f7d305d8e9f..35533e360a1ed5fe3defd36cec672b59f246a289 100644 (file)
@@ -136,16 +136,15 @@ static BOOL net_io_netinfo_1(const char *desc, NETLOGON_INFO_1 *info, prs_struct
 static void init_netinfo_2(NETLOGON_INFO_2 *info, uint32 flags, uint32 pdc_status,
                                uint32 tc_status, const char *trusted_dc_name)
 {
-       int len_dc_name = strlen(trusted_dc_name);
        info->flags      = flags;
        info->pdc_status = pdc_status;
        info->ptr_trusted_dc_name = 1;
        info->tc_status  = tc_status;
 
        if (trusted_dc_name != NULL)
-               init_unistr2(&info->uni_trusted_dc_name, trusted_dc_name, len_dc_name+1);
+               init_unistr2(&info->uni_trusted_dc_name, trusted_dc_name, UNI_STR_TERMINATE);
        else
-               init_unistr2(&info->uni_trusted_dc_name, "", 1);
+               init_unistr2(&info->uni_trusted_dc_name, "", UNI_STR_TERMINATE);
 }
 
 /*******************************************************************
@@ -183,6 +182,50 @@ 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)
+{
+       if (info == NULL)
+               return False;
+               
+       prs_debug(ps, depth, desc, "net_io_ctrl_data_info_5");
+       depth++;
+       
+       if ( !prs_uint32( "function_code", ps, depth, &info->function_code ) )
+               return False;
+       
+       if(!prs_uint32("ptr_domain", ps, depth, &info->ptr_domain))
+               return False;
+               
+       if ( info->ptr_domain ) {
+               if(!smb_io_unistr2("domain", &info->domain, info->ptr_domain, ps, depth))
+                       return False;
+       }
+               
+       return True;
+}
+
+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;
+               
+       prs_debug(ps, depth, desc, "net_io_ctrl_data_info_6");
+       depth++;
+       
+       if ( !prs_uint32( "function_code", ps, depth, &info->function_code ) )
+               return False;
+       
+       if(!prs_uint32("ptr_domain", ps, depth, &info->ptr_domain))
+               return False;
+               
+       if ( info->ptr_domain ) {
+               if(!smb_io_unistr2("domain", &info->domain, info->ptr_domain, ps, depth))
+                       return False;
+       }
+               
+       return True;
+}
+
 /*******************************************************************
  Reads or writes an NET_Q_LOGON_CTRL2 structure.
 ********************************************************************/
@@ -211,9 +254,23 @@ BOOL net_io_q_logon_ctrl2(const char *desc, NET_Q_LOGON_CTRL2 *q_l, prs_struct *
                return False;
        if(!prs_uint32("query_level  ", ps, depth, &q_l->query_level))
                return False;
-       if(!prs_uint32("switch_value ", ps, depth, &q_l->switch_value))
-               return False;
+       switch ( q_l->function_code ) {
+               case NETLOGON_CONTROL_REDISCOVER:
+                       if ( !net_io_ctrl_data_info_5( "ctrl_data_info5", &q_l->info.info5, ps, depth) ) 
+                               return False;
+                       break;
+                       
+               case NETLOGON_CONTROL_TC_QUERY:
+                       if ( !net_io_ctrl_data_info_6( "ctrl_data_info6", &q_l->info.info6, ps, depth) ) 
+                               return False;
+                       break;
 
+               default:
+                       DEBUG(0,("net_io_q_logon_ctrl2: unknown function_code [%d]\n",
+                               q_l->function_code));
+                       return False;
+       }
+       
        return True;
 }
 
@@ -228,9 +285,8 @@ void init_net_q_logon_ctrl2(NET_Q_LOGON_CTRL2 *q_l, const char *srv_name,
 
        q_l->function_code = 0x01;
        q_l->query_level = query_level;
-       q_l->switch_value  = 0x01;
 
-       init_unistr2(&q_l->uni_server_name, srv_name, strlen(srv_name) + 1);
+       init_unistr2(&q_l->uni_server_name, srv_name, UNI_STR_TERMINATE);
 }
 
 /*******************************************************************
@@ -242,9 +298,7 @@ void init_net_r_logon_ctrl2(NET_R_LOGON_CTRL2 *r_l, uint32 query_level,
                            uint32 logon_attempts, uint32 tc_status, 
                            const char *trusted_domain_name)
 {
-       DEBUG(5,("init_r_logon_ctrl2\n"));
-
-       r_l->switch_value  = query_level; /* should only be 0x1 */
+       r_l->switch_value  = query_level; 
 
        switch (query_level) {
        case 1:
@@ -360,7 +414,7 @@ void init_net_q_logon_ctrl(NET_Q_LOGON_CTRL *q_l, const char *srv_name,
        q_l->function_code = 0x01; /* ??? */
        q_l->query_level = query_level;
 
-       init_unistr2(&q_l->uni_server_name, srv_name, strlen(srv_name) + 1);
+       init_unistr2(&q_l->uni_server_name, srv_name, UNI_STR_TERMINATE);
 }
 
 /*******************************************************************
@@ -425,6 +479,90 @@ BOOL net_io_r_logon_ctrl(const char *desc, NET_R_LOGON_CTRL *r_l, prs_struct *ps
        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"));
+
+       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_GETDCNAME structure.
+********************************************************************/
+
+BOOL net_io_q_getdcname(const char *desc, NET_Q_GETDCNAME *r_t, prs_struct *ps,
+                       int depth)
+{
+       if (r_t == NULL)
+               return False;
+
+       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))
+               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_GETDCNAME structure.
+********************************************************************/
+void init_net_r_getdcname(NET_R_GETDCNAME *r_t, const char *dcname)
+{
+       DEBUG(5,("init_r_getdcname\n"));
+
+       init_unistr2(&r_t->uni_dcname, dcname, UNI_STR_TERMINATE);
+}
+
+/*******************************************************************
+ Reads or writes an NET_R_GETDCNAME structure.
+********************************************************************/
+
+BOOL net_io_r_getdcname(const char *desc, NET_R_GETDCNAME *r_t, prs_struct *ps,
+                       int depth)
+{
+       if (r_t == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "net_io_r_getdcname");
+       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_ntstatus("status", ps, depth, &r_t->status))
+               return False;
+
+       return True;
+}
+
 /*******************************************************************
  Inits an NET_R_TRUST_DOM_LIST structure.
 ********************************************************************/
@@ -432,7 +570,7 @@ BOOL net_io_r_logon_ctrl(const char *desc, NET_R_LOGON_CTRL *r_l, prs_struct *ps
 void init_r_trust_dom(NET_R_TRUST_DOM_LIST *r_t,
                        uint32 num_doms, const char *dom_name)
 {
-       int i = 0;
+       unsigned int i = 0;
 
        DEBUG(5,("init_r_trust_dom\n"));
 
@@ -446,10 +584,10 @@ void init_r_trust_dom(NET_R_TRUST_DOM_LIST *r_t,
        for (i = 0; i < num_doms; i++) {
                fstring domain_name;
                fstrcpy(domain_name, dom_name);
-               strupper(domain_name);
-               init_unistr2(&r_t->uni_trust_dom_name[i], domain_name, strlen(domain_name)+1);
+               strupper_m(domain_name);
+               init_unistr2(&r_t->uni_trust_dom_name[i], domain_name, UNI_STR_TERMINATE);
                /* the use of UNISTR2 here is non-standard. */
-               r_t->uni_trust_dom_name[i].undoc = 0x1;
+               r_t->uni_trust_dom_name[i].offset = 0x1;
        }
        
        r_t->status = NT_STATUS_OK;
@@ -533,14 +671,14 @@ BOOL net_io_q_trust_dom(const char *desc, NET_Q_TRUST_DOM_LIST *q_l, prs_struct
 
 void init_q_req_chal(NET_Q_REQ_CHAL *q_c,
                     const char *logon_srv, const char *logon_clnt,
-                    DOM_CHAL *clnt_chal)
+                    const DOM_CHAL *clnt_chal)
 {
        DEBUG(5,("init_q_req_chal: %d\n", __LINE__));
 
        q_c->undoc_buffer = 1; /* don't know what this buffer is */
 
-       init_unistr2(&q_c->uni_logon_srv, logon_srv , strlen(logon_srv )+1);
-       init_unistr2(&q_c->uni_logon_clnt, logon_clnt, strlen(logon_clnt)+1);
+       init_unistr2(&q_c->uni_logon_srv, logon_srv , UNI_STR_TERMINATE);
+       init_unistr2(&q_c->uni_logon_clnt, logon_clnt, UNI_STR_TERMINATE);
 
        memcpy(q_c->clnt_chal.data, clnt_chal->data, sizeof(clnt_chal->data));
 
@@ -654,7 +792,7 @@ BOOL net_io_r_auth(const char *desc, NET_R_AUTH *r_a, prs_struct *ps, int depth)
 
 void init_q_auth_2(NET_Q_AUTH_2 *q_a,
                const char *logon_srv, const char *acct_name, uint16 sec_chan, const char *comp_name,
-               DOM_CHAL *clnt_chal, uint32 clnt_flgs)
+               const DOM_CHAL *clnt_chal, uint32 clnt_flgs)
 {
        DEBUG(5,("init_q_auth_2: %d\n", __LINE__));
 
@@ -722,7 +860,7 @@ BOOL net_io_r_auth_2(const char *desc, NET_R_AUTH_2 *r_a, prs_struct *ps, int de
 
 void init_q_auth_3(NET_Q_AUTH_3 *q_a,
                const char *logon_srv, const char *acct_name, uint16 sec_chan, const char *comp_name,
-               DOM_CHAL *clnt_chal, uint32 clnt_flgs)
+               const DOM_CHAL *clnt_chal, uint32 clnt_flgs)
 {
        DEBUG(5,("init_q_auth_3: %d\n", __LINE__));
 
@@ -801,7 +939,7 @@ void init_q_srv_pwset(NET_Q_SRV_PWSET *q_s,
        DEBUG(5,("init_q_srv_pwset\n"));
        
        /* Process the new password. */
-       cred_hash3( nt_cypher, hashed_mach_pwd, sess_key, 1);
+       cred_hash3( nt_cypher, hashed_mach_pwd, (const unsigned char *)sess_key, 1);
 
        init_clnt_info(&q_s->clnt_id, logon_srv, acct_name, sec_chan, comp_name, cred);
 
@@ -881,7 +1019,7 @@ static int init_dom_sid2s(TALLOC_CTX *ctx, const char *sids_str, DOM_SID2 **ppsi
                }
 
                /* Now allocate space for them. */
-               *ppsids = (DOM_SID2 *)talloc_zero(ctx, count * sizeof(DOM_SID2));
+               *ppsids = TALLOC_ZERO_ARRAY(ctx, DOM_SID2, count);
                if (*ppsids == NULL)
                        return 0;
 
@@ -910,10 +1048,6 @@ void init_id_info1(NET_ID_INFO_1 *id, const char *domain_name,
                                const char *sess_key,
                                unsigned char lm_cypher[16], unsigned char nt_cypher[16])
 {
-       int len_domain_name = strlen(domain_name);
-       int len_user_name   = strlen(user_name  );
-       int len_wksta_name  = strlen(wksta_name );
-
        unsigned char lm_owf[16];
        unsigned char nt_owf[16];
 
@@ -921,13 +1055,9 @@ void init_id_info1(NET_ID_INFO_1 *id, const char *domain_name,
 
        id->ptr_id_info1 = 1;
 
-       init_uni_hdr(&id->hdr_domain_name, len_domain_name);
-
        id->param_ctrl = param_ctrl;
        init_logon_id(&id->logon_id, log_id_low, log_id_high);
 
-       init_uni_hdr(&id->hdr_user_name, len_user_name);
-       init_uni_hdr(&id->hdr_wksta_name, len_wksta_name);
 
        if (lm_cypher && nt_cypher) {
                unsigned char key[16];
@@ -962,9 +1092,12 @@ void init_id_info1(NET_ID_INFO_1 *id, const char *domain_name,
        init_owf_info(&id->lm_owf, lm_cypher);
        init_owf_info(&id->nt_owf, nt_cypher);
 
-       init_unistr2(&id->uni_domain_name, domain_name, len_domain_name);
-       init_unistr2(&id->uni_user_name, user_name, len_user_name);
-       init_unistr2(&id->uni_wksta_name, wksta_name, len_wksta_name);
+       init_unistr2(&id->uni_domain_name, domain_name, UNI_FLAGS_NONE);
+       init_uni_hdr(&id->hdr_domain_name, &id->uni_domain_name);
+       init_unistr2(&id->uni_user_name, user_name, UNI_FLAGS_NONE);
+       init_uni_hdr(&id->hdr_user_name, &id->uni_user_name);
+       init_unistr2(&id->uni_wksta_name, wksta_name, UNI_FLAGS_NONE);
+       init_uni_hdr(&id->hdr_wksta_name, &id->uni_wksta_name);
 }
 
 /*******************************************************************
@@ -1038,45 +1171,27 @@ void init_id_info2(NET_ID_INFO_2 * id, const char *domain_name,
                   uint32 log_id_low, uint32 log_id_high,
                   const char *user_name, const char *wksta_name,
                   const uchar lm_challenge[8],
-                  const uchar * lm_chal_resp, int lm_chal_resp_len,
-                  const uchar * nt_chal_resp, int nt_chal_resp_len)
+                  const uchar * lm_chal_resp, size_t lm_chal_resp_len,
+                  const uchar * nt_chal_resp, size_t nt_chal_resp_len)
 {
-       int len_domain_name = strlen(domain_name);
-       int len_user_name   = strlen(user_name  );
-       int len_wksta_name  = strlen(wksta_name );
-       unsigned char lm_owf[24];
-       unsigned char nt_owf[128];
 
        DEBUG(5,("init_id_info2: %d\n", __LINE__));
 
        id->ptr_id_info2 = 1;
 
-       init_uni_hdr(&id->hdr_domain_name, len_domain_name);
-
        id->param_ctrl = param_ctrl;
        init_logon_id(&id->logon_id, log_id_low, log_id_high);
 
-       init_uni_hdr(&id->hdr_user_name, len_user_name);
-       init_uni_hdr(&id->hdr_wksta_name, len_wksta_name);
-
-       if (nt_chal_resp) {
-               /* oops.  can only send what-ever-it-is direct */
-               memcpy(nt_owf, nt_chal_resp, MIN(sizeof(nt_owf), nt_chal_resp_len));
-               nt_chal_resp = nt_owf;
-       }
-       if (lm_chal_resp) {
-               /* oops.  can only send what-ever-it-is direct */
-               memcpy(lm_owf, lm_chal_resp, MIN(sizeof(lm_owf), lm_chal_resp_len));
-               lm_chal_resp = lm_owf;
-       }
-
        memcpy(id->lm_chal, lm_challenge, sizeof(id->lm_chal));
        init_str_hdr(&id->hdr_nt_chal_resp, nt_chal_resp_len, nt_chal_resp_len, (nt_chal_resp != NULL) ? 1 : 0);
        init_str_hdr(&id->hdr_lm_chal_resp, lm_chal_resp_len, lm_chal_resp_len, (lm_chal_resp != NULL) ? 1 : 0);
 
-       init_unistr2(&id->uni_domain_name, domain_name, len_domain_name);
-       init_unistr2(&id->uni_user_name, user_name, len_user_name);
-       init_unistr2(&id->uni_wksta_name, wksta_name, len_wksta_name);
+       init_unistr2(&id->uni_domain_name, domain_name, UNI_FLAGS_NONE);
+       init_uni_hdr(&id->hdr_domain_name, &id->uni_domain_name);
+       init_unistr2(&id->uni_user_name, user_name, UNI_FLAGS_NONE);
+       init_uni_hdr(&id->hdr_user_name, &id->uni_user_name);
+       init_unistr2(&id->uni_wksta_name, wksta_name, UNI_FLAGS_NONE);
+       init_uni_hdr(&id->hdr_wksta_name, &id->uni_wksta_name);
 
        init_string2(&id->nt_chal_resp, (const char *)nt_chal_resp, nt_chal_resp_len, nt_chal_resp_len);
        init_string2(&id->lm_chal_resp, (const char *)lm_chal_resp, lm_chal_resp_len, lm_chal_resp_len);
@@ -1181,7 +1296,7 @@ static BOOL net_io_id_info_ctr(const char *desc, NET_ID_INFO_CTR **pp_ctr, prs_s
        depth++;
 
        if (UNMARSHALLING(ps)) {
-               ctr = *pp_ctr = (NET_ID_INFO_CTR *)prs_alloc_mem(ps, sizeof(NET_ID_INFO_CTR));
+               ctr = *pp_ctr = PRS_ALLOC_MEM(ps, NET_ID_INFO_CTR, 1);
                if (ctr == NULL)
                        return False;
        }
@@ -1275,38 +1390,24 @@ void init_net_user_info3(TALLOC_CTX *ctx, NET_USER_INFO_3 *usr,
                         
                         uint16 logon_count, uint16 bad_pw_count,
                         uint32 num_groups, const DOM_GID *gids,
-                        uint32 user_flgs, uchar sess_key[16],
+                        uint32 user_flgs, uchar user_session_key[16],
+                        uchar lm_session_key[16],
                         const char *logon_srv, const char *logon_dom,
                         const DOM_SID *dom_sid, const char *other_sids)
 {
        /* only cope with one "other" sid, right now. */
        /* need to count the number of space-delimited sids */
-       int i;
+       unsigned int i;
        int num_other_sids = 0;
        
        NTTIME          logon_time, logoff_time, kickoff_time,
                        pass_last_set_time, pass_can_change_time,
                        pass_must_change_time;
 
-       int             len_user_name, len_full_name, len_home_dir,
-                       len_dir_drive, len_logon_script, len_profile_path;
-                       
-       int len_logon_srv    = strlen(logon_srv);
-       int len_logon_dom    = strlen(logon_dom);
-
-       len_user_name    = strlen(user_name   );
-       len_full_name    = strlen(full_name   );
-       len_home_dir     = strlen(home_dir    );
-       len_dir_drive    = strlen(dir_drive   );
-       len_logon_script = strlen(logon_script);
-       len_profile_path = strlen(profile_path);
-
-
        ZERO_STRUCTP(usr);
 
        usr->ptr_user_info = 1; /* yes, we're bothering to put USER_INFO data here */
 
-
        /* Create NTTIME structs */
        unix_to_nt_time (&logon_time,            unix_logon_time);
        unix_to_nt_time (&logoff_time,           unix_logoff_time);
@@ -1322,13 +1423,6 @@ void init_net_user_info3(TALLOC_CTX *ctx, NET_USER_INFO_3 *usr,
        usr->pass_can_change_time  = pass_can_change_time;
        usr->pass_must_change_time = pass_must_change_time;
 
-       init_uni_hdr(&usr->hdr_user_name, len_user_name);
-       init_uni_hdr(&usr->hdr_full_name, len_full_name);
-       init_uni_hdr(&usr->hdr_logon_script, len_logon_script);
-       init_uni_hdr(&usr->hdr_profile_path, len_profile_path);
-       init_uni_hdr(&usr->hdr_home_dir, len_home_dir);
-       init_uni_hdr(&usr->hdr_dir_drive, len_dir_drive);
-
        usr->logon_count = logon_count;
        usr->bad_pw_count = bad_pw_count;
 
@@ -1339,41 +1433,55 @@ void init_net_user_info3(TALLOC_CTX *ctx, NET_USER_INFO_3 *usr,
        usr->buffer_groups = 1; /* indicates fill in groups, below, even if there are none */
        usr->user_flgs = user_flgs;
 
-       if (sess_key != NULL)
-               memcpy(usr->user_sess_key, sess_key, sizeof(usr->user_sess_key));
+       if (user_session_key != NULL)
+               memcpy(usr->user_sess_key, user_session_key, sizeof(usr->user_sess_key));
        else
                memset((char *)usr->user_sess_key, '\0', sizeof(usr->user_sess_key));
 
-       init_uni_hdr(&usr->hdr_logon_srv, len_logon_srv);
-       init_uni_hdr(&usr->hdr_logon_dom, len_logon_dom);
-
        usr->buffer_dom_id = dom_sid ? 1 : 0; /* yes, we're bothering to put a domain SID in */
 
-       memset((char *)usr->padding, '\0', sizeof(usr->padding));
+       memset((char *)usr->lm_sess_key, '\0', sizeof(usr->lm_sess_key));
+       memset(&usr->acct_flags, '\0', sizeof(usr->acct_flags));
+
+       for (i=0; i<7; i++) {
+               memset(&usr->unknown[i], '\0', sizeof(usr->unknown));
+       }
+
+       if (lm_session_key != NULL) {
+               memcpy(usr->lm_sess_key, lm_session_key, sizeof(usr->lm_sess_key));
+       }
 
        num_other_sids = init_dom_sid2s(ctx, other_sids, &usr->other_sids);
 
        usr->num_other_sids = num_other_sids;
        usr->buffer_other_sids = (num_other_sids != 0) ? 1 : 0; 
        
-       init_unistr2(&usr->uni_user_name, user_name, len_user_name);
-       init_unistr2(&usr->uni_full_name, full_name, len_full_name);
-       init_unistr2(&usr->uni_logon_script, logon_script, len_logon_script);
-       init_unistr2(&usr->uni_profile_path, profile_path, len_profile_path);
-       init_unistr2(&usr->uni_home_dir, home_dir, len_home_dir);
-       init_unistr2(&usr->uni_dir_drive, dir_drive, len_dir_drive);
+       init_unistr2(&usr->uni_user_name, user_name, UNI_FLAGS_NONE);
+       init_uni_hdr(&usr->hdr_user_name, &usr->uni_user_name);
+       init_unistr2(&usr->uni_full_name, full_name, UNI_FLAGS_NONE);
+       init_uni_hdr(&usr->hdr_full_name, &usr->uni_full_name);
+       init_unistr2(&usr->uni_logon_script, logon_script, UNI_FLAGS_NONE);
+       init_uni_hdr(&usr->hdr_logon_script, &usr->uni_logon_script);
+       init_unistr2(&usr->uni_profile_path, profile_path, UNI_FLAGS_NONE);
+       init_uni_hdr(&usr->hdr_profile_path, &usr->uni_profile_path);
+       init_unistr2(&usr->uni_home_dir, home_dir, UNI_FLAGS_NONE);
+       init_uni_hdr(&usr->hdr_home_dir, &usr->uni_home_dir);
+       init_unistr2(&usr->uni_dir_drive, dir_drive, UNI_FLAGS_NONE);
+       init_uni_hdr(&usr->hdr_dir_drive, &usr->uni_dir_drive);
 
        usr->num_groups2 = num_groups;
 
-       usr->gids = (DOM_GID *)talloc_zero(ctx,sizeof(DOM_GID) * (num_groups));
+       usr->gids = TALLOC_ZERO_ARRAY(ctx,DOM_GID,num_groups);
        if (usr->gids == NULL && num_groups>0)
                return;
 
        for (i = 0; i < num_groups; i++) 
                usr->gids[i] = gids[i]; 
                
-       init_unistr2(&usr->uni_logon_srv, logon_srv, len_logon_srv);
-       init_unistr2(&usr->uni_logon_dom, logon_dom, len_logon_dom);
+       init_unistr2(&usr->uni_logon_srv, logon_srv, UNI_FLAGS_NONE);
+       init_uni_hdr(&usr->hdr_logon_srv, &usr->uni_logon_srv);
+       init_unistr2(&usr->uni_logon_dom, logon_dom, UNI_FLAGS_NONE);
+       init_uni_hdr(&usr->hdr_logon_dom, &usr->uni_logon_dom);
 
        init_dom_sid2(&usr->dom_sid, dom_sid);
        /* "other" sids are set up above */
@@ -1388,9 +1496,9 @@ void init_net_user_info3(TALLOC_CTX *ctx, NET_USER_INFO_3 *usr,
 ********************************************************************/
 
 BOOL net_io_user_info3(const char *desc, NET_USER_INFO_3 *usr, prs_struct *ps, 
-                      int depth, uint16 validation_level)
+                      int depth, uint16 validation_level, BOOL kerb_validation_level)
 {
-       int i;
+       unsigned int i;
 
        if (usr == NULL)
                return False;
@@ -1462,9 +1570,19 @@ BOOL net_io_user_info3(const char *desc, NET_USER_INFO_3 *usr, prs_struct *ps,
 
        if(!prs_uint32("buffer_dom_id ", ps, depth, &usr->buffer_dom_id)) /* undocumented logon domain id pointer */
                return False;
-       if(!prs_uint8s (False, "padding       ", ps, depth, usr->padding, 40)) /* unused padding bytes? */
+
+       if(!prs_uint8s(False, "lm_sess_key", ps, depth, usr->lm_sess_key, 8)) /* lm session key */
+               return False;
+
+       if(!prs_uint32("acct_flags ", ps, depth, &usr->acct_flags)) /* Account flags  */
                return False;
 
+       for (i = 0; i < 7; i++)
+       {
+               if (!prs_uint32("unkown", ps, depth, &usr->unknown[i])) /* unknown */
+                        return False;
+       }
+
        if (validation_level == 3) {
                if(!prs_uint32("num_other_sids", ps, depth, &usr->num_other_sids)) /* 0 - num_sids */
                        return False;
@@ -1477,6 +1595,18 @@ BOOL net_io_user_info3(const char *desc, NET_USER_INFO_3 *usr, prs_struct *ps,
                }
        }
                
+       /* get kerb validation info (not really part of user_info_3) - Guenther */
+
+       if (kerb_validation_level) {
+
+               if(!prs_uint32("ptr_res_group_dom_sid", ps, depth, &usr->ptr_res_group_dom_sid))
+                       return False;
+               if(!prs_uint32("res_group_count", ps, depth, &usr->res_group_count))
+                       return False;
+               if(!prs_uint32("ptr_res_groups", ps, depth, &usr->ptr_res_groups))
+                       return False;
+       }
+
        if(!smb_io_unistr2("uni_user_name", &usr->uni_user_name, usr->hdr_user_name.buffer, ps, depth)) /* username unicode string */
                return False;
        if(!smb_io_unistr2("uni_full_name", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth)) /* user's full name unicode string */
@@ -1496,7 +1626,7 @@ BOOL net_io_user_info3(const char *desc, NET_USER_INFO_3 *usr, prs_struct *ps,
                return False;
 
        if (UNMARSHALLING(ps) && usr->num_groups2 > 0) {
-               usr->gids = (DOM_GID *)prs_alloc_mem(ps, sizeof(DOM_GID)*usr->num_groups2);
+               usr->gids = PRS_ALLOC_MEM(ps, DOM_GID, usr->num_groups2);
                if (usr->gids == NULL)
                        return False;
        }
@@ -1508,37 +1638,63 @@ BOOL net_io_user_info3(const char *desc, NET_USER_INFO_3 *usr, prs_struct *ps,
 
        if(!smb_io_unistr2("uni_logon_srv", &usr->uni_logon_srv, usr->hdr_logon_srv.buffer, ps, depth)) /* logon server unicode string */
                return False;
-       if(!smb_io_unistr2("uni_logon_dom", &usr->uni_logon_dom, usr->hdr_logon_srv.buffer, ps, depth)) /* logon domain unicode string */
+       if(!smb_io_unistr2("uni_logon_dom", &usr->uni_logon_dom, usr->hdr_logon_dom.buffer, ps, depth)) /* logon domain unicode string */
                return False;
 
        if(!smb_io_dom_sid2("", &usr->dom_sid, ps, depth))           /* domain SID */
                return False;
 
-       if (usr->num_other_sids) {
+       if (usr->buffer_other_sids) {
 
-               if (UNMARSHALLING(ps)) {
-                       usr->other_sids = (DOM_SID2 *)prs_alloc_mem(ps, sizeof(DOM_SID2)*usr->num_other_sids);
-                       if (usr->other_sids == NULL)
-                               return False;
+               uint32 num_other_sids = usr->num_other_sids;
+
+               if (!(usr->user_flgs & LOGON_EXTRA_SIDS)) {
+                       DEBUG(10,("net_io_user_info3: user_flgs attribute does not have LOGON_EXTRA_SIDS\n"));
+                       /* return False; */
                }
-       
-               if(!prs_uint32("num_other_groups", ps, depth, &usr->num_other_groups))
+
+               if (!prs_uint32("num_other_sids", ps, depth,
+                               &num_other_sids))
                        return False;
 
-               if (UNMARSHALLING(ps) && usr->num_other_groups > 0) {
-                       usr->other_gids = (DOM_GID *)prs_alloc_mem(ps, sizeof(DOM_GID)*usr->num_other_groups);
-                       if (usr->other_gids == NULL)
+               if (num_other_sids != usr->num_other_sids)
+                       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 ((num_other_sids != 0) &&
+                           ((usr->other_sids == NULL) ||
+                            (usr->other_sids_attrib == NULL)))
                                return False;
                }
-       
-               for (i = 0; i < usr->num_other_groups; i++) {
-                       if(!smb_io_gid("", &usr->other_gids[i], ps, depth)) /* other GIDs */
+
+               /* First the pointers to the SIDS and attributes */
+
+               depth++;
+
+               for (i=0; i<usr->num_other_sids; i++) {
+                       uint32 ptr = 1;
+
+                       if (!prs_uint32("sid_ptr", ps, depth, &ptr))
+                               return False;
+
+                       if (UNMARSHALLING(ps) && (ptr == 0))
+                               return False;
+
+                       if (!prs_uint32("attribute", ps, depth,
+                                       &usr->other_sids_attrib[i]))
                                return False;
                }
+       
                for (i = 0; i < usr->num_other_sids; i++) {
                        if(!smb_io_dom_sid2("", &usr->other_sids[i], ps, depth)) /* other domain SIDs */
                                return False;
                }
+
+               depth--;
        }
 
        return True;
@@ -1562,6 +1718,9 @@ BOOL net_io_q_sam_logon(const char *desc, NET_Q_SAM_LOGON *q_l, prs_struct *ps,
        if(!smb_io_sam_info("", &q_l->sam_id, ps, depth))
                return False;
 
+       if(!prs_align_uint16(ps))
+               return False;
+       
        if(!prs_uint16("validation_level", ps, depth, &q_l->validation_level))
                return False;
 
@@ -1582,8 +1741,10 @@ BOOL net_io_r_sam_logon(const char *desc, NET_R_SAM_LOGON *r_l, prs_struct *ps,
 
        if(!prs_uint32("buffer_creds", ps, depth, &r_l->buffer_creds)) /* undocumented buffer pointer */
                return False;
-       if(!smb_io_cred("", &r_l->srv_creds, ps, depth)) /* server credentials.  server time stamp appears to be ignored. */
-               return False;
+       if (&r_l->buffer_creds) {
+               if(!smb_io_cred("", &r_l->srv_creds, ps, depth)) /* server credentials.  server time stamp appears to be ignored. */
+                       return False;
+       }
 
        if(!prs_uint16("switch_value", ps, depth, &r_l->switch_value))
                return False;
@@ -1591,11 +1752,11 @@ BOOL net_io_r_sam_logon(const char *desc, NET_R_SAM_LOGON *r_l, prs_struct *ps,
                return False;
 
 #if 1 /* W2k always needs this - even for bad passwd. JRA */
-       if(!net_io_user_info3("", r_l->user, ps, depth, r_l->switch_value))
+       if(!net_io_user_info3("", r_l->user, ps, depth, r_l->switch_value, False))
                return False;
 #else
        if (r_l->switch_value != 0) {
-               if(!net_io_user_info3("", r_l->user, ps, depth, r_l->switch_value))
+               if(!net_io_user_info3("", r_l->user, ps, depth, r_l->switch_value, False))
                        return False;
        }
 #endif
@@ -1669,8 +1830,8 @@ BOOL init_net_q_sam_sync(NET_Q_SAM_SYNC * q_s, const char *srv_name,
 {
        DEBUG(5, ("init_q_sam_sync\n"));
 
-       init_unistr2(&q_s->uni_srv_name, srv_name, strlen(srv_name) + 1);
-       init_unistr2(&q_s->uni_cli_name, cli_name, strlen(cli_name) + 1);
+       init_unistr2(&q_s->uni_srv_name, srv_name, UNI_STR_TERMINATE);
+       init_unistr2(&q_s->uni_cli_name, cli_name, UNI_STR_TERMINATE);
 
         if (cli_creds)
                 memcpy(&q_s->cli_creds, cli_creds, sizeof(q_s->cli_creds));
@@ -1802,15 +1963,26 @@ static BOOL net_io_sam_domain_info(const char *desc, SAM_DOMAIN_INFO * info,
                 return False;
        if (!smb_io_time("creation_time", &info->creation_time, ps, depth))
                 return False;
-
-       if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
-                return False;
-       if (!smb_io_unihdr("hdr_unknown", &info->hdr_unknown, ps, depth))
-                return False;
-
-       if (prs_offset(ps) + 40 > prs_data_size(ps))
-                return False;
-        prs_set_offset(ps, prs_offset(ps) + 40);
+       if (!prs_uint32("security_information", ps, depth, &info->security_information))
+               return False;
+       if (!smb_io_bufhdr4("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
+               return False;
+       if (!smb_io_lockout_string_hdr("hdr_account_lockout_string", &info->hdr_account_lockout, ps, depth))
+               return False;
+       if (!smb_io_unihdr("hdr_unknown2", &info->hdr_unknown2, ps, depth))
+               return False;
+       if (!smb_io_unihdr("hdr_unknown3", &info->hdr_unknown3, ps, depth))
+               return False;
+       if (!smb_io_unihdr("hdr_unknown4", &info->hdr_unknown4, ps, depth))
+               return False;
+       if (!prs_uint32("logon_chgpass", ps, depth, &info->logon_chgpass))
+               return False;
+       if (!prs_uint32("unknown6", ps, depth, &info->unknown6))
+               return False;
+       if (!prs_uint32("unknown7", ps, depth, &info->unknown7))
+               return False;
+       if (!prs_uint32("unknown8", ps, depth, &info->unknown8))
+               return False;
 
        if (!smb_io_unistr2("uni_dom_name", &info->uni_dom_name,
                             info->hdr_dom_name.buffer, ps, depth))
@@ -1819,13 +1991,23 @@ static BOOL net_io_sam_domain_info(const char *desc, SAM_DOMAIN_INFO * info,
                             info->hdr_oem_info.buffer, ps, depth))
                 return False;
 
-       if (!smb_io_buffer4("buf_sec_desc", &info->buf_sec_desc,
-                            info->hdr_sec_desc.buffer, ps, depth))
-                return False;
-       if (!smb_io_unistr2("buf_unknown", &info->buf_unknown,
-                            info->hdr_unknown.buffer, ps, depth))
+       if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
                 return False;
 
+       if (!smb_io_account_lockout_str("account_lockout", &info->account_lockout, 
+                                       info->hdr_account_lockout.buffer, ps, depth))
+               return False;
+
+       if (!smb_io_unistr2("buf_unknown2", &info->buf_unknown2, 
+                           info->hdr_unknown2.buffer, ps, depth))
+               return False;
+       if (!smb_io_unistr2("buf_unknown3", &info->buf_unknown3, 
+                           info->hdr_unknown3.buffer, ps, depth))
+               return False;
+       if (!smb_io_unistr2("buf_unknown4", &info->buf_unknown4, 
+                           info->hdr_unknown4.buffer, ps, depth))
+               return False;
+
        return True;
 }
 
@@ -1847,9 +2029,9 @@ static BOOL net_io_sam_group_info(const char *desc, SAM_GROUP_INFO * info,
        if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
                 return False;
 
-       if (prs_offset(ps) + 48 > prs_data_size(ps))
+        if (ps->data_offset + 48 > ps->buffer_size)
                 return False;
-        prs_set_offset(ps, prs_offset(ps) + 48);
+       ps->data_offset += 48;
 
        if (!smb_io_unistr2("uni_grp_name", &info->uni_grp_name,
                             info->hdr_grp_name.buffer, ps, depth))
@@ -1857,8 +2039,7 @@ static BOOL net_io_sam_group_info(const char *desc, SAM_GROUP_INFO * info,
        if (!smb_io_unistr2("uni_grp_desc", &info->uni_grp_desc,
                             info->hdr_grp_desc.buffer, ps, depth))
                 return False;
-       if (!smb_io_buffer4("buf_sec_desc", &info->buf_sec_desc,
-                            info->hdr_sec_desc.buffer, ps, depth))
+       if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
                 return False;
 
        return True;
@@ -1977,9 +2158,8 @@ BOOL make_sam_account_info(SAM_ACCOUNT_INFO * info,
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-static BOOL net_io_sam_account_info(const char *desc, uint8 sess_key[16],
-                                   SAM_ACCOUNT_INFO * info, prs_struct *ps,
-                                   int depth)
+static BOOL net_io_sam_account_info(const char *desc, SAM_ACCOUNT_INFO *info,
+                               prs_struct *ps, int depth)
 {
        BUFHDR2 hdr_priv_data;
        uint32 i;
@@ -2110,8 +2290,7 @@ static BOOL net_io_sam_account_info(const char *desc, uint8 sess_key[16],
        if (!prs_uint32("unknown2", ps, depth, &info->unknown2))
                 return False;
 
-       if (!smb_io_buffer4("buf_logon_hrs", &info->buf_logon_hrs,
-                            info->ptr_logon_hrs, ps, depth))
+       if (!smb_io_rpc_blob("buf_logon_hrs", &info->buf_logon_hrs, ps, depth))
                 return False;
        prs_align(ps);
        if (!smb_io_unistr2("uni_comment", &info->uni_comment,
@@ -2128,13 +2307,13 @@ static BOOL net_io_sam_account_info(const char *desc, uint8 sess_key[16],
                uint32 len = 0x44;
                if (!prs_uint32("pwd_len", ps, depth, &len))
                         return False;
-               old_offset = prs_offset(ps);
-               if (len == 0x44)
+               old_offset = ps->data_offset;
+               if (len > 0)
                {
                        if (ps->io)
                        {
                                /* reading */
-                                if (!prs_hash1(ps, prs_offset(ps), sess_key))
+                                if (!prs_hash1(ps, ps->data_offset, len))
                                         return False;
                        }
                        if (!net_io_sam_passwd_info("pass", &info->pass, 
@@ -2144,16 +2323,15 @@ static BOOL net_io_sam_account_info(const char *desc, uint8 sess_key[16],
                        if (!ps->io)
                        {
                                /* writing */
-                                if (!prs_hash1(ps, old_offset, sess_key))
+                                if (!prs_hash1(ps, old_offset, len))
                                         return False;
                        }
                }
-                if (old_offset + len > prs_data_size(ps))
+                if (old_offset + len > ps->buffer_size)
                         return False;
-               prs_set_offset(ps, old_offset + len);
+               ps->data_offset = old_offset + len;
        }
-       if (!smb_io_buffer4("buf_sec_desc", &info->buf_sec_desc,
-                            info->hdr_sec_desc.buffer, ps, depth))
+       if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
                 return False;
        prs_align(ps);
        if (!smb_io_unistr2("uni_profile", &info->uni_profile,
@@ -2185,9 +2363,9 @@ static BOOL net_io_sam_group_mem_info(const char *desc, SAM_GROUP_MEM_INFO * inf
        if (!prs_uint32("num_members", ps, depth, &info->num_members))
                 return False;
 
-        if (prs_offset(ps) + 16 > prs_data_size(ps))
+        if (ps->data_offset + 16 > ps->buffer_size)
                 return False;
-       prs_set_offset(ps, prs_offset(ps) + 16);
+       ps->data_offset += 16;
 
        if (info->ptr_rids != 0)
        {
@@ -2201,8 +2379,7 @@ static BOOL net_io_sam_group_mem_info(const char *desc, SAM_GROUP_MEM_INFO * inf
                        return False;
                }
 
-                info->rids = talloc(ps->mem_ctx, sizeof(uint32) *
-                                    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",
@@ -2229,8 +2406,7 @@ static BOOL net_io_sam_group_mem_info(const char *desc, SAM_GROUP_MEM_INFO * inf
                        return False;
                }
 
-                info->attribs = talloc(ps->mem_ctx, sizeof(uint32) *
-                                       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",
@@ -2267,19 +2443,19 @@ static BOOL net_io_sam_alias_info(const char *desc, SAM_ALIAS_INFO * info,
        if (!smb_io_unihdr("hdr_als_desc", &info->hdr_als_desc, ps, depth))
                 return False;
 
-        if (prs_offset(ps) + 40 > prs_data_size(ps))
+        if (ps->data_offset + 40 > ps->buffer_size)
                 return False;
-       prs_set_offset(ps, prs_offset(ps) + 40);
+       ps->data_offset += 40;
 
        if (!smb_io_unistr2("uni_als_name", &info->uni_als_name,
                             info->hdr_als_name.buffer, ps, depth))
                 return False;
-       if (!smb_io_buffer4("buf_sec_desc", &info->buf_sec_desc,
-                            info->hdr_sec_desc.buffer, ps, depth))
+       if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
                 return False;
+
        if (!smb_io_unistr2("uni_als_desc", &info->uni_als_desc,
-                            info->hdr_als_name.buffer, ps, depth))
-                return False;
+                           info->hdr_als_desc.buffer, ps, depth))
+               return False;
 
        return True;
 }
@@ -2302,12 +2478,12 @@ static BOOL net_io_sam_alias_mem_info(const char *desc, SAM_ALIAS_MEM_INFO * inf
        if (!prs_uint32("ptr_members", ps, depth, &info->ptr_members))
                 return False;
 
+       if (ps->data_offset + 16 > ps->buffer_size)
+               return False;
+       ps->data_offset += 16;
+
        if (info->ptr_members != 0)
        {
-                if (prs_offset(ps) + 16 > prs_data_size(ps))
-                        return False;
-                prs_set_offset(ps, prs_offset(ps) + 16);
-
                if (!prs_uint32("num_sids", ps, depth, &info->num_sids))
                         return False;
                if (info->num_sids != info->num_members)
@@ -2316,8 +2492,7 @@ static BOOL net_io_sam_alias_mem_info(const char *desc, SAM_ALIAS_MEM_INFO * inf
                        return False;
                }
 
-                info->ptr_sids = talloc(ps->mem_ctx, sizeof(uint32) *
-                                        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",
@@ -2332,8 +2507,7 @@ static BOOL net_io_sam_alias_mem_info(const char *desc, SAM_ALIAS_MEM_INFO * inf
                                 return False;
                }
 
-                info->sids = talloc(ps->mem_ctx, sizeof(DOM_SID2) *
-                                    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",
@@ -2363,7 +2537,7 @@ reads or writes a structure.
 static BOOL net_io_sam_policy_info(const char *desc, SAM_DELTA_POLICY *info,
                                      prs_struct *ps, int depth)
 {
-       int i;
+       unsigned int i;
        prs_debug(ps, depth, desc, "net_io_sam_policy_info");
        depth++;
 
@@ -2435,14 +2609,17 @@ static BOOL net_io_sam_policy_info(const char *desc, SAM_DELTA_POLICY *info,
        if(!smb_io_dom_sid2("domain_sid", &info->domain_sid, ps, depth))
                return False;
 
-       if (!smb_io_buffer4("buf_sec_desc", &info->buf_sec_desc,
-                            info->hdr_sec_desc.buffer, ps, depth))
+       if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
 
                return False;
 
        return True;
 }
 
+#if 0
+
+/* This function is pretty broken - see bug #334 */
+
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
@@ -2491,6 +2668,12 @@ static BOOL net_io_sam_trustdoms_info(const char *desc, SAM_DELTA_TRUSTDOMS *inf
        return True;
 }
 
+#endif
+
+#if 0
+
+/* This function doesn't work - see bug #334 */
+
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
@@ -2578,13 +2761,15 @@ static BOOL net_io_sam_secret_info(const char *desc, SAM_DELTA_SECRET *info,
        return True;
 }
 
+#endif
+
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
 static BOOL net_io_sam_privs_info(const char *desc, SAM_DELTA_PRIVS *info,
                                      prs_struct *ps, int depth)
 {
-       int i;
+       unsigned int i;
 
        prs_debug(ps, depth, desc, "net_io_sam_privs_info");
        depth++;
@@ -2638,7 +2823,7 @@ 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(ps->mem_ctx, sizeof(uint32) * info->attribute_count);
+       info->attributes = TALLOC_ARRAY(ps->mem_ctx, uint32, info->attribute_count);
 
        for (i=0; i<info->attribute_count; i++)
                if(!prs_uint32("attributes", ps, depth, &info->attributes[i]))
@@ -2647,8 +2832,8 @@ 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(ps->mem_ctx, sizeof(UNIHDR) * info->privlist_count);
-       info->uni_privslist = talloc(ps->mem_ctx, sizeof(UNISTR2) * 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);
 
        for (i=0; i<info->privlist_count; i++)
                if(!smb_io_unihdr("hdr_privslist", &info->hdr_privslist[i], ps, depth))
@@ -2658,8 +2843,7 @@ static BOOL net_io_sam_privs_info(const char *desc, SAM_DELTA_PRIVS *info,
                if (!smb_io_unistr2("uni_privslist", &info->uni_privslist[i], True, ps, depth))
                        return False;
 
-       if (!smb_io_buffer4("buf_sec_desc", &info->buf_sec_desc,
-                            info->hdr_sec_desc.buffer, ps, depth))
+       if (!smb_io_rpc_blob("buf_sec_desc", &info->buf_sec_desc, ps, depth))
                 return False;
 
        return True;
@@ -2668,7 +2852,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, uint8 sess_key[16],
+static BOOL net_io_sam_delta_ctr(const char *desc,
                                 SAM_DELTA_CTR * delta, uint16 type,
                                 prs_struct *ps, int depth)
 {
@@ -2693,7 +2877,7 @@ static BOOL net_io_sam_delta_ctr(const char *desc, uint8 sess_key[16],
                        break;
 
                case SAM_DELTA_ACCOUNT_INFO:
-                       if (!net_io_sam_account_info("", sess_key, &delta->account_info, ps, depth))
+                       if (!net_io_sam_account_info("", &delta->account_info, ps, depth))
                                 return False;
                        break;
 
@@ -2722,14 +2906,10 @@ static BOOL net_io_sam_delta_ctr(const char *desc, uint8 sess_key[16],
                                 return False;
                        break;
 
-               case SAM_DELTA_TRUST_DOMS:
-                       if (!net_io_sam_trustdoms_info("", &delta->trustdoms_info, ps, depth))
-                                return False;
-                       break;
+                       /* These guys are implemented but broken */
 
+               case SAM_DELTA_TRUST_DOMS:
                case SAM_DELTA_SECRET_INFO:
-                       if (!net_io_sam_secret_info("", &delta->secret_info, ps, depth))
-                                return False;
                        break;
 
                        /* These guys are not implemented yet */
@@ -2750,7 +2930,7 @@ static BOOL net_io_sam_delta_ctr(const char *desc, uint8 sess_key[16],
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-BOOL net_io_r_sam_sync(const char *desc, uint8 sess_key[16],
+BOOL net_io_r_sam_sync(const char *desc,
                       NET_R_SAM_SYNC * r_s, prs_struct *ps, int depth)
 {
        uint32 i;
@@ -2784,10 +2964,7 @@ BOOL net_io_r_sam_sync(const char *desc, uint8 sess_key[16],
                        }
 
                         if (r_s->num_deltas2 > 0) {
-                                r_s->hdr_deltas = (SAM_DELTA_HDR *)
-                                        talloc(ps->mem_ctx, r_s->num_deltas2 *
-                                               sizeof(SAM_DELTA_HDR));
-                          
+                                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", 
@@ -2805,10 +2982,7 @@ BOOL net_io_r_sam_sync(const char *desc, uint8 sess_key[16],
                        }
 
                         if (r_s->num_deltas2 > 0) {
-                                r_s->deltas = (SAM_DELTA_CTR *)
-                                        talloc(ps->mem_ctx, r_s->num_deltas2 *
-                                               sizeof(SAM_DELTA_CTR));
-
+                                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", 
@@ -2820,7 +2994,7 @@ BOOL net_io_r_sam_sync(const char *desc, uint8 sess_key[16],
                        for (i = 0; i < r_s->num_deltas2; i++)
                        {
                                if (!net_io_sam_delta_ctr(
-                                        "", sess_key, &r_s->deltas[i],
+                                        "", &r_s->deltas[i],
                                         r_s->hdr_deltas[i].type3,
                                         ps, depth)) {
                                         DEBUG(0, ("hmm, failed on i=%d\n", i));
@@ -2846,8 +3020,8 @@ BOOL init_net_q_sam_deltas(NET_Q_SAM_DELTAS *q_s, const char *srv_name,
 {
        DEBUG(5, ("init_net_q_sam_deltas\n"));
 
-       init_unistr2(&q_s->uni_srv_name, srv_name, strlen(srv_name) + 1);
-       init_unistr2(&q_s->uni_cli_name, cli_name, strlen(cli_name) + 1);
+       init_unistr2(&q_s->uni_srv_name, srv_name, UNI_STR_TERMINATE);
+       init_unistr2(&q_s->uni_cli_name, cli_name, UNI_STR_TERMINATE);
 
        memcpy(&q_s->cli_creds, cli_creds, sizeof(q_s->cli_creds));
        memset(&q_s->ret_creds, 0, sizeof(q_s->ret_creds));
@@ -2892,10 +3066,10 @@ 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, uint8 sess_key[16],
+BOOL net_io_r_sam_deltas(const char *desc,
                          NET_R_SAM_DELTAS *r_s, prs_struct *ps, int depth)
 {
-        int i;
+        unsigned int i;
 
        prs_debug(ps, depth, desc, "net_io_r_sam_deltas");
        depth++;
@@ -2920,9 +3094,7 @@ BOOL net_io_r_sam_deltas(const char *desc, uint8 sess_key[16],
                if (r_s->ptr_deltas != 0)
                {
                         if (r_s->num_deltas > 0) {
-                                r_s->hdr_deltas = (SAM_DELTA_HDR *)
-                                        talloc(ps->mem_ctx, r_s->num_deltas *
-                                               sizeof(SAM_DELTA_HDR));
+                                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", 
@@ -2938,10 +3110,7 @@ BOOL net_io_r_sam_deltas(const char *desc, uint8 sess_key[16],
                        }
                         
                         if (r_s->num_deltas > 0) {
-                                r_s->deltas = (SAM_DELTA_CTR *)
-                                        talloc(ps->mem_ctx, r_s->num_deltas *
-                                               sizeof(SAM_DELTA_CTR));
-
+                                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", 
@@ -2953,7 +3122,7 @@ BOOL net_io_r_sam_deltas(const char *desc, uint8 sess_key[16],
                        for (i = 0; i < r_s->num_deltas; i++)
                        {
                                if (!net_io_sam_delta_ctr(
-                                        "", sess_key,
+                                        "",
                                         &r_s->deltas[i],
                                         r_s->hdr_deltas[i].type2,
                                         ps, depth))