Mail Archives: cygwin/2010/03/08/21:05:35
--------------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 -