struct cli_state *cli;
extern BOOL in_client;
+static int port = SMB_PORT;
pstring cur_dir = "\\";
pstring cd_path = "";
static pstring service;
static pstring desthost;
extern pstring global_myname;
-extern pstring myhostname;
static pstring password;
static pstring username;
static pstring workgroup;
static char *cmdstr;
static BOOL got_pass;
+static int io_bufsize = 64512;
extern struct in_addr ipzero;
-extern pstring scope;
static int name_type = 0x20;
int put_total_time_ms = 0;
/* totals globals */
-int dir_total = 0;
+static double dir_total;
#define USENMB
-#define CNV_LANG(s) dos_to_unix(s,False)
-#define CNV_INPUT(s) unix_to_dos(s,True)
-
-
/****************************************************************************
write to a local file with CR/LF->LF translation if appropriate. return the
number taken from the buffer. This may not equal the number written.
return(fread(b,size,n,f));
i = 0;
- while (i < n) {
+ while (i < (n - 1) && (i < BUFFER_SIZE)) {
if ((c = getc(f)) == EOF) {
break;
}
if (c == '\n') { /* change all LFs to CR/LF */
b[i++] = '\r';
- n++;
}
- if(i < n)
- b[i++] = c;
+ b[i++] = c;
}
return(i);
msg[l] = c;
}
+ /*
+ * The message is in UNIX codepage format. Convert to
+ * DOS before sending.
+ */
+
+ unix_to_dos(msg, True);
+
if (!cli_message_text(cli, msg, l, grp_id)) {
printf("SMBsendtxt failed (%s)\n",cli_errstr(cli));
return;
****************************************************************************/
static void cmd_pwd(void)
{
- DEBUG(0,("Current directory is %s",CNV_LANG(service)));
- DEBUG(0,("%s\n",CNV_LANG(cur_dir)));
+ DEBUG(0,("Current directory is %s",service));
+ DEBUG(0,("%s\n",cur_dir));
}
if (next_token(NULL,buf,NULL,sizeof(buf)))
do_cd(buf);
else
- DEBUG(0,("Current directory is %s\n",CNV_LANG(cur_dir)));
+ DEBUG(0,("Current directory is %s\n",cur_dir));
}
if (finfo->mode & aDIR) return(True);
if (*fileselection &&
- !mask_match(finfo->name,fileselection,False,False)) {
+ !mask_match(finfo->name,fileselection,False)) {
DEBUG(3,("match_match %s failed\n", finfo->name));
return False;
}
{
if (do_this_one(finfo)) {
time_t t = finfo->mtime; /* the time is assumed to be passed as GMT */
- DEBUG(0,(" %-30s%7.7s%8.0f %s",
- CNV_LANG(finfo->name),
+ DEBUG(0,(" %-30s%7.7s %8.0f %s",
+ finfo->name,
attrib_string(finfo->mode),
(double)finfo->size,
asctime(LocalTime(&t))));
static BOOL do_list_recurse;
static BOOL do_list_dirs;
-static int do_list_attr;
+static char *do_list_queue = 0;
+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)(file_info *);
+/****************************************************************************
+functions for do_list_queue
+ ****************************************************************************/
+
+/*
+ * The do_list_queue is a NUL-separated list of strings stored in a
+ * char*. Since this is a FIFO, we keep track of the beginning and
+ * ending locations of the data in the queue. When we overflow, we
+ * double the size of the char*. When the start of the data passes
+ * the midpoint, we move everything back. This is logically more
+ * complex than a linked list, but easier from a memory management
+ * angle. In any memory error condition, do_list_queue is reset.
+ * Functions check to ensure that do_list_queue is non-NULL before
+ * accessing it.
+ */
+static void reset_do_list_queue(void)
+{
+ if (do_list_queue)
+ {
+ free(do_list_queue);
+ }
+ do_list_queue = 0;
+ do_list_queue_size = 0;
+ do_list_queue_start = 0;
+ do_list_queue_end = 0;
+}
+
+static void init_do_list_queue(void)
+{
+ reset_do_list_queue();
+ do_list_queue_size = 1024;
+ do_list_queue = malloc(do_list_queue_size);
+ if (do_list_queue == 0) {
+ DEBUG(0,("malloc fail for size %d\n",
+ (int)do_list_queue_size));
+ reset_do_list_queue();
+ } else {
+ memset(do_list_queue, 0, do_list_queue_size);
+ }
+}
+
+static void adjust_do_list_queue(void)
+{
+ /*
+ * If the starting point of the queue is more than half way through,
+ * move everything toward the beginning.
+ */
+ if (do_list_queue && (do_list_queue_start == do_list_queue_end))
+ {
+ DEBUG(4,("do_list_queue is empty\n"));
+ do_list_queue_start = do_list_queue_end = 0;
+ *do_list_queue = '\0';
+ }
+ else if (do_list_queue_start > (do_list_queue_size / 2))
+ {
+ DEBUG(4,("sliding do_list_queue backward\n"));
+ memmove(do_list_queue,
+ do_list_queue + do_list_queue_start,
+ do_list_queue_end - do_list_queue_start);
+ do_list_queue_end -= do_list_queue_start;
+ do_list_queue_start = 0;
+ }
+
+}
+
+static void add_to_do_list_queue(const char* entry)
+{
+ long new_end = do_list_queue_end + ((long)strlen(entry)) + 1;
+ while (new_end > do_list_queue_size)
+ {
+ do_list_queue_size *= 2;
+ DEBUG(4,("enlarging do_list_queue to %d\n",
+ (int)do_list_queue_size));
+ do_list_queue = Realloc(do_list_queue, do_list_queue_size);
+ if (! do_list_queue) {
+ DEBUG(0,("failure enlarging do_list_queue to %d bytes\n",
+ (int)do_list_queue_size));
+ reset_do_list_queue();
+ }
+ else
+ {
+ memset(do_list_queue + do_list_queue_size / 2,
+ 0, do_list_queue_size / 2);
+ }
+ }
+ if (do_list_queue)
+ {
+ pstrcpy(do_list_queue + do_list_queue_end, entry);
+ do_list_queue_end = new_end;
+ DEBUG(4,("added %s to do_list_queue (start=%d, end=%d)\n",
+ entry, (int)do_list_queue_start, (int)do_list_queue_end));
+ }
+}
+
+static char *do_list_queue_head(void)
+{
+ return do_list_queue + do_list_queue_start;
+}
+
+static void remove_do_list_queue_head(void)
+{
+ if (do_list_queue_end > do_list_queue_start)
+ {
+ do_list_queue_start += strlen(do_list_queue_head()) + 1;
+ adjust_do_list_queue();
+ DEBUG(4,("removed head of do_list_queue (start=%d, end=%d)\n",
+ (int)do_list_queue_start, (int)do_list_queue_end));
+ }
+}
+
+static int do_list_queue_empty(void)
+{
+ return (! (do_list_queue && *do_list_queue));
+}
+
/****************************************************************************
a helper for do_list
****************************************************************************/
-static void do_list_helper(file_info *f, const char *mask)
+static void do_list_helper(file_info *f, const char *mask, void *state)
{
if (f->mode & aDIR) {
if (do_list_dirs && do_this_one(f)) {
if (!p) return;
p[1] = 0;
pstrcat(mask2, f->name);
- if (do_list_fn == display_finfo) {
- DEBUG(0,("\n%s\n",CNV_LANG(mask2)));
- }
pstrcat(mask2,"\\*");
- do_list(mask2, do_list_attr, do_list_fn, True, True);
+ add_to_do_list_queue(mask2);
}
return;
}
****************************************************************************/
void do_list(const char *mask,uint16 attribute,void (*fn)(file_info *),BOOL rec, BOOL dirs)
{
+ static int in_do_list = 0;
+
+ if (in_do_list && rec)
+ {
+ fprintf(stderr, "INTERNAL ERROR: do_list called recursively when the recursive flag is true\n");
+ exit(1);
+ }
+
+ in_do_list = 1;
+
do_list_recurse = rec;
do_list_dirs = dirs;
do_list_fn = fn;
- do_list_attr = attribute;
- cli_list(cli, mask, attribute, do_list_helper);
+ if (rec)
+ {
+ init_do_list_queue();
+ add_to_do_list_queue(mask);
+
+ while (! do_list_queue_empty())
+ {
+ /*
+ * Need to copy head so that it doesn't become
+ * invalid inside the call to cli_list. This
+ * would happen if the list were expanded
+ * during the call.
+ * Fix from E. Jay Berkenbilt (ejb@ql.org)
+ */
+ pstring head;
+ pstrcpy(head, do_list_queue_head());
+ cli_list(cli, head, attribute, do_list_helper, NULL);
+ remove_do_list_queue_head();
+ if ((! do_list_queue_empty()) && (fn == display_finfo))
+ {
+ char* next_file = do_list_queue_head();
+ char* save_ch = 0;
+ if ((strlen(next_file) >= 2) &&
+ (next_file[strlen(next_file) - 1] == '*') &&
+ (next_file[strlen(next_file) - 2] == '\\'))
+ {
+ save_ch = next_file +
+ strlen(next_file) - 2;
+ *save_ch = '\0';
+ }
+ DEBUG(0,("\n%s\n",next_file));
+ if (save_ch)
+ {
+ *save_ch = '\\';
+ }
+ }
+ }
+ }
+ else
+ {
+ if (cli_list(cli, mask, attribute, do_list_helper, NULL) == -1)
+ {
+ DEBUG(0, ("%s listing %s\n", cli_errstr(cli), mask));
+ }
+ }
+
+ in_do_list = 0;
+ reset_do_list_queue();
}
/****************************************************************************
do_dskattr();
- DEBUG(3, ("Total bytes listed: %d\n", dir_total));
+ DEBUG(3, ("Total bytes listed: %.0f\n", dir_total));
}
do_dskattr();
- DEBUG(0, ("Total number of bytes: %d\n", dir_total));
+ DEBUG(0, ("Total number of bytes: %.0f\n", dir_total));
}
BOOL newhandle = False;
char *data;
struct timeval tp_start;
- int read_size = 65520;
+ int read_size = io_bufsize;
uint16 attr;
size_t size;
off_t nread = 0;
fnum = cli_open(cli, rname, O_RDONLY, DENY_NONE);
if (fnum == -1) {
- DEBUG(0,("%s opening remote file %s\n",cli_errstr(cli),CNV_LANG(rname)));
+ DEBUG(0,("%s opening remote file %s\n",cli_errstr(cli),rname));
return;
}
if(!strcmp(lname,"-")) {
handle = fileno(stdout);
} else {
- handle = open(lname,O_WRONLY|O_CREAT|O_TRUNC,0644);
+ handle = sys_open(lname,O_WRONLY|O_CREAT|O_TRUNC,0644);
newhandle = True;
}
if (handle < 0) {
}
- if (!cli_getattrE(cli, fnum, &attr, &size, NULL, NULL, NULL)) {
- DEBUG(0,("getattrE: %s\n",cli_errstr(cli)));
+ if (!cli_qfileinfo(cli, fnum,
+ &attr, &size, NULL, NULL, NULL, NULL, NULL) &&
+ !cli_getattrE(cli, fnum,
+ &attr, &size, NULL, NULL, NULL)) {
+ DEBUG(0,("getattrib: %s\n",cli_errstr(cli)));
return;
}
-
DEBUG(2,("getting file %s of size %.0f as %s ",
lname, (double)size, lname));
- data = (char *)malloc(read_size);
+ if(!(data = (char *)malloc(read_size))) {
+ DEBUG(0,("malloc fail for size %d\n", read_size));
+ cli_close(cli, fnum);
+ return;
+ }
while (1) {
int n = cli_read(cli, fnum, data, nread, read_size);
nread += n;
}
+
+ if (nread < size) {
+ DEBUG (0, ("Short read when getting file %s. Only got %ld bytes.\n",
+ rname, (long)nread));
+ }
+
+ free(data);
if (!cli_close(cli, fnum)) {
DEBUG(0,("Error %s closing remote file\n",cli_errstr(cli)));
get_total_time_ms += this_time;
get_total_size += nread;
- DEBUG(2,("(%g kb/s) (average %g kb/s)\n",
+ DEBUG(2,("(%3.1f kb/s) (average %3.1f kb/s)\n",
nread / (1.024*this_time + 1.0e-4),
get_total_size / (1.024*get_total_time_ms)));
}
if (finfo->mode & aDIR)
slprintf(quest,sizeof(pstring)-1,
- "Get directory %s? ",CNV_LANG(finfo->name));
+ "Get directory %s? ",finfo->name);
else
slprintf(quest,sizeof(pstring)-1,
- "Get file %s? ",CNV_LANG(finfo->name));
+ "Get file %s? ",finfo->name);
if (prompt && !yesno(quest)) return;
strlower(finfo->name);
if (!directory_exist(finfo->name,NULL) &&
- dos_mkdir(finfo->name,0777) != 0) {
- DEBUG(0,("failed to create directory %s\n",CNV_LANG(finfo->name)));
+ mkdir(finfo->name,0777) != 0) {
+ DEBUG(0,("failed to create directory %s\n",finfo->name));
pstrcpy(cur_dir,saved_curdir);
return;
}
- if (dos_chdir(finfo->name) != 0) {
- DEBUG(0,("failed to chdir to directory %s\n",CNV_LANG(finfo->name)));
+ if (chdir(finfo->name) != 0) {
+ DEBUG(0,("failed to chdir to directory %s\n",finfo->name));
pstrcpy(cur_dir,saved_curdir);
return;
}
fstrcat(rname,"\\");
slprintf(tmpname,
sizeof(fstring)-1,
- "%s/smbmore.%d",tmpdir(),(int)getpid());
+ "%s/smbmore.%d",tmpdir(),(int)sys_getpid());
fstrcpy(lname,tmpname);
if (!next_token(NULL,rname+strlen(rname),NULL,sizeof(rname)-strlen(rname))) {
{
if (!cli_mkdir(cli, name)) {
DEBUG(0,("%s making remote directory %s\n",
- cli_errstr(cli),CNV_LANG(name)));
+ cli_errstr(cli),name));
return(False);
}
/****************************************************************************
-make a directory of name "name"
+ Exit client.
****************************************************************************/
static void cmd_quit(void)
{
FILE *f;
int nread=0;
char *buf=NULL;
- int maxwrite=65520;
+ int maxwrite=io_bufsize;
struct timeval tp_start;
GetTimeOfDay(&tp_start);
- fnum = cli_open(cli, rname, O_WRONLY|O_CREAT|O_TRUNC, DENY_NONE);
+ fnum = cli_open(cli, rname, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE);
if (fnum == -1) {
- DEBUG(0,("%s opening remote file %s\n",cli_errstr(cli),CNV_LANG(rname)));
+ DEBUG(0,("%s opening remote file %s\n",cli_errstr(cli),rname));
return;
}
f = stdin;
/* size of file is not known */
} else {
- f = fopen(lname,"r");
+ f = sys_fopen(lname,"r");
}
if (!f) {
DEBUG(1,("putting file %s as %s ",lname,
- CNV_LANG(rname)));
+ rname));
buf = (char *)malloc(maxwrite);
while (!feof(f)) {
int ret;
if ((n = readfile(buf,1,n,f)) < 1) {
- DEBUG(0,("Error reading local file\n"));
+ if((n == 0) && feof(f))
+ break; /* Empty local file. */
+
+ DEBUG(0,("Error reading local file: %s\n", strerror(errno) ));
break;
}
}
if (!cli_close(cli, fnum)) {
- DEBUG(0,("%s closing remote file %s\n",cli_errstr(cli),CNV_LANG(rname)));
+ DEBUG(0,("%s closing remote file %s\n",cli_errstr(cli),rname));
fclose(f);
if (buf) free(buf);
return;
put_total_time_ms += this_time;
put_total_size += nread;
- DEBUG(1,("(%g kb/s) (average %g kb/s)\n",
+ DEBUG(1,("(%3.1f kb/s) (average %3.1f kb/s)\n",
nread / (1.024*this_time + 1.0e-4),
put_total_size / (1.024*put_total_time_ms)));
}
{
pstring s;
while (!feof(f)) {
- if (fscanf(f,"%s",s) != 1) return(False);
- trim_string(s,"./",NULL);
+ if (!fgets(s,sizeof(s),f)) return(False);
+ trim_string(s,"./","\n");
if (strncmp(s,name,strlen(name)) != 0) {
pstrcpy(name,s);
return(True);
FILE *f;
slprintf(tmpname,sizeof(pstring)-1,
- "%s/ls.smb.%d",tmpdir(),(int)getpid());
+ "%s/ls.smb.%d",tmpdir(),(int)sys_getpid());
if (recurse)
slprintf(cmd,sizeof(pstring)-1,
- "find . -name \"%s\" -print > %s",p,tmpname);
+ "find . -name \"%s\" -print > %s",p,tmpname);
else
slprintf(cmd,sizeof(pstring)-1,
- "/bin/ls %s > %s",p,tmpname);
+ "find . -maxdepth 1 -name \"%s\" -print > %s",p,tmpname);
system(cmd);
- f = fopen(tmpname,"r");
+ f = sys_fopen(tmpname,"r");
if (!f) continue;
while (!feof(f)) {
pstring quest;
- if (fscanf(f,"%s",lname) != 1) break;
- trim_string(lname,"./",NULL);
+ if (!fgets(lname,sizeof(lname),f)) break;
+ trim_string(lname,"./","\n");
again1:
pstrcpy(rname,cur_dir);
pstrcat(rname,lname);
+ dos_format(rname);
if (!cli_chkpath(cli, rname) && !do_mkdir(rname)) {
pstrcat(lname,"/");
if (!seek_list(f,lname))
if (cli_printjob_del(cli, job)) {
printf("Job %d cancelled\n",job);
} else {
- printf("Error calcelling job %d : %s\n",job,cli_errstr(cli));
+ printf("Error cancelling job %d : %s\n",job,cli_errstr(cli));
}
}
pstrcpy(rname,lname);
p = strrchr(rname,'/');
if (p) {
- slprintf(rname, sizeof(rname)-1, "%s-%d", p+1, (int)getpid());
+ slprintf(rname, sizeof(rname)-1, "%s-%d", p+1, (int)sys_getpid());
}
if (strequal(lname,"-")) {
- slprintf(rname, sizeof(rname)-1, "stdin-%d", (int)getpid());
+ slprintf(rname, sizeof(rname)-1, "stdin-%d", (int)sys_getpid());
}
do_put(rname, lname);
return;
if (!cli_unlink(cli, mask)) {
- DEBUG(0,("%s deleting remote file %s\n",cli_errstr(cli),CNV_LANG(mask)));
+ DEBUG(0,("%s deleting remote file %s\n",cli_errstr(cli),mask));
}
}
do_list(mask, attribute,do_del,False,False);
}
+/****************************************************************************
+****************************************************************************/
+static void cmd_open(void)
+{
+ pstring mask;
+ fstring buf;
+
+ pstrcpy(mask,cur_dir);
+
+ if (!next_token(NULL,buf,NULL,sizeof(buf))) {
+ DEBUG(0,("del <filename>\n"));
+ return;
+ }
+ pstrcat(mask,buf);
+
+ cli_open(cli, mask, O_RDWR, DENY_ALL);
+}
+
/****************************************************************************
remove a directory
if (!cli_rmdir(cli, mask)) {
DEBUG(0,("%s removing remote directory file %s\n",
- cli_errstr(cli),CNV_LANG(mask)));
+ cli_errstr(cli),mask));
}
}
SMB_STRUCT_STAT sbuf;
ok = next_token(NULL,buf,NULL,sizeof(buf));
- if (ok && (dos_stat(buf,&sbuf) == 0)) {
+ if (ok && (sys_stat(buf,&sbuf) == 0)) {
newer_than = sbuf.st_mtime;
DEBUG(1,("Getting files newer than %s",
asctime(LocalTime(&newer_than))));
pstring d;
if (next_token(NULL,buf,NULL,sizeof(buf)))
- dos_chdir(buf);
- DEBUG(2,("the local directory is now %s\n",GetWd(d)));
+ chdir(buf);
+ DEBUG(2,("the local directory is now %s\n",sys_getwd(d)));
}
/****************************************************************************
list a share name
****************************************************************************/
-static void browse_fn(const char *name, uint32 m, const char *comment)
+static void browse_fn(const char *name, uint32 m,
+ const char *comment, void *state)
{
fstring typestr;
+
*typestr=0;
switch (m)
****************************************************************************/
static BOOL browse_host(BOOL sort)
{
+ int ret;
+
printf("\n\tSharename Type Comment\n");
printf("\t--------- ---- -------\n");
- return cli_RNetShareEnum(cli, browse_fn);
+ if((ret = cli_RNetShareEnum(cli, browse_fn, NULL)) == -1)
+ printf("Error returning browse list: %s\n", cli_errstr(cli));
+
+ return (ret != -1);
}
/****************************************************************************
list a server name
****************************************************************************/
-static void server_fn(const char *name, uint32 m, const char *comment)
+static void server_fn(const char *name, uint32 m,
+ const char *comment, void *state)
{
printf("\t%-16.16s %s\n", name, comment);
}
****************************************************************************/
static BOOL list_servers(char *wk_grp)
{
+ if (!cli->server_domain) return False;
+
printf("\n\tServer Comment\n");
printf("\t--------- -------\n");
- cli_NetServerEnum(cli, workgroup, SV_TYPE_ALL, server_fn);
+ cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_ALL, server_fn, NULL);
printf("\n\tWorkgroup Master\n");
printf("\t--------- -------\n");
- cli_NetServerEnum(cli, workgroup, SV_TYPE_DOMAIN_ENUM, server_fn);
+ cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_DOMAIN_ENUM, server_fn, NULL);
return True;
}
+#if defined(HAVE_LIBREADLINE)
+# if defined(HAVE_READLINE_HISTORY_H) || defined(HAVE_HISTORY_H)
+/****************************************************************************
+history
+****************************************************************************/
+static void cmd_history(void)
+{
+ HIST_ENTRY **hlist;
+ register int i;
+
+ hlist = history_list (); /* Get pointer to history list */
+
+ if (hlist) /* If list not empty */
+ {
+ for (i = 0; hlist[i]; i++) /* then display it */
+ DEBUG(0, ("%d: %s\n", i, hlist[i]->line));
+ }
+}
+# endif
+#endif
/* Some constants for completing filename arguments */
{"more",cmd_more,"<remote name> view a remote file with your pager",{COMPL_REMOTE,COMPL_NONE}},
{"mask",cmd_select,"<mask> mask all filenames against this",{COMPL_REMOTE,COMPL_NONE}},
{"del",cmd_del,"<mask> delete all matching files",{COMPL_REMOTE,COMPL_NONE}},
+ {"open",cmd_open,"<mask> open a file",{COMPL_REMOTE,COMPL_NONE}},
{"rm",cmd_del,"<mask> delete all matching files",{COMPL_REMOTE,COMPL_NONE}},
{"mkdir",cmd_mkdir,"<directory> make a directory",{COMPL_NONE,COMPL_NONE}},
{"md",cmd_mkdir,"<directory> make a directory",{COMPL_NONE,COMPL_NONE}},
{"setmode",cmd_setmode,"filename <setmode string> change modes of file",{COMPL_REMOTE,COMPL_NONE}},
{"help",cmd_help,"[command] give help on a command",{COMPL_NONE,COMPL_NONE}},
{"?",cmd_help,"[command] give help on a command",{COMPL_NONE,COMPL_NONE}},
+#ifdef HAVE_LIBREADLINE
+ {"history",cmd_history,"displays the command history",{COMPL_NONE,COMPL_NONE}},
+#endif
{"!",NULL,"run a shell command on the local system",{COMPL_NONE,COMPL_NONE}},
{"",NULL,NULL,{COMPL_NONE,COMPL_NONE}}
};
}
}
+#ifndef HAVE_LIBREADLINE
/****************************************************************************
wait for keyboard activity, swallowing network packets
****************************************************************************/
timeout.tv_sec = 20;
timeout.tv_usec = 0;
- sys_select(MAX(cli->fd,fileno(stdin))+1,&fds,&timeout);
-
+ sys_select_intr(MAX(cli->fd,fileno(stdin))+1,&fds,&timeout);
+
if (FD_ISSET(fileno(stdin),&fds))
return;
cli_chkpath(cli, "\\");
}
}
+#endif
/****************************************************************************
process a -c command string
cmd = p + 1;
}
- /* input language code to internal one */
- CNV_INPUT (line);
-
/* and get the first part of the command */
ptr = line;
if (!next_token(&ptr,tok,NULL,sizeof(tok))) continue;
if ((i = process_tok(tok)) >= 0) {
commands[i].fn();
} else if (i == -2) {
- DEBUG(0,("%s: command abbreviation ambiguous\n",CNV_LANG(tok)));
+ DEBUG(0,("%s: command abbreviation ambiguous\n",tok));
} else {
- DEBUG(0,("%s: command not found\n",CNV_LANG(tok)));
+ DEBUG(0,("%s: command not found\n",tok));
}
}
}
pstring line;
char *ptr;
+#ifdef HAVE_LIBREADLINE
+/* Minimal readline support, 29Jun1999, s.xenitellis@rhbnc.ac.uk */
+#ifdef PROMPTSIZE
+#undef PROMPTSIZE
+#endif
+#define PROMPTSIZE 2048
+ char prompt_str[PROMPTSIZE]; /* This holds the buffer "smb: \dir1\> " */
+
+ char *temp; /* Gets the buffer from readline() */
+ temp = (char *)NULL;
+#endif
while (!feof(stdin)) {
fstring tok;
int i;
+#ifdef HAVE_LIBREADLINE
+ if ( temp != (char *)NULL )
+ {
+ free( temp ); /* Free memory allocated every time by readline() */
+ temp = (char *)NULL;
+ }
+ slprintf( prompt_str, PROMPTSIZE - 1, "smb: %s> ", cur_dir );
+
+ temp = readline( prompt_str ); /* We read the line here */
+
+ if ( !temp )
+ break; /* EOF occured */
+
+ if ( *temp ) /* If non-empty line, save to history */
+ add_history (temp);
+
+ strncpy( line, temp, 1023 ); /* Maximum size of (pstring)line. Null is guarranteed. */
+#else
/* display a prompt */
- DEBUG(0,("smb: %s> ", CNV_LANG(cur_dir)));
+ DEBUG(0,("smb: %s> ", cur_dir));
dbgflush( );
wait_keyboard();
/* and get a response */
if (!fgets(line,1000,stdin))
break;
+#endif
- /* input language code to internal one */
- CNV_INPUT (line);
-
/* special case - first char is ! */
if (*line == '!') {
system(line + 1);
if ((i = process_tok(tok)) >= 0) {
commands[i].fn();
} else if (i == -2) {
- DEBUG(0,("%s: command abbreviation ambiguous\n",CNV_LANG(tok)));
+ DEBUG(0,("%s: command abbreviation ambiguous\n",tok));
} else {
- DEBUG(0,("%s: command not found\n",CNV_LANG(tok)));
+ DEBUG(0,("%s: command not found\n",tok));
}
}
}
char *server_n;
struct in_addr ip;
extern struct in_addr ipzero;
-
- if (*share == '\\') {
- server = share+2;
- share = strchr(server,'\\');
- if (!share) return NULL;
- *share = 0;
- share++;
+ fstring servicename;
+ char *sharename;
+
+ /* make a copy so we don't modify the global string 'service' */
+ safe_strcpy(servicename, share, sizeof(servicename)-1);
+ sharename = servicename;
+ if (*sharename == '\\') {
+ server = sharename+2;
+ sharename = strchr(server,'\\');
+ if (!sharename) return NULL;
+ *sharename = 0;
+ sharename++;
}
server_n = server;
ip = ipzero;
- strupper(server);
-
- make_nmb_name(&calling, global_myname, 0x0, "");
- make_nmb_name(&called , server, name_type, "");
+ make_nmb_name(&calling, global_myname, 0x0);
+ make_nmb_name(&called , server, name_type);
again:
ip = ipzero;
if (have_ip) ip = dest_ip;
/* have to open a new connection */
- if (!(c=cli_initialise(NULL)) || !cli_connect(c, server_n, &ip)) {
+ if (!(c=cli_initialise(NULL)) || (cli_set_port(c, port) == 0) ||
+ !cli_connect(c, server_n, &ip)) {
DEBUG(0,("Connection to %s failed\n", server_n));
return NULL;
}
if (!cli_session_request(c, &calling, &called)) {
- DEBUG(0,("session request to %s failed\n", called.name));
+ char *p;
+ DEBUG(0,("session request to %s failed (%s)\n",
+ called.name, cli_errstr(c)));
cli_shutdown(c);
+ free(c);
+ if ((p=strchr(called.name, '.'))) {
+ *p = 0;
+ goto again;
+ }
if (strcmp(called.name, "*SMBSERVER")) {
- make_nmb_name(&called , "*SMBSERVER", 0x20, "");
+ make_nmb_name(&called , "*SMBSERVER", 0x20);
goto again;
}
return NULL;
if (!cli_negprot(c)) {
DEBUG(0,("protocol negotiation failed\n"));
cli_shutdown(c);
+ free(c);
return NULL;
}
password, strlen(password),
password, strlen(password),
workgroup)) {
- DEBUG(0,("session setup failed: %s\n", cli_errstr(c)));
- return NULL;
+ /* if a password was not supplied then try again with a null username */
+ if (password[0] || !username[0] ||
+ !cli_session_setup(c, "", "", 0, "", 0, workgroup)) {
+ DEBUG(0,("session setup failed: %s\n", cli_errstr(c)));
+ cli_shutdown(c);
+ free(c);
+ return NULL;
+ }
+ DEBUG(0,("Anonymous login successful\n"));
}
/*
DEBUG(4,(" session setup ok\n"));
- if (!cli_send_tconX(c, share, "?????",
+ if (!cli_send_tconX(c, sharename, "?????",
password, strlen(password)+1)) {
DEBUG(0,("tree connect failed: %s\n", cli_errstr(c)));
cli_shutdown(c);
+ free(c);
return NULL;
}
static BOOL process(char *base_directory)
{
cli = do_connect(desthost, service);
-
if (!cli) {
return(False);
}
****************************************************************************/
static void usage(char *pname)
{
- DEBUG(0,("Usage: %s service <password> ", pname));
+ DEBUG(0,("Usage: %s service <password> [options]", pname));
DEBUG(0,("\nVersion %s\n",VERSION));
DEBUG(0,("\t-s smb.conf pathname to smb.conf file\n"));
- DEBUG(0,("\t-B IP addr broadcast IP address to use\n"));
DEBUG(0,("\t-O socket_options socket options to use\n"));
DEBUG(0,("\t-R name resolve order use these name resolution services only\n"));
DEBUG(0,("\t-M host send a winpopup message to the host\n"));
DEBUG(0,("\t-L host get a list of shares available on a host\n"));
DEBUG(0,("\t-t terminal code terminal i/o code {sjis|euc|jis7|jis8|junet|hex}\n"));
DEBUG(0,("\t-m max protocol set the max protocol level\n"));
+ DEBUG(0,("\t-A filename get the credentials from a file\n"));
DEBUG(0,("\t-W workgroup set the workgroup name\n"));
DEBUG(0,("\t-T<c|x>IXFqgbNan command line tar\n"));
DEBUG(0,("\t-D directory start from directory\n"));
DEBUG(0,("\t-c command string execute semicolon separated commands\n"));
+ DEBUG(0,("\t-b xmit/send buffer changes the transmit/send buffer (default: 65520)\n"));
DEBUG(0,("\n"));
}
sscanf(p, "%d", &fd);
close_it = False;
} else if ((p = getenv("PASSWD_FILE")) != NULL) {
- fd = open(p, O_RDONLY);
+ fd = sys_open(p, O_RDONLY, 0);
pstrcpy(spec, p);
if (fd < 0) {
fprintf(stderr, "Error opening PASSWD_FILE %s: %s\n",
/****************************************************************************
handle a -L query
****************************************************************************/
-static int do_host_query(char *query_host, int port)
+static int do_host_query(char *query_host)
{
cli = do_connect(query_host, "IPC$");
- if (!cli) return 1;
+ if (!cli)
+ return 1;
browse_host(True);
list_servers(workgroup);
/****************************************************************************
handle a tar operation
****************************************************************************/
-static int do_tar_op(int port, char *base_directory)
+static int do_tar_op(char *base_directory)
{
int ret;
cli = do_connect(desthost, service);
+ if (!cli)
+ return 1;
recurse=True;
ip = ipzero;
- strupper(desthost);
-
- make_nmb_name(&calling, global_myname, 0x0, "");
- make_nmb_name(&called , desthost, name_type, "");
+ make_nmb_name(&calling, global_myname, 0x0);
+ make_nmb_name(&called , desthost, name_type);
ip = ipzero;
if (have_ip) ip = dest_ip;
{
fstring base_directory;
char *pname = argv[0];
- int port = SMB_PORT;
int opt;
extern FILE *dbf;
extern char *optarg;
extern int optind;
pstring query_host;
BOOL message = False;
- BOOL explicit_user = False;
extern char tar_type;
static pstring servicesf = CONFIGFILE;
pstring term_code;
DEBUGLEVEL = 2;
+#ifdef HAVE_LIBREADLINE
+ /* Allow conditional parsing of the ~/.inputrc file. */
+ rl_readline_name = "smbclient";
+#endif
setup_logging(pname,True);
- TimeInit();
- charset_initialise();
+ /*
+ * If the -E option is given, be careful not to clobber stdout
+ * before processing the options. 28.Feb.99, richard@hacom.nl.
+ * Also pre-parse the -s option to get the service file name.
+ */
- if(!get_myname(myhostname,NULL)) {
- DEBUG(0,("Failed to get my hostname.\n"));
+ for (opt = 1; opt < argc; opt++) {
+ if (strcmp(argv[opt], "-E") == 0)
+ dbf = stderr;
+ else if(strncmp(argv[opt], "-s", 2) == 0) {
+ if(argv[opt][2] != '\0')
+ pstrcpy(servicesf, &argv[opt][2]);
+ else if(argv[opt+1] != NULL) {
+ /*
+ * At least one more arg left.
+ */
+ pstrcpy(servicesf, argv[opt+1]);
+ } else {
+ usage(pname);
+ exit(1);
+ }
+ }
}
+ TimeInit();
+ charset_initialise();
+
in_client = True; /* Make sure that we tell lp_load we are */
if (!lp_load(servicesf,True,False,False)) {
codepage_initialise(lp_client_code_page());
- interpret_coding_system(term_code);
-
#ifdef WITH_SSL
sslutil_init(0);
#endif
}
while ((opt =
- getopt(argc, argv,"s:B:O:R:M:i:Nn:d:Pp:l:hI:EU:L:t:m:W:T:D:c:")) != EOF) {
+ getopt(argc, argv,"s:O:R:M:i:Nn:d:Pp:l:hI:EU:L:t:m:W:T:D:c:b:A:")) != EOF) {
switch (opt) {
case 's':
pstrcpy(servicesf, optarg);
break;
- case 'B':
- iface_set_default(NULL,optarg,NULL);
- break;
case 'O':
pstrcpy(user_socket_options,optarg);
break;
case 'M':
name_type = 0x03; /* messages are sent to NetBIOS name type 0x3 */
pstrcpy(desthost,optarg);
- strupper(desthost);
message = True;
break;
case 'i':
- pstrcpy(scope,optarg);
+ {
+ extern pstring global_scope;
+ pstrcpy(global_scope,optarg);
+ strupper(global_scope);
+ }
break;
case 'N':
got_pass = True;
case 'U':
{
char *lp;
- explicit_user = True;
pstrcpy(username,optarg);
if ((lp=strchr(username,'%'))) {
*lp = 0;
}
}
break;
+
+ case 'A':
+ {
+ FILE *auth;
+ fstring buf;
+ uint16 len = 0;
+ char *ptr, *val, *param;
+
+ if ((auth=sys_fopen(optarg, "r")) == NULL)
+ {
+ /* fail if we can't open the credentials file */
+ DEBUG(0,("ERROR: Unable to open credentials file!\n"));
+ exit (-1);
+ }
+
+ while (!feof(auth))
+ {
+ /* get a line from the file */
+ if (!fgets (buf, sizeof(buf), auth))
+ continue;
+ len = strlen(buf);
+
+ if ((len) && (buf[len-1]=='\n'))
+ {
+ buf[len-1] = '\0';
+ len--;
+ }
+ if (len == 0)
+ continue;
+
+ /* break up the line into parameter & value.
+ will need to eat a little whitespace possibly */
+ param = buf;
+ if (!(ptr = strchr (buf, '=')))
+ continue;
+ val = ptr+1;
+ *ptr = '\0';
+
+ /* eat leading white space */
+ while ((*val!='\0') && ((*val==' ') || (*val=='\t')))
+ val++;
+
+ if (strwicmp("password", param) == 0)
+ {
+ pstrcpy(password, val);
+ got_pass = True;
+ }
+ else if (strwicmp("username", param) == 0)
+ pstrcpy(username, val);
+
+ memset(buf, 0, sizeof(buf));
+ }
+ fclose(auth);
+ }
+ break;
+
case 'L':
- pstrcpy(query_host,optarg);
- if(!explicit_user)
- *username = '\0';
+ p = optarg;
+ while(*p == '\\' || *p == '/')
+ p++;
+ pstrcpy(query_host,p);
break;
case 't':
pstrcpy(term_code, optarg);
cmdstr = optarg;
got_pass = True;
break;
+ case 'b':
+ io_bufsize = MAX(1, atoi(optarg));
+ break;
default:
usage(pname);
exit(1);
}
}
- get_myname((*global_myname)?NULL:global_myname,NULL);
- strupper(global_myname);
+ get_myname((*global_myname)?NULL:global_myname);
if(*new_name_resolve_order)
lp_set_name_resolve_order(new_name_resolve_order);
+ if (*term_code)
+ interpret_coding_system(term_code);
+
if (!tar_type && !*query_host && !*service && !message) {
usage(pname);
exit(1);
DEBUG( 3, ( "Client started (version %s).\n", VERSION ) );
if (tar_type) {
- return do_tar_op(port, base_directory);
+ if (cmdstr)
+ process_command_string(cmdstr);
+ return do_tar_op(base_directory);
}
if ((p=strchr(query_host,'#'))) {
}
if (*query_host) {
- return do_host_query(query_host, port);
+ return do_host_query(query_host);
}
if (message) {
}
if (!process(base_directory)) {
- close_sockets();
return(1);
}
- close_sockets();
return(0);
}