From mad@madpilot.net  Tue May 15 16:21:33 2012
Return-Path: <mad@madpilot.net>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 71503106566B
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 15 May 2012 16:21:33 +0000 (UTC)
	(envelope-from mad@madpilot.net)
Received: from megatron.madpilot.net (megatron.madpilot.net [88.149.173.206])
	by mx1.freebsd.org (Postfix) with ESMTP id 0E4298FC0A
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 15 May 2012 16:21:33 +0000 (UTC)
Received: from megatron.madpilot.net (localhost [127.0.0.1])
	by megatron.madpilot.net (Postfix) with ESMTP id 3VsPD62GQXz2Yc
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 15 May 2012 18:21:26 +0200 (CEST)
Received: from megatron.madpilot.net ([127.0.0.1])
	by megatron.madpilot.net (megatron.madpilot.net [127.0.0.1]) (amavisd-new, port 10026)
	with ESMTP id ucuimw1KFlHr for <FreeBSD-gnats-submit@freebsd.org>;
	Tue, 15 May 2012 18:21:20 +0200 (CEST)
Received: by megatron.madpilot.net (Postfix, from userid 1000)
	id 3VsPD05sWNz2Yb; Tue, 15 May 2012 18:21:20 +0200 (CEST)
Message-Id: <3VsPD05sWNz2Yb@megatron.madpilot.net>
Date: Tue, 15 May 2012 18:21:20 +0200 (CEST)
From: Guido Falsi <madpilot@FreeBSD.org>
Reply-To: Guido Falsi <madpilot@FreeBSD.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] examples/csh/dot.cshrc SSH_AUTH_SOCK example incorrect
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         167932
>Category:       docs
>Synopsis:       [PATCH] examples/csh/dot.cshrc SSH_AUTH_SOCK example incorrect
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    eadler
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          doc-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue May 15 16:30:02 UTC 2012
>Closed-Date:    Tue Jun 05 05:17:11 UTC 2012
>Last-Modified:  Tue Jun 05 05:17:11 UTC 2012
>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:

From: Warren Block <wblock@wonkity.com>
To: Guido Falsi <madpilot@freebsd.org>
Cc: FreeBSD-gnats-submit@freebsd.org, freebsd-doc@freebsd.org
Subject: Re: docs/167932: [PATCH] examples/csh/dot.cshrc SSH_AUTH_SOCK example
 incorrect
Date: Tue, 15 May 2012 12:50:26 -0600 (MDT)

 On Tue, 15 May 2012, Guido Falsi wrote:
 
 > 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 }'`
 
 awk can do a little more to eliminate the second grep:
 
 setenv SSH_AUTH_SOCK `sockstat | grep "^${USER} " | awk '/ssh-agent/ { print $6 }'`
 
 The anchor before and space after the username in the grep are to make 
 it an exact match and not a subset ("jsm" versus "jsmith").  Although I 
 don't know what sockstat does with a username longer than eight 
 characters.
 
 > I know this is a minor glitch, but I thought it was worth reporting
 > anyway.
 
 It is.  Accuracy and precision are the goal.
Responsible-Changed-From-To: freebsd-doc->eadler 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Tue May 15 19:35:44 UTC 2012 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=167932 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: docs/167932: commit references a PR
Date: Tue, 15 May 2012 20:15:30 +0000 (UTC)

 Author: eadler
 Date: Tue May 15 20:15:17 2012
 New Revision: 235481
 URL: http://svn.freebsd.org/changeset/base/235481
 
 Log:
   Rework sample code which sets SSH_AUTH_SOCK to the user's ssh-agent
   socket path if running
   
   PR:		167932
   Submitted by:	madpilot (pr)
   Submitted by:	wblock (final patch)
   Reviewed by:	If someone else reviewed your modification.
   Approved by:	cperciva (implicit)
   MFC after:	3 days
 
 Modified:
   head/share/examples/csh/dot.cshrc
 
 Modified: head/share/examples/csh/dot.cshrc
 ==============================================================================
 --- head/share/examples/csh/dot.cshrc	Tue May 15 17:21:46 2012	(r235480)
 +++ head/share/examples/csh/dot.cshrc	Tue May 15 20:15:17 2012	(r235481)
 @@ -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} " | awk '/ssh-agent/ { print $6 }'`
  endif
  
  # Change only root's prompt
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: eadler 
State-Changed-When: Tue May 15 21:48:32 UTC 2012 
State-Changed-Why:  
committed in r235481 

