gwenhywfar  4.99.8beta
ctplugin.c
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Wed Mar 16 2005
3  copyright : (C) 2005 by Martin Preuss
4  email : martin@libchipcard.de
5 
6  ***************************************************************************
7  * Please see toplevel file COPYING for license details *
8  ***************************************************************************/
9 
10 #ifdef HAVE_CONFIG_H
11 # include <config.h>
12 #endif
13 
14 #define DISABLE_DEBUGLOG
15 
16 
17 #include "ctplugin_p.h"
18 #include "i18n_l.h"
19 
20 #include <gwenhywfar/gwenhywfar.h>
21 #include <gwenhywfar/misc.h>
22 #include <gwenhywfar/debug.h>
23 #include <gwenhywfar/gui.h>
24 #include <gwenhywfar/pathmanager.h>
25 
26 
27 #ifdef OS_WIN32
28 # define DIRSEP "\\"
29 #else
30 # define DIRSEP "/"
31 #endif
32 
33 
34 
35 GWEN_INHERIT(GWEN_PLUGIN, GWEN_CRYPT_TOKEN_PLUGIN)
36 
37 
38 
39 
42  int err;
43  GWEN_STRINGLIST *sl;
44 
47  if (err) {
48  DBG_ERROR(GWEN_LOGDOMAIN, "Could not register CryptToken plugin manager");
49  return err;
50  }
51 
52  /* create plugin paths */
54  if (sl) {
56  GWEN_BUFFER *pbuf;
57 
58  pbuf=GWEN_Buffer_new(0, 256, 0, 1);
59 
61  while(se) {
64  DBG_INFO(GWEN_LOGDOMAIN, "Adding plugin path [%s]",
65  GWEN_Buffer_GetStart(pbuf));
67  GWEN_Buffer_GetStart(pbuf));
68  GWEN_Buffer_Reset(pbuf);
70  }
71  GWEN_Buffer_free(pbuf);
73  }
74 
75  return 0;
76 }
77 
78 
79 
82 
84  if (pm) {
85  int rv;
86 
88  if (rv) {
90  "Could not unregister CryptToken plugin manager (%d)", rv);
91  return rv;
92  }
93  else
95  }
96 
97  return 0;
98 }
99 
100 
101 
102 
103 
104 
105 
106 
107 
108 
109 
111  GWEN_CRYPT_TOKEN_DEVICE devType,
112  const char *typeName,
113  const char *fileName) {
114  GWEN_PLUGIN *pl;
115  GWEN_CRYPT_TOKEN_PLUGIN *xpl;
116 
117  pl=GWEN_Plugin_new(mgr, typeName, fileName);
118  GWEN_NEW_OBJECT(GWEN_CRYPT_TOKEN_PLUGIN, xpl);
119  GWEN_INHERIT_SETDATA(GWEN_PLUGIN, GWEN_CRYPT_TOKEN_PLUGIN, pl, xpl, GWEN_Crypt_Token_Plugin_FreeData);
120  xpl->devType=devType;
121 
122  return pl;
123 }
124 
125 
126 
129  GWEN_CRYPT_TOKEN_PLUGIN *xpl;
130 
131  xpl=(GWEN_CRYPT_TOKEN_PLUGIN*)p;
132 
133  GWEN_FREE_OBJECT(xpl);
134 }
135 
136 
137 
139  GWEN_CRYPT_TOKEN_PLUGIN *xpl;
140 
141  assert(pl);
142  xpl=GWEN_INHERIT_GETDATA(GWEN_PLUGIN, GWEN_CRYPT_TOKEN_PLUGIN, pl);
143  assert(xpl);
144 
145  if (xpl->createTokenFn)
146  return xpl->createTokenFn(pl, name);
147  else {
148  DBG_WARN(GWEN_LOGDOMAIN, "No createTokenFn");
149  return NULL;
150  }
151 }
152 
153 
154 
156  GWEN_CRYPT_TOKEN_PLUGIN *xpl;
157 
158  assert(pl);
159  xpl=GWEN_INHERIT_GETDATA(GWEN_PLUGIN, GWEN_CRYPT_TOKEN_PLUGIN, pl);
160  assert(xpl);
161 
162  if (xpl->checkTokenFn)
163  return xpl->checkTokenFn(pl, name);
164  else {
165  DBG_INFO(GWEN_LOGDOMAIN, "No checkTokenFn");
167  }
168 }
169 
170 
171 
173  GWEN_CRYPT_TOKEN_PLUGIN *xpl;
174 
175  assert(pl);
176  xpl=GWEN_INHERIT_GETDATA(GWEN_PLUGIN, GWEN_CRYPT_TOKEN_PLUGIN, pl);
177  assert(xpl);
178 
179  return xpl->devType;
180 }
181 
182 
183 
186  GWEN_CRYPT_TOKEN_PLUGIN *xpl;
188 
189  assert(pl);
190  xpl=GWEN_INHERIT_GETDATA(GWEN_PLUGIN, GWEN_CRYPT_TOKEN_PLUGIN, pl);
191  assert(xpl);
192 
193  of=xpl->createTokenFn;
194  xpl->createTokenFn=fn;
195 
196  return of;
197 }
198 
199 
200 
203  GWEN_CRYPT_TOKEN_PLUGIN *xpl;
205 
206  assert(pl);
207  xpl=GWEN_INHERIT_GETDATA(GWEN_PLUGIN, GWEN_CRYPT_TOKEN_PLUGIN, pl);
208  assert(xpl);
209 
210  of=xpl->checkTokenFn;
211  xpl->checkTokenFn=fn;
212 
213  return of;
214 }
215 
216 
217 
218 
219 
220 
221 
222 
223 
224 
228 
230  if (pl1) {
233 
236  if (pit) {
238  const char *ts;
239 
240  if (devt==GWEN_Crypt_Token_Device_Any)
241  ts=NULL;
242  else
245  while(pd) {
246  GWEN_XMLNODE *node;
247  const char *nts;
248  int match=0;
249 
251  assert(node);
252  nts=GWEN_XMLNode_GetProperty(node, "device", 0);
253  if (nts) {
254  if (!ts || (ts && strcasecmp(ts, nts)==0))
255  match=1;
256  }
257  else if (!ts)
258  match=1;
259 
260  if (match) {
262 
265  }
266 
268  }
270  }
272 
276  "No matching plugin descriptions for the given device type");
277  return NULL;
278  }
279  return pl2;
280  }
281  else {
282  DBG_ERROR(GWEN_LOGDOMAIN, "No plugin descriptions at all");
283  }
284  return NULL;
285 }
286 
287 
288 
291  GWEN_BUFFER *typeName,
292  GWEN_BUFFER *tokenName,
293  uint32_t guiid) {
295 
296  assert(pm);
297 
299  if (pdl==NULL) {
300  DBG_ERROR(GWEN_LOGDOMAIN, "No plugin descriptions found for this device type");
301  GWEN_Gui_ProgressLog(guiid,
303  I18N("No plugin found for this device type"));
304  GWEN_Gui_ProgressLog(guiid,
306  I18N("If you're using a Debian/Ubuntu based system "
307  "please consider to install package "
308  LIBCHIPCARD_GWENHYWFAR_PLUGIN_PACKAGE));
309  return GWEN_ERROR_NOT_FOUND;
310  }
311  else {
313 
315  if (pit) {
317  uint32_t progressId;
318  unsigned int pdcount;
319  unsigned int cnt=0;
320 
328  I18N("Determining plugin module..."),
329  NULL,
330  pdcount,
331  guiid);
332 
334  assert(pd);
335  while(pd) {
336  GWEN_XMLNODE *n;
337  int err;
338  GWEN_PLUGIN *pl;
339  char logbuffer[256];
340 
342  assert(n);
343 
344  snprintf(logbuffer, sizeof(logbuffer)-1,
345  I18N("Loading plugin \"%s\""),
347  logbuffer[sizeof(logbuffer)-1]=0;
348  GWEN_Gui_ProgressLog(progressId,
350  logbuffer);
351 
352  /* device type matches, check this plugin */
354  if (pl) {
355  GWEN_BUFFER *lTokenName;
356  int rv;
357 
358  lTokenName=GWEN_Buffer_dup(tokenName);
359 
360  snprintf(logbuffer, sizeof(logbuffer)-1,
361  I18N("Checking plugin \"%s\""),
362  GWEN_Plugin_GetName(pl));
363  logbuffer[sizeof(logbuffer)-1]=0;
364  GWEN_Gui_ProgressLog(progressId,
366  logbuffer);
367 
369  "Checking plugin \"%s\" for [%s]",
371  GWEN_Buffer_GetStart(lTokenName));
372 
373  rv=GWEN_Crypt_Token_Plugin_CheckToken(pl, lTokenName);
374  switch(rv) {
375  case 0:
376  /* responsive plugin found */
377  snprintf(logbuffer, sizeof(logbuffer)-1,
378  I18N("Plugin \"%s\" supports this token"),
379  GWEN_Plugin_GetName(pl));
380  logbuffer[sizeof(logbuffer)-1]=0;
381  err=GWEN_Gui_ProgressLog(progressId,
383  logbuffer);
384  if (err==GWEN_ERROR_USER_ABORTED) {
385  GWEN_Gui_ProgressEnd(progressId);
386  GWEN_Buffer_free(lTokenName);
389  return err;
390  }
391 
392  GWEN_Buffer_Reset(typeName);
394  GWEN_Buffer_Reset(tokenName);
395  GWEN_Buffer_AppendBuffer(tokenName, lTokenName);
396  GWEN_Buffer_free(lTokenName);
399  GWEN_Gui_ProgressEnd(progressId);
400  return 0;
401 
403  snprintf(logbuffer, sizeof(logbuffer)-1,
404  I18N("Plugin \"%s\": Function not implemented"),
405  GWEN_Plugin_GetName(pl));
406  logbuffer[sizeof(logbuffer)-1]=0;
407  GWEN_Gui_ProgressLog(progressId,
409  logbuffer);
410  break;
411 
413  snprintf(logbuffer, sizeof(logbuffer)-1,
414  I18N("Plugin \"%s\" does not support this token"),
415  GWEN_Plugin_GetName(pl));
416  logbuffer[sizeof(logbuffer)-1]=0;
417  GWEN_Gui_ProgressLog(progressId,
419  logbuffer);
420  break;
421 
422  case GWEN_ERROR_BAD_NAME:
423  snprintf(logbuffer, sizeof(logbuffer)-1,
424  I18N("Plugin \"%s\" supports this token, but the name "
425  "did not match"),
426  GWEN_Plugin_GetName(pl));
427  logbuffer[sizeof(logbuffer)-1]=0;
428  GWEN_Gui_ProgressLog(progressId,
430  logbuffer);
431  break;
432 
433  default:
434  snprintf(logbuffer, sizeof(logbuffer)-1,
435  I18N("Plugin \"%s\": Unexpected error (%d)"),
436  GWEN_Plugin_GetName(pl), rv);
437  logbuffer[sizeof(logbuffer)-1]=0;
438  GWEN_Gui_ProgressLog(progressId,
440  logbuffer);
441  break;
442  } /* switch */
443  } /* if plugin loaded */
444  else {
445  snprintf(logbuffer, sizeof(logbuffer)-1,
446  I18N("Could not load plugin \"%s\""),
448  logbuffer[sizeof(logbuffer)-1]=0;
449  GWEN_Gui_ProgressLog(progressId,
451  logbuffer);
452  }
453 
454  cnt++;
455  err=GWEN_Gui_ProgressAdvance(progressId, cnt);
456  if (err) {
457  DBG_INFO(GWEN_LOGDOMAIN, "User aborted");
458  GWEN_Gui_ProgressEnd(progressId);
461  GWEN_Gui_ProgressEnd(progressId);
462  return err;
463  }
464 
466  }
467 
468  GWEN_Gui_ProgressEnd(progressId);
470  }
472  }
473 
475 }
476 
477 
478 
479 
480 
481 
482 
483 
484 
int GWEN_Gui_ProgressLog(uint32_t id, GWEN_LOGGER_LEVEL level, const char *text)
Definition: gui.c:940
GWEN_PLUGIN_DESCRIPTION_LIST2 * GWEN_PluginManager_GetPluginDescrs(GWEN_PLUGIN_MANAGER *pm)
Definition: plugin.c:595
struct GWEN_PLUGIN_MANAGER GWEN_PLUGIN_MANAGER
Definition: plugin.h:40
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition: buffer.c:223
#define I18N(m)
Definition: error.c:42
struct GWEN_STRINGLISTENTRYSTRUCT GWEN_STRINGLISTENTRY
Definition: stringlist.h:51
int GWEN_Gui_ProgressAdvance(uint32_t id, uint32_t progress)
Definition: gui.c:920
GWEN_CRYPT_TOKEN_DEVICE GWEN_Crypt_Token_Plugin_GetDeviceType(const GWEN_PLUGIN *pl)
Definition: ctplugin.c:172
struct GWEN_PLUGIN GWEN_PLUGIN
Definition: plugin.h:39
GWEN_CRYPT_TOKEN_PLUGIN_CHECKTOKEN_FN GWEN_Crypt_Token_Plugin_SetCheckTokenFn(GWEN_PLUGIN *pl, GWEN_CRYPT_TOKEN_PLUGIN_CHECKTOKEN_FN fn)
Definition: ctplugin.c:201
#define GWEN_CRYPT_TOKEN_FOLDER
Definition: ctplugin.h:25
GWEN_PLUGIN_DESCRIPTION_LIST2_ITERATOR * GWEN_PluginDescription_List2_First(GWEN_PLUGIN_DESCRIPTION_LIST2 *l)
#define GWEN_GUI_PROGRESS_ALLOW_EMBED
Definition: gui.h:196
const char * GWEN_XMLNode_GetProperty(const GWEN_XMLNODE *n, const char *name, const char *defaultValue)
Definition: xml.c:228
struct GWEN_PLUGIN_DESCRIPTION GWEN_PLUGIN_DESCRIPTION
Definition: plugindescr.h:41
#define GWEN_CRYPT_TOKEN_PLUGIN_TYPENAME
Definition: ctplugin.h:24
int GWENHYWFAR_CB(* GWEN_CRYPT_TOKEN_PLUGIN_CHECKTOKEN_FN)(GWEN_PLUGIN *pl, GWEN_BUFFER *name)
Definition: ctplugin_be.h:28
#define GWEN_FREE_OBJECT(varname)
Definition: memory.h:92
#define NULL
Definition: binreloc.c:290
#define GWEN_GUI_PROGRESS_ALWAYS_SHOW_LOG
Definition: gui.h:199
void GWEN_PluginManager_free(GWEN_PLUGIN_MANAGER *pm)
Definition: plugin.c:189
#define DIRSEP
Definition: ctplugin.c:30
#define GWEN_GUI_PROGRESS_DELAY
Definition: gui.h:192
#define DBG_WARN(dbg_logger, format, args...)
Definition: debug.h:118
struct GWEN_PLUGIN_DESCRIPTION_LIST2_ITERATOR GWEN_PLUGIN_DESCRIPTION_LIST2_ITERATOR
Definition: listdoc.h:6243
int GWEN_Crypt_Token_ModuleInit(void)
Definition: ctplugin.c:40
GWEN_PLUGIN * GWEN_PluginManager_GetPlugin(GWEN_PLUGIN_MANAGER *pm, const char *s)
Definition: plugin.c:501
#define GWEN_LOGDOMAIN
Definition: logger.h:35
void GWEN_PluginDescription_List2_freeAll(GWEN_PLUGIN_DESCRIPTION_LIST2 *pdl)
Definition: plugindescr.c:188
GWEN_CRYPT_TOKEN * GWEN_Crypt_Token_Plugin_CreateToken(GWEN_PLUGIN *pl, const char *name)
Definition: ctplugin.c:138
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
Definition: buffer.c:38
GWEN_PLUGIN_MANAGER * GWEN_PluginManager_FindPluginManager(const char *s)
Definition: plugin.c:519
GWEN_STRINGLISTENTRY * GWEN_StringList_FirstEntry(const GWEN_STRINGLIST *sl)
Definition: stringlist.c:352
void GWEN_PluginDescription_List2Iterator_free(GWEN_PLUGIN_DESCRIPTION_LIST2_ITERATOR *li)
void GWEN_Buffer_Reset(GWEN_BUFFER *bf)
Definition: buffer.c:684
GWEN_PLUGIN_DESCRIPTION_LIST2 * GWEN_Crypt_Token_PluginManager_GetPluginDescrs(GWEN_PLUGIN_MANAGER *pm, GWEN_CRYPT_TOKEN_DEVICE devt)
Definition: ctplugin.c:225
const char * GWEN_StringListEntry_Data(const GWEN_STRINGLISTENTRY *se)
Definition: stringlist.c:366
void GWEN_StringList_free(GWEN_STRINGLIST *sl)
Definition: stringlist.c:57
GWEN_PLUGIN_DESCRIPTION_LIST2 * GWEN_PluginDescription_List2_new()
GWEN_PLUGIN_DESCRIPTION * GWEN_PluginDescription_List2Iterator_Next(GWEN_PLUGIN_DESCRIPTION_LIST2_ITERATOR *li)
#define GWEN_NEW_OBJECT(typ, varname)
Definition: memory.h:86
void GWEN_PluginDescription_List2_PushBack(GWEN_PLUGIN_DESCRIPTION_LIST2 *l, GWEN_PLUGIN_DESCRIPTION *p)
int GWEN_Crypt_Token_PluginManager_CheckToken(GWEN_PLUGIN_MANAGER *pm, GWEN_CRYPT_TOKEN_DEVICE devt, GWEN_BUFFER *typeName, GWEN_BUFFER *tokenName, uint32_t guiid)
Definition: ctplugin.c:289
#define GWENHYWFAR_CB
Definition: gwenhywfarapi.h:89
unsigned int GWEN_PluginDescription_List2_GetSize(GWEN_PLUGIN_DESCRIPTION_LIST2 *l)
int GWEN_Buffer_AppendBuffer(GWEN_BUFFER *bf, GWEN_BUFFER *sf)
Definition: buffer.c:549
GWEN_PLUGIN_DESCRIPTION * GWEN_PluginDescription_dup(const GWEN_PLUGIN_DESCRIPTION *pd)
Definition: plugindescr.c:141
GWEN_PLUGIN * GWEN_Crypt_Token_Plugin_new(GWEN_PLUGIN_MANAGER *mgr, GWEN_CRYPT_TOKEN_DEVICE devType, const char *typeName, const char *fileName)
Definition: ctplugin.c:110
GWEN_PLUGIN_MANAGER * GWEN_PluginManager_new(const char *name, const char *destLib)
Definition: plugin.c:170
struct GWEN_STRINGLISTSTRUCT GWEN_STRINGLIST
Definition: stringlist.h:54
GWEN_PLUGIN_DESCRIPTION * GWEN_PluginDescription_List2Iterator_Data(GWEN_PLUGIN_DESCRIPTION_LIST2_ITERATOR *li)
GWENHYWFAR_CB void GWEN_Crypt_Token_Plugin_FreeData(GWEN_UNUSED void *bp, void *p)
Definition: ctplugin.c:128
const char * GWEN_Plugin_GetName(const GWEN_PLUGIN *p)
Definition: plugin.c:137
int GWEN_PluginManager_Register(GWEN_PLUGIN_MANAGER *pm)
Definition: plugin.c:534
GWEN_STRINGLIST * GWEN_PathManager_GetPaths(const char *destLib, const char *pathName)
Definition: pathmanager.c:483
GWEN_BUFFER * GWEN_Buffer_dup(GWEN_BUFFER *bf)
Definition: buffer.c:102
#define GWEN_ERROR_BAD_NAME
Definition: error.h:110
struct GWEN_PLUGIN_DESCRIPTION_LIST2 GWEN_PLUGIN_DESCRIPTION_LIST2
Definition: listdoc.h:6238
void GWEN_Buffer_free(GWEN_BUFFER *bf)
Definition: buffer.c:83
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition: buffer.h:41
struct GWEN_CRYPT_TOKEN GWEN_CRYPT_TOKEN
Definition: ct.h:19
uint32_t GWEN_Gui_ProgressStart(uint32_t progressFlags, const char *title, const char *text, uint64_t total, uint32_t guiid)
Definition: gui.c:903
GWEN_XMLNODE * GWEN_PluginDescription_GetXmlNode(const GWEN_PLUGIN_DESCRIPTION *pd)
Definition: plugindescr.c:391
int GWEN_Gui_ProgressEnd(uint32_t id)
Definition: gui.c:971
#define DBG_ERROR(dbg_logger, format, args...)
Definition: debug.h:97
int GWEN_Crypt_Token_Plugin_CheckToken(GWEN_PLUGIN *pl, GWEN_BUFFER *name)
Definition: ctplugin.c:155
#define GWEN_GUI_PROGRESS_SHOW_PROGRESS
Definition: gui.h:197
#define GWEN_ERROR_NOT_SUPPORTED
Definition: error.h:109
#define GWEN_GUI_PROGRESS_SHOW_LOG
Definition: gui.h:193
GWEN_STRINGLISTENTRY * GWEN_StringListEntry_Next(const GWEN_STRINGLISTENTRY *se)
Definition: stringlist.c:359
const char * GWEN_Crypt_Token_Device_toString(GWEN_CRYPT_TOKEN_DEVICE d)
Definition: ct.c:1126
const char * GWEN_PluginDescription_GetName(const GWEN_PLUGIN_DESCRIPTION *pd)
Definition: plugindescr.c:215
#define GWEN_ERROR_NOT_FOUND
Definition: error.h:89
#define GWEN_PM_PLUGINDIR
Definition: gwenhywfar.h:53
#define DBG_INFO(dbg_logger, format, args...)
Definition: debug.h:164
#define GWEN_PM_LIBNAME
Definition: gwenhywfar.h:42
GWEN_CRYPT_TOKEN_DEVICE
Definition: ct.h:35
int GWEN_PluginManager_Unregister(GWEN_PLUGIN_MANAGER *pm)
Definition: plugin.c:564
int GWEN_PluginManager_AddPath(GWEN_PLUGIN_MANAGER *pm, const char *callingLib, const char *s)
Definition: plugin.c:210
#define GWEN_INHERIT(bt, t)
Definition: inherit.h:264
GWEN_CRYPT_TOKEN_PLUGIN_CREATETOKEN_FN GWEN_Crypt_Token_Plugin_SetCreateTokenFn(GWEN_PLUGIN *pl, GWEN_CRYPT_TOKEN_PLUGIN_CREATETOKEN_FN fn)
Definition: ctplugin.c:184
#define GWEN_ERROR_USER_ABORTED
Definition: error.h:65
#define GWEN_INHERIT_SETDATA(bt, t, element, data, fn)
Definition: inherit.h:292
GWEN_CRYPT_TOKEN *GWENHYWFAR_CB(* GWEN_CRYPT_TOKEN_PLUGIN_CREATETOKEN_FN)(GWEN_PLUGIN *pl, const char *name)
Definition: ctplugin_be.h:24
struct GWEN__XMLNODE GWEN_XMLNODE
Definition: xml.h:148
GWEN_PLUGIN * GWEN_Plugin_new(GWEN_PLUGIN_MANAGER *pm, const char *name, const char *fileName)
Definition: plugin.c:79
int GWEN_Crypt_Token_ModuleFini(void)
Definition: ctplugin.c:80
#define GWEN_UNUSED
int GWEN_Buffer_AppendString(GWEN_BUFFER *bf, const char *buffer)
Definition: buffer.c:1014
#define GWEN_INHERIT_GETDATA(bt, t, element)
Definition: inherit.h:271
#define GWEN_GUI_PROGRESS_SHOW_ABORT
Definition: gui.h:194
#define GWEN_ERROR_NOT_IMPLEMENTED
Definition: error.h:108