Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 154589 Details for
Bug 239934
Shredding patch for logrotate
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
patch to make logrotate call GNU shred
lshred.diff (text/plain), 6.52 KB, created by
Peter Eckersley
on 2007-05-12 18:47:51 UTC
(
hide
)
Description:
patch to make logrotate call GNU shred
Filename:
MIME Type:
Creator:
Peter Eckersley
Created:
2007-05-12 18:47:51 UTC
Size:
6.52 KB
patch
obsolete
>diff -ru logrotate-3.7.1/config.c logrotate-shred/config.c >--- logrotate-3.7.1/config.c 2003-08-07 04:13:14.000000000 -0700 >+++ logrotate-shred/config.c 2007-05-11 02:19:28.000000000 -0700 >@@ -471,6 +471,14 @@ > newlog->flags &= ~LOG_FLAG_COMPRESS; > > *endtag = oldchar, start = endtag; >+ } else if (!strcmp(start, "shred")) { >+ newlog->flags |= LOG_FLAG_SHRED; >+ >+ *endtag = oldchar, start = endtag; >+ } else if (!strcmp(start, "noshred")) { >+ newlog->flags &= ~LOG_FLAG_SHRED; >+ >+ *endtag = oldchar, start = endtag; > } else if (!strcmp(start, "delaycompress")) { > newlog->flags |= LOG_FLAG_DELAYCOMPRESS; > >@@ -654,6 +662,21 @@ > return 1; > } > *endtag = oldchar, start = endtag; >+ } >+ } else if (!strcmp(start, "shredcycles")) { >+ *endtag = oldchar, start = endtag; >+ >+ if (!isolateValue(configFile, lineNum, "shred cycles", >+ &start, &endtag)) { >+ oldchar = *endtag, *endtag = '\0'; >+ >+ newlog->shred_cycles = strtoul(start, &chptr, 0); >+ if (*chptr || newlog->shred_cycles < 0) { >+ message(MESS_ERROR, "%s:%d bad shred cycles '%s'\n", >+ configFile, lineNum, start); >+ return 1; >+ } >+ *endtag = oldchar, start = endtag; > } > } else if (!strcmp(start, "start")) { > *endtag = oldchar, start = endtag; >diff -ru logrotate-3.7.1/logrotate.8 logrotate-shred/logrotate.8 >--- logrotate-3.7.1/logrotate.8 2003-08-07 04:13:14.000000000 -0700 >+++ logrotate-shred/logrotate.8 2007-05-11 02:25:37.000000000 -0700 >@@ -299,6 +299,10 @@ > option). > > .TP >+\fBnoshred\fR >+Do not use \fBshred\fR when deleting old log files. See also \fBshred\fR. >+ >+.TP > \fBnotifempty\fR > Do not rotate the log if it is empty (this overrides the \fBifempty\fR option). > >@@ -367,6 +371,17 @@ > option. > > .TP >+\fBshred\fR >+Delete log files using \fBshred\fR -u instead of unlink(). This should >+ensure that logs are not readable after their scheduled deletion; it is the >+default behaviour. See also \fBnoshred\fR. >+ >+.TP >+\fBshredcycles\fR \fIcount\fR >+Asks GNU \fBshred\fR to overwite log files \fBcount\fR times before >+deletion. Without this option, \fBshred\fR's default will be used. >+ >+.TP > \fBstart \fIcount\fR > This is the number to use as the base for rotation. For example, if > you specify 0, the logs will be created with a .0 extension as they are >diff -ru logrotate-3.7.1/logrotate.c logrotate-shred/logrotate.c >--- logrotate-3.7.1/logrotate.c 2004-10-19 14:41:24.000000000 -0700 >+++ logrotate-shred/logrotate.c 2007-05-11 02:04:47.000000000 -0700 >@@ -41,6 +41,7 @@ > int debug = 0; > char * mailCommand = DEFAULT_MAIL_COMMAND; > time_t nowSecs = 0; >+static int shred_file(char * filename, logInfo *log); > > static logState * findState(const char * fn, struct stateSet * sip) { > int i; >@@ -195,7 +196,7 @@ > return 1; > } > >- unlink(name); >+ shred_file(name,log); > > return 0; > } >@@ -744,7 +745,7 @@ > if (!hasErrors && disposeName) { > message(MESS_DEBUG, "removing old log %s\n", disposeName); > >- if (!debug && unlink(disposeName)) { >+ if (!debug && shred_file(disposeName,log)) { > message(MESS_ERROR, "Failed to remove old log %s: %s\n", > disposeName, strerror(errno)); > hasErrors = 1; >@@ -1045,19 +1046,52 @@ > > } > >+#define SHRED_CALL "shred -u " >+#define SHRED_COUNT_FLAG "-n " >+#define DIGITS 10 >+static int shred_file(char * filename, logInfo *log) >+/* unlink, but try to call shred from GNU fileutils */ >+{ >+ int len, ret; >+ char *cmd; >+ char count[DIGITS]; /* that's a lot of shredding :) */ >+ >+ if (!(log->flags & LOG_FLAG_SHRED)) { >+ return unlink(filename); >+ } >+ >+ len = strlen(filename) + strlen(SHRED_CALL); >+ len += strlen(SHRED_COUNT_FLAG) + DIGITS; >+ cmd = malloc(len); >+ >+ if (!cmd) { >+ message(MESS_ERROR, "malloc error while shredding"); >+ return unlink(filename); >+ } >+ strcpy(cmd, SHRED_CALL); >+ if (log->shred_cycles != 0) { >+ strcat(cmd, SHRED_COUNT_FLAG); >+ snprintf(count, DIGITS - 1, "%d", log->shred_cycles); >+ strcat(count, " "); >+ strcat(cmd, count); >+ } >+ strcat(cmd, filename); >+ ret = system(cmd); >+ free(cmd); >+ if (ret != 0) { >+ message(MESS_NORMAL, "Failed to shred %s\n", filename); >+ if (ret != -1) { >+ message(MESS_NORMAL, "Shred returned %d\n", ret); >+ } >+ return unlink(filename); >+ } else { >+ return ret; >+ } >+} >+ >+ > int main(int argc, const char ** argv) { >- logInfo defConfig = { NULL, NULL, 0, NULL, ROT_SIZE, >- /* threshHold */ 1024 * 1024, 0, >- /* log start */ -1, >- /* pre, post */ NULL, NULL, >- /* first, last */ NULL, NULL, >- /* logAddress */ NULL, >- /* extension */ NULL, >- /* compression */ COMPRESS_COMMAND, >- UNCOMPRESS_COMMAND, COMPRESS_EXT, >- /* rotate pattern */ NULL, >- /* flags */ LOG_FLAG_IFEMPTY, >- /* createMode */ NO_MODE, NO_UID, NO_GID }; >+ logInfo defConfig = DEFAULT_CONFIG; > int numLogs = 0; > int force = 0; > logInfo * logs = NULL; >diff -ru logrotate-3.7.1/logrotate.h logrotate-shred/logrotate.h >--- logrotate-3.7.1/logrotate.h 2003-08-07 04:13:14.000000000 -0700 >+++ logrotate-shred/logrotate.h 2007-05-11 00:19:42.000000000 -0700 >@@ -15,6 +15,8 @@ > #define LOG_FLAG_MAILFIRST (1 << 6) > #define LOG_FLAG_SHAREDSCRIPTS (1 << 7) > #define LOG_FLAG_COPY (1 << 8) >+#define LOG_FLAG_SHRED (1 << 9) >+ > > #define NO_FORCE_ROTATE 0 > #define FORCE_ROTATE 1 >@@ -43,6 +45,7 @@ > char * compress_ext; > struct rotatePatternElement * rotatePattern; > int flags; >+ int shred_cycles; /* if !=0, pass -n shred_cycles to GNU shred */ > mode_t createMode; /* if any/all of these are -1, we use the */ > uid_t createUid; /* attributes from the log file just rotated */ > gid_t createGid; >@@ -51,6 +54,22 @@ > int compress_options_count; > } logInfo; > >+#define LOG_FLAG_DEFAULTS (LOG_FLAG_IFEMPTY & LOG_FLAG_SHRED) >+ >+#define DEFAULT_CONFIG { NULL, NULL, 0, NULL, ROT_SIZE, \ >+ /* threshHold */ 1024 * 1024, 0,\ >+ /* log start */ -1,\ >+ /* pre, post */ NULL, NULL,\ >+ /* first, last */ NULL, NULL,\ >+ /* logAddress */ NULL, \ >+ /* extension */ NULL, \ >+ /* compression */ COMPRESS_COMMAND,\ >+ UNCOMPRESS_COMMAND, COMPRESS_EXT,\ >+ /* rotate pattern */ NULL,\ >+ /* flags */ LOG_FLAG_DEFAULTS,\ >+ /* shred cycles */ 0,\ >+ /* createMode */ NO_MODE, NO_UID, NO_GID } >+ > int readConfigPath(const char * path, logInfo * defConfig, > logInfo ** logsPtr, int * numLogsPtr); >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 239934
: 154589