@ -17,7 +17,7 @@
@@ -17,7 +17,7 @@
# include <fcntl.h>
# include <errno.h>
# include <unistd.h>
# include "ts3init_cookie _seed.h"
# include "ts3init_random _seed.h"
# include "ts3init_match.h"
# define param_act(t, s, f) xtables_param_act((t), "ts3init_get_puzzle", (s), (f))
@ -29,18 +29,18 @@ static void ts3init_get_puzzle_help(void)
@@ -29,18 +29,18 @@ static void ts3init_get_puzzle_help(void)
" ts3init_get_puzzle match options: \n "
" --min-client n The sending client needs to be at least version. \n "
" --check-cookie Check that the cookie was generated by same seed. \n "
" --seed <seed> Seed is a %i byte lowercase hex number in. \n "
" --random- seed <seed> Seed is a %i byte lowercase hex number in. \n "
" A source could be /dev/random. \n "
" --seed-file <file> Read the seed from a file. \n " ,
COOKIE _SEED_LEN
" --random- seed-file <file> Read the seed from a file. \n " ,
RANDOM _SEED_LEN
) ;
}
static const struct option ts3init_get_puzzle_opts [ ] = {
{ . name = " min-client " , . has_arg = true , . val = ' 1 ' } ,
{ . name = " check-cookie " , . has_arg = false , . val = ' 2 ' } ,
{ . name = " seed " , . has_arg = true , . val = ' 3 ' } ,
{ . name = " seed-file " , . has_arg = true , . val = ' 4 ' } ,
{ . name = " random- seed" , . has_arg = true , . val = ' 3 ' } ,
{ . name = " random- seed-file" , . has_arg = true , . val = ' 4 ' } ,
{ NULL } ,
} ;
@ -70,26 +70,26 @@ static int ts3init_get_puzzle_parse(int c, char **argv, int invert, unsigned int
@@ -70,26 +70,26 @@ static int ts3init_get_puzzle_parse(int c, char **argv, int invert, unsigned int
return true ;
case ' 3 ' :
param_act ( XTF_ONLY_ONCE , " --seed " , info - > specific_options & CHK_GET_PUZZLE_SEED_FROM_ARGUMENT ) ;
param_act ( XTF_NO_INVERT , " --seed " , invert ) ;
if ( strlen ( optarg ) ! = ( COOKIE _SEED_LEN * 2 ) )
param_act ( XTF_ONLY_ONCE , " --random- seed " , info - > specific_options & CHK_GET_PUZZLE_RANDOM _SEED_FROM_ARGUMENT ) ;
param_act ( XTF_NO_INVERT , " --random- seed " , invert ) ;
if ( strlen ( optarg ) ! = ( RANDOM _SEED_LEN * 2 ) )
xtables_error ( PARAMETER_PROBLEM ,
" ts3init_get_puzzle: invalid seed length " ) ;
if ( ! hex2int _seed( optarg , info - > cookie _seed) )
" ts3init_get_puzzle: invalid random seed length " ) ;
if ( ! parse_random _seed( optarg , info - > random _seed) )
xtables_error ( PARAMETER_PROBLEM ,
" ts3init_get_puzzle: invalid seed. (not lowercase hex) " ) ;
info - > specific_options | = CHK_GET_PUZZLE_SEED_FROM_ARGUMENT ;
* flags | = CHK_GET_PUZZLE_SEED_FROM_ARGUMENT ;
" ts3init_get_puzzle: invalid random seed. (not lowercase hex) " ) ;
info - > specific_options | = CHK_GET_PUZZLE_RANDOM_ SEED_FROM_ARGUMENT ;
* flags | = CHK_GET_PUZZLE_RANDOM_ SEED_FROM_ARGUMENT ;
return true ;
case ' 4 ' :
param_act ( XTF_ONLY_ONCE , " --seed-file " , info - > specific_options & CHK_GET_PUZZLE_SEED_FROM_FILE ) ;
param_act ( XTF_NO_INVERT , " --seed-file " , invert ) ;
param_act ( XTF_ONLY_ONCE , " --random- seed-file " , info - > specific_options & CHK_GET_PUZZLE_RANDOM _SEED_FROM_FILE ) ;
param_act ( XTF_NO_INVERT , " --random- seed-file " , invert ) ;
if ( read_cookie _seed_from_file ( " ts3init_get_puzzle " , optarg , info - > cookie _seed) )
memcpy ( info - > cookie _seed_path, optarg , strlen ( optarg ) + 1 ) ;
info - > specific_options | = CHK_GET_PUZZLE_SEED_FROM_FILE ;
* flags | = CHK_GET_PUZZLE_SEED_FROM_FILE ;
if ( read_random _seed_from_file ( " ts3init_get_puzzle " , optarg , info - > random _seed) )
memcpy ( info - > random _seed_path, optarg , strlen ( optarg ) + 1 ) ;
info - > specific_options | = CHK_GET_PUZZLE_RANDOM_ SEED_FROM_FILE ;
* flags | = CHK_GET_PUZZLE_RANDOM_ SEED_FROM_FILE ;
return true ;
default :
@ -108,18 +108,18 @@ static void ts3init_get_puzzle_save(const void *ip, const struct xt_entry_match
@@ -108,18 +108,18 @@ static void ts3init_get_puzzle_save(const void *ip, const struct xt_entry_match
{
printf ( " --check-cookie " ) ;
}
if ( info - > specific_options & CHK_GET_PUZZLE_SEED_FROM_ARGUMENT )
if ( info - > specific_options & CHK_GET_PUZZLE_RANDOM_ SEED_FROM_ARGUMENT )
{
printf ( " --seed " ) ;
for ( int i = 0 ; i < COOKIE _SEED_LEN; i + + )
printf ( " --random- seed " ) ;
for ( int i = 0 ; i < RANDOM _SEED_LEN; i + + )
{
printf ( " %02X " , info - > cookie _seed[ i ] ) ;
printf ( " %02X " , info - > random _seed[ i ] ) ;
}
printf ( " " ) ;
}
if ( info - > specific_options & CHK_GET_PUZZLE_SEED_FROM_FILE )
if ( info - > specific_options & CHK_GET_PUZZLE_RANDOM_ SEED_FROM_FILE )
{
printf ( " --seed-file \" %s \" " , info - > cookie _seed_path) ;
printf ( " --random- seed-file \" %s \" " , info - > random _seed_path) ;
}
}
@ -132,12 +132,12 @@ static void ts3init_get_puzzle_print(const void *ip, const struct xt_entry_match
@@ -132,12 +132,12 @@ static void ts3init_get_puzzle_print(const void *ip, const struct xt_entry_match
static void ts3init_get_puzzle_check ( unsigned int flags )
{
bool seed_from_argument = flags & CHK_GET_PUZZLE_SEED_FROM_ARGUMENT ;
bool seed_from_file = flags & CHK_GET_PUZZLE_SEED_FROM_FILE ;
bool seed_from_argument = flags & CHK_GET_PUZZLE_RANDOM_ SEED_FROM_ARGUMENT ;
bool seed_from_file = flags & CHK_GET_PUZZLE_RANDOM_ SEED_FROM_FILE ;
if ( seed_from_argument & & seed_from_file )
{
xtables_error ( PARAMETER_PROBLEM ,
" ts3init_get_puzzle: --seed and --seed-file "
" ts3init_get_puzzle: --random- seed and --random -seed-file "
" can not be specified at the same time " ) ;
}
if ( flags & CHK_GET_PUZZLE_CHECK_COOKIE )
@ -146,7 +146,7 @@ static void ts3init_get_puzzle_check(unsigned int flags)
@@ -146,7 +146,7 @@ static void ts3init_get_puzzle_check(unsigned int flags)
{
xtables_error ( PARAMETER_PROBLEM ,
" ts3init_get_puzzle: --check-cookie requires either "
" --seed or --seed-file " ) ;
" --random- seed or --random -seed-file " ) ;
}
}
}