diff options
Diffstat (limited to 'source/rpcclient')
-rw-r--r-- | source/rpcclient/cmd_lsarpc.c | 200 | ||||
-rw-r--r-- | source/rpcclient/cmd_netlogon.c | 108 | ||||
-rw-r--r-- | source/rpcclient/cmd_samr.c | 587 | ||||
-rw-r--r-- | source/rpcclient/cmd_srvsvc.c | 328 | ||||
-rw-r--r-- | source/rpcclient/cmd_wkssvc.c | 95 | ||||
-rw-r--r-- | source/rpcclient/display.c | 1013 | ||||
-rw-r--r-- | source/rpcclient/rpcclient.c | 757 |
7 files changed, 3088 insertions, 0 deletions
diff --git a/source/rpcclient/cmd_lsarpc.c b/source/rpcclient/cmd_lsarpc.c new file mode 100644 index 00000000000..d1c2711aed7 --- /dev/null +++ b/source/rpcclient/cmd_lsarpc.c @@ -0,0 +1,200 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + 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. +*/ + + + +#ifdef SYSLOG +#undef SYSLOG +#endif + +#include "includes.h" +#include "nterr.h" + +extern int DEBUGLEVEL; + +#define DEBUG_TESTING + +extern struct cli_state *smb_cli; +extern int smb_tidx; + +extern FILE* out_hnd; + + +/**************************************************************************** +nt lsa query +****************************************************************************/ +void cmd_lsa_query_info(struct client_info *info) +{ + fstring srv_name; + + BOOL res = True; + + fstrcpy(info->dom.level3_dom, ""); + fstrcpy(info->dom.level3_sid, ""); + fstrcpy(info->dom.level5_dom, ""); + fstrcpy(info->dom.level5_sid, ""); + + fstrcpy(srv_name, "\\\\"); + fstrcat(srv_name, info->myhostname); + strupper(srv_name); + + DEBUG(4,("cmd_lsa_query_info: server:%s\n", srv_name)); + + DEBUG(5, ("cmd_lsa_query_info: smb_cli->fd:%d\n", smb_cli->fd)); + + /* open LSARPC session. */ + res = res ? cli_nt_session_open(smb_cli, PIPE_LSARPC, False) : False; + + /* lookup domain controller; receive a policy handle */ + res = res ? do_lsa_open_policy(smb_cli, + srv_name, + &info->dom.lsa_info_pol, False) : False; + + /* send client info query, level 3. receive domain name and sid */ + res = res ? do_lsa_query_info_pol(smb_cli, + &info->dom.lsa_info_pol, 0x03, + info->dom.level3_dom, + info->dom.level3_sid) : False; + + /* send client info query, level 5. receive domain name and sid */ + res = res ? do_lsa_query_info_pol(smb_cli, + &info->dom.lsa_info_pol, 0x05, + info->dom.level5_dom, + info->dom.level5_sid) : False; + + res = res ? do_lsa_close(smb_cli, &info->dom.lsa_info_pol) : False; + + /* close the session */ + cli_nt_session_close(smb_cli); + + if (res) + { + BOOL domain_something = False; + DEBUG(5,("cmd_lsa_query_info: query succeeded\n")); + + fprintf(out_hnd, "LSA Query Info Policy\n"); + + if (info->dom.level3_sid[0] != 0) + { + fprintf(out_hnd, "Domain Member - Domain: %s SID: %s\n", + info->dom.level3_dom, info->dom.level3_sid); + domain_something = True; + } + if (info->dom.level5_sid[0] != 0) + { + fprintf(out_hnd, "Domain Controller - Domain: %s SID: %s\n", + info->dom.level5_dom, info->dom.level5_sid); + domain_something = True; + } + if (!domain_something) + { + fprintf(out_hnd, "%s is not a Domain Member or Controller\n", + info->dest_host); + } + } + else + { + DEBUG(5,("cmd_lsa_query_info: query failed\n")); + } +} + +/**************************************************************************** +nt lsa query +****************************************************************************/ +void cmd_lsa_lookup_sids(struct client_info *info) +{ + fstring temp; + fstring sid_name; + fstring srv_name; + DOM_SID sid; + DOM_SID *sids[1]; + char **names = NULL; + + BOOL res = True; + + DEBUG(5, ("cmd_lsa_lookup_sids: smb_cli->fd:%d\n", smb_cli->fd)); + + fstrcpy(srv_name, "\\\\"); + fstrcat(srv_name, info->myhostname); + strupper(srv_name); + + fstrcpy(sid_name, info->dom.level5_sid); + + if (next_token(NULL, temp, NULL, sizeof(temp))) + { + if (info->dom.level5_sid[0] == 0) + { + fprintf(out_hnd, "please use lsaquery first or specify a complete SID\n"); + return; + } + + if (strnequal("S-", temp, 2)) + { + fstrcpy(sid_name, temp); + } + else + { + fstrcat(sid_name, "-"); + fstrcat(sid_name, temp); + } + } + else + { + fprintf(out_hnd, "lsalookup RID or SID\n"); + return; + } + + DEBUG(4,("cmd_lsa_lookup_sids: server: %s sid:%s\n", + srv_name, sid_name)); + + make_dom_sid(&sid, sid_name); + + sids[0] = &sid; + + /* open LSARPC session. */ + res = res ? cli_nt_session_open(smb_cli, PIPE_LSARPC, False) : False; + + /* lookup domain controller; receive a policy handle */ + res = res ? do_lsa_open_policy(smb_cli, + srv_name, + &info->dom.lsa_info_pol, True) : False; + + /* send client info query, level 3. receive domain name and sid */ + res = res ? do_lsa_lookup_sids(smb_cli, + &info->dom.lsa_info_pol, 1, sids, names) : False; + + res = res ? do_lsa_close(smb_cli, &info->dom.lsa_info_pol) : False; + + /* close the session */ + cli_nt_session_close(smb_cli); + + if (res) + { + DEBUG(5,("cmd_lsa_lookup_sids: query succeeded\n")); + + } + else + { + DEBUG(5,("cmd_lsa_lookup_sids: query failed\n")); + } +} + diff --git a/source/rpcclient/cmd_netlogon.c b/source/rpcclient/cmd_netlogon.c new file mode 100644 index 00000000000..40bb257072d --- /dev/null +++ b/source/rpcclient/cmd_netlogon.c @@ -0,0 +1,108 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + 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. +*/ + + + +#ifdef SYSLOG +#undef SYSLOG +#endif + +#include "includes.h" +#include "nterr.h" + +extern int DEBUGLEVEL; + +#define DEBUG_TESTING + +extern struct cli_state *smb_cli; + +extern FILE* out_hnd; + + +/**************************************************************************** +experimental nt login. +****************************************************************************/ +void cmd_netlogon_login_test(struct client_info *info) +{ + BOOL res = True; + + /* machine account passwords */ + pstring new_mach_pwd; + + /* initialisation */ + new_mach_pwd[0] = 0; + + DEBUG(5,("do_nt_login_test: %d\n", __LINE__)); + +#if 0 + /* check whether the user wants to change their machine password */ + res = res ? trust_account_check(info->dest_ip, info->dest_host, + info->myhostname, smb_cli->domain, + info->mach_acct, new_mach_pwd) : False; +#endif + /* open NETLOGON session. negotiate credentials */ + res = res ? do_nt_session_open(smb_cli, + info->dest_host, info->myhostname, + info->mach_acct, + smb_cli->user_name, smb_cli->domain, + info->dom.sess_key, &info->dom.clnt_cred) : False; + + /* change the machine password? */ + if (new_mach_pwd != NULL && new_mach_pwd[0] != 0) + { + res = res ? do_nt_srv_pwset(smb_cli, info->dom.lsarpc_fnum, + info->dom.sess_key, &info->dom.clnt_cred, &info->dom.rtn_cred, + new_mach_pwd, + info->dest_host, info->mach_acct, info->myhostname) : False; + } + + /* create the user-identification info */ + make_nt_login_interactive(&info->dom.ctr, + info->dom.sess_key, + smb_cli->domain, info->myhostname, + getuid(), smb_cli->user_name); + + /* do an NT login */ + res = res ? do_nt_login(smb_cli, info->dom.lsarpc_fnum, + info->dom.sess_key, &info->dom.clnt_cred, &info->dom.rtn_cred, + &info->dom.ctr, info->dest_host, info->myhostname, &info->dom.user_info3) : False; + + /* ok! you're logged in! do anything you like, then... */ + + /* do an NT logout */ + res = res ? do_nt_logoff(smb_cli, info->dom.lsarpc_fnum, + info->dom.sess_key, &info->dom.clnt_cred, &info->dom.rtn_cred, + &info->dom.ctr, info->dest_host, info->myhostname) : False; + + /* close the session */ + cli_nt_session_close(smb_cli); + + if (res) + { + DEBUG(5,("cmd_nt_login: login test succeeded\n")); + } + else + { + DEBUG(5,("cmd_nt_login: login test failed\n")); + } +} + diff --git a/source/rpcclient/cmd_samr.c b/source/rpcclient/cmd_samr.c new file mode 100644 index 00000000000..c45c4c7c23d --- /dev/null +++ b/source/rpcclient/cmd_samr.c @@ -0,0 +1,587 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + 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. +*/ + + + +#ifdef SYSLOG +#undef SYSLOG +#endif + +#include "includes.h" +#include "nterr.h" + +extern int DEBUGLEVEL; + +#define DEBUG_TESTING + +extern struct cli_state *smb_cli; + +extern FILE* out_hnd; + + +/**************************************************************************** +experimental SAM encryted rpc test connection +****************************************************************************/ +void cmd_sam_test(struct client_info *info) +{ + fstring srv_name; + fstring domain; + fstring sid; + BOOL res = True; + + fstrcpy(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; + } + + fstrcpy(srv_name, "\\\\"); + fstrcat(srv_name, info->myhostname); + strupper(srv_name); + + + fprintf(out_hnd, "SAM Encryption Test\n"); + + /* open SAMR session. */ + res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR, True) : False; + + /* close the session */ + cli_nt_session_close(smb_cli); + + if (res) + { + DEBUG(5,("cmd_sam_test: succeeded\n")); + } + else + { + DEBUG(5,("cmd_sam_test: failed\n")); + } +} + + +/**************************************************************************** +experimental SAM users enum. +****************************************************************************/ +void cmd_sam_enum_users(struct client_info *info) +{ + fstring srv_name; + fstring domain; + fstring sid; + DOM_SID sid1; + int user_idx; + BOOL res = True; + BOOL request_user_info = False; + BOOL request_group_info = False; + uint16 num_entries = 0; + uint16 unk_0 = 0x0; + uint16 acb_mask = 0; + uint16 unk_1 = 0x0; + uint32 admin_rid = 0x304; /* absolutely no idea. */ + fstring tmp; + + fstrcpy(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; + } + + make_dom_sid(&sid1, sid); + + fstrcpy(srv_name, "\\\\"); + fstrcat(srv_name, info->dest_host); + strupper(srv_name); + + /* a bad way to do token parsing... */ + if (next_token(NULL, tmp, NULL, sizeof(tmp))) + { + request_user_info |= strequal(tmp, "-u"); + request_group_info |= strequal(tmp, "-g"); + } + + if (next_token(NULL, tmp, NULL, sizeof(tmp))) + { + request_user_info |= strequal(tmp, "-u"); + request_group_info |= strequal(tmp, "-g"); + } + +#ifdef DEBUG_TESTING + if (next_token(NULL, tmp, NULL, sizeof(tmp))) + { + num_entries = (uint16)strtoul(tmp, (char**)NULL, 16); + } + + if (next_token(NULL, tmp, NULL, sizeof(tmp))) + { + unk_0 = (uint16)strtoul(tmp, (char**)NULL, 16); + } + + if (next_token(NULL, tmp, NULL, sizeof(tmp))) + { + acb_mask = (uint16)strtoul(tmp, (char**)NULL, 16); + } + + if (next_token(NULL, tmp, NULL, sizeof(tmp))) + { + unk_1 = (uint16)strtoul(tmp, (char**)NULL, 16); + } +#endif + + fprintf(out_hnd, "SAM Enumerate Users\n"); + fprintf(out_hnd, "From: %s To: %s Domain: %s SID: %s\n", + info->myhostname, srv_name, domain, sid); + +#ifdef DEBUG_TESTING + DEBUG(5,("Number of entries:%d unk_0:%04x acb_mask:%04x unk_1:%04x\n", + num_entries, unk_0, acb_mask, unk_1)); +#endif + + /* open SAMR session. negotiate credentials */ + res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR, False) : False; + + /* establish a connection. */ + res = res ? do_samr_connect(smb_cli, + srv_name, 0x00000020, + &info->dom.samr_pol_connect) : False; + + /* connect to the domain */ + res = res ? do_samr_open_domain(smb_cli, + &info->dom.samr_pol_connect, admin_rid, &sid1, + &info->dom.samr_pol_open_domain) : False; + + /* read some users */ + res = res ? do_samr_enum_dom_users(smb_cli, + &info->dom.samr_pol_open_domain, + num_entries, unk_0, acb_mask, unk_1, 0xffff, + &info->dom.sam, &info->dom.num_sam_entries) : False; + + if (res && info->dom.num_sam_entries == 0) + { + fprintf(out_hnd, "No users\n"); + } + + if (request_user_info || request_group_info) + { + /* query all the users */ + user_idx = 0; + + while (res && user_idx < info->dom.num_sam_entries) + { + uint32 user_rid = info->dom.sam[user_idx].smb_userid; + SAM_USER_INFO_21 usr; + + fprintf(out_hnd, "User RID: %8x User Name: %s\n", + user_rid, + info->dom.sam[user_idx].acct_name); + + if (request_user_info) + { + /* send user info query, level 0x15 */ + if (get_samr_query_userinfo(smb_cli, + &info->dom.samr_pol_open_domain, + 0x15, user_rid, &usr)) + { + display_sam_user_info_21(out_hnd, ACTION_HEADER , &usr); + display_sam_user_info_21(out_hnd, ACTION_ENUMERATE, &usr); + display_sam_user_info_21(out_hnd, ACTION_FOOTER , &usr); + } + } + + if (request_group_info) + { + uint32 num_groups; + DOM_GID gid[LSA_MAX_GROUPS]; + + /* send user group query */ + if (get_samr_query_usergroups(smb_cli, + &info->dom.samr_pol_open_domain, + user_rid, &num_groups, gid)) + { + display_group_rid_info(out_hnd, ACTION_HEADER , num_groups, gid); + display_group_rid_info(out_hnd, ACTION_ENUMERATE, num_groups, gid); + display_group_rid_info(out_hnd, ACTION_FOOTER , num_groups, gid); + } + } + + user_idx++; + } + } + + res = res ? do_samr_close(smb_cli, + &info->dom.samr_pol_connect) : False; + + res = res ? do_samr_close(smb_cli, + &info->dom.samr_pol_open_domain) : False; + + /* close the session */ + cli_nt_session_close(smb_cli); + + if (info->dom.sam != NULL) + { + free(info->dom.sam); + } + + if (res) + { + DEBUG(5,("cmd_sam_enum_users: succeeded\n")); + } + else + { + DEBUG(5,("cmd_sam_enum_users: failed\n")); + } +} + + +/**************************************************************************** +experimental SAM user query. +****************************************************************************/ +void cmd_sam_query_user(struct client_info *info) +{ + fstring srv_name; + fstring domain; + fstring sid; + DOM_SID sid1; + int user_idx = 0; /* FIXME maybe ... */ + BOOL res = True; + uint32 admin_rid = 0x304; /* absolutely no idea. */ + fstring rid_str ; + fstring info_str; + uint32 user_rid = 0; + uint32 info_level = 0x15; + + SAM_USER_INFO_21 usr; + + fstrcpy(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; + } + + make_dom_sid(&sid1, sid); + + fstrcpy(srv_name, "\\\\"); + fstrcat(srv_name, info->dest_host); + strupper(srv_name); + + if (next_token(NULL, rid_str , NULL, sizeof(rid_str )) && + next_token(NULL, info_str, NULL, sizeof(info_str))) + { + user_rid = strtoul(rid_str , (char**)NULL, 16); + info_level = strtoul(info_str, (char**)NULL, 10); + } + + fprintf(out_hnd, "SAM Query User: rid %x info level %d\n", + user_rid, info_level); + 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, False) : False; + + /* establish a connection. */ + res = res ? do_samr_connect(smb_cli, + srv_name, 0x00000020, + &info->dom.samr_pol_connect) : False; + + /* connect to the domain */ + res = res ? do_samr_open_domain(smb_cli, + &info->dom.samr_pol_connect, admin_rid, &sid1, + &info->dom.samr_pol_open_domain) : False; + + fprintf(out_hnd, "User RID: %8x User Name: %s\n", + user_rid, + info->dom.sam[user_idx].acct_name); + + /* send user info query, level */ + if (get_samr_query_userinfo(smb_cli, + &info->dom.samr_pol_open_domain, + info_level, user_rid, &usr)) + { + if (info_level == 0x15) + { + display_sam_user_info_21(out_hnd, ACTION_HEADER , &usr); + display_sam_user_info_21(out_hnd, ACTION_ENUMERATE, &usr); + display_sam_user_info_21(out_hnd, ACTION_FOOTER , &usr); + } + } + + res = res ? do_samr_close(smb_cli, + &info->dom.samr_pol_connect) : False; + + res = res ? do_samr_close(smb_cli, + &info->dom.samr_pol_open_domain) : False; + + /* close the session */ + cli_nt_session_close(smb_cli); + + if (res) + { + DEBUG(5,("cmd_sam_query_user: succeeded\n")); + } + else + { + DEBUG(5,("cmd_sam_query_user: failed\n")); + } +} + + +/**************************************************************************** +experimental SAM groups query. +****************************************************************************/ +void cmd_sam_query_groups(struct client_info *info) +{ + fstring srv_name; + fstring domain; + fstring sid; + DOM_SID sid1; + BOOL res = True; + fstring info_str; + uint32 switch_value = 2; + uint32 admin_rid = 0x304; /* absolutely no idea. */ + + fstrcpy(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; + } + + make_dom_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 Groups: 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, False) : False; + + /* establish a connection. */ + res = res ? do_samr_connect(smb_cli, + srv_name, 0x00000020, + &info->dom.samr_pol_connect) : False; + + /* connect to the domain */ + res = res ? do_samr_open_domain(smb_cli, + &info->dom.samr_pol_connect, admin_rid, &sid1, + &info->dom.samr_pol_open_domain) : False; + + /* send a samr 0x8 command */ + res = res ? do_samr_unknown_8(smb_cli, + &info->dom.samr_pol_open_domain, switch_value) : False; + + res = res ? do_samr_close(smb_cli, + &info->dom.samr_pol_connect) : False; + + res = res ? do_samr_close(smb_cli, + &info->dom.samr_pol_open_domain) : False; + + /* close the session */ + cli_nt_session_close(smb_cli); + + if (res) + { + DEBUG(5,("cmd_sam_query_groups: succeeded\n")); + } + else + { + DEBUG(5,("cmd_sam_query_groups: failed\n")); + } +} + + +/**************************************************************************** +experimental SAM aliases query. +****************************************************************************/ +void cmd_sam_enum_aliases(struct client_info *info) +{ + fstring srv_name; + fstring domain; + fstring sid; + DOM_SID sid1; + BOOL res = True; + BOOL request_user_info = False; + BOOL request_alias_info = False; + uint32 admin_rid = 0x304; /* absolutely no idea. */ + fstring tmp; + + uint32 num_aliases = 3; + uint32 alias_rid[3] = { DOMAIN_GROUP_RID_ADMINS, DOMAIN_GROUP_RID_USERS, DOMAIN_GROUP_RID_GUESTS }; + fstring alias_names [3]; + uint32 num_als_usrs[3]; + + fstrcpy(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; + } + + make_dom_sid(&sid1, sid); + + fstrcpy(srv_name, "\\\\"); + fstrcat(srv_name, info->dest_host); + strupper(srv_name); + + /* a bad way to do token parsing... */ + if (next_token(NULL, tmp, NULL, sizeof(tmp))) + { + request_user_info |= strequal(tmp, "-u"); + request_alias_info |= strequal(tmp, "-g"); + } + + if (next_token(NULL, tmp, NULL, sizeof(tmp))) + { + request_user_info |= strequal(tmp, "-u"); + request_alias_info |= strequal(tmp, "-g"); + } + + fprintf(out_hnd, "SAM Enumerate Aliases\n"); + 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, False) : False; + + /* establish a connection. */ + res = res ? do_samr_connect(smb_cli, + srv_name, 0x00000020, + &info->dom.samr_pol_connect) : False; + + /* connect to the domain */ + res = res ? do_samr_open_domain(smb_cli, + &info->dom.samr_pol_connect, admin_rid, &sid1, + &info->dom.samr_pol_open_domain) : False; + + /* send a query on the aliase */ + res = res ? do_samr_query_unknown_12(smb_cli, + &info->dom.samr_pol_open_domain, admin_rid, num_aliases, alias_rid, + &num_aliases, alias_names, num_als_usrs) : False; + + if (res) + { + display_alias_name_info(out_hnd, ACTION_HEADER , num_aliases, alias_names, num_als_usrs); + display_alias_name_info(out_hnd, ACTION_ENUMERATE, num_aliases, alias_names, num_als_usrs); + display_alias_name_info(out_hnd, ACTION_FOOTER , num_aliases, alias_names, num_als_usrs); + } + +#if 0 + + /* read some users */ + res = res ? do_samr_enum_dom_users(smb_cli, + &info->dom.samr_pol_open_domain, + num_entries, unk_0, acb_mask, unk_1, 0xffff, + info->dom.sam, &info->dom.num_sam_entries) : False; + + if (res && info->dom.num_sam_entries == 0) + { + fprintf(out_hnd, "No users\n"); + } + + if (request_user_info || request_alias_info) + { + /* query all the users */ + user_idx = 0; + + while (res && user_idx < info->dom.num_sam_entries) + { + uint32 user_rid = info->dom.sam[user_idx].smb_userid; + SAM_USER_INFO_21 usr; + + fprintf(out_hnd, "User RID: %8x User Name: %s\n", + user_rid, + info->dom.sam[user_idx].acct_name); + + if (request_user_info) + { + /* send user info query, level 0x15 */ + if (get_samr_query_userinfo(smb_cli, + &info->dom.samr_pol_open_domain, + 0x15, user_rid, &usr)) + { + display_sam_user_info_21(out_hnd, ACTION_HEADER , &usr); + display_sam_user_info_21(out_hnd, ACTION_ENUMERATE, &usr); + display_sam_user_info_21(out_hnd, ACTION_FOOTER , &usr); + } + } + + if (request_alias_info) + { + uint32 num_aliases; + DOM_GID gid[LSA_MAX_GROUPS]; + + /* send user aliase query */ + if (get_samr_query_useraliases(smb_cli, + &info->dom.samr_pol_open_domain, + user_rid, &num_aliases, gid)) + { + display_alias_info(out_hnd, ACTION_HEADER , num_aliases, gid); + display_alias_info(out_hnd, ACTION_ENUMERATE, num_aliases, gid); + display_alias_info(out_hnd, ACTION_FOOTER , num_aliases, gid); + } + } + + user_idx++; + } + } +#endif + + res = res ? do_samr_close(smb_cli, + &info->dom.samr_pol_connect) : False; + + res = res ? do_samr_close(smb_cli, + &info->dom.samr_pol_open_domain) : False; + + /* close the session */ + cli_nt_session_close(smb_cli); + + if (res) + { + DEBUG(5,("cmd_sam_enum_users: succeeded\n")); + } + else + { + DEBUG(5,("cmd_sam_enum_users: failed\n")); + } +} + + diff --git a/source/rpcclient/cmd_srvsvc.c b/source/rpcclient/cmd_srvsvc.c new file mode 100644 index 00000000000..4d4fb791a92 --- /dev/null +++ b/source/rpcclient/cmd_srvsvc.c @@ -0,0 +1,328 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + 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. +*/ + + + +#ifdef SYSLOG +#undef SYSLOG +#endif + +#include "includes.h" +#include "nterr.h" + +extern int DEBUGLEVEL; + +#define DEBUG_TESTING + +extern struct cli_state *smb_cli; + +extern FILE* out_hnd; + + +/**************************************************************************** +server get info query +****************************************************************************/ +void cmd_srv_query_info(struct client_info *info) +{ + fstring dest_srv; + fstring tmp; + SRV_INFO_CTR ctr; + uint32 info_level = 101; + + BOOL res = True; + + bzero(&ctr, sizeof(ctr)); + + fstrcpy(dest_srv, "\\\\"); + fstrcat(dest_srv, info->dest_host); + strupper(dest_srv); + + if (next_token(NULL, tmp, NULL, sizeof(tmp)-1)) + { + info_level = strtoul(tmp, (char**)NULL, 10); + } + + DEBUG(4,("cmd_srv_query_info: server:%s info level: %d\n", + dest_srv, (int)info_level)); + + DEBUG(5, ("cmd_srv_query_info: smb_cli->fd:%d\n", smb_cli->fd)); + + /* open LSARPC session. */ + res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, False) : False; + + /* send info level: receive requested info. hopefully. */ + res = res ? do_srv_net_srv_get_info(smb_cli, + dest_srv, info_level, &ctr) : False; + + /* close the session */ + cli_nt_session_close(smb_cli); + + if (res) + { + DEBUG(5,("cmd_srv_query_info: query succeeded\n")); + + display_srv_info_ctr(out_hnd, ACTION_HEADER , &ctr); + display_srv_info_ctr(out_hnd, ACTION_ENUMERATE, &ctr); + display_srv_info_ctr(out_hnd, ACTION_FOOTER , &ctr); + } + else + { + DEBUG(5,("cmd_srv_query_info: query failed\n")); + } +} + +/**************************************************************************** +server enum connections +****************************************************************************/ +void cmd_srv_enum_conn(struct client_info *info) +{ + fstring dest_srv; + fstring qual_srv; + fstring tmp; + SRV_CONN_INFO_CTR ctr; + ENUM_HND hnd; + uint32 info_level = 0; + + BOOL res = True; + + bzero(&ctr, sizeof(ctr)); + + fstrcpy(qual_srv, "\\\\"); + fstrcat(qual_srv, info->myhostname); + strupper(qual_srv); + + fstrcpy(dest_srv, "\\\\"); + fstrcat(dest_srv, info->dest_host); + strupper(dest_srv); + + if (next_token(NULL, tmp, NULL, sizeof(tmp)-1)) + { + info_level = strtoul(tmp, (char**)NULL, 10); + } + + DEBUG(4,("cmd_srv_enum_conn: server:%s info level: %d\n", + dest_srv, (int)info_level)); + + DEBUG(5, ("cmd_srv_enum_conn: smb_cli->fd:%d\n", smb_cli->fd)); + + /* open srvsvc session. */ + res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, False) : False; + + hnd.ptr_hnd = 1; + hnd.handle = 0; + + /* enumerate connections on server */ + res = res ? do_srv_net_srv_conn_enum(smb_cli, + dest_srv, qual_srv, + info_level, &ctr, 0xffffffff, &hnd) : False; + + if (res) + { + display_srv_conn_info_ctr(out_hnd, ACTION_HEADER , &ctr); + display_srv_conn_info_ctr(out_hnd, ACTION_ENUMERATE, &ctr); + display_srv_conn_info_ctr(out_hnd, ACTION_FOOTER , &ctr); + } + + /* close the session */ + cli_nt_session_close(smb_cli); + + if (res) + { + DEBUG(5,("cmd_srv_enum_conn: query succeeded\n")); + } + else + { + DEBUG(5,("cmd_srv_enum_conn: query failed\n")); + } +} + +/**************************************************************************** +server enum shares +****************************************************************************/ +void cmd_srv_enum_shares(struct client_info *info) +{ + fstring dest_srv; + fstring tmp; + SRV_SHARE_INFO_CTR ctr; + ENUM_HND hnd; + uint32 info_level = 1; + + BOOL res = True; + + bzero(&ctr, sizeof(ctr)); + + fstrcpy(dest_srv, "\\\\"); + fstrcat(dest_srv, info->dest_host); + strupper(dest_srv); + + if (next_token(NULL, tmp, NULL, sizeof(tmp)-1)) + { + info_level = strtoul(tmp, (char**)NULL, 10); + } + + DEBUG(4,("cmd_srv_enum_shares: server:%s info level: %d\n", + dest_srv, (int)info_level)); + + DEBUG(5, ("cmd_srv_enum_shares: smb_cli->fd:%d\n", smb_cli->fd)); + + /* open srvsvc session. */ + res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, False) : False; + + hnd.ptr_hnd = 0; + hnd.handle = 0; + + /* enumerate shares_files on server */ + res = res ? do_srv_net_srv_share_enum(smb_cli, + dest_srv, + info_level, &ctr, 0xffffffff, &hnd) : False; + + if (res) + { + display_srv_share_info_ctr(out_hnd, ACTION_HEADER , &ctr); + display_srv_share_info_ctr(out_hnd, ACTION_ENUMERATE, &ctr); + display_srv_share_info_ctr(out_hnd, ACTION_FOOTER , &ctr); + } + + /* close the session */ + cli_nt_session_close(smb_cli); + + if (res) + { + DEBUG(5,("cmd_srv_enum_shares: query succeeded\n")); + } + else + { + DEBUG(5,("cmd_srv_enum_shares: query failed\n")); + } +} + +/**************************************************************************** +server enum sessions +****************************************************************************/ +void cmd_srv_enum_sess(struct client_info *info) +{ + fstring dest_srv; + fstring tmp; + SRV_SESS_INFO_CTR ctr; + ENUM_HND hnd; + uint32 info_level = 0; + + BOOL res = True; + + bzero(&ctr, sizeof(ctr)); + + fstrcpy(dest_srv, "\\\\"); + fstrcat(dest_srv, info->dest_host); + strupper(dest_srv); + + if (next_token(NULL, tmp, NULL, sizeof(tmp)-1)) + { + info_level = strtoul(tmp, (char**)NULL, 10); + } + + DEBUG(4,("cmd_srv_enum_sess: server:%s info level: %d\n", + dest_srv, (int)info_level)); + + DEBUG(5, ("cmd_srv_enum_sess: smb_cli->fd:%d\n", smb_cli->fd)); + + /* open srvsvc session. */ + res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, False) : False; + + hnd.ptr_hnd = 1; + hnd.handle = 0; + + /* enumerate sessions on server */ + res = res ? do_srv_net_srv_sess_enum(smb_cli, + dest_srv, NULL, info_level, &ctr, 0x1000, &hnd) : False; + + /* close the session */ + cli_nt_session_close(smb_cli); + + if (res) + { + DEBUG(5,("cmd_srv_enum_sess: query succeeded\n")); + } + else + { + DEBUG(5,("cmd_srv_enum_sess: query failed\n")); + } +} + +/**************************************************************************** +server enum files +****************************************************************************/ +void cmd_srv_enum_files(struct client_info *info) +{ + fstring dest_srv; + fstring tmp; + SRV_FILE_INFO_CTR ctr; + ENUM_HND hnd; + uint32 info_level = 3; + + BOOL res = True; + + bzero(&ctr, sizeof(ctr)); + + fstrcpy(dest_srv, "\\\\"); + fstrcat(dest_srv, info->dest_host); + strupper(dest_srv); + + if (next_token(NULL, tmp, NULL, sizeof(tmp)-1)) + { + info_level = strtoul(tmp, (char**)NULL, 10); + } + + DEBUG(4,("cmd_srv_enum_files: server:%s info level: %d\n", + dest_srv, (int)info_level)); + + DEBUG(5, ("cmd_srv_enum_files: smb_cli->fd:%d\n", smb_cli->fd)); + + /* open srvsvc session. */ + res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, False) : False; + + hnd.ptr_hnd = 1; + hnd.handle = 0; + + /* enumerate files on server */ + res = res ? do_srv_net_srv_file_enum(smb_cli, + dest_srv, NULL, info_level, &ctr, 0x1000, &hnd) : False; + + if (res) + { + display_srv_file_info_ctr(out_hnd, ACTION_HEADER , &ctr); + display_srv_file_info_ctr(out_hnd, ACTION_ENUMERATE, &ctr); + display_srv_file_info_ctr(out_hnd, ACTION_FOOTER , &ctr); + } + + /* close the session */ + cli_nt_session_close(smb_cli); + + if (res) + { + DEBUG(5,("cmd_srv_enum_files: query succeeded\n")); + } + else + { + DEBUG(5,("cmd_srv_enum_files: query failed\n")); + } +} + diff --git a/source/rpcclient/cmd_wkssvc.c b/source/rpcclient/cmd_wkssvc.c new file mode 100644 index 00000000000..350aa296577 --- /dev/null +++ b/source/rpcclient/cmd_wkssvc.c @@ -0,0 +1,95 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + 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. +*/ + + + +#ifdef SYSLOG +#undef SYSLOG +#endif + +#include "includes.h" +#include "nterr.h" + +extern int DEBUGLEVEL; + +#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; + + bzero(&ctr, sizeof(ctr)); + + fstrcpy(dest_wks, "\\\\"); + fstrcat(dest_wks, info->dest_host); + strupper(dest_wks); + + if (next_token(NULL, tmp, NULL, sizeof(tmp))) + { + info_level = strtoul(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, PIPE_WKSSVC, False) : 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")); + } +} + diff --git a/source/rpcclient/display.c b/source/rpcclient/display.c new file mode 100644 index 00000000000..f399b7fc031 --- /dev/null +++ b/source/rpcclient/display.c @@ -0,0 +1,1013 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + Samba utility functions + Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Luke Kenneth Casson Leighton 1996 - 1998 + + 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" + + +/**************************************************************************** +convert a share mode to a string +****************************************************************************/ +char *get_file_mode_str(uint32 share_mode) +{ + static fstring mode; + + switch ((share_mode>>4)&0xF) + { + case DENY_NONE : fstrcpy(mode, "DENY_NONE "); break; + case DENY_ALL : fstrcpy(mode, "DENY_ALL "); break; + case DENY_DOS : fstrcpy(mode, "DENY_DOS "); break; + case DENY_READ : fstrcpy(mode, "DENY_READ "); break; + case DENY_WRITE: fstrcpy(mode, "DENY_WRITE "); break; + default : fstrcpy(mode, "DENY_???? "); break; + } + + switch (share_mode & 0xF) + { + case 0 : fstrcat(mode, "RDONLY"); break; + case 1 : fstrcat(mode, "WRONLY"); break; + case 2 : fstrcat(mode, "RDWR "); break; + default: fstrcat(mode, "R??W??"); break; + } + + return mode; +} + +/**************************************************************************** +convert an oplock mode to a string +****************************************************************************/ +char *get_file_oplock_str(uint32 op_type) +{ + static fstring oplock; + BOOL excl = IS_BITS_SET_ALL(op_type, EXCLUSIVE_OPLOCK); + BOOL batch = IS_BITS_SET_ALL(op_type, BATCH_OPLOCK ); + + oplock[0] = 0; + + if (excl ) fstrcat(oplock, "EXCLUSIVE"); + if (excl && batch) fstrcat(oplock, "+"); + if ( batch) fstrcat(oplock, "BATCH"); + if (!excl && !batch) fstrcat(oplock, "NONE"); + + return oplock; +} + +/**************************************************************************** +convert a share type enum to a string +****************************************************************************/ +char *get_share_type_str(uint32 type) +{ + static fstring typestr; + + switch (type) + { + case STYPE_DISKTREE: fstrcpy(typestr, "Disk" ); break; + case STYPE_PRINTQ : fstrcpy(typestr, "Printer"); break; + case STYPE_DEVICE : fstrcpy(typestr, "Device" ); break; + case STYPE_IPC : fstrcpy(typestr, "IPC" ); break; + default : fstrcpy(typestr, "????" ); break; + } + return typestr; +} + +/**************************************************************************** +convert a server type enum to a string +****************************************************************************/ +char *get_server_type_str(uint32 type) +{ + static fstring typestr; + + if (type == SV_TYPE_ALL) + { + fstrcpy(typestr, "All"); + } + else + { + int i; + typestr[0] = 0; + for (i = 0; i < 32; i++) + { + if (IS_BITS_SET_ALL(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; +} + +/**************************************************************************** +server info level 101 display function +****************************************************************************/ +void display_srv_info_101(FILE *out_hnd, enum action_type action, + SRV_INFO_101 *sv101) +{ + if (sv101 == NULL) + { + return; + } + + switch (action) + { + case ACTION_HEADER: + { + fprintf(out_hnd, "Server Info Level 101:\n"); + + break; + } + case ACTION_ENUMERATE: + { + fstring name; + fstring comment; + + fstrcpy(name , unistrn2(sv101->uni_name .buffer, sv101->uni_name .uni_str_len)); + fstrcpy(comment , unistrn2(sv101->uni_comment .buffer, sv101->uni_comment .uni_str_len)); + + display_server(out_hnd, action, name, sv101->srv_type, comment); + + fprintf(out_hnd, "\tplatform_id : %d\n" , sv101->platform_id); + fprintf(out_hnd, "\tos version : %d.%d\n" , sv101->ver_major, sv101->ver_minor); + + break; + } + case ACTION_FOOTER: + { + break; + } + } + +} + +/**************************************************************************** +server info level 102 display function +****************************************************************************/ +void display_srv_info_102(FILE *out_hnd, enum action_type action,SRV_INFO_102 *sv102) +{ + if (sv102 == NULL) + { + return; + } + + switch (action) + { + case ACTION_HEADER: + { + fprintf(out_hnd, "Server Info Level 102:\n"); + + break; + } + case ACTION_ENUMERATE: + { + fstring name; + fstring comment; + fstring usr_path; + + fstrcpy(name , unistrn2(sv102->uni_name .buffer, sv102->uni_name .uni_str_len)); + fstrcpy(comment , unistrn2(sv102->uni_comment .buffer, sv102->uni_comment .uni_str_len)); + fstrcpy(usr_path, unistrn2(sv102->uni_usr_path.buffer, sv102->uni_usr_path.uni_str_len)); + + display_server(out_hnd, action, name, sv102->srv_type, comment); + + fprintf(out_hnd, "\tplatform_id : %d\n" , sv102->platform_id); + fprintf(out_hnd, "\tos version : %d.%d\n" , sv102->ver_major, sv102->ver_minor); + + fprintf(out_hnd, "\tusers : %x\n" , sv102->users ); + fprintf(out_hnd, "\tdisc, hidden : %x,%x\n" , sv102->disc , sv102->hidden ); + fprintf(out_hnd, "\tannounce, delta : %d, %d\n", sv102->announce , sv102->ann_delta); + fprintf(out_hnd, "\tlicenses : %d\n" , sv102->licenses ); + fprintf(out_hnd, "\tuser path : %s\n" , usr_path); + + break; + } + case ACTION_FOOTER: + { + break; + } + } +} + +/**************************************************************************** +server info container display function +****************************************************************************/ +void display_srv_info_ctr(FILE *out_hnd, enum action_type action,SRV_INFO_CTR *ctr) +{ + if (ctr == NULL || ctr->ptr_srv_ctr == 0) + { + fprintf(out_hnd, "Server Information: unavailable due to an error\n"); + return; + } + + switch (ctr->switch_value) + { + case 101: + { + display_srv_info_101(out_hnd, action, &(ctr->srv.sv101)); + break; + } + case 102: + { + display_srv_info_102(out_hnd, action, &(ctr->srv.sv102)); + break; + } + default: + { + fprintf(out_hnd, "Server Information: Unknown Info Level\n"); + break; + } + } +} + +/**************************************************************************** +connection info level 0 display function +****************************************************************************/ +void display_conn_info_0(FILE *out_hnd, enum action_type action, + CONN_INFO_0 *info0) +{ + if (info0 == NULL) + { + return; + } + + switch (action) + { + case ACTION_HEADER: + { + fprintf(out_hnd, "Connection Info Level 0:\n"); + + break; + } + case ACTION_ENUMERATE: + { + fprintf(out_hnd, "\tid: %d\n", info0->id); + + break; + } + case ACTION_FOOTER: + { + fprintf(out_hnd, "\n"); + break; + } + } + +} + +/**************************************************************************** +connection info level 1 display function +****************************************************************************/ +void display_conn_info_1(FILE *out_hnd, enum action_type action, + CONN_INFO_1 *info1, CONN_INFO_1_STR *str1) +{ + if (info1 == NULL || str1 == NULL) + { + return; + } + + switch (action) + { + case ACTION_HEADER: + { + fprintf(out_hnd, "Connection Info Level 1:\n"); + + break; + } + case ACTION_ENUMERATE: + { + fstring usr_name; + fstring net_name; + + fstrcpy(usr_name, unistrn2(str1->uni_usr_name.buffer, str1->uni_usr_name.uni_str_len)); + fstrcpy(net_name, unistrn2(str1->uni_net_name.buffer, str1->uni_net_name.uni_str_len)); + + fprintf(out_hnd, "\tid : %d\n", info1->id); + fprintf(out_hnd, "\ttype : %s\n", get_share_type_str(info1->type)); + fprintf(out_hnd, "\tnum_opens: %d\n", info1->num_opens); + fprintf(out_hnd, "\tnum_users: %d\n", info1->num_users); + fprintf(out_hnd, "\topen_time: %d\n", info1->open_time); + + fprintf(out_hnd, "\tuser name: %s\n", usr_name); + fprintf(out_hnd, "\tnet name: %s\n", net_name); + + break; + } + case ACTION_FOOTER: + { + fprintf(out_hnd, "\n"); + break; + } + } + +} + +/**************************************************************************** +connection info level 0 container display function +****************************************************************************/ +void display_srv_conn_info_0_ctr(FILE *out_hnd, enum action_type action, + SRV_CONN_INFO_0 *ctr) +{ + if (ctr == NULL) + { + fprintf(out_hnd, "display_srv_conn_info_0_ctr: unavailable due to an internal error\n"); + return; + } + + switch (action) + { + case ACTION_HEADER: + { + break; + } + case ACTION_ENUMERATE: + { + int i; + + for (i = 0; i < ctr->num_entries_read; i++) + { + display_conn_info_0(out_hnd, ACTION_HEADER , &(ctr->info_0[i])); + display_conn_info_0(out_hnd, ACTION_ENUMERATE, &(ctr->info_0[i])); + display_conn_info_0(out_hnd, ACTION_FOOTER , &(ctr->info_0[i])); + } + break; + } + case ACTION_FOOTER: + { + break; + } + } +} + +/**************************************************************************** +connection info level 1 container display function +****************************************************************************/ +void display_srv_conn_info_1_ctr(FILE *out_hnd, enum action_type action, + SRV_CONN_INFO_1 *ctr) +{ + if (ctr == NULL) + { + fprintf(out_hnd, "display_srv_conn_info_1_ctr: unavailable due to an internal error\n"); + return; + } + + switch (action) + { + case ACTION_HEADER: + { + break; + } + case ACTION_ENUMERATE: + { + int i; + + for (i = 0; i < ctr->num_entries_read; i++) + { + display_conn_info_1(out_hnd, ACTION_HEADER , &(ctr->info_1[i]), &(ctr->info_1_str[i])); + display_conn_info_1(out_hnd, ACTION_ENUMERATE, &(ctr->info_1[i]), &(ctr->info_1_str[i])); + display_conn_info_1(out_hnd, ACTION_FOOTER , &(ctr->info_1[i]), &(ctr->info_1_str[i])); + } + break; + } + case ACTION_FOOTER: + { + break; + } + } +} + +/**************************************************************************** +connection info container display function +****************************************************************************/ +void display_srv_conn_info_ctr(FILE *out_hnd, enum action_type action, + SRV_CONN_INFO_CTR *ctr) +{ + if (ctr == NULL || ctr->ptr_conn_ctr == 0) + { + fprintf(out_hnd, "display_srv_conn_info_ctr: unavailable due to an internal error\n"); + return; + } + + switch (ctr->switch_value) + { + case 0: + { + display_srv_conn_info_0_ctr(out_hnd, action, + &(ctr->conn.info0)); + break; + } + case 1: + { + display_srv_conn_info_1_ctr(out_hnd, action, + &(ctr->conn.info1)); + break; + } + default: + { + fprintf(out_hnd, "display_srv_conn_info_ctr: Unknown Info Level\n"); + break; + } + } +} + + +/**************************************************************************** +share info level 1 display function +****************************************************************************/ +void display_share_info_1(FILE *out_hnd, enum action_type action, + SH_INFO_1 *info1, SH_INFO_1_STR *str1) +{ + if (info1 == NULL || str1 == NULL) + { + return; + } + + switch (action) + { + case ACTION_HEADER: + { + fprintf(out_hnd, "Share Info Level 1:\n"); + + break; + } + case ACTION_ENUMERATE: + { + fstring remark ; + fstring net_name; + + fstrcpy(net_name, unistrn2(str1->uni_netname.buffer, str1->uni_netname.uni_str_len)); + fstrcpy(remark , unistrn2(str1->uni_remark .buffer, str1->uni_remark .uni_str_len)); + + display_share(out_hnd, action, net_name, info1->type, remark); + + break; + } + case ACTION_FOOTER: + { + fprintf(out_hnd, "\n"); + break; + } + } + +} + +/**************************************************************************** +share info level 2 display function +****************************************************************************/ +void display_share_info_2(FILE *out_hnd, enum action_type action, + SH_INFO_2 *info2, SH_INFO_2_STR *str2) +{ + if (info2 == NULL || str2 == NULL) + { + return; + } + + switch (action) + { + case ACTION_HEADER: + { + fprintf(out_hnd, "Share Info Level 2:\n"); + + break; + } + case ACTION_ENUMERATE: + { + fstring remark ; + fstring net_name; + fstring path ; + fstring passwd ; + + fstrcpy(net_name, unistrn2(str2->uni_netname.buffer, str2->uni_netname.uni_str_len)); + fstrcpy(remark , unistrn2(str2->uni_remark .buffer, str2->uni_remark .uni_str_len)); + fstrcpy(path , unistrn2(str2->uni_path .buffer, str2->uni_path .uni_str_len)); + fstrcpy(passwd , unistrn2(str2->uni_passwd .buffer, str2->uni_passwd .uni_str_len)); + + display_share2(out_hnd, action, net_name, info2->type, remark, + info2->perms, info2->max_uses, info2->num_uses, + path, passwd); + + break; + } + case ACTION_FOOTER: + { + fprintf(out_hnd, "\n"); + break; + } + } + +} + +/**************************************************************************** +share info level 1 container display function +****************************************************************************/ +void display_srv_share_info_1_ctr(FILE *out_hnd, enum action_type action, + SRV_SHARE_INFO_1 *ctr) +{ + if (ctr == NULL) + { + fprintf(out_hnd, "display_srv_share_info_1_ctr: unavailable due to an internal error\n"); + return; + } + + switch (action) + { + case ACTION_HEADER: + { + break; + } + case ACTION_ENUMERATE: + { + int i; + + for (i = 0; i < ctr->num_entries_read; i++) + { + display_share_info_1(out_hnd, ACTION_HEADER , &(ctr->info_1[i]), &(ctr->info_1_str[i])); + display_share_info_1(out_hnd, ACTION_ENUMERATE, &(ctr->info_1[i]), &(ctr->info_1_str[i])); + display_share_info_1(out_hnd, ACTION_FOOTER , &(ctr->info_1[i]), &(ctr->info_1_str[i])); + } + break; + } + case ACTION_FOOTER: + { + break; + } + } +} + +/**************************************************************************** +share info level 2 container display function +****************************************************************************/ +void display_srv_share_info_2_ctr(FILE *out_hnd, enum action_type action, + SRV_SHARE_INFO_2 *ctr) +{ + if (ctr == NULL) + { + fprintf(out_hnd, "display_srv_share_info_2_ctr: unavailable due to an internal error\n"); + return; + } + + switch (action) + { + case ACTION_HEADER: + { + break; + } + case ACTION_ENUMERATE: + { + int i; + + for (i = 0; i < ctr->num_entries_read; i++) + { + display_share_info_2(out_hnd, ACTION_HEADER , &(ctr->info_2[i]), &(ctr->info_2_str[i])); + display_share_info_2(out_hnd, ACTION_ENUMERATE, &(ctr->info_2[i]), &(ctr->info_2_str[i])); + display_share_info_2(out_hnd, ACTION_FOOTER , &(ctr->info_2[i]), &(ctr->info_2_str[i])); + } + break; + } + case ACTION_FOOTER: + { + break; + } + } +} + +/**************************************************************************** +share info container display function +****************************************************************************/ +void display_srv_share_info_ctr(FILE *out_hnd, enum action_type action, + SRV_SHARE_INFO_CTR *ctr) +{ + if (ctr == NULL || ctr->ptr_share_ctr == 0) + { + fprintf(out_hnd, "display_srv_share_info_ctr: unavailable due to an internal error\n"); + return; + } + + switch (ctr->switch_value) + { + case 1: + { + display_srv_share_info_1_ctr(out_hnd, action, + &(ctr->share.info1)); + break; + } + case 2: + { + display_srv_share_info_2_ctr(out_hnd, action, + &(ctr->share.info2)); + break; + } + default: + { + fprintf(out_hnd, "display_srv_share_info_ctr: Unknown Info Level\n"); + break; + } + } +} + + +/**************************************************************************** +file info level 3 display function +****************************************************************************/ +void display_file_info_3(FILE *out_hnd, enum action_type action, + FILE_INFO_3 *info3, FILE_INFO_3_STR *str3) +{ + if (info3 == NULL || str3 == NULL) + { + return; + } + + switch (action) + { + case ACTION_HEADER: + { + fprintf(out_hnd, "File Info Level 3:\n"); + + break; + } + case ACTION_ENUMERATE: + { + fstring path_name; + fstring user_name; + + fstrcpy(path_name, unistrn2(str3->uni_path_name.buffer, str3->uni_path_name.uni_str_len)); + fstrcpy(user_name, unistrn2(str3->uni_user_name.buffer, str3->uni_user_name.uni_str_len)); + + fprintf(out_hnd, "\tid : %d\n", info3->id); + fprintf(out_hnd, "\tperms : %s\n", get_file_mode_str(info3->perms)); + fprintf(out_hnd, "\tnum_locks: %d\n", info3->num_locks); + + fprintf(out_hnd, "\tpath name: %s\n", path_name); + fprintf(out_hnd, "\tuser name: %s\n", user_name); + + break; + } + case ACTION_FOOTER: + { + fprintf(out_hnd, "\n"); + break; + } + } + +} + +/**************************************************************************** +file info level 3 container display function +****************************************************************************/ +void display_srv_file_info_3_ctr(FILE *out_hnd, enum action_type action, + SRV_FILE_INFO_3 *ctr) +{ + if (ctr == NULL) + { + fprintf(out_hnd, "display_srv_file_info_3_ctr: unavailable due to an internal error\n"); + return; + } + + switch (action) + { + case ACTION_HEADER: + { + break; + } + case ACTION_ENUMERATE: + { + int i; + + for (i = 0; i < ctr->num_entries_read; i++) + { + display_file_info_3(out_hnd, ACTION_HEADER , &(ctr->info_3[i]), &(ctr->info_3_str[i])); + display_file_info_3(out_hnd, ACTION_ENUMERATE, &(ctr->info_3[i]), &(ctr->info_3_str[i])); + display_file_info_3(out_hnd, ACTION_FOOTER , &(ctr->info_3[i]), &(ctr->info_3_str[i])); + } + break; + } + case ACTION_FOOTER: + { + break; + } + } +} + +/**************************************************************************** +file info container display function +****************************************************************************/ +void display_srv_file_info_ctr(FILE *out_hnd, enum action_type action, + SRV_FILE_INFO_CTR *ctr) +{ + if (ctr == NULL || ctr->ptr_file_ctr == 0) + { + fprintf(out_hnd, "display_srv_file_info_ctr: unavailable due to an internal error\n"); + return; + } + + switch (ctr->switch_value) + { + case 3: + { + display_srv_file_info_3_ctr(out_hnd, action, + &(ctr->file.info3)); + break; + } + default: + { + fprintf(out_hnd, "display_srv_file_info_ctr: Unknown Info Level\n"); + break; + } + } +} + +/**************************************************************************** + print browse connection on a host + ****************************************************************************/ +void display_server(FILE *out_hnd, enum action_type action, + char *sname, uint32 type, char *comment) +{ + switch (action) + { + case ACTION_HEADER: + { + break; + } + case ACTION_ENUMERATE: + { + fprintf(out_hnd, "\t%-15.15s%-20s %s\n", + sname, get_server_type_str(type), comment); + break; + } + case ACTION_FOOTER: + { + break; + } + } +} + +/**************************************************************************** +print shares on a host +****************************************************************************/ +void display_share(FILE *out_hnd, enum action_type action, + char *sname, uint32 type, char *comment) +{ + switch (action) + { + case ACTION_HEADER: + { + break; + } + case ACTION_ENUMERATE: + { + fprintf(out_hnd, "\t%-15.15s%-10.10s%s\n", + sname, get_share_type_str(type), comment); + break; + } + case ACTION_FOOTER: + { + break; + } + } +} + + +/**************************************************************************** +print shares on a host, level 2 +****************************************************************************/ +void display_share2(FILE *out_hnd, enum action_type action, + char *sname, uint32 type, char *comment, + uint32 perms, uint32 max_uses, uint32 num_uses, + char *path, char *passwd) +{ + switch (action) + { + case ACTION_HEADER: + { + break; + } + case ACTION_ENUMERATE: + { + fprintf(out_hnd, "\t%-15.15s%-10.10s%s %x %x %x %s %s\n", + sname, get_share_type_str(type), comment, + perms, max_uses, num_uses, path, passwd); + break; + } + case ACTION_FOOTER: + { + break; + } + } +} + + +/**************************************************************************** +print name info +****************************************************************************/ +void display_name(FILE *out_hnd, enum action_type action, + char *sname) +{ + switch (action) + { + case ACTION_HEADER: + { + break; + } + case ACTION_ENUMERATE: + { + fprintf(out_hnd, "\t%-21.21s\n", sname); + break; + } + case ACTION_FOOTER: + { + break; + } + } +} + + +/**************************************************************************** + display group rid info + ****************************************************************************/ +void display_group_rid_info(FILE *out_hnd, enum action_type action, + uint32 num_gids, DOM_GID *gid) +{ + switch (action) + { + case ACTION_HEADER: + { + if (num_gids == 0) + { + fprintf(out_hnd, "\tNo Groups\n"); + } + else + { + fprintf(out_hnd, "\tGroup Info\n"); + fprintf(out_hnd, "\t----------\n"); + } + break; + } + case ACTION_ENUMERATE: + { + int i; + + for (i = 0; i < num_gids; i++) + { + fprintf(out_hnd, "\tGroup RID: %8x attr: %x\n", + gid[i].g_rid, gid[i].attr); + } + + break; + } + case ACTION_FOOTER: + { + fprintf(out_hnd, "\n"); + break; + } + } +} + + +/**************************************************************************** + display alias name info + ****************************************************************************/ +void display_alias_name_info(FILE *out_hnd, enum action_type action, + uint32 num_aliases, fstring *alias_name, uint32 *num_als_usrs) +{ + switch (action) + { + case ACTION_HEADER: + { + if (num_aliases == 0) + { + fprintf(out_hnd, "\tNo Aliases\n"); + } + else + { + fprintf(out_hnd, "\tAlias Names\n"); + fprintf(out_hnd, "\t----------- \n"); + } + break; + } + case ACTION_ENUMERATE: + { + int i; + + for (i = 0; i < num_aliases; i++) + { + fprintf(out_hnd, "\tAlias Name: %s Attributes: %3d\n", + alias_name[i], num_als_usrs[i]); + } + + break; + } + case ACTION_FOOTER: + { + fprintf(out_hnd, "\n"); + break; + } + } +} + + +/**************************************************************************** + display sam_user_info_21 structure + ****************************************************************************/ +void display_sam_user_info_21(FILE *out_hnd, enum action_type action, SAM_USER_INFO_21 *usr) +{ + switch (action) + { + case ACTION_HEADER: + { + fprintf(out_hnd, "\tUser Info, Level 0x15\n"); + fprintf(out_hnd, "\t---------------------\n"); + + break; + } + case ACTION_ENUMERATE: + { + fprintf(out_hnd, "\t\tUser Name : %s\n", unistrn2(usr->uni_user_name .buffer, usr->uni_user_name .uni_str_len)); /* username unicode string */ + fprintf(out_hnd, "\t\tFull Name : %s\n", unistrn2(usr->uni_full_name .buffer, usr->uni_full_name .uni_str_len)); /* user's full name unicode string */ + fprintf(out_hnd, "\t\tHome Drive : %s\n", unistrn2(usr->uni_home_dir .buffer, usr->uni_home_dir .uni_str_len)); /* home directory unicode string */ + fprintf(out_hnd, "\t\tDir Drive : %s\n", unistrn2(usr->uni_dir_drive .buffer, usr->uni_dir_drive .uni_str_len)); /* home directory drive unicode string */ + fprintf(out_hnd, "\t\tProfile Path: %s\n", unistrn2(usr->uni_profile_path.buffer, usr->uni_profile_path.uni_str_len)); /* profile path unicode string */ + fprintf(out_hnd, "\t\tLogon Script: %s\n", unistrn2(usr->uni_logon_script.buffer, usr->uni_logon_script.uni_str_len)); /* logon script unicode string */ + fprintf(out_hnd, "\t\tDescription : %s\n", unistrn2(usr->uni_acct_desc .buffer, usr->uni_acct_desc .uni_str_len)); /* user description unicode string */ + fprintf(out_hnd, "\t\tWorkstations: %s\n", unistrn2(usr->uni_workstations.buffer, usr->uni_workstations.uni_str_len)); /* workstaions unicode string */ + fprintf(out_hnd, "\t\tUnknown Str : %s\n", unistrn2(usr->uni_unknown_str .buffer, usr->uni_unknown_str .uni_str_len)); /* unknown string unicode string */ + fprintf(out_hnd, "\t\tRemote Dial : %s\n", unistrn2(usr->uni_munged_dial .buffer, usr->uni_munged_dial .uni_str_len)); /* munged remote access unicode string */ + + fprintf(out_hnd, "\t\tLogon Time : %s\n", http_timestring(interpret_nt_time(&(usr->logon_time )))); + fprintf(out_hnd, "\t\tLogoff Time : %s\n", http_timestring(interpret_nt_time(&(usr->logoff_time )))); + fprintf(out_hnd, "\t\tKickoff Time : %s\n", http_timestring(interpret_nt_time(&(usr->kickoff_time )))); + fprintf(out_hnd, "\t\tPassword last set Time : %s\n", http_timestring(interpret_nt_time(&(usr->pass_last_set_time )))); + fprintf(out_hnd, "\t\tPassword can change Time : %s\n", http_timestring(interpret_nt_time(&(usr->pass_can_change_time )))); + fprintf(out_hnd, "\t\tPassword must change Time: %s\n", http_timestring(interpret_nt_time(&(usr->pass_must_change_time)))); + + fprintf(out_hnd, "\t\tunknown_2[0..31]...\n"); /* user passwords? */ + + fprintf(out_hnd, "\t\tuser_rid : %x\n" , usr->user_rid ); /* User ID */ + fprintf(out_hnd, "\t\tgroup_rid: %x\n" , usr->group_rid); /* Group ID */ + fprintf(out_hnd, "\t\tacb_info : %04x\n", usr->acb_info ); /* Account Control Info */ + + fprintf(out_hnd, "\t\tunknown_3: %08x\n", usr->unknown_3); /* 0x00ff ffff */ + fprintf(out_hnd, "\t\tlogon_divs: %d\n", usr->logon_divs); /* 0x0000 00a8 which is 168 which is num hrs in a week */ + fprintf(out_hnd, "\t\tunknown_5: %08x\n", usr->unknown_5); /* 0x0002 0000 */ + + fprintf(out_hnd, "\t\tpadding1[0..7]...\n"); + + if (usr->ptr_logon_hrs) + { + fprintf(out_hnd, "\t\tlogon_hrs[0..%d]...\n", usr->logon_hrs.len); + } + + break; + } + case ACTION_FOOTER: + { + fprintf(out_hnd, "\n"); + break; + } + } +} + diff --git a/source/rpcclient/rpcclient.c b/source/rpcclient/rpcclient.c new file mode 100644 index 00000000000..174cea78ad5 --- /dev/null +++ b/source/rpcclient/rpcclient.c @@ -0,0 +1,757 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + SMB client + Copyright (C) Andrew Tridgell 1994-1998 + + 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. +*/ + +#ifdef SYSLOG +#undef SYSLOG +#endif + +#include "includes.h" + +#ifndef REGISTER +#define REGISTER 0 +#endif + +extern pstring scope; + +extern pstring user_socket_options; + + +extern pstring debugf; +extern int DEBUGLEVEL; + + +extern file_info def_finfo; + +#define CNV_LANG(s) dos2unix_format(s,False) +#define CNV_INPUT(s) unix2dos_format(s,True) + +static int process_tok(fstring tok); +static void cmd_help(struct client_info *info); +static void cmd_quit(struct client_info *info); + +static struct cli_state smbcli; +struct cli_state *smb_cli = &smbcli; + +FILE *out_hnd; + +/**************************************************************************** +initialise smb client structure +****************************************************************************/ +void rpcclient_init(void) +{ + bzero(smb_cli, sizeof(smb_cli)); + cli_initialise(smb_cli); +} + +/**************************************************************************** +make smb client connection +****************************************************************************/ +static BOOL rpcclient_connect(struct client_info *info) +{ + struct nmb_name calling; + struct nmb_name called; + + make_nmb_name(&called , dns_to_netbios_name(info->dest_host ), info->name_type, scope); + make_nmb_name(&calling, dns_to_netbios_name(info->myhostname), 0x0 , scope); + + if (!cli_establish_connection(smb_cli, + info->dest_host, &info->dest_ip, + &calling, &called, + info->share, info->svc_type, + False, True)) + { + DEBUG(0,("rpcclient_connect: connection failed\n")); + cli_shutdown(smb_cli); + return False; + } + + return True; +} + +/**************************************************************************** +stop the smb connection(s?) +****************************************************************************/ +static void rpcclient_stop(void) +{ + cli_shutdown(smb_cli); +} +/**************************************************************************** + This defines the commands supported by this client + ****************************************************************************/ +struct +{ + char *name; + void (*fn)(struct client_info*); + char *description; +} commands[] = +{ +#if 0 + {"ntlogin", cmd_netlogon_login_test, "<username> NT Domain login test"}, +#endif + {"wksinfo", cmd_wks_query_info, "DCE/RPC - Workstation Query Info"}, + {"srvinfo", cmd_srv_query_info, "DCE/RPC - Server Query Info"}, + {"srvsessions",cmd_srv_enum_sess, "DCE/RPC - List sessions on a server"}, + {"srvshares", cmd_srv_enum_shares, "DCE/RPC - List shares on a server"}, + {"srvconnections",cmd_srv_enum_conn, "DCE/RPC - List connections on a server"}, + {"srvfiles", cmd_srv_enum_files, "DCE/RPC - List files on a server"}, + {"lsaquery", cmd_lsa_query_info, "Query Info Policy (domain member or server)"}, + {"lookupsids", cmd_lsa_lookup_sids, "Resolve names from SIDs"}, + {"enumusers", cmd_sam_enum_users, "SAM User Database Query (experimental!)"}, + {"samuser", cmd_sam_query_user, "<username> SAM User Query (experimental!)"}, + {"samtest", cmd_sam_test , "SAM User Encrypted RPC test (experimental!)"}, + {"enumaliases",cmd_sam_enum_aliases, "SAM Aliases Database Query (experimental!)"}, +#if 0 + {"enumgroups", cmd_sam_enum_groups, "SAM Group Database Query (experimental!)"}, +#endif + {"samgroups", cmd_sam_query_groups, "SAM Group Database Query (experimental!)"}, + {"quit", cmd_quit, "logoff the server"}, + {"q", cmd_quit, "logoff the server"}, + {"exit", cmd_quit, "logoff the server"}, + {"bye", cmd_quit, "logoff the server"}, + {"help", cmd_help, "[command] give help on a command"}, + {"?", cmd_help, "[command] give help on a command"}, + {"!", NULL, "run a shell command on the local system"}, + {"", NULL, NULL} +}; + + +/**************************************************************************** +do a (presumably graceful) quit... +****************************************************************************/ +static void cmd_quit(struct client_info *info) +{ + rpcclient_stop(); +#ifdef MEM_MAN + { + extern FILE* dbf; + smb_mem_write_status(dbf); + smb_mem_write_errors(dbf); + smb_mem_write_verbose(dbf); + } +#endif + exit(0); +} + +/**************************************************************************** +help +****************************************************************************/ +static void cmd_help(struct client_info *info) +{ + int i=0,j; + fstring buf; + + if (next_token(NULL,buf,NULL, sizeof(buf))) + { + if ((i = process_tok(buf)) >= 0) + fprintf(out_hnd, "HELP %s:\n\t%s\n\n",commands[i].name,commands[i].description); + } + else + while (commands[i].description) + { + for (j=0; commands[i].description && (j<5); j++) { + fprintf(out_hnd, "%-15s",commands[i].name); + i++; + } + fprintf(out_hnd, "\n"); + } +} + +/******************************************************************* + lookup a command string in the list of commands, including + abbreviations + ******************************************************************/ +static int process_tok(fstring tok) +{ + int i = 0, matches = 0; + int cmd=0; + int tok_len = strlen(tok); + + while (commands[i].fn != NULL) + { + if (strequal(commands[i].name,tok)) + { + matches = 1; + cmd = i; + break; + } + else if (strnequal(commands[i].name, tok, tok_len)) + { + matches++; + cmd = i; + } + i++; + } + + if (matches == 0) + return(-1); + else if (matches == 1) + return(cmd); + else + return(-2); +} + +/**************************************************************************** +wait for keyboard activity, swallowing network packets +****************************************************************************/ +static void wait_keyboard(struct cli_state *cli) +{ + fd_set fds; + struct timeval timeout; + + while (1) + { + FD_ZERO(&fds); + FD_SET(cli->fd,&fds); + FD_SET(fileno(stdin),&fds); + + timeout.tv_sec = 20; + timeout.tv_usec = 0; + sys_select(MAX(cli->fd,fileno(stdin))+1,&fds,&timeout); + + if (FD_ISSET(fileno(stdin),&fds)) + return; + + /* We deliberately use receive_smb instead of + client_receive_smb as we want to receive + session keepalives and then drop them here. + */ + if (FD_ISSET(cli->fd,&fds)) + receive_smb(cli->fd,cli->inbuf,0); + } +} + +/**************************************************************************** + process commands from the client +****************************************************************************/ +static void do_command(struct client_info *info, char *tok, char *line) +{ + int i; + + if ((i = process_tok(tok)) >= 0) + { + commands[i].fn(info); + } + else if (i == -2) + { + fprintf(out_hnd, "%s: command abbreviation ambiguous\n", CNV_LANG(tok)); + } + else + { + fprintf(out_hnd, "%s: command not found\n", CNV_LANG(tok)); + } +} + +/**************************************************************************** + process commands from the client +****************************************************************************/ +static BOOL process( struct client_info *info, char *cmd_str) +{ + pstring line; + char *cmd = cmd_str; + + if (cmd[0] != '\0') while (cmd[0] != '\0') + { + char *p; + fstring tok; + + if ((p = strchr(cmd, ';')) == 0) + { + strncpy(line, cmd, 999); + line[1000] = '\0'; + cmd += strlen(cmd); + } + else + { + if (p - cmd > 999) p = cmd + 999; + strncpy(line, cmd, p - cmd); + line[p - cmd] = '\0'; + cmd = p + 1; + } + + /* input language code to internal one */ + CNV_INPUT (line); + + /* get the first part of the command */ + { + char *ptr = line; + if (!next_token(&ptr,tok,NULL, sizeof(tok))) continue; + } + + do_command(info, tok, line); + } + else while (!feof(stdin)) + { + fstring tok; + + /* display a prompt */ + fprintf(out_hnd, "smb: %s> ", CNV_LANG(info->cur_dir)); + fflush(out_hnd); + +#ifdef CLIX + line[0] = wait_keyboard(smb_cli); + /* this might not be such a good idea... */ + if ( line[0] == EOF) + { + break; + } +#else + wait_keyboard(smb_cli); +#endif + + /* and get a response */ +#ifdef CLIX + fgets( &line[1],999, stdin); +#else + if (!fgets(line,1000,stdin)) + { + break; + } +#endif + + /* input language code to internal one */ + CNV_INPUT (line); + + /* special case - first char is ! */ + if (*line == '!') + { + system(line + 1); + continue; + } + + fprintf(out_hnd, "%s\n", line); + + /* get the first part of the command */ + { + char *ptr = line; + if (!next_token(&ptr,tok,NULL, sizeof(tok))) continue; + } + + do_command(info, tok, line); + } + + return(True); +} + +/**************************************************************************** +usage on the program +****************************************************************************/ +static void usage(char *pname) +{ + fprintf(out_hnd, "Usage: %s service <password> [-d debuglevel] [-l log] ", + pname); + + fprintf(out_hnd, "\nVersion %s\n",VERSION); + fprintf(out_hnd, "\t-d debuglevel set the debuglevel\n"); + fprintf(out_hnd, "\t-l log basename. Basename for log/debug files\n"); + fprintf(out_hnd, "\t-n netbios name. Use this name as my netbios name\n"); + fprintf(out_hnd, "\t-N don't ask for a password\n"); + fprintf(out_hnd, "\t-m max protocol set the max protocol level\n"); + fprintf(out_hnd, "\t-I dest IP use this IP to connect to\n"); + fprintf(out_hnd, "\t-E write messages to stderr instead of stdout\n"); + fprintf(out_hnd, "\t-U username set the network username\n"); + fprintf(out_hnd, "\t-W workgroup set the workgroup name\n"); + fprintf(out_hnd, "\t-c command string execute semicolon separated commands\n"); + fprintf(out_hnd, "\t-t terminal code terminal i/o code {sjis|euc|jis7|jis8|junet|hex}\n"); + fprintf(out_hnd, "\n"); +} + +enum client_action +{ + CLIENT_NONE, + CLIENT_IPC, + CLIENT_SVC +}; + +/**************************************************************************** + main program +****************************************************************************/ + int main(int argc,char *argv[]) +{ + char *pname = argv[0]; + int opt; + extern FILE *dbf; + extern char *optarg; + extern int optind; + static pstring servicesf = CONFIGFILE; + pstring term_code; + char *p; + BOOL got_pass = False; + char *cmd_str=""; + mode_t myumask = 0755; + enum client_action cli_action = CLIENT_NONE; + + struct client_info cli_info; + + pstring password; /* local copy only, if one is entered */ + + out_hnd = stdout; + + rpcclient_init(); + +#ifdef KANJI + pstrcpy(term_code, KANJI); +#else /* KANJI */ + *term_code = 0; +#endif /* KANJI */ + + DEBUGLEVEL = 2; + + cli_info.put_total_size = 0; + cli_info.put_total_time_ms = 0; + cli_info.get_total_size = 0; + cli_info.get_total_time_ms = 0; + + cli_info.dir_total = 0; + cli_info.newer_than = 0; + cli_info.archive_level = 0; + cli_info.print_mode = 1; + + cli_info.translation = False; + cli_info.recurse_dir = False; + cli_info.lowercase = False; + cli_info.prompt = True; + cli_info.abort_mget = True; + + cli_info.dest_ip.s_addr = 0; + cli_info.name_type = 0x20; + + pstrcpy(cli_info.cur_dir , "\\"); + pstrcpy(cli_info.file_sel, ""); + pstrcpy(cli_info.base_dir, ""); + pstrcpy(smb_cli->domain, ""); + pstrcpy(smb_cli->user_name, ""); + pstrcpy(cli_info.myhostname, ""); + pstrcpy(cli_info.dest_host, ""); + + pstrcpy(cli_info.svc_type, "A:"); + pstrcpy(cli_info.share, ""); + pstrcpy(cli_info.service, ""); + + pstrcpy(cli_info.dom.level3_sid, ""); + pstrcpy(cli_info.dom.level3_dom, ""); + pstrcpy(cli_info.dom.level5_sid, ""); + pstrcpy(cli_info.dom.level5_dom, ""); + + smb_cli->nt_pipe_fnum = 0xffff; + + setup_logging(pname, True); + + TimeInit(); + charset_initialise(); + + myumask = umask(0); + umask(myumask); + + if (getenv("USER")) + { + pstrcpy(smb_cli->user_name,getenv("USER")); + + /* modification to support userid%passwd syntax in the USER var + 25.Aug.97, jdblair@uab.edu */ + + if ((p=strchr(smb_cli->user_name,'%'))) + { + *p = 0; + pstrcpy(password,p+1); + got_pass = True; + memset(strchr(getenv("USER"),'%')+1,'X',strlen(password)); + } + strupper(smb_cli->user_name); + } + + password[0] = 0; + + /* modification to support PASSWD environmental var + 25.Aug.97, jdblair@uab.edu */ + if (getenv("PASSWD")) + { + pstrcpy(password,getenv("PASSWD")); + } + + if (*smb_cli->user_name == 0 && getenv("LOGNAME")) + { + pstrcpy(smb_cli->user_name,getenv("LOGNAME")); + strupper(smb_cli->user_name); + } + + if (argc < 2) + { + usage(pname); + exit(1); + } + + if (*argv[1] != '-') + { + + pstrcpy(cli_info.service, argv[1]); + /* Convert any '/' characters in the service name to '\' characters */ + string_replace( cli_info.service, '/','\\'); + argc--; + argv++; + + DEBUG(1,("service: %s\n", cli_info.service)); + + if (count_chars(cli_info.service,'\\') < 3) + { + usage(pname); + printf("\n%s: Not enough '\\' characters in service\n", cli_info.service); + exit(1); + } + + /* + if (count_chars(cli_info.service,'\\') > 3) + { + usage(pname); + printf("\n%s: Too many '\\' characters in service\n", cli_info.service); + exit(1); + } + */ + + if (argc > 1 && (*argv[1] != '-')) + { + got_pass = True; + pstrcpy(password,argv[1]); + memset(argv[1],'X',strlen(argv[1])); + argc--; + argv++; + } + + cli_action = CLIENT_SVC; + } + + while ((opt = getopt(argc, argv,"s:B:O:M:S:i:N:d:l:hI:EB:U:L:t:m:W:T:D:c:")) != EOF) + { + switch (opt) + { + case 'm': + { + /* FIXME ... max_protocol seems to be funny here */ + + int max_protocol = 0; + max_protocol = interpret_protocol(optarg,max_protocol); + fprintf(stderr, "max protocol not currently supported\n"); + break; + } + + case 'O': + { + pstrcpy(user_socket_options,optarg); + break; + } + + case 'S': + { + pstrcpy(cli_info.dest_host,optarg); + strupper(cli_info.dest_host); + cli_action = CLIENT_IPC; + break; + } + + case 'B': + { + iface_set_default(NULL,optarg,NULL); + break; + } + + case 'i': + { + pstrcpy(scope, optarg); + break; + } + + case 'U': + { + char *lp; + pstrcpy(smb_cli->user_name,optarg); + if ((lp=strchr(smb_cli->user_name,'%'))) + { + *lp = 0; + pstrcpy(password,lp+1); + got_pass = True; + memset(strchr(optarg,'%')+1,'X',strlen(password)); + } + break; + } + + case 'W': + { + pstrcpy(smb_cli->domain,optarg); + break; + } + + case 'E': + { + dbf = stderr; + break; + } + + case 'I': + { + cli_info.dest_ip = *interpret_addr2(optarg); + if (zero_ip(cli_info.dest_ip)) + { + exit(1); + } + break; + } + + case 'N': + { + got_pass = True; + break; + } + + case 'd': + { + if (*optarg == 'A') + DEBUGLEVEL = 10000; + else + DEBUGLEVEL = atoi(optarg); + break; + } + + case 'l': + { + slprintf(debugf, sizeof(debugf)-1, + "%s.client",optarg); + break; + } + + case 'c': + { + cmd_str = optarg; + got_pass = True; + break; + } + + case 'h': + { + usage(pname); + exit(0); + break; + } + + case 's': + { + pstrcpy(servicesf, optarg); + break; + } + + case 't': + { + pstrcpy(term_code, optarg); + break; + } + + default: + { + usage(pname); + exit(1); + break; + } + } + } + + if (cli_action == CLIENT_NONE) + { + usage(pname); + exit(1); + } + + DEBUG(3,("%s client started (version %s)\n",timestring(),VERSION)); + + if (!get_myname(cli_info.myhostname, NULL)) + { + fprintf(stderr, "Failed to get my hostname.\n"); + } + + if (!lp_load(servicesf,True, False, False)) + { + fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); + } + + codepage_initialise(lp_client_code_page()); + + if (*smb_cli->domain == 0) pstrcpy(smb_cli->domain,lp_workgroup()); + + load_interfaces(); + + if (cli_action == CLIENT_IPC) + { + pstrcpy(cli_info.share, "IPC$"); + pstrcpy(cli_info.svc_type, "IPC"); + } + + fstrcpy(cli_info.mach_acct, cli_info.myhostname); + strupper(cli_info.mach_acct); + fstrcat(cli_info.mach_acct, "$"); + + /* set the password cache info */ + if (got_pass) + { + if (password[0] == 0) + { + pwd_set_nullpwd(&(smb_cli->pwd)); + } + else + { + pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */ + } + } + else + { + pwd_read(&(smb_cli->pwd), "Enter Password:", True); + } + + /* paranoia: destroy the local copy of the password */ + bzero(password, sizeof(password)); + + /* establish connections. nothing to stop these being re-established. */ + rpcclient_connect(&cli_info); + + DEBUG(5,("rpcclient_connect: smb_cli->fd:%d\n", smb_cli->fd)); + if (smb_cli->fd <= 0) + { + fprintf(stderr, "warning: connection could not be established to %s<%02x>\n", + cli_info.dest_host, cli_info.name_type); + fprintf(stderr, "this version of smbclient may crash if you proceed\n"); + exit(-1); + } + + switch (cli_action) + { + case CLIENT_IPC: + { + process(&cli_info, cmd_str); + break; + } + + default: + { + fprintf(stderr, "unknown client action requested\n"); + break; + } + } + + rpcclient_stop(); + + return(0); +} |