Exemplo n.º 1
0
int Query(TVSocket *ClientSocket)
{
	char			CS[100];
	unsigned char	pszSig[16];
	SHashNode		*spNode;
	char        	*cmdPtr1;
	
	ClientSocket->ClearToLineEnd();
	ClientSocket->BWriteLine("200 Result Follows.",true);
	while(1)
	{
    	cmdPtr1=ClientSocket->GetToken();
    	strcpy(CS,cmdPtr1);
    	if( !strcmp(CS,".") )
    		break;
    	asc2bin(CS, 32, (char *)pszSig);
		spNode=Hash->Query(pszSig);
		if( !spNode )
			ClientSocket->BWriteLine("0\n",false);
		else if( spNode->cFlag==0 )
		{
			ClientSocket->BWriteLine("1\n",false);
			spNode->cFlag=1;
		}else
			ClientSocket->BWriteLine("2\n",false);
    }
    ClientSocket->FlushWB();
}
Exemplo n.º 2
0
void
special_test_blf (void)
{
  u_int8_t *akey = "0123456789ABCDEFF0E1D2C3B4A59687";
  u_int8_t *aiv = "FEDCBA9876543210";
  u_int8_t data[] = "7654321 Now is the time for \0\0\0"; /* len 29 */
  u_int8_t *acipher
    = "6B77B4D63006DEE605B156E27403979358DEB9E7154616D959F1652BD5FF92CCE7";
  u_int8_t key[16], cipher[32], iv[8];
  struct crypto_xf *xf;
  struct keystate *ks;
  enum cryptoerr err;
  int i;

  asc2bin (key, akey, strlen (akey));
  asc2bin (iv, aiv, strlen (aiv));
  asc2bin (cipher, acipher, 64);

  xf = crypto_get (BLOWFISH_CBC);
  printf ("Special Test-Case %s: ", xf->name);

  ks = crypto_init (xf, key, 16, &err);
  if (!ks)
    {
      printf ("FAILED (init %d)", err);
      goto fail;
    }

  crypto_init_iv (ks, iv, xf->blocksize);
  crypto_encrypt (ks, data, 32);

  for (i = 0; i < 32; i++)
    if (data[i] != cipher[i])
	break;
  if (i < 32)
    printf ("FAILED ");
  else
    printf ("OKAY ");

  free (ks);

fail:
  printf ("\n");
  return;
}
Exemplo n.º 3
0
bool LoadCS(char *pszFileName)
{
	FILE		*fpCS;
	SHashNode	*spNode=NULL;
	char		czBuffer[LINE_BUF_LEN+1];

	strcpy(g_pszCSFile,pszFileName);
	if( (fpCS=fopen(pszFileName,"r")) == NULL )
		return false;
	while( fgets(czBuffer,LINE_BUF_LEN,fpCS) )
	{
		if( strlen(czBuffer)==33 )
		{
			spNode=(SHashNode *)Memory->Malloc(sizeof(SHashNode));
			asc2bin(czBuffer,32,(char *)spNode->pszSignature);
			Hash->Insert(spNode);
			spNode->cFlag=0;
		}
	}
	fclose(fpCS);
	return true;
}
Exemplo n.º 4
0
// START FUNC DECL
int
qtils(
      int argc,
      char **argv,
      char *rslt_buf,
      int sz_rslt_buf
      )
