Adding LSA_OPENSECRET (-> LsarOpenSecret) and LSA_QUERYSECRET
[samba.git] / source3 / rpc_parse / parse_lsa.c
index 5adff5256d91e0ae53bde7046de19498a39985b5..c01664c15c5d48c294cbdc70a15bc1bd5666324b 100644 (file)
@@ -26,8 +26,6 @@
 
 extern int DEBUGLEVEL;
 
-static void lsa_io_trans_names(char *desc, LSA_TRANS_NAME_ENUM *trn, prs_struct *ps, int depth);
-
 /*******************************************************************
 creates a LSA_TRANS_NAME structure.
 ********************************************************************/
@@ -75,40 +73,44 @@ static void lsa_io_dom_r_ref(char *desc,  DOM_R_REF *r_r, prs_struct *ps, int de
        
        prs_uint32("undoc_buffer  ", ps, depth, &(r_r->undoc_buffer  )); /* undocumented buffer pointer. */
        prs_uint32("num_ref_doms_1", ps, depth, &(r_r->num_ref_doms_1)); /* num referenced domains? */
-       prs_uint32("undoc_buffer2 ", ps, depth, &(r_r->undoc_buffer2 )); /* undocumented buffer pointer. */
+       prs_uint32("ptr_ref_dom   ", ps, depth, &(r_r->ptr_ref_dom   )); /* undocumented buffer pointer. */
        prs_uint32("max_entries   ", ps, depth, &(r_r->max_entries   )); /* 32 - max number of entries */
-       prs_uint32("num_ref_doms_2", ps, depth, &(r_r->num_ref_doms_2)); /* 4 - num referenced domains? */
 
-       SMB_ASSERT_ARRAY(r_r->hdr_ref_dom, r_r->num_ref_doms_1-1);
-       SMB_ASSERT_ARRAY(r_r->ref_dom, r_r->num_ref_doms_2);
+       SMB_ASSERT_ARRAY(r_r->hdr_ref_dom, r_r->num_ref_doms_1);
 
-       for (i = 0; i < r_r->num_ref_doms_1; i++)
+       if (r_r->ptr_ref_dom != 0)
        {
-               fstring t;
-
-               slprintf(t, sizeof(t) - 1, "dom_ref[%d] ", i);
-               smb_io_unihdr(t, &(r_r->hdr_ref_dom[i].hdr_dom_name), ps, depth);
-
-               slprintf(t, sizeof(t) - 1, "sid_ptr[%d] ", i);
-               prs_uint32(t, ps, depth, &(r_r->hdr_ref_dom[i].ptr_dom_sid));
-       }
+               prs_uint32("num_ref_doms_2", ps, depth, &(r_r->num_ref_doms_2)); /* 4 - num referenced domains? */
+               SMB_ASSERT_ARRAY(r_r->ref_dom, r_r->num_ref_doms_2);
 
-       for (i = 0, n = 0, s = 0; i < r_r->num_ref_doms_2; i++)
-       {
-               fstring t;
-
-               if (r_r->hdr_ref_dom[i].hdr_dom_name.buffer != 0)
+               for (i = 0; i < r_r->num_ref_doms_1; i++)
                {
+                       fstring t;
+
                        slprintf(t, sizeof(t) - 1, "dom_ref[%d] ", i);
-                       smb_io_unistr2(t, &(r_r->ref_dom[n].uni_dom_name), True, ps, depth); /* domain name unicode string */
-                       n++;
+                       smb_io_unihdr(t, &(r_r->hdr_ref_dom[i].hdr_dom_name), ps, depth);
+
+                       slprintf(t, sizeof(t) - 1, "sid_ptr[%d] ", i);
+                       prs_uint32(t, ps, depth, &(r_r->hdr_ref_dom[i].ptr_dom_sid));
                }
 
-               if (r_r->hdr_ref_dom[i].ptr_dom_sid != 0)
+               for (i = 0, n = 0, s = 0; i < r_r->num_ref_doms_2; i++)
                {
-                       slprintf(t, sizeof(t) - 1, "sid_ptr[%d] ", i);
-                       smb_io_dom_sid2("", &(r_r->ref_dom[s].ref_dom), ps, depth); /* referenced domain SIDs */
-                       s++;
+                       fstring t;
+
+                       if (r_r->hdr_ref_dom[i].hdr_dom_name.buffer != 0)
+                       {
+                               slprintf(t, sizeof(t) - 1, "dom_ref[%d] ", i);
+                               smb_io_unistr2(t, &(r_r->ref_dom[n].uni_dom_name), True, ps, depth); /* domain name unicode string */
+                               n++;
+                       }
+
+                       if (r_r->hdr_ref_dom[i].ptr_dom_sid != 0)
+                       {
+                               slprintf(t, sizeof(t) - 1, "sid_ptr[%d] ", i);
+                               smb_io_dom_sid2("", &(r_r->ref_dom[s].ref_dom), ps, depth); /* referenced domain SIDs */
+                               s++;
+                       }
                }
        }
 }
