libmpm

morphux C package management library
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/libmpm

commit 49dea4cd435234f3da010f3d4679190a28f1f160
parent 050af83d2edb5157e0120a5d58d2dececc79d681
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Wed, 19 Apr 2017 19:30:11 +0200

Add(libsodium): Add libsodium in the dependencies

Diffstat:
M.gitmodules | 3+++
MMakefile | 12++++++++----
Minc/packer.h | 9+++++----
Alib/libsodium | 1+
Asrc/lib_init.c | 5+++++
Msrc/packer.c | 7++++++-
Mtests/Makefile | 3++-
7 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/.gitmodules b/.gitmodules @@ -13,3 +13,6 @@ [submodule "docs/doxygen-theme"] path = docs/doxygen-theme url = https://github.com/Ne02ptzero/doxygen-theme +[submodule "lib/libsodium"] + path = lib/libsodium + url = https://github.com/jedisct1/libsodium.git diff --git a/Makefile b/Makefile @@ -25,7 +25,8 @@ IFLAGS = -I inc/ \ -I lib/curl/lib/ \ -I lib/json-c/ \ -I lib/sqlite \ - -I lib/libconfuse/src/ + -I lib/libconfuse/src/ \ + -I lib/libsodium/src/libsodium/include/ # Optimisation Flags OFLAGS = -std=gnu99 -g -O3 @@ -37,7 +38,8 @@ SFLAGS = -Wall -Wextra -Werror -Wno-unused-result LFLAGS = -L lib/libmorphux -lmorphux \ -L ./lib/curl/lib/.libs/ -lcurl \ -L ./lib/json-c/.libs -ljson-c \ - -L ./lib/libconfuse/.libs -lconfuse + -L ./lib/libconfuse/.libs -lconfuse \ + -L ./lib/libsodium/src/libsodium/.libs/ -lsodium CFLAGS = $(SFLAGS) $(IFLAGS) $(OFLAGS) $(LFLAGS) ARFLAGS = -cq @@ -52,6 +54,7 @@ L_MORPHUX = ../lib/libmorphux/libmorphux.a L_CURL = ../lib/curl/lib/.libs/libcurl.a L_JSON = ../lib/json-c/.libs/libjson-c.a L_CONF = ../lib/libconfuse/src/.libs/libconfuse.a +L_SODIUM = ../lib/libsodium/src/libsodium/.libs/libsodium.a all: $(NAME) @@ -63,8 +66,8 @@ $(NAME): $(SQLITE) $(OBJS) @if [ ! -d "$(OBJ_DIR)" ]; then mkdir $(OBJ_DIR); fi @cp $(OBJS) $(OBJ_DIR) @cp $(SQLITE) $(OBJ_DIR) - @echo "AR\t\t$(L_MORPHUX) $(L_CURL) $(L_JSON) $(L_CONF)" - @cd $(OBJ_DIR) && ar -x $(L_MORPHUX) && ar -x $(L_CURL) && ar -x $(L_JSON) && ar -x $(L_CONF) + @echo "AR\t\t$(L_MORPHUX) $(L_CURL) $(L_JSON) $(L_CONF) $(L_SODIUM)" + @cd $(OBJ_DIR) && ar -x $(L_MORPHUX) && ar -x $(L_CURL) && ar -x $(L_JSON) && ar -x $(L_CONF) && ar -x $(L_SODIUM) @echo "CCLD\t\t$(NAME)" @$(LIB) $(ARFLAGS) $(NAME) objs/*.o @rm -rf $(OBJ_DIR) @@ -78,6 +81,7 @@ init: cd lib/curl/ && ./buildconf && ./configure --disable-shared --enable-debug --enable-maintainer-mode && make cd lib/json-c/ && sh autogen.sh && ./configure --disable-shared && make cd lib/libconfuse/ && sh autogen.sh && ./configure && make + cd lib/libsodium/ && sh autogen.sh && ./configure && make doc: doxygen docs/doxyfile diff --git a/inc/packer.h b/inc/packer.h @@ -25,6 +25,7 @@ # include <sys/types.h> # include <dirent.h> # include <limits.h> +# include <sodium.h> # define PACKER_DEF_CONF_FN "package.json" # define PACKER_DEF_EXT ".mpx" @@ -88,10 +89,10 @@ typedef struct packer_s { } packer_t; typedef struct packer_file_s { - char *fn; /*!< Filename, with relative path (Ex: srcs/main.c ) */ - off_t file_size; /*!< File size, in bytes */ - char sum[65]; /*!< Sha256sum of the file */ - char *content; /*!< Actual content of the file */ + char *fn; /*!< Filename, with relative path (Ex: srcs/main.c ) */ + off_t file_size; /*!< File size, in bytes */ + char sum[crypto_hash_sha256_BYTES]; /*!< Sha256sum of the file */ + char *content; /*!< Actual content of the file */ } packer_file_t; /*! diff --git a/lib/libsodium b/lib/libsodium @@ -0,0 +1 @@ +Subproject commit dfc226fed6d5634fe802f0357c5d1994286b0538 diff --git a/src/lib_init.c b/src/lib_init.c @@ -0,0 +1,5 @@ +#include <libmpm.h> + +static void __attribute__((constructor)) mpm_init(void) { + sodium_init(); +} diff --git a/src/packer.c b/src/packer.c @@ -486,6 +486,8 @@ static packer_file_t *packer_file_init(const char *file, const char *dir) { if (strcat(ret->fn, file) == NULL) goto error; + ret->sum[0] = 0; + return ret; error: @@ -528,6 +530,9 @@ static bool read_files_from_dir(const char *dir_name, mlist_t **files, mlist_t * { file->file_size = mpm_get_file_size_from_fn(file->fn); file->content = mpm_read_file_from_fn(file->fn); + crypto_hash_sha256((unsigned char *)file->sum, + (const unsigned char *)file->content, + file->file_size); list_add((*files), file, sizeof(*file)); } free(file); @@ -567,7 +572,7 @@ static bool write_package_sources(FILE *fd, packer_t *ctx) { packer_file_t *file; list_for_each(files_list, tmp, file) { - printf("File: %s:\n'%s'\n", file->fn, file->content); + printf("File: %s %s:\n'%s'\n", file->fn, file->sum, file->content); } list_free(files_list, packer_file_free); diff --git a/tests/Makefile b/tests/Makefile @@ -7,7 +7,8 @@ IFLAGS = -I ../inc/ \ -I ../lib/curl/lib/ \ -I ../lib/json-c/ \ -I ../lib/sqlite \ - -I ../lib/libconfuse/src/ + -I ../lib/libconfuse/src/ \ + -I ../lib/libsodium/src/libsodium/include/ # Optimisation Flags OFLAGS = -std=gnu99 -g -O3