ascii-chat 0.11.33
Video chat in your terminal
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)
 Create a temporary GPG homedir for isolated key operations.
 
const char * gpg_homedir_path (const gpg_homedir_t *homedir)
 Get the homedir path for use in GPG commands.
 
void gpg_homedir_destroy (gpg_homedir_t *homedir)
 Destroy a temporary GPG homedir and clean up all files.
 

Detailed Description

Temporary GPG homedir management implementation.

Definition in file homedir.c.

Function Documentation

◆ gpg_homedir_create()

gpg_homedir_t * gpg_homedir_create ( void  )

Create a temporary GPG homedir for isolated key operations.

Creates a new temporary directory configured for GPG use. The directory is isolated from the user's main GPG keyring.

Returns
Pointer to homedir handle on success, NULL on failure Caller must destroy with gpg_homedir_destroy()
Note
The directory is created in the system temp location (TMPDIR, /tmp, etc.)

Definition at line 22 of file homedir.c.

22 {
24 if (!homedir) {
25 log_error("Failed to allocate memory for GPG homedir handle");
26 return NULL;
27 }
28
29 /* Create temporary directory using platform abstraction */
30 if (platform_mkdtemp(homedir->path, sizeof(homedir->path), "ascii-chat-gpg") != 0) {
31 log_error("Failed to create temporary GPG homedir");
32 SAFE_FREE(homedir);
33 return NULL;
34 }
35
36 /* Restrict permissions to owner only (mode 0700) using platform abstraction */
37 if (platform_chmod(homedir->path, 0700) != 0) {
38 log_warn("Failed to set permissions on GPG homedir, attempting cleanup");
39 platform_rmdir_recursive(homedir->path);
40 SAFE_FREE(homedir);
41 return NULL;
42 }
43
44 log_debug("Created temporary GPG homedir: %s", homedir->path);
45 return homedir;
46}
#define SAFE_FREE(ptr)
Definition common.h:376
#define SAFE_MALLOC(size, cast)
Definition common.h:264
#define log_warn(...)
Log a WARN message.
Definition log/log.h:574
#define log_error(...)
Log an ERROR message.
Definition log/log.h:587
#define log_debug(...)
Log a DEBUG message.
Definition log/log.h:548
int platform_chmod(const char *pathname, int mode)
Change file permissions/mode.
asciichat_error_t platform_rmdir_recursive(const char *path)
Recursively delete a directory and all its contents.
asciichat_error_t platform_mkdtemp(char *path_out, size_t path_size, const char *prefix)
Create a temporary directory with a given prefix.
Opaque handle to a temporary GPG homedir.

References log_debug, log_error, log_warn, platform_chmod(), platform_mkdtemp(), platform_rmdir_recursive(), SAFE_FREE, and SAFE_MALLOC.

◆ gpg_homedir_destroy()

void gpg_homedir_destroy ( gpg_homedir_t *  homedir)

Destroy a temporary GPG homedir and clean up all files.

Recursively deletes the temporary directory and all its contents. Safe to call on NULL pointer (no-op).

Parameters
homedirHandle from gpg_homedir_create() (can be NULL)

Definition at line 55 of file homedir.c.

55 {
56 if (!homedir) {
57 return;
58 }
59
60 /* Recursively delete the entire directory and all contents using platform abstraction */
61 if (platform_rmdir_recursive(homedir->path) != 0) {
62 log_warn("Failed to completely clean up GPG homedir: %s", homedir->path);
63 } else {
64 log_debug("Cleaned up temporary GPG homedir: %s", homedir->path);
65 }
66
67 SAFE_FREE(homedir);
68}

References log_debug, log_warn, platform_rmdir_recursive(), and SAFE_FREE.

◆ gpg_homedir_path()

const char * gpg_homedir_path ( const gpg_homedir_t *  homedir)

Get the homedir path for use in GPG commands.

Returns the filesystem path of the temporary homedir. This path should be used with gpg's –homedir flag.

Parameters
homedirHandle from gpg_homedir_create()
Returns
Pointer to path string (valid until gpg_homedir_destroy() is called) Returns NULL if homedir is invalid

Definition at line 48 of file homedir.c.

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