@@ -378,6 +380,171 @@ void lsa_io_q_query(char *desc,  LSA_Q_QUERY_INFO *q_q, prs_struct *ps, int dept
        prs_uint16("info_class", ps, depth, &(q_q->info_class));
 }
 
+/*******************************************************************
+makes an LSA_Q_OPEN_SECRET structure.
+********************************************************************/
+void make_q_open_secret(LSA_Q_OPEN_SECRET *q_o, POLICY_HND *pol_hnd,
+                       char *secret_name, uint32 desired_access)
+{
+       int len = strlen(secret_name);
+
+       if (q_o == NULL) return;
+
+       DEBUG(5,("make_q_open_secret"));
+
+       memcpy(&(q_o->pol), pol_hnd, sizeof(q_o->pol));
+
+       make_uni_hdr(&(q_o->hdr_secret), len, len, 1);
+       make_unistr2(&(q_o->uni_secret), secret_name, len);
+
+       q_o->des_access = desired_access;
+}
+
+/*******************************************************************
+reads or writes an LSA_Q_OPEN_SECRET structure.
+********************************************************************/
+void lsa_io_q_open_secret(char *desc, LSA_Q_OPEN_SECRET *q_o, prs_struct *ps, int depth)
+{
+       if (q_o == NULL) return;
+
+       prs_debug(ps, depth, desc, "lsa_io_q_open_secret");
+       depth++;
+
+       smb_io_pol_hnd("", &(q_o->pol), ps, depth);
+
+       prs_align(ps);
+       smb_io_unihdr ("", &(q_o->hdr_secret), ps, depth);
+       smb_io_unistr2("", &(q_o->uni_secret), 1, ps, depth);
+
+       prs_align(ps);
+       prs_uint32("des_access", ps, depth, &(q_o->des_access));
+}
+
+/*******************************************************************
+reads or writes an LSA_R_OPEN_SECRET structure.
+********************************************************************/
+void lsa_io_r_open_secret(char *desc, LSA_R_OPEN_SECRET *r_o, prs_struct *ps, int depth)
+{
+       if (r_o == NULL) return;
+
+       prs_debug(ps, depth, desc, "lsa_io_r_open_secret");
+       depth++;
+
+       smb_io_pol_hnd("", &(r_o->pol), ps, depth);
+
+       prs_uint32("status", ps, depth, &(r_o->status));
+}
+
+/*******************************************************************
+reads or writes an LSA_SECRET_VALUE structure.
+********************************************************************/
+void lsa_io_secret_value(char *desc, LSA_SECRET_VALUE *value, prs_struct *ps, int depth)
+{
+       if (value == NULL) return;
+
+       prs_debug(ps, depth, desc, "lsa_io_secret_value");
+       depth++;
+
+       prs_align(ps);
+       prs_uint32("ptr_secret", ps, depth, &(value->ptr_secret));
+
+       if (value->ptr_secret == 0)
+       {
+               return;
+       }
+
+       smb_io_strhdr2("hdr_secret", &(value->hdr_secret), ps, depth);
+       smb_io_string2("secret"    , &(value->secret    ),
+                      value->hdr_secret.buffer, ps, depth);
+}
+
+/*******************************************************************
+reads or writes an LSA_SECRET_INFO structure.
+********************************************************************/
+void lsa_io_secret_info(char *desc, LSA_SECRET_INFO *info, prs_struct *ps, int depth)
+{
+       if (info == NULL) return;
+
+       prs_debug(ps, depth, desc, "lsa_io_secret_info");
+       depth++;
+
+       prs_align(ps);
+       prs_uint32("ptr_value ", ps, depth, &(info->ptr_value ));
+
+       if (info->ptr_value != 0)
+       {
+               lsa_io_secret_value("", &(info->value), ps, depth);
+       }
+
+       prs_align(ps);
+       prs_uint32("ptr_update", ps, depth, &(info->ptr_update));
+
+       if (info->ptr_update != 0)
+       {
+               ps->align = 8;
+               prs_align(ps);
+               ps->align = 4;
+
+               smb_io_time("last_update", &(info->last_update), ps, depth);
+       }
+}
+
+/*******************************************************************
+makes an LSA_Q_QUERY_SECRET structure.
+********************************************************************/
+void make_q_query_secret(LSA_Q_QUERY_SECRET *q_q, POLICY_HND *pol)
+{
+       if (q_q == NULL) return;
+
+       DEBUG(5,("make_q_query_secret"));
+
+       memcpy(&(q_q->pol), pol, sizeof(q_q->pol));
+
+       /* Want secret */
+       q_q->info.ptr_value = 1;
+       q_q->info.value.ptr_secret = 0;
+
+       /* Want last change time */
+       q_q->info.ptr_update = 1;
+
+       /* Don't care about old info */
+       q_q->oldinfo.ptr_value = 0;
+       q_q->oldinfo.ptr_update = 0;
+}
+
+/*******************************************************************
+reads or writes an LSA_Q_QUERY_SECRET structure.
+********************************************************************/
+void lsa_io_q_query_secret(char *desc, LSA_Q_QUERY_SECRET *q_q, prs_struct *ps, int depth)
+{
+       if (q_q == NULL) return;
+
+       prs_debug(ps, depth, desc, "lsa_io_q_query_secret");
+       depth++;
+
+       smb_io_pol_hnd("", &(q_q->pol), ps, depth);
+
+       lsa_io_secret_info("", &(q_q->info   ), ps, depth);
+       lsa_io_secret_info("", &(q_q->oldinfo), ps, depth);
+}
+
+/*******************************************************************
+reads or writes an LSA_Q_QUERY_SECRET structure.
+********************************************************************/
+void lsa_io_r_query_secret(char *desc, LSA_R_QUERY_SECRET *r_q, prs_struct *ps, int depth)
+{
+       if (r_q == NULL) return;
+
+       prs_debug(ps, depth, desc, "lsa_io_r_query_secret");
+       depth++;
+
+       lsa_io_secret_info("", &(r_q->info   ), ps, depth);
+       lsa_io_secret_info("", &(r_q->oldinfo), ps, depth);
+
+       prs_align(ps);
+       prs_uint32("status", ps, depth, &(r_q->status));
+}
+
 /*******************************************************************
 reads or writes an LSA_Q_ENUM_TRUST_DOM structure.
 ********************************************************************/
