file checks: Merge warn_if_group_others_accessible() into check_file_access()
PATCH 1/1 file checks: Merge warn_if_group_others_accessible() into check_file_access()
Commit 825e2ec1f358f2e8 cleaned up the usage of warn_if_group_others_accessible() and moved it into options.c. At this point there is only one caller of this function, check_file_access().
This takes that clean-up one step further and merges everything into check_file_access(). In addition it removes some no longer needed #ifdefs and uses platform_stat() to allow a similar check to happen on the Windows platform as well.
--- src/openvpn/options.c | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-)
src/openvpn/options.c +12 -26
@@ -57,6 +57,7 @@#include "manage.h" #include "forward.h" #include "ssl_verify.h" +#include "platform.h" #include <ctype.h> #include "memdbg.h"
@@ -2683,31 +2684,6 @@ options_postprocess_mutate (struct options *o)*/ #ifndef ENABLE_SMALL /** Expect people using the stripped down version to know what they do */ -/* -* Warn if a given file is group/others accessible. -*/ -static void -warn_if_group_others_accessible (const char * filename) -{ -#ifndef WIN32 -#ifdef HAVE_STAT -if (strcmp (filename,INLINE_FILE_TAG )) - { -struct stat st; -if (stat (filename, &st)) - { -msg (M_WARN |M_ERRNO ,"WARNING: cannot stat file '%s'" , filename); - } -else - { -if (st.st_mode & (S_IRWXG |S_IRWXO )) -msg (M_WARN ,"WARNING: file '%s' is group or others accessible" , filename); - } - } -#endif -#endif -} -#define CHKACC_FILE (1<<0)/** Check for a file/directory precense */ #define CHKACC_DIRPATH (1<<1)/** Check for directory precense where a file should reside */ #define CHKACC_FILEXSTWR (1<<2)/** If file exists, is it writable? */
@@ -2754,9 +2730,19 @@ check_file_access(const int type, const char *file, const int mode, const char *if (platform_access (file,W_OK ) !=0 ) errcode = errno; +/* Warn if a given file is group/others accessible. */ if (type &CHKACC_PRIVATE ) { -warn_if_group_others_accessible (file); +platform_stat_t st; +if (platform_stat (file, &st)) + { +msg (M_WARN |M_ERRNO ,"WARNING: cannot stat file '%s'" , file); + } +else + { +if (st.st_mode & (S_IRWXG |S_IRWXO )) +msg (M_WARN ,"WARNING: file '%s' is group or others accessible" , file); + } }/* Scream if an error is found */
Signature · 1 line
1.8.3.1
Hi,
Quoted 70 lines · David Sommerseth
Commit
825e2ec1f358f2e8cleaned up the usage ofwarn_if_group_others_accessible()and moved it intooptions.c. At this point there is only one caller of this function,check_file_access().This takes that clean-up one step further and merges everything into
check_file_access(). In addition it removes some no longer needed #ifdefs and usesplatform_stat()to allow a similar check to happen on the Windows platform as well.Signed-off-by David Sommerseth <[email protected]...>--- src/openvpn/options.c | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-)src/openvpn/options.c +5
-26@@ -57,6 +57,7 @@#include "manage.h" #include "forward.h" #include "ssl_verify.h" +#include "platform.h" #include <ctype.h> #include "memdbg.h" @@ -2683,31 +2684,6 @@ options_postprocess_mutate (struct options *o)*/ #ifndef ENABLE_SMALL /** Expect people using the stripped down version to know what they do */ -/* -* Warn if a given file is group/others accessible. -*/ -static void -warn_if_group_others_accessible (const char * filename) -{ -#ifndef WIN32 -#ifdef HAVE_STAT -if (strcmp (filename,INLINE_FILE_TAG )) - { -struct stat st; -if (stat (filename, &st)) - { -msg (M_WARN |M_ERRNO ,"WARNING: cannot stat file '%s'" , filename); - } -else - { -if (st.st_mode & (S_IRWXG |S_IRWXO )) -msg (M_WARN ,"WARNING: file '%s' is group or others accessible" , filename); - } - } -#endif -#endif -} -#define CHKACC_FILE (1<<0)/** Check for a file/directory precense */ #define CHKACC_DIRPATH (1<<1)/** Check for directory precense where a file should reside */ #define CHKACC_FILEXSTWR (1<<2)/** If file exists, is it writable? */ @@ -2754,9 +2730,19 @@ check_file_access(const int type, const char *file, const int mode, const char *if (platform_access (file,W_OK ) !=0 ) errcode = errno; +/* Warn if a given file is group/others accessible. */ if (type &CHKACC_PRIVATE ) { -warn_if_group_others_accessible (file); +platform_stat_t st; +if (platform_stat (file, &st)) + {
src/openvpn/options.c check_file_access(const int type, const char *file, const int mode, const char * · line 2748
Quoted 10 lines
src/openvpn/options.c +7
-0+msg (M_WARN |M_ERRNO ,"WARNING: cannot stat file '%s'" , file); + } +else + { +if (st.st_mode & (S_IRWXG |S_IRWXO )) +msg (M_WARN ,"WARNING: file '%s' is group or others accessible" , file); + } }/* Scream if an error is found */
Hm, I like the removal of the #ifdefs, but I don't think we should merge warn_if_group_others_accessible() into check_file_access(). Why? Because when it was a separate function, the code was self-documenting and nicely separated. Now, we need an extra comment that basically exists of the previous function name to explain what we're doing.
I was also wondering, have you tested that this work as expected on Windows? Since Windows has a quite different permission system. Or will is simply never warn, like before? That would be fine for this patch.
-Steffan
Quoted 3 lines · Steffan Karger
I was also wondering, have you tested that this work as expected on Windows? Since Windows has a quite different permission system. Or will is simply never warn, like before? That would be fine for this patch.
According to https://msdn.microsoft.com/en-us/library/3kyc8381.aspx, the S_IRWXG|S_IRWXO flags we're checking for will never be set on Windows, so that's fine.
-Steffan
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 53 lines · Steffan Karger
Hi,
Quoted 50 lines · David Sommerseth
Commit
825e2ec1f358f2e8cleaned up the usage ofwarn_if_group_others_accessible()and moved it intooptions.c. At this point there is only one caller of this function,check_file_access().This takes that clean-up one step further and merges everything into
check_file_access(). In addition it removes some no longer needed #ifdefs and usesplatform_stat()to allow a similar check to happen on the Windows platform as well.Signed-off-by David Sommerseth <[email protected]...> ---
src/openvpn/options.c| 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-)src/openvpn/options.c index renamed from src/openvpn/options.c +0
-04d31e4c..369f3f4 100644 ---
a/src/openvpn/options.c+++b/src/openvpn/options.c@@ -57,6 +57,7 @@ #include "manage.h" #include "forward.h" #include "ssl_verify.h" +#include "platform.h" #include <ctype.h>#include "
memdbg.h" @@ -2683,31 +2684,6 @@options_postprocess_mutate(struct options *o) */ #ifndefENABLE_SMALL/** Expect people using the stripped down version to know what they do */src/openvpn/options.c index renamed from src/openvpn/options.c +0
-2-/* - * Warn if a given file is group/others accessible. - */ -static void -warn_if_group_others_accessible (const char*filename) -{ -#ifndef WIN32 -#ifdef
HAVE_STAT- if (strcmp
(filename,INLINE_FILE_TAG)) - { - struct stat st; -
if (stat (filename, &st)) - { - msg (M_WARN|M_ERRNO,
"WARNING: cannot stat file '%s'", filename); - } - else - {src/openvpn/options.c index renamed from src/openvpn/options.c +0
-1- if (st.st_mode & (S_IRWXG|S_IRWXO)) - msg (M_WARN,"WARNING: file '%s' is group or others accessible", filename); -
} - } -#endif -#endif -} - #defineCHKACC_FILE(1<<0)
/** Check for a file/directory precense */ #defineCHKACC_DIRPATH
(1<<1) /** Check for directory precense where a file should
reside */ #defineCHKACC_FILEXSTWR(1<<2) /** If file exists, is it writable? */ @@ -2754,9 +2730,19 @@ check_file_access(const int type, const char *file, const int mode, const char * if (platform_access(file,W_OK) != 0) errcode = errno;+ /* Warn if a given file is group/others accessible. */ if
(type &CHKACC_PRIVATE) { -warn_if_group_others_accessible
(file); +platform_stat_tst; + if (platform_stat
(file, &st)) + { + msg (M_WARN|M_ERRNO, "WARNING: cannot stat
file '%s'", file); + } + else + { + if (st.st_mode &
(S_IRWXG|S_IRWXO)) + msg (M_WARN, "WARNING: file '%s' is
group or others accessible", file); + } }
Quoted 6 lines
Quoted 2 lines
/* Scream if an error is found */
Hm, I like the removal of the #ifdefs, but I don't think we should merge
warn_if_group_others_accessible()intocheck_file_access(). Why?
That function is already fairly short, and these additional lines in the function doesn't add much. And it falls perfectly within the scope of "check file access". Had the scope for this function been broader and expected to be used more places, it would have a place as a separate function, IMO.
Quoted 4 lines
Because when it was a separate function, the code was self-documenting and nicely separated. Now, we need an extra comment that basically exists of the previous function name to explain what we're doing.
The overall change reduces the lines of code with 14 lines. Just 4 of them are #ifdef related. And I personally find it easier to read a comment and then see instantly what happens below. Otherwise you read a function name, guess what it does based on its name but don't know before you've located the function and read it.
So when there's a benefit of reducing the total amount of lines, I value that even more.
With that said, there are plenty of reasons why not to merge functions. But from my point of view, the use scope for warn_if_group_others_accessible() is clearly defined and falls perfectly under the responsibility check_file_access() primarily should have. And with just one caller, I think this approach is simpler and cleaner.
Quoted 4 lines
I was also wondering, have you tested that this work as expected on Windows? Since Windows has a quite different permission system. Or will is simply never warn, like before? That would be fine for this patch.
I do not have any Windows test environments, so I'll admit that's a bold (and risky) move of me. However, as you've identified, S_IRWXG|S_IRWXO is not set so shouldn't cause any issues.
- --
kind regards,
David Sommerseth
OpenVPN Technologies, Inc
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)
iQIcBAEBAgAGBQJYLHRGAAoJEIbPlEyWcf3yHrEP/3ETuMw700Aw1qU0NFtfyA1X rFyx7cn4HWaKSnb15b/I5SaniG2frh/dfFmSudbm1SZIbS+tFMV33HL0Rrzca+f7 pyAQsbOVFcvuG7dZrbutUCZ7v19d93xkYr06Z1ceHtuG1pqa0ZiVow7eKiHzxjnG yNmYqbuPRzgiMnXkA1Nd3toaeGO6ee6hPnKHWUdIg/UWFmDJqnYac3ErC+jNuzB8 jaSzGXTAIpj7O/R4B4pkzd+La1nnsUce0iAeEw9EUpFQN9VxaJ8+28MscsQIiKg7 AAPLFHCWuZEw2WENTvpRvT4pTYfaztb8sxDLt8GO31x8MHR8c8t4i76u6T9ma73Q mSTGcErALkR4zaxn9BSbXZLrxsBFZeWCM5WfGcD5lVQCQrQC4zPBVhUvaL9Sq1vi oEEVcavBvjN2yGzuQQQ8k6fNAjKhD2VETKY11RpWxuo2L/YiEVKigu0O1mt6FiBU 2a9LnBctsx0a5jPGmHg1fb1AlLh+F/DqsKjIlXxG7TwECAkam4PCJsG9j3hs/77/ fXVsgkjdxNQwEA+ZrzoCiMIy3YCxphiMg38jXnoVmY5T2uk3n0Uhutk356F06egK 233aA3eI+p060UCwPY/RK7KXAfHt6ivGAVMHUOdOqQM3NKlBEPaLiR8U8FDwfvqk SXZsoYN0NzuurabdSefK
=IkUh
-----END PGP SIGNATURE-----
Quoted 79 lines · David Sommerseth
Quoted 51 lines · Steffan Karger
Quoted 50 lines · David Sommerseth
Commit
825e2ec1f358f2e8cleaned up the usage ofwarn_if_group_others_accessible()and moved it intooptions.c. At this point there is only one caller of this function,check_file_access().This takes that clean-up one step further and merges everything into
check_file_access(). In addition it removes some no longer needed #ifdefs and usesplatform_stat()to allow a similar check to happen on the Windows platform as well.Signed-off-by David Sommerseth <[email protected]...> ---
src/openvpn/options.c| 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-)src/openvpn/options.c index renamed from src/openvpn/options.c +0
-04d31e4c..369f3f4 100644 ---
a/src/openvpn/options.c+++b/src/openvpn/options.c@@ -57,6 +57,7 @@ #include "manage.h" #include "forward.h" #include "ssl_verify.h" +#include "platform.h" #include <ctype.h>#include "
memdbg.h" @@ -2683,31 +2684,6 @@options_postprocess_mutate(struct options *o) */ #ifndefENABLE_SMALL/** Expect people using the stripped down version to know what they do */src/openvpn/options.c index renamed from src/openvpn/options.c +0
-2-/* - * Warn if a given file is group/others accessible. - */ -static void -warn_if_group_others_accessible (const char*filename) -{ -#ifndef WIN32 -#ifdef
HAVE_STAT- if (strcmp
(filename,INLINE_FILE_TAG)) - { - struct stat st; -
if (stat (filename, &st)) - { - msg (M_WARN|M_ERRNO,
"WARNING: cannot stat file '%s'", filename); - } - else - {src/openvpn/options.c index renamed from src/openvpn/options.c +0
-1- if (st.st_mode & (S_IRWXG|S_IRWXO)) - msg (M_WARN,"WARNING: file '%s' is group or others accessible", filename); -
} - } -#endif -#endif -} - #defineCHKACC_FILE(1<<0)
/** Check for a file/directory precense */ #defineCHKACC_DIRPATH
(1<<1) /** Check for directory precense where a file should
reside */ #defineCHKACC_FILEXSTWR(1<<2) /** If file exists, is it writable? */ @@ -2754,9 +2730,19 @@ check_file_access(const int type, const char *file, const int mode, const char * if (platform_access(file,W_OK) != 0) errcode = errno;+ /* Warn if a given file is group/others accessible. */ if
(type &CHKACC_PRIVATE) { -warn_if_group_others_accessible
(file); +platform_stat_tst; + if (platform_stat
(file, &st)) + { + msg (M_WARN|M_ERRNO, "WARNING: cannot stat
file '%s'", file); + } + else + { + if (st.st_mode &
(S_IRWXG|S_IRWXO)) + msg (M_WARN, "WARNING: file '%s' is
group or others accessible", file); + } }Quoted 6 lines
Quoted 2 lines
/* Scream if an error is found */
Hm, I like the removal of the #ifdefs, but I don't think we should merge
warn_if_group_others_accessible()intocheck_file_access(). Why?That function is already fairly short, and these additional lines in the function doesn't add much. And it falls perfectly within the scope of "check file access". Had the scope for this function been broader and expected to be used more places, it would have a place as a separate function, IMO.
Quoted 4 lines
Because when it was a separate function, the code was self-documenting and nicely separated. Now, we need an extra comment that basically exists of the previous function name to explain what we're doing.
The overall change reduces the lines of code with 14 lines. Just 4 of them are #ifdef related. And I personally find it easier to read a comment and then see instantly what happens below. Otherwise you read a function name, guess what it does based on its name but don't know before you've located the function and read it.
So when there's a benefit of reducing the total amount of lines, I value that even more.
Quoted 6 lines
With that said, there are plenty of reasons why not to merge functions. But from my point of view, the use scope for
warn_if_group_others_accessible()is clearly defined and falls perfectly under the responsibilitycheck_file_access()primarily should have. And with just one caller, I think this approach is simpler and cleaner.
We clearly have different opinions here, so I guess we'll have to discuss that further some time. But as far as I'm concerned that should not hold up this patch.
Quoted 8 lines
Quoted 4 lines
I was also wondering, have you tested that this work as expected on Windows? Since Windows has a quite different permission system. Or will is simply never warn, like before? That would be fine for this patch.
I do not have any Windows test environments, so I'll admit that's a bold (and risky) move of me. However, as you've identified, S_IRWXG|S_IRWXO is not set so shouldn't cause any issues.
Combined with a compile-test I just this and the fact that the worst thing that could happen is an incorrect warning (Windows builds never warned before), I feel confident enough to ACK this:
ACK.
-Steffan
Quoted 9 lines · Steffan Karger
Quoted 3 lines
I do not have any Windows test environments, so I'll admit that's a bold (and risky) move of me. However, as you've identified, S_IRWXG|S_IRWXO is not set so shouldn't cause any issues.
Combined with a compile-test I just this and the fact that the worst thing that could happen is an incorrect warning (Windows builds never warned before), I feel confident enough to ACK this:
ACK.
But the question is will this compile for windows? I doubt it will unless we add some dummy defines for S_IRWXG etc..
Selva
Hi,
Quoted 7 lines · Selva Nair
Quoted 4 lines · Steffan Karger
Quoted 3 lines
I do not have any Windows test environments, so I'll admit that's a bold (and risky) move of me. However, as you've identified, S_IRWXG|S_IRWXO is not set so shouldn't cause any issues.
Quoted 8 lines
Quoted 5 lines
Combined with a compile-test I just this and the fact that the worst thing that could happen is an incorrect warning (Windows builds never warned before), I feel confident enough to ACK this:
ACK.
But the question is will this compile for windows? I doubt it will unless we add some dummy defines for
S_IRWXGetc..
As Selva was afraid, it breaks windows compilation.
i686-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -I../.. -I../../include -I../../include -I../../src/compat -DWIN32_LEAN_AND_MEAN -DNTDDI_VERSION=NTDDI_VISTA -D_WIN32_WINNT=_WIN32_WINNT_VISTA -I/home/samuli/buildtest/openvpn-build/windows-nsis/tmp/image-i686/openvpn/include -I/home/samuli/buildtest/openvpn-build/windows-nsis/tmp/image-i686/openvpn/include -I/home/samuli/buildtest/openvpn-build/windows-nsis/tmp/image-i686/openvpn/include -I/home/samuli/buildtest/openvpn-build/windows-nsis/tmp/image-i686/openvpn/include -municode -UUNICODE -std=c99 -MT options.o -MD -MP -MF .deps/options.Tpo -c -o options.o options.c options.c: In function 'check_file_access':
options.c:2743:22: error: 'S_IRWXG' undeclared (first use in this function)
if (st.st_mode & (S_IRWXG|S_IRWXO))
^
options.c:2743:22: note: each undeclared identifier is reported only once for each function it appears in
options.c:2743:30: error: 'S_IRWXO' undeclared (first use in this function)
if (st.st_mode & (S_IRWXG|S_IRWXO))
^"I do not have a windows test environment, so I'll boldly and risky commit something which is not a must-have for 2.4_beta1 but just a code shuffling-around, and which breaks platforms" is not a very good strategy.
gert
Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany [email protected]...
fax: +49-89-35655025 [email protected]...-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Your patch has been applied to the master branch
commit 05de0a6e8fb675e309d599a185e70a1c54b8e7e9
Author: David Sommerseth Date: Mon Nov 14 23:45:08 2016 +0100
file checks: Merge warn_if_group_others_accessible() into check_file_access()
Signed-off-by: David Sommerseth <[email protected]...>
Acked-by: Steffan Karger <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg13062.html- --
kind regards,
David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)
iQIcBAEBAgAGBQJYLJL3AAoJEIbPlEyWcf3y1wMP/3ZO01T+nMGxzkcuM2SsKdsD LrWUYO7i56PlYkMxmNoAWYfMLJe2RlNILTuiFAklAkWLqE6GgMfQBIIV1TLkr560 zd+s6UMVowEEm7x2dJyXVBRemFSJv3/XwexMNL+TZKJAMQ/3wfbtg6GiIV5+20TM GAFhpEGVVgqRnGDj1r1sRsXJdZx1o4aNKCnG+PIcXkLNN5V2K6WSSc8Xj9xDZcg7 xN5lUJ7/yOU/hiPcJRToELkoTFXuHmbMP784IxD7hON21hmvtY8S9yJ2tN34PEMZ Pim36WbaXftlXgQbMRaiUo9lDLi8pi+Cj5kIEU7rzMjFvPWbGsQTrWzlB/wPyzAf gn0aHHmnoaqXFjQnuZwL1SZN8k6LM3rNmpes30p5BFvRpPuVNDRsu0cdeXJENr4n qeDm5reSqlN8owfAUlhI3/XGa7Hb18KrIcNMNyJoZ3r4ws5DlFtBj2fIJGvY0Vm9 DWtsEVMUd0C6wTVHLb6/i3pz22CZ13hO4o4vlsS+Z9c3DLROjfWwZEnk1nHlyUMm 93fltyQ4stOe2yisY3plMp85E6jKKnNTfhkVgf0n1VBhdzQFpyIt5gkIHi377O2V rfwP4j+AfhSZuXDeXBWzFG1xN8dhKY4oXW/Ex4g1dwzOkQncmQLLxVhaxKOBJOdk tRJKoLIt8Y4r4b26NqHe
=RFgS
-----END PGP SIGNATURE-----