]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/ipfilter/lib/save_execute.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / ipfilter / lib / save_execute.c
1 #include "ipf.h"
2 #include "ipmon.h"
3
4 static void *execute_parse __P((char **));
5 static void execute_destroy __P((void *));
6 static int execute_send __P((void *, ipmon_msg_t *));
7 static void execute_print __P((void *));
8
9 typedef struct execute_opts_s {
10         char    *path;
11 } execute_opts_t;
12
13 ipmon_saver_t executesaver = {
14         "execute",
15         execute_destroy,
16         NULL,                   /* dup */
17         NULL,                   /* match */
18         execute_parse,
19         execute_print,
20         execute_send
21 };
22
23
24 static void *
25 execute_parse(char **strings)
26 {
27         execute_opts_t *ctx;
28
29         ctx = calloc(1, sizeof(*ctx));
30
31         if (ctx != NULL && strings[0] != NULL && strings[0][0] != '\0') {
32                 ctx->path = strdup(strings[0]);
33
34         } else {
35                 free(ctx);
36                 return NULL;
37         }
38
39         return ctx;
40 }
41
42
43 static void
44 execute_print(ctx)
45         void *ctx;
46 {
47         execute_opts_t *exe = ctx;
48
49         printf("%s", exe->path);
50 }
51
52
53 static void
54 execute_destroy(ctx)
55         void *ctx;
56 {
57         execute_opts_t *exe = ctx;
58
59         if (exe != NULL)
60                 free(exe->path);
61         free(exe);
62 }
63
64
65 static int
66 execute_send(ctx, msg)
67         void *ctx;
68         ipmon_msg_t *msg;
69 {
70         execute_opts_t *exe = ctx;
71         FILE *fp;
72
73         fp = popen(exe->path, "w");
74         if (fp != NULL) {
75                 fwrite(msg->imm_msg, msg->imm_msglen, 1, fp);
76                 pclose(fp);
77         }
78         return 0;
79 }
80