Source-Changes-HG archive

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

[src/trunk]: src/tests/modules Make use of the new MODCTL_EXISTS check to que...



details:   https://anonhg.NetBSD.org/src/rev/0feadb305de6
branches:  trunk
changeset: 780956:0feadb305de6
user:      martin <martin%NetBSD.org@localhost>
date:      Mon Aug 13 08:07:03 2012 +0000

description:
Make use of the new MODCTL_EXISTS check to query kernel wether (and why
not) we can load modules.

diffstat:

 tests/modules/t_modctl.c |  37 ++++++++++++++++++-------------------
 1 files changed, 18 insertions(+), 19 deletions(-)

diffs (106 lines):

diff -r 49ceef480bec -r 0feadb305de6 tests/modules/t_modctl.c
--- a/tests/modules/t_modctl.c  Mon Aug 13 02:53:25 2012 +0000
+++ b/tests/modules/t_modctl.c  Mon Aug 13 08:07:03 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_modctl.c,v 1.9 2012/04/17 06:23:52 jruoho Exp $      */
+/*     $NetBSD: t_modctl.c,v 1.10 2012/08/13 08:07:03 martin Exp $     */
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: t_modctl.c,v 1.9 2012/04/17 06:23:52 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: t_modctl.c,v 1.10 2012/08/13 08:07:03 martin Exp $");
 
 #include <sys/module.h>
 #include <sys/sysctl.h>
@@ -46,7 +46,7 @@
 
 enum presence_check { both_checks, stat_check, sysctl_check };
 
-static bool    skip_nonmodular(void);
+static void    check_permission(void);
 static bool    get_modstat_info(const char *, modstat_t *);
 static bool    get_sysctl(const char *, void *buf, const size_t);
 static bool    k_helper_is_present_stat(void);
@@ -61,12 +61,20 @@
 /* --------------------------------------------------------------------- */
 
 /*
- * A function that is called if the kernel is detected to be non-MODULAR.
+ * A function checking wether we are allowed to load modules currently
+ * (either the kernel is not modular, or securelevel may prevent it)
  */
-static bool
-skip_nonmodular(void)
+static void
+check_permission(void)
 {
-       atf_tc_skip("Kernel does not have 'options MODULAR'.");
+       int err;
+
+       err = modctl(MODCTL_EXISTS, 0);
+       if (err == ENOSYS)
+               atf_tc_skip("Kernel does not have 'options MODULAR'.");
+       else if (err == EPERM)
+               atf_tc_skip("Module loading administratively forbidden");
+       ATF_CHECK(err == 0);
 }
 
 static bool
@@ -77,6 +85,7 @@
        struct iovec iov;
        modstat_t *ms;
 
+       check_permission();
        for (len = 4096; ;) {
                iov.iov_base = malloc(len);
                iov.iov_len = len;
@@ -84,10 +93,6 @@
                errno = 0;
 
                if (modctl(MODCTL_STAT, &iov) != 0) {
-
-                       if (errno == ENOSYS)
-                               skip_nonmodular();
-
                        int err = errno;
                        fprintf(stderr, "modctl(MODCTL_STAT) failed: %s\n",
                            strerror(err));
@@ -203,6 +208,7 @@
        char filename[MAXPATHLEN], *propsstr;
        modctl_load_t ml;
 
+       check_permission();
        if (props == NULL) {
                props = prop_dictionary_create();
                propsstr = prop_dictionary_externalize(props);
@@ -226,10 +232,6 @@
        errno = err = 0;
 
        if (modctl(MODCTL_LOAD, &ml) == -1) {
-
-               if (errno == ENOSYS)
-                       skip_nonmodular();
-
                err = errno;
                fprintf(stderr, "modctl(MODCTL_LOAD, %s), failed: %s\n",
                    filename, strerror(err));
@@ -251,14 +253,11 @@
 {
        int err;
 
+       check_permission();
        printf("Unloading module %s\n", name);
        errno = err = 0;
 
        if (modctl(MODCTL_UNLOAD, __UNCONST(name)) == -1) {
-
-               if (errno == ENOSYS)
-                       skip_nonmodular();
-
                err = errno;
                fprintf(stderr, "modctl(MODCTL_UNLOAD, %s) failed: %s\n",
                    name, strerror(err));



Home | Main Index | Thread Index | Old Index