[IRC-Dev CVS] [CVS] Module ircd-ircdev: Change committed
Brought to you by:
zolty
From: Toni G. <zo...@us...> - 2007-04-26 19:17:44
|
Committer : zolty CVSROOT : /cvsroot/irc-dev Module : ircd-ircdev Commit time: 2007-04-26 19:17:41 UTC Modified files: ChangeLog ChangeLog.es configure include/client.h include/ircd_features.h include/ircd_reslib.h include/patchlevel.h include/res.h include/s_auth.h include/s_user.h ircd/ircd_parser.y ircd/ircd_res.c ircd/ircd_reslib.c ircd/list.c ircd/m_cap.c ircd/m_pong.c ircd/m_user.c ircd/os_generic.c ircd/s_auth.c ircd/s_bsd.c ircd/s_conf.c ircd/s_misc.c ircd/s_user.c Removed files: include/ircd_auth.h ircd/ircd_auth.c Log message: Author: zo...@ir... Log message: 2007-04-26 Toni Garcïa <zo...@ir...> 1.0.beta5 * Nuevo AUTH * Fix soporte IPv6 para SunOS y FreeBSD ---------------------- diff included ---------------------- Index: ircd-ircdev/ChangeLog diff -u ircd-ircdev/ChangeLog:1.53 ircd-ircdev/ChangeLog:1.54 --- ircd-ircdev/ChangeLog:1.53 Sun Apr 22 06:56:17 2007 +++ ircd-ircdev/ChangeLog Thu Apr 26 12:17:30 2007 @@ -1,10 +1,14 @@ # # ChangeLog for ircd-ircdev # -# $Id: ChangeLog,v 1.53 2007/04/22 13:56:17 zolty Exp $ +# $Id: ChangeLog,v 1.54 2007/04/26 19:17:30 zolty Exp $ # # Insert new changes at beginning of the change list. # +2007-04-26 Toni Garcïa <zo...@ir...> 1.0.beta5 + * New AUTH + * Fix IPv6 support for SunOS and FreeBSD + 2007-04-22 Toni Garcïa <zo...@ir...> 1.0.beta4 * New Configure and Makefiles * New Yacc y Lex parser Index: ircd-ircdev/ChangeLog.es diff -u ircd-ircdev/ChangeLog.es:1.53 ircd-ircdev/ChangeLog.es:1.54 --- ircd-ircdev/ChangeLog.es:1.53 Sun Apr 22 06:56:17 2007 +++ ircd-ircdev/ChangeLog.es Thu Apr 26 12:17:30 2007 @@ -1,10 +1,14 @@ # # Log de Cambios para ircd-ircdev # -# $Id: ChangeLog.es,v 1.53 2007/04/22 13:56:17 zolty Exp $ +# $Id: ChangeLog.es,v 1.54 2007/04/26 19:17:30 zolty Exp $ # # Insertar los nuevos cambios al principio de esta lista de cambios. # +2007-04-26 Toni Garc�a <zo...@ir...> 1.0.beta5 + * Nuevo AUTH + * Fix soporte IPv6 para SunOS y FreeBSD + 2007-04-22 Toni Garc�a <zo...@ir...> 1.0.beta4 * Nuevo Configure y Makefiles * Nuevo Yacc y Lex parser Index: ircd-ircdev/configure diff -u ircd-ircdev/configure:1.21 ircd-ircdev/configure:1.22 --- ircd-ircdev/configure:1.21 Sun Apr 22 06:56:17 2007 +++ ircd-ircdev/configure Thu Apr 26 12:17:30 2007 @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.ac Revision: 1.3 . +# From configure.ac Revision: 1.1 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.61 for IRC-Dev IRC Daemon 1.0.beta. # Index: ircd-ircdev/include/client.h diff -u ircd-ircdev/include/client.h:1.19 ircd-ircdev/include/client.h:1.20 --- ircd-ircdev/include/client.h:1.19 Sun Apr 22 06:56:19 2007 +++ ircd-ircdev/include/client.h Thu Apr 26 12:17:31 2007 @@ -21,7 +21,7 @@ */ /** @file * @brief Structures and functions for handling local clients. - * @version $Id: client.h,v 1.19 2007/04/22 13:56:19 zolty Exp $ + * @version $Id: client.h,v 1.20 2007/04/26 19:17:31 zolty Exp $ */ #ifndef INCLUDED_client_h #define INCLUDED_client_h @@ -143,7 +143,6 @@ FLAG_BURST, /**< Server is receiving a net.burst */ FLAG_BURST_ACK, /**< Server is waiting for eob ack */ FLAG_IPCHECK, /**< Added or updated IPregistry data */ - FLAG_IAUTHED, /**< Got IAUTH response for user */ FLAG_LOCOP, /**< Local operator -- SRB */ FLAG_SERVNOTICE, /**< server notices such as kill */ FLAG_OPER, /**< Operator */ @@ -191,7 +190,6 @@ time_t con_nexttarget;/**< Next time a target change is allowed */ time_t con_lasttime; /**< Last time data read from socket */ time_t con_since; /**< Last time we accepted a command */ - unsigned int con_cookie; /**< Random number the user must PONG */ struct MsgQ con_sendQ; /**< Outgoing message queue */ struct DBuf con_recvQ; /**< Incoming data yet to be parsed */ unsigned int con_sendM; /**< Stats: protocol messages sent */ @@ -204,7 +202,6 @@ HandlerType con_handler; /**< Message index into command table for parsing. */ struct ListingArgs* con_listing; /**< Current LIST status. */ - unsigned long con_unreg; /**< Indicate what still needs to be done */ unsigned int con_max_sendq; /**< cached max send queue for client */ unsigned int con_ping_freq; /**< cached ping freq */ unsigned short con_lastsq; /**< # 2k blocks when sendqueued @@ -226,8 +223,7 @@ struct Privs con_privs; /**< Oper privileges */ struct CapSet con_capab; /**< Client capabilities (from us) */ struct CapSet con_active; /**< Active capabilities (to us) */ - struct AuthRequest* con_auth; /**< auth request for client */ - struct IAuthRequest* con_iauth; /**< iauth request for client */ + struct AuthRequest* con_auth; /**< Auth request for client */ }; /** Magic constant to identify valid Connection structures. */ @@ -257,13 +253,6 @@ char cli_info[REALLEN + 1]; /**< Free form additional client information */ }; -#define CLIREG_NICK 0x0001 /**< Client must set nickname */ -#define CLIREG_USER 0x0002 /**< Client must set username */ -#define CLIREG_COOKIE 0x0004 /**< Client must return cookie */ -#define CLIREG_CAP 0x0008 /**< Client in capability negotiation */ - -#define CLIREG_INIT (CLIREG_NICK | CLIREG_USER | CLIREG_COOKIE) - /** Magic constant to identify valid Client structures. */ #define CLIENT_MAGIC 0x4ca08286 @@ -317,8 +306,6 @@ #define cli_capab(cli) con_capab(cli_connect(cli)) /** Get active client capabilities for client */ #define cli_active(cli) con_active(cli_connect(cli)) -/** Get flags for remaining registration tasks */ -#define cli_unreg(cli) con_unreg(cli_connect(cli)) /** Get client name. */ #define cli_name(cli) ((cli)->cli_name) /** Get client username (ident). */ @@ -340,8 +327,6 @@ #define cli_nextnick(cli) con_nextnick(cli_connect(cli)) /** Get next time a target change is allowed for the client. */ #define cli_nexttarget(cli) con_nexttarget(cli_connect(cli)) -/** Get required PING/PONG cookie for client. */ -#define cli_cookie(cli) con_cookie(cli_connect(cli)) /** Get SendQ for client. */ #define cli_sendQ(cli) con_sendQ(cli_connect(cli)) /** Get RecvQ for client. */ @@ -384,8 +369,6 @@ #define cli_proc(cli) con_proc(cli_connect(cli)) /** Get auth request for client. */ #define cli_auth(cli) con_auth(cli_connect(cli)) -/** Get iauth request for client. */ -#define cli_iauth(cli) con_iauth(cli_connect(cli)) /** Get sentalong marker for client. */ #define cli_sentalong(cli) con_sentalong(cli_connect(cli)) @@ -419,8 +402,6 @@ #define con_lasttime(con) ((con)->con_lasttime) /** Get last time we accepted a command from the connection. */ #define con_since(con) ((con)->con_since) -/** Get PING/PONG confirmation cookie for connection. */ -#define con_cookie(con) ((con)->con_cookie) /** Get SendQ for connection. */ #define con_sendQ(con) ((con)->con_sendQ) /** Get RecvQ for connection. */ @@ -441,8 +422,6 @@ #define con_handler(con) ((con)->con_handler) /** Get the LIST status for the connection. */ #define con_listing(con) ((con)->con_listing) -/** Get remining steps before registration completes. */ -#define con_unreg(con) ((con)->con_unreg) /** Get the maximum permitted SendQ size for the connection. */ #define con_max_sendq(con) ((con)->con_max_sendq) /** Get the ping frequency for the connection. */ @@ -471,8 +450,6 @@ #define con_active(con) (&(con)->con_active) /** Get the auth request for the connection. */ #define con_auth(con) ((con)->con_auth) -/** Get the iauth request for the connection. */ -#define con_iauth(con) ((con)->con_iauth) #define STAT_CONNECTING 0x001 /**< connecting to another server */ #define STAT_HANDSHAKE 0x002 /**< pass - server sent */ @@ -567,8 +544,6 @@ #define IsDeaf(x) HasFlag(x, FLAG_DEAF) /** Return non-zero if the client has been IP-checked for clones. */ #define IsIPChecked(x) HasFlag(x, FLAG_IPCHECK) -/** Return non-zero if the client has been okayed by iauth. */ -#define IsIAuthed(x) HasFlag(x, FLAG_IAUTHED) /** Return non-zero if we have received an ident response for the client. */ #define IsIdented(x) HasFlag(x, FLAG_GOTID) /** Return non-zero if the client has set mode +i (invisible). */ @@ -633,8 +608,6 @@ #define SetGotId(x) SetFlag(x, FLAG_GOTID) /** Mark a client as being IP-checked. */ #define SetIPChecked(x) SetFlag(x, FLAG_IPCHECK) -/** Mark a client as being iauth-checked. */ -#define SetIAuthed(x) SetFlag(x, FLAG_IAUTHED) /** Mark a client as having mode +i (invisible). */ #define SetInvisible(x) SetFlag(x, FLAG_INVISIBLE) /** Mark a client as causing a net.join. */ @@ -737,12 +710,13 @@ #define SNO_CONNEXIT 0x4000 /**< client connect/exit (ugh) */ #define SNO_AUTO 0x8000 /**< AUTO G-Lines */ #define SNO_DEBUG 0x10000 /**< debugging messages (DEBUGMODE only) */ +#define SNO_AUTH 0x20000 /**< IAuth notices */ +/** Bitmask of all valid server notice bits. */ #ifdef DEBUGMODE -# define SNO_ALL 0x1ffff /**< Bitmask of all valid server - * notice bits. */ +# define SNO_ALL 0x3ffff #else -# define SNO_ALL 0xffff +# define SNO_ALL 0x2ffff #endif /** Server notice bits allowed to normal users. */ @@ -753,7 +727,7 @@ /** Server notice bits enabled by default for IRC operators. */ #define SNO_OPERDEFAULT (SNO_DEFAULT|SNO_HACK2|SNO_HACK4|SNO_THROTTLE|SNO_OLDSNO) /** Server notice bits reserved to IRC operators. */ -#define SNO_OPER (SNO_CONNEXIT|SNO_OLDREALOP) +#define SNO_OPER (SNO_CONNEXIT|SNO_OLDREALOP|SNO_AUTH) /** Noisy server notice bits that cause other bits to be cleared during connect. */ #define SNO_NOISY (SNO_SERVKILL|SNO_UNAUTH) Index: ircd-ircdev/include/ircd_auth.h diff -u ircd-ircdev/include/ircd_auth.h:1.3 ircd-ircdev/include/ircd_auth.h:removed --- ircd-ircdev/include/ircd_auth.h:1.3 Thu Apr 19 15:53:46 2007 +++ ircd-ircdev/include/ircd_auth.h Thu Apr 26 12:17:42 2007 @@ -1,44 +0,0 @@ -/* - * IRC-Dev IRCD - An advanced and innovative IRC Daemon, include/ircd_auth.h - * - * Copyright (C) 2002-2007 IRC-Dev Development Team <de...@ir...> - * Copyright (C) 2004 Michael Poole <md...@tr...> - * Copyright (C) 2001 Perry Lorier <is...@co...> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -/** @file - * @brief Interface to IAuth client implementation. - * @version $Id: ircd_auth.h,v 1.3 2007/04/19 22:53:46 zolty Exp $ - */ -#ifndef INCLUDED_ircd_auth_h -#define INCLUDED_ircd_auth_h - -#ifndef INCLUDED_config_h -#include "config.h" -#endif - -struct IAuth; -extern struct IAuth *iauth_active; - -struct IAuth *iauth_connect(char *host, unsigned short port, char *passwd, time_t reconnect, time_t timeout); -int iauth_start_client(struct IAuth *iauth, struct Client *cptr); -void iauth_exit_client(struct Client *cptr); - -void iauth_mark_closing(void); -void iauth_close_unused(void); - -#endif /* INCLUDED_ircd_auth_h */ Index: ircd-ircdev/include/ircd_features.h diff -u ircd-ircdev/include/ircd_features.h:1.17 ircd-ircdev/include/ircd_features.h:1.18 --- ircd-ircdev/include/ircd_features.h:1.17 Sat Apr 21 09:20:18 2007 +++ ircd-ircdev/include/ircd_features.h Thu Apr 26 12:17:31 2007 @@ -21,7 +21,7 @@ */ /** @file * @brief Public interfaces and declarations for dealing with configurable features. - * @version $Id: ircd_features.h,v 1.17 2007/04/21 16:20:18 zolty Exp $ + * @version $Id: ircd_features.h,v 1.18 2007/04/26 19:17:31 zolty Exp $ */ #ifndef INCLUDED_features_h #define INCLUDED_features_h @@ -51,6 +51,7 @@ FEAT_HUB, FEAT_WALLOPS_OPER_ONLY, FEAT_NODNS, + FEAT_NOIDENT, FEAT_RANDOM_SEED, FEAT_DEFAULT_LIST_PARAM, FEAT_NICKNAMEHISTORYLENGTH, Index: ircd-ircdev/include/ircd_reslib.h diff -u ircd-ircdev/include/ircd_reslib.h:1.3 ircd-ircdev/include/ircd_reslib.h:1.4 --- ircd-ircdev/include/ircd_reslib.h:1.3 Thu Apr 19 15:53:46 2007 +++ ircd-ircdev/include/ircd_reslib.h Thu Apr 26 12:17:31 2007 @@ -21,7 +21,7 @@ */ /** @file * @brief Interface from ircd resolver to its support functions. - * @version $Id: ircd_reslib.h,v 1.3 2007/04/19 22:53:46 zolty Exp $ + * @version $Id: ircd_reslib.h,v 1.4 2007/04/26 19:17:31 zolty Exp $ */ #ifndef INCLUDED_ircdreslib_h #define INCLUDED_ircdreslib_h @@ -76,17 +76,7 @@ int irc_res_init(void); int irc_dn_expand(const unsigned char *msg, const unsigned char *eom, const unsigned char *src, char *dst, int dstsiz); -int irc_ns_name_uncompress(const unsigned char *msg, const unsigned char *eom, const unsigned char *src, char *dst, size_t dstsiz); -int irc_ns_name_unpack(const unsigned char *msg, const unsigned char *eom, const unsigned char *src, unsigned char *dst, size_t dstsiz); -int irc_ns_name_ntop(const char *src, char *dst, size_t dstsiz); -int irc_dn_comp(const char *src, unsigned char *dst, int dstsiz, unsigned char **dnptrs, unsigned char **lastdnptr); int irc_dn_skipname(const unsigned char *ptr, const unsigned char *eom); -int irc_ns_name_skip(const unsigned char **ptrptr, const unsigned char *eom); -unsigned int irc_ns_get16(const unsigned char *src); -unsigned long irc_ns_get32(const unsigned char *src); -void irc_ns_put16(unsigned int src, unsigned char *dst); -void irc_ns_put32(unsigned long src, unsigned char *dst); -int irc_ns_name_pton(const char *src, unsigned char *dst, size_t dstsiz); -int irc_ns_name_pack(const unsigned char *src, unsigned char *dst, int dstsiz, const unsigned char **dnptrs, const unsigned char **lastdnptr); int irc_res_mkquery(const char *dname, int class, int type, unsigned char *buf, int buflen); +unsigned int irc_ns_get16(const unsigned char *src); #endif /* INCLUDED_res_h */ Index: ircd-ircdev/include/patchlevel.h diff -u ircd-ircdev/include/patchlevel.h:1.52 ircd-ircdev/include/patchlevel.h:1.53 --- ircd-ircdev/include/patchlevel.h:1.52 Sun Apr 22 06:56:19 2007 +++ ircd-ircdev/include/patchlevel.h Thu Apr 26 12:17:31 2007 @@ -17,10 +17,10 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: patchlevel.h,v 1.52 2007/04/22 13:56:19 zolty Exp $ + * $Id: patchlevel.h,v 1.53 2007/04/26 19:17:31 zolty Exp $ * */ -#define PATCHLEVEL "4" +#define PATCHLEVEL "5" #define RELEASE "1.0.beta" Index: ircd-ircdev/include/res.h diff -u ircd-ircdev/include/res.h:1.9 ircd-ircdev/include/res.h:1.10 --- ircd-ircdev/include/res.h:1.9 Thu Apr 19 15:53:47 2007 +++ ircd-ircdev/include/res.h Thu Apr 26 12:17:31 2007 @@ -22,7 +22,7 @@ */ /** @file * @brief IRC resolver API. - * @version $Id: res.h,v 1.9 2007/04/19 22:53:47 zolty Exp $ + * @version $Id: res.h,v 1.10 2007/04/26 19:17:31 zolty Exp $ */ #ifndef INCLUDED_res_h @@ -67,6 +67,7 @@ #define QUERY 0 /**< Forward (normal) DNS query operation. */ #define NO_ERRORS 0 /**< No errors processing a query. */ #define SERVFAIL 2 /**< Server error while processing a query. */ +#define NXDOMAIN 3 /**< Domain name in query does not exist. */ #define T_A 1 /**< Hostname -> IPv4 query type. */ #define T_AAAA 28 /**< Hostname -> IPv6 query type. */ #define T_PTR 12 /**< IP(v4 or v6) -> hostname query type. */ @@ -130,13 +131,24 @@ } HEADER; extern void restart_resolver(void); -extern void add_local_domain(char *hname, size_t size); +extern void clear_nameservers(void); +extern void add_nameserver(const char *ipaddr); extern size_t cres_mem(struct Client* cptr); extern void delete_resolver_queries(const void *vptr); extern void report_dns_servers(struct Client *source_p, const struct StatDesc *sd, char *param); extern void gethost_byname(const char *name, dns_callback_f callback, void *ctx); extern void gethost_byaddr(const struct irc_in_addr *addr, dns_callback_f callback, void *ctx); +/** Evaluate to non-zero if \a ADDR is an unspecified (all zeros) address. */ +#define irc_in_addr_unspec(ADDR) (((ADDR)->in6_16[0] == 0) \ + && ((ADDR)->in6_16[1] == 0) \ + && ((ADDR)->in6_16[2] == 0) \ + && ((ADDR)->in6_16[3] == 0) \ + && ((ADDR)->in6_16[4] == 0) \ + && ((ADDR)->in6_16[6] == 0) \ + && ((ADDR)->in6_16[7] == 0) \ + && ((ADDR)->in6_16[5] == 0 \ + || (ADDR)->in6_16[5] == 65535)) /** Evaluate to non-zero if \a ADDR is a valid address (not all 0s and not all 1s). */ #define irc_in_addr_valid(ADDR) (((ADDR)->in6_16[0] && ~(ADDR)->in6_16[0]) \ || (ADDR)->in6_16[1] != (ADDR)->in6_16[0] \ Index: ircd-ircdev/include/s_auth.h diff -u ircd-ircdev/include/s_auth.h:1.5 ircd-ircdev/include/s_auth.h:1.6 --- ircd-ircdev/include/s_auth.h:1.5 Thu Apr 19 15:53:47 2007 +++ ircd-ircdev/include/s_auth.h Thu Apr 26 12:17:31 2007 @@ -2,6 +2,8 @@ * IRC-Dev IRCD - An advanced and innovative IRC Daemon, include/s_auth.h * * Copyright (C) 2002-2007 IRC-Dev Development Team <de...@ir...> + * Copyright (C) 2004 Michael Poole <md...@tr...> + * Copyright (C) 2001 Perry Lorier <is...@co...> * Copyright (C) 1992 Darren Reed * * This program is free software; you can redistribute it and/or modify @@ -21,7 +23,7 @@ */ /** @file * @brief Interface for DNS and ident lookups. - * @version $Id: s_auth.h,v 1.5 2007/04/19 22:53:47 zolty Exp $ + * @version $Id: s_auth.h,v 1.6 2007/04/26 19:17:31 zolty Exp $ */ #ifndef INCLUDED_s_auth_h #define INCLUDED_s_auth_h @@ -35,50 +37,24 @@ #endif struct Client; - -/** Stores state of the DNS and RFC 1413 ident lookups for a client. */ -struct AuthRequest { - struct AuthRequest* next; /**< linked list node ptr */ - struct AuthRequest* prev; /**< linked list node ptr */ - struct Client* client; /**< pointer to client struct for request */ - unsigned int flags; /**< current state of request */ - int fd; /**< file descriptor for auth queries */ - struct Socket socket; /**< socket descriptor for auth queries */ - struct Timer timeout; /**< timeout timer for auth queries */ -}; - -/* - * flag values for AuthRequest - * NAMESPACE: AM_xxx - Authentication Module - */ -#define AM_AUTH_CONNECTING 0x01 /**< waiting for ident connect to complete */ -#define AM_AUTH_PENDING 0x02 /**< ident connected, waiting for response */ -#define AM_DNS_PENDING 0x04 /**< dns request sent, waiting for response */ - -#define AM_SOCKET 0x40 /**< socket structure not destroyed */ -#define AM_TIMEOUT 0x80 /**< timer structure not destroyed */ - -/** If any of AM_FREE_MASK bits are set, operations are still in progress. */ -#define AM_FREE_MASK (AM_SOCKET | AM_TIMEOUT) - -#define SetDNSPending(x) ((x)->flags |= AM_DNS_PENDING) -#define ClearDNSPending(x) ((x)->flags &= ~AM_DNS_PENDING) -#define IsDNSPending(x) ((x)->flags & AM_DNS_PENDING) - -#define SetAuthConnect(x) ((x)->flags |= AM_AUTH_CONNECTING) -#define ClearAuthConnect(x) ((x)->flags &= ~AM_AUTH_CONNECTING) -#define IsAuthConnect(x) ((x)->flags & AM_AUTH_CONNECTING) - -#define SetAuthPending(x) ((x)->flags |= AM_AUTH_PENDING) -#define ClearAuthPending(x) ((x)->flags &= AM_AUTH_PENDING) -#define IsAuthPending(x) ((x)->flags & AM_AUTH_PENDING) - -#define ClearAuth(x) ((x)->flags &= ~(AM_AUTH_PENDING | AM_AUTH_CONNECTING)) -#define IsDoingAuth(x) ((x)->flags & (AM_AUTH_PENDING | AM_AUTH_CONNECTING)) +struct AuthRequest; +struct StatDesc; extern void start_auth(struct Client *); -extern void read_auth_reply(struct AuthRequest* req); -extern void send_auth_query(struct AuthRequest* req); -extern void destroy_auth_request(struct AuthRequest *req, int send_reports); +extern int auth_ping_timeout(struct Client *); +extern int auth_set_pong(struct AuthRequest *auth, unsigned int cookie); +extern int auth_set_user(struct AuthRequest *auth, const char *username, const char *hostname, const char *servername, const char *userinfo); +extern int auth_set_nick(struct AuthRequest *auth, const char *nickname); +extern int auth_set_password(struct AuthRequest *auth, const char *password); +extern int auth_cap_start(struct AuthRequest *auth); +extern int auth_cap_done(struct AuthRequest *auth); +extern void destroy_auth_request(struct AuthRequest *req); + +extern int auth_spawn(int argc, char *argv[]); +extern void auth_send_exit(struct Client *cptr); +extern void auth_mark_closing(void); +extern void auth_close_unused(void); +extern void report_iauth_conf(struct Client *cptr, const struct StatDesc *sd, char *param); +extern void report_iauth_stats(struct Client *cptr, const struct StatDesc *sd, char *param); #endif /* INCLUDED_s_auth_h */ Index: ircd-ircdev/include/s_user.h diff -u ircd-ircdev/include/s_user.h:1.11 ircd-ircdev/include/s_user.h:1.12 --- ircd-ircdev/include/s_user.h:1.11 Thu Apr 19 15:53:47 2007 +++ ircd-ircdev/include/s_user.h Thu Apr 26 12:17:31 2007 @@ -21,7 +21,7 @@ */ /** @file s_user.h * @brief Miscellaneous user-related helper functions. - * @version $Id: s_user.h,v 1.11 2007/04/19 22:53:47 zolty Exp $ + * @version $Id: s_user.h,v 1.12 2007/04/26 19:17:31 zolty Exp $ */ #ifndef INCLUDED_s_user_h #define INCLUDED_s_user_h @@ -72,8 +72,6 @@ #define MATCH_SERVER 1 /**< flag for relay_masked_message (etc) to indicate the mask matches a server name */ #define MATCH_HOST 2 /**< flag for relay_masked_message (etc) to indicate the mask matches host name */ -#define COOKIE_VERIFIED 0xffffffff /**< value for cli_cookie() to show completion */ - /* used in set_nick_name */ #define NICK_EQUIVALENT 0x01 /** < Equivalent */ #define NICK_RENAMED 0x02 /** < Rename */ @@ -105,8 +103,7 @@ */ extern struct User* make_user(struct Client *cptr); extern void free_user(struct User *user); -extern int register_user(struct Client* cptr, struct Client* sptr, - const char* nick, char* username); +extern int register_user(struct Client* cptr, struct Client *sptr); extern void user_count_memory(size_t* count_out, size_t* bytes_out); Index: ircd-ircdev/ircd/ircd_auth.c diff -u ircd-ircdev/ircd/ircd_auth.c:1.11 ircd-ircdev/ircd/ircd_auth.c:removed --- ircd-ircdev/ircd/ircd_auth.c:1.11 Sat Apr 21 14:17:22 2007 +++ ircd-ircdev/ircd/ircd_auth.c Thu Apr 26 12:17:42 2007 @@ -1,843 +0,0 @@ -/* - * IRC-Dev IRCD - An advanced and innovative IRC Daemon, ircd/ircd_iauth.c - * - * Copyright (C) 2002-2007 IRC-Dev Development Team <de...@ir...> - * Copyright (C) 2004 Michael Poole <md...@tr...> - * Copyright (C) 2001 Perry Lorier <is...@co...> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -/** @file - * @brief IAuth client implementation for an IRC server. - * @version $Id: ircd_auth.c,v 1.11 2007/04/21 21:17:22 zolty Exp $ - */ -#include "config.h" -#include "client.h" -#include "ircd_alloc.h" -#include "ircd_auth.h" -#include "ircd_events.h" -#include "ircd_features.h" -#include "ircd_log.h" -#include "ircd_osdep.h" -#include "ircd_snprintf.h" -#include "ircd_string.h" -#include "ircd.h" -#include "msg.h" -#include "msgq.h" -#include "res.h" -#include "s_bsd.h" -#include "s_debug.h" -#include "s_misc.h" -#include "s_user.h" -#include "send.h" - -/* #include <assert.h> -- Now using assert in ircd_log.h */ -#include <errno.h> -#include <netdb.h> -#include <string.h> -#include <unistd.h> -#include <sys/socket.h> -#include <netinet/in.h> -#ifdef HAVE_STDINT_H -#include <stdint.h> -#endif - -/** Describes state of a single pending IAuth request. */ -struct IAuthRequest { - struct IAuthRequest *iar_prev; /**< previous request struct */ - struct IAuthRequest *iar_next; /**< next request struct */ - struct Client *iar_client; /**< client being authenticated */ - char iar_timed; /**< if non-zero, using parent i_request_timer */ -}; - -/** Enumeration of IAuth connection flags. */ -enum IAuthFlag -{ - IAUTH_BLOCKED, /**< socket buffer full */ - IAUTH_CONNECTED, /**< server greeting/handshake done */ - IAUTH_ABORT, /**< abort connection asap */ - IAUTH_ICLASS, /**< tell iauth about all local users */ - IAUTH_CLOSING, /**< candidate to be disposed */ - IAUTH_LAST_FLAG /**< total number of flags */ -}; -/** Declare a bitset structure indexed by IAuthFlag. */ -DECLARE_FLAGSET(IAuthFlags, IAUTH_LAST_FLAG); - -/** Describes state of an IAuth connection. */ -struct IAuth { - struct IAuthRequest i_list_head; /**< doubly linked list of requests */ - struct MsgQ i_sendQ; /**< messages queued to send */ - struct Socket i_socket; /**< connection to server */ - struct Timer i_reconn_timer; /**< when to reconnect the connection */ - struct Timer i_request_timer; /**< when the current request times out */ - struct IAuthFlags i_flags; /**< connection state/status/flags */ - unsigned int i_recvM; /**< messages received */ - unsigned int i_sendM; /**< messages sent */ - unsigned int i_recvK; /**< kilobytes received */ - unsigned int i_sendK; /**< kilobytes sent */ - unsigned short i_recvB; /**< bytes received modulo 1024 */ - unsigned short i_sendB; /**< bytes sent modulo 1024 */ - time_t i_reconnect; /**< seconds to wait before reconnecting */ - time_t i_timeout; /**< seconds to wait for a request */ - unsigned int i_count; /**< characters used in i_buffer */ - char i_buffer[BUFSIZE+1]; /**< partial unprocessed line from server */ - char i_passwd[PASSWDLEN+1]; /**< password for connection */ - char i_host[HOSTLEN+1]; /**< iauth server hostname */ - struct irc_sockaddr i_addr; /**< iauth server ip address and port */ - struct IAuth *i_next; /**< next connection in list */ -}; - -/** Return flags element of \a iauth. */ -#define i_flags(iauth) ((iauth)->i_flags) -/** Return whether flag \a flag is set on \a iauth. */ -#define IAuthGet(iauth, flag) FlagHas(&i_flags(iauth), flag) -/** Set flag \a flag on \a iauth. */ -#define IAuthSet(iauth, flag) FlagSet(&i_flags(iauth), flag) -/** Clear flag \a flag from \a iauth. */ -#define IAuthClr(iauth, flag) FlagClr(&i_flags(iauth), flag) -/** Get blocked state for \a iauth. */ -#define i_GetBlocked(iauth) IAuthGet(iauth, IAUTH_BLOCKED) -/** Set blocked state for \a iauth. */ -#define i_SetBlocked(iauth) IAuthSet(iauth, IAUTH_BLOCKED) -/** Clear blocked state for \a iauth. */ -#define i_ClrBlocked(iauth) IAuthClr(iauth, IAUTH_BLOCKED) -/** Get connected flag for \a iauth. */ -#define i_GetConnected(iauth) IAuthGet(iauth, IAUTH_CONNECTED) -/** Set connected flag for \a iauth. */ -#define i_SetConnected(iauth) IAuthSet(iauth, IAUTH_CONNECTED) -/** Clear connected flag for \a iauth. */ -#define i_ClrConnected(iauth) IAuthClr(iauth, IAUTH_CONNECTED) -/** Get abort flag for \a iauth. */ -#define i_GetAbort(iauth) IAuthGet(iauth, IAUTH_ABORT) -/** Set abort flag for \a iauth. */ -#define i_SetAbort(iauth) IAuthSet(iauth, IAUTH_ABORT) -/** Clear abort flag for \a iauth. */ -#define i_ClrAbort(iauth) IAuthClr(iauth, IAUTH_ABORT) -/** Get IClass flag for \a iauth. */ -#define i_GetIClass(iauth) IAuthGet(iauth, IAUTH_ICLASS) -/** Set IClass flag for \a iauth. */ -#define i_SetIClass(iauth) IAuthSet(iauth, IAUTH_ICLASS) -/** Clear IClass flag for \a iauth. */ -#define i_ClrIClass(iauth) IAuthClr(iauth, IAUTH_ICLASS) -/** Get closing flag for \a iauth. */ -#define i_GetClosing(iauth) IAuthGet(iauth, IAUTH_CLOSING) -/** Set closing flag for \a iauth. */ -#define i_SetClosing(iauth) IAuthSet(iauth, IAUTH_CLOSING) -/** Clear closing flag for \a iauth. */ -#define i_ClrClosing(iauth) IAuthClr(iauth, IAUTH_CLOSING) - -/** Return head of request linked list for \a iauth. */ -#define i_list_head(iauth) ((iauth)->i_list_head) -/** Return socket event generator for \a iauth. */ -#define i_socket(iauth) ((iauth)->i_socket) -/** Return reconnect timer for \a iauth. */ -#define i_reconn_timer(iauth) ((iauth)->i_reconn_timer) -/** Return request timeout timer for \a iauth. */ -#define i_request_timer(iauth) ((iauth)->i_request_timer) -/** Return DNS query for \a iauth. */ -#define i_query(iauth) ((iauth)->i_query) -/** Return received bytes (modulo 1024) for \a iauth. */ -#define i_recvB(iauth) ((iauth)->i_recvB) -/** Return received kilobytes (modulo 1024) for \a iauth. */ -#define i_recvK(iauth) ((iauth)->i_recvK) -/** Return received megabytes for \a iauth. */ -#define i_recvM(iauth) ((iauth)->i_recvM) -/** Return sent bytes (modulo 1024) for \a iauth. */ -#define i_sendB(iauth) ((iauth)->i_sendB) -/** Return sent kilobytes (modulo 1024) for \a iauth. */ -#define i_sendK(iauth) ((iauth)->i_sendK) -/** Return sent megabytes for \a iauth. */ -#define i_sendM(iauth) ((iauth)->i_sendM) -/** Return outbound message queue for \a iauth. */ -#define i_sendQ(iauth) ((iauth)->i_sendQ) -/** Return reconnection interval for \a iauth. */ -#define i_reconnect(iauth) ((iauth)->i_reconnect) -/** Return request timeout interval for \a iauth. */ -#define i_timeout(iauth) ((iauth)->i_timeout) -/** Return length of unprocessed message data for \a iauth. */ -#define i_count(iauth) ((iauth)->i_count) -/** Return start of unprocessed message data for \a iauth. */ -#define i_buffer(iauth) ((iauth)->i_buffer) -/** Return password we send for \a iauth. */ -#define i_passwd(iauth) ((iauth)->i_passwd) -/** Return server hostname for \a iauth. */ -#define i_host(iauth) ((iauth)->i_host) -/** Return address of IAuth server for \a iauth. */ -#define i_addr(iauth) ((iauth)->i_addr) -/** Return server port for \a iauth. */ -#define i_port(iauth) ((iauth)->i_addr.port) -/** Return next IAuth connection after \a iauth. */ -#define i_next(iauth) ((iauth)->i_next) - -/** Command table entry. */ -struct IAuthCmd { - const char *iac_name; /**< Name of command. */ - void (*iac_func)(struct IAuth *iauth, int, char *[]); /**< Handler function. */ -}; - -/** Active %IAuth connection(s). */ -struct IAuth *iauth_active; - -static void iauth_write(struct IAuth *iauth); -static void iauth_reconnect(struct IAuth *iauth); -static void iauth_disconnect(struct IAuth *iauth); -static void iauth_sock_callback(struct Event *ev); -static void iauth_send_request(struct IAuth *iauth, struct IAuthRequest *iar); -static void iauth_dispose_request(struct IAuth *iauth, struct IAuthRequest *iar); -static void iauth_cmd_doneauth(struct IAuth *iauth, int argc, char *argv[]); -static void iauth_cmd_badauth(struct IAuth *iauth, int argc, char *argv[]); - -/** Table of responses we might get from the IAuth server. */ -static const struct IAuthCmd iauth_cmdtab[] = { - { "DoneAuth", iauth_cmd_doneauth }, - { "BadAuth", iauth_cmd_badauth }, - { NULL, NULL } -}; - -/** Start (or update) a connection to an %IAuth server. - * If a connection already exists for the specified server name and - * port, update it with the other parameters; otherwise allocate a new - * IAuth record. - * @param[in] host %IAuth server hostname. - * @param[in] port %IAuth server port. - * @param[in] passwd Password to send. - * @param[in] reconnect Reconnect interval. - * @param[in] timeout Request timeout interval. - * @return IAuth structure for that connection. - */ -struct IAuth *iauth_connect(char *host, unsigned short port, char *passwd, time_t reconnect, time_t timeout) -{ - struct IAuth *iauth; - - for (iauth = iauth_active; iauth; iauth = i_next(iauth)) { - if (!ircd_strncmp(i_host(iauth), host, HOSTLEN) - && (i_port(iauth) == port)) { - i_ClrClosing(iauth); - i_reconnect(iauth) = reconnect; - if (t_active(&i_reconn_timer(iauth)) && (t_expire(&i_reconn_timer(iauth)) > CurrentTime + i_reconnect(iauth))) - timer_chg(&i_reconn_timer(iauth), TT_RELATIVE, i_reconnect(iauth)); - break; - } - } - if (NULL == iauth) { - if (iauth_active && !i_GetClosing(iauth_active)) { - log_write(LS_CONFIG, L_WARNING, 0, "Creating extra active IAuth connection to %s:%d.", host, port); - } - iauth = MyCalloc(1, sizeof(*iauth)); - i_list_head(iauth).iar_prev = &i_list_head(iauth); - i_list_head(iauth).iar_next = &i_list_head(iauth); - msgq_init(&i_sendQ(iauth)); - ircd_strncpy(i_host(iauth), host, HOSTLEN); - memset(&i_addr(iauth), 0, sizeof(i_addr(iauth))); - i_port(iauth) = port; - iauth_active = iauth; - timer_init(&i_reconn_timer(iauth)); - i_reconnect(iauth) = reconnect; - iauth_reconnect(iauth); - } - if (passwd) - ircd_strncpy(i_passwd(iauth), passwd, PASSWDLEN); - else - i_passwd(iauth)[0] = '\0'; - i_timeout(iauth) = timeout; - i_SetIClass(iauth); - return iauth; -} - -/** Mark all %IAuth connections as closing. */ -void iauth_mark_closing(void) -{ - struct IAuth *iauth; - for (iauth = iauth_active; iauth; iauth = i_next(iauth)) - i_SetClosing(iauth); -} - -/** Close a particular %IAuth connection. - * @param[in] iauth %Connection to close. - */ -void iauth_close(struct IAuth *iauth) -{ - /* Figure out what to do with the closing connection's requests. */ - if (i_list_head(iauth).iar_next != &i_list_head(iauth)) { - struct IAuthRequest *iar; - if (iauth_active || i_next(iauth)) { - /* If iauth_active != NULL, send requests to it; otherwise if - * i_next(iauth) != NULL, we can hope it or some later - * connection will be active. - */ - struct IAuth *target = iauth_active ? iauth_active : i_next(iauth); - - /* Append iauth->i_list_head to end of target->i_list_head. */ - iar = i_list_head(iauth).iar_next; - iar->iar_prev = i_list_head(target).iar_prev; - i_list_head(target).iar_prev->iar_next = iar; - iar = i_list_head(iauth).iar_prev; - iar->iar_next = &i_list_head(target); - i_list_head(target).iar_prev = iar; - - /* If the target is not closing, send the requests. */ - for (iar = i_list_head(iauth).iar_next; - iar != &i_list_head(target); - iar = iar->iar_next) { - if (!i_GetClosing(target)) - iauth_send_request(target, iar); - } - } else { - /* No active connections - approve the requests and drop them. */ - while ((iar = i_list_head(iauth).iar_next) != &i_list_head(iauth)) { - struct Client *client = iar->iar_client; - iauth_dispose_request(iauth, iar); - register_user(client, client, cli_name(client), cli_username(client)); - } - } - } - /* Make sure the connection closes with an empty request list. */ - i_list_head(iauth).iar_prev = &i_list_head(iauth); - i_list_head(iauth).iar_next = &i_list_head(iauth); - /* Cancel the timer, if it is active. */ - if (t_active(&i_reconn_timer(iauth))) - timer_del(&i_reconn_timer(iauth)); - if (t_active(&i_request_timer(iauth))) - timer_del(&i_request_timer(iauth)); - /* Disconnect from the server. */ - if (i_GetConnected(iauth)) - iauth_disconnect(iauth); - /* Free memory. */ - MyFree(iauth); -} - -/** Close all %IAuth connections marked as closing. */ -void iauth_close_unused(void) -{ - struct IAuth *prev, *iauth, *next; - - for (prev = NULL, iauth = iauth_active; iauth; iauth = next) { - next = i_next(iauth); - if (i_GetClosing(iauth)) { - /* Update iauth_active linked list. */ - if (prev) - i_next(prev) = next; - else - iauth_active = next; - /* Close and destroy the connection. */ - iauth_close(iauth); - } else { - prev = iauth; - } - } -} - -/** Send a line to an %IAuth server. - * @param[in] iauth %Connection to send on. - * @param[in] format Format string for message. - */ -static void iauth_send(struct IAuth *iauth, const char *format, ...) -{ - va_list vl; - struct MsgBuf *mb; - - va_start(vl, format); - mb = msgq_vmake(0, format, vl); - va_end(vl); - msgq_add(&i_sendQ(iauth), mb, 0); - msgq_clean(mb); -} - -/** Report a protocol violation from the %IAuth server. - * @param[in] iauth %Connection that experienced the violation. - * @param[in] format Format string for message to operators. - */ -static void iauth_protocol_violation(struct IAuth *iauth, const char *format, ...) -{ - struct VarData vd; - assert(iauth != 0); - assert(format != 0); - vd.vd_format = format; - va_start(vd.vd_args, format); - sendto_opmask(NULL, SNO_CONNEXIT, "IAuth protocol violation: %v", &vd); - va_end(vd.vd_args); -} - -/** Send on-connect burst to an %IAuth server. - * @param[in] iauth %Connection that has completed. - */ -static void iauth_on_connect(struct IAuth *iauth) -{ - struct IAuthRequest *iar; - if (EmptyString(i_passwd(iauth))) - iauth_send(iauth, "Server %s", cli_name(&me)); - else - iauth_send(iauth, "Server %s %s", cli_name(&me), i_passwd(iauth)); - if (i_GetIClass(iauth)) { - /* TODO: report local users to iauth */ - iauth_send(iauth, "EndUsers"); - } - i_SetConnected(iauth); - for (iar = i_list_head(iauth).iar_next; - iar != &i_list_head(iauth); - iar = iar->iar_next) - iauth_send_request(iauth, iar); - iauth_write(iauth); -} - -/** Complete disconnection of an %IAuth connection. - * @param[in] iauth %Connection to fully close. - */ -static void iauth_disconnect(struct IAuth *iauth) -{ - close(s_fd(&i_socket(iauth))); - socket_del(&i_socket(iauth)); - i_ClrConnected(iauth); -} - -/** DNS completion callback for an %IAuth connection. - * @param[in] vptr Pointer to the IAuth struct. - * @param[in] he DNS reply parameters. - */ -static void iauth_dns_callback(void *vptr, const struct irc_in_addr *addr, const char *h_name) -{ - struct IAuth *iauth = vptr; - if (!addr) { - log_write(LS_IAUTH, L_NOTICE, 0, "IAuth connection to %s failed: host lookup failed", i_host(iauth)); - } else { - memcpy(&i_addr(iauth).addr, addr, sizeof(i_addr(iauth).addr)); - if (!irc_in_addr_valid(&i_addr(iauth).addr)) { - log_write(LS_IAUTH, L_NOTICE, 0, "IAuth connection to %s failed: host came back as unresolved", i_host(iauth)); - return; - } - iauth_reconnect(iauth); - } -} - -/** Timer callback for reconnecting to %IAuth. - * @param[in] ev Timer event for reconnect. - */ -static void iauth_reconnect_ev(struct Event *ev) -{ - if (ev_type(ev) == ET_EXPIRE) - iauth_reconnect(t_data(ev_timer(ev))); -} - -/** Schedule a reconnection for \a iauth. - * @param[in] iauth %Connection that needs to be reconnected. - */ -static void iauth_schedule_reconnect(struct IAuth *iauth) -{ - struct Timer *timer; - timer = &i_reconn_timer(iauth); - if (t_onqueue(timer)) - timer_chg(timer, TT_RELATIVE, i_reconnect(iauth)); - else - timer_add(&i_reconn_timer(iauth), iauth_reconnect_ev, - iauth, TT_RELATIVE, i_reconnect(iauth)); -} - -/** Initiate a (re-)connection to \a iauth. - * @param[in] iauth %Connection that should be initiated. - */ -static void iauth_reconnect(struct IAuth *iauth) -{ - struct irc_sockaddr *local; - IOResult result; - int fd; - - if (i_GetConnected(iauth)) { - iauth_disconnect(iauth); - iauth_schedule_reconnect(iauth); - return; - } - log_write(LS_IAUTH, L_DEBUG, 0, "IAuth attempt connection to %s port %p.", i_host(iauth), i_port(iauth)); - if (!irc_in_addr_valid(&i_addr(iauth).addr) - && !ircd_aton(&i_addr(iauth).addr, i_host(iauth))) { - gethost_byname(i_host(iauth), iauth_dns_callback, iauth); - return; - } - local = irc_in_addr_is_ipv4(&i_addr(iauth).addr) ? &VirtualHost_v4 : &VirtualHost_v6; - fd = os_socket(local, SOCK_STREAM, "IAuth"); - if (fd < 0) { - iauth_schedule_reconnect(iauth); - return; - } - if (!os_set_sockbufs(fd, SERVER_TCP_WINDOW, SERVER_TCP_WINDOW)) { - log_write(LS_IAUTH, L_WARNING, 0, "IAuth reconnect unable to set socket buffers: %s", strerror(errno)); - goto failure; - } - s_fd(&i_socket(iauth)) = fd; - result = os_connect_nonb(fd, &i_addr(iauth)); - if (result == IO_FAILURE) { - log_write(LS_IAUTH, L_NOTICE, 0, "IAuth reconnect unable to initiate connection: %s", strerror(errno)); - goto failure; - } - if (!socket_add(&i_socket(iauth), iauth_sock_callback, iauth, - (result == IO_SUCCESS) ? SS_CONNECTED : SS_CONNECTING, - SOCK_EVENT_READABLE | SOCK_EVENT_WRITABLE, fd)) { - log_write(LS_IAUTH, L_WARNING, 0, "IAuth reconnect unable to add socket: %s", strerror(errno)); - goto failure; - } - return; -failure: - close(fd); - i_ClrConnected(iauth); - iauth_schedule_reconnect(iauth); - return; -} - -/** Read input from \a iauth. - * Reads up to SERVER_TCP_WINDOW bytes per pass. - * @param[in] iauth Readable connection. - */ -static void iauth_read(struct IAuth *iauth) -{ - char *src, *endp, *old_buffer, *argv[MAXPARA + 1]; - unsigned int length, argc, ii; - char readbuf[SERVER_TCP_WINDOW]; - - length = 0; - if (IO_FAILURE == os_recv_nonb(s_fd(&i_socket(iauth)), readbuf, sizeof(readbuf), &length) - || length == 0) { - iauth_reconnect(iauth); - return; - } - i_recvB(iauth) += length; - if (i_recvB(iauth) > 1023) { - i_recvK(iauth) += i_recvB(iauth) >> 10; - i_recvB(iauth) &= 1023; - } - old_buffer = i_buffer(iauth); - endp = old_buffer + i_count(iauth); - for (src = readbuf; length > 0; --length) { - *endp = *src++; - if (IsEol(*endp)) { - /* Skip blank lines. */ - if (endp == old_buffer) - continue; - /* NUL-terminate line and split parameters. */ - *endp = '\0'; - for (argc = 0, endp = old_buffer; *endp && (argc < MAXPARA); ) { - while (*endp == ' ') - *endp++ = '\0'; - if (*endp == '\0') - break; - if (*endp == ':') - { - argv[argc++] = endp + 1; - break; - } - argv[argc++] = endp; - for (; *endp && *endp != ' '; ++endp) ; - } - argv[argc] = NULL; - /* Count line and reset endp to start of buffer. */ - i_recvM(iauth)++; - endp = old_buffer; - /* Look up command and try to dispatch. */ - if (argc > 0) { - for (ii = 0; iauth_cmdtab[ii].iac_name; ++ii) { - if (!ircd_strcmp(iauth_cmdtab[ii].iac_name, argv[0])) { - iauth_cmdtab[ii].iac_func(iauth, argc, argv); - if (i_GetAbort(iauth)) - iauth_disconnect(iauth); - break; - } - } - } - } - else if (endp < old_buffer + BUFSIZE) - endp++; - } - i_count(iauth) = endp - old_buffer; -} - -/** Send queued output to \a iauth. - * @param[in] iauth Writable connection with queued data. - */ -static void iauth_write(struct IAuth *iauth) -{ - unsigned int bytes_tried, bytes_sent; - IOResult iores; - - if (i_GetBlocked(iauth)) - return; - while (MsgQLength(&i_sendQ(iauth)) > 0) { - iores = os_sendv_nonb(s_fd(&i_socket(iauth)), &i_sendQ(iauth), &bytes_tried, &bytes_sent); - switch (iores) { - case IO_SUCCESS: - msgq_delete(&i_sendQ(iauth), bytes_sent); - i_sendB(iauth) += bytes_sent; - if (i_sendB(iauth) > 1023) { - i_sendK(iauth) += i_sendB(iauth) >> 10; - i_sendB(iauth) &= 1023; - } - if (bytes_tried == bytes_sent) - break; - /* If bytes_sent < bytes_tried, fall through to IO_BLOCKED. */ - case IO_BLOCKED: - i_SetBlocked(iauth); - socket_events(&i_socket(iauth), SOCK_ACTION_ADD | SOCK_EVENT_WRITABLE); - return; - case IO_FAILURE: - iauth_disconnect(iauth); - return; - } - } - /* We were able to flush all events, so remove notification. */ - socket_events(&i_socket(iauth), SOCK_ACTION_DEL | SOCK_EVENT_WRITABLE); -} - -/** Handle socket activity for an %IAuth connection. - * @param[in] ev &Socket event; the IAuth connection is the user data pointer for the socket. - */ -static void iauth_sock_callback(struct Event *ev) -{ - struct IAuth *iauth; - - assert(0 != ev_socket(ev)); - iauth = (struct IAuth*) s_data(ev_socket(ev)); - assert(0 != iauth); - - switch (ev_type(ev)) { - case ET_CONNECT: - socket_state(ev_socket(ev), SS_CONNECTED); - iauth_on_connect(iauth); - break; - case ET_DESTROY: - if (!i_GetClosing(iauth)) - iauth_schedule_reconnect(iauth); - break; - case ET_READ: - iauth_read(iauth); - break; - case ET_WRITE: - i_ClrBlocked(iauth); - iauth_write(iauth); - break; - case ET_ERROR: - log_write(LS_IAUTH, L_ERROR, 0, "IAuth socket error: %s", strerror(ev_data(ev))); - /* and fall through to the ET_EOF case */ - case ET_EOF: - iauth_disconnect(iauth); - iauth_schedule_reconnect(iauth); - break; - default: - assert(0 && "Unrecognized event type"); - break; - } -} - -/* Functions related to IAuthRequest structs */ - -/** Handle timeout while waiting for a response. - * @param[in] ev Timer event that expired. - */ -static void iauth_request_ev(struct Event *ev) -{ - /* TODO: this could probably be more intelligent */ - if (ev_type(ev) == ET_EXPIRE) { - log_write(LS_IAUTH, L_NOTICE, 0, "IAuth request timed out; reconnecting"); - iauth_reconnect(t_data(ev_timer(ev))); - } -} - -/** Send a authorization request to an %IAuth server. - * @param[in] iauth %Connection to send request on. - * @param[in] iar Request to send. - */ -static void iauth_send_request(struct IAuth *iauth, struct IAuthRequest *iar) -{ - struct Client *client; - - /* If iauth is not connected, we must defer the request. */ - if (!i_GetConnected(iauth)) { - Debug((DEBUG_SEND, "IAuth deferring request for %s because we are not connected.", cli_name(iar->iar_client))); - return; - } - - /* If no timed request, set up expiration timer. */ - if (!t_active(&i_request_timer(iauth))) { - struct Timer *timer = timer_init(&i_request_timer(iauth)); - timer_add(timer, iauth_request_ev, iauth, TT_RELATIVE, i_timeout(iauth)); - iar->iar_timed = 1; - } else - iar->iar_timed = 0; - - /* Send the FullAuth request. */ - client = iar->iar_client; - assert(iar->iar_client != NULL); - iauth_send(iauth, "FullAuth %x %s %s %s %s %s :%s", - client, cli_name(client), cli_username(client), - cli_user(client)->host, cli_sock_ip(client), - cli_passwd(client), cli_info(client)); - - /* Write to the socket if we can. */ - iauth_write(iauth); -} - -/** Start independent authorization check for a client. - * @param[in] iauth %Connection to send request on. - * @param[in] cptr Client to check. - * @return Zero, or CPTR_KILLED in case of memory allocation failure. - */ -int iauth_start_client(struct IAuth *iauth, struct Client *cptr) -{ - struct IAuthRequest *iar; - - /* Allocate and initialize IAuthRequest struct. */ - if (!(iar = MyCalloc(1, sizeof(*iar)))) - return exit_client(cptr, cptr, &me, "IAuth memory allocation failed"); - cli_iauth(cptr) = iar; - iar->iar_next = &i_list_head(iauth); - iar->iar_prev = i_list_head(iauth).iar_prev; - iar->iar_client = cptr; - iar->iar_prev->iar_next = iar; - iar->iar_next->iar_prev = iar; - - /* Send request. */ - iauth_send_request(iauth, iar); - - return 0; -} - -/** Handle a client that is disconnecting. - * If there is a pending %IAuth request for the client, close it. - * @param[in] cptr Client that is disconnecting. - */ -void iauth_exit_client(struct Client *cptr) -{ - if (cli_iauth(cptr)) { - iauth_dispose_request(iauth_active, cli_iauth(cptr)); - cli_iauth(cptr) = NULL; - } - if (iauth_active && i_GetConnected(iauth_active)) { - iauth_send(iauth_active, "ExitUser %x", cptr); - iauth_write(iauth_active); - } -} - -/** Find pending request with a particular ID. - * @param[in] iauth %Connection context for the ID. - * @param[in] id Identifier to look up. - * @return IAuthRequest with that ID, or NULL. - */ -static struct IAuthRequest *iauth_find_request(struct IAuth *iauth, char *id) -{ - struct IAuthRequest *curr; - struct Client *target; - target = (struct Client*)strtoul(id, NULL, 16); - for (curr = i_list_head(iauth).iar_next; - curr != &i_list_head(iauth); - curr = curr->iar_next) { - assert(curr->iar_client != NULL); - if (target == curr->iar_client) - return curr; - } - return NULL; -} - -/** Unlink and free a request. - * @param[in] iauth Connection that owns the request. - * @param[in] iar Request to free. - */ -static void iauth_dispose_request(struct IAuth *iauth, struct IAuthRequest *iar) -{ - assert(iar->iar_client != NULL); - if (iar->iar_timed && t_active(&i_request_timer(iauth))) - timer_del(&i_request_timer(iauth)); - cli_iauth(iar->iar_client) = NULL; - iar->iar_prev->iar_next = iar->iar_next; - iar->iar_next->iar_prev = iar->iar_prev; - MyFree(iar); -} - -/** Handle a DoneAuth response from %IAuth. - * This means the client is authorized, so let them in. - * @param[in] iauth Connection that sent the message. - * @param[in] argc Argument count. - * @param[in] argv Argument list. - */ -static void iauth_cmd_doneauth(struct IAuth *iauth, int argc, char *argv[]) -{ - struct IAuthRequest *iar; - struct Client *client; - char *id; - char *username; - char *hostname; - char *c_class; -#if defined(UNDERNET) - char *account; -#endif - - if (argc < 5) { - iauth_protocol_violation(iauth, "Only %d parameters for DoneAuth (expected >=5)", argc); - return; - } - id = argv[1]; - username = argv[2]; - hostname = argv[3]; - c_class = argv[4]; -#if defined(UNDERNET) - account = (argc > 5) ? argv[5] : 0; -#endif - iar = iauth_find_request(iauth, id); - if (!iar) { - iauth_protocol_violation(iauth, "Got unexpected DoneAuth for id %s", id); - return; - } - client = iar->iar_client; - ircd_strncpy(cli_username(client), username, USERLEN); - ircd_strncpy(cli_user(client)->host, hostname, HOSTLEN); -#if defined(UNDERNET) - if (account) { - ircd_strncpy(cli_user(client)->account, account, ACCOUNTLEN); - SetAccount(client); - } -#endif - SetIAuthed(client); - iauth_dispose_request(iauth, iar); - register_user(client, client, cli_name(client), username); -} - -/** Handle a BadAuth response from %IAuth. - * This means the client is not authorized, so dump them. - * @param[in] iauth Connection that sent the message. - * @param[in] argc Argument count. - * @param[in] argv Argument list. - */ -static void iauth_cmd_badauth(struct IAuth *iauth, int argc, char *argv[]) -{ - struct IAuthRequest *iar; - struct Client *client; - char *id; - char *reason; - - if (argc < 3) { - iauth_protocol_violation(iauth, "Only %d parameters for BadAuth (expected >=3)", argc); - return; - } - id = argv[1]; - reason = argv[2]; - if (EmptyString(reason)) { - iauth_protocol_violation(iauth, "Empty BadAuth reason for id %s", id); - return; - } - iar = iauth_find_request(iauth, id); - if (!iar) { - iauth_protocol_violation(iauth, "Got unexpected BadAuth for id %s", id); - return; - } - client = iar->iar_client; - iauth_dispose_request(iauth, iar); - exit_client(client, client, &me, reason); -} Index: ircd-ircdev/ircd/ircd_parser.y diff -u ircd-ircdev/ircd/ircd_parser.y:1.26 ircd-ircdev/ircd/ircd_parser.y:1.27 --- ircd-ircdev/ircd/ircd_parser.y:1.26 Sun Apr 22 06:56:20 2007 +++ ircd-ircdev/ircd/ircd_parser.y Thu Apr 26 12:17:31 2007 @@ -18,7 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: ircd_parser.y,v 1.26 2007/04/22 13:56:20 zolty Exp $ + * $Id: ircd_parser.y,v 1.27 2007/04/26 19:17:31 zolty Exp $ * */ %{ @@ -34,7 +34,6 @@ #include "hash.h" #include "ircd.h" #include "ircd_alloc.h" -#include "ircd_auth.h" #include "ircd_chattr.h" #include "ircd_log.h" #include "ircd_reply.h" @@ -49,6 +48,7 @@ #include "opercmds.h" #include "parse.h" #include "res.h" +#include "s_auth.h" #include "s_bsd.h" #include "s_conf.h" #include "s_debug.h" @@ -451,7 +451,7 @@ { char *server = $4; - /* add_nameserver(server); TODO-ZOLTAN */ + add_nameserver(server); MyFree(server); }; @@ -1235,8 +1235,8 @@ iauthblock: IAUTH '{' iauthitems '}' ';' { - /* if (permitted(BLOCK_IAUTH, 1)) - auth_spawn(stringno, stringlist); TODO-ZOLTAN */ + if (permitted(BLOCK_IAUTH, 1)) + auth_spawn(stringno, stringlist); while (stringno > 0) MyFree(stringlist[--stringno]); }; Index: ircd-ircdev/ircd/ircd_res.c diff -u ircd-ircdev/ircd/ircd_res.c:1.14 ircd-ircdev/ircd/ircd_res.c:1.15 --- ircd-ircdev/ircd/ircd_res.c:1.14 Sun Apr 22 06:56:20 2007 +++ ircd-ircdev/ircd/ircd_res.c Thu Apr 26 12:17:31 2007 @@ -41,7 +41,7 @@ */ /** @file * @brief IRC resolver functions. - * @version $Id: ircd_res.c,v 1.14 2007/04/22 13:56:20 zolty Exp $ + * @version $Id: ircd_res.c,v 1.15 2007/04/26 19:17:31 zolty Exp $ */ #include "client.h" #include "ircd_alloc.h" @@ -167,6 +167,16 @@ extern int irc_nscount; extern char irc_domain[HOSTLEN]; +/** Prepare the resolver library to (optionally) accept a list of + * DNS servers through add_dns_server(). + */ +void clear_nameservers(void) +{ + irc_nscount = 0; + memset(&VirtualHost_dns_v4, 0, sizeof(VirtualHost_dns_v4)); + memset(&VirtualHost_dns_v6, 0, sizeof(VirtualHost_dns_v6)); +} + /** Check whether \a inp is a nameserver we use. * @param[in] inp Nameserver address. * @return Non-zero if we trust \a inp; zero if not. @@ -191,26 +201,43 @@ void restart_resolver(void) { + int need_v4; + int need_v6; + int ns; + irc_res_init(); if (!request_list.next) request_list.next = request_list.prev = &request_list; - if (!s_active(&res_socket_v4)) + /* Check which address family (or families) our nameservers use. */ + for (need_v4 = need_v6 = ns = 0; ns < irc_nscount; ns++) + { + if (irc_in_addr_is_ipv4(&irc_nsaddr_list[ns].addr)) + need_v4 = 1; + else + need_v6 = 1; + } + + /* If we need an IPv4 socket, and don't have one, open it. */ + if (need_v4 && !s_active(&res_socket_v4)) { - int fd = os_socket(&VirtualHost_v4, SOCK_DGRAM, "Resolver UDPv4 socket", AF_INET); + int fd = os_socket(&VirtualHost_dns_v4, SOCK_DGRAM, "Resolver UDPv4 socket", AF_INET); if (fd >= 0) socket_add(&res_socket_v4, res_readreply, NULL, SS_DATAGRAM, SOCK_EVENT_READABLE, fd); } - if (!s_active(&res_socket_v6)) +#ifdef AF_INET6 + /* If we need an IPv6 socket, and don't have one, open it. */ + if (need_v6 && !s_active(&res_socket_v6)) { - int fd = os_socket(&VirtualHost_v6, SOCK_DGRAM, "Resolver UDPv6 socket", AF_INET6); + int fd = os_socket(&VirtualHost_dns_v6, SOCK_DGRAM, "Resolver UDPv6 socket", AF_INET6); if (fd >= 0) socket_add(&res_socket_v6, res_readreply, NULL, SS_DATAGRAM, SOCK_EVENT_READABLE, fd); } +#endif if (s_active(&res_socket_v4) || s_active(&res_socket_v6)) timer_init(&res_timeout); @@ -221,7 +248,7 @@ * @param[in,out] hname Hostname to check. * @param[in] size Length of \a hname buffer. */ -void +static void add_local_domain(char* hname, size_t size) { /* try to fix up unqualified names @@ -269,7 +296,8 @@ } /** Create a DNS request record for the server. - * @param[in] query Callback information for caller. + * @param[in] callback Callback function to use. + * @param[in] ctx Context parameter for \a callback. * @return Newly allocated and linked-in reslist. */ static struct reslist * @@ -440,7 +468,8 @@ /** Try to look up address for a hostname, trying IPv6 (T_AAAA) first. * @param[in] name Hostname to look up. - * @param[in] query Callback information. + * @param[in] callback Function to call upon completion. + * @param[in] ctx Callback data to pass to \a callback. */ void gethost_byname(const char *name, dns_callback_f callback, void *ctx) @@ -450,7 +479,8 @@ /** Try to look up hostname for an address. * @param[in] addr Address to look up. - * @param[in] query Callback information. + * @param[in] callback Function to call upon completion. + * @param[in] ctx Callback data to pass to \a callback. */ void gethost_byaddr(const struct irc_in_addr *addr, dns_callback_f callback, void *ctx) @@ -459,7 +489,8 @@ } /** Send a query to look up the address for a name. - * @param[in] query Callback information. + * @param[in] callback Callback function to call upon completion. + * @param[in] ctx Context information to pass to \a callback. * @param[in] name Hostname to look up. * @param[in] request DNS lookup structure (may be NULL). * @param[in] type Preferred request type. @@ -731,9 +762,6 @@ break; case T_CNAME: /* first check we already haven't started looking into a cname */ - if (request->type != T_PTR) - return(0); - if (request->state == REQ_CNAME) { n = irc_dn_expand((unsigned char *)buf, (unsigned char *)eob, @@ -812,7 +840,7 @@ if ((header->rcode != NO_ERRORS) || (header->ancount == 0)) { - if (SERVFAIL == header->rcode) + if (SERVFAIL == header->rcode || NXDOMAIN == header->rcode) { /* * If a bad error was returned, we stop here and don't send Index: ircd-ircdev/ircd/ircd_reslib.c diff -u ircd-ircdev/ircd/ircd_reslib.c:1.4 ircd-ircdev/ircd/ircd_reslib.c:1.5 --- ircd-ircdev/ircd/ircd_reslib.c:1.4 Thu Apr 19 15:53:48 2007 +++ ircd-ircdev/ircd/ircd_reslib.c Thu Apr 26 12:17:31 2007 @@ -122,13 +122,13 @@ /** @file * @brief DNS resolver library functions. - * @version $Id: ircd_reslib.c,v 1.4 2007/04/19 22:53:48 zolty Exp $ + * @version $Id: ircd_reslib.c,v 1.5 2007/04/26 19:17:31 zolty Exp $ */ /** Array of nameserver addresses. */ struct irc_sockaddr irc_nsaddr_list[IRCD_MAXNS]; /** Number of nameservers in #irc_nsaddr_list. */ -int irc_nscount = 0; +int irc_nscount; /** Local domain to use as a search suffix. */ char irc_domain[HOSTLEN + 1]; @@ -153,7 +153,6 @@ }; static int parse_resvconf(void); -static void add_nameserver(char *arg); /** Array of decimal digits, indexed by value. */ static const char digits[] = "0123456789"; @@ -175,8 +174,7 @@ int irc_res_init(void) { - irc_nscount = 0; - return(parse_resvconf()); + return (irc_nscount == 0) ? parse_resvconf() : 0; } /** Read resolver configuration file for domain and nameserver lines. @@ -246,13 +244,13 @@ /** Add a resolver to #irc_nsaddr_list. * @param[in] arg Dotted quad or IPv6 text form of nameserver address. */ -static void -... [truncated message content] |