2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1994-1998
5 Copyright (C) Simo Sorce 2001-2002
6 Copyright (C) Jelmer Vernooij 2003
7 Copyright (C) Gerald (Jerry) Carter 2004
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "client/client_proto.h"
26 #include "include/rpc_client.h"
31 extern BOOL AllowDebugChange;
32 extern BOOL override_logfile;
34 extern BOOL in_client;
36 pstring cur_dir = "\\";
37 static pstring cd_path = "";
38 static pstring service;
39 static pstring desthost;
40 static pstring username;
41 static pstring calling_name;
42 static BOOL grepable=False;
43 static char *cmdstr = NULL;
45 static int io_bufsize = 64512;
47 static int name_type = 0x20;
48 extern int max_protocol;
50 static int process_tok(pstring tok);
51 static int cmd_help(void);
53 static TALLOC_CTX *ctx;
54 #define CREATE_ACCESS_READ READ_CONTROL_ACCESS
57 /* 30 second timeout on most commands */
58 #define CLIENT_TIMEOUT (30*1000)
59 #define SHORT_TIMEOUT (5*1000)
61 /* value for unused fid field in trans2 secondary request */
62 #define FID_UNUSED (0xFFFF)
64 time_t newer_than = 0;
65 static int archive_level = 0;
67 static BOOL translation = False;
70 /* clitar bits insert */
73 extern BOOL tar_reset;
77 static BOOL prompt = True;
79 static BOOL recurse = False;
80 static BOOL showacls = False;
81 BOOL lowercase = False;
83 static struct in_addr dest_ip;
85 #define SEPARATORS " \t\n\r"
87 static BOOL abort_mget = True;
89 static pstring fileselection = "";
91 extern file_info def_finfo;
94 SMB_BIG_UINT get_total_size = 0;
95 unsigned int get_total_time_ms = 0;
96 static SMB_BIG_UINT put_total_size = 0;
97 static unsigned int put_total_time_ms = 0;
100 static double dir_total;
102 /* root cli_state connection */
104 struct cli_state *cli;
106 static char CLI_DIRSEP_CHAR = '\\';
107 static char CLI_DIRSEP_STR[] = { '\\', '\0' };
109 /****************************************************************************
110 Write to a local file with CR/LF->LF translation if appropriate. Return the
111 number taken from the buffer. This may not equal the number written.
112 ****************************************************************************/
114 static int writefile(int f, char *b, int n)
124 if (*b == '\r' && (i<(n-1)) && *(b+1) == '\n') {
127 if (write(f, b, 1) != 1) {
137 /****************************************************************************
138 Read from a file with LF->CR/LF translation if appropriate. Return the
139 number read. read approx n bytes.
140 ****************************************************************************/
142 static int readfile(char *b, int n, XFILE *f)
148 return x_fread(b,1,n,f);
151 while (i < (n - 1) && (i < BUFFER_SIZE)) {
152 if ((c = x_getc(f)) == EOF) {
156 if (c == '\n') { /* change all LFs to CR/LF */
166 /****************************************************************************
168 ****************************************************************************/
170 static void send_message(void)
175 if (!cli_message_start(cli, desthost, username, &grp_id)) {
176 d_printf("message start: %s\n", cli_errstr(cli));
181 d_printf("Connected. Type your message, ending it with a Control-D\n");
183 while (!feof(stdin) && total_len < 1600) {
184 int maxlen = MIN(1600 - total_len,127);
191 for (l=0;l<maxlen && (c=fgetc(stdin))!=EOF;l++) {
197 if (!cli_message_text(cli, msg, l, grp_id)) {
198 d_printf("SMBsendtxt failed (%s)\n",cli_errstr(cli));
205 if (total_len >= 1600)
206 d_printf("the message was truncated to 1600 bytes\n");
208 d_printf("sent %d bytes\n",total_len);
210 if (!cli_message_end(cli, grp_id)) {
211 d_printf("SMBsendend failed (%s)\n",cli_errstr(cli));
216 /****************************************************************************
217 Check the space on a device.
218 ****************************************************************************/
220 static int do_dskattr(void)
222 int total, bsize, avail;
223 struct cli_state *targetcli;
226 if ( !cli_resolve_path( "", cli, cur_dir, &targetcli, targetpath ) ) {
227 d_printf("Error in dskattr: %s\n", cli_errstr(cli));
231 if (!cli_dskattr(targetcli, &bsize, &total, &avail)) {
232 d_printf("Error in dskattr: %s\n",cli_errstr(targetcli));
236 d_printf("\n\t\t%d blocks of size %d. %d blocks available\n",
237 total, bsize, avail);
242 /****************************************************************************
244 ****************************************************************************/
246 static int cmd_pwd(void)
248 d_printf("Current directory is %s",service);
249 d_printf("%s\n",cur_dir);
253 /****************************************************************************
254 Change directory - inner section.
255 ****************************************************************************/
257 static int do_cd(char *newdir)
263 struct cli_state *targetcli;
264 SMB_STRUCT_STAT sbuf;
270 /* Save the current directory in case the new directory is invalid */
272 pstrcpy(saved_dir, cur_dir);
274 if (*p == CLI_DIRSEP_CHAR)
279 if ((cur_dir[0] != '\0') && (*(cur_dir+strlen(cur_dir)-1) != CLI_DIRSEP_CHAR)) {
280 pstrcat(cur_dir, CLI_DIRSEP_STR);
283 dos_clean_name(cur_dir);
284 pstrcpy( dname, cur_dir );
285 pstrcat(cur_dir,CLI_DIRSEP_STR);
286 dos_clean_name(cur_dir);
288 if ( !cli_resolve_path( "", cli, dname, &targetcli, targetpath ) ) {
289 d_printf("cd %s: %s\n", dname, cli_errstr(cli));
290 pstrcpy(cur_dir,saved_dir);
295 if ( strequal(targetpath,CLI_DIRSEP_STR ) )
298 /* Use a trans2_qpathinfo to test directories for modern servers.
299 Except Win9x doesn't support the qpathinfo_basic() call..... */
301 if ( targetcli->protocol > PROTOCOL_LANMAN2 && !targetcli->win95 ) {
302 if ( !cli_qpathinfo_basic( targetcli, targetpath, &sbuf, &attributes ) ) {
303 d_printf("cd %s: %s\n", dname, cli_errstr(targetcli));
304 pstrcpy(cur_dir,saved_dir);
308 if ( !(attributes&FILE_ATTRIBUTE_DIRECTORY) ) {
309 d_printf("cd %s: not a directory\n", dname);
310 pstrcpy(cur_dir,saved_dir);
314 pstrcat( targetpath, CLI_DIRSEP_STR );
315 dos_clean_name( targetpath );
317 if ( !cli_chkpath(targetcli, targetpath) ) {
318 d_printf("cd %s: %s\n", dname, cli_errstr(targetcli));
319 pstrcpy(cur_dir,saved_dir);
328 pstrcpy(cd_path,cur_dir);
332 /****************************************************************************
334 ****************************************************************************/
336 static int cmd_cd(void)
341 if (next_token_nr(NULL,buf,NULL,sizeof(buf)))
344 d_printf("Current directory is %s\n",cur_dir);
349 /*******************************************************************
350 Decide if a file should be operated on.
351 ********************************************************************/
353 static BOOL do_this_one(file_info *finfo)
355 if (finfo->mode & aDIR)
358 if (*fileselection &&
359 !mask_match(finfo->name,fileselection,False)) {
360 DEBUG(3,("mask_match %s failed\n", finfo->name));
364 if (newer_than && finfo->mtime_ts.tv_sec < newer_than) {
365 DEBUG(3,("newer_than %s failed\n", finfo->name));
369 if ((archive_level==1 || archive_level==2) && !(finfo->mode & aARCH)) {
370 DEBUG(3,("archive %s failed\n", finfo->name));
377 /****************************************************************************
378 Display info about a file.
379 ****************************************************************************/
381 static void display_finfo(file_info *finfo)
383 if (do_this_one(finfo)) {
384 time_t t = finfo->mtime_ts.tv_sec; /* the time is assumed to be passed as GMT */
386 d_printf(" %-30s%7.7s %8.0f %s",
388 attrib_string(finfo->mode),
391 dir_total += finfo->size;
396 /* skip if this is . or .. */
397 if ( strequal(finfo->name,"..") || strequal(finfo->name,".") )
399 /* create absolute filename for cli_nt_create() FIXME */
400 pstrcpy( afname, cwd);
401 pstrcat( afname, "\\");
402 pstrcat( afname, finfo->name);
403 /* print file meta date header */
404 d_printf( "FILENAME:%s\n", afname);
405 d_printf( "MODE:%s\n", attrib_string(finfo->mode));
406 d_printf( "SIZE:%.0f\n", (double)finfo->size);
407 d_printf( "MTIME:%s", time_to_asc(&t));
408 fnum = cli_nt_create(cli, afname, CREATE_ACCESS_READ);
410 DEBUG( 0, ("display_finfo() Failed to open %s: %s\n",
415 sd = cli_query_secdesc(cli, fnum, ctx);
417 DEBUG( 0, ("display_finfo() failed to "
418 "get security descriptor: %s",
421 display_sec_desc(sd);
428 /****************************************************************************
429 Accumulate size of a file.
430 ****************************************************************************/
432 static void do_du(file_info *finfo)
434 if (do_this_one(finfo)) {
435 dir_total += finfo->size;
439 static BOOL do_list_recurse;
440 static BOOL do_list_dirs;
441 static char *do_list_queue = 0;
442 static long do_list_queue_size = 0;
443 static long do_list_queue_start = 0;
444 static long do_list_queue_end = 0;
445 static void (*do_list_fn)(file_info *);
447 /****************************************************************************
448 Functions for do_list_queue.
449 ****************************************************************************/
452 * The do_list_queue is a NUL-separated list of strings stored in a
453 * char*. Since this is a FIFO, we keep track of the beginning and
454 * ending locations of the data in the queue. When we overflow, we
455 * double the size of the char*. When the start of the data passes
456 * the midpoint, we move everything back. This is logically more
457 * complex than a linked list, but easier from a memory management
458 * angle. In any memory error condition, do_list_queue is reset.
459 * Functions check to ensure that do_list_queue is non-NULL before
463 static void reset_do_list_queue(void)
465 SAFE_FREE(do_list_queue);
466 do_list_queue_size = 0;
467 do_list_queue_start = 0;
468 do_list_queue_end = 0;
471 static void init_do_list_queue(void)
473 reset_do_list_queue();
474 do_list_queue_size = 1024;
475 do_list_queue = (char *)SMB_MALLOC(do_list_queue_size);
476 if (do_list_queue == 0) {
477 d_printf("malloc fail for size %d\n",
478 (int)do_list_queue_size);
479 reset_do_list_queue();
481 memset(do_list_queue, 0, do_list_queue_size);
485 static void adjust_do_list_queue(void)
488 * If the starting point of the queue is more than half way through,
489 * move everything toward the beginning.
492 if (do_list_queue == NULL) {
493 DEBUG(4,("do_list_queue is empty\n"));
494 do_list_queue_start = do_list_queue_end = 0;
498 if (do_list_queue_start == do_list_queue_end) {
499 DEBUG(4,("do_list_queue is empty\n"));
500 do_list_queue_start = do_list_queue_end = 0;
501 *do_list_queue = '\0';
502 } else if (do_list_queue_start > (do_list_queue_size / 2)) {
503 DEBUG(4,("sliding do_list_queue backward\n"));
504 memmove(do_list_queue,
505 do_list_queue + do_list_queue_start,
506 do_list_queue_end - do_list_queue_start);
507 do_list_queue_end -= do_list_queue_start;
508 do_list_queue_start = 0;
512 static void add_to_do_list_queue(const char* entry)
514 long new_end = do_list_queue_end + ((long)strlen(entry)) + 1;
515 while (new_end > do_list_queue_size) {
516 do_list_queue_size *= 2;
517 DEBUG(4,("enlarging do_list_queue to %d\n",
518 (int)do_list_queue_size));
519 do_list_queue = (char *)SMB_REALLOC(do_list_queue, do_list_queue_size);
520 if (! do_list_queue) {
521 d_printf("failure enlarging do_list_queue to %d bytes\n",
522 (int)do_list_queue_size);
523 reset_do_list_queue();
525 memset(do_list_queue + do_list_queue_size / 2,
526 0, do_list_queue_size / 2);
530 safe_strcpy_base(do_list_queue + do_list_queue_end,
531 entry, do_list_queue, do_list_queue_size);
532 do_list_queue_end = new_end;
533 DEBUG(4,("added %s to do_list_queue (start=%d, end=%d)\n",
534 entry, (int)do_list_queue_start, (int)do_list_queue_end));
538 static char *do_list_queue_head(void)
540 return do_list_queue + do_list_queue_start;
543 static void remove_do_list_queue_head(void)
545 if (do_list_queue_end > do_list_queue_start) {
546 do_list_queue_start += strlen(do_list_queue_head()) + 1;
547 adjust_do_list_queue();
548 DEBUG(4,("removed head of do_list_queue (start=%d, end=%d)\n",
549 (int)do_list_queue_start, (int)do_list_queue_end));
553 static int do_list_queue_empty(void)
555 return (! (do_list_queue && *do_list_queue));
558 /****************************************************************************
559 A helper for do_list.
560 ****************************************************************************/
562 static void do_list_helper(const char *mntpoint, file_info *f, const char *mask, void *state)
566 /* save the directory */
567 pstrcpy( f->dir, mask );
568 if ( (dir_end = strrchr( f->dir, CLI_DIRSEP_CHAR )) != NULL ) {
572 if (f->mode & aDIR) {
573 if (do_list_dirs && do_this_one(f)) {
576 if (do_list_recurse &&
577 !strequal(f->name,".") &&
578 !strequal(f->name,"..")) {
583 d_printf("Empty dir name returned. Possible server misconfiguration.\n");
587 pstrcpy(mask2, mntpoint);
588 pstrcat(mask2, mask);
589 p = strrchr_m(mask2,CLI_DIRSEP_CHAR);
593 pstrcat(mask2, f->name);
594 pstrcat(mask2,"\\*");
595 add_to_do_list_queue(mask2);
600 if (do_this_one(f)) {
605 /****************************************************************************
606 A wrapper around cli_list that adds recursion.
607 ****************************************************************************/
609 void do_list(const char *mask,uint16 attribute,void (*fn)(file_info *),BOOL rec, BOOL dirs)
611 static int in_do_list = 0;
612 struct cli_state *targetcli;
615 if (in_do_list && rec) {
616 fprintf(stderr, "INTERNAL ERROR: do_list called recursively when the recursive flag is true\n");
622 do_list_recurse = rec;
627 init_do_list_queue();
628 add_to_do_list_queue(mask);
630 while (! do_list_queue_empty()) {
632 * Need to copy head so that it doesn't become
633 * invalid inside the call to cli_list. This
634 * would happen if the list were expanded
636 * Fix from E. Jay Berkenbilt (ejb@ql.org)
639 pstrcpy(head, do_list_queue_head());
643 if ( !cli_resolve_path( "", cli, head, &targetcli, targetpath ) ) {
644 d_printf("do_list: [%s] %s\n", head, cli_errstr(cli));
645 remove_do_list_queue_head();
649 cli_list(targetcli, targetpath, attribute, do_list_helper, NULL);
650 remove_do_list_queue_head();
651 if ((! do_list_queue_empty()) && (fn == display_finfo)) {
652 char* next_file = do_list_queue_head();
654 if ((strlen(next_file) >= 2) &&
655 (next_file[strlen(next_file) - 1] == '*') &&
656 (next_file[strlen(next_file) - 2] == CLI_DIRSEP_CHAR)) {
657 save_ch = next_file +
658 strlen(next_file) - 2;
660 if (showacls) /* cwd is only used if showacls is on */
661 pstrcpy( cwd, next_file);
663 if (!showacls) /* don't disturbe the showacls output */
664 d_printf("\n%s\n",next_file);
666 *save_ch = CLI_DIRSEP_CHAR;
673 if ( cli_resolve_path( "", cli, mask, &targetcli, targetpath ) ) {
674 if (cli_list(targetcli, targetpath, attribute, do_list_helper, NULL) == -1)
675 d_printf("%s listing %s\n", cli_errstr(targetcli), targetpath);
678 d_printf("do_list: [%s] %s\n", mask, cli_errstr(cli));
683 reset_do_list_queue();
686 /****************************************************************************
687 Get a directory listing.
688 ****************************************************************************/
690 static int cmd_dir(void)
692 uint16 attribute = aDIR | aSYSTEM | aHIDDEN;
699 if (strcmp(cur_dir, CLI_DIRSEP_STR) != 0) {
700 pstrcpy(mask,cur_dir);
701 if ((mask[0] != '\0') && (mask[strlen(mask)-1]!=CLI_DIRSEP_CHAR))
702 pstrcat(mask,CLI_DIRSEP_STR);
704 pstrcpy(mask, CLI_DIRSEP_STR);
707 if (next_token_nr(NULL,buf,NULL,sizeof(buf))) {
709 if (*p == CLI_DIRSEP_CHAR)
717 do_list(mask, attribute, display_finfo, recurse, True);
721 DEBUG(3, ("Total bytes listed: %.0f\n", dir_total));
726 /****************************************************************************
727 Get a directory listing.
728 ****************************************************************************/
730 static int cmd_du(void)
732 uint16 attribute = aDIR | aSYSTEM | aHIDDEN;
739 pstrcpy(mask,cur_dir);
740 if ((mask[0] != '\0') && (mask[strlen(mask)-1]!=CLI_DIRSEP_CHAR))
741 pstrcat(mask,CLI_DIRSEP_STR);
743 if (next_token_nr(NULL,buf,NULL,sizeof(buf))) {
745 if (*p == CLI_DIRSEP_CHAR)
753 do_list(mask, attribute, do_du, recurse, True);
757 d_printf("Total number of bytes: %.0f\n", dir_total);
762 /****************************************************************************
763 Get a file from rname to lname
764 ****************************************************************************/
766 static int do_get(char *rname, char *lname, BOOL reget)
768 int handle = 0, fnum;
769 BOOL newhandle = False;
771 struct timeval tp_start;
772 int read_size = io_bufsize;
778 struct cli_state *targetcli;
786 if ( !cli_resolve_path( "", cli, rname, &targetcli, targetname ) ) {
787 d_printf("Failed to open %s: %s\n", rname, cli_errstr(cli));
791 GetTimeOfDay(&tp_start);
793 if ( targetcli->dfsroot ) {
796 /* we need to refer to the full \server\share\path format
799 pstrcpy( path, targetname );
800 cli_dfs_make_full_path( targetname, targetcli->desthost,
801 targetcli->share, path);
804 fnum = cli_open(targetcli, targetname, O_RDONLY, DENY_NONE);
807 d_printf("%s opening remote file %s\n",cli_errstr(cli),rname);
811 if(!strcmp(lname,"-")) {
812 handle = fileno(stdout);
815 handle = sys_open(lname, O_WRONLY|O_CREAT, 0644);
817 start = sys_lseek(handle, 0, SEEK_END);
819 d_printf("Error seeking local file\n");
824 handle = sys_open(lname, O_WRONLY|O_CREAT|O_TRUNC, 0644);
829 d_printf("Error opening local file %s\n",lname);
834 if (!cli_qfileinfo(targetcli, fnum,
835 &attr, &size, NULL, NULL, NULL, NULL, NULL) &&
836 !cli_getattrE(targetcli, fnum,
837 &attr, &size, NULL, NULL, NULL)) {
838 d_printf("getattrib: %s\n",cli_errstr(targetcli));
842 DEBUG(1,("getting file %s of size %.0f as %s ",
843 rname, (double)size, lname));
845 if(!(data = (char *)SMB_MALLOC(read_size))) {
846 d_printf("malloc fail for size %d\n", read_size);
847 cli_close(targetcli, fnum);
852 int n = cli_read(targetcli, fnum, data, nread + start, read_size);
857 if (writefile(handle,data, n) != n) {
858 d_printf("Error writing local file\n");
866 if (nread + start < size) {
867 DEBUG (0, ("Short read when getting file %s. Only got %ld bytes.\n",
868 rname, (long)nread));
875 if (!cli_close(targetcli, fnum)) {
876 d_printf("Error %s closing remote file\n",cli_errstr(cli));
884 if (archive_level >= 2 && (attr & aARCH)) {
885 cli_setatr(cli, rname, attr & ~(uint16)aARCH, 0);
889 struct timeval tp_end;
892 GetTimeOfDay(&tp_end);
894 (tp_end.tv_sec - tp_start.tv_sec)*1000 +
895 (tp_end.tv_usec - tp_start.tv_usec)/1000;
896 get_total_time_ms += this_time;
897 get_total_size += nread;
899 DEBUG(1,("(%3.1f kb/s) (average %3.1f kb/s)\n",
900 nread / (1.024*this_time + 1.0e-4),
901 get_total_size / (1.024*get_total_time_ms)));
907 /****************************************************************************
909 ****************************************************************************/
911 static int cmd_get(void)
917 pstrcpy(rname,cur_dir);
918 pstrcat(rname,CLI_DIRSEP_STR);
920 p = rname + strlen(rname);
922 if (!next_token_nr(NULL,p,NULL,sizeof(rname)-strlen(rname))) {
923 d_printf("get <filename>\n");
927 dos_clean_name(rname);
929 next_token_nr(NULL,lname,NULL,sizeof(lname));
931 return do_get(rname, lname, False);
934 /****************************************************************************
935 Do an mget operation on one file.
936 ****************************************************************************/
938 static void do_mget(file_info *finfo)
942 pstring saved_curdir;
945 if (strequal(finfo->name,".") || strequal(finfo->name,".."))
949 d_printf("mget aborted\n");
953 if (finfo->mode & aDIR)
954 slprintf(quest,sizeof(pstring)-1,
955 "Get directory %s? ",finfo->name);
957 slprintf(quest,sizeof(pstring)-1,
958 "Get file %s? ",finfo->name);
960 if (prompt && !yesno(quest))
963 if (!(finfo->mode & aDIR)) {
964 pstrcpy(rname,cur_dir);
965 pstrcat(rname,finfo->name);
966 do_get(rname, finfo->name, False);
970 /* handle directories */
971 pstrcpy(saved_curdir,cur_dir);
973 pstrcat(cur_dir,finfo->name);
974 pstrcat(cur_dir,CLI_DIRSEP_STR);
976 unix_format(finfo->name);
978 strlower_m(finfo->name);
980 if (!directory_exist(finfo->name,NULL) &&
981 mkdir(finfo->name,0777) != 0) {
982 d_printf("failed to create directory %s\n",finfo->name);
983 pstrcpy(cur_dir,saved_curdir);
987 if (chdir(finfo->name) != 0) {
988 d_printf("failed to chdir to directory %s\n",finfo->name);
989 pstrcpy(cur_dir,saved_curdir);
993 pstrcpy(mget_mask,cur_dir);
994 pstrcat(mget_mask,"*");
996 do_list(mget_mask, aSYSTEM | aHIDDEN | aDIR,do_mget,False, True);
998 pstrcpy(cur_dir,saved_curdir);
1001 /****************************************************************************
1002 View the file using the pager.
1003 ****************************************************************************/
1005 static int cmd_more(void)
1007 pstring rname,lname,pager_cmd;
1012 pstrcpy(rname,cur_dir);
1013 pstrcat(rname,CLI_DIRSEP_STR);
1015 slprintf(lname,sizeof(lname)-1, "%s/smbmore.XXXXXX",tmpdir());
1016 fd = smb_mkstemp(lname);
1018 d_printf("failed to create temporary file for more\n");
1023 if (!next_token_nr(NULL,rname+strlen(rname),NULL,sizeof(rname)-strlen(rname))) {
1024 d_printf("more <filename>\n");
1028 dos_clean_name(rname);
1030 rc = do_get(rname, lname, False);
1032 pager=getenv("PAGER");
1034 slprintf(pager_cmd,sizeof(pager_cmd)-1,
1035 "%s %s",(pager? pager:PAGER), lname);
1042 /****************************************************************************
1044 ****************************************************************************/
1046 static int cmd_mget(void)
1048 uint16 attribute = aSYSTEM | aHIDDEN;
1060 while (next_token_nr(NULL,p,NULL,sizeof(buf))) {
1061 pstrcpy(mget_mask,cur_dir);
1062 if ((mget_mask[0] != '\0') && (mget_mask[strlen(mget_mask)-1]!=CLI_DIRSEP_CHAR))
1063 pstrcat(mget_mask,CLI_DIRSEP_STR);
1065 if (*p == CLI_DIRSEP_CHAR)
1066 pstrcpy(mget_mask,p);
1068 pstrcat(mget_mask,p);
1069 do_list(mget_mask, attribute,do_mget,False,True);
1073 pstrcpy(mget_mask,cur_dir);
1074 if(mget_mask[strlen(mget_mask)-1]!=CLI_DIRSEP_CHAR)
1075 pstrcat(mget_mask,CLI_DIRSEP_STR);
1076 pstrcat(mget_mask,"*");
1077 do_list(mget_mask, attribute,do_mget,False,True);
1083 /****************************************************************************
1084 Make a directory of name "name".
1085 ****************************************************************************/
1087 static BOOL do_mkdir(char *name)
1089 struct cli_state *targetcli;
1092 if ( !cli_resolve_path( "", cli, name, &targetcli, targetname ) ) {
1093 d_printf("mkdir %s: %s\n", name, cli_errstr(cli));
1097 if (!cli_mkdir(targetcli, targetname)) {
1098 d_printf("%s making remote directory %s\n",
1099 cli_errstr(targetcli),name);
1106 /****************************************************************************
1107 Show 8.3 name of a file.
1108 ****************************************************************************/
1110 static BOOL do_altname(char *name)
1113 if (!NT_STATUS_IS_OK(cli_qpathinfo_alt_name(cli, name, altname))) {
1114 d_printf("%s getting alt name for %s\n",
1115 cli_errstr(cli),name);
1118 d_printf("%s\n", altname);
1123 /****************************************************************************
1125 ****************************************************************************/
1127 static int cmd_quit(void)
1130 talloc_destroy( ctx);
1136 /****************************************************************************
1138 ****************************************************************************/
1140 static int cmd_mkdir(void)
1146 pstrcpy(mask,cur_dir);
1148 if (!next_token_nr(NULL,p,NULL,sizeof(buf))) {
1150 d_printf("mkdir <dirname>\n");
1161 trim_char(ddir,'.','\0');
1162 p = strtok(ddir,"/\\");
1165 if (!cli_chkpath(cli, ddir2)) {
1168 pstrcat(ddir2,CLI_DIRSEP_STR);
1169 p = strtok(NULL,"/\\");
1178 /****************************************************************************
1180 ****************************************************************************/
1182 static int cmd_altname(void)
1188 pstrcpy(name,cur_dir);
1190 if (!next_token_nr(NULL,p,NULL,sizeof(buf))) {
1191 d_printf("altname <file>\n");
1201 /****************************************************************************
1203 ****************************************************************************/
1205 static int do_put(char *rname, char *lname, BOOL reput)
1209 SMB_OFF_T start = 0;
1212 int maxwrite = io_bufsize;
1214 struct timeval tp_start;
1215 struct cli_state *targetcli;
1218 if ( !cli_resolve_path( "", cli, rname, &targetcli, targetname ) ) {
1219 d_printf("Failed to open %s: %s\n", rname, cli_errstr(cli));
1223 GetTimeOfDay(&tp_start);
1226 fnum = cli_open(targetcli, targetname, O_RDWR|O_CREAT, DENY_NONE);
1228 if (!cli_qfileinfo(targetcli, fnum, NULL, &start, NULL, NULL, NULL, NULL, NULL) &&
1229 !cli_getattrE(targetcli, fnum, NULL, &start, NULL, NULL, NULL)) {
1230 d_printf("getattrib: %s\n",cli_errstr(cli));
1235 fnum = cli_open(targetcli, targetname, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE);
1239 d_printf("%s opening remote file %s\n",cli_errstr(targetcli),rname);
1243 /* allow files to be piped into smbclient
1246 Note that in this case this function will exit(0) rather
1248 if (!strcmp(lname, "-")) {
1250 /* size of file is not known */
1252 f = x_fopen(lname,O_RDONLY, 0);
1254 if (x_tseek(f, start, SEEK_SET) == -1) {
1255 d_printf("Error seeking local file\n");
1262 d_printf("Error opening local file %s\n",lname);
1266 DEBUG(1,("putting file %s as %s ",lname,
1269 buf = (char *)SMB_MALLOC(maxwrite);
1271 d_printf("ERROR: Not enough memory!\n");
1274 while (!x_feof(f)) {
1278 if ((n = readfile(buf,n,f)) < 1) {
1279 if((n == 0) && x_feof(f))
1280 break; /* Empty local file. */
1282 d_printf("Error reading local file: %s\n", strerror(errno));
1287 ret = cli_write(targetcli, fnum, 0, buf, nread + start, n);
1290 d_printf("Error writing file: %s\n", cli_errstr(cli));
1298 if (!cli_close(targetcli, fnum)) {
1299 d_printf("%s closing remote file %s\n",cli_errstr(cli),rname);
1313 struct timeval tp_end;
1316 GetTimeOfDay(&tp_end);
1318 (tp_end.tv_sec - tp_start.tv_sec)*1000 +
1319 (tp_end.tv_usec - tp_start.tv_usec)/1000;
1320 put_total_time_ms += this_time;
1321 put_total_size += nread;
1323 DEBUG(1,("(%3.1f kb/s) (average %3.1f kb/s)\n",
1324 nread / (1.024*this_time + 1.0e-4),
1325 put_total_size / (1.024*put_total_time_ms)));
1336 /****************************************************************************
1338 ****************************************************************************/
1340 static int cmd_put(void)
1347 pstrcpy(rname,cur_dir);
1348 pstrcat(rname,CLI_DIRSEP_STR);
1350 if (!next_token_nr(NULL,p,NULL,sizeof(buf))) {
1351 d_printf("put <filename>\n");
1356 if (next_token_nr(NULL,p,NULL,sizeof(buf)))
1359 pstrcat(rname,lname);
1361 dos_clean_name(rname);
1365 /* allow '-' to represent stdin
1366 jdblair, 24.jun.98 */
1367 if (!file_exist(lname,&st) &&
1368 (strcmp(lname,"-"))) {
1369 d_printf("%s does not exist\n",lname);
1374 return do_put(rname, lname, False);
1377 /*************************************
1378 File list structure.
1379 *************************************/
1381 static struct file_list {
1382 struct file_list *prev, *next;
1387 /****************************************************************************
1388 Free a file_list structure.
1389 ****************************************************************************/
1391 static void free_file_list (struct file_list *list_head)
1393 struct file_list *list, *next;
1395 for (list = list_head; list; list = next) {
1397 DLIST_REMOVE(list_head, list);
1398 SAFE_FREE(list->file_path);
1403 /****************************************************************************
1404 Seek in a directory/file list until you get something that doesn't start with
1406 ****************************************************************************/
1408 static BOOL seek_list(struct file_list *list, char *name)
1411 trim_string(list->file_path,"./","\n");
1412 if (strncmp(list->file_path, name, strlen(name)) != 0) {
1421 /****************************************************************************
1422 Set the file selection mask.
1423 ****************************************************************************/
1425 static int cmd_select(void)
1427 pstrcpy(fileselection,"");
1428 next_token_nr(NULL,fileselection,NULL,sizeof(fileselection));
1433 /****************************************************************************
1434 Recursive file matching function act as find
1435 match must be always set to True when calling this function
1436 ****************************************************************************/
1438 static int file_find(struct file_list **list, const char *directory,
1439 const char *expression, BOOL match)
1441 SMB_STRUCT_DIR *dir;
1442 struct file_list *entry;
1443 struct stat statbuf;
1449 dir = sys_opendir(directory);
1453 while ((dname = readdirname(dir))) {
1454 if (!strcmp("..", dname))
1456 if (!strcmp(".", dname))
1459 if (asprintf(&path, "%s/%s", directory, dname) <= 0) {
1464 if (!match || !gen_fnmatch(expression, dname)) {
1466 ret = stat(path, &statbuf);
1468 if (S_ISDIR(statbuf.st_mode)) {
1470 ret = file_find(list, path, expression, False);
1473 d_printf("file_find: cannot stat file %s\n", path);
1482 entry = SMB_MALLOC_P(struct file_list);
1484 d_printf("Out of memory in file_find\n");
1488 entry->file_path = path;
1489 entry->isdir = isdir;
1490 DLIST_ADD(*list, entry);
1500 /****************************************************************************
1502 ****************************************************************************/
1504 static int cmd_mput(void)
1509 while (next_token_nr(NULL,p,NULL,sizeof(buf))) {
1511 struct file_list *temp_list;
1512 char *quest, *lname, *rname;
1516 ret = file_find(&file_list, ".", p, True);
1518 free_file_list(file_list);
1526 for (temp_list = file_list; temp_list;
1527 temp_list = temp_list->next) {
1530 if (asprintf(&lname, "%s/", temp_list->file_path) <= 0)
1532 trim_string(lname, "./", "/");
1534 /* check if it's a directory */
1535 if (temp_list->isdir) {
1536 /* if (!recurse) continue; */
1539 if (asprintf(&quest, "Put directory %s? ", lname) < 0) break;
1540 if (prompt && !yesno(quest)) { /* No */
1541 /* Skip the directory */
1542 lname[strlen(lname)-1] = '/';
1543 if (!seek_list(temp_list, lname))
1547 if(asprintf(&rname, "%s%s", cur_dir, lname) < 0) break;
1549 if (!cli_chkpath(cli, rname) &&
1551 DEBUG (0, ("Unable to make dir, skipping..."));
1552 /* Skip the directory */
1553 lname[strlen(lname)-1] = '/';
1554 if (!seek_list(temp_list, lname))
1561 if (asprintf(&quest,"Put file %s? ", lname) < 0) break;
1562 if (prompt && !yesno(quest)) /* No */
1567 if (asprintf(&rname, "%s%s", cur_dir, lname) < 0) break;
1572 do_put(rname, lname, False);
1574 free_file_list(file_list);
1583 /****************************************************************************
1585 ****************************************************************************/
1587 static int do_cancel(int job)
1589 if (cli_printjob_del(cli, job)) {
1590 d_printf("Job %d cancelled\n",job);
1593 d_printf("Error cancelling job %d : %s\n",job,cli_errstr(cli));
1598 /****************************************************************************
1600 ****************************************************************************/
1602 static int cmd_cancel(void)
1607 if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
1608 d_printf("cancel <jobid> ...\n");
1614 } while (next_token_nr(NULL,buf,NULL,sizeof(buf)));
1619 /****************************************************************************
1621 ****************************************************************************/
1623 static int cmd_print(void)
1629 if (!next_token_nr(NULL,lname,NULL, sizeof(lname))) {
1630 d_printf("print <filename>\n");
1634 pstrcpy(rname,lname);
1635 p = strrchr_m(rname,'/');
1637 slprintf(rname, sizeof(rname)-1, "%s-%d", p+1, (int)sys_getpid());
1640 if (strequal(lname,"-")) {
1641 slprintf(rname, sizeof(rname)-1, "stdin-%d", (int)sys_getpid());
1644 return do_put(rname, lname, False);
1647 /****************************************************************************
1648 Show a print queue entry.
1649 ****************************************************************************/
1651 static void queue_fn(struct print_job_info *p)
1653 d_printf("%-6d %-9d %s\n", (int)p->id, (int)p->size, p->name);
1656 /****************************************************************************
1658 ****************************************************************************/
1660 static int cmd_queue(void)
1662 cli_print_queue(cli, queue_fn);
1667 /****************************************************************************
1669 ****************************************************************************/
1671 static void do_del(file_info *finfo)
1675 pstr_sprintf( mask, "%s\\%s", finfo->dir, finfo->name );
1677 if (finfo->mode & aDIR)
1680 if (!cli_unlink(cli, mask)) {
1681 d_printf("%s deleting remote file %s\n",cli_errstr(cli),mask);
1685 /****************************************************************************
1687 ****************************************************************************/
1689 static int cmd_del(void)
1693 uint16 attribute = aSYSTEM | aHIDDEN;
1698 pstrcpy(mask,cur_dir);
1700 if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
1701 d_printf("del <filename>\n");
1706 do_list(mask, attribute,do_del,False,False);
1711 /****************************************************************************
1712 ****************************************************************************/
1714 static int cmd_open(void)
1718 struct cli_state *targetcli;
1722 pstrcpy(mask,cur_dir);
1724 if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
1725 d_printf("open <filename>\n");
1730 if ( !cli_resolve_path( "", cli, mask, &targetcli, targetname ) ) {
1731 d_printf("open %s: %s\n", mask, cli_errstr(cli));
1735 fnum = cli_nt_create(targetcli, targetname, FILE_READ_DATA|FILE_WRITE_DATA);
1737 fnum = cli_nt_create(targetcli, targetname, FILE_READ_DATA);
1739 d_printf("open file %s: for read/write fnum %d\n", targetname, fnum);
1741 d_printf("Failed to open file %s. %s\n", targetname, cli_errstr(cli));
1744 d_printf("open file %s: for read/write fnum %d\n", targetname, fnum);
1750 /****************************************************************************
1751 ****************************************************************************/
1753 static int cmd_posix_open(void)
1757 struct cli_state *targetcli;
1762 pstrcpy(mask,cur_dir);
1764 if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
1765 d_printf("posix_open <filename> 0<mode>\n");
1769 if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
1770 d_printf("posix_open <filename> 0<mode>\n");
1773 mode = (mode_t)strtol(buf, (char **)NULL, 8);
1775 if (!cli_resolve_path( "", cli, mask, &targetcli, targetname )) {
1776 d_printf("posix_open %s: %s\n", mask, cli_errstr(cli));
1780 fnum = cli_posix_open(targetcli, targetname, O_CREAT|O_RDWR, mode);
1782 fnum = cli_posix_open(targetcli, targetname, O_CREAT|O_RDONLY, mode);
1784 d_printf("posix_open file %s: for read/write fnum %d\n", targetname, fnum);
1786 d_printf("Failed to open file %s. %s\n", targetname, cli_errstr(cli));
1789 d_printf("posix_open file %s: for read/write fnum %d\n", targetname, fnum);
1795 static int cmd_posix_mkdir(void)
1799 struct cli_state *targetcli;
1804 pstrcpy(mask,cur_dir);
1806 if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
1807 d_printf("posix_mkdir <filename> 0<mode>\n");
1811 if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
1812 d_printf("posix_mkdir <filename> 0<mode>\n");
1815 mode = (mode_t)strtol(buf, (char **)NULL, 8);
1817 if (!cli_resolve_path( "", cli, mask, &targetcli, targetname )) {
1818 d_printf("posix_mkdir %s: %s\n", mask, cli_errstr(cli));
1822 fnum = cli_posix_mkdir(targetcli, targetname, mode);
1824 d_printf("Failed to open file %s. %s\n", targetname, cli_errstr(cli));
1826 d_printf("posix_mkdir created directory %s\n", targetname);
1832 static int cmd_posix_unlink(void)
1836 struct cli_state *targetcli;
1839 pstrcpy(mask,cur_dir);
1841 if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
1842 d_printf("posix_unlink <filename>\n");
1847 if (!cli_resolve_path( "", cli, mask, &targetcli, targetname )) {
1848 d_printf("posix_unlink %s: %s\n", mask, cli_errstr(cli));
1852 if (!cli_posix_unlink(targetcli, targetname)) {
1853 d_printf("Failed to unlink file %s. %s\n", targetname, cli_errstr(cli));
1855 d_printf("posix_unlink deleted file %s\n", targetname);
1861 static int cmd_posix_rmdir(void)
1865 struct cli_state *targetcli;
1868 pstrcpy(mask,cur_dir);
1870 if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
1871 d_printf("posix_rmdir <filename>\n");
1876 if (!cli_resolve_path( "", cli, mask, &targetcli, targetname)) {
1877 d_printf("posix_rmdir %s: %s\n", mask, cli_errstr(cli));
1881 if (!cli_posix_rmdir(targetcli, targetname)) {
1882 d_printf("Failed to unlink directory %s. %s\n", targetname, cli_errstr(cli));
1884 d_printf("posix_rmdir deleted directory %s\n", targetname);
1890 static int cmd_close(void)
1895 if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
1896 d_printf("close <fnum>\n");
1901 /* We really should use the targetcli here.... */
1902 if (!cli_close(cli, fnum)) {
1903 d_printf("close %d: %s\n", fnum, cli_errstr(cli));
1909 static int cmd_posix(void)
1911 uint16 major, minor;
1912 uint32 caplow, caphigh;
1915 if (!SERVER_HAS_UNIX_CIFS(cli)) {
1916 d_printf("Server doesn't support UNIX CIFS extensions.\n");
1920 if (!cli_unix_extensions_version(cli, &major, &minor, &caplow, &caphigh)) {
1921 d_printf("Can't get UNIX CIFS extensions version from server.\n");
1925 d_printf("Server supports CIFS extensions %u.%u\n", (unsigned int)major, (unsigned int)minor);
1928 if (caplow & CIFS_UNIX_FCNTL_LOCKS_CAP) {
1929 pstrcat(caps, "locks ");
1931 if (caplow & CIFS_UNIX_POSIX_ACLS_CAP) {
1932 pstrcat(caps, "acls ");
1934 if (caplow & CIFS_UNIX_XATTTR_CAP) {
1935 pstrcat(caps, "eas ");
1937 if (caplow & CIFS_UNIX_POSIX_PATHNAMES_CAP) {
1938 pstrcat(caps, "pathnames ");
1940 if (caplow & CIFS_UNIX_POSIX_PATH_OPERATIONS_CAP) {
1941 pstrcat(caps, "posix_path_operations ");
1944 if (strlen(caps) > 0 && caps[strlen(caps)-1] == ' ') {
1945 caps[strlen(caps)-1] = '\0';
1948 if (!cli_set_unix_extensions_capabilities(cli, major, minor, caplow, caphigh)) {
1949 d_printf("Can't set UNIX CIFS extensions capabilities. %s.\n", cli_errstr(cli));
1953 d_printf("Selecting server supported CIFS capabilities %s\n", caps);
1955 if (caplow & CIFS_UNIX_POSIX_PATHNAMES_CAP) {
1956 CLI_DIRSEP_CHAR = '/';
1957 *CLI_DIRSEP_STR = '/';
1958 pstrcpy(cur_dir, CLI_DIRSEP_STR);
1964 static int cmd_lock(void)
1967 SMB_BIG_UINT start, len;
1968 enum brl_type lock_type;
1971 if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
1972 d_printf("lock <fnum> [r|w] <hex-start> <hex-len>\n");
1977 if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
1978 d_printf("lock <fnum> [r|w] <hex-start> <hex-len>\n");
1982 if (*buf == 'r' || *buf == 'R') {
1983 lock_type = READ_LOCK;
1984 } else if (*buf == 'w' || *buf == 'W') {
1985 lock_type = WRITE_LOCK;
1987 d_printf("lock <fnum> [r|w] <hex-start> <hex-len>\n");
1991 if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
1992 d_printf("lock <fnum> [r|w] <hex-start> <hex-len>\n");
1996 start = (SMB_BIG_UINT)strtol(buf, (char **)NULL, 16);
1998 if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
1999 d_printf("lock <fnum> [r|w] <hex-start> <hex-len>\n");
2003 len = (SMB_BIG_UINT)strtol(buf, (char **)NULL, 16);
2005 if (!cli_posix_lock(cli, fnum, start, len, True, lock_type)) {
2006 d_printf("lock failed %d: %s\n", fnum, cli_errstr(cli));
2012 static int cmd_unlock(void)
2015 SMB_BIG_UINT start, len;
2018 if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
2019 d_printf("unlock <fnum> <hex-start> <hex-len>\n");
2024 if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
2025 d_printf("unlock <fnum> <hex-start> <hex-len>\n");
2029 start = (SMB_BIG_UINT)strtol(buf, (char **)NULL, 16);
2031 if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
2032 d_printf("unlock <fnum> <hex-start> <hex-len>\n");
2036 len = (SMB_BIG_UINT)strtol(buf, (char **)NULL, 16);
2038 if (!cli_posix_unlock(cli, fnum, start, len)) {
2039 d_printf("unlock failed %d: %s\n", fnum, cli_errstr(cli));
2046 /****************************************************************************
2048 ****************************************************************************/
2050 static int cmd_rmdir(void)
2054 struct cli_state *targetcli;
2057 pstrcpy(mask,cur_dir);
2059 if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
2060 d_printf("rmdir <dirname>\n");
2065 if ( !cli_resolve_path( "", cli, mask, &targetcli, targetname ) ) {
2066 d_printf("rmdir %s: %s\n", mask, cli_errstr(cli));
2070 if (!cli_rmdir(targetcli, targetname)) {
2071 d_printf("%s removing remote directory file %s\n",
2072 cli_errstr(targetcli),mask);
2078 /****************************************************************************
2080 ****************************************************************************/
2082 static int cmd_link(void)
2084 pstring oldname,newname;
2086 struct cli_state *targetcli;
2089 pstrcpy(oldname,cur_dir);
2090 pstrcpy(newname,cur_dir);
2092 if (!next_token_nr(NULL,buf,NULL,sizeof(buf)) ||
2093 !next_token_nr(NULL,buf2,NULL, sizeof(buf2))) {
2094 d_printf("link <oldname> <newname>\n");
2098 pstrcat(oldname,buf);
2099 pstrcat(newname,buf2);
2101 if ( !cli_resolve_path( "", cli, oldname, &targetcli, targetname ) ) {
2102 d_printf("link %s: %s\n", oldname, cli_errstr(cli));
2106 if (!SERVER_HAS_UNIX_CIFS(targetcli)) {
2107 d_printf("Server doesn't support UNIX CIFS calls.\n");
2111 if (!cli_unix_hardlink(targetcli, targetname, newname)) {
2112 d_printf("%s linking files (%s -> %s)\n", cli_errstr(targetcli), newname, oldname);
2119 /****************************************************************************
2121 ****************************************************************************/
2123 static int cmd_symlink(void)
2125 pstring oldname,newname;
2128 if (!SERVER_HAS_UNIX_CIFS(cli)) {
2129 d_printf("Server doesn't support UNIX CIFS calls.\n");
2133 pstrcpy(newname,cur_dir);
2135 if (!next_token_nr(NULL,buf,NULL,sizeof(buf)) ||
2136 !next_token_nr(NULL,buf2,NULL, sizeof(buf2))) {
2137 d_printf("symlink <oldname> <newname>\n");
2141 pstrcpy(oldname,buf);
2142 pstrcat(newname,buf2);
2144 if (!cli_unix_symlink(cli, oldname, newname)) {
2145 d_printf("%s symlinking files (%s -> %s)\n",
2146 cli_errstr(cli), newname, oldname);
2153 /****************************************************************************
2155 ****************************************************************************/
2157 static int cmd_chmod(void)
2162 struct cli_state *targetcli;
2165 pstrcpy(src,cur_dir);
2167 if (!next_token_nr(NULL,buf,NULL,sizeof(buf)) ||
2168 !next_token_nr(NULL,buf2,NULL, sizeof(buf2))) {
2169 d_printf("chmod mode file\n");
2173 mode = (mode_t)strtol(buf, NULL, 8);
2176 if ( !cli_resolve_path( "", cli, src, &targetcli, targetname ) ) {
2177 d_printf("chmod %s: %s\n", src, cli_errstr(cli));
2181 if (!SERVER_HAS_UNIX_CIFS(targetcli)) {
2182 d_printf("Server doesn't support UNIX CIFS calls.\n");
2186 if (!cli_unix_chmod(targetcli, targetname, mode)) {
2187 d_printf("%s chmod file %s 0%o\n",
2188 cli_errstr(targetcli), src, (unsigned int)mode);
2195 static const char *filetype_to_str(mode_t mode)
2197 if (S_ISREG(mode)) {
2198 return "regular file";
2199 } else if (S_ISDIR(mode)) {
2203 if (S_ISCHR(mode)) {
2204 return "character device";
2208 if (S_ISBLK(mode)) {
2209 return "block device";
2213 if (S_ISFIFO(mode)) {
2218 if (S_ISLNK(mode)) {
2219 return "symbolic link";
2223 if (S_ISSOCK(mode)) {
2230 static char rwx_to_str(mode_t m, mode_t bt, char ret)
2239 static char *unix_mode_to_str(char *s, mode_t m)
2242 const char *str = filetype_to_str(m);
2258 *p++ = str[1] == 'y' ? 'l' : 's';
2265 *p++ = rwx_to_str(m, S_IRUSR, 'r');
2266 *p++ = rwx_to_str(m, S_IWUSR, 'w');
2267 *p++ = rwx_to_str(m, S_IXUSR, 'x');
2268 *p++ = rwx_to_str(m, S_IRGRP, 'r');
2269 *p++ = rwx_to_str(m, S_IWGRP, 'w');
2270 *p++ = rwx_to_str(m, S_IXGRP, 'x');
2271 *p++ = rwx_to_str(m, S_IROTH, 'r');
2272 *p++ = rwx_to_str(m, S_IWOTH, 'w');
2273 *p++ = rwx_to_str(m, S_IXOTH, 'x');
2278 /****************************************************************************
2279 Utility function for UNIX getfacl.
2280 ****************************************************************************/
2282 static char *perms_to_string(fstring permstr, unsigned char perms)
2284 fstrcpy(permstr, "---");
2285 if (perms & SMB_POSIX_ACL_READ) {
2288 if (perms & SMB_POSIX_ACL_WRITE) {
2291 if (perms & SMB_POSIX_ACL_EXECUTE) {
2297 /****************************************************************************
2299 ****************************************************************************/
2301 static int cmd_getfacl(void)
2304 uint16 major, minor;
2305 uint32 caplow, caphigh;
2306 char *retbuf = NULL;
2308 SMB_STRUCT_STAT sbuf;
2309 uint16 num_file_acls = 0;
2310 uint16 num_dir_acls = 0;
2312 struct cli_state *targetcli;
2315 pstrcpy(src,cur_dir);
2317 if (!next_token_nr(NULL,name,NULL,sizeof(name))) {
2318 d_printf("stat file\n");
2324 if ( !cli_resolve_path( "", cli, src, &targetcli, targetname ) ) {
2325 d_printf("stat %s: %s\n", src, cli_errstr(cli));
2329 if (!SERVER_HAS_UNIX_CIFS(targetcli)) {
2330 d_printf("Server doesn't support UNIX CIFS calls.\n");
2334 if (!cli_unix_extensions_version(targetcli, &major, &minor, &caplow, &caphigh)) {
2335 d_printf("Can't get UNIX CIFS version from server.\n");
2339 if (!(caplow & CIFS_UNIX_POSIX_ACLS_CAP)) {
2340 d_printf("This server supports UNIX extensions but doesn't support POSIX ACLs.\n");
2345 if (!cli_unix_stat(targetcli, targetname, &sbuf)) {
2346 d_printf("%s getfacl doing a stat on file %s\n",
2347 cli_errstr(targetcli), src);
2351 if (!cli_unix_getfacl(targetcli, targetname, &rb_size, &retbuf)) {
2352 d_printf("%s getfacl file %s\n",
2353 cli_errstr(targetcli), src);
2357 /* ToDo : Print out the ACL values. */
2358 if (SVAL(retbuf,0) != SMB_POSIX_ACL_VERSION || rb_size < 6) {
2359 d_printf("getfacl file %s, unknown POSIX acl version %u.\n",
2360 src, (unsigned int)CVAL(retbuf,0) );
2365 num_file_acls = SVAL(retbuf,2);
2366 num_dir_acls = SVAL(retbuf,4);
2367 if (rb_size != SMB_POSIX_ACL_HEADER_SIZE + SMB_POSIX_ACL_ENTRY_SIZE*(num_file_acls+num_dir_acls)) {
2368 d_printf("getfacl file %s, incorrect POSIX acl buffer size (should be %u, was %u).\n",
2370 (unsigned int)(SMB_POSIX_ACL_HEADER_SIZE + SMB_POSIX_ACL_ENTRY_SIZE*(num_file_acls+num_dir_acls)),
2371 (unsigned int)rb_size);
2377 d_printf("# file: %s\n", src);
2378 d_printf("# owner: %u\n# group: %u\n", (unsigned int)sbuf.st_uid, (unsigned int)sbuf.st_gid);
2380 if (num_file_acls == 0 && num_dir_acls == 0) {
2381 d_printf("No acls found.\n");
2384 for (i = 0; i < num_file_acls; i++) {
2387 unsigned char tagtype = CVAL(retbuf, SMB_POSIX_ACL_HEADER_SIZE+(i*SMB_POSIX_ACL_ENTRY_SIZE));
2388 unsigned char perms = CVAL(retbuf, SMB_POSIX_ACL_HEADER_SIZE+(i*SMB_POSIX_ACL_ENTRY_SIZE)+1);
2391 case SMB_POSIX_ACL_USER_OBJ:
2394 case SMB_POSIX_ACL_USER:
2395 uorg = IVAL(retbuf,SMB_POSIX_ACL_HEADER_SIZE+(i*SMB_POSIX_ACL_ENTRY_SIZE)+2);
2396 d_printf("user:%u:", uorg);
2398 case SMB_POSIX_ACL_GROUP_OBJ:
2399 d_printf("group::");
2401 case SMB_POSIX_ACL_GROUP:
2402 uorg = IVAL(retbuf,SMB_POSIX_ACL_HEADER_SIZE+(i*SMB_POSIX_ACL_ENTRY_SIZE)+2);
2403 d_printf("group:%u", uorg);
2405 case SMB_POSIX_ACL_MASK:
2408 case SMB_POSIX_ACL_OTHER:
2409 d_printf("other::");
2412 d_printf("getfacl file %s, incorrect POSIX acl tagtype (%u).\n",
2413 src, (unsigned int)tagtype );
2418 d_printf("%s\n", perms_to_string(permstring, perms));
2421 for (i = 0; i < num_dir_acls; i++) {
2424 unsigned char tagtype = CVAL(retbuf, SMB_POSIX_ACL_HEADER_SIZE+((i+num_file_acls)*SMB_POSIX_ACL_ENTRY_SIZE));
2425 unsigned char perms = CVAL(retbuf, SMB_POSIX_ACL_HEADER_SIZE+((i+num_file_acls)*SMB_POSIX_ACL_ENTRY_SIZE)+1);
2428 case SMB_POSIX_ACL_USER_OBJ:
2429 d_printf("default:user::");
2431 case SMB_POSIX_ACL_USER:
2432 uorg = IVAL(retbuf,SMB_POSIX_ACL_HEADER_SIZE+((i+num_file_acls)*SMB_POSIX_ACL_ENTRY_SIZE)+2);
2433 d_printf("default:user:%u:", uorg);
2435 case SMB_POSIX_ACL_GROUP_OBJ:
2436 d_printf("default:group::");
2438 case SMB_POSIX_ACL_GROUP:
2439 uorg = IVAL(retbuf,SMB_POSIX_ACL_HEADER_SIZE+((i+num_file_acls)*SMB_POSIX_ACL_ENTRY_SIZE)+2);
2440 d_printf("default:group:%u", uorg);
2442 case SMB_POSIX_ACL_MASK:
2443 d_printf("default:mask::");
2445 case SMB_POSIX_ACL_OTHER:
2446 d_printf("default:other::");
2449 d_printf("getfacl file %s, incorrect POSIX acl tagtype (%u).\n",
2450 src, (unsigned int)tagtype );
2455 d_printf("%s\n", perms_to_string(permstring, perms));
2462 /****************************************************************************
2464 ****************************************************************************/
2466 static int cmd_stat(void)
2470 SMB_STRUCT_STAT sbuf;
2471 struct cli_state *targetcli;
2475 if (!SERVER_HAS_UNIX_CIFS(cli)) {
2476 d_printf("Server doesn't support UNIX CIFS calls.\n");
2480 pstrcpy(src,cur_dir);
2482 if (!next_token_nr(NULL,name,NULL,sizeof(name))) {
2483 d_printf("stat file\n");
2490 if ( !cli_resolve_path( "", cli, src, &targetcli, targetname ) ) {
2491 d_printf("stat %s: %s\n", src, cli_errstr(cli));
2495 if (!cli_unix_stat(targetcli, targetname, &sbuf)) {
2496 d_printf("%s stat file %s\n",
2497 cli_errstr(targetcli), src);
2501 /* Print out the stat values. */
2502 d_printf("File: %s\n", src);
2503 d_printf("Size: %-12.0f\tBlocks: %u\t%s\n",
2504 (double)sbuf.st_size,
2505 (unsigned int)sbuf.st_blocks,
2506 filetype_to_str(sbuf.st_mode));
2508 #if defined(S_ISCHR) && defined(S_ISBLK)
2509 if (S_ISCHR(sbuf.st_mode) || S_ISBLK(sbuf.st_mode)) {
2510 d_printf("Inode: %.0f\tLinks: %u\tDevice type: %u,%u\n",
2511 (double)sbuf.st_ino,
2512 (unsigned int)sbuf.st_nlink,
2513 unix_dev_major(sbuf.st_rdev),
2514 unix_dev_minor(sbuf.st_rdev));
2517 d_printf("Inode: %.0f\tLinks: %u\n",
2518 (double)sbuf.st_ino,
2519 (unsigned int)sbuf.st_nlink);
2521 d_printf("Access: (0%03o/%s)\tUid: %u\tGid: %u\n",
2522 ((int)sbuf.st_mode & 0777),
2523 unix_mode_to_str(mode_str, sbuf.st_mode),
2524 (unsigned int)sbuf.st_uid,
2525 (unsigned int)sbuf.st_gid);
2527 lt = localtime(&sbuf.st_atime);
2529 strftime(mode_str, sizeof(mode_str), "%Y-%m-%d %T %z", lt);
2531 fstrcpy(mode_str, "unknown");
2533 d_printf("Access: %s\n", mode_str);
2535 lt = localtime(&sbuf.st_mtime);
2537 strftime(mode_str, sizeof(mode_str), "%Y-%m-%d %T %z", lt);
2539 fstrcpy(mode_str, "unknown");
2541 d_printf("Modify: %s\n", mode_str);
2543 lt = localtime(&sbuf.st_ctime);
2545 strftime(mode_str, sizeof(mode_str), "%Y-%m-%d %T %z", lt);
2547 fstrcpy(mode_str, "unknown");
2549 d_printf("Change: %s\n", mode_str);
2555 /****************************************************************************
2557 ****************************************************************************/
2559 static int cmd_chown(void)
2564 pstring buf, buf2, buf3;
2565 struct cli_state *targetcli;
2568 pstrcpy(src,cur_dir);
2570 if (!next_token_nr(NULL,buf,NULL,sizeof(buf)) ||
2571 !next_token_nr(NULL,buf2,NULL, sizeof(buf2)) ||
2572 !next_token_nr(NULL,buf3,NULL, sizeof(buf3))) {
2573 d_printf("chown uid gid file\n");
2577 uid = (uid_t)atoi(buf);
2578 gid = (gid_t)atoi(buf2);
2581 if ( !cli_resolve_path( "", cli, src, &targetcli, targetname ) ) {
2582 d_printf("chown %s: %s\n", src, cli_errstr(cli));
2587 if (!SERVER_HAS_UNIX_CIFS(targetcli)) {
2588 d_printf("Server doesn't support UNIX CIFS calls.\n");
2592 if (!cli_unix_chown(targetcli, targetname, uid, gid)) {
2593 d_printf("%s chown file %s uid=%d, gid=%d\n",
2594 cli_errstr(targetcli), src, (int)uid, (int)gid);
2601 /****************************************************************************
2603 ****************************************************************************/
2605 static int cmd_rename(void)
2610 pstrcpy(src,cur_dir);
2611 pstrcpy(dest,cur_dir);
2613 if (!next_token_nr(NULL,buf,NULL,sizeof(buf)) ||
2614 !next_token_nr(NULL,buf2,NULL, sizeof(buf2))) {
2615 d_printf("rename <src> <dest>\n");
2622 if (!cli_rename(cli, src, dest)) {
2623 d_printf("%s renaming files\n",cli_errstr(cli));
2630 /****************************************************************************
2631 Print the volume name.
2632 ****************************************************************************/
2634 static int cmd_volume(void)
2640 if (!cli_get_fs_volume_info(cli, volname, &serial_num, &create_date)) {
2641 d_printf("Errr %s getting volume info\n",cli_errstr(cli));
2645 d_printf("Volume: |%s| serial number 0x%x\n", volname, (unsigned int)serial_num);
2649 /****************************************************************************
2650 Hard link files using the NT call.
2651 ****************************************************************************/
2653 static int cmd_hardlink(void)
2657 struct cli_state *targetcli;
2660 pstrcpy(src,cur_dir);
2661 pstrcpy(dest,cur_dir);
2663 if (!next_token_nr(NULL,buf,NULL,sizeof(buf)) ||
2664 !next_token_nr(NULL,buf2,NULL, sizeof(buf2))) {
2665 d_printf("hardlink <src> <dest>\n");
2672 if ( !cli_resolve_path( "", cli, src, &targetcli, targetname ) ) {
2673 d_printf("hardlink %s: %s\n", src, cli_errstr(cli));
2677 if (!SERVER_HAS_UNIX_CIFS(targetcli)) {
2678 d_printf("Server doesn't support UNIX CIFS calls.\n");
2682 if (!cli_nt_hardlink(targetcli, targetname, dest)) {
2683 d_printf("%s doing an NT hard link of files\n",cli_errstr(targetcli));
2690 /****************************************************************************
2691 Toggle the prompt flag.
2692 ****************************************************************************/
2694 static int cmd_prompt(void)
2697 DEBUG(2,("prompting is now %s\n",prompt?"on":"off"));
2702 /****************************************************************************
2703 Set the newer than time.
2704 ****************************************************************************/
2706 static int cmd_newer(void)
2710 SMB_STRUCT_STAT sbuf;
2712 ok = next_token_nr(NULL,buf,NULL,sizeof(buf));
2713 if (ok && (sys_stat(buf,&sbuf) == 0)) {
2714 newer_than = sbuf.st_mtime;
2715 DEBUG(1,("Getting files newer than %s",
2716 time_to_asc(&newer_than)));
2721 if (ok && newer_than == 0) {
2722 d_printf("Error setting newer-than time\n");
2729 /****************************************************************************
2730 Set the archive level.
2731 ****************************************************************************/
2733 static int cmd_archive(void)
2737 if (next_token_nr(NULL,buf,NULL,sizeof(buf))) {
2738 archive_level = atoi(buf);
2740 d_printf("Archive level is %d\n",archive_level);
2745 /****************************************************************************
2746 Toggle the lowercaseflag.
2747 ****************************************************************************/
2749 static int cmd_lowercase(void)
2751 lowercase = !lowercase;
2752 DEBUG(2,("filename lowercasing is now %s\n",lowercase?"on":"off"));
2757 /****************************************************************************
2758 Toggle the case sensitive flag.
2759 ****************************************************************************/
2761 static int cmd_setcase(void)
2763 BOOL orig_case_sensitive = cli_set_case_sensitive(cli, False);
2765 cli_set_case_sensitive(cli, !orig_case_sensitive);
2766 DEBUG(2,("filename case sensitivity is now %s\n",!orig_case_sensitive ?
2772 /****************************************************************************
2773 Toggle the showacls flag.
2774 ****************************************************************************/
2776 static int cmd_showacls(void)
2778 showacls = !showacls;
2779 DEBUG(2,("showacls is now %s\n",showacls?"on":"off"));
2781 if (!ctx && showacls)
2782 ctx = talloc_init("smbclient:showacls");
2784 DEBUG( 0, ("cmd_showacls() out of memory. talloc_init() failed.\n"));
2791 /****************************************************************************
2792 Toggle the recurse flag.
2793 ****************************************************************************/
2795 static int cmd_recurse(void)
2798 DEBUG(2,("directory recursion is now %s\n",recurse?"on":"off"));
2803 /****************************************************************************
2804 Toggle the translate flag.
2805 ****************************************************************************/
2807 static int cmd_translate(void)
2809 translation = !translation;
2810 DEBUG(2,("CR/LF<->LF and print text translation now %s\n",
2811 translation?"on":"off"));
2816 /****************************************************************************
2818 ****************************************************************************/
2820 static int cmd_lcd(void)
2825 if (next_token_nr(NULL,buf,NULL,sizeof(buf)))
2827 DEBUG(2,("the local directory is now %s\n",sys_getwd(d)));
2832 /****************************************************************************
2833 Get a file restarting at end of local file.
2834 ****************************************************************************/
2836 static int cmd_reget(void)
2839 pstring remote_name;
2842 pstrcpy(remote_name, cur_dir);
2843 pstrcat(remote_name, CLI_DIRSEP_STR);
2845 p = remote_name + strlen(remote_name);
2847 if (!next_token_nr(NULL, p, NULL, sizeof(remote_name) - strlen(remote_name))) {
2848 d_printf("reget <filename>\n");
2851 pstrcpy(local_name, p);
2852 dos_clean_name(remote_name);
2854 next_token_nr(NULL, local_name, NULL, sizeof(local_name));
2856 return do_get(remote_name, local_name, True);
2859 /****************************************************************************
2860 Put a file restarting at end of local file.
2861 ****************************************************************************/
2863 static int cmd_reput(void)
2866 pstring remote_name;
2871 pstrcpy(remote_name, cur_dir);
2872 pstrcat(remote_name, CLI_DIRSEP_STR);
2874 if (!next_token_nr(NULL, p, NULL, sizeof(buf))) {
2875 d_printf("reput <filename>\n");
2878 pstrcpy(local_name, p);
2880 if (!file_exist(local_name, &st)) {
2881 d_printf("%s does not exist\n", local_name);
2885 if (next_token_nr(NULL, p, NULL, sizeof(buf)))
2886 pstrcat(remote_name, p);
2888 pstrcat(remote_name, local_name);
2890 dos_clean_name(remote_name);
2892 return do_put(remote_name, local_name, True);
2895 /****************************************************************************
2897 ****************************************************************************/
2899 static void browse_fn(const char *name, uint32 m,
2900 const char *comment, void *state)
2908 case STYPE_DISKTREE:
2909 fstrcpy(typestr,"Disk"); break;
2911 fstrcpy(typestr,"Printer"); break;
2913 fstrcpy(typestr,"Device"); break;
2915 fstrcpy(typestr,"IPC"); break;
2917 /* FIXME: If the remote machine returns non-ascii characters
2918 in any of these fields, they can corrupt the output. We
2919 should remove them. */
2921 d_printf("\t%-15s %-10.10s%s\n",
2922 name,typestr,comment);
2924 d_printf ("%s|%s|%s\n",typestr,name,comment);
2928 static BOOL browse_host_rpc(BOOL sort)
2931 struct rpc_pipe_client *pipe_hnd;
2932 TALLOC_CTX *mem_ctx;
2933 uint32 enum_hnd = 0;
2934 struct srvsvc_NetShareCtr1 ctr1;
2935 union srvsvc_NetShareCtr ctr;
2940 mem_ctx = talloc_new(NULL);
2941 if (mem_ctx == NULL) {
2942 DEBUG(0, ("talloc_new failed\n"));
2946 pipe_hnd = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC, &status);
2948 if (pipe_hnd == NULL) {
2949 DEBUG(10, ("Could not connect to srvsvc pipe: %s\n",
2950 nt_errstr(status)));
2951 TALLOC_FREE(mem_ctx);
2959 status = rpccli_srvsvc_NetShareEnum(pipe_hnd, mem_ctx, "", &level,
2960 &ctr, 0xffffffff, &numentries,
2963 if (!NT_STATUS_IS_OK(status)) {
2964 TALLOC_FREE(mem_ctx);
2965 cli_rpc_pipe_close(pipe_hnd);
2969 for (i=0; i<numentries; i++) {
2970 struct srvsvc_NetShareInfo1 *info = &ctr.ctr1->array[i];
2971 browse_fn(info->name, info->type, info->comment, NULL);
2974 TALLOC_FREE(mem_ctx);
2975 cli_rpc_pipe_close(pipe_hnd);
2979 /****************************************************************************
2980 Try and browse available connections on a host.
2981 ****************************************************************************/
2983 static BOOL browse_host(BOOL sort)
2987 d_printf("\n\tSharename Type Comment\n");
2988 d_printf("\t--------- ---- -------\n");
2991 if (browse_host_rpc(sort)) {
2995 if((ret = cli_RNetShareEnum(cli, browse_fn, NULL)) == -1)
2996 d_printf("Error returning browse list: %s\n", cli_errstr(cli));
3001 /****************************************************************************
3003 ****************************************************************************/
3005 static void server_fn(const char *name, uint32 m,
3006 const char *comment, void *state)
3010 d_printf("\t%-16s %s\n", name, comment);
3012 d_printf("%s|%s|%s\n",(char *)state, name, comment);
3016 /****************************************************************************
3017 Try and browse available connections on a host.
3018 ****************************************************************************/
3020 static BOOL list_servers(const char *wk_grp)
3024 if (!cli->server_domain)
3028 d_printf("\n\tServer Comment\n");
3029 d_printf("\t--------- -------\n");
3031 fstrcpy( state, "Server" );
3032 cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_ALL, server_fn,
3036 d_printf("\n\tWorkgroup Master\n");
3037 d_printf("\t--------- -------\n");
3040 fstrcpy( state, "Workgroup" );
3041 cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_DOMAIN_ENUM,
3046 /****************************************************************************
3047 Print or set current VUID
3048 ****************************************************************************/
3050 static int cmd_vuid(void)
3054 if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
3055 d_printf("Current VUID is %d\n", cli->vuid);
3059 cli->vuid = atoi(buf);
3063 /****************************************************************************
3064 Setup a new VUID, by issuing a session setup
3065 ****************************************************************************/
3067 static int cmd_logon(void)
3069 pstring l_username, l_password;
3072 if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
3073 d_printf("logon <username> [<password>]\n");
3077 pstrcpy(l_username, buf);
3079 if (!next_token_nr(NULL,buf2,NULL,sizeof(buf)))
3081 char *pass = getpass("Password: ");
3083 pstrcpy(l_password, pass);
3086 pstrcpy(l_password, buf2);
3088 if (!NT_STATUS_IS_OK(cli_session_setup(cli, l_username,
3089 l_password, strlen(l_password),
3090 l_password, strlen(l_password),
3092 d_printf("session setup failed: %s\n", cli_errstr(cli));
3096 d_printf("Current VUID is %d\n", cli->vuid);
3101 /****************************************************************************
3102 list active connections
3103 ****************************************************************************/
3105 static int cmd_list_connect(void)
3112 /****************************************************************************
3113 display the current active client connection
3114 ****************************************************************************/
3116 static int cmd_show_connect( void )
3118 struct cli_state *targetcli;
3121 if ( !cli_resolve_path( "", cli, cur_dir, &targetcli, targetpath ) ) {
3122 d_printf("showconnect %s: %s\n", cur_dir, cli_errstr(cli));
3126 d_printf("//%s/%s\n", targetcli->desthost, targetcli->share);
3130 /* Some constants for completing filename arguments */
3132 #define COMPL_NONE 0 /* No completions */
3133 #define COMPL_REMOTE 1 /* Complete remote filename */
3134 #define COMPL_LOCAL 2 /* Complete local filename */
3136 /* This defines the commands supported by this client.
3137 * NOTE: The "!" must be the last one in the list because it's fn pointer
3138 * field is NULL, and NULL in that field is used in process_tok()
3139 * (below) to indicate the end of the list. crh
3145 const char *description;
3146 char compl_args[2]; /* Completion argument info */
3148 {"?",cmd_help,"[command] give help on a command",{COMPL_NONE,COMPL_NONE}},
3149 {"altname",cmd_altname,"<file> show alt name",{COMPL_NONE,COMPL_NONE}},
3150 {"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}},
3151 {"blocksize",cmd_block,"blocksize <number> (default 20)",{COMPL_NONE,COMPL_NONE}},
3152 {"cancel",cmd_cancel,"<jobid> cancel a print queue entry",{COMPL_NONE,COMPL_NONE}},
3153 {"case_sensitive",cmd_setcase,"toggle the case sensitive flag to server",{COMPL_NONE,COMPL_NONE}},
3154 {"cd",cmd_cd,"[directory] change/report the remote directory",{COMPL_REMOTE,COMPL_NONE}},
3155 {"chmod",cmd_chmod,"<src> <mode> chmod a file using UNIX permission",{COMPL_REMOTE,COMPL_REMOTE}},
3156 {"chown",cmd_chown,"<src> <uid> <gid> chown a file using UNIX uids and gids",{COMPL_REMOTE,COMPL_REMOTE}},
3157 {"close",cmd_close,"<fid> close a file given a fid",{COMPL_REMOTE,COMPL_REMOTE}},
3158 {"del",cmd_del,"<mask> delete all matching files",{COMPL_REMOTE,COMPL_NONE}},
3159 {"dir",cmd_dir,"<mask> list the contents of the current directory",{COMPL_REMOTE,COMPL_NONE}},
3160 {"du",cmd_du,"<mask> computes the total size of the current directory",{COMPL_REMOTE,COMPL_NONE}},
3161 {"exit",cmd_quit,"logoff the server",{COMPL_NONE,COMPL_NONE}},
3162 {"get",cmd_get,"<remote name> [local name] get a file",{COMPL_REMOTE,COMPL_LOCAL}},
3163 {"getfacl",cmd_getfacl,"<file name> get the POSIX ACL on a file (UNIX extensions only)",{COMPL_REMOTE,COMPL_LOCAL}},
3164 {"hardlink",cmd_hardlink,"<src> <dest> create a Windows hard link",{COMPL_REMOTE,COMPL_REMOTE}},
3165 {"help",cmd_help,"[command] give help on a command",{COMPL_NONE,COMPL_NONE}},
3166 {"history",cmd_history,"displays the command history",{COMPL_NONE,COMPL_NONE}},
3167 {"lcd",cmd_lcd,"[directory] change/report the local current working directory",{COMPL_LOCAL,COMPL_NONE}},
3168 {"link",cmd_link,"<oldname> <newname> create a UNIX hard link",{COMPL_REMOTE,COMPL_REMOTE}},
3169 {"lock",cmd_lock,"lock <fnum> [r|w] <hex-start> <hex-len> : set a POSIX lock",{COMPL_REMOTE,COMPL_REMOTE}},
3170 {"lowercase",cmd_lowercase,"toggle lowercasing of filenames for get",{COMPL_NONE,COMPL_NONE}},
3171 {"ls",cmd_dir,"<mask> list the contents of the current directory",{COMPL_REMOTE,COMPL_NONE}},
3172 {"mask",cmd_select,"<mask> mask all filenames against this",{COMPL_REMOTE,COMPL_NONE}},
3173 {"md",cmd_mkdir,"<directory> make a directory",{COMPL_NONE,COMPL_NONE}},
3174 {"mget",cmd_mget,"<mask> get all the matching files",{COMPL_REMOTE,COMPL_NONE}},
3175 {"mkdir",cmd_mkdir,"<directory> make a directory",{COMPL_NONE,COMPL_NONE}},
3176 {"more",cmd_more,"<remote name> view a remote file with your pager",{COMPL_REMOTE,COMPL_NONE}},
3177 {"mput",cmd_mput,"<mask> put all matching files",{COMPL_REMOTE,COMPL_NONE}},
3178 {"newer",cmd_newer,"<file> only mget files newer than the specified local file",{COMPL_LOCAL,COMPL_NONE}},
3179 {"open",cmd_open,"<mask> open a file",{COMPL_REMOTE,COMPL_NONE}},
3180 {"posix", cmd_posix, "turn on all POSIX capabilities", {COMPL_REMOTE,COMPL_NONE}},
3181 {"posix_open",cmd_posix_open,"<name> 0<mode> open_flags mode open a file using POSIX interface",{COMPL_REMOTE,COMPL_NONE}},
3182 {"posix_mkdir",cmd_posix_mkdir,"<name> 0<mode> creates a directory using POSIX interface",{COMPL_REMOTE,COMPL_NONE}},
3183 {"posix_rmdir",cmd_posix_rmdir,"<name> removes a directory using POSIX interface",{COMPL_REMOTE,COMPL_NONE}},
3184 {"posix_unlink",cmd_posix_unlink,"<name> removes a file using POSIX interface",{COMPL_REMOTE,COMPL_NONE}},
3185 {"print",cmd_print,"<file name> print a file",{COMPL_NONE,COMPL_NONE}},
3186 {"prompt",cmd_prompt,"toggle prompting for filenames for mget and mput",{COMPL_NONE,COMPL_NONE}},
3187 {"put",cmd_put,"<local name> [remote name] put a file",{COMPL_LOCAL,COMPL_REMOTE}},
3188 {"pwd",cmd_pwd,"show current remote directory (same as 'cd' with no args)",{COMPL_NONE,COMPL_NONE}},
3189 {"q",cmd_quit,"logoff the server",{COMPL_NONE,COMPL_NONE}},
3190 {"queue",cmd_queue,"show the print queue",{COMPL_NONE,COMPL_NONE}},
3191 {"quit",cmd_quit,"logoff the server",{COMPL_NONE,COMPL_NONE}},
3192 {"rd",cmd_rmdir,"<directory> remove a directory",{COMPL_NONE,COMPL_NONE}},
3193 {"recurse",cmd_recurse,"toggle directory recursion for mget and mput",{COMPL_NONE,COMPL_NONE}},
3194 {"reget",cmd_reget,"<remote name> [local name] get a file restarting at end of local file",{COMPL_REMOTE,COMPL_LOCAL}},
3195 {"rename",cmd_rename,"<src> <dest> rename some files",{COMPL_REMOTE,COMPL_REMOTE}},
3196 {"reput",cmd_reput,"<local name> [remote name] put a file restarting at end of remote file",{COMPL_LOCAL,COMPL_REMOTE}},
3197 {"rm",cmd_del,"<mask> delete all matching files",{COMPL_REMOTE,COMPL_NONE}},
3198 {"rmdir",cmd_rmdir,"<directory> remove a directory",{COMPL_NONE,COMPL_NONE}},
3199 {"showacls",cmd_showacls,"toggle if ACLs are shown or not",{COMPL_NONE,COMPL_NONE}},
3200 {"setmode",cmd_setmode,"filename <setmode string> change modes of file",{COMPL_REMOTE,COMPL_NONE}},
3201 {"stat",cmd_stat,"filename Do a UNIX extensions stat call on a file",{COMPL_REMOTE,COMPL_REMOTE}},
3202 {"symlink",cmd_symlink,"<oldname> <newname> create a UNIX symlink",{COMPL_REMOTE,COMPL_REMOTE}},
3203 {"tar",cmd_tar,"tar <c|x>[IXFqbgNan] current directory to/from <file name>",{COMPL_NONE,COMPL_NONE}},
3204 {"tarmode",cmd_tarmode,"<full|inc|reset|noreset> tar's behaviour towards archive bits",{COMPL_NONE,COMPL_NONE}},
3205 {"translate",cmd_translate,"toggle text translation for printing",{COMPL_NONE,COMPL_NONE}},
3206 {"unlock",cmd_unlock,"unlock <fnum> <hex-start> <hex-len> : remove a POSIX lock",{COMPL_REMOTE,COMPL_REMOTE}},
3207 {"volume",cmd_volume,"print the volume name",{COMPL_NONE,COMPL_NONE}},
3208 {"vuid",cmd_vuid,"change current vuid",{COMPL_NONE,COMPL_NONE}},
3209 {"logon",cmd_logon,"establish new logon",{COMPL_NONE,COMPL_NONE}},
3210 {"listconnect",cmd_list_connect,"list open connections",{COMPL_NONE,COMPL_NONE}},
3211 {"showconnect",cmd_show_connect,"display the current active connection",{COMPL_NONE,COMPL_NONE}},
3213 /* Yes, this must be here, see crh's comment above. */
3214 {"!",NULL,"run a shell command on the local system",{COMPL_NONE,COMPL_NONE}},
3215 {NULL,NULL,NULL,{COMPL_NONE,COMPL_NONE}}
3218 /*******************************************************************
3219 Lookup a command string in the list of commands, including
3221 ******************************************************************/
3223 static int process_tok(pstring tok)
3225 int i = 0, matches = 0;
3227 int tok_len = strlen(tok);
3229 while (commands[i].fn != NULL) {
3230 if (strequal(commands[i].name,tok)) {
3234 } else if (strnequal(commands[i].name, tok, tok_len)) {
3243 else if (matches == 1)
3249 /****************************************************************************
3251 ****************************************************************************/
3253 static int cmd_help(void)
3258 if (next_token_nr(NULL,buf,NULL,sizeof(buf))) {
3259 if ((i = process_tok(buf)) >= 0)
3260 d_printf("HELP %s:\n\t%s\n\n",commands[i].name,commands[i].description);
3262 while (commands[i].description) {
3263 for (j=0; commands[i].description && (j<5); j++) {
3264 d_printf("%-15s",commands[i].name);
3273 /****************************************************************************
3274 Process a -c command string.
3275 ****************************************************************************/
3277 static int process_command_string(char *cmd)
3283 /* establish the connection if not already */
3286 cli = cli_cm_open(desthost, service, True);
3291 while (cmd[0] != '\0') {
3296 if ((p = strchr_m(cmd, ';')) == 0) {
3297 strncpy(line, cmd, 999);
3303 strncpy(line, cmd, p - cmd);
3304 line[p - cmd] = '\0';
3308 /* and get the first part of the command */
3310 if (!next_token_nr(&ptr,tok,NULL,sizeof(tok))) continue;
3312 if ((i = process_tok(tok)) >= 0) {
3313 rc = commands[i].fn();
3314 } else if (i == -2) {
3315 d_printf("%s: command abbreviation ambiguous\n",tok);
3317 d_printf("%s: command not found\n",tok);
3324 #define MAX_COMPLETIONS 100
3332 } completion_remote_t;
3334 static void completion_remote_filter(const char *mnt, file_info *f, const char *mask, void *state)
3336 completion_remote_t *info = (completion_remote_t *)state;
3338 if ((info->count < MAX_COMPLETIONS - 1) && (strncmp(info->text, f->name, info->len) == 0) && (strcmp(f->name, ".") != 0) && (strcmp(f->name, "..") != 0)) {
3339 if ((info->dirmask[0] == 0) && !(f->mode & aDIR))
3340 info->matches[info->count] = SMB_STRDUP(f->name);
3344 if (info->dirmask[0] != 0)
3345 pstrcpy(tmp, info->dirmask);
3348 pstrcat(tmp, f->name);
3351 info->matches[info->count] = SMB_STRDUP(tmp);
3353 if (info->matches[info->count] == NULL)
3356 smb_readline_ca_char(0);
3358 if (info->count == 1)
3359 info->samelen = strlen(info->matches[info->count]);
3361 while (strncmp(info->matches[info->count], info->matches[info->count-1], info->samelen) != 0)
3367 static char **remote_completion(const char *text, int len)
3371 completion_remote_t info = { "", NULL, 1, 0, NULL, 0 };
3373 /* can't have non-static intialisation on Sun CC, so do it
3379 if (len >= MIN(PATH_MAX,sizeof(pstring))) {
3383 info.matches = SMB_MALLOC_ARRAY(char *,MAX_COMPLETIONS);
3384 if (!info.matches) {
3389 * We're leaving matches[0] free to fill it later with the text to
3390 * display: Either the one single match or the longest common subset
3393 info.matches[0] = NULL;
3396 for (i = len-1; i >= 0; i--) {
3397 if ((text[i] == '/') || (text[i] == CLI_DIRSEP_CHAR)) {
3402 info.text = text+i+1;
3403 info.samelen = info.len = len-i-1;
3406 strncpy(info.dirmask, text, i+1);
3407 info.dirmask[i+1] = 0;
3408 pstr_sprintf(dirmask, "%s%*s*", cur_dir, i-1, text);
3410 pstr_sprintf(dirmask, "%s*", cur_dir);
3413 if (cli_list(cli, dirmask, aDIR | aSYSTEM | aHIDDEN, completion_remote_filter, &info) < 0)
3416 if (info.count == 1) {
3419 * No matches at all, NULL indicates there is nothing
3422 SAFE_FREE(info.matches[0]);
3423 SAFE_FREE(info.matches);
3427 if (info.count == 2) {
3430 * Exactly one match in matches[1], indicate this is the one
3434 info.matches[0] = info.matches[1];
3435 info.matches[1] = NULL;
3437 return info.matches;
3441 * We got more than one possible match, set the result to the maximum
3445 info.matches[0] = SMB_STRNDUP(info.matches[1], info.samelen);
3446 info.matches[info.count] = NULL;
3447 return info.matches;
3450 for (i = 0; i < info.count; i++)
3451 free(info.matches[i]);
3456 static char **completion_fn(const char *text, int start, int end)
3458 smb_readline_ca_char(' ');
3461 const char *buf, *sp;
3465 buf = smb_readline_get_line_buffer();
3469 sp = strchr(buf, ' ');
3473 for (i = 0; commands[i].name; i++) {
3474 if ((strncmp(commands[i].name, buf, sp - buf) == 0) &&
3475 (commands[i].name[sp - buf] == 0)) {
3479 if (commands[i].name == NULL)
3485 if (sp == (buf + start))
3486 compl_type = commands[i].compl_args[0];
3488 compl_type = commands[i].compl_args[1];
3490 if (compl_type == COMPL_REMOTE)
3491 return remote_completion(text, end - start);
3492 else /* fall back to local filename completion */
3496 int i, len, samelen = 0, count=1;
3498 matches = SMB_MALLOC_ARRAY(char *, MAX_COMPLETIONS);
3505 for (i=0;commands[i].fn && count < MAX_COMPLETIONS-1;i++) {
3506 if (strncmp(text, commands[i].name, len) == 0) {
3507 matches[count] = SMB_STRDUP(commands[i].name);
3508 if (!matches[count])
3511 samelen = strlen(matches[count]);
3513 while (strncmp(matches[count], matches[count-1], samelen) != 0)
3520 case 0: /* should never happen */
3524 matches[0] = SMB_STRDUP(matches[1]);
3527 matches[0] = (char *)SMB_MALLOC(samelen+1);
3530 strncpy(matches[0], matches[1], samelen);
3531 matches[0][samelen] = 0;
3533 matches[count] = NULL;
3537 for (i = 0; i < count; i++)
3545 /****************************************************************************
3546 Make sure we swallow keepalives during idle time.
3547 ****************************************************************************/
3549 static void readline_callback(void)
3552 struct timeval timeout;
3553 static time_t last_t;
3569 FD_SET(cli->fd,&fds);
3572 timeout.tv_usec = 0;
3573 sys_select_intr(cli->fd+1,&fds,NULL,NULL,&timeout);
3575 /* We deliberately use receive_smb instead of
3576 client_receive_smb as we want to receive
3577 session keepalives and then drop them here.
3579 if (FD_ISSET(cli->fd,&fds)) {
3580 if (!receive_smb(cli->fd,cli->inbuf,0)) {
3581 DEBUG(0, ("Read from server failed, maybe it closed the "
3588 /* Ping the server to keep the connection alive using SMBecho. */
3590 unsigned char garbage[16];
3591 memset(garbage, 0xf0, sizeof(garbage));
3592 cli_echo(cli, garbage, sizeof(garbage));
3596 /****************************************************************************
3597 Process commands on stdin.
3598 ****************************************************************************/
3600 static int process_stdin(void)
3612 /* display a prompt */
3613 slprintf(the_prompt, sizeof(the_prompt)-1, "smb: %s> ", cur_dir);
3614 cline = smb_readline(the_prompt, readline_callback, completion_fn);
3618 pstrcpy(line, cline);
3620 /* special case - first char is ! */
3626 /* and get the first part of the command */
3628 if (!next_token_nr(&ptr,tok,NULL,sizeof(tok))) continue;
3630 if ((i = process_tok(tok)) >= 0) {
3631 rc = commands[i].fn();
3632 } else if (i == -2) {
3633 d_printf("%s: command abbreviation ambiguous\n",tok);
3635 d_printf("%s: command not found\n",tok);
3641 /****************************************************************************
3642 Process commands from the client.
3643 ****************************************************************************/
3645 static int process(char *base_directory)
3649 cli = cli_cm_open(desthost, service, True);
3654 if (*base_directory) {
3655 rc = do_cd(base_directory);
3663 rc = process_command_string(cmdstr);
3672 /****************************************************************************
3674 ****************************************************************************/
3676 static int do_host_query(char *query_host)
3678 cli = cli_cm_open(query_host, "IPC$", True);
3686 /* Workgroups simply don't make sense over anything
3687 else but port 139... */
3690 cli_cm_set_port( 139 );
3691 cli = cli_cm_open(query_host, "IPC$", True);
3695 d_printf("NetBIOS over TCP disabled -- no workgroup available\n");
3699 list_servers(lp_workgroup());
3706 /****************************************************************************
3707 Handle a tar operation.
3708 ****************************************************************************/
3710 static int do_tar_op(char *base_directory)
3714 /* do we already have a connection? */
3716 cli = cli_cm_open(desthost, service, True);
3723 if (*base_directory) {
3724 ret = do_cd(base_directory);
3738 /****************************************************************************
3739 Handle a message operation.
3740 ****************************************************************************/
3742 static int do_message_op(void)
3745 struct nmb_name called, calling;
3746 fstring server_name;
3747 char name_type_hex[10];
3750 make_nmb_name(&calling, calling_name, 0x0);
3751 make_nmb_name(&called , desthost, name_type);
3753 fstrcpy(server_name, desthost);
3754 snprintf(name_type_hex, sizeof(name_type_hex), "#%X", name_type);
3755 fstrcat(server_name, name_type_hex);
3761 /* we can only do messages over port 139 (to windows clients at least) */
3763 msg_port = port ? port : 139;
3765 if (!(cli=cli_initialise()) || (cli_set_port(cli, msg_port) != msg_port) ||
3766 !cli_connect(cli, server_name, &ip)) {
3767 d_printf("Connection to %s failed\n", desthost);
3771 if (!cli_session_request(cli, &calling, &called)) {
3772 d_printf("session request failed\n");
3784 /****************************************************************************
3786 ****************************************************************************/
3788 int main(int argc,char *argv[])
3790 pstring base_directory;
3793 BOOL message = False;
3795 static const char *new_name_resolve_order = NULL;
3799 fstring new_workgroup;
3800 struct poptOption long_options[] = {
3803 { "name-resolve", 'R', POPT_ARG_STRING, &new_name_resolve_order, 'R', "Use these name resolution services only", "NAME-RESOLVE-ORDER" },
3804 { "message", 'M', POPT_ARG_STRING, NULL, 'M', "Send message", "HOST" },
3805 { "ip-address", 'I', POPT_ARG_STRING, NULL, 'I', "Use this IP to connect to", "IP" },
3806 { "stderr", 'E', POPT_ARG_NONE, NULL, 'E', "Write messages to stderr instead of stdout" },
3807 { "list", 'L', POPT_ARG_STRING, NULL, 'L', "Get a list of shares available on a host", "HOST" },
3808 { "terminal", 't', POPT_ARG_STRING, NULL, 't', "Terminal I/O code {sjis|euc|jis7|jis8|junet|hex}", "CODE" },
3809 { "max-protocol", 'm', POPT_ARG_STRING, NULL, 'm', "Set the max protocol level", "LEVEL" },
3810 { "tar", 'T', POPT_ARG_STRING, NULL, 'T', "Command line tar", "<c|x>IXFqgbNan" },
3811 { "directory", 'D', POPT_ARG_STRING, NULL, 'D', "Start from directory", "DIR" },
3812 { "command", 'c', POPT_ARG_STRING, &cmdstr, 'c', "Execute semicolon separated commands" },
3813 { "send-buffer", 'b', POPT_ARG_INT, &io_bufsize, 'b', "Changes the transmit/send buffer", "BYTES" },
3814 { "port", 'p', POPT_ARG_INT, &port, 'p', "Port to connect to", "PORT" },
3815 { "grepable", 'g', POPT_ARG_NONE, NULL, 'g', "Produce grepable output" },
3817 POPT_COMMON_CONNECTION
3818 POPT_COMMON_CREDENTIALS
3825 pstrcpy(term_code, KANJI);
3831 *base_directory = 0;
3833 /* initialize the workgroup name so we can determine whether or
3834 not it was set by a command line option */
3836 set_global_myworkgroup( "" );
3837 set_global_myname( "" );
3839 /* set default debug level to 0 regardless of what smb.conf sets */
3840 setup_logging( "smbclient", True );
3841 DEBUGLEVEL_CLASS[DBGC_ALL] = 1;
3842 if ((dbf = x_fdup(x_stderr))) {
3843 x_setbuf( dbf, NULL );
3846 pc = poptGetContext("smbclient", argc, (const char **) argv, long_options,
3847 POPT_CONTEXT_KEEP_FIRST);
3848 poptSetOtherOptionHelp(pc, "service <password>");
3850 in_client = True; /* Make sure that we tell lp_load we are */
3852 while ((opt = poptGetNextOpt(pc)) != -1) {
3855 /* Messages are sent to NetBIOS name type 0x3
3856 * (Messenger Service). Make sure we default
3857 * to port 139 instead of port 445. srl,crh
3860 cli_cm_set_dest_name_type( name_type );
3861 pstrcpy(desthost,poptGetOptArg(pc));
3863 cli_cm_set_port( 139 );
3868 dest_ip = *interpret_addr2(poptGetOptArg(pc));
3869 if (is_zero_ip(dest_ip))
3873 cli_cm_set_dest_ip( dest_ip );
3881 display_set_stderr();
3885 pstrcpy(query_host, poptGetOptArg(pc));
3888 pstrcpy(term_code, poptGetOptArg(pc));
3891 max_protocol = interpret_protocol(poptGetOptArg(pc), max_protocol);
3894 /* We must use old option processing for this. Find the
3895 * position of the -T option in the raw argv[]. */
3898 for (i = 1; i < argc; i++) {
3899 if (strncmp("-T", argv[i],2)==0)
3903 if (!(optnum = tar_parseargs(argc, argv, poptGetOptArg(pc), i))) {
3904 poptPrintUsage(pc, stderr, 0);
3907 /* Now we must eat (optnum - i) options - they have
3908 * been processed by tar_parseargs().
3911 for (i = 0; i < optnum; i++)
3916 pstrcpy(base_directory,poptGetOptArg(pc));
3926 /* check for the -P option */
3929 cli_cm_set_port( port );
3932 * Don't load debug level from smb.conf. It should be
3933 * set by cmdline arg or remain default (0)
3935 AllowDebugChange = False;
3937 /* save the workgroup...
3939 FIXME!! do we need to do this for other options as well
3940 (or maybe a generic way to keep lp_load() from overwriting
3943 fstrcpy( new_workgroup, lp_workgroup() );
3944 pstrcpy( calling_name, global_myname() );
3946 if ( override_logfile )
3947 setup_logging( lp_logfile(), False );
3949 if (!lp_load(dyn_CONFIGFILE,True,False,False,True)) {
3950 fprintf(stderr, "%s: Can't load %s - run testparm to debug it\n",
3951 argv[0], dyn_CONFIGFILE);
3956 if ( strlen(new_workgroup) != 0 )
3957 set_global_myworkgroup( new_workgroup );
3959 if ( strlen(calling_name) != 0 )
3960 set_global_myname( calling_name );
3962 pstrcpy( calling_name, global_myname() );
3964 if(poptPeekArg(pc)) {
3965 pstrcpy(service,poptGetArg(pc));
3966 /* Convert any '/' characters in the service name to '\' characters */
3967 string_replace(service, '/','\\');
3969 if (count_chars(service,'\\') < 3) {
3970 d_printf("\n%s: Not enough '\\' characters in service\n",service);
3971 poptPrintUsage(pc, stderr, 0);
3976 if (poptPeekArg(pc) && !cmdline_auth_info.got_pass) {
3977 cmdline_auth_info.got_pass = True;
3978 pstrcpy(cmdline_auth_info.password,poptGetArg(pc));
3983 if(new_name_resolve_order)
3984 lp_set_name_resolve_order(new_name_resolve_order);
3986 if (!tar_type && !*query_host && !*service && !message) {
3987 poptPrintUsage(pc, stderr, 0);
3991 poptFreeContext(pc);
3993 /* store the username an password for dfs support */
3995 cli_cm_set_credentials( &cmdline_auth_info );
3996 pstrcpy(username, cmdline_auth_info.username);
3998 DEBUG(3,("Client started (version %s).\n", SAMBA_VERSION_STRING));
4002 process_command_string(cmdstr);
4003 return do_tar_op(base_directory);
4007 char *qhost = query_host;
4010 while (*qhost == '\\' || *qhost == '/')
4013 if ((slash = strchr_m(qhost, '/'))
4014 || (slash = strchr_m(qhost, '\\'))) {
4018 if ((p=strchr_m(qhost, '#'))) {
4021 sscanf(p, "%x", &name_type);
4022 cli_cm_set_dest_name_type( name_type );
4025 return do_host_query(qhost);
4029 return do_message_op();
4032 if (process(base_directory)) {
4036 talloc_destroy( ctx);