コード例 #1
0
    def getTargetFromShortcut(self, path):
        szShortcutTarget = ctypes.c_wchar_p(path)
        szProductCode = ctypes.create_unicode_buffer(4096)
        szFeatureId = ctypes.create_unicode_buffer(4096)
        szComponentCode = ctypes.create_unicode_buffer(4096)

        status = self.dll.MsiGetShortcutTargetW(szShortcutTarget,
                                                ctypes.byref(szProductCode),
                                                ctypes.byref(szFeatureId),
                                                ctypes.byref(szComponentCode))
        if status != self.SUCCESS:
            Logger.debug3("MsiGetShortcutTargetW return %d on '%s'" %
                          (status, path))
            return None

        path_len = ctypes.c_uint(4096)
        path_buffer = ctypes.create_unicode_buffer(4096)

        status = self.dll.MsiGetComponentPathW(szProductCode.value,
                                               szComponentCode.value,
                                               ctypes.byref(path_buffer),
                                               ctypes.byref(path_len))
        if status != self.INSTALLSTATE_LOCAL:
            Logger.debug2("MsiGetComponentPathW return %d on '%s'" %
                          (status, path))
            return None

        return path_buffer.value
コード例 #2
0
ファイル: Profile.py プロジェクト: Oyatsumi/ulteo4Kode4kids
	def copySessionStart(self):
		for f in [self.DesktopDir, self.DocumentsDir]:
			d = os.path.join(self.mountPoint, f)

			while not os.path.exists(d):
				try:
					os.makedirs(d)
				except OSError, err:
					Logger.debug2("Profile mkdir failed (concurrent access because of more than one ApS) => %s"%(str(err)))
					continue
コード例 #3
0
ファイル: Rec.py プロジェクト: Oyatsumi/ulteo4Kode4kids
	def process_IN_CREATE(self, event_k):
		if event_k.name == ".htaccess":
			if event_k.path.startswith(Config.spool):
				buf = event_k.path[len(Config.spool)+1:].split("/")
				if len(buf) == 1:
					Logger.debug2("process_IN_CREATE doesn't change file attribute on root .htaccess file")
					return
		  
		path = os.path.join(event_k.path,event_k.name)
		self.process(path)
コード例 #4
0
ファイル: Profile.py プロジェクト: bacgroup/ovd_sources
    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)
コード例 #5
0
ファイル: Profile.py プロジェクト: Oyatsumi/ulteo4Kode4kids
	def copySessionStop(self):
		# etre sur que le type est logoff !
		
		
		d = os.path.join(self.mountPoint, "conf.Windows")
		while not os.path.exists(d):
			try:
				os.makedirs(d)
			except OSError, err:
				Logger.debug2("conf.Windows mkdir failed (concurrent access because of more than one ApS) => %s"%(str(err)))
				continue
コード例 #6
0
ファイル: Profile.py プロジェクト: zhaolei1/ulteo4Kode4kids
    def copySessionStart(self):
        for f in [self.DesktopDir, self.DocumentsDir]:
            d = os.path.join(self.mountPoint, f)

            while not os.path.exists(d):
                try:
                    os.makedirs(d)
                except OSError, err:
                    Logger.debug2(
                        "Profile mkdir failed (concurrent access because of more than one ApS) => %s"
                        % (str(err)))
                    continue
コード例 #7
0
ファイル: Rec.py プロジェクト: zhaolei1/ulteo4Kode4kids
    def process_IN_CREATE(self, event_k):
        if event_k.name == ".htaccess":
            if event_k.path.startswith(Config.spool):
                buf = event_k.path[len(Config.spool) + 1:].split("/")
                if len(buf) == 1:
                    Logger.debug2(
                        "process_IN_CREATE doesn't change file attribute on root .htaccess file"
                    )
                    return

        path = os.path.join(event_k.path, event_k.name)
        self.process(path)
