Source-Changes-HG archive

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

[src/trunk]: src/sbin/cgdconfig * allow specification of kernel operations ve...



details:   https://anonhg.NetBSD.org/src/rev/6eb0c434a377
branches:  trunk
changeset: 747302:6eb0c434a377
user:      pooka <pooka%NetBSD.org@localhost>
date:      Tue Sep 08 21:36:35 2009 +0000

description:
* allow specification of kernel operations vector
* make it possible to build cgdconfig as a library

diffstat:

 sbin/cgdconfig/Makefile           |  16 ++----------
 sbin/cgdconfig/Makefile.cgdconfig |  24 +++++++++++++++++++
 sbin/cgdconfig/cgd_kernelops.c    |  47 +++++++++++++++++++++++++++++++++++++++
 sbin/cgdconfig/cgd_kernelops.h    |  45 +++++++++++++++++++++++++++++++++++++
 sbin/cgdconfig/cgdconfig.c        |  35 +++++++++++++++++++---------
 5 files changed, 142 insertions(+), 25 deletions(-)

diffs (287 lines):

diff -r e75fdace8c5d -r 6eb0c434a377 sbin/cgdconfig/Makefile
--- a/sbin/cgdconfig/Makefile   Tue Sep 08 21:34:57 2009 +0000
+++ b/sbin/cgdconfig/Makefile   Tue Sep 08 21:36:35 2009 +0000
@@ -1,20 +1,10 @@
-# $NetBSD: Makefile,v 1.11 2009/04/20 16:05:30 drochner Exp $
+# $NetBSD: Makefile,v 1.12 2009/09/08 21:36:35 pooka Exp $
 
 PROG=  cgdconfig
 MAN=   cgdconfig.8
 
-SRCS=  cgdconfig.c             \
-       cgdlex.l                \
-       cgdparse.y              \
-       pkcs5_pbkdf2.c          \
-       params.c                \
-       utils.c
+SRCS+= cgd_kernelops.c
 
-CPPFLAGS+= -I${.CURDIR} -I. -DYY_NO_INPUT
-
-YHEADER=1
-
-DPADD=  ${LIBUTIL} ${LIBCRYPTO} ${LIBCRYPT} ${LIBY} ${LIBL}
-LDADD=  -lutil -lcrypto -lcrypt -ly -ll
+.include "${.CURDIR}/Makefile.cgdconfig"
 
 .include <bsd.prog.mk>
