#include "trans2.h"
#include "libsmb/nmblib.h"
#include "include/ntioctl.h"
+#include "../libcli/smb/smbXcli_base.h"
#ifndef REGISTER
#define REGISTER 0
#define CREATE_ACCESS_READ READ_CONTROL_ACCESS
-/* 30 second timeout on most commands */
-#define CLIENT_TIMEOUT (30*1000)
-#define SHORT_TIMEOUT (5*1000)
-
/* value for unused fid field in trans2 secondary request */
#define FID_UNUSED (0xFFFF)
struct push_state {
XFILE *f;
- SMB_OFF_T nread;
+ off_t nread;
};
static size_t push_source(uint8_t *buf, size_t n, void *priv)
/* Use a trans2_qpathinfo to test directories for modern servers.
Except Win9x doesn't support the qpathinfo_basic() call..... */
- if (cli_state_protocol(targetcli) > PROTOCOL_LANMAN2 && !targetcli->win95) {
+ if (smbXcli_conn_protocol(targetcli->conn) > PROTOCOL_LANMAN2 && !targetcli->win95) {
status = cli_qpathinfo_basic(targetcli, targetpath, &sbuf,
&attributes);
bool newhandle = false;
struct timespec tp_start;
uint16 attr;
- SMB_OFF_T size;
+ off_t size;
off_t start = 0;
- SMB_OFF_T nread = 0;
+ off_t nread = 0;
int rc = 0;
struct cli_state *targetcli = NULL;
char *targetname = NULL;
}
if (lowercase) {
- strlower_m(lname);
+ if (!strlower_m(lname)) {
+ d_printf("strlower_m %s failed\n", lname);
+ return 1;
+ }
}
status = cli_resolve_path(ctx, "", auth_info, cli, rname, &targetcli,
handle = fileno(stdout);
} else {
if (reget) {
- handle = sys_open(lname, O_WRONLY|O_CREAT, 0644);
+ handle = open(lname, O_WRONLY|O_CREAT, 0644);
if (handle >= 0) {
- start = sys_lseek(handle, 0, SEEK_END);
+ start = lseek(handle, 0, SEEK_END);
if (start == -1) {
d_printf("Error seeking local file\n");
return 1;
}
}
} else {
- handle = sys_open(lname, O_WRONLY|O_CREAT|O_TRUNC, 0644);
+ handle = open(lname, O_WRONLY|O_CREAT|O_TRUNC, 0644);
}
newhandle = true;
}
string_replace(finfo->name,'\\','/');
if (lowercase) {
- strlower_m(finfo->name);
+ if (!strlower_m(finfo->name)) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
}
if (!directory_exist(finfo->name) &&
return NT_STATUS_NO_MEMORY;
}
- status = do_list(mget_mask, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY,do_mget,false, true);
- if (!NT_STATUS_IS_OK(status)) {
+ status = do_list(mget_mask,
+ (FILE_ATTRIBUTE_SYSTEM
+ | FILE_ATTRIBUTE_HIDDEN
+ | FILE_ATTRIBUTE_DIRECTORY),
+ do_mget, false, true);
+ if (!NT_STATUS_IS_OK(status)
+ && !NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
+ /*
+ * Ignore access denied errors to ensure all permitted files are
+ * pulled down.
+ */
return status;
}
const char *pager;
int fd;
int rc = 0;
+ mode_t mask;
rname = talloc_strdup(ctx, client_get_cur_dir());
if (!rname) {
if (!lname) {
return 1;
}
+ mask = umask(S_IRWXO | S_IRWXG);
fd = mkstemp(lname);
+ umask(mask);
if (fd == -1) {
d_printf("failed to create temporary file for more\n");
return 1;
{
fstring altname;
struct timespec b_time, a_time, m_time, c_time;
- SMB_OFF_T size;
+ off_t size;
uint16_t mode;
SMB_INO_T ino;
NTTIME tmp;
}
status = cli_ntcreate(cli, name, 0,
- CREATE_ACCESS_READ, 0,
+ SEC_FILE_READ_DATA | SEC_FILE_READ_ATTRIBUTE |
+ SEC_STD_SYNCHRONIZE, 0,
FILE_SHARE_READ|FILE_SHARE_WRITE
|FILE_SHARE_DELETE,
FILE_OPEN, 0x0, 0x0, &fnum);
TALLOC_CTX *ctx = talloc_tos();
uint16_t fnum;
XFILE *f;
- SMB_OFF_T start = 0;
+ off_t start = 0;
int rc = 0;
struct timespec tp_start;
struct cli_state *targetcli;
static int file_find(struct file_list **list, const char *directory,
const char *expression, bool match)
{
- SMB_STRUCT_DIR *dir;
+ DIR *dir;
struct file_list *entry;
struct stat statbuf;
int ret;
bool isdir;
const char *dname;
- dir = sys_opendir(directory);
+ dir = opendir(directory);
if (!dir)
return -1;
if (ret == -1) {
SAFE_FREE(path);
- sys_closedir(dir);
+ closedir(dir);
return -1;
}
}
entry = SMB_MALLOC_P(struct file_list);
if (!entry) {
d_printf("Out of memory in file_find\n");
- sys_closedir(dir);
+ closedir(dir);
return -1;
}
entry->file_path = path;
}
}
- sys_closedir(dir);
+ closedir(dir);
return 0;
}
goto fail;
}
status = cli_ntcreate(
- cli, name, 0, READ_CONTROL_ACCESS, 0,
+ cli, name, 0, FILE_READ_DATA, 0,
FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
FILE_OPEN, 0, 0, &fnum);
if (!NT_STATUS_IS_OK(status)) {
}
if (!next_token_talloc(ctx, &cmd_ptr,&l_password,NULL)) {
- char *pass = getpass("Password: ");
- if (pass) {
- l_password = talloc_strdup(ctx,pass);
+ char pwd[256] = {0};
+ int rc;
+
+ rc = samba_getpass("Password: ", pwd, sizeof(pwd), false, false);
+ if (rc == 0) {
+ l_password = talloc_strdup(ctx, pwd);
}
}
if (!l_password) {
return 1;
}
- d_printf("//%s/%s\n", cli_state_remote_name(targetcli), targetcli->share);
+ d_printf("//%s/%s\n", smbXcli_conn_remote_name(targetcli->conn), targetcli->share);
return 0;
}
{"cancel",cmd_cancel,"<jobid> cancel a print queue entry",{COMPL_NONE,COMPL_NONE}},
{"case_sensitive",cmd_setcase,"toggle the case sensitive flag to server",{COMPL_NONE,COMPL_NONE}},
{"cd",cmd_cd,"[directory] change/report the remote directory",{COMPL_REMOTE,COMPL_NONE}},
- {"chmod",cmd_chmod,"<src> <mode> chmod a file using UNIX permission",{COMPL_REMOTE,COMPL_REMOTE}},
- {"chown",cmd_chown,"<src> <uid> <gid> chown a file using UNIX uids and gids",{COMPL_REMOTE,COMPL_REMOTE}},
- {"close",cmd_close,"<fid> close a file given a fid",{COMPL_REMOTE,COMPL_REMOTE}},
+ {"chmod",cmd_chmod,"<src> <mode> chmod a file using UNIX permission",{COMPL_REMOTE,COMPL_NONE}},
+ {"chown",cmd_chown,"<src> <uid> <gid> chown a file using UNIX uids and gids",{COMPL_REMOTE,COMPL_NONE}},
+ {"close",cmd_close,"<fid> close a file given a fid",{COMPL_REMOTE,COMPL_NONE}},
{"del",cmd_del,"<mask> delete all matching files",{COMPL_REMOTE,COMPL_NONE}},
{"dir",cmd_dir,"<mask> list the contents of the current directory",{COMPL_REMOTE,COMPL_NONE}},
{"du",cmd_du,"<mask> computes the total size of the current directory",{COMPL_REMOTE,COMPL_NONE}},
{"echo",cmd_echo,"ping the server",{COMPL_NONE,COMPL_NONE}},
{"exit",cmd_quit,"logoff the server",{COMPL_NONE,COMPL_NONE}},
{"get",cmd_get,"<remote name> [local name] get a file",{COMPL_REMOTE,COMPL_LOCAL}},
- {"getfacl",cmd_getfacl,"<file name> get the POSIX ACL on a file (UNIX extensions only)",{COMPL_REMOTE,COMPL_LOCAL}},
+ {"getfacl",cmd_getfacl,"<file name> get the POSIX ACL on a file (UNIX extensions only)",{COMPL_REMOTE,COMPL_NONE}},
{"geteas", cmd_geteas, "<file name> get the EA list of a file",
- {COMPL_REMOTE, COMPL_LOCAL}},
+ {COMPL_REMOTE, COMPL_NONE}},
{"hardlink",cmd_hardlink,"<src> <dest> create a Windows hard link",{COMPL_REMOTE,COMPL_REMOTE}},
{"help",cmd_help,"[command] give help on a command",{COMPL_NONE,COMPL_NONE}},
{"history",cmd_history,"displays the command history",{COMPL_NONE,COMPL_NONE}},
{"rename",cmd_rename,"<src> <dest> rename some files",{COMPL_REMOTE,COMPL_REMOTE}},
{"reput",cmd_reput,"<local name> [remote name] put a file restarting at end of remote file",{COMPL_LOCAL,COMPL_REMOTE}},
{"rm",cmd_del,"<mask> delete all matching files",{COMPL_REMOTE,COMPL_NONE}},
- {"rmdir",cmd_rmdir,"<directory> remove a directory",{COMPL_NONE,COMPL_NONE}},
+ {"rmdir",cmd_rmdir,"<directory> remove a directory",{COMPL_REMOTE,COMPL_NONE}},
{"showacls",cmd_showacls,"toggle if ACLs are shown or not",{COMPL_NONE,COMPL_NONE}},
{"setea", cmd_setea, "<file name> <eaname> <eaval> Set an EA of a file",
{COMPL_REMOTE, COMPL_LOCAL}},
- {"setmode",cmd_setmode,"filename <setmode string> change modes of file",{COMPL_REMOTE,COMPL_NONE}},
- {"stat",cmd_stat,"filename Do a UNIX extensions stat call on a file",{COMPL_REMOTE,COMPL_REMOTE}},
+ {"setmode",cmd_setmode,"<file name> <setmode string> change modes of file",{COMPL_REMOTE,COMPL_NONE}},
+ {"stat",cmd_stat,"<file name> Do a UNIX extensions stat call on a file",{COMPL_REMOTE,COMPL_NONE}},
{"symlink",cmd_symlink,"<oldname> <newname> create a UNIX symlink",{COMPL_REMOTE,COMPL_REMOTE}},
{"tar",cmd_tar,"tar <c|x>[IXFqbgNan] current directory to/from <file name>",{COMPL_NONE,COMPL_NONE}},
{"tarmode",cmd_tarmode,"<full|inc|reset|noreset> tar's behaviour towards archive bits",{COMPL_NONE,COMPL_NONE}},
info.matches[0] = SMB_STRNDUP(info.matches[1], info.samelen);
info.matches[info.count] = NULL;
+ TALLOC_FREE(ctx);
return info.matches;
cleanup:
poptGetArg(pc));
}
+
switch (opt) {
case 'M':
/* Messages are sent to NetBIOS name type 0x3
}
if ( override_logfile )
- setup_logging( lp_logfile(), DEBUG_FILE );
+ setup_logging( lp_logfile(talloc_tos()), DEBUG_FILE );
if (!lp_load_client(get_dyn_CONFIGFILE())) {
fprintf(stderr, "%s: Can't load %s - run testparm to debug it\n",
}
if(new_name_resolve_order)
- lp_set_name_resolve_order(new_name_resolve_order);
+ lp_set_cmdline("name resolve order", new_name_resolve_order);
if (!tar_type && !query_host && !service && !message) {
poptPrintUsage(pc, stderr, 0);
}
poptFreeContext(pc);
+ popt_burn_cmdline_password(argc, argv);
DEBUG(3,("Client started (version %s).\n", samba_version_string()));
if (tar_type) {
if (cmdstr)
process_command_string(cmdstr);
- return do_tar_op(base_directory);
- }
-
- if (query_host && *query_host) {
+ rc = do_tar_op(base_directory);
+ } else if (query_host && *query_host) {
char *qhost = query_host;
char *slash;
sscanf(p, "%x", &name_type);
}
- return do_host_query(qhost);
- }
-
- if (message) {
- return do_message_op(auth_info);
- }
-
- if (process(base_directory)) {
- return 1;
+ rc = do_host_query(qhost);
+ } else if (message) {
+ rc = do_message_op(auth_info);
+ } else if (process(base_directory)) {
+ rc = 1;
}
TALLOC_FREE(frame);