11286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley/*
21286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley * session.c - PPP session control.
31286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *
41286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley * Copyright (c) 2007 Diego Rivera. All rights reserved.
51286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *
61286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley * Redistribution and use in source and binary forms, with or without
71286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley * modification, are permitted provided that the following conditions
81286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley * are met:
91286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *
101286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley * 1. Redistributions of source code must retain the above copyright
111286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *    notice, this list of conditions and the following disclaimer.
121286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *
131286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley * 2. The name(s) of the authors of this software must not be used to
141286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *    endorse or promote products derived from this software without
151286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *    prior written permission.
161286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *
171286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley * 3. Redistributions of any form whatsoever must retain the following
181286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *    acknowledgment:
191286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *    "This product includes software developed by Paul Mackerras
201286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *     <paulus@samba.org>".
211286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *
221286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
231286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
241286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
251286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
261286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
271286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
281286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
291286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley */
301286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley
311286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley#ifndef __SESSION_H
321286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley#define __SESSION_H
331286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley
341286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley#define SESS_AUTH  1	/* Check User Authentication */
351286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley#define SESS_ACCT  2	/* Check Account Validity */
361286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley
371286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley/* Convenience parameter to do the whole enchilada */
381286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley#define SESS_ALL   (SESS_AUTH | SESS_ACCT)
391286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley
401286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley/*
411286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley * int session_start(...)
421286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *
431286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley * Start a session, performing any necessary validations.
441286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *
451286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley * Parameters:
461286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley * 	const int flags :
471286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley * 		Any combination of the SESS_XXX flags, to indicate what the function
481286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *		should do as part of its checks
491286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *
501286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *	const char* user :
511286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *		The username to validate.  May safely be null.
521286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *
531286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *	const char* passwd :
541286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *		The password to validate the user with. May safely be null.
551286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *
561286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *	const char* tty :
571286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *		The TTY the user is connected on. May safely be null.
581286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *
591286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *	char** msg :
601286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *		A char* to return an error or success message.  This message will be returned
611286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *		regardless of the result.  May safely be null.
621286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *
631286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley * Return Value:
641286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley * 	Zero value for failure, non-zero value for successful session verification.
651286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley */
661286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langleyint
671286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langleysession_start(const int flags, const char* user, const char* passwd, const char* tty, char** msg);
681286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley
691286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley/* Added these macros for convenience... */
701286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley#define session_auth(user, pass, tty, msg) \
711286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley	session_start(SESS_AUTH, user, pass, tty, msg)
721286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley
731286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley#define session_check(user, pass, tty, msg) \
741286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley	session_start(SESS_ACCT, user, pass, tty, msg)
751286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley
761286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley#define session_full(user, pass, tty, msg) \
771286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley	session_start(SESS_ALL, user, pass, tty, msg)
781286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley
791286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley/*
801286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley * void session_end(...)
811286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *
821286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley * End a previously-started session.
831286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *
841286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley * Parameters:
851286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *	const char* tty :
861286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley *		The TTY the user is connected on. May safely be null.
871286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley */
881286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langleyvoid
891286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langleysession_end(const char* tty);
901286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley
911286c078a4b93695b3812e8c7fe7918c28ea18b4Adam Langley#endif
92