Beispiel #1
0
        public static ICommand CreateCommandExecutor(
            string commandValue,
            CommandLineParameters instance,
            InputControl io
            )
        {
            var types = LoadTypes();

            foreach (var type in types)
            {
                var attr = type.GetCustomAttribute <CommandLineCommandAttribute>();

                if (string.Equals(commandValue, attr.Command, StringComparison.InvariantCultureIgnoreCase))
                {
                    var ctor = type.GetConstructor(new[] { typeof(CommandLineParameters) });

                    ICommand command;

                    if (ctor != null)
                    {
                        command = (ICommand)ctor.Invoke(new[] { instance });
                    }
                    else
                    {
                        command = (ICommand)Activator.CreateInstance(type);
                    }

                    command.IO = io;

                    return(command);
                }
            }

            return(null);
        }
Beispiel #2
0
        protected BaseCommand(CommandLineParameters parameters)
        {
            this.Parameters = parameters;

            this.ParseParameters();

            this.CalculateUserAndRealm();
        }
Beispiel #3
0
        private async Task DumpServiceTicket(KerberosClient client)
        {
            var rep = await client.GetServiceTicket(this.DumpServicePrincipalName);

            string apreq;

            if (this.DumpAsNegotiate)
            {
                apreq = Convert.ToBase64String(rep.EncodeGssApi().ToArray());
            }
            else
            {
                apreq = Convert.ToBase64String(rep.EncodeApplication().ToArray());
            }

            var command = new KerberosDumpCommand(CommandLineParameters.Parse($"kdecode --ticket \"{apreq}\""));

            await command.Execute();
        }
        private bool TryProcessSystemCommand(CommandLineParameters parameters, out bool exiting)
        {
            exiting = false;

            switch (parameters.Command.ToLowerInvariant())
            {
            case "exit":
            case "quit":
            case "q":
                exiting = true;
                return(true);

            case "clear":
            case "cls":
                this.io.Clear();

                return(true);
            }

            return(false);
        }
Beispiel #5
0
        private async Task ExecuteCommand(CommandLineParameters parameters)
        {
            var command = parameters.CreateCommandExecutor(this.io);

            if (command == null)
            {
                this.PrintUnknownCommand(parameters);
            }

            bool executed = false;

            if (command != null)
            {
                executed = await command.Execute();
            }

            if (!executed)
            {
                command?.DisplayHelp();
            }
        }
        private async Task ExecuteCommand(CommandLineParameters parameters)
        {
            var command = parameters.CreateCommandExecutor(this.io);

            if (command == null)
            {
                this.PrintUnknownCommand(parameters);
            }

            if (command != null)
            {
                var executed = await command.Execute();

                if (!executed)
                {
                    this.io.Writer.WriteLine();
                    command.DisplayHelp();
                }
            }

            this.io.Writer.WriteLine();
        }
Beispiel #7
0
 public KerberosListCommand(CommandLineParameters parameters)
     : base(parameters)
 {
 }
 public KerberosDestroyCommand(CommandLineParameters parameters)
     : base(parameters)
 {
 }
 public KerberosWhoAmI(CommandLineParameters parameters)
     : base(parameters)
 {
 }
 public KerberosKeytabCommand(CommandLineParameters parameters)
     : base(parameters)
 {
 }
 public KerberosConfigCommand(CommandLineParameters parameters)
     : base(parameters)
 {
 }
        private async Task StartLoop()
        {
            bool attemptExternal = !string.IsNullOrWhiteSpace(this.CommandLine) || !string.IsNullOrWhiteSpace(this.LoadingModule);
            bool singleRun       = false;

            while (true)
            {
                string commandLine = null;

                if (attemptExternal)
                {
                    commandLine     = this.CommandLine;
                    attemptExternal = false;
                }

                if (string.IsNullOrWhiteSpace(commandLine) && string.IsNullOrWhiteSpace(this.LoadingModule))
                {
                    this.io.Writer.Write(this.ShellPrefix);
                    commandLine = this.io.Reader.ReadLine();
                }

                if (!string.IsNullOrWhiteSpace(this.LoadingModule))
                {
                    commandLine = $"{this.LoadingModule} {commandLine}".Trim();
                    singleRun   = true;
                }

                var parameters = CommandLineParameters.Parse(commandLine);

                if (string.IsNullOrWhiteSpace(parameters?.Command))
                {
                    continue;
                }

                if (this.TryProcessSystemCommand(parameters, out bool exiting))
                {
                    if (exiting && !this.TryPopShell())
                    {
                        break;
                    }

                    continue;
                }

                try
                {
                    await this.ExecuteCommand(parameters);
                }
                catch (AggregateException agg)
                {
                    this.io.Writer.WriteLine();

                    foreach (var ex in agg.InnerExceptions)
                    {
                        this.io.Writer.WriteLine(ex.Message);
                    }
                }
                catch (Exception ex)
                {
                    if (ex is TargetInvocationException tex)
                    {
                        ex = tex.InnerException;
                    }

                    this.io.Writer.WriteLine();

                    if (this.Verbose)
                    {
                        this.io.Writer.WriteLine(ex);
                    }
                    else
                    {
                        this.io.Writer.WriteLine(ex.Message);
                    }

                    this.io.Writer.WriteLine();
                }

                if (singleRun)
                {
                    break;
                }
            }
        }
 private void PrintUnknownCommand(CommandLineParameters parameters)
 {
     this.io.Writer.WriteLine();
     this.io.Writer.WriteLine(string.Format(Strings.UnknownCommand, parameters.Command));
 }
Beispiel #14
0
        protected BaseCommand(CommandLineParameters parameters)
        {
            this.Parameters = parameters;

            this.ParseParameters();
        }