1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-25 23:21:54 +03:00

get rid of the old rpcclient code - it needs to be rewritten to use the new rpc infrastructure

This commit is contained in:
Andrew Tridgell 0001-01-01 00:00:00 +00:00
parent 8c49669dbe
commit c9163d5e05
12 changed files with 0 additions and 7598 deletions

View File

@ -1,237 +0,0 @@
/*
Unix SMB/CIFS implementation.
RPC pipe client
Copyright (C) Tim Potter 2000
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "rpcclient.h"
/* Check DFS is supported by the remote server */
static NTSTATUS cmd_dfs_exist(struct cli_state *cli, TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
BOOL dfs_exists;
NTSTATUS result;
if (argc != 1) {
printf("Usage: %s\n", argv[0]);
return NT_STATUS_OK;
}
result = cli_dfs_exist(cli, mem_ctx, &dfs_exists);
if (NT_STATUS_IS_OK(result))
printf("dfs is %spresent\n", dfs_exists ? "" : "not ");
return result;
}
static NTSTATUS cmd_dfs_add(struct cli_state *cli, TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
NTSTATUS result;
const char *entrypath, *servername, *sharename, *comment;
uint32 flags = 0;
if (argc != 5) {
printf("Usage: %s entrypath servername sharename comment\n",
argv[0]);
return NT_STATUS_OK;
}
entrypath = argv[1];
servername = argv[2];
sharename = argv[3];
comment = argv[4];
result = cli_dfs_add(cli, mem_ctx, entrypath, servername,
sharename, comment, flags);
return result;
}
static NTSTATUS cmd_dfs_remove(struct cli_state *cli, TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
NTSTATUS result;
const char *entrypath, *servername, *sharename;
if (argc != 4) {
printf("Usage: %s entrypath servername sharename\n", argv[0]);
return NT_STATUS_OK;
}
entrypath = argv[1];
servername = argv[2];
sharename = argv[3];
result = cli_dfs_remove(cli, mem_ctx, entrypath, servername,
sharename);
return result;
}
/* Display a DFS_INFO_1 structure */
static void display_dfs_info_1(DFS_INFO_1 *info1)
{
fstring temp;
unistr2_to_ascii(temp, &info1->entrypath, sizeof(temp) - 1);
printf("entrypath: %s\n", temp);
}
/* Display a DFS_INFO_2 structure */
static void display_dfs_info_2(DFS_INFO_2 *info2)
{
fstring temp;
unistr2_to_ascii(temp, &info2->entrypath, sizeof(temp) - 1);
printf("entrypath: %s\n", temp);
unistr2_to_ascii(temp, &info2->comment, sizeof(temp) - 1);
printf("\tcomment: %s\n", temp);
printf("\tstate: %d\n", info2->state);
printf("\tnum_storages: %d\n", info2->num_storages);
}
/* Display a DFS_INFO_3 structure */
static void display_dfs_info_3(DFS_INFO_3 *info3)
{
fstring temp;
int i;
unistr2_to_ascii(temp, &info3->entrypath, sizeof(temp) - 1);
printf("entrypath: %s\n", temp);
unistr2_to_ascii(temp, &info3->comment, sizeof(temp) - 1);
printf("\tcomment: %s\n", temp);
printf("\tstate: %d\n", info3->state);
printf("\tnum_storages: %d\n", info3->num_storages);
for (i = 0; i < info3->num_storages; i++) {
DFS_STORAGE_INFO *dsi = &info3->storages[i];
unistr2_to_ascii(temp, &dsi->servername, sizeof(temp) - 1);
printf("\t\tstorage[%d] servername: %s\n", i, temp);
unistr2_to_ascii(temp, &dsi->sharename, sizeof(temp) - 1);
printf("\t\tstorage[%d] sharename: %s\n", i, temp);
}
}
/* Display a DFS_INFO_CTR structure */
static void display_dfs_info_ctr(DFS_INFO_CTR *ctr)
{
int i;
for (i = 0; i < ctr->num_entries; i++) {
switch (ctr->switch_value) {
case 0x01:
display_dfs_info_1(&ctr->dfs.info1[i]);
break;
case 0x02:
display_dfs_info_2(&ctr->dfs.info2[i]);
break;
case 0x03:
display_dfs_info_3(&ctr->dfs.info3[i]);
break;
default:
printf("unsupported info level %d\n",
ctr->switch_value);
break;
}
}
}
/* Enumerate dfs shares */
static NTSTATUS cmd_dfs_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
DFS_INFO_CTR ctr;
NTSTATUS result;
uint32 info_level = 1;
if (argc > 2) {
printf("Usage: %s [info_level]\n", argv[0]);
return NT_STATUS_OK;
}
if (argc == 2)
info_level = atoi(argv[1]);
result = cli_dfs_enum(cli, mem_ctx, info_level, &ctr);
if (NT_STATUS_IS_OK(result))
display_dfs_info_ctr(&ctr);
return result;
}
static NTSTATUS cmd_dfs_getinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
NTSTATUS result;
const char *entrypath, *servername, *sharename;
uint32 info_level = 1;
DFS_INFO_CTR ctr;
if (argc < 4 || argc > 5) {
printf("Usage: %s entrypath servername sharename "
"[info_level]\n", argv[0]);
return NT_STATUS_OK;
}
entrypath = argv[1];
servername = argv[2];
sharename = argv[3];
if (argc == 5)
info_level = atoi(argv[4]);
result = cli_dfs_get_info(cli, mem_ctx, entrypath, servername,
sharename, info_level, &ctr);
if (NT_STATUS_IS_OK(result))
display_dfs_info_ctr(&ctr);
return result;
}
/* List of commands exported by this module */
struct cmd_set dfs_commands[] = {
{ "DFS" },
{ "dfsexist", cmd_dfs_exist, PI_NETDFS, "Query DFS support", "" },
{ "dfsadd", cmd_dfs_add, PI_NETDFS, "Add a DFS share", "" },
{ "dfsremove", cmd_dfs_remove, PI_NETDFS, "Remove a DFS share", "" },
{ "dfsgetinfo", cmd_dfs_getinfo, PI_NETDFS, "Query DFS share info", "" },
{ "dfsenum", cmd_dfs_enum, PI_NETDFS, "Enumerate dfs shares", "" },
{ NULL }
};

View File

@ -1,59 +0,0 @@
/*
Unix SMB/CIFS implementation.
RPC pipe client
Copyright (C) Gerald Carter 2002
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "rpcclient.h"
/* Look up domain related information on a remote host */
static NTSTATUS cmd_ds_dsrole_getprimarydominfo(struct cli_state *cli,
TALLOC_CTX *mem_ctx, int argc,
const char **argv)
{
NTSTATUS result;
DS_DOMINFO_CTR ctr;
result = cli_ds_getprimarydominfo( cli, mem_ctx, DsRolePrimaryDomainInfoBasic, &ctr );
if ( NT_STATUS_IS_OK(result) )
{
printf ("Machine Role = [%d]\n", ctr.basic->machine_role);
if ( ctr.basic->flags & DSROLE_PRIMARY_DS_RUNNING ) {
printf( "Directory Service is running.\n");
printf( "Domain is in %s mode.\n", (ctr.basic->flags & DSROLE_PRIMARY_DS_MIXED_MODE) ? "mixed" : "native" );
}
else
printf( "Directory Service not running on server\n");
}
return result;
}
/* List of commands exported by this module */
struct cmd_set ds_commands[] = {
{ "LSARPC-DS" },
{ "dsroledominfo", cmd_ds_dsrole_getprimarydominfo, PI_LSARPC_DS, "Get Primary Domain Information", "" },
{ NULL }
};

View File

