Few days ago I sent a PR to the caddy-ssh to properly handle 2 aspects of PTY sessions:

1- properly channeling of std{in,out} to remote when user sends commands

2- user details lookup on macOS

Buckle up! We have a can of worms in hand 🥫🪱 🧵

#golang

github.com/mohammed90/cad…
Issue 1:

The issue was recognized when a friend reported `scp` and `rsync` not working. I found the culprit to be not hooking up the session's/channel's I/O to spawned process, otherwise the new process assumed the null devices as its std{in,out,err}.
In other words, the newly created process was not reading/writing to/from the client's shell, rather from, e.g., secondary tty device (pair of the pty device). Thus the I/O was not channeled from the client to the process, rather to the PTY session.

dev.to/napicella/linu…
The PR hooks the client's I/O directly as the newly spawned process' std{in,out}. This means when issuing a command which expects to read bytes from stdin, the stdin of the remote process is fed from the local client, not the remote tty. Now `scp` et. al. can work.

Onto item 2..
Issue 2:

If you're on macOS, go look for your user in `/etc/passwd`. You will not find it. macOS uses Open Directory to manage the users, so the users' {meta,}data are stored in the DirectoryService(8) database.

en.wikipedia.org/wiki/Apple_Ope…
In #golang, implementation of user lookup in `os/user` pkg uses the native function `getpwnam_r` w/ cgo; but only parses `/etc/passwd` otherwise, except for lookups of current user which goes through syscall. Lookups return empty results for other users.

github.com/golang/go/issu…
To avoid cgo and still maintain robust and comprehensive offering, I had to shell out to `dscl` on macOS to obtain full user details (TODO: swap with `dscacheutil`) and parse /etc/passwd on other *nix platforms.
There's another area in caddy-ssh where I use `os/user.Lookup`, but for that I'll use the github.com/tweekmonster/l… module there because I don't need the user's shell in that area.

github.com/tweekmonster/l…
I left the PR open to simmer while I dwell a bit more on its implementation, tweak few more things, and do final touches while I close other life items. It was another wild ride through PTY and how avoiding C while interacting with the OS brings in unforeseen complexity.

#ssh

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Mohammed S. Al Sahaf

Mohammed S. Al Sahaf Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(