1 From b9420c3bfc2a8b9d35d0c8e5f6849007c2bc21fa Mon Sep 17 00:00:00 2001
2 From: Darik Horn <dajhorn@vanadac.com>
3 Date: Mon, 14 Apr 2014 13:22:24 -0400
4 Subject: [PATCH] Use FHS installation directories.
6 Install to `/usr/sbin`, `/usr/lib`, and `/var/lib` according to the Linux
7 filesystem hierarchy standard if SoftEther is built through autotools.
9 In a managed installation, the FHS stipulates that the application must
10 accomodate a read-only installation path. This requires a new `GetStateDir`
11 function that substitues `GetExeDir` in some parts of the code.
14 https://github.com/dajhorn/SoftEtherVPN/commit/b9420c3bfc2a8b9d35d0c8e5f6849007c2bc21fa.
16 Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
17 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
19 autotools/softether.am | 1 +
20 src/Cedar/Admin.c | 2 +-
21 src/Cedar/Command.c | 6 +++++-
22 src/Cedar/Logging.c | 2 +-
23 src/Cedar/Server.c | 4 ++--
24 src/Mayaqua/Encrypt.c | 2 +-
25 src/Mayaqua/FileIO.c | 39 ++++++++++++++++++++++++++++++++++++---
26 src/Mayaqua/FileIO.h | 2 ++
27 src/Mayaqua/Mayaqua.c | 4 ++++
28 src/Mayaqua/Table.c | 6 +++++-
29 src/Mayaqua/Unix.c | 6 +++---
30 src/bin/hamcore/Makefile.am | 8 ++++++--
31 12 files changed, 67 insertions(+), 15 deletions(-)
33 Index: b/autotools/softether.am
34 ===================================================================
35 --- a/autotools/softether.am
36 +++ b/autotools/softether.am
39 -I$(top_srcdir)/src/Mayaqua \
40 -I$(top_srcdir)/src/Cedar \
41 + -DSTATE_DIR='"@localstatedir@/lib/softether"' \
45 Index: b/src/Cedar/Admin.c
46 ===================================================================
47 --- a/src/Cedar/Admin.c
48 +++ b/src/Cedar/Admin.c
49 @@ -10334,7 +10334,7 @@
51 Zero(t, sizeof(RPC_READ_LOG_FILE));
53 - GetExeDir(exe_dir, sizeof(exe_dir));
54 + GetStateDir(exe_dir, sizeof(exe_dir));
55 Format(full_path, sizeof(full_path), "%s/%s", exe_dir, filepath);
58 Index: b/src/Cedar/Command.c
59 ===================================================================
60 --- a/src/Cedar/Command.c
61 +++ b/src/Cedar/Command.c
65 GetExeName(exe, sizeof(exe));
66 - GetExeDir(exe_dir, sizeof(exe_dir));
67 + GetStateDir(exe_dir, sizeof(exe_dir));
70 dirs = EnumDir(exe_dir);
76 + wchar_t *filename = L"" STATE_DIR L"/vpn_checker_tmp";
78 wchar_t *filename = L"/tmp/vpn_checker_tmp";
81 wchar_t filename[MAX_PATH];
82 CombinePathW(filename, sizeof(filename), MsGetMyTempDirW(), L"vpn_checker_tmp");
83 Index: b/src/Cedar/Logging.c
84 ===================================================================
85 --- a/src/Cedar/Logging.c
86 +++ b/src/Cedar/Logging.c
89 e = ZeroMalloc(sizeof(ERASER));
91 - GetExeDir(dir, sizeof(dir));
92 + GetStateDir(dir, sizeof(dir));
95 e->MinFreeSpace = min_size;
96 Index: b/src/Cedar/Server.c
97 ===================================================================
98 --- a/src/Cedar/Server.c
99 +++ b/src/Cedar/Server.c
100 @@ -1060,7 +1060,7 @@
104 - GetExeDir(exe_dir, sizeof(exe_dir));
105 + GetStateDir(exe_dir, sizeof(exe_dir));
107 // Enumerate in the server_log
109 @@ -1134,7 +1134,7 @@
113 - GetExeDir(exe_dir, sizeof(exe_dir));
114 + GetStateDir(exe_dir, sizeof(exe_dir));
115 Format(dir_full_path, sizeof(dir_full_path), "%s/%s", exe_dir, dirname);
117 dir = EnumDir(dir_full_path);
118 Index: b/src/Mayaqua/Encrypt.c
119 ===================================================================
120 --- a/src/Mayaqua/Encrypt.c
121 +++ b/src/Mayaqua/Encrypt.c
126 - GetExeDir(dirname, sizeof(dirname));
127 + GetStateDir(dirname, sizeof(dirname));
129 // Search the CRL file
130 t = EnumDir(dirname);
131 Index: b/src/Mayaqua/FileIO.c
132 ===================================================================
133 --- a/src/Mayaqua/FileIO.c
134 +++ b/src/Mayaqua/FileIO.c
137 #include <Mayaqua/Mayaqua.h>
140 +static char exe_file_name[MAX_SIZE] = STATE_DIR "/a.out";
141 +static wchar_t exe_file_name_w[MAX_SIZE] = L"" STATE_DIR L"/a.out";
143 static char exe_file_name[MAX_SIZE] = "/tmp/a.out";
144 static wchar_t exe_file_name_w[MAX_SIZE] = L"/tmp/a.out";
147 static LIST *hamcore = NULL;
148 static IO *hamcore_io = NULL;
150 @@ -1038,7 +1044,7 @@
153 // If the file exist in hamcore/ directory on the local disk, read it
154 - GetExeDirW(exe_dir, sizeof(exe_dir));
155 + GetStateDirW(exe_dir, sizeof(exe_dir));
157 UniFormat(tmp, sizeof(tmp), L"%s/%S/%S", exe_dir, HAMCORE_DIR_NAME, filename);
159 @@ -1154,7 +1160,7 @@
163 - GetExeDirW(exe_dir, sizeof(exe_dir));
164 + GetStateDirW(exe_dir, sizeof(exe_dir));
165 UniFormat(tmp, sizeof(tmp), L"%s/%S", exe_dir, HAMCORE_FILE_NAME);
167 UniFormat(tmp2, sizeof(tmp2), L"%s/%S", exe_dir, HAMCORE_FILE_NAME_2);
168 @@ -1438,6 +1444,33 @@
169 GetDirNameFromFilePathW(name, size, exe_file_name_w);
172 +void GetStateDir(char *name, UINT size)
174 + // Validate arguments
180 + StrCpy(name, size, STATE_DIR);
182 + GetExeDir(name, size)
185 +void GetStateDirW(wchar_t *name, UINT size)
187 + // Validate arguments
193 + UniStrCpy(name, size, L"" STATE_DIR L"");
195 + GetExeDirW(name, size)
199 // Get the EXE file name
200 void GetExeName(char *name, UINT size)
202 @@ -2389,7 +2422,7 @@
205 wchar_t dir[MAX_SIZE];
206 - GetExeDirW(dir, sizeof(dir));
207 + GetStateDirW(dir, sizeof(dir));
208 ConbinePathW(dst, size, dir, &src[1]);
211 Index: b/src/Mayaqua/FileIO.h
212 ===================================================================
213 --- a/src/Mayaqua/FileIO.h
214 +++ b/src/Mayaqua/FileIO.h
216 void GetExeNameW(wchar_t *name, UINT size);
217 void GetExeDir(char *name, UINT size);
218 void GetExeDirW(wchar_t *name, UINT size);
219 +void GetStateDir(char *name, UINT size);
220 +void GetStateDirW(wchar_t *name, UINT size);
221 void BuildHamcore(char *dst_filename, char *src_dir, bool unix_only);
222 int CompareHamcore(void *p1, void *p2);
224 Index: b/src/Mayaqua/Mayaqua.c
225 ===================================================================
226 --- a/src/Mayaqua/Mayaqua.c
227 +++ b/src/Mayaqua/Mayaqua.c
233 + // This check causes hamcorebuilder to fail in an unprivileged
234 + // environment, and is unnecessary for a managed installation.
238 // Initialization of Probe
240 Index: b/src/Mayaqua/Table.c
241 ===================================================================
242 --- a/src/Mayaqua/Table.c
243 +++ b/src/Mayaqua/Table.c
244 @@ -1191,7 +1191,7 @@
248 - GetExeDirW(exe, sizeof(exe));
249 + GetStateDirW(exe, sizeof(exe));
250 UniStrCpy(hashtemp, sizeof(hashtemp), strfilename);
251 BinToStrW(tmp, sizeof(tmp), filehash, MD5_SIZE);
252 UniStrCat(hashtemp, sizeof(hashtemp), tmp);
253 @@ -1204,7 +1204,11 @@
258 + UniStrCpy(exe, sizeof(exe), L"" STATE_DIR L"");
260 UniStrCpy(exe, sizeof(exe), L"/tmp");
263 StrToUni(exe, sizeof(exe), MsGetTempDir());
265 Index: b/src/Mayaqua/Unix.c
266 ===================================================================
267 --- a/src/Mayaqua/Unix.c
268 +++ b/src/Mayaqua/Unix.c
270 StrCpy(tmp, sizeof(tmp), instance_name);
273 - GetExeDir(dir, sizeof(dir));
274 + GetStateDir(dir, sizeof(dir));
276 // File name generation
277 Format(name, sizeof(name), "%s/.%s", dir, tmp);
278 @@ -2260,7 +2260,7 @@
282 - GetExeDir(dir, sizeof(dir));
283 + GetStateDir(dir, sizeof(dir));
285 GetExeName(exe_name, sizeof(exe_name));
286 StrCat(exe_name, sizeof(exe_name), ":pid_hash");
287 @@ -2305,7 +2305,7 @@
291 - GetExeDir(dir, sizeof(dir));
292 + GetStateDir(dir, sizeof(dir));
294 GetExeName(exe_name, sizeof(exe_name));
295 StrCat(exe_name, sizeof(exe_name), ":pid_hash");
296 Index: b/src/bin/hamcore/Makefile.am
297 ===================================================================
298 --- a/src/bin/hamcore/Makefile.am
299 +++ b/src/bin/hamcore/Makefile.am
302 include $(top_srcdir)/autotools/softether.am
304 -# This is required to use a custom build rule with -Wall and -Werror enabled.
305 +# An empty EXEEXT required for overrides with -Wall and -Werror enabled.
306 AUTOMAKE_OPTIONS = -Wno-override
309 HAMCOREBUILDER = $(top_builddir)/src/hamcorebuilder/hamcorebuilder
311 -sbin_PROGRAMS = hamcore.se2
312 +noinst_PROGRAMS = hamcore.se2
314 hamcore.se2$(EXEEXT): $(HAMCOREBUILDER)
315 $(HAMCOREBUILDER) $(top_srcdir)/src/bin/hamcore $@
317 +install-exec-local: hamcore.se2$(EXEEXT)
318 + $(INSTALL_DATA) -D hamcore.se2$(EXEEXT) $(DESTDIR)$(localstatedir)/lib/softether/hamcore.se2