@ -1,760 +0,0 @@
/*
Unix SMB/CIFS implementation.
RPC pipe client
Copyright (C) Tim Potter 2000
Copyright (C) Rafal Szczesniak 2002
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "rpcclient.h"
/* useful function to allow entering a name instead of a SID and
* looking it up automatically */
static NTSTATUS name_to_sid(struct cli_state *cli,
TALLOC_CTX *mem_ctx,
DOM_SID *sid, const char *name)
{
POLICY_HND pol;
uint32 *sid_types;
NTSTATUS result;
DOM_SID *sids;
/* maybe its a raw SID */
if (strncmp(name, "S-", 2) == 0 &&
string_to_sid(sid, name)) {
return NT_STATUS_OK;
}
result = cli_lsa_open_policy(cli, mem_ctx, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&pol);
if (!NT_STATUS_IS_OK(result))
goto done;
result = cli_lsa_lookup_names(cli, mem_ctx, &pol, 1, &name, &sids, &sid_types);
if (!NT_STATUS_IS_OK(result))
goto done;
cli_lsa_close(cli, mem_ctx, &pol);
*sid = sids[0];
done:
return result;
}
/* Look up domain related information on a remote host */
static NTSTATUS cmd_lsa_query_info_policy(struct cli_state *cli,
TALLOC_CTX *mem_ctx, int argc,
const char **argv)
{
POLICY_HND pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
DOM_SID dom_sid;
GUID dom_guid;
fstring sid_str, domain_name="", dns_name="", forest_name="";
uint32 info_class = 3;
if (argc > 2) {
printf("Usage: %s [info_class]\n", argv[0]);
return NT_STATUS_OK;
}
if (argc == 2)
info_class = atoi(argv[1]);
/* Lookup info policy */
switch (info_class) {
case 12:
result = cli_lsa_open_policy2(cli, mem_ctx, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&pol);
if (!NT_STATUS_IS_OK(result))
goto done;
result = cli_lsa_query_info_policy2(cli, mem_ctx, &pol,
info_class, domain_name,
dns_name, forest_name,
&dom_guid, &dom_sid);
break;
default:
result = cli_lsa_open_policy(cli, mem_ctx, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&pol);
if (!NT_STATUS_IS_OK(result))
goto done;
result = cli_lsa_query_info_policy(cli, mem_ctx, &pol,
info_class, domain_name,
&dom_sid);
}
if (!NT_STATUS_IS_OK(result))
goto done;
sid_to_string(sid_str, &dom_sid);
if (domain_name[0])
printf("domain %s has sid %s\n", domain_name, sid_str);
else
printf("could not query info for level %d\n", info_class);
if (dns_name[0])
printf("domain dns name is %s\n", dns_name);
if (forest_name[0])
printf("forest name is %s\n", forest_name);
if (info_class == 12) {
printf("domain GUID is ");
print_guid(&dom_guid);
}
done:
return result;
}
/* Resolve a list of names to a list of sids */
static NTSTATUS cmd_lsa_lookup_names(struct cli_state *cli,
TALLOC_CTX *mem_ctx, int argc,
const char **argv)
{
POLICY_HND pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
DOM_SID *sids;
uint32 *types;
int i;
if (argc == 1) {
printf("Usage: %s [name1 [name2 [...]]]\n", argv[0]);
return NT_STATUS_OK;
}
result = cli_lsa_open_policy(cli, mem_ctx, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&pol);
if (!NT_STATUS_IS_OK(result))
goto done;
result = cli_lsa_lookup_names(cli, mem_ctx, &pol, argc - 1,
(const char**)(argv + 1), &sids, &types);
if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) !=
NT_STATUS_V(STATUS_SOME_UNMAPPED))
goto done;
result = NT_STATUS_OK;
/* Print results */
for (i = 0; i < (argc - 1); i++) {
fstring sid_str;
sid_to_string(sid_str, &sids[i]);
printf("%s %s (%s: %d)\n", argv[i + 1], sid_str,
sid_type_lookup(types[i]), types[i]);
}
done:
return result;
}
/* Resolve a list of SIDs to a list of names */
static NTSTATUS cmd_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
POLICY_HND pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
DOM_SID *sids;
char **domains;
char **names;
uint32 *types;
int i;
if (argc == 1) {
printf("Usage: %s [sid1 [sid2 [...]]]\n", argv[0]);
return NT_STATUS_OK;
}
result = cli_lsa_open_policy(cli, mem_ctx, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&pol);
if (!NT_STATUS_IS_OK(result))
goto done;
/* Convert arguments to sids */
sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * (argc - 1));
if (!sids) {
printf("could not allocate memory for %d sids\n", argc - 1);
goto done;
}
for (i = 0; i < argc - 1; i++)
if (!string_to_sid(&sids[i], argv[i + 1])) {
result = NT_STATUS_INVALID_SID;
goto done;
}
/* Lookup the SIDs */
result = cli_lsa_lookup_sids(cli, mem_ctx, &pol, argc - 1, sids,
&domains, &names, &types);
if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) !=
NT_STATUS_V(STATUS_SOME_UNMAPPED))
goto done;
result = NT_STATUS_OK;
/* Print results */
for (i = 0; i < (argc - 1); i++) {
fstring sid_str;
sid_to_string(sid_str, &sids[i]);
printf("%s %s\\%s (%d)\n", sid_str,
domains[i] ? domains[i] : "*unknown*",
names[i] ? names[i] : "*unknown*", types[i]);
}
done:
return result;
}
/* Enumerate list of trusted domains */
static NTSTATUS cmd_lsa_enum_trust_dom(struct cli_state *cli,
TALLOC_CTX *mem_ctx, int argc,
const char **argv)
{
POLICY_HND pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
DOM_SID *domain_sids;
char **domain_names;
/* defaults, but may be changed using params */
uint32 enum_ctx = 0;
uint32 num_domains = 0;
int i;
if (argc > 2) {
printf("Usage: %s [enum context (0)]\n", argv[0]);
return NT_STATUS_OK;
}
if (argc == 2 && argv[1]) {
enum_ctx = atoi(argv[2]);
}
result = cli_lsa_open_policy(cli, mem_ctx, True,
POLICY_VIEW_LOCAL_INFORMATION,
&pol);
if (!NT_STATUS_IS_OK(result))
goto done;
/* Lookup list of trusted domains */
result = cli_lsa_enum_trust_dom(cli, mem_ctx, &pol, &enum_ctx,
&num_domains,
&domain_names, &domain_sids);
if (!NT_STATUS_IS_OK(result) &&
!NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) &&
!NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES))
goto done;
/* Print results: list of names and sids returned in this response. */
for (i = 0; i < num_domains; i++) {
fstring sid_str;
sid_to_string(sid_str, &domain_sids[i]);
printf("%s %s\n", domain_names[i] ? domain_names[i] :
"*unknown*", sid_str);
}
done:
return result;
}
/* Enumerates privileges */
static NTSTATUS cmd_lsa_enum_privilege(struct cli_state *cli,
TALLOC_CTX *mem_ctx, int argc,
const char **argv)
{
POLICY_HND pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
uint32 enum_context=0;
uint32 pref_max_length=0x1000;
uint32 count=0;
char **privs_name;
uint32 *privs_high;
uint32 *privs_low;
int i;
if (argc > 3) {
printf("Usage: %s [enum context] [max length]\n", argv[0]);
return NT_STATUS_OK;
}
if (argc>=2)
enum_context=atoi(argv[1]);
if (argc==3)
pref_max_length=atoi(argv[2]);
result = cli_lsa_open_policy(cli, mem_ctx, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&pol);
if (!NT_STATUS_IS_OK(result))
goto done;
result = cli_lsa_enum_privilege(cli, mem_ctx, &pol, &enum_context, pref_max_length,
&count, &privs_name, &privs_high, &privs_low);
if (!NT_STATUS_IS_OK(result))
goto done;
/* Print results */
printf("found %d privileges\n\n", count);
for (i = 0; i < count; i++) {
printf("%s \t\t%d:%d (0x%x:0x%x)\n", privs_name[i] ? privs_name[i] : "*unknown*",
privs_high[i], privs_low[i], privs_high[i], privs_low[i]);
}
done:
return result;
}
/* Get privilege name */
static NTSTATUS cmd_lsa_get_dispname(struct cli_state *cli,
TALLOC_CTX *mem_ctx, int argc,
const char **argv)
{
POLICY_HND pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
uint16 lang_id=0;
uint16 lang_id_sys=0;
uint16 lang_id_desc;
fstring description;
if (argc != 2) {
printf("Usage: %s privilege name\n", argv[0]);
return NT_STATUS_OK;
}
result = cli_lsa_open_policy(cli, mem_ctx, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&pol);
if (!NT_STATUS_IS_OK(result))
goto done;
result = cli_lsa_get_dispname(cli, mem_ctx, &pol, argv[1], lang_id, lang_id_sys, description, &lang_id_desc);
if (!NT_STATUS_IS_OK(result))
goto done;
/* Print results */
printf("%s -> %s (language: 0x%x)\n", argv[1], description, lang_id_desc);
done:
return result;
}
/* Enumerate the LSA SIDS */
static NTSTATUS cmd_lsa_enum_sids(struct cli_state *cli,
TALLOC_CTX *mem_ctx, int argc,
const char **argv)
{
POLICY_HND pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
uint32 enum_context=0;
uint32 pref_max_length=0x1000;
DOM_SID *sids;
uint32 count=0;
int i;
if (argc > 3) {
printf("Usage: %s [enum context] [max length]\n", argv[0]);
return NT_STATUS_OK;
}
if (argc>=2)
enum_context=atoi(argv[1]);
if (argc==3)
pref_max_length=atoi(argv[2]);
result = cli_lsa_open_policy(cli, mem_ctx, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&pol);
if (!NT_STATUS_IS_OK(result))
goto done;
result = cli_lsa_enum_sids(cli, mem_ctx, &pol, &enum_context, pref_max_length,
&count, &sids);
if (!NT_STATUS_IS_OK(result))
goto done;
/* Print results */
printf("found %d SIDs\n\n", count);
for (i = 0; i < count; i++) {
fstring sid_str;
sid_to_string(sid_str, &sids[i]);
printf("%s\n", sid_str);
}
done:
return result;
}
/* Enumerate the privileges of an SID */
static NTSTATUS cmd_lsa_enum_privsaccounts(struct cli_state *cli,
TALLOC_CTX *mem_ctx, int argc,
const char **argv)
{
POLICY_HND dom_pol;
POLICY_HND user_pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
uint32 access_desired = 0x000f000f;
DOM_SID sid;
uint32 count=0;
LUID_ATTR *set;
int i;
if (argc != 2 ) {
printf("Usage: %s SID\n", argv[0]);
return NT_STATUS_OK;
}
result = name_to_sid(cli, mem_ctx, &sid, argv[1]);
if (!NT_STATUS_IS_OK(result))
goto done;
result = cli_lsa_open_policy2(cli, mem_ctx, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&dom_pol);
if (!NT_STATUS_IS_OK(result))
goto done;
result = cli_lsa_open_account(cli, mem_ctx, &dom_pol, &sid, access_desired, &user_pol);
if (!NT_STATUS_IS_OK(result))
goto done;
result = cli_lsa_enum_privsaccount(cli, mem_ctx, &user_pol, &count, &set);
if (!NT_STATUS_IS_OK(result))
goto done;
/* Print results */
printf("found %d privileges for SID %s\n\n", count, argv[1]);
printf("high\tlow\tattribute\n");
for (i = 0; i < count; i++) {
printf("%u\t%u\t%u\n", set[i].luid.high, set[i].luid.low, set[i].attr);
}
done:
return result;
}
/* Enumerate the privileges of an SID via LsaEnumerateAccountRights */
static NTSTATUS cmd_lsa_enum_acct_rights(struct cli_state *cli,
TALLOC_CTX *mem_ctx, int argc,
const char **argv)
{
POLICY_HND dom_pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
DOM_SID sid;
uint32 count;
char **rights;
int i;
if (argc != 2 ) {
printf("Usage: %s SID\n", argv[0]);
return NT_STATUS_OK;
}
result = name_to_sid(cli, mem_ctx, &sid, argv[1]);
if (!NT_STATUS_IS_OK(result))
goto done;
result = cli_lsa_open_policy2(cli, mem_ctx, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&dom_pol);
if (!NT_STATUS_IS_OK(result))
goto done;
result = cli_lsa_enum_account_rights(cli, mem_ctx, &dom_pol, sid, &count, &rights);
if (!NT_STATUS_IS_OK(result))
goto done;
printf("found %d privileges for SID %s\n", count, sid_string_static(&sid));
for (i = 0; i < count; i++) {
printf("\t%s\n", rights[i]);
}
done:
return result;
}
/* Enumerate the accounts with a specific right */
static NTSTATUS cmd_lsa_enum_acct_with_right(struct cli_state *cli,
TALLOC_CTX *mem_ctx, int argc,
const char **argv)
{
POLICY_HND dom_pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
DOM_SID *sids;
uint32 count;
const char *right;
int i;
if (argc != 2 ) {
printf("Usage: %s <RIGHT>\n", argv[0]);
return NT_STATUS_OK;
}
right = argv[1];
result = cli_lsa_open_policy2(cli, mem_ctx, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&dom_pol);
if (!NT_STATUS_IS_OK(result))
goto done;
result = cli_lsa_enum_account_with_right(cli, mem_ctx, &dom_pol, right, &count, &sids);
if (!NT_STATUS_IS_OK(result))
goto done;
printf("found %d SIDs for '%s'\n", count, right);
for (i = 0; i < count; i++) {
printf("\t%s\n", sid_string_static(&sids[i]));
}
done:
return result;
}
/* add some privileges to a SID via LsaAddAccountRights */
static NTSTATUS cmd_lsa_add_acct_rights(struct cli_state *cli,
TALLOC_CTX *mem_ctx, int argc,
const char **argv)
{
POLICY_HND dom_pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
DOM_SID sid;
if (argc < 3 ) {
printf("Usage: %s SID [rights...]\n", argv[0]);
return NT_STATUS_OK;
}
result = name_to_sid(cli, mem_ctx, &sid, argv[1]);
if (!NT_STATUS_IS_OK(result))
goto done;
result = cli_lsa_open_policy2(cli, mem_ctx, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&dom_pol);
if (!NT_STATUS_IS_OK(result))
goto done;
result = cli_lsa_add_account_rights(cli, mem_ctx, &dom_pol, sid,
argc-2, argv+2);
if (!NT_STATUS_IS_OK(result))
goto done;
done:
return result;
}
/* remove some privileges to a SID via LsaRemoveAccountRights */
static NTSTATUS cmd_lsa_remove_acct_rights(struct cli_state *cli,
TALLOC_CTX *mem_ctx, int argc,
const char **argv)
{
POLICY_HND dom_pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
DOM_SID sid;
if (argc < 3 ) {
printf("Usage: %s SID [rights...]\n", argv[0]);
return NT_STATUS_OK;
}
result = name_to_sid(cli, mem_ctx, &sid, argv[1]);
if (!NT_STATUS_IS_OK(result))
goto done;
result = cli_lsa_open_policy2(cli, mem_ctx, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&dom_pol);
if (!NT_STATUS_IS_OK(result))
goto done;
result = cli_lsa_remove_account_rights(cli, mem_ctx, &dom_pol, sid,
False, argc-2, argv+2);
if (!NT_STATUS_IS_OK(result))
goto done;
done:
return result;
}
/* Get a privilege value given its name */
static NTSTATUS cmd_lsa_lookupprivvalue(struct cli_state *cli,
TALLOC_CTX *mem_ctx, int argc,
const char **argv)
{
POLICY_HND pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
LUID luid;
if (argc != 2 ) {
printf("Usage: %s name\n", argv[0]);
return NT_STATUS_OK;
}
result = cli_lsa_open_policy2(cli, mem_ctx, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&pol);
if (!NT_STATUS_IS_OK(result))
goto done;
result = cli_lsa_lookupprivvalue(cli, mem_ctx, &pol, argv[1], &luid);
if (!NT_STATUS_IS_OK(result))
goto done;
/* Print results */
printf("%u:%u (0x%x:0x%x)\n", luid.high, luid.low, luid.high, luid.low);
done:
return result;
}
/* Query LSA security object */
static NTSTATUS cmd_lsa_query_secobj(struct cli_state *cli,
TALLOC_CTX *mem_ctx, int argc,
const char **argv)
{
POLICY_HND pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
SEC_DESC_BUF *sdb;
uint32 sec_info = 0x00000004; /* ??? */
if (argc != 1 ) {
printf("Usage: %s\n", argv[0]);
return NT_STATUS_OK;
}
result = cli_lsa_open_policy2(cli, mem_ctx, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&pol);
if (!NT_STATUS_IS_OK(result))
goto done;
result = cli_lsa_query_secobj(cli, mem_ctx, &pol, sec_info, &sdb);
if (!NT_STATUS_IS_OK(result))
goto done;
/* Print results */
display_sec_desc(sdb->sec);
done:
return result;
}
/* List of commands exported by this module */
struct cmd_set lsarpc_commands[] = {
{ "LSARPC" },
{ "lsaquery", cmd_lsa_query_info_policy, PI_LSARPC, "Query info policy", "" },
{ "lookupsids", cmd_lsa_lookup_sids, PI_LSARPC, "Convert SIDs to names", "" },
{ "lookupnames", cmd_lsa_lookup_names, PI_LSARPC, "Convert names to SIDs", "" },
{ "enumtrust", cmd_lsa_enum_trust_dom, PI_LSARPC, "Enumerate trusted domains", "Usage: [preferred max number] [enum context (0)]" },
{ "enumprivs", cmd_lsa_enum_privilege, PI_LSARPC, "Enumerate privileges", "" },
{ "getdispname", cmd_lsa_get_dispname, PI_LSARPC, "Get the privilege name", "" },
{ "lsaenumsid", cmd_lsa_enum_sids, PI_LSARPC, "Enumerate the LSA SIDS", "" },
{ "lsaenumprivsaccount", cmd_lsa_enum_privsaccounts, PI_LSARPC, "Enumerate the privileges of an SID", "" },
{ "lsaenumacctrights", cmd_lsa_enum_acct_rights, PI_LSARPC, "Enumerate the rights of an SID", "" },
{ "lsaenumacctwithright",cmd_lsa_enum_acct_with_right,PI_LSARPC,"Enumerate accounts with a right", "" },
{ "lsaaddacctrights", cmd_lsa_add_acct_rights, PI_LSARPC, "Add rights to an account", "" },
{ "lsaremoveacctrights", cmd_lsa_remove_acct_rights, PI_LSARPC, "Remove rights from an account", "" },
{ "lsalookupprivvalue", cmd_lsa_lookupprivvalue, PI_LSARPC, "Get a privilege value given its name", "" },
{ "lsaquerysecobj", cmd_lsa_query_secobj, PI_LSARPC, "Query LSA security object", "" },
{ NULL }
};

