Dirk Zimmermann 6 months ago
parent
commit
5b5607aaad
69 changed files with 813 additions and 616 deletions
  1. +11
    -7
      Makefile.conf
  2. +16
    -3
      build-windows/generate_code.cmd
  3. +1
    -1
      build-windows/libpEpasn1/libpEpasn1.vcxproj
  4. +16
    -2
      build-windows/pEpEngine.vcxproj
  5. +33
    -0
      build-windows/pEpEngine.vcxproj.filters
  6. +4
    -3
      codegen/gen_statemachine.ysl2
  7. +8
    -16
      src/Makefile
  8. +10
    -0
      src/baseprotocol.c
  9. +4
    -3
      src/engine_sql.c
  10. +103
    -97
      src/engine_sql.h
  11. +3
    -3
      src/etpan_mime.c
  12. +3
    -2
      src/keymanagement.c
  13. +2
    -1
      src/map_asn1.c
  14. +2
    -2
      src/map_asn1.h
  15. +4
    -0
      src/message.c
  16. +1
    -0
      src/message.h
  17. +120
    -104
      src/message_api.c
  18. +54
    -39
      src/message_api.h
  19. +12
    -5
      src/message_codec.c
  20. +13
    -0
      src/message_codec.h
  21. +34
    -0
      src/pEpEngine.h
  22. +1
    -1
      src/pEp_internal.h
  23. +15
    -2
      src/pgp_sequoia.c
  24. +14
    -3
      src/platform.h
  25. +18
    -0
      src/platform_disable_attributes.h
  26. +3
    -3
      src/platform_unix.c
  27. +5
    -5
      src/platform_unix.h
  28. +4
    -0
      src/platform_windows.h
  29. +15
    -0
      src/platform_zos.c
  30. +36
    -0
      src/platform_zos.h
  31. +0
    -8
      src/stdlib.h
  32. +0
    -10
      src/string.h
  33. +34
    -2
      src/sync_api.c
  34. +1
    -1
      src/timestamp.c
  35. +5
    -3
      test/Makefile
  36. +7
    -4
      test/src/AppleMailTest.cc
  37. +1
    -2
      test/src/AsciiBinaryAtt998Test.cc
  38. +1
    -1
      test/src/BareDecryptShellTest.cc
  39. +8
    -8
      test/src/CheckRenewedExpiredKeyTrustStatusTest.cc
  40. +4
    -5
      test/src/DecryptAttachPrivateKeyTrustedTest.cc
  41. +2
    -3
      test/src/DecryptAttachPrivateKeyUntrustedTest.cc
  42. +2
    -4
      test/src/ElevatedAttachmentsTest.cc
  43. +11
    -7
      test/src/EncryptForIdentityTest.cc
  44. +7
    -7
      test/src/Engine463Test.cc
  45. +1
    -2
      test/src/Engine514Test.cc
  46. +4
    -5
      test/src/Engine619Test.cc
  47. +1
    -2
      test/src/Engine655Test.cc
  48. +1
    -2
      test/src/Engine704Test.cc
  49. +4
    -3
      test/src/ExternalRevokeTest.cc
  50. +34
    -59
      test/src/GroupEncryptionTest.cc
  51. +3
    -3
      test/src/HeaderKeyImportTest.cc
  52. +18
    -36
      test/src/KeyAttachmentTest.cc
  53. +20
    -30
      test/src/KeyResetMessageTest.cc
  54. +2
    -2
      test/src/LeastColorGroupTest.cc
  55. +4
    -3
      test/src/LeastCommonDenomColorTest.cc
  56. +2
    -2
      test/src/MapAsn1Test.cc
  57. +2
    -4
      test/src/MessageNullFromTest.cc
  58. +2
    -2
      test/src/MessageTwoPointOhTest.cc
  59. +2
    -4
      test/src/NoOwnIdentWritesOnDecryptTest.cc
  60. +5
    -5
      test/src/OldMessageApiTest.cc
  61. +6
    -12
      test/src/PassphraseTest.cc
  62. +13
    -26
      test/src/PepSubjectReceivedTest.cc
  63. +6
    -4
      test/src/ReceiverRatingTest.cc
  64. +24
    -33
      test/src/ReencryptPlusExtraKeysTest.cc
  65. +1
    -2
      test/src/SenderFPRTest.cc
  66. +6
    -2
      test/src/TestUtilities.cc
  67. +1
    -2
      test/src/URIAddressTest.cc
  68. +1
    -2
      test/src/UnencryptedPepMailTest.cc
  69. +2
    -2
      test/src/VerifyTest.cc

+ 11
- 7
Makefile.conf View File

@ -87,6 +87,7 @@ endif
# Are we wiping this on purpose?
LDLIBS=
# Define compiler.
ifeq ($(BUILD_FOR),OS/390)
CC=xlclang
else ifeq ($(BUILD_FOR),Linux)
@ -95,10 +96,11 @@ else ifeq ($(BUILD_FOR),Darwin)
CC=clang
endif
# Add platform-specific compilation options.
ifeq ($(BUILD_FOR),OS/390)
CFLAGS= -Wno-gnu-include-next -qnosearch -I$(HERE) -I.
CFLAGS+= -I/usr/include
CFLAGS+= -DZOS -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=200112L -qlanglvl=NOLIBEXT
CFLAGS+= -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=200112L -qlanglvl=NOLIBEXT
else ifeq ($(BUILD_FOR),Linux)
CFLAGS+=-fPIC -fstrict-aliasing -fdiagnostics-color=auto
else ifeq ($(BUILD_FOR),Darwin)
@ -176,7 +178,7 @@ endif
ifeq ($(BUILD_FOR),OS/390)
CXXFLAGS+= -fdiagnostics-color=auto -Wno-gnu-include-next
CXXFLAGS+= -qnosearch -I$(HERE) -I. -I../src -I../asn.1 $(ETPAN_INC) -I/usr/lpp/java/J8.0_64/include -I/usr/include
CXXFLAGS+= -DZOS -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=200112L
CXXFLAGS+= -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=200112L
ifdef WARN
CXXFLAGS+=
else
@ -218,9 +220,9 @@ endif
######### C and C++ #########
ifeq ($(BUILD_FOR),OS/390)
CPPFLAGS=-W "l,xplink,dll" -W "c,float(ieee),xplink,dll,exportall"
CPPFLAGS+=-W "l,xplink,dll" -W "c,float(ieee),xplink,dll,exportall"
else ifeq ($(BUILD_FOR),Darwin)
CPPFLAGS=-D_DARWIN_C_SOURCE
CPPFLAGS+=-D_DARWIN_C_SOURCE
else
LDLIBS+=-luuid
endif
@ -295,12 +297,14 @@ SEQUOIA_INC=
# EXTRA_MACROS=-DDEFAULT_KEYSERVER=\"default-server.org\" -DCRASHDUMP_DEFAULT_LINES=23
EXTRA_MACROS=
# Notice the single quotes below: since user definitions can contain dollar
# signs it is important to prevent their expansion: shell variable references
# here must be expanded at run time, and not at compile time.
ifdef PER_USER_DIRECTORY
EXTRA_MACROS+= -DPER_USER_DIRECTORY=\"$(PER_USER_DIRECTORY)\"
EXTRA_MACROS+= -DPER_USER_DIRECTORY='"$(PER_USER_DIRECTORY)"'
endif
ifdef PER_MACHINE_DIRECTORY
EXTRA_MACROS+= -DPER_MACHINE_DIRECTORY=\"$(PER_MACHINE_DIRECTORY)\"
EXTRA_MACROS+= -DPER_MACHINE_DIRECTORY='"$(PER_MACHINE_DIRECTORY)"'
endif
CFLAGS+=$(EXTRA_MACROS)


+ 16
- 3
build-windows/generate_code.cmd View File

