8860e0b46a7ffd8b106b15fdd830a993e6f96a6d
[ircu2.10.12-pk.git] / include / s_conf.h
1 /** @file s_conf.h
2  * @brief ircd configuration file API.
3  * @version $Id$
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 /** Indicates ConfItem types that count associated clients. */
36 #define CONF_CLIENT_MASK        (CONF_CLIENT | CONF_OPERATOR | CONF_SERVER)
37
38 /** Checks whether the CONF_ILLEGAL bit is set on \a x. */
39 #define IsIllegal(x)    ((x)->status & CONF_ILLEGAL)
40
41 /*
42  * Structures
43  */
44
45 /** Configuration item to limit peer or client access. */
46 struct ConfItem
47 {
48   struct ConfItem *next;    /**< Next ConfItem in #GlobalConfList */
49   unsigned int status;      /**< Set of CONF_* bits. */
50   unsigned int clients;     /**< Number of *LOCAL* clients using this */
51   unsigned int maximum;     /**< For CONF_SERVER, max hops.
52                                For CONF_CLIENT, max connects per IP. */
53   struct ConnectionClass *conn_class;  /**< Class of connection */
54   struct irc_sockaddr origin;  /**< Local address for outbound connections */
55   struct irc_sockaddr address; /**< IP and port */
56   char *username;     /**< For CONF_CLIENT and CONF_OPERATOR, username mask. */
57   char *host;         /**< Peer hostname */
58   char *origin_name;  /**< Text form of origin address */
59   char *passwd;       /**< Password field */
60   char *name;         /**< Name of peer */
61   char *hub_limit;    /**< Mask that limits servers allowed behind
62                          this one. */
63   time_t hold;        /**< Earliest time to attempt an outbound
64                          connect on this ConfItem. */
65   int dns_pending;    /**< A dns request is pending. */
66   int addrbits;       /**< Number of bits valid in ConfItem::address. */
67   struct Privs privs; /**< Privileges for opers. */
68   /** Used to detect if a privilege has been set by this ConfItem. */
69   struct Privs privs_dirty;
70 };
71
72 /** Channel quarantine structure. */
73 struct qline
74 {
75   struct qline *next; /**< Next qline in #GlobalQuarantineList. */
76   char *chname;       /**< Quarantined channel name. */
77   char *reason;       /**< Reason for quarantine. */
78 };
79
80 /** Local K-line structure. */
81 struct DenyConf {
82   struct DenyConf*    next;     /**< Next DenyConf in #denyConfList. */
83   char*               hostmask; /**< Mask for  IP or hostname. */
84   char*               message;  /**< Message to send to denied users. */
85   char*               usermask; /**< Mask for client's username. */
86   char*               realmask; /**< Mask for realname. */
87   struct irc_in_addr  address;  /**< Address for IP-based denies. */
88   unsigned int        flags;    /**< Interpretation flags for the above.  */
89   unsigned char       bits;     /**< Number of bits for ipkills */
90 };
91
92 #define DENY_FLAGS_FILE     0x0001 /**< Comment is a filename */
93
94 /** Local server configuration. */
95 struct LocalConf {
96   char*          name;        /**< Name of server. */
97   char*          description; /**< Description of server. */
98   unsigned int   numeric;     /**< Globally assigned server numnick. */
99   char*          location1;   /**< First line of location information. */
100   char*          location2;   /**< Second line of location information. */
101   char*          contact;     /**< Admin contact information. */
102 };
103
104 enum {
105   CRULE_AUTO = 1, /**< CRule applies to automatic connections. */
106   CRULE_ALL  = 2, /**< CRule applies to oper-requested connections. */
107   CRULE_MASK = 3
108 };
109
110 /** Connection rule configuration. */
111 struct CRuleConf {
112   struct CRuleConf* next;     /**< Next CRule in cruleConfList. */
113   char*             hostmask; /**< Mask of affected server names. */
114   char*             rule;     /**< Text version of the rule. */
115   int               type;     /**< One of CRULE_AUTO or CRULE_ALL. */
116   struct CRuleNode* node;     /**< Parsed form of the rule. */
117 };
118
119 /** Authorization check result. */
120 enum AuthorizationCheckResult {
121   ACR_OK,                 /**< User accepted. */
122   ACR_NO_AUTHORIZATION,   /**< No matching ConfItem for the user. */
123   ACR_TOO_MANY_IN_CLASS,  /**< Connection class was already full. */
124   ACR_TOO_MANY_FROM_IP,   /**< User's IP already has max connections. */
125   ACR_ALREADY_AUTHORIZED, /**< User already had an attached ConfItem. */
126   ACR_BAD_SOCKET          /**< Client has bad file descriptor. */
127 };
128
129 /** Target description for service commands. */
130 struct nick_host {
131   struct nick_host *next; /**< Next nick_host struct in struct s_map. */
132   int nicklen;            /**< offset of @ part of server string */
133   char nick[1];           /**< start of nick\@server string */
134 };
135
136 #define SMAP_FAST 1           /**< Command does not have MFLG_SLOW. */
137
138 /** Target set for a service pseudo-command. */
139 struct s_map {
140   struct s_map *next;         /**< Next element in #GlobalServiceMapList. */
141   struct Message *msg;        /**< Message element formed for this mapping. */
142   char *name;                 /**< Text name of the mapping. */
143   char *command;              /**< Command name to use. */
144   char *prepend;              /**< Extra text to prepend to user's text. */
145   unsigned int flags;         /**< Bitwise map of SMAP_* flags. */
146   struct nick_host *services; /**< Linked list of possible targets. */
147 };
148
149
150 /*
151  * GLOBALS
152  */
153 extern struct ConfItem* GlobalConfList;
154 extern int              GlobalConfCount;
155 extern struct s_map*    GlobalServiceMapList;
156 extern struct qline*    GlobalQuarantineList;
157
158 /*
159  * Proto types
160  */
161
162 extern int init_conf(void);
163
164 extern const struct LocalConf* conf_get_local(void);
165 extern const struct CRuleConf* conf_get_crule_list(void);
166 extern const struct DenyConf*  conf_get_deny_list(void);
167
168 extern const char* conf_eval_crule(const char* name, int mask);
169
170 extern struct ConfItem* attach_confs_byhost(struct Client* cptr, const char* host, int statmask);
171 extern struct ConfItem* find_conf_byhost(struct SLink* lp, const char* host, int statmask);
172 extern struct ConfItem* find_conf_byname(struct SLink* lp, const char *name, int statmask);
173 extern struct ConfItem* conf_find_server(const char* name);
174
175 extern void det_confs_butmask(struct Client *cptr, int mask);
176 extern enum AuthorizationCheckResult attach_conf(struct Client *cptr, struct ConfItem *aconf);
177 extern struct ConfItem* find_conf_exact(const char* name, struct Client *cptr, int statmask);
178 extern enum AuthorizationCheckResult conf_check_client(struct Client *cptr);
179 extern int  conf_check_server(struct Client *cptr);
180 extern int rehash(struct Client *cptr, int sig);
181 extern int find_kill(struct Client *cptr);
182 extern const char *find_quarantine(const char* chname);
183 extern void lookup_confhost(struct ConfItem *aconf);
184 extern void conf_parse_userhost(struct ConfItem *aconf, char *host);
185 extern struct ConfItem *conf_debug_iline(const char *client);
186
187 extern void yyerror(const char *msg);
188
189 #endif /* INCLUDED_s_conf_h */