Example #1
0
  def realize_perms(self):
    path = self.id_attrs['path']

    # Order is important. First lchown then lchmod.
    owner = self.wanted_attrs['owner']
    group = self.wanted_attrs['group']
    if owner is not None:
      uid = pwd.getpwnam(owner).pw_uid
    else:
      uid = -1
    if group is not None:
      gid = grp.getgrnam(group).gr_gid
    else:
      gid = -1
    # -1 means no change
    os.lchown(path, uid, gid)

    # XXX if we handle symlinks, need to wrap lchmod.
    os.chmod(path, oct_to_int(self.wanted_attrs['mode']))
Example #2
0
def is_valid_mode(mode):
  mode = oct_to_int(mode)
  # Only allow the permission bits and suid stuff.
  return mode == stat.S_IMODE(mode)