4 Commits
24.04 ... 24.05

Author SHA1 Message Date
ngn
3e3c09c6bc update: version macro 2024-08-16 06:52:39 +03:00
ngn
ebc9192ae2 fix: temp directory and permission fixes 2024-08-16 06:52:05 +03:00
ngn
e41a627882 fix: make dirs readable by other users 2024-08-16 05:25:02 +03:00
ngn
2aa147b351 fix: do not check write permissions for ctx dirs 2024-08-16 04:24:09 +03:00
13 changed files with 36 additions and 30 deletions

View File

@ -22,7 +22,7 @@
// clang-format on
#define LM_VERSION "24.04"
#define LM_VERSION "24.05"
#include "ctx.h"
#include "error.h"

View File

@ -140,7 +140,7 @@ typedef enum lm_error {
LM_ERR_InstallSaveFail = 138,
LM_ERR_FailMkdir = 139,
LM_ERR_NotDir = 140,
LM_ERR_NoWrite = 141,
LM_ERR_NoRead = 141,
LM_ERR_PoolListBadDir = 142,
LM_ERR_FileNotExist = 143,
LM_ERR_FileNotLink = 144,

View File

@ -42,7 +42,7 @@ void pdebug_binary(char *data, size_t len);
bool parse_host(char *addr, char *host, uint16_t *port);
bool copy_blocks(struct archive *w, struct archive *r);
bool extract_archive(char *dst, char *src);
bool mkdir_ifnot(char *path);
bool mkdir_ifnot(char *path, int mode);
int join_multiple(char *res, const char *base, const char *pth, const char *pth2);
int join(char *res, const char *base, const char *pth);

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-16 03:06+0300\n"
"POT-Creation-Date: 2024-08-16 06:47+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -600,7 +600,7 @@ msgid "failed to create install script save directory"
msgstr ""
#: src/error.c:171
msgid "directory does not have write permissions"
msgid "directory does not have read permissions"
msgstr ""
#: src/error.c:172

View File

@ -3,15 +3,16 @@
#include "../../include/ctx.h"
#include <linux/limits.h>
#include <strings.h>
#include <stdbool.h>
#include <stdlib.h>
#include <locale.h>
#include <string.h>
#include <stdio.h>
#include <strings.h>
#include <errno.h>
bool __lm_ctx_init_checkdir(char *path){
if(!mkdir_ifnot(path)){
if(!mkdir_ifnot(path, 0755)){
lm_error_set(LM_ERR_FailMkdir);
return false;
}
@ -21,8 +22,8 @@ bool __lm_ctx_init_checkdir(char *path){
return false;
}
if(!can_write(path)){
lm_error_set(LM_ERR_NoWrite);
if(!can_read(path)){
lm_error_set(LM_ERR_NoRead);
return false;
}
@ -63,6 +64,12 @@ bool lm_ctx_new(lm_ctx_t *ctx, char *root_dir, char *temp_dir, char *data_dir) {
goto end;
}
if(root_dir != NULL && !can_write(root_dir)){
pdebug(__func__, "check failed for specified root directory: %s", lm_strerror());
lm_error_set(LM_ERR_CtxRootFail, root_dir, "directory is not writeable");
goto end;
}
if(root_dir != NULL)
ctx->root = realpath(root_dir, NULL);
@ -94,6 +101,8 @@ end:
void lm_ctx_free(lm_ctx_t *ctx) {
lm_ctx_pool_clear(ctx);
lm_ctx_temp_clear(ctx);
free(ctx->data);
free(ctx->root);
free(ctx->temp);

View File

@ -29,7 +29,7 @@ bool __lm_ctx_save_install(lm_ctx_t *ctx, lm_pkg_t *pkg, char *install_path){
sprintf(script_name, "install_%s", pkg->data.name);
join(script_dir, ctx->data, "scripts");
if(!mkdir_ifnot(script_dir)){
if(!mkdir_ifnot(script_dir, 0755)){
lm_error_set(LM_ERR_InstallDirFail);
return false;
}
@ -229,10 +229,8 @@ bool lm_ctx_install(lm_ctx_t *ctx, lm_pkg_t *pkg, bool run_install, lm_ctx_insta
return false;
}
if(!mkdir_ifnot(ctx->temp)){
lm_error_set(LM_ERR_CtxTempFailMkdir);
return false;
}
if(!lm_ctx_temp_clear(ctx))
return false; // error set by function
if(!lm_ctx_database_init(ctx))
return false; // error set by function

View File

@ -19,7 +19,7 @@ char *lm_ctx_temp_dir(lm_ctx_t *ctx, char *dir){
char td[strlen(ctx->temp)+strlen(dir)+10];
join(td, ctx->temp, dir);
if(!mkdir_ifnot(td)){
if(!mkdir_ifnot(td, 0755)){
lm_error_set(LM_ERR_CtxTempFailMkdir);
return NULL;
}
@ -35,11 +35,10 @@ bool lm_ctx_temp_clear(lm_ctx_t *ctx) {
rmrf(ctx->temp);
if(!mkdir_ifnot(ctx->temp)){
if(!mkdir_ifnot(ctx->temp, 0755)){
lm_error_set(LM_ERR_CtxTempFailMkdir);
return false;
}
return true;
}

View File

@ -38,12 +38,12 @@ lm_database_t *lm_database_new(char *path){
char *err = NULL;
bzero(db, sizeof(lm_database_t));
if(exists(path, NULL) && (is_file(path) || !can_read(path) || !can_write(path))){
if(exists(path, NULL) && (is_file(path) || !can_read(path))){
lm_error_set(LM_ERR_DbCantAccess);
return NULL;
}
if(!exists(path, NULL) && !mkdir_ifnot(path)){
if(!exists(path, NULL) && !mkdir_ifnot(path, 0755)){
lm_error_set(LM_ERR_DbCantAccess);
return NULL;
}
@ -58,7 +58,7 @@ lm_database_t *lm_database_new(char *path){
return NULL;
}
if(sqlite3_exec(db->sql, queries[QUERY_CREATE_TABLE], NULL, 0, &err) != SQLITE_OK){
if(can_write(path) && sqlite3_exec(db->sql, queries[QUERY_CREATE_TABLE], NULL, 0, &err) != SQLITE_OK){
pdebug(__func__, "(%s) failed to create packages table: %s", packagesdb, err);
lm_error_set(LM_ERR_DbSqlCreateFail);
sqlite3_free(err);

View File

@ -168,7 +168,7 @@ void lm_error_set(lm_error_t code, ...) {
{.code = LM_ERR_DbChangesNotExists, .desc = _("package changes file not found in the database") },
{.code = LM_ERR_DbChangesChmodFail, .desc = _("failed to change mod of the changes file") },
{.code = LM_ERR_InstallDirFail, .desc = _("failed to create install script save directory") },
{.code = LM_ERR_NoWrite, .desc = _("directory does not have write permissions") },
{.code = LM_ERR_NoRead, .desc = _("directory does not have read permissions") },
{.code = LM_ERR_NotDir, .desc = _("specified path is not a directory") },
{.code = LM_ERR_FailMkdir, .desc = _("failed to create the specified directory") },
{.code = LM_ERR_PoolListBadDir, .desc = _("specified list extraction directory is not accessible") },

View File

@ -89,7 +89,7 @@ bool lm_pool_info_download(lm_pool_t *pool, lm_mptp_transfer_callback_t callback
return false;
}
if(!mkdir_ifnot(pool->dir)){
if(!mkdir_ifnot(pool->dir, 0755)){
lm_error_set(LM_ERR_PoolBadDir);
return false;
}

View File

@ -30,12 +30,12 @@ bool lm_pool_list_load(lm_pool_t *pool, char *dir){
pdebug(__func__, "(%s) extracting pool to %s", pool->name, dir);
if(!mkdir_ifnot(pool->dir)){
if(!mkdir_ifnot(pool->dir, 0755)){
lm_error_set(LM_ERR_PoolBadDir);
return false;
}
if(!mkdir_ifnot(dir)){
if(!mkdir_ifnot(dir, 0755)){
lm_error_set(LM_ERR_PoolListBadDir);
return false;
}
@ -102,7 +102,7 @@ bool lm_pool_list_download(lm_pool_t *pool, char *dir, lm_mptp_transfer_callback
return false;
}
if(!mkdir_ifnot(pool->dir)){
if(!mkdir_ifnot(pool->dir, 0755)){
lm_error_set(LM_ERR_PoolBadDir);
return false;
}

View File

@ -17,7 +17,7 @@ bool lm_pool_path_set_dir(lm_pool_t *pool, char *dir){
if(NULL == dir)
return true;
if(exists(dir, NULL) && (is_file(dir) || !can_read(dir) || !can_write(dir))){
if(exists(dir, NULL) && (is_file(dir) || !can_read(dir))){
lm_error_set(LM_ERR_PoolBadDir);
return false;
}
@ -26,12 +26,12 @@ bool lm_pool_path_set_dir(lm_pool_t *pool, char *dir){
pool->info_file = join_alloc(dir, "INFO");
pool->list_file = join_alloc(dir, "LIST");
if(exists(pool->info_file, NULL) && (!is_file(pool->info_file) || !can_read(pool->info_file) || !can_write(pool->info_file))){
if(exists(pool->info_file, NULL) && (!is_file(pool->info_file) || !can_read(pool->info_file))){
lm_error_set(LM_ERR_PoolBadPaths);
return false;
}
if(exists(pool->list_file, NULL) && (!is_file(pool->list_file) || !can_read(pool->list_file) || !can_write(pool->list_file))){
if(exists(pool->list_file, NULL) && (!is_file(pool->list_file) || !can_read(pool->list_file))){
lm_error_set(LM_ERR_PoolBadPaths);
return false;
}

View File

@ -278,8 +278,8 @@ bool can_write(char *path) {
return access(path, W_OK) == 0;
}
bool mkdir_ifnot(char *path) {
return !(mkdir(path, 0700) < 0 && errno != EEXIST);
bool mkdir_ifnot(char *path, int mode) {
return !(mkdir(path, mode) < 0 && errno != EEXIST);
}
bool package_name_valid(char *name) {