diff --git a/Makefile b/Makefile index b7d3026..4c33ebc 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,9 @@ include config.mk +COLOR_GREEN=\033[0;32m +COLOR_BLUE=\033[0;34m +COLOR_RESET=\033[0m + all: @echo "Run 'make test' for the test binary, or 'make lib' to generate a static library." @echo "Run 'make help' for a full list of options." @@ -22,11 +26,15 @@ lib: $(AR) -rc build/lib/libglacier.a build/lib/libglacier.o install: + @echo "$(COLOR_BLUE)[i]$(COLOR_RESET) Installing static library to $(PREFIX)/lib..." install lib/libglacier.a $(PREFIX)/lib - install include/glacier_config.h $(PREFIX)/include - install include/glacier_log.h $(PREFIX)/include - install include/glacier_pkgops.h $(PREFIX)/include - install include/glacier_runtime.h $(PREFIX)/include + install include/config.h $(PREFIX)/include/glacier + install include/data.h $(PREFIX)/include/glacier + install include/log.h $(PREFIX)/include/glacier + install include/pkgops.h $(PREFIX)/include/glacier + install include/runtime.h $(PREFIX)/include/glacier + install include/security.h $(PREFIX)/include/glacier + @echo "$(COLOR_GREEN)[*]$(COLOR_RESET) Finished installing static library to $(PREFIX)/lib." clean: rm -rf build diff --git a/include/glacier_config.h b/include/config.h similarity index 88% rename from include/glacier_config.h rename to include/config.h index 59a25bb..bb38d23 100644 --- a/include/glacier_config.h +++ b/include/config.h @@ -1,17 +1,17 @@ /* - * glacier.h - Function declarations for libglacier + * config.h - Function declarations for libglacier * * This file is part of Glacier. * * Glacier is free software: you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation, either + * GNU Lesser General Public License as published by the Free Software Foundation, either * version 3 of the License, or (at your option) any later version. * * Glacier is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License along with Glacier. If + * You should have received a copy of the GNU Lesser General Public License along with Glacier. If * not, see . */ diff --git a/include/glacier_data.h b/include/data.h similarity index 91% rename from include/glacier_data.h rename to include/data.h index bec5c25..db87d87 100644 --- a/include/glacier_data.h +++ b/include/data.h @@ -1,17 +1,17 @@ /* - * glacier_log.h - Data structures for libglacier + * data.h - Data structures for libglacier * * This file is part of Glacier. * * Glacier is free software: you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation, either + * GNU Lesser General Public License as published by the Free Software Foundation, either * version 3 of the License, or (at your option) any later version. * * Glacier is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License along with Glacier. If + * You should have received a copy of the GNU Lesser General Public License along with Glacier. If * not, see . */ diff --git a/include/globals.h b/include/globals.h new file mode 100644 index 0000000..25df87a --- /dev/null +++ b/include/globals.h @@ -0,0 +1,33 @@ +/* + * globals.h - Global variables for libglacier + * + * This file is part of Glacier. + * + * Glacier is free software: you can redistribute it and/or modify it under the terms of the + * GNU Lesser General Public License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * Glacier is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with Glacier. If + * not, see . + */ + +#ifndef GLOBALS_H_ +#define GLOBALS_H_ + +extern config_t cfg; +extern config_setting_t *setting; +extern const char str; + +extern const char *GLACIER_REPO; +extern const char *GLACIER_ARCH; +extern const char *GLACIER_TARGET; +extern const char *GLACIER_LOCALDB; +extern const char *GLACIER_SYSTEM_PROFILE; + +const char *runtime_files[]; + +#endif diff --git a/include/glacier_log.h b/include/log.h similarity index 89% rename from include/glacier_log.h rename to include/log.h index 3145ede..2e3e36e 100644 --- a/include/glacier_log.h +++ b/include/log.h @@ -1,17 +1,17 @@ /* - * glacier_log.h - Logging function declarations for libglacier + * log.h - Logging function declarations for libglacier * * This file is part of Glacier. * * Glacier is free software: you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation, either + * GNU Lesser General Public License as published by the Free Software Foundation, either * version 3 of the License, or (at your option) any later version. * * Glacier is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License along with Glacier. If + * You should have received a copy of the GNU Lesser General Public License along with Glacier. If * not, see . */ diff --git a/include/glacier_pkgops.h b/include/pkgops.h similarity index 83% rename from include/glacier_pkgops.h rename to include/pkgops.h index d28bdfd..6498b5c 100644 --- a/include/glacier_pkgops.h +++ b/include/pkgops.h @@ -1,17 +1,17 @@ /* - * glacier_pkgops.h - Package-related function declarations for libglacier + * pkgops.h - Package-related function declarations for libglacier * * This file is part of Glacier. * * Glacier is free software: you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation, either + * GNU Lesser General Public License as published by the Free Software Foundation, either * version 3 of the License, or (at your option) any later version. * * Glacier is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License along with Glacier. If + * You should have received a copy of the GNU Lesser General Public License along with Glacier. If * not, see . */ diff --git a/include/glacier_runtime.h b/include/runtime.h similarity index 83% rename from include/glacier_runtime.h rename to include/runtime.h index 716b820..7c91b54 100644 --- a/include/glacier_runtime.h +++ b/include/runtime.h @@ -1,17 +1,17 @@ /* - * glacier_runtime.h - Runtime function declarations for libglacier + * runtime.h - Runtime function declarations for libglacier * * This file is part of Glacier. * * Glacier is free software: you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation, either + * GNU Lesser General Public License as published by the Free Software Foundation, either * version 3 of the License, or (at your option) any later version. * * Glacier is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License along with Glacier. If + * You should have received a copy of the GNU Lesser General Public License along with Glacier. If * not, see . */ diff --git a/include/glacier_security.h b/include/security.h similarity index 74% rename from include/glacier_security.h rename to include/security.h index 27ce1c7..591d480 100644 --- a/include/glacier_security.h +++ b/include/security.h @@ -1,17 +1,17 @@ /* - * glacier_runtime.h - Runtime function declarations for libglacier + * security.h - Runtime function declarations for libglacier * * This file is part of Glacier. * * Glacier is free software: you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation, either + * GNU Lesser General Public License as published by the Free Software Foundation, either * version 3 of the License, or (at your option) any later version. * * Glacier is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License along with Glacier. If + * You should have received a copy of the GNU Lesser General Public License along with Glacier. If * not, see . */ diff --git a/libglacier.c b/libglacier.c index cee9748..1c18328 100644 --- a/libglacier.c +++ b/libglacier.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -30,6 +31,7 @@ #include #include "config.h" +#include "include/globals.h" #define BUFFER_SIZE 1024 #define MAX_CHILDREN 64 @@ -648,5 +650,30 @@ run_make_task(char TASK[]) int compare_file_hash(char ORIG_HASH[], char FILE[]) { + FILE *pkg; + pkg = fopen(FILE, "rb"); + if (pkg == NULL) { + return -1; + } + + unsigned char hash[SHA256_DIGEST_LENGTH]; + SHA256_CTX sha256; + + SHA256_Init(&sha256); + + const int hashBufferSize = 1024; + unsigned char hashBuffer[hashBufferSize]; + int bytesRead; + + while ((byesRead = fread(hashBuffer, 1, hashBufferSize, pkg)) != 0) { + SHA256_Update(&sha256, hashBuffer, bytesRead); + } + + SHA256_Final(hash, &sha256); + fclose(pkg); + + for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) { + printf("%02x", hash[i]); + } }