shadow_pass.c

来自「国际标准协议的」· C语言 代码 · 共 60 行

C
60
字号
#include	<stdio.h>
#include	<stdlib.h>
#include	<string.h>
#include	<strings.h>
#include	<fcntl.h>
#include	<shadow.h>

main()
{
	FILE	*fp;
	
	char	buf[1000];
	int	i,j;
	char	*ptr;
	struct spwd	sha;
	struct spwd	*shaptr;

	printf("显示shadow文件的内容\n");
	
	if((fp=fopen("shadow","r"))==NULL)
	{
		printf("Cannot open shadow file.\n");
		exit(1);
	}
	
	j=0;
	while(!feof(fp))
	{
		if(fgets(buf,1000,fp)==NULL)
		{
			printf("Read shadow file error!\n");
			exit(-1);
		}
		
		ptr=strchr(buf,':');
		*ptr=0;
		shaptr=getspnam(buf);
		
		
		if(shaptr==NULL)
		{
			printf("null!!\n");
			exit(-1);
		}
		
		printf("用户名:%s\n",shaptr->sp_namp);
		printf("密码:%s\n",shaptr->sp_pwdp);
		printf("过期日:%d\n",shaptr->sp_expire);
		
		
		printf("***************\n");
		j++;
	}
	
	printf("总用户数:%d\n",j);
	printf("结束\n");
	exit(0);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?