⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cuzika.c

📁 国际标准协议的
💻 C
📖 第 1 页 / 共 2 页
字号:
/*每0.01元人民币=10个现金单位按现时拨号费每小时3元计算,拨号每分钟需5分人民币=>50个现金单位INT32 最大能表示200多万元人民币*/#include	<stdio.h>#include	<stdlib.h>#include	<string.h>#include	<strings.h>#include	<fcntl.h>#include	<unistd.h>#include	<shadow.h>#include	<pwd.h>#include	"acc_file.h"typedef struct account_pw {	char	cid[10];	/* Card ID */	char	passwd[16];	/* Card Password */	char	type;		/* Card type */	char	status;		/* Card Active Status */	long	first_date;	/* First login time */	long	last_date;	/* Last login time */	char	account_id[12];	/* Bank account id */	long	left_fee;	/* Left available fee */} ACCOUNT_PW;main(){	ACCOUNT_PW	user_czk;	stru_user	user_xf;	FILE	*fp_czk;	FILE	*fp_xf;	FILE	*fp_uid;	int	id,i;	FILE	*fp;	char	buf[1000];	int	j,k;	char	*ptr;	struct spwd	sha;	struct spwd	*shaptr;	struct passwd	*pwdptr;	long	expire_date;	int	ever;	long	groupid;	INT32	uid;	int	other_usr,invalid_usr;		int	czkjs_used,czkjs_unused,czkbz_used,czkbz_unused,czk_lock;	int	u10,u20,u21,u22,u25,u29,u49,u200,u209,u40,u41,u42,u201,u45,u204,u210,u50,u51,u52,u53,u54,u55,u56,u57,u58,u59,u151,u152,u30,u220,u222,u240,u242,u230,u231,u250,u251,u31;	char	temp_usrname1[12];	char	temp_usrname2[12];	long	temp_count;		czkjs_used=czkjs_unused=czkbz_used=czkbz_unused=czk_lock=0;	other_usr=invalid_usr=0;	u10=u20=u21=u22=u25=u29=u49=u200=u209=u40=u41=u42=u201=u45=u204=u210=u50=u51=u52=u53=u54=u55=u56=u57=u58=u59=u151=u152=u30=u220=u222=u240=u242=u230=u231=u250=u251=u31=0;	if((fp_xf=fopen("user.dat","wb"))==NULL)	{		printf("Cannot open user.dat for write!\n");		exit(1);	}	strcpy(user_xf.Uname,"system");	strcpy(user_xf.Passwd,(const char *)crypt("manager","./"));	user_xf.Uid=1;	user_xf.Gid=1;	user_xf.UertPtr=-1;	user_xf.ListPtr=-1;	if(fwrite(&user_xf,sizeof(stru_user),1,fp_xf)!=1)	{		printf("Write user.dat error!(Can not create root user)\n");		exit(-1);	}	id=1000;	printf("转换储值卡用户\n");	for(i=1;i<=8;i++)	{				if(i==1)		{			if((fp_czk=fopen("/usr/radius/raddb/account_1.pw","rb"))==NULL)			{				printf("Cannot open account_1.pw\n");				exit(1);			}		}				if(i==2)		{			if((fp_czk=fopen("/usr/radius/raddb/account_2.pw","rb"))==NULL)			{				printf("Cannot open account_2.pw\n");				exit(1);			}		}		if(i==3)		{			if((fp_czk=fopen("/usr/radius/raddb/account_3.pw","rb"))==NULL)			{				printf("Cannot open account_3.pw\n");				exit(1);			}		}		if(i==4)		{			if((fp_czk=fopen("/usr/radius/raddb/account_4.pw","rb"))==NULL)			{				printf("Cannot open account_4.pw\n");				exit(1);			}		}		if(i==5)		{			if((fp_czk=fopen("/usr/radius/raddb/account_5.pw","rb"))==NULL)			{				printf("Cannot open account_5.pw\n");				exit(1);			}		}				if(i==6)		{			if((fp_czk=fopen("/usr/radius/raddb/account_6.pw","rb"))==NULL)			{				printf("Cannot open account_6.pw\n");				exit(1);			}		}		if(i==7)		{			if((fp_czk=fopen("/usr/radius/raddb/account_8.pw","rb"))==NULL)			{				printf("Cannot open account_8.pw\n");				exit(1);			}		}		if(i==8)		{			if((fp_czk=fopen("/usr/radius/raddb/account_9.pw","rb"))==NULL)			{				printf("Cannot open account_9.pw\n");				exit(1);			}		}				printf("正在处理第%d个文件,Uid=%d\n",i,id);				while(!feof(fp_czk))		{			if(fread(&user_czk,sizeof(ACCOUNT_PW),1,fp_czk)!=1)			{/*				printf("Read pw file error!\n");*/				break;			}			/*			printf("CardID is %s\n",user_czk.cid);			printf("Card Password is %s\n",user_czk.passwd);			printf("Card type is %c\n",user_czk.type);			printf("Card Active Status is %c\n",user_czk.status);			printf("First login time is %d\n",user_czk.first_date);			printf("Last login time is %d\n",user_czk.last_date);			printf("Bank account id is %s\n",user_czk.account_id);			printf("Left available fee is %d\n\n",user_czk.left_fee);*/				strcpy(user_xf.Uname,user_czk.cid);			strcpy(user_xf.Passwd,user_czk.passwd);/*			strcpy(user_xf.Passwd,(const char *)crypt("test","./"));*/			user_xf.Uid=id;			id++;									user_xf.Ulevel=0;			user_xf.Cid=1;			user_xf.Status=0;			user_xf.CostType=2;			strcpy(user_xf.Reserve,"czk_user");			user_xf.PeriodTm=0xFFFFFFFF;			user_xf.Wday=0xFF;			user_xf.PointAmt=0;			user_xf.Credit=0;			user_xf.Auth=0;			user_xf.PerLimit=0x7FFFFFFF;			user_xf.DayLimit=0x7FFFFFFF;			user_xf.ListPtr=-1;			user_xf.UertPtr=-1;			if(user_czk.cid[0]=='6' || user_czk.cid[0]=='8' || user_czk.cid[0]=='9')			{				user_xf.Gid=212;//储值卡包租用户				user_xf.Type=2;				user_xf.CashAmt=0;								if(user_czk.status=='0')	//还未使用过的包租卡				{					user_xf.AccvalidTm=-1;//包租用户的包租时间改为用AccexpTm表示,单位"分钟"					user_xf.Amount=0;					user_xf.Last_time=-1;															if(user_czk.cid[0]=='6')					{						user_xf.AccexpTm=3*365*24*60;					}					else if(user_czk.cid[0]=='8')					{						user_xf.AccexpTm=5*365*24*60;											}					else if(user_czk.cid[0]=='9')					{						user_xf.AccexpTm=30*24*60;											}										czkbz_unused++;									}				else if(user_czk.status=='1')	//已开始使用的包租卡				{					user_xf.AccvalidTm=user_czk.first_date;					user_xf.Last_time=user_czk.last_date;					user_xf.Amount=0;										if(user_czk.cid[0]=='6')					{						user_xf.AccexpTm=user_czk.first_date+3*365*24*60*60;					}					else if(user_czk.cid[0]=='8')					{						user_xf.AccexpTm=user_czk.first_date+5*365*24*60*60;											}					else if(user_czk.cid[0]=='9')					{						user_xf.AccexpTm=user_czk.first_date+30*24*60*60;											}										czkbz_used++;				}			}			else			{				user_xf.Gid=211;//储值卡计时用户				user_xf.Type=1;				user_xf.CashAmt=0;												if(user_czk.status=='0')	//未使用的记时卡				{					user_xf.AccvalidTm=-1;					user_xf.AccexpTm=(user_czk.left_fee*5)/6;//储值卡计时用户的卡值(使用系统现金单位)改为在AccexpTm中表示					user_xf.Last_time=-1;										user_xf.Amount=0;										czkjs_unused++;				}				else if(user_czk.status=='1')	//已使用的记时卡				{					user_xf.AccvalidTm=user_czk.first_date;					user_xf.AccexpTm=time(NULL)+30*365*24*60*60;					user_xf.Last_time=user_czk.last_date;					user_xf.Amount=0;					user_xf.CashAmt=(user_czk.left_fee*5)/6;//储值卡计时用户现金余额					czkjs_used++;				}											}						//被锁定的储值卡帐号			if(user_czk.status=='N' || user_czk.status=='n')			{				user_xf.AccvalidTm=time(NULL);				user_xf.AccexpTm=time(NULL);				user_xf.Last_time=time(NULL);				user_xf.CashAmt=0;				user_xf.Status=1;				user_xf.Amount=0;								czk_lock++;			}									if(fwrite(&user_xf,sizeof(stru_user),1,fp_xf)!=1)			{				printf("Write user.dat error!\n");				exit(-1);			}								}			fclose(fp_czk);		}		k=id-1000;	printf("转换原有UNIX用户\n");		if((fp=fopen("/etc/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");*/			break;		}				ptr=strchr(buf,':');		*ptr=0;		shaptr=getspnam(buf);		pwdptr=getpwnam(buf);						if(shaptr==NULL)		{			printf("没权限读SHADOW文件!!\n");			exit(-1);		}		if(pwdptr==NULL)		{			printf("PASSWD文件中没有该用户记录!!\n");						invalid_usr++;			continue;						}		/*		printf("USERNAME:%s\n",shaptr->sp_namp);		printf("Gid:%d\n",pwdptr->pw_gid);		printf("密码:%s\n",shaptr->sp_pwdp);		printf("过期日:%d\n",shaptr->sp_expire);		printf("***************\n");*/		if(pwdptr->pw_gid==10)		{			u10++;		}		if(pwdptr->pw_gid==20)		{			u20++;		}		if(pwdptr->pw_gid==21)		{			u21++;		}		if(pwdptr->pw_gid==22)		{			u22++;		}		if(pwdptr->pw_gid==25)		{			u25++;		}		if(pwdptr->pw_gid==29)		{			u29++;		}		if(pwdptr->pw_gid==49)		{			u49++;		}		if(pwdptr->pw_gid==200)		{			u200++;		}		if(pwdptr->pw_gid==209)		{			u209++;		}		if(pwdptr->pw_gid==40)		{			u40++;		}		if(pwdptr->pw_gid==41)

⌨️ 快捷键说明

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