/* -*-c-*-
*
- * $Id: identify.c,v 1.3 1999/07/26 23:26:21 mdw Exp $
+ * $Id: identify.c,v 1.5 1999/10/10 16:45:34 mdw Exp $
*
* Identifies and logs the client of a connection
*
/*----- Revision history --------------------------------------------------*
*
* $Log: identify.c,v $
+ * Revision 1.5 1999/10/10 16:45:34 mdw
+ * Modified to use new mLib resolver and ident client.
+ *
+ * Revision 1.4 1999/07/27 18:30:53 mdw
+ * Various minor portability fixes.
+ *
* Revision 1.3 1999/07/26 23:26:21 mdw
* Minor modifications for new design.
*
#include <netdb.h>
#include <mLib/alloc.h>
+#include <mLib/bres.h>
#include <mLib/conn.h>
#include <mLib/dstr.h>
+#include <mLib/ident.h>
#include <mLib/report.h>
#include <mLib/sel.h>
#include <mLib/selbuf.h>
#include <mLib/str.h>
-#include "bres.h"
#include "fw.h"
-#include "ident.h"
#include "identify.h"
/*----- Magic numbers -----------------------------------------------------*/
time_t when; /* When the connection occurred */
conn c; /* Connection selector */
unsigned state; /* Current state of the world */
+ sel_timer t; /* Timeout selector */
bres_client r; /* Backgd resolver client block */
+ ident_request i; /* Ident client block */
char host[64]; /* Resolved hostname */
char user[32]; /* Authenticated client user */
- sel_timer t; /* Timeout selector */
- selbuf id; /* Reader for the RFC931 client */
} id;
#define S_HOST 1u /* Read the hostname from resolver */
#define S_USER 2u /* Read the username from RFC931 */
-#define S_UCONN 4u /* Connected to remote RFC931 */
-#define S_TIMER 8u /* Timeout has completed */
+#define S_TIMER 4u /* Timeout has completed */
/*----- Main code ---------------------------------------------------------*/
if (!(i->state & S_HOST))
bres_abort(&i->r);
- if (!(i->state & S_UCONN))
- conn_kill(&i->c);
- else if (!(i->state & S_USER))
- selbuf_disable(&i->id);
+ if (!(i->state & S_USER))
+ ident_abort(&i->i);
if (!(i->state & S_TIMER))
sel_rmtimer(&i->t);
/* --- @id_res@ --- *
*
- * Arguments: @const char *host@ = name of the resolved host
+ * Arguments: @struct hostent *h@ = name of the resolved host
* @void *vp@ = pointer to identification block
*
* Returns: ---
* Use: Responds to a completed reverse name resolution.
*/
-static void id_res(const char *host, void *vp)
+static void id_res(struct hostent *h, void *vp)
{
id *i = vp;
- str_sanitize(i->host, host, sizeof(i->host));
+ if (h)
+ str_sanitize(i->host, h->h_name, sizeof(i->host));
i->state |= S_HOST;
if (i->state & S_USER)
id_done(i);
/* --- @id_ident@ --- *
*
- * Arguments: @char *p@ = pointer to string read from server
+ * Arguments: @ident_reply *i@ = pointer to string read from server
* @void *vp@ = pointer to identification block
*
* Returns: ---
* Use: Responds to a line read from the remote RFC931 server.
*/
-static void id_ident(char *p, void *vp)
+static void id_ident(ident_reply *ir, void *vp)
{
id *i = vp;
- /* --- Get rid of the connection --- */
-
- i->state |= S_USER;
- selbuf_disable(&i->id);
- close(i->id.reader.fd);
-
- /* --- Read the information from the returned line --- */
+ /* --- Read the information from the client --- */
- if (p) {
- ident idbuf;
- ident_parse(p, &idbuf);
- if (idbuf.type == ident_userid)
- str_sanitize(i->user, idbuf.u.userid.user, sizeof(i->user));
- }
+ if (ir && ir->type == IDENT_USERID)
+ str_sanitize(i->user, ir->u.userid.user, sizeof(i->user));
/* --- Maybe finish off this identification --- */
+ i->state |= S_USER;
if (i->state & S_HOST)
id_done(i);
}
-/* --- @id_conn@ --- *
- *
- * Arguments: @int fd@ = file descriptor connected
- * @void *vp@ = pointer to identification block
- *
- * Returns: ---
- *
- * Use: Responds to a completed connection to the remote RFC931
- * server.
- */
-
-static void id_conn(int fd, void *vp)
-{
- id *i = vp;
-
- if (fd == -1) {
- i->state |= S_USER | S_UCONN;
- if (i->state & S_HOST)
- id_done(i);
- } else {
- dstr d = DSTR_INIT;
- dstr_putf(&d, "%u, %u\n",
- ntohs(i->q.rsin.sin_port), ntohs(i->q.lsin.sin_port));
- write(fd, d.buf, d.len);
- dstr_destroy(&d);
- i->state |= S_UCONN;
- selbuf_init(&i->id, sel, fd, id_ident, i);
- }
-}
-
/* --- @id_timer@ --- *
*
* Arguments: @struct timeval *tv@ = pointer to the current time
/* --- Set up the connection to the identity server --- */
- {
- int fd;
- struct sockaddr_in sin;
-
- if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0)
- id_conn(-1, i);
- else {
- sin.sin_family = AF_INET;
- sin.sin_addr = q->lsin.sin_addr;
- sin.sin_port = 0;
- if (bind(fd, (struct sockaddr *)&sin, sizeof(sin))) {
- close(fd);
- id_conn(-1, i);
- } else {
- int opt = 1;
- sin.sin_family = AF_INET;
- sin.sin_addr = q->rsin.sin_addr;
- sin.sin_port = htons(113);
- setsockopt(fd, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt));
- conn_init(&i->c, sel, fd,
- (struct sockaddr *)&sin, sizeof(sin),
- id_conn, i);
- }
- }
- }
+ ident(&i->i, sel, &q->lsin, &q->rsin, id_ident, i);
/* --- Set up the name resolver --- */
- bres_resolve(&i->r, q->rsin.sin_addr, id_res, i);
+ bres_byaddr(&i->r, q->rsin.sin_addr, id_res, i);
/* --- Set up the time limiter --- */