@ -8,6 +8,7 @@ SET engine_directory=%current_directory:~0,-14%
:: YML2 directory is ...\pEpForWindowsAdapterSolution\yml2\
SET yml2_directory=%engine_directory:~0,-11%\yml2
SET YML2PROC="%yml2_directory%\yml2proc"
:: Create the system.db
PUSHD %engine_directory%\db
@ -24,7 +25,8 @@ PY -m pip install --upgrade pip
PY -m pip install wheel
PY -m pip install yml2
SET YML2PROC="%yml2_directory%\yml2proc"
:: Generate code in ...\pEpEngine\codegen
CD ..\..\pEpEngine\codegen
:: Generate the Sync code
IF NOT EXIST generated MKDIR generated
@ -66,10 +68,20 @@ CD %engine_directory%\asn.1
DEL *.h
DEL *.c
..\..\Tools\asn1c\bin\asn1c -S ../../Tools/asn1c/share/asn1c -gen-PER -fincludes-quoted -fcompound-names -pdu=auto pEp.asn1 keysync.asn1 sync.asn1 trustsync.asn1 groupsync.asn1 managedgroup.asn1 keyreset.asn1 distribution.asn1 exploration.asn1
..\..\Tools\asn1c\bin\asn1c -S ../../Tools/asn1c/share/asn1c -gen-PER -fincludes-quoted -fcompound-names -pdu=auto pEp.asn1 sync.asn1 keysync.asn1 trustsync.asn1 groupsync.asn1 distribution.asn1 keyreset.asn1 managedgroup.asn1 exploration.asn1
type nul >> "Sync.c"
IF %ERRORLEVEL% NEQ 0 GOTO end
..\..\Tools\asn1c\bin\asn1c -S ../../Tools/asn1c/share/asn1c -gen-PER -fincludes-quoted -fcompound-names -pdu=auto pEp.asn1 sync.asn1 keysync.asn1 trustsync.asn1 groupsync.asn1
type nul >> "Distribution.c"
IF %ERRORLEVEL% NEQ 0 GOTO end
..\..\Tools\asn1c\bin\asn1c -S ../../Tools/asn1c/share/asn1c -gen-PER -fincludes-quoted -fcompound-names -pdu=auto pEp.asn1 storage.asn1 messagestorage.asn1
type nul >> "Storage.c"
IF %ERRORLEVEL% NEQ 0 GOTO end
..\..\Tools\asn1c\bin\asn1c -S ../../Tools/asn1c/share/asn1c -gen-PER -fincludes-quoted -fcompound-names -pdu=auto pEp.asn1 keyreset.asn1 distribution.asn1 managedgroup.asn1 exploration.asn1
..\..\Tools\asn1c\bin\asn1c -S ../../Tools/asn1c/share/asn1c -gen-PER -fincludes-quoted -fcompound-names -pdu=auto pEp.asn1 message.asn1
type nul >> "ASN1Message.c"
IF %ERRORLEVEL% NEQ 0 GOTO end
DEL *-sample.c
@ -77,6 +89,7 @@ DEL *-sample.c
CD %engine_directory%\..
MKDIR pEp
XCOPY pEpEngine\src\*.h pEp\ /Y/F/I
XCOPY libpEpAdapter\src\*.h pEp\ /Y/F/I
XCOPY libpEpAdapter\src\*.hh pEp\ /Y/F/I
XCOPY libpEpAdapter\src\*.hxx pEp\ /Y/F/I


+ 1
- 1
build-windows/libpEpasn1/libpEpasn1.vcxproj View File

@ -55,7 +55,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(ProjectDir)..\..\asn.1</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)..\..\asn.1;$(SolutionDir)pEp</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>


+ 16
- 2
build-windows/pEpEngine.vcxproj View File

@ -72,7 +72,7 @@
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;PEPENGINE_EXPORTS;_CRT_SECURE_NO_WARNINGS;USE_SEQUOIA;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<EnablePREfast>false</EnablePREfast>
<AdditionalIncludeDirectories>$(SolutionDir)libetpan\build-windows\include;$(SolutionDir)Tools\asn1c\share\asn1c;$(SolutionDir)sequoia\openpgp-ffi\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)pEpEngine\asn.1;$(SolutionDir);$(SolutionDir)libetpan\build-windows\include;$(SolutionDir)Tools\asn1c\share\asn1c;$(SolutionDir)sequoia\openpgp-ffi\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<CompileAs>Default</CompileAs>
<DisableSpecificWarnings>4703</DisableSpecificWarnings>
</ClCompile>
@ -103,7 +103,7 @@
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;PEPENGINE_EXPORTS;USE_SEQUOIA;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>false</SDLCheck>
<TreatWarningAsError>false</TreatWarningAsError>
<AdditionalIncludeDirectories>$(SolutionDir)libetpan\build-windows\include;$(SolutionDir)Tools\asn1c\share\asn1c;$(SolutionDir)sequoia\openpgp-ffi\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir);$(SolutionDir)libetpan\build-windows\include;$(SolutionDir)Tools\asn1c\share\asn1c;$(SolutionDir)sequoia\openpgp-ffi\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<CompileAs>Default</CompileAs>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<ControlFlowGuard>Guard</ControlFlowGuard>
@ -148,6 +148,7 @@
<ClCompile Include="..\src\map_asn1.c" />
<ClCompile Include="..\src\message.c" />
<ClCompile Include="..\src\message_api.c" />
<ClCompile Include="..\src\message_codec.c" />
<ClCompile Include="..\src\mime.c" />
<ClCompile Include="..\src\openpgp_compat.c" />
<ClCompile Include="..\src\pEpEngine.c" />
@ -175,27 +176,36 @@
<ClInclude Include="..\src\base64.h" />
<ClInclude Include="..\src\baseprotocol.h" />
<ClInclude Include="..\src\bloblist.h" />
<ClInclude Include="..\src\commit_hash.h" />
<ClInclude Include="..\src\cryptotech.h" />
<ClInclude Include="..\src\distribution_codec.h" />
<ClInclude Include="..\src\dynamic_api.h" />
<ClInclude Include="..\src\email.h" />
<ClInclude Include="..\src\engine_sql.h" />
<ClInclude Include="..\src\etpan_mime.h" />
<ClInclude Include="..\src\fsm_common.h" />
<ClInclude Include="..\src\group.h" />
<ClInclude Include="..\src\GroupSync_fsm.h" />
<ClInclude Include="..\src\group_internal.h" />
<ClInclude Include="..\src\growing_buf.h" />
<ClInclude Include="..\src\identity_list.h" />
<ClInclude Include="..\src\internal_format.h" />
<ClInclude Include="..\src\keymanagement.h" />
<ClInclude Include="..\src\keymanagement_internal.h" />
<ClInclude Include="..\src\keyreset_command.h" />
<ClInclude Include="..\src\KeySync_fsm.h" />
<ClInclude Include="..\src\key_reset.h" />
<ClInclude Include="..\src\key_reset_internal.h" />
<ClInclude Include="..\src\labeled_int_list.h" />
<ClInclude Include="..\src\map_asn1.h" />
<ClInclude Include="..\src\message.h" />
<ClInclude Include="..\src\message_api.h" />
<ClInclude Include="..\src\message_api_internal.h" />
<ClInclude Include="..\src\message_codec.h" />
<ClInclude Include="..\src\mime.h" />
<ClInclude Include="..\src\openpgp_compat.h" />
<ClInclude Include="..\src\pEpEngine.h" />
<ClInclude Include="..\src\pEpEngine_internal.h" />
<ClInclude Include="..\src\pEp_internal.h" />
<ClInclude Include="..\src\pEp_string.h" />
<ClInclude Include="..\src\pgp_sequoia.h" />
@ -217,6 +227,7 @@
<ClInclude Include="..\src\timestamp.h" />
<ClInclude Include="..\src\transport.h" />
<ClInclude Include="..\src\trans_auto.h" />
<ClInclude Include="..\src\TrustSync_fsm.h" />
<ClInclude Include="..\src\wrappers.h" />
</ItemGroup>
<ItemGroup>
@ -226,6 +237,9 @@
<ProjectReference Include="..\..\libetpan\build-windows\libetpan\libetpan.vcxproj">
<Project>{ba4ded3c-e56f-4484-bfc3-9c13e461a1be}</Project>
</ProjectReference>
<ProjectReference Include="..\..\libpEpTransport\build-windows\libpEpTransport.vcxproj">
<Project>{13f8fc08-53f8-4615-8445-3d713c0374e4}</Project>
</ProjectReference>
<ProjectReference Include="libpEpasn1\libpEpasn1.vcxproj">
<Project>{9a67164d-b8f8-4601-a24b-28afe774d41c}</Project>
</ProjectReference>


