/
FileUtils.h
154 lines (123 loc) · 4.88 KB
/
FileUtils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*****************************************************************************
* Author: Valient Gough <vgough@pobox.com>
*
*****************************************************************************
* Copyright (c) 2004, Valient Gough
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _FileUtils_incl_
#define _FileUtils_incl_
#include <sys/types.h>
#include <memory>
#include <string>
#include "CipherKey.h"
#include "FSConfig.h"
#include "Interface.h"
#include "encfs.h"
// true if the path points to an existing node (of any type)
bool fileExists(const char *fileName);
// true if path is a directory
bool isDirectory(const char *fileName);
// true if starts with '/'
bool isAbsolutePath(const char *fileName);
// pointer to just after the last '/'
const char *lastPathElement(const char *name);
std::string parentDirectory(const std::string &path);
// ask the user for permission to create the directory. If they say ok, then
// do it and return true.
bool userAllowMkdir(const char *dirPath, mode_t mode);
bool userAllowMkdir(int promptno, const char *dirPath, mode_t mode);
class Cipher;
class DirNode;
struct EncFS_Root {
shared_ptr<Cipher> cipher;
CipherKey volumeKey;
shared_ptr<DirNode> root;
EncFS_Root();
~EncFS_Root();
};
typedef shared_ptr<EncFS_Root> RootPtr;
enum ConfigMode { Config_Prompt, Config_Standard, Config_Paranoia };
/**
* EncFS_Opts stores internal settings
*
* See struct EncFS_Args (main.cpp) for the parsed command line arguments
*/
struct EncFS_Opts {
std::string rootDir;
std::string mountPoint; // where to make filesystem visible
bool createIfNotFound; // create filesystem if not found
bool idleTracking; // turn on idle monitoring of filesystem
bool mountOnDemand; // mounting on-demand
bool delayMount; // delay initial mount
bool checkKey; // check crypto key decoding
bool forceDecode; // force decode on MAC block failures
std::string passwordProgram; // path to password program (or empty)
bool useStdin; // read password from stdin rather then prompting
bool annotate; // print annotation line prompt to stderr.
bool ownerCreate; // set owner of new files to caller
bool reverseEncryption; // Reverse encryption
bool noCache; /* Disable block cache (in EncFS) and stat cache (in kernel).
* This is needed if the backing files may be modified
* behind the back of EncFS (for example, in reverse mode).
* See main.cpp for a longer explaination. */
bool readOnly; // Mount read-only
bool requireMac; // Throw an error if MAC is disabled
ConfigMode configMode;
EncFS_Opts() {
createIfNotFound = true;
idleTracking = false;
mountOnDemand = false;
delayMount = false;
checkKey = true;
forceDecode = false;
useStdin = false;
annotate = false;
ownerCreate = false;
reverseEncryption = false;
configMode = Config_Prompt;
noCache = false;
readOnly = false;
requireMac = false;
}
};
/*
Read existing config file. Looks for any supported configuration version.
*/
ConfigType readConfig(const std::string &rootDir,
const shared_ptr<EncFSConfig> &config);
/*
Save the configuration. Saves back as the same configuration type as was
read from.
*/
bool saveConfig(ConfigType type, const std::string &rootdir,
const shared_ptr<EncFSConfig> &config);
class EncFS_Context;
RootPtr initFS(EncFS_Context *ctx, const shared_ptr<EncFS_Opts> &opts);
RootPtr createV6Config(EncFS_Context *ctx, const shared_ptr<EncFS_Opts> &opts);
void showFSInfo(const shared_ptr<EncFSConfig> &config);
bool readV4Config(const char *configFile, const shared_ptr<EncFSConfig> &config,
struct ConfigInfo *);
bool writeV4Config(const char *configFile,
const shared_ptr<EncFSConfig> &config);
bool readV5Config(const char *configFile, const shared_ptr<EncFSConfig> &config,
struct ConfigInfo *);
bool writeV5Config(const char *configFile,
const shared_ptr<EncFSConfig> &config);
bool readV6Config(const char *configFile, const shared_ptr<EncFSConfig> &config,
struct ConfigInfo *);
bool writeV6Config(const char *configFile,
const shared_ptr<EncFSConfig> &config);
#endif