如果在Linux下编程修改用户密码?

icuc88 2003-10-18 01:13:47
1. 要使用PAM
2. 不允许交互
3. 用C语言



得分条件:

完全实现述要求。不要给我PAM的例子,网站连接。。。诸如此类,我都有。不要叫我直接修改/etc/passwd文件。

UP更没有分。
...全文
49 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
icuc88 2003-12-11
  • 打赏
  • 举报
回复
再次UP!
wide288 2003-12-01
  • 打赏
  • 举报
回复
不可以交互,你怎么知道你改的密码啊。
还有PAM 是什么啊,不知道
icuc88 2003-12-01
  • 打赏
  • 举报
回复
to: blh(老猫)

你肯定这样不用输入密码和用户名吗?

如果是PAM的例子,肯定是交互的。
blh 2003-12-01
  • 打赏
  • 举报
回复

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <unistd.h>
#include <sys/types.h>

#include <security/pam_appl.h>
#include <security/pam_misc.h>
#include <pwd.h>
#include <popt.h>

extern int misc_conv(int num_msg, const struct pam_message **msgm,struct pam_response **response, void *appdata_ptr);

/* conversation function & corresponding structure */
static struct pam_conv conv =
{
misc_conv,
NULL
};

const char *username = NULL; /* username specified on the command line */

#ifdef HAVE_PAM_FAIL_DELAY
#define PASSWD_FAIL_DELAY 2000000 /* usec delay on failure */
#endif

static int stdin_conv(int num_msg, const struct pam_message **msgm, struct pam_response **response, void *appdata_ptr)
{
struct pam_response *reply;
int count;

if (num_msg <= 0)
return PAM_CONV_ERR;

reply = (struct pam_response *) calloc(num_msg, sizeof(struct pam_response));
if (reply == NULL) {
return PAM_CONV_ERR;
}

for (count=0; count < num_msg; ++count)
{
reply[count].resp_retcode = 0;
reply[count].resp = strdup(appdata_ptr);
}

*response = reply;
reply = NULL;

return PAM_SUCCESS;
}


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

retval = pam_start("passwd", username, &conv, &pamh);

#ifdef HAVE_PAM_FAIL_DELAY
retval = pam_fail_delay(pamh, PASSWD_FAIL_DELAY);
if (retval != PAM_SUCCESS) {
fprintf(stderr, "passwd: unable to set failure delay\n");
exit(1);
}
#endif
while (retval == PAM_SUCCESS)
{
retval = pam_chauthtok(pamh, 0);
if (retval != PAM_SUCCESS)
break;
retval = pam_end(pamh, PAM_SUCCESS);
if (retval != PAM_SUCCESS)
break;
printf( "passwd: all authentication tokens updated successfully\n");
exit(0);
}

if (retval != PAM_SUCCESS)
fprintf(stderr, "passwd: %s\n", pam_strerror(pamh, retval));

if (pamh != NULL)
{
(void) pam_end(pamh,PAM_SUCCESS);
pamh = NULL;
}

exit(1);
}
michaelowenii 2003-12-01
  • 打赏
  • 举报
回复
我不行!
hecCIBN 2003-12-01
  • 打赏
  • 举报
回复
等着接分
delphimm 2003-11-30
  • 打赏
  • 举报
回复
有啊,我来也!! 接分!!!
icuc88 2003-11-04
  • 打赏
  • 举报
回复
没有人来吗?散分!
icuc88 2003-10-28
  • 打赏
  • 举报
回复
散分!
zeng_xiangyang 2003-10-18
  • 打赏
  • 举报
回复
ai
ravingboy 2003-10-18
  • 打赏
  • 举报
回复
顺便问一下怎么编程实现修改/etc/passwd文件呢?
zaiquansun 2003-10-18
  • 打赏
  • 举报
回复
太难了,同志
icuc88 2003-10-18
  • 打赏
  • 举报
回复
要求还不少,呵呵
^^^^^^^^^^^^^^^^
我在这个板块只能送100分,如果觉得不够,解决后可以另外给。
warton 2003-10-18
  • 打赏
  • 举报
回复
要求还不少,呵呵
icuc88 2003-10-18
  • 打赏
  • 举报
回复
没有人知道吗?如果没有,我就移动帖子,当送分了。

1,508

社区成员

发帖
与我相关
我的任务
社区描述
Windows专区 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