Coverage Report

Created: 2025-04-22 06:17

/src/neomutt/ncrypt/expando_smime.c
Line
Count
Source (jump to first uncovered line)
1
/**
2
 * @file
3
 * Ncrypt Expando definitions
4
 *
5
 * @authors
6
 * Copyright (C) 2024 Richard Russon <rich@flatcap.org>
7
 *
8
 * @copyright
9
 * This program is free software: you can redistribute it and/or modify it under
10
 * the terms of the GNU General Public License as published by the Free Software
11
 * Foundation, either version 2 of the License, or (at your option) any later
12
 * version.
13
 *
14
 * This program is distributed in the hope that it will be useful, but WITHOUT
15
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17
 * details.
18
 *
19
 * You should have received a copy of the GNU General Public License along with
20
 * this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
/**
24
 * @page ncrypt_expando_smime Ncrypt Expando definitions
25
 *
26
 * Ncrypt Expando definitions
27
 */
28
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
40
/**
41
 * smime_command_algorithm - Smime Command: algorithm - Implements ::get_string_t - @ingroup expando_get_string_api
42
 */
43
static void smime_command_algorithm(const struct ExpandoNode *node, void *data,
44
                                    MuttFormatFlags flags, struct Buffer *buf)
45
0
{
46
0
  const struct SmimeCommandContext *cctx = data;
47
48
0
  const char *s = cctx->cryptalg;
49
0
  buf_strcpy(buf, s);
50
0
}
51
52
/**
53
 * smime_command_certificate_ids - Smime Command: certificate IDs - Implements ::get_string_t - @ingroup expando_get_string_api
54
 */
55
static void smime_command_certificate_ids(const struct ExpandoNode *node, void *data,
56
                                          MuttFormatFlags flags, struct Buffer *buf)
57
0
{
58
0
  const struct SmimeCommandContext *cctx = data;
59
60
0
  const char *s = cctx->certificates;
61
0
  buf_strcpy(buf, s);
62
0
}
63
64
/**
65
 * smime_command_certificate_path - Smime Command: CA location - Implements ::get_string_t - @ingroup expando_get_string_api
66
 */
67
static void smime_command_certificate_path(const struct ExpandoNode *node, void *data,
68
                                           MuttFormatFlags flags, struct Buffer *buf)
69
0
{
70
0
  const char *const c_smime_ca_location = cs_subset_path(NeoMutt->sub, "smime_ca_location");
71
72
0
  struct Buffer *path = buf_pool_get();
73
0
  struct Buffer *buf1 = buf_pool_get();
74
0
  struct Buffer *buf2 = buf_pool_get();
75
0
  struct stat st = { 0 };
76
77
0
  buf_strcpy(path, c_smime_ca_location);
78
0
  buf_expand_path(path);
79
0
  buf_quote_filename(buf1, buf_string(path), true);
80
81
0
  if ((stat(buf_string(path), &st) != 0) || !S_ISDIR(st.st_mode))
82
0
  {
83
0
    buf_printf(buf2, "-CAfile %s", buf_string(buf1));
84
0
  }
85
0
  else
86
0
  {
87
0
    buf_printf(buf2, "-CApath %s", buf_string(buf1));
88
0
  }
89
90
0
  buf_copy(buf, buf2);
91
92
0
  buf_pool_release(&path);
93
0
  buf_pool_release(&buf1);
94
0
  buf_pool_release(&buf2);
95
0
}
96
97
/**
98
 * smime_command_digest_algorithm - Smime Command: Message digest algorithm - Implements ::get_string_t - @ingroup expando_get_string_api
99
 */
100
static void smime_command_digest_algorithm(const struct ExpandoNode *node, void *data,
101
                                           MuttFormatFlags flags, struct Buffer *buf)
102
0
{
103
0
  const struct SmimeCommandContext *cctx = data;
104
105
0
  const char *s = cctx->digestalg;
106
0
  buf_strcpy(buf, s);
107
0
}
108
109
/**
110
 * smime_command_intermediate_ids - Smime Command: Intermediate certificates - Implements ::get_string_t - @ingroup expando_get_string_api
111
 */
112
static void smime_command_intermediate_ids(const struct ExpandoNode *node, void *data,
113
                                           MuttFormatFlags flags, struct Buffer *buf)
114
0
{
115
0
  const struct SmimeCommandContext *cctx = data;
116
117
0
  const char *s = cctx->intermediates;
118
0
  buf_strcpy(buf, s);
119
0
}
120
121
/**
122
 * smime_command_key - Smime Command: Key-pair - Implements ::get_string_t - @ingroup expando_get_string_api
123
 */
124
static void smime_command_key(const struct ExpandoNode *node, void *data,
125
                              MuttFormatFlags flags, struct Buffer *buf)
126
0
{
127
0
  const struct SmimeCommandContext *cctx = data;
128
129
0
  const char *s = cctx->key;
130
0
  buf_strcpy(buf, s);
131
0
}
132
133
/**
134
 * smime_command_message_file - Smime Command: Filename of message - Implements ::get_string_t - @ingroup expando_get_string_api
135
 */
136
static void smime_command_message_file(const struct ExpandoNode *node, void *data,
137
                                       MuttFormatFlags flags, struct Buffer *buf)
138
0
{
139
0
  const struct SmimeCommandContext *cctx = data;
140
141
0
  const char *s = cctx->fname;
142
0
  buf_strcpy(buf, s);
143
0
}
144
145
/**
146
 * smime_command_signature_file - Smime Command: Filename of signature - Implements ::get_string_t - @ingroup expando_get_string_api
147
 */
148
static void smime_command_signature_file(const struct ExpandoNode *node, void *data,
149
                                         MuttFormatFlags flags, struct Buffer *buf)
150
0
{
151
0
  const struct SmimeCommandContext *cctx = data;
152
153
0
  const char *s = cctx->sig_fname;
154
0
  buf_strcpy(buf, s);
155
0
}
156
157
/**
158
 * SmimeCommandRenderCallbacks - Callbacks for Smime Command Expandos
159
 *
160
 * @sa SmimeCommandFormatDef, ExpandoDataGlobal, ExpandoDataSmimeCmd
161
 */
162
const struct ExpandoRenderCallback SmimeCommandRenderCallbacks[] = {
163
  // clang-format off
164
  { ED_SMIME_CMD, ED_SMI_ALGORITHM,        smime_command_algorithm,        NULL },
165
  { ED_SMIME_CMD, ED_SMI_CERTIFICATE_IDS,  smime_command_certificate_ids,  NULL },
166
  { ED_SMIME_CMD, ED_SMI_CERTIFICATE_PATH, smime_command_certificate_path, NULL },
167
  { ED_SMIME_CMD, ED_SMI_DIGEST_ALGORITHM, smime_command_digest_algorithm, NULL },
168
  { ED_SMIME_CMD, ED_SMI_INTERMEDIATE_IDS, smime_command_intermediate_ids, NULL },
169
  { ED_SMIME_CMD, ED_SMI_KEY,              smime_command_key,              NULL },
170
  { ED_SMIME_CMD, ED_SMI_MESSAGE_FILE,     smime_command_message_file,     NULL },
171
  { ED_SMIME_CMD, ED_SMI_SIGNATURE_FILE,   smime_command_signature_file,   NULL },
172
  { -1, -1, NULL, NULL },
173
  // clang-format on
174
};