clearing up security descriptor
authorLuke Leighton <lkcl@samba.org>
Wed, 11 Nov 1998 19:22:08 +0000 (19:22 +0000)
committerLuke Leighton <lkcl@samba.org>
Wed, 11 Nov 1998 19:22:08 +0000 (19:22 +0000)
(This used to be commit abdc9d790b7d27b70aaf88451f5c82c99c94ca6e)

source3/include/byteorder.h
source3/include/proto.h
source3/include/rpc_secdes.h
source3/rpc_client/cli_reg.c
source3/rpc_parse/parse_prs.c
source3/rpc_parse/parse_reg.c
source3/rpc_parse/parse_sec.c
source3/rpcclient/cmd_reg.c
source3/rpcclient/display.c

index 3371fd24cbc6d29ea2f26fe4c21439a94affe04c..2a615e9ddebbc58e66c782625ce7600b61daeba2 100644 (file)
@@ -205,7 +205,7 @@ it also defines lots of intermediate macros, just ignore those :-)
 #define DBG_RW_PCVAL(charmode,string,depth,base,read,inbuf,outbuf,len) \
        RW_PCVAL(read,inbuf,outbuf,len) \
        DEBUG(5,("%s%04x %s: ", \
-             tab_depth(depth), PTR_DIFF(inbuf,base),string)); \
+             tab_depth(depth), base,string)); \
     if (charmode) print_asc(5, (unsigned char*)(outbuf), (len)); else \
        { int idx; for (idx = 0; idx < len; idx++) { DEBUG(5,("%02x ", (outbuf)[idx])); } } \
        DEBUG(5,("\n"));
@@ -213,7 +213,7 @@ it also defines lots of intermediate macros, just ignore those :-)
 #define DBG_RW_PSVAL(charmode,string,depth,base,read,inbuf,outbuf,len) \
        RW_PSVAL(read,inbuf,outbuf,len) \
        DEBUG(5,("%s%04x %s: ", \
-             tab_depth(depth), PTR_DIFF(inbuf,base),string)); \
+             tab_depth(depth), base,string)); \
     if (charmode) print_asc(5, (unsigned char*)(outbuf), 2*(len)); else \
        { int idx; for (idx = 0; idx < len; idx++) { DEBUG(5,("%04x ", (outbuf)[idx])); } } \
        DEBUG(5,("\n"));
@@ -221,7 +221,7 @@ it also defines lots of intermediate macros, just ignore those :-)
 #define DBG_RW_PIVAL(charmode,string,depth,base,read,inbuf,outbuf,len) \
        RW_PIVAL(read,inbuf,outbuf,len) \
        DEBUG(5,("%s%04x %s: ", \
-             tab_depth(depth), PTR_DIFF(inbuf,base),string)); \
+             tab_depth(depth), base,string)); \
     if (charmode) print_asc(5, (unsigned char*)(outbuf), 4*(len)); else \
        { int idx; for (idx = 0; idx < len; idx++) { DEBUG(5,("%08x ", (outbuf)[idx])); } } \
        DEBUG(5,("\n"));
@@ -229,15 +229,15 @@ it also defines lots of intermediate macros, just ignore those :-)
 #define DBG_RW_CVAL(string,depth,base,read,inbuf,outbuf) \
        RW_CVAL(read,inbuf,outbuf,0) \
        DEBUG(5,("%s%04x %s: %02x\n", \
-             tab_depth(depth), PTR_DIFF(inbuf,base), string, outbuf));
+             tab_depth(depth), base, string, outbuf));
 
 #define DBG_RW_SVAL(string,depth,base,read,inbuf,outbuf) \
        RW_SVAL(read,inbuf,outbuf,0) \
        DEBUG(5,("%s%04x %s: %04x\n", \
-             tab_depth(depth), PTR_DIFF(inbuf,base), string, outbuf));
+             tab_depth(depth), base, string, outbuf));
 
 #define DBG_RW_IVAL(string,depth,base,read,inbuf,outbuf) \
        RW_IVAL(read,inbuf,outbuf,0) \
        DEBUG(5,("%s%04x %s: %08x\n", \
-             tab_depth(depth), PTR_DIFF(inbuf,base), string, outbuf));
+             tab_depth(depth), base, string, outbuf));
 
