Ejemplo n.º 1
0
        private void CommandOpened(object sender, SessionRequestedArgs e)
        {
            var match   = RegexParseCommand.Match(e.CommandText);
            var command = match.Groups["cmd"].Value;
            var project = match.Groups["proj"].Value;

            if (string.IsNullOrWhiteSpace(command) || string.IsNullOrWhiteSpace(project))
            {
                throw new SshConnectionException("Unexpected command.", DisconnectReason.ByApplication);
            }

            var requireWrite = command == "git-receive-pack";
            var fingerprint  = e.AttachedUserauthArgs.Fingerprint;
            var key          = Convert.ToBase64String(e.AttachedUserauthArgs.Key);
            var allow        = requireWrite
                ? _repositoryService.CanWriteRepository(project, fingerprint, key)
                : _repositoryService.CanReadRepository(project, fingerprint, key);

            if (!allow)
            {
                throw new SshConnectionException("Access denied.", DisconnectReason.ByApplication);
            }

            e.Channel.DataReceived  += DataReceived;
            e.Channel.EofReceived   += EofReceived;
            e.Channel.CloseReceived += CloseReceived;
            _channel = e.Channel;

            StartProcess(command, project);
        }