summaryrefslogtreecommitdiff
path: root/src/tspi/gtk/main.c
blob: 3b76402b8cdc939f74e4a5ffaffa3f1e6e6daef0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

/*
 * Licensed Materials - Property of IBM
 *
 * trousers - An open source TCG Software Stack
 *
 * (C) Copyright International Business Machines Corp. 2004
 *
 */

/*
 * Initial main.c file generated by Glade. Edit as required.
 * Glade will not overwrite this file.
 */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <sys/types.h>
#include <string.h>

#include <gtk/gtk.h>

#undef TRUE
#undef FALSE

#include "trousers/tss.h"
#include "tsplog.h"

#include "interface.h"
#include "support.h"

/*
 * DisplayPINWindow()
 *
 * Popup the dialog to collect an existing password.
 *
 * string - buffer that the password will be passed back to caller in
 * popup - UTF-8 string to be displayed in the title bar of the dialog box
 *
 */
TSS_RESULT
DisplayPINWindow(BYTE *string, UINT32 *string_len, BYTE *popup)
{
  GtkWidget *dialog1;
  struct userdata ud;

  ud.string_len = 0;

#ifdef ENABLE_NLS
  bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);
#endif

  gtk_set_locale();
  gtk_init_check((int *)NULL, (char ***)NULL);

  LogDebug("address of string_len: %p", &ud.string_len);
  dialog1 = create_password_dialog(&ud, (char *)popup);
  gtk_widget_show(dialog1);

  gtk_main();

  if (ud.string_len) {
	  memcpy(string, ud.string, ud.string_len);
	  memset(ud.string, 0, ud.string_len);
	  free(ud.string);
  }
  *string_len = ud.string_len;

  return TSS_SUCCESS;
}

/*
 * DisplayNewPINWindow()
 *
 * Popup the dialog to collect a new password.
 *
 * string - buffer that the password will be passed back to caller in
 * popup - UTF-8 string to be displayed in the title bar of the dialog box
 *
 */
TSS_RESULT
DisplayNewPINWindow(BYTE *string, UINT32 *string_len, BYTE *popup)
{
  GtkWidget *dialog1;
  struct userdata ud;

  ud.string_len = 0;

#ifdef ENABLE_NLS
  bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);
#endif

  gtk_set_locale();
  gtk_init_check((int *)NULL, (char ***)NULL);

  LogDebug("address of string_len: %p", &ud.string_len);
  dialog1 = create_new_password_dialog(&ud, (char *)popup);
  gtk_widget_show(dialog1);

  gtk_main();

  if (ud.string_len) {
	  memcpy(string, ud.string, ud.string_len);
	  memset(ud.string, 0, ud.string_len);
	  free(ud.string);
  }
  *string_len = ud.string_len;

  return TSS_SUCCESS;
}