NeoMutt  2022-04-29-145-g9b6a0e
Teaching an old dog new tricks

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

+ Collaboration diagram for smime_invoke_import():


void smime_class_invoke_import (const char *infile, const char *mailbox)
 Implements CryptModuleSpecs::smime_invoke_import() -. More...

Detailed Description

Add a certificate and update index file (externally)

infileFile containing certificate

Function Documentation

◆ smime_class_invoke_import()

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

Implements CryptModuleSpecs::smime_invoke_import() -.

Definition at line 1158 of file smime.c.

1159 {
1160  char *certfile = NULL;
1161  struct Buffer *buf = NULL;
1163  FILE *fp_err = mutt_file_mkstemp();
1164  if (!fp_err)
1165  {
1166  mutt_perror(_("Can't create temporary file"));
1167  goto done;
1168  }
1170  FILE *fp_out = mutt_file_mkstemp();
1171  if (!fp_out)
1172  {
1173  mutt_perror(_("Can't create temporary file"));
1174  goto done;
1175  }
1177  buf = mutt_buffer_pool_get();
1178  const bool c_smime_ask_cert_label = cs_subset_bool(NeoMutt->sub, "smime_ask_cert_label");
1179  if (c_smime_ask_cert_label)
1180  {
1181  if ((mutt_buffer_get_field(_("Label for certificate: "), buf,
1182  MUTT_COMP_NO_FLAGS, false, NULL, NULL, NULL) != 0) ||
1183  mutt_buffer_is_empty(buf))
1184  {
1185  goto done;
1186  }
1187  }
1189  mutt_endwin();
1190  certfile = smime_extract_certificate(infile);
1191  if (certfile)
1192  {
1193  mutt_endwin();
1195  const char *const c_smime_import_cert_command = cs_subset_string(NeoMutt->sub, "smime_import_cert_command");
1196  FILE *fp_smime_in = NULL;
1197  pid_t pid = smime_invoke(&fp_smime_in, NULL, NULL, -1, fileno(fp_out),
1198  fileno(fp_err), certfile, NULL, NULL, NULL, NULL,
1199  NULL, NULL, c_smime_import_cert_command);
1200  if (pid == -1)
1201  {
1202  mutt_message(_("Error: unable to create OpenSSL subprocess"));
1203  goto done;
1204  }
1205  fputs(mutt_buffer_string(buf), fp_smime_in);
1206  fputc('\n', fp_smime_in);
1207  mutt_file_fclose(&fp_smime_in);
1209  filter_wait(pid);
1211  mutt_file_unlink(certfile);
1212  FREE(&certfile);
1213  }
1215  fflush(fp_out);
1216  rewind(fp_out);
1217  fflush(fp_err);
1218  rewind(fp_err);
1220  mutt_file_copy_stream(fp_out, stdout);
1221  mutt_file_copy_stream(fp_err, stdout);
1223 done:
1224  mutt_file_fclose(&fp_out);
1225  mutt_file_fclose(&fp_err);
1227 }
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:250
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
void mutt_endwin(void)
Shutdown curses.
Definition: curs_lib.c:355
int mutt_buffer_get_field(const char *field, struct Buffer *buf, CompletionFlags complete, bool multiple, struct Mailbox *m, char ***files, int *numfiles)
Ask the user for a string.
Definition: window.c:180
int mutt_file_copy_stream(FILE *fp_in, FILE *fp_out)
Copy the contents of one file into another.
Definition: file.c:260
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:152
void mutt_file_unlink(const char *s)
Delete a file, carefully.
Definition: file.c:194
#define mutt_file_mkstemp()
Definition: file.h:112
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:217
#define mutt_message(...)
Definition: logging.h:86
#define mutt_perror(...)
Definition: logging.h:88
#define FREE(x)
Definition: memory.h:43
#define _(a)
Definition: message.h:28
No flags are set.
Definition: mutt.h:52
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
static char * smime_extract_certificate(const char *infile)
Extract an SMIME certificate from a file.
Definition: smime.c:975
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 char *format)
Run an SMIME command.
Definition: smime.c:404
String manipulation buffer.
Definition: buffer.h:34
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ Here is the call graph for this function: