Giter VIP home page Giter VIP logo

cbwin's People

Contributors

marcosdiez avatar xilun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cbwin's Issues

Starting parameters for bash.exe

I need to start bash with the following arguments: "C:\windows\system32\bash.exe -l -i -cur_console:p1 -new_console:p:n"

But its not possible to do it through outbash.exe

wstart /mnt/c/windows does not work

it should have the same effect as being in cmd.exe and typing

start c:\windows

I think that can easily be fixed. If you agree with this behavior, just tell me and I can write a PR during the weekend.

0.9 breaks my use case

Hi Xilun,

I was using 0.6 for a while, but when I updated to 0.9, it broke my use case.

interactive win32 console programs are broken (input and output)

(Output breakage is actually also seen in some non-interactive win32 console programs.)

It can probably be fixed in a lot of cases by a few calls of GetConsoleMode() and SetConsoleMode().

In case of concurrent executions there might be no perfect way to do it, but I guess something that works most of the time can be good enough.

Use double quotes to prevent word splitting may be better

When I pass a filename which contains spaces to wcmd/wrun/wstart:

# Use tab to complete filename
$ wstart c:/mine/app/mpv/mpv.exe aa\ bb.mp4

Playing: aa
[file] Cannot open file 'aa': No such file or directory
Failed to open aa.

Playing: bb.mp4
[file] Cannot open file 'bb.mp4': No such file or directory
Failed to open bb.mp4.

or

$ wstart c:/mine/app/mpv/mpv.exe "aa bb.mp4"
Playing: aa
[file] Cannot open file 'aa': No such file or directory
Failed to open aa.

Playing: bb.mp4
[file] Cannot open file 'bb.mp4': No such file or directory
Failed to open bb.mp4.

aa bb.mp4 was splited to two filenames.

# It works, but inconveniently.
$ wrun c:/mine/app/mpv/mpv.exe '"aa bb.mp4"'
Playing: aa bb.mp4

So I wrote a shell function:

vrun() {
    local cmd arg
    cmd="$1"
    shift

    for i in "$@"; do
        arg=$arg' "'$i'"'
    done

    wrun $cmd $arg
}

$ vrun c:/mine/app/mpv/mpv.exe aa\ bb.mp4
Playing: aa bb.mp4

$ vrun c:/mine/app/mpv/mpv.exe "aa bb.mp4"
Playing: aa bb.mp4

But I think wrun/wcmd/wstart should do this work, like this:

diff --git a/caller/wrun.c b/caller/wrun.c
index ed99a21..4dbcff4 100644
--- a/caller/wrun.c
+++ b/caller/wrun.c

@@ -964,8 +981,9 @@ int main(int argc, char *argv[])

     bool sep = false;
     for (int i = 0; i < argc; i++) {
-        if (sep) string_append(&outbash_command, " ");
+        if (sep) string_append(&outbash_command, " \"");
         string_append(&outbash_command, argv[i]);
+        if (sep) string_append(&outbash_command, "\"");
         sep = true;
     }
     string_append(&outbash_command, "\n\n");
@@ -1017,6 +1035,7 @@ int main(int argc, char *argv[])
         terminate_nocore();
     }

No terminal support

I know I can use ssh to connect directly to running machine or even use virtualbox GUI to connect to the running virtual machine, but sometimes it is more convenient to be used as such. Currently if I try to wrun vagrant ssh or wrun ssh it gives me:

Pseudo-terminal will not be allocated because stdin is not a terminal.

cover safe elevated usage (disallow trivial escalation in that case)

Even if, for now, outbash should only be used on single user computers, it would be nice to at least disallow trivial escalation when outbash is launched elevated. For now it does nothing special, so if it has been launched elevated all the Win32 processes it launches will also be elevated. This is not desirable, because it does not control access.

