"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "config.c" between
logrotate-3.18.0.tar.xz and logrotate-3.18.1.tar.xz

About: logrotate rotates, compresses, and mails system logs.

config.c  (logrotate-3.18.0.tar.xz):config.c  (logrotate-3.18.1.tar.xz)
skipping to change at line 15 skipping to change at line 15
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <glob.h> #include <glob.h>
#include <grp.h> #include <grp.h>
#include <popt.h> #include <popt.h>
#include <pwd.h> #include <pwd.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <time.h>
#include <unistd.h> #include <unistd.h>
#include <assert.h> #include <assert.h>
#include <wchar.h> #include <wchar.h>
#include <wctype.h> #include <wctype.h>
#include <fnmatch.h> #include <fnmatch.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <libgen.h> #include <libgen.h>
#if !defined(PATH_MAX) && defined(__FreeBSD__) #if !defined(PATH_MAX) && defined(__FreeBSD__)
#include <sys/param.h> #include <sys/param.h>
skipping to change at line 64 skipping to change at line 63
int asprintf(char **string_ptr, const char *format, ...) int asprintf(char **string_ptr, const char *format, ...)
{ {
va_list arg; va_list arg;
char *str; char *str;
int size; int size;
int rv; int rv;
va_start(arg, format); va_start(arg, format);
size = vsnprintf(NULL, 0, format, arg); size = vsnprintf(NULL, 0, format, arg);
size++;
va_end(arg); va_end(arg);
va_start(arg, format); if (size < 0) {
str = malloc(size); return -1;
}
str = malloc((size_t)size + 1);
if (str == NULL) { if (str == NULL) {
va_end(arg); return -1;
/*
* Strictly speaking, GNU asprintf doesn't do this,
* but the caller isn't checking the return value.
*/
message_OOM();
exit(1);
} }
rv = vsnprintf(str, size, format, arg); va_start(arg, format);
rv = vsnprintf(str, (size_t)size + 1, format, arg);
va_end(arg); va_end(arg);
*string_ptr = str; *string_ptr = str;
return (rv); return rv;
} }
#endif #endif
#if !defined(HAVE_STRNDUP) #if !defined(HAVE_STRNDUP)
char *strndup(const char *s, size_t n) char *strndup(const char *s, size_t n)
{ {
size_t nAvail; size_t nAvail;
char *p; char *p;
skipping to change at line 318 skipping to change at line 313
parsed_gid < INT_MAX && /* parsed_gid != ULONG_MAX && */ parsed_gid < INT_MAX && /* parsed_gid != ULONG_MAX && */
getgrgid((gid_t)parsed_gid) != NULL) { getgrgid((gid_t)parsed_gid) != NULL) {
*pGid = (gid_t)parsed_gid; *pGid = (gid_t)parsed_gid;
return 0; return 0;
} }
return -1; return -1;
} }
static int readModeUidGid(const char *configFile, int lineNum, char *key, static int readModeUidGid(const char *configFile, int lineNum, const char *key,
const char *directive, mode_t *mode, uid_t *pUid, const char *directive, mode_t *mode, uid_t *pUid,
gid_t *pGid) gid_t *pGid)
{ {
char u[200], g[200]; char u[200], g[200];
mode_t m = 0; mode_t m = 0;
char tmp; char tmp;
int rc; int rc;
if (!strcmp("su", directive)) if (!strcmp("su", directive))
/* do not read <mode> for the 'su' directive */ /* do not read <mode> for the 'su' directive */
skipping to change at line 817 skipping to change at line 812
.compress_options_count = 0 .compress_options_count = 0
}; };
tabooPatterns = malloc(sizeof(*tabooPatterns) * defTabooCount); tabooPatterns = malloc(sizeof(*tabooPatterns) * defTabooCount);
if (tabooPatterns == NULL) { if (tabooPatterns == NULL) {
message_OOM(); message_OOM();
return 1; return 1;
} }
for (i = 0; i < defTabooCount; i++) { for (i = 0; i < defTabooCount; i++) {
int bytes;
char *pattern = NULL; char *pattern = NULL;
/* generate a pattern by concatenating star (wildcard) to the /* generate a pattern by concatenating star (wildcard) to the
* suffix literal * suffix literal
*/ */
bytes = asprintf(&pattern, "*%s", defTabooExts[i]); if (asprintf(&pattern, "*%s", defTabooExts[i]) < 0) {
if (bytes != -1) {
tabooPatterns[i] = pattern;
tabooCount++;
} else {
free_2d_array(tabooPatterns, tabooCount); free_2d_array(tabooPatterns, tabooCount);
message_OOM(); message_OOM();
return 1; return 1;
} }
tabooPatterns[i] = pattern;
tabooCount++;
} }
for (file = paths; *file; file++) { for (file = paths; *file; file++) {
if (readConfigPath(*file, &defConfig)) if (readConfigPath(*file, &defConfig))
result = 1; result = 1;
} }
free_2d_array(tabooPatterns, tabooCount); free_2d_array(tabooPatterns, tabooCount);
freeLogInfo(&defConfig); freeLogInfo(&defConfig);
return result; return result;
} }
skipping to change at line 945 skipping to change at line 938
/* We want the glob operation to abort on error, so return 1 */ /* We want the glob operation to abort on error, so return 1 */
return 1; return 1;
} }
#define freeLogItem(what) \ #define freeLogItem(what) \
do { \ do { \
free(newlog->what); \ free(newlog->what); \
newlog->what = NULL; \ newlog->what = NULL; \
} while (0) } while (0)
#define RAISE_ERROR() \ #define RAISE_ERROR() \
if (newlog != defConfig) { \ do { \
state = STATE_ERROR; \ if (newlog != defConfig) { \
goto next_state; \ state = STATE_ERROR; \
} else { \ goto next_state; \
goto error; \ } else { \
} goto error; \
} \
} while(0)
#define MAX_NESTING 16U #define MAX_NESTING 16U
static int readConfigFile(const char *configFile, struct logInfo *defConfig) static int readConfigFile(const char *configFile, struct logInfo *defConfig)
{ {
int fd; int fd;
char *buf, *key = NULL; char *buf, *key = NULL;
size_t length; size_t length;
int lineNum = 1; int lineNum = 1;
char *scriptStart = NULL; char *scriptStart = NULL;
char **scriptDest = NULL; char **scriptDest = NULL;
struct logInfo *newlog = defConfig; struct logInfo *newlog = defConfig;
char *start, *chptr; char *start, *chptr;
struct stat sb; struct stat sb;
int state = STATE_DEFAULT; int state = STATE_DEFAULT;
int logerror = 0; int logerror = 0;
/* to check if incompatible criteria are specified */ /* to check if incompatible criteria are specified */
int criterium_set = 0; int criterium_set = 0;
static unsigned recursion_depth = 0U; static unsigned recursion_depth = 0U;
char *globerr_msg = NULL; char *globerr_msg = NULL;
int in_config = 0; int in_config = 0;
#ifdef HAVE_MADVISE
int r;
#endif
struct flock fd_lock = { struct flock fd_lock = {
.l_start = 0, .l_start = 0,
.l_len = 0, .l_len = 0,
.l_whence = SEEK_SET, .l_whence = SEEK_SET,
.l_type = F_RDLCK .l_type = F_RDLCK
}; };
fd = open(configFile, O_RDONLY); fd = open(configFile, O_RDONLY);
if (fd < 0) { if (fd < 0) {
message(MESS_ERROR, "failed to open config file %s: %s\n", message(MESS_ERROR, "failed to open config file %s: %s\n",
skipping to change at line 1013 skipping to change at line 1011
if (!getpwuid(getuid())) { if (!getpwuid(getuid())) {
message(MESS_ERROR, "Cannot find logrotate UID (%d) in passwd file: %s\n ", message(MESS_ERROR, "Cannot find logrotate UID (%d) in passwd file: %s\n ",
getuid(), strerror(errno)); getuid(), strerror(errno));
close(fd); close(fd);
return 1; return 1;
} }
if (getuid() == ROOT_UID) { if (getuid() == ROOT_UID) {
if ((sb.st_mode & 07533) != 0400) { if ((sb.st_mode & 07533) != 0400) {
message(MESS_DEBUG, message(MESS_NORMAL,
"Potentially dangerous mode on %s: 0%o\n", "Potentially dangerous mode on %s: 0%o\n",
configFile, (unsigned) (sb.st_mode & 07777)); configFile, (unsigned) (sb.st_mode & 07777));
} }
if (sb.st_mode & 0022) { if (sb.st_mode & 0022) {
message(MESS_ERROR, message(MESS_ERROR,
"Ignoring %s because it is writable by group or others.\n", "Ignoring %s because it is writable by group or others.\n",
configFile); configFile);
close(fd); close(fd);
return 0; return 0;
skipping to change at line 1070 skipping to change at line 1068
if (buf == MAP_FAILED) { if (buf == MAP_FAILED) {
message(MESS_ERROR, "Error mapping config file %s: %s\n", message(MESS_ERROR, "Error mapping config file %s: %s\n",
configFile, strerror(errno)); configFile, strerror(errno));
close(fd); close(fd);
return 1; return 1;
} }
#ifdef HAVE_MADVISE #ifdef HAVE_MADVISE
#ifdef MADV_DONTFORK #ifdef MADV_DONTFORK
madvise(buf, length + 2, r = madvise(buf, length, MADV_SEQUENTIAL | MADV_WILLNEED | MADV_DONTFORK);
MADV_SEQUENTIAL | MADV_WILLNEED | MADV_DONTFORK);
#else /* MADV_DONTFORK */ #else /* MADV_DONTFORK */
madvise(buf, length + 2, r = madvise(buf, length, MADV_SEQUENTIAL | MADV_WILLNEED);
MADV_SEQUENTIAL | MADV_WILLNEED);
#endif /* MADV_DONTFORK */ #endif /* MADV_DONTFORK */
if (r < 0) {
message(MESS_DEBUG, "Failed to advise use of memory: %s\n",
strerror(errno));
}
#endif /* HAVE_MADVISE */ #endif /* HAVE_MADVISE */
message(MESS_DEBUG, "reading config file %s\n", configFile); message(MESS_DEBUG, "reading config file %s\n", configFile);
for (start = buf; (size_t)(start - buf) < length; start++) { for (start = buf; (size_t)(start - buf) < length; start++) {
switch (state) { switch (state) {
case STATE_DEFAULT: case STATE_DEFAULT:
if (isblank((unsigned char)*start)) if (isblank((unsigned char)*start))
continue; continue;
/* Skip comment */ /* Skip comment */
if (*start == '#') { if (*start == '#') {
state = STATE_SKIP_LINE; state = STATE_SKIP_LINE;
continue; continue;
} }
if (isalpha((unsigned char)*start)) { if (isalpha((unsigned char)*start)) {
free(key); free(key);
key = isolateWord(&start, &buf, length); key = isolateWord(&start, &buf, length);
if (key == NULL) if (key == NULL) {
message(MESS_ERROR, "%s:%d failed to parse keyword\n",
configFile, lineNum);
continue; continue;
}
if (!isspace((unsigned char)*start)) {
message(MESS_NORMAL, "%s:%d keyword '%s' not properly"
" separated, found %#x\n",
configFile, lineNum, key, *start);
}
if (!strcmp(key, "compress")) { if (!strcmp(key, "compress")) {
newlog->flags |= LOG_FLAG_COMPRESS; newlog->flags |= LOG_FLAG_COMPRESS;
} else if (!strcmp(key, "nocompress")) { } else if (!strcmp(key, "nocompress")) {
newlog->flags &= ~LOG_FLAG_COMPRESS; newlog->flags &= ~LOG_FLAG_COMPRESS;
} else if (!strcmp(key, "delaycompress")) { } else if (!strcmp(key, "delaycompress")) {
newlog->flags |= LOG_FLAG_DELAYCOMPRESS; newlog->flags |= LOG_FLAG_DELAYCOMPRESS;
} else if (!strcmp(key, "nodelaycompress")) { } else if (!strcmp(key, "nodelaycompress")) {
newlog->flags &= ~LOG_FLAG_DELAYCOMPRESS; newlog->flags &= ~LOG_FLAG_DELAYCOMPRESS;
} else if (!strcmp(key, "shred")) { } else if (!strcmp(key, "shred")) {
newlog->flags |= LOG_FLAG_SHRED; newlog->flags |= LOG_FLAG_SHRED;
} else if (!strcmp(key, "noshred")) { } else if (!strcmp(key, "noshred")) {
newlog->flags &= ~LOG_FLAG_SHRED; newlog->flags &= ~LOG_FLAG_SHRED;
} else if (!strcmp(key, "sharedscripts")) { } else if (!strcmp(key, "sharedscripts")) {
newlog->flags |= LOG_FLAG_SHAREDSCRIPTS; newlog->flags |= LOG_FLAG_SHAREDSCRIPTS;
} else if (!strcmp(key, "nosharedscripts")) { } else if (!strcmp(key, "nosharedscripts")) {
newlog->flags &= ~LOG_FLAG_SHAREDSCRIPTS; newlog->flags &= ~LOG_FLAG_SHAREDSCRIPTS;
} else if (!strcmp(key, "copytruncate")) { } else if (!strcmp(key, "copytruncate")) {
newlog->flags |= LOG_FLAG_COPYTRUNCATE; newlog->flags |= LOG_FLAG_COPYTRUNCATE;
newlog->flags &= ~LOG_FLAG_TMPFILENAME;
} else if (!strcmp(key, "nocopytruncate")) { } else if (!strcmp(key, "nocopytruncate")) {
newlog->flags &= ~LOG_FLAG_COPYTRUNCATE; newlog->flags &= ~LOG_FLAG_COPYTRUNCATE;
} else if (!strcmp(key, "renamecopy")) { } else if (!strcmp(key, "renamecopy")) {
newlog->flags |= LOG_FLAG_TMPFILENAME; newlog->flags |= LOG_FLAG_TMPFILENAME;
newlog->flags &= ~LOG_FLAG_COPYTRUNCATE;
} else if (!strcmp(key, "norenamecopy")) { } else if (!strcmp(key, "norenamecopy")) {
newlog->flags &= ~LOG_FLAG_TMPFILENAME; newlog->flags &= ~LOG_FLAG_TMPFILENAME;
} else if (!strcmp(key, "copy")) { } else if (!strcmp(key, "copy")) {
newlog->flags |= LOG_FLAG_COPY; newlog->flags |= LOG_FLAG_COPY;
} else if (!strcmp(key, "nocopy")) { } else if (!strcmp(key, "nocopy")) {
newlog->flags &= ~LOG_FLAG_COPY; newlog->flags &= ~LOG_FLAG_COPY;
} else if (!strcmp(key, "ifempty")) { } else if (!strcmp(key, "ifempty")) {
newlog->flags |= LOG_FLAG_IFEMPTY; newlog->flags |= LOG_FLAG_IFEMPTY;
} else if (!strcmp(key, "notifempty")) { } else if (!strcmp(key, "notifempty")) {
newlog->flags &= ~LOG_FLAG_IFEMPTY; newlog->flags &= ~LOG_FLAG_IFEMPTY;
} else if (!strcmp(key, "dateext")) { } else if (!strcmp(key, "dateext")) {
newlog->flags |= LOG_FLAG_DATEEXT; newlog->flags |= LOG_FLAG_DATEEXT;
} else if (!strcmp(key, "nodateext")) { } else if (!strcmp(key, "nodateext")) {
newlog->flags &= ~LOG_FLAG_DATEEXT; newlog->flags &= ~LOG_FLAG_DATEEXT;
} else if (!strcmp(key, "dateyesterday")) { } else if (!strcmp(key, "dateyesterday")) {
newlog->flags |= LOG_FLAG_DATEYESTERDAY; newlog->flags |= LOG_FLAG_DATEYESTERDAY;
} else if (!strcmp(key, "datehourago")) { } else if (!strcmp(key, "datehourago")) {
newlog->flags |= LOG_FLAG_DATEHOURAGO; newlog->flags |= LOG_FLAG_DATEHOURAGO;
} else if (!strcmp(key, "dateformat")) { } else if (!strcmp(key, "dateformat")) {
freeLogItem(dateformat); freeLogItem(dateformat);
newlog->dateformat = isolateLine(&start, &buf, length); newlog->dateformat = isolateValue(configFile, lineNum,
if (newlog->dateformat == NULL) key, &start, &buf,
continue; length);
} else if (!strcmp(key, "noolddir")) { } else if (!strcmp(key, "noolddir")) {
newlog->oldDir = NULL; freeLogItem(oldDir);
} else if (!strcmp(key, "mailfirst")) { } else if (!strcmp(key, "mailfirst")) {
newlog->flags |= LOG_FLAG_MAILFIRST; newlog->flags |= LOG_FLAG_MAILFIRST;
} else if (!strcmp(key, "maillast")) { } else if (!strcmp(key, "maillast")) {
newlog->flags &= ~LOG_FLAG_MAILFIRST; newlog->flags &= ~LOG_FLAG_MAILFIRST;
} else if (!strcmp(key, "su")) { } else if (!strcmp(key, "su")) {
int rv; int rv;
mode_t tmp_mode = NO_MODE; mode_t tmp_mode = NO_MODE;
free(key); free(key);
key = isolateLine(&start, &buf, length); key = isolateLine(&start, &buf, length);
if (key == NULL) if (key == NULL) {
continue; message(MESS_ERROR, "%s:%d failed to parse su option
value\n",
configFile, lineNum);
RAISE_ERROR();
}
rv = readModeUidGid(configFile, lineNum, key, "su", rv = readModeUidGid(configFile, lineNum, key, "su",
&tmp_mode, &newlog->suUid, &tmp_mode, &newlog->suUid,
&newlog->suGid); &newlog->suGid);
if (rv == -1) { if (rv == -1) {
RAISE_ERROR(); RAISE_ERROR();
} }
else if (tmp_mode != NO_MODE) { else if (tmp_mode != NO_MODE) {
message(MESS_ERROR, "%s:%d extra arguments for " message(MESS_ERROR, "%s:%d extra arguments for "
"su\n", configFile, lineNum); "su\n", configFile, lineNum);
skipping to change at line 1266 skipping to change at line 1279
free(opt); free(opt);
} }
else { else {
free(opt); free(opt);
continue; continue;
} }
} else if (!strcmp(key, "shredcycles")) { } else if (!strcmp(key, "shredcycles")) {
free(key); free(key);
key = isolateValue(configFile, lineNum, "shred cycles", key = isolateValue(configFile, lineNum, "shred cycles",
&start, &buf, length); &start, &buf, length);
if (key == NULL) if (key == NULL) {
continue; RAISE_ERROR();
}
newlog->shred_cycles = (int)strtoul(key, &chptr, 0); newlog->shred_cycles = (int)strtoul(key, &chptr, 0);
if (*chptr || newlog->shred_cycles < 0) { if (*chptr || newlog->shred_cycles < 0) {
message(MESS_ERROR, "%s:%d bad shred cycles '%s'\n", message(MESS_ERROR, "%s:%d bad shred cycles '%s'\n",
configFile, lineNum, key); configFile, lineNum, key);
goto error; RAISE_ERROR();
} }
} else if (!strcmp(key, "hourly")) { } else if (!strcmp(key, "hourly")) {
set_criterium(&newlog->criterium, ROT_HOURLY, &criterium _set); set_criterium(&newlog->criterium, ROT_HOURLY, &criterium _set);
} else if (!strcmp(key, "daily")) { } else if (!strcmp(key, "daily")) {
set_criterium(&newlog->criterium, ROT_DAYS, &criterium_s et); set_criterium(&newlog->criterium, ROT_DAYS, &criterium_s et);
newlog->threshold = 1; newlog->threshold = 1;
} else if (!strcmp(key, "monthly")) { } else if (!strcmp(key, "monthly")) {
set_criterium(&newlog->criterium, ROT_MONTHLY, &criteriu m_set); set_criterium(&newlog->criterium, ROT_MONTHLY, &criteriu m_set);
} else if (!strcmp(key, "weekly")) { } else if (!strcmp(key, "weekly")) {
unsigned weekday; unsigned weekday;
skipping to change at line 1307 skipping to change at line 1321
} }
message(MESS_ERROR, "%s:%d bad weekly directive '%s'\n", message(MESS_ERROR, "%s:%d bad weekly directive '%s'\n",
configFile, lineNum, key); configFile, lineNum, key);
goto error; goto error;
} else if (!strcmp(key, "yearly")) { } else if (!strcmp(key, "yearly")) {
set_criterium(&newlog->criterium, ROT_YEARLY, &criterium _set); set_criterium(&newlog->criterium, ROT_YEARLY, &criterium _set);
} else if (!strcmp(key, "rotate")) { } else if (!strcmp(key, "rotate")) {
free(key); free(key);
key = isolateValue(configFile, lineNum, "rotate count", &start, key = isolateValue(configFile, lineNum, "rotate count", &start,
&buf, length); &buf, length);
if (key == NULL) if (key == NULL) {
continue; RAISE_ERROR();
}
newlog->rotateCount = (int)strtol(key, &chptr, 0); newlog->rotateCount = (int)strtol(key, &chptr, 0);
if (*chptr || newlog->rotateCount < -1) { if (*chptr || newlog->rotateCount < -1) {
message(MESS_ERROR, message(MESS_ERROR,
"%s:%d bad rotation count '%s'\n", "%s:%d bad rotation count '%s'\n",
configFile, lineNum, key); configFile, lineNum, key);
RAISE_ERROR(); RAISE_ERROR();
} }
} else if (!strcmp(key, "start")) { } else if (!strcmp(key, "start")) {
free(key); free(key);
key = isolateValue(configFile, lineNum, "start count", & start, key = isolateValue(configFile, lineNum, "start count", & start,
&buf, length); &buf, length);
if (key == NULL) if (key == NULL) {
continue; RAISE_ERROR();
}
newlog->logStart = (int)strtoul(key, &chptr, 0); newlog->logStart = (int)strtoul(key, &chptr, 0);
if (*chptr || newlog->logStart < 0) { if (*chptr || newlog->logStart < 0) {
message(MESS_ERROR, "%s:%d bad start count '%s'\n", message(MESS_ERROR, "%s:%d bad start count '%s'\n",
configFile, lineNum, key); configFile, lineNum, key);
RAISE_ERROR(); RAISE_ERROR();
} }
} else if (!strcmp(key, "minage")) { } else if (!strcmp(key, "minage")) {
free(key); free(key);
key = isolateValue(configFile, lineNum, "minage count", &start, key = isolateValue(configFile, lineNum, "minage count", &start,
&buf, length); &buf, length);
if (key == NULL) if (key == NULL) {
continue; RAISE_ERROR();
}
newlog->rotateMinAge = (int)strtoul(key, &chptr, 0); newlog->rotateMinAge = (int)strtoul(key, &chptr, 0);
if (*chptr || newlog->rotateMinAge < 0) { if (*chptr || newlog->rotateMinAge < 0) {
message(MESS_ERROR, "%s:%d bad minimum age '%s'\n", message(MESS_ERROR, "%s:%d bad minimum age '%s'\n",
configFile, lineNum, start); configFile, lineNum, start);
RAISE_ERROR(); RAISE_ERROR();
} }
} else if (!strcmp(key, "maxage")) { } else if (!strcmp(key, "maxage")) {
free(key); free(key);
key = isolateValue(configFile, lineNum, "maxage count", &start, key = isolateValue(configFile, lineNum, "maxage count", &start,
&buf, length); &buf, length);
if (key == NULL) if (key == NULL) {
continue; RAISE_ERROR();
}
newlog->rotateAge = (int)strtoul(key, &chptr, 0); newlog->rotateAge = (int)strtoul(key, &chptr, 0);
if (*chptr || newlog->rotateAge < 0) { if (*chptr || newlog->rotateAge < 0) {
message(MESS_ERROR, "%s:%d bad maximum age '%s'\n", message(MESS_ERROR, "%s:%d bad maximum age '%s'\n",
configFile, lineNum, start); configFile, lineNum, start);
RAISE_ERROR(); RAISE_ERROR();
} }
} else if (!strcmp(key, "errors")) { } else if (!strcmp(key, "errors")) {
message(MESS_DEBUG, message(MESS_NORMAL,
"%s: %d: the errors directive is deprecated and no longer used.\n", "%s: %d: the errors directive is deprecated and no longer used.\n",
configFile, lineNum); configFile, lineNum);
} else if (!strcmp(key, "mail")) { } else if (!strcmp(key, "mail")) {
freeLogItem(logAddress); freeLogItem(logAddress);
if (!(newlog->logAddress = readAddress(configFile, lineN um, if (!(newlog->logAddress = readAddress(configFile, lineN um,
"mail", &start, &buf, length))) { "mail", &start, &buf, length))) {
RAISE_ERROR(); RAISE_ERROR();
} }
else continue;
} else if (!strcmp(key, "nomail")) { } else if (!strcmp(key, "nomail")) {
freeLogItem(logAddress); freeLogItem(logAddress);
} else if (!strcmp(key, "missingok")) { } else if (!strcmp(key, "missingok")) {
newlog->flags |= LOG_FLAG_MISSINGOK; newlog->flags |= LOG_FLAG_MISSINGOK;
} else if (!strcmp(key, "nomissingok")) { } else if (!strcmp(key, "nomissingok")) {
newlog->flags &= ~LOG_FLAG_MISSINGOK; newlog->flags &= ~LOG_FLAG_MISSINGOK;
} else if (!strcmp(key, "prerotate")) { } else if (!strcmp(key, "prerotate")) {
freeLogItem (pre); freeLogItem (pre);
scriptStart = start; scriptStart = start;
scriptDest = &newlog->pre; scriptDest = &newlog->pre;
skipping to change at line 1423 skipping to change at line 1440
while (isspace((unsigned char)*endtag) && *endtag) while (isspace((unsigned char)*endtag) && *endtag)
endtag++; endtag++;
} else { } else {
free_2d_array(tabooPatterns, tabooCount); free_2d_array(tabooPatterns, tabooCount);
tabooCount = 0; tabooCount = 0;
/* realloc of NULL is safe by definition */ /* realloc of NULL is safe by definition */
tabooPatterns = NULL; tabooPatterns = NULL;
} }
while (*endtag) { while (*endtag) {
int bytes;
char *pattern = NULL; char *pattern = NULL;
chptr = endtag; chptr = endtag;
while (!isspace((unsigned char)*chptr) && *chptr != ',' && *chptr) while (!isspace((unsigned char)*chptr) && *chptr != ',' && *chptr)
chptr++; chptr++;
/* accept only non-empty patterns to avoid exclusion of everything */ /* accept only non-empty patterns to avoid exclusion of everything */
if (endtag < chptr) { if (endtag < chptr) {
char **tmp = realloc(tabooPatterns, sizeof(*tabo oPatterns) * char **tmp = realloc(tabooPatterns, sizeof(*tabo oPatterns) *
(tabooCount + 1)); (tabooCount + 1));
if (tmp == NULL) { if (tmp == NULL) {
message_OOM(); message_OOM();
RAISE_ERROR(); RAISE_ERROR();
} }
tabooPatterns = tmp; tabooPatterns = tmp;
bytes = asprintf(&pattern, "*%.*s", (int)(chptr if (asprintf(&pattern, "*%.*s", (int)(chptr - en
- endtag), endtag); dtag), endtag) < 0) {
message_OOM();
RAISE_ERROR();
}
/* should test for malloc() failure */
assert(bytes != -1);
tabooPatterns[tabooCount] = pattern; tabooPatterns[tabooCount] = pattern;
tabooCount++; tabooCount++;
} }
endtag = chptr; endtag = chptr;
if (*endtag == ',') if (*endtag == ',')
endtag++; endtag++;
while (*endtag && isspace((unsigned char)*endtag)) while (*endtag && isspace((unsigned char)*endtag))
endtag++; endtag++;
} }
skipping to change at line 1483 skipping to change at line 1500
while (isspace((unsigned char)*endtag) && *endtag) while (isspace((unsigned char)*endtag) && *endtag)
endtag++; endtag++;
} else { } else {
free_2d_array(tabooPatterns, tabooCount); free_2d_array(tabooPatterns, tabooCount);
tabooCount = 0; tabooCount = 0;
/* realloc of NULL is safe by definition */ /* realloc of NULL is safe by definition */
tabooPatterns = NULL; tabooPatterns = NULL;
} }
while (*endtag) { while (*endtag) {
int bytes;
char *pattern = NULL; char *pattern = NULL;
char **tmp; char **tmp;
chptr = endtag; chptr = endtag;
while (!isspace((unsigned char)*chptr) && *chptr != ',' && *chptr) while (!isspace((unsigned char)*chptr) && *chptr != ',' && *chptr)
chptr++; chptr++;
tmp = realloc(tabooPatterns, sizeof(*tabooPatterns) * tmp = realloc(tabooPatterns, sizeof(*tabooPatterns) *
(tabooCount + 1)); (tabooCount + 1));
if (tmp == NULL) { if (tmp == NULL) {
message_OOM(); message_OOM();
RAISE_ERROR(); RAISE_ERROR();
} }
tabooPatterns = tmp; tabooPatterns = tmp;
bytes = asprintf(&pattern, "%.*s", (int)(chptr - end if (asprintf(&pattern, "%.*s", (int)(chptr - endtag)
tag), endtag); , endtag) < 0) {
message_OOM();
RAISE_ERROR();
}
/* should test for malloc() failure */
assert(bytes != -1);
tabooPatterns[tabooCount] = pattern; tabooPatterns[tabooCount] = pattern;
tabooCount++; tabooCount++;
endtag = chptr; endtag = chptr;
if (*endtag == ',') if (*endtag == ',')
endtag++; endtag++;
while (*endtag && isspace((unsigned char)*endtag)) while (*endtag && isspace((unsigned char)*endtag))
endtag++; endtag++;
} }
} else if (!strcmp(key, "include")) { } else if (!strcmp(key, "include")) {
int rv; int rv;
free(key); free(key);
key = isolateValue(configFile, lineNum, "include", &star t, key = isolateValue(configFile, lineNum, "include", &star t,
&buf, length); &buf, length);
if (key == NULL) if (key == NULL) {
continue; RAISE_ERROR();
}
if (key[0] == '~' && key[1] == '/') { if (key[0] == '~' && key[1] == '/') {
/* replace '~' with content of $HOME cause low-level functions /* replace '~' with content of $HOME cause low-level functions
* like stat() do not support the glob ~ * like stat() do not support the glob ~
*/ */
const char *env_home = secure_getenv("HOME"); const char *env_home = secure_getenv("HOME");
char *new_key = NULL; char *new_key = NULL;
if (!env_home) { if (!env_home) {
const struct passwd *pwd = getpwuid(getuid()); const struct passwd *pwd = getpwuid(getuid());
skipping to change at line 1542 skipping to change at line 1560
configFile, lineNum); configFile, lineNum);
if (!pwd) { if (!pwd) {
message(MESS_ERROR, "%s:%d cannot get passwd entry for " message(MESS_ERROR, "%s:%d cannot get passwd entry for "
"running user %u: %s\n", "running user %u: %s\n",
configFile, lineNum, getuid(), strerr or(errno)); configFile, lineNum, getuid(), strerr or(errno));
RAISE_ERROR(); RAISE_ERROR();
} }
env_home = pwd->pw_dir; env_home = pwd->pw_dir;
} }
if (asprintf(&new_key, "%s/%s", env_home, key + 2) = = -1) { if (asprintf(&new_key, "%s/%s", env_home, key + 2) < 0) {
message_OOM(); message_OOM();
RAISE_ERROR(); RAISE_ERROR();
} }
message(MESS_DEBUG, "%s:%d replaced %s with '%s' for include directive\n", message(MESS_DEBUG, "%s:%d replaced %s with '%s' for include directive\n",
configFile, lineNum, key, env_home); configFile, lineNum, key, env_home);
free(key); free(key);
key = new_key; key = new_key;
} }
message(MESS_DEBUG, "including %s\n", key); message(MESS_DEBUG, "including %s\n", key);
skipping to change at line 1580 skipping to change at line 1598
if (!(newlog->oldDir = readPath(configFile, lineNum, if (!(newlog->oldDir = readPath(configFile, lineNum,
"olddir", &start, &buf, length))) { "olddir", &start, &buf, length))) {
RAISE_ERROR(); RAISE_ERROR();
} }
message(MESS_DEBUG, "olddir is now %s\n", newlog->oldDir ); message(MESS_DEBUG, "olddir is now %s\n", newlog->oldDir );
} else if (!strcmp(key, "extension")) { } else if (!strcmp(key, "extension")) {
free(key); free(key);
key = isolateValue(configFile, lineNum, "extension name" , &start, key = isolateValue(configFile, lineNum, "extension name" , &start,
&buf, length); &buf, length);
if (key == NULL) if (key == NULL) {
continue; RAISE_ERROR();
}
freeLogItem (extension); freeLogItem (extension);
newlog->extension = key; newlog->extension = key;
key = NULL; key = NULL;
message(MESS_DEBUG, "extension is now %s\n", newlog->ext ension); message(MESS_DEBUG, "extension is now %s\n", newlog->ext ension);
} else if (!strcmp(key, "addextension")) { } else if (!strcmp(key, "addextension")) {
free(key); free(key);
key = isolateValue(configFile, lineNum, "addextension na me", &start, key = isolateValue(configFile, lineNum, "addextension na me", &start,
&buf, length); &buf, length);
if (key == NULL) if (key == NULL) {
continue; RAISE_ERROR();
}
freeLogItem (addextension); freeLogItem (addextension);
newlog->addextension = key; newlog->addextension = key;
key = NULL; key = NULL;
message(MESS_DEBUG, "addextension is now %s\n", message(MESS_DEBUG, "addextension is now %s\n",
newlog->addextension); newlog->addextension);
} else if (!strcmp(key, "compresscmd")) { } else if (!strcmp(key, "compresscmd")) {
char *compresscmd_full; char *compresscmd_full;
const char *compresscmd_base; const char *compresscmd_base;
unsigned i; unsigned i;
skipping to change at line 1894 skipping to change at line 1914
message(MESS_DEBUG, message(MESS_DEBUG,
"%s:%d verifying log file " "%s:%d verifying log file "
"path failed %s: %s, log is probably missing, " "path failed %s: %s, log is probably missing, "
"but missingok is set, so this is no t an error.\n", "but missingok is set, so this is no t an error.\n",
configFile, lineNum, configFile, lineNum,
dirName, strerror(errno)); dirName, strerror(errno));
free(dirpath); free(dirpath);
continue; continue;
} }
} }
ld = malloc(strlen(dirName) + strlen(newlog->oldDir) if (asprintf(&ld, "%s/%s", dirName, newlog->oldDir)
+ 2); < 0) {
if (ld == NULL) {
message_OOM(); message_OOM();
free(dirpath); free(dirpath);
goto error; goto error;
} }
sprintf(ld, "%s/%s", dirName, newlog->oldDir);
free(dirpath); free(dirpath);
if (newlog->oldDir[0] != '/') { if (newlog->oldDir[0] != '/') {
dirName = ld; dirName = ld;
} }
else { else {
dirName = newlog->oldDir; dirName = newlog->oldDir;
} }
if (stat(dirName, &sb)) { if (stat(dirName, &sb)) {
skipping to change at line 2074 skipping to change at line 2093
* "start" points to the beginning of the next line. * "start" points to the beginning of the next line.
*/ */
if (*start != '\n') { if (*start != '\n') {
state = STATE_SKIP_LINE | STATE_SKIP_CONFIG; state = STATE_SKIP_LINE | STATE_SKIP_CONFIG;
} }
} }
} }
break; break;
default: default:
message(MESS_FATAL, message(MESS_FATAL,
"%s: %d: readConfigFile() unknown state\n", "%s: %d: readConfigFile() unknown state: %#x\n",
configFile, lineNum); configFile, lineNum, state);
} }
if (*start == '\n') { if (*start == '\n') {
lineNum++; lineNum++;
} }
next_state: ; next_state: ;
} }
if (scriptStart) { if (scriptStart) {
message(MESS_ERROR, message(MESS_ERROR,
"%s:prerotate, postrotate or preremove without endscript\n", "%s:prerotate, postrotate or preremove without endscript\n",
configFile); configFile);
goto error; goto error;
} }
free(key); free(key);
munmap(buf, length); munmap(buf, length);
close(fd); close(fd);
free(globerr_msg);
return logerror; return logerror;
error: error:
/* free is a NULL-safe operation */ /* free is a NULL-safe operation */
free(key); free(key);
munmap(buf, length); munmap(buf, length);
close(fd); close(fd);
free(globerr_msg);
return 1; return 1;
} }
/* vim: set et sw=4 ts=4: */ /* vim: set et sw=4 ts=4: */
 End of changes. 46 change blocks. 
74 lines changed or deleted 96 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)