Tuesday, November 14, 2006

Windows Printer on Linux

I'm a Ubuntu user but I also run a number of Windows machines for work purposes. I was actually shocked recently to discover that CUPS supports my Brother HL-5140 laser printer without me having to download any binary blobs from the Brother website. So that's good.

What's not so great is that gnome-cups-ui has no concept of workgroups or domains for connecting via smb to a windows printer. When you go to "add new printer" or when you view the connection properties after adding the new printer, the fields you are presented with are:

  • Host
  • Printer
  • Username
  • Password

After googling for a bit, I discovered that people have figured out that if you put the workgroup name in the Host field and then enter username:password@host/Printer into the Printer field and nothing into either the username or password fields, you can print!

Curious about this obscurity, I did an apt-get source gnome-cups-ui and hunted around for a bit. Eventually, I found some code that looks basically like this:

if (username != NULL && username[0] && password != NULL && password[0])
ret = g_strdup_printf("smb://%s:%s@%s/%s", username, password, host, printer);
else
ret = g_strdup_printf("smb://%s/%s", host, printer);

do you see what's happening? The hack outlined above uses the second case. An alternative would be to enter workgroup/username into the Username field and your password into the password field, that would use the first case. The problem with doing that, however, is that if you don't enter a password then the username will be ignored.. this isn't much good if you're trying to use the Guest account, which requires no password. Also, even if you're using a real account, the resulting URI won't parse correctly so when you refresh the connection properties you'll end up with the workgroup in the Host field and everything else (including your password) in the Printer field.

I wrote myself a nice little patch to ask for a workgroup and parse the uri correctly, etc. If anyone wants it, you can grab it from here:

gnome-cups-manager-0.31-with-workgroup.diff

However, turns out this has already been fixed in the latest CVS, so I won't be contacting the authors. Kinda makes me wonder how long it takes for fixes like this to filter out of CVS and into the distributions. Ubuntu releases are tied to the GNOME releases, so it should be one of the fastest to get fixes like this, but this is still broken in the latest Ubuntu release (Edgy).

2 comments:

  1. Honestly, this is a distro based on Debian. Of course there's going to be old releases - Debian are incredibly slow in updating their repositories, and since Ubuntu is based on the testing branch (so I've heard) it's no surprise.

    ReplyDelete
  2. All the files in /tmp will be deleted every time the router rebooted. Remember to download printer firmware again if you don't have external storage media. In case you have an USB hub and an USB flash stick mounted under /opt, you can have second copy of firmware on the USB stick:

    ReplyDelete