• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python
2#
3# Copyright 2017 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6#
7"""
8Recursively shifts the UID/GIDs of the target directory for user namespacing.
9"""
10
11import argparse
12import grp
13import pwd
14import os
15import sys
16
17def main():
18  parser = argparse.ArgumentParser()
19  parser.add_argument('target', help='recursively shifts UIDs/GIDs of target')
20  args = parser.parse_args()
21
22  for root, dirs, files in os.walk(args.target):
23    for f in files:
24      path = os.path.join(root, f)
25      stat_info = os.lstat(path)
26      if (stat_info.st_uid < 655360):
27        os.lchown(path, stat_info.st_uid + 655360, stat_info.st_gid + 655360)
28    for d in dirs:
29      path = os.path.join(root, d)
30      stat_info = os.lstat(path)
31      if (stat_info.st_uid < 655360):
32        os.lchown(path, stat_info.st_uid + 655360, stat_info.st_gid + 655360)
33
34if __name__ == '__main__':
35  main()
36