Bug 841

Summary: visudo could give a more precise error description
Product: Sudo Reporter: Marcel Partap <mpartap>
Component: VisudoAssignee: Todd C. Miller <Todd.Miller>
Status: RESOLVED FIXED    
Severity: enhancement CC: mavit+bugzilla.sudo.ws
Priority: low    
Version: 1.8.23   
Hardware: PC   
OS: Linux   

Description Marcel Partap 2018-07-15 05:31:57 MDT
">>> /etc/sudoers.d/pmbootstrap: syntax error near line 1 <<<" is not too helpful.
What exactly have I done wrong? Which subcheck triggers the error?
Comment 1 Todd C. Miller 2020-08-10 14:03:12 MDT
I committed changes last week to provide more information about where in the sudoers line the error is.  Currently, this will only show the location of the offending token in the line.  In the future I hope to have more descriptive error messages as well in the form of "expected foo but got bar".  It is a little more difficult to get that information out of the parser.
Comment 2 Todd C. Miller 2020-09-21 08:32:15 MDT
Sudo 1.9.3 produces more detailed syntax error messages.

Here’s a brief look at the syntax error message changes, given a sudoers file with two errors:
 
millert ALL = /fail : foo
root ALL = ALL foo
 
Sudo 1.9.2:
 
>>> sudoers: syntax error near line 1 <<<
>>> sudoers: syntax error near line 2 <<<
parse error in sudoers near line 1
 
Sudo 1.9.3:
 
sudoers:1: syntax error, unexpected '\n', expecting '=' or ','
millert ALL = /fail : foo
                         ^
sudoers:2: syntax error, unexpected WORD, expecting END or ':' or '\n'
root ALL = ALL foo
               ^~~
 
In the sudo 1.9.3 case, the first part of the privilege, “millert ALL = /fail” is still parsed.  Only the part after the ‘:’ with the error is discarded.
Comment 3 Marcel Partap 2020-09-24 09:47:27 MDT
That seems much better for figuring out problems, thanks for implementing this! : )
Comment 4 Peter Oliver 2020-11-01 14:23:39 MST
(In reply to Todd C. Miller from comment #1)
> I committed changes last week to provide more information about
> where in the sudoers line the error is.  Currently, this will only
> show the location of the offending token in the line.

Additionally, would it be possible to give the column number as a number?  I'd like to parse the output of visudo to highlight the error in my text editor, and this would make that easier.  For example:

sudoers:1:25: syntax error, unexpected '\n', expecting '=' or ','
millert ALL = /fail : foo
                         ^
sudoers:2:16: syntax error, unexpected WORD, expecting END or ':' or '\n'
root ALL = ALL foo
               ^~~
Comment 5 Todd C. Miller 2020-11-01 14:27:24 MST
Sure, the information is already available so this is just a matter of adjusting the warning message format.
Comment 6 Todd C. Miller 2020-11-06 19:51:19 MST
The following commits add the column number:
https://www.sudo.ws/repos/sudo/rev/0aea28dec8f2
https://www.sudo.ws/repos/sudo/rev/1c9d86b88517