close

Вход

Забыли?

вход по аккаунту

?

output2

код для вставкиСкачать
60
}
61
62/*-----------------------------------------------------------------------------*/
63
64
CLASS_ATTR(auth,
0444
,
&
_show,
&
_store);
65
66/*-----------------------------------------------------------------------------*/
67
68
static
int
read_config_file
(
void
)
69
{
70
struct
file
*
f
=
filp_open(CONFIGFILE,O_RDONLY,
0
);
71
72
if
(f
==
NULL
)
73
{
74
printk(KERN_ALERT
"file open failed:%s
\n
",CONFIGFILE);
75
76
return
FAIL;
77
}
78
79
char
buf[BUFSIZE
+
1
]
=
{
0
};
80
char
vendor_id_str[]
=
"0xXXXX";
81
char
product_id_str[]
=
"0xXXXX";
82
83
ssize_t
cnt
=
0
;
84
loff_t offset
=
0
;
85
int
uid_length
=
0
;
86
int
gid_length
=
0
;
87
int
line_length
=
0
;
88
int
name_length
=
0
;
89
int
cnt_of_delims
=
0
;
90
int
are_there_vid_pid
=
0
;
91
92
INIT_LIST_HEAD(
&
_userInfoList.list);
93
94
for
(;;)
95
{
96
cnt
=
kernel_read(f,offset,buf,BUFSIZE);
97
98
if
(cnt
==
0
)
99
break
;
100
101
name_length
=
0
;
102
line_length
=
0
;
103
cnt_of_delims
=
0
;
104
gid_length
=
0
;
105
uid_length
=
0
;
106
are_there_vid_pid
=
0
;
107
108//parse file
109
for
(;(line_length
<
cnt)
&&
(buf[line_length]
!=
’\n’
);
++
line_length)
110
{
111
if
(buf[line_length]
==
’:’
)
112
++
cnt_of_delims;
113
else
114
{
115
if
(cnt_of_delims
==
0
)
++
name_length;
116
if
(cnt_of_delims
==
2
)
++
uid_length;
117
if
(cnt_of_delims
==
3
)
++
gid_length;
118
if
(cnt_of_delims
==
4
)
119
{
120
if
(isxdigit(buf[line_length])
||
buf[line_length]
==
’ ’
)
//nasty solution
121
++
are_there_vid_pid;
122
}
123
}
124
}
125
126
offset
+=
line_length
+
1
;
/* 1 - ignore\n*/
127
128
char
*
username
=
kzalloc(name_length
+
1
,GFP_KERNEL);
129
130
strncpy(username,buf,name_length);
131
132
long
vendor_id
=
0
,
133
product_id
=
0
;
134
135
if
(are_there_vid_pid
==
PRODUCTIDLENGTH
+
VENDORIDLENGTH
+
1
)
12
136
{
137
strncpy(vendor_id_str
+
2
,buf
+
name_length
+
uid_length
+
gid_length
+
5
,VENDORIDLENGTH);
138
strncpy(product_id_str
+
2
,buf
+
name_length
+
uid_length
+
gid_length
+
VENDORIDLENGTH
+
6
,PRODUCTIDLENGTH);
139
140
strict_strtol(vendor_id_str,
16
,
&
vendor_id);
141
strict_strtol(product_id_str,
16
,
&
product_id);
142
}
143
144
if
(vendor_id)
//http://www.linux-usb.org/usb.ids (vendorID!= 0)
145
{
146
struct
UserInfoList
*
aNewUserInfo;
147
148
aNewUserInfo
=
kmalloc(
sizeof
(
struct
UserInfoList),GFP_KERNEL);
149
aNewUserInfo
->
idVendor
=
vendor_id;
150
aNewUserInfo
->
idProduct
=
product_id;
151
aNewUserInfo
->
username
=
username;
152
153
INIT_LIST_HEAD(
&
aNewUserInfo
->
list);
154
list_add_tail(
&
aNewUserInfo
->
list,
&
_userInfoList.list);
155
}
156
else
157
kfree(username);
158
159
160
memset(buf,
0
,
sizeof
(buf));
161
memset(vendor_id_str
+
2
,
’X’
,VENDORIDLENGTH);
162
memset(product_id_str
+
2
,
’X’
,PRODUCTIDLENGTH);
163
}
164
165
filp_close(f,
NULL
);
166
167
return
SUCCESS;
168
}
169
170/*-----------------------------------------------------------------------------*/
171
172
static
int
match_device
(
struct
usb_device
*
dev)
173
{
174
int
retval
= -
ENODEV;
175
176
struct
UserInfoList
*
iter;
177
178
list_for_each_entry(iter,
&
_userInfoList.list,list)
179
{
180
181
if
((dev
->
descriptor.idVendor
==
iter
->
idVendor)
&&
182
(dev
->
descriptor.idProduct
==
iter
->
idProduct))
183
{
184
if
((_prevUserName
==
NULL
)
||
185
((_prevUserName
!=
NULL
)
&&
strcmp(_prevUserName,iter
->
username)))
186
{
187
memset(_username,
0
,
sizeof
(_username));
188
_store(_class,
&
class_attr_auth,iter
->
username,strlen(iter
->
username));
189
_prevUserName
=
iter
->
username;
190
}
191
192
return
SUCCESS;
193
}
194
}
195
196
int
child;
197
198
for
(child
=
0
;child
<
dev
->
maxchild;
++
child)
199
{
200
if
(dev
->
children[child])
201
{
202
retval
=
match_device(dev
->
children[child]);
203
204
if
(retval
==
SUCCESS)
205
return
retval;
206
}
207
}
208
209
return
retval;
210
}
211
13
Автор
perplexus
Документ
Категория
Без категории
Просмотров
53
Размер файла
75 Кб
Теги
output
1/--страниц
Пожаловаться на содержимое документа