audit.c revision 171537
1249259Sdim/* 2249259Sdim * Copyright (c) 2005 Apple Computer, Inc. 3249259Sdim * All rights reserved. 4249259Sdim * 5249259Sdim * Redistribution and use in source and binary forms, with or without 6249259Sdim * modification, are permitted provided that the following conditions 7249259Sdim * are met: 8249259Sdim * 9249259Sdim * 1. Redistributions of source code must retain the above copyright 10249259Sdim * notice, this list of conditions and the following disclaimer. 11249259Sdim * 2. Redistributions in binary form must reproduce the above copyright 12249259Sdim * notice, this list of conditions and the following disclaimer in the 13249259Sdim * documentation and/or other materials provided with the distribution. 14249259Sdim * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 15249259Sdim * its contributors may be used to endorse or promote products derived 16249259Sdim * from this software without specific prior written permission. 17249259Sdim * 18249259Sdim * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 19249259Sdim * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20249259Sdim * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21249259Sdim * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 22249259Sdim * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23249259Sdim * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24249259Sdim * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25249259Sdim * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26249259Sdim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27249259Sdim * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28249259Sdim * 29249259Sdim * $P4: //depot/projects/trustedbsd/openbsm/bin/audit/audit.c#8 $ 30249259Sdim */ 31249259Sdim/* 32249259Sdim * Program to trigger the audit daemon with a message that is either: 33249259Sdim * - Open a new audit log file 34249259Sdim * - Read the audit control file and take action on it 35249259Sdim * - Close the audit log file and exit 36249259Sdim * 37249259Sdim */ 38249259Sdim 39249259Sdim#include <sys/types.h> 40249259Sdim#include <sys/queue.h> 41249259Sdim#include <sys/uio.h> 42249259Sdim 43249259Sdim#include <bsm/libbsm.h> 44249259Sdim 45249259Sdim#include <fcntl.h> 46249259Sdim#include <stdio.h> 47249259Sdim#include <stdlib.h> 48249259Sdim#include <unistd.h> 49249259Sdim 50249259Sdimstatic void 51249259Sdimusage(void) 52249259Sdim{ 53249259Sdim 54249259Sdim (void)fprintf(stderr, "Usage: audit -n | -s | -t \n"); 55249259Sdim exit(-1); 56249259Sdim} 57249259Sdim 58249259Sdim/* 59249259Sdim * Main routine to process command line options. 60249259Sdim */ 61249259Sdimint 62249259Sdimmain(int argc, char **argv) 63249259Sdim{ 64249259Sdim int ch; 65249259Sdim unsigned int trigger = 0; 66249259Sdim 67249259Sdim if (argc != 2) 68249259Sdim usage(); 69249259Sdim 70249259Sdim while ((ch = getopt(argc, argv, "nst")) != -1) { 71249259Sdim switch(ch) { 72249259Sdim 73249259Sdim case 'n': 74249259Sdim trigger = AUDIT_TRIGGER_ROTATE_USER; 75249259Sdim break; 76249259Sdim 77 case 's': 78 trigger = AUDIT_TRIGGER_READ_FILE; 79 break; 80 81 case 't': 82 trigger = AUDIT_TRIGGER_CLOSE_AND_DIE; 83 break; 84 85 case '?': 86 default: 87 usage(); 88 break; 89 } 90 } 91 if (auditon(A_SENDTRIGGER, &trigger, sizeof(trigger)) < 0) { 92 perror("Error sending trigger"); 93 exit(-1); 94 } else { 95 printf("Trigger sent.\n"); 96 exit (0); 97 } 98} 99