modified: sysvinit-2.86/doc/Propaganda
[mikesnafu-overlay.git] / sysvinit-2.86 / src / wall.c
blob92ffbc1a4079495f69e7eef859bab206a1911da1
1 /*
2 * wall.c Write to all users logged in.
4 * Usage: wall [text]
6 * Version: @(#)wall 2.79 12-Sep-2000 miquels@cistron.nl
8 * This file is part of the sysvinit suite,
9 * Copyright 1991-2000 Miquel van Smoorenburg.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
17 #include <stdio.h>
18 #include <string.h>
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <pwd.h>
22 #include <syslog.h>
25 char *Version = "@(#) wall 2.79 12-Sep-2000 miquels@cistron.nl";
26 #define MAXLEN 4096
27 #define MAXLINES 20
29 extern void wall(char *, int, int);
31 int main(int argc, char **argv)
33 char buf[MAXLEN];
34 char line[83];
35 int i, f, ch;
36 int len = 0;
37 int remote = 0;
38 char *p;
39 char *whoami;
40 struct passwd *pwd;
42 buf[0] = 0;
43 if ((pwd = getpwuid(getuid())) == NULL) {
44 if (getuid() == 0)
45 whoami = "root";
46 else {
47 fprintf(stderr, "You don't exist. Go away.\n");
48 exit(1);
50 } else
51 whoami = pwd->pw_name;
53 while((ch = getopt(argc, argv, "n")) != EOF)
54 switch(ch) {
55 case 'n':
57 * Undocumented option for suppressing
58 * banner from rpc.rwalld. Only works if
59 * we are root or if we're NOT setgid.
61 if (geteuid() != 0 && getgid() != getegid()) {
62 fprintf(stderr, "wall -n: not priviliged\n");
63 exit(1);
65 remote = 1;
66 break;
67 default:
68 fprintf(stderr, "usage: wall [message]\n");
69 return 1;
70 break;
73 if ((argc - optind) > 0) {
74 for(f = optind; f < argc; f++) {
75 len += strlen(argv[f]) + 1;
76 if (len >= MAXLEN-2) break;
77 strcat(buf, argv[f]);
78 if (f < argc-1) strcat(buf, " ");
80 strcat(buf, "\r\n");
81 } else {
82 while(fgets(line, 80, stdin)) {
84 * Make sure that line ends in \r\n
86 for(p = line; *p && *p != '\r' && *p != '\n'; p++)
88 strcpy(p, "\r\n");
89 len += strlen(line);
90 if (len >= MAXLEN) break;
91 strcat(buf, line);
95 i = 0;
96 for (p = buf; *p; p++) {
97 if (*p == '\n' && i++ > MAXLINES) {
98 *++p = 0;
99 break;
103 openlog("wall", LOG_PID, LOG_USER);
104 syslog(LOG_INFO, "wall: user %s broadcasted %d lines (%d chars)",
105 whoami, i, strlen(buf));
106 closelog();
108 unsetenv("TZ");
109 wall(buf, 0, remote);
111 /*NOTREACHED*/
112 return 0;