1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

Remove pstrings from client/client.c by doing a large rewrite.

Mostly compiles....
Jeremy.
This commit is contained in:
Jeremy Allison 2007-12-06 17:16:33 -08:00
parent 48252d124d
commit c87f3eba9a
18 changed files with 1901 additions and 1205 deletions

File diff suppressed because it is too large Load Diff

View File

@ -142,7 +142,7 @@ struct cli_state {
smb_sign_info sign_info;
/* the session key for this CLI, outside
/* the session key for this CLI, outside
any per-pipe authenticaion */
DATA_BLOB user_session_key;
@ -173,8 +173,7 @@ typedef struct file_info {
struct timespec mtime_ts;
struct timespec atime_ts;
struct timespec ctime_ts;
char name[1024];
char dir[1024]; /* Should use allocated PATH_MAX here.... */
char *name;
char short_name[13*3]; /* the *3 is to cope with multi-byte */
} file_info;

View File

@ -42,8 +42,8 @@ extern const struct poptOption popt_common_dynconfig[];
"Build-time configuration overrides:", NULL },
struct user_auth_info {
pstring username;
pstring password;
char *username;
char *password;
bool got_pass;
bool use_kerberos;
int signing_state;

View File

@ -128,18 +128,53 @@ size_t __unsafe_string_function_usage_here_char__(void);
* long. This is not a good situation, because we can't do the normal
* sanity checks. Don't use in new code! */
#define overmalloc_safe_strcpy(dest,src,maxlength) safe_strcpy_fn(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE,dest,src,maxlength)
#define safe_strcpy(dest,src,maxlength) safe_strcpy_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE,dest,src,maxlength)
#define safe_strcat(dest,src,maxlength) safe_strcat_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE,dest,src,maxlength)
#define push_string(base_ptr, dest, src, dest_len, flags) push_string_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, base_ptr, 0, dest, src, dest_len, flags)
#define pull_string(base_ptr, smb_flags2, dest, src, dest_len, src_len, flags) pull_string_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, base_ptr, smb_flags2, dest, src, dest_len, src_len, flags)
#define pull_string_talloc(ctx, base_ptr, smb_flags2, dest, src, src_len, flags) pull_string_talloc_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, ctx, base_ptr, smb_flags2, dest, src, src_len, flags)
#define clistr_push(cli, dest, src, dest_len, flags) clistr_push_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, cli, dest, src, dest_len, flags)
#define clistr_pull(cli, dest, src, dest_len, src_len, flags) clistr_pull_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, cli, dest, src, dest_len, src_len, flags)
#define srvstr_push(base_ptr, smb_flags2, dest, src, dest_len, flags) srvstr_push_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, base_ptr, smb_flags2, dest, src, dest_len, flags)
#define overmalloc_safe_strcpy(dest,src,maxlength) \
safe_strcpy_fn(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, \
dest,src,maxlength)
#define alpha_strcpy(dest,src,other_safe_chars,maxlength) alpha_strcpy_fn(SAFE_STRING_FUNCTION_NAME,SAFE_STRING_LINE,dest,src,other_safe_chars,maxlength)
#define StrnCpy(dest,src,n) StrnCpy_fn(SAFE_STRING_FUNCTION_NAME,SAFE_STRING_LINE,dest,src,n)
#define safe_strcpy(dest,src,maxlength) \
safe_strcpy_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, \
dest,src,maxlength)
#define safe_strcat(dest,src,maxlength) \
safe_strcat_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, \
dest,src,maxlength)
#define push_string(base_ptr, dest, src, dest_len, flags) \
push_string_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, \
base_ptr, 0, dest, src, dest_len, flags)
#define pull_string(base_ptr, smb_flags2, dest, src, dest_len, src_len, flags) \
pull_string_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, \
base_ptr, smb_flags2, dest, src, dest_len, src_len, flags)
#define pull_string_talloc(ctx, base_ptr, smb_flags2, dest, src, src_len, flags) \
pull_string_talloc_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, \
ctx, base_ptr, smb_flags2, dest, src, src_len, flags)
#define clistr_push(cli, dest, src, dest_len, flags) \
clistr_push_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, \
cli, dest, src, dest_len, flags)
#define clistr_pull(cli, dest, src, dest_len, src_len, flags) \
clistr_pull_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, \
cli, dest, src, dest_len, src_len, flags)
#define clistr_pull_talloc(ctx, cli, pp_dest, src, src_len, flags) \
clistr_pull_talloc_fn(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, \
ctx, cli, pp_dest, src, src_len, flags)
#define srvstr_push(base_ptr, smb_flags2, dest, src, dest_len, flags) \
srvstr_push_fn2(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, \
base_ptr, smb_flags2, dest, src, dest_len, flags)
#define alpha_strcpy(dest,src,other_safe_chars,maxlength) \
alpha_strcpy_fn(SAFE_STRING_FUNCTION_NAME,SAFE_STRING_LINE, \
dest,src,other_safe_chars,maxlength)
#define StrnCpy(dest,src,n) \
StrnCpy_fn(SAFE_STRING_FUNCTION_NAME,SAFE_STRING_LINE, \
dest,src,n)
#ifdef HAVE_COMPILER_WILL_OPTIMIZE_OUT_FNS

