2004-05-09 Michael Poole <mdpoole@troilus.org>
[ircu2.10.12-pk.git] / include / s_conf.h
1 /*
2  * s_conf.h
3  *
4  * $Id$ 
5  */
6 #ifndef INCLUDED_s_conf_h
7 #define INCLUDED_s_conf_h
8 #ifndef INCLUDED_time_h
9 #include <time.h>              /* struct tm */
10 #define INCLUDED_time_h
11 #endif
12 #ifndef INCLUDED_sys_types_h
13 #include <sys/types.h>
14 #define INCLUDED_sys_types_h
15 #endif
16 #ifndef INCLUDED_netinet_in_h
17 #include <netinet/in.h>        /* struct in_addr */
18 #define INCLUDED_netinet_in_h
19 #endif
20 #include "client.h"
21
22 struct Client;
23 struct SLink;
24 struct TRecord;
25 struct Message;
26
27
28 /*
29  * General defines
30  */
31
32 /*-----------------------------------------------------------------------------
33  * Macros
34  */
35
36 #define CONF_ILLEGAL            0x80000000
37 #define CONF_MATCH              0x40000000
38 #define CONF_CLIENT             0x0002
39 #define CONF_SERVER             0x0004
40 #define CONF_LOCOP              0x0010
41 #define CONF_OPERATOR           0x0020
42 #define CONF_LEAF               0x1000
43 #define CONF_HUB                0x4000
44 #define CONF_UWORLD             0x8000
45
46 #define CONF_OPS                (CONF_OPERATOR | CONF_LOCOP)
47 #define CONF_CLIENT_MASK        (CONF_CLIENT | CONF_OPS | CONF_SERVER)
48
49 #define IsIllegal(x)    ((x)->status & CONF_ILLEGAL)
50
51 /*
52  * Structures
53  */
54
55 struct ConfItem
56 {
57   struct ConfItem *next;
58   unsigned int status;      /* If CONF_ILLEGAL, delete when no clients */
59   unsigned int clients;     /* Number of *LOCAL* clients using this */
60   struct ConnectionClass *conn_class;  /* Class of connection */
61   struct in_addr ipnum;       /* ip number of host field */
62   char *host;
63   char *passwd;
64   char *name;
65   time_t hold; /* Hold until this time (calendar time) */
66   int dns_pending; /* a dns request is pending */
67   unsigned short port;
68   unsigned char bits; /* Number of bits for ipkills. */
69   struct Privs privs; /* Priviledges for opers. */
70   /* Used to detect if a privilege has been touched. */
71   struct Privs privs_dirty;
72 };
73
74 struct ServerConf {
75   struct ServerConf* next;
76   char*              hostname;
77   char*              passwd;
78   char*              alias;
79   struct in_addr     address;
80   int                port;
81   int                dns_pending;
82   int                connected;
83   time_t             hold;
84   struct ConnectionClass*  conn_class;
85 };
86
87 struct qline
88 {
89   struct qline *next;
90   char *chname;
91   char *reason;
92 };
93
94 struct DenyConf {
95   struct DenyConf*    next;
96   char*               hostmask;
97   char*               message;
98   char*               usermask;
99   unsigned int        address;
100   unsigned int        flags;
101   char                bits;        /* Number of bits for ipkills */
102 };
103
104 #define DENY_FLAGS_FILE     0x0001 /* Comment is a filename */
105 #define DENY_FLAGS_IP       0x0002 /* K-line by IP address */
106 #define DENY_FLAGS_REALNAME 0x0004 /* K-line by real name */
107
108 /*
109  * A line: A:<line 1>:<line 2>:<line 3>
110  */
111 struct LocalConf {
112   char*          name;
113   char*          description;
114   struct in_addr vhost_address;
115   unsigned int   numeric;
116   char*          location1;
117   char*          location2;
118   char*          contact;
119 };
120
121 struct MotdItem {
122   char line[82];
123   struct MotdItem *next;
124 };
125
126 struct MotdConf {
127   struct MotdConf* next;
128   char* hostmask;
129   char* path;
130 };
131
132 enum {
133   CRULE_AUTO = 1,
134   CRULE_ALL  = 2,
135   CRULE_MASK = 3
136 };
137
138 struct CRuleNode;
139
140 struct CRuleConf {
141   struct CRuleConf* next;
142   char*             hostmask;
143   char*             rule;
144   int               type;
145   struct CRuleNode* node;
146 };
147
148 struct TRecord {
149   struct TRecord *next;
150   char *hostmask;
151   struct MotdItem *tmotd;
152   struct tm tmotd_tm;
153 };
154
155 enum AuthorizationCheckResult {
156   ACR_OK,
157   ACR_NO_AUTHORIZATION,
158   ACR_TOO_MANY_IN_CLASS,
159   ACR_TOO_MANY_FROM_IP,
160   ACR_ALREADY_AUTHORIZED,
161   ACR_BAD_SOCKET
162 };
163
164 struct nick_host {
165   struct nick_host *next;
166   int nicklen; /* offset of @ part of server string */
167   char nick[1]; /* start of nick@server string */
168 };
169
170 struct s_map {
171   struct s_map *next;
172   struct Message *msg;
173   char *name;
174   char *command;
175   char *prepend;
176   struct nick_host *services;
177 };
178
179
180 /*
181  * GLOBALS
182  */
183 extern struct ConfItem* GlobalConfList;
184 extern int              GlobalConfCount;
185 extern struct tm        motd_tm;
186 extern struct MotdItem* motd;
187 extern struct MotdItem* rmotd;
188 extern struct TRecord*  tdata;
189 extern struct s_map*    GlobalServiceMapList;
190 extern struct qline*    GlobalQuarantineList;
191
192 /*
193  * Proto types
194  */
195
196 extern int init_conf(void);
197
198 extern const struct LocalConf* conf_get_local(void);
199 extern const struct MotdConf*  conf_get_motd_list(void);
200 extern const struct CRuleConf* conf_get_crule_list(void);
201 extern const struct DenyConf*  conf_get_deny_list(void);
202
203 extern const char* conf_eval_crule(const char* name, int mask);
204
205 extern struct ConfItem* attach_confs_byhost(struct Client* cptr, const char* host, int statmask);
206 extern struct ConfItem* find_conf_byhost(struct SLink* lp, const char* host, int statmask);
207 extern struct ConfItem* find_conf_byname(struct SLink* lp, const char *name, int statmask);
208 extern struct ConfItem* conf_find_server(const char* name);
209
210 extern void det_confs_butmask(struct Client *cptr, int mask);
211 extern enum AuthorizationCheckResult attach_conf(struct Client *cptr, struct ConfItem *aconf);
212 extern struct ConfItem* find_conf_exact(const char* name, const char* user,
213                                         const char* host, int statmask);
214 extern enum AuthorizationCheckResult conf_check_client(struct Client *cptr);
215 extern int  conf_check_server(struct Client *cptr);
216 extern struct ConfItem* find_conf_name(const char* name, int statmask);
217 extern int rehash(struct Client *cptr, int sig);
218 extern void read_tlines(void);
219 extern int find_kill(struct Client *cptr);
220 extern int find_restrict(struct Client *cptr);
221 extern struct MotdItem* read_motd(const char* motdfile);
222 extern const char *find_quarantine(const char* chname);
223 extern void lookup_confhost(struct ConfItem *aconf);
224
225 extern void yyerror(const char *msg);
226
227 #endif /* INCLUDED_s_conf_h */