+ 33
- 0
build-windows/pEpEngine.vcxproj.filters View File

@ -141,6 +141,9 @@
<ClCompile Include="..\src\GroupSync_fsm.c">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="..\src\message_codec.c">
<Filter>Quelldateien</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\keymanagement.h">
@ -296,6 +299,36 @@
<ClInclude Include="..\src\group.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="..\src\commit_hash.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="..\src\engine_sql.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="..\src\group_internal.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="..\src\GroupSync_fsm.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="..\src\key_reset_internal.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="..\src\keymanagement_internal.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="..\src\message_api_internal.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="..\src\message_codec.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="..\src\pEpEngine_internal.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="..\src\TrustSync_fsm.h">
<Filter>Headerdateien</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Text Include="..\LICENSE.txt" />


+ 4
- 3
codegen/gen_statemachine.ysl2 View File

@ -533,8 +533,8 @@ tstylesheet {
{
PEP_STATUS status = PEP_STATUS_OK;
assert(session && fsm > None && message_type > None);
if (!(session && fsm > None && message_type > None))
assert(session && (int) fsm > None && message_type > None);
if (!(session && (int) fsm > None && message_type > None))
return PEP_ILLEGAL_VALUE;
time_t now = time(NULL);
@ -1653,6 +1653,7 @@ tstylesheet {
* @retval PEP_ILLEGAL_VALUE if input error during logging
* @retval PEP_STATUS_OK otherwise
*/
__attribute__((__unused__))
static PEP_STATUS _«@name»_ERR_LOG_int(PEP_SESSION session, char *t, int n, bool hex)
{
char *_buf = _str(n, hex);
@ -1677,7 +1678,7 @@ tstylesheet {
if (!session)
return invalid_state;
if (state == None)
if ((int) state == None)
state = «@name»_state_Init;
switch (state) {


+ 8
- 16
src/Makefile View File

@ -5,17 +5,6 @@
include ../Makefile.conf
# Notice the single quotes below: since user definitions can contain dollar
# signs it is important to prevent their expansion: shell variable references
# here must be expanded at run time, and not at compile time.
ifdef PER_USER_DIRECTORY
EXTRA_MACROS+= -DPER_USER_DIRECTORY='"$(PER_USER_DIRECTORY)"'
endif
ifdef PER_MACHINE_DIRECTORY
EXTRA_MACROS+= -DPER_MACHINE_DIRECTORY='"$(PER_MACHINE_DIRECTORY)"'
endif
ifneq ($(BUILD_ON),OS/390)
LDFLAGS+= -shared
endif
@ -103,9 +92,11 @@ all: $(TARGET)
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
# If only the goal 'clean' is given, do not generate and include the '%.d' files.
# Do not generate and include the '%.d' files if cleaning or uninstalling.
ifneq ($(MAKECMDGOALS),clean)
-include $(DEPENDS)
ifneq ($(MAKECMDGOALS),uninstall)
-include $(DEPENDS)
endif
endif
$(TARGET): libpEpEngine.a
@ -128,7 +119,8 @@ HEADERS_TO_INSTALL = \
timestamp.h identity_list.h bloblist.h stringpair.h message.h mime.h group.h \
cryptotech.h sync_api.h pEp_string.h openpgp_compat.h engine_sql.h \
labeled_int_list.h key_reset.h base64.h sync_codec.h distribution_codec.h \
storage_codec.h status_to_string.h keyreset_command.h platform.h platform_unix.h \
storage_codec.h status_to_string.h keyreset_command.h platform.h \
platform_unix.h platform_windows.h platform_zos.h \
transport.h growing_buf.h $(wildcard ../asn.1/*.h)
# CAVEAT:
@ -139,6 +131,7 @@ install_headers: $(TARGET)
cp $(HEADERS_TO_INSTALL) $(DESTDIR)$(PREFIX)/include/pEp/
# FIXME: Does anyone but Roker use install_headers? Otherwise, remove the dependency.
# I occasionally use it. --positron
install: $(TARGET) install_headers
mkdir -p "$(DESTDIR)$(PREFIX)/lib/"
cp -v $< $(DESTDIR)$(PREFIX)/lib/
@ -149,9 +142,8 @@ beinstall: install
uninstall:
rm -f $(DESTDIR)$(PREFIX)/lib/$(TARGET)
rm $(addprefix $(DESTDIR)$(PREFIX)/include/pEp/,$(notdir $(HEADERS_TO_INSTALL)))
rm -f $(addprefix $(DESTDIR)$(PREFIX)/include/pEp/,$(notdir $(HEADERS_TO_INSTALL)))
rmdir $(DESTDIR)$(PREFIX)/include/pEp 2> /dev/null || true
tags: $(wildcard *.c) $(wildcard *.h)
ctags --sort=yes *.c *.h

+ 10
- 0
src/baseprotocol.c View File

@ -260,6 +260,16 @@ PEP_STATUS try_base_prepare_message(
message **result
)
{
/* Special case: if messageToSend is not defined there is no way to handle
passphrases: in that case just exit with PEP_SYNC_NO_CHANNEL. This is
required for pEp4Thunderbird (P4TB-413) with the most recent
libpEpAdapter (master) and JSONServerAdapter (master) as of 2021-11-05:
JSONServerAdapter performs a temporary incomplete initialisation by
supplying some NULL callbacks, and initialises in a complete way only
later. */
if (session->messageToSend == NULL)
return PEP_SYNC_NO_CHANNEL;
PEP_STATUS status = PEP_STATUS_OK;
assert(session && session->messageToSend && session->notifyHandshake);


+ 4
- 3
src/engine_sql.c View File

@ -929,7 +929,7 @@ PEP_STATUS get_db_user_version(PEP_SESSION session, int* version) {
static PEP_STATUS _verify_version(PEP_SESSION session, int* version) {
// Sometimes the user_version wasn't set correctly.
bool version_changed = true;
int int_result;
int int_result __attribute__((__unused__));
if (table_contains_column(session, "identity", "username")) {
*version = 17;
}
@ -998,7 +998,8 @@ static PEP_STATUS _verify_version(PEP_SESSION session, int* version) {
static PEP_STATUS _upgrade_DB_to_ver_2(PEP_SESSION session) {
// N.B. addition of device_group column removed in DDL v10
int int_result = sqlite3_exec(
int int_result __attribute__((__unused__))
= sqlite3_exec(
session->db,
"alter table pgp_keypair\n"
" add column flags integer default 0;\n",
@ -1653,7 +1654,7 @@ static PEP_STATUS _check_and_execute_upgrades(PEP_SESSION session, int version)
}
PEP_STATUS pEp_sql_init(PEP_SESSION session) {
bool very_first = false;
bool very_first __attribute__((__unused__)) = false;
PEP_STATUS status = create_tables(session);
if (status != PEP_STATUS_OK)
return status;


+ 103
- 97
src/engine_sql.h View File

@ -10,21 +10,26 @@ PEP_STATUS pEp_sql_init(PEP_SESSION session);
PEP_STATUS pEp_prepare_sql_stmts(PEP_SESSION session);
PEP_STATUS pEp_finalize_sql_stmts(PEP_SESSION session);
/* The strings below are not always all used in a C file, so it is normal that
a lot of these variables are unused: we do not want warnings, nor complicated
attribute declrations for every variable. */
#define MAYBE_UNUSED __attribute__((__unused__))
/**
* Strings to feed into prepared statements
*/
static const char *sql_log =
static const char *sql_log MAYBE_UNUSED =
"insert into log (title, entity, description, comment)"
"values (?1, ?2, ?3, ?4);";
static const char *sql_trustword =
static const char *sql_trustword MAYBE_UNUSED =
"select id, word from wordlist where lang = lower(?1) "
"and id = ?2 ;";
// FIXME?: problems if we don't have a key for the user - we get nothing
// Also: we've never used pgp_keypair.flags before now, but it seems to me that
// having combination of those flags is a road to ruin. Changing this for now.
static const char *sql_get_identity =
static const char *sql_get_identity MAYBE_UNUSED =
"select identity.main_key_id,"
" (case when (identity.flags & 1024 = 0) then ifnull(identity.username, person.username) "
" else identity.username end),"
@ -45,7 +50,7 @@ static const char *sql_get_identity =
" order by is_own desc, "
" timestamp desc; ";
static const char *sql_get_identities_by_main_key_id =
static const char *sql_get_identities_by_main_key_id MAYBE_UNUSED =
"select address, identity.user_id,"
" (case when (identity.flags & 1024 = 0) then ifnull(identity.username, person.username) "
" else identity.username end),"
@ -61,7 +66,7 @@ static const char *sql_get_identities_by_main_key_id =
" order by is_own desc, "
" timestamp desc; ";
static const char *sql_get_identity_without_trust_check =
static const char *sql_get_identity_without_trust_check MAYBE_UNUSED =
"select identity.main_key_id,"
" (case when (identity.flags & 1024 = 0) then ifnull(identity.username, person.username) "
" else identity.username end),"
@ -77,7 +82,7 @@ static const char *sql_get_identity_without_trust_check =
" order by is_own desc, "
" timestamp desc; ";
static const char *sql_get_identities_by_address =
static const char *sql_get_identities_by_address MAYBE_UNUSED =
"select user_id, identity.main_key_id,"
" (case when (identity.flags & 1024 = 0) then ifnull(identity.username, person.username) "
" else identity.username end),"
@ -92,7 +97,7 @@ static const char *sql_get_identities_by_address =
" order by is_own desc, "
" timestamp desc; ";
static const char *sql_get_identities_by_userid =
static const char *sql_get_identities_by_userid MAYBE_UNUSED =
"select address, identity.main_key_id,"
" (case when (identity.flags & 1024 = 0) then ifnull(identity.username, person.username) "
" else identity.username end),"
@ -108,16 +113,16 @@ static const char *sql_get_identities_by_userid =
" order by is_own desc, "
" timestamp desc; ";
static const char *sql_replace_identities_fpr =
static const char *sql_replace_identities_fpr MAYBE_UNUSED =
"update identity"
" set main_key_id = ?1 "
" where main_key_id = ?2 ;";
static const char* sql_set_default_identity_fpr =
static const char* sql_set_default_identity_fpr MAYBE_UNUSED =
"update identity set main_key_id = ?3 "
" where user_id = ?1 and address = ?2; ";
static const char *sql_get_default_identity_fpr =
static const char *sql_get_default_identity_fpr MAYBE_UNUSED =
"select main_key_id from identity"
" where (case when (address = ?1) then (1)"
" when (lower(address) = lower(?1)) then (1)"
@ -126,19 +131,19 @@ static const char *sql_get_default_identity_fpr =
" end) = 1 "
" and user_id = ?2 ;";
static const char *sql_remove_fpr_as_identity_default =
static const char *sql_remove_fpr_as_identity_default MAYBE_UNUSED =
"update identity set main_key_id = NULL where main_key_id = ?1 ;";
static const char *sql_remove_fpr_as_user_default =
static const char *sql_remove_fpr_as_user_default MAYBE_UNUSED =
"update person set main_key_id = NULL where main_key_id = ?1 ;";
// Set person, but if already exist, only update.
// if main_key_id already set, don't touch.
static const char *sql_set_person =
static const char *sql_set_person MAYBE_UNUSED =
"insert into person (id, username, lang, main_key_id)"
" values (?1, ?2, ?3, ?4) ;";
static const char *sql_update_person =
static const char *sql_update_person MAYBE_UNUSED =
"update person "
" set username = ?2, "
" lang = ?3, "
@ -149,46 +154,46 @@ static const char *sql_update_person =
" where id = ?1 ;";
// Will cascade.
static const char *sql_delete_person =
static const char *sql_delete_person MAYBE_UNUSED =
"delete from person where id = ?1 ;";
static const char *sql_set_as_pEp_user =
static const char *sql_set_as_pEp_user MAYBE_UNUSED =
"update person set is_pEp_user = 1 "
" where id = ?1 ; ";
static const char *sql_is_pEp_user =
static const char *sql_is_pEp_user MAYBE_UNUSED =
"select is_pEp_user from person "
" where id = ?1 ; ";
static const char* sql_exists_person =
static const char* sql_exists_person MAYBE_UNUSED =
"select count(*) from person "
" where id = ?1 ;";
// This will cascade to identity and trust
static const char* sql_replace_userid =
static const char* sql_replace_userid MAYBE_UNUSED =
"update person set id = ?1 "
" where id = ?2;";
// Hopefully this cascades and removes trust entries...
static const char *sql_delete_key =
static const char *sql_delete_key MAYBE_UNUSED =
"delete from pgp_keypair "
" where fpr = ?1 ; ";
static const char *sql_replace_main_user_fpr =
static const char *sql_replace_main_user_fpr MAYBE_UNUSED =
"update person "
" set main_key_id = ?1 "
" where id = ?2 ;";
static const char *sql_get_main_user_fpr =
static const char *sql_get_main_user_fpr MAYBE_UNUSED =
"select main_key_id from person"
" where id = ?1 ;";
static const char *sql_replace_main_user_fpr_if_equal =
static const char *sql_replace_main_user_fpr_if_equal MAYBE_UNUSED =
"update person "
" set main_key_id = ?1 "
" where id = ?2 and main_key_id = ?3;";
static const char *sql_refresh_userid_default_key =
static const char *sql_refresh_userid_default_key MAYBE_UNUSED =
"update person "
" set main_key_id = "
" (select identity.main_key_id from identity "
@ -200,23 +205,23 @@ static const char *sql_refresh_userid_default_key =
" limit 1) "
"where id = ?1 ; ";
static const char *sql_set_pgp_keypair =
static const char *sql_set_pgp_keypair MAYBE_UNUSED =
"insert or ignore into pgp_keypair (fpr) "
"values (upper(replace(?1,' ',''))) ;";
static const char *sql_set_pgp_keypair_flags =
static const char *sql_set_pgp_keypair_flags MAYBE_UNUSED =
"update pgp_keypair set flags = "
" ((?1 & 65535) | (select flags from pgp_keypair "
" where fpr = (upper(replace(?2,' ',''))))) "
" where fpr = (upper(replace(?2,' ',''))) ;";
static const char *sql_unset_pgp_keypair_flags =
static const char *sql_unset_pgp_keypair_flags MAYBE_UNUSED =
"update pgp_keypair set flags = "
" ( ~(?1 & 65535) & (select flags from pgp_keypair"
" where fpr = (upper(replace(?2,' ',''))))) "
" where fpr = (upper(replace(?2,' ',''))) ;";
static const char* sql_exists_identity_entry =
static const char* sql_exists_identity_entry MAYBE_UNUSED =
"select count(*) from identity "
" where (case when (address = ?1) then (1)"
" when (lower(address) = lower(?1)) then (1)"
@ -225,7 +230,7 @@ static const char* sql_exists_identity_entry =
" end) = 1"
" and user_id = ?2;";
static const char *sql_set_identity_entry =
static const char *sql_set_identity_entry MAYBE_UNUSED =
"insert into identity ("
" address, main_key_id, "
" user_id, "
@ -243,7 +248,7 @@ static const char *sql_set_identity_entry =
" ?8 "
" );";
static const char* sql_update_identity_entry =
static const char* sql_update_identity_entry MAYBE_UNUSED =
"update identity "
" set main_key_id = upper(replace(?2,' ','')), "
" username = coalesce(username, ?4), "
@ -258,7 +263,7 @@ static const char* sql_update_identity_entry =
" end) = 1 "
" and user_id = ?3 ;";
static const char* sql_force_set_identity_username =
static const char* sql_force_set_identity_username MAYBE_UNUSED =
"update identity "
" set username = coalesce(username, ?3) "
" where (case when (address = ?1) then (1)"
@ -278,7 +283,7 @@ static const char* sql_force_set_identity_username =
// " ) | (?4 & 255)"
/* set_identity ignores previous flags, and doesn't filter machine flags */
static const char *sql_set_identity_flags =
static const char *sql_set_identity_flags MAYBE_UNUSED =
"update identity set flags = "
" ((?1 & 65535) | (select flags from identity"
" where (case when (address = ?2) then (1)"
@ -294,7 +299,7 @@ static const char *sql_set_identity_flags =
" end) = 1"
" and user_id = ?3 ;";
static const char *sql_unset_identity_flags =
static const char *sql_unset_identity_flags MAYBE_UNUSED =
"update identity set flags = "
" ( ~(?1 & 65535) & (select flags from identity"
" where (case when (address = ?2) then (1)"
@ -310,7 +315,7 @@ static const char *sql_unset_identity_flags =
" end) = 1"
" and user_id = ?3 ;";
static const char *sql_set_ident_enc_format =
static const char *sql_set_ident_enc_format MAYBE_UNUSED =
"update identity "
" set enc_format = ?1 "
" where (case when (address = ?2) then (1)"
@ -320,7 +325,7 @@ static const char *sql_set_ident_enc_format =
" end) = 1 "
" and user_id = ?3 ;";
static const char *sql_set_pEp_version =
static const char *sql_set_pEp_version MAYBE_UNUSED =
"update identity "
" set pEp_version_major = ?1, "
" pEp_version_minor = ?2 "
@ -331,7 +336,7 @@ static const char *sql_set_pEp_version =
" end) = 1 "
" and user_id = ?4 ;";
static const char *sql_upgrade_pEp_version_by_user_id =
static const char *sql_upgrade_pEp_version_by_user_id MAYBE_UNUSED =
"update identity "
" set pEp_version_major = ?1, "
" pEp_version_minor = ?2 "
@ -342,19 +347,19 @@ static const char *sql_upgrade_pEp_version_by_user_id =
" else 0 "
" end) = 1 ;";
static const char *sql_set_trust =
static const char *sql_set_trust MAYBE_UNUSED =
"insert into trust (user_id, pgp_keypair_fpr, comm_type) "
"values (?1, upper(replace(?2,' ','')), ?3) ;";
static const char *sql_update_trust =
static const char *sql_update_trust MAYBE_UNUSED =
"update trust set comm_type = ?3 "
" where user_id = ?1 and pgp_keypair_fpr = upper(replace(?2,' ',''));";
static const char *sql_clear_trust_info =
static const char *sql_clear_trust_info MAYBE_UNUSED =
"delete from trust "
" where user_id = ?1 and pgp_keypair_fpr = upper(replace(?2,' ',''));";
static const char *sql_update_trust_to_pEp =
static const char *sql_update_trust_to_pEp MAYBE_UNUSED =
"update trust set comm_type = comm_type + 71 "
" where (user_id = ?1 "
" and (case when (comm_type = 56) then (1) "
@ -362,54 +367,54 @@ static const char *sql_update_trust_to_pEp =
" else 0"
" end) = 1); ";
static const char* sql_exists_trust_entry =
static const char* sql_exists_trust_entry MAYBE_UNUSED =
"select count(*) from trust "
" where user_id = ?1 and pgp_keypair_fpr = upper(replace(?2,' ',''));";
static const char *sql_update_trust_for_fpr =
static const char *sql_update_trust_for_fpr MAYBE_UNUSED =
"update trust "
"set comm_type = ?1 "
"where pgp_keypair_fpr = upper(replace(?2,' ','')) ;";
static const char *sql_get_trust =
static const char *sql_get_trust MAYBE_UNUSED =
"select comm_type from trust where user_id = ?1 "
"and pgp_keypair_fpr = upper(replace(?2,' ','')) ;";
static const char *sql_get_trust_by_userid =
static const char *sql_get_trust_by_userid MAYBE_UNUSED =
"select pgp_keypair_fpr, comm_type from trust where user_id = ?1 ";
static const char *sql_least_trust =
static const char *sql_least_trust MAYBE_UNUSED =
"select min(comm_type) from trust where"
" pgp_keypair_fpr = upper(replace(?1,' ',''))"
" and comm_type != 0;"; // ignores PEP_ct_unknown
// returns PEP_ct_unknown only when no known trust is recorded
static const char *sql_update_key_sticky_bit_for_user =
static const char *sql_update_key_sticky_bit_for_user MAYBE_UNUSED =
"update trust set sticky = ?1 "
" where user_id = ?2 and pgp_keypair_fpr = upper(replace(?3,' ','')) ;";
static const char *sql_is_key_sticky_for_user =
static const char *sql_is_key_sticky_for_user MAYBE_UNUSED =
"select sticky from trust "
" where user_id = ?1 and pgp_keypair_fpr = upper(replace(?2,' ','')) ; ";
static const char *sql_mark_as_compromised =
static const char *sql_mark_as_compromised MAYBE_UNUSED =
"update trust not indexed set comm_type = 15"
" where pgp_keypair_fpr = upper(replace(?1,' ','')) ;";
static const char *sql_crashdump =
static const char *sql_crashdump MAYBE_UNUSED =
"select timestamp, title, entity, description, comment"
" from log order by timestamp desc limit ?1 ;";
static const char *sql_languagelist =
static const char *sql_languagelist MAYBE_UNUSED =
"select i18n_language.lang, name, phrase"
" from i18n_language join i18n_token using (lang) where i18n_token.id = 1000;" ;
static const char *sql_i18n_token =
static const char *sql_i18n_token MAYBE_UNUSED =
"select phrase from i18n_token where lang = lower(?1) and id = ?2 ;";
// Own keys
// We only care if it's 0 or non-zero
static const char *sql_own_key_is_listed =
static const char *sql_own_key_is_listed MAYBE_UNUSED =
"select count(*) from ("
" select pgp_keypair_fpr from trust"
" join identity on trust.user_id = identity.user_id"
@ -417,7 +422,7 @@ static const char *sql_own_key_is_listed =
" and identity.is_own = 1"
");";
static const char *sql_is_own_address =
static const char *sql_is_own_address MAYBE_UNUSED =
"select count(*) from ("
" select address from identity"
" where (case when (address = ?1) then (1)"
@ -428,7 +433,7 @@ static const char *sql_is_own_address =
" and identity.is_own = 1"
");";
static const char *sql_own_identities_retrieve =
static const char *sql_own_identities_retrieve MAYBE_UNUSED =
"select address, identity.main_key_id, identity.user_id,"
" (case when (identity.flags & 1024 = 0) then ifnull(identity.username, person.username) "
" else identity.username end),"
@ -443,174 +448,175 @@ static const char *sql_own_identities_retrieve =
" where identity.is_own = 1"
" and (identity.flags & ?1) = 0;";
static const char *sql_own_keys_retrieve =
static const char *sql_own_keys_retrieve MAYBE_UNUSED =
"select distinct pgp_keypair_fpr from trust"
" join identity on trust.user_id = identity.user_id"
" where identity.is_own = 1";
static const char* sql_get_user_default_key =
static const char* sql_get_user_default_key MAYBE_UNUSED =
"select main_key_id from person"
" where id = ?1;";
static const char* sql_get_all_keys_for_user =
static const char* sql_get_all_keys_for_user MAYBE_UNUSED =
"select pgp_keypair_fpr from trust"
" where user_id = ?1; ";
static const char* sql_get_default_own_userid =
static const char* sql_get_default_own_userid MAYBE_UNUSED =
"select id from person"
" join identity on id = identity.user_id"
" where identity.is_own = 1";
// Sequence
static const char *sql_sequence_value1 =
static const char *sql_sequence_value1 MAYBE_UNUSED =
"insert or replace into sequences (name, value) "
"values (?1, "
" (select coalesce((select value + 1 from sequences "
" where name = ?1), 1 ))); ";
static const char *sql_sequence_value2 =
static const char *sql_sequence_value2 MAYBE_UNUSED =
"select value from sequences where name = ?1 ;";
// Revocation tracking
static const char *sql_set_revoked =
static const char *sql_set_revoked MAYBE_UNUSED =
"insert or replace into revoked_keys ("
" revoked_fpr, replacement_fpr, revocation_date) "
"values (upper(replace(?1,' ','')),"
" upper(replace(?2,' ','')),"
" ?3) ;";
static const char *sql_get_revoked =
static const char *sql_get_revoked MAYBE_UNUSED =
"select revoked_fpr, revocation_date from revoked_keys"
" where replacement_fpr = upper(replace(?1,' ','')) ;";
static const char *sql_get_replacement_fpr =
static const char *sql_get_replacement_fpr MAYBE_UNUSED =
"select replacement_fpr, revocation_date from revoked_keys"
" where revoked_fpr = upper(replace(?1,' ','')) ;";
static const char *sql_get_userid_alias_default =
static const char *sql_get_userid_alias_default MAYBE_UNUSED =
"select default_id from alternate_user_id "
" where alternate_id = ?1 ; ";
// Revocation tracking
static const char *sql_add_mistrusted_key =
static const char *sql_add_mistrusted_key MAYBE_UNUSED =
"insert or replace into mistrusted_keys (fpr) "
" values (upper(replace(?1,' ',''))) ;";
static const char *sql_delete_mistrusted_key =
static const char *sql_delete_mistrusted_key MAYBE_UNUSED =
"delete from mistrusted_keys where fpr = upper(replace(?1,' ','')) ;";
static const char *sql_is_mistrusted_key =
static const char *sql_is_mistrusted_key MAYBE_UNUSED =
"select count(*) from mistrusted_keys where fpr = upper(replace(?1,' ','')) ;";
static const char *sql_add_userid_alias =
static const char *sql_add_userid_alias MAYBE_UNUSED =
"insert or replace into alternate_user_id (alternate_id, default_id) "
"values (?2, ?1) ;";
static const char *sql_add_into_social_graph =
static const char *sql_add_into_social_graph MAYBE_UNUSED =
"insert or replace into social_graph(own_userid, own_address, contact_userid) "
"values (?1, ?2, ?3) ;";
static const char *sql_get_own_address_binding_from_contact =
static const char *sql_get_own_address_binding_from_contact MAYBE_UNUSED =
"select own_address from social_graph where own_userid = ?1 and contact_userid = ?2 ;";
static const char *sql_set_revoke_contact_as_notified =
static const char *sql_set_revoke_contact_as_notified MAYBE_UNUSED =
"insert or replace into revocation_contact_list(fpr, own_address, contact_id) values (?1, ?2, ?3) ;";
static const char *sql_get_contacted_ids_from_revoke_fpr =
static const char *sql_get_contacted_ids_from_revoke_fpr MAYBE_UNUSED =
"select * from revocation_contact_list where fpr = ?1 ;";
static const char *sql_was_id_for_revoke_contacted =
static const char *sql_was_id_for_revoke_contacted MAYBE_UNUSED =
"select count(*) from revocation_contact_list where fpr = ?1 and own_address = ?2 and contact_id = ?3 ;";
static const char *sql_has_id_contacted_address =
static const char *sql_has_id_contacted_address MAYBE_UNUSED =
"select count(*) from social_graph where own_address = ?1 and contact_userid = ?2 ;";
// We only need user_id and address, since in the main usage, we'll call update_identity
// on this anyway when sending out messages.
static const char *sql_get_last_contacted =
static const char *sql_get_last_contacted MAYBE_UNUSED =
"select user_id, address from identity where datetime('now') < datetime(timestamp, '+14 days') ; ";
static const char *sql_create_group =
static const char *sql_create_group MAYBE_UNUSED =
"insert into groups (group_id, group_address, manager_userid, manager_address) "
"VALUES (?1, ?2, ?3, ?4) ;";
static const char *sql_enable_group =
static const char *sql_enable_group MAYBE_UNUSED =
"update groups set active = 1 "
" where group_id = ?1 and group_address = ?2 ;";
static const char *sql_disable_group =
static const char *sql_disable_group MAYBE_UNUSED =
"update groups set active = 0 "
" where group_id = ?1 and group_address = ?2 ;";
static const char *sql_exists_group_entry =
static const char *sql_exists_group_entry MAYBE_UNUSED =
"select count(*) from groups "
" where group_id = ?1 and group_address = ?2;";
static const char *sql_group_add_member =
static const char *sql_group_add_member MAYBE_UNUSED =
"insert or ignore into own_groups_members (group_id, group_address, member_id, member_address) "
" values (?1, ?2, ?3, ?4) ;";
static const char *sql_group_delete_member =
static const char *sql_group_delete_member MAYBE_UNUSED =
"delete from own_groups_members "
" where group_id = ?1 and group_address = ?2 and "
" member_id = ?3 and member_address = ?4 ;";
static const char *sql_set_group_member_status =
static const char *sql_set_group_member_status MAYBE_UNUSED =
"update own_groups_members set active_member = ?1 "
" where group_id = ?2 and group_address = ?3 and "
" member_id = ?4 and member_address = ?5; ";
static const char *sql_group_join =
static const char *sql_group_join MAYBE_UNUSED =
"update own_memberships set have_joined = 1 "
" where group_id = ?1 and group_address = ?2 and "
" own_id = ?3 and own_address = ?4; ";
static const char *sql_leave_group =
static const char *sql_leave_group MAYBE_UNUSED =
"update own_memberships set have_joined = 0 "
" where group_id = ?1 and group_address = ?2 and "
" own_id = ?3 and own_address = ?4; ";
static const char *sql_get_all_members =
static const char *sql_get_all_members MAYBE_UNUSED =
"select member_id, member_address, active_member from own_groups_members "
" where group_id = ?1 and group_address = ?2; ";
static const char *sql_get_active_members =
static const char *sql_get_active_members MAYBE_UNUSED =
"select member_id, member_address from own_groups_members "
" where group_id = ?1 and group_address = ?2 and active_member = 1; ";
static const char *sql_get_group_manager =
static const char *sql_get_group_manager MAYBE_UNUSED =
"select manager_userid, manager_address from groups "
" where group_id = ?1 and group_address = ?2; ";
static const char *sql_is_invited_group_member =
static const char *sql_is_invited_group_member MAYBE_UNUSED =
"select count(*) from own_groups_members "
" where group_id = ?1 and group_address = ?2 and member_id = ?3 and member_address = ?4; ";
static const char *sql_is_active_group_member =
static const char *sql_is_active_group_member MAYBE_UNUSED =
"select active_member from own_groups_members "
" where group_id = ?1 and group_address = ?2 and member_id = ?3 and member_address = ?4; ";
static const char *sql_get_all_groups =
static const char *sql_get_all_groups MAYBE_UNUSED =
"select group_id, group_address from own_memberships; ";
static const char *sql_get_active_groups =
static const char *sql_get_active_groups MAYBE_UNUSED =
"select group_id, group_address from own_memberships where have_joined = 1; ";
static const char *sql_add_own_membership_entry =
static const char *sql_add_own_membership_entry MAYBE_UNUSED =
"insert or replace into own_memberships (group_id, group_address, own_id, own_address, have_joined) "
" values (?1, ?2, ?3, ?4, 0) ; ";
static const char *sql_is_group_active =
static const char *sql_is_group_active MAYBE_UNUSED =
"select count(*) from groups "
" where group_id = ?1 and group_address = ?2 and active = 1; ";
// This below can return multiple entries for multiple idents in same group
// FIXME: decide what we really need here
static const char *sql_retrieve_own_membership_info_for_group =
static const char *sql_retrieve_own_membership_info_for_group MAYBE_UNUSED =
"select own_id, own_address, have_joined "
" from own_memberships "
" inner join groups using (group_id, group_address) "
" where group_id = ?1 and group_address = ?2; ";
static const char *sql_retrieve_own_membership_info_for_group_and_ident =
static const char *sql_retrieve_own_membership_info_for_group_and_ident
MAYBE_UNUSED =
"select have_joined, manager_userid, manager_address, active "
" from own_memberships "
" inner join groups using (group_id, group_address) "
" where group_id = ?1 and group_address = ?2 and own_id = ?3 and own_address = ?4; ";
// This will return all membership info for all identities
static const char *sql_retrieve_all_own_membership_info =
static const char *sql_retrieve_all_own_membership_info MAYBE_UNUSED =
"select group_id, group_address, own_id, own_address, have_joined, manager_id, manager_address, active "
" from own_memberships "
" inner join using (group_id, group_address); ";
static const char* sql_get_own_membership_status =
static const char* sql_get_own_membership_status MAYBE_UNUSED =
"select have_joined from own_memberships "
" where group_id = ?1 and group_address = ?2 and "
" own_id = ?3 and own_address = ?4; ";

+ 3
- 3
src/etpan_mime.c View File

@ -566,7 +566,7 @@ struct mailimf_date_time * timestamp_to_etpantime(const timestamp *ts)
result->dt_day = ts->tm_mday;
result->dt_month = ts->tm_mon + 1;
result->dt_year = ts->tm_year + 1900;
#ifndef ZOS
#ifndef __MVS__
result->dt_zone = (int) (ts->tm_gmtoff / 36L);
#endif
return result;
@ -587,14 +587,14 @@ timestamp * etpantime_to_timestamp(const struct mailimf_date_time *et)
result->tm_mday = et->dt_day;
result->tm_mon = et->dt_month - 1;
result->tm_year = et->dt_year - 1900;
#ifndef ZOS
#ifndef __MVS__
result->tm_gmtoff = 36L * (long) et->dt_zone;
#endif
// Normalize to UTC and then forget the offset.
time_t t = timegm_with_gmtoff(result);
gmtime_r(&t, result);
#ifndef ZOS
#ifndef __MVS__
result->tm_gmtoff = 0;
#endif
return result;


+ 3
- 2
src/keymanagement.c View File

@ -772,7 +772,8 @@ DYNAMIC_API PEP_STATUS update_identity(
// grab some information about the stored identity
bool candidate_has_real_id = strstr(candidate_id, "TOFU_") != candidate_id;
bool candidate_has_username = !EMPTYSTR(candidate->username);
bool candidate_name_is_addr = candidate_has_username ? strcmp(candidate->address, candidate->username) == 0 : false;
bool candidate_name_is_addr __attribute__((unused))
= candidate_has_username ? strcmp(candidate->address, candidate->username) == 0 : false;
// This is where the optimisation gets a little weird:
//
@ -1020,7 +1021,7 @@ PEP_STATUS _myself(PEP_SESSION session,
// this leads to crashes otherwise
if (!(identity->user_id && identity->user_id[0])) {
if (EMPTYSTR(identity->user_id)) {
free(identity->user_id);
identity->user_id = strdup(PEP_OWN_USERID);
assert(identity->user_id);


+ 2
- 1
src/map_asn1.c View File

@ -6,6 +6,7 @@
#include "pEp_internal.h"
#include "map_asn1.h"
#include "message_codec.h"
/* Expand to a statement checking that the given expression evaluates to a
non-NULL result, first using an assert and then an explicit check in C. If
@ -1073,7 +1074,7 @@ ASN1Message_t *ASN1Message_from_message(
enomem:
if (allocated)
ASN_STRUCT_FREE(asn_DEF_ASN1Message, result);
free_ASN1Message(result);
return NULL;
}


+ 2
- 2
src/map_asn1.h View File

@ -9,8 +9,8 @@
#include "message.h"
#include "ASN1Message.h"
#include "Identity.h" // ENGINE-971
#include "IdentityList.h" // ENGINE-971
#include "Identity.h"
#include "IdentityList.h"
#ifdef __cplusplus
extern "C" {


+ 4
- 0
src/message.c View File

@ -197,6 +197,8 @@ DYNAMIC_API message * message_dup(const message *src)
msg->enc_format = src->enc_format;
msg->rating = src->rating;
return msg;
enomem:
@ -209,11 +211,13 @@ DYNAMIC_API void message_transfer(message* dst, message *src)
assert(dst);
assert(src);
/* Scalars */
dst->dir = src->dir;
dst->rawmsg_ref = src->rawmsg_ref;
dst->rawmsg_size = src->rawmsg_size;
dst->refering_msg_ref = src->refering_msg_ref;
dst->enc_format = src->enc_format;
dst->rating = src->rating;
/* Strings */
free(dst->id);


+ 1
- 0
src/message.h View File

@ -87,6 +87,7 @@ typedef struct _message {
char* _sender_fpr; // INTERNAL USE ONLY - fingerprint of
// sending signer.
// (read_only to the outside)
PEP_rating rating; // message rating
} message;
/**


+ 120
- 104
src/message_api.c View File

@ -24,6 +24,8 @@
#include "group.h"
#include "group_internal.h"
#include "status_to_string.h"
#include <assert.h>
#include <string.h>
#include <stdlib.h>
@ -108,6 +110,8 @@ static char * keylist_to_string(const stringlist_t *keylist)
static const char * rating_to_string(PEP_rating rating)
{
switch (rating) {
case PEP_rating_undefined:
return "undefined";
case PEP_rating_cannot_decrypt:
return "cannot_decrypt";
case PEP_rating_have_no_key:
@ -131,7 +135,8 @@ static const char * rating_to_string(PEP_rating rating)
case PEP_rating_under_attack:
return "under_attack";
default:
return "undefined";
assert(0);
return "invalid rating (this should never happen)";
}
}
@ -404,6 +409,8 @@ void decorate_message(
replace_opt_field(msg, "X-KeyList", _keylist, clobber);
free(_keylist);
}
msg->rating = rating;
}
/**
@ -2170,7 +2177,7 @@ bool import_attached_keys(
int i = 0;
bloblist_t* prev = NULL;
bloblist_t* prev __attribute__ ((__unused__)) = NULL;
bool do_not_advance = false;
const char* pubkey_header = "-----BEGIN PGP PUBLIC KEY BLOCK-----";
@ -2682,6 +2689,9 @@ DYNAMIC_API PEP_STATUS encrypt_message(
if (src->dir == PEP_dir_incoming)
return PEP_ILLEGAL_VALUE;
// Reset the message rating before doing anything...
src->rating = PEP_rating_undefined;
determine_encryption_format(src);
// TODO: change this for multi-encryption in message format 2.0
if (src->enc_format != PEP_enc_none)
@ -2743,100 +2753,44 @@ DYNAMIC_API PEP_STATUS encrypt_message(
unsigned int max_version_minor = 0;
pEp_version_major_minor(PEP_VERSION, &max_version_major, &max_version_minor);
identity_list * _il = NULL;
identity_list * _il __attribute__((__unused__)) = NULL;
//
// Update the identities and gather key and version information
// for sending
//
if (enc_format != PEP_enc_none && (_il = src->bcc) && _il->ident)
// BCC limited support:
{
// - App splits mails with BCC in multiple mails.
// - Each email is encrypted separately
if(_il->next || (src->to && src->to->ident) || (src->cc && src->cc->ident))
{
// Only one Bcc with no other recipient allowed for now
return PEP_ILLEGAL_VALUE;
}
// If you think this call is a beast, try the cut-and-pasted code 3 x
PEP_STATUS _status = _update_state_for_ident_list(
session, src->from, _il,
&_k,
&max_comm_type,
&max_version_major,
&max_version_minor,
&has_pEp_user,
&dest_keys_found,
true);
switch (_status) {
case PEP_PASSPHRASE_REQUIRED:
case PEP_PASSPHRASE_FOR_NEW_KEYS_REQUIRED:
case PEP_WRONG_PASSPHRASE:
status = _status;
goto pEp_error;
case PEP_STATUS_OK:
break;
default:
status = PEP_UNENCRYPTED;
goto pEp_error;
}
}
else // Non BCC
{
// If you think this call is a beast, try the cut-and-pasted code 3 x
PEP_STATUS _status = PEP_STATUS_OK;
if (src->to) {
_status = _update_state_for_ident_list(
session, src->from, src->to,
&_k,
&max_comm_type,
&max_version_major,
&max_version_minor,
&has_pEp_user,
&dest_keys_found,
false
);
switch (_status) {
case PEP_PASSPHRASE_REQUIRED:
case PEP_PASSPHRASE_FOR_NEW_KEYS_REQUIRED:
case PEP_WRONG_PASSPHRASE:
goto pEp_error;
case PEP_STATUS_OK:
break;
default:
status = PEP_UNENCRYPTED;
goto pEp_error;
}
}
if (src->cc) {
_status = _update_state_for_ident_list(
session, src->from, src->cc,
&_k,
&max_comm_type,
&max_version_major,
&max_version_minor,
&has_pEp_user,
&dest_keys_found,
false
);
switch (_status) {
case PEP_PASSPHRASE_REQUIRED:
case PEP_PASSPHRASE_FOR_NEW_KEYS_REQUIRED:
case PEP_WRONG_PASSPHRASE:
goto pEp_error;
case PEP_STATUS_OK:
break;
default:
status = PEP_UNENCRYPTED;
goto pEp_error;
}
}
}
# define UPDATE_STATE_FOR_IDENT_LIST_AND_JUMP_ON_ERROR( \
ident_list_actual, \
suppress_update_for_bcc) \
do { \
identity_list *ident_list = (ident_list_actual); \
if (ident_list) { \
status = _update_state_for_ident_list( \
session, src->from, ident_list, \
&_k, \
&max_comm_type, \
&max_version_major, \
&max_version_minor, \
&has_pEp_user, \
&dest_keys_found, \
(suppress_update_for_bcc) \
); \
switch (status) { \
case PEP_PASSPHRASE_REQUIRED: \
case PEP_PASSPHRASE_FOR_NEW_KEYS_REQUIRED: \
case PEP_WRONG_PASSPHRASE: \
goto pEp_error; \
case PEP_STATUS_OK: \
break; \
default: \
status = PEP_UNENCRYPTED; \
goto pEp_error; \
} \
} \
} while (false)
UPDATE_STATE_FOR_IDENT_LIST_AND_JUMP_ON_ERROR (src->to, false);
UPDATE_STATE_FOR_IDENT_LIST_AND_JUMP_ON_ERROR (src->cc, false);
UPDATE_STATE_FOR_IDENT_LIST_AND_JUMP_ON_ERROR (src->bcc, true);
if (max_version_major < 2)
force_v_1 = true;
@ -2944,7 +2898,16 @@ DYNAMIC_API PEP_STATUS encrypt_message(
}
if (msg) {
decorate_message(session, msg, PEP_rating_undefined, NULL, true, true);
/* Obtain the message rating... */
PEP_rating rating;
status = sent_message_rating(session, msg, & rating);
if (status == PEP_OUT_OF_MEMORY)
goto enomem;
else if (status != PEP_STATUS_OK)
goto pEp_error;
/* ...And store it into the message along with the other decorations. */
decorate_message(session, msg, rating, NULL, true, true);
if (_src->id) {
msg->id = strdup(_src->id);
assert(msg->id);
@ -4475,6 +4438,7 @@ static PEP_STATUS reconcile_src_and_inner_messages(message* src,
*
* @retval bool
*/
__attribute__ ((__unused__))
static bool is_trusted_own_priv_fpr(PEP_SESSION session,
const char* own_id,
const char* fpr
@ -4511,6 +4475,7 @@ static bool is_trusted_own_priv_fpr(PEP_SESSION session,
*
* @retval bool
*/
__attribute__ ((__unused__))
static bool reject_fpr(PEP_SESSION session, const char* fpr) {
bool reject = true;
@ -4990,7 +4955,9 @@ static const char* process_key_claim(message* src,
// There are times when we don't want errors during calls to be fatal. Once any action is taken on that
// status, if we are going to continue processing and not bail from the message, the status needs to be reset
// to PEP_STATUS_OK, or, alternately, we need to be using a temp status variable.
//
// This internal function does *not* set the rating field of the message: that
// part of the job is within decrypt_message.
static PEP_STATUS _decrypt_message(
PEP_SESSION session,
message *src,
@ -6259,12 +6226,11 @@ pEp_error:
return status;
}
DYNAMIC_API PEP_STATUS decrypt_message(
DYNAMIC_API PEP_STATUS decrypt_message_2(
PEP_SESSION session,
message *src,
message **dst,
stringlist_t **keylist,
PEP_rating *rating,
PEP_decrypt_flags_t *flags
)
{
@ -6272,24 +6238,32 @@ DYNAMIC_API PEP_STATUS decrypt_message(
assert(src);
assert(dst);
assert(keylist);
assert(rating);
assert(flags);
if (!(session && src && dst && keylist && rating && flags))
if (!(session && src && dst && keylist && flags))
return PEP_ILLEGAL_VALUE;
if (!(*flags & PEP_decrypt_flag_untrusted_server))
*keylist = NULL;
// Reset the message rating before doing anything. We will compute a new
// value, that _decrypt_message sets as an output parameter.
src->rating = PEP_rating_undefined;
PEP_rating rating = PEP_rating_undefined;
stringlist_t* imported_key_fprs = NULL;
uint64_t changed_key_bitvec = 0;
PEP_STATUS status = _decrypt_message(session, src, dst, keylist,
rating, flags, NULL,
&rating, flags, NULL,
&imported_key_fprs, &changed_key_bitvec);
message *msg = *dst ? *dst : src;
/* Set the rating field of the message. Notice that even in case of non-ok
result status the value of this field may be meaningful. */
msg->rating = rating;
// Ok, now we check to see if it was an administrative message. We do this by testing base_extract for success
// with protocol families.
if (msg && msg->