NeoMutt  2025-12-11-1039-g550ac6
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_quit (struct PgpData *pd, const struct KeyEvent *event)
 Save changes and exit this dialog - Implements pgp_function_t -.
static int op_generic_select_entry (struct PgpData *pd, const struct KeyEvent *event)
 Select the current entry - Implements pgp_function_t -.
static int op_verify_key (struct PgpData *pd, const struct KeyEvent *event)
 Verify a PGP public key - Implements pgp_function_t -.
static int op_view_id (struct PgpData *pd, const struct KeyEvent *event)
 View the key's user id - Implements pgp_function_t -.

Detailed Description

Prototype for a Pgp Function.

Parameters
menuMenu
eventEvent to process
Return values
enumFunctionRetval
Precondition
menu is not NULL
event is not NULL

Function Documentation

◆ op_quit()

int op_quit ( struct PgpData * pd,
const struct KeyEvent * event )
static

Save changes and exit this dialog - Implements pgp_function_t -.

Definition at line 54 of file functions_pgp.c.

55{
56 pd->done = true;
57 return FR_SUCCESS;
58}
@ FR_SUCCESS
Valid function - successfully performed.
Definition dispatcher.h:40
bool done
Should we close the Dialog?

◆ op_generic_select_entry()

int op_generic_select_entry ( struct PgpData * pd,
const struct KeyEvent * event )
static

Select the current entry - Implements pgp_function_t -.

Definition at line 63 of file functions_pgp.c.

64{
65 /* XXX make error reporting more verbose */
66
67 const int index = menu_get_index(pd->menu);
68 struct PgpUid **pkey = ARRAY_GET(pd->key_table, index);
69 if (!pkey)
70 return FR_ERROR;
71
73 {
74 if (!pgp_key_is_valid((*pkey)->parent))
75 {
76 mutt_error(_("This key can't be used: expired/disabled/revoked"));
77 return FR_ERROR;
78 }
79 }
80
81 if (OptPgpCheckTrust && (!pgp_id_is_valid((*pkey)) || !pgp_id_is_strong((*pkey))))
82 {
83 const char *str = "";
84 char buf2[1024] = { 0 };
85
86 if ((*pkey)->flags & KEYFLAG_CANTUSE)
87 {
88 str = _("ID is expired/disabled/revoked. Do you really want to use the key?");
89 }
90 else
91 {
92 switch ((*pkey)->trust & 0x03)
93 {
94 case 0:
95 default:
96 str = _("ID has undefined validity. Do you really want to use the key?");
97 break;
98 case 1:
99 str = _("ID is not valid. Do you really want to use the key?");
100 break;
101 case 2:
102 str = _("ID is only marginally valid. Do you really want to use the key?");
103 break;
104 }
105 }
106
107 snprintf(buf2, sizeof(buf2), "%s", str);
108
109 if (query_yesorno(buf2, MUTT_NO) != MUTT_YES)
110 {
112 return FR_NO_ACTION;
113 }
114 }
115
116 pd->key = (*pkey)->parent;
117 pd->done = true;
118 return FR_SUCCESS;
119}
#define ARRAY_GET(head, idx)
Return the element at index.
Definition array.h:109
@ FR_ERROR
Valid function - error occurred.
Definition dispatcher.h:39
@ FR_NO_ACTION
Valid function - no action performed.
Definition dispatcher.h:38
bool OptPgpCheckTrust
(pseudo) used by dlg_pgp()
Definition globals.c:55
#define mutt_error(...)
Definition logging2.h:94
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition menu.c:153
#define _(a)
Definition message.h:28
void mutt_clear_error(void)
Clear the message line (bottom line of screen).
#define KEYFLAG_CANTUSE
Definition lib.h:161
bool pgp_id_is_valid(struct PgpUid *uid)
Is a PGP key valid.
Definition pgpkey.c:152
bool pgp_id_is_strong(struct PgpUid *uid)
Is a PGP key strong?
Definition pgpkey.c:139
bool pgp_key_is_valid(struct PgpKeyInfo *k)
Is a PGP key valid?
Definition pgpkey.c:107
@ 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:329
struct Menu * menu
Pgp Menu.
struct PgpUidArray * key_table
Array of Keys.
struct PgpKeyInfo * key
Selected Key.
struct PgpKeyInfo * parent
Parent key.
Definition pgplib.h:58
PGP User ID.
Definition pgplib.h:36
Here is the call graph for this function:

◆ op_verify_key()

int op_verify_key ( struct PgpData * pd,
const struct KeyEvent * event )
static

Verify a PGP public key - Implements pgp_function_t -.

Definition at line 124 of file functions_pgp.c.

