コード例 #1
0
UINT8 app_brushCard(void)
{
	UINT8 Sector;
	UINT8 CardIndex;
    UINT8 i;
	for (CardIndex = MEM_CARD; CardIndex <= PWD_CARD; CardIndex++)
	{
		if (b_FactorySystem)
		{
			CardIndex = PWD_CARD;
		}
		if (CardIndex == MEM_CARD)
		{
			Load_Key(&s_System.MGM_Card);
		}
		else if (CardIndex == USER_CARD)
		{
			Load_Key(&s_System.USER_Card);
		}
		else if (CardIndex == PWD_CARD)
		{
			Load_Key(PWD_Card);
		}
		MIF_Halt();
		if (Request(RF_CMD_REQUEST_STD) != FM1702_OK)
		{
			continue;
		}
        for(i=0; i<2; i++)
        {
            if (AntiColl() == FM1702_OK && SelectCard() == FM1702_OK)
            {
                if (CardIndex == USER_CARD)     //用户卡验证钱所在扇区
                {
                    Sector = s_System.Sector;
                }
                else                            //管理和密码卡验证1扇区
                {
                    Sector = 1;
                }
                if (Authentication(gCard_UID, Sector, 0x60) == FM1702_OK)
                {
                    return CardIndex;
                }
            }
        }
	}
	return NONE_CARD;
}
コード例 #2
0
ファイル: main.c プロジェクト: evilperfect/Things.Interested
/**
 * 函数:main()
 *
 * 检查程序的执行权限,检查命令行参数格式。
 * 允许的调用格式包括:
 * 	njit-client  username  password
 * 	njit-client  username  password  eth0
 * 	njit-client  username  password  eth1
 *  若没有从命令行指定网卡,则默认将使用eth0
 */
