Commit Graph

6734 Commits

Author SHA1 Message Date
Sami Kerola 0a2c1e8ed7 tools: generate autotools files if missing
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-09-10 12:57:31 +02:00
Sami Kerola bce5163b68 last: fix memory leak
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-09-10 12:57:31 +02:00
Karel Zak 646e159aa9 lib/strutils: optimalize {starts,ends}with()
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-10 12:18:20 +02:00
Karel Zak 9b5dc4cb8d su: fix lastlog and btmp logging
The su(1) logging code mix ups "old" and "new" passwd structs. The
result is things like

	Sep  9 11:50:45 x2 su: (to kzak) kzak on none

in /var/log/messages. The right log entry is

	Sep  9 11:50:45 x2 su: (to root) kzak on pts/3

The bug has been introduced by commit c74a7af17c.

References: https://bugzilla.redhat.com/show_bug.cgi?id=1005194
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-09 12:37:34 +02:00
Karel Zak 46568b002d agetty: cleanup debug ifdefs
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-09 09:15:40 +02:00
Karel Zak 2ea747ebf1 last: --fulltime and --time-format are mutually exclusive
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-02 11:42:44 +02:00
Karel Zak c87e4fbbf4 last: consolidate time formatting to one struct
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-02 11:28:43 +02:00
Karel Zak ee24e58f86 last: use bit array
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-02 11:11:38 +02:00
Sami Kerola 1342426248 tests: check last(1) and utmpdump(1) IPv6 functionality
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:10 +01:00
Sami Kerola ee508c153f utmpdump: make IPv6 addresses work
(unless bug[s]) This change is backwards compatibile.  Earlier binary to
text dumps can be converted back to binary, or otherway around.

The only thing that will not work are IPv6 addresses that possible
earlier conversion had broke.  Such conversions resulted with random IPv4
in place of IPv6 address in text format, and original information is gone
forever.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:10 +01: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 31d28e0951 last: tell verbally system is still running
Use of uptime time stamp as previous boot login time makes the output not
constant, which is rather difficult to test.  Verbal message 'system is
still running' makes testing easy, and noticing which boot is still
running clear to a person.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:10 +01:00
Sami Kerola 97bbb5e41c last: trim trailing white spaces
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:10 +01:00
Sami Kerola da051b5aaa tests: add last(1) test
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:09 +01:00
Sami Kerola 438269dca9 last: never restrict session time
When a session time will reach whopping 10000 days the last round bracket
is unnecessarily removed from output.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:09 +01:00
Sami Kerola 4440390ef0 docs: add --time-format to last(1) manual page
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:09 +01:00
Sami Kerola 45f11b6bf7 last: add --time-format with iso-8601 format
The ISO-8601 format makes consuming time stamps easy with various
parsers.  The format includes time zone information which is crucial when
an investigator is trying to make sense outputs collected from systems
all a across planet.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:09 +01:00
Sami Kerola 83484375f2 last: use configuration struct
This allows reducing global variables and will minimize number of
arguments for functions making code a little bit easier to read, and
maintain.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:09 +01:00
Sami Kerola 4e01db8842 last: fix --present option logic error
Printing of sessions 'still logged in' was skipped because an error in
logic.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:09 +01:00
Sami Kerola 36f5c80a40 docs: add --since and time option formats to last(1) manual
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:08 +01:00
Sami Kerola dd50168b91 last: add --since time spec option
The --since and --until options are companions often needed together.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:08 +01:00
Sami Kerola 75ab9bf1eb lib/time-util: move YYYYMMDDHHMMSS to common parser
Even while the YYYYMMDDHHMMSS time format it not magnificent it is best
to make it to be part of the one, and only, time format parser.

Proposed-by: Karel Zak <kzak@redhat.com>
References: http://markmail.org/message/6baqt4ttkopu7ra6
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:08 +01:00
Sami Kerola 3a4ae395a4 last: parse easy to use time formats
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:08 +01:00
Sami Kerola 199e939d88 lib/strutils: move *swith() functions to private library
Avoid code dublication in libmount and time-util.

Proposed-by: Karel Zak <kzak@redhat.com>
Reference: http://markmail.org/message/h7zexvqsieqngtmx
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:08 +01:00
Sami Kerola 2659a49ef0 lib/time-util: copy time parsing functions from systemd
The functions are copied nearly as-is.  Coding style has been modified to
match with util-linux project, while the functionality remains untouched.

CC: Lennart Poettering <lennart@poettering.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:08 +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 f7afb6b6b8 docs: add note to wall(1) about sessions which will not get message
Sessions that has in utmp data ut_line begining with ':' are skipped.
This is done to avoid write errors to devices such as '/dev/:0'.  For
example wdm is reported to to generate such utmp line.

