home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 3
/
PDCD_3.iso
/
internet
/
tcpipsrc
/
h
/
if
/
MiscServ
/
c
/
ident
next >
Wrap
Text File
|
1995-02-06
|
3KB
|
145 lines
/*
*
* Simple ident support...
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "global.h"
#include "mbuf.h"
#include "timer.h"
#include "internet.h"
#include "icmp.h"
#include "netuser.h"
#include "tcp.h"
#include "ident.h"
#include "session.h"
#include "misc.h"
#include "arc.h"
static char idname[16];
static void sndmsg(struct tcb *, char *);
struct tcb *id_tcb = NULLTCB;
int ident1(int argc, char **argv)
{
extern int32 ip_addr;
struct socket lsocket;
if (id_tcb)
return(0);
/* start ident daemon */
lsocket.address = ip_addr;
lsocket.port = IDENT_PORT;
if (argc < 2)
strcpy(idname, "UNKNOWN");
else
{
strcpy(idname, argv[1]);
rip(idname);
}
id_tcb = open_tcp(&lsocket, NULLSOCK, TCP_SERVER, 0, (void(*)())rcv_ident,
NULLVFP, (void(*)())ident_state, 0, NULL);
return(0);
}
/*
* Handle incoming ident connections and closures.
*/
void ident_state(struct tcb *tcb, char old, char new)
{
struct ident *id;
old = old;
switch(new){
case ESTABLISHED:
id = (struct ident *) malloc(sizeof(struct ident));
tcb->user = (char *)id; /* Upward pointer */
id->tcb = tcb; /* Downward pointer */
return;
case CLOSED:
if (tcb == id_tcb)
{
close_tcp(id_tcb);
id_tcb = NULLTCB;
}
if (tcb->user != NULLCHAR)
free(tcb->user);
del_tcp(tcb);
break;
}
}
/*
* Stop the ident server.
*/
int ident0(void)
{
if (id_tcb != NULLTCB) {
close_tcp(id_tcb);
id_tcb = NULLTCB;
}
return(0);
}
/*
* Send a short message on a tcb
*/
static void sndmsg(struct tcb *tcb, char *msg)
{
struct mbuf *bp;
bp = qdata(msg,(int16)strlen(msg));
send_tcp(tcb,bp);
}
/*
* ident receive upcall.
*/
void rcv_ident(register struct tcb *tcb, int16 ccnt)
{
struct ident *id;
struct mbuf *mbuf,
*bp;
char req[80];
int cnt;
if ((id = (struct ident *) tcb->user) == NULLID) /* uh oh! */
return;
if(recv_tcp(tcb,&bp,ccnt) == 0)
return;
cnt = pullup(&bp, req, ccnt);
req[cnt] = '\0';
free_p(bp);
rip(req);
strcat(req, " : USERID : UNIX : ");
strcat(req, idname);
log_event(tcb,"ID Request: %s",req);
strcat(req, "\r\n");
sndmsg(tcb, req);
close_tcp(tcb);
}
int doident(int argc, char **argv)
{
if (argc>1)
{
strcpy(idname, argv[1]);
rip(idname);
}
else
cwprintf(NULL, "Ident: %s\r\n",idname);
return 0;
}