-.\" $OpenBSD: pflogd.8,v 1.49 2017/05/30 17:15:06 schwarze Exp $
+.\" $OpenBSD: pflogd.8,v 1.50 2018/08/26 18:24:46 brynet Exp $
.\"
.\" Copyright (c) 2001 Can Erkin Acar. All rights reserved.
.\"
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd $Mdocdate: May 30 2017 $
+.Dd $Mdocdate: August 26 2018 $
.Dt PFLOGD 8
.Os
.Sh NAME
tries to preserve the integrity of the log file against I/O errors.
Furthermore, integrity of an existing log file is verified before
appending.
-If there is an invalid log file or an I/O error, the log file is moved
-out of the way and a new one is created.
-If a new file cannot be created, logging is suspended until a
+If there is an invalid log file or an I/O error, logging is suspended
+until a
.Dv SIGHUP
or a
.Dv SIGALRM
-/* $OpenBSD: pflogd.c,v 1.58 2017/09/09 13:02:52 brynet Exp $ */
+/* $OpenBSD: pflogd.c,v 1.59 2018/08/26 18:24:46 brynet Exp $ */
/*
* Copyright (c) 2001 Theo de Raadt
int if_exists(char *);
void logmsg(int, const char *, ...);
void purge_buffer(void);
-int reset_dump(int);
+int reset_dump(void);
int scan_dump(FILE *, off_t);
int set_snaplen(int);
void set_suspended(int);
void sig_hup(int);
void usage(void);
-static int try_reset_dump(int);
-
/* buffer must always be greater than snaplen */
static int bufpkt = 0; /* number of packets in buffer */
static int buflen = 0; /* allocated size of buffer */
}
int
-reset_dump(int nomove)
-{
- int ret;
-
- for (;;) {
- ret = try_reset_dump(nomove);
- if (ret <= 0)
- break;
- }
-
- return (ret);
-}
-
-/*
- * tries to (re)open log file, nomove flag is used with -x switch
- * returns 0: success, 1: retry (log moved), -1: error
- */
-int
-try_reset_dump(int nomove)
+reset_dump(void)
{
struct pcap_file_header hdr;
struct stat st;
}
} else if (scan_dump(fp, st.st_size)) {
fclose(fp);
- if (nomove || priv_move_log()) {
- logmsg(LOG_ERR,
- "Invalid/incompatible log file, move it away");
- return (-1);
- }
- return (1);
+ logmsg(LOG_ERR,
+ "Invalid/incompatible log file, move it away");
+ return (-1);
}
dpcap = fp;
bufpkt = 0;
}
- if (reset_dump(Xflag) < 0) {
+ if (reset_dump() < 0) {
if (Xflag)
return (1);
if (gotsig_close)
break;
if (gotsig_hup) {
- if (reset_dump(0)) {
+ int was_suspended = suspended;
+ if (reset_dump()) {
logmsg(LOG_ERR,
"Logging suspended: open error");
set_suspended(1);
+ } else {
+ if (was_suspended)
+ logmsg(LOG_NOTICE, "Logging resumed");
}
gotsig_hup = 0;
}
-/* $OpenBSD: privsep.c,v 1.30 2017/09/09 13:02:52 brynet Exp $ */
+/* $OpenBSD: privsep.c,v 1.31 2018/08/26 18:24:46 brynet Exp $ */
/*
* Copyright (c) 2003 Can Erkin Acar
enum cmd_types {
PRIV_INIT_PCAP, /* init pcap fdpass bpf */
PRIV_SET_SNAPLEN, /* set the snaplength */
- PRIV_MOVE_LOG, /* move logfile away */
PRIV_OPEN_LOG, /* open logfile for appending */
};
static void must_read(int, void *, size_t);
static void must_write(int, void *, size_t);
static int set_snaplen(int snap);
-static int move_log(const char *name);
extern char *filename;
extern char *interface;
filename, strerror(olderrno));
break;
- case PRIV_MOVE_LOG:
- logmsg(LOG_DEBUG,
- "[priv]: msg PRIV_MOVE_LOG received");
- ret = move_log(filename);
- must_write(socks[0], &ret, sizeof(int));
- break;
-
default:
logmsg(LOG_ERR, "[priv]: unknown command %d", cmd);
_exit(1);
return 0;
}
-static int
-move_log(const char *name)
-{
- char ren[PATH_MAX];
- int len;
-
- for (;;) {
- int fd;
-
- len = snprintf(ren, sizeof(ren), "%s.bad.XXXXXXXX", name);
- if (len >= sizeof(ren)) {
- logmsg(LOG_ERR, "[priv] new name too long");
- return (1);
- }
-
- /* lock destination */
- fd = mkstemp(ren);
- if (fd >= 0) {
- close(fd);
- break;
- }
- if (errno != EINTR) {
- logmsg(LOG_ERR, "[priv] failed to create new name: %s",
- strerror(errno));
- return (1);
- }
- }
-
- if (rename(name, ren)) {
- logmsg(LOG_ERR, "[priv] failed to rename %s to %s: %s",
- name, ren, strerror(errno));
- unlink(ren);
- return (1);
- }
-
- logmsg(LOG_NOTICE,
- "[priv]: log file %s moved to %s", name, ren);
-
- return (0);
-}
-
-
/* receive bpf fd from privileged process using fdpass and init pcap */
int
priv_init_pcap(int snaplen)
return (fd);
}
-/* Move-away and reopen log-file */
-int
-priv_move_log(void)
-{
- int cmd, ret;
-
- if (priv_fd < 0)
- errx(1, "%s: called from privileged portion", __func__);
-
- cmd = PRIV_MOVE_LOG;
- must_write(priv_fd, &cmd, sizeof(int));
- must_read(priv_fd, &ret, sizeof(int));
-
- return (ret);
-}
-
/* If priv parent gets a TERM or HUP, pass it through to child instead */
static void
sig_pass_to_chld(int sig)