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 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
|
/**
* @file
*
* Test policy loading capabilities that were introduced in SETools
* 3.2.
*
* @author Jeremy A. Mowery jmowery@tresys.com
* @author Jason Tang jtang@tresys.com
*
* Copyright (C) 2007-2008 Tresys Technology, LLC
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <config.h>
#include <CUnit/CUnit.h>
#include <qpol/policy.h>
#include <stdbool.h>
#define POLICY_ROOT TEST_POLICIES "/policy-versions"
struct capability_answer
{
const char *policy_name;
int policy_type;
unsigned int policy_version;
bool has_attributes;
bool has_syn_rules;
bool has_line_numbers;
bool has_conditionals;
bool has_mls;
bool has_polcaps;
bool has_source;
bool has_modules;
char *enforcing_type, *permissive_type;
};
static void capability_test(const struct capability_answer *ca)
{
qpol_policy_t *q = NULL;
int policy_type = qpol_policy_open_from_file(ca->policy_name, &q, NULL, NULL, QPOL_POLICY_OPTION_NO_NEVERALLOWS);
CU_ASSERT_FATAL(policy_type >= 0);
CU_ASSERT_EQUAL(policy_type, ca->policy_type);
unsigned policy_version;
int retval;
retval = qpol_policy_get_policy_version(q, &policy_version);
CU_ASSERT_EQUAL_FATAL(retval, 0);
CU_ASSERT_EQUAL(policy_version, ca->policy_version);
bool cap;
cap = (bool) qpol_policy_has_capability(q, QPOL_CAP_ATTRIB_NAMES);
CU_ASSERT_EQUAL(cap, ca->has_attributes);
cap = (bool) qpol_policy_has_capability(q, QPOL_CAP_SYN_RULES);
CU_ASSERT_EQUAL(cap, ca->has_syn_rules);
cap = (bool) qpol_policy_has_capability(q, QPOL_CAP_LINE_NUMBERS);
CU_ASSERT_EQUAL(cap, ca->has_line_numbers);
cap = (bool) qpol_policy_has_capability(q, QPOL_CAP_CONDITIONALS);
CU_ASSERT_EQUAL(cap, ca->has_conditionals);
cap = (bool) qpol_policy_has_capability(q, QPOL_CAP_MLS);
CU_ASSERT_EQUAL(cap, ca->has_mls);
cap = (bool) qpol_policy_has_capability(q, QPOL_CAP_POLCAPS);
CU_ASSERT_EQUAL(cap, ca->has_polcaps);
cap = (bool) qpol_policy_has_capability(q, QPOL_CAP_SOURCE);
CU_ASSERT_EQUAL(cap, ca->has_source);
cap = (bool) qpol_policy_has_capability(q, QPOL_CAP_MODULES);
CU_ASSERT_EQUAL(cap, ca->has_modules);
unsigned char ispermissive;
const qpol_type_t *type;
if (ca->enforcing_type != NULL) {
retval = qpol_policy_get_type_by_name(q, ca->enforcing_type, &type);
CU_ASSERT(retval == 0 && type != NULL);
retval = qpol_type_get_ispermissive(q, type, &ispermissive);
CU_ASSERT(retval == 0 && ispermissive == 0);
}
if (ca->permissive_type != NULL) {
retval = qpol_policy_get_type_by_name(q, ca->permissive_type, &type);
CU_ASSERT(retval == 0 && type != NULL);
retval = qpol_type_get_ispermissive(q, type, &ispermissive);
CU_ASSERT(retval == 0 && ispermissive == 1);
}
qpol_policy_destroy(&q);
}
static void capability_v12_source(void)
{
struct capability_answer cap = {
POLICY_ROOT "/policy-12.conf",
QPOL_POLICY_KERNEL_SOURCE, // policy type
12U, // policy version
true, // has attributes
true, // has syntactic rules
true, // has line numbers
false, // has conditionals
false, // has mls
false, // has policy capabilities
true, // has source
false, // has modules
"fs_t", NULL // enforcing / permissive types
};
capability_test(&cap);
}
static void capability_v15_source(void)
{
struct capability_answer cap = {
POLICY_ROOT "/policy-15.conf",
QPOL_POLICY_KERNEL_SOURCE, // policy type
15U, // policy version
true, // has attributes
true, // has syntactic rules
true, // has line numbers
false, // has conditionals
false, // has mls
false, // has policy capabilities
true, // has source
false, // has modules
"fs_t", NULL // enforcing / permissive types
};
capability_test(&cap);
}
static void capability_v15_binary(void)
{
struct capability_answer cap = {
POLICY_ROOT "/policy.15",
QPOL_POLICY_KERNEL_BINARY, // policy type
15U, // policy version
false, // has attributes
false, // has syntactic rules
false, // has line numbers
false, // has conditionals
false, // has mls
false, // has policy capabilities
false, // has source
false, // has modules
"fs_t", NULL // enforcing / permissive types
};
capability_test(&cap);
}
static void capability_v16_source(void)
{
struct capability_answer cap = {
POLICY_ROOT "/policy-16.conf",
QPOL_POLICY_KERNEL_SOURCE, // policy type
16U, // policy version
true, // has attributes
true, // has syntactic rules
true, // has line numbers
true, // has conditionals
false, // has mls
false, // has policy capabilities
true, // has source
false, // has modules
"fs_t", NULL // enforcing / permissive types
};
capability_test(&cap);
}
static void capability_v16_binary(void)
{
struct capability_answer cap = {
POLICY_ROOT "/policy.16",
QPOL_POLICY_KERNEL_BINARY, // policy type
16U, // policy version
false, // has attributes
false, // has syntactic rules
false, // has line numbers
true, // has conditionals
false, // has mls
false, // has policy capabilities
false, // has source
false, // has modules
"fs_t", NULL // enforcing / permissive types
};
capability_test(&cap);
}
static void capability_v17_source(void)
{
struct capability_answer cap = {
POLICY_ROOT "/policy-17.conf",
QPOL_POLICY_KERNEL_SOURCE, // policy type
17U, // policy version
true, // has attributes
true, // has syntactic rules
true, // has line numbers
true, // has conditionals
false, // has mls
false, // has policy capabilities
true, // has source
false, // has modules
"fs_t", NULL // enforcing / permissive types
};
capability_test(&cap);
}
static void capability_v17_binary(void)
{
struct capability_answer cap = {
POLICY_ROOT "/policy.17",
QPOL_POLICY_KERNEL_BINARY, // policy type
17U, // policy version
false, // has attributes
false, // has syntactic rules
false, // has line numbers
true, // has conditionals
false, // has mls
false, // has policy capabilities
false, // has source
false, // has modules
"fs_t", NULL // enforcing / permissive types
};
capability_test(&cap);
}
static void capability_v18_source(void)
{
struct capability_answer cap = {
POLICY_ROOT "/policy-18.conf",
QPOL_POLICY_KERNEL_SOURCE, // policy type
18U, // policy version
true, // has attributes
true, // has syntactic rules
true, // has line numbers
true, // has conditionals
false, // has mls
false, // has policy capabilities
true, // has source
false, // has modules
"wing_t", NULL // enforcing / permissive types
};
capability_test(&cap);
}
static void capability_v18_binary(void)
{
struct capability_answer cap = {
POLICY_ROOT "/policy.18",
QPOL_POLICY_KERNEL_BINARY, // policy type
18U, // policy version
false, // has attributes
false, // has syntactic rules
false, // has line numbers
true, // has conditionals
false, // has mls
false, // has policy capabilities
false, // has source
false, // has modules
"wing_t", NULL // enforcing / permissive types
};
capability_test(&cap);
}
static void capability_v19_binary(void)
{
struct capability_answer cap = {
POLICY_ROOT "/policy.19",
QPOL_POLICY_KERNEL_BINARY, // policy type
19U, // policy version
false, // has attributes
false, // has syntactic rules
false, // has line numbers
true, // has conditionals
false, // has mls
false, // has policy capabilities
false, // has source
false, // has modules
"wing_t", NULL // enforcing / permissive types
};
capability_test(&cap);
}
static void capability_v19_binary_mls(void)
{
struct capability_answer cap = {
POLICY_ROOT "/policy-mls.19",
QPOL_POLICY_KERNEL_BINARY, // policy type
19U, // policy version
false, // has attributes
false, // has syntactic rules
false, // has line numbers
true, // has conditionals
true, // has mls
false, // has policy capabilities
false, // has source
false, // has modules
"root_t", NULL // enforcing / permissive types
};
capability_test(&cap);
}
static void capability_v20_binary(void)
{
struct capability_answer cap = {
POLICY_ROOT "/policy.20",
QPOL_POLICY_KERNEL_BINARY, // policy type
20U, // policy version
false, // has attributes
false, // has syntactic rules
false, // has line numbers
true, // has conditionals
false, // has mls
false, // has policy capabilities
false, // has source
false, // has modules
"wing_t", NULL // enforcing / permissive types
};
capability_test(&cap);
}
static void capability_v20_binary_mls(void)
{
struct capability_answer cap = {
POLICY_ROOT "/policy-mls.20",
QPOL_POLICY_KERNEL_BINARY, // policy type
20U, // policy version
false, // has attributes
false, // has syntactic rules
false, // has line numbers
true, // has conditionals
true, // has mls
false, // has policy capabilities
false, // has source
false, // has modules
"root_t", NULL // enforcing / permissive types
};
capability_test(&cap);
}
static void capability_v21_source(void)
{
struct capability_answer cap = {
POLICY_ROOT "/policy-mls-21.conf",
QPOL_POLICY_KERNEL_SOURCE, // policy type
21U, // policy version
true, // has attributes
true, // has syntactic rules
true, // has line numbers
true, // has conditionals
true, // has mls
false, // has policy capabilities
true, // has source
false, // has modules
"root_t", NULL // enforcing / permissive types
};
capability_test(&cap);
}
static void capability_v21_binary(void)
{
struct capability_answer cap = {
POLICY_ROOT "/policy-mls.21",
QPOL_POLICY_KERNEL_BINARY, // policy type
21U, // policy version
false, // has attributes
false, // has syntactic rules
false, // has line numbers
true, // has conditionals
true, // has mls
false, // has policy capabilities
false, // has source
false, // has modules
"root_t", NULL // enforcing / permissive types
};
capability_test(&cap);
}
static void capability_v22_source(void)
{
struct capability_answer cap = {
POLICY_ROOT "/policy-mls-22.conf",
QPOL_POLICY_KERNEL_SOURCE, // policy type
22U, // policy version
true, // has attributes
true, // has syntactic rules
true, // has line numbers
true, // has conditionals
true, // has mls
true, // has policy capabilities
true, // has source
false, // has modules
"root_t", NULL // enforcing / permissive types
};
capability_test(&cap);
}
static void capability_v22_binary(void)
{
struct capability_answer cap = {
POLICY_ROOT "/policy-mls.22",
QPOL_POLICY_KERNEL_BINARY, // policy type
22U, // policy version
false, // has attributes
false, // has syntactic rules
false, // has line numbers
true, // has conditionals
true, // has mls
true, // has policy capabilities
false, // has source
false, // has modules
"root_t", NULL // enforcing / permissive types
};
capability_test(&cap);
}
static void capability_v23_source(void)
{
struct capability_answer cap = {
POLICY_ROOT "/policy-mls-23.conf",
QPOL_POLICY_KERNEL_SOURCE, // policy type
23U, // policy version
true, // has attributes
true, // has syntactic rules
true, // has line numbers
true, // has conditionals
true, // has mls
true, // has policy capabilities
true, // has source
false, // has modules
"root_t", "system_t" // enforcing / permissive types
};
capability_test(&cap);
}
static void capability_v23_binary(void)
{
struct capability_answer cap = {
POLICY_ROOT "/policy-mls.23",
QPOL_POLICY_KERNEL_BINARY, // policy type
23U, // policy version
false, // has attributes
false, // has syntactic rules
false, // has line numbers
true, // has conditionals
true, // has mls
true, // has policy capabilities
false, // has source
false, // has modules
"root_t", "system_t" // enforcing / permissive types
};
capability_test(&cap);
}
static void capability_modv6_base_binary(void)
{
struct capability_answer cap = {
POLICY_ROOT "/base-6.pp",
QPOL_POLICY_MODULE_BINARY, // policy type
6U, // policy version
true, // has attributes
true, // has syntactic rules
false, // has line numbers
true, // has conditionals
true, // has mls
false, // has policy capabilities
false, // has source
true, // has modules
"root_t", NULL // enforcing / permissive types
};
capability_test(&cap);
}
static void capability_modv8_base_binary(void)
{
struct capability_answer cap = {
POLICY_ROOT "/base-8.pp",
QPOL_POLICY_MODULE_BINARY, // policy type
8U, // policy version
true, // has attributes
true, // has syntactic rules
false, // has line numbers
true, // has conditionals
true, // has mls
true, // has policy capabilities
false, // has source
true, // has modules
"root_t", "system_t" // enforcing / permissive types
};
capability_test(&cap);
}
CU_TestInfo capabilities_tests[] = {
{"v12, source", capability_v12_source},
{"v15, source", capability_v15_source},
{"v15, binary", capability_v15_binary},
{"v16, source", capability_v16_source},
{"v16, binary", capability_v16_binary},
{"v17, source", capability_v17_source},
{"v17, binary", capability_v17_binary},
{"v18, source", capability_v18_source},
{"v18, binary", capability_v18_binary},
{"v19, binary", capability_v19_binary},
{"v19, binary mls", capability_v19_binary_mls},
{"v20, binary", capability_v20_binary},
{"v20, binary mls", capability_v20_binary_mls},
{"v21, source", capability_v21_source},
{"v21, binary", capability_v21_binary},
{"v22, source", capability_v22_source},
{"v22, binary", capability_v22_binary},
{"v23, source", capability_v23_source},
{"v23, binary", capability_v23_binary},
{"mod v6, base binary", capability_modv6_base_binary},
{"mod v8, base binary", capability_modv8_base_binary},
CU_TEST_INFO_NULL
};
int capabilities_init()
{
return 0;
}
int capabilities_cleanup()
{
return 0;
}
|