#include <sys/types.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/user.h>
#include <sys/vnode.h>
#include <sys/vfs.h>
#include <sys/kmem.h>
#include <sys/proc.h>
#include <sys/uio.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/pathname.h>
#include <sys/acct.h>
#include <c2/audit.h>
#include <c2/audit_kernel.h>
#include <c2/audit_record.h>
#include <sys/sysmacros.h>
#include <sys/atomic.h>
int
au_token_size(m)
token_t *m;
{
int i;
if (m == (token_t *)0)
return (0);
for (i = 0; m != (token_t *)0; m = m->next_buf)
i += m->len;
return (i);
}
token_t *
au_set(cp, size)
caddr_t cp;
uint_t size;
{
au_buff_t *head;
au_buff_t *tail;
au_buff_t *m;
uint_t l;
head = NULL;
tail = NULL;
while (size) {
m = au_get_buff();
l = MIN(size, AU_BUFSIZE);
bcopy(cp, memtod(m, char *), l);
m->len = l;
if (head)
tail->next_buf = m;
else
head = m;
tail = m;
size -= l;
cp += l;
}
return (head);
}
token_t *
au_append_token(chain, m)
token_t *chain;
token_t *m;
{
token_t *mbp;
if (chain == (token_t *)0)
return (m);
if (m == (token_t *)0)
return (chain);
for (mbp = chain; mbp->next_buf != (token_t *)0; mbp = mbp->next_buf)
;
mbp->next_buf = m;
return (chain);
}
void
audit_fixpath(struct audit_path *app, int len)
{
int id;
int is;
int cnt;
int slashseen;
char *s;
char c;
cnt = app->audp_cnt;
s = app->audp_sect[cnt - 1];
is = (app->audp_sect[cnt] - s) - len;
if (is <= 2)
is = 0;
slashseen = (is > 0);
for (id = is; ; is++) {
if ((c = s[is]) == '\0') {
if (id > 1 && s[id-1] == '/') {
--id;
}
s[id++] = '\0';
break;
}
if (slashseen) {
if (c == '/') {
continue;
}
} else if (c == '/') {
slashseen = 1;
s[id++] = c;
continue;
}
if (c == '.') {
if ((c = s[is+1]) == '\0') {
if (id > 1)
id--;
continue;
}
if (c == '/') {
is += 1;
continue;
}
if (c == '.' && (s[is+2] == '\0' || s[is+2] == '/')) {
is++;
if (id == 0 && cnt > 1) {
char *s_attr;
app->audp_cnt = --cnt;
s_attr = s;
s = app->audp_sect[cnt - 1];
id = s_attr - s;
is += id;
id--;
slashseen = 0;
continue;
}
if (id > 0)
id--;
while (id > 0 && s[id - 1] != '/')
id--;
continue;
}
}
for (;;) {
c = s[is++];
if (c == '\0' || c == '/')
break;
s[id++] = c;
}
slashseen = 0;
is -= 2;
}
if (id == 1 && cnt > 1) {
s[0] = '.';
s[1] = '\0';
id = 2;
}
app->audp_sect[cnt] = s + id;
}