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>
74 if (sr->refCount==1) {
75 free(sr->archiveName);
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(__MINGW32__)) || defined(OS_DARWIN)
626 assert(sr->refCount);
632 rv=readlink(fname, lbuf,
sizeof(lbuf)-1);
635 fname, errno, strerror(errno));
668 # warning "Function readlink() is not available"
715 assert(sr->refCount);
718 #if _BSD_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
719 rv=lstat(fname, &st);
725 fname, errno, strerror(errno));
736 switch(st.st_mode & S_IFMT) {
922 assert(sr->refCount);
931 int64_t startOfTagHeader;
932 int64_t startOfTagData;
933 unsigned int tagType;
935 uint32_t fullTagSize;
940 startOfTagHeader=pos;
965 startOfTagData=pos+rv;
980 if (tagType==GWEN_SAR_TAG_HEADER) {
1017 else if (tagType==GWEN_SAR_TAG_FILE) {
1018 if (lastHeader==
NULL) {
1028 (
unsigned long int) tagLength);
1044 else if (tagType==GWEN_SAR_TAG_HASH) {
1045 if (lastHeader==
NULL) {
1061 else if (tagType==GWEN_SAR_TAG_SIGNATURE) {
1064 sr->signaturePos=startOfTagData;
1065 sr->signatureSize=tagLength;
1087 pos=startOfTagData+tagLength;
1111 assert(sr->refCount);
1201 I18N(
"File Operation"),
1202 I18N(
"Extracting file from archive"),
1207 uint8_t fbuf[10240];
1211 if (bs>
sizeof(fbuf))
1258 (
unsigned long int)bs, (
unsigned long int) fsize);
1356 #if ((_BSD_SOURCE || _XOPEN_SOURCE >= 500 || (_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) || _POSIX_C_SOURCE >= 200112L) && !defined(__MINGW32__)) || defined(OS_DARWIN)
1369 assert(sr->refCount);
1462 fname, errno, strerror(errno));
1499 rv=chmod(fname, mode);
1502 fname, errno, strerror(errno));
1565 # warning "Function symlink() is not available"
1587 assert(sr->refCount);
1724 rv=mkdir(fname, mode);
1730 fname, errno, strerror(errno));
1798 assert(sr->refCount);
1836 I18N(
"File Operation"),
1837 I18N(
"Unpacking archive file"),
1870 fprintf(stderr,
"Error closing archive (%d)\n", rv);
1884 if (getcwd(savedPwd,
sizeof(savedPwd)-1)==
NULL) {
1888 savedPwd[
sizeof(savedPwd)-1]=0;
1896 if (chdir(savedPwd)) {
1911 assert(sr->refCount);
1913 if (sr->openMode!=GWEN_Sar_OpenMode_Opened &&
1914 sr->openMode!=GWEN_Sar_OpenMode_Created) {
1919 if (sr->signaturePos!=0 || sr->signatureSize!=0) {
1929 uint8_t hashBuf[21];
1954 I18N(
"File Operation"),
1955 I18N(
"Signing archive file"),
2088 assert(sr->refCount);
2090 if (sr->openMode!=GWEN_Sar_OpenMode_Opened &&
2091 sr->openMode!=GWEN_Sar_OpenMode_Created) {
2096 if (sr->signaturePos==0 || sr->signatureSize==0) {
2106 uint8_t hashBuf[21];
2131 I18N(
"File Operation"),
2132 I18N(
"Signing archive file"),
2379 I18N(
"File Operation"),
2380 I18N(
"Checking archive file"),
2413 fprintf(stderr,
"Error closing archive (%d)\n", rv);
int GWEN_SyncIo_WriteForced(GWEN_SYNCIO *sio, const uint8_t *buffer, uint32_t size)
uint32_t GWEN_Buffer_GetBytesLeft(GWEN_BUFFER *bf)
int GWEN_Sar_Sign(GWEN_SAR *sr, GWEN_CRYPTMGR *cm)
GWENHYWFAR_API int64_t GWEN_SyncIo_File_Seek(GWEN_SYNCIO *sio, int64_t pos, GWEN_SYNCIO_FILE_WHENCE whence)
struct GWEN_TIME GWEN_TIME
int GWEN_Sar_ExtractAndDigestFileDir(GWEN_SAR *sr, const GWEN_SAR_FILEHEADER *fh, int checkOnly)
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
int GWEN_SyncIo_Connect(GWEN_SYNCIO *sio)
int GWEN_Gui_ProgressAdvance(uint32_t id, uint32_t progress)
int GWEN_Sar_ScanFile(GWEN_SAR *sr)
void GWEN_MDigest_free(GWEN_MDIGEST *md)
int GWEN_CryptMgr_Sign(GWEN_CRYPTMGR *cm, const uint8_t *pData, uint32_t lData, GWEN_BUFFER *dbuf)
int GWEN_Buffer_AllocRoom(GWEN_BUFFER *bf, uint32_t size)
#define GWEN_ERROR_INVALID
int GWEN_Sar_FileHeaderToTlv(const GWEN_SAR_FILEHEADER *fh, GWEN_BUFFER *tbuf)
#define GWEN_SYNCIO_FILE_FLAGS_WRITE
uint32_t GWEN_Buffer_GetUsedBytes(const GWEN_BUFFER *bf)
#define GWEN_GUI_PROGRESS_ALLOW_EMBED
#define GWEN_SYNCIO_FILE_FLAGS_READ
void GWEN_TLV_free(GWEN_TLV *tlv)
#define GWEN_SYNCIO_FILE_FLAGS_GEXEC
GWEN_SAR * GWEN_Sar_new(void)
int GWEN_SyncIo_Read(GWEN_SYNCIO *sio, uint8_t *buffer, uint32_t size)
int GWEN_Sar_AddFile(GWEN_SAR *sr, const char *fname)
int GWEN_Sar_CloseArchive(GWEN_SAR *sr, int abandon)
#define GWEN_FREE_OBJECT(varname)
int GWEN_Sar_UnpackArchive(const char *inFile, const char *where)
#define GWEN_SYNCIO_FILE_FLAGS_UREAD
#define DBG_VERBOUS(dbg_logger, format, args...)
const GWEN_SAR_FILEHEADER_LIST * GWEN_Sar_GetHeaders(GWEN_SAR *sr)
#define GWEN_GUI_PROGRESS_DELAY
int GWEN_Buffer_AdjustUsedBytes(GWEN_BUFFER *bf)
#define DBG_WARN(dbg_logger, format, args...)
GWEN_SAR_FILEHEADER * GWEN_SarFileHeader_List_Next(const GWEN_SAR_FILEHEADER *element)
int GWEN_Sar_ExtractAndDigestFileLink(GWEN_SAR *sr, const GWEN_SAR_FILEHEADER *fh, int checkOnly)
int GWEN_TLV_ReadHeader(GWEN_TLV *tlv, const uint8_t *p, uint32_t size, int isBerTlv)
int GWEN_MDigest_Update(GWEN_MDIGEST *md, const uint8_t *buf, unsigned int l)
int GWEN_Buffer_ReserveBytes(GWEN_BUFFER *bf, uint32_t res)
void GWEN_Sar_Attach(GWEN_SAR *sr)
int GWEN_Sar_ExtractFile(GWEN_SAR *sr, const GWEN_SAR_FILEHEADER *fh)
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
int GWEN_TLV_DirectlyToBuffer(unsigned int tagType, unsigned int tagMode, const void *tagData, int tagLength, int isBerTlv, GWEN_BUFFER *mbuf)
GWEN_SYNCIO_FILE_CREATIONMODE
void GWEN_Buffer_Reset(GWEN_BUFFER *bf)
int GWEN_Buffer_IncrementPos(GWEN_BUFFER *bf, uint32_t i)
#define GWEN_SYNCIO_FILE_FLAGS_GREAD
uint8_t * GWEN_MDigest_GetDigestPtr(GWEN_MDIGEST *md)
unsigned int GWEN_TLV_GetTagType(const GWEN_TLV *tlv)
#define GWEN_ERROR_BAD_DATA
int GWEN_MDigest_Begin(GWEN_MDIGEST *md)
int GWEN_Sar_AddAndDigestFileLink(GWEN_SAR *sr, const GWEN_SAR_FILEHEADER *fh, GWEN_MDIGEST *md)
#define GWEN_GUI_PROGRESS_ONE
#define GWEN_SYNCIO_FILE_FLAGS_OEXEC
#define GWEN_NEW_OBJECT(typ, varname)
struct GWEN_SYNCIO GWEN_SYNCIO
void GWEN_SarFileHeader_List_Add(GWEN_SAR_FILEHEADER *element, GWEN_SAR_FILEHEADER_LIST *list)
GWENHYWFAR_API int GWEN_Time_toUtcString(const GWEN_TIME *t, const char *tmpl, GWEN_BUFFER *buf)
GWENHYWFAR_API GWEN_MDIGEST * GWEN_MDigest_Rmd160_new(void)
uint64_t GWEN_Sar_ReadUint64(const uint8_t *p, uint32_t bs)
GWEN_SAR_FILEHEADER * GWEN_SarFileHeader_List_First(const GWEN_SAR_FILEHEADER_LIST *l)
#define DBG_DEBUG(dbg_logger, format, args...)
int GWEN_Sar_VerifyArchive(const char *inFile, const char *signer, GWEN_CRYPT_KEY *key)
int GWEN_Sar_CheckFile(GWEN_SAR *sr, const GWEN_SAR_FILEHEADER *fh)
int GWEN_SyncIo_ReadForced(GWEN_SYNCIO *sio, uint8_t *buffer, uint32_t size)
int GWEN_Sar_Verify(GWEN_SAR *sr, GWEN_CRYPTMGR *cm)
struct GWEN_MDIGEST GWEN_MDIGEST
#define GWEN_SYNCIO_FILE_FLAGS_GWRITE
void GWEN_Text_LogString(const char *s, unsigned int l, const char *logDomain, GWEN_LOGGER_LEVEL lv)
GWEN_TLV * GWEN_TLV_new(void)
void GWEN_Sar_free(GWEN_SAR *sr)
struct GWEN_CRYPT_KEY GWEN_CRYPT_KEY
#define GWEN_SYNCIO_FILE_FLAGS_UWRITE
void GWEN_SarFileHeader_List_free(GWEN_SAR_FILEHEADER_LIST *l)
const void * GWEN_TLV_GetTagData(const GWEN_TLV *tlv)
void GWEN_Buffer_free(GWEN_BUFFER *bf)
unsigned int GWEN_TLV_GetTagSize(const GWEN_TLV *tlv)
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
void GWEN_SyncIo_free(GWEN_SYNCIO *sio)
GWEN_CRYPTMGR * GWEN_CryptMgrKeys_new(const char *localName, GWEN_CRYPT_KEY *localKey, const char *peerName, GWEN_CRYPT_KEY *peerKey, int ownKeys)
void GWEN_SyncIo_AddFlags(GWEN_SYNCIO *sio, uint32_t fl)
void GWEN_CryptMgr_free(GWEN_CRYPTMGR *cm)
uint32_t GWEN_Gui_ProgressStart(uint32_t progressFlags, const char *title, const char *text, uint64_t total, uint32_t guiid)
int GWEN_Gui_ProgressEnd(uint32_t id)
#define GWEN_ERROR_NOT_OPEN
int GWEN_MDigest_End(GWEN_MDIGEST *md)
int GWEN_TLV_WriteHeader(unsigned int tagType, unsigned int tagMode, uint64_t tagLength, int isBerTlv, GWEN_BUFFER *mbuf)
#define DBG_ERROR(dbg_logger, format, args...)
GWENHYWFAR_API GWEN_TIME * GWEN_Time_fromUtcString(const char *s, const char *tmpl)
int GWEN_Sar_OpenArchive(GWEN_SAR *sr, const char *aname, GWEN_SYNCIO_FILE_CREATIONMODE cm, uint32_t acc)
unsigned int GWEN_MDigest_GetDigestSize(GWEN_MDIGEST *md)
int GWEN_Buffer_SetPos(GWEN_BUFFER *bf, uint32_t i)
int GWEN_SyncIo_Disconnect(GWEN_SYNCIO *sio)
int GWEN_Sar_ExtractAndDigestFileReg(GWEN_SAR *sr, const GWEN_SAR_FILEHEADER *fh, int checkOnly)
#define GWEN_GUI_PROGRESS_SHOW_PROGRESS
GWEN_SAR_FILEHEADER_LIST * GWEN_SarFileHeader_List_new()
unsigned int GWEN_TLV_GetTagLength(const GWEN_TLV *tlv)
#define GWEN_SYNCIO_FILE_FLAGS_OWRITE
int GWEN_Sar_AddAndDigestFile(GWEN_SAR *sr, const GWEN_SAR_FILEHEADER *fh, GWEN_MDIGEST *md)
#define DBG_INFO(dbg_logger, format, args...)
int GWEN_Sar_CreateArchive(GWEN_SAR *sr, const char *aname)
int GWEN_Sar__UnpackArchive(const char *inFile, const char *where)
int GWEN_Sar_ExtractAndDigestFile(GWEN_SAR *sr, const GWEN_SAR_FILEHEADER *fh, int checkOnly)
GWEN_TLV * GWEN_TLV_fromBuffer(GWEN_BUFFER *mbuf, int isBerTlv)
int GWEN_Sar_AddAndDigestFileReg(GWEN_SAR *sr, const GWEN_SAR_FILEHEADER *fh, GWEN_MDIGEST *md)
#define GWEN_ERROR_VERIFY
GWENHYWFAR_API GWEN_SYNCIO * GWEN_SyncIo_File_new(const char *path, GWEN_SYNCIO_FILE_CREATIONMODE cm)
int GWEN_Sar_CheckArchive(const char *inFile)
void GWEN_Buffer_Rewind(GWEN_BUFFER *bf)
struct GWEN_CRYPTMGR GWEN_CRYPTMGR
int GWEN_CryptMgr_Verify(GWEN_CRYPTMGR *cm, const uint8_t *pData, uint32_t lData, GWEN_BUFFER *dbuf)
int GWEN_Buffer_InsertBytes(GWEN_BUFFER *bf, const char *buffer, uint32_t size)
#define GWEN_SYNCIO_FILE_FLAGS_OREAD
#define GWEN_SYNCIO_FILE_FLAGS_UEXEC
GWENHYWFAR_API GWEN_TIME * GWEN_Time_fromSeconds(uint32_t s)
int GWEN_Sar_SignArchive(const char *inFile, const char *signer, GWEN_CRYPT_KEY *key)
int GWEN_SyncIo_Flush(GWEN_SYNCIO *sio)
uint32_t GWEN_SarFileHeader_List_GetCount(const GWEN_SAR_FILEHEADER_LIST *l)
#define GWEN_GUI_PROGRESS_SHOW_ABORT
int GWEN_Sar_TlvToFileHeader(GWEN_BUFFER *mbuf, GWEN_SAR_FILEHEADER *fh)