Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
3e3c09c6bc | |||
ebc9192ae2 | |||
e41a627882 | |||
2aa147b351 |
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
#define LM_VERSION "24.04"
|
#define LM_VERSION "24.05"
|
||||||
|
|
||||||
#include "ctx.h"
|
#include "ctx.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
@ -140,7 +140,7 @@ typedef enum lm_error {
|
|||||||
LM_ERR_InstallSaveFail = 138,
|
LM_ERR_InstallSaveFail = 138,
|
||||||
LM_ERR_FailMkdir = 139,
|
LM_ERR_FailMkdir = 139,
|
||||||
LM_ERR_NotDir = 140,
|
LM_ERR_NotDir = 140,
|
||||||
LM_ERR_NoWrite = 141,
|
LM_ERR_NoRead = 141,
|
||||||
LM_ERR_PoolListBadDir = 142,
|
LM_ERR_PoolListBadDir = 142,
|
||||||
LM_ERR_FileNotExist = 143,
|
LM_ERR_FileNotExist = 143,
|
||||||
LM_ERR_FileNotLink = 144,
|
LM_ERR_FileNotLink = 144,
|
||||||
|
@ -42,7 +42,7 @@ void pdebug_binary(char *data, size_t len);
|
|||||||
bool parse_host(char *addr, char *host, uint16_t *port);
|
bool parse_host(char *addr, char *host, uint16_t *port);
|
||||||
bool copy_blocks(struct archive *w, struct archive *r);
|
bool copy_blocks(struct archive *w, struct archive *r);
|
||||||
bool extract_archive(char *dst, char *src);
|
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_multiple(char *res, const char *base, const char *pth, const char *pth2);
|
||||||
int join(char *res, const char *base, const char *pth);
|
int join(char *res, const char *base, const char *pth);
|
||||||
|
@ -8,7 +8,7 @@ msgid ""
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: PACKAGE VERSION\n"
|
"Project-Id-Version: PACKAGE VERSION\n"
|
||||||
"Report-Msgid-Bugs-To: \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"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
@ -600,7 +600,7 @@ msgid "failed to create install script save directory"
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/error.c:171
|
#: src/error.c:171
|
||||||
msgid "directory does not have write permissions"
|
msgid "directory does not have read permissions"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/error.c:172
|
#: src/error.c:172
|
||||||
|
@ -3,15 +3,16 @@
|
|||||||
#include "../../include/ctx.h"
|
#include "../../include/ctx.h"
|
||||||
|
|
||||||
#include <linux/limits.h>
|
#include <linux/limits.h>
|
||||||
|
#include <strings.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <strings.h>
|
#include <errno.h>
|
||||||
|
|
||||||
bool __lm_ctx_init_checkdir(char *path){
|
bool __lm_ctx_init_checkdir(char *path){
|
||||||
if(!mkdir_ifnot(path)){
|
if(!mkdir_ifnot(path, 0755)){
|
||||||
lm_error_set(LM_ERR_FailMkdir);
|
lm_error_set(LM_ERR_FailMkdir);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -21,8 +22,8 @@ bool __lm_ctx_init_checkdir(char *path){
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!can_write(path)){
|
if(!can_read(path)){
|
||||||
lm_error_set(LM_ERR_NoWrite);
|
lm_error_set(LM_ERR_NoRead);
|
||||||
return false;
|
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;
|
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)
|
if(root_dir != NULL)
|
||||||
ctx->root = realpath(root_dir, NULL);
|
ctx->root = realpath(root_dir, NULL);
|
||||||
|
|
||||||
@ -94,6 +101,8 @@ end:
|
|||||||
|
|
||||||
void lm_ctx_free(lm_ctx_t *ctx) {
|
void lm_ctx_free(lm_ctx_t *ctx) {
|
||||||
lm_ctx_pool_clear(ctx);
|
lm_ctx_pool_clear(ctx);
|
||||||
|
lm_ctx_temp_clear(ctx);
|
||||||
|
|
||||||
free(ctx->data);
|
free(ctx->data);
|
||||||
free(ctx->root);
|
free(ctx->root);
|
||||||
free(ctx->temp);
|
free(ctx->temp);
|
||||||
|
@ -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);
|
sprintf(script_name, "install_%s", pkg->data.name);
|
||||||
join(script_dir, ctx->data, "scripts");
|
join(script_dir, ctx->data, "scripts");
|
||||||
|
|
||||||
if(!mkdir_ifnot(script_dir)){
|
if(!mkdir_ifnot(script_dir, 0755)){
|
||||||
lm_error_set(LM_ERR_InstallDirFail);
|
lm_error_set(LM_ERR_InstallDirFail);
|
||||||
return false;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!mkdir_ifnot(ctx->temp)){
|
if(!lm_ctx_temp_clear(ctx))
|
||||||
lm_error_set(LM_ERR_CtxTempFailMkdir);
|
return false; // error set by function
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!lm_ctx_database_init(ctx))
|
if(!lm_ctx_database_init(ctx))
|
||||||
return false; // error set by function
|
return false; // error set by function
|
||||||
|
@ -19,7 +19,7 @@ char *lm_ctx_temp_dir(lm_ctx_t *ctx, char *dir){
|
|||||||
char td[strlen(ctx->temp)+strlen(dir)+10];
|
char td[strlen(ctx->temp)+strlen(dir)+10];
|
||||||
join(td, ctx->temp, dir);
|
join(td, ctx->temp, dir);
|
||||||
|
|
||||||
if(!mkdir_ifnot(td)){
|
if(!mkdir_ifnot(td, 0755)){
|
||||||
lm_error_set(LM_ERR_CtxTempFailMkdir);
|
lm_error_set(LM_ERR_CtxTempFailMkdir);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -35,11 +35,10 @@ bool lm_ctx_temp_clear(lm_ctx_t *ctx) {
|
|||||||
|
|
||||||
rmrf(ctx->temp);
|
rmrf(ctx->temp);
|
||||||
|
|
||||||
if(!mkdir_ifnot(ctx->temp)){
|
if(!mkdir_ifnot(ctx->temp, 0755)){
|
||||||
lm_error_set(LM_ERR_CtxTempFailMkdir);
|
lm_error_set(LM_ERR_CtxTempFailMkdir);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,12 +38,12 @@ lm_database_t *lm_database_new(char *path){
|
|||||||
char *err = NULL;
|
char *err = NULL;
|
||||||
bzero(db, sizeof(lm_database_t));
|
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);
|
lm_error_set(LM_ERR_DbCantAccess);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!exists(path, NULL) && !mkdir_ifnot(path)){
|
if(!exists(path, NULL) && !mkdir_ifnot(path, 0755)){
|
||||||
lm_error_set(LM_ERR_DbCantAccess);
|
lm_error_set(LM_ERR_DbCantAccess);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ lm_database_t *lm_database_new(char *path){
|
|||||||
return NULL;
|
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);
|
pdebug(__func__, "(%s) failed to create packages table: %s", packagesdb, err);
|
||||||
lm_error_set(LM_ERR_DbSqlCreateFail);
|
lm_error_set(LM_ERR_DbSqlCreateFail);
|
||||||
sqlite3_free(err);
|
sqlite3_free(err);
|
||||||
|
@ -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_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_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_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_NotDir, .desc = _("specified path is not a directory") },
|
||||||
{.code = LM_ERR_FailMkdir, .desc = _("failed to create the specified directory") },
|
{.code = LM_ERR_FailMkdir, .desc = _("failed to create the specified directory") },
|
||||||
{.code = LM_ERR_PoolListBadDir, .desc = _("specified list extraction directory is not accessible") },
|
{.code = LM_ERR_PoolListBadDir, .desc = _("specified list extraction directory is not accessible") },
|
||||||
|
@ -89,7 +89,7 @@ bool lm_pool_info_download(lm_pool_t *pool, lm_mptp_transfer_callback_t callback
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!mkdir_ifnot(pool->dir)){
|
if(!mkdir_ifnot(pool->dir, 0755)){
|
||||||
lm_error_set(LM_ERR_PoolBadDir);
|
lm_error_set(LM_ERR_PoolBadDir);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -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);
|
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);
|
lm_error_set(LM_ERR_PoolBadDir);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!mkdir_ifnot(dir)){
|
if(!mkdir_ifnot(dir, 0755)){
|
||||||
lm_error_set(LM_ERR_PoolListBadDir);
|
lm_error_set(LM_ERR_PoolListBadDir);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -102,7 +102,7 @@ bool lm_pool_list_download(lm_pool_t *pool, char *dir, lm_mptp_transfer_callback
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!mkdir_ifnot(pool->dir)){
|
if(!mkdir_ifnot(pool->dir, 0755)){
|
||||||
lm_error_set(LM_ERR_PoolBadDir);
|
lm_error_set(LM_ERR_PoolBadDir);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ bool lm_pool_path_set_dir(lm_pool_t *pool, char *dir){
|
|||||||
if(NULL == dir)
|
if(NULL == dir)
|
||||||
return true;
|
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);
|
lm_error_set(LM_ERR_PoolBadDir);
|
||||||
return false;
|
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->info_file = join_alloc(dir, "INFO");
|
||||||
pool->list_file = join_alloc(dir, "LIST");
|
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);
|
lm_error_set(LM_ERR_PoolBadPaths);
|
||||||
return false;
|
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);
|
lm_error_set(LM_ERR_PoolBadPaths);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -278,8 +278,8 @@ bool can_write(char *path) {
|
|||||||
return access(path, W_OK) == 0;
|
return access(path, W_OK) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mkdir_ifnot(char *path) {
|
bool mkdir_ifnot(char *path, int mode) {
|
||||||
return !(mkdir(path, 0700) < 0 && errno != EEXIST);
|
return !(mkdir(path, mode) < 0 && errno != EEXIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool package_name_valid(char *name) {
|
bool package_name_valid(char *name) {
|
||||||
|
Reference in New Issue
Block a user