summaryrefslogtreecommitdiff
path: root/src/libimcv/imv/tables.sql
blob: b50c6ed12e34adf14b771a6b49dcba6ad956ef3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/* IMV PTS SQLite database */

DROP TABLE IF EXISTS directories;
CREATE TABLE directories (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  path TEXT NOT NULL
);
DROP INDEX IF EXISTS directories_path;
CREATE INDEX directories_path ON directories (
  path
);

DROP TABLE IF EXISTS files;
CREATE TABLE files (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  dir INTEGER DEFAULT 0 REFERENCES directories(id),
  name TEXT NOT NULL
);
DROP INDEX IF EXISTS files_name;
CREATE INDEX files_name ON files (
  name
);

DROP TABLE IF EXISTS products;
CREATE TABLE products (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  name TEXT NOT NULL
);
DROP INDEX IF EXISTS products_name;
CREATE INDEX products_name ON products (
  name
);

DROP TABLE IF EXISTS algorithms;
CREATE TABLE algorithms (
  id INTEGER PRIMARY KEY,
  name VARCHAR(20) not NULL
);

DROP TABLE IF EXISTS file_hashes;
CREATE TABLE file_hashes (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  file INTEGER NOT NULL REFERENCES files(id),
  version INTEGER REFERENCES versions(id),
  device INTEGER REFERENCES devices(id),
  size INTEGER,
  algo INTEGER NOT NULL REFERENCES algorithms(id),
  hash VARCHAR(64) NOT NULL,
  mutable INTEGER DEFAULT 0
);
DROP INDEX IF EXISTS "file_hashes_idx";
CREATE INDEX "file_hashes_idx" ON "file_hashes" ("file", "version", "algo");

DROP TABLE IF EXISTS groups;
CREATE TABLE groups (
  id INTEGER NOT NULL PRIMARY KEY,
  name VARCHAR(50) NOT NULL UNIQUE,
  parent INTEGER
);

DROP TABLE IF EXISTS groups_members;
CREATE TABLE groups_members (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  group_id INTEGER NOT NULL REFERENCES groups(id),
  device_id INTEGER NOT NULL REFERENCES devices(id),
  UNIQUE (group_id, device_id)
);

DROP TABLE IF EXISTS groups_product_defaults;
CREATE TABLE groups_product_defaults (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  group_id INTEGER NOT NULL REFERENCES groups(id),
  product_id INTEGER NOT NULL REFERENCES products(id),
  UNIQUE (group_id, product_id)
);

DROP TABLE IF EXISTS policies;
CREATE TABLE policies (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  type INTEGER NOT NULL,
  name VARCHAR(100) NOT NULL UNIQUE,
  argument TEXT DEFAULT '' NOT NULL,
  rec_fail INTEGER NOT NULL,
  rec_noresult INTEGER NOT NULL,
  file INTEGER DEFAULT 0 REFERENCES files(id),
  dir INTEGER DEFAULT 0 REFERENCES directories(id)
);

DROP TABLE IF EXISTS enforcements;
CREATE TABLE enforcements (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  policy INTEGER NOT NULL REFERENCES policies(id),
  group_id INTEGER NOT NULL REFERENCES groups(id),
  rec_fail INTEGER,
  rec_noresult INTEGER,
  max_age INTEGER NOT NULL,
  UNIQUE (policy, group_id)
);

DROP TABLE IF EXISTS sessions;
CREATE TABLE sessions (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  time INTEGER NOT NULL,
  connection INTEGER NOT NULL,
  identity INTEGER DEFAULT 0 REFERENCES identities(id),
  device INTEGER DEFAULT 0 REFERENCES devices(id),
  product INTEGER DEFAULT 0 REFERENCES products(id),
  rec INTEGER DEFAULT 3
);

DROP TABLE IF EXISTS sessions_identities;
CREATE TABLE sessions_identities (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  session_id INTEGER NOT NULL REFERENCES sessions(id),
  identity_id INTEGER NOT NULL REFERENCES identities(id),
  UNIQUE (session_id, identity_id)
);

DROP TABLE IF EXISTS workitems;
CREATE TABLE workitems (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  session INTEGER NOT NULL REFERENCES sessions(id),
  enforcement INTEGER NOT NULL REFERENCES enforcements(id),
  type INTEGER NOT NULL,
  arg_str TEXT,
  arg_int INTEGER DEFAULT 0,
  rec_fail INTEGER NOT NULL,
  rec_noresult INTEGER NOT NULL,
  rec_final INTEGER,
  result TEXT
);
DROP INDEX IF EXISTS workitems_session;
CREATE INDEX workitems_sessions ON workitems (
  session
);

