NeoMutt  2024-11-14-138-ge5ca67
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
expando_smime.c
Go to the documentation of this file.
1
29#include <stdbool.h>
30#include <stdio.h>
31#include <sys/stat.h>
32#include "mutt/lib.h"
33#include "config/lib.h"
34#include "core/lib.h"
35#include "expando_smime.h"
36#include "expando/lib.h"
37#include "muttlib.h"
38#include "smime.h"
39
43static void smime_command_algorithm(const struct ExpandoNode *node, void *data,
44 MuttFormatFlags flags, struct Buffer *buf)
45{
46 const struct SmimeCommandContext *cctx = data;
47
48 const char *s = cctx->cryptalg;
49 buf_strcpy(buf, s);
50}
51
55static void smime_command_certificate_ids(const struct ExpandoNode *node, void *data,
56 MuttFormatFlags flags, struct Buffer *buf)
57{
58 const struct SmimeCommandContext *cctx = data;
59
60 const char *s = cctx->certificates;
61 buf_strcpy(buf, s);
62}
63
67static void smime_command_certificate_path(const struct ExpandoNode *node, void *data,
68 MuttFormatFlags flags, struct Buffer *buf)
69{
70 const char *const c_smime_ca_location = cs_subset_path(NeoMutt->sub, "smime_ca_location");
71
72 struct Buffer *path = buf_pool_get();
73 struct Buffer *buf1 = buf_pool_get();
74 struct Buffer *buf2 = buf_pool_get();
75 struct stat st = { 0 };
76
77 buf_strcpy(path, c_smime_ca_location);
78 buf_expand_path(path);
79 buf_quote_filename(buf1, buf_string(path), true);
80
81 if ((stat(buf_string(path), &st) != 0) || !S_ISDIR(st.st_mode))
82 {
83 buf_printf(buf2, "-CAfile %s", buf_string(buf1));
84 }
85 else
86 {
87 buf_printf(buf2, "-CApath %s", buf_string(buf1));
88 }
89
90 buf_copy(buf, buf2);
91
92 buf_pool_release(&path);
93 buf_pool_release(&buf1);
94 buf_pool_release(&buf2);
95}
96
100static void smime_command_digest_algorithm(const struct ExpandoNode *node, void *data,
101 MuttFormatFlags flags, struct Buffer *buf)
102{
103 const struct SmimeCommandContext *cctx = data;
104
105 const char *s = cctx->digestalg;
106 buf_strcpy(buf, s);
107}
108
112static void smime_command_intermediate_ids(const struct ExpandoNode *node, void *data,
113 MuttFormatFlags flags, struct Buffer *buf)
114{
115 const struct SmimeCommandContext *cctx = data;
116
117 const char *s = cctx->intermediates;
118 buf_strcpy(buf, s);
119}
120
124static void smime_command_key(const struct ExpandoNode *node, void *data,
125 MuttFormatFlags flags, struct Buffer *buf)
126{
127 const struct SmimeCommandContext *cctx = data;
128
129 const char *s = cctx->key;
130 buf_strcpy(buf, s);
131}
132
136static void smime_command_message_file(const struct ExpandoNode *node, void *data,
137 MuttFormatFlags flags, struct Buffer *buf)
138{
139 const struct SmimeCommandContext *cctx = data;
140
141 const char *s = cctx->fname;
142 buf_strcpy(buf, s);
143}
144
148static void smime_command_signature_file(const struct ExpandoNode *node, void *data,
149 MuttFormatFlags flags, struct Buffer *buf)
150{
151 const struct SmimeCommandContext *cctx = data;
152
153 const char *s = cctx->sig_fname;
154 buf_strcpy(buf, s);
155}
156
163 // clang-format off
172 { -1, -1, NULL, NULL },
173 // clang-format on
174};
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:161
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:395
size_t buf_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
Definition: buffer.c:601
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition: helpers.c:168
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
@ ED_SMIME_CMD
Smime Command ED_SMI_ ExpandoDataSmimeCmd.
Definition: domain.h:55
Parse Expando string.
const struct ExpandoRenderCallback SmimeCommandRenderCallbacks[]
Callbacks for Smime Command Expandos.
Ncrypt Smime Expando definitions.
void buf_quote_filename(struct Buffer *buf, const char *filename, bool add_outer)
Quote a filename to survive the shell's quoting rules.
Definition: file.c:933
static void smime_command_message_file(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Smime Command: Filename of message - Implements get_string_t -.
static void smime_command_signature_file(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Smime Command: Filename of signature - Implements get_string_t -.
static void smime_command_certificate_ids(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Smime Command: certificate IDs - Implements get_string_t -.
Definition: expando_smime.c:55
static void smime_command_key(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Smime Command: Key-pair - Implements get_string_t -.
static void smime_command_intermediate_ids(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Smime Command: Intermediate certificates - Implements get_string_t -.
static void smime_command_digest_algorithm(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Smime Command: Message digest algorithm - Implements get_string_t -.
static void smime_command_certificate_path(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Smime Command: CA location - Implements get_string_t -.
Definition: expando_smime.c:67
static void smime_command_algorithm(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Smime Command: algorithm - Implements get_string_t -.
Definition: expando_smime.c:43
Convenience wrapper for the library headers.
void buf_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:315
Some miscellaneous functions.
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
uint8_t MuttFormatFlags
Flags for expando_render(), e.g. MUTT_FORMAT_FORCESUBJ.
Definition: render.h:32
SMIME helper routines.
@ ED_SMI_MESSAGE_FILE
SmimeCommandContext.fname.
Definition: smime.h:81
@ ED_SMI_ALGORITHM
SmimeCommandContext.cryptalg.
Definition: smime.h:75
@ ED_SMI_SIGNATURE_FILE
SmimeCommandContext.sig_fname.
Definition: smime.h:82
@ ED_SMI_DIGEST_ALGORITHM
SmimeCommandContext.digestalg.
Definition: smime.h:78
@ ED_SMI_CERTIFICATE_IDS
SmimeCommandContext.certificates.
Definition: smime.h:76
@ ED_SMI_KEY
SmimeCommandContext.key.
Definition: smime.h:80
@ ED_SMI_INTERMEDIATE_IDS
SmimeCommandContext.intermediates.
Definition: smime.h:79
@ ED_SMI_CERTIFICATE_PATH
Path of Smime certificates.
Definition: smime.h:77
String manipulation buffer.
Definition: buffer.h:36
Basic Expando Node.
Definition: node.h:67
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
Data for a SIME command.
Definition: smime.h:58
const char * sig_fname
s
Definition: smime.h:63
const char * intermediates
i
Definition: smime.h:65
const char * digestalg
d
Definition: smime.h:61
const char * cryptalg
a
Definition: smime.h:60
const char * key
k
Definition: smime.h:59
const char * fname
f
Definition: smime.h:62
const char * certificates
c
Definition: smime.h:64