gwenhywfar  4.3.3
cgui.c
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Tue Oct 02 2002
3  copyright : (C) 2002 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 #define DISABLE_DEBUGLOG
31 
32 
33 #ifndef ICONV_CONST
34 # define ICONV_CONST
35 #endif
36 
37 
38 #include "cgui_p.h"
39 #include "i18n_l.h"
40 
41 #include <gwenhywfar/gui_be.h>
42 #include <gwenhywfar/inherit.h>
43 #include <gwenhywfar/debug.h>
44 #include <gwenhywfar/misc.h>
45 #include <gwenhywfar/db.h>
46 #include <gwenhywfar/gwentime.h>
47 #include <gwenhywfar/mdigest.h>
48 #include <gwenhywfar/text.h>
49 
50 
51 #include <stdlib.h>
52 #include <string.h>
53 #include <ctype.h>
54 #ifdef HAVE_TERMIOS_H
55 # include <termios.h>
56 #endif
57 #include <unistd.h>
58 #include <fcntl.h>
59 #include <stdio.h>
60 #include <errno.h>
61 
62 #ifdef HAVE_SIGNAL_H
63 # include <signal.h>
64 #endif
65 
66 
67 
68 GWEN_INHERIT(GWEN_GUI, GWEN_GUI_CGUI)
69 
70 
71 
72 
74  GWEN_GUI *gui;
75  GWEN_GUI_CGUI *cgui;
76 
77  gui=GWEN_Gui_new();
78  GWEN_NEW_OBJECT(GWEN_GUI_CGUI, cgui);
79  cgui->progressList=GWEN_Gui_CProgress_List_new();
80  GWEN_INHERIT_SETDATA(GWEN_GUI, GWEN_GUI_CGUI, gui, cgui,
82 
93 
94  cgui->checkCertFn=GWEN_Gui_SetCheckCertFn(gui, GWEN_Gui_CGui_CheckCert);
95 
96  cgui->dbPasswords=GWEN_DB_Group_new("passwords");
97  cgui->dbCerts=GWEN_DB_Group_new("certs");
98  cgui->badPasswords=GWEN_StringList_new();
99 
100  return gui;
101 }
102 
103 
104 
106  GWEN_GUI_CGUI *cgui;
107 
108  cgui=(GWEN_GUI_CGUI*)p;
109  GWEN_Gui_CProgress_List_free(cgui->progressList);
110  GWEN_StringList_free(cgui->badPasswords);
111  GWEN_DB_Group_free(cgui->dbCerts);
112  GWEN_DB_Group_free(cgui->dbPasswords);
113  GWEN_FREE_OBJECT(cgui);
114 }
115 
116 
117 
118 const char *GWEN_Gui_CGui_GetCharSet(const GWEN_GUI *gui) {
119  return GWEN_Gui_GetCharSet(gui);
120 }
121 
122 
123 
124 void GWEN_Gui_CGui_SetCharSet(GWEN_GUI *gui, const char *s) {
125  GWEN_Gui_SetCharSet(gui, s);
126 }
127 
128 
129 
132 }
133 
134 
135 
137  if (i)
139  else
141 }
142 
143 
144 
147 }
148 
149 
150 
152  if (i)
154  else
156 }
157 
158 
159 
161  int chr;
162 #ifdef HAVE_TERMIOS_H
163  struct termios OldAttr, NewAttr;
164  int AttrChanged = 0;
165 #endif
166 #if HAVE_DECL_SIGPROCMASK
167  sigset_t snew, sold;
168 #endif
169 
170  // disable canonical mode to receive a single character
171 #if HAVE_DECL_SIGPROCMASK
172  sigemptyset(&snew);
173  sigaddset(&snew, SIGINT);
174  sigaddset(&snew, SIGSTOP);
175  sigprocmask(SIG_BLOCK, &snew, &sold);
176 #endif
177 #ifdef HAVE_TERMIOS_H
178  if (0 == tcgetattr (fileno (stdin), &OldAttr)){
179  NewAttr = OldAttr;
180  NewAttr.c_lflag &= ~ICANON;
181  NewAttr.c_lflag &= ~ECHO;
182  tcsetattr (fileno (stdin), TCSAFLUSH, &NewAttr);
183  AttrChanged = !0;
184  }
185 #endif
186 
187  for (;;) {
188  chr=getchar();
189  if (waitFor) {
190  if (chr==-1 ||
191  chr==GWEN_GUI_CGUI_CHAR_ABORT ||
192  chr==GWEN_GUI_CGUI_CHAR_ENTER ||
193  chr==waitFor)
194  break;
195  }
196  else
197  break;
198  }
199 
200 #ifdef HAVE_TERMIOS_H
201  /* re-enable canonical mode (if previously disabled) */
202  if (AttrChanged)
203  tcsetattr (fileno (stdin), TCSADRAIN, &OldAttr);
204 #endif
205 
206 #if HAVE_DECL_SIGPROCMASK
207  sigprocmask(SIG_BLOCK, &sold, 0);
208 #endif
209 
210  return chr;
211 }
212 
213 
214 
216  uint32_t flags,
217  char *buffer,
218  int minLen,
219  int maxLen,
220  uint32_t guiid){
221 #ifdef HAVE_TERMIOS_H
222  struct termios OldInAttr, NewInAttr;
223  struct termios OldOutAttr, NewOutAttr;
224  int AttrInChanged = 0;
225  int AttrOutChanged = 0;
226 #endif
227  int chr;
228  unsigned int pos;
229  int rv;
230 #if HAVE_DECL_SIGPROCMASK
231  sigset_t snew, sold;
232 #endif
233 
234  /* if possible, disable echo from stdin to stderr during password
235  * entry */
236 #if HAVE_DECL_SIGPROCMASK
237  sigemptyset(&snew);
238  sigaddset(&snew, SIGINT);
239  sigaddset(&snew, SIGSTOP);
240  sigprocmask(SIG_BLOCK, &snew, &sold);
241 #endif
242 
243 #ifdef HAVE_TERMIOS_H
244  if (0 == tcgetattr (fileno (stdin), &OldInAttr)){
245  NewInAttr = OldInAttr;
246  NewInAttr.c_lflag &= ~ECHO;
247  NewInAttr.c_lflag &= ~ICANON;
248  tcsetattr (fileno (stdin), TCSAFLUSH, &NewInAttr);
249  AttrInChanged = !0;
250  }
251  if (0 == tcgetattr (fileno (stderr), &OldOutAttr)){
252  NewOutAttr = OldOutAttr;
253  NewOutAttr.c_lflag &= ~ICANON;
254  tcsetattr (fileno (stderr), TCSAFLUSH, &NewOutAttr);
255  AttrOutChanged = !0;
256  }
257 #endif
258 
259  pos=0;
260  rv=0;
261  for (;;) {
262  chr=getchar();
263  if (chr==GWEN_GUI_CGUI_CHAR_DELETE) {
264  if (pos) {
265  pos--;
266  fprintf(stderr, "%c %c", 8, 8);
267  }
268  }
269  else if (chr==GWEN_GUI_CGUI_CHAR_ENTER) {
270  if (minLen && pos<minLen) {
271  if (pos==0 && (flags & GWEN_GUI_INPUT_FLAGS_ALLOW_DEFAULT)) {
275  I18N("Empty Input"),
276  I18N("Your input was empty.\n"
277  "Do you want to use the default?"),
278  I18N("Yes"),
279  I18N("No"),
280  I18N("Abort"), guiid);
281  if (rv==1) {
283  break;
284  }
285  else {
287  break;
288  }
289  }
290  else {
291  /* too few characters */
292  fprintf(stderr, "\007");
293  }
294  }
295  else {
296  fprintf(stderr, "\n");
297  buffer[pos]=0;
298  rv=0;
299  break;
300  }
301  }
302  else {
303  if (pos<maxLen) {
304  if (chr==GWEN_GUI_CGUI_CHAR_ABORT) {
305  DBG_INFO(GWEN_LOGDOMAIN, "User aborted");
307  break;
308  }
309  else {
310  if ((flags & GWEN_GUI_INPUT_FLAGS_NUMERIC) &&
311  !isdigit(chr)) {
312  /* bad character */
313  fprintf(stderr, "\007");
314  }
315  else {
316  if (flags & GWEN_GUI_INPUT_FLAGS_SHOW)
317  fprintf(stderr, "%c", chr);
318  else
319  fprintf(stderr, "*");
320  buffer[pos++]=chr;
321  buffer[pos]=0;
322  }
323  }
324  }
325  else {
326  /* buffer full */
327  fprintf(stderr, "\007");
328  }
329  }
330  } /* for */
331 
332 #ifdef HAVE_TERMIOS_H
333  /* re-enable echo (if previously disabled) */
334  if (AttrOutChanged)
335  tcsetattr (fileno (stderr), TCSADRAIN, &OldOutAttr);
336  if (AttrInChanged)
337  tcsetattr (fileno (stdin), TCSADRAIN, &OldInAttr);
338 #endif
339 
340 #if HAVE_DECL_SIGPROCMASK
341  sigprocmask(SIG_BLOCK, &sold, 0);
342 #endif
343  return rv;
344 }
345 
346 
347 
349  uint32_t flags,
350  const char *title,
351  const char *text,
352  const char *b1,
353  const char *b2,
354  const char *b3,
355  GWEN_UNUSED uint32_t guiid) {
356  GWEN_GUI_CGUI *cgui;
357  GWEN_BUFFER *tbuf;
358  int c;
359 
360  assert(gui);
361  cgui=GWEN_INHERIT_GETDATA(GWEN_GUI, GWEN_GUI_CGUI, gui);
362  assert(cgui);
363 
364  tbuf=GWEN_Buffer_new(0, 256, 0, 1);
365  GWEN_Gui_GetRawText(gui, text, tbuf);
366 
369  fprintf(stderr,
370  "Got the following dangerous message:\n%s\n",
371  GWEN_Buffer_GetStart(tbuf));
372  GWEN_Buffer_free(tbuf);
373  return 0;
374  }
375  else {
377  "Auto-answering the following message with %d:\n%s",
379  GWEN_Buffer_GetStart(tbuf));
380  GWEN_Buffer_free(tbuf);
381  return GWEN_GUI_MSG_FLAGS_CONFIRM_BUTTON(flags);
382  }
383  }
384 
385  fprintf(stderr, "===== %s =====\n", title);
386  fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(tbuf));
387  GWEN_Buffer_free(tbuf);
388  tbuf=0;
389 
390  if (b1) {
391  fprintf(stderr, "(1) %s", b1);
392  if (b2) {
393  fprintf(stderr, " (2) %s", b2);
394  if (b3) {
395  fprintf(stderr, " (3) %s", b3);
396  }
397  }
398  fprintf(stderr, "\n");
399  }
400  fprintf(stderr, "Please enter your choice: ");
401  for(;;) {
403  if (c==EOF) {
404  fprintf(stderr, "Aborted.\n");
406  }
407  if (!b1 && c==13)
408  return 0;
409  if (c=='1' && b1) {
410  fprintf(stderr, "1\n");
411  return 1;
412  }
413  else if (c=='2' && b2) {
414  fprintf(stderr, "2\n");
415  return 2;
416  }
417  else if (c=='3' && b3) {
418  fprintf(stderr, "3\n");
419  return 3;
420  }
421  else {
422  fprintf(stderr, "%c", 7);
423  }
424  } /* for */
425 
426 }
427 
428 
429 
431  uint32_t flags,
432  const char *title,
433  const char *text,
434  char *buffer,
435  int minLen,
436  int maxLen,
437  uint32_t guiid) {
438  int rv;
439  GWEN_BUFFER *tbuf;
440 
441  assert(gui);
442  tbuf=GWEN_Buffer_new(0, 256, 0, 1);
443  GWEN_Gui_GetRawText(gui, text, tbuf);
444 
445  fprintf(stderr, "===== %s =====\n", title);
446  fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(tbuf));
447  GWEN_Buffer_free(tbuf);
448  tbuf=0;
449 
450  if (flags & GWEN_GUI_INPUT_FLAGS_CONFIRM) {
451  for (;;) {
452  char *lbuffer=0;
453 
454  lbuffer=(char*)malloc(maxLen);
455  if (!lbuffer) {
456  DBG_ERROR(GWEN_LOGDOMAIN, "Not enough memory for %d bytes", maxLen);
457  return GWEN_ERROR_INVALID;
458  }
459  fprintf(stderr, "Input: ");
460  rv=GWEN_Gui_CGui__input(gui, flags, lbuffer, minLen, maxLen, guiid);
461  if (rv) {
462  free(lbuffer);
463  return rv;
464  }
465 
466  fprintf(stderr, "Again: ");
467  rv=GWEN_Gui_CGui__input(gui, flags, buffer, minLen, maxLen, guiid);
468  if (rv) {
469  free(lbuffer);
470  return rv;
471  }
472  if (strcmp(lbuffer, buffer)!=0) {
473  fprintf(stderr,
474  "ERROR: Entries do not match, please try (again or abort)\n");
475  }
476  else {
477  rv=0;
478  break;
479  }
480 
481  } /* for */
482  }
483  else {
484  fprintf(stderr, "Input: ");
485  rv=GWEN_Gui_CGui__input(gui, flags, buffer, minLen, maxLen, guiid);
486  }
487 
488  return rv;
489 }
490 
491 
492 
494  GWEN_UNUSED uint32_t flags,
495  const char *title,
496  const char *text,
497  GWEN_UNUSED uint32_t guiid) {
498  GWEN_GUI_CGUI *cgui;
499  GWEN_BUFFER *tbuf;
500 
501  assert(gui);
502  cgui=GWEN_INHERIT_GETDATA(GWEN_GUI, GWEN_GUI_CGUI, gui);
503  assert(cgui);
504 
505  tbuf=GWEN_Buffer_new(0, 256, 0, 1);
506  GWEN_Gui_GetRawText(gui, text, tbuf);
507 
508  fprintf(stderr, "----- %s -----\n", title);
509  fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(tbuf));
510  GWEN_Buffer_free(tbuf);
511  tbuf=0;
512 
513  return ++(cgui->nextBoxId);
514 }
515 
516 
517 
518 void GWEN_Gui_CGui_HideBox(GWEN_GUI *gui, GWEN_UNUSED uint32_t id) {
519  GWEN_GUI_CGUI *cgui;
520 
521  assert(gui);
522  cgui=GWEN_INHERIT_GETDATA(GWEN_GUI, GWEN_GUI_CGUI, gui);
523  assert(cgui);
524 
525  /* nothing to do right now */
526 }
527 
528 
529 
531  uint32_t progressFlags,
532  const char *title,
533  const char *text,
534  uint64_t total,
535  GWEN_UNUSED uint32_t guiid) {
536  GWEN_GUI_CGUI *cgui;
537  GWEN_GUI_CPROGRESS *cp;
538 
539  assert(gui);
540  cgui=GWEN_INHERIT_GETDATA(GWEN_GUI, GWEN_GUI_CGUI, gui);
541  assert(cgui);
542 
543  cp=GWEN_Gui_CProgress_new(gui,
544  ++(cgui->nextProgressId),
545  progressFlags,
546  title,
547  text,
548  total);
549  GWEN_Gui_CProgress_List_Insert(cp, cgui->progressList);
550  return GWEN_Gui_CProgress_GetId(cp);
551 }
552 
553 
554 
556  GWEN_GUI_CGUI *cgui;
557  GWEN_GUI_CPROGRESS *cp;
558 
559  assert(gui);
560  cgui=GWEN_INHERIT_GETDATA(GWEN_GUI, GWEN_GUI_CGUI, gui);
561  assert(cgui);
562 
563  cp=GWEN_Gui_CProgress_List_First(cgui->progressList);
564  if (id==0)
565  return cp;
566  while(cp) {
567  if (GWEN_Gui_CProgress_GetId(cp)==id)
568  break;
569  cp=GWEN_Gui_CProgress_List_Next(cp);
570  } /* while */
571 
572  return cp;
573 }
574 
575 
576 
578  uint32_t id,
579  uint64_t progress) {
580  GWEN_GUI_CGUI *cgui;
581  GWEN_GUI_CPROGRESS *cp;
582 
583  assert(gui);
584  cgui=GWEN_INHERIT_GETDATA(GWEN_GUI, GWEN_GUI_CGUI, gui);
585  assert(cgui);
586 
587  cp=GWEN_Gui_CGui__findProgress(gui, id);
588  if (!cp) {
589  DBG_DEBUG(GWEN_LOGDOMAIN, "Progress object %u not found", id);
590  return 0;
591  }
592  else {
593  return GWEN_Gui_CProgress_Advance(cp, progress);
594  }
595 }
596 
597 
598 
600  uint32_t id,
601  GWEN_LOGGER_LEVEL level,
602  const char *text) {
603  GWEN_GUI_CGUI *cgui;
604  GWEN_GUI_CPROGRESS *cp;
605 
606  assert(gui);
607  cgui=GWEN_INHERIT_GETDATA(GWEN_GUI, GWEN_GUI_CGUI, gui);
608  assert(cgui);
609 
610  cp=GWEN_Gui_CGui__findProgress(gui, id);
611  if (!cp) {
612  DBG_DEBUG(GWEN_LOGDOMAIN, "Progress object %u not found", id);
613  return 0;
614  }
615  else {
616  return GWEN_Gui_CProgress_Log(cp, level, text);
617  }
618 }
619 
620 
621 
622 int GWEN_Gui_CGui_ProgressEnd(GWEN_GUI *gui,uint32_t id) {
623  GWEN_GUI_CGUI *cgui;
624  GWEN_GUI_CPROGRESS *cp;
625 
626  assert(gui);
627  cgui=GWEN_INHERIT_GETDATA(GWEN_GUI, GWEN_GUI_CGUI, gui);
628  assert(cgui);
629 
630  cp=GWEN_Gui_CGui__findProgress(gui, id);
631  if (!cp) {
632  DBG_DEBUG(GWEN_LOGDOMAIN, "Progress object %u not found", id);
633  return 0;
634  }
635  else {
636  int rv;
637 
638  rv=GWEN_Gui_CProgress_End(cp);
639  GWEN_Gui_CProgress_List_Del(cp);
641  return rv;
642  }
643 }
644 
645 
646 
648  GWEN_UNUSED const char *docTitle,
649  GWEN_UNUSED const char *docType,
650  GWEN_UNUSED const char *descr,
651  GWEN_UNUSED const char *text,
652  GWEN_UNUSED uint32_t guiid) {
654 }
655 
656 
657 
658 int GWEN_Gui_CGui__HashPair(const char *token,
659  const char *pin,
660  GWEN_BUFFER *buf) {
661  GWEN_MDIGEST *md;
662  int rv;
663 
664  /* hash token and pin */
666  rv=GWEN_MDigest_Begin(md);
667  if (rv==0)
668  rv=GWEN_MDigest_Update(md, (const uint8_t*)token, strlen(token));
669  if (rv==0)
670  rv=GWEN_MDigest_Update(md, (const uint8_t*)pin, strlen(pin));
671  if (rv==0)
672  rv=GWEN_MDigest_End(md);
673  if (rv<0) {
674  DBG_ERROR(GWEN_LOGDOMAIN, "Hash error (%d)", rv);
675  GWEN_MDigest_free(md);
676  return rv;
677  }
678 
681  buf,
682  0, 0, 0);
683  GWEN_MDigest_free(md);
684  return 0;
685 }
686 
687 
688 
690  const GWEN_SSLCERTDESCR *cd,
691  GWEN_SYNCIO *sio, uint32_t guiid) {
692  GWEN_GUI_CGUI *cgui;
693  const char *hash;
694  const char *status;
695  GWEN_BUFFER *hbuf;
696  int i;
697 
698  assert(gui);
699  cgui=GWEN_INHERIT_GETDATA(GWEN_GUI, GWEN_GUI_CGUI, gui);
700  assert(cgui);
701 
704 
705  hbuf=GWEN_Buffer_new(0, 64, 0, 1);
706  GWEN_Gui_CGui__HashPair(hash, status, hbuf);
707 
708  i=GWEN_DB_GetIntValue(cgui->dbCerts, GWEN_Buffer_GetStart(hbuf), 0, 1);
709  if (i==0) {
711  "Automatically accepting certificate [%s]",
712  hash);
713  GWEN_Buffer_free(hbuf);
714  return 0;
715  }
716 
718  uint32_t fl;
719 
723  "Automatically accepting valid new certificate [%s]",
724  hash);
725  GWEN_Buffer_free(hbuf);
726  return 0;
727  }
728  else {
730  "Automatically rejecting certificate [%s] (noninteractive)",
731  hash);
732  GWEN_Buffer_free(hbuf);
734  }
735  }
736 
737  if (cgui->checkCertFn) {
738  i=cgui->checkCertFn(gui, cd, sio, guiid);
739  if (i==0) {
741  GWEN_Buffer_GetStart(hbuf), i);
742  }
743  GWEN_Buffer_free(hbuf);
744 
745  return i;
746  }
747  else {
748  GWEN_Buffer_free(hbuf);
750  }
751 }
752 
753 
754 
756  const char *token,
757  const char *pin,
759  GWEN_UNUSED uint32_t guiid) {
760  GWEN_GUI_CGUI *cgui;
761 
762  assert(gui);
763  cgui=GWEN_INHERIT_GETDATA(GWEN_GUI, GWEN_GUI_CGUI, gui);
764  assert(cgui);
765 
766  if (token==NULL && pin==NULL && status==GWEN_Gui_PasswordStatus_Remove) {
767  if (cgui->persistentPasswords==0)
768  GWEN_DB_ClearGroup(cgui->dbPasswords, NULL);
769  }
770  else {
771  GWEN_BUFFER *hbuf;
772 
773  hbuf=GWEN_Buffer_new(0, 64, 0, 1);
774  GWEN_Gui_CGui__HashPair(token, pin, hbuf);
775  if (status==GWEN_Gui_PasswordStatus_Bad)
776  GWEN_StringList_AppendString(cgui->badPasswords,
777  GWEN_Buffer_GetStart(hbuf),
778  0, 1);
779  else if (status==GWEN_Gui_PasswordStatus_Ok ||
781  if (cgui->persistentPasswords==0)
782  GWEN_StringList_RemoveString(cgui->badPasswords,
783  GWEN_Buffer_GetStart(hbuf));
784  }
785  GWEN_Buffer_free(hbuf);
786  }
787 
788  return 0;
789 }
790 
791 
792 
794  uint32_t flags,
795  const char *token,
796  const char *title,
797  const char *text,
798  char *buffer,
799  int minLen,
800  int maxLen,
801  uint32_t guiid) {
802  GWEN_GUI_CGUI *cgui;
803 
804  assert(gui);
805  cgui=GWEN_INHERIT_GETDATA(GWEN_GUI, GWEN_GUI_CGUI, gui);
806  assert(cgui);
807 
808  if (flags & GWEN_GUI_INPUT_FLAGS_TAN) {
809  return GWEN_Gui_InputBox(flags,
810  title,
811  text,
812  buffer,
813  minLen,
814  maxLen,
815  guiid);
816  }
817  else {
818  GWEN_BUFFER *buf;
819  int rv;
820  const char *s;
821 
822  buf=GWEN_Buffer_new(0, 256, 0, 1);
824 
825  if (!(flags & GWEN_GUI_INPUT_FLAGS_CONFIRM)) {
826  s=GWEN_DB_GetCharValue(cgui->dbPasswords,
828  0, NULL);
829  if (s) {
830  int i;
831 
832  i=strlen(s);
833  if (i>=minLen && i < maxLen) {
834  memmove(buffer, s, i+1);
835  GWEN_Buffer_free(buf);
836  return 0;
837  }
838  else {
839  DBG_ERROR(GWEN_LOGDOMAIN, "Stored password [%s] is not within size limits (%d), rejecting.",
840  GWEN_Buffer_GetStart(buf), i);
841  }
842  }
843  }
844 
847  "Password for [%s] missing in noninteractive mode, "
848  "aborting", GWEN_Buffer_GetStart(buf));
849  GWEN_Buffer_free(buf);
851  }
852 
853  for (;;) {
854  rv=GWEN_Gui_InputBox(flags,
855  title,
856  text,
857  buffer,
858  minLen,
859  maxLen,
860  guiid);
861  if (rv) {
862  GWEN_Buffer_free(buf);
863  return rv;
864  }
865  else {
866  GWEN_BUFFER *hbuf;
867  int isBad=0;
868 
869  hbuf=GWEN_Buffer_new(0, 64, 0, 1);
870  GWEN_Gui_CGui__HashPair(token, buffer, hbuf);
871  isBad=GWEN_StringList_HasString(cgui->badPasswords,
872  GWEN_Buffer_GetStart(hbuf));
873  if (!isBad) {
874  GWEN_Buffer_free(hbuf);
875  break;
876  }
880  I18N("Enforce PIN"),
881  I18N(
882  "You entered the same PIN twice.\n"
883  "The PIN is marked as bad, do you want\n"
884  "to use it anyway?"
885  "<html>"
886  "<p>"
887  "You entered the same PIN twice."
888  "</p>"
889  "<p>"
890  "The PIN is marked as <b>bad</b>, "
891  "do you want to use it anyway?"
892  "</p>"
893  "</html>"),
894  I18N("Use my input"),
895  I18N("Re-enter"),
896  0,
897  guiid);
898  if (rv==1) {
899  /* accept this input */
900  GWEN_StringList_RemoveString(cgui->badPasswords,
901  GWEN_Buffer_GetStart(hbuf));
902  GWEN_Buffer_free(hbuf);
903  break;
904  }
905  GWEN_Buffer_free(hbuf);
906  }
907  } /* for */
908 
910  GWEN_Buffer_GetStart(buf), buffer);
911  GWEN_Buffer_free(buf);
912  return 0;
913  }
914 }
915 
916 
917 
919  GWEN_DB_NODE *dbPasswords,
920  int persistent) {
921  GWEN_GUI_CGUI *cgui;
922 
923  assert(gui);
924  cgui=GWEN_INHERIT_GETDATA(GWEN_GUI, GWEN_GUI_CGUI, gui);
925  assert(cgui);
926 
927  GWEN_DB_Group_free(cgui->dbPasswords);
928  cgui->dbPasswords=dbPasswords;
929  cgui->persistentPasswords=persistent;
930 }
931 
932 
933 
935  GWEN_GUI_CGUI *cgui;
936 
937  assert(gui);
938  cgui=GWEN_INHERIT_GETDATA(GWEN_GUI, GWEN_GUI_CGUI, gui);
939  assert(cgui);
940 
941  return cgui->dbPasswords;
942 }
943 
944 
945 
947  GWEN_GUI_CGUI *cgui;
948 
949  assert(gui);
950  cgui=GWEN_INHERIT_GETDATA(GWEN_GUI, GWEN_GUI_CGUI, gui);
951  assert(cgui);
952 
953  GWEN_DB_Group_free(cgui->dbCerts);
954  cgui->dbCerts=dbCerts;
955 }
956 
957 
958 
960  GWEN_GUI_CGUI *cgui;
961 
962  assert(gui);
963  cgui=GWEN_INHERIT_GETDATA(GWEN_GUI, GWEN_GUI_CGUI, gui);
964  assert(cgui);
965 
966  return cgui->dbCerts;
967 }
968 
969