summaryrefslogtreecommitdiffstats
path: root/login-utils
diff options
context:
space:
mode:
authorRuediger Meier2016-12-01 09:52:11 +0100
committerKarel Zak2016-12-07 12:35:24 +0100
commitb4b919fe5e1fc1d346fa6315748d0e0709d02096 (patch)
treee5eba9e27c382d608ab4c93edc1892d88d84e876 /login-utils
parentagetty: remove obsolete HAVE_UPDWTMP fallback (diff)
downloadkernel-qcow2-util-linux-b4b919fe5e1fc1d346fa6315748d0e0709d02096.tar.gz
kernel-qcow2-util-linux-b4b919fe5e1fc1d346fa6315748d0e0709d02096.tar.xz
kernel-qcow2-util-linux-b4b919fe5e1fc1d346fa6315748d0e0709d02096.zip
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>
Diffstat (limited to 'login-utils')
-rw-r--r--login-utils/last.c32
-rw-r--r--login-utils/login.c30
-rw-r--r--login-utils/lslogins.c26
-rw-r--r--login-utils/su-common.c6
-rw-r--r--login-utils/utmpdump.c10
5 files changed, 53 insertions, 51 deletions
diff --git a/login-utils/last.c b/login-utils/last.c
index da7ed36c8..75eff5b94 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -30,7 +30,7 @@
#include <time.h>
#include <stdio.h>
#include <ctype.h>
-#include <utmp.h>
+#include <utmpx.h>
#include <pwd.h>
#include <stdlib.h>
#include <unistd.h>
@@ -94,7 +94,7 @@ struct last_control {
/* Double linked list of struct utmp's */
struct utmplist {
- struct utmp ut;
+ struct utmpx ut;
struct utmplist *next;
struct utmplist *prev;
};
@@ -173,7 +173,7 @@ static int which_time_format(const char *s)
* Read one utmp entry, return in new format.
* Automatically reposition file pointer.
*/
-static int uread(FILE *fp, struct utmp *u, int *quit, const char *filename)
+static int uread(FILE *fp, struct utmpx *u, int *quit, const char *filename)
{
static int utsize;
static char buf[UCHUNKSIZE];
@@ -186,14 +186,14 @@ static int uread(FILE *fp, struct utmp *u, int *quit, const char *filename)
/*
* Normal read.
*/
- return fread(u, sizeof(struct utmp), 1, fp);
+ return fread(u, sizeof(struct utmpx), 1, fp);
}
if (u == NULL) {
/*
* Initialize and position.
*/
- utsize = sizeof(struct utmp);
+ utsize = sizeof(struct utmpx);
fseeko(fp, 0, SEEK_END);
fpos = ftello(fp);
if (fpos == 0)
@@ -217,7 +217,7 @@ static int uread(FILE *fp, struct utmp *u, int *quit, const char *filename)
*/
bpos -= utsize;
if (bpos >= 0) {
- memcpy(u, buf + bpos, sizeof(struct utmp));
+ memcpy(u, buf + bpos, sizeof(struct utmpx));
return 1;
}
@@ -253,7 +253,7 @@ static int uread(FILE *fp, struct utmp *u, int *quit, const char *filename)
memcpy(tmp, buf + UCHUNKSIZE + bpos, -bpos);
bpos += UCHUNKSIZE;
- memcpy(u, tmp, sizeof(struct utmp));
+ memcpy(u, tmp, sizeof(struct utmpx));
return 1;
}
@@ -376,7 +376,7 @@ static void trim_trailing_spaces(char *s)
/*
* Show one line of information on screen
*/
-static int list(const struct last_control *ctl, struct utmp *p, time_t logout_time, int what)
+static int list(const struct last_control *ctl, struct utmpx *p, time_t logout_time, int what)
{
time_t secs, utmp_time;
char logintime[LAST_TIMESTAMP_LEN];
@@ -592,7 +592,7 @@ static void __attribute__((__noreturn__)) usage(const struct last_control *ctl,
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
-static int is_phantom(const struct last_control *ctl, struct utmp *ut)
+static int is_phantom(const struct last_control *ctl, struct utmpx *ut)
{
struct passwd *pw;
char path[32];
@@ -632,7 +632,7 @@ static void process_wtmp_file(const struct last_control *ctl,
{
FILE *fp; /* File pointer of wtmp file */
- struct utmp ut; /* Current utmp entry */
+ struct utmpx ut; /* Current utmp entry */
struct utmplist *ulist = NULL; /* All entries */
struct utmplist *p; /* Pointer into utmplist */
struct utmplist *next; /* Pointer into utmplist */
@@ -837,7 +837,7 @@ static void process_wtmp_file(const struct last_control *ctl,
if (ut.ut_line[0] == 0)
break;
p = xmalloc(sizeof(struct utmplist));
- memcpy(&p->ut, &ut, sizeof(struct utmp));
+ memcpy(&p->ut, &ut, sizeof(struct utmpx));
p->next = ulist;
p->prev = NULL;
if (ulist)
@@ -848,7 +848,9 @@ static void process_wtmp_file(const struct last_control *ctl,
case EMPTY:
case INIT_PROCESS:
case LOGIN_PROCESS:
+#ifdef ACCOUNTING
case ACCOUNTING:
+#endif
/* ignored ut_types */
break;
@@ -987,10 +989,10 @@ int main(int argc, char **argv)
ctl.until = (time_t) (p / 1000000);
break;
case 'w':
- if (ctl.name_len < sizeof(((struct utmp *) 0)->ut_user))
- ctl.name_len = sizeof(((struct utmp *) 0)->ut_user);
- if (ctl.domain_len < sizeof(((struct utmp *) 0)->ut_host))
- ctl.domain_len = sizeof(((struct utmp *) 0)->ut_host);
+ if (ctl.name_len < sizeof(((struct utmpx *) 0)->ut_user))
+ ctl.name_len = sizeof(((struct utmpx *) 0)->ut_user);
+ if (ctl.domain_len < sizeof(((struct utmpx *) 0)->ut_host))
+ ctl.domain_len = sizeof(((struct utmpx *) 0)->ut_host);
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
diff --git a/login-utils/login.c b/login-utils/login.c
index 343044865..37553ef0a 100644
--- a/login-utils/login.c
+++ b/login-utils/login.c
@@ -45,7 +45,7 @@
#include <errno.h>
#include <grp.h>
#include <pwd.h>
-#include <utmp.h>
+#include <utmpx.h>
#ifdef HAVE_LASTLOG_H
# include <lastlog.h>
#endif
@@ -428,7 +428,7 @@ static void init_tty(struct login_context *cxt)
*/
static void log_btmp(struct login_context *cxt)
{
- struct utmp ut;
+ struct utmpx ut;
struct timeval tv;
memset(&ut, 0, sizeof(ut));
@@ -456,7 +456,7 @@ static void log_btmp(struct login_context *cxt)
sizeof(ut.ut_addr_v6));
}
- updwtmp(_PATH_BTMP, &ut);
+ updwtmpx(_PATH_BTMP, &ut);
}
@@ -555,12 +555,12 @@ done:
*/
static void log_utmp(struct login_context *cxt)
{
- struct utmp ut;
- struct utmp *utp;
+ struct utmpx ut;
+ struct utmpx *utp;
struct timeval tv;
- utmpname(_PATH_UTMP);
- setutent();
+ utmpxname(_PATH_UTMP);
+ setutxent();
/* Find pid in utmp.
*
@@ -570,7 +570,7 @@ static void log_utmp(struct login_context *cxt)
* but some number calculated from the previous and current runlevel.)
* -- Michael Riepe <michael@stud.uni-hannover.de>
*/
- while ((utp = getutent()))
+ while ((utp = getutxent()))
if (utp->ut_pid == cxt->pid
&& utp->ut_type >= INIT_PROCESS
&& utp->ut_type <= DEAD_PROCESS)
@@ -579,19 +579,19 @@ static void log_utmp(struct login_context *cxt)
/* If we can't find a pre-existing entry by pid, try by line.
* BSD network daemons may rely on this. */
if (utp == NULL && cxt->tty_name) {
- setutent();
+ setutxent();
ut.ut_type = LOGIN_PROCESS;
strncpy(ut.ut_line, cxt->tty_name, sizeof(ut.ut_line));
- utp = getutline(&ut);
+ utp = getutxline(&ut);
}
/* If we can't find a pre-existing entry by pid and line, try it by id.
* Very stupid telnetd daemons don't set up utmp at all. (kzak) */
if (utp == NULL && cxt->tty_number) {
- setutent();
+ setutxent();
ut.ut_type = DEAD_PROCESS;
strncpy(ut.ut_id, cxt->tty_number, sizeof(ut.ut_id));
- utp = getutid(&ut);
+ utp = getutxid(&ut);
}
if (utp)
@@ -619,10 +619,10 @@ static void log_utmp(struct login_context *cxt)
sizeof(ut.ut_addr_v6));
}
- pututline(&ut);
- endutent();
+ pututxline(&ut);
+ endutxent();
- updwtmp(_PATH_WTMP, &ut);
+ updwtmpx(_PATH_WTMP, &ut);
}
static void log_syslog(struct login_context *cxt)
diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c
index 410987646..a08db6252 100644
--- a/login-utils/lslogins.c
+++ b/login-utils/lslogins.c
@@ -31,7 +31,7 @@
#include <shadow.h>
#include <paths.h>
#include <time.h>
-#include <utmp.h>
+#include <utmpx.h>
#include <signal.h>
#include <err.h>
#include <limits.h>
@@ -243,10 +243,10 @@ static const struct lslogins_coldesc coldescs[] =
};
struct lslogins_control {
- struct utmp *wtmp;
+ struct utmpx *wtmp;
size_t wtmp_size;
- struct utmp *btmp;
+ struct utmpx *btmp;
size_t btmp_size;
void *usertree;
@@ -410,7 +410,7 @@ again:
return res;
}
-static struct utmp *get_last_wtmp(struct lslogins_control *ctl, const char *username)
+static struct utmpx *get_last_wtmp(struct lslogins_control *ctl, const char *username)
{
size_t n = 0;
@@ -445,7 +445,7 @@ static int require_btmp(void)
return 0;
}
-static struct utmp *get_last_btmp(struct lslogins_control *ctl, const char *username)
+static struct utmpx *get_last_btmp(struct lslogins_control *ctl, const char *username)
{
size_t n = 0;
@@ -462,21 +462,21 @@ static struct utmp *get_last_btmp(struct lslogins_control *ctl, const char *user
}
-static int read_utmp(char const *file, size_t *nents, struct utmp **res)
+static int read_utmp(char const *file, size_t *nents, struct utmpx **res)
{
size_t n_read = 0, n_alloc = 0;
- struct utmp *utmp = NULL, *u;
+ struct utmpx *utmp = NULL, *u;
- if (utmpname(file) < 0)
+ if (utmpxname(file) < 0)
return -errno;
- setutent();
+ setutxent();
errno = 0;
- while ((u = getutent()) != NULL) {
+ while ((u = getutxent()) != NULL) {
if (n_read == n_alloc) {
n_alloc += 32;
- utmp = xrealloc(utmp, n_alloc * sizeof (struct utmp));
+ utmp = xrealloc(utmp, n_alloc * sizeof (struct utmpx));
}
utmp[n_read++] = *u;
}
@@ -485,7 +485,7 @@ static int read_utmp(char const *file, size_t *nents, struct utmp **res)
return -errno;
}
- endutent();
+ endutxent();
*nents = n_read;
*res = utmp;
@@ -578,7 +578,7 @@ static struct lslogins_user *get_user_info(struct lslogins_control *ctl, const c
struct passwd *pwd;
struct group *grp;
struct spwd *shadow;
- struct utmp *user_wtmp = NULL, *user_btmp = NULL;
+ struct utmpx *user_wtmp = NULL, *user_btmp = NULL;
int n = 0;
time_t time;
uid_t uid;
diff --git a/login-utils/su-common.c b/login-utils/su-common.c
index c48d9510e..0928a2b1a 100644
--- a/login-utils/su-common.c
+++ b/login-utils/su-common.c
@@ -58,7 +58,7 @@ enum
#include <signal.h>
#include <sys/wait.h>
#include <syslog.h>
-#include <utmp.h>
+#include <utmpx.h>
#include "err.h"
@@ -182,7 +182,7 @@ log_syslog(struct passwd const *pw, bool successful)
*/
static void log_btmp(struct passwd const *pw)
{
- struct utmp ut;
+ struct utmpx ut;
struct timeval tv;
const char *tty_name, *tty_num;
@@ -204,7 +204,7 @@ static void log_btmp(struct passwd const *pw)
ut.ut_type = LOGIN_PROCESS; /* XXX doesn't matter */
ut.ut_pid = getpid();
- updwtmp(_PATH_BTMP, &ut);
+ updwtmpx(_PATH_BTMP, &ut);
}
diff --git a/login-utils/utmpdump.c b/login-utils/utmpdump.c
index 4a85afa7d..fd90b5e10 100644
--- a/login-utils/utmpdump.c
+++ b/login-utils/utmpdump.c
@@ -28,7 +28,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <utmp.h>
+#include <utmpx.h>
#include <time.h>
#include <ctype.h>
#include <getopt.h>
@@ -87,7 +87,7 @@ static void xcleanse(char *s, int len)
*s = '?';
}
-static void print_utline(struct utmp *ut, FILE *out)
+static void print_utline(struct utmpx *ut, FILE *out)
{
const char *addr_string;
char buffer[INET6_ADDRSTRLEN];
@@ -129,7 +129,7 @@ static void roll_file(const char *filename, off_t *size, FILE *out)
{
FILE *in;
struct stat st;
- struct utmp ut;
+ struct utmpx ut;
off_t pos;
if (!(in = fopen(filename, "r")))
@@ -207,7 +207,7 @@ static int follow_by_inotify(FILE *in, const char *filename, FILE *out)
static FILE *dump(FILE *in, const char *filename, int follow, FILE *out)
{
- struct utmp ut;
+ struct utmpx ut;
if (follow)
ignore_result( fseek(in, -10 * sizeof(ut), SEEK_END) );
@@ -265,7 +265,7 @@ static int gettok(char *line, char *dest, int size, int eatspace)
static void undump(FILE *in, FILE *out)
{
- struct utmp ut;
+ struct utmpx ut;
char s_addr[INET6_ADDRSTRLEN + 1], s_time[29], *linestart, *line;
int count = 0;