View File

@ -1,342 +0,0 @@
/*
Unix SMB/CIFS implementation.
RPC pipe client
Copyright (C) Tim Potter 2000
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "rpcclient.h"
static NTSTATUS cmd_netlogon_logon_ctrl2(struct cli_state *cli,
TALLOC_CTX *mem_ctx, int argc,
const char **argv)
{
uint32 query_level = 1;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
if (argc > 1) {
fprintf(stderr, "Usage: %s\n", argv[0]);
return NT_STATUS_OK;
}
result = cli_netlogon_logon_ctrl2(cli, mem_ctx, query_level);
if (!NT_STATUS_IS_OK(result))
goto done;
/* Display results */
done:
return result;
}
static NTSTATUS cmd_netlogon_logon_ctrl(struct cli_state *cli,
TALLOC_CTX *mem_ctx, int argc,
const char **argv)
{
#if 0
uint32 query_level = 1;
#endif
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
if (argc > 1) {
fprintf(stderr, "Usage: %s\n", argv[0]);
return NT_STATUS_OK;
}
#if 0
result = cli_netlogon_logon_ctrl(cli, mem_ctx, query_level);
if (!NT_STATUS_IS_OK(result)) {
goto done;
}
#endif
/* Display results */
return result;
}
/* Display sam synchronisation information */
static void display_sam_sync(uint32 num_deltas, SAM_DELTA_HDR *hdr_deltas,
SAM_DELTA_CTR *deltas)
{
fstring name;
uint32 i, j;
for (i = 0; i < num_deltas; i++) {
switch (hdr_deltas[i].type) {
case SAM_DELTA_DOMAIN_INFO:
unistr2_to_ascii(name,
&deltas[i].domain_info.uni_dom_name,
sizeof(name) - 1);
printf("Domain: %s\n", name);
break;
case SAM_DELTA_GROUP_INFO:
unistr2_to_ascii(name,
&deltas[i].group_info.uni_grp_name,
sizeof(name) - 1);
printf("Group: %s\n", name);
break;
case SAM_DELTA_ACCOUNT_INFO:
unistr2_to_ascii(name,
&deltas[i].account_info.uni_acct_name,
sizeof(name) - 1);
printf("Account: %s\n", name);
break;
case SAM_DELTA_ALIAS_INFO:
unistr2_to_ascii(name,
&deltas[i].alias_info.uni_als_name,
sizeof(name) - 1);
printf("Alias: %s\n", name);
break;
case SAM_DELTA_ALIAS_MEM: {
SAM_ALIAS_MEM_INFO *alias = &deltas[i].als_mem_info;
for (j = 0; j < alias->num_members; j++) {
fstring sid_str;
sid_to_string(sid_str, &alias->sids[j].sid);
printf("%s\n", sid_str);
}
break;
}
case SAM_DELTA_GROUP_MEM: {
SAM_GROUP_MEM_INFO *group = &deltas[i].grp_mem_info;
for (j = 0; j < group->num_members; j++)
printf("rid 0x%x, attrib 0x%08x\n",
group->rids[j], group->attribs[j]);
break;
}
case SAM_DELTA_MODIFIED_COUNT: {
SAM_DELTA_MOD_COUNT *mc = &deltas[i].mod_count;
printf("sam sequence update: 0x%04x\n", mc->seqnum);
break;
}
default:
printf("unknown delta type 0x%02x\n",
hdr_deltas[i].type);
break;
}
}
}
/* Perform sam synchronisation */
static NTSTATUS cmd_netlogon_sam_sync(struct cli_state *cli,
TALLOC_CTX *mem_ctx, int argc,
const char **argv)
{
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
unsigned char trust_passwd[16];
uint32 database_id = 0, num_deltas;
SAM_DELTA_HDR *hdr_deltas;
SAM_DELTA_CTR *deltas;
DOM_CRED ret_creds;
uint32 neg_flags = 0x000001ff;
if (argc > 2) {
fprintf(stderr, "Usage: %s [database_id]\n", argv[0]);
return NT_STATUS_OK;
}
if (argc == 2)
database_id = atoi(argv[1]);
if (!secrets_init()) {
fprintf(stderr, "Unable to initialise secrets database\n");
return result;
}
/* Initialise session credentials */
if (!secrets_fetch_trust_account_password(lp_workgroup(), trust_passwd,
NULL)) {
fprintf(stderr, "could not fetch trust account password\n");
goto done;
}
result = cli_nt_setup_creds(cli, get_sec_chan(), trust_passwd, &neg_flags, 2);
if (!NT_STATUS_IS_OK(result)) {
fprintf(stderr, "Error initialising session creds\n");
goto done;
}
/* on first call the returnAuthenticator is empty */
memset(&ret_creds, 0, sizeof(ret_creds));
/* Synchronise sam database */
result = cli_netlogon_sam_sync(cli, mem_ctx, &ret_creds, database_id,
0, &num_deltas, &hdr_deltas, &deltas);
if (!NT_STATUS_IS_OK(result))
goto done;
/* Display results */
display_sam_sync(num_deltas, hdr_deltas, deltas);
done:
return result;
}
/* Perform sam delta synchronisation */
static NTSTATUS cmd_netlogon_sam_deltas(struct cli_state *cli,
TALLOC_CTX *mem_ctx, int argc,
const char **argv)
{
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
unsigned char trust_passwd[16];
uint32 database_id, num_deltas, tmp;
SAM_DELTA_HDR *hdr_deltas;
SAM_DELTA_CTR *deltas;
UINT64_S seqnum;
uint32 neg_flags = 0x000001ff;
if (argc != 3) {
fprintf(stderr, "Usage: %s database_id seqnum\n", argv[0]);
return NT_STATUS_OK;
}
database_id = atoi(argv[1]);
tmp = atoi(argv[2]);
seqnum.low = tmp & 0xffff;
seqnum.high = 0;
if (!secrets_init()) {
fprintf(stderr, "Unable to initialise secrets database\n");
goto done;
}
/* Initialise session credentials */
if (!secrets_fetch_trust_account_password(lp_workgroup(), trust_passwd,
NULL)) {
fprintf(stderr, "could not fetch trust account password\n");
goto done;
}
result = cli_nt_setup_creds(cli, get_sec_chan(), trust_passwd, &neg_flags, 2);
if (!NT_STATUS_IS_OK(result)) {
fprintf(stderr, "Error initialising session creds\n");
goto done;
}
/* Synchronise sam database */
result = cli_netlogon_sam_deltas(cli, mem_ctx, database_id,
seqnum, &num_deltas,
&hdr_deltas, &deltas);
if (!NT_STATUS_IS_OK(result))
goto done;
/* Display results */
display_sam_sync(num_deltas, hdr_deltas, deltas);
done:
return result;
}
/* Log on a domain user */
static NTSTATUS cmd_netlogon_sam_logon(struct cli_state *cli,
TALLOC_CTX *mem_ctx, int argc,
const char **argv)
{
unsigned char trust_passwd[16];
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
int logon_type = NET_LOGON_TYPE;
const char *username, *password;
uint32 neg_flags = 0x000001ff;
int auth_level = 2;
/* Check arguments */
if (argc < 3 || argc > 6) {
fprintf(stderr, "Usage: samlogon <username> <password> "
"[logon_type] [neg flags] [auth level (2 or 3)]\n"
"neg flags being 0x000001ff or 0x6007ffff\n");
return NT_STATUS_OK;
}
username = argv[1];
password = argv[2];
if (argc == 4)
sscanf(argv[3], "%i", &logon_type);
if (argc == 5)
sscanf(argv[4], "%i", &neg_flags);
if (argc == 6)
sscanf(argv[5], "%i", &auth_level);
/* Authenticate ourselves with the domain controller */
if (!secrets_init()) {
fprintf(stderr, "Unable to initialise secrets database\n");
return result;
}
if (!secrets_fetch_trust_account_password(lp_workgroup(), trust_passwd, NULL)) {
fprintf(stderr, "could not fetch trust account password\n");
goto done;
}
result = cli_nt_setup_creds(cli, get_sec_chan(), trust_passwd, &neg_flags, auth_level);
if (!NT_STATUS_IS_OK(result)) {
fprintf(stderr, "Error initialising session creds\n");
goto done;
}
/* Perform the sam logon */
result = cli_netlogon_sam_logon(cli, mem_ctx, username, password, logon_type);
if (!NT_STATUS_IS_OK(result))
goto done;
done:
return result;
}
/* List of commands exported by this module */
struct cmd_set netlogon_commands[] = {
{ "NETLOGON" },
{ "logonctrl2", cmd_netlogon_logon_ctrl2, PI_NETLOGON, "Logon Control 2", "" },
{ "logonctrl", cmd_netlogon_logon_ctrl, PI_NETLOGON, "Logon Control", "" },
{ "samsync", cmd_netlogon_sam_sync, PI_NETLOGON, "Sam Synchronisation", "" },
{ "samdeltas", cmd_netlogon_sam_deltas, PI_NETLOGON, "Query Sam Deltas", "" },
{ "samlogon", cmd_netlogon_sam_logon, PI_NETLOGON, "Sam Logon", "" },
{ NULL }
};

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,361 +0,0 @@
/*
Unix SMB/CIFS implementation.
RPC pipe client
Copyright (C) Andrew Tridgell 1992-1999
Copyright (C) Luke Kenneth Casson Leighton 1996 - 1999
Copyright (C) Tim Potter 2000,2002
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "rpcclient.h"
/* Display server query info */
static char *get_server_type_str(uint32 type)
{
static fstring typestr;
int i;
if (type == SV_TYPE_ALL) {
fstrcpy(typestr, "All");
return typestr;
}
typestr[0] = 0;
for (i = 0; i < 32; i++) {
if (type & (1 << i)) {
switch (1 << i) {
case SV_TYPE_WORKSTATION:
fstrcat(typestr, "Wk ");
break;
case SV_TYPE_SERVER:
fstrcat(typestr, "Sv ");
break;
case SV_TYPE_SQLSERVER:
fstrcat(typestr, "Sql ");
break;
case SV_TYPE_DOMAIN_CTRL:
fstrcat(typestr, "PDC ");
break;
case SV_TYPE_DOMAIN_BAKCTRL:
fstrcat(typestr, "BDC ");
break;
case SV_TYPE_TIME_SOURCE:
fstrcat(typestr, "Tim ");
break;
case SV_TYPE_AFP:
fstrcat(typestr, "AFP ");
break;
case SV_TYPE_NOVELL:
fstrcat(typestr, "Nov ");
break;
case SV_TYPE_DOMAIN_MEMBER:
fstrcat(typestr, "Dom ");
break;
case SV_TYPE_PRINTQ_SERVER:
fstrcat(typestr, "PrQ ");
break;
case SV_TYPE_DIALIN_SERVER:
fstrcat(typestr, "Din ");
break;
case SV_TYPE_SERVER_UNIX:
fstrcat(typestr, "Unx ");
break;
case SV_TYPE_NT:
fstrcat(typestr, "NT ");
break;
case SV_TYPE_WFW:
fstrcat(typestr, "Wfw ");
break;
case SV_TYPE_SERVER_MFPN:
fstrcat(typestr, "Mfp ");
break;
case SV_TYPE_SERVER_NT:
fstrcat(typestr, "SNT ");
break;
case SV_TYPE_POTENTIAL_BROWSER:
fstrcat(typestr, "PtB ");
break;
case SV_TYPE_BACKUP_BROWSER:
fstrcat(typestr, "BMB ");
break;
case SV_TYPE_MASTER_BROWSER:
fstrcat(typestr, "LMB ");
break;
case SV_TYPE_DOMAIN_MASTER:
fstrcat(typestr, "DMB ");
break;
case SV_TYPE_SERVER_OSF:
fstrcat(typestr, "OSF ");
break;
case SV_TYPE_SERVER_VMS:
fstrcat(typestr, "VMS ");
break;
case SV_TYPE_WIN95_PLUS:
fstrcat(typestr, "W95 ");
break;
case SV_TYPE_ALTERNATE_XPORT:
fstrcat(typestr, "Xpt ");
break;
case SV_TYPE_LOCAL_LIST_ONLY:
fstrcat(typestr, "Dom ");
break;
case SV_TYPE_DOMAIN_ENUM:
fstrcat(typestr, "Loc ");
break;
}
}
}
i = strlen(typestr) - 1;
if (typestr[i] == ' ')
typestr[i] = 0;
return typestr;
}
static void display_server(char *sname, uint32 type, const char *comment)
{
printf("\t%-15.15s%-20s %s\n", sname, get_server_type_str(type),
comment);
}
static void display_srv_info_101(SRV_INFO_101 *sv101)
{
fstring name;
fstring comment;
unistr2_to_ascii(name, &sv101->uni_name, sizeof(name) - 1);
unistr2_to_ascii(comment, &sv101->uni_comment, sizeof(comment) - 1);
display_server(name, sv101->srv_type, comment);
printf("\tplatform_id :\t%d\n", sv101->platform_id);
printf("\tos version :\t%d.%d\n", sv101->ver_major,
sv101->ver_minor);
printf("\tserver type :\t0x%x\n", sv101->srv_type);
}
static void display_srv_info_102(SRV_INFO_102 *sv102)
{
fstring name;
fstring comment;
fstring usr_path;
unistr2_to_ascii(name, &sv102->uni_name, sizeof(name) - 1);
unistr2_to_ascii(comment, &sv102->uni_comment, sizeof(comment) - 1);
unistr2_to_ascii(usr_path, &sv102->uni_usr_path, sizeof(usr_path) - 1);
display_server(name, sv102->srv_type, comment);
printf("\tplatform_id :\t%d\n", sv102->platform_id);
printf("\tos version :\t%d.%d\n", sv102->ver_major,
sv102->ver_minor);
printf("\tusers :\t%x\n", sv102->users);
printf("\tdisc, hidden :\t%x, %x\n", sv102->disc, sv102->hidden);
printf("\tannounce, delta :\t%d, %d\n", sv102->announce,
sv102->ann_delta);
printf("\tlicenses :\t%d\n", sv102->licenses);
printf("\tuser path :\t%s\n", usr_path);
}
/* Server query info */
static NTSTATUS cmd_srvsvc_srv_query_info(struct cli_state *cli,
TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
uint32 info_level = 101;
SRV_INFO_CTR ctr;
WERROR result;
if (argc > 2) {
printf("Usage: %s [infolevel]\n", argv[0]);
return NT_STATUS_OK;
}
if (argc == 2)
info_level = atoi(argv[1]);
result = cli_srvsvc_net_srv_get_info(cli, mem_ctx, info_level,
&ctr);
if (!W_ERROR_IS_OK(result)) {
goto done;
}
/* Display results */
switch (info_level) {
case 101:
display_srv_info_101(&ctr.srv.sv101);
break;
case 102:
display_srv_info_102(&ctr.srv.sv102);
break;
default:
printf("unsupported info level %d\n", info_level);
break;
}
done:
return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
}
static void display_share_info_1(SRV_SHARE_INFO_1 *info1)
{
fstring netname = "", remark = "";
rpcstr_pull_unistr2_fstring(netname, &info1->info_1_str.uni_netname);
rpcstr_pull_unistr2_fstring(remark, &info1->info_1_str.uni_remark);
printf("netname: %s\n", netname);
printf("\tremark:\t%s\n", remark);
}
static void display_share_info_2(SRV_SHARE_INFO_2 *info2)
{
fstring netname = "", remark = "", path = "", passwd = "";
rpcstr_pull_unistr2_fstring(netname, &info2->info_2_str.uni_netname);
rpcstr_pull_unistr2_fstring(remark, &info2->info_2_str.uni_remark);
rpcstr_pull_unistr2_fstring(path, &info2->info_2_str.uni_path);
rpcstr_pull_unistr2_fstring(passwd, &info2->info_2_str.uni_passwd);
printf("netname: %s\n", netname);
printf("\tremark:\t%s\n", remark);
printf("\tpath:\t%s\n", path);
printf("\tpassword:\t%s\n", passwd);
}
static NTSTATUS cmd_srvsvc_net_share_enum(struct cli_state *cli,
TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
uint32 info_level = 2;
SRV_SHARE_INFO_CTR ctr;
WERROR result;
ENUM_HND hnd;
uint32 preferred_len = 0xffffffff, i;
if (argc > 2) {
printf("Usage: %s [infolevel]\n", argv[0]);
return NT_STATUS_OK;
}
if (argc == 2)
info_level = atoi(argv[1]);
init_enum_hnd(&hnd, 0);
result = cli_srvsvc_net_share_enum(
cli, mem_ctx, info_level, &ctr, preferred_len, &hnd);
if (!W_ERROR_IS_OK(result) || !ctr.num_entries)
goto done;
/* Display results */
switch (info_level) {
case 1:
for (i = 0; i < ctr.num_entries; i++)
display_share_info_1(&ctr.share.info1[i]);
break;
case 2:
for (i = 0; i < ctr.num_entries; i++)
display_share_info_2(&ctr.share.info2[i]);
break;
default:
printf("unsupported info level %d\n", info_level);
break;
}
done:
return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
}
static NTSTATUS cmd_srvsvc_net_remote_tod(struct cli_state *cli,
TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
TIME_OF_DAY_INFO tod;
WERROR result;
if (argc > 1) {
printf("Usage: %s\n", argv[0]);
return NT_STATUS_OK;
}
result = cli_srvsvc_net_remote_tod(
cli, mem_ctx, cli->srv_name_slash, &tod);
if (!W_ERROR_IS_OK(result))
goto done;
done:
return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
}
static NTSTATUS cmd_srvsvc_net_file_enum(struct cli_state *cli,
TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
uint32 info_level = 3;
SRV_FILE_INFO_CTR ctr;
WERROR result;
ENUM_HND hnd;
uint32 preferred_len = 0;
if (argc > 2) {
printf("Usage: %s [infolevel]\n", argv[0]);
return NT_STATUS_OK;
}
if (argc == 2)
info_level = atoi(argv[1]);
init_enum_hnd(&hnd, 0);
ZERO_STRUCT(ctr);
result = cli_srvsvc_net_file_enum(
cli, mem_ctx, info_level, NULL, &ctr, preferred_len, &hnd);
if (!W_ERROR_IS_OK(result))
goto done;
done:
return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
}
/* List of commands exported by this module */
struct cmd_set srvsvc_commands[] = {
{ "SRVSVC" },
{ "srvinfo", cmd_srvsvc_srv_query_info, PI_SRVSVC, "Server query info", "" },
{ "netshareenum", cmd_srvsvc_net_share_enum, PI_SRVSVC, "Enumerate shares", "" },
{ "netfileenum", cmd_srvsvc_net_file_enum, PI_SRVSVC, "Enumerate open files", "" },
{ "netremotetod", cmd_srvsvc_net_remote_tod, PI_SRVSVC, "Fetch remote time of day", "" },
{ NULL }
};

