Commit 1b59e7d contained a typo that didn't really fix pwmd_command().
[libpwmd.git] / src / types.h
blobfdce6cf937dcdee1630b49e06e8ccfed2eb4dc9a
1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
2 /*
3 Copyright (C) 2006-2009 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
19 #ifndef TYPES_H
20 #define TYPES_H
22 #include <assuan.h>
24 #ifdef WITH_TCP
25 #include <libssh2.h>
26 #endif
28 #define N_ARRAY(a) (sizeof(a)/sizeof(a[0]))
30 typedef enum {
31 ASYNC_CMD_NONE,
32 #ifdef WITH_TCP
33 ASYNC_CMD_DNS,
34 ASYNC_CMD_CONNECT,
35 ASYNC_CMD_HOSTKEY,
36 #endif
37 ASYNC_CMD_OPEN,
38 ASYNC_CMD_OPEN2,
39 ASYNC_CMD_SAVE,
40 ASYNC_CMD_SAVE2,
41 } pwmd_async_cmd_t;
43 enum {
44 PINENTRY_OPEN,
45 PINENTRY_OPEN_FAILED,
46 PINENTRY_SAVE,
47 PINENTRY_SAVE_CONFIRM
50 #ifdef WITH_TCP
51 typedef struct {
52 char *host;
53 unsigned port;
54 char *username;
55 char *known_hosts;
56 char *identity;
57 char *identity_pub;
58 int fd;
59 gpg_error_t rc;
60 ares_channel chan;
61 int async;
62 struct hostent *he;
63 LIBSSH2_SESSION *session;
64 LIBSSH2_CHANNEL *channel;
65 int get_only;
66 char *hostkey;
67 pwmd_async_cmd_t cmd;
68 } pwmd_tcp_conn_t;
69 #endif
71 enum {
72 PWMD_V1,
73 PWMD_V2
76 struct pwm_s {
77 assuan_context_t ctx;
78 int version;
79 #ifdef WITH_TCP
80 pwmd_tcp_conn_t *tcp_conn;
81 pwmd_ip_version_t prot;
82 #endif
83 int fd;
84 pwmd_async_t state;
85 pwmd_async_cmd_t cmd;
86 char *result; // not related to anything the client can see.
87 #ifdef WITH_PINENTRY
88 pid_t pid; // for pinentry timeouts when used with ..async2().
89 assuan_context_t pctx;
90 int nb_fd; // for pwmd_open/save_async2().
91 pid_t nb_pid;
92 #endif
93 int pinentry_tries;
94 int pin_try;
95 char *pinentry_path;
96 char *pinentry_tty;
97 char *pinentry_term;
98 char *pinentry_display;
99 char *lcctype;
100 char *lcmessages;
101 char *title;
102 char *prompt;
103 char *desc;
104 char *password;
105 char *filename;
106 int pinentry_timeout;
107 pwmd_passphrase_cb_t passfunc;
108 void *passdata;
109 pwmd_status_cb_t status_func;
110 void *status_data;
111 pwmd_inquire_cb_t inquire_func;
112 void *inquire_data;
113 char *name;
116 typedef struct {
117 size_t len;
118 void *buf;
119 } membuf_t;
121 typedef struct {
122 int fd;
123 gpg_error_t error;
124 char password[ASSUAN_LINELENGTH+1];
125 } pwmd_nb_status_t;
127 static gpg_error_t assuan_command(pwm_t *pwm, assuan_context_t ctx,
128 char **result, const char *cmd);
129 static gpg_error_t do_open_command(pwm_t *pwm, const char *filename, char *password);
130 static gpg_error_t do_save_command(pwm_t *pwm, char *password);
131 static gpg_error_t send_pinentry_options(pwm_t *pwm);
133 #ifdef WITH_PINENTRY
134 static pwm_t *gpwm;
135 static int gelapsed, gtimeout;
136 static gpg_error_t gerror;
137 static gpg_error_t pinentry_command(pwm_t *pwm, char **result, const char *cmd);
138 #endif
140 #endif