LCOV - code coverage report
Current view: top level - app/fddev/configure - keys.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 43 0.0 %
Date: 2025-03-10 12:29:05 Functions: 0 3 0.0 %

          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 * 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 * config,
      32           0 :       int        pre_init FD_PARAM_UNUSED ) {
      33           0 :   char path[ PATH_MAX ];
      34           0 :   FD_TEST( fd_cstr_printf_check( path, PATH_MAX, NULL, "%s/faucet.json", config->scratch_directory ) );
      35           0 :   if( FD_UNLIKELY( unlink( path ) && errno != ENOENT ) )
      36           0 :     FD_LOG_ERR(( "could not remove cluster file `%s` (%i-%s)", path, errno, fd_io_strerror( errno ) ));
      37           0 :   FD_TEST( fd_cstr_printf_check( path, PATH_MAX, NULL, "%s/stake-account.json", config->scratch_directory ) );
      38           0 :   if( FD_UNLIKELY( unlink( path ) && errno != ENOENT ) )
      39           0 :     FD_LOG_ERR(( "could not remove cluster file `%s` (%i-%s)", path, errno, fd_io_strerror( errno ) ));
      40           0 :   FD_TEST( fd_cstr_printf_check( path, PATH_MAX, NULL, "%s/vote-account.json", config->scratch_directory ) );
      41           0 :   if( FD_UNLIKELY( unlink( path ) && errno != ENOENT ) )
      42           0 :     FD_LOG_ERR(( "could not remove cluster file `%s` (%i-%s)", path, errno, fd_io_strerror( errno ) ));
      43           0 : }
      44             : 
      45             : 
      46             : static configure_result_t
      47           0 : check( config_t const * config ) {
      48           0 :   char faucet[ PATH_MAX ], stake[ PATH_MAX ], vote[ PATH_MAX ];
      49             : 
      50           0 :   FD_TEST( fd_cstr_printf_check( faucet, PATH_MAX, NULL, "%s/faucet.json", config->scratch_directory ) );
      51           0 :   FD_TEST( fd_cstr_printf_check( stake,  PATH_MAX, NULL, "%s/stake-account.json", config->scratch_directory ) );
      52           0 :   FD_TEST( fd_cstr_printf_check( vote,   PATH_MAX, NULL, "%s/vote-account.json", config->scratch_directory ) );
      53             : 
      54           0 :   struct stat st;
      55           0 :   if( FD_UNLIKELY( stat( faucet, &st ) && errno == ENOENT &&
      56           0 :                    stat( stake,  &st ) && errno == ENOENT &&
      57           0 :                    stat( vote,   &st ) && errno == ENOENT ) )
      58           0 :     NOT_CONFIGURED( "not all of faucet.json, stake-account.json, and vote-account.json exist" );
      59             : 
      60           0 :   CHECK( check_dir( config->scratch_directory, config->uid, config->gid, S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR ) );
      61             : 
      62           0 :   CHECK( check_file( faucet, config->uid, config->gid, S_IFREG | S_IRUSR | S_IWUSR ) );
      63           0 :   CHECK( check_file( stake,  config->uid, config->gid, S_IFREG | S_IRUSR | S_IWUSR ) );
      64           0 :   CHECK( check_file( vote,   config->uid, config->gid, S_IFREG | S_IRUSR | S_IWUSR ) );
      65           0 :   CONFIGURE_OK();
      66           0 : }
      67             : 
      68             : configure_stage_t fd_cfg_stage_keys = {
      69             :   .name            = NAME,
      70             :   .always_recreate = 0,
      71             :   .enabled         = NULL,
      72             :   .init_perm       = NULL,
      73             :   .fini_perm       = NULL,
      74             :   .init            = init,
      75             :   .fini            = fini,
      76             :   .check           = check,
      77             : };
      78             : 
      79             : #undef NAME

Generated by: LCOV version 1.14