moved measurement and metadata flags to product_file table

This commit is contained in:
Andreas Steffen
2011-11-28 21:23:59 +01:00
parent 3e93e28427
commit dac976296c
5 changed files with 176 additions and 167 deletions
+3 -4
View File
@@ -87,6 +87,9 @@ attest_db_t *attest;
static void cleanup(void)
{
attest->destroy(attest);
libpts_deinit();
libimcv_deinit();
closelog();
}
static void do_args(int argc, char *argv[])
@@ -296,10 +299,6 @@ int main(int argc, char *argv[])
do_args(argc, argv);
libpts_deinit();
libimcv_deinit();
closelog();
exit(EXIT_SUCCESS);
}
+54 -32
View File
@@ -382,15 +382,26 @@ METHOD(attest_db_t, list_files, void,
{
enumerator_t *e;
char *file;
int fid, is_dir, count = 0;
int fid, is_dir, meas, meta, count = 0;
if (this->pid)
{
e = this->db->query(this->db,
"SELECT f.id, f.type, f.path FROM files AS f "
"SELECT f.id, f.type, f.path, pf.measurement, pf.metadata "
"FROM files AS f "
"JOIN product_file AS pf ON f.id = pf.file "
"WHERE pf.product = ? ORDER BY f.path",
DB_INT, this->pid, DB_INT, DB_INT, DB_TEXT);
DB_INT, this->pid, DB_INT, DB_INT, DB_TEXT, DB_INT, DB_INT);
if (e)
{
while (e->enumerate(e, &fid, &is_dir, &file, &meas, &meta))
{
printf("%3d: |%s%s| %s %s\n", fid, meas ? "M":" ", meta ? "T":" ",
is_dir ? "d":" ", file);
count++;
}
e->destroy(e);
}
}
else
{
@@ -398,23 +409,23 @@ METHOD(attest_db_t, list_files, void,
"SELECT id, type, path FROM files "
"ORDER BY path",
DB_INT, DB_INT, DB_TEXT);
}
if (e)
{
while (e->enumerate(e, &fid, &is_dir, &file))
if (e)
{
printf("%3d: %s %s\n", fid, is_dir ? "d":" ", file);
count++;
while (e->enumerate(e, &fid, &is_dir, &file))
{
printf("%3d: %s %s\n", fid, is_dir ? "d":" ", file);
count++;
}
e->destroy(e);
}
e->destroy(e);
}
printf("%d file%s found", count, (count == 1) ? "" : "s");
if (this->product)
{
printf(" for product '%s'", this->product);
}
printf("\n");
printf("%d file%s found", count, (count == 1) ? "" : "s");
if (this->product)
{
printf(" for product '%s'", this->product);
}
printf("\n");
}
METHOD(attest_db_t, list_products, void,
@@ -422,38 +433,49 @@ METHOD(attest_db_t, list_products, void,
{
enumerator_t *e;
char *product;
int pid, count = 0;
int pid, meas, meta, count = 0;
if (this->fid)
{
e = this->db->query(this->db,
"SELECT p.id, p.name FROM products AS p "
"SELECT p.id, p.name, pf.measurement, pf.metadata "
"FROM products AS p "
"JOIN product_file AS pf ON p.id = pf.product "
"WHERE pf.file = ? ORDER BY p.name",
DB_INT, this->fid, DB_INT, DB_TEXT);
DB_INT, this->fid, DB_INT, DB_TEXT, DB_INT, DB_INT);
if (e)
{
while (e->enumerate(e, &pid, &product, &meas, &meta))
{
printf("%3d: |%s%s| %s\n", pid, meas ? "M":" ", meta ? "T":" ",
product);
count++;
}
e->destroy(e);
}
}
else
{
e = this->db->query(this->db, "SELECT id, name FROM products "
"ORDER BY name",
DB_INT, DB_TEXT);
}
if (e)
{
while (e->enumerate(e, &pid, &product))
if (e)
{
printf("%3d: %s\n", pid, product);
count++;
while (e->enumerate(e, &pid, &product))
{
printf("%3d: %s\n", pid, product);
count++;
}
e->destroy(e);
}
e->destroy(e);
}
printf("%d product%s found", count, (count == 1) ? "" : "s");
if (this->file)
{
printf(" for file '%s'", this->file);
}
printf("\n");
printf("%d product%s found", count, (count == 1) ? "" : "s");
if (this->file)
{
printf(" for file '%s'", this->file);
}
printf("\n");
}
/**
+114 -126
View File
@@ -45,135 +45,135 @@ INSERT INTO products (
/* Files */
INSERT INTO files ( /* 1 */
type, path, measurement
type, path
) VALUES (
0, '/lib/i386-linux-gnu/libdl.so.2', 1
0, '/lib/i386-linux-gnu/libdl.so.2'
);
INSERT INTO files (
type, path, measurement
type, path
) VALUES (
0, '/lib/x86_64-linux-gnu/libdl.so.2', 1
0, '/lib/x86_64-linux-gnu/libdl.so.2'
);
INSERT INTO files (
type, path, measurement
type, path
) VALUES (
0, '/lib/libdl.so.2', 1
0, '/lib/libdl.so.2'
);
INSERT INTO files (
type, path, measurement
type, path
) VALUES (
0, '/sbin/iptables', 1
0, '/sbin/iptables'
);
INSERT INTO files ( /* 5 */
type, path, measurement
type, path
) VALUES (
0, '/lib/libxtables.so.5', 1
0, '/lib/libxtables.so.5'
);
INSERT INTO files (
type, path, measurement
type, path
) VALUES (
0, '/lib/libxtables.so.2', 1
0, '/lib/libxtables.so.2'
);
INSERT INTO files (
type, path, measurement
type, path
) VALUES (
1, '/lib/xtables/', 1
1, '/lib/xtables/'
);
INSERT INTO files (
type, path, measurement
type, path
) VALUES (
0, 'libxt_udp.so', 1
0, 'libxt_udp.so'
);
INSERT INTO files (
type, path, measurement
type, path
) VALUES (
0, 'libxt_tcp.so', 1
0, 'libxt_tcp.so'
);
INSERT INTO files ( /* 10 */
type, path, measurement
type, path
) VALUES (
0, 'libxt_esp.so', 1
0, 'libxt_esp.so'
);
INSERT INTO files (
type, path, measurement
type, path
) VALUES (
0, 'libxt_policy.so', 1
0, 'libxt_policy.so'
);
INSERT INTO files (
type, path, measurement
type, path
) VALUES (
0, 'libxt_conntrack.so', 1
0, 'libxt_conntrack.so'
);
INSERT INTO files (
type, path, measurement
type, path
) VALUES (
0, 'libipt_SNAT.so', 1
0, 'libipt_SNAT.so'
);
INSERT INTO files (
type, path, measurement
type, path
) VALUES (
0, 'libipt_DNAT.so', 1
0, 'libipt_DNAT.so'
);
INSERT INTO files ( /* 15 */
type, path, measurement
type, path
) VALUES (
0, 'libipt_MASQUERADE.so', 1
0, 'libipt_MASQUERADE.so'
);
INSERT INTO files (
type, path, measurement
type, path
) VALUES (
0, 'libipt_LOG.so', 1
0, 'libipt_LOG.so'
);
INSERT INTO files (
type, path, measurement
type, path
) VALUES (
0, '/sbin/ip6tables', 1
0, '/sbin/ip6tables'
);
INSERT INTO files (
type, path, measurement
type, path
) VALUES (
0, 'libip6t_LOG.so', 1
0, 'libip6t_LOG.so'
);
INSERT INTO files (
type, path, measurement
type, path
) VALUES (
0, 'libxt_mark.so', 1
0, 'libxt_mark.so'
);
INSERT INTO files ( /* 20 */
type, path, measurement
type, path
) VALUES (
0, 'libxt_MARK.so', 1
0, 'libxt_MARK.so'
);
INSERT INTO files (
type, path, measurement
type, path
) VALUES (
1, '/lib/iptables', 1
1, '/lib/iptables'
);
INSERT INTO files (
type, path, metadata
type, path
) VALUES (
0, '/etc/tnc_config', 1
0, '/etc/tnc_config'
);
INSERT INTO files (
@@ -337,225 +337,213 @@ INSERT INTO components (
/* Product-File */
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
1, 1
1, 1, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
1, 4
1, 4, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
1, 5
1, 5, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
1, 7
1, 7, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
1, 17
1, 17, 1
);
INSERT INTO product_file (
product, file
product, file, metadata
) VALUES (
1, 22
1, 22, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
2, 2
2, 2, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
2, 4
2, 4, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
2, 5
2, 5, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
2, 7
2, 7, 1
);
INSERT INTO product_file (
product, file
product, file, metadata
) VALUES (
2, 22
2, 22, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
3, 3
3, 3, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
3, 4
3, 4, 1
);
INSERT INTO product_file (
product, file
product, file, metadata
) VALUES (
3, 22
3, 22, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
4, 3
4, 3, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
4, 4
4, 4, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
4, 6
4, 6, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
4, 7
4, 7, 1
);
INSERT INTO product_file (
product, file
product, file, metadata
) VALUES (
4, 22
4, 22, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
4, 23
5, 3, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
4, 24
5, 4, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
5, 3
5, 6, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
5, 4
5, 7, 1
);
INSERT INTO product_file (
product, file
product, file, metadata
) VALUES (
5, 6
5, 22, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
5, 7
6, 3, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
5, 22
6, 4, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
6, 3
6, 17, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
6, 4
6, 21, 1
);
INSERT INTO product_file (
product, file
product, file, metadata
) VALUES (
6, 17
6, 22, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
6, 21
7, 1, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
6, 22
7, 4, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
7, 1
7, 5, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
7, 4
7, 7, 1
);
INSERT INTO product_file (
product, file
product, file, measurement
) VALUES (
7, 5
7, 17, 1
);
INSERT INTO product_file (
product, file
product, file, metadata
) VALUES (
7, 7
);
INSERT INTO product_file (
product, file
) VALUES (
7, 17
);
INSERT INTO product_file (
product, file
) VALUES (
7, 22
7, 22, 1
);
/* Product Component */
@@ -4,9 +4,7 @@ DROP TABLE IF EXISTS files;
CREATE TABLE files (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
type INTEGER NOT NULL,
path TEXT NOT NULL,
measurement INTEGER DEFAULT 0,
metadata INTEGER DEFAULT 0
path TEXT NOT NULL
);
DROP TABLE IF EXISTS components;
@@ -31,6 +29,8 @@ DROP TABLE IF EXISTS product_file;
CREATE TABLE product_file (
product INTEGER NOT NULL,
file INTEGER NOT NULL,
measurement INTEGER DEFAULT 0,
metadata INTEGER DEFAULT 0,
PRIMARY KEY (product, file)
);
+2 -2
View File
@@ -49,7 +49,7 @@ METHOD(pts_database_t, create_file_meas_enumerator, enumerator_t*,
"SELECT f.id, f.type, f.path FROM files AS f "
"JOIN product_file AS pf ON f.id = pf.file "
"JOIN products AS p ON p.id = pf.product "
"WHERE p.name = ? AND f.measurement = 1",
"WHERE p.name = ? AND pf.measurement = 1",
DB_TEXT, product, DB_INT, DB_INT, DB_TEXT);
return e;
}
@@ -64,7 +64,7 @@ METHOD(pts_database_t, create_file_meta_enumerator, enumerator_t*,
"SELECT f.type, f.path FROM files AS f "
"JOIN product_file AS pf ON f.id = pf.file "
"JOIN products AS p ON p.id = pf.product "
"WHERE p.name = ? AND f.metadata = 1",
"WHERE p.name = ? AND pf.metadata = 1",
DB_TEXT, product, DB_INT, DB_TEXT);
return e;
}