2006-11-29 04:12:00 +03:00
|
|
|
/* $NetBSD: veriexecctl.c,v 1.26 2006/11/29 01:12:00 elad Exp $ */
|
2002-11-23 13:52:49 +03:00
|
|
|
|
|
|
|
/*-
|
2006-11-21 03:22:04 +03:00
|
|
|
* Copyright 2005 Elad Efrat <elad@NetBSD.org>
|
2005-04-20 17:44:45 +04:00
|
|
|
* Copyright 2005 Brett Lymn <blymn@netbsd.org>
|
|
|
|
*
|
2002-11-23 13:52:49 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code has been donated to The NetBSD Foundation by the Author.
|
|
|
|
*
|
|
|
|
* 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. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software withough specific prior written permission
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-04-20 17:44:45 +04:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/verified_exec.h>
|
2006-07-15 03:00:09 +04:00
|
|
|
#include <sys/statvfs.h>
|
2002-11-23 13:52:49 +03:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2002-12-06 05:26:14 +03:00
|
|
|
#include <stdlib.h>
|
2005-04-20 17:44:45 +04:00
|
|
|
#include <string.h>
|
2002-11-23 13:52:49 +03:00
|
|
|
#include <fcntl.h>
|
2005-04-20 17:44:45 +04:00
|
|
|
#include <unistd.h>
|
2004-03-06 14:57:14 +03:00
|
|
|
#include <err.h>
|
2005-04-20 17:44:45 +04:00
|
|
|
#include <errno.h>
|
2006-11-29 04:12:00 +03:00
|
|
|
#include <inttypes.h>
|
2005-04-20 17:44:45 +04:00
|
|
|
|
2006-11-29 01:22:02 +03:00
|
|
|
#include <prop/proplib.h>
|
|
|
|
|
2005-04-20 17:44:45 +04:00
|
|
|
#include "veriexecctl.h"
|
|
|
|
|
|
|
|
#define VERIEXEC_DEVICE "/dev/veriexec"
|
2004-03-06 14:57:14 +03:00
|
|
|
|
2006-11-29 01:22:02 +03:00
|
|
|
extern prop_dictionary_t load_params;
|
|
|
|
extern char *filename;
|
2005-06-13 19:18:44 +04:00
|
|
|
extern int yynerrs;
|
2005-05-21 00:06:34 +04:00
|
|
|
int gfd, verbose = 0, phase;
|
2005-04-21 16:45:12 +04:00
|
|
|
size_t line;
|
2002-11-23 13:52:49 +03:00
|
|
|
|
2005-04-20 17:44:45 +04:00
|
|
|
/*
|
|
|
|
* Prototypes
|
|
|
|
*/
|
2005-04-21 16:45:12 +04:00
|
|
|
static FILE *openlock(const char *);
|
|
|
|
static void phase1_preload(void);
|
|
|
|
static int fingerprint_load(char*);
|
|
|
|
static void usage(void) __attribute__((__noreturn__));
|
2005-04-21 15:21:58 +04:00
|
|
|
|
2005-04-21 16:45:12 +04:00
|
|
|
static FILE *
|
2005-04-20 17:44:45 +04:00
|
|
|
openlock(const char *path)
|
2002-11-23 13:52:49 +03:00
|
|
|
{
|
2005-04-21 15:21:58 +04:00
|
|
|
int lfd;
|
2005-04-20 17:44:45 +04:00
|
|
|
|
2005-04-21 16:45:12 +04:00
|
|
|
if ((lfd = open(path, O_RDONLY|O_EXLOCK, 0)) == -1)
|
|
|
|
return NULL;
|
2005-04-20 17:44:45 +04:00
|
|
|
|
2005-04-21 16:45:12 +04:00
|
|
|
return fdopen(lfd, "r");
|
2005-04-20 17:44:45 +04:00
|
|
|
}
|
|
|
|
|
2005-05-21 00:06:34 +04:00
|
|
|
struct veriexec_up *
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
dev_lookup(char *vfs)
|
2005-04-20 17:44:45 +04:00
|
|
|
{
|
2005-05-21 00:06:34 +04:00
|
|
|
struct veriexec_up *p;
|
2005-04-20 17:44:45 +04:00
|
|
|
|
2005-04-21 16:45:12 +04:00
|
|
|
CIRCLEQ_FOREACH(p, ¶ms_list, vu_list)
|
2006-11-29 01:22:02 +03:00
|
|
|
if (strcmp(dict_gets(p->vu_preload, "mount"), vfs) == 0)
|
2005-04-20 17:44:45 +04:00
|
|
|
return (p);
|
|
|
|
|
2005-04-21 16:45:12 +04:00
|
|
|
return NULL;
|
2005-04-20 17:44:45 +04:00
|
|
|
}
|
|
|
|
|
2005-05-21 00:06:34 +04:00
|
|
|
struct veriexec_up *
|
2006-07-15 03:00:09 +04:00
|
|
|
dev_add(char *vfs)
|
2005-04-20 17:44:45 +04:00
|
|
|
{
|
2005-05-21 00:06:34 +04:00
|
|
|
struct veriexec_up *up;
|
2005-04-20 17:44:45 +04:00
|
|
|
|
2005-04-21 16:45:12 +04:00
|
|
|
if ((up = calloc((size_t)1, sizeof(*up))) == NULL)
|
2005-04-20 17:44:45 +04:00
|
|
|
err(1, "No memory");
|
|
|
|
|
2006-11-29 01:22:02 +03:00
|
|
|
up->vu_preload = prop_dictionary_create();
|
|
|
|
|
|
|
|
dict_sets(up->vu_preload, "mount", vfs);
|
|
|
|
prop_dictionary_set_uint64(up->vu_preload, "count", 1);
|
2005-04-20 17:44:45 +04:00
|
|
|
|
|
|
|
CIRCLEQ_INSERT_TAIL(¶ms_list, up, vu_list);
|
|
|
|
|
2005-04-21 16:45:12 +04:00
|
|
|
return up;
|
2005-04-20 17:44:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Load all devices, get rid of the list. */
|
2005-04-21 16:45:12 +04:00
|
|
|
static void
|
2005-04-20 17:44:45 +04:00
|
|
|
phase1_preload(void)
|
|
|
|
{
|
|
|
|
if (verbose)
|
|
|
|
printf("Phase 1: Calculating hash table sizes:\n");
|
|
|
|
|
|
|
|
while (!CIRCLEQ_EMPTY(¶ms_list)) {
|
2005-05-21 00:06:34 +04:00
|
|
|
struct veriexec_up *vup;
|
2006-07-15 03:00:09 +04:00
|
|
|
struct statvfs sv;
|
2005-04-20 17:44:45 +04:00
|
|
|
|
|
|
|
vup = CIRCLEQ_FIRST(¶ms_list);
|
|
|
|
|
2006-11-29 01:22:02 +03:00
|
|
|
if (statvfs(dict_gets(vup->vu_preload, "mount"), &sv) != 0)
|
|
|
|
err(1, "Can't statvfs() `%s'",
|
|
|
|
dict_gets(vup->vu_preload, "mount"));
|
2006-07-15 03:00:09 +04:00
|
|
|
|
2006-11-29 01:22:02 +03:00
|
|
|
if (prop_dictionary_send_ioctl(vup->vu_preload, gfd,
|
|
|
|
VERIEXEC_TABLESIZE) == -1) {
|
2005-06-03 17:21:35 +04:00
|
|
|
if (errno != EEXIST)
|
|
|
|
err(1, "Error in phase 1: Can't "
|
2006-07-15 03:00:09 +04:00
|
|
|
"set hash table size for mount `%s'",
|
|
|
|
sv.f_mntonname);
|
2005-06-03 17:21:35 +04:00
|
|
|
}
|
2005-04-20 17:44:45 +04:00
|
|
|
|
|
|
|
if (verbose) {
|
2006-11-29 01:22:02 +03:00
|
|
|
uint64_t count;
|
|
|
|
|
|
|
|
prop_dictionary_get_uint64(vup->vu_preload, "count",
|
|
|
|
&count);
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
printf(" => Hash table sizing successful for mount "
|
2006-11-29 04:12:00 +03:00
|
|
|
"`%s'. (%" PRIu64 " entries)\n", sv.f_mntonname,
|
|
|
|
count);
|
2005-04-20 17:44:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
CIRCLEQ_REMOVE(¶ms_list, vup, vu_list);
|
2006-11-29 01:22:02 +03:00
|
|
|
|
|
|
|
prop_object_release(vup->vu_preload);
|
|
|
|
|
2005-04-20 17:44:45 +04:00
|
|
|
free(vup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load the fingerprint. Assumes that the fingerprint pseudo-device is
|
2005-04-21 15:21:58 +04:00
|
|
|
* opened and the file handle is in gfd.
|
2005-04-20 17:44:45 +04:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
phase2_load(void)
|
|
|
|
{
|
2006-11-29 01:22:02 +03:00
|
|
|
uint8_t t;
|
|
|
|
|
2005-10-05 17:48:48 +04:00
|
|
|
/*
|
|
|
|
* If there's no access type specified, use the default.
|
|
|
|
*/
|
2006-11-29 01:22:02 +03:00
|
|
|
prop_dictionary_get_uint8(load_params, "entry-type", &t);
|
|
|
|
if (!(t & (VERIEXEC_DIRECT|VERIEXEC_INDIRECT|VERIEXEC_FILE))) {
|
|
|
|
t |= VERIEXEC_DIRECT;
|
|
|
|
prop_dictionary_set_uint8(load_params, "entry-type", t);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prop_dictionary_send_ioctl(load_params, gfd, VERIEXEC_LOAD) == -1)
|
|
|
|
warn("Cannot load params from `%s'",
|
|
|
|
dict_gets(load_params, "file"));
|
|
|
|
|
|
|
|
prop_object_release(load_params);
|
|
|
|
|
|
|
|
load_params = NULL;
|
2005-04-20 17:44:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fingerprint load handling.
|
|
|
|
*/
|
2005-04-21 16:45:12 +04:00
|
|
|
static int
|
2005-04-21 15:21:58 +04:00
|
|
|
fingerprint_load(char *ifile)
|
2005-04-20 17:44:45 +04:00
|
|
|
{
|
|
|
|
CIRCLEQ_INIT(¶ms_list);
|
2002-11-23 13:52:49 +03:00
|
|
|
|
2005-04-21 16:45:12 +04:00
|
|
|
if ((yyin = openlock(ifile)) == NULL)
|
|
|
|
err(1, "Cannot open `%s'", ifile);
|
2002-11-23 13:52:49 +03:00
|
|
|
|
2005-04-20 17:44:45 +04:00
|
|
|
/*
|
|
|
|
* Phase 1: Scan all config files, creating the list of devices
|
|
|
|
* we have fingerprinted files on, and the amount of
|
|
|
|
* files per device. Lock all files to maintain sync.
|
|
|
|
*/
|
|
|
|
phase = 1;
|
|
|
|
|
|
|
|
if (verbose) {
|
2005-04-21 16:45:12 +04:00
|
|
|
(void)printf("Phase 1: Building hash table information:\n");
|
|
|
|
(void)printf("=> Parsing \"%s\"\n", ifile);
|
2005-04-20 17:44:45 +04:00
|
|
|
}
|
|
|
|
|
2005-06-13 19:18:44 +04:00
|
|
|
line = 1;
|
2005-04-20 17:44:45 +04:00
|
|
|
yyparse();
|
2005-06-13 19:18:44 +04:00
|
|
|
if (yynerrs)
|
|
|
|
return -1;
|
2005-04-20 17:44:45 +04:00
|
|
|
|
2005-04-21 16:45:12 +04:00
|
|
|
phase1_preload();
|
2005-04-20 17:44:45 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Phase 2: After we have a circular queue containing all the
|
|
|
|
* devices we care about and the sizes for the hash
|
|
|
|
* tables, do a rescan, this time actually loading the
|
|
|
|
* file data.
|
|
|
|
*/
|
|
|
|
rewind(yyin);
|
|
|
|
phase = 2;
|
|
|
|
if (verbose) {
|
2005-04-21 16:45:12 +04:00
|
|
|
(void)printf("Phase 2: Loading per-file fingerprints.\n");
|
|
|
|
(void)printf("=> Parsing \"%s\"\n", ifile);
|
2002-11-23 13:52:49 +03:00
|
|
|
}
|
|
|
|
|
2005-06-13 19:18:44 +04:00
|
|
|
line = 1;
|
2002-11-23 13:52:49 +03:00
|
|
|
yyparse();
|
2005-04-20 17:44:45 +04:00
|
|
|
|
2005-04-21 16:45:12 +04:00
|
|
|
(void)fclose(yyin);
|
2005-04-20 17:44:45 +04:00
|
|
|
|
2005-04-21 16:45:12 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2005-06-01 22:29:16 +04:00
|
|
|
(void)fprintf(stderr, "Usage: %s [-v] [load <signature_file>]\n",
|
2005-05-20 23:52:52 +04:00
|
|
|
getprogname());
|
2005-04-21 16:45:12 +04:00
|
|
|
exit(1);
|
2005-04-20 17:44:45 +04:00
|
|
|
}
|
|
|
|
|
2005-12-13 00:47:58 +03:00
|
|
|
static void
|
|
|
|
print_flags(unsigned char flags)
|
|
|
|
{
|
|
|
|
char buf[64];
|
|
|
|
|
|
|
|
if (!flags) {
|
|
|
|
printf("<none>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
|
|
|
|
while (flags) {
|
|
|
|
if (*buf)
|
|
|
|
strlcat(buf, ", ", sizeof(buf));
|
|
|
|
|
|
|
|
if (flags & VERIEXEC_DIRECT) {
|
|
|
|
strlcat(buf, "direct", sizeof(buf));
|
|
|
|
flags &= ~VERIEXEC_DIRECT;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (flags & VERIEXEC_INDIRECT) {
|
|
|
|
strlcat(buf, "indirect", sizeof(buf));
|
|
|
|
flags &= ~VERIEXEC_INDIRECT;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (flags & VERIEXEC_FILE) {
|
|
|
|
strlcat(buf, "file", sizeof(buf));
|
|
|
|
flags &= ~VERIEXEC_FILE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (flags & VERIEXEC_UNTRUSTED) {
|
|
|
|
strlcat(buf, "untrusted", sizeof(buf));
|
|
|
|
flags &= ~VERIEXEC_UNTRUSTED;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("%s\n", buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-11-29 01:22:02 +03:00
|
|
|
print_query(prop_dictionary_t qp, char *file)
|
2005-12-13 00:47:58 +03:00
|
|
|
{
|
2006-07-15 03:00:09 +04:00
|
|
|
struct statvfs sv;
|
2006-11-29 01:22:02 +03:00
|
|
|
const char *v;
|
2005-12-13 00:47:58 +03:00
|
|
|
int i;
|
2006-11-29 01:22:02 +03:00
|
|
|
uint8_t u8;
|
2005-12-13 00:47:58 +03:00
|
|
|
|
2006-07-15 03:00:09 +04:00
|
|
|
if (statvfs(file, &sv) != 0)
|
|
|
|
err(1, "Can't statvfs() `%s'\n", file);
|
|
|
|
|
2005-12-13 00:47:58 +03:00
|
|
|
printf("Filename: %s\n", file);
|
2006-07-15 03:00:09 +04:00
|
|
|
printf("Mount: %s\n", sv.f_mntonname);
|
2005-12-13 00:47:58 +03:00
|
|
|
printf("Entry flags: ");
|
2006-11-29 01:22:02 +03:00
|
|
|
prop_dictionary_get_uint8(qp, "entry-type", &u8);
|
|
|
|
print_flags(u8);
|
|
|
|
prop_dictionary_get_uint8(qp, "status", &u8);
|
|
|
|
printf("Entry status: %s\n", STATUS_STRING(u8));
|
|
|
|
printf("Fingerprint algorithm: %s\n", dict_gets(qp, "fp-type"));
|
2005-12-13 00:47:58 +03:00
|
|
|
printf("Fingerprint: ");
|
2006-11-29 01:22:02 +03:00
|
|
|
v = dict_getd(qp, "fp");
|
|
|
|
for (i = 0; i < prop_data_size(prop_dictionary_get(qp, "fp")); i++)
|
|
|
|
printf("%02x", v[i] & 0xff);
|
2005-12-13 00:47:58 +03:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2005-04-20 17:44:45 +04:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
2005-04-21 16:45:12 +04:00
|
|
|
setprogname(argv[0]);
|
2005-04-20 17:44:45 +04:00
|
|
|
|
2005-04-21 16:45:12 +04:00
|
|
|
while ((c = getopt(argc, argv, "v")) != -1)
|
2005-04-20 17:44:45 +04:00
|
|
|
switch (c) {
|
|
|
|
case 'v':
|
|
|
|
verbose = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2005-04-21 16:45:12 +04:00
|
|
|
usage();
|
2005-04-20 17:44:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
2005-04-21 16:45:12 +04:00
|
|
|
if ((gfd = open(VERIEXEC_DEVICE, O_RDWR, 0)) == -1)
|
|
|
|
err(1, "Cannot open `%s'", VERIEXEC_DEVICE);
|
2005-04-20 17:44:45 +04:00
|
|
|
|
2005-05-20 23:52:52 +04:00
|
|
|
/*
|
|
|
|
* Handle the different commands we can do.
|
|
|
|
*/
|
2005-04-21 16:45:12 +04:00
|
|
|
if (argc == 2 && strcasecmp(argv[0], "load") == 0) {
|
2006-11-29 01:22:02 +03:00
|
|
|
load_params = NULL;
|
2005-04-20 17:44:45 +04:00
|
|
|
filename = argv[1];
|
|
|
|
fingerprint_load(argv[1]);
|
2005-12-10 05:10:00 +03:00
|
|
|
} else if (argc == 2 && strcasecmp(argv[0], "delete") == 0) {
|
2006-11-29 01:22:02 +03:00
|
|
|
prop_dictionary_t dp;
|
2005-12-10 05:10:00 +03:00
|
|
|
struct stat sb;
|
|
|
|
|
|
|
|
if (stat(argv[1], &sb) == -1)
|
|
|
|
err(1, "Can't stat `%s'", argv[1]);
|
|
|
|
|
2006-11-29 01:22:02 +03:00
|
|
|
dp = prop_dictionary_create();
|
|
|
|
dict_sets(dp, "file", argv[1]);
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
|
2005-12-10 05:10:00 +03:00
|
|
|
/*
|
|
|
|
* If it's a regular file, remove it. If it's a directory,
|
|
|
|
* remove the entire table. If it's neither, abort.
|
|
|
|
*/
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
if (!S_ISDIR(sb.st_mode) && !S_ISREG(sb.st_mode))
|
2005-12-10 05:10:00 +03:00
|
|
|
errx(1, "`%s' is not a regular file or directory.", argv[1]);
|
|
|
|
|
2006-11-29 01:22:02 +03:00
|
|
|
if (prop_dictionary_send_ioctl(dp, gfd, VERIEXEC_DELETE) == -1)
|
2005-12-10 05:10:00 +03:00
|
|
|
err(1, "Error deleting `%s'", argv[1]);
|
2006-11-29 01:22:02 +03:00
|
|
|
|
|
|
|
prop_object_release(dp);
|
2005-12-13 00:47:58 +03:00
|
|
|
} else if (argc == 2 && strcasecmp(argv[0], "query") == 0) {
|
2006-11-29 01:22:02 +03:00
|
|
|
prop_dictionary_t qp, rqp;
|
2005-12-13 00:47:58 +03:00
|
|
|
struct stat sb;
|
|
|
|
|
|
|
|
if (stat(argv[1], &sb) == -1)
|
|
|
|
err(1, "Can't stat `%s'", argv[1]);
|
|
|
|
if (!S_ISREG(sb.st_mode))
|
|
|
|
errx(1, "`%s' is not a regular file.", argv[1]);
|
|
|
|
|
2006-11-29 01:22:02 +03:00
|
|
|
qp = prop_dictionary_create();
|
okay, since there was no way to divide this to two commits, here it goes..
introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.
this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.
as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.
also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.
tons of input from yamt@, wrstuden@, martin@, and christos@.
2006-07-14 22:41:40 +04:00
|
|
|
|
2006-11-29 01:22:02 +03:00
|
|
|
dict_sets(qp, "file", argv[1]);
|
2005-12-13 00:47:58 +03:00
|
|
|
|
2006-11-29 01:22:02 +03:00
|
|
|
if (prop_dictionary_sendrecv_ioctl(qp, gfd, VERIEXEC_QUERY,
|
|
|
|
&rqp) == -1)
|
2005-12-13 00:47:58 +03:00
|
|
|
err(1, "Error querying `%s'", argv[1]);
|
|
|
|
|
2006-11-29 01:22:02 +03:00
|
|
|
if (rqp != NULL) {
|
|
|
|
print_query(rqp, argv[1]);
|
|
|
|
prop_object_release(rqp);
|
|
|
|
}
|
|
|
|
|
|
|
|
prop_object_release(qp);
|
2005-04-21 16:45:12 +04:00
|
|
|
} else
|
|
|
|
usage();
|
2005-04-20 17:44:45 +04:00
|
|
|
|
2005-04-21 16:45:12 +04:00
|
|
|
(void)close(gfd);
|
|
|
|
return 0;
|
2002-11-23 13:52:49 +03:00
|
|
|
}
|