コード例 #8
0
ファイル: Profile.py プロジェクト: zhaolei1/ulteo4Kode4kids
    def copySessionStop(self):
        # etre sur que le type est logoff !

        d = os.path.join(self.mountPoint, "conf.Windows")
        while not os.path.exists(d):
            try:
                os.makedirs(d)
            except OSError, err:
                Logger.debug2(
                    "conf.Windows mkdir failed (concurrent access because of more than one ApS) => %s"
                    % (str(err)))
                continue
コード例 #9
0
ファイル: Profile.py プロジェクト: bloveing/openulteo
	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)
コード例 #10
0
ファイル: Profile.py プロジェクト: skdong/nfs-ovd
	def copySessionStop(self):
		if self.homeDir is None or not os.path.isdir(self.homeDir):
			return
		
		d = os.path.join(self.profile_mount_point, "conf.Linux")
		while not os.path.exists(d):
			try:
				os.makedirs(d)
			except OSError, err:
				if self.isNetworkError(err[0]):
					Logger.warn("Unable to access profile: %s"%(str(err)))
					return
				
				Logger.debug2("conf.Linux mkdir failed (concurrent access because of more than one ApS) => %s"%(str(err)))
				continue
コード例 #11
0
ファイル: Manager.py プロジェクト: zhaolei1/ulteo4Kode4kids
class Manager:
    ts_group_name = RolePlatform.TS.getUsersGroup()
    ovd_group_name = "OVDUsers"

    def __init__(self, smManager):
        self.smManager = smManager

    def send_session_status(self, session):
        try:
            doc = Document()
            rootNode = doc.createElement('session')
            rootNode.setAttribute("id", session.id)
            rootNode.setAttribute("status", session.status)
            if session.status == Session.SESSION_STATUS_DESTROYED and session.end_status is not None:
                rootNode.setAttribute("reason", session.end_status)

            doc.appendChild(rootNode)
        except Exception, e:
            print str(e)

        response = self.smManager.send_packet("/session/status", doc)
        Logger.debug2("ApplicationServer: send_session_status: %s" %
                      (response))
        if response is False:
            Logger.warn("ApplicationServer: unable to send session status")
        else:
            response.close()
            response = None
コード例 #12
0
ファイル: Profile.py プロジェクト: zhaolei1/ulteo4Kode4kids
    def copySessionStop(self):
        if self.homeDir is None or not os.path.isdir(self.homeDir):
            return

        d = os.path.join(self.profile_mount_point, "conf.Linux")
        while not os.path.exists(d):
            try:
                os.makedirs(d)
            except OSError, err:
                if self.isNetworkError(err[0]):
                    Logger.warn("Unable to access profile: %s" % (str(err)))
                    return

                Logger.debug2(
                    "conf.Linux mkdir failed (concurrent access because of more than one ApS) => %s"
                    % (str(err)))
                continue
コード例 #13
0
ファイル: Rec.py プロジェクト: Oyatsumi/ulteo4Kode4kids
	def process(self, path):
		if os.path.isdir(path):
			Logger.debug("FileServer::Rec chmod dir %s"%(path))
			chmod_flag = stat.S_IRWXU | stat.S_IRWXG | stat.S_ISGID
		elif os.path.isfile(path):
			Logger.debug("FileServer::Rec chmod file %s"%(path))
			chmod_flag = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP
		else:
			chmod_flag = None
		
		try:
			os.lchown(path, Config.uid, Config.gid)
			if chmod_flag is not None:
				os.chmod(path, chmod_flag)
		except OSError, err:
			if os.path.exists(path):
				Logger.warn("Unable to change file owner for '%s'"%(path))
				Logger.debug("lchown returned %s"%(err))
			else:
				Logger.debug2("FS:REC: path '%s' deleted before chown/chmod operations"%(path))
