1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
/*
* Implements the PAM session group API (pam_sm_open_session and
* pam_sm_close_session).
*
* Opening a session is mostly equivalent to calling pam_setcred with the flag
* to establish credentials but may return PAM_IGNORE. Closing a session
* destroys the PAM context, which will destroy the ticket cache.
*
* Copyright 2005, 2006, 2007, 2009 Russ Allbery <rra@stanford.edu>
* Copyright 2005 Andres Salomon <dilinger@debian.org>
* Copyright 1999, 2000 Frank Cusack <fcusack@fcusack.com>
*
* See LICENSE for licensing terms.
*/
/* Get prototypes for the session functions. */
#define PAM_SM_SESSION
#include <config.h>
#include <portable/pam.h>
#include <errno.h>
#include <string.h>
#include <internal.h>
/*
* Store the user's credentials. Nearly all of the work is done by
* pamk5_setcred.
*/
int
pam_sm_open_session(pam_handle_t *pamh, int flags, int argc,
const char **argv)
{
struct pam_args *args;
int pamret;
args = pamk5_args_parse(pamh, flags, argc, argv);
if (args == NULL) {
pamk5_crit(NULL, "cannot allocate memory: %s", strerror(errno));
pamret = PAM_SERVICE_ERR;
goto done;
}
ENTRY(args, flags);
pamret = pamk5_setcred(args, 0);
done:
EXIT(args, pamret);
pamk5_args_free(args);
return pamret;
}
/*
* Terminate session management, which in this case means freeing our
* context, along with destroying its associated ticket cache if appropriate.
*/
int
pam_sm_close_session(pam_handle_t *pamh, int flags, int argc,
const char **argv)
{
struct pam_args *args;
int pamret;
args = pamk5_args_parse(pamh, flags, argc, argv);
if (args == NULL) {
pamk5_crit(NULL, "cannot allocate memory: %s", strerror(errno));
pamret = PAM_SERVICE_ERR;
goto done;
}
ENTRY(args, flags);
pamret = pam_set_data(pamh, "pam_krb5", NULL, NULL);
if (pamret != PAM_SUCCESS)
pamk5_err_pam(args, pamret, "cannot clear context data");
args->ctx = NULL;
done:
EXIT(args, pamret);
pamk5_args_free(args);
return pamret;
}
|