Esempio n. 1
0
void test_odb_backend_simple__read_with_hash_mismatch_fails(void)
{
	const fake_object objs[] = {
		{ "1234567890123456789012345678901234567890", "nonmatching content" },
		{ NULL, NULL }
	};

	setup_backend(objs);

	cl_git_pass(git_oid_fromstr(&_oid, objs[0].oid));
	cl_git_fail_with(GIT_EMISMATCH, git_odb_read(&_obj, _odb, &_oid));
}
Esempio n. 2
0
void test_odb_backend_simple__exists_fails_for_nonexisting_object(void)
{
	const fake_object objs[] = {
		{ "f6ea0495187600e7b2288c8ac19c5886383a4632", "foobar" },
		{ NULL, NULL }
	};

	setup_backend(objs);

	cl_git_pass(git_oid_fromstr(&_oid, "f6ea0495187600e7b2288c8ac19c5886383a4633"));
	cl_assert(git_odb_exists(_odb, &_oid) == 0);
}
Esempio n. 3
0
void test_odb_backend_simple__read_of_nonexisting_object_fails(void)
{
	const fake_object objs[] = {
		{ "f6ea0495187600e7b2288c8ac19c5886383a4632", "foobar" },
		{ NULL, NULL }
	};

	setup_backend(objs);

	cl_git_pass(git_oid_fromstr(&_oid, "f6ea0495187600e7b2288c8ac19c5886383a4633"));
	cl_git_fail_with(GIT_ENOTFOUND, git_odb_read(&_obj, _odb, &_oid));
}
Esempio n. 4
0
void test_odb_backend_simple__exists_succeeds(void)
{
	const fake_object objs[] = {
		{ "f6ea0495187600e7b2288c8ac19c5886383a4632", "foobar" },
		{ NULL, NULL }
	};

	setup_backend(objs);

	cl_git_pass(git_oid_fromstr(&_oid, objs[0].oid));
	cl_assert(git_odb_exists(_odb, &_oid));
}
Esempio n. 5
0
void test_odb_backend_simple__exists_with_ambiguous_prefix_fails(void)
{
	const fake_object objs[] = {
		{ "1234567890111111111111111111111111111111", "first content" },
		{ "1234567890222222222222222222222222222222", "second content" },
		{ NULL, NULL }
	};

	setup_backend(objs);

	cl_git_pass(git_oid_fromstr(&_oid, objs[0].oid));
	cl_git_fail_with(GIT_EAMBIGUOUS, git_odb_exists_prefix(NULL, _odb, &_oid, 7));
}
Esempio n. 6
0
void test_odb_backend_simple__read_prefix_succeeds(void)
{
	const fake_object objs[] = {
		{ "f6ea0495187600e7b2288c8ac19c5886383a4632", "foobar" },
		{ NULL, NULL }
	};

	setup_backend(objs);

	cl_git_pass(git_oid_fromstr(&_oid, "f6ea0495187600e7b2288c8ac19c5886383a4632"));
	cl_git_pass(git_odb_read(&_obj, _odb, &_oid));

	assert_object_contains(_obj, objs[0].content);
}
Esempio n. 7
0
void test_odb_backend_simple__read_with_hash_mismatch_succeeds_without_verification(void)
{
	const fake_object objs[] = {
		{ "1234567890123456789012345678901234567890", "nonmatching content" },
		{ NULL, NULL }
	};

	setup_backend(objs);
	cl_git_pass(git_oid_fromstr(&_oid, objs[0].oid));

	cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 0));
	cl_git_pass(git_odb_read(&_obj, _odb, &_oid));

	assert_object_contains(_obj, objs[0].content);
}
Esempio n. 8
0
void test_odb_backend_simple__exists_prefix_succeeds(void)
{
	const fake_object objs[] = {
		{ "1234567890111111111111111111111111111111", "first content" },
		{ "1234567890222222222222222222222222222222", "second content" },
		{ NULL, NULL }
	};
	git_oid found;

	setup_backend(objs);

	cl_git_pass(git_oid_fromstr(&_oid, objs[0].oid));
	cl_git_pass(git_odb_exists_prefix(&found, _odb, &_oid, 12));
	cl_assert(git_oid_equal(&found, &_oid));
}
Esempio n. 9
0
void test_odb_backend_simple__read_with_highly_ambiguous_prefix(void)
{
	const fake_object objs[] = {
		{ "1234567890111111111111111111111111111111", "first content" },
		{ "1234567890111111111111111111111111111112", "second content" },
		{ NULL, NULL }
	};

	setup_backend(objs);

	cl_git_pass(git_oid_fromstr(&_oid, objs[0].oid));
	cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 0));
	cl_git_fail_with(GIT_EAMBIGUOUS, git_odb_read_prefix(&_obj, _odb, &_oid, 39));
	cl_git_pass(git_odb_read_prefix(&_obj, _odb, &_oid, 40));
	assert_object_contains(_obj, objs[0].content);
}
Esempio n. 10
0
void test_odb_backend_simple__null_oid_is_ignored(void)
{
	const fake_object objs[] = {
		{ "0000000000000000000000000000000000000000", "null oid content" },
		{ NULL, NULL }
	};
	git_oid null_oid = {{0}};
	git_odb_object *obj;

	setup_backend(objs);

	cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 0));
	cl_assert(!git_odb_exists(_odb, &null_oid));

	cl_git_fail_with(GIT_ENOTFOUND, git_odb_read(&obj, _odb, &null_oid));
	cl_assert(giterr_last() && strstr(giterr_last()->message, "null OID"));
}
Esempio n. 11
0
int main (int argc, char *argv[])
{
  fd_set readset;
  fd_set writeset;
  int n, sel;
  int c, errflg=0;
  struct sigaction sigact;
  sigset_t sigmask;
  char *scratch, *next_scratch;
  char nmea_buf[1024];
  char send_buf[1024];
  int  gps_buf[15];
  int  nmea_index = 0;
  int  send_len = 0;
  /* Set default options */
  outfile = stdout;
  int sAnt = 0;

  memset(gps_buf, 0, 15);
  memset(send_buf, 0, 1024);
  send_len = 0;

  /* Process options */
  while ((c = getopt(argc, argv, "Vlqvs:o:p:t:m:u:g:/:")) != EOF)
    switch (c) {
      case 'q':
	quiet=1;
	break;
      case 'v':
        verbose = 1;
        break;
      case 'l':
        linebuff = 1;
        break;
      case 'p':
        opt_ptyname = optarg;
        break;
      case 't':
        opt_ttyname = optarg;
        break;
      case 'm':
	/* mode for pty: [user,[group,]]mode */
	scratch = strdup(optarg);
	if ((next_scratch = strchr(scratch,',')) != NULL) {
	  /* Username */
	  *next_scratch = '\0';
	  next_scratch++;

	  frontend_owner = find_uid(scratch);

	  scratch = next_scratch;

	  if ((next_scratch = strchr(scratch,',')) != NULL)
	  {
	    /* Group */
	    *next_scratch = '\0';
	    next_scratch++;
	    
	    frontend_group = find_gid(scratch);

	    scratch = next_scratch;
	  }
	}
	frontend_mode = strtol(scratch,NULL,8);
	break;
      case 'u':
	switch_uid = find_uid(optarg);
	break;
      case 'g':
	switch_gid = find_gid(optarg);
	break;
      case '/':
	switch_root = strdup(optarg);
	break;
      case 's':
        settings = optarg;
        break;
      case 'o':
        outfilename=optarg;
        if ( (outfile = fopen(outfilename,"w")) == NULL)
          errorf("Couldn't open output file '%s' for write: %s\n",outfilename,strerror(errno));
        break;
      case 'V':
	puts(VERSION);
	exit(0);
      case '?':
      default:
        errflg++;
        break;
    }

  if (errflg || ((argc-optind) < 1) || ((argc-optind) > 2)) {
    usage(argv[0]);
    exit (2);
  }

  /* Process the two non-flag options */
  backend = argv[optind];
  if ((argc-optind) == 2)
    frontend = argv[optind+1];
        
  if (strcmp(frontend,"-") == 0)
    frontend = NULL;
  if (linebuff)
    setlinebuf(outfile);

  atexit (closedown);
  /* Do some initialization */
  stty_initstore();

  sendudp_open();
  /* Setup backend */
  if (setup_backend(backfd) < 0)
    errorf ("select failed. errno = %d\n", errno);

  /* Setup frontend */
  if ((setup_frontend(frontfd)) < 0)
    errorf("setup_frontend failed: %s\n",strerror(errno));

  /* Drop privileges if we've been asked to */
  if (switch_root)
  {
    if (chroot(switch_root) != 0)
      errorf("chroot(%s) failed: %s\n",switch_root,strerror(errno));
  }
  if (switch_gid != -1)
  {
    if (setgroups(1,&switch_gid) == -1)
      errorf("setgroups(1,[%d]) failed: %s\n",switch_gid, strerror(errno));
    if (setregid(switch_gid, switch_gid) == -1)
      errorf("setregid(%d,%d) failed: %s\n",switch_gid,switch_gid);
    if (getgid() != switch_gid)
      errorf("setregid succeeded, but we're the wrong gid!");
    if (getegid() != switch_gid)
      errorf("setregid succeeded, but we're the wrong effective gid!");
  }
  if (switch_uid != -1)
  {
    if (setreuid(switch_uid, switch_uid) == -1)
      errorf("setreuid(%d,%d) failed: %s\n",switch_uid,switch_uid,strerror(errno));
    if (getuid() != switch_uid)
      errorf("setreuid succeeded, but we're the wrong uid!");
    if (geteuid() != switch_uid)
      errorf("setregid succeeded, but we're the wrong effective uid!");
  }

  
  /* calc (initial) max file descriptor to use in select() */
  fdmax = max(backfd[0], frontfd[0]);

  /* Set up signal handlers and such */
  sigemptyset(&sigmask);
  memset(&sigact,0,sizeof sigact);
  sigact.sa_handler = sigdeath;
  sigact.sa_mask = sigmask;

  sigaction(SIGHUP,&sigact,NULL);
  sigaction(SIGINT,&sigact,NULL);
  sigaction(SIGQUIT,&sigact,NULL);
  sigaction(SIGPIPE,&sigact,NULL);
  sigaction(SIGTERM,&sigact,NULL);

  sigact.sa_handler = sigchld;
  sigaction(SIGCHLD,&sigact,NULL);

  pthread_t udp_recv;
  pthread_create(&udp_recv, NULL, udp_recv_gnssmode_thread, NULL);
  pthread_detach(udp_recv);

  struct tm p;
  time_t timep;
  while (!please_die_now)
  {
    do
    {
      FD_ZERO (&readset);
      FD_SET (backfd[0], &readset);
      FD_SET (frontfd[0], &readset);
      FD_ZERO (&writeset);
      FD_SET (backfd[1], &writeset);
      FD_SET (frontfd[1], &writeset);
      sel = select(fdmax + 1, &readset, &writeset, NULL, NULL);
    }
    while (sel == -1 && errno == EINTR && !please_die_now);
    if (sel == -1 && errno != EINTR)
      errorf ("select failed. errno = %d\n", errno);
    else if (please_die_now)
      break;

    if (FD_ISSET(backfd[0], &readset))
    {
      if ((n = read(backfd[0], buff, BUFF_SIZE)) == 0)
      {
	/* Serial port has closed.  This doesn't really make sense for
	 * a real serial port, but for sockets and programs, probably
	 * we should just exit.
	 */
	if (!quiet)
	  errorf("Backend device was closed.\n");
	break;
      }
      else if (n < 0)
      {
	if ( (errno != EAGAIN) && (errno != EINTR) )
	{
	  errorf("Error reading from backend device: %s\n",strerror(errno));
	}
	break;
      }
      else
      {
	/* We should handle this better.  FIX */
    	if(FD_ISSET(frontfd[1], &writeset))
        {
        if (write (frontfd[1], buff, n) != n)
	  errorf("Error writing to frontend device: %s\n",strerror(errno));
        }
       // if (!quiet)
	     //   dumpbuff(1,buff,n);
	//nmea decode
	{
		tNmea_Msg nmeamsg ;	
	 	int i=0;
		int ret = 0;
		for(i=0; i<n; i++)
		{
			if(buff[i] == '$')
				nmea_index = 0;
			nmea_buf[nmea_index] = buff[i];
			if(buff[i] == '\r')
				nmea_buf[nmea_index] = 0;
			if(buff[i] == '\n')
			{
				nmea_buf[nmea_index] = 0;
                #if 0
        			if (!quiet)
					fprintf(outfile,"%s\n",nmea_buf);
                #endif
#if 1 
				
                ret = NmeaDecode(nmea_buf,&nmeamsg);
                
                if(nmeamsg.nMsgMask == GGA_DECODE)
                {
                    memset(send_buf, 0, 1024);
                    send_len = 0;
                }

                memcpy(send_buf+send_len, nmea_buf, nmea_index);
                send_len += strlen(nmea_buf);
                send_buf[send_len] = 0x0D;
                send_len ++;
                                    
				if(nmeamsg.nMsgMask & ANT_DECODE)
				{
					sAnt = nmeamsg.nAnttenaStatus;
					//sendudp(1011,&sAnt, 4);  //gui
					sAnt |= (nmeamsg.version<<8);
				}

				if(nmeamsg.nMsgMask & RMC_DECODE)
				{
				    if (nmea_buf[3] == 'R' && nmea_buf[4] == 'M' && nmea_buf[5] == 'C' )
				    {
                        if (!quiet)
                            fprintf(outfile,"%s=len=%d\n",nmea_buf, strlen(nmea_buf));
                        sendudp(1014,nmea_buf, strlen(nmea_buf));  //busdemaon
				    }
				}
                
				if(nmeamsg.nMsgMask >= 0x8F)
				{
				   sendudp(1012, send_buf, send_len);
                   sendudp(1011,&nmeamsg.aSvInfo, 2*sizeof(tSVData));  //gui satelite display
                   if (!quiet) 
                   {
                       //fprintf(outfile,"\r\n\r\n%s---------send_len=%d\n\n",send_buf,send_len);
                       
                       fprintf(outfile,"nAnttenaStatus=%d,position=%c mode=%d fy=%f fx=%f (%d-%d-%d)(%d:%d:%f)\n",
                           sAnt,
                           nmeamsg.cFixFlag,
                           NmeaGetRxRunMode(),
                           nmeamsg.fLatInDegree,
                           nmeamsg.fLonInDegree,
                           nmeamsg.usYear,    
                           nmeamsg.ucMonth,
                           nmeamsg.ucDay,                           
                           nmeamsg.usHours,    
                           nmeamsg.usMinutes,
                           nmeamsg.fSeconds);
                   }
                   #if 1
                   localtime_r(&timep, &p);
                   p.tm_sec = (int)nmeamsg.fSeconds;
                   p.tm_min = nmeamsg.usMinutes;
                   p.tm_hour = nmeamsg.usHours+8;
                   p.tm_mday = nmeamsg.ucDay;
                   p.tm_mon = nmeamsg.ucMonth-1;
                   p.tm_year = nmeamsg.usYear + 100;
                   timep = mktime(&p);
                    if(nmeamsg.cFixFlag == 'A')
                        gps_buf[0] = 1;
                    else
                        gps_buf[0] = 0;
                    gps_buf[1] = nmeamsg.fLonInDegree*1000000;
                    gps_buf[2] = nmeamsg.fLatInDegree*1000000;
                    gps_buf[3] = (int)timep;
                    gps_buf[4] = (int)timep;
                    gps_buf[5] = nmeamsg.fHeading;
                    gps_buf[6] = nmeamsg.fGroundVel*1.85;
                    if(nmeamsg.cLatIdx == 'S')
                        gps_buf[7] = 1;
                    else
                        gps_buf[7] = 0;
                    if(nmeamsg.cLonIdx == 'W')
                        gps_buf[8] = 1;
                    else
                        gps_buf[8] = 0;
                    gps_buf[9] = nmeamsg.fAltitude;    
                    
                    gps_buf[10] = NmeaGetRxRunMode();
                    gps_buf[11] = nmeamsg.aSvInfo[1].nSvsUsed;
                    gps_buf[12] = nmeamsg.aSvInfo[0].nSvsUsed;
                    gps_buf[13] = sAnt;
#if 0
                    printf("position=%d, flon=%d, flat=%d, %d, %d, iOrientation=%d, vel=%d, s=%d, w=%d, alt=%d, mode=%d, gps=%d, bd=%d\n",
                        gps_buf[0], gps_buf[1],gps_buf[2],gps_buf[3], gps_buf[4],gps_buf[5], gps_buf[6],gps_buf[7], gps_buf[8],gps_buf[9], gps_buf[10],
                        gps_buf[11], gps_buf[12]);
#endif
                    sendudp(1013, gps_buf, 4*14);
                    sendudp(1015, gps_buf, 4*14);  //busdemaon
                    memset(gps_buf, 0 , 15);
                    #endif
                    
                    memset(send_buf, 0, 1024);
                    send_len = 0;
				}
                
#endif
			}	
			nmea_index++;
//			fprintf(outfile,"nmea_index = %d\n",nmea_index);
			if(nmea_index >= 1024)
				nmea_index = 0;
				
		}	
	}
      }
    }

    if (please_die_now)
      break;

    if (FD_ISSET(frontfd[0], &readset))
    {
      if ((n = read(frontfd[0], buff, BUFF_SIZE)) == 0)
      {
        if (listenfd)
        {
          if (close(frontfd[0]) < 0)
            errorf("Couldn't close old frontfd: %s\n",strerror(errno));
          if ((frontfd[0]=frontfd[1]=accept(listenfd,NULL,NULL)) < 0)
            errorf("Couldn't accept new socket connection: %s\n",strerror(errno));
        }
          
      }
      else if (n <= 0)
      {
	if ( (errno == EAGAIN) || (errno == EINTR) )
	{
	  /* No real error */
	}
	else
	{
	  errorf("Error reading from frontend device: %s\n",strerror(errno));
	}
      }
      else
      {
        if (write (backfd[1], buff, n) != n)
	  errorf("Error writing to backend device: %s\n",strerror(errno));
	if (!quiet)
	  dumpbuff(0,buff,n);
      }
    }

  }
  stty_orig();
  exit(0);
}