ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
Video chat in your terminal
Loading...
Searching...
No Matches
homedir.c
Go to the documentation of this file.
1
6
7#include <recast/defer.h>
9#include <ascii-chat/common.h>
10#include <ascii-chat/log/log.h>
11#include <libplatform/filesystem.h>
12#include <string.h>
13#include <stdlib.h>
14
23
26 if (!homedir) {
27 log_error("Failed to allocate memory for GPG homedir handle");
28 return NULL;
29 }
30
31 /* Create temporary directory using platform abstraction */
32 if (platform_mkdtemp(homedir->path, sizeof(homedir->path), "ascii-chat-gpg") != 0) {
33 log_error("Failed to create temporary GPG homedir");
34 return NULL;
35 }
36
37 defer_named(temp_directory, platform_rmdir_recursive(homedir->path));
38
39 /* Restrict permissions to owner only (mode 0700) using platform abstraction */
40 if (platform_chmod(homedir->path, 0700) != 0) {
41 log_warn("Failed to set permissions on GPG homedir, attempting cleanup");
42 return NULL;
43 }
44
45 log_debug("Created temporary GPG homedir: %s", homedir->path);
46 defer_cancel(temp_directory);
47 gpg_homedir_t *result = homedir;
48 homedir = NULL;
49 return result;
50}
51
52const char *gpg_homedir_path(const gpg_homedir_t *homedir) {
53 if (!homedir) {
54 return NULL;
55 }
56 return homedir->path;
57}
58
60 if (!homedir) {
61 return;
62 }
63
64 /* Recursively delete the entire directory and all contents using platform abstraction */
65 if (platform_rmdir_recursive(homedir->path) != 0) {
66 log_warn("Failed to completely clean up GPG homedir: %s", homedir->path);
67 } else {
68 log_debug("Cleaned up temporary GPG homedir: %s", homedir->path);
69 }
70
71 SAFE_FREE(homedir);
72}
#define SAFE_FREE(ptr)
#define SAFE_MALLOC_DEFER_FREE(name, size, cast)
#define PLATFORM_MAX_PATH_LENGTH
#define log_warn(...)
Log a WARN message.
Definition log/log.h:615
#define log_error(...)
Log an ERROR message.
Definition log/log.h:628
#define log_debug(...)
Log a DEBUG message.
Definition log/log.h:589
const char * gpg_homedir_path(const gpg_homedir_t *homedir)
Get the homedir path for use in GPG commands.
Definition homedir.c:52
void gpg_homedir_destroy(gpg_homedir_t *homedir)
Destroy a temporary GPG homedir and clean up all files.
Definition homedir.c:59
gpg_homedir_t * gpg_homedir_create(void)
Create a temporary GPG homedir for isolated key operations.
Definition homedir.c:24
Temporary GPG homedir management for isolated key operations.
struct gpg_homedir gpg_homedir_t
Opaque handle to a temporary GPG homedir.
Definition homedir.h:45
⚙️ Common definitions, error codes, macros, and types shared throughout the application
📝 Logging API with multiple log levels and terminal output control
🔤 String Manipulation and Shell Escaping Utilities
Describes a temporary GnuPG home directory used to isolate key parsing from the user's real keyring....
Definition homedir.c:20
char path[4096]
Definition homedir.c:21