gwenhywfar  5.10.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 #include "gui/gui_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;
100 
101  gnutls_global_init();
102 
103  if (gwen_binreloc_initialized==0) {
104 #ifdef ENABLE_BINRELOC
105  BrInitError br_error;
106 
107  /* Init binreloc. Note: It is not totally clear whether the correct
108  function might still be br_init() instead of br_init_lib(). */
109  if (!br_init_lib(&br_error)) {
110  DBG_INFO(GWEN_LOGDOMAIN, "Error on br_init: %d\n", br_error);
112  }
113  else
115 #else
117 #endif
118  }
119 
121 
123  if (err)
124  return err;
125 
126  /* Define some paths used by gwenhywfar; add the windows
127  registry entries first, because on Unix those functions
128  simply do nothing and on windows they will ensure that the
129  most valid paths (which are those from the registry) are
130  first in the path lists. */
131 
132  /* ---------------------------------------------------------------------
133  * $sysconfdir e.g. "/etc" */
140 #if defined(OS_WIN32) || defined(ENABLE_LOCAL_INSTALL)
141  /* add folder relative to EXE */
145  GWEN_SYSCONF_DIR,
147 #else
148  /* add absolute folder */
152  GWEN_SYSCONF_DIR);
153 #endif
154 
155  /* ---------------------------------------------------------------------
156  * $localedir e.g. "/usr/share/locale" */
163 #if defined(OS_WIN32) || defined(ENABLE_LOCAL_INSTALL)
164  /* add folder relative to EXE */
168  LOCALEDIR,
170 #else
171  /* add absolute folder */
175  LOCALEDIR);
176 #endif
177 
178  /* ---------------------------------------------------------------------
179  * $plugindir e.g. "/usr/lib/gwenhywfar/plugins/0" */
186 #if defined(OS_WIN32) || defined(ENABLE_LOCAL_INSTALL)
187  /* add folder relative to EXE */
191  PLUGINDIR,
193 #else
194  /* add absolute folder */
198  PLUGINDIR);
199 #endif
200 
201  /* ---------------------------------------------------------------------
202  * datadir e.g. "/usr/share/gwenhywfar" */
209 #if defined(OS_WIN32) || defined(ENABLE_LOCAL_INSTALL)
210  /* add folder relative to EXE */
214  GWEN_DATADIR,
216 #else
217  /* add absolute folder */
221  GWEN_DATADIR);
222 #endif
223 
224  /* ---------------------------------------------------------------------
225  * system datadir e.g. "/usr/share" */
232 #if defined(OS_WIN32) || defined(ENABLE_LOCAL_INSTALL)
233  /* add folder relative to EXE */
237  GWEN_SYSDATADIR,
239 #else
240  /* add absolute folder */
244  GWEN_SYSDATADIR);
245 #endif
246 
247  /* Initialize other modules. */
248  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing I18N module");
249  err=GWEN_I18N_ModuleInit();
250  if (err)
251  return err;
252  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing InetAddr module");
254  if (err)
255  return err;
256  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing Socket module");
258  if (err)
259  return err;
260  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing Libloader module");
262  if (err)
263  return err;
264  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing Crypt3 module");
266  if (err)
267  return err;
268  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing Process module");
270  if (err)
271  return err;
272  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing Plugin module");
274  if (err)
275  return err;
276  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing DataBase IO module");
277  err=GWEN_DBIO_ModuleInit();
278  if (err)
279  return err;
280  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing ConfigMgr module");
282  if (err)
283  return err;
284  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing CryptToken2 module");
286  if (err)
287  return err;
288  DBG_DEBUG(GWEN_LOGDOMAIN, "Initializing GUI module");
289  err=GWEN_Gui_ModuleInit();
290  if (err)
291  return err;
292  /* add more modules here */
293 
294  }
296 
297  return 0;
298 
299 }
300 
301 
302 
303 int GWEN_Fini(void)
304 {
305  int err;
306 
307  err=0;
308 
309  if (gwen_is_initialized==0)
310  return 0;
311 
313  if (gwen_is_initialized==0) {
314  int lerr;
315 
316  /* add more modules here */
318 
320  if (lerr) {
321  err=lerr;
322  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
323  "Could not deinitialze module CryptToken2");
324  }
326  if (lerr) {
327  err=lerr;
328  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
329  "Could not deinitialze module ConfigMgr");
330  }
331  lerr=GWEN_DBIO_ModuleFini();
332  if (lerr) {
333  err=lerr;
334  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
335  "Could not deinitialze module DBIO");
336  }
337  lerr=GWEN_Plugin_ModuleFini();
338  if (lerr) {
339  err=lerr;
340  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
341  "Could not deinitialze module Plugin");
342  }
344  if (lerr) {
345  err=lerr;
346  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
347  "Could not deinitialze module Process");
348  }
349  lerr=GWEN_Crypt3_ModuleFini();
350  if (lerr) {
351  err=lerr;
352  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
353  "Could not deinitialze module Crypt3");
354  }
356  if (lerr) {
357  err=lerr;
358  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
359  "Could not deinitialze module LibLoader");
360  }
361  lerr=GWEN_Socket_ModuleFini();
362  if (lerr) {
363  err=lerr;
364  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
365  "Could not deinitialze module Socket");
366  }
368  if (lerr) {
369  err=lerr;
370  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
371  "Could not deinitialze module InetAddr");
372  }
373 
374  lerr=GWEN_I18N_ModuleFini();
375  if (lerr) {
376  err=lerr;
377  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
378  "Could not deinitialze module I18N");
379  }
380 
382  if (lerr) {
383  err=lerr;
384  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
385  "Could not deinitialze module PathManager");
386  }
387 
389 
390  /* these two modules must be deinitialized at last */
391  lerr=GWEN_Logger_ModuleFini();
392  if (lerr) {
393  err=lerr;
394  DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_Fini: "
395  "Could not deinitialze module Logger");
396  }
397 
398  gnutls_global_deinit();
399 
400  }
401 
402  return err;
403 }
404 
405 
406 
408 {
411  return GWEN_Fini();
412 }
413 
414 
415 
416 void GWEN_Version(int *major,
417  int *minor,
418  int *patchlevel,
419  int *build)
420 {
423  *patchlevel=GWENHYWFAR_VERSION_PATCHLEVEL;
425 }
426 
427 
428 
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:44
#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:416
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: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:214
#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
void GWEN_Gui_ModuleFini()
Definition: gui.c:89
int GWEN_Process_ModuleInit(void)
int GWEN_Fini_Forced(void)
Definition: gwenhywfar.c:407
#define GWEN_REGNAME_LOCALEDIR
Definition: gwenhywfar.c:81
int GWEN_Fini(void)
Definition: gwenhywfar.c:303
#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:181
#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_InetAddr_ModuleInit(void)
int GWEN_LibLoader_ModuleInit(void)
int GWEN_Gui_ModuleInit()
Definition: gui.c:79
int GWEN_Crypt_Token_ModuleFini(void)
Definition: ctplugin.c:85
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)