~ubuntu-branches/ubuntu/oneiric/gnupg2/oneiric-updates

« back to all changes in this revision

Viewing changes to cipher/dynload.c

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-10-04 10:25:53 UTC
  • mfrom: (5.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20081004102553-fv62pp8dsitxli47
Tags: 2.0.9-3.1
* Non-maintainer upload.
* agent/gpg-agent.c: Deinit the threading library before exec'ing
  the command to run in --daemon mode. And because that still doesn't
  restore the sigprocmask, do that manually. Closes: #499569

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* dynload.c - load cipher extensions
2
 
 *      Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
3
 
 *
4
 
 * This file is part of GnuPG.
5
 
 *
6
 
 * GnuPG is free software; you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; either version 2 of the License, or
9
 
 * (at your option) any later version.
10
 
 *
11
 
 * GnuPG is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 * GNU General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program; if not, write to the Free Software
18
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19
 
 */
20
 
 
21
 
#include <config.h>
22
 
#include <stdio.h>
23
 
#include <stdlib.h>
24
 
#include <string.h>
25
 
#include <unistd.h>
26
 
#include "util.h"
27
 
#include "cipher.h"
28
 
#include "algorithms.h"
29
 
 
30
 
 
31
 
typedef struct ext_list {
32
 
    struct ext_list *next;
33
 
    char name[1];
34
 
} *EXTLIST;
35
 
 
36
 
static EXTLIST extensions;
37
 
 
38
 
/* This is actually not used anymore but we keep a list of already 
39
 
 * set extensions modules here.   
40
 
 *
41
 
 * Here is the ancient comment:
42
 
 * Register an extension module.  The last registered module will
43
 
 * be loaded first.  A name may have a list of classes
44
 
 * appended; e.g:
45
 
 *      mymodule.so(1:17,3:20,3:109)
46
 
 * means that this module provides digest algorithm 17 and public key
47
 
 * algorithms 20 and 109.  This is only a hint but if it is there the
48
 
 * loader may decide to only load a module which claims to have a
49
 
 * requested algorithm.
50
 
 *
51
 
 * mainpgm is the path to the program which wants to load a module
52
 
 * it is only used in some environments.
53
 
 */
54
 
void
55
 
register_cipher_extension( const char *mainpgm, const char *fname )
56
 
{
57
 
    EXTLIST r, el, intex;
58
 
    char *p, *pe;
59
 
 
60
 
    if( *fname != DIRSEP_C ) { /* do tilde expansion etc */
61
 
        char *tmp;
62
 
 
63
 
        if( strchr(fname, DIRSEP_C) )
64
 
            tmp = make_filename(fname, NULL);
65
 
        else
66
 
            tmp = make_filename(GNUPG_LIBDIR, fname, NULL);
67
 
        el = m_alloc_clear( sizeof *el + strlen(tmp) );
68
 
        strcpy(el->name, tmp );
69
 
        m_free(tmp);
70
 
    }
71
 
    else {
72
 
        el = m_alloc_clear( sizeof *el + strlen(fname) );
73
 
        strcpy(el->name, fname );
74
 
    }
75
 
    /* check whether we have a class hint */
76
 
    if( (p=strchr(el->name,'(')) && (pe=strchr(p+1,')')) && !pe[1] )
77
 
        *p = *pe = 0;
78
 
 
79
 
    /* check that it is not already registered */
80
 
    intex = NULL;
81
 
    for(r = extensions; r; r = r->next ) {
82
 
        if( !compare_filenames(r->name, el->name) ) {
83
 
            log_info("extension `%s' already registered\n", el->name );
84
 
            m_free(el);
85
 
            return;
86
 
        }
87
 
    }
88
 
    /* and register */
89
 
    el->next = extensions;
90
 
    extensions = el;
91
 
}
92
 
 
93
 
/* Return the module name with index SEQ, return NULL as as indication
94
 
   for end of list. */
95
 
const char *
96
 
dynload_enum_module_names (int seq)
97
 
{
98
 
  EXTLIST el = extensions;
99
 
 
100
 
  for (; el && el->name && seq; el = el->next, seq--)
101
 
    ;
102
 
  return el? el->name:NULL;
103
 
}