diff options
-rw-r--r-- | runtime/cryprov.h | 1 | ||||
-rw-r--r-- | runtime/libgcry.c | 17 | ||||
-rw-r--r-- | runtime/libgcry.h | 1 | ||||
-rw-r--r-- | runtime/lmcry_gcry.c | 8 | ||||
-rw-r--r-- | runtime/stream.c | 6 |
5 files changed, 29 insertions, 4 deletions
diff --git a/runtime/cryprov.h b/runtime/cryprov.h index a940d833..0c3053d4 100644 --- a/runtime/cryprov.h +++ b/runtime/cryprov.h @@ -43,6 +43,7 @@ BEGINinterface(cryprov) /* name must also be changed in ENDinterface macro! */ rsRetVal (*Decrypt)(void *pFileInstData, uchar *buf, size_t *lenBuf); rsRetVal (*OnFileClose)(void *pFileInstData, off64_t offsLogfile); void (*SetDeleteOnClose)(void *pFileInstData, int val); + rsRetVal (*DeleteStateFiles)(uchar *logfn); 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 bbf6e1e6..0b3b8fc2 100644 --- a/runtime/libgcry.c +++ b/runtime/libgcry.c @@ -310,6 +310,23 @@ eiClose(gcryfile gf, off64_t offsLogfile) DBGPRINTF("encryption info file %s: closed\n", gf->eiName); } +/* this is a special functon for use by the rsyslog disk queue subsystem. It + * needs to have the capability to delete state when a queue file is rolled + * over. This simply generates the file name and deletes it. It must take care + * of "all" state files, which currently happens to be a single one. + */ +rsRetVal +gcryfileDeleteState(uchar *logfn) +{ + char fn[MAXFNAME+1]; + DEFiRet; + snprintf(fn, sizeof(fn), "%s%s", logfn, ENCINFO_SUFFIX); + fn[MAXFNAME] = '\0'; /* be on save side */ + DBGPRINTF("crypto provider deletes state file '%s' on request\n", fn); + unlink(fn); + RETiRet; +} + static rsRetVal gcryfileConstruct(gcryctx ctx, gcryfile *pgf, uchar *logfn) { diff --git a/runtime/libgcry.h b/runtime/libgcry.h index a3004a01..819ac77c 100644 --- a/runtime/libgcry.h +++ b/runtime/libgcry.h @@ -59,6 +59,7 @@ rsRetVal rsgcryInitCrypt(gcryctx ctx, gcryfile *pgf, uchar *fname, char openMode rsRetVal rsgcryEncrypt(gcryfile pF, uchar *buf, size_t *len); rsRetVal rsgcryDecrypt(gcryfile pF, uchar *buf, size_t *len); int gcryGetKeyFromProg(char *cmd, char **key, unsigned *keylen); +rsRetVal gcryfileDeleteState(uchar *fn); /* error states */ #define RSGCRYE_EI_OPEN 1 /* error opening .encinfo file */ diff --git a/runtime/lmcry_gcry.c b/runtime/lmcry_gcry.c index d30aeddc..3941b06c 100644 --- a/runtime/lmcry_gcry.c +++ b/runtime/lmcry_gcry.c @@ -212,10 +212,15 @@ finalize_it: static void SetDeleteOnClose(void *pF, int val) { -dbgprintf("DDDD: SetDeleteOnClose %d\n", val); gcryfileSetDeleteOnClose(pF, val); } +static void +DeleteStateFiles(uchar *logfn) +{ + return gcryfileDeleteState(logfn); +} + static rsRetVal OnFileOpen(void *pT, uchar *fn, void *pGF, char openMode) { @@ -274,6 +279,7 @@ CODESTARTobjQueryInterface(lmcry_gcry) pIf->Encrypt = Encrypt; pIf->Decrypt = Decrypt; pIf->OnFileClose = OnFileClose; + pIf->DeleteStateFiles = DeleteStateFiles; finalize_it: ENDobjQueryInterface(lmcry_gcry) diff --git a/runtime/stream.c b/runtime/stream.c index 19daaed6..ac97d484 100644 --- a/runtime/stream.c +++ b/runtime/stream.c @@ -259,7 +259,6 @@ 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: @@ -410,7 +409,7 @@ 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) { + if(pThis->cryprov != NULL && pThis->fd == -1) { strmOpenFile(pThis); } @@ -1469,6 +1468,8 @@ strmMultiFileSeek(strm_t *pThis, int FNum, off64_t offs, off64_t *bytesDel) "deleting '%s' (%lld bytes)\n", pThis->iCurrFNum, FNum, pThis->pszCurrFName, (long long) *bytesDel); unlink((char*)pThis->pszCurrFName); + if(pThis->cryprov != NULL) + pThis->cryprov->DeleteStateFiles(pThis->pszCurrFName); free(pThis->pszCurrFName); pThis->pszCurrFName = NULL; pThis->iCurrFNum = FNum; @@ -1638,7 +1639,6 @@ 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; |