init
This commit is contained in:
13
logsrv/Makefile
Executable file
13
logsrv/Makefile
Executable file
@@ -0,0 +1,13 @@
|
||||
LIBS = -ltermcap
|
||||
CC = cc
|
||||
CFLAGS = -g
|
||||
OBJECTS = client.o socket.o
|
||||
|
||||
SOURCES = client.c socket.c
|
||||
|
||||
.c.o:
|
||||
${CC} ${CFLAGS} -c $<
|
||||
|
||||
client: ${OBJECTS}
|
||||
${CC} ${CFLAGS} -o dataservd ${OBJECTS} ${LIBS}
|
||||
|
||||
8
logsrv/autostart
Executable file
8
logsrv/autostart
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/csh
|
||||
cd /ecn/ecnstf0/irc/misc/dataserv
|
||||
while(1)
|
||||
if(-r core) then
|
||||
rm core
|
||||
dataservd
|
||||
endif
|
||||
end
|
||||
295
logsrv/client.c
Normal file
295
logsrv/client.c
Normal file
@@ -0,0 +1,295 @@
|
||||
/*
|
||||
WILDTHANG DATA SERVER VERSION 1.0
|
||||
WildThang is dvmitche@midway.ecn.uoknor.edu
|
||||
Please note that due to the nature of this program
|
||||
I have not opted to comment the code. I have done this for
|
||||
Various reasons!
|
||||
*/
|
||||
|
||||
/* do you REALLY think we need ALL of these *grin* */
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/wait.h>
|
||||
#include <netdb.h>
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <termios.h>
|
||||
|
||||
#ifdef SIGTSTP
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/file.h>
|
||||
#endif
|
||||
#include <sys/param.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <netinet/in.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include "config.h"
|
||||
|
||||
int PORTNUM = PORT,newsockfd,level;
|
||||
int NUMUSERS=0; /* counter of users logged in */
|
||||
int REFPROCESS=0;
|
||||
char buf[512],*hostname;
|
||||
char *Serv;
|
||||
char tempp[512];
|
||||
char sockbuf[512],*sptr;
|
||||
char loginname[20];
|
||||
|
||||
extern char *linetok[]; /* from socketc. */
|
||||
extern int USEIDENT; /* from socket.c */
|
||||
extern char *get_server(char *fromhost); /* from socket.c */
|
||||
|
||||
/* WARNING:THIS MUST NOT BE CHANGED... ELSE STRANGE THINGS SEEM TO HAPPEN */
|
||||
#define SOCKLINK 9219423
|
||||
#define VERSION "TELCLIENT_1.8"
|
||||
|
||||
void handle_kids()
|
||||
{int pid;
|
||||
|
||||
#ifdef OSF1
|
||||
union wait *status;
|
||||
status = (union wait *)malloc(sizeof(long));
|
||||
|
||||
while( (pid = wait3(status,WNOHANG, (struct rusage *)0)) > 0) { }
|
||||
|
||||
#else
|
||||
|
||||
union wait status;
|
||||
while( (pid = wait3(&status,WNOHANG, (struct rusage *)0)) > 0) { }
|
||||
|
||||
#endif /* OSF1 */
|
||||
|
||||
NUMUSERS--;
|
||||
}
|
||||
|
||||
|
||||
main(argc,argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{ int m,j,sockfd,insockfd,retlen,retval,outfd,infd,i,route;
|
||||
struct sockaddr_in sockst,insock;
|
||||
struct hostent *hp;
|
||||
int opt=1;
|
||||
struct sockaddr_in from;
|
||||
int fromlen;
|
||||
char hostid[255],hosthld[255];
|
||||
|
||||
signal(SIGCLD,handle_kids);
|
||||
if(BACKGROUND) goto_bg();
|
||||
|
||||
|
||||
if(argc > 1) { /* process command line options */
|
||||
if(*argv[1] == '-') {
|
||||
*argv[1]++;
|
||||
if(*argv[1]=='p')
|
||||
if(atoi(argv[2])>6000) PORTNUM = atoi(argv[2]);
|
||||
}
|
||||
}
|
||||
|
||||
if ((sockfd=socket(AF_INET,SOCK_STREAM,0))<0) {
|
||||
perror("socked");
|
||||
exit(1);
|
||||
}
|
||||
if(!BACKGROUND) printf("GOT SOCKET %d\n",sockfd);
|
||||
#ifdef SO_REUSEADDR
|
||||
if (setsockopt(sockfd,SOL_SOCKET, SO_REUSEADDR,&opt,sizeof(opt)) <0)
|
||||
{ exit(-1); }
|
||||
#endif
|
||||
|
||||
sockst.sin_family=AF_INET;
|
||||
sockst.sin_addr.s_addr=INADDR_ANY;
|
||||
sockst.sin_port=htons(PORTNUM);
|
||||
|
||||
if ((bind(sockfd,(struct sockaddr *)&sockst,sizeof(sockst)))<0) {
|
||||
perror("bind");
|
||||
exit(1);
|
||||
}
|
||||
if(!BACKGROUND) printf("BIND SOCKET Complete\n");
|
||||
|
||||
if ((listen(sockfd,1))<0) {
|
||||
perror("listen");
|
||||
exit(1);
|
||||
}
|
||||
if(!BACKGROUND) printf("Listening for connections\n");
|
||||
|
||||
while(1)
|
||||
{ if ((newsockfd=accept(sockfd,(struct sockaddr *) 0,(int *) 0))<0)
|
||||
{
|
||||
continue;
|
||||
/* will receive a sig from dying children */
|
||||
}
|
||||
if(!BACKGROUND) printf("GOT CONNECTION %d\n",newsockfd);
|
||||
|
||||
if (!fork())
|
||||
{
|
||||
close(sockfd);
|
||||
|
||||
do_menu(newsockfd);
|
||||
close(newsockfd);
|
||||
exit(0);
|
||||
}
|
||||
close(newsockfd);
|
||||
}
|
||||
}
|
||||
|
||||
int bbs_cat(sck,filename)
|
||||
int sck;
|
||||
char *filename;
|
||||
{
|
||||
FILE *fp;
|
||||
char *sbuf;
|
||||
char line[512],command[512];
|
||||
if ( (fp = fopen(filename,"r")) == NULL)
|
||||
return 0;
|
||||
for(; ;) {
|
||||
if(fgets(line,80,fp) == NULL) { fclose(fp); return 1; }
|
||||
if(write(sck,line,strlen(line)) != strlen(line)) {
|
||||
fclose(fp); return 1; }
|
||||
if(write(sck,"",0) != 0) {
|
||||
fclose(fp); return 1; }
|
||||
}
|
||||
}
|
||||
|
||||
int bbs_pcom(sck,command)
|
||||
int sck;
|
||||
char *command;
|
||||
{
|
||||
FILE *fp;
|
||||
char *sbuf;
|
||||
char line[512];
|
||||
if ( (fp = popen(command,"r")) == NULL)
|
||||
return 0;
|
||||
for(; ;) {
|
||||
if(fgets(line,80,fp) == NULL) { pclose(fp); return 1; }
|
||||
if(write(sck,line,strlen(line)) != strlen(line)) {
|
||||
pclose(fp); return 1; }
|
||||
if(write(sck,"",0) != 0) {
|
||||
pclose(fp); return 1; }
|
||||
}
|
||||
}
|
||||
int bbs_grep(sck,filename)
|
||||
int sck;
|
||||
char *filename;
|
||||
{
|
||||
FILE *fp;
|
||||
int i;
|
||||
char *sbuf,*token[256];
|
||||
char line[512],command[512];
|
||||
strcpy(line,sockbuf);
|
||||
|
||||
token[i=0]=strtok(sockbuf," ");
|
||||
while(token[++i]=strtok(NULL, " ")); token[i]=NULL;
|
||||
|
||||
if(i < 1) return 0;
|
||||
|
||||
sprintf(command,"%s -i %s %s",GREPCOM,token[0],filename);
|
||||
|
||||
bbs_pcom(sck,command);
|
||||
}
|
||||
|
||||
int bbs_tail(sck,filename)
|
||||
int sck;
|
||||
char *filename;
|
||||
{
|
||||
FILE *fp;
|
||||
int i;
|
||||
char *sbuf,*token[256];
|
||||
char line[512],command[512];
|
||||
strcpy(line,sockbuf);
|
||||
|
||||
token[i=0]=strtok(sockbuf," ");
|
||||
while(token[++i]=strtok(NULL, " ")); token[i]=NULL;
|
||||
|
||||
if(i < 1) return 0;
|
||||
|
||||
sprintf(command,"%s -50 %s",TAILCOM,filename);
|
||||
|
||||
bbs_pcom(sck,command);
|
||||
}
|
||||
|
||||
goto_bg()
|
||||
{
|
||||
register int child,fd;
|
||||
#ifdef SUN
|
||||
fclose(stdin); fclose(stdout); fclose(stderr);
|
||||
#else
|
||||
close(0); close(1); close(2);
|
||||
#endif
|
||||
|
||||
if(getppid() == 1) goto out;
|
||||
|
||||
#ifdef SIGTTOU
|
||||
signal(SIGTTOU,SIG_IGN);
|
||||
#endif
|
||||
#ifdef SIGTTIN
|
||||
signal(SIGTTIN,SIG_IGN);
|
||||
#endif
|
||||
#ifdef SIGTSTP
|
||||
signal(SIGTSTP,SIG_IGN);
|
||||
#endif
|
||||
|
||||
if( (child =fork()) < 0)
|
||||
perror("fork");
|
||||
else if (child > 0)
|
||||
exit(0);
|
||||
|
||||
#ifdef SIGTSTP
|
||||
if (setpgrp(0,getpid()) == -1)
|
||||
perror("SETGROUP");
|
||||
|
||||
if( (fd = open("/dev/tty",O_RDWR)) >= 0) {
|
||||
ioctl(fd, TIOCNOTTY, (char *)NULL);
|
||||
close(fd);
|
||||
}
|
||||
#else
|
||||
if(setpgrp() == -1)
|
||||
perror("set group");
|
||||
|
||||
signal(SIGHUP,SIG_IGN);
|
||||
|
||||
if( (child = fork()) < 0)
|
||||
perror("cant fork");
|
||||
else if (child > 0)
|
||||
exit(0);
|
||||
#endif
|
||||
|
||||
out:
|
||||
for(fd=0;fd<NOFILE;fd++)
|
||||
close(fd);
|
||||
errno = 0;
|
||||
|
||||
|
||||
#ifdef SIGTSTP
|
||||
signal(SIGCLD, handle_kids);
|
||||
#else
|
||||
signal(SIGCLD, SIG_IGN);
|
||||
#endif
|
||||
}
|
||||
|
||||
do_menu(int sckfd)
|
||||
{
|
||||
writeln(sckfd," Welcome to WildThang's Uworld Log report Service\n");
|
||||
writeln(sckfd," ==================================================\n");
|
||||
writeln(sckfd," please specify the word you wish to search for\n");
|
||||
writeln(sckfd," from the log database. some special commands are:\n");
|
||||
writeln(sckfd," ALL -- Displays the entire log file to you\n");
|
||||
writeln(sckfd," TAIL -- Displays the last 50 lines of the log\n");
|
||||
writeln(sckfd," KTEL -- Displays the activity of BANNED telusers\n");
|
||||
writeln(sckfd," KILL -- Displays the activity of KILLS by IRCops\n");
|
||||
writeln(sckfd," <word> -- scans log file for occurances of 'word'\n");
|
||||
writeln(sckfd," ==================================================\n");
|
||||
|
||||
writeln(sckfd,"\nEnter Choice: (press return when done) :");
|
||||
readcom(sckfd,10);
|
||||
if(strlen(sockbuf) < 1){ close(sckfd); exit(0); }
|
||||
|
||||
if(!strncasecmp(sockbuf,"tail",4)) bbs_tail(newsockfd,DATAFILE);
|
||||
else if(!strncasecmp(sockbuf,"all",3)) bbs_cat(newsockfd,DATAFILE);
|
||||
else bbs_grep(newsockfd,DATAFILE);
|
||||
|
||||
}
|
||||
14
logsrv/com.c
Normal file
14
logsrv/com.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
#include "config.h"
|
||||
|
||||
extern char *sptr,sockbuf[512];
|
||||
|
||||
/* i kept this seperate for ease in adding future commands. */
|
||||
void bbs_com(sck)
|
||||
int sck;
|
||||
{
|
||||
if(!match(sockbuf,"irc")) irc(sck,0);
|
||||
else irc(sck,0);
|
||||
return;
|
||||
}
|
||||
|
||||
26
logsrv/config.h
Executable file
26
logsrv/config.h
Executable file
@@ -0,0 +1,26 @@
|
||||
/* SYSTEM SPECIFIC CONFIGURATIONS */
|
||||
/* ONLY ONE OF THE FOLLOWING MAY BE DEFINED */
|
||||
|
||||
#undef ULTRIX /* this should work for most systems */
|
||||
#define OSF1 /* use this on DEC alpha machines */
|
||||
#undef NEED_SETENV /* use this if your system doesnt support setenv() */
|
||||
#define SUN
|
||||
|
||||
/* list of servers for client */
|
||||
/* defualt port all ports must be > 6000 if specified from commandline */
|
||||
#define PORT 9500
|
||||
#define DATAFILE "/ecn/ecnstf0/danny/dvmitche/uworld/Uworld.log"
|
||||
#define GREPCOM "/usr/ucb/grep"
|
||||
#define TAILCOM "/usr/ucb/tail"
|
||||
|
||||
#define MAXLINE 512
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#define BACKGROUND 1 /* +-integer for background */
|
||||
|
||||
#ifdef SUN
|
||||
#ifndef NEED_SETENV
|
||||
#define NEED_SETENV
|
||||
#endif
|
||||
|
||||
#endif
|
||||
144
logsrv/socket.c
Normal file
144
logsrv/socket.c
Normal file
@@ -0,0 +1,144 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
#include <signal.h>
|
||||
#include "config.h"
|
||||
|
||||
extern char buf[512];
|
||||
extern char sockbuf[512],*sptr;
|
||||
extern int PORTNUM;
|
||||
extern int level;
|
||||
|
||||
|
||||
char *linetok[256];
|
||||
int USEIDENT= 0;
|
||||
int call_socket(hostname,portnum)
|
||||
char *hostname;
|
||||
int portnum;
|
||||
{ struct sockaddr_in sa;
|
||||
struct hostent *hp;
|
||||
int a, s;
|
||||
if((hp=gethostbyname(hostname))==NULL) {
|
||||
errno=ECONNREFUSED;
|
||||
return(-1); }
|
||||
bzero(&sa, sizeof(sa));
|
||||
bcopy(hp->h_addr, (char *)&sa.sin_addr, hp->h_length);
|
||||
sa.sin_family = hp->h_addrtype;
|
||||
sa.sin_port = htons((u_short)portnum);
|
||||
if((s=socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0) return(-1);
|
||||
if(connect(s,(struct sockaddr *) &sa, sizeof(sa)) < 0) {
|
||||
close(s);
|
||||
return(-1); }
|
||||
return(s);
|
||||
}
|
||||
|
||||
int readln(int sckfd)
|
||||
{ int i=0,valid=1; char c;
|
||||
while(valid) {
|
||||
if(read(sckfd,&c,1)<1) return(0);
|
||||
if(i<511 && c != '\n') sockbuf[i++]=c; else valid=0; }
|
||||
sockbuf[i]='\0'; return(1);
|
||||
}
|
||||
|
||||
int writeln(sckfd,outbuf)
|
||||
int sckfd;
|
||||
char *outbuf;
|
||||
{ int to=0;
|
||||
if(write(sckfd, outbuf, strlen(outbuf)) < to )
|
||||
return(0);
|
||||
return(1);
|
||||
}
|
||||
|
||||
int readcom(sck,tout)
|
||||
int sck;
|
||||
int tout;
|
||||
{
|
||||
int sok;
|
||||
time_t time_in,time_out;
|
||||
int dumb = 1;
|
||||
fd_set readfs;
|
||||
struct timeval *zimeout;
|
||||
time_in=time(NULL);
|
||||
while(1) {
|
||||
time_out = time(NULL);
|
||||
if(time_out - time_in > tout) return 0;
|
||||
FD_ZERO(&readfs);
|
||||
FD_SET(sck,&readfs);
|
||||
if(select(FD_SETSIZE, &readfs, NULL, NULL,(dumb ? NULL : zimeout))) {
|
||||
|
||||
if(FD_ISSET(sck,&readfs)) {
|
||||
if(!BACKGROUND) puts("READING REPLY");
|
||||
sok = readln(sck);
|
||||
if (sok) {
|
||||
sptr=sockbuf;
|
||||
*(sptr+strlen(sockbuf)-1)='\0';
|
||||
return 1;
|
||||
} }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int do_auth(hostname,sockfd)
|
||||
char *hostname;
|
||||
int sockfd;
|
||||
{ int authfd,ulen,tlen,lcnt,ct;
|
||||
struct sockaddr_in sock,us,them;
|
||||
|
||||
writeln(sockfd,"Checking your identification\n");
|
||||
|
||||
if( (authfd=call_socket(hostname,113)) < 0) /* host not running identd */
|
||||
{
|
||||
USEIDENT=0;
|
||||
sprintf(buf,"[%d] [%s] You should ask your sysadmin to instal identd\n",
|
||||
authfd,hostname);
|
||||
writeln(sockfd,buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(getsockname(sockfd,(struct sockaddr *)&us,&ulen))
|
||||
{ if(!BACKGROUND) puts("getsockname failed");
|
||||
USEIDENT=0;
|
||||
return 0;
|
||||
}
|
||||
if(getpeername(sockfd,(struct sockaddr *)&them,&tlen))
|
||||
{ if(!BACKGROUND) puts("getpeername failed");
|
||||
USEIDENT=0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
sprintf(buf,"%u,%u \r\n",
|
||||
(unsigned int) ntohs(them.sin_port),
|
||||
(unsigned int) PORTNUM);
|
||||
|
||||
writeln(authfd,buf);
|
||||
writeln(sockfd,"CHECKING IDENTD\n");
|
||||
|
||||
readcom(authfd,15);
|
||||
if(!BACKGROUND) puts(sockbuf);
|
||||
|
||||
linetok[lcnt=0]=strtok(sockbuf," ");
|
||||
while(linetok[++lcnt]=strtok(NULL, " ")); linetok[lcnt]=NULL;
|
||||
|
||||
if((lcnt > 7) && (!strcmp(linetok[4],"USERID")))
|
||||
{ USEIDENT = 1;
|
||||
sprintf(buf,"Greetings %s@%s, Welcome to our system\n",linetok[8],
|
||||
hostname);
|
||||
writeln(sockfd,buf);
|
||||
if(!BACKGROUND)
|
||||
{ printf("GOT IT %s %d\n",linetok[8],lcnt);
|
||||
}
|
||||
}
|
||||
else USEIDENT = 0;
|
||||
close(authfd);
|
||||
}
|
||||
Reference in New Issue
Block a user