本文整理汇总了C++中pam_setcred函数的典型用法代码示例。如果您正苦于以下问题:C++ pam_setcred函数的具体用法?C++ pam_setcred怎么用?C++ pam_setcred使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pam_setcred函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: xlsh_session_open
int xlsh_session_open(const char* service, const char* user,
pam_handle_t** handle)
{
struct pam_conv conv = { xlsh_session_conv, NULL };
pam_handle_t* pam_handle;
if(pam_start(service, user, &conv, &pam_handle) != PAM_SUCCESS)
return XLSH_ERROR;
if(xlsh_X)
pam_set_item(pam_handle, PAM_TTY, XLSH_XTTY);
else
pam_set_item(pam_handle, PAM_TTY, ttyname(0));
if(pam_authenticate(pam_handle, 0) != PAM_SUCCESS) {
pam_end(pam_handle, 0);
return XLSH_ERROR;
}
if(pam_acct_mgmt(pam_handle, 0) != PAM_SUCCESS) {
pam_end(pam_handle, 0);
return XLSH_ERROR;
}
if(pam_setcred(pam_handle, PAM_ESTABLISH_CRED) != PAM_SUCCESS) {
pam_end(pam_handle, 0);
return XLSH_ERROR;
}
if(pam_open_session(pam_handle, 0) != PAM_SUCCESS) {
pam_setcred(pam_handle, PAM_DELETE_CRED);
pam_end(pam_handle, 0);
return XLSH_ERROR;
}
*handle = pam_handle;
return XLSH_EOK;
}
开发者ID:drwilly,项目名称:xlsh,代码行数:35,代码来源:xlsh.c
示例2: do_pam_setcred
void
do_pam_setcred(int init)
{
sshpam_err = pam_set_item(sshpam_handle, PAM_CONV,
(const void *)&store_conv);
if (sshpam_err != PAM_SUCCESS)
fatal("PAM: failed to set PAM_CONV: %s",
pam_strerror(sshpam_handle, sshpam_err));
if (init) {
debug("PAM: establishing credentials");
sshpam_err = pam_setcred(sshpam_handle, PAM_ESTABLISH_CRED);
} else {
debug("PAM: reinitializing credentials");
sshpam_err = pam_setcred(sshpam_handle, PAM_REINITIALIZE_CRED);
}
if (sshpam_err == PAM_SUCCESS) {
sshpam_cred_established = 1;
return;
}
if (sshpam_authenticated)
fatal("PAM: pam_setcred(): %s",
pam_strerror(sshpam_handle, sshpam_err));
else
debug("PAM: pam_setcred(): %s",
pam_strerror(sshpam_handle, sshpam_err));
}
开发者ID:Alkzndr,项目名称:freebsd,代码行数:26,代码来源:auth-pam.c
示例3: sftppam_exit_ev
static void sftppam_exit_ev(const void *event_data, void *user_data) {
/* Close the PAM session */
if (sftppam_pamh != NULL) {
int res;
#ifdef PAM_CRED_DELETE
res = pam_setcred(sftppam_pamh, PAM_CRED_DELETE);
#else
res = pam_setcred(sftppam_pamh, PAM_DELETE_CRED);
#endif
if (res != PAM_SUCCESS) {
pr_trace_msg(trace_channel, 9, "PAM error setting PAM_DELETE_CRED: %s",
pam_strerror(sftppam_pamh, res));
}
res = pam_close_session(sftppam_pamh, PAM_SILENT);
pam_end(sftppam_pamh, res);
sftppam_pamh = NULL;
}
if (sftppam_user != NULL) {
free(sftppam_user);
sftppam_user = NULL;
sftppam_userlen = 0;
}
}
开发者ID:jmaggard10,项目名称:proftpd,代码行数:28,代码来源:mod_sftp_pam.c
示例4: switch
void Authenticator::close_session(void) {
switch((last_result=pam_close_session(pam_handle, 0))) {
// The documentation and implementation of Linux PAM differs:
// PAM_SESSION_ERROR is described in the documentation but
// don't exists in the actual implementation. This issue needs
// to be fixes at some point.
default:
//case PAM_SESSION_ERROR:
pam_setcred(pam_handle, PAM_DELETE_CRED);
_end();
throw Exception(pam_handle, "pam_close_session", last_result);
case PAM_SUCCESS:
break;
};
switch((last_result=pam_setcred(pam_handle, PAM_DELETE_CRED))) {
default:
case PAM_CRED_ERR:
case PAM_CRED_UNAVAIL:
case PAM_CRED_EXPIRED:
case PAM_USER_UNKNOWN:
_end();
throw Exception(pam_handle, "pam_setcred()", last_result);
case PAM_SUCCESS:
break;
}
return;
}
开发者ID:JackDanger,项目名称:chromiumos,代码行数:30,代码来源:PAM.cpp
示例5: run_test_case
static enum pamtest_err run_test_case(pam_handle_t *ph,
struct pam_testcase *tc)
{
switch (tc->pam_operation) {
case PAMTEST_AUTHENTICATE:
tc->op_rv = pam_authenticate(ph, tc->flags);
return PAMTEST_ERR_OK;
case PAMTEST_SETCRED:
tc->op_rv = pam_setcred(ph, tc->flags);
return PAMTEST_ERR_OK;
case PAMTEST_ACCOUNT:
tc->op_rv = pam_acct_mgmt(ph, tc->flags);
return PAMTEST_ERR_OK;
case PAMTEST_OPEN_SESSION:
tc->op_rv = pam_open_session(ph, tc->flags);
return PAMTEST_ERR_OK;
case PAMTEST_CLOSE_SESSION:
tc->op_rv = pam_close_session(ph, tc->flags);
return PAMTEST_ERR_OK;
case PAMTEST_CHAUTHTOK:
tc->op_rv = pam_chauthtok(ph, tc->flags);
return PAMTEST_ERR_OK;
case PAMTEST_GETENVLIST:
tc->case_out.envlist = pam_getenvlist(ph);
return PAMTEST_ERR_OK;
case PAMTEST_KEEPHANDLE:
tc->case_out.ph = ph;
return PAMTEST_ERR_KEEPHANDLE;
default:
return PAMTEST_ERR_OP;
}
return PAMTEST_ERR_OP;
}
开发者ID:encukou,项目名称:samba,代码行数:34,代码来源:libpamtest.c
示例6: pam_setcred
bool PamHandle::setCred(int flags) {
m_result = pam_setcred(m_handle, flags | m_silent);
if (m_result != PAM_SUCCESS) {
qWarning() << "[PAM] setCred:" << pam_strerror(m_handle, m_result);
}
return m_result == PAM_SUCCESS;
}
开发者ID:Acidburn0zzz,项目名称:sddm-1,代码行数:7,代码来源:PamHandle.cpp
示例7: SessionExit
void SessionExit(struct display *d, int status, int removeAuth)
{
#ifdef USE_PAM
pam_handle_t *pamh = thepamh();
if (pamh) {
/* shutdown PAM session */
if (pam_setcred(pamh, PAM_DELETE_CRED) != PAM_SUCCESS)
WDMError("pam_setcred(DELETE_CRED) failed, errno=%d", errno);
pam_close_session(pamh, 0);
pam_end(pamh, PAM_SUCCESS);
pamh = NULL;
}
#endif
/* make sure the server gets reset after the session is over */
if (d->serverPid >= 2 && d->resetSignal)
kill(d->serverPid, d->resetSignal);
else
ResetServer(d);
if (removeAuth) {
setgid(verify.gid);
setuid(verify.uid);
RemoveUserAuthorization(d, &verify);
}
WDMDebug("Display %s exiting with status %d\n", d->name, status);
exit(status);
}
开发者ID:bbidulock,项目名称:wdm,代码行数:27,代码来源:session.c
示例8: auth
static int auth(const char *password) {
pam_handle_t* pamh;
struct passwd *pw;
if ((pw = getpwuid(getuid())) == NULL)
return 0;
struct pam_response * reply = malloc(sizeof(struct pam_response));
if (!reply)
return 0;
struct pam_conv pamc = { conversation, reply };
int rc = 0;
reply->resp = strdup(password);
reply->resp_retcode = 0;
pam_start("slock", pw->pw_name, &pamc, &pamh);
if (pam_set_item(pamh, PAM_AUTHTOK, password) == PAM_SUCCESS &&
pam_authenticate(pamh,PAM_DISALLOW_NULL_AUTHTOK) == PAM_SUCCESS &&
pam_acct_mgmt(pamh, 0) == PAM_SUCCESS &&
pam_setcred(pamh, PAM_REFRESH_CRED) == PAM_SUCCESS) {
rc = 1;
}
pam_end(pamh,0);
return rc;
}
开发者ID:jackdoe,项目名称:slock,代码行数:25,代码来源:slock.c
示例9: pam_finish
void
pam_finish ()
{
int rc = 0;
/*
* Allow PAM to clean up its state by closing the user session and
* ending the association with PAM.
*/
if (!conf->use_pam)
return;
if (pam_h != NULL) {
/*
* Log any errors, but there's no need to return a SLURM error.
*/
if ((rc = pam_close_session (pam_h, 0)) != PAM_SUCCESS) {
error("pam_close_session: %s", pam_strerror(pam_h, rc));
}
if ((rc = pam_setcred (pam_h, PAM_DELETE_CRED)) != PAM_SUCCESS){
error("pam_setcred DELETE: %s", pam_strerror(pam_h,rc));
}
if ((rc = pam_end (pam_h, rc)) != PAM_SUCCESS) {
error("pam_end: %s", pam_strerror(NULL, rc));
}
pam_h = NULL;
}
}
开发者ID:HDOD,项目名称:slurm,代码行数:29,代码来源:pam_ses.c
示例10: init_groups
static void
init_groups (const struct passwd* pw, gid_t* groups, int num_groups) {
int retval;
errno = 0;
if (num_groups) {
retval = setgroups (num_groups, groups);
} else {
retval = initgroups (pw->pw_name, pw->pw_gid);
}
if (retval == -1) {
cleanup_pam (PAM_ABORT);
err (EXIT_FAILURE, _("cannot set groups"));
}
endgrent ();
retval = pam_setcred (pamh, PAM_ESTABLISH_CRED);
if (is_pam_failure(retval)) {
errx (EXIT_FAILURE, "%s", pam_strerror (pamh, retval));
} else {
_pam_cred_established = 1;
}
}
开发者ID:TheNeikos,项目名称:bughack,代码行数:25,代码来源:su-common.2.27.1-1.modified.c
示例11: mc_pam_auth
/* Return 0 if authentication failed, 1 otherwise */
static int
mc_pam_auth (const char *username, const char *password)
{
pam_handle_t *pamh;
struct user_pass up;
int status;
up.username = username;
up.password = password;
conv.appdata_ptr = &up;
if ((status =
pam_start ("mcserv", username, &conv, &pamh)) != PAM_SUCCESS)
goto failed_pam;
if ((status = pam_authenticate (pamh, 0)) != PAM_SUCCESS)
goto failed_pam;
if ((status = pam_acct_mgmt (pamh, 0)) != PAM_SUCCESS)
goto failed_pam;
if ((status = pam_setcred (pamh, PAM_ESTABLISH_CRED)) != PAM_SUCCESS)
goto failed_pam;
pam_end (pamh, status);
return 0;
failed_pam:
pam_end (pamh, status);
return 1;
}
开发者ID:sfionov,项目名称:mc-dev,代码行数:28,代码来源:mcserv.c
示例12: do_pam_cleanup_proc
/* Called at exit to cleanly shutdown PAM */
static void
do_pam_cleanup_proc(void *context)
{
int pam_retval;
pam_stuff *pam = (pam_stuff *) context;
if (pam == NULL)
return;
if (pam->authctxt != NULL && pam->authctxt->pam == pam) {
pam->authctxt->pam_retval = pam->last_pam_retval;
pam->authctxt->pam = NULL;
pam->authctxt = NULL;
}
if (pam->h == NULL)
return;
/*
* We're in fatal_cleanup() or not in userauth or without a
* channel -- can't converse now, too bad.
*/
pam_retval = pam_set_item(pam->h, PAM_CONV, NULL);
if (pam_retval != PAM_SUCCESS) {
log("Cannot remove PAM conv, close session or delete creds[%d]: %.200s",
pam_retval, PAM_STRERROR(pam->h, pam_retval));
goto cleanup;
}
if (pam->state & PAM_S_DONE_OPEN_SESSION) {
pam_retval = pam_close_session(pam->h, 0);
if (pam_retval != PAM_SUCCESS)
log("Cannot close PAM session[%d]: %.200s",
pam_retval, PAM_STRERROR(pam->h, pam_retval));
}
if (pam->state & PAM_S_DONE_SETCRED) {
pam_retval = pam_setcred(pam->h, PAM_DELETE_CRED);
if (pam_retval != PAM_SUCCESS)
debug("Cannot delete credentials[%d]: %.200s",
pam_retval, PAM_STRERROR(pam->h, pam_retval));
}
cleanup:
/* Use the previous PAM result, if not PAM_SUCCESS for pam_end() */
if (pam->last_pam_retval != PAM_SUCCESS)
pam_retval = pam_end(pam->h, pam->last_pam_retval);
else if (pam_retval != PAM_SUCCESS)
pam_retval = pam_end(pam->h, pam_retval);
else
pam_retval = pam_end(pam->h, PAM_ABORT);
if (pam_retval != PAM_SUCCESS)
log("Cannot release PAM authentication[%d]: %.200s",
pam_retval, PAM_STRERROR(pam->h, pam_retval));
xfree(pam);
}
开发者ID:andreiw,项目名称:polaris,代码行数:60,代码来源:auth-pam.c
示例13: checkpw_cleanup
static void checkpw_cleanup (pam_handle_t *hdl)
{
#if 0 /* see checkpw() for why this is #if 0 */
pam_close_session (hdl,NIL); /* close session [uw]tmp */
#endif
pam_setcred (hdl,PAM_DELETE_CRED);
pam_end (hdl,PAM_SUCCESS);
}
开发者ID:Distrotech,项目名称:pine,代码行数:8,代码来源:ckp_pam.c
示例14: mdm_verify_cleanup
void
mdm_verify_cleanup (MdmDisplay *d)
{
gid_t groups[1] = { 0 };
cur_mdm_disp = d;
if (pamh != NULL) {
gint pamerr;
pam_handle_t *tmp_pamh;
gboolean old_opened_session;
gboolean old_did_setcred;
mdm_debug ("Running mdm_verify_cleanup and pamh != NULL");
mdm_sigterm_block_push ();
mdm_sigchld_block_push ();
tmp_pamh = pamh;
pamh = NULL;
old_opened_session = opened_session;
opened_session = FALSE;
old_did_setcred = did_setcred;
did_setcred = FALSE;
mdm_sigchld_block_pop ();
mdm_sigterm_block_pop ();
pamerr = PAM_SUCCESS;
/* Close the users session */
if (old_opened_session) {
mdm_debug ("Running pam_close_session");
pamerr = pam_close_session (tmp_pamh, 0);
}
/* Throw away the credentials */
if (old_did_setcred) {
mdm_debug ("Running pam_setcred with PAM_DELETE_CRED");
pamerr = pam_setcred (tmp_pamh, PAM_DELETE_CRED);
}
pam_end (tmp_pamh, pamerr);
/* Workaround to avoid mdm messages being logged as PAM_pwdb */
mdm_log_shutdown ();
mdm_log_init ();
}
/* Clear the group setup */
setgid (0);
/* this will get rid of any suplementary groups etc... */
setgroups (1, groups);
cur_mdm_disp = NULL;
/* reset limits */
mdm_reset_limits ();
}
开发者ID:ActusOS,项目名称:mdm,代码行数:56,代码来源:verify-pam.c
示例15: pam_setcred
int context::rmcred()
{
int code = static_cast<int>(errc::success);
if(_M_cred)
{
code = pam_setcred(_M_pamh, PAM_DELETE_CRED);
_M_cred = false;
}
return code;
}
开发者ID:dimitry-ishenko,项目名称:camel,代码行数:10,代码来源:pam.cpp
示例16: pam_start
bool PAMAuthenticator::authenticate(void)
{
pam_conv c;
c.conv = PAMAuthenticator::conv;
c.appdata_ptr = this;
int res = pam_start("repwatchproxy", 0, &c, &this->m_ph);
if (res == PAM_SUCCESS) {
res = pam_set_item(this->m_ph, PAM_RUSER, this->m_user.constData());
if (res != PAM_SUCCESS) {
goto getout;
}
res = pam_set_item(this->m_ph, PAM_RHOST, this->m_host.constData());
if (res != PAM_SUCCESS) {
goto getout;
}
res = pam_authenticate(this->m_ph, 0);
if (res != PAM_SUCCESS) {
goto getout;
}
res = pam_acct_mgmt(this->m_ph, 0);
if (PAM_NEW_AUTHTOK_REQD == res) {
res = pam_chauthtok(this->m_ph, PAM_CHANGE_EXPIRED_AUTHTOK);
}
if (res != PAM_SUCCESS) {
goto getout;
}
res = pam_setcred(this->m_ph, PAM_ESTABLISH_CRED);
if (res != PAM_SUCCESS) {
goto getout;
}
res = pam_open_session(this->m_ph, 0);
if (res != PAM_SUCCESS) {
goto getout;
}
return true;
getout:
qWarning("%s: %s", Q_FUNC_INFO, pam_strerror(this->m_ph, res));
pam_end(this->m_ph, res);
}
else {
qCritical("PAM initialization failed");
}
this->m_ph = 0;
return false;
}
开发者ID:sjinks,项目名称:repwatch_proxy,代码行数:55,代码来源:pamauthenticator.cpp
示例17: xlsh_session_close
int xlsh_session_close(pam_handle_t* handle)
{
pam_close_session(handle, 0);
if(pam_setcred(handle, PAM_DELETE_CRED) != PAM_SUCCESS) {
pam_end(handle, 0);
return XLSH_ERROR;
}
pam_end(handle, 0);
return XLSH_EOK;
}
开发者ID:drwilly,项目名称:xlsh,代码行数:11,代码来源:xlsh.c
示例18: pam_session_open
gboolean pam_session_open(void)
{
g_pamLastStatus = pam_setcred(g_pamHandle, PAM_ESTABLISH_CRED);
if (g_pamLastStatus != PAM_SUCCESS)
{
fprintf(stderr, "Jolicloud-DisplayManager: Unable to define pam credentials. Error %d\n",
g_pamLastStatus);
return FALSE;
}
g_pamLastStatus = pam_open_session(g_pamHandle, 0);
if (g_pamLastStatus != PAM_SUCCESS)
{
fprintf(stderr, "Jolicloud-DisplayManager: Unable to open session with pan. Error %d\n",
g_pamLastStatus);
pam_setcred(g_pamHandle, PAM_DELETE_CRED);
return FALSE;
}
return TRUE;
}
开发者ID:AlfredArouna,项目名称:jolicloud-displaymanager,代码行数:21,代码来源:pam.c
示例19: loginpam_session
/*
* Note that the position of the pam_setcred() call is discussable:
*
* - the PAM docs recommend pam_setcred() before pam_open_session()
* - but the original RFC http://www.opengroup.org/rfc/mirror-rfc/rfc86.0.txt
* uses pam_setcred() after pam_open_session()
*
* The old login versions (before year 2011) followed the RFC. This is probably
* not optimal, because there could be a dependence between some session modules
* and the user's credentials.
*
* The best is probably to follow openssh and call pam_setcred() before and
* after pam_open_session(). -- [email protected] (18-Nov-2011)
*
*/
static void loginpam_session(struct login_context *cxt)
{
int rc;
pam_handle_t *pamh = cxt->pamh;
rc = pam_setcred(pamh, PAM_ESTABLISH_CRED);
if (is_pam_failure(rc))
loginpam_err(pamh, rc);
rc = pam_open_session(pamh, 0);
if (is_pam_failure(rc)) {
pam_setcred(cxt->pamh, PAM_DELETE_CRED);
loginpam_err(pamh, rc);
}
rc = pam_setcred(pamh, PAM_REINITIALIZE_CRED);
if (is_pam_failure(rc)) {
pam_close_session(pamh, 0);
loginpam_err(pamh, rc);
}
}
开发者ID:abrodkin,项目名称:util-linux,代码行数:36,代码来源:login.c
示例20: pam_setup
int
pam_setup (char *user, char *host)
{
/*
* Any application using PAM must provide a conversion function, which
* is used for direct communication between a loaded module and the
* application. In this case, SLURM does need a communication mechanism,
* so the default (or null) conversation function may be used.
*/
struct pam_conv conv = {misc_conv, NULL};
int rc = 0;
if (!conf->use_pam)
return SLURM_SUCCESS;
/*
* SLURM uses PAM to obtain resource limits established by the system
* administrator. PAM's session management library is responsible for
* handling resource limits. When a PAM session is opened on behalf of
* a user, the limits imposed by the sys admin are picked up. Opening
* a PAM session requires a PAM handle, which is obtained when the PAM
* interface is initialized. (PAM handles are required with essentially
* all PAM calls.) It's also necessary to have the users PAM credentials
* to open a user session.
*/
if ((rc = pam_start (SLURM_SERVICE_PAM, user, &conv, &pam_h))
!= PAM_SUCCESS) {
error ("pam_start: %s", pam_strerror(pam_h, rc));
return SLURM_ERROR;
} else if ((rc = pam_set_item (pam_h, PAM_USER, user))
!= PAM_SUCCESS) {
error ("pam_set_item USER: %s", pam_strerror(pam_h, rc));
return SLURM_ERROR;
} else if ((rc = pam_set_item (pam_h, PAM_RUSER, user))
!= PAM_SUCCESS) {
error ("pam_set_item RUSER: %s", pam_strerror(pam_h, rc));
return SLURM_ERROR;
} else if ((rc = pam_set_item (pam_h, PAM_RHOST, host))
!= PAM_SUCCESS) {
error ("pam_set_item HOST: %s", pam_strerror(pam_h, rc));
return SLURM_ERROR;
} else if ((rc = pam_setcred (pam_h, PAM_ESTABLISH_CRED))
!= PAM_SUCCESS) {
error ("pam_setcred: %s", pam_strerror(pam_h, rc));
return SLURM_ERROR;
} else if ((rc = pam_open_session (pam_h, 0)) != PAM_SUCCESS) {
error("pam_open_session: %s", pam_strerror(pam_h, rc));
return SLURM_ERROR;
}
return SLURM_SUCCESS;
}
开发者ID:IFCA,项目名称:slurm,代码行数:52,代码来源:pam_ses.c
注:本文中的pam_setcred函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论