xref: /OK3568_Linux_fs/buildroot/package/softether/0003-use-fhs-install-directories.patch (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1From b9420c3bfc2a8b9d35d0c8e5f6849007c2bc21fa Mon Sep 17 00:00:00 2001
2From: Darik Horn <dajhorn@vanadac.com>
3Date: Mon, 14 Apr 2014 13:22:24 -0400
4Subject: [PATCH] Use FHS installation directories.
5
6Install to `/usr/sbin`, `/usr/lib`, and `/var/lib` according to the Linux
7filesystem hierarchy standard if SoftEther is built through autotools.
8
9In a managed installation, the FHS stipulates that the application must
10accomodate a read-only installation path.  This requires a new `GetStateDir`
11function that substitues `GetExeDir` in some parts of the code.
12
13Taken from Github at
14https://github.com/dajhorn/SoftEtherVPN/commit/b9420c3bfc2a8b9d35d0c8e5f6849007c2bc21fa.
15
16Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
17Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
18
19[Updated for 4.28 build 9669 beta - src/Mayaqua/Encrypt.c dropped IsXRevoked()
20Signed-off-by: Matthew Weber <matthew.weber@rockwellcollins.com>
21---
22 autotools/softether.am      |  1 +
23 src/Cedar/Admin.c           |  2 +-
24 src/Cedar/Command.c         |  6 +++++-
25 src/Cedar/Logging.c         |  2 +-
26 src/Cedar/Server.c          |  4 ++--
27 src/Mayaqua/FileIO.c        | 39 ++++++++++++++++++++++++++++++++++++---
28 src/Mayaqua/FileIO.h        |  2 ++
29 src/Mayaqua/Mayaqua.c       |  4 ++++
30 src/Mayaqua/Table.c         |  6 +++++-
31 src/Mayaqua/Unix.c          |  6 +++---
32 src/bin/hamcore/Makefile.am |  8 ++++++--
33 11 files changed, 66 insertions(+), 14 deletions(-)
34
35Index: b/autotools/softether.am
36===================================================================
37--- a/autotools/softether.am
38+++ b/autotools/softether.am
39@@ -27,6 +27,7 @@
40 	-I$(top_srcdir)/src \
41 	-I$(top_srcdir)/src/Mayaqua \
42 	-I$(top_srcdir)/src/Cedar \
43+	-DSTATE_DIR='"@localstatedir@/lib/softether"' \
44 	-DUNIX \
45 	-DUNIX_LINUX \
46 	-D_REENTRANT \
47Index: b/src/Cedar/Admin.c
48===================================================================
49--- a/src/Cedar/Admin.c
50+++ b/src/Cedar/Admin.c
51@@ -10334,7 +10334,7 @@
52
53 	Zero(t, sizeof(RPC_READ_LOG_FILE));
54
55-	GetExeDir(exe_dir, sizeof(exe_dir));
56+	GetStateDir(exe_dir, sizeof(exe_dir));
57 	Format(full_path, sizeof(full_path), "%s/%s", exe_dir, filepath);
58
59 	// Read file
60Index: b/src/Cedar/Command.c
61===================================================================
62--- a/src/Cedar/Command.c
63+++ b/src/Cedar/Command.c
64@@ -527,7 +527,7 @@
65 	UINT i;
66
67 	GetExeName(exe, sizeof(exe));
68-	GetExeDir(exe_dir, sizeof(exe_dir));
69+	GetStateDir(exe_dir, sizeof(exe_dir));
70
71 	ok = false;
72 	dirs = EnumDir(exe_dir);
73@@ -552,7 +552,11 @@
74 		UCHAR *buf;
75 		IO *io;
76 #ifndef	OS_WIN32
77+#ifdef STATE_DIR
78+		wchar_t *filename = L"" STATE_DIR L"/vpn_checker_tmp";
79+#else
80 		wchar_t *filename = L"/tmp/vpn_checker_tmp";
81+#endif
82 #else	// OS_WIN32
83 		wchar_t filename[MAX_PATH];
84 		CombinePathW(filename, sizeof(filename), MsGetMyTempDirW(), L"vpn_checker_tmp");
85Index: b/src/Cedar/Logging.c
86===================================================================
87--- a/src/Cedar/Logging.c
88+++ b/src/Cedar/Logging.c
89@@ -508,7 +508,7 @@
90
91 	e = ZeroMalloc(sizeof(ERASER));
92
93-	GetExeDir(dir, sizeof(dir));
94+	GetStateDir(dir, sizeof(dir));
95
96 	e->Log = log;
97 	e->MinFreeSpace = min_size;
98Index: b/src/Cedar/Server.c
99===================================================================
100--- a/src/Cedar/Server.c
101+++ b/src/Cedar/Server.c
102@@ -1060,7 +1060,7 @@
103 		hubname = NULL;
104 	}
105
106-	GetExeDir(exe_dir, sizeof(exe_dir));
107+	GetStateDir(exe_dir, sizeof(exe_dir));
108
109 	// Enumerate in the server_log
110 	if (hubname == NULL)
111@@ -1134,7 +1134,7 @@
112 		return;
113 	}
114
115-	GetExeDir(exe_dir, sizeof(exe_dir));
116+	GetStateDir(exe_dir, sizeof(exe_dir));
117 	Format(dir_full_path, sizeof(dir_full_path), "%s/%s", exe_dir, dirname);
118
119 	dir = EnumDir(dir_full_path);
120Index: b/src/Mayaqua/FileIO.c
121===================================================================
122--- a/src/Mayaqua/FileIO.c
123+++ b/src/Mayaqua/FileIO.c
124@@ -122,8 +122,14 @@
125 #include <errno.h>
126 #include <Mayaqua/Mayaqua.h>
127
128+#ifdef STATE_DIR
129+static char exe_file_name[MAX_SIZE] = STATE_DIR "/a.out";
130+static wchar_t exe_file_name_w[MAX_SIZE] = L"" STATE_DIR L"/a.out";
131+#else
132 static char exe_file_name[MAX_SIZE] = "/tmp/a.out";
133 static wchar_t exe_file_name_w[MAX_SIZE] = L"/tmp/a.out";
134+#endif
135+
136 static LIST *hamcore = NULL;
137 static IO *hamcore_io = NULL;
138
139@@ -1038,7 +1044,7 @@
140 	}
141
142 	// If the file exist in hamcore/ directory on the local disk, read it
143-	GetExeDirW(exe_dir, sizeof(exe_dir));
144+	GetStateDirW(exe_dir, sizeof(exe_dir));
145
146 	UniFormat(tmp, sizeof(tmp), L"%s/%S/%S", exe_dir, HAMCORE_DIR_NAME, filename);
147
148@@ -1154,7 +1160,7 @@
149 		return;
150 	}
151
152-	GetExeDirW(exe_dir, sizeof(exe_dir));
153+	GetStateDirW(exe_dir, sizeof(exe_dir));
154 	UniFormat(tmp, sizeof(tmp), L"%s/%S", exe_dir, HAMCORE_FILE_NAME);
155
156 	UniFormat(tmp2, sizeof(tmp2), L"%s/%S", exe_dir, HAMCORE_FILE_NAME_2);
157@@ -1438,6 +1444,33 @@
158 	GetDirNameFromFilePathW(name, size, exe_file_name_w);
159 }
160
161+void GetStateDir(char *name, UINT size)
162+{
163+	// Validate arguments
164+	if (name == NULL)
165+	{
166+		return;
167+	}
168+#ifdef STATE_DIR
169+	StrCpy(name, size, STATE_DIR);
170+#else
171+	GetExeDir(name, size)
172+#endif
173+}
174+void GetStateDirW(wchar_t *name, UINT size)
175+{
176+	// Validate arguments
177+	if (name == NULL)
178+	{
179+		return;
180+	}
181+#ifdef STATE_DIR
182+	UniStrCpy(name, size, L"" STATE_DIR L"");
183+#else
184+	GetExeDirW(name, size)
185+#endif
186+}
187+
188 // Get the EXE file name
189 void GetExeName(char *name, UINT size)
190 {
191@@ -2389,7 +2422,7 @@
192 	else
193 	{
194 		wchar_t dir[MAX_SIZE];
195-		GetExeDirW(dir, sizeof(dir));
196+		GetStateDirW(dir, sizeof(dir));
197 		ConbinePathW(dst, size, dir, &src[1]);
198 	}
199 }
200Index: b/src/Mayaqua/FileIO.h
201===================================================================
202--- a/src/Mayaqua/FileIO.h
203+++ b/src/Mayaqua/FileIO.h
204@@ -349,6 +349,8 @@
205 void GetExeNameW(wchar_t *name, UINT size);
206 void GetExeDir(char *name, UINT size);
207 void GetExeDirW(wchar_t *name, UINT size);
208+void GetStateDir(char *name, UINT size);
209+void GetStateDirW(wchar_t *name, UINT size);
210 void BuildHamcore(char *dst_filename, char *src_dir, bool unix_only);
211 int CompareHamcore(void *p1, void *p2);
212 void InitHamcore();
213Index: b/src/Mayaqua/Mayaqua.c
214===================================================================
215--- a/src/Mayaqua/Mayaqua.c
216+++ b/src/Mayaqua/Mayaqua.c
217@@ -611,7 +611,11 @@
218 		_exit(0);
219 	}
220
221+#ifndef STATE_DIR
222+	// This check causes hamcorebuilder to fail in an unprivileged
223+	// environment, and is unnecessary for a managed installation.
224 	CheckUnixTempDir();
225+#endif
226
227 	// Initialization of Probe
228 	InitProbe();
229Index: b/src/Mayaqua/Table.c
230===================================================================
231--- a/src/Mayaqua/Table.c
232+++ b/src/Mayaqua/Table.c
233@@ -1191,7 +1191,7 @@
234 		return;
235 	}
236
237-	GetExeDirW(exe, sizeof(exe));
238+	GetStateDirW(exe, sizeof(exe));
239 	UniStrCpy(hashtemp, sizeof(hashtemp), strfilename);
240 	BinToStrW(tmp, sizeof(tmp), filehash, MD5_SIZE);
241 	UniStrCat(hashtemp, sizeof(hashtemp), tmp);
242@@ -1204,7 +1204,11 @@
243 	UniStrLower(tmp);
244
245 #ifndef	OS_WIN32
246+#ifdef STATE_DIR
247+	UniStrCpy(exe, sizeof(exe), L"" STATE_DIR L"");
248+#else
249 	UniStrCpy(exe, sizeof(exe), L"/tmp");
250+#endif
251 #else	// OS_WIN32
252 	StrToUni(exe, sizeof(exe), MsGetTempDir());
253 #endif	// OS_WIN32
254Index: b/src/Mayaqua/Unix.c
255===================================================================
256--- a/src/Mayaqua/Unix.c
257+++ b/src/Mayaqua/Unix.c
258@@ -928,7 +928,7 @@
259 		StrCpy(tmp, sizeof(tmp), instance_name);
260 	}
261
262-	GetExeDir(dir, sizeof(dir));
263+	GetStateDir(dir, sizeof(dir));
264
265 	// File name generation
266 	Format(name, sizeof(name), "%s/.%s", dir, tmp);
267@@ -2260,7 +2260,7 @@
268 		return;
269 	}
270
271-	GetExeDir(dir, sizeof(dir));
272+	GetStateDir(dir, sizeof(dir));
273
274 	GetExeName(exe_name, sizeof(exe_name));
275 	StrCat(exe_name, sizeof(exe_name), ":pid_hash");
276@@ -2305,7 +2305,7 @@
277 		return;
278 	}
279
280-	GetExeDir(dir, sizeof(dir));
281+	GetStateDir(dir, sizeof(dir));
282
283 	GetExeName(exe_name, sizeof(exe_name));
284 	StrCat(exe_name, sizeof(exe_name), ":pid_hash");
285Index: b/src/bin/hamcore/Makefile.am
286===================================================================
287--- a/src/bin/hamcore/Makefile.am
288+++ b/src/bin/hamcore/Makefile.am
289@@ -18,12 +18,16 @@
290
291 include $(top_srcdir)/autotools/softether.am
292
293-# This is required to use a custom build rule with -Wall and -Werror enabled.
294+# An empty EXEEXT required for overrides with -Wall and -Werror enabled.
295 AUTOMAKE_OPTIONS = -Wno-override
296 EXEEXT =
297+
298 HAMCOREBUILDER = $(top_builddir)/src/hamcorebuilder/hamcorebuilder
299
300-sbin_PROGRAMS = hamcore.se2
301+noinst_PROGRAMS = hamcore.se2
302
303 hamcore.se2$(EXEEXT): $(HAMCOREBUILDER)
304 	$(HAMCOREBUILDER) $(top_srcdir)/src/bin/hamcore $@
305+
306+install-exec-local: hamcore.se2$(EXEEXT)
307+	$(INSTALL_DATA) -D hamcore.se2$(EXEEXT) $(DESTDIR)$(localstatedir)/lib/softether/hamcore.se2
308