int main(int argc, char *argv[])
{
    //注册退出事件函数
    sigemptyset(&act.sa_mask);
    act.sa_sigaction = exit_handler;
    act.sa_flags = SA_SIGINFO;

	char *UserName;
	char *Password;

	/* 检查当前是否具有root权限 */
	if (getuid() != 0) {
		fprintf(stderr, "抱歉,运行本客户端程序需要root权限\n");
		fprintf(stderr, "(RedHat/Fedora下使用su命令切换为root)\n");
		fprintf(stderr, "(Ubuntu/Debian下在命令前添加sudo)\n");
		exit(-1);
	}

	/* 检查命令行参数格式 */
	if (argc<3 || argc>4) {
		fprintf(stderr, "命令行参数错误!\n");
		fprintf(stderr,	"正确的调用格式例子如下:\n");
		fprintf(stderr,	"    %s username password\n", argv[0]);
		fprintf(stderr,	"    %s username password eth0\n", argv[0]);
		fprintf(stderr,	"    %s username password eth1\n", argv[0]);
		fprintf(stderr, "(注:若不指明网卡,默认情况下将使用eth0)\n");
		exit(-1);
	} else if (argc == 4) {
		DeviceName = argv[3]; // 允许从命令行指定设备名
	} else {
		DeviceName = "eth0"; // 缺省情况下使用的设备
	}
	UserName = argv[1];
	Password = argv[2];

	/* 调用子函数完成802.1X认证 */
	Authentication(UserName, Password, DeviceName);

	return (0);
}
コード例 #3
0
ファイル: xd_h3c.c プロジェクト: jefby/xd-h3c
//主函数
int main(int argc,char *argv[])
{
	int c = 0, i, j;
	int opt;
	opterr = 0;
	//注册退出事件函数
	sigemptyset(&act.sa_mask);
	act.sa_sigaction = exit_handler;
	act.sa_flags = SA_SIGINFO;
	if(sigaction(SIGINT, &act, NULL))
	{
		perror("sigaction");
		return -1;
	}
	//开始解析命令行
	for(i=0; i<argc; i++)
	{
		for(j=0;j<strlen(argv[i]);j++)
		if(argv[i][j]=='-' && strlen(argv[i])!=1)
			c++;
	}
	if(c<argc/2)
	{
		printf("命令行输入错误!\n请尝试执行“xdh3c --help”来获取更多信息。\n");
		exit(-1);
	}
	struct option long_options[] = {
		{"help", 0, NULL, 'h'},
		{"username", 0, NULL, 'u'},
		{"password", 0, NULL, 'p'},
		{"device", 0, NULL, 'n'},
		{"logoff", 0, NULL, 'l'},       
		{ NULL, 0, NULL, 0},
	};
	//命令行包含的选项
	static const char *options="u::p::n::l::h";
	if(argc==1)
	{
		print_help();
		exit(-1);
	}

	while((opt=getopt_long(argc,argv,options,long_options,NULL))!=-1)
	{
		switch(opt)
		{
			//用户名
			case 'u':
			if(checkprocess() == -1)
			{
				fprintf(stderr, "%s","用户已经登录!\n");
				exit(-1);
			}
			if(argv[optind] == NULL)
			{
				getUserName();
				getPassword();
				getDevice();
			}
			else
			{
				if(argv[optind+1] == NULL)
				{
					strcpy(username, argv[optind]);
					//clean argv[]
					strncpy(argv[optind], "*****", strlen(argv[optind]));
					getPassword();
					getDevice();
				}
				else
				{
					strcpy(username, argv[optind]);
					//clean argv[]
					strncpy(argv[optind], "*****", strlen(argv[optind]));
				}
			}
			break;
			//密码
			case 'p':
			if(checkprocess() == -1)
			{
				fprintf(stderr, "%s\n","用户已经登录!\n");
				exit(-1);
			}
			if(strlen(username) == 0)
			{
				getUserName();
				getPassword();
				getDevice();
			}
			else if(argv[optind]==NULL)
			{
				getPassword();
				getDevice();
			}
			else if(argv[optind+1]==NULL)
			{
				strcpy(password, argv[optind]);
				//clean argv[]
				strncpy(argv[optind], "*****", strlen(argv[optind]));
				getDevice();
			}
			else
			{
				strcpy(password,argv[optind]);
				//clean argv[]
				strncpy(argv[optind], "*****", strlen(argv[optind]));
			}
			break;
			//网卡名称 
			case 'n':
			if(checkprocess() == -1)
			{
				fprintf(stderr, "%s\n","用户已经登录!\n");
				exit(2);
			}
			if(username == NULL)
			{
				getUserName();
				getPassword(); 
				getDevice();
			}
			else if(password==NULL)
			{
				getPassword();
				getDevice();
			}
			else if(argv[optind]==NULL)
				getDevice();
			else
				strcpy(devicename,argv[optind]);
			break;
			//帮助信息
			case 'h':
				print_help();
				exit(0);
				break;
			//注销
			case 'l':
			if(argv[optind]==NULL)
				getDevice();
			else
				strcpy(devicename,argv[optind]);
			SendLogoffPkt(devicename);
			exit(0);
			break;
			case '?':
				printf("未识别的选项!\n请尝试执行“xdh3c --help”来获取更多信息。\n");
				exit(1);
				break;
		}//switch
	}//while
       
	if((strlen(username)!=0)&&(strlen(password)!=0)&&(strlen(devicename)!=0))
	{
	//	printf("%s %s %s\n",username,password,devicename);
		Authentication(username,password,devicename);
	}
	else
		fprintf(stderr,"%s\n","用户名、密码和网卡名称不能为空!");
    return 0;
}
コード例 #4
0
int main(int argc, char *argv[])
{
	char *UserName = NULL;
	char *Password = NULL;
	char *DeviceName = NULL;
	char buf[256];

	if (argc < 3 || argc > 4) {
		char *appname;
#if defined(WIN32)
		int len, i;
		appname = argv[0];
		len = strlen(appname);

		for (i = len - 1; i > 0; i--) {
			if (appname[i] == '\\' || appname[i] == '/') {
				appname = appname + i + 1;
				break;
			}
		}
#else
		appname = argv[0];
#endif
		fprintf(stderr, "命令行参数错误!\n");
		fprintf(stderr,	"正确的调用格式例子如下:\n");
		fprintf(stderr,	"    %s username password\n", appname);
		fprintf(stderr,	"    %s username password eth0\n", appname);
		fprintf(stderr,	"    %s username password eth1\n", appname);
		fprintf(stderr, "(注:若不指明网卡,默认情况下将会进行网卡选择)\n");
		exit(-1);
	} else if (argc == 4) {
		DeviceName = argv[3]; // 允许从命令行指定设备名
	} else {
		// 缺省情况下使用的设备
		char errbuf[PCAP_ERRBUF_SIZE];
		pcap_if_t *alldevs;
		pcap_if_t *dev;
		char key;

		if (pcap_findalldevs(&alldevs, errbuf) == -1) {
			fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
			exit(1);
		}

		printf("Select an adapter by input Y\n");

		for (dev = alldevs; dev != NULL; dev = dev->next) {
			printf("%s (%s)\n", dev->name, dev->description);
			key = getchar();
			if (key == 'Y' || key == 'y') {
				strcpy(buf, dev->name);
				DeviceName = buf;
				break;
			}
		}

		pcap_freealldevs(alldevs);
	}

	if (!DeviceName) {
		printf("Please select an adapter!\n");
		exit(-1);
	}

	UserName = argv[1];
	Password = argv[2];

	Authentication(UserName, Password, DeviceName);
	
	return 0;
}
コード例 #5
0
ファイル: main.c プロジェクト: kxion/agan8021xclient
int main(int argc, char* argv[])
{
    pcap_if_t *d;
    int i;
    int iMax;
    int inum;
    char *UserName;
    char *Password;
    char DeviceName[128];
    const size_t DEVICE_NAME_MAX=sizeof(DeviceName)-1;

    if (argc >= 3)
    {
        UserName = argv[1];
        Password = argv[2];
        fprintf(stderr, "USERNAME=%s\n", UserName);
        fprintf(stderr, "PASSWORD=%s\n", Password);
    }

    /* 检查命令行参数格式 */
    if (argc<3)
    {
        fprintf(stderr, "命令行参数错误!\n");
        fprintf(stderr,	"正确的格式为:\n");
        fprintf(stderr,	"    %s username password [netcard]\n", argv[0]);
        fprintf(stderr, "(注:不指明网卡时将提示用户手动选择,但用户名和秘码是必须放在命令行中的)\n");/*TODO: 界面有待改进*/
        exit(-1);
    }
    else if (argc == 4 && argv[3] != NULL)
    {/* 从命令行指定网卡接口设备名 */
        size_t n = strlen(argv[3]);
        if (DEVICE_NAME_MAX < n)
        {   n = DEVICE_NAME_MAX;
        }
        memcpy(DeviceName, argv[3], n);
        DeviceName[n] = '\0';
        /* FIXME: 这里没有检查用户指定的网卡名称是否存在,以及能否被libnet和libpcap打开并进行操作 */
        /* TODO: CheckDevice(DeviceName); */
        fprintf(stderr, "NETCARD=%s\n", DeviceName);
    } else
    {/* 不指明网卡时将提示用户手动选择 */
        pcap_if_t *alldevs;
        char errbuf[PCAP_ERRBUF_SIZE];
        /* 获取设备列表(通过libpcap) */
        if (pcap_findalldevs(&alldevs, errbuf) == -1)
        {
            fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
            exit(1);
        }

        fprintf(stderr, "NETCARD=\n");
        d = alldevs;
        i = iMax = 0;
        while (d != NULL)
        {
            if (d->name && strcmp(d->name, "lo")!=0 && strcmp(d->name, "any")!=0 && strcmp(d->name, "")!=0)
            {
                i++;
                printf("%d.(%s)\n", i, d->name);
            }
            d = d->next;
        }
        iMax = i;
        if(iMax==0)
        {
            fprintf(stderr, "\nNo interfaces found! Make sure libpcap is installed and you are root.\n");
            exit(1);
        }
        printf("\nPlease choose net card (1-%d):",iMax);
        inum = 0;
        scanf("%d", &inum);
        while (inum<=0 || inum>iMax)
        {
            int ch;
            fprintf(stderr, "Error: Unexpected input!\n");
            if (!feof(stdin))
            {   do { /* 清空stdin输入流中剩余的字符, 通常是scanf读取后遗留的回车符'\n' */
                    ch = fgetc(stdin);
                   } while (ch != EOF && ch != '\n');
            }
            printf("Please choose net card (1-%d):",iMax);
            inum = 0;
            scanf("%d", &inum);
        }

        i = 1;
        d = alldevs;
        while (i < inum)
        {
            if (d->name && strcmp(d->name, "lo")!=0 && strcmp(d->name, "any")!=0 && strcmp(d->name, "")!=0)
            {
                i++;
            }
            d=d->next;
        }
        size_t n = strlen(d->name);
        if (n > DEVICE_NAME_MAX)
        {   n = DEVICE_NAME_MAX;
        }
        memcpy(DeviceName, d->name, n);
        DeviceName[n] = '\0';
        printf("%d.(%s)\n", inum, DeviceName);
        pcap_freealldevs(alldevs);
    }

    /* 调用子函数完成802.1X认证 */
    Authentication(UserName, Password, DeviceName);
    return(0);
}
コード例 #6
0
const char * GetDeviceList()
{
	pcap_if_t *alldevs;
	pcap_if_t *d;
	int i=0,counter;
	char errbuf[PCAP_ERRBUF_SIZE];
	string dNameList[32];
	string dDeviceList[64];
	/* 获取本地机器设备列表 */
	if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)
	{
		fprintf(stderr,"Error in pcap_findalldevs_ex: %s\n", errbuf);
		exit(1);
	}
	counter=0;
	/* 打印列表 */
	cout.setf(ios::left);
	cout<<"请选择你要使用的网卡:"<<endl;
	cout<<setw(5)<<"序号 "<<setw(70)<<"网卡名称"<<"网卡描述"<<endl;
	for(d=alldevs; d != NULL; d= d->next)
	{

		cout<<setw(5)<<++i;
		
		cout<<setw(69)<<d->name;
		dNameList[counter]=d->name;
		counter++;
		if (d->description)printf(" (%s)\n", d->description);
		else printf(" (No description available)\n");
	}
	if (i == 0)
	{
		printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
		return "";
	}
	/* 不再需要设备列表了,释放它 */
	pcap_freealldevs(alldevs);
	int selection = 0;
	const char *DeviceName;
	cout<<"请选择序号:";
	while (1)
	{
		cin>>selection;
		if (selection > counter-1)continue;
		else
		{
			DeviceName=dNameList[selection-1].c_str();
			break;
		}
	};
	const char *au ,*bp,*dName;
	char a[32],b[128];
	cout<<"请输入用户名:";
	scanf("%s",a);
	cout<<"请输入密码:";
	scanf("%s",b);
	au=a;
	bp=b;
	if (DeviceName != "")cout<<Authentication(a,b,DeviceName);
	return DeviceName;

}
コード例 #7
0
ファイル: main.c プロジェクト: Vincent-bin/scutclient
int main(int argc, char *argv[])
{
	LogWrite(INF,"%s","#Start scutclient#");
	int client=0;
	printf("\n***************************************************************\n\n");
	printf("SCUTclient is based on njit8021xclient which is made by liuqun.\n");
	printf("Welcome to join in Router of SCUT QQ group 262939451.\n\n");
	printf("\n***************************************************************\n");
	/* 检查当前是否具有root权限 */
	if (getuid() != 0) {
		LogWrite(ERROR,"%s","Sorry,it is unroot.");
		printf("Sorry,it is unroot.\n");
		exit(-1);
	}

	/* 检查命令行参数格式 */
	if (argc<2 || argc>5) {
		printf("Command is Illegal ,You can input command like this:\n");
		printf("    %s username\n", argv[0]);
		printf("    %s username password \n", argv[0]);
		printf("    %s username password Interface_Of_Wan\n", argv[0]);
		printf("    %s inode username\n", argv[0]);
		printf("    %s inode username password \n", argv[0]);
		printf("    %s inode username password Interface_Of_Wan\n", argv[0]);
		printf("    %s digital username\n", argv[0]);
		printf("    %s digital username password \n", argv[0]);
		printf("    %s digital username password Interface_Of_Wan\n", argv[0]);
		exit(-1);
	} 


	if(*argv[1]!='i' || *argv[1]!='d'||*argv[1]!='I' || *argv[1]!='D')
	{
	client = 1;
		if (argc == 4)
		{
			DeviceName = argv[3]; // 允许从命令行指定设备名
			UserName = argv[1];
			Password = argv[2];	
		} 
		if (argc == 3 || argc == 2) 
		{
			UserName = argv[1];
			if (argc == 2)
			{
				Password = UserName;// 用户名和密码相同
			}
			else 
			{
				Password = argv[2];
			}
			FILE   *stream;
			char   buf[32]={0};
			char   tmp[32]={0} ;
			int	count = 0;
			//memset( buf, '/0', sizeof(buf) );
			stream = popen( "uci get network.wan.ifname", "r" );
			if(stream == NULL)
				printf("Command error : uci get network.wan.ifname not found , this command is used on OpenWRT");
			else
			{
				count = fread( buf, sizeof(char), sizeof(buf), stream); 
				DeviceName=tmp;
				memcpy(DeviceName, buf , count-1);
			}
			pclose( stream ); 
		} 
	}
	
	if( *argv[1]=='i' || *argv[1]=='I')
	{
		client = 2;
		if (argc == 5)
		{

			DeviceName = argv[4]; // 允许从命令行指定设备名
			UserName = argv[2];
			Password = argv[3];	
		} 
		if (argc == 4 || argc == 3) 
		{
			UserName = argv[2];
			if (argc == 3)
			{
				Password = UserName;// 用户名和密码相同
			}
			else 
			{
				Password = argv[3];
			}
			FILE   *stream;
			char   buf[32]={0};
			char   tmp[32]={0} ;
			int	count = 0;
			//memset( buf, '/0', sizeof(buf) );
			stream = popen( "uci get network.wan.ifname", "r" );
			if(stream == NULL)
				printf("Command error : uci get network.wan.ifname not found , this command is used on OpenWRT\n");
			else
			{
				count = fread( buf, sizeof(char), sizeof(buf), stream); 
				DeviceName=tmp;
				memcpy(DeviceName, buf , count-1);
			}
			pclose( stream ); 
		} 
	}
	
	if( *argv[1]=='d' || *argv[1]=='D')
	{
	client = 3;
		if (argc == 5)
		{
			DeviceName = argv[4]; // 允许从命令行指定设备名
			UserName = argv[2];
			Password = argv[3];	
		} 
		if (argc == 4 || argc == 3) 
		{
			UserName = argv[2];
			if (argc == 3)
			{
				Password = UserName;// 用户名和密码相同
			}
			else 
			{
				Password = argv[3];
			}
			FILE   *stream;
			char   buf[32]={0};
			char   tmp[32]={0} ;
			int	count = 0;
			//memset( buf, '/0', sizeof(buf) );
			stream = popen( "uci get network.wan.ifname", "r" );
			if(stream == NULL)
				printf("Command error : uci get network.wan.ifname not found , this command is used on OpenWRT\n");
			else
			{
				count = fread( buf, sizeof(char), sizeof(buf), stream); 
				DeviceName=tmp;
				memcpy(DeviceName, buf , count-1);
			}
			pclose( stream ); 
		} 
	}

	/* 调用子函数完成802.1X认证 */
	Authentication(client);

	return (0);
}
コード例 #8
0
ファイル: TClientSockThread.cpp プロジェクト: IshPeredysh/udd
void TClientSockThread::AcceptClient()
{
	int iResult;
	int iSendResult;
	char recvbuf[DEFAULT_BUFLEN];
	char sandbuf[DEFAULT_BUFLEN];
	int recvbuflen = DEFAULT_BUFLEN;

	bool IsData;
	int CommandID, CurCommandID;
	int DataType, CurDataType;
	TMemoryStream *ms = new TMemoryStream;

	if (Authentication(ClientSocket, ms))	{

		CurCommandID = -1;
		// Receive until the peer shuts down the connection
		do {
			iResult = recv(ClientSocket, recvbuf, recvbuflen, 0);
			if (iResult > 0) {
				Form1->m->Lines->Append("Bytes received: " + IntToStr(iResult));

				CommandID = GetCommand(recvbuf, iResult);
				if (CommandID == CM_EXEC) {
					RunCommand( ClientSocket, CurCommandID, ms);
					StrCopy(sandbuf, "ok\0");
					iSendResult = send( ClientSocket, sandbuf, strlen(sandbuf), 0 );
				}
				else if (CommandID) {
					CurCommandID = CommandID;
					ms->Clear();
					StrCopy(sandbuf, "ok\0");
					iSendResult = send( ClientSocket, sandbuf, strlen(sandbuf), 0 );
				}
				else	{
					ms->Write(recvbuf, iResult);
					StrCopy(sandbuf, "ok\0");
					iSendResult = send( ClientSocket, sandbuf, strlen(sandbuf), 0 );
				}

	//

	// Echo the buffer back to the sender
	//			iSendResult = send( ClientSocket, recvbuf, iResult, 0 );
	//			if (iSendResult == SOCKET_ERROR) {
	//				Form1->m->Lines->Append("send failed with error: " + IntToStr(WSAGetLastError()));
	//				closesocket(ClientSocket);
	//				WSACleanup();
	//				return;
	//			}
	//			Form1->m->Lines->Append("Bytes sent: " + IntToStr(iSendResult));


			}
			else if (iResult == 0)
				Form1->m->Lines->Append("Connection closing...\n");
			else  {
				Form1->m->Lines->Append("recv failed with error: " + IntToStr(WSAGetLastError()));
				closesocket(ClientSocket);
				WSACleanup();
				delete ms;
				return;
			}

		} while (iResult > 0);
	}

	// shutdown the connection since we're done
	iResult = shutdown(ClientSocket, SD_SEND);
	if (iResult == SOCKET_ERROR) {
		Form1->m->Lines->Append("shutdown failed with error: " + IntToStr(WSAGetLastError()));
		closesocket(ClientSocket);
		WSACleanup();
		delete ms;
		return;
	}

	// cleanup
	closesocket(ClientSocket);
	delete ms;
}