Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 15 May 2012 18:21:20 +0200 (CEST)
From:      Guido Falsi <madpilot@FreeBSD.org>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   docs/167932: [PATCH] examples/csh/dot.cshrc SSH_AUTH_SOCK example incorrect
Message-ID:  <3VsPD05sWNz2Yb@megatron.madpilot.net>
Resent-Message-ID: <201205151630.q4FGU2ib038625@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         167932
>Category:       docs
>Synopsis:       [PATCH] examples/csh/dot.cshrc SSH_AUTH_SOCK example incorrect
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-doc
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          doc-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue May 15 16:30:02 UTC 2012
>Closed-Date:
>Last-Modified:
>Originator:     Guido Falsi
>Release:        FreeBSD 9.0-STABLE amd64
>Organization:
>Environment:
System: FreeBSD megatron.madpilot.net 9.0-STABLE FreeBSD 9.0-STABLE #5: Sun Apr 22 14:22:36 CEST 2012 root@megatron.madpilot.net:/usr/obj/usr/src/sys/MEGATRON amd64

>Description:

While experimenting with the .cshrc examples I discovered that the
sample for automatically setting SSH_AUTH_SOCK does not work as is.

It's easily tricked by other processes and cut seems to split on
every single space character, not grouping them.

I was using this revision of the file:

# $FreeBSD: stable/9/share/examples/csh/dot.cshrc 234978 2012-05-03 19:55:36Z eadler $

I tested a few possible solutions. I'm quite aware that none of
these is rock solid, but they do perform better than the sample
code in the file. I'm sure someone will come up with an even better
implementation.

It is my personal opinion that sample code should be as correctly
working as possible.

The simpliest and most legible (used in the attached patch):

setenv SSH_AUTH_SOCK `sockstat | grep "${USER}" | grep ssh-agent | awk '{ print $6 }'`

a slightly less legible one, but avoiding the double grep:

setenv SSH_AUTH_SOCK `sockstat | egrep "${USER}.*ssh-agent" | awk '{ print $6 }'`

and a simplier(but with horrible legibility) one relying only on sed:

setenv SSH_AUTH_SOCK `sockstat | sed -n "/${USER}.*ssh-agent/s/[^\/]*\(.*\)/\1/p"`

I know this is a minor glitch, but I thought it was worth reporting
anyway.

>How-To-Repeat:

Enable the sample code to populate SSH_AUTH_SOCK.
launch an ssh-agent on teh target machine.
Login via ssh.
Run "env" and notice that the SSH_AUTH_SOCK variable will be empty
even if there is an ssh-agent running.

>Fix:

--- dot.cshrc.orig	2012-05-15 18:03:10.053581560 +0200
+++ dot.cshrc	2012-05-15 18:11:25.903582833 +0200
@@ -5,7 +5,7 @@
 
 # Sets SSH_AUTH_SOCK to the user's ssh-agent socket path if running
 if (${?SSH_AUTH_SOCK} != "1") then
-	setenv SSH_AUTH_SOCK `sockstat | grep "${USER}" | cut -d ' ' -f 6` 
+	setenv SSH_AUTH_SOCK `sockstat | grep "${USER}" | grep ssh-agent | awk '{ print $6 }'`
 endif
 
 # Change only root's prompt
>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3VsPD05sWNz2Yb>