mschorm / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
3aff07c
--- util-linux-2.13-pre2/hwclock/hwclock.c.audit	2005-07-31 22:15:18.000000000 +0200
3aff07c
+++ util-linux-2.13-pre2/hwclock/hwclock.c	2005-08-30 11:11:11.000000000 +0200
169b953
@@ -81,9 +81,11 @@
169b953
 #include <stdarg.h>
169b953
 #include <getopt.h>
169b953
 #include <sysexits.h>
169b953
+#include <libaudit.h>
169b953
 
169b953
 #include "clock.h"
169b953
 #include "nls.h"
169b953
+#include "audit.h"
169b953
 
169b953
 #define MYNAME "hwclock"
169b953
 
169b953
@@ -1234,7 +1236,7 @@
169b953
     va_end(ap);
169b953
   }
169b953
  
169b953
-  exit(fmt ? EX_USAGE : 0);
169b953
+  audit_exit(fmt ? EX_USAGE : 0);
169b953
 }
169b953
 
169b953
 static const struct option longopts[] = {
3aff07c
@@ -1298,6 +1300,15 @@
169b953
 	/* Remember what time we were invoked */
169b953
 	gettimeofday(&startup_time, NULL);
169b953
 
169b953
+	audit_fd = audit_open();
3aff07c
+	if (audit_fd < 0 && !(errno == EINVAL || errno == EPROTONOSUPPORT ||
3aff07c
+				errno == EAFNOSUPPORT)) {
3aff07c
+		/* You get these error codes only when the kernel doesn't have
3aff07c
+	   	 * audit compiled in. */
169b953
+		fprintf(stderr, "Error - unable to connect to audit system\n");
169b953
+		return EX_NOPERM;
169b953
+	}
169b953
+
169b953
 	setlocale(LC_ALL, "");
169b953
 #ifdef LC_NUMERIC
169b953
 	/* We need LC_CTYPE and LC_TIME and LC_MESSAGES, but must avoid
3aff07c
@@ -1393,6 +1404,13 @@
169b953
 	argc -= optind;
169b953
 	argv += optind;
169b953
 
169b953
+	if (testing != TRUE) {
169b953
+		if (adjust == TRUE || hctosys == TRUE || systohc == TRUE ||
169b953
+			set == TRUE || setepoch == TRUE) {
169b953
+			auditable_event(1);
169b953
+		}
169b953
+	}
169b953
+
169b953
 	if (argc > 0) {
169b953
 		usage(_("%s takes no non-option arguments.  "
169b953
 			"You supplied %d.\n"),
3aff07c
@@ -1403,27 +1421,27 @@
169b953
 		fprintf(stderr, _("You have specified multiple functions.\n"
169b953
 				  "You can only perform one function "
169b953
 				  "at a time.\n"));
169b953
-		exit(EX_USAGE);
169b953
+		audit_exit(EX_USAGE);
169b953
 	}
169b953
 
169b953
 	if (utc && local_opt) {
169b953
 		fprintf(stderr, _("%s: The --utc and --localtime options "
169b953
 				  "are mutually exclusive.  You specified "
169b953
 				  "both.\n"), MYNAME);
169b953
-		exit(EX_USAGE);
169b953
+		audit_exit(EX_USAGE);
169b953
 	}
169b953
 
169b953
 	if (adjust && noadjfile) {
169b953
 		fprintf(stderr, _("%s: The --adjust and --noadjfile options "
169b953
 				  "are mutually exclusive.  You specified "
169b953
 				  "both.\n"), MYNAME);
169b953
-		exit(EX_USAGE);
169b953
+		audit_exit(EX_USAGE);
169b953
 	}
169b953
 
169b953
 	if (noadjfile && !(utc || local_opt)) {
169b953
 		fprintf(stderr, _("%s: With --noadjfile, you must specify "
169b953
 				  "either --utc or --localtime\n"), MYNAME);
169b953
-		exit(EX_USAGE);
169b953
+		audit_exit(EX_USAGE);
169b953
 	}
169b953
 
169b953
 #ifdef __alpha__
3aff07c
@@ -1437,7 +1455,7 @@
169b953
 		if (rc != 0) {
169b953
 			fprintf(stderr, _("No usable set-to time.  "
169b953
 					  "Cannot set clock.\n"));
169b953
-			exit(EX_USAGE);
169b953
+			audit_exit(EX_USAGE);
169b953
 		}
169b953
 	}
169b953
 
3aff07c
@@ -1469,11 +1487,11 @@
169b953
 	}
169b953
 
169b953
 	if (!permitted)
169b953
-		exit(EX_NOPERM);
169b953
+		audit_exit(EX_NOPERM);
169b953
 
169b953
 	if (getepoch || setepoch) {
169b953
 		manipulate_epoch(getepoch, setepoch, epoch_option, testing);
169b953
-		return 0;
169b953
+		audit_exit(0);
169b953
 	}
169b953
 
169b953
 	if (debug)
3aff07c
@@ -1487,12 +1505,14 @@
169b953
 			fprintf(stderr,
169b953
 				_("Use the --debug option to see the details "
169b953
 				  "of our search for an access method.\n"));
169b953
-		exit(1);
169b953
+		audit_exit(1);
169b953
 	}
169b953
 
169b953
-	return manipulate_clock(show, adjust, noadjfile, set, set_time,
169b953
+	rc = manipulate_clock(show, adjust, noadjfile, set, set_time,
169b953
 				hctosys, systohc, startup_time, utc,
169b953
 				local_opt, testing);
169b953
+	audit_exit(rc);
169b953
+	return rc;	/* Not reached */
169b953
 }
