From e5398e091780133b1049bd87a75fbc299ed51749 Mon Sep 17 00:00:00 2001 From: mdw Date: Mon, 26 Jul 1999 23:26:21 +0000 Subject: [PATCH] Minor modifications for new design. --- acl.c | 29 +++++++++++++++++++++++++---- acl.h | 22 ++++++++++++++++++---- chan.c | 22 ++++++++++++---------- identify.c | 38 +++++++++++++------------------------- identify.h | 21 +++++++++++++-------- 5 files changed, 81 insertions(+), 51 deletions(-) diff --git a/acl.c b/acl.c index 4dadc24..a7e448e 100644 --- a/acl.c +++ b/acl.c @@ -1,10 +1,10 @@ /* -*-c-*- * - * $Id: acl.c,v 1.1 1999/07/01 08:56:23 mdw Exp $ + * $Id: acl.c,v 1.2 1999/07/26 23:28:15 mdw Exp $ * * Access control list handling * - * (c) 1999 Mark Wooding + * (c) 1999 Straylight/Edgeware */ /*----- Licensing notice --------------------------------------------------* @@ -29,8 +29,11 @@ /*----- Revision history --------------------------------------------------* * * $Log: acl.c,v $ - * Revision 1.1 1999/07/01 08:56:23 mdw - * Initial revision + * Revision 1.2 1999/07/26 23:28:15 mdw + * Minor modifications for new design. + * + * Revision 1.1.1.1 1999/07/01 08:56:23 mdw + * Initial revision. * */ @@ -110,6 +113,24 @@ void acl_dump(acl_entry *a, FILE *fp) } } +/* --- @acl_free@ --- * + * + * Arguments: @acl_entry *a@ = pointer to a list of ACLs + * + * Returns: --- + * + * Use: Frees all of the memory used by an ACL. + */ + +void acl_free(acl_entry *a) +{ + while (a) { + acl_entry *aa = a; + a = a->next; + DESTROY(aa); + } +} + /* --- @acl_add@ --- * * * Arguments: @acl_entry ***a@ = address of pointer to list tail diff --git a/acl.h b/acl.h index 8b8588c..45b8a40 100644 --- a/acl.h +++ b/acl.h @@ -1,10 +1,10 @@ /* -*-c-*- * - * $Id: acl.h,v 1.1 1999/07/01 08:56:23 mdw Exp $ + * $Id: acl.h,v 1.2 1999/07/26 23:28:16 mdw Exp $ * * Access control list handling * - * (c) 1999 Mark Wooding + * (c) 1999 Straylight/Edgeware */ /*----- Licensing notice --------------------------------------------------* @@ -29,8 +29,11 @@ /*----- Revision history --------------------------------------------------* * * $Log: acl.h,v $ - * Revision 1.1 1999/07/01 08:56:23 mdw - * Initial revision + * Revision 1.2 1999/07/26 23:28:16 mdw + * Minor modifications for new design. + * + * Revision 1.1.1.1 1999/07/01 08:56:23 mdw + * Initial revision. * */ @@ -88,6 +91,17 @@ extern int acl_check(acl_entry */*a*/, struct in_addr /*addr*/); extern void acl_dump(acl_entry */*a*/, FILE */*fp*/); +/* --- @acl_free@ --- * + * + * Arguments: @acl_entry *a@ = pointer to a list of ACLs + * + * Returns: --- + * + * Use: Frees all of the memory used by an ACL. + */ + +extern void acl_free(acl_entry */*a*/); + /* --- @acl_add@ --- * * * Arguments: @acl_entry ***a@ = address of pointer to list tail diff --git a/chan.c b/chan.c index 55e6a75..855c769 100644 --- a/chan.c +++ b/chan.c @@ -1,10 +1,10 @@ /* -*-c-*- * - * $Id: chan.c,v 1.1 1999/07/01 08:56:23 mdw Exp $ + * $Id: chan.c,v 1.2 1999/07/26 23:27:52 mdw Exp $ * * Channel management * - * (c) 1999 Mark Wooding + * (c) 1999 Straylight/Edgeware */ /*----- Licensing notice --------------------------------------------------* @@ -29,8 +29,11 @@ /*----- Revision history --------------------------------------------------* * * $Log: chan.c,v $ - * Revision 1.1 1999/07/01 08:56:23 mdw - * Initial revision + * Revision 1.2 1999/07/26 23:27:52 mdw + * Minor modifications for new design. + * + * Revision 1.1.1.1 1999/07/01 08:56:23 mdw + * Initial revision. * */ @@ -114,10 +117,8 @@ static void writechan(int fd, unsigned mode, void *vp) /* --- Close the output end if necessary --- */ - if (c->len == 0 && (c->f & CHANF_CLOSE)) { - shutdown(fd, 1); + if (c->len == 0 && (c->f & CHANF_CLOSE)) c->func(c->p); - } return; /* --- Force a close if an error occurred --- */ @@ -167,7 +168,7 @@ static void readchan(int fd, unsigned mode, void *vp) } else if (r == 0) goto close; - else if (c->len == 0 && !(c->f & CHANF_READY)) + else if (c->len == 0 && (c->f & CHANF_READY)) sel_addfile(&c->w); c->len += r; if (c->len == CHAN_BUFSZ) @@ -178,7 +179,7 @@ static void readchan(int fd, unsigned mode, void *vp) close: c->f |= CHANF_CLOSE; - if (!c->len) + if (!c->len && (c->f & CHANF_READY)) sel_addfile(&c->w); sel_rmfile(&c->r); } @@ -216,8 +217,9 @@ void chan_dest(chan *c, int fd) if (c->f & CHANF_READY) return; sel_initfile(sel, &c->w, fd, SEL_WRITE, writechan, c); - if (c->len) + if (c->len || (c->f & CHANF_CLOSE)) sel_addfile(&c->w); + c->f |= CHANF_READY; } /* --- @chan_open@ --- * diff --git a/identify.c b/identify.c index 86cd594..50f7ae2 100644 --- a/identify.c +++ b/identify.c @@ -1,10 +1,10 @@ /* -*-c-*- * - * $Id: identify.c,v 1.2 1999/07/03 13:56:59 mdw Exp $ + * $Id: identify.c,v 1.3 1999/07/26 23:26:21 mdw Exp $ * * Identifies and logs the client of a connection * - * (c) 1999 Mark Wooding + * (c) 1999 Straylight/Edgeware */ /*----- Licensing notice --------------------------------------------------* @@ -29,6 +29,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: identify.c,v $ + * Revision 1.3 1999/07/26 23:26:21 mdw + * Minor modifications for new design. + * * Revision 1.2 1999/07/03 13:56:59 mdw * Log connections to syslog or stderr as appropriate. * @@ -80,8 +83,6 @@ typedef struct id { id_req q; /* Copy of client's request block */ - void (*func)(void */*p*/); /* Function to call when done */ - void *p; /* Argument to pass to function */ time_t when; /* When the connection occurred */ conn c; /* Connection selector */ unsigned state; /* Current state of the world */ @@ -110,9 +111,6 @@ typedef struct id { static void id_done(id *i) { - char buf[64]; - struct tm *tm; - /* --- Close down the various dependent bits --- */ if (!(i->state & S_HOST)) @@ -126,21 +124,13 @@ static void id_done(id *i) /* --- Report the final result --- */ - tm = localtime(&i->when); - strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm); - if (flags & FW_SYSLOG) { - syslog(LOG_NOTICE, "%s %s %s from %s@%s [%s]\n", - buf, i->q.desc, i->q.act, - i->user, i->host, inet_ntoa(i->q.rsin.sin_addr)); - } else { - fprintf(stderr, "%s %s %s from %s@%s [%s]\n", - buf, i->q.desc, i->q.act, - i->user, i->host, inet_ntoa(i->q.rsin.sin_addr)); - } + fw_log(i->when, "[%s] %s from %s@%s [%s]", + i->q.desc, i->q.act, + i->user, i->host, inet_ntoa(i->q.rsin.sin_addr)); /* --- Dispose of the block --- */ - i->func(i->p); + REFFD_DEC(i->q.r); free(i); } @@ -247,8 +237,6 @@ static void id_timer(struct timeval *tv, void *vp) /* --- @identify@ --- * * * Arguments: @const id_req *q@ = pointer to request block - * @void (*func)(void *p)@ = function to call when done - * @void *p@ = argument to pass to function * * Returns: --- * @@ -256,8 +244,7 @@ static void id_timer(struct timeval *tv, void *vp) * which will, eventually, report a message to the system log. */ -void identify(const id_req *q, - void (*func)(void */*p*/), void *p) +void identify(const id_req *q) { id *i; @@ -265,8 +252,7 @@ void identify(const id_req *q, i = xmalloc(sizeof(*i)); i->q = *q; - i->func = func; - i->p = p; + REFFD_INC(i->q.r); str_sanitize(i->host, inet_ntoa(q->rsin.sin_addr), sizeof(i->host)); strcpy(i->user, ""); @@ -289,9 +275,11 @@ void identify(const id_req *q, 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); diff --git a/identify.h b/identify.h index c4019b6..b7fe1bc 100644 --- a/identify.h +++ b/identify.h @@ -1,10 +1,10 @@ /* -*-c-*- * - * $Id: identify.h,v 1.1 1999/07/01 08:56:23 mdw Exp $ + * $Id: identify.h,v 1.2 1999/07/26 23:26:21 mdw Exp $ * * Identifies and logs the client of a connection * - * (c) 1999 Mark Wooding + * (c) 1999 Straylight/Edgeware */ /*----- Licensing notice --------------------------------------------------* @@ -29,8 +29,11 @@ /*----- Revision history --------------------------------------------------* * * $Log: identify.h,v $ - * Revision 1.1 1999/07/01 08:56:23 mdw - * Initial revision + * Revision 1.2 1999/07/26 23:26:21 mdw + * Minor modifications for new design. + * + * Revision 1.1.1.1 1999/07/01 08:56:23 mdw + * Initial revision. * */ @@ -46,6 +49,10 @@ #include #include +#ifndef REFFD_H +# include "reffd.h" +#endif + /*----- Data structures ---------------------------------------------------*/ typedef struct id_req { @@ -53,6 +60,7 @@ typedef struct id_req { struct sockaddr_in rsin; /* Remote address of connection */ const char *desc; /* Description of connection */ const char *act; /* Action taken by server */ + reffd *r; /* Pointer to file descriptor */ } id_req; /*----- Functions provided ------------------------------------------------*/ @@ -60,8 +68,6 @@ typedef struct id_req { /* --- @identify@ --- * * * Arguments: @const id_req *q@ = pointer to request block - * @void (*func)(void *p)@ = function to call when done - * @void *p@ = argument to pass to function * * Returns: --- * @@ -69,8 +75,7 @@ typedef struct id_req { * which will, eventually, report a message to the system log. */ -extern void identify(const id_req */*q*/, - void (*/*func*/)(void */*p*/), void */*p*/); +extern void identify(const id_req */*q*/); /*----- That's all, folks -------------------------------------------------*/ -- 2.11.0