#include "includes.h"
#include "client/client_proto.h"
-#include "include/rpc_client.h"
+#include "../librpc/gen_ndr/cli_srvsvc.h"
+
#ifndef REGISTER
#define REGISTER 0
#endif
static int io_bufsize = 524288;
static int name_type = 0x20;
-extern int max_protocol;
+static int max_protocol = PROTOCOL_NT1;
static int process_tok(char *tok);
static int cmd_help(void);
bool lowercase = false;
static struct sockaddr_storage dest_ss;
+static char dest_ss_str[INET6_ADDRSTRLEN];
#define SEPARATORS " \t\n\r"
static char CLI_DIRSEP_CHAR = '\\';
static char CLI_DIRSEP_STR[] = { '\\', '\0' };
+/* Authentication for client connections. */
+struct user_auth_info *auth_info;
+
/* Accessor functions for directory paths. */
static char *fileselection;
static const char *client_get_fileselection(void)
number read. read approx n bytes.
****************************************************************************/
-static int readfile(char *b, int n, XFILE *f)
+static int readfile(uint8_t *b, int n, XFILE *f)
{
int i;
int c;
return(i);
}
-/****************************************************************************
- Send a message.
-****************************************************************************/
+struct push_state {
+ XFILE *f;
+ SMB_OFF_T nread;
+};
-static void send_message(void)
+static size_t push_source(uint8_t *buf, size_t n, void *priv)
{
- int total_len = 0;
- int grp_id;
+ struct push_state *state = (struct push_state *)priv;
+ int result;
- if (!cli_message_start(cli, desthost,
- get_cmdline_auth_info_username(), &grp_id)) {
- d_printf("message start: %s\n", cli_errstr(cli));
- return;
+ if (x_feof(state->f)) {
+ return 0;
}
+ result = readfile(buf, n, state->f);
+ state->nread += result;
+ return result;
+}
- d_printf("Connected. Type your message, ending it with a Control-D\n");
-
- while (!feof(stdin) && total_len < 1600) {
- int maxlen = MIN(1600 - total_len,127);
- char msg[1024];
- int l=0;
- int c;
+/****************************************************************************
+ Send a message.
+****************************************************************************/
- ZERO_ARRAY(msg);
+static void send_message(const char *username)
+{
+ char buf[1600];
+ NTSTATUS status;
+ int i;
- for (l=0;l<maxlen && (c=fgetc(stdin))!=EOF;l++) {
- if (c == '\n')
- msg[l++] = '\r';
- msg[l] = c;
- }
+ d_printf("Type your message, ending it with a Control-D\n");
- if ((total_len > 0) && (strlen(msg) == 0)) {
+ i = 0;
+ while (i<sizeof(buf)-2) {
+ int c = fgetc(stdin);
+ if (c == EOF) {
break;
}
-
- if (!cli_message_text(cli, msg, l, grp_id)) {
- d_printf("SMBsendtxt failed (%s)\n",cli_errstr(cli));
- return;
+ if (c == '\n') {
+ buf[i++] = '\r';
}
-
- total_len += l;
+ buf[i++] = c;
}
+ buf[i] = '\0';
- if (total_len >= 1600)
- d_printf("the message was truncated to 1600 bytes\n");
- else
- d_printf("sent %d bytes\n",total_len);
-
- if (!cli_message_end(cli, grp_id)) {
- d_printf("SMBsendend failed (%s)\n",cli_errstr(cli));
- return;
+ status = cli_message(cli, desthost, username, buf);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_fprintf(stderr, "cli_message returned %s\n",
+ nt_errstr(status));
}
}
char *targetpath = NULL;
TALLOC_CTX *ctx = talloc_tos();
- if ( !cli_resolve_path(ctx, "", cli, client_get_cur_dir(), &targetcli, &targetpath)) {
+ if ( !cli_resolve_path(ctx, "", auth_info, cli, client_get_cur_dir(), &targetcli, &targetpath)) {
d_printf("Error in dskattr: %s\n", cli_errstr(cli));
return 1;
}
- if (!cli_dskattr(targetcli, &bsize, &total, &avail)) {
+ if (!NT_STATUS_IS_OK(cli_dskattr(targetcli, &bsize, &total, &avail))) {
d_printf("Error in dskattr: %s\n",cli_errstr(targetcli));
return 1;
}
/* 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, CLI_DIRSEP_STR);
+ new_cd = talloc_asprintf_append(new_cd, "%s", CLI_DIRSEP_STR);
if (!new_cd) {
goto out;
}
new_cd = clean_name(ctx, new_cd);
client_set_cur_dir(new_cd);
- if ( !cli_resolve_path(ctx, "", cli, new_cd, &targetcli, &targetpath)) {
+ if ( !cli_resolve_path(ctx, "", auth_info, cli, new_cd, &targetcli, &targetpath)) {
d_printf("cd %s: %s\n", new_cd, cli_errstr(cli));
client_set_cur_dir(saved_dir);
goto out;
goto out;
}
- if (!cli_chkpath(targetcli, targetpath)) {
+ if (!NT_STATUS_IS_OK(cli_chkpath(targetcli, targetpath))) {
d_printf("cd %s: %s\n", new_cd, cli_errstr(targetcli));
client_set_cur_dir(saved_dir);
goto out;
dir_total += finfo->size;
} else {
char *afname = NULL;
- int fnum;
+ uint16_t fnum;
/* skip if this is . or .. */
if ( strequal(finfo->name,"..") || strequal(finfo->name,".") )
return;
- /* create absolute filename for cli_nt_create() FIXME */
+ /* create absolute filename for cli_ntcreate() FIXME */
afname = talloc_asprintf(ctx,
"%s%s%s",
dir,
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));
- fnum = cli_nt_create(finfo->cli, afname, CREATE_ACCESS_READ);
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(finfo->cli, afname, 0,
+ CREATE_ACCESS_READ, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
+ FILE_OPEN, 0x0, 0x0, &fnum))) {
DEBUG( 0, ("display_finfo() Failed to open %s: %s\n",
afname,
cli_errstr( finfo->cli)));
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,
/* check for dfs */
- if ( !cli_resolve_path(ctx, "", cli, head, &targetcli, &targetpath ) ) {
+ if ( !cli_resolve_path(ctx, "", auth_info, cli, head, &targetcli, &targetpath ) ) {
d_printf("do_list: [%s] %s\n", head, cli_errstr(cli));
remove_do_list_queue_head();
continue;
}
} else {
/* check for dfs */
- if (cli_resolve_path(ctx, "", cli, mask, &targetcli, &targetpath)) {
+ if (cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetpath)) {
if (cli_list(targetcli, targetpath, attribute, do_list_helper, NULL) == -1) {
d_printf("%s listing %s\n",
cli_errstr(targetcli), targetpath);
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_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 (*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, "*");
static int do_get(const char *rname, const char *lname_in, bool reget)
{
TALLOC_CTX *ctx = talloc_tos();
- int handle = 0, fnum;
+ int handle = 0;
+ uint16_t fnum;
bool newhandle = false;
struct timeval tp_start;
uint16 attr;
strlower_m(lname);
}
- if (!cli_resolve_path(ctx, "", cli, rname, &targetcli, &targetname ) ) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, rname, &targetcli, &targetname ) ) {
d_printf("Failed to open %s: %s\n", rname, cli_errstr(cli));
return 1;
}
GetTimeOfDay(&tp_start);
- fnum = cli_open(targetcli, targetname, O_RDONLY, DENY_NONE);
-
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(targetcli, targetname, O_RDONLY, DENY_NONE, &fnum))) {
d_printf("%s opening remote file %s\n",cli_errstr(cli),rname);
return 1;
}
if (!cli_qfileinfo(targetcli, fnum,
&attr, &size, NULL, NULL, NULL, NULL, NULL) &&
- !cli_getattrE(targetcli, fnum,
- &attr, &size, 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;
}
return 1;
}
- if (!cli_close(targetcli, fnum)) {
+ if (!NT_STATUS_IS_OK(cli_close(targetcli, fnum))) {
d_printf("Error %s closing remote file\n",cli_errstr(cli));
rc = 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;
}
strlower_m(finfo->name);
}
- if (!directory_exist(finfo->name,NULL) &&
+ if (!directory_exist(finfo->name) &&
mkdir(finfo->name,0777) != 0) {
d_printf("failed to create directory %s\n",finfo->name);
client_set_cur_dir(saved_curdir);
}
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);
if (!lname) {
return 1;
}
- fd = smb_mkstemp(lname);
+ fd = mkstemp(lname);
if (fd == -1) {
d_printf("failed to create temporary file for more\n");
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;
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_asprintf(ctx,
"%s*",
struct cli_state *targetcli;
char *targetname = NULL;
- if (!cli_resolve_path(ctx, "", cli, name, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, name, &targetcli, &targetname)) {
d_printf("mkdir %s: %s\n", name, cli_errstr(cli));
return false;
}
- if (!cli_mkdir(targetcli, targetname)) {
+ if (!NT_STATUS_IS_OK(cli_mkdir(targetcli, targetname))) {
d_printf("%s making remote directory %s\n",
cli_errstr(targetcli),name);
return false;
static int cmd_quit(void)
{
- cli_cm_shutdown();
+ cli_shutdown(cli);
exit(0);
/* NOTREACHED */
return 0;
}
return 1;
}
- mask = talloc_asprintf_append(mask, buf);
+ mask = talloc_asprintf_append(mask, "%s", buf);
if (!mask) {
return 1;
}
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, mask, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) {
return 1;
}
trim_char(ddir,'.','\0');
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)) {
+ if (!NT_STATUS_IS_OK(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;
}
d_printf("altname <file>\n");
return 1;
}
- name = talloc_asprintf_append(name, buf);
+ name = talloc_asprintf_append(name, "%s", buf);
if (!name) {
return 1;
}
d_printf("allinfo <file>\n");
return 1;
}
- name = talloc_asprintf_append(name, buf);
+ name = talloc_asprintf_append(name, "%s", buf);
if (!name) {
return 1;
}
static int do_put(const char *rname, const char *lname, bool reput)
{
TALLOC_CTX *ctx = talloc_tos();
- int fnum;
+ uint16_t fnum;
XFILE *f;
SMB_OFF_T start = 0;
- off_t nread = 0;
- char *buf = NULL;
- int maxwrite = io_bufsize;
int rc = 0;
struct timeval tp_start;
struct cli_state *targetcli;
char *targetname = NULL;
+ struct push_state state;
+ NTSTATUS status;
- if (!cli_resolve_path(ctx, "", cli, rname, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, rname, &targetcli, &targetname)) {
d_printf("Failed to open %s: %s\n", rname, cli_errstr(cli));
return 1;
}
GetTimeOfDay(&tp_start);
if (reput) {
- fnum = cli_open(targetcli, targetname, O_RDWR|O_CREAT, DENY_NONE);
- if (fnum >= 0) {
+ 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) &&
- !cli_getattrE(targetcli, fnum, NULL, &start, NULL, NULL, NULL)) {
+ !NT_STATUS_IS_OK(cli_getattrE(targetcli, fnum, NULL, &start, NULL, NULL, NULL))) {
d_printf("getattrib: %s\n",cli_errstr(cli));
return 1;
}
}
} else {
- fnum = cli_open(targetcli, targetname, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE);
+ status = cli_open(targetcli, targetname, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE, &fnum);
}
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(status)) {
d_printf("%s opening remote file %s\n",cli_errstr(targetcli),rname);
return 1;
}
if (f && reput) {
if (x_tseek(f, start, SEEK_SET) == -1) {
d_printf("Error seeking local file\n");
+ x_fclose(f);
return 1;
}
}
DEBUG(1,("putting file %s as %s ",lname,
rname));
- buf = (char *)SMB_MALLOC(maxwrite);
- if (!buf) {
- d_printf("ERROR: Not enough memory!\n");
- return 1;
- }
- while (!x_feof(f)) {
- int n = maxwrite;
- int ret;
-
- if ((n = readfile(buf,n,f)) < 1) {
- if((n == 0) && x_feof(f))
- break; /* Empty local file. */
-
- d_printf("Error reading local file: %s\n", strerror(errno));
- rc = 1;
- break;
- }
-
- ret = cli_write(targetcli, fnum, 0, buf, nread + start, n);
+ x_setvbuf(f, NULL, X_IOFBF, io_bufsize);
- if (n != ret) {
- d_printf("Error writing file: %s\n", cli_errstr(cli));
- rc = 1;
- break;
- }
+ state.f = f;
+ state.nread = 0;
- nread += n;
+ status = cli_push(targetcli, fnum, 0, 0, io_bufsize, push_source,
+ &state);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_fprintf(stderr, "cli_push returned %s\n", nt_errstr(status));
}
- if (!cli_close(targetcli, fnum)) {
+ if (!NT_STATUS_IS_OK(cli_close(targetcli, fnum))) {
d_printf("%s closing remote file %s\n",cli_errstr(cli),rname);
- x_fclose(f);
- SAFE_FREE(buf);
+ if (f != x_stdin) {
+ x_fclose(f);
+ }
return 1;
}
x_fclose(f);
}
- SAFE_FREE(buf);
-
{
struct timeval tp_end;
int this_time;
(tp_end.tv_sec - tp_start.tv_sec)*1000 +
(tp_end.tv_usec - tp_start.tv_usec)/1000;
put_total_time_ms += this_time;
- put_total_size += nread;
+ put_total_size += state.nread;
DEBUG(1,("(%3.1f kb/s) (average %3.1f kb/s)\n",
- nread / (1.024*this_time + 1.0e-4),
+ state.nread / (1.024*this_time + 1.0e-4),
put_total_size / (1.024*put_total_time_ms)));
}
if (f == x_stdin) {
- cli_cm_shutdown();
+ cli_shutdown(cli);
exit(0);
}
}
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;
SMB_STRUCT_STAT st;
/* allow '-' to represent stdin
jdblair, 24.jun.98 */
- if (!file_exist(lname,&st) &&
+ if (!file_exist_stat(lname, &st, false) &&
(strcmp(lname,"-"))) {
d_printf("%s does not exist\n",lname);
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;
}
normalize_name(rname);
- if (!cli_chkpath(cli, rname) &&
+ if (!NT_STATUS_IS_OK(cli_chkpath(cli, rname)) &&
!do_mkdir(rname)) {
DEBUG (0, ("Unable to make dir, skipping..."));
/* Skip the directory */
return;
}
- if (!cli_unlink(finfo->cli, mask)) {
+ if (!NT_STATUS_IS_OK(cli_unlink(finfo->cli, mask, aSYSTEM | aHIDDEN))) {
d_printf("%s deleting remote file %s\n",
cli_errstr(finfo->cli),mask);
}
d_printf("del <filename>\n");
return 1;
}
- mask = talloc_asprintf_append(mask, buf);
+ mask = talloc_asprintf_append(mask, "%s", buf);
if (!mask) {
return 1;
}
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, mask, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) {
d_printf("cmd_wdel %s: %s\n", mask, cli_errstr(cli));
return 1;
}
- if (!cli_unlink_full(targetcli, targetname, attribute)) {
+ if (!NT_STATUS_IS_OK(cli_unlink(targetcli, targetname, attribute))) {
d_printf("%s deleting remote files %s\n",cli_errstr(targetcli),targetname);
}
return 0;
char *buf = NULL;
char *targetname = NULL;
struct cli_state *targetcli;
- int fnum;
+ uint16_t fnum = (uint16_t)-1;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
d_printf("open <filename>\n");
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, mask, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) {
d_printf("open %s: %s\n", mask, cli_errstr(cli));
return 1;
}
- fnum = cli_nt_create(targetcli, targetname, FILE_READ_DATA|FILE_WRITE_DATA);
- if (fnum == -1) {
- fnum = cli_nt_create(targetcli, targetname, FILE_READ_DATA);
- if (fnum != -1) {
+ if (!NT_STATUS_IS_OK(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_READ_DATA, 0,
+ FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum))) {
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));
char *targetname = NULL;
struct cli_state *targetcli;
mode_t mode;
- int fnum;
+ uint16_t fnum;
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, "", cli, mask, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) {
d_printf("posix_open %s: %s\n", mask, cli_errstr(cli));
return 1;
}
- fnum = cli_posix_open(targetcli, targetname, O_CREAT|O_RDWR, mode);
- if (fnum == -1) {
- fnum = cli_posix_open(targetcli, targetname, O_CREAT|O_RDONLY, mode);
- if (fnum != -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);
} else {
d_printf("Failed to open file %s. %s\n", targetname, cli_errstr(cli));
char *targetname = NULL;
struct cli_state *targetcli;
mode_t mode;
- int fnum;
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, "", cli, mask, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) {
d_printf("posix_mkdir %s: %s\n", mask, cli_errstr(cli));
return 1;
}
- fnum = cli_posix_mkdir(targetcli, targetname, mode);
- if (fnum == -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));
} else {
d_printf("posix_mkdir created directory %s\n", targetname);
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, mask, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) {
d_printf("posix_unlink %s: %s\n", mask, cli_errstr(cli));
return 1;
}
- if (!cli_posix_unlink(targetcli, targetname)) {
+ if (!NT_STATUS_IS_OK(cli_posix_unlink(targetcli, targetname))) {
d_printf("Failed to unlink file %s. %s\n", targetname, cli_errstr(cli));
} else {
d_printf("posix_unlink deleted file %s\n", targetname);
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, mask, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) {
d_printf("posix_rmdir %s: %s\n", mask, cli_errstr(cli));
return 1;
}
- if (!cli_posix_rmdir(targetcli, targetname)) {
+ if (!NT_STATUS_IS_OK(cli_posix_rmdir(targetcli, targetname))) {
d_printf("Failed to unlink directory %s. %s\n", targetname, cli_errstr(cli));
} else {
d_printf("posix_rmdir deleted directory %s\n", targetname);
fnum = atoi(buf);
/* We really should use the targetcli here.... */
- if (!cli_close(cli, fnum)) {
+ if (!NT_STATUS_IS_OK(cli_close(cli, fnum))) {
d_printf("close %d: %s\n", fnum, cli_errstr(cli));
return 1;
}
uint16 major, minor;
uint32 caplow, caphigh;
char *caps;
+ NTSTATUS status;
if (!SERVER_HAS_UNIX_CIFS(cli)) {
d_printf("Server doesn't support UNIX CIFS extensions.\n");
return 1;
}
- if (!cli_unix_extensions_version(cli, &major, &minor, &caplow, &caphigh)) {
- d_printf("Can't get UNIX CIFS extensions version from server.\n");
+ status = cli_unix_extensions_version(cli, &major, &minor, &caplow,
+ &caphigh);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("Can't get UNIX CIFS extensions version from "
+ "server: %s\n", nt_errstr(status));
return 1;
}
len = (uint64_t)strtol(buf, (char **)NULL, 16);
- if (!cli_posix_lock(cli, fnum, start, len, true, lock_type)) {
+ 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));
}
len = (uint64_t)strtol(buf, (char **)NULL, 16);
- if (!cli_posix_unlock(cli, fnum, start, len)) {
+ if (!NT_STATUS_IS_OK(cli_posix_unlock(cli, fnum, start, len))) {
d_printf("unlock failed %d: %s\n", fnum, cli_errstr(cli));
}
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, mask, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) {
d_printf("rmdir %s: %s\n", mask, cli_errstr(cli));
return 1;
}
- if (!cli_rmdir(targetcli, targetname)) {
+ if (!NT_STATUS_IS_OK(cli_rmdir(targetcli, targetname))) {
d_printf("%s removing remote directory file %s\n",
cli_errstr(targetcli),mask);
}
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, oldname, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, oldname, &targetcli, &targetname)) {
d_printf("link %s: %s\n", oldname, cli_errstr(cli));
return 1;
}
return 1;
}
- if (!cli_unix_hardlink(targetcli, targetname, newname)) {
+ if (!NT_STATUS_IS_OK(cli_posix_hardlink(targetcli, targetname, newname))) {
d_printf("%s linking files (%s -> %s)\n", cli_errstr(targetcli), newname, oldname);
return 1;
}
return 0;
}
+/****************************************************************************
+ UNIX readlink.
+****************************************************************************/
+
+static int cmd_readlink(void)
+{
+ TALLOC_CTX *ctx = talloc_tos();
+ char *name= NULL;
+ char *buf = NULL;
+ char *targetname = NULL;
+ char linkname[PATH_MAX+1];
+ struct cli_state *targetcli;
+
+ if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
+ d_printf("readlink <name>\n");
+ return 1;
+ }
+ name = talloc_asprintf(ctx,
+ "%s%s",
+ client_get_cur_dir(),
+ buf);
+ if (!name) {
+ return 1;
+ }
+
+ if (!cli_resolve_path(ctx, "", auth_info, cli, name, &targetcli, &targetname)) {
+ d_printf("readlink %s: %s\n", name, cli_errstr(cli));
+ return 1;
+ }
+
+ if (!SERVER_HAS_UNIX_CIFS(targetcli)) {
+ d_printf("Server doesn't support UNIX CIFS calls.\n");
+ return 1;
+ }
+
+ if (!NT_STATUS_IS_OK(cli_posix_readlink(targetcli, name,
+ linkname, PATH_MAX+1))) {
+ d_printf("%s readlink on file %s\n",
+ cli_errstr(targetcli), name);
+ return 1;
+ }
+
+ d_printf("%s -> %s\n", name, linkname);
+
+ return 0;
+}
+
+
/****************************************************************************
UNIX symlink.
****************************************************************************/
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, oldname, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, oldname, &targetcli, &targetname)) {
d_printf("link %s: %s\n", oldname, cli_errstr(cli));
return 1;
}
return 1;
}
- if (!cli_unix_symlink(targetcli, targetname, newname)) {
+ if (!NT_STATUS_IS_OK(cli_posix_symlink(targetcli, targetname, newname))) {
d_printf("%s symlinking files (%s -> %s)\n",
cli_errstr(targetcli), newname, targetname);
return 1;
mode = (mode_t)strtol(buf, NULL, 8);
- if (!cli_resolve_path(ctx, "", cli, src, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetname)) {
d_printf("chmod %s: %s\n", src, cli_errstr(cli));
return 1;
}
return 1;
}
- if (!cli_unix_chmod(targetcli, targetname, mode)) {
+ if (!NT_STATUS_IS_OK(cli_posix_chmod(targetcli, targetname, mode))) {
d_printf("%s chmod file %s 0%o\n",
cli_errstr(targetcli), src, (unsigned int)mode);
return 1;
uint16 num_file_acls = 0;
uint16 num_dir_acls = 0;
uint16 i;
+ NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&name,NULL)) {
d_printf("getfacl filename\n");
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, src, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetname)) {
d_printf("stat %s: %s\n", src, cli_errstr(cli));
return 1;
}
return 1;
}
- if (!cli_unix_extensions_version(targetcli, &major, &minor,
- &caplow, &caphigh)) {
- d_printf("Can't get UNIX CIFS version from server.\n");
+ status = cli_unix_extensions_version(targetcli, &major, &minor,
+ &caplow, &caphigh);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("Can't get UNIX CIFS version from server: %s.\n",
+ nt_errstr(status));
return 1;
}
return 1;
}
- if (!cli_unix_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);
return 1;
}
- if (!cli_unix_getfacl(targetcli, targetname, &rb_size, &retbuf)) {
+ if (!NT_STATUS_IS_OK(cli_posix_getfacl(targetcli, targetname, ctx, &rb_size, &retbuf))) {
d_printf("%s getfacl file %s\n",
cli_errstr(targetcli), src);
return 1;
}
/* ToDo : Print out the ACL values. */
- if (SVAL(retbuf,0) != SMB_POSIX_ACL_VERSION || rb_size < 6) {
+ if (rb_size < 6 || SVAL(retbuf,0) != SMB_POSIX_ACL_VERSION) {
d_printf("getfacl file %s, unknown POSIX acl version %u.\n",
src, (unsigned int)CVAL(retbuf,0) );
- SAFE_FREE(retbuf);
return 1;
}
src,
(unsigned int)(SMB_POSIX_ACL_HEADER_SIZE + SMB_POSIX_ACL_ENTRY_SIZE*(num_file_acls+num_dir_acls)),
(unsigned int)rb_size);
-
- SAFE_FREE(retbuf);
return 1;
}
d_printf("# file: %s\n", src);
- d_printf("# owner: %u\n# group: %u\n", (unsigned int)sbuf.st_uid, (unsigned int)sbuf.st_gid);
+ d_printf("# owner: %u\n# group: %u\n", (unsigned int)sbuf.st_ex_uid, (unsigned int)sbuf.st_ex_gid);
if (num_file_acls == 0 && num_dir_acls == 0) {
d_printf("No acls found.\n");
d_printf("%s\n", perms_to_string(permstring, perms));
}
- SAFE_FREE(retbuf);
return 0;
}
fstring mode_str;
SMB_STRUCT_STAT sbuf;
struct tm *lt;
+ time_t tmp_time;
if (!next_token_talloc(ctx, &cmd_ptr,&name,NULL)) {
d_printf("stat file\n");
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, src, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetname)) {
d_printf("stat %s: %s\n", src, cli_errstr(cli));
return 1;
}
return 1;
}
- if (!cli_unix_stat(targetcli, targetname, &sbuf)) {
+ if (!NT_STATUS_IS_OK(cli_posix_stat(targetcli, targetname, &sbuf))) {
d_printf("%s stat file %s\n",
cli_errstr(targetcli), src);
return 1;
/* Print out the stat values. */
d_printf("File: %s\n", src);
d_printf("Size: %-12.0f\tBlocks: %u\t%s\n",
- (double)sbuf.st_size,
- (unsigned int)sbuf.st_blocks,
- filetype_to_str(sbuf.st_mode));
+ (double)sbuf.st_ex_size,
+ (unsigned int)sbuf.st_ex_blocks,
+ filetype_to_str(sbuf.st_ex_mode));
#if defined(S_ISCHR) && defined(S_ISBLK)
- if (S_ISCHR(sbuf.st_mode) || S_ISBLK(sbuf.st_mode)) {
+ if (S_ISCHR(sbuf.st_ex_mode) || S_ISBLK(sbuf.st_ex_mode)) {
d_printf("Inode: %.0f\tLinks: %u\tDevice type: %u,%u\n",
- (double)sbuf.st_ino,
- (unsigned int)sbuf.st_nlink,
- unix_dev_major(sbuf.st_rdev),
- unix_dev_minor(sbuf.st_rdev));
+ (double)sbuf.st_ex_ino,
+ (unsigned int)sbuf.st_ex_nlink,
+ unix_dev_major(sbuf.st_ex_rdev),
+ unix_dev_minor(sbuf.st_ex_rdev));
} else
#endif
d_printf("Inode: %.0f\tLinks: %u\n",
- (double)sbuf.st_ino,
- (unsigned int)sbuf.st_nlink);
+ (double)sbuf.st_ex_ino,
+ (unsigned int)sbuf.st_ex_nlink);
d_printf("Access: (0%03o/%s)\tUid: %u\tGid: %u\n",
- ((int)sbuf.st_mode & 0777),
- unix_mode_to_str(mode_str, sbuf.st_mode),
- (unsigned int)sbuf.st_uid,
- (unsigned int)sbuf.st_gid);
+ ((int)sbuf.st_ex_mode & 0777),
+ unix_mode_to_str(mode_str, sbuf.st_ex_mode),
+ (unsigned int)sbuf.st_ex_uid,
+ (unsigned int)sbuf.st_ex_gid);
- lt = localtime(&sbuf.st_atime);
+ tmp_time = convert_timespec_to_time_t(sbuf.st_ex_atime);
+ lt = localtime(&tmp_time);
if (lt) {
strftime(mode_str, sizeof(mode_str), "%Y-%m-%d %T %z", lt);
} else {
}
d_printf("Access: %s\n", mode_str);
- lt = localtime(&sbuf.st_mtime);
+ tmp_time = convert_timespec_to_time_t(sbuf.st_ex_mtime);
+ lt = localtime(&tmp_time);
if (lt) {
strftime(mode_str, sizeof(mode_str), "%Y-%m-%d %T %z", lt);
} else {
}
d_printf("Modify: %s\n", mode_str);
- lt = localtime(&sbuf.st_ctime);
+ tmp_time = convert_timespec_to_time_t(sbuf.st_ex_ctime);
+ lt = localtime(&tmp_time);
if (lt) {
strftime(mode_str, sizeof(mode_str), "%Y-%m-%d %T %z", lt);
} else {
if (!src) {
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, src, &targetcli, &targetname) ) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetname) ) {
d_printf("chown %s: %s\n", src, cli_errstr(cli));
return 1;
}
return 1;
}
- if (!cli_unix_chown(targetcli, targetname, uid, gid)) {
+ if (!NT_STATUS_IS_OK(cli_posix_chown(targetcli, targetname, uid, gid))) {
d_printf("%s chown file %s uid=%d, gid=%d\n",
cli_errstr(targetcli), src, (int)uid, (int)gid);
return 1;
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, src, &targetcli, &targetsrc)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetsrc)) {
d_printf("rename %s: %s\n", src, cli_errstr(cli));
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, dest, &targetcli, &targetdest)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, dest, &targetcli, &targetdest)) {
d_printf("rename %s: %s\n", dest, cli_errstr(cli));
return 1;
}
- if (!cli_rename(targetcli, targetsrc, targetdest)) {
+ if (!NT_STATUS_IS_OK(cli_rename(targetcli, targetsrc, targetdest))) {
d_printf("%s renaming files %s -> %s \n",
cli_errstr(targetcli),
targetsrc,
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, src, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetname)) {
d_printf("hardlink %s: %s\n", src, cli_errstr(cli));
return 1;
}
- if (!cli_nt_hardlink(targetcli, targetname, dest)) {
+ 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));
return 1;
}
SMB_STRUCT_STAT sbuf;
ok = next_token_talloc(ctx, &cmd_ptr,&buf,NULL);
- if (ok && (sys_stat(buf,&sbuf) == 0)) {
- newer_than = sbuf.st_mtime;
+ if (ok && (sys_stat(buf, &sbuf, false) == 0)) {
+ newer_than = convert_timespec_to_time_t(sbuf.st_ex_mtime);
DEBUG(1,("Getting files newer than %s",
time_to_asc(newer_than)));
} else {
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) {
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;
}
return 1;
}
- if (!file_exist(local_name, &st)) {
+ if (!file_exist_stat(local_name, &st, false)) {
d_printf("%s does not exist\n", local_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;
static bool browse_host_rpc(bool sort)
{
NTSTATUS status;
- struct rpc_pipe_client *pipe_hnd;
+ struct rpc_pipe_client *pipe_hnd = NULL;
TALLOC_CTX *frame = talloc_stackframe();
WERROR werr;
struct srvsvc_NetShareInfoCtr info_ctr;
static int cmd_list_connect(void)
{
- cli_cm_display();
+ cli_cm_display(cli);
return 0;
}
struct cli_state *targetcli;
char *targetpath;
- if (!cli_resolve_path(ctx, "", cli, client_get_cur_dir(),
+ 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));
return 1;
{"q",cmd_quit,"logoff the server",{COMPL_NONE,COMPL_NONE}},
{"queue",cmd_queue,"show the print queue",{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}},
{"reget",cmd_reget,"<remote name> [local name] get a file restarting at end of local file",{COMPL_REMOTE,COMPL_LOCAL}},
/* establish the connection if not already */
if (!cli) {
- cli = cli_cm_open(talloc_tos(), NULL, desthost,
- service, true, smb_encrypt);
+ 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) {
return 1;
}
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, CLI_DIRSEP_STR);
+ tmp = talloc_asprintf_append(tmp, "%s", CLI_DIRSEP_STR);
}
if (!tmp) {
TALLOC_FREE(ctx);
goto cleanup;
}
- if (!cli_resolve_path(ctx, "", cli, dirmask, &targetcli, &targetpath)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, dirmask, &targetcli, &targetpath)) {
goto cleanup;
}
if (cli_list(targetcli, targetpath, aDIR | aSYSTEM | aHIDDEN,
again:
- if (cli->fd == -1)
+ if (cli->fd < 0 || cli->fd >= FD_SETSIZE) {
+ errno = EBADF;
return;
+ }
FD_ZERO(&fds);
FD_SET(cli->fd,&fds);
/* 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;
int rc = 0;
cli = cli_cm_open(talloc_tos(), NULL,
- desthost, service, true, smb_encrypt);
+ have_ip ? dest_ss_str : desthost,
+ service, auth_info, true, smb_encrypt,
+ max_protocol, port, name_type);
if (!cli) {
return 1;
}
if (base_directory && *base_directory) {
rc = do_cd(base_directory);
if (rc) {
- cli_cm_shutdown();
+ cli_shutdown(cli);
return rc;
}
}
process_stdin();
}
- cli_cm_shutdown();
+ cli_shutdown(cli);
return rc;
}
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);
+ query_host, "IPC$", auth_info, true, smb_encrypt,
+ max_protocol, port, name_type);
if (!cli)
return 1;
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;
+ /* Ensure that the host can do IPv4 */
+
+ if (!interpret_addr(query_host)) {
+ struct sockaddr_storage ss;
+ 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
else but port 139... */
- cli_cm_shutdown();
- cli_cm_set_port( 139 );
+ cli_shutdown(cli);
cli = cli_cm_open(talloc_tos(), NULL,
- query_host, "IPC$", true, smb_encrypt);
+ query_host, "IPC$", auth_info, true, smb_encrypt,
+ max_protocol, 139, name_type);
}
if (cli == NULL) {
list_servers(lp_workgroup());
- cli_cm_shutdown();
+ cli_shutdown(cli);
return(0);
}
/* do we already have a connection? */
if (!cli) {
cli = cli_cm_open(talloc_tos(), NULL,
- desthost, service, true, smb_encrypt);
+ have_ip ? dest_ss_str : desthost,
+ service, auth_info, true, smb_encrypt,
+ max_protocol, port, name_type);
if (!cli)
return 1;
}
if (base_directory && *base_directory) {
ret = do_cd(base_directory);
if (ret) {
- cli_cm_shutdown();
+ cli_shutdown(cli);
return ret;
}
}
ret=process_tar();
- cli_cm_shutdown();
+ cli_shutdown(cli);
return(ret);
}
Handle a message operation.
****************************************************************************/
-static int do_message_op(void)
+static int do_message_op(struct user_auth_info *a_info)
{
struct sockaddr_storage ss;
struct nmb_name called, calling;
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;
msg_port = port ? port : 139;
- if (!(cli=cli_initialise()) || (cli_set_port(cli, msg_port) != msg_port)) {
+ 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);
if (!NT_STATUS_IS_OK(status)) {
if (!cli_session_request(cli, &calling, &called)) {
d_printf("session request failed\n");
- cli_cm_shutdown();
+ cli_shutdown(cli);
return 1;
}
- send_message();
- cli_cm_shutdown();
+ send_message(get_cmdline_auth_info_username(a_info));
+ cli_shutdown(cli);
return 0;
}
int opt;
char *query_host = NULL;
bool message = false;
- char *term_code = NULL;
static const char *new_name_resolve_order = NULL;
poptContext pc;
char *p;
{ "ip-address", 'I', POPT_ARG_STRING, NULL, 'I', "Use this IP to connect to", "IP" },
{ "stderr", 'E', POPT_ARG_NONE, NULL, 'E', "Write messages to stderr instead of stdout" },
{ "list", 'L', POPT_ARG_STRING, NULL, 'L', "Get a list of shares available on a host", "HOST" },
- { "terminal", 't', POPT_ARG_STRING, NULL, 't', "Terminal I/O code {sjis|euc|jis7|jis8|junet|hex}", "CODE" },
{ "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" },
exit(ENOMEM);
}
-#ifdef KANJI
- term_code = talloc_strdup(frame,KANJI);
-#else /* KANJI */
- term_code = talloc_strdup(frame,"");
-#endif /* KANJI */
- if (!term_code) {
- exit(ENOMEM);
- }
-
/* initialize the workgroup name so we can determine whether or
not it was set by a command line option */
load_case_tables();
+ auth_info = user_auth_info_init(frame);
+ if (auth_info == NULL) {
+ exit(1);
+ }
+ popt_common_set_auth_info(auth_info);
+
/* skip argv(0) */
pc = poptGetContext("smbclient", argc, (const char **) argv, long_options, 0);
poptSetOtherOptionHelp(pc, "service <password>");
}
/* if the service has already been retrieved then check if we have also a password */
- if (service_opt && (!get_cmdline_auth_info_got_pass()) && poptPeekArg(pc)) {
- set_cmdline_auth_info_password(poptGetArg(pc));
+ if (service_opt
+ && (!get_cmdline_auth_info_got_pass(auth_info))
+ && poptPeekArg(pc)) {
+ set_cmdline_auth_info_password(auth_info,
+ poptGetArg(pc));
}
switch (opt) {
* to port 139 instead of port 445. srl,crh
*/
name_type = 0x03;
- cli_cm_set_dest_name_type( name_type );
desthost = talloc_strdup(frame,poptGetOptArg(pc));
if (!desthost) {
exit(ENOMEM);
}
if( !port )
- cli_cm_set_port( 139 );
+ port = 139;
message = true;
break;
case 'I':
exit(1);
}
have_ip = true;
-
- cli_cm_set_dest_ss(&dest_ss);
+ print_sockaddr(dest_ss_str, sizeof(dest_ss_str), &dest_ss);
}
break;
case 'E':
exit(ENOMEM);
}
break;
- case 't':
- term_code = talloc_strdup(frame,poptGetOptArg(pc));
- if (!term_code) {
- exit(ENOMEM);
- }
- break;
case 'm':
max_protocol = interpret_protocol(poptGetOptArg(pc), max_protocol);
break;
}
/* if the service has already been retrieved then check if we have also a password */
- if (service_opt && !get_cmdline_auth_info_got_pass() && poptPeekArg(pc)) {
- set_cmdline_auth_info_password(poptGetArg(pc));
+ if (service_opt
+ && !get_cmdline_auth_info_got_pass(auth_info)
+ && poptPeekArg(pc)) {
+ set_cmdline_auth_info_password(auth_info,
+ poptGetArg(pc));
}
- /* check for the -P option */
-
- if ( port != 0 )
- cli_cm_set_port( port );
-
/*
* Don't load debug level from smb.conf. It should be
* set by cmdline arg or remain default (0)
argv[0], get_dyn_CONFIGFILE());
}
- if (get_cmdline_auth_info_use_machine_account() &&
- !set_cmdline_auth_info_machine_account_creds()) {
+ if (get_cmdline_auth_info_use_machine_account(auth_info) &&
+ !set_cmdline_auth_info_machine_account_creds(auth_info)) {
exit(-1);
}
calling_name = talloc_strdup(frame, global_myname() );
}
- smb_encrypt = get_cmdline_auth_info_smb_encrypt();
+ smb_encrypt = get_cmdline_auth_info_smb_encrypt(auth_info);
if (!init_names()) {
fprintf(stderr, "init_names() failed\n");
exit(1);
poptFreeContext(pc);
- /* Store the username and password for dfs support */
-
- cli_cm_set_credentials();
+ DEBUG(3,("Client started (version %s).\n", samba_version_string()));
- DEBUG(3,("Client started (version %s).\n", SAMBA_VERSION_STRING));
+ /* Ensure we have a password (or equivalent). */
+ set_cmdline_auth_info_getpass(auth_info);
if (tar_type) {
if (cmdstr)
*p = 0;
p++;
sscanf(p, "%x", &name_type);
- cli_cm_set_dest_name_type( name_type );
}
return do_host_query(qhost);
}
if (message) {
- return do_message_op();
+ return do_message_op(auth_info);
}
if (process(base_directory)) {