From 6bf6b0ad44c72643699b282c9891113a933a3812 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Tue, 14 Sep 1999 21:04:02 +0000 Subject: added rpcclient SamrQueryDisplayInfo command "dispinfo" (This used to be commit 6c98d6c9aae64016bfe7727cfe12762967eb5a84) --- source3/rpc_client/cli_samr.c | 70 ++++++++++++++++++++++++++++++++++ source3/rpcclient/cmd_samr.c | 87 +++++++++++++++++++++++++++++++++++++++++++ source3/rpcclient/rpcclient.c | 3 +- 3 files changed, 159 insertions(+), 1 deletion(-) diff --git a/source3/rpc_client/cli_samr.c b/source3/rpc_client/cli_samr.c index e49ea268b9..389895fb58 100644 --- a/source3/rpc_client/cli_samr.c +++ b/source3/rpc_client/cli_samr.c @@ -2448,3 +2448,73 @@ BOOL samr_close(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd) return valid_close; } +/**************************************************************************** +do a SAMR query display info +****************************************************************************/ +BOOL samr_query_dispinfo(struct cli_state *cli, uint16 fnum, + POLICY_HND *pol_open_domain, uint16 level, + uint32 *num_entries, + SAM_DISPINFO_CTR *ctr) +{ + prs_struct data; + prs_struct rdata; + + SAMR_Q_QUERY_DISPINFO q_o; + BOOL valid_query = False; + + DEBUG(4,("SAMR Query Display Info. level: %d\n", level)); + + if (pol_open_domain == NULL || num_entries == NULL || ctr == NULL || + level == 0) + { + return False; + } + + /* create and send a MSRPC command with api SAMR_QUERY_DISPINFO */ + + prs_init(&data , 1024, 4, SAFETY_MARGIN, False); + prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True ); + + /* store the parameters */ + make_samr_q_query_dispinfo(&q_o, pol_open_domain, level, 0, 0xffffffff); + + /* turn parameters into data stream */ + samr_io_q_query_dispinfo("", &q_o, &data, 0); + + /* send the data on \PIPE\ */ + if (rpc_api_pipe_req(cli, fnum, SAMR_QUERY_DISPINFO, &data, &rdata)) + { + SAMR_R_QUERY_DISPINFO r_o; + BOOL p; + + /* get user info */ + r_o.ctr = ctr; + + samr_io_r_query_dispinfo("", &r_o, &rdata, 0); + p = rdata.offset != 0; + + if (p && r_o.status != 0) + { + /* report error code */ + DEBUG(0,("SAMR_R_QUERY_DISPINFO: %s\n", get_nt_error_msg(r_o.status))); + p = False; + } + + if (p && r_o.switch_level != level) + { + DEBUG(0,("SAMR_R_QUERY_DISPINFO: received incorrect level %d\n", + r_o.switch_level)); + } + + if (p && r_o.ptr_entries != 0) + { + valid_query = True; + } + } + + prs_mem_free(&data ); + prs_mem_free(&rdata ); + + return valid_query; +} + diff --git a/source3/rpcclient/cmd_samr.c b/source3/rpcclient/cmd_samr.c index f988a5af42..08dedac701 100644 --- a/source3/rpcclient/cmd_samr.c +++ b/source3/rpcclient/cmd_samr.c @@ -1576,6 +1576,93 @@ void cmd_sam_query_user(struct client_info *info) } +/**************************************************************************** +experimental SAM query display info. +****************************************************************************/ +void cmd_sam_query_dispinfo(struct client_info *info) +{ + uint16 fnum; + fstring srv_name; + fstring domain; + fstring sid; + DOM_SID sid1; + BOOL res = True; + fstring info_str; + uint16 switch_value = 1; + uint32 ace_perms = 0x304; /* absolutely no idea. */ + SAM_DISPINFO_CTR ctr; + SAM_DISPINFO_1 inf1; + uint32 num_entries; + + sid_to_string(sid, &info->dom.level5_sid); + fstrcpy(domain, info->dom.level5_dom); + + if (strlen(sid) == 0) + { + fprintf(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + return; + } + + string_to_sid(&sid1, sid); + + fstrcpy(srv_name, "\\\\"); + fstrcat(srv_name, info->dest_host); + strupper(srv_name); + + if (next_token(NULL, info_str, NULL, sizeof(info_str))) + { + switch_value = strtoul(info_str, (char**)NULL, 10); + } + + fprintf(out_hnd, "SAM Query Domain Info: info level %d\n", switch_value); + fprintf(out_hnd, "From: %s To: %s Domain: %s SID: %s\n", + info->myhostname, srv_name, domain, sid); + + /* open SAMR session. negotiate credentials */ + res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR, &fnum) : False; + + /* establish a connection. */ + res = res ? samr_connect(smb_cli, fnum, + srv_name, 0x00000020, + &info->dom.samr_pol_connect) : False; + + /* connect to the domain */ + res = res ? samr_open_domain(smb_cli, fnum, + &info->dom.samr_pol_connect, ace_perms, &sid1, + &info->dom.samr_pol_open_domain) : False; + + ctr.sam.info1 = &inf1; + + /* send a samr query_disp_info command */ + res = res ? samr_query_dispinfo(smb_cli, fnum, + &info->dom.samr_pol_open_domain, switch_value, + &num_entries, &ctr) : False; + + res = res ? samr_close(smb_cli, fnum, + &info->dom.samr_pol_connect) : False; + + res = res ? samr_close(smb_cli, fnum, + &info->dom.samr_pol_open_domain) : False; + + /* close the session */ + cli_nt_session_close(smb_cli, fnum); + + if (res) + { + DEBUG(5,("cmd_sam_query_dispinfo: succeeded\n")); +#if 0 + display_sam_disp_info_ctr(out_hnd, ACTION_HEADER , switch_value, &ctr); + display_sam_disp_info_ctr(out_hnd, ACTION_ENUMERATE, switch_value, &ctr); + display_sam_disp_info_ctr(out_hnd, ACTION_FOOTER , switch_value, &ctr); +#endif + } + else + { + DEBUG(5,("cmd_sam_query_dispinfo: failed\n")); + } +} + + /**************************************************************************** experimental SAM domain info query. ****************************************************************************/ diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c index c598777426..f33f0fa1dd 100644 --- a/source3/rpcclient/rpcclient.c +++ b/source3/rpcclient/rpcclient.c @@ -145,7 +145,8 @@ struct {"samtest", cmd_sam_test , "SAM User Encrypted RPC test (experimental!)"}, {"enumaliases",cmd_sam_enum_aliases, "SAM Aliases Database Query (experimental!)"}, {"enumgroups", cmd_sam_enum_groups, "SAM Group Database Query (experimental!)"}, - {"dominfo", cmd_sam_query_dominfo, "SAM Query Domain Info(experimental!)"}, + {"dominfo", cmd_sam_query_dominfo, "SAM Query Domain Info"}, + {"dispinfo", cmd_sam_query_dispinfo, "SAM Query Display Info"}, {"querysecret", cmd_lsa_query_secret, "LSA Query Secret (developer use)"}, {"samsync", cmd_sam_sync, "SAM Synchronization Test (experimental)"}, {"quit", cmd_quit, "logoff the server"}, -- cgit