-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathfingerd.c
94 lines (86 loc) · 1.8 KB
/
fingerd.c
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
/* Internet Finger server
* Copyright 1991 Phil Karn, KA9Q
*/
#include <stdio.h>
#include <string.h>
#include "global.h"
#include "files.h"
#include "mbuf.h"
#include "socket.h"
#include "session.h"
#include "proc.h"
#include "dirutil.h"
#include "commands.h"
#include "mailbox.h"
static void fingerd(int s,void *unused,void *p);
/* Start up finger service */
int
finstart(argc,argv,p)
int argc;
char *argv[];
void *p;
{
uint16 port;
if(argc < 2)
port = IPPORT_FINGER;
else
port = atoi(argv[1]);
return start_tcp(port,"Finger Server",fingerd,512);
}
static void
fingerd(s,n,p)
int s;
void *n;
void *p;
{
char user[80];
FILE *fp;
char *file,*cp;
FILE *network;
network = fdopen(s,"r+t");
sockowner(s,Curproc);
logmsg(s,"open Finger");
fgets(user,sizeof(user),network);
rip(user);
if(strlen(user) == 0){
fp = dir(Fdir,0);
if(fp == NULL)
fprintf(network,"No finger information available\n");
else
fprintf(network,"Known users on this system:\n");
} else {
file = pathname(Fdir,user);
cp = pathname(Fdir,"");
/* Check for attempted security violation (e.g., somebody
* might be trying to finger "../ftpusers"!)
*/
if(strncmp(file,cp,strlen(cp)) != 0){
fp = NULL;
fprintf(network,"Invalid user name %s\n",user);
} else if((fp = fopen(file,READ_TEXT)) == NULL)
fprintf(network,"User %s not known\n",user);
free(cp);
free(file);
}
if(fp != NULL){
sendfile(fp,network,ASCII_TYPE,0);
fclose(fp);
}
if(strlen(user) == 0 && Listusers != NULL)
(*Listusers)(network);
fclose(network);
logmsg(s,"close Finger");
}
int
fin0(argc,argv,p)
int argc;
char *argv[];
void *p;
{
uint16 port;
if(argc < 2)
port = IPPORT_FINGER;
else
port = atoi(argv[1]);
return stop_tcp(port);
}