免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1293 | 回复: 3
打印 上一主题 下一主题

有谁用过pam,进来交流一下 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-03-12 09:42 |只看该作者 |倒序浏览
rt

论坛徽章:
0
2 [报告]
发表于 2004-03-12 10:36 |只看该作者

有谁用过pam,进来交流一下

/*
  This program was contributed by Shane Watts
  [modifications by AGM]

  You need to add the following (or equivalent) to the /etc/pam.conf file.
  # check authorization
  check_user   auth       required     /usr/lib/security/pam_unix_auth.so
  check_user   account    required     /usr/lib/security/pam_unix_acct.so
*/

#include <security/pam_appl.h>;
#include <security/pam_misc.h>;
#include <stdio.h>;

static struct pam_conv conv = {
    misc_conv,
    NULL
};

int main(int argc, char *argv[])
{
    pam_handle_t *pamh=NULL;
    int retval;
    const char *user="nobody";

    if(argc == 2) {
        user = argv[1];
    }

    if(argc >; 2) {
        fprintf(stderr, "Usage: check_user [username]\n";
        exit(1);
    }

    retval = pam_start("check_user", user, &conv, &pamh);
        
    if (retval == PAM_SUCCESS)
    {
        retval = pam_authenticate(pamh, 0);    /* is user really user? */
        
    }

    if (retval == PAM_SUCCESS)
    {
        printf("ss\n";
        retval = pam_acct_mgmt(pamh, 0);       /* permitted access? */
    }

    /* This is where we have been authorized or not. */

    if (retval == PAM_SUCCESS) {
        fprintf(stdout, "Authenticated\n";
    } else {
        fprintf(stdout, "Not Authenticated\n";
    }

    if (pam_end(pamh,retval) != PAM_SUCCESS) {     /* close Linux-PAM */
        pamh = NULL;
        fprintf(stderr, "check_user: failed to release authenticator\n";
        exit(1);
    }

    return ( retval == PAM_SUCCESS ? 0:1 );       /* indicate success */
}

像以上这段代码,它是利用misc_conv来作为提示用户输入密码,那么如何编写类似的鉴权呢?

论坛徽章:
0
3 [报告]
发表于 2004-03-12 11:41 |只看该作者

有谁用过pam,进来交流一下

行了,解决了,太高兴了!!

论坛徽章:
0
4 [报告]
发表于 2004-03-12 15:23 |只看该作者

有谁用过pam,进来交流一下

解决了什么?如何解决的?可否为大家介绍介绍?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP