[GLUE] Rsync SAMBA_3_2_0 SVN r25598 in order to create the v3-2-test branch.
[samba.git] / source / rpc_parse / parse_lsa.c
index bd83dabed753d41d4d9bd34bd990cddfa60522e7..15d7d80c039dedf68c3faaacb69a23eec110622d 100644 (file)
@@ -10,7 +10,7 @@
  *  
  *  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,
@@ -19,8 +19,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"
@@ -573,14 +572,17 @@ void init_r_enum_trust_dom(TALLOC_CTX *ctx, LSA_R_ENUM_TRUST_DOM *out,
                        return;
                }
 
-               out->domlist->domains = TALLOC_ARRAY( ctx, DOMAIN_INFO,
+               if (out->count) {
+                       out->domlist->domains = TALLOC_ARRAY( ctx, DOMAIN_INFO,
                                                      out->count );
-               
-               if ( !out->domlist->domains ) {
-                       out->status = NT_STATUS_NO_MEMORY;
-                       return;
+                       if ( !out->domlist->domains ) {
+                               out->status = NT_STATUS_NO_MEMORY;
+                               return;
+                       }
+               } else {                
+                       out->domlist->domains = NULL;
                }
-               
+       
                out->domlist->count = out->count;
                
                /* initialize the list of domains and their sid */
@@ -737,9 +739,13 @@ static BOOL lsa_io_dom_query_2(const char *desc, DOM_QUERY_2 *d_q, prs_struct *p
                        return False;
 
                if (UNMARSHALLING(ps)) {
-                       d_q->auditsettings = TALLOC_ZERO_ARRAY(ps->mem_ctx, uint32, d_q->count2);
-                       if (!d_q->auditsettings) {
-                               return False;
+                       if (d_q->count2) {
+                               d_q->auditsettings = TALLOC_ZERO_ARRAY(ps->mem_ctx, uint32, d_q->count2);
+                               if (!d_q->auditsettings) {
+                                       return False;
+                               }
+                       } else {
+                               d_q->auditsettings = NULL;
                        }
                }
 
@@ -1118,16 +1124,16 @@ static void init_lsa_sid_enum(TALLOC_CTX *mem_ctx, LSA_SID_ENUM *sen,
 
        /* Allocate memory for sids and sid pointers */
 
-       if (num_entries == 0) return;
-
-       if ((sen->ptr_sid = TALLOC_ZERO_ARRAY(mem_ctx, uint32, num_entries )) == NULL) {
-               DEBUG(3, ("init_lsa_sid_enum(): out of memory for ptr_sid\n"));
-               return;
-       }
+       if (num_entries) {
+               if ((sen->ptr_sid = TALLOC_ZERO_ARRAY(mem_ctx, uint32, num_entries )) == NULL) {
+                       DEBUG(3, ("init_lsa_sid_enum(): out of memory for ptr_sid\n"));
+                       return;
+               }
 
-       if ((sen->sid = TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID2, num_entries)) == NULL) {
-               DEBUG(3, ("init_lsa_sid_enum(): out of memory for sids\n"));
-               return;
+               if ((sen->sid = TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID2, num_entries)) == NULL) {
+                       DEBUG(3, ("init_lsa_sid_enum(): out of memory for sids\n"));
+                       return;
+               }
        }
 
        /* Copy across SIDs and SID pointers */
@@ -1171,7 +1177,7 @@ static BOOL lsa_io_sid_enum(const char *desc, LSA_SID_ENUM *sen, prs_struct *ps,
 
        /* Mallocate memory if we're unpacking from the wire */
 
-       if (UNMARSHALLING(ps)) {
+       if (UNMARSHALLING(ps) && sen->num_entries) {
                if ((sen->ptr_sid = PRS_ALLOC_MEM( ps, uint32, sen->num_entries)) == NULL) {
                        DEBUG(3, ("init_lsa_sid_enum(): out of memory for "
                                  "ptr_sid\n"));
@@ -1349,12 +1355,17 @@ static BOOL lsa_io_trans_names(const char *desc, LSA_TRANS_NAME_ENUM *trn,
                               &trn->num_entries2))
                        return False;
 
-               if (UNMARSHALLING(ps)) {
-                       if ((trn->name = PRS_ALLOC_MEM(ps, LSA_TRANS_NAME, trn->num_entries)) == NULL) {
+               if (trn->num_entries2 != trn->num_entries) {
+                       /* RPC fault */
+                       return False;
+               }
+
+               if (UNMARSHALLING(ps) && trn->num_entries2) {
+                       if ((trn->name = PRS_ALLOC_MEM(ps, LSA_TRANS_NAME, trn->num_entries2)) == NULL) {
                                return False;
                        }
 
-                       if ((trn->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, trn->num_entries)) == NULL) {
+                       if ((trn->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, trn->num_entries2)) == NULL) {
                                return False;
                        }
                }
@@ -1406,12 +1417,17 @@ static BOOL lsa_io_trans_names2(const char *desc, LSA_TRANS_NAME_ENUM2 *trn,
                               &trn->num_entries2))
                        return False;
 
-               if (UNMARSHALLING(ps)) {
-                       if ((trn->name = PRS_ALLOC_MEM(ps, LSA_TRANS_NAME2, trn->num_entries)) == NULL) {
+               if (trn->num_entries2 != trn->num_entries) {
+                       /* RPC fault */
+                       return False;
+               }
+
+               if (UNMARSHALLING(ps) && trn->num_entries2) {
+                       if ((trn->name = PRS_ALLOC_MEM(ps, LSA_TRANS_NAME2, trn->num_entries2)) == NULL) {
                                return False;
                        }
 
-                       if ((trn->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, trn->num_entries)) == NULL) {
+                       if ((trn->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, trn->num_entries2)) == NULL) {
                                return False;
                        }
                }
@@ -1459,7 +1475,7 @@ BOOL lsa_io_r_lookup_sids(const char *desc, LSA_R_LOOKUP_SIDS *r_s,
                if(!lsa_io_dom_r_ref ("dom_ref", r_s->dom_ref, ps, depth)) /* domain reference info */
                        return False;
 
-       if(!lsa_io_trans_names("names  ", r_s->names, ps, depth)) /* translated names */
+       if(!lsa_io_trans_names("names  ", &r_s->names, ps, depth)) /* translated names */
                return False;
 
        if(!prs_align(ps))
@@ -1494,7 +1510,7 @@ BOOL lsa_io_r_lookup_sids2(const char *desc, LSA_R_LOOKUP_SIDS2 *r_s,
                if(!lsa_io_dom_r_ref ("dom_ref", r_s->dom_ref, ps, depth)) /* domain reference info */
                        return False;
 
-       if(!lsa_io_trans_names2("names  ", r_s->names, ps, depth)) /* translated names */
+       if(!lsa_io_trans_names2("names  ", &r_s->names, ps, depth)) /* translated names */
                return False;
 
        if(!prs_align(ps))
@@ -1530,7 +1546,7 @@ BOOL lsa_io_r_lookup_sids3(const char *desc, LSA_R_LOOKUP_SIDS3 *r_s,
                if(!lsa_io_dom_r_ref ("dom_ref", r_s->dom_ref, ps, depth)) /* domain reference info */
                        return False;
 
-       if(!lsa_io_trans_names2("names  ", r_s->names, ps, depth)) /* translated names */
+       if(!lsa_io_trans_names2("names  ", &r_s->names, ps, depth)) /* translated names */
                return False;
 
        if(!prs_align(ps))
@@ -1550,7 +1566,8 @@ makes a structure.
 ********************************************************************/
 
 void init_q_lookup_names(TALLOC_CTX *mem_ctx, LSA_Q_LOOKUP_NAMES *q_l, 
-                        POLICY_HND *hnd, int num_names, const char **names)
+                        POLICY_HND *hnd, int num_names, const char **names, 
+                        int level)
 {
        unsigned int i;
 
@@ -1561,16 +1578,21 @@ void init_q_lookup_names(TALLOC_CTX *mem_ctx, LSA_Q_LOOKUP_NAMES *q_l,
        q_l->pol = *hnd;
        q_l->num_entries = num_names;
        q_l->num_entries2 = num_names;
-       q_l->lookup_level = 1;
+       q_l->lookup_level = level;
 
-       if ((q_l->uni_name = TALLOC_ZERO_ARRAY(mem_ctx, UNISTR2, num_names)) == NULL) {
-               DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
-               return;
-       }
+       if (num_names) {
+               if ((q_l->uni_name = TALLOC_ZERO_ARRAY(mem_ctx, UNISTR2, num_names)) == NULL) {
+                       DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
+                       return;
+               }
 
-       if ((q_l->hdr_name = TALLOC_ZERO_ARRAY(mem_ctx, UNIHDR, num_names)) == NULL) {
-               DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
-               return;
+               if ((q_l->hdr_name = TALLOC_ZERO_ARRAY(mem_ctx, UNIHDR, num_names)) == NULL) {
+                       DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
+                       return;
+               }
+       } else {
+               q_l->uni_name = NULL;
+               q_l->hdr_name = NULL;
        }
 
        for (i = 0; i < num_names; i++) {
@@ -1678,7 +1700,7 @@ BOOL lsa_io_r_lookup_names(const char *desc, LSA_R_LOOKUP_NAMES *out, prs_struct
                        return False;
                }
 
-               if (UNMARSHALLING(ps)) {
+               if (UNMARSHALLING(ps) && out->num_entries2) {
                        if ((out->dom_rid = PRS_ALLOC_MEM(ps, DOM_RID, out->num_entries2))
                            == NULL) {
                                DEBUG(3, ("lsa_io_r_lookup_names(): out of memory\n"));
@@ -1803,7 +1825,7 @@ BOOL lsa_io_r_lookup_names2(const char *desc, LSA_R_LOOKUP_NAMES2 *out, prs_stru
                        return False;
                }
 
-               if (UNMARSHALLING(ps)) {
+               if (UNMARSHALLING(ps) && out->num_entries2) {
                        if ((out->dom_rid = PRS_ALLOC_MEM(ps, DOM_RID2, out->num_entries2))
                            == NULL) {
                                DEBUG(3, ("lsa_io_r_lookup_names2(): out of memory\n"));
@@ -1956,7 +1978,7 @@ BOOL lsa_io_r_lookup_names3(const char *desc, LSA_R_LOOKUP_NAMES3 *out, prs_stru
                        return False;
                }
 
-               if (UNMARSHALLING(ps)) {
+               if (UNMARSHALLING(ps) && out->num_entries2) {
                        if ((out->trans_sids = PRS_ALLOC_MEM(ps, LSA_TRANSLATED_SID3, out->num_entries2))
                            == NULL) {
                                DEBUG(3, ("lsa_io_r_lookup_names3(): out of memory\n"));
@@ -2085,7 +2107,7 @@ BOOL lsa_io_r_lookup_names4(const char *desc, LSA_R_LOOKUP_NAMES4 *out, prs_stru
                        return False;
                }
 
-               if (UNMARSHALLING(ps)) {
+               if (UNMARSHALLING(ps) && out->num_entries2) {
                        if ((out->trans_sids = PRS_ALLOC_MEM(ps, LSA_TRANSLATED_SID3, out->num_entries2))
                            == NULL) {
                                DEBUG(3, ("lsa_io_r_lookup_names4(): out of memory\n"));
@@ -2117,50 +2139,6 @@ BOOL lsa_io_r_lookup_names4(const char *desc, LSA_R_LOOKUP_NAMES4 *out, prs_stru
        return True;
 }
 
-/*******************************************************************
- Inits an LSA_Q_CLOSE structure.
-********************************************************************/
-
-void init_lsa_q_close(LSA_Q_CLOSE *in, POLICY_HND *hnd)
-{
-       DEBUG(5, ("init_lsa_q_close\n"));
-
-       memcpy(&in->pol, hnd, sizeof(in->pol));
-}
-
-/*******************************************************************
- Reads or writes an LSA_Q_CLOSE structure.
-********************************************************************/
-
-BOOL lsa_io_q_close(const char *desc, LSA_Q_CLOSE *in, prs_struct *ps, int depth)
-{
-       prs_debug(ps, depth, desc, "lsa_io_q_close");
-       depth++;
-
-       if(!smb_io_pol_hnd("", &in->pol, ps, depth))
-               return False;
-
-       return True;
-}
-
-/*******************************************************************
- Reads or writes an LSA_R_CLOSE structure.
-********************************************************************/
-
-BOOL lsa_io_r_close(const char *desc,  LSA_R_CLOSE *out, prs_struct *ps, int depth)
-{
-       prs_debug(ps, depth, desc, "lsa_io_r_close");
-       depth++;
-
-       if(!smb_io_pol_hnd("", &out->pol, ps, depth))
-               return False;
-
-       if(!prs_ntstatus("status", ps, depth, &out->status))
-               return False;
-
-       return True;
-}
-
 /*******************************************************************
  Reads or writes an LSA_Q_OPEN_SECRET structure.
 ********************************************************************/
@@ -2324,7 +2302,7 @@ BOOL lsa_io_r_enum_privs(const char *desc, LSA_R_ENUM_PRIVS *out, prs_struct *ps
                if(!prs_uint32("count1", ps, depth, &out->count1))
                        return False;
 
-               if (UNMARSHALLING(ps))
+               if (UNMARSHALLING(ps) && out->count1)
                        if (!(out->privs = PRS_ALLOC_MEM(ps, LSA_PRIV_ENTRY, out->count1)))
                                return False;
 
@@ -2759,7 +2737,7 @@ static BOOL lsa_io_luid_attr(const char *desc, LUID_ATTR *out, prs_struct *ps, i
 
 static BOOL lsa_io_privilege_set(const char *desc, PRIVILEGE_SET *out, prs_struct *ps, int depth)
 {
-       uint32 i;
+       uint32 i, dummy;
 
        prs_debug(ps, depth, desc, "lsa_io_privilege_set");
        depth++;
@@ -2767,7 +2745,7 @@ static BOOL lsa_io_privilege_set(const char *desc, PRIVILEGE_SET *out, prs_struc
        if(!prs_align(ps))
                return False;
  
-       if(!prs_uint32("count", ps, depth, &out->count))
+       if(!prs_uint32("count", ps, depth, &dummy))
                return False;
        if(!prs_uint32("control", ps, depth, &out->control))
                return False;
@@ -2922,7 +2900,7 @@ BOOL lsa_io_r_setsystemaccount(const char *desc, LSA_R_SETSYSTEMACCOUNT  *out, p
 }
 
 
-static void init_lsa_string( LSA_STRING *uni, const char *string )
+void init_lsa_string( LSA_STRING *uni, const char *string )
 {
        init_unistr2(&uni->unistring, string, UNI_FLAGS_NONE);
        init_uni_hdr(&uni->hdr, &uni->unistring);
@@ -3193,20 +3171,20 @@ void init_q_enum_acct_rights(LSA_Q_ENUM_ACCT_RIGHTS *in,
 NTSTATUS init_r_enum_acct_rights( LSA_R_ENUM_ACCT_RIGHTS *out, PRIVILEGE_SET *privileges )
 {
        uint32 i;
-       char *privname;
+       const char *privname;
        const char **privname_array = NULL;
        int num_priv = 0;
 
        for ( i=0; i<privileges->count; i++ ) {
                privname = luid_to_privilege_name( &privileges->set[i].luid );
                if ( privname ) {
-                       if ( !add_string_to_array( get_talloc_ctx(), privname, &privname_array, &num_priv ) ) 
+                       if ( !add_string_to_array( talloc_tos(), privname, &privname_array, &num_priv ) )
                                return NT_STATUS_NO_MEMORY;
                }
        }
 
        if ( num_priv ) {
-               out->rights = TALLOC_P( get_talloc_ctx(), UNISTR4_ARRAY );
+               out->rights = TALLOC_P( talloc_tos(), UNISTR4_ARRAY );
                if (!out->rights) {
                        return NT_STATUS_NO_MEMORY;
                }
@@ -3277,7 +3255,7 @@ void init_q_add_acct_rights( LSA_Q_ADD_ACCT_RIGHTS *in, POLICY_HND *hnd,
        in->pol = *hnd;
        init_dom_sid2(&in->sid, sid);
        
-       in->rights = TALLOC_P( get_talloc_ctx(), UNISTR4_ARRAY );
+       in->rights = TALLOC_P( talloc_tos(), UNISTR4_ARRAY );
        if (!in->rights) {
                smb_panic("init_q_add_acct_rights: talloc fail\n");
                return;
@@ -3345,7 +3323,7 @@ void init_q_remove_acct_rights(LSA_Q_REMOVE_ACCT_RIGHTS *in,
        in->removeall = removeall;
        in->count = count;
 
-       in->rights = TALLOC_P( get_talloc_ctx(), UNISTR4_ARRAY );
+       in->rights = TALLOC_P( talloc_tos(), UNISTR4_ARRAY );
        if (!in->rights) {
                smb_panic("init_q_remove_acct_rights: talloc fail\n");
                return;
@@ -3886,7 +3864,7 @@ static BOOL smb_io_lsa_data_buf(const char *desc, LSA_DATA_BUF *buf,
        prs_debug(ps, depth, desc, "smb_io_lsa_data_buf");
        depth++;
 
-       if ( UNMARSHALLING(ps) ) {
+       if ( UNMARSHALLING(ps) && length ) {
                if ( !(buf->data = PRS_ALLOC_MEM( ps, uint8, length )) )
                        return False;
        }
@@ -3900,7 +3878,7 @@ static BOOL smb_io_lsa_data_buf(const char *desc, LSA_DATA_BUF *buf,
        if (!prs_uint32("length", ps, depth, &buf->length))
                return False;
 
-       if(!prs_uint8s(False, "data", ps, depth, buf->data, size))
+       if(!prs_uint8s(False, "data", ps, depth, buf->data, length))
                return False;
 
        return True;