コード例 #1
0
ファイル: ProductKey.c プロジェクト: aevernon/triggerman
PRODUCTKEY_API void	generate ( long expr_time, long product_key_length, char* product_key )
{

	ICE_KEY*		ice_key;
	unsigned char	cipherkey		[MAX_PASS_LEN];
	unsigned char	encrypted_data	[MAX_PASS_LEN + 1];
	char			expr_time_str	[MAX_PASS_LEN];
	char			plain_text		[MAX_PASS_LEN];

	assert ( product_key_length >= (2 * MAX_PASS_LEN) + 1 );
	assert ( product_key );

	// Convert expiration time to char data and add validating characters
	memset ( expr_time_str,	'\0', MAX_PASS_LEN );
	memset ( plain_text,		'\0', MAX_PASS_LEN );

	ltoa ( expr_time, expr_time_str, 10);

	plain_text[0] = VALID_KEY_CHAR;
	strcat ( plain_text, expr_time_str );
	strcat ( plain_text, VALID_KEY_CHAR_STR );

	// cipherkey must match the one in Vigilert/Configure/ice.c.
	cipherkey[0] = 3; cipherkey[1] = 98; cipherkey[2] = 202; cipherkey[3] = 15;
	cipherkey[4] = 112; cipherkey[5] = 153; cipherkey[6] = 121; cipherkey[7] = 52;
	ice_key = ice_key_create (1);
	ice_key_set (ice_key, cipherkey);
	memset (encrypted_data, '\0', MAX_PASS_LEN + 1);
	memset (product_key,	'\0', (2 * MAX_PASS_LEN) + 1);
	ice_key_encrypt (ice_key, (unsigned char *) plain_text, encrypted_data);
	ice_key_destroy (ice_key);
	bin2asc (encrypted_data, MAX_PASS_LEN, product_key);
}
コード例 #2
0
void CoreUDPHandler::attach(IReciver* reciver)
{
    if(reciver != NULL)
    {
        for(size_t i = 0; i < recivers_.size(); ++i)
        {
            if(recivers_[i] == reciver)
            {
                return ;
            }
        }

        CORE_INFO("core udp handler, attach reciver = 0x" << bin2asc((uint8_t *)reciver, sizeof(reciver)));
        recivers_.push_back(reciver);
    }
}
コード例 #3
0
ファイル: peochk.c プロジェクト: rhaamo/sosyslog
/*
 * generate:
 *	generate initial key and write it on keyfile and key0file
 *	in the last file data is written as ascii string
 */
void
generate(void)
{
	int	 kfd;
	int	 k0fd;
	unsigned char	 key[20];
	unsigned char	 keyasc[41];
	int	 keylen;
	unsigned char	 randvalue[20];

	if (getrandom(randvalue, 20) < 0) {
		release();
		perror("getrandom");
		exit(-1);
	}
	if ( (keylen = mac(method, NULL, 0, randvalue, 20, key)) == -1) {
		release();
		perror("fatal");
		exit(-1);
	}
	if ( (kfd = open(keyfile, O_WRONLY|O_CREAT|O_EXCL,
	    S_IRUSR|S_IWUSR)) == -1) {
		release();
		perror(keyfile);
		exit(-1);
	}
	if ( (k0fd = open(key0file, O_WRONLY|O_CREAT|O_EXCL,
	    S_IRUSR|S_IWUSR)) == -1) {
		unlink(keyfile);
		close(kfd);
		release();
		perror(key0file);
		exit(-1);
	}

	/* write key 0 */
	write(kfd, key, keylen);
	write(k0fd, bin2asc(keyasc, key, keylen), keylen << 1);
	close(kfd);
	close(k0fd);
}
コード例 #4
0
ファイル: qtils.c プロジェクト: TimLand/datacl
// 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);
}