mcdope / pam_usb

Hardware authentication for Linux using ordinary flash media (USB & Card based).
GNU General Public License v2.0
190 stars 20 forks source link

Syntax error: "(" unexpected (when doing sudo) #180

Closed steelsnake closed 2 years ago

steelsnake commented 2 years ago

Hey there :) Nothing drastic, as the sudo command still works, but when running "sudo bash" under Konsole I get this error: sh 1: Syntax error: "(" unexpected

Full debug log ( the error is about halfway down after "trying to get tty by loginctl":

[05:24:53] jenni@wombat:~$ sudo bash
* Authentication request for user "jenni" (sudo)
[src/local.c:227] Checking whether the caller (sudo) is local or not...
[src/local.c:238]       Checking pid 187374 (sudo)...
[src/local.c:238]       Checking pid 187366 (/bin/bash)...
[src/local.c:238]       Checking pid 186946 (konsole)...
[src/local.c:238]       Checking pid      1 (/sbin/init)...
[src/local.c:296]       Using DISPLAY :0 for utmp search
[src/local.c:050]       No utmp entry found for tty ":0"
[src/local.c:312]       Trying to get tty from display server
[src/local.c:322]               Failed, no result while trying to get TTY from display server
[src/local.c:327]       Trying to get tty by DISPLAY
[src/local.c:335]               Failed, no result while searching utmp for display :0 owned by user jenni
[src/local.c:344]       Trying to get tty by loginctl
sh: 1: Syntax error: "(" unexpected
[src/local.c:214]               'loginctl' returned nothing.'
[src/local.c:355]               Failed, no result while searching utmp for tty (null)
[src/local.c:367]       Fallback: Using TTY /dev/pts/3 from ttyname() for search
[src/local.c:053]               utmp entry for tty "pts/3" found
[src/local.c:054]                       utmp->ut_pid: 187366
[src/local.c:055]                       utmp->ut_user: jenni
[src/local.c:071]               Checking utmp->ut_addr_v6[0]
[src/local.c:071]               Checking utmp->ut_addr_v6[1]
[src/local.c:071]               Checking utmp->ut_addr_v6[2]
[src/local.c:071]               Checking utmp->ut_addr_v6[3]
[src/local.c:075]       utmp check successful, request originates from a local source!
[src/local.c:374] No remote access detected, seems to be local request - allowing.
[src/device.c:038] Searching for "KeychainDrive" in the hardware database...
* Authentication device "KeychainDrive" is connected.
[src/device.c:100] One time pad is disabled, no more verifications to do.
* Access granted.
mcdope commented 2 years ago

Yeah, I've noticed that one too sometimes. Will check it.

Would be nice if you could lend me a hand and run this command and post its output here:

loginctl show-session $(awk '/tty/ {print $1}' <(loginctl)) -p TTY | tail -1 | awk -F= '{print $2}'

If this yields the same Syntax error (or empty) please try loginctl show-session $(awk '/tty/ {print $1}' <(loginctl)) -p TTY | tail -1. If you still get that error (or empty) please try loginctl show-session $(awk '/tty/ {print $1}' <(loginctl)) -p TTY. And if even that fails, please provide just the output of loginctl.

steelsnake commented 2 years ago

The command produces no output and no errors:

[17:05:37] jenni@wombat:~$ loginctl show-session $(awk '/tty/ {print $1}' <(loginctl)) -p TTY | tail -1 | awk -F= '{print $2}'
[17:06:07] jenni@wombat:~$ 

For reference, loginctl by itself produces this output when run from Konsole:

[17:06:07] jenni@wombat:~$ loginctl
SESSION  UID USER  SEAT  TTY
   1471 1000 jenni seat0 
   2101 1000 jenni seat0 
   2335 1000 jenni seat0 
   2457 1000 jenni seat0 
   2840 1000 jenni seat0 
      3 1000 jenni seat0 
    595 1000 jenni seat0 
    838 1000 jenni seat0 

8 sessions listed.

Edited to add: I just went ahead and ran those under sudo as well, same output

mcdope commented 2 years ago

Thanks. That explains why loginctl does not return a tty - it does not have it. Still wondering why that triggers the sh error...

mcdope commented 2 years ago

omg... why have i never tried this before... the clue lies in the first three chars - /bin/sh is used to execute the command and that command seems to have syntax not supported by sh ....

If that command is run in /bin/sh you get the same error. Will have to rework that command to be sh-compatible.

Edit: Note for future self: change cmd to

CMDTMP=`loginctl | awk '/tty/ {print $1}'`; loginctl show-session $CMDTMP -p TTY | tail -1 | awk -F= '{print $2}'
mcdope commented 2 years ago

@steelsnake Please try again after building from branch issue-180-fix-sh-error-on-loginctl-call / #182

Unsigned packages of that branch are available at https://www.dropbox.com/sh/qbqnkha5l93wu3o/AABgxe3hB7BFeXg9s0kgGwE2a?dl=0

steelsnake commented 2 years ago

The updated package indeed fixes the syntax error :)

mcdope commented 2 years ago

Thanks, gonna merge that PR after work then.