169b953
 
169b953
 /* A single routine for greater uniformity */
3aff07c
--- /dev/null	2005-08-29 11:11:19.415613608 +0200
3aff07c
+++ util-linux-2.13-pre2/hwclock/audit.c	2005-08-30 11:10:38.000000000 +0200
3aff07c
@@ -0,0 +1,73 @@
169b953
+/* audit.c -- This file contains the audit system extensions
169b953
+ *
169b953
+ * Copyright 2005 Red Hat Inc., Durham, North Carolina.
169b953
+ * All Rights Reserved.
169b953
+ *
169b953
+ * This program is free software; you can redistribute it and/or modify
169b953
+ * it under the terms of the GNU General Public License as published by
169b953
+ * the Free Software Foundation; either version 2 of the License, or
169b953
+ * (at your option) any later version.
169b953
+ *
169b953
+ * This program is distributed in the hope that it will be useful,
169b953
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
169b953
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
169b953
+ * GNU General Public License for more details.
169b953
+ *
169b953
+ * You should have received a copy of the GNU General Public License
169b953
+ * along with this program; if not, write to the Free Software
169b953
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
169b953
+ *
169b953
+ * Authors:
169b953
+ *     Steve Grubb <sgrubb@redhat.com>
169b953
+ */
169b953
+
169b953
+#include <stdio.h>
169b953
+#include <string.h>
169b953
+#include <stdlib.h>
169b953
+#include <unistd.h>
169b953
+#include <libaudit.h>
169b953
+#include "audit.h"
169b953
+
169b953
+int audit_fd = -1;
169b953
+
169b953
+/*
169b953
+ * This function will log a message to the audit system using a predefined
169b953
+ * message format. Parameter usage is as follows:
169b953
+ *
169b953
+ * op  -  operation. "adding user", "changing finger info", "deleting group"
169b953
+ * result - 0 = "success"  or  1 = "failed"
169b953
+ */
169b953
+static void audit_logger(const char *op, int result) 
169b953
+{
169b953
+	char msg_buf[256]; /* Common buffer for messaging */
169b953
+	const char *success;
169b953
+	extern char *progname;
169b953
+
3aff07c
+	if (audit_fd < 0)
3aff07c
+		return;		/* kernel without audit support */
3aff07c
+
169b953
+	if (!result)
169b953
+		success = "success";
169b953
+	else
169b953
+		success = "failed";
169b953
+
169b953
+	/* Add some audit info & log it.  */
169b953
+	snprintf(msg_buf, sizeof(msg_buf),
169b953
+		"%s: op=%s id=%u res=%s", progname, op, getuid(), success);
169b953
+	audit_send_user_message(audit_fd, AUDIT_USYS_CONFIG, msg_buf);
169b953
+	close(audit_fd);
169b953
+}
169b953
+
169b953
+static int audit_this = 0;
169b953
+void auditable_event(int i)
169b953
+{
169b953
+	audit_this = i;
169b953
+}
169b953
+
169b953
+void audit_exit(int status)
169b953
+{
169b953
+	if (audit_this)
169b953
+		audit_logger("changing system time", status);
169b953
+	exit(status);
169b953
+}
169b953
+
3aff07c
--- util-linux-2.13-pre2/hwclock/kd.c.audit	2005-07-31 18:01:20.000000000 +0200
3aff07c
+++ util-linux-2.13-pre2/hwclock/kd.c	2005-08-30 11:06:38.000000000 +0200
169b953
@@ -19,6 +19,7 @@
169b953
 
169b953
 #include "clock.h"
169b953
 #include "nls.h"
169b953
+#include "audit.h"
169b953
 
169b953
 static int con_fd = -1;		/* opened by probe_for_kd_clock() */
169b953
 				/* never closed */
169b953
@@ -103,7 +104,7 @@
169b953
 
169b953
   if (ioctl(con_fd, KDGHWCLK, &t) == -1) {
169b953
     outsyserr(_("ioctl() failed to read time from %s"), con_fd_filename);
169b953
-    exit(EX_IOERR);
169b953
+    audit_exit(EX_IOERR);
169b953
   }
169b953
 
169b953
   tm->tm_sec  = t.sec;
169b953
@@ -139,7 +140,7 @@
169b953
 
169b953
   if (ioctl(con_fd, KDSHWCLK, &t ) == -1) {
169b953
     outsyserr(_("ioctl KDSHWCLK failed"));
169b953
-    exit(1);
169b953
+    audit_exit(1);
169b953
   }
