systoken.c revision 7883e825152992a0f20c3f52f7c4bb902a56205c
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Token processing for sysupd; each token function does one
* or more operations. All of them bump the buffer pointer
* to the next token; some of them extract one or more data
* from the token.
*/
#define DEBUG 0
#if DEBUG
#else
#define DPRINT(x)
#endif
#include <locale.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "toktable.h" /* ../praudit */
#include "sysplugin.h"
#include "systoken.h"
#include <audit_plugin.h>
#if DEBUG
#endif
static void anchor_path(char *);
size_t);
static void skip_bytes(parse_context_t *);
static void skip_string(parse_context_t *);
static int xgeneric(parse_context_t *);
/*
* Process a token in a record to (1) extract data of interest if any
* and (2) point to the next token.
*
* returns 0 if ok. + or - values are of debug value:
*
* returns -1 if the parsing of the token failed.
*
* returns +<previous id> if the token is not found. This value
* is used to help determine where in the record the problem
* occurred. The common failure case is that the parsing of
* token M is incorrect and the buffer pointer ends up pointing
* to garbage. The positive error value of M *may* be the id of
* the incorrectly parsed token.
*/
int
{
char tokenid;
static char prev_tokenid = -1;
int rc;
#if DEBUG
if (first) {
first = 0;
}
#endif
return (rc);
}
/* here if token id is not in table */
return (prev_tokenid);
}
/* There should not be any file tokens in the middle of a record */
/* ARGSUSED */
int
{
return (-1);
}
/* ARGSUSED */
int
{
return (-1);
}
static void
{
}
/*
* 32bit header
*/
int
{
return (0);
}
int
{
return (0);
}
int
{
return (0);
}
int
{
return (0);
}
/*
* ======================================================
* The following token processing routines return
* 0: if parsed ok
* -1: can't parse and can't determine location of next token
* ======================================================
*/
int
{
short magic_number;
if (magic_number != AUT_TRAILER_MAGIC)
return (-1);
return (0);
}
/*
* Format of arbitrary data token:
* arbitrary data token id &(ctx->adr) char
* how to print adr_char
* basic unit adr_char
* unit count adr_char, specifying number of units of
* data items depends on basic unit
*
*/
int
{
char basic_unit, unit_count;
switch (basic_unit) {
case AUR_CHAR: /* same as AUR_BYTE */
break;
case AUR_SHORT:
break;
case AUR_INT32: /* same as AUR_INT */
break;
case AUR_INT64:
break;
default:
return (-1);
break;
}
return (0);
}
/*
* Format of opaque token:
* opaque token id adr_char
* size adr_short
* data adr_char, size times
*
*/
int
{
return (0);
}
/*
* Format of return32 value token:
* return value token id adr_char
* error number adr_char
* return value adr_u_int32
*
*/
int
{
char errnum;
return (0);
}
/*
* Format of return64 value token:
* return value token id adr_char
* error number adr_char
* return value adr_u_int64
*
*/
int
{
char errnum;
return (0);
}
/*
* Format of sequence token:
* sequence token id adr_char
* audit_count int32_t
*
*/
int
{
return (0);
}
/*
* Format of text token:
* text token id adr_char
* text adr_string
*/
int
{
size_t separator_sz = 0;
char *bp; /* pointer to output string */
return (-1);
}
len--; /* includes EOS */
return (0);
}
/*
* Format of tid token:
* ip token id adr_char
* terminal type adr_char
* terminal type = AU_IPADR:
* remote port: ushort
* local port: ushort
* IP type: int32 -- AU_IPv4 or AU_IPv6
* address: int32 if IPv4, else 4 * int32
*/
int
{
switch (type) {
default:
return (-1); /* other than IP type is not implemented */
case AU_IPADR:
break;
}
return (0);
}
/*
* Format of ip_addr token:
* ip token id adr_char
* address adr_int32
*
*/
int
{
return (0);
}
/*
* Format of ip_addr_ex token:
* ip token id adr_char
* ip type adr_int32
* address 4*adr_int32
*
*/
int
{
return (0);
}
/*
* Format of ip token:
* ip header token id adr_char
* version adr_char
* type of service adr_char
* length adr_short
* id adr_u_short
* offset adr_u_short
* ttl adr_char
* protocol adr_char
* checksum adr_u_short
* source address adr_int32
* destination address adr_int32
*
*/
int
{
(3 * sizeof (short)) +
(2 * sizeof (char)) +
sizeof (short) +
(2 * sizeof (int32_t));
return (0);
}
/*
* Format of iport token:
* ip port address token id adr_char
* port address adr_short
*
*/
int
{
return (0);
}
/*
* Format of groups token:
* group token id adr_char
* group list adr_int32, 16 times
*
*/
int
{
return (0);
}
/*
* Format of newgroups token:
* group token id adr_char
* number of groups adr_short
* group list adr_int32, "number" times
*
*/
int
{
short int number;
return (0);
}
/*
* Format of argument32 token:
* argument token id adr_char
* argument number adr_char
* argument value adr_int32
* argument description adr_string
*
*/
int
{
return (0);
}
/*
* Format of argument64 token:
* argument token id adr_char
* argument number adr_char
* argument value adr_int64
* argument description adr_string
*
*/
int
{
return (0);
}
int
{
return (0);
}
/*
* Format of attribute token: (old pre SunOS 5.7 format)
* attribute token id adr_char
* mode adr_int32 (printed in octal)
* uid adr_int32
* gid adr_int32
* file system id adr_int32
* node id adr_int32
* device adr_int32
*
*/
int
{
return (0);
}
/*
* Format of attribute32 token:
* attribute token id adr_char
* mode adr_int32 (printed in octal)
* uid adr_int32
* gid adr_int32
* file system id adr_int32
* node id adr_int64
* device adr_int32
*
*/
int
{
return (0);
}
/*
* Format of attribute64 token:
* attribute token id adr_char
* mode adr_int32 (printed in octal)
* uid adr_int32
* gid adr_int32
* file system id adr_int32
* node id adr_int64
* device adr_int64
*
*/
int
{
return (0);
}
/*
* Format of command token:
* attribute token id adr_char
* argc adr_short
* argv len adr_short variable amount of argv len
* argv text argv len and text
* .
* .
* .
* envp count adr_short variable amount of envp len
* envp len adr_short and text
* envp text envp len
* .
* .
* .
*
*/
int
{
short cnt;
short i;
for (i = 0; i < cnt; i++)
for (i = 0; i < cnt; i++)
return (0);
}
/*
* Format of exit token:
* attribute token id adr_char
* return value adr_int32
* errno adr_int32
*
*/
int
{
return (0);
}
/*
* Format of exec_args token:
* attribute token id adr_char
* count value adr_int32
* strings null terminated strings
*
*/
int
{
int count, i;
for (i = 1; i <= count; i++) {
}
return (0);
}
/*
* Format of exec_env token:
* attribute token id adr_char
* count value adr_int32
* strings null terminated strings
*
*/
int
{
int count, i;
for (i = 1; i <= count; i++)
return (0);
}
/*
* Format of liaison token:
*/
int
{
return (0);
}
/*
* Format of path token:
* path adr_string
*/
int
{
0);
return (-1);
/*
* anchor the path because collapse_path needs it
*/
}
return (0);
}
/*
* path attr token / AUT_XATPATH
*
* Format of path attr token:
* token id adr_char
* string count adr_int32
* strings adr_string
*
* the sequence of strings is converted to a single string with
* a blank separator replacing the EOS for all but the last
* string.
*/
int
{
int count, i;
int last_len;
char *p;
for (i = 0; i <= count; i++) {
p += last_len + 1;
}
/* fix up: replace each eos except the last with ' ' */
for (i = 0; i < count; i++) {
while (*p++ != '\0');
*(p - 1) = ' ';
}
return (0);
}
/*
* Format of System V IPC permission token:
* System V IPC permission token id adr_char
* uid adr_int32
* gid adr_int32
* cuid adr_int32
* cgid adr_int32
* mode adr_int32
* seq adr_int32
* key adr_int32
* label adr_opaque, sizeof (bslabel_t)
* bytes
*/
int
{
#if TSOL
#endif
return (0);
}
static void
{
}
/*
* Format of process32 token:
* process token id adr_char
* auid adr_int32
* euid adr_int32
* egid adr_int32
* ruid adr_int32
* rgid adr_int32
* pid adr_int32
* sid adr_int32
* termid adr_int32*2
*
*/
int
{
return (0);
}
/*
* Format of process32_ex token:
* process token id adr_char
* auid adr_int32
* euid adr_int32
* egid adr_int32
* ruid adr_int32
* rgid adr_int32
* pid adr_int32
* sid adr_int32
* termid adr_int32*6
*
*/
int
{
return (0);
}
/*
* Format of process64 token:
* process token id adr_char
* auid adr_int32
* euid adr_int32
* egid adr_int32
* ruid adr_int32
* rgid adr_int32
* pid adr_int32
* sid adr_int32
* termid adr_int64+adr_int32
*
*/
int
{
return (0);
}
/*
* Format of process64 token:
* process token id adr_char
* auid adr_int32
* euid adr_int32
* egid adr_int32
* ruid adr_int32
* rgid adr_int32
* pid adr_int32
* sid adr_int32
* termid adr_int64+5*adr_int32
*
*/
int
{
return (0);
}
/*
* Format of System V IPC token:
* System V IPC token id adr_char
* System V IPC type adr_char
* object id adr_int32
*
*/
int
{
return (0);
}
/*
* Format of socket token:
* socket_type adrm_short
* remote_port adrm_short
* remote_inaddr adrm_int32
*
*/
int
{
return (0);
}
/*
* Format of socket token:
*
*/
int
{
short ip_size;
(ip_size * sizeof (char)) +
sizeof (short) +
(ip_size * sizeof (char));
return (0);
}
static void
{
}
/*
* Format of subject32 token:
* subject token id adr_char
* auid adr_int32
* euid adr_int32
* egid adr_int32
* ruid adr_int32
* rgid adr_int32
* pid adr_int32
* sid adr_int32
* termid adr_int32*2
*
*/
int
{
return (0);
}
/*
* Format of subject32_ex token:
* subject token id adr_char
* auid adr_int32
* euid adr_int32
* egid adr_int32
* ruid adr_int32
* rgid adr_int32
* pid adr_int32
* sid adr_int32
* termid_addr adr_int32*6
*
*/
int
{
return (0);
}
/*
* Format of subject64 token:
* subject token id adr_char
* auid adr_int32
* euid adr_int32
* egid adr_int32
* ruid adr_int32
* rgid adr_int32
* pid adr_int32
* sid adr_int32
* termid adr_int64+adr_int32
*
*/
int
{
return (0);
}
/*
* Format of subject64 token:
* subject token id adr_char
* auid adr_int32
* euid adr_int32
* egid adr_int32
* ruid adr_int32
* rgid adr_int32
* pid adr_int32
* sid adr_int32
* termid adr_int64+5*adr_int32
*
*/
int
{
return (0);
}
int
{
return (0);
}
int
{
return (0);
}
/*
* anchor a path name with a slash
* assume we have enough space
*/
static void
anchor_path(char *path)
{
*path = '/';
}
/*
* copy path to collapsed path.
* collapsed path does not contain:
* successive slashes
* instances of dot-slash
* instances of dot-dot-slash
* passed path must be anchored with a '/'
*/
static size_t
{
int id; /* index of where we are in destination string */
int is; /* index of where we are in source string */
int slashseen; /* have we seen a slash */
ls++; /* source length including '\0' */
slashseen = 0;
if (s[is] == '\0') {
--id;
}
s[id++] = '\0';
break;
}
/* previous character was a / */
if (slashseen) {
if (s[is] == '/')
continue; /* another slash, ignore it */
} else if (s[is] == '/') {
/* we see a /, just copy it and try again */
slashseen = 1;
s[id++] = '/';
continue;
}
/* /./ seen */
is += 1;
continue;
}
/* XXX/. seen */
if (id > 1)
id--;
continue;
}
/* XXX/.. seen */
is += 1;
if (id > 0)
id--;
id++;
continue;
}
/* XXX/../ seen */
is += 2;
if (id > 0)
id--;
id++;
continue;
}
is--;
}
}
/*
* for tokens with sub-fields that include a length, this
* skips the sub-field.
*/
static void
{
ushort_t c;
}
static void
{
char c;
do {
} while (c != (char)0);
}
/*
* add a byte to specified length so there can be a prefix of
* '/' added (if needed for paths). Another is added for '\0'
*
* if offset is zero, new data overwrites old, if any. Otherwise
* new data is appended to the end.
*/
static void
{
char *bp;
len++; /* in case need to add '/' prefix */
if (*p == NULL) {
perror("audit_sysudp.so");
return;
}
if (offset > 0)
offset--; /* overwrite end of string */
}
/*
* Format of host token:
* host adr_uint32
*/
int
{
return (0);
}
/*
* Format of useofauth token:
* uauth token id adr_char
* uauth adr_string
*
*/
int
{
return (0);
}
/*
* Format of zonename token:
* zonename token id adr_char
* zonename adr_string
*
*/
int
{
0);
return (0);
}
int
{
}
int
{
}
int
{
}
int
{
}
int
{
}
int
{
}
/*
* Format of xgeneric token:
* XID adr_int32
* creator UID adr_int32
*
* Includes: xcolormap, xcursor, xfont, xgc, xpixmap, and xwindow
*/
static int
{
return (0);
}
/*
* Format of xproperty token:
* XID adr_int32
* creator UID adr_int32
* atom string adr_string
*/
int
{
return (0);
}
/*
* Format of xclient token:
* xclient id adr_int32
*/
int
{
return (0);
}
/*
* Format of clearance token:
* clearance adr_char*(sizeof (bclear_t))
*
* ifdef TSOL because of bclear_t
*/
#ifndef TSOL
/* ARGSUSED */
#endif /* !TSOL */
int
{
#ifdef TSOL
return (0);
#else /* !TSOL */
return (-1);
#endif /* TSOL */
}
/*
* Format of ilabel token:
* ilabel adr_char*(sizeof (bilabel_t))
*/
#ifndef TSOL
/* ARGSUSED */
#endif /* !TSOL */
int
{
#ifdef TSOL
return (0);
#else /* !TSOL */
return (-1);
#endif /* TSOL */
}
/*
* -----------------------------------------------------------------------
* privilege_token() : Process privilege token and display contents
*
* Format of privilege token:
* privilege token id adr_char
* privilege type adr_string
* privilege adr_string
* -----------------------------------------------------------------------
*/
int
{
return (0);
}
/*
* Format of slabel token:
* slabel adr_char*(sizeof (bslabel_t))
*/
#ifndef TSOL
/* ARGSUSED */
#endif /* !TSOL */
int
{
#ifdef TSOL
return (0);
#else /* !TSOL */
return (-1);
#endif /* TSOL */
}
/*
* Format of useofpriv token:
* priv_type adr_char
* priv_set_t adr_short
* priv_set adr_char*(sizeof (priv_set_t))
*/
int
{
return (0);
}