1 |
twoaday |
2 |
/* wptOwnertrust.cpp - Ownertrust im- and export |
2 |
twoaday |
23 |
* Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz |
3 |
|
|
* Copyright (C) 2005 g10 Code GmbH |
4 |
twoaday |
2 |
* |
5 |
|
|
* This file is part of WinPT. |
6 |
|
|
* |
7 |
|
|
* WinPT is free software; you can redistribute it and/or modify |
8 |
|
|
* it under the terms of the GNU General Public License as published by |
9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
10 |
|
|
* (at your option) any later version. |
11 |
|
|
* |
12 |
|
|
* WinPT is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
19 |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
#include <windows.h> |
23 |
twoaday |
23 |
#include <errno.h> |
24 |
|
|
#include <sys/stat.h> |
25 |
twoaday |
2 |
|
26 |
|
|
#include "../resource.h" |
27 |
|
|
#include "wptTypes.h" |
28 |
|
|
#include "wptGPG.h" |
29 |
|
|
#include "wptErrors.h" |
30 |
|
|
#include "wptNLS.h" |
31 |
|
|
#include "wptW32API.h" |
32 |
|
|
|
33 |
|
|
|
34 |
twoaday |
23 |
/* Export the ownertrust to the file @fname. |
35 |
|
|
Return value: 0 on success. */ |
36 |
|
|
static gpgme_error_t |
37 |
|
|
gpg_export_ownertrust (const char *fname) |
38 |
|
|
{ |
39 |
|
|
gpgme_error_t err; |
40 |
|
|
char *ot_data = NULL; |
41 |
|
|
FILE *f; |
42 |
|
|
|
43 |
|
|
err = gpg_manage_ownertrust (&ot_data, 1); |
44 |
|
|
if (err) |
45 |
|
|
return err; |
46 |
|
|
f = fopen (fname, "wb"); |
47 |
|
|
if (f) { |
48 |
|
|
fwrite (ot_data, 1, strlen (ot_data), f); |
49 |
|
|
fclose (f); |
50 |
|
|
} |
51 |
|
|
else |
52 |
|
|
err = gpg_error_from_errno (errno); |
53 |
|
|
free (ot_data); |
54 |
|
|
return 0; |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
|
58 |
|
|
/* Import the ownertrust from file @fname. |
59 |
|
|
Return value: 0 on success. */ |
60 |
|
|
static gpgme_error_t |
61 |
|
|
gpg_import_ownertrust (const char *fname) |
62 |
|
|
{ |
63 |
|
|
gpgme_error_t err; |
64 |
|
|
FILE *f; |
65 |
|
|
struct stat st; |
66 |
|
|
char *ot_data; |
67 |
|
|
|
68 |
|
|
if (stat (fname, &st)) |
69 |
|
|
return gpg_error_from_errno (errno); |
70 |
|
|
f = fopen (fname, "rb"); |
71 |
|
|
if (!f) |
72 |
|
|
return gpg_error_from_errno (errno); |
73 |
|
|
ot_data = (char*)calloc (1, st.st_size+1); |
74 |
|
|
if (!ot_data) |
75 |
|
|
BUG (NULL); |
76 |
|
|
fread (ot_data, 1, st.st_size, f); |
77 |
|
|
fclose (f); |
78 |
|
|
|
79 |
|
|
err = gpg_manage_ownertrust (&ot_data, 0); |
80 |
|
|
|
81 |
|
|
free (ot_data); |
82 |
|
|
return 0; |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
|
86 |
|
|
/* Dialog procedure to manage the ownertrust. */ |
87 |
twoaday |
2 |
BOOL CALLBACK |
88 |
twoaday |
23 |
ownertrust_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
89 |
twoaday |
2 |
{ |
90 |
|
|
gpgme_error_t err; |
91 |
|
|
char fname[256]; |
92 |
|
|
|
93 |
|
|
switch( msg ) { |
94 |
|
|
case WM_INITDIALOG: |
95 |
twoaday |
23 |
#ifndef LANG_DE |
96 |
twoaday |
2 |
SetWindowText( dlg, _("Ownertrust") ); |
97 |
|
|
SetDlgItemText( dlg, IDC_OWNERTRUST_INFO, _("File") ); |
98 |
|
|
SetDlgItemText( dlg, IDC_OWNERTRUST_DESC, |
99 |
|
|
_("Here it is possible to save or restore the ownertrust from the " |
100 |
|
|
"'trustdb' file. This could be very useful because the values are NOT " |
101 |
|
|
"stored in the keyring.") ); |
102 |
twoaday |
23 |
#endif |
103 |
|
|
center_window( dlg, NULL ); |
104 |
twoaday |
2 |
SetForegroundWindow( dlg ); |
105 |
|
|
return TRUE; |
106 |
|
|
|
107 |
|
|
case WM_SYSCOMMAND: |
108 |
|
|
if( LOWORD (wparam) == SC_CLOSE ) |
109 |
|
|
EndDialog( dlg, TRUE ); |
110 |
|
|
return FALSE; |
111 |
|
|
|
112 |
|
|
case WM_COMMAND: |
113 |
|
|
switch ( LOWORD( wparam ) ) { |
114 |
|
|
case IDC_OWNERTRUST_SELFILE: |
115 |
|
|
const char * s; |
116 |
twoaday |
23 |
s = get_filename_dlg (dlg, 1, _("Please select a filename"), NULL, NULL); |
117 |
|
|
if (s && *s) |
118 |
|
|
SetDlgItemText (dlg, IDC_OWNERTRUST_FILE, s); |
119 |
twoaday |
2 |
break; |
120 |
|
|
|
121 |
|
|
case IDC_OWNERTRUST_EXPORT: |
122 |
|
|
if( !GetDlgItemText( dlg, IDC_OWNERTRUST_FILE, fname, sizeof fname -1 ) ) { |
123 |
|
|
msg_box( dlg, _("Please enter the filename."), _("Ownertrust"), MB_ERR ); |
124 |
|
|
return FALSE; |
125 |
|
|
} |
126 |
twoaday |
23 |
err = gpg_export_ownertrust (fname); |
127 |
twoaday |
2 |
if( err ) { |
128 |
|
|
msg_box( dlg, gpgme_strerror( err ), _("Ownertrust"), MB_ERR ); |
129 |
|
|
return FALSE; |
130 |
|
|
} |
131 |
|
|
status_box( dlg, _("Ownertrust successfully exported."), _("GnuPG Status") ); |
132 |
|
|
EndDialog( dlg, TRUE ); |
133 |
|
|
return TRUE; |
134 |
|
|
|
135 |
|
|
case IDC_OWNERTRUST_IMPORT: |
136 |
|
|
if( !GetDlgItemText( dlg, IDC_OWNERTRUST_FILE, fname, sizeof fname-1 ) ) { |
137 |
|
|
msg_box( dlg, _("Please enter the filename."), _("Ownertrust"), MB_ERR ); |
138 |
|
|
return FALSE; |
139 |
|
|
} |
140 |
twoaday |
23 |
err = gpg_import_ownertrust( fname ); |
141 |
twoaday |
2 |
if( err ) { |
142 |
|
|
msg_box( dlg, gpgme_strerror( err ), _("Ownertrust"), MB_ERR ); |
143 |
|
|
return FALSE; |
144 |
|
|
} |
145 |
|
|
status_box( dlg, _("Ownertrust succefully imported."), _("GnuPG Status") ); |
146 |
|
|
EndDialog( dlg, TRUE ); |
147 |
|
|
return TRUE; |
148 |
|
|
|
149 |
|
|
case IDCANCEL: |
150 |
|
|
EndDialog( dlg, FALSE ); |
151 |
|
|
return FALSE; |
152 |
|
|
} |
153 |
|
|
break; |
154 |
|
|
} |
155 |
|
|
|
156 |
|
|
return FALSE; |
157 |
twoaday |
23 |
} |
158 |
|
|
|