2009-10-27 03:59:03 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
|
|
|
* wall - write a message to all logged-in users
|
|
|
|
* Copyright (c) 2009 Bernhard Reutner-Fischer
|
|
|
|
*
|
2010-08-16 23:44:46 +05:30
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2009-10-27 03:59:03 +05:30
|
|
|
*/
|
|
|
|
|
2013-10-06 18:44:25 +05:30
|
|
|
//config:config WALL
|
2017-07-19 01:31:24 +05:30
|
|
|
//config: bool "wall (2.5 kb)"
|
2013-10-06 18:44:25 +05:30
|
|
|
//config: default y
|
|
|
|
//config: depends on FEATURE_UTMP
|
|
|
|
//config: help
|
|
|
|
//config: Write a message to all users that are logged in.
|
|
|
|
|
|
|
|
/* Needs to be run by root or be suid root - needs to write to /dev/TTY: */
|
|
|
|
//applet:IF_WALL(APPLET(wall, BB_DIR_USR_BIN, BB_SUID_REQUIRE))
|
|
|
|
|
|
|
|
//kbuild:lib-$(CONFIG_WALL) += wall.o
|
|
|
|
|
2011-04-11 06:59:49 +05:30
|
|
|
//usage:#define wall_trivial_usage
|
|
|
|
//usage: "[FILE]"
|
|
|
|
//usage:#define wall_full_usage "\n\n"
|
|
|
|
//usage: "Write content of FILE or stdin to all logged-in users"
|
|
|
|
//usage:
|
|
|
|
//usage:#define wall_sample_usage
|
|
|
|
//usage: "echo foo | wall\n"
|
|
|
|
//usage: "wall ./mymessage"
|
|
|
|
|
2009-10-27 03:59:03 +05:30
|
|
|
#include "libbb.h"
|
|
|
|
|
|
|
|
int wall_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
|
|
|
int wall_main(int argc UNUSED_PARAM, char **argv)
|
|
|
|
{
|
2015-04-03 02:33:46 +05:30
|
|
|
struct utmpx *ut;
|
2009-10-27 03:59:03 +05:30
|
|
|
char *msg;
|
2013-10-06 18:44:25 +05:30
|
|
|
int fd;
|
2009-10-27 03:59:03 +05:30
|
|
|
|
2013-10-06 18:44:25 +05:30
|
|
|
fd = STDIN_FILENO;
|
|
|
|
if (argv[1]) {
|
|
|
|
/* The applet is setuid.
|
|
|
|
* Access to the file must be under user's uid/gid.
|
|
|
|
*/
|
2013-10-08 18:23:29 +05:30
|
|
|
fd = xopen_as_uid_gid(argv[1], O_RDONLY, getuid(), getgid());
|
2013-10-06 18:44:25 +05:30
|
|
|
}
|
2009-10-27 03:59:03 +05:30
|
|
|
msg = xmalloc_read(fd, NULL);
|
|
|
|
if (ENABLE_FEATURE_CLEAN_UP && argv[1])
|
|
|
|
close(fd);
|
2015-04-03 02:33:46 +05:30
|
|
|
setutxent();
|
|
|
|
while ((ut = getutxent()) != NULL) {
|
2009-10-27 03:59:03 +05:30
|
|
|
char *line;
|
|
|
|
if (ut->ut_type != USER_PROCESS)
|
|
|
|
continue;
|
|
|
|
line = concat_path_file("/dev", ut->ut_line);
|
|
|
|
xopen_xwrite_close(line, msg);
|
|
|
|
free(line);
|
|
|
|
}
|
|
|
|
if (ENABLE_FEATURE_CLEAN_UP) {
|
2015-04-03 02:33:46 +05:30
|
|
|
endutxent();
|
2009-10-27 03:59:03 +05:30
|
|
|
free(msg);
|
|
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|