return 0;
}
+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;
+}
+
+static inline struct Client *
+cid_to_client(uint32_t cid, bool delete)
+{
+ struct Client *client_p;
+
+ if(delete)
+ client_p = rb_dictionary_delete(cid_clients, RB_UINT_TO_POINTER(cid));
+ else
+ client_p = rb_dictionary_retrieve(cid_clients, RB_UINT_TO_POINTER(cid));
+
+ if(client_p == NULL)
+ {
+ iwarn("authd sent us back a bad client ID: %ux", cid);
+ restart_authd();
+ return NULL;
+ }
+
+ return client_p;
+}
+
static void
parse_authd_reply(rb_helper * helper)
{
int parc;
char authdBuf[READBUF_SIZE];
char *parv[MAXPARA + 1];
- long lcid;
uint32_t cid;
struct Client *client_p;
return;
}
- if((lcid = strtol(parv[1], NULL, 16)) > UINT32_MAX || lcid < 0)
- {
- iwarn("authd sent us back a bad client ID: %ld", lcid);
- restart_authd();
+ if((cid = str_to_cid(parv[1])) == 0)
return;
- }
-
- cid = (uint32_t)lcid;
/* cid to uid (retrieve and delete) */
- if((client_p = rb_dictionary_delete(cid_clients, RB_UINT_TO_POINTER(cid))) == NULL)
- {
- iwarn("authd sent us back an unknown client ID %x", cid);
- restart_authd();
+ if((client_p = cid_to_client(cid, true)) == NULL)
return;
- }
- authd_decide_client(client_p, parv[2], parv[3], true, '\0', NULL, NULL);
+ authd_accept_client(client_p, parv[2], parv[3]);
break;
case 'R': /* Reject client */
if(parc != 7)
return;
}
- if((lcid = strtol(parv[1], NULL, 16)) > UINT32_MAX || lcid < 0)
- {
- iwarn("authd sent us back a bad client ID %ld", lcid);
- restart_authd();
+ if((cid = str_to_cid(parv[1])) == 0)
return;
- }
-
- cid = (uint32_t)lcid;
/* cid to uid (retrieve and delete) */
- if((client_p = rb_dictionary_delete(cid_clients, RB_UINT_TO_POINTER(cid))) == NULL)
- {
- iwarn("authd sent us back an unknown client ID %x", cid);
- restart_authd();
+ if((client_p = cid_to_client(cid, true)) == NULL)
return;
- }
- authd_decide_client(client_p, parv[3], parv[4], false, toupper(*parv[2]), parv[5], parv[6]);
+ authd_reject_client(client_p, parv[3], parv[4], toupper(*parv[2]), parv[5], parv[6]);
break;
case 'N': /* Notice to client */
if(parc != 3)
return;
}
- if((lcid = strtol(parv[1], NULL, 16)) > UINT32_MAX || lcid < 0)
- {
- iwarn("authd sent us back a bad client ID %ld", lcid);
- restart_authd();
+ if((cid = str_to_cid(parv[1])) == 0)
return;
- }
-
- cid = (uint32_t)lcid;
/* cid to uid */
- if((client_p = rb_dictionary_retrieve(cid_clients, RB_UINT_TO_POINTER(cid))) == NULL)
- {
- iwarn("authd sent us back an unknown client ID %x", cid);
- restart_authd();
+ if((client_p = cid_to_client(cid, false)) == NULL)
return;
- }
sendto_one_notice(client_p, ":%s", parv[2]);
break;
*
* After this point authd no longer "owns" the client.
*/
-void
+static inline void
authd_decide_client(struct Client *client_p, const char *ident, const char *host, bool accept, char cause, const char *data, const char *reason)
{
if(client_p->preClient == NULL || client_p->preClient->authd_cid == 0)
read_packet(client_p->localClient->F, client_p);
}
+/* Convenience function to accept client */
+void
+authd_accept_client(struct Client *client_p, const char *ident, const char *host)
+{
+ authd_decide_client(client_p, ident, host, true, '\0', NULL, NULL);
+}
+
+/* Convenience function to reject client */
+void
+authd_reject_client(struct Client *client_p, const char *ident, const char *host, char cause, const char *data, const char *reason)
+{
+ authd_decide_client(client_p, ident, host, false, cause, data, reason);
+}
+
void
authd_abort_client(struct Client *client_p)
{
rb_helper_write(authd_helper, "E %x", client_p->preClient->authd_cid);
/* XXX should we blindly allow like this? */
- authd_decide_client(client_p, "*", "*", true, '\0', NULL, NULL);
+ authd_accept_client(client_p, "*", "*");
client_p->preClient->authd_cid = 0;
}
}
/* Create an OPM listener */
-bool
-create_opm_listener(struct rb_sockaddr_storage *addr)
+void
+create_opm_listener(const char *ip, uint16_t port)
{
- char addrbuf[HOSTIPLEN];
-
- if(!rb_inet_ntop_sock((struct sockaddr *)addr, addrbuf, sizeof(addrbuf)))
- return false;
+ rb_helper_write(authd_helper, "O opm_listener %s %hu", ip, port);
+}
- if(addrbuf[0] == ':')
- {
- /* Reformat for authd sending */
- memmove(addrbuf + 1, addrbuf, sizeof(addrbuf) - 1);
- addrbuf[0] = '0';
- }
+/* Disable all OPM scans */
+void
+opm_check_enable(bool enabled)
+{
+ rb_helper_write(authd_helper, "O opm_enable %d", enabled ? 1 : 0);
+}
- rb_helper_write(authd_helper, "O opm_listener %s %hu", addrbuf, ntohs(GET_SS_PORT(addr)));
- return true;
+/* Create an OPM proxy scan */
+void
+create_opm_proxy_scan(const char *scan, uint16_t port)
+{
+ rb_helper_write(authd_helper, "O opm_scanner %s %hu", scan, port);
}