On AlmaLinux subprocess.call(['/usr/bin/login']) gets hanged

I have a customized login button on Alma Linux VM, on pressing enter key it will call calls a python script, which internally call ‘/usr/bin/login’ command.

At below code, it gets stuck and login prompt is not seen.
subprocess.call([‘/usr/bin/login’])

I tried using… subprocess.call([''exec, ‘/usr/bin/login’]) in script it throws error…

Traceback (most recent call last):
File “/opt/test/scripts/./uag_login”, line 114, in
main()
File “//opt/test/scripts/./uag_login”, line 111, in main
curses.wrapper(login_screen)
File “/usr/lib64/python3.9/curses/init.py”, line 94, in wrapper
return func(stdscr, *args, **kwds)
File “/opt/test/scripts/./uag_login”, line 76, in login_screen
subprocess.call([‘exec’, ‘/usr/bin/login’])
File “/usr/lib64/python3.9/subprocess.py”, line 349, in call
with Popen(*popenargs, **kwargs) as p:
File “/usr/lib64/python3.9/subprocess.py”, line 951, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File “/usr/lib64/python3.9/subprocess.py”, line 1837, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: ‘exec’

Note : when i run ‘login’ or ‘exec login’ command manually it works, the issue is seen only when these commands are executed through python scripts.

I believe exec is typically a shell built-in, not an independent executable (or rather, it has to be, since it’s changing the very meaning of a command, from executing a subprocess to replacing the shell with the new program). So I’d be looking for an equivalent Python construct, that actually replaces the Python process rather than trying to create a subprocess.

Regardless, please exercise caution, as what you are doing sounds to me like it has a good possibility of creating some kind of security hole.

1 Like