delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/03/08/21:05:35

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SARE_FREE_WEBM_LAPOSTE
X-Spam-Check-By: sourceware.org
Message-ID: <4B95AD50.9010300@laposte.net>
Date: Tue, 09 Mar 2010 03:07:12 +0100
From: Cyrille Lefevre <cyrille DOT lefevre-lists AT laposte DOT net>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.3) Gecko/20070326 Thunderbird/2.0.0.0 Mnenhy/0.7.5.666
MIME-Version: 1.0
To: cygwin AT cygwin DOT com, Kurt-Franke AT web DOT de
Subject: Re: ssh + patch + $TMP
References: <1266525566 DOT 7752 DOT 1360709921 AT webmail DOT messagingengine DOT com> <loom DOT 20100219T220113-236 AT post DOT gmane DOT org> <4B806ACA DOT 2030409 AT laposte DOT net> <loom DOT 20100222T212522-331 AT post DOT gmane DOT org>, <4B92D7A1 DOT 7010603 AT laposte DOT net> <23881903 DOT 1595996 DOT 1268073848982 DOT JavaMail DOT fmail AT mwmweb034>
In-Reply-To: <23881903.1595996.1268073848982.JavaMail.fmail@mwmweb034>
X-me-spamlevel: not-spam
X-me-spamrating: 36.000000
X-me-spamcause: OK, (-100)(0000)gggruggvucftvghtrhhoucdtuddrvdeltddrheelucetggdotefuucfrrhhofhhilhgvmecuoehnohhnvgeqnecuuegrihhlohhuthemuceftddtnecutehnshifvghrucdlqddutddtmd
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

--------------070303090701020702030707
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable

Kurt Franke a =E9crit :
> -----Urspr=FCngliche Nachricht-----
> Von: Cyrille Lefevre <cyrille DOT lefevre-lists AT laposte DOT net>
> Gesendet: 06.03.2010 23:30:57
> An: cygwin AT cygwin DOT com,Kurt-Franke AT web DOT de
> Betreff: Re: ssh + patch + $TMP
>=20
>> the attached script only fork 5 processes (ps, grep, mount, find and=20
>> awk), and does not use any temporary files, so, it should not degrade=20
>> ssh logins performance.
>> existing environment variables are not overwritten.

<snip things I known for a long time, now, about 20 years of unix behind=20
me..., but you couldn't known that, so, don't care>

> thus you must write the environment settings build in awk script from reg=
istry to=20
> a file and source it at shell level after awk script has finished.

you are wrong here, no need for an output file to be sourced, you miss=20
the eval statement which interpret the output of the awk script within=20
the current shell. however, I've fixed a small bug here, it should be=20
eval "$(...)" and not eval $(...).

> and, of course, not all all existing environment variables should be pres=
erved.

as said before, only non existing variables are exported. however, I've=20
added an array (override) of environment variables to override.

> in the special those with bad values must get a correct value.

all windows variables are converted to cygwin ones using cygpath -u like=20
translation within awk. however, I've added an array (nocygpath) of=20
variables to not translate.

> for example TMP and TEMP have invalid values after a logon via sshd - the=
y are set
> to the value used by the user which is running the sshd and to the value =
of
> the actual user.

original TEMP variable :

TEMP=3D"/cygdrive/c/Users/CYG_SE~1/AppData/Local/Temp"

yours (wrong) :

TEMP=3D"/cygdrive/c/AppData/Local/Temp"

mine w/ override=3DTEMP :

TEMP=3D"/cygdrive/c/Users/Cyrille/AppData/Local/Temp"

also, you don't handle ComSpec, nor Path and windir upper case=20
conversion as cygwin does and the Path content isn't added to the=20
current PATH one as windows does (improved w/ no duplicates).

> if running with a windows version less 6.0 in a sshd session USERNAME and=
 USERDOMAIN
> have the values belonging to the SYSTEM user and not the values of the ac=
tual user.

did you setup cyglsa ?
what is the value of whoami from the "Windows XP Support Tools" ?
=3D> /cygdrive/c/program\ files/support\ tools/whoami
under Vista, it's /cygdrive/c/windows/system32/whoami

