lslogins: add functionality
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
This commit is contained in:
parent
78dd745089
commit
29cc2a5568
|
@ -116,6 +116,7 @@ update.log
|
|||
/lsblk
|
||||
/lscpu
|
||||
/lslocks
|
||||
/lslogins
|
||||
/mcookie
|
||||
/mesg
|
||||
/mkfs
|
||||
|
|
|
@ -37,6 +37,7 @@ dist_noinst_HEADERS += \
|
|||
include/pathnames.h \
|
||||
include/procutils.h \
|
||||
include/randutils.h \
|
||||
include/readutmp.h \
|
||||
include/rpmatch.h \
|
||||
include/setproctitle.h \
|
||||
include/strutils.h \
|
||||
|
|
|
@ -26,7 +26,8 @@ libcommon_la_SOURCES = \
|
|||
lib/timeutils.c \
|
||||
lib/ttyutils.c \
|
||||
lib/xgetpass.c \
|
||||
lib/exec_shell.c
|
||||
lib/exec_shell.c \
|
||||
lib/readutmp.c
|
||||
|
||||
if LINUX
|
||||
libcommon_la_SOURCES += \
|
||||
|
|
|
@ -165,6 +165,19 @@ newgrp_LDADD += -lcrypt
|
|||
endif
|
||||
endif # BUILD_NEWGRP
|
||||
|
||||
if BUILD_LSLOGINS
|
||||
usrbin_exec_PROGRAMS += lslogins
|
||||
dist_man_MANS += login-utils/lslogins.1
|
||||
lslogins_SOURCES = \
|
||||
login-utils/lslogins.c \
|
||||
login-utils/logindefs.c \
|
||||
login-utils/logindefs.h
|
||||
lslogins_LDADD = $(LDADD) libcommon.la libsmartcols.la
|
||||
lslogins_CFLAGS = $(AM_CFLAGS) -I$(ul_libsmartcols_incdir)
|
||||
if HAVE_SELINUX
|
||||
lslogins_LDADD += -lselinux
|
||||
endif
|
||||
endif # BUILD_LSLOGINS
|
||||
|
||||
if BUILD_VIPW
|
||||
usrsbin_exec_PROGRAMS += vipw
|
||||
|
@ -207,16 +220,3 @@ endif
|
|||
if BUILD_VIPW
|
||||
cd $(DESTDIR)$(usrsbin_execdir) && ln -sf vipw vigr
|
||||
endif
|
||||
|
||||
if BUILD_LSLOGINS
|
||||
usrbin_exec_PROGRAMS += lslogins
|
||||
dist_man_MANS += login-utils/lslogins.1
|
||||
lslogins_SOURCES = \
|
||||
login-utils/lslogins.c \
|
||||
login-utils/lslogins.h
|
||||
lslogins_LDADD = $(LDADD) libcommon.la libsmartcols.la
|
||||
lslogins_CFLAGS = $(AM_CFLAGS) -I$(ul_libsmartcols_incdir)
|
||||
if HAVE_SELINUX
|
||||
lslogins_LDADD += -lselinux
|
||||
endif
|
||||
endif # BUILD_LSLOGINS
|
||||
|
|
|
@ -1248,7 +1248,7 @@ int main(int argc, char **argv)
|
|||
|
||||
endpwent();
|
||||
|
||||
cxt.quiet = get_hushlogin_status(pwd);
|
||||
cxt.quiet = get_hushlogin_status(pwd, 1);
|
||||
|
||||
log_utmp(&cxt);
|
||||
log_audit(&cxt, 1);
|
||||
|
|
|
@ -307,7 +307,7 @@ int effective_access(const char *path, int mode)
|
|||
* BSD setreuid().
|
||||
*/
|
||||
|
||||
int get_hushlogin_status(struct passwd *pwd)
|
||||
int get_hushlogin_status(struct passwd *pwd, int force_check)
|
||||
{
|
||||
const char *files[] = { _PATH_HUSHLOGINS, _PATH_HUSHLOGIN, NULL };
|
||||
const char *file;
|
||||
|
@ -358,12 +358,13 @@ int get_hushlogin_status(struct passwd *pwd)
|
|||
/* per-account setting */
|
||||
if (strlen(pwd->pw_dir) + sizeof(file) + 2 > sizeof(buf))
|
||||
continue;
|
||||
else {
|
||||
|
||||
sprintf(buf, "%s/%s", pwd->pw_dir, file);
|
||||
|
||||
if (force_check) {
|
||||
uid_t ruid = getuid();
|
||||
gid_t egid = getegid();
|
||||
|
||||
sprintf(buf, "%s/%s", pwd->pw_dir, file);
|
||||
|
||||
if (setregid(-1, pwd->pw_gid) == 0 &&
|
||||
setreuid(0, pwd->pw_uid) == 0)
|
||||
ok = effective_access(buf, O_RDONLY) == 0;
|
||||
|
@ -377,6 +378,15 @@ int get_hushlogin_status(struct passwd *pwd)
|
|||
if (ok)
|
||||
return 1; /* enabled by user */
|
||||
}
|
||||
else {
|
||||
int rc;
|
||||
rc = effective_access(buf, O_RDONLY);
|
||||
if (rc == 0)
|
||||
return 1;
|
||||
else if (rc == -1 && errno == EACCES)
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -9,6 +9,6 @@ extern const char *getlogindefs_str(const char *name, const char *dflt);
|
|||
extern void free_getlogindefs_data(void);
|
||||
extern int logindefs_setenv(const char *name, const char *conf, const char *dflt);
|
||||
extern int effective_access(const char *path, int mode);
|
||||
extern int get_hushlogin_status(struct passwd *pwd);
|
||||
extern int get_hushlogin_status(struct passwd *pwd, int force_check);
|
||||
|
||||
#endif /* UTIL_LINUX_LOGINDEFS_H */
|
||||
|
|
|
@ -73,6 +73,9 @@ Show extra information about users - home diretory, default login shell, passwor
|
|||
\fB\-z\fR, \fB\-\-print0\fR
|
||||
Delimit user entries with a nul character, instead of a newline.
|
||||
.TP
|
||||
\fB\-Z\fR, \fB\-\-context\fR
|
||||
Display the users' security context.
|
||||
.TP
|
||||
\fB\-h\fR, \fB\-\-help\fR
|
||||
Display help information and exit.
|
||||
\fB\-v\fR, \fB\-\-version\fR
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue