1 |
/* wptOwnertrust.cpp - Ownertrust im- and export |
/* wptOwnertrust.cpp - Ownertrust im- and export |
2 |
* Copyright (C) 2001, 2002, 2003 Timo Schulz |
* Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz |
3 |
|
* Copyright (C) 2005 g10 Code GmbH |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
6 |
* |
* |
20 |
*/ |
*/ |
21 |
|
|
22 |
#include <windows.h> |
#include <windows.h> |
23 |
|
#include <errno.h> |
24 |
|
#include <sys/stat.h> |
25 |
|
|
26 |
#include "../resource.h" |
#include "../resource.h" |
27 |
#include "wptTypes.h" |
#include "wptTypes.h" |
31 |
#include "wptW32API.h" |
#include "wptW32API.h" |
32 |
|
|
33 |
|
|
34 |
|
/* 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 |
BOOL CALLBACK |
BOOL CALLBACK |
88 |
ownertrust_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam ) |
ownertrust_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
89 |
{ |
{ |
90 |
gpgme_error_t err; |
gpgme_error_t err; |
91 |
char fname[256]; |
char fname[256]; |
92 |
|
|
93 |
switch( msg ) { |
switch( msg ) { |
94 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
95 |
#ifndef LANG_DE |
#ifndef LANG_DE |
96 |
SetWindowText( dlg, _("Ownertrust") ); |
SetWindowText( dlg, _("Ownertrust") ); |
97 |
SetDlgItemText( dlg, IDC_OWNERTRUST_INFO, _("File") ); |
SetDlgItemText( dlg, IDC_OWNERTRUST_INFO, _("File") ); |
98 |
SetDlgItemText( dlg, IDC_OWNERTRUST_DESC, |
SetDlgItemText( dlg, IDC_OWNERTRUST_DESC, |
99 |
_("Here it is possible to save or restore the ownertrust from the " |
_("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 " |
"'trustdb' file. This could be very useful because the values are NOT " |
101 |
"stored in the keyring.") ); |
"stored in the keyring.") ); |
102 |
#endif |
#endif |
103 |
center_window( dlg ); |
center_window( dlg, NULL ); |
104 |
SetForegroundWindow( dlg ); |
SetForegroundWindow( dlg ); |
105 |
return TRUE; |
return TRUE; |
106 |
|
|
113 |
switch ( LOWORD( wparam ) ) { |
switch ( LOWORD( wparam ) ) { |
114 |
case IDC_OWNERTRUST_SELFILE: |
case IDC_OWNERTRUST_SELFILE: |
115 |
const char * s; |
const char * s; |
116 |
s = get_filename_dlg( dlg, 1, _("Please select a filename"), NULL, NULL ); |
s = get_filename_dlg (dlg, 1, _("Please select a filename"), NULL, NULL); |
117 |
if( s && *s ) |
if (s && *s) |
118 |
SetDlgItemText( dlg, IDC_OWNERTRUST_FILE, s ); |
SetDlgItemText (dlg, IDC_OWNERTRUST_FILE, s); |
119 |
break; |
break; |
120 |
|
|
121 |
case IDC_OWNERTRUST_EXPORT: |
case IDC_OWNERTRUST_EXPORT: |
123 |
msg_box( dlg, _("Please enter the filename."), _("Ownertrust"), MB_ERR ); |
msg_box( dlg, _("Please enter the filename."), _("Ownertrust"), MB_ERR ); |
124 |
return FALSE; |
return FALSE; |
125 |
} |
} |
126 |
err = gpgme_op_ownertrust_export_file( fname ); |
err = gpg_export_ownertrust (fname); |
127 |
if( err ) { |
if( err ) { |
128 |
msg_box( dlg, gpgme_strerror( err ), _("Ownertrust"), MB_ERR ); |
msg_box( dlg, gpgme_strerror( err ), _("Ownertrust"), MB_ERR ); |
129 |
return FALSE; |
return FALSE; |
137 |
msg_box( dlg, _("Please enter the filename."), _("Ownertrust"), MB_ERR ); |
msg_box( dlg, _("Please enter the filename."), _("Ownertrust"), MB_ERR ); |
138 |
return FALSE; |
return FALSE; |
139 |
} |
} |
140 |
err = gpgme_op_ownertrust_import_file( fname ); |
err = gpg_import_ownertrust( fname ); |
141 |
if( err ) { |
if( err ) { |
142 |
msg_box( dlg, gpgme_strerror( err ), _("Ownertrust"), MB_ERR ); |
msg_box( dlg, gpgme_strerror( err ), _("Ownertrust"), MB_ERR ); |
143 |
return FALSE; |
return FALSE; |
154 |
} |
} |
155 |
|
|
156 |
return FALSE; |
return FALSE; |
157 |
} /* ownertrust_dlg_proc */ |
} |
158 |
|
|