added the 'lsaenumacctwithright' command to rpcclient. This allows you
authorAndrew Tridgell <tridge@samba.org>
Mon, 10 Feb 2003 11:31:23 +0000 (11:31 +0000)
committerAndrew Tridgell <tridge@samba.org>
Mon, 10 Feb 2003 11:31:23 +0000 (11:31 +0000)
to lookup what SIDs have a particular privilege (that is how
privileges are stored).
(This used to be commit 3ddb5fb0dd33992b7db54a661752551a3fefc0b4)

source3/include/rpc_lsa.h
source3/include/rpc_misc.h
source3/rpc_client/cli_lsarpc.c
source3/rpc_parse/parse_lsa.c
source3/rpc_parse/parse_misc.c
source3/rpcclient/cmd_lsarpc.c

index fc6cbeb6cdab5c46c615d968f635142c504412f7..c091e7332127cb94eff6808d55ec944195685246 100644 (file)
@@ -553,7 +553,6 @@ typedef struct
        DOM_SID2 sid;
        uint32 removeall;
        UNISTR2_ARRAY rights;
-       uint32 count;
 } LSA_Q_REMOVE_ACCT_RIGHTS;
 
 /* LSA_R_REMOVE_ACCT_RIGHTS - LSA remove account rights */
@@ -562,6 +561,23 @@ typedef struct
        NTSTATUS status;
 } LSA_R_REMOVE_ACCT_RIGHTS;
 
+/* LSA_Q_ENUM_ACCT_WITH_RIGHT - LSA enum accounts with right */
+typedef struct
+{
+       POLICY_HND pol;
+       STRHDR right_hdr;
+       UNISTR2 right; 
+} LSA_Q_ENUM_ACCT_WITH_RIGHT;
+
+/* LSA_R_ENUM_ACCT_WITH_RIGHT - LSA enum accounts with right */
+typedef struct
+{
+       uint32 count;
+       SID_ARRAY sids;
+       NTSTATUS status;
+} LSA_R_ENUM_ACCT_WITH_RIGHT;
+
+
 /* LSA_Q_PRIV_GET_DISPNAME - LSA get privilege display name */
 typedef struct lsa_q_priv_get_dispname
 {
index 771048943512892ab3618e84ad2417677d49b34b..06ad760c58fee7d11be50c688b622cafef670cb2 100644 (file)
@@ -227,6 +227,22 @@ typedef struct
        UNISTR2_ARRAY_EL *strings;
 } UNISTR2_ARRAY;
 
+
+/* an element in a sid array */
+typedef struct
+{
+       uint32 ref_id;
+       DOM_SID2 sid;
+} SID_ARRAY_EL;
+
+/* an array of sids */
+typedef struct 
+{
+       uint32 ref_id;
+       uint32 count;
+       SID_ARRAY_EL *sids;
+} SID_ARRAY;
+
 /* DOM_RID2 - domain RID structure for ntlsa pipe */
 typedef struct domrid2_info
 {
index 3c7d0855f4efaf387f769f96abe72669824f79c8..bb9f4e938469fff01871b18a3d4e6f001695e185 100644 (file)
@@ -1292,6 +1292,58 @@ done:
 }
 
 
