Commit Graph

118 Commits

Author SHA1 Message Date
Karel Zak 17d5b26436 su: (pty) change owner and mode for pty
The current situation:

 # su --pty - kzak
 $ ll $(tty)
 crw--w---- 1 root tty 136, 9 Feb 23 11:53 /dev/pts/9
 $ mesg
 mesg: cannot open /dev/pts/9: Permission denied

the pseudo-terminal is still owned by the original user.

New version:

 # su --pty - kzak
 # ll $(tty)
 crw--w---- 1 kzak tty 136, 9 Feb 23 11:56 /dev/pts/9
 # mesg
 is y

The patch follows login(1) to change the pty owner and group. It
follows "TTYPERM" and "TTYGROUP" from login.defs (or econf lib).

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-02-23 11:52:45 +01:00
Karel Zak 497c61f7b0 su: explicitly enable echo for --pty
Since 75ccd75a2f we need to explicitly
set echo flag by ul_pty_slave_echo(pty, 1).

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-02-23 11:37:15 +01:00
Karel Zak 6165376737 su: use full tty path for PAM_TTY
pam_set_item() man page:
 PAM_TTY
   The terminal name: prefixed by /dev/ if it is a device file;
   for graphical, X-based, applications the value for this item
   should be the $DISPLAY variable.

It seems for example pam_timestamp module is not robust enough to
differentiate between /dev/ and pty/0 and it assumes that '/' in the
path always means '/dev/' prefix ...

Fixes: https://github.com/karelzak/util-linux/issues/1242
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-02-03 14:45:15 +01:00
Karel Zak 1e89f4fe18 su: remove useless assignment
Address: https://github.com/karelzak/util-linux/issues/1145
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-23 16:54:34 +02:00
Karel Zak d5e8818e03 Merge branch 'libeconf' of https://github.com/thkukuk/util-linux
* 'libeconf' of https://github.com/thkukuk/util-linux:
  Adjust test output to pass test suite
  Add support for libeconf
2020-05-25 12:23:13 +02:00
Rosen Penev ad296391f9
[clang-tidy] fix wrong *cmp usage
Found with bugprone-suspicious-string-compare

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-20 13:21:00 -07:00
Jouke Witteveen 1c788737d7 su: silence a useless warning
When the requested shell matches the restricted shell, there is no reason
to issue a warning, since we will be doing precisely as requested.

Signed-off-by: Jouke Witteveen <j.witteveen@gmail.com>
2019-12-06 12:40:55 +01:00
Karel Zak bdc3cc65ab su: fix error message
Reported-by: Pedro Albuquerque <palbuquerque73@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-29 10:04:29 +01:00
Karel Zak bdd4335706 lib/pty-session: make wait_child callback optional
Now the code is duplicate on many places, but all we usually need is to
remember child status. It seems good enough to have very simple
callback child_die() to inform application about a change.

The patch also add PID to all signal related callbacks.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-08 13:11:54 +02:00
Karel Zak 46737a7332 su: (pty) remove unnecessary call
The pty code has to save the original signal mask without application
assistance.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-08 13:11:54 +02:00
Karel Zak b923bdbe52 su: use lib/pty-session.c code for --pty
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-08 13:11:54 +02:00
Thorsten Kukuk 9e584ff324 Add support for libeconf 2019-09-03 15:04:43 +02:00
Jakub Hrozek 9a1a982206 su: More descriptive error message on malformed user entry
With users coming from LDAP, it is often the case that the entry in LDAP
does not contain one or more attributes required by su or, because of
misconfigured access control rights, the attribute might not be readable
by the LDAP client. In that case, su just tells the user that the user
does not exist.

It might be more user-friendly to tell the user to check the user entry
for all required fields.
2019-05-31 13:23:57 +02:00
Karel Zak 00749b05b9 su: make comment more friedly to 'make checkxalloc'
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-24 12:45:20 +02:00
Karel Zak 2c308875a7 misc: consolidate version printing and close_stdout()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-16 15:14:13 +02:00
Karel Zak 99c1ebee21 su: change error message
We use PAM and if pam_strerror() returns nothing we have no clue why
authentication failed. It's mistake to blame incorrect password if
there are many possible reason...

Addresses: https://github.com/karelzak/util-linux/issues/778
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-03-25 16:39:43 +01:00
Karel Zak 5932ef81de su: be sensitive to another SIGCHLD ssi_codes
See the same issue for script: 27afe50168

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-03-06 12:02:30 +01:00
Karel Zak 282ca3d87b su: fix --pty terminal initialization
* use proper winsize rather than uninitialized variable (Oops...)

* set the current terminal to the raw mode

* disable ECHO for non-terminal execution to be compatible with
  non-pty output

Addresses: https://github.com/karelzak/util-linux/issues/767
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-03-06 12:01:18 +01:00
Stanislav Brabec 86f42e5a2a su-common.c: prefer ENV_SUPATH over ENV_ROOTPATH
ENV_SUPATH and ENV_ROOTPATH are equivalent and ENV_ROOTPATH takes
precedence in both login and su. It makes no sense. More logical would be
precedence of ENV_SUPATH in su and ENV_ROOTPATH in login.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2019-01-10 12:26:38 +01:00
Stanislav Brabec 15a191f6d3 su-common.c: prefer /etc/default/su over login.defs
su(1) documentation says:
       /etc/default/su  command specific logindef config file
       /etc/login.defs  global logindef config file

