File: efingerd.c

package info (click to toggle)
efingerd 1.6.2.7
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 296 kB
  • ctags: 34
  • sloc: sh: 344; ansic: 254; makefile: 61
file content (168 lines) | stat: -rw-r--r-- 3,535 bytes parent folder | download | duplicates (6)
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/* 
 * ================================================================
 * Please view:
 *
 * 	README for program information.
 * 	COPYING for distribution information.
 *
 * 	based on ident2 by Michael Bacarella (defile@nyct.net)
 *
 * ================================================================ 
 */
#include "efingerd.h"

	unsigned short client_timeout = 60;


/* ------------------------------------------------------------------
 * killsock:
 *	violently kills a socket
 * ------------------------------------------------------------------
 */
void killsock (int s)
{
	shutdown (s, 2);
	close (s);
}



/* ------------------------------------------------------------------
 * get_request	:	a fgets for file descriptors 
 * ------------------------------------------------------------------
 */
int get_request (int d, char buffer[], u_short len)
{
	u_short i;
	char ch;
 
	memset (buffer, 0, len);
	for (i = 0; i < len; i++) {
		if (read (d, &ch, 1) != 1)
			return -1; 
		else if (ch == '\n') { /* some buggy clients send only \n */
			break;
		     }
		else if (ch == '\r') {
			read (d, &ch, 1); /* should read the following \n */
			break;
		     }
		else
			buffer[i] = ch;
	}
	buffer[i] = '\0';
	return i;
}




/* ------------------------------------------------------------------
 * client_reply: 
 *	send a reply back to the client..
 * ------------------------------------------------------------------
 */
void client_reply (int sd, char *outcome)
{
	write (sd, outcome, strlen (outcome));
}



/* ============================================================================
	LOCAL FUNCTIONS
============================================================================ */


/* usage:
 * ------------------------------------------------------------------
 */	
static void	usage (char *progname)
{
	 fprintf (stderr, "usage: %s [options]\n"
			"   --help     This information.\n"
			"   --version  Print version information and exit.\n"
			"   -t X       Time to keep connection.\n"
			"              ex: -t 25  maintain connections for up to 25 seconds.\n"
			"   -n         Do not lookup addresses, use IP numbers instead.\n"
			"   -f         Do not display users' full names.\n"
			"   -u         Ignore user-specific .efingerd file\n",
			progname);
	exit (0);
}



/* ------------------------------------------------------------------
 * print_version:
 *	wouldn't want to disappoint anyone.
 * ------------------------------------------------------------------
 */
static void	print_version (void)
{
	fprintf (stderr, "efingerd %s\n", ID_VERSION );
	exit (0);
}



int main (int argc, char *argv[])
{	
	u_short i;
	
	resolve_addr = 1;
	display_full_name = 1;
	ignore_user = 0;
	
	for (i = 1; i < argc; i++) {
		if (argv[i][0] == '-') {
			switch (argv[i][1]) {
				case 't':
					client_timeout = atoi ( argv[++i]);
					break;

				case 'f':
					display_full_name = 0;
					break;
                    
				case 'v':
					print_version ();
					
				case 'n':
					resolve_addr = 0;
					break;

				case 'u':
					ignore_user = 1;
					break;
                
				case 'h':
					usage (argv[0]);
                	
				case '-':

					if (strncmp ("version", ( argv[i]+2), 7) == 0)
						print_version ();

					else if (strcmp ("help", ( argv[i]+2)) == 0)
						usage (argv[0]);
						
					break;
			}
		}
	}
	
		
	
	openlog ("efingerd", LOG_PID, LOG_DAEMON);
	alarm (client_timeout);
	signal (SIGALRM, killtic);
    	
	inetd_service (0, 1);
    
	killsock (0);
	killsock (1);
	closelog ();
	exit (-1);

}