Line data Source code
1 : #include "../../fdctl/configure/configure.h"
2 :
3 : #include <sys/stat.h>
4 :
5 : #define NAME "keys"
6 :
7 :
8 : static void
9 0 : init( config_t * const config ) {
10 0 : mkdir_all( config->scratch_directory, config->uid, config->gid );
11 :
12 0 : struct stat st;
13 0 : if( FD_UNLIKELY( stat( config->consensus.identity_path, &st ) && errno==ENOENT ) )
14 0 : generate_keypair( config->consensus.identity_path, config, 0 );
15 :
16 0 : char faucet[ PATH_MAX ];
17 0 : FD_TEST( fd_cstr_printf_check( faucet, PATH_MAX, NULL, "%s/faucet.json", config->scratch_directory ) );
18 0 : generate_keypair( faucet, config, 0 );
19 :
20 0 : char stake[ PATH_MAX ];
21 0 : FD_TEST( fd_cstr_printf_check( stake, PATH_MAX, NULL, "%s/stake-account.json", config->scratch_directory ) );
22 0 : generate_keypair( stake, config, 0 );
23 :
24 0 : char vote[ PATH_MAX ];
25 0 : FD_TEST( fd_cstr_printf_check( vote, PATH_MAX, NULL, "%s/vote-account.json", config->scratch_directory ) );
26 0 : generate_keypair( vote, config, 0 );
27 0 : }
28 :
29 :
30 : static void
31 : fini( config_t * const config,
32 0 : int pre_init ) {
33 0 : (void)pre_init;
34 :
35 0 : char path[ PATH_MAX ];
36 0 : FD_TEST( fd_cstr_printf_check( path, PATH_MAX, NULL, "%s/faucet.json", config->scratch_directory ) );
37 0 : if( FD_UNLIKELY( unlink( path ) && errno != ENOENT ) )
38 0 : FD_LOG_ERR(( "could not remove cluster file `%s` (%i-%s)", path, errno, fd_io_strerror( errno ) ));
39 0 : FD_TEST( fd_cstr_printf_check( path, PATH_MAX, NULL, "%s/stake-account.json", config->scratch_directory ) );
40 0 : if( FD_UNLIKELY( unlink( path ) && errno != ENOENT ) )
41 0 : FD_LOG_ERR(( "could not remove cluster file `%s` (%i-%s)", path, errno, fd_io_strerror( errno ) ));
42 0 : FD_TEST( fd_cstr_printf_check( path, PATH_MAX, NULL, "%s/vote-account.json", config->scratch_directory ) );
43 0 : if( FD_UNLIKELY( unlink( path ) && errno != ENOENT ) )
44 0 : FD_LOG_ERR(( "could not remove cluster file `%s` (%i-%s)", path, errno, fd_io_strerror( errno ) ));
45 0 : }
46 :
47 :
48 : static configure_result_t
49 0 : check( config_t * const config ) {
50 0 : char faucet[ PATH_MAX ], stake[ PATH_MAX ], vote[ PATH_MAX ];
51 :
52 0 : FD_TEST( fd_cstr_printf_check( faucet, PATH_MAX, NULL, "%s/faucet.json", config->scratch_directory ) );
53 0 : FD_TEST( fd_cstr_printf_check( stake, PATH_MAX, NULL, "%s/stake-account.json", config->scratch_directory ) );
54 0 : FD_TEST( fd_cstr_printf_check( vote, PATH_MAX, NULL, "%s/vote-account.json", config->scratch_directory ) );
55 :
56 0 : struct stat st;
57 0 : if( FD_UNLIKELY( stat( faucet, &st ) && errno == ENOENT &&
58 0 : stat( stake, &st ) && errno == ENOENT &&
59 0 : stat( vote, &st ) && errno == ENOENT ) )
60 0 : NOT_CONFIGURED( "not all of faucet.json, stake-account.json, and vote-account.json exist" );
61 :
62 0 : CHECK( check_dir( config->scratch_directory, config->uid, config->gid, S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR ) );
63 :
64 0 : CHECK( check_file( faucet, config->uid, config->gid, S_IFREG | S_IRUSR | S_IWUSR ) );
65 0 : CHECK( check_file( stake, config->uid, config->gid, S_IFREG | S_IRUSR | S_IWUSR ) );
66 0 : CHECK( check_file( vote, config->uid, config->gid, S_IFREG | S_IRUSR | S_IWUSR ) );
67 0 : CONFIGURE_OK();
68 0 : }
69 :
70 : configure_stage_t keys = {
71 : .name = NAME,
72 : .always_recreate = 0,
73 : .enabled = NULL,
74 : .init_perm = NULL,
75 : .fini_perm = NULL,
76 : .init = init,
77 : .fini = fini,
78 : .check = check,
79 : };
80 :
81 : #undef NAME
|