diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2013-03-25 15:56:33 +0100 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2013-03-25 15:56:33 +0100 |
commit | c896a6ba7498e15ddfe869823a64434a4180d57b (patch) | |
tree | 04d665ab29ad27f115d1cf7854862b18b97eb75f /tools/rsgtutil.c | |
parent | 199630a5ef8f0c919fbbbd9e122415d1d72886a3 (diff) | |
download | rsyslog-c896a6ba7498e15ddfe869823a64434a4180d57b.tar.gz rsyslog-c896a6ba7498e15ddfe869823a64434a4180d57b.tar.bz2 rsyslog-c896a6ba7498e15ddfe869823a64434a4180d57b.zip |
rsgtsig: finish implementation of 'extend' mode
This is tested as far as possible. However, the actual extend
case can only be tested in about three weeks from now when the
next publication is out. I have done module-testing with a
mockup extend call, so chances are great the final test will
be passed.
Diffstat (limited to 'tools/rsgtutil.c')
-rw-r--r-- | tools/rsgtutil.c | 75 |
1 files changed, 62 insertions, 13 deletions
diff --git a/tools/rsgtutil.c b/tools/rsgtutil.c index 1f475527..45106c00 100644 --- a/tools/rsgtutil.c +++ b/tools/rsgtutil.c @@ -26,6 +26,7 @@ #include <stdio.h> #include <errno.h> #include <string.h> +#include <unistd.h> #include <gt_base.h> #include <gt_http.h> #include <getopt.h> @@ -197,6 +198,7 @@ verify(char *name) uint8_t bInBlock; int r = 0; char sigfname[4096]; + char oldsigfname[4096]; char nsigfname[4096]; gterrctx_t ectx; @@ -222,6 +224,9 @@ verify(char *name) perror(nsigfname); goto err; } + snprintf(oldsigfname, sizeof(oldsigfname), + "%s.gtsig.old", name); + oldsigfname[sizeof(oldsigfname)-1] = '\0'; } } @@ -231,18 +236,18 @@ verify(char *name) ectx.fp = stderr; ectx.filename = strdup(sigfname); - if((r = rsgt_chkFileHdr(sigfp, "LOGSIG10")) != 0) goto err; + if((r = rsgt_chkFileHdr(sigfp, "LOGSIG10")) != 0) goto done; if(mode == MD_EXTEND) { if(fwrite("LOGSIG10", 8, 1, nsigfp) != 1) { perror(nsigfname); r = RSGTE_IO; - goto err; + goto done; } } gf = rsgt_vrfyConstruct_gf(); if(gf == NULL) { fprintf(stderr, "error initializing signature file structure\n"); - goto err; + goto done; } bInBlock = 0; @@ -255,36 +260,80 @@ verify(char *name) rsgt_objfree(0x0902, bs); if((r = rsgt_getBlockParams(sigfp, 1, &bs, &bHasRecHashes, &bHasIntermedHashes)) != 0) - goto err; + goto done; rsgt_vrfyBlkInit(gf, bs, bHasRecHashes, bHasIntermedHashes); ectx.recNum = 0; ++ectx.blkNum; } ++ectx.recNum, ++ectx.recNumInFile; if((r = doVerifyRec(logfp, sigfp, nsigfp, bs, gf, &ectx, bInBlock)) != 0) - goto err; + goto done; if(ectx.recNum == bs->recCount) { - verifyBLOCK_SIG(bs, gf, sigfp, nsigfp, - (mode == MD_EXTEND) ? 1 : 0, &ectx); + if((r = verifyBLOCK_SIG(bs, gf, sigfp, nsigfp, + (mode == MD_EXTEND) ? 1 : 0, &ectx)) != 0) + goto done; bInBlock = 0; } else bInBlock = 1; } - fclose(logfp); - fclose(sigfp); - fclose(nsigfp); +done: + if(r != RSGTE_EOF) + goto err; + + fclose(logfp); logfp = NULL; + fclose(sigfp); sigfp = NULL; + fclose(nsigfp); nsigfp = NULL; + + /* everything went fine, so we rename files if we updated them */ + if(mode == MD_EXTEND) { + if(unlink(oldsigfname) != 0) { + if(errno != ENOENT) { + perror("unlink oldsig"); + r = RSGTE_IO; + goto err; + } + } + if(link(sigfname, oldsigfname) != 0) { + perror("link oldsig"); + r = RSGTE_IO; + goto err; + } + if(unlink(sigfname) != 0) { + perror("unlink cursig"); + r = RSGTE_IO; + goto err; + } + if(link(nsigfname, sigfname) != 0) { + perror("link newsig"); + fprintf(stderr, "WARNING: current sig file has been " + "renamed to %s - you need to manually recover " + "it.\n", oldsigfname); + r = RSGTE_IO; + goto err; + } + if(unlink(nsigfname) != 0) { + perror("unlink newsig"); + fprintf(stderr, "WARNING: current sig file has been " + "renamed to %s - you need to manually recover " + "it.\n", oldsigfname); + r = RSGTE_IO; + goto err; + } + } rsgtExit(); rsgt_errctxExit(&ectx); return; + err: + fprintf(stderr, "error %d processing file %s\n", r, name); if(logfp != NULL) fclose(logfp); if(sigfp != NULL) fclose(sigfp); - if(nsigfp != NULL) + if(nsigfp != NULL) { fclose(nsigfp); - if(r != RSGTE_EOF) - fprintf(stderr, "error %d processing file %s\n", r, name); + unlink(nsigfname); + } rsgtExit(); rsgt_errctxExit(&ectx); } |