]>
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
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%cauthd%s", ircd_paths
[IRCD_PATH_LIBEXEC
], RB_PATH_SEPARATOR
, suffix
);
60 if(access(fullpath
, X_OK
) == -1)
62 snprintf(fullpath
, sizeof(fullpath
), "%s%cbin%cauthd%s",
63 ConfigFileEntry
.dpath
, RB_PATH_SEPARATOR
, RB_PATH_SEPARATOR
, suffix
);
64 if(access(fullpath
, X_OK
) == -1)
67 "Unable to execute authd in %s or %s/bin",
68 ircd_paths
[IRCD_PATH_LIBEXEC
], ConfigFileEntry
.dpath
);
69 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
70 "Unable to execute authd in %s or %s/bin",
71 ircd_paths
[IRCD_PATH_LIBEXEC
], 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
];
100 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]);
122 ilog(L_MAIN
, "authd sent a result with wrong number of arguments: got %d", parc
);
131 /* parv[0] conveys status */
134 ilog(L_MAIN
, "authd sent a result with wrong number of arguments: got %d", parc
);
138 dns_stats_results_callback(parv
[1], parv
[0], parc
- 3, (const char **)&parv
[3]);
155 ilog(L_MAIN
, "Unable to start authd helper: %s", strerror(errno
));
161 restart_authd_cb(rb_helper
* helper
)
163 ilog(L_MAIN
, "authd: restart_authd_cb called, authd died?");
164 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "authd: restart_authd_cb called, authd died?");
167 rb_helper_close(helper
);
176 restart_authd_cb(authd_helper
);
182 rb_helper_write(authd_helper
, "R");
188 if(authd_helper
== NULL
)