File: display.c

package info (click to toggle)
cfingerd 1.4.3-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 964 kB
  • sloc: ansic: 3,776; perl: 501; makefile: 137; sh: 73
file content (136 lines) | stat: -rw-r--r-- 2,719 bytes parent folder | download | duplicates (8)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 * 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[STRLEN];
    char *p;

    memset(hostname, 0, STRLEN);

    gethostname((char *) hostname, (size_t) STRLEN);
    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(const 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;
    char *idle;

    our_host = get_localhost();
    if (times_on == 0) {
	printf ("Nobody logged in.\n");
	return;
    } else
	printf ("USERNAME Real name                      Idletime TTY Remote console location\n");

    for (i = 0; (i < times_on) && (i < MAX_TTYS); i++) {
	char console[30];
	struct passwd *pwent;

	if (strlen((char *) tty_list[i].locale) == 0)
	    snprintf(console, sizeof(console), "(%s)", our_host);
	else
	    snprintf(console, sizeof(console), "(%s)", tty_list[i].locale);

	if (strlen((char *) tty_list[i].username) > 1) {
	    char *username=NULL;
	    char ru[9], fn[STRLEN];

	    memset(ru, 0, sizeof (ru));
	    memset(fn, 0, sizeof (fn));

	    strncpy(ru, tty_list[i].username, sizeof(ru)-1);

	    pwent = getpwnam((char *) ru);

	    if (pwent) {
		char *cp, *x;

		cp = pwent->pw_gecos;
		if ((x = index (pwent->pw_gecos, ',')) != NULL) /* username */
		    *x = '\0';
		    if ((username = (char *)malloc (strlen(cp)+1)) != NULL) {
			memset (username, 0, strlen(cp)+1);
			strcpy (username, cp);
		    }
		snprintf(fn, sizeof(fn), "%s/.nofinger", pwent->pw_dir);
	    }

	    idle = calc_idle((char *) tty_list[i].line);
	    if (pwent) {
		if (!exist((char *) fn)) {
		    if (idle) {
			printf("%-8.8s %-30.30s %8.8s ",
			       ru, username?username:"", idle);

			printf("%3.3s %-25.25s\n",
			       (char *) tty_list[i].tty, console);
		    }
		}
	    } else {
		if (idle) {
		    printf("%-8.8s %-30.30s %8.8s ",
			   ru, ru, idle);

		    printf("%3.3s %-25.25s\n",
			   (char *) tty_list[i].tty, console);
		}
	    }
	}

	fflush(stdout);
    }
}

/*
 * Local variables:
 *  c-indent-level: 4
 *  c-basic-offset: 4
 *  tab-width: 8
 * End:
 */