diff --git a/authd/Makefile.am b/authd/Makefile.am index 235061c4..ef2c44a4 100644 --- a/authd/Makefile.am +++ b/authd/Makefile.am @@ -4,13 +4,14 @@ AM_CPPFLAGS = -I../include -I../librb/include authd_SOURCES = \ authd.c \ - res.c \ - reslib.c \ - reslist.c \ dns.c \ getaddrinfo.c \ getnameinfo.c \ + notice.c \ provider.c \ + res.c \ + reslib.c \ + reslist.c \ providers/blacklist.c \ providers/ident.c \ providers/rdns.c diff --git a/authd/authd.c b/authd/authd.c index acd5bc1e..d77d87b1 100644 --- a/authd/authd.c +++ b/authd/authd.c @@ -21,6 +21,7 @@ #include "authd.h" #include "dns.h" #include "provider.h" +#include "notice.h" #define MAXPARA 10 diff --git a/authd/notice.c b/authd/notice.c new file mode 100644 index 00000000..3e1d3f8a --- /dev/null +++ b/authd/notice.c @@ -0,0 +1,48 @@ +/* authd/notice.c - send notices back to the ircd and to clients + * Copyright (c) 2016 Elizabeth Myers + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice is present in all copies. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "authd.h" +#include "notice.h" + +/* Send a notice to a client */ +void notice_client(uint32_t cid, const char *fmt, ...) +{ + char buf[BUFSIZE]; + va_list args; + + va_start(args, fmt); + vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + rb_helper_write(authd_helper, "N %x :%s", cid, buf); +} + +/* Send a warning to the IRC daemon for logging, etc. */ +void warn_opers(notice_level_t level, const char *fmt, ...) +{ + char buf[BUFSIZE]; + va_list args; + + va_start(args, fmt); + vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + rb_helper_write(authd_helper, "W %c :%s", level, buf); +} diff --git a/authd/notice.h b/authd/notice.h new file mode 100644 index 00000000..1e48bccf --- /dev/null +++ b/authd/notice.h @@ -0,0 +1,35 @@ +/* authd/notice.h - send notices back to the ircd and to clients + * Copyright (c) 2016 Elizabeth Myers + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice is present in all copies. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __CHARYBDIS_AUTHD_NOTICE_H__ +#define __CHARYBDIS_AUTHD_NOTICE_H__ + +typedef enum +{ + L_DEBUG = 'D', + L_INFO = 'I', + L_WARN = 'W', + L_CRIT ='C', +} notice_level_t; + +void notice_client(uint32_t cid, const char *fmt, ...); +void warn_opers(notice_level_t level, const char *fmt, ...); + +#endif /* __CHARYBDIS_AUTHD_NOTICE_H__ */ diff --git a/authd/provider.c b/authd/provider.c index 4e17793e..1a6c6517 100644 --- a/authd/provider.c +++ b/authd/provider.c @@ -49,6 +49,7 @@ #include "rb_dictionary.h" #include "authd.h" #include "provider.h" +#include "notice.h" rb_dlink_list auth_providers; @@ -193,32 +194,6 @@ void accept_client(struct auth_client *auth, provider_t id) cancel_providers(auth); } -/* Send a notice to a client */ -void notice_client(struct auth_client *auth, const char *fmt, ...) -{ - char buf[BUFSIZE]; - va_list args; - - va_start(args, fmt); - vsnprintf(buf, sizeof(buf), fmt, args); - va_end(args); - - rb_helper_write(authd_helper, "N %x :%s", auth->cid, buf); -} - -/* Send a warning to the IRC daemon for logging, etc. */ -void warn_opers(notice_level_t level, const char *fmt, ...) -{ - char buf[BUFSIZE]; - va_list args; - - va_start(args, fmt); - vsnprintf(buf, sizeof(buf), fmt, args); - va_end(args); - - rb_helper_write(authd_helper, "W %c :%s", level, buf); -} - /* Begin authenticating user */ static void start_auth(const char *cid, const char *l_ip, const char *l_port, const char *c_ip, const char *c_port) { diff --git a/authd/provider.h b/authd/provider.h index ef96ca84..8fab21cf 100644 --- a/authd/provider.h +++ b/authd/provider.h @@ -34,14 +34,6 @@ typedef enum PROVIDER_BLACKLIST, } provider_t; -typedef enum -{ - L_DEBUG = 'D', - L_INFO = 'I', - L_WARN = 'W', - L_CRIT ='C', -} notice_level_t; - struct auth_client { uint16_t cid; /* Client ID */ @@ -103,9 +95,6 @@ void provider_done(struct auth_client *auth, provider_t id); void accept_client(struct auth_client *auth, provider_t id); void reject_client(struct auth_client *auth, provider_t id, const char *reason); -void notice_client(struct auth_client *auth, const char *fmt, ...); -void warn_opers(notice_level_t level, const char *fmt, ...); - void handle_new_connection(int parc, char *parv[]); /* Provider is operating on this auth_client (set this if you have async work to do) */ diff --git a/authd/providers/blacklist.c b/authd/providers/blacklist.c index 22917c03..df7d3974 100644 --- a/authd/providers/blacklist.c +++ b/authd/providers/blacklist.c @@ -39,6 +39,7 @@ #include "authd.h" #include "provider.h" +#include "notice.h" #include "stdinc.h" #include "dns.h" diff --git a/authd/providers/ident.c b/authd/providers/ident.c index a19b289e..2c561462 100644 --- a/authd/providers/ident.c +++ b/authd/providers/ident.c @@ -21,6 +21,7 @@ #include "stdinc.h" #include "match.h" #include "authd.h" +#include "notice.h" #include "provider.h" #include "res.h" @@ -120,7 +121,7 @@ bool ident_start(struct auth_client *auth) GET_SS_LEN(&l_addr), ident_connected, query, ident_timeout); - notice_client(auth, messages[REPORT_LOOKUP]); + notice_client(auth->cid, messages[REPORT_LOOKUP]); set_provider_on(auth, PROVIDER_IDENT); return true; @@ -249,7 +250,7 @@ static void client_fail(struct auth_client *auth, ident_message report) rb_free(query); auth->data[PROVIDER_IDENT] = NULL; - notice_client(auth, messages[report]); + notice_client(auth->cid, messages[report]); provider_done(auth, PROVIDER_IDENT); } @@ -261,7 +262,7 @@ static void client_success(struct auth_client *auth) rb_free(query); auth->data[PROVIDER_IDENT] = NULL; - notice_client(auth, messages[REPORT_FOUND]); + notice_client(auth->cid, messages[REPORT_FOUND]); provider_done(auth, PROVIDER_IDENT); } diff --git a/authd/providers/rdns.c b/authd/providers/rdns.c index ddce08fb..0b203740 100644 --- a/authd/providers/rdns.c +++ b/authd/providers/rdns.c @@ -22,6 +22,7 @@ #include "rb_commio.h" #include "authd.h" #include "provider.h" +#include "notice.h" #include "res.h" #include "dns.h" @@ -87,7 +88,7 @@ bool client_dns_start(struct auth_client *auth) query->query = lookup_hostname(auth->c_ip, dns_answer_callback, auth); - notice_client(auth, messages[REPORT_LOOKUP]); + notice_client(auth->cid, messages[REPORT_LOOKUP]); set_provider_on(auth, PROVIDER_RDNS); return true; } @@ -144,7 +145,7 @@ static void client_fail(struct auth_client *auth, dns_message report) rb_strlcpy(auth->hostname, "*", sizeof(auth->hostname)); - notice_client(auth, messages[report]); + notice_client(auth->cid, messages[report]); cancel_query(query->query); rb_free(query); @@ -157,7 +158,7 @@ static void client_success(struct auth_client *auth) { struct user_query *query = auth->data[PROVIDER_RDNS]; - notice_client(auth, messages[REPORT_FOUND]); + notice_client(auth->cid, messages[REPORT_FOUND]); cancel_query(query->query); rb_free(query);