コード例 #14
0
ファイル: Manager.py プロジェクト: bloveing/openulteo
	def send_session_status(self, session):
		try:
			doc = Document()
			rootNode = doc.createElement('session')
			rootNode.setAttribute("id", session.id)
			rootNode.setAttribute("status", session.status)
			if session.status == Session.SESSION_STATUS_DESTROYED and session.end_status is not None:
				rootNode.setAttribute("reason", session.end_status)
			
			doc.appendChild(rootNode)
		except Exception:
			Logger.exception("ApplicationServer: send_session_status")
		
		response = self.smManager.send_packet("/session/status", doc)
		Logger.debug2("ApplicationServer: send_session_status: %s"%(response))
		if response is False:
			Logger.warn("ApplicationServer: unable to send session status")
		else:
			response.close()
			response = None
コード例 #15
0
class Session(UserDict):
	SESSION_STATUS_UNKNOWN = "unknown"
	SESSION_STATUS_ERROR = "error"
	SESSION_STATUS_INITED = "ready"
	SESSION_STATUS_ACTIVE = "logged"
	SESSION_STATUS_INACTIVE = "disconnected"
	SESSION_STATUS_WAIT_DESTROY = "wait_destroy"
	SESSION_STATUS_DESTROYED = "destroyed"
	
	MODE_DESKTOP = "desktop"
	MODE_APPLICATIONS = "applications"
	
	def __init__(self, id_, data, debug=False):
		UserDict.__init__(self)
		self.id = id_
		self.update(data)
		self.status = Session.SESSION_STATUS_INITED
		if not debug:
			self.sm_request_manager = SMRequestManager()
			self.sm_request_manager.initialize();
	
	def switch_status(self, status_):
		self.status = status_
		self.send_server_status()
	
	def credentials(self):
		return {
			'USE_CURRENT_USER_LOGIN': self.get('USER_LOGIN', ''),
			'USE_CURRENT_USER_PASSWD': self.get('USER_PASSWD', ''),
		}
	
	def send_server_status(self):
		doc = None;
		try:
			doc = Document()
			rootNode = doc.createElement('session')
			rootNode.setAttribute("id", self.id)
			rootNode.setAttribute("status", self.status)
			rootNode.setAttribute("role", "webapps")
			doc.appendChild(rootNode)
		except Exception, e:
			Logger.warn("WebappsServer: unable to format session status xml: %s"(str(e)))
		
		if not hasattr(self, "sm_request_manager"):
			return
		
		response = self.sm_request_manager.send_packet("/session/status", doc)
		Logger.debug2("WebappsServer: send_session_status: %s"%(response))
		
		if response is False:
			Logger.warn("WebappsServer: unable to send session status")
		else:
			response.close()
			response = None
コード例 #16
0
ファイル: Msi.py プロジェクト: bloveing/openulteo
	def getTargetFromShortcut(self, path):
		szShortcutTarget = ctypes.c_wchar_p(path)
		szProductCode = ctypes.create_unicode_buffer(4096)
		szFeatureId = ctypes.create_unicode_buffer(4096)
		szComponentCode = ctypes.create_unicode_buffer(4096)
		
		status = self.dll.MsiGetShortcutTargetW(szShortcutTarget, ctypes.byref(szProductCode), ctypes.byref(szFeatureId), ctypes.byref(szComponentCode))
		if status != self.SUCCESS:
			Logger.debug3("MsiGetShortcutTargetW return %d on '%s'"%(status, path))
			return None
		
		path_len = ctypes.c_uint(4096)
		path_buffer = ctypes.create_unicode_buffer(4096)
		
		status = self.dll.MsiGetComponentPathW(szProductCode.value, szComponentCode.value, ctypes.byref(path_buffer), ctypes.byref(path_len))
		if status != self.INSTALLSTATE_LOCAL:
			Logger.debug2("MsiGetComponentPathW return %d on '%s'"%(status, path))
			return None
		
		return path_buffer.value
