diff options
author | Adam Harrison <adamdharrison@gmail.com> | 2022-12-29 23:50:22 -0500 |
---|---|---|
committer | Adam Harrison <adamdharrison@gmail.com> | 2022-12-29 23:50:22 -0500 |
commit | f49d5014aba8dbc5e04c3ec60353c3b7958687ac (patch) | |
tree | 249d0a86b7439a66401b332186bc0dfd3e260035 | |
parent | e2bb76d7a96b4f3639413e6899c06007019c56f3 (diff) | |
download | lite-xl-plugin-manager-f49d5014aba8dbc5e04c3ec60353c3b7958687ac.tar.gz lite-xl-plugin-manager-f49d5014aba8dbc5e04c3ec60353c3b7958687ac.zip |
Began process of integrating keychain queries for mac into lpm.
-rwxr-xr-x | build.sh | 18 | ||||
-rw-r--r-- | src/lpm.c | 39 | ||||
-rw-r--r-- | src/lpm.lua | 2 |
3 files changed, 43 insertions, 16 deletions
@@ -8,9 +8,10 @@ SRCS="src/*.c" CFLAGS="$CFLAGS -Ilib/prefix/include" -LDFLAGS="$LDFLAGS -lm -static-libgcc -Llib/prefix/lib" +LDFLAGS="$LDFLAGS -lm -Llib/prefix/lib" [[ "$@" == "clean" ]] && rm -rf lib/libgit2/build lib/zlib/build lib/libzip/build lib/mbedtls-2.27.0/build lib/prefix lua $BIN *.exe src/lpm.luac src/lpm.lua.c && exit 0 +cmake --version >/dev/null && [[ "$?" != 0 ]] && echo "Please ensure that you have cmake installed." && exit -1 # Build supporting libraries, libz, libmbedtls, libmbedcrypto, libgit2, libzip, libmicrotar, liblua CMAKE_DEFAULT_FLAGS=" $CMAKE_DEFAULT_FLAGS -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=`pwd`/lib/prefix -DCMAKE_INSTALL_PREFIX=`pwd`/lib/prefix -DBUILD_SHARED_LIBS=OFF" @@ -18,19 +19,19 @@ mkdir -p lib/prefix/include lib/prefix/lib if [[ "$@" != *"-lz"* ]]; then [ ! -e "lib/zlib" ] && echo "Make sure you've cloned submodules. (git submodule update --init --depth=1)" && exit -1 [[ ! -e "lib/zlib/build" && $OSTYPE != 'msys'* ]] && cd lib/zlib && mkdir build && cd build && $CC -D_LARGEFILE64_SOURCE -I.. ../*.c -c && ar rc libz.a *.o && cp libz.a ../../prefix/lib && cp ../*.h ../../prefix/include && cd ../../../ - LDFLAGS="$LDFLAGS -l:libz.a" + LDFLAGS="$LDFLAGS -lz" fi if [[ "$@" != *"-lmbedtls"* && "$@" != *"-lmbedcrypto"* ]]; then - [ ! -e "lib/mbedtls-2.27.0/build" ] && cd lib/mbedtls-2.27.0 && mkdir build && cd build && CFLAGS="-DMBEDTLS_MD4_C=1" cmake .. $CMAKE_DEFAULT_FLAGS -G "Unix Makefiles" -DENABLE_TESTING=OFF -DENABLE_PROGRAMS=OFF $SSL_CONFIGURE && CFLAGS="-DMBEDTLS_MD4_C=1" $MAKE -j $JOBS && $MAKE install && cd ../../../ - LDFLAGS="$LDFLAGS -l:libmbedtls.a -l:libmbedx509.a -l:libmbedcrypto.a" + [ ! -e "lib/mbedtls-2.27.0/build" ] && cd lib/mbedtls-2.27.0 && mkdir build && cd build && CFLAGS="-DMBEDTLS_MD4_C=1 -w" cmake .. $CMAKE_DEFAULT_FLAGS -G "Unix Makefiles" -DENABLE_TESTING=OFF -DENABLE_PROGRAMS=OFF $SSL_CONFIGURE && CFLAGS="-DMBEDTLS_MD4_C=1 -w" $MAKE -j $JOBS && $MAKE install && cd ../../../ + LDFLAGS="$LDFLAGS -lmbedtls -lmbedx509 -lmbedcrypto" fi if [[ "$@" != *"-lgit2"* ]]; then [ ! -e "lib/libgit2/build" ] && cd lib/libgit2 && mkdir build && cd build && cmake .. -G "Unix Makefiles" $GIT2_CONFIGURE $CMAKE_DEFAULT_FLAGS -DBUILD_TESTS=OFF -DBUILD_CLI=OFF -DREGEX_BACKEND=builtin -DUSE_SSH=OFF -DUSE_HTTPS=mbedTLS && $MAKE -j $JOBS && $MAKE install && cd ../../../ - LDFLAGS="-l:libgit2.a $LDFLAGS" + LDFLAGS="-lgit2 $LDFLAGS" fi if [[ "$@" != *"-lzip"* ]]; then [ ! -e "lib/libzip/build" ] && cd lib/libzip && mkdir build && cd build && cmake .. -G "Unix Makefiles" $CMAKE_DEFAULT_FLAGS -DBUILD_TOOLS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_DOC=OFF -DENABLE_COMMONCRYPTO=OFF -DENABLE_GNUTLS=OFF -DENABLE_OPENSSL=OFF -DENABLE_BZIP2=OFF -DENABLE_LZMA=OFF -DENABLE_ZSTD=OFF && $MAKE -j $JOBS && $MAKE install && cd ../../../ - LDFLAGS="$LDFLAGS -l:libzip.a" + LDFLAGS="$LDFLAGS -lzip" fi [[ "$@" != *"-lmicrotar"* ]] && CFLAGS="$CFLAGS -Ilib/microtar/src" && SRCS="$SRCS lib/microtar/src/microtar.c" [[ "$@" != *"-llua"* ]] && CFLAGS="$CFLAGS -Ilib/lua -DMAKE_LIB=1" && SRCS="$SRCS lib/lua/onelua.c" @@ -42,8 +43,9 @@ if [[ "$@" == *"-DLPM_STATIC"* ]]; then xxd -i src/lpm.luac > src/lpm.lua.c fi -[[ $OSTYPE != 'msys'* && $CC != *'mingw'* && $CC != "emcc" ]] && LDFLAGS=" $LDFLAGS -ldl" -[[ $OSTYPE == 'msys'* || $CC == *'mingw'* ]] && LDFLAGS="$LDFLAGS -lbcrypt -lws2_32 -lz -lwinhttp -lole32 -lcrypt32 -lrpcrt4" +[[ $OSTYPE != 'msys'* && $CC != *'mingw'* && $CC != "emcc" ]] && LDFLAGS="$LDFLAGS -ldl" +[[ $OSTYPE == 'msys'* || $CC == *'mingw'* ]] && LDFLAGS="$LDFLAGS -lbcrypt -lws2_32 -lz -lwinhttp -lole32 -lcrypt32 -lrpcrt4" +[[ $OSTYPE == *'darwin'* ]] && LDFLAGS="$LDFLAGS -liconv -framework Security" [[ " $@" != *" -g"* && " $@" != *" -O"* ]] && CFLAGS="$CFLAGS -O3" && LDFLAGS="$LDFLAGS -s" $CC $CFLAGS $SRCS $@ -o $BIN $LDFLAGS @@ -37,6 +37,10 @@ #include <microtar.h> #include <zip.h> +#ifdef __APPLE__ + #include <Security/Security.h> +#endif + static char hex_digits[] = "0123456789abcdef"; static int lpm_hash(lua_State* L) { size_t len; @@ -457,8 +461,24 @@ static int lpm_certs(lua_State* L) { } fclose(file); CertCloseStore(hSystemStore, 0); + #elseif __APPLE__ // https://developer.apple.com/forums/thread/691009 + CFStringRef keys[] = { kSecClass, kSecMatchLimit, kSecReturnRef }; + CFTypeRef values[] = { kSecClassCertificate, kSecMatchLimitAll, kCFBooleanTrue }; + CFDictionaryRef query = CFDictionaryCreate( + NULL, + (const void **) keys, + values, + sizeof(keys) / sizeof(keys[0]), + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks + ); + CFTypeRef copyResult = NULL; + OSStatus err = SecItemCopyMatching(query, ©Result); + if (err == errSecSuccess) { + CFShow(copyResult); + } #else - return luaL_error(L, "can't use system certificates on non-windows"); + return luaL_error(L, "can't use system certificates on windows or mac"); #endif } git_libgit2_opts(GIT_OPT_SET_SSL_CERT_LOCATIONS, path, NULL); @@ -827,12 +847,16 @@ static const luaL_Reg system_lib[] = { #endif -#ifndef LITE_ARCH_TUPLE +#ifndef ARCH_PROCESSOR #if __x86_64__ || _WIN64 || __MINGW64__ #define ARCH_PROCESSOR "x86_64" - #else + #elif __i386__ #define ARCH_PROCESSOR "x86" + #else + #error "Please define -DARCH_PROCESSOR." #endif +#endif +#ifndef ARCH_PLATFORM #if _WIN32 #define ARCH_PLATFORM "windows" #elif __linux__ @@ -840,8 +864,10 @@ static const luaL_Reg system_lib[] = { #elif __APPLE__ #define ARCH_PLATFORM "darwin" #else - #error "Please define -DLITE_ARCH_TUPLE." + #error "Please define -DARCH_PLATFORM." #endif +#endif +#ifndef LITE_ARCH_TUPLE #define LITE_ARCH_TUPLE ARCH_PROCESSOR "-" ARCH_PLATFORM #endif @@ -865,15 +891,14 @@ int main(int argc, char* argv[]) { lua_setglobal(L, "ARGV"); lua_pushliteral(L, LPM_VERSION); lua_setglobal(L, "VERSION"); + lua_pushliteral(L, ARCH_PLATFORM); + lua_setglobal(L, "PLATFORM"); #if _WIN32 - lua_pushliteral(L, "windows"); lua_pushliteral(L, "\\"); #else - lua_pushliteral(L, "posix"); lua_pushliteral(L, "/"); #endif lua_setglobal(L, "PATHSEP"); - lua_setglobal(L, "PLATFORM"); lua_pushliteral(L, LITE_ARCH_TUPLE); lua_setglobal(L, "ARCH"); #ifndef LPM_STATIC diff --git a/src/lpm.lua b/src/lpm.lua index a7f0401..f6bf3cf 100644 --- a/src/lpm.lua +++ b/src/lpm.lua @@ -1670,7 +1670,7 @@ in any circumstance unless explicitly supplied. "/etc/openssl/certs", -- NetBSD "/var/ssl/certs", -- AIX } - if PLATFORM == "windows" then + if PLATFORM == "windows" or PLATFORM == "darwin" then common.mkdirp(TMPDIR) system.certs("system", TMPDIR .. PATHSEP .. "certs.crt") else |