#include <stdbool.h>
#include <stdlib.h>
Go to the source code of this file.
◆ READ_STR_PROMPT_BASE
#define READ_STR_PROMPT_BASE "Enter %s: " |
◆ YH_INTERNAL
#define YH_INTERNAL __attribute__((visibility("hidden"))) |
◆ parse_pw()
bool YH_INTERNAL parse_pw |
( |
const char * | prompt, |
|
|
char * | pw, |
|
|
char * | parsed, |
|
|
size_t * | parsed_len ) |
Definition at line 61 of file parsing.c.
61 {
62 if (strlen(pw) > *parsed_len) {
63 fprintf(stderr, "Unable to read name, buffer too small\n");
64 return false;
65 }
66
67 if (strlen(pw) == 0) {
68 if (
read_string(prompt, parsed, *parsed_len,
true) ==
false) {
69 return false;
70 }
71 } else {
72 strncpy(parsed, pw, *parsed_len);
73 }
74
75 *parsed_len = strlen(parsed);
76
77 return true;
78}
bool read_string(const char *name, char *str_buf, size_t str_buf_len, bool hidden)
◆ read_string()
bool YH_INTERNAL read_string |
( |
const char * | name, |
|
|
char * | str_buf, |
|
|
size_t | str_buf_len, |
|
|
bool | hidden ) |
Definition at line 26 of file parsing.c.
27 {
28
31
32 if (str_buf_len < 1) {
33 fprintf(stderr,
"Unable to read %s: buffer too small\n",
name);
34 return false;
35 }
36
38 if (
ret < 0 || ((
unsigned int)
ret) > (
sizeof(prompt) - 1)) {
39 fprintf(stderr,
"Unable to read %s: snprintf failed\n",
name);
40 return false;
41 }
42
43 if (hidden == true) {
44 ret = EVP_read_pw_string(str_buf, str_buf_len, prompt,
true);
46 fprintf(stderr,
"Retrieving %s failed (%d)\n",
name,
ret);
47 return false;
48 }
49 } else {
50 fprintf(stdout, "%s", prompt);
51 str_buf = fgets(str_buf, str_buf_len, stdin);
52 if (str_buf == NULL) {
53 return false;
54 }
55 str_buf[strlen(str_buf) - 1] = '\0';
56 }
57
58 return true;
59}
#define READ_STR_PROMPT_BASE