ircu2.10.12 pk910 fork
[ircu2.10.12-pk.git] / include / s_conf.h
1 /** @file s_conf.h
2  * @brief ircd configuration file API.
3  * @version $Id: s_conf.h 1462 2005-08-21 13:46:08Z entrope $
4  */
5 #ifndef INCLUDED_s_conf_h
6 #define INCLUDED_s_conf_h
7 #ifndef INCLUDED_time_h
8 #include <time.h>              /* struct tm */
9 #define INCLUDED_time_h
10 #endif
11 #ifndef INCLUDED_sys_types_h
12 #include <sys/types.h>
13 #define INCLUDED_sys_types_h
14 #endif
15 #include "client.h"
16
17 struct Client;
18 struct SLink;
19 struct Message;
20
21 /*
22  * General defines
23  */
24
25 /*-----------------------------------------------------------------------------
26  * Macros
27  */
28
29 #define CONF_ILLEGAL            0x80000000 /**< Delete the ConfItem when no remaining clients. */
30 #define CONF_CLIENT             0x0002     /**< ConfItem describes a Client block */
31 #define CONF_SERVER             0x0004     /**< ConfItem describes a Connect block */
32 #define CONF_OPERATOR           0x0020     /**< ConfItem describes an Operator block */
33 #define CONF_UWORLD             0x8000     /**< ConfItem describes a Uworld server */
34
35 #define CONF_AUTOCONNECT        0x0001     /**< Autoconnect to a server */
36 #define CONF_SECURE             0x0002     /**< Secure connection */
37
38 /** Indicates ConfItem types that count associated clients. */
39 #define CONF_CLIENT_MASK        (CONF_CLIENT | CONF_OPERATOR | CONF_SERVER)
40
41 /** Checks whether the CONF_ILLEGAL bit is set on \a x. */
42 #define IsIllegal(x)    ((x)->status & CONF_ILLEGAL)
43
44 /*
45  * Structures
46  */
47
48 /** Configuration item to limit peer or client access. */
49 struct ConfItem
50 {
51   struct ConfItem *next;    /**< Next ConfItem in #GlobalConfList */
52   unsigned int status;      /**< Set of CONF_* bits. */
53   unsigned int clients;     /**< Number of *LOCAL* clients using this */
54   unsigned int maximum;     /**< For CONF_SERVER, max hops.
55                                For CONF_CLIENT, max connects per IP. */
56   struct ConnectionClass *conn_class;  /**< Class of connection */
57   struct irc_sockaddr origin;  /**< Local address for outbound connections */
58   struct irc_sockaddr address; /**< IP and port */
59   char *username;     /**< For CONF_CLIENT and CONF_OPERATOR, username mask. */
60   char *host;         /**< Peer hostname */
61   char *origin_name;  /**< Text form of origin address */
62   char *passwd;       /**< Password field */
63   char *name;         /**< Name of peer */
64   char *hub_limit;    /**< Mask that limits servers allowed behind
65                          this one. */
66   time_t hold;        /**< Earliest time to attempt an outbound
67                          connect on this ConfItem. */
68   int dns_pending;    /**< A dns request is pending. */
69   int flags;          /**< Additional modifiers for item. */
70   int addrbits;       /**< Number of bits valid in ConfItem::address. */
71   struct Privs privs; /**< Privileges for opers. */
72   /** Used to detect if a privilege has been set by this ConfItem. */
73   struct Privs privs_dirty;
74 };
75
76 /** Channel quarantine structure. */
77 struct qline
78 {
79   struct qline *next; /**< Next qline in #GlobalQuarantineList. */
80   char *chname;       /**< Quarantined channel name. */
81   char *reason;       /**< Reason for quarantine. */
82 };
83
84 /** Local K-line structure. */
85 struct DenyConf {
86   struct DenyConf*    next;     /**< Next DenyConf in #denyConfList. */
87   char*               hostmask; /**< Mask for  IP or hostname. */
88   char*               message;  /**< Message to send to denied users. */
89   char*               usermask; /**< Mask for client's username. */
90   char*               realmask; /**< Mask for realname. */
91   struct irc_in_addr  address;  /**< Address for IP-based denies. */
92   unsigned int        flags;    /**< Interpretation flags for the above.  */
93   unsigned char       bits;     /**< Number of bits for ipkills */
94 };
95
96 #define DENY_FLAGS_FILE     0x0001 /**< Comment is a filename */
97
98 /** Local server configuration. */
99 struct LocalConf {
100   char*          name;        /**< Name of server. */
101   char*          description; /**< Description of server. */
102   unsigned int   numeric;     /**< Globally assigned server numnick. */
103   char*          location1;   /**< First line of location information. */
104   char*          location2;   /**< Second line of location information. */
105   char*          contact;     /**< Admin contact information. */
106 };
107
108 enum {
109   CRULE_AUTO = 1, /**< CRule applies to automatic connections. */
110   CRULE_ALL  = 2, /**< CRule applies to oper-requested connections. */
111   CRULE_MASK = 3
112 };
113
114 /** Connection rule configuration. */
115 struct CRuleConf {
116   struct CRuleConf* next;     /**< Next CRule in cruleConfList. */
117   char*             hostmask; /**< Mask of affected server names. */
118   char*             rule;     /**< Text version of the rule. */
119   int               type;     /**< One of CRULE_AUTO or CRULE_ALL. */
120   struct CRuleNode* node;     /**< Parsed form of the rule. */
121 };
122
123 /** Authorization check result. */
124 enum AuthorizationCheckResult {
125   ACR_OK,                 /**< User accepted. */
126   ACR_NO_AUTHORIZATION,   /**< No matching ConfItem for the user. */
127   ACR_TOO_MANY_IN_CLASS,  /**< Connection class was already full. */
128   ACR_TOO_MANY_FROM_IP,   /**< User's IP already has max connections. */
129   ACR_ALREADY_AUTHORIZED, /**< User already had an attached ConfItem. */
130   ACR_BAD_SOCKET          /**< Client has bad file descriptor. */
131 };
132
133 /** Target description for service commands. */
134 struct nick_host {
135   struct nick_host *next; /**< Next nick_host struct in struct s_map. */
136   int nicklen;            /**< offset of @ part of server string */
137   char nick[1];           /**< start of nick\@server string */
138 };
139
140 #define SMAP_FAST 1           /**< Command does not have MFLG_SLOW. */
141
142 /** Target set for a service pseudo-command. */
143 struct s_map {
144   struct s_map *next;         /**< Next element in #GlobalServiceMapList. */
145   struct Message *msg;        /**< Message element formed for this mapping. */
146   char *name;                 /**< Text name of the mapping. */
147   char *command;              /**< Command name to use. */
148   char *prepend;              /**< Extra text to prepend to user's text. */
149   unsigned int flags;         /**< Bitwise map of SMAP_* flags. */
150   struct nick_host *services; /**< Linked list of possible targets. */
151 };
152
153 /** WebIRC config types. */
154 #define WEBIRC_PASS  0      /**< Password the webirc has to send. */
155 #define WEBIRC_HOST  1      /**< Host/IP mask which must match to the webirc socket. */
156 #define WEBIRC_SPOOF 2      /**< Host/IP mask which must match the spoofed ip. */
157
158 /** WebIRC config node */
159 struct webirc_node {
160     unsigned int type;
161     unsigned int neg;
162     char *content;
163     struct webirc_node *next, *prev;
164 };
165
166 /** WebIRC config list */
167 struct webirc_block {
168     char name[NICKLEN + 1];             /**< name of the block */
169     struct webirc_node *list;           /**< list of entries: circular double linked list;
170                                                               NULL if empty; list itself is the first node
171                                                               sorted by type (ascending) */
172     struct webirc_block *next, *prev;
173 };
174
175
176 /*
177  * GLOBALS
178  */
179 extern struct ConfItem* GlobalConfList;
180 extern int              GlobalConfCount;
181 extern struct s_map*    GlobalServiceMapList;
182 extern struct qline*    GlobalQuarantineList;
183 extern char *           GlobalForwards[256];
184
185 /* WebIRC config list.
186  * - circular double linked list
187  * - NULL if no node present
188  * - the list itself is the first node
189  */
190 extern struct webirc_block *GlobalWebIRCConf;
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 CRuleConf* conf_get_crule_list(void);
200 extern const struct DenyConf*  conf_get_deny_list(void);
201
202 extern struct webirc_block *webirc_block();
203 extern void webirc_establish(struct webirc_block *block);
204 extern void webirc_set(struct webirc_block *block, unsigned int type, const char *content, unsigned int len, unsigned int neg);
205 extern void webirc_list_clear(struct webirc_block *block);
206 extern void webirc_clear();
207
208 extern const char* conf_eval_crule(const char* name, int mask);
209
210 extern struct ConfItem* attach_confs_byhost(struct Client* cptr, const char* host, int statmask);
211 extern struct ConfItem* find_conf_byhost(struct SLink* lp, const char* host, int statmask);
212 extern struct ConfItem* find_conf_byname(struct SLink* lp, const char *name, int statmask);
213 extern struct ConfItem* conf_find_server(const char* name);
214
215 extern void det_confs_butmask(struct Client *cptr, int mask);
216 extern enum AuthorizationCheckResult attach_conf(struct Client *cptr, struct ConfItem *aconf);
217 extern struct ConfItem* find_conf_exact(const char* name, struct Client *cptr, int statmask);
218 extern enum AuthorizationCheckResult conf_check_client(struct Client *cptr);
219 extern int  conf_check_server(struct Client *cptr);
220 extern int rehash(struct Client *cptr, int sig);
221 extern int find_kill(struct Client *cptr);
222 extern const char *find_quarantine(const char* chname);
223 extern void lookup_confhost(struct ConfItem *aconf);
224 extern void conf_parse_userhost(struct ConfItem *aconf, char *host);
225 extern struct ConfItem *conf_debug_iline(const char *client);
226 extern void free_mapping(struct s_map *smap);
227
228 extern void yyerror(const char *msg);
229
230 #endif /* INCLUDED_s_conf_h */