📄 mdfa2acct.c
字号:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <fcntl.h>
#include <shadow.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "account.h"
#include "acc_file.h"
#include "acc_shm.h"
main(int agrc,char **argv)
{
FILE *fp_user,*fp_shadow;
BYTE buf[12];
BYTE buf1;
struct spwd *aa,*bb;
int i,j,found=0;
stru_user user;
printf("\n根据user.dat修改shadow文件\n");
while(1)
{
/* sleep(3600);*/
if((fp_user=fopen("user.dat","rb"))==NULL)
{
printf("\nCannot open user.dat");
continue;
}
if(fseek(fp_user,122800*sizeof(user),SEEK_SET)==-1)
{
printf("\nfseek error!");
continue;
}
j=0;
while(!feof(fp_user))
{
if(fread(&user,sizeof(stru_user),1,fp_user)!=1)
{
printf("\nFinish scanning user.dat!");
break;
}
bb=getspnam(user.Uname);
if(bb==NULL)
{
/* 这是一个在user.dat中新开的用户 */
printf("*");
}
else if(labs((bb->sp_expire)*24*60*60-user.AccexpTm)>24*60*60)
{
if(lckpwdf()==-1)
{
printf("\n非常抱歉,lckpwdf failed!");
continue;
}
if((fp_shadow=fopen("/etc/new.shadow.file.weng","w"))==NULL)
{
printf("\n非常抱歉,open /etc/new.shadow.file.weng failed!");
ulckpwdf();
continue;
}
setspent();
found=0;
while((aa=getspent())!=NULL )
{
if (!strcmp(aa->sp_namp, user.Uname))
{
found=1;
aa->sp_expire=-1;
}
if (putspent(aa,fp_shadow) != 0)
{
found = 0;
break;
}
}
fclose(fp_shadow);
chmod("/etc/new.shadow.file.weng", S_IRUSR);
if(!found)
{
/* 对该帐号的操作失败 */
printf("\n对用户 [%s] 的操作失败!",user.Uname);
}
else
{
if(!rename("/etc/new.shadow.file.weng","/etc/shadow"))
{
printf("\nModify shadow file for user [%s]!",user.Uname);
}
else
printf("\nCan't rename!!");
}
ulckpwdf();
}
else
{
printf(".");
}
j++;
}
fclose(fp_user);
sleep(3600);
}
printf("\n结束");
exit(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -