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 (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved. 23 */ 24 25 #ifndef _BSM_LIBBSM_H 26 #define _BSM_LIBBSM_H 27 28 29 #include <ctype.h> 30 #include <secdb.h> 31 #include <stdio.h> 32 #include <errno.h> 33 #include <sys/types.h> 34 #include <bsm/audit.h> 35 #include <bsm/audit_record.h> 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 #ifndef TEXT_DOMAIN 42 #define TEXT_DOMAIN "SUNW_OST_OSLIB" 43 #endif 44 45 extern const char *bsm_dom; 46 47 /* 48 * For audit_event(5) 49 */ 50 struct au_event_ent { 51 au_event_t ae_number; 52 char *ae_name; 53 char *ae_desc; 54 au_class_t ae_class; 55 }; 56 typedef struct au_event_ent au_event_ent_t; 57 58 /* 59 * For audit_class(5) 60 */ 61 struct au_class_ent { 62 char *ac_name; 63 au_class_t ac_class; 64 char *ac_desc; 65 }; 66 typedef struct au_class_ent au_class_ent_t; 67 68 /* 69 * For audit_user(5) 70 */ 71 struct au_user_ent { 72 char *au_name; 73 au_mask_t au_always; 74 au_mask_t au_never; 75 }; 76 typedef struct au_user_ent au_user_ent_t; 77 78 /* 79 * Internal representation of audit user in libnsl 80 */ 81 typedef struct au_user_str_s { 82 char *au_name; 83 char *au_always; 84 char *au_never; 85 } au_user_str_t; 86 87 /* 88 * opaque context value for getacval.c 89 */ 90 typedef struct au_acinfo au_acinfo_t; 91 92 /* 93 * adrf's version of adr_t 94 */ 95 typedef struct adrf_s { 96 adr_t *adrf_adr; 97 FILE *adrf_fp; 98 } adrf_t; 99 100 /* 101 * Functions that manipulate bytes from an audit file 102 */ 103 104 extern void adr_char(adr_t *, char *, int); 105 extern int adr_count(adr_t *); 106 extern void adr_int32(adr_t *, int32_t *, int); 107 extern void adr_uid(adr_t *, uid_t *, int); 108 extern void adr_int64(adr_t *, int64_t *, int); 109 extern void adr_short(adr_t *, short *, int); 110 extern void adr_ushort(adr_t *, ushort_t *, int); 111 extern void adr_start(adr_t *, char *); 112 113 extern int adrf_char(adrf_t *, char *, int); 114 extern int adrf_int32(adrf_t *, int32_t *, int); 115 extern int adrf_int64(adrf_t *, int64_t *, int); 116 extern int adrf_short(adrf_t *, short *, int); 117 extern void adrf_start(adrf_t *, adr_t *, FILE *); 118 extern int adrf_u_char(adrf_t *, uchar_t *, int); 119 extern int adrf_u_int32(adrf_t *, uint32_t *, int); 120 extern int adrf_u_int64(adrf_t *, uint64_t *, int); 121 extern int adrf_u_short(adrf_t *, ushort_t *, int); 122 123 /* 124 * Functions that manipulate bytes from an audit character stream. 125 */ 126 127 extern void adrm_start(adr_t *, char *); 128 extern void adrm_char(adr_t *, char *, int); 129 extern void adrm_short(adr_t *, short *, int); 130 extern void adrm_int64(adr_t *, int64_t *, int); 131 extern void adrm_int32(adr_t *, int32_t *, int); 132 extern void adrm_uid(adr_t *, uid_t *, int); 133 extern void adrm_u_int32(adr_t *, uint32_t *, int); 134 extern void adrm_u_char(adr_t *, uchar_t *, int); 135 extern void adrm_u_int64(adr_t *, uint64_t *, int); 136 extern void adrm_u_short(adr_t *, ushort_t *, int); 137 extern void adrm_putint32(adr_t *, int32_t *, int); 138 139 /* 140 * Functions that do I/O for audit files 141 */ 142 143 extern int au_close(int, int, au_event_t); 144 extern int au_open(void); 145 extern int au_write(int, token_t *); 146 147 /* 148 * Functions than manipulate audit events 149 */ 150 151 extern void setauevent(void); 152 extern void endauevent(void); 153 154 extern au_event_ent_t *getauevent(void); 155 extern au_event_ent_t *getauevent_r(au_event_ent_t *); 156 extern au_event_ent_t *getauevnam(char *); 157 extern au_event_ent_t *getauevnam_r(au_event_ent_t *, char *); 158 extern au_event_ent_t *getauevnum(au_event_t); 159 extern au_event_ent_t *getauevnum_r(au_event_ent_t *, au_event_t); 160 extern au_event_t getauevnonam(char *); 161 extern int au_preselect(au_event_t, au_mask_t *, int, int); 162 extern int cacheauevent(au_event_ent_t **, au_event_t); 163 164 /* 165 * Functions that manipulate audit classes 166 */ 167 168 extern void setauclass(void); 169 extern void endauclass(void); 170 171 extern int cacheauclass(au_class_ent_t **, au_class_t); 172 extern int cacheauclassnam(au_class_ent_t **, char *); 173 extern au_class_ent_t *getauclassent(void); 174 extern au_class_ent_t *getauclassent_r(au_class_ent_t *); 175 extern au_class_ent_t *getauclassnam(char *); 176 extern au_class_ent_t *getauclassnam_r(au_class_ent_t *, char *); 177 178 /* 179 * Functions that manipulate the audit control file 180 */ 181 182 void endac(void); 183 void setac(void); 184 185 int getacdir(char *, int); 186 int getacmin(int *); 187 int getacna(char *, int); 188 int getacflg(char *, int); 189 190 /* 191 * Functions that manipulate the audit control file 192 */ 193 194 195 au_acinfo_t *_openac(char *); 196 void _endac(au_acinfo_t *); 197 void _rewindac(au_acinfo_t *); 198 199 int _getacdir(au_acinfo_t *, char *, int); 200 int _getaclib(au_acinfo_t *, kva_t **); 201 int _getacmin(au_acinfo_t *, int *); 202 int _getacna(au_acinfo_t *, char *, int); 203 int _getacflg(au_acinfo_t *, char *, int); 204 int _getacplug(au_acinfo_t *, kva_t **); 205 206 /* 207 * Functions that manipulate audit masks 208 */ 209 210 extern int au_user_mask(char *, au_mask_t *); 211 extern int getauditflagsbin(char *, au_mask_t *); 212 extern int getauditflagschar(char *, au_mask_t *, int); 213 extern int getfauditflags(au_mask_t *, au_mask_t *, au_mask_t *); 214 extern boolean_t __chkflags(char *, au_mask_t *, boolean_t, char **); 215 216 /* 217 * Functions that do system calls 218 */ 219 220 extern int audit(char *, int); 221 extern int auditon(int, caddr_t, int); 222 extern int auditdoor(int); 223 extern int getaudit(auditinfo_t *); 224 extern int getaudit_addr(auditinfo_addr_t *, int); 225 extern int getauid(au_id_t *); 226 extern int setaudit(auditinfo_t *); 227 extern int setaudit_addr(auditinfo_addr_t *, int); 228 extern int setauid(au_id_t *); 229 230 /* 231 * Defines for au_preselect(3) 232 */ 233 #define AU_PRS_SUCCESS 1 234 #define AU_PRS_FAILURE 2 235 #define AU_PRS_BOTH (AU_PRS_SUCCESS|AU_PRS_FAILURE) 236 237 #define AU_PRS_USECACHE 0 238 #define AU_PRS_REREAD 1 239 240 /* 241 * Defines for cacheauclass and cacheauevent 242 */ 243 #define AU_CACHE_FREE 0x0000 244 #define AU_CACHE_NAME 0x0001 245 #define AU_CACHE_NUMBER 0x0002 246 247 /* Flags for user-level audit routines: au_open, au_close, au_to_ */ 248 #define AU_TO_NO_WRITE 0 249 #define AU_TO_WRITE 1 250 251 /* system audit files for auditd */ 252 #define AUDITCLASSFILE "/etc/security/audit_class" 253 #define AUDITCONTROLFILE "/etc/security/audit_control" 254 #define AUDITEVENTFILE "/etc/security/audit_event" 255 #define AUDITUSERFILE "/etc/security/audit_user" 256 257 /* array sizes for audit library structures */ 258 #define AU_CLASS_NAME_MAX 8 259 #define AU_CLASS_DESC_MAX 72 260 #define AU_EVENT_NAME_MAX 30 261 #define AU_EVENT_DESC_MAX 50 262 #define AU_EVENT_LINE_MAX 256 263 264 /* 265 * Some macros used internally by the nsswitch code 266 */ 267 #define AUDITUSER_FILENAME "/etc/security/audit_user" 268 #define AUDITUSER_DB_NAME "audit_user.org_dir" 269 #define AUDITUSER_DB_NCOL 3 /* total columns */ 270 #define AUDITUSER_DB_NKEYCOL 1 /* total searchable columns */ 271 #define AUDITUSER_DB_TBLT "audit_user_tbl" 272 #define AUDITUSER_SUCCESS 0 273 #define AUDITUSER_PARSE_ERANGE 1 274 #define AUDITUSER_NOT_FOUND 2 275 276 #define AUDITUSER_COL0_KW "name" 277 #define AUDITUSER_COL1_KW "always" 278 #define AUDITUSER_COL2_KW "never" 279 280 /* 281 * indices of searchable columns 282 */ 283 #define AUDITUSER_KEYCOL0 0 /* name */ 284 285 286 #ifdef __cplusplus 287 } 288 #endif 289 290 #endif /* _BSM_LIBBSM_H */ 291