NeoMutt  2025-12-11-980-ge38c27
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
gnupgparse.h File Reference

Parse the output of CLI PGP programinclude "pgpkey.h". More...

#include "pgpkey.h"
+ Include dependency graph for gnupgparse.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

struct PgpKeyInfopgp_get_candidates (enum PgpRing keyring, struct ListHead *hints)
 Find PGP keys matching a list of hints.
 

Detailed Description

Parse the output of CLI PGP programinclude "pgpkey.h".

Authors
  • Richard Russon
  • Pietro Cerutti

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file gnupgparse.h.

Function Documentation

◆ pgp_get_candidates()

struct PgpKeyInfo * pgp_get_candidates ( enum PgpRing keyring,
struct ListHead * hints )

Find PGP keys matching a list of hints.

Parameters
keyringPGP Keyring
hintsList of strings to match
Return values
ptrKey list
NULLError

Definition at line 419 of file gnupgparse.c.

420{
422 FILE *fp = NULL;
423 pid_t pid;
424 char buf[1024] = { 0 };
425 struct PgpKeyInfo *db = NULL;
426 struct PgpKeyInfo **kend = NULL;
427 struct PgpKeyInfo *k = NULL;
428 struct PgpKeyInfo *kk = NULL;
429 struct PgpKeyInfo *mainkey = NULL;
430 bool is_sub = false;
431
432 int fd_null = open("/dev/null", O_RDWR);
433 if (fd_null == -1)
434 return NULL;
435
436 mutt_str_replace(&mod_data->charset, cc_charset());
437
438 pid = pgp_invoke_list_keys(NULL, &fp, NULL, -1, -1, fd_null, keyring, hints);
439 if (pid == -1)
440 {
441 close(fd_null);
442 return NULL;
443 }
444
445 kend = &db;
446 k = NULL;
447 while (fgets(buf, sizeof(buf) - 1, fp))
448 {
449 kk = parse_pub_line(buf, &is_sub, k);
450 if (!kk)
451 continue;
452
453 /* Only append kk to the list if it's new. */
454 if (kk != k)
455 {
456 if (k)
457 kend = &k->next;
458 *kend = kk;
459 k = kk;
460
461 if (is_sub)
462 {
463 struct PgpUid **l = NULL;
464
465 k->flags |= KEYFLAG_SUBKEY;
466 k->parent = mainkey;
467 for (l = &k->address; *l; l = &(*l)->next)
468 ; // do nothing
469
470 *l = pgp_copy_uids(mainkey->address, k);
471 }
472 else
473 {
474 mainkey = k;
475 }
476 }
477 }
478
479 if (ferror(fp))
480 mutt_perror("fgets");
481
482 mutt_file_fclose(&fp);
483 filter_wait(pid);
484
485 close(fd_null);
486
487 return db;
488}
const char * cc_charset(void)
Get the cached value of $charset.
#define mutt_file_fclose(FP)
Definition file.h:144
static struct PgpKeyInfo * parse_pub_line(char *buf, bool *is_subkey, struct PgpKeyInfo *k)
Parse the 'pub' line from the pgp output.
Definition gnupgparse.c:135
#define mutt_perror(...)
Definition logging2.h:95
@ MODULE_ID_NCRYPT
ModuleNcrypt, Ncrypt
Definition module_api.h:82
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
Definition filter.c:231
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition string.c:284
@ KEYFLAG_SUBKEY
Key is a subkey.
Definition lib.h:154
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:666
pid_t pgp_invoke_list_keys(FILE **fp_pgp_in, FILE **fp_pgp_out, FILE **fp_pgp_err, int fd_pgp_in, int fd_pgp_out, int fd_pgp_err, enum PgpRing keyring, struct ListHead *hints)
Find matching PGP Keys.
Definition pgpinvoke.c:421
struct PgpUid * pgp_copy_uids(struct PgpUid *up, struct PgpKeyInfo *parent)
Copy a list of PGP UIDs.
Definition pgplib.c:128
Ncrypt private Module data.
Definition module_data.h:39
char * charset
gnupgparse charset
Definition module_data.h:50
Container for Accounts, Notifications.
Definition neomutt.h:41
Information about a PGP key.
Definition pgplib.h:49
KeyFlags flags
Key flags.
Definition pgplib.h:53
struct PgpKeyInfo * next
Linked list.
Definition pgplib.h:59
struct PgpUid * address
User IDs.
Definition pgplib.h:52
struct PgpKeyInfo * parent
Parent key.
Definition pgplib.h:58
PGP User ID.
Definition pgplib.h:36
struct PgpUid * next
Linked list.
Definition pgplib.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function: