gwenhywfar  4.99.15beta
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 {
94  int err;
95 
96  if (gwen_is_initialized==0) {
98  if (err)
99  return err;
101  if (err)
102  return err;
103 
104  gnutls_global_init();
105 
106  if (gwen_binreloc_initialized==0) {
107 #ifdef ENABLE_BINRELOC
108  BrInitError br_error;
109 
110  /* Init binreloc. Note: It is not totally clear whether the correct
111  function might still be br_init() instead of br_init_lib(). */
112  if (!br_init_lib(&br_error)) {
113  DBG_INFO(GWEN_LOGDOMAIN, "Error on br_init: %d\n", br_error);
115  }
116  else
118 #else
120 #endif
121  }
122 
124 
126  if (err)
127  return err;
128 
129  /* Define some paths used by gwenhywfar; add the windows
130  registry entries first, because on Unix those functions
131  simply do nothing and on windows they will ensure that the
132  most valid paths (which are those from the registry) are
133  first in the path lists. */
134 
135  /* ---------------------------------------------------------------------
136  * $sysconfdir e.g. "/etc" */
143 #if defined(OS_WIN32) || defined(ENABLE_LOCAL_INSTALL)
144  /* add folder relative to EXE */
148  GWEN_SYSCONF_DIR,
150 #else
151  /* add absolute folder */
155  GWEN_SYSCONF_DIR);
156 #endif
157 
158  /* ---------------------------------------------------------------------
159  * $localedir e.g. "/usr/share/locale" */
166 #if defined(OS_WIN32) || defined(ENABLE_LOCAL_INSTALL)
167  /* add folder relative to EXE */
171  LOCALEDIR,
173 #else
174  /* add absolute folder */
178  LOCALEDIR);
179 #endif
180 
181  /* ---------------------------------------------------------------------
182  * $plugindir e.g. "/usr/lib/gwenhywfar/plugins/0" */
189 #if defined(OS_WIN32) || defined(ENABLE_LOCAL_INSTALL)
190  /* add folder relative to EXE */
194  PLUGINDIR,
196 #else
197  /* add absolute folder */
201  PLUGINDIR);
202 #endif
203 
204  /* ---------------------------------------------------------------------
205  * datadir e.g. "/usr/share/gwenhywfar" */
212 #if defined(OS_WIN32) || defined(ENABLE_LOCAL_INSTALL)
213  /* add folder relative to EXE */
217  GWEN_DATADIR,
219 #else
220  /* add absolute folder */
224  GWEN_DATADIR);
225 #endif
226 
227  /* ---------------------------------------------------------------------
228  * system datadir e.g. "/usr/share" */
235 #if defined(OS_WIN32) || defined(ENABLE_LOCAL_INSTALL)
236  /* add folder relative to EXE */
240  GWEN_SYSDATADIR,
242 #else
243  /* add absolute folder */
247  GWEN_SYSDATADIR);
248 #endif
249 
250  /* Initialize other modules. */
251  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing I18N module");
252  err=GWEN_I18N_ModuleInit();
253  if (err)
254  return err;
255  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing InetAddr module");
257  if (err)
258  return err;
259  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing Socket module");
261  if (err)
262  return err;
263  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing Libloader module");
265  if (err)
266  return err;
267  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing Crypt3 module");
269  if (err)
270  return err;
271  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing Process module");
273  if (err)
274  return err;
275  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing Plugin module");
277  if (err)
278  return err;
279  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing DataBase IO module");
280  err=GWEN_DBIO_ModuleInit();
281  if (err)
282  return err;
283  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing ConfigMgr module");
285  if (err)
286  return err;
287  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing CryptToken2 module");
289  if (err)
290  return err;
291  /* add more modules here */
292 
293  }
295 
296  return 0;
297 
298 }
299 
300 
301 
302 int GWEN_Fini(void)
303 {
304  int err;
305 
306  err=0;
307 
308  if (gwen_is_initialized==0)
309  return 0;
310 
312  if (gwen_is_initialized==0) {
313  int lerr;
314 
315  /* add more modules here */
317  if (lerr) {
318  err=lerr;
319  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
320  "Could not deinitialze module CryptToken2");
321  }
323  if (lerr) {
324  err=lerr;
325  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
326  "Could not deinitialze module ConfigMgr");
327  }
328  lerr=GWEN_DBIO_ModuleFini();
329  if (lerr) {
330  err=lerr;
331  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
332  "Could not deinitialze module DBIO");
333  }
334  lerr=GWEN_Plugin_ModuleFini();
335  if (lerr) {
336  err=lerr;
337  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
338  "Could not deinitialze module Plugin");
339  }
341  if (lerr) {
342  err=lerr;
343  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
344  "Could not deinitialze module Process");
345  }
346  lerr=GWEN_Crypt3_ModuleFini();
347  if (lerr) {
348  err=lerr;
349  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
350  "Could not deinitialze module Crypt3");
351  }
353  if (lerr) {
354  err=lerr;
355  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
356  "Could not deinitialze module LibLoader");
357  }
358  lerr=GWEN_Socket_ModuleFini();
359  if (lerr) {
360  err=lerr;
361  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
362  "Could not deinitialze module Socket");
363  }
365  if (lerr) {
366  err=lerr;
367  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
368  "Could not deinitialze module InetAddr");
369  }
370 
371  lerr=GWEN_I18N_ModuleFini();
372  if (lerr) {
373  err=lerr;
374  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
375  "Could not deinitialze module I18N");
376  }
377 
379  if (lerr) {
380  err=lerr;
381  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
382  "Could not deinitialze module PathManager");
383  }
384 
386 
387  /* these two modules must be deinitialized at last */
388  lerr=GWEN_Logger_ModuleFini();
389  if (lerr) {
390  err=lerr;
391  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
392  "Could not deinitialze module Logger");
393  }
394 
395  lerr=GWEN_Memory_ModuleFini();
396  if (lerr) {
397  err=lerr;
398  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
399  "Could not deinitialze module Memory");
400  }
401 
402  gnutls_global_deinit();
403 
404  }
405 
406  return err;
407 }
408 
409 
410 
412 {
415  return GWEN_Fini();
416 }
417 
418 
419 
420 void GWEN_Version(int *major,
421  int *minor,
422  int *patchlevel,
423  int *build)
424 {
427  *patchlevel=GWENHYWFAR_VERSION_PATCHLEVEL;
429 }
430 
431 
432 
int GWEN_ConfigMgr_ModuleFini(void)
Definition: configmgr.c:96
int GWEN_Plugin_ModuleFini(void)
Definition: plugin.c:73
#define GWENHYWFAR_VERSION_MAJOR
Definition: version.h:33
int GWEN_DBIO_ModuleFini(void)
Definition: dbio.c:122
int GWEN_LibLoader_ModuleFini(void)
#define GWEN_PM_SYSDATADIR
Definition: gwenhywfar.h:66
static int gwen_binreloc_initialized
Definition: gwenhywfar.c:88
int GWEN_PathManager_AddPath(const char *callingLib, const char *destLib, const char *pathName, const char *pathValue)
Definition: pathmanager.c:121
#define GWEN_REGNAME_SYSCONFDIR
Definition: gwenhywfar.c:80
#define GWEN_REGNAME_DATADIR
Definition: gwenhywfar.c:82
int GWEN_Crypt3_ModuleFini(void)
Definition: cryptkey.c:54
#define GWENHYWFAR_VERSION_PATCHLEVEL
Definition: version.h:35
int GWEN_Crypt_Token_ModuleInit(void)
Definition: ctplugin.c:40
#define GWEN_LOGDOMAIN
Definition: logger.h:35
int build(GWEN_DB_NODE *dbArgs)
Definition: build.c:303
#define GWENHYWFAR_VERSION_BUILD
Definition: version.h:36
int GWEN_I18N_ModuleInit(void)
Definition: i18n.c:130
int GWEN_Socket_ModuleFini(void)
void GWEN_Version(int *major, int *minor, int *patchlevel, int *build)
Definition: gwenhywfar.c:420
int GWEN_Logger_ModuleFini(void)
Definition: logger.c:81
int GWEN_Crypt3_ModuleInit(void)
Definition: cryptkey.c:34
#define GWEN_REGNAME_PLUGINDIR
Definition: gwenhywfar.c:79
int GWEN_Plugin_ModuleInit(void)
Definition: plugin.c:65
int GWEN_I18N_ModuleFini(void)
Definition: i18n.c:172
int GWEN_PathManager_ModuleInit(void)
Definition: pathmanager.c:53
#define br_init_lib
Definition: binreloc.h:40
#define DBG_DEBUG(dbg_logger, format, args...)
Definition: debug.h:208
#define GWEN_PM_SYSCONFDIR
Definition: gwenhywfar.h:46
int GWEN_Error_ModuleInit(void)
Definition: error.c:63
static unsigned int gwen_is_initialized
Definition: gwenhywfar.c:87
int GWEN_Error_ModuleFini(void)
Definition: error.c:71
int GWEN_Memory_ModuleInit(void)
Definition: memory.c:64
int GWEN_Process_ModuleInit(void)
int GWEN_Fini_Forced(void)
Definition: gwenhywfar.c:411
#define GWEN_REGNAME_LOCALEDIR
Definition: gwenhywfar.c:81
int GWEN_Fini(void)
Definition: gwenhywfar.c:302
#define DBG_ERROR(dbg_logger, format, args...)
Definition: debug.h:97
int GWEN_Process_ModuleFini(void)
BrInitError
Definition: binreloc.h:22
int GWEN_Socket_ModuleInit(void)
int GWEN_PathManager_ModuleFini(void)
Definition: pathmanager.c:62
#define GWEN_REGNAME_SYSDATADIR
Definition: gwenhywfar.c:83
int GWEN_DBIO_ModuleInit(void)
Definition: dbio.c:81
#define GWEN_REGKEY_PATHS
Definition: gwenhywfar.c:76
int GWEN_PathManager_AddRelPath(const char *callingLib, const char *destLib, const char *pathName, const char *pathValue, GWEN_PATHMANAGER_RELMODE rm)
Definition: pathmanager.c:163
#define GWEN_PM_PLUGINDIR
Definition: gwenhywfar.h:53
#define GWEN_PM_LOCALEDIR
Definition: gwenhywfar.h:49
#define GWEN_PM_DATADIR
Definition: gwenhywfar.h:56
#define DBG_INFO(dbg_logger, format, args...)
Definition: debug.h:177
#define GWENHYWFAR_VERSION_MINOR
Definition: version.h:34
int GWEN_PathManager_AddPathFromWinReg(GWEN_UNUSED const char *callingLib, GWEN_UNUSED const char *destLib, GWEN_UNUSED const char *pathName, GWEN_UNUSED const char *keypath, GWEN_UNUSED const char *varname)
Definition: pathmanager.c:716
#define GWEN_PM_LIBNAME
Definition: gwenhywfar.h:42
int GWEN_InetAddr_ModuleFini(void)
int GWEN_ConfigMgr_ModuleInit(void)
Definition: configmgr.c:55
int GWEN_Init(void)
Definition: gwenhywfar.c:92
int GWEN_Memory_ModuleFini(void)
Definition: memory.c:80
int GWEN_InetAddr_ModuleInit(void)
int GWEN_LibLoader_ModuleInit(void)
int GWEN_Crypt_Token_ModuleFini(void)
Definition: ctplugin.c:81
int GWEN_Logger_ModuleInit(void)
Definition: logger.c:59
int GWEN_PathManager_DefinePath(const char *destLib, const char *pathName)
Definition: pathmanager.c:71
char * GWEN__get_plugindir(const char *default_dir)