DROP TABLE IF EXISTS results;
CREATE TABLE results (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  session INTEGER NOT NULL REFERENCES measurements(id),
  policy INTEGER NOT NULL REFERENCES policies(id),
  rec INTEGER NOT NULL,
  result TEXT NOT NULL
);
DROP INDEX IF EXISTS results_session;
CREATE INDEX results_session ON results (
  session
);

DROP TABLE IF EXISTS components;
CREATE TABLE components (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  vendor_id INTEGER NOT NULL,
  name INTEGER NOT NULL,
  qualifier INTEGER DEFAULT 0,
  label TEXT NOT NULL
);

DROP TABLE IF EXISTS component_hashes;
CREATE TABLE component_hashes (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  component INTEGER NOT NULL REFERENCES components(id),
  key INTEGER NOT NULL REFERENCES devices(id),
  seq_no INTEGER NOT NULL,
  pcr INTEGER NOT NULL,
  algo INTEGER NOT NULL REFERENCES algorithms(id),
  hash BLOB NOT NULL
);

DROP TABLE IF EXISTS packages;
CREATE TABLE packages (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  name TEXT NOT NULL,
  blacklist INTEGER DEFAULT 0
);
DROP INDEX IF EXISTS packages_name;
CREATE INDEX packages_name ON packages (
  name
);

DROP TABLE IF EXISTS versions;
CREATE TABLE versions (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  product INTEGER NOT NULL REFERENCES products(id),
  package INTEGER NOT NULL REFERENCES packages(id),
  release TEXT,
  security INTEGER DEFAULT 0,
  blacklist INTEGER DEFAULT 0,
  time INTEGER DEFAULT 0
);
DROP INDEX IF EXISTS versions_release;
CREATE INDEX versions_release ON versions (
  release
);
DROP INDEX IF EXISTS versions_package_product;
CREATE INDEX versions_package_product ON versions (
  package, product
);

DROP TABLE IF EXISTS devices;
CREATE TABLE devices (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  description TEXT DEFAULT '',
  value TEXT NOT NULL,
  product INTEGER REFERENCES products(id),
  trusted INTEGER DEFAULT 0,
  created INTEGER
);
DROP INDEX IF EXISTS devices_id;
CREATE INDEX devices_value ON devices (
  value
);

DROP TABLE IF EXISTS identities;
CREATE TABLE identities (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  type INTEGER NOT NULL,
  value BLOB NOT NULL,
  UNIQUE (type, value)
);

DROP TABLE IF EXISTS "swid_entities";
CREATE TABLE "swid_entities" (
  "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  "name" VARCHAR(255) NOT NULL,
  "regid" VARCHAR(255) NOT NULL
);
DROP INDEX IF EXISTS "swid_entities_name";
DROP INDEX IF EXISTS "swid_entities_regid";
CREATE INDEX "swid_entities_name" ON "swid_entities" (
  "name"
);
CREATE INDEX "swid_entities_regid" ON "swid_entities" (
  "regid"
);

DROP TABLE IF EXISTS "swid_entityroles";
CREATE TABLE "swid_entityroles" (
  "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  "tag_id" INTEGER NOT NULL REFERENCES "swid_tags" ("id"),
  "entity_id" INTEGER NOT NULL,
  "role" SMALLINT UNSIGNED NOT NULL
);
DROP INDEX if EXISTS "swid_entityroles_tag_id";
DROP INDEX IF EXISTS "swid_entityroles_tag_entity_id";
CREATE INDEX "swid_entityroles_tag_id" ON "swid_entityroles" (
  "tag_id"
);
CREATE INDEX "swid_entityroles_entity_id" ON "swid_entityroles" (
  "entity_id"
);

DROP TABLE IF EXISTS "swid_tags";
CREATE TABLE "swid_tags" (
  "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  "version_id" INTEGER REFERENCES "versions" ("id"),
  "package_name" VARCHAR(255) NOT NULL,
  "version_str" VARCHAR(255) NOT NULL,
  "unique_id" VARCHAR(255) NOT NULL,
  "swid_xml" TEXT NOT NULL,
  "software_id" VARCHAR(255) NOT NULL
);
DROP INDEX IF EXISTS "swid_tags_software_id";
DROP INDEX if EXISTS "swid_tags_unique_id";
DROP INDEX IF EXISTS "swid_tags_version";
DROP INDEX IF EXISTS "swid_tags_package_name";

CREATE INDEX "swid_tags_software_id" ON "swid_tags" (
  "software_id"
);
CREATE INDEX "swid_tags_unique_id" ON "swid_tags" (
  "unique_id"
);
CREATE INDEX "swid_tags_version_id" ON "swid_tags" (
  "version_id"
);
CREATE INDEX "swid_tags_package_name" ON "swid_tags" (
  "package_name"
);

DROP TABLE IF EXISTS "swid_tags_files";
CREATE TABLE "swid_tags_files" (
  "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  "tag_id" INTEGER NOT NULL,
  "file_id" INTEGER NOT NULL REFERENCES "files" ("id"),
  UNIQUE ("tag_id", "file_id")
);
DROP INDEX IF EXISTS "swid_tags_files_file_id";
DROP INDEX IF EXISTS "swid_tags_files_tag_id";
CREATE INDEX "swid_tags_files_file_id" ON "swid_tags_files" (
  "file_id"
);
CREATE INDEX "swid_tags_files_tag_id" ON "swid_tags_files" (
  "tag_id"
);

DROP TABLE IF EXISTS "swid_tags_sessions";
CREATE TABLE "swid_tags_sessions" (
  "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  "tag_id" INTEGER NOT NULL,
  "session_id" INTEGER NOT NULL REFERENCES "sessions" ("id"),
  UNIQUE ("tag_id", "session_id")
);
DROP INDEX IF EXISTS "swid_tags_sessions_tag_id";
DROP INDEX IF EXISTS "swid_tags_sessions_session_id";
CREATE INDEX "swid_tags_sessions_tag_id" ON "swid_tags_sessions" (
  "tag_id"
);
CREATE INDEX "swid_tags_sessions_session_id" ON "swid_tags_sessions" (
"session_id"
);

DROP TABLE IF EXISTS "swid_tagstats";
CREATE TABLE "swid_tagstats" (
  "id" INTEGER NOT NULL PRIMARY KEY,
  "tag_id" INTEGER NOT NULL REFERENCES "swid_tags" ("id"),
  "device_id" INTEGER NOT NULL REFERENCES "devices" ("id"),
  "first_seen_id" INTEGER NOT NULL REFERENCES "sessions" ("id"),
  "last_seen_id" INTEGER NOT NULL REFERENCES "sessions" ("id"),
  "first_installed_id" INTEGER REFERENCES "swid_events" ("id"),
  "last_deleted_id" INTEGER REFERENCES "swid_events" ("id"),
  UNIQUE ("tag_id", "device_id")
);
CREATE INDEX "swid_tagstats_tag_id" ON "swid_tagstats" ("tag_id");
CREATE INDEX "swid_tagstats_device_id" ON "swid_tagstats" ("device_id");
CREATE INDEX "swid_tagstats_first_seen_id" ON "swid_tagstats" ("first_seen_id");
CREATE INDEX "swid_tagstats_last_seen_id" ON "swid_tagstats" ("last_seen_id");

DROP TABLE IF EXISTS "swid_events";
CREATE TABLE "swid_events" (
  "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  "device" INTEGER REFERENCES "devices" ("id"),
  "epoch" INTEGER NOT NULL,
  "eid" INTEGER NOT NULL,
  "timestamp" CHAR(20) NOT NULL
);
DROP INDEX IF EXISTS "swid_events_device";
CREATE INDEX "swid_events_device" ON "swid_events" (
  "device"
);

DROP TABLE IF EXISTS "swid_tags_events";
CREATE TABLE "swid_tags_events" (
  "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  "tag_id" INTEGER NOT NULL REFERENCES "swid_tags" ("id"),
  "event_id" INTEGER NOT NULL REFERENCES "swid_events" ("id"),
  "action" INTEGER NOT NULL,
  "record_id" INTEGER DEFAULT 0,
  "source_id" INTEGER DEFAULT 0
);
DROP INDEX IF EXISTS "swid_tags_events_event_id";
DROP INDEX IF EXISTS "swid_tags_events_tag_id";
CREATE INDEX "swid_tags_events_event_id" ON "swid_tags_events" (
  "event_id"
);
CREATE INDEX "swid_tags_events_tag_id" ON "swid_tags_events" (
  "tag_id"
);