コード例 #17
0
ファイル: Manager.py プロジェクト: bacgroup/ovd_sources
    def send_session_status(self, session):
        try:
            doc = Document()
            rootNode = doc.createElement('session')
            rootNode.setAttribute("id", session.id)
            rootNode.setAttribute("status", session.status)
            if session.status == Session.SESSION_STATUS_DESTROYED and session.end_status is not None:
                rootNode.setAttribute("reason", session.end_status)

            doc.appendChild(rootNode)
        except Exception:
            Logger.exception("ApplicationServer: send_session_status")

        response = self.smManager.send_packet("/session/status", doc)
        Logger.debug2("ApplicationServer: send_session_status: %s" %
                      (response))
        if response is False:
            Logger.warn("ApplicationServer: unable to send session status")
        else:
            response.close()
            response = None
コード例 #18
0
ファイル: Profile.py プロジェクト: bloveing/openulteo
    def copySessionStop(self):
        if self.homeDir is None or not os.path.isdir(self.homeDir):
            return

        d = os.path.join(self.profile_mount_point, "conf.Linux")
        trial = 5
        while not System.mount_point_exist(d):
            try:
                os.makedirs(d)
            except OSError, err:
                if self.isNetworkError(err[0]):
                    Logger.exception("Unable to access profile")
                    return

                trial -= 1
                if trial == 0:
                    Logger.exception("Failed to create directory %s" % d)
                    return

                time.sleep(random.randint(1, 10) / 100.0)
                Logger.debug2("conf.Linux mkdir failed (concurrent access because of more than one ApS)")
                continue
コード例 #19
0
ファイル: Rec.py プロジェクト: zhaolei1/ulteo4Kode4kids
    def process(self, path):
        if os.path.isdir(path):
            Logger.debug("FileServer::Rec chmod dir %s" % (path))
            chmod_flag = stat.S_IRWXU | stat.S_IRWXG | stat.S_ISGID
        elif os.path.isfile(path):
            Logger.debug("FileServer::Rec chmod file %s" % (path))
            chmod_flag = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP
        else:
            chmod_flag = None

        try:
            os.lchown(path, Config.uid, Config.gid)
            if chmod_flag is not None:
                os.chmod(path, chmod_flag)
        except OSError, err:
            if os.path.exists(path):
                Logger.warn("Unable to change file owner for '%s'" % (path))
                Logger.debug("lchown returned %s" % (err))
            else:
                Logger.debug2(
                    "FS:REC: path '%s' deleted before chown/chmod operations" %
                    (path))
コード例 #20
0
ファイル: Profile.py プロジェクト: bacgroup/ovd_sources
    def copySessionStop(self):
        if self.homeDir is None or not os.path.isdir(self.homeDir):
            return

        d = os.path.join(self.profile_mount_point, "conf.Linux")
        trial = 5
        while not System.mount_point_exist(d):
            try:
                os.makedirs(d)
            except OSError, err:
                if self.isNetworkError(err[0]):
                    Logger.exception("Unable to access profile")
                    return

                trial -= 1
                if trial == 0:
                    Logger.exception("Failed to create directory %s" % d)
                    return

                time.sleep(random.randint(1, 10) / 100.0)
                Logger.debug2(
                    "conf.Linux mkdir failed (concurrent access because of more than one ApS)"
                )
                continue
