1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #include <sys/types.h> 28 #include <sys/systeminfo.h> 29 #include <bsm/audit.h> 30 #include <bsm/libbsm.h> 31 #include <bsm/audit_uevents.h> 32 #include <bsm/audit_private.h> 33 #include <unistd.h> 34 #include <stdlib.h> 35 #include <string.h> 36 37 #include <locale.h> 38 #include "generic.h" 39 40 #define AUDIT_AT_TEXTBUF 256 41 static char textbuf[AUDIT_AT_TEXTBUF]; 42 43 int 44 audit_at_create(char *path, int sorf) 45 { 46 int r = 0; 47 48 if (cannot_audit(0)) { 49 return (0); 50 } else { 51 char *anc_name; 52 auditinfo_addr_t ai; 53 54 if (getaudit_addr(&ai, sizeof (ai))) { 55 return (-1); 56 } 57 58 /* 59 * create an ancilary file if audit characteristics exist 60 */ 61 62 anc_name = audit_cron_make_anc_name(path); 63 if (anc_name == NULL) 64 r = -1; 65 else if (audit_crontab_process_not_audited()) 66 free(anc_name); 67 else { 68 r = audit_cron_setinfo(anc_name, &ai); 69 free(anc_name); 70 } 71 72 aug_init(); 73 aug_save_auid(ai.ai_auid); 74 aug_save_euid(geteuid()); 75 aug_save_egid(getegid()); 76 aug_save_uid(getuid()); 77 aug_save_gid(getgid()); 78 aug_save_pid(getpid()); 79 aug_save_asid(ai.ai_asid); 80 aug_save_tid_ex(ai.ai_termid.at_port, ai.ai_termid.at_addr, 81 ai.ai_termid.at_type); 82 83 aug_save_path(path); 84 aug_save_event(AUE_at_create); 85 aug_save_sorf(sorf); 86 87 if (aug_audit() != 0) 88 return (-1); 89 90 return (r); 91 } 92 } 93 94 int 95 audit_at_delete(char *name, char *path, int sorf) 96 { 97 int r = 0, err = 0; 98 char full_path[PATH_MAX]; 99 100 if (cannot_audit(0)) 101 return (0); 102 103 if (path != NULL) { 104 if (strlen(path) + strlen(name) + 2 > PATH_MAX) 105 r = -2; /* bad at-job name */ 106 else { 107 (void) strcat(strcat(strcpy(full_path, path), "/"), 108 name); 109 name = full_path; 110 } 111 } 112 113 if (sorf == 0) { 114 char *anc_name; 115 anc_name = audit_cron_make_anc_name(name); 116 r = unlink(anc_name); 117 if (r == -1) 118 err = errno; 119 free(anc_name); 120 } 121 122 aug_init(); 123 (void) aug_save_me(); 124 if (r == -1) { 125 (void) snprintf(textbuf, sizeof (textbuf), 126 dgettext(bsm_dom, "ancillary file: %s"), 127 strerror(err)); 128 aug_save_text(textbuf); 129 } else if (r == -2) { 130 aug_save_text( 131 dgettext(bsm_dom, "bad format of at-job name")); 132 } 133 134 aug_save_path(name); 135 aug_save_event(AUE_at_delete); 136 aug_save_sorf(sorf); 137 138 if (aug_audit() != 0) 139 return (-1); 140 return (r); 141 } 142