Fix readline completion function prototype problems.
[Samba/ekacnet.git] / source / client / client.c
blob78c242af745a57181f3b9206e0cff984dd0633df
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 SMB client
5 Copyright (C) Andrew Tridgell 1994-1998
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #define NO_SYSLOG
24 #include "includes.h"
26 #ifndef REGISTER
27 #define REGISTER 0
28 #endif
30 struct cli_state *cli;
31 extern BOOL in_client;
32 extern BOOL AllowDebugChange;
33 static int port = SMB_PORT;
34 pstring cur_dir = "\\";
35 pstring cd_path = "";
36 static pstring service;
37 static pstring desthost;
38 extern pstring global_myname;
39 static pstring password;
40 static pstring username;
41 static pstring workgroup;
42 static char *cmdstr;
43 static BOOL got_pass;
44 static int io_bufsize = 64512;
45 extern struct in_addr ipzero;
47 static int name_type = 0x20;
48 static int max_protocol = PROTOCOL_NT1;
49 extern pstring user_socket_options;
51 static int process_tok(fstring tok);
52 static void cmd_help(void);
54 /* 30 second timeout on most commands */
55 #define CLIENT_TIMEOUT (30*1000)
56 #define SHORT_TIMEOUT (5*1000)
58 /* value for unused fid field in trans2 secondary request */
59 #define FID_UNUSED (0xFFFF)
61 time_t newer_than = 0;
62 int archive_level = 0;
64 BOOL translation = False;
66 static BOOL have_ip;
68 /* clitar bits insert */
69 extern int blocksize;
70 extern BOOL tar_inc;
71 extern BOOL tar_reset;
72 /* clitar bits end */
75 mode_t myumask = 0755;
77 BOOL prompt = True;
79 int printmode = 1;
81 static BOOL recurse = False;
82 BOOL lowercase = False;
84 struct in_addr dest_ip;
86 #define SEPARATORS " \t\n\r"
88 BOOL abort_mget = True;
90 pstring fileselection = "";
92 extern file_info def_finfo;
94 /* timing globals */
95 int get_total_size = 0;
96 int get_total_time_ms = 0;
97 int put_total_size = 0;
98 int put_total_time_ms = 0;
100 /* totals globals */
101 static double dir_total;
103 #define USENMB
105 /****************************************************************************
106 write to a local file with CR/LF->LF translation if appropriate. return the
107 number taken from the buffer. This may not equal the number written.
108 ****************************************************************************/
109 static int writefile(int f, char *b, int n)
111 int i;
113 if (!translation) {
114 return write(f,b,n);
117 i = 0;
118 while (i < n) {
119 if (*b == '\r' && (i<(n-1)) && *(b+1) == '\n') {
120 b++;i++;
122 if (write(f, b, 1) != 1) {
123 break;
125 b++;
126 i++;
129 return(i);
132 /****************************************************************************
133 read from a file with LF->CR/LF translation if appropriate. return the
134 number read. read approx n bytes.
135 ****************************************************************************/
136 static int readfile(char *b, int size, int n, FILE *f)
138 int i;
139 int c;
141 if (!translation || (size != 1))
142 return(fread(b,size,n,f));
144 i = 0;
145 while (i < (n - 1) && (i < BUFFER_SIZE)) {
146 if ((c = getc(f)) == EOF) {
147 break;
150 if (c == '\n') { /* change all LFs to CR/LF */
151 b[i++] = '\r';
154 b[i++] = c;
157 return(i);
161 /****************************************************************************
162 send a message
163 ****************************************************************************/
164 static void send_message(void)
166 int total_len = 0;
167 int grp_id;
169 if (!cli_message_start(cli, desthost, username, &grp_id)) {
170 DEBUG(0,("message start: %s\n", cli_errstr(cli)));
171 return;
175 printf("Connected. Type your message, ending it with a Control-D\n");
177 while (!feof(stdin) && total_len < 1600) {
178 int maxlen = MIN(1600 - total_len,127);
179 pstring msg;
180 int l=0;
181 int c;
183 ZERO_ARRAY(msg);
185 for (l=0;l<maxlen && (c=fgetc(stdin))!=EOF;l++) {
186 if (c == '\n')
187 msg[l++] = '\r';
188 msg[l] = c;
192 * The message is in UNIX codepage format. Convert to
193 * DOS before sending.
196 unix_to_dos(msg, True);
198 if (!cli_message_text(cli, msg, l, grp_id)) {
199 printf("SMBsendtxt failed (%s)\n",cli_errstr(cli));
200 return;
203 total_len += l;
206 if (total_len >= 1600)
207 printf("the message was truncated to 1600 bytes\n");
208 else
209 printf("sent %d bytes\n",total_len);
211 if (!cli_message_end(cli, grp_id)) {
212 printf("SMBsendend failed (%s)\n",cli_errstr(cli));
213 return;
219 /****************************************************************************
220 check the space on a device
221 ****************************************************************************/
222 static void do_dskattr(void)
224 int total, bsize, avail;
226 if (!cli_dskattr(cli, &bsize, &total, &avail)) {
227 DEBUG(0,("Error in dskattr: %s\n",cli_errstr(cli)));
228 return;
231 DEBUG(0,("\n\t\t%d blocks of size %d. %d blocks available\n",
232 total, bsize, avail));
235 /****************************************************************************
236 show cd/pwd
237 ****************************************************************************/
238 static void cmd_pwd(void)
240 DEBUG(0,("Current directory is %s",service));
241 DEBUG(0,("%s\n",cur_dir));
245 /****************************************************************************
246 change directory - inner section
247 ****************************************************************************/
248 static void do_cd(char *newdir)
250 char *p = newdir;
251 pstring saved_dir;
252 pstring dname;
254 dos_format(newdir);
256 /* Save the current directory in case the
257 new directory is invalid */
258 pstrcpy(saved_dir, cur_dir);
259 if (*p == '\\')
260 pstrcpy(cur_dir,p);
261 else
262 pstrcat(cur_dir,p);
263 if (*(cur_dir+strlen(cur_dir)-1) != '\\') {
264 pstrcat(cur_dir, "\\");
266 dos_clean_name(cur_dir);
267 pstrcpy(dname,cur_dir);
268 pstrcat(cur_dir,"\\");
269 dos_clean_name(cur_dir);
271 if (!strequal(cur_dir,"\\")) {
272 if (!cli_chkpath(cli, dname)) {
273 DEBUG(0,("cd %s: %s\n", dname, cli_errstr(cli)));
274 pstrcpy(cur_dir,saved_dir);
278 pstrcpy(cd_path,cur_dir);
281 /****************************************************************************
282 change directory
283 ****************************************************************************/
284 static void cmd_cd(void)
286 fstring buf;
288 if (next_token(NULL,buf,NULL,sizeof(buf)))
289 do_cd(buf);
290 else
291 DEBUG(0,("Current directory is %s\n",cur_dir));
295 /*******************************************************************
296 decide if a file should be operated on
297 ********************************************************************/
298 static BOOL do_this_one(file_info *finfo)
300 if (finfo->mode & aDIR) return(True);
302 if (*fileselection &&
303 !mask_match(finfo->name,fileselection,False)) {
304 DEBUG(3,("match_match %s failed\n", finfo->name));
305 return False;
308 if (newer_than && finfo->mtime < newer_than) {
309 DEBUG(3,("newer_than %s failed\n", finfo->name));
310 return(False);
313 if ((archive_level==1 || archive_level==2) && !(finfo->mode & aARCH)) {
314 DEBUG(3,("archive %s failed\n", finfo->name));
315 return(False);
318 return(True);
321 /****************************************************************************
322 display info about a file
323 ****************************************************************************/
324 static void display_finfo(file_info *finfo)
326 if (do_this_one(finfo)) {
327 time_t t = finfo->mtime; /* the time is assumed to be passed as GMT */
328 DEBUG(0,(" %-30s%7.7s %8.0f %s",
329 finfo->name,
330 attrib_string(finfo->mode),
331 (double)finfo->size,
332 asctime(LocalTime(&t))));
333 dir_total += finfo->size;
338 /****************************************************************************
339 accumulate size of a file
340 ****************************************************************************/
341 static void do_du(file_info *finfo)
343 if (do_this_one(finfo)) {
344 dir_total += finfo->size;
348 static BOOL do_list_recurse;
349 static BOOL do_list_dirs;
350 static char *do_list_queue = 0;
351 static long do_list_queue_size = 0;
352 static long do_list_queue_start = 0;
353 static long do_list_queue_end = 0;
354 static void (*do_list_fn)(file_info *);
356 /****************************************************************************
357 functions for do_list_queue
358 ****************************************************************************/
361 * The do_list_queue is a NUL-separated list of strings stored in a
362 * char*. Since this is a FIFO, we keep track of the beginning and
363 * ending locations of the data in the queue. When we overflow, we
364 * double the size of the char*. When the start of the data passes
365 * the midpoint, we move everything back. This is logically more
366 * complex than a linked list, but easier from a memory management
367 * angle. In any memory error condition, do_list_queue is reset.
368 * Functions check to ensure that do_list_queue is non-NULL before
369 * accessing it.
371 static void reset_do_list_queue(void)
373 if (do_list_queue)
375 free(do_list_queue);
377 do_list_queue = 0;
378 do_list_queue_size = 0;
379 do_list_queue_start = 0;
380 do_list_queue_end = 0;
383 static void init_do_list_queue(void)
385 reset_do_list_queue();
386 do_list_queue_size = 1024;
387 do_list_queue = malloc(do_list_queue_size);
388 if (do_list_queue == 0) {
389 DEBUG(0,("malloc fail for size %d\n",
390 (int)do_list_queue_size));
391 reset_do_list_queue();
392 } else {
393 memset(do_list_queue, 0, do_list_queue_size);
397 static void adjust_do_list_queue(void)
400 * If the starting point of the queue is more than half way through,
401 * move everything toward the beginning.
403 if (do_list_queue && (do_list_queue_start == do_list_queue_end))
405 DEBUG(4,("do_list_queue is empty\n"));
406 do_list_queue_start = do_list_queue_end = 0;
407 *do_list_queue = '\0';
409 else if (do_list_queue_start > (do_list_queue_size / 2))
411 DEBUG(4,("sliding do_list_queue backward\n"));
412 memmove(do_list_queue,
413 do_list_queue + do_list_queue_start,
414 do_list_queue_end - do_list_queue_start);
415 do_list_queue_end -= do_list_queue_start;
416 do_list_queue_start = 0;
421 static void add_to_do_list_queue(const char* entry)
423 char *dlq;
425 long new_end = do_list_queue_end + ((long)strlen(entry)) + 1;
426 while (new_end > do_list_queue_size)
428 do_list_queue_size *= 2;
429 DEBUG(4,("enlarging do_list_queue to %d\n",
430 (int)do_list_queue_size));
431 dlq = Realloc(do_list_queue, do_list_queue_size);
432 if (!dlq) {
433 DEBUG(0,("failure enlarging do_list_queue to %d bytes\n",
434 (int)do_list_queue_size));
435 reset_do_list_queue();
436 } else {
437 do_list_queue = dlq;
438 memset(do_list_queue + do_list_queue_size / 2,
439 0, do_list_queue_size / 2);
442 if (do_list_queue)
444 pstrcpy(do_list_queue + do_list_queue_end, entry);
445 do_list_queue_end = new_end;
446 DEBUG(4,("added %s to do_list_queue (start=%d, end=%d)\n",
447 entry, (int)do_list_queue_start, (int)do_list_queue_end));
451 static char *do_list_queue_head(void)
453 return do_list_queue + do_list_queue_start;
456 static void remove_do_list_queue_head(void)
458 if (do_list_queue_end > do_list_queue_start)
460 do_list_queue_start += strlen(do_list_queue_head()) + 1;
461 adjust_do_list_queue();
462 DEBUG(4,("removed head of do_list_queue (start=%d, end=%d)\n",
463 (int)do_list_queue_start, (int)do_list_queue_end));
467 static int do_list_queue_empty(void)
469 return (! (do_list_queue && *do_list_queue));
472 /****************************************************************************
473 a helper for do_list
474 ****************************************************************************/
475 static void do_list_helper(file_info *f, const char *mask, void *state)
477 if (f->mode & aDIR) {
478 if (do_list_dirs && do_this_one(f)) {
479 do_list_fn(f);
481 if (do_list_recurse &&
482 !strequal(f->name,".") &&
483 !strequal(f->name,"..")) {
484 pstring mask2;
485 char *p;
487 pstrcpy(mask2, mask);
488 p = strrchr(mask2,'\\');
489 if (!p) return;
490 p[1] = 0;
491 pstrcat(mask2, f->name);
492 pstrcat(mask2,"\\*");
493 add_to_do_list_queue(mask2);
495 return;
498 if (do_this_one(f)) {
499 do_list_fn(f);
504 /****************************************************************************
505 a wrapper around cli_list that adds recursion
506 ****************************************************************************/
507 void do_list(const char *mask,uint16 attribute,void (*fn)(file_info *),BOOL rec, BOOL dirs)
509 static int in_do_list = 0;
511 if (in_do_list && rec)
513 fprintf(stderr, "INTERNAL ERROR: do_list called recursively when the recursive flag is true\n");
514 exit(1);
517 in_do_list = 1;
519 do_list_recurse = rec;
520 do_list_dirs = dirs;
521 do_list_fn = fn;
523 if (rec)
525 init_do_list_queue();
526 add_to_do_list_queue(mask);
528 while (! do_list_queue_empty())
531 * Need to copy head so that it doesn't become
532 * invalid inside the call to cli_list. This
533 * would happen if the list were expanded
534 * during the call.
535 * Fix from E. Jay Berkenbilt (ejb@ql.org)
537 pstring head;
538 pstrcpy(head, do_list_queue_head());
539 cli_list(cli, head, attribute, do_list_helper, NULL);
540 remove_do_list_queue_head();
541 if ((! do_list_queue_empty()) && (fn == display_finfo))
543 char* next_file = do_list_queue_head();
544 char* save_ch = 0;
545 if ((strlen(next_file) >= 2) &&
546 (next_file[strlen(next_file) - 1] == '*') &&
547 (next_file[strlen(next_file) - 2] == '\\'))
549 save_ch = next_file +
550 strlen(next_file) - 2;
551 *save_ch = '\0';
553 DEBUG(0,("\n%s\n",next_file));
554 if (save_ch)
556 *save_ch = '\\';
561 else
563 if (cli_list(cli, mask, attribute, do_list_helper, NULL) == -1)
565 DEBUG(0, ("%s listing %s\n", cli_errstr(cli), mask));
569 in_do_list = 0;
570 reset_do_list_queue();
573 /****************************************************************************
574 get a directory listing
575 ****************************************************************************/
576 static void cmd_dir(void)
578 uint16 attribute = aDIR | aSYSTEM | aHIDDEN;
579 pstring mask;
580 fstring buf;
581 char *p=buf;
583 dir_total = 0;
584 pstrcpy(mask,cur_dir);
585 if(mask[strlen(mask)-1]!='\\')
586 pstrcat(mask,"\\");
588 if (next_token(NULL,buf,NULL,sizeof(buf))) {
589 dos_format(p);
590 if (*p == '\\')
591 pstrcpy(mask,p);
592 else
593 pstrcat(mask,p);
595 else {
596 pstrcat(mask,"*");
599 do_list(mask, attribute, display_finfo, recurse, True);
601 do_dskattr();
603 DEBUG(3, ("Total bytes listed: %.0f\n", dir_total));
607 /****************************************************************************
608 get a directory listing
609 ****************************************************************************/
610 static void cmd_du(void)
612 uint16 attribute = aDIR | aSYSTEM | aHIDDEN;
613 pstring mask;
614 fstring buf;
615 char *p=buf;
617 dir_total = 0;
618 pstrcpy(mask,cur_dir);
619 if(mask[strlen(mask)-1]!='\\')
620 pstrcat(mask,"\\");
622 if (next_token(NULL,buf,NULL,sizeof(buf))) {
623 dos_format(p);
624 if (*p == '\\')
625 pstrcpy(mask,p);
626 else
627 pstrcat(mask,p);
628 } else {
629 pstrcat(mask,"*");
632 do_list(mask, attribute, do_du, recurse, True);
634 do_dskattr();
636 DEBUG(0, ("Total number of bytes: %.0f\n", dir_total));
640 /****************************************************************************
641 get a file from rname to lname
642 ****************************************************************************/
643 static void do_get(char *rname,char *lname)
645 int handle=0,fnum;
646 BOOL newhandle = False;
647 char *data;
648 struct timeval tp_start;
649 int read_size = io_bufsize;
650 uint16 attr;
651 size_t size;
652 off_t nread = 0;
654 GetTimeOfDay(&tp_start);
656 if (lowercase) {
657 strlower(lname);
660 fnum = cli_open(cli, rname, O_RDONLY, DENY_NONE);
662 if (fnum == -1) {
663 DEBUG(0,("%s opening remote file %s\n",cli_errstr(cli),rname));
664 return;
667 if(!strcmp(lname,"-")) {
668 handle = fileno(stdout);
669 } else {
670 handle = sys_open(lname,O_WRONLY|O_CREAT|O_TRUNC,0644);
671 newhandle = True;
673 if (handle < 0) {
674 DEBUG(0,("Error opening local file %s\n",lname));
675 return;
679 if (!cli_qfileinfo(cli, fnum,
680 &attr, &size, NULL, NULL, NULL, NULL, NULL) &&
681 !cli_getattrE(cli, fnum,
682 &attr, &size, NULL, NULL, NULL)) {
683 DEBUG(0,("getattrib: %s\n",cli_errstr(cli)));
684 return;
687 DEBUG(2,("getting file %s of size %.0f as %s ",
688 lname, (double)size, lname));
690 if(!(data = (char *)malloc(read_size))) {
691 DEBUG(0,("malloc fail for size %d\n", read_size));
692 cli_close(cli, fnum);
693 return;
696 while (1) {
697 int n = cli_read(cli, fnum, data, nread, read_size);
699 if (n <= 0) break;
701 if (writefile(handle,data, n) != n) {
702 DEBUG(0,("Error writing local file\n"));
703 break;
706 nread += n;
709 if (nread < size) {
710 DEBUG (0, ("Short read when getting file %s. Only got %ld bytes.\n",
711 rname, (long)nread));
714 free(data);
716 if (!cli_close(cli, fnum)) {
717 DEBUG(0,("Error %s closing remote file\n",cli_errstr(cli)));
720 if (newhandle) {
721 close(handle);
724 if (archive_level >= 2 && (attr & aARCH)) {
725 cli_setatr(cli, rname, attr & ~(uint16)aARCH, 0);
729 struct timeval tp_end;
730 int this_time;
732 GetTimeOfDay(&tp_end);
733 this_time =
734 (tp_end.tv_sec - tp_start.tv_sec)*1000 +
735 (tp_end.tv_usec - tp_start.tv_usec)/1000;
736 get_total_time_ms += this_time;
737 get_total_size += nread;
739 DEBUG(2,("(%3.1f kb/s) (average %3.1f kb/s)\n",
740 nread / (1.024*this_time + 1.0e-4),
741 get_total_size / (1.024*get_total_time_ms)));
746 /****************************************************************************
747 get a file
748 ****************************************************************************/
749 static void cmd_get(void)
751 pstring lname;
752 pstring rname;
753 char *p;
755 pstrcpy(rname,cur_dir);
756 pstrcat(rname,"\\");
758 p = rname + strlen(rname);
760 if (!next_token(NULL,p,NULL,sizeof(rname)-strlen(rname))) {
761 DEBUG(0,("get <filename>\n"));
762 return;
764 pstrcpy(lname,p);
765 dos_clean_name(rname);
767 next_token(NULL,lname,NULL,sizeof(lname));
769 do_get(rname, lname);
773 /****************************************************************************
774 do a mget operation on one file
775 ****************************************************************************/
776 static void do_mget(file_info *finfo)
778 pstring rname;
779 pstring quest;
780 pstring saved_curdir;
781 pstring mget_mask;
783 if (strequal(finfo->name,".") || strequal(finfo->name,".."))
784 return;
786 if (abort_mget) {
787 DEBUG(0,("mget aborted\n"));
788 return;
791 if (finfo->mode & aDIR)
792 slprintf(quest,sizeof(pstring)-1,
793 "Get directory %s? ",finfo->name);
794 else
795 slprintf(quest,sizeof(pstring)-1,
796 "Get file %s? ",finfo->name);
798 if (prompt && !yesno(quest)) return;
800 if (!(finfo->mode & aDIR)) {
801 pstrcpy(rname,cur_dir);
802 pstrcat(rname,finfo->name);
803 do_get(rname,finfo->name);
804 return;
807 /* handle directories */
808 pstrcpy(saved_curdir,cur_dir);
810 pstrcat(cur_dir,finfo->name);
811 pstrcat(cur_dir,"\\");
813 unix_format(finfo->name);
814 if (lowercase)
815 strlower(finfo->name);
817 if (!directory_exist(finfo->name,NULL) &&
818 mkdir(finfo->name,0777) != 0) {
819 DEBUG(0,("failed to create directory %s\n",finfo->name));
820 pstrcpy(cur_dir,saved_curdir);
821 return;
824 if (chdir(finfo->name) != 0) {
825 DEBUG(0,("failed to chdir to directory %s\n",finfo->name));
826 pstrcpy(cur_dir,saved_curdir);
827 return;
830 pstrcpy(mget_mask,cur_dir);
831 pstrcat(mget_mask,"*");
833 do_list(mget_mask, aSYSTEM | aHIDDEN | aDIR,do_mget,False, True);
834 chdir("..");
835 pstrcpy(cur_dir,saved_curdir);
839 /****************************************************************************
840 view the file using the pager
841 ****************************************************************************/
842 static void cmd_more(void)
844 fstring rname,lname,pager_cmd;
845 char *pager;
846 int fd;
848 fstrcpy(rname,cur_dir);
849 fstrcat(rname,"\\");
851 slprintf(lname,sizeof(lname)-1, "%s/smbmore.XXXXXX",tmpdir());
852 fd = smb_mkstemp(lname);
853 if (fd == -1) {
854 DEBUG(0,("failed to create temporary file for more\n"));
855 return;
857 close(fd);
859 if (!next_token(NULL,rname+strlen(rname),NULL,sizeof(rname)-strlen(rname))) {
860 DEBUG(0,("more <filename>\n"));
861 unlink(lname);
862 return;
864 dos_clean_name(rname);
866 do_get(rname,lname);
868 pager=getenv("PAGER");
870 slprintf(pager_cmd,sizeof(pager_cmd)-1,
871 "%s %s",(pager? pager:PAGER), lname);
872 system(pager_cmd);
873 unlink(lname);
878 /****************************************************************************
879 do a mget command
880 ****************************************************************************/
881 static void cmd_mget(void)
883 uint16 attribute = aSYSTEM | aHIDDEN;
884 pstring mget_mask;
885 fstring buf;
886 char *p=buf;
888 *mget_mask = 0;
890 if (recurse)
891 attribute |= aDIR;
893 abort_mget = False;
895 while (next_token(NULL,p,NULL,sizeof(buf))) {
896 pstrcpy(mget_mask,cur_dir);
897 if(mget_mask[strlen(mget_mask)-1]!='\\')
898 pstrcat(mget_mask,"\\");
900 if (*p == '\\')
901 pstrcpy(mget_mask,p);
902 else
903 pstrcat(mget_mask,p);
904 do_list(mget_mask, attribute,do_mget,False,True);
907 if (!*mget_mask) {
908 pstrcpy(mget_mask,cur_dir);
909 if(mget_mask[strlen(mget_mask)-1]!='\\')
910 pstrcat(mget_mask,"\\");
911 pstrcat(mget_mask,"*");
912 do_list(mget_mask, attribute,do_mget,False,True);
917 /****************************************************************************
918 make a directory of name "name"
919 ****************************************************************************/
920 static BOOL do_mkdir(char *name)
922 if (!cli_mkdir(cli, name)) {
923 DEBUG(0,("%s making remote directory %s\n",
924 cli_errstr(cli),name));
925 return(False);
928 return(True);
932 /****************************************************************************
933 Exit client.
934 ****************************************************************************/
935 static void cmd_quit(void)
937 cli_shutdown(cli);
938 exit(0);
942 /****************************************************************************
943 make a directory
944 ****************************************************************************/
945 static void cmd_mkdir(void)
947 pstring mask;
948 fstring buf;
949 char *p=buf;
951 pstrcpy(mask,cur_dir);
953 if (!next_token(NULL,p,NULL,sizeof(buf))) {
954 if (!recurse)
955 DEBUG(0,("mkdir <dirname>\n"));
956 return;
958 pstrcat(mask,p);
960 if (recurse) {
961 pstring ddir;
962 pstring ddir2;
963 *ddir2 = 0;
965 pstrcpy(ddir,mask);
966 trim_string(ddir,".",NULL);
967 p = strtok(ddir,"/\\");
968 while (p) {
969 pstrcat(ddir2,p);
970 if (!cli_chkpath(cli, ddir2)) {
971 do_mkdir(ddir2);
973 pstrcat(ddir2,"\\");
974 p = strtok(NULL,"/\\");
976 } else {
977 do_mkdir(mask);
982 /****************************************************************************
983 put a single file
984 ****************************************************************************/
985 static void do_put(char *rname,char *lname)
987 int fnum;
988 FILE *f;
989 int nread=0;
990 char *buf=NULL;
991 int maxwrite=io_bufsize;
993 struct timeval tp_start;
994 GetTimeOfDay(&tp_start);
996 fnum = cli_open(cli, rname, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE);
998 if (fnum == -1) {
999 DEBUG(0,("%s opening remote file %s\n",cli_errstr(cli),rname));
1000 return;
1003 /* allow files to be piped into smbclient
1004 jdblair 24.jun.98 */
1005 if (!strcmp(lname, "-")) {
1006 f = stdin;
1007 /* size of file is not known */
1008 } else {
1009 f = sys_fopen(lname,"r");
1012 if (!f) {
1013 DEBUG(0,("Error opening local file %s\n",lname));
1014 return;
1018 DEBUG(1,("putting file %s as %s ",lname,
1019 rname));
1021 buf = (char *)malloc(maxwrite);
1022 if (!buf) {
1023 DEBUG(0, ("ERROR: Not enough memory!\n"));
1024 return;
1026 while (!feof(f)) {
1027 int n = maxwrite;
1028 int ret;
1030 if ((n = readfile(buf,1,n,f)) < 1) {
1031 if((n == 0) && feof(f))
1032 break; /* Empty local file. */
1034 DEBUG(0,("Error reading local file: %s\n", strerror(errno) ));
1035 break;
1038 ret = cli_write(cli, fnum, 0, buf, nread, n);
1040 if (n != ret) {
1041 DEBUG(0,("Error writing file: %s\n", cli_errstr(cli)));
1042 break;
1045 nread += n;
1048 if (!cli_close(cli, fnum)) {
1049 DEBUG(0,("%s closing remote file %s\n",cli_errstr(cli),rname));
1050 fclose(f);
1051 if (buf) free(buf);
1052 return;
1056 fclose(f);
1057 if (buf) free(buf);
1060 struct timeval tp_end;
1061 int this_time;
1063 GetTimeOfDay(&tp_end);
1064 this_time =
1065 (tp_end.tv_sec - tp_start.tv_sec)*1000 +
1066 (tp_end.tv_usec - tp_start.tv_usec)/1000;
1067 put_total_time_ms += this_time;
1068 put_total_size += nread;
1070 DEBUG(1,("(%3.1f kb/s) (average %3.1f kb/s)\n",
1071 nread / (1.024*this_time + 1.0e-4),
1072 put_total_size / (1.024*put_total_time_ms)));
1075 if (f == stdin) {
1076 cli_shutdown(cli);
1077 exit(0);
1083 /****************************************************************************
1084 put a file
1085 ****************************************************************************/
1086 static void cmd_put(void)
1088 pstring lname;
1089 pstring rname;
1090 fstring buf;
1091 char *p=buf;
1093 pstrcpy(rname,cur_dir);
1094 pstrcat(rname,"\\");
1096 if (!next_token(NULL,p,NULL,sizeof(buf))) {
1097 DEBUG(0,("put <filename>\n"));
1098 return;
1100 pstrcpy(lname,p);
1102 if (next_token(NULL,p,NULL,sizeof(buf)))
1103 pstrcat(rname,p);
1104 else
1105 pstrcat(rname,lname);
1107 dos_clean_name(rname);
1110 SMB_STRUCT_STAT st;
1111 /* allow '-' to represent stdin
1112 jdblair, 24.jun.98 */
1113 if (!file_exist(lname,&st) &&
1114 (strcmp(lname,"-"))) {
1115 DEBUG(0,("%s does not exist\n",lname));
1116 return;
1120 do_put(rname,lname);
1123 /*************************************
1124 File list structure
1125 *************************************/
1127 static struct file_list {
1128 struct file_list *prev, *next;
1129 char *file_path;
1130 BOOL isdir;
1131 } *file_list;
1133 /****************************************************************************
1134 Free a file_list structure
1135 ****************************************************************************/
1137 static void free_file_list (struct file_list * list)
1139 struct file_list *tmp;
1141 while (list)
1143 tmp = list;
1144 DLIST_REMOVE(list, list);
1145 if (tmp->file_path) free(tmp->file_path);
1146 free(tmp);
1150 /****************************************************************************
1151 seek in a directory/file list until you get something that doesn't start with
1152 the specified name
1153 ****************************************************************************/
1154 static BOOL seek_list(struct file_list *list, char *name)
1156 while (list) {
1157 trim_string(list->file_path,"./","\n");
1158 if (strncmp(list->file_path, name, strlen(name)) != 0) {
1159 return(True);
1161 list = list->next;
1164 return(False);
1167 /****************************************************************************
1168 set the file selection mask
1169 ****************************************************************************/
1170 static void cmd_select(void)
1172 pstrcpy(fileselection,"");
1173 next_token(NULL,fileselection,NULL,sizeof(fileselection));
1176 /****************************************************************************
1177 Recursive file matching function act as find
1178 match must be always set to True when calling this function
1179 ****************************************************************************/
1180 static int file_find(struct file_list **list, const char *directory,
1181 const char *expression, BOOL match)
1183 DIR *dir;
1184 struct file_list *entry;
1185 struct stat statbuf;
1186 int ret;
1187 char *path;
1188 BOOL isdir;
1189 char *dname;
1191 dir = opendir(directory);
1192 if (!dir) return -1;
1194 while ((dname = readdirname(dir))) {
1195 if (!strcmp("..", dname)) continue;
1196 if (!strcmp(".", dname)) continue;
1198 if (asprintf(&path, "%s/%s", directory, dname) <= 0) {
1199 continue;
1202 isdir = False;
1203 if (!match || !ms_fnmatch(expression, dname)) {
1204 if (recurse) {
1205 ret = stat(path, &statbuf);
1206 if (ret == 0) {
1207 if (S_ISDIR(statbuf.st_mode)) {
1208 isdir = True;
1209 ret = file_find(list, path, expression, False);
1211 } else {
1212 DEBUG(0,("file_find: cannot stat file %s\n", path));
1215 if (ret == -1) {
1216 free(path);
1217 closedir(dir);
1218 return -1;
1221 entry = (struct file_list *) malloc(sizeof (struct file_list));
1222 if (!entry) {
1223 DEBUG(0,("Out of memory in file_find\n"));
1224 closedir(dir);
1225 return -1;
1227 entry->file_path = path;
1228 entry->isdir = isdir;
1229 DLIST_ADD(*list, entry);
1230 } else {
1231 free(path);
1235 closedir(dir);
1236 return 0;
1239 /****************************************************************************
1240 mput some files
1241 ****************************************************************************/
1242 static void cmd_mput(void)
1244 fstring buf;
1245 char *p=buf;
1247 while (next_token(NULL,p,NULL,sizeof(buf))) {
1248 int ret;
1249 struct file_list *temp_list;
1250 char *quest, *lname, *rname;
1252 file_list = NULL;
1254 ret = file_find(&file_list, ".", p, True);
1255 if (ret) {
1256 free_file_list(file_list);
1257 continue;
1260 quest = NULL;
1261 lname = NULL;
1262 rname = NULL;
1264 for (temp_list = file_list; temp_list;
1265 temp_list = temp_list->next) {
1267 if (lname) free(lname);
1268 if (asprintf(&lname, "%s/", temp_list->file_path) <= 0)
1269 continue;
1270 trim_string(lname, "./", "/");
1272 /* check if it's a directory */
1273 if (temp_list->isdir) {
1274 /* if (!recurse) continue; */
1276 if (quest) free(quest);
1277 asprintf(&quest, "Put directory %s? ", lname);
1278 if (prompt && !yesno(quest)) { /* No */
1279 /* Skip the directory */
1280 lname[strlen(lname)-1] = '/';
1281 if (!seek_list(temp_list, lname))
1282 break;
1283 } else { /* Yes */
1284 if (rname) free(rname);
1285 asprintf(&rname, "%s%s", cur_dir, lname);
1286 dos_format(rname);
1287 if (!cli_chkpath(cli, rname) &&
1288 !do_mkdir(rname)) {
1289 DEBUG (0, ("Unable to make dir, skipping..."));
1290 /* Skip the directory */
1291 lname[strlen(lname)-1] = '/';
1292 if (!seek_list(temp_list, lname))
1293 break;
1296 continue;
1297 } else {
1298 if (quest) free(quest);
1299 asprintf(&quest,"Put file %s? ", lname);
1300 if (prompt && !yesno(quest)) /* No */
1301 continue;
1303 /* Yes */
1304 if (rname) free(rname);
1305 asprintf(&rname, "%s%s", cur_dir, lname);
1308 dos_format(rname);
1310 do_put(rname, lname);
1312 free_file_list(file_list);
1313 if (quest) free(quest);
1314 if (lname) free(lname);
1315 if (rname) free(rname);
1320 /****************************************************************************
1321 cancel a print job
1322 ****************************************************************************/
1323 static void do_cancel(int job)
1325 if (cli_printjob_del(cli, job)) {
1326 printf("Job %d cancelled\n",job);
1327 } else {
1328 printf("Error cancelling job %d : %s\n",job,cli_errstr(cli));
1333 /****************************************************************************
1334 cancel a print job
1335 ****************************************************************************/
1336 static void cmd_cancel(void)
1338 fstring buf;
1339 int job;
1341 if (!next_token(NULL,buf,NULL,sizeof(buf))) {
1342 printf("cancel <jobid> ...\n");
1343 return;
1345 do {
1346 job = atoi(buf);
1347 do_cancel(job);
1348 } while (next_token(NULL,buf,NULL,sizeof(buf)));
1352 /****************************************************************************
1353 print a file
1354 ****************************************************************************/
1355 static void cmd_print(void)
1357 pstring lname;
1358 pstring rname;
1359 char *p;
1361 if (!next_token(NULL,lname,NULL, sizeof(lname))) {
1362 DEBUG(0,("print <filename>\n"));
1363 return;
1366 pstrcpy(rname,lname);
1367 p = strrchr(rname,'/');
1368 if (p) {
1369 slprintf(rname, sizeof(rname)-1, "%s-%d", p+1, (int)sys_getpid());
1372 if (strequal(lname,"-")) {
1373 slprintf(rname, sizeof(rname)-1, "stdin-%d", (int)sys_getpid());
1376 do_put(rname, lname);
1380 /****************************************************************************
1381 show a print queue entry
1382 ****************************************************************************/
1383 static void queue_fn(struct print_job_info *p)
1385 DEBUG(0,("%-6d %-9d %s\n", (int)p->id, (int)p->size, p->name));
1388 /****************************************************************************
1389 show a print queue
1390 ****************************************************************************/
1391 static void cmd_queue(void)
1393 cli_print_queue(cli, queue_fn);
1396 /****************************************************************************
1397 delete some files
1398 ****************************************************************************/
1399 static void do_del(file_info *finfo)
1401 pstring mask;
1403 pstrcpy(mask,cur_dir);
1404 pstrcat(mask,finfo->name);
1406 if (finfo->mode & aDIR)
1407 return;
1409 if (!cli_unlink(cli, mask)) {
1410 DEBUG(0,("%s deleting remote file %s\n",cli_errstr(cli),mask));
1414 /****************************************************************************
1415 delete some files
1416 ****************************************************************************/
1417 static void cmd_del(void)
1419 pstring mask;
1420 fstring buf;
1421 uint16 attribute = aSYSTEM | aHIDDEN;
1423 if (recurse)
1424 attribute |= aDIR;
1426 pstrcpy(mask,cur_dir);
1428 if (!next_token(NULL,buf,NULL,sizeof(buf))) {
1429 DEBUG(0,("del <filename>\n"));
1430 return;
1432 pstrcat(mask,buf);
1434 do_list(mask, attribute,do_del,False,False);
1437 /****************************************************************************
1438 ****************************************************************************/
1439 static void cmd_open(void)
1441 pstring mask;
1442 fstring buf;
1444 pstrcpy(mask,cur_dir);
1446 if (!next_token(NULL,buf,NULL,sizeof(buf))) {
1447 DEBUG(0,("del <filename>\n"));
1448 return;
1450 pstrcat(mask,buf);
1452 cli_open(cli, mask, O_RDWR, DENY_ALL);
1456 /****************************************************************************
1457 remove a directory
1458 ****************************************************************************/
1459 static void cmd_rmdir(void)
1461 pstring mask;
1462 fstring buf;
1464 pstrcpy(mask,cur_dir);
1466 if (!next_token(NULL,buf,NULL,sizeof(buf))) {
1467 DEBUG(0,("rmdir <dirname>\n"));
1468 return;
1470 pstrcat(mask,buf);
1472 if (!cli_rmdir(cli, mask)) {
1473 DEBUG(0,("%s removing remote directory file %s\n",
1474 cli_errstr(cli),mask));
1478 /****************************************************************************
1479 rename some files
1480 ****************************************************************************/
1481 static void cmd_rename(void)
1483 pstring src,dest;
1484 fstring buf,buf2;
1486 pstrcpy(src,cur_dir);
1487 pstrcpy(dest,cur_dir);
1489 if (!next_token(NULL,buf,NULL,sizeof(buf)) ||
1490 !next_token(NULL,buf2,NULL, sizeof(buf2))) {
1491 DEBUG(0,("rename <src> <dest>\n"));
1492 return;
1495 pstrcat(src,buf);
1496 pstrcat(dest,buf2);
1498 if (!cli_rename(cli, src, dest)) {
1499 DEBUG(0,("%s renaming files\n",cli_errstr(cli)));
1500 return;
1505 /****************************************************************************
1506 toggle the prompt flag
1507 ****************************************************************************/
1508 static void cmd_prompt(void)
1510 prompt = !prompt;
1511 DEBUG(2,("prompting is now %s\n",prompt?"on":"off"));
1515 /****************************************************************************
1516 set the newer than time
1517 ****************************************************************************/
1518 static void cmd_newer(void)
1520 fstring buf;
1521 BOOL ok;
1522 SMB_STRUCT_STAT sbuf;
1524 ok = next_token(NULL,buf,NULL,sizeof(buf));
1525 if (ok && (sys_stat(buf,&sbuf) == 0)) {
1526 newer_than = sbuf.st_mtime;
1527 DEBUG(1,("Getting files newer than %s",
1528 asctime(LocalTime(&newer_than))));
1529 } else {
1530 newer_than = 0;
1533 if (ok && newer_than == 0)
1534 DEBUG(0,("Error setting newer-than time\n"));
1537 /****************************************************************************
1538 set the archive level
1539 ****************************************************************************/
1540 static void cmd_archive(void)
1542 fstring buf;
1544 if (next_token(NULL,buf,NULL,sizeof(buf))) {
1545 archive_level = atoi(buf);
1546 } else
1547 DEBUG(0,("Archive level is %d\n",archive_level));
1550 /****************************************************************************
1551 toggle the lowercaseflag
1552 ****************************************************************************/
1553 static void cmd_lowercase(void)
1555 lowercase = !lowercase;
1556 DEBUG(2,("filename lowercasing is now %s\n",lowercase?"on":"off"));
1562 /****************************************************************************
1563 toggle the recurse flag
1564 ****************************************************************************/
1565 static void cmd_recurse(void)
1567 recurse = !recurse;
1568 DEBUG(2,("directory recursion is now %s\n",recurse?"on":"off"));
1571 /****************************************************************************
1572 toggle the translate flag
1573 ****************************************************************************/
1574 static void cmd_translate(void)
1576 translation = !translation;
1577 DEBUG(2,("CR/LF<->LF and print text translation now %s\n",
1578 translation?"on":"off"));
1582 /****************************************************************************
1583 do a printmode command
1584 ****************************************************************************/
1585 static void cmd_printmode(void)
1587 fstring buf;
1588 fstring mode;
1590 if (next_token(NULL,buf,NULL,sizeof(buf))) {
1591 if (strequal(buf,"text")) {
1592 printmode = 0;
1593 } else {
1594 if (strequal(buf,"graphics"))
1595 printmode = 1;
1596 else
1597 printmode = atoi(buf);
1601 switch(printmode)
1603 case 0:
1604 fstrcpy(mode,"text");
1605 break;
1606 case 1:
1607 fstrcpy(mode,"graphics");
1608 break;
1609 default:
1610 slprintf(mode,sizeof(mode)-1,"%d",printmode);
1611 break;
1614 DEBUG(2,("the printmode is now %s\n",mode));
1617 /****************************************************************************
1618 do the lcd command
1619 ****************************************************************************/
1620 static void cmd_lcd(void)
1622 fstring buf;
1623 pstring d;
1625 if (next_token(NULL,buf,NULL,sizeof(buf)))
1626 chdir(buf);
1627 DEBUG(2,("the local directory is now %s\n",sys_getwd(d)));
1630 /****************************************************************************
1631 list a share name
1632 ****************************************************************************/
1633 static void browse_fn(const char *name, uint32 m,
1634 const char *comment, void *state)
1636 fstring typestr;
1638 *typestr=0;
1640 switch (m)
1642 case STYPE_DISKTREE:
1643 fstrcpy(typestr,"Disk"); break;
1644 case STYPE_PRINTQ:
1645 fstrcpy(typestr,"Printer"); break;
1646 case STYPE_DEVICE:
1647 fstrcpy(typestr,"Device"); break;
1648 case STYPE_IPC:
1649 fstrcpy(typestr,"IPC"); break;
1652 printf("\t%-15.15s%-10.10s%s\n",
1653 name, typestr,comment);
1657 /****************************************************************************
1658 try and browse available connections on a host
1659 ****************************************************************************/
1660 static BOOL browse_host(BOOL sort)
1662 int ret;
1664 printf("\n\tSharename Type Comment\n");
1665 printf("\t--------- ---- -------\n");
1667 if((ret = cli_RNetShareEnum(cli, browse_fn, NULL)) == -1)
1668 printf("Error returning browse list: %s\n", cli_errstr(cli));
1670 return (ret != -1);
1673 /****************************************************************************
1674 list a server name
1675 ****************************************************************************/
1676 static void server_fn(const char *name, uint32 m,
1677 const char *comment, void *state)
1679 printf("\t%-16.16s %s\n", name, comment);
1682 /****************************************************************************
1683 try and browse available connections on a host
1684 ****************************************************************************/
1685 static BOOL list_servers(char *wk_grp)
1687 if (!cli->server_domain) return False;
1689 printf("\n\tServer Comment\n");
1690 printf("\t--------- -------\n");
1692 cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_ALL, server_fn, NULL);
1694 printf("\n\tWorkgroup Master\n");
1695 printf("\t--------- -------\n");
1697 cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_DOMAIN_ENUM, server_fn, NULL);
1698 return True;
1701 /* Some constants for completing filename arguments */
1703 #define COMPL_NONE 0 /* No completions */
1704 #define COMPL_REMOTE 1 /* Complete remote filename */
1705 #define COMPL_LOCAL 2 /* Complete local filename */
1707 /* This defines the commands supported by this client */
1708 struct
1710 char *name;
1711 void (*fn)(void);
1712 char *description;
1713 char compl_args[2]; /* Completion argument info */
1714 } commands[] =
1716 {"ls",cmd_dir,"<mask> list the contents of the current directory",{COMPL_REMOTE,COMPL_NONE}},
1717 {"dir",cmd_dir,"<mask> list the contents of the current directory",{COMPL_REMOTE,COMPL_NONE}},
1718 {"du",cmd_du,"<mask> computes the total size of the current directory",{COMPL_REMOTE,COMPL_NONE}},
1719 {"lcd",cmd_lcd,"[directory] change/report the local current working directory",{COMPL_LOCAL,COMPL_NONE}},
1720 {"cd",cmd_cd,"[directory] change/report the remote directory",{COMPL_REMOTE,COMPL_NONE}},
1721 {"pwd",cmd_pwd,"show current remote directory (same as 'cd' with no args)",{COMPL_NONE,COMPL_NONE}},
1722 {"get",cmd_get,"<remote name> [local name] get a file",{COMPL_REMOTE,COMPL_LOCAL}},
1723 {"mget",cmd_mget,"<mask> get all the matching files",{COMPL_REMOTE,COMPL_NONE}},
1724 {"put",cmd_put,"<local name> [remote name] put a file",{COMPL_LOCAL,COMPL_REMOTE}},
1725 {"mput",cmd_mput,"<mask> put all matching files",{COMPL_REMOTE,COMPL_NONE}},
1726 {"rename",cmd_rename,"<src> <dest> rename some files",{COMPL_REMOTE,COMPL_REMOTE}},
1727 {"more",cmd_more,"<remote name> view a remote file with your pager",{COMPL_REMOTE,COMPL_NONE}},
1728 {"mask",cmd_select,"<mask> mask all filenames against this",{COMPL_REMOTE,COMPL_NONE}},
1729 {"del",cmd_del,"<mask> delete all matching files",{COMPL_REMOTE,COMPL_NONE}},
1730 {"open",cmd_open,"<mask> open a file",{COMPL_REMOTE,COMPL_NONE}},
1731 {"rm",cmd_del,"<mask> delete all matching files",{COMPL_REMOTE,COMPL_NONE}},
1732 {"mkdir",cmd_mkdir,"<directory> make a directory",{COMPL_NONE,COMPL_NONE}},
1733 {"md",cmd_mkdir,"<directory> make a directory",{COMPL_NONE,COMPL_NONE}},
1734 {"rmdir",cmd_rmdir,"<directory> remove a directory",{COMPL_NONE,COMPL_NONE}},
1735 {"rd",cmd_rmdir,"<directory> remove a directory",{COMPL_NONE,COMPL_NONE}},
1736 {"prompt",cmd_prompt,"toggle prompting for filenames for mget and mput",{COMPL_NONE,COMPL_NONE}},
1737 {"recurse",cmd_recurse,"toggle directory recursion for mget and mput",{COMPL_NONE,COMPL_NONE}},
1738 {"translate",cmd_translate,"toggle text translation for printing",{COMPL_NONE,COMPL_NONE}},
1739 {"lowercase",cmd_lowercase,"toggle lowercasing of filenames for get",{COMPL_NONE,COMPL_NONE}},
1740 {"print",cmd_print,"<file name> print a file",{COMPL_NONE,COMPL_NONE}},
1741 {"printmode",cmd_printmode,"<graphics or text> set the print mode",{COMPL_NONE,COMPL_NONE}},
1742 {"queue",cmd_queue,"show the print queue",{COMPL_NONE,COMPL_NONE}},
1743 {"cancel",cmd_cancel,"<jobid> cancel a print queue entry",{COMPL_NONE,COMPL_NONE}},
1744 {"quit",cmd_quit,"logoff the server",{COMPL_NONE,COMPL_NONE}},
1745 {"q",cmd_quit,"logoff the server",{COMPL_NONE,COMPL_NONE}},
1746 {"exit",cmd_quit,"logoff the server",{COMPL_NONE,COMPL_NONE}},
1747 {"newer",cmd_newer,"<file> only mget files newer than the specified local file",{COMPL_LOCAL,COMPL_NONE}},
1748 {"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}},
1749 {"tar",cmd_tar,"tar <c|x>[IXFqbgNan] current directory to/from <file name>",{COMPL_NONE,COMPL_NONE}},
1750 {"blocksize",cmd_block,"blocksize <number> (default 20)",{COMPL_NONE,COMPL_NONE}},
1751 {"tarmode",cmd_tarmode,
1752 "<full|inc|reset|noreset> tar's behaviour towards archive bits",{COMPL_NONE,COMPL_NONE}},
1753 {"setmode",cmd_setmode,"filename <setmode string> change modes of file",{COMPL_REMOTE,COMPL_NONE}},
1754 {"help",cmd_help,"[command] give help on a command",{COMPL_NONE,COMPL_NONE}},
1755 {"?",cmd_help,"[command] give help on a command",{COMPL_NONE,COMPL_NONE}},
1756 {"history",cmd_history,"displays the command history",{COMPL_NONE,COMPL_NONE}},
1757 {"!",NULL,"run a shell command on the local system",{COMPL_NONE,COMPL_NONE}},
1758 {"",NULL,NULL,{COMPL_NONE,COMPL_NONE}}
1762 /*******************************************************************
1763 lookup a command string in the list of commands, including
1764 abbreviations
1765 ******************************************************************/
1766 static int process_tok(fstring tok)
1768 int i = 0, matches = 0;
1769 int cmd=0;
1770 int tok_len = strlen(tok);
1772 while (commands[i].fn != NULL) {
1773 if (strequal(commands[i].name,tok)) {
1774 matches = 1;
1775 cmd = i;
1776 break;
1777 } else if (strnequal(commands[i].name, tok, tok_len)) {
1778 matches++;
1779 cmd = i;
1781 i++;
1784 if (matches == 0)
1785 return(-1);
1786 else if (matches == 1)
1787 return(cmd);
1788 else
1789 return(-2);
1792 /****************************************************************************
1793 help
1794 ****************************************************************************/
1795 static void cmd_help(void)
1797 int i=0,j;
1798 fstring buf;
1800 if (next_token(NULL,buf,NULL,sizeof(buf))) {
1801 if ((i = process_tok(buf)) >= 0)
1802 DEBUG(0,("HELP %s:\n\t%s\n\n",commands[i].name,commands[i].description));
1803 } else {
1804 while (commands[i].description) {
1805 for (j=0; commands[i].description && (j<5); j++) {
1806 DEBUG(0,("%-15s",commands[i].name));
1807 i++;
1809 DEBUG(0,("\n"));
1814 /****************************************************************************
1815 process a -c command string
1816 ****************************************************************************/
1817 static void process_command_string(char *cmd)
1819 pstring line;
1820 char *ptr;
1822 while (cmd[0] != '\0') {
1823 char *p;
1824 fstring tok;
1825 int i;
1827 if ((p = strchr(cmd, ';')) == 0) {
1828 strncpy(line, cmd, 999);
1829 line[1000] = '\0';
1830 cmd += strlen(cmd);
1831 } else {
1832 if (p - cmd > 999) p = cmd + 999;
1833 strncpy(line, cmd, p - cmd);
1834 line[p - cmd] = '\0';
1835 cmd = p + 1;
1838 /* and get the first part of the command */
1839 ptr = line;
1840 if (!next_token(&ptr,tok,NULL,sizeof(tok))) continue;
1842 if ((i = process_tok(tok)) >= 0) {
1843 commands[i].fn();
1844 } else if (i == -2) {
1845 DEBUG(0,("%s: command abbreviation ambiguous\n",tok));
1846 } else {
1847 DEBUG(0,("%s: command not found\n",tok));
1852 /****************************************************************************
1853 handle completion of commands for readline
1854 ****************************************************************************/
1855 static char **completion_fn(const char *text, int start, int end)
1857 #define MAX_COMPLETIONS 100
1858 char **matches;
1859 int i, count=0;
1861 /* for words not at the start of the line fallback to filename completion */
1862 if (start) return NULL;
1864 matches = (char **)malloc(sizeof(matches[0])*MAX_COMPLETIONS);
1865 if (!matches) return NULL;
1867 matches[count++] = strdup(text);
1868 if (!matches[0]) return NULL;
1870 for (i=0;commands[i].fn && count < MAX_COMPLETIONS-1;i++) {
1871 if (strncmp(text, commands[i].name, strlen(text)) == 0) {
1872 matches[count] = strdup(commands[i].name);
1873 if (!matches[count]) return NULL;
1874 count++;
1878 if (count == 2) {
1879 free(matches[0]);
1880 matches[0] = strdup(matches[1]);
1882 matches[count] = NULL;
1883 return matches;
1887 /****************************************************************************
1888 make sure we swallow keepalives during idle time
1889 ****************************************************************************/
1890 static void readline_callback(void)
1892 fd_set fds;
1893 struct timeval timeout;
1894 static time_t last_t;
1895 time_t t;
1897 t = time(NULL);
1899 if (t - last_t < 5) return;
1901 last_t = t;
1903 again:
1904 FD_ZERO(&fds);
1905 FD_SET(cli->fd,&fds);
1907 timeout.tv_sec = 0;
1908 timeout.tv_usec = 0;
1909 sys_select_intr(cli->fd+1,&fds,&timeout);
1911 /* We deliberately use receive_smb instead of
1912 client_receive_smb as we want to receive
1913 session keepalives and then drop them here.
1915 if (FD_ISSET(cli->fd,&fds)) {
1916 receive_smb(cli->fd,cli->inbuf,0);
1917 goto again;
1920 cli_chkpath(cli, "\\");
1924 /****************************************************************************
1925 process commands on stdin
1926 ****************************************************************************/
1927 static void process_stdin(void)
1929 char *ptr;
1931 while (1) {
1932 fstring tok;
1933 fstring the_prompt;
1934 char *line;
1935 int i;
1937 /* display a prompt */
1938 slprintf(the_prompt, sizeof(the_prompt)-1, "smb: %s> ", cur_dir);
1939 line = smb_readline(the_prompt, readline_callback, completion_fn);
1941 if (!line) break;
1943 /* special case - first char is ! */
1944 if (*line == '!') {
1945 system(line + 1);
1946 continue;
1949 /* and get the first part of the command */
1950 ptr = line;
1951 if (!next_token(&ptr,tok,NULL,sizeof(tok))) continue;
1953 if ((i = process_tok(tok)) >= 0) {
1954 commands[i].fn();
1955 } else if (i == -2) {
1956 DEBUG(0,("%s: command abbreviation ambiguous\n",tok));
1957 } else {
1958 DEBUG(0,("%s: command not found\n",tok));
1964 /*****************************************************
1965 return a connection to a server
1966 *******************************************************/
1967 struct cli_state *do_connect(char *server, char *share)
1969 struct cli_state *c;
1970 struct nmb_name called, calling;
1971 char *server_n;
1972 struct in_addr ip;
1973 extern struct in_addr ipzero;
1974 fstring servicename;
1975 char *sharename;
1977 /* make a copy so we don't modify the global string 'service' */
1978 safe_strcpy(servicename, share, sizeof(servicename)-1);
1979 sharename = servicename;
1980 if (*sharename == '\\') {
1981 server = sharename+2;
1982 sharename = strchr(server,'\\');
1983 if (!sharename) return NULL;
1984 *sharename = 0;
1985 sharename++;
1988 server_n = server;
1990 ip = ipzero;
1992 make_nmb_name(&calling, global_myname, 0x0);
1993 make_nmb_name(&called , server, name_type);
1995 again:
1996 ip = ipzero;
1997 if (have_ip) ip = dest_ip;
1999 /* have to open a new connection */
2000 if (!(c=cli_initialise(NULL)) || (cli_set_port(c, port) == 0) ||
2001 !cli_connect(c, server_n, &ip)) {
2002 DEBUG(0,("Connection to %s failed\n", server_n));
2003 return NULL;
2006 c->protocol = max_protocol;
2008 if (!cli_session_request(c, &calling, &called)) {
2009 char *p;
2010 DEBUG(0,("session request to %s failed (%s)\n",
2011 called.name, cli_errstr(c)));
2012 cli_shutdown(c);
2013 if ((p=strchr(called.name, '.'))) {
2014 *p = 0;
2015 goto again;
2017 if (strcmp(called.name, "*SMBSERVER")) {
2018 make_nmb_name(&called , "*SMBSERVER", 0x20);
2019 goto again;
2021 return NULL;
2024 DEBUG(4,(" session request ok\n"));
2026 if (!cli_negprot(c)) {
2027 DEBUG(0,("protocol negotiation failed\n"));
2028 cli_shutdown(c);
2029 return NULL;
2032 if (!got_pass) {
2033 char *pass = getpass("Password: ");
2034 if (pass) {
2035 pstrcpy(password, pass);
2039 if (!cli_session_setup(c, username,
2040 password, strlen(password),
2041 password, strlen(password),
2042 workgroup)) {
2043 /* if a password was not supplied then try again with a null username */
2044 if (password[0] || !username[0] ||
2045 !cli_session_setup(c, "", "", 0, "", 0, workgroup)) {
2046 DEBUG(0,("session setup failed: %s\n", cli_errstr(c)));
2047 cli_shutdown(c);
2048 return NULL;
2050 DEBUG(0,("Anonymous login successful\n"));
2054 * These next two lines are needed to emulate
2055 * old client behaviour for people who have
2056 * scripts based on client output.
2057 * QUESTION ? Do we want to have a 'client compatibility
2058 * mode to turn these on/off ? JRA.
2061 if (*c->server_domain || *c->server_os || *c->server_type)
2062 DEBUG(1,("Domain=[%s] OS=[%s] Server=[%s]\n",
2063 c->server_domain,c->server_os,c->server_type));
2065 DEBUG(4,(" session setup ok\n"));
2067 if (!cli_send_tconX(c, sharename, "?????",
2068 password, strlen(password)+1)) {
2069 DEBUG(0,("tree connect failed: %s\n", cli_errstr(c)));
2070 cli_shutdown(c);
2071 return NULL;
2074 DEBUG(4,(" tconx ok\n"));
2076 return c;
2080 /****************************************************************************
2081 process commands from the client
2082 ****************************************************************************/
2083 static BOOL process(char *base_directory)
2085 cli = do_connect(desthost, service);
2086 if (!cli) {
2087 return(False);
2090 if (*base_directory) do_cd(base_directory);
2092 if (cmdstr) {
2093 process_command_string(cmdstr);
2094 } else {
2095 process_stdin();
2098 cli_shutdown(cli);
2099 return(True);
2102 /****************************************************************************
2103 usage on the program
2104 ****************************************************************************/
2105 static void usage(char *pname)
2107 DEBUG(0,("Usage: %s service <password> [options]", pname));
2109 DEBUG(0,("\nVersion %s\n",VERSION));
2110 DEBUG(0,("\t-s smb.conf pathname to smb.conf file\n"));
2111 DEBUG(0,("\t-O socket_options socket options to use\n"));
2112 DEBUG(0,("\t-R name resolve order use these name resolution services only\n"));
2113 DEBUG(0,("\t-M host send a winpopup message to the host\n"));
2114 DEBUG(0,("\t-i scope use this NetBIOS scope\n"));
2115 DEBUG(0,("\t-N don't ask for a password\n"));
2116 DEBUG(0,("\t-n netbios name. Use this name as my netbios name\n"));
2117 DEBUG(0,("\t-d debuglevel set the debuglevel\n"));
2118 DEBUG(0,("\t-P connect to service as a printer\n"));
2119 DEBUG(0,("\t-p port connect to the specified port\n"));
2120 DEBUG(0,("\t-l log basename. Basename for log/debug files\n"));
2121 DEBUG(0,("\t-h Print this help message.\n"));
2122 DEBUG(0,("\t-I dest IP use this IP to connect to\n"));
2123 DEBUG(0,("\t-E write messages to stderr instead of stdout\n"));
2124 DEBUG(0,("\t-U username set the network username\n"));
2125 DEBUG(0,("\t-L host get a list of shares available on a host\n"));
2126 DEBUG(0,("\t-t terminal code terminal i/o code {sjis|euc|jis7|jis8|junet|hex}\n"));
2127 DEBUG(0,("\t-m max protocol set the max protocol level\n"));
2128 DEBUG(0,("\t-A filename get the credentials from a file\n"));
2129 DEBUG(0,("\t-W workgroup set the workgroup name\n"));
2130 DEBUG(0,("\t-T<c|x>IXFqgbNan command line tar\n"));
2131 DEBUG(0,("\t-D directory start from directory\n"));
2132 DEBUG(0,("\t-c command string execute semicolon separated commands\n"));
2133 DEBUG(0,("\t-b xmit/send buffer changes the transmit/send buffer (default: 65520)\n"));
2134 DEBUG(0,("\n"));
2138 /****************************************************************************
2139 get a password from a a file or file descriptor
2140 exit on failure
2141 ****************************************************************************/
2142 static void get_password_file(void)
2144 int fd = -1;
2145 char *p;
2146 BOOL close_it = False;
2147 pstring spec;
2148 char pass[128];
2150 if ((p = getenv("PASSWD_FD")) != NULL) {
2151 pstrcpy(spec, "descriptor ");
2152 pstrcat(spec, p);
2153 sscanf(p, "%d", &fd);
2154 close_it = False;
2155 } else if ((p = getenv("PASSWD_FILE")) != NULL) {
2156 fd = sys_open(p, O_RDONLY, 0);
2157 pstrcpy(spec, p);
2158 if (fd < 0) {
2159 fprintf(stderr, "Error opening PASSWD_FILE %s: %s\n",
2160 spec, strerror(errno));
2161 exit(1);
2163 close_it = True;
2166 for(p = pass, *p = '\0'; /* ensure that pass is null-terminated */
2167 p && p - pass < sizeof(pass);) {
2168 switch (read(fd, p, 1)) {
2169 case 1:
2170 if (*p != '\n' && *p != '\0') {
2171 *++p = '\0'; /* advance p, and null-terminate pass */
2172 break;
2174 case 0:
2175 if (p - pass) {
2176 *p = '\0'; /* null-terminate it, just in case... */
2177 p = NULL; /* then force the loop condition to become false */
2178 break;
2179 } else {
2180 fprintf(stderr, "Error reading password from file %s: %s\n",
2181 spec, "empty password\n");
2182 exit(1);
2185 default:
2186 fprintf(stderr, "Error reading password from file %s: %s\n",
2187 spec, strerror(errno));
2188 exit(1);
2191 pstrcpy(password, pass);
2192 if (close_it)
2193 close(fd);
2198 /****************************************************************************
2199 handle a -L query
2200 ****************************************************************************/
2201 static int do_host_query(char *query_host)
2203 cli = do_connect(query_host, "IPC$");
2204 if (!cli)
2205 return 1;
2207 browse_host(True);
2208 list_servers(workgroup);
2210 cli_shutdown(cli);
2212 return(0);
2216 /****************************************************************************
2217 handle a tar operation
2218 ****************************************************************************/
2219 static int do_tar_op(char *base_directory)
2221 int ret;
2222 cli = do_connect(desthost, service);
2223 if (!cli)
2224 return 1;
2226 recurse=True;
2228 if (*base_directory) do_cd(base_directory);
2230 ret=process_tar();
2232 cli_shutdown(cli);
2234 return(ret);
2237 /****************************************************************************
2238 handle a message operation
2239 ****************************************************************************/
2240 static int do_message_op(void)
2242 struct in_addr ip;
2243 struct nmb_name called, calling;
2245 ip = ipzero;
2247 make_nmb_name(&calling, global_myname, 0x0);
2248 make_nmb_name(&called , desthost, name_type);
2250 ip = ipzero;
2251 if (have_ip) ip = dest_ip;
2253 if (!(cli=cli_initialise(NULL)) || (cli_set_port(cli, port) == 0) || !cli_connect(cli, desthost, &ip)) {
2254 DEBUG(0,("Connection to %s failed\n", desthost));
2255 return 1;
2258 if (!cli_session_request(cli, &calling, &called)) {
2259 DEBUG(0,("session request failed\n"));
2260 cli_shutdown(cli);
2261 return 1;
2264 send_message();
2265 cli_shutdown(cli);
2267 return 0;
2271 /****************************************************************************
2272 main program
2273 ****************************************************************************/
2274 int main(int argc,char *argv[])
2276 fstring base_directory;
2277 char *pname = argv[0];
2278 int opt;
2279 extern FILE *dbf;
2280 extern char *optarg;
2281 extern int optind;
2282 pstring query_host;
2283 BOOL message = False;
2284 extern char tar_type;
2285 static pstring servicesf = CONFIGFILE;
2286 pstring term_code;
2287 pstring new_name_resolve_order;
2288 pstring logfile;
2289 char *p;
2291 #ifdef KANJI
2292 pstrcpy(term_code, KANJI);
2293 #else /* KANJI */
2294 *term_code = 0;
2295 #endif /* KANJI */
2297 *query_host = 0;
2298 *base_directory = 0;
2300 *new_name_resolve_order = 0;
2302 DEBUGLEVEL = 2;
2304 setup_logging(pname,True);
2307 * If the -E option is given, be careful not to clobber stdout
2308 * before processing the options. 28.Feb.99, richard@hacom.nl.
2309 * Also pre-parse the -s option to get the service file name.
2312 for (opt = 1; opt < argc; opt++) {
2313 if (strcmp(argv[opt], "-E") == 0)
2314 dbf = stderr;
2315 else if(strncmp(argv[opt], "-s", 2) == 0) {
2316 if(argv[opt][2] != '\0')
2317 pstrcpy(servicesf, &argv[opt][2]);
2318 else if(argv[opt+1] != NULL) {
2320 * At least one more arg left.
2322 pstrcpy(servicesf, argv[opt+1]);
2323 } else {
2324 usage(pname);
2325 exit(1);
2328 else if(strncmp(argv[opt], "-d", 2) == 0) {
2329 AllowDebugChange = False;
2330 if(argv[opt][2] != '\0') {
2331 if (argv[opt][2] == 'A')
2332 DEBUGLEVEL = 10000;
2333 else
2334 DEBUGLEVEL = atoi(&argv[opt][2]);
2335 } else if(argv[opt+1] != NULL) {
2337 * At least one more arg left.
2339 if (argv[opt+1][0] == 'A')
2340 DEBUGLEVEL = 10000;
2341 else
2342 DEBUGLEVEL = atoi(argv[opt+1]);
2343 } else {
2344 usage(pname);
2345 exit(1);
2350 TimeInit();
2351 charset_initialise();
2353 in_client = True; /* Make sure that we tell lp_load we are */
2355 if (!lp_load(servicesf,True,False,False)) {
2356 fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf);
2359 codepage_initialise(lp_client_code_page());
2361 #ifdef WITH_SSL
2362 sslutil_init(0);
2363 #endif
2365 pstrcpy(workgroup,lp_workgroup());
2367 load_interfaces();
2368 myumask = umask(0);
2369 umask(myumask);
2371 if (getenv("USER")) {
2372 pstrcpy(username,getenv("USER"));
2374 /* modification to support userid%passwd syntax in the USER var
2375 25.Aug.97, jdblair@uab.edu */
2377 if ((p=strchr(username,'%'))) {
2378 *p = 0;
2379 pstrcpy(password,p+1);
2380 got_pass = True;
2381 memset(strchr(getenv("USER"),'%')+1,'X',strlen(password));
2383 strupper(username);
2386 /* modification to support PASSWD environmental var
2387 25.Aug.97, jdblair@uab.edu */
2388 if (getenv("PASSWD")) {
2389 pstrcpy(password,getenv("PASSWD"));
2390 got_pass = True;
2393 if (getenv("PASSWD_FD") || getenv("PASSWD_FILE")) {
2394 get_password_file();
2395 got_pass = True;
2398 if (*username == 0 && getenv("LOGNAME")) {
2399 pstrcpy(username,getenv("LOGNAME"));
2400 strupper(username);
2403 if (*username == 0) {
2404 pstrcpy(username,"GUEST");
2407 if (argc < 2) {
2408 usage(pname);
2409 exit(1);
2412 if (*argv[1] != '-') {
2413 pstrcpy(service,argv[1]);
2414 /* Convert any '/' characters in the service name to '\' characters */
2415 string_replace( service, '/','\\');
2416 argc--;
2417 argv++;
2419 if (count_chars(service,'\\') < 3) {
2420 usage(pname);
2421 printf("\n%s: Not enough '\\' characters in service\n",service);
2422 exit(1);
2425 if (argc > 1 && (*argv[1] != '-')) {
2426 got_pass = True;
2427 pstrcpy(password,argv[1]);
2428 memset(argv[1],'X',strlen(argv[1]));
2429 argc--;
2430 argv++;
2434 while ((opt =
2435 getopt(argc, argv,"s:O:R:M:i:Nn:d:Pp:l:hI:EU:L:t:m:W:T:D:c:b:A:")) != EOF) {
2436 switch (opt) {
2437 case 's':
2438 pstrcpy(servicesf, optarg);
2439 break;
2440 case 'O':
2441 pstrcpy(user_socket_options,optarg);
2442 break;
2443 case 'R':
2444 pstrcpy(new_name_resolve_order, optarg);
2445 break;
2446 case 'M':
2447 name_type = 0x03; /* messages are sent to NetBIOS name type 0x3 */
2448 pstrcpy(desthost,optarg);
2449 message = True;
2450 break;
2451 case 'i':
2453 extern pstring global_scope;
2454 pstrcpy(global_scope,optarg);
2455 strupper(global_scope);
2457 break;
2458 case 'N':
2459 got_pass = True;
2460 break;
2461 case 'n':
2462 pstrcpy(global_myname,optarg);
2463 break;
2464 case 'd':
2465 if (*optarg == 'A')
2466 DEBUGLEVEL = 10000;
2467 else
2468 DEBUGLEVEL = atoi(optarg);
2469 AllowDebugChange = False;
2470 break;
2471 case 'P':
2472 /* not needed anymore */
2473 break;
2474 case 'p':
2475 port = atoi(optarg);
2476 break;
2477 case 'l':
2478 slprintf(logfile,sizeof(logfile)-1, "%s.client",optarg);
2479 lp_set_logfile(logfile);
2480 break;
2481 case 'h':
2482 usage(pname);
2483 exit(0);
2484 break;
2485 case 'I':
2487 dest_ip = *interpret_addr2(optarg);
2488 if (zero_ip(dest_ip))
2489 exit(1);
2490 have_ip = True;
2492 break;
2493 case 'E':
2494 dbf = stderr;
2495 break;
2496 case 'U':
2498 char *lp;
2499 pstrcpy(username,optarg);
2500 if ((lp=strchr(username,'%'))) {
2501 *lp = 0;
2502 pstrcpy(password,lp+1);
2503 got_pass = True;
2504 memset(strchr(optarg,'%')+1,'X',strlen(password));
2507 break;
2509 case 'A':
2511 FILE *auth;
2512 fstring buf;
2513 uint16 len = 0;
2514 char *ptr, *val, *param;
2516 if ((auth=sys_fopen(optarg, "r")) == NULL)
2518 /* fail if we can't open the credentials file */
2519 DEBUG(0,("ERROR: Unable to open credentials file!\n"));
2520 exit (-1);
2523 while (!feof(auth))
2525 /* get a line from the file */
2526 if (!fgets (buf, sizeof(buf), auth))
2527 continue;
2528 len = strlen(buf);
2530 if ((len) && (buf[len-1]=='\n'))
2532 buf[len-1] = '\0';
2533 len--;
2535 if (len == 0)
2536 continue;
2538 /* break up the line into parameter & value.
2539 will need to eat a little whitespace possibly */
2540 param = buf;
2541 if (!(ptr = strchr (buf, '=')))
2542 continue;
2543 val = ptr+1;
2544 *ptr = '\0';
2546 /* eat leading white space */
2547 while ((*val!='\0') && ((*val==' ') || (*val=='\t')))
2548 val++;
2550 if (strwicmp("password", param) == 0)
2552 pstrcpy(password, val);
2553 got_pass = True;
2555 else if (strwicmp("username", param) == 0)
2556 pstrcpy(username, val);
2557 else if (strwicmp("domain", param) == 0)
2558 pstrcpy(workgroup,val);
2559 memset(buf, 0, sizeof(buf));
2561 fclose(auth);
2563 break;
2565 case 'L':
2566 p = optarg;
2567 while(*p == '\\' || *p == '/')
2568 p++;
2569 pstrcpy(query_host,p);
2570 break;
2571 case 't':
2572 pstrcpy(term_code, optarg);
2573 break;
2574 case 'm':
2575 max_protocol = interpret_protocol(optarg, max_protocol);
2576 break;
2577 case 'W':
2578 pstrcpy(workgroup,optarg);
2579 break;
2580 case 'T':
2581 if (!tar_parseargs(argc, argv, optarg, optind)) {
2582 usage(pname);
2583 exit(1);
2585 break;
2586 case 'D':
2587 pstrcpy(base_directory,optarg);
2588 break;
2589 case 'c':
2590 cmdstr = optarg;
2591 break;
2592 case 'b':
2593 io_bufsize = MAX(1, atoi(optarg));
2594 break;
2595 default:
2596 usage(pname);
2597 exit(1);
2601 get_myname((*global_myname)?NULL:global_myname);
2603 if(*new_name_resolve_order)
2604 lp_set_name_resolve_order(new_name_resolve_order);
2606 if (*term_code)
2607 interpret_coding_system(term_code);
2609 if (!tar_type && !*query_host && !*service && !message) {
2610 usage(pname);
2611 exit(1);
2614 DEBUG( 3, ( "Client started (version %s).\n", VERSION ) );
2616 if (tar_type) {
2617 if (cmdstr)
2618 process_command_string(cmdstr);
2619 return do_tar_op(base_directory);
2622 if ((p=strchr(query_host,'#'))) {
2623 *p = 0;
2624 p++;
2625 sscanf(p, "%x", &name_type);
2628 if (*query_host) {
2629 return do_host_query(query_host);
2632 if (message) {
2633 return do_message_op();
2636 if (!process(base_directory)) {
2637 return(1);
2640 return(0);