Import SJ3 2.0.1.20
Signed-off-by: Masanori Ogino <mogino@acm.org>
This commit is contained in:
commit
b568905e51
208 changed files with 89304 additions and 0 deletions
84
server/Imakefile
Normal file
84
server/Imakefile
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright (c) 1991-1994 Sony Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Except as contained in this notice, the name of Sony Corporation
|
||||
* shall not be used in advertising or otherwise to promote the sale, use
|
||||
* or other dealings in this Software without prior written authorization
|
||||
* from Sony Corporation.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $SonyRCSfile: Imakefile,v $
|
||||
* $SonyRevision: 1.3 $
|
||||
* $SonyDate: 1997/01/23 11:20:53 $
|
||||
*/
|
||||
|
||||
/*
|
||||
* Change some make rules.
|
||||
* Patched by Hidekazu Kuroki(hidekazu@cs.titech.ac.jp) 1996/8/10
|
||||
*/
|
||||
|
||||
#include "../sj3.tmpl"
|
||||
|
||||
CONFFILE = $(SJ3CONFDIR)/serverrc
|
||||
RKDIR = ../sj3lib
|
||||
|
||||
INCLUDES = -I../include
|
||||
#if SystemV4 || SystemV
|
||||
#if HasSockets
|
||||
EXTRA_LIBRARIES = -lnsl
|
||||
#endif
|
||||
#endif
|
||||
DEFINES = $(ARCDEFS) $(SYSDEFS) $(USETLI)
|
||||
|
||||
CONVLIB = ../kanakan/libkanakan.a
|
||||
DEPLIBS = $(CONVLIB)
|
||||
LOCAL_LIBRARIES = $(CONVLIB)
|
||||
INSTFLAGS = -o $(SJ3OWNER) -g $(SJ3GROUP) -m 4755
|
||||
XCOMM INSTFLAGS2 = -o $(SJ3OWNER) -g $(SJ3GROUP) -m 444
|
||||
|
||||
#MKDIRHIER = ../util/mkdirh/mkdirh
|
||||
|
||||
SRCS = comuni.c \
|
||||
error.c \
|
||||
execute.c \
|
||||
main.c \
|
||||
setup.c \
|
||||
time_stamp.c \
|
||||
version.c \
|
||||
../sj3lib/string.c
|
||||
|
||||
OBJS = comuni.o \
|
||||
error.o \
|
||||
execute.o \
|
||||
main.o \
|
||||
setup.o \
|
||||
time_stamp.o \
|
||||
version.o \
|
||||
string.o
|
||||
|
||||
AllTarget(sj3serv)
|
||||
NormalProgramTarget(sj3serv,$(OBJS),$(DEPLIBS),$(LOCAL_LIBRARIES),)
|
||||
DependTarget()
|
||||
LinkSourceFile(string.c,$(RKDIR))
|
||||
InstallProgramWithFlags(sj3serv,$(SJ3BINDIR),$(INSTFLAGS))
|
||||
InstallNonExecFile(serverrc,$(SJ3CONFDIR))
|
||||
870
server/comuni.c
Normal file
870
server/comuni.c
Normal file
|
|
@ -0,0 +1,870 @@
|
|||
/*
|
||||
* Copyright (c) 1991-1994 Sony Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Except as contained in this notice, the name of Sony Corporation
|
||||
* shall not be used in advertising or otherwise to promote the sale, use
|
||||
* or other dealings in this Software without prior written authorization
|
||||
* from Sony Corporation.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* $SonyRCSfile: comuni.c,v $
|
||||
* $SonyRevision: 1.4 $
|
||||
* $SonyDate: 1994/11/16 07:34:05 $
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include "sj_sysvdef.h"
|
||||
#include "sj_kcnv.h"
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
#include <setjmp.h>
|
||||
#include <errno.h>
|
||||
#ifdef SVR4
|
||||
#include <sys/filio.h>
|
||||
#include <sys/signal.h>
|
||||
#include <poll.h>
|
||||
#endif
|
||||
#ifdef TLI
|
||||
#include <fcntl.h>
|
||||
#include <tiuser.h>
|
||||
#include <stropts.h>
|
||||
#include <sys/types.h>
|
||||
#include <netdir.h>
|
||||
#include <netconfig.h>
|
||||
#endif
|
||||
|
||||
#ifdef SVR4
|
||||
#define signal sigset
|
||||
#endif
|
||||
|
||||
#if defined(__FD_SET) && !defined(FD_SET)
|
||||
# define FD_SET __FD_SET
|
||||
# define FD_ZERO __FD_ZERO
|
||||
# define FD_CLR __FD_CLR
|
||||
# define FD_ISSET __FD_ISSET
|
||||
#endif
|
||||
|
||||
#ifndef SOMAXCONN
|
||||
# define SOMAXCONN 5
|
||||
#endif
|
||||
|
||||
int client_num = 0;
|
||||
Client *client = NULL;
|
||||
Client *cur_client;
|
||||
|
||||
int maxfds = 0;
|
||||
#ifdef SVR4
|
||||
struct pollfd poll_fds[_NFILE];
|
||||
#else
|
||||
fd_set fds_org = { 0 };
|
||||
#endif
|
||||
jmp_buf client_dead;
|
||||
int client_fd;
|
||||
|
||||
extern char *socket_name;
|
||||
extern char *port_name;
|
||||
#ifdef TLI
|
||||
extern char *port_number;
|
||||
extern char *proto_name;
|
||||
#else
|
||||
extern int port_number;
|
||||
#endif
|
||||
extern int max_client;
|
||||
extern int errno;
|
||||
|
||||
static int fd_inet = -1;
|
||||
static int fd_unix = -1;
|
||||
|
||||
static char putbuf[BUFSIZ];
|
||||
static char getbuf[BUFSIZ];
|
||||
static int putpos = 0;
|
||||
static int buflen = 0;
|
||||
static int getpos = 0;
|
||||
|
||||
|
||||
|
||||
socket_init()
|
||||
{
|
||||
#ifdef SVR4
|
||||
int i;
|
||||
|
||||
for (i = 0; i < _NFILE; i++) {
|
||||
poll_fds[i].fd = -1;
|
||||
poll_fds[i].events = 0;
|
||||
poll_fds[i].revents = 0;
|
||||
}
|
||||
#else
|
||||
FD_ZERO(&fds_org);
|
||||
#endif
|
||||
client_num = 0;
|
||||
maxfds = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void set_fd(fd)
|
||||
int fd;
|
||||
{
|
||||
#ifdef SVR4
|
||||
poll_fds[maxfds].fd = fd;
|
||||
poll_fds[maxfds].events = POLLIN;
|
||||
maxfds++;
|
||||
#else
|
||||
FD_SET(fd, &fds_org);
|
||||
if (fd >= maxfds) maxfds = fd + 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void clr_fd(fd)
|
||||
int fd;
|
||||
{
|
||||
#ifdef SVR4
|
||||
register int i, j;
|
||||
|
||||
for (i = 0; i < maxfds; i++) {
|
||||
if (poll_fds[i].fd == fd) {
|
||||
maxfds--;
|
||||
for (j = i; j < maxfds; j++) {
|
||||
poll_fds[j].fd = poll_fds[j+1].fd;
|
||||
poll_fds[j].events = poll_fds[j+1].events;
|
||||
poll_fds[j].revents = poll_fds[j+1].revents;
|
||||
}
|
||||
poll_fds[j].fd = -1;
|
||||
poll_fds[j].events = 0;
|
||||
poll_fds[j].revents = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
FD_CLR(fd, &fds_org);
|
||||
if (maxfds == fd + 1) {
|
||||
while (--fd >= 0) {
|
||||
if (FD_ISSET(fd, &fds_org)) break;
|
||||
}
|
||||
maxfds = fd + 1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if (!defined(TLI) || (defined(TLI) && defined(SOCK_UNIX)))
|
||||
|
||||
|
||||
static void open_af_unix()
|
||||
{
|
||||
struct sockaddr_un sunix;
|
||||
|
||||
unlink(socket_name);
|
||||
|
||||
memset((char *)&sunix, '\0', sizeof(sunix));
|
||||
sunix.sun_family = AF_UNIX;
|
||||
strcpy(sunix.sun_path, socket_name);
|
||||
|
||||
if ((fd_unix = socket(AF_UNIX, SOCK_STREAM, 0)) == ERROR) {
|
||||
unlink(socket_name);
|
||||
fprintf(stderr, "Can't create AF_UNIX socket\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (bind(fd_unix, (struct sockaddr *)&sunix, strlen(sunix.sun_path) + 2) == ERROR) {
|
||||
if (errno == EADDRINUSE)
|
||||
fprintf(stderr, "Port '%s' is already in use\n",
|
||||
socket_name);
|
||||
else
|
||||
fprintf(stderr, "Can't bind AF_UNIX socket\n");
|
||||
shutdown(fd_unix, 2);
|
||||
close(fd_unix);
|
||||
unlink(socket_name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (listen(fd_unix, SOMAXCONN) == ERROR) {
|
||||
shutdown(fd_unix, 2);
|
||||
unlink(socket_name);
|
||||
close(fd_unix);
|
||||
fprintf(stderr, "Can't listen AF_UNIX socket\n");
|
||||
exit(1);
|
||||
}
|
||||
set_fd(fd_unix);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TLI
|
||||
struct t_call *inet_callptr;
|
||||
struct netconfig *nconf;
|
||||
#endif
|
||||
|
||||
|
||||
static void open_af_inet()
|
||||
{
|
||||
#ifdef TLI
|
||||
struct t_bind *req;
|
||||
struct nd_hostserv hserv;
|
||||
struct nd_addrlist *addrs;
|
||||
struct t_optmgmt *opt;
|
||||
struct opthdr *hdr;
|
||||
void *handlep;
|
||||
extern int t_errno;
|
||||
extern void *setnetpath();
|
||||
extern struct netconfig *getnetpath();
|
||||
#else
|
||||
struct sockaddr_in sin;
|
||||
struct servent *sp;
|
||||
u_short port;
|
||||
#endif
|
||||
int true = 1;
|
||||
|
||||
|
||||
#ifdef TLI
|
||||
if (( handlep = setnetpath()) == NULL) {
|
||||
fprintf(stderr, "Setnetpath fail\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while((nconf = getnetpath(handlep)) != NULL) {
|
||||
if ((nconf->nc_semantics == NC_TPI_COTS_ORD) &&
|
||||
(strncmp(nconf->nc_proto, proto_name, strlen(proto_name)) == 0))
|
||||
break;
|
||||
}
|
||||
if (nconf == NULL) {
|
||||
fprintf(stderr, "No connection mode transport\n");
|
||||
exit(1);
|
||||
}
|
||||
hserv.h_host = HOST_SELF;
|
||||
hserv.h_serv = port_number;
|
||||
if (netdir_getbyname(nconf, &hserv, &addrs) != 0) {
|
||||
hserv.h_serv = port_name;
|
||||
if (netdir_getbyname(nconf, &hserv, &addrs) != 0) {
|
||||
fprintf(stderr, "Can't get address\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if ((fd_inet = t_open(nconf->nc_device, O_RDWR, (struct t_info *) NULL)) < 0) {
|
||||
fprintf(stderr,"Can't t_open\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ((opt = (struct t_optmgmt *) t_alloc(fd_inet, T_OPTMGMT, T_ALL)) == NULL) {
|
||||
fprintf(stderr, "Can't t_alloc error for T_OPTMGT\n");
|
||||
exit(1);
|
||||
}
|
||||
if ((hdr = (struct opthdr *) malloc(sizeof(*hdr) + sizeof(true))) == NULL) {
|
||||
fprintf(stderr, "server: not malloc\n");
|
||||
exit(1);
|
||||
}
|
||||
hdr->level = SOL_SOCKET;
|
||||
hdr->name = SO_REUSEADDR;
|
||||
hdr->len = sizeof(true);
|
||||
|
||||
(void) memcpy(&true, (char *)hdr + sizeof(*hdr), sizeof(true));
|
||||
|
||||
opt->opt.len = opt->opt.maxlen = sizeof(*hdr) + sizeof(true);
|
||||
opt->flags = T_CHECK;
|
||||
opt->opt.buf = (char *)hdr;
|
||||
|
||||
if ((t_optmgmt(fd_inet, opt, opt) < 0) || !(opt->flags & T_SUCCESS)){
|
||||
fprintf(stderr, "Warning: Can't reuse address %s(%s)\n",
|
||||
port_name, port_number);
|
||||
} else {
|
||||
opt->flags = T_NEGOTIATE;
|
||||
|
||||
(void) memcpy(&true, (char *)hdr + sizeof(*hdr), sizeof(true));
|
||||
(void) t_optmgmt(fd_inet, opt, opt);
|
||||
}
|
||||
|
||||
if ((req = (struct t_bind *) t_alloc(fd_inet, T_BIND, T_ALL)) == NULL) {
|
||||
t_close(fd_inet);
|
||||
fprintf(stderr, "Can't alloc bind data\n");
|
||||
exit(1);
|
||||
}
|
||||
req->addr.maxlen = addrs->n_addrs->maxlen;
|
||||
req->addr.len = addrs->n_addrs->len;
|
||||
|
||||
(void) memcpy(addrs->n_addrs->buf, req->addr.buf, addrs->n_addrs->len);
|
||||
req->qlen = 5;
|
||||
|
||||
if (t_bind(fd_inet, req, req) < 0 ) {
|
||||
fprintf(stderr, "Can't t_bind\n");
|
||||
t_close(fd_inet);
|
||||
exit(1);
|
||||
}
|
||||
if (memcmp(req->addr.buf, addrs->n_addrs->buf, addrs->n_addrs->len) != 0) {
|
||||
fprintf(stderr, "Port '%s(%s)' is already in use\n",
|
||||
port_name, port_number);
|
||||
t_close(fd_inet);
|
||||
exit(1);
|
||||
}
|
||||
if ((inet_callptr = (struct t_call *) t_alloc(fd_inet, T_CALL, T_ALL)) == NULL) {
|
||||
fprintf(stderr,"t_alloc error for T_CALL\n");
|
||||
t_close(fd_inet);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
inet_callptr->addr = *(addrs->n_addrs);
|
||||
|
||||
|
||||
inet_callptr->udata.maxlen = 0;
|
||||
inet_callptr->udata.len = 0;
|
||||
inet_callptr->udata.buf = (char *) NULL;
|
||||
#else
|
||||
if (sp = getservbyname(port_name, "tcp"))
|
||||
port = ntohs(sp -> s_port);
|
||||
else
|
||||
port = port_number;
|
||||
|
||||
memset((char *)&sin, '\0', sizeof(sin));
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_port = htons(port);
|
||||
sin.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
|
||||
if ((fd_inet = socket(AF_INET, SOCK_STREAM, 0)) == ERROR) {
|
||||
fprintf(stderr, "Can't create AF_INET socket\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
setsockopt(fd_inet, SOL_SOCKET, SO_REUSEADDR, &true, sizeof(true));
|
||||
|
||||
if (bind(fd_inet, (struct sockaddr *)&sin, sizeof(sin)) == ERROR) {
|
||||
if (errno == EADDRINUSE) {
|
||||
if (sp)
|
||||
fprintf(stderr,
|
||||
"Port '%s(%d)' is already in use\n",
|
||||
port_name, port);
|
||||
else
|
||||
fprintf(stderr,
|
||||
"Port %d is already in use\n",
|
||||
port);
|
||||
}
|
||||
else
|
||||
fprintf(stderr, "Can't bind AF_INET socket\n");
|
||||
shutdown(fd_inet, 2);
|
||||
close(fd_inet);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (listen(fd_inet, SOMAXCONN) == ERROR) {
|
||||
shutdown(fd_inet, 2);
|
||||
close(fd_inet);
|
||||
fprintf(stderr, "Can't listen AF_INET socket\n");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
set_fd(fd_inet);
|
||||
}
|
||||
open_socket()
|
||||
{
|
||||
open_af_inet();
|
||||
#if (!defined(TLI) || (defined(TLI) && defined(SOCK_UNIX)))
|
||||
open_af_unix();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if (!defined(TLI) || (defined(TLI) && defined(SOCK_UNIX)))
|
||||
|
||||
|
||||
static int connect_af_unix()
|
||||
{
|
||||
struct sockaddr_un sunix;
|
||||
int i = sizeof(sunix);
|
||||
int fd;
|
||||
|
||||
if ((fd = accept(fd_unix, (struct sockaddr *)&sunix, &i)) == ERROR)
|
||||
warning_out("Can't accept AF_UNIX socket");
|
||||
return fd;
|
||||
}
|
||||
#endif
|
||||
#ifdef TLI
|
||||
int
|
||||
accept_func(fd, callptr, name, closeflg)
|
||||
int fd;
|
||||
struct t_call *callptr;
|
||||
char *name;
|
||||
int closeflg;
|
||||
{
|
||||
int newfd;
|
||||
int look;
|
||||
extern int t_errno;
|
||||
|
||||
if ((newfd = t_open(name, O_RDWR, (struct t_info *)0)) < 0) {
|
||||
if (!closeflg) warning_out("Can't t_open");
|
||||
return ERROR;
|
||||
}
|
||||
if (t_bind(newfd, (struct t_bind *)0, (struct t_bind *)0) < 0) {
|
||||
if (!closeflg) warning_out("t_bind error");
|
||||
return ERROR;
|
||||
}
|
||||
t_errno = 0;
|
||||
if (t_accept(fd, newfd, callptr) <0 ){
|
||||
t_close(newfd);
|
||||
if (!closeflg) warning_out("t_accept error");
|
||||
return ERROR;
|
||||
}
|
||||
if (ioctl(newfd, I_POP, (char *) 0) < 0) {
|
||||
if (!closeflg) warning_out("I_POP timod failed");
|
||||
return ERROR;
|
||||
}
|
||||
if (ioctl(newfd, I_PUSH, "tirdwr") < 0) {
|
||||
if (!closeflg) warning_out("I_PUSH tirdwr failed");
|
||||
return ERROR;
|
||||
}
|
||||
return(newfd);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
static int connect_af_inet()
|
||||
{
|
||||
#ifndef TLI
|
||||
struct sockaddr_in sin;
|
||||
int i = sizeof(sin);
|
||||
#endif
|
||||
int fd;
|
||||
|
||||
#ifdef TLI
|
||||
if (t_listen(fd_inet, inet_callptr) < 0) {
|
||||
warning_out("t_listen error");
|
||||
|
||||
}
|
||||
|
||||
if ((fd = accept_func(fd_inet, inet_callptr, nconf->nc_device, FALSE)) == ERROR)
|
||||
#else
|
||||
if ((fd = accept(fd_inet, (struct sockaddr *)&sin, &i)) == ERROR)
|
||||
#endif
|
||||
warning_out("Can't accept AF_INET socket");
|
||||
return fd;
|
||||
}
|
||||
|
||||
#if (!defined(TLI) || (defined(TLI) && defined(SOCK_UNIX)))
|
||||
|
||||
|
||||
static void close_af_unix()
|
||||
{
|
||||
struct sockaddr_un sunix;
|
||||
int true = 1;
|
||||
int i;
|
||||
|
||||
ioctl(fd_unix, FIONBIO, &true);
|
||||
for ( ; ; ) {
|
||||
i = sizeof(sunix);
|
||||
if (accept(fd_unix, (struct sockaddr *)&sunix, &i) < 0) break;
|
||||
}
|
||||
shutdown(fd_unix, 2);
|
||||
close(fd_unix);
|
||||
unlink(socket_name);
|
||||
clr_fd(fd_unix);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
static void close_af_inet()
|
||||
{
|
||||
#ifndef TLI
|
||||
struct sockaddr_in sin;
|
||||
#endif
|
||||
int true = 1;
|
||||
int i;
|
||||
|
||||
ioctl(fd_inet, FIONBIO, &true);
|
||||
for ( ; ; ) {
|
||||
#ifdef TLI
|
||||
if (accept_func(fd_inet, inet_callptr, nconf->nc_device, TRUE) < 0)
|
||||
break;
|
||||
#else
|
||||
i = sizeof(sin);
|
||||
if (accept(fd_inet, (struct sockaddr *)&sin, &i) < 0) break;
|
||||
#endif
|
||||
}
|
||||
#ifdef TLI
|
||||
t_sndrel(fd_inet);
|
||||
t_close(fd_inet);
|
||||
clr_fd(fd_inet);
|
||||
#else
|
||||
shutdown(fd_inet, 2);
|
||||
close(fd_inet);
|
||||
clr_fd(fd_inet);
|
||||
#endif
|
||||
}
|
||||
close_socket()
|
||||
{
|
||||
#if (!defined(TLI) || (defined(TLI) && defined(SOCK_UNIX)))
|
||||
close_af_unix();
|
||||
#endif
|
||||
close_af_inet();
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void connect_client(readfds)
|
||||
#ifdef SVR4
|
||||
struct pollfd *readfds;
|
||||
#else
|
||||
fd_set *readfds;
|
||||
#endif
|
||||
{
|
||||
int fd;
|
||||
#if (defined(TLI) && defined(SOCK_UNIX))
|
||||
int unix_flag=0;
|
||||
#endif
|
||||
Client *client_tmp;
|
||||
|
||||
#ifdef SVR4
|
||||
int i;
|
||||
|
||||
for (i = 0; i < maxfds; i++) {
|
||||
if ((readfds[i].fd == fd_inet) &&
|
||||
(readfds[i].revents == POLLIN)) {
|
||||
fd = connect_af_inet();
|
||||
readfds[i].revents = 0;
|
||||
break;
|
||||
}
|
||||
#if (!defined(TLI) || (defined(TLI) && defined(SOCK_UNIX)))
|
||||
if ((readfds[i].fd == fd_unix) &&
|
||||
(readfds[i].revents == POLLIN)) {
|
||||
fd = connect_af_unix();
|
||||
readfds[i].revents = 0;
|
||||
#if (defined(TLI) && defined(SOCK_UNIX))
|
||||
unix_flag = 1;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (i == maxfds) return;
|
||||
#else /* SVR4 */
|
||||
if (FD_ISSET(fd_inet, readfds))
|
||||
fd = connect_af_inet();
|
||||
#if (!defined(TLI) || (defined(TLI) && defined(SOCK_UNIX)))
|
||||
else if (FD_ISSET(fd_unix, readfds))
|
||||
#if (defined(TLI) && defined(SOCK_UNIX))
|
||||
{
|
||||
fd = connect_af_unix();
|
||||
unix_flag = 1;
|
||||
}
|
||||
#else
|
||||
fd = connect_af_unix();
|
||||
#endif
|
||||
#endif
|
||||
else
|
||||
return;
|
||||
#endif /* SVR4 */
|
||||
if (fd == ERROR) return;
|
||||
|
||||
|
||||
|
||||
|
||||
if (client_num >= MaxClientNum || client_num >= max_client) {
|
||||
warning_out("No more client");
|
||||
}
|
||||
|
||||
else {
|
||||
debug_out(1, "client create(%d)\r\n", fd);
|
||||
logging_out("connect to client on %d", fd);
|
||||
|
||||
|
||||
if (client_tmp = (Client *)malloc(sizeof(Client))) {
|
||||
memset(client_tmp, 0, sizeof(Client));
|
||||
client_tmp->fd = fd;
|
||||
#if (defined(TLI) && defined(SOCK_UNIX))
|
||||
client_tmp->unix_flag = unix_flag;
|
||||
#endif
|
||||
client_tmp->next = client;
|
||||
client = client_tmp;
|
||||
client_num++;
|
||||
|
||||
set_fd(fd);
|
||||
|
||||
return;
|
||||
}
|
||||
warning_out("No more client(Can't alloc)");
|
||||
}
|
||||
#ifdef TLI
|
||||
#ifdef SOCK_UNIX
|
||||
if (unix_flag) {
|
||||
shutdown(fd, 2);
|
||||
close(fd);
|
||||
} else {
|
||||
t_sndrel(fd);
|
||||
t_close(fd);
|
||||
}
|
||||
#else
|
||||
t_sndrel(fd);
|
||||
t_close(fd);
|
||||
#endif
|
||||
#else
|
||||
shutdown(fd, 2);
|
||||
close(fd);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
static Client *disconnect_client(cp)
|
||||
Client *cp;
|
||||
{
|
||||
WorkArea *wp;
|
||||
StdyFile *sp;
|
||||
int fd;
|
||||
Client *cl_tmp, *cl_before;
|
||||
int i;
|
||||
|
||||
if (sp = cp->stdy) closestdy(sp);
|
||||
if (wp = cp->work) free_workarea(wp);
|
||||
|
||||
debug_out(1, "client dead(%d)\r\n", cp->fd);
|
||||
logging_out("disconnect from client on %d", cp->fd);
|
||||
#ifdef TLI
|
||||
#ifdef SOCK_UNIX
|
||||
if (cp->unix_flag) {
|
||||
shutdown(fd = cp->fd, 2);
|
||||
close(fd);
|
||||
clr_fd(fd);
|
||||
} else {
|
||||
fd = cp->fd;
|
||||
t_sndrel(fd);
|
||||
t_close(fd);
|
||||
clr_fd(fd);
|
||||
}
|
||||
#else
|
||||
fd = cp->fd;
|
||||
t_sndrel(fd);
|
||||
t_close(fd);
|
||||
clr_fd(fd);
|
||||
#endif
|
||||
#else
|
||||
shutdown(fd = cp->fd, 2);
|
||||
close(fd);
|
||||
clr_fd(fd);
|
||||
#endif
|
||||
if (cp == client) {
|
||||
client = cp->next;
|
||||
free(cp);
|
||||
cp = client;
|
||||
} else {
|
||||
cl_before = client;
|
||||
cl_tmp = client->next;
|
||||
while (cl_tmp) {
|
||||
if (cl_tmp == cp) {
|
||||
cl_before->next = cp->next;
|
||||
free(cp);
|
||||
break;
|
||||
}
|
||||
cl_before = cl_tmp;
|
||||
cl_tmp = cl_tmp->next;
|
||||
}
|
||||
cp = cl_before->next;
|
||||
}
|
||||
client_num--;
|
||||
return cp;
|
||||
}
|
||||
|
||||
#ifndef SIGPIPE
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
void communicate()
|
||||
{
|
||||
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
for ( ; ; ) {
|
||||
#ifdef SVR4
|
||||
int i;
|
||||
|
||||
while(poll(poll_fds, maxfds, -1) == ERROR) {
|
||||
if (errno != EINTR) error_out("poll");
|
||||
errno = 0;
|
||||
}
|
||||
#else
|
||||
|
||||
fd_set readfds;
|
||||
|
||||
|
||||
readfds = fds_org;
|
||||
while (select(maxfds,&readfds,NULL,NULL,NULL) == ERROR) {
|
||||
if (errno != EINTR) error_out("select");
|
||||
errno = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
for (cur_client = client ; cur_client; ) {
|
||||
|
||||
if (setjmp(client_dead)) {
|
||||
cur_client = disconnect_client(cur_client);
|
||||
continue;
|
||||
}
|
||||
#ifdef SVR4
|
||||
for ( i = 0; i < maxfds; i++) {
|
||||
if ((poll_fds[i].fd == cur_client->fd) &&
|
||||
(poll_fds[i].revents == POLLIN)) {
|
||||
poll_fds[i].revents = 0;
|
||||
client_fd = cur_client->fd;
|
||||
putpos = buflen = getpos = 0;
|
||||
execute_cmd();
|
||||
break;
|
||||
}
|
||||
}
|
||||
cur_client = cur_client->next;
|
||||
}
|
||||
connect_client(poll_fds);
|
||||
#else
|
||||
if (FD_ISSET(cur_client->fd, &readfds)) {
|
||||
client_fd = cur_client->fd;
|
||||
putpos = buflen = getpos = 0;
|
||||
execute_cmd();
|
||||
}
|
||||
cur_client = cur_client->next;
|
||||
}
|
||||
connect_client(&readfds);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void put_flush()
|
||||
{
|
||||
register int len;
|
||||
register int i;
|
||||
register char *p;
|
||||
|
||||
for (len = putpos, p = putbuf ; len > 0 ; ) {
|
||||
if ((i = write(client_fd, p, len)) == ERROR) {
|
||||
longjmp(client_dead, -1);
|
||||
}
|
||||
len -= i;
|
||||
p += i;
|
||||
}
|
||||
putpos = 0;
|
||||
}
|
||||
void put_byte(c)
|
||||
register int c;
|
||||
{
|
||||
putbuf[putpos++] = c;
|
||||
if (putpos >= sizeof(putbuf)) put_flush();
|
||||
}
|
||||
void put_work(c)
|
||||
register int c;
|
||||
{
|
||||
put_byte(c >> 8);
|
||||
put_byte(c & 0xff);
|
||||
}
|
||||
void put_int(c)
|
||||
register int c;
|
||||
{
|
||||
put_byte(c >> (8 * 3));
|
||||
put_byte(c >> (8 * 2));
|
||||
put_byte(c >> (8 * 1));
|
||||
put_byte(c);
|
||||
}
|
||||
Uchar *put_string(p)
|
||||
register Uchar *p;
|
||||
{
|
||||
if (p) {
|
||||
do {
|
||||
put_byte(*p);
|
||||
} while (*p++);
|
||||
}
|
||||
else
|
||||
put_byte(0);
|
||||
return p;
|
||||
}
|
||||
Uchar *put_ndata(p, n)
|
||||
register Uchar *p;
|
||||
register int n;
|
||||
{
|
||||
while (n-- > 0) put_byte(p ? *p++ : 0);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void get_buf()
|
||||
{
|
||||
register int i;
|
||||
|
||||
for (;;) {
|
||||
if ((i = read(client_fd, getbuf, sizeof(getbuf))) > 0) break;
|
||||
if (i == ERROR) {
|
||||
if (errno == EINTR) continue;
|
||||
if (errno == EWOULDBLOCK) continue;
|
||||
}
|
||||
longjmp(client_dead, -1);
|
||||
}
|
||||
buflen = i;
|
||||
getpos = 0;
|
||||
}
|
||||
int get_byte()
|
||||
{
|
||||
if (getpos >= buflen) get_buf();
|
||||
return (getbuf[getpos++] & 0xff);
|
||||
}
|
||||
int get_word()
|
||||
{
|
||||
register int i;
|
||||
|
||||
i = get_byte();
|
||||
return ((i << 8) | get_byte());
|
||||
}
|
||||
int get_int()
|
||||
{
|
||||
register int i0;
|
||||
register int i1;
|
||||
register int i2;
|
||||
|
||||
i0 = get_byte();
|
||||
i1 = get_byte();
|
||||
i2 = get_byte();
|
||||
return((i0 << (8*3)) | (i1 << (8*2)) | (i2 << (8*1)) | get_byte());
|
||||
}
|
||||
int get_nstring(p, n)
|
||||
register Uchar *p;
|
||||
register int n;
|
||||
{
|
||||
register int c;
|
||||
|
||||
do {
|
||||
c = get_byte();
|
||||
if (n-- > 0) *p++ = c;
|
||||
} while (c);
|
||||
|
||||
return (n < 0) ? ERROR : 0;
|
||||
}
|
||||
Uchar *get_ndata(p, n)
|
||||
register Uchar *p;
|
||||
register int n;
|
||||
{
|
||||
while (n-- > 0) *p++ = get_byte();
|
||||
return p;
|
||||
}
|
||||
173
server/error.c
Normal file
173
server/error.c
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
/*
|
||||
* Copyright (c) 1991-1994 Sony Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Except as contained in this notice, the name of Sony Corporation
|
||||
* shall not be used in advertising or otherwise to promote the sale, use
|
||||
* or other dealings in this Software without prior written authorization
|
||||
* from Sony Corporation.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* $SonyRCSfile: error.c,v $
|
||||
* $SonyRevision: 1.1 $
|
||||
* $SonyDate: 1994/06/03 08:02:51 $
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include "sj_typedef.h"
|
||||
|
||||
extern char program_name[];
|
||||
extern int debug_level;
|
||||
extern int client_fd;
|
||||
|
||||
static char *tty_name = "/dev/tty";
|
||||
static FILE *errfp = NULL;
|
||||
static FILE *logfp = NULL;
|
||||
static FILE *dbgfp = NULL;
|
||||
|
||||
|
||||
|
||||
open_error()
|
||||
{
|
||||
extern char *error_file;
|
||||
int flg = 0;
|
||||
|
||||
if (error_file && *error_file) {
|
||||
if (!strcmp(error_file, tty_name)) {
|
||||
errfp = stderr;
|
||||
flg = -1;
|
||||
}
|
||||
else if (!(errfp = fopen(error_file, "a")))
|
||||
fprintf(stderr, "Can't open \"%s\"\r\n", error_file);
|
||||
}
|
||||
else
|
||||
errfp = NULL;
|
||||
|
||||
return flg;
|
||||
}
|
||||
|
||||
error_out(s, p1, p2, p3, p4, p5)
|
||||
char *s;
|
||||
int p1, p2, p3, p4, p5;
|
||||
{
|
||||
char tmp[BUFSIZ];
|
||||
|
||||
if (errfp) {
|
||||
sprintf(tmp, s, p1, p2, p3, p4, p5);
|
||||
fprintf(errfp, "%s: %s\r\n", program_name, tmp);
|
||||
fflush(errfp);
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
warning_out(s, p1, p2, p3, p4, p5)
|
||||
char *s;
|
||||
int p1, p2, p3, p4, p5;
|
||||
{
|
||||
char tmp[BUFSIZ];
|
||||
|
||||
if (errfp) {
|
||||
sprintf(tmp, s, p1, p2, p3, p4);
|
||||
fprintf(errfp, "%s: warning: %s\r\n", program_name, tmp);
|
||||
fflush(errfp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
open_log()
|
||||
{
|
||||
extern char *log_file;
|
||||
int flg = 0;
|
||||
|
||||
if (log_file && *log_file) {
|
||||
if (!strcmp(log_file, tty_name)) {
|
||||
logfp = stderr;
|
||||
flg = -1;
|
||||
}
|
||||
else
|
||||
logfp = fopen(log_file, "a");
|
||||
if (logfp) {
|
||||
long t;
|
||||
|
||||
time(&t);
|
||||
fprintf(logfp, "%s: log started at %s\r",
|
||||
program_name, ctime(&t));
|
||||
fflush(logfp);
|
||||
}
|
||||
else
|
||||
fprintf(stderr, "Can't open \"%s\"\r\n", log_file);
|
||||
}
|
||||
else
|
||||
logfp = NULL;
|
||||
|
||||
return flg;
|
||||
}
|
||||
|
||||
logging_out(s, p1, p2, p3, p4, p5)
|
||||
char *s;
|
||||
int p1, p2, p3, p4, p5;
|
||||
{
|
||||
char tmp[BUFSIZ];
|
||||
|
||||
if (logfp) {
|
||||
sprintf(tmp, s, p1, p2, p3, p4, p5);
|
||||
fprintf(logfp, "%s\r\n", tmp);
|
||||
fflush(logfp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
open_debug()
|
||||
{
|
||||
extern char *debug_file;
|
||||
int flg = 0;
|
||||
|
||||
if (debug_file && *debug_file) {
|
||||
if (!strcmp(debug_file, tty_name)) {
|
||||
dbgfp = stderr;
|
||||
flg = -1;
|
||||
}
|
||||
else if (!(dbgfp = fopen(debug_file, "a")))
|
||||
fprintf(stderr, "Can't open \"%s\"\r\n", debug_file);
|
||||
}
|
||||
else
|
||||
dbgfp = NULL;
|
||||
|
||||
return flg;
|
||||
}
|
||||
|
||||
debug_out(lvl, s, p1, p2, p3, p4, p5)
|
||||
int lvl;
|
||||
char *s;
|
||||
int p1, p2, p3, p4, p5;
|
||||
{
|
||||
if (lvl <= debug_level && dbgfp) {
|
||||
fprintf(dbgfp, s, p1, p2, p3, p4, p5);
|
||||
fflush(dbgfp);
|
||||
}
|
||||
}
|
||||
1632
server/execute.c
Normal file
1632
server/execute.c
Normal file
File diff suppressed because it is too large
Load diff
249
server/main.c
Normal file
249
server/main.c
Normal file
|
|
@ -0,0 +1,249 @@
|
|||
/*
|
||||
* Copyright (c) 1991-1994 Sony Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Except as contained in this notice, the name of Sony Corporation
|
||||
* shall not be used in advertising or otherwise to promote the sale, use
|
||||
* or other dealings in this Software without prior written authorization
|
||||
* from Sony Corporation.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* $SonyRCSfile: main.c,v $
|
||||
* $SonyRevision: 1.3 $
|
||||
* $SonyDate: 1995/02/03 07:38:44 $
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include "sj_sysvdef.h"
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#ifdef SVR4
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/termios.h>
|
||||
#endif
|
||||
#include "Const.h"
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid_sony[] = "$Header: /export/work/contrib/sj3/server/RCS/main.c,v 1.12 1994/06/03 07:41:30 notanaka Exp $ SONY;";
|
||||
#endif
|
||||
|
||||
#ifdef SVR4
|
||||
#define signal sigset
|
||||
#endif
|
||||
|
||||
void _exit();
|
||||
|
||||
extern int fork_flag;
|
||||
extern char *lock_file;
|
||||
|
||||
|
||||
|
||||
static void opening()
|
||||
{
|
||||
extern char *version_number;
|
||||
extern char *time_stamp;
|
||||
|
||||
printf("Kana-Kanji Conversion Server Version %s\r\n", version_number);
|
||||
printf("Copyright (c) 1990-1995 Sony Corporation\r\n");
|
||||
printf("Created at %s\r\n", time_stamp);
|
||||
}
|
||||
|
||||
#ifdef LOCK_FILE
|
||||
|
||||
|
||||
int make_lockfile()
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = open(lock_file, O_CREAT | O_EXCL, 0600);
|
||||
if (fd < 0) return ERROR;
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
int erase_lockfile()
|
||||
{
|
||||
return unlink(lock_file);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#if !defined(__sony_news) || defined(SVR4)
|
||||
static int signal_handler(sig)
|
||||
int sig;
|
||||
{
|
||||
warning_out("signal %d catched.", sig);
|
||||
}
|
||||
|
||||
static int terminate_handler(sig)
|
||||
int sig;
|
||||
{
|
||||
close_socket();
|
||||
sj_closeall();
|
||||
#ifdef LOCK_FILE
|
||||
erase_lockfile();
|
||||
#endif
|
||||
exit(0);
|
||||
}
|
||||
#else
|
||||
static int signal_handler(sig, code, scp)
|
||||
int sig;
|
||||
int code;
|
||||
struct sigcontext *scp;
|
||||
{
|
||||
warning_out("signal %d, code %d catched.", sig, code);
|
||||
}
|
||||
|
||||
static int terminate_handler(sig, code, scp)
|
||||
int sig;
|
||||
int code;
|
||||
struct sigcontext *scp;
|
||||
{
|
||||
close_socket();
|
||||
sj_closeall();
|
||||
#ifdef LOCK_FILE
|
||||
erase_lockfile();
|
||||
#endif
|
||||
exit(0);
|
||||
}
|
||||
#endif
|
||||
server_terminate()
|
||||
{
|
||||
close_socket();
|
||||
sj_closeall();
|
||||
#ifdef LOCK_FILE
|
||||
erase_lockfile();
|
||||
#endif
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void exec_fork()
|
||||
{
|
||||
int tmp;
|
||||
|
||||
if (fork_flag && (tmp = fork())) {
|
||||
if (tmp < 0) {
|
||||
fprintf(stderr, "Can't fork child process\r\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
else {
|
||||
signal(SIGCHLD, _exit);
|
||||
signal(SIGHUP , SIG_IGN);
|
||||
signal(SIGINT , SIG_IGN);
|
||||
signal(SIGQUIT, SIG_IGN);
|
||||
signal(SIGTSTP, SIG_IGN);
|
||||
signal(SIGTERM, _exit);
|
||||
wait(0);
|
||||
_exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
signal(SIGHUP, (void (*)())signal_handler);
|
||||
|
||||
|
||||
signal(SIGINT, (void (*)())terminate_handler);
|
||||
signal(SIGQUIT, (void (*)())signal_handler);
|
||||
signal(SIGTERM, (void (*)())terminate_handler);
|
||||
if (fork_flag)
|
||||
signal(SIGTSTP, SIG_IGN);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static void leave_tty()
|
||||
{
|
||||
int tmp;
|
||||
|
||||
tmp = open_error();
|
||||
tmp |= open_log();
|
||||
tmp |= open_debug();
|
||||
kill(getppid(), SIGTERM);
|
||||
fclose(stdin);
|
||||
fclose(stdout);
|
||||
if (!tmp) fclose(stderr);
|
||||
|
||||
if (fork_flag) {
|
||||
#ifdef SVR4
|
||||
(void) setsid();
|
||||
#else
|
||||
if ((tmp = open("/dev/tty", O_RDWR)) >= 0) {
|
||||
ioctl(tmp, TIOCNOTTY, 0);
|
||||
close(tmp);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
#ifdef __sony_news
|
||||
(void) setlocale(LC_CTYPE, "ja_JP.EUC");
|
||||
#endif
|
||||
opening();
|
||||
if (setuid(geteuid())) {
|
||||
fprintf(stderr, "error at setuid.\r\n"); exit(1);
|
||||
}
|
||||
|
||||
parse_arg(argc, argv);
|
||||
read_runcmd();
|
||||
set_default();
|
||||
|
||||
#ifdef LOCK_FILE
|
||||
if (make_lockfile() == ERROR) {
|
||||
fprintf(stderr, "Already running...\r\n"); exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
exec_fork();
|
||||
|
||||
socket_init();
|
||||
open_socket();
|
||||
|
||||
leave_tty();
|
||||
|
||||
preload_dict();
|
||||
preopen_dict();
|
||||
communicate();
|
||||
|
||||
close_socket();
|
||||
sj_closeall();
|
||||
#ifdef LOCK_FILE
|
||||
erase_lockfile();
|
||||
#endif
|
||||
exit(0);
|
||||
}
|
||||
117
server/rc.sj3serv
Normal file
117
server/rc.sj3serv
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
##
|
||||
## Copyright (c) 1994 Sony Corporation
|
||||
##
|
||||
## Permission is hereby granted, free of charge, to any person obtaining
|
||||
## a copy of this software and associated documentation files (the
|
||||
## "Software"), to deal in the Software without restriction, including
|
||||
## without limitation the rights to use, copy, modify, merge, publish,
|
||||
## distribute, sublicense, and/or sell copies of the Software, and to
|
||||
## permit persons to whom the Software is furnished to do so, subject to
|
||||
## the following conditions:
|
||||
##
|
||||
## The above copyright notice and this permission notice shall be
|
||||
## included in all copies or substantial portions of the Software.
|
||||
##
|
||||
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
## IN NO EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY CLAIM,
|
||||
## DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
## OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
||||
## THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
##
|
||||
## Except as contained in this notice, the name of Sony Corporation
|
||||
## shall not be used in advertising or otherwise to promote the sale, use
|
||||
## or other dealings in this Software without prior written authorization
|
||||
## from Sony Corporation.
|
||||
##
|
||||
|
||||
##
|
||||
## $SonyRCSfile: rc.sj3serv,v $
|
||||
## $SonyRevision: 1.1 $
|
||||
## $SonyDate: 1994/06/03 08:02:54 $
|
||||
##
|
||||
|
||||
## sj3serv
|
||||
##
|
||||
## If you want to start sj3serv when system boots, please delete '#' at the
|
||||
## head of CMDNAME below.
|
||||
##
|
||||
|
||||
CMDNAME=sj3serv
|
||||
|
||||
PRINTNAME=$CMDNAME
|
||||
CMDDIR=/usr/bin
|
||||
BACKGROUND=
|
||||
PATH=/usr/bin:/bin
|
||||
CMDPATH=$CMDDIR/$CMDNAME
|
||||
|
||||
RESTARTMESSAGE=
|
||||
STARTMESSAGE=
|
||||
DOWNMESSAGE=
|
||||
#RESTARTMESSAGE="Restarting $PRINTNAME"
|
||||
#STARTMESSAGE="Starting $PRINTNAME"
|
||||
#DOWNMESSAGE="Killed $PRINTNAME"
|
||||
USAGEMESSAGE="Usage: $0 [start|stop]"
|
||||
|
||||
if [ "$CMDNAME" = "sj3serv" ]
|
||||
then
|
||||
if [ ! -d /usr/bin ]
|
||||
then # /usr not mounted
|
||||
exit
|
||||
fi
|
||||
|
||||
pid=`/sbin/findproc $CMDNAME`
|
||||
case "$1" in
|
||||
'start')
|
||||
if [ $pid ]
|
||||
then
|
||||
kill -TERM $pid
|
||||
sleep 1
|
||||
pid=`/sbin/findproc $CMDNAME`
|
||||
if [ $pid ]
|
||||
then
|
||||
kill -9 $pid
|
||||
fi
|
||||
if [ -f $CMDPATH ]
|
||||
then
|
||||
if [ "$RESTARTMESSAGE" ]
|
||||
then
|
||||
echo $RESTARTMESSAGE > /dev/console
|
||||
fi
|
||||
eval $CMDPATH $BACKGROUND
|
||||
fi
|
||||
else
|
||||
if [ -f $CMDPATH ]
|
||||
then
|
||||
if [ "$STARTMESSAGE" ]
|
||||
then
|
||||
echo $STARTMESSAGE >/dev/console
|
||||
fi
|
||||
eval $CMDPATH $BACKGROUND
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
'stop')
|
||||
if [ $pid ]
|
||||
then
|
||||
kill -TERM $pid
|
||||
sleep 1
|
||||
pid=`/sbin/findproc $CMDNAME`
|
||||
if [ $pid ]
|
||||
then
|
||||
kill -9 $pid
|
||||
fi
|
||||
if [ "$DOWNMESSAGE" ]
|
||||
then
|
||||
echo $DOWNMESSAGE > /dev/console
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo $USAGEMESSAGE
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
|
||||
98
server/rc.sj3serv.FreeBSD
Normal file
98
server/rc.sj3serv.FreeBSD
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
##
|
||||
## Copyright (c) 1994 Sony Corporation
|
||||
##
|
||||
## Permission is hereby granted, free of charge, to any person obtaining
|
||||
## a copy of this software and associated documentation files (the
|
||||
## "Software"), to deal in the Software without restriction, including
|
||||
## without limitation the rights to use, copy, modify, merge, publish,
|
||||
## distribute, sublicense, and/or sell copies of the Software, and to
|
||||
## permit persons to whom the Software is furnished to do so, subject to
|
||||
## the following conditions:
|
||||
##
|
||||
## The above copyright notice and this permission notice shall be
|
||||
## included in all copies or substantial portions of the Software.
|
||||
##
|
||||
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
## IN NO EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY CLAIM,
|
||||
## DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
## OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
||||
## THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
##
|
||||
## Except as contained in this notice, the name of Sony Corporation
|
||||
## shall not be used in advertising or otherwise to promote the sale, use
|
||||
## or other dealings in this Software without prior written authorization
|
||||
## from Sony Corporation.
|
||||
##
|
||||
|
||||
##
|
||||
## $SonyRCSfile: rc.sj3serv.FreeBSD,v $
|
||||
## $SonyRevision: 1.1 $
|
||||
## $SonyDate: 1997/01/23 11:09:48 $
|
||||
##
|
||||
|
||||
## sj3serv
|
||||
##
|
||||
## If you want to start sj3serv when system boots, please delete '#' at the
|
||||
## head of CMDNAME below.
|
||||
##
|
||||
|
||||
CMDNAME=sj3serv
|
||||
|
||||
PRINTNAME=$CMDNAME
|
||||
CMDDIR=/usr/local/bin
|
||||
BACKGROUND=
|
||||
PATH=/usr/local/bin:/usr/bin:/bin
|
||||
CMDPATH=$CMDDIR/$CMDNAME
|
||||
|
||||
RESTARTMESSAGE=
|
||||
STARTMESSAGE=
|
||||
DOWNMESSAGE=
|
||||
#RESTARTMESSAGE="Restarting $PRINTNAME"
|
||||
#STARTMESSAGE="Starting $PRINTNAME"
|
||||
#DOWNMESSAGE="Killed $PRINTNAME"
|
||||
USAGEMESSAGE="Usage: $0 [start|stop]"
|
||||
|
||||
##
|
||||
## For system which don't have a findproc command.(FreeBSD, ...)
|
||||
## Patched by Hidekazu Kuroki(hidekazu@cs.titech.ac.jp) 1996/8/10
|
||||
##
|
||||
|
||||
if [ "$CMDNAME" = "sj3serv" ]
|
||||
then
|
||||
if [ ! -d /usr/local/bin ]
|
||||
then # /usr/local not mounted
|
||||
exit
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
'start')
|
||||
if [ -f $CMDPATH ]
|
||||
then
|
||||
if [ "$STARTMESSAGE" ]
|
||||
then
|
||||
echo $STARTMESSAGE >/dev/console
|
||||
fi
|
||||
eval $CMDPATH $BACKGROUND
|
||||
fi
|
||||
;;
|
||||
'stop')
|
||||
;;
|
||||
'')
|
||||
if [ -f $CMDPATH ]
|
||||
then
|
||||
if [ "$STARTMESSAGE" ]
|
||||
then
|
||||
echo $STARTMESSAGE >/dev/console
|
||||
fi
|
||||
eval $CMDPATH $BACKGROUND
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo $USAGEMESSAGE
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
|
||||
35
server/serverrc
Normal file
35
server/serverrc
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
##
|
||||
## Copyright (c) 1991-1994 Sony Corporation
|
||||
##
|
||||
## Permission is hereby granted, free of charge, to any person obtaining
|
||||
## a copy of this software and associated documentation files (the
|
||||
## "Software"), to deal in the Software without restriction, including
|
||||
## without limitation the rights to use, copy, modify, merge, publish,
|
||||
## distribute, sublicense, and/or sell copies of the Software, and to
|
||||
## permit persons to whom the Software is furnished to do so, subject to
|
||||
## the following conditions:
|
||||
##
|
||||
## The above copyright notice and this permission notice shall be
|
||||
## included in all copies or substantial portions of the Software.
|
||||
##
|
||||
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
## IN NO EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY CLAIM,
|
||||
## DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
## OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
||||
## THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
##
|
||||
## Except as contained in this notice, the name of Sony Corporation
|
||||
## shall not be used in advertising or otherwise to promote the sale, use
|
||||
## or other dealings in this Software without prior written authorization
|
||||
## from Sony Corporation.
|
||||
##
|
||||
|
||||
##
|
||||
## $SonyRCSfile: serverrc,v $
|
||||
## $SonyRevision: 1.1 $
|
||||
## $SonyDate: 1994/06/03 08:02:55 $
|
||||
##
|
||||
|
||||
readdict sj3main.dic
|
||||
562
server/setup.c
Normal file
562
server/setup.c
Normal file
|
|
@ -0,0 +1,562 @@
|
|||
/*
|
||||
* Copyright (c) 1991-1994 Sony Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Except as contained in this notice, the name of Sony Corporation
|
||||
* shall not be used in advertising or otherwise to promote the sale, use
|
||||
* or other dealings in this Software without prior written authorization
|
||||
* from Sony Corporation.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* $SonyRCSfile: setup.c,v $
|
||||
* $SonyRevision: 1.3 $
|
||||
* $SonyDate: 1994/12/09 11:27:07 $
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include "sj_sysvdef.h"
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#ifdef SVR4
|
||||
#include <string.h>
|
||||
#else
|
||||
#include <strings.h>
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/param.h>
|
||||
#include "sj_typedef.h"
|
||||
#include "sj_const.h"
|
||||
#include "sj_var.h"
|
||||
#include "sj_dict.h"
|
||||
#include "sj_struct.h"
|
||||
#include "sj_rename.h"
|
||||
#include "Const.h"
|
||||
#include "Struct.h"
|
||||
#include "sj_global.h"
|
||||
|
||||
typedef struct strlist {
|
||||
u_char *str1;
|
||||
u_char *str2;
|
||||
struct strlist *link;
|
||||
} StrList;
|
||||
|
||||
char program_name [PathNameLen];
|
||||
char runcmd_file [PathNameLen];
|
||||
|
||||
char *debug_file = NULL;
|
||||
int debug_level = -1;
|
||||
int fork_flag = -1;
|
||||
|
||||
int max_client = -1;
|
||||
char *dict_dir = NULL;
|
||||
StrList *read_dict = NULL;
|
||||
StrList *open_dict = NULL;
|
||||
char *error_file = NULL;
|
||||
char *log_file = NULL;
|
||||
char *port_name = NULL;
|
||||
#ifdef TLI
|
||||
char *port_number = NULL;
|
||||
#else
|
||||
int port_number = -1;
|
||||
#endif
|
||||
char *socket_name = NULL;
|
||||
#ifdef LOCK_FILE
|
||||
char *lock_file = NULL;
|
||||
#endif
|
||||
int dir_mode = -1;
|
||||
int file_mode = S_IRUSR|S_IWUSR;
|
||||
StrList *allow_user = NULL;
|
||||
#ifdef TLI
|
||||
char *proto_name = NULL;
|
||||
#endif
|
||||
|
||||
static int line_number;
|
||||
|
||||
char *malloc();
|
||||
|
||||
|
||||
|
||||
#ifdef OLD
|
||||
#else
|
||||
RcError(p)
|
||||
char *p;
|
||||
{
|
||||
fprintf(stderr, "%s: \"%s\", line %d: %s\r\n",
|
||||
program_name, runcmd_file, line_number, p);
|
||||
fflush(stderr);
|
||||
exit(1);
|
||||
}
|
||||
RcWarning(p)
|
||||
char *p;
|
||||
{
|
||||
fprintf(stderr, "%s: warning: \"%s\", line %d: %s\r\n",
|
||||
program_name, runcmd_file, line_number, p);
|
||||
fflush(stderr);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
static cmpstr(src, dst)
|
||||
u_char *src, *dst;
|
||||
{
|
||||
int flg;
|
||||
int c;
|
||||
|
||||
flg = (isupper(*src)) ? -1 : 0;
|
||||
while (*src) {
|
||||
c = flg ? *dst : (isupper(*dst) ? tolower(*dst) : *dst);
|
||||
if (*src != c) return -1;
|
||||
src += 1;
|
||||
dst += 1;
|
||||
}
|
||||
if (*dst) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static u_char *get_str(p, dst)
|
||||
u_char *p;
|
||||
char **dst;
|
||||
{
|
||||
if (!*dst) {
|
||||
*dst = malloc(strlen((char *)p) + 1);
|
||||
if (!*dst) RcError("no more memory");
|
||||
strcpy(*dst, (char *)p);
|
||||
}
|
||||
while (*p++) ;
|
||||
return p;
|
||||
}
|
||||
static u_char *get_int(p, dst)
|
||||
u_char *p;
|
||||
int *dst;
|
||||
{
|
||||
register char *fmt;
|
||||
|
||||
fmt = (*p == '0') ? "%o" : "%d";
|
||||
if (sscanf((char *)p, fmt, dst) != 1) RcError("bad integer");
|
||||
while (*p++) ;
|
||||
return p;
|
||||
}
|
||||
static u_char *get_flag(p, dst)
|
||||
u_char *p;
|
||||
int *dst;
|
||||
{
|
||||
if (sscanf((char *)p, "%d", dst) == 1)
|
||||
;
|
||||
else if (!cmpstr("on", p))
|
||||
*dst = -1;
|
||||
else if (!cmpstr("off", p))
|
||||
*dst = 0;
|
||||
else
|
||||
RcError("bad flag");
|
||||
while (*p++) ;
|
||||
return p;
|
||||
}
|
||||
static u_char *get_list(p, dst)
|
||||
u_char *p;
|
||||
StrList **dst;
|
||||
{
|
||||
StrList *s1, *s2;
|
||||
|
||||
if (*p) {
|
||||
s1 = (StrList *)malloc(sizeof(StrList));
|
||||
if (!s1) RcError("no more memory");
|
||||
s1 -> link = NULL;
|
||||
|
||||
s1 -> str1 = (u_char *)malloc(strlen((char *)p) + 1);
|
||||
if (!(s1 -> str1)) RcError("no more memory");
|
||||
strcpy((char *)s1 -> str1, (char *)p);
|
||||
while (*p++) ;
|
||||
|
||||
if (*p) {
|
||||
s1 -> str2 = (u_char *)malloc(strlen((char *)p) + 1);
|
||||
if (!(s1 -> str2)) RcError("no more memory");
|
||||
strcpy((char *)s1 -> str2, (char *)p);
|
||||
while (*p++) ;
|
||||
}
|
||||
else
|
||||
s1 -> str2 = NULL;
|
||||
|
||||
if (*dst) {
|
||||
for (s2 = *dst ; s2 -> link ; s2 = s2 -> link)
|
||||
;
|
||||
s2 -> link = s1;
|
||||
}
|
||||
else
|
||||
*dst = s1;
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct optlist {
|
||||
char *optname;
|
||||
u_char *(*optfunc)();
|
||||
int optarg;
|
||||
} option[] = {
|
||||
"DebugOut", get_str, (int)&debug_file,
|
||||
"DebugLevel", get_int, (int)&debug_level,
|
||||
"ForkFlag", get_flag, (int)&fork_flag,
|
||||
|
||||
"PortName", get_str, (int)&port_name,
|
||||
#ifdef TLI
|
||||
"PortNumber", get_str, (int)&port_number,
|
||||
"ProtoName", get_str, (int)&proto_name,
|
||||
#else
|
||||
"PortNumber", get_int, (int)&port_number,
|
||||
#endif
|
||||
"SocketName", get_str, (int)&socket_name,
|
||||
#ifdef LOCK_FILE
|
||||
"LockFile", get_str, (int)&lock_file;
|
||||
#endif
|
||||
|
||||
"maxclient", get_int, (int)&max_client,
|
||||
"dictdir", get_str, (int)&dict_dir,
|
||||
"readdict", get_list, (int)&read_dict,
|
||||
"opendict", get_list, (int)&open_dict,
|
||||
"errorout", get_str, (int)&error_file,
|
||||
"logout", get_str, (int)&log_file,
|
||||
"dirmode", get_int, (int)&dir_mode,
|
||||
"filemode", get_int, (int)&file_mode,
|
||||
"allowuser", get_list, (int)&allow_user,
|
||||
0, 0, 0
|
||||
};
|
||||
|
||||
|
||||
|
||||
static int skip_blank(fp)
|
||||
FILE *fp;
|
||||
{
|
||||
register int c;
|
||||
|
||||
c = getc(fp);
|
||||
while (c == ' ' || c == '\t') c = getc(fp);
|
||||
return c;
|
||||
}
|
||||
static int skip_line(fp)
|
||||
FILE *fp;
|
||||
{
|
||||
register int c;
|
||||
|
||||
c = getc(fp);
|
||||
while (c != '\n' && c != EOF) c = getc(fp);
|
||||
return c;
|
||||
}
|
||||
static readln(fp, p, len)
|
||||
FILE *fp;
|
||||
char *p;
|
||||
int len;
|
||||
{
|
||||
int c;
|
||||
int quote = EOF;
|
||||
int flg = 0;
|
||||
|
||||
c = skip_blank(fp);
|
||||
while (c != '\n' && c != EOF) {
|
||||
if (c == '\\') {
|
||||
if ((c = getc(fp)) == EOF) break;
|
||||
if (c == '\n') {
|
||||
line_number++; c = getc(fp); continue;
|
||||
}
|
||||
switch (c) {
|
||||
case 'n': c = '\n'; break;
|
||||
case 't': c = '\t'; break;
|
||||
case 'r': c = '\r'; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
else if (c == '^') {
|
||||
c = getc(fp);
|
||||
if (c < '@' || '_' < c) {
|
||||
ungetc(c, fp); c = '^';
|
||||
}
|
||||
else
|
||||
c -= '@';
|
||||
}
|
||||
else if (c == quote) {
|
||||
quote = EOF; c = getc(fp); continue;
|
||||
}
|
||||
else if (quote != EOF)
|
||||
;
|
||||
else if (c == '\'' || c == '"') {
|
||||
quote = c; c = getc(fp); continue;
|
||||
}
|
||||
else if (c == '#') {
|
||||
len -= 1; *p++ = 0; flg = 0;
|
||||
c = skip_line(fp); continue;
|
||||
}
|
||||
else if (c == ' ' || c == '\t') {
|
||||
len -= 1; *p++ = 0; flg = 0;
|
||||
c = skip_blank(fp); continue;
|
||||
}
|
||||
|
||||
if (len > 2) { len -= 1; *p++ = c; flg = -1; }
|
||||
c = getc(fp);
|
||||
}
|
||||
line_number++;
|
||||
if (flg) *p++ = 0;
|
||||
*p++ = 0;
|
||||
|
||||
return c;
|
||||
}
|
||||
read_line(fp, buf, len)
|
||||
FILE *fp;
|
||||
char *buf;
|
||||
int len;
|
||||
{
|
||||
int flg;
|
||||
|
||||
do {
|
||||
flg = readln(fp, buf, len);
|
||||
if (*buf) return 0;
|
||||
} while (flg != EOF);
|
||||
|
||||
return EOF;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void read_runcmd()
|
||||
{
|
||||
FILE *fp;
|
||||
u_char buf[BUFSIZ];
|
||||
struct optlist *opt;
|
||||
u_char *p;
|
||||
int i;
|
||||
|
||||
if (!(fp = fopen(runcmd_file, "r"))) {
|
||||
warning_out("Can't open run-command file \"%s\"", runcmd_file);
|
||||
return;
|
||||
}
|
||||
line_number = 0;
|
||||
while (read_line(fp, buf, sizeof(buf)) != EOF) {
|
||||
for (opt = option ; p = (u_char *)opt -> optname ; opt++)
|
||||
if (!cmpstr(p, buf)) break;
|
||||
if (p) {
|
||||
p = buf; while (*p++) ;
|
||||
p = (*opt->optfunc)(p, opt->optarg);
|
||||
}
|
||||
else
|
||||
RcError("undefined option");
|
||||
|
||||
if (*p) RcError("too many argment");
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static set_defstr(d, s)
|
||||
char **d, *s;
|
||||
{
|
||||
if (*d == NULL && s) {
|
||||
*d = malloc(strlen(s) + 1);
|
||||
if (!*d) error_out("failed at memory allocation");
|
||||
strcpy(*d, s);
|
||||
}
|
||||
}
|
||||
static set_defint(d, s)
|
||||
int *d, s;
|
||||
{
|
||||
if (*d < 0) *d = s;
|
||||
}
|
||||
void set_default()
|
||||
{
|
||||
set_defstr(&debug_file, DebugOutFile);
|
||||
set_defstr(&error_file, ErrorOutFile);
|
||||
set_defstr(&dict_dir, DictRootDir);
|
||||
set_defstr(&log_file, LogOutFile);
|
||||
set_defstr(&port_name, PortName);
|
||||
set_defstr(&socket_name, SocketName);
|
||||
#ifdef LOCK_FILE
|
||||
set_defstr(&lock_file, LockFile);
|
||||
#endif
|
||||
#ifdef TLI
|
||||
set_defstr(&proto_name, ProtoName);
|
||||
#endif
|
||||
|
||||
set_defint(&debug_level, DebugLevel);
|
||||
set_defint(&fork_flag, ForkFlag);
|
||||
set_defint(&max_client, MaxClientNum);
|
||||
#ifdef TLI
|
||||
set_defstr(&port_number, PortNumber);
|
||||
#else
|
||||
set_defint(&port_number, PortNumber);
|
||||
#endif
|
||||
set_defint(&dir_mode, DirectryMode);
|
||||
set_defint(&file_mode, DictFileMode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void parse_arg(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
int c;
|
||||
int errflg = 0;
|
||||
char *p;
|
||||
|
||||
extern char *optarg, *strrchr();
|
||||
extern int optind;
|
||||
|
||||
p = (p = strrchr(argv[0], '/')) ? p + 1 : argv[0];
|
||||
strcpy(program_name, p);
|
||||
strcpy(runcmd_file, RunCmdFile);
|
||||
|
||||
while ((c = getopt(argc, argv, "f:")) != EOF) {
|
||||
switch (c) {
|
||||
case 'f':
|
||||
strcpy(runcmd_file, optarg);
|
||||
break;
|
||||
|
||||
case '?':
|
||||
default:
|
||||
errflg++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (errflg || optind < argc) {
|
||||
fprintf(stderr, "Usage: %s [-f RunCmdFile]\n", program_name);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
preload_dict()
|
||||
{
|
||||
StrList *p;
|
||||
char filename[PathNameLen];
|
||||
|
||||
work_base = (Global *)malloc(sizeof(Global));
|
||||
if (!work_base) {
|
||||
warning_out("can't load default dictionary(not enough memory)");
|
||||
return;
|
||||
}
|
||||
|
||||
for (p = read_dict ; p ; p = p -> link) {
|
||||
strncpy(filename, (char *)p -> str1, sizeof(filename));
|
||||
filename[sizeof(filename) - 1] = '\0';
|
||||
if (make_full_path(filename))
|
||||
warning_out("too long filename \"%s\"", p -> str1);
|
||||
|
||||
else if (opendict(filename, p -> str2))
|
||||
logging_out("load dictionary \"%s\"", filename);
|
||||
|
||||
else
|
||||
warning_out("can't open dictionary \"%s\"", filename);
|
||||
}
|
||||
|
||||
free(work_base);
|
||||
}
|
||||
|
||||
preopen_dict()
|
||||
{
|
||||
StrList *p;
|
||||
char filename[PathNameLen];
|
||||
DICT *dict;
|
||||
DICTL *dictl;
|
||||
|
||||
work_base = global_work_base = (Global *)malloc(sizeof(Global));
|
||||
if (!work_base) {
|
||||
warning_out("can't open default dictionary(not enough memory)");
|
||||
return;
|
||||
}
|
||||
memset(work_base, 0, sizeof(Global));
|
||||
|
||||
for (p = open_dict ; p ; p = p -> link) {
|
||||
strncpy(filename, p -> str1, sizeof(filename));
|
||||
filename[sizeof(filename) - 1] = '\0';
|
||||
if (make_full_path(filename))
|
||||
warning_out("too long filename \"%s\"", p -> str1);
|
||||
|
||||
else if (dict = (DICT *)opendict(filename, p -> str2)) {
|
||||
logging_out("open dictionary \"%s\"", filename);
|
||||
if (!(dictl = (DICTL *)malloc(sizeof *dictl))) {
|
||||
closedict((DictFile *)dict);
|
||||
warning_out("can't open dictionary \"%s\"", filename);
|
||||
continue;
|
||||
}
|
||||
dictl -> dict = dict;
|
||||
dictl -> next = dictlist;
|
||||
dictlist = dictl;
|
||||
|
||||
} else
|
||||
warning_out("can't open dictionary \"%s\"", filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static str_match(s, d)
|
||||
char *s;
|
||||
char *d;
|
||||
{
|
||||
while (*d) {
|
||||
if (*s == '*') {
|
||||
while (*s == '*') s++;
|
||||
if (!*s) return TRUE;
|
||||
while (*d) {
|
||||
if (str_match(s, d)) return TRUE;
|
||||
d++;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
if (*s != '?' && *s != *d) break;
|
||||
s++;
|
||||
d++;
|
||||
}
|
||||
return (!*s) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
check_user(user, host)
|
||||
char *user;
|
||||
char *host;
|
||||
{
|
||||
StrList *p;
|
||||
|
||||
if (!allow_user) return TRUE;
|
||||
|
||||
for (p = allow_user ; p ; p = p -> link) {
|
||||
if (!str_match(p -> str1, user)) continue;
|
||||
|
||||
if (p -> str2)
|
||||
if (!str_match(p -> str2, host)) continue;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
41
server/time_stamp.c
Normal file
41
server/time_stamp.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 1991-1994 Sony Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Except as contained in this notice, the name of Sony Corporation
|
||||
* shall not be used in advertising or otherwise to promote the sale, use
|
||||
* or other dealings in this Software without prior written authorization
|
||||
* from Sony Corporation.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* $SonyRCSfile: time_stamp.c,v $
|
||||
* $SonyRevision: 1.6 $
|
||||
* $SonyDate: 1998/04/08 13:11:10 $
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
char *time_stamp = "Mon Mar 23 16:42:59 JST 1998";
|
||||
|
||||
40
server/version.c
Normal file
40
server/version.c
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 1991-1994 Sony Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Except as contained in this notice, the name of Sony Corporation
|
||||
* shall not be used in advertising or otherwise to promote the sale, use
|
||||
* or other dealings in this Software without prior written authorization
|
||||
* from Sony Corporation.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* $SonyRCSfile: version.c,v $
|
||||
* $SonyRevision: 1.9 $
|
||||
* $SonyDate: 1998/04/08 13:11:10 $
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
char *version_number = "2.08C";
|
||||
Loading…
Add table
Add a link
Reference in a new issue