0003-use-fhs-install-directories.patch 8.7 KB

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