/* * authcookie.C: Remote authentication ticket management * Rights to this code are documented in doc/pod/license.pod. * * Copyright © 2005-2007 Atheme Project (http://www.atheme.org) */ static char const rcsid[] = "$Id: authcookie.C,v 1.4 2007/08/28 17:08:12 pippijn Exp $"; #include "atheme.h" #include "authcookie.h" list_t authcookie_list; void authcookie_init (void) { #if 0 authcookie_heap = BlockHeapCreate (sizeof (authcookie_t), 1024); #endif } /* * authcookie_create() * * Inputs: * account associated with the authcookie * * Outputs: * pointer to new authcookie * * Side Effects: * an authcookie ticket is created, and validated. */ authcookie_t * authcookie_create (myuser_t *mu) { authcookie_t *au = new authcookie_t; au->ticket = gen_pw (20); au->myuser = mu; au->expire = NOW + 3600; node_add (au, &au->node, &authcookie_list); return au; } /* * authcookie_find() * * Inputs: * either the ticket string, the myuser_t it is associated with, or both * * Outputs: * the authcookie ticket for this object, if any * * Side Effects: * none */ authcookie_t * authcookie_find (char *ticket, myuser_t *myuser) { node_t *n; authcookie_t *ac; /* at least one must be specified */ return_val_if_fail (ticket != NULL || myuser != NULL, NULL); if (!myuser) /* must have ticket */ { LIST_FOREACH (n, authcookie_list.head) { ac = static_cast (n->data); if (!strcmp (ac->ticket, ticket)) return ac; } } else if (!ticket) /* must have myuser */ { LIST_FOREACH (n, authcookie_list.head) { ac = static_cast (n->data); if (ac->myuser == myuser) return ac; } } else /* must have both */ { LIST_FOREACH (n, authcookie_list.head) { ac = static_cast (n->data); if (ac->myuser == myuser && !strcmp (ac->ticket, ticket)) return ac; } } return NULL; } /* * authcookie_destroy() * * Inputs: * an authcookie to destroy * * Outputs: * none * * Side Effects: * an authcookie is destroyed */ void authcookie_destroy (authcookie_t *ac) { return_if_fail (ac != NULL); node_del (&ac->node, &authcookie_list); sfree (ac->ticket); delete ac; } /* * authcookie_destroy_all() * * Inputs: * a myuser_t pointer * * Outputs: * none * * Side Effects: * all authcookies for the user are destroyed */ void authcookie_destroy_all (myuser_t *mu) { node_t *n, *tn; authcookie_t *ac; LIST_FOREACH_SAFE (n, tn, authcookie_list.head) { ac = static_cast (n->data); if (ac->myuser == mu) authcookie_destroy (ac); } } /* * authcookie_expire() * * Inputs: * unused arg because this is an event function * * Outputs: * none * * Side Effects: * expired authcookies are destroyed */ void authcookie_expire (void *arg) { authcookie_t *ac; node_t *n, *tn; (void) arg; LIST_FOREACH_SAFE (n, tn, authcookie_list.head) { ac = static_cast (n->data); if (ac->expire <= NOW) authcookie_destroy (ac); } } /* * authcookie_validate() * * Inputs: * a ticket and myuser pair that needs to be validated * * Outputs: * true if the authcookie is valid, * otherwise false * * Side Effects: * expired authcookies are destroyed here */ bool authcookie_validate (char *ticket, myuser_t *myuser) { authcookie_t *ac = authcookie_find (ticket, myuser); if (ac == NULL) return false; if (ac->expire <= NOW) { authcookie_destroy (ac); return false; } return true; } /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs * vim:ts=8 * vim:sw=8 * vim:noexpandtab */