|
Lines 496-510
Link Here
|
| 496 |
/** |
496 |
/** |
| 497 |
* Search the autodetected_scanners list for USB scanners |
497 |
* Search the autodetected_scanners list for USB scanners |
| 498 |
* and if at least one USB scanner was found, |
498 |
* and if at least one USB scanner was found, |
| 499 |
* then create the file /etc/resmgr.conf.d/50-scanner.conf |
499 |
* then create the file /etc/hal/fdi/policy/10osvendor/80-scanner.fdi |
| 500 |
* with an entry for each autodetected USB scanner like |
500 |
* with an entry for each autodetected USB scanner like |
| 501 |
* ----------------------------------------------------------------------------------- |
501 |
* ----------------------------------------------------------------------------------- |
| 502 |
* add usb:vendor=0x1234,product=0x5678 scanner |
502 |
* <match key="linux.subsystem" string="usb"> |
| 503 |
* add usb:vendor=0x1a2b,product=0x3c4d scanner |
503 |
* <match key="usb.vendor_id" int="0x12345"> |
|
|
504 |
* <match key="usb.product_id" int="0x5678"> |
| 505 |
* <merge key="resmgr.class" type="string">scanner</merge> |
| 506 |
* </match> |
| 507 |
* </match> |
| 508 |
* </match> |
| 504 |
* ----------------------------------------------------------------------------------- |
509 |
* ----------------------------------------------------------------------------------- |
| 505 |
* and (re)-start and enable the service "resmgr" |
510 |
* otherwise remove the file /etc/hal/fdi/policy/10osvendor/80-scanner.fdi |
| 506 |
* otherwise remove the file /etc/resmgr.conf.d/50-scanner.conf |
|
|
| 507 |
* and (re)-start the service "resmgr". |
| 508 |
* Ignore whether or not an autodetected USB scanner appears in the active_scanners list |
511 |
* Ignore whether or not an autodetected USB scanner appears in the active_scanners list |
| 509 |
* (i.e. simply grant access to all autodetected USB scanners) |
512 |
* (i.e. simply grant access to all autodetected USB scanners) |
| 510 |
* because on x86_64 "scanimage -L" cannot find scanners using the 32-bit epkowa backend |
513 |
* because on x86_64 "scanimage -L" cannot find scanners using the 32-bit epkowa backend |
|
Lines 515-542
Link Here
|
| 515 |
* @return true on success |
518 |
* @return true on success |
| 516 |
*/ |
519 |
*/ |
| 517 |
boolean SetUsbScannerAccessPermissions() |
520 |
boolean SetUsbScannerAccessPermissions() |
| 518 |
{ string resmgr_scanner_config_file = "/etc/resmgr.conf.d/50-scanner.conf"; |
521 |
{ string resmgr_scanner_config_dir = "/etc/hal/fdi/policy/10osvendor"; |
|
|
522 |
string resmgr_scanner_config_file = resmgr_scanner_config_dir + "/80-scanner.fdi"; |
| 519 |
boolean autodetected_usb_scanner = false; |
523 |
boolean autodetected_usb_scanner = false; |
| 520 |
boolean autodetected_usb_scanner_with_missing_ids = false; |
524 |
boolean autodetected_usb_scanner_with_missing_ids = false; |
|
|
525 |
string content = ""; |
| 526 |
SCR::Execute (.target.mkdir, resmgr_scanner_config_dir); |
| 521 |
foreach( map< string, string > autodetected_scanner, |
527 |
foreach( map< string, string > autodetected_scanner, |
| 522 |
autodetected_scanners, |
528 |
autodetected_scanners, |
| 523 |
{ if( "USB" == autodetected_scanner["connection"]:"unknown" ) |
529 |
{ if( "USB" == autodetected_scanner["connection"]:"unknown" ) |
| 524 |
{ // There is an autodetected USB scanner. |
530 |
{ // There is an autodetected USB scanner. |
| 525 |
if( ! autodetected_usb_scanner ) |
531 |
if( ! autodetected_usb_scanner ) |
| 526 |
{ // Clear /etc/resmgr.conf.d/50-scanner.conf and write the header comment |
532 |
{ // Clear fdi file and write the header comment |
| 527 |
// only for the first autodetected USB scanner |
533 |
// only for the first autodetected USB scanner |
| 528 |
// (i.e. when autodetected_usb_scanner is still false): |
534 |
// (i.e. when autodetected_usb_scanner is still false): |
| 529 |
y2milestone( "There is an autodetected USB scanner: Setting USB Scanner Access Permissions in %1 anew.", resmgr_scanner_config_file ); |
535 |
y2milestone( "There is an autodetected USB scanner: Setting USB Scanner Access Permissions in %1 anew.", resmgr_scanner_config_file ); |
| 530 |
if( ExecuteBashCommand( "echo '# Use /usr/sbin/lsusb to create entries like:' >" + resmgr_scanner_config_file ) |
536 |
content = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> |
| 531 |
&& ExecuteBashCommand( "echo '# add usb:vendor=0x1a2b,product=0x3c4d scanner' >>" + resmgr_scanner_config_file ) |
537 |
<!-- Use /usr/sbin/lsusb to create entries like: |
| 532 |
&& ExecuteBashCommand( "echo '# to grant access to USB scanners:' >>" + resmgr_scanner_config_file ) |
538 |
<match key=\"linux.subsystem\" string=\"usb\"> |
| 533 |
) |
539 |
<match key=\"usb.vendor_id\" int=\"0x1234\"> |
| 534 |
{ y2milestone( "(Re)-created %1", resmgr_scanner_config_file ); |
540 |
<match key=\"usb.product_id\" int=\"0x5678\"> |
| 535 |
} |
541 |
<merge key=\"resmgr.class\" type=\"string\">scanner</merge> |
| 536 |
else |
542 |
</match> |
| 537 |
{ y2milestone( "Failed to (re)-create %1", resmgr_scanner_config_file ); |
543 |
</match> |
| 538 |
return false; |
544 |
</match> |
| 539 |
} |
545 |
|
|
|
546 |
to grant access to USB scanners --> |
| 547 |
|
| 548 |
<deviceinfo version=\"0.2\"> |
| 549 |
<device> |
| 550 |
"; |
| 540 |
} |
551 |
} |
| 541 |
autodetected_usb_scanner = true; |
552 |
autodetected_usb_scanner = true; |
| 542 |
string usb_vendor_id = autodetected_scanner["usb_vendor_id"]:""; |
553 |
string usb_vendor_id = autodetected_scanner["usb_vendor_id"]:""; |
|
Lines 551-599
Link Here
|
| 551 |
} |
562 |
} |
| 552 |
else |
563 |
else |
| 553 |
{ // USB vendor ID and USB product ID exist: |
564 |
{ // USB vendor ID and USB product ID exist: |
| 554 |
string resmgr_entry = "add usb:" + "vendor=" + usb_vendor_id + ",product=" + usb_product_id + " scanner"; |
565 |
content = content + sformat(" |
| 555 |
if( ! ExecuteBashCommand( "echo '" + resmgr_entry + "' >>" + resmgr_scanner_config_file ) ) |
566 |
<match key=\"linux.subsystem\" string=\"usb\"> |
| 556 |
{ y2milestone( "Failed to write '%1' into %2", resmgr_entry, resmgr_scanner_config_file ); |
567 |
<match key=\"usb.vendor_id\" int=\"%1\"> |
| 557 |
return false; |
568 |
<match key=\"usb.product_id\" int=\"%2\"> |
| 558 |
} |
569 |
<merge key=\"resmgr.class\" type=\"string\">scanner</merge> |
| 559 |
else |
570 |
</match> |
| 560 |
{ y2milestone( "Wrote '%1' into %2", resmgr_entry, resmgr_scanner_config_file ); |
571 |
</match> |
| 561 |
} |
572 |
</match> |
|
|
573 |
", usb_vendor_id, usb_product_id); |
| 562 |
} |
574 |
} |
| 563 |
} |
575 |
} |
| 564 |
} |
576 |
} |
| 565 |
); |
577 |
); |
| 566 |
if( autodetected_usb_scanner ) |
578 |
|
| 567 |
{ // If there is an autodetected USB scanner, |
579 |
if(content != "") |
| 568 |
// /etc/resmgr.conf.d/50-scanner.conf was (re)-created in any case |
580 |
{ |
| 569 |
// so that resmgr must be (re)-started and enabled: |
581 |
content = content + " </device>\n</deviceinfo>\n"; |
| 570 |
if( ! Service::Restart( "resmgr" ) ) |
582 |
if((boolean)SCR::Write(.target.string, resmgr_scanner_config_file, content)) |
| 571 |
{ y2milestone( "Service::Restart('resmgr') failed." ); |
583 |
{ |
| 572 |
return false; |
584 |
y2milestone( "(Re)-created %1", resmgr_scanner_config_file ); |
| 573 |
} |
585 |
} |
| 574 |
if( ! Service::Enable( "resmgr" ) ) |
586 |
else |
| 575 |
{ y2milestone( "Service::Enable('resmgr') failed." ); |
587 |
{ |
|
|
588 |
y2milestone( "Failed to (re)-create %1", resmgr_scanner_config_file ); |
| 589 |
// displayed in error dialog (%1 is a filename) |
| 590 |
bash_result["stderr"] = sformat(_("can't write file %1"), resmgr_scanner_config_file); |
| 576 |
return false; |
591 |
return false; |
| 577 |
} |
592 |
} |
| 578 |
y2milestone( "Service resmgr (re)-started and enabled." ); |
|
|
| 579 |
if( autodetected_usb_scanner_with_missing_ids ) |
| 580 |
{ return false; |
| 581 |
} |
| 582 |
return true; |
| 583 |
} |
593 |
} |
| 584 |
else |
594 |
if( !autodetected_usb_scanner && |
| 585 |
{ if( ! ExecuteBashCommand( "rm -f " + resmgr_scanner_config_file ) ) |
595 |
(boolean)SCR::Execute(.target.remove, resmgr_scanner_config_file) != true ) |
| 586 |
{ y2milestone( "Failed to remove %1", resmgr_scanner_config_file ); |
596 |
{ y2milestone( "Failed to remove %1", resmgr_scanner_config_file ); |
| 587 |
return false; |
597 |
// displayed in error dialog (%1 is a filename) |
| 588 |
} |
598 |
bash_result["stderr"] = sformat(_("can't remove file %1"), resmgr_scanner_config_file); |
| 589 |
y2milestone( "Removed %1 (using 'rm -f').", resmgr_scanner_config_file ); |
599 |
return false; |
| 590 |
if( ! Service::Restart( "resmgr" ) ) |
|
|
| 591 |
{ y2milestone( "Service::Restart('resmgr') failed." ); |
| 592 |
return false; |
| 593 |
} |
| 594 |
y2milestone( "Service resmgr (re)-started." ); |
| 595 |
return true; |
| 596 |
} |
600 |
} |
|
|
601 |
return true; |
| 597 |
} |
602 |
} |
| 598 |
|
603 |
|
| 599 |
/** |
604 |
/** |