125{
126 FILE *fp_null = mutt_file_fopen("/dev/null", "w");
127 if (!fp_null)
128 {
129 mutt_perror(_("Can't open /dev/null"));
130 return FR_ERROR;
131 }
132 struct Buffer *tempfile = NULL;
133 tempfile = buf_pool_get();
134 buf_mktemp(tempfile);
135 FILE *fp_tmp = mutt_file_fopen(buf_string(tempfile), "w");
136 if (!fp_tmp)
137 {
138 mutt_perror(_("Can't create temporary file"));
139 mutt_file_fclose(&fp_null);
140 buf_pool_release(&tempfile);
141 return FR_ERROR;
142 }
143
144 mutt_message(_("Invoking PGP..."));
145
146 const int index = menu_get_index(pd->menu);
147 struct PgpUid **pkey = ARRAY_GET(pd->key_table, index);
148 if (!pkey)
149 {
150 mutt_file_fclose(&fp_tmp);
151 mutt_file_fclose(&fp_null);
152 buf_pool_release(&tempfile);
153 return FR_ERROR;
154 }
155
156 char tmpbuf[256] = { 0 };
157 snprintf(tmpbuf, sizeof(tmpbuf), "0x%s",
158 pgp_fpr_or_lkeyid(pgp_principal_key((*pkey)->parent)));
159
160 pid_t pid = pgp_invoke_verify_key(NULL, NULL, NULL, -1, fileno(fp_tmp),
161 fileno(fp_null), tmpbuf);
162 if (pid == -1)
163 {
164 mutt_perror(_("Can't create filter"));
165 unlink(buf_string(tempfile));
166 mutt_file_fclose(&fp_tmp);
167 mutt_file_fclose(&fp_null);
168 buf_pool_release(&tempfile);
169 return FR_ERROR;
170 }
171
172 filter_wait(pid);
173 mutt_file_fclose(&fp_tmp);
174 mutt_file_fclose(&fp_null);
176 char title[1024] = { 0 };
177 snprintf(title, sizeof(title), _("Key ID: 0x%s"),
178 pgp_keyid(pgp_principal_key((*pkey)->parent)));
179
180 struct PagerData pdata = { 0 };
181 struct PagerView pview = { &pdata };
182
183 pdata.fname = buf_string(tempfile);
184
185 pview.banner = title;
186 pview.flags = MUTT_PAGER_NONE;
187 pview.mode = PAGER_MODE_OTHER;
188
189 mutt_do_pager(&pview, NULL);
190 buf_pool_release(&tempfile);
192 return FR_SUCCESS;
193}
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:144
#define mutt_file_fopen(PATH, MODE)
Definition file.h:143
#define mutt_message(...)
Definition logging2.h:93
#define mutt_perror(...)
Definition logging2.h:95
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition menu.c:177
@ MENU_REDRAW_FULL
Redraw everything.
Definition lib.h:64
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
Definition filter.c:231
#define MUTT_PAGER_NONE
No flags are set.
Definition lib.h:63
@ PAGER_MODE_OTHER
Pager is invoked via 3rd path. Non-email content is likely to be shown.
Definition lib.h:143
char * pgp_keyid(struct PgpKeyInfo *k)
Get the ID of the main (parent) key.
Definition pgp.c:201
char * pgp_fpr_or_lkeyid(struct PgpKeyInfo *k)
Get the fingerprint or long keyid.
Definition pgp.c:231
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:397
struct PgpKeyInfo * pgp_principal_key(struct PgpKeyInfo *key)
Get the main (parent) PGP key.
Definition pgpkey.c:95
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
String manipulation buffer.
Definition buffer.h:36
Data to be displayed by PagerView.
Definition lib.h:162
const char * fname
Name of the file to read.
Definition lib.h:166
Paged view into some data.
Definition lib.h:173
struct PagerData * pdata
Data that pager displays. NOTNULL.
Definition lib.h:174
enum PagerMode mode
Pager mode.
Definition lib.h:175
PagerFlags flags
Additional settings to tweak pager's function.
Definition lib.h:176
const char * banner
Title to display in status bar.
Definition lib.h:177
#define buf_mktemp(buf)
Definition tmp.h:33
Here is the call graph for this function:

◆ op_view_id()

int op_view_id ( struct PgpData * pd,
const struct KeyEvent * event )
static

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

Definition at line 198 of file functions_pgp.c.

199{
200 const int index = menu_get_index(pd->menu);
201 struct PgpUid **pkey = ARRAY_GET(pd->key_table, index);
202 if (!pkey)
203 return FR_ERROR;
204
205 mutt_message("%s", NONULL((*pkey)->addr));
206 return FR_SUCCESS;
207}
#define NONULL(x)
Definition string2.h:44
Here is the call graph for this function: