1#!/usr/bin/env python 2 3import os 4import sys 5import time 6load_path = '../' 7if False: 8 sys.path.insert(0, load_path) 9 10import capng 11last = capng.CAP_LAST_CAP 12 13print("Doing basic bit tests...") 14capng.capng_clear(capng.CAPNG_SELECT_BOTH) 15if capng.capng_have_capabilities(capng.CAPNG_SELECT_BOTH) != capng.CAPNG_NONE: 16 print("Failed clearing capabilities\n") 17 sys.exit(1) 18 19capng.capng_fill(capng.CAPNG_SELECT_BOTH) 20if capng.capng_have_capabilities(capng.CAPNG_SELECT_BOTH) != capng.CAPNG_FULL: 21 print("Failed filling capabilities") 22 sys.exit(1) 23 24text = capng.capng_print_caps_numeric(capng.CAPNG_PRINT_BUFFER, capng.CAPNG_SELECT_CAPS) 25len = len(text) 26if len < 80 and last > 30: 27 last = 30 28 29print("Doing advanced bit tests for %d capabilities...\n" % (last)) 30for i in range(last+1): 31 capng.capng_clear(capng.CAPNG_SELECT_BOTH) 32 rc = capng.capng_update(capng.CAPNG_ADD, capng.CAPNG_EFFECTIVE, i) 33 if rc: 34 print("Failed update test 1") 35 sys.exit(1) 36 37 rc = capng.capng_have_capability(capng.CAPNG_EFFECTIVE, int(i)) 38 if rc <= capng.CAPNG_NONE: 39 print("Failed have capability test 1") 40 capng.capng_print_caps_numeric(capng.CAPNG_PRINT_STDOUT, capng.CAPNG_SELECT_CAPS) 41 sys.exit(1) 42 43 if capng.capng_have_capabilities(capng.CAPNG_SELECT_CAPS) != capng.CAPNG_PARTIAL: 44 print("Failed have capabilities test 1") 45 sys.exit(1) 46 47 capng.capng_fill(capng.CAPNG_SELECT_BOTH) 48 rc = capng.capng_update(capng.CAPNG_DROP, capng.CAPNG_EFFECTIVE, i) 49 if rc: 50 print("Failed update test 3") 51 sys.exit(1) 52 53 if capng.capng_have_capabilities(capng.CAPNG_SELECT_CAPS)!=capng.CAPNG_PARTIAL: 54 print("Failed have capabilities test 3") 55 capng.capng_print_caps_numeric(capng.CAPNG_PRINT_STDOUT, capng.CAPNG_SELECT_CAPS) 56 sys.exit(1) 57 58 rc = capng.capng_update(capng.CAPNG_ADD, capng.CAPNG_EFFECTIVE, i) 59 if rc: 60 print("Failed update test 4") 61 sys.exit(1) 62 63 if capng.capng_have_capabilities(capng.CAPNG_SELECT_CAPS) != capng.CAPNG_FULL: 64 print("Failed have capabilities test 4") 65 capng.capng_print_caps_numeric(capng.CAPNG_PRINT_STDOUT, capng.CAPNG_SELECT_CAPS) 66 sys.exit(1) 67 68sys.exit(0) 69