pwmc: always save with the keyfile as key material.
[libpwmd.git] / src / types.h
blob20bf37d88c1c8a983eb2d9683a29c479e34ec1ac
1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
2 /*
3 Copyright (C) 2006-2010 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 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
26 #include <assuan.h>
27 #include <libpwmd.h>
29 #ifdef WITH_TCP
30 #include <libssh2.h>
31 #ifndef DNS_USE_GETTIMEOFDAY_FOR_ID
32 #define DNS_USE_GETTIMEOFDAY_FOR_ID 1
33 #endif
34 #include <ares.h>
35 #include <arpa/nameser.h>
36 #endif
38 #ifdef WITH_LIBPTH
39 #include <pth.h>
40 #endif
42 #ifdef ENABLE_NLS
43 #ifdef HAVE_SETLOCALE
44 #include <locale.h>
45 #endif
46 #include "gettext.h"
47 #define N_(msgid) dgettext("libpwmd", msgid)
48 #else
49 #define N_(msgid) (msgid)
50 #endif
52 #define N_ARRAY(a) (sizeof(a)/sizeof(a[0]))
54 typedef enum {
55 ASYNC_CMD_NONE,
56 #ifdef WITH_TCP
57 ASYNC_CMD_DNS,
58 ASYNC_CMD_CONNECT,
59 ASYNC_CMD_HOSTKEY,
60 #endif
61 ASYNC_CMD_OPEN,
62 ASYNC_CMD_OPEN2,
63 ASYNC_CMD_SAVE,
64 ASYNC_CMD_SAVE2,
65 } pwmd_async_cmd_t;
67 #ifdef WITH_TCP
68 typedef enum {
69 SSH_RESUME = -1,
70 SSH_NONE,
71 SSH_INIT,
72 SSH_AUTHLIST,
73 SSH_AUTH,
74 SSH_AGENT,
75 SSH_CHANNEL,
76 SSH_SHELL
77 } pwmd_ssh_async_t;
79 typedef struct {
80 char *host;
81 unsigned port;
82 char *username;
83 char *known_hosts;
84 char *identity;
85 char *identity_pub;
86 int fd;
87 gpg_error_t rc;
88 ares_channel chan;
89 int async;
90 struct in_addr addr;
91 int addrtype;
92 LIBSSH2_SESSION *session;
93 LIBSSH2_CHANNEL *channel;
94 LIBSSH2_KNOWNHOSTS *kh;
95 LIBSSH2_AGENT *agent;
96 struct libssh2_agent_publickey *agent_identity;
97 struct libssh2_agent_publickey *agent_identity_prev;
98 struct libssh2_knownhost *hostent;
99 struct libssh2_knownhost *hostent_ip;
100 char *hostkey;
101 pwmd_async_cmd_t cmd;
102 pwmd_ssh_async_t state;
103 } pwmd_tcp_conn_t;
104 #endif
106 #define OPT_LOCK_ON_OPEN 0x01
107 #define OPT_BASE64 0x02
109 struct pwm_s {
110 assuan_context_t ctx;
111 #ifdef WITH_TCP
112 pwmd_tcp_conn_t *tcp_conn;
113 pwmd_ip_version_t prot;
114 pwmd_knownhost_cb_t kh_cb;
115 void *kh_data;
116 int use_agent;
117 #endif
118 int fd;
119 pwmd_async_t state;
120 pwmd_async_cmd_t cmd;
121 pwmd_async_cmd_t lastcmd;
122 char *result; // not related to anything the client can see.
123 #ifdef WITH_PINENTRY
124 pid_t pid; // for pinentry timeouts when used with ..async2().
125 assuan_context_t pctx;
126 int nb_fd; // for pwmd_open/save_async2().
127 pid_t nb_pid;
128 char *_password;
129 #endif
130 int pinentry_tries;
131 int pin_try;
132 char *pinentry_path;
133 char *pinentry_tty;
134 char *pinentry_term;
135 char *pinentry_display;
136 char *lcctype;
137 char *lcmessages;
138 char *title;
139 char *prompt;
140 char *desc;
141 char *password;
142 char *filename;
143 int pinentry_timeout;
144 int disable_pinentry;
145 pwmd_passphrase_cb_t passfunc;
146 void *passdata;
147 pwmd_status_cb_t status_func;
148 void *status_data;
149 pwmd_inquire_cb_t inquire_func;
150 void *inquire_data;
151 size_t inquire_total;
152 size_t inquire_sent;
153 #ifdef WITH_QUALITY
154 int (*_inquire_func)(void *, const char *);
155 void *_inquire_data;
156 #endif
157 char *name;
158 char *cipher;
159 long iterations;
160 unsigned opts;
163 typedef struct {
164 size_t len;
165 void *buf;
166 } membuf_t;
168 typedef struct {
169 int fd;
170 gpg_error_t error;
171 char password[ASSUAN_LINELENGTH+1];
172 } pwmd_nb_status_t;
174 gpg_error_t _assuan_command(pwm_t *pwm, assuan_context_t ctx,
175 char **result, const char *cmd);
176 gpg_error_t _connect_finalize(pwm_t *pwm);
178 #endif