ascii-chat 0.8.38
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
homedir.c
Go to the documentation of this file.
1
7#include <ascii-chat/crypto/gpg/homedir.h>
8#include <ascii-chat/common.h>
9#include <ascii-chat/log/logging.h>
10#include <ascii-chat/platform/util.h>
11#include <ascii-chat/platform/filesystem.h>
12#include <string.h>
13#include <stdlib.h>
14
22
23gpg_homedir_t *gpg_homedir_create(void) {
24 gpg_homedir_t *homedir = SAFE_MALLOC(sizeof(gpg_homedir_t), gpg_homedir_t *);
25 if (!homedir) {
26 log_error("Failed to allocate memory for GPG homedir handle");
27 return NULL;
28 }
29
30 /* Create temporary directory using platform abstraction */
31 if (platform_mkdtemp(homedir->path, sizeof(homedir->path), "ascii-chat-gpg") != 0) {
32 log_error("Failed to create temporary GPG homedir");
33 SAFE_FREE(homedir);
34 return NULL;
35 }
36
37 /* Restrict permissions to owner only (mode 0700) using platform abstraction */
38 if (platform_chmod(homedir->path, 0700) != 0) {
39 log_warn("Failed to set permissions on GPG homedir, attempting cleanup");
40 platform_rmdir_recursive(homedir->path);
41 SAFE_FREE(homedir);
42 return NULL;
43 }
44
45 log_debug("Created temporary GPG homedir: %s", homedir->path);
46 return homedir;
47}
48
49const char *gpg_homedir_path(const gpg_homedir_t *homedir) {
50 if (!homedir) {
51 return NULL;
52 }
53 return homedir->path;
54}
55
56void gpg_homedir_destroy(gpg_homedir_t *homedir) {
57 if (!homedir) {
58 return;
59 }
60
61 /* Recursively delete the entire directory and all contents using platform abstraction */
62 if (platform_rmdir_recursive(homedir->path) != 0) {
63 log_warn("Failed to completely clean up GPG homedir: %s", homedir->path);
64 } else {
65 log_debug("Cleaned up temporary GPG homedir: %s", homedir->path);
66 }
67
68 SAFE_FREE(homedir);
69}
const char * gpg_homedir_path(const gpg_homedir_t *homedir)
Definition homedir.c:49
void gpg_homedir_destroy(gpg_homedir_t *homedir)
Definition homedir.c:56
gpg_homedir_t * gpg_homedir_create(void)
Definition homedir.c:23
Internal structure for temporary GPG homedir.
Definition homedir.c:19
char path[PLATFORM_MAX_PATH_LENGTH]
Definition homedir.c:20
#define PLATFORM_MAX_PATH_LENGTH
Definition system.c:64