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