NeoMutt  2024-10-02-37-gfa9146
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
Pgp Function API

Prototype for a Pgp Function. More...

+ Collaboration diagram for Pgp Function API:

Functions

static int op_exit (struct PgpData *pd, int op)
 Exit this menu - Implements pgp_function_t -.
 
static int op_generic_select_entry (struct PgpData *pd, int op)
 Select the current entry - Implements pgp_function_t -.
 
static int op_verify_key (struct PgpData *pd, int op)
 Verify a PGP public key - Implements pgp_function_t -.
 
static int op_view_id (struct PgpData *pd, int op)
 View the key's user id - Implements pgp_function_t -.
 

Detailed Description

Prototype for a Pgp Function.

Parameters
menuMenu
opOperation to perform, e.g. OP_GENERIC_SELECT_ENTRY
Return values
enumFunctionRetval

Function Documentation

◆ op_exit()

static int op_exit ( struct PgpData pd,
int  op 
)
static

Exit this menu - Implements pgp_function_t -.

Definition at line 52 of file pgp_functions.c.

53{
54 pd->done = true;
55 return FR_SUCCESS;
56}
@ FR_SUCCESS
Valid function - successfully performed.
Definition: dispatcher.h:39
bool done
Should we close the Dialog?
Definition: pgp_functions.h:35

◆ op_generic_select_entry()

static int op_generic_select_entry ( struct PgpData pd,
int  op 
)
static

Select the current entry - Implements pgp_function_t -.

Definition at line 61 of file pgp_functions.c.

62{
63 /* XXX make error reporting more verbose */
64
65 const int index = menu_get_index(pd->menu);
66 struct PgpUid *cur_key = pd->key_table[index];
68 {
69 if (!pgp_key_is_valid(cur_key->parent))
70 {
71 mutt_error(_("This key can't be used: expired/disabled/revoked"));
72 return FR_ERROR;
73 }
74 }
75
76 if (OptPgpCheckTrust && (!pgp_id_is_valid(cur_key) || !pgp_id_is_strong(cur_key)))
77 {
78 const char *str = "";
79 char buf2[1024] = { 0 };
80
81 if (cur_key->flags & KEYFLAG_CANTUSE)
82 {
83 str = _("ID is expired/disabled/revoked. Do you really want to use the key?");
84 }
85 else
86 {
87 switch (cur_key->trust & 0x03)
88 {
89 case 0:
90 str = _("ID has undefined validity. Do you really want to use the key?");
91 break;
92 case 1:
93 str = _("ID is not valid. Do you really want to use the key?");
94 break;
95 case 2:
96 str = _("ID is only marginally valid. Do you really want to use the key?");
97 break;
98 }
99 }
100
101 snprintf(buf2, sizeof(buf2), "%s", str);
102
103 if (query_yesorno(buf2, MUTT_NO) != MUTT_YES)
104 {
106 return FR_NO_ACTION;
107 }
108 }
109
110 pd->key = cur_key->parent;
111 pd->done = true;
112 return FR_SUCCESS;
113}
@ FR_ERROR
Valid function - error occurred.
Definition: dispatcher.h:38
@ FR_NO_ACTION
Valid function - no action performed.
Definition: dispatcher.h:37
bool OptPgpCheckTrust
(pseudo) used by dlg_pgp()
Definition: globals.c:70
#define mutt_error(...)
Definition: logging2.h:92
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:160
#define _(a)
Definition: message.h:28
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:74
#define KEYFLAG_CANTUSE
Definition: lib.h:139
bool pgp_id_is_valid(struct PgpUid *uid)
Is a PGP key valid.
Definition: pgpkey.c:149
bool pgp_id_is_strong(struct PgpUid *uid)
Is a PGP key strong?
Definition: pgpkey.c:136
bool pgp_key_is_valid(struct PgpKeyInfo *k)
Is a PGP key valid?
Definition: pgpkey.c:104
@ MUTT_NO
User answered 'No', or assume 'No'.
Definition: quad.h:38
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
Definition: quad.h:39
enum QuadOption query_yesorno(const char *prompt, enum QuadOption def)
Ask the user a Yes/No question.
Definition: question.c:327
struct PgpUid ** key_table
Array of Keys.
Definition: pgp_functions.h:37
struct Menu * menu
Pgp Menu.
Definition: pgp_functions.h:36
struct PgpKeyInfo * key
Selected Key.
Definition: pgp_functions.h:38
PGP User ID.
Definition: pgplib.h:35
short trust
Definition: pgplib.h:37
struct PgpKeyInfo * parent
Parent key.
Definition: pgplib.h:39
int flags
Definition: pgplib.h:38
+ Here is the call graph for this function:

◆ op_verify_key()

static int op_verify_key ( struct PgpData pd,
int  op 
)
static

Verify a PGP public key - Implements pgp_function_t -.