コード例 #21
0
ファイル: Profile.py プロジェクト: zhaolei1/ulteo4Kode4kids
    def mount(self):
        os.makedirs(self.cifs_dst)
        self.homeDir = pwd.getpwnam(
            self.transformToLocaleEncoding(self.session.user.name))[5]

        if self.profile is not None:
            os.makedirs(self.profile_mount_point)

            cmd = "mount -t cifs -o username=%s,password=%s,uid=%s,gid=0,umask=077 //%s/%s %s" % (
                self.profile["login"], self.profile["password"],
                self.session.user.name, self.profile["server"],
                self.profile["dir"], self.profile_mount_point)
            cmd = self.transformToLocaleEncoding(cmd)
            Logger.debug("Profile mount command: '%s'" % (cmd))
            s, o = commands.getstatusoutput(cmd)
            if s != 0:
                Logger.error("Profile mount failed")
                Logger.debug("Profile mount failed (status: %d) => %s" %
                             (s, o))
                os.rmdir(self.profile_mount_point)
            else:
                self.profileMounted = True

        for sharedFolder in self.sharedFolders:
            dest = os.path.join(
                self.MOUNT_POINT, self.session.id,
                "sharedFolder_" + hashlib.md5(sharedFolder["server"] +
                                              sharedFolder["dir"]).hexdigest())
            if not os.path.exists(dest):
                os.makedirs(dest)

            print "mount dest ", dest
            cmd = "mount -t cifs -o username=%s,password=%s,uid=%s,gid=0,umask=077 //%s/%s %s" % (
                sharedFolder["login"], sharedFolder["password"],
                self.session.user.name, sharedFolder["server"],
                sharedFolder["dir"], dest)
            cmd = self.transformToLocaleEncoding(cmd)
            Logger.debug("Profile, sharedFolder mount command: '%s'" % (cmd))
            s, o = commands.getstatusoutput(cmd)
            if s != 0:
                Logger.error("Profile sharedFolder mount failed")
                Logger.debug(
                    "Profile sharedFolder mount failed (status: %d) => %s" %
                    (s, o))
                os.rmdir(dest)
            else:
                sharedFolder["mountdest"] = dest
                home = self.homeDir

                dst = os.path.join(home, sharedFolder["name"])
                i = 0
                while os.path.exists(dst):
                    dst = os.path.join(home,
                                       sharedFolder["name"] + "_%d" % (i))
                    i += 1

                if not os.path.exists(dst):
                    os.makedirs(dst)

                cmd = "mount -o bind \"%s\" \"%s\"" % (dest, dst)
                cmd = self.transformToLocaleEncoding(cmd)
                Logger.debug("Profile bind dir command '%s'" % (cmd))
                s, o = commands.getstatusoutput(cmd)
                if s != 0:
                    Logger.error("Profile bind dir failed")
                    Logger.error("Profile bind dir failed (status: %d) %s" %
                                 (s, o))
                else:
                    sharedFolder["local_path"] = dst
                    self.folderRedirection.append(dst)
                    self.addGTKBookmark(dst)

        if self.profile is not None and self.profileMounted:
            for d in [self.DesktopDir, self.DocumentsDir]:
                src = os.path.join(self.profile_mount_point, d)
                dst = os.path.join(self.homeDir, d)

                while not os.path.exists(src):
                    try:
                        os.makedirs(src)
                    except OSError, err:
                        if self.isNetworkError(err[0]):
                            Logger.warn("Unable to access profile: %s" %
                                        (str(err)))
                            return

                        Logger.debug2(
                            "Profile mkdir failed (concurrent access because of more than one ApS) => %s"
                            % (str(err)))
                        continue

                if not os.path.exists(dst):
                    os.makedirs(dst)

                cmd = "mount -o bind \"%s\" \"%s\"" % (src, dst)
                cmd = self.transformToLocaleEncoding(cmd)
                Logger.debug("Profile bind dir command '%s'" % (cmd))
                s, o = commands.getstatusoutput(cmd)
                if s != 0:
                    Logger.error("Profile bind dir failed")
                    Logger.error("Profile bind dir failed (status: %d) %s" %
                                 (s, o))
                else:
                    self.folderRedirection.append(dst)

            self.copySessionStart()
