Package sabayon :: Module usermod
[hide private]
[frames] | no frames]

Source Code for Module sabayon.usermod

 1  # 
 2  # Copyright (C) 2005 Red Hat, Inc. 
 3  # 
 4  # This program is free software; you can redistribute it and/or modify 
 5  # it under the terms of the GNU General Public License as published by 
 6  # the Free Software Foundation; either version 2 of the License, or 
 7  # (at your option) any later version. 
 8  # 
 9  # This program is distributed in the hope that it will be useful, 
10  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
12  # GNU General Public License for more details. 
13  # 
14  # You should have received a copy of the GNU General Public License 
15  # along with this program; if not, write to the Free Software 
16  # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
17  # 
18   
19  import os 
20  import os.path 
21  import tempfile 
22  import shutil 
23  import subprocess 
24  from config import * 
25  import debuglog 
26   
27 -def dprint (fmt, *args):
28 debuglog.debug_log (False, debuglog.DEBUG_LOG_DOMAIN_USERMOD, fmt % args)
29
30 -def set_shell (username, shell):
31 argv = USERMOD_ARGV + [ "-s", shell, username ] 32 dprint ("Executing %s" % argv) 33 subprocess.call (argv)
34 35 # 36 # FIXME: 37 # we're fairly screwed if there's another gamin, gconfd-2 38 # or whatever already running when we do this. We probably 39 # should just shut them down. 40 #
41 -def set_homedir (username, homedir):
42 argv = USERMOD_ARGV + [ "-d", homedir, username ] 43 dprint ("Executing %s" % argv) 44 return subprocess.call (argv)
45
46 -def create_temporary_homedir (uid, gid):
47 temp_homedir = tempfile.mkdtemp (prefix = "sabayon-temp-home-") 48 49 def copy_tree (src, dst, uid, gid): 50 for file in os.listdir (src): 51 src_path = os.path.join (src, file) 52 dst_path = os.path.join (dst, file) 53 54 if os.path.islink (src_path): 55 linkto = os.readlink (src_path) 56 os.symlink (linkto, dst_path) 57 elif os.path.isdir (src_path): 58 os.mkdir (dst_path) 59 os.chmod (dst_path, os.lstat(src_path).st_mode) 60 copy_tree (src_path, dst_path, uid, gid) 61 os.chown (dst_path, uid, gid) 62 else: 63 shutil.copy2 (src_path, dst_path) 64 os.chown (dst_path, uid, gid)
65 66 copy_tree (SKEL_HOMEDIR, temp_homedir, uid, gid) 67 os.chown (temp_homedir, uid, gid) 68 return temp_homedir 69