View File

@ -1,84 +0,0 @@
/*
Unix SMB/CIFS implementation.
NT Domain Authentication SMB / MSRPC client
Copyright (C) Andrew Tridgell 1994-1997
Copyright (C) Luke Kenneth Casson Leighton 1996-1997
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#define DEBUG_TESTING
extern struct cli_state *smb_cli;
extern FILE* out_hnd;
/****************************************************************************
workstation get info query
****************************************************************************/
void cmd_wks_query_info(struct client_info *info)
{
fstring dest_wks;
fstring tmp;
WKS_INFO_100 ctr;
uint32 info_level = 100;
BOOL res = True;
memset((char *)&ctr, '\0', sizeof(ctr));
fstrcpy(dest_wks, "\\\\");
fstrcat(dest_wks, info->dest_host);
strupper(dest_wks);
if (next_token_nr(NULL, tmp, NULL, sizeof(tmp)))
{
info_level = (uint32)strtol(tmp, (char**)NULL, 10);
}
DEBUG(4,("cmd_wks_query_info: server:%s info level: %d\n",
dest_wks, info_level));
DEBUG(5, ("cmd_wks_query_info: smb_cli->fd:%d\n", smb_cli->fd));
/* open LSARPC session. */
res = res ? cli_nt_session_open(smb_cli, PI_WKSSVC) : False;
/* send info level: receive requested info. hopefully. */
res = res ? do_wks_query_info(smb_cli,
dest_wks, info_level, &ctr) : False;
/* close the session */
cli_nt_session_close(smb_cli);
if (res)
{
DEBUG(5,("cmd_wks_query_info: query succeeded\n"));
#if 0
display_wks_info_100(out_hnd, ACTION_HEADER , &ctr);
display_wks_info_100(out_hnd, ACTION_ENUMERATE, &ctr);
display_wks_info_100(out_hnd, ACTION_FOOTER , &ctr);
#endif
}
else
{
DEBUG(5,("cmd_wks_query_info: query failed\n"));
}
}

