This source file includes following definitions.
- ncp_ioctl
1
2
3
4
5
6
7
8 #include <asm/segment.h>
9 #include <linux/errno.h>
10 #include <linux/fs.h>
11 #include <linux/ncp_fs.h>
12 #include <linux/ioctl.h>
13 #include <linux/sched.h>
14 #include <linux/mm.h>
15 #include <linux/ncp.h>
16
17 int
18 ncp_ioctl (struct inode * inode, struct file * filp,
19 unsigned int cmd, unsigned long arg)
20 {
21 int result;
22 struct ncp_ioctl_request request;
23 struct ncp_fs_info info;
24 struct ncp_server *server = NCP_SERVER(inode);
25
26
27
28
29
30
31 switch(cmd) {
32 case _IOR('n', 1, unsigned char *):
33 cmd = NCP_IOC_NCPREQUEST;
34 break;
35 case _IOR('u', 1, uid_t):
36 cmd = NCP_IOC_GETMOUNTUID;
37 break;
38 case _IO('l', 1):
39 cmd = NCP_IOC_CONN_LOGGED_IN;
40 break;
41 case _IOWR('i', 1, unsigned char *):
42 cmd = NCP_IOC_GET_FS_INFO;
43 break;
44 }
45
46 switch(cmd) {
47 case NCP_IOC_NCPREQUEST:
48
49 if ( (permission(inode, MAY_WRITE) != 0)
50 && (current->uid != server->m.mounted_uid))
51 {
52 return -EACCES;
53 }
54
55 if ((result = verify_area(VERIFY_READ, (char *)arg,
56 sizeof(request))) != 0)
57 {
58 return result;
59 }
60
61 memcpy_fromfs(&request, (struct ncp_ioctl_request *)arg,
62 sizeof(request));
63
64 if ( (request.function > 255)
65 || (request.size >
66 NCP_PACKET_SIZE - sizeof(struct ncp_request_header)))
67 {
68 return -EINVAL;
69 }
70
71 if ((result = verify_area(VERIFY_WRITE, (char *)request.data,
72 NCP_PACKET_SIZE)) != 0)
73 {
74 return result;
75 }
76
77 ncp_lock_server(server);
78
79
80
81
82 server->has_subfunction = 0;
83 server->current_size = request.size;
84 memcpy_fromfs(server->packet, request.data, request.size);
85
86 ncp_request(server, request.function);
87
88 DPRINTK("ncp_ioctl: copy %d bytes\n",
89 server->reply_size);
90 memcpy_tofs(request.data, server->packet, server->reply_size);
91
92 ncp_unlock_server(server);
93
94 return server->reply_size;
95
96 case NCP_IOC_CONN_LOGGED_IN:
97
98 if ( (permission(inode, MAY_WRITE) != 0)
99 && (current->uid != server->m.mounted_uid))
100 {
101 return -EACCES;
102 }
103
104 return ncp_conn_logged_in(server);
105
106 case NCP_IOC_GET_FS_INFO:
107
108 if ( (permission(inode, MAY_WRITE) != 0)
109 && (current->uid != server->m.mounted_uid))
110 {
111 return -EACCES;
112 }
113
114 if ((result = verify_area(VERIFY_WRITE, (char *)arg,
115 sizeof(info))) != 0)
116 {
117 return result;
118 }
119
120 memcpy_fromfs(&info, (struct ncp_fs_info *)arg,
121 sizeof(info));
122
123 if (info.version != NCP_GET_FS_INFO_VERSION)
124 {
125 DPRINTK("info.version invalid: %d\n", info.version);
126 return -EINVAL;
127 }
128
129 info.addr = server->m.serv_addr;
130 info.mounted_uid = server->m.mounted_uid;
131 info.connection = server->connection;
132 info.buffer_size = server->buffer_size;
133 info.volume_number = NCP_ISTRUCT(inode)->volNumber;
134 info.directory_id = NCP_ISTRUCT(inode)->DosDirNum;
135
136 memcpy_tofs((struct ncp_fs_info *)arg, &info, sizeof(info));
137 return 0;
138
139 case NCP_IOC_GETMOUNTUID:
140
141 if ( (permission(inode, MAY_READ) != 0)
142 && (current->uid != server->m.mounted_uid))
143 {
144 return -EACCES;
145 }
146
147 if ((result = verify_area(VERIFY_WRITE, (uid_t*) arg,
148 sizeof(uid_t))) != 0)
149 {
150 return result;
151 }
152 put_fs_word(server->m.mounted_uid, (uid_t*) arg);
153 return 0;
154
155 default:
156 return -EINVAL;
157 }
158
159 return -EINVAL;
160 }