Skip to contentSkip to conversation

Simplify check_cmd_access() function

PATCH In review David Sommerseth 4 participants 5 messages May 2, 2012 – May 3, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Simplify check_cmd_access() function

To avoid confusion between check_file_access() and check_cmd_access() in the future, remove unneeded arguments from check_cmd_access()

As a command will always be a file, it should always check for CHKACC_FILE and nothing else. And as the commands always will need X_OK, check only for that.

One change from earlier behaviour is that R_OK is not checked for. The reason is that only scripts require R_OK to work. However, a system might be installed with binaries with only X_OK set. If a script is missing R_OK, then the execution will fail due to lacking permissions.

---
 src/openvpn/options.c |   48 ++++++++++++++++++++++++++----------------------
 1 files changed, 26 insertions(+), 22 deletions(-)
src/openvpn/options.c +26 -22
index 5da2eb6..7769625 100644
@@ -2690,7 +2690,7 @@ check_file_access(const int type, const char *file, const int mode, const char *
  * check_file_access() arguments.
  */
 static bool
-check_cmd_access(const int type, const char *command, const int mode, const char *opt)
+check_cmd_access(const char *command, const char *opt)
 {
   struct argv argv;
   bool return_code;
@@ -2705,7 +2705,11 @@ check_cmd_access(const int type, const char *command, const int mode, const char
 
   /* if an executable is specified then check it; otherwise, complain */
   if (argv.argv[0])
-      return_code = check_file_access(type, argv.argv[0], mode, opt);
+    /* Scripts requires R_OK as well, but that might fail on binaries which
+     * only requires X_OK to function on Unix - a scenario not unlikely to
+     * be seen on suid binaries.
+     */
+    return_code = check_file_access(CHKACC_FILE, argv.argv[0], X_OK, opt);
   else
     {
       msg (M_NOPREFIX|M_OPTERR, "%s fails with '%s': No path to executable.",
@@ -2797,26 +2801,26 @@ options_postprocess_filechecks (struct options *options)
 
   /* ** Script hooks that accept an optionally quoted and/or escaped executable path, ** */
   /* ** optionally followed by arguments ** */
-  errs |= check_cmd_access (CHKACC_FILE, options->auth_user_pass_verify_script,
-                            R_OK|X_OK, "--auth-user-pass-verify script");
-  errs |= check_cmd_access (CHKACC_FILE, options->client_connect_script,
-                            R_OK|X_OK, "--client-connect script");
-  errs |= check_cmd_access (CHKACC_FILE, options->client_disconnect_script,
-                            R_OK|X_OK, "--client-disconnect script");
-  errs |= check_cmd_access (CHKACC_FILE, options->tls_verify,
-                            R_OK|X_OK, "--tls-verify script");
-  errs |= check_cmd_access (CHKACC_FILE, options->up_script,
-                            R_OK|X_OK, "--up script");
-  errs |= check_cmd_access (CHKACC_FILE, options->down_script,
-                            R_OK|X_OK, "--down script");
-  errs |= check_cmd_access (CHKACC_FILE, options->ipchange,
-                            R_OK|X_OK, "--ipchange script");
-  errs |= check_cmd_access (CHKACC_FILE, options->route_script,
-                            R_OK|X_OK, "--route-up script");
-  errs |= check_cmd_access (CHKACC_FILE, options->route_predown_script,
-                            R_OK|X_OK, "--route-pre-down script");
-  errs |= check_cmd_access (CHKACC_FILE, options->learn_address_script,
-                            R_OK|X_OK, "--learn-address script");
+  errs |= check_cmd_access (options->auth_user_pass_verify_script,
+                            "--auth-user-pass-verify script");
+  errs |= check_cmd_access (options->client_connect_script,
+                            "--client-connect script");
+  errs |= check_cmd_access (options->client_disconnect_script,
+                            "--client-disconnect script");
+  errs |= check_cmd_access (options->tls_verify,
+                            "--tls-verify script");
+  errs |= check_cmd_access (options->up_script,
+                            "--up script");
+  errs |= check_cmd_access (options->down_script,
+                            "--down script");
+  errs |= check_cmd_access (options->ipchange,
+                            "--ipchange script");
+  errs |= check_cmd_access (options->route_script,
+                            "--route-up script");
+  errs |= check_cmd_access (options->route_predown_script,
+                            "--route-pre-down script");
+  errs |= check_cmd_access (options->learn_address_script,
+                            "--learn-address script");
 #endif /* P2MP_SERVER */
 
   if (errs)
Signature · 1 line
1.7.4.4
#1 lore raw

Looks good.
If you testing this one, please ensure symbolic links also works properly... :)

Quoted 103 lines · David Sommerseth

To avoid confusion between check_file_access() and check_cmd_access() in the future, remove unneeded arguments from check_cmd_access()

As a command will always be a file, it should always check for CHKACC_FILE and nothing else.  And as the commands always will need X_OK, check only for that.

One change from earlier behaviour is that R_OK is not checked for.  The reason is that only scripts require R_OK to work.  However, a system might be installed with binaries with only X_OK set.  If a script is missing R_OK, then the execution will fail due to lacking permissions.

---
 src/openvpn/options.c |   48 ++++++++++++++++++++++++++----------------------

 1 files changed, 26 insertions(+), 22 deletions(-)
src/openvpn/options.c +0 -0
index 5da2eb6..7769625 100644
@@ -2690,7 +2690,7 @@ check_file_access(const int type, const char *file, const int mode, const char *
  * check_file_access() arguments.
  */

 static bool

src/openvpn/options.c +1 -1
-check_cmd_access(const int type, const char *command, const int mode, const char *opt)
+check_cmd_access(const char *command, const char *opt)

 {
  struct argv argv;
  bool return_code;

src/openvpn/options.c +5 -1
@@ -2705,7 +2705,11 @@ check_cmd_access(const int type, const char *command, const int mode, const char
 
   /* if an executable is specified then check it; otherwise, complain */
   if (argv.argv[0])
-      return_code = check_file_access(type, argv.argv[0], mode, opt);
+    /* Scripts requires R_OK as well, but that might fail on binaries which
+     * only requires X_OK to function on Unix - a scenario not unlikely to
+     * be seen on suid binaries.
+     */
+    return_code = check_file_access(CHKACC_FILE, argv.argv[0], X_OK, opt);

  else
    {
      msg (M_NOPREFIX|M_OPTERR, "%s fails with '%s': No path to executable.",

src/openvpn/options.c +20 -21
@@ -2797,26 +2801,26 @@ options_postprocess_filechecks (struct options *options)
 
   /* ** Script hooks that accept an optionally quoted and/or escaped executable path, ** */
   /* ** optionally followed by arguments ** */
-  errs |= check_cmd_access (CHKACC_FILE, options->auth_user_pass_verify_script,
-                            R_OK|X_OK, "--auth-user-pass-verify script");
-  errs |= check_cmd_access (CHKACC_FILE, options->client_connect_script,
-                            R_OK|X_OK, "--client-connect script");
-  errs |= check_cmd_access (CHKACC_FILE, options->client_disconnect_script,
-                            R_OK|X_OK, "--client-disconnect script");
-  errs |= check_cmd_access (CHKACC_FILE, options->tls_verify,
-                            R_OK|X_OK, "--tls-verify script");
-  errs |= check_cmd_access (CHKACC_FILE, options->up_script,
-                            R_OK|X_OK, "--up script");
-  errs |= check_cmd_access (CHKACC_FILE, options->down_script,
-                            R_OK|X_OK, "--down script");
-  errs |= check_cmd_access (CHKACC_FILE, options->ipchange,
-                            R_OK|X_OK, "--ipchange script");
-  errs |= check_cmd_access (CHKACC_FILE, options->route_script,
-                            R_OK|X_OK, "--route-up script");
-  errs |= check_cmd_access (CHKACC_FILE, options->route_predown_script,
-                            R_OK|X_OK, "--route-pre-down script");
-  errs |= check_cmd_access (CHKACC_FILE, options->learn_address_script,
-                            R_OK|X_OK, "--learn-address script");
+  errs |= check_cmd_access (options->auth_user_pass_verify_script,
+                            "--auth-user-pass-verify script");
+  errs |= check_cmd_access (options->client_connect_script,
+                            "--client-connect script");
+  errs |= check_cmd_access (options->client_disconnect_script,
+                            "--client-disconnect script");
+  errs |= check_cmd_access (options->tls_verify,
+                            "--tls-verify script");
+  errs |= check_cmd_access (options->up_script,
+                            "--up script");
+  errs |= check_cmd_access (options->down_script,
+                            "--down script");
+  errs |= check_cmd_access (options->ipchange,
+                            "--ipchange script");
+  errs |= check_cmd_access (options->route_script,
+                            "--route-up script");
+  errs |= check_cmd_access (options->route_predown_script,
+                            "--route-pre-down script");
+  errs |= check_cmd_access (options->learn_address_script,
+                            "--learn-address script");
  #endif /* P2MP_SERVER */
 
   if (errs)
--

1.7.4.4

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Openvpn-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

#2 lore raw

Hi,

Quoted 2 lines · Alon Bar-Lev

Looks good.
If you testing this one, please ensure symbolic links also works properly... :)

The man page for access() (on Linux) states:

DESCRIPTION
access() checks whether the calling process can access the file path- name. If pathname is a symbolic link, it is dereferenced.
...
CONFORMING TO

       SVr4, 4.3BSD, POSIX.1-2001.

so it should work for symlinks, across all POSIX compliant platforms (even if the NetBSD and FreeBSD manpages do not mention anything about symlinks, except ELOOP).

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]...
#3 lore raw
In reply to Alon Bar-Lev

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 2 lines · Alon Bar-Lev

Looks good. If you testing this one, please ensure symbolic links also works properly... :)

Just to confirm, as I forgot to mention that in the 'applied' message earlier on. This was tested with symlinks on Linux. Both with a symlink pointing to a non-existing file and to a file which does exist. It all behaved as expected - wrong symlink gave a "no such file" error, otherwise the proper script was executed.

kind regards,

David Sommerseth

Quoted 81 lines
Quoted 79 lines · David Sommerseth

To avoid confusion between check_file_access() and check_cmd_access() in the future, remove unneeded arguments from check_cmd_access()

As a command will always be a file, it should always check for CHKACC_FILE and nothing else. And as the commands always will need X_OK, check only for that.

One change from earlier behaviour is that R_OK is not checked for. The reason is that only scripts require R_OK to work. However, a system might be installed with binaries with only X_OK set. If a script is missing R_OK, then the execution will fail due to lacking permissions.

src/openvpn/options.c | 48
++++++++++++++++++++++++++---------------------- 1 files changed, 26 insertions(+), 22 deletions(-)

src/openvpn/options.c index renamed from src/openvpn/options.c +0 -0

5da2eb6..7769625 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -2690,7 +2690,7 @@ check_file_access(const int type, const char *file, const int mode, const char * * check_file_access() arguments. */ static bool -check_cmd_access(const int type, const char *command, const int mode, const char *opt) +check_cmd_access(const char *command, const char *opt) { struct argv argv; bool return_code;

src/openvpn/options.c index renamed from src/openvpn/options.c +0 -0
@@ -2705,7 +2705,11 @@ check_cmd_access(const int type, const

char *command, const int mode, const char

/* if an executable is specified then check it; otherwise,
complain */ if (argv.argv[0]) - return_code =
check_file_access(type, argv.argv[0], mode, opt); + /*
Scripts requires R_OK as well, but that might fail on binaries which + * only requires X_OK to function on Unix - a scenario
not unlikely to + * be seen on suid binaries. + */ +
return_code = check_file_access(CHKACC_FILE, argv.argv[0], X_OK, opt); else { msg (M_NOPREFIX|M_OPTERR, "%s fails with '%s': No path to executable.", @@ -2797,26 +2801,26 @@ options_postprocess_filechecks (struct options *options)

/* ** Script hooks that accept an optionally quoted and/or escaped executable path, ** */ /* ** optionally followed by arguments ** */ - errs |= check_cmd_access (CHKACC_FILE, options->auth_user_pass_verify_script, - R_OK|X_OK, "--auth-user-pass-verify script"); - errs |= check_cmd_access (CHKACC_FILE, options->client_connect_script, - R_OK|X_OK, "--client-connect script"); - errs |= check_cmd_access (CHKACC_FILE, options->client_disconnect_script, - R_OK|X_OK, "--client-disconnect script"); - errs |= check_cmd_access (CHKACC_FILE, options->tls_verify, - R_OK|X_OK, "--tls-verify script"); - errs |= check_cmd_access (CHKACC_FILE, options->up_script, - R_OK|X_OK, "--up script"); - errs |= check_cmd_access (CHKACC_FILE, options->down_script, - R_OK|X_OK, "--down script"); - errs |= check_cmd_access (CHKACC_FILE, options->ipchange, - R_OK|X_OK, "--ipchange script"); - errs |= check_cmd_access (CHKACC_FILE, options->route_script, - R_OK|X_OK, "--route-up script"); - errs |= check_cmd_access (CHKACC_FILE, options->route_predown_script, - R_OK|X_OK, "--route-pre-down script"); - errs |= check_cmd_access (CHKACC_FILE, options->learn_address_script, - R_OK|X_OK, "--learn-address script"); + errs |= check_cmd_access (options->auth_user_pass_verify_script, + "--auth-user-pass-verify script"); + errs |= check_cmd_access (options->client_connect_script, + "--client-connect script"); + errs |= check_cmd_access (options->client_disconnect_script, + "--client-disconnect script"); + errs |= check_cmd_access
(options->tls_verify, + "--tls-verify
script"); + errs |= check_cmd_access (options->up_script, + "--up script"); + errs |= check_cmd_access
(options->down_script, + "--down
script"); + errs |= check_cmd_access (options->ipchange, + "--ipchange script"); + errs |= check_cmd_access
(options->route_script, + "--route-up
script"); + errs |= check_cmd_access (options->route_predown_script, + "--route-pre-down script"); + errs |= check_cmd_access (options->learn_address_script, + "--learn-address script"); #endif /* P2MP_SERVER */

Quoted 7 lines
Quoted 7 lines

if (errs) -- 1.7.4.4

------------------------------------------------------------------------------

Live Security Virtual Conference

Quoted 9 lines
Quoted 8 lines

Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats.
http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________ Openvpn-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Quoted 4 lines

------------------------------------------------------------------------------

Live Security Virtual Conference

Quoted 9 lines

Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats.
http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________ Openvpn-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk+iTTcACgkQDC186MBRfrrHowCePfFeXrX1XrvZ1kgWHyHxeUn/ 6n0Ani5Wc4jzQYPq68VswxbeN3LPBBfY
=GQ81
-----END PGP SIGNATURE-----

#4 lore raw
In reply to David Sommerseth

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 14 lines · David Sommerseth

To avoid confusion between check_file_access() and check_cmd_access() in the future, remove unneeded arguments from check_cmd_access()

As a command will always be a file, it should always check for CHKACC_FILE and nothing else. And as the commands always will need X_OK, check only for that.

One change from earlier behaviour is that R_OK is not checked for. The reason is that only scripts require R_OK to work. However, a system might be installed with binaries with only X_OK set. If a script is missing R_OK, then the execution will fail due to lacking permissions.

Quoted 4 lines

src/openvpn/options.c | 48
++++++++++++++++++++++++++---------------------- 1 files changed, 26 insertions(+), 22 deletions(-)

Applied to master branches on -testing and -stable trees.

commit 0576a9f2f8c8a7cf2d50579e6762df6c86b388c5

Author: David Sommerseth <[email protected]...>
Date:   Wed May 2 19:54:12 2012 +0200
    Simplify check_cmd_access() function

    Signed-off-by: David Sommerseth <[email protected]...>
    Acked-by: Alon Bar-Lev <[email protected]...>
    Message-Id: [email protected]...
    URL: http://article.gmane.org/gmane.network.openvpn.devel/6391

kind regards,

David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk+iNbgACgkQDC186MBRfrqS+QCgjAEP5G6I4ZuPIENYMZXSxMoo 3UQAn2jZpM5ufBNPimZLvd/XV5ahbKeI
=Xyxv
-----END PGP SIGNATURE-----