diff -r e75fdace8c5d -r 6eb0c434a377 sbin/cgdconfig/Makefile.cgdconfig
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/cgdconfig/Makefile.cgdconfig Tue Sep 08 21:36:35 2009 +0000
@@ -0,0 +1,24 @@
+#      $NetBSD: Makefile.cgdconfig,v 1.1 2009/09/08 21:36:35 pooka Exp $
+#
+
+SRCS+= cgdconfig.c             \
+       cgdlex.l                \
+       cgdparse.y              \
+       pkcs5_pbkdf2.c          \
+       params.c                \
+       utils.c
+
+CPPFLAGS+= -I${.CURDIR} -I. -DYY_NO_INPUT
+
+YHEADER=1
+
+DPADD=  ${LIBUTIL} ${LIBCRYPTO} ${LIBCRYPT} ${LIBY} ${LIBL}
+LDADD=  -lutil -lcrypto -lcrypt -ly -ll
+
+.include <bsd.own.mk>
+
+CGDCONFIGDIR=  ${NETBSDSRCDIR}/sbin/cgdconfig
+
+.PATH: ${CGDCONFIGDIR}
+
+CPPFLAGS+=     -I${CGDCONFIGDIR}
diff -r e75fdace8c5d -r 6eb0c434a377 sbin/cgdconfig/cgd_kernelops.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/cgdconfig/cgd_kernelops.c    Tue Sep 08 21:36:35 2009 +0000
@@ -0,0 +1,47 @@
+/*     $NetBSD: cgd_kernelops.c,v 1.1 2009/09/08 21:36:35 pooka Exp $  */
+
+/*
+ * Copyright (c) 2009 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: cgd_kernelops.c,v 1.1 2009/09/08 21:36:35 pooka Exp $");
+#endif /* !lint */
+
+#include <sys/types.h>
+#include <sys/ioctl.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "cgd_kernelops.h"
+
+const struct cgd_kernelops cgd_kops = {
+       .ko_open = (void *)open, /* XXX: rump_syscalls prototype */
+       .ko_ioctl = (void *)ioctl,
+       .ko_pread = pread,
+       .ko_close = close,
+};
diff -r e75fdace8c5d -r 6eb0c434a377 sbin/cgdconfig/cgd_kernelops.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/cgdconfig/cgd_kernelops.h    Tue Sep 08 21:36:35 2009 +0000
@@ -0,0 +1,45 @@
+/*      $NetBSD: cgd_kernelops.h,v 1.1 2009/09/08 21:36:35 pooka Exp $ */
+
+/*
+ * Copyright (c) 2009 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _CGD_KERNEL_OPS_H_
+#define _CGD_KERNEL_OPS_H_
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <fcntl.h>
+
+struct cgd_kernelops {
+       int (*ko_open)(const char *, int, mode_t);
+       int (*ko_ioctl)(int, unsigned long, void *);
+       int (*ko_close)(int);
+       int (*ko_pread)(int, void *, size_t, off_t);
+};
+extern const struct cgd_kernelops cgd_kops;
+
+#endif /* _CGD_KERNEL_OPS_H_ */
diff -r e75fdace8c5d -r 6eb0c434a377 sbin/cgdconfig/cgdconfig.c
--- a/sbin/cgdconfig/cgdconfig.c        Tue Sep 08 21:34:57 2009 +0000
+++ b/sbin/cgdconfig/cgdconfig.c        Tue Sep 08 21:36:35 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cgdconfig.c,v 1.27 2008/07/24 19:07:36 christos Exp $ */
+/* $NetBSD: cgdconfig.c,v 1.28 2009/09/08 21:36:35 pooka Exp $ */
 
 /*-
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 2002, 2003\
  The NetBSD Foundation, Inc.  All rights reserved.");
-__RCSID("$NetBSD: cgdconfig.c,v 1.27 2008/07/24 19:07:36 christos Exp $");
+__RCSID("$NetBSD: cgdconfig.c,v 1.28 2009/09/08 21:36:35 pooka Exp $");
 #endif
 
 #include <err.h>
@@ -59,6 +59,8 @@
 #include "params.h"
 #include "pkcs5_pbkdf2.h"
 #include "utils.h"
+#include "cgd_kernelops.h"
+#include "cgdconfig.h"
 
 #define CGDCONFIG_DIR          "/etc/cgd"
 #define CGDCONFIG_CFILE                CGDCONFIG_DIR "/cgd.conf"
@@ -168,9 +170,18 @@
        *action = value;
 }
 
+#ifndef CGDCONFIG_AS_LIB
 int
 main(int argc, char **argv)
 {
+
+       return cgdconfig(argc, argv);
+}
+#endif
+
+int
+cgdconfig(int argc, char *argv[])
+{
        struct params *p;
        struct params *tp;
        struct keygen *kg;
@@ -447,7 +458,7 @@
        if (flags == CONFIG_FLAGS_FROMALL && (argc < 2 || argc > 3))
                return -1;
 
-       fd = opendisk(*argv, O_RDWR, buf, sizeof(buf), 1);
+       fd = opendisk1(*argv, O_RDWR, buf, sizeof(buf), 1, cgd_kops.ko_open);
        if (fd == -1) {
                int saved_errno = errno;
 
@@ -464,7 +475,7 @@
                return 0;
 
        ret = unconfigure_fd(fd);
-       (void)close(fd);
+       (void)cgd_kops.ko_close(fd);
        return ret;
 }
 
@@ -473,7 +484,7 @@
 {
        struct  cgd_ioctl ci;
 
-       if (ioctl(fd, CGDIOCCLR, &ci) == -1) {
+       if (cgd_kops.ko_ioctl(fd, CGDIOCCLR, &ci) == -1) {
                warn("ioctl");
                return -1;
        }
@@ -572,7 +583,7 @@
                        break;
 
                (void)unconfigure_fd(fd);
-               (void)close(fd);
+               (void)cgd_kops.ko_close(fd);
 
                if (!loop) {
                        warnx("verification failed permanently");
@@ -583,11 +594,11 @@
        }
 
        params_free(p);
-       (void)close(fd);
+       (void)cgd_kops.ko_close(fd);
        return 0;
 bail_err:
        params_free(p);
-       (void)close(fd);
+       (void)cgd_kops.ko_close(fd);
        return -1;
 }
 
@@ -646,7 +657,7 @@
                return 0;
        }
 
-       fd = opendisk(cgd, O_RDWR, buf, buflen, 0);
+       fd = opendisk1(cgd, O_RDWR, buf, buflen, 0, cgd_kops.ko_open);
        if (fd == -1)
                warnx("can't open cgd \"%s\", \"%s\"", cgd, buf);
 
@@ -680,7 +691,7 @@
        if (nflag)
                return 0;
 
-       if (ioctl(fd, CGDIOCSET, &ci) == -1) {
+       if (cgd_kops.ko_ioctl(fd, CGDIOCSET, &ci) == -1) {
                int saved_errno = errno;
                warn("ioctl");
                return saved_errno;
@@ -728,7 +739,7 @@
         * partition information.
         */
 
-       ret = pread(fd, buf, 8192, 0);
+       ret = cgd_kops.ko_pread(fd, buf, 8192, 0);
        if (ret < 0) {
                warn("can't read disklabel area");
                return -1;
@@ -753,7 +764,7 @@
                } u;
                ssize_t ret;
 
-               ret = pread(fd, &u, sizeof(u), sblock_try[i]);
+               ret = cgd_kops.ko_pread(fd, &u, sizeof(u), sblock_try[i]);
                if (ret < 0) {
                        warn("pread");
                        break;



Home | Main Index | Thread Index | Old Index