def copySessionStop(self): # etre sur que le type est logoff ! d = shell.SHGetFolderPath(0, shellcon.CSIDL_COMMON_APPDATA, 0, 0) profile_tmp_dir = os.path.join(d, "ulteo", "profile", self.session.user.name) profile_tmp_dir = System.local_encode(profile_tmp_dir) profile_filter = System.local_encode(Config.profile_filters_filename) d = os.path.join(self.mountPoint, "conf.Windows.%s" % System.getWindowsVersionName()) trial = 5 while not os.path.exists(d): try: os.makedirs(d) except OSError: trial -= 1 if trial == 0: Logger.exception("Failed to create directory %s" % d) return False time.sleep(random.randint(1, 10) / 100.0) Logger.debug2( "conf.Windows mkdir failed (concurrent access because of more than one ApS)" ) continue # Copy user registry src = os.path.join(self.session.windowsProfileDir, "NTUSER.DAT") dst = os.path.join(d, "NTUSER.DAT") if os.path.exists(src): try: win32file.CopyFile(src, dst, False) except: Logger.error("Unable to copy registry to profile") else: Logger.warn("Weird: no NTUSER.DAT in user home dir ...") # Copy configuration File if self.profile['profile_mode'] == 'standard': cmd = self.getRsyncMethod(Profile.toCygPath(profile_tmp_dir), Profile.toCygPath(d), Profile.toCygPath(profile_filter)) Logger.debug("rsync cmd '%s'" % (cmd)) p = System.execute(cmd) if p.returncode is not 0: Logger.error("Unable to copy conf to profile") Logger.debug( "Unable to copy conf to profile, cmd '%s' return %d: %s" % (cmd, p.returncode, p.stdout.read())) if os.path.exists(profile_tmp_dir): System.DeleteDirectory(profile_tmp_dir)
def copySessionStop(self): # etre sur que le type est logoff ! d = shell.SHGetFolderPath(0, shellcon.CSIDL_COMMON_APPDATA, 0, 0) profile_tmp_dir = os.path.join(d, "ulteo", "profile", self.session.user.name) profile_tmp_dir = System.local_encode(profile_tmp_dir) profile_filter = System.local_encode(Config.profile_filters_filename) d = os.path.join(self.mountPoint, "conf.Windows.%s"%System.getWindowsVersionName()) trial = 5 while not os.path.exists(d): try: os.makedirs(d) except OSError: trial -= 1 if trial == 0: Logger.exception("Failed to create directory %s"%d) return False time.sleep(random.randint(1,10)/100.0) Logger.debug2("conf.Windows mkdir failed (concurrent access because of more than one ApS)") continue # Copy user registry src = os.path.join(self.session.windowsProfileDir, "NTUSER.DAT") dst = os.path.join(d, "NTUSER.DAT") if os.path.exists(src): try: win32file.CopyFile(src, dst, False) except: Logger.error("Unable to copy registry to profile") else: Logger.warn("Weird: no NTUSER.DAT in user home dir ...") # Copy configuration File if self.profile['profile_mode'] == 'standard': cmd = self.getRsyncMethod(Profile.toCygPath(profile_tmp_dir), Profile.toCygPath(d), Profile.toCygPath(profile_filter)) Logger.debug("rsync cmd '%s'"%(cmd)) p = System.execute(cmd) if p.returncode is not 0: Logger.error("Unable to copy conf to profile") Logger.debug("Unable to copy conf to profile, cmd '%s' return %d: %s"%(cmd, p.returncode, p.stdout.read())) if os.path.exists(profile_tmp_dir): System.DeleteDirectory(profile_tmp_dir)
def copySessionStart(self): d = shell.SHGetFolderPath(0, shellcon.CSIDL_COMMON_APPDATA, 0, 0) profile_tmp_dir = os.path.join(d, "ulteo", "profile", self.session.user.name) profile_tmp_dir = System.local_encode(profile_tmp_dir) profile_filter = System.local_encode(Config.profile_filters_filename) for f in [self.DesktopDir, self.DocumentsDir]: d = os.path.join(self.mountPoint, "Data", f) trial = 5 while not os.path.exists(d): try: os.makedirs(d) except OSError: trial -= 1 if trial == 0: Logger.exception("Failed to create directory %s" % d) return False time.sleep(random.randint(1, 10) / 100.0) Logger.debug2( "Profile mkdir failed (concurrent access because of more than one ApS)" ) continue d = os.path.join(self.mountPoint, "conf.Windows.%s" % System.getWindowsVersionName()) if os.path.exists(d): # clean temporary file used by windows to load registry dirs = None try: dirs = os.listdir(d) except Exception: Logger.exception("Unable to list content of the directory %s" % d) return for content in dirs: if content.startswith(r"NTUSER.DAT.LOG") or content.startswith( r"NTUSER.DAT{"): try: path = os.path.join(d, content) os.remove(path) except Exception: Logger.exception("Unable to delete %s" % path) # Copy user registry src = os.path.join(d, "NTUSER.DAT") if os.path.exists(src): dst = os.path.join(self.session.windowsProfileDir, "NTUSER.DAT") rand = random.randrange(10000, 50000) hiveName_src = "OVD_%s_%d" % (str(self.session.id), rand) win32api.RegLoadKey(win32con.HKEY_USERS, hiveName_src, src) hiveName_dst = "OVD_%s_%d" % (str(self.session.id), rand + 1) win32api.RegLoadKey(win32con.HKEY_USERS, hiveName_dst, dst) hkey_src = win32api.RegOpenKey(win32con.HKEY_USERS, r"%s" % (hiveName_src), 0, win32con.KEY_ALL_ACCESS) hkey_dst = win32api.RegOpenKey(win32con.HKEY_USERS, r"%s" % (hiveName_dst), 0, win32con.KEY_ALL_ACCESS) Reg.CopyTree(hkey_src, "Software", hkey_dst, self.registry_copy_blacklist) win32api.RegCloseKey(hkey_src) win32api.RegCloseKey(hkey_dst) win32api.RegUnLoadKey(win32con.HKEY_USERS, hiveName_src) win32api.RegUnLoadKey(win32con.HKEY_USERS, hiveName_dst) # Copy configuration File if self.profile['profile_mode'] == 'standard': cmd = self.getRsyncMethod(Profile.toCygPath(d), Profile.toCygPath(profile_tmp_dir), Profile.toCygPath(profile_filter)) Logger.debug("rsync cmd '%s'" % (cmd)) p = System.execute(cmd) if p.returncode is not 0: Logger.error("Unable to copy conf from profile") Logger.debug( "Unable to copy conf from profile, cmd '%s' return %d: %s" % (cmd, p.returncode, p.stdout.read())) if os.path.exists(profile_tmp_dir): System.rchown(profile_tmp_dir, self.session.user.name)
def copySessionStart(self): d = shell.SHGetFolderPath(0, shellcon.CSIDL_COMMON_APPDATA, 0, 0) profile_tmp_dir = os.path.join(d, "ulteo", "profile", self.session.user.name) profile_tmp_dir = System.local_encode(profile_tmp_dir) profile_filter = System.local_encode(Config.profile_filters_filename) for f in [self.DesktopDir, self.DocumentsDir]: d = os.path.join(self.mountPoint, "Data", f) trial = 5 while not os.path.exists(d): try: os.makedirs(d) except OSError: trial -= 1 if trial == 0: Logger.exception("Failed to create directory %s"%d) return False time.sleep(random.randint(1,10)/100.0) Logger.debug2("Profile mkdir failed (concurrent access because of more than one ApS)") continue d = os.path.join(self.mountPoint, "conf.Windows.%s"%System.getWindowsVersionName()) if os.path.exists(d): # clean temporary file used by windows to load registry dirs = None try: dirs = os.listdir(d) except Exception: Logger.exception("Unable to list content of the directory %s"%d) return for content in dirs: if content.startswith(r"NTUSER.DAT.LOG") or content.startswith(r"NTUSER.DAT{"): try : path = os.path.join(d, content) os.remove(path) except Exception: Logger.exception("Unable to delete %s"%path) # Copy user registry src = os.path.join(d, "NTUSER.DAT") if os.path.exists(src): dst = os.path.join(self.session.windowsProfileDir, "NTUSER.DAT") rand = random.randrange(10000, 50000) hiveName_src = "OVD_%s_%d"%(str(self.session.id), rand) win32api.RegLoadKey(win32con.HKEY_USERS, hiveName_src, src) hiveName_dst = "OVD_%s_%d"%(str(self.session.id), rand+1) win32api.RegLoadKey(win32con.HKEY_USERS, hiveName_dst, dst) hkey_src = win32api.RegOpenKey(win32con.HKEY_USERS, r"%s"%(hiveName_src), 0, win32con.KEY_ALL_ACCESS) hkey_dst = win32api.RegOpenKey(win32con.HKEY_USERS, r"%s"%(hiveName_dst), 0, win32con.KEY_ALL_ACCESS) Reg.CopyTree(hkey_src, "Software", hkey_dst, self.registry_copy_blacklist) win32api.RegCloseKey(hkey_src) win32api.RegCloseKey(hkey_dst) win32api.RegUnLoadKey(win32con.HKEY_USERS, hiveName_src) win32api.RegUnLoadKey(win32con.HKEY_USERS, hiveName_dst) # Copy configuration File if self.profile['profile_mode'] == 'standard': cmd = self.getRsyncMethod(Profile.toCygPath(d), Profile.toCygPath(profile_tmp_dir), Profile.toCygPath(profile_filter)) Logger.debug("rsync cmd '%s'"%(cmd)) p = System.execute(cmd) if p.returncode is not 0: Logger.error("Unable to copy conf from profile") Logger.debug("Unable to copy conf from profile, cmd '%s' return %d: %s"%(cmd, p.returncode, p.stdout.read())) if os.path.exists(profile_tmp_dir): System.rchown(profile_tmp_dir, self.session.user.name)