Added pinentry's password quality meter support. Requires cracklib2
[pwmd.git] / src / common.h
blob071df0ba702b66626ffbdedf83a8393b78caa983
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 struct {
52 size_t len;
53 void *buf;
54 } membuf_t;
56 typedef enum {
57 PINENTRY_NONE,
58 PINENTRY_INIT,
59 PINENTRY_PID,
60 PINENTRY_RUNNING,
61 PINENTRY_TIMEOUT
62 } pinentry_status_t;
64 typedef struct {
65 gint fd;
66 gpg_error_t error;
67 pinentry_status_t status;
68 union {
69 gchar key[ASSUAN_LINELENGTH];
70 pid_t pid;
71 } what;
72 } pinentry_key_s;
74 enum {
75 PINENTRY_OPEN,
76 PINENTRY_SAVE
79 typedef gpg_error_t (*pinentry_finalize_cb)(assuan_context_t, guchar *, gboolean);
81 struct pinentry_s {
82 pth_t tid;
83 pth_mutex_t status_mutex;
84 pth_event_t ev;
85 gint which;
86 gchar *filename;
87 assuan_context_t ctx;
88 pinentry_finalize_cb cb;
89 pid_t pid;
90 pid_t pin_pid;
91 gint fd;
92 pinentry_status_t status;
93 gchar *title;
94 gchar *desc;
95 gchar *prompt;
96 gchar *ttyname;
97 gchar *ttytype;
98 gchar *display;
99 gchar *path;
100 gint timeout;
101 gboolean has_lock;
102 gint enable;
103 membuf_t data;
104 int (*inquire_cb)(void *data, const char *line);
105 void *inquire_data;
107 #endif
109 typedef struct {
110 gint iter;
111 guchar iv[16]; /* FIXME: is this portable? */
112 } file_header_t;
114 struct client_thread_s {
115 pth_t tid;
116 gint fd;
117 pth_msgport_t msg;
118 gchar *msg_name;
119 struct client_s *cl;
122 struct client_s {
123 assuan_context_t ctx;
124 #ifdef WITH_PINENTRY
125 struct pinentry_s *pinentry;
126 #endif
127 gint fd;
128 gpointer doc; /* xmlDocPtr */
129 gpointer xml_error;
130 gpointer xml;
131 gint len;
132 gint state;
133 gcry_cipher_hd_t gh;
134 gchar *filename;
135 guchar md5file[16];
136 gboolean new;
137 gboolean freed;
138 time_t mtime;
139 gboolean has_lock;
140 gboolean is_lock_cmd;
141 inquire_status_t inquire_status;
142 struct client_thread_s *thd;
145 gsize gcrykeysize, gcryblocksize;
146 GKeyFile *keyfileh;
147 gboolean log_syslog;
148 gint zlib_bufsize;
150 void log_write(const gchar *fmt, ...);
151 gpg_error_t send_error(assuan_context_t ctx, gpg_error_t pwmd_errno);
152 gpg_error_t send_syserror(assuan_context_t ctx, int e);
153 gint open_file(const gchar *filename, struct stat *st);
154 gpg_error_t do_xml_encrypt(struct client_s *client, gcry_cipher_hd_t gh,
155 const gchar *filename, gpointer data, size_t insize, guchar *shakey,
156 gint iter);
157 gint get_key_file_integer(const gchar *section, const gchar *what);
158 gboolean get_key_file_boolean(const gchar *section, const gchar *what);
159 gchar *get_key_file_string(const gchar *section, const gchar *what);
160 gchar *expand_homedir(gchar *str);
161 void free_client(struct client_s *client);
162 gpg_error_t send_status(assuan_context_t ctx, status_msg_t which);
164 #endif