View File

@ -1692,10 +1692,15 @@ size_t push_string_fn(const char *function, unsigned int line,
The resulting string in "dest" is always null terminated.
**/
size_t pull_string_fn(const char *function, unsigned int line,
const void *base_ptr, uint16 smb_flags2, char *dest,
const void *src, size_t dest_len, size_t src_len,
int flags)
size_t pull_string_fn(const char *function,
unsigned int line,
const void *base_ptr,
uint16 smb_flags2,
char *dest,
const void *src,
size_t dest_len,
size_t src_len,
int flags)
{
#ifdef DEVELOPER
clobber_region(function, line, dest, dest_len);

View File

@ -36,7 +36,57 @@
extern bool AllowDebugChange;
extern bool override_logfile;
struct user_auth_info cmdline_auth_info;
static struct user_auth_info cmdline_auth_info;
const char *get_cmdline_auth_info_username(void)
{
if (!cmdline_auth_info.username) {
return "";
}
return cmdline_auth_info.username;
}
void set_cmdline_auth_info_username(const char *username)
{
SAFE_FREE(cmdline_auth_info.username);
cmdline_auth_info.username = SMB_STRDUP(username);
if (!cmdline_auth_info.username) {
exit(ENOMEM);
}
}
const char *get_cmdline_auth_info_password(void)
{
if (!cmdline_auth_info.password) {
return "";
}
return cmdline_auth_info.password;
}
void set_cmdline_auth_info_password(const char *password)
{
SAFE_FREE(cmdline_auth_info.password);
cmdline_auth_info.password = SMB_STRDUP(password);
if (!cmdline_auth_info.password) {
exit(ENOMEM);
}
cmdline_auth_info.got_pass = true;
}
int get_cmdline_auth_info_signing_state(void)
{
return cmdline_auth_info.signing_state;
}
bool get_cmdline_auth_info_use_kerberos(void)
{
return cmdline_auth_info.use_kerberos;
}
bool get_cmdline_auth_info_got_pass(void)
{
return cmdline_auth_info.got_pass;
}
static void set_logfile(poptContext con, const char * arg)
{
@ -100,7 +150,7 @@ static void popt_common_callback(poptContext con,
case 's':
if (arg) {
pstrcpy(dyn_CONFIGFILE, arg);
strlcpy(dyn_CONFIGFILE, arg,sizeof(dyn_CONFIGFILE));
}
break;
@ -213,13 +263,13 @@ static void popt_dynconfig_callback(poptContext con,
case DYN_LMHOSTSFILE:
if (arg) {
pstrcpy(dyn_LMHOSTSFILE, arg);
strlcpy(dyn_LMHOSTSFILE, arg,sizeof(dyn_LMHOSTSFILE));
}
break;
case DYN_LIBDIR:
if (arg) {
pstrcpy(dyn_LIBDIR, arg);
strlcpy(dyn_LIBDIR, arg,sizeof(dyn_LIBDIR));
}
break;
@ -231,25 +281,25 @@ static void popt_dynconfig_callback(poptContext con,
case DYN_LOCKDIR:
if (arg) {
pstrcpy(dyn_LOCKDIR, arg);
strlcpy(dyn_LOCKDIR, arg,sizeof(dyn_LOCKDIR));
}
break;
case DYN_PIDDIR:
if (arg) {
pstrcpy(dyn_PIDDIR, arg);
strlcpy(dyn_PIDDIR, arg,sizeof(dyn_PIDDIR));
}
break;
case DYN_SMB_PASSWD_FILE:
if (arg) {
pstrcpy(dyn_SMB_PASSWD_FILE, arg);
strlcpy(dyn_SMB_PASSWD_FILE, arg,sizeof(dyn_SMB_PASSWD_FILE));
}
break;
case DYN_PRIVATE_DIR:
if (arg) {
pstrcpy(dyn_PRIVATE_DIR, arg);
strlcpy(dyn_PRIVATE_DIR, arg, sizeof(dyn_PRIVATE_DIR));
}
break;
@ -289,7 +339,7 @@ const struct poptOption popt_common_dynconfig[] = {
* exit on failure
* ****************************************************************************/
static void get_password_file(struct user_auth_info *a)
static void get_password_file(void)
{
int fd = -1;
char *p;
@ -342,12 +392,14 @@ static void get_password_file(struct user_auth_info *a)
}
}
SAFE_FREE(spec);
pstrcpy(a->password, pass);
if (close_it)
set_cmdline_auth_info_password(pass);
if (close_it) {
close(fd);
}
}
static void get_credentials_file(const char *file, struct user_auth_info *info)
static void get_credentials_file(const char *file, struct user_auth_info *info)
{
XFILE *auth;
fstring buf;
@ -389,15 +441,22 @@ static void get_credentials_file(const char *file, struct user_auth_info *info)
while ((*val!='\0') && ((*val==' ') || (*val=='\t')))
val++;
if (strwicmp("password", param) == 0)
{
pstrcpy(info->password, val);
if (strwicmp("password", param) == 0) {
SAFE_FREE(info->password);
info->password = SMB_STRDUP(val);
if (!info->password) {
exit(ENOMEM);
}
info->got_pass = True;
}
else if (strwicmp("username", param) == 0)
pstrcpy(info->username, val);
else if (strwicmp("domain", param) == 0)
} else if (strwicmp("username", param) == 0) {
SAFE_FREE(info->username);
info->username = SMB_STRDUP(val);
if (!info->username) {
exit(ENOMEM);
}
} else if (strwicmp("domain", param) == 0) {
set_global_myworkgroup(val);
}
memset(buf, 0, sizeof(buf));
}
x_fclose(auth);
@ -413,7 +472,7 @@ static void get_credentials_file(const char *file, struct user_auth_info *info)
*/
static void popt_common_credentials_callback(poptContext con,
static void popt_common_credentials_callback(poptContext con,
enum poptCallbackReason reason,
const struct poptOption *opt,
const char *arg, const void *data)
@ -424,24 +483,29 @@ static void popt_common_credentials_callback(poptContext con,
cmdline_auth_info.use_kerberos = False;
cmdline_auth_info.got_pass = False;
cmdline_auth_info.signing_state = Undefined;
pstrcpy(cmdline_auth_info.username, "GUEST");
set_cmdline_auth_info_username("GUEST");
if (getenv("LOGNAME"))pstrcpy(cmdline_auth_info.username,getenv("LOGNAME"));
if (getenv("LOGNAME")) {
set_cmdline_auth_info_username(getenv("LOGNAME"));
}
if (getenv("USER")) {
pstrcpy(cmdline_auth_info.username,getenv("USER"));
char *puser = SMB_STRDUP(getenv("USER"));
if (!puser) {
exit(ENOMEM);
}
set_cmdline_auth_info_username(puser);
if ((p = strchr_m(cmdline_auth_info.username,'%'))) {
if ((p = strchr_m(puser,'%'))) {
*p = 0;
pstrcpy(cmdline_auth_info.password,p+1);
cmdline_auth_info.got_pass = True;
set_cmdline_auth_info_password(p+1);
memset(strchr_m(getenv("USER"),'%')+1,'X',strlen(cmdline_auth_info.password));
}
SAFE_FREE(puser);
}
if (getenv("PASSWD")) {
pstrcpy(cmdline_auth_info.password,getenv("PASSWD"));
cmdline_auth_info.got_pass = True;
set_cmdline_auth_info_password(getenv("PASSWD"));
}
if (getenv("PASSWD_FD") || getenv("PASSWD_FILE")) {
@ -468,7 +532,7 @@ static void popt_common_credentials_callback(poptContext con,
break;
case 'A':
get_credentials_file(arg, &cmdline_auth_info);
get_credentials_file(arg);
break;
case 'k':
@ -476,22 +540,22 @@ static void popt_common_credentials_callback(poptContext con,
d_printf("No kerberos support compiled in\n");
exit(1);
#else
cmdline_auth_info.use_kerberos = True;
cmdline_auth_info.got_pass = True;
cmdline_auth_info.use_kerberos = true;
cmdline_auth_info.got_pass = true;
#endif
break;
case 'S':
{
cmdline_auth_info.signing_state = -1;
if (strequal(arg, "off") || strequal(arg, "no") || strequal(arg, "false"))
cmdline_auth_info.signing_state = False;
else if (strequal(arg, "on") || strequal(arg, "yes") || strequal(arg, "true") ||
strequal(arg, "auto") )
cmdline_auth_info.signing_state = True;
else if (strequal(arg, "force") || strequal(arg, "required") || strequal(arg, "forced"))
if (strequal(arg, "off") || strequal(arg, "no") || strequal(arg, "false")) {
cmdline_auth_info.signing_state = false;
} else if (strequal(arg, "on") || strequal(arg, "yes") || strequal(arg, "true") ||
strequal(arg, "auto")) {
cmdline_auth_info.signing_state = true;
} else if (strequal(arg, "force") || strequal(arg, "required") || strequal(arg, "forced")) {
cmdline_auth_info.signing_state = Required;
else {
} else {
fprintf(stderr, "Unknown signing option %s\n", arg );
exit(1);
}
@ -500,35 +564,37 @@ static void popt_common_credentials_callback(poptContext con,
case 'P':
{
char *opt_password = NULL;
char *pwd = NULL;
/* it is very useful to be able to make ads queries as the
machine account for testing purposes and for domain leave */
if (!secrets_init()) {
d_printf("ERROR: Unable to open secrets database\n");
exit(1);
}
opt_password = secrets_fetch_machine_password(lp_workgroup(), NULL, NULL);
if (!opt_password) {
d_printf("ERROR: Unable to fetch machine password\n");
exit(1);
}
pstr_sprintf(cmdline_auth_info.username, "%s$",
global_myname());
pstrcpy(cmdline_auth_info.password,opt_password);
if (asprintf(&pwd, "%s$", global_myname()) < 0) {
exit(ENOMEM);
}
set_cmdline_auth_info_username(pwd);
set_cmdline_auth_info_password(opt_password);
SAFE_FREE(pwd);
SAFE_FREE(opt_password);
/* machine accounts only work with kerberos */
cmdline_auth_info.use_kerberos = True;
cmdline_auth_info.got_pass = True;
cmdline_auth_info.use_kerberos = true;
}
break;
}
}
struct poptOption popt_common_credentials[] = {
{ NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, (void *)popt_common_credentials_callback },
{ "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "USERNAME" },

View File

@ -53,7 +53,7 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void)
char **(completion_fn)(const char *text, int start, int end))
{
fd_set fds;
static char *line;
char *line = NULL;
struct timeval timeout;
int fd = x_fileno(x_stdin);
char *ret;
@ -64,11 +64,9 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void)
x_fflush(x_stdout);
}
if (line == NULL) {
line = (char *)SMB_MALLOC(BUFSIZ);
if (!line) {
return NULL;
}
line = (char *)SMB_MALLOC(BUFSIZ);
if (!line) {
return NULL;
}
while (1) {
@ -80,10 +78,14 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void)
if (sys_select_intr(fd+1,&fds,NULL,NULL,&timeout) == 1) {
ret = x_fgets(line, BUFSIZ, x_stdin);
if (ret == 0) {
SAFE_FREE(line);
}
return ret;
}
if (callback)
if (callback) {
callback();
}
}
}
@ -91,7 +93,7 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void)
Display the prompt and wait for input. Call callback() regularly.
****************************************************************************/
char *smb_readline(const char *prompt, void (*callback)(void),
char *smb_readline(const char *prompt, void (*callback)(void),
char **(completion_fn)(const char *text, int start, int end))
{
char *ret;
@ -99,7 +101,7 @@ char *smb_readline(const char *prompt, void (*callback)(void),
interactive = isatty(x_fileno(x_stdin)) || getenv("CLI_FORCE_INTERACTIVE");
if (!interactive) {
return smb_readline_replacement(NULL, callback, completion_fn);
return smb_readline_replacement(NULL, callback, completion_fn);
}
#if HAVE_LIBREADLINE
@ -167,7 +169,7 @@ int cmd_history(void)
int i;
hlist = history_list();
for (i = 0; hlist && hlist[i]; i++) {
DEBUG(0, ("%d: %s\n", i, hlist[i]->line));
}
@ -177,4 +179,3 @@ int cmd_history(void)
return 0;
}

View File

@ -57,9 +57,6 @@ extern unsigned int global_clobber_region_line;
enum protocol_types Protocol = PROTOCOL_COREPLUS;
/* a default finfo structure to ensure all fields are sensible */
file_info def_finfo;
/* this is used by the chaining code */
int chain_size = 0;
@ -692,21 +689,6 @@ char *clean_name(TALLOC_CTX *ctx, const char *s)
return unix_clean_name(ctx, str);
}
/*******************************************************************
Horrible temporary hack until pstring is dead.
********************************************************************/
char *pstring_clean_name(pstring s)
{
char *str = clean_name(NULL,s);
if (!str) {
return NULL;
}
pstrcpy(s, str);
TALLOC_FREE(str);
return s;
}
/*******************************************************************
Close the low 3 fd's and open dev/null in their place.
********************************************************************/
@ -718,7 +700,7 @@ void close_low_fds(bool stderr_too)
int i;
close(0);
close(1);
close(1);
if (stderr_too)
close(2);

View File

@ -266,7 +266,8 @@ const char *cli_cm_get_mntpoint(struct cli_state *c)
********************************************************************/
static struct cli_state *cli_cm_connect(TALLOC_CTX *ctx,
const char *server,
struct cli_state *referring_cli,
const char *server,
const char *share,
bool show_hdr)
{
@ -289,8 +290,17 @@ static struct cli_state *cli_cm_connect(TALLOC_CTX *ctx,
cli_cm_set_mntpoint(node->cli, "");
return node->cli;
if (referring_cli && referring_cli->posix_capabilities) {
uint16 major, minor;
uint32 caplow, caphigh;
if (cli_unix_extensions_version(cli, &major,
&minor, &caplow, &caphigh)) {
cli_set_unix_extensions_capabilities(cli, major, minor,
caplow, caphigh);
}
}
return node->cli;
}
/********************************************************************
@ -317,6 +327,7 @@ static struct cli_state *cli_cm_find(const char *server, const char *share)
****************************************************************************/
struct cli_state *cli_cm_open(TALLOC_CTX *ctx,
struct cli_state *referring_cli,
const char *server,
const char *share,
bool show_hdr)
@ -327,7 +338,7 @@ struct cli_state *cli_cm_open(TALLOC_CTX *ctx,
c = cli_cm_find(server, share);
if (!c) {
c = cli_cm_connect(ctx, server, share, show_hdr);
c = cli_cm_connect(ctx, referring_cli, server, share, show_hdr);
}
return c;
@ -378,17 +389,17 @@ static void cm_set_password(const char *newpass)
}
}
void cli_cm_set_credentials(struct user_auth_info *user)
void cli_cm_set_credentials(void)
{
SAFE_FREE(cm_creds.username);
cm_creds.username = SMB_STRDUP(user->username);
cm_creds.username = SMB_STRDUP(get_cmdline_auth_info_username());
if (user->got_pass) {
cm_set_password(user->password);
if (get_cmdline_auth_info_got_pass()) {
cm_set_password(get_cmdline_auth_info_password());
}
cm_creds.use_kerberos = user->use_kerberos;
cm_creds.signing_state = user->signing_state;
cm_creds.use_kerberos = get_cmdline_auth_info_use_kerberos();
cm_creds.signing_state = get_cmdline_auth_info_signing_state();
}
/****************************************************************************
@ -729,7 +740,8 @@ bool cli_resolve_path(TALLOC_CTX *ctx,
/* Check for the referral. */
if (!(cli_ipc = cli_cm_open(ctx, rootcli->desthost, "IPC$", false))) {
if (!(cli_ipc = cli_cm_open(ctx, rootcli,
rootcli->desthost, "IPC$", false))) {
return false;
}
@ -768,7 +780,8 @@ bool cli_resolve_path(TALLOC_CTX *ctx,
*/
/* Open the connection to the target server & share */
if ((*targetcli = cli_cm_open(ctx, server, share, false)) == NULL) {
if ((*targetcli = cli_cm_open(ctx, rootcli,
server, share, false)) == NULL) {
d_printf("Unable to follow dfs referral [\\%s\\%s]\n",
server, share );
return false;
@ -852,31 +865,6 @@ bool cli_resolve_path(TALLOC_CTX *ctx,
return true;
}
/********************************************************************
Temporary hack - remove when pstring is dead. JRA.
********************************************************************/
bool cli_resolve_path_pstring( const char *mountpt,
struct cli_state *rootcli,
const char *path,
struct cli_state **targetcli,
pstring targetpath)
{
char *tpath = NULL;
TALLOC_CTX *ctx = talloc_stackframe();
bool ret = cli_resolve_path(ctx,
mountpt,
rootcli,
path,
targetcli,
&tpath);
if (tpath) {
pstrcpy(targetpath, tpath);
}
TALLOC_FREE(ctx);
return ret;
}
/********************************************************************
********************************************************************/

View File

@ -22,7 +22,7 @@
/****************************************************************************
Get UNIX extensions version info.
****************************************************************************/
bool cli_unix_extensions_version(struct cli_state *cli, uint16 *pmajor, uint16 *pminor,
uint32 *pcaplow, uint32 *pcaphigh)
{
@ -33,18 +33,18 @@ bool cli_unix_extensions_version(struct cli_state *cli, uint16 *pmajor, uint16 *
unsigned int rparam_count=0, rdata_count=0;
setup = TRANSACT2_QFSINFO;
SSVAL(param,0,SMB_QUERY_CIFS_UNIX_INFO);
if (!cli_send_trans(cli, SMBtrans2,
NULL,
if (!cli_send_trans(cli, SMBtrans2,
NULL,
0, 0,
&setup, 1, 0,
param, 2, 0,
NULL, 0, 560)) {
goto cleanup;
}
if (!cli_receive_trans(cli, SMBtrans2,
&rparam, &rparam_count,
&rdata, &rdata_count)) {
@ -67,7 +67,7 @@ bool cli_unix_extensions_version(struct cli_state *cli, uint16 *pmajor, uint16 *
cli->posix_capabilities = *pcaplow = IVAL(rdata,4);
*pcaphigh = IVAL(rdata,8);
/* todo: but not yet needed
/* todo: but not yet needed
* return the other stuff
*/
@ -75,13 +75,13 @@ cleanup:
SAFE_FREE(rparam);
SAFE_FREE(rdata);
return ret;
return ret;
}
/****************************************************************************
Set UNIX extensions capabilities.
****************************************************************************/
bool cli_set_unix_extensions_capabilities(struct cli_state *cli, uint16 major, uint16 minor,
uint32 caplow, uint32 caphigh)
{
@ -93,7 +93,7 @@ bool cli_set_unix_extensions_capabilities(struct cli_state *cli, uint16 major, u
unsigned int rparam_count=0, rdata_count=0;
setup = TRANSACT2_SETFSINFO;
SSVAL(param,0,0);
SSVAL(param,2,SMB_SET_CIFS_UNIX_INFO);
@ -102,15 +102,15 @@ bool cli_set_unix_extensions_capabilities(struct cli_state *cli, uint16 major, u
SIVAL(data,4,caplow);
SIVAL(data,8,caphigh);
if (!cli_send_trans(cli, SMBtrans2,
NULL,
if (!cli_send_trans(cli, SMBtrans2,
NULL,
0, 0,
&setup, 1, 0,
param, 4, 0,
data, 12, 560)) {
goto cleanup;
}
if (!cli_receive_trans(cli, SMBtrans2,
&rparam, &rparam_count,
&rdata, &rdata_count)) {
@ -128,7 +128,7 @@ cleanup:
SAFE_FREE(rparam);
SAFE_FREE(rdata);
return ret;
return ret;
}
bool cli_get_fs_attr_info(struct cli_state *cli, uint32 *fs_attr)
@ -143,18 +143,18 @@ bool cli_get_fs_attr_info(struct cli_state *cli, uint32 *fs_attr)
smb_panic("cli_get_fs_attr_info() called with NULL Pionter!");
setup = TRANSACT2_QFSINFO;
SSVAL(param,0,SMB_QUERY_FS_ATTRIBUTE_INFO);
if (!cli_send_trans(cli, SMBtrans2,
NULL,
if (!cli_send_trans(cli, SMBtrans2,
NULL,
0, 0,
&setup, 1, 0,
param, 2, 0,
NULL, 0, 560)) {
goto cleanup;
}
if (!cli_receive_trans(cli, SMBtrans2,
&rparam, &rparam_count,
&rdata, &rdata_count)) {
@ -174,7 +174,7 @@ bool cli_get_fs_attr_info(struct cli_state *cli, uint32 *fs_attr)
*fs_attr = IVAL(rdata,0);
/* todo: but not yet needed
/* todo: but not yet needed
* return the other stuff
*/
@ -182,7 +182,7 @@ cleanup:
SAFE_FREE(rparam);
SAFE_FREE(rdata);
return ret;
return ret;
}
bool cli_get_fs_volume_info_old(struct cli_state *cli, fstring volume_name, uint32 *pserial_number)
@ -195,18 +195,18 @@ bool cli_get_fs_volume_info_old(struct cli_state *cli, fstring volume_name, uint
unsigned char nlen;
setup = TRANSACT2_QFSINFO;
SSVAL(param,0,SMB_INFO_VOLUME);
if (!cli_send_trans(cli, SMBtrans2,
NULL,
if (!cli_send_trans(cli, SMBtrans2,
NULL,
0, 0,
&setup, 1, 0,
param, 2, 0,
NULL, 0, 560)) {
goto cleanup;
}
if (!cli_receive_trans(cli, SMBtrans2,
&rparam, &rparam_count,
&rdata, &rdata_count)) {
@ -230,7 +230,7 @@ bool cli_get_fs_volume_info_old(struct cli_state *cli, fstring volume_name, uint
nlen = CVAL(rdata,l2_vol_cch);
clistr_pull(cli, volume_name, rdata + l2_vol_szVolLabel, sizeof(fstring), nlen, STR_NOALIGN);
/* todo: but not yet needed
/* todo: but not yet needed
* return the other stuff
*/
@ -238,7 +238,7 @@ cleanup:
SAFE_FREE(rparam);
SAFE_FREE(rdata);
return ret;
return ret;
}
bool cli_get_fs_volume_info(struct cli_state *cli, fstring volume_name, uint32 *pserial_number, time_t *pdate)
@ -251,18 +251,18 @@ bool cli_get_fs_volume_info(struct cli_state *cli, fstring volume_name, uint32 *
unsigned int nlen;
setup = TRANSACT2_QFSINFO;
SSVAL(param,0,SMB_QUERY_FS_VOLUME_INFO);
if (!cli_send_trans(cli, SMBtrans2,
NULL,
if (!cli_send_trans(cli, SMBtrans2,
NULL,
0, 0,
&setup, 1, 0,
param, 2, 0,
NULL, 0, 560)) {
goto cleanup;
}
if (!cli_receive_trans(cli, SMBtrans2,
&rparam, &rparam_count,
&rdata, &rdata_count)) {
@ -291,7 +291,7 @@ bool cli_get_fs_volume_info(struct cli_state *cli, fstring volume_name, uint32 *
nlen = IVAL(rdata,12);
clistr_pull(cli, volume_name, rdata + 18, sizeof(fstring), nlen, STR_UNICODE);
/* todo: but not yet needed
/* todo: but not yet needed
* return the other stuff
*/
@ -299,5 +299,5 @@ cleanup:
SAFE_FREE(rparam);
SAFE_FREE(rdata);
return ret;
return ret;
}

View File

@ -19,11 +19,11 @@
#include "includes.h"
/****************************************************************************
start a message sequence
Start a message sequence.
****************************************************************************/
int cli_message_start_build(struct cli_state *cli, char *host, char *username)
int cli_message_start_build(struct cli_state *cli, const char *host, const char *username)
{
char *p;
@ -33,25 +33,26 @@ int cli_message_start_build(struct cli_state *cli, char *host, char *username)
SCVAL(cli->outbuf,smb_com,SMBsendstrt);
SSVAL(cli->outbuf,smb_tid,cli->cnum);
cli_setup_packet(cli);
p = smb_buf(cli->outbuf);
*p++ = 4;
p += clistr_push(cli, p, username, -1, STR_ASCII|STR_TERMINATE);
p += clistr_push(cli, p, username,
cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_ASCII|STR_TERMINATE);
*p++ = 4;
p += clistr_push(cli, p, host, -1, STR_ASCII|STR_TERMINATE);
p += clistr_push(cli, p, host,
cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_ASCII|STR_TERMINATE);
cli_setup_bcc(cli, p);
return(PTR_DIFF(p, cli->outbuf));
}
bool cli_message_start(struct cli_state *cli, char *host, char *username,
bool cli_message_start(struct cli_state *cli, const char *host, const char *username,
int *grp)
{
cli_message_start_build(cli, host, username);
cli_send_smb(cli);
cli_send_smb(cli);
if (!cli_receive_smb(cli)) {
return False;
}
@ -63,11 +64,11 @@ bool cli_message_start(struct cli_state *cli, char *host, char *username,
return True;
}
/****************************************************************************
send a message
Send a message
****************************************************************************/
int cli_message_text_build(struct cli_state *cli, char *msg, int len, int grp)
int cli_message_text_build(struct cli_state *cli, const char *msg, int len, int grp)
{
char *msgdos;
int lendos;
@ -80,17 +81,23 @@ int cli_message_text_build(struct cli_state *cli, char *msg, int len, int grp)
cli_setup_packet(cli);
SSVAL(cli->outbuf,smb_vwv0,grp);
p = smb_buf(cli->outbuf);
*p++ = 1;
if ((lendos = (int)convert_string_allocate(NULL,CH_UNIX, CH_DOS, msg,len, (void **)(void *)&msgdos, True)) < 0 || !msgdos) {
DEBUG(3,("Conversion failed, sending message in UNIX charset\n"));
SSVAL(p, 0, len); p += 2;
if (len > cli->bufsize - PTR_DIFF(p,cli->outbuf)) {
return -1;
}
memcpy(p, msg, len);
p += len;
} else {
SSVAL(p, 0, lendos); p += 2;
if (lendos > cli->bufsize - PTR_DIFF(p,cli->outbuf)) {
return -1;
}
memcpy(p, msgdos, lendos);
p += lendos;
SAFE_FREE(msgdos);
@ -101,7 +108,7 @@ int cli_message_text_build(struct cli_state *cli, char *msg, int len, int grp)
return(PTR_DIFF(p, cli->outbuf));
}
bool cli_message_text(struct cli_state *cli, char *msg, int len, int grp)
bool cli_message_text(struct cli_state *cli, const char *msg, int len, int grp)
{
cli_message_text_build(cli, msg, len, grp);
@ -114,11 +121,12 @@ bool cli_message_text(struct cli_state *cli, char *msg, int len, int grp)
if (cli_is_error(cli)) return False;
return True;
}
}
/****************************************************************************
end a message
End a message.
****************************************************************************/
int cli_message_end_build(struct cli_state *cli, int grp)
{
char *p;
@ -150,4 +158,4 @@ bool cli_message_end(struct cli_state *cli, int grp)
if (cli_is_error(cli)) return False;
return True;
}
}

View File

@ -20,9 +20,13 @@
#include "includes.h"
size_t clistr_push_fn(const char *function, unsigned int line,
struct cli_state *cli, void *dest,
const char *src, int dest_len, int flags)
size_t clistr_push_fn(const char *function,
unsigned int line,
struct cli_state *cli,
void *dest,
const char *src,
int dest_len,
int flags)
{
size_t buf_used = PTR_DIFF(dest, cli->outbuf);
if (dest_len == -1) {
@ -38,23 +42,46 @@ size_t clistr_push_fn(const char *function, unsigned int line,
dest, src, cli->bufsize - buf_used,
flags);
}
/* 'normal' push into size-specified buffer */
return push_string_fn(function, line, cli->outbuf,
SVAL(cli->outbuf, smb_flg2),
dest, src, dest_len, flags);
}
size_t clistr_pull_fn(const char *function, unsigned int line,
struct cli_state *cli, char *dest, const void *src,
int dest_len, int src_len,
int flags)
size_t clistr_pull_fn(const char *function,
unsigned int line,
struct cli_state *cli,
char *dest,
const void *src,
int dest_len,
int src_len,
int flags)
{
return pull_string_fn(function, line, cli->inbuf,
SVAL(cli->inbuf, smb_flg2), dest, src, dest_len,
src_len, flags);
}
size_t clistr_pull_talloc_fn(const char *function,
unsigned int line,
TALLOC_CTX *ctx,
struct cli_state *cli,
char **pp_dest,
const void *src,
int src_len,
int flags)
{
return pull_string_talloc_fn(function,
line,
ctx,
cli->inbuf,
SVAL(cli->inbuf, smb_flg2),
pp_dest,
src,
src_len,
flags);
}
size_t clistr_align_out(struct cli_state *cli, const void *p, int flags)
{

View File

@ -2671,9 +2671,9 @@ static WERROR cmd_spoolss_printercmp(struct rpc_pipe_client *cli,
nt_status = cli_full_connection(&cli_server2, global_myname(), servername2,
NULL, 0,
"IPC$", "IPC",
cmdline_auth_info.username,
get_cmdline_auth_info_username(),
lp_workgroup(),
cmdline_auth_info.password,
get_cmdline_auth_info_password(),
cmdline_auth_info.use_kerberos ? CLI_FULL_CONNECTION_USE_KERBEROS : 0,
cmdline_auth_info.signing_state, NULL);

View File

@ -571,8 +571,8 @@ static NTSTATUS do_cmd(struct cli_state *cli,
cmd_entry->pipe_idx,
pipe_default_auth_level,
lp_workgroup(),
cmdline_auth_info.username,
cmdline_auth_info.password,
get_cmdline_auth_info_username(),
get_cmdline_auth_info_password(),
&ntresult);
break;
case PIPE_AUTH_TYPE_NTLMSSP:
@ -580,8 +580,8 @@ static NTSTATUS do_cmd(struct cli_state *cli,
cmd_entry->pipe_idx,
pipe_default_auth_level,
lp_workgroup(),
cmdline_auth_info.username,
cmdline_auth_info.password,
get_cmdline_auth_info_username(),
get_cmdline_auth_info_password(),
&ntresult);
break;
case PIPE_AUTH_TYPE_SCHANNEL:
@ -887,7 +887,7 @@ out_free:
/* Loop around accepting commands */
while(1) {
char *line;
char *line = NULL;
line = smb_readline("rpcclient $> ", NULL, completion_fn);
@ -896,6 +896,7 @@ out_free:
if (line[0] != '\n')
process_cmd(cli, line);
SAFE_FREE(line);
}
done:

View File

@ -23,8 +23,6 @@
#define REGISTER 0
#endif
extern file_info def_finfo;
#define CNV_LANG(s) dos2unix_format(s,False)
#define CNV_INPUT(s) unix2dos_format(s,True)

View File

@ -579,15 +579,18 @@ int main(int argc, char *argv[])
/* Loop around accepting commands */
while(1) {
char *line;
char *line = NULL;
line = smb_readline("vfstest $> ", NULL, completion_fn);
if (line == NULL)
if (line == NULL) {
break;
}
if (line[0] != '\n')
if (line[0] != '\n') {
process_cmd(&vfs, line);
}
SAFE_FREE(line);
}
conn_free(vfs.conn);

View File

@ -237,15 +237,17 @@ int net_rpc_shell(int argc, const char **argv)
d_printf("Talking to domain %s (%s)\n", ctx->domain_name,
sid_string_static(ctx->domain_sid));
this_ctx = ctx;
while(1) {
char *prompt;
char *line;
char *prompt = NULL;
char *line = NULL;
int ret;
asprintf(&prompt, "%s> ", this_ctx->whoami);
if (asprintf(&prompt, "%s> ", this_ctx->whoami) < 0) {
break;
}
line = smb_readline(prompt, NULL, completion_fn);
SAFE_FREE(prompt);
@ -256,18 +258,22 @@ int net_rpc_shell(int argc, const char **argv)
ret = poptParseArgvString(line, &argc, &argv);
if (ret == POPT_ERROR_NOARG) {
SAFE_FREE(line);
continue;
}
if (ret != 0) {
d_fprintf(stderr, "cmdline invalid: %s\n",
poptStrerror(ret));
SAFE_FREE(line);
return False;
}
if ((line[0] != '\n') &&
(!net_sh_process(this_ctx, argc, argv))) {
SAFE_FREE(line);
break;
}
SAFE_FREE(line);
}
cli_shutdown(ctx->cli);

View File

@ -827,9 +827,12 @@ static struct cli_state *connect_one(const char *server, const char *share)
if (NT_STATUS_IS_OK(nt_status = cli_full_connection(&c, global_myname(), server,
&ss, 0,
share, "?????",
cmdline_auth_info.username, lp_workgroup(),
cmdline_auth_info.password, 0,
cmdline_auth_info.signing_state, NULL))) {
get_cmdline_auth_info_username(),
lp_workgroup(),
get_cmdline_auth_info_password(),
0,
get_cmdline_auth_info.signing_state(),
NULL))) {
return c;
} else {
DEBUG(0,("cli_full_connection failed! (%s)\n", nt_errstr(nt_status)));