@@ -83,7 +83,27 @@ static void device_lock(struct device *device)
8383 err (1 , "failed to lock lockfile %s" , lock );
8484}
8585
86+ static bool device_check_access (struct device * device ,
87+ const char * username )
88+ {
89+ struct device_user * user ;
90+
91+ if (!device -> users )
92+ return true;
93+
94+ if (!username )
95+ return false;
96+
97+ list_for_each_entry (user , device -> users , node ) {
98+ if (!strcmp (user -> username , username ))
99+ return true;
100+ }
101+
102+ return false;
103+ }
104+
86105struct device * device_open (const char * board ,
106+ const char * username ,
87107 struct fastboot_ops * fastboot_ops )
88108{
89109 struct device * device ;
@@ -98,6 +118,9 @@ struct device *device_open(const char *board,
98118found :
99119 assert (device -> open || device -> console_dev );
100120
121+ if (!device_check_access (device , username ))
122+ return NULL ;
123+
101124 device_lock (device );
102125
103126 if (device -> open ) {
@@ -269,14 +292,17 @@ void device_send_break(struct device *device)
269292 device -> send_break (device );
270293}
271294
272- void device_list_devices (void )
295+ void device_list_devices (const char * username )
273296{
274297 struct device * device ;
275298 struct msg hdr ;
276299 size_t len ;
277300 char buf [80 ];
278301
279302 list_for_each_entry (device , & devices , node ) {
303+ if (!device_check_access (device , username ))
304+ continue ;
305+
280306 if (device -> name )
281307 len = snprintf (buf , sizeof (buf ), "%-20s %s" , device -> board , device -> name );
282308 else
@@ -293,15 +319,21 @@ void device_list_devices(void)
293319 write (STDOUT_FILENO , & hdr , sizeof (hdr ));
294320}
295321
296- void device_info (const void * data , size_t dlen )
322+ void device_info (const char * username , const void * data , size_t dlen )
297323{
298324 struct device * device ;
299325 struct msg hdr ;
300326 char * description ;
301327 size_t len = 0 ;
302328
303329 list_for_each_entry (device , & devices , node ) {
304- if (!strncmp (device -> board , data , dlen ) && device -> description ) {
330+ if (strncmp (device -> board , data , dlen ))
331+ continue ;
332+
333+ if (!device_check_access (device , username ))
334+ continue ;
335+
336+ if (device -> description ) {
305337 description = device -> description ;
306338 len = strlen (device -> description );
307339 break ;
0 commit comments