@@ -562,6 +729,48 @@ static void lsa_io_sid_enum(char *desc, LSA_SID_ENUM *sen,
        }
 }
 
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+static void lsa_io_trans_names(char *desc, LSA_TRANS_NAME_ENUM *trn,
+                               prs_struct *ps, int depth)
+{
+       int i;
+
+       if (trn == NULL) return;
+
+       prs_debug(ps, depth, desc, "lsa_io_trans_names");
+       depth++;
+
+       prs_align(ps);
+       
+       prs_uint32("num_entries    ", ps, depth, &(trn->num_entries));
+       prs_uint32("ptr_trans_names", ps, depth, &(trn->ptr_trans_names));
+
+       if (trn->ptr_trans_names != 0)
+       {
+               prs_uint32("num_entries2   ", ps, depth, &(trn->num_entries2));
+               SMB_ASSERT_ARRAY(trn->name, trn->num_entries);
+
+               for (i = 0; i < trn->num_entries2; i++)
+               {
+                       fstring t;
+                       slprintf(t, sizeof(t) - 1, "name[%d] ", i);
+
+                       lsa_io_trans_name(t, &(trn->name[i]), ps, depth); /* translated name */
+
+               }
+               for (i = 0; i < trn->num_entries2; i++)
+               {
+                       fstring t;
+                       slprintf(t, sizeof(t) - 1, "name[%d] ", i);
+
+                       smb_io_unistr2(t, &(trn->uni_name[i]), trn->name[i].hdr_name.buffer, ps, depth);
+                       prs_align(ps);
+               }
+       }
+}
+
 /*******************************************************************
 makes a structure.
 ********************************************************************/