index 7eb4f4e49d42049cec5971bf3a349cecbc16f252..1ed983d1a02bae476d3015611b2d506e222303a4 100644 (file)
@@ -1610,9 +1610,12 @@ BOOL prs_unistr2(BOOL charmode, char *name, prs_struct *ps, int depth, UNISTR2 *
 BOOL prs_unistr3(BOOL charmode, char *name, UNISTR3 *str, prs_struct *ps, int depth);
 BOOL prs_unistr(char *name, prs_struct *ps, int depth, UNISTR *str);
 BOOL prs_string(char *name, prs_struct *ps, int depth, char *str, uint16 len, uint16 max_buf_size);
-BOOL prs_uint16_pre(char *name, prs_struct *ps, int depth, uint16 *data16, uint32 *off_ptr);
-BOOL prs_uint16_post(char *name, prs_struct *ps, int depth,
+BOOL prs_uint16_pre(char *name, prs_struct *ps, int depth, uint16 *data16, uint32 *offset);
+BOOL prs_uint16_post(char *name, prs_struct *ps, int depth, uint16 *data16,
                                uint32 ptr_uint16, uint32 start_offset);
+BOOL prs_uint32_pre(char *name, prs_struct *ps, int depth, uint32 *data32, uint32 *offset);
+BOOL prs_uint32_post(char *name, prs_struct *ps, int depth, uint32 *data32,
+                               uint32 ptr_uint32, uint32 start_offset);
 
 /*The following definitions come from  rpc_parse/parse_reg.c  */
 
@@ -1653,9 +1656,6 @@ void reg_io_r_close(char *desc,  REG_R_CLOSE *r_u, prs_struct *ps, int depth);
 void make_reg_q_get_key_sec(REG_Q_GET_KEY_SEC *q_i, POLICY_HND *pol, 
                                uint32 buf_len, SEC_DESC_BUF *sec_buf);
 void reg_io_q_get_key_sec(char *desc,  REG_Q_GET_KEY_SEC *r_q, prs_struct *ps, int depth);
-void make_reg_r_get_key_sec(REG_R_GET_KEY_SEC *r_i, POLICY_HND *pol, 
-                               uint32 buf_len, uint8 *buf,
-                               uint32 status);
 void reg_io_r_get_key_sec(char *desc,  REG_R_GET_KEY_SEC *r_q, prs_struct *ps, int depth);
 void make_reg_q_info(REG_Q_INFO *q_i, POLICY_HND *pol, char *product_type,
                                time_t unix_time, uint8 major, uint8 minor);
@@ -1924,7 +1924,6 @@ void sec_io_info(char *desc, SEC_INFO *t, prs_struct *ps, int depth);
 void sec_io_ace(char *desc, SEC_ACE *t, prs_struct *ps, int depth);
 void sec_io_acl(char *desc, SEC_ACL *t, prs_struct *ps, int depth);
 void sec_io_desc(char *desc, SEC_DESC *t, prs_struct *ps, int depth);
-void make_sec_desc_buf(SEC_DESC_BUF *buf, int len, uint32 buf_ptr);
 void sec_io_desc_buf(char *desc, SEC_DESC_BUF *sec, prs_struct *ps, int depth);
 
 /*The following definitions come from  rpc_parse/parse_srv.c  */
index 587b31e3dcb5799a1974e9ec4f22a5656f644050..1b438d3dfe5777147e424e3789d2126a19ed38f1 100644 (file)
@@ -73,8 +73,7 @@ typedef struct security_acl_info
 /* SEC_DESC */
 typedef struct security_descriptor_info
 {
-       uint16 unknown_1; /* 0x0001 */
-       uint16 unknown_2; /* 0x8004 */
+       uint32 unknown_1; /* 0x8004 0001 */
 
        uint32 off_owner_sid; /* offset to owner sid */
        uint32 off_pnt_sid  ; /* offset to parent? sid */
@@ -94,7 +93,7 @@ typedef struct sec_desc_buf_info
        uint32 undoc;
        uint32 len;
 
-       SEC_DESC sec;
+       SEC_DESC *sec;
 
 } SEC_DESC_BUF;
 
index 27c1c8e7605427d27b6ead61b64a4514d24403fd..69982a8d44a9fc696d38c2d673d399d5bccd3a58 100644 (file)
@@ -471,6 +471,10 @@ BOOL do_reg_get_key_sec(struct cli_state *cli, POLICY_HND *hnd,
                ZERO_STRUCT(r_o);
 
                r_o.data = sec_buf;
+               if (*sec_buf_size != 0)
+               {
+                       sec_buf->sec = (SEC_DESC*)malloc(*sec_buf_size);
+               }
                reg_io_r_get_key_sec("", &r_o, &rbuf, 0);
                p = rbuf.offset != 0;
 
index 873a6897924339383cc3bf93006f16cacf291b86..cc068778ac330c4ee9c0e1d557f8a5832283f21b 100644 (file)
@@ -303,14 +303,18 @@ BOOL prs_string(char *name, prs_struct *ps, int depth, char *str, uint16 len, ui
  prs_uint16 wrapper.  call this and it sets up a pointer to where the
  uint16 should be stored, or gets the size if reading
  ********************************************************************/
-BOOL prs_uint16_pre(char *name, prs_struct *ps, int depth, uint16 *data16, uint32 *off_ptr)
+BOOL prs_uint16_pre(char *name, prs_struct *ps, int depth, uint16 *data16, uint32 *offset)
 {
-       (*off_ptr) = ps->offset;
+       (*offset) = ps->io;
        if (ps->io)
        {
                /* reading. */
                return prs_uint16(name, ps, depth, data16);
        }
+       else
+       {
+               ps->offset += sizeof(uint16);
+       }
        return True;
 }
 
@@ -318,7 +322,7 @@ BOOL prs_uint16_pre(char *name, prs_struct *ps, int depth, uint16 *data16, uint3
  prs_uint16 wrapper.  call this and it retrospectively stores the size.
  does nothing on reading, as that is already handled by ...._pre()
  ********************************************************************/
-BOOL prs_uint16_post(char *name, prs_struct *ps, int depth,
+BOOL prs_uint16_post(char *name, prs_struct *ps, int depth, uint16 *data16,
                                uint32 ptr_uint16, uint32 start_offset)
 {
        if (!ps->io)
@@ -331,6 +335,53 @@ BOOL prs_uint16_post(char *name, prs_struct *ps, int depth,
                prs_uint16(name, ps, depth, &data_size);
                ps->offset = old_offset;
        }
+       else
+       {
+               ps->offset = start_offset + (*data16);
+       }
+       return True;
+}
+
+/*******************************************************************
+ prs_uint32 wrapper.  call this and it sets up a pointer to where the
+ uint32 should be stored, or gets the size if reading
+ ********************************************************************/
+BOOL prs_uint32_pre(char *name, prs_struct *ps, int depth, uint32 *data32, uint32 *offset)
+{
+       (*offset) = ps->io;
+       if (ps->io)
+       {
+               /* reading. */
+               return prs_uint32(name, ps, depth, data32);
+       }
+       else
+       {
+               ps->offset += sizeof(uint32);
+       }
+       return True;
+}
+
+/*******************************************************************
+ prs_uint32 wrapper.  call this and it retrospectively stores the size.
+ does nothing on reading, as that is already handled by ...._pre()
+ ********************************************************************/
+BOOL prs_uint32_post(char *name, prs_struct *ps, int depth, uint32 *data32,
+                               uint32 ptr_uint32, uint32 start_offset)
+{
+       if (!ps->io)
+       {
+               /* storing: go back and do a retrospective job.  i hate this */
+               uint32 data_size = ps->offset - start_offset;
+               uint32 old_offset = ps->offset;
+
+               ps->offset = ptr_uint32;
+               prs_uint32(name, ps, depth, &data_size);
+               ps->offset = old_offset;
+       }
+       else
+       {
+               ps->offset = start_offset + (*data32);
+       }
        return True;
 }
 
index fa63717e5b4e8aa9407f81d9e68c339dc09e4380..b650847b809b8d5ce24dfc74e6c0e33672903cc9 100644 (file)
@@ -553,11 +553,17 @@ void make_reg_q_get_key_sec(REG_Q_GET_KEY_SEC *q_i, POLICY_HND *pol,
 
        q_i->unknown = 0x7;
 
-       q_i->ptr = 1;
+       q_i->ptr = sec_buf != NULL ? 1 : 0;
        q_i->data = sec_buf;
 
-       make_buf_hdr(&(q_i->hdr_sec), buf_len, 0);
-       make_sec_desc_buf(q_i->data, buf_len, 0);
+       if (sec_buf != NULL)
+       {
+               make_buf_hdr(&(q_i->hdr_sec), buf_len, 0);
+               q_i->data->max_len = buf_len;
+               q_i->data->undoc = 0;
+               q_i->data->len = 0;
+               q_i->data->sec = NULL;
+       }
 }
 
 /*******************************************************************
@@ -586,10 +592,11 @@ void reg_io_q_get_key_sec(char *desc,  REG_Q_GET_KEY_SEC *r_q, prs_struct *ps, i
        }
 }
 
+#if 0
 /*******************************************************************
 makes a structure.
 ********************************************************************/
-void make_reg_r_get_key_sec(REG_R_GET_KEY_SEC *r_i, POLICY_HND *pol, 
+ void make_reg_r_get_key_sec(REG_R_GET_KEY_SEC *r_i, POLICY_HND *pol, 
                                uint32 buf_len, uint8 *buf,
                                uint32 status)
 {
@@ -601,6 +608,7 @@ void make_reg_r_get_key_sec(REG_R_GET_KEY_SEC *r_i, POLICY_HND *pol,
 
        r_i->status = status; /* 0x0000 0000 or 0x0000 007a */
 }
+#endif 
 
 /*******************************************************************
 reads or writes a structure.
index bedf042b7fe7080255635276ebc9d752d2f5bf4f..af5da93bfb1b55817c30b3ca86ad468c83bea62c 100644 (file)
@@ -66,11 +66,7 @@ void sec_io_ace(char *desc, SEC_ACE *t, prs_struct *ps, int depth)
        prs_align(ps);
        smb_io_dom_sid("sid ", &t->sid , ps, depth);
 
-       prs_uint16_post("ace_size ", ps, depth, offset_ace_size, old_offset);
-       if (ps->io)
-       {
-               ps->offset = old_offset + t->ace_size;
-       }
+       prs_uint16_post("ace_size ", ps, depth, &t->ace_size, offset_ace_size, old_offset);
 }
 
 /*******************************************************************
@@ -105,11 +101,7 @@ void sec_io_acl(char *desc, SEC_ACL *t, prs_struct *ps, int depth)
 
        prs_align(ps);
 
-       prs_uint16_post("acl_size ", ps, depth, offset_acl_size, old_offset);
-       if (ps->io)
-       {
-               ps->offset = old_offset + t->acl_size;
-       }
+       prs_uint16_post("acl_size ", ps, depth, &t->acl_size, offset_acl_size, old_offset);
 }
 
 
@@ -118,6 +110,12 @@ reads or writes a structure.
 ********************************************************************/
 void sec_io_desc(char *desc, SEC_DESC *t, prs_struct *ps, int depth)
 {
+       uint32 off_owner_sid;
+       uint32 off_pnt_sid  ;
+       uint32 off_unknown  ;
+       uint32 off_acl      ;
+       uint32 old_offset;
+
        if (t == NULL) return;
 
        prs_debug(ps, depth, desc, "sec_io_desc");
@@ -125,39 +123,39 @@ void sec_io_desc(char *desc, SEC_DESC *t, prs_struct *ps, int depth)
 
        prs_align(ps);
        
-       prs_uint16("unknown_1", ps, depth, &(t->unknown_1));
-       prs_uint16("unknown_2", ps, depth, &(t->unknown_2));
+       /* start of security descriptor stored for back-calc offset purposes */
+       old_offset = ps->offset;
+
+       prs_uint32("unknown_1", ps, depth, &(t->unknown_1));
 
-       prs_uint32("off_owner_sid", ps, depth, &(t->off_owner_sid));
-       prs_uint32("off_pnt_sid  ", ps, depth, &(t->off_pnt_sid  ));
-       prs_uint32("off_unknown  ", ps, depth, &(t->off_unknown  ));
-       prs_uint32("off_acl      ", ps, depth, &(t->off_acl      ));
+       prs_uint32_pre("off_owner_sid", ps, depth, &(t->off_owner_sid), &off_owner_sid);
+       prs_uint32_pre("off_pnt_sid  ", ps, depth, &(t->off_pnt_sid  ), &off_pnt_sid  );
+       prs_uint32_pre("off_unknown  ", ps, depth, &(t->off_unknown  ), &off_unknown  );
+       prs_uint32_pre("off_acl      ", ps, depth, &(t->off_acl      ), &off_acl      );
 
+       prs_uint32_post("off_acl     ", ps, depth, &(t->off_acl      ), off_acl      , old_offset);
        sec_io_acl    ("acl"       , &t->acl       , ps, depth);
+       prs_align(ps);
+
+       prs_uint32_post("off_unknown  ", ps, depth, &(t->off_unknown  ), off_unknown  , ps->offset);
+
+       prs_uint32_post("off_owner_sid", ps, depth, &(t->off_owner_sid), off_owner_sid, old_offset);
        smb_io_dom_sid("owner_sid ", &t->owner_sid , ps, depth);
        prs_align(ps);
+
+       prs_uint32_post("off_pnt_sid  ", ps, depth, &(t->off_pnt_sid  ), off_pnt_sid  , old_offset);
        smb_io_dom_sid("parent_sid", &t->parent_sid, ps, depth);
        prs_align(ps);
 }
 
-/*******************************************************************
-creates a SEC_DESC_BUF structure.
-********************************************************************/
-void make_sec_desc_buf(SEC_DESC_BUF *buf, int len, uint32 buf_ptr)
-{
-       ZERO_STRUCTP(buf);
-
-       /* max buffer size (allocated size) */
-       buf->max_len = len;
-       buf->undoc       = 0;
-       buf->len = buf_ptr != 0 ? len : 0;
-}
-
 /*******************************************************************
 reads or writes a SEC_DESC_BUF structure.
 ********************************************************************/
 void sec_io_desc_buf(char *desc, SEC_DESC_BUF *sec, prs_struct *ps, int depth)
 {
+       uint32 off_len;
+       uint32 old_offset;
+
        if (sec == NULL) return;
 
        prs_debug(ps, depth, desc, "sec_io_desc_buf");
@@ -165,12 +163,18 @@ void sec_io_desc_buf(char *desc, SEC_DESC_BUF *sec, prs_struct *ps, int depth)
 
        prs_align(ps);
        
-       prs_uint32("max_len", ps, depth, &(sec->max_len));
-       prs_uint32("undoc  ", ps, depth, &(sec->undoc  ));
-       prs_uint32("len    ", ps, depth, &(sec->len    ));
+       prs_uint32    ("max_len", ps, depth, &(sec->max_len));
+       prs_uint32    ("undoc  ", ps, depth, &(sec->undoc  ));
+       prs_uint32_pre("len    ", ps, depth, &(sec->len    ), &off_len);
+
+       old_offset = ps->offset;
 
-       if (sec->len != 0)
+       /* reading, length is non-zero; writing, descriptor is non-NULL */
+       if ((sec->len != 0 || (!ps->io)) && sec->sec != NULL)
        {
-               sec_io_desc("sec   ", &sec->sec, ps, depth);
+               sec_io_desc("sec   ", sec->sec, ps, depth);
        }
+
+       prs_uint32_post("len    ", ps, depth, &(sec->len    ), off_len    , old_offset);
 }
+
index 4d49d19b3b605a5d10b756ade5c4dc6c5ab5f675..fd5fc71828d5d0d27bb4767a268c164fe43ed956 100644 (file)
@@ -766,17 +766,20 @@ void cmd_reg_get_key_sec(struct client_info *info)
 
        /* query key sec info.  first call sets sec_buf_size. */
        sec_buf_size = 0;
+       sec_buf.sec = NULL;
+
        res4 = res3 ? do_reg_get_key_sec(smb_cli, &key_pol,
                                &sec_buf_size, &sec_buf) : False;
        
        res4 = res4 ? do_reg_get_key_sec(smb_cli, &key_pol,
                                &sec_buf_size, &sec_buf) : False;
 
-       if (res4 && sec_buf.len > 0)
+       if (res4 && sec_buf.len > 0 && sec_buf.sec != NULL)
        {
-               display_sec_desc(out_hnd, ACTION_HEADER   , &sec_buf.sec);
-               display_sec_desc(out_hnd, ACTION_ENUMERATE, &sec_buf.sec);
-               display_sec_desc(out_hnd, ACTION_FOOTER   , &sec_buf.sec);
+               display_sec_desc(out_hnd, ACTION_HEADER   , sec_buf.sec);
+               display_sec_desc(out_hnd, ACTION_ENUMERATE, sec_buf.sec);
+               display_sec_desc(out_hnd, ACTION_FOOTER   , sec_buf.sec);
+               free(sec_buf.sec);
        }
 
        /* close the key handle */
index c55358bc9c21545b0380090b5740127dc8f9f304..c35f8db9af5c569b2a34c35a499b2256f8e6017e 100644 (file)
@@ -1175,7 +1175,7 @@ void display_sec_desc(FILE *out_hnd, enum action_type action, SEC_DESC *sec)
        {
                case ACTION_HEADER:
                {
-                       fprintf(out_hnd, "\tSecurity Descriptor\tunk 1,2: %x %x\n", sec->unknown_1, sec->unknown_2); 
+                       fprintf(out_hnd, "\tSecurity Descriptor\tunk 1: %x\n", sec->unknown_1); 
                        fprintf(out_hnd, "\t-------------------\n");
 
                        break;