You are not logged in.

#1 2019-08-09 17:54:23

dawnofman
Member
Registered: 2019-07-26
Posts: 140

can't manage to escape variables in /etc/security/pam_env.conf

I am using pam_env to set many system-wide environment variables (regardless of the shell being used) like LS_COLORS for ls, etc; and, everything is working as expected except when I want to set a variable containing a backslash; eg:

colorWHATEVER DEFAULT="\e[1;37m"

Upon login:

echo $colorWHATEVER;

e[1;37m

The backslash is missing; so, without reading further I did:

colorWHATEVER DEFAULT="\\e[1;37m"

Upon login:

echo $colorWHATEVER;

e[1;37m

Same result: no backslash -not even without the double quotes.

The silly examples in /etc/security/pam_env.conf show that you can escape with the backslash and provides two examples: \$ for $ and \@ for @

Now, reading the man page for pam_env.conf:

(Possibly non-existent) environment variables may be used in values using the ${string} syntax and (possibly non-existent) PAM_ITEMs may be used in values using the @{string} syntax. Both the $ and @ characters can be backslash escaped to be used as literal values values can be delimited with "", escaped " not supported.

Which seems (convoluted) english to state that the only characters you can escape are $ and @ ... am I right ?

Last edited by dawnofman (2019-08-09 18:02:56)

Offline

#2 2019-08-09 21:01:38

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,494

Re: can't manage to escape variables in /etc/security/pam_env.conf

This probably has nothing to do w/ pam_env - try

colorWHATEVER="\\\e[1;37m"

or

colorWHATEVER='\\e[1;37m'

However I assume what you're trying to do won't work this way.

colorWHATEVER='\e[1;37m'

will be the correct export even if "echo $colorWHATEVER" doesn't reflect what you think it reflects.

Offline

#3 2019-08-10 03:01:08

dawnofman
Member
Registered: 2019-07-26
Posts: 140

Re: can't manage to escape variables in /etc/security/pam_env.conf

seth wrote:
colorWHATEVER="\\\e[1;37m"

same result: no backslah, no color:

echo "${colorWHATEVER}";
e[1;37m
printf "${colorWHATEVER}xxxxxx\n";
e[1;37mxxxxxx
seth wrote:
colorWHATEVER='\\e[1;37m'

same result: no backslah, no color:

echo "${colorWHATEVER}";
'e[1;37m'
printf "${colorWHATEVER}xxxxxx\n";
'e[1;37m'xxxxxx
seth wrote:
colorWHATEVER='\e[1;37m'

same result: no backslah, no color:

echo "${colorWHATEVER}";
'e[1;37m'
printf "${colorWHATEVER}xxxxxx\n";
'e[1;37m'xxxxxx

Offline

#4 2019-08-10 05:28:22

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,494

Re: can't manage to escape variables in /etc/security/pam_env.conf

I'd understand if the escaping variable doesn't work, but the other two should seriously print "\e[1;37m" - did you check whether the changes you made were applied at all to your test environment (eg. w/ a different color or exporting another, more trivial variable like "foo DEFAULT=bar")?

Offline

#5 2019-08-10 17:12:10

dawnofman
Member
Registered: 2019-07-26
Posts: 140

Re: can't manage to escape variables in /etc/security/pam_env.conf

seth wrote:

I'd understand if the escaping variable doesn't work, but the other two should seriously print "\e[1;37m" - did you check whether the changes you made were applied at all to your test environment (eg. w/ a different color or exporting another, more trivial variable like "foo DEFAULT=bar")?

whatever='abc'

printf "${whatever}\n";
'abc'

pam_env.conf doesn't treat single quotes like anything special, it seems it only looks for double quotes, and whether there are @ and/or $ escaped characters, everything else is disregarded.

Try it in your /etc/security/pam_env.conf with something inocuos, you don't have to modify the PAM stack, pam_env is loaded by default.

Offline

Board footer

Powered by FluxBB