コード例 #22
0
ファイル: Profile.py プロジェクト: bloveing/openulteo
    def mount(self):
        os.makedirs(self.cifs_dst)
        self.homeDir = pwd.getpwnam(self.transformToLocaleEncoding(self.session.user.name))[5]

        if self.profile is not None:
            os.makedirs(self.profile_mount_point)

            u = urlparse.urlparse(self.profile["uri"])
            if u.scheme == "cifs":
                ret = self.mount_cifs(self.profile, u, self.profile_mount_point)

            elif u.scheme in ("webdav", "webdavs"):
                ret = self.mount_webdav(self.profile, u, self.profile_mount_point)
            else:
                Logger.warn("Profile: unknown protocol in share uri '%s'" % (self.profile["uri"]))
                ret = False

            if ret is False:
                Logger.error("Profile mount failed")
                os.rmdir(self.profile_mount_point)
                return False
            else:
                self.profileMounted = True

        if self.profile is not None and self.profileMounted:
            for d in [self.DesktopDir, self.DocumentsDir]:
                src = os.path.join(self.profile_mount_point, "Data", d)
                src = self.transformToLocaleEncoding(src)
                dst = os.path.join(self.homeDir, d)

                trial = 5
                while not System.mount_point_exist(src):
                    try:
                        os.makedirs(src)
                    except OSError, err:
                        if self.isNetworkError(err[0]):
                            Logger.exception("Unable to access profile")
                            return False

                        trial -= 1
                        if trial == 0:
                            Logger.exception("Failed to create directory %s" % (src))
                            return False

                        time.sleep(random.randint(1, 10) / 100.0)
                        Logger.debug2(
                            "Profile mkdir failed (concurrent access because of more than one ApS) => %s" % (str(err))
                        )
                        continue

                if self.profile["profile_mode"] == "standard":
                    if not System.mount_point_exist(dst):
                        os.makedirs(dst)

                    cmd = 'mount -o bind "%s" "%s"' % (src, dst)
                    Logger.debug("Profile bind dir command '%s'" % (cmd))
                    p = System.execute(cmd)
                    if p.returncode != 0:
                        Logger.error("Profile bind dir failed")
                        Logger.error("Profile bind dir failed (status: %d) %s" % (p.returncode, p.stdout.read()))
                        return False
                    else:
                        self.folderRedirection.append(dst)

            if self.profile["profile_mode"] == "advanced":
                cmd = 'RegularUnionFS "%s" "%s" -o user=%s' % (
                    self.transformToLocaleEncoding(self.profile_mount_point),
                    self.homeDir,
                    self.transformToLocaleEncoding(self.session.user.name),
                )
                Logger.debug("Profile bind dir command '%s'" % (cmd))
                p = System.execute(cmd)
                if p.returncode != 0:
                    Logger.error("Profile bind dir failed")
                    Logger.error("Profile bind dir failed (status: %d) %s" % (p.returncode, p.stdout.read()))
                    return False
                else:
                    self.folderRedirection.append(self.homeDir)

            self.copySessionStart()
コード例 #23
0
ファイル: Profile.py プロジェクト: bacgroup/ovd_sources
    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)
コード例 #24
0
ファイル: Profile.py プロジェクト: bacgroup/ovd_sources
    def mount(self):
        os.makedirs(self.cifs_dst)
        self.homeDir = pwd.getpwnam(
            self.transformToLocaleEncoding(self.session.user.name))[5]

        if self.profile is not None:
            os.makedirs(self.profile_mount_point)

            u = urlparse.urlparse(self.profile["uri"])
            if u.scheme == "cifs":
                ret = self.mount_cifs(self.profile, u,
                                      self.profile_mount_point)

            elif u.scheme in ("webdav", "webdavs"):
                ret = self.mount_webdav(self.profile, u,
                                        self.profile_mount_point)
            else:
                Logger.warn("Profile: unknown protocol in share uri '%s'" %
                            (self.profile["uri"]))
                ret = False

            if ret is False:
                Logger.error("Profile mount failed")
                os.rmdir(self.profile_mount_point)
                return False
            else:
                self.profileMounted = True

        if self.profile is not None and self.profileMounted:
            for d in [self.DesktopDir, self.DocumentsDir]:
                src = os.path.join(self.profile_mount_point, "Data", d)
                src = self.transformToLocaleEncoding(src)
                dst = os.path.join(self.homeDir, d)

                trial = 5
                while not System.mount_point_exist(src):
                    try:
                        os.makedirs(src)
                    except OSError, err:
                        if self.isNetworkError(err[0]):
                            Logger.exception("Unable to access profile")
                            return False

                        trial -= 1
                        if trial == 0:
                            Logger.exception("Failed to create directory %s" %
                                             (src))
                            return False

                        time.sleep(random.randint(1, 10) / 100.0)
                        Logger.debug2(
                            "Profile mkdir failed (concurrent access because of more than one ApS) => %s"
                            % (str(err)))
                        continue

                if self.profile['profile_mode'] == 'standard':
                    if not System.mount_point_exist(dst):
                        os.makedirs(dst)

                    cmd = "mount -o bind \"%s\" \"%s\"" % (src, dst)
                    Logger.debug("Profile bind dir command '%s'" % (cmd))
                    p = System.execute(cmd)
                    if p.returncode != 0:
                        Logger.error("Profile bind dir failed")
                        Logger.error(
                            "Profile bind dir failed (status: %d) %s" %
                            (p.returncode, p.stdout.read()))
                        return False
                    else:
                        self.folderRedirection.append(dst)

            if self.profile['profile_mode'] == 'advanced':
                cmd = "RegularUnionFS \"%s\" \"%s\" -o user=%s" % (
                    self.transformToLocaleEncoding(
                        self.profile_mount_point), self.homeDir,
                    self.transformToLocaleEncoding(self.session.user.name))
                Logger.debug("Profile bind dir command '%s'" % (cmd))
                p = System.execute(cmd)
                if p.returncode != 0:
                    Logger.error("Profile bind dir failed")
                    Logger.error("Profile bind dir failed (status: %d) %s" %
                                 (p.returncode, p.stdout.read()))
                    return False
                else:
                    self.folderRedirection.append(self.homeDir)

            self.copySessionStart()
