def install_client(self): logon = win32security.LogonUser( self.user.name, None, self.user.infos["password"], win32security.LOGON32_LOGON_INTERACTIVE, win32security.LOGON32_PROVIDER_DEFAULT) data = {} data["UserName"] = self.user.name hkey = win32profile.LoadUserProfile(logon, data) self.windowsProfileDir = win32profile.GetUserProfileDirectory(logon) sessionDir = os.path.join(self.SPOOL_USER, self.user.name) self.windowsProgramsDir = shell.SHGetFolderPath( 0, shellcon.CSIDL_PROGRAMS, logon, 0) Logger.debug("startmenu: %s" % (self.windowsProgramsDir)) # remove default startmenu if os.path.exists(self.windowsProgramsDir): System.DeleteDirectory(self.windowsProgramsDir) os.makedirs(self.windowsProgramsDir) self.appDataDir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, logon, 0) self.localAppDataDir = shell.SHGetFolderPath( 0, shellcon.CSIDL_LOCAL_APPDATA, logon, 0) Logger.debug("localAppdata: '%s'" % (self.localAppDataDir)) Logger.debug("appdata: '%s'" % (self.appDataDir)) win32profile.UnloadUserProfile(logon, hkey) win32api.CloseHandle(logon) self.init_user_session_dir(sessionDir) if self.profile is not None and self.profile.hasProfile(): if not self.profile.mount(): if self.parameters.has_key( "need_valid_profile" ) and self.parameters["need_valid_profile"] == "1": return False else: self.profile.copySessionStart() self.profile.installLogoffGPO() if self.profile is not None and self.profile.mountPoint is not None: d = os.path.join(self.profile.mountPoint, self.profile.DesktopDir) self.cleanupShortcut(d) self.install_desktop_shortcuts() self.overwriteDefaultRegistry(self.windowsProfileDir) if self.profile is not None and self.profile.hasProfile(): self.profile.umount() self.succefully_initialized = True return True
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 init_user_session_dir(self, user_session_dir): self.user_session_dir = user_session_dir if os.path.isdir(self.user_session_dir): System.DeleteDirectory(self.user_session_dir) try: os.makedirs(self.user_session_dir) except WindowsError, e: if e[0] == 183: # The directory already exist Logger.debug("The directory %s already exist" % (self.user_session_dir))