// STOP FUNC DECL
{
  int status = 0;
  int itemp;
  if ( ( argc <= 1 ) || ( argc >= 14 ) )  {go_BYE(-1); }
  if ( strcmp(argv[1], "time_since_epoch") == 0 ) { 
    if ( argc != 3 ) { go_BYE(-1); }
    if ( strcmp(argv[2], "usec") == 0 ) { 
      sprintf(rslt_buf, "%llu", get_time_usec());
    }
    else if ( strcmp(argv[2], "sec") == 0 ) { 
      status = time1(&itemp); cBYE(status);
      sprintf(rslt_buf, "%d", itemp);
    }
  }
  else if ( strcmp(argv[1], "hdfs_get") == 0 ) { 
    if ( argc != 11 ) { fprintf(stderr, "argc = %d \n", argc); go_BYE(-1); }
    char url[4096]; zero_string(url, 4096); int port;

    char *username = argv[2]; // 
    char *server   = argv[3]; // 
    char *str_port = argv[4]; // 
    char *from     = argv[5]; // /user/<username>/XXXXX/part-r-00000
    if ( *username == '\0' ) { go_BYE(-1); }
    if ( *server   == '\0' ) { go_BYE(-1); }
    if ( *str_port == '\0' ) { go_BYE(-1); }
    if ( *from     == '\0' ) { go_BYE(-1); }
    //----------------------------------------------------
    if ( *from != '/' ) { go_BYE(-1); }
    status = stoI4(str_port, &port); cBYE(status);
    if ( port < 1024 ) { go_BYE(-1); }
    //----------------------------------------------------
    strcpy(url, "http://");
    strcat(url, server); 
    strcat(url, ":"); 
    strcat(url, str_port);
    strcat(url, "/webhdfs/v1");
    strcat(url, from);
    status = hdfs_get(username, url, argv[6], argv[7], argv[8], argv[9], argv[10]); 
    cBYE(status);
  }
  else if ( strcmp(argv[1], "replace_char") == 0 ) { 
    if ( argc != 5 ) { go_BYE(-1); }
    status = replace_char(argv[2], argv[3], argv[4]); cBYE(status);
  }
  else if ( strcmp(argv[1], "tab_split") == 0 ) {
    if ( argc != 7 ) { go_BYE(-1); }
    status = tab_split(argv[2], argv[3], argv[4], argv[5], argv[6]); cBYE(status);
  }
  else if ( strcmp(argv[1], "qhead") == 0 ) {
    if ( argc != 5 ) { go_BYE(-1); }
    status = qhead(argv[2], argv[3], argv[4]); cBYE(status);
  }
  else if ( strcmp(argv[1], "chk_ascii") == 0 ) {
    if ( argc != 3 ) { go_BYE(-1); }
    status = chk_ascii(argv[2]); cBYE(status);
  }
  else if ( strcmp(argv[1], "urlencode") == 0 ) {
    if ( argc != 3 ) { go_BYE(-1); }
    status = ext_url_encode(argv[2], rslt_buf, sz_rslt_buf); cBYE(status);
  }
  else if ( strcmp(argv[1], "urldecode") == 0 ) {
    if ( argc != 3 ) { go_BYE(-1); }
    status = ext_url_decode(argv[2], rslt_buf, sz_rslt_buf); cBYE(status);
  }
  else if ( strcmp(argv[1], "esc_for_latex") == 0 ) {
    if ( argc != 2 ) { go_BYE(-1); }
    status = esc_for_latex(); cBYE(status);
  }
  else if ( strcmp(argv[1], "hash_string") == 0 ) {
    if ( argc != 4 ) { go_BYE(-1); }
    status = ext_hash_string(argv[2], argv[3]); cBYE(status);
  }
  else if ( strcmp(argv[1], "txt_sub") == 0 ) {
    if ( argc != 4 ) { go_BYE(-1); }
    status = txt_sub(argv[2], argv[3]); cBYE(status);
  }
  else if ( strcmp(argv[1], "asc2bin") == 0 ) {
    if ( argc != 5 ) { go_BYE(-1); }
    status = asc2bin(argv[2], argv[3], argv[4]); cBYE(status);
  }
  else if ( strcmp(argv[1], "bin2asc") == 0 ) {
    if ( argc != 6 ) { go_BYE(-1); }
    status = bin2asc(argv[2], argv[3], argv[4], argv[5]); cBYE(status);
  }
  else if ( strcmp(argv[1], "date_to_I4") == 0 ) {
    if ( argc != 6 ) { go_BYE(-1); }
    status = date_to_I4 (argv[2], argv[3], argv[4], argv[5]); cBYE(status);
  }
  else if ( strcmp(argv[1], "sortbindmp") == 0 ) {
    if ( argc != 5 ) { go_BYE(-1); }
    status = sortbindmp(argv[2], argv[3], argv[4]); cBYE(status);
  }
  else if ( strcmp(argv[1], "mk_ldb_dict") == 0 ) {
    if ( argc != 9 ) { go_BYE(-1); }
    char *q_data_dir = getenv("Q_DATA_DIR");
    if ( q_data_dir == NULL ) { go_BYE(-1); }
    status = mk_ldb_dict(argv[2], argv[3], argv[4], argv[5], argv[6], 
	argv[7], argv[8], q_data_dir); 
    cBYE(status);
  }



  else { go_BYE(-1); }
 BYE:
  return(status);
}
Exemplo n.º 5
0
/*
 * check: read logfile and check it
 */