コード例 #25
0
ファイル: Manager.py プロジェクト: bacgroup/ovd_sources
class Manager:
    ts_group_name = TS.getUsersGroup()
    ovd_group_name = "OVDUsers"

    def __init__(self, smManager):
        self.smManager = smManager

    def send_session_status(self, session):
        try:
            doc = Document()
            rootNode = doc.createElement('session')
            rootNode.setAttribute("id", session.id)
            rootNode.setAttribute("status", session.status)
            if session.status == Session.SESSION_STATUS_DESTROYED and session.end_status is not None:
                rootNode.setAttribute("reason", session.end_status)

            doc.appendChild(rootNode)
        except Exception:
            Logger.exception("ApplicationServer: send_session_status")

        response = self.smManager.send_packet("/session/status", doc)
        Logger.debug2("ApplicationServer: send_session_status: %s" %
                      (response))
        if response is False:
            Logger.warn("ApplicationServer: unable to send session status")
        else:
            response.close()
            response = None

    def send_session_dump(self, session):
        dumps = {}

        for path in glob.glob(
                os.path.join(Config.spool_dir, "sessions dump archive",
                             "%s %s-*" % (session.id, session.user.name))):
            try:
                f = file(path, "r")
            except IOError, err:
                continue

            data = f.read()
            f.close()

            name = os.path.basename(path)
            name = name[len("%s %s-" % (session.id, session.user.name)):]

            dumps[name] = data

        data = session.log.get_full_log()
        if len(data) > 0:
            dumps["server.log"] = data

        try:
            doc = Document()
            rootNode = doc.createElement('session')
            rootNode.setAttribute("id", session.id)

            for (name, data) in dumps.items():
                textNode = doc.createTextNode(base64.encodestring(data))

                node = doc.createElement('dump')
                node.setAttribute("name", name)
                node.appendChild(textNode)

                rootNode.appendChild(node)

            doc.appendChild(rootNode)
        except Exception:
            Logger.exception("ApplicationServer: send_session_dump")

        response = self.smManager.send_packet("/session/dump", doc)
        Logger.debug2("ApplicationServer: send_session_dump: %s" % (response))
        if response is False:
            Logger.warn("ApplicationServer: unable to send session dump")
        else:
            response.close()
            response = None
