1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
/*
* USERLIST
* Display management routines
*/
#include "userlist.h"
#include "proto.h"
char *inettos(long addr)
{
char *ret;
int p1, p2, p3, p4;
ret = (char *) malloc(20);
p1 = (addr & 0x000000FF);
p2 = (addr & 0x0000FF00) >> 8;
p3 = (addr & 0x00FF0000) >> 16;
p4 = (addr & 0xFF000000) >> 24;
sprintf(ret, "%d.%d.%d.%d", p1, p2, p3, p4);
return(ret);
}
char *get_localhost(void)
{
#ifndef LOCAL_NAME
char *ret;
char hostname[80];
char *p;
bzero(hostname, 80);
gethostname((char *) hostname, (size_t) 80);
if ((p = index(hostname, '.')) != NULL)
*p = '\0';
ret = (char *) malloc(strlen((char *) hostname) + 1);
sprintf(ret, "%s", (char *) hostname);
return(ret);
#else
return(LOCAL_NAME);
#endif
}
int exist(char *filename)
{
FILE *file;
file = fopen(filename, "r");
if (file) {
fclose(file);
return(1);
} else
return(0);
}
void process_display(void)
{
int i;
char *our_host;
our_host = get_localhost();
printf("Username Real name Idletime TTY Remote console\n");
for (i = 0; i < times_on; i++) {
char console[30];
struct passwd *pwent;
if (strlen((char *) tty_list[i].locale) == 0)
sprintf(console, "(%s)", our_host);
else
sprintf(console, "(%s)", tty_list[i].locale);
if (strlen((char *) tty_list[i].username) > 1) {
char username[80], dummy[80], ru[8], fn[80];
bzero(username, 80);
bzero(dummy, 80);
bzero(ru, 8);
bzero(fn, 80);
strcpy(ru, tty_list[i].username);
ru[8] = 0;
pwent = getpwnam((char *) ru);
if (pwent) {
sscanf(pwent->pw_gecos, "%[^,],%[^\r\n]\r\n", username, dummy);
sprintf(fn, "%s/.nofinger", pwent->pw_dir);
}
if (pwent) {
if (!exist((char *) fn)) {
printf("%-8.8s %-30.30s ",
ru, username);
show_idle((char *) tty_list[i].line);
printf("%3.3s %-25.25s\n",
(char *) tty_list[i].tty, console);
}
} else {
printf("%-8.8s %-30.30s ",
ru, ru);
show_idle((char *) tty_list[i].line);
printf("%3.3s %-25.25s\n",
(char *) tty_list[i].tty, console);
}
}
fflush(stdout);
}
}
|