]>
jfr.im git - solanum.git/blob - ircd/authd.c
2 * authd.c: An interface to authd.
3 * (based somewhat on ircd-ratbox dns.c)
5 * Copyright (C) 2005 Aaron Sethman <androsyn@ratbox.org>
6 * Copyright (C) 2005-2012 ircd-ratbox development team
7 * Copyright (C) 2016 William Pitcock <nenolod@dereferenced.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
26 #include <ratbox_lib.h>
28 #include <ircd_defs.h>
40 static int start_authd(void);
41 static void parse_authd_reply(rb_helper
* helper
);
42 static void restart_authd_cb(rb_helper
* helper
);
44 rb_helper
*authd_helper
;
45 static char *authd_path
;
50 char fullpath
[PATH_MAX
+ 1];
52 const char *suffix
= ".exe";
54 const char *suffix
= "";
56 if(authd_path
== NULL
)
58 snprintf(fullpath
, sizeof(fullpath
), "%s/authd%s", PKGLIBEXECDIR
, suffix
);
60 if(access(fullpath
, X_OK
) == -1)
62 snprintf(fullpath
, sizeof(fullpath
), "%s/libexec/charybdis/authd%s",
63 ConfigFileEntry
.dpath
, suffix
);
64 if(access(fullpath
, X_OK
) == -1)
67 "Unable to execute authd in %s or %s/libexec/charybdis",
68 PKGLIBEXECDIR
, ConfigFileEntry
.dpath
);
69 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
70 "Unable to execute authd in %s or %s/libexec/charybdis",
71 PKGLIBEXECDIR
, ConfigFileEntry
.dpath
);
77 authd_path
= rb_strdup(fullpath
);
80 authd_helper
= rb_helper_start("authd", authd_path
, parse_authd_reply
, restart_authd_cb
);
82 if(authd_helper
== NULL
)
84 ilog(L_MAIN
, "Unable to start authd helper: %s", strerror(errno
));
85 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Unable to start authd helper: %s", strerror(errno
));
88 ilog(L_MAIN
, "authd helper started");
89 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "authd helper started");
90 rb_helper_run(authd_helper
);
95 parse_authd_reply(rb_helper
* helper
)
99 char dnsBuf
[READBUF_SIZE
];
101 char *parv
[MAXPARA
+ 1];
102 while((len
= rb_helper_read(helper
, dnsBuf
, sizeof(dnsBuf
))) > 0)
104 parc
= rb_string_to_array(dnsBuf
, parv
, MAXPARA
+1);
111 ilog(L_MAIN
, "authd sent a result with wrong number of arguments: got %d", parc
);
115 dns_results_callback(parv
[1], parv
[2], parv
[3], parv
[4]);
128 ilog(L_MAIN
, "Unable to start authd helper: %s", strerror(errno
));
134 restart_authd_cb(rb_helper
* helper
)
136 ilog(L_MAIN
, "authd: restart_authd_cb called, authd died?");
137 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "authd: restart_authd_cb called, authd died?");
140 rb_helper_close(helper
);
149 restart_authd_cb(authd_helper
);
155 rb_helper_write(authd_helper
, "R");
161 if(authd_helper
== NULL
)