Commit Graph

91 Commits

Author SHA1 Message Date
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
Karel Zak 2260e493d6 su: add debug.h stuff
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak c34865b96d su: use switch() to split after fork
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak a4440cd1f1 su: move PAM session initialization to separate function
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 13de9b2194 su: rename evaluate_uid()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak e402d13746 su: cosmetic code changes
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 9303158534 su: cleanup setuid/gid related code
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 13396b1046 su: cleanup setenv related code
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 581ddd373a su: cleanup shell related code
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 94c6730bb9 su: cleanup usernames usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 032d759a10 su: cleanup pwd struct usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 302b7b65e4 su: consolidate tty name usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak dc5bfb71ff su: reorder functions
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak b9a92282e5 su: cleanup PAM stuff
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 42be9bda5b su: cleanup usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 832f5cd524 su: add control struct
* setup logindefs loader by function rather than by global pointer

* move basic booleans to the su_context struct

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak b1195aa07d su: cosmetic changes after indent
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 983652abc1 su: fix indention
Yes, I know... this patch is horrible. We all hate this in git
history, but the original indention from coreutils has been so
crazy...

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Ruediger Meier f45f3ec34a misc: consolidate macro style USAGE_HELP_OPTIONS
changed in include/c.h and applied via sed:

  sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c")
  sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c")

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 16:54:33 +02:00
Ruediger Meier b1a294c448 misc: introduce print_usage_help_options()
Consolidate --help and --version descriptions. We are
now able to align them to the other options.

We changed include/c.h. The rest of this patch was
generated by sed, plus manually setting the right
alignment numbers. We do not change anything but
white spaces in the --help output.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:26:19 +02:00
Ruediger Meier 5118d1be2a misc: never use usage(ERROR)
We are using better/shorter error messages and somtimes
also errtryhelp().

Here we fix all cases where the usage function took
an int argument for exit_code.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Sami Kerola b1557fe981 misc: fix ggc-7 fallthrough warnings
(Original patch and commit message edited by Rudi.)

gcc-7 adds -Wimplicit-fallthrough=3 to our default flag -Wextra.
This warning can be silenced by using comment /* fallthrough */
which is also recognized by other tools like coverity. There are
also other valid comments (see man gcc-7) but we consolidate this
style now.

We could have also used __attribute__((fallthrough)) but the comment
looks nice and does not need to be ifdef'ed for compatibility.

Reference: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=7652
Reference: https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/
Reviewed-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Suggested-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-06-14 11:48:22 +02:00
Sami Kerola 90936fafb4 su: remove duplicate const declaration
login-utils/su-common.c:619:14: warning: duplicate 'const' declaration
specifier [-Wduplicate-decl-specifier]
   const char const **args = xcalloc (n_args, sizeof *args);

Regression-from: 71f207a5f5
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-05-16 14:55:32 +02:00
Sami Kerola 71f207a5f5
sulogin: reduce vulnerability surface
Hopefully these changes are unreachable code, but better safe than sorry
when dealing with setuid root code that is installed everywhere.  Quite
obviously the introduced abort() calls protect from impossible inputs.

Secondly set all possible data to be read-only in attempt to make it more
difficult to alter anything at all.

Reference: https://www.securecoding.cert.org/confluence/display/c/DCL00-C.+Const-qualify+immutable+objects
Reviewed-by: Petr Vorel <petr.vorel@gmail.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-05-02 23:22:04 +01:00
Sami Kerola 8791804065 misc: do not use plain 0 as NULL [smatch scan]
text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer

Since many 'struct option' has used zero as NULL make them more readable in
same go by reindenting, and using named argument requirements.

Reference: https://lwn.net/Articles/93577/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Karel Zak dffab154d2 su: properly clear child PID
Reported-by: Tobias Stöckmann <tobias@stoeckmann.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-01 11:58:09 +01:00
Karel Zak 37410713b2 su, runuser: fix typo in the /etc/default path
Reported-by: Andreas Henriksson <andreas@fatal.se>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-20 11:02:23 +01:00
Karel Zak 281873b874 runuser: add "--" to SYNOPSIS
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-19 12:04:05 +01:00