LCOV - code coverage report
Current view: top level - app/shared_dev/commands/configure - keys.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 44 0.0 %
Date: 2025-03-20 12:08:36 Functions: 0 3 0.0 %

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

Generated by: LCOV version 1.14