NeoMutt  2024-12-12-14-g7b49f7
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{
421 FILE *fp = NULL;
422 pid_t pid;
423 char buf[1024] = { 0 };
424 struct PgpKeyInfo *db = NULL, **kend = NULL, *k = NULL, *kk = NULL, *mainkey = NULL;
425 bool is_sub = false;
426
427 int fd_null = open("/dev/null", O_RDWR);
428 if (fd_null == -1)
429 return NULL;
430
432
433 pid = pgp_invoke_list_keys(NULL, &fp, NULL, -1, -1, fd_null, keyring, hints);
434 if (pid == -1)
435 {
436 close(fd_null);
437 return NULL;
438 }
439
440 kend = &db;
441 k = NULL;
442 while (fgets(buf, sizeof(buf) - 1, fp))
443 {
444 kk = parse_pub_line(buf, &is_sub, k);
445 if (!kk)
446 continue;
447
448 /* Only append kk to the list if it's new. */
449 if (kk != k)
450 {
451 if (k)
452 kend = &k->next;
453 *kend = kk;
454 k = kk;
455
456 if (is_sub)
457 {
458 struct PgpUid **l = NULL;
459
460 k->flags |= KEYFLAG_SUBKEY;
461 k->parent = mainkey;
462 for (l = &k->address; *l; l = &(*l)->next)
463 ; // do nothing
464
465 *l = pgp_copy_uids(mainkey->address, k);
466 }
467 else
468 {
469 mainkey = k;
470 }
471 }
472 }
473
474 if (ferror(fp))
475 mutt_perror("fgets");
476
477 mutt_file_fclose(&fp);
478 filter_wait(pid);
479
480 close(fd_null);
481
482 return db;
483}
const char * cc_charset(void)
Get the cached value of $charset.
Definition: config_cache.c:116
#define mutt_file_fclose(FP)
Definition: file.h:138
static char * Charset
Cached copy of $charset.
Definition: gnupgparse.c:76
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:136
#define mutt_perror(...)
Definition: logging2.h:93
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:220
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:280
#define KEYFLAG_SUBKEY
Key is a subkey.
Definition: lib.h:140
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:422
struct PgpUid * pgp_copy_uids(struct PgpUid *up, struct PgpKeyInfo *parent)
Copy a list of PGP UIDs.
Definition: pgplib.c:127
Information about a PGP key.
Definition: pgplib.h:49
PGP User ID.
Definition: pgplib.h:36
int flags
Definition: pgplib.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function: