1/*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
--- 26 unchanged lines hidden (view full) ---
35
36#if 0
37#ifndef lint
38static char sccsid[] = "@(#)rwhod.c 8.1 (Berkeley) 6/6/93";
39#endif /* not lint */
40#endif
41
42#include <sys/cdefs.h>
43__FBSDID("$FreeBSD: head/usr.sbin/rwhod/rwhod.c 201060 2009-12-27 21:14:55Z ed $");
44
45#include <sys/param.h>
46#include <sys/socket.h>
47#include <sys/stat.h>
48#include <sys/signal.h>
49#include <sys/ioctl.h>
50#include <sys/sysctl.h>
51
--- 10 unchanged lines hidden (view full) ---
62#include <fcntl.h>
63#include <netdb.h>
64#include <paths.h>
65#include <stdio.h>
66#include <stdlib.h>
67#include <string.h>
68#include <syslog.h>
69#include <timeconv.h>
70#define _ULOG_POSIX_NAMES
71#include <ulog.h>
72#include <unistd.h>
73#include <pwd.h>
74#include <grp.h>
75
76/*
77 * This version of Berkeley's rwhod has been modified to use IP multicast
78 * datagrams, under control of a new command-line option:
79 *
80 * rwhod -m causes rwhod to use IP multicast (instead of
--- 61 unchanged lines hidden (view full) ---
142 struct sockaddr *n_addr; /* who to send to */
143 int n_addrlen; /* size of address */
144 int n_flags; /* should forward?, interface flags */
145};
146
147struct neighbor *neighbors;
148struct whod mywd;
149struct servent *sp;
150int s;
151
152#define WHDRSIZE (int)(sizeof(mywd) - sizeof(mywd.wd_we))
153
154void run_as(uid_t *, gid_t *);
155int configure(int);
156void getboottime(int);
157void onalrm(int);
158void quit(const char *);
--- 68 unchanged lines hidden (view full) ---
227 if (gethostname(myname, sizeof(myname) - 1) < 0) {
228 syslog(LOG_ERR, "gethostname: %m");
229 exit(1);
230 }
231 if ((cp = index(myname, '.')) != NULL)
232 *cp = '\0';
233 strncpy(mywd.wd_hostname, myname, sizeof(mywd.wd_hostname) - 1);
234 mywd.wd_hostname[sizeof(mywd.wd_hostname) - 1] = '\0';
235 getboottime(0);
236 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
237 syslog(LOG_ERR, "socket: %m");
238 exit(1);
239 }
240 if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)) < 0) {
241 syslog(LOG_ERR, "setsockopt SO_BROADCAST: %m");
242 exit(1);
--- 131 unchanged lines hidden (view full) ---
374 if (!isascii(*name) || !(isalnum(*name) || ispunct(*name)))
375 return (0);
376 name++, size++;
377 }
378 *name = '\0';
379 return (size > 0);
380}
381
382void
383onalrm(int signo __unused)
384{
385 struct neighbor *np;
386 struct whoent *we = mywd.wd_we, *wend;
387 struct stat stb;
388 struct utmpx *ut;
389 static int alarmcount = 0;
390 double avenrun[3];
391 time_t now;
392 int i, cc;
393
394 now = time(NULL);
395 if (alarmcount % 10 == 0)
396 getboottime(0);
397 alarmcount++;
398 wend = &mywd.wd_we[1024 / sizeof(struct whoent)];
399 setutxent();
400 while ((ut = getutxent()) != NULL && we < wend) {
401 if (ut->ut_type != USER_PROCESS)
402 continue;
403 strncpy(we->we_utmp.out_line, ut->ut_line,
404 sizeof(we->we_utmp.out_line));
405 strncpy(we->we_utmp.out_name, ut->ut_user,
406 sizeof(we->we_utmp.out_name));
407 we->we_utmp.out_time =
408 htonl(_time_to_time32(ut->ut_tv.tv_sec));
409 we++;
410 }
411 endutxent();
412
413 if (chdir(_PATH_DEV)) {
414 syslog(LOG_ERR, "chdir(%s): %m", _PATH_DEV);
415 exit(1);
416 }
417 wend = we;
418 for (we = mywd.wd_we; we < wend; we++) {
419 if (stat(we->we_utmp.out_line, &stb) >= 0)
420 we->we_idle = htonl(now - stb.st_atime);
421 we++;
422 }
423 (void)getloadavg(avenrun, sizeof(avenrun)/sizeof(avenrun[0]));
424 for (i = 0; i < 3; i++)
425 mywd.wd_loadav[i] = htonl((u_long)(avenrun[i] * 100));
426 cc = (char *)wend - (char *)&mywd;
427 mywd.wd_sendtime = htonl(_time_to_time32(time(NULL)));
428 mywd.wd_vers = WHODVERSION;
429 mywd.wd_type = WHODTYPE_STATUS;
430 if (multicast_mode == SCOPED_MULTICAST) {
431 (void) sendto(s, (char *)&mywd, cc, 0,
432 (struct sockaddr *)&multicast_addr,
433 sizeof(multicast_addr));
434 }
--- 11 unchanged lines hidden (view full) ---
446 exit(1);
447 }
448 (void) sendto(s, (char *)&mywd, cc, 0,
449 (struct sockaddr *)&multicast_addr,
450 sizeof(multicast_addr));
451 } else (void) sendto(s, (char *)&mywd, cc, 0,
452 np->n_addr, np->n_addrlen);
453 }
454 if (chdir(_PATH_RWHODIR)) {
455 syslog(LOG_ERR, "chdir(%s): %m", _PATH_RWHODIR);
456 exit(1);
457 }
458 (void) alarm(AL_INTERVAL);
459}
460
461void
462getboottime(signo)
463 int signo __unused;
464{
465 int mib[2];
--- 237 unchanged lines hidden ---
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
--- 26 unchanged lines hidden (view full) ---
35
36#if 0
37#ifndef lint
38static char sccsid[] = "@(#)rwhod.c 8.1 (Berkeley) 6/6/93";
39#endif /* not lint */
40#endif
41
42#include <sys/cdefs.h>
43__FBSDID("$FreeBSD: head/usr.sbin/rwhod/rwhod.c 201060 2009-12-27 21:14:55Z ed $");
44
45#include <sys/param.h>
46#include <sys/socket.h>
47#include <sys/stat.h>
48#include <sys/signal.h>
49#include <sys/ioctl.h>
50#include <sys/sysctl.h>
51
--- 10 unchanged lines hidden (view full) ---
62#include <fcntl.h>
63#include <netdb.h>
64#include <paths.h>
65#include <stdio.h>
66#include <stdlib.h>
67#include <string.h>
68#include <syslog.h>
69#include <timeconv.h>
70#define _ULOG_POSIX_NAMES
71#include <ulog.h>
72#include <unistd.h>
73#include <pwd.h>
74#include <grp.h>
75
76/*
77 * This version of Berkeley's rwhod has been modified to use IP multicast
78 * datagrams, under control of a new command-line option:
79 *
80 * rwhod -m causes rwhod to use IP multicast (instead of
--- 61 unchanged lines hidden (view full) ---
142 struct sockaddr *n_addr; /* who to send to */
143 int n_addrlen; /* size of address */
144 int n_flags; /* should forward?, interface flags */
145};
146
147struct neighbor *neighbors;
148struct whod mywd;
149struct servent *sp;
150int s;
151
152#define WHDRSIZE (int)(sizeof(mywd) - sizeof(mywd.wd_we))
153
154void run_as(uid_t *, gid_t *);
155int configure(int);
156void getboottime(int);
157void onalrm(int);
158void quit(const char *);
--- 68 unchanged lines hidden (view full) ---
227 if (gethostname(myname, sizeof(myname) - 1) < 0) {
228 syslog(LOG_ERR, "gethostname: %m");
229 exit(1);
230 }
231 if ((cp = index(myname, '.')) != NULL)
232 *cp = '\0';
233 strncpy(mywd.wd_hostname, myname, sizeof(mywd.wd_hostname) - 1);
234 mywd.wd_hostname[sizeof(mywd.wd_hostname) - 1] = '\0';
235 getboottime(0);
236 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
237 syslog(LOG_ERR, "socket: %m");
238 exit(1);
239 }
240 if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)) < 0) {
241 syslog(LOG_ERR, "setsockopt SO_BROADCAST: %m");
242 exit(1);
--- 131 unchanged lines hidden (view full) ---
374 if (!isascii(*name) || !(isalnum(*name) || ispunct(*name)))
375 return (0);
376 name++, size++;
377 }
378 *name = '\0';
379 return (size > 0);
380}
381
382void
383onalrm(int signo __unused)
384{
385 struct neighbor *np;
386 struct whoent *we = mywd.wd_we, *wend;
387 struct stat stb;
388 struct utmpx *ut;
389 static int alarmcount = 0;
390 double avenrun[3];
391 time_t now;
392 int i, cc;
393
394 now = time(NULL);
395 if (alarmcount % 10 == 0)
396 getboottime(0);
397 alarmcount++;
398 wend = &mywd.wd_we[1024 / sizeof(struct whoent)];
399 setutxent();
400 while ((ut = getutxent()) != NULL && we < wend) {
401 if (ut->ut_type != USER_PROCESS)
402 continue;
403 strncpy(we->we_utmp.out_line, ut->ut_line,
404 sizeof(we->we_utmp.out_line));
405 strncpy(we->we_utmp.out_name, ut->ut_user,
406 sizeof(we->we_utmp.out_name));
407 we->we_utmp.out_time =
408 htonl(_time_to_time32(ut->ut_tv.tv_sec));
409 we++;
410 }
411 endutxent();
412
413 if (chdir(_PATH_DEV)) {
414 syslog(LOG_ERR, "chdir(%s): %m", _PATH_DEV);
415 exit(1);
416 }
417 wend = we;
418 for (we = mywd.wd_we; we < wend; we++) {
419 if (stat(we->we_utmp.out_line, &stb) >= 0)
420 we->we_idle = htonl(now - stb.st_atime);
421 we++;
422 }
423 (void)getloadavg(avenrun, sizeof(avenrun)/sizeof(avenrun[0]));
424 for (i = 0; i < 3; i++)
425 mywd.wd_loadav[i] = htonl((u_long)(avenrun[i] * 100));
426 cc = (char *)wend - (char *)&mywd;
427 mywd.wd_sendtime = htonl(_time_to_time32(time(NULL)));
428 mywd.wd_vers = WHODVERSION;
429 mywd.wd_type = WHODTYPE_STATUS;
430 if (multicast_mode == SCOPED_MULTICAST) {
431 (void) sendto(s, (char *)&mywd, cc, 0,
432 (struct sockaddr *)&multicast_addr,
433 sizeof(multicast_addr));
434 }
--- 11 unchanged lines hidden (view full) ---
446 exit(1);
447 }
448 (void) sendto(s, (char *)&mywd, cc, 0,
449 (struct sockaddr *)&multicast_addr,
450 sizeof(multicast_addr));
451 } else (void) sendto(s, (char *)&mywd, cc, 0,
452 np->n_addr, np->n_addrlen);
453 }
454 if (chdir(_PATH_RWHODIR)) {
455 syslog(LOG_ERR, "chdir(%s): %m", _PATH_RWHODIR);
456 exit(1);
457 }
458 (void) alarm(AL_INTERVAL);
459}
460
461void
462getboottime(signo)
463 int signo __unused;
464{
465 int mib[2];
--- 237 unchanged lines hidden ---