diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/cryprov.h | 1 | ||||
-rw-r--r-- | runtime/libgcry.c | 5 | ||||
-rw-r--r-- | runtime/libgcry.h | 9 | ||||
-rw-r--r-- | runtime/lmcry_gcry.c | 7 | ||||
-rw-r--r-- | runtime/queue.c | 1 | ||||
-rw-r--r-- | runtime/stream.c | 19 |
6 files changed, 40 insertions, 2 deletions
diff --git a/runtime/cryprov.h b/runtime/cryprov.h index 66c1cfd1..a940d833 100644 --- a/runtime/cryprov.h +++ b/runtime/cryprov.h @@ -42,6 +42,7 @@ BEGINinterface(cryprov) /* name must also be changed in ENDinterface macro! */ rsRetVal (*Encrypt)(void *pFileInstData, uchar *buf, size_t *lenBuf); rsRetVal (*Decrypt)(void *pFileInstData, uchar *buf, size_t *lenBuf); rsRetVal (*OnFileClose)(void *pFileInstData, off64_t offsLogfile); + void (*SetDeleteOnClose)(void *pFileInstData, int val); ENDinterface(cryprov) #define cryprovCURR_IF_VERSION 3 /* increment whenever you change the interface structure! */ #endif /* #ifndef INCLUDED_CRYPROV_H */ diff --git a/runtime/libgcry.c b/runtime/libgcry.c index 3fca50ec..57380243 100644 --- a/runtime/libgcry.c +++ b/runtime/libgcry.c @@ -344,7 +344,12 @@ gcryfileDestruct(gcryfile gf, off64_t offsLogfile) if(gf == NULL) goto done; +dbgprintf("DDDD: cryprov closes file %s\n", gf->eiName); eiClose(gf, offsLogfile); + if(gf->bDeleteOnClose) { + DBGPRINTF("unlink file '%s' due to bDeleteOnClose set\n", gf->eiName); + unlink((char*)gf->eiName); + } free(gf->eiName); free(gf); done: return r; diff --git a/runtime/libgcry.h b/runtime/libgcry.h index 190f4737..7c704bcf 100644 --- a/runtime/libgcry.h +++ b/runtime/libgcry.h @@ -43,6 +43,7 @@ struct gcryfile_s { uchar *readBuf; int16_t readBufIdx; int16_t readBufMaxIdx; + int8_t bDeleteOnClose; /* for queue support, similar to stream subsys */ }; int gcryGetKeyFromFile(char *fn, char **key, unsigned *keylen); @@ -68,6 +69,14 @@ int gcryGetKeyFromProg(char *cmd, char **key, unsigned *keylen); #define RSGCRY_FILETYPE_NAME "rsyslog-enrcyption-info" #define ENCINFO_SUFFIX ".encinfo" +/* Note: gf may validly be NULL, e.g. if file has not yet been opened! */ +static inline void +gcryfileSetDeleteOnClose(gcryfile gf, int val) +{ + if(gf != NULL) + gf->bDeleteOnClose = val; +} + static inline int rsgcryAlgoname2Algo(char *algoname) { if(!strcmp((char*)algoname, "3DES")) return GCRY_CIPHER_3DES; diff --git a/runtime/lmcry_gcry.c b/runtime/lmcry_gcry.c index decb8591..d30aeddc 100644 --- a/runtime/lmcry_gcry.c +++ b/runtime/lmcry_gcry.c @@ -209,6 +209,12 @@ finalize_it: RETiRet; } +static void +SetDeleteOnClose(void *pF, int val) +{ +dbgprintf("DDDD: SetDeleteOnClose %d\n", val); + gcryfileSetDeleteOnClose(pF, val); +} static rsRetVal OnFileOpen(void *pT, uchar *fn, void *pGF, char openMode) @@ -262,6 +268,7 @@ CODESTARTobjQueryInterface(lmcry_gcry) } pIf->Construct = (rsRetVal(*)(void*)) lmcry_gcryConstruct; pIf->SetCnfParam = SetCnfParam; + pIf->SetDeleteOnClose = SetDeleteOnClose; pIf->Destruct = (rsRetVal(*)(void*)) lmcry_gcryDestruct; pIf->OnFileOpen = OnFileOpen; pIf->Encrypt = Encrypt; diff --git a/runtime/queue.c b/runtime/queue.c index 6af4905b..0f77bceb 100644 --- a/runtime/queue.c +++ b/runtime/queue.c @@ -2779,7 +2779,6 @@ qqueueApplyCnfParam(qqueue_t *pThis, struct nvlst *lst) pThis->lenFilePrefix = es_strlen(pvals[i].val.d.estr); } else if(!strcmp(pblk.descr[i].name, "queue.cry.provider")) { pThis->cryprovName = (uchar*) es_str2cstr(pvals[i].val.d.estr, NULL); -dbgprintf("DDDD: crypto provider set: '%s'\n", pThis->cryprovName); } else if(!strcmp(pblk.descr[i].name, "queue.size")) { pThis->iMaxQueueSize = pvals[i].val.d.n; } else if(!strcmp(pblk.descr[i].name, "queue.dequeuebatchsize")) { diff --git a/runtime/stream.c b/runtime/stream.c index e411577f..19daaed6 100644 --- a/runtime/stream.c +++ b/runtime/stream.c @@ -259,6 +259,8 @@ doPhysOpen(strm_t *pThis) CHKiRet(pThis->cryprov->OnFileOpen(pThis->cryprovData, pThis->pszCurrFName, &pThis->cryprovFileData, (pThis->tOperationsMode == STREAMMODE_READ) ? 'r' : 'w')); +dbgprintf("DDDD: stream bDeleteOnClose %d\n", pThis->bDeleteOnClose); + pThis->cryprov->SetDeleteOnClose(pThis->cryprovFileData, pThis->bDeleteOnClose); } finalize_it: RETiRet; @@ -406,6 +408,12 @@ static rsRetVal strmCloseFile(strm_t *pThis) } } + /* if we have a signature provider, we must make sure that the crypto + * state files are opened and proper close processing happens. */ + if(pThis->fd == -1) { + strmOpenFile(pThis); + } + /* the file may already be closed (or never have opened), so guard * against this. -- rgerhards, 2010-03-19 */ @@ -1611,7 +1619,6 @@ finalize_it: /* property set methods */ /* simple ones first */ -DEFpropSetMeth(strm, bDeleteOnClose, int) DEFpropSetMeth(strm, iMaxFileSize, int) DEFpropSetMeth(strm, iFileNumDigits, int) DEFpropSetMeth(strm, tOperationsMode, int) @@ -1627,6 +1634,16 @@ DEFpropSetMeth(strm, pszSizeLimitCmd, uchar*) DEFpropSetMeth(strm, cryprov, cryprov_if_t*) DEFpropSetMeth(strm, cryprovData, void*) +static rsRetVal strmSetbDeleteOnClose(strm_t *pThis, int val) +{ + pThis->bDeleteOnClose = val; + if(pThis->cryprov != NULL) { +dbgprintf("DDDD: set stream bDeleteOnClose %d\n", pThis->bDeleteOnClose); + pThis->cryprov->SetDeleteOnClose(pThis->cryprovFileData, pThis->bDeleteOnClose); + } + return RS_RET_OK; +} + static rsRetVal strmSetiMaxFiles(strm_t *pThis, int iNewVal) { pThis->iMaxFiles = iNewVal; |