1 /*
2  * libmavis_log.c
3  *
4  * (C)1998-2011 by Marc Huber <Marc.Huber@web.de>
5  * All rights reserved.
6  *
7  * $Id: libmavis_log.c,v 1.16 2015/03/14 06:11:28 marc Exp $
8  *
9  */
10 
11 #define __MAVIS_log__
12 
13 #include "misc/memops.h"
14 #include "mavis.h"
15 #include "debug.h"
16 #include "log.h"
17 #include <string.h>
18 #include <dlfcn.h>
19 
20 static const char rcsid[] __attribute__ ((used)) = "$Id: libmavis_log.c,v 1.16 2015/03/14 06:11:28 marc Exp $";
21 
22 #define HAVE_mavis_parse_in
mavis_parse_in(mavis_ctx * mcx,struct sym * sym)23 static int mavis_parse_in(mavis_ctx * mcx, struct sym *sym)
24 {
25     while (1) {
26 	switch (sym->code) {
27 	case S_script:
28 	    mavis_script_parse(mcx, sym);
29 	    continue;
30 	case S_eof:
31 	case S_closebra:
32 	    return MAVIS_CONF_OK;
33 	default:
34 	    parse_error_expect(sym, S_script, S_unknown);
35 	}
36     }
37 }
38 
39 #define HAVE_mavis_recv_out
mavis_recv_out(void * pcx,av_ctx ** ac)40 static int mavis_recv_out(void *pcx __attribute__ ((unused)), av_ctx ** ac)
41 {
42     char *avresult = av_get(*ac, AV_A_RESULT);
43     char *avcomment = av_get(*ac, AV_A_COMMENT);
44     char *avtype = av_get(*ac, AV_A_TYPE);
45     char *avuser = av_get(*ac, AV_A_USER);
46     char *avipaddr = av_get(*ac, AV_A_IPADDR);
47     char *avtransport = av_get(*ac, AV_A_TRANSPORT);
48     char *avpath = av_get(*ac, AV_A_PATH);
49 
50     if (!avresult)
51 	avresult = AV_V_RESULT_NOTFOUND;
52 
53     if (avtype) {
54 	if (avuser && avipaddr && (!strcmp(avtype, AV_V_TYPE_FTP)
55 				   || !strcmp(avtype, AV_V_TYPE_LOGIN)
56 				   || !strcmp(avtype, AV_V_TYPE_WWW)
57 				   || !strcmp(avtype, AV_V_TYPE_POP3)
58 				   || !strcmp(avtype, AV_V_TYPE_TACPLUS)
59 				   || !strcmp(avtype, AV_V_TYPE_POP3PATH))) {
60 	    if (avcomment)
61 		logmsg("%s %s: %s [%s] (%s)", avtype, avresult, avuser, avipaddr, avcomment);
62 	    else
63 		logmsg("%s %s: %s [%s]", avtype, avresult, avuser, avipaddr);
64 	} else if (!strcmp(avtype, AV_V_TYPE_RADIUS) && avuser) {
65 	    if (avcomment)
66 		logmsg("%s %s: %s (%s)", avtype, avresult, avuser, avcomment);
67 	    else
68 		logmsg("%s %s: %s", avtype, avresult, avuser);
69 	} else if (!strcmp(avtype, AV_V_TYPE_TRANSPORT)
70 		   || !strcmp(avtype, AV_V_TYPE_VIRTUAL)) {
71 	    if (avcomment) {
72 		if (avtransport && !strcmp(avresult, AV_V_RESULT_OK))
73 		    logmsg("%s %s: '%s' -> '%s%s%s' (%s)", avtype, avresult, avuser, avtransport, avpath ? ":" : "", avpath ? avpath : "", avcomment);
74 		else
75 		    logmsg("%s %s: '%s' (%s)", avtype, avresult, avuser, avcomment);
76 	    } else {
77 		if (avtransport && !strcmp(avresult, AV_V_RESULT_OK))
78 		    logmsg("%s %s: '%s' -> '%s%s%s'", avtype, avresult, avuser, avtransport, avpath ? ":" : "", avpath ? avpath : "");
79 		else
80 		    logmsg("%s %s: '%s'", avtype, avresult, avuser);
81 	    }
82 	} else if (!strcmp(avtype, AV_V_TYPE_CANONICAL)) {
83 	    if (avcomment) {
84 		if (avtransport && !strcmp(avresult, AV_V_RESULT_OK))
85 		    logmsg("%s %s: '%s' -> '%s' (%s)", avtype, avresult, avuser, avpath ? avpath : "", avcomment);
86 		else
87 		    logmsg("%s %s: '%s' (%s)", avtype, avresult, avuser, avcomment);
88 	    } else {
89 		if (avtransport && !strcmp(avresult, AV_V_RESULT_OK))
90 		    logmsg("%s %s: '%s' -> '%s'", avtype, avresult, avuser, avpath ? avpath : "");
91 		else
92 		    logmsg("%s %s: '%s'", avtype, avresult, avuser);
93 	    }
94 	}
95     }
96     return MAVIS_FINAL;
97 }
98 
99 #define MAVIS_name "log"
100 #include "mavis_glue.c"
101