diff --git a/Makefile b/Makefile index 700afa7..6136d8c 100644 --- a/Makefile +++ b/Makefile @@ -2,9 +2,9 @@ VERSION=1.1.9 CFLAGS+= -O2 -Wall -Wextra -Wshadow -rdynamic\ -D_FILE_OFFSET_BITS=64 -DVERSION=\"$(VERSION)\" \ - `pkg-config --cflags-only-I gumbo libcurl fuse` -LIBS = -pthread -lgumbo -lcurl -lfuse -lcrypto -COBJS = main.o network.o fuse_local.o link.o cache.o util.o + `pkg-config --cflags-only-I gumbo libcurl fuse uuid` +LIBS = -pthread -lgumbo -lcurl -lfuse -lcrypto -luuid +COBJS = network.o fuse_local.o link.o cache.o util.o sonic.o prefix ?= /usr/local diff --git a/src/link.c b/src/link.c index 1dd0f32..c7e4f6c 100644 --- a/src/link.c +++ b/src/link.c @@ -172,7 +172,7 @@ void Link_req_file_stat(Link *this_link) * * It gets freed in curl_multi_perform_once(); */ - TransferStruct *transfer = malloc(sizeof(TransferStruct)); + TransferStruct *transfer = calloc(1, sizeof(TransferStruct)); if (!transfer) { fprintf(stderr, "Link_get_size(): malloc failed!\n"); exit_failure(); diff --git a/src/sonic.c b/src/sonic.c new file mode 100644 index 0000000..91815a8 --- /dev/null +++ b/src/sonic.c @@ -0,0 +1,57 @@ +#include "util.h" + +#include +#include + +#include +#include + +#define MD5_HASH_LEN 32 +#define SALT_LEN 36 +/** + * \brief generate the salt for authentication string + * \details this effectively generates a UUID string, which we use as the salt + * \return a pointer to a 37-char array with the salt. + */ +char *generate_salt() +{ + char *out; + out = calloc(SALT_LEN + 1, sizeof(char)); + uuid_t uu; + uuid_generate(uu); + uuid_unparse(uu, out); + return out; +} + +/** + * \brief generate the md5sum of a string + * \param[in] str a character array for the input string + * \return a pointer to a 33-char array with the salt + */ +char *generate_md5sum(const char *str) +{ + MD5_CTX c; + unsigned char md5[MD5_DIGEST_LENGTH]; + size_t len = strnlen(str, MAX_PATH_LEN); + char *out = calloc(MD5_HASH_LEN + 1, sizeof(char)); + + MD5_Init(&c); + MD5_Update(&c, str, len); + MD5_Final(md5, &c); + + for(int i = 0; i < MD5_DIGEST_LENGTH; i++) { + sprintf(out + 2 * i, "%02x", md5[i]); + } + return out; +} + +int main(int argc, char **argv) +{ + (void) argc; + (void) argv; + + char *salt = generate_salt(); + char *md5sum = generate_md5sum(salt); + + printf("%s\n%s\n", salt, md5sum); +} diff --git a/src/sonic.h b/src/sonic.h new file mode 100644 index 0000000..546a530 --- /dev/null +++ b/src/sonic.h @@ -0,0 +1,4 @@ +#ifndef SONIC_H +#define SONIC_H + +#endif diff --git a/src/util.h b/src/util.h index 1798c14..eefcb95 100644 --- a/src/util.h +++ b/src/util.h @@ -15,7 +15,10 @@ */ #define MAX_PATH_LEN 4096 -/** \brief the maximum length of a filename. */ +/** + * \brief the maximum length of a filename. + * \details This corresponds the filename length under Ext4. + */ #define MAX_FILENAME_LEN 255 /**