package/nodejs: security bump for 0.10.x to version 0.10.42
[buildroot-gz.git] / package / softether / 0001-use-fhs-install-directories.patch
blobc489cc1a6ccaba913a8bb58e0103de086114065a
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.
13 Taken from Github at
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>
18 ---
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
37 @@ -27,6 +27,7 @@
38 -I$(top_srcdir)/src \
39 -I$(top_srcdir)/src/Mayaqua \
40 -I$(top_srcdir)/src/Cedar \
41 + -DSTATE_DIR='"@localstatedir@/lib/softether"' \
42 -DUNIX \
43 -DUNIX_LINUX \
44 -D_REENTRANT \
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);
57 // Read file
58 Index: b/src/Cedar/Command.c
59 ===================================================================
60 --- a/src/Cedar/Command.c
61 +++ b/src/Cedar/Command.c
62 @@ -527,7 +527,7 @@
63 UINT i;
65 GetExeName(exe, sizeof(exe));
66 - GetExeDir(exe_dir, sizeof(exe_dir));
67 + GetStateDir(exe_dir, sizeof(exe_dir));
69 ok = false;
70 dirs = EnumDir(exe_dir);
71 @@ -552,7 +552,11 @@
72 UCHAR *buf;
73 IO *io;
74 #ifndef OS_WIN32
75 +#ifdef STATE_DIR
76 + wchar_t *filename = L"" STATE_DIR L"/vpn_checker_tmp";
77 +#else
78 wchar_t *filename = L"/tmp/vpn_checker_tmp";
79 +#endif
80 #else // OS_WIN32
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
87 @@ -508,7 +508,7 @@
89 e = ZeroMalloc(sizeof(ERASER));
91 - GetExeDir(dir, sizeof(dir));
92 + GetStateDir(dir, sizeof(dir));
94 e->Log = log;
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 @@
101 hubname = NULL;
104 - GetExeDir(exe_dir, sizeof(exe_dir));
105 + GetStateDir(exe_dir, sizeof(exe_dir));
107 // Enumerate in the server_log
108 if (hubname == NULL)
109 @@ -1134,7 +1134,7 @@
110 return;
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
122 @@ -579,7 +579,7 @@
123 return false;
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
135 @@ -122,8 +122,14 @@
136 #include <errno.h>
137 #include <Mayaqua/Mayaqua.h>
139 +#ifdef STATE_DIR
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";
142 +#else
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";
145 +#endif
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 @@
160 return;
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
175 + if (name == NULL)
177 + return;
179 +#ifdef STATE_DIR
180 + StrCpy(name, size, STATE_DIR);
181 +#else
182 + GetExeDir(name, size)
183 +#endif
185 +void GetStateDirW(wchar_t *name, UINT size)
187 + // Validate arguments
188 + if (name == NULL)
190 + return;
192 +#ifdef STATE_DIR
193 + UniStrCpy(name, size, L"" STATE_DIR L"");
194 +#else
195 + GetExeDirW(name, size)
196 +#endif
199 // Get the EXE file name
200 void GetExeName(char *name, UINT size)
202 @@ -2389,7 +2422,7 @@
203 else
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
215 @@ -349,6 +349,8 @@
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);
223 void InitHamcore();
224 Index: b/src/Mayaqua/Mayaqua.c
225 ===================================================================
226 --- a/src/Mayaqua/Mayaqua.c
227 +++ b/src/Mayaqua/Mayaqua.c
228 @@ -611,7 +611,11 @@
229 _exit(0);
232 +#ifndef STATE_DIR
233 + // This check causes hamcorebuilder to fail in an unprivileged
234 + // environment, and is unnecessary for a managed installation.
235 CheckUnixTempDir();
236 +#endif
238 // Initialization of Probe
239 InitProbe();
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 @@
245 return;
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 @@
254 UniStrLower(tmp);
256 #ifndef OS_WIN32
257 +#ifdef STATE_DIR
258 + UniStrCpy(exe, sizeof(exe), L"" STATE_DIR L"");
259 +#else
260 UniStrCpy(exe, sizeof(exe), L"/tmp");
261 +#endif
262 #else // OS_WIN32
263 StrToUni(exe, sizeof(exe), MsGetTempDir());
264 #endif // OS_WIN32
265 Index: b/src/Mayaqua/Unix.c
266 ===================================================================
267 --- a/src/Mayaqua/Unix.c
268 +++ b/src/Mayaqua/Unix.c
269 @@ -928,7 +928,7 @@
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 @@
279 return;
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 @@
288 return;
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
300 @@ -18,12 +18,16 @@
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
307 EXEEXT =
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