1
0
mirror of https://github.com/samba-team/samba.git synced 2025-12-03 04:23:50 +03:00

ok. *whew*. this is the first completed part of the restructure.

verified that lsaquery, lsalookupsids work, and found some bugs in the
parameters of these commands :-)

soo... we now have an lsa_* api that has the same arguments as the nt
Lsa* api!  cool!

the only significant coding difference is the introduction of a
user_credentials structure, containing user, domain, pass and ntlmssp
flags.
This commit is contained in:
Luke Leighton
-
parent c01b18e632
commit 57bff6fe82
15 changed files with 153 additions and 153 deletions

View File

@@ -78,7 +78,17 @@ struct pwd_info
uchar sess_key[16]; uchar sess_key[16];
}; };
struct cli_state { struct user_credentials
{
fstring user_name;
fstring domain;
struct pwd_info pwd;
uint32 ntlmssp_flags;
};
struct cli_state
{
int port; int port;
int fd; int fd;
uint16 cnum; uint16 cnum;
@@ -88,12 +98,12 @@ struct cli_state {
int protocol; int protocol;
int sec_mode; int sec_mode;
int rap_error; int rap_error;
int privilages; int privileges;
struct user_credentials usr;
fstring eff_name; fstring eff_name;
fstring desthost; fstring desthost;
fstring user_name;
fstring domain;
/* /*
* The following strings are the * The following strings are the
@@ -108,10 +118,8 @@ struct cli_state {
fstring dev; fstring dev;
struct nmb_name called; struct nmb_name called;
struct nmb_name calling; struct nmb_name calling;
fstring full_dest_host_name;
struct in_addr dest_ip; struct in_addr dest_ip;
struct pwd_info pwd;
unsigned char cryptkey[8]; unsigned char cryptkey[8];
unsigned char lm_cli_chal[8]; unsigned char lm_cli_chal[8];
unsigned char nt_cli_chal[128]; unsigned char nt_cli_chal[128];

View File

@@ -481,6 +481,7 @@ int set_maxfiles(int requested_max);
void reg_get_subkey(char *full_keyname, char *key_name, char *subkey_name); void reg_get_subkey(char *full_keyname, char *key_name, char *subkey_name);
BOOL reg_split_key(const char *full_keyname, uint32 *reg_type, char *key_name); BOOL reg_split_key(const char *full_keyname, uint32 *reg_type, char *key_name);
BOOL become_user_permanently(uid_t uid, gid_t gid); BOOL become_user_permanently(uid_t uid, gid_t gid);
BOOL resolve_srv_name(const char* srv_name, fstring dest_host, struct in_addr *ip);
/*The following definitions come from lib/util_array.c */ /*The following definitions come from lib/util_array.c */
@@ -668,6 +669,7 @@ void unistr2_free(UNISTR2 *name);
/*The following definitions come from libsmb/clientgen.c */ /*The following definitions come from libsmb/clientgen.c */
void copy_user_creds(struct user_credentials *to, const struct user_credentials *from);
int cli_set_port(struct cli_state *cli, int port); int cli_set_port(struct cli_state *cli, int port);
char *cli_errstr(struct cli_state *cli); char *cli_errstr(struct cli_state *cli);
void cli_safe_smb_errstr(struct cli_state *cli, char *msg, size_t len); void cli_safe_smb_errstr(struct cli_state *cli, char *msg, size_t len);
@@ -747,6 +749,7 @@ BOOL cli_negprot(struct cli_state *cli);
BOOL cli_session_request(struct cli_state *cli, BOOL cli_session_request(struct cli_state *cli,
struct nmb_name *calling, struct nmb_name *called); struct nmb_name *calling, struct nmb_name *called);
BOOL cli_connect(struct cli_state *cli, const char *host, struct in_addr *ip); BOOL cli_connect(struct cli_state *cli, const char *host, struct in_addr *ip);
void cli_init_creds(struct cli_state *cli, const struct user_credentials *usr);
struct cli_state *cli_initialise(struct cli_state *cli); struct cli_state *cli_initialise(struct cli_state *cli);
void cli_close_socket(struct cli_state *cli); void cli_close_socket(struct cli_state *cli);
void cli_shutdown(struct cli_state *cli); void cli_shutdown(struct cli_state *cli);

View File

@@ -882,7 +882,8 @@ static BOOL lookup_remote_ntname(const char *ntname, DOM_SID *sid, uint8 *type)
struct cli_state cli; struct cli_state cli;
POLICY_HND lsa_pol; POLICY_HND lsa_pol;
fstring srv_name; fstring srv_name;
extern struct cli_state *rpc_smb_cli; extern struct user_credentials *usr_creds;
struct user_credentials usr;
BOOL res3 = True; BOOL res3 = True;
BOOL res4 = True; BOOL res4 = True;
@@ -891,7 +892,10 @@ static BOOL lookup_remote_ntname(const char *ntname, DOM_SID *sid, uint8 *type)
uint8 *types; uint8 *types;
char *names[1]; char *names[1];
rpc_smb_cli = &cli; usr_creds = &usr;
ZERO_STRUCT(usr);
pwd_set_nullpwd(&usr.pwd);
DEBUG(5,("lookup_remote_ntname: %s\n", ntname)); DEBUG(5,("lookup_remote_ntname: %s\n", ntname));

View File

@@ -3228,3 +3228,24 @@ BOOL become_user_permanently(uid_t uid, gid_t gid)
return(True); return(True);
} }
BOOL resolve_srv_name(const char* srv_name, fstring dest_host,
struct in_addr *ip)
{
DEBUG(10,("resolve_srv_name: %s\n", srv_name));
if (srv_name == NULL || strequal("\\\\.", srv_name))
{
fstrcpy(dest_host, global_myname);
ip = interpret_addr2("127.0.0.1");
return True;
}
if (!strnequal("\\\\", srv_name, 2))
{
return False;
}
fstrcpy(dest_host, &srv_name[2]);
return resolve_name(dest_host, ip, 0x20);
}

View File

@@ -31,6 +31,14 @@ extern int DEBUGLEVEL;
* set the port that will be used for connections by the client * set the port that will be used for connections by the client
*/ */
void copy_user_creds(struct user_credentials *to, const struct user_credentials *from)
{
safe_strcpy(to->domain , from->domain , sizeof(from->domain )-1);
safe_strcpy(to->user_name, from->user_name, sizeof(from->user_name)-1);
memcpy(&to->pwd, &from->pwd, sizeof(from->pwd));
to->ntlmssp_flags = from->ntlmssp_flags;
};
int cli_set_port(struct cli_state *cli, int port) int cli_set_port(struct cli_state *cli, int port)
{ {
@@ -585,7 +593,7 @@ BOOL cli_NetWkstaUserLogon(struct cli_state *cli,char *user, char *workstation)
if (cli->rap_error == 0) { if (cli->rap_error == 0) {
DEBUG(4,("NetWkstaUserLogon success\n")); DEBUG(4,("NetWkstaUserLogon success\n"));
cli->privilages = SVAL(p, 24); cli->privileges = SVAL(p, 24);
fstrcpy(cli->eff_name,p+2); fstrcpy(cli->eff_name,p+2);
} else { } else {
DEBUG(1,("NetwkstaUserLogon gave error %d\n", cli->rap_error)); DEBUG(1,("NetwkstaUserLogon gave error %d\n", cli->rap_error));
@@ -1003,10 +1011,10 @@ static BOOL cli_calc_session_pwds(struct cli_state *cli,
cli->nt_cli_chal, cli->nt_cli_chal,
&cli->nt_cli_chal_len, &cli->nt_cli_chal_len,
cli->calling.name, cli->calling.name,
cli->domain); cli->usr.domain);
nt_owf_gen(pword, nt_owf); nt_owf_gen(pword, nt_owf);
ntv2_owf_gen(nt_owf, cli->user_name, cli->domain, kr); ntv2_owf_gen(nt_owf, cli->usr.user_name, cli->usr.domain, kr);
/* lm # */ /* lm # */
memcpy(pword, cli->lm_cli_chal, 8); memcpy(pword, cli->lm_cli_chal, 8);
@@ -1063,7 +1071,7 @@ BOOL cli_session_setup(struct cli_state *cli,
return False; return False;
} }
fstrcpy(cli->user_name, user); fstrcpy(cli->usr.user_name, user);
return cli_calc_session_pwds(cli, pword, ntpword, return cli_calc_session_pwds(cli, pword, ntpword,
pass, &passlen, pass, &passlen,
@@ -2695,6 +2703,15 @@ BOOL cli_connect(struct cli_state *cli, const char *host, struct in_addr *ip)
} }
/****************************************************************************
initialise a client structure
****************************************************************************/
void cli_init_creds(struct cli_state *cli, const struct user_credentials *usr)
{
copy_user_creds(&cli->usr, usr);
cli->ntlmssp_cli_flgs = usr->ntlmssp_flags;
}
/**************************************************************************** /****************************************************************************
initialise a client structure initialise a client structure
****************************************************************************/ ****************************************************************************/
@@ -2913,7 +2930,7 @@ BOOL cli_reestablish_connection(struct cli_state *cli)
DEBUG(5,("cli_reestablish_connection: %s connecting to %s (ip %s) - %s [%s]\n", DEBUG(5,("cli_reestablish_connection: %s connecting to %s (ip %s) - %s [%s]\n",
nmb_namestr(&calling), nmb_namestr(&called), nmb_namestr(&calling), nmb_namestr(&called),
inet_ntoa(cli->dest_ip), inet_ntoa(cli->dest_ip),
cli->user_name, cli->domain)); cli->usr.user_name, cli->usr.domain));
cli->fd = -1; cli->fd = -1;
@@ -2951,7 +2968,7 @@ BOOL cli_establish_connection(struct cli_state *cli,
DEBUG(5,("cli_establish_connection: %s connecting to %s (%s) - %s [%s] with NTLM%s\n", DEBUG(5,("cli_establish_connection: %s connecting to %s (%s) - %s [%s] with NTLM%s\n",
callingstr, calledstr, inet_ntoa(*dest_ip), callingstr, calledstr, inet_ntoa(*dest_ip),
cli->user_name, cli->domain, cli->usr.user_name, cli->usr.domain,
cli->use_ntlmv2 ? "v2" : "v1")); cli->use_ntlmv2 ? "v2" : "v1"));
/* establish connection */ /* establish connection */
@@ -2991,10 +3008,10 @@ BOOL cli_establish_connection(struct cli_state *cli,
return False; return False;
} }
if (cli->domain[0] == 0) if (cli->usr.domain[0] == 0)
{ {
safe_strcpy(cli->domain, cli->server_domain, safe_strcpy(cli->usr.domain, cli->server_domain,
sizeof(cli->domain)); sizeof(cli->usr.domain));
} }
if (IS_BITS_SET_ALL(cli->capabilities, CAP_EXTENDED_SECURITY)) if (IS_BITS_SET_ALL(cli->capabilities, CAP_EXTENDED_SECURITY))
@@ -3064,10 +3081,10 @@ BOOL cli_establish_connection(struct cli_state *cli,
buf_len = PTR_DIFF(p, pwd_buf); buf_len = PTR_DIFF(p, pwd_buf);
/* first session negotiation stage */ /* first session negotiation stage */
if (!cli_session_setup_x(cli, cli->user_name, if (!cli_session_setup_x(cli, cli->usr.user_name,
pwd_buf, buf_len, pwd_buf, buf_len,
NULL, 0, NULL, 0,
cli->domain)) cli->usr.domain))
{ {
DEBUG(1,("failed session setup\n")); DEBUG(1,("failed session setup\n"));
if (do_shutdown) if (do_shutdown)
@@ -3103,17 +3120,17 @@ BOOL cli_establish_connection(struct cli_state *cli,
if (cli->use_ntlmv2 != False) if (cli->use_ntlmv2 != False)
{ {
DEBUG(10,("cli_establish_connection: NTLMv2\n")); DEBUG(10,("cli_establish_connection: NTLMv2\n"));
pwd_make_lm_nt_owf2(&(cli->pwd), cli->cryptkey, pwd_make_lm_nt_owf2(&(cli->usr.pwd), cli->cryptkey,
cli->user_name, calling->name, cli->domain); cli->usr.user_name, calling->name, cli->usr.domain);
} }
else else
{ {
DEBUG(10,("cli_establish_connection: NTLMv1\n")); DEBUG(10,("cli_establish_connection: NTLMv1\n"));
pwd_make_lm_nt_owf(&(cli->pwd), cli->cryptkey); pwd_make_lm_nt_owf(&(cli->usr.pwd), cli->cryptkey);
} }
create_ntlmssp_resp(&cli->pwd, cli->domain, create_ntlmssp_resp(&cli->usr.pwd, cli->usr.domain,
cli->user_name, cli->calling.name, cli->usr.user_name, cli->calling.name,
cli->ntlmssp_cli_flgs, cli->ntlmssp_cli_flgs,
&auth_resp); &auth_resp);
prs_link(NULL, &auth_resp, NULL); prs_link(NULL, &auth_resp, NULL);
@@ -3172,10 +3189,10 @@ BOOL cli_establish_connection(struct cli_state *cli,
*p_oem++ = gssapi_len & 0xff; *p_oem++ = gssapi_len & 0xff;
/* second session negotiation stage */ /* second session negotiation stage */
if (!cli_session_setup_x(cli, cli->user_name, if (!cli_session_setup_x(cli, cli->usr.user_name,
pwd_buf, buf_len, pwd_buf, buf_len,
NULL, 0, NULL, 0,
cli->domain)) cli->usr.domain))
{ {
DEBUG(1,("failed session setup\n")); DEBUG(1,("failed session setup\n"));
if (do_shutdown) if (do_shutdown)
@@ -3202,12 +3219,12 @@ BOOL cli_establish_connection(struct cli_state *cli,
} }
} }
} }
else if (cli->pwd.cleartext || cli->pwd.null_pwd) else if (cli->usr.pwd.cleartext || cli->usr.pwd.null_pwd)
{ {
fstring passwd, ntpasswd; fstring passwd, ntpasswd;
int pass_len = 0, ntpass_len = 0; int pass_len = 0, ntpass_len = 0;
if (cli->pwd.null_pwd) if (cli->usr.pwd.null_pwd)
{ {
/* attempt null session */ /* attempt null session */
passwd[0] = ntpasswd[0] = 0; passwd[0] = ntpasswd[0] = 0;
@@ -3216,15 +3233,15 @@ BOOL cli_establish_connection(struct cli_state *cli,
else else
{ {
/* attempt clear-text session */ /* attempt clear-text session */
pwd_get_cleartext(&(cli->pwd), passwd); pwd_get_cleartext(&(cli->usr.pwd), passwd);
pass_len = strlen(passwd); pass_len = strlen(passwd);
} }
/* attempt clear-text session */ /* attempt clear-text session */
if (!cli_session_setup(cli, cli->user_name, if (!cli_session_setup(cli, cli->usr.user_name,
passwd, pass_len, passwd, pass_len,
ntpasswd, ntpass_len, ntpasswd, ntpass_len,
cli->domain)) cli->usr.domain))
{ {
DEBUG(1,("failed session setup\n")); DEBUG(1,("failed session setup\n"));
if (do_shutdown) if (do_shutdown)
@@ -3257,23 +3274,23 @@ BOOL cli_establish_connection(struct cli_state *cli,
if (cli->use_ntlmv2 != False) if (cli->use_ntlmv2 != False)
{ {
DEBUG(10,("cli_establish_connection: NTLMv2\n")); DEBUG(10,("cli_establish_connection: NTLMv2\n"));
pwd_make_lm_nt_owf2(&(cli->pwd), cli->cryptkey, pwd_make_lm_nt_owf2(&(cli->usr.pwd), cli->cryptkey,
cli->user_name, calling->name, cli->domain); cli->usr.user_name, calling->name, cli->usr.domain);
} }
else else
{ {
DEBUG(10,("cli_establish_connection: NTLMv1\n")); DEBUG(10,("cli_establish_connection: NTLMv1\n"));
pwd_make_lm_nt_owf(&(cli->pwd), cli->cryptkey); pwd_make_lm_nt_owf(&(cli->usr.pwd), cli->cryptkey);
} }
pwd_get_lm_nt_owf(&(cli->pwd), lm_sess_pwd, nt_sess_pwd, pwd_get_lm_nt_owf(&(cli->usr.pwd), lm_sess_pwd, nt_sess_pwd,
&nt_sess_pwd_len, cli->sess_key); &nt_sess_pwd_len, cli->sess_key);
/* attempt encrypted session */ /* attempt encrypted session */
if (!cli_session_setup_x(cli, cli->user_name, if (!cli_session_setup_x(cli, cli->usr.user_name,
(char*)lm_sess_pwd, sizeof(lm_sess_pwd), (char*)lm_sess_pwd, sizeof(lm_sess_pwd),
(char*)nt_sess_pwd, nt_sess_pwd_len, (char*)nt_sess_pwd, nt_sess_pwd_len,
cli->domain)) cli->usr.domain))
{ {
DEBUG(1,("failed session setup\n")); DEBUG(1,("failed session setup\n"));
@@ -3384,7 +3401,7 @@ BOOL cli_connect_serverlist(struct cli_state *cli, char *p)
*/ */
make_nmb_name(&stupid_smbserver_called , "*SMBSERVER", 0x20, scope); make_nmb_name(&stupid_smbserver_called , "*SMBSERVER", 0x20, scope);
pwd_set_nullpwd(&cli->pwd); pwd_set_nullpwd(&cli->usr.pwd);
if (!cli_establish_connection(cli, remote_machine, &dest_ip, if (!cli_establish_connection(cli, remote_machine, &dest_ip,
&calling, &called, &calling, &called,

View File

@@ -73,7 +73,7 @@ addresses. Cannot add to ourselves.\n", remote_machine));
cli.protocol = PROTOCOL_NT1; cli.protocol = PROTOCOL_NT1;
pwd_set_nullpwd(&cli.pwd); pwd_set_nullpwd(&cli.usr.pwd);
if (!cli_establish_connection(&cli, remote_machine, &cli.dest_ip, if (!cli_establish_connection(&cli, remote_machine, &cli.dest_ip,
&calling, &called, &calling, &called,

View File

@@ -31,8 +31,6 @@
extern int DEBUGLEVEL; extern int DEBUGLEVEL;
extern struct cli_state *rpc_smb_cli;
/**************************************************************************** /****************************************************************************
obtain the sid from the PDC. do some verification along the way... obtain the sid from the PDC. do some verification along the way...
****************************************************************************/ ****************************************************************************/
@@ -45,8 +43,12 @@ BOOL get_domain_sids(const char *myname,
BOOL res = True; BOOL res = True;
fstring dom3; fstring dom3;
fstring dom5; fstring dom5;
extern struct user_credentials *usr_creds;
rpc_smb_cli = &cli; struct user_credentials usr;
usr_creds = &usr;
ZERO_STRUCT(usr);
pwd_set_nullpwd(&usr.pwd);
if (sid3 == NULL && sid5 == NULL) if (sid3 == NULL && sid5 == NULL)
{ {
@@ -142,7 +144,12 @@ BOOL get_trust_sid_and_domain(const char* myname, char *server,
fstring dom3; fstring dom3;
fstring dom5; fstring dom5;
rpc_smb_cli = &cli; extern struct user_credentials *usr_creds;
struct user_credentials usr;
usr_creds = &usr;
ZERO_STRUCT(usr);
pwd_set_nullpwd(&usr.pwd);
if (!cli_connect_serverlist(&cli, server)) if (!cli_connect_serverlist(&cli, server))
{ {
@@ -478,7 +485,7 @@ BOOL lsa_query_secret(POLICY_HND *hnd, STRING2 *secret,
memcpy(&enc_secret, &(r_q.info.value.enc_secret), sizeof(STRING2)); memcpy(&enc_secret, &(r_q.info.value.enc_secret), sizeof(STRING2));
memcpy(last_update, &(r_q.info.last_update), sizeof(NTTIME)); memcpy(last_update, &(r_q.info.last_update), sizeof(NTTIME));
valid_info = nt_decrypt_string2(secret, &enc_secret, valid_info = nt_decrypt_string2(secret, &enc_secret,
(char*)(cli->pwd.smb_nt_pwd)); (char*)(cli->usr.pwd.smb_nt_pwd));
} }
} }

View File

@@ -572,8 +572,8 @@ BOOL do_sam_sync(struct cli_state *cli, uchar trust_passwd[16],
*num_deltas = 0; *num_deltas = 0;
DEBUG(5,("Attempting SAM sync with PDC, domain: %s name: %s\n", DEBUG(5,("Attempting SAM sync with PDC: %s\n",
cli->domain, srv_name)); srv_name));
/* open NETLOGON session. negotiate credentials */ /* open NETLOGON session. negotiate credentials */
res = res ? cli_nt_session_open(cli, PIPE_NETLOGON, &nt_pipe_fnum) : False; res = res ? cli_nt_session_open(cli, PIPE_NETLOGON, &nt_pipe_fnum) : False;

View File

@@ -55,9 +55,7 @@ BOOL synchronise_passdb(void)
return False; return False;
} }
pstrcpy(cli.domain, lp_workgroup()); if (!trust_get_passwd(trust_passwd, lp_workgroup(), global_myname))
if (!trust_get_passwd(trust_passwd, cli.domain, global_myname))
{ {
return False; return False;
} }

View File

@@ -903,7 +903,7 @@ static BOOL rpc_pipe_bind(struct cli_state *cli, uint16 fnum,
ntlmssp_auth ? &auth_ntlm : NULL, ntlmssp_auth ? &auth_ntlm : NULL,
rpc_call_id, rpc_call_id,
abstract, transfer, abstract, transfer,
global_myname, cli->domain, cli->ntlmssp_cli_flgs); global_myname, cli->usr.domain, cli->usr.ntlmssp_flags);
/* this is a hack due to limitations in rpc_api_pipe */ /* this is a hack due to limitations in rpc_api_pipe */
prs_init(&data, mem_buf_len(hdr.data), 4, 0x0, False); prs_init(&data, mem_buf_len(hdr.data), 4, 0x0, False);
@@ -967,16 +967,16 @@ static BOOL rpc_pipe_bind(struct cli_state *cli, uint16 fnum,
prs_init(&hdr_autha, 1024, 4, SAFETY_MARGIN, False); prs_init(&hdr_autha, 1024, 4, SAFETY_MARGIN, False);
prs_init(&auth_resp, 1024, 4, SAFETY_MARGIN, False); prs_init(&auth_resp, 1024, 4, SAFETY_MARGIN, False);
pwd_make_lm_nt_owf(&cli->pwd, rhdr_chal.challenge); pwd_make_lm_nt_owf(&cli->usr.pwd, rhdr_chal.challenge);
create_rpc_bind_resp(&cli->pwd, cli->domain, create_rpc_bind_resp(&cli->usr.pwd, cli->usr.domain,
cli->user_name, global_myname, cli->usr.user_name, global_myname,
cli->ntlmssp_cli_flgs, cli->ntlmssp_cli_flgs,
rpc_call_id, rpc_call_id,
&hdra, &hdr_autha, &auth_resp); &hdra, &hdr_autha, &auth_resp);
pwd_get_lm_nt_owf(&cli->pwd, lm_owf, NULL, NULL, NULL); pwd_get_lm_nt_owf(&cli->usr.pwd, lm_owf, NULL, NULL, NULL);
pwd_get_lm_nt_16(&cli->pwd, lm_hash, NULL); pwd_get_lm_nt_16(&cli->usr.pwd, lm_hash, NULL);
NTLMSSPOWFencrypt(lm_hash, lm_owf, p24); NTLMSSPOWFencrypt(lm_hash, lm_owf, p24);
{ {
unsigned char j = 0; unsigned char j = 0;

View File

@@ -48,7 +48,7 @@ void cmd_lsa_enum_trust_dom(struct client_info *info, int argc, char *argv[])
BOOL res = True; BOOL res = True;
fstrcpy(srv_name, "\\\\"); fstrcpy(srv_name, "\\\\");
fstrcat(srv_name, info->myhostname); fstrcat(srv_name, info->dest_host);
strupper(srv_name); strupper(srv_name);
DEBUG(4,("cmd_lsa_enum_trust_dom: server:%s\n", srv_name)); DEBUG(4,("cmd_lsa_enum_trust_dom: server:%s\n", srv_name));
@@ -106,7 +106,7 @@ void cmd_lsa_query_info(struct client_info *info, int argc, char *argv[])
ZERO_STRUCT(info->dom.level5_sid); ZERO_STRUCT(info->dom.level5_sid);
fstrcpy(srv_name, "\\\\"); fstrcpy(srv_name, "\\\\");
fstrcat(srv_name, info->myhostname); fstrcat(srv_name, info->dest_host);
strupper(srv_name); strupper(srv_name);
DEBUG(4,("cmd_lsa_query_info: server:%s\n", srv_name)); DEBUG(4,("cmd_lsa_query_info: server:%s\n", srv_name));
@@ -180,7 +180,7 @@ void cmd_lsa_lookup_names(struct client_info *info, int argc, char *argv[])
BOOL res = True; BOOL res = True;
fstrcpy(srv_name, "\\\\"); fstrcpy(srv_name, "\\\\");
fstrcat(srv_name, info->myhostname); fstrcat(srv_name, info->dest_host);
strupper(srv_name); strupper(srv_name);
DEBUG(4,("cmd_lsa_lookup_names: server: %s\n", srv_name)); DEBUG(4,("cmd_lsa_lookup_names: server: %s\n", srv_name));
@@ -251,7 +251,7 @@ void cmd_lsa_lookup_sids(struct client_info *info, int argc, char *argv[])
BOOL res = True; BOOL res = True;
fstrcpy(srv_name, "\\\\"); fstrcpy(srv_name, "\\\\");
fstrcat(srv_name, info->myhostname); fstrcat(srv_name, info->dest_host);
strupper(srv_name); strupper(srv_name);
DEBUG(4,("cmd_lsa_lookup_sids: server: %s\n", srv_name)); DEBUG(4,("cmd_lsa_lookup_sids: server: %s\n", srv_name));

View File

@@ -34,6 +34,7 @@ extern int DEBUGLEVEL;
#define DEBUG_TESTING #define DEBUG_TESTING
extern struct cli_state *smb_cli; extern struct cli_state *smb_cli;
extern struct user_credentials *usr_creds;
extern FILE* out_hnd; extern FILE* out_hnd;
extern pstring global_myname; extern pstring global_myname;
@@ -68,7 +69,7 @@ void cmd_netlogon_login_test(struct client_info *info, int argc, char *argv[])
if (argc < 1) if (argc < 1)
{ {
fstrcpy(nt_user_name, smb_cli->user_name); fstrcpy(nt_user_name, usr_creds->user_name);
if (nt_user_name[0] == 0) if (nt_user_name[0] == 0)
{ {
report(out_hnd,"ntlogin: must specify username with anonymous connection\n"); report(out_hnd,"ntlogin: must specify username with anonymous connection\n");
@@ -94,12 +95,12 @@ void cmd_netlogon_login_test(struct client_info *info, int argc, char *argv[])
DEBUG(5,("do_nt_login_test: username %s\n", nt_user_name)); DEBUG(5,("do_nt_login_test: username %s\n", nt_user_name));
res = res ? trust_get_passwd(trust_passwd, smb_cli->domain, info->myhostname) : False; res = res ? trust_get_passwd(trust_passwd, usr_creds->domain, info->myhostname) : False;
#if 0 #if 0
/* check whether the user wants to change their machine password */ /* check whether the user wants to change their machine password */
res = res ? trust_account_check(info->dest_ip, info->dest_host, res = res ? trust_account_check(info->dest_ip, info->dest_host,
info->myhostname, smb_cli->domain, info->myhostname, usr_creds->domain,
info->mach_acct, new_mach_pwd) : False; info->mach_acct, new_mach_pwd) : False;
#endif #endif
/* open NETLOGON session. negotiate credentials */ /* open NETLOGON session. negotiate credentials */
@@ -130,7 +131,7 @@ void cmd_netlogon_login_test(struct client_info *info, int argc, char *argv[])
/* do an NT login */ /* do an NT login */
res = res ? cli_nt_login_interactive(smb_cli, nt_pipe_fnum, res = res ? cli_nt_login_interactive(smb_cli, nt_pipe_fnum,
smb_cli->domain, nt_user_name, usr_creds->domain, nt_user_name,
getuid(), nt_password, getuid(), nt_password,
&info->dom.ctr, &info->dom.user_info3) : False; &info->dom.ctr, &info->dom.user_info3) : False;
@@ -174,7 +175,7 @@ void cmd_netlogon_domain_test(struct client_info *info, int argc, char *argv[])
fstrcpy(inter_dom_acct, nt_trust_dom); fstrcpy(inter_dom_acct, nt_trust_dom);
fstrcat(inter_dom_acct, "$"); fstrcat(inter_dom_acct, "$");
res = res ? trust_get_passwd(trust_passwd, smb_cli->domain, nt_trust_dom) : False; res = res ? trust_get_passwd(trust_passwd, usr_creds->domain, nt_trust_dom) : False;
/* open NETLOGON session. negotiate credentials */ /* open NETLOGON session. negotiate credentials */
res = res ? cli_nt_session_open(smb_cli, PIPE_NETLOGON, &nt_pipe_fnum) : False; res = res ? cli_nt_session_open(smb_cli, PIPE_NETLOGON, &nt_pipe_fnum) : False;
@@ -203,7 +204,7 @@ void cmd_sam_sync(struct client_info *info, int argc, char *argv[])
uchar trust_passwd[16]; uchar trust_passwd[16];
extern pstring global_myname; extern pstring global_myname;
if (!trust_get_passwd(trust_passwd, smb_cli->domain, global_myname)) if (!trust_get_passwd(trust_passwd, usr_creds->domain, global_myname))
{ {
report(out_hnd, "cmd_sam_sync: no trust account password\n"); report(out_hnd, "cmd_sam_sync: no trust account password\n");
return; return;

View File

@@ -34,6 +34,7 @@ extern int DEBUGLEVEL;
#define DEBUG_TESTING #define DEBUG_TESTING
extern struct cli_state *smb_cli; extern struct cli_state *smb_cli;
extern struct user_credentials *usr_creds;
extern FILE* out_hnd; extern FILE* out_hnd;
@@ -151,7 +152,7 @@ void cmd_sam_ntchange_pwd(struct client_info *info, int argc, char *argv[])
new_passwd = (char*)getpass("New Password (ONCE ONLY - get it right :-)"); new_passwd = (char*)getpass("New Password (ONCE ONLY - get it right :-)");
nt_lm_owf_gen(new_passwd, lm_newhash, nt_newhash); nt_lm_owf_gen(new_passwd, lm_newhash, nt_newhash);
pwd_get_lm_nt_16(&(smb_cli->pwd), lm_oldhash, nt_oldhash ); pwd_get_lm_nt_16(&(usr_creds->pwd), lm_oldhash, nt_oldhash );
make_oem_passwd_hash(nt_newpass, new_passwd, nt_oldhash, True); make_oem_passwd_hash(nt_newpass, new_passwd, nt_oldhash, True);
make_oem_passwd_hash(lm_newpass, new_passwd, lm_oldhash, True); make_oem_passwd_hash(lm_newpass, new_passwd, lm_oldhash, True);
E_old_pw_hash(lm_newhash, lm_oldhash, lm_hshhash); E_old_pw_hash(lm_newhash, lm_oldhash, lm_hshhash);
@@ -176,7 +177,7 @@ void cmd_sam_ntchange_pwd(struct client_info *info, int argc, char *argv[])
/* establish a connection. */ /* establish a connection. */
res = res ? samr_chgpasswd_user(smb_cli, fnum, res = res ? samr_chgpasswd_user(smb_cli, fnum,
srv_name, smb_cli->user_name, srv_name, usr_creds->user_name,
nt_newpass, nt_hshhash, nt_newpass, nt_hshhash,
lm_newpass, lm_hshhash) : False; lm_newpass, lm_hshhash) : False;
/* close the session */ /* close the session */

View File

@@ -35,6 +35,7 @@ extern int DEBUGLEVEL;
extern FILE* out_hnd; extern FILE* out_hnd;
extern struct cli_state *smb_cli; extern struct cli_state *smb_cli;
extern struct user_credentials *usr_creds;
extern int smb_tidx; extern int smb_tidx;
/**************************************************************************** /****************************************************************************
@@ -127,7 +128,7 @@ void cmd_spoolss_open_printer_ex(struct client_info *info, int argc, char *argv[
strupper(srv_name); strupper(srv_name);
DEBUG(4,("spoolopen - printer: %s server: %s user: %s\n", DEBUG(4,("spoolopen - printer: %s server: %s user: %s\n",
printer_name, srv_name, smb_cli->user_name)); printer_name, srv_name, usr_creds->user_name));
DEBUG(5, ("cmd_spoolss_open_printer_ex: smb_cli->fd:%d\n", smb_cli->fd)); DEBUG(5, ("cmd_spoolss_open_printer_ex: smb_cli->fd:%d\n", smb_cli->fd));
@@ -137,7 +138,7 @@ void cmd_spoolss_open_printer_ex(struct client_info *info, int argc, char *argv[
res = res ? spoolss_open_printer_ex(smb_cli, nt_pipe_fnum, res = res ? spoolss_open_printer_ex(smb_cli, nt_pipe_fnum,
printer_name, printer_name,
0, 0, 0, 0, 0, 0,
srv_name, smb_cli->user_name, srv_name, usr_creds->user_name,
&hnd) : False; &hnd) : False;
res = res ? spoolss_closeprinter(smb_cli, nt_pipe_fnum, &hnd) : False; res = res ? spoolss_closeprinter(smb_cli, nt_pipe_fnum, &hnd) : False;
@@ -255,10 +256,10 @@ void cmd_spoolss_enum_jobs(struct client_info *info, int argc, char *argv[])
strupper(srv_name); strupper(srv_name);
DEBUG(4,("spoolopen - printer: %s server: %s user: %s\n", DEBUG(4,("spoolopen - printer: %s server: %s user: %s\n",
printer_name, srv_name, smb_cli->user_name)); printer_name, srv_name, usr_creds->user_name));
if (msrpc_spoolss_enum_jobs(smb_cli, if (msrpc_spoolss_enum_jobs(smb_cli,
srv_name, smb_cli->user_name, printer_name, srv_name, usr_creds->user_name, printer_name,
level, &num, &ctr, level, &num, &ctr,
spool_job_info_ctr)) spool_job_info_ctr))
{ {

View File

@@ -46,9 +46,10 @@ static int process_tok(fstring tok);
static void cmd_help(struct client_info *info, int argc, char *argv[]); static void cmd_help(struct client_info *info, int argc, char *argv[]);
static void cmd_quit(struct client_info *info, int argc, char *argv[]); static void cmd_quit(struct client_info *info, int argc, char *argv[]);
static struct user_credentials usr;
static struct cli_state smbcli; static struct cli_state smbcli;
struct cli_state *smb_cli = &smbcli; struct cli_state *smb_cli = &smbcli;
extern struct cli_state *rpc_smb_cli;
static struct client_info cli_info; static struct client_info cli_info;
@@ -57,52 +58,6 @@ static uint32 cmd_argc = 0;
FILE *out_hnd; FILE *out_hnd;
/****************************************************************************
initialise smb client structure
****************************************************************************/
void rpcclient_init(void)
{
bzero(smb_cli, sizeof(smb_cli));
rpc_smb_cli = smb_cli;
cli_initialise(smb_cli);
smb_cli->capabilities |= CAP_NT_SMBS | CAP_STATUS32;
}
/****************************************************************************
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);
smb_cli->use_ntlmv2 = lp_client_ntlmv2();
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);
}
#define COMPL_NONE 0 #define COMPL_NONE 0
#define COMPL_REGKEY 1 #define COMPL_REGKEY 1
#define COMPL_SAMUSR 3 #define COMPL_SAMUSR 3
@@ -618,7 +573,6 @@ do a (presumably graceful) quit...
****************************************************************************/ ****************************************************************************/
static void cmd_quit(struct client_info *info, int argc, char *argv[]) static void cmd_quit(struct client_info *info, int argc, char *argv[])
{ {
rpcclient_stop();
#ifdef MEM_MAN #ifdef MEM_MAN
{ {
extern FILE* dbf; extern FILE* dbf;
@@ -1375,14 +1329,17 @@ static char *complete_cmd_null(char *text, int state)
char *cmd_str=""; char *cmd_str="";
mode_t myumask = 0755; mode_t myumask = 0755;
enum client_action cli_action = CLIENT_NONE; enum client_action cli_action = CLIENT_NONE;
extern struct user_credentials *usr_creds;
pstring password; /* local copy only, if one is entered */ pstring password; /* local copy only, if one is entered */
usr.ntlmssp_flags = 0x0;
usr_creds = &usr;
out_hnd = stdout; out_hnd = stdout;
fstrcpy(debugf, argv[0]); fstrcpy(debugf, argv[0]);
init_policy_hnd(64); init_policy_hnd(64);
rpcclient_init();
#ifdef KANJI #ifdef KANJI
pstrcpy(term_code, KANJI); pstrcpy(term_code, KANJI);
@@ -1414,8 +1371,8 @@ static char *complete_cmd_null(char *text, int state)
pstrcpy(cli_info.cur_dir , "\\"); pstrcpy(cli_info.cur_dir , "\\");
pstrcpy(cli_info.file_sel, ""); pstrcpy(cli_info.file_sel, "");
pstrcpy(cli_info.base_dir, ""); pstrcpy(cli_info.base_dir, "");
pstrcpy(smb_cli->domain, ""); pstrcpy(usr.domain, "");
pstrcpy(smb_cli->user_name, ""); pstrcpy(usr.user_name, "");
pstrcpy(cli_info.myhostname, ""); pstrcpy(cli_info.myhostname, "");
pstrcpy(cli_info.dest_host, ""); pstrcpy(cli_info.dest_host, "");
@@ -1455,19 +1412,19 @@ static char *complete_cmd_null(char *text, int state)
if (getenv("USER")) if (getenv("USER"))
{ {
pstrcpy(smb_cli->user_name,getenv("USER")); pstrcpy(usr.user_name,getenv("USER"));
/* modification to support userid%passwd syntax in the USER var /* modification to support userid%passwd syntax in the USER var
25.Aug.97, jdblair@uab.edu */ 25.Aug.97, jdblair@uab.edu */
if ((p=strchr(smb_cli->user_name,'%'))) if ((p=strchr(usr.user_name,'%')))
{ {
*p = 0; *p = 0;
pstrcpy(password,p+1); pstrcpy(password,p+1);
got_pass = True; got_pass = True;
memset(strchr(getenv("USER"),'%')+1,'X',strlen(password)); memset(strchr(getenv("USER"),'%')+1,'X',strlen(password));
} }
strupper(smb_cli->user_name); strupper(usr.user_name);
} }
password[0] = 0; password[0] = 0;
@@ -1479,10 +1436,10 @@ static char *complete_cmd_null(char *text, int state)
pstrcpy(password,getenv("PASSWD")); pstrcpy(password,getenv("PASSWD"));
} }
if (*smb_cli->user_name == 0 && getenv("LOGNAME")) if (*usr.user_name == 0 && getenv("LOGNAME"))
{ {
pstrcpy(smb_cli->user_name,getenv("LOGNAME")); pstrcpy(usr.user_name,getenv("LOGNAME"));
strupper(smb_cli->user_name); strupper(usr.user_name);
} }
if (argc < 2) if (argc < 2)
@@ -1573,8 +1530,8 @@ static char *complete_cmd_null(char *text, int state)
case 'U': case 'U':
{ {
char *lp; char *lp;
pstrcpy(smb_cli->user_name,optarg); pstrcpy(usr.user_name,optarg);
if ((lp=strchr(smb_cli->user_name,'%'))) if ((lp=strchr(usr.user_name,'%')))
{ {
*lp = 0; *lp = 0;
pstrcpy(password,lp+1); pstrcpy(password,lp+1);
@@ -1586,7 +1543,7 @@ static char *complete_cmd_null(char *text, int state)
case 'W': case 'W':
{ {
pstrcpy(smb_cli->domain,optarg); pstrcpy(usr.domain,optarg);
break; break;
} }
@@ -1707,38 +1664,22 @@ static char *complete_cmd_null(char *text, int state)
{ {
if (password[0] == 0) if (password[0] == 0)
{ {
pwd_set_nullpwd(&(smb_cli->pwd)); pwd_set_nullpwd(&(usr.pwd));
} }
else else
{ {
/* generate 16 byte hashes */ /* generate 16 byte hashes */
pwd_make_lm_nt_16(&(smb_cli->pwd), password); pwd_make_lm_nt_16(&(usr.pwd), password);
} }
} }
else else
{ {
pwd_read(&(smb_cli->pwd), "Enter Password:", True); pwd_read(&(usr.pwd), "Enter Password:", True);
} }
mdfour(smb_cli->sess_key, smb_cli->pwd.smb_nt_pwd, 16);
/* paranoia: destroy the local copy of the password */ /* paranoia: destroy the local copy of the password */
bzero(password, sizeof(password)); bzero(password, sizeof(password));
/* establish connections. nothing to stop these being re-established. */
rpcclient_connect(&cli_info);
smb_cli->ntlmssp_cli_flgs = 0x0;
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) switch (cli_action)
{ {
case CLIENT_IPC: case CLIENT_IPC:
@@ -1754,7 +1695,5 @@ static char *complete_cmd_null(char *text, int state)
} }
} }
rpcclient_stop();
return(0); return(0);
} }