Commit Graph

46 Commits

Author SHA1 Message Date
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
Sami Kerola cdf84bf658
write: fix potential string overflow
Noticed when compiled with gcc verion 9.2.1 20200130.

term-utils/write.c:182:7: warning: ‘strcmp’ argument 1 declared attribute
			  ‘nonstring’ [-Wstringop-overflow=]
  182 |   if (strcmp(u->ut_line, ctl->src_tty_name) == 0) {
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/utmpx.h:31,
                 from term-utils/write.c:60:
/usr/include/bits/utmpx.h:59:8: note: argument ‘ut_line’ declared here
   59 |   char ut_line[__UT_LINESIZE]
      |        ^~~~~~~

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-02-15 15:23:36 +00: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
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 9325dbfd20 misc: cleanup and fix --unknownopt issues
Fixed checkusage.sh warnings:

  rtcwake: --unknownopt, non-empty stdout

  rtcwake: --unknownopt, stderr too long: 21
  blockdev: --unknownopt, stderr too long: 28
  lsipc: --unknownopt, stderr too long: 77
  pg: --unknownopt, stderr too long: 23
  renice: --unknownopt, stderr too long: 18
  sulogin: --unknownopt, stderr too long: 17
  write: --unknownopt, stderr too long: 12

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Karel Zak 677ec86cef Use --help suggestion on invalid option
The current default is to print all usage() output. This is overkill
in many case.

Addresses: https://github.com/karelzak/util-linux/issues/338
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-19 13:13:34 +01:00
Ruediger Meier b4b919fe5e login-utils: switch to utmpx.h
Now the build will fail on many non-Linux systems because
utmpx.h is available everywhere but we still use non-POSIX
features. We'll fix this next commit.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-12-07 12:35:24 +01:00
Ruediger Meier a924b4004c login-utils: avoid using the defined utmp sizes.
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-12-07 12:35:24 +01:00
Karel Zak aefd6a9d6a write: don't use strftime()
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-07-14 13:20:58 +02:00
Sami Kerola 285c1f3a3e
lib: try to find tty in get_terminal_name()
Try all standard terminal input/output file descriptors when finding tty
name in get_germinal_name().  This should make all invocations of the
function as robust as they can get.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-03 23:35:10 +01:00
Sami Kerola a58b90255c
write: stop removing and adding /dev/ in front of tty string
Add both path and tty name representations of tty's to control structure,
that point to same string beginning from different depths.  This way there
is no need to removing and adding /dev/ in front of tty string all the time.

Secondly this change makes it possible to use of get_terminal_name() from
ttyutils.c.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-03 23:35:10 +01:00
Sami Kerola 50e417c8ad
write: tell when effective gid and tty path group mismatch
Most commonly this error happens when write(1) executable does not have
correct group ownership and setgid bit.  The earlier message was unclear
what exactly was wrong.

$ mesg
is y
$ write testuser
write: you have write permission turned off

Alternatively the 'getegid() == s.st_gid' could be considered unnecessary.
Afterall if to write to destination tty is denied that does not go unnoticed
at thet time when tty is opened.

Reviewed-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-03 23:35:09 +01:00
Sami Kerola 5592bf0d9a
write: improve coding style
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-03 23:35:09 +01:00
Sami Kerola a8031743ea
write: remove PUTC macro
Function like macros make following the execution flow unnecessarily
difficult, and deserves to be removed.

Requested-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-03 23:34:55 +01:00
Sami Kerola a079439266
write: make timestamp to be obviously just a clock time
By looking the code one will had hard time knowing that a slice of ctime()
from characters 11 to 16 is HH:MM time format.  Use of strftime("%H:%M")
makes this a lot less mysterious.

In same go make \007 hex printouts to be \a that is the same thing: alarm.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-01 22:07:02 +01:00
Sami Kerola c1d0a95eea
write: remove unnecessary utmp variables
glibc documentation tells getutent() calls are not thread safe, and
recommends to copy the context of the structures when information is wished
to be stored.  This leads to excessive copying, that in this case is not
relevant.  write(1) is single threaded program and there is no reason to
assume this would change in future.

Reference: http://www.gnu.org/software/libc/manual/html_node/Manipulating-the-Database.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-01 21:17:25 +01:00
Sami Kerola d732758e65
write: improve function and variable names
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-01 21:13:13 +01:00
Sami Kerola b5a6937961
write: add control structure to clarify what is going on
This is done purely an improve readability of the source code.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-01 21:08:53 +01:00
Sami Kerola 97ebab4ea8
write: run atexit() checks at the end of execution
Earlier use of _exit() caused program to terminate abnormally from atexit()
perspective and standard file descriptor close checks did not run resulting
to blindness if writes were successful, or not.  Easy fix is to avoid
running _exit() altogether.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-01 21:01:26 +01:00
Sami Kerola e4aaa0e593
write: use xstrncpy() from strutils.h
Earlier if the tty path was exactly length of the maximum ut_line then last
character of the path was overwrote by \0.  This is in practise theoretical
bug, as it is unheard that a tty device path could be 32 characters long.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-01 20:59:23 +01:00
Sami Kerola 489a0fd2f5
write: set atime value in term_chk() only when needed
The search_utmp() is needs atime but main() does not, so remove the later.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-01 20:54:02 +01:00
Sami Kerola 59f3d6ae12
write: remove pointless fileno(3) calls
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-01 20:51:47 +01:00
Sami Kerola b985f37240
write: get rid of function prototypes
Marking functions static and writing them in order where functions are
introduced before use is enough.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-01 20:51:47 +01:00
Sami Kerola 1baec22b08
write: remove unused variable
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-01 20:51:47 +01:00
Sebastian Rasmussen 9e93004171 misc: Fix various typos
Fix various typos in error messages, warnings, debug strings,
comments and names of static functions.

Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
2016-05-31 23:40:21 +02:00
Wayne Pollock 3e90d04af9
write: fix setuid related regression
The write(1) is commonly a setuid binary, because common users cannot by
default write to each others terminals.  Since the commit in reference, that
is part of releases v2.24 to v2.28, the write(1) has used access(2) to check
capability to write to a destination terminal.  The catch is that access(2)
uses real UID and GID to when performing the accessibility.  The obvious
correction is to avoid access(2) when in context of setuid binaries.

As a smaller fix, but equally important fix, ensure the 'msgsok' variable is
initialized to indicate no access.  Uninitialized variable will almost
certainly do wrong thing at the time of check.

Breaking-commit: 0233a8ea18
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Wayne Pollock <profwaynepollock@gmail.com>
2016-05-07 22:49:41 +01:00
Benno Schulenberg 451dbcfae1 textual: add a docstring to most of the utilities
This adds a concise description of a tool to its usage text.

A first form of this patch was proposed by Steven Honeyman
(see http://www.spinics.net/lists/util-linux-ng/msg09994.html).

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-01-06 11:27:38 +01:00
Sami Kerola db433bf737 textual: use usage() text element macros
Translating these text elements should happen only once, which is
more likely when the text macros are used properly.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-01 12:33:26 +02:00
Sami Kerola a587cc5520 textual: use manual tail usage() macro
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-01 12:33:24 +02:00
Sami Kerola f627750083 textual: use version printing macro everywhere
Only mount, umount, and blkid remains not using the macro because they
are print also library references.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-01 12:33:23 +02:00
Karel Zak 78a3b0af30 include/carefulputc: cleanup and add fputs_{quoted,nonblank}()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-03 12:29:16 +02:00
Sami Kerola cfa7fe890b last, utmpdump, agetty, wall, write: avoid compatibility hacks
In include/bits/utmp.h the ut_user and ut_time macros are marked with
comment they are backwards compatibility hacks.  It is probably best to
avoid use of these macros where ever possible.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:10 +01:00
Sami Kerola 0233a8ea18 write: change determination can user write to a terminal
Earlier test failed when user had write permission, but was not in
special group that owns terminal devices, usually tty.

This made write(1) to fail for root, if the root did not happen to be in
tty group.  In this commit root is granted ot write to anyone, even if
they have mesg(1) turned off.  For an user who is trying to write to own
other session the group write bit is significant only for whether mesg(1)
are enabled.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:07 +01:00
Sami Kerola ada6c48f06 include: carefulput: print determined char when unprintable char is found
This is done to allow reuse of the functin in last(1).

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-23 10:58:48 +02:00
Benno Schulenberg b50945d4ac textual: spell and encode the name of Arkadiusz Miśkiewicz correctly
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-02-06 11:15:02 +01:00
Karel Zak a0fc344b78 write: stop using MAXHOSTNAMELEN
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-10-19 16:27:58 +02:00
Thomas Schwinge 4658cfd492 write: Don't explicitly include <asm/param.h>.
It doesn't exist on some systems, but will come in via <sys/param.h> on the
others.

Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
2012-05-29 10:11:41 +02:00
Thomas Schwinge e78a7ecd4f write: Use PATH_MAX instead of MAXPATHLEN, as elsewhere.
Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
2012-05-29 10:11:37 +02:00
Sami Kerola cdd2a8c360 term-utils: verify writing to streams was successful
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-04-04 19:46:25 +02:00
Karel Zak b89fdd9c05 write: fix path for freopen()
Reported-by: xinglp <xinglp@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-09-06 03:18:46 +02:00
Karel Zak 4c27cd9089 write: cleanup usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-16 13:56:17 +02:00
Benno Schulenberg 1bf3e8a8eb write: remove inconsistent periods from two error messages
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2011-08-15 15:49:47 +02:00
Sami Kerola 5f51b8b25d write: maintenance fixes
Use libc error printing facilities, remove void casting, clean up
unused headers and alignt coding style with README.devel.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-06-25 14:25:40 +02:00
Sami Kerola aa44b95f12 write: long options & new usage
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-06-25 14:24:16 +02:00
Sami Kerola 4aa9d65bfa build-sys: move write to term-utils directory
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-06-25 13:54:31 +02:00