1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
|
/* lookup_table.c --
* Copyright 2004-2008,2012-13,2016 Red Hat Inc., Durham, North Carolina.
* All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Authors:
* Steve Grubb <sgrubb@redhat.com>
* Rickard E. (Rik) Faith <faith@redhat.com>
*/
#include "config.h"
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include "libaudit.h"
#include "gen_tables.h"
#include "private.h"
#ifndef NO_TABLES
#ifdef WITH_ARM
#include "arm_tables.h"
#endif
#ifdef WITH_AARCH64
#include "aarch64_tables.h"
#endif
#include "i386_tables.h"
#include "ppc_tables.h"
#include "s390_tables.h"
#include "s390x_tables.h"
#include "x86_64_tables.h"
#include "errtabs.h"
#include "fstypetabs.h"
#include "ftypetabs.h"
#include "fieldtabs.h"
#endif
#include "msg_typetabs.h"
#include "actiontabs.h"
#include "flagtabs.h"
#include "machinetabs.h"
#include "optabs.h"
struct int_transtab {
int key;
unsigned int lvalue;
};
static const struct int_transtab elftab[] = {
{ MACH_X86, AUDIT_ARCH_I386 },
{ MACH_86_64, AUDIT_ARCH_X86_64 },
{ MACH_PPC64, AUDIT_ARCH_PPC64 },
{ MACH_PPC64LE, AUDIT_ARCH_PPC64LE},
{ MACH_PPC, AUDIT_ARCH_PPC },
{ MACH_S390X, AUDIT_ARCH_S390X },
{ MACH_S390, AUDIT_ARCH_S390 },
#ifdef WITH_ARM
{ MACH_ARM, AUDIT_ARCH_ARM },
#endif
#ifdef WITH_AARCH64
{ MACH_AARCH64, AUDIT_ARCH_AARCH64},
#endif
};
#define AUDIT_ELF_NAMES (sizeof(elftab)/sizeof(elftab[0]))
int audit_name_to_field(const char *field)
{
#ifndef NO_TABLES
int res;
if (field_s2i(field, &res) != 0)
return res;
#endif
return -1;
}
const char *audit_field_to_name(int field)
{
#ifndef NO_TABLES
return field_i2s(field);
#else
return NULL;
#endif
}
int audit_name_to_syscall(const char *sc, int machine)
{
int res = -1, found = 0;
switch (machine)
{
#ifndef NO_TABLES
case MACH_X86:
found = i386_syscall_s2i(sc, &res);
break;
case MACH_86_64:
found = x86_64_syscall_s2i(sc, &res);
break;
case MACH_PPC64:
case MACH_PPC64LE:
case MACH_PPC:
found = ppc_syscall_s2i(sc, &res);
break;
case MACH_S390X:
found = s390x_syscall_s2i(sc, &res);
break;
case MACH_S390:
found = s390_syscall_s2i(sc, &res);
break;
#ifdef WITH_ARM
case MACH_ARM:
found = arm_syscall_s2i(sc, &res);
break;
#endif
#ifdef WITH_AARCH64
case MACH_AARCH64:
found = aarch64_syscall_s2i(sc, &res);
break;
#endif
#endif
default:
return -1;
}
if (found)
return res;
return -1;
}
const char *audit_syscall_to_name(int sc, int machine)
{
#ifndef NO_TABLES
switch (machine)
{
case MACH_X86:
return i386_syscall_i2s(sc);
case MACH_86_64:
return x86_64_syscall_i2s(sc);
case MACH_PPC64:
case MACH_PPC64LE:
case MACH_PPC:
return ppc_syscall_i2s(sc);
case MACH_S390X:
return s390x_syscall_i2s(sc);
case MACH_S390:
return s390_syscall_i2s(sc);
#ifdef WITH_ARM
case MACH_ARM:
return arm_syscall_i2s(sc);
#endif
#ifdef WITH_AARCH64
case MACH_AARCH64:
return aarch64_syscall_i2s(sc);
#endif
}
#endif
return NULL;
}
int audit_name_to_flag(const char *flag)
{
int res;
if (flag_s2i(flag, &res) != 0)
return res;
return -1;
}
const char *audit_flag_to_name(int flag)
{
return flag_i2s(flag);
}
int audit_name_to_action(const char *action)
{
int res;
if (action_s2i(action, &res) != 0)
return res;
return -1;
}
const char *audit_action_to_name(int action)
{
return action_i2s(action);
}
// On the critical path for ausearch parser
int audit_name_to_msg_type(const char *msg_type)
{
int rc;
if (msg_type_s2i(msg_type, &rc) != 0)
return rc;
/* Take a stab at converting */
if (strncmp(msg_type, "UNKNOWN[", 8) == 0) {
int len;
char buf[8];
const char *end = strchr(msg_type + 8, ']');
if (end == NULL)
return -1;
len = end - (msg_type + 8);
if (len > 7)
len = 7;
memset(buf, 0, sizeof(buf));
strncpy(buf, msg_type + 8, len);
errno = 0;
return strtol(buf, NULL, 10);
} else if (isdigit(*msg_type)) {
errno = 0;
return strtol(msg_type, NULL, 10);
}
return -1;
}
const char *audit_msg_type_to_name(int msg_type)
{
return msg_type_i2s(msg_type);
}
int audit_name_to_machine(const char *machine)
{
int res;
if (machine_s2i(machine, &res) != 0)
return res;
return -1;
}
const char *audit_machine_to_name(int machine)
{
return machine_i2s(machine);
}
unsigned int audit_machine_to_elf(int machine)
{
unsigned int i;
for (i = 0; i < AUDIT_ELF_NAMES; i++)
if (elftab[i].key == machine)
return elftab[i].lvalue;
return 0;
}
int audit_elf_to_machine(unsigned int elf)
{
unsigned int i;
for (i = 0; i < AUDIT_ELF_NAMES; i++)
if (elftab[i].lvalue == elf) return elftab[i].key;
return -1;
}
const char *audit_operator_to_symbol(int op)
{
return op_i2s(op);
}
/* This function returns 0 on error, otherwise the converted value */
int audit_name_to_errno(const char *error)
{
#ifndef NO_TABLES
int rc, minus = 1;
if (*error == '-') {
minus = -1;
error++;
}
if (err_s2i(error, &rc) == 0)
rc = 0;
return rc*minus;
#else
return 0;
#endif
}
/* This function does not handle negative numbers yet */
const char *audit_errno_to_name(int error)
{
#ifndef NO_TABLES
if (error < 0)
return NULL;
return err_i2s(error);
#else
return NULL;
#endif
}
int audit_name_to_ftype(const char *name)
{
int res;
#ifndef NO_TABLES
if (ftype_s2i(name, &res) != 0)
return res;
#endif
return -1;
}
const char *audit_ftype_to_name(int ftype)
{
#ifndef NO_TABLES
return ftype_i2s(ftype);
#else
return NULL;
#endif
}
int audit_name_to_fstype(const char *name)
{
int res;
#ifndef NO_TABLES
if (fstype_s2i(name, &res) != 0)
return res;
#endif
return -1;
}
const char *audit_fstype_to_name(int fstype)
{
#ifndef NO_TABLES
return fstype_i2s(fstype);
#else
return NULL;
#endif
}
|