ze-filter  (ze-filter-0.8.0-develop-180218)
ze-netclass.h
Go to the documentation of this file.
1 /*
2  *
3  * ze-filter - Mail Server Filter for sendmail
4  *
5  * Copyright (c) 2001-2018 - Jose-Marcio Martins da Cruz
6  *
7  * Auteur : Jose Marcio Martins da Cruz
8  * jose.marcio.mc@gmail.org
9  *
10  * Historique :
11  * Creation : janvier 2002
12  *
13  * This program is free software, but with restricted license :
14  *
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19  *
20  * More details about ze-filter license can be found at ze-filter
21  * web site : http://foss.jose-marcio.org
22  */
23 
24 #ifndef __ZE_NETCLASS_H
25 
31 #define NET_UNKNOWN 0
32 
33 #define NET_LOCAL 0x0001
34 #define NET_DOMAIN 0x0002
35 #define NET_FRIEND 0x0004
36 #define NET_AUTH 0x0008
37 #define NET_OTHER 0x0080
38 
39 #define NET_WHITE 0x1000
40 #define NET_BLACK 0x2000
41 
42 #define NET_KNOWN (NET_LOCAL | NET_FRIEND | NET_DOMAIN | NET_AUTH | NET_OTHER)
43 
44 #define IS_FRIEND(class) (((class) & NET_FRIEND) != 0 ? TRUE : FALSE)
45 #define IS_DOMAIN(class) (((class) & NET_DOMAIN) != 0 ? TRUE : FALSE)
46 #define IS_LOCAL(class) (((class) & NET_LOCAL) != 0 ? TRUE : FALSE)
47 #define IS_AUTH(class) (((class) & NET_AUTH) != 0 ? TRUE : FALSE)
48 #define IS_OTHER(class) (((class) & NET_OTHER) != 0 ? TRUE : FALSE)
49 
50 #define IS_KNOWN(class) (((class) & NET_KNOWN) != 0 ? TRUE : FALSE)
51 #define IS_UNKNOWN(class) (((class) & NET_KNOWN) == 0 ? TRUE : FALSE)
52 
53 #define SET_NET_CLASS(class, which) ((class) |= (which))
54 
55 #define CLR_NET_CLASS(class, which) ((class) &= ~(which))
56 
57 #define NET_CLASS_LABEL(class) (IS_LOCAL(class) ? "LOCAL" : \
58  IS_DOMAIN(class) ? "DOMAIN" : \
59  IS_FRIEND(class) ? "FRIEND" : \
60  IS_AUTH(class) ? "AUTH" : \
61  IS_OTHER(class) ? "OTHER" : "UNKNOWN")
62 
63 #define NET_CLASS_VALUE(label) (STRCASEEQUAL(label, "LOCAL") ? NET_LOCAL : \
64  STRCASEEQUAL(label, "DOMAIN") ? NET_DOMAIN : \
65  STRCASEEQUAL(label, "FRIEND") ? NET_OTHER : \
66  STRCASEEQUAL(label, "OTHER") ? NET_OTHER : \
67  NET_UNKNOWN)
68 
69 typedef struct {
70  bool ok;
71  int class;
72  char label[32];
73  char equiv[32];
74 } netclass_T;
75 
76 #define NETCLASS_INITIALIZER {FALSE, NET_UNKNOWN}
77 
78 int check_host_class (char *ip, char *name,
79  char *label, size_t sz);
80 
81 int GetClientNetClass(char *ip, char *name, netclass_T *class,
82  char *label, size_t sz);
83 
84 int DecodeNetClass(char *, char *, size_t);
85 
86 
89 #define __ZE_NETCLASS_H
90 #endif
int check_host_class(char *ip, char *name, char *label, size_t sz)
int GetClientNetClass(char *ip, char *name, netclass_T *class, char *label, size_t sz)
Definition: ze-netclass.c:49
int DecodeNetClass(char *, char *, size_t)
Definition: ze-netclass.c:124