Changeset 740 for vendor/current/source3/client
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- Location:
- vendor/current/source3/client
- Files:
-
- 5 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)) { -
vendor/current/source3/client/client_proto.h
r414 r740 24 24 #define _CLIENT_PROTO_H_ 25 25 26 struct cli_state; 27 struct file_info; 26 28 27 29 /* The following definitions come from client/client.c */ … … 29 31 const char *client_get_cur_dir(void); 30 32 const char *client_set_cur_dir(const char *newdir); 31 voiddo_list(const char *mask,33 NTSTATUS do_list(const char *mask, 32 34 uint16 attribute, 33 void (*fn)(file_info *, const char *dir), 35 NTSTATUS (*fn)(struct cli_state *cli_state, struct file_info *, 36 const char *dir), 34 37 bool rec, 35 38 bool dirs); -
vendor/current/source3/client/clitar.c
r414 r740 36 36 37 37 #include "includes.h" 38 #include "system/filesys.h" 38 39 #include "clitar.h" 39 40 #include "client/client_proto.h" 41 #include "libsmb/libsmb.h" 40 42 41 43 static int clipfind(char **aret, int ret, char *tok); … … 70 72 #define ATTRRESET 0 71 73 72 static uint16 attribute = aDIR | aSYSTEM | aHIDDEN;74 static uint16 attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN; 73 75 74 76 #ifndef CLIENT_TIMEOUT … … 115 117 static void writetarheader(int f, const char *aname, uint64_t size, time_t mtime, 116 118 const char *amode, unsigned char ftype); 117 static void do_atar(const char *rname_in,char *lname,file_info *finfo1); 118 static void do_tar(file_info *finfo, const char *dir); 119 static NTSTATUS do_atar(const char *rname_in, char *lname, 120 struct file_info *finfo1); 121 static NTSTATUS do_tar(struct cli_state *cli_state, struct file_info *finfo, 122 const char *dir); 119 123 static void oct_it(uint64_t value, int ndgs, char *p); 120 124 static void fixtarname(char *tptr, const char *fp, size_t l); … … 292 296 if ((unoct(hb->dbuf.mode, sizeof(hb->dbuf.mode)) & S_IFDIR) || 293 297 (*(finfo->name+strlen(finfo->name)-1) == '\\')) { 294 finfo->mode= aDIR;298 finfo->mode=FILE_ATTRIBUTE_DIRECTORY; 295 299 } else { 296 300 finfo->mode=0; /* we don't care about mode at the moment, we'll … … 487 491 char *s1_0=s1; 488 492 489 while(*s1 && *s2 && (*s1 == *s2 || tolower_ ascii(*s1) == tolower_ascii(*s2) ||493 while(*s1 && *s2 && (*s1 == *s2 || tolower_m(*s1) == tolower_m(*s2) || 490 494 (*s1 == '\\' && *s2=='/') || (*s1 == '/' && *s2=='\\'))) { 491 495 s1++; s2++; … … 614 618 ***************************************************************************/ 615 619 616 static void do_atar(const char *rname_in,char *lname,file_info *finfo1) 620 static NTSTATUS do_atar(const char *rname_in, char *lname, 621 struct file_info *finfo1) 617 622 { 618 623 uint16_t fnum = (uint16_t)-1; … … 626 631 char *rname = NULL; 627 632 TALLOC_CTX *ctx = talloc_stackframe(); 628 629 struct time valtp_start;630 631 GetTimeOfDay(&tp_start);633 NTSTATUS status = NT_STATUS_OK; 634 struct timespec tp_start; 635 636 clock_gettime_mono(&tp_start); 632 637 633 638 data = SMB_MALLOC_ARRAY(char, read_size); 634 639 if (!data) { 635 640 DEBUG(0,("do_atar: out of memory.\n")); 641 status = NT_STATUS_NO_MEMORY; 636 642 goto cleanup; 637 643 } … … 660 666 rname = clean_name(ctx, rname_in); 661 667 if (!rname) { 668 status = NT_STATUS_NO_MEMORY; 662 669 goto cleanup; 663 670 } 664 671 665 if (!NT_STATUS_IS_OK(cli_open(cli, rname, O_RDONLY, DENY_NONE, &fnum))) { 672 status = cli_open(cli, rname, O_RDONLY, DENY_NONE, &fnum); 673 if (!NT_STATUS_IS_OK(status)) { 666 674 DEBUG(0,("%s opening remote file %s (%s)\n", 667 675 cli_errstr(cli),rname, client_get_cur_dir())); … … 672 680 if (finfo.name == NULL) { 673 681 DEBUG(0, ("Unable to allocate space for finfo.name in do_atar\n")); 682 status = NT_STATUS_NO_MEMORY; 674 683 goto cleanup; 675 684 } … … 679 688 DEBUG(3,("file %s attrib 0x%X\n",finfo.name,finfo.mode)); 680 689 681 if (tar_inc && !(finfo.mode & aARCH)) {690 if (tar_inc && !(finfo.mode & FILE_ATTRIBUTE_ARCHIVE)) { 682 691 DEBUG(4, ("skipping %s - archive bit not set\n", finfo.name)); 683 692 shallitime=0; 684 } else if (!tar_system && (finfo.mode & aSYSTEM)) {693 } else if (!tar_system && (finfo.mode & FILE_ATTRIBUTE_SYSTEM)) { 685 694 DEBUG(4, ("skipping %s - system bit is set\n", finfo.name)); 686 695 shallitime=0; 687 } else if (!tar_hidden && (finfo.mode & aHIDDEN)) {696 } else if (!tar_hidden && (finfo.mode & FILE_ATTRIBUTE_HIDDEN)) { 688 697 DEBUG(4, ("skipping %s - hidden bit is set\n", finfo.name)); 689 698 shallitime=0; … … 702 711 if (datalen == -1) { 703 712 DEBUG(0,("Error reading file %s : %s\n", rname, cli_errstr(cli))); 713 status = cli_nt_error(cli); 704 714 break; 705 715 } … … 730 740 if (dotarbuf(tarhandle,data,datalen) != datalen) { 731 741 DEBUG(0,("Error writing to tar file - %s\n", strerror(errno))); 742 status = map_nt_error_from_unix(errno); 732 743 break; 733 744 } 734 745 735 746 if ( (datalen == 0) && (finfo.size != 0) ) { 747 status = NT_STATUS_UNSUCCESSFUL; 736 748 DEBUG(0,("Error reading file %s. Got 0 bytes\n", rname)); 737 749 break; … … 746 758 DEBUG(0, ("Didn't get entire file. size=%.0f, nread=%d\n", 747 759 (double)finfo.size, (int)nread)); 748 if (padit(data, (uint64_t)sizeof(data), finfo.size - nread)) 760 if (padit(data, (uint64_t)sizeof(data), finfo.size - nread)) { 761 status = map_nt_error_from_unix(errno); 749 762 DEBUG(0,("Error writing tar file - %s\n", strerror(errno))); 763 } 750 764 } 751 765 … … 759 773 DEBUG(4, ("skipping %s - initial read failed (file was locked ?)\n", finfo.name)); 760 774 shallitime=0; 775 status = NT_STATUS_UNSUCCESSFUL; 761 776 } 762 777 } … … 766 781 767 782 if (shallitime) { 768 struct time valtp_end;783 struct timespec tp_end; 769 784 int this_time; 770 785 771 786 /* if shallitime is true then we didn't skip */ 772 787 if (tar_reset && !dry_run) 773 (void) do_setrattr(finfo.name, aARCH, ATTRRESET);774 775 GetTimeOfDay(&tp_end);776 this_time = (tp_end.tv_sec - tp_start.tv_sec)*1000 + (tp_end.tv_ usec - tp_start.tv_usec)/1000;788 (void) do_setrattr(finfo.name, FILE_ATTRIBUTE_ARCHIVE, ATTRRESET); 789 790 clock_gettime_mono(&tp_end); 791 this_time = (tp_end.tv_sec - tp_start.tv_sec)*1000 + (tp_end.tv_nsec - tp_start.tv_nsec)/1000000; 777 792 get_total_time_ms += this_time; 778 793 get_total_size += finfo.size; … … 798 813 TALLOC_FREE(ctx); 799 814 SAFE_FREE(data); 815 return status; 800 816 } 801 817 … … 804 820 ***************************************************************************/ 805 821 806 static void do_tar(file_info *finfo, const char *dir) 822 static NTSTATUS do_tar(struct cli_state *cli_state, struct file_info *finfo, 823 const char *dir) 807 824 { 808 825 TALLOC_CTX *ctx = talloc_stackframe(); 826 NTSTATUS status = NT_STATUS_OK; 809 827 810 828 if (strequal(finfo->name,"..") || strequal(finfo->name,".")) 811 return ;829 return NT_STATUS_OK; 812 830 813 831 /* Is it on the exclude list ? */ … … 822 840 finfo->name); 823 841 if (!exclaim) { 824 return ;842 return NT_STATUS_NO_MEMORY; 825 843 } 826 844 … … 831 849 DEBUG(3,("Skipping file %s\n", exclaim)); 832 850 TALLOC_FREE(exclaim); 833 return ;851 return NT_STATUS_OK; 834 852 } 835 853 TALLOC_FREE(exclaim); 836 854 } 837 855 838 if (finfo->mode & aDIR) {856 if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) { 839 857 char *saved_curdir = NULL; 840 858 char *new_cd = NULL; … … 843 861 saved_curdir = talloc_strdup(ctx, client_get_cur_dir()); 844 862 if (!saved_curdir) { 845 return ;863 return NT_STATUS_NO_MEMORY; 846 864 } 847 865 … … 856 874 finfo->name); 857 875 if (!new_cd) { 858 return ;876 return NT_STATUS_NO_MEMORY; 859 877 } 860 878 client_set_cur_dir(new_cd); … … 875 893 client_get_cur_dir()); 876 894 if (!mtar_mask) { 877 return ;895 return NT_STATUS_NO_MEMORY; 878 896 } 879 897 DEBUG(5, ("Doing list with mtar_mask: %s\n", mtar_mask)); 880 do_list(mtar_mask, attribute, do_tar, False, True);898 status = do_list(mtar_mask, attribute, do_tar, False, True); 881 899 client_set_cur_dir(saved_curdir); 882 900 TALLOC_FREE(saved_curdir); … … 889 907 finfo->name); 890 908 if (!rname) { 891 return ;892 } 893 do_atar(rname,finfo->name,finfo);909 return NT_STATUS_NO_MEMORY; 910 } 911 status = do_atar(rname,finfo->name,finfo); 894 912 TALLOC_FREE(rname); 895 913 } 914 return status; 896 915 } 897 916 … … 999 1018 static int get_file(file_info2 finfo) 1000 1019 { 1001 uint16_t fnum ;1020 uint16_t fnum = (uint16_t) -1; 1002 1021 int pos = 0, dsize = 0, bpos = 0; 1003 1022 uint64_t rsize = 0; 1023 NTSTATUS status; 1004 1024 1005 1025 DEBUG(5, ("get_file: file: %s, size %.0f\n", finfo.name, (double)finfo.size)); 1006 1026 1007 if (ensurepath(finfo.name) && 1008 (!NT_STATUS_IS_OK(cli_open(cli, finfo.name, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE,&fnum)))) { 1027 if (!ensurepath(finfo.name)) { 1009 1028 DEBUG(0, ("abandoning restore\n")); 1010 return(False); 1029 return False; 1030 } 1031 1032 status = cli_open(cli, finfo.name, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE, &fnum); 1033 if (!NT_STATUS_IS_OK(status)) { 1034 DEBUG(0, ("abandoning restore\n")); 1035 return False; 1011 1036 } 1012 1037 … … 1022 1047 DEBUG(5, ("writing %i bytes, bpos = %i ...\n", dsize, bpos)); 1023 1048 1024 if (cli_write(cli, fnum, 0, buffer_p + bpos, pos, dsize) != dsize) { 1025 DEBUG(0, ("Error writing remote file\n")); 1049 status = cli_writeall(cli, fnum, 0, 1050 (uint8_t *)(buffer_p + bpos), pos, 1051 dsize, NULL); 1052 if (!NT_STATUS_IS_OK(status)) { 1053 DEBUG(0, ("Error writing remote file: %s\n", 1054 nt_errstr(status))); 1026 1055 return 0; 1027 1056 } … … 1156 1185 { 1157 1186 file_info2 finfo; 1158 struct time valtp_start;1187 struct timespec tp_start; 1159 1188 char *longfilename = NULL, linkflag; 1160 1189 int skip = False; … … 1162 1191 ZERO_STRUCT(finfo); 1163 1192 1164 GetTimeOfDay(&tp_start);1193 clock_gettime_mono(&tp_start); 1165 1194 DEBUG(5, ("RJS do_tarput called ...\n")); 1166 1195 … … 1184 1213 if ((next_block(tarbuf, &buffer_p, tbufsiz) <= 0) && !skip_file(finfo.size)) { 1185 1214 DEBUG(0, ("Short file, bailing out...\n")); 1215 SAFE_FREE(longfilename); 1186 1216 return; 1187 1217 } … … 1190 1220 case -1: 1191 1221 DEBUG(0, ("abandoning restore, -1 from read tar header\n")); 1222 SAFE_FREE(longfilename); 1192 1223 return; 1193 1224 1194 1225 case 0: /* chksum is zero - looks like an EOF */ 1195 1226 DEBUG(0, ("tar: restored %d files and directories\n", ntarf)); 1227 SAFE_FREE(longfilename); 1196 1228 return; /* Hmmm, bad here ... */ 1197 1229 … … 1375 1407 break; 1376 1408 case 'r': 1377 attra[direct]|= aRONLY;1409 attra[direct]|=FILE_ATTRIBUTE_READONLY; 1378 1410 break; 1379 1411 case 'h': 1380 attra[direct]|= aHIDDEN;1412 attra[direct]|=FILE_ATTRIBUTE_HIDDEN; 1381 1413 break; 1382 1414 case 's': 1383 attra[direct]|= aSYSTEM;1415 attra[direct]|=FILE_ATTRIBUTE_SYSTEM; 1384 1416 break; 1385 1417 case 'a': 1386 attra[direct]|= aARCH;1418 attra[direct]|=FILE_ATTRIBUTE_ARCHIVE; 1387 1419 break; 1388 1420 default: … … 1924 1956 */ 1925 1957 if (tarhandle == 1) { 1926 dbf = x_stderr;1958 setup_logging("smbclient", DEBUG_STDERR); 1927 1959 } 1928 1960 if (!argv[Optind]) { -
vendor/current/source3/client/dnsbrowse.c
r591 r740 24 24 25 25 #include <dns_sd.h> 26 #include "system/select.h" 26 27 27 28 /* Holds service instances found during DNS browse */ … … 61 62 int fdsetsz; 62 63 int ret; 63 fd_set *fdset = NULL;64 64 struct timeval tv; 65 65 DNSServiceErrorType err; … … 78 78 mdnsfd = DNSServiceRefSockFD(mdns_conn_sdref); 79 79 for (;;) { 80 if (fdset != NULL) { 81 TALLOC_FREE(fdset); 82 } 83 84 if (mdnsfd < 0 || mdnsfd >= FD_SETSIZE) { 85 errno = EBADF; 86 break; 87 } 88 89 fdsetsz = howmany(mdnsfd + 1, NFDBITS) * sizeof(fd_mask); 90 fdset = TALLOC_ZERO(ctx, fdsetsz); 91 FD_SET(mdnsfd, fdset); 92 93 tv.tv_sec = 1; 94 tv.tv_usec = 0; 95 96 /* Wait until response received from mDNS daemon */ 97 ret = sys_select(mdnsfd + 1, fdset, NULL, NULL, &tv); 80 int revents; 81 82 ret = poll_one_fd(mdnsfd, POLLIN|POLLHUP, 1000, &revents); 98 83 if (ret <= 0 && errno != EINTR) { 99 84 break; 100 85 } 101 86 102 if ( FD_ISSET(mdnsfd, fdset)) {87 if (revents & (POLLIN|POLLHUP|POLLERR)) { 103 88 /* Invoke callback function */ 104 89 DNSServiceProcessResult(mdns_conn_sdref); … … 161 146 int fdsetsz; 162 147 int ret; 163 fd_set *fdset = NULL;164 148 struct mdns_browse_state bstate; 165 149 struct mdns_smbsrv_result *resptr; … … 183 167 mdnsfd = DNSServiceRefSockFD(mdns_conn_sdref); 184 168 for (;;) { 185 if (fdset != NULL) { 186 TALLOC_FREE(fdset); 187 } 188 189 if (mdnsfd < 0 || mdnsfd >= FD_SETSIZE) { 190 errno = EBADF; 191 TALLOC_FREE(ctx); 192 return 1; 193 } 194 195 fdsetsz = howmany(mdnsfd + 1, NFDBITS) * sizeof(fd_mask); 196 fdset = TALLOC_ZERO(ctx, fdsetsz); 197 FD_SET(mdnsfd, fdset); 198 199 tv.tv_sec = 1; 200 tv.tv_usec = 0; 201 202 /* Wait until response received from mDNS daemon */ 203 ret = sys_select(mdnsfd + 1, fdset, NULL, NULL, &tv); 169 int revents; 170 171 ret = poll_one_fd(mdnsfd, POLLIN|POLLHUP, &revents, 1000); 204 172 if (ret <= 0 && errno != EINTR) { 205 173 break; 206 174 } 207 175 208 if ( FD_ISSET(mdnsfd, fdset)) {176 if (revents & (POLLIN|POLLHUP|POLLERR)) { 209 177 /* Invoke callback function */ 210 178 if (DNSServiceProcessResult(mdns_conn_sdref)) { -
vendor/current/source3/client/smbspool.c
r414 r740 24 24 25 25 #include "includes.h" 26 #include "system/filesys.h" 27 #include "system/passwd.h" 28 #include "libsmb/libsmb.h" 26 29 27 30 /* … … 241 244 */ 242 245 243 setup_logging("smbspool", True);246 setup_logging("smbspool", DEBUG_STDOUT); 244 247 245 248 lp_set_in_client(True); /* Make sure that we tell lp_load we are */ … … 402 405 *need_auth = false; 403 406 nt_status = cli_start_connection(&cli, myname, server, NULL, port, 404 Undefined, flags , NULL);407 Undefined, flags); 405 408 if (!NT_STATUS_IS_OK(nt_status)) { 406 409 fprintf(stderr, "ERROR: Connection failed: %s\n", nt_errstr(nt_status)); … … 559 562 char buffer[8192], /* Buffer for copy */ 560 563 *ptr; /* Pointer into title */ 564 NTSTATUS nt_status; 561 565 562 566 … … 575 579 */ 576 580 577 if (!NT_STATUS_IS_OK(cli_open(cli, title, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum))) { 581 nt_status = cli_open(cli, title, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, 582 &fnum); 583 if (!NT_STATUS_IS_OK(nt_status)) { 578 584 fprintf(stderr, "ERROR: %s opening remote spool %s\n", 579 cli_errstr(cli), title);580 return (get_exit_code(cli, cli_nt_error(cli)));585 nt_errstr(nt_status), title); 586 return get_exit_code(cli, nt_status); 581 587 } 582 588 … … 591 597 592 598 while ((nbytes = fread(buffer, 1, sizeof(buffer), fp)) > 0) { 593 if (cli_write(cli, fnum, 0, buffer, tbytes, nbytes) != nbytes) { 594 int status = get_exit_code(cli, cli_nt_error(cli)); 595 596 fprintf(stderr, "ERROR: Error writing spool: %s\n", cli_errstr(cli)); 597 fprintf(stderr, "DEBUG: Returning status %d...\n", status); 599 NTSTATUS status; 600 601 status = cli_writeall(cli, fnum, 0, (uint8_t *)buffer, 602 tbytes, nbytes, NULL); 603 if (!NT_STATUS_IS_OK(status)) { 604 int ret = get_exit_code(cli, status); 605 fprintf(stderr, "ERROR: Error writing spool: %s\n", 606 nt_errstr(status)); 607 fprintf(stderr, "DEBUG: Returning status %d...\n", 608 ret); 598 609 cli_close(cli, fnum); 599 610 600 return ( status);611 return (ret); 601 612 } 602 613 tbytes += nbytes; 603 614 } 604 615 605 if (!NT_STATUS_IS_OK(cli_close(cli, fnum))) { 616 nt_status = cli_close(cli, fnum); 617 if (!NT_STATUS_IS_OK(nt_status)) { 606 618 fprintf(stderr, "ERROR: %s closing remote spool %s\n", 607 cli_errstr(cli), title);608 return (get_exit_code(cli, cli_nt_error(cli)));619 nt_errstr(nt_status), title); 620 return get_exit_code(cli, nt_status); 609 621 } else { 610 622 return (0);
Note:
See TracChangeset
for help on using the changeset viewer.