gwenhywfar  4.3.3
gwenhywfar.c
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Thu Sep 11 2003
3  copyright : (C) 2003 by Martin Preuss
4  email : martin@libchipcard.de
5 
6  ***************************************************************************
7  * *
8  * This library is free software; you can redistribute it and/or *
9  * modify it under the terms of the GNU Lesser General Public *
10  * License as published by the Free Software Foundation; either *
11  * version 2.1 of the License, or (at your option) any later version. *
12  * *
13  * This library is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16  * Lesser General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU Lesser General Public *
19  * License along with this library; if not, write to the Free Software *
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21  * MA 02111-1307 USA *
22  * *
23  ***************************************************************************/
24 
25 
26 #ifdef HAVE_CONFIG_H
27 # include <config.h>
28 #endif
29 
30 /* Internationalization */
31 #ifdef ENABLE_NLS
32 # include <libintl.h>
33 # include <locale.h>
34 #endif
35 
36 
37 #include <gwenhywfar/gwenhywfar.h>
38 #include <gwenhywfar/directory.h>
39 #include <gwenhywfar/pathmanager.h>
40 
41 #include "base/debug.h"
42 #include "base/logger_l.h"
43 
44 #include "base/error_l.h"
45 #include "base/memory_l.h"
46 #include "base/pathmanager_l.h"
47 #include "base/plugin_l.h"
48 #include "base/i18n_l.h"
49 
50 #include "os/inetaddr_l.h"
51 #include "os/inetsocket_l.h"
52 #include "os/libloader_l.h"
53 #include "os/process_l.h"
54 
55 #include "parser/dbio_l.h"
56 #include "parser/configmgr_l.h"
57 #include "crypt3/cryptkey_l.h"
58 #include "crypttoken/ctplugin_l.h"
59 
60 #include "binreloc.h"
61 
62 #include <gnutls/gnutls.h>
63 
64 
65 /* for regkey stuff */
66 #ifdef OS_WIN32
67 # define DIRSEP "\\"
68 # include <windows.h>
69 #else
70 # define DIRSEP "/"
71 #endif
72 
73 
74 /* Watch out: Make sure these are identical with the identifiers
75  in gwenhywfar.iss.in ! */
76 #define GWEN_REGKEY_PATHS "Software\\Gwenhywfar\\Paths"
77 #define GWEN_REGNAME_PREFIX "prefix"
78 #define GWEN_REGNAME_LIBDIR "libdir"
79 #define GWEN_REGNAME_PLUGINDIR "plugindir"
80 #define GWEN_REGNAME_SYSCONFDIR "sysconfdir"
81 #define GWEN_REGNAME_LOCALEDIR "localedir"
82 #define GWEN_REGNAME_DATADIR "pkgdatadir"
83 #define GWEN_REGNAME_SYSDATADIR "sysdatadir"
84 
85 
86 
87 static unsigned int gwen_is_initialized=0;
89 
90 char *GWEN__get_plugindir (const char *default_dir);
91 
92 int GWEN_Init(void) {
93  int err;
94 
95  if (gwen_is_initialized==0) {
97  if (err)
98  return err;
100  if (err)
101  return err;
102 
103  gnutls_global_init();
104 
105  if (gwen_binreloc_initialized==0) {
106 #ifdef ENABLE_BINRELOC
107  BrInitError br_error;
108 
109  /* Init binreloc. Note: It is not totally clear whether the correct
110  function might still be br_init() instead of br_init_lib(). */
111  if (!br_init_lib(&br_error)) {
112  DBG_INFO(GWEN_LOGDOMAIN, "Error on br_init: %d\n", br_error);
114  }
115  else
117 #else
119 #endif
120  }
121 
123 
125  if (err)
126  return err;
127 
128  /* Define some paths used by gwenhywfar; add the windows
129  registry entries first, because on Unix those functions
130  simply do nothing and on windows they will ensure that the
131  most valid paths (which are those from the registry) are
132  first in the path lists. */
133 
134  /* ---------------------------------------------------------------------
135  * $sysconfdir e.g. "/etc" */
142 #if defined(OS_WIN32) || defined(ENABLE_LOCAL_INSTALL)
143  /* add folder relative to EXE */
147  GWEN_SYSCONF_DIR,
149 #else
150  /* add absolute folder */
154  GWEN_SYSCONF_DIR);
155 #endif
156 
157  /* ---------------------------------------------------------------------
158  * $localedir e.g. "/usr/share/locale" */
165 #if defined(OS_WIN32) || defined(ENABLE_LOCAL_INSTALL)
166  /* add folder relative to EXE */
170  LOCALEDIR,
172 #else
173  /* add absolute folder */
177  LOCALEDIR);
178 #endif
179 
180  /* ---------------------------------------------------------------------
181  * $plugindir e.g. "/usr/lib/gwenhywfar/plugins/0" */
188 #if defined(OS_WIN32) || defined(ENABLE_LOCAL_INSTALL)
189  /* add folder relative to EXE */
193  PLUGINDIR,
195 #else
196  /* add absolute folder */
200  PLUGINDIR);
201 #endif
202 
203  /* ---------------------------------------------------------------------
204  * datadir e.g. "/usr/share/gwenhywfar" */
211 #if defined(OS_WIN32) || defined(ENABLE_LOCAL_INSTALL)
212  /* add folder relative to EXE */
216  GWEN_DATADIR,
218 #else
219  /* add absolute folder */
223  GWEN_DATADIR);
224 #endif
225 
226  /* ---------------------------------------------------------------------
227  * system datadir e.g. "/usr/share" */
234 #if defined(OS_WIN32) || defined(ENABLE_LOCAL_INSTALL)
235  /* add folder relative to EXE */
239  GWEN_SYSDATADIR,
241 #else
242  /* add absolute folder */
246  GWEN_SYSDATADIR);
247 #endif
248 
249  /* Initialize other modules. */
250  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing I18N module");
251  err=GWEN_I18N_ModuleInit();
252  if (err)
253  return err;
254  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing InetAddr module");
256  if (err)
257  return err;
258  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing Socket module");
260  if (err)
261  return err;
262  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing Libloader module");
264  if (err)
265  return err;
266  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing Crypt3 module");
268  if (err)
269  return err;
270  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing Process module");
272  if (err)
273  return err;
274  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing Plugin module");
276  if (err)
277  return err;
278  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing DataBase IO module");
279  err=GWEN_DBIO_ModuleInit();
280  if (err)
281  return err;
282  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing ConfigMgr module");
284  if (err)
285  return err;
286  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing CryptToken2 module");
288  if (err)
289  return err;
290  /* add more modules here */
291 
292  }
294 
295  return 0;
296 
297 }
298 
299 
300 
301 int GWEN_Fini(void) {
302  int err;
303 
304  err=0;
305 
306  if (gwen_is_initialized==0)
307  return 0;
308 
310  if (gwen_is_initialized==0) {
311  int lerr;
312 
313  /* add more modules here */
315  if (lerr) {
316  err=lerr;
317  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
318  "Could not deinitialze module CryptToken2");
319  }
321  if (lerr) {
322  err=lerr;
323  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
324  "Could not deinitialze module ConfigMgr");
325  }
326  lerr=GWEN_DBIO_ModuleFini();
327  if (lerr) {
328  err=lerr;
329  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
330  "Could not deinitialze module DBIO");
331  }
332  lerr=GWEN_Plugin_ModuleFini();
333  if (lerr) {
334  err=lerr;
335  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
336  "Could not deinitialze module Plugin");
337  }
339  if (lerr) {
340  err=lerr;
341  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
342  "Could not deinitialze module Process");
343  }
344  lerr=GWEN_Crypt3_ModuleFini();
345  if (lerr) {
346  err=lerr;
347  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
348  "Could not deinitialze module Crypt3");
349  }
351  if (lerr) {
352  err=lerr;
353  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
354  "Could not deinitialze module LibLoader");
355  }
356  lerr=GWEN_Socket_ModuleFini();
357  if (lerr) {
358  err=lerr;
359  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
360  "Could not deinitialze module Socket");
361  }
363  if (lerr) {
364  err=lerr;
365  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
366  "Could not deinitialze module InetAddr");
367  }
368 
369  lerr=GWEN_I18N_ModuleFini();
370  if (lerr) {
371  err=lerr;
372  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
373  "Could not deinitialze module I18N");
374  }
375 
377  if (lerr) {
378  err=lerr;
379  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
380  "Could not deinitialze module PathManager");
381  }
382 
384 
385  /* these two modules must be deinitialized at last */
386  lerr=GWEN_Logger_ModuleFini();
387  if (lerr) {
388  err=lerr;
389  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
390  "Could not deinitialze module Logger");
391  }
392 
393  lerr=GWEN_Memory_ModuleFini();
394  if (lerr) {
395  err=lerr;
396  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
397  "Could not deinitialze module Memory");
398  }
399 
400  gnutls_global_deinit();
401 
402  }
403 
404  return err;
405 }
406 
407 
408 
409 int GWEN_Fini_Forced(void) {
412  return GWEN_Fini();
413 }
414 
415 
416 
417 void GWEN_Version(int *major,
418  int *minor,
419  int *patchlevel,
420  int *build){
423  *patchlevel=GWENHYWFAR_VERSION_PATCHLEVEL;
425 }
426 
427 
428