ascii-chat 0.8.38
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
homedir.c File Reference

Temporary GPG homedir management implementation. More...

Go to the source code of this file.

Data Structures

struct  gpg_homedir
 Internal structure for temporary GPG homedir. More...
 

Functions

gpg_homedir_t * gpg_homedir_create (void)
 
const char * gpg_homedir_path (const gpg_homedir_t *homedir)
 
void gpg_homedir_destroy (gpg_homedir_t *homedir)
 

Detailed Description

Temporary GPG homedir management implementation.

Definition in file homedir.c.

Function Documentation

◆ gpg_homedir_create()

gpg_homedir_t * gpg_homedir_create ( void  )

Definition at line 23 of file homedir.c.

23 {
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}

◆ gpg_homedir_destroy()

void gpg_homedir_destroy ( gpg_homedir_t *  homedir)

Definition at line 56 of file homedir.c.

56 {
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}

◆ gpg_homedir_path()

const char * gpg_homedir_path ( const gpg_homedir_t *  homedir)

Definition at line 49 of file homedir.c.

49 {
50 if (!homedir) {
51 return NULL;
52 }
53 return homedir->path;
54}