def sendResponse(contentProvider): logonUserResponse = ICP_pb2.LogonUserResponse() if contentProvider: logger.debug("returning session {0} -> {1}".format( session.getId(), contentProvider.pipeName)) logonUserResponse.serviceEndpoint = '\\\\.\\pipe\\{0}'.format( contentProvider.pipeName) (logonUserResponse.maxWidth, logonUserResponse.maxHeight) = session.policy.maxResolution logonUserResponse.ogonCookie = contentProvider.ogonCookie logonUserResponse.backendCookie = contentProvider.backendCookie #logonUserResponse.maxMonitors = session.policy.maxMonitors else: logonUserResponse.serviceEndpoint = '' (logonUserResponse.maxWidth, logonUserResponse.maxHeight) = (0, 0) logonUserResponse.ogonCookie = logonUserResponse.backendCookie = '' #logonUserResponse.maxMonitors = session.policy.maxMonitors ret = [ self.connection.buildResponse(pbrpc.msgType, pbrpc.tag, logonUserResponse) ] if contentProvider and session.isAuthenticated( ) and self.spokenProtocol > 101: logonInfoReq = ICP_pb2.LogonInfoRequest() logonInfoReq.connectionId = connectionId logonInfoReq.login = session.login logonInfoReq.domain = session.domain logonInfoReq.sessionId = session.getId() logonInfoReq.cookie = session.reconnectCookie.encode('utf-8') def logonInfoReqCb(args): (status, payload) = args if status != pbRPC_pb2.RPCBase.SUCCESS: logger.error("pbRPC: error in logon info requests") else: resp = ICP_pb2.LogonInfoResponse() resp.ParseFromString(payload) logger.debug('logonInfoReq: success={0}'.format( resp.success)) d = Deferred() d.addCallback(logonInfoReqCb) ret.append( self.connection.buildQuery(ICP_pb2.LogonInfo, logonInfoReq, d)) if session.isAuthenticated() and self.topka.sessionNotification: reactor.callLater( 0.1, self.topka.sessionNotification.SessionNotification, wtsapi.WTS_REMOTE_CONNECT, session.getId()) return ret
def EndSession(self, pbrpc, msg): logger.debug("EndSession(sessionId={0})".format(msg.sessionId)) ret = SBP_pb2.EndSessionResponse() session = self.topka.retrieveSessionBySessionId(msg.sessionId) if session is None or session.connectionId is None: logger.error("session {0} not found".format(msg.sessionId)) ret.success = False return ret ret.success = True logoffReq = ICP_pb2.LogoffUserSessionRequest() logoffReq.connectionId = session.connectionId session.state = wtsapi.WTSDisconnected def endSessionCb(args): (status, payload) = args if status != pbRPC_pb2.RPCBase.SUCCESS: logger.error("pbRPC: error in LogoffUserSession") else: resp = ICP_pb2.LogoffUserSessionResponse() resp.ParseFromString(payload) logger.debug('logoffUserSessionResp: loggedoff={0}'.format( resp.loggedoff)) d = Deferred() d.addCallback(endSessionCb) return [ self.connection.buildResponse(pbrpc.msgType, pbrpc.tag, ret), self.connection.buildQuery(ICP_pb2.LogoffUserSession, logoffReq, d) ]
def DisconnectUserSession(self, _pbrpc, msg): logger.debug('DisconnectUserSession(connId={0})'.format( msg.connectionId)) session = self.topka.retrieveSessionByConnectionId(msg.connectionId) d = defer.succeed(True) if session: session.connectionId = None if self.topka.sessionNotification: self.topka.sessionNotification.SessionNotification( wtsapi.WTS_REMOTE_DISCONNECT, session.getId()) if session.state == wtsapi.WTSIdle or not session.policy.allowReconnect: # let's kill all running apps if # * session was not logged on (greeter) # * session's policy doesn't allow reconnection d = session.killApps() self.topka.removeSession(session) session.state = wtsapi.WTSDisconnected ret = ICP_pb2.DisconnectUserSessionResponse() def error(v): logger.error('got error {0}'.format(v)) ret.disconnected = False return ret def cb(v): ret.disconnected = True return ret return d.addCallbacks(cb, error)
def endSessionCb(args): (status, payload) = args if status != pbRPC_pb2.RPCBase.SUCCESS: logger.error("pbRPC: error in LogoffUserSession") else: resp = ICP_pb2.LogoffUserSessionResponse() resp.ParseFromString(payload) logger.debug('logoffUserSessionResp: loggedoff={0}'.format( resp.loggedoff))
def logonInfoReqCb(args): (status, payload) = args if status != pbRPC_pb2.RPCBase.SUCCESS: logger.error("pbRPC: error in logon info requests") else: resp = ICP_pb2.LogonInfoResponse() resp.ParseFromString(payload) logger.debug('logonInfoReq: success={0}'.format( resp.success))
def logonInfoCb(args): (status, payload) = args if status != pbRPC_pb2.RPCBase.SUCCESS: logger.error("pbRPC: error in logonInfo") return resp = ICP_pb2.LogonInfoResponse() resp.ParseFromString(payload) logger.debug('LogonInfo: success={0}'.format(resp.success))
def errorHandler(e): logger.error( 'completeLogonOrReconnect: got an error={0}'.format(e)) logonUserResponse = ICP_pb2.LogonUserResponse() logonUserResponse.serviceEndpoint = '' (logonUserResponse.maxWidth, logonUserResponse.maxHeight) = (0, 0) logonUserResponse.ogonCookie = '' logonUserResponse.backendCookie = '' return [ self.connection.buildResponse(pbrpc.msgType, pbrpc.tag, logonUserResponse) ]
def switchPipeCb(args): (status, payload) = args if status != pbRPC_pb2.RPCBase.SUCCESS: logger.error("pbRPC: error in SwitchReq") return resp = ICP_pb2.SwitchToResponse() resp.ParseFromString(payload) logger.debug('switchToResp: success={0}'.format(resp.success)) if resp.success and sessionToDrop: logger.debug("removing greeter session %s as instructed" % sessionToDrop.getId()) self.topka.removeSession(sessionToDrop)
def PropertyBulk(self, _pbrpc, msg): props = [] for p in msg.properties: props.append(p.propertyPath) logger.debug("propertyBulk(%s, [%s])" % (msg.connectionId, ", ".join(props))) ogonConfig = self.config['ogon'] ret = ICP_pb2.PropertyBulkResponse() for p in msg.properties: key = p.propertyPath if key.startswith("ogon."): key = key[len("ogon."):] propValue = ret.results.add() propValue.success = False if key in ogonConfig: v = ogonConfig[key] if p.propertyType == ICP_pb2.PROP_BOOL: if isinstance(v, bool): propValue.boolValue = v propValue.success = True else: logger.error('propertyBulk: %s is not a bool' % p.propertyPath) elif p.propertyType == ICP_pb2.PROP_NUMBER: if isinstance(v, int): propValue.intValue = v propValue.success = True else: logger.error('propertyBulk: %s is not a number' % p.propertyPath) elif p.propertyType == ICP_pb2.PROP_STRING: if isinstance(v, str): propValue.stringValue = v propValue.success = True else: logger.error('propertyBulk: %s is not a string' % p.propertyPath) else: logger.error("propertyBulk: property %s not found" % key) return ret
def PropertyString(self, _pbrpc, msg): logger.debug("propertyString(%s, %s)" % (msg.connectionId, msg.path)) ret = ICP_pb2.PropertyStringResponse() ret.success = True key = msg.path if key.startswith("ogon."): key = key[len("ogon."):] ogonConfig = self.config['ogon'] ret.success = key in ogonConfig ret.value = ogonConfig.get(key, '') if not ret.success: logger.error("value %s not found in config" % key) return ret
def PropertyBool(self, _pbrpc, msg): logger.debug("propertyBool(%s, %s)" % (msg.connectionId, msg.path)) ret = ICP_pb2.PropertyBoolResponse() ret.success = False key = msg.path if key.startswith("ogon."): key = key[len("ogon."):] ogonConfig = self.config['ogon'] if key in ogonConfig: v = ogonConfig[key] if isinstance(v, bool): ret.value = v ret.success = True else: logger.error("value %s not found in config" % key) ret.value = -1 return ret
def sendResponse(contentProvider): ret.authStatus = SBP_pb2.AuthenticateUserResponse.AUTH_SUCCESSFUL answers = [ self.connection.buildResponse(pbrpc.msgType, pbrpc.tag, ret) ] switchReq = ICP_pb2.SwitchToRequest() switchReq.connectionId = srcSession.connectionId switchReq.serviceEndpoint = '\\\\.\\pipe\\{0}'.format( contentProvider.pipeName) (switchReq.maxWidth, switchReq.maxHeight) = retSession.policy.maxResolution switchReq.ogonCookie = contentProvider.ogonCookie switchReq.backendCookie = contentProvider.backendCookie def switchPipeCb(args): (status, payload) = args if status != pbRPC_pb2.RPCBase.SUCCESS: logger.error("pbRPC: error in SwitchReq") return resp = ICP_pb2.SwitchToResponse() resp.ParseFromString(payload) logger.debug('switchToResp: success={0}'.format(resp.success)) if resp.success and sessionToDrop: logger.debug("removing greeter session %s as instructed" % sessionToDrop.getId()) self.topka.removeSession(sessionToDrop) d = Deferred() d.addCallback(switchPipeCb) answers.append( self.connection.buildQuery(ICP_pb2.SwitchTo, switchReq, d)) if self.spokenProtocol > 100: logonInfo = ICP_pb2.LogonInfoRequest() logonInfo.connectionId = retSession.connectionId logonInfo.login = user logonInfo.domain = domain logonInfo.sessionId = retSession.getId() def logonInfoCb(args): (status, payload) = args if status != pbRPC_pb2.RPCBase.SUCCESS: logger.error("pbRPC: error in logonInfo") return resp = ICP_pb2.LogonInfoResponse() resp.ParseFromString(payload) logger.debug('LogonInfo: success={0}'.format(resp.success)) d2 = Deferred() d2.addCallback(logonInfoCb) answers.append( self.connection.buildQuery(ICP_pb2.LogonInfo, logonInfo, d2)) if retSession.isAuthenticated() and self.topka.sessionNotification: reactor.callLater( 0.1, self.topka.sessionNotification.SessionNotification, wtsapi.WTS_REMOTE_CONNECT, retSession.getId()) return answers
def RemoteControlEnded(self, _pbrpc, msg): logger.debug("RemoteControlEnded(spy={0} spied={1})".format( msg.spyId, msg.spiedId)) ret = ICP_pb2.RemoteControlEndedResponse() ret.success = True return ret
def IsChannelAllowed(self, _pbrpc, msg): logger.debug("IsChannelAllowed(%s)" % msg.ChannelName) ret = ICP_pb2.IsChannelAllowedResponse() ret.channelAllowed = True return ret