/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-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> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* connect stream server support
*/
#include "csslib.h"
#include <dirent.h>
#if !defined(O_NONBLOCK) && defined(FNDELAY)
#endif
{
#ifdef SIGCHLD
#endif
};
/*
* catch interrupts
*/
static void
{
#endif
#ifdef SIGCHLD
#endif
}
/*
* called on exit
*/
static void
done(void)
{
}
/*
* drop fd ip
*/
static void
{
register int fd;
register int user;
if (!css)
{
{
fd = -1;
}
{
}
css->fdlistening--;
if (user)
else if (fd >= 0)
}
}
/*
* open the service
*/
{
int type;
int n;
char* s;
char* t;
{
n = OPEN_MIN;
return 0;
return 0;
}
n = 2 * CS_NAME_MAX;
return 0;
n = n / 2 + 1;
goto bad;
{
{
goto bad;
}
type = *s;
if (s = strchr(t, '/'))
*s = 0;
{
{
else
}
goto bad;
}
}
else
{
if ((css->disc->flags & CSS_AUTHENTICATE) && csopen(css->state, css->service, CS_OPEN_CREATE|CS_OPEN_MOUNT))
{
(*css->disc->errorf)(css, css->disc, ERROR_SYSTEM|3, "%s: cannot create authentication directory", css->service);
goto bad;
}
}
if ((css->disc->flags & CSS_DAEMON) && csdaemon(css->state, (css->disc->flags & CSS_PRESERVE) ? ~0L : ((1<<css->fd)|(1<<2))))
{
goto bad;
}
{
*s = 0;
{
goto bad;
}
{
goto bad;
}
*s = '/';
/*
* get the fid for the global and local authentication dirs
* authentication files can only be in these dirs and
* must not be symlinks -- symlinks can point to untrusted
* places and other dirs may get untrusted filesystems
* mounted via the automounter
*/
n = 0;
if (*--s == '/' && ++n >= 3)
break;
if (n != 3)
{
goto bad;
}
*s = 0;
{
goto bad;
}
*s = '/';
if (lstat(s, &st) && (mkdir(s, S_IRWXU|S_IRWXG|S_IRWXO) || chmod(s, S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO) || lstat(s, &st)))
{
goto bad;
}
if (type == 't' && *(css->control - 2) != CS_MNT_OTHER && *(css->control - 2) != '.' && *(css->control - 2) != '*')
{
CSTIME();
if (close(open(css->mount, O_WRONLY|O_CREAT|O_TRUNC, st.st_mode & (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH))) ||
{
(*css->disc->errorf)(css, css->disc, 3, "%s: cannot create service authentication file", css->mount);
goto bad;
}
}
if (type != 'f') s += sfsprintf(s, sizeof(css->buf) - (s - css->buf), "/n/%s", csname(css->state, 0));
{
close(2);
}
}
{
for (n = 0; n < elementsof(signals); n++)
}
CSTIME();
return css;
bad:
return 0;
}
/*
* close the service
*/
int
{
register int i;
register int k;
static char mnt[] =
{
};
pss = 0;
while (xss)
{
{
{
{
else
}
}
for (i = 0; i < elementsof(mnt); i++)
{
}
if (pss)
else
if (css)
return 0;
}
else
{
}
}
if (css)
return -1;
{
}
return 0;
}
/*
* file descriptor manipulation
*
* CS_POLL_DUP(n) move fd to n
* CS_POLL_MOVE(n) move fd to n
* CS_POLL_PRI(n) set fd priority (not yet)
* CS_POLL_CLOSE close+delete fd from table
* CS_POLL_AUTH|* authenticate then poll
* CS_POLL_* poll
* CS_POLL_USER| don't close unless CS_POLL_CLOSE
*/
{
register int n;
register int nfd;
register int cmd;
int flags;
#if DEBUG
#endif
if (!css)
return 0;
if (op == 0)
if (op & CS_POLL_ARG)
{
}
else
cmd = 0;
if (op != CS_POLL_CLOSE)
{
if (op & CS_POLL_AUTH)
{
op &= ~CS_POLL_AUTH;
}
if (op & CS_POLL_CONNECT)
{
op |= CS_POLL_READ;
}
for (n = 0;; n++)
{
{
return 0;
return 0;
{
}
css->fdlistening++;
#if DEBUG
goto show;
#else
return ip;
#endif
}
{
switch (cmd)
{
case 0:
return 0;
{
css->fdlistening--;
css->fdlistening++;
if (op & CS_POLL_WRITE)
{
#ifdef O_NONBLOCK
{
{
flags |= O_NONBLOCK;
}
}
#endif
}
}
break;
case CS_POLL_DUP:
/*ip->actionf = 0;*/
goto again;
case CS_POLL_MOVE:
return 0;
break;
case CS_POLL_PRI:
break;
}
#if DEBUG
show:
{
errorf(state.main->id, NiL, -9, "cssfd: pending=%d polling=%d next=%d fd=%d op=0x%08lx", state.fdpending, state.fdpolling, state.fdnext, ofd, oop);
errorf(state.main->id, NiL, -9, "cssfd: index=%d fd=%d events=%06o actionf=%p", n, state.fdpoll[n].fd, state.fdpoll[n].events, state.fdinfo[state.fdpoll[n].fd].actionf);
}
#endif
return ip;
}
}
}
{
{
break;
}
#if DEBUG
ip = 0;
goto show;
#endif
}
return 0;
}
/*
* poll for the next fd event
* some events may be pending from the last call
*/
{
register int fd;
char* s;
char* t;
int n;
int fdnew;
int status;
int to;
int oerrno;
int err;
int clrerr;
int sig;
int clrsig;
unsigned long key;
unsigned long z;
unsigned long timeout;
char** vp;
{
return 0;
}
timeout = 0;
else
for (;;)
{
{
CSTIME();
{
return 0;
}
{
{
}
{
else
pp++;
}
}
{
{
}
{
}
}
{
{
{
continue;
}
}
pp++;
}
{
clrsig = 0;
clrerr = 0;
}
else
{
err = 0;
sig = 0;
}
CSTIME();
else
z = to;
{
if (ms > z)
ms -= z;
else
}
{
{
else if (css->timeout_remain <= z)
{
}
else
css->timeout_remain -= z;
}
{
messagef((state.main->id, NiL, -4, "csspoll: pending=%d polling=%d z=%I*d wakeup=%I*d remain=%I*d", state.fdpending, state.fdpolling, sizeof(z), z, sizeof(css->disc->wakeup), css->disc->wakeup, sizeof(css->wakeup_remain), css->wakeup_remain));
if (css->wakeup_remain <= z)
{
}
else
css->wakeup_remain -= z;
}
if (err)
{
{
if (!sig)
clrerr = 1;
clrsig = 1;
}
{
clrerr = 1;
}
}
}
if (err && (ms != CS_NEVER || (flags & CSS_INTERRUPT) && (sig || err == EINTR) && !clrsig || (flags & CSS_ERROR) && !sig && err != EINTR && !clrerr))
{
return 0;
}
}
do
{
{
break;
}
messagef((state.main->id, NiL, -9, "csspoll: pending=%d polling=%d next=%d fd=%d status=%06o", state.fdpending, state.fdpolling, state.fdnext, fd, pp->status));
switch (status)
{
{
{
}
break;
}
/*FALLTHROUGH*/
case CS_POLL_CONNECT|CS_POLL_READ:
break;
case CS_POLL_AUTH|CS_POLL_READ:
{
case 1:
goto reject;
goto reject;
switch (key)
{
case CS_KEY_SEND:
goto reject;
break;
default:
if (key <= CS_KEY_MAX || key != css->newkey && key != css->oldkey || tokscan(t, NiL, "%ld", &ap->id.pid) != 1)
goto reject;
{
goto ok;
}
n = sfsprintf(css->tmp, sizeof(css->tmp), "%lu %lu\n", (unsigned long)ap->atime, (unsigned long)ap->mtime);
goto reject;
break;
}
break;
case 2:
goto reject;
*t++ = 0;
goto reject;
*s = 0;
goto reject;
*s = '/';
#if _UWIN
#else
#endif
break;
goto reject;
{
/*
* kick the NonFS cache
*/
goto reject;
*s = 0;
*s = '.';
goto reject;
}
goto reject;
ok:
goto reject;
{
*t++ = 0;
*vp = 0;
}
break;
default:
goto reject;
}
break;
case CS_POLL_READ|CS_POLL_WRITE:
case CS_POLL_WRITE:
/*FALLTHROUGH*/
case CS_POLL_READ:
messagef((state.main->id, NiL, -9, "csspoll: status=%06o fd=%d actionf=%p", status, fd, ip->actionf));
{
return ip;
}
if (n < 0)
goto reject;
break;
case CS_POLL_AUTH:
case CS_POLL_AUTH|CS_POLL_CONNECT:
case CS_POLL_CONNECT:
break;
case 0:
continue;
default:
break;
}
}
}