init.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1989-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Eduardo Krell <ekrell@adexus.cl> *
* *
***********************************************************************/
#pragma prototyped
/*
* 3d file system initialization
*/
#include "3d.h"
static const char id[] =
"\n@(#)$Id: 3d [ "
#if DEBUG
"debug "
#endif
#if FS
"msg "
#endif
"safe "
#if VCS
"vcs "
#endif
"] (AT&T Research) 2012-06-25 $\0\n"
#else
"\n@(#)$Id: 3d (AT&T Research) 2011-06-25 $\0\n"
#endif
;
/*
* if _3d_2d!=0 && getenv(_3d_2d)==0 then 2d
*/
char* _3d_2d = 0;
/*
* 3d mount get and set access functions
*/
static int
{
register int n;
register int sum = 0;
register unsigned long x;
int m;
#if FS
#endif
{
if (buf)
{
if (fs->flags & FS_BOUND) n = sfsprintf(buf, 0, "%-*s", fs->servicesize ? fs->servicesize : strlen(fs->service), fs->service);
m = n;
#if FS
{
}
{
}
{
{
break;
}
}
n += sfsprintf(buf + n, 0, "/match=%-*s", fs->matchsize ? fs->matchsize : strlen(fs->match), fs->match);
{
}
#endif
{
{
}
n = 0;
}
{
buf += n++;
*buf++ = ' ';
}
else n = 0;
}
gs->specialsize +
fs->specialsize +
#if FS
#endif
6;
sum += n;
if (op)
{
break;
}
}
sum += n;
return(sum);
}
/*
* return mask for msg calls in state.key.*
*/
static unsigned long
getmsgmask(const char* e)
{
register char* s;
register char* t;
register int c;
register unsigned long x = ~0;
{
for (t = s; t < (char*)e; t++)
if (*t == '/')
break;
if (c = *t) *t = 0;
x = msgsetmask(s);
if (c) *t = c;
}
}
static int
{
register unsigned long x;
int n;
int old;
const char* oe;
#if FS
#endif
{
if (!*arg)
return(0);
}
{
old = 0;
}
{
return(0);
}
else old = 1;
if (*arg)
{
if (!fs->service || (fs->servicesize ? fs->servicesize : strlen(fs->service)) != n || strncmp(arg, fs->service, n))
{
}
}
switch (x)
{
break;
break;
break;
#if FS
break;
{
}
break;
break;
{
}
break;
break;
{
}
break;
if (!mp)
{
{
{
{
int n;
char* e;
}
}
}
}
{
}
break;
break;
{
void* dll;
{
}
}
break;
{
}
{
if (opsize)
{
}
}
break;
{
}
break;
{
}
break;
{
}
break;
break;
break;
break;
break;
break;
default:
break;
#endif
}
if (!old)
{
#if FS
#endif
}
return(0);
}
static int
{
register int n;
if (op) return(-1);
return(n);
}
static int
{
}
static int
{
register int n;
if (op) return(-1);
return(n);
}
static int
{
}
static int
{
register int n;
if (op)
return -1;
return n;
}
typedef int (*Init_f)(int, const char*, int);
static int
{
void* dll;
static const char sym[] = "_3d_init";
return -1;
if (argsize)
{
return -1;
}
{
return -1;
}
{
return -1;
}
}
#if FS
static void
bencode(char** b, char* e, register unsigned long n, int a, int r, int x)
{
register char* s;
register char* t;
register int m;
register int z;
char buf[16];
s = buf;
z = (1 << (r - (x != 0)));
do
{
m = n & ((1 << r) - 1);
*s++ = m + ((m >= z) ? x : a);
t = *b;
while (s > buf && t < e)
*t++ = *--s;
}
#endif
static int
{
register int c;
register int n;
register int sum = 0;
register unsigned long x;
char* b;
char* e;
int m;
/*
* table version
*/
{
if (buf)
{
buf += n;
}
sum += n;
}
/*
* trace output -- special case to capture redirection early
*/
{
if (buf)
{
n = sfsprintf(buf, 0, "%-*s /#%s/%s ", fs->servicesize ? fs->servicesize : strlen(fs->service), fs->service, state.fs[FS_fs].special, fs->special);
buf += n;
}
else n = (fs->servicesize ? fs->servicesize : strlen(fs->service)) + state.fs[FS_fs].specialsize + fs->specialsize + 4;
sum += n;
}
/*
* test mask
*/
{
if (buf)
{
buf += n;
}
sum += n;
}
/*
* readdir() view boundaries
*/
{
if (buf)
{
buf += n;
}
sum += n;
}
#if DEBUG
/*
* debug level
*/
{
if (buf)
{
buf += n;
}
sum += n;
}
#endif
/*
* license features
*/
{
if (buf)
{
buf += n;
}
sum += n;
}
/*
* 2d && 3d
*/
if (!x && (state.in_2d || state.limit < TABSIZE) || x == HASHKEY2(HASHKEYN('2'),'d') || x == HASHKEY2(HASHKEYN('3'),'d'))
{
if (buf)
{
n = (state.limit == TABSIZE) ? sfsprintf(buf, 0, "- /#%s/%cd ", fs->special, state.in_2d ? '2' : '3') : sfsprintf(buf, 0, "- /#%s/2d=%d ", fs->special, state.limit);
buf += n;
}
sum += n;
}
#if FS
/*
* file table
*/
{
c = -1;
{
}
{
if ((x = n - m - 1) > 0)
m = n;
}
*b = 0;
if (n)
{
if (buf)
{
buf += n;
}
sum += n;
}
}
#endif
/*
* fd table
*/
if (!x && (flags & (MAP_EXEC|MAP_INIT)) && state.table.fd != TABLE_FD || x == HASHKEY5('t','a','b','l','e'))
{
if (buf)
{
{
}
{
n = -1;
}
else
{
}
if (n < 0) n = 0;
else
{
buf += n;
}
}
sum += n;
}
/*
* syscall count
*/
{
if (buf)
{
buf += n;
}
sum += n;
}
/*
* syscall trace
*/
{
if (buf)
{
n = sfsprintf(buf, 0, "- /#%s/trace=%u ", fs->special, state.trace.pid + ((flags & (MAP_EXEC|MAP_INIT)) && state.trace.pid <= 2));
buf += n;
}
sum += n;
}
/*
* syscall calls
*/
{
if (buf)
{
buf += n++;
*buf++ = ' ';
}
sum += n;
}
#if FS
/*
* message timeout
*/
{
if (buf)
{
buf += n;
}
sum += n;
}
#endif
return(sum);
}
#define DUMP_call (1<<0)
/*
* dump Table_t
*/
static void
{
register int n;
{
{
}
}
}
/*
* dump internal state to option output
*/
static void
{
register char* e;
register int list;
register int n;
int on;
char* b;
else
{
list = 0;
for (;;)
{
{
case 0:
break;
continue;
continue;
continue;
continue;
list |= DUMP_mount;
continue;
continue;
list |= DUMP_state;
continue;
continue;
}
break;
}
if (!list) return;
}
if (list & DUMP_state)
{
{
bprintf(&b, e, " ");
}
#if DEBUG
#endif
#if LICENSED
#endif
}
{
bprintf(&b, e, "\nfs table\n\n");
{
else n -= 10 - 'a';
if (fs->flags & FS_BOUND) bprintf(&b, e, " service=%-*s", fs->servicesize ? fs->servicesize : strlen(fs->service), fs->service);
#if LICENSED
#endif
{
bprintf(&b, e, " call=");
}
{
bprintf(&b, e, " ack=");
}
{
bprintf(&b, e, " terse=");
}
bprintf(&b, e, "\n");
}
}
if (list & DUMP_mount)
{
bprintf(&b, e, "\nmount table\n\n");
{
else n -= 10 - 'a';
if (mp->logical) bprintf(&b, e, " logical=%-*s", mp->logicalsize ? mp->logicalsize : strlen(mp->logical), mp->logical);
if (mp->physical) bprintf(&b, e, " physical=%-*s", mp->physicalsize ? mp->physicalsize : strlen(mp->physical), mp->physical);
bprintf(&b, e, "\n");
}
}
{
bprintf(&b, e, "\nfile table\n\n");
{
if (mp)
{
else n -= 10 - 'a';
}
if (fp->id.fid[0] || fp->id.fid[1]) bprintf(&b, e, " fid=%ld%s%ld", fp->id.fid[0], fp->id.fid[1] >= 0 ? "+" : state.null, fp->id.fid[1]);
bprintf(&b, e, "\n");
}
}
}
#endif
static int
{
register int c;
register const char* oe;
register char* s;
int i;
int m;
long n;
#if FS
#endif
{
else
{
}
break;
break;
break;
break;
{
{
goto setout;
}
}
break;
#if DEBUG
c = error_info.trace;
{
if (!c)
{
errno = 0;
}
goto setout;
}
break;
#endif
break;
#endif
#if FS
n = -1;
m = 0;
while (s < oe)
{
long fid[2];
long off;
if ((c = *s++) >= '0' && c < '0' + 8)
{
i = c - '0';
i = (i << 3) + c - '0';
if (s >= oe) break;
n += i;
}
else n++;
fid[0] = 0;
while (c >= 'a' && c < 'a' + 16)
{
if (s >= oe) break;
c = *s++;
}
fid[1] = 0;
while (c >= 'A' && c < 'A' + 16)
{
if (s >= oe) break;
c = *s++;
}
off = 0;
while (c >= 'a' && c < 'a' + 16)
{
if (s >= oe) break;
c = *s++;
}
i = 0;
for (;;)
{
if (c >= 'Q' && c < 'Q' + 8)
i = (i << 4) + c - 'Q';
else if (c >= 'q' && c < 'q' + 8)
i = (i << 4) + c - 'q' + 8;
else break;
if (s >= oe) break;
c = *s++;
}
if (i) m = i;
{
}
}
break;
#endif
break;
{
}
break;
{
}
break;
break;
#endif
{
CLOSE(i);
}
break;
{
}
break;
#if FS
break;
break;
#endif
{
{
}
}
break;
return(-1);
break;
return(0);
}
static int
{
register int n = 0;
if (op) return(-1);
{
}
return(n);
}
/*
* set state.pwd from s
*/
static int
setpwd(register const char* s)
{
int osiz;
int olev;
return(-1);
{
return(-1);
}
if ((s = pathreal(state.pwd, 0, &pwd)) && (dot.st_ino == pwd.st_ino && dot.st_dev == pwd.st_dev || state.path.linkname && !STAT(state.path.name, &pwd) && dot.st_ino == pwd.st_ino && dot.st_dev == pwd.st_dev))
{
message((-1, "setpwd: state.pwd=%s state.level=%d state.path.level=%d", state.pwd, state.level, state.path.level));
return(0);
}
return(-1);
}
static int
{
int c;
int r;
return(0);
if (argsize)
{
}
else c = 0;
return(r);
}
static int
{
if (op) return(-1);
}
static int
{
}
/*
* set state.shell from s
*/
static int
setshell(register const char* s)
{
if (ACCESS(s, 1))
{
return(-1);
}
return(0);
}
/*
* static data initialization
*/
{
IDNAME, /* cmd */
".", /* dot */
"", /* null */
"1", /* one */
var_3d, /* env3d */
var_pwd, /* envpwd */
var_shell, /* envshell */
var_view, /* envview */
{
#if FS
#endif
/* NOTE: add internal mounts here */
#endif
},
"default", /* default instance name*/
".../...", /* opaque */
TABSIZE, /* limit */
};
/*
* note external control interrupt
*/
static void
{
}
/*
* handle external control interrupt
*/
void
control(void)
{
char* s;
int fd;
ssize_t n;
{
else
{
s = "/tmp/3d";
n = 0;
}
if (!n) n = strlen(s);
{
{
buf[n] = 0;
}
}
}
}
/*
* push system call intercept
*/
int
{
register int i;
for (i = 0;; i++)
{
return(-1);
break;
}
break;
return(0);
}
/*
* 3d initialization
*/
#define env_2d (1<<0)
#define var_cmd "_="
#define var_disable "_3D_DISABLE_="
#define var_home "HOME="
#define var_path "PATH="
int
{
register char* cp;
register int i;
char* home = 0;
int n;
int oerrno;
/*
* initialize the 3d state
*/
#if DEBUG
#endif
#if defined(SIGIO)
n = SIGIO;
#else
n = SIGPWR;
#endif
#endif
callinit();
{
}
/*
* extract the 3d tables from table.fd or the top of the environment
*/
i = 0;
if ((n = peek(TABLE_FD, state.table.buf, sizeof(state.table.buf) - 1)) > 0 && !mapinit(state.table.buf, 1))
{
}
else
{
{
ep++;
environ++;
}
}
else i |= env_2d;
/*
* look for remaining var_* not in env_* mask i
*/
{
{
return(0);
}
{
}
{
}
{
}
{
if (geteuid())
}
{
}
{
char* mp;
char* zp;
{
}
{
}
{
}
ep++;
}
{
{
if (!n)
{
static char msg[] = "3d: invalid PWD -- falling back to 2d\n";
}
}
}
{
}
{
{
#if DEBUG
#else
static char msg[] = "3d: . is not safe\n";
_exit(2);
#endif
}
}
return(0);
}