[Fedora-directory-commits] ldapserver/ldap/servers/slapd log.c, 1.16, 1.17
Noriko Hosoi (nhosoi)
fedora-directory-commits at redhat.com
Wed Oct 3 20:17:24 UTC 2007
Author: nhosoi
Update of /cvs/dirsec/ldapserver/ldap/servers/slapd
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv24419
Modified Files:
log.c
Log Message:
Resolves: #304161
Summary: logrotation time of -1 causes hang
Change description:
1. slapd_log_audit_proc, slapd_log_error_proc_internal, and log_flush_buffer:
use absolute value of rotationtime_secs to calculate the rotationsyncclock.
2. when the result of "atoi" for nsslapd-XXX-logrotationtime is 0 due to the
invalid setting, logrotation time is reset to -1 (no rotation).
3. if nsslapd-XXX-logrotationtime and nsslapd-XXX-logexpirationtime is large
(near MAXINT) and calculated rotationtime_secs and/or exptime_secs is
overflown, set MAXINT to the sec value.
Index: log.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/log.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- log.c 17 Aug 2007 02:12:37 -0000 1.16
+++ log.c 3 Oct 2007 20:17:22 -0000 1.17
@@ -1050,6 +1050,10 @@
}
rtime = atoi(rtime_str);
+
+ if (0 == rtime) {
+ rtime = -1; /* Value Range: -1 | 1 to PR_INT32_MAX */
+ }
switch (logtype) {
case SLAPD_ACCESS_LOG:
@@ -1087,6 +1091,10 @@
value = -1;
}
+ if (rtime > 0 && value < 0) {
+ value = PR_INT32_MAX; /* overflown */
+ }
+
switch (logtype) {
case SLAPD_ACCESS_LOG:
fe_cfg->accesslog_rotationtime = rtime;
@@ -1116,7 +1124,7 @@
******************************************************************************/
int log_set_rotationtimeunit(const char *attrname, char *runit, int logtype, char *errorbuf, int apply)
{
- int value= 0;
+ int origvalue = 0, value = 0;
int runitType;
int rv = 0;
@@ -1150,15 +1158,15 @@
switch (logtype) {
case SLAPD_ACCESS_LOG:
LOG_ACCESS_LOCK_WRITE( );
- value = loginfo.log_access_rotationtime;
+ origvalue = loginfo.log_access_rotationtime;
break;
case SLAPD_ERROR_LOG:
LOG_ERROR_LOCK_WRITE( );
- value = loginfo.log_error_rotationtime;
+ origvalue = loginfo.log_error_rotationtime;
break;
case SLAPD_AUDIT_LOG:
LOG_AUDIT_LOCK_WRITE( );
- value = loginfo.log_audit_rotationtime;
+ origvalue = loginfo.log_audit_rotationtime;
break;
default:
rv = 1;
@@ -1166,23 +1174,27 @@
if (strcasecmp(runit, "month") == 0) {
runitType = LOG_UNIT_MONTHS;
- value *= 31 * 24 * 60 * 60;
+ value = origvalue * 31 * 24 * 60 * 60;
} else if (strcasecmp(runit, "week") == 0) {
runitType = LOG_UNIT_WEEKS;
- value *= 7 * 24 * 60 * 60;
+ value = origvalue * 7 * 24 * 60 * 60;
} else if (strcasecmp(runit, "day") == 0) {
runitType = LOG_UNIT_DAYS;
- value *= 24 * 60 * 60;
+ value = origvalue * 24 * 60 * 60;
} else if (strcasecmp(runit, "hour") == 0) {
runitType = LOG_UNIT_HOURS;
- value *= 3600;
+ value = origvalue * 3600;
} else if (strcasecmp(runit, "minute") == 0) {
runitType = LOG_UNIT_MINS;
- value *= 60;
+ value = origvalue * 60;
} else {
/* In this case we don't rotate */
runitType = LOG_UNIT_UNKNOWN;
- value = -1;
+ value = -1;
+ }
+
+ if (origvalue > 0 && value < 0) {
+ value = PR_INT32_MAX; /* overflown */
}
switch (logtype) {
@@ -1392,7 +1404,7 @@
return rv;
}
- exptime = atoi(exptime_str);
+ exptime = atoi(exptime_str); /* <= 0: no exptime */
switch (logtype) {
case SLAPD_ACCESS_LOG:
@@ -1429,9 +1441,12 @@
value = -1;
}
- if (value < rsec) {
+ if (value > 0 && value < rsec) {
value = rsec;
}
+ if (exptime > 0 && value < 0) {
+ value = PR_INT32_MAX; /* overflown */
+ }
switch (logtype) {
case SLAPD_ACCESS_LOG:
@@ -1534,7 +1549,7 @@
value = -1;
}
- if ((value> 0) && value < rsecs ) {
+ if ((value > 0) && value < rsecs) {
value = rsecs;
}
@@ -1693,7 +1708,7 @@
return 0;
}
while (loginfo.log_audit_rotationsyncclock <= loginfo.log_audit_ctime) {
- loginfo.log_audit_rotationsyncclock += loginfo.log_audit_rotationtime_secs;
+ loginfo.log_audit_rotationsyncclock += PR_ABS(loginfo.log_audit_rotationtime_secs);
}
}
if (loginfo.log_audit_state & LOGGING_NEED_TITLE) {
@@ -1743,7 +1758,7 @@
return 0;
}
while (loginfo.log_error_rotationsyncclock <= loginfo.log_error_ctime) {
- loginfo.log_error_rotationsyncclock += loginfo.log_error_rotationtime_secs;
+ loginfo.log_error_rotationsyncclock += PR_ABS(loginfo.log_error_rotationtime_secs);
}
}
@@ -2644,8 +2659,8 @@
if (loginfo.log_access_rotationsync_enabled &&
loginfo.log_access_rotationunit != LOG_UNIT_HOURS &&
loginfo.log_access_rotationunit != LOG_UNIT_MINS &&
- loginfo.log_access_ctime < loginfo.log_access_rotationsyncclock - loginfo.log_access_rotationtime_secs) {
- loginfo.log_access_rotationsyncclock -= loginfo.log_access_rotationtime_secs;
+ loginfo.log_access_ctime < loginfo.log_access_rotationsyncclock - PR_ABS(loginfo.log_access_rotationtime_secs)) {
+ loginfo.log_access_rotationsyncclock -= PR_ABS(loginfo.log_access_rotationtime_secs);
}
return logfile_type;
}
@@ -3365,8 +3380,8 @@
if (loginfo.log_error_rotationsync_enabled &&
loginfo.log_error_rotationunit != LOG_UNIT_HOURS &&
loginfo.log_error_rotationunit != LOG_UNIT_MINS &&
- loginfo.log_error_ctime < loginfo.log_error_rotationsyncclock - loginfo.log_error_rotationtime_secs) {
- loginfo.log_error_rotationsyncclock -= loginfo.log_error_rotationtime_secs;
+ loginfo.log_error_ctime < loginfo.log_error_rotationsyncclock - PR_ABS(loginfo.log_error_rotationtime_secs)) {
+ loginfo.log_error_rotationsyncclock -= PR_ABS(loginfo.log_error_rotationtime_secs);
}
return logfile_type;
@@ -3452,8 +3467,8 @@
if (loginfo.log_audit_rotationsync_enabled &&
loginfo.log_audit_rotationunit != LOG_UNIT_HOURS &&
loginfo.log_audit_rotationunit != LOG_UNIT_MINS &&
- loginfo.log_audit_ctime < loginfo.log_audit_rotationsyncclock - loginfo.log_audit_rotationtime_secs) {
- loginfo.log_audit_rotationsyncclock -= loginfo.log_audit_rotationtime_secs;
+ loginfo.log_audit_ctime < loginfo.log_audit_rotationsyncclock - PR_ABS(loginfo.log_audit_rotationtime_secs)) {
+ loginfo.log_audit_rotationsyncclock -= PR_ABS(loginfo.log_audit_rotationtime_secs);
}
return logfile_type;
@@ -3842,7 +3857,7 @@
return;
}
while (loginfo.log_access_rotationsyncclock <= loginfo.log_access_ctime) {
- loginfo.log_access_rotationsyncclock += loginfo.log_access_rotationtime_secs;
+ loginfo.log_access_rotationsyncclock += PR_ABS(loginfo.log_access_rotationtime_secs);
}
}
More information about the Fedora-directory-commits
mailing list