2 Unix SMB/Netbios implementation.
5 Copyright (C) Andrew Tridgell 1994-1998
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 struct cli_state *cli;
31 extern BOOL in_client;
32 static int port = SMB_PORT;
33 pstring cur_dir = "\\";
35 static pstring service;
36 static pstring desthost;
37 extern pstring global_myname;
38 extern pstring myhostname;
39 static pstring password;
40 static pstring username;
41 static pstring workgroup;
44 extern struct in_addr ipzero;
47 static int name_type = 0x20;
49 extern pstring user_socket_options;
51 static int process_tok(fstring tok);
52 static void cmd_help(void);
54 /* 30 second timeout on most commands */
55 #define CLIENT_TIMEOUT (30*1000)
56 #define SHORT_TIMEOUT (5*1000)
58 /* value for unused fid field in trans2 secondary request */
59 #define FID_UNUSED (0xFFFF)
61 time_t newer_than = 0;
62 int archive_level = 0;
64 extern pstring debugf;
65 extern int DEBUGLEVEL;
67 BOOL translation = False;
71 /* clitar bits insert */
74 extern BOOL tar_reset;
78 mode_t myumask = 0755;
84 static BOOL recurse = False;
85 BOOL lowercase = False;
87 struct in_addr dest_ip;
89 #define SEPARATORS " \t\n\r"
91 BOOL abort_mget = True;
93 pstring fileselection = "";
95 extern file_info def_finfo;
98 int get_total_size = 0;
99 int get_total_time_ms = 0;
100 int put_total_size = 0;
101 int put_total_time_ms = 0;
104 static double dir_total;
108 #define CNV_LANG(s) dos_to_unix(s,False)
109 #define CNV_INPUT(s) unix_to_dos(s,True)
112 /****************************************************************************
113 write to a local file with CR/LF->LF translation if appropriate. return the
114 number taken from the buffer. This may not equal the number written.
115 ****************************************************************************/
116 static int writefile(int f, char *b, int n)
126 if (*b == '\r' && (i<(n-1)) && *(b+1) == '\n') {
129 if (write(f, b, 1) != 1) {
139 /****************************************************************************
140 read from a file with LF->CR/LF translation if appropriate. return the
141 number read. read approx n bytes.
142 ****************************************************************************/
143 static int readfile(char *b, int size, int n, FILE *f)
148 if (!translation || (size != 1))
149 return(fread(b,size,n,f));
153 if ((c = getc(f)) == EOF) {
157 if (c == '\n') { /* change all LFs to CR/LF */
170 /****************************************************************************
172 ****************************************************************************/
173 static void send_message(void)
178 if (!cli_message_start(cli, desthost, username, &grp_id)) {
179 DEBUG(0,("message start: %s\n", cli_errstr(cli)));
184 printf("Connected. Type your message, ending it with a Control-D\n");
186 while (!feof(stdin) && total_len < 1600) {
187 int maxlen = MIN(1600 - total_len,127);
194 for (l=0;l<maxlen && (c=fgetc(stdin))!=EOF;l++) {
200 if (!cli_message_text(cli, msg, l, grp_id)) {
201 printf("SMBsendtxt failed (%s)\n",cli_errstr(cli));
208 if (total_len >= 1600)
209 printf("the message was truncated to 1600 bytes\n");
211 printf("sent %d bytes\n",total_len);
213 if (!cli_message_end(cli, grp_id)) {
214 printf("SMBsendend failed (%s)\n",cli_errstr(cli));
221 /****************************************************************************
222 check the space on a device
223 ****************************************************************************/
224 static void do_dskattr(void)
226 int total, bsize, avail;
228 if (!cli_dskattr(cli, &bsize, &total, &avail)) {
229 DEBUG(0,("Error in dskattr: %s\n",cli_errstr(cli)));
233 DEBUG(0,("\n\t\t%d blocks of size %d. %d blocks available\n",
234 total, bsize, avail));
237 /****************************************************************************
239 ****************************************************************************/
240 static void cmd_pwd(void)
242 DEBUG(0,("Current directory is %s",CNV_LANG(service)));
243 DEBUG(0,("%s\n",CNV_LANG(cur_dir)));
247 /****************************************************************************
248 change directory - inner section
249 ****************************************************************************/
250 static void do_cd(char *newdir)
258 /* Save the current directory in case the
259 new directory is invalid */
260 pstrcpy(saved_dir, cur_dir);
265 if (*(cur_dir+strlen(cur_dir)-1) != '\\') {
266 pstrcat(cur_dir, "\\");
268 dos_clean_name(cur_dir);
269 pstrcpy(dname,cur_dir);
270 pstrcat(cur_dir,"\\");
271 dos_clean_name(cur_dir);
273 if (!strequal(cur_dir,"\\")) {
274 if (!cli_chkpath(cli, dname)) {
275 DEBUG(0,("cd %s: %s\n", dname, cli_errstr(cli)));
276 pstrcpy(cur_dir,saved_dir);
280 pstrcpy(cd_path,cur_dir);
283 /****************************************************************************
285 ****************************************************************************/
286 static void cmd_cd(void)
290 if (next_token(NULL,buf,NULL,sizeof(buf)))
293 DEBUG(0,("Current directory is %s\n",CNV_LANG(cur_dir)));
297 /*******************************************************************
298 decide if a file should be operated on
299 ********************************************************************/
300 static BOOL do_this_one(file_info *finfo)
302 if (finfo->mode & aDIR) return(True);
304 if (*fileselection &&
305 !mask_match(finfo->name,fileselection,False,False)) {
306 DEBUG(3,("match_match %s failed\n", finfo->name));
310 if (newer_than && finfo->mtime < newer_than) {
311 DEBUG(3,("newer_than %s failed\n", finfo->name));
315 if ((archive_level==1 || archive_level==2) && !(finfo->mode & aARCH)) {
316 DEBUG(3,("archive %s failed\n", finfo->name));
323 /****************************************************************************
324 display info about a file
325 ****************************************************************************/
326 static void display_finfo(file_info *finfo)
328 if (do_this_one(finfo)) {
329 time_t t = finfo->mtime; /* the time is assumed to be passed as GMT */
330 DEBUG(0,(" %-30s%7.7s%8.0f %s",
331 CNV_LANG(finfo->name),
332 attrib_string(finfo->mode),
334 asctime(LocalTime(&t))));
335 dir_total += finfo->size;
340 /****************************************************************************
341 accumulate size of a file
342 ****************************************************************************/
343 static void do_du(file_info *finfo)
345 if (do_this_one(finfo)) {
346 dir_total += finfo->size;
350 static BOOL do_list_recurse;
351 static BOOL do_list_dirs;
352 static int do_list_attr;
353 static void (*do_list_fn)(file_info *);
355 /****************************************************************************
357 ****************************************************************************/
358 static void do_list_helper(file_info *f, const char *mask)
360 if (f->mode & aDIR) {
361 if (do_list_dirs && do_this_one(f)) {
364 if (do_list_recurse &&
365 !strequal(f->name,".") &&
366 !strequal(f->name,"..")) {
370 pstrcpy(mask2, mask);
371 p = strrchr(mask2,'\\');
374 pstrcat(mask2, f->name);
375 if (do_list_fn == display_finfo) {
376 DEBUG(0,("\n%s\n",CNV_LANG(mask2)));
378 pstrcat(mask2,"\\*");
379 do_list(mask2, do_list_attr, do_list_fn, True, True);
384 if (do_this_one(f)) {
390 /****************************************************************************
391 a wrapper around cli_list that adds recursion
392 ****************************************************************************/
393 void do_list(const char *mask,uint16 attribute,void (*fn)(file_info *),BOOL rec, BOOL dirs)
395 do_list_recurse = rec;
398 do_list_attr = attribute;
400 cli_list(cli, mask, attribute, do_list_helper);
403 /****************************************************************************
404 get a directory listing
405 ****************************************************************************/
406 static void cmd_dir(void)
408 uint16 attribute = aDIR | aSYSTEM | aHIDDEN;
414 pstrcpy(mask,cur_dir);
415 if(mask[strlen(mask)-1]!='\\')
418 if (next_token(NULL,buf,NULL,sizeof(buf))) {
429 do_list(mask, attribute, display_finfo, recurse, True);
433 DEBUG(3, ("Total bytes listed: %.0f\n", dir_total));
437 /****************************************************************************
438 get a directory listing
439 ****************************************************************************/
440 static void cmd_du(void)
442 uint16 attribute = aDIR | aSYSTEM | aHIDDEN;
448 pstrcpy(mask,cur_dir);
449 if(mask[strlen(mask)-1]!='\\')
452 if (next_token(NULL,buf,NULL,sizeof(buf))) {
462 do_list(mask, attribute, do_du, recurse, True);
466 DEBUG(0, ("Total number of bytes: %.0f\n", dir_total));
470 /****************************************************************************
471 get a file from rname to lname
472 ****************************************************************************/
473 static void do_get(char *rname,char *lname)
476 BOOL newhandle = False;
478 struct timeval tp_start;
479 int read_size = 65520;
484 GetTimeOfDay(&tp_start);
490 fnum = cli_open(cli, rname, O_RDONLY, DENY_NONE);
493 DEBUG(0,("%s opening remote file %s\n",cli_errstr(cli),CNV_LANG(rname)));
497 if(!strcmp(lname,"-")) {
498 handle = fileno(stdout);
500 handle = sys_open(lname,O_WRONLY|O_CREAT|O_TRUNC,0644);
504 DEBUG(0,("Error opening local file %s\n",lname));
509 if (!cli_qfileinfo(cli, fnum,
510 &attr, &size, NULL, NULL, NULL, NULL, NULL) &&
511 !cli_getattrE(cli, fnum,
512 &attr, &size, NULL, NULL, NULL)) {
513 DEBUG(0,("getattrib: %s\n",cli_errstr(cli)));
517 DEBUG(2,("getting file %s of size %.0f as %s ",
518 lname, (double)size, lname));
520 data = (char *)malloc(read_size);
523 int n = cli_read(cli, fnum, data, nread, read_size);
527 if (writefile(handle,data, n) != n) {
528 DEBUG(0,("Error writing local file\n"));
535 if (!cli_close(cli, fnum)) {
536 DEBUG(0,("Error %s closing remote file\n",cli_errstr(cli)));
543 if (archive_level >= 2 && (attr & aARCH)) {
544 cli_setatr(cli, rname, attr & ~(uint16)aARCH, 0);
548 struct timeval tp_end;
551 GetTimeOfDay(&tp_end);
553 (tp_end.tv_sec - tp_start.tv_sec)*1000 +
554 (tp_end.tv_usec - tp_start.tv_usec)/1000;
555 get_total_time_ms += this_time;
556 get_total_size += nread;
558 DEBUG(2,("(%g kb/s) (average %g kb/s)\n",
559 nread / (1.024*this_time + 1.0e-4),
560 get_total_size / (1.024*get_total_time_ms)));
565 /****************************************************************************
567 ****************************************************************************/
568 static void cmd_get(void)
574 pstrcpy(rname,cur_dir);
577 p = rname + strlen(rname);
579 if (!next_token(NULL,p,NULL,sizeof(rname)-strlen(rname))) {
580 DEBUG(0,("get <filename>\n"));
584 dos_clean_name(rname);
586 next_token(NULL,lname,NULL,sizeof(lname));
588 do_get(rname, lname);
592 /****************************************************************************
593 do a mget operation on one file
594 ****************************************************************************/
595 static void do_mget(file_info *finfo)
599 pstring saved_curdir;
602 if (strequal(finfo->name,".") || strequal(finfo->name,".."))
606 DEBUG(0,("mget aborted\n"));
610 if (finfo->mode & aDIR)
611 slprintf(quest,sizeof(pstring)-1,
612 "Get directory %s? ",CNV_LANG(finfo->name));
614 slprintf(quest,sizeof(pstring)-1,
615 "Get file %s? ",CNV_LANG(finfo->name));
617 if (prompt && !yesno(quest)) return;
619 if (!(finfo->mode & aDIR)) {
620 pstrcpy(rname,cur_dir);
621 pstrcat(rname,finfo->name);
622 do_get(rname,finfo->name);
626 /* handle directories */
627 pstrcpy(saved_curdir,cur_dir);
629 pstrcat(cur_dir,finfo->name);
630 pstrcat(cur_dir,"\\");
632 unix_format(finfo->name);
634 strlower(finfo->name);
636 if (!dos_directory_exist(finfo->name,NULL) &&
637 dos_mkdir(finfo->name,0777) != 0) {
638 DEBUG(0,("failed to create directory %s\n",CNV_LANG(finfo->name)));
639 pstrcpy(cur_dir,saved_curdir);
643 if (dos_chdir(finfo->name) != 0) {
644 DEBUG(0,("failed to chdir to directory %s\n",CNV_LANG(finfo->name)));
645 pstrcpy(cur_dir,saved_curdir);
649 pstrcpy(mget_mask,cur_dir);
650 pstrcat(mget_mask,"*");
652 do_list(mget_mask, aSYSTEM | aHIDDEN | aDIR,do_mget,False, True);
654 pstrcpy(cur_dir,saved_curdir);
658 /****************************************************************************
659 view the file using the pager
660 ****************************************************************************/
661 static void cmd_more(void)
663 fstring rname,lname,tmpname,pager_cmd;
666 fstrcpy(rname,cur_dir);
670 "%s/smbmore.%d",tmpdir(),(int)getpid());
671 fstrcpy(lname,tmpname);
673 if (!next_token(NULL,rname+strlen(rname),NULL,sizeof(rname)-strlen(rname))) {
674 DEBUG(0,("more <filename>\n"));
677 dos_clean_name(rname);
681 pager=getenv("PAGER");
683 slprintf(pager_cmd,sizeof(pager_cmd)-1,
684 "%s %s",(pager? pager:PAGER), tmpname);
691 /****************************************************************************
693 ****************************************************************************/
694 static void cmd_mget(void)
696 uint16 attribute = aSYSTEM | aHIDDEN;
708 while (next_token(NULL,p,NULL,sizeof(buf))) {
709 pstrcpy(mget_mask,cur_dir);
710 if(mget_mask[strlen(mget_mask)-1]!='\\')
711 pstrcat(mget_mask,"\\");
714 pstrcpy(mget_mask,p);
716 pstrcat(mget_mask,p);
717 do_list(mget_mask, attribute,do_mget,False,True);
721 pstrcpy(mget_mask,cur_dir);
722 if(mget_mask[strlen(mget_mask)-1]!='\\')
723 pstrcat(mget_mask,"\\");
724 pstrcat(mget_mask,"*");
725 do_list(mget_mask, attribute,do_mget,False,True);
730 /****************************************************************************
731 make a directory of name "name"
732 ****************************************************************************/
733 static BOOL do_mkdir(char *name)
735 if (!cli_mkdir(cli, name)) {
736 DEBUG(0,("%s making remote directory %s\n",
737 cli_errstr(cli),CNV_LANG(name)));
745 /****************************************************************************
746 make a directory of name "name"
747 ****************************************************************************/
748 static void cmd_quit(void)
755 /****************************************************************************
757 ****************************************************************************/
758 static void cmd_mkdir(void)
764 pstrcpy(mask,cur_dir);
766 if (!next_token(NULL,p,NULL,sizeof(buf))) {
768 DEBUG(0,("mkdir <dirname>\n"));
779 trim_string(ddir,".",NULL);
780 p = strtok(ddir,"/\\");
783 if (!cli_chkpath(cli, ddir2)) {
787 p = strtok(NULL,"/\\");
795 /****************************************************************************
797 ****************************************************************************/
798 static void do_put(char *rname,char *lname)
806 struct timeval tp_start;
807 GetTimeOfDay(&tp_start);
809 fnum = cli_open(cli, rname, O_WRONLY|O_CREAT|O_TRUNC, DENY_NONE);
812 DEBUG(0,("%s opening remote file %s\n",cli_errstr(cli),CNV_LANG(rname)));
816 /* allow files to be piped into smbclient
818 if (!strcmp(lname, "-")) {
820 /* size of file is not known */
822 f = sys_fopen(lname,"r");
826 DEBUG(0,("Error opening local file %s\n",lname));
831 DEBUG(1,("putting file %s as %s ",lname,
834 buf = (char *)malloc(maxwrite);
839 if ((n = readfile(buf,1,n,f)) < 1) {
840 DEBUG(0,("Error reading local file\n"));
844 ret = cli_write(cli, fnum, 0, buf, nread, n);
847 DEBUG(0,("Error writing file: %s\n", cli_errstr(cli)));
854 if (!cli_close(cli, fnum)) {
855 DEBUG(0,("%s closing remote file %s\n",cli_errstr(cli),CNV_LANG(rname)));
866 struct timeval tp_end;
869 GetTimeOfDay(&tp_end);
871 (tp_end.tv_sec - tp_start.tv_sec)*1000 +
872 (tp_end.tv_usec - tp_start.tv_usec)/1000;
873 put_total_time_ms += this_time;
874 put_total_size += nread;
876 DEBUG(1,("(%g kb/s) (average %g kb/s)\n",
877 nread / (1.024*this_time + 1.0e-4),
878 put_total_size / (1.024*put_total_time_ms)));
889 /****************************************************************************
891 ****************************************************************************/
892 static void cmd_put(void)
899 pstrcpy(rname,cur_dir);
902 if (!next_token(NULL,p,NULL,sizeof(buf))) {
903 DEBUG(0,("put <filename>\n"));
908 if (next_token(NULL,p,NULL,sizeof(buf)))
911 pstrcat(rname,lname);
913 dos_clean_name(rname);
917 /* allow '-' to represent stdin
918 jdblair, 24.jun.98 */
919 if (!file_exist(lname,&st) &&
920 (strcmp(lname,"-"))) {
921 DEBUG(0,("%s does not exist\n",lname));
930 /****************************************************************************
931 seek in a directory/file list until you get something that doesn't start with
933 ****************************************************************************/
934 static BOOL seek_list(FILE *f,char *name)
938 if (fscanf(f,"%s",s) != 1) return(False);
939 trim_string(s,"./",NULL);
940 if (strncmp(s,name,strlen(name)) != 0) {
950 /****************************************************************************
951 set the file selection mask
952 ****************************************************************************/
953 static void cmd_select(void)
955 pstrcpy(fileselection,"");
956 next_token(NULL,fileselection,NULL,sizeof(fileselection));
960 /****************************************************************************
962 ****************************************************************************/
963 static void cmd_mput(void)
970 while (next_token(NULL,p,NULL,sizeof(buf))) {
976 slprintf(tmpname,sizeof(pstring)-1,
977 "%s/ls.smb.%d",tmpdir(),(int)getpid());
979 slprintf(cmd,sizeof(pstring)-1,
980 "find . -name \"%s\" -print > %s",p,tmpname);
982 slprintf(cmd,sizeof(pstring)-1,
983 "/bin/ls %s > %s",p,tmpname);
986 f = sys_fopen(tmpname,"r");
992 if (fscanf(f,"%s",lname) != 1) break;
993 trim_string(lname,"./",NULL);
997 /* check if it's a directory */
998 if (directory_exist(lname,&st)) {
999 if (!recurse) continue;
1000 slprintf(quest,sizeof(pstring)-1,
1001 "Put directory %s? ",lname);
1002 if (prompt && !yesno(quest)) {
1004 if (!seek_list(f,lname))
1009 pstrcpy(rname,cur_dir);
1010 pstrcat(rname,lname);
1011 if (!cli_chkpath(cli, rname) && !do_mkdir(rname)) {
1013 if (!seek_list(f,lname))
1019 slprintf(quest,sizeof(quest)-1,
1020 "Put file %s? ",lname);
1021 if (prompt && !yesno(quest)) continue;
1023 pstrcpy(rname,cur_dir);
1024 pstrcat(rname,lname);
1029 do_put(rname,lname);
1037 /****************************************************************************
1039 ****************************************************************************/
1040 static void do_cancel(int job)
1042 if (cli_printjob_del(cli, job)) {
1043 printf("Job %d cancelled\n",job);
1045 printf("Error calcelling job %d : %s\n",job,cli_errstr(cli));
1050 /****************************************************************************
1052 ****************************************************************************/
1053 static void cmd_cancel(void)
1058 if (!next_token(NULL,buf,NULL,sizeof(buf))) {
1059 printf("cancel <jobid> ...\n");
1065 } while (next_token(NULL,buf,NULL,sizeof(buf)));
1069 /****************************************************************************
1071 ****************************************************************************/
1072 static void cmd_print(void)
1078 if (!next_token(NULL,lname,NULL, sizeof(lname))) {
1079 DEBUG(0,("print <filename>\n"));
1083 pstrcpy(rname,lname);
1084 p = strrchr(rname,'/');
1086 slprintf(rname, sizeof(rname)-1, "%s-%d", p+1, (int)getpid());
1089 if (strequal(lname,"-")) {
1090 slprintf(rname, sizeof(rname)-1, "stdin-%d", (int)getpid());
1093 do_put(rname, lname);
1097 /****************************************************************************
1098 show a print queue entry
1099 ****************************************************************************/
1100 static void queue_fn(struct print_job_info *p)
1102 DEBUG(0,("%-6d %-9d %s\n", (int)p->id, (int)p->size, p->name));
1105 /****************************************************************************
1107 ****************************************************************************/
1108 static void cmd_queue(void)
1110 cli_print_queue(cli, queue_fn);
1113 /****************************************************************************
1115 ****************************************************************************/
1116 static void do_del(file_info *finfo)
1120 pstrcpy(mask,cur_dir);
1121 pstrcat(mask,finfo->name);
1123 if (finfo->mode & aDIR)
1126 if (!cli_unlink(cli, mask)) {
1127 DEBUG(0,("%s deleting remote file %s\n",cli_errstr(cli),CNV_LANG(mask)));
1131 /****************************************************************************
1133 ****************************************************************************/
1134 static void cmd_del(void)
1138 uint16 attribute = aSYSTEM | aHIDDEN;
1143 pstrcpy(mask,cur_dir);
1145 if (!next_token(NULL,buf,NULL,sizeof(buf))) {
1146 DEBUG(0,("del <filename>\n"));
1151 do_list(mask, attribute,do_del,False,False);
1155 /****************************************************************************
1157 ****************************************************************************/
1158 static void cmd_rmdir(void)
1163 pstrcpy(mask,cur_dir);
1165 if (!next_token(NULL,buf,NULL,sizeof(buf))) {
1166 DEBUG(0,("rmdir <dirname>\n"));
1171 if (!cli_rmdir(cli, mask)) {
1172 DEBUG(0,("%s removing remote directory file %s\n",
1173 cli_errstr(cli),CNV_LANG(mask)));
1177 /****************************************************************************
1179 ****************************************************************************/
1180 static void cmd_rename(void)
1185 pstrcpy(src,cur_dir);
1186 pstrcpy(dest,cur_dir);
1188 if (!next_token(NULL,buf,NULL,sizeof(buf)) ||
1189 !next_token(NULL,buf2,NULL, sizeof(buf2))) {
1190 DEBUG(0,("rename <src> <dest>\n"));
1197 if (!cli_rename(cli, src, dest)) {
1198 DEBUG(0,("%s renaming files\n",cli_errstr(cli)));
1204 /****************************************************************************
1205 toggle the prompt flag
1206 ****************************************************************************/
1207 static void cmd_prompt(void)
1210 DEBUG(2,("prompting is now %s\n",prompt?"on":"off"));
1214 /****************************************************************************
1215 set the newer than time
1216 ****************************************************************************/
1217 static void cmd_newer(void)
1221 SMB_STRUCT_STAT sbuf;
1223 ok = next_token(NULL,buf,NULL,sizeof(buf));
1224 if (ok && (dos_stat(buf,&sbuf) == 0)) {
1225 newer_than = sbuf.st_mtime;
1226 DEBUG(1,("Getting files newer than %s",
1227 asctime(LocalTime(&newer_than))));
1232 if (ok && newer_than == 0)
1233 DEBUG(0,("Error setting newer-than time\n"));
1236 /****************************************************************************
1237 set the archive level
1238 ****************************************************************************/
1239 static void cmd_archive(void)
1243 if (next_token(NULL,buf,NULL,sizeof(buf))) {
1244 archive_level = atoi(buf);
1246 DEBUG(0,("Archive level is %d\n",archive_level));
1249 /****************************************************************************
1250 toggle the lowercaseflag
1251 ****************************************************************************/
1252 static void cmd_lowercase(void)
1254 lowercase = !lowercase;
1255 DEBUG(2,("filename lowercasing is now %s\n",lowercase?"on":"off"));
1261 /****************************************************************************
1262 toggle the recurse flag
1263 ****************************************************************************/
1264 static void cmd_recurse(void)
1267 DEBUG(2,("directory recursion is now %s\n",recurse?"on":"off"));
1270 /****************************************************************************
1271 toggle the translate flag
1272 ****************************************************************************/
1273 static void cmd_translate(void)
1275 translation = !translation;
1276 DEBUG(2,("CR/LF<->LF and print text translation now %s\n",
1277 translation?"on":"off"));
1281 /****************************************************************************
1282 do a printmode command
1283 ****************************************************************************/
1284 static void cmd_printmode(void)
1289 if (next_token(NULL,buf,NULL,sizeof(buf))) {
1290 if (strequal(buf,"text")) {
1293 if (strequal(buf,"graphics"))
1296 printmode = atoi(buf);
1303 fstrcpy(mode,"text");
1306 fstrcpy(mode,"graphics");
1309 slprintf(mode,sizeof(mode)-1,"%d",printmode);
1313 DEBUG(2,("the printmode is now %s\n",mode));
1316 /****************************************************************************
1318 ****************************************************************************/
1319 static void cmd_lcd(void)
1324 if (next_token(NULL,buf,NULL,sizeof(buf)))
1326 DEBUG(2,("the local directory is now %s\n",sys_getwd(d)));
1329 /****************************************************************************
1331 ****************************************************************************/
1332 static void browse_fn(const char *name, uint32 m, const char *comment)
1339 case STYPE_DISKTREE:
1340 fstrcpy(typestr,"Disk"); break;
1342 fstrcpy(typestr,"Printer"); break;
1344 fstrcpy(typestr,"Device"); break;
1346 fstrcpy(typestr,"IPC"); break;
1349 printf("\t%-15.15s%-10.10s%s\n",
1350 name, typestr,comment);
1354 /****************************************************************************
1355 try and browse available connections on a host
1356 ****************************************************************************/
1357 static BOOL browse_host(BOOL sort)
1359 printf("\n\tSharename Type Comment\n");
1360 printf("\t--------- ---- -------\n");
1362 return cli_RNetShareEnum(cli, browse_fn);
1365 /****************************************************************************
1367 ****************************************************************************/
1368 static void server_fn(const char *name, uint32 m, const char *comment)
1370 printf("\t%-16.16s %s\n", name, comment);
1373 /****************************************************************************
1374 try and browse available connections on a host
1375 ****************************************************************************/
1376 static BOOL list_servers(char *wk_grp)
1378 printf("\n\tServer Comment\n");
1379 printf("\t--------- -------\n");
1381 cli_NetServerEnum(cli, workgroup, SV_TYPE_ALL, server_fn);
1383 printf("\n\tWorkgroup Master\n");
1384 printf("\t--------- -------\n");
1386 cli_NetServerEnum(cli, workgroup, SV_TYPE_DOMAIN_ENUM, server_fn);
1391 /* Some constants for completing filename arguments */
1393 #define COMPL_NONE 0 /* No completions */
1394 #define COMPL_REMOTE 1 /* Complete remote filename */
1395 #define COMPL_LOCAL 2 /* Complete local filename */
1397 /* This defines the commands supported by this client */
1403 char compl_args[2]; /* Completion argument info */
1406 {"ls",cmd_dir,"<mask> list the contents of the current directory",{COMPL_REMOTE,COMPL_NONE}},
1407 {"dir",cmd_dir,"<mask> list the contents of the current directory",{COMPL_REMOTE,COMPL_NONE}},
1408 {"du",cmd_du,"<mask> computes the total size of the current directory",{COMPL_REMOTE,COMPL_NONE}},
1409 {"lcd",cmd_lcd,"[directory] change/report the local current working directory",{COMPL_LOCAL,COMPL_NONE}},
1410 {"cd",cmd_cd,"[directory] change/report the remote directory",{COMPL_REMOTE,COMPL_NONE}},
1411 {"pwd",cmd_pwd,"show current remote directory (same as 'cd' with no args)",{COMPL_NONE,COMPL_NONE}},
1412 {"get",cmd_get,"<remote name> [local name] get a file",{COMPL_REMOTE,COMPL_LOCAL}},
1413 {"mget",cmd_mget,"<mask> get all the matching files",{COMPL_REMOTE,COMPL_NONE}},
1414 {"put",cmd_put,"<local name> [remote name] put a file",{COMPL_LOCAL,COMPL_REMOTE}},
1415 {"mput",cmd_mput,"<mask> put all matching files",{COMPL_REMOTE,COMPL_NONE}},
1416 {"rename",cmd_rename,"<src> <dest> rename some files",{COMPL_REMOTE,COMPL_REMOTE}},
1417 {"more",cmd_more,"<remote name> view a remote file with your pager",{COMPL_REMOTE,COMPL_NONE}},
1418 {"mask",cmd_select,"<mask> mask all filenames against this",{COMPL_REMOTE,COMPL_NONE}},
1419 {"del",cmd_del,"<mask> delete all matching files",{COMPL_REMOTE,COMPL_NONE}},
1420 {"rm",cmd_del,"<mask> delete all matching files",{COMPL_REMOTE,COMPL_NONE}},
1421 {"mkdir",cmd_mkdir,"<directory> make a directory",{COMPL_NONE,COMPL_NONE}},
1422 {"md",cmd_mkdir,"<directory> make a directory",{COMPL_NONE,COMPL_NONE}},
1423 {"rmdir",cmd_rmdir,"<directory> remove a directory",{COMPL_NONE,COMPL_NONE}},
1424 {"rd",cmd_rmdir,"<directory> remove a directory",{COMPL_NONE,COMPL_NONE}},
1425 {"prompt",cmd_prompt,"toggle prompting for filenames for mget and mput",{COMPL_NONE,COMPL_NONE}},
1426 {"recurse",cmd_recurse,"toggle directory recursion for mget and mput",{COMPL_NONE,COMPL_NONE}},
1427 {"translate",cmd_translate,"toggle text translation for printing",{COMPL_NONE,COMPL_NONE}},
1428 {"lowercase",cmd_lowercase,"toggle lowercasing of filenames for get",{COMPL_NONE,COMPL_NONE}},
1429 {"print",cmd_print,"<file name> print a file",{COMPL_NONE,COMPL_NONE}},
1430 {"printmode",cmd_printmode,"<graphics or text> set the print mode",{COMPL_NONE,COMPL_NONE}},
1431 {"queue",cmd_queue,"show the print queue",{COMPL_NONE,COMPL_NONE}},
1432 {"cancel",cmd_cancel,"<jobid> cancel a print queue entry",{COMPL_NONE,COMPL_NONE}},
1433 {"quit",cmd_quit,"logoff the server",{COMPL_NONE,COMPL_NONE}},
1434 {"q",cmd_quit,"logoff the server",{COMPL_NONE,COMPL_NONE}},
1435 {"exit",cmd_quit,"logoff the server",{COMPL_NONE,COMPL_NONE}},
1436 {"newer",cmd_newer,"<file> only mget files newer than the specified local file",{COMPL_LOCAL,COMPL_NONE}},
1437 {"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}},
1438 {"tar",cmd_tar,"tar <c|x>[IXFqbgNan] current directory to/from <file name>",{COMPL_NONE,COMPL_NONE}},
1439 {"blocksize",cmd_block,"blocksize <number> (default 20)",{COMPL_NONE,COMPL_NONE}},
1440 {"tarmode",cmd_tarmode,
1441 "<full|inc|reset|noreset> tar's behaviour towards archive bits",{COMPL_NONE,COMPL_NONE}},
1442 {"setmode",cmd_setmode,"filename <setmode string> change modes of file",{COMPL_REMOTE,COMPL_NONE}},
1443 {"help",cmd_help,"[command] give help on a command",{COMPL_NONE,COMPL_NONE}},
1444 {"?",cmd_help,"[command] give help on a command",{COMPL_NONE,COMPL_NONE}},
1445 {"!",NULL,"run a shell command on the local system",{COMPL_NONE,COMPL_NONE}},
1446 {"",NULL,NULL,{COMPL_NONE,COMPL_NONE}}
1450 /*******************************************************************
1451 lookup a command string in the list of commands, including
1453 ******************************************************************/
1454 static int process_tok(fstring tok)
1456 int i = 0, matches = 0;
1458 int tok_len = strlen(tok);
1460 while (commands[i].fn != NULL) {
1461 if (strequal(commands[i].name,tok)) {
1465 } else if (strnequal(commands[i].name, tok, tok_len)) {
1474 else if (matches == 1)
1480 /****************************************************************************
1482 ****************************************************************************/
1483 static void cmd_help(void)
1488 if (next_token(NULL,buf,NULL,sizeof(buf))) {
1489 if ((i = process_tok(buf)) >= 0)
1490 DEBUG(0,("HELP %s:\n\t%s\n\n",commands[i].name,commands[i].description));
1492 while (commands[i].description) {
1493 for (j=0; commands[i].description && (j<5); j++) {
1494 DEBUG(0,("%-15s",commands[i].name));
1502 /****************************************************************************
1503 wait for keyboard activity, swallowing network packets
1504 ****************************************************************************/
1505 static void wait_keyboard(void)
1508 struct timeval timeout;
1512 FD_SET(cli->fd,&fds);
1513 FD_SET(fileno(stdin),&fds);
1515 timeout.tv_sec = 20;
1516 timeout.tv_usec = 0;
1517 sys_select(MAX(cli->fd,fileno(stdin))+1,&fds,&timeout);
1519 if (FD_ISSET(fileno(stdin),&fds))
1522 /* We deliberately use receive_smb instead of
1523 client_receive_smb as we want to receive
1524 session keepalives and then drop them here.
1526 if (FD_ISSET(cli->fd,&fds))
1527 receive_smb(cli->fd,cli->inbuf,0);
1529 cli_chkpath(cli, "\\");
1533 /****************************************************************************
1534 process a -c command string
1535 ****************************************************************************/
1536 static void process_command_string(char *cmd)
1541 while (cmd[0] != '\0') {
1546 if ((p = strchr(cmd, ';')) == 0) {
1547 strncpy(line, cmd, 999);
1551 if (p - cmd > 999) p = cmd + 999;
1552 strncpy(line, cmd, p - cmd);
1553 line[p - cmd] = '\0';
1557 /* input language code to internal one */
1560 /* and get the first part of the command */
1562 if (!next_token(&ptr,tok,NULL,sizeof(tok))) continue;
1564 if ((i = process_tok(tok)) >= 0) {
1566 } else if (i == -2) {
1567 DEBUG(0,("%s: command abbreviation ambiguous\n",CNV_LANG(tok)));
1569 DEBUG(0,("%s: command not found\n",CNV_LANG(tok)));
1574 #ifdef HAVE_LIBREADLINE
1576 /****************************************************************************
1577 GNU readline completion functions
1578 ****************************************************************************/
1580 /* Argh. This is where it gets ugly. We really need to be able to
1581 pass back from the do_list() iterator function. */
1583 static int compl_state;
1584 static char *compl_text;
1585 static pstring result;
1587 /* Iterator function for do_list() */
1589 static void complete_process_file(file_info *f)
1591 /* Do we have a partial match? */
1593 if ((compl_state >= 0) && (strncmp(compl_text, f->name,
1594 strlen(compl_text)) == 0)) {
1596 /* Return filename if we have made enough matches */
1598 if (compl_state == 0) {
1599 pstrcpy(result, f->name);
1608 /* Complete a remote file */
1610 static char *complete_remote_file(char *text, int state)
1612 int attribute = aDIR | aSYSTEM | aHIDDEN;
1615 /* Create dir mask */
1617 pstrcpy(mask, cur_dir);
1620 /* Initialise static vars for filename match */
1623 compl_state = state;
1626 /* Iterate over all files in directory */
1628 do_list(mask, attribute, complete_process_file, False, True);
1630 /* Return matched filename */
1632 if (result[0] != '\0') {
1633 return strdup(result); /* Readline will dispose of strings */
1639 /* Complete a smbclient command */
1641 static char *complete_cmd(char *text, int state)
1643 static int cmd_index;
1652 /* Return the next name which partially matches the list of commands */
1654 while (strlen(name = commands[cmd_index++].name) > 0) {
1655 if (strncmp(name, text, strlen(text)) == 0) {
1656 return strdup(name);
1663 /* Main completion function for smbclient. Work out which word we are
1664 trying to complete and call the appropriate helper function -
1665 complete_cmd() if we are completing smbclient commands,
1666 comlete_remote_file() if we are completing a file on the remote end,
1667 filename_completion_function() builtin to GNU readline for local
1670 static char **completion_fn(char *text, int start, int end)
1672 int i, num_words, cmd_index;
1675 /* If we are at the start of a word, we are completing a smbclient
1679 return completion_matches(text, complete_cmd);
1682 /* Count # of words in command */
1685 for (i = 0; i <= end; i++) {
1686 if ((rl_line_buffer[i] != ' ') && (lastch == ' '))
1688 lastch = rl_line_buffer[i];
1691 if (rl_line_buffer[end] == ' ')
1694 /* Work out which command we are completing for */
1696 for (cmd_index = 0; strcmp(commands[cmd_index].name, "") != 0;
1699 /* Check each command in array */
1701 if (strncmp(rl_line_buffer, commands[cmd_index].name,
1702 strlen(commands[cmd_index].name)) == 0) {
1704 /* Call appropriate completion function */
1706 if ((num_words == 2) || (num_words == 3)) {
1707 switch (commands[cmd_index].compl_args[num_words - 2]) {
1710 return completion_matches(text, complete_remote_file);
1714 return completion_matches(text, filename_completion_function);
1718 /* An invalid completion type */
1723 /* We're either completing an argument > 3 or found an invalid
1724 completion type. Either way do nothing about it. */
1733 /* To avoid filename completion being activated when no valid
1734 completions are found, we assign this stub completion function
1735 to the rl_completion_entry_function variable. */
1737 static char *complete_cmd_null(char *text, int state)
1742 #endif /* HAVE_LIBREADLINE */
1744 /****************************************************************************
1745 process commands on stdin
1746 ****************************************************************************/
1747 static void process_stdin(void)
1750 #ifdef HAVE_LIBREADLINE
1755 while (!feof(stdin)) {
1759 #ifndef HAVE_LIBREADLINE
1761 /* display a prompt */
1762 DEBUG(0,("smb: %s> ", CNV_LANG(cur_dir)));
1767 /* and get a response */
1768 if (!fgets(line,1000,stdin))
1771 #else /* !HAVE_LIBREADLINE */
1773 /* Read input using GNU Readline */
1775 slprintf(promptline, sizeof(promptline) - 1, "smb: %s> ",
1778 if (!readline(promptline))
1781 /* Copy read line to samba buffer */
1783 pstrcpy(line, rl_line_buffer);
1784 pstrcat(line, "\n");
1786 /* Add line to history */
1788 if (strlen(line) > 0)
1791 /* input language code to internal one */
1794 /* special case - first char is ! */
1800 /* and get the first part of the command */
1802 if (!next_token(&ptr,tok,NULL,sizeof(tok))) continue;
1804 if ((i = process_tok(tok)) >= 0) {
1806 } else if (i == -2) {
1807 DEBUG(0,("%s: command abbreviation ambiguous\n",CNV_LANG(tok)));
1809 DEBUG(0,("%s: command not found\n",CNV_LANG(tok)));
1815 /*****************************************************
1816 return a connection to a server
1817 *******************************************************/
1818 struct cli_state *do_connect(char *server, char *share, int smb_port)
1820 struct cli_state *smb_cli;
1821 struct nmb_name called, calling, stupid_smbserver_called;
1824 extern struct in_addr ipzero;
1826 if ((smb_cli=cli_initialise(NULL)) == NULL)
1828 DEBUG(1,("cli_initialise failed\n"));
1835 share = strchr(server,'\\');
1836 if (!share) return NULL;
1845 make_nmb_name(&calling, global_myname, 0x0, "");
1846 make_nmb_name(&called , server, name_type, "");
1847 make_nmb_name(&stupid_smbserver_called , "*SMBSERVER", 0x20, scope);
1849 fstrcpy(smb_cli->usr.user_name, username);
1850 fstrcpy(smb_cli->usr.domain, workgroup);
1853 if (have_ip) ip = dest_ip;
1855 if (cli_set_port(smb_cli, smb_port) == 0)
1860 /* set the password cache info */
1863 if (password[0] == 0)
1865 pwd_set_nullpwd(&(smb_cli->usr.pwd));
1869 /* generate 16 byte hashes */
1870 pwd_make_lm_nt_16(&(smb_cli->usr.pwd), password);
1875 pwd_read(&(smb_cli->usr.pwd), "Password:", True);
1878 /* paranoia: destroy the local copy of the password */
1879 bzero(password, sizeof(password));
1881 smb_cli->use_ntlmv2 = lp_client_ntlmv2();
1883 if (!cli_establish_connection(smb_cli, server, &ip, &calling, &called,
1884 share, "?????", False, True) &&
1885 !cli_establish_connection(smb_cli, server, &ip,
1886 &calling, &stupid_smbserver_called,
1887 share, "?????", False, True))
1896 /****************************************************************************
1897 process commands from the client
1898 ****************************************************************************/
1899 static BOOL process(char *base_directory)
1901 cli = do_connect(desthost, service, port);
1906 if (*base_directory) do_cd(base_directory);
1909 process_command_string(cmdstr);
1918 /****************************************************************************
1919 usage on the program
1920 ****************************************************************************/
1921 static void usage(char *pname)
1923 DEBUG(0,("Usage: %s service <password> ", pname));
1925 DEBUG(0,("\nVersion %s\n",VERSION));
1926 DEBUG(0,("\t-s smb.conf pathname to smb.conf file\n"));
1927 DEBUG(0,("\t-B IP addr broadcast IP address to use\n"));
1928 DEBUG(0,("\t-O socket_options socket options to use\n"));
1929 DEBUG(0,("\t-R name resolve order use these name resolution services only\n"));
1930 DEBUG(0,("\t-M host send a winpopup message to the host\n"));
1931 DEBUG(0,("\t-i scope use this NetBIOS scope\n"));
1932 DEBUG(0,("\t-N don't ask for a password\n"));
1933 DEBUG(0,("\t-n netbios name. Use this name as my netbios name\n"));
1934 DEBUG(0,("\t-d debuglevel set the debuglevel\n"));
1935 DEBUG(0,("\t-P connect to service as a printer\n"));
1936 DEBUG(0,("\t-p port connect to the specified port\n"));
1937 DEBUG(0,("\t-l log basename. Basename for log/debug files\n"));
1938 DEBUG(0,("\t-h Print this help message.\n"));
1939 DEBUG(0,("\t-I dest IP use this IP to connect to\n"));
1940 DEBUG(0,("\t-E write messages to stderr instead of stdout\n"));
1941 DEBUG(0,("\t-U username set the network username\n"));
1942 DEBUG(0,("\t-L host get a list of shares available on a host\n"));
1943 DEBUG(0,("\t-t terminal code terminal i/o code {sjis|euc|jis7|jis8|junet|hex}\n"));
1944 DEBUG(0,("\t-m max protocol set the max protocol level\n"));
1945 DEBUG(0,("\t-W workgroup set the workgroup name\n"));
1946 DEBUG(0,("\t-T<c|x>IXFqgbNan command line tar\n"));
1947 DEBUG(0,("\t-D directory start from directory\n"));
1948 DEBUG(0,("\t-c command string execute semicolon separated commands\n"));
1953 /****************************************************************************
1954 get a password from a a file or file descriptor
1956 ****************************************************************************/
1957 static void get_password_file(void)
1961 BOOL close_it = False;
1965 if ((p = getenv("PASSWD_FD")) != NULL) {
1966 pstrcpy(spec, "descriptor ");
1968 sscanf(p, "%d", &fd);
1970 } else if ((p = getenv("PASSWD_FILE")) != NULL) {
1971 fd = sys_open(p, O_RDONLY, 0);
1974 fprintf(stderr, "Error opening PASSWD_FILE %s: %s\n",
1975 spec, strerror(errno));
1981 for(p = pass, *p = '\0'; /* ensure that pass is null-terminated */
1982 p && p - pass < sizeof(pass);) {
1983 switch (read(fd, p, 1)) {
1985 if (*p != '\n' && *p != '\0') {
1986 *++p = '\0'; /* advance p, and null-terminate pass */
1991 *p = '\0'; /* null-terminate it, just in case... */
1992 p = NULL; /* then force the loop condition to become false */
1995 fprintf(stderr, "Error reading password from file %s: %s\n",
1996 spec, "empty password\n");
2001 fprintf(stderr, "Error reading password from file %s: %s\n",
2002 spec, strerror(errno));
2006 pstrcpy(password, pass);
2013 /****************************************************************************
2015 ****************************************************************************/
2016 static int do_host_query(char *query_host, int smb_port)
2018 cli = do_connect(query_host, "IPC$", smb_port);
2023 list_servers(workgroup);
2031 /****************************************************************************
2032 handle a tar operation
2033 ****************************************************************************/
2034 static int do_tar_op(int smb_port, char *base_directory)
2037 cli = do_connect(desthost, service, smb_port);
2043 if (*base_directory) do_cd(base_directory);
2052 /****************************************************************************
2053 handle a message operation
2054 ****************************************************************************/
2055 static int do_message_op(void)
2058 struct nmb_name called, calling;
2062 make_nmb_name(&calling, global_myname, 0x0, "");
2063 make_nmb_name(&called , desthost, name_type, "");
2066 if (have_ip) ip = dest_ip;
2068 if (!(cli=cli_initialise(NULL)) || !cli_connect(cli, desthost, &ip)) {
2069 DEBUG(0,("Connection to %s failed\n", desthost));
2073 if (!cli_session_request(cli, &calling, &called)) {
2074 DEBUG(0,("session request failed\n"));
2086 /****************************************************************************
2088 ****************************************************************************/
2089 int main(int argc,char *argv[])
2091 fstring base_directory;
2092 char *pname = argv[0];
2095 extern char *optarg;
2098 BOOL message = False;
2099 BOOL explicit_user = False;
2100 extern char tar_type;
2101 static pstring servicesf = CONFIGFILE;
2103 pstring new_name_resolve_order;
2107 pstrcpy(term_code, KANJI);
2113 *base_directory = 0;
2115 *new_name_resolve_order = 0;
2119 setup_logging(pname,True);
2122 charset_initialise();
2124 if(!get_myname(myhostname,NULL)) {
2125 DEBUG(0,("Failed to get my hostname.\n"));
2128 in_client = True; /* Make sure that we tell lp_load we are */
2130 if (!lp_load(servicesf,True,False,False)) {
2131 fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf);
2134 codepage_initialise(lp_client_code_page());
2136 interpret_coding_system(term_code);
2142 pstrcpy(workgroup,lp_workgroup());
2148 if (getenv("USER")) {
2149 pstrcpy(username,getenv("USER"));
2151 /* modification to support userid%passwd syntax in the USER var
2152 25.Aug.97, jdblair@uab.edu */
2154 if ((p=strchr(username,'%'))) {
2156 pstrcpy(password,p+1);
2158 memset(strchr(getenv("USER"),'%')+1,'X',strlen(password));
2163 /* modification to support PASSWD environmental var
2164 25.Aug.97, jdblair@uab.edu */
2165 if (getenv("PASSWD")) {
2166 pstrcpy(password,getenv("PASSWD"));
2170 if (getenv("PASSWD_FD") || getenv("PASSWD_FILE")) {
2171 get_password_file();
2175 if (*username == 0 && getenv("LOGNAME")) {
2176 pstrcpy(username,getenv("LOGNAME"));
2180 if (*username == 0) {
2181 pstrcpy(username,"GUEST");
2189 if (*argv[1] != '-') {
2190 pstrcpy(service,argv[1]);
2191 /* Convert any '/' characters in the service name to '\' characters */
2192 string_replace( service, '/','\\');
2196 if (count_chars(service,'\\') < 3) {
2198 printf("\n%s: Not enough '\\' characters in service\n",service);
2202 if (argc > 1 && (*argv[1] != '-')) {
2204 pstrcpy(password,argv[1]);
2205 memset(argv[1],'X',strlen(argv[1]));
2212 getopt(argc, argv,"s:B:O:R:M:i:Nn:d:Pp:l:hI:EU:L:t:m:W:T:D:c:")) != EOF) {
2215 pstrcpy(servicesf, optarg);
2218 iface_set_default(NULL,optarg,NULL);
2221 pstrcpy(user_socket_options,optarg);
2224 pstrcpy(new_name_resolve_order, optarg);
2227 name_type = 0x03; /* messages are sent to NetBIOS name type 0x3 */
2228 pstrcpy(desthost,optarg);
2232 pstrcpy(scope,optarg);
2238 pstrcpy(global_myname,optarg);
2244 DEBUGLEVEL = atoi(optarg);
2247 /* not needed anymore */
2250 port = atoi(optarg);
2253 slprintf(debugf,sizeof(debugf)-1, "%s.client",optarg);
2261 dest_ip = *interpret_addr2(optarg);
2262 if (zero_ip(dest_ip))
2273 explicit_user = True;
2274 pstrcpy(username,optarg);
2275 if ((lp=strchr(username,'%'))) {
2277 pstrcpy(password,lp+1);
2279 memset(strchr(optarg,'%')+1,'X',strlen(password));
2284 pstrcpy(query_host,optarg);
2289 pstrcpy(term_code, optarg);
2292 /* no longer supported */
2295 pstrcpy(workgroup,optarg);
2298 if (!tar_parseargs(argc, argv, optarg, optind)) {
2304 pstrcpy(base_directory,optarg);
2316 get_myname((*global_myname)?NULL:global_myname,NULL);
2318 if(*new_name_resolve_order)
2319 lp_set_name_resolve_order(new_name_resolve_order);
2321 if (!tar_type && !*query_host && !*service && !message) {
2326 #ifdef HAVE_LIBREADLINE
2328 /* Initialise GNU Readline */
2330 rl_readline_name = "smbclient";
2331 rl_attempted_completion_function = completion_fn;
2332 rl_completion_entry_function = (Function *)complete_cmd_null;
2334 /* Initialise history list */
2338 #endif /* HAVE_LIBREADLINE */
2340 DEBUG( 3, ( "Client started (version %s).\n", VERSION ) );
2343 return do_tar_op(port, base_directory);
2346 if ((p=strchr(query_host,'#'))) {
2349 sscanf(p, "%x", &name_type);
2353 return do_host_query(query_host, port);
2357 return do_message_op();
2360 if (!process(base_directory)) {