34 #include <gwenhywfar/misc.h>
35 #include <gwenhywfar/debug.h>
36 #include <gwenhywfar/tlv.h>
37 #include <gwenhywfar/gui.h>
38 #include <gwenhywfar/text.h>
39 #include <gwenhywfar/cryptmgrkeys.h>
41 #include <sys/types.h>
56 sr->headers=GWEN_SarFileHeader_List_new();
74 if (sr->refCount==1) {
75 free(sr->archiveName);
76 GWEN_SarFileHeader_List_free(sr->headers);
97 if (sr->openMode!=GWEN_Sar_OpenMode_Closed) {
102 free(sr->archiveName);
103 sr->archiveName=strdup(aname);
120 sr->openMode=GWEN_Sar_OpenMode_Created;
137 assert(sr->refCount);
140 if (sr->openMode!=GWEN_Sar_OpenMode_Closed) {
145 free(sr->archiveName);
146 sr->archiveName=strdup(aname);
157 sr->openMode=GWEN_Sar_OpenMode_Opened;
166 sr->openMode=GWEN_Sar_OpenMode_Closed;
180 assert(sr->refCount);
182 if (sr->openMode!=GWEN_Sar_OpenMode_Opened &&
183 sr->openMode!=GWEN_Sar_OpenMode_Created) {
196 free(sr->archiveName);
197 sr->archiveName=
NULL;
198 sr->openMode=GWEN_Sar_OpenMode_Closed;
209 free(sr->archiveName);
210 sr->archiveName=
NULL;
211 sr->openMode=GWEN_Sar_OpenMode_Closed;
217 free(sr->archiveName);
218 sr->archiveName=
NULL;
219 sr->openMode=GWEN_Sar_OpenMode_Closed;
235 v32=GWEN_SAR_HEADER_VERSION;
236 hbuf[0]=(v32>>24) & 0xff;
237 hbuf[1]=(v32>>16) & 0xff;
238 hbuf[2]=(v32>>8) & 0xff;
249 hbuf[0]=(v32>>24) & 0xff;
250 hbuf[1]=(v32>>16) & 0xff;
251 hbuf[2]=(v32>>8) & 0xff;
267 hbuf[0]=(v32>>24) & 0xff;
268 hbuf[1]=(v32>>16) & 0xff;
269 hbuf[2]=(v32>>8) & 0xff;
323 hbuf[0]=(v64>>56) & 0xff;
324 hbuf[1]=(v64>>48) & 0xff;
325 hbuf[2]=(v64>>40) & 0xff;
326 hbuf[3]=(v64>>32) & 0xff;
327 hbuf[4]=(v64>>24) & 0xff;
328 hbuf[5]=(v64>>16) & 0xff;
329 hbuf[6]=(v64>>8) & 0xff;
343 v=(((uint64_t)(p[0]))<<56)+
344 (((uint64_t)(p[1]))<<48)+
345 (((uint64_t)(p[2]))<<40)+
346 (((uint64_t)(p[3]))<<32)+
347 (((uint64_t)(p[4]))<<24)+
348 (((uint64_t)(p[5]))<<16)+
349 (((uint64_t)(p[6]))<<8)+
353 v=(((uint64_t)(p[0]))<<48)+
354 (((uint64_t)(p[1]))<<40)+
355 (((uint64_t)(p[2]))<<32)+
356 (((uint64_t)(p[3]))<<24)+
357 (((uint64_t)(p[4]))<<16)+
358 (((uint64_t)(p[5]))<<8)+
362 v=(((uint64_t)(p[0]))<<40)+
363 (((uint64_t)(p[1]))<<32)+
364 (((uint64_t)(p[2]))<<24)+
365 (((uint64_t)(p[3]))<<16)+
366 (((uint64_t)(p[4]))<<8)+
370 v=(((uint64_t)(p[0]))<<32)+
371 (((uint64_t)(p[1]))<<24)+
372 (((uint64_t)(p[2]))<<16)+
373 (((uint64_t)(p[3]))<<8)+
377 v=(((uint64_t)(p[0]))<<24)+
378 (((uint64_t)(p[1]))<<16)+
379 (((uint64_t)(p[2]))<<8)+
383 v=(((uint64_t)(p[0]))<<16)+
384 (((uint64_t)(p[1]))<<8)+
388 v=(((uint64_t)(p[0]))<<8)+
392 v=((uint64_t)(p[0]));
419 case GWEN_SAR_TAG_HEADER_VERSION:
424 case GWEN_SAR_TAG_HEADER_STATUS:
429 case GWEN_SAR_TAG_HEADER_FLAGS:
434 case GWEN_SAR_TAG_HEADER_PATH:
438 case GWEN_SAR_TAG_HEADER_TYPE:
443 case GWEN_SAR_TAG_HEADER_PERM:
448 case GWEN_SAR_TAG_HEADER_ATIME:
453 case GWEN_SAR_TAG_HEADER_MTIME:
458 case GWEN_SAR_TAG_HEADER_CTIME:
463 case GWEN_SAR_TAG_HEADER_SIZE:
491 assert(sr->refCount);
537 I18N(
"File Operation"),
538 I18N(
"Copying file into archive"),
583 (
unsigned long int)bs, (
unsigned long int) fsize);
617 #if _BSD_SOURCE || _XOPEN_SOURCE >= 500 || (_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) || _POSIX_C_SOURCE >= 200112L || defined(OS_DARWIN)
625 assert(sr->refCount);
631 rv=readlink(fname, lbuf,
sizeof(lbuf)-1);
634 fname, errno, strerror(errno));
667 # warning "Function readlink() is not available"
714 assert(sr->refCount);
717 #if _BSD_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
718 rv=lstat(fname, &st);
724 fname, errno, strerror(errno));
735 switch(st.st_mode & S_IFMT) {
921 assert(sr->refCount);
930 int64_t startOfTagHeader;
931 int64_t startOfTagData;
932 unsigned int tagType;
934 uint32_t fullTagSize;
939 startOfTagHeader=pos;
964 startOfTagData=pos+rv;
979 if (tagType==GWEN_SAR_TAG_HEADER) {
1013 GWEN_SarFileHeader_List_Add(fh, sr->headers);
1016 else if (tagType==GWEN_SAR_TAG_FILE) {
1017 if (lastHeader==
NULL) {
1027 (
unsigned long int) tagLength);
1043 else if (tagType==GWEN_SAR_TAG_HASH) {
1044 if (lastHeader==
NULL) {
1060 else if (tagType==GWEN_SAR_TAG_SIGNATURE) {
1063 sr->signaturePos=startOfTagData;
1064 sr->signatureSize=tagLength;
1086 pos=startOfTagData+tagLength;
1110 assert(sr->refCount);
1200 I18N(
"File Operation"),
1201 I18N(
"Extracting file from archive"),
1206 uint8_t fbuf[10240];
1210 if (bs>
sizeof(fbuf))
1257 (
unsigned long int)bs, (
unsigned long int) fsize);
1355 #if _BSD_SOURCE || _XOPEN_SOURCE >= 500 || (_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) || _POSIX_C_SOURCE >= 200112L || defined(OS_DARWIN)
1368 assert(sr->refCount);
1461 fname, errno, strerror(errno));
1498 rv=chmod(fname, mode);
1501 fname, errno, strerror(errno));
1564 # warning "Function symlink() is not available"
1586 assert(sr->refCount);
1723 rv=mkdir(fname, mode);
1729 fname, errno, strerror(errno));
1797 assert(sr->refCount);
1806 const GWEN_SAR_FILEHEADER_LIST *fhl;
1835 I18N(
"File Operation"),
1836 I18N(
"Unpacking archive file"),
1837 GWEN_SarFileHeader_List_GetCount(fhl),
1840 fh=GWEN_SarFileHeader_List_First(fhl);
1862 fh=GWEN_SarFileHeader_List_Next(fh);
1869 fprintf(stderr,
"Error closing archive (%d)\n", rv);
1883 if (getcwd(savedPwd,
sizeof(savedPwd)-1)==
NULL) {
1887 savedPwd[
sizeof(savedPwd)-1]=0;
1895 if (chdir(savedPwd)) {
1907 GWEN_SAR_FILEHEADER_LIST *fhl;
1910 assert(sr->refCount);
1912 if (sr->openMode!=GWEN_Sar_OpenMode_Opened &&
1913 sr->openMode!=GWEN_Sar_OpenMode_Created) {
1918 if (sr->signaturePos!=0 || sr->signatureSize!=0) {
1928 uint8_t hashBuf[21];
1942 fh=GWEN_SarFileHeader_List_First(fhl);
1945 fh=GWEN_SarFileHeader_List_Next(fh);
1953 I18N(
"File Operation"),
1954 I18N(
"Signing archive file"),
1955 GWEN_SarFileHeader_List_GetCount(fhl),
1957 fh=GWEN_SarFileHeader_List_First(fhl);
2007 fh=GWEN_SarFileHeader_List_Next(fh);
2084 GWEN_SAR_FILEHEADER_LIST *fhl;
2087 assert(sr->refCount);
2089 if (sr->openMode!=GWEN_Sar_OpenMode_Opened &&
2090 sr->openMode!=GWEN_Sar_OpenMode_Created) {
2095 if (sr->signaturePos==0 || sr->signatureSize==0) {
2105 uint8_t hashBuf[21];
2119 fh=GWEN_SarFileHeader_List_First(fhl);
2122 fh=GWEN_SarFileHeader_List_Next(fh);
2130 I18N(
"File Operation"),
2131 I18N(
"Signing archive file"),
2132 GWEN_SarFileHeader_List_GetCount(fhl),
2134 fh=GWEN_SarFileHeader_List_First(fhl);
2184 fh=GWEN_SarFileHeader_List_Next(fh);
2357 const GWEN_SAR_FILEHEADER_LIST *fhl;
2378 I18N(
"File Operation"),
2379 I18N(
"Checking archive file"),
2380 GWEN_SarFileHeader_List_GetCount(fhl),
2383 fh=GWEN_SarFileHeader_List_First(fhl);
2405 fh=GWEN_SarFileHeader_List_Next(fh);
2412 fprintf(stderr,
"Error closing archive (%d)\n", rv);