View File

@ -1,144 +0,0 @@
/*
Unix SMB/CIFS implementation.
Samba utility functions
Copyright (C) Andrew Tridgell 1992-1999
Copyright (C) Luke Kenneth Casson Leighton 1996 - 1999
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "rpcclient.h"
/****************************************************************************
convert a security permissions into a string
****************************************************************************/
char *get_sec_mask_str(uint32 type)
{
static fstring typestr="";
typestr[0] = 0;
if (type & GENERIC_ALL_ACCESS)
fstrcat(typestr, "Generic all access ");
if (type & GENERIC_EXECUTE_ACCESS)
fstrcat(typestr, "Generic execute access ");
if (type & GENERIC_WRITE_ACCESS)
fstrcat(typestr, "Generic write access ");
if (type & GENERIC_READ_ACCESS)
fstrcat(typestr, "Generic read access ");
if (type & MAXIMUM_ALLOWED_ACCESS)
fstrcat(typestr, "MAXIMUM_ALLOWED_ACCESS ");
if (type & SYSTEM_SECURITY_ACCESS)
fstrcat(typestr, "SYSTEM_SECURITY_ACCESS ");
if (type & SYNCHRONIZE_ACCESS)
fstrcat(typestr, "SYNCHRONIZE_ACCESS ");
if (type & WRITE_OWNER_ACCESS)
fstrcat(typestr, "WRITE_OWNER_ACCESS ");
if (type & WRITE_DAC_ACCESS)
fstrcat(typestr, "WRITE_DAC_ACCESS ");
if (type & READ_CONTROL_ACCESS)
fstrcat(typestr, "READ_CONTROL_ACCESS ");
if (type & DELETE_ACCESS)
fstrcat(typestr, "DELETE_ACCESS ");
printf("\t\tSpecific bits: 0x%lx\n", (unsigned long)type&SPECIFIC_RIGHTS_MASK);
return typestr;
}
/****************************************************************************
display sec_access structure
****************************************************************************/
void display_sec_access(SEC_ACCESS *info)
{
printf("\t\tPermissions: 0x%x: %s\n", info->mask, get_sec_mask_str(info->mask));
}
/****************************************************************************
display sec_ace structure
****************************************************************************/
void display_sec_ace(SEC_ACE *ace)
{
fstring sid_str;
printf("\tACE\n\t\ttype: ");
switch (ace->type) {
case SEC_ACE_TYPE_ACCESS_ALLOWED:
printf("ACCESS ALLOWED");
break;
case SEC_ACE_TYPE_ACCESS_DENIED:
printf("ACCESS DENIED");
break;
case SEC_ACE_TYPE_SYSTEM_AUDIT:
printf("SYSTEM AUDIT");
break;
case SEC_ACE_TYPE_SYSTEM_ALARM:
printf("SYSTEM ALARM");
break;
default:
printf("????");
break;
}
printf(" (%d) flags: %d\n", ace->type, ace->flags);
display_sec_access(&ace->info);
sid_to_string(sid_str, &ace->trustee);
printf("\t\tSID: %s\n\n", sid_str);
}
/****************************************************************************
display sec_acl structure
****************************************************************************/
void display_sec_acl(SEC_ACL *sec_acl)
{
int i;
printf("\tACL\tNum ACEs:\t%d\trevision:\t%x\n",
sec_acl->num_aces, sec_acl->revision);
printf("\t---\n");
if (sec_acl->size != 0 && sec_acl->num_aces != 0)
for (i = 0; i < sec_acl->num_aces; i++)
display_sec_ace(&sec_acl->ace[i]);
}
/****************************************************************************
display sec_desc structure
****************************************************************************/
void display_sec_desc(SEC_DESC *sec)
{
fstring sid_str;
if (sec->sacl) {
printf("SACL\n");
display_sec_acl(sec->sacl);
}
if (sec->dacl) {
printf("DACL\n");
display_sec_acl(sec->dacl);
}
if (sec->owner_sid) {
sid_to_string(sid_str, sec->owner_sid);
printf("\tOwner SID:\t%s\n", sid_str);
}
if (sec->grp_sid) {
sid_to_string(sid_str, sec->grp_sid);
printf("\tParent SID:\t%s\n", sid_str);
}
}

