+ if (IsUserPort(auth->client))
+ sendheader(auth->client, REPORT_FAIL_ID);
+ return;
+ }
+ if (IsUserPort(auth->client))
+ sendheader(auth->client, REPORT_DO_ID);
+
+ if ((result = os_connect_nonb(fd, &remote_addr)) == IO_FAILURE ||
+ !socket_add(&auth->socket, auth_sock_callback, (void*) auth,
+ result == IO_SUCCESS ? SS_CONNECTED : SS_CONNECTING,
+ SOCK_EVENT_READABLE, fd)) {
+ ++ServerStats->is_abad;
+ if (IsUserPort(auth->client))
+ sendheader(auth->client, REPORT_FAIL_ID);
+ close(fd);
+ return;
+ }
+
+ FlagSet(&auth->flags, AR_AUTH_PENDING);
+ if (result == IO_SUCCESS)
+ send_auth_query(auth);
+}
+
+/** Initiate DNS lookup for a client.
+ * @param[in] auth The auth request for which to start the DNS lookup.
+ */
+static void start_dns_query(struct AuthRequest *auth)
+{
+ if (feature_bool(FEAT_NODNS)) {
+ sendto_iauth(auth->client, "d");
+ return;
+ }
+
+ if (irc_in_addr_is_loopback(&cli_ip(auth->client))) {
+ strcpy(cli_sockhost(auth->client), cli_name(&me));
+ sendto_iauth(auth->client, "N %s", cli_sockhost(auth->client));
+ return;
+ }
+
+ if (IsUserPort(auth->client))
+ sendheader(auth->client, REPORT_DO_DNS);
+
+ FlagSet(&auth->flags, AR_DNS_PENDING);
+ gethost_byaddr(&cli_ip(auth->client), auth_dns_callback, auth);
+}
+
+/** Initiate IAuth check for a client.
+ * @param[in] auth The auth request for which to star the IAuth check.
+ */
+static void start_iauth_query(struct AuthRequest *auth)
+{
+ FlagSet(&auth->flags, AR_IAUTH_PENDING);
+ if (!sendto_iauth(auth->client, "C %s %hu %s %hu",
+ cli_sock_ip(auth->client), auth->port,
+ ircd_ntoa(&auth->local.addr), auth->local.port))
+ FlagClr(&auth->flags, AR_IAUTH_PENDING);
+}
+
+/** Starts auth (identd) and dns queries for a client.
+ * @param[in] client The client for which to start queries.
+ */
+void start_auth(struct Client* client)
+{
+ struct irc_sockaddr remote;
+ struct AuthRequest* auth;
+
+ assert(0 != client);
+ Debug((DEBUG_INFO, "Beginning auth request on client %p", client));
+
+ /* Register with event handlers. */
+ cli_lasttime(client) = CurrentTime;
+ cli_since(client) = CurrentTime;
+ if (cli_fd(client) > HighestFd)
+ HighestFd = cli_fd(client);
+ LocalClientArray[cli_fd(client)] = client;
+ socket_events(&(cli_socket(client)), SOCK_ACTION_SET | SOCK_EVENT_READABLE);
+
+ /* Allocate the AuthRequest. */
+ auth = auth_freelist;
+ if (auth)
+ auth_freelist = auth->next;
+ else
+ auth = MyMalloc(sizeof(*auth));
+ assert(0 != auth);
+ memset(auth, 0, sizeof(*auth));
+ auth->client = client;
+ cli_auth(client) = auth;
+ s_fd(&auth->socket) = -1;
+ timer_add(timer_init(&auth->timeout), auth_timeout_callback, (void*) auth,
+ TT_RELATIVE, feature_int(FEAT_AUTH_TIMEOUT));
+
+ /* Try to get socket endpoint addresses. */
+ if (!os_get_sockname(cli_fd(client), &auth->local)
+ || !os_get_peername(cli_fd(client), &remote)) {
+ ++ServerStats->is_abad;
+ if (IsUserPort(auth->client))
+ sendheader(auth->client, REPORT_FAIL_ID);
+ exit_client(auth->client, auth->client, &me, "Socket local/peer lookup failed");
+ return;
+ }
+ auth->port = remote.port;
+
+ /* Try to start DNS lookup. */
+ start_dns_query(auth);
+
+ /* Try to start ident lookup. */
+ start_auth_query(auth);
+
+ /* Set required client inputs for users. */
+ if (IsUserPort(client)) {
+ cli_user(client) = make_user(client);
+ cli_user(client)->server = &me;
+ FlagSet(&auth->flags, AR_NEEDS_USER);
+ FlagSet(&auth->flags, AR_NEEDS_NICK);
+
+ /* Try to start iauth lookup. */
+ start_iauth_query(auth);
+ }
+
+ /* Add client to GlobalClientList. */
+ add_client_to_list(client);
+
+ /* Check which auth events remain pending. */
+ check_auth_finished(auth);
+}
+
+/** Mark that a user has PONGed while unregistered.
+ * @param[in] auth Authorization request for client.
+ * @param[in] cookie PONG cookie value sent by client.
+ * @return Zero if client should be kept, CPTR_KILLED if rejected.
+ */
+int auth_set_pong(struct AuthRequest *auth, unsigned int cookie)
+{
+ assert(auth != NULL);
+ if (!FlagHas(&auth->flags, AR_NEEDS_PONG))
+ return 0;
+ if (cookie != auth->cookie)
+ {
+ send_reply(auth->client, SND_EXPLICIT | ERR_BADPING,
+ ":To connect, type /QUOTE PONG %u", auth->cookie);
+ return 0;
+ }
+ cli_lasttime(auth->client) = CurrentTime;
+ FlagClr(&auth->flags, AR_NEEDS_PONG);
+ return check_auth_finished(auth);
+}
+
+/** Record a user's claimed username and userinfo.
+ * @param[in] auth Authorization request for client.
+ * @param[in] username Client's asserted username.
+ * @param[in] hostname Third argument of USER command (client's
+ * hostname, per RFC 1459).
+ * @param[in] servername Fourth argument of USER command (server's
+ * name, per RFC 1459).
+ * @param[in] userinfo Client's asserted self-description.
+ * @return Zero if client should be kept, CPTR_KILLED if rejected.
+ */
+int auth_set_user(struct AuthRequest *auth, const char *username, const char *hostname, const char *servername, const char *userinfo)
+{
+ struct Client *cptr;
+
+ assert(auth != NULL);
+ if (FlagHas(&auth->flags, AR_IAUTH_HURRY))
+ return 0;
+ FlagClr(&auth->flags, AR_NEEDS_USER);
+ cptr = auth->client;
+ ircd_strncpy(cli_info(cptr), userinfo, REALLEN);
+ ircd_strncpy(cli_user(cptr)->username, username, USERLEN);
+ ircd_strncpy(cli_user(cptr)->host, cli_sockhost(cptr), HOSTLEN);
+ if (IAuthHas(iauth, IAUTH_UNDERNET))
+ sendto_iauth(cptr, "U %s %s %s :%s", username, hostname, servername, userinfo);
+ else if (IAuthHas(iauth, IAUTH_ADDLINFO))
+ sendto_iauth(cptr, "U %s", username);
+ return check_auth_finished(auth);
+}
+
+/** Handle authorization-related aspects of initial nickname selection.
+ * This is called after verifying that the nickname is available.
+ * @param[in] auth Authorization request for client.
+ * @param[in] nickname Client's requested nickname.
+ * @return Zero if client should be kept, CPTR_KILLED if rejected.
+ */
+int auth_set_nick(struct AuthRequest *auth, const char *nickname)
+{
+ assert(auth != NULL);
+ FlagClr(&auth->flags, AR_NEEDS_NICK);
+ /*
+ * If the client hasn't gotten a cookie-ping yet,
+ * choose a cookie and send it. -record!jegelhof@cloud9.net
+ */
+ if (!auth->cookie) {
+ do {
+ auth->cookie = ircrandom();
+ } while (!auth->cookie);
+ sendrawto_one(auth->client, "PING :%u", auth->cookie);
+ FlagSet(&auth->flags, AR_NEEDS_PONG);
+ }
+ if (IAuthHas(iauth, IAUTH_UNDERNET))
+ sendto_iauth(auth->client, "n %s", nickname);
+ return check_auth_finished(auth);
+}
+
+/** Record a user's password.
+ * @param[in] auth Authorization request for client.
+ * @param[in] password Client's password.
+ * @return Zero if client should be kept, CPTR_KILLED if rejected.
+ */
+int auth_set_password(struct AuthRequest *auth, const char *password)
+{
+ assert(auth != NULL);
+ if (IAuthHas(iauth, IAUTH_ADDLINFO))
+ sendto_iauth(auth->client, "P :%s", password);
+ return 0;
+}
+
+/** Send exit notification for \a cptr to iauth.
+ * @param[in] cptr Client who is exiting.
+ */
+void auth_send_exit(struct Client *cptr)
+{
+ sendto_iauth(cptr, "D");
+}
+
+/** Mark that a user has started capabilities negotiation.
+ * This blocks authorization until auth_cap_done() is called.
+ * @param[in] auth Authorization request for client.
+ * @return Zero if client should be kept, CPTR_KILLED if rejected.
+ */
+int auth_cap_start(struct AuthRequest *auth)
+{
+ assert(auth != NULL);
+ FlagSet(&auth->flags, AR_CAP_PENDING);
+ return 0;
+}
+
+/** Mark that a user has completed capabilities negotiation.
+ * This unblocks authorization if auth_cap_start() was called.
+ * @param[in] auth Authorization request for client.
+ * @return Zero if client should be kept, CPTR_KILLED if rejected.
+ */
+int auth_cap_done(struct AuthRequest *auth)
+{
+ assert(auth != NULL);
+ FlagClr(&auth->flags, AR_CAP_PENDING);
+ return check_auth_finished(auth);
+}
+
+/** Attempt to spawn the process for an IAuth instance.
+ * @param[in] iauth IAuth descriptor.
+ * @param[in] automatic If non-zero, apply sanity checks against
+ * excessive automatic restarts.
+ * @return 0 on success, non-zero on failure.
+ */
+int iauth_do_spawn(struct IAuth *iauth, int automatic)
+{
+ pid_t cpid;
+ int s_io[2];
+ int s_err[2];
+ int res;
+
+ if (automatic && CurrentTime - iauth->started < 5)
+ {
+ sendto_opmask_butone(NULL, SNO_AUTH, "IAuth crashed fast, leaving it dead.");
+ return -1;
+ }
+
+ /* Record time we tried to spawn the iauth process. */
+ iauth->started = CurrentTime;
+
+ /* Attempt to allocate a pair of sockets. */
+ res = os_socketpair(s_io);
+ if (res) {
+ res = errno;
+ Debug((DEBUG_INFO, "Unable to create IAuth socketpair: %s", strerror(res)));
+ return res;
+ }
+
+ /* Mark the parent's side of the pair (element 0) as non-blocking. */
+ res = os_set_nonblocking(s_io[0]);
+ if (!res) {
+ res = errno;
+ Debug((DEBUG_INFO, "Unable to make IAuth socket non-blocking: %s", strerror(res)));
+ close(s_io[1]);
+ close(s_io[0]);
+ return res;
+ }
+
+ /* Initialize the socket structure to talk to the child. */
+ res = socket_add(i_socket(iauth), iauth_sock_callback, iauth,
+ SS_CONNECTED, SOCK_EVENT_READABLE, s_io[0]);
+ if (!res) {
+ res = errno;
+ Debug((DEBUG_INFO, "Unable to register IAuth socket: %s", strerror(res)));
+ close(s_io[1]);
+ close(s_io[0]);
+ return res;
+ }
+
+ /* Allocate another pair for stderr. */
+ res = os_socketpair(s_err);
+ if (res) {
+ res = errno;
+ Debug((DEBUG_INFO, "Unable to create IAuth stderr: %s", strerror(res)));
+ socket_del(i_socket(iauth));
+ close(s_io[1]);
+ close(s_io[0]);
+ return res;
+ }
+
+ /* Mark parent side of this pair non-blocking, too. */
+ res = os_set_nonblocking(s_err[0]);
+ if (!res) {
+ res = errno;
+ Debug((DEBUG_INFO, "Unable to make IAuth stderr non-blocking: %s", strerror(res)));
+ close(s_err[1]);
+ close(s_err[0]);
+ socket_del(i_socket(iauth));
+ close(s_io[1]);
+ close(s_io[0]);
+ return res;
+ }
+
+ /* And set up i_stderr(iauth). */
+ res = socket_add(i_stderr(iauth), iauth_stderr_callback, iauth,
+ SS_CONNECTED, SOCK_EVENT_READABLE, s_err[0]);
+ if (!res) {
+ res = errno;
+ Debug((DEBUG_INFO, "Unable to register IAuth stderr: %s", strerror(res)));
+ close(s_err[1]);
+ close(s_err[0]);
+ socket_del(i_socket(iauth));
+ close(s_io[1]);
+ close(s_io[0]);
+ return res;
+ }
+
+ /* Attempt to fork a child process. */
+ cpid = fork();
+ if (cpid < 0) {
+ /* Error forking the child, still in parent. */
+ res = errno;
+ Debug((DEBUG_INFO, "Unable to fork IAuth child: %s", strerror(res)));
+ socket_del(i_stderr(iauth));
+ close(s_err[1]);
+ close(s_err[0]);
+ socket_del(i_socket(iauth));
+ close(s_io[1]);
+ close(s_io[0]);
+ return res;
+ }
+
+ if (cpid > 0) {
+ /* We are the parent process. Close the child's sockets. */
+ close(s_io[1]);
+ close(s_err[1]);
+ /* Send our server name (supposedly for proxy checking purposes)
+ * and maximum number of connections (for allocation hints).
+ * Need to use conf_get_local() since &me may not be fully
+ * initialized the first time we run.
+ */
+ sendto_iauth(NULL, "M %s %d", conf_get_local()->name, MAXCONNECTIONS);
+ /* Indicate success (until the child dies). */
+ return 0;
+ }
+
+ /* We are the child process.
+ * Duplicate our end of the socket to stdin, stdout and stderr.
+ * Then close all the higher-numbered FDs and exec the process.
+ */
+ if (dup2(s_io[1], 0) == 0
+ && dup2(s_io[1], 1) == 1
+ && dup2(s_err[1], 2) == 2) {
+ close_connections(0);
+ execvp(iauth->i_argv[0], iauth->i_argv);
+ }
+
+ /* If we got here, something was seriously wrong. */
+ exit(EXIT_FAILURE);
+}
+
+/** See if an %IAuth program must be spawned.
+ * If a process is already running with the specified options, keep it.
+ * Otherwise spawn a new child process to perform the %IAuth function.
+ * @param[in] argc Number of parameters to use when starting process.
+ * @param[in] argv Array of parameters to start process.
+ * @return 0 on failure, 1 on new process, 2 on reuse of existing process.
+ */
+int auth_spawn(int argc, char *argv[])
+{
+ int ii;
+
+ if (iauth) {
+ int same = 1;
+
+ /* Check that incoming arguments all match pre-existing arguments. */
+ for (ii = 0; same && (ii < argc); ++ii) {
+ if (NULL == iauth->i_argv[ii]
+ || 0 != strcmp(iauth->i_argv[ii], argv[ii]))
+ same = 0;
+ }
+ /* Check that we have no more pre-existing arguments. */
+ if (same && iauth->i_argv[ii])
+ same = 0;
+ /* If they are the same and still connected, clear the "closing" flag and exit. */
+ if (same && i_GetConnected(iauth)) {
+ Debug((DEBUG_INFO, "Reusing existing IAuth process"));
+ IAuthClr(iauth, IAUTH_CLOSING);
+ return 2;
+ }
+ auth_close_unused();
+ }
+
+ /* Need to initialize a new connection. */
+ iauth = MyCalloc(1, sizeof(*iauth));
+ msgq_init(i_sendQ(iauth));
+ /* Populate iauth's argv array. */
+ iauth->i_argv = MyCalloc(argc + 1, sizeof(iauth->i_argv[0]));
+ for (ii = 0; ii < argc; ++ii)
+ DupString(iauth->i_argv[ii], argv[ii]);
+ iauth->i_argv[ii] = NULL;
+ /* Try to spawn it, and handle the results. */
+ if (iauth_do_spawn(iauth, 0))
+ return 0;
+ IAuthClr(iauth, IAUTH_CLOSING);
+ return 1;
+}
+
+/** Mark all %IAuth connections as closing. */
+void auth_mark_closing(void)
+{
+ if (iauth)
+ IAuthSet(iauth, IAUTH_CLOSING);
+}
+
+/** Complete disconnection of an %IAuth connection.
+ * @param[in] iauth %Connection to fully close.
+ */
+static void iauth_disconnect(struct IAuth *iauth)
+{
+ if (iauth == NULL)
+ return;
+
+ /* Close main socket. */
+ if (s_fd(i_socket(iauth)) != -1) {
+ close(s_fd(i_socket(iauth)));
+ socket_del(i_socket(iauth));
+ s_fd(i_socket(iauth)) = -1;
+ }
+
+ /* Close error socket. */
+ if (s_fd(i_stderr(iauth)) != -1) {
+ close(s_fd(i_stderr(iauth)));
+ socket_del(i_stderr(iauth));
+ s_fd(i_stderr(iauth)) = -1;
+ }
+}
+
+/** Close all %IAuth connections marked as closing. */
+void auth_close_unused(void)
+{
+ if (IAuthHas(iauth, IAUTH_CLOSING)) {
+ int ii;
+ iauth_disconnect(iauth);
+ if (iauth->i_argv) {
+ for (ii = 0; iauth->i_argv[ii]; ++ii)
+ MyFree(iauth->i_argv[ii]);
+ MyFree(iauth->i_argv);
+ }
+ MyFree(iauth);
+ }
+}
+
+/** Send queued output to \a iauth.
+ * @param[in] iauth Writable connection with queued data.
+ */
+static void iauth_write(struct IAuth *iauth)
+{
+ unsigned int bytes_tried, bytes_sent;
+ IOResult iores;
+
+ if (IAuthHas(iauth, IAUTH_BLOCKED))
+ return;
+ while (MsgQLength(i_sendQ(iauth)) > 0) {
+ iores = os_sendv_nonb(s_fd(i_socket(iauth)), i_sendQ(iauth), &bytes_tried, &bytes_sent);
+ switch (iores) {
+ case IO_SUCCESS:
+ msgq_delete(i_sendQ(iauth), bytes_sent);
+ iauth->i_sendB += bytes_sent;
+ if (bytes_tried == bytes_sent)
+ break;
+ /* If bytes_sent < bytes_tried, fall through to IO_BLOCKED. */
+ case IO_BLOCKED:
+ IAuthSet(iauth, IAUTH_BLOCKED);
+ socket_events(i_socket(iauth), SOCK_ACTION_ADD | SOCK_EVENT_WRITABLE);
+ return;
+ case IO_FAILURE:
+ iauth_disconnect(iauth);
+ return;
+ }
+ }
+ /* We were able to flush all events, so remove notification. */
+ socket_events(i_socket(iauth), SOCK_ACTION_DEL | SOCK_EVENT_WRITABLE);
+}
+
+/** Send a message to iauth.
+ * @param[in] cptr Optional client context for message.
+ * @param[in] format Format string for message.
+ * @return Non-zero on successful send or buffering, zero on failure.
+ */
+static int sendto_iauth(struct Client *cptr, const char *format, ...)
+{
+ struct VarData vd;
+ struct MsgBuf *mb;
+
+ /* Do not send requests when we have no iauth. */
+ if (!i_GetConnected(iauth))
+ return 0;
+ /* Do not send for clients in the NORMAL state. */
+ if (cptr
+ && (format[0] != 'D')
+ && (!cli_auth(cptr) || !FlagHas(&cli_auth(cptr)->flags, AR_IAUTH_PENDING)))
+ return 0;
+
+ /* Build the message buffer. */
+ vd.vd_format = format;
+ va_start(vd.vd_args, format);
+ if (0 == cptr)
+ mb = msgq_make(NULL, "-1 %v", &vd);
+ else
+ mb = msgq_make(NULL, "%d %v", cli_fd(cptr), &vd);
+ va_end(vd.vd_args);
+
+ /* Tack it onto the iauth sendq and try to write it. */
+ ++iauth->i_sendM;
+ msgq_add(i_sendQ(iauth), mb, 0);
+ msgq_clean(mb);
+ iauth_write(iauth);
+ return 1;
+}
+
+/** Send text to interested operators (SNO_AUTH server notice).
+ * @param[in] iauth Active IAuth session.
+ * @param[in] cli Client referenced by command.
+ * @param[in] parc Number of parameters (1).
+ * @param[in] params Text to send.
+ * @return Zero.
+ */
+static int iauth_cmd_snotice(struct IAuth *iauth, struct Client *cli,
+ int parc, char **params)
+{
+ sendto_opmask_butone(NULL, SNO_AUTH, "%s", params[0]);
+ return 0;
+}
+
+/** Set the debug level for the session.
+ * @param[in] iauth Active IAuth session.
+ * @param[in] cli Client referenced by command.
+ * @param[in] parc Number of parameters (1).
+ * @param[in] params String starting with an integer.
+ * @return Zero.
+ */
+static int iauth_cmd_debuglevel(struct IAuth *iauth, struct Client *cli,
+ int parc, char **params)
+{
+ int new_level;
+
+ new_level = parc > 0 ? atoi(params[0]) : 0;
+ if (i_debug(iauth) > 0 || new_level > 0) {
+ /* The "ia_dbg" name is borrowed from (IRCnet) ircd. */
+ sendto_opmask_butone(NULL, SNO_AUTH, "ia_dbg = %d", new_level);
+ }
+ i_debug(iauth) = new_level;
+ return 0;
+}
+
+/** Set policy options for the session.
+ * Old policy is forgotten, and any of the following characters in \a
+ * params enable the corresponding policy:
+ * \li A IAUTH_ADDLINFO
+ * \li R IAUTH_REQUIRED
+ * \li T IAUTH_TIMEOUT
+ * \li W IAUTH_EXTRAWAIT
+ * \li U IAUTH_UNDERNET
+ *
+ * @param[in] iauth Active IAuth session.
+ * @param[in] cli Client referenced by command.
+ * @param[in] parc Number of parameters (1).
+ * @param[in] params Zero or more policy options.
+ * @return Zero.
+ */
+static int iauth_cmd_policy(struct IAuth *iauth, struct Client *cli,
+ int parc, char **params)
+{
+ enum IAuthFlag flag;
+ char *p;
+
+ /* Erase old policy first. */
+ for (flag = IAUTH_FIRST_OPTION; flag < IAUTH_LAST_FLAG; ++flag)
+ IAuthClr(iauth, flag);
+
+ if (parc > 0) /* only try to parse if we were given a policy string */
+ /* Parse new policy set. */
+ for (p = params[0]; *p; p++) switch (*p) {
+ case 'A': IAuthSet(iauth, IAUTH_ADDLINFO); break;
+ case 'R': IAuthSet(iauth, IAUTH_REQUIRED); break;
+ case 'T': IAuthSet(iauth, IAUTH_TIMEOUT); break;
+ case 'W': IAuthSet(iauth, IAUTH_EXTRAWAIT); break;
+ case 'U': IAuthSet(iauth, IAUTH_UNDERNET); break;
+ }
+
+ /* Optionally notify operators. */
+ if (i_debug(iauth) > 0)
+ sendto_opmask_butone(NULL, SNO_AUTH, "iauth options: %s", params[0]);
+ return 0;
+}
+
+/** Set the iauth program version number.
+ * @param[in] iauth Active IAuth session.
+ * @param[in] cli Client referenced by command.
+ * @param[in] parc Number of parameters (1).
+ * @param[in] params Version number or name.
+ * @return Zero.
+ */
+static int iauth_cmd_version(struct IAuth *iauth, struct Client *cli,
+ int parc, char **params)
+{
+ MyFree(iauth->i_version);
+ DupString(iauth->i_version, parc > 0 ? params[0] : "<NONE>");
+ sendto_opmask_butone(NULL, SNO_AUTH, "iauth version %s running.",
+ iauth->i_version);
+ return 0;
+}
+
+/** Paste a parameter list together into a single string.
+ * @param[in] parc Number of parameters.
+ * @param[in] params Parameter list to paste together.
+ * @return Pasted parameter list.
+ */
+static char *paste_params(int parc, char **params)
+{
+ char *str, *tmp;
+ int len = 0, lengths[MAXPARA], i;
+
+ /* Compute the length... */
+ for (i = 0; i < parc; i++)
+ len += lengths[i] = strlen(params[i]);
+
+ /* Allocate memory, accounting for string lengths, spaces (parc - 1), a
+ * sentinel, and the trailing \0
+ */
+ str = MyMalloc(len + parc + 1);
+
+ /* Build the pasted string */
+ for (tmp = str, i = 0; i < parc; i++) {
+ if (i) /* add space separator... */
+ *(tmp++) = ' ';
+ if (i == parc - 1) /* add colon sentinel */
+ *(tmp++) = ':';
+
+ /* Copy string component... */
+ memcpy(tmp, params[i], lengths[i]);
+ tmp += lengths[i]; /* move to end of string */
+ }
+
+ /* terminate the string... */
+ *tmp = '\0';
+
+ return str; /* return the pasted string */
+}
+
+/** Clear cached iauth configuration information.
+ * @param[in] iauth Active IAuth session.
+ * @param[in] cli Client referenced by command.
+ * @param[in] parc Number of parameters (0).
+ * @param[in] params Parameter list (ignored).
+ * @return Zero.
+ */
+static int iauth_cmd_newconfig(struct IAuth *iauth, struct Client *cli,
+ int parc, char **params)
+{
+ struct SLink *head;
+ struct SLink *next;
+
+ head = iauth->i_config;
+ iauth->i_config = NULL;
+ for (; head; head = next) {
+ next = head->next;
+ MyFree(head->value.cp);
+ free_link(head);
+ }
+ sendto_opmask_butone(NULL, SNO_AUTH, "New iauth configuration.");
+ return 0;
+}
+
+/** Append iauth configuration information.
+ * @param[in] iauth Active IAuth session.
+ * @param[in] cli Client referenced by command.
+ * @param[in] parc Number of parameters.
+ * @param[in] params Description of configuration element.
+ * @return Zero.
+ */
+static int iauth_cmd_config(struct IAuth *iauth, struct Client *cli,
+ int parc, char **params)
+{
+ struct SLink *node;
+
+ if (iauth->i_config) {
+ for (node = iauth->i_config; node->next; node = node->next) ;
+ node = node->next = make_link();
+ } else {
+ node = iauth->i_config = make_link();