gwenhywfar  5.4.1
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/pathmanager_l.h"
46 #include "base/plugin_l.h"
47 #include "base/i18n_l.h"
48 
49 #include "os/inetaddr_l.h"
50 #include "os/inetsocket_l.h"
51 #include "os/libloader_l.h"
52 #include "os/process_l.h"
53 
54 #include "parser/dbio_l.h"
55 #include "parser/configmgr_l.h"
56 #include "crypt3/cryptkey_l.h"
57 #include "crypttoken/ctplugin_l.h"
58 
59 #include "binreloc.h"
60 
61 #include <gnutls/gnutls.h>
62 
63 
64 /* for regkey stuff */
65 #ifdef OS_WIN32
66 # define DIRSEP "\\"
67 # include <windows.h>
68 #else
69 # define DIRSEP "/"
70 #endif
71 
72 
73 /* Watch out: Make sure these are identical with the identifiers
74  in gwenhywfar.iss.in ! */
75 #define GWEN_REGKEY_PATHS "Software\\Gwenhywfar\\Paths"
76 #define GWEN_REGNAME_PREFIX "prefix"
77 #define GWEN_REGNAME_LIBDIR "libdir"
78 #define GWEN_REGNAME_PLUGINDIR "plugindir"
79 #define GWEN_REGNAME_SYSCONFDIR "sysconfdir"
80 #define GWEN_REGNAME_LOCALEDIR "localedir"
81 #define GWEN_REGNAME_DATADIR "pkgdatadir"
82 #define GWEN_REGNAME_SYSDATADIR "sysdatadir"
83 
84 
85 
86 static unsigned int gwen_is_initialized=0;
88 
89 char *GWEN__get_plugindir(const char *default_dir);
90 
91 int GWEN_Init(void)
92 {
93  int err;
94 
95  if (gwen_is_initialized==0) {
97  if (err)
98  return err;
99 
100  gnutls_global_init();
101 
102  if (gwen_binreloc_initialized==0) {
103 #ifdef ENABLE_BINRELOC
104  BrInitError br_error;
105 
106  /* Init binreloc. Note: It is not totally clear whether the correct
107  function might still be br_init() instead of br_init_lib(). */
108  if (!br_init_lib(&br_error)) {
109  DBG_INFO(GWEN_LOGDOMAIN, "Error on br_init: %d\n", br_error);
111  }
112  else
114 #else
116 #endif
117  }
118 
120 
122  if (err)
123  return err;
124 
125  /* Define some paths used by gwenhywfar; add the windows
126  registry entries first, because on Unix those functions
127  simply do nothing and on windows they will ensure that the
128  most valid paths (which are those from the registry) are
129  first in the path lists. */
130 
131  /* ---------------------------------------------------------------------
132  * $sysconfdir e.g. "/etc" */
139 #if defined(OS_WIN32) || defined(ENABLE_LOCAL_INSTALL)
140  /* add folder relative to EXE */
144  GWEN_SYSCONF_DIR,
146 #else
147  /* add absolute folder */
151  GWEN_SYSCONF_DIR);
152 #endif
153 
154  /* ---------------------------------------------------------------------
155  * $localedir e.g. "/usr/share/locale" */
162 #if defined(OS_WIN32) || defined(ENABLE_LOCAL_INSTALL)
163  /* add folder relative to EXE */
167  LOCALEDIR,
169 #else
170  /* add absolute folder */
174  LOCALEDIR);
175 #endif
176 
177  /* ---------------------------------------------------------------------
178  * $plugindir e.g. "/usr/lib/gwenhywfar/plugins/0" */
185 #if defined(OS_WIN32) || defined(ENABLE_LOCAL_INSTALL)
186  /* add folder relative to EXE */
190  PLUGINDIR,
192 #else
193  /* add absolute folder */
197  PLUGINDIR);
198 #endif
199 
200  /* ---------------------------------------------------------------------
201  * datadir e.g. "/usr/share/gwenhywfar" */
208 #if defined(OS_WIN32) || defined(ENABLE_LOCAL_INSTALL)
209  /* add folder relative to EXE */
213  GWEN_DATADIR,
215 #else
216  /* add absolute folder */
220  GWEN_DATADIR);
221 #endif
222 
223  /* ---------------------------------------------------------------------
224  * system datadir e.g. "/usr/share" */
231 #if defined(OS_WIN32) || defined(ENABLE_LOCAL_INSTALL)
232  /* add folder relative to EXE */
236  GWEN_SYSDATADIR,
238 #else
239  /* add absolute folder */
243  GWEN_SYSDATADIR);
244 #endif
245 
246  /* Initialize other modules. */
247  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing I18N module");
248  err=GWEN_I18N_ModuleInit();
249  if (err)
250  return err;
251  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing InetAddr module");
253  if (err)
254  return err;
255  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing Socket module");
257  if (err)
258  return err;
259  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing Libloader module");
261  if (err)
262  return err;
263  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing Crypt3 module");
265  if (err)
266  return err;
267  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing Process module");
269  if (err)
270  return err;
271  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing Plugin module");
273  if (err)
274  return err;
275  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing DataBase IO module");
276  err=GWEN_DBIO_ModuleInit();
277  if (err)
278  return err;
279  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing ConfigMgr module");
281  if (err)
282  return err;
283  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing CryptToken2 module");
285  if (err)
286  return err;
287  /* add more modules here */
288 
289  }
291 
292  return 0;
293 
294 }
295 
296 
297 
298 int GWEN_Fini(void)
299 {
300  int err;
301 
302  err=0;
303 
304  if (gwen_is_initialized==0)
305  return 0;
306 
308  if (gwen_is_initialized==0) {
309  int lerr;
310 
311  /* add more modules here */
313  if (lerr) {
314  err=lerr;
315  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
316  "Could not deinitialze module CryptToken2");
317  }
319  if (lerr) {
320  err=lerr;
321  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
322  "Could not deinitialze module ConfigMgr");
323  }
324  lerr=GWEN_DBIO_ModuleFini();
325  if (lerr) {
326  err=lerr;
327  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
328  "Could not deinitialze module DBIO");
329  }
330  lerr=GWEN_Plugin_ModuleFini();
331  if (lerr) {
332  err=lerr;
333  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
334  "Could not deinitialze module Plugin");
335  }
337  if (lerr) {
338  err=lerr;
339  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
340  "Could not deinitialze module Process");
341  }
342  lerr=GWEN_Crypt3_ModuleFini();
343  if (lerr) {
344  err=lerr;
345  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
346  "Could not deinitialze module Crypt3");
347  }
349  if (lerr) {
350  err=lerr;
351  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
352  "Could not deinitialze module LibLoader");
353  }
354  lerr=GWEN_Socket_ModuleFini();
355  if (lerr) {
356  err=lerr;
357  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
358  "Could not deinitialze module Socket");
359  }
361  if (lerr) {
362  err=lerr;
363  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
364  "Could not deinitialze module InetAddr");
365  }
366 
367  lerr=GWEN_I18N_ModuleFini();
368  if (lerr) {
369  err=lerr;
370  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
371  "Could not deinitialze module I18N");
372  }
373 
375  if (lerr) {
376  err=lerr;
377  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
378  "Could not deinitialze module PathManager");
379  }
380 
382 
383  /* these two modules must be deinitialized at last */
384  lerr=GWEN_Logger_ModuleFini();
385  if (lerr) {
386  err=lerr;
387  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
388  "Could not deinitialze module Logger");
389  }
390 
391  gnutls_global_deinit();
392 
393  }
394 
395  return err;
396 }
397 
398 
399 
401 {
404  return GWEN_Fini();
405 }
406 
407 
408 
409 void GWEN_Version(int *major,
410  int *minor,
411  int *patchlevel,
412  int *build)
413 {
416  *patchlevel=GWENHYWFAR_VERSION_PATCHLEVEL;
418 }
419 
420 
421 
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:87
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:79
#define GWEN_REGNAME_DATADIR
Definition: gwenhywfar.c:81
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:132
int GWEN_Socket_ModuleFini(void)
void GWEN_Version(int *major, int *minor, int *patchlevel, int *build)
Definition: gwenhywfar.c:409
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:78
int GWEN_Plugin_ModuleInit(void)
Definition: plugin.c:65
int GWEN_I18N_ModuleFini(void)
Definition: i18n.c:174
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:209
#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:86
int GWEN_Error_ModuleFini(void)
Definition: error.c:71
int GWEN_Process_ModuleInit(void)
int GWEN_Fini_Forced(void)
Definition: gwenhywfar.c:400
#define GWEN_REGNAME_LOCALEDIR
Definition: gwenhywfar.c:80
int GWEN_Fini(void)
Definition: gwenhywfar.c:298
#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:82
int GWEN_DBIO_ModuleInit(void)
Definition: dbio.c:81
#define GWEN_REGKEY_PATHS
Definition: gwenhywfar.c:75
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:178
#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:91
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)