Fixed a segfault during an SSH connection failure.
[libpwmd.git] / src / types.h
blob0bbe3fc50d76b5e778fdc621f15de02edff3cce3
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>
23 #include <libpwmd.h>
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
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 enum {
66 PINENTRY_OPEN,
67 PINENTRY_OPEN_FAILED,
68 PINENTRY_SAVE,
69 PINENTRY_SAVE_CONFIRM
72 #ifdef WITH_TCP
73 typedef struct {
74 char *host;
75 unsigned port;
76 char *username;
77 char *known_hosts;
78 char *identity;
79 char *identity_pub;
80 int fd;
81 gpg_error_t rc;
82 ares_channel chan;
83 int async;
84 struct hostent *he;
85 LIBSSH2_SESSION *session;
86 LIBSSH2_CHANNEL *channel;
87 char *hostkey;
88 pwmd_async_cmd_t cmd;
89 } pwmd_tcp_conn_t;
90 #endif
92 enum {
93 PWMD_V1,
94 PWMD_V2
97 struct pwm_s {
98 assuan_context_t ctx;
99 int version;
100 #ifdef WITH_TCP
101 pwmd_tcp_conn_t *tcp_conn;
102 pwmd_ip_version_t prot;
103 #endif
104 int fd;
105 pwmd_async_t state;
106 pwmd_async_cmd_t cmd;
107 char *result; // not related to anything the client can see.
108 #ifdef WITH_PINENTRY
109 pid_t pid; // for pinentry timeouts when used with ..async2().
110 assuan_context_t pctx;
111 int nb_fd; // for pwmd_open/save_async2().
112 pid_t nb_pid;
113 char *_password;
114 #endif
115 int pinentry_tries;
116 int pin_try;
117 char *pinentry_path;
118 char *pinentry_tty;
119 char *pinentry_term;
120 char *pinentry_display;
121 char *lcctype;
122 char *lcmessages;
123 char *title;
124 char *prompt;
125 char *desc;
126 char *password;
127 char *filename;
128 int pinentry_timeout;
129 pwmd_passphrase_cb_t passfunc;
130 void *passdata;
131 pwmd_status_cb_t status_func;
132 void *status_data;
133 pwmd_inquire_cb_t inquire_func;
134 void *inquire_data;
135 char *name;
138 typedef struct {
139 size_t len;
140 void *buf;
141 } membuf_t;
143 typedef struct {
144 int fd;
145 gpg_error_t error;
146 char password[ASSUAN_LINELENGTH+1];
147 } pwmd_nb_status_t;
149 gpg_error_t _assuan_command(pwm_t *pwm, assuan_context_t ctx,
150 char **result, const char *cmd)
151 __attribute__ ((visibility ("hidden")));
153 gpg_error_t _connect_finalize(pwm_t *pwm)
154 __attribute__ ((visibility ("hidden")));
156 #endif