#include "popt_common.h"
#include "rpc_client/cli_pipe.h"
#include "client/client_proto.h"
+#include "client/clitar_proto.h"
#include "../librpc/gen_ndr/ndr_srvsvc_c.h"
#include "../lib/util/select.h"
#include "system/readline.h"
#include "trans2.h"
#include "libsmb/nmblib.h"
#include "include/ntioctl.h"
+#include "../libcli/smb/smbXcli_base.h"
+#include "lib/util/xfile.h"
#ifndef REGISTER
#define REGISTER 0
extern int do_smb_browse(void); /* mDNS browsing */
extern bool override_logfile;
-extern char tar_type;
static int port = 0;
static char *service;
static char *cmdstr = NULL;
const char *cmd_ptr = NULL;
-static int io_bufsize = 524288;
+static int io_bufsize = 0; /* we use the default size */
+static int io_timeout = (CLIENT_TIMEOUT/1000); /* Per operation timeout (in seconds). */
static int name_type = 0x20;
-static int max_protocol = PROTOCOL_NT1;
+static int max_protocol = -1;
static int process_tok(char *tok);
static int cmd_help(void);
#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)
static bool translation = false;
static bool have_ip;
-/* clitar bits insert */
-extern int blocksize;
-extern bool tar_inc;
-extern bool tar_reset;
-/* clitar bits end */
-
static bool prompt = true;
static bool recurse = false;
static bool showacls = false;
bool lowercase = false;
+static bool backup_intent = false;
static struct sockaddr_storage dest_ss;
static char dest_ss_str[INET6_ADDRSTRLEN];
return x_fread(b,1,n,f);
i = 0;
- while (i < (n - 1) && (i < BUFFER_SIZE)) {
+ while (i < (n - 1)) {
if ((c = x_getc(f)) == EOF) {
break;
}
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)
static int do_dskattr(void)
{
- int total, bsize, avail;
+ uint64_t total, bsize, avail;
struct cli_state *targetcli = NULL;
char *targetpath = NULL;
TALLOC_CTX *ctx = talloc_tos();
return 1;
}
- status = cli_dskattr(targetcli, &bsize, &total, &avail);
+ status = cli_disk_size(targetcli, targetpath, &bsize, &total, &avail);
if (!NT_STATUS_IS_OK(status)) {
d_printf("Error in dskattr: %s\n", nt_errstr(status));
return 1;
}
- d_printf("\n\t\t%d blocks of size %d. %d blocks available\n",
- total, bsize, avail);
+ d_printf("\n\t\t%" PRIu64
+ " blocks of size %" PRIu64
+ ". %" PRIu64 " blocks available\n",
+ total, bsize, avail);
return 0;
}
char *targetpath = NULL;
struct cli_state *targetcli = NULL;
SMB_STRUCT_STAT sbuf;
- uint32 attributes;
+ uint32_t attributes;
int ret = 1;
TALLOC_CTX *ctx = talloc_stackframe();
NTSTATUS status;
/* Use a trans2_qpathinfo to test directories for modern servers.
Except Win9x doesn't support the qpathinfo_basic() call..... */
- if (targetcli->protocol > PROTOCOL_LANMAN2 && !targetcli->win95) {
+ if (smbXcli_conn_protocol(targetcli->conn) > PROTOCOL_LANMAN2 && !targetcli->win95) {
status = cli_qpathinfo_basic(targetcli, targetpath, &sbuf,
&attributes);
status = cli_ntcreate(cli_state, afname, 0,
CREATE_ACCESS_READ, 0,
FILE_SHARE_READ|FILE_SHARE_WRITE,
- FILE_OPEN, 0x0, 0x0, &fnum);
+ FILE_OPEN, 0x0, 0x0, &fnum, NULL);
if (!NT_STATUS_IS_OK(status)) {
DEBUG( 0, ("display_finfo() Failed to open %s: %s\n",
afname, nt_errstr(status)));
} else {
struct security_descriptor *sd = NULL;
- sd = cli_query_secdesc(cli_state, fnum, ctx);
- if (!sd) {
- status = cli_nt_error(cli_state);
+ status = cli_query_secdesc(cli_state, fnum,
+ ctx, &sd);
+ if (!NT_STATUS_IS_OK(status)) {
DEBUG( 0, ("display_finfo() failed to "
- "get security descriptor: %s",
- nt_errstr(status)));
+ "get security descriptor: %s",
+ nt_errstr(status)));
} else {
display_sec_desc(sd);
}
****************************************************************************/
NTSTATUS do_list(const char *mask,
- uint16 attribute,
+ uint16_t attribute,
NTSTATUS (*fn)(struct cli_state *cli_state, struct file_info *,
const char *dir),
bool rec,
static int cmd_dir(void)
{
TALLOC_CTX *ctx = talloc_tos();
- uint16 attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
+ uint16_t attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
char *mask = NULL;
char *buf = NULL;
int rc = 1;
static int cmd_du(void)
{
TALLOC_CTX *ctx = talloc_tos();
- uint16 attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
+ uint16_t attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
char *mask = NULL;
char *buf = NULL;
NTSTATUS status;
uint16_t fnum;
bool newhandle = false;
struct timespec tp_start;
- uint16 attr;
- SMB_OFF_T size;
+ uint16_t attr;
+ 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;
}
}
if (archive_level >= 2 && (attr & FILE_ATTRIBUTE_ARCHIVE)) {
- cli_setatr(cli, rname, attr & ~(uint16)FILE_ATTRIBUTE_ARCHIVE, 0);
+ cli_setatr(cli, rname, attr & ~(uint16_t)FILE_ATTRIBUTE_ARCHIVE, 0);
}
{
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;
static int cmd_mget(void)
{
TALLOC_CTX *ctx = talloc_tos();
- uint16 attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
+ uint16_t attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
char *mget_mask = NULL;
char *buf = NULL;
NTSTATUS status = NT_STATUS_OK;
{
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;
uint16_t fnum;
unsigned int num_streams;
struct stream_struct *streams;
int num_snapshots;
- char **snapshots;
+ char **snapshots = NULL;
unsigned int i;
NTSTATUS status;
if (!NT_STATUS_IS_OK(status)) {
d_printf("%s getting alt name for %s\n", nt_errstr(status),
name);
- return false;
+ /*
+ * Ignore not supported or not implemented, it does not
+ * hurt if we can't list alternate names.
+ */
+ if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED) ||
+ NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED)) {
+ altname[0] = '\0';
+ } else {
+ return false;
+ }
}
d_printf("altname: %s\n", altname);
- status = cli_qpathinfo2(cli, name, &b_time, &a_time, &m_time, &c_time,
- &size, &mode, &ino);
+ status = cli_qpathinfo3(cli, name, &b_time, &a_time, &m_time, &c_time,
+ &size, &mode, NULL);
if (!NT_STATUS_IS_OK(status)) {
d_printf("%s getting pathinfo for %s\n", nt_errstr(status),
name);
return false;
}
- unix_timespec_to_nt_time(&tmp, b_time);
+ tmp = unix_timespec_to_nt_time(b_time);
d_printf("create_time: %s\n", nt_time_string(talloc_tos(), tmp));
- unix_timespec_to_nt_time(&tmp, a_time);
+ tmp = unix_timespec_to_nt_time(a_time);
d_printf("access_time: %s\n", nt_time_string(talloc_tos(), tmp));
- unix_timespec_to_nt_time(&tmp, m_time);
+ tmp = unix_timespec_to_nt_time(m_time);
d_printf("write_time: %s\n", nt_time_string(talloc_tos(), tmp));
- unix_timespec_to_nt_time(&tmp, c_time);
+ tmp = unix_timespec_to_nt_time(c_time);
d_printf("change_time: %s\n", nt_time_string(talloc_tos(), tmp));
d_printf("attributes: %s (%x)\n", attr_str(talloc_tos(), mode), mode);
}
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);
+ FILE_OPEN, 0x0, 0x0, &fnum, NULL);
if (!NT_STATUS_IS_OK(status)) {
/*
* Ignore failure, it does not hurt if we can't list
*/
return 0;
}
+ /*
+ * In order to get shadow copy data over SMB1 we
+ * must call twice, once with 'get_names = false'
+ * to get the size, then again with 'get_names = true'
+ * to get the data or a Windows server fails to return
+ * valid info. Samba doesn't have this bug. JRA.
+ */
+
+ status = cli_shadow_copy_data(talloc_tos(), cli, fnum,
+ false, &snapshots, &num_snapshots);
+ if (!NT_STATUS_IS_OK(status)) {
+ cli_close(cli, fnum);
+ return 0;
+ }
status = cli_shadow_copy_data(talloc_tos(), cli, fnum,
true, &snapshots, &num_snapshots);
if (!NT_STATUS_IS_OK(status)) {
d_printf("%s\n", snapshots[i]);
snap_name = talloc_asprintf(talloc_tos(), "%s%s",
snapshots[i], name);
- status = cli_qpathinfo2(cli, snap_name, &b_time, &a_time,
+ status = cli_qpathinfo3(cli, snap_name, &b_time, &a_time,
&m_time, &c_time, &size,
NULL, NULL);
if (!NT_STATUS_IS_OK(status)) {
TALLOC_FREE(snap_name);
continue;
}
- unix_timespec_to_nt_time(&tmp, b_time);
+ tmp = unix_timespec_to_nt_time(b_time);
d_printf("create_time: %s\n", nt_time_string(talloc_tos(), tmp));
- unix_timespec_to_nt_time(&tmp, a_time);
+ tmp = unix_timespec_to_nt_time(a_time);
d_printf("access_time: %s\n", nt_time_string(talloc_tos(), tmp));
- unix_timespec_to_nt_time(&tmp, m_time);
+ tmp =unix_timespec_to_nt_time(m_time);
d_printf("write_time: %s\n", nt_time_string(talloc_tos(), tmp));
- unix_timespec_to_nt_time(&tmp, c_time);
+ tmp = unix_timespec_to_nt_time(c_time);
d_printf("change_time: %s\n", nt_time_string(talloc_tos(), tmp));
d_printf("size: %d\n", (int)size);
}
TALLOC_FREE(snapshots);
+ cli_close(cli, fnum);
return 0;
}
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;
if (f == x_stdin) {
cli_shutdown(cli);
- exit(0);
+ exit(rc);
}
return rc;
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;
}
rname = talloc_asprintf(ctx,
"%s-%d",
p+1,
- (int)sys_getpid());
+ (int)getpid());
}
if (strequal(lname,"-")) {
rname = talloc_asprintf(ctx,
"stdin-%d",
- (int)sys_getpid());
+ (int)getpid());
}
if (!rname) {
return 1;
char *mask = NULL;
char *buf = NULL;
NTSTATUS status = NT_STATUS_OK;
- uint16 attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
+ uint16_t attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
if (recurse) {
attribute |= FILE_ATTRIBUTE_DIRECTORY;
TALLOC_CTX *ctx = talloc_tos();
char *mask = NULL;
char *buf = NULL;
- uint16 attribute;
+ uint16_t attribute;
struct cli_state *targetcli;
char *targetname = NULL;
NTSTATUS status;
return 1;
}
- attribute = (uint16)strtol(buf, (char **)NULL, 16);
+ attribute = (uint16_t)strtol(buf, (char **)NULL, 16);
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
d_printf("wdel 0x<attrib> <wcard>\n");
status = cli_ntcreate(targetcli, targetname, 0,
FILE_READ_DATA|FILE_WRITE_DATA, 0,
FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN,
- 0x0, 0x0, &fnum);
+ 0x0, 0x0, &fnum, NULL);
if (!NT_STATUS_IS_OK(status)) {
status = cli_ntcreate(targetcli, targetname, 0,
FILE_READ_DATA, 0,
FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN,
- 0x0, 0x0, &fnum);
+ 0x0, 0x0, &fnum, NULL);
if (NT_STATUS_IS_OK(status)) {
d_printf("open file %s: for read/write fnum %d\n", targetname, fnum);
} else {
static int cmd_posix(void)
{
TALLOC_CTX *ctx = talloc_tos();
- uint16 major, minor;
- uint32 caplow, caphigh;
+ uint16_t major, minor;
+ uint32_t caplow, caphigh;
char *caps;
NTSTATUS status;
return 0;
}
+static int cmd_posix_whoami(void)
+{
+ TALLOC_CTX *ctx = talloc_tos();
+ NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
+ uint64_t uid = 0;
+ uint64_t gid = 0;
+ uint32_t num_gids = 0;
+ uint32_t num_sids = 0;
+ uint64_t *gids = NULL;
+ struct dom_sid *sids = NULL;
+ bool guest = false;
+ uint32_t i;
+
+ status = cli_posix_whoami(cli,
+ ctx,
+ &uid,
+ &gid,
+ &num_gids,
+ &gids,
+ &num_sids,
+ &sids,
+ &guest);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("posix_whoami failed with error %s\n", nt_errstr(status));
+ return 1;
+ }
+
+ d_printf("GUEST:%s\n", guest ? "True" : "False");
+ d_printf("UID:%" PRIu64 "\n", uid);
+ d_printf("GID:%" PRIu64 "\n", gid);
+ d_printf("NUM_GIDS:%" PRIu32 "\n", num_gids);
+ for (i = 0; i < num_gids; i++) {
+ d_printf("GIDS[%" PRIu32 "]:%" PRIu64 "\n", i, gids[i]);
+ }
+ d_printf("NUM_SIDS:%" PRIu32 "\n", num_sids);
+ for (i = 0; i < num_sids; i++) {
+ char *sid_str = dom_sid_string(ctx, &sids[i]);
+ d_printf("SIDS[%" PRIu32 "]:%s\n", i, sid_str);
+ TALLOC_FREE(sid_str);
+ }
+ return 0;
+}
+
/****************************************************************************
Remove a directory.
char *name = NULL;
char *targetname = NULL;
struct cli_state *targetcli;
- uint16 major, minor;
- uint32 caplow, caphigh;
+ uint16_t major, minor;
+ uint32_t caplow, caphigh;
char *retbuf = NULL;
size_t rb_size = 0;
SMB_STRUCT_STAT sbuf;
- uint16 num_file_acls = 0;
- uint16 num_dir_acls = 0;
- uint16 i;
+ uint16_t num_file_acls = 0;
+ uint16_t num_dir_acls = 0;
+ uint16_t i;
NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&name,NULL)) {
return 1;
}
- status = cli_posix_getfacl(targetcli, targetname, ctx, &rb_size, &retbuf);
+ status = cli_posix_getacl(targetcli, targetname, ctx, &rb_size, &retbuf);
if (!NT_STATUS_IS_OK(status)) {
d_printf("%s getfacl file %s\n",
nt_errstr(status), src);
}
for (i = 0; i < num_file_acls; i++) {
- uint32 uorg;
+ uint32_t uorg;
fstring permstring;
unsigned char tagtype = CVAL(retbuf, SMB_POSIX_ACL_HEADER_SIZE+(i*SMB_POSIX_ACL_ENTRY_SIZE));
unsigned char perms = CVAL(retbuf, SMB_POSIX_ACL_HEADER_SIZE+(i*SMB_POSIX_ACL_ENTRY_SIZE)+1);
}
for (i = 0; i < num_dir_acls; i++) {
- uint32 uorg;
+ uint32_t uorg;
fstring permstring;
unsigned char tagtype = CVAL(retbuf, SMB_POSIX_ACL_HEADER_SIZE+((i+num_file_acls)*SMB_POSIX_ACL_ENTRY_SIZE));
unsigned char perms = CVAL(retbuf, SMB_POSIX_ACL_HEADER_SIZE+((i+num_file_acls)*SMB_POSIX_ACL_ENTRY_SIZE)+1);
return 0;
}
-static void printf_cb(const char *buf, void *private_data)
-{
- printf("%s", buf);
-}
-
/****************************************************************************
Get the EA list of a file
****************************************************************************/
for (i=0; i<num_eas; i++) {
d_printf("%s (%d) =\n", eas[i].name, (int)eas[i].flags);
- dump_data_cb(eas[i].value.data, eas[i].value.length, false,
- printf_cb, NULL);
+ dump_data_file(eas[i].value.data, eas[i].value.length, false,
+ stdout);
d_printf("\n");
}
return 0;
}
+struct scopy_timing {
+ struct timespec tp_start;
+};
+
+static int scopy_status(off_t written, void *priv)
+{
+ struct timespec tp_end;
+ unsigned int scopy_total_time_ms;
+ struct scopy_timing *st = priv;
+
+ clock_gettime_mono(&tp_end);
+ scopy_total_time_ms = nsec_time_diff(&tp_end,&st->tp_start)/1000000;
+
+ DEBUG(5,("Copied %jd bytes at an average %3.1f kb/s\n",
+ (intmax_t)written, written / (1.024*scopy_total_time_ms)));
+
+ return true;
+}
+
+/****************************************************************************
+ Server-Side copy some file.
+****************************************************************************/
+
+static int cmd_scopy(void)
+{
+ TALLOC_CTX *ctx = talloc_tos();
+ char *src, *dest;
+ char *buf, *buf2;
+ struct cli_state *targetcli;
+ char *targetsrc;
+ char *targetdest;
+ uint32_t DesiredAccess, ShareAccess, CreateDisposition, CreateOptions;
+ struct smb_create_returns cr;
+ uint16_t destfnum = (uint16_t)-1;
+ uint16_t srcfnum = (uint16_t)-1;
+ off_t written = 0;
+ struct scopy_timing st;
+ int rc = 0;
+ NTSTATUS status;
+
+ if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) ||
+ !next_token_talloc(ctx, &cmd_ptr,&buf2,NULL)) {
+ d_printf("scopy <src> <dest>\n");
+ return 1;
+ }
+
+ src = talloc_asprintf(ctx,
+ "%s%s",
+ client_get_cur_dir(),
+ buf);
+ if (!src) {
+ return 1;
+ }
+
+ dest = talloc_asprintf(ctx,
+ "%s%s",
+ client_get_cur_dir(),
+ buf2);
+ if (!dest) {
+ return 1;
+ }
+
+ status = cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli,
+ &targetsrc);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("scopy %s: %s\n", src, nt_errstr(status));
+ return 1;
+ }
+
+ status = cli_resolve_path(ctx, "", auth_info, cli, dest, &targetcli,
+ &targetdest);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("scopy %s: %s\n", dest, nt_errstr(status));
+ return 1;
+ }
+
+
+ DesiredAccess = (FILE_READ_DATA|FILE_READ_EA|FILE_READ_ATTRIBUTES|
+ READ_CONTROL_ACCESS|SYNCHRONIZE_ACCESS);
+ ShareAccess = FILE_SHARE_READ|FILE_SHARE_DELETE;
+ CreateDisposition = FILE_OPEN;
+ CreateOptions = (FILE_SEQUENTIAL_ONLY|FILE_NON_DIRECTORY_FILE|
+ FILE_OPEN_REPARSE_POINT);
+ status = cli_ntcreate(targetcli, targetsrc, 0, DesiredAccess, 0,
+ ShareAccess, CreateDisposition, CreateOptions, 0x0,
+ &srcfnum, &cr);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("Failed to open file %s. %s\n",
+ targetsrc, nt_errstr(status));
+ return 1;
+ }
+
+ DesiredAccess = (FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|FILE_READ_EA|
+ FILE_WRITE_EA|FILE_READ_ATTRIBUTES|FILE_WRITE_ATTRIBUTES|
+ DELETE_ACCESS|READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|SYNCHRONIZE_ACCESS);
+ ShareAccess = FILE_SHARE_NONE;
+ CreateDisposition = FILE_CREATE;
+ CreateOptions = FILE_SEQUENTIAL_ONLY|FILE_NON_DIRECTORY_FILE;
+ status = cli_ntcreate(targetcli, targetdest, 0, DesiredAccess,
+ FILE_ATTRIBUTE_ARCHIVE, ShareAccess, CreateDisposition,
+ CreateOptions, 0x0, &destfnum, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("Failed to create file %s. %s\n",
+ targetdest, nt_errstr(status));
+ cli_close(targetcli, srcfnum);
+ return 1;
+ }
+
+ clock_gettime_mono(&st.tp_start);
+ status = cli_splice(targetcli, targetcli, srcfnum, destfnum,
+ cr.end_of_file, 0, 0, &written, scopy_status, &st);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("%s copying file %s -> %s \n",
+ nt_errstr(status),
+ targetsrc,
+ targetdest);
+ rc = 1;
+ }
+
+ status = cli_close(targetcli, srcfnum);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("Error %s closing remote source file\n", nt_errstr(status));
+ rc = 1;
+ }
+ status = cli_close(targetcli, destfnum);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("Error %s closing remote dest file\n", nt_errstr(status));
+ rc = 1;
+ }
+
+ return rc;
+}
+
/****************************************************************************
Print the volume name.
****************************************************************************/
return 0;
}
+/****************************************************************************
+ Watch directory changes
+****************************************************************************/
+
+static int cmd_notify(void)
+{
+ TALLOC_CTX *frame = talloc_stackframe();
+ char *name, *buf;
+ NTSTATUS status;
+ uint16_t fnum;
+
+ name = talloc_strdup(talloc_tos(), client_get_cur_dir());
+ if (name == NULL) {
+ goto fail;
+ }
+ if (!next_token_talloc(talloc_tos(), &cmd_ptr, &buf, NULL)) {
+ goto usage;
+ }
+ name = talloc_asprintf_append(name, "%s", buf);
+ if (name == NULL) {
+ goto fail;
+ }
+ status = cli_ntcreate(
+ cli, name, 0, FILE_READ_DATA, 0,
+ FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+ FILE_OPEN, 0, 0, &fnum, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("Could not open file: %s\n", nt_errstr(status));
+ goto fail;
+ }
+
+ while (1) {
+ uint32_t i, num_changes;
+ struct notify_change *changes;
+
+ status = cli_notify(cli, fnum, 1000, FILE_NOTIFY_CHANGE_ALL,
+ true,
+ talloc_tos(), &num_changes, &changes);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("notify returned %s\n",
+ nt_errstr(status));
+ goto fail;
+ }
+ for (i=0; i<num_changes; i++) {
+ printf("%4.4x %s\n", changes[i].action,
+ changes[i].name);
+ }
+ TALLOC_FREE(changes);
+ }
+usage:
+ d_printf("notify <dir name>\n");
+fail:
+ TALLOC_FREE(frame);
+ return 1;
+}
+
/****************************************************************************
Set the archive level.
****************************************************************************/
return 0;
}
+/****************************************************************************
+ Toggle the backup_intent state.
+****************************************************************************/
+
+static int cmd_backup(void)
+{
+ backup_intent = !backup_intent;
+ cli_set_backup_intent(cli, backup_intent);
+ DEBUG(2,("backup intent is now %s\n",backup_intent?"on":"off"));
+ return 1;
+}
+
/****************************************************************************
Toggle the lowercaseflag.
****************************************************************************/
List a share name.
****************************************************************************/
-static void browse_fn(const char *name, uint32 m,
+static void browse_fn(const char *name, uint32_t m,
const char *comment, void *state)
{
const char *typestr = "";
int i;
struct dcerpc_binding_handle *b;
- status = cli_rpc_pipe_open_noauth(cli, &ndr_table_srvsvc.syntax_id,
+ status = cli_rpc_pipe_open_noauth(cli, &ndr_table_srvsvc,
&pipe_hnd);
if (!NT_STATUS_IS_OK(status)) {
List a server name.
****************************************************************************/
-static void server_fn(const char *name, uint32 m,
+static void server_fn(const char *name, uint32_t m,
const char *comment, void *state)
{
char *buf;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
- d_printf("Current VUID is %d\n", cli->vuid);
+ d_printf("Current VUID is %d\n",
+ cli_state_get_uid(cli));
return 0;
}
- cli->vuid = atoi(buf);
+ cli_state_set_uid(cli, atoi(buf));
return 0;
}
{
TALLOC_CTX *ctx = talloc_tos();
char *l_username, *l_password;
+ struct cli_credentials *creds = NULL;
NTSTATUS nt_status;
if (!next_token_talloc(ctx, &cmd_ptr,&l_username,NULL)) {
}
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;
}
- nt_status = cli_session_setup(cli, l_username,
- l_password, strlen(l_password),
- l_password, strlen(l_password),
- lp_workgroup());
+ creds = cli_session_creds_init(ctx,
+ l_username,
+ lp_workgroup(),
+ NULL, /* realm */
+ l_password,
+ false, /* use_kerberos */
+ false, /* fallback_after_kerberos */
+ false, /* use_ccache */
+ false); /* password_is_nt_hash */
+ if (creds == NULL) {
+ d_printf("cli_session_creds_init() failed.\n");
+ return -1;
+ }
+ nt_status = cli_session_setup_creds(cli, creds);
+ TALLOC_FREE(creds);
if (!NT_STATUS_IS_OK(nt_status)) {
d_printf("session setup failed: %s\n", nt_errstr(nt_status));
return -1;
}
- d_printf("Current VUID is %d\n", cli->vuid);
+ d_printf("Current VUID is %d\n", cli_state_get_uid(cli));
+ return 0;
+}
+
+/**
+ * close the session
+ */
+
+static int cmd_logoff(void)
+{
+ NTSTATUS status;
+
+ status = cli_ulogoff(cli);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("logoff failed: %s\n", nt_errstr(status));
+ return -1;
+ }
+
+ d_printf("logoff successful\n");
+ return 0;
+}
+
+
+/**
+ * tree connect (connect to a share)
+ */
+
+static int cmd_tcon(void)
+{
+ TALLOC_CTX *ctx = talloc_tos();
+ char *sharename;
+ NTSTATUS status;
+
+ if (!next_token_talloc(ctx, &cmd_ptr, &sharename, NULL)) {
+ d_printf("tcon <sharename>\n");
+ return 0;
+ }
+
+ if (!sharename) {
+ return 1;
+ }
+
+ status = cli_tree_connect(cli, sharename, "?????", "", 0);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("tcon failed: %s\n", nt_errstr(status));
+ return -1;
+ }
+
+ talloc_free(sharename);
+
+ d_printf("tcon to %s successful, tid: %u\n", sharename,
+ cli_state_get_tid(cli));
+ return 0;
+}
+
+/**
+ * tree disconnect (disconnect from a share)
+ */
+
+static int cmd_tdis(void)
+{
+ NTSTATUS status;
+
+ status = cli_tdis(cli);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("tdis failed: %s\n", nt_errstr(status));
+ return -1;
+ }
+
+ d_printf("tdis successful\n");
+ return 0;
+}
+
+
+/**
+ * get or set tid
+ */
+
+static int cmd_tid(void)
+{
+ TALLOC_CTX *ctx = talloc_tos();
+ char *tid_str;
+
+ if (!next_token_talloc(ctx, &cmd_ptr, &tid_str, NULL)) {
+ if (cli_state_has_tcon(cli)) {
+ d_printf("current tid is %d\n", cli_state_get_tid(cli));
+ } else {
+ d_printf("no tcon currently\n");
+ }
+ } else {
+ uint16_t tid = atoi(tid_str);
+ cli_state_set_tid(cli, tid);
+ }
+
return 0;
}
return 1;
}
- d_printf("//%s/%s\n", targetcli->desthost, targetcli->share);
+ d_printf("//%s/%s\n", smbXcli_conn_remote_name(targetcli->conn), targetcli->share);
+ return 0;
+}
+
+/**
+ * set_remote_attr - set DOS attributes of a remote file
+ * @filename: path to the file name
+ * @new_attr: attribute bit mask to use
+ * @mode: one of ATTR_SET or ATTR_UNSET
+ *
+ * Update the file attributes with the one provided.
+ */
+int set_remote_attr(const char *filename, uint16_t new_attr, int mode)
+{
+ extern struct cli_state *cli;
+ uint16_t old_attr;
+ NTSTATUS status;
+
+ status = cli_getatr(cli, filename, &old_attr, NULL, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("cli_getatr failed: %s\n", nt_errstr(status));
+ return 1;
+ }
+
+ if (mode == ATTR_SET) {
+ new_attr |= old_attr;
+ } else {
+ new_attr = old_attr & ~new_attr;
+ }
+
+ status = cli_setatr(cli, filename, new_attr, 0);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("cli_setatr failed: %s\n", nt_errstr(status));
+ return 1;
+ }
+
return 0;
}
+/**
+ * cmd_setmode - interactive command to set DOS attributes
+ *
+ * Read a filename and mode from the client command line and update
+ * the file DOS attributes.
+ */
+int cmd_setmode(void)
+{
+ const extern char *cmd_ptr;
+ char *buf;
+ char *fname = NULL;
+ uint16_t attr[2] = {0};
+ int mode = ATTR_SET;
+ int err = 0;
+ bool ok;
+ TALLOC_CTX *ctx = talloc_new(NULL);
+ if (ctx == NULL) {
+ return 1;
+ }
+
+ ok = next_token_talloc(ctx, &cmd_ptr, &buf, NULL);
+ if (!ok) {
+ d_printf("setmode <filename> <[+|-]rsha>\n");
+ err = 1;
+ goto out;
+ }
+
+ fname = talloc_asprintf(ctx,
+ "%s%s",
+ client_get_cur_dir(),
+ buf);
+ if (fname == NULL) {
+ err = 1;
+ goto out;
+ }
+
+ while (next_token_talloc(ctx, &cmd_ptr, &buf, NULL)) {
+ const char *s = buf;
+
+ while (*s) {
+ switch (*s++) {
+ case '+':
+ mode = ATTR_SET;
+ break;
+ case '-':
+ mode = ATTR_UNSET;
+ break;
+ case 'r':
+ attr[mode] |= FILE_ATTRIBUTE_READONLY;
+ break;
+ case 'h':
+ attr[mode] |= FILE_ATTRIBUTE_HIDDEN;
+ break;
+ case 's':
+ attr[mode] |= FILE_ATTRIBUTE_SYSTEM;
+ break;
+ case 'a':
+ attr[mode] |= FILE_ATTRIBUTE_ARCHIVE;
+ break;
+ default:
+ d_printf("setmode <filename> <perm=[+|-]rsha>\n");
+ err = 1;
+ goto out;
+ }
+ }
+ }
+
+ if (attr[ATTR_SET] == 0 && attr[ATTR_UNSET] == 0) {
+ d_printf("setmode <filename> <[+|-]rsha>\n");
+ err = 1;
+ goto out;
+ }
+
+ DEBUG(2, ("perm set %d %d\n", attr[ATTR_SET], attr[ATTR_UNSET]));
+
+ /* ignore return value: server might not store DOS attributes */
+ set_remote_attr(fname, attr[ATTR_SET], ATTR_SET);
+ set_remote_attr(fname, attr[ATTR_UNSET], ATTR_UNSET);
+out:
+ talloc_free(ctx);
+ return err;
+}
+
/****************************************************************************
iosize command
***************************************************************************/
int iosize;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
- if (!smb_encrypt) {
- d_printf("iosize <n> or iosize 0x<n>. "
- "Minimum is 16384 (0x4000), "
- "max is 16776960 (0xFFFF00)\n");
+ if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
+ if (!smb_encrypt) {
+ d_printf("iosize <n> or iosize 0x<n>. "
+ "Minimum is 0 (default), "
+ "max is 16776960 (0xFFFF00)\n");
+ } else {
+ d_printf("iosize <n> or iosize 0x<n>. "
+ "(Encrypted connection) ,"
+ "Minimum is 0 (default), "
+ "max is 130048 (0x1FC00)\n");
+ }
} else {
- d_printf("iosize <n> or iosize 0x<n>. "
- "(Encrypted connection) ,"
- "Minimum is 16384 (0x4000), "
- "max is 130048 (0x1FC00)\n");
+ d_printf("iosize <n> or iosize 0x<n>.\n");
}
return 1;
}
iosize = strtol(buf,NULL,0);
- if (smb_encrypt && (iosize < 0x4000 || iosize > 0xFC00)) {
- d_printf("iosize out of range for encrypted "
- "connection (min = 16384 (0x4000), "
- "max = 130048 (0x1FC00)");
- return 1;
- } else if (!smb_encrypt && (iosize < 0x4000 || iosize > 0xFFFF00)) {
- d_printf("iosize out of range (min = 16384 (0x4000), "
- "max = 16776960 (0xFFFF00)");
- return 1;
+ if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
+ if (smb_encrypt && (iosize < 0 || iosize > 0xFC00)) {
+ d_printf("iosize out of range for encrypted "
+ "connection (min = 0 (default), "
+ "max = 130048 (0x1FC00)\n");
+ return 1;
+ } else if (!smb_encrypt && (iosize < 0 || iosize > 0xFFFF00)) {
+ d_printf("iosize out of range (min = 0 (default), "
+ "max = 16776960 (0xFFFF00)\n");
+ return 1;
+ }
}
io_bufsize = iosize;
return 0;
}
+/****************************************************************************
+ timeout command
+***************************************************************************/
+
+static int cmd_timeout(void)
+{
+ TALLOC_CTX *ctx = talloc_tos();
+ char *buf;
+
+ if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
+ unsigned int old_timeout = cli_set_timeout(cli, 0);
+ cli_set_timeout(cli, old_timeout);
+ d_printf("timeout <n> (per-operation timeout "
+ "in seconds - currently %u).\n",
+ old_timeout/1000);
+ return 1;
+ }
+
+ io_timeout = strtol(buf,NULL,0);
+ cli_set_timeout(cli, io_timeout*1000);
+ d_printf("io_timeout per operation is now %d\n", io_timeout);
+ return 0;
+}
+
+
/****************************************************************************
history
****************************************************************************/
{COMPL_NONE,COMPL_NONE}},
{"altname",cmd_altname,"<file> show alt name",{COMPL_NONE,COMPL_NONE}},
{"archive",cmd_archive,"<level>\n0=ignore archive bit\n1=only get archive files\n2=only get archive files and reset archive bit\n3=get all files and reset archive bit",{COMPL_NONE,COMPL_NONE}},
+ {"backup",cmd_backup,"toggle backup intent state",{COMPL_NONE,COMPL_NONE}},
{"blocksize",cmd_block,"blocksize <number> (default 20)",{COMPL_NONE,COMPL_NONE}},
{"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}},
{"lcd",cmd_lcd,"[directory] change/report the local current working directory",{COMPL_LOCAL,COMPL_NONE}},
{"link",cmd_link,"<oldname> <newname> create a UNIX hard link",{COMPL_REMOTE,COMPL_REMOTE}},
{"lock",cmd_lock,"lock <fnum> [r|w] <hex-start> <hex-len> : set a POSIX lock",{COMPL_REMOTE,COMPL_REMOTE}},
- {"lowercase",cmd_lowercase,"toggle lowercasing of filenames for get",{COMPL_NONE,COMPL_NONE}},
+ {"lowercase",cmd_lowercase,"toggle lowercasing of filenames for get",{COMPL_NONE,COMPL_NONE}},
{"ls",cmd_dir,"<mask> list the contents of the current directory",{COMPL_REMOTE,COMPL_NONE}},
{"l",cmd_dir,"<mask> list the contents of the current directory",{COMPL_REMOTE,COMPL_NONE}},
{"mask",cmd_select,"<mask> mask all filenames against this",{COMPL_REMOTE,COMPL_NONE}},
{"md",cmd_mkdir,"<directory> make a directory",{COMPL_NONE,COMPL_NONE}},
{"mget",cmd_mget,"<mask> get all the matching files",{COMPL_REMOTE,COMPL_NONE}},
{"mkdir",cmd_mkdir,"<directory> make a directory",{COMPL_NONE,COMPL_NONE}},
- {"more",cmd_more,"<remote name> view a remote file with your pager",{COMPL_REMOTE,COMPL_NONE}},
+ {"more",cmd_more,"<remote name> view a remote file with your pager",{COMPL_REMOTE,COMPL_NONE}},
{"mput",cmd_mput,"<mask> put all matching files",{COMPL_REMOTE,COMPL_NONE}},
{"newer",cmd_newer,"<file> only mget files newer than the specified local file",{COMPL_LOCAL,COMPL_NONE}},
+ {"notify",cmd_notify,"<file>Get notified of dir changes",{COMPL_REMOTE,COMPL_NONE}},
{"open",cmd_open,"<mask> open a file",{COMPL_REMOTE,COMPL_NONE}},
{"posix", cmd_posix, "turn on all POSIX capabilities", {COMPL_REMOTE,COMPL_NONE}},
{"posix_encrypt",cmd_posix_encrypt,"<domain> <user> <password> start up transport encryption",{COMPL_REMOTE,COMPL_NONE}},
{"posix_mkdir",cmd_posix_mkdir,"<name> 0<mode> creates a directory using POSIX interface",{COMPL_REMOTE,COMPL_NONE}},
{"posix_rmdir",cmd_posix_rmdir,"<name> removes a directory using POSIX interface",{COMPL_REMOTE,COMPL_NONE}},
{"posix_unlink",cmd_posix_unlink,"<name> removes a file using POSIX interface",{COMPL_REMOTE,COMPL_NONE}},
+ {"posix_whoami",cmd_posix_whoami,"retun logged on user information "
+ "using POSIX interface",{COMPL_REMOTE,COMPL_NONE}},
{"print",cmd_print,"<file name> print a file",{COMPL_NONE,COMPL_NONE}},
- {"prompt",cmd_prompt,"toggle prompting for filenames for mget and mput",{COMPL_NONE,COMPL_NONE}},
+ {"prompt",cmd_prompt,"toggle prompting for filenames for mget and mput",{COMPL_NONE,COMPL_NONE}},
{"put",cmd_put,"<local name> [remote name] put a file",{COMPL_LOCAL,COMPL_REMOTE}},
{"pwd",cmd_pwd,"show current remote directory (same as 'cd' with no args)",{COMPL_NONE,COMPL_NONE}},
{"q",cmd_quit,"logoff the server",{COMPL_NONE,COMPL_NONE}},
{"quit",cmd_quit,"logoff the server",{COMPL_NONE,COMPL_NONE}},
{"readlink",cmd_readlink,"filename Do a UNIX extensions readlink call on a symlink",{COMPL_REMOTE,COMPL_REMOTE}},
{"rd",cmd_rmdir,"<directory> remove a directory",{COMPL_NONE,COMPL_NONE}},
- {"recurse",cmd_recurse,"toggle directory recursion for mget and mput",{COMPL_NONE,COMPL_NONE}},
+ {"recurse",cmd_recurse,"toggle directory recursion for mget and mput",{COMPL_NONE,COMPL_NONE}},
{"reget",cmd_reget,"<remote name> [local name] get a file restarting at end of local file",{COMPL_REMOTE,COMPL_LOCAL}},
{"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}},
- {"showacls",cmd_showacls,"toggle if ACLs are shown or not",{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}},
+ {"scopy",cmd_scopy,"<src> <dest> server-side copy file",{COMPL_REMOTE,COMPL_REMOTE}},
+ {"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}},
+ {"timeout",cmd_timeout,"timeout <number> - set the per-operation timeout in seconds (default 20)",{COMPL_NONE,COMPL_NONE}},
{"translate",cmd_translate,"toggle text translation for printing",{COMPL_NONE,COMPL_NONE}},
{"unlock",cmd_unlock,"unlock <fnum> <hex-start> <hex-len> : remove a POSIX lock",{COMPL_REMOTE,COMPL_REMOTE}},
{"volume",cmd_volume,"print the volume name",{COMPL_NONE,COMPL_NONE}},
{"logon",cmd_logon,"establish new logon",{COMPL_NONE,COMPL_NONE}},
{"listconnect",cmd_list_connect,"list open connections",{COMPL_NONE,COMPL_NONE}},
{"showconnect",cmd_show_connect,"display the current active connection",{COMPL_NONE,COMPL_NONE}},
+ {"tcon",cmd_tcon,"connect to a share" ,{COMPL_NONE,COMPL_NONE}},
+ {"tdis",cmd_tdis,"disconnect from a share",{COMPL_NONE,COMPL_NONE}},
+ {"tid",cmd_tid,"show or set the current tid (tree-id)",{COMPL_NONE,COMPL_NONE}},
+ {"logoff",cmd_logoff,"log off (close the session)",{COMPL_NONE,COMPL_NONE}},
{"..",cmd_cd_oneup,"change the remote directory (up one level)",{COMPL_REMOTE,COMPL_NONE}},
/* Yes, this must be here, see crh's comment above. */
if (!NT_STATUS_IS_OK(status)) {
return 1;
}
+ cli_set_timeout(cli, io_timeout*1000);
}
while (cmd[0] != '\0') {
info.matches[0] = SMB_STRNDUP(info.matches[1], info.samelen);
info.matches[info.count] = NULL;
+ TALLOC_FREE(ctx);
return info.matches;
cleanup:
static time_t last_t;
struct timespec now;
time_t t;
- int ret, revents;
+ NTSTATUS status;
+ unsigned char garbage[16];
clock_gettime_mono(&now);
t = now.tv_sec;
last_t = t;
- again:
-
- if (cli->fd == -1)
+ /* Ping the server to keep the connection alive using SMBecho. */
+ memset(garbage, 0xf0, sizeof(garbage));
+ status = cli_echo(cli, 1, data_blob_const(garbage, sizeof(garbage)));
+ if (NT_STATUS_IS_OK(status)) {
return;
-
- /* We deliberately use receive_smb_raw instead of
- client_receive_smb as we want to receive
- session keepalives and then drop them here.
- */
-
- ret = poll_intr_one_fd(cli->fd, POLLIN|POLLHUP, 0, &revents);
-
- if ((ret > 0) && (revents & (POLLIN|POLLHUP|POLLERR))) {
- NTSTATUS status;
- size_t len;
-
- set_smb_read_error(&cli->smb_rw_error, SMB_READ_OK);
-
- status = receive_smb_raw(cli->fd, cli->inbuf, cli->bufsize, 0, 0, &len);
-
- if (!NT_STATUS_IS_OK(status)) {
- if (cli->fd != -1) {
- close(cli->fd);
- cli->fd = -1;
- }
-
- DEBUG(0, ("Read from server failed, maybe it closed "
- "the connection\n"));
-
- finished = true;
- smb_readline_done();
- if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) {
- set_smb_read_error(&cli->smb_rw_error,
- SMB_READ_EOF);
- return;
- }
-
- if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
- set_smb_read_error(&cli->smb_rw_error,
- SMB_READ_TIMEOUT);
- return;
- }
-
- set_smb_read_error(&cli->smb_rw_error, SMB_READ_ERROR);
- return;
- }
- if(CVAL(cli->inbuf,0) != SMBkeepalive) {
- DEBUG(0, ("Read from server "
- "returned unexpected packet!\n"));
- return;
- }
-
- goto again;
}
- /* Ping the server to keep the connection alive using SMBecho. */
- {
- NTSTATUS status;
- unsigned char garbage[16];
- memset(garbage, 0xf0, sizeof(garbage));
- status = cli_echo(cli, 1, data_blob_const(garbage, sizeof(garbage)));
-
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(0, ("SMBecho failed. Maybe server has closed "
- "the connection\n"));
- finished = true;
- smb_readline_done();
- }
+ if (!cli_state_is_connected(cli)) {
+ DEBUG(0,("SMBecho failed (%s). The connection is "
+ "disconnected now\n", nt_errstr(status)));
+ finished = true;
+ smb_readline_done();
}
}
return 1;
}
+ cli_set_timeout(cli, io_timeout*1000);
+
if (base_directory && *base_directory) {
rc = do_cd(base_directory);
if (rc) {
return 1;
}
+ cli_set_timeout(cli, io_timeout*1000);
browse_host(true);
/* Ensure that the host can do IPv4 */
}
}
- if (port != 139) {
+ if (lp_disable_netbios()) {
+ goto out;
+ }
+
+ if (port != NBT_SMB_PORT) {
/* Workgroups simply don't make sense over anything
else but port 139... */
status = cli_cm_open(talloc_tos(), NULL,
have_ip ? dest_ss_str : query_host,
"IPC$", auth_info, true, smb_encrypt,
- max_protocol, 139, name_type, &cli);
+ max_protocol, NBT_SMB_PORT, name_type,
+ &cli);
if (!NT_STATUS_IS_OK(status)) {
cli = NULL;
}
if (cli == NULL) {
d_printf("NetBIOS over TCP disabled -- no workgroup available\n");
- return 1;
+ return 0;
}
+ cli_set_timeout(cli, io_timeout*1000);
list_servers(lp_workgroup());
-
+out:
cli_shutdown(cli);
return(0);
static int do_tar_op(const char *base_directory)
{
- int ret;
+ struct tar *tar_ctx = tar_get_ctx();
+ int ret = 0;
/* do we already have a connection? */
if (!cli) {
service, auth_info, true, smb_encrypt,
max_protocol, port, name_type, &cli);
if (!NT_STATUS_IS_OK(status)) {
- return 1;
+ ret = 1;
+ goto out;
}
+ cli_set_timeout(cli, io_timeout*1000);
}
- recurse=true;
+ recurse = true;
if (base_directory && *base_directory) {
ret = do_cd(base_directory);
if (ret) {
- cli_shutdown(cli);
- return ret;
+ goto out_cli;
}
}
- ret=process_tar();
+ ret = tar_process(tar_ctx);
+ out_cli:
cli_shutdown(cli);
-
- return(ret);
+ out:
+ return ret;
}
/****************************************************************************
{
NTSTATUS status;
+ if (lp_disable_netbios()) {
+ d_printf("NetBIOS over TCP disabled.\n");
+ return 1;
+ }
+
status = cli_connect_nb(desthost, have_ip ? &dest_ss : NULL,
- port ? port : 139, name_type,
- lp_netbios_name(), Undefined, &cli);
+ port ? port : NBT_SMB_PORT, name_type,
+ lp_netbios_name(), SMB_SIGNING_DEFAULT, 0, &cli);
if (!NT_STATUS_IS_OK(status)) {
d_printf("Connection to %s failed. Error %s\n", desthost, nt_errstr(status));
return 1;
}
+ cli_set_timeout(cli, io_timeout*1000);
send_message(get_cmdline_auth_info_username(a_info));
cli_shutdown(cli);
main program
****************************************************************************/
- int main(int argc,char *argv[])
+int main(int argc,char *argv[])
{
+ const char **const_argv = discard_const_p(const char *, argv);
char *base_directory = NULL;
int opt;
char *query_host = NULL;
int rc = 0;
bool tar_opt = false;
bool service_opt = false;
+ struct tar *tar_ctx = tar_get_ctx();
+
struct poptOption long_options[] = {
POPT_AUTOHELP
{ "max-protocol", 'm', POPT_ARG_STRING, NULL, 'm', "Set the max protocol level", "LEVEL" },
{ "tar", 'T', POPT_ARG_STRING, NULL, 'T', "Command line tar", "<c|x>IXFqgbNan" },
{ "directory", 'D', POPT_ARG_STRING, NULL, 'D', "Start from directory", "DIR" },
- { "command", 'c', POPT_ARG_STRING, &cmdstr, 'c', "Execute semicolon separated commands" },
+ { "command", 'c', POPT_ARG_STRING, &cmdstr, 'c', "Execute semicolon separated commands" },
{ "send-buffer", 'b', POPT_ARG_INT, &io_bufsize, 'b', "Changes the transmit/send buffer", "BYTES" },
+ { "timeout", 't', POPT_ARG_INT, &io_timeout, 'b', "Changes the per-operation timeout", "SECONDS" },
{ "port", 'p', POPT_ARG_INT, &port, 'p', "Port to connect to", "PORT" },
{ "grepable", 'g', POPT_ARG_NONE, NULL, 'g', "Produce grepable output" },
{ "browse", 'B', POPT_ARG_NONE, NULL, 'B', "Browse SMB servers using DNS" },
/* set default debug level to 1 regardless of what smb.conf sets */
setup_logging( "smbclient", DEBUG_DEFAULT_STDERR );
- load_case_tables();
+ smb_init_locale();
lp_set_cmdline("log level", "1");
- auth_info = user_auth_info_init(frame);
- if (auth_info == NULL) {
- exit(1);
- }
- popt_common_set_auth_info(auth_info);
+ popt_common_credentials_set_delay_post();
/* skip argv(0) */
- pc = poptGetContext("smbclient", argc, (const char **) argv, long_options, 0);
+ pc = poptGetContext("smbclient", argc, const_argv, long_options, 0);
poptSetOtherOptionHelp(pc, "service <password>");
- lp_set_in_client(true); /* Make sure that we tell lp_load we are */
-
while ((opt = poptGetNextOpt(pc)) != -1) {
/* if the tar option has been called previouslt, now we need to eat out the leftovers */
/* if the service has already been retrieved then check if we have also a password */
if (service_opt
- && (!get_cmdline_auth_info_got_pass(auth_info))
+ && (!get_cmdline_auth_info_got_pass(cmdline_auth_info))
&& poptPeekArg(pc)) {
- set_cmdline_auth_info_password(auth_info,
+ set_cmdline_auth_info_password(cmdline_auth_info,
poptGetArg(pc));
}
+
switch (opt) {
case 'M':
/* Messages are sent to NetBIOS name type 0x3
exit(ENOMEM);
}
if( !port )
- port = 139;
+ port = NBT_SMB_PORT;
message = true;
break;
case 'I':
}
break;
case 'm':
- max_protocol = interpret_protocol(poptGetOptArg(pc), max_protocol);
+ lp_set_cmdline("client max protocol", poptGetOptArg(pc));
break;
case 'T':
/* We must use old option processing for this. Find the
* position of the -T option in the raw argv[]. */
{
int i;
+
for (i = 1; i < argc; i++) {
if (strncmp("-T", argv[i],2)==0)
break;
}
i++;
- if (!tar_parseargs(argc, argv, poptGetOptArg(pc), i)) {
+ if (tar_parse_args(tar_ctx, poptGetOptArg(pc),
+ const_argv + i, argc - i)) {
poptPrintUsage(pc, stderr, 0);
exit(1);
}
/* if the service has already been retrieved then check if we have also a password */
if (service_opt
- && !get_cmdline_auth_info_got_pass(auth_info)
+ && !get_cmdline_auth_info_got_pass(cmdline_auth_info)
&& poptPeekArg(pc)) {
- set_cmdline_auth_info_password(auth_info,
+ set_cmdline_auth_info_password(cmdline_auth_info,
poptGetArg(pc));
}
if ( override_logfile )
- setup_logging( lp_logfile(), DEBUG_FILE );
+ setup_logging( lp_logfile(talloc_tos()), DEBUG_FILE );
- if (!lp_load(get_dyn_CONFIGFILE(),true,false,false,true)) {
+ if (!lp_load_client(get_dyn_CONFIGFILE())) {
fprintf(stderr, "%s: Can't load %s - run testparm to debug it\n",
argv[0], get_dyn_CONFIGFILE());
}
- if (get_cmdline_auth_info_use_machine_account(auth_info) &&
- !set_cmdline_auth_info_machine_account_creds(auth_info)) {
- exit(-1);
- }
-
load_interfaces();
if (service_opt && service) {
}
}
- smb_encrypt = get_cmdline_auth_info_smb_encrypt(auth_info);
if (!init_names()) {
fprintf(stderr, "init_names() failed\n");
exit(1);
}
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) {
+ if (!tar_to_process(tar_ctx) && !query_host && !service && !message) {
poptPrintUsage(pc, stderr, 0);
exit(1);
}
poptFreeContext(pc);
+ popt_burn_cmdline_password(argc, argv);
DEBUG(3,("Client started (version %s).\n", samba_version_string()));
/* Ensure we have a password (or equivalent). */
- set_cmdline_auth_info_getpass(auth_info);
+ popt_common_credentials_post();
+ auth_info = cmdline_auth_info;
+ smb_encrypt = get_cmdline_auth_info_smb_encrypt(auth_info);
+
+ max_protocol = lp_client_max_protocol();
- if (tar_type) {
+ if (tar_to_process(tar_ctx)) {
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);