@@ -576,9 +785,8 @@ void make_q_lookup_sids(LSA_Q_LOOKUP_SIDS *q_l, POLICY_HND *hnd,
        memcpy(&(q_l->pol), hnd, sizeof(q_l->pol));
        make_lsa_sid_enum(&(q_l->sids), num_sids, sids);
 
-       q_l->names.num_entries     = 0;
        q_l->names.ptr_trans_names = 0;
-       q_l->names.num_entries2    = 0;
+       q_l->names.num_entries     = 0;
 
        q_l->level.value = level;
 }
@@ -603,48 +811,6 @@ void lsa_io_q_lookup_sids(char *desc, LSA_Q_LOOKUP_SIDS *q_s, prs_struct *ps, in
        prs_uint32("mapped_count", ps, depth, &(q_s->mapped_count));
 }
 
-/*******************************************************************
-reads or writes a structure.
-********************************************************************/
-static void lsa_io_trans_names(char *desc, LSA_TRANS_NAME_ENUM *trn,
-                               prs_struct *ps, int depth)
-{
-       int i;
-       int i2;
-
-       if (trn == NULL) return;
-
-       prs_debug(ps, depth, desc, "lsa_io_trans_names");
-       depth++;
-
-       prs_align(ps);
-       
-       prs_uint32("num_entries    ", ps, depth, &(trn->num_entries));
-       prs_uint32("ptr_trans_names", ps, depth, &(trn->ptr_trans_names));
-
-       if (trn->ptr_trans_names != 0)
-       {
-               prs_uint32("num_entries2   ", ps, depth, &(trn->num_entries2));
-
-               SMB_ASSERT_ARRAY(trn->name, trn->num_entries);
-
-               for (i = 0, i2 = 0; i < trn->num_entries2; i++)
-               {
-                       fstring t;
-                       slprintf(t, sizeof(t) - 1, "name[%d] ", i);
-
-                       lsa_io_trans_name(t, &(trn->name[i]), ps, depth); /* translated name */
-
-                       if (trn->name[i].hdr_name.buffer != 0)
-                       {
-                               smb_io_unistr2(t, &(trn->uni_name[i2]), 1, ps, depth);
-                               prs_align(ps);
-                               i2++;
-                       }
-               }
-       }
-}
-
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
@@ -671,7 +837,7 @@ void lsa_io_r_lookup_sids(char *desc,  LSA_R_LOOKUP_SIDS *r_s, prs_struct *ps, i
 makes a structure.
 ********************************************************************/
 void make_q_lookup_names(LSA_Q_LOOKUP_NAMES *q_l, POLICY_HND *hnd,
-                               int num_names, char **names)
+                               int num_names, const char **names)
 {
        int i;
        if (q_l == NULL) return;
@@ -680,16 +846,17 @@ void make_q_lookup_names(LSA_Q_LOOKUP_NAMES *q_l, POLICY_HND *hnd,
 
        memcpy(&(q_l->pol), hnd, sizeof(q_l->pol));
 
-       SMB_ASSERT_ARRAY(q_l->uni_name, q_l->num_entries);
-
        q_l->num_entries     = num_names;
        q_l->num_entries2    = num_names;
 
+       SMB_ASSERT_ARRAY(q_l->uni_name, q_l->num_entries);
+
        for (i = 0; i < num_names; i++)
        {
-               int len = strlen(names[i]);
+               const char* name = names[i];
+               int len = strlen(name);
                make_uni_hdr(&q_l->hdr_name[i], len, len, len != 0);
-               make_unistr2(&q_l->uni_name[i], names[i], len);
+               make_unistr2(&q_l->uni_name[i], name, len);
        }
 
        q_l->num_trans_entries  = 0;