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-2004
7 Copyright (C) James J Myers 2003 <myersjj@samba.org>
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 "dynconfig.h"
27 #include "lib/cmdline/popt_common.h"
28 #include "librpc/gen_ndr/ndr_srvsvc.h"
29 #include "libcli/raw/libcliraw.h"
30 #include "system/time.h"
31 #include "system/dir.h"
32 #include "system/filesys.h"
33 #include "dlinklist.h"
39 struct smbcli_state *cli;
40 extern BOOL in_client;
42 pstring cur_dir = "\\";
43 static pstring cd_path = "";
44 static pstring service;
45 static pstring desthost;
46 static pstring username;
47 static pstring domain;
48 static pstring password;
49 static char *cmdstr = NULL;
51 static int io_bufsize = 64512;
53 static int name_type = 0x20;
55 static int process_tok(fstring tok);
56 static int cmd_help(const char **cmd_ptr);
58 /* 30 second timeout on most commands */
59 #define CLIENT_TIMEOUT (30*1000)
60 #define SHORT_TIMEOUT (5*1000)
62 /* value for unused fid field in trans2 secondary request */
63 #define FID_UNUSED (0xFFFF)
65 time_t newer_than = 0;
66 static int archive_level = 0;
68 static BOOL translation = False;
70 /* clitar bits insert */
73 extern BOOL tar_reset;
77 static BOOL prompt = True;
79 static int printmode = 1;
81 static BOOL recurse = False;
82 BOOL lowercase = False;
84 static const char *dest_ip;
86 #define SEPARATORS " \t\n\r"
88 static BOOL abort_mget = True;
90 static pstring fileselection = "";
93 uint64_t get_total_size = 0;
94 uint_t get_total_time_ms = 0;
95 static uint64_t put_total_size = 0;
96 static uint_t put_total_time_ms = 0;
99 static double dir_total;
103 /* some forward declarations */
104 static struct smbcli_state *do_connect(const char *server, const char *share);
107 /*******************************************************************
108 Reduce a file name, removing .. elements.
109 ********************************************************************/
110 void dos_clean_name(char *s)
114 DEBUG(3,("dos_clean_name [%s]\n",s));
116 /* remove any double slashes */
117 all_string_sub(s, "\\\\", "\\", 0);
119 while ((p = strstr(s,"\\..\\")) != NULL) {
125 if ((p=strrchr_m(s,'\\')) != NULL)
132 trim_string(s,NULL,"\\..");
134 all_string_sub(s, "\\.\\", "\\", 0);
137 /****************************************************************************
138 write to a local file with CR/LF->LF translation if appropriate. return the
139 number taken from the buffer. This may not equal the number written.
140 ****************************************************************************/
141 static int writefile(int f, char *b, int n)
151 if (*b == '\r' && (i<(n-1)) && *(b+1) == '\n') {
154 if (write(f, b, 1) != 1) {
164 /****************************************************************************
165 read from a file with LF->CR/LF translation if appropriate. return the
166 number read. read approx n bytes.
167 ****************************************************************************/
168 static int readfile(char *b, int n, XFILE *f)
174 return x_fread(b,1,n,f);
177 while (i < (n - 1)) {
178 if ((c = x_getc(f)) == EOF) {
182 if (c == '\n') { /* change all LFs to CR/LF */
193 /****************************************************************************
195 ****************************************************************************/
196 static void send_message(void)
201 if (!smbcli_message_start(cli->tree, desthost, username, &grp_id)) {
202 d_printf("message start: %s\n", smbcli_errstr(cli->tree));
207 d_printf("Connected. Type your message, ending it with a Control-D\n");
209 while (!feof(stdin) && total_len < 1600) {
210 int maxlen = MIN(1600 - total_len,127);
217 for (l=0;l<maxlen && (c=fgetc(stdin))!=EOF;l++) {
223 if (!smbcli_message_text(cli->tree, msg, l, grp_id)) {
224 d_printf("SMBsendtxt failed (%s)\n",smbcli_errstr(cli->tree));
231 if (total_len >= 1600)
232 d_printf("the message was truncated to 1600 bytes\n");
234 d_printf("sent %d bytes\n",total_len);
236 if (!smbcli_message_end(cli->tree, grp_id)) {
237 d_printf("SMBsendend failed (%s)\n",smbcli_errstr(cli->tree));
244 /****************************************************************************
245 check the space on a device
246 ****************************************************************************/
247 static int do_dskattr(void)
249 int total, bsize, avail;
251 if (NT_STATUS_IS_ERR(smbcli_dskattr(cli->tree, &bsize, &total, &avail))) {
252 d_printf("Error in dskattr: %s\n",smbcli_errstr(cli->tree));
256 d_printf("\n\t\t%d blocks of size %d. %d blocks available\n",
257 total, bsize, avail);
262 /****************************************************************************
264 ****************************************************************************/
265 static int cmd_pwd(const char **cmd_ptr)
267 d_printf("Current directory is %s",service);
268 d_printf("%s\n",cur_dir);
273 convert a string to dos format
275 static void dos_format(char *s)
277 string_replace(s, '/', '\\');
280 /****************************************************************************
281 change directory - inner section
282 ****************************************************************************/
283 static int do_cd(char *newdir)
291 /* Save the current directory in case the
292 new directory is invalid */
293 pstrcpy(saved_dir, cur_dir);
298 if (*(cur_dir+strlen(cur_dir)-1) != '\\') {
299 pstrcat(cur_dir, "\\");
301 dos_clean_name(cur_dir);
302 pstrcpy(dname,cur_dir);
303 pstrcat(cur_dir,"\\");
304 dos_clean_name(cur_dir);
306 if (!strequal(cur_dir,"\\")) {
307 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, dname))) {
308 d_printf("cd %s: %s\n", dname, smbcli_errstr(cli->tree));
309 pstrcpy(cur_dir,saved_dir);
313 pstrcpy(cd_path,cur_dir);
318 /****************************************************************************
320 ****************************************************************************/
321 static int cmd_cd(const char **cmd_ptr)
326 if (next_token(cmd_ptr,buf,NULL,sizeof(buf)))
329 d_printf("Current directory is %s\n",cur_dir);
335 BOOL mask_match(struct smbcli_state *c, const char *string, char *pattern,
336 BOOL is_case_sensitive)
340 if (strcmp(string,"..") == 0)
342 if (strcmp(pattern,".") == 0)
345 if (is_case_sensitive)
346 return ms_fnmatch(pattern, string,
347 c->transport->negotiate.protocol) == 0;
349 fstrcpy(p2, pattern);
353 return ms_fnmatch(p2, s2, c->transport->negotiate.protocol) == 0;
358 /*******************************************************************
359 decide if a file should be operated on
360 ********************************************************************/
361 static BOOL do_this_one(struct clilist_file_info *finfo)
363 if (finfo->attrib & FILE_ATTRIBUTE_DIRECTORY) return(True);
365 if (*fileselection &&
366 !mask_match(cli, finfo->name,fileselection,False)) {
367 DEBUG(3,("mask_match %s failed\n", finfo->name));
371 if (newer_than && finfo->mtime < newer_than) {
372 DEBUG(3,("newer_than %s failed\n", finfo->name));
376 if ((archive_level==1 || archive_level==2) && !(finfo->attrib & FILE_ATTRIBUTE_ARCHIVE)) {
377 DEBUG(3,("archive %s failed\n", finfo->name));
384 /****************************************************************************
385 display info about a file
386 ****************************************************************************/
387 static void display_finfo(struct clilist_file_info *finfo)
389 if (do_this_one(finfo)) {
390 time_t t = finfo->mtime; /* the time is assumed to be passed as GMT */
391 char *astr = attrib_string(NULL, finfo->attrib);
392 d_printf(" %-30s%7.7s %8.0f %s",
396 asctime(localtime(&t)));
397 dir_total += finfo->size;
403 /****************************************************************************
404 accumulate size of a file
405 ****************************************************************************/
406 static void do_du(struct clilist_file_info *finfo)
408 if (do_this_one(finfo)) {
409 dir_total += finfo->size;
413 static BOOL do_list_recurse;
414 static BOOL do_list_dirs;
415 static char *do_list_queue = 0;
416 static long do_list_queue_size = 0;
417 static long do_list_queue_start = 0;
418 static long do_list_queue_end = 0;
419 static void (*do_list_fn)(struct clilist_file_info *);
421 /****************************************************************************
422 functions for do_list_queue
423 ****************************************************************************/
426 * The do_list_queue is a NUL-separated list of strings stored in a
427 * char*. Since this is a FIFO, we keep track of the beginning and
428 * ending locations of the data in the queue. When we overflow, we
429 * double the size of the char*. When the start of the data passes
430 * the midpoint, we move everything back. This is logically more
431 * complex than a linked list, but easier from a memory management
432 * angle. In any memory error condition, do_list_queue is reset.
433 * Functions check to ensure that do_list_queue is non-NULL before
436 static void reset_do_list_queue(void)
438 SAFE_FREE(do_list_queue);
439 do_list_queue_size = 0;
440 do_list_queue_start = 0;
441 do_list_queue_end = 0;
444 static void init_do_list_queue(void)
446 reset_do_list_queue();
447 do_list_queue_size = 1024;
448 do_list_queue = malloc(do_list_queue_size);
449 if (do_list_queue == 0) {
450 d_printf("malloc fail for size %d\n",
451 (int)do_list_queue_size);
452 reset_do_list_queue();
454 memset(do_list_queue, 0, do_list_queue_size);
458 static void adjust_do_list_queue(void)
461 * If the starting point of the queue is more than half way through,
462 * move everything toward the beginning.
464 if (do_list_queue && (do_list_queue_start == do_list_queue_end))
466 DEBUG(4,("do_list_queue is empty\n"));
467 do_list_queue_start = do_list_queue_end = 0;
468 *do_list_queue = '\0';
470 else if (do_list_queue_start > (do_list_queue_size / 2))
472 DEBUG(4,("sliding do_list_queue backward\n"));
473 memmove(do_list_queue,
474 do_list_queue + do_list_queue_start,
475 do_list_queue_end - do_list_queue_start);
476 do_list_queue_end -= do_list_queue_start;
477 do_list_queue_start = 0;
482 static void add_to_do_list_queue(const char* entry)
485 long new_end = do_list_queue_end + ((long)strlen(entry)) + 1;
486 while (new_end > do_list_queue_size)
488 do_list_queue_size *= 2;
489 DEBUG(4,("enlarging do_list_queue to %d\n",
490 (int)do_list_queue_size));
491 dlq = Realloc(do_list_queue, do_list_queue_size);
493 d_printf("failure enlarging do_list_queue to %d bytes\n",
494 (int)do_list_queue_size);
495 reset_do_list_queue();
500 memset(do_list_queue + do_list_queue_size / 2,
501 0, do_list_queue_size / 2);
506 safe_strcpy(do_list_queue + do_list_queue_end, entry,
507 do_list_queue_size - do_list_queue_end - 1);
508 do_list_queue_end = new_end;
509 DEBUG(4,("added %s to do_list_queue (start=%d, end=%d)\n",
510 entry, (int)do_list_queue_start, (int)do_list_queue_end));
514 static char *do_list_queue_head(void)
516 return do_list_queue + do_list_queue_start;
519 static void remove_do_list_queue_head(void)
521 if (do_list_queue_end > do_list_queue_start)
523 do_list_queue_start += strlen(do_list_queue_head()) + 1;
524 adjust_do_list_queue();
525 DEBUG(4,("removed head of do_list_queue (start=%d, end=%d)\n",
526 (int)do_list_queue_start, (int)do_list_queue_end));
530 static int do_list_queue_empty(void)
532 return (! (do_list_queue && *do_list_queue));
535 /****************************************************************************
537 ****************************************************************************/
538 static void do_list_helper(struct clilist_file_info *f, const char *mask, void *state)
540 if (f->attrib & FILE_ATTRIBUTE_DIRECTORY) {
541 if (do_list_dirs && do_this_one(f)) {
544 if (do_list_recurse &&
545 !strequal(f->name,".") &&
546 !strequal(f->name,"..")) {
550 pstrcpy(mask2, mask);
551 p = strrchr_m(mask2,'\\');
554 pstrcat(mask2, f->name);
555 pstrcat(mask2,"\\*");
556 add_to_do_list_queue(mask2);
561 if (do_this_one(f)) {
567 /****************************************************************************
568 a wrapper around smbcli_list that adds recursion
569 ****************************************************************************/
570 void do_list(const char *mask,uint16_t attribute,
571 void (*fn)(struct clilist_file_info *),BOOL rec, BOOL dirs)
573 static int in_do_list = 0;
575 if (in_do_list && rec)
577 fprintf(stderr, "INTERNAL ERROR: do_list called recursively when the recursive flag is true\n");
583 do_list_recurse = rec;
589 init_do_list_queue();
590 add_to_do_list_queue(mask);
592 while (! do_list_queue_empty())
595 * Need to copy head so that it doesn't become
596 * invalid inside the call to smbcli_list. This
597 * would happen if the list were expanded
599 * Fix from E. Jay Berkenbilt (ejb@ql.org)
602 pstrcpy(head, do_list_queue_head());
603 smbcli_list(cli->tree, head, attribute, do_list_helper, NULL);
604 remove_do_list_queue_head();
605 if ((! do_list_queue_empty()) && (fn == display_finfo))
607 char* next_file = do_list_queue_head();
609 if ((strlen(next_file) >= 2) &&
610 (next_file[strlen(next_file) - 1] == '*') &&
611 (next_file[strlen(next_file) - 2] == '\\'))
613 save_ch = next_file +
614 strlen(next_file) - 2;
617 d_printf("\n%s\n",next_file);
627 if (smbcli_list(cli->tree, mask, attribute, do_list_helper, NULL) == -1)
629 d_printf("%s listing %s\n", smbcli_errstr(cli->tree), mask);
634 reset_do_list_queue();
637 /****************************************************************************
638 get a directory listing
639 ****************************************************************************/
640 static int cmd_dir(const char **cmd_ptr)
642 uint16_t attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
649 pstrcpy(mask,cur_dir);
650 if(mask[strlen(mask)-1]!='\\')
653 if (next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
661 if (cli->tree->session->transport->negotiate.protocol <=
669 do_list(mask, attribute, display_finfo, recurse, True);
673 DEBUG(3, ("Total bytes listed: %.0f\n", dir_total));
679 /****************************************************************************
680 get a directory listing
681 ****************************************************************************/
682 static int cmd_du(const char **cmd_ptr)
684 uint16_t attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
691 pstrcpy(mask,cur_dir);
692 if(mask[strlen(mask)-1]!='\\')
695 if (next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
705 do_list(mask, attribute, do_du, recurse, True);
709 d_printf("Total number of bytes: %.0f\n", dir_total);
715 /****************************************************************************
716 get a file from rname to lname
717 ****************************************************************************/
718 static int do_get(char *rname, const char *lname, BOOL reget)
720 int handle = 0, fnum;
721 BOOL newhandle = False;
723 struct timeval tp_start;
724 int read_size = io_bufsize;
731 GetTimeOfDay(&tp_start);
734 strlower(discard_const_p(char, lname));
737 fnum = smbcli_open(cli->tree, rname, O_RDONLY, DENY_NONE);
740 d_printf("%s opening remote file %s\n",smbcli_errstr(cli->tree),rname);
744 if(!strcmp(lname,"-")) {
745 handle = fileno(stdout);
748 handle = open(lname, O_WRONLY|O_CREAT, 0644);
750 start = lseek(handle, 0, SEEK_END);
752 d_printf("Error seeking local file\n");
757 handle = open(lname, O_WRONLY|O_CREAT|O_TRUNC, 0644);
762 d_printf("Error opening local file %s\n",lname);
767 if (NT_STATUS_IS_ERR(smbcli_qfileinfo(cli->tree, fnum,
768 &attr, &size, NULL, NULL, NULL, NULL, NULL)) &&
769 NT_STATUS_IS_ERR(smbcli_getattrE(cli->tree, fnum,
770 &attr, &size, NULL, NULL, NULL))) {
771 d_printf("getattrib: %s\n",smbcli_errstr(cli->tree));
775 DEBUG(2,("getting file %s of size %.0f as %s ",
776 rname, (double)size, lname));
778 if(!(data = (char *)malloc(read_size))) {
779 d_printf("malloc fail for size %d\n", read_size);
780 smbcli_close(cli->tree, fnum);
785 int n = smbcli_read(cli->tree, fnum, data, nread + start, read_size);
789 if (writefile(handle,data, n) != n) {
790 d_printf("Error writing local file\n");
798 if (nread + start < size) {
799 DEBUG (0, ("Short read when getting file %s. Only got %ld bytes.\n",
800 rname, (long)nread));
807 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
808 d_printf("Error %s closing remote file\n",smbcli_errstr(cli->tree));
816 if (archive_level >= 2 && (attr & FILE_ATTRIBUTE_ARCHIVE)) {
817 smbcli_setatr(cli->tree, rname, attr & ~(uint16_t)FILE_ATTRIBUTE_ARCHIVE, 0);
821 struct timeval tp_end;
824 GetTimeOfDay(&tp_end);
826 (tp_end.tv_sec - tp_start.tv_sec)*1000 +
827 (tp_end.tv_usec - tp_start.tv_usec)/1000;
828 get_total_time_ms += this_time;
829 get_total_size += nread;
831 DEBUG(2,("(%3.1f kb/s) (average %3.1f kb/s)\n",
832 nread / (1.024*this_time + 1.0e-4),
833 get_total_size / (1.024*get_total_time_ms)));
840 /****************************************************************************
842 ****************************************************************************/
843 static int cmd_get(const char **cmd_ptr)
849 pstrcpy(rname,cur_dir);
852 p = rname + strlen(rname);
854 if (!next_token(cmd_ptr,p,NULL,sizeof(rname)-strlen(rname))) {
855 d_printf("get <filename>\n");
859 dos_clean_name(rname);
861 next_token(cmd_ptr,lname,NULL,sizeof(lname));
863 return do_get(rname, lname, False);
866 /****************************************************************************
867 Put up a yes/no prompt.
868 ****************************************************************************/
869 static BOOL yesno(char *p)
874 if (!fgets(ans,sizeof(ans)-1,stdin))
877 if (*ans == 'y' || *ans == 'Y')
883 /****************************************************************************
884 do a mget operation on one file
885 ****************************************************************************/
886 static void do_mget(struct clilist_file_info *finfo)
890 pstring saved_curdir;
893 if (strequal(finfo->name,".") || strequal(finfo->name,".."))
897 d_printf("mget aborted\n");
901 if (finfo->attrib & FILE_ATTRIBUTE_DIRECTORY)
902 slprintf(quest,sizeof(pstring)-1,
903 "Get directory %s? ",finfo->name);
905 slprintf(quest,sizeof(pstring)-1,
906 "Get file %s? ",finfo->name);
908 if (prompt && !yesno(quest)) return;
910 if (!(finfo->attrib & FILE_ATTRIBUTE_DIRECTORY)) {
911 pstrcpy(rname,cur_dir);
912 pstrcat(rname,finfo->name);
913 do_get(rname, finfo->name, False);
917 /* handle directories */
918 pstrcpy(saved_curdir,cur_dir);
920 pstrcat(cur_dir,finfo->name);
921 pstrcat(cur_dir,"\\");
923 string_replace(discard_const_p(char, finfo->name), '\\', '/');
925 strlower(discard_const_p(char, finfo->name));
928 if (!directory_exist(finfo->name,NULL) &&
929 mkdir(finfo->name,0777) != 0) {
930 d_printf("failed to create directory %s\n",finfo->name);
931 pstrcpy(cur_dir,saved_curdir);
935 if (chdir(finfo->name) != 0) {
936 d_printf("failed to chdir to directory %s\n",finfo->name);
937 pstrcpy(cur_dir,saved_curdir);
941 pstrcpy(mget_mask,cur_dir);
942 pstrcat(mget_mask,"*");
944 do_list(mget_mask, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY,do_mget,False, True);
946 pstrcpy(cur_dir,saved_curdir);
950 /****************************************************************************
951 view the file using the pager
952 ****************************************************************************/
953 static int cmd_more(const char **cmd_ptr)
955 fstring rname,lname,pager_cmd;
960 fstrcpy(rname,cur_dir);
963 slprintf(lname,sizeof(lname)-1, "%s/smbmore.XXXXXX",tmpdir());
964 fd = smb_mkstemp(lname);
966 d_printf("failed to create temporary file for more\n");
971 if (!next_token(cmd_ptr,rname+strlen(rname),NULL,sizeof(rname)-strlen(rname))) {
972 d_printf("more <filename>\n");
976 dos_clean_name(rname);
978 rc = do_get(rname, lname, False);
980 pager=getenv("PAGER");
982 slprintf(pager_cmd,sizeof(pager_cmd)-1,
983 "%s %s",(pager? pager:PAGER), lname);
992 /****************************************************************************
994 ****************************************************************************/
995 static int cmd_mget(const char **cmd_ptr)
997 uint16_t attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
1005 attribute |= FILE_ATTRIBUTE_DIRECTORY;
1009 while (next_token(cmd_ptr,p,NULL,sizeof(buf))) {
1010 pstrcpy(mget_mask,cur_dir);
1011 if(mget_mask[strlen(mget_mask)-1]!='\\')
1012 pstrcat(mget_mask,"\\");
1015 pstrcpy(mget_mask,p);
1017 pstrcat(mget_mask,p);
1018 do_list(mget_mask, attribute,do_mget,False,True);
1022 pstrcpy(mget_mask,cur_dir);
1023 if(mget_mask[strlen(mget_mask)-1]!='\\')
1024 pstrcat(mget_mask,"\\");
1025 pstrcat(mget_mask,"*");
1026 do_list(mget_mask, attribute,do_mget,False,True);
1033 /****************************************************************************
1034 make a directory of name "name"
1035 ****************************************************************************/
1036 static NTSTATUS do_mkdir(char *name)
1040 if (NT_STATUS_IS_ERR(status = smbcli_mkdir(cli->tree, name))) {
1041 d_printf("%s making remote directory %s\n",
1042 smbcli_errstr(cli->tree),name);
1049 /****************************************************************************
1050 show 8.3 name of a file
1051 ****************************************************************************/
1052 static BOOL do_altname(char *name)
1054 const char *altname;
1055 if (!NT_STATUS_IS_OK(smbcli_qpathinfo_alt_name(cli->tree, name, &altname))) {
1056 d_printf("%s getting alt name for %s\n",
1057 smbcli_errstr(cli->tree),name);
1060 d_printf("%s\n", altname);
1066 /****************************************************************************
1068 ****************************************************************************/
1069 static int cmd_quit(const char **cmd_ptr)
1071 smbcli_shutdown(cli);
1078 /****************************************************************************
1080 ****************************************************************************/
1081 static int cmd_mkdir(const char **cmd_ptr)
1087 pstrcpy(mask,cur_dir);
1089 if (!next_token(cmd_ptr,p,NULL,sizeof(buf))) {
1091 d_printf("mkdir <dirname>\n");
1102 trim_string(ddir,".",NULL);
1103 p = strtok(ddir,"/\\");
1106 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, ddir2))) {
1109 pstrcat(ddir2,"\\");
1110 p = strtok(NULL,"/\\");
1120 /****************************************************************************
1122 ****************************************************************************/
1123 static int cmd_altname(const char **cmd_ptr)
1129 pstrcpy(name,cur_dir);
1131 if (!next_token(cmd_ptr,p,NULL,sizeof(buf))) {
1132 d_printf("altname <file>\n");
1143 /****************************************************************************
1145 ****************************************************************************/
1146 static int do_put(char *rname, char *lname, BOOL reput)
1153 int maxwrite = io_bufsize;
1156 struct timeval tp_start;
1157 GetTimeOfDay(&tp_start);
1160 fnum = smbcli_open(cli->tree, rname, O_RDWR|O_CREAT, DENY_NONE);
1162 if (NT_STATUS_IS_ERR(smbcli_qfileinfo(cli->tree, fnum, NULL, &start, NULL, NULL, NULL, NULL, NULL)) &&
1163 NT_STATUS_IS_ERR(smbcli_getattrE(cli->tree, fnum, NULL, &start, NULL, NULL, NULL))) {
1164 d_printf("getattrib: %s\n",smbcli_errstr(cli->tree));
1169 fnum = smbcli_open(cli->tree, rname, O_RDWR|O_CREAT|O_TRUNC,
1174 d_printf("%s opening remote file %s\n",smbcli_errstr(cli->tree),rname);
1178 /* allow files to be piped into smbclient
1181 Note that in this case this function will exit(0) rather
1183 if (!strcmp(lname, "-")) {
1185 /* size of file is not known */
1187 f = x_fopen(lname,O_RDONLY, 0);
1189 if (x_tseek(f, start, SEEK_SET) == -1) {
1190 d_printf("Error seeking local file\n");
1197 d_printf("Error opening local file %s\n",lname);
1202 DEBUG(1,("putting file %s as %s ",lname,
1205 buf = (char *)malloc(maxwrite);
1207 d_printf("ERROR: Not enough memory!\n");
1210 while (!x_feof(f)) {
1214 if ((n = readfile(buf,n,f)) < 1) {
1215 if((n == 0) && x_feof(f))
1216 break; /* Empty local file. */
1218 d_printf("Error reading local file: %s\n", strerror(errno));
1223 ret = smbcli_write(cli->tree, fnum, 0, buf, nread + start, n);
1226 d_printf("Error writing file: %s\n", smbcli_errstr(cli->tree));
1234 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
1235 d_printf("%s closing remote file %s\n",smbcli_errstr(cli->tree),rname);
1249 struct timeval tp_end;
1252 GetTimeOfDay(&tp_end);
1254 (tp_end.tv_sec - tp_start.tv_sec)*1000 +
1255 (tp_end.tv_usec - tp_start.tv_usec)/1000;
1256 put_total_time_ms += this_time;
1257 put_total_size += nread;
1259 DEBUG(1,("(%3.1f kb/s) (average %3.1f kb/s)\n",
1260 nread / (1.024*this_time + 1.0e-4),
1261 put_total_size / (1.024*put_total_time_ms)));
1265 smbcli_shutdown(cli);
1274 /****************************************************************************
1276 ****************************************************************************/
1277 static int cmd_put(const char **cmd_ptr)
1284 pstrcpy(rname,cur_dir);
1285 pstrcat(rname,"\\");
1287 if (!next_token(cmd_ptr,p,NULL,sizeof(buf))) {
1288 d_printf("put <filename>\n");
1293 if (next_token(cmd_ptr,p,NULL,sizeof(buf)))
1296 pstrcat(rname,lname);
1298 dos_clean_name(rname);
1302 /* allow '-' to represent stdin
1303 jdblair, 24.jun.98 */
1304 if (!file_exist(lname,&st) &&
1305 (strcmp(lname,"-"))) {
1306 d_printf("%s does not exist\n",lname);
1311 return do_put(rname, lname, False);
1314 /*************************************
1316 *************************************/
1318 static struct file_list {
1319 struct file_list *prev, *next;
1324 /****************************************************************************
1325 Free a file_list structure
1326 ****************************************************************************/
1328 static void free_file_list (struct file_list * list)
1330 struct file_list *tmp;
1335 DLIST_REMOVE(list, list);
1336 SAFE_FREE(tmp->file_path);
1341 /****************************************************************************
1342 seek in a directory/file list until you get something that doesn't start with
1344 ****************************************************************************/
1345 static BOOL seek_list(struct file_list *list, char *name)
1348 trim_string(list->file_path,"./","\n");
1349 if (strncmp(list->file_path, name, strlen(name)) != 0) {
1358 /****************************************************************************
1359 set the file selection mask
1360 ****************************************************************************/
1361 static int cmd_select(const char **cmd_ptr)
1363 pstrcpy(fileselection,"");
1364 next_token(cmd_ptr,fileselection,NULL,sizeof(fileselection));
1369 /*******************************************************************
1370 A readdir wrapper which just returns the file name.
1371 ********************************************************************/
1372 static const char *readdirname(DIR *p)
1380 ptr = (struct dirent *)readdir(p);
1384 dname = ptr->d_name;
1391 #ifdef HAVE_BROKEN_READDIR
1392 /* using /usr/ucb/cc is BAD */
1398 int len = NAMLEN(ptr);
1399 memcpy(buf, dname, len);
1407 /****************************************************************************
1408 Recursive file matching function act as find
1409 match must be always set to True when calling this function
1410 ****************************************************************************/
1411 static int file_find(struct file_list **list, const char *directory,
1412 const char *expression, BOOL match)
1415 struct file_list *entry;
1416 struct stat statbuf;
1422 dir = opendir(directory);
1423 if (!dir) return -1;
1425 while ((dname = readdirname(dir))) {
1426 if (!strcmp("..", dname)) continue;
1427 if (!strcmp(".", dname)) continue;
1429 if (asprintf(&path, "%s/%s", directory, dname) <= 0) {
1434 if (!match || !gen_fnmatch(expression, dname)) {
1436 ret = stat(path, &statbuf);
1438 if (S_ISDIR(statbuf.st_mode)) {
1440 ret = file_find(list, path, expression, False);
1443 d_printf("file_find: cannot stat file %s\n", path);
1452 entry = (struct file_list *) malloc(sizeof (struct file_list));
1454 d_printf("Out of memory in file_find\n");
1458 entry->file_path = path;
1459 entry->isdir = isdir;
1460 DLIST_ADD(*list, entry);
1470 /****************************************************************************
1472 ****************************************************************************/
1473 static int cmd_mput(const char **cmd_ptr)
1478 while (next_token(cmd_ptr,p,NULL,sizeof(buf))) {
1480 struct file_list *temp_list;
1481 char *quest, *lname, *rname;
1485 ret = file_find(&file_list, ".", p, True);
1487 free_file_list(file_list);
1495 for (temp_list = file_list; temp_list;
1496 temp_list = temp_list->next) {
1499 if (asprintf(&lname, "%s/", temp_list->file_path) <= 0)
1501 trim_string(lname, "./", "/");
1503 /* check if it's a directory */
1504 if (temp_list->isdir) {
1505 /* if (!recurse) continue; */
1508 if (asprintf(&quest, "Put directory %s? ", lname) < 0) break;
1509 if (prompt && !yesno(quest)) { /* No */
1510 /* Skip the directory */
1511 lname[strlen(lname)-1] = '/';
1512 if (!seek_list(temp_list, lname))
1516 if(asprintf(&rname, "%s%s", cur_dir, lname) < 0) break;
1518 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, rname)) &&
1519 NT_STATUS_IS_ERR(do_mkdir(rname))) {
1520 DEBUG (0, ("Unable to make dir, skipping..."));
1521 /* Skip the directory */
1522 lname[strlen(lname)-1] = '/';
1523 if (!seek_list(temp_list, lname))
1530 if (asprintf(&quest,"Put file %s? ", lname) < 0) break;
1531 if (prompt && !yesno(quest)) /* No */
1536 if (asprintf(&rname, "%s%s", cur_dir, lname) < 0) break;
1541 do_put(rname, lname, False);
1543 free_file_list(file_list);
1553 /****************************************************************************
1555 ****************************************************************************/
1556 static int do_cancel(int job)
1558 d_printf("REWRITE: print job cancel not implemented\n");
1563 /****************************************************************************
1565 ****************************************************************************/
1566 static int cmd_cancel(const char **cmd_ptr)
1571 if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
1572 d_printf("cancel <jobid> ...\n");
1578 } while (next_token(cmd_ptr,buf,NULL,sizeof(buf)));
1584 /****************************************************************************
1586 ****************************************************************************/
1587 static int cmd_print(const char **cmd_ptr)
1593 if (!next_token(cmd_ptr,lname,NULL, sizeof(lname))) {
1594 d_printf("print <filename>\n");
1598 pstrcpy(rname,lname);
1599 p = strrchr_m(rname,'/');
1601 slprintf(rname, sizeof(rname)-1, "%s-%d", p+1, (int)getpid());
1604 if (strequal(lname,"-")) {
1605 slprintf(rname, sizeof(rname)-1, "stdin-%d", (int)getpid());
1608 return do_put(rname, lname, False);
1612 /****************************************************************************
1614 ****************************************************************************/
1615 static int cmd_queue(const char **cmd_ptr)
1617 d_printf("REWRITE: print job queue not implemented\n");
1622 /****************************************************************************
1624 ****************************************************************************/
1625 static int cmd_del(const char **cmd_ptr)
1629 uint16_t attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
1632 attribute |= FILE_ATTRIBUTE_DIRECTORY;
1634 pstrcpy(mask,cur_dir);
1636 if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
1637 d_printf("del <filename>\n");
1642 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, mask))) {
1643 d_printf("%s deleting remote file %s\n",smbcli_errstr(cli->tree),mask);
1650 /****************************************************************************
1651 delete a whole directory tree
1652 ****************************************************************************/
1653 static int cmd_deltree(const char **cmd_ptr)
1659 pstrcpy(dname,cur_dir);
1661 if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
1662 d_printf("deltree <dirname>\n");
1667 ret = smbcli_deltree(cli->tree, dname);
1670 printf("Failed to delete tree %s - %s\n", dname, smbcli_errstr(cli->tree));
1674 printf("Deleted %d files in %s\n", ret, dname);
1680 /****************************************************************************
1681 show as much information as possible about a file
1682 ****************************************************************************/
1683 static int cmd_allinfo(const char **cmd_ptr)
1688 TALLOC_CTX *mem_ctx;
1689 union smb_fileinfo finfo;
1692 pstrcpy(fname,cur_dir);
1694 if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
1695 d_printf("allinfo <filename>\n");
1700 mem_ctx = talloc_init("%s", fname);
1702 /* first a ALL_INFO QPATHINFO */
1703 finfo.generic.level = RAW_FILEINFO_ALL_INFO;
1704 finfo.generic.in.fname = fname;
1705 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
1706 if (!NT_STATUS_IS_OK(status)) {
1707 d_printf("%s - %s\n", fname, nt_errstr(status));
1712 d_printf("\tcreate_time: %s\n", nt_time_string(mem_ctx, finfo.all_info.out.create_time));
1713 d_printf("\taccess_time: %s\n", nt_time_string(mem_ctx, finfo.all_info.out.access_time));
1714 d_printf("\twrite_time: %s\n", nt_time_string(mem_ctx, finfo.all_info.out.write_time));
1715 d_printf("\tchange_time: %s\n", nt_time_string(mem_ctx, finfo.all_info.out.change_time));
1716 d_printf("\tattrib: 0x%x\n", finfo.all_info.out.attrib);
1717 d_printf("\talloc_size: %lu\n", (unsigned long)finfo.all_info.out.alloc_size);
1718 d_printf("\tsize: %lu\n", (unsigned long)finfo.all_info.out.size);
1719 d_printf("\tnlink: %u\n", finfo.all_info.out.nlink);
1720 d_printf("\tdelete_pending: %u\n", finfo.all_info.out.delete_pending);
1721 d_printf("\tdirectory: %u\n", finfo.all_info.out.directory);
1722 d_printf("\tea_size: %u\n", finfo.all_info.out.ea_size);
1723 d_printf("\tfname: '%s'\n", finfo.all_info.out.fname.s);
1725 /* 8.3 name if any */
1726 finfo.generic.level = RAW_FILEINFO_ALT_NAME_INFO;
1727 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
1728 if (NT_STATUS_IS_OK(status)) {
1729 d_printf("\talt_name: %s\n", finfo.alt_name_info.out.fname.s);
1732 /* file_id if available */
1733 finfo.generic.level = RAW_FILEINFO_INTERNAL_INFORMATION;
1734 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
1735 if (NT_STATUS_IS_OK(status)) {
1736 d_printf("\tfile_id %.0f\n",
1737 (double)finfo.internal_information.out.file_id);
1740 /* the EAs, if any */
1741 finfo.generic.level = RAW_FILEINFO_ALL_EAS;
1742 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
1743 if (NT_STATUS_IS_OK(status)) {
1745 for (i=0;i<finfo.all_eas.out.num_eas;i++) {
1746 d_printf("\tEA[%d] flags=%d %s=%*.*s\n", i,
1747 finfo.all_eas.out.eas[i].flags,
1748 finfo.all_eas.out.eas[i].name.s,
1749 finfo.all_eas.out.eas[i].value.length,
1750 finfo.all_eas.out.eas[i].value.length,
1751 finfo.all_eas.out.eas[i].value.data);
1755 /* streams, if available */
1756 finfo.generic.level = RAW_FILEINFO_STREAM_INFO;
1757 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
1758 if (NT_STATUS_IS_OK(status)) {
1760 for (i=0;i<finfo.stream_info.out.num_streams;i++) {
1761 d_printf("\tstream %d:\n", i);
1762 d_printf("\t\tsize %ld\n",
1763 (long)finfo.stream_info.out.streams[i].size);
1764 d_printf("\t\talloc size %ld\n",
1765 (long)finfo.stream_info.out.streams[i].alloc_size);
1766 d_printf("\t\tname %s\n", finfo.stream_info.out.streams[i].stream_name.s);
1770 /* dev/inode if available */
1771 finfo.generic.level = RAW_FILEINFO_COMPRESSION_INFORMATION;
1772 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
1773 if (NT_STATUS_IS_OK(status)) {
1774 d_printf("\tcompressed size %ld\n", (long)finfo.compression_info.out.compressed_size);
1775 d_printf("\tformat %ld\n", (long)finfo.compression_info.out.format);
1776 d_printf("\tunit_shift %ld\n", (long)finfo.compression_info.out.unit_shift);
1777 d_printf("\tchunk_shift %ld\n", (long)finfo.compression_info.out.chunk_shift);
1778 d_printf("\tcluster_shift %ld\n", (long)finfo.compression_info.out.cluster_shift);
1781 talloc_destroy(mem_ctx);
1788 /****************************************************************************
1789 show any ACL on a file
1790 ****************************************************************************/
1791 static int cmd_acl(const char **cmd_ptr)
1796 TALLOC_CTX *mem_ctx;
1797 union smb_fileinfo query;
1801 pstrcpy(fname,cur_dir);
1803 if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
1804 d_printf("acl <filename>\n");
1809 fnum = smbcli_open(cli->tree, fname, O_RDONLY, DENY_NONE);
1811 d_printf("%s - %s\n", fname, smbcli_errstr(cli->tree));
1815 mem_ctx = talloc_init("%s", fname);
1817 query.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
1818 query.query_secdesc.in.fnum = fnum;
1819 query.query_secdesc.in.secinfo_flags = 0x7;
1821 status = smb_raw_fileinfo(cli->tree, mem_ctx, &query);
1822 if (!NT_STATUS_IS_OK(status)) {
1823 d_printf("%s - %s\n", fname, nt_errstr(status));
1828 NDR_PRINT_DEBUG(security_descriptor, query.query_secdesc.out.sd);
1830 talloc_destroy(mem_ctx);
1837 /****************************************************************************
1838 ****************************************************************************/
1839 static int cmd_open(const char **cmd_ptr)
1844 pstrcpy(mask,cur_dir);
1846 if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
1847 d_printf("open <filename>\n");
1852 smbcli_open(cli->tree, mask, O_RDWR, DENY_ALL);
1858 /****************************************************************************
1860 ****************************************************************************/
1861 static int cmd_rmdir(const char **cmd_ptr)
1866 pstrcpy(mask,cur_dir);
1868 if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
1869 d_printf("rmdir <dirname>\n");
1874 if (NT_STATUS_IS_ERR(smbcli_rmdir(cli->tree, mask))) {
1875 d_printf("%s removing remote directory file %s\n",
1876 smbcli_errstr(cli->tree),mask);
1882 /****************************************************************************
1884 ****************************************************************************/
1885 static int cmd_link(const char **cmd_ptr)
1890 if (!(cli->transport->negotiate.capabilities & CAP_UNIX)) {
1891 d_printf("Server doesn't support UNIX CIFS calls.\n");
1895 pstrcpy(src,cur_dir);
1896 pstrcpy(dest,cur_dir);
1898 if (!next_token(cmd_ptr,buf,NULL,sizeof(buf)) ||
1899 !next_token(cmd_ptr,buf2,NULL, sizeof(buf2))) {
1900 d_printf("link <src> <dest>\n");
1907 if (NT_STATUS_IS_ERR(smbcli_unix_hardlink(cli->tree, src, dest))) {
1908 d_printf("%s linking files (%s -> %s)\n", smbcli_errstr(cli->tree), src, dest);
1915 /****************************************************************************
1917 ****************************************************************************/
1919 static int cmd_symlink(const char **cmd_ptr)
1924 if (!(cli->transport->negotiate.capabilities & CAP_UNIX)) {
1925 d_printf("Server doesn't support UNIX CIFS calls.\n");
1929 pstrcpy(src,cur_dir);
1930 pstrcpy(dest,cur_dir);
1932 if (!next_token(cmd_ptr,buf,NULL,sizeof(buf)) ||
1933 !next_token(cmd_ptr,buf2,NULL, sizeof(buf2))) {
1934 d_printf("symlink <src> <dest>\n");
1941 if (NT_STATUS_IS_ERR(smbcli_unix_symlink(cli->tree, src, dest))) {
1942 d_printf("%s symlinking files (%s -> %s)\n",
1943 smbcli_errstr(cli->tree), src, dest);
1950 /****************************************************************************
1952 ****************************************************************************/
1954 static int cmd_chmod(const char **cmd_ptr)
1960 if (!(cli->transport->negotiate.capabilities & CAP_UNIX)) {
1961 d_printf("Server doesn't support UNIX CIFS calls.\n");
1965 pstrcpy(src,cur_dir);
1967 if (!next_token(cmd_ptr,buf,NULL,sizeof(buf)) ||
1968 !next_token(cmd_ptr,buf2,NULL, sizeof(buf2))) {
1969 d_printf("chmod mode file\n");
1973 mode = (mode_t)strtol(buf, NULL, 8);
1976 if (NT_STATUS_IS_ERR(smbcli_unix_chmod(cli->tree, src, mode))) {
1977 d_printf("%s chmod file %s 0%o\n",
1978 smbcli_errstr(cli->tree), src, (uint_t)mode);
1985 /****************************************************************************
1987 ****************************************************************************/
1989 static int cmd_chown(const char **cmd_ptr)
1994 fstring buf, buf2, buf3;
1996 if (!(cli->transport->negotiate.capabilities & CAP_UNIX)) {
1997 d_printf("Server doesn't support UNIX CIFS calls.\n");
2001 pstrcpy(src,cur_dir);
2003 if (!next_token(cmd_ptr,buf,NULL,sizeof(buf)) ||
2004 !next_token(cmd_ptr,buf2,NULL, sizeof(buf2)) ||
2005 !next_token(cmd_ptr,buf3,NULL, sizeof(buf3))) {
2006 d_printf("chown uid gid file\n");
2010 uid = (uid_t)atoi(buf);
2011 gid = (gid_t)atoi(buf2);
2014 if (NT_STATUS_IS_ERR(smbcli_unix_chown(cli->tree, src, uid, gid))) {
2015 d_printf("%s chown file %s uid=%d, gid=%d\n",
2016 smbcli_errstr(cli->tree), src, (int)uid, (int)gid);
2023 /****************************************************************************
2025 ****************************************************************************/
2026 static int cmd_rename(const char **cmd_ptr)
2031 pstrcpy(src,cur_dir);
2032 pstrcpy(dest,cur_dir);
2034 if (!next_token(cmd_ptr,buf,NULL,sizeof(buf)) ||
2035 !next_token(cmd_ptr,buf2,NULL, sizeof(buf2))) {
2036 d_printf("rename <src> <dest>\n");
2043 if (NT_STATUS_IS_ERR(smbcli_rename(cli->tree, src, dest))) {
2044 d_printf("%s renaming files\n",smbcli_errstr(cli->tree));
2052 /****************************************************************************
2053 toggle the prompt flag
2054 ****************************************************************************/
2055 static int cmd_prompt(const char **cmd_ptr)
2058 DEBUG(2,("prompting is now %s\n",prompt?"on":"off"));
2064 /****************************************************************************
2065 set the newer than time
2066 ****************************************************************************/
2067 static int cmd_newer(const char **cmd_ptr)
2073 ok = next_token(cmd_ptr,buf,NULL,sizeof(buf));
2074 if (ok && (stat(buf,&sbuf) == 0)) {
2075 newer_than = sbuf.st_mtime;
2076 DEBUG(1,("Getting files newer than %s",
2077 asctime(localtime(&newer_than))));
2082 if (ok && newer_than == 0) {
2083 d_printf("Error setting newer-than time\n");
2090 /****************************************************************************
2091 set the archive level
2092 ****************************************************************************/
2093 static int cmd_archive(const char **cmd_ptr)
2097 if (next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
2098 archive_level = atoi(buf);
2100 d_printf("Archive level is %d\n",archive_level);
2105 /****************************************************************************
2106 toggle the lowercaseflag
2107 ****************************************************************************/
2108 static int cmd_lowercase(const char **cmd_ptr)
2110 lowercase = !lowercase;
2111 DEBUG(2,("filename lowercasing is now %s\n",lowercase?"on":"off"));
2119 /****************************************************************************
2120 toggle the recurse flag
2121 ****************************************************************************/
2122 static int cmd_recurse(const char **cmd_ptr)
2125 DEBUG(2,("directory recursion is now %s\n",recurse?"on":"off"));
2130 /****************************************************************************
2131 toggle the translate flag
2132 ****************************************************************************/
2133 static int cmd_translate(const char **cmd_ptr)
2135 translation = !translation;
2136 DEBUG(2,("CR/LF<->LF and print text translation now %s\n",
2137 translation?"on":"off"));
2143 /****************************************************************************
2144 do a printmode command
2145 ****************************************************************************/
2146 static int cmd_printmode(const char **cmd_ptr)
2151 if (next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
2152 if (strequal(buf,"text")) {
2155 if (strequal(buf,"graphics"))
2158 printmode = atoi(buf);
2165 fstrcpy(mode,"text");
2168 fstrcpy(mode,"graphics");
2171 slprintf(mode,sizeof(mode)-1,"%d",printmode);
2175 DEBUG(2,("the printmode is now %s\n",mode));
2180 /****************************************************************************
2182 ****************************************************************************/
2183 static int cmd_lcd(const char **cmd_ptr)
2188 if (next_token(cmd_ptr,buf,NULL,sizeof(buf)))
2190 DEBUG(2,("the local directory is now %s\n",sys_getwd(d)));
2195 /****************************************************************************
2196 get a file restarting at end of local file
2197 ****************************************************************************/
2198 static int cmd_reget(const char **cmd_ptr)
2201 pstring remote_name;
2204 pstrcpy(remote_name, cur_dir);
2205 pstrcat(remote_name, "\\");
2207 p = remote_name + strlen(remote_name);
2209 if (!next_token(cmd_ptr, p, NULL, sizeof(remote_name) - strlen(remote_name))) {
2210 d_printf("reget <filename>\n");
2213 pstrcpy(local_name, p);
2214 dos_clean_name(remote_name);
2216 next_token(cmd_ptr, local_name, NULL, sizeof(local_name));
2218 return do_get(remote_name, local_name, True);
2221 /****************************************************************************
2222 put a file restarting at end of local file
2223 ****************************************************************************/
2224 static int cmd_reput(const char **cmd_ptr)
2227 pstring remote_name;
2232 pstrcpy(remote_name, cur_dir);
2233 pstrcat(remote_name, "\\");
2235 if (!next_token(cmd_ptr, p, NULL, sizeof(buf))) {
2236 d_printf("reput <filename>\n");
2239 pstrcpy(local_name, p);
2241 if (!file_exist(local_name, &st)) {
2242 d_printf("%s does not exist\n", local_name);
2246 if (next_token(cmd_ptr, p, NULL, sizeof(buf)))
2247 pstrcat(remote_name, p);
2249 pstrcat(remote_name, local_name);
2251 dos_clean_name(remote_name);
2253 return do_put(remote_name, local_name, True);
2258 return a string representing a share type
2260 static const char *share_type_str(uint32_t type)
2262 switch (type & 0xF) {
2263 case STYPE_DISKTREE:
2278 display a list of shares from a level 1 share enum
2280 static void display_share_result(struct srvsvc_NetShareCtr1 *ctr1)
2284 for (i=0;i<ctr1->count;i++) {
2285 struct srvsvc_NetShareInfo1 *info = ctr1->array+i;
2287 printf("\t%-15s %-10.10s %s\n",
2289 share_type_str(info->type),
2296 /****************************************************************************
2297 try and browse available shares on a host
2298 ****************************************************************************/
2299 static BOOL browse_host(const char *query_host)
2301 struct dcerpc_pipe *p;
2304 struct srvsvc_NetShareEnumAll r;
2305 uint32_t resume_handle = 0;
2306 TALLOC_CTX *mem_ctx = talloc_init("browse_host");
2307 struct srvsvc_NetShareCtr1 ctr1;
2309 binding = talloc_asprintf(mem_ctx, "ncacn_np:%s", query_host);
2311 status = dcerpc_pipe_connect(&p, binding,
2313 DCERPC_SRVSVC_VERSION,
2315 username, password);
2316 if (!NT_STATUS_IS_OK(status)) {
2317 d_printf("Failed to connect to %s - %s\n",
2318 binding, nt_errstr(status));
2319 talloc_destroy(mem_ctx);
2322 talloc_steal(mem_ctx, p);
2324 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
2326 r.in.ctr.ctr1 = &ctr1;
2327 r.in.max_buffer = ~0;
2328 r.in.resume_handle = &resume_handle;
2330 d_printf("\n\tSharename Type Comment\n");
2331 d_printf("\t--------- ---- -------\n");
2335 status = dcerpc_srvsvc_NetShareEnumAll(p, mem_ctx, &r);
2337 if (NT_STATUS_IS_OK(status) &&
2338 (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA) ||
2339 W_ERROR_IS_OK(r.out.result)) &&
2341 display_share_result(r.out.ctr.ctr1);
2342 resume_handle += r.out.ctr.ctr1->count;
2344 } while (NT_STATUS_IS_OK(status) && W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA));
2346 talloc_destroy(mem_ctx);
2348 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2349 d_printf("Failed NetShareEnumAll %s - %s/%s\n",
2350 binding, nt_errstr(status), win_errstr(r.out.result));
2357 /****************************************************************************
2358 try and browse available connections on a host
2359 ****************************************************************************/
2360 static BOOL list_servers(const char *wk_grp)
2362 d_printf("REWRITE: list servers not implemented\n");
2366 /* Some constants for completing filename arguments */
2368 #define COMPL_NONE 0 /* No completions */
2369 #define COMPL_REMOTE 1 /* Complete remote filename */
2370 #define COMPL_LOCAL 2 /* Complete local filename */
2372 /* This defines the commands supported by this client.
2373 * NOTE: The "!" must be the last one in the list because it's fn pointer
2374 * field is NULL, and NULL in that field is used in process_tok()
2375 * (below) to indicate the end of the list. crh
2380 int (*fn)(const char **cmd_ptr);
2381 const char *description;
2382 char compl_args[2]; /* Completion argument info */
2385 {"?",cmd_help,"[command] give help on a command",{COMPL_NONE,COMPL_NONE}},
2386 {"altname",cmd_altname,"<file> show alt name",{COMPL_NONE,COMPL_NONE}},
2387 {"acl",cmd_acl,"<file> show file ACL",{COMPL_NONE,COMPL_NONE}},
2388 {"allinfo",cmd_allinfo,"<file> show all possible info about a file",{COMPL_NONE,COMPL_NONE}},
2389 {"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}},
2390 {"cancel",cmd_cancel,"<jobid> cancel a print queue entry",{COMPL_NONE,COMPL_NONE}},
2391 {"cd",cmd_cd,"[directory] change/report the remote directory",{COMPL_REMOTE,COMPL_NONE}},
2392 {"chmod",cmd_chmod,"<src> <mode> chmod a file using UNIX permission",{COMPL_REMOTE,COMPL_REMOTE}},
2393 {"chown",cmd_chown,"<src> <uid> <gid> chown a file using UNIX uids and gids",{COMPL_REMOTE,COMPL_REMOTE}},
2394 {"del",cmd_del,"<mask> delete all matching files",{COMPL_REMOTE,COMPL_NONE}},
2395 {"deltree",cmd_deltree,"<dir> delete a whole directory tree",{COMPL_REMOTE,COMPL_NONE}},
2396 {"dir",cmd_dir,"<mask> list the contents of the current directory",{COMPL_REMOTE,COMPL_NONE}},
2397 {"du",cmd_du,"<mask> computes the total size of the current directory",{COMPL_REMOTE,COMPL_NONE}},
2398 {"exit",cmd_quit,"logoff the server",{COMPL_NONE,COMPL_NONE}},
2399 {"get",cmd_get,"<remote name> [local name] get a file",{COMPL_REMOTE,COMPL_LOCAL}},
2400 {"help",cmd_help,"[command] give help on a command",{COMPL_NONE,COMPL_NONE}},
2401 {"history",cmd_history,"displays the command history",{COMPL_NONE,COMPL_NONE}},
2402 {"lcd",cmd_lcd,"[directory] change/report the local current working directory",{COMPL_LOCAL,COMPL_NONE}},
2403 {"link",cmd_link,"<src> <dest> create a UNIX hard link",{COMPL_REMOTE,COMPL_REMOTE}},
2404 {"lowercase",cmd_lowercase,"toggle lowercasing of filenames for get",{COMPL_NONE,COMPL_NONE}},
2405 {"ls",cmd_dir,"<mask> list the contents of the current directory",{COMPL_REMOTE,COMPL_NONE}},
2406 {"mask",cmd_select,"<mask> mask all filenames against this",{COMPL_REMOTE,COMPL_NONE}},
2407 {"md",cmd_mkdir,"<directory> make a directory",{COMPL_NONE,COMPL_NONE}},
2408 {"mget",cmd_mget,"<mask> get all the matching files",{COMPL_REMOTE,COMPL_NONE}},
2409 {"mkdir",cmd_mkdir,"<directory> make a directory",{COMPL_NONE,COMPL_NONE}},
2410 {"more",cmd_more,"<remote name> view a remote file with your pager",{COMPL_REMOTE,COMPL_NONE}},
2411 {"mput",cmd_mput,"<mask> put all matching files",{COMPL_REMOTE,COMPL_NONE}},
2412 {"newer",cmd_newer,"<file> only mget files newer than the specified local file",{COMPL_LOCAL,COMPL_NONE}},
2413 {"open",cmd_open,"<mask> open a file",{COMPL_REMOTE,COMPL_NONE}},
2414 {"print",cmd_print,"<file name> print a file",{COMPL_NONE,COMPL_NONE}},
2415 {"printmode",cmd_printmode,"<graphics or text> set the print mode",{COMPL_NONE,COMPL_NONE}},
2416 {"prompt",cmd_prompt,"toggle prompting for filenames for mget and mput",{COMPL_NONE,COMPL_NONE}},
2417 {"put",cmd_put,"<local name> [remote name] put a file",{COMPL_LOCAL,COMPL_REMOTE}},
2418 {"pwd",cmd_pwd,"show current remote directory (same as 'cd' with no args)",{COMPL_NONE,COMPL_NONE}},
2419 {"q",cmd_quit,"logoff the server",{COMPL_NONE,COMPL_NONE}},
2420 {"queue",cmd_queue,"show the print queue",{COMPL_NONE,COMPL_NONE}},
2421 {"quit",cmd_quit,"logoff the server",{COMPL_NONE,COMPL_NONE}},
2422 {"rd",cmd_rmdir,"<directory> remove a directory",{COMPL_NONE,COMPL_NONE}},
2423 {"recurse",cmd_recurse,"toggle directory recursion for mget and mput",{COMPL_NONE,COMPL_NONE}},
2424 {"reget",cmd_reget,"<remote name> [local name] get a file restarting at end of local file",{COMPL_REMOTE,COMPL_LOCAL}},
2425 {"rename",cmd_rename,"<src> <dest> rename some files",{COMPL_REMOTE,COMPL_REMOTE}},
2426 {"reput",cmd_reput,"<local name> [remote name] put a file restarting at end of remote file",{COMPL_LOCAL,COMPL_REMOTE}},
2427 {"rm",cmd_del,"<mask> delete all matching files",{COMPL_REMOTE,COMPL_NONE}},
2428 {"rmdir",cmd_rmdir,"<directory> remove a directory",{COMPL_NONE,COMPL_NONE}},
2429 {"symlink",cmd_symlink,"<src> <dest> create a UNIX symlink",{COMPL_REMOTE,COMPL_REMOTE}},
2430 {"translate",cmd_translate,"toggle text translation for printing",{COMPL_NONE,COMPL_NONE}},
2432 /* Yes, this must be here, see crh's comment above. */
2433 {"!",NULL,"run a shell command on the local system",{COMPL_NONE,COMPL_NONE}},
2434 {NULL,NULL,NULL,{COMPL_NONE,COMPL_NONE}}
2438 /*******************************************************************
2439 lookup a command string in the list of commands, including
2441 ******************************************************************/
2442 static int process_tok(fstring tok)
2444 int i = 0, matches = 0;
2446 int tok_len = strlen(tok);
2448 while (commands[i].fn != NULL) {
2449 if (strequal(commands[i].name,tok)) {
2453 } else if (strncasecmp(commands[i].name, tok, tok_len) == 0) {
2462 else if (matches == 1)
2468 /****************************************************************************
2470 ****************************************************************************/
2471 static int cmd_help(const char **cmd_ptr)
2476 if (next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
2477 if ((i = process_tok(buf)) >= 0)
2478 d_printf("HELP %s:\n\t%s\n\n",commands[i].name,commands[i].description);
2480 while (commands[i].description) {
2481 for (j=0; commands[i].description && (j<5); j++) {
2482 d_printf("%-15s",commands[i].name);
2491 /****************************************************************************
2492 process a -c command string
2493 ****************************************************************************/
2494 static int process_command_string(char *cmd)
2500 /* establish the connection if not already */
2503 cli = do_connect(desthost, service);
2508 while (cmd[0] != '\0') {
2513 if ((p = strchr_m(cmd, ';')) == 0) {
2514 strncpy(line, cmd, 999);
2518 if (p - cmd > 999) p = cmd + 999;
2519 strncpy(line, cmd, p - cmd);
2520 line[p - cmd] = '\0';
2524 /* and get the first part of the command */
2526 if (!next_token(&ptr,tok,NULL,sizeof(tok))) continue;
2528 if ((i = process_tok(tok)) >= 0) {
2529 rc = commands[i].fn(&ptr);
2530 } else if (i == -2) {
2531 d_printf("%s: command abbreviation ambiguous\n",tok);
2533 d_printf("%s: command not found\n",tok);
2540 #define MAX_COMPLETIONS 100
2548 } completion_remote_t;
2550 static void completion_remote_filter(struct clilist_file_info *f, const char *mask, void *state)
2552 completion_remote_t *info = (completion_remote_t *)state;
2554 if ((info->count < MAX_COMPLETIONS - 1) && (strncmp(info->text, f->name, info->len) == 0) && (strcmp(f->name, ".") != 0) && (strcmp(f->name, "..") != 0)) {
2555 if ((info->dirmask[0] == 0) && !(f->attrib & FILE_ATTRIBUTE_DIRECTORY))
2556 info->matches[info->count] = strdup(f->name);
2560 if (info->dirmask[0] != 0)
2561 pstrcpy(tmp, info->dirmask);
2564 pstrcat(tmp, f->name);
2565 if (f->attrib & FILE_ATTRIBUTE_DIRECTORY)
2567 info->matches[info->count] = strdup(tmp);
2569 if (info->matches[info->count] == NULL)
2571 if (f->attrib & FILE_ATTRIBUTE_DIRECTORY)
2572 smb_readline_ca_char(0);
2574 if (info->count == 1)
2575 info->samelen = strlen(info->matches[info->count]);
2577 while (strncmp(info->matches[info->count], info->matches[info->count-1], info->samelen) != 0)
2583 static char **remote_completion(const char *text, int len)
2587 completion_remote_t info = { "", NULL, 1, 0, NULL, 0 };
2593 if (len >= PATH_MAX)
2596 info.matches = (char **)malloc(sizeof(info.matches[0])*MAX_COMPLETIONS);
2597 if (!info.matches) return NULL;
2598 info.matches[0] = NULL;
2600 for (i = len-1; i >= 0; i--)
2601 if ((text[i] == '/') || (text[i] == '\\'))
2603 info.text = text+i+1;
2604 info.samelen = info.len = len-i-1;
2607 strncpy(info.dirmask, text, i+1);
2608 info.dirmask[i+1] = 0;
2609 snprintf(dirmask, sizeof(dirmask), "%s%*s*", cur_dir, i-1, text);
2611 snprintf(dirmask, sizeof(dirmask), "%s*", cur_dir);
2613 if (smbcli_list(cli->tree, dirmask,
2614 FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN,
2615 completion_remote_filter, &info) < 0)
2618 if (info.count == 2)
2619 info.matches[0] = strdup(info.matches[1]);
2621 info.matches[0] = malloc(info.samelen+1);
2622 if (!info.matches[0])
2624 strncpy(info.matches[0], info.matches[1], info.samelen);
2625 info.matches[0][info.samelen] = 0;
2627 info.matches[info.count] = NULL;
2628 return info.matches;
2631 for (i = 0; i < info.count; i++)
2632 free(info.matches[i]);
2637 static char **completion_fn(const char *text, int start, int end)
2639 smb_readline_ca_char(' ');
2642 const char *buf, *sp;
2646 buf = smb_readline_get_line_buffer();
2650 sp = strchr(buf, ' ');
2654 for (i = 0; commands[i].name; i++)
2655 if ((strncmp(commands[i].name, text, sp - buf) == 0) && (commands[i].name[sp - buf] == 0))
2657 if (commands[i].name == NULL)
2663 if (sp == (buf + start))
2664 compl_type = commands[i].compl_args[0];
2666 compl_type = commands[i].compl_args[1];
2668 if (compl_type == COMPL_REMOTE)
2669 return remote_completion(text, end - start);
2670 else /* fall back to local filename completion */
2674 int i, len, samelen, count=1;
2676 matches = (char **)malloc(sizeof(matches[0])*MAX_COMPLETIONS);
2677 if (!matches) return NULL;
2681 for (i=0;commands[i].fn && count < MAX_COMPLETIONS-1;i++) {
2682 if (strncmp(text, commands[i].name, len) == 0) {
2683 matches[count] = strdup(commands[i].name);
2684 if (!matches[count])
2687 samelen = strlen(matches[count]);
2689 while (strncmp(matches[count], matches[count-1], samelen) != 0)
2696 case 0: /* should never happen */
2700 matches[0] = strdup(matches[1]);
2703 matches[0] = malloc(samelen+1);
2706 strncpy(matches[0], matches[1], samelen);
2707 matches[0][samelen] = 0;
2709 matches[count] = NULL;
2722 /****************************************************************************
2723 make sure we swallow keepalives during idle time
2724 ****************************************************************************/
2725 static void readline_callback(void)
2727 static time_t last_t;
2732 if (t - last_t < 5) return;
2736 smbcli_transport_process(cli->transport);
2739 smbcli_chkpath(cli->tree, "\\");
2744 /****************************************************************************
2745 process commands on stdin
2746 ****************************************************************************/
2747 static void process_stdin(void)
2757 /* display a prompt */
2758 slprintf(the_prompt, sizeof(the_prompt)-1, "smb: %s> ", cur_dir);
2759 cline = smb_readline(the_prompt, readline_callback, completion_fn);
2763 pstrcpy(line, cline);
2765 /* special case - first char is ! */
2771 /* and get the first part of the command */
2773 if (!next_token(&ptr,tok,NULL,sizeof(tok))) continue;
2775 if ((i = process_tok(tok)) >= 0) {
2776 commands[i].fn(&ptr);
2777 } else if (i == -2) {
2778 d_printf("%s: command abbreviation ambiguous\n",tok);
2780 d_printf("%s: command not found\n",tok);
2786 /*****************************************************
2787 return a connection to a server
2788 *******************************************************/
2789 static struct smbcli_state *do_connect(const char *server, const char *share)
2791 struct smbcli_state *c;
2792 struct nmb_name called, calling;
2793 const char *server_n;
2794 fstring servicename;
2798 /* make a copy so we don't modify the global string 'service' */
2799 fstrcpy(servicename, share);
2800 sharename = servicename;
2801 if (*sharename == '\\') {
2802 server = sharename+2;
2803 sharename = strchr_m(server,'\\');
2804 if (!sharename) return NULL;
2809 asprintf(&sharename, "\\\\%s\\%s", server, sharename);
2811 server_n = dest_ip?dest_ip:server;
2813 make_nmb_name(&calling, lp_netbios_name(), 0x0);
2814 choose_called_name(&called, server, name_type);
2817 /* have to open a new connection */
2818 if (!(c=smbcli_state_init(NULL)) || !smbcli_socket_connect(c, server_n)) {
2819 d_printf("Connection to %s failed\n", server_n);
2823 if (!smbcli_transport_establish(c, &calling, &called)) {
2825 d_printf("session request to %s failed\n",
2828 if ((p=strchr_m(called.name, '.'))) {
2832 if (strcmp(called.name, "*SMBSERVER")) {
2833 make_nmb_name(&called , "*SMBSERVER", 0x20);
2839 DEBUG(4,(" session request ok\n"));
2841 if (NT_STATUS_IS_ERR(smbcli_negprot(c))) {
2842 d_printf("protocol negotiation failed\n");
2847 status = smbcli_session_setup(c, username, password, domain);
2848 if (NT_STATUS_IS_ERR(status)) {
2849 d_printf("authenticated session setup failed: %s\n", nt_errstr(status));
2850 /* if a password was not supplied then try again with a null username */
2851 if (password[0] || !username[0]) {
2852 status = smbcli_session_setup(c, "", "", lp_workgroup());
2854 if (NT_STATUS_IS_ERR(status)) {
2855 d_printf("session setup failed: %s\n", nt_errstr(status));
2859 d_printf("Anonymous login successful\n");
2862 DEBUG(4,(" session setup ok\n"));
2864 if (NT_STATUS_IS_ERR(smbcli_send_tconX(c, sharename, "?????", password))) {
2865 d_printf("tree connect failed: %s\n", smbcli_errstr(c->tree));
2870 DEBUG(4,(" tconx ok\n"));
2876 /****************************************************************************
2877 process commands from the client
2878 ****************************************************************************/
2879 static int process(char *base_directory)
2883 cli = do_connect(desthost, service);
2888 if (*base_directory) do_cd(base_directory);
2891 rc = process_command_string(cmdstr);
2896 smbcli_shutdown(cli);
2900 /****************************************************************************
2902 ****************************************************************************/
2903 static int do_host_query(char *query_host)
2905 browse_host(query_host);
2906 list_servers(lp_workgroup());
2911 /****************************************************************************
2912 handle a message operation
2913 ****************************************************************************/
2914 static int do_message_op(void)
2916 struct nmb_name called, calling;
2917 const char *server_name;
2919 make_nmb_name(&calling, lp_netbios_name(), 0x0);
2920 choose_called_name(&called, desthost, name_type);
2922 server_name = dest_ip ? dest_ip : desthost;
2924 if (!(cli=smbcli_state_init(NULL)) || !smbcli_socket_connect(cli, server_name)) {
2925 d_printf("Connection to %s failed\n", server_name);
2929 if (!smbcli_transport_establish(cli, &calling, &called)) {
2930 d_printf("session request failed\n");
2931 smbcli_shutdown(cli);
2936 smbcli_shutdown(cli);
2943 * Process "-L hostname" option.
2945 * We don't actually do anything yet -- we just stash the name in a
2946 * global variable and do the query when all options have been read.
2948 static void remember_query_host(const char *arg,
2953 while (*arg == '\\' || *arg == '/')
2955 pstrcpy(query_host, arg);
2956 if ((slash = strchr(query_host, '/'))
2957 || (slash = strchr(query_host, '\\'))) {
2963 /****************************************************************************
2965 ****************************************************************************/
2966 int main(int argc,char *argv[])
2968 fstring base_directory;
2971 BOOL message = False;
2976 TALLOC_CTX *mem_ctx;
2977 struct poptOption long_options[] = {
2980 { "message", 'M', POPT_ARG_STRING, NULL, 'M', "Send message", "HOST" },
2981 { "ip-address", 'I', POPT_ARG_STRING, NULL, 'I', "Use this IP to connect to", "IP" },
2982 { "stderr", 'E', POPT_ARG_NONE, NULL, 'E', "Write messages to stderr instead of stdout" },
2983 { "list", 'L', POPT_ARG_STRING, NULL, 'L', "Get a list of shares available on a host", "HOST" },
2984 { "terminal", 't', POPT_ARG_STRING, NULL, 't', "Terminal I/O code {sjis|euc|jis7|jis8|junet|hex}", "CODE" },
2985 { "directory", 'D', POPT_ARG_STRING, NULL, 'D', "Start from directory", "DIR" },
2986 { "command", 'c', POPT_ARG_STRING, &cmdstr, 'c', "Execute semicolon separated commands" },
2987 { "send-buffer", 'b', POPT_ARG_INT, NULL, 'b', "Changes the transmit/send buffer", "BYTES" },
2988 { "port", 'p', POPT_ARG_INT, &port, 'p', "Port to connect to", "PORT" },
2990 POPT_COMMON_CONNECTION
2991 POPT_COMMON_CREDENTIALS
2997 pstrcpy(term_code, KANJI);
3003 *base_directory = 0;
3005 setup_logging(argv[0],DEBUG_STDOUT);
3006 mem_ctx = talloc_init("client.c/main");
3008 d_printf("\nclient.c: Not enough memory\n");
3012 if (!lp_load(dyn_CONFIGFILE,True,False,False)) {
3013 fprintf(stderr, "%s: Can't load %s - run testparm to debug it\n",
3014 argv[0], dyn_CONFIGFILE);
3017 pc = poptGetContext("smbclient", argc, (const char **) argv, long_options, 0);
3018 poptSetOtherOptionHelp(pc, "[OPTIONS] service <password>");
3020 in_client = True; /* Make sure that we tell lp_load we are */
3022 while ((opt = poptGetNextOpt(pc)) != -1) {
3025 /* Messages are sent to NetBIOS name type 0x3
3026 * (Messenger Service). Make sure we default
3027 * to port 139 instead of port 445. srl,crh
3030 pstrcpy(desthost,poptGetOptArg(pc));
3031 if( 0 == port ) port = 139;
3035 dest_ip = poptGetOptArg(pc);
3038 setup_logging("client", DEBUG_STDERR);
3042 remember_query_host(poptGetOptArg(pc), query_host);
3045 pstrcpy(term_code, poptGetOptArg(pc));
3048 fstrcpy(base_directory,poptGetOptArg(pc));
3051 io_bufsize = MAX(1, atoi(poptGetOptArg(pc)));
3058 smbclient_init_subsystems;
3060 if(poptPeekArg(pc)) {
3061 pstrcpy(service,poptGetArg(pc));
3062 /* Convert any '/' characters in the service name to '\' characters */
3063 string_replace(service, '/','\\');
3065 if (count_chars(service,'\\') < 3) {
3066 d_printf("\n%s: Not enough '\\' characters in service\n",service);
3067 poptPrintUsage(pc, stderr, 0);
3072 if (poptPeekArg(pc)) {
3073 cmdline_set_userpassword(poptGetArg(pc));
3078 if (!*query_host && !*service && !message) {
3079 poptPrintUsage(pc, stderr, 0);
3083 poptFreeContext(pc);
3085 pstrcpy(username, cmdline_get_username());
3086 pstrcpy(domain, cmdline_get_userdomain());
3087 pstrcpy(password, cmdline_get_userpassword());
3089 DEBUG( 3, ( "Client started (version %s).\n", SAMBA_VERSION_STRING ) );
3091 talloc_destroy(mem_ctx);
3093 if ((p=strchr_m(query_host,'#'))) {
3096 sscanf(p, "%x", &name_type);
3100 return do_host_query(query_host);
3104 return do_message_op();
3107 if (process(base_directory)) {