NeoMutt  2025-01-09-41-g086358
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
smime_invoke_import()

Add a certificate and update index file (externally) More...

+ Collaboration diagram for smime_invoke_import():

Functions

void smime_class_invoke_import (const char *infile, const char *mailbox)
 Add a certificate and update index file (externally) - Implements CryptModuleSpecs::smime_invoke_import() -.
 

Detailed Description

Add a certificate and update index file (externally)

Parameters
infileFile containing certificate
mailboxMailbox

Function Documentation

◆ smime_class_invoke_import()

void smime_class_invoke_import ( const char *  infile,
const char *  mailbox 
)

Add a certificate and update index file (externally) - Implements CryptModuleSpecs::smime_invoke_import() -.

Definition at line 989 of file smime.c.

990{
991 char *certfile = NULL;
992 struct Buffer *buf = NULL;
993
994 FILE *fp_out = NULL;
995 FILE *fp_err = mutt_file_mkstemp();
996 if (!fp_err)
997 {
998 mutt_perror(_("Can't create temporary file"));
999 goto done;
1000 }
1001
1002 fp_out = mutt_file_mkstemp();
1003 if (!fp_out)
1004 {
1005 mutt_perror(_("Can't create temporary file"));
1006 goto done;
1007 }
1008
1009 buf = buf_pool_get();
1010 const bool c_smime_ask_cert_label = cs_subset_bool(NeoMutt->sub, "smime_ask_cert_label");
1011 if (c_smime_ask_cert_label)
1012 {
1013 if ((mw_get_field(_("Label for certificate: "), buf, MUTT_COMP_NO_FLAGS,
1014 HC_OTHER, NULL, NULL) != 0) ||
1015 buf_is_empty(buf))
1016 {
1017 goto done;
1018 }
1019 }
1020
1021 mutt_endwin();
1022 certfile = smime_extract_certificate(infile);
1023 if (certfile)
1024 {
1025 mutt_endwin();
1026
1027 const struct Expando *c_smime_import_cert_command =
1028 cs_subset_expando(NeoMutt->sub, "smime_import_cert_command");
1029 FILE *fp_smime_in = NULL;
1030 pid_t pid = smime_invoke(&fp_smime_in, NULL, NULL, -1, fileno(fp_out),
1031 fileno(fp_err), certfile, NULL, NULL, NULL, NULL,
1032 NULL, NULL, c_smime_import_cert_command);
1033 if (pid == -1)
1034 {
1035 mutt_message(_("Error: unable to create OpenSSL subprocess"));
1036 goto done;
1037 }
1038 fputs(buf_string(buf), fp_smime_in);
1039 fputc('\n', fp_smime_in);
1040 mutt_file_fclose(&fp_smime_in);
1041
1042 filter_wait(pid);
1043
1044 mutt_file_unlink(certfile);
1045 FREE(&certfile);
1046 }
1047
1048 fflush(fp_out);
1049 rewind(fp_out);
1050 fflush(fp_err);
1051 rewind(fp_err);
1052
1053 mutt_file_copy_stream(fp_out, stdout);
1054 mutt_file_copy_stream(fp_err, stdout);
1055
1056done:
1057 mutt_file_fclose(&fp_out);
1058 mutt_file_fclose(&fp_err);
1059 buf_pool_release(&buf);
1060}
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:291
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
const struct Expando * cs_subset_expando(const struct ConfigSubset *sub, const char *name)
Get an Expando config item by name.
Definition: config_type.c:357
void mutt_endwin(void)
Shutdown curses.
Definition: curs_lib.c:151
int mutt_file_copy_stream(FILE *fp_in, FILE *fp_out)
Copy the contents of one file into another.
Definition: file.c:225
void mutt_file_unlink(const char *s)
Delete a file, carefully.
Definition: file.c:159
#define mutt_file_fclose(FP)
Definition: file.h:139
int mw_get_field(const char *prompt, struct Buffer *buf, CompletionFlags complete, enum HistoryClass hclass, const struct CompleteOps *comp_api, void *cdata)
Ask the user for a string -.
Definition: window.c:273
#define mutt_message(...)
Definition: logging2.h:91
#define mutt_perror(...)
Definition: logging2.h:93
@ HC_OTHER
Miscellaneous strings.
Definition: lib.h:58
#define FREE(x)
Definition: memory.h:55
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:220
#define _(a)
Definition: message.h:28
#define MUTT_COMP_NO_FLAGS
No flags are set.
Definition: mutt.h:56
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:96
static char * smime_extract_certificate(const char *infile)
Extract an SMIME certificate from a file.
Definition: smime.c:806
static pid_t smime_invoke(FILE **fp_smime_in, FILE **fp_smime_out, FILE **fp_smime_err, int fp_smime_infd, int fp_smime_outfd, int fp_smime_errfd, const char *fname, const char *sig_fname, const char *cryptalg, const char *digestalg, const char *key, const char *certificates, const char *intermediates, const struct Expando *exp)
Run an SMIME command.
Definition: smime.c:225
String manipulation buffer.
Definition: buffer.h:36
Parsed Expando trees.
Definition: expando.h:41
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
#define mutt_file_mkstemp()
Definition: tmp.h:36
+ Here is the call graph for this function: