diff options
| author | Thomas Schmucker <ts@its1.de> | 2025-06-15 09:40:02 +0200 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2025-06-15 09:40:02 +0200 |
| commit | 97deedd97a1d026586afa23d47a00322bcd22e59 (patch) | |
| tree | 74adfa72390caeef30357ae17771afafe0dfca93 | |
| parent | 7bf6bc9385adff81f0f66962630bdd60572d5c57 (diff) | |
| download | use-bcrypt-97deedd97a1d026586afa23d47a00322bcd22e59.tar.gz use-bcrypt-97deedd97a1d026586afa23d47a00322bcd22e59.tar.bz2 use-bcrypt-97deedd97a1d026586afa23d47a00322bcd22e59.zip | |
Update auf neue lua-bcrypt version
| -rw-r--r-- | .clang-format | 45 | ||||
| -rw-r--r-- | .clang-tidy | 20 | ||||
| -rw-r--r-- | .gitignore | 5 | ||||
| -rw-r--r-- | bcrypt-test.c | 48 | ||||
| -rw-r--r-- | compile_flags.txt | 5 | ||||
| -rw-r--r-- | makefile | 19 |
6 files changed, 108 insertions, 34 deletions
diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..b32bad6 --- /dev/null +++ b/.clang-format | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | --- | ||
| 2 | AccessModifierOffset: -4 | ||
| 3 | AlignConsecutiveAssignments: 'true' | ||
| 4 | AlignConsecutiveDeclarations: 'true' | ||
| 5 | AlignEscapedNewlines: Left | ||
| 6 | AlignTrailingComments: 'true' | ||
| 7 | AlwaysBreakAfterReturnType: TopLevelDefinitions | ||
| 8 | BreakBeforeBraces: Stroustrup | ||
| 9 | BreakConstructorInitializers: BeforeComma | ||
| 10 | BreakInheritanceList: BeforeComma | ||
| 11 | ColumnLimit: '0' | ||
| 12 | CompactNamespaces: 'false' | ||
| 13 | Cpp11BracedListStyle: 'false' | ||
| 14 | FixNamespaceComments: 'true' | ||
| 15 | IncludeBlocks: Regroup | ||
| 16 | IncludeCategories: | ||
| 17 | - Regex: '^.*(precomp|pch|stdafx)' | ||
| 18 | Priority: -1 | ||
| 19 | - Regex: '^<.*>' | ||
| 20 | Priority: 1 | ||
| 21 | - Regex: '^".*"' | ||
| 22 | Priority: 2 | ||
| 23 | - Regex: '.*' | ||
| 24 | Priority: 3 | ||
| 25 | IndentCaseLabels: 'false' | ||
| 26 | IndentPPDirectives: AfterHash | ||
| 27 | IndentWidth: '4' | ||
| 28 | IndentWrappedFunctionNames: 'false' | ||
| 29 | KeepEmptyLinesAtTheStartOfBlocks: 'false' | ||
| 30 | PointerAlignment: Right | ||
| 31 | SortIncludes: 'true' | ||
| 32 | SpaceAfterCStyleCast: 'true' | ||
| 33 | SpaceAfterTemplateKeyword: 'false' | ||
| 34 | SpaceBeforeAssignmentOperators: 'true' | ||
| 35 | SpaceBeforeParens: ControlStatements | ||
| 36 | SpaceBeforeRangeBasedForLoopColon: 'false' | ||
| 37 | SpaceInEmptyParentheses: 'false' | ||
| 38 | SpacesInAngles: 'false' | ||
| 39 | SpacesInCStyleCastParentheses: 'false' | ||
| 40 | SpacesInConditionalStatement: 'true' | ||
| 41 | SpacesInParentheses: 'false' | ||
| 42 | Standard: Auto | ||
| 43 | TabWidth: '4' | ||
| 44 | UseTab: ForIndentation | ||
| 45 | ... | ||
diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..fe17118 --- /dev/null +++ b/.clang-tidy | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | --- | ||
| 2 | Checks: "*, | ||
| 3 | -abseil-*, | ||
| 4 | -altera-*, | ||
| 5 | -android-*, | ||
| 6 | -fuchsia-*, | ||
| 7 | -google-*, | ||
| 8 | -llvm*, | ||
| 9 | -modernize-use-trailing-return-type, | ||
| 10 | -zircon-*, | ||
| 11 | -readability-else-after-return, | ||
| 12 | -readability-static-accessed-through-instance, | ||
| 13 | -readability-avoid-const-params-in-decls, | ||
| 14 | -cppcoreguidelines-non-private-member-variables-in-classes, | ||
| 15 | -misc-non-private-member-variables-in-classes, | ||
| 16 | " | ||
| 17 | WarningsAsErrors: '' | ||
| 18 | HeaderFilterRegex: '' | ||
| 19 | FormatStyle: none | ||
| 20 | |||
| @@ -1,7 +1,4 @@ | |||
| 1 | lua-bcrypt | ||
| 2 | |||
| 3 | *.o | 1 | *.o |
| 2 | *.a | ||
| 4 | bcrypt-test | 3 | bcrypt-test |
| 5 | tags | ||
| 6 | .tags | ||
| 7 | user.db | 4 | user.db |
diff --git a/bcrypt-test.c b/bcrypt-test.c index 1df296d..19bd85e 100644 --- a/bcrypt-test.c +++ b/bcrypt-test.c | |||
| @@ -1,19 +1,20 @@ | |||
| 1 | #include <ctype.h> | ||
| 2 | #include <stdbool.h> | ||
| 1 | #include <stdio.h> | 3 | #include <stdio.h> |
| 2 | #include <stdlib.h> | 4 | #include <stdlib.h> |
| 3 | #include <stdbool.h> | ||
| 4 | #include <ctype.h> | ||
| 5 | #include <string.h> | 5 | #include <string.h> |
| 6 | 6 | ||
| 7 | #include "lua-bcrypt/compat/include/pwd.h" | 7 | #include "bcrypt.h" |
| 8 | 8 | ||
| 9 | #define USER_DATABASE "./user.db" | 9 | #define USER_DATABASE "./user.db" |
| 10 | #define SECURITY_LEVEL 12 | 10 | #define SECURITY_LEVEL 12 |
| 11 | #define SEP '|' | 11 | #define SEP '|' |
| 12 | #define MAX_LINE_LENGTH 256 | ||
| 12 | 13 | ||
| 13 | static bool | 14 | static bool |
| 14 | valid_char(int ch) | 15 | valid_char(int chr) |
| 15 | { | 16 | { |
| 16 | return isalnum(ch) || ch == '_' || ch == '-' || ch == '.'; | 17 | return isalnum(chr) || chr == '_' || chr == '-' || chr == '.'; |
| 17 | } | 18 | } |
| 18 | 19 | ||
| 19 | /** | 20 | /** |
| @@ -25,7 +26,7 @@ valid_char(int ch) | |||
| 25 | * \return true on success (user was created) or false on error | 26 | * \return true on success (user was created) or false on error |
| 26 | */ | 27 | */ |
| 27 | bool | 28 | bool |
| 28 | create_user(const char *username, const char *password) | 29 | create_user(const char *username, const char *password) // NOLINT |
| 29 | { | 30 | { |
| 30 | // check for invalid characters in username | 31 | // check for invalid characters in username |
| 31 | for ( const char *ptr = username; *ptr; ++ptr ) { | 32 | for ( const char *ptr = username; *ptr; ++ptr ) { |
| @@ -34,8 +35,8 @@ create_user(const char *username, const char *password) | |||
| 34 | } | 35 | } |
| 35 | } | 36 | } |
| 36 | 37 | ||
| 37 | FILE *db = fopen(USER_DATABASE, "a"); | 38 | FILE *database = fopen(USER_DATABASE, "a"); |
| 38 | if ( db == NULL ) { | 39 | if ( database == NULL ) { |
| 39 | return false; | 40 | return false; |
| 40 | } | 41 | } |
| 41 | 42 | ||
| @@ -45,8 +46,8 @@ create_user(const char *username, const char *password) | |||
| 45 | return false; | 46 | return false; |
| 46 | } | 47 | } |
| 47 | 48 | ||
| 48 | fprintf(db, "%s%c%s\n", username, SEP, hash); | 49 | (void) fprintf(database, "%s%c%s\n", username, SEP, hash); |
| 49 | fclose(db); | 50 | (void) fclose(database); |
| 50 | 51 | ||
| 51 | return true; | 52 | return true; |
| 52 | } | 53 | } |
| @@ -60,18 +61,18 @@ create_user(const char *username, const char *password) | |||
| 60 | * @return true, if the user was successfully authenticated, otherwise false | 61 | * @return true, if the user was successfully authenticated, otherwise false |
| 61 | */ | 62 | */ |
| 62 | bool | 63 | bool |
| 63 | check_user(const char *const username, const char *const password) | 64 | check_user(const char *const username, const char *const password) // NOLINT |
| 64 | { | 65 | { |
| 65 | FILE *db = fopen(USER_DATABASE, "r"); | 66 | FILE *database = fopen(USER_DATABASE, "r"); |
| 66 | if ( db == NULL ) { | 67 | if ( database == NULL ) { |
| 67 | return false; | 68 | return false; |
| 68 | } | 69 | } |
| 69 | 70 | ||
| 70 | const size_t username_length = strlen(username); | 71 | const size_t username_length = strlen(username); |
| 71 | char line[256]; | 72 | char line[MAX_LINE_LENGTH]; |
| 72 | 73 | ||
| 73 | bool found = false; | 74 | bool found = false; |
| 74 | while ( !found && fgets(line, sizeof line, db) ) { | 75 | while ( !found && fgets(line, sizeof line, database) ) { |
| 75 | line[strcspn(line, "\r\n")] = '\0'; // remove newline (if exists) | 76 | line[strcspn(line, "\r\n")] = '\0'; // remove newline (if exists) |
| 76 | 77 | ||
| 77 | if ( strncmp(line, username, username_length) != 0 ) { | 78 | if ( strncmp(line, username, username_length) != 0 ) { |
| @@ -82,7 +83,7 @@ check_user(const char *const username, const char *const password) | |||
| 82 | continue; | 83 | continue; |
| 83 | } | 84 | } |
| 84 | 85 | ||
| 85 | if ( bcrypt_checkpass(password, &line[username_length+1]) != 0 ) { | 86 | if ( bcrypt_checkpass(password, &line[username_length + 1]) != 0 ) { |
| 86 | continue; | 87 | continue; |
| 87 | } | 88 | } |
| 88 | 89 | ||
| @@ -90,7 +91,7 @@ check_user(const char *const username, const char *const password) | |||
| 90 | found = true; | 91 | found = true; |
| 91 | } | 92 | } |
| 92 | 93 | ||
| 93 | fclose(db); | 94 | (void) fclose(database); |
| 94 | 95 | ||
| 95 | return found; | 96 | return found; |
| 96 | } | 97 | } |
| @@ -105,16 +106,16 @@ check_user(const char *const username, const char *const password) | |||
| 105 | bool | 106 | bool |
| 106 | check_user_if_exists(const char *username) | 107 | check_user_if_exists(const char *username) |
| 107 | { | 108 | { |
| 108 | FILE *db = fopen(USER_DATABASE, "r"); | 109 | FILE *database = fopen(USER_DATABASE, "r"); |
| 109 | if ( db == NULL ) { | 110 | if ( database == NULL ) { |
| 110 | return false; | 111 | return false; |
| 111 | } | 112 | } |
| 112 | 113 | ||
| 113 | const size_t username_length = strlen(username); | 114 | const size_t username_length = strlen(username); |
| 114 | char line[256]; | 115 | char line[MAX_LINE_LENGTH]; |
| 115 | 116 | ||
| 116 | bool found = false; | 117 | bool found = false; |
| 117 | while ( !found && fgets(line, sizeof line, db) ) { | 118 | while ( !found && fgets(line, sizeof line, database) ) { |
| 118 | line[strcspn(line, "\r\n")] = '\0'; // remove newline (if exists) | 119 | line[strcspn(line, "\r\n")] = '\0'; // remove newline (if exists) |
| 119 | 120 | ||
| 120 | if ( strncmp(line, username, username_length) != 0 ) { | 121 | if ( strncmp(line, username, username_length) != 0 ) { |
| @@ -129,7 +130,7 @@ check_user_if_exists(const char *username) | |||
| 129 | found = true; | 130 | found = true; |
| 130 | } | 131 | } |
| 131 | 132 | ||
| 132 | fclose(db); | 133 | (void) fclose(database); |
| 133 | 134 | ||
| 134 | return found; | 135 | return found; |
| 135 | } | 136 | } |
| @@ -143,6 +144,3 @@ main(void) | |||
| 143 | 144 | ||
| 144 | return EXIT_SUCCESS; | 145 | return EXIT_SUCCESS; |
| 145 | } | 146 | } |
| 146 | |||
| 147 | |||
| 148 | |||
diff --git a/compile_flags.txt b/compile_flags.txt new file mode 100644 index 0000000..93961f5 --- /dev/null +++ b/compile_flags.txt | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | -Wall | ||
| 2 | -Werror | ||
| 3 | -Wno-pointer-sign | ||
| 4 | -std=c17 | ||
| 5 | -I../lua-bcrypt/src | ||
| @@ -1,13 +1,22 @@ | |||
| 1 | all: bcrypt-test | 1 | all: bcrypt-test |
| 2 | 2 | ||
| 3 | CFLAGS =-Wall -Werror -std=c99 -pedantic -g | 3 | # git clone https://github.com/mikejsavage/lua-bcrypt.git |
| 4 | LUA_BCRYPT_PATH=../lua-bcrypt/src | ||
| 4 | 5 | ||
| 5 | bcrypt-test: bcrypt-test.o | 6 | CFLAGS =-Wall -Werror -Wno-pointer-sign -std=c17 -O2 -I$(LUA_BCRYPT_PATH) |
| 6 | cc -o $@ bcrypt-test.o lua-bcrypt/bcrypt.a | ||
| 7 | 7 | ||
| 8 | bcrypt-test.o: bcrypt-test.c | 8 | bcrypt-test: bcrypt-test.o bcrypt-lib.a |
| 9 | cc -o $@ bcrypt-test.o bcrypt-lib.a | ||
| 10 | |||
| 11 | bcrypt-lib.a: bcrypt.o blowfish.o ggentropy.o safebfuns.o | ||
| 12 | ar -crs $@ $^ | ||
| 13 | |||
| 14 | %.o: %.c | ||
| 15 | cc $(CFLAGS) -o $@ -c $< | ||
| 16 | |||
| 17 | %.o: $(LUA_BCRYPT_PATH)/%.c | ||
| 9 | cc $(CFLAGS) -o $@ -c $< | 18 | cc $(CFLAGS) -o $@ -c $< |
| 10 | 19 | ||
| 11 | .PHONY: clean | 20 | .PHONY: clean |
| 12 | clean: | 21 | clean: |
| 13 | rm -f bcrypt-test bcrypt-test.o | 22 | rm -f bcrypt-test *.a *.o |
