Added ssh-agent support. Enable with PWMD_OPTION_SSH_AGENT.
[libpwmd.git] / src / types.h
blob18069ed718a6569b69642997fa9f4caa8fb47614
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 #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 #endif
50 #define N_ARRAY(a) (sizeof(a)/sizeof(a[0]))
52 typedef enum {
53 ASYNC_CMD_NONE,
54 #ifdef WITH_TCP
55 ASYNC_CMD_DNS,
56 ASYNC_CMD_CONNECT,
57 ASYNC_CMD_HOSTKEY,
58 #endif
59 ASYNC_CMD_OPEN,
60 ASYNC_CMD_OPEN2,
61 ASYNC_CMD_SAVE,
62 ASYNC_CMD_SAVE2,
63 } pwmd_async_cmd_t;
65 #ifdef WITH_TCP
66 typedef enum {
67 SSH_RESUME = -1,
68 SSH_NONE,
69 SSH_INIT,
70 SSH_AUTHLIST,
71 SSH_AUTH,
72 SSH_AGENT,
73 SSH_CHANNEL,
74 SSH_SHELL
75 } pwmd_ssh_async_t;
77 typedef struct {
78 char *host;
79 unsigned port;
80 char *username;
81 char *known_hosts;
82 char *identity;
83 char *identity_pub;
84 int fd;
85 gpg_error_t rc;
86 ares_channel chan;
87 int async;
88 struct in_addr addr;
89 int addrtype;
90 LIBSSH2_SESSION *session;
91 LIBSSH2_CHANNEL *channel;
92 LIBSSH2_KNOWNHOSTS *kh;
93 LIBSSH2_AGENT *agent;
94 struct libssh2_agent_publickey *agent_identity;
95 struct libssh2_agent_publickey *agent_identity_prev;
96 struct libssh2_knownhost *hostent;
97 struct libssh2_knownhost *hostent_ip;
98 char *hostkey;
99 pwmd_async_cmd_t cmd;
100 pwmd_ssh_async_t state;
101 } pwmd_tcp_conn_t;
102 #endif
104 #define OPT_LOCK_ON_OPEN 0x01
105 #define OPT_BASE64 0x02
107 struct pwm_s {
108 assuan_context_t ctx;
109 #ifdef WITH_TCP
110 pwmd_tcp_conn_t *tcp_conn;
111 pwmd_ip_version_t prot;
112 pwmd_knownhost_cb_t kh_cb;
113 void *kh_data;
114 int use_agent;
115 #endif
116 int fd;
117 pwmd_async_t state;
118 pwmd_async_cmd_t cmd;
119 pwmd_async_cmd_t lastcmd;
120 char *result; // not related to anything the client can see.
121 #ifdef WITH_PINENTRY
122 pid_t pid; // for pinentry timeouts when used with ..async2().
123 assuan_context_t pctx;
124 int nb_fd; // for pwmd_open/save_async2().
125 pid_t nb_pid;
126 char *_password;
127 #endif
128 int pinentry_tries;
129 int pin_try;
130 char *pinentry_path;
131 char *pinentry_tty;
132 char *pinentry_term;
133 char *pinentry_display;
134 char *lcctype;
135 char *lcmessages;
136 char *title;
137 char *prompt;
138 char *desc;
139 char *password;
140 char *filename;
141 int pinentry_timeout;
142 pwmd_passphrase_cb_t passfunc;
143 void *passdata;
144 pwmd_status_cb_t status_func;
145 void *status_data;
146 pwmd_inquire_cb_t inquire_func;
147 void *inquire_data;
148 size_t inquire_total;
149 size_t inquire_sent;
150 #ifdef WITH_QUALITY
151 int (*_inquire_func)(void *, const char *);
152 void *_inquire_data;
153 #endif
154 char *name;
155 char *cipher;
156 long iterations;
157 unsigned opts;
160 typedef struct {
161 size_t len;
162 void *buf;
163 } membuf_t;
165 typedef struct {
166 int fd;
167 gpg_error_t error;
168 char password[ASSUAN_LINELENGTH+1];
169 } pwmd_nb_status_t;
171 gpg_error_t _assuan_command(pwm_t *pwm, assuan_context_t ctx,
172 char **result, const char *cmd)
173 __attribute__ ((visibility ("hidden")));
175 gpg_error_t _connect_finalize(pwm_t *pwm)
176 __attribute__ ((visibility ("hidden")));
178 #endif