Updated the FSF address in the copyright header.
[pwmd.git] / src / common.h
blobedadcc2659688c2961c8bc0f4c20b2582cf086f9
1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
2 /*
3 Copyright (C) 2006-2008 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 COMMON_H
20 #define COMMON_H
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <pth.h>
25 #include "status.h"
27 #define _ASSUAN_ONLY_GPG_ERRORS 1
28 #include <assuan.h>
30 #ifdef ENABLE_NLS
31 #ifdef HAVE_LOCALE_H
32 #include <locale.h>
33 #endif
34 #endif
36 #include "gettext.h"
37 #define N_(msgid) gettext(msgid)
39 enum {
40 STATE_CONNECTED,
41 STATE_OPEN
44 typedef enum {
45 INQUIRE_INIT,
46 INQUIRE_BUSY,
47 INQUIRE_DONE
48 } inquire_status_t;
50 #ifdef WITH_PINENTRY
51 typedef enum {
52 PINENTRY_NONE,
53 PINENTRY_INIT,
54 PINENTRY_PID,
55 PINENTRY_RUNNING,
56 PINENTRY_TIMEOUT
57 } pinentry_status_t;
59 typedef struct {
60 gint fd;
61 gpg_error_t error;
62 pinentry_status_t status;
63 union {
64 gchar key[ASSUAN_LINELENGTH];
65 pid_t pid;
66 } what;
67 } pinentry_key_s;
69 enum {
70 PINENTRY_OPEN,
71 PINENTRY_SAVE
74 typedef gpg_error_t (*pinentry_finalize_cb)(assuan_context_t, guchar *, gboolean);
76 struct pinentry_s {
77 pth_t tid;
78 pth_mutex_t status_mutex;
79 pth_event_t ev;
80 gint which;
81 gchar *filename;
82 assuan_context_t ctx;
83 pinentry_finalize_cb cb;
84 pid_t pid;
85 pid_t pin_pid;
86 gint fd;
87 pinentry_status_t status;
88 gchar *title;
89 gchar *desc;
90 gchar *prompt;
91 gchar *ttyname;
92 gchar *ttytype;
93 gchar *display;
94 gchar *path;
95 gint timeout;
96 gboolean has_lock;
97 gint enable;
99 #endif
101 typedef struct {
102 gint iter;
103 guchar iv[16]; /* FIXME: is this portable? */
104 } file_header_t;
106 struct client_thread_s {
107 pth_t tid;
108 gint fd;
109 pth_msgport_t msg;
110 gchar *msg_name;
111 struct client_s *cl;
114 struct client_s {
115 assuan_context_t ctx;
116 #ifdef WITH_PINENTRY
117 struct pinentry_s *pinentry;
118 #endif
119 gint fd;
120 gpointer doc; /* xmlDocPtr */
121 gpointer xml_error;
122 gpointer xml;
123 gint len;
124 gint state;
125 gcry_cipher_hd_t gh;
126 gchar *filename;
127 guchar md5file[16];
128 gboolean new;
129 gboolean freed;
130 time_t mtime;
131 gboolean has_lock;
132 gboolean is_lock_cmd;
133 inquire_status_t inquire_status;
134 struct client_thread_s *thd;
137 gsize gcrykeysize, gcryblocksize;
138 GKeyFile *keyfileh;
139 gboolean log_syslog;
140 gint zlib_bufsize;
142 void log_write(const gchar *fmt, ...);
143 gpg_error_t send_error(assuan_context_t ctx, gpg_error_t pwmd_errno);
144 gpg_error_t send_syserror(assuan_context_t ctx, int e);
145 gint open_file(const gchar *filename, struct stat *st);
146 gpg_error_t do_xml_encrypt(struct client_s *client, gcry_cipher_hd_t gh,
147 const gchar *filename, gpointer data, size_t insize, guchar *shakey,
148 gint iter);
149 gint get_key_file_integer(const gchar *section, const gchar *what);
150 gboolean get_key_file_boolean(const gchar *section, const gchar *what);
151 gchar *get_key_file_string(const gchar *section, const gchar *what);
152 gchar *expand_homedir(gchar *str);
153 void free_client(struct client_s *client);
154 gpg_error_t send_status(assuan_context_t ctx, status_msg_t which);
156 #endif