From 41e0a6587016e706d4666eec7337d908aff01fd5 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 10 Jul 2016 15:03:58 -0500 Subject: [PATCH] audit: add actual audit log I/O functions (ref #88) --- Makefile.am | 1 + libpkgconf/audit.c | 34 ++++++++++++++++++++++++++++++++++ libpkgconf/libpkgconf.h | 4 ++++ main.c | 3 +++ 4 files changed, 42 insertions(+) create mode 100644 libpkgconf/audit.c diff --git a/Makefile.am b/Makefile.am index 26dc4b6..9910dee 100644 --- a/Makefile.am +++ b/Makefile.am @@ -57,6 +57,7 @@ EXTRA_DIST = \ pkginclude_HEADERS = libpkgconf/bsdstubs.h libpkgconf/iter.h libpkgconf/libpkgconf.h libpkgconf/stdinc.h libpkgconf_la_SOURCES = \ + libpkgconf/audit.c \ libpkgconf/cache.c \ libpkgconf/pkg.c \ libpkgconf/bsdstubs.c \ diff --git a/libpkgconf/audit.c b/libpkgconf/audit.c new file mode 100644 index 0000000..e31505e --- /dev/null +++ b/libpkgconf/audit.c @@ -0,0 +1,34 @@ +/* + * audit.c + * package audit log functions + * + * Copyright (c) 2016 pkgconf authors (see AUTHORS). + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * This software is provided 'as is' and without any warranty, express or + * implied. In no event shall the authors be liable for any damages arising + * from the use of this software. + */ + +#include + +static FILE *pkgconf_auditf = NULL; + +void +pkgconf_audit_open_log(FILE *auditf) +{ + pkgconf_auditf = auditf; +} + +void +pkgconf_audit_log(const char *format, ...) +{ + va_list va; + + va_start(va, format); + vfprintf(pkgconf_auditf, format, va); + va_end(va); +} diff --git a/libpkgconf/libpkgconf.h b/libpkgconf/libpkgconf.h index f5b0ff2..c956294 100644 --- a/libpkgconf/libpkgconf.h +++ b/libpkgconf/libpkgconf.h @@ -206,4 +206,8 @@ void pkgconf_cache_add(pkgconf_pkg_t *pkg); void pkgconf_cache_remove(pkgconf_pkg_t *pkg); void pkgconf_cache_free(void); +/* audit.c */ +void pkgconf_audit_open_log(FILE *auditf); +void pkgconf_audit_log(const char *format, ...) PRINTFLIKE(1, 2); + #endif diff --git a/main.c b/main.c index 5b9016c..30232be 100644 --- a/main.c +++ b/main.c @@ -782,7 +782,10 @@ main(int argc, char *argv[]) logfile_arg = getenv("PKG_CONFIG_LOG"); if (logfile_arg != NULL) + { logfile_out = fopen(logfile_arg, "w"); + pkgconf_audit_open_log(logfile_out); + } if (required_module_version != NULL) {