authd: split out notices stuff for backporting to master.

This commit is contained in:
Elizabeth Myers 2016-03-25 21:29:44 -05:00
parent a70a737c9b
commit db821ee9ba
9 changed files with 98 additions and 46 deletions

View file

@ -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

View file

@ -21,6 +21,7 @@
#include "authd.h"
#include "dns.h"
#include "provider.h"
#include "notice.h"
#define MAXPARA 10

48
authd/notice.c Normal file
View file

@ -0,0 +1,48 @@
/* authd/notice.c - send notices back to the ircd and to clients
* Copyright (c) 2016 Elizabeth Myers <elizabeth@interlinked.me>
*
* 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);
}

35
authd/notice.h Normal file
View file

@ -0,0 +1,35 @@
/* authd/notice.h - send notices back to the ircd and to clients
* Copyright (c) 2016 Elizabeth Myers <elizabeth@interlinked.me>
*
* 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__ */

View file

@ -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)
{

View file

@ -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) */

View file

@ -39,6 +39,7 @@
#include "authd.h"
#include "provider.h"
#include "notice.h"
#include "stdinc.h"
#include "dns.h"

View file

@ -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);
}

View file

@ -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);