extern bool AllowDebugChange;
extern bool override_logfile;
extern char tar_type;
-extern bool in_client;
static int port = 0;
static char *service;
static char *calling_name;
static bool grepable = false;
static char *cmdstr = NULL;
-static const char *cmd_ptr = NULL;
+const char *cmd_ptr = NULL;
-static int io_bufsize = 64512;
+static int io_bufsize = 524288;
static int name_type = 0x20;
extern int max_protocol;
return 0;
}
+/****************************************************************************
+ Ensure name has correct directory separators.
+****************************************************************************/
+
+static void normalize_name(char *newdir)
+{
+ if (!(cli->posix_capabilities & CIFS_UNIX_POSIX_PATHNAMES_CAP)) {
+ string_replace(newdir,'/','\\');
+ }
+}
+
/****************************************************************************
Change directory - inner section.
****************************************************************************/
TALLOC_FREE(ctx);
return 1;
}
- string_replace(newdir,'/','\\');
+
+ normalize_name(newdir);
/* Save the current directory in case the new directory is invalid */
if (!new_cd) {
goto out;
}
- if ((new_cd[0] != '\0') && (*(new_cd+strlen(new_cd)-1) != CLI_DIRSEP_CHAR)) {
- new_cd = talloc_asprintf_append(new_cd, CLI_DIRSEP_STR);
- if (!new_cd) {
- goto out;
- }
- }
- client_set_cur_dir(new_cd);
}
- if (!new_cd) {
- goto out;
+
+ /* Ensure cur_dir ends in a DIRSEP */
+ if ((new_cd[0] != '\0') && (*(new_cd+strlen(new_cd)-1) != CLI_DIRSEP_CHAR)) {
+ new_cd = talloc_asprintf_append(new_cd, "%s", CLI_DIRSEP_STR);
+ if (!new_cd) {
+ goto out;
+ }
}
+ client_set_cur_dir(new_cd);
new_cd = clean_name(ctx, new_cd);
client_set_cur_dir(new_cd);
/* create absolute filename for cli_nt_create() FIXME */
afname = talloc_asprintf(ctx,
"%s%s%s",
- client_get_cwd(),
+ dir,
CLI_DIRSEP_STR,
finfo->name);
if (!afname) {
return;
}
/* print file meta date header */
- d_printf( "FILENAME:%s\n", afname);
+ d_printf( "FILENAME:%s\n", finfo->name);
d_printf( "MODE:%s\n", attrib_string(finfo->mode));
d_printf( "SIZE:%.0f\n", (double)finfo->size);
d_printf( "MTIME:%s", time_to_asc(t));
return;
}
p = strrchr_m(mask2,CLI_DIRSEP_CHAR);
- if (!p) {
- TALLOC_FREE(dir);
- return;
+ if (p) {
+ p[1] = 0;
+ } else {
+ mask2[0] = '\0';
}
- p[1] = 0;
mask2 = talloc_asprintf_append(mask2,
"%s%s*",
f->name,
int rc = 1;
dir_total = 0;
- if (strcmp(client_get_cur_dir(), CLI_DIRSEP_STR) != 0) {
- mask = talloc_strdup(ctx, client_get_cur_dir());
- if (!mask) {
- return 1;
- }
- if ((mask[0] != '\0') && (mask[strlen(mask)-1]!=CLI_DIRSEP_CHAR)) {
- mask = talloc_asprintf_append(mask, CLI_DIRSEP_STR);
- }
- } else {
- mask = talloc_strdup(ctx, CLI_DIRSEP_STR);
- }
-
+ mask = talloc_strdup(ctx, client_get_cur_dir());
if (!mask) {
return 1;
}
if (next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
- string_replace(buf,'/','\\');
+ normalize_name(buf);
if (*buf == CLI_DIRSEP_CHAR) {
- mask = talloc_strdup(ctx, buf + 1);
+ mask = talloc_strdup(ctx, buf);
} else {
- mask = talloc_asprintf_append(mask, buf);
+ mask = talloc_asprintf_append(mask, "%s", buf);
}
} else {
mask = talloc_asprintf_append(mask, "*");
return 1;
}
if ((mask[0] != '\0') && (mask[strlen(mask)-1]!=CLI_DIRSEP_CHAR)) {
- mask = talloc_asprintf_append(mask, CLI_DIRSEP_STR);
+ mask = talloc_asprintf_append(mask, "%s", CLI_DIRSEP_STR);
if (!mask) {
return 1;
}
}
if (next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
- string_replace(buf,'/','\\');
+ normalize_name(buf);
if (*buf == CLI_DIRSEP_CHAR) {
mask = talloc_strdup(ctx, buf);
} else {
- mask = talloc_asprintf_append(mask, buf);
+ mask = talloc_asprintf_append(mask, "%s", buf);
}
} else {
mask = talloc_strdup(ctx, "*");
Get a file from rname to lname
****************************************************************************/
+static NTSTATUS writefile_sink(char *buf, size_t n, void *priv)
+{
+ int *pfd = (int *)priv;
+ if (writefile(*pfd, buf, n) == -1) {
+ return map_nt_error_from_unix(errno);
+ }
+ return NT_STATUS_OK;
+}
+
static int do_get(const char *rname, const char *lname_in, bool reget)
{
TALLOC_CTX *ctx = talloc_tos();
int handle = 0, fnum;
bool newhandle = false;
- char *data = NULL;
struct timeval tp_start;
- int read_size = io_bufsize;
uint16 attr;
SMB_OFF_T size;
off_t start = 0;
- off_t nread = 0;
+ SMB_OFF_T nread = 0;
int rc = 0;
struct cli_state *targetcli = NULL;
char *targetname = NULL;
char *lname = NULL;
+ NTSTATUS status;
lname = talloc_strdup(ctx, lname_in);
if (!lname) {
DEBUG(1,("getting file %s of size %.0f as %s ",
rname, (double)size, lname));
- if(!(data = (char *)SMB_MALLOC(read_size))) {
- d_printf("malloc fail for size %d\n", read_size);
+ status = cli_pull(targetcli, fnum, start, size, io_bufsize,
+ writefile_sink, (void *)&handle, &nread);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_fprintf(stderr, "parallel_read returned %s\n",
+ nt_errstr(status));
cli_close(targetcli, fnum);
return 1;
}
- while (1) {
- int n = cli_read(targetcli, fnum, data, nread + start, read_size);
-
- if (n <= 0)
- break;
-
- if (writefile(handle,data, n) != n) {
- d_printf("Error writing local file\n");
- rc = 1;
- break;
- }
-
- nread += n;
- }
-
- if (nread + start < size) {
- DEBUG (0, ("Short read when getting file %s. Only got %ld bytes.\n",
- rname, (long)nread));
-
- rc = 1;
- }
-
- SAFE_FREE(data);
-
if (!cli_close(targetcli, fnum)) {
d_printf("Error %s closing remote file\n",cli_errstr(cli));
rc = 1;
char *rname = NULL;
char *fname = NULL;
- rname = talloc_asprintf(ctx,
- "%s%s",
- client_get_cur_dir(),
- CLI_DIRSEP_STR);
+ rname = talloc_strdup(ctx, client_get_cur_dir());
if (!rname) {
return 1;
}
d_printf("get <filename> [localname]\n");
return 1;
}
- rname = talloc_asprintf_append(rname, fname);
+ rname = talloc_asprintf_append(rname, "%s", fname);
if (!rname) {
return 1;
}
}
do_list(mget_mask, aSYSTEM | aHIDDEN | aDIR,do_mget,false, true);
- chdir("..");
+ if (chdir("..") == -1) {
+ d_printf("do_mget: failed to chdir to .. (error %s)\n",
+ strerror(errno) );
+ }
client_set_cur_dir(saved_curdir);
TALLOC_FREE(mget_mask);
TALLOC_FREE(saved_curdir);
int fd;
int rc = 0;
- rname = talloc_asprintf(ctx,
- "%s%s",
- client_get_cur_dir(),
- CLI_DIRSEP_STR);
+ rname = talloc_strdup(ctx, client_get_cur_dir());
if (!rname) {
return 1;
}
unlink(lname);
return 1;
}
- rname = talloc_asprintf_append(rname, fname);
+ rname = talloc_asprintf_append(rname, "%s", fname);
if (!rname) {
return 1;
}
if (!pager_cmd) {
return 1;
}
- system(pager_cmd);
+ if (system(pager_cmd) == -1) {
+ d_printf("system command '%s' returned -1\n",
+ pager_cmd);
+ }
unlink(lname);
return rc;
if (!mget_mask) {
return 1;
}
- if ((mget_mask[0] != '\0') &&
- (mget_mask[strlen(mget_mask)-1]!=CLI_DIRSEP_CHAR)) {
- mget_mask = talloc_asprintf_append(mget_mask,
- CLI_DIRSEP_STR);
- if (!mget_mask) {
- return 1;
- }
- }
-
if (*buf == CLI_DIRSEP_CHAR) {
mget_mask = talloc_strdup(ctx, buf);
} else {
mget_mask = talloc_asprintf_append(mget_mask,
- buf);
+ "%s", buf);
}
if (!mget_mask) {
return 1;
do_list(mget_mask, attribute, do_mget, false, true);
}
+ if (mget_mask == NULL) {
+ d_printf("nothing to mget\n");
+ return 0;
+ }
+
if (!*mget_mask) {
- mget_mask = talloc_strdup(ctx, client_get_cur_dir());
- if (!mget_mask) {
- return 1;
- }
- if(mget_mask[strlen(mget_mask)-1]!=CLI_DIRSEP_CHAR) {
- mget_mask = talloc_asprintf_append(mget_mask,
- CLI_DIRSEP_STR);
- if (!mget_mask) {
- return 1;
- }
- }
- mget_mask = talloc_asprintf_append(mget_mask, "*");
+ mget_mask = talloc_asprintf(ctx,
+ "%s*",
+ client_get_cur_dir());
if (!mget_mask) {
return 1;
}
}
return 1;
}
- mask = talloc_asprintf_append(mask, buf);
+ mask = talloc_asprintf_append(mask, "%s", buf);
if (!mask) {
return 1;
}
struct cli_state *targetcli;
char *targetname = NULL;
char *p = NULL;
+ char *saveptr;
ddir2 = talloc_strdup(ctx, "");
if (!ddir2) {
return 1;
}
trim_char(ddir,'.','\0');
- p = strtok(ddir,"/\\");
+ p = strtok_r(ddir, "/\\", &saveptr);
while (p) {
- ddir2 = talloc_asprintf_append(ddir2, p);
+ ddir2 = talloc_asprintf_append(ddir2, "%s", p);
if (!ddir2) {
return 1;
}
if (!cli_chkpath(targetcli, ddir2)) {
do_mkdir(ddir2);
}
- ddir2 = talloc_asprintf_append(ddir2, CLI_DIRSEP_STR);
+ ddir2 = talloc_asprintf_append(ddir2, "%s", CLI_DIRSEP_STR);
if (!ddir2) {
return 1;
}
- p = strtok(NULL,"/\\");
+ p = strtok_r(NULL, "/\\", &saveptr);
}
} else {
do_mkdir(mask);
d_printf("altname <file>\n");
return 1;
}
- name = talloc_asprintf_append(name, buf);
+ name = talloc_asprintf_append(name, "%s", buf);
if (!name) {
return 1;
}
return 0;
}
+/****************************************************************************
+ Show all info we can get
+****************************************************************************/
+
+static int do_allinfo(const char *name)
+{
+ fstring altname;
+ struct timespec b_time, a_time, m_time, c_time;
+ SMB_OFF_T size;
+ uint16_t mode;
+ SMB_INO_T ino;
+ NTTIME tmp;
+ unsigned int num_streams;
+ struct stream_struct *streams;
+ unsigned int i;
+
+ if (!NT_STATUS_IS_OK(cli_qpathinfo_alt_name(cli, name, altname))) {
+ d_printf("%s getting alt name for %s\n",
+ cli_errstr(cli),name);
+ return false;
+ }
+ d_printf("altname: %s\n", altname);
+
+ if (!cli_qpathinfo2(cli, name, &b_time, &a_time, &m_time, &c_time,
+ &size, &mode, &ino)) {
+ d_printf("%s getting pathinfo for %s\n",
+ cli_errstr(cli),name);
+ return false;
+ }
+
+ 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));
+
+ if (!cli_qpathinfo_streams(cli, name, talloc_tos(), &num_streams,
+ &streams)) {
+ d_printf("%s getting streams for %s\n",
+ cli_errstr(cli),name);
+ return false;
+ }
+
+ for (i=0; i<num_streams; i++) {
+ d_printf("stream: [%s], %lld bytes\n", streams[i].name,
+ (unsigned long long)streams[i].size);
+ }
+
+ return 0;
+}
+
+/****************************************************************************
+ Show all info we can get
+****************************************************************************/
+
+static int cmd_allinfo(void)
+{
+ TALLOC_CTX *ctx = talloc_tos();
+ char *name;
+ char *buf;
+
+ name = talloc_strdup(ctx, client_get_cur_dir());
+ if (!name) {
+ return 1;
+ }
+
+ if (!next_token_talloc(ctx, &cmd_ptr, &buf, NULL)) {
+ d_printf("allinfo <file>\n");
+ return 1;
+ }
+ name = talloc_asprintf_append(name, "%s", buf);
+ if (!name) {
+ return 1;
+ }
+
+ do_allinfo(name);
+
+ return 0;
+}
+
/****************************************************************************
Put a single file.
****************************************************************************/
char *rname;
char *buf;
- rname = talloc_asprintf(ctx,
- "%s%s",
- client_get_cur_dir(),
- CLI_DIRSEP_STR);
+ rname = talloc_strdup(ctx, client_get_cur_dir());
if (!rname) {
return 1;
}
}
if (next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
- rname = talloc_asprintf_append(rname, buf);
+ rname = talloc_asprintf_append(rname, "%s", buf);
} else {
- rname = talloc_asprintf_append(rname, lname);
+ rname = talloc_asprintf_append(rname, "%s", lname);
}
if (!rname) {
return 1;
Free a file_list structure.
****************************************************************************/
-static void free_file_list (struct file_list *list_head)
+static void free_file_list (struct file_list *l_head)
{
struct file_list *list, *next;
- for (list = list_head; list; list = next) {
+ for (list = l_head; list; list = next) {
next = list->next;
- DLIST_REMOVE(list_head, list);
+ DLIST_REMOVE(l_head, list);
SAFE_FREE(list->file_path);
SAFE_FREE(list);
}
break;
} else { /* Yes */
SAFE_FREE(rname);
- if(asprintf(&rname, "%s%s", cur_dir, lname) < 0) {
+ if(asprintf(&rname, "%s%s", client_get_cur_dir(), lname) < 0) {
break;
}
- string_replace(rname,'/','\\');
+ normalize_name(rname);
if (!cli_chkpath(cli, rname) &&
!do_mkdir(rname)) {
DEBUG (0, ("Unable to make dir, skipping..."));
/* Yes */
SAFE_FREE(rname);
- if (asprintf(&rname, "%s%s", cur_dir, lname) < 0) {
+ if (asprintf(&rname, "%s%s", client_get_cur_dir(), lname) < 0) {
break;
}
}
- string_replace(rname,'/','\\');
+ normalize_name(rname);
do_put(rname, lname, false);
}
d_printf("del <filename>\n");
return 1;
}
- mask = talloc_asprintf_append(mask, buf);
+ mask = talloc_asprintf_append(mask, "%s", buf);
if (!mask) {
return 1;
}
break;
case SMB_POSIX_ACL_GROUP:
uorg = IVAL(retbuf,SMB_POSIX_ACL_HEADER_SIZE+(i*SMB_POSIX_ACL_ENTRY_SIZE)+2);
- d_printf("group:%u", uorg);
+ d_printf("group:%u:", uorg);
break;
case SMB_POSIX_ACL_MASK:
d_printf("mask::");
break;
case SMB_POSIX_ACL_GROUP:
uorg = IVAL(retbuf,SMB_POSIX_ACL_HEADER_SIZE+((i+num_file_acls)*SMB_POSIX_ACL_ENTRY_SIZE)+2);
- d_printf("default:group:%u", uorg);
+ d_printf("default:group:%u:", uorg);
break;
case SMB_POSIX_ACL_MASK:
d_printf("default:mask::");
char *d;
if (next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
- chdir(buf);
+ if (chdir(buf) == -1) {
+ d_printf("chdir to %s failed (%s)\n",
+ buf, strerror(errno));
+ }
}
d = TALLOC_ARRAY(ctx, char, PATH_MAX+1);
if (!d) {
char *fname = NULL;
char *p = NULL;
- remote_name = talloc_asprintf(ctx,
- "%s%s",
- client_get_cur_dir(),
- CLI_DIRSEP_STR);
+ remote_name = talloc_strdup(ctx, client_get_cur_dir());
if (!remote_name) {
return 1;
}
d_printf("reget <filename>\n");
return 1;
}
- remote_name = talloc_asprintf_append(remote_name, fname);
+ remote_name = talloc_asprintf_append(remote_name, "%s", fname);
if (!remote_name) {
return 1;
}
char *buf;
SMB_STRUCT_STAT st;
- remote_name = talloc_asprintf(ctx,
- "%s%s",
- client_get_cur_dir(),
- CLI_DIRSEP_STR);
+ remote_name = talloc_strdup(ctx, client_get_cur_dir());
if (!remote_name) {
return 1;
}
if (next_token_talloc(ctx, &cmd_ptr, &buf, NULL)) {
remote_name = talloc_asprintf_append(remote_name,
- buf);
+ "%s", buf);
} else {
remote_name = talloc_asprintf_append(remote_name,
- local_name);
+ "%s", local_name);
}
if (!remote_name) {
return 1;
NTSTATUS status;
struct rpc_pipe_client *pipe_hnd;
TALLOC_CTX *frame = talloc_stackframe();
- ENUM_HND enum_hnd;
WERROR werr;
- SRV_SHARE_INFO_CTR ctr;
+ struct srvsvc_NetShareInfoCtr info_ctr;
+ struct srvsvc_NetShareCtr1 ctr1;
+ uint32_t resume_handle = 0;
+ uint32_t total_entries = 0;
int i;
- init_enum_hnd(&enum_hnd, 0);
-
- pipe_hnd = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC, &status);
+ status = cli_rpc_pipe_open_noauth(cli, &ndr_table_srvsvc.syntax_id,
+ &pipe_hnd);
- if (pipe_hnd == NULL) {
+ if (!NT_STATUS_IS_OK(status)) {
DEBUG(10, ("Could not connect to srvsvc pipe: %s\n",
nt_errstr(status)));
TALLOC_FREE(frame);
return false;
}
- werr = rpccli_srvsvc_net_share_enum(pipe_hnd, frame, 1, &ctr,
- 0xffffffff, &enum_hnd);
+ ZERO_STRUCT(info_ctr);
+ ZERO_STRUCT(ctr1);
+
+ info_ctr.level = 1;
+ info_ctr.ctr.ctr1 = &ctr1;
+
+ status = rpccli_srvsvc_NetShareEnumAll(pipe_hnd, frame,
+ pipe_hnd->desthost,
+ &info_ctr,
+ 0xffffffff,
+ &total_entries,
+ &resume_handle,
+ &werr);
- if (!W_ERROR_IS_OK(werr)) {
- cli_rpc_pipe_close(pipe_hnd);
+ if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) {
+ TALLOC_FREE(pipe_hnd);
TALLOC_FREE(frame);
return false;
}
- for (i=0; i<ctr.num_entries; i++) {
- SRV_SHARE_INFO_1 *info = &ctr.share.info1[i];
- char *name, *comment;
- name = rpcstr_pull_unistr2_talloc(
- frame, &info->info_1_str.uni_netname);
- comment = rpcstr_pull_unistr2_talloc(
- frame, &info->info_1_str.uni_remark);
- browse_fn(name, info->info_1.type, comment, NULL);
+ for (i=0; i < info_ctr.ctr.ctr1->count; i++) {
+ struct srvsvc_NetShareInfo1 info = info_ctr.ctr.ctr1->array[i];
+ browse_fn(info.name, info.type, info.comment, NULL);
}
- cli_rpc_pipe_close(pipe_hnd);
+ TALLOC_FREE(pipe_hnd);
TALLOC_FREE(frame);
return true;
}
d_printf("iosize <n> or iosize 0x<n>. "
"(Encrypted connection) ,"
"Minimum is 16384 (0x4000), "
- "max is 64512 (0xFC00)\n");
+ "max is 130048 (0x1FC00)\n");
}
return 1;
}
if (smb_encrypt && (iosize < 0x4000 || iosize > 0xFC00)) {
d_printf("iosize out of range for encrypted "
"connection (min = 16384 (0x4000), "
- "max = 64512 (0xFC00)");
+ "max = 130048 (0x1FC00)");
return 1;
} else if (!smb_encrypt && (iosize < 0x4000 || iosize > 0xFFFF00)) {
d_printf("iosize out of range (min = 16384 (0x4000), "
char compl_args[2]; /* Completion argument info */
} commands[] = {
{"?",cmd_help,"[command] give help on a command",{COMPL_NONE,COMPL_NONE}},
+ {"allinfo",cmd_allinfo,"<file> show all available info",
+ {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}},
{"blocksize",cmd_block,"blocksize <number> (default 20)",{COMPL_NONE,COMPL_NONE}},
TALLOC_CTX *ctx = talloc_stackframe();
char *tmp;
- if (info->dirmask && info->dirmask[0] != 0) {
- tmp = talloc_strdup(ctx,info->dirmask);
- } else {
- tmp = talloc_strdup(ctx,"");
- }
+ tmp = talloc_strdup(ctx,info->dirmask);
if (!tmp) {
TALLOC_FREE(ctx);
return;
}
- tmp = talloc_asprintf_append(tmp, f->name);
+ tmp = talloc_asprintf_append(tmp, "%s", f->name);
if (!tmp) {
TALLOC_FREE(ctx);
return;
}
if (f->mode & aDIR) {
- tmp = talloc_asprintf_append(tmp, "/");
+ tmp = talloc_asprintf_append(tmp, "%s", CLI_DIRSEP_STR);
}
if (!tmp) {
TALLOC_FREE(ctx);
}
}
+static bool finished;
+
/****************************************************************************
Make sure we swallow keepalives during idle time.
****************************************************************************/
session keepalives and then drop them here.
*/
if (FD_ISSET(cli->fd,&fds)) {
- if (receive_smb_raw(cli->fd,cli->inbuf,0,0,&cli->smb_rw_error) == -1) {
- DEBUG(0, ("Read from server failed, maybe it closed the "
- "connection\n"));
+ 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) {
{
unsigned char garbage[16];
memset(garbage, 0xf0, sizeof(garbage));
- cli_echo(cli, 1, garbage, sizeof(garbage));
+ if (!cli_echo(cli, 1, garbage, sizeof(garbage))) {
+ DEBUG(0, ("SMBecho failed. Maybe server has closed "
+ "the connection\n"));
+ smb_readline_done();
+ finished = true;
+ }
}
}
{
int rc = 0;
- while (1) {
+ while (!finished) {
TALLOC_CTX *frame = talloc_stackframe();
char *tok = NULL;
char *the_prompt = NULL;
/* special case - first char is ! */
if (*line == '!') {
- system(line + 1);
+ if (system(line + 1) == -1) {
+ d_printf("system() command %s failed.\n",
+ line+1);
+ }
SAFE_FREE(line);
TALLOC_FREE(frame);
continue;
static int do_host_query(const char *query_host)
{
+ struct sockaddr_storage ss;
+
cli = cli_cm_open(talloc_tos(), NULL,
query_host, "IPC$", true, smb_encrypt);
if (!cli)
browse_host(true);
+ if (interpret_string_addr(&ss, query_host, 0) && (ss.ss_family != AF_INET)) {
+ d_printf("%s is an IPv6 address -- no workgroup available\n",
+ query_host);
+ return 1;
+ }
+
if (port != 139) {
/* Workgroups simply don't make sense over anything
snprintf(name_type_hex, sizeof(name_type_hex), "#%X", name_type);
fstrcat(server_name, name_type_hex);
- zero_addr(&ss);
+ zero_sockaddr(&ss);
if (have_ip)
ss = dest_ss;
{ "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" },
- { "encrypt", 'e', POPT_ARG_NONE, NULL, 'e', "Encrypt SMB transport (UNIX extended servers only)" },
POPT_COMMON_SAMBA
POPT_COMMON_CONNECTION
POPT_COMMON_CREDENTIALS
set_global_myworkgroup( "" );
set_global_myname( "" );
- /* set default debug level to 0 regardless of what smb.conf sets */
+ /* 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))) {
pc = poptGetContext("smbclient", argc, (const char **) argv, long_options, 0);
poptSetOtherOptionHelp(pc, "service <password>");
- in_client = true; /* Make sure that we tell lp_load we are */
+ lp_set_in_client(true); /* Make sure that we tell lp_load we are */
while ((opt = poptGetNextOpt(pc)) != -1) {
argv[0], get_dyn_CONFIGFILE());
}
+ if (get_cmdline_auth_info_use_machine_account() &&
+ !set_cmdline_auth_info_machine_account_creds()) {
+ exit(-1);
+ }
+
load_interfaces();
if (service_opt && service) {
calling_name = talloc_strdup(frame, global_myname() );
}
- init_names();
+ smb_encrypt = get_cmdline_auth_info_smb_encrypt();
+ if (!init_names()) {
+ fprintf(stderr, "init_names() failed\n");
+ exit(1);
+ }
if(new_name_resolve_order)
lp_set_name_resolve_order(new_name_resolve_order);