예제 #1
0
int checkparameter(int argc,char** argv,PHGlobal *pglobal,PH_parameter *parameter)
{
	int i = 0,repma = 0;

#ifndef WIN32
	strcpy(parameter->szconfig,"/etc/phlinux.conf");
#else
	strcpy(parameter->szconfig,"d:\phlinux.ini");
#endif
	for( i=1;i<argc;i++ ) {
		if(strcmp(argv[i],"-i")==0||strcmp(argv[i],"--interact")==0) {
/*			if(parameter->bAppointIni) {
				if(parameter->bAppointIni)
				{
					HelpPrint();
					return -1;
				}
				parameter->bNewIni=1;
			}*/
			parameter->bNewIni=1;
		}
		else if(strcmp(argv[i],"-d")==0||strcmp(argv[i],"--daemon")==0)
		{
			parameter->bDaemon=1;
		}
		else if(strcmp(argv[i],"-c")==0||strcmp(argv[i],"--config")==0)
		{
			parameter->bAppointIni=1;
			if(++i<argc) {
				if(parameter->bNewIni || strchr(argv[i],'-')!=NULL) {
					HelpPrint();
					return -1;
				}
				memset(parameter->szconfig,0,sizeof(parameter->szconfig));
				strcpy(parameter->szconfig,argv[i]);
			}
			else
			{
				printf("Please appoint configuration file!\n");
				return -1;
			}
		}
		else if(strcmp(argv[i],"-u")==0||strcmp(argv[i],"--user")==0)
		{
			parameter->bUser=1;
			if(++i<argc)
			{
				if(strchr(argv[i],'-')!=NULL)
				{
					HelpPrint();
					return -1;
				}
				strcpy(parameter->szuserName,argv[i]);
			}
			else
			{
				printf("Please appoint user name!\n");
				return -1;
			}
		}
		else if(strcmp(argv[i],"-f")==0||strcmp(argv[i],"--first-run")==0)
		{
			parameter->bFirstRun=1;
		}
		else
		{
			HelpPrint();
			return -1;
		}
	}
	if ( i == 1)
	{
		InitIni(pglobal,parameter);
		BindNic(pglobal,parameter);
	}

	repma = ParameterAnalysis(argc,argv,pglobal,parameter);
	if( repma !=0 )
		return -1;

	return 0;
}
예제 #2
0
int ParameterAnalysis(int argc,char *argv[],PHGlobal *pglobal,PH_parameter *parameter)
{
	BOOL rin;
	
	if(parameter->bFirstRun)
	{
		if(parameter->bNewIni||parameter->bDaemon||parameter->bAppointIni||parameter->bUser)
		{
			HelpPrint();
			return -1;
		}
		else
		{
			NewIni(parameter->szconfig,pglobal,parameter);
			exit (0);
		}
	}
	if(parameter->bUser)
	{	
#ifndef WIN32
		char command[1024];
		int i = 0;
		memset(command,0,sizeof(command));
		sprintf(command,"su %s -c \"",parameter->szuserName);
		for( i = 0;i < argc; i++ ) {
			if( !strcmp( argv[i], "-u" ) )
				continue;
			else if( i>0 && !strcmp( argv[i-1], "-u"  ) )
				continue;
			sprintf(command,"%s %s",command,argv[i]);
		}
		sprintf(command,"%s \"",command);
		system(command);
/*		ostringstream ostr;
		ostr<<"su "<<userName<<" -c "<<"\""<<argv[0];
		for(m_comIterator=m_comList.begin(); m_comIterator!=m_comList.end();++m_comIterator)
			ostr<<" "<<*m_comIterator;
		ostr<<"\"";
		std::string gstr=ostr.str();
		system(gstr.c_str());*/
#endif
		return -1;
	}  	
	if(parameter->bNewIni)
	{
		memset(parameter->szconfig,0,sizeof(parameter->szconfig));
		if( strlen(parameter->szconfig) == 0 )
#ifndef WIN32
			strcpy(parameter->szconfig,"/etc/phlinux.conf");
#else
			strcpy(parameter->szconfig,"D:\\phlinux.ini");
#endif
		if( NewIni(parameter->szconfig,pglobal,parameter) != 0 )
			return -1;
		BindNic( pglobal,parameter );
	}
	if(parameter->bAppointIni)
	{
		if( LoadFile( pglobal,parameter ) != 0 )
			return -1;
		BindNic( pglobal,parameter );
	}
	if(parameter->bDaemon)
	{
		if(!parameter->bNewIni && !parameter->bAppointIni)
		{
			if( InitIni(pglobal,parameter) != 0 )
				return -1;
			BindNic( pglobal,parameter );
		}
//		LOG(1)(" bNewIni[%d] and bAppointIni[%d] has an unexpected error,please check it.",parameter->bNewIni,parameter->bAppointIni);
//		rin=InDaemon();
//		if(!rin)
//			return -1;	
	}

	return 0;
}
예제 #3
0
int main(int argc, char *argv[])
{
	int FileLength = 0;
	uint32_t BIOSOffset = 0;
	unsigned char *BIOSImage = NULL;
	int fd;
	uint32_t Offset1, Offset2;
	int i, len;
	unsigned char *tmp;

	if ((argc != 2) || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
		HelpPrint(argv[0]);
		return 1;
	}

	fd = open(argv[1], O_RDONLY);
	if (fd < 0) {
		fprintf(stderr, "Error: Failed to open %s: %s\n", argv[1],
			strerror(errno));
		return 1;
	}

	FileLength = lseek(fd, 0, SEEK_END);
	if (FileLength < 0) {
		fprintf(stderr, "Error: Failed to lseek \"%s\": %s\n", argv[1],
			strerror(errno));
		return 1;
	}

	BIOSOffset = (0x100000 - FileLength) & 0xFFFFF;

	BIOSImage = mmap(NULL, FileLength, PROT_READ, MAP_PRIVATE, fd, 0);
	if (BIOSImage < 0) {
		fprintf(stderr, "Error: Failed to mmap %s: %s\n", argv[1],
			strerror(errno));
		return 1;
	}

	printf("Using file \"%s\" (%ukB)\n", argv[1], FileLength >> 10);

	for (i = 0; BIOSIdentification[i].Handler; i++) {
		len = strlen(BIOSIdentification[i].String1);
		tmp =
		    memmem(BIOSImage, FileLength - len,
			   BIOSIdentification[i].String1, len);
		if (!tmp)
			continue;
		Offset1 = tmp - BIOSImage;

		len = strlen(BIOSIdentification[i].String2);
		tmp =
		    memmem(BIOSImage, FileLength - len,
			   BIOSIdentification[i].String2, len);
		if (!tmp)
			continue;
		Offset2 = tmp - BIOSImage;

		if (BIOSIdentification[i].Handler
		    (BIOSImage, FileLength, BIOSOffset, Offset1, Offset2))
			return 0;
		else
			return 1;
	}

	fprintf(stderr, "Error: Unable to detect BIOS Image type.\n");
	return 1;
}