URI special character substitution buggy
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
system-config-printer (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
Binary package hint: system-
I'm running freshly upgraded (as of April 9, 2007) edgy with system-
E [09/Apr/
ILURE
E [09/Apr/
E [09/Apr/
E [09/Apr/
ILURE
E [09/Apr/
NIED)
E [09/Apr/
ry in 60 seconds...
Looking in the /etc/cupsys/
DeviceURI smb://domain%
Instead it looks like:
DeviceURI smb://domain%
Note that "%5Cu" has been replaced by "%5D". "%5C" is the URI encoding of '\'; the Windows stuff here wants "domain\username" as the username. The '\' is replaced by the next ASCII keycode, and the following character is overwritten. The cool bit is that if you repeatedly open up the "Change" dialog next to the Device URI field, the character keeps mutating by 1. Awesome!
The URI coding/decoding done with some throwaway local functions, percentEncode and percentDecode. I replaced it with urllib.quote and urllib.unquote and now the URI looks to be saved correctly. I still can't get authorized for some other reason (bug? misconfiguration?) but at least the configuration file is not obviously wrong anymore. Patch below. Don't forget to add a dependency on urllib.
--- /usr/share/
+++ /usr/share/
@@ -47,7 +47,7 @@
from cupsd import CupsConfig
import probe_printer
import gtk_label_autowrap
-
+import urllib
domain=
import locale
@@ -63,44 +63,6 @@
busy_cursor = gtk.gdk.
ready_cursor = gtk.gdk.
-def percentEncode (text):
- """Percent-encode ASCII text ready for inclusion in a URI."""
- l = len (text)
- i = 0
- while i < l:
- c = text[i]
- a = ord (c)
- if (a <= 0x1f or a == 0x7f or
- c == ' ' or
- '<>#%"'.find (c) != -1 or
- '{}|\^[]`'.find (c) != -1):
- pre = text[:i]
- post = text[i + 1:]
- text = pre + "%" + ("%2X" % a) + post
- i += 2
- l += 2
- i += 1
- return text
-
-def percentDecode (text):
- """Percent-decode URI text to ASCII."""
- l = len (text)
- r = 0
- w = ''
- xdigs = "01234567890abcdef"
- while r < l:
- if r + 2 < l and text[r] == '%':
- c10 = xdigs.find (text[r + 1].lower ())
- if c10 != -1:
- c01 = xdigs.find (text[r + 2].lower ())
- if c01 != -1:
- w += chr (c10 * 0x10 + c01)
- r += 3
- else:
- w += text[r]
- r += 1
- return w
-
class GUI:
def __init__(self):
@@ -1874,16 +1836,16 @@
share = uri
return (group, host, share,
- percentDecode (user), percentDecode (password))
+ urllib.unquote (user), urllib.unquote (password))
def construct_SMBURI (self, group, host, share,
if password:
- uri_password = ':' + percentEncode (password)
+ uri_password = ':' + urllib.quote (password)
if user:
- return "%s%s%s/%s/%s" % (percentEncode (user),
+ return "%s%s%s/%s/%s" % (urllib.quote (user),
def on_entSMBURI_
And ironically, I got it working by replacing the "%5C" with a plain '\' in the URI definition. For username "domain\username", this works:
DeviceURI smb://domain\ username: password@ /hostname/ queuename
I'm guessing that the URL quoting should only be done on part of the URI, not the part including the username and password.