-
Notifications
You must be signed in to change notification settings - Fork 1
/
operations.c
107 lines (80 loc) · 2.85 KB
/
operations.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
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "operations.h"
#include "net.h"
int ftpfs_init_data_connection(struct ftp_sb_info *info)
{
struct sockaddr_in saddr;
int r;
char *send_buffer,*recv_buffer,*tmp;
int i1,i2,i3,i4,p1,p2;
unsigned int ip;
unsigned int port;
send_buffer = kmalloc(SND_BUFFER_SIZE,GFP_KERNEL);
recv_buffer = kmalloc(RCV_BUFFER_SIZE,GFP_KERNEL);
tmp = kmalloc(RCV_BUFFER_SIZE,GFP_KERNEL);
sprintf(tmp, "PASV\r\n");
send_reply(info->control, tmp);
r=read_response(info->control, recv_buffer);
sscanf(recv_buffer,"%d %*s %*s %*s (%d,%d,%d,%d,%d,%d)",&r,&i1,&i2,&i3,&i4,&p1,&p2);
ip = (i1<<0x18)+(i2<<0x10)+(i3<<0x8)+i4;
port = 0x100*p1+p2;
printk("FTPFS::data connection: %x:%x",ip,port);
sock_create(PF_INET, SOCK_STREAM,IPPROTO_TCP, &info->data);
memset(&saddr,0, sizeof(saddr));
saddr.sin_family = AF_INET;
saddr.sin_port = htons(port);
saddr.sin_addr.s_addr =htonl(ip);
r = info->control->ops->connect(info->data,
(struct sockaddr *) &saddr,
sizeof(saddr), O_RDWR);
kfree(send_buffer);
kfree(recv_buffer);
kfree(tmp);
return 0;
}
int ftpfs_init_connection(struct ftp_sb_info *info)
{
struct sockaddr_in saddr;
int r;
char *send_buffer,*recv_buffer,*tmp;
send_buffer = kmalloc(SND_BUFFER_SIZE,GFP_KERNEL);
recv_buffer = kmalloc(RCV_BUFFER_SIZE,GFP_KERNEL);
tmp = kmalloc(RCV_BUFFER_SIZE,GFP_KERNEL);
sock_create(PF_INET, SOCK_STREAM,IPPROTO_TCP, &info->control);
memset(&saddr,0, sizeof(saddr));
saddr.sin_family = AF_INET;
saddr.sin_port = htons(CONTROL_PORT);
saddr.sin_addr.s_addr =htonl(info->params.host);
r = info->control->ops->connect(info->control,
(struct sockaddr *) &saddr,
sizeof(saddr), O_RDWR);
if (r && (r != -EINPROGRESS)) {
printk("FTPFS::connect error: %d\n", r);
}
r=read_response(info->control, recv_buffer);
sprintf(tmp, "USER %s\r\n",info->params.username );
send_reply(info->control, tmp);
r=read_response(info->control, recv_buffer);
sprintf(tmp, "PASS %s\r\n", info->params.password);
send_reply(info->control, tmp);
r=read_response(info->control, tmp);
ftpfs_init_data_connection(info);
kfree(send_buffer);
kfree(recv_buffer);
kfree(tmp);
return 0;
}
int ftpfs_cd(char *path,struct ftp_sb_info *info)
{
char *send_buffer,*recv_buffer,*tmp;
int r;
send_buffer = kmalloc(SND_BUFFER_SIZE,GFP_KERNEL);
recv_buffer = kmalloc(RCV_BUFFER_SIZE,GFP_KERNEL);
tmp = kmalloc(RCV_BUFFER_SIZE,GFP_KERNEL);
sprintf(tmp, "CWD %s\r\n",path);
send_reply(info->control, tmp);
r=read_response(info->control, recv_buffer);
kfree(send_buffer);
kfree(recv_buffer);
kfree(tmp);
return 0;
}