*/
#include "includes.h"
+#include "system/filesys.h"
#include "popt_common.h"
+#include "rpc_client/cli_pipe.h"
#include "client/client_proto.h"
-#include "../librpc/gen_ndr/cli_srvsvc.h"
+#include "../librpc/gen_ndr/ndr_srvsvc_c.h"
+#include "../lib/util/select.h"
+#include "system/readline.h"
+#include "../libcli/smbreadline/smbreadline.h"
+#include "../libcli/security/security.h"
+#include "system/select.h"
+#include "libsmb/libsmb.h"
+#include "libsmb/clirap.h"
+#include "trans2.h"
+#include "libsmb/nmblib.h"
+#include "include/ntioctl.h"
#ifndef REGISTER
#define REGISTER 0
extern int do_smb_browse(void); /* mDNS browsing */
-extern bool AllowDebugChange;
extern bool override_logfile;
extern char tar_type;
static int port = 0;
static char *service;
static char *desthost;
-static char *calling_name;
static bool grepable = false;
static char *cmdstr = NULL;
const char *cmd_ptr = NULL;
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];
TALLOC_CTX *ctx = talloc_tos();
NTSTATUS status;
- if ( !cli_resolve_path(ctx, "", auth_info, cli, client_get_cur_dir(), &targetcli, &targetpath)) {
- d_printf("Error in dskattr: %s\n", cli_errstr(cli));
+ status = cli_resolve_path(ctx, "", auth_info, cli,
+ client_get_cur_dir(), &targetcli,
+ &targetpath);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("Error in dskattr: %s\n", nt_errstr(status));
return 1;
}
uint32 attributes;
int ret = 1;
TALLOC_CTX *ctx = talloc_stackframe();
+ NTSTATUS status;
newdir = talloc_strdup(ctx, new_dir);
if (!newdir) {
new_cd = clean_name(ctx, new_cd);
client_set_cur_dir(new_cd);
- if ( !cli_resolve_path(ctx, "", auth_info, cli, new_cd, &targetcli, &targetpath)) {
- d_printf("cd %s: %s\n", new_cd, cli_errstr(cli));
+ status = cli_resolve_path(ctx, "", auth_info, cli, new_cd,
+ &targetcli, &targetpath);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("cd %s: %s\n", new_cd, nt_errstr(status));
client_set_cur_dir(saved_dir);
goto out;
}
/* 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) {
- NTSTATUS status;
+ if (cli_state_protocol(targetcli) > PROTOCOL_LANMAN2 && !targetcli->win95) {
status = cli_qpathinfo_basic(targetcli, targetpath, &sbuf,
&attributes);
goto out;
}
} else {
- NTSTATUS status;
targetpath = talloc_asprintf(ctx,
"%s%s",
return false;
}
- if (finfo->mode & aDIR) {
+ if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
return true;
}
return false;
}
- if ((archive_level==1 || archive_level==2) && !(finfo->mode & aARCH)) {
+ if ((archive_level==1 || archive_level==2) && !(finfo->mode & FILE_ATTRIBUTE_ARCHIVE)) {
DEBUG(3,("archive %s failed\n", finfo->name));
return false;
}
Display info about a file.
****************************************************************************/
-static void display_finfo(struct cli_state *cli_state, struct file_info *finfo,
+static NTSTATUS display_finfo(struct cli_state *cli_state, struct file_info *finfo,
const char *dir)
{
time_t t;
TALLOC_CTX *ctx = talloc_tos();
+ NTSTATUS status = NT_STATUS_OK;
if (!do_this_one(finfo)) {
- return;
+ return NT_STATUS_OK;
}
t = finfo->mtime_ts.tv_sec; /* the time is assumed to be passed as GMT */
if (!showacls) {
d_printf(" %-30s%7.7s %8.0f %s",
finfo->name,
- attrib_string(finfo->mode),
+ attrib_string(talloc_tos(), finfo->mode),
(double)finfo->size,
time_to_asc(t));
dir_total += finfo->size;
} else {
char *afname = NULL;
uint16_t fnum;
- NTSTATUS status;
/* skip if this is . or .. */
if ( strequal(finfo->name,"..") || strequal(finfo->name,".") )
- return;
+ return NT_STATUS_OK;
/* create absolute filename for cli_ntcreate() FIXME */
afname = talloc_asprintf(ctx,
"%s%s%s",
CLI_DIRSEP_STR,
finfo->name);
if (!afname) {
- return;
+ return NT_STATUS_NO_MEMORY;
}
/* print file meta date header */
d_printf( "FILENAME:%s\n", finfo->name);
- d_printf( "MODE:%s\n", attrib_string(finfo->mode));
+ d_printf( "MODE:%s\n", attrib_string(talloc_tos(), finfo->mode));
d_printf( "SIZE:%.0f\n", (double)finfo->size);
d_printf( "MTIME:%s", time_to_asc(t));
status = cli_ntcreate(cli_state, afname, 0,
afname, nt_errstr(status)));
} else {
struct security_descriptor *sd = NULL;
- sd = cli_query_secdesc(cli_state, fnum, ctx);
- if (!sd) {
+ 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",
- cli_errstr(cli_state)));
+ "get security descriptor: %s",
+ nt_errstr(status)));
} else {
display_sec_desc(sd);
}
}
TALLOC_FREE(afname);
}
+ return status;
}
/****************************************************************************
Accumulate size of a file.
****************************************************************************/
-static void do_du(struct cli_state *cli_state, struct file_info *finfo,
+static NTSTATUS do_du(struct cli_state *cli_state, struct file_info *finfo,
const char *dir)
{
if (do_this_one(finfo)) {
dir_total += finfo->size;
}
+ return NT_STATUS_OK;
}
static bool do_list_recurse;
static long do_list_queue_size = 0;
static long do_list_queue_start = 0;
static long do_list_queue_end = 0;
-static void (*do_list_fn)(struct cli_state *cli_state, struct file_info *,
+static NTSTATUS (*do_list_fn)(struct cli_state *cli_state, struct file_info *,
const char *dir);
/****************************************************************************
}
}
if (do_list_queue) {
- safe_strcpy_base(do_list_queue + do_list_queue_end,
+ strlcpy_base(do_list_queue + do_list_queue_end,
entry, do_list_queue, do_list_queue_size);
do_list_queue_end = new_end;
DEBUG(4,("added %s to do_list_queue (start=%d, end=%d)\n",
A helper for do_list.
****************************************************************************/
-static void do_list_helper(const char *mntpoint, struct file_info *f,
+static NTSTATUS do_list_helper(const char *mntpoint, struct file_info *f,
const char *mask, void *state)
{
struct cli_state *cli_state = (struct cli_state *)state;
TALLOC_CTX *ctx = talloc_tos();
char *dir = NULL;
char *dir_end = NULL;
+ NTSTATUS status = NT_STATUS_OK;
/* Work out the directory. */
dir = talloc_strdup(ctx, mask);
if (!dir) {
- return;
+ return NT_STATUS_NO_MEMORY;
}
if ((dir_end = strrchr(dir, CLI_DIRSEP_CHAR)) != NULL) {
*dir_end = '\0';
}
- if (f->mode & aDIR) {
+ if (f->mode & FILE_ATTRIBUTE_DIRECTORY) {
if (do_list_dirs && do_this_one(f)) {
- do_list_fn(cli_state, f, dir);
+ status = do_list_fn(cli_state, f, dir);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
}
if (do_list_recurse &&
f->name &&
if (!f->name[0]) {
d_printf("Empty dir name returned. Possible server misconfiguration.\n");
TALLOC_FREE(dir);
- return;
+ return NT_STATUS_UNSUCCESSFUL;
}
mask2 = talloc_asprintf(ctx,
mask);
if (!mask2) {
TALLOC_FREE(dir);
- return;
+ return NT_STATUS_NO_MEMORY;
}
p = strrchr_m(mask2,CLI_DIRSEP_CHAR);
if (p) {
CLI_DIRSEP_STR);
if (!mask2) {
TALLOC_FREE(dir);
- return;
+ return NT_STATUS_NO_MEMORY;
}
add_to_do_list_queue(mask2);
TALLOC_FREE(mask2);
}
TALLOC_FREE(dir);
- return;
+ return NT_STATUS_OK;
}
if (do_this_one(f)) {
- do_list_fn(cli_state, f, dir);
+ status = do_list_fn(cli_state, f, dir);
}
TALLOC_FREE(dir);
+ return status;
}
/****************************************************************************
A wrapper around cli_list that adds recursion.
****************************************************************************/
-void do_list(const char *mask,
+NTSTATUS do_list(const char *mask,
uint16 attribute,
- void (*fn)(struct cli_state *cli_state, struct file_info *,
+ NTSTATUS (*fn)(struct cli_state *cli_state, struct file_info *,
const char *dir),
bool rec,
bool dirs)
TALLOC_CTX *ctx = talloc_tos();
struct cli_state *targetcli = NULL;
char *targetpath = NULL;
+ NTSTATUS ret_status = NT_STATUS_OK;
+ NTSTATUS status = NT_STATUS_OK;
if (in_do_list && rec) {
fprintf(stderr, "INTERNAL ERROR: do_list called recursively when the recursive flag is true\n");
char *head = talloc_strdup(ctx, do_list_queue_head());
if (!head) {
- return;
+ return NT_STATUS_NO_MEMORY;
}
/* check for dfs */
- if ( !cli_resolve_path(ctx, "", auth_info, cli, head, &targetcli, &targetpath ) ) {
- d_printf("do_list: [%s] %s\n", head, cli_errstr(cli));
+ status = cli_resolve_path(ctx, "", auth_info, cli,
+ head, &targetcli,
+ &targetpath);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("do_list: [%s] %s\n", head,
+ nt_errstr(status));
remove_do_list_queue_head();
continue;
}
- cli_list(targetcli, targetpath, attribute,
+ status = cli_list(targetcli, targetpath, attribute,
do_list_helper, targetcli);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("%s listing %s\n",
+ nt_errstr(status), targetpath);
+ ret_status = status;
+ }
remove_do_list_queue_head();
if ((! do_list_queue_empty()) && (fn == display_finfo)) {
char *next_file = do_list_queue_head();
}
} else {
/* check for dfs */
- if (cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetpath)) {
- NTSTATUS status;
-
+ status = cli_resolve_path(ctx, "", auth_info, cli, mask,
+ &targetcli, &targetpath);
+ if (NT_STATUS_IS_OK(status)) {
status = cli_list(targetcli, targetpath, attribute,
do_list_helper, targetcli);
if (!NT_STATUS_IS_OK(status)) {
d_printf("%s listing %s\n",
nt_errstr(status), targetpath);
+ ret_status = status;
}
TALLOC_FREE(targetpath);
} else {
- d_printf("do_list: [%s] %s\n", mask, cli_errstr(cli));
+ d_printf("do_list: [%s] %s\n", mask, nt_errstr(status));
+ ret_status = status;
}
}
in_do_list = 0;
reset_do_list_queue();
+ return ret_status;
}
/****************************************************************************
static int cmd_dir(void)
{
TALLOC_CTX *ctx = talloc_tos();
- uint16 attribute = aDIR | aSYSTEM | aHIDDEN;
+ uint16 attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
char *mask = NULL;
char *buf = NULL;
int rc = 1;
+ NTSTATUS status;
dir_total = 0;
mask = talloc_strdup(ctx, client_get_cur_dir());
client_set_cwd(client_get_cur_dir());
}
- do_list(mask, attribute, display_finfo, recurse, true);
+ status = do_list(mask, attribute, display_finfo, recurse, true);
+ if (!NT_STATUS_IS_OK(status)) {
+ return 1;
+ }
rc = do_dskattr();
static int cmd_du(void)
{
TALLOC_CTX *ctx = talloc_tos();
- uint16 attribute = aDIR | aSYSTEM | aHIDDEN;
+ uint16 attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
char *mask = NULL;
char *buf = NULL;
+ NTSTATUS status;
int rc = 1;
dir_total = 0;
mask = talloc_strdup(ctx, "*");
}
- do_list(mask, attribute, do_du, recurse, true);
+ status = do_list(mask, attribute, do_du, recurse, true);
+ if (!NT_STATUS_IS_OK(status)) {
+ return 1;
+ }
rc = do_dskattr();
int handle = 0;
uint16_t fnum;
bool newhandle = false;
- struct timeval tp_start;
+ struct timespec tp_start;
uint16 attr;
SMB_OFF_T size;
off_t start = 0;
strlower_m(lname);
}
- if (!cli_resolve_path(ctx, "", auth_info, cli, rname, &targetcli, &targetname ) ) {
- d_printf("Failed to open %s: %s\n", rname, cli_errstr(cli));
+ status = cli_resolve_path(ctx, "", auth_info, cli, rname, &targetcli,
+ &targetname);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("Failed to open %s: %s\n", rname, nt_errstr(status));
return 1;
}
- GetTimeOfDay(&tp_start);
+ clock_gettime_mono(&tp_start);
status = cli_open(targetcli, targetname, O_RDONLY, DENY_NONE, &fnum);
if (!NT_STATUS_IS_OK(status)) {
}
- if (!cli_qfileinfo(targetcli, fnum,
- &attr, &size, NULL, NULL, NULL, NULL, NULL) &&
- !NT_STATUS_IS_OK(cli_getattrE(targetcli, fnum,
- &attr, &size, NULL, NULL, NULL))) {
- d_printf("getattrib: %s\n",cli_errstr(targetcli));
- return 1;
+ status = cli_qfileinfo_basic(targetcli, fnum, &attr, &size, NULL, NULL,
+ NULL, NULL, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ status = cli_getattrE(targetcli, fnum, &attr, &size, NULL, NULL,
+ NULL);
+ if(!NT_STATUS_IS_OK(status)) {
+ d_printf("getattrib: %s\n", nt_errstr(status));
+ return 1;
+ }
}
DEBUG(1,("getting file %s of size %.0f as %s ",
close(handle);
}
- if (archive_level >= 2 && (attr & aARCH)) {
- cli_setatr(cli, rname, attr & ~(uint16)aARCH, 0);
+ if (archive_level >= 2 && (attr & FILE_ATTRIBUTE_ARCHIVE)) {
+ cli_setatr(cli, rname, attr & ~(uint16)FILE_ATTRIBUTE_ARCHIVE, 0);
}
{
- struct timeval tp_end;
+ struct timespec tp_end;
int this_time;
- GetTimeOfDay(&tp_end);
- this_time =
- (tp_end.tv_sec - tp_start.tv_sec)*1000 +
- (tp_end.tv_usec - tp_start.tv_usec)/1000;
+ clock_gettime_mono(&tp_end);
+ this_time = nsec_time_diff(&tp_end,&tp_start)/1000000;
get_total_time_ms += this_time;
get_total_size += nread;
Do an mget operation on one file.
****************************************************************************/
-static void do_mget(struct cli_state *cli_state, struct file_info *finfo,
+static NTSTATUS do_mget(struct cli_state *cli_state, struct file_info *finfo,
const char *dir)
{
TALLOC_CTX *ctx = talloc_tos();
+ NTSTATUS status = NT_STATUS_OK;
char *rname = NULL;
char *quest = NULL;
char *saved_curdir = NULL;
char *new_cd = NULL;
if (!finfo->name) {
- return;
+ return NT_STATUS_OK;
}
if (strequal(finfo->name,".") || strequal(finfo->name,".."))
- return;
+ return NT_STATUS_OK;
if (abort_mget) {
d_printf("mget aborted\n");
- return;
+ return NT_STATUS_UNSUCCESSFUL;
}
- if (finfo->mode & aDIR) {
+ if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
if (asprintf(&quest,
"Get directory %s? ",finfo->name) < 0) {
- return;
+ return NT_STATUS_NO_MEMORY;
}
} else {
if (asprintf(&quest,
"Get file %s? ",finfo->name) < 0) {
- return;
+ return NT_STATUS_NO_MEMORY;
}
}
if (prompt && !yesno(quest)) {
SAFE_FREE(quest);
- return;
+ return NT_STATUS_OK;
}
SAFE_FREE(quest);
- if (!(finfo->mode & aDIR)) {
+ if (!(finfo->mode & FILE_ATTRIBUTE_DIRECTORY)) {
rname = talloc_asprintf(ctx,
"%s%s",
client_get_cur_dir(),
finfo->name);
if (!rname) {
- return;
+ return NT_STATUS_NO_MEMORY;
}
do_get(rname, finfo->name, false);
TALLOC_FREE(rname);
- return;
+ return NT_STATUS_OK;
}
/* handle directories */
saved_curdir = talloc_strdup(ctx, client_get_cur_dir());
if (!saved_curdir) {
- return;
+ return NT_STATUS_NO_MEMORY;
}
new_cd = talloc_asprintf(ctx,
finfo->name,
CLI_DIRSEP_STR);
if (!new_cd) {
- return;
+ return NT_STATUS_NO_MEMORY;
}
client_set_cur_dir(new_cd);
mkdir(finfo->name,0777) != 0) {
d_printf("failed to create directory %s\n",finfo->name);
client_set_cur_dir(saved_curdir);
- return;
+ return map_nt_error_from_unix(errno);
}
if (chdir(finfo->name) != 0) {
d_printf("failed to chdir to directory %s\n",finfo->name);
client_set_cur_dir(saved_curdir);
- return;
+ return map_nt_error_from_unix(errno);
}
mget_mask = talloc_asprintf(ctx,
client_get_cur_dir());
if (!mget_mask) {
- return;
+ 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)) {
+ return status;
}
- do_list(mget_mask, aSYSTEM | aHIDDEN | aDIR,do_mget,false, true);
if (chdir("..") == -1) {
d_printf("do_mget: failed to chdir to .. (error %s)\n",
strerror(errno) );
+ return map_nt_error_from_unix(errno);
}
client_set_cur_dir(saved_curdir);
TALLOC_FREE(mget_mask);
TALLOC_FREE(saved_curdir);
TALLOC_FREE(new_cd);
+ return NT_STATUS_OK;
}
/****************************************************************************
static int cmd_mget(void)
{
TALLOC_CTX *ctx = talloc_tos();
- uint16 attribute = aSYSTEM | aHIDDEN;
+ uint16 attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
char *mget_mask = NULL;
char *buf = NULL;
+ NTSTATUS status = NT_STATUS_OK;
if (recurse) {
- attribute |= aDIR;
+ attribute |= FILE_ATTRIBUTE_DIRECTORY;
}
abort_mget = false;
while (next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
+
mget_mask = talloc_strdup(ctx, client_get_cur_dir());
if (!mget_mask) {
return 1;
if (!mget_mask) {
return 1;
}
- do_list(mget_mask, attribute, do_mget, false, true);
+ status = do_list(mget_mask, attribute, do_mget, false, true);
+ if (!NT_STATUS_IS_OK(status)) {
+ return 1;
+ }
}
if (mget_mask == NULL) {
if (!mget_mask) {
return 1;
}
- do_list(mget_mask, attribute, do_mget, false, true);
+ status = do_list(mget_mask, attribute, do_mget, false, true);
+ if (!NT_STATUS_IS_OK(status)) {
+ return 1;
+ }
}
return 0;
char *targetname = NULL;
NTSTATUS status;
- if (!cli_resolve_path(ctx, "", auth_info, cli, name, &targetcli, &targetname)) {
- d_printf("mkdir %s: %s\n", name, cli_errstr(cli));
+ status = cli_resolve_path(ctx, "", auth_info, cli, name, &targetcli,
+ &targetname);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("mkdir %s: %s\n", name, nt_errstr(status));
return false;
}
TALLOC_CTX *ctx = talloc_tos();
char *mask = NULL;
char *buf = NULL;
+ NTSTATUS status;
mask = talloc_strdup(ctx, client_get_cur_dir());
if (!mask) {
return 1;
}
- if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) {
+ status = cli_resolve_path(ctx, "", auth_info, cli, mask,
+ &targetcli, &targetname);
+ if (!NT_STATUS_IS_OK(status)) {
return 1;
}
static char *attr_str(TALLOC_CTX *mem_ctx, uint16_t mode)
{
- char *attrs = TALLOC_ZERO_ARRAY(mem_ctx, char, 17);
+ char *attrs = talloc_zero_array(mem_ctx, char, 17);
int i = 0;
if (!(mode & FILE_ATTRIBUTE_NORMAL)) {
+ if (mode & FILE_ATTRIBUTE_ENCRYPTED) {
+ attrs[i++] = 'E';
+ }
+ if (mode & FILE_ATTRIBUTE_NONINDEXED) {
+ attrs[i++] = 'N';
+ }
+ if (mode & FILE_ATTRIBUTE_OFFLINE) {
+ attrs[i++] = 'O';
+ }
+ if (mode & FILE_ATTRIBUTE_COMPRESSED) {
+ attrs[i++] = 'C';
+ }
+ if (mode & FILE_ATTRIBUTE_REPARSE_POINT) {
+ attrs[i++] = 'r';
+ }
+ if (mode & FILE_ATTRIBUTE_SPARSE) {
+ attrs[i++] = 's';
+ }
+ if (mode & FILE_ATTRIBUTE_TEMPORARY) {
+ attrs[i++] = 'T';
+ }
+ if (mode & FILE_ATTRIBUTE_NORMAL) {
+ attrs[i++] = 'N';
+ }
if (mode & FILE_ATTRIBUTE_READONLY) {
attrs[i++] = 'R';
}
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;
unsigned int i;
NTSTATUS status;
unix_timespec_to_nt_time(&tmp, c_time);
d_printf("change_time: %s\n", nt_time_string(talloc_tos(), tmp));
- d_printf("attributes: %s\n", attr_str(talloc_tos(), mode));
+ d_printf("attributes: %s (%x)\n", attr_str(talloc_tos(), mode), mode);
status = cli_qpathinfo_streams(cli, name, talloc_tos(), &num_streams,
&streams);
(unsigned long long)streams[i].size);
}
+ if (mode & FILE_ATTRIBUTE_REPARSE_POINT) {
+ char *subst, *print;
+ uint32_t flags;
+
+ status = cli_readlink(cli, name, talloc_tos(), &subst, &print,
+ &flags);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_fprintf(stderr, "cli_readlink returned %s\n",
+ nt_errstr(status));
+ } else {
+ d_printf("symlink: subst=[%s], print=[%s], flags=%x\n",
+ subst, print, flags);
+ TALLOC_FREE(subst);
+ TALLOC_FREE(print);
+ }
+ }
+
+ status = cli_ntcreate(cli, name, 0,
+ CREATE_ACCESS_READ, 0,
+ FILE_SHARE_READ|FILE_SHARE_WRITE
+ |FILE_SHARE_DELETE,
+ FILE_OPEN, 0x0, 0x0, &fnum);
+ if (!NT_STATUS_IS_OK(status)) {
+ /*
+ * Ignore failure, it does not hurt if we can't list
+ * snapshots
+ */
+ return 0;
+ }
+ status = cli_shadow_copy_data(talloc_tos(), cli, fnum,
+ true, &snapshots, &num_snapshots);
+ if (!NT_STATUS_IS_OK(status)) {
+ cli_close(cli, fnum);
+ return 0;
+ }
+
+ for (i=0; i<num_snapshots; i++) {
+ char *snap_name;
+
+ 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,
+ &m_time, &c_time, &size,
+ NULL, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_fprintf(stderr, "pathinfo(%s) failed: %s\n",
+ snap_name, nt_errstr(status));
+ TALLOC_FREE(snap_name);
+ continue;
+ }
+ unix_timespec_to_nt_time(&tmp, b_time);
+ d_printf("create_time: %s\n", nt_time_string(talloc_tos(), tmp));
+ unix_timespec_to_nt_time(&tmp, a_time);
+ d_printf("access_time: %s\n", nt_time_string(talloc_tos(), tmp));
+ unix_timespec_to_nt_time(&tmp, m_time);
+ d_printf("write_time: %s\n", nt_time_string(talloc_tos(), tmp));
+ unix_timespec_to_nt_time(&tmp, c_time);
+ d_printf("change_time: %s\n", nt_time_string(talloc_tos(), tmp));
+ d_printf("size: %d\n", (int)size);
+ }
+
+ TALLOC_FREE(snapshots);
+
return 0;
}
XFILE *f;
SMB_OFF_T start = 0;
int rc = 0;
- struct timeval tp_start;
+ struct timespec tp_start;
struct cli_state *targetcli;
char *targetname = NULL;
struct push_state state;
NTSTATUS status;
- if (!cli_resolve_path(ctx, "", auth_info, cli, rname, &targetcli, &targetname)) {
- d_printf("Failed to open %s: %s\n", rname, cli_errstr(cli));
+ status = cli_resolve_path(ctx, "", auth_info, cli, rname,
+ &targetcli, &targetname);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("Failed to open %s: %s\n", rname, nt_errstr(status));
return 1;
}
- GetTimeOfDay(&tp_start);
+ clock_gettime_mono(&tp_start);
if (reput) {
status = cli_open(targetcli, targetname, O_RDWR|O_CREAT, DENY_NONE, &fnum);
if (NT_STATUS_IS_OK(status)) {
- if (!cli_qfileinfo(targetcli, fnum, NULL, &start, NULL, NULL, NULL, NULL, NULL) &&
- !NT_STATUS_IS_OK(cli_getattrE(targetcli, fnum, NULL, &start, NULL, NULL, NULL))) {
- d_printf("getattrib: %s\n",cli_errstr(cli));
+ if (!NT_STATUS_IS_OK(status = cli_qfileinfo_basic(
+ targetcli, fnum, NULL,
+ &start, NULL, NULL,
+ NULL, NULL, NULL)) &&
+ !NT_STATUS_IS_OK(status = cli_getattrE(
+ targetcli, fnum, NULL,
+ &start, NULL, NULL,
+ NULL))) {
+ d_printf("getattrib: %s\n", nt_errstr(status));
return 1;
}
}
}
if (!NT_STATUS_IS_OK(status)) {
- d_printf("%s opening remote file %s\n",cli_errstr(targetcli),rname);
+ d_printf("%s opening remote file %s\n", nt_errstr(status),
+ rname);
return 1;
}
}
{
- struct timeval tp_end;
+ struct timespec tp_end;
int this_time;
- GetTimeOfDay(&tp_end);
- this_time =
- (tp_end.tv_sec - tp_start.tv_sec)*1000 +
- (tp_end.tv_usec - tp_start.tv_usec)/1000;
+ clock_gettime_mono(&tp_end);
+ this_time = nsec_time_diff(&tp_end,&tp_start)/1000000;
put_total_time_ms += this_time;
put_total_size += state.nread;
if (f == x_stdin) {
cli_shutdown(cli);
- exit(0);
+ exit(rc);
}
return rc;
d_printf("Job %d cancelled\n",job);
return 0;
} else {
- d_printf("Error cancelling job %d : %s\n",job,cli_errstr(cli));
+ NTSTATUS status = cli_nt_error(cli);
+ d_printf("Error cancelling job %d : %s\n",
+ job, nt_errstr(status));
return 1;
}
}
Delete some files.
****************************************************************************/
-static void do_del(struct cli_state *cli_state, struct file_info *finfo,
+static NTSTATUS do_del(struct cli_state *cli_state, struct file_info *finfo,
const char *dir)
{
TALLOC_CTX *ctx = talloc_tos();
CLI_DIRSEP_CHAR,
finfo->name);
if (!mask) {
- return;
+ return NT_STATUS_NO_MEMORY;
}
- if (finfo->mode & aDIR) {
+ if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
TALLOC_FREE(mask);
- return;
+ return NT_STATUS_OK;
}
- status = cli_unlink(cli_state, mask, aSYSTEM | aHIDDEN);
+ status = cli_unlink(cli_state, mask, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!NT_STATUS_IS_OK(status)) {
d_printf("%s deleting remote file %s\n",
nt_errstr(status), mask);
}
TALLOC_FREE(mask);
+ return status;
}
/****************************************************************************
TALLOC_CTX *ctx = talloc_tos();
char *mask = NULL;
char *buf = NULL;
- uint16 attribute = aSYSTEM | aHIDDEN;
+ NTSTATUS status = NT_STATUS_OK;
+ uint16 attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
if (recurse) {
- attribute |= aDIR;
+ attribute |= FILE_ATTRIBUTE_DIRECTORY;
}
mask = talloc_strdup(ctx, client_get_cur_dir());
return 1;
}
- do_list(mask,attribute,do_del,false,false);
+ status = do_list(mask,attribute,do_del,false,false);
+ if (!NT_STATUS_IS_OK(status)) {
+ return 1;
+ }
return 0;
}
return 1;
}
- if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) {
- d_printf("cmd_wdel %s: %s\n", mask, cli_errstr(cli));
+ status = cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli,
+ &targetname);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("cmd_wdel %s: %s\n", mask, nt_errstr(status));
return 1;
}
char *targetname = NULL;
struct cli_state *targetcli;
uint16_t fnum = (uint16_t)-1;
+ NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
d_printf("open <filename>\n");
return 1;
}
- if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) {
- d_printf("open %s: %s\n", mask, cli_errstr(cli));
+ status = cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli,
+ &targetname);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("open %s: %s\n", mask, nt_errstr(status));
return 1;
}
- if (!NT_STATUS_IS_OK(cli_ntcreate(targetcli, targetname, 0,
+ status = cli_ntcreate(targetcli, targetname, 0,
FILE_READ_DATA|FILE_WRITE_DATA, 0,
- FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum))) {
- if (NT_STATUS_IS_OK(cli_ntcreate(targetcli, targetname, 0,
+ FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN,
+ 0x0, 0x0, &fnum);
+ 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))) {
+ FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN,
+ 0x0, 0x0, &fnum);
+ if (NT_STATUS_IS_OK(status)) {
d_printf("open file %s: for read/write fnum %d\n", targetname, fnum);
} else {
- d_printf("Failed to open file %s. %s\n", targetname, cli_errstr(cli));
+ d_printf("Failed to open file %s. %s\n",
+ targetname, nt_errstr(status));
}
} else {
d_printf("open file %s: for read/write fnum %d\n", targetname, fnum);
struct cli_state *targetcli;
mode_t mode;
uint16_t fnum;
+ NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
d_printf("posix_open <filename> 0<mode>\n");
}
mode = (mode_t)strtol(buf, (char **)NULL, 8);
- if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) {
- d_printf("posix_open %s: %s\n", mask, cli_errstr(cli));
+ status = cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli,
+ &targetname);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("posix_open %s: %s\n", mask, nt_errstr(status));
return 1;
}
- if (!NT_STATUS_IS_OK(cli_posix_open(targetcli, targetname, O_CREAT|O_RDWR, mode, &fnum))) {
- if (!NT_STATUS_IS_OK(cli_posix_open(targetcli, targetname, O_CREAT|O_RDONLY, mode, &fnum))) {
- d_printf("posix_open file %s: for read/write fnum %d\n", targetname, fnum);
+ status = cli_posix_open(targetcli, targetname, O_CREAT|O_RDWR, mode,
+ &fnum);
+ if (!NT_STATUS_IS_OK(status)) {
+ status = cli_posix_open(targetcli, targetname,
+ O_CREAT|O_RDONLY, mode, &fnum);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("Failed to open file %s. %s\n", targetname,
+ nt_errstr(status));
} else {
- d_printf("Failed to open file %s. %s\n", targetname, cli_errstr(cli));
+ d_printf("posix_open file %s: for readonly fnum %d\n",
+ targetname, fnum);
}
} else {
- d_printf("posix_open file %s: for read/write fnum %d\n", targetname, fnum);
+ d_printf("posix_open file %s: for read/write fnum %d\n",
+ targetname, fnum);
}
return 0;
char *targetname = NULL;
struct cli_state *targetcli;
mode_t mode;
+ NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
d_printf("posix_mkdir <filename> 0<mode>\n");
}
mode = (mode_t)strtol(buf, (char **)NULL, 8);
- if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) {
- d_printf("posix_mkdir %s: %s\n", mask, cli_errstr(cli));
+ status = cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli,
+ &targetname);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("posix_mkdir %s: %s\n", mask, nt_errstr(status));
return 1;
}
- if (!NT_STATUS_IS_OK(cli_posix_mkdir(targetcli, targetname, mode))) {
- d_printf("Failed to open file %s. %s\n", targetname, cli_errstr(cli));
+ status = cli_posix_mkdir(targetcli, targetname, mode);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("Failed to open file %s. %s\n",
+ targetname, nt_errstr(status));
} else {
d_printf("posix_mkdir created directory %s\n", targetname);
}
char *buf = NULL;
char *targetname = NULL;
struct cli_state *targetcli;
+ NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
d_printf("posix_unlink <filename>\n");
return 1;
}
- if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) {
- d_printf("posix_unlink %s: %s\n", mask, cli_errstr(cli));
+ status = cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli,
+ &targetname);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("posix_unlink %s: %s\n", mask, nt_errstr(status));
return 1;
}
- if (!NT_STATUS_IS_OK(cli_posix_unlink(targetcli, targetname))) {
- d_printf("Failed to unlink file %s. %s\n", targetname, cli_errstr(cli));
+ status = cli_posix_unlink(targetcli, targetname);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("Failed to unlink file %s. %s\n",
+ targetname, nt_errstr(status));
} else {
d_printf("posix_unlink deleted file %s\n", targetname);
}
char *buf = NULL;
char *targetname = NULL;
struct cli_state *targetcli;
+ NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
d_printf("posix_rmdir <filename>\n");
return 1;
}
- if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) {
- d_printf("posix_rmdir %s: %s\n", mask, cli_errstr(cli));
+ status = cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli,
+ &targetname);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("posix_rmdir %s: %s\n", mask, nt_errstr(status));
return 1;
}
- if (!NT_STATUS_IS_OK(cli_posix_rmdir(targetcli, targetname))) {
- d_printf("Failed to unlink directory %s. %s\n", targetname, cli_errstr(cli));
+ status = cli_posix_rmdir(targetcli, targetname);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("Failed to unlink directory %s. %s\n",
+ targetname, nt_errstr(status));
} else {
d_printf("posix_rmdir deleted directory %s\n", targetname);
}
TALLOC_CTX *ctx = talloc_tos();
char *buf = NULL;
int fnum;
+ NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
d_printf("close <fnum>\n");
fnum = atoi(buf);
/* We really should use the targetcli here.... */
- if (!NT_STATUS_IS_OK(cli_close(cli, fnum))) {
- d_printf("close %d: %s\n", fnum, cli_errstr(cli));
+ status = cli_close(cli, fnum);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("close %d: %s\n", fnum, nt_errstr(status));
return 1;
}
return 0;
uint64_t start, len;
enum brl_type lock_type;
int fnum;
+ NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
d_printf("lock <fnum> [r|w] <hex-start> <hex-len>\n");
len = (uint64_t)strtol(buf, (char **)NULL, 16);
- if (!NT_STATUS_IS_OK(cli_posix_lock(cli, fnum, start, len, true, lock_type))) {
- d_printf("lock failed %d: %s\n", fnum, cli_errstr(cli));
+ status = cli_posix_lock(cli, fnum, start, len, true, lock_type);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("lock failed %d: %s\n", fnum, nt_errstr(status));
}
return 0;
char *buf = NULL;
uint64_t start, len;
int fnum;
+ NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
d_printf("unlock <fnum> <hex-start> <hex-len>\n");
len = (uint64_t)strtol(buf, (char **)NULL, 16);
- if (!NT_STATUS_IS_OK(cli_posix_unlock(cli, fnum, start, len))) {
- d_printf("unlock failed %d: %s\n", fnum, cli_errstr(cli));
+ status = cli_posix_unlock(cli, fnum, start, len);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("unlock failed %d: %s\n", fnum, nt_errstr(status));
}
return 0;
char *buf = NULL;
char *targetname = NULL;
struct cli_state *targetcli;
+ NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
d_printf("rmdir <dirname>\n");
return 1;
}
- if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) {
- d_printf("rmdir %s: %s\n", mask, cli_errstr(cli));
+ status = cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli,
+ &targetname);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("rmdir %s: %s\n", mask, nt_errstr(status));
return 1;
}
- if (!NT_STATUS_IS_OK(cli_rmdir(targetcli, targetname))) {
+ status = cli_rmdir(targetcli, targetname);
+ if (!NT_STATUS_IS_OK(status)) {
d_printf("%s removing remote directory file %s\n",
- cli_errstr(targetcli),mask);
+ nt_errstr(status), mask);
}
return 0;
char *buf2 = NULL;
char *targetname = NULL;
struct cli_state *targetcli;
+ NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) ||
!next_token_talloc(ctx, &cmd_ptr,&buf2,NULL)) {
return 1;
}
- if (!cli_resolve_path(ctx, "", auth_info, cli, oldname, &targetcli, &targetname)) {
- d_printf("link %s: %s\n", oldname, cli_errstr(cli));
+ status = cli_resolve_path(ctx, "", auth_info, cli, oldname, &targetcli,
+ &targetname);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("link %s: %s\n", oldname, nt_errstr(status));
return 1;
}
return 1;
}
- if (!NT_STATUS_IS_OK(cli_posix_hardlink(targetcli, targetname, newname))) {
- d_printf("%s linking files (%s -> %s)\n", cli_errstr(targetcli), newname, oldname);
+ status = cli_posix_hardlink(targetcli, targetname, newname);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("%s linking files (%s -> %s)\n",
+ nt_errstr(status), newname, oldname);
return 1;
}
return 0;
char *targetname = NULL;
char linkname[PATH_MAX+1];
struct cli_state *targetcli;
+ NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
d_printf("readlink <name>\n");
return 1;
}
- if (!cli_resolve_path(ctx, "", auth_info, cli, name, &targetcli, &targetname)) {
- d_printf("readlink %s: %s\n", name, cli_errstr(cli));
+ status = cli_resolve_path(ctx, "", auth_info, cli, name, &targetcli,
+ &targetname);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("readlink %s: %s\n", name, nt_errstr(status));
return 1;
}
return 1;
}
- if (!NT_STATUS_IS_OK(cli_posix_readlink(targetcli, name,
- linkname, PATH_MAX+1))) {
+ status = cli_posix_readlink(targetcli, name, linkname, PATH_MAX+1);
+ if (!NT_STATUS_IS_OK(status)) {
d_printf("%s readlink on file %s\n",
- cli_errstr(targetcli), name);
+ nt_errstr(status), name);
return 1;
}
char *newname = NULL;
char *buf = NULL;
char *buf2 = NULL;
- char *targetname = NULL;
- struct cli_state *targetcli;
+ struct cli_state *newcli;
+ NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) ||
!next_token_talloc(ctx, &cmd_ptr,&buf2,NULL)) {
d_printf("symlink <oldname> <newname>\n");
return 1;
}
- oldname = talloc_asprintf(ctx,
- "%s%s",
- client_get_cur_dir(),
- buf);
- if (!oldname) {
- return 1;
- }
- newname = talloc_asprintf(ctx,
- "%s%s",
- client_get_cur_dir(),
- buf2);
- if (!newname) {
- return 1;
- }
-
- if (!cli_resolve_path(ctx, "", auth_info, cli, oldname, &targetcli, &targetname)) {
- d_printf("link %s: %s\n", oldname, cli_errstr(cli));
- return 1;
- }
+ /* Oldname (link target) must be an untouched blob. */
+ oldname = buf;
- if (!SERVER_HAS_UNIX_CIFS(targetcli)) {
- d_printf("Server doesn't support UNIX CIFS calls.\n");
- return 1;
+ if (SERVER_HAS_UNIX_CIFS(cli)) {
+ newname = talloc_asprintf(ctx, "%s%s", client_get_cur_dir(),
+ buf2);
+ if (!newname) {
+ return 1;
+ }
+ /* New name must be present in share namespace. */
+ status = cli_resolve_path(ctx, "", auth_info, cli, newname,
+ &newcli, &newname);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("link %s: %s\n", oldname, nt_errstr(status));
+ return 1;
+ }
+ status = cli_posix_symlink(newcli, oldname, newname);
+ } else {
+ status = cli_symlink(
+ cli, oldname, buf2,
+ buf2[0] == '\\' ? 0 : SYMLINK_FLAG_RELATIVE);
}
- if (!NT_STATUS_IS_OK(cli_posix_symlink(targetcli, targetname, newname))) {
+ if (!NT_STATUS_IS_OK(status)) {
d_printf("%s symlinking files (%s -> %s)\n",
- cli_errstr(targetcli), newname, targetname);
+ nt_errstr(status), oldname, newname);
return 1;
}
char *targetname = NULL;
struct cli_state *targetcli;
mode_t mode;
+ NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) ||
!next_token_talloc(ctx, &cmd_ptr,&buf2,NULL)) {
mode = (mode_t)strtol(buf, NULL, 8);
- if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetname)) {
- d_printf("chmod %s: %s\n", src, cli_errstr(cli));
+ status = cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli,
+ &targetname);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("chmod %s: %s\n", src, nt_errstr(status));
return 1;
}
return 1;
}
- if (!NT_STATUS_IS_OK(cli_posix_chmod(targetcli, targetname, mode))) {
+ status = cli_posix_chmod(targetcli, targetname, mode);
+ if (!NT_STATUS_IS_OK(status)) {
d_printf("%s chmod file %s 0%o\n",
- cli_errstr(targetcli), src, (unsigned int)mode);
+ nt_errstr(status), src, (unsigned int)mode);
return 1;
}
return 1;
}
- if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetname)) {
- d_printf("stat %s: %s\n", src, cli_errstr(cli));
+ status = cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli,
+ &targetname);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("stat %s: %s\n", src, nt_errstr(status));
return 1;
}
return 1;
}
+ status = cli_posix_stat(targetcli, targetname, &sbuf);
if (!NT_STATUS_IS_OK(cli_posix_stat(targetcli, targetname, &sbuf))) {
d_printf("%s getfacl doing a stat on file %s\n",
- cli_errstr(targetcli), src);
+ nt_errstr(status), src);
return 1;
}
- if (!NT_STATUS_IS_OK(cli_posix_getfacl(targetcli, targetname, ctx, &rb_size, &retbuf))) {
+ status = cli_posix_getfacl(targetcli, targetname, ctx, &rb_size, &retbuf);
+ if (!NT_STATUS_IS_OK(status)) {
d_printf("%s getfacl file %s\n",
- cli_errstr(targetcli), src);
+ nt_errstr(status), src);
return 1;
}
return 0;
}
+static void printf_cb(const char *buf, void *private_data)
+{
+ printf("%s", buf);
+}
+
+/****************************************************************************
+ Get the EA list of a file
+****************************************************************************/
+
+static int cmd_geteas(void)
+{
+ TALLOC_CTX *ctx = talloc_tos();
+ char *src = NULL;
+ char *name = NULL;
+ char *targetname = NULL;
+ struct cli_state *targetcli;
+ NTSTATUS status;
+ size_t i, num_eas;
+ struct ea_struct *eas;
+
+ if (!next_token_talloc(ctx, &cmd_ptr,&name,NULL)) {
+ d_printf("geteas filename\n");
+ return 1;
+ }
+ src = talloc_asprintf(ctx,
+ "%s%s",
+ client_get_cur_dir(),
+ name);
+ if (!src) {
+ return 1;
+ }
+
+ status = cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli,
+ &targetname);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("stat %s: %s\n", src, nt_errstr(status));
+ return 1;
+ }
+
+ status = cli_get_ea_list_path(targetcli, targetname, talloc_tos(),
+ &num_eas, &eas);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("cli_get_ea_list_path: %s\n", nt_errstr(status));
+ return 1;
+ }
+
+ 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);
+ d_printf("\n");
+ }
+
+ TALLOC_FREE(eas);
+
+ return 0;
+}
+
+/****************************************************************************
+ Set an EA of a file
+****************************************************************************/
+
+static int cmd_setea(void)
+{
+ TALLOC_CTX *ctx = talloc_tos();
+ char *src = NULL;
+ char *name = NULL;
+ char *eaname = NULL;
+ char *eavalue = NULL;
+ char *targetname = NULL;
+ struct cli_state *targetcli;
+ NTSTATUS status;
+
+ if (!next_token_talloc(ctx, &cmd_ptr, &name, NULL)
+ || !next_token_talloc(ctx, &cmd_ptr, &eaname, NULL)) {
+ d_printf("setea filename eaname value\n");
+ return 1;
+ }
+ if (!next_token_talloc(ctx, &cmd_ptr, &eavalue, NULL)) {
+ eavalue = talloc_strdup(ctx, "");
+ }
+ src = talloc_asprintf(ctx,
+ "%s%s",
+ client_get_cur_dir(),
+ name);
+ if (!src) {
+ return 1;
+ }
+
+ status = cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli,
+ &targetname);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("stat %s: %s\n", src, nt_errstr(status));
+ return 1;
+ }
+
+ status = cli_set_ea_path(targetcli, targetname, eaname, eavalue,
+ strlen(eavalue));
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("set_ea %s: %s\n", src, nt_errstr(status));
+ return 1;
+ }
+
+ return 0;
+}
+
/****************************************************************************
UNIX stat.
****************************************************************************/
SMB_STRUCT_STAT sbuf;
struct tm *lt;
time_t tmp_time;
+ NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&name,NULL)) {
d_printf("stat file\n");
return 1;
}
- if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetname)) {
- d_printf("stat %s: %s\n", src, cli_errstr(cli));
+ status = cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli,
+ &targetname);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("stat %s: %s\n", src, nt_errstr(status));
return 1;
}
return 1;
}
- if (!NT_STATUS_IS_OK(cli_posix_stat(targetcli, targetname, &sbuf))) {
+ status = cli_posix_stat(targetcli, targetname, &sbuf);
+ if (!NT_STATUS_IS_OK(status)) {
d_printf("%s stat file %s\n",
- cli_errstr(targetcli), src);
+ nt_errstr(status), src);
return 1;
}
char *buf, *buf2, *buf3;
struct cli_state *targetcli;
char *targetname = NULL;
+ NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) ||
!next_token_talloc(ctx, &cmd_ptr,&buf2,NULL) ||
if (!src) {
return 1;
}
- if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetname) ) {
- d_printf("chown %s: %s\n", src, cli_errstr(cli));
+ status = cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli,
+ &targetname);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("chown %s: %s\n", src, nt_errstr(status));
return 1;
}
return 1;
}
- if (!NT_STATUS_IS_OK(cli_posix_chown(targetcli, targetname, uid, gid))) {
+ status = cli_posix_chown(targetcli, targetname, uid, gid);
+ if (!NT_STATUS_IS_OK(status)) {
d_printf("%s chown file %s uid=%d, gid=%d\n",
- cli_errstr(targetcli), src, (int)uid, (int)gid);
+ nt_errstr(status), src, (int)uid, (int)gid);
return 1;
}
struct cli_state *targetcli;
char *targetsrc;
char *targetdest;
+ NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) ||
!next_token_talloc(ctx, &cmd_ptr,&buf2,NULL)) {
return 1;
}
- if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetsrc)) {
- d_printf("rename %s: %s\n", src, cli_errstr(cli));
+ status = cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli,
+ &targetsrc);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("rename %s: %s\n", src, nt_errstr(status));
return 1;
}
- if (!cli_resolve_path(ctx, "", auth_info, cli, dest, &targetcli, &targetdest)) {
- d_printf("rename %s: %s\n", dest, cli_errstr(cli));
+ status = cli_resolve_path(ctx, "", auth_info, cli, dest, &targetcli,
+ &targetdest);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("rename %s: %s\n", dest, nt_errstr(status));
return 1;
}
- if (!NT_STATUS_IS_OK(cli_rename(targetcli, targetsrc, targetdest))) {
+ status = cli_rename(targetcli, targetsrc, targetdest);
+ if (!NT_STATUS_IS_OK(status)) {
d_printf("%s renaming files %s -> %s \n",
- cli_errstr(targetcli),
+ nt_errstr(status),
targetsrc,
targetdest);
return 1;
static int cmd_volume(void)
{
- fstring volname;
- uint32 serial_num;
+ char *volname;
+ uint32_t serial_num;
time_t create_date;
NTSTATUS status;
- status = cli_get_fs_volume_info(cli, volname, &serial_num,
+ status = cli_get_fs_volume_info(cli, talloc_tos(),
+ &volname, &serial_num,
&create_date);
if (!NT_STATUS_IS_OK(status)) {
d_printf("Error %s getting volume info\n", nt_errstr(status));
char *buf, *buf2;
struct cli_state *targetcli;
char *targetname;
+ NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) ||
!next_token_talloc(ctx, &cmd_ptr,&buf2,NULL)) {
return 1;
}
- if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetname)) {
- d_printf("hardlink %s: %s\n", src, cli_errstr(cli));
+ status = cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli,
+ &targetname);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("hardlink %s: %s\n", src, nt_errstr(status));
return 1;
}
- if (!NT_STATUS_IS_OK(cli_nt_hardlink(targetcli, targetname, dest))) {
- d_printf("%s doing an NT hard link of files\n",cli_errstr(targetcli));
+ status = cli_nt_hardlink(targetcli, targetname, dest);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("%s doing an NT hard link of files\n",
+ nt_errstr(status));
return 1;
}
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.
****************************************************************************/
buf, strerror(errno));
}
}
- d = TALLOC_ARRAY(ctx, char, PATH_MAX+1);
+ d = sys_getwd();
if (!d) {
return 1;
}
- DEBUG(2,("the local directory is now %s\n",sys_getwd(d)));
+ DEBUG(2,("the local directory is now %s\n",d));
+ SAFE_FREE(d);
return 0;
}
uint32_t resume_handle = 0;
uint32_t total_entries = 0;
int i;
+ struct dcerpc_binding_handle *b;
status = cli_rpc_pipe_open_noauth(cli, &ndr_table_srvsvc.syntax_id,
&pipe_hnd);
return false;
}
+ b = pipe_hnd->binding_handle;
+
ZERO_STRUCT(info_ctr);
ZERO_STRUCT(ctr1);
info_ctr.level = 1;
info_ctr.ctr.ctr1 = &ctr1;
- status = rpccli_srvsvc_NetShareEnumAll(pipe_hnd, frame,
+ status = dcerpc_srvsvc_NetShareEnumAll(b, frame,
pipe_hnd->desthost,
&info_ctr,
0xffffffff,
return true;
}
- if((ret = cli_RNetShareEnum(cli, browse_fn, NULL)) == -1)
- d_printf("Error returning browse list: %s\n", cli_errstr(cli));
+ if((ret = cli_RNetShareEnum(cli, browse_fn, NULL)) == -1) {
+ NTSTATUS status = cli_nt_error(cli);
+ d_printf("Error returning browse list: %s\n",
+ nt_errstr(status));
+ }
return (ret != -1);
}
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;
+ NTSTATUS nt_status;
if (!next_token_talloc(ctx, &cmd_ptr,&l_username,NULL)) {
d_printf("logon <username> [<password>]\n");
return 1;
}
- if (!NT_STATUS_IS_OK(cli_session_setup(cli, l_username,
- l_password, strlen(l_password),
- l_password, strlen(l_password),
- lp_workgroup()))) {
- d_printf("session setup failed: %s\n", cli_errstr(cli));
+ nt_status = cli_session_setup(cli, l_username,
+ l_password, strlen(l_password),
+ l_password, strlen(l_password),
+ lp_workgroup());
+ 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_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;
}
- d_printf("Current VUID is %d\n", cli->vuid);
+ 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;
}
TALLOC_CTX *ctx = talloc_tos();
struct cli_state *targetcli;
char *targetpath;
+ NTSTATUS status;
- if (!cli_resolve_path(ctx, "", auth_info, cli, client_get_cur_dir(),
- &targetcli, &targetpath ) ) {
- d_printf("showconnect %s: %s\n", cur_dir, cli_errstr(cli));
+ status = cli_resolve_path(ctx, "", auth_info, cli,
+ client_get_cur_dir(), &targetcli,
+ &targetpath);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("showconnect %s: %s\n", cur_dir, nt_errstr(status));
return 1;
}
- d_printf("//%s/%s\n", targetcli->desthost, targetcli->share);
+ d_printf("//%s/%s\n", cli_state_remote_name(targetcli), targetcli->share);
return 0;
}
return 0;
}
+/****************************************************************************
+history
+****************************************************************************/
+static int cmd_history(void)
+{
+#if defined(HAVE_LIBREADLINE) && defined(HAVE_HISTORY_LIST)
+ HIST_ENTRY **hlist;
+ int i;
+
+ hlist = history_list();
+
+ for (i = 0; hlist && hlist[i]; i++) {
+ DEBUG(0, ("%d: %s\n", i, hlist[i]->line));
+ }
+#else
+ DEBUG(0,("no history without readline support\n"));
+#endif
+
+ return 0;
+}
/* Some constants for completing filename arguments */
{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}},
{"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}},
+ {"geteas", cmd_geteas, "<file name> get the EA list of a file",
+ {COMPL_REMOTE, COMPL_LOCAL}},
{"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}},
{"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}},
+ {"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}},
{"symlink",cmd_symlink,"<oldname> <newname> create a UNIX symlink",{COMPL_REMOTE,COMPL_REMOTE}},
{"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. */
/* establish the connection if not already */
if (!cli) {
- cli = cli_cm_open(talloc_tos(), NULL,
- have_ip ? dest_ss_str : desthost,
- service, auth_info,
- true, smb_encrypt,
- max_protocol, port, name_type);
- if (!cli) {
+ NTSTATUS status;
+
+ status = cli_cm_open(talloc_tos(), NULL,
+ have_ip ? dest_ss_str : desthost,
+ service, auth_info,
+ true, smb_encrypt,
+ max_protocol, port, name_type,
+ &cli);
+ if (!NT_STATUS_IS_OK(status)) {
return 1;
}
}
int len;
};
-static void completion_remote_filter(const char *mnt,
+static NTSTATUS completion_remote_filter(const char *mnt,
struct file_info *f,
const char *mask,
void *state)
struct completion_remote *info = (struct completion_remote *)state;
if (info->count >= MAX_COMPLETIONS - 1) {
- return;
+ return NT_STATUS_OK;
}
if (strncmp(info->text, f->name, info->len) != 0) {
- return;
+ return NT_STATUS_OK;
}
if (ISDOT(f->name) || ISDOTDOT(f->name)) {
- return;
+ return NT_STATUS_OK;
}
- if ((info->dirmask[0] == 0) && !(f->mode & aDIR))
+ if ((info->dirmask[0] == 0) && !(f->mode & FILE_ATTRIBUTE_DIRECTORY))
info->matches[info->count] = SMB_STRDUP(f->name);
else {
TALLOC_CTX *ctx = talloc_stackframe();
tmp = talloc_strdup(ctx,info->dirmask);
if (!tmp) {
TALLOC_FREE(ctx);
- return;
+ return NT_STATUS_NO_MEMORY;
}
tmp = talloc_asprintf_append(tmp, "%s", f->name);
if (!tmp) {
TALLOC_FREE(ctx);
- return;
+ return NT_STATUS_NO_MEMORY;
}
- if (f->mode & aDIR) {
+ if (f->mode & FILE_ATTRIBUTE_DIRECTORY) {
tmp = talloc_asprintf_append(tmp, "%s",
CLI_DIRSEP_STR);
}
if (!tmp) {
TALLOC_FREE(ctx);
- return;
+ return NT_STATUS_NO_MEMORY;
}
info->matches[info->count] = SMB_STRDUP(tmp);
TALLOC_FREE(ctx);
}
if (info->matches[info->count] == NULL) {
- return;
+ return NT_STATUS_OK;
}
- if (f->mode & aDIR) {
+ if (f->mode & FILE_ATTRIBUTE_DIRECTORY) {
smb_readline_ca_char(0);
}
if (info->count == 1) {
}
}
info->count++;
+ return NT_STATUS_OK;
}
static char **remote_completion(const char *text, int len)
goto cleanup;
}
- if (!cli_resolve_path(ctx, "", auth_info, cli, dirmask, &targetcli, &targetpath)) {
+ status = cli_resolve_path(ctx, "", auth_info, cli, dirmask, &targetcli,
+ &targetpath);
+ if (!NT_STATUS_IS_OK(status)) {
goto cleanup;
}
- status = cli_list(targetcli, targetpath, aDIR | aSYSTEM | aHIDDEN,
+ status = cli_list(targetcli, targetpath, FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN,
completion_remote_filter, (void *)&info);
if (!NT_STATUS_IS_OK(status)) {
goto cleanup;
static void readline_callback(void)
{
- fd_set fds;
- struct timeval timeout;
static time_t last_t;
+ struct timespec now;
time_t t;
+ NTSTATUS status;
+ unsigned char garbage[16];
- t = time(NULL);
+ clock_gettime_mono(&now);
+ t = now.tv_sec;
if (t - last_t < 5)
return;
last_t = t;
- again:
-
- if (cli->fd == -1)
- return;
-
- FD_ZERO(&fds);
- FD_SET(cli->fd,&fds);
-
- timeout.tv_sec = 0;
- timeout.tv_usec = 0;
- sys_select_intr(cli->fd+1,&fds,NULL,NULL,&timeout);
-
- /* We deliberately use receive_smb_raw instead of
- client_receive_smb as we want to receive
- session keepalives and then drop them here.
- */
- if (FD_ISSET(cli->fd,&fds)) {
- 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)) {
- 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();
- }
+ 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 (%s). Maybe server has closed "
+ "the connection\n", nt_errstr(status)));
+ finished = true;
+ smb_readline_done();
}
}
static int process(const char *base_directory)
{
int rc = 0;
+ NTSTATUS status;
- cli = cli_cm_open(talloc_tos(), NULL,
- have_ip ? dest_ss_str : desthost,
- service, auth_info, true, smb_encrypt,
- max_protocol, port, name_type);
- if (!cli) {
+ status = cli_cm_open(talloc_tos(), NULL,
+ have_ip ? dest_ss_str : desthost,
+ service, auth_info, true, smb_encrypt,
+ max_protocol, port, name_type, &cli);
+ if (!NT_STATUS_IS_OK(status)) {
return 1;
}
static int do_host_query(const char *query_host)
{
- cli = cli_cm_open(talloc_tos(), NULL,
- query_host, "IPC$", auth_info, true, smb_encrypt,
- max_protocol, port, name_type);
- if (!cli)
+ NTSTATUS status;
+
+ status = cli_cm_open(talloc_tos(), NULL,
+ have_ip ? dest_ss_str : query_host,
+ "IPC$", auth_info, true, smb_encrypt,
+ max_protocol, port, name_type, &cli);
+ if (!NT_STATUS_IS_OK(status)) {
return 1;
+ }
browse_host(true);
else but port 139... */
cli_shutdown(cli);
- cli = cli_cm_open(talloc_tos(), NULL,
- query_host, "IPC$", auth_info, true, smb_encrypt,
- max_protocol, 139, name_type);
+ 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);
+ if (!NT_STATUS_IS_OK(status)) {
+ cli = NULL;
+ }
}
if (cli == NULL) {
/* do we already have a connection? */
if (!cli) {
- cli = cli_cm_open(talloc_tos(), NULL,
- have_ip ? dest_ss_str : desthost,
- service, auth_info, true, smb_encrypt,
- max_protocol, port, name_type);
- if (!cli)
+ NTSTATUS status;
+
+ status = cli_cm_open(talloc_tos(), NULL,
+ have_ip ? dest_ss_str : desthost,
+ service, auth_info, true, smb_encrypt,
+ max_protocol, port, name_type, &cli);
+ if (!NT_STATUS_IS_OK(status)) {
return 1;
+ }
}
recurse=true;
static int do_message_op(struct user_auth_info *a_info)
{
- struct sockaddr_storage ss;
- struct nmb_name called, calling;
- fstring server_name;
- char name_type_hex[10];
- int msg_port;
NTSTATUS status;
- make_nmb_name(&calling, calling_name, 0x0);
- make_nmb_name(&called , desthost, name_type);
-
- fstrcpy(server_name, desthost);
- snprintf(name_type_hex, sizeof(name_type_hex), "#%X", name_type);
- fstrcat(server_name, name_type_hex);
-
- zero_sockaddr(&ss);
- if (have_ip)
- ss = dest_ss;
-
- /* we can only do messages over port 139 (to windows clients at least) */
-
- msg_port = port ? port : 139;
-
- if (!(cli=cli_initialise())) {
- d_printf("Connection to %s failed\n", desthost);
- return 1;
- }
- cli_set_port(cli, msg_port);
-
- status = cli_connect(cli, server_name, &ss);
+ status = cli_connect_nb(desthost, have_ip ? &dest_ss : NULL,
+ port ? port : 139, 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;
}
- if (!cli_session_request(cli, &calling, &called)) {
- d_printf("session request failed\n");
- cli_shutdown(cli);
- return 1;
- }
-
send_message(get_cmdline_auth_info_username(a_info));
cli_shutdown(cli);
poptContext pc;
char *p;
int rc = 0;
- fstring new_workgroup;
bool tar_opt = false;
bool service_opt = false;
struct poptOption long_options[] = {
exit(ENOMEM);
}
- /* initialize the workgroup name so we can determine whether or
- not it was set by a command line option */
-
- set_global_myworkgroup( "" );
- set_global_myname( "" );
-
/* set default debug level to 1 regardless of what smb.conf sets */
- setup_logging( "smbclient", true );
- DEBUGLEVEL_CLASS[DBGC_ALL] = 1;
- if ((dbf = x_fdup(x_stderr))) {
- x_setbuf( dbf, NULL );
- }
-
+ setup_logging( "smbclient", DEBUG_DEFAULT_STDERR );
load_case_tables();
+ lp_set_cmdline("log level", "1");
+
auth_info = user_auth_info_init(frame);
if (auth_info == NULL) {
exit(1);
pc = poptGetContext("smbclient", argc, (const char **) 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 */
}
break;
case 'E':
- if (dbf) {
- x_fclose(dbf);
- }
- dbf = x_stderr;
+ setup_logging("smbclient", DEBUG_STDERR );
display_set_stderr();
break;
poptGetArg(pc));
}
- /*
- * Don't load debug level from smb.conf. It should be
- * set by cmdline arg or remain default (0)
- */
- AllowDebugChange = false;
-
- /* save the workgroup...
-
- FIXME!! do we need to do this for other options as well
- (or maybe a generic way to keep lp_load() from overwriting
- everything)? */
-
- fstrcpy( new_workgroup, lp_workgroup() );
- calling_name = talloc_strdup(frame, global_myname() );
- if (!calling_name) {
- exit(ENOMEM);
- }
-
if ( override_logfile )
- setup_logging( lp_logfile(), false );
+ setup_logging( lp_logfile(), 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 ( strlen(new_workgroup) != 0 ) {
- set_global_myworkgroup( new_workgroup );
- }
-
- if ( strlen(calling_name) != 0 ) {
- set_global_myname( calling_name );
- } else {
- TALLOC_FREE(calling_name);
- calling_name = talloc_strdup(frame, global_myname() );
- }
-
smb_encrypt = get_cmdline_auth_info_smb_encrypt(auth_info);
if (!init_names()) {
fprintf(stderr, "init_names() failed\n");