本文整理汇总了C++中pam_get_user函数的典型用法代码示例。如果您正苦于以下问题:C++ pam_get_user函数的具体用法?C++ pam_get_user怎么用?C++ pam_get_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pam_get_user函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: pam_sm_authenticate
PAM_EXTERN
int pam_sm_authenticate(pam_handle_t *pamh, int flags UNUSED,
int argc, const char **argv)
{
int retval;
const char *user=NULL;
/*
* authentication requires we know who the user wants to be
*/
retval = pam_get_user(pamh, &user, NULL);
if (retval != PAM_SUCCESS) {
D(("get user returned error: %s", pam_strerror(pamh,retval)));
return retval;
}
if (user == NULL || *user == '\0') {
D(("username not known"));
retval = pam_set_item(pamh, PAM_USER, (const void *) DEFAULT_USER);
if (retval != PAM_SUCCESS)
return retval;
}
user = NULL; /* clean up */
retval = parse_args(PAM_SUCCESS, "auth", pamh, argc, argv);
return retval;
}
开发者ID:BackupTheBerlios,项目名称:wl530g-svn,代码行数:27,代码来源:pam_debug.c
示例2: pam_sm_authenticate
PAM_EXTERN
int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc
, const char **argv)
{
const char *service=NULL, *user=NULL, *terminal=NULL
, *rhost=NULL, *ruser=NULL;
(void) pam_get_item(pamh, PAM_SERVICE, (const void **)&service);
(void) pam_get_item(pamh, PAM_TTY, (const void **)&terminal);
_pam_log(LOG_NOTICE, "service: %s [on terminal: %s]"
, service ? service : "<unknown>"
, terminal ? terminal : "<unknown>"
);
(void) pam_get_user(pamh, &user, "Who are you? ");
(void) pam_get_item(pamh, PAM_RUSER, (const void **)&ruser);
(void) pam_get_item(pamh, PAM_RHOST, (const void **)&rhost);
_pam_log(LOG_NOTICE, "user: (uid=%d) -> %s [remote: %[email protected]%s]"
, getuid()
, user ? user : "<unknown>"
, ruser ? ruser : "?nobody"
, rhost ? rhost : "?nowhere"
);
/* we are just a fly on the wall */
return PAM_IGNORE;
}
开发者ID:ysleu,项目名称:RTL8685,代码行数:27,代码来源:pam_warn.c
示例3: _whawty_ctx_init
int _whawty_ctx_init(whawty_ctx_t* ctx, pam_handle_t *pamh, int flags, int argc, const char **argv)
{
ctx->flags_ = 0;
ctx->pamh_ = pamh;
ctx->username_ = NULL;
ctx->password_ = NULL;
ctx->sockpath_ = NULL;
ctx->sock_ = -1;
ctx->timeout_ = 3;
if(flags & PAM_SILENT)
ctx->flags_ |= WHAWTY_CONF_SILENT;
// flag PAM_DISALLOW_NULL_AUTHTOK is not applicable and will therefore be ignored
int ret = _whawty_parse_args(ctx, argc, argv);
if(ret != PAM_SUCCESS)
return ret;
ret = pam_get_user(pamh, &(ctx->username_), NULL);
if(ret == PAM_SUCCESS) {
_whawty_logf(ctx, LOG_DEBUG, "successfully initialized [sock=%s]", ctx->sockpath_);
} else {
_whawty_logf(ctx, LOG_ERR, "pam_get_user() failed [%s]", pam_strerror(ctx->pamh_, ret));
}
return ret;
}
开发者ID:PeterTheOne,项目名称:auth,代码行数:26,代码来源:pam_whawty.c
示例4: pam_sm_chauthtok
PAM_EXTERN int
pam_sm_chauthtok (pam_handle_t *ph, int flags, int argc, const char **argv)
{
const char *user;
struct passwd *pwd;
uint args;
int ret;
args = parse_args (ph, argc, argv);
if (args & ARG_IGNORE_SERVICE)
return PAM_SUCCESS;
/* Figure out and/or prompt for the user name */
ret = pam_get_user (ph, &user, NULL);
if (ret != PAM_SUCCESS) {
syslog (GKR_LOG_ERR, "gkr-pam: couldn't get the user name: %s",
pam_strerror (ph, ret));
return PAM_SERVICE_ERR;
}
pwd = getpwnam (user);
if (!pwd) {
syslog (GKR_LOG_ERR, "gkr-pam: error looking up user information for: %s", user);
return PAM_SERVICE_ERR;
}
if (flags & PAM_PRELIM_CHECK)
return pam_chauthtok_preliminary (ph, pwd);
else if (flags & PAM_UPDATE_AUTHTOK)
return pam_chauthtok_update (ph, pwd, args);
else
return PAM_IGNORE;
}
开发者ID:bhull2010,项目名称:mate-keyring,代码行数:34,代码来源:gkr-pam-module.c
示例5: pam_sm_authenticate
PAM_EXTERN int
pam_sm_authenticate ( pam_handle_t *pamh, int flags, int argc,
const char *argv[] )
{
int retval;
const char *user, *prompt;
char *data,*data2,*flag;
char * pwdt,*pwds;
retval = pam_get_user ( pamh, &user, NULL );
if (retval != PAM_SUCCESS)
return retval;
D(("Got user: %s", user));
D(("cenas"));
pam_prompt(pamh, PAM_PROMPT_ECHO_OFF, &data,"attempt");
if(data == NULL)
return PAM_AUTH_ERR;
Base64Decode(data,&pwdt);
D(("Attempted Password: %s \n", pwdt));
pam_prompt(pamh, PAM_PROMPT_ECHO_OFF, &data2,"storedpassword");
Base64Decode(data2,&pwds);
if(strlen(data2) == 0)
return PAM_AUTH_ERR;
D(("Stored Password: %s \n", pwds));
if(strcmp(pwdt,pwds) == 0){
D(("PTEID CC authentication: success!"));
return PAM_SUCCESS;
}
return PAM_AUTH_ERR;
}
开发者ID:joelpinheiro,项目名称:Safebox-Smartcard-Auth,代码行数:34,代码来源:pam_safebox_pw.c
示例6: pam_get_uid
static int pam_get_uid( pam_handle_t *pamh, uid_t *uid, const char **userp )
{
const char *user;
struct passwd *pw;
#ifdef MAIN
user = cline_user;
#else
pam_get_user( pamh, &user, NULL );
#endif
if ( !user || !*user ) {
_pam_log(LOG_ERR, MODULE_NAME ": pam_get_uid; user?");
return PAM_AUTH_ERR;
}
if ( ! ( pw = getpwnam( user ) ) ) {
_pam_log(LOG_ERR,MODULE_NAME ": pam_get_uid; no such user %s",user);
return PAM_USER_UNKNOWN;
}
if ( uid ) *uid = pw->pw_uid;
if ( userp ) *userp = user;
return PAM_SUCCESS;
}
开发者ID:aosm,项目名称:pam,代码行数:25,代码来源:pam_tally.c
示例7: pam_sm_open_session
int pam_sm_open_session(pam_handle_t *pamh, int flags, int argc,
const char **argv)
{
const char *PAM_user = NULL;
int ret;
if (!cgm_dbus_connect()) {
mysyslog(LOG_ERR, "Failed to connect to cgmanager\n");
return PAM_SESSION_ERR;
}
if (argc > 1 && strcmp(argv[0], "-c") == 0)
ctrl_list = validate_and_dup(argv[1]);
if (!ctrl_list)
get_active_controllers();
cgm_escape();
ret = pam_get_user(pamh, &PAM_user, NULL);
if (ret != PAM_SUCCESS) {
cgm_dbus_disconnect();
mysyslog(LOG_ERR, "PAM-CGM: couldn't get user\n");
return PAM_SESSION_ERR;
}
ret = handle_login(PAM_user);
cgm_dbus_disconnect();
return ret;
}
开发者ID:hallyn,项目名称:pam-cgm,代码行数:27,代码来源:pam_cgm.c
示例8: pam_sm_open_session
PAM_EXTERN int
pam_sm_open_session(pam_handle_t *pamh, int flags,
int argc, const char **argv)
{
const struct passwd *pwent;
const char *user;
struct stat di;
void (*sh)(int);
pid_t child;
int res;
/* Who are we talking about anyway? */
res = pam_get_user(pamh, &user, NULL);
if (res != PAM_SUCCESS)
return res;
/* Fetch passwd entry */
pwent = getpwnam(user);
if (!pwent)
{
pam_error(pamh, "User not found in passwd?");
return PAM_CRED_INSUFFICIENT;
}
openlog("pam_mkhomedir", LOG_PID, LOG_AUTH);
if (stat(pwent->pw_dir, &di))
return pam_mkhd_copy(pamh, pwent, "/etc/skel", pwent->pw_dir);
return PAM_SUCCESS;
}
开发者ID:djbclark,项目名称:bb10qnx,代码行数:30,代码来源:pam_mkhomedir.c
示例9: pam_sm_close_session
PAM_VISIBLE int
pam_sm_close_session(pam_handle_t *pamh, int flags,
int argc, const char *argv[])
{
modopt_t *options = NULL;
const char *user, *rhost;
int rc;
PGresult *res;
PGconn *conn;
user = NULL; rhost = NULL;
if ((options = mod_options(argc, argv)) != NULL) {
if (options->query_session_close) {
if ((rc = pam_get_item(pamh, PAM_RHOST, (const void **)&rhost)) == PAM_SUCCESS) {
if ((rc = pam_get_user(pamh, &user, NULL)) == PAM_SUCCESS) {
DBGLOG("Session opened for user: %s", user);
if ((conn = db_connect(options))) {
pg_execParam(conn, &res, options->query_session_close, pam_get_service(pamh), user, NULL, rhost);
PQclear(res);
PQfinish(conn);
}
}
}
}
//free_module_options(options);
}
return (PAM_SUCCESS);
}
开发者ID:ZachGreen-ShipOffers,项目名称:pam-pgsql,代码行数:34,代码来源:pam_pgsql.c
示例10: get_context
/* Create and populate a context based on a given PAM handle and
* module name. */
struct context *
get_context(pam_handle_t *pamh, char *name, char *module)
{
struct context *ctx;
syslog(LOG_AUTH|LOG_DEBUG, "get_context (%s) in", module ? module : "??");
ctx = malloc(sizeof(struct context));
memset(ctx, 0, sizeof(struct context));
syslog(LOG_AUTH|LOG_DEBUG, "uname");
uname(&ctx->uts);
syslog(LOG_AUTH|LOG_DEBUG, "pam_get_user");
pam_get_user(pamh, &ctx->user, NULL);
syslog(LOG_AUTH|LOG_DEBUG, "pam_get_item(PAM_SERVICE)");
pam_get_item(pamh, PAM_SERVICE, (PAM_CONST void **)&ctx->svc);
syslog(LOG_AUTH|LOG_DEBUG, "pam_get_item(PAM_RHOST)");
pam_get_item(pamh, PAM_RHOST, (PAM_CONST void **)&ctx->rhost);
syslog(LOG_AUTH|LOG_DEBUG, "strdup");
ctx->module = strdup(module);
ctx->name = strdup(name);
ctx->log = LOG_AUTH;
if (ctx->user == NULL)
ctx->user = "(unknown)";
if (ctx->svc == NULL)
ctx->svc = "(unknown)";
if (ctx->rhost == NULL)
ctx->rhost = "(local)";
syslog(LOG_AUTH|LOG_DEBUG, "get_context (%s) out", module ? module : "??");
return ctx;
}
开发者ID:DHTC-Tools,项目名称:ubolt,代码行数:35,代码来源:util.c
示例11: pam_sm_close_session
PAM_EXTERN int
pam_sm_close_session (pam_handle_t *ph, int flags, int argc, const char **argv)
{
struct passwd *pwd;
const char *user;
int ret;
ret = pam_get_user (ph, &user, NULL);
if (ret != PAM_SUCCESS) {
syslog (GKR_LOG_ERR, "gkr-pam: couldn't get user from pam: %s",
pam_strerror (ph, ret));
return PAM_SERVICE_ERR;
}
pwd = getpwnam (user);
if (!pwd) {
syslog (GKR_LOG_ERR, "gkr-pam: error looking up user information for: %s", user);
return PAM_SERVICE_ERR;
}
stop_daemon (ph, pwd);
/* Don't bother user when daemon can't be stopped */
return PAM_SUCCESS;
}
开发者ID:bhull2010,项目名称:mate-keyring,代码行数:25,代码来源:gkr-pam-module.c
示例12: pam_sm_open_session
PAM_EXTERN int
pam_sm_open_session (pam_handle_t *ph, int flags, int argc, const char **argv)
{
const char *user = NULL, *password = NULL;
struct passwd *pwd;
int ret;
uint args;
int started_daemon;
args = parse_args (ph, argc, argv);
if (args & ARG_IGNORE_SERVICE)
return PAM_SUCCESS;
/* Figure out the user name */
ret = pam_get_user (ph, &user, NULL);
if (ret != PAM_SUCCESS) {
syslog (GKR_LOG_ERR, "gkr-pam: couldn't get the user name: %s",
pam_strerror (ph, ret));
return PAM_SERVICE_ERR;
}
pwd = getpwnam (user);
if (!pwd) {
syslog (GKR_LOG_ERR, "gkr-pam: error looking up user information for: %s", user);
return PAM_SERVICE_ERR;
}
/* Get the stored authtok here */
if (pam_get_data (ph, "gkr_system_authtok", (const void**)&password) != PAM_SUCCESS) {
/*
* No password, no worries, maybe this (PAM using) application
* didn't do authentication, or is hopeless and wants to call
* different PAM callbacks from different processes.
*
* No use complaining
*/
password = NULL;
}
started_daemon = 0;
/* Should we start the daemon? */
if (args & ARG_AUTO_START) {
ret = start_daemon_if_necessary (ph, pwd, password, &started_daemon);
if (ret != PAM_SUCCESS)
return ret;
}
/* If mate keyring is running, but we didn't start it here, then unlock now */
if (get_any_env (ph, ENV_CONTROL) != NULL) {
if (!started_daemon && password != NULL) {
if (unlock_keyring (ph, pwd, password) != PAM_SUCCESS)
return PAM_SERVICE_ERR;
}
}
return PAM_SUCCESS;
}
开发者ID:bhull2010,项目名称:mate-keyring,代码行数:59,代码来源:gkr-pam-module.c
示例13: g_new0
/**
* EscalateModuleNew:
* @pamh: PAM handle.
* @flags: PAM flags.
* @argc: Number of arguments given to the PAM module.
* @argv: Array of argument strings given to the PAM module.
* @helper: Path to helper executable, or #NULL for the default path.
* @error: (out)(allow-none): Error return location or #NULL.
*
* Returns: New #EscalateModule instance.
*/
EscalateModule *EscalateModuleNew(pam_handle_t *pamh, gint flags, gint argc,
const gchar **argv, const gchar *helper,
GError **error) {
EscalateModule *self = g_new0(EscalateModule, 1);
gint pam_result = PAM_SYSTEM_ERR;
const gchar *username = NULL;
self->pamh = pamh;
self->flags = flags;
self->keep_going = TRUE;
self->result = PAM_SYSTEM_ERR;
for (guint i = 0; i < argc; i++) {
const gchar *arg = argv[i];
if (g_str_equal(arg, "use_first_pass")) {
self->use_first_pass = TRUE;
} else if (g_str_equal(arg, "try_first_pass")) {
self->try_first_pass = TRUE;
} else {
g_set_error(error, ESCALATE_MODULE_ERROR,
ESCALATE_MODULE_ERROR_UNKNOWN_ARG,
"Unknown argument '%s'", arg);
goto failed;
}
}
pam_result = pam_get_item(pamh, PAM_CONV, (const void **) &self->conv);
if (pam_result != PAM_SUCCESS) {
g_error("Failed to get conversation function: %s",
pam_strerror(pamh, pam_result));
}
if (!self->conv) {
g_set_error(error, ESCALATE_MODULE_ERROR, ESCALATE_MODULE_ERROR_CONV,
"No conversation function available");
goto failed;
}
pam_result = pam_get_user(pamh, &username, NULL);
if (pam_result != PAM_SUCCESS) {
g_set_error(error, ESCALATE_MODULE_ERROR, ESCALATE_MODULE_ERROR_NO_USERNAME,
"Failed to find a username");
goto failed;
}
self->username = g_strdup(username);
// TODO(vonhollen): Handle SIGCHLD for this process without messing up an
// existing handler.
self->child = EscalateSubprocessNew(helper, error);
if (!self->child)
goto failed;
return self;
failed:
EscalateModuleFree(self);
return NULL;
}
开发者ID:passy,项目名称:libpam-policycache,代码行数:69,代码来源:escalate_module.c
示例14: pam_sm_authenticate
PAM_EXTERN int
pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv)
{
const char *username;
char *password;
int retval = PAM_AUTH_ERR;
gray_pam_init(PAM_SERVICE_ERR);
/* parse arguments */
_pam_parse(argc, argv);
/* Get the username */
retval = pam_get_user(pamh, &username, NULL);
if (retval != PAM_SUCCESS || !username) {
DEBUG(1, ("can not get the username"));
return PAM_SERVICE_ERR;
}
/* Get the password */
if (_pam_get_password(pamh, &password, "Password:"))
return PAM_SERVICE_ERR;
if (retval != PAM_SUCCESS) {
_pam_log(LOG_ERR, "Could not retrive user's password");
return PAM_SERVICE_ERR;
}
if (gray_env_read(gpam_sql_config_file, &config_env))
retval = PAM_SERVICE_ERR;
else {
gray_slist_t slist;
/* FIXME: This comment is needed to pacify
`make check-sql-config' in doc:
gpam_sql_find_config("passwd-query") */
retval = gpam_sql_verify_user_pass(pamh, password,
get_query2(pamh, "passwd-query",
"query", &slist, 1));
gray_slist_free(&slist);
}
gray_env_free(config_env);
config_env = NULL;
switch (retval) {
case PAM_ACCT_EXPIRED:
_pam_log(LOG_NOTICE, "user '%s': account expired", username);
break;
case PAM_SUCCESS:
_pam_log(LOG_NOTICE, "user '%s' granted access", username);
break;
default:
_pam_log(LOG_NOTICE, "user '%s' failed to authenticate",
username);
}
return retval;
}
开发者ID:Gnitset,项目名称:pam-modules,代码行数:57,代码来源:pam_sql.c
示例15: pam_sm_acct_mgmt
/* public: check if account has expired, or needs new password */
PAM_VISIBLE int
pam_sm_acct_mgmt(pam_handle_t *pamh, int flags, int argc,
const char **argv)
{
modopt_t *options = NULL;
const char *user, *rhost;
int rc = PAM_AUTH_ERR;
PGconn *conn;
PGresult *res;
user = NULL; rhost = NULL;
if ((options = mod_options(argc, argv)) != NULL) {
/* query not specified, just succeed. */
if (options->query_acct == NULL) {
//free_module_options(options);
return PAM_SUCCESS;
}
if ((rc = pam_get_item(pamh, PAM_RHOST, (const void **)&rhost)) == PAM_SUCCESS) {
if((rc = pam_get_user(pamh, &user, NULL)) == PAM_SUCCESS) {
if(!(conn = db_connect(options))) {
rc = PAM_AUTH_ERR;
} else {
DBGLOG("query: %s", options->query_acct);
rc = PAM_AUTH_ERR;
if(pg_execParam(conn, &res, options->query_acct, pam_get_service(pamh), user, NULL, rhost) == PAM_SUCCESS) {
if (PQntuples(res) == 1 &&
PQnfields(res) >= 2 && PQnfields(res) <= 3) {
char *expired_db = PQgetvalue(res, 0, 0);
char *newtok_db = PQgetvalue(res, 0, 1);
rc = PAM_SUCCESS;
if (PQnfields(res)>=3) {
char *nulltok_db = PQgetvalue(res, 0, 2);
if ((!strcmp(nulltok_db, "t")) && (flags & PAM_DISALLOW_NULL_AUTHTOK))
rc = PAM_NEW_AUTHTOK_REQD;
}
if (!strcmp(newtok_db, "t"))
rc = PAM_NEW_AUTHTOK_REQD;
if (!strcmp(expired_db, "t"))
rc = PAM_ACCT_EXPIRED;
} else {
DBGLOG("query_acct should return one row and two or three columns");
rc = PAM_PERM_DENIED;
}
PQclear(res);
}
PQfinish(conn);
}
}
}
}
//free_module_options(options);
return rc;
}
开发者ID:ZachGreen-ShipOffers,项目名称:pam-pgsql,代码行数:58,代码来源:pam_pgsql.c
示例16: pam_sm_authenticate
PAM_EXTERN int
pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char *argv[]){
// log
pam_syslog(pamh, LOG_INFO, "moje logiii");
struct passwd *pw = NULL, pw_s;
const char *user = NULL;
char btaddr[50];
int port;
char buffer[1024], checkfile[1024];
int pgu_ret, gpn_ret, snp_ret, a_ret;
pgu_ret = pam_get_user(pamh, &user, NULL);
fprintf(stderr, "%s", user);
fprintf(stderr, "\n");
if (pgu_ret != PAM_SUCCESS || user == NULL) {
return(PAM_IGNORE);
}
/* gpn_ret = getpwnam_r(user, &pw_s, buffer, sizeof(buffer), &pw);*/
/* if (gpn_ret != 0 || pw == NULL || pw->pw_dir == NULL || pw->pw_dir[0] != '/') {*/
/* return(PAM_IGNORE);*/
/* }*/
//snp_ret = snprintf(checkfile, sizeof(checkfile), "%s/.pam_blue_auth", pw->pw_dir);
//if (snp_ret >= sizeof(checkfile)) {
// return(PAM_IGNORE);
//}
a_ret = check_user_rules(&user, &btaddr, &port);
//a_ret = access(checkfile, F_OK);
if (a_ret == 0) {
fprintf(stderr, "The user's file exists\n");
if(rfcomm_client(btaddr, port)==0){
//if(1==1){
fprintf(stderr, "return authentication success\n");
return(PAM_SUCCESS);
}
else{
fprintf(stderr, "return authentication success\n");
return(PAM_AUTH_ERR);
}
}
else{
fprintf(stderr, "The user's doesn't file exist, return authentication PAM_IGNORE\n");
return(PAM_AUTH_ERR);
}
}
开发者ID:slaweksiluk,项目名称:BlueAuth,代码行数:57,代码来源:pam.c
示例17: pam_sm_authenticate
/*****************************************************************************
Func Name: pam_sm_authenticate
Date Created: 2009/2/23
Author: chendong
Description: PAM 认证接口函数
Input: pam_handle_t * pamh PAM HANDLE
int flags 调试标记
int argc 参数列表大小
const char ** argv 参数列表
Output: 无
Return: PAM错误码
Caution:
-----------------------------------------------------------------------------
Modification History
DATE NAME DESCRIPTION
-----------------------------------------------------------------------------
******************************************************************************/
PAM_EXTERN int
pam_sm_authenticate (pam_handle_t * pamh, int flags, int argc,
const char **argv)
{
int method;
int ret;
struct pam_ext_item *item = NULL;
char user_name[256];
const char *user;
void *item_tmp = (void *)item;
int auth_mode = 1;
pam_local_parse_option (argc, argv);
method = PAM_EXT_METHOD_PAP;
ret = pam_get_item (pamh, PAM_EXT_METHOD, (const void **)&item_tmp);
item = (struct pam_ext_item *)item_tmp;
if (PAM_SUCCESS == ret)
{
method = *(int *) item->item_value;
}
switch (method)
{
case PAM_EXT_METHOD_EAP:
ret = pam_local_eap_auth (pamh, user_name);
user = user_name;
break;
case PAM_EXT_METHOD_PAP:
default:
/* 取用户名 */
ret = pam_get_user (pamh, &user, NULL);
if (ret != PAM_SUCCESS)
{
return ret;
}
ret = pam_local_pap_auth (pamh, user); /**/
if (ret != PAM_SUCCESS)
{
return ret;
}
pam_set_extern_item(pamh, PAM_EXT_WEB_AUTH_MODE, sizeof(int),
(void *)&auth_mode);
break;
}
if (PAM_SUCCESS == ret)
{
pam_local_authorization (pamh, user); /**/
}
pam_local_logger ("Local authenticate user %s %s", user,
(PAM_SUCCESS == ret)?"succeeded":"failed");
(void) flags;
return ret;
}
开发者ID:millken,项目名称:zhuxianB30,代码行数:74,代码来源:pam_local.c
示例18: pam_sm_authenticate
/* PAM entry point for authentication verification */
PAM_EXTERN int pam_sm_authenticate(pam_handle_t _unused_ *ph, int _unused_ flags,
int _unused_ argc, const char _unused_ **argv)
{
struct agent_data_t data;
const struct passwd *pwd;
const char *user, *password;
enum agent id = AGENT_DEFAULT;
int ret;
ret = pam_get_user(ph, &user, NULL);
if (ret != PAM_SUCCESS) {
syslog(PAM_LOG_ERR, "pam-envoy: couldn't get the user name: %s",
pam_strerror(ph, ret));
return PAM_SERVICE_ERR;
}
pwd = getpwnam(user);
if (!pwd) {
syslog(PAM_LOG_ERR, "pam-envoy: error looking up user information: %s",
strerror(errno));
return PAM_SERVICE_ERR;
}
/* Look up the password */
ret = pam_get_item(ph, PAM_AUTHTOK, (const void**)&password);
if (ret != PAM_SUCCESS || password == NULL) {
if (ret == PAM_SUCCESS)
syslog(PAM_LOG_WARN, "pam-envoy: no password is available for user");
else
syslog(PAM_LOG_WARN, "pam-envoy: no password is available for user: %s",
pam_strerror(ph, ret));
return PAM_SUCCESS;
}
if (pam_get_agent(&data, id, pwd->pw_uid, pwd->pw_gid) < 0) {
syslog(PAM_LOG_WARN, "pam-envoy: failed to get agent for user");
return PAM_SUCCESS;
}
if (data.status == ENVOY_RUNNING && data.type == AGENT_GPG_AGENT) {
_cleanup_gpg_ struct gpg_t *agent = gpg_agent_connection(data.gpg);
if (password) {
const struct fingerprint_t *fpt = gpg_keyinfo(agent);
for (; fpt; fpt = fpt->next) {
if (gpg_preset_passphrase(agent, fpt->fingerprint, -1, password) < 0)
syslog(PAM_LOG_ERR, "failed to unlock '%s'", fpt->fingerprint);
}
}
gpg_close(agent);
}
return PAM_SUCCESS;
}
开发者ID:RagnarDanneskjold,项目名称:envoy,代码行数:56,代码来源:pam_envoy.c
示例19: pam_get_user
char *_pam_get_user(pam_handle_t *pamh) {
int retval;
char *user;
retval = pam_get_user(pamh, (void *)&user, "Username: ");
if (retval != PAM_SUCCESS || user == NULL || *user == '\0') {
_pam_log(LOG_ERR, "unable to obtain username");
user = NULL;
}
return user;
}
开发者ID:jeroennijhof,项目名称:pam_tacplus,代码行数:11,代码来源:support.c
示例20: pam_sm_authenticate
PAM_EXTERN
int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
const char **argv)
{
int retval = PAM_SUCCESS;
int fd;
const char *username;
char *mtmp=NULL;
struct passwd *user_pwd;
struct pam_conv *conversation;
struct pam_message message;
struct pam_message *pmessage = &message;
struct pam_response *resp = NULL;
struct stat st;
if ((fd = open("/etc/nologin", O_RDONLY, 0)) >= 0) {
/* root can still log in; lusers cannot */
if ((pam_get_user(pamh, &username, NULL) != PAM_SUCCESS)
|| !username) {
return PAM_SERVICE_ERR;
}
user_pwd = getpwnam(username);
if (user_pwd && user_pwd->pw_uid == 0) {
message.msg_style = PAM_TEXT_INFO;
} else {
if (!user_pwd) {
retval = PAM_USER_UNKNOWN;
} else {
retval = PAM_AUTH_ERR;
}
message.msg_style = PAM_ERROR_MSG;
}
/* fill in message buffer with contents of /etc/nologin */
if (fstat(fd, &st) < 0) /* give up trying to display message */
return retval;
message.msg = mtmp = malloc(st.st_size+1);
/* if malloc failed... */
if (!message.msg) return retval;
read(fd, mtmp, st.st_size);
mtmp[st.st_size] = '\000';
/* Use conversation function to give user contents of /etc/nologin */
pam_get_item(pamh, PAM_CONV, (const void **)&conversation);
conversation->conv(1, (const struct pam_message **)&pmessage,
&resp, conversation->appdata_ptr);
free(mtmp);
if (resp)
_pam_drop_reply(resp, 1);
}
return retval;
}
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:53,代码来源:pam_nologin.c
注:本文中的pam_get_user函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论