1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-11-13 22:08:52 +01:00
gnupg/cipher/dynload.c

102 lines
2.9 KiB
C
Raw Normal View History

2002-06-29 15:31:13 +02:00
/* dynload.c - load cipher extensions
2002-08-03 12:50:53 +02:00
* Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
2002-06-29 15:31:13 +02:00
*
* This file is part of GnuPG.
*
* GnuPG is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
2007-10-23 12:48:09 +02:00
* the Free Software Foundation; either version 3 of the License, or
2002-06-29 15:31:13 +02:00
* (at your option) any later version.
*
* GnuPG 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
2007-10-23 12:48:09 +02:00
* along with this program; if not, see <http://www.gnu.org/licenses/>.
2002-06-29 15:31:13 +02:00
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "util.h"
#include "cipher.h"
2002-08-03 12:50:53 +02:00
#include "algorithms.h"
2002-06-29 15:31:13 +02:00
typedef struct ext_list {
struct ext_list *next;
char name[1];
} *EXTLIST;
static EXTLIST extensions;
2011-08-09 10:54:22 +02:00
/* This is actually not used anymore but we keep a list of already
* set extensions modules here.
2002-08-03 12:50:53 +02:00
*
* Here is the ancient comment:
2002-06-29 15:31:13 +02:00
* Register an extension module. The last registered module will
* be loaded first. A name may have a list of classes
* appended; e.g:
* mymodule.so(1:17,3:20,3:109)
* means that this module provides digest algorithm 17 and public key
* algorithms 20 and 109. This is only a hint but if it is there the
* loader may decide to only load a module which claims to have a
* requested algorithm.
*
* mainpgm is the path to the program which wants to load a module
* it is only used in some environments.
*/
void
register_cipher_extension( const char *mainpgm, const char *fname )
{
2011-08-09 10:54:22 +02:00
EXTLIST r, el;
2002-06-29 15:31:13 +02:00
char *p, *pe;
if( *fname != DIRSEP_C ) { /* do tilde expansion etc */
char *tmp;
if( strchr(fname, DIRSEP_C) )
tmp = make_filename(fname, NULL);
else
tmp = make_filename(GNUPG_LIBDIR, fname, NULL);
2005-07-27 20:10:56 +02:00
el = xmalloc_clear( sizeof *el + strlen(tmp) );
2002-06-29 15:31:13 +02:00
strcpy(el->name, tmp );
2005-07-27 20:10:56 +02:00
xfree(tmp);
2002-06-29 15:31:13 +02:00
}
else {
2005-07-27 20:10:56 +02:00
el = xmalloc_clear( sizeof *el + strlen(fname) );
2002-06-29 15:31:13 +02:00
strcpy(el->name, fname );
}
/* check whether we have a class hint */
2002-08-03 12:50:53 +02:00
if( (p=strchr(el->name,'(')) && (pe=strchr(p+1,')')) && !pe[1] )
2002-06-29 15:31:13 +02:00
*p = *pe = 0;
/* check that it is not already registered */
for(r = extensions; r; r = r->next ) {
if( !compare_filenames(r->name, el->name) ) {
log_info("extension `%s' already registered\n", el->name );
2005-07-27 20:10:56 +02:00
xfree(el);
2002-06-29 15:31:13 +02:00
return;
}
}
/* and register */
el->next = extensions;
extensions = el;
}
2002-08-03 12:50:53 +02:00
/* Return the module name with index SEQ, return NULL as as indication
for end of list. */
2002-06-29 15:31:13 +02:00
const char *
2002-08-03 12:50:53 +02:00
dynload_enum_module_names (int seq)
2002-06-29 15:31:13 +02:00
{
2002-08-03 12:50:53 +02:00
EXTLIST el = extensions;
2002-06-29 15:31:13 +02:00
2002-08-03 12:50:53 +02:00
for (; el && el->name && seq; el = el->next, seq--)
;
return el? el->name:NULL;
2002-06-29 15:31:13 +02:00
}