It indirectly indicates that /etc/default/su should take precedence
over /etc/login.defs.

But the reverse is true. It is not possible to define ENV_PATH in
/etc/login.defs and then make su specific customization in
/etc/default/su. We need to change read order to match the documented
behavior.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2019-01-10 12:26:38 +01:00
Karel Zak 7f76bc8a75 su: cleanup code to copy to log strings
man utmp:
  String fields are terminated by a null byte ('\0') if they are shorter
  than the size of the field.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-10-03 17:10:13 +02:00
Karel Zak 75efef98d4 su: add --whitelist-environment
* usable with --login to whitelist specified environment variables

* the list is ignored for the core variables like HOME, SHELL, USER,
  LOGNAME and PATH (su --login always resets these variables)

Note that su(1) requires password and after successful authentication
user has full control over the session, so he can set arbitrary
environment variables. The whitelist makes things more user friendly
only.

The patch removes unnecessary optimization when allocate environ[]. It
seems better to keep all in glibc hands and just reset the environment
array only.

Addresses: https://github.com/karelzak/util-linux/issues/221
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-15 13:03:21 +02:00
Ruediger Meier 73afd3f8e8 misc: fix typos using codespell
Some more funny typos, please review carefully.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-02-16 11:12:52 +01:00
Samuel Thibault 4365c8107f su: build fix for the case where USE_PTY is not defined
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-12 12:09:40 +01:00
Karel Zak 3c29b695dd su: use errexec()
The new macro is fully compatible with original (coreutils) code.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-01 15:37:22 +01:00
Karel Zak a15dca2f6d include/debug: introduce __UL_INIT_DEBUG_FROM_STRING()
Let's make it possible to use debug.h without environment variables.

Suggested-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-17 13:58:29 +01:00
Karel Zak f4b03edb73 login-utils: use free_getlogindefs_data()
It seems better to deallocate logindefs.conf stuff in long time
running (=waiting) processes like login(1) and su(1).

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-28 14:49:05 +01:00
Sami Kerola fcf841f8d3 misc: fix typos
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-28 14:39:13 +01:00
Karel Zak e9fde3e900 su: (pty) improve SIGSTOP/SIGCONT semantic
We want to use waitpid() only when child is terminated or stopped to
pick up child status, otherwise PTY proxy has to be active. This is
difference between "su" and "su --pty". For "su" we keep parent all
time in waitpid().

It would be possible to use separate code based on signalfd_siginfo,
but it seems better to keep all this stuff on one place -- it  means
wait_for_child().

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:49:11 +02:00
Karel Zak 13ee2f4d78 su: (pty) save child status
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:49:11 +02:00
Karel Zak 5328d8e7e8 su: (pty) simplify stdin usage in poll()
Not sure why I have problem with this years ago for script(1), but it
seems .fd=-1 is really enough to the ignore the FD.

Reported-by: Vaclav Dolezal <vdolezal@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:49:11 +02:00
Karel Zak 61b3106ba3 su: (pty) fix slave terminal attributes initialization
Reported-by: Vaclav Dolezal <vdolezal@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:49:11 +02:00
Karel Zak 0214f438a6 su: (pty) fix child signal mask usage
The signal mask is used by pty_init_slave(), but it has never been
uninitialized before fork(), so child gets 0 as a mask :-(

Note that script(1) has no this issue because it opens signal-fd
before fork().

Reported-by: Vaclav Dolezal <vdolezal@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:49:11 +02:00
Karel Zak ae6e2537ff su: fix non-pty compilation
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:49:11 +02:00
Karel Zak 927ded6be6 su: enable TIOCSCTTY and minor changes
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:49:11 +02:00
Karel Zak eb7d0ad0fe su: add PTY support
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:49:11 +02:00
Karel Zak 04845ec766 su: add --pty option
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:49:11 +02:00
Karel Zak 305ef556d6 su: move parent signals setup to separate function
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:49:11 +02:00
Karel Zak b55e712816 su: make wait_for_child() usable in arbitrary situation
For example if called more than once; to keep PTY code simple and
robust.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:49:11 +02:00
Karel Zak 665f36bed9 su: keep old sigactions in control struct
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:49:11 +02:00
Karel Zak f6e8b23658 su: fix refactoring bug in child PID usage
Fix child pid cleanup according to commit 0076012563ff34e294a6166d605118bcdd35f7e1.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 44f36ad1ed su: add child to control struct
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak e192de658b su: fix compiler warnings [-Wimplicit-fallthrough=]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak b09e7ea851 su: add wait_for_child()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 8ce9c38690 su: unblock signals is all initialized
This patch a little bit reorders signals initialization. The original
code unblocks SIGINT SIGQUIT before signal handler is set for the
signals. It means there is a small possible race.

It seems better to compose wanted mask, setup handlers and then
unblock all the wanted signals.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 5fc211d217 su: clean up signals usage
- don't use magic numbers to index old actions
- don't use if () if ()
- make if() conditions more readable

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak feab56878a su: clean up const usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak e19db0449e su: fix debug message
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 6b28328255 su: properly clear child PID
The patch from master branch, somehow lost during su refactoring
rebase.

Reported-by: Tobias Stöckmann <tobias@stoeckmann.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 242708de5b su: improve some debug messages
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00