169b953
   return 0;
169b953
 }
3aff07c
--- util-linux-2.13-pre2/hwclock/Makefile.am.audit	2005-01-30 00:18:46.000000000 +0100
3aff07c
+++ util-linux-2.13-pre2/hwclock/Makefile.am	2005-08-30 11:06:38.000000000 +0200
169b953
@@ -4,4 +4,5 @@
169b953
 
169b953
 sbin_PROGRAMS = hwclock
169b953
 
169b953
-hwclock_SOURCES = hwclock.c cmos.c rtc.c kd.c
3aff07c
\ Chybí znak konce řádku na konci souboru
169b953
+hwclock_SOURCES = hwclock.c cmos.c rtc.c kd.c audit.c
169b953
+hwclock_LDADD = -laudit
3aff07c
\ Chybí znak konce řádku na konci souboru
3aff07c
--- /dev/null	2005-08-29 11:11:19.415613608 +0200
3aff07c
+++ util-linux-2.13-pre2/hwclock/audit.h	2005-08-30 11:06:38.000000000 +0200
169b953
@@ -0,0 +1,34 @@
169b953
+/* audit.h -- This file contains the function prototypes for audit calls
169b953
+ * Copyright 2005 Red Hat Inc., Durham, North Carolina.
169b953
+ * All Rights Reserved.
169b953
+ *
169b953
+ * This program is free software; you can redistribute it and/or modify
169b953
+ * it under the terms of the GNU General Public License as published by
169b953
+ * the Free Software Foundation; either version 2 of the License, or
169b953
+ * (at your option) any later version.
169b953
+ *
169b953
+ * This program is distributed in the hope that it will be useful,
169b953
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
169b953
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
169b953
+ * GNU General Public License for more details.
169b953
+ *
169b953
+ * You should have received a copy of the GNU General Public License
169b953
+ * along with this program; if not, write to the Free Software
169b953
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
169b953
+ *
169b953
+ * Author:
169b953
+ *   Steve Grubb <sgrubb@redhat.com>
169b953
+ *
169b953
+ */
169b953
+
169b953
+#ifndef HW_AUDIT_H
169b953
+#define HW_AUDIT_H
169b953
+
169b953
+/* This is the file descriptor used by the audit system */
169b953
+extern int audit_fd;
169b953
+
169b953
+/* This is the logging functions */
169b953
+void auditable_event(int i);
169b953
+void audit_exit(int status);
169b953
+
169b953
+#endif
3aff07c
--- util-linux-2.13-pre2/hwclock/clock.h.audit	2000-12-07 17:39:53.000000000 +0100
3aff07c
+++ util-linux-2.13-pre2/hwclock/clock.h	2005-08-30 11:06:38.000000000 +0200
169b953
@@ -24,7 +24,12 @@
169b953
 extern char *progname;
169b953
 extern int debug;
169b953
 extern int epoch_option;
169b953
-extern void outsyserr(char *msg, ...);
169b953
+extern void outsyserr(char *msg, ...)
169b953
+#ifdef __GNUC__
169b953
+        __attribute__ ((format (printf, 1, 2)));
169b953
+#else
169b953
+        ;
169b953
+#endif
169b953
 
169b953
 /* cmos.c */
169b953
 extern void set_cmos_epoch(int ARCconsole, int SRM);
3aff07c
--- util-linux-2.13-pre2/hwclock/rtc.c.audit	2005-07-31 22:15:45.000000000 +0200
3aff07c
+++ util-linux-2.13-pre2/hwclock/rtc.c	2005-08-30 11:06:38.000000000 +0200
169b953
@@ -8,6 +8,7 @@
169b953
 
169b953
 #include "clock.h"
169b953
 #include "nls.h"
169b953
+#include "audit.h"
169b953
 
169b953
 /*
169b953
  * Get defines for rtc stuff.
169b953
@@ -114,7 +115,7 @@
169b953
 
169b953
 	if (rtc_fd < 0) {
169b953
 		outsyserr(_("open() of %s failed"), rtc_dev_name);
169b953
-		exit(EX_OSFILE);
169b953
+		audit_exit(EX_OSFILE);
169b953
 	}
169b953
 	return rtc_fd;
169b953
 }
169b953
@@ -149,7 +150,7 @@
169b953
 		perror(ioctlname);
169b953
 		fprintf(stderr, _("ioctl() to %s to read the time failed.\n"),
169b953
 			rtc_dev_name);
169b953
-		exit(EX_IOERR);
169b953
+		audit_exit(EX_IOERR);
169b953
 	}
169b953
 
169b953
 	tm->tm_isdst = -1;          /* don't know whether it's dst */
169b953
@@ -329,7 +330,7 @@
169b953
 		perror(ioctlname);
169b953
 		fprintf(stderr, _("ioctl() to %s to set the time failed.\n"),
169b953
 			rtc_dev_name);
169b953
-		exit(EX_IOERR);
169b953
+		audit_exit(EX_IOERR);
169b953
 	}
169b953
 
169b953
 	if (debug)