#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 "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 = -1;
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;
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;
}
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;
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)));
****************************************************************************/
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;
+ uint16_t attr;
off_t size;
off_t start = 0;
off_t nread = 0;
}
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);
}
{
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;
struct timespec b_time, a_time, m_time, c_time;
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);
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;
}
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;
}
+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.
****************************************************************************/
status = cli_ntcreate(
cli, name, 0, FILE_READ_DATA, 0,
FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
- FILE_OPEN, 0, 0, &fnum);
+ 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;
TALLOC_FREE(changes);
}
usage:
- d_printf("notify <file>\n");
+ d_printf("notify <dir name>\n");
fail:
TALLOC_FREE(frame);
return 1;
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 = "";
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)
{
{
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)) {
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;
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}},
+ {"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}},
{"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}},
{"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_REMOTE,COMPL_NONE}},
- {"showacls",cmd_showacls,"toggle if ACLs are shown or not",{COMPL_NONE,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,"<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}},
if (!NT_STATUS_IS_OK(status)) {
return 1;
}
+ cli_set_timeout(cli, io_timeout*1000);
}
while (cmd[0] != '\0') {
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 (lp_disable_netbios()) {
+ goto out;
+ }
+
if (port != NBT_SMB_PORT) {
/* Workgroups simply don't make sense over anything
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 : NBT_SMB_PORT, name_type,
lp_netbios_name(), SMB_SIGNING_DEFAULT, 0, &cli);
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>");
while ((opt = poptGetNextOpt(pc)) != -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));
}
* 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));
}
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_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);
}
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_cli_maxprotocol();
+ max_protocol = lp_client_max_protocol();
- if (tar_type) {
+ if (tar_to_process(tar_ctx)) {
if (cmdstr)
process_command_string(cmdstr);
rc = do_tar_op(base_directory);