diff --git a/lang/cpp/src/Makefile.am b/lang/cpp/src/Makefile.am index 1e6bdc28..1b1de327 100644 --- a/lang/cpp/src/Makefile.am +++ b/lang/cpp/src/Makefile.am @@ -1,109 +1,110 @@ # Makefile.am for GPGMEPP. # Copyright (C) 2016 Bundesamt für Sicherheit in der Informationstechnik # Software engineering by Intevation GmbH # # This file is part of GPGMEPP. # # GPGME-CL is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # GPGME-CL is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA EXTRA_DIST = GpgmeppConfig.cmake.in.in GpgmeppConfigVersion.cmake.in \ gpgmepp_version.h.in GpgmeppConfig-w32.cmake.in.in lib_LTLIBRARIES = libgpgmepp.la main_sources = \ exception.cpp context.cpp key.cpp trustitem.cpp data.cpp callbacks.cpp \ eventloopinteractor.cpp editinteractor.cpp \ keylistresult.cpp keygenerationresult.cpp importresult.cpp \ decryptionresult.cpp verificationresult.cpp \ signingresult.cpp encryptionresult.cpp \ engineinfo.cpp gpgsetexpirytimeeditinteractor.cpp \ gpgsetownertrusteditinteractor.cpp gpgsignkeyeditinteractor.cpp \ gpgadduserideditinteractor.cpp gpggencardkeyinteractor.cpp \ defaultassuantransaction.cpp \ scdgetinfoassuantransaction.cpp gpgagentgetinfoassuantransaction.cpp \ vfsmountresult.cpp configuration.cpp tofuinfo.cpp swdbresult.cpp gpgmepp_headers = \ configuration.h context.h data.h decryptionresult.h \ defaultassuantransaction.h editinteractor.h encryptionresult.h \ engineinfo.h error.h eventloopinteractor.h exception.h global.h \ gpgadduserideditinteractor.h gpgagentgetinfoassuantransaction.h \ gpgmefw.h gpgsetexpirytimeeditinteractor.h \ gpgsetownertrusteditinteractor.h gpgsignkeyeditinteractor.h \ gpggencardkeyinteractor.h \ importresult.h keygenerationresult.h key.h keylistresult.h \ notation.h result.h scdgetinfoassuantransaction.h signingresult.h \ trustitem.h verificationresult.h vfsmountresult.h gpgmepp_export.h \ tofuinfo.h swdbresult.h private_gpgmepp_headers = \ result_p.h context_p.h util.h callbacks.h data_p.h interface_headers= \ interfaces/assuantransaction.h interfaces/dataprovider.h \ interfaces/passphraseprovider.h interfaces/progressprovider.h gpgmeppincludedir = $(includedir)/gpgme++ gpgmeppinclude_HEADERS = $(gpgmepp_headers) nobase_gpgmeppinclude_HEADERS = $(interface_headers) nodist_gpgmeppinclude_HEADERS = gpgmepp_version.h libgpgmepp_la_SOURCES = $(main_sources) $(gpgmepp_headers) context_vanilla.cpp \ $(interface_headers) $(private_gpgmepp_headers) AM_CPPFLAGS = -I$(top_builddir)/src @GPG_ERROR_CFLAGS@ @LIBASSUAN_CFLAGS@ \ - -DBUILDING_GPGMEPP + -DBUILDING_GPGMEPP -Wsuggest-override \ + -Wzero-as-null-pointer-constant libgpgmepp_la_LIBADD = ../../../src/libgpgme.la @LIBASSUAN_LIBS@ libgpgmepp_la_LDFLAGS = -no-undefined -version-info \ @LIBGPGMEPP_LT_CURRENT@:@LIBGPGMEPP_LT_REVISION@:@LIBGPGMEPP_LT_AGE@ if HAVE_MACOS_SYSTEM libsuffix=.dylib else libsuffix=.so endif if HAVE_W32_SYSTEM GpgmeppConfig.cmake: GpgmeppConfig-w32.cmake.in sed -e 's|[@]resolved_bindir@|$(bindir)|g' < "$<" | \ sed -e 's|[@]resolved_libdir@|$(libdir)|g' | \ sed -e 's|[@]resolved_includedir@|$(includedir)|g' > $@ else GpgmeppConfig.cmake: GpgmeppConfig.cmake.in sed -e 's|[@]resolved_libdir@|$(libdir)|g' < "$<" | \ sed -e 's|[@]libsuffix@|$(libsuffix)|g' | \ sed -e 's|[@]resolved_includedir@|$(includedir)|g' > $@ endif install-cmake-files: GpgmeppConfig.cmake GpgmeppConfigVersion.cmake -$(INSTALL) -d $(DESTDIR)$(libdir)/cmake/Gpgmepp $(INSTALL) -m 644 GpgmeppConfig.cmake \ $(DESTDIR)$(libdir)/cmake/Gpgmepp/GpgmeppConfig.cmake $(INSTALL) -m 644 GpgmeppConfigVersion.cmake \ $(DESTDIR)$(libdir)/cmake/Gpgmepp/GpgmeppConfigVersion.cmake uninstall-cmake-files: -rm $(DESTDIR)$(libdir)/cmake/Gpgmepp/GpgmeppConfigVersion.cmake -rm $(DESTDIR)$(libdir)/cmake/Gpgmepp/GpgmeppConfig.cmake -rmdir $(DESTDIR)$(libdir)/cmake/Gpgmepp/ install-data-local: install-cmake-files uninstall-local: uninstall-cmake-files CLEANFILES = GpgmeppConfig.cmake GpgmeppConfigVersion.cmake \ gpgmepp_version.h GpgmeppConfig.cmake.in diff --git a/lang/cpp/src/callbacks.cpp b/lang/cpp/src/callbacks.cpp index f7692a03..21c2a813 100644 --- a/lang/cpp/src/callbacks.cpp +++ b/lang/cpp/src/callbacks.cpp @@ -1,155 +1,155 @@ /* callbacks.cpp - callback targets for internal use: Copyright (C) 2003,2004 Klarälvdalens Datakonsult AB 2016 Bundesamt für Sicherheit in der Informationstechnik Software engineering by Intevation GmbH This file is part of GPGME++. GPGME++ is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. GPGME++ is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with GPGME++; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "callbacks.h" #include "util.h" #include #include #include #include #include #include #include #include #include #include #include static inline gpgme_error_t make_err_from_syserror() { return gpgme_error_from_syserror(); } using GpgME::ProgressProvider; using GpgME::PassphraseProvider; using GpgME::DataProvider; void progress_callback(void *opaque, const char *what, int type, int current, int total) { ProgressProvider *provider = static_cast(opaque); if (provider) { provider->showProgress(what, type, current, total); } } /* To avoid that a compiler optimizes certain memset calls away, these macros may be used instead. */ #define wipememory2(_ptr,_set,_len) do { \ volatile char *_vptr=(volatile char *)(_ptr); \ size_t _vlen=(_len); \ while(_vlen) { *_vptr=(_set); _vptr++; _vlen--; } \ } while(0) #define wipememory(_ptr,_len) wipememory2(_ptr,0,_len) gpgme_error_t passphrase_callback(void *opaque, const char *uid_hint, const char *desc, int prev_was_bad, int fd) { PassphraseProvider *provider = static_cast(opaque); bool canceled = false; gpgme_error_t err = GPG_ERR_NO_ERROR; - char *passphrase = provider ? provider->getPassphrase(uid_hint, desc, prev_was_bad, canceled) : 0 ; + char *passphrase = provider ? provider->getPassphrase(uid_hint, desc, prev_was_bad, canceled) : nullptr ; if (canceled) { err = make_error(GPG_ERR_CANCELED); } else { if (passphrase && *passphrase) { size_t passphrase_length = std::strlen(passphrase); size_t written = 0; do { ssize_t now_written = gpgme_io_write(fd, passphrase + written, passphrase_length - written); if (now_written < 0) { err = make_err_from_syserror(); break; } written += now_written; } while (written < passphrase_length); } } if (passphrase && *passphrase) { wipememory(passphrase, std::strlen(passphrase)); } free(passphrase); gpgme_io_write(fd, "\n", 1); return err; } static gpgme_ssize_t data_read_callback(void *opaque, void *buf, size_t buflen) { DataProvider *provider = static_cast(opaque); if (!provider) { gpgme_err_set_errno(gpgme_err_code_to_errno(GPG_ERR_EINVAL)); return -1; } return (gpgme_ssize_t)provider->read(buf, buflen); } static gpgme_ssize_t data_write_callback(void *opaque, const void *buf, size_t buflen) { DataProvider *provider = static_cast(opaque); if (!provider) { gpgme_err_set_errno(gpgme_err_code_to_errno(GPG_ERR_EINVAL)); return -1; } return (gpgme_ssize_t)provider->write(buf, buflen); } static gpgme_off_t data_seek_callback(void *opaque, gpgme_off_t offset, int whence) { DataProvider *provider = static_cast(opaque); if (!provider) { gpgme_err_set_errno(gpgme_err_code_to_errno(GPG_ERR_EINVAL)); return -1; } if (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END) { gpgme_err_set_errno(gpgme_err_code_to_errno(GPG_ERR_EINVAL)); return -1; } return provider->seek((off_t)offset, whence); } static void data_release_callback(void *opaque) { DataProvider *provider = static_cast(opaque); if (provider) { provider->release(); } } const gpgme_data_cbs GpgME::data_provider_callbacks = { &data_read_callback, &data_write_callback, &data_seek_callback, &data_release_callback }; diff --git a/lang/cpp/src/configuration.cpp b/lang/cpp/src/configuration.cpp index 8ccc05e9..33c812f7 100644 --- a/lang/cpp/src/configuration.cpp +++ b/lang/cpp/src/configuration.cpp @@ -1,940 +1,940 @@ /* configuration.cpp - wraps gpgme configuration components Copyright (C) 2010 Klarälvdalens Datakonsult AB 2016 Bundesamt für Sicherheit in der Informationstechnik Software engineering by Intevation GmbH This file is part of GPGME++. GPGME++ is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. GPGME++ is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with GPGME++; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "configuration.h" #include "error.h" #include "util.h" #include #include #include #include #include #include using namespace GpgME; using namespace GpgME::Configuration; typedef std::shared_ptr< std::remove_pointer::type > shared_gpgme_conf_opt_t; typedef std::weak_ptr< std::remove_pointer::type > weak_gpgme_conf_opt_t; typedef std::shared_ptr< std::remove_pointer::type > shared_gpgme_conf_arg_t; typedef std::weak_ptr< std::remove_pointer::type > weak_gpgme_conf_arg_t; typedef std::shared_ptr< std::remove_pointer::type > shared_gpgme_ctx_t; typedef std::weak_ptr< std::remove_pointer::type > weak_gpgme_ctx_t; namespace { struct nodelete { template void operator()(T *) {} }; } // static std::vector Component::load(Error &returnedError) { // // 1. get a context: // - gpgme_ctx_t ctx_native = 0; + gpgme_ctx_t ctx_native = nullptr; if (const gpgme_error_t err = gpgme_new(&ctx_native)) { returnedError = Error(err); return std::vector(); } const shared_gpgme_ctx_t ctx(ctx_native, &gpgme_release); // // 2. load the config: // - gpgme_conf_comp_t conf_list_native = 0; + gpgme_conf_comp_t conf_list_native = nullptr; if (const gpgme_error_t err = gpgme_op_conf_load(ctx_native, &conf_list_native)) { returnedError = Error(err); return std::vector(); } shared_gpgme_conf_comp_t head(conf_list_native, &gpgme_conf_release); // // 3. convert to vector: // std::vector result; while (head) { // secure 'head->next' (if any) against memleaks: shared_gpgme_conf_comp_t next; if (head->next) { next.reset(head->next, &gpgme_conf_release); } // now prevent double-free of next.get() and following: - head->next = 0; + head->next = nullptr; // now add a new Component to 'result' (may throw): result.resize(result.size() + 1); result.back().comp.swap(head); // .comp = std::move( head ); head.swap(next); // head = std::move( next ); } return result; } Error Component::save() const { if (isNull()) { return Error(make_error(GPG_ERR_INV_ARG)); } // // 1. get a context: // - gpgme_ctx_t ctx_native = 0; + gpgme_ctx_t ctx_native = nullptr; if (const gpgme_error_t err = gpgme_new(&ctx_native)) { return Error(err); } const shared_gpgme_ctx_t ctx(ctx_native, &gpgme_release); // // 2. save the config: // return Error(gpgme_op_conf_save(ctx.get(), comp.get())); } const char *Component::name() const { - return comp ? comp->name : 0 ; + return comp ? comp->name : nullptr; } const char *Component::description() const { - return comp ? comp->description : 0 ; + return comp ? comp->description : nullptr ; } const char *Component::programName() const { - return comp ? comp->program_name : 0 ; + return comp ? comp->program_name : nullptr ; } Option Component::option(unsigned int idx) const { - gpgme_conf_opt_t opt = 0; + gpgme_conf_opt_t opt = nullptr; if (comp) { opt = comp->options; } while (opt && idx) { opt = opt->next; --idx; } if (opt) { return Option(comp, opt); } return Option(); } Option Component::option(const char *name) const { - gpgme_conf_opt_t opt = 0; + gpgme_conf_opt_t opt = nullptr; if (comp) { opt = comp->options; } using namespace std; // for strcmp while (opt && strcmp(name, opt->name) != 0) { opt = opt->next; } if (opt) { return Option(comp, opt); } return Option(); } unsigned int Component::numOptions() const { unsigned int result = 0; - for (gpgme_conf_opt_t opt = comp ? comp->options : 0 ; opt ; opt = opt->next) { + for (gpgme_conf_opt_t opt = comp ? comp->options : nullptr ; opt ; opt = opt->next) { ++result; } return result; } std::vector