NeoMutt  2025-12-11-1039-g550ac6
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 424 of file gnupgparse.c.

425{
427 FILE *fp = NULL;
428 pid_t pid;
429 char buf[1024] = { 0 };
430 struct PgpKeyInfo *db = NULL;
431 struct PgpKeyInfo **kend = NULL;
432 struct PgpKeyInfo *k = NULL;
433 struct PgpKeyInfo *kk = NULL;
434 struct PgpKeyInfo *mainkey = NULL;
435 bool is_sub = false;
436
437 int fd_null = open("/dev/null", O_RDWR);
438 if (fd_null == -1)
439 return NULL;
440
441 mutt_str_replace(&mod_data->charset, cc_charset());
442
443 pid = pgp_invoke_list_keys(NULL, &fp, NULL, -1, -1, fd_null, keyring, hints);
444 if (pid == -1)
445 {
446 close(fd_null);
447 return NULL;
448 }
449
450 kend = &db;
451 k = NULL;
452 while (fgets(buf, sizeof(buf) - 1, fp))
453 {
454 kk = parse_pub_line(buf, &is_sub, k);
455 if (!kk)
456 continue;
457
458 /* Only append kk to the list if it's new. */
459 if (kk != k)
460 {
461 if (k)
462 kend = &k->next;
463 *kend = kk;
464 k = kk;
465
466 if (is_sub)
467 {
468 struct PgpUid **l = NULL;
469
470 k->flags |= KEYFLAG_SUBKEY;
471 k->parent = mainkey;
472 for (l = &k->address; *l; l = &(*l)->next)
473 ; // do nothing
474
475 *l = pgp_copy_uids(mainkey->address, k);
476 }
477 else
478 {
479 mainkey = k;
480 }
481 }
482 }
483
484 if (ferror(fp))
485 mutt_perror("fgets");
486
487 mutt_file_fclose(&fp);
488 filter_wait(pid);
489
490 close(fd_null);
491
492 return db;
493}
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: