NeoMutt  2024-04-16-36-g75b6fb
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 418 of file gnupgparse.c.

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