Perhaps in future this code should be revalidated.  If an utmp data
contains broken device lines it might be best inform user with a error
message, rather than skipping silently suspicious device entries.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:07 +01:00
Sami Kerola 2af00c40a6 docs: add --present to last(1) manual page
I forgot to update manual after writing this functionality.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:07 +01:00
Sami Kerola 5721ea5753 wall: line wrap at column 79 also when line has tab chars
Earlier tabs caused random ragged right indentation, because the tab
length was assumed to be 1 char which is not the case most of the time.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:07 +01:00
Sami Kerola 1e6f6cdb84 mesg: sync usage() with howto-usage-function.txt
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:07 +01:00
Sami Kerola bbeae1cef1 wall: sync usage() with howto-usage-function.txt
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:07 +01:00
Sami Kerola 30faa20244 last: fix typo
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:06 +01:00
Sami Kerola cff0667f42 wall: send message also to sessions opened by user 'sleeper'
Ignoring an user by name, and not telling about it in manual page, is
unexpected.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:06 +01:00
Sami Kerola 918785dd1f build-sys: pylibmount will not work when python3 is present
While compiling with up to date Archlinux I notice the recently added
pylibmount does not link correctly.  Failures inform fundamental types
such as PyFileObject and PyFile_Type being missing.

It seems automake AM_PATH_PYTHON will prefer the python in path, which
for this distribution right now is python3.  As some sort of go-around
one can install older python, and symlink it to earlier in PATH lookup.

$ ln -s /usr/bin/python2 $HOME/bin/python
$ export PATH=$HOME/bin:$PATH

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:06 +01:00
Karel Zak fb4edda749 su: suppress PAM info messages for -c or non-login sessions
The 'Last login:' messages from PAM lastlogin module is unexpected
for non-login sessions or when -c <command> executed.

For example:

  $ su - -c id
  Last login: Wed Jul 24 08:36:28 CEST 2013 from dhcp-25-161.brq.redhat.com on pts/18
  uid=0(root) gid=0(root) skupiny=0(root)

this makes 'su' useless in scripts.

This patch suppress all PAM_TEXT_INFO messages for -c and for
non-login session ('-' is not specified) after pam_authenticate() and
pam_acct_mgmt().

Note that the new PAM conversation function checks the first message
in the msg[] array only. It seems good enough as PAM internally uses
pam_info() function that does not use multiple messages for one conv
call.

References: https://bugzilla.redhat.com/show_bug.cgi?id=987787
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-27 11:49:13 +02:00
Karel Zak 03d00d495f build-sys: add CFLAGS and LDFLAGS for daemons and shared libs
This is necessary for paranoid security guys who believe that things
like "-Wl,-z,relro" or "-Wl,-z,bind_now" is a way how to make the
world a safer place...

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-27 11:49:01 +02:00
Karel Zak ef2c9e3f5e tests: minor changes to make tests more portable
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-26 13:48:40 +02:00
Karel Zak 7bed68bf9e swapon: cleanup man page
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-23 13:02:18 +02:00
Rafael Aquini d6387c98cb swapon: allow a more flexible swap discard policy
Introduce the necessary changes to swapon(8) allowing a sysadmin to leverage
the new changes introduced to sys_swapon by "swap: discard while swapping
only if SWAP_FLAG_DISCARD_PAGES", therefore allowing a more flexible set of
choices when selection the discard policy for mounted swap areas.
This patch introduces the following optional arguments to the already
existent swapon(8) "--discard" option, in order to allow a discard type to
be selected at swapon time:
 * once    : only single-time area discards are issued. (swapon)
 * pages   : discard freed pages before they are reused.
If no policy is selected both discard types are enabled. (default)

[kzak@redhat.com: - support <policy> argument for short -d option too,
                  - add errx() on unsupported policy name]

Signed-off-by: Rafael Aquini <aquini@redhat.com>
Acked-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-23 12:50:39 +02:00
Karel Zak b86727542f last: mention optional arguments in usage
Reported-by: Bernhard Voelker <mail@bernhard-voelker.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-23 12:01:01 +02:00
Sami Kerola 37f534a667 last: add --present option
The --present option will allow user to easily determine who where logged
in at a given time.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-23 11:45:42 +02:00
Sami Kerola 7ec7822965 last: allow --file to be defined multiple times
This is useful when an admin is trying to find something, and has to
process all available data.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-23 11:31:34 +02:00
Sami Kerola 751947b6fc last: global variables are initialize automatically to zero
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-23 10:59:03 +02:00
Sami Kerola 328734c048 last: use as narrow variable scoping as possible
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-23 10:59:02 +02:00
Sami Kerola f65833b930 last: remove broken code
Comment in the deletion tells everything necessary.

"This doesn't work on modern systems, where only a DNS lookup of the
result from hostname() will get you the domainname.  Remember that
domainname() is the NIS domainname, not DNS.  So basically this whole
piece of code is bullshit."

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-23 10:59:00 +02:00
Sami Kerola e843d04753 last: prefer enum rather than #definition list
Incremental number lists are more hard to get wrong with enum, and they
are nicer to debug as for example gdb is aware of these symbolic names.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-23 10:58:59 +02:00
Sami Kerola 5cae90f9d1 last: make switch cases complete, and inform if impossible occurs
Some of the ut_type numbers does not seem to be recognized by last(1) so
they are, at least for now, silently ignored.  See glibc documentation
for information what the ignored EMPTY, INIT_PROCESS, LOGIN_PROCESS, and
ACCOUNTING mean.

Reference: FIXME
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-23 10:58:57 +02:00
Sami Kerola 1bd68aab3b last: check expected numeric user input is number
This commit also changes the line count to use unsigned integers, as
negative numbers in this context does not make sense.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-23 10:58:55 +02:00
Sami Kerola 2e58cd407e last: use carefulput() for printable character output
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-23 10:58:51 +02: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