+/* list account SIDs that have the specified right */
+
+NTSTATUS cli_lsa_enum_account_with_right(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+                                        POLICY_HND *pol, const char *right,
+                                        uint32 *count, DOM_SID **sids)
+{
+       prs_struct qbuf, rbuf;
+       LSA_Q_ENUM_ACCT_WITH_RIGHT q;
+       LSA_R_ENUM_ACCT_WITH_RIGHT r;
+       NTSTATUS result;
+
+       ZERO_STRUCT(q);
+
+       /* Initialise parse structures */
+       prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+       prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
+
+       /* Marshall data and send request */
+       init_q_enum_acct_with_right(&q, pol, right);
+
+       if (!lsa_io_q_enum_acct_with_right("", &q, &qbuf, 0) ||
+           !rpc_api_pipe_req(cli, LSA_ENUMACCTWITHRIGHT, &qbuf, &rbuf)) {
+               result = NT_STATUS_UNSUCCESSFUL;
+               goto done;
+       }
+
+       /* Unmarshall response */
+
+       if (!lsa_io_r_enum_acct_with_right("", &r, &rbuf, 0)) {
+               result = NT_STATUS_UNSUCCESSFUL;
+               goto done;
+       }
+
+       *count = r.count;
+
+       if (!NT_STATUS_IS_OK(result = r.status)) {
+               goto done;
+       }
+
+       if (*count) {
+               int i;
+               (*sids) = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * (*count));
+               for (i=0; i<*count; i++) {
+                       sid_copy(&(*sids)[i], &r.sids.sids[i].sid.sid);
+               }
+       }
+done:
+
+       return result;
+}
+
+
 #if 0
 
 /** An example of how to use the routines in this file.  Fetch a DOMAIN
index a3ffe86af3ca8cdbffb3d7fe2c48822a77a4e11e..6832b0df667bc6b2c1b0adf2dbd93d385e2eaabb 100644 (file)
@@ -2395,7 +2395,6 @@ void init_q_remove_acct_rights(LSA_Q_REMOVE_ACCT_RIGHTS *q_q,
        init_dom_sid2(&q_q->sid, sid);
        q_q->removeall = removeall;
        init_unistr2_array(&q_q->rights, count, rights);
-       q_q->count = 5;
 }
 
 
@@ -2426,7 +2425,7 @@ BOOL lsa_io_q_remove_acct_rights(const char *desc, LSA_Q_REMOVE_ACCT_RIGHTS *q_q
 }
 
 /*******************************************************************
-reads or writes a LSA_R_ENUM_ACCT_RIGHTS structure.
+reads or writes a LSA_R_REMOVE_ACCT_RIGHTS structure.
 ********************************************************************/
 BOOL lsa_io_r_remove_acct_rights(const char *desc, LSA_R_REMOVE_ACCT_RIGHTS *r_c, prs_struct *ps, int depth)
 {
@@ -2446,3 +2445,68 @@ void init_r_remove_acct_rights(LSA_R_REMOVE_ACCT_RIGHTS *q_r)
 {
        DEBUG(5, ("init_r_remove_acct_rights\n"));
 }
+
+/*******************************************************************
+ Inits an LSA_Q_ENUM_ACCT_WITH_RIGHT structure.
+********************************************************************/
+void init_q_enum_acct_with_right(LSA_Q_ENUM_ACCT_WITH_RIGHT *q_q, 
+                                POLICY_HND *hnd, 
+                                const char *right)
+{
+       DEBUG(5, ("init_q_enum_acct_with_right\n"));
+
+       q_q->pol = *hnd;
+       init_unistr2(&q_q->right, right, strlen(right));
+       init_str_hdr(&q_q->right_hdr, 
+                    q_q->right.uni_max_len*2, 
+                    q_q->right.uni_max_len*2, right?1:0);
+}
+
+
+/*******************************************************************
+reads or writes a LSA_Q_ENUM_ACCT_WITH_RIGHT structure.
+********************************************************************/
+BOOL lsa_io_q_enum_acct_with_right(const char *desc, LSA_Q_ENUM_ACCT_WITH_RIGHT *q_q, prs_struct *ps, int depth)
+{
+       prs_debug(ps, depth, desc, "lsa_io_q_enum_acct_with_right");
+       depth++;
+
+       if (!smb_io_pol_hnd("", &q_q->pol, ps, depth))
+               return False;
+
+       if (!prs_uint32("ref_id  ", ps, depth, &q_q->right_hdr.buffer))
+               return False;
+
+       if (UNMARSHALLING(ps) && q_q->right_hdr.buffer == 0) {
+               return True;
+       }
+
+       if (!smb_io_strhdr("", &q_q->right_hdr, ps, depth))
+               return False;
+
+       if (!smb_io_unistr2("", &q_q->right, q_q->right_hdr.buffer, ps, depth))
+               return False;
+
+       return True;
+}
+
+
+/*******************************************************************
+reads or writes a LSA_R_ENUM_ACCT_WITH_RIGHT structure.
+********************************************************************/
+BOOL lsa_io_r_enum_acct_with_right(const char *desc, LSA_R_ENUM_ACCT_WITH_RIGHT *r_c, prs_struct *ps, int depth)
+{
+       prs_debug(ps, depth, desc, "lsa_io_r_enum_acct_with_right");
+       depth++;
+
+       if (!prs_uint32("count  ", ps, depth, &r_c->count))
+               return False;
+
+       if (!smb_io_sid_array("sids  ", &r_c->sids, ps, depth))
+               return False;
+
+       if(!prs_ntstatus("status", ps, depth, &r_c->status))
+               return False;
+
+       return True;
+}
index 43d26a691d02f3fb9988f3b87bbaa115c8e34c26..403a12ee538e801eb4946657114458840301d04c 100644 (file)
@@ -1122,6 +1122,51 @@ BOOL smb_io_unistr2_array(const char *desc, UNISTR2_ARRAY *array, prs_struct *ps
 }
 
 
+/*******************************************************************
+ Reads or writes a SID_ARRAY structure.
+********************************************************************/
+BOOL smb_io_sid_array(const char *desc, SID_ARRAY *array, prs_struct *ps, int depth)
+{
+       int i;
+
+       prs_debug(ps, depth, desc, "smb_io_sid_array");
+       depth++;
+
+       if(!prs_uint32("ref_id", ps, depth, &array->ref_id))
+               return False;
+
+       if (! array->ref_id) {
+               return True;
+       }
+
+       if(!prs_uint32("count", ps, depth, &array->count))
+               return False;
+
+       if (array->count == 0) {
+               return True;
+       }
+
+       if (UNMARSHALLING(ps)) {
+               array->sids = talloc_zero(get_talloc_ctx(), array->count * sizeof(array->sids[0]));
+       }
+       if (! array->sids) {
+               return False;
+       }
+
+       for (i=0;i<array->count;i++) {
+               if(!prs_uint32("ref_id", ps, depth, &array->sids[i].ref_id))
+                       return False;
+       }
+
+       for (i=0;i<array->count;i++) {
+               if (!smb_io_dom_sid2("sid", &array->sids[i].sid, ps, depth)) 
+                       return False;
+       }
+       
+       return True;
+}
+
+
 /*******************************************************************
  Inits a DOM_RID2 structure.
 ********************************************************************/
index 8afeb8e83bd1410dd0161cc9910383442d263256..91107a7c6d1fbca4a677517fe9cc92daf201632a 100644 (file)
@@ -297,7 +297,7 @@ static NTSTATUS cmd_lsa_enum_trust_dom(struct cli_state *cli,
 /* Enumerates privileges */
 
 static NTSTATUS cmd_lsa_enum_privilege(struct cli_state *cli, 
-                                          TALLOC_CTX *mem_ctx, int argc, 
+                                      TALLOC_CTX *mem_ctx, int argc, 
                                           char **argv) 
 {
        POLICY_HND pol;
@@ -388,7 +388,7 @@ static NTSTATUS cmd_lsa_get_dispname(struct cli_state *cli,
 /* Enumerate the LSA SIDS */
 
 static NTSTATUS cmd_lsa_enum_sids(struct cli_state *cli, 
-                                     TALLOC_CTX *mem_ctx, int argc, 
+                                 TALLOC_CTX *mem_ctx, int argc, 
                                      char **argv) 
 {
        POLICY_HND pol;
@@ -540,6 +540,50 @@ static NTSTATUS cmd_lsa_enum_acct_rights(struct cli_state *cli,
 }
 
 
+/* Enumerate the accounts with a specific right */
+
+static NTSTATUS cmd_lsa_enum_acct_with_right(struct cli_state *cli, 
+                                            TALLOC_CTX *mem_ctx, int argc, 
+                                            const char **argv) 
+{
+       POLICY_HND dom_pol;
+       NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
+       DOM_SID *sids;
+       uint32 count;
+       const char *right;
+
+       int i;
+
+       if (argc != 2 ) {
+               printf("Usage: %s <RIGHT>\n", argv[0]);
+               return NT_STATUS_OK;
+       }
+
+       right = argv[1];
+
+       result = cli_lsa_open_policy2(cli, mem_ctx, True, 
+                                    SEC_RIGHTS_MAXIMUM_ALLOWED,
+                                    &dom_pol);
+
+       if (!NT_STATUS_IS_OK(result))
+               goto done;
+
+       result = cli_lsa_enum_account_with_right(cli, mem_ctx, &dom_pol, right, &count, &sids);
+
+       if (!NT_STATUS_IS_OK(result))
+               goto done;
+
+       printf("found %d SIDs for '%s'\n", count, right);
+
+       for (i = 0; i < count; i++) {
+               printf("\t%s\n", sid_string_static(&sids[i]));
+       }
+
+ done:
+       return result;
+}
+
+
 /* add some privileges to a SID via LsaAddAccountRights */
 
 static NTSTATUS cmd_lsa_add_acct_rights(struct cli_state *cli, 
@@ -703,6 +747,7 @@ struct cmd_set lsarpc_commands[] = {
        { "lsaenumsid",          cmd_lsa_enum_sids,          PI_LSARPC, "Enumerate the LSA SIDS",               "" },
        { "lsaenumprivsaccount", cmd_lsa_enum_privsaccounts, PI_LSARPC, "Enumerate the privileges of an SID",   "" },
        { "lsaenumacctrights",   cmd_lsa_enum_acct_rights,   PI_LSARPC, "Enumerate the rights of an SID",   "" },
+       { "lsaenumacctwithright",cmd_lsa_enum_acct_with_right,PI_LSARPC,"Enumerate accounts with a right",   "" },
        { "lsaaddacctrights",    cmd_lsa_add_acct_rights,    PI_LSARPC, "Add rights to an account",   "" },
        { "lsaremoveacctrights", cmd_lsa_remove_acct_rights, PI_LSARPC, "Remove rights from an account",   "" },
        { "lsalookupprivvalue",  cmd_lsa_lookupprivvalue,    PI_LSARPC, "Get a privilege value given its name", "" },