http://www.freebsd.org/cgi/query-pr.cgi?pr=167932 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: docs/167932: commit references a PR
Date: Fri,  1 Jun 2012 06:40:19 +0000 (UTC)

 Author: eadler
 Date: Fri Jun  1 06:39:55 2012
 New Revision: 236382
 URL: http://svn.freebsd.org/changeset/base/236382
 
 Log:
   MFC r235481:
   	Rework sample code which sets SSH_AUTH_SOCK to the user's ssh-agent
   	socket path if running
   
   PR:		167932
   Approved by:	cperciva (implicit)
 
 Modified:
   stable/9/share/examples/csh/dot.cshrc
 Directory Properties:
   stable/9/share/examples/csh/   (props changed)
 
 Modified: stable/9/share/examples/csh/dot.cshrc
 ==============================================================================
 --- stable/9/share/examples/csh/dot.cshrc	Fri Jun  1 06:20:39 2012	(r236381)
 +++ stable/9/share/examples/csh/dot.cshrc	Fri Jun  1 06:39:55 2012	(r236382)
 @@ -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} " | awk '/ssh-agent/ { print $6 }'`
  endif
  
  # Change only root's prompt
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: docs/167932: commit references a PR
Date: Fri,  1 Jun 2012 06:40:41 +0000 (UTC)

 Author: eadler
 Date: Fri Jun  1 06:40:29 2012
 New Revision: 236383
 URL: http://svn.freebsd.org/changeset/base/236383
 
 Log:
   MFC r235481:
   	Rework sample code which sets SSH_AUTH_SOCK to the user's ssh-agent
   	socket path if running
   
   PR:		167932
   Approved by:	cperciva (implicit)
 
 Modified:
   stable/8/share/examples/csh/dot.cshrc
 Directory Properties:
   stable/8/share/examples/csh/   (props changed)
 
 Modified: stable/8/share/examples/csh/dot.cshrc
 ==============================================================================
 --- stable/8/share/examples/csh/dot.cshrc	Fri Jun  1 06:39:55 2012	(r236382)
 +++ stable/8/share/examples/csh/dot.cshrc	Fri Jun  1 06:40:29 2012	(r236383)
 @@ -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} " | awk '/ssh-agent/ { print $6 }'`
  endif
  
  # Change only root's prompt
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: docs/167932: commit references a PR
Date: Fri,  1 Jun 2012 06:41:08 +0000 (UTC)

 Author: eadler
 Date: Fri Jun  1 06:40:48 2012
 New Revision: 236384
 URL: http://svn.freebsd.org/changeset/base/236384
 
 Log:
   MFC r235481:
   	Rework sample code which sets SSH_AUTH_SOCK to the user's ssh-agent
   	socket path if running
   
   PR:		167932
   Approved by:	cperciva (implicit)
 
 Modified:
   stable/7/share/examples/csh/dot.cshrc
 Directory Properties:
   stable/7/share/examples/csh/   (props changed)
 
 Modified: stable/7/share/examples/csh/dot.cshrc
 ==============================================================================
 --- stable/7/share/examples/csh/dot.cshrc	Fri Jun  1 06:40:29 2012	(r236383)
 +++ stable/7/share/examples/csh/dot.cshrc	Fri Jun  1 06:40:48 2012	(r236384)
 @@ -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} " | awk '/ssh-agent/ { print $6 }'`
  endif
  
  # Change only root's prompt
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: eadler 
State-Changed-When: Tue Jun 5 05:17:10 UTC 2012 
State-Changed-Why:  
Committed. Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=167932 
>Unformatted:
