Changeset 740 for vendor/current/source3/client/client.c
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/client/client.c
r591 r740 23 23 24 24 #include "includes.h" 25 #include "system/filesys.h" 26 #include "popt_common.h" 27 #include "rpc_client/cli_pipe.h" 25 28 #include "client/client_proto.h" 26 #include "../librpc/gen_ndr/cli_srvsvc.h" 29 #include "../librpc/gen_ndr/ndr_srvsvc_c.h" 30 #include "../lib/util/select.h" 31 #include "system/readline.h" 32 #include "../libcli/smbreadline/smbreadline.h" 33 #include "../libcli/security/security.h" 34 #include "system/select.h" 35 #include "libsmb/libsmb.h" 36 #include "libsmb/clirap.h" 37 #include "trans2.h" 38 #include "libsmb/nmblib.h" 27 39 28 40 #ifndef REGISTER … … 32 44 extern int do_smb_browse(void); /* mDNS browsing */ 33 45 34 extern bool AllowDebugChange;35 46 extern bool override_logfile; 36 47 extern char tar_type; … … 164 175 165 176 /**************************************************************************** 177 Put up a yes/no prompt. 178 ****************************************************************************/ 179 180 static bool yesno(const char *p) 181 { 182 char ans[20]; 183 printf("%s",p); 184 185 if (!fgets(ans,sizeof(ans)-1,stdin)) 186 return(False); 187 188 if (*ans == 'y' || *ans == 'Y') 189 return(True); 190 191 return(False); 192 } 193 194 /**************************************************************************** 166 195 Write to a local file with CR/LF->LF translation if appropriate. Return the 167 196 number taken from the buffer. This may not equal the number written. … … 281 310 char *targetpath = NULL; 282 311 TALLOC_CTX *ctx = talloc_tos(); 312 NTSTATUS status; 283 313 284 314 if ( !cli_resolve_path(ctx, "", auth_info, cli, client_get_cur_dir(), &targetcli, &targetpath)) { … … 287 317 } 288 318 289 if (!NT_STATUS_IS_OK(cli_dskattr(targetcli, &bsize, &total, &avail))) { 290 d_printf("Error in dskattr: %s\n",cli_errstr(targetcli)); 319 status = cli_dskattr(targetcli, &bsize, &total, &avail); 320 if (!NT_STATUS_IS_OK(status)) { 321 d_printf("Error in dskattr: %s\n", nt_errstr(status)); 291 322 return 1; 292 323 } … … 315 346 static void normalize_name(char *newdir) 316 347 { 317 if (!(cli-> posix_capabilities & CIFS_UNIX_POSIX_PATHNAMES_CAP)) {348 if (!(cli->requested_posix_capabilities & CIFS_UNIX_POSIX_PATHNAMES_CAP)) { 318 349 string_replace(newdir,'/','\\'); 319 350 } … … 391 422 392 423 if (targetcli->protocol > PROTOCOL_LANMAN2 && !targetcli->win95) { 393 if (!cli_qpathinfo_basic( targetcli, targetpath, &sbuf, &attributes ) ) { 394 d_printf("cd %s: %s\n", new_cd, cli_errstr(targetcli)); 424 NTSTATUS status; 425 426 status = cli_qpathinfo_basic(targetcli, targetpath, &sbuf, 427 &attributes); 428 if (!NT_STATUS_IS_OK(status)) { 429 d_printf("cd %s: %s\n", new_cd, nt_errstr(status)); 395 430 client_set_cur_dir(saved_dir); 396 431 goto out; … … 403 438 } 404 439 } else { 440 NTSTATUS status; 441 405 442 targetpath = talloc_asprintf(ctx, 406 443 "%s%s", … … 417 454 } 418 455 419 if (!NT_STATUS_IS_OK(cli_chkpath(targetcli, targetpath))) { 420 d_printf("cd %s: %s\n", new_cd, cli_errstr(targetcli)); 456 status = cli_chkpath(targetcli, targetpath); 457 if (!NT_STATUS_IS_OK(status)) { 458 d_printf("cd %s: %s\n", new_cd, nt_errstr(status)); 421 459 client_set_cur_dir(saved_dir); 422 460 goto out; … … 463 501 ********************************************************************/ 464 502 465 static bool do_this_one( file_info *finfo)503 static bool do_this_one(struct file_info *finfo) 466 504 { 467 505 if (!finfo->name) { … … 469 507 } 470 508 471 if (finfo->mode & aDIR) {509 if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) { 472 510 return true; 473 511 } … … 484 522 } 485 523 486 if ((archive_level==1 || archive_level==2) && !(finfo->mode & aARCH)) {524 if ((archive_level==1 || archive_level==2) && !(finfo->mode & FILE_ATTRIBUTE_ARCHIVE)) { 487 525 DEBUG(3,("archive %s failed\n", finfo->name)); 488 526 return false; … … 496 534 ****************************************************************************/ 497 535 498 static void display_finfo(file_info *finfo, const char *dir) 536 static NTSTATUS display_finfo(struct cli_state *cli_state, struct file_info *finfo, 537 const char *dir) 499 538 { 500 539 time_t t; 501 540 TALLOC_CTX *ctx = talloc_tos(); 541 NTSTATUS status = NT_STATUS_OK; 502 542 503 543 if (!do_this_one(finfo)) { 504 return ;544 return NT_STATUS_OK; 505 545 } 506 546 … … 519 559 /* skip if this is . or .. */ 520 560 if ( strequal(finfo->name,"..") || strequal(finfo->name,".") ) 521 return ;561 return NT_STATUS_OK; 522 562 /* create absolute filename for cli_ntcreate() FIXME */ 523 563 afname = talloc_asprintf(ctx, … … 527 567 finfo->name); 528 568 if (!afname) { 529 return ;569 return NT_STATUS_NO_MEMORY; 530 570 } 531 571 /* print file meta date header */ … … 534 574 d_printf( "SIZE:%.0f\n", (double)finfo->size); 535 575 d_printf( "MTIME:%s", time_to_asc(t)); 536 if (!NT_STATUS_IS_OK(cli_ntcreate(finfo->cli, afname, 0, 537 CREATE_ACCESS_READ, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, 538 FILE_OPEN, 0x0, 0x0, &fnum))) { 576 status = cli_ntcreate(cli_state, afname, 0, 577 CREATE_ACCESS_READ, 0, 578 FILE_SHARE_READ|FILE_SHARE_WRITE, 579 FILE_OPEN, 0x0, 0x0, &fnum); 580 if (!NT_STATUS_IS_OK(status)) { 539 581 DEBUG( 0, ("display_finfo() Failed to open %s: %s\n", 540 afname, 541 cli_errstr( finfo->cli))); 582 afname, nt_errstr(status))); 542 583 } else { 543 SEC_DESC*sd = NULL;544 sd = cli_query_secdesc( finfo->cli, fnum, ctx);584 struct security_descriptor *sd = NULL; 585 sd = cli_query_secdesc(cli_state, fnum, ctx); 545 586 if (!sd) { 546 587 DEBUG( 0, ("display_finfo() failed to " 547 588 "get security descriptor: %s", 548 cli_errstr( finfo->cli))); 589 cli_errstr(cli_state))); 590 status = cli_nt_error(cli_state); 549 591 } else { 550 592 display_sec_desc(sd); … … 554 596 TALLOC_FREE(afname); 555 597 } 598 return status; 556 599 } 557 600 … … 560 603 ****************************************************************************/ 561 604 562 static void do_du(file_info *finfo, const char *dir) 605 static NTSTATUS do_du(struct cli_state *cli_state, struct file_info *finfo, 606 const char *dir) 563 607 { 564 608 if (do_this_one(finfo)) { 565 609 dir_total += finfo->size; 566 610 } 611 return NT_STATUS_OK; 567 612 } 568 613 … … 573 618 static long do_list_queue_start = 0; 574 619 static long do_list_queue_end = 0; 575 static void (*do_list_fn)(file_info *, const char *dir); 620 static NTSTATUS (*do_list_fn)(struct cli_state *cli_state, struct file_info *, 621 const char *dir); 576 622 577 623 /**************************************************************************** … … 690 736 ****************************************************************************/ 691 737 692 static void do_list_helper(const char *mntpoint, file_info *f, const char *mask, void *state) 693 { 738 static NTSTATUS do_list_helper(const char *mntpoint, struct file_info *f, 739 const char *mask, void *state) 740 { 741 struct cli_state *cli_state = (struct cli_state *)state; 694 742 TALLOC_CTX *ctx = talloc_tos(); 695 743 char *dir = NULL; 696 744 char *dir_end = NULL; 745 NTSTATUS status = NT_STATUS_OK; 697 746 698 747 /* Work out the directory. */ 699 748 dir = talloc_strdup(ctx, mask); 700 749 if (!dir) { 701 return ;750 return NT_STATUS_NO_MEMORY; 702 751 } 703 752 if ((dir_end = strrchr(dir, CLI_DIRSEP_CHAR)) != NULL) { … … 705 754 } 706 755 707 if (f->mode & aDIR) {756 if (f->mode & FILE_ATTRIBUTE_DIRECTORY) { 708 757 if (do_list_dirs && do_this_one(f)) { 709 do_list_fn(f, dir); 758 status = do_list_fn(cli_state, f, dir); 759 if (!NT_STATUS_IS_OK(status)) { 760 return status; 761 } 710 762 } 711 763 if (do_list_recurse && … … 719 771 d_printf("Empty dir name returned. Possible server misconfiguration.\n"); 720 772 TALLOC_FREE(dir); 721 return ;773 return NT_STATUS_UNSUCCESSFUL; 722 774 } 723 775 … … 728 780 if (!mask2) { 729 781 TALLOC_FREE(dir); 730 return ;782 return NT_STATUS_NO_MEMORY; 731 783 } 732 784 p = strrchr_m(mask2,CLI_DIRSEP_CHAR); … … 742 794 if (!mask2) { 743 795 TALLOC_FREE(dir); 744 return ;796 return NT_STATUS_NO_MEMORY; 745 797 } 746 798 add_to_do_list_queue(mask2); … … 748 800 } 749 801 TALLOC_FREE(dir); 750 return ;802 return NT_STATUS_OK; 751 803 } 752 804 753 805 if (do_this_one(f)) { 754 do_list_fn(f,dir);806 status = do_list_fn(cli_state, f, dir); 755 807 } 756 808 TALLOC_FREE(dir); 809 return status; 757 810 } 758 811 … … 761 814 ****************************************************************************/ 762 815 763 voiddo_list(const char *mask,816 NTSTATUS do_list(const char *mask, 764 817 uint16 attribute, 765 void (*fn)(file_info *, const char *dir), 818 NTSTATUS (*fn)(struct cli_state *cli_state, struct file_info *, 819 const char *dir), 766 820 bool rec, 767 821 bool dirs) … … 771 825 struct cli_state *targetcli = NULL; 772 826 char *targetpath = NULL; 827 NTSTATUS ret_status = NT_STATUS_OK; 828 NTSTATUS status = NT_STATUS_OK; 773 829 774 830 if (in_do_list && rec) { … … 798 854 799 855 if (!head) { 800 return ;856 return NT_STATUS_NO_MEMORY; 801 857 } 802 858 … … 809 865 } 810 866 811 cli_list(targetcli, targetpath, attribute, do_list_helper, NULL); 867 status = cli_list(targetcli, targetpath, attribute, 868 do_list_helper, targetcli); 869 if (!NT_STATUS_IS_OK(status)) { 870 d_printf("%s listing %s\n", 871 nt_errstr(status), targetpath); 872 ret_status = status; 873 } 812 874 remove_do_list_queue_head(); 813 875 if ((! do_list_queue_empty()) && (fn == display_finfo)) { … … 837 899 /* check for dfs */ 838 900 if (cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetpath)) { 839 if (cli_list(targetcli, targetpath, attribute, do_list_helper, NULL) == -1) { 901 902 status = cli_list(targetcli, targetpath, attribute, 903 do_list_helper, targetcli); 904 if (!NT_STATUS_IS_OK(status)) { 840 905 d_printf("%s listing %s\n", 841 cli_errstr(targetcli), targetpath); 906 nt_errstr(status), targetpath); 907 ret_status = status; 842 908 } 843 909 TALLOC_FREE(targetpath); 844 910 } else { 845 911 d_printf("do_list: [%s] %s\n", mask, cli_errstr(cli)); 912 ret_status = cli_nt_error(cli); 846 913 } 847 914 } … … 849 916 in_do_list = 0; 850 917 reset_do_list_queue(); 918 return ret_status; 851 919 } 852 920 … … 858 926 { 859 927 TALLOC_CTX *ctx = talloc_tos(); 860 uint16 attribute = aDIR | aSYSTEM | aHIDDEN;928 uint16 attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN; 861 929 char *mask = NULL; 862 930 char *buf = NULL; 863 931 int rc = 1; 932 NTSTATUS status; 864 933 865 934 dir_total = 0; … … 888 957 } 889 958 890 do_list(mask, attribute, display_finfo, recurse, true); 959 status = do_list(mask, attribute, display_finfo, recurse, true); 960 if (!NT_STATUS_IS_OK(status)) { 961 return 1; 962 } 891 963 892 964 rc = do_dskattr(); … … 904 976 { 905 977 TALLOC_CTX *ctx = talloc_tos(); 906 uint16 attribute = aDIR | aSYSTEM | aHIDDEN;978 uint16 attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN; 907 979 char *mask = NULL; 908 980 char *buf = NULL; 981 NTSTATUS status; 909 982 int rc = 1; 910 983 … … 932 1005 } 933 1006 934 do_list(mask, attribute, do_du, recurse, true); 1007 status = do_list(mask, attribute, do_du, recurse, true); 1008 if (!NT_STATUS_IS_OK(status)) { 1009 return 1; 1010 } 935 1011 936 1012 rc = do_dskattr(); … … 983 1059 uint16_t fnum; 984 1060 bool newhandle = false; 985 struct time valtp_start;1061 struct timespec tp_start; 986 1062 uint16 attr; 987 1063 SMB_OFF_T size; … … 1008 1084 } 1009 1085 1010 GetTimeOfDay(&tp_start); 1011 1012 if (!NT_STATUS_IS_OK(cli_open(targetcli, targetname, O_RDONLY, DENY_NONE, &fnum))) { 1013 d_printf("%s opening remote file %s\n",cli_errstr(cli),rname); 1086 clock_gettime_mono(&tp_start); 1087 1088 status = cli_open(targetcli, targetname, O_RDONLY, DENY_NONE, &fnum); 1089 if (!NT_STATUS_IS_OK(status)) { 1090 d_printf("%s opening remote file %s\n", nt_errstr(status), 1091 rname); 1014 1092 return 1; 1015 1093 } … … 1038 1116 1039 1117 1040 if (!cli_qfileinfo(targetcli, fnum, 1041 &attr, &size, NULL, NULL, NULL, NULL, NULL) && 1042 !NT_STATUS_IS_OK(cli_getattrE(targetcli, fnum, 1043 &attr, &size, NULL, NULL, NULL))) { 1044 d_printf("getattrib: %s\n",cli_errstr(targetcli)); 1045 return 1; 1118 status = cli_qfileinfo_basic(targetcli, fnum, &attr, &size, NULL, NULL, 1119 NULL, NULL, NULL); 1120 if (!NT_STATUS_IS_OK(status)) { 1121 status = cli_getattrE(targetcli, fnum, &attr, &size, NULL, NULL, 1122 NULL); 1123 if(!NT_STATUS_IS_OK(status)) { 1124 d_printf("getattrib: %s\n", nt_errstr(status)); 1125 return 1; 1126 } 1046 1127 } 1047 1128 … … 1058 1139 } 1059 1140 1060 if (!NT_STATUS_IS_OK(cli_close(targetcli, fnum))) { 1061 d_printf("Error %s closing remote file\n",cli_errstr(cli)); 1141 status = cli_close(targetcli, fnum); 1142 if (!NT_STATUS_IS_OK(status)) { 1143 d_printf("Error %s closing remote file\n", nt_errstr(status)); 1062 1144 rc = 1; 1063 1145 } … … 1067 1149 } 1068 1150 1069 if (archive_level >= 2 && (attr & aARCH)) {1070 cli_setatr(cli, rname, attr & ~(uint16) aARCH, 0);1151 if (archive_level >= 2 && (attr & FILE_ATTRIBUTE_ARCHIVE)) { 1152 cli_setatr(cli, rname, attr & ~(uint16)FILE_ATTRIBUTE_ARCHIVE, 0); 1071 1153 } 1072 1154 1073 1155 { 1074 struct time valtp_end;1156 struct timespec tp_end; 1075 1157 int this_time; 1076 1158 1077 GetTimeOfDay(&tp_end); 1078 this_time = 1079 (tp_end.tv_sec - tp_start.tv_sec)*1000 + 1080 (tp_end.tv_usec - tp_start.tv_usec)/1000; 1159 clock_gettime_mono(&tp_end); 1160 this_time = nsec_time_diff(&tp_end,&tp_start)/1000000; 1081 1161 get_total_time_ms += this_time; 1082 1162 get_total_size += nread; … … 1132 1212 ****************************************************************************/ 1133 1213 1134 static void do_mget(file_info *finfo, const char *dir) 1135 { 1136 TALLOC_CTX *ctx = talloc_tos(); 1214 static NTSTATUS do_mget(struct cli_state *cli_state, struct file_info *finfo, 1215 const char *dir) 1216 { 1217 TALLOC_CTX *ctx = talloc_tos(); 1218 NTSTATUS status = NT_STATUS_OK; 1137 1219 char *rname = NULL; 1138 1220 char *quest = NULL; … … 1142 1224 1143 1225 if (!finfo->name) { 1144 return ;1226 return NT_STATUS_OK; 1145 1227 } 1146 1228 1147 1229 if (strequal(finfo->name,".") || strequal(finfo->name,"..")) 1148 return ;1230 return NT_STATUS_OK; 1149 1231 1150 1232 if (abort_mget) { 1151 1233 d_printf("mget aborted\n"); 1152 return ;1153 } 1154 1155 if (finfo->mode & aDIR) {1234 return NT_STATUS_UNSUCCESSFUL; 1235 } 1236 1237 if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) { 1156 1238 if (asprintf(&quest, 1157 1239 "Get directory %s? ",finfo->name) < 0) { 1158 return ;1240 return NT_STATUS_NO_MEMORY; 1159 1241 } 1160 1242 } else { 1161 1243 if (asprintf(&quest, 1162 1244 "Get file %s? ",finfo->name) < 0) { 1163 return ;1245 return NT_STATUS_NO_MEMORY; 1164 1246 } 1165 1247 } … … 1167 1249 if (prompt && !yesno(quest)) { 1168 1250 SAFE_FREE(quest); 1169 return ;1251 return NT_STATUS_OK; 1170 1252 } 1171 1253 SAFE_FREE(quest); 1172 1254 1173 if (!(finfo->mode & aDIR)) {1255 if (!(finfo->mode & FILE_ATTRIBUTE_DIRECTORY)) { 1174 1256 rname = talloc_asprintf(ctx, 1175 1257 "%s%s", … … 1177 1259 finfo->name); 1178 1260 if (!rname) { 1179 return ;1261 return NT_STATUS_NO_MEMORY; 1180 1262 } 1181 1263 do_get(rname, finfo->name, false); 1182 1264 TALLOC_FREE(rname); 1183 return ;1265 return NT_STATUS_OK; 1184 1266 } 1185 1267 … … 1187 1269 saved_curdir = talloc_strdup(ctx, client_get_cur_dir()); 1188 1270 if (!saved_curdir) { 1189 return ;1271 return NT_STATUS_NO_MEMORY; 1190 1272 } 1191 1273 … … 1196 1278 CLI_DIRSEP_STR); 1197 1279 if (!new_cd) { 1198 return ;1280 return NT_STATUS_NO_MEMORY; 1199 1281 } 1200 1282 client_set_cur_dir(new_cd); … … 1209 1291 d_printf("failed to create directory %s\n",finfo->name); 1210 1292 client_set_cur_dir(saved_curdir); 1211 return ;1293 return map_nt_error_from_unix(errno); 1212 1294 } 1213 1295 … … 1215 1297 d_printf("failed to chdir to directory %s\n",finfo->name); 1216 1298 client_set_cur_dir(saved_curdir); 1217 return ;1299 return map_nt_error_from_unix(errno); 1218 1300 } 1219 1301 … … 1223 1305 1224 1306 if (!mget_mask) { 1225 return; 1226 } 1227 1228 do_list(mget_mask, aSYSTEM | aHIDDEN | aDIR,do_mget,false, true); 1307 return NT_STATUS_NO_MEMORY; 1308 } 1309 1310 status = do_list(mget_mask, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY,do_mget,false, true); 1311 if (!NT_STATUS_IS_OK(status)) { 1312 return status; 1313 } 1314 1229 1315 if (chdir("..") == -1) { 1230 1316 d_printf("do_mget: failed to chdir to .. (error %s)\n", 1231 1317 strerror(errno) ); 1318 return map_nt_error_from_unix(errno); 1232 1319 } 1233 1320 client_set_cur_dir(saved_curdir); … … 1235 1322 TALLOC_FREE(saved_curdir); 1236 1323 TALLOC_FREE(new_cd); 1324 return NT_STATUS_OK; 1237 1325 } 1238 1326 … … 1309 1397 { 1310 1398 TALLOC_CTX *ctx = talloc_tos(); 1311 uint16 attribute = aSYSTEM | aHIDDEN;1399 uint16 attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN; 1312 1400 char *mget_mask = NULL; 1313 1401 char *buf = NULL; 1402 NTSTATUS status = NT_STATUS_OK; 1314 1403 1315 1404 if (recurse) { 1316 attribute |= aDIR;1405 attribute |= FILE_ATTRIBUTE_DIRECTORY; 1317 1406 } 1318 1407 … … 1320 1409 1321 1410 while (next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { 1411 1322 1412 mget_mask = talloc_strdup(ctx, client_get_cur_dir()); 1323 1413 if (!mget_mask) { … … 1333 1423 return 1; 1334 1424 } 1335 do_list(mget_mask, attribute, do_mget, false, true); 1425 status = do_list(mget_mask, attribute, do_mget, false, true); 1426 if (!NT_STATUS_IS_OK(status)) { 1427 return 1; 1428 } 1336 1429 } 1337 1430 … … 1348 1441 return 1; 1349 1442 } 1350 do_list(mget_mask, attribute, do_mget, false, true); 1443 status = do_list(mget_mask, attribute, do_mget, false, true); 1444 if (!NT_STATUS_IS_OK(status)) { 1445 return 1; 1446 } 1351 1447 } 1352 1448 … … 1363 1459 struct cli_state *targetcli; 1364 1460 char *targetname = NULL; 1461 NTSTATUS status; 1365 1462 1366 1463 if (!cli_resolve_path(ctx, "", auth_info, cli, name, &targetcli, &targetname)) { … … 1369 1466 } 1370 1467 1371 if (!NT_STATUS_IS_OK(cli_mkdir(targetcli, targetname))) { 1468 status = cli_mkdir(targetcli, targetname); 1469 if (!NT_STATUS_IS_OK(status)) { 1372 1470 d_printf("%s making remote directory %s\n", 1373 cli_errstr(targetcli),name);1471 nt_errstr(status),name); 1374 1472 return false; 1375 1473 } … … 1385 1483 { 1386 1484 fstring altname; 1387 1388 if (!NT_STATUS_IS_OK(cli_qpathinfo_alt_name(cli, name, altname))) { 1485 NTSTATUS status; 1486 1487 status = cli_qpathinfo_alt_name(cli, name, altname); 1488 if (!NT_STATUS_IS_OK(status)) { 1389 1489 d_printf("%s getting alt name for %s\n", 1390 cli_errstr(cli),name);1490 nt_errstr(status),name); 1391 1491 return false; 1392 1492 } … … 1505 1605 } 1506 1606 1607 static char *attr_str(TALLOC_CTX *mem_ctx, uint16_t mode) 1608 { 1609 char *attrs = TALLOC_ZERO_ARRAY(mem_ctx, char, 17); 1610 int i = 0; 1611 1612 if (!(mode & FILE_ATTRIBUTE_NORMAL)) { 1613 if (mode & FILE_ATTRIBUTE_ENCRYPTED) { 1614 attrs[i++] = 'E'; 1615 } 1616 if (mode & FILE_ATTRIBUTE_NONINDEXED) { 1617 attrs[i++] = 'N'; 1618 } 1619 if (mode & FILE_ATTRIBUTE_OFFLINE) { 1620 attrs[i++] = 'O'; 1621 } 1622 if (mode & FILE_ATTRIBUTE_COMPRESSED) { 1623 attrs[i++] = 'C'; 1624 } 1625 if (mode & FILE_ATTRIBUTE_REPARSE_POINT) { 1626 attrs[i++] = 'r'; 1627 } 1628 if (mode & FILE_ATTRIBUTE_SPARSE) { 1629 attrs[i++] = 's'; 1630 } 1631 if (mode & FILE_ATTRIBUTE_TEMPORARY) { 1632 attrs[i++] = 'T'; 1633 } 1634 if (mode & FILE_ATTRIBUTE_NORMAL) { 1635 attrs[i++] = 'N'; 1636 } 1637 if (mode & FILE_ATTRIBUTE_READONLY) { 1638 attrs[i++] = 'R'; 1639 } 1640 if (mode & FILE_ATTRIBUTE_HIDDEN) { 1641 attrs[i++] = 'H'; 1642 } 1643 if (mode & FILE_ATTRIBUTE_SYSTEM) { 1644 attrs[i++] = 'S'; 1645 } 1646 if (mode & FILE_ATTRIBUTE_DIRECTORY) { 1647 attrs[i++] = 'D'; 1648 } 1649 if (mode & FILE_ATTRIBUTE_ARCHIVE) { 1650 attrs[i++] = 'A'; 1651 } 1652 } 1653 return attrs; 1654 } 1655 1507 1656 /**************************************************************************** 1508 1657 Show all info we can get … … 1517 1666 SMB_INO_T ino; 1518 1667 NTTIME tmp; 1668 uint16_t fnum; 1519 1669 unsigned int num_streams; 1520 1670 struct stream_struct *streams; 1671 int num_snapshots; 1672 char **snapshots; 1521 1673 unsigned int i; 1522 1523 if (!NT_STATUS_IS_OK(cli_qpathinfo_alt_name(cli, name, altname))) { 1524 d_printf("%s getting alt name for %s\n", 1525 cli_errstr(cli),name); 1674 NTSTATUS status; 1675 1676 status = cli_qpathinfo_alt_name(cli, name, altname); 1677 if (!NT_STATUS_IS_OK(status)) { 1678 d_printf("%s getting alt name for %s\n", nt_errstr(status), 1679 name); 1526 1680 return false; 1527 1681 } 1528 1682 d_printf("altname: %s\n", altname); 1529 1683 1530 if (!cli_qpathinfo2(cli, name, &b_time, &a_time, &m_time, &c_time, 1531 &size, &mode, &ino)) { 1532 d_printf("%s getting pathinfo for %s\n", 1533 cli_errstr(cli),name); 1684 status = cli_qpathinfo2(cli, name, &b_time, &a_time, &m_time, &c_time, 1685 &size, &mode, &ino); 1686 if (!NT_STATUS_IS_OK(status)) { 1687 d_printf("%s getting pathinfo for %s\n", nt_errstr(status), 1688 name); 1534 1689 return false; 1535 1690 } … … 1547 1702 d_printf("change_time: %s\n", nt_time_string(talloc_tos(), tmp)); 1548 1703 1549 if (!cli_qpathinfo_streams(cli, name, talloc_tos(), &num_streams, 1550 &streams)) { 1551 d_printf("%s getting streams for %s\n", 1552 cli_errstr(cli),name); 1704 d_printf("attributes: %s (%x)\n", attr_str(talloc_tos(), mode), mode); 1705 1706 status = cli_qpathinfo_streams(cli, name, talloc_tos(), &num_streams, 1707 &streams); 1708 if (!NT_STATUS_IS_OK(status)) { 1709 d_printf("%s getting streams for %s\n", nt_errstr(status), 1710 name); 1553 1711 return false; 1554 1712 } … … 1558 1716 (unsigned long long)streams[i].size); 1559 1717 } 1718 1719 status = cli_ntcreate(cli, name, 0, 1720 CREATE_ACCESS_READ, 0, 1721 FILE_SHARE_READ|FILE_SHARE_WRITE 1722 |FILE_SHARE_DELETE, 1723 FILE_OPEN, 0x0, 0x0, &fnum); 1724 if (!NT_STATUS_IS_OK(status)) { 1725 /* 1726 * Ignore failure, it does not hurt if we can't list 1727 * snapshots 1728 */ 1729 return 0; 1730 } 1731 status = cli_shadow_copy_data(talloc_tos(), cli, fnum, 1732 true, &snapshots, &num_snapshots); 1733 if (!NT_STATUS_IS_OK(status)) { 1734 cli_close(cli, fnum); 1735 return 0; 1736 } 1737 1738 for (i=0; i<num_snapshots; i++) { 1739 char *snap_name; 1740 1741 d_printf("%s\n", snapshots[i]); 1742 snap_name = talloc_asprintf(talloc_tos(), "%s%s", 1743 snapshots[i], name); 1744 status = cli_qpathinfo2(cli, snap_name, &b_time, &a_time, 1745 &m_time, &c_time, &size, 1746 NULL, NULL); 1747 if (!NT_STATUS_IS_OK(status)) { 1748 d_fprintf(stderr, "pathinfo(%s) failed: %s\n", 1749 snap_name, nt_errstr(status)); 1750 TALLOC_FREE(snap_name); 1751 continue; 1752 } 1753 unix_timespec_to_nt_time(&tmp, b_time); 1754 d_printf("create_time: %s\n", nt_time_string(talloc_tos(), tmp)); 1755 unix_timespec_to_nt_time(&tmp, a_time); 1756 d_printf("access_time: %s\n", nt_time_string(talloc_tos(), tmp)); 1757 unix_timespec_to_nt_time(&tmp, m_time); 1758 d_printf("write_time: %s\n", nt_time_string(talloc_tos(), tmp)); 1759 unix_timespec_to_nt_time(&tmp, c_time); 1760 d_printf("change_time: %s\n", nt_time_string(talloc_tos(), tmp)); 1761 d_printf("size: %d\n", (int)size); 1762 } 1763 1764 TALLOC_FREE(snapshots); 1560 1765 1561 1766 return 0; … … 1602 1807 SMB_OFF_T start = 0; 1603 1808 int rc = 0; 1604 struct time valtp_start;1809 struct timespec tp_start; 1605 1810 struct cli_state *targetcli; 1606 1811 char *targetname = NULL; … … 1613 1818 } 1614 1819 1615 GetTimeOfDay(&tp_start);1820 clock_gettime_mono(&tp_start); 1616 1821 1617 1822 if (reput) { 1618 1823 status = cli_open(targetcli, targetname, O_RDWR|O_CREAT, DENY_NONE, &fnum); 1619 1824 if (NT_STATUS_IS_OK(status)) { 1620 if (!cli_qfileinfo(targetcli, fnum, NULL, &start, NULL, NULL, NULL, NULL, NULL) && 1621 !NT_STATUS_IS_OK(cli_getattrE(targetcli, fnum, NULL, &start, NULL, NULL, NULL))) { 1622 d_printf("getattrib: %s\n",cli_errstr(cli)); 1825 if (!NT_STATUS_IS_OK(status = cli_qfileinfo_basic( 1826 targetcli, fnum, NULL, 1827 &start, NULL, NULL, 1828 NULL, NULL, NULL)) && 1829 !NT_STATUS_IS_OK(status = cli_getattrE( 1830 targetcli, fnum, NULL, 1831 &start, NULL, NULL, 1832 NULL))) { 1833 d_printf("getattrib: %s\n", nt_errstr(status)); 1623 1834 return 1; 1624 1835 } … … 1629 1840 1630 1841 if (!NT_STATUS_IS_OK(status)) { 1631 d_printf("%s opening remote file %s\n",cli_errstr(targetcli),rname); 1842 d_printf("%s opening remote file %s\n", nt_errstr(status), 1843 rname); 1632 1844 return 1; 1633 1845 } … … 1669 1881 if (!NT_STATUS_IS_OK(status)) { 1670 1882 d_fprintf(stderr, "cli_push returned %s\n", nt_errstr(status)); 1671 } 1672 1673 if (!NT_STATUS_IS_OK(cli_close(targetcli, fnum))) { 1674 d_printf("%s closing remote file %s\n",cli_errstr(cli),rname); 1883 rc = 1; 1884 } 1885 1886 status = cli_close(targetcli, fnum); 1887 if (!NT_STATUS_IS_OK(status)) { 1888 d_printf("%s closing remote file %s\n", nt_errstr(status), 1889 rname); 1675 1890 if (f != x_stdin) { 1676 1891 x_fclose(f); … … 1684 1899 1685 1900 { 1686 struct time valtp_end;1901 struct timespec tp_end; 1687 1902 int this_time; 1688 1903 1689 GetTimeOfDay(&tp_end); 1690 this_time = 1691 (tp_end.tv_sec - tp_start.tv_sec)*1000 + 1692 (tp_end.tv_usec - tp_start.tv_usec)/1000; 1904 clock_gettime_mono(&tp_end); 1905 this_time = nsec_time_diff(&tp_end,&tp_start)/1000000; 1693 1906 put_total_time_ms += this_time; 1694 1907 put_total_size += state.nread; … … 2079 2292 ****************************************************************************/ 2080 2293 2081 static void do_del(file_info *finfo, const char *dir) 2294 static NTSTATUS do_del(struct cli_state *cli_state, struct file_info *finfo, 2295 const char *dir) 2082 2296 { 2083 2297 TALLOC_CTX *ctx = talloc_tos(); 2084 2298 char *mask = NULL; 2299 NTSTATUS status; 2085 2300 2086 2301 mask = talloc_asprintf(ctx, … … 2090 2305 finfo->name); 2091 2306 if (!mask) { 2092 return ;2093 } 2094 2095 if (finfo->mode & aDIR) {2307 return NT_STATUS_NO_MEMORY; 2308 } 2309 2310 if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) { 2096 2311 TALLOC_FREE(mask); 2097 return; 2098 } 2099 2100 if (!NT_STATUS_IS_OK(cli_unlink(finfo->cli, mask, aSYSTEM | aHIDDEN))) { 2312 return NT_STATUS_OK; 2313 } 2314 2315 status = cli_unlink(cli_state, mask, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 2316 if (!NT_STATUS_IS_OK(status)) { 2101 2317 d_printf("%s deleting remote file %s\n", 2102 cli_errstr(finfo->cli),mask);2318 nt_errstr(status), mask); 2103 2319 } 2104 2320 TALLOC_FREE(mask); 2321 return status; 2105 2322 } 2106 2323 … … 2114 2331 char *mask = NULL; 2115 2332 char *buf = NULL; 2116 uint16 attribute = aSYSTEM | aHIDDEN; 2333 NTSTATUS status = NT_STATUS_OK; 2334 uint16 attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN; 2117 2335 2118 2336 if (recurse) { 2119 attribute |= aDIR;2337 attribute |= FILE_ATTRIBUTE_DIRECTORY; 2120 2338 } 2121 2339 … … 2133 2351 } 2134 2352 2135 do_list(mask,attribute,do_del,false,false); 2353 status = do_list(mask,attribute,do_del,false,false); 2354 if (!NT_STATUS_IS_OK(status)) { 2355 return 1; 2356 } 2136 2357 return 0; 2137 2358 } … … 2149 2370 struct cli_state *targetcli; 2150 2371 char *targetname = NULL; 2372 NTSTATUS status; 2151 2373 2152 2374 if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { … … 2174 2396 } 2175 2397 2176 if (!NT_STATUS_IS_OK(cli_unlink(targetcli, targetname, attribute))) { 2177 d_printf("%s deleting remote files %s\n",cli_errstr(targetcli),targetname); 2398 status = cli_unlink(targetcli, targetname, attribute); 2399 if (!NT_STATUS_IS_OK(status)) { 2400 d_printf("%s deleting remote files %s\n", nt_errstr(status), 2401 targetname); 2178 2402 } 2179 2403 return 0; … … 2533 2757 d_printf("Server supports CIFS capabilities %s\n", caps); 2534 2758 2535 if (!cli_set_unix_extensions_capabilities(cli, major, minor, caplow, caphigh)) { 2536 d_printf("Can't set UNIX CIFS extensions capabilities. %s.\n", cli_errstr(cli)); 2759 status = cli_set_unix_extensions_capabilities(cli, major, minor, 2760 caplow, caphigh); 2761 if (!NT_STATUS_IS_OK(status)) { 2762 d_printf("Can't set UNIX CIFS extensions capabilities. %s.\n", 2763 nt_errstr(status)); 2537 2764 return 1; 2538 2765 } … … 2778 3005 char *buf = NULL; 2779 3006 char *buf2 = NULL; 2780 char *targetname = NULL; 2781 struct cli_state *targetcli; 3007 struct cli_state *newcli; 2782 3008 2783 3009 if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) || … … 2786 3012 return 1; 2787 3013 } 2788 oldname = talloc_asprintf(ctx, 2789 "%s%s", 2790 client_get_cur_dir(), 2791 buf); 2792 if (!oldname) { 2793 return 1; 2794 } 3014 /* Oldname (link target) must be an untouched blob. */ 3015 oldname = buf; 3016 2795 3017 newname = talloc_asprintf(ctx, 2796 3018 "%s%s", … … 2801 3023 } 2802 3024 2803 if (!cli_resolve_path(ctx, "", auth_info, cli, oldname, &targetcli, &targetname)) { 3025 /* New name must be present in share namespace. */ 3026 if (!cli_resolve_path(ctx, "", auth_info, cli, newname, &newcli, &newname)) { 2804 3027 d_printf("link %s: %s\n", oldname, cli_errstr(cli)); 2805 3028 return 1; 2806 3029 } 2807 3030 2808 if (!SERVER_HAS_UNIX_CIFS( targetcli)) {3031 if (!SERVER_HAS_UNIX_CIFS(newcli)) { 2809 3032 d_printf("Server doesn't support UNIX CIFS calls.\n"); 2810 3033 return 1; 2811 3034 } 2812 3035 2813 if (!NT_STATUS_IS_OK(cli_posix_symlink( targetcli, targetname, newname))) {3036 if (!NT_STATUS_IS_OK(cli_posix_symlink(newcli, oldname, newname))) { 2814 3037 d_printf("%s symlinking files (%s -> %s)\n", 2815 cli_errstr( targetcli), newname, targetname);3038 cli_errstr(newcli), newname, newname); 2816 3039 return 1; 2817 3040 } … … 3140 3363 } 3141 3364 3365 static void printf_cb(const char *buf, void *private_data) 3366 { 3367 printf("%s", buf); 3368 } 3369 3370 /**************************************************************************** 3371 Get the EA list of a file 3372 ****************************************************************************/ 3373 3374 static int cmd_geteas(void) 3375 { 3376 TALLOC_CTX *ctx = talloc_tos(); 3377 char *src = NULL; 3378 char *name = NULL; 3379 char *targetname = NULL; 3380 struct cli_state *targetcli; 3381 NTSTATUS status; 3382 size_t i, num_eas; 3383 struct ea_struct *eas; 3384 3385 if (!next_token_talloc(ctx, &cmd_ptr,&name,NULL)) { 3386 d_printf("geteas filename\n"); 3387 return 1; 3388 } 3389 src = talloc_asprintf(ctx, 3390 "%s%s", 3391 client_get_cur_dir(), 3392 name); 3393 if (!src) { 3394 return 1; 3395 } 3396 3397 if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, 3398 &targetname)) { 3399 d_printf("stat %s: %s\n", src, cli_errstr(cli)); 3400 return 1; 3401 } 3402 3403 status = cli_get_ea_list_path(targetcli, targetname, talloc_tos(), 3404 &num_eas, &eas); 3405 if (!NT_STATUS_IS_OK(status)) { 3406 d_printf("cli_get_ea_list_path: %s\n", nt_errstr(status)); 3407 return 1; 3408 } 3409 3410 for (i=0; i<num_eas; i++) { 3411 d_printf("%s (%d) =\n", eas[i].name, (int)eas[i].flags); 3412 dump_data_cb(eas[i].value.data, eas[i].value.length, false, 3413 printf_cb, NULL); 3414 d_printf("\n"); 3415 } 3416 3417 TALLOC_FREE(eas); 3418 3419 return 0; 3420 } 3421 3422 /**************************************************************************** 3423 Set an EA of a file 3424 ****************************************************************************/ 3425 3426 static int cmd_setea(void) 3427 { 3428 TALLOC_CTX *ctx = talloc_tos(); 3429 char *src = NULL; 3430 char *name = NULL; 3431 char *eaname = NULL; 3432 char *eavalue = NULL; 3433 char *targetname = NULL; 3434 struct cli_state *targetcli; 3435 NTSTATUS status; 3436 3437 if (!next_token_talloc(ctx, &cmd_ptr, &name, NULL) 3438 || !next_token_talloc(ctx, &cmd_ptr, &eaname, NULL)) { 3439 d_printf("setea filename eaname value\n"); 3440 return 1; 3441 } 3442 if (!next_token_talloc(ctx, &cmd_ptr, &eavalue, NULL)) { 3443 eavalue = talloc_strdup(ctx, ""); 3444 } 3445 src = talloc_asprintf(ctx, 3446 "%s%s", 3447 client_get_cur_dir(), 3448 name); 3449 if (!src) { 3450 return 1; 3451 } 3452 3453 if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, 3454 &targetname)) { 3455 d_printf("stat %s: %s\n", src, cli_errstr(cli)); 3456 return 1; 3457 } 3458 3459 status = cli_set_ea_path(targetcli, targetname, eaname, eavalue, 3460 strlen(eavalue)); 3461 if (!NT_STATUS_IS_OK(status)) { 3462 d_printf("set_ea %s: %s\n", src, nt_errstr(status)); 3463 return 1; 3464 } 3465 3466 return 0; 3467 } 3468 3142 3469 /**************************************************************************** 3143 3470 UNIX stat. … … 3356 3683 uint32 serial_num; 3357 3684 time_t create_date; 3358 3359 if (!cli_get_fs_volume_info(cli, volname, &serial_num, &create_date)) { 3360 d_printf("Errr %s getting volume info\n",cli_errstr(cli)); 3685 NTSTATUS status; 3686 3687 status = cli_get_fs_volume_info(cli, volname, &serial_num, 3688 &create_date); 3689 if (!NT_STATUS_IS_OK(status)) { 3690 d_printf("Error %s getting volume info\n", nt_errstr(status)); 3361 3691 return 1; 3362 3692 } … … 3685 4015 uint32_t total_entries = 0; 3686 4016 int i; 4017 struct dcerpc_binding_handle *b; 3687 4018 3688 4019 status = cli_rpc_pipe_open_noauth(cli, &ndr_table_srvsvc.syntax_id, … … 3696 4027 } 3697 4028 4029 b = pipe_hnd->binding_handle; 4030 3698 4031 ZERO_STRUCT(info_ctr); 3699 4032 ZERO_STRUCT(ctr1); … … 3702 4035 info_ctr.ctr.ctr1 = &ctr1; 3703 4036 3704 status = rpccli_srvsvc_NetShareEnumAll(pipe_hnd, frame,4037 status = dcerpc_srvsvc_NetShareEnumAll(b, frame, 3705 4038 pipe_hnd->desthost, 3706 4039 &info_ctr, … … 3819 4152 TALLOC_CTX *ctx = talloc_tos(); 3820 4153 char *l_username, *l_password; 4154 NTSTATUS nt_status; 3821 4155 3822 4156 if (!next_token_talloc(ctx, &cmd_ptr,&l_username,NULL)) { … … 3835 4169 } 3836 4170 3837 if (!NT_STATUS_IS_OK(cli_session_setup(cli, l_username, 3838 l_password, strlen(l_password), 3839 l_password, strlen(l_password), 3840 lp_workgroup()))) { 3841 d_printf("session setup failed: %s\n", cli_errstr(cli)); 4171 nt_status = cli_session_setup(cli, l_username, 4172 l_password, strlen(l_password), 4173 l_password, strlen(l_password), 4174 lp_workgroup()); 4175 if (!NT_STATUS_IS_OK(nt_status)) { 4176 d_printf("session setup failed: %s\n", nt_errstr(nt_status)); 3842 4177 return -1; 3843 4178 } … … 3919 4254 } 3920 4255 4256 /**************************************************************************** 4257 history 4258 ****************************************************************************/ 4259 static int cmd_history(void) 4260 { 4261 #if defined(HAVE_LIBREADLINE) && defined(HAVE_HISTORY_LIST) 4262 HIST_ENTRY **hlist; 4263 int i; 4264 4265 hlist = history_list(); 4266 4267 for (i = 0; hlist && hlist[i]; i++) { 4268 DEBUG(0, ("%d: %s\n", i, hlist[i]->line)); 4269 } 4270 #else 4271 DEBUG(0,("no history without readline support\n")); 4272 #endif 4273 4274 return 0; 4275 } 3921 4276 3922 4277 /* Some constants for completing filename arguments */ … … 3956 4311 {"get",cmd_get,"<remote name> [local name] get a file",{COMPL_REMOTE,COMPL_LOCAL}}, 3957 4312 {"getfacl",cmd_getfacl,"<file name> get the POSIX ACL on a file (UNIX extensions only)",{COMPL_REMOTE,COMPL_LOCAL}}, 4313 {"geteas", cmd_geteas, "<file name> get the EA list of a file", 4314 {COMPL_REMOTE, COMPL_LOCAL}}, 3958 4315 {"hardlink",cmd_hardlink,"<src> <dest> create a Windows hard link",{COMPL_REMOTE,COMPL_REMOTE}}, 3959 4316 {"help",cmd_help,"[command] give help on a command",{COMPL_NONE,COMPL_NONE}}, … … 3996 4353 {"rmdir",cmd_rmdir,"<directory> remove a directory",{COMPL_NONE,COMPL_NONE}}, 3997 4354 {"showacls",cmd_showacls,"toggle if ACLs are shown or not",{COMPL_NONE,COMPL_NONE}}, 4355 {"setea", cmd_setea, "<file name> <eaname> <eaval> Set an EA of a file", 4356 {COMPL_REMOTE, COMPL_LOCAL}}, 3998 4357 {"setmode",cmd_setmode,"filename <setmode string> change modes of file",{COMPL_REMOTE,COMPL_NONE}}, 3999 4358 {"stat",cmd_stat,"filename Do a UNIX extensions stat call on a file",{COMPL_REMOTE,COMPL_REMOTE}}, … … 4134 4493 #define MAX_COMPLETIONS 100 4135 4494 4136 typedef struct{4495 struct completion_remote { 4137 4496 char *dirmask; 4138 4497 char **matches; … … 4140 4499 const char *text; 4141 4500 int len; 4142 } completion_remote_t;4143 4144 static voidcompletion_remote_filter(const char *mnt,4145 file_info *f,4501 }; 4502 4503 static NTSTATUS completion_remote_filter(const char *mnt, 4504 struct file_info *f, 4146 4505 const char *mask, 4147 4506 void *state) 4148 4507 { 4149 completion_remote_t *info = (completion_remote_t *)state; 4150 4151 if ((info->count < MAX_COMPLETIONS - 1) && 4152 (strncmp(info->text, f->name, info->len) == 0) && 4153 (strcmp(f->name, ".") != 0) && 4154 (strcmp(f->name, "..") != 0)) { 4155 if ((info->dirmask[0] == 0) && !(f->mode & aDIR)) 4156 info->matches[info->count] = SMB_STRDUP(f->name); 4157 else { 4158 TALLOC_CTX *ctx = talloc_stackframe(); 4159 char *tmp; 4160 4161 tmp = talloc_strdup(ctx,info->dirmask); 4162 if (!tmp) { 4163 TALLOC_FREE(ctx); 4164 return; 4165 } 4166 tmp = talloc_asprintf_append(tmp, "%s", f->name); 4167 if (!tmp) { 4168 TALLOC_FREE(ctx); 4169 return; 4170 } 4171 if (f->mode & aDIR) { 4172 tmp = talloc_asprintf_append(tmp, "%s", CLI_DIRSEP_STR); 4173 } 4174 if (!tmp) { 4175 TALLOC_FREE(ctx); 4176 return; 4177 } 4178 info->matches[info->count] = SMB_STRDUP(tmp); 4508 struct completion_remote *info = (struct completion_remote *)state; 4509 4510 if (info->count >= MAX_COMPLETIONS - 1) { 4511 return NT_STATUS_OK; 4512 } 4513 if (strncmp(info->text, f->name, info->len) != 0) { 4514 return NT_STATUS_OK; 4515 } 4516 if (ISDOT(f->name) || ISDOTDOT(f->name)) { 4517 return NT_STATUS_OK; 4518 } 4519 4520 if ((info->dirmask[0] == 0) && !(f->mode & FILE_ATTRIBUTE_DIRECTORY)) 4521 info->matches[info->count] = SMB_STRDUP(f->name); 4522 else { 4523 TALLOC_CTX *ctx = talloc_stackframe(); 4524 char *tmp; 4525 4526 tmp = talloc_strdup(ctx,info->dirmask); 4527 if (!tmp) { 4179 4528 TALLOC_FREE(ctx); 4180 } 4181 if (info->matches[info->count] == NULL) { 4182 return; 4183 } 4184 if (f->mode & aDIR) { 4185 smb_readline_ca_char(0); 4186 } 4187 if (info->count == 1) { 4188 info->samelen = strlen(info->matches[info->count]); 4189 } else { 4190 while (strncmp(info->matches[info->count], 4191 info->matches[info->count-1], 4192 info->samelen) != 0) { 4193 info->samelen--; 4194 } 4195 } 4196 info->count++; 4197 } 4529 return NT_STATUS_NO_MEMORY; 4530 } 4531 tmp = talloc_asprintf_append(tmp, "%s", f->name); 4532 if (!tmp) { 4533 TALLOC_FREE(ctx); 4534 return NT_STATUS_NO_MEMORY; 4535 } 4536 if (f->mode & FILE_ATTRIBUTE_DIRECTORY) { 4537 tmp = talloc_asprintf_append(tmp, "%s", 4538 CLI_DIRSEP_STR); 4539 } 4540 if (!tmp) { 4541 TALLOC_FREE(ctx); 4542 return NT_STATUS_NO_MEMORY; 4543 } 4544 info->matches[info->count] = SMB_STRDUP(tmp); 4545 TALLOC_FREE(ctx); 4546 } 4547 if (info->matches[info->count] == NULL) { 4548 return NT_STATUS_OK; 4549 } 4550 if (f->mode & FILE_ATTRIBUTE_DIRECTORY) { 4551 smb_readline_ca_char(0); 4552 } 4553 if (info->count == 1) { 4554 info->samelen = strlen(info->matches[info->count]); 4555 } else { 4556 while (strncmp(info->matches[info->count], 4557 info->matches[info->count-1], 4558 info->samelen) != 0) { 4559 info->samelen--; 4560 } 4561 } 4562 info->count++; 4563 return NT_STATUS_OK; 4198 4564 } 4199 4565 … … 4205 4571 struct cli_state *targetcli = NULL; 4206 4572 int i; 4207 completion_remote_t info = { NULL, NULL, 1, 0, NULL, 0 }; 4208 4209 /* can't have non-static intialisation on Sun CC, so do it 4573 struct completion_remote info = { NULL, NULL, 1, 0, NULL, 0 }; 4574 NTSTATUS status; 4575 4576 /* can't have non-static initialisation on Sun CC, so do it 4210 4577 at run time here */ 4211 4578 info.samelen = len; … … 4264 4631 goto cleanup; 4265 4632 } 4266 if (cli_list(targetcli, targetpath, aDIR | aSYSTEM | aHIDDEN, 4267 completion_remote_filter, (void *)&info) < 0) { 4633 status = cli_list(targetcli, targetpath, FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN, 4634 completion_remote_filter, (void *)&info); 4635 if (!NT_STATUS_IS_OK(status)) { 4268 4636 goto cleanup; 4269 4637 } … … 4407 4775 static void readline_callback(void) 4408 4776 { 4409 fd_set fds;4410 struct timeval timeout;4411 4777 static time_t last_t; 4778 struct timespec now; 4412 4779 time_t t; 4413 4414 t = time(NULL); 4780 int ret, revents; 4781 4782 clock_gettime_mono(&now); 4783 t = now.tv_sec; 4415 4784 4416 4785 if (t - last_t < 5) … … 4421 4790 again: 4422 4791 4423 if (cli->fd < 0 || cli->fd >= FD_SETSIZE) { 4424 errno = EBADF; 4792 if (cli->fd == -1) 4425 4793 return; 4426 }4427 4428 FD_ZERO(&fds);4429 FD_SET(cli->fd,&fds);4430 4431 timeout.tv_sec = 0;4432 timeout.tv_usec = 0;4433 sys_select_intr(cli->fd+1,&fds,NULL,NULL,&timeout);4434 4794 4435 4795 /* We deliberately use receive_smb_raw instead of … … 4437 4797 session keepalives and then drop them here. 4438 4798 */ 4439 if (FD_ISSET(cli->fd,&fds)) { 4799 4800 ret = poll_intr_one_fd(cli->fd, POLLIN|POLLHUP, 0, &revents); 4801 4802 if ((ret > 0) && (revents & (POLLIN|POLLHUP|POLLERR))) { 4440 4803 NTSTATUS status; 4441 4804 size_t len; … … 4591 4954 { 4592 4955 cli = cli_cm_open(talloc_tos(), NULL, 4593 query_host, "IPC$", auth_info, true, smb_encrypt,4956 have_ip ? dest_ss_str : query_host, "IPC$", auth_info, true, smb_encrypt, 4594 4957 max_protocol, port, name_type); 4595 4958 if (!cli) … … 4617 4980 cli_shutdown(cli); 4618 4981 cli = cli_cm_open(talloc_tos(), NULL, 4619 query_host, "IPC$", auth_info, true, smb_encrypt, 4982 have_ip ? dest_ss_str : query_host, "IPC$", 4983 auth_info, true, smb_encrypt, 4620 4984 max_protocol, 139, name_type); 4621 4985 } … … 4771 5135 4772 5136 /* set default debug level to 1 regardless of what smb.conf sets */ 4773 setup_logging( "smbclient", true ); 4774 DEBUGLEVEL_CLASS[DBGC_ALL] = 1; 4775 if ((dbf = x_fdup(x_stderr))) { 4776 x_setbuf( dbf, NULL ); 4777 } 4778 5137 setup_logging( "smbclient", DEBUG_DEFAULT_STDERR ); 4779 5138 load_case_tables(); 5139 5140 lp_set_cmdline("log level", "1"); 4780 5141 4781 5142 auth_info = user_auth_info_init(frame); … … 4844 5205 break; 4845 5206 case 'E': 4846 if (dbf) { 4847 x_fclose(dbf); 4848 } 4849 dbf = x_stderr; 5207 setup_logging("smbclient", DEBUG_STDERR ); 4850 5208 display_set_stderr(); 4851 5209 break; … … 4921 5279 } 4922 5280 4923 /*4924 * Don't load debug level from smb.conf. It should be4925 * set by cmdline arg or remain default (0)4926 */4927 AllowDebugChange = false;4928 4929 5281 /* save the workgroup... 4930 5282 … … 4940 5292 4941 5293 if ( override_logfile ) 4942 setup_logging( lp_logfile(), false);5294 setup_logging( lp_logfile(), DEBUG_FILE ); 4943 5295 4944 5296 if (!lp_load(get_dyn_CONFIGFILE(),true,false,false,true)) {
Note:
See TracChangeset
for help on using the changeset viewer.