created why2_get_authority_cert_path fn

This commit is contained in:
Václav Šmejkal 2025-02-01 16:26:32 +01:00
parent 43f4d31023
commit 61c06dc25a
Signed by: ENGO150
GPG Key ID: 4A57E86482968843
2 changed files with 22 additions and 7 deletions

View File

@ -51,6 +51,7 @@ char *why2_chat_client_config(char *key); //hihi, *grabs shotgun quietly*
char *why2_get_server_users_path(void); //RETURNS WHY2_CHAT_CONFIG_SERVER_USERS LOCATION
char *why2_get_client_config_path(void); //RETURNS WHY2_CHAT_CONFIG_CLIENT LOCATION
char *why2_get_authority_cert_path(char *username); //RETURNS PATH TO CA CERTS
#ifdef __cplusplus
}

View File

@ -35,7 +35,8 @@ enum CONFIG_TYPES
{
CLIENT,
SERVER,
SERVER_USERS
SERVER_USERS,
AUTHORITY
};
void init_config(char *filename)
@ -97,6 +98,10 @@ char *config_path(enum CONFIG_TYPES type)
path = why2_replace(WHY2_CONFIG_DIR "/" WHY2_CHAT_CONFIG_SERVER_USERS, "{HOME}", getenv("HOME"));
break;
case AUTHORITY:
path = why2_replace(WHY2_CONFIG_DIR "/" WHY2_CHAT_AUTHORITY_DIR, "{HOME}", getenv("HOME"));
break;
default:
why2_die("CONFIG_TYPE not implemented!");
break;
@ -156,16 +161,11 @@ void why2_chat_init_authority(void)
why2_directory();
//GET THE CONFIG TYPE
char *buffer = why2_malloc(strlen(WHY2_CONFIG_DIR) + strlen(WHY2_CHAT_AUTHORITY_DIR) + 2);
sprintf(buffer, "%s/%s", WHY2_CONFIG_DIR, WHY2_CHAT_AUTHORITY_DIR);
char *path = why2_replace(buffer, "{HOME}", getenv("HOME"));
char *path = config_path(AUTHORITY);
if (access(path, R_OK) != 0) mkdir(path, 0700); //DIRECTORY DOESN'T EXIST; CREATE IT
//DEALLOCATION
why2_deallocate(path);
why2_deallocate(buffer);
}
char *why2_chat_server_config(char *key)
@ -187,3 +187,17 @@ char *why2_get_client_config_path(void)
{
return config_path(CLIENT);
}
char *why2_get_authority_cert_path(char *username)
{
char *buffer = config_path(AUTHORITY);
char *path = why2_malloc(strlen(buffer) + strlen(username) + strlen(WHY2_CHAT_AUTHORITY_CERTS_EXTENSION) + 2);
//GET THE FILE
sprintf(path, "%s/%s%s%c", buffer, username, WHY2_CHAT_AUTHORITY_CERTS_EXTENSION, '\0');
//DEALLOCATION
why2_deallocate(buffer);
return path;
}