It is desirable to allow outbash to be launched elevated, because bash.exe allows it and the resulting WSL processes get Win32 administrator privilege (mostly for FS access on drive FS). For now I think that WSL has a security hole that allows escalation (microsoft/WSL#626) though existing elevated WSL processes but I have no doubt they will fix it for Redstone.

So, back to outbash: if it runs elevated, it should "simply" run commands on behalf of the caller process. I think this is doable with a very cautious usage of Iphlpapi to retrieve the Win PID of the peer and then open the process handle (to get the token) in such a way that we know it is effectively from the process which emitted the command. We must really be very very cautious: I've constructed a scenario where the Win PID potentially points to another process even though the socket is still open and fully alive... The safe approach would be somehow similar to what I've done to suspend the processes of the Windows Job: a second control while the Handle is open.

NOTE: remember that outbash.exe intrinsically allows escalation from WSL user to WSL root. This is due to the WSL design, and unrelated to this issue. The WSL VolFs is physically hosted in AppData of the user account with Win32 user permissions, Win32 processes are not subject to WSL access control, so they are effectively equivalent to WSL root. There is no way to change that without modifying Windows.

Vagrant output doesn't wrap correctly

vagrant-terminal-output

See image above. Basically, when I run commands like wrun vagrant up, the Vagrant output doesn't wrap correctly, and it's really hard to read the output.

I glanced through other open issues, and didn't see one that was directly related, but feel free to close if there's another open issue that would describe/help fix this behavior.

better handle scenarios with a weaker link to the windows console (tmux, xterm&co, etc.)

For now redirections are forced on pts, and there is OUTBASH_PORT and ~/.config/cbwin/outbash_port if launched with --outbash-session, but this far from ideal. In cases where we came from a Windows Console that is not there anymore (because we launched an xterm, a tmux, whatever) we just fail unless we manually unset OUTBASH_PORT and we somehow managed keep an --outbash-session running. Automating all of that would be preferable.

Some inputted characters skipped in Docker interactive terminal

I've set up Docker for Windows to launch from cbwin via an alias wrun docker. Most docker commands work like a charm, but I see some issues with processing input in an interactive container:

image

As you can see, entering "echo hello" dropped various characters depending on how fast i type, seemingly. Really interesting is after i exit the container, the characters that were skipped get output to my prompt.

I've already had success with formatting Docker's stdout using the wcmd echo solution from #37. Could there be a similar workaround for this issue?

Great tool by the way... soon I won't have a use case for cygwin!

a cmd-like behavior distinguishing between console / GUI target programs might be useful

For example in cmd "notepad" starts notepad and do not wait for its termination, while cmd waits for termination of console programs.

However, this is not trivial to implement given how Win32 processes are managed in jobs with the current policy of terminating them on exit of the initial win32 process (except with silent-breakaway:1, which is used by wstart)
Basically I would probably have to check myself if the target is GUI or console (at least if the termination policy remains)

manage Win32 processes using Jobs

for a more proper suspend and termination support

See Job Objects and Job Object Functions on MSDN.

Note: process should be created suspended, then put in the job, then resumed, otherwise there is a risk of a race where newly created processes could spawn others before being put in the job...

Default command handler

Here is a script for people that want to use WSL like Cygwin. If command is not found on Linux it will attempt to run it on windows automatically:

# Whether to attempt to run command from %USERPROFILE% dir.
# This is useful when current path can't be translated to a windows path.
# Also potentially dangerous for example if you run windows delete commands
# in /tmp it may actually delete your windows home dir
ATTEMPT_TO_RUN_IN_HOME_DIR=false

# Choose one from 'wcmd', 'wrun', 'wstart'
COMMAND="wrun"

try_cbwin() {
    if [[ $# -gt 0 ]]; then
        if $COMMAND where "$1" > /dev/null 2>&1; then
            $COMMAND "$@"
            return 0
        fi
        if [ "$ATTEMPT_TO_RUN_IN_HOME_DIR" = true ] && $COMMAND : where "$1" > /dev/null 2>&1; then
            $COMMAND : "$@"
            return 0
        fi
    fi

    return 1
}

save_old_command_handler() {
    if declare -f command_not_found_handler > /dev/null; then
        eval "$(echo "orig_command_not_found_handler(){"; declare -f $1 | tail -n +2)"
        OLD_COMMAND_HANDLER=true
    else
        OLD_COMMAND_HANDLER=false
    fi
}

command_not_found_chain_handler() {
    if try_cbwin "$@"; then
        return 0
    elif [ $OLD_COMMAND_HANDLER = true ]; then
        orig_command_not_found_handler "$@"
        return $?
    else
        return 1
    fi
}

case "${SHELL}" in
    */zsh)
        save_old_command_handler "command_not_found_handler"
        command_not_found_handler() {
            command_not_found_chain_handler "$@"
            return $?
        }
        ;;
    */bash)
        save_old_command_handler "command_not_found_handle"
        command_not_found_handle() {
            command_not_found_chain_handler "$@"
            return $?
        }
        ;;
esac

Just save this script to a file and add source this_script.sh to .bashrc or .zshrc depending on your shell. This is pretty basic implementation, feel free to improve it

Not work inside zsh

Works directly in bash.
However, after I launch zsh inside bash, wcmd errors
ERR MSG:

wcmd: OUTBASH_PORT environment variable not set, and could not read /home/lky/.config/cbwin/outbash_port
wcmd: can't translate a WSL VolFs path to a Win32 one
[1] 132 killed wcmd ver

wsl

backgrounded & force redirected caller => SIGTTIN

Ex: bg a wrun notepad & in tmux

There is not much I can do about it... at least for console programs.
Once again detecting GUI programs would be beneficial: we could have NUL redirects by default.

find a workaround to mitigate failures of GetExtendedTcpTable()

GetExtendedTcpTable() sometimes miserably fails and returns 0xc0000001 (NT status generic error)
(This prevents a command from being launched when this occurs.)

I must find a workaround to mitigate the effect of such failures. Calling GetExtendedTcpTable() again in a loop in this case is not efficient enough (I still have some failures after 5 retries...)

Text is not aligning right.

its hard to read because the out put text looks like this.

ult: TASK [wordpress-install : include] *********************************************
                                                                                     ==> default: included: /vagrant/roles/wordpress-install/tasks/directories.yml for 192.168.50.5
                                     ==> default:
                                                  ==> default: TASK [wordpress-install : Create web root of sites] ****************************
 ==> default: ok: [192.168.50.5] => (item=example.com)
                                                      ==> default:
                                                                   ==> default: TASK [wordpress-install : Create shared folder of sites] ***********************
                  ==> default: changed: [192.168.50.5] => (item=example.com)
                                                                            ==> default:
                                                                                         ==> default: TASK [wordpress-install : Change site owner to user] ***************************
                                        ==> default: changed: [192.168.50.5] => (item=example.com)
                                                                                                  ==> default:
                                                                                                               ==> default: TASK [wordpress-install : Create .env file] ************************************
                                                              ==> default: changed: [192.168.50.5] => (item=example.com)
                                                                                                                        ==> default:
                                                                                                                                     ==> default: TASK [wordpress-install : Copy .env file into web root] ************************
                                                                                    ==> default: changed: [192.168.50.5] => (item=example.com)
                                                                                                                                             ==> default:
            ==> default: TASK [wordpress-install : Install Dependencies with Composer] ******************

anyone know how to fix this??

Thank you!!

Can't remove cbwin from my pc

Hi,

I found and used cbwin last year in University to launch external graphical programms. However I now use the WSL which can launch GUI programms by itself so I no longer use cbwin. I tried to delete it but Windows told me I didn't have the rights to access/delete or do anything with the directory. So now I don't know what to do to remove it and I didn't found any help on Github or somewhere else. Thank you

PS : The files attached are pictures of the error message printed by Windows which can be translated by "Windows can't acceed to the peripheral, the access path or the specified file. You may not have the appropriate rights to access to the element" and what's printed in WSL.

(sry for my english)

error_cbwin

error_cbwin2

Let cbwin in session mode launch multiple wcmd instances in parallel

Hi @xilun I was thinking about cbwin and Alex Ionescu's lxserver/lxext persistent communication socket idea, and I was thinking, you could likely do it even more easily with cbwin in session mode.

So here's the idea: when you run something like wcmd cmd or wcmd powershell when cbwin is in session mode, you have two options:

wcmd could inform outbash.exe that it's going to poll a new tcp port, and then outbash launches a new cmd.exe instance that is broadcasting over that new port, just like if we launched a new instance of outbash. If wcmd gets killed, outbash should kill the cmd that it launched.

The other option is to avoid negotiating a secondary tcp port at all, and tag communications between instances of wcmd and outbash on the session port with the PID of the wcmd instance.

The idea behind this is that you could run a single outbash session but lots and lots of wcmd instances in parallel, so for instance, you could run several copies of cmd.exe, powershell.exe, zsh, bash, etc inside of a terminal multiplexer like tmux, or in separate terminal emulators running within the same lxsession.

The benefit of the second method (tagging) is that if/when MS documents the interface that Alex Ionescu's lxserver/lxext uses, you could immediately remove the tcp loopback and pipe communications directly.

Using outbash with urxvtc and Xming

Hi xilun, I was wondering if there was a way to get outbash working with urxvt and Xming. I want to be able to set the clickable links feature in urxvt and have it pipe out to my Windows browser, but right now, it looks like the outbash_port gets reset on every restart. I want to run urxvtd in outbash (which would bind outbash to a port) then run urxvtc so the outbash port is automatically set to be the port bound in the console that started the daemon.

Any idea how to do this, or if you could program it in?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.