void
check(void)
{
	FILE *finput;
	int   i;
	int   input;
	int   mfd;
	unsigned char  key[41];
	int   keylen;
	unsigned char  lastkey[21];
	int   lastkeylen;
	int   line;
	unsigned char  mkey1[21];
	int   mkey1len;
	unsigned char  mkey2[21];
	int   mkey2len;
	char  msg[MAXLINE];
	int   msglen;

	/* open logfile */
	if (actionf & ST_IN)
		input = STDIN_FILENO;
	else if ( (input = open(logfile, O_RDONLY, 0)) == -1) {
		perror(logfile);
		exit(-1);
	}

	mfd = 0;	/* shutup gcc */

	/* open macfile */
	if (macfile)
		if ( (mfd = open(macfile, O_RDONLY, 0)) == -1) {
			perror(macfile);
			exit(-1);
		}

	/* read initial key (as ascii string) and tranlate it to binary */
	if ( (i = open(key0file, O_RDONLY, 0)) == -1) {
		perror(key0file);
		exit(-1);
	}
	if ( (keylen = read(i, key, 40)) == -1) {
		perror(key0file);
		exit(-1);
	}
	if (!keylen) {
		if (actionf & QUIET)
			eexit(1, "1\n");
		else
			eexit(1, "(1) %s: %s\n", key0file, corrupted);
	}
	key[keylen] = 0;
	asc2bin(key, key);
	keylen >>= 1;
	close(i);

	/* read last key */
	if ( (i = open(keyfile, O_RDONLY, 0)) == -1) {
		perror(keyfile);
		exit(-1);
	}
	if ( (lastkeylen = read(i, lastkey, 20)) == -1) {
		perror(keyfile);
		exit(-1);
	}
	if (!lastkeylen) {
		if (actionf & QUIET)
			eexit(1, "1\n");
		else
			eexit(1, "(1) %s: %s\n", keyfile, corrupted);
	}
	close(i);

	/* test both key lenghts */
	if (lastkeylen != keylen) {
		if (actionf & QUIET)
			eexit(1, "1\n");
		else
			eexit(1, "(1) %s and/or %s %s\n", key0file, keyfile,
			    corrupted);
	}

	/* check it */
	line = 1;
	finput = NULL;
	while ( (msglen = readline(input, msg, MAXLINE, &finput)) > 0) {
		if (macfile) {
			if ( ((mkey1len = mac2(key, keylen,
			    (unsigned char *) msg, msglen, mkey1)) < 0) ||
			    ((mkey2len = read(mfd, mkey2,
			    mkey1len)) < 0) ) {
				perror(macfile);
				exit(-1);
			}
			if ((mkey2len != mkey1len) || memcmp(mkey2, mkey1,
			    mkey1len)) {
				if (actionf & QUIET)
					eexit(1, "%i\n", line);
				else
					eexit(1, "(%i) %s %s on line %i\n",
					    line, logfile, corrupted, line);
			}
			line++;
		}
		if ( (keylen = mac(method, key, keylen,
		    (unsigned char *) msg, msglen, key)) == -1) {
			perror("fatal");
			exit(-1);
		}
	}

	if (finput != NULL)
		fclose(finput);

	if (macfile != NULL)
		close(mfd);

	if (i < 0) {
		fprintf(stderr, "error reading logs form %s : %s\n",
		    (actionf & ST_IN) ? "standard input" : logfile,
		    strerror(errno));
		exit(-1);
	}

	if (memcmp(lastkey, key, keylen)) {
		if (actionf & QUIET) 
			eexit(1, "1\n");
		else
			eexit(1, "(1) %s %s\n", logfile, corrupted);
	}
	if (actionf & QUIET)
		eexit(0, "0\n");
	else
		eexit(0, "(0) %s file is ok\n", logfile);
}