1ca0716f5SRobert Watson /* 2ca0716f5SRobert Watson * Copyright (c) 2005 Apple Computer, Inc. 3ca0716f5SRobert Watson * All rights reserved. 4ca0716f5SRobert Watson * 5ca0716f5SRobert Watson * @APPLE_BSD_LICENSE_HEADER_START@ 6ca0716f5SRobert Watson * 7ca0716f5SRobert Watson * Redistribution and use in source and binary forms, with or without 8ca0716f5SRobert Watson * modification, are permitted provided that the following conditions 9ca0716f5SRobert Watson * are met: 10ca0716f5SRobert Watson * 11ca0716f5SRobert Watson * 1. Redistributions of source code must retain the above copyright 12ca0716f5SRobert Watson * notice, this list of conditions and the following disclaimer. 13ca0716f5SRobert Watson * 2. Redistributions in binary form must reproduce the above copyright 14ca0716f5SRobert Watson * notice, this list of conditions and the following disclaimer in the 15ca0716f5SRobert Watson * documentation and/or other materials provided with the distribution. 16ca0716f5SRobert Watson * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 17ca0716f5SRobert Watson * its contributors may be used to endorse or promote products derived 18ca0716f5SRobert Watson * from this software without specific prior written permission. 19ca0716f5SRobert Watson * 20ca0716f5SRobert Watson * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 21ca0716f5SRobert Watson * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22ca0716f5SRobert Watson * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23ca0716f5SRobert Watson * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 24ca0716f5SRobert Watson * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25ca0716f5SRobert Watson * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26ca0716f5SRobert Watson * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27ca0716f5SRobert Watson * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28ca0716f5SRobert Watson * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29ca0716f5SRobert Watson * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30ca0716f5SRobert Watson * 31ca0716f5SRobert Watson * @APPLE_BSD_LICENSE_HEADER_END@ 32ca0716f5SRobert Watson * 334bd0c025SRobert Watson * $P4: //depot/projects/trustedbsd/openbsm/bin/auditd/audit_warn.c#7 $ 34ca0716f5SRobert Watson */ 35ca0716f5SRobert Watson 36ca0716f5SRobert Watson #include <sys/types.h> 373b97a967SRobert Watson 38ca0716f5SRobert Watson #include <stdio.h> 393b97a967SRobert Watson #include <stdlib.h> 403b97a967SRobert Watson #include <unistd.h> 41ca0716f5SRobert Watson 42ca0716f5SRobert Watson #include "auditd.h" 43ca0716f5SRobert Watson 44ca0716f5SRobert Watson /* 45ca0716f5SRobert Watson * Write an audit-related error to the system log via syslog(3). 46ca0716f5SRobert Watson */ 47ca0716f5SRobert Watson static int 48ca0716f5SRobert Watson auditwarnlog(char *args[]) 49ca0716f5SRobert Watson { 50ca0716f5SRobert Watson char *loc_args[9]; 51ca0716f5SRobert Watson pid_t pid; 52ca0716f5SRobert Watson int i; 53ca0716f5SRobert Watson 54ca0716f5SRobert Watson loc_args[0] = AUDITWARN_SCRIPT; 55ca0716f5SRobert Watson for (i = 0; args[i] != NULL && i < 8; i++) 56ca0716f5SRobert Watson loc_args[i+1] = args[i]; 57ca0716f5SRobert Watson loc_args[i+1] = NULL; 58ca0716f5SRobert Watson 59ca0716f5SRobert Watson pid = fork(); 60ca0716f5SRobert Watson if (pid == -1) 61ca0716f5SRobert Watson return (-1); 62ca0716f5SRobert Watson if (pid == 0) { 63ca0716f5SRobert Watson /* 64ca0716f5SRobert Watson * Child. 65ca0716f5SRobert Watson */ 66ca0716f5SRobert Watson execv(AUDITWARN_SCRIPT, loc_args); 67ca0716f5SRobert Watson syslog(LOG_ERR, "Could not exec %s (%m)\n", 68ca0716f5SRobert Watson AUDITWARN_SCRIPT); 69ca0716f5SRobert Watson exit(1); 70ca0716f5SRobert Watson } 71ca0716f5SRobert Watson /* 72ca0716f5SRobert Watson * Parent. 73ca0716f5SRobert Watson */ 74ca0716f5SRobert Watson return (0); 75ca0716f5SRobert Watson } 76ca0716f5SRobert Watson 77ca0716f5SRobert Watson /* 78ca0716f5SRobert Watson * Indicates that the hard limit for all filesystems has been exceeded count 79ca0716f5SRobert Watson * times. 80ca0716f5SRobert Watson */ 81ca0716f5SRobert Watson int 82ca0716f5SRobert Watson audit_warn_allhard(int count) 83ca0716f5SRobert Watson { 84ca0716f5SRobert Watson char intstr[12]; 85ca0716f5SRobert Watson char *args[3]; 86ca0716f5SRobert Watson 87ca0716f5SRobert Watson snprintf(intstr, 12, "%d", count); 88ca0716f5SRobert Watson 89ca0716f5SRobert Watson args[0] = HARDLIM_ALL_WARN; 90ca0716f5SRobert Watson args[1] = intstr; 91ca0716f5SRobert Watson args[2] = NULL; 92ca0716f5SRobert Watson 93ca0716f5SRobert Watson return (auditwarnlog(args)); 94ca0716f5SRobert Watson } 95ca0716f5SRobert Watson 96ca0716f5SRobert Watson /* 97ca0716f5SRobert Watson * Indicates that the soft limit for all filesystems has been exceeded. 98ca0716f5SRobert Watson */ 99ca0716f5SRobert Watson int 100ca0716f5SRobert Watson audit_warn_allsoft(void) 101ca0716f5SRobert Watson { 102ca0716f5SRobert Watson char *args[2]; 103ca0716f5SRobert Watson 104ca0716f5SRobert Watson args[0] = SOFTLIM_ALL_WARN; 105ca0716f5SRobert Watson args[1] = NULL; 106ca0716f5SRobert Watson 107ca0716f5SRobert Watson return (auditwarnlog(args)); 108ca0716f5SRobert Watson } 109ca0716f5SRobert Watson 110ca0716f5SRobert Watson /* 111ca0716f5SRobert Watson * Indicates that someone other than the audit daemon turned off auditing. 112ca0716f5SRobert Watson * XXX Its not clear at this point how this function will be invoked. 113ca0716f5SRobert Watson * 114ca0716f5SRobert Watson * XXXRW: This function is not used. 115ca0716f5SRobert Watson */ 116ca0716f5SRobert Watson int 117ca0716f5SRobert Watson audit_warn_auditoff(void) 118ca0716f5SRobert Watson { 119ca0716f5SRobert Watson char *args[2]; 120ca0716f5SRobert Watson 121ca0716f5SRobert Watson args[0] = AUDITOFF_WARN; 122ca0716f5SRobert Watson args[1] = NULL; 123ca0716f5SRobert Watson 124ca0716f5SRobert Watson return (auditwarnlog(args)); 125ca0716f5SRobert Watson } 126ca0716f5SRobert Watson 127ca0716f5SRobert Watson /* 1284bd0c025SRobert Watson * Indicate that a trail file has been closed, so can now be post-processed. 1294bd0c025SRobert Watson */ 1304bd0c025SRobert Watson int 1314bd0c025SRobert Watson audit_warn_closefile(char *filename) 1324bd0c025SRobert Watson { 1334bd0c025SRobert Watson char *args[3]; 1344bd0c025SRobert Watson 1354bd0c025SRobert Watson args[0] = CLOSEFILE_WARN; 1364bd0c025SRobert Watson args[1] = filename; 1374bd0c025SRobert Watson args[2] = NULL; 1384bd0c025SRobert Watson 1394bd0c025SRobert Watson return (auditwarnlog(args)); 1404bd0c025SRobert Watson } 1414bd0c025SRobert Watson 1424bd0c025SRobert Watson /* 143ca0716f5SRobert Watson * Indicates that the audit deammn is already running 144ca0716f5SRobert Watson */ 145ca0716f5SRobert Watson int 146ca0716f5SRobert Watson audit_warn_ebusy(void) 147ca0716f5SRobert Watson { 148ca0716f5SRobert Watson char *args[2]; 149ca0716f5SRobert Watson 150ca0716f5SRobert Watson args[0] = EBUSY_WARN; 151ca0716f5SRobert Watson args[1] = NULL; 152ca0716f5SRobert Watson 153ca0716f5SRobert Watson return (auditwarnlog(args)); 154ca0716f5SRobert Watson } 155ca0716f5SRobert Watson 156ca0716f5SRobert Watson /* 157ca0716f5SRobert Watson * Indicates that there is a problem getting the directory from 158ca0716f5SRobert Watson * audit_control. 159ca0716f5SRobert Watson * 160ca0716f5SRobert Watson * XXX Note that we take the filename instead of a count as the argument here 161ca0716f5SRobert Watson * (different from BSM). 162ca0716f5SRobert Watson */ 163ca0716f5SRobert Watson int 164ca0716f5SRobert Watson audit_warn_getacdir(char *filename) 165ca0716f5SRobert Watson { 166ca0716f5SRobert Watson char *args[3]; 167ca0716f5SRobert Watson 168ca0716f5SRobert Watson args[0] = GETACDIR_WARN; 169ca0716f5SRobert Watson args[1] = filename; 170ca0716f5SRobert Watson args[2] = NULL; 171ca0716f5SRobert Watson 172ca0716f5SRobert Watson return (auditwarnlog(args)); 173ca0716f5SRobert Watson } 174ca0716f5SRobert Watson 175ca0716f5SRobert Watson /* 176ca0716f5SRobert Watson * Indicates that the hard limit for this file has been exceeded. 177ca0716f5SRobert Watson */ 178ca0716f5SRobert Watson int 179ca0716f5SRobert Watson audit_warn_hard(char *filename) 180ca0716f5SRobert Watson { 181ca0716f5SRobert Watson char *args[3]; 182ca0716f5SRobert Watson 183ca0716f5SRobert Watson args[0] = HARDLIM_WARN; 184ca0716f5SRobert Watson args[1] = filename; 185ca0716f5SRobert Watson args[2] = NULL; 186ca0716f5SRobert Watson 187ca0716f5SRobert Watson return (auditwarnlog(args)); 188ca0716f5SRobert Watson } 189ca0716f5SRobert Watson 190ca0716f5SRobert Watson /* 191ca0716f5SRobert Watson * Indicates that auditing could not be started. 192ca0716f5SRobert Watson */ 193ca0716f5SRobert Watson int 194ca0716f5SRobert Watson audit_warn_nostart(void) 195ca0716f5SRobert Watson { 196ca0716f5SRobert Watson char *args[2]; 197ca0716f5SRobert Watson 198ca0716f5SRobert Watson args[0] = NOSTART_WARN; 199ca0716f5SRobert Watson args[1] = NULL; 200ca0716f5SRobert Watson 201ca0716f5SRobert Watson return (auditwarnlog(args)); 202ca0716f5SRobert Watson } 203ca0716f5SRobert Watson 204ca0716f5SRobert Watson /* 205ca0716f5SRobert Watson * Indicaes that an error occrred during the orderly shutdown of the audit 206ca0716f5SRobert Watson * daemon. 207ca0716f5SRobert Watson */ 208ca0716f5SRobert Watson int 209ca0716f5SRobert Watson audit_warn_postsigterm(void) 210ca0716f5SRobert Watson { 211ca0716f5SRobert Watson char *args[2]; 212ca0716f5SRobert Watson 213ca0716f5SRobert Watson args[0] = POSTSIGTERM_WARN; 214ca0716f5SRobert Watson args[1] = NULL; 215ca0716f5SRobert Watson 216ca0716f5SRobert Watson return (auditwarnlog(args)); 217ca0716f5SRobert Watson } 218ca0716f5SRobert Watson 219ca0716f5SRobert Watson /* 220ca0716f5SRobert Watson * Indicates that the soft limit for this file has been exceeded. 221ca0716f5SRobert Watson */ 222ca0716f5SRobert Watson int 223ca0716f5SRobert Watson audit_warn_soft(char *filename) 224ca0716f5SRobert Watson { 225ca0716f5SRobert Watson char *args[3]; 226ca0716f5SRobert Watson 227ca0716f5SRobert Watson args[0] = SOFTLIM_WARN; 228ca0716f5SRobert Watson args[1] = filename; 229ca0716f5SRobert Watson args[2] = NULL; 230ca0716f5SRobert Watson 231ca0716f5SRobert Watson return (auditwarnlog(args)); 232ca0716f5SRobert Watson } 233ca0716f5SRobert Watson 234ca0716f5SRobert Watson /* 235ca0716f5SRobert Watson * Indicates that the temporary audit file already exists indicating a fatal 236ca0716f5SRobert Watson * error. 237ca0716f5SRobert Watson */ 238ca0716f5SRobert Watson int 239ca0716f5SRobert Watson audit_warn_tmpfile(void) 240ca0716f5SRobert Watson { 241ca0716f5SRobert Watson char *args[2]; 242ca0716f5SRobert Watson 243ca0716f5SRobert Watson args[0] = TMPFILE_WARN; 244ca0716f5SRobert Watson args[1] = NULL; 245ca0716f5SRobert Watson 246ca0716f5SRobert Watson return (auditwarnlog(args)); 247ca0716f5SRobert Watson } 248