Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libc/sys Refactor code in ATF ptrace(...



details:   https://anonhg.NetBSD.org/src/rev/f160bf662fda
branches:  trunk
changeset: 319022:f160bf662fda
user:      kamil <kamil%NetBSD.org@localhost>
date:      Sun May 13 23:01:25 2018 +0000
description:
Refactor code in ATF ptrace(2) tests

Move the can_we_set_dbregs() auxiliary function from t_ptrace_x86_wait.h
to a common file t_ptrace_wait.h. This allows using this function for
checking whether the DBREGS set operations in ptrace(2) are accessible for
a user.

Sponsored by <The NetBSD Foundation>

diffstat:

 tests/lib/libc/sys/t_ptrace_wait.h     |  31 ++++++++++++++++++++++++++++++-
 tests/lib/libc/sys/t_ptrace_x86_wait.h |  29 +----------------------------
 2 files changed, 31 insertions(+), 29 deletions(-)

diffs (88 lines):

diff -r f6e55e7290c9 -r f160bf662fda tests/lib/libc/sys/t_ptrace_wait.h
--- a/tests/lib/libc/sys/t_ptrace_wait.h        Sun May 13 22:58:58 2018 +0000
+++ b/tests/lib/libc/sys/t_ptrace_wait.h        Sun May 13 23:01:25 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_ptrace_wait.h,v 1.3 2018/04/28 17:56:55 kamil Exp $  */
+/*     $NetBSD: t_ptrace_wait.h,v 1.4 2018/05/13 23:01:25 kamil Exp $  */
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -409,6 +409,35 @@
        }
 }
 
+#if defined(HAVE_DBREGS)
+static bool
+can_we_set_dbregs(void)
+{
+       static long euid = -1;
+       static int user_set_dbregs  = -1;
+       size_t user_set_dbregs_len = sizeof(user_set_dbregs);
+
+       if (euid == -1)
+               euid = geteuid();
+
+       if (euid == 0)
+               return true;
+
+       if (user_set_dbregs == -1) {
+               if (sysctlbyname("security.models.extensions.user_set_dbregs",
+                       &user_set_dbregs, &user_set_dbregs_len, NULL, 0)
+                       == -1) {
+                       return false;
+               }
+       }
+
+       if (user_set_dbregs > 0)
+               return true;
+       else
+               return false;
+}
+#endif
+
 #if defined(TWAIT_HAVE_PID)
 #define ATF_TP_ADD_TC_HAVE_PID(a,b)    ATF_TP_ADD_TC(a,b)
 #else
diff -r f6e55e7290c9 -r f160bf662fda tests/lib/libc/sys/t_ptrace_x86_wait.h
--- a/tests/lib/libc/sys/t_ptrace_x86_wait.h    Sun May 13 22:58:58 2018 +0000
+++ b/tests/lib/libc/sys/t_ptrace_x86_wait.h    Sun May 13 23:01:25 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_ptrace_x86_wait.h,v 1.5 2018/04/08 17:20:18 kamil Exp $      */
+/*     $NetBSD: t_ptrace_x86_wait.h,v 1.6 2018/05/13 23:01:25 kamil Exp $      */
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -57,33 +57,6 @@
        } bits;
 };
 
-static bool
-can_we_set_dbregs(void)
-{
-       static long euid = -1;
-       static int user_set_dbregs  = -1;
-       size_t user_set_dbregs_len = sizeof(user_set_dbregs);
-
-       if (euid == -1)
-               euid = geteuid();
-
-       if (euid == 0)
-               return true;
-
-       if (user_set_dbregs == -1) {
-               if (sysctlbyname("security.models.extensions.user_set_dbregs",
-                       &user_set_dbregs, &user_set_dbregs_len, NULL, 0)
-                       == -1) {
-                       return false;
-               }
-       }
-
-       if (user_set_dbregs > 0)
-               return true;
-       else
-               return false;
-}
-
 ATF_TC(dbregs_print);
 ATF_TC_HEAD(dbregs_print, tc)
 {



Home | Main Index | Thread Index | Old Index