nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | #include <string.h> |
2 | #include <stdio.h> |
||
3 | #include <stdlib.h> |
||
4 | |||
5 | #include "greylist.h" |
||
6 | #include "helpers.h" |
||
7 | |||
8 | struct greylist { |
||
9 | struct ether_addr mac; |
||
10 | struct greylist *next; |
||
11 | }; |
||
12 | |||
13 | struct greylist *glist = NULL; |
||
14 | char black = 0; |
||
15 | |||
16 | struct greylist *add_to_greylist(struct ether_addr new, struct greylist *glist) { |
||
17 | struct greylist *gnew = malloc(sizeof(struct greylist)); |
||
18 | |||
19 | gnew->mac = new; |
||
20 | |||
21 | if (glist) { |
||
22 | gnew->next = glist->next; |
||
23 | glist->next = gnew; |
||
24 | } else { |
||
25 | glist = gnew; |
||
26 | gnew->next = gnew; |
||
27 | } |
||
28 | |||
29 | return glist; |
||
30 | } |
||
31 | |||
32 | struct greylist *search_in_greylist(struct ether_addr mac, struct greylist *glist) { |
||
33 | struct greylist *first; |
||
34 | |||
35 | if (! glist) return NULL; |
||
36 | |||
37 | first = glist; |
||
38 | do { |
||
39 | if (MAC_MATCHES(mac, glist->mac)) { |
||
40 | return glist; |
||
41 | } |
||
42 | glist = glist->next; |
||
43 | } while (glist != first); |
||
44 | |||
45 | return NULL; |
||
46 | } |
||
47 | |||
48 | void load_greylist(char isblacklist, char *filename) { |
||
49 | char *entry; |
||
50 | |||
51 | if (filename) { |
||
52 | entry = read_next_line(filename, 1); |
||
53 | while(entry) { |
||
54 | if (! search_in_greylist(parse_mac(entry), glist)) { //Only add new entries |
||
55 | glist = add_to_greylist(parse_mac(entry), glist); |
||
56 | } |
||
57 | free(entry); |
||
58 | entry = read_next_line(filename, 0); |
||
59 | } |
||
60 | } |
||
61 | |||
62 | black = isblacklist; |
||
63 | } |
||
64 | |||
65 | char is_blacklisted(struct ether_addr mac) { |
||
66 | struct greylist *entry = search_in_greylist(mac, glist); |
||
67 | |||
68 | if (black) { |
||
69 | if (entry) return 1; |
||
70 | else return 0; |
||
71 | } else { |
||
72 | if (entry) return 0; |
||
73 | else return 1; |
||
74 | } |
||
75 | } |
||
76 | |||
77 | char is_whitelisted(struct ether_addr mac) { |
||
78 | if (is_blacklisted(mac)) { |
||
79 | return 0; |
||
80 | } else { |
||
81 | return 1; |
||
82 | } |
||
83 | } |