gwenhywfar  4.6.0beta
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 
227  GWEN_PLUGIN_DESCRIPTION_LIST2 *pl1;
228 
230  if (pl1) {
231  GWEN_PLUGIN_DESCRIPTION_LIST2_ITERATOR *pit;
232  GWEN_PLUGIN_DESCRIPTION_LIST2 *pl2;
233 
234  pl2=GWEN_PluginDescription_List2_new();
235  pit=GWEN_PluginDescription_List2_First(pl1);
236  if (pit) {
238  const char *ts;
239 
240  if (devt==GWEN_Crypt_Token_Device_Any)
241  ts=NULL;
242  else
244  pd=GWEN_PluginDescription_List2Iterator_Data(pit);
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 
264  GWEN_PluginDescription_List2_PushBack(pl2, pd2);
265  }
266 
267  pd=GWEN_PluginDescription_List2Iterator_Next(pit);
268  }
269  GWEN_PluginDescription_List2Iterator_free(pit);
270  }
272 
273  if (GWEN_PluginDescription_List2_GetSize(pl2)==0) {
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) {
294  GWEN_PLUGIN_DESCRIPTION_LIST2 *pdl;
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 {
312  GWEN_PLUGIN_DESCRIPTION_LIST2_ITERATOR *pit;
313 
314  pit=GWEN_PluginDescription_List2_First(pdl);
315  if (pit) {
317  uint32_t progressId;
318  unsigned int pdcount;
319  unsigned int cnt=0;
320 
321  pdcount=GWEN_PluginDescription_List2_GetSize(pdl);
328  I18N("Determining plugin module..."),
329  NULL,
330  pdcount,
331  guiid);
332 
333  pd=GWEN_PluginDescription_List2Iterator_Data(pit);
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);
387  GWEN_PluginDescription_List2Iterator_free(pit);
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);
397  GWEN_PluginDescription_List2Iterator_free(pit);
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);
459  GWEN_PluginDescription_List2Iterator_free(pit);
461  GWEN_Gui_ProgressEnd(progressId);
462  return err;
463  }
464 
465  pd=GWEN_PluginDescription_List2Iterator_Next(pit);
466  }
467 
468  GWEN_Gui_ProgressEnd(progressId);
469  GWEN_PluginDescription_List2Iterator_free(pit);
470  }
472  }
473 
475 }
476 
477 
478 
479 
480 
481 
482 
483 
484