EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Custom Shell Property

Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.
#1318
Posted: 10/02/2006 10:54:11
by Robert Kemp (Basic support level)
Joined: 10/02/2006
Posts: 3

Is there a property in SSHBlackbox (.NET edition) that allows the developer to specify a custom command shell? My plan is to create my own shell with an extreemly limited and custom command-set.
#1320
Posted: 10/02/2006 13:10:43
by Eugene Mayevski (EldoS Corp.)

Are you talking about the ssh server? You can create your own implementation of shel subsystem handler, and do all procesing as you need.


Sincerely yours
Eugene Mayevski
#1401
Posted: 10/10/2006 15:23:39
by Robert Kemp (Basic support level)
Joined: 10/02/2006
Posts: 3

Would you mind posting (or e-mailing me) a sample Shell Subsystem Handler class so I am sure to implement it correctly?

Thank you.
#1408
Posted: 10/11/2006 01:17:30
by Eugene Mayevski (EldoS Corp.)

The only shell subsystem handler we have is written in Delphi and is a part of source code. We don't have other samples and we don't have enough resources to create one now. You can start implementing a handler, and if you have problems, we will check your code.


Sincerely yours
Eugene Mayevski
#1448
Posted: 10/13/2006 14:52:47
by Robert Kemp (Basic support level)
Joined: 10/02/2006
Posts: 3

I know that there are a few things missing from my class -- mainly because it doesn’t work :-). I got this far by using the documentation located here: [URL=http://www.eldos.com/documentation/sbb/documentation/ref_cl_shellsshsubsystemhandler.html]http://www.eldos.com/documentation/sbb/documentation/ref_cl_shellsshsubsystemhandler.html[/URL]

Is there anyone at Eldos or in the user community who can fill in the blanks so I can continue my evalution?

Thank you.


[ Download ]
#1451
Posted: 10/14/2006 00:28:16
by Ken Ivanov (EldoS Corp.)

The following code was taken from the TElShellSSHSubsystemHandler source. Please use it as a guide.

Code
procedure TElShellSSHSubsystemHandler.ProcessStdOutput();
var
  Buf : CharArray;
  Len, OldLen : integer;
  S : string;
  ByteBuf : ByteArray;
begin
  SetLength(Buf, 4096);
  while true and (not FProc.HasExited) do
  begin
    try
      Len := FProc.StandardOutput.Read(Buf, 0, Length(Buf));
      if Len > 0 then
      begin
        FSync.WaitToWrite;
        try
          S := System.String.Create(Buf, 0, Len);
          ByteBuf := BytesOfString(S);
          Len := Length(ByteBuf);
          OldLen := Length(FStdOutSpool);
          SetLength(FStdOutSpool, OldLen + Len);
          Move(ByteBuf, 0, FStdOutSpool, 0, Len);
        finally
          FSync.Done;
        end;
      end;
      Thread.Sleep(0);
    except
      Break;
    end;
  end;
end;

procedure TElShellSSHSubsystemHandler.ProcessStdError();
var
  Buf : CharArray;
  Len, OldLen : integer;
  S : string;
  ByteBuf : ByteArray;
begin
  SetLength(Buf, 4096);
  while true and (not FProc.HasExited) do
  begin
    try
      Len := FProc.StandardError.Read(Buf, 0, Length(Buf));
      if Len > 0 then
      begin
        FSync.WaitToWrite;
        try
          S := System.String.Create(Buf, 0, Len);
          ByteBuf := BytesOfString(S);
          Len := Length(ByteBuf);
          OldLen := Length(FStdErrSpool);
          SetLength(FStdErrSpool, OldLen + Len);
          Move(ByteBuf, 0, FStdErrSpool, 0, Len);
        finally
          FSync.Done;
        end;
      end;
      Thread.Sleep(0);
    except
      Break;
    end;
  end;
end;

procedure TElShellSSHSubsystemHandler.Execute;
var
  Buf : ByteArray;
  ChBuf : CharArray;
  StdOutReader, StdErrReader: Thread;
  cmd: string;
  Received: cardinal;
  S: string;
begin
  SetLength(Buf, 8192);
  SetLength(ChBuf, 8192);
  if Length(Command) = 0 then
    cmd := GetEnvironmentVariable('COMSPEC')
  else
    cmd := GetEnvironmentVariable('COMSPEC') + ' /c ' + Command;
  FProc := Process.Create;
  FProc.StartInfo.Filename := cmd;
  FProc.StartInfo.RedirectStandardInput := true;
  FProc.StartInfo.RedirectStandardOutput := true;
  FProc.StartInfo.RedirectStandardError := true;
  FProc.StartInfo.UseShellExecute := false;
  FProc.StartInfo.WindowStyle := ProcessWindowStyle.Hidden;
  FProc.StartInfo.CreateNoWindow := true;
  FSync := TElSharedResource.Create;
  if FProc.Start() then
  begin
    try
      StdOutReader := Thread.Create(new ThreadStart(ProcessStdOutput));
      StdErrReader := Thread.Create(new ThreadStart(ProcessStdError));
      StdOutReader.Start();
      StdErrReader.Start();
      while (not FProc.HasExited)
        and (not Terminated) and (Connected) do
      begin
        Received := ReceiveData(Buf, 0, Length(Buf));
        S := ConvLF(Buf, 0, Received);
        if Length(S) > 0 then
          FProc.StandardInput.Write(S);
        FSync.WaitToWrite();
        try
          if Length(FStdOutSpool) > 0 then
          begin
            SendData(FStdOutSpool);
            SetLength(FStdOutSpool, 0);
          end;
          if Length(FStdErrSpool) > 0 then
          begin
            SendData(FStdErrSpool);
            SetLength(FStdErrSpool, 0);
          end;
        finally
          FSync.Done;
        end;
        Thread.Sleep(0);
      end;
    finally
      Cleanup;
    end;
  end;
end;
Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.

Reply

Statistics

Topic viewed 3465 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!