View File

@ -1,756 +0,0 @@
/*
Unix SMB/CIFS implementation.
RPC pipe client
Copyright (C) Tim Potter 2000-2001
Copyright (C) Martin Pool 2003
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "rpcclient.h"
DOM_SID domain_sid;
/* List to hold groups of commands.
*
* Commands are defined in a list of arrays: arrays are easy to
* statically declare, and lists are easier to dynamically extend.
*/
static struct cmd_list {
struct cmd_list *prev, *next;
struct cmd_set *cmd_set;
} *cmd_list;
/****************************************************************************
handle completion of commands for readline
****************************************************************************/
static char **completion_fn(char *text, int start, int end)
{
#define MAX_COMPLETIONS 100
char **matches;
int i, count=0;
struct cmd_list *commands = cmd_list;
#if 0 /* JERRY */
/* FIXME!!! -- what to do when completing argument? */
/* for words not at the start of the line fallback
to filename completion */
if (start)
return NULL;
#endif
/* make sure we have a list of valid commands */
if (!commands)
return NULL;
matches = (char **)malloc(sizeof(matches[0])*MAX_COMPLETIONS);
if (!matches) return NULL;
matches[count++] = strdup(text);
if (!matches[0]) return NULL;
while (commands && count < MAX_COMPLETIONS-1)
{
if (!commands->cmd_set)
break;
for (i=0; commands->cmd_set[i].name; i++)
{
if ((strncmp(text, commands->cmd_set[i].name, strlen(text)) == 0) &&
commands->cmd_set[i].fn)
{
matches[count] = strdup(commands->cmd_set[i].name);
if (!matches[count])
return NULL;
count++;
}
}
commands = commands->next;
}
if (count == 2) {
SAFE_FREE(matches[0]);
matches[0] = strdup(matches[1]);
}
matches[count] = NULL;
return matches;
}
/***********************************************************************
* read in username/password credentials from a file
*/
static void read_authfile (
char *filename,
char* username,
char* password,
char* domain
)
{
FILE *auth;
fstring buf;
uint16 len = 0;
char *ptr, *val, *param;
if ((auth=sys_fopen(filename, "r")) == NULL)
{
printf ("ERROR: Unable to open credentials file!\n");
return;
}
while (!feof(auth))
{
/* get a line from the file */
if (!fgets (buf, sizeof(buf), auth))
continue;
len = strlen(buf);
/* skip empty lines */
if ((len) && (buf[len-1]=='\n'))
{
buf[len-1] = '\0';
len--;
}
if (len == 0)
continue;
/* break up the line into parameter & value.
will need to eat a little whitespace possibly */
param = buf;
if (!(ptr = strchr_m(buf, '=')))
continue;
val = ptr+1;
*ptr = '\0';
/* eat leading white space */
while ((*val!='\0') && ((*val==' ') || (*val=='\t')))
val++;
if (strwicmp("password", param) == 0)
fstrcpy (password, val);
else if (strwicmp("username", param) == 0)
fstrcpy (username, val);
else if (strwicmp("domain", param) == 0)
fstrcpy (domain, val);
memset(buf, 0, sizeof(buf));
}
fclose(auth);
return;
}
static char* next_command (char** cmdstr)
{
static pstring command;
char *p;
if (!cmdstr || !(*cmdstr))
return NULL;
p = strchr_m(*cmdstr, ';');
if (p)
*p = '\0';
pstrcpy(command, *cmdstr);
if (p)
*cmdstr = p + 1;
else
*cmdstr = NULL;
return command;
}
/**
* Find default username from environment variables.
*
* @param username fstring to receive username; not touched if none is
* known.
**/
static void get_username (char *username)
{
if (getenv("USER"))
fstrcpy(username,getenv("USER"));
if (*username == 0 && getenv("LOGNAME"))
fstrcpy(username,getenv("LOGNAME"));
if (*username == 0) {
fstrcpy(username,"GUEST");
}
return;
}
/* Fetch the SID for this computer */
static void fetch_machine_sid(struct cli_state *cli)
{
POLICY_HND pol;
NTSTATUS result = NT_STATUS_OK;
uint32 info_class = 5;
fstring domain_name;
static BOOL got_domain_sid;
TALLOC_CTX *mem_ctx;
if (got_domain_sid) return;
if (!(mem_ctx=talloc_init("fetch_machine_sid")))
{
DEBUG(0,("fetch_machine_sid: talloc_init returned NULL!\n"));
goto error;
}
if (!cli_nt_session_open (cli, PI_LSARPC)) {
fprintf(stderr, "could not initialise lsa pipe\n");
goto error;
}
result = cli_lsa_open_policy(cli, mem_ctx, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&pol);
if (!NT_STATUS_IS_OK(result)) {
goto error;
}
result = cli_lsa_query_info_policy(cli, mem_ctx, &pol, info_class,
domain_name, &domain_sid);
if (!NT_STATUS_IS_OK(result)) {
goto error;
}
got_domain_sid = True;
cli_lsa_close(cli, mem_ctx, &pol);
cli_nt_session_close(cli);
talloc_destroy(mem_ctx);
return;
error:
fprintf(stderr, "could not obtain sid for domain %s\n", cli->domain);
if (!NT_STATUS_IS_OK(result)) {
fprintf(stderr, "error: %s\n", nt_errstr(result));
}
exit(1);
}
/* List the available commands on a given pipe */
static NTSTATUS cmd_listcommands(struct cli_state *cli, TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
struct cmd_list *tmp;
struct cmd_set *tmp_set;
int i;
/* Usage */
if (argc != 2) {
printf("Usage: %s <pipe>\n", argv[0]);
return NT_STATUS_OK;
}
/* Help on one command */
for (tmp = cmd_list; tmp; tmp = tmp->next)
{
tmp_set = tmp->cmd_set;
if (!StrCaseCmp(argv[1], tmp_set->name))
{
printf("Available commands on the %s pipe:\n\n", tmp_set->name);
i = 0;
tmp_set++;
while(tmp_set->name) {
printf("%20s", tmp_set->name);
tmp_set++;
i++;
if (i%4 == 0)
printf("\n");
}
/* drop out of the loop */
break;
}
}
printf("\n\n");
return NT_STATUS_OK;
}
/* Display help on commands */
static NTSTATUS cmd_help(struct cli_state *cli, TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
struct cmd_list *tmp;
struct cmd_set *tmp_set;
/* Usage */
if (argc > 2) {
printf("Usage: %s [command]\n", argv[0]);
return NT_STATUS_OK;
}
/* Help on one command */
if (argc == 2) {
for (tmp = cmd_list; tmp; tmp = tmp->next) {
tmp_set = tmp->cmd_set;
while(tmp_set->name) {
if (strequal(argv[1], tmp_set->name)) {
if (tmp_set->usage &&
tmp_set->usage[0])
printf("%s\n", tmp_set->usage);
else
printf("No help for %s\n", tmp_set->name);
return NT_STATUS_OK;
}
tmp_set++;
}
}
printf("No such command: %s\n", argv[1]);
return NT_STATUS_OK;
}
/* List all commands */
for (tmp = cmd_list; tmp; tmp = tmp->next) {
tmp_set = tmp->cmd_set;
while(tmp_set->name) {
printf("%15s\t\t%s\n", tmp_set->name,
tmp_set->description ? tmp_set->description:
"");
tmp_set++;
}
}
return NT_STATUS_OK;
}
/* Change the debug level */
static NTSTATUS cmd_debuglevel(struct cli_state *cli, TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
if (argc > 2) {
printf("Usage: %s [debuglevel]\n", argv[0]);
return NT_STATUS_OK;
}
if (argc == 2) {
DEBUGLEVEL = atoi(argv[1]);
}
printf("debuglevel is %d\n", DEBUGLEVEL);
return NT_STATUS_OK;
}
static NTSTATUS cmd_quit(struct cli_state *cli, TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
exit(0);
return NT_STATUS_OK; /* NOTREACHED */
}
/* Built in rpcclient commands */
static struct cmd_set rpcclient_commands[] = {
{ "GENERAL OPTIONS" },
{ "help", cmd_help, -1, "Get help on commands", "[command]" },
{ "?", cmd_help, -1, "Get help on commands", "[command]" },
{ "debuglevel", cmd_debuglevel, -1, "Set debug level", "level" },
{ "list", cmd_listcommands, -1, "List available commands on <pipe>", "pipe" },
{ "exit", cmd_quit, -1, "Exit program", "" },
{ "quit", cmd_quit, -1, "Exit program", "" },
{ NULL }
};
static struct cmd_set separator_command[] = {
{ "---------------", NULL, -1, "----------------------" },
{ NULL }
};
/* Various pipe commands */
extern struct cmd_set lsarpc_commands[];
extern struct cmd_set samr_commands[];
extern struct cmd_set spoolss_commands[];
extern struct cmd_set netlogon_commands[];
extern struct cmd_set srvsvc_commands[];
extern struct cmd_set dfs_commands[];
extern struct cmd_set reg_commands[];
extern struct cmd_set ds_commands[];
static struct cmd_set *rpcclient_command_list[] = {
rpcclient_commands,
lsarpc_commands,
ds_commands,
samr_commands,
spoolss_commands,
netlogon_commands,
srvsvc_commands,
dfs_commands,
reg_commands,
NULL
};
static void add_command_set(struct cmd_set *cmd_set)
{
struct cmd_list *entry;
if (!(entry = (struct cmd_list *)malloc(sizeof(struct cmd_list)))) {
DEBUG(0, ("out of memory\n"));
return;
}
ZERO_STRUCTP(entry);
entry->cmd_set = cmd_set;
DLIST_ADD(cmd_list, entry);
}
/**
* Call an rpcclient function, passing an argv array.
*
* @param cmd Command to run, as a single string.
**/
static NTSTATUS do_cmd(struct cli_state *cli,
struct cmd_set *cmd_entry,
int argc, char **argv)
{
NTSTATUS result;
TALLOC_CTX *mem_ctx;
/* Create mem_ctx */
if (!(mem_ctx = talloc_init("do_cmd"))) {
DEBUG(0, ("talloc_init() failed\n"));
return NT_STATUS_UNSUCCESSFUL;
}
/* Open pipe */
if (cmd_entry->pipe_idx != -1)
if (!cli_nt_session_open(cli, cmd_entry->pipe_idx)) {
DEBUG(0, ("Could not initialize pipe\n"));
return NT_STATUS_UNSUCCESSFUL;
}
/* Run command */
result = cmd_entry->fn(cli, mem_ctx, argc, (const char **) argv);
/* Cleanup */
if (cmd_entry->pipe_idx != -1)
cli_nt_session_close(cli);
talloc_destroy(mem_ctx);
return result;
}
/**
* Process a command entered at the prompt or as part of -c
*
* @returns The NTSTATUS from running the command.
**/
static NTSTATUS process_cmd(struct cli_state *cli, char *cmd)
{
struct cmd_list *temp_list;
NTSTATUS result = NT_STATUS_OK;
int ret;
int argc;
char **argv = NULL;
if ((ret = poptParseArgvString(cmd, &argc, (const char ***) &argv)) != 0) {
fprintf(stderr, "rpcclient: %s\n", poptStrerror(ret));
return NT_STATUS_UNSUCCESSFUL;
}
/* Walk through a dlist of arrays of commands. */
for (temp_list = cmd_list; temp_list; temp_list = temp_list->next) {
struct cmd_set *temp_set = temp_list->cmd_set;
while (temp_set->name) {
if (strequal(argv[0], temp_set->name)) {
if (!temp_set->fn) {
fprintf (stderr, "Invalid command\n");
goto out_free;
}
result = do_cmd(cli, temp_set, argc, argv);
goto out_free;
}
temp_set++;
}
}
if (argv[0]) {
printf("command not found: %s\n", argv[0]);
}
out_free:
if (!NT_STATUS_IS_OK(result)) {
printf("result was %s\n", nt_errstr(result));
}
if (argv) {
/* NOTE: popt allocates the whole argv, including the
* strings, as a single block. So a single free is
* enough to release it -- we don't free the
* individual strings. rtfm. */
free(argv);
}
return result;
}
/* Main function */
int main(int argc, char *argv[])
{
static int got_pass = 0;
BOOL interactive = True;
int opt;
static char *cmdstr = "";
const char *server;
struct cli_state *cli;
fstring password="",
username="",
domain="";
static char *opt_authfile=NULL,
*opt_username=NULL,
*opt_domain=NULL,
*opt_logfile=NULL,
*opt_ipaddr=NULL;
pstring logfile;
struct cmd_set **cmd_set;
struct in_addr server_ip;
NTSTATUS nt_status;
/* make sure the vars that get altered (4th field) are in
a fixed location or certain compilers complain */
poptContext pc;
struct poptOption long_options[] = {
POPT_AUTOHELP
{"authfile", 'A', POPT_ARG_STRING, &opt_authfile, 'A', "File containing user credentials", "AUTHFILE"},
{"nopass", 'N', POPT_ARG_NONE, &got_pass, 'N', "Don't ask for a password"},
{"user", 'U', POPT_ARG_STRING, &opt_username, 'U', "Set the network username", "USER"},
{"workgroup", 'W', POPT_ARG_STRING, &opt_domain, 'W', "Set the domain name for user account", "DOMAIN"},
{"command", 'c', POPT_ARG_STRING, &cmdstr, 'c', "Execute semicolon separated cmds", "COMMANDS"},
{"logfile", 'l', POPT_ARG_STRING, &opt_logfile, 'l', "Logfile to use instead of stdout", "LOGFILE" },
{"dest-ip", 'I', POPT_ARG_STRING, &opt_ipaddr, 'I', "Specify destination IP address", "IP"},
{ NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug },
{ NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile },
{ NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version},
{ NULL }
};
setlinebuf(stdout);
/* Parse options */
pc = poptGetContext("rpcclient", argc, (const char **) argv,
long_options, 0);
if (argc == 1) {
poptPrintHelp(pc, stderr, 0);
return 0;
}
while((opt = poptGetNextOpt(pc)) != -1) {
switch (opt) {
case 'A':
/* only get the username, password, and domain from the file */
read_authfile (opt_authfile, username, password, domain);
if (strlen (password))
got_pass = 1;
break;
case 'l':
slprintf(logfile, sizeof(logfile) - 1, "%s.client",
opt_logfile);
lp_set_logfile(logfile);
interactive = False;
break;
case 'U': {
char *lp;
fstrcpy(username,opt_username);
if ((lp=strchr_m(username,'%'))) {
*lp = 0;
fstrcpy(password,lp+1);
got_pass = 1;
memset(strchr_m(opt_username,'%') + 1, 'X',
strlen(password));
}
break;
}
case 'I':
if ( (server_ip.s_addr=inet_addr(opt_ipaddr)) == INADDR_NONE ) {
fprintf(stderr, "%s not a valid IP address\n",
opt_ipaddr);
return 1;
}
case 'W':
fstrcpy(domain, opt_domain);
break;
}
}
/* Get server as remaining unparsed argument. Print usage if more
than one unparsed argument is present. */
server = poptGetArg(pc);
if (!server || poptGetArg(pc)) {
poptPrintHelp(pc, stderr, 0);
return 1;
}
poptFreeContext(pc);
/* the following functions are part of the Samba debugging
facilities. See lib/debug.c */
setup_logging("rpcclient", interactive);
if (!interactive)
reopen_logs();
/* Load smb.conf file */
if (!lp_load(dyn_CONFIGFILE,True,False,False))
fprintf(stderr, "Can't load %s\n", dyn_CONFIGFILE);
load_interfaces();
if (!init_names())
return 1;
/* Resolve the IP address */
if (!opt_ipaddr && !resolve_name(server, &server_ip, 0x20)) {
fprintf(stderr, "Unable to resolve %s\n", server);
return 1;
}
/*
* Get password
* from stdin if necessary
*/
if (!got_pass) {
char *pass = getpass("Password:");
if (pass) {
fstrcpy(password, pass);
}
}
if (!strlen(username) && !got_pass)
get_username(username);
nt_status = cli_full_connection(&cli, lp_netbios_name(), server,
&server_ip, 0,
"IPC$", "IPC",
username, domain,
password, 0, NULL);
if (!NT_STATUS_IS_OK(nt_status)) {
DEBUG(0,("Cannot connect to server. Error was %s\n", nt_errstr(nt_status)));
return 1;
}
memset(password,'X',sizeof(password));
/* Load command lists */
cmd_set = rpcclient_command_list;
while(*cmd_set) {
add_command_set(*cmd_set);
add_command_set(separator_command);
cmd_set++;
}
fetch_machine_sid(cli);
/* Do anything specified with -c */
if (cmdstr[0]) {
char *cmd;
char *p = cmdstr;
while((cmd=next_command(&p)) != NULL) {
process_cmd(cli, cmd);
}
cli_shutdown(cli);
return 0;
}
/* Loop around accepting commands */
while(1) {
pstring prompt;
char *line;
slprintf(prompt, sizeof(prompt) - 1, "rpcclient $> ");
line = smb_readline(prompt, NULL, completion_fn);
if (line == NULL)
break;
if (line[0] != '\n')
process_cmd(cli, line);
}
cli_shutdown(cli);
return 0;
}

View File

@ -1,34 +0,0 @@
/*
Unix SMB/CIFS implementation.
RPC pipe client
Copyright (C) Tim Potter 2000
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef RPCCLIENT_H
#define RPCCLIENT_H
struct cmd_set {
const char *name;
NTSTATUS (*fn)(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc,
const char **argv);
int pipe_idx;
const char *description;
const char *usage;
};
#endif /* RPCCLIENT_H */