OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Helper script to perform actions as a super-user on ChromeOS. | 6 """Helper script to perform actions as a super-user on ChromeOS. |
7 | 7 |
8 Needs to be run with superuser privileges, typically using the | 8 Needs to be run with superuser privileges, typically using the |
9 suid_python binary. | 9 suid_python binary. |
10 | 10 |
11 Usage: | 11 Usage: |
12 sudo python suid_actions.py --action=CleanFlimflamDirs | 12 sudo python suid_actions.py --action=CleanFlimflamDirs |
13 """ | 13 """ |
14 | 14 |
15 import logging | |
15 import optparse | 16 import optparse |
16 import os | 17 import os |
17 import shutil | 18 import shutil |
18 import sys | 19 import sys |
19 | 20 |
20 | |
21 sys.path.append('/usr/local') # to import autotest libs. | 21 sys.path.append('/usr/local') # to import autotest libs. |
22 from autotest.cros import cryptohome | 22 from autotest.cros import cryptohome |
23 | 23 |
24 _AUTO_CLEAR_LOCAL_STATE_MAGIC_FILE = '/root/.forget_usernames' | |
25 | |
24 | 26 |
25 class SuidAction(object): | 27 class SuidAction(object): |
26 """Helper to perform some super-user actions on ChromeOS.""" | 28 """Helper to perform some super-user actions on ChromeOS.""" |
27 | 29 |
28 def _ParseArgs(self): | 30 def _ParseArgs(self): |
29 parser = optparse.OptionParser() | 31 parser = optparse.OptionParser() |
30 parser.add_option( | 32 parser.add_option( |
31 '-a', '--action', help='Action to perform.') | 33 '-a', '--action', help='Action to perform.') |
32 self._options = parser.parse_args()[0] | 34 self._options = parser.parse_args()[0] |
33 if not self._options.action: | 35 if not self._options.action: |
(...skipping 24 matching lines...) Expand all Loading... | |
58 shutil.rmtree(path) | 60 shutil.rmtree(path) |
59 else: | 61 else: |
60 os.remove(path) | 62 os.remove(path) |
61 finally: | 63 finally: |
62 os.system('start flimflam') | 64 os.system('start flimflam') |
63 | 65 |
64 def RemoveAllCryptohomeVaults(self): | 66 def RemoveAllCryptohomeVaults(self): |
65 """Remove any existing cryptohome vaults.""" | 67 """Remove any existing cryptohome vaults.""" |
66 cryptohome.remove_all_vaults() | 68 cryptohome.remove_all_vaults() |
67 | 69 |
70 def DisableLocalStateAutoClearing(self): | |
Nirnimesh
2012/04/12 01:46:24
If you agree with my previous replies, these need
bartfab (slow)
2012/04/12 12:49:31
To maximize test coverage, I went with the route o
| |
71 """Disable clearing of the local state on session manager startup.""" | |
72 os.system('mount -o remount,rw /') | |
73 os.remove(_AUTO_CLEAR_LOCAL_STATE_MAGIC_FILE) | |
74 assert not os.path.exists(_AUTO_CLEAR_LOCAL_STATE_MAGIC_FILE) | |
75 os.system('mount -o remount,ro /') | |
76 logging.debug('Removed %s. Session manager will not clear local state on ' | |
77 'startup.' % _AUTO_CLEAR_LOCAL_STATE_MAGIC_FILE) | |
78 | |
79 def EnableLocalStateAutoClearing(self): | |
80 """Enable clearing of the local state on session manager startup.""" | |
81 os.system('mount -o remount,rw /') | |
82 open(_AUTO_CLEAR_LOCAL_STATE_MAGIC_FILE, 'w').close() | |
83 assert os.path.exists(_AUTO_CLEAR_LOCAL_STATE_MAGIC_FILE) | |
84 os.system('mount -o remount,ro /') | |
85 logging.debug('Created %s. Session manager will clear local state on ' | |
86 'startup.' % _AUTO_CLEAR_LOCAL_STATE_MAGIC_FILE) | |
87 | |
68 | 88 |
69 if __name__ == '__main__': | 89 if __name__ == '__main__': |
70 sys.exit(SuidAction().Run()) | 90 sys.exit(SuidAction().Run()) |
OLD | NEW |