Menu

#1870 command line switch to send a string to plugins

KeePass_2.x
closed
nobody
None
5
2019-04-02
2014-05-09
sambowry
No

Please add a command line switch to send a string to plugins of a running KeePass. Usage example:

keepass.exe "-event:asdf 1234"
keepass.exe  -event:ilo://server/

I think this feature is needed to allow writing of URL Protocol Handler plugins.

Here is my proof of concept amateur implementation:
https://github.com/sambowry/keepass2/commit/b8b30f517085dd3776d3cc7cb37053bee7ed7424

Discussion

  • Dominik Reichl

    Dominik Reichl - 2014-05-09

    I don't see why you would need this for writing URL protocol handler plugins. For an example, see the IOProtocolExt plugin (this plugin e.g. adds handlers for scp:// and sftp://, and does not require such a command line option).

    Best regards,
    Dominik

     
    • sambowry

      sambowry - 2014-05-10

      I know only one method* to start an application by clicking on an URL in a web browser: there must be a registry entry HKCU/software/classes/(protocol)/shell/open/command = "exe args". Than the 'exe' should pass the 'arg' to the URL processing module of the running program instance. KeePass is the best choice for the 'exe' role because the URL handler will be a KeePass plugin.

      I don't found code fragments in IOProtocolExt which is usable by me for this task.

      A minimalistic example to demonstrate the "event" switch usage for receiving URLs:
      https://github.com/sambowry/KPUrl/blob/master/KPUrl/KPUrlExt.cs

      [* I tried DDE (ndde) too, but it does not work for me with Internet Explorer. ]

       
  • sambowry

    sambowry - 2014-05-10

    I changed the syntax. Passing all command line args may more usable than passing only one string:

    keepass.exe -event:value0 -arg1:value1 -arg2:value2
    

    KeePass modifications:
    https://github.com/sambowry/keepass2/tree/ipc

    demo plugin shows how to receive "-event" message args:
    https://github.com/sambowry/KPUrl

    The plugin registers a "KPUrl:" Protocol Handler in the Windows Registry at KeePass start, and remove it at exit. Then displays "KPUrl:any string" messages received from web browsers or other callers.

    The plugin registers enabled UrlSchemeOverrides. It save matching URL scheme entries (e.g. 'ssh:') at start ('KPUrl-ssh:') and restore on exit.

    The attached screenshot demonstrate a basic usage example. You have an URL in a (webpage, email, Excel, etc) document: "ssh://sample1". One click and KeePass find the right entry then run "PuTTY.exe -l MyUsername -pw MyPassword -ssh sample1".

     

    Last edit: sambowry 2014-05-11
  • Dominik Reichl

    Dominik Reichl - 2014-05-14

    Thanks; I've implemented this now. Your plugin can subscribe to the event IpcUtilEx.IpcEvent, which is raised e.g. when running KeePass.exe with the -e:EVENT command line parameter (where EVENT describes the event, like the "KPUrl" that you used; your plugin should check the Name property of the event arguments for being EVENT).

    Here's the latest development snapshot for testing (including the modified source code files):
    http://keepass.info/filepool/KeePass_140514_c.zip

    By the way, in my opinion your plugin should maintain an own list of system-wide URL scheme handlers. The URL overrides in KeePass and system-wide URL scheme handlers are two different things. For example, URL overrides within KeePass have an entry context, whereas system-wide URLs do not; a separate management would allow to introduce better entry matching methods. Furthermore, while it is fine to override URLs with standard protocols like HTTP/HTTPS/FTP within KeePass, most users probably don't want this system-wide.

    Best regards,
    Dominik

     
    • kibinimatik

      kibinimatik - 2019-04-01

      What should happen, if more than one KeePass instances are running and such a command line argument is sent?
      Would it be most correct if each plugin in each KeePass instance handles this event separately?
      The behaviour with the KeePass 2.41 seems undefined.

       
  • Dominik Reichl

    Dominik Reichl - 2014-05-14
    • status: open --> closed
     
  • Dominik Reichl

    Dominik Reichl - 2019-04-01

    Such extended IPC messages are handled by one KeePass instance only. KeePass uses this mechanism for opening another database, and here the expected behavior is to open it once.

    Best regards,
    Dominik

     
  • Dominik Reichl

    Dominik Reichl - 2019-04-02

    Whether it makes sense that a command is handled by one or by all other instances depends on the command and the user's intention.

    Therefore, I've now added a '-e1:' command line parameter, which works like '-e:', but is handled by one other instance only. '-e:' is now handled by all other instances.

    Event handlers in plugins do not need to be changed. Both '-e:' and '-e1:' invoke the IpcUtilEx.IpcEvent event.

    Here's the latest development snapshot for testing:
    https://keepass.info/filepool/KeePass_190402.zip

    Thanks and best regards,
    Dominik

     
  • kibinimatik

    kibinimatik - 2019-04-02

    Many thanks!

     

Log in to post a comment.

MongoDB Logo MongoDB