resilar / sqleet

SQLite3 encryption that sucks less
The Unlicense
375 stars 55 forks source link

Any way to compile on MacOS? #40

Closed PrimeDominus closed 3 years ago

PrimeDominus commented 3 years ago
$gcc sqleet.c shell.c -o sqleet -lpthread -ldl
sqleet.c:229304:9: warning: 'syscall' is deprecated: first deprecated in macOS
      10.12 - syscall(2) is unsupported; please switch to a supported interface.
      For SYS_kdebug_trace use kdebug_signpost(). [-Wdeprecated-declarations]
    if (syscall(SYS_getentropy, buf, n) == 0)
        ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/unistd.h:742:6: note: 
      'syscall' has been explicitly marked deprecated here
int      syscall(int, ...);
         ^
1 warning generated.
utelle commented 3 years ago

The problem can be resolved by replacing line 526 of crypto.c, which is

    #if defined(__linux__) && defined(SYS_getrandom)

by

#if defined(__APPLE__) && defined(__MAC_10_12) && __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_12
  if (getentropy(buf, n) == 0)
    return n;
#elif defined(__linux__) && defined(SYS_getrandom)
nabajyotimitra commented 3 years ago

gcc sqleet.c shell.c -o sqleet -lpthread -ldl In file included from sqleet.c:9: ./crypto.c:528:9: warning: implicit declaration of function 'getentropy' is invalid in C99 [-Wimplicit-function-declaration] if (getentropy(buf, n) == 0) ^ 1 warning generated.

utelle commented 3 years ago

Sorry, I forgot to mention that you need to include the header file defining function getentropy, for example after line 523 in crypto.c:

#if defined(__APPLE__) && defined(__MAC_10_12)
#include <sys/random.h>
#endif
PrimeDominus commented 3 years ago

Thanks for your help.

In addition to the steps @utelle has provided, we needed to ensure the right version of Python was used prior to running the gcc command. Otherwise the usage example on the Readme doesn't work when running: [sqleet]% ./sqleet 'file:hello.db?key=swordfish' 'SELECT * FROM hello'

For those interested, this is because https://bugs.python.org/issue28676

Unfortunately, we found that running gcc in a new terminal window reverts to using the system default Python version (which doesn't have the fix) instead of our updated brew installed version.

We followed the steps in https://opensource.com/article/19/5/python-3-default-mac to install the latest version of Python and set it as global, and then ran the gcc command.

However, we had to do all this within the same terminal session, otherwise a new session would again revert to using the unpatched system default Python version.