/* prototypes
*/
-static char * get_user_pw(fko_cli_options_t *options, const int crypt_op);
+static char * get_user_pw(fko_ctx_t ctx,
+ fko_cli_options_t *options, const int crypt_op);
static void display_ctx(fko_ctx_t ctx);
static void errmsg(const char *msg, const int err);
static void show_last_command(void);
/* Finalize the context data (encrypt and encode the SPA data)
*/
- res = fko_spa_data_final(ctx, get_user_pw(&options, CRYPT_OP_ENCRYPT));
+ res = fko_spa_data_final(ctx, get_user_pw(ctx, &options, CRYPT_OP_ENCRYPT));
if(res != FKO_SUCCESS)
{
errmsg("fko_spa_data_final", res);
}
res = fko_decrypt_spa_data(
- ctx2, get_user_pw(&options, CRYPT_OP_DECRYPT)
+ ctx2, get_user_pw(ctx2, &options, CRYPT_OP_DECRYPT)
);
if(res != FKO_SUCCESS)
/* Prompt for and receive a user password.
*/
static char*
-get_user_pw(fko_cli_options_t *options, const int crypt_op)
+get_user_pw(fko_ctx_t ctx, fko_cli_options_t *options, const int crypt_op)
{
char *pw_ptr = NULL;
static char *no_pw = "";
*/
if (options->get_key_file[0] != 0x0)
{
- pw_ptr = getpasswd_file(options->get_key_file, options->spa_server_str);
+ pw_ptr = getpasswd_file(ctx, options);
}
else if (options->use_gpg)
{
if (pw_ptr == NULL)
{
fprintf(stderr, "Received no password data, exiting.\n");
+ fko_destroy(ctx);
exit(EXIT_FAILURE);
}
/* Function for accepting password input from from a file
*/
char*
-getpasswd_file(const char *pw_file, const char *server_str)
+getpasswd_file(fko_ctx_t ctx, const fko_cli_options_t *options)
{
FILE *pwfile_ptr;
unsigned int numLines = 0, i = 0, found_dst;
char tmp_char_buf[MAX_LINE_LEN] = {0};
char *lptr;
- if ((pwfile_ptr = fopen(pw_file, "r")) == NULL)
+ if ((pwfile_ptr = fopen(options->get_key_file, "r")) == NULL)
{
- fprintf(stderr, "Could not open config file: %s\n", pw_file);
- exit(1);
+ fprintf(stderr, "Could not open config file: %s\n", options->get_key_file);
+ fko_destroy(ctx);
+ exit(EXIT_FAILURE);
}
while ((fgets(conf_line_buf, MAX_LINE_LEN, pwfile_ptr)) != NULL)
* reference the matching one for the SPA server we are contacting
*/
found_dst = 1;
- for (i=0; i < strlen(server_str); i++)
- if (*lptr++ != server_str[i])
+ for (i=0; i < strlen(options->spa_server_str); i++)
+ if (*lptr++ != options->spa_server_str[i])
found_dst = 0;
if (! found_dst)
if (pwbuf[0] == '\0') {
fprintf(stderr, "Could not get password for IP: %s from: %s\n",
- server_str, pw_file);
- exit(1);
+ options->spa_server_str, options->get_key_file);
+ fko_destroy(ctx);
+ exit(EXIT_FAILURE);
}
return pwbuf;