> may be some others have also invalid values.
> I think it is better to preserve a known list of variables and overwrite =
all others.

whatever you wanted, the idea was here and I just wanted to help you to=20
optimize your work.
anyway, I do it for fun, so, please, be more gentle next time and don't=20
fire someone else for whatever reason.

your script takes 15s while mine takes 1s only, so, learn about it.

Regards,

Cyrille Lefevre
--=20
mailto:Cyrille DOT Lefevre-lists AT laposte DOT net

--------------070303090701020702030707
Content-Type: text/plain;
 name="ssh-session-env.sh"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="ssh-session-env.sh"

#!/bin/sh
#
# ssh-session-env.sh - script for installation in /etc/profile.d
#
# because in sessions started from sshd the windows system environment
# variables in general are not set except for some which are possible
# special handled (like PATH, etc.) and the windows user environment
# variables are not set from the actual user but from the user of the
# sshd server this script is used to build this environment settings in
# shells with bournish syntax which uses /etc/profile for initialization.
#
# authors: Kurt Franke, Cyrille Lefevre
#
# date:   06 march 2010

if ps -fp ${PPID} | grep -q "/usr/sbin/sshd$"; then
	_SECONDS_=${SECONDS:-$(date +%s)}
	_IFS_=${IFS}
	IFS='
'
	eval "$(awk -v q="'" -v mp="$(mount --show-cygdrive-prefixes)" '
function s2a(str, a, sep,	i, t) {
	if (sep == "") sep = " +"
	split(str, t, sep)
	for (i in t) a[t[i]] = ""
}
function uniqp(p,	i, j, k, o, n, a, s) {
	k = split(p, o, ":")
	for (i = j = 1; i <= k; i++)
		if (!(tolower(o[i]) in a))
			a[tolower(n[j++] = o[i])] = ""
	p = s = ""
	for (i = 1; i < j; i++) {
		p = p s n[i]
		s = ":"
	}
	return p
}
BEGIN {
	s2a("APPDATA CLASSPATH QTJAVA LOCALAPPDATA USERPROFILE VS90COMNTOOLS", \
	    noconvert)
	s2a("HOMEPATH PATH TEMP TMP", override)
	sub(/.*\n/, "", mp)
	sub(/[ \t].*/, "", mp)
}
{
	var = FILENAME
	sub(".*/", "", var)
	var = toupper(var)
	sub("\0$", "")
	environ[var] = var == "PATH" && var in environ ? \
		environ[var] ";" $0 : $0
}
END {
	flag = 1
	while (flag) {
		flag = 0
		for (var in environ) {
			val = environ[var]
			if (match(val,/%[^%]+%/)) {
				flag = 1
				subvar = substr(val, RSTART+1, RLENGTH-2)
				subvar = toupper(subvar)
				subval = subvar in environ ? \
					environ[subvar] : ENVIRON[subvar]
				if (subval !~ /%[^%]%/) {
					head = substr(val, 1, RSTART-1)
					tail = substr(val, RSTART+RLENGTH)
					environ[var] = head subval tail
				}
			}
		}
	}
	for (var in environ) {
		if (!(var in override) && var in ENVIRON)
			continue
		val = environ[var]
		if (!(var in noconvert) && (val ~ /;/ || val ~ /^.:/)) {
			gsub(/([a-zA-Z]):/, mp "/&", val)
			gsub(/:/,"",val)
			gsub(/\\/,"/",val)
			gsub(/;/,":",val)
		}
		if (var == "PATH") val = uniqp(ENVIRON[var] ":" val)
		gsub(q, "\\"q, val)
		print "export", var "="q val q
	}
}
' /proc/registry/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Session\ Manager/Environment/* \
  /proc/registry/HKEY_CURRENT_USER/Environment/* \
  $(find /proc/registry/HKEY_CURRENT_USER/Volatile\ Environment -type f 2>/dev/null))"
	echo "elapsed: $(( ${SECONDS:-$(date +%s)} - $_SECONDS_ ))s"
	IFS=${_IFS_}
	unset _IFS_ _SECONDS_
fi

# eof


--------------070303090701020702030707
Content-Type: text/plain; charset=us-ascii

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
--------------070303090701020702030707--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019