Changeset 740 for vendor/current/source3/client/clitar.c
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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]) {
Note:
See TracChangeset
for help on using the changeset viewer.