2016-01-06 11:41:57 +01:00
|
|
|
/*
|
|
|
|
* authd.c: An interface to authd.
|
|
|
|
* (based somewhat on ircd-ratbox dns.c)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Aaron Sethman <androsyn@ratbox.org>
|
|
|
|
* Copyright (C) 2005-2012 ircd-ratbox development team
|
|
|
|
* Copyright (C) 2016 William Pitcock <nenolod@dereferenced.org>
|
|
|
|
*
|
|
|
|
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
|
|
|
* USA
|
|
|
|
*/
|
|
|
|
|
2016-08-15 10:17:35 +02:00
|
|
|
namespace ircd {
|
2016-08-13 05:05:54 +02:00
|
|
|
|
2016-04-02 11:49:01 +02:00
|
|
|
typedef void (*authd_cb_t)(int, char **);
|
|
|
|
|
|
|
|
struct authd_cb
|
|
|
|
{
|
|
|
|
authd_cb_t fn;
|
|
|
|
int min_parc;
|
|
|
|
};
|
|
|
|
|
2016-01-06 11:41:57 +01:00
|
|
|
static int start_authd(void);
|
|
|
|
static void parse_authd_reply(rb_helper * helper);
|
|
|
|
static void restart_authd_cb(rb_helper * helper);
|
2016-03-28 09:30:54 +02:00
|
|
|
static EVH timeout_dead_authd_clients;
|
2016-01-06 11:41:57 +01:00
|
|
|
|
2016-04-02 11:49:01 +02:00
|
|
|
static void cmd_accept_client(int parc, char **parv);
|
|
|
|
static void cmd_reject_client(int parc, char **parv);
|
|
|
|
static void cmd_dns_result(int parc, char **parv);
|
|
|
|
static void cmd_notice_client(int parc, char **parv);
|
|
|
|
static void cmd_oper_warn(int parc, char **parv);
|
|
|
|
static void cmd_stats_results(int parc, char **parv);
|
|
|
|
|
2016-08-15 10:17:35 +02:00
|
|
|
rb_helper *authd_helper;
|
2016-01-06 11:41:57 +01:00
|
|
|
static char *authd_path;
|
|
|
|
|
2016-03-28 23:47:51 +02:00
|
|
|
uint32_t cid;
|
2016-03-28 09:11:16 +02:00
|
|
|
static rb_dictionary *cid_clients;
|
2016-03-28 09:30:54 +02:00
|
|
|
static struct ev_entry *timeout_ev;
|
2016-03-28 09:11:16 +02:00
|
|
|
|
2016-08-15 10:17:35 +02:00
|
|
|
rb_dictionary *bl_stats;
|
2016-03-28 09:11:16 +02:00
|
|
|
|
2016-08-15 10:17:35 +02:00
|
|
|
rb_dlink_list opm_list;
|
|
|
|
struct OPMListener opm_listeners[LISTEN_LAST];
|
2016-04-12 16:33:51 +02:00
|
|
|
|
2016-07-23 00:11:39 +02:00
|
|
|
std::array<authd_cb, 256> authd_cmd_tab =
|
|
|
|
[]{
|
2016-07-13 07:17:21 +02:00
|
|
|
std::array<authd_cb, 256> ret {0};
|
|
|
|
ret['A'] = { cmd_accept_client, 4 };
|
|
|
|
ret['E'] = { cmd_dns_result, 5 };
|
|
|
|
ret['N'] = { cmd_notice_client, 3 };
|
|
|
|
ret['R'] = { cmd_reject_client, 7 };
|
|
|
|
ret['W'] = { cmd_oper_warn, 3 };
|
|
|
|
ret['X'] = { cmd_stats_results, 3 };
|
|
|
|
ret['Y'] = { cmd_stats_results, 3 };
|
|
|
|
ret['Z'] = { cmd_stats_results, 3 };
|
|
|
|
return ret;
|
2016-07-23 00:11:39 +02:00
|
|
|
}();
|
2016-04-02 11:49:01 +02:00
|
|
|
|
2016-01-06 11:41:57 +01:00
|
|
|
static int
|
|
|
|
start_authd(void)
|
|
|
|
{
|
|
|
|
char fullpath[PATH_MAX + 1];
|
|
|
|
#ifdef _WIN32
|
|
|
|
const char *suffix = ".exe";
|
|
|
|
#else
|
|
|
|
const char *suffix = "";
|
|
|
|
#endif
|
|
|
|
if(authd_path == NULL)
|
|
|
|
{
|
2016-08-14 05:35:06 +02:00
|
|
|
snprintf(fullpath, sizeof(fullpath), "%s%cauthd%s", path::get(path::LIBEXEC), RB_PATH_SEPARATOR, suffix);
|
2016-01-06 11:41:57 +01:00
|
|
|
|
|
|
|
if(access(fullpath, X_OK) == -1)
|
|
|
|
{
|
2016-03-25 00:45:28 +01:00
|
|
|
snprintf(fullpath, sizeof(fullpath), "%s%cbin%cauthd%s",
|
|
|
|
ConfigFileEntry.dpath, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR, suffix);
|
2016-01-06 11:41:57 +01:00
|
|
|
if(access(fullpath, X_OK) == -1)
|
|
|
|
{
|
2016-08-14 05:35:06 +02:00
|
|
|
// TODO: double dipping
|
2016-03-29 02:06:31 +02:00
|
|
|
ierror("Unable to execute authd in %s or %s/bin",
|
2016-08-14 05:35:06 +02:00
|
|
|
path::get(path::LIBEXEC),
|
|
|
|
ConfigFileEntry.dpath);
|
|
|
|
|
|
|
|
// TODO: double dipping
|
2016-08-26 13:50:12 +02:00
|
|
|
sendto_realops_snomask(sno::GENERAL, L_ALL,
|
2016-08-14 05:35:06 +02:00
|
|
|
"Unable to execute authd in %s or %s/bin",
|
|
|
|
path::get(path::LIBEXEC),
|
|
|
|
ConfigFileEntry.dpath);
|
2016-01-06 11:41:57 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
authd_path = rb_strdup(fullpath);
|
|
|
|
}
|
|
|
|
|
2016-03-28 09:11:16 +02:00
|
|
|
if(cid_clients == NULL)
|
|
|
|
cid_clients = rb_dictionary_create("authd cid to uid mapping", rb_uint32cmp);
|
|
|
|
|
2016-03-28 09:30:54 +02:00
|
|
|
if(timeout_ev == NULL)
|
|
|
|
timeout_ev = rb_event_addish("timeout_dead_authd_clients", timeout_dead_authd_clients, NULL, 1);
|
|
|
|
|
2016-01-06 11:41:57 +01:00
|
|
|
authd_helper = rb_helper_start("authd", authd_path, parse_authd_reply, restart_authd_cb);
|
|
|
|
|
|
|
|
if(authd_helper == NULL)
|
|
|
|
{
|
2016-03-29 02:06:31 +02:00
|
|
|
ierror("Unable to start authd helper: %s", strerror(errno));
|
2016-08-26 13:50:12 +02:00
|
|
|
sendto_realops_snomask(sno::GENERAL, L_ALL, "Unable to start authd helper: %s", strerror(errno));
|
2016-01-06 11:41:57 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2016-04-30 08:11:08 +02:00
|
|
|
|
2016-01-06 11:41:57 +01:00
|
|
|
ilog(L_MAIN, "authd helper started");
|
2016-08-26 13:50:12 +02:00
|
|
|
sendto_realops_snomask(sno::GENERAL, L_ALL, "authd helper started");
|
2016-01-06 11:41:57 +01:00
|
|
|
rb_helper_run(authd_helper);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-02 08:16:47 +02:00
|
|
|
static inline uint32_t
|
|
|
|
str_to_cid(const char *str)
|
|
|
|
{
|
|
|
|
long lcid = strtol(str, NULL, 16);
|
|
|
|
|
|
|
|
if(lcid > UINT32_MAX || lcid <= 0)
|
|
|
|
{
|
|
|
|
iwarn("authd sent us back a bad client ID: %lx", lcid);
|
|
|
|
restart_authd();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (uint32_t)lcid;
|
|
|
|
}
|
|
|
|
|
2016-08-22 03:57:43 +02:00
|
|
|
static inline client::client *
|
2016-06-01 21:55:35 +02:00
|
|
|
cid_to_client(uint32_t ncid, bool del)
|
2016-04-02 08:16:47 +02:00
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *client_p;
|
2016-04-02 08:16:47 +02:00
|
|
|
|
2016-06-01 21:55:35 +02:00
|
|
|
if(del)
|
2016-08-22 03:57:43 +02:00
|
|
|
client_p = (client::client *)rb_dictionary_delete(cid_clients, RB_UINT_TO_POINTER(ncid));
|
2016-04-02 08:16:47 +02:00
|
|
|
else
|
2016-08-22 03:57:43 +02:00
|
|
|
client_p = (client::client *)rb_dictionary_retrieve(cid_clients, RB_UINT_TO_POINTER(ncid));
|
2016-04-02 08:16:47 +02:00
|
|
|
|
2016-04-02 10:51:54 +02:00
|
|
|
/* If the client's not found, that's okay, it may have already gone away.
|
|
|
|
* --Elizafox */
|
2016-04-02 08:16:47 +02:00
|
|
|
|
|
|
|
return client_p;
|
|
|
|
}
|
|
|
|
|
2016-08-22 03:57:43 +02:00
|
|
|
static inline client::client *
|
2016-06-01 21:55:35 +02:00
|
|
|
str_cid_to_client(const char *str, bool del)
|
2016-04-02 08:20:49 +02:00
|
|
|
{
|
2016-06-01 21:55:35 +02:00
|
|
|
uint32_t ncid = str_to_cid(str);
|
2016-04-02 08:20:49 +02:00
|
|
|
|
2016-06-01 21:55:35 +02:00
|
|
|
if(ncid == 0)
|
2016-04-02 08:20:49 +02:00
|
|
|
return NULL;
|
|
|
|
|
2016-06-01 21:55:35 +02:00
|
|
|
return cid_to_client(ncid, del);
|
2016-04-02 08:20:49 +02:00
|
|
|
}
|
|
|
|
|
2016-01-06 11:41:57 +01:00
|
|
|
static void
|
2016-04-02 11:49:01 +02:00
|
|
|
cmd_accept_client(int parc, char **parv)
|
2016-01-06 11:41:57 +01:00
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *client_p;
|
2016-04-02 11:51:11 +02:00
|
|
|
|
2016-04-02 11:49:01 +02:00
|
|
|
/* cid to uid (retrieve and delete) */
|
|
|
|
if((client_p = str_cid_to_client(parv[1], true)) == NULL)
|
|
|
|
return;
|
2016-03-08 09:53:25 +01:00
|
|
|
|
2016-04-02 11:49:01 +02:00
|
|
|
authd_accept_client(client_p, parv[2], parv[3]);
|
|
|
|
}
|
2016-01-06 11:41:57 +01:00
|
|
|
|
2016-04-02 11:49:01 +02:00
|
|
|
static void
|
|
|
|
cmd_dns_result(int parc, char **parv)
|
|
|
|
{
|
|
|
|
dns_results_callback(parv[1], parv[2], parv[3], parv[4]);
|
|
|
|
}
|
2016-03-28 09:11:16 +02:00
|
|
|
|
2016-04-02 11:49:01 +02:00
|
|
|
static void
|
|
|
|
cmd_notice_client(int parc, char **parv)
|
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *client_p;
|
2016-03-28 09:11:16 +02:00
|
|
|
|
2016-04-02 11:49:01 +02:00
|
|
|
if((client_p = str_cid_to_client(parv[1], false)) == NULL)
|
|
|
|
return;
|
2016-03-28 09:11:16 +02:00
|
|
|
|
2016-04-02 11:49:01 +02:00
|
|
|
sendto_one_notice(client_p, ":%s", parv[2]);
|
|
|
|
}
|
2016-03-28 09:11:16 +02:00
|
|
|
|
2016-04-02 11:49:01 +02:00
|
|
|
static void
|
|
|
|
cmd_reject_client(int parc, char **parv)
|
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *client_p;
|
2016-03-28 23:47:51 +02:00
|
|
|
|
2016-04-02 11:49:01 +02:00
|
|
|
/* cid to uid (retrieve and delete) */
|
|
|
|
if((client_p = str_cid_to_client(parv[1], true)) == NULL)
|
|
|
|
return;
|
2016-03-28 09:19:34 +02:00
|
|
|
|
2016-04-02 11:49:01 +02:00
|
|
|
authd_reject_client(client_p, parv[3], parv[4], toupper(*parv[2]), parv[5], parv[6]);
|
|
|
|
}
|
2016-04-02 08:20:49 +02:00
|
|
|
|
2016-04-02 11:49:01 +02:00
|
|
|
static void
|
|
|
|
cmd_oper_warn(int parc, char **parv)
|
|
|
|
{
|
2016-04-03 03:31:32 +02:00
|
|
|
switch(*parv[1])
|
2016-04-02 11:49:01 +02:00
|
|
|
{
|
|
|
|
case 'D': /* Debug */
|
2016-08-26 13:50:12 +02:00
|
|
|
sendto_realops_snomask(sno::DEBUG, L_ALL, "authd debug: %s", parv[2]);
|
2016-04-03 03:31:32 +02:00
|
|
|
idebug("authd: %s", parv[2]);
|
2016-04-02 11:49:01 +02:00
|
|
|
break;
|
|
|
|
case 'I': /* Info */
|
2016-08-26 13:50:12 +02:00
|
|
|
sendto_realops_snomask(sno::GENERAL, L_ALL, "authd info: %s", parv[2]);
|
2016-04-03 03:31:32 +02:00
|
|
|
inotice("authd: %s", parv[2]);
|
2016-04-02 11:49:01 +02:00
|
|
|
break;
|
|
|
|
case 'W': /* Warning */
|
2016-08-26 13:50:12 +02:00
|
|
|
sendto_realops_snomask(sno::GENERAL, L_ALL, "authd WARNING: %s", parv[2]);
|
2016-04-03 03:31:32 +02:00
|
|
|
iwarn("authd: %s", parv[2]);
|
2016-04-02 11:49:01 +02:00
|
|
|
break;
|
|
|
|
case 'C': /* Critical (error) */
|
2016-08-26 13:50:12 +02:00
|
|
|
sendto_realops_snomask(sno::GENERAL, L_ALL, "authd CRITICAL: %s", parv[2]);
|
2016-04-03 03:31:32 +02:00
|
|
|
ierror("authd: %s", parv[2]);
|
2016-04-02 11:49:01 +02:00
|
|
|
break;
|
|
|
|
default: /* idk */
|
2016-08-26 13:50:12 +02:00
|
|
|
sendto_realops_snomask(sno::GENERAL, L_ALL, "authd sent us an unknown oper notice type (%s): %s", parv[1], parv[2]);
|
2016-04-03 03:31:32 +02:00
|
|
|
ilog(L_MAIN, "authd unknown oper notice type (%s): %s", parv[1], parv[2]);
|
2016-04-02 11:49:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-03-26 03:57:42 +01:00
|
|
|
|
2016-04-02 11:49:01 +02:00
|
|
|
static void
|
|
|
|
cmd_stats_results(int parc, char **parv)
|
|
|
|
{
|
|
|
|
/* Select by type */
|
|
|
|
switch(*parv[2])
|
|
|
|
{
|
|
|
|
case 'D':
|
|
|
|
/* parv[0] conveys status */
|
|
|
|
if(parc < 4)
|
|
|
|
{
|
|
|
|
iwarn("authd sent a result with wrong number of arguments: got %d", parc);
|
|
|
|
restart_authd();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dns_stats_results_callback(parv[1], parv[0], parc - 3, (const char **)&parv[3]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parse_authd_reply(rb_helper * helper)
|
|
|
|
{
|
|
|
|
ssize_t len;
|
|
|
|
int parc;
|
2016-04-02 11:51:11 +02:00
|
|
|
char buf[READBUF_SIZE];
|
2016-04-02 11:49:01 +02:00
|
|
|
char *parv[MAXPARA + 1];
|
2016-03-26 03:57:42 +01:00
|
|
|
|
2016-04-02 11:51:11 +02:00
|
|
|
while((len = rb_helper_read(helper, buf, sizeof(buf))) > 0)
|
2016-04-02 11:49:01 +02:00
|
|
|
{
|
|
|
|
struct authd_cb *cmd;
|
|
|
|
|
2016-04-02 11:51:11 +02:00
|
|
|
parc = rb_string_to_array(buf, parv, MAXPARA+1);
|
2016-04-23 05:06:42 +02:00
|
|
|
cmd = &authd_cmd_tab[(unsigned char)*parv[0]];
|
2016-04-02 11:49:01 +02:00
|
|
|
if(cmd->fn != NULL)
|
|
|
|
{
|
|
|
|
if(cmd->min_parc > parc)
|
2016-03-08 09:53:25 +01:00
|
|
|
{
|
2016-04-02 11:49:01 +02:00
|
|
|
iwarn("authd sent a result with wrong number of arguments: expected %d, got %d",
|
|
|
|
cmd->min_parc, parc);
|
2016-03-08 09:53:25 +01:00
|
|
|
restart_authd();
|
2016-04-02 11:49:01 +02:00
|
|
|
continue;
|
2016-03-08 09:53:25 +01:00
|
|
|
}
|
|
|
|
|
2016-04-02 11:49:01 +02:00
|
|
|
cmd->fn(parc, parv);
|
2016-01-06 11:41:57 +01:00
|
|
|
}
|
2016-04-02 12:05:28 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
iwarn("authd sent us a bad command type: %c", *parv[0]);
|
|
|
|
restart_authd();
|
|
|
|
continue;
|
|
|
|
}
|
2016-01-06 11:41:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-15 10:17:35 +02:00
|
|
|
init_authd(void)
|
2016-01-06 11:41:57 +01:00
|
|
|
{
|
|
|
|
if(start_authd())
|
|
|
|
{
|
2016-03-29 02:06:31 +02:00
|
|
|
ierror("Unable to start authd helper: %s", strerror(errno));
|
2016-01-06 11:41:57 +01:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-28 09:11:16 +02:00
|
|
|
void
|
2016-08-15 10:17:35 +02:00
|
|
|
configure_authd(void)
|
2016-03-28 09:11:16 +02:00
|
|
|
{
|
2016-04-12 16:33:51 +02:00
|
|
|
/* Timeouts */
|
2016-03-28 09:11:16 +02:00
|
|
|
set_authd_timeout("ident_timeout", GlobalSetOptions.ident_timeout);
|
|
|
|
set_authd_timeout("rdns_timeout", ConfigFileEntry.connect_timeout);
|
2016-03-28 23:47:51 +02:00
|
|
|
set_authd_timeout("rbl_timeout", ConfigFileEntry.connect_timeout);
|
2016-04-12 16:33:51 +02:00
|
|
|
|
2016-03-28 23:47:51 +02:00
|
|
|
ident_check_enable(!ConfigFileEntry.disable_auth);
|
2016-04-12 16:33:51 +02:00
|
|
|
|
|
|
|
/* Configure OPM */
|
|
|
|
if(rb_dlink_list_length(&opm_list) > 0 &&
|
|
|
|
(opm_listeners[LISTEN_IPV4].ipaddr[0] != '\0' ||
|
|
|
|
opm_listeners[LISTEN_IPV6].ipaddr[0] != '\0'))
|
|
|
|
{
|
|
|
|
rb_dlink_node *ptr;
|
|
|
|
|
|
|
|
if(opm_listeners[LISTEN_IPV4].ipaddr[0] != '\0')
|
|
|
|
rb_helper_write(authd_helper, "O opm_listener %s %hu",
|
|
|
|
opm_listeners[LISTEN_IPV4].ipaddr, opm_listeners[LISTEN_IPV4].port);
|
|
|
|
|
|
|
|
#ifdef RB_IPV6
|
|
|
|
if(opm_listeners[LISTEN_IPV6].ipaddr[0] != '\0')
|
|
|
|
rb_helper_write(authd_helper, "O opm_listener %s %hu",
|
|
|
|
opm_listeners[LISTEN_IPV6].ipaddr, opm_listeners[LISTEN_IPV6].port);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
RB_DLINK_FOREACH(ptr, opm_list.head)
|
|
|
|
{
|
2016-07-13 07:17:21 +02:00
|
|
|
struct OPMScanner *scanner = (OPMScanner *)ptr->data;
|
2016-04-12 16:33:51 +02:00
|
|
|
rb_helper_write(authd_helper, "O opm_scanner %s %hu",
|
|
|
|
scanner->type, scanner->port);
|
|
|
|
}
|
|
|
|
|
|
|
|
opm_check_enable(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
opm_check_enable(false);
|
2016-03-28 09:11:16 +02:00
|
|
|
}
|
|
|
|
|
2016-04-30 08:11:08 +02:00
|
|
|
static void
|
2016-08-22 03:57:43 +02:00
|
|
|
authd_free_client(client::client *client_p)
|
2016-04-30 08:11:08 +02:00
|
|
|
{
|
|
|
|
if(client_p == NULL || client_p->preClient == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(client_p->preClient->auth.cid == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(authd_helper != NULL)
|
|
|
|
rb_helper_write(authd_helper, "E %x", client_p->preClient->auth.cid);
|
|
|
|
|
|
|
|
client_p->preClient->auth.accepted = true;
|
|
|
|
client_p->preClient->auth.cid = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
authd_free_client_cb(rb_dictionary_element *delem, void *unused)
|
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *client_p = (client::client *)delem->data;
|
2016-04-30 08:11:08 +02:00
|
|
|
authd_free_client(client_p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
authd_abort_client(client::client *client_p)
|
2016-04-30 08:11:08 +02:00
|
|
|
{
|
|
|
|
rb_dictionary_delete(cid_clients, RB_UINT_TO_POINTER(client_p->preClient->auth.cid));
|
|
|
|
authd_free_client(client_p);
|
|
|
|
}
|
|
|
|
|
2016-01-06 11:41:57 +01:00
|
|
|
static void
|
|
|
|
restart_authd_cb(rb_helper * helper)
|
|
|
|
{
|
2016-04-01 09:27:48 +02:00
|
|
|
rb_dictionary_iter iter;
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *client_p;
|
2016-04-01 09:27:48 +02:00
|
|
|
|
2016-03-29 02:06:31 +02:00
|
|
|
iwarn("authd: restart_authd_cb called, authd died?");
|
2016-08-26 13:50:12 +02:00
|
|
|
sendto_realops_snomask(sno::GENERAL, L_ALL, "authd: restart_authd_cb called, authd died?");
|
2016-04-01 09:27:48 +02:00
|
|
|
|
2016-01-06 11:41:57 +01:00
|
|
|
if(helper != NULL)
|
|
|
|
{
|
|
|
|
rb_helper_close(helper);
|
|
|
|
authd_helper = NULL;
|
|
|
|
}
|
2016-04-01 09:27:48 +02:00
|
|
|
|
2016-04-30 08:11:08 +02:00
|
|
|
rb_dictionary_destroy(cid_clients, authd_free_client_cb, NULL);
|
|
|
|
cid_clients = NULL;
|
2016-04-01 09:27:48 +02:00
|
|
|
|
2016-01-06 11:41:57 +01:00
|
|
|
start_authd();
|
2016-04-03 03:31:32 +02:00
|
|
|
configure_authd();
|
2016-01-06 11:41:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-15 10:17:35 +02:00
|
|
|
restart_authd(void)
|
2016-01-06 11:41:57 +01:00
|
|
|
{
|
2016-04-03 05:30:54 +02:00
|
|
|
ierror("authd restarting...");
|
2016-01-06 11:41:57 +01:00
|
|
|
restart_authd_cb(authd_helper);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-15 10:17:35 +02:00
|
|
|
rehash_authd(void)
|
2016-01-06 11:41:57 +01:00
|
|
|
{
|
|
|
|
rb_helper_write(authd_helper, "R");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-15 10:17:35 +02:00
|
|
|
check_authd(void)
|
2016-01-06 11:41:57 +01:00
|
|
|
{
|
|
|
|
if(authd_helper == NULL)
|
|
|
|
restart_authd();
|
|
|
|
}
|
2016-03-28 09:11:16 +02:00
|
|
|
|
|
|
|
static inline uint32_t
|
|
|
|
generate_cid(void)
|
|
|
|
{
|
|
|
|
if(++cid == 0)
|
|
|
|
cid = 1;
|
|
|
|
|
|
|
|
return cid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Basically when this is called we begin handing off the client to authd for
|
|
|
|
* processing. authd "owns" the client until processing is finished, or we
|
|
|
|
* timeout from authd. authd will make a decision whether or not to accept the
|
|
|
|
* client, but it's up to other parts of the code (for now) to decide if we're
|
|
|
|
* gonna accept the client and ignore authd's suggestion.
|
|
|
|
*
|
|
|
|
* --Elizafox
|
2016-04-25 22:35:58 +02:00
|
|
|
*
|
|
|
|
* If this is an SSL connection we must defer handing off the client for
|
|
|
|
* reading until it is open and we have the certificate fingerprint, otherwise
|
|
|
|
* it's possible for the client to immediately send data before authd completes
|
|
|
|
* and before the status of the connection is communicated via ssld. This data
|
|
|
|
* could then be processed too early by read_packet().
|
2016-03-28 09:11:16 +02:00
|
|
|
*/
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
authd_initiate_client(client::client *client_p, bool defer)
|
2016-03-28 09:11:16 +02:00
|
|
|
{
|
|
|
|
char client_ipaddr[HOSTIPLEN+1];
|
|
|
|
char listen_ipaddr[HOSTIPLEN+1];
|
|
|
|
uint16_t client_port, listen_port;
|
|
|
|
uint32_t authd_cid;
|
|
|
|
|
2016-04-10 16:20:51 +02:00
|
|
|
if(client_p->preClient == NULL || client_p->preClient->auth.cid != 0)
|
2016-03-28 09:11:16 +02:00
|
|
|
return;
|
|
|
|
|
2016-04-10 16:20:51 +02:00
|
|
|
authd_cid = client_p->preClient->auth.cid = generate_cid();
|
2016-03-28 09:11:16 +02:00
|
|
|
|
|
|
|
/* Collisions are extremely unlikely, so disregard the possibility */
|
2016-03-28 23:47:51 +02:00
|
|
|
rb_dictionary_add(cid_clients, RB_UINT_TO_POINTER(authd_cid), client_p);
|
2016-03-28 09:11:16 +02:00
|
|
|
|
|
|
|
/* Retrieve listener and client IP's */
|
|
|
|
rb_inet_ntop_sock((struct sockaddr *)&client_p->preClient->lip, listen_ipaddr, sizeof(listen_ipaddr));
|
|
|
|
rb_inet_ntop_sock((struct sockaddr *)&client_p->localClient->ip, client_ipaddr, sizeof(client_ipaddr));
|
|
|
|
|
|
|
|
/* Retrieve listener and client ports */
|
2016-03-31 10:00:29 +02:00
|
|
|
listen_port = ntohs(GET_SS_PORT(&client_p->preClient->lip));
|
|
|
|
client_port = ntohs(GET_SS_PORT(&client_p->localClient->ip));
|
2016-03-28 09:11:16 +02:00
|
|
|
|
2016-04-25 22:35:58 +02:00
|
|
|
if(defer)
|
|
|
|
client_p->preClient->auth.flags |= AUTHC_F_DEFERRED;
|
|
|
|
|
2016-03-28 09:32:05 +02:00
|
|
|
/* Add a bit of a fudge factor... */
|
2016-04-10 16:20:51 +02:00
|
|
|
client_p->preClient->auth.timeout = rb_current_time() + ConfigFileEntry.connect_timeout + 10;
|
2016-03-28 09:11:16 +02:00
|
|
|
|
|
|
|
rb_helper_write(authd_helper, "C %x %s %hu %s %hu", authd_cid, listen_ipaddr, listen_port, client_ipaddr, client_port);
|
|
|
|
}
|
|
|
|
|
2016-04-25 22:35:58 +02:00
|
|
|
static inline void
|
2016-08-22 03:57:43 +02:00
|
|
|
authd_read_client(client::client *client_p)
|
2016-04-25 22:35:58 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* When a client has auth'ed, we want to start reading what it sends
|
|
|
|
* us. This is what read_packet() does.
|
|
|
|
* -- adrian
|
|
|
|
*
|
|
|
|
* Above comment was originally in s_auth.c, but moved here with below code.
|
|
|
|
* --Elizafox
|
|
|
|
*/
|
|
|
|
rb_dlinkAddTail(client_p, &client_p->node, &global_client_list);
|
|
|
|
read_packet(client_p->localClient->F, client_p);
|
|
|
|
}
|
|
|
|
|
2016-03-28 09:11:16 +02:00
|
|
|
/* When this is called we have a decision on client acceptance.
|
|
|
|
*
|
2016-04-25 22:35:58 +02:00
|
|
|
* After this point authd no longer "owns" the client, but if
|
|
|
|
* it's flagged as deferred then we're still waiting for a call
|
|
|
|
* to authd_deferred_client().
|
2016-03-28 09:11:16 +02:00
|
|
|
*/
|
2016-04-02 08:05:21 +02:00
|
|
|
static inline void
|
2016-08-22 03:57:43 +02:00
|
|
|
authd_decide_client(client::client *client_p, const char *ident, const char *host, bool accept, char cause, const char *data, const char *reason)
|
2016-03-28 09:11:16 +02:00
|
|
|
{
|
2016-04-10 16:20:51 +02:00
|
|
|
if(client_p->preClient == NULL || client_p->preClient->auth.cid == 0)
|
2016-03-28 09:11:16 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
if(*ident != '*')
|
|
|
|
{
|
|
|
|
rb_strlcpy(client_p->username, ident, sizeof(client_p->username));
|
2016-08-23 04:33:36 +02:00
|
|
|
set_got_id(*client_p);
|
2016-04-01 09:43:01 +02:00
|
|
|
ServerStats.is_asuc++;
|
2016-03-28 09:11:16 +02:00
|
|
|
}
|
|
|
|
else
|
2016-04-01 09:43:01 +02:00
|
|
|
ServerStats.is_abad++; /* s_auth used to do this, stay compatible */
|
2016-03-28 09:11:16 +02:00
|
|
|
|
|
|
|
if(*host != '*')
|
|
|
|
rb_strlcpy(client_p->host, host, sizeof(client_p->host));
|
|
|
|
|
2016-04-10 16:20:51 +02:00
|
|
|
rb_dictionary_delete(cid_clients, RB_UINT_TO_POINTER(client_p->preClient->auth.cid));
|
2016-04-02 10:46:31 +02:00
|
|
|
|
2016-04-10 16:20:51 +02:00
|
|
|
client_p->preClient->auth.accepted = accept;
|
|
|
|
client_p->preClient->auth.cause = cause;
|
|
|
|
client_p->preClient->auth.data = (data == NULL ? NULL : rb_strdup(data));
|
|
|
|
client_p->preClient->auth.reason = (reason == NULL ? NULL : rb_strdup(reason));
|
|
|
|
client_p->preClient->auth.cid = 0;
|
2016-03-28 09:11:16 +02:00
|
|
|
|
2016-04-25 22:35:58 +02:00
|
|
|
client_p->preClient->auth.flags |= AUTHC_F_COMPLETE;
|
|
|
|
if((client_p->preClient->auth.flags & AUTHC_F_DEFERRED) == 0)
|
|
|
|
authd_read_client(client_p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
authd_deferred_client(client::client *client_p)
|
2016-04-25 22:35:58 +02:00
|
|
|
{
|
|
|
|
client_p->preClient->auth.flags &= ~AUTHC_F_DEFERRED;
|
|
|
|
if(client_p->preClient->auth.flags & AUTHC_F_COMPLETE)
|
|
|
|
authd_read_client(client_p);
|
2016-03-28 09:11:16 +02:00
|
|
|
}
|
|
|
|
|
2016-04-02 08:05:21 +02:00
|
|
|
/* Convenience function to accept client */
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
authd_accept_client(client::client *client_p, const char *ident, const char *host)
|
2016-04-02 08:05:21 +02:00
|
|
|
{
|
|
|
|
authd_decide_client(client_p, ident, host, true, '\0', NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convenience function to reject client */
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
authd_reject_client(client::client *client_p, const char *ident, const char *host, char cause, const char *data, const char *reason)
|
2016-04-02 08:05:21 +02:00
|
|
|
{
|
|
|
|
authd_decide_client(client_p, ident, host, false, cause, data, reason);
|
|
|
|
}
|
|
|
|
|
2016-03-28 09:30:54 +02:00
|
|
|
static void
|
2016-08-15 06:54:32 +02:00
|
|
|
timeout_dead_authd_clients(void *notused)
|
2016-03-28 09:30:54 +02:00
|
|
|
{
|
|
|
|
rb_dictionary_iter iter;
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *client_p;
|
2016-04-30 08:11:08 +02:00
|
|
|
rb_dlink_list freelist = { NULL, NULL, 0 };
|
|
|
|
rb_dlink_node *ptr, *nptr;
|
2016-03-28 09:30:54 +02:00
|
|
|
|
2016-07-13 07:17:21 +02:00
|
|
|
void *elem;
|
|
|
|
RB_DICTIONARY_FOREACH(elem, &iter, cid_clients)
|
2016-03-28 09:30:54 +02:00
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
client_p = (client::client *)elem;
|
2016-04-10 16:20:51 +02:00
|
|
|
if(client_p->preClient->auth.timeout < rb_current_time())
|
2016-04-30 08:11:08 +02:00
|
|
|
{
|
|
|
|
authd_free_client(client_p);
|
|
|
|
rb_dlinkAddAlloc(client_p, &freelist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RB_DICTIONARY_FOREACH is not safe for deletion, so we do this crap */
|
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, nptr, freelist.head)
|
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
client_p = (client::client *)ptr->data;
|
2016-04-30 08:11:08 +02:00
|
|
|
rb_dictionary_delete(cid_clients, RB_UINT_TO_POINTER(client_p->preClient->auth.cid));
|
2016-03-28 09:30:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-28 09:11:16 +02:00
|
|
|
/* Send a new blacklist to authd */
|
|
|
|
void
|
2016-08-15 10:17:35 +02:00
|
|
|
add_blacklist(const char *host, const char *reason, uint8_t iptype, rb_dlink_list *filters)
|
2016-03-28 09:11:16 +02:00
|
|
|
{
|
|
|
|
rb_dlink_node *ptr;
|
2016-07-13 07:17:21 +02:00
|
|
|
struct BlacklistStats *stats = (BlacklistStats *)rb_malloc(sizeof(struct BlacklistStats));
|
2016-03-28 23:47:51 +02:00
|
|
|
char filterbuf[BUFSIZE] = "*";
|
2016-03-28 09:11:16 +02:00
|
|
|
size_t s = 0;
|
|
|
|
|
2016-04-30 08:11:08 +02:00
|
|
|
if(bl_stats == NULL)
|
2016-07-13 07:17:21 +02:00
|
|
|
bl_stats = rb_dictionary_create("blacklist statistics", reinterpret_cast<int (*)(const void *, const void *)>(rb_strcasecmp));
|
2016-04-30 08:11:08 +02:00
|
|
|
|
2016-03-28 09:11:16 +02:00
|
|
|
/* Build a list of comma-separated values for authd.
|
|
|
|
* We don't check for validity - do it elsewhere.
|
|
|
|
*/
|
|
|
|
RB_DLINK_FOREACH(ptr, filters->head)
|
|
|
|
{
|
2016-07-13 07:17:21 +02:00
|
|
|
char *filter = (char *)ptr->data;
|
2016-03-28 09:11:16 +02:00
|
|
|
size_t filterlen = strlen(filter) + 1;
|
|
|
|
|
|
|
|
if(s + filterlen > sizeof(filterbuf))
|
|
|
|
break;
|
|
|
|
|
|
|
|
snprintf(&filterbuf[s], sizeof(filterbuf) - s, "%s,", filter);
|
|
|
|
|
|
|
|
s += filterlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(s)
|
|
|
|
filterbuf[s - 1] = '\0';
|
|
|
|
|
2016-04-12 16:43:50 +02:00
|
|
|
stats->host = rb_strdup(host);
|
2016-03-28 09:11:16 +02:00
|
|
|
stats->iptype = iptype;
|
|
|
|
stats->hits = 0;
|
2016-06-25 04:29:02 +02:00
|
|
|
rb_dictionary_add(bl_stats, stats->host, stats);
|
2016-03-28 09:11:16 +02:00
|
|
|
|
|
|
|
rb_helper_write(authd_helper, "O rbl %s %hhu %s :%s", host, iptype, filterbuf, reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete a blacklist */
|
|
|
|
void
|
2016-08-15 10:17:35 +02:00
|
|
|
del_blacklist(const char *host)
|
2016-03-28 09:11:16 +02:00
|
|
|
{
|
2016-07-13 07:17:21 +02:00
|
|
|
struct BlacklistStats *stats = (BlacklistStats *)rb_dictionary_retrieve(bl_stats, host);
|
2016-04-12 16:33:51 +02:00
|
|
|
if(stats != NULL)
|
|
|
|
{
|
2016-06-25 04:29:02 +02:00
|
|
|
rb_dictionary_delete(bl_stats, host);
|
2016-04-12 16:43:50 +02:00
|
|
|
rb_free(stats->host);
|
2016-04-12 16:33:51 +02:00
|
|
|
rb_free(stats);
|
|
|
|
}
|
2016-03-28 09:11:16 +02:00
|
|
|
|
|
|
|
rb_helper_write(authd_helper, "O rbl_del %s", host);
|
|
|
|
}
|
|
|
|
|
2016-04-30 08:11:08 +02:00
|
|
|
static void
|
|
|
|
blacklist_delete(rb_dictionary_element *delem, void *unused)
|
|
|
|
{
|
2016-07-13 07:17:21 +02:00
|
|
|
struct BlacklistStats *stats = (BlacklistStats *)delem->data;
|
2016-04-30 08:11:08 +02:00
|
|
|
|
|
|
|
rb_free(stats->host);
|
|
|
|
rb_free(stats);
|
|
|
|
}
|
|
|
|
|
2016-03-28 09:11:16 +02:00
|
|
|
/* Delete all the blacklists */
|
|
|
|
void
|
2016-08-15 10:17:35 +02:00
|
|
|
del_blacklist_all(void)
|
2016-03-28 09:11:16 +02:00
|
|
|
{
|
2016-04-30 14:11:06 +02:00
|
|
|
if(bl_stats != NULL)
|
|
|
|
rb_dictionary_destroy(bl_stats, blacklist_delete, NULL);
|
2016-04-30 08:11:08 +02:00
|
|
|
bl_stats = NULL;
|
2016-03-28 09:11:16 +02:00
|
|
|
|
|
|
|
rb_helper_write(authd_helper, "O rbl_del_all");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Adjust an authd timeout value */
|
2016-04-01 09:43:01 +02:00
|
|
|
bool
|
2016-08-15 10:17:35 +02:00
|
|
|
set_authd_timeout(const char *key, int timeout)
|
2016-03-28 09:11:16 +02:00
|
|
|
{
|
2016-04-01 09:43:01 +02:00
|
|
|
if(timeout <= 0)
|
|
|
|
return false;
|
|
|
|
|
2016-03-28 09:11:16 +02:00
|
|
|
rb_helper_write(authd_helper, "O %s %d", key, timeout);
|
2016-04-01 09:43:01 +02:00
|
|
|
return true;
|
2016-03-28 09:11:16 +02:00
|
|
|
}
|
2016-03-28 09:42:20 +02:00
|
|
|
|
2016-04-01 09:43:01 +02:00
|
|
|
/* Enable identd checks */
|
2016-03-28 09:42:20 +02:00
|
|
|
void
|
2016-08-15 10:17:35 +02:00
|
|
|
ident_check_enable(bool enabled)
|
2016-03-28 09:42:20 +02:00
|
|
|
{
|
|
|
|
rb_helper_write(authd_helper, "O ident_enabled %d", enabled ? 1 : 0);
|
|
|
|
}
|
2016-04-01 09:43:01 +02:00
|
|
|
|
2016-04-12 16:33:51 +02:00
|
|
|
/* Create an OPM listener
|
|
|
|
* XXX - This is a big nasty hack, but it avoids resending duplicate data when
|
|
|
|
* configure_authd() is called.
|
|
|
|
*/
|
|
|
|
void
|
2016-08-15 10:17:35 +02:00
|
|
|
conf_create_opm_listener(const char *ip, uint16_t port)
|
2016-04-12 16:33:51 +02:00
|
|
|
{
|
|
|
|
char ipbuf[HOSTIPLEN];
|
|
|
|
struct OPMListener *listener;
|
|
|
|
|
|
|
|
rb_strlcpy(ipbuf, ip, sizeof(ipbuf));
|
|
|
|
if(ipbuf[0] == ':')
|
|
|
|
{
|
|
|
|
memmove(ipbuf + 1, ipbuf, sizeof(ipbuf) - 1);
|
|
|
|
ipbuf[0] = '0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* I am much too lazy to use rb_inet_pton and GET_SS_FAMILY for now --Elizafox */
|
|
|
|
listener = &opm_listeners[(strchr(ipbuf, ':') != NULL ? LISTEN_IPV6 : LISTEN_IPV4)];
|
|
|
|
rb_strlcpy(listener->ipaddr, ipbuf, sizeof(listener->ipaddr));
|
|
|
|
listener->port = port;
|
|
|
|
}
|
|
|
|
|
2016-04-02 08:05:21 +02:00
|
|
|
void
|
2016-08-15 10:17:35 +02:00
|
|
|
create_opm_listener(const char *ip, uint16_t port)
|
2016-04-01 09:43:01 +02:00
|
|
|
{
|
2016-04-03 02:28:19 +02:00
|
|
|
char ipbuf[HOSTIPLEN];
|
2016-04-12 16:33:51 +02:00
|
|
|
|
|
|
|
/* XXX duplicated in conf_create_opm_listener */
|
2016-04-03 02:28:19 +02:00
|
|
|
rb_strlcpy(ipbuf, ip, sizeof(ipbuf));
|
|
|
|
if(ipbuf[0] == ':')
|
|
|
|
{
|
|
|
|
memmove(ipbuf + 1, ipbuf, sizeof(ipbuf) - 1);
|
|
|
|
ipbuf[0] = '0';
|
|
|
|
}
|
|
|
|
|
2016-04-12 16:33:51 +02:00
|
|
|
conf_create_opm_listener(ip, port);
|
2016-04-12 16:37:56 +02:00
|
|
|
rb_helper_write(authd_helper, "O opm_listener %s %hu", ipbuf, port);
|
2016-04-12 16:33:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-15 10:17:35 +02:00
|
|
|
delete_opm_listener_all(void)
|
2016-04-12 16:33:51 +02:00
|
|
|
{
|
|
|
|
memset(&opm_listeners, 0, sizeof(opm_listeners));
|
|
|
|
rb_helper_write(authd_helper, "O opm_listener_del_all");
|
2016-04-02 08:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable all OPM scans */
|
|
|
|
void
|
2016-08-15 10:17:35 +02:00
|
|
|
opm_check_enable(bool enabled)
|
2016-04-02 08:05:21 +02:00
|
|
|
{
|
2016-04-03 02:45:27 +02:00
|
|
|
rb_helper_write(authd_helper, "O opm_enabled %d", enabled ? 1 : 0);
|
2016-04-02 08:05:21 +02:00
|
|
|
}
|
|
|
|
|
2016-04-12 16:33:51 +02:00
|
|
|
/* Create an OPM proxy scanner
|
|
|
|
* XXX - This is a big nasty hack, but it avoids resending duplicate data when
|
|
|
|
* configure_authd() is called.
|
|
|
|
*/
|
|
|
|
void
|
2016-08-15 10:17:35 +02:00
|
|
|
conf_create_opm_proxy_scanner(const char *type, uint16_t port)
|
2016-04-12 16:33:51 +02:00
|
|
|
{
|
2016-07-13 07:17:21 +02:00
|
|
|
struct OPMScanner *scanner = (OPMScanner *)rb_malloc(sizeof(struct OPMScanner));
|
2016-04-12 16:33:51 +02:00
|
|
|
|
|
|
|
rb_strlcpy(scanner->type, type, sizeof(scanner->type));
|
|
|
|
scanner->port = port;
|
|
|
|
rb_dlinkAdd(scanner, &scanner->node, &opm_list);
|
|
|
|
}
|
|
|
|
|
2016-04-02 08:05:21 +02:00
|
|
|
void
|
2016-08-15 10:17:35 +02:00
|
|
|
create_opm_proxy_scanner(const char *type, uint16_t port)
|
2016-04-02 08:05:21 +02:00
|
|
|
{
|
2016-04-12 16:33:51 +02:00
|
|
|
conf_create_opm_proxy_scanner(type, port);
|
2016-04-02 09:29:48 +02:00
|
|
|
rb_helper_write(authd_helper, "O opm_scanner %s %hu", type, port);
|
2016-04-01 09:43:01 +02:00
|
|
|
}
|
2016-04-03 02:45:27 +02:00
|
|
|
|
|
|
|
void
|
2016-08-15 10:17:35 +02:00
|
|
|
delete_opm_proxy_scanner(const char *type, uint16_t port)
|
2016-04-03 02:45:27 +02:00
|
|
|
{
|
2016-04-12 16:33:51 +02:00
|
|
|
rb_dlink_node *ptr, *nptr;
|
|
|
|
|
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, nptr, opm_list.head)
|
|
|
|
{
|
2016-07-13 07:17:21 +02:00
|
|
|
struct OPMScanner *scanner = (OPMScanner *)ptr->data;
|
2016-04-12 16:33:51 +02:00
|
|
|
|
|
|
|
if(rb_strncasecmp(scanner->type, type, sizeof(scanner->type)) == 0 &&
|
|
|
|
scanner->port == port)
|
|
|
|
{
|
|
|
|
rb_dlinkDelete(ptr, &opm_list);
|
|
|
|
rb_free(scanner);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-03 02:45:27 +02:00
|
|
|
rb_helper_write(authd_helper, "O opm_scanner_del %s %hu", type, port);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-15 10:17:35 +02:00
|
|
|
delete_opm_proxy_scanner_all(void)
|
2016-04-03 02:45:27 +02:00
|
|
|
{
|
2016-04-12 16:33:51 +02:00
|
|
|
rb_dlink_node *ptr, *nptr;
|
|
|
|
|
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, nptr, opm_list.head)
|
|
|
|
{
|
2016-07-13 07:17:21 +02:00
|
|
|
struct OPMScanner *scanner = (OPMScanner *)ptr->data;
|
2016-04-12 16:33:51 +02:00
|
|
|
|
|
|
|
rb_dlinkDelete(ptr, &opm_list);
|
|
|
|
rb_free(scanner);
|
|
|
|
}
|
|
|
|
|
2016-04-03 02:45:27 +02:00
|
|
|
rb_helper_write(authd_helper, "O opm_scanner_del_all");
|
|
|
|
}
|
2016-08-15 10:17:35 +02:00
|
|
|
|
|
|
|
} // namespace ircd
|