1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
3 Copyright (C) 2006-2011 Ben Kibbey <bjk@luxsci.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02110-1301 USA
22 #include <sys/types.h>
26 #include <glib/gi18n.h>
28 #define _ASSUAN_ONLY_GPG_ERRORS 1
66 pinentry_status_t status
;
68 gchar key
[ASSUAN_LINELENGTH
];
73 typedef gpg_error_t (*pinentry_finalize_cb
)(assuan_context_t
, guchar
*, gboolean
);
77 pth_mutex_t status_mutex
;
78 pth_mutex_t cond_mutex
;
83 pinentry_finalize_cb cb
;
87 pinentry_status_t status
;
102 assuan_error_t (*inquire_cb
)(void *data
, const char *line
);
128 file_header_v1_t fh1
;
131 } file_header_internal_t
;
133 struct client_thread_s
{
137 pth_mutex_t mp_mutex
;
142 struct assuan_cmd_s
{
143 assuan_context_t ctx
;
149 /* For use with .flags in the data file header. */
150 #define PWMD_CIPHER_OFFSET (1)
151 #define PWMD_CIPHER(n) (PWMD_CIPHER_OFFSET << n)
152 #define PWMD_CIPHER_AES128 PWMD_CIPHER(0)
153 #define PWMD_CIPHER_AES192 PWMD_CIPHER(1)
154 #define PWMD_CIPHER_AES256 PWMD_CIPHER(2)
155 #define PWMD_CIPHER_SERPENT128 PWMD_CIPHER(3)
156 #define PWMD_CIPHER_SERPENT192 PWMD_CIPHER(4)
157 #define PWMD_CIPHER_SERPENT256 PWMD_CIPHER(5)
158 #define PWMD_CIPHER_CAMELLIA128 PWMD_CIPHER(6)
159 #define PWMD_CIPHER_CAMELLIA192 PWMD_CIPHER(7)
160 #define PWMD_CIPHER_CAMELLIA256 PWMD_CIPHER(8)
161 #define PWMD_CIPHER_3DES PWMD_CIPHER(9)
162 #define PWMD_CIPHER_CAST5 PWMD_CIPHER(10)
163 #define PWMD_CIPHER_BLOWFISH PWMD_CIPHER(11)
164 #define PWMD_CIPHER_TWOFISH PWMD_CIPHER(12)
165 #define PWMD_CIPHER_TWOFISH128 PWMD_CIPHER(13)
167 #define PWMD_FLAG_OFFSET (1<<15)
168 #define PWMD_FLAG(n) (PWMD_FLAG_OFFSET << n)
181 file_header_internal_t
*fh
;
187 /* These are flags that are set by a client option via the SET command. */
188 #define OPT_ITERATIONS 0x1
189 #define OPT_PINENTRY 0x2
190 #define OPT_PINENTRY_TO 0x4
191 #define OPT_CIPHER 0x8
192 #define OPT_LOCK 0x10
193 #define OPT_INQUIRE 0x20
194 #define OPT_BASE64 0x40
197 assuan_context_t ctx
;
199 struct pinentry_s
*pinentry
;
201 gpointer doc
; /* xmlDocPtr */
212 gboolean is_lock_cmd
;
213 inquire_status_t inquire_status
;
214 struct client_thread_s
*thd
;
215 struct crypto_s
*crypto
;
218 gboolean lock_on_open
;
219 gboolean rc_on_locked
;
225 pth_mutex_t rcfile_mutex
;
226 pth_mutex_t cn_mutex
;
227 GSList
*cn_thread_list
;
229 void log_write(const gchar
*fmt
, ...);
230 gpg_error_t
send_error(assuan_context_t ctx
, gpg_error_t e
);
231 gint
open_file(const gchar
*filename
, struct stat
*st
);
232 gpg_error_t
do_xml_encrypt(struct client_s
*client
, struct crypto_s
*,
233 const gchar
*filename
);
234 gint
get_key_file_integer(const gchar
*section
, const gchar
*what
);
235 gdouble
get_key_file_double(const gchar
*section
, const gchar
*what
);
236 gboolean
get_key_file_boolean(const gchar
*section
, const gchar
*what
);
237 gchar
*get_key_file_string(const gchar
*section
, const gchar
*what
);
238 gchar
*expand_homedir(gchar
*str
);
239 void free_client(struct client_s
*client
);
240 void cleanup_crypto(struct crypto_s
**);
241 struct crypto_s
*init_client_crypto();
242 gpg_error_t
init_client_crypto2(const char *filename
,
243 struct crypto_s
*crypto
);
244 gpg_error_t
do_assuan_command(assuan_context_t ctx
,
245 void *(*cb
)(void *data
), void *data
);
246 void close_file_header(file_header_internal_t
*fh
);
247 void cleanup_ev_cb(void *arg
);
248 void cleanup_mutex_cb(void *arg
);
249 void cleanup_fd_cb(void *arg
);
250 void cleanup_unlink_cb(void *arg
);
251 void cleanup_attr_cb(void *arg
);
252 void cleanup_cancel_cb(void *arg
);
253 guint
pwmd_cipher_str_to_cipher(const gchar
*str
);
254 const gchar
*pwmd_cipher_to_str(guint64 flags
);
255 file_header_internal_t
*read_file_header(const gchar
*filename
, gboolean v1
,