<html><head></head><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div id="yui_3_16_0_1_1487987694228_11237">Hi,</div><div id="yui_3_16_0_1_1487987694228_11236"><br></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_11249">I found some errors and unexpected/confusing behaviour in pam_env.</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_11249"><br></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_11249"><br></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_11249">1)</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_11249"><br></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_11249">The user environment file is not parsed with the correct function, but it is parsed as a configuration file. This means that DEFAULT and OVERRIDE are recognized as special words and that parameter expansion is done.</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_11249"><br></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_11249">Please see pam_env.c at line 826.</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_11249"><br></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_11249">The parsing seems to work just because of unexpected behaviour #4 below (that is, also in config file the syntax "variable=value" is honored, even if because of an error.)</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_11249"><br></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_11249"><br></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_11249">2)</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_11249"><br></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_11249">From what I understand, setting DEFAULT= deletes a variable if OVERRIDE is empty or non-existing. But with some configuration combinations you get inconsistent behaviour:</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_11249"><br></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_11249">this_variable_is_removed</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_14556">this_one_is_removed_too DEFAULT=</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_14557">this_one_is_removed_as_well OVERRIDE="" DEFAULT=</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_14558">also_this_one_is_removed DEFAULT= OVERRIDE=</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_14559">but_this_one_is_added_as_empty_var OVERRIDE= DEFAULT=</div><div id="yui_3_16_0_1_1487987694228_17905"><br></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17906">This happens because in pam_env.c, in function _parse_line, variable quoteflg is not properly handled (more specifically, it is decremented even when it shouldn't).</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17907"><br></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17907"><br></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17907">3)<br></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17907"><br></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17907">I don't know if it is a bug or not, but it's most definitely unexpected.</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17907">If in the env file I write:</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17907"><br></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17907">export a=1</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17907"><br></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17907">it works. But:</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17907"><br></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17907">export  b=2   # note that there are two spaces</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17907">export    c=3 # note that there is a TAB character</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17907"><br></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17907">do not work. The parser in _parse_env_file (pam_env.c:220) does not handle anything different from a single space.</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17907"><br></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17907"><br></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28341">4)</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28342"><br id="yui_3_16_0_1_1487987694228_28343"></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28344">If in conf file I write:</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28345"><br id="yui_3_16_0_1_1487987694228_28346"></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28347">variable</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28348"># or<br id="yui_3_16_0_1_1487987694228_28349"></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28350">variable DEFAULT=<br id="yui_3_16_0_1_1487987694228_28351"></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28352"><br id="yui_3_16_0_1_1487987694228_28353"></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28354">the expected behaviour is to remove that variable from the environment. But the parser does not check for '=' signs, so if have this in the conf file (NOT in the env file):</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28355"><br id="yui_3_16_0_1_1487987694228_28356"></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28357">this_does_not_do_what_expected=yeah</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28358"># or even this:<br id="yui_3_16_0_1_1487987694228_28359"></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28360">neither_does_this=ohyeah!     DEFAULT=<br id="yui_3_16_0_1_1487987694228_28361"></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28362"><br id="yui_3_16_0_1_1487987694228_28363"></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28364">the module tries to remove the variable "this_does_not_do_what_expected=yeah" from the environment (as per debug log: remove variable "this_does_not_do_what_expected=yeah"), but it results in adding the variable "this_does_not_do_what_expected" instead, with value = "yeah".</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28364"><br></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28364">Note that this is the reason why the parsing of the user environment file seems to work.</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28365"><br id="yui_3_16_0_1_1487987694228_28366"></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28367"><br id="yui_3_16_0_1_1487987694228_28368"></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28369">5)</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28370"><br id="yui_3_16_0_1_1487987694228_28371"></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28372">The '#' char is recognized as comment even if it's not the first non-blank character in the line (differently from what written in the man page).</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28373">Especially, a conf line like this one:</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28374"><br id="yui_3_16_0_1_1487987694228_28375"></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28376">variable DEFAULT="a#b"</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28377"><br id="yui_3_16_0_1_1487987694228_28378"></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28379">does not work, it results in an error (Unterminated quoted string: "a). If not supported, this should be at least mentioned in the manual.</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28379">Note that the same problem is in the env file, because the line parsing function is the same (_assemble_line).</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28380"><br id="yui_3_16_0_1_1487987694228_28381"></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_28380"><br></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17923">6)</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17924"><br id="yui_3_16_0_1_1487987694228_17925"></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17924">pam_env.c:74:</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17966">/* This is a flag used to designate an empty string */</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17967">static char quote='Z';</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17968"><br id="yui_3_16_0_1_1487987694228_17969"></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17968">but in function check_var (row 511):</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_17968"><div dir="ltr" id="yui_3_16_0_1_1487987694228_18082">    if (&quote == var->defval) {</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_18083">      /*</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_18084">       * This means that the empty string was given for defval value</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_18085">       * which indicates that a variable should be defined with no value</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_18086">       */</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_18087">      *var->defval = '\0';</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_18088"><br id="yui_3_16_0_1_1487987694228_18089"></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_18088">as it can be seen, the last line changes the value of quote. This does not seem to have ill effects, but it is not nice because quote becomes = '\0', which has also a special meaning different from quote itself (quote means the empty quoted string, '\0' means the empty unquoted string).</div><div dir="ltr" id="yui_3_16_0_1_1487987694228_18088"><br></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_18088"><br></div><div dir="ltr" id="yui_3_16_0_1_1487987694228_18088"><div dir="ltr" style="margin-top: 0.1em; margin-bottom: 0.1em;" id="yui_3_16_0_1_1487987694228_18121">7)</div><div dir="ltr" style="margin-top: 0.1em; margin-bottom: 0.1em;" id="yui_3_16_0_1_1487987694228_18121"><br></div><div dir="ltr" style="margin-top: 0.1em; margin-bottom: 0.1em;" id="yui_3_16_0_1_1487987694228_18121">the "_parse_env_file" function in pam_env.c gets lines using function "_assemble_line", but then repeats a lot of the checks that have already been done (comments, empty lines, whitespaces at the beginning, ...)</div><div dir="ltr" style="margin-top: 0.1em; margin-bottom: 0.1em;" id="yui_3_16_0_1_1487987694228_18121"><br></div><div dir="ltr" style="margin-top: 0.1em; margin-bottom: 0.1em;" id="yui_3_16_0_1_1487987694228_18121"><br></div><div dir="ltr" style="margin-top: 0.1em; margin-bottom: 0.1em;" id="yui_3_16_0_1_1487987694228_18121">Regards</div></div></div></div></body></html>