How to set the lib-directory when running gpg-1.0.7?

David Champion dgc at uchicago.edu
Wed Jun 26 00:20:01 CEST 2002


[Hijacked from gnupg-users...]

* On 2002.06.25, in <lfly9d343j5.fsf at gspc71.informatik.uni-stuttgart.de>,
*	"Helmut Waitzmann" <Helmut.Waitzmann at web.de> wrote:
> 
> Is it possible, to supply an option that sets the default
> location for extensions, for example:
> 
>    gpg --extension-directory "$HOME"/lib/gnupg/
> 
> ?  I know, that I can supply a default location during
> ./configure with the option --libdir="$HOME"/lib, but that
> doesn't work, if my home directory gets moved after installing.

I've been wanting something like this myself, for other reasons. This
patch creates a "--module-path" option:
$ gpg --help | grep module-path
     --module-path                colon-separated list of module directories


E.g.
$ gpg --module-path ~/lib/gnupg:/usr/local/lib/gnupg --load-extension foo

If you have load-extension directives in ~/.gnupg/options, you probably
need to put a module-path directive in there, too -- this file is
processed before the command line.

An empty path element will be replaced with gnupg's default extension
directory, so:
	$ gpg --load-extension foo
looks in the default location, and
	$ gpg --module-path ~/lib::/opt/lib/gnupg
looks in ~/lib, then the default location, then /opt/lib/gnupg.

(You can begin or end with an empty path, too, as in "--module-path
~/lib:" or "--module-path :~/lib".)

--debug 4 will show the search sequence, along with other cipher
debugging information.

-- 
 -D.	dgc at uchicago.edu	NSIT	University of Chicago
-------------- next part --------------
diff -ur gnupg-1.0.7-base/cipher/dynload.c gnupg-1.0.7/cipher/dynload.c
--- gnupg-1.0.7-base/cipher/dynload.c	Mon Aug 20 03:51:53 2001
+++ gnupg-1.0.7/cipher/dynload.c	Tue Jun 25 16:01:15 2002
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <sys/stat.h>
 #ifdef HAVE_DL_DLOPEN
   #include <dlfcn.h>
 #elif defined(HAVE_DLD_DLD_LINK)
@@ -37,6 +38,7 @@
 #include "util.h"
 #include "cipher.h"
 #include "dynload.h"
+#include "g10/options.h"
 
 #ifdef WITH_SYMBOL_UNDERSCORE
   #define SYMBOL_VERSION "_gnupgext_version"
@@ -173,18 +175,45 @@
 {
     EXTLIST r, el, intex;
     char *p, *pe;
+    struct stat s;
 
   #ifdef HAVE_DLD_DLD_LINK
     if( !mainpgm_path && mainpgm && *mainpgm )
 	mainpgm_path = m_strdup(mainpgm);
   #endif
     if( *fname != DIRSEP_C ) { /* do tilde expansion etc */
-	char *tmp;
+	char *tmp = NULL;
+	char **mpath;
 
 	if( strchr(fname, DIRSEP_C) )
 	    tmp = make_filename(fname, NULL);
-	else
-	    tmp = make_filename(GNUPG_LIBDIR, fname, NULL);
+	else {
+	    mpath = (char **)opt.module_paths;
+	    if (!mpath)
+		tmp = make_filename(GNUPG_LIBDIR, fname, NULL);
+	    else while (mpath && *mpath) {
+		if (**mpath) {
+		    if (opt.debug & DBG_CIPHER_VALUE)
+			log_debug("Trying %s/%s...\n", *mpath, fname);
+		    tmp = make_filename(*mpath, fname, NULL);
+		} else {
+		    if (opt.debug & DBG_CIPHER_VALUE)
+			log_debug("Trying %s/%s...\n", GNUPG_LIBDIR, fname);
+		    tmp = make_filename(GNUPG_LIBDIR, fname, NULL);
+		}
+		if (stat(tmp, &s) == 0) {
+		    if (opt.debug & DBG_CIPHER_VALUE)
+			log_debug("Found %s\n", tmp);
+		    break;
+		}
+		tmp = NULL;
+		++mpath;
+	    }
+	}
+	if (!tmp) {
+	    log_error("%s: error loading extension: not found\n", fname);
+	    return;
+	}
 	el = m_alloc_clear( sizeof *el + strlen(tmp) );
 	strcpy(el->name, tmp );
 	m_free(tmp);
diff -ur gnupg-1.0.7-base/g10/g10.c gnupg-1.0.7/g10/g10.c
--- gnupg-1.0.7-base/g10/g10.c	Thu Apr 25 02:57:21 2002
+++ gnupg-1.0.7/g10/g10.c	Tue Jun 25 16:01:39 2002
@@ -230,6 +230,7 @@
     oKeyServerOptions,
     oTempDir,
     oExecPath,
+    oModulePath,
     oEncryptTo,
     oNoEncryptTo,
     oLoggerFD,
@@ -356,6 +357,7 @@
     { oNoDefRecipient, "no-default-recipient", 0, "@" },
     { oTempDir, "temp-directory", 2, "@" },
     { oExecPath, "exec-path", 2, "@" },
+    { oModulePath, "module-path", 2|8, N_("colon-separated list of module directories") },
     { oEncryptTo, "encrypt-to", 2, "@" },
     { oNoEncryptTo, "no-encrypt-to", 0, "@" },
     { oUser, "local-user",2, N_("use this user-id to sign or decrypt")},
@@ -1226,6 +1228,31 @@
 	      strcat(path,pargs.r.ret_str);
 	      if(putenv(path)!=0)
 		log_error(_("unable to set exec-path to %s\n"),path);
+	    }
+	    break;
+	  case oModulePath:
+	    {
+	      int   i = 2;
+	      char *p = pargs.r.ret_str;
+	      char *q;
+	      while (p = strchr(p, ':')) {
+		++p;
+		++i;
+	      }
+	      opt.module_paths = malloc(sizeof(char *) * i);
+	      i = 0;
+	      p = q = pargs.r.ret_str;
+	      while (p) {
+		if (q = strchr(p, ':')) {
+		  *q = '\0';
+		  opt.module_paths[i++] = p;
+	          p = ++q;
+		} else {
+		  opt.module_paths[i++] = p;
+		  p = NULL;
+		}
+	      }
+	      opt.module_paths[i] = NULL;
 	    }
 	    break;
 	  case oNotation: add_notation_data( pargs.r.ret_str ); break;
diff -ur gnupg-1.0.7-base/g10/options.h gnupg-1.0.7/g10/options.h
--- gnupg-1.0.7-base/g10/options.h	Mon Apr 29 09:25:56 2002
+++ gnupg-1.0.7/g10/options.h	Tue Jun 25 14:10:24 2002
@@ -123,6 +123,7 @@
     int exec_disable;
     int no_perm_warn;
     char *temp_dir;
+    char **module_paths;
     int no_encrypt_to;
     int interactive;
     STRLIST notation_data;


More information about the Gnupg-devel mailing list