コード例 #26
0
ファイル: Profile.py プロジェクト: skdong/nfs-ovd
	def mount(self):
		os.makedirs(self.cifs_dst)
		self.homeDir = pwd.getpwnam(self.transformToLocaleEncoding(self.session.user.name))[5]
		
		if self.profile is not None:
			os.makedirs(self.profile_mount_point)
			
			cmd = "mount -t cifs -o username=%s,password=%s,uid=%s,gid=0 //%s/%s %s"%(self.profile["login"], self.profile["password"], self.session.user.name, self.profile["server"], self.profile["dir"], self.profile_mount_point)
			cmd = self.transformToLocaleEncoding(cmd)
			Logger.debug("Profile mount command: '%s'"%(cmd))
			s,o = commands.getstatusoutput(cmd)
			if s != 0:
				Logger.error("Profile mount failed")
				Logger.debug("Profile mount failed (status: %d) => %s"%(s, o))
				os.rmdir(self.profile_mount_point)
			else:
				self.profileMounted = True
		
		for sharedFolder in self.sharedFolders:
			dest = os.path.join(self.MOUNT_POINT, self.session.id, "sharedFolder_"+ hashlib.md5(sharedFolder["server"]+ sharedFolder["dir"]).hexdigest())
			if not os.path.exists(dest):
				os.makedirs(dest)
			
			print "mount dest ",dest
			cmd = "mount -t cifs -o username=%s,password=%s,uid=%s,gid=0 //%s/%s %s"%(sharedFolder["login"], sharedFolder["password"], self.session.user.name, sharedFolder["server"], sharedFolder["dir"], dest)
			cmd = self.transformToLocaleEncoding(cmd)
			Logger.debug("Profile, sharedFolder mount command: '%s'"%(cmd))
			s,o = commands.getstatusoutput(cmd)
			if s != 0:
				Logger.error("Profile sharedFolder mount failed")
				Logger.debug("Profile sharedFolder mount failed (status: %d) => %s"%(s, o))
				os.rmdir(dest)
			else:
				sharedFolder["mountdest"] = dest
				home = self.homeDir
				
				dst = os.path.join(home, sharedFolder["name"])
				i = 0
				while os.path.exists(dst):
					dst = os.path.join(home, sharedFolder["name"]+"_%d"%(i))
					i += 1
				
				if not os.path.exists(dst):
					os.makedirs(dst)
				
				cmd = "mount -o bind \"%s\" \"%s\""%(dest, dst)
				cmd = self.transformToLocaleEncoding(cmd)
				Logger.debug("Profile bind dir command '%s'"%(cmd))
				s,o = commands.getstatusoutput(cmd)
				if s != 0:
					Logger.error("Profile bind dir failed")
					Logger.error("Profile bind dir failed (status: %d) %s"%(s, o))
				else:
					sharedFolder["local_path"] = dst
					self.folderRedirection.append(dst)
					self.addGTKBookmark(dst)
		
		if self.profile is not None and self.profileMounted:
			for d in [self.DesktopDir, self.DocumentsDir]:
				src = os.path.join(self.profile_mount_point, d)
				dst = os.path.join(self.homeDir, d)
				
				while not os.path.exists(src):
					try:
						os.makedirs(src)
					except OSError, err:
						if self.isNetworkError(err[0]):
							Logger.warn("Unable to access profile: %s"%(str(err)))
							return
						
						Logger.debug2("Profile mkdir failed (concurrent access because of more than one ApS) => %s"%(str(err)))
						continue
				
				if not os.path.exists(dst):
					os.makedirs(dst)
				
				cmd = "mount -o bind \"%s\" \"%s\""%(src, dst)
				cmd = self.transformToLocaleEncoding(cmd)
				Logger.debug("Profile bind dir command '%s'"%(cmd))
				s,o = commands.getstatusoutput(cmd)
				if s != 0:
					Logger.error("Profile bind dir failed")
					Logger.error("Profile bind dir failed (status: %d) %s"%(s, o))
				else:
					self.folderRedirection.append(dst)
			
			
			self.copySessionStart()
コード例 #27
0
ファイル: Profile.py プロジェクト: bloveing/openulteo
	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)