LCOV - code coverage report
Current view: top level - source3/rpcclient - cmd_lsarpc.c (source / functions) Hit Total Coverage
Test: coverage report for vadcx-master-patch-75612 fe003de8 Lines: 129 1158 11.1 %
Date: 2024-02-29 22:57:05 Functions: 6 44 13.6 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    RPC pipe client
       4             : 
       5             :    Copyright (C) Tim Potter              2000
       6             :    Copyright (C) Rafal Szczesniak        2002
       7             :    Copyright (C) Guenther Deschner       2008
       8             : 
       9             :    This program is free software; you can redistribute it and/or modify
      10             :    it under the terms of the GNU General Public License as published by
      11             :    the Free Software Foundation; either version 3 of the License, or
      12             :    (at your option) any later version.
      13             : 
      14             :    This program is distributed in the hope that it will be useful,
      15             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17             :    GNU General Public License for more details.
      18             : 
      19             :    You should have received a copy of the GNU General Public License
      20             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      21             : */
      22             : 
      23             : #include "includes.h"
      24             : #include "rpcclient.h"
      25             : #include "../libcli/auth/libcli_auth.h"
      26             : #include "../librpc/gen_ndr/ndr_lsa.h"
      27             : #include "../librpc/gen_ndr/ndr_lsa_c.h"
      28             : #include "rpc_client/cli_lsarpc.h"
      29             : #include "rpc_client/init_lsa.h"
      30             : #include "../libcli/security/security.h"
      31             : 
      32             : /* useful function to allow entering a name instead of a SID and
      33             :  * looking it up automatically */
      34           0 : static NTSTATUS name_to_sid(struct rpc_pipe_client *cli,
      35             :                             TALLOC_CTX *mem_ctx,
      36             :                             struct dom_sid *sid,
      37             :                             const char *name)
      38             : {
      39             :         struct policy_handle pol;
      40             :         enum lsa_SidType *sid_types;
      41             :         NTSTATUS status, result;
      42             :         struct dom_sid *sids;
      43           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
      44             : 
      45             :         /* maybe its a raw SID */
      46           0 :         if (strncmp(name, "S-", 2) == 0 &&
      47           0 :             string_to_sid(sid, name)) {
      48           0 :                 return NT_STATUS_OK;
      49             :         }
      50             : 
      51           0 :         status = rpccli_lsa_open_policy(cli, mem_ctx, True,
      52             :                                      SEC_FLAG_MAXIMUM_ALLOWED,
      53             :                                      &pol);
      54           0 :         if (!NT_STATUS_IS_OK(status))
      55           0 :                 goto done;
      56             : 
      57           0 :         status = rpccli_lsa_lookup_names(cli, mem_ctx, &pol, 1, &name, NULL, 1, &sids, &sid_types);
      58           0 :         if (!NT_STATUS_IS_OK(status))
      59           0 :                 goto done;
      60             : 
      61           0 :         dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
      62             : 
      63           0 :         *sid = sids[0];
      64             : 
      65           0 : done:
      66           0 :         return status;
      67             : }
      68             : 
      69           0 : static void display_query_info_1(struct lsa_AuditLogInfo *r)
      70             : {
      71           0 :         d_printf("percent_full:\t%d\n", r->percent_full);
      72           0 :         d_printf("maximum_log_size:\t%d\n", r->maximum_log_size);
      73           0 :         d_printf("retention_time:\t%lld\n", (long long)r->retention_time);
      74           0 :         d_printf("shutdown_in_progress:\t%d\n", r->shutdown_in_progress);
      75           0 :         d_printf("time_to_shutdown:\t%lld\n", (long long)r->time_to_shutdown);
      76           0 :         d_printf("next_audit_record:\t%d\n", r->next_audit_record);
      77           0 : }
      78             : 
      79           0 : static void display_query_info_2(struct lsa_AuditEventsInfo *r)
      80             : {
      81             :         int i;
      82           0 :         d_printf("Auditing enabled:\t%d\n", r->auditing_mode);
      83           0 :         d_printf("Auditing categories:\t%d\n", r->count);
      84           0 :         d_printf("Auditsettings:\n");
      85           0 :         for (i=0; i<r->count; i++) {
      86           0 :                 const char *val = audit_policy_str(talloc_tos(), r->settings[i]);
      87           0 :                 const char *policy = audit_description_str(i);
      88           0 :                 d_printf("%s:\t%s\n", policy, val);
      89             :         }
      90           0 : }
      91             : 
      92           0 : static void display_query_info_3(struct lsa_DomainInfo *r)
      93             : {
      94             :         struct dom_sid_buf buf;
      95           0 :         d_printf("Domain Name: %s\n", r->name.string);
      96           0 :         d_printf("Domain Sid: %s\n", dom_sid_str_buf(r->sid, &buf));
      97           0 : }
      98             : 
      99           0 : static void display_query_info_5(struct lsa_DomainInfo *r)
     100             : {
     101             :         struct dom_sid_buf buf;
     102           0 :         d_printf("Domain Name: %s\n", r->name.string);
     103           0 :         d_printf("Domain Sid: %s\n", dom_sid_str_buf(r->sid, &buf));
     104           0 : }
     105             : 
     106           0 : static void display_query_info_10(struct lsa_AuditFullSetInfo *r)
     107             : {
     108           0 :         d_printf("Shutdown on full: %d\n", r->shutdown_on_full);
     109           0 : }
     110             : 
     111           0 : static void display_query_info_11(struct lsa_AuditFullQueryInfo *r)
     112             : {
     113           0 :         d_printf("Shutdown on full: %d\n", r->shutdown_on_full);
     114           0 :         d_printf("Log is full: %d\n", r->log_is_full);
     115           0 : }
     116             : 
     117           0 : static void display_query_info_12(struct lsa_DnsDomainInfo *r)
     118             : {
     119             :         struct dom_sid_buf buf;
     120           0 :         d_printf("Domain NetBios Name: %s\n", r->name.string);
     121           0 :         d_printf("Domain DNS Name: %s\n", r->dns_domain.string);
     122           0 :         d_printf("Domain Forest Name: %s\n", r->dns_forest.string);
     123           0 :         d_printf("Domain Sid: %s\n", dom_sid_str_buf(r->sid, &buf));
     124           0 :         d_printf("Domain GUID: %s\n", GUID_string(talloc_tos(),
     125           0 :                                                       &r->domain_guid));
     126           0 : }
     127             : 
     128           0 : static void display_lsa_query_info(union lsa_PolicyInformation *info,
     129             :                                    enum lsa_PolicyInfo level)
     130             : {
     131           0 :         switch (level) {
     132           0 :                 case 1:
     133           0 :                         display_query_info_1(&info->audit_log);
     134           0 :                         break;
     135           0 :                 case 2:
     136           0 :                         display_query_info_2(&info->audit_events);
     137           0 :                         break;
     138           0 :                 case 3:
     139           0 :                         display_query_info_3(&info->domain);
     140           0 :                         break;
     141           0 :                 case 5:
     142           0 :                         display_query_info_5(&info->account_domain);
     143           0 :                         break;
     144           0 :                 case 10:
     145           0 :                         display_query_info_10(&info->auditfullset);
     146           0 :                         break;
     147           0 :                 case 11:
     148           0 :                         display_query_info_11(&info->auditfullquery);
     149           0 :                         break;
     150           0 :                 case 12:
     151           0 :                         display_query_info_12(&info->dns);
     152           0 :                         break;
     153           0 :                 default:
     154           0 :                         printf("can't display info level: %d\n", level);
     155           0 :                         break;
     156             :         }
     157           0 : }
     158             : 
     159           0 : static NTSTATUS cmd_lsa_query_info_policy(struct rpc_pipe_client *cli,
     160             :                                           TALLOC_CTX *mem_ctx,
     161             :                                           int argc,
     162             :                                           const char **argv)
     163             : {
     164             :         struct policy_handle pol;
     165             :         NTSTATUS status, result;
     166           0 :         union lsa_PolicyInformation *info = NULL;
     167           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
     168             : 
     169           0 :         uint32_t info_class = 3;
     170             : 
     171           0 :         if (argc > 2) {
     172           0 :                 printf("Usage: %s [info_class]\n", argv[0]);
     173           0 :                 return NT_STATUS_OK;
     174             :         }
     175             : 
     176           0 :         if (argc == 2)
     177           0 :                 info_class = atoi(argv[1]);
     178             : 
     179           0 :         switch (info_class) {
     180           0 :         case 12: {
     181           0 :                 union lsa_revision_info out_revision_info = {
     182             :                         .info1 = {
     183             :                                 .revision = 0,
     184             :                         },
     185             :                 };
     186           0 :                 uint32_t out_version = 0;
     187             : 
     188           0 :                 status = dcerpc_lsa_open_policy_fallback(
     189             :                         b,
     190             :                         mem_ctx,
     191           0 :                         cli->srv_name_slash,
     192             :                         true,
     193             :                         SEC_FLAG_MAXIMUM_ALLOWED,
     194             :                         &out_version,
     195             :                         &out_revision_info,
     196             :                         &pol,
     197             :                         &result);
     198           0 :                 if (any_nt_status_not_ok(status, result, &status)) {
     199           0 :                         goto done;
     200             :                 }
     201             : 
     202           0 :                 status = dcerpc_lsa_QueryInfoPolicy2(b, mem_ctx,
     203             :                                                      &pol,
     204             :                                                      info_class,
     205             :                                                      &info,
     206             :                                                      &result);
     207           0 :                 break;
     208             :         }
     209           0 :         default:
     210           0 :                 status = rpccli_lsa_open_policy(cli, mem_ctx, True,
     211             :                                                 SEC_FLAG_MAXIMUM_ALLOWED,
     212             :                                                 &pol);
     213             : 
     214           0 :                 if (!NT_STATUS_IS_OK(status))
     215           0 :                         goto done;
     216             : 
     217           0 :                 status = dcerpc_lsa_QueryInfoPolicy(b, mem_ctx,
     218             :                                                     &pol,
     219             :                                                     info_class,
     220             :                                                     &info,
     221             :                                                     &result);
     222             :         }
     223             : 
     224           0 :         if (!NT_STATUS_IS_OK(status)) {
     225           0 :                 goto done;
     226             :         }
     227           0 :         status = result;
     228           0 :         if (NT_STATUS_IS_OK(result)) {
     229           0 :                 display_lsa_query_info(info, info_class);
     230             :         }
     231             : 
     232           0 :         dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
     233             : 
     234           0 :  done:
     235           0 :         return status;
     236             : }
     237             : 
     238             : /* Resolve a list of names to a list of sids */
     239             : 
     240           2 : static NTSTATUS cmd_lsa_lookup_names(struct rpc_pipe_client *cli,
     241             :                                      TALLOC_CTX *mem_ctx,
     242             :                                      int argc,
     243             :                                      const char **argv)
     244             : {
     245             :         struct policy_handle pol;
     246             :         NTSTATUS status, result;
     247             :         struct dom_sid *sids;
     248             :         enum lsa_SidType *types;
     249             :         int i;
     250           2 :         struct dcerpc_binding_handle *b = cli->binding_handle;
     251             : 
     252           2 :         if (argc == 1) {
     253           0 :                 printf("Usage: %s [name1 [name2 [...]]]\n", argv[0]);
     254           0 :                 return NT_STATUS_OK;
     255             :         }
     256             : 
     257           2 :         status = rpccli_lsa_open_policy(cli, mem_ctx, True,
     258             :                                         LSA_POLICY_LOOKUP_NAMES,
     259             :                                         &pol);
     260             : 
     261           2 :         if (!NT_STATUS_IS_OK(status))
     262           0 :                 goto done;
     263             : 
     264           2 :         status = rpccli_lsa_lookup_names(cli, mem_ctx, &pol, argc - 1,
     265             :                                       (const char**)(argv + 1), NULL, 1, &sids, &types);
     266             : 
     267           2 :         if (!NT_STATUS_IS_OK(status) && NT_STATUS_V(status) !=
     268           0 :             NT_STATUS_V(STATUS_SOME_UNMAPPED))
     269           0 :                 goto done;
     270             : 
     271           2 :         status = NT_STATUS_OK;
     272             : 
     273             :         /* Print results */
     274             : 
     275           4 :         for (i = 0; i < (argc - 1); i++) {
     276             :                 struct dom_sid_buf sid_str;
     277           6 :                 printf("%s %s (%s: %d)\n",
     278           2 :                        argv[i + 1],
     279           2 :                        dom_sid_str_buf(&sids[i], &sid_str),
     280           2 :                        sid_type_lookup(types[i]),
     281           2 :                        types[i]);
     282             :         }
     283             : 
     284           2 :         dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
     285             : 
     286           2 :  done:
     287           2 :         return status;
     288             : }
     289             : 
     290             : /* Resolve a list of names to a list of sids */
     291             : 
     292         102 : static NTSTATUS cmd_lsa_lookup_names_level(struct rpc_pipe_client *cli,
     293             :                                            TALLOC_CTX *mem_ctx,
     294             :                                            int argc,
     295             :                                            const char **argv)
     296             : {
     297             :         struct policy_handle pol;
     298             :         NTSTATUS status, result;
     299         102 :         struct dom_sid *sids = NULL;
     300         102 :         enum lsa_SidType *types = NULL;
     301             :         int i, level;
     302         102 :         struct dcerpc_binding_handle *b = cli->binding_handle;
     303             : 
     304         102 :         if (argc < 3) {
     305           0 :                 printf("Usage: %s [level] [name1 [name2 [...]]]\n", argv[0]);
     306           0 :                 return NT_STATUS_OK;
     307             :         }
     308             : 
     309         102 :         status = rpccli_lsa_open_policy(cli, mem_ctx, True,
     310             :                                         LSA_POLICY_LOOKUP_NAMES,
     311             :                                         &pol);
     312         102 :         if (!NT_STATUS_IS_OK(status)) {
     313           0 :                 goto done;
     314             :         }
     315             : 
     316         102 :         level = atoi(argv[1]);
     317             : 
     318         102 :         status = rpccli_lsa_lookup_names(cli, mem_ctx, &pol, argc - 2,
     319             :                                       (const char**)(argv + 2), NULL, level, &sids, &types);
     320             : 
     321         102 :         if (!NT_STATUS_IS_OK(status) && NT_STATUS_V(status) !=
     322          22 :             NT_STATUS_V(STATUS_SOME_UNMAPPED))
     323             :         {
     324          22 :                 goto done;
     325             :         }
     326             : 
     327          80 :         status = NT_STATUS_OK;
     328             : 
     329             :         /* Print results */
     330             : 
     331         160 :         for (i = 0; i < (argc - 2); i++) {
     332             :                 struct dom_sid_buf sid_str;
     333         240 :                 printf("%s %s (%s: %d)\n",
     334          80 :                        argv[i + 2],
     335          80 :                        dom_sid_str_buf(&sids[i], &sid_str),
     336          80 :                        sid_type_lookup(types[i]),
     337          80 :                        types[i]);
     338             :         }
     339             : 
     340          80 :         dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
     341             : 
     342         102 :  done:
     343         102 :         return status;
     344             : }
     345             : 
     346           0 : static NTSTATUS cmd_lsa_lookup_names4(struct rpc_pipe_client *cli,
     347             :                                       TALLOC_CTX *mem_ctx, int argc,
     348             :                                       const char **argv)
     349             : {
     350             :         NTSTATUS status, result;
     351             : 
     352             :         uint32_t num_names;
     353             :         struct lsa_String *names;
     354           0 :         struct lsa_RefDomainList *domains = NULL;
     355             :         struct lsa_TransSidArray3 sids;
     356           0 :         uint32_t count = 0;
     357             :         int i;
     358           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
     359             : 
     360           0 :         if (argc == 1) {
     361           0 :                 printf("Usage: %s [name1 [name2 [...]]]\n", argv[0]);
     362           0 :                 return NT_STATUS_OK;
     363             :         }
     364             : 
     365           0 :         ZERO_STRUCT(sids);
     366             : 
     367           0 :         num_names = argc-1;
     368           0 :         names = talloc_array(mem_ctx, struct lsa_String, num_names);
     369           0 :         NT_STATUS_HAVE_NO_MEMORY(names);
     370             : 
     371           0 :         for (i=0; i < num_names; i++) {
     372           0 :                 init_lsa_String(&names[i], argv[i+1]);
     373             :         }
     374             : 
     375           0 :         status = dcerpc_lsa_LookupNames4(b, mem_ctx,
     376             :                                          num_names,
     377             :                                          names,
     378             :                                          &domains,
     379             :                                          &sids,
     380             :                                          1,
     381             :                                          &count,
     382             :                                          0,
     383             :                                          0,
     384             :                                          &result);
     385           0 :         if (!NT_STATUS_IS_OK(status)) {
     386           0 :                 return status;
     387             :         }
     388           0 :         if (!NT_STATUS_IS_OK(result)) {
     389           0 :                 return result;
     390             :         }
     391             : 
     392           0 :         if (sids.count != num_names) {
     393           0 :                 return NT_STATUS_INVALID_NETWORK_RESPONSE;
     394             :         }
     395             : 
     396           0 :         for (i = 0; i < sids.count; i++) {
     397             :                 struct dom_sid_buf sid_str;
     398           0 :                 printf("%s %s (%s: %d)\n",
     399           0 :                        argv[i+1],
     400           0 :                        dom_sid_str_buf(sids.sids[i].sid, &sid_str),
     401           0 :                        sid_type_lookup(sids.sids[i].sid_type),
     402           0 :                        sids.sids[i].sid_type);
     403             :         }
     404             : 
     405           0 :         return status;
     406             : }
     407             : 
     408             : /* Resolve a list of SIDs to a list of names */
     409             : 
     410           2 : static NTSTATUS cmd_lsa_lookup_sids(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
     411             :                                     int argc, const char **argv)
     412             : {
     413             :         struct policy_handle pol;
     414             :         NTSTATUS status, result;
     415             :         struct dom_sid *sids;
     416             :         char **domains;
     417             :         char **names;
     418             :         enum lsa_SidType *types;
     419             :         int i;
     420           2 :         struct dcerpc_binding_handle *b = cli->binding_handle;
     421             : 
     422           2 :         if (argc == 1) {
     423           0 :                 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv[0]);
     424           0 :                 return NT_STATUS_OK;
     425             :         }
     426             : 
     427           2 :         status = rpccli_lsa_open_policy(cli, mem_ctx, True,
     428             :                                         LSA_POLICY_LOOKUP_NAMES,
     429             :                                         &pol);
     430             : 
     431           2 :         if (!NT_STATUS_IS_OK(status))
     432           0 :                 goto done;
     433             : 
     434             :         /* Convert arguments to sids */
     435             : 
     436           2 :         sids = talloc_array(mem_ctx, struct dom_sid, argc - 1);
     437             : 
     438           2 :         if (!sids) {
     439           0 :                 printf("could not allocate memory for %d sids\n", argc - 1);
     440           0 :                 goto done;
     441             :         }
     442             : 
     443           4 :         for (i = 0; i < argc - 1; i++)
     444           2 :                 if (!string_to_sid(&sids[i], argv[i + 1])) {
     445           0 :                         status = NT_STATUS_INVALID_SID;
     446           0 :                         goto done;
     447             :                 }
     448             : 
     449             :         /* Lookup the SIDs */
     450             : 
     451           2 :         status = rpccli_lsa_lookup_sids(cli, mem_ctx, &pol, argc - 1, sids,
     452             :                                      &domains, &names, &types);
     453             : 
     454           2 :         if (!NT_STATUS_IS_OK(status) && NT_STATUS_V(status) !=
     455           0 :             NT_STATUS_V(STATUS_SOME_UNMAPPED))
     456           0 :                 goto done;
     457             : 
     458           2 :         status = NT_STATUS_OK;
     459             : 
     460             :         /* Print results */
     461             : 
     462           4 :         for (i = 0; i < (argc - 1); i++) {
     463             :                 struct dom_sid_buf sid_str;
     464             : 
     465           2 :                 dom_sid_str_buf(&sids[i], &sid_str);
     466           2 :                 if (types[i] == SID_NAME_DOMAIN) {
     467           0 :                         printf("%s %s (%d)\n", sid_str.buf,
     468           0 :                                domains[i] ? domains[i] : "*unknown*",
     469           0 :                                types[i]);
     470             :                 } else {
     471           2 :                         printf("%s %s\\%s (%d)\n", sid_str.buf,
     472           2 :                                domains[i] ? domains[i] : "*unknown*",
     473           2 :                                names[i] ? names[i] : "*unknown*",
     474           2 :                                types[i]);
     475             :                 }
     476             :         }
     477             : 
     478           2 :         dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
     479             : 
     480           2 :  done:
     481           2 :         return status;
     482             : }
     483             : 
     484           2 : static NTSTATUS cmd_lsa_lookup_sids_level(struct rpc_pipe_client *cli,
     485             :                                           TALLOC_CTX *mem_ctx, int argc,
     486             :                                           const char **argv)
     487             : {
     488             :         struct policy_handle pol;
     489             :         NTSTATUS status, result;
     490           2 :         struct dom_sid *sids = NULL;
     491           2 :         char **domains = NULL;
     492           2 :         char **names = NULL;
     493           2 :         enum lsa_SidType *types = NULL;
     494             :         int i, level;
     495           2 :         struct dcerpc_binding_handle *b = cli->binding_handle;
     496             : 
     497           2 :         if (argc < 3) {
     498           0 :                 printf("Usage: %s [level] [sid1 [sid2 [...]]]\n", argv[0]);
     499           0 :                 return NT_STATUS_OK;
     500             :         }
     501             : 
     502           2 :         status = rpccli_lsa_open_policy(cli, mem_ctx, True,
     503             :                                         LSA_POLICY_LOOKUP_NAMES,
     504             :                                         &pol);
     505           2 :         if (!NT_STATUS_IS_OK(status)) {
     506           0 :                 goto done;
     507             :         }
     508             : 
     509           2 :         level = atoi(argv[1]);
     510             : 
     511             :         /* Convert arguments to sids */
     512             : 
     513           2 :         sids = talloc_array(mem_ctx, struct dom_sid, argc - 2);
     514           2 :         if (sids == NULL) {
     515           0 :                 printf("could not allocate memory for %d sids\n", argc - 2);
     516           0 :                 goto done;
     517             :         }
     518             : 
     519           4 :         for (i = 0; i < argc - 2; i++) {
     520           2 :                 if (!string_to_sid(&sids[i], argv[i + 2])) {
     521           0 :                         status = NT_STATUS_INVALID_SID;
     522           0 :                         goto done;
     523             :                 }
     524             :         }
     525             : 
     526             :         /* Lookup the SIDs */
     527             : 
     528           2 :         status = dcerpc_lsa_lookup_sids_generic(cli->binding_handle,
     529             :                                                 mem_ctx,
     530             :                                                 &pol,
     531             :                                                 argc - 2,
     532             :                                                 sids,
     533             :                                                 level,
     534             :                                                 &domains,
     535             :                                                 &names,
     536             :                                                 &types,
     537             :                                                 false,
     538             :                                                 &result);
     539           2 :         if (!NT_STATUS_IS_OK(status)) {
     540           0 :                 goto done;
     541             :         }
     542           2 :         status = result;
     543             : 
     544           2 :         if (!NT_STATUS_IS_OK(status) && NT_STATUS_V(status) !=
     545           0 :             NT_STATUS_V(STATUS_SOME_UNMAPPED))
     546             :         {
     547           0 :                 goto done;
     548             :         }
     549             : 
     550           2 :         status = NT_STATUS_OK;
     551             : 
     552             :         /* Print results */
     553             : 
     554           4 :         for (i = 0; i < (argc - 2); i++) {
     555             :                 struct dom_sid_buf sid_str;
     556             : 
     557           2 :                 dom_sid_str_buf(&sids[i], &sid_str);
     558           2 :                 if (types[i] == SID_NAME_DOMAIN) {
     559           0 :                         printf("%s %s (%d)\n", sid_str.buf,
     560           0 :                                domains[i] ? domains[i] : "*unknown*",
     561           0 :                                types[i]);
     562             :                 } else {
     563           2 :                         printf("%s %s\\%s (%d)\n", sid_str.buf,
     564           2 :                                domains[i] ? domains[i] : "*unknown*",
     565           2 :                                names[i] ? names[i] : "*unknown*",
     566           2 :                                types[i]);
     567             :                 }
     568             :         }
     569             : 
     570           2 :         dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
     571             : 
     572           2 :  done:
     573           2 :         return status;
     574             : }
     575             : 
     576             : /* Resolve a list of SIDs to a list of names */
     577             : 
     578           2 : static NTSTATUS cmd_lsa_lookup_sids3(struct rpc_pipe_client *cli,
     579             :                                      TALLOC_CTX *mem_ctx,
     580             :                                      int argc, const char **argv)
     581             : {
     582           2 :         NTSTATUS status = NT_STATUS_UNSUCCESSFUL, result;
     583             :         int i;
     584             :         struct lsa_SidArray sids;
     585           2 :         struct lsa_RefDomainList *domains = NULL;
     586             :         struct lsa_TransNameArray2 names;
     587           2 :         uint32_t count = 0;
     588           2 :         struct dcerpc_binding_handle *b = cli->binding_handle;
     589             : 
     590           2 :         if (argc == 1) {
     591           0 :                 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv[0]);
     592           0 :                 return NT_STATUS_OK;
     593             :         }
     594             : 
     595           2 :         ZERO_STRUCT(names);
     596             : 
     597             :         /* Convert arguments to sids */
     598             : 
     599           2 :         sids.num_sids = argc-1;
     600           2 :         sids.sids = talloc_array(mem_ctx, struct lsa_SidPtr, sids.num_sids);
     601           2 :         if (!sids.sids) {
     602           0 :                 printf("could not allocate memory for %d sids\n", sids.num_sids);
     603           0 :                 goto done;
     604             :         }
     605             : 
     606           4 :         for (i = 0; i < sids.num_sids; i++) {
     607           2 :                 sids.sids[i].sid = talloc(sids.sids, struct dom_sid);
     608           2 :                 if (sids.sids[i].sid == NULL) {
     609           0 :                         status = NT_STATUS_NO_MEMORY;
     610           0 :                         goto done;
     611             :                 }
     612           2 :                 if (!string_to_sid(sids.sids[i].sid, argv[i+1])) {
     613           0 :                         status = NT_STATUS_INVALID_SID;
     614           0 :                         goto done;
     615             :                 }
     616             :         }
     617             : 
     618             :         /* Lookup the SIDs */
     619           2 :         status = dcerpc_lsa_LookupSids3(b, mem_ctx,
     620             :                                         &sids,
     621             :                                         &domains,
     622             :                                         &names,
     623             :                                         1,
     624             :                                         &count,
     625             :                                         0,
     626             :                                         0,
     627             :                                         &result);
     628           2 :         if (!NT_STATUS_IS_OK(status)) {
     629           0 :                 goto done;
     630             :         }
     631           2 :         if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) !=
     632           0 :             NT_STATUS_V(STATUS_SOME_UNMAPPED)) {
     633           0 :                 status = result;
     634           0 :                 goto done;
     635             :         }
     636             : 
     637           2 :         status = NT_STATUS_OK;
     638             : 
     639             :         /* Print results */
     640             : 
     641           4 :         for (i = 0; i < names.count; i++) {
     642             :                 struct dom_sid_buf sid_str;
     643             : 
     644           2 :                 if (i >= sids.num_sids) {
     645           0 :                         break;
     646             :                 }
     647           2 :                 printf("%s %s (%d)\n",
     648           2 :                        dom_sid_str_buf(sids.sids[i].sid, &sid_str),
     649           2 :                        names.names[i].name.string,
     650           2 :                        names.names[i].sid_type);
     651             :         }
     652             : 
     653           2 :  done:
     654           2 :         return status;
     655             : }
     656             : 
     657             : 
     658             : /* Enumerate list of trusted domains */
     659             : 
     660           0 : static NTSTATUS cmd_lsa_enum_trust_dom(struct rpc_pipe_client *cli,
     661             :                                        TALLOC_CTX *mem_ctx,
     662             :                                        int argc,
     663             :                                        const char **argv)
     664             : {
     665             :         struct policy_handle pol;
     666             :         NTSTATUS status, result;
     667             :         struct lsa_DomainList domain_list;
     668           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
     669             : 
     670             :         /* defaults, but may be changed using params */
     671           0 :         uint32_t enum_ctx = 0;
     672             :         int i;
     673           0 :         uint32_t max_size = (uint32_t)-1;
     674             : 
     675           0 :         if (argc > 2) {
     676           0 :                 printf("Usage: %s [enum context (0)]\n", argv[0]);
     677           0 :                 return NT_STATUS_OK;
     678             :         }
     679             : 
     680           0 :         if (argc == 2 && argv[1]) {
     681           0 :                 enum_ctx = atoi(argv[2]);
     682             :         }
     683             : 
     684           0 :         status = rpccli_lsa_open_policy(cli, mem_ctx, True,
     685             :                                      LSA_POLICY_VIEW_LOCAL_INFORMATION,
     686             :                                      &pol);
     687             : 
     688           0 :         if (!NT_STATUS_IS_OK(status))
     689           0 :                 goto done;
     690             : 
     691           0 :         status = STATUS_MORE_ENTRIES;
     692             : 
     693           0 :         while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
     694             : 
     695             :                 /* Lookup list of trusted domains */
     696             : 
     697           0 :                 status = dcerpc_lsa_EnumTrustDom(b, mem_ctx,
     698             :                                                  &pol,
     699             :                                                  &enum_ctx,
     700             :                                                  &domain_list,
     701             :                                                  max_size,
     702             :                                                  &result);
     703           0 :                 if (!NT_STATUS_IS_OK(status)) {
     704           0 :                         goto done;
     705             :                 }
     706           0 :                 if (!NT_STATUS_IS_OK(result) &&
     707           0 :                     !NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) &&
     708           0 :                     !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)) {
     709           0 :                         status = result;
     710           0 :                         goto done;
     711             :                 }
     712             : 
     713             :                 /* Print results: list of names and sids returned in this
     714             :                  * response. */
     715           0 :                 for (i = 0; i < domain_list.count; i++) {
     716             :                         struct dom_sid_buf sid_str;
     717             : 
     718           0 :                         printf("%s %s\n",
     719           0 :                                 domain_list.domains[i].name.string ?
     720           0 :                                 domain_list.domains[i].name.string : "*unknown*",
     721           0 :                                 dom_sid_str_buf(domain_list.domains[i].sid,
     722             :                                                 &sid_str));
     723             :                 }
     724             :         }
     725             : 
     726           0 :         dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
     727           0 :  done:
     728           0 :         return status;
     729             : }
     730             : 
     731             : /* Enumerates privileges */
     732             : 
     733           0 : static NTSTATUS cmd_lsa_enum_privilege(struct rpc_pipe_client *cli,
     734             :                                        TALLOC_CTX *mem_ctx,
     735             :                                        int argc,
     736             :                                        const char **argv)
     737             : {
     738             :         struct policy_handle pol;
     739             :         NTSTATUS status, result;
     740             :         struct lsa_PrivArray priv_array;
     741           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
     742             : 
     743           0 :         uint32_t enum_context=0;
     744           0 :         uint32_t pref_max_length=0x1000;
     745             :         int i;
     746             : 
     747           0 :         if (argc > 3) {
     748           0 :                 printf("Usage: %s [enum context] [max length]\n", argv[0]);
     749           0 :                 return NT_STATUS_OK;
     750             :         }
     751             : 
     752           0 :         if (argc>=2)
     753           0 :                 enum_context=atoi(argv[1]);
     754             : 
     755           0 :         if (argc==3)
     756           0 :                 pref_max_length=atoi(argv[2]);
     757             : 
     758           0 :         status = rpccli_lsa_open_policy(cli, mem_ctx, True,
     759             :                                      SEC_FLAG_MAXIMUM_ALLOWED,
     760             :                                      &pol);
     761             : 
     762           0 :         if (!NT_STATUS_IS_OK(status))
     763           0 :                 goto done;
     764             : 
     765           0 :         status = dcerpc_lsa_EnumPrivs(b, mem_ctx,
     766             :                                       &pol,
     767             :                                       &enum_context,
     768             :                                       &priv_array,
     769             :                                       pref_max_length,
     770             :                                       &result);
     771           0 :         if (!NT_STATUS_IS_OK(status))
     772           0 :                 goto done;
     773           0 :         if (!NT_STATUS_IS_OK(result)) {
     774           0 :                 status = result;
     775           0 :                 goto done;
     776             :         }
     777             : 
     778             :         /* Print results */
     779           0 :         printf("found %d privileges\n\n", priv_array.count);
     780             : 
     781           0 :         for (i = 0; i < priv_array.count; i++) {
     782           0 :                 printf("%s \t\t%d:%d (0x%x:0x%x)\n",
     783           0 :                        priv_array.privs[i].name.string ? priv_array.privs[i].name.string : "*unknown*",
     784           0 :                        priv_array.privs[i].luid.high,
     785           0 :                        priv_array.privs[i].luid.low,
     786           0 :                        priv_array.privs[i].luid.high,
     787           0 :                        priv_array.privs[i].luid.low);
     788             :         }
     789             : 
     790           0 :         dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
     791           0 :  done:
     792           0 :         return status;
     793             : }
     794             : 
     795             : /* Get privilege name */
     796             : 
     797           0 : static NTSTATUS cmd_lsa_get_dispname(struct rpc_pipe_client *cli,
     798             :                                      TALLOC_CTX *mem_ctx,
     799             :                                      int argc,
     800             :                                      const char **argv)
     801             : {
     802             :         struct policy_handle pol;
     803             :         NTSTATUS status, result;
     804           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
     805             : 
     806           0 :         uint16_t lang_id=0;
     807           0 :         uint16_t lang_id_sys=0;
     808             :         uint16_t lang_id_desc;
     809             :         struct lsa_String lsa_name;
     810           0 :         struct lsa_StringLarge *description = NULL;
     811             : 
     812           0 :         if (argc != 2) {
     813           0 :                 printf("Usage: %s privilege name\n", argv[0]);
     814           0 :                 return NT_STATUS_OK;
     815             :         }
     816             : 
     817           0 :         status = rpccli_lsa_open_policy(cli, mem_ctx, True,
     818             :                                      SEC_FLAG_MAXIMUM_ALLOWED,
     819             :                                      &pol);
     820             : 
     821           0 :         if (!NT_STATUS_IS_OK(status))
     822           0 :                 goto done;
     823             : 
     824           0 :         init_lsa_String(&lsa_name, argv[1]);
     825             : 
     826           0 :         status = dcerpc_lsa_LookupPrivDisplayName(b, mem_ctx,
     827             :                                                   &pol,
     828             :                                                   &lsa_name,
     829             :                                                   lang_id,
     830             :                                                   lang_id_sys,
     831             :                                                   &description,
     832             :                                                   &lang_id_desc,
     833             :                                                   &result);
     834           0 :         if (!NT_STATUS_IS_OK(status))
     835           0 :                 goto done;
     836           0 :         if (!NT_STATUS_IS_OK(result)) {
     837           0 :                 status = result;
     838           0 :                 goto done;
     839             :         }
     840             : 
     841             :         /* Print results */
     842           0 :         printf("%s -> %s (language: 0x%x)\n", argv[1], description->string, lang_id_desc);
     843             : 
     844           0 :         dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
     845           0 :  done:
     846           0 :         return status;
     847             : }
     848             : 
     849             : /* Enumerate the LSA SIDS */
     850             : 
     851           0 : static NTSTATUS cmd_lsa_enum_sids(struct rpc_pipe_client *cli,
     852             :                                   TALLOC_CTX *mem_ctx,
     853             :                                   int argc,
     854             :                                   const char **argv)
     855             : {
     856             :         struct policy_handle pol;
     857             :         NTSTATUS status, result;
     858           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
     859             : 
     860           0 :         uint32_t enum_context=0;
     861           0 :         uint32_t pref_max_length=0x1000;
     862             :         struct lsa_SidArray sid_array;
     863             :         int i;
     864             : 
     865           0 :         if (argc > 3) {
     866           0 :                 printf("Usage: %s [enum context] [max length]\n", argv[0]);
     867           0 :                 return NT_STATUS_OK;
     868             :         }
     869             : 
     870           0 :         if (argc>=2)
     871           0 :                 enum_context=atoi(argv[1]);
     872             : 
     873           0 :         if (argc==3)
     874           0 :                 pref_max_length=atoi(argv[2]);
     875             : 
     876           0 :         status = rpccli_lsa_open_policy(cli, mem_ctx, True,
     877             :                                      SEC_FLAG_MAXIMUM_ALLOWED,
     878             :                                      &pol);
     879             : 
     880           0 :         if (!NT_STATUS_IS_OK(status))
     881           0 :                 goto done;
     882             : 
     883           0 :         status = dcerpc_lsa_EnumAccounts(b, mem_ctx,
     884             :                                          &pol,
     885             :                                          &enum_context,
     886             :                                          &sid_array,
     887             :                                          pref_max_length,
     888             :                                          &result);
     889           0 :         if (!NT_STATUS_IS_OK(status))
     890           0 :                 goto done;
     891           0 :         if (!NT_STATUS_IS_OK(result)) {
     892           0 :                 status = result;
     893           0 :                 goto done;
     894             :         }
     895             : 
     896             :         /* Print results */
     897           0 :         printf("found %d SIDs\n\n", sid_array.num_sids);
     898             : 
     899           0 :         for (i = 0; i < sid_array.num_sids; i++) {
     900             :                 struct dom_sid_buf sid_str;
     901             : 
     902           0 :                 printf("%s\n",
     903           0 :                        dom_sid_str_buf(sid_array.sids[i].sid, &sid_str));
     904             :         }
     905             : 
     906           0 :         dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
     907           0 :  done:
     908           0 :         return status;
     909             : }
     910             : 
     911             : /* Create a new account */
     912             : 
     913           0 : static NTSTATUS cmd_lsa_create_account(struct rpc_pipe_client *cli,
     914             :                                        TALLOC_CTX *mem_ctx,
     915             :                                        int argc,
     916             :                                        const char **argv)
     917             : {
     918             :         struct policy_handle dom_pol;
     919             :         struct policy_handle user_pol;
     920             :         NTSTATUS status, result;
     921           0 :         uint32_t des_access = 0x000f000f;
     922           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
     923           0 :         union lsa_revision_info out_revision_info = {
     924             :                 .info1 = {
     925             :                         .revision = 0,
     926             :                 },
     927             :         };
     928           0 :         uint32_t out_version = 0;
     929             : 
     930             :         struct dom_sid sid;
     931             : 
     932           0 :         if (argc != 2 ) {
     933           0 :                 printf("Usage: %s SID\n", argv[0]);
     934           0 :                 return NT_STATUS_OK;
     935             :         }
     936             : 
     937           0 :         status = name_to_sid(cli, mem_ctx, &sid, argv[1]);
     938           0 :         if (!NT_STATUS_IS_OK(status))
     939           0 :                 goto done;
     940             : 
     941           0 :         status = dcerpc_lsa_open_policy_fallback(b,
     942             :                                                  mem_ctx,
     943           0 :                                                  cli->srv_name_slash,
     944             :                                                  true,
     945             :                                                  SEC_FLAG_MAXIMUM_ALLOWED,
     946             :                                                  &out_version,
     947             :                                                  &out_revision_info,
     948             :                                                  &dom_pol,
     949             :                                                  &result);
     950           0 :         if (any_nt_status_not_ok(status, result, &status)) {
     951           0 :                 goto done;
     952             :         }
     953             : 
     954           0 :         status = dcerpc_lsa_CreateAccount(b, mem_ctx,
     955             :                                           &dom_pol,
     956             :                                           &sid,
     957             :                                           des_access,
     958             :                                           &user_pol,
     959             :                                           &result);
     960           0 :         if (!NT_STATUS_IS_OK(status))
     961           0 :                 goto done;
     962           0 :         if (!NT_STATUS_IS_OK(result)) {
     963           0 :                 status = result;
     964           0 :                 goto done;
     965             :         }
     966             : 
     967           0 :         printf("Account for SID %s successfully created\n\n", argv[1]);
     968           0 :         status = NT_STATUS_OK;
     969             : 
     970           0 :         dcerpc_lsa_Close(b, mem_ctx, &dom_pol, &result);
     971           0 :  done:
     972           0 :         return status;
     973             : }
     974             : 
     975             : 
     976             : /* Enumerate the privileges of an SID */
     977             : 
     978           0 : static NTSTATUS cmd_lsa_enum_privsaccounts(struct rpc_pipe_client *cli,
     979             :                                            TALLOC_CTX *mem_ctx,
     980             :                                            int argc,
     981             :                                            const char **argv)
     982             : {
     983             :         struct policy_handle dom_pol;
     984             :         struct policy_handle user_pol;
     985             :         NTSTATUS status, result;
     986           0 :         uint32_t access_desired = 0x000f000f;
     987             :         struct dom_sid sid;
     988           0 :         struct lsa_PrivilegeSet *privs = NULL;
     989             :         int i;
     990           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
     991           0 :         union lsa_revision_info out_revision_info = {
     992             :                 .info1 = {
     993             :                         .revision = 0,
     994             :                 },
     995             :         };
     996           0 :         uint32_t out_version = 0;
     997             : 
     998           0 :         if (argc != 2 ) {
     999           0 :                 printf("Usage: %s SID\n", argv[0]);
    1000           0 :                 return NT_STATUS_OK;
    1001             :         }
    1002             : 
    1003           0 :         status = name_to_sid(cli, mem_ctx, &sid, argv[1]);
    1004           0 :         if (!NT_STATUS_IS_OK(status))
    1005           0 :                 goto done;
    1006             : 
    1007           0 :         status = dcerpc_lsa_open_policy_fallback(b,
    1008             :                                                  mem_ctx,
    1009           0 :                                                  cli->srv_name_slash,
    1010             :                                                  true,
    1011             :                                                  SEC_FLAG_MAXIMUM_ALLOWED,
    1012             :                                                  &out_version,
    1013             :                                                  &out_revision_info,
    1014             :                                                  &dom_pol,
    1015             :                                                  &result);
    1016           0 :         if (any_nt_status_not_ok(status, result, &status)) {
    1017           0 :                 goto done;
    1018             :         }
    1019             : 
    1020           0 :         status = dcerpc_lsa_OpenAccount(b, mem_ctx,
    1021             :                                         &dom_pol,
    1022             :                                         &sid,
    1023             :                                         access_desired,
    1024             :                                         &user_pol,
    1025             :                                         &result);
    1026           0 :         if (!NT_STATUS_IS_OK(status))
    1027           0 :                 goto done;
    1028           0 :         if (!NT_STATUS_IS_OK(result)) {
    1029           0 :                 status = result;
    1030           0 :                 goto done;
    1031             :         }
    1032             : 
    1033           0 :         status = dcerpc_lsa_EnumPrivsAccount(b, mem_ctx,
    1034             :                                              &user_pol,
    1035             :                                              &privs,
    1036             :                                              &result);
    1037           0 :         if (!NT_STATUS_IS_OK(status))
    1038           0 :                 goto done;
    1039           0 :         if (!NT_STATUS_IS_OK(result)) {
    1040           0 :                 status = result;
    1041           0 :                 goto done;
    1042             :         }
    1043             : 
    1044             :         /* Print results */
    1045           0 :         printf("found %d privileges for SID %s\n\n", privs->count, argv[1]);
    1046           0 :         printf("high\tlow\tattribute\n");
    1047             : 
    1048           0 :         for (i = 0; i < privs->count; i++) {
    1049           0 :                 printf("%u\t%u\t%u\n",
    1050           0 :                         privs->set[i].luid.high,
    1051           0 :                         privs->set[i].luid.low,
    1052           0 :                         privs->set[i].attribute);
    1053             :         }
    1054             : 
    1055           0 :         dcerpc_lsa_Close(b, mem_ctx, &dom_pol, &result);
    1056           0 :  done:
    1057           0 :         return status;
    1058             : }
    1059             : 
    1060             : 
    1061             : /* Enumerate the privileges of an SID via LsaEnumerateAccountRights */
    1062             : 
    1063           0 : static NTSTATUS cmd_lsa_enum_acct_rights(struct rpc_pipe_client *cli,
    1064             :                                          TALLOC_CTX *mem_ctx,
    1065             :                                          int argc,
    1066             :                                          const char **argv)
    1067             : {
    1068             :         struct policy_handle dom_pol;
    1069             :         NTSTATUS status, result;
    1070             :         struct dom_sid sid;
    1071             :         struct dom_sid_buf buf;
    1072             :         struct lsa_RightSet rights;
    1073           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
    1074           0 :         union lsa_revision_info out_revision_info = {
    1075             :                 .info1 = {
    1076             :                         .revision = 0,
    1077             :                 },
    1078             :         };
    1079           0 :         uint32_t out_version = 0;
    1080             : 
    1081             :         int i;
    1082             : 
    1083           0 :         if (argc != 2 ) {
    1084           0 :                 printf("Usage: %s SID\n", argv[0]);
    1085           0 :                 return NT_STATUS_OK;
    1086             :         }
    1087             : 
    1088           0 :         status = name_to_sid(cli, mem_ctx, &sid, argv[1]);
    1089           0 :         if (!NT_STATUS_IS_OK(status))
    1090           0 :                 goto done;
    1091             : 
    1092           0 :         status = dcerpc_lsa_open_policy_fallback(b,
    1093             :                                                  mem_ctx,
    1094           0 :                                                  cli->srv_name_slash,
    1095             :                                                  true,
    1096             :                                                  SEC_FLAG_MAXIMUM_ALLOWED,
    1097             :                                                  &out_version,
    1098             :                                                  &out_revision_info,
    1099             :                                                  &dom_pol,
    1100             :                                                  &result);
    1101           0 :         if (any_nt_status_not_ok(status, result, &status)) {
    1102           0 :                 goto done;
    1103             :         }
    1104             : 
    1105           0 :         status = dcerpc_lsa_EnumAccountRights(b, mem_ctx,
    1106             :                                               &dom_pol,
    1107             :                                               &sid,
    1108             :                                               &rights,
    1109             :                                               &result);
    1110           0 :         if (!NT_STATUS_IS_OK(status))
    1111           0 :                 goto done;
    1112           0 :         if (!NT_STATUS_IS_OK(result)) {
    1113           0 :                 status = result;
    1114           0 :                 goto done;
    1115             :         }
    1116             : 
    1117           0 :         printf("found %d privileges for SID %s\n", rights.count,
    1118             :                dom_sid_str_buf(&sid, &buf));
    1119             : 
    1120           0 :         for (i = 0; i < rights.count; i++) {
    1121           0 :                 printf("\t%s\n", rights.names[i].string);
    1122             :         }
    1123             : 
    1124           0 :         dcerpc_lsa_Close(b, mem_ctx, &dom_pol, &result);
    1125           0 :  done:
    1126           0 :         return status;
    1127             : }
    1128             : 
    1129             : 
    1130             : /* add some privileges to a SID via LsaAddAccountRights */
    1131             : 
    1132           0 : static NTSTATUS cmd_lsa_add_acct_rights(struct rpc_pipe_client *cli,
    1133             :                                         TALLOC_CTX *mem_ctx,
    1134             :                                         int argc,
    1135             :                                         const char **argv)
    1136             : {
    1137             :         struct policy_handle dom_pol;
    1138             :         NTSTATUS status, result;
    1139             :         struct lsa_RightSet rights;
    1140             :         struct dom_sid sid;
    1141             :         int i;
    1142           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
    1143           0 :         union lsa_revision_info out_revision_info = {
    1144             :                 .info1 = {
    1145             :                         .revision = 0,
    1146             :                 },
    1147             :         };
    1148           0 :         uint32_t out_version = 0;
    1149             : 
    1150           0 :         if (argc < 3 ) {
    1151           0 :                 printf("Usage: %s SID [rights...]\n", argv[0]);
    1152           0 :                 return NT_STATUS_OK;
    1153             :         }
    1154             : 
    1155           0 :         status = name_to_sid(cli, mem_ctx, &sid, argv[1]);
    1156           0 :         if (!NT_STATUS_IS_OK(status))
    1157           0 :                 goto done;
    1158             : 
    1159           0 :         status = dcerpc_lsa_open_policy_fallback(b,
    1160             :                                                  mem_ctx,
    1161           0 :                                                  cli->srv_name_slash,
    1162             :                                                  true,
    1163             :                                                  SEC_FLAG_MAXIMUM_ALLOWED,
    1164             :                                                  &out_version,
    1165             :                                                  &out_revision_info,
    1166             :                                                  &dom_pol,
    1167             :                                                  &result);
    1168           0 :         if (any_nt_status_not_ok(status, result, &status)) {
    1169           0 :                 goto done;
    1170             :         }
    1171             : 
    1172           0 :         rights.count = argc-2;
    1173           0 :         rights.names = talloc_array(mem_ctx, struct lsa_StringLarge,
    1174             :                                     rights.count);
    1175           0 :         if (!rights.names) {
    1176           0 :                 return NT_STATUS_NO_MEMORY;
    1177             :         }
    1178             : 
    1179           0 :         for (i=0; i<argc-2; i++) {
    1180           0 :                 init_lsa_StringLarge(&rights.names[i], argv[i+2]);
    1181             :         }
    1182             : 
    1183           0 :         status = dcerpc_lsa_AddAccountRights(b, mem_ctx,
    1184             :                                              &dom_pol,
    1185             :                                              &sid,
    1186             :                                              &rights,
    1187             :                                              &result);
    1188           0 :         if (!NT_STATUS_IS_OK(status))
    1189           0 :                 goto done;
    1190           0 :         if (!NT_STATUS_IS_OK(result)) {
    1191           0 :                 status = result;
    1192           0 :                 goto done;
    1193             :         }
    1194             : 
    1195           0 :         dcerpc_lsa_Close(b, mem_ctx, &dom_pol, &result);
    1196           0 :  done:
    1197           0 :         return status;
    1198             : }
    1199             : 
    1200             : 
    1201             : /* remove some privileges to a SID via LsaRemoveAccountRights */
    1202             : 
    1203           0 : static NTSTATUS cmd_lsa_remove_acct_rights(struct rpc_pipe_client *cli,
    1204             :                                            TALLOC_CTX *mem_ctx,
    1205             :                                            int argc,
    1206             :                                            const char **argv)
    1207             : {
    1208             :         struct policy_handle dom_pol;
    1209             :         NTSTATUS status, result;
    1210             :         struct lsa_RightSet rights;
    1211             :         struct dom_sid sid;
    1212             :         int i;
    1213           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
    1214           0 :         union lsa_revision_info out_revision_info = {
    1215             :                 .info1 = {
    1216             :                         .revision = 0,
    1217             :                 },
    1218             :         };
    1219           0 :         uint32_t out_version = 0;
    1220             : 
    1221           0 :         if (argc < 3 ) {
    1222           0 :                 printf("Usage: %s SID [rights...]\n", argv[0]);
    1223           0 :                 return NT_STATUS_OK;
    1224             :         }
    1225             : 
    1226           0 :         status = name_to_sid(cli, mem_ctx, &sid, argv[1]);
    1227           0 :         if (!NT_STATUS_IS_OK(status))
    1228           0 :                 goto done;
    1229             : 
    1230           0 :         status = dcerpc_lsa_open_policy_fallback(b,
    1231             :                                                  mem_ctx,
    1232           0 :                                                  cli->srv_name_slash,
    1233             :                                                  true,
    1234             :                                                  SEC_FLAG_MAXIMUM_ALLOWED,
    1235             :                                                  &out_version,
    1236             :                                                  &out_revision_info,
    1237             :                                                  &dom_pol,
    1238             :                                                  &result);
    1239           0 :         if (any_nt_status_not_ok(status, result, &status)) {
    1240           0 :                 goto done;
    1241             :         }
    1242             : 
    1243           0 :         rights.count = argc-2;
    1244           0 :         rights.names = talloc_array(mem_ctx, struct lsa_StringLarge,
    1245             :                                     rights.count);
    1246           0 :         if (!rights.names) {
    1247           0 :                 return NT_STATUS_NO_MEMORY;
    1248             :         }
    1249             : 
    1250           0 :         for (i=0; i<argc-2; i++) {
    1251           0 :                 init_lsa_StringLarge(&rights.names[i], argv[i+2]);
    1252             :         }
    1253             : 
    1254           0 :         status = dcerpc_lsa_RemoveAccountRights(b, mem_ctx,
    1255             :                                                 &dom_pol,
    1256             :                                                 &sid,
    1257             :                                                 false,
    1258             :                                                 &rights,
    1259             :                                                 &result);
    1260           0 :         if (!NT_STATUS_IS_OK(status))
    1261           0 :                 goto done;
    1262           0 :         if (!NT_STATUS_IS_OK(result)) {
    1263           0 :                 status = result;
    1264           0 :                 goto done;
    1265             :         }
    1266             : 
    1267           0 :         dcerpc_lsa_Close(b, mem_ctx, &dom_pol, &result);
    1268             : 
    1269           0 :  done:
    1270           0 :         return status;
    1271             : }
    1272             : 
    1273             : 
    1274             : /* Get a privilege value given its name */
    1275             : 
    1276           0 : static NTSTATUS cmd_lsa_lookup_priv_value(struct rpc_pipe_client *cli,
    1277             :                                           TALLOC_CTX *mem_ctx,
    1278             :                                           int argc,
    1279             :                                           const char **argv)
    1280             : {
    1281             :         struct policy_handle pol;
    1282             :         NTSTATUS status, result;
    1283             :         struct lsa_LUID luid;
    1284             :         struct lsa_String name;
    1285           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
    1286           0 :         union lsa_revision_info out_revision_info = {
    1287             :                 .info1 = {
    1288             :                         .revision = 0,
    1289             :                 },
    1290             :         };
    1291           0 :         uint32_t out_version = 0;
    1292             : 
    1293           0 :         if (argc != 2 ) {
    1294           0 :                 printf("Usage: %s name\n", argv[0]);
    1295           0 :                 return NT_STATUS_OK;
    1296             :         }
    1297             : 
    1298           0 :         status = dcerpc_lsa_open_policy_fallback(b,
    1299             :                                                  mem_ctx,
    1300           0 :                                                  cli->srv_name_slash,
    1301             :                                                  true,
    1302             :                                                  SEC_FLAG_MAXIMUM_ALLOWED,
    1303             :                                                  &out_version,
    1304             :                                                  &out_revision_info,
    1305             :                                                  &pol,
    1306             :                                                  &result);
    1307           0 :         if (any_nt_status_not_ok(status, result, &status)) {
    1308           0 :                 goto done;
    1309             :         }
    1310             : 
    1311           0 :         init_lsa_String(&name, argv[1]);
    1312             : 
    1313           0 :         status = dcerpc_lsa_LookupPrivValue(b, mem_ctx,
    1314             :                                             &pol,
    1315             :                                             &name,
    1316             :                                             &luid,
    1317             :                                             &result);
    1318           0 :         if (!NT_STATUS_IS_OK(status))
    1319           0 :                 goto done;
    1320           0 :         if (!NT_STATUS_IS_OK(result)) {
    1321           0 :                 status = result;
    1322           0 :                 goto done;
    1323             :         }
    1324             : 
    1325             :         /* Print results */
    1326             : 
    1327           0 :         printf("%u:%u (0x%x:0x%x)\n", luid.high, luid.low, luid.high, luid.low);
    1328             : 
    1329           0 :         dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
    1330           0 :  done:
    1331           0 :         return status;
    1332             : }
    1333             : 
    1334             : /* Query LSA security object */
    1335             : 
    1336           0 : static NTSTATUS cmd_lsa_query_secobj(struct rpc_pipe_client *cli,
    1337             :                                      TALLOC_CTX *mem_ctx,
    1338             :                                      int argc,
    1339             :                                      const char **argv)
    1340             : {
    1341             :         struct policy_handle pol;
    1342             :         NTSTATUS status, result;
    1343             :         struct sec_desc_buf *sdb;
    1344           0 :         uint32_t sec_info = SECINFO_DACL;
    1345           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
    1346           0 :         union lsa_revision_info out_revision_info = {
    1347             :                 .info1 = {
    1348             :                         .revision = 0,
    1349             :                 },
    1350             :         };
    1351           0 :         uint32_t out_version = 0;
    1352             : 
    1353           0 :         if (argc < 1 || argc > 2) {
    1354           0 :                 printf("Usage: %s [sec_info]\n", argv[0]);
    1355           0 :                 return NT_STATUS_OK;
    1356             :         }
    1357             : 
    1358           0 :         if (argc == 2)
    1359           0 :                 sscanf(argv[1], "%x", &sec_info);
    1360             : 
    1361           0 :         status = dcerpc_lsa_open_policy_fallback(b,
    1362             :                                                  mem_ctx,
    1363           0 :                                                  cli->srv_name_slash,
    1364             :                                                  true,
    1365             :                                                  SEC_FLAG_MAXIMUM_ALLOWED,
    1366             :                                                  &out_version,
    1367             :                                                  &out_revision_info,
    1368             :                                                  &pol,
    1369             :                                                  &result);
    1370           0 :         if (any_nt_status_not_ok(status, result, &status)) {
    1371           0 :                 goto done;
    1372             :         }
    1373             : 
    1374           0 :         status = dcerpc_lsa_QuerySecurity(b, mem_ctx,
    1375             :                                           &pol,
    1376             :                                           sec_info,
    1377             :                                           &sdb,
    1378             :                                           &result);
    1379           0 :         if (!NT_STATUS_IS_OK(status))
    1380           0 :                 goto done;
    1381           0 :         if (!NT_STATUS_IS_OK(result)) {
    1382           0 :                 status = result;
    1383           0 :                 goto done;
    1384             :         }
    1385             : 
    1386             :         /* Print results */
    1387             : 
    1388           0 :         display_sec_desc(sdb->sd);
    1389             : 
    1390           0 :         dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
    1391           0 :  done:
    1392           0 :         return status;
    1393             : }
    1394             : 
    1395           0 : static void display_trust_dom_info_4(struct lsa_TrustDomainInfoPassword *p,
    1396             :                                      DATA_BLOB session_key)
    1397             : {
    1398             :         char *pwd, *pwd_old;
    1399             : 
    1400           0 :         DATA_BLOB data     = data_blob_const(p->password->data, p->password->length);
    1401           0 :         DATA_BLOB data_old = data_blob_const(p->old_password->data, p->old_password->length);
    1402             : 
    1403           0 :         pwd     = sess_decrypt_string(talloc_tos(), &data, &session_key);
    1404           0 :         pwd_old = sess_decrypt_string(talloc_tos(), &data_old, &session_key);
    1405             : 
    1406           0 :         d_printf("Password:\t%s\n", pwd);
    1407           0 :         d_printf("Old Password:\t%s\n", pwd_old);
    1408             : 
    1409           0 :         talloc_free(pwd);
    1410           0 :         talloc_free(pwd_old);
    1411           0 : }
    1412             : 
    1413           0 : static void display_trust_dom_info(TALLOC_CTX *mem_ctx,
    1414             :                                    union lsa_TrustedDomainInfo *info,
    1415             :                                    enum lsa_TrustDomInfoEnum info_class,
    1416             :                                    DATA_BLOB session_key)
    1417             : {
    1418           0 :         switch (info_class) {
    1419           0 :                 case LSA_TRUSTED_DOMAIN_INFO_PASSWORD:
    1420           0 :                         display_trust_dom_info_4(&info->password, session_key);
    1421           0 :                         break;
    1422           0 :                 default: {
    1423           0 :                         const char *str = NULL;
    1424           0 :                         str = NDR_PRINT_UNION_STRING(mem_ctx,
    1425             :                                                      lsa_TrustedDomainInfo,
    1426             :                                                      info_class, info);
    1427           0 :                         if (str) {
    1428           0 :                                 d_printf("%s\n", str);
    1429             :                         }
    1430           0 :                         break;
    1431             :                 }
    1432             :         }
    1433           0 : }
    1434             : 
    1435           0 : static NTSTATUS cmd_lsa_query_trustdominfobysid(struct rpc_pipe_client *cli,
    1436             :                                                 TALLOC_CTX *mem_ctx,
    1437             :                                                 int argc,
    1438             :                                                 const char **argv)
    1439             : {
    1440             :         struct policy_handle pol;
    1441             :         NTSTATUS status, result;
    1442             :         struct dom_sid dom_sid;
    1443           0 :         uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
    1444           0 :         union lsa_TrustedDomainInfo *info = NULL;
    1445           0 :         enum lsa_TrustDomInfoEnum info_class = 1;
    1446             :         DATA_BLOB session_key;
    1447           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
    1448           0 :         union lsa_revision_info out_revision_info = {
    1449             :                 .info1 = {
    1450             :                         .revision = 0,
    1451             :                 },
    1452             :         };
    1453           0 :         uint32_t out_version = 0;
    1454             : 
    1455           0 :         if (argc > 3 || argc < 2) {
    1456           0 :                 printf("Usage: %s [sid] [info_class]\n", argv[0]);
    1457           0 :                 return NT_STATUS_OK;
    1458             :         }
    1459             : 
    1460           0 :         if (!string_to_sid(&dom_sid, argv[1]))
    1461           0 :                 return NT_STATUS_NO_MEMORY;
    1462             : 
    1463           0 :         if (argc == 3)
    1464           0 :                 info_class = atoi(argv[2]);
    1465             : 
    1466           0 :         status = dcerpc_lsa_open_policy_fallback(b,
    1467             :                                                  mem_ctx,
    1468           0 :                                                  cli->srv_name_slash,
    1469             :                                                  true,
    1470             :                                                  access_mask,
    1471             :                                                  &out_version,
    1472             :                                                  &out_revision_info,
    1473             :                                                  &pol,
    1474             :                                                  &result);
    1475           0 :         if (any_nt_status_not_ok(status, result, &status)) {
    1476           0 :                 goto done;
    1477             :         }
    1478             : 
    1479           0 :         status = dcerpc_lsa_QueryTrustedDomainInfoBySid(b, mem_ctx,
    1480             :                                                         &pol,
    1481             :                                                         &dom_sid,
    1482             :                                                         info_class,
    1483             :                                                         &info,
    1484             :                                                         &result);
    1485           0 :         if (!NT_STATUS_IS_OK(status))
    1486           0 :                 goto done;
    1487           0 :         if (!NT_STATUS_IS_OK(result)) {
    1488           0 :                 status = result;
    1489           0 :                 goto done;
    1490             :         }
    1491             : 
    1492           0 :         status = cli_get_session_key(mem_ctx, cli, &session_key);
    1493           0 :         if (!NT_STATUS_IS_OK(status)) {
    1494           0 :                 DEBUG(0, ("Could not retrieve session key: %s\n", nt_errstr(status)));
    1495           0 :                 goto done;
    1496             :         }
    1497             : 
    1498           0 :         display_trust_dom_info(mem_ctx, info, info_class, session_key);
    1499             : 
    1500           0 :  done:
    1501           0 :         dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
    1502             : 
    1503           0 :         return status;
    1504             : }
    1505             : 
    1506           0 : static NTSTATUS cmd_lsa_query_trustdominfobyname(struct rpc_pipe_client *cli,
    1507             :                                                  TALLOC_CTX *mem_ctx,
    1508             :                                                  int argc,
    1509             :                                                  const char **argv)
    1510             : {
    1511             :         struct policy_handle pol;
    1512             :         NTSTATUS status, result;
    1513           0 :         uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
    1514           0 :         union lsa_TrustedDomainInfo *info = NULL;
    1515           0 :         enum lsa_TrustDomInfoEnum info_class = 1;
    1516             :         struct lsa_String trusted_domain;
    1517           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
    1518             :         DATA_BLOB session_key;
    1519           0 :         union lsa_revision_info out_revision_info = {
    1520             :                 .info1 = {
    1521             :                         .revision = 0,
    1522             :                 },
    1523             :         };
    1524           0 :         uint32_t out_version = 0;
    1525             : 
    1526           0 :         if (argc > 3 || argc < 2) {
    1527           0 :                 printf("Usage: %s [name] [info_class]\n", argv[0]);
    1528           0 :                 return NT_STATUS_OK;
    1529             :         }
    1530             : 
    1531           0 :         if (argc == 3)
    1532           0 :                 info_class = atoi(argv[2]);
    1533             : 
    1534           0 :         status = dcerpc_lsa_open_policy_fallback(b,
    1535             :                                                  mem_ctx,
    1536           0 :                                                  cli->srv_name_slash,
    1537             :                                                  true,
    1538             :                                                  access_mask,
    1539             :                                                  &out_version,
    1540             :                                                  &out_revision_info,
    1541             :                                                  &pol,
    1542             :                                                  &result);
    1543           0 :         if (any_nt_status_not_ok(status, result, &status)) {
    1544           0 :                 goto done;
    1545             :         }
    1546             : 
    1547           0 :         init_lsa_String(&trusted_domain, argv[1]);
    1548             : 
    1549           0 :         status = dcerpc_lsa_QueryTrustedDomainInfoByName(b, mem_ctx,
    1550             :                                                          &pol,
    1551             :                                                          &trusted_domain,
    1552             :                                                          info_class,
    1553             :                                                          &info,
    1554             :                                                          &result);
    1555           0 :         if (!NT_STATUS_IS_OK(status))
    1556           0 :                 goto done;
    1557           0 :         if (!NT_STATUS_IS_OK(result)) {
    1558           0 :                 status = result;
    1559           0 :                 goto done;
    1560             :         }
    1561             : 
    1562           0 :         status = cli_get_session_key(mem_ctx, cli, &session_key);
    1563           0 :         if (!NT_STATUS_IS_OK(status)) {
    1564           0 :                 DEBUG(0, ("Could not retrieve session key: %s\n", nt_errstr(status)));
    1565           0 :                 goto done;
    1566             :         }
    1567             : 
    1568           0 :         display_trust_dom_info(mem_ctx, info, info_class, session_key);
    1569             : 
    1570           0 :  done:
    1571           0 :         dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
    1572             : 
    1573           0 :         return status;
    1574             : }
    1575             : 
    1576           0 : static NTSTATUS cmd_lsa_set_trustdominfo(struct rpc_pipe_client *cli,
    1577             :                                          TALLOC_CTX *mem_ctx, int argc,
    1578             :                                          const char **argv)
    1579             : {
    1580             :         struct policy_handle pol, trustdom_pol;
    1581             :         NTSTATUS status, result;
    1582           0 :         uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
    1583             :         union lsa_TrustedDomainInfo info;
    1584             :         struct dom_sid dom_sid;
    1585           0 :         enum lsa_TrustDomInfoEnum info_class = 1;
    1586           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
    1587           0 :         union lsa_revision_info out_revision_info = {
    1588             :                 .info1 = {
    1589             :                         .revision = 0,
    1590             :                 },
    1591             :         };
    1592           0 :         uint32_t out_version = 0;
    1593             : 
    1594           0 :         if (argc > 4 || argc < 3) {
    1595           0 :                 printf("Usage: %s [sid] [info_class] [value]\n", argv[0]);
    1596           0 :                 return NT_STATUS_OK;
    1597             :         }
    1598             : 
    1599           0 :         if (!string_to_sid(&dom_sid, argv[1])) {
    1600           0 :                 return NT_STATUS_NO_MEMORY;
    1601             :         }
    1602             : 
    1603             : 
    1604           0 :         info_class = atoi(argv[2]);
    1605             : 
    1606           0 :         switch (info_class) {
    1607           0 :         case 13: /* LSA_TRUSTED_DOMAIN_SUPPORTED_ENCRYPTION_TYPES */
    1608           0 :                 info.enc_types.enc_types = atoi(argv[3]);
    1609           0 :                 break;
    1610           0 :         default:
    1611           0 :                 return NT_STATUS_INVALID_PARAMETER;
    1612             :         }
    1613             : 
    1614           0 :         status = dcerpc_lsa_open_policy_fallback(b,
    1615             :                                                  mem_ctx,
    1616           0 :                                                  cli->srv_name_slash,
    1617             :                                                  true,
    1618             :                                                  access_mask,
    1619             :                                                  &out_version,
    1620             :                                                  &out_revision_info,
    1621             :                                                  &pol,
    1622             :                                                  &result);
    1623           0 :         if (any_nt_status_not_ok(status, result, &status)) {
    1624           0 :                 goto done;
    1625             :         }
    1626             : 
    1627           0 :         status = dcerpc_lsa_OpenTrustedDomain(b, mem_ctx,
    1628             :                                               &pol,
    1629             :                                               &dom_sid,
    1630             :                                               access_mask,
    1631             :                                               &trustdom_pol,
    1632             :                                               &result);
    1633           0 :         if (!NT_STATUS_IS_OK(status)) {
    1634           0 :                 goto done;
    1635             :         }
    1636           0 :         if (!NT_STATUS_IS_OK(result)) {
    1637           0 :                 status = result;
    1638           0 :                 goto done;
    1639             :         }
    1640             : 
    1641           0 :         status = dcerpc_lsa_SetInformationTrustedDomain(b, mem_ctx,
    1642             :                                                         &trustdom_pol,
    1643             :                                                         info_class,
    1644             :                                                         &info,
    1645             :                                                         &result);
    1646           0 :         if (!NT_STATUS_IS_OK(status)) {
    1647           0 :                 goto done;
    1648             :         }
    1649           0 :         if (!NT_STATUS_IS_OK(result)) {
    1650           0 :                 status = result;
    1651           0 :                 goto done;
    1652             :         }
    1653           0 :  done:
    1654           0 :         dcerpc_lsa_Close(b, mem_ctx, &trustdom_pol, &result);
    1655           0 :         dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
    1656             : 
    1657           0 :         return status;
    1658             : }
    1659             : 
    1660           0 : static NTSTATUS cmd_lsa_query_trustdominfo(struct rpc_pipe_client *cli,
    1661             :                                            TALLOC_CTX *mem_ctx,
    1662             :                                            int argc,
    1663             :                                            const char **argv)
    1664             : {
    1665             :         struct policy_handle pol, trustdom_pol;
    1666             :         NTSTATUS status, result;
    1667           0 :         uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
    1668           0 :         union lsa_TrustedDomainInfo *info = NULL;
    1669             :         struct dom_sid dom_sid;
    1670           0 :         enum lsa_TrustDomInfoEnum info_class = 1;
    1671             :         DATA_BLOB session_key;
    1672           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
    1673           0 :         union lsa_revision_info out_revision_info = {
    1674             :                 .info1 = {
    1675             :                         .revision = 0,
    1676             :                 },
    1677             :         };
    1678           0 :         uint32_t out_version = 0;
    1679             : 
    1680           0 :         if (argc > 3 || argc < 2) {
    1681           0 :                 printf("Usage: %s [sid] [info_class]\n", argv[0]);
    1682           0 :                 return NT_STATUS_OK;
    1683             :         }
    1684             : 
    1685           0 :         if (!string_to_sid(&dom_sid, argv[1]))
    1686           0 :                 return NT_STATUS_NO_MEMORY;
    1687             : 
    1688             : 
    1689           0 :         if (argc == 3)
    1690           0 :                 info_class = atoi(argv[2]);
    1691             : 
    1692           0 :         status = dcerpc_lsa_open_policy_fallback(b,
    1693             :                                                  mem_ctx,
    1694           0 :                                                  cli->srv_name_slash,
    1695             :                                                  true,
    1696             :                                                  access_mask,
    1697             :                                                  &out_version,
    1698             :                                                  &out_revision_info,
    1699             :                                                  &pol,
    1700             :                                                  &result);
    1701           0 :         if (any_nt_status_not_ok(status, result, &status)) {
    1702           0 :                 goto done;
    1703             :         }
    1704             : 
    1705           0 :         status = dcerpc_lsa_OpenTrustedDomain(b, mem_ctx,
    1706             :                                               &pol,
    1707             :                                               &dom_sid,
    1708             :                                               access_mask,
    1709             :                                               &trustdom_pol,
    1710             :                                               &result);
    1711           0 :         if (!NT_STATUS_IS_OK(status))
    1712           0 :                 goto done;
    1713           0 :         if (!NT_STATUS_IS_OK(result)) {
    1714           0 :                 status = result;
    1715           0 :                 goto done;
    1716             :         }
    1717             : 
    1718           0 :         status = dcerpc_lsa_QueryTrustedDomainInfo(b, mem_ctx,
    1719             :                                                    &trustdom_pol,
    1720             :                                                    info_class,
    1721             :                                                    &info,
    1722             :                                                    &result);
    1723           0 :         if (!NT_STATUS_IS_OK(status))
    1724           0 :                 goto done;
    1725           0 :         if (!NT_STATUS_IS_OK(result)) {
    1726           0 :                 status = result;
    1727           0 :                 goto done;
    1728             :         }
    1729             : 
    1730           0 :         status = cli_get_session_key(mem_ctx, cli, &session_key);
    1731           0 :         if (!NT_STATUS_IS_OK(status)) {
    1732           0 :                 DEBUG(0, ("Could not retrieve session key: %s\n", nt_errstr(status)));
    1733           0 :                 goto done;
    1734             :         }
    1735             : 
    1736           0 :         display_trust_dom_info(mem_ctx, info, info_class, session_key);
    1737             : 
    1738           0 :  done:
    1739           0 :         dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
    1740             : 
    1741           0 :         return status;
    1742             : }
    1743             : 
    1744         223 : static NTSTATUS cmd_lsa_get_username(struct rpc_pipe_client *cli,
    1745             :                                      TALLOC_CTX *mem_ctx, int argc,
    1746             :                                      const char **argv)
    1747             : {
    1748             :         NTSTATUS status, result;
    1749         223 :         const char *servername = cli->desthost;
    1750         223 :         struct lsa_String *account_name = NULL;
    1751         223 :         struct lsa_String *authority_name = NULL;
    1752         223 :         struct dcerpc_binding_handle *b = cli->binding_handle;
    1753             : 
    1754         223 :         if (argc > 2) {
    1755           0 :                 printf("Usage: %s servername\n", argv[0]);
    1756           0 :                 return NT_STATUS_OK;
    1757             :         }
    1758             : 
    1759         223 :         status = dcerpc_lsa_GetUserName(b, mem_ctx,
    1760             :                                         servername,
    1761             :                                         &account_name,
    1762             :                                         &authority_name,
    1763             :                                         &result);
    1764         223 :         if (!NT_STATUS_IS_OK(status)) {
    1765          30 :                 goto done;
    1766             :         }
    1767         193 :         if (!NT_STATUS_IS_OK(result)) {
    1768           0 :                 status = result;
    1769           0 :                 goto done;
    1770             :         }
    1771             : 
    1772             :         /* Print results */
    1773             : 
    1774           0 :         printf("Account Name: %s, Authority Name: %s\n",
    1775         193 :                 account_name->string, authority_name ? authority_name->string :
    1776             :                 "");
    1777             : 
    1778         223 :  done:
    1779         223 :         return status;
    1780             : }
    1781             : 
    1782           0 : static NTSTATUS cmd_lsa_add_priv(struct rpc_pipe_client *cli,
    1783             :                                  TALLOC_CTX *mem_ctx, int argc,
    1784             :                                  const char **argv)
    1785             : {
    1786             :         struct policy_handle dom_pol, user_pol;
    1787             :         NTSTATUS status, result;
    1788             :         struct lsa_PrivilegeSet privs;
    1789           0 :         struct lsa_LUIDAttribute *set = NULL;
    1790             :         struct dom_sid sid;
    1791             :         int i;
    1792           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
    1793           0 :         union lsa_revision_info out_revision_info = {
    1794             :                 .info1 = {
    1795             :                         .revision = 0,
    1796             :                 },
    1797             :         };
    1798           0 :         uint32_t out_version = 0;
    1799             : 
    1800           0 :         ZERO_STRUCT(privs);
    1801             : 
    1802           0 :         if (argc < 3 ) {
    1803           0 :                 printf("Usage: %s SID [rights...]\n", argv[0]);
    1804           0 :                 return NT_STATUS_OK;
    1805             :         }
    1806             : 
    1807           0 :         status = name_to_sid(cli, mem_ctx, &sid, argv[1]);
    1808           0 :         if (!NT_STATUS_IS_OK(status)) {
    1809           0 :                 goto done;
    1810             :         }
    1811             : 
    1812           0 :         status = dcerpc_lsa_open_policy_fallback(b,
    1813             :                                                  mem_ctx,
    1814           0 :                                                  cli->srv_name_slash,
    1815             :                                                  true,
    1816             :                                                  SEC_FLAG_MAXIMUM_ALLOWED,
    1817             :                                                  &out_version,
    1818             :                                                  &out_revision_info,
    1819             :                                                  &dom_pol,
    1820             :                                                  &result);
    1821           0 :         if (any_nt_status_not_ok(status, result, &status)) {
    1822           0 :                 goto done;
    1823             :         }
    1824             : 
    1825           0 :         status = dcerpc_lsa_OpenAccount(b, mem_ctx,
    1826             :                                         &dom_pol,
    1827             :                                         &sid,
    1828             :                                         SEC_FLAG_MAXIMUM_ALLOWED,
    1829             :                                         &user_pol,
    1830             :                                         &result);
    1831           0 :         if (!NT_STATUS_IS_OK(status)) {
    1832           0 :                 goto done;
    1833             :         }
    1834           0 :         if (!NT_STATUS_IS_OK(result)) {
    1835           0 :                 status = result;
    1836           0 :                 goto done;
    1837             :         }
    1838             : 
    1839           0 :         for (i=2; i<argc; i++) {
    1840             : 
    1841             :                 struct lsa_String priv_name;
    1842             :                 struct lsa_LUID luid;
    1843             : 
    1844           0 :                 init_lsa_String(&priv_name, argv[i]);
    1845             : 
    1846           0 :                 status = dcerpc_lsa_LookupPrivValue(b, mem_ctx,
    1847             :                                                     &dom_pol,
    1848             :                                                     &priv_name,
    1849             :                                                     &luid,
    1850             :                                                     &result);
    1851           0 :                 if (!NT_STATUS_IS_OK(status)) {
    1852           0 :                         continue;
    1853             :                 }
    1854           0 :                 if (!NT_STATUS_IS_OK(result)) {
    1855           0 :                         status = result;
    1856           0 :                         continue;
    1857             :                 }
    1858             : 
    1859           0 :                 privs.count++;
    1860           0 :                 set = talloc_realloc(mem_ctx, set,
    1861             :                                            struct lsa_LUIDAttribute,
    1862             :                                            privs.count);
    1863           0 :                 if (!set) {
    1864           0 :                         return NT_STATUS_NO_MEMORY;
    1865             :                 }
    1866             : 
    1867           0 :                 set[privs.count-1].luid = luid;
    1868           0 :                 set[privs.count-1].attribute = 0;
    1869             :         }
    1870             : 
    1871           0 :         privs.set = set;
    1872             : 
    1873           0 :         status = dcerpc_lsa_AddPrivilegesToAccount(b, mem_ctx,
    1874             :                                                    &user_pol,
    1875             :                                                    &privs,
    1876             :                                                    &result);
    1877           0 :         if (!NT_STATUS_IS_OK(status)) {
    1878           0 :                 goto done;
    1879             :         }
    1880           0 :         if (!NT_STATUS_IS_OK(result)) {
    1881           0 :                 status = result;
    1882           0 :                 goto done;
    1883             :         }
    1884             : 
    1885           0 :         dcerpc_lsa_Close(b, mem_ctx, &user_pol, &result);
    1886           0 :         dcerpc_lsa_Close(b, mem_ctx, &dom_pol, &result);
    1887           0 :  done:
    1888           0 :         return status;
    1889             : }
    1890             : 
    1891           0 : static NTSTATUS cmd_lsa_del_priv(struct rpc_pipe_client *cli,
    1892             :                                  TALLOC_CTX *mem_ctx, int argc,
    1893             :                                  const char **argv)
    1894             : {
    1895             :         struct policy_handle dom_pol, user_pol;
    1896             :         NTSTATUS status, result;
    1897             :         struct lsa_PrivilegeSet privs;
    1898           0 :         struct lsa_LUIDAttribute *set = NULL;
    1899             :         struct dom_sid sid;
    1900             :         int i;
    1901           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
    1902           0 :         union lsa_revision_info out_revision_info = {
    1903             :                 .info1 = {
    1904             :                         .revision = 0,
    1905             :                 },
    1906             :         };
    1907           0 :         uint32_t out_version = 0;
    1908             : 
    1909           0 :         ZERO_STRUCT(privs);
    1910             : 
    1911           0 :         if (argc < 3 ) {
    1912           0 :                 printf("Usage: %s SID [rights...]\n", argv[0]);
    1913           0 :                 return NT_STATUS_OK;
    1914             :         }
    1915             : 
    1916           0 :         status = name_to_sid(cli, mem_ctx, &sid, argv[1]);
    1917           0 :         if (!NT_STATUS_IS_OK(status)) {
    1918           0 :                 goto done;
    1919             :         }
    1920             : 
    1921           0 :         status = dcerpc_lsa_open_policy_fallback(b,
    1922             :                                                  mem_ctx,
    1923           0 :                                                  cli->srv_name_slash,
    1924             :                                                  true,
    1925             :                                                  SEC_FLAG_MAXIMUM_ALLOWED,
    1926             :                                                  &out_version,
    1927             :                                                  &out_revision_info,
    1928             :                                                  &dom_pol,
    1929             :                                                  &result);
    1930           0 :         if (any_nt_status_not_ok(status, result, &status)) {
    1931           0 :                 goto done;
    1932             :         }
    1933             : 
    1934           0 :         status = dcerpc_lsa_OpenAccount(b, mem_ctx,
    1935             :                                         &dom_pol,
    1936             :                                         &sid,
    1937             :                                         SEC_FLAG_MAXIMUM_ALLOWED,
    1938             :                                         &user_pol,
    1939             :                                         &result);
    1940           0 :         if (!NT_STATUS_IS_OK(status)) {
    1941           0 :                 goto done;
    1942             :         }
    1943           0 :         if (!NT_STATUS_IS_OK(result)) {
    1944           0 :                 status = result;
    1945           0 :                 goto done;
    1946             :         }
    1947             : 
    1948           0 :         for (i=2; i<argc; i++) {
    1949             : 
    1950             :                 struct lsa_String priv_name;
    1951             :                 struct lsa_LUID luid;
    1952             : 
    1953           0 :                 init_lsa_String(&priv_name, argv[i]);
    1954             : 
    1955           0 :                 status = dcerpc_lsa_LookupPrivValue(b, mem_ctx,
    1956             :                                                     &dom_pol,
    1957             :                                                     &priv_name,
    1958             :                                                     &luid,
    1959             :                                                     &result);
    1960           0 :                 if (!NT_STATUS_IS_OK(status)) {
    1961           0 :                         continue;
    1962             :                 }
    1963           0 :                 if (!NT_STATUS_IS_OK(result)) {
    1964           0 :                         status = result;
    1965           0 :                         continue;
    1966             :                 }
    1967             : 
    1968           0 :                 privs.count++;
    1969           0 :                 set = talloc_realloc(mem_ctx, set,
    1970             :                                            struct lsa_LUIDAttribute,
    1971             :                                            privs.count);
    1972           0 :                 if (!set) {
    1973           0 :                         return NT_STATUS_NO_MEMORY;
    1974             :                 }
    1975             : 
    1976           0 :                 set[privs.count-1].luid = luid;
    1977           0 :                 set[privs.count-1].attribute = 0;
    1978             :         }
    1979             : 
    1980           0 :         privs.set = set;
    1981             : 
    1982             : 
    1983           0 :         status = dcerpc_lsa_RemovePrivilegesFromAccount(b, mem_ctx,
    1984             :                                                         &user_pol,
    1985             :                                                         false,
    1986             :                                                         &privs,
    1987             :                                                         &result);
    1988           0 :         if (!NT_STATUS_IS_OK(status)) {
    1989           0 :                 goto done;
    1990             :         }
    1991           0 :         if (!NT_STATUS_IS_OK(result)) {
    1992           0 :                 status = result;
    1993           0 :                 goto done;
    1994             :         }
    1995             : 
    1996           0 :         dcerpc_lsa_Close(b, mem_ctx, &user_pol, &result);
    1997           0 :         dcerpc_lsa_Close(b, mem_ctx, &dom_pol, &result);
    1998           0 :  done:
    1999           0 :         return status;
    2000             : }
    2001             : 
    2002           0 : static NTSTATUS cmd_lsa_create_secret(struct rpc_pipe_client *cli,
    2003             :                                       TALLOC_CTX *mem_ctx, int argc,
    2004             :                                       const char **argv)
    2005             : {
    2006             :         NTSTATUS status, result;
    2007             :         struct policy_handle handle, sec_handle;
    2008             :         struct lsa_String name;
    2009           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
    2010           0 :         union lsa_revision_info out_revision_info = {
    2011             :                 .info1 = {
    2012             :                         .revision = 0,
    2013             :                 },
    2014             :         };
    2015           0 :         uint32_t out_version = 0;
    2016             : 
    2017           0 :         if (argc < 2) {
    2018           0 :                 printf("Usage: %s name\n", argv[0]);
    2019           0 :                 return NT_STATUS_OK;
    2020             :         }
    2021             : 
    2022           0 :         status = dcerpc_lsa_open_policy_fallback(b,
    2023             :                                                  mem_ctx,
    2024           0 :                                                  cli->srv_name_slash,
    2025             :                                                  true,
    2026             :                                                  SEC_FLAG_MAXIMUM_ALLOWED,
    2027             :                                                  &out_version,
    2028             :                                                  &out_revision_info,
    2029             :                                                  &sec_handle,
    2030             :                                                  &result);
    2031           0 :         if (any_nt_status_not_ok(status, result, &status)) {
    2032           0 :                 return status;
    2033             :         }
    2034             : 
    2035           0 :         init_lsa_String(&name, argv[1]);
    2036             : 
    2037           0 :         status = dcerpc_lsa_CreateSecret(b, mem_ctx,
    2038             :                                          &handle,
    2039             :                                          name,
    2040             :                                          SEC_FLAG_MAXIMUM_ALLOWED,
    2041             :                                          &sec_handle,
    2042             :                                          &result);
    2043           0 :         if (!NT_STATUS_IS_OK(status)) {
    2044           0 :                 goto done;
    2045             :         }
    2046           0 :         if (!NT_STATUS_IS_OK(result)) {
    2047           0 :                 status = result;
    2048           0 :                 goto done;
    2049             :         }
    2050             : 
    2051           0 :  done:
    2052           0 :         if (is_valid_policy_hnd(&sec_handle)) {
    2053           0 :                 dcerpc_lsa_Close(b, mem_ctx, &sec_handle, &result);
    2054             :         }
    2055           0 :         if (is_valid_policy_hnd(&handle)) {
    2056           0 :                 dcerpc_lsa_Close(b, mem_ctx, &handle, &result);
    2057             :         }
    2058             : 
    2059           0 :         return status;
    2060             : }
    2061             : 
    2062           0 : static NTSTATUS cmd_lsa_delete_secret(struct rpc_pipe_client *cli,
    2063             :                                       TALLOC_CTX *mem_ctx, int argc,
    2064             :                                       const char **argv)
    2065             : {
    2066             :         NTSTATUS status, result;
    2067             :         struct policy_handle handle, sec_handle;
    2068             :         struct lsa_String name;
    2069           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
    2070           0 :         union lsa_revision_info out_revision_info = {
    2071             :                 .info1 = {
    2072             :                         .revision = 0,
    2073             :                 },
    2074             :         };
    2075           0 :         uint32_t out_version = 0;
    2076             : 
    2077           0 :         if (argc < 2) {
    2078           0 :                 printf("Usage: %s name\n", argv[0]);
    2079           0 :                 return NT_STATUS_OK;
    2080             :         }
    2081             : 
    2082           0 :         status = dcerpc_lsa_open_policy_fallback(b,
    2083             :                                                  mem_ctx,
    2084           0 :                                                  cli->srv_name_slash,
    2085             :                                                  true,
    2086             :                                                  SEC_FLAG_MAXIMUM_ALLOWED,
    2087             :                                                  &out_version,
    2088             :                                                  &out_revision_info,
    2089             :                                                  &handle,
    2090             :                                                  &result);
    2091           0 :         if (any_nt_status_not_ok(status, result, &status)) {
    2092           0 :                 return status;
    2093             :         }
    2094             : 
    2095           0 :         init_lsa_String(&name, argv[1]);
    2096             : 
    2097           0 :         status = dcerpc_lsa_OpenSecret(b, mem_ctx,
    2098             :                                        &handle,
    2099             :                                        name,
    2100             :                                        SEC_FLAG_MAXIMUM_ALLOWED,
    2101             :                                        &sec_handle,
    2102             :                                        &result);
    2103           0 :         if (!NT_STATUS_IS_OK(status)) {
    2104           0 :                 goto done;
    2105             :         }
    2106           0 :         if (!NT_STATUS_IS_OK(result)) {
    2107           0 :                 status = result;
    2108           0 :                 goto done;
    2109             :         }
    2110             : 
    2111           0 :         status = dcerpc_lsa_DeleteObject(b, mem_ctx,
    2112             :                                          &sec_handle,
    2113             :                                          &result);
    2114           0 :         if (!NT_STATUS_IS_OK(status)) {
    2115           0 :                 goto done;
    2116             :         }
    2117           0 :         if (!NT_STATUS_IS_OK(result)) {
    2118           0 :                 status = result;
    2119           0 :                 goto done;
    2120             :         }
    2121             : 
    2122           0 :  done:
    2123           0 :         if (is_valid_policy_hnd(&sec_handle)) {
    2124           0 :                 dcerpc_lsa_Close(b, mem_ctx, &sec_handle, &result);
    2125             :         }
    2126           0 :         if (is_valid_policy_hnd(&handle)) {
    2127           0 :                 dcerpc_lsa_Close(b, mem_ctx, &handle, &result);
    2128             :         }
    2129             : 
    2130           0 :         return status;
    2131             : }
    2132             : 
    2133           0 : static NTSTATUS cmd_lsa_query_secret(struct rpc_pipe_client *cli,
    2134             :                                      TALLOC_CTX *mem_ctx, int argc,
    2135             :                                      const char **argv)
    2136             : {
    2137             :         NTSTATUS status, result;
    2138             :         struct policy_handle handle, sec_handle;
    2139             :         struct lsa_String name;
    2140             :         struct lsa_DATA_BUF_PTR new_val;
    2141           0 :         NTTIME new_mtime = 0;
    2142             :         struct lsa_DATA_BUF_PTR old_val;
    2143           0 :         NTTIME old_mtime = 0;
    2144             :         DATA_BLOB session_key;
    2145           0 :         DATA_BLOB new_blob = data_blob_null;
    2146           0 :         DATA_BLOB old_blob = data_blob_null;
    2147             :         char *new_secret, *old_secret;
    2148           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
    2149           0 :         union lsa_revision_info out_revision_info = {
    2150             :                 .info1 = {
    2151             :                         .revision = 0,
    2152             :                 },
    2153             :         };
    2154           0 :         uint32_t out_version = 0;
    2155             : 
    2156           0 :         if (argc < 2) {
    2157           0 :                 printf("Usage: %s name\n", argv[0]);
    2158           0 :                 return NT_STATUS_OK;
    2159             :         }
    2160             : 
    2161           0 :         status = dcerpc_lsa_open_policy_fallback(b,
    2162             :                                                  mem_ctx,
    2163           0 :                                                  cli->srv_name_slash,
    2164             :                                                  true,
    2165             :                                                  SEC_FLAG_MAXIMUM_ALLOWED,
    2166             :                                                  &out_version,
    2167             :                                                  &out_revision_info,
    2168             :                                                  &handle,
    2169             :                                                  &result);
    2170           0 :         if (any_nt_status_not_ok(status, result, &status)) {
    2171           0 :                 return status;
    2172             :         }
    2173             : 
    2174           0 :         init_lsa_String(&name, argv[1]);
    2175             : 
    2176           0 :         status = dcerpc_lsa_OpenSecret(b, mem_ctx,
    2177             :                                        &handle,
    2178             :                                        name,
    2179             :                                        SEC_FLAG_MAXIMUM_ALLOWED,
    2180             :                                        &sec_handle,
    2181             :                                        &result);
    2182           0 :         if (!NT_STATUS_IS_OK(status)) {
    2183           0 :                 goto done;
    2184             :         }
    2185           0 :         if (!NT_STATUS_IS_OK(result)) {
    2186           0 :                 status = result;
    2187           0 :                 goto done;
    2188             :         }
    2189             : 
    2190           0 :         ZERO_STRUCT(new_val);
    2191           0 :         ZERO_STRUCT(old_val);
    2192             : 
    2193           0 :         status = dcerpc_lsa_QuerySecret(b, mem_ctx,
    2194             :                                         &sec_handle,
    2195             :                                         &new_val,
    2196             :                                         &new_mtime,
    2197             :                                         &old_val,
    2198             :                                         &old_mtime,
    2199             :                                         &result);
    2200           0 :         if (!NT_STATUS_IS_OK(status)) {
    2201           0 :                 goto done;
    2202             :         }
    2203           0 :         if (!NT_STATUS_IS_OK(result)) {
    2204           0 :                 status = result;
    2205           0 :                 goto done;
    2206             :         }
    2207             : 
    2208           0 :         status = cli_get_session_key(mem_ctx, cli, &session_key);
    2209           0 :         if (!NT_STATUS_IS_OK(status)) {
    2210           0 :                 goto done;
    2211             :         }
    2212             : 
    2213           0 :         if (new_val.buf) {
    2214           0 :                 new_blob = data_blob_const(new_val.buf->data, new_val.buf->length);
    2215             :         }
    2216           0 :         if (old_val.buf) {
    2217           0 :                 old_blob = data_blob_const(old_val.buf->data, old_val.buf->length);
    2218             :         }
    2219             : 
    2220           0 :         new_secret = sess_decrypt_string(mem_ctx, &new_blob, &session_key);
    2221           0 :         old_secret = sess_decrypt_string(mem_ctx, &old_blob, &session_key);
    2222           0 :         if (new_secret) {
    2223           0 :                 d_printf("new secret: %s\n", new_secret);
    2224             :         }
    2225           0 :         if (old_secret) {
    2226           0 :                 d_printf("old secret: %s\n", old_secret);
    2227             :         }
    2228             : 
    2229           0 :  done:
    2230           0 :         if (is_valid_policy_hnd(&sec_handle)) {
    2231           0 :                 dcerpc_lsa_Close(b, mem_ctx, &sec_handle, &result);
    2232             :         }
    2233           0 :         if (is_valid_policy_hnd(&handle)) {
    2234           0 :                 dcerpc_lsa_Close(b, mem_ctx, &handle, &result);
    2235             :         }
    2236             : 
    2237           0 :         return status;
    2238             : }
    2239             : 
    2240           0 : static NTSTATUS cmd_lsa_set_secret(struct rpc_pipe_client *cli,
    2241             :                                    TALLOC_CTX *mem_ctx, int argc,
    2242             :                                    const char **argv)
    2243             : {
    2244             :         NTSTATUS status, result;
    2245             :         struct policy_handle handle, sec_handle;
    2246             :         struct lsa_String name;
    2247             :         struct lsa_DATA_BUF new_val;
    2248             :         struct lsa_DATA_BUF old_val;
    2249             :         DATA_BLOB enc_key;
    2250             :         DATA_BLOB session_key;
    2251           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
    2252           0 :         union lsa_revision_info out_revision_info = {
    2253             :                 .info1 = {
    2254             :                         .revision = 0,
    2255             :                 },
    2256             :         };
    2257           0 :         uint32_t out_version = 0;
    2258             : 
    2259           0 :         if (argc < 3) {
    2260           0 :                 printf("Usage: %s name secret\n", argv[0]);
    2261           0 :                 return NT_STATUS_OK;
    2262             :         }
    2263             : 
    2264           0 :         status = dcerpc_lsa_open_policy_fallback(b,
    2265             :                                                  mem_ctx,
    2266           0 :                                                  cli->srv_name_slash,
    2267             :                                                  true,
    2268             :                                                  SEC_FLAG_MAXIMUM_ALLOWED,
    2269             :                                                  &out_version,
    2270             :                                                  &out_revision_info,
    2271             :                                                  &handle,
    2272             :                                                  &result);
    2273           0 :         if (any_nt_status_not_ok(status, result, &status)) {
    2274           0 :                 return status;
    2275             :         }
    2276             : 
    2277           0 :         init_lsa_String(&name, argv[1]);
    2278             : 
    2279           0 :         status = dcerpc_lsa_OpenSecret(b, mem_ctx,
    2280             :                                        &handle,
    2281             :                                        name,
    2282             :                                        SEC_FLAG_MAXIMUM_ALLOWED,
    2283             :                                        &sec_handle,
    2284             :                                        &result);
    2285           0 :         if (!NT_STATUS_IS_OK(status)) {
    2286           0 :                 goto done;
    2287             :         }
    2288           0 :         if (!NT_STATUS_IS_OK(result)) {
    2289           0 :                 status = result;
    2290           0 :                 goto done;
    2291             :         }
    2292             : 
    2293           0 :         ZERO_STRUCT(new_val);
    2294           0 :         ZERO_STRUCT(old_val);
    2295             : 
    2296           0 :         status = cli_get_session_key(mem_ctx, cli, &session_key);
    2297           0 :         if (!NT_STATUS_IS_OK(status)) {
    2298           0 :                 goto done;
    2299             :         }
    2300             : 
    2301           0 :         enc_key = sess_encrypt_string(argv[2], &session_key);
    2302             : 
    2303           0 :         new_val.length = enc_key.length;
    2304           0 :         new_val.size = enc_key.length;
    2305           0 :         new_val.data = enc_key.data;
    2306             : 
    2307           0 :         status = dcerpc_lsa_SetSecret(b, mem_ctx,
    2308             :                                       &sec_handle,
    2309             :                                       &new_val,
    2310             :                                       NULL,
    2311             :                                       &result);
    2312           0 :         if (!NT_STATUS_IS_OK(status)) {
    2313           0 :                 goto done;
    2314             :         }
    2315           0 :         if (!NT_STATUS_IS_OK(result)) {
    2316           0 :                 status = result;
    2317           0 :                 goto done;
    2318             :         }
    2319             : 
    2320           0 :  done:
    2321           0 :         if (is_valid_policy_hnd(&sec_handle)) {
    2322           0 :                 dcerpc_lsa_Close(b, mem_ctx, &sec_handle, &result);
    2323             :         }
    2324           0 :         if (is_valid_policy_hnd(&handle)) {
    2325           0 :                 dcerpc_lsa_Close(b, mem_ctx, &handle, &result);
    2326             :         }
    2327             : 
    2328           0 :         return status;
    2329             : }
    2330             : 
    2331           0 : static NTSTATUS cmd_lsa_retrieve_private_data(struct rpc_pipe_client *cli,
    2332             :                                               TALLOC_CTX *mem_ctx, int argc,
    2333             :                                               const char **argv)
    2334             : {
    2335             :         NTSTATUS status, result;
    2336             :         struct policy_handle handle;
    2337             :         struct lsa_String name;
    2338             :         struct lsa_DATA_BUF *val;
    2339             :         DATA_BLOB session_key;
    2340           0 :         DATA_BLOB blob = data_blob_null;
    2341             :         char *secret;
    2342           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
    2343           0 :         union lsa_revision_info out_revision_info = {
    2344             :                 .info1 = {
    2345             :                         .revision = 0,
    2346             :                 },
    2347             :         };
    2348           0 :         uint32_t out_version = 0;
    2349             : 
    2350           0 :         if (argc < 2) {
    2351           0 :                 printf("Usage: %s name\n", argv[0]);
    2352           0 :                 return NT_STATUS_OK;
    2353             :         }
    2354             : 
    2355           0 :         status = dcerpc_lsa_open_policy_fallback(b,
    2356             :                                                  mem_ctx,
    2357           0 :                                                  cli->srv_name_slash,
    2358             :                                                  true,
    2359             :                                                  SEC_FLAG_MAXIMUM_ALLOWED,
    2360             :                                                  &out_version,
    2361             :                                                  &out_revision_info,
    2362             :                                                  &handle,
    2363             :                                                  &result);
    2364           0 :         if (any_nt_status_not_ok(status, result, &status)) {
    2365           0 :                 return status;
    2366             :         }
    2367             : 
    2368           0 :         init_lsa_String(&name, argv[1]);
    2369             : 
    2370           0 :         ZERO_STRUCT(val);
    2371             : 
    2372           0 :         status = dcerpc_lsa_RetrievePrivateData(b, mem_ctx,
    2373             :                                                 &handle,
    2374             :                                                 &name,
    2375             :                                                 &val,
    2376             :                                                 &result);
    2377           0 :         if (!NT_STATUS_IS_OK(status)) {
    2378           0 :                 goto done;
    2379             :         }
    2380           0 :         if (!NT_STATUS_IS_OK(result)) {
    2381           0 :                 status = result;
    2382           0 :                 goto done;
    2383             :         }
    2384             : 
    2385           0 :         status = cli_get_session_key(mem_ctx, cli, &session_key);
    2386           0 :         if (!NT_STATUS_IS_OK(status)) {
    2387           0 :                 goto done;
    2388             :         }
    2389             : 
    2390           0 :         if (val) {
    2391           0 :                 blob = data_blob_const(val->data, val->length);
    2392             :         }
    2393             : 
    2394           0 :         secret = sess_decrypt_string(mem_ctx, &blob, &session_key);
    2395           0 :         if (secret) {
    2396           0 :                 d_printf("secret: %s\n", secret);
    2397             :         }
    2398             : 
    2399           0 :  done:
    2400           0 :         if (is_valid_policy_hnd(&handle)) {
    2401           0 :                 dcerpc_lsa_Close(b, mem_ctx, &handle, &result);
    2402             :         }
    2403             : 
    2404           0 :         return status;
    2405             : }
    2406             : 
    2407           0 : static NTSTATUS cmd_lsa_store_private_data(struct rpc_pipe_client *cli,
    2408             :                                            TALLOC_CTX *mem_ctx, int argc,
    2409             :                                            const char **argv)
    2410             : {
    2411             :         NTSTATUS status, result;
    2412             :         struct policy_handle handle;
    2413             :         struct lsa_String name;
    2414             :         struct lsa_DATA_BUF val;
    2415             :         DATA_BLOB session_key;
    2416             :         DATA_BLOB enc_key;
    2417           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
    2418           0 :         union lsa_revision_info out_revision_info = {
    2419             :                 .info1 = {
    2420             :                         .revision = 0,
    2421             :                 },
    2422             :         };
    2423           0 :         uint32_t out_version = 0;
    2424             : 
    2425           0 :         if (argc < 3) {
    2426           0 :                 printf("Usage: %s name secret\n", argv[0]);
    2427           0 :                 return NT_STATUS_OK;
    2428             :         }
    2429             : 
    2430           0 :         status = dcerpc_lsa_open_policy_fallback(b,
    2431             :                                                  mem_ctx,
    2432           0 :                                                  cli->srv_name_slash,
    2433             :                                                  true,
    2434             :                                                  SEC_FLAG_MAXIMUM_ALLOWED,
    2435             :                                                  &out_version,
    2436             :                                                  &out_revision_info,
    2437             :                                                  &handle,
    2438             :                                                  &result);
    2439           0 :         if (any_nt_status_not_ok(status, result, &status)) {
    2440           0 :                 return status;
    2441             :         }
    2442             : 
    2443           0 :         init_lsa_String(&name, argv[1]);
    2444             : 
    2445           0 :         ZERO_STRUCT(val);
    2446             : 
    2447           0 :         status = cli_get_session_key(mem_ctx, cli, &session_key);
    2448           0 :         if (!NT_STATUS_IS_OK(status)) {
    2449           0 :                 goto done;
    2450             :         }
    2451             : 
    2452           0 :         enc_key = sess_encrypt_string(argv[2], &session_key);
    2453             : 
    2454           0 :         val.length = enc_key.length;
    2455           0 :         val.size = enc_key.length;
    2456           0 :         val.data = enc_key.data;
    2457             : 
    2458           0 :         status = dcerpc_lsa_StorePrivateData(b, mem_ctx,
    2459             :                                              &handle,
    2460             :                                              &name,
    2461             :                                              &val,
    2462             :                                              &result);
    2463           0 :         if (!NT_STATUS_IS_OK(status)) {
    2464           0 :                 goto done;
    2465             :         }
    2466           0 :         if (!NT_STATUS_IS_OK(result)) {
    2467           0 :                 status = result;
    2468           0 :                 goto done;
    2469             :         }
    2470             : 
    2471           0 :  done:
    2472           0 :         if (is_valid_policy_hnd(&handle)) {
    2473           0 :                 dcerpc_lsa_Close(b, mem_ctx, &handle, &result);
    2474             :         }
    2475             : 
    2476           0 :         return status;
    2477             : }
    2478             : 
    2479           0 : static NTSTATUS cmd_lsa_create_trusted_domain(struct rpc_pipe_client *cli,
    2480             :                                               TALLOC_CTX *mem_ctx, int argc,
    2481             :                                               const char **argv)
    2482             : {
    2483             :         NTSTATUS status, result;
    2484             :         struct policy_handle handle, trustdom_handle;
    2485             :         struct dom_sid sid;
    2486             :         struct lsa_DomainInfo info;
    2487           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
    2488           0 :         union lsa_revision_info out_revision_info = {
    2489             :                 .info1 = {
    2490             :                         .revision = 0,
    2491             :                 },
    2492             :         };
    2493           0 :         uint32_t out_version = 0;
    2494             : 
    2495           0 :         if (argc < 3) {
    2496           0 :                 printf("Usage: %s name sid\n", argv[0]);
    2497           0 :                 return NT_STATUS_OK;
    2498             :         }
    2499             : 
    2500           0 :         status = dcerpc_lsa_open_policy_fallback(b,
    2501             :                                                  mem_ctx,
    2502           0 :                                                  cli->srv_name_slash,
    2503             :                                                  true,
    2504             :                                                  SEC_FLAG_MAXIMUM_ALLOWED,
    2505             :                                                  &out_version,
    2506             :                                                  &out_revision_info,
    2507             :                                                  &handle,
    2508             :                                                  &result);
    2509           0 :         if (any_nt_status_not_ok(status, result, &status)) {
    2510           0 :                 return status;
    2511             :         }
    2512             : 
    2513           0 :         init_lsa_StringLarge(&info.name, argv[1]);
    2514           0 :         info.sid = &sid;
    2515           0 :         string_to_sid(&sid, argv[2]);
    2516             : 
    2517           0 :         status = dcerpc_lsa_CreateTrustedDomain(b, mem_ctx,
    2518             :                                                 &handle,
    2519             :                                                 &info,
    2520             :                                                 SEC_FLAG_MAXIMUM_ALLOWED,
    2521             :                                                 &trustdom_handle,
    2522             :                                                 &result);
    2523           0 :         if (!NT_STATUS_IS_OK(status)) {
    2524           0 :                 goto done;
    2525             :         }
    2526           0 :         if (!NT_STATUS_IS_OK(result)) {
    2527           0 :                 status = result;
    2528           0 :                 goto done;
    2529             :         }
    2530             : 
    2531           0 :  done:
    2532           0 :         if (is_valid_policy_hnd(&trustdom_handle)) {
    2533           0 :                 dcerpc_lsa_Close(b, mem_ctx, &trustdom_handle, &result);
    2534             :         }
    2535             : 
    2536           0 :         if (is_valid_policy_hnd(&handle)) {
    2537           0 :                 dcerpc_lsa_Close(b, mem_ctx, &handle, &result);
    2538             :         }
    2539             : 
    2540           0 :         return status;
    2541             : }
    2542             : 
    2543           0 : static NTSTATUS cmd_lsa_delete_trusted_domain(struct rpc_pipe_client *cli,
    2544             :                                               TALLOC_CTX *mem_ctx, int argc,
    2545             :                                               const char **argv)
    2546             : {
    2547             :         NTSTATUS status, result;
    2548             :         struct policy_handle handle, trustdom_handle;
    2549             :         struct lsa_String name;
    2550           0 :         struct dom_sid *sid = NULL;
    2551           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
    2552           0 :         union lsa_revision_info out_revision_info = {
    2553             :                 .info1 = {
    2554             :                         .revision = 0,
    2555             :                 },
    2556             :         };
    2557           0 :         uint32_t out_version = 0;
    2558             : 
    2559           0 :         if (argc < 2) {
    2560           0 :                 printf("Usage: %s name\n", argv[0]);
    2561           0 :                 return NT_STATUS_OK;
    2562             :         }
    2563             : 
    2564           0 :         status = dcerpc_lsa_open_policy_fallback(b,
    2565             :                                                  mem_ctx,
    2566           0 :                                                  cli->srv_name_slash,
    2567             :                                                  true,
    2568             :                                                  SEC_FLAG_MAXIMUM_ALLOWED,
    2569             :                                                  &out_version,
    2570             :                                                  &out_revision_info,
    2571             :                                                  &handle,
    2572             :                                                  &result);
    2573           0 :         if (any_nt_status_not_ok(status, result, &status)) {
    2574           0 :                 return status;
    2575             :         }
    2576             : 
    2577           0 :         init_lsa_String(&name, argv[1]);
    2578             : 
    2579           0 :         status = dcerpc_lsa_OpenTrustedDomainByName(b, mem_ctx,
    2580             :                                                     &handle,
    2581             :                                                     name,
    2582             :                                                     SEC_FLAG_MAXIMUM_ALLOWED,
    2583             :                                                     &trustdom_handle,
    2584             :                                                     &result);
    2585           0 :         if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(result)) {
    2586           0 :                 goto delete_object;
    2587             :         }
    2588             : 
    2589             :         {
    2590           0 :                 uint32_t resume_handle = 0;
    2591             :                 struct lsa_DomainList domains;
    2592             :                 int i;
    2593             : 
    2594           0 :                 status = dcerpc_lsa_EnumTrustDom(b, mem_ctx,
    2595             :                                                  &handle,
    2596             :                                                  &resume_handle,
    2597             :                                                  &domains,
    2598             :                                                  0xffff,
    2599             :                                                  &result);
    2600           0 :                 if (!NT_STATUS_IS_OK(status)) {
    2601           0 :                         goto done;
    2602             :                 }
    2603           0 :                 if (!NT_STATUS_IS_OK(result)) {
    2604           0 :                         status = result;
    2605           0 :                         goto done;
    2606             :                 }
    2607             : 
    2608           0 :                 for (i=0; i < domains.count; i++) {
    2609           0 :                         if (strequal(domains.domains[i].name.string, argv[1])) {
    2610           0 :                                 sid = domains.domains[i].sid;
    2611           0 :                                 break;
    2612             :                         }
    2613             :                 }
    2614             : 
    2615           0 :                 if (!sid) {
    2616           0 :                         return NT_STATUS_INVALID_SID;
    2617             :                 }
    2618             :         }
    2619             : 
    2620           0 :         status = dcerpc_lsa_OpenTrustedDomain(b, mem_ctx,
    2621             :                                               &handle,
    2622             :                                               sid,
    2623             :                                               SEC_FLAG_MAXIMUM_ALLOWED,
    2624             :                                               &trustdom_handle,
    2625             :                                               &result);
    2626           0 :         if (!NT_STATUS_IS_OK(status)) {
    2627           0 :                 goto done;
    2628             :         }
    2629           0 :         if (!NT_STATUS_IS_OK(result)) {
    2630           0 :                 status = result;
    2631           0 :                 goto done;
    2632             :         }
    2633             : 
    2634           0 :  delete_object:
    2635           0 :         status = dcerpc_lsa_DeleteObject(b, mem_ctx,
    2636             :                                          &trustdom_handle,
    2637             :                                          &result);
    2638           0 :         if (!NT_STATUS_IS_OK(status)) {
    2639           0 :                 goto done;
    2640             :         }
    2641           0 :         if (!NT_STATUS_IS_OK(result)) {
    2642           0 :                 status = result;
    2643           0 :                 goto done;
    2644             :         }
    2645             : 
    2646           0 :  done:
    2647           0 :         if (is_valid_policy_hnd(&trustdom_handle)) {
    2648           0 :                 dcerpc_lsa_Close(b, mem_ctx, &trustdom_handle, &result);
    2649             :         }
    2650             : 
    2651           0 :         if (is_valid_policy_hnd(&handle)) {
    2652           0 :                 dcerpc_lsa_Close(b, mem_ctx, &handle, &result);
    2653             :         }
    2654             : 
    2655           0 :         return status;
    2656             : }
    2657             : 
    2658             : 
    2659             : /* List of commands exported by this module */
    2660             : 
    2661             : struct cmd_set lsarpc_commands[] = {
    2662             : 
    2663             :         {
    2664             :                 .name = "LSARPC",
    2665             :         },
    2666             : 
    2667             :         {
    2668             :                 .name               = "lsaquery",
    2669             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2670             :                 .ntfn               = cmd_lsa_query_info_policy,
    2671             :                 .wfn                =  NULL,
    2672             :                 .table              = &ndr_table_lsarpc,
    2673             :                 .rpc_pipe           = NULL,
    2674             :                 .description        = "Query info policy",
    2675             :                 .usage              = "",
    2676             :         },
    2677             :         {
    2678             :                 .name               = "lookupsids",
    2679             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2680             :                 .ntfn               = cmd_lsa_lookup_sids,
    2681             :                 .wfn                = NULL,
    2682             :                 .table              = &ndr_table_lsarpc,
    2683             :                 .rpc_pipe           = NULL,
    2684             :                 .description        = "Convert SIDs to names",
    2685             :                 .usage              = "",
    2686             :         },
    2687             :         {
    2688             :                 .name               = "lookupsids3",
    2689             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2690             :                 .ntfn               = cmd_lsa_lookup_sids3,
    2691             :                 .wfn                = NULL,
    2692             :                 .table              = &ndr_table_lsarpc,
    2693             :                 .rpc_pipe           = NULL,
    2694             :                 .description        = "Convert SIDs to names",
    2695             :                 .usage              = "",
    2696             :         },
    2697             :         {
    2698             :                 .name               = "lookupsids_level",
    2699             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2700             :                 .ntfn               = cmd_lsa_lookup_sids_level,
    2701             :                 .wfn                = NULL,
    2702             :                 .table              = &ndr_table_lsarpc,
    2703             :                 .rpc_pipe           = NULL,
    2704             :                 .description        = "Convert SIDs to names",
    2705             :                 .usage              = "",
    2706             :         },
    2707             :         {
    2708             :                 .name               = "lookupnames",
    2709             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2710             :                 .ntfn               = cmd_lsa_lookup_names,
    2711             :                 .wfn                = NULL,
    2712             :                 .table              = &ndr_table_lsarpc,
    2713             :                 .rpc_pipe           = NULL,
    2714             :                 .description        = "Convert names to SIDs",
    2715             :                 .usage              = "",
    2716             :         },
    2717             :         {
    2718             :                 .name               = "lookupnames4",
    2719             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2720             :                 .ntfn               = cmd_lsa_lookup_names4,
    2721             :                 .wfn                = NULL,
    2722             :                 .table              = &ndr_table_lsarpc,
    2723             :                 .rpc_pipe           = NULL,
    2724             :                 .description        = "Convert names to SIDs",
    2725             :                 .usage              = "",
    2726             :         },
    2727             :         {
    2728             :                 .name               = "lookupnames_level",
    2729             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2730             :                 .ntfn               = cmd_lsa_lookup_names_level,
    2731             :                 .wfn                = NULL,
    2732             :                 .table              = &ndr_table_lsarpc,
    2733             :                 .rpc_pipe           = NULL,
    2734             :                 .description        = "Convert names to SIDs",
    2735             :                 .usage              = "",
    2736             :         },
    2737             :         {
    2738             :                 .name               = "enumtrust",
    2739             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2740             :                 .ntfn               = cmd_lsa_enum_trust_dom,
    2741             :                 .wfn                = NULL,
    2742             :                 .table              = &ndr_table_lsarpc,
    2743             :                 .rpc_pipe           = NULL,
    2744             :                 .description        = "Enumerate trusted domains",
    2745             :                 .usage              = "Usage: [preferred max number] [enum context (0)]",
    2746             :         },
    2747             :         {
    2748             :                 .name               = "enumprivs",
    2749             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2750             :                 .ntfn               = cmd_lsa_enum_privilege,
    2751             :                 .wfn                = NULL,
    2752             :                 .table              = &ndr_table_lsarpc,
    2753             :                 .rpc_pipe           = NULL,
    2754             :                 .description        = "Enumerate privileges",
    2755             :                 .usage              = "",
    2756             :         },
    2757             :         {
    2758             :                 .name               = "getdispname",
    2759             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2760             :                 .ntfn               = cmd_lsa_get_dispname,
    2761             :                 .wfn                = NULL,
    2762             :                 .table              = &ndr_table_lsarpc,
    2763             :                 .rpc_pipe           = NULL,
    2764             :                 .description        = "Get the privilege name",
    2765             :                 .usage              = "",
    2766             :         },
    2767             :         {
    2768             :                 .name               = "lsaenumsid",
    2769             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2770             :                 .ntfn               = cmd_lsa_enum_sids,
    2771             :                 .wfn                = NULL,
    2772             :                 .table              = &ndr_table_lsarpc,
    2773             :                 .rpc_pipe           = NULL,
    2774             :                 .description        = "Enumerate the LSA SIDS",
    2775             :                 .usage              = "",
    2776             :         },
    2777             :         {
    2778             :                 .name               = "lsacreateaccount",
    2779             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2780             :                 .ntfn               = cmd_lsa_create_account,
    2781             :                 .wfn                = NULL,
    2782             :                 .table              = &ndr_table_lsarpc,
    2783             :                 .rpc_pipe           = NULL,
    2784             :                 .description        = "Create a new lsa account",
    2785             :                 .usage              = "",
    2786             :         },
    2787             :         {
    2788             :                 .name               = "lsaenumprivsaccount",
    2789             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2790             :                 .ntfn               = cmd_lsa_enum_privsaccounts,
    2791             :                 .wfn                = NULL,
    2792             :                 .table              = &ndr_table_lsarpc,
    2793             :                 .rpc_pipe           = NULL,
    2794             :                 .description        = "Enumerate the privileges of an SID",
    2795             :                 .usage              = "",
    2796             :         },
    2797             :         {
    2798             :                 .name               = "lsaenumacctrights",
    2799             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2800             :                 .ntfn               = cmd_lsa_enum_acct_rights,
    2801             :                 .wfn                = NULL,
    2802             :                 .table              = &ndr_table_lsarpc,
    2803             :                 .rpc_pipe           = NULL,
    2804             :                 .description        = "Enumerate the rights of an SID",
    2805             :                 .usage              = "",
    2806             :         },
    2807             :         {
    2808             :                 .name               = "lsaaddpriv",
    2809             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2810             :                 .ntfn               = cmd_lsa_add_priv,
    2811             :                 .wfn                = NULL,
    2812             :                 .table              = &ndr_table_lsarpc,
    2813             :                 .rpc_pipe           = NULL,
    2814             :                 .description        = "Assign a privilege to a SID",
    2815             :                 .usage              = "",
    2816             :         },
    2817             :         {
    2818             :                 .name               = "lsadelpriv",
    2819             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2820             :                 .ntfn               = cmd_lsa_del_priv,
    2821             :                 .wfn                = NULL,
    2822             :                 .table              = &ndr_table_lsarpc,
    2823             :                 .rpc_pipe           = NULL,
    2824             :                 .description        = "Revoke a privilege from a SID",
    2825             :                 .usage              = "",
    2826             :         },
    2827             :         {
    2828             :                 .name               = "lsaaddacctrights",
    2829             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2830             :                 .ntfn               = cmd_lsa_add_acct_rights,
    2831             :                 .wfn                = NULL,
    2832             :                 .table              = &ndr_table_lsarpc,
    2833             :                 .rpc_pipe           = NULL,
    2834             :                 .description        = "Add rights to an account",
    2835             :                 .usage              = "",
    2836             :         },
    2837             :         {
    2838             :                 .name               = "lsaremoveacctrights",
    2839             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2840             :                 .ntfn               = cmd_lsa_remove_acct_rights,
    2841             :                 .wfn                = NULL,
    2842             :                 .table              = &ndr_table_lsarpc,
    2843             :                 .rpc_pipe           = NULL,
    2844             :                 .description        = "Remove rights from an account",
    2845             :                 .usage              = "",
    2846             :         },
    2847             :         {
    2848             :                 .name               = "lsalookupprivvalue",
    2849             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2850             :                 .ntfn               = cmd_lsa_lookup_priv_value,
    2851             :                 .wfn                = NULL,
    2852             :                 .table              = &ndr_table_lsarpc,
    2853             :                 .rpc_pipe           = NULL,
    2854             :                 .description        = "Get a privilege value given its name",
    2855             :                 .usage              = "",
    2856             :         },
    2857             :         {
    2858             :                 .name               = "lsaquerysecobj",
    2859             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2860             :                 .ntfn               = cmd_lsa_query_secobj,
    2861             :                 .wfn                = NULL,
    2862             :                 .table              = &ndr_table_lsarpc,
    2863             :                 .rpc_pipe           = NULL,
    2864             :                 .description        = "Query LSA security object",
    2865             :                 .usage              = "",
    2866             :         },
    2867             :         {
    2868             :                 .name               = "lsaquerytrustdominfo",
    2869             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2870             :                 .ntfn               = cmd_lsa_query_trustdominfo,
    2871             :                 .wfn                = NULL,
    2872             :                 .table              = &ndr_table_lsarpc,
    2873             :                 .rpc_pipe           = NULL,
    2874             :                 .description        = "Query LSA trusted domains info (given a SID)",
    2875             :                 .usage              = "",
    2876             :         },
    2877             :         {
    2878             :                 .name               = "lsaquerytrustdominfobyname",
    2879             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2880             :                 .ntfn               = cmd_lsa_query_trustdominfobyname,
    2881             :                 .wfn                = NULL,
    2882             :                 .table              = &ndr_table_lsarpc,
    2883             :                 .rpc_pipe           = NULL,
    2884             :                 .description        = "Query LSA trusted domains info (given a name), only works for Windows > 2k",
    2885             :                 .usage              = "",
    2886             :         },
    2887             :         {
    2888             :                 .name               = "lsaquerytrustdominfobysid",
    2889             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2890             :                 .ntfn               = cmd_lsa_query_trustdominfobysid,
    2891             :                 .wfn                = NULL,
    2892             :                 .table              = &ndr_table_lsarpc,
    2893             :                 .rpc_pipe           = NULL,
    2894             :                 .description        = "Query LSA trusted domains info (given a SID)",
    2895             :                 .usage              = "",
    2896             :         },
    2897             :         {
    2898             :                 .name               = "lsasettrustdominfo",
    2899             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2900             :                 .ntfn               = cmd_lsa_set_trustdominfo,
    2901             :                 .wfn                = NULL,
    2902             :                 .table              = &ndr_table_lsarpc,
    2903             :                 .rpc_pipe           = NULL,
    2904             :                 .description        = "Set LSA trusted domain info",
    2905             :                 .usage              = "",
    2906             :         },
    2907             :         {
    2908             :                 .name               = "getusername",
    2909             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2910             :                 .ntfn               = cmd_lsa_get_username,
    2911             :                 .wfn                = NULL,
    2912             :                 .table              = &ndr_table_lsarpc,
    2913             :                 .rpc_pipe           = NULL,
    2914             :                 .description        = "Get username",
    2915             :                 .usage              = "",
    2916             :         },
    2917             :         {
    2918             :                 .name               = "createsecret",
    2919             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2920             :                 .ntfn               = cmd_lsa_create_secret,
    2921             :                 .wfn                = NULL,
    2922             :                 .table              = &ndr_table_lsarpc,
    2923             :                 .rpc_pipe           = NULL,
    2924             :                 .description        = "Create Secret",
    2925             :                 .usage              = "",
    2926             :         },
    2927             :         {
    2928             :                 .name               = "deletesecret",
    2929             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2930             :                 .ntfn               = cmd_lsa_delete_secret,
    2931             :                 .wfn                = NULL,
    2932             :                 .table              = &ndr_table_lsarpc,
    2933             :                 .rpc_pipe           = NULL,
    2934             :                 .description        = "Delete Secret",
    2935             :                 .usage              = "",
    2936             :         },
    2937             :         {
    2938             :                 .name               = "querysecret",
    2939             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2940             :                 .ntfn               = cmd_lsa_query_secret,
    2941             :                 .wfn                = NULL,
    2942             :                 .table              = &ndr_table_lsarpc,
    2943             :                 .rpc_pipe           = NULL,
    2944             :                 .description        = "Query Secret",
    2945             :                 .usage              = "",
    2946             :         },
    2947             :         {
    2948             :                 .name               = "setsecret",
    2949             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2950             :                 .ntfn               = cmd_lsa_set_secret,
    2951             :                 .wfn                = NULL,
    2952             :                 .table              = &ndr_table_lsarpc,
    2953             :                 .rpc_pipe           = NULL,
    2954             :                 .description        = "Set Secret",
    2955             :                 .usage              = "",
    2956             :         },
    2957             :         {
    2958             :                 .name               = "retrieveprivatedata",
    2959             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2960             :                 .ntfn               = cmd_lsa_retrieve_private_data,
    2961             :                 .wfn                = NULL,
    2962             :                 .table              = &ndr_table_lsarpc,
    2963             :                 .rpc_pipe           = NULL,
    2964             :                 .description        = "Retrieve Private Data",
    2965             :                 .usage              = "",
    2966             :         },
    2967             :         {
    2968             :                 .name               = "storeprivatedata",
    2969             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2970             :                 .ntfn               = cmd_lsa_store_private_data,
    2971             :                 .wfn                = NULL,
    2972             :                 .table              = &ndr_table_lsarpc,
    2973             :                 .rpc_pipe           = NULL,
    2974             :                 .description        = "Store Private Data",
    2975             :                 .usage              = "",
    2976             :         },
    2977             :         {
    2978             :                 .name               = "createtrustdom",
    2979             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2980             :                 .ntfn               = cmd_lsa_create_trusted_domain,
    2981             :                 .wfn                = NULL,
    2982             :                 .table              = &ndr_table_lsarpc,
    2983             :                 .rpc_pipe           = NULL,
    2984             :                 .description        = "Create Trusted Domain",
    2985             :                 .usage              = "",
    2986             :         },
    2987             :         {
    2988             :                 .name               = "deletetrustdom",
    2989             :                 .returntype         = RPC_RTYPE_NTSTATUS,
    2990             :                 .ntfn               = cmd_lsa_delete_trusted_domain,
    2991             :                 .wfn                = NULL,
    2992             :                 .table              = &ndr_table_lsarpc,
    2993             :                 .rpc_pipe           = NULL,
    2994             :                 .description        = "Delete Trusted Domain",
    2995             :                 .usage              = "",
    2996             :         },
    2997             :         {
    2998             :                 .name = NULL,
    2999             :         },
    3000             : };

Generated by: LCOV version 1.14