1
#ifndef PMT_PAM_MOUNT_H
2
#define PMT_PAM_MOUNT_H 1
7
#include <libHX/list.h>
8
#include <libHX/option.h>
9
#include <libHX/string.h>
12
#ifdef HAVE_VISIBILITY_HIDDEN
13
# define EXPORT_SYMBOL __attribute__((visibility("default")))
15
# define EXPORT_SYMBOL
19
# define S_IRXG (S_IRGRP | S_IXGRP)
22
# define S_IRXO (S_IROTH | S_IXOTH)
24
#define sizeof_z(x) (sizeof(x) - 1)
27
* So many programs trash a useful $PATH (including mount(8)),
28
* so just provide our own.
30
#define PMT_DFL_PATH \
31
"/usr/local/libexec/hxtools:/usr/local/lib/hxtools:" \
32
"/usr/local/sbin:/usr/local/bin:" \
33
"/usr/libexec/hxtools:/usr/lib/hxtools:" \
34
"/usr/sbin:/usr/bin:/sbin:/bin"
35
#define PMT_DFL_DMCRYPT_CIPHER "aes-cbc-essiv:sha256"
36
#define PMT_DFL_FSK_CIPHER "aes-256-cbc"
37
#define PMT_DFL_FSK_HASH "sha1"
39
/* Note that you will also need to change PMPREFIX in pmvarrun.c then! */
40
#define l0g(fmt, ...) \
41
misc_log(("%s(%s:%u): " fmt), pmtlog_prefix, HX_basename(__FILE__), \
42
__LINE__, ## __VA_ARGS__)
43
#define w4rn(fmt, ...) \
44
misc_warn(("%s(%s:%u): " fmt), pmtlog_prefix, HX_basename(__FILE__), \
45
__LINE__, ## __VA_ARGS__)
94
struct HXlist_head list;
95
enum command_type type;
96
/* true if configuration from global config, false if luserconf */
98
/* set, so that umount can rmdir it */
100
/* expansion already took place */
102
/* was handed off to mount_op() */
105
char *fstype, *server, *volume, *mountpoint, *cipher;
106
char *fs_key_cipher, *fs_key_hash, *fs_key_path;
107
/* May be NULL if no options */
108
struct HXclist_head options;
115
* @sig_hup: send SIGHUP to processes keeping mountpoint open
116
* @sig_term: send SIGTERM - " -
117
* @sig_kill: send SIGKILL - " -
118
* @sig_wait: wait this many seconds between sending signals,
122
/* user logging in */
125
bool mkmntpoint, rmdir_mntpt;
126
bool seen_mntoptions_require, seen_mntoptions_allow;
128
struct HXdeque *command[_CMD_MAX];
129
struct HXmap *options_require, *options_allow, *options_deny;
130
struct HXclist_head volume_list;
132
char *msg_authpw, *msg_sessionpw, *path;
134
bool sig_hup, sig_term, sig_kill;
135
unsigned int sig_wait;
140
struct HXlist_head list;
144
* struct ehd_request - mapping and mount request for EHD
145
* @mountpoint: where to mount EHD
146
* @fs_cipher: cipher used for filesystem (cryptsetup name)
147
* @fs_hash: hash used for filesystem (cryptsetup name)
148
* @container: path to disk image
149
* @key_data: key material
150
* @key_size: size of key data, in bytes
151
* @trunc_keysize: extra cryptsetup instruction for truncation (in bytes)
152
* @readonly: create readonly mount?
155
const char *mountpoint;
156
const char *fs_cipher, *fs_hash, *container;
157
const void *key_data;
158
unsigned int key_size, trunc_keysize;
163
* struct ehd_mount - EHD mount info
164
* @container: path to disk image
165
* @lower_device: link to either @container if a block device,
166
* otherwise points to @loop_device.
167
* @loop_device: loop device that was created, if any
168
* @crypto_name: crypto device that was created (basename only)
169
* @crypto_device: full path to the crypto device
173
const char *lower_device;
176
hxmc_t *crypto_device;
179
struct ehd_crypto_ops {
180
int (*load)(const struct ehd_mtreq *, struct ehd_mount *);
181
int (*unload)(const struct ehd_mount *);
184
typedef int (mount_op_fn_t)(const struct config *, struct vol *,
185
struct HXformat_map *, const char *);
190
static inline void format_add(struct HXformat_map *table, const char *key,
194
HXformat_add(table, key, "", HXTYPE_STRING);
196
HXformat_add(table, key, value, HXTYPE_STRING | HXFORMAT_IMMED);
199
static inline const char *znul(const char *s)
201
return (s == NULL) ? "(null)" : s;
207
extern int ehd_load(const struct ehd_mtreq *, struct ehd_mount *);
208
extern int ehd_unload(const struct ehd_mount *);
209
extern void ehd_mtfree(struct ehd_mount *);
210
extern hxmc_t *ehd_decrypt_key(const char *, const char *, const char *,
212
extern unsigned int cipher_digest_security(const char *);
213
extern hxmc_t *pmt_get_password(const char *);
218
extern const struct ehd_crypto_ops ehd_cgd_ops;
219
extern const struct ehd_crypto_ops ehd_dmcrypt_ops;
221
extern int dmc_is_luks(const char *, bool);
226
extern size_t pmt_block_getsize64(const char *);
227
extern int pmt_loop_setup(const char *, char **, bool);
228
extern int pmt_loop_release(const char *);
233
extern const char *pmtlog_prefix;
234
extern bool pmtlog_path[PMTLOG_SRCMAX][PMTLOG_DSTMAX];
236
extern int misc_log(const char *, ...);
237
extern int misc_warn(const char *, ...);
242
extern void arglist_add(struct HXdeque *, const char *,
243
const struct HXformat_map *);
244
extern struct HXdeque *arglist_build(const struct HXdeque *,
245
const struct HXformat_map *);
246
extern void arglist_log(const struct HXdeque *);
247
extern void arglist_llog(const char *const *);
248
extern bool kvplist_contains(const struct HXclist_head *, const char *);
249
extern char *kvplist_get(const struct HXclist_head *, const char *);
250
extern void kvplist_genocide(struct HXclist_head *);
251
extern hxmc_t *kvplist_to_str(const struct HXclist_head *);
252
extern void misc_add_ntdom(struct HXformat_map *, const char *);
253
extern void misc_dump_id(const char *);
254
extern int pmt_fileop_exists(const char *);
255
extern int pmt_fileop_owns(const char *, const char *);
256
extern char *relookup_user(const char *);
257
extern long str_to_long(const char *);
258
extern void *xmalloc(size_t);
259
extern void *xrealloc(void *, size_t);
260
extern char *xstrdup(const char *);
265
/* Enum constants must match order of /etc/mtab and /etc/cmtab, respectively. */
267
SMTABF_CONTAINER = 0,
273
CMTABF_MOUNTPOINT = 0,
280
extern int pmt_smtab_add(const char *, const char *,
281
const char *, const char *);
282
extern int pmt_smtab_remove(const char *, enum smtab_field);
283
extern int pmt_smtab_mounted(const char *, const char *,
284
int (*)(const char *, const char *));
285
extern int pmt_cmtab_add(const char *, const char *,
286
const char *, const char *);
287
extern int pmt_cmtab_get(const char *, enum cmtab_field,
288
char **, char **, char **, char **);
289
extern int pmt_cmtab_remove(const char *, enum cmtab_field);
290
extern int pmt_cmtab_mounted(const char *, const char *);
295
extern mount_op_fn_t do_mount, do_unmount;
296
extern int fstype_nodev(const char *);
297
extern int mount_op(mount_op_fn_t *, const struct config *, struct vol *,
299
extern void umount_final(struct config *);
300
extern int pmt_already_mounted(const struct config *,
301
const struct vol *, struct HXformat_map *);
302
extern hxmc_t *pmt_vol_to_dev(const struct vol *);
303
extern bool fstype_icase(const char *);
304
extern bool fstype2_icase(enum command_type);
309
extern int (*ofl_printf)(const char *, ...);
310
extern bool ofl(const char *, unsigned int);
315
#ifndef HAVE_VISIBILITY_HIDDEN
316
/* Workaround Xserver issue */
317
# define Debug pmt_debug
319
extern unsigned int Debug;
320
extern struct config Config;
325
extern bool expandconfig(const struct config *);
326
extern void initconfig(struct config *);
327
extern bool readconfig(const char *, bool, struct config *);
328
extern void freeconfig(struct config *);
333
extern bool luserconf_volume_record_sane(const struct config *, const struct vol *);
334
extern bool volume_record_sane(const struct config *, const struct vol *);
339
extern const struct HXproc_ops pmt_spawn_ops, pmt_dropprivs_ops;
341
extern int pmt_spawn_dq(struct HXdeque *, struct HXproc *);
343
#endif /* PMT_PAM_MOUNT_H */