From 9db5d05376cc23a8bfecd31aaef61e716363b3ad Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 30 Jan 2001 16:00:50 +0000 Subject: [PATCH] Lookup the path in the Registry --- AUTHORS | 9 ++++ TODO | 2 +- gpgme/ChangeLog | 4 ++ gpgme/Makefile.am | 5 +- gpgme/debug.c | 2 +- gpgme/posix-util.c | 45 ++++++++++++++++++ gpgme/rungpg.c | 3 +- gpgme/util.h | 5 ++ gpgme/w32-util.c | 114 +++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 184 insertions(+), 5 deletions(-) create mode 100644 gpgme/posix-util.c create mode 100644 gpgme/w32-util.c diff --git a/AUTHORS b/AUTHORS index e69de29..20ea6e0 100644 --- a/AUTHORS +++ b/AUTHORS @@ -0,0 +1,9 @@ +Program: gpgme +Maintainer: Werner Koch + + +FSF + * Code taken from GnuPG: gpgme/w32-util.c + +Werner Koch + * Design and most stuff. diff --git a/TODO b/TODO index 59a6d8c..a829ea0 100644 --- a/TODO +++ b/TODO @@ -5,6 +5,6 @@ * Allow to use GTK's main loop instead of the select stuff in wait.c -* Remove all that funny exit code handling - we donn't need it. +* Remove all that funny exit code handling - we don't need it. diff --git a/gpgme/ChangeLog b/gpgme/ChangeLog index 03c72d3..0f704a5 100644 --- a/gpgme/ChangeLog +++ b/gpgme/ChangeLog @@ -1,5 +1,9 @@ 2001-01-30 Werner Koch + * posix-util.c, w32-util.c: New. + (_gpgme_get_gpg_path): New, suggested by Jan-Oliver. + * rungpg.c (_gpgme_gpg_spawn): Use new function to get GPG's path. + * signers.c (gpgme_signers_add): Ooops, one should test code and not just write it; the newarr was not assigned. Thanks to José for pointing this out. Hmmm, still not tested, why shoudl a coder diff --git a/gpgme/Makefile.am b/gpgme/Makefile.am index 20944ac..59faab4 100644 --- a/gpgme/Makefile.am +++ b/gpgme/Makefile.am @@ -13,7 +13,8 @@ libgpgme_la_LDFLAGS = -version-info \ libgpgme_la_INCLUDES = -I$(top_srcdir)/lib libgpgme_la_SOURCES = \ - gpgme.h types.h util.h util.c debug.c \ + gpgme.h types.h \ + util.h util.c posix-util.c w32-util.c \ context.h ops.h \ data.c recipient.c signers.c \ wait.c wait.h \ @@ -31,7 +32,7 @@ libgpgme_la_SOURCES = \ rungpg.c rungpg.h status-table.h \ sema.h posix-sema.c w32-sema.c \ syshdr.h io.h posix-io.c w32-io.c \ - gpgme.c version.c errors.c + gpgme.c debug.c version.c errors.c errors.c : gpgme.h diff --git a/gpgme/debug.c b/gpgme/debug.c index f41929b..7cb5121 100644 --- a/gpgme/debug.c +++ b/gpgme/debug.c @@ -94,7 +94,7 @@ _gpgme_debug_begin ( void **helper, int level, const char *text) return; } - /* Oh what a pitty sthat we don't have a asprintf or snprintf under + /* Oh what a pitty that we don't have a asprintf or snprintf under * Windoze. We definitely should write our own clib for W32! */ sprintf ( ctl->fname, "/tmp/gpgme_debug.%d.%p", getpid (), ctl ); ctl->fp = fopen (ctl->fname, "w+"); diff --git a/gpgme/posix-util.c b/gpgme/posix-util.c new file mode 100644 index 0000000..3c0c692 --- /dev/null +++ b/gpgme/posix-util.c @@ -0,0 +1,45 @@ +/* posix-util.c - Utility functions for Posix + * Copyright (C) 2001 Werner Koch (dd9jn) + * + * This file is part of GPGME. + * + * GPGME 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 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 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 + */ + + +#include +#ifndef HAVE_DOSISH_SYSTEM + +#include +#include +#include +#include + +#include "util.h" + + +const char * +_gpgme_get_gpg_path (void) +{ + return GPG_PATH; +} + + +#endif /*!HAVE_DOSISH_SYSTEM*/ + + + + + diff --git a/gpgme/rungpg.c b/gpgme/rungpg.c index 101d9a9..8c9d2b7 100644 --- a/gpgme/rungpg.c +++ b/gpgme/rungpg.c @@ -718,7 +718,8 @@ _gpgme_gpg_spawn( GpgObject gpg, void *opaque ) fd_parent_list[n].dup_to = -1; - pid = _gpgme_io_spawn (GPG_PATH, gpg->argv, fd_child_list, fd_parent_list); + pid = _gpgme_io_spawn (_gpgme_get_gpg_path (), + gpg->argv, fd_child_list, fd_parent_list); xfree (fd_child_list); if (pid == -1) { return mk_error (Exec_Error); diff --git a/gpgme/util.h b/gpgme/util.h index 65bfa2b..0d901e6 100644 --- a/gpgme/util.h +++ b/gpgme/util.h @@ -119,6 +119,11 @@ char *stpcpy (char *a, const char *b); +/*-- {posix,w32}-util.c --*/ +const char *_gpgme_get_gpg_path (void); + + + #endif /* UTIL_H */ diff --git a/gpgme/w32-util.c b/gpgme/w32-util.c new file mode 100644 index 0000000..f1001a6 --- /dev/null +++ b/gpgme/w32-util.c @@ -0,0 +1,114 @@ +/* w32-util.c - Utility functions for the W32 API + * Copyright (C) 2001 Werner Koch (dd9jn) + * Copyright (C) 1999 Free Software Foundation, Inc + * + * This file is part of GPGME. + * + * GPGME 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 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 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 + */ + + +#include +#ifdef HAVE_DOSISH_SYSTEM + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "syshdr.h" + +#include "util.h" + +/**************** + * Return a string from the Win32 Registry or NULL in case of + * error. Caller must release the return value. A NULL for root + * is an alias fro HKEY_CURRENT_USER + */ +static char * +read_w32_registry_string ( const char *root, + const char *dir, const char *name ) +{ + HKEY root_key, key_handle; + DWORD n1, nbytes; + char *result = NULL; + + if( !root ) + root_key = HKEY_CURRENT_USER; + else if( !strcmp( root, "HKEY_CLASSES_ROOT" ) ) + root_key = HKEY_CLASSES_ROOT; + else if( !strcmp( root, "HKEY_CURRENT_USER" ) ) + root_key = HKEY_CURRENT_USER; + else if( !strcmp( root, "HKEY_LOCAL_MACHINE" ) ) + root_key = HKEY_LOCAL_MACHINE; + else if( !strcmp( root, "HKEY_USERS" ) ) + root_key = HKEY_USERS; + else if( !strcmp( root, "HKEY_PERFORMANCE_DATA" ) ) + root_key = HKEY_PERFORMANCE_DATA; + else if( !strcmp( root, "HKEY_CURRENT_CONFIG" ) ) + root_key = HKEY_CURRENT_CONFIG; + else + return NULL; + + if( RegOpenKeyEx( root_key, dir, 0, KEY_READ, &key_handle ) ) + return NULL; /* no need for a RegClose, so return direct */ + + nbytes = 1; + if( RegQueryValueEx( key_handle, name, 0, NULL, NULL, &nbytes ) ) + goto leave; + result = xtrymalloc( (n1=nbytes+1) ); + if( !result ) + goto leave; + if( RegQueryValueEx( key_handle, name, 0, NULL, result, &n1 ) ) { + xfree(result); result = NULL; + goto leave; + } + result[nbytes] = 0; /* make sure it is really a string */ + + leave: + RegCloseKey( key_handle ); + return result; +} + + +const char * +_gpgme_get_gpg_path (void) +{ + static char *gpg_program = NULL; + + if (!gpg_program) { + gpg_program = read_w32_registry_string ( NULL, + "Software\\GNU\\GnuPG", "gpgProgram" ); + if (!gpg_program) + gpg_program = GPG_PATH; + } + + return gpg_program; +} + + + + +#endif /*HAVE_DOSISH_SYSTEM*/ + + + + + -- 2.26.2