audit.c revision 155518
1/*
2 * Copyright (c) 2005 Apple Computer, Inc.
3 * All rights reserved.
4 *
5 * @APPLE_BSD_LICENSE_HEADER_START@
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1.  Redistributions of source code must retain the above copyright
12 *     notice, this list of conditions and the following disclaimer.
13 * 2.  Redistributions in binary form must reproduce the above copyright
14 *     notice, this list of conditions and the following disclaimer in the
15 *     documentation and/or other materials provided with the distribution.
16 * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
17 *     its contributors may be used to endorse or promote products derived
18 *     from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 * @APPLE_BSD_LICENSE_HEADER_END@
32 *
33 * $P4: //depot/projects/trustedbsd/openbsm/bin/audit/audit.c#5 $
34 */
35/*
36 * Program to trigger the audit daemon with a message that is either:
37 *    - Open a new audit log file
38 *    - Read the audit control file and take action on it
39 *    - Close the audit log file and exit
40 *
41 */
42
43#include <sys/types.h>
44#include <sys/queue.h>
45#include <sys/uio.h>
46
47#include <bsm/audit.h>
48
49#include <fcntl.h>
50#include <stdio.h>
51#include <stdlib.h>
52#include <unistd.h>
53
54static void
55usage(void)
56{
57
58	(void)fprintf(stderr, "Usage: audit -n | -s | -t \n");
59	exit(-1);
60}
61
62/*
63 * Main routine to process command line options.
64 */
65int
66main(int argc, char **argv)
67{
68	int ch;
69	unsigned int trigger = 0;
70
71	if (argc != 2)
72		usage();
73
74	while ((ch = getopt(argc, argv, "nst")) != -1) {
75		switch(ch) {
76
77		case 'n':
78			trigger = AUDIT_TRIGGER_OPEN_NEW;
79			break;
80
81		case 's':
82			trigger = AUDIT_TRIGGER_READ_FILE;
83			break;
84
85		case 't':
86			trigger = AUDIT_TRIGGER_CLOSE_AND_DIE;
87			break;
88
89		case '?':
90		default:
91			usage();
92			break;
93		}
94	}
95	if (auditon(A_SENDTRIGGER, &trigger, sizeof(trigger)) < 0) {
96		perror("Error sending trigger");
97		exit(-1);
98	} else {
99		printf("Trigger sent.\n");
100		exit (0);
101	}
102}
103