Definition at line 118 of file pgp_functions.c.

119{
120 FILE *fp_null = mutt_file_fopen("/dev/null", "w");
121 if (!fp_null)
122 {
123 mutt_perror(_("Can't open /dev/null"));
124 return FR_ERROR;
125 }
126 struct Buffer *tempfile = NULL;
127 tempfile = buf_pool_get();
128 buf_mktemp(tempfile);
129 FILE *fp_tmp = mutt_file_fopen(buf_string(tempfile), "w");
130 if (!fp_tmp)
131 {
132 mutt_perror(_("Can't create temporary file"));
133 mutt_file_fclose(&fp_null);
134 buf_pool_release(&tempfile);
135 return FR_ERROR;
136 }
137
138 mutt_message(_("Invoking PGP..."));
139
140 const int index = menu_get_index(pd->menu);
141 struct PgpUid *cur_key = pd->key_table[index];
142 char tmpbuf[256] = { 0 };
143 snprintf(tmpbuf, sizeof(tmpbuf), "0x%s",
145
146 pid_t pid = pgp_invoke_verify_key(NULL, NULL, NULL, -1, fileno(fp_tmp),
147 fileno(fp_null), tmpbuf);
148 if (pid == -1)
149 {
150 mutt_perror(_("Can't create filter"));
151 unlink(buf_string(tempfile));
152 mutt_file_fclose(&fp_tmp);
153 mutt_file_fclose(&fp_null);
154 }
155
156 filter_wait(pid);
157 mutt_file_fclose(&fp_tmp);
158 mutt_file_fclose(&fp_null);
160 char title[1024] = { 0 };
161 snprintf(title, sizeof(title), _("Key ID: 0x%s"),
163
164 struct PagerData pdata = { 0 };
165 struct PagerView pview = { &pdata };
166
167 pdata.fname = buf_string(tempfile);
168
169 pview.banner = title;
171 pview.mode = PAGER_MODE_OTHER;
172
173 mutt_do_pager(&pview, NULL);
174 buf_pool_release(&tempfile);
176 return FR_SUCCESS;
177}
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
int mutt_do_pager(struct PagerView *pview, struct Email *e)
Display some page-able text to the user (help or attachment)
Definition: do_pager.c:122
#define mutt_file_fclose(FP)
Definition: file.h:138
#define mutt_file_fopen(PATH, MODE)
Definition: file.h:137
#define mutt_message(...)
Definition: logging2.h:91
#define mutt_perror(...)
Definition: logging2.h:93
#define MENU_REDRAW_FULL
Redraw everything.
Definition: lib.h:59
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition: menu.c:184
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:220
#define MUTT_PAGER_NO_FLAGS
No flags are set.
Definition: lib.h:60
@ PAGER_MODE_OTHER
Pager is invoked via 3rd path. Non-email content is likely to be shown.
Definition: lib.h:142
char * pgp_keyid(struct PgpKeyInfo *k)
Get the ID of the main (parent) key.
Definition: pgp.c:204
char * pgp_fpr_or_lkeyid(struct PgpKeyInfo *k)
Get the fingerprint or long keyid.
Definition: pgp.c:234
pid_t pgp_invoke_verify_key(FILE **fp_pgp_in, FILE **fp_pgp_out, FILE **fp_pgp_err, int fd_pgp_in, int fd_pgp_out, int fd_pgp_err, const char *uids)
Use PGP to verify a key.
Definition: pgpinvoke.c:465
struct PgpKeyInfo * pgp_principal_key(struct PgpKeyInfo *key)
Get the main (parent) PGP key.
Definition: pgpkey.c:92
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
String manipulation buffer.
Definition: buffer.h:36
Data to be displayed by PagerView.
Definition: lib.h:161
const char * fname
Name of the file to read.
Definition: lib.h:165
Paged view into some data.
Definition: lib.h:172
struct PagerData * pdata
Data that pager displays. NOTNULL.
Definition: lib.h:173
enum PagerMode mode
Pager mode.
Definition: lib.h:174
PagerFlags flags
Additional settings to tweak pager's function.
Definition: lib.h:175
const char * banner
Title to display in status bar.
Definition: lib.h:176
#define buf_mktemp(buf)
Definition: tmp.h:33
+ Here is the call graph for this function:

◆ op_view_id()

static int op_view_id ( struct PgpData pd,
int  op 
)
static

View the key's user id - Implements pgp_function_t -.

Definition at line 182 of file pgp_functions.c.

183{
184 const int index = menu_get_index(pd->menu);
185 struct PgpUid *cur_key = pd->key_table[index];
186 mutt_message("%s", NONULL(cur_key->addr));
187 return FR_SUCCESS;
188}
#define NONULL(x)
Definition: string2.h:37
char * addr
Definition: pgplib.h:36
+ Here is the call graph for this function: