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