forked from openkylin/platform_build
Merge "Fix failing test_fs_config_generator.py tests"
am: f83ba4e8b1
Change-Id: I70fc52b006407fc749057b74c2599eac2e4c5392
This commit is contained in:
commit
cff9af302b
|
@ -112,7 +112,8 @@ class Utils(object):
|
||||||
'Cannot specify delimiter character ":" in uid: "%s"' % uid)
|
'Cannot specify delimiter character ":" in uid: "%s"' % uid)
|
||||||
if ':' in logon:
|
if ':' in logon:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
'Cannot specify delimiter character ":" in logon: "%s"' % logon)
|
'Cannot specify delimiter character ":" in logon: "%s"' %
|
||||||
|
logon)
|
||||||
return logon, uid
|
return logon, uid
|
||||||
|
|
||||||
|
|
||||||
|
@ -158,16 +159,17 @@ class AID(object):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.normalized_value = str(int(value, 0))
|
self.normalized_value = str(int(value, 0))
|
||||||
except ValueException:
|
except ValueError:
|
||||||
raise ValueError('Invalid "value", not aid number, got: \"%s\"' % value)
|
raise ValueError(
|
||||||
|
'Invalid "value", not aid number, got: \"%s\"' % value)
|
||||||
|
|
||||||
# Where we calculate the friendly name
|
# Where we calculate the friendly name
|
||||||
friendly = identifier[len(AID.PREFIX):].lower()
|
friendly = identifier[len(AID.PREFIX):].lower()
|
||||||
self.friendly = AID._fixup_friendly(friendly)
|
self.friendly = AID._fixup_friendly(friendly)
|
||||||
|
|
||||||
if len(self.friendly) > 31:
|
if len(self.friendly) > 31:
|
||||||
raise ValueError('AID names must be under 32 characters "%s"' % self.friendly)
|
raise ValueError(
|
||||||
|
'AID names must be under 32 characters "%s"' % self.friendly)
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
|
|
||||||
|
@ -217,6 +219,7 @@ class FSConfig(object):
|
||||||
user (str): The uid or #define identifier (AID_SYSTEM)
|
user (str): The uid or #define identifier (AID_SYSTEM)
|
||||||
group (str): The gid or #define identifier (AID_SYSTEM)
|
group (str): The gid or #define identifier (AID_SYSTEM)
|
||||||
caps (str): The capability set.
|
caps (str): The capability set.
|
||||||
|
path (str): The path of the file or directory.
|
||||||
filename (str): The file it was found in.
|
filename (str): The file it was found in.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -227,6 +230,7 @@ class FSConfig(object):
|
||||||
user (str): The uid or #define identifier (AID_SYSTEM)
|
user (str): The uid or #define identifier (AID_SYSTEM)
|
||||||
group (str): The gid or #define identifier (AID_SYSTEM)
|
group (str): The gid or #define identifier (AID_SYSTEM)
|
||||||
caps (str): The capability set as a list.
|
caps (str): The capability set as a list.
|
||||||
|
path (str): The path of the file or directory.
|
||||||
filename (str): The file it was found in.
|
filename (str): The file it was found in.
|
||||||
"""
|
"""
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
|
@ -242,6 +246,11 @@ class FSConfig(object):
|
||||||
and self.group == other.group and self.caps == other.caps \
|
and self.group == other.group and self.caps == other.caps \
|
||||||
and self.path == other.path and self.filename == other.filename
|
and self.path == other.path and self.filename == other.filename
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return 'FSConfig(%r, %r, %r, %r, %r, %r)' % (self.mode, self.user,
|
||||||
|
self.group, self.caps,
|
||||||
|
self.path, self.filename)
|
||||||
|
|
||||||
|
|
||||||
class AIDHeaderParser(object):
|
class AIDHeaderParser(object):
|
||||||
"""Parses an android_filesystem_config.h file.
|
"""Parses an android_filesystem_config.h file.
|
||||||
|
@ -256,10 +265,10 @@ class AIDHeaderParser(object):
|
||||||
work.
|
work.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
_SKIP_AIDS = [
|
_SKIP_AIDS = [
|
||||||
re.compile(r'%sUNUSED[0-9].*' % AID.PREFIX),
|
re.compile(r'%sUNUSED[0-9].*' % AID.PREFIX),
|
||||||
re.compile(r'%sAPP' % AID.PREFIX), re.compile(r'%sUSER' % AID.PREFIX)
|
re.compile(r'%sAPP' % AID.PREFIX),
|
||||||
|
re.compile(r'%sUSER' % AID.PREFIX)
|
||||||
]
|
]
|
||||||
_AID_DEFINE = re.compile(r'\s*#define\s+%s.*' % AID.PREFIX)
|
_AID_DEFINE = re.compile(r'\s*#define\s+%s.*' % AID.PREFIX)
|
||||||
_OEM_START_KW = 'START'
|
_OEM_START_KW = 'START'
|
||||||
|
@ -310,7 +319,9 @@ class AIDHeaderParser(object):
|
||||||
identifier = chunks[1]
|
identifier = chunks[1]
|
||||||
value = chunks[2]
|
value = chunks[2]
|
||||||
|
|
||||||
if any(x.match(identifier) for x in AIDHeaderParser._SKIP_AIDS):
|
if any(
|
||||||
|
x.match(identifier)
|
||||||
|
for x in AIDHeaderParser._SKIP_AIDS):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -322,8 +333,8 @@ class AIDHeaderParser(object):
|
||||||
self._handle_aid(identifier, value)
|
self._handle_aid(identifier, value)
|
||||||
except ValueError as exception:
|
except ValueError as exception:
|
||||||
sys.exit(
|
sys.exit(
|
||||||
error_message('{} for "{}"'.format(exception,
|
error_message('{} for "{}"'.format(
|
||||||
identifier)))
|
exception, identifier)))
|
||||||
|
|
||||||
def _handle_aid(self, identifier, value):
|
def _handle_aid(self, identifier, value):
|
||||||
"""Handle an AID C #define.
|
"""Handle an AID C #define.
|
||||||
|
@ -346,8 +357,8 @@ class AIDHeaderParser(object):
|
||||||
raise ValueError('Duplicate aid "%s"' % identifier)
|
raise ValueError('Duplicate aid "%s"' % identifier)
|
||||||
|
|
||||||
if value in self._aid_value_to_name and aid.identifier not in AIDHeaderParser._COLLISION_OK:
|
if value in self._aid_value_to_name and aid.identifier not in AIDHeaderParser._COLLISION_OK:
|
||||||
raise ValueError('Duplicate aid value "%s" for %s' % (value,
|
raise ValueError(
|
||||||
identifier))
|
'Duplicate aid value "%s" for %s' % (value, identifier))
|
||||||
|
|
||||||
self._aid_name_to_value[aid.friendly] = aid
|
self._aid_name_to_value[aid.friendly] = aid
|
||||||
self._aid_value_to_name[value] = aid.friendly
|
self._aid_value_to_name[value] = aid.friendly
|
||||||
|
@ -400,11 +411,11 @@ class AIDHeaderParser(object):
|
||||||
if tmp == int_value:
|
if tmp == int_value:
|
||||||
raise ValueError('START and END values equal %u' % int_value)
|
raise ValueError('START and END values equal %u' % int_value)
|
||||||
elif is_start and tmp < int_value:
|
elif is_start and tmp < int_value:
|
||||||
raise ValueError('END value %u less than START value %u' %
|
raise ValueError(
|
||||||
(tmp, int_value))
|
'END value %u less than START value %u' % (tmp, int_value))
|
||||||
elif not is_start and tmp > int_value:
|
elif not is_start and tmp > int_value:
|
||||||
raise ValueError('END value %u less than START value %u' %
|
raise ValueError(
|
||||||
(int_value, tmp))
|
'END value %u less than START value %u' % (int_value, tmp))
|
||||||
|
|
||||||
# Add START values to the head of the list and END values at the end.
|
# Add START values to the head of the list and END values at the end.
|
||||||
# Thus, the list is ordered with index 0 as START and index 1 as END.
|
# Thus, the list is ordered with index 0 as START and index 1 as END.
|
||||||
|
@ -533,7 +544,7 @@ class FSConfigFileParser(object):
|
||||||
|
|
||||||
# list of handler to required options, used to identify the
|
# list of handler to required options, used to identify the
|
||||||
# parsing section
|
# parsing section
|
||||||
_SECTIONS = [('_handle_aid', ('value',)),
|
_SECTIONS = [('_handle_aid', ('value', )),
|
||||||
('_handle_path', ('mode', 'user', 'group', 'caps'))]
|
('_handle_path', ('mode', 'user', 'group', 'caps'))]
|
||||||
|
|
||||||
def __init__(self, config_files, oem_ranges):
|
def __init__(self, config_files, oem_ranges):
|
||||||
|
@ -596,8 +607,8 @@ class FSConfigFileParser(object):
|
||||||
break
|
break
|
||||||
|
|
||||||
if not found:
|
if not found:
|
||||||
sys.exit('Invalid section "%s" in file: "%s"' %
|
sys.exit('Invalid section "%s" in file: "%s"' % (section,
|
||||||
(section, file_name))
|
file_name))
|
||||||
|
|
||||||
# sort entries:
|
# sort entries:
|
||||||
# * specified path before prefix match
|
# * specified path before prefix match
|
||||||
|
@ -959,7 +970,7 @@ class FSConfigGen(BaseGenerator):
|
||||||
|
|
||||||
common = base_set & oem_set
|
common = base_set & oem_set
|
||||||
|
|
||||||
if len(common) > 0:
|
if common:
|
||||||
emsg = 'Following AID Collisions detected for: \n'
|
emsg = 'Following AID Collisions detected for: \n'
|
||||||
for friendly in common:
|
for friendly in common:
|
||||||
base = base_friendly[friendly]
|
base = base_friendly[friendly]
|
||||||
|
@ -1234,11 +1245,12 @@ class PasswdGen(BaseGenerator):
|
||||||
aids = parser.aids
|
aids = parser.aids
|
||||||
|
|
||||||
# nothing to do if no aids defined
|
# nothing to do if no aids defined
|
||||||
if len(aids) == 0:
|
if not aids:
|
||||||
return
|
return
|
||||||
|
|
||||||
for aid in aids:
|
for aid in aids:
|
||||||
if required_prefix is None or aid.friendly.startswith(required_prefix):
|
if required_prefix is None or aid.friendly.startswith(
|
||||||
|
required_prefix):
|
||||||
self._print_formatted_line(aid)
|
self._print_formatted_line(aid)
|
||||||
else:
|
else:
|
||||||
sys.exit("%s: AID '%s' must start with '%s'" %
|
sys.exit("%s: AID '%s' must start with '%s'" %
|
||||||
|
@ -1294,6 +1306,7 @@ class GroupGen(PasswdGen):
|
||||||
|
|
||||||
print "%s::%s:" % (logon, uid)
|
print "%s::%s:" % (logon, uid)
|
||||||
|
|
||||||
|
|
||||||
@generator('print')
|
@generator('print')
|
||||||
class PrintGen(BaseGenerator):
|
class PrintGen(BaseGenerator):
|
||||||
"""Prints just the constants and values, separated by spaces, in an easy to
|
"""Prints just the constants and values, separated by spaces, in an easy to
|
||||||
|
|
|
@ -45,19 +45,21 @@ class Tests(unittest.TestCase):
|
||||||
def test_aid(self):
|
def test_aid(self):
|
||||||
"""Test AID class constructor"""
|
"""Test AID class constructor"""
|
||||||
|
|
||||||
aid = AID('AID_FOO_BAR', '0xFF', 'myfakefile')
|
aid = AID('AID_FOO_BAR', '0xFF', 'myfakefile', '/system/bin/sh')
|
||||||
self.assertEquals(aid.identifier, 'AID_FOO_BAR')
|
self.assertEqual(aid.identifier, 'AID_FOO_BAR')
|
||||||
self.assertEquals(aid.value, '0xFF')
|
self.assertEqual(aid.value, '0xFF')
|
||||||
self.assertEquals(aid.found, 'myfakefile')
|
self.assertEqual(aid.found, 'myfakefile')
|
||||||
self.assertEquals(aid.normalized_value, '255')
|
self.assertEqual(aid.normalized_value, '255')
|
||||||
self.assertEquals(aid.friendly, 'foo_bar')
|
self.assertEqual(aid.friendly, 'foo_bar')
|
||||||
|
self.assertEqual(aid.login_shell, '/system/bin/sh')
|
||||||
|
|
||||||
aid = AID('AID_MEDIA_EX', '1234', 'myfakefile')
|
aid = AID('AID_MEDIA_EX', '1234', 'myfakefile', '/vendor/bin/sh')
|
||||||
self.assertEquals(aid.identifier, 'AID_MEDIA_EX')
|
self.assertEqual(aid.identifier, 'AID_MEDIA_EX')
|
||||||
self.assertEquals(aid.value, '1234')
|
self.assertEqual(aid.value, '1234')
|
||||||
self.assertEquals(aid.found, 'myfakefile')
|
self.assertEqual(aid.found, 'myfakefile')
|
||||||
self.assertEquals(aid.normalized_value, '1234')
|
self.assertEqual(aid.normalized_value, '1234')
|
||||||
self.assertEquals(aid.friendly, 'mediaex')
|
self.assertEqual(aid.friendly, 'mediaex')
|
||||||
|
self.assertEqual(aid.login_shell, '/vendor/bin/sh')
|
||||||
|
|
||||||
def test_aid_header_parser_good(self):
|
def test_aid_header_parser_good(self):
|
||||||
"""Test AID Header Parser good input file"""
|
"""Test AID Header Parser good input file"""
|
||||||
|
@ -265,9 +267,9 @@ class Tests(unittest.TestCase):
|
||||||
dirs = parser.dirs
|
dirs = parser.dirs
|
||||||
aids = parser.aids
|
aids = parser.aids
|
||||||
|
|
||||||
self.assertEquals(len(files), 1)
|
self.assertEqual(len(files), 1)
|
||||||
self.assertEquals(len(dirs), 1)
|
self.assertEqual(len(dirs), 1)
|
||||||
self.assertEquals(len(aids), 1)
|
self.assertEqual(len(aids), 1)
|
||||||
|
|
||||||
aid = aids[0]
|
aid = aids[0]
|
||||||
fcap = files[0]
|
fcap = files[0]
|
||||||
|
@ -275,14 +277,14 @@ class Tests(unittest.TestCase):
|
||||||
|
|
||||||
self.assertEqual(fcap,
|
self.assertEqual(fcap,
|
||||||
FSConfig('0777', 'AID_FOO', 'AID_SYSTEM',
|
FSConfig('0777', 'AID_FOO', 'AID_SYSTEM',
|
||||||
'(1ULL << CAP_BLOCK_SUSPEND)',
|
'CAP_MASK_LONG(CAP_BLOCK_SUSPEND)',
|
||||||
'/system/bin/file', temp_file.name))
|
'/system/bin/file', temp_file.name))
|
||||||
|
|
||||||
self.assertEqual(dcap,
|
self.assertEqual(dcap,
|
||||||
FSConfig('0777', 'AID_FOO', 'AID_SYSTEM', '(0)',
|
FSConfig('0777', 'AID_FOO', 'AID_SYSTEM', '(0)',
|
||||||
'/vendor/path/dir/', temp_file.name))
|
'/vendor/path/dir/', temp_file.name))
|
||||||
|
|
||||||
self.assertEqual(aid, AID('AID_OEM1', '0x1389', temp_file.name))
|
self.assertEqual(aid, AID('AID_OEM1', '0x1389', temp_file.name, '/vendor/bin/sh'))
|
||||||
|
|
||||||
def test_fs_config_file_parser_bad(self):
|
def test_fs_config_file_parser_bad(self):
|
||||||
"""Test FSConfig Parser bad input file"""
|
"""Test FSConfig Parser bad input file"""
|
||||||
|
|
Loading…
Reference in New Issue