Monday, November 22, 2010

Part III - Cups and Windows Drivers - Automagically delicious!

Primer

Wow, this one has been a long time in coming. Call it lack of motivation,
writing 3 other blog posts, or I realized just how much of a PITA it is
to actually get this up and running. Either way, here you go.

Part III focuses on being able to connect to your cups server via samba,
and have the samba/cups server automatically push out the necessary drivers
for your printer. Once again, keep in mind that this was done on an
ubuntu/debian server; so mileage may vary.

First thing you want to do is install the necessary packages to get samba
installed and configured properly. There are plenty of GUI tools out there
to help you setup samba (swat, and some gui utility to setup samba from gnome
are two that come to mind). But alas, it's easier for me to know what actually
goes into a configuration file if I do it from the command line and edit
the smb.conf file. So that's what I'll be doing here in this blog post.

So, first things first: install samba and other necessary apps:

a. apt-get install samba samba-common samba-common-bin
b. download the cups windows drivers from cup's web page
1. wget http://www.cups.org/software.php?VERSION=1.4.5&FILE=cups/windows/cups-windows-6.0-source.tar.gz

Configuring Samba and Cups Services

Once samba is installed, time to play with the configuration, navigate to
/etc/samba/ and open up smb.conf
1. vim /etc/samba/smb.conf

Now, because my network may be slightly different than yours, I will
pastebin what my smb.conf file looks like; the main thing to worry about
is the print share, this is where samba and cups talk to each other about
the necessary printer drivers and whatnot. I know at first glance, it may
look like there are two printer shares, but one is for the window's printers
to view the printers, and the other is print$ that talks to cups. Both very necessary pieces of information.

Pastebin of smb.conf:
http://www.pastebin.ca/1999380


Once you have successfully setup smb, and tested with: testparm /etc/samba/smb.conf
then it's time to move on to the next step.

** Side Note: I have read on the internet that the following lines should
be put into your /etc/cups/cupsd.conf file, but have found for whatever
reason that it's not necessary on the setup that I use, but if your having
problems printing; you might want to add these lines into your cupds.conf file


mime.convs:
application/octet-stream application/vnd.cups-raw 0 -

mime.types:
application/octet-stream




After you have setup smb.conf file, there are a few more steps necessary
to get samba to play nice with your printers


a) mkdir -m 777 /var/spool/samba
b) Create a samba user, you can use root, or another use
1) smbpasswd -a root

Get Windows print drivers & Install the cups/samba magic

A) Extract/Build Windows Cups drivers


Okay, I assume you went out and downloaded the Cups drivers (see Introduction); and you followed my steps in
Part 1 of this (putting the proper .ppd file in place for your printer) Now you
need to build the necessary drivers for cups/windows magic.


a) cd to the download directory where you put the cups-windows-source
b) extract the file
  1) tar zxvf cups-windows-6.0-source.tar.gz
c) Navigate to your new directory
  1) cd cups-windows-6.0
d) build packages
  make install


When you run make install, you should see something simliar to this:
Creating directory /usr/share/cups/drivers...
Installing cups6.inf...
Installing cups6.ini...
Installing cupsps6.dll...
Installing cupsui6.dll...


B) Retrieve Windows postscript files from a Windows machine


Now here comes the tricky part. In the past you were able to just get adobe postscript files and use these to generate what was
needed for cups to frolic hand in hand with Windows Operating Systems. Now, through much searching, I have been unable to locate
a valid download from adobe that would work with my Windows 7 machine. So we have to go about this the hard way. Was there ever
really an easy way to this? I mean come-on, this is a 3-part series.


1. As I said, this is the tricky part; the easiest way I found (on both windows vista, 7 and xp) was to find a printer in add/remove
printers that used postscript drivers, and was somewhat similar to the printer that I was going to be using (not necessary, force of
habit no doubt). Once this 'fake' printer was installed, I did a search for the files that I would need for adding to the cups server.


Windows 7/Vista/XP:
cups6.ini
cupsps6.dll
cupsui6.dll
ps5ui.dll
pscript5.dll
pscript.hlp
pscript.ntf



2. Once you have located ALL of these files; scp them over to /usr/share/cups/drivers on the cups server; make sure that they are all lowercase.



And now the magic begins. Before you begin this next step, make sure you created a samba user as outlined earlier. Also, you need to edit your /etc/samba/smb.conf
and modify security = share, to security = user for this next step. Don't forget to change it back to 'security = share' once you have completed this step, or restarting
samba for the changes to take effect.



**Note - I also found through various research, if you have more than 1 samba server on your network, you need to bring the one you are working on, network interface down
(ifconfig dev down) for the duration of the next few steps.



C) Run the following commands to export cups drivers


1. cupsaddsmb -H localhost -U root -a -v
2. At this point, enter your password, if all is good..you should see a whole boatload of data coming across your screen (hopefully all good) talking about
grabbing the PPD file for your printer (see Part 1) and adding all sorts of cups/samba magic to make everything work.

Once this is complete, DON'T FORGET to change 'security = user' back to 'security = share' or your going to have some problems when it comes to adding printers

** Note - I found that you need to get necessary windows files as separate entities for 32bit and 64bit OS's. So if you have both a 32bit windows host and a 64bit windows host;
you need to get the same dll's (and other files as illustrated above) and run the cupsaddsmb command against both (just put the in different directories prior to running cupsaddsmb)




Testing Out



Final test, and a quick one at that. Fire up your windows client. Now you have two options, you can either add the printer through the add printer wizard, or via \\hostname\printers.
Either one should automagically show the printer in question, allowing you to add the printer to your windows client without having to add print drivers.



Now my reasoning behind this? Well if you really got this far in the blogpost; then I'm sure your curious just why I went through all of this just for a print server at the house.
Well, between work laptops, friends and family that come visit, and odd-ball machines that I tend to work on; it's easier and much less stressful for people that want to print, to
just browse the print share and add the printer; rather than me hunting down my Driver CD and hoping it's compatible with whatever flavor of windows that currently resides
on someone's computer. That and it gets away from installing all of the unnecessary 'junk' that most of the printer CD's come with; when all the person want's to do is print
out a page or two from a website.

Anyway, that concludes part III of Samba and Cups. Holy crap, I realize it took forever (and 2 other blog posts) but as you can see, it was a large work in progress, documenting every one of
my little steps along the way.

Wednesday, November 10, 2010

Paranoid Penguin - Information hidden inside of EXIF tagged images

So, this blog actually came about because of the newest 200th edition of @LinuxJournal. The article from LJ had something to do with what you use linux for. Option #51 was "Delete all the GPS location date from Images". Well, I saw that and got to thinking about how many people don't realize that GPS (among other information) is stored inside of an EXIF tagged image (JPEG, TIFF). Alas! a blog post on the very subject was born.

About EXIF


EXIF (exchangeable image file format) was created as a camera specification in 1998 and used by various camera manufactures (and now camera phones) to ‘tag’ image information including, but not limited to: Date and Time stamps, Camera settings, thumbnails, Descriptions and now GPS information. During my testing of EXIF data, I found that images taken with a camera had the following information by default:
* Camera Settings (Exposure, lens used, ISO, Make/Model, Sometimes the SN of the Camera and/or Lens, and Manufacturers information.
Images taken with a Camera phone usually had the above information, but included the phones make/model, Software version and GPS ‘tag’ of the image itself.

Concerns


What I believe is that some users of camera phone’s (as reflected by some example data that I had collected from images for this blog) have no clue just what is stored on their images when they upload that ‘awesome image of my new big screen TV at home’. So as to the title of this blog, paranoid penguin; I will be talking about just how much data is stored on those twitpic/facebook/lmnop image’s that people store. I think a main concern about these images is not only the Make/Model/SW Version of the phone being tagged in EXIF image’s (can you say phone exploits?) but also people that have inadvertently enabled GPS tagging of their images without realizing it. I’m pretty sure the guy who took an image of all his pot, didn’t want a GPS location tagged to his picture he uploaded!

Real-World Examples of Data Collected


As I stated earlier, I began this blog; curious about just how much information people inadvertently put out when they submit images. Because of this, I picked one of the most used image sharing sites for twitter, twitpic. I figured that people snap images of all sorts of strange stuff, and ‘tweet’ it to the world. For this test, I selected 9 random topics to search for; so that I wasn’t limiting myself to ‘latest images’. From those 9 random topics, I picked 10 random images for a total of 90 images. Below, is a table of information that I found relevant to this post.

Totals:
Total Images = 90
Total EXIF Images = 36
GPS Enabled Images = 14
Phones = 28
Camera’s = 8

Percentages:

% of Images w/ EXIF Data = 40%
% of GPS EXIF Images = 50%
% of Phones = 77%
% of Camera’s = 23%

So, in a nutshell, almost half of the images uploaded to twitpic had useful EXIF data, and out of those; HALF, yes HALF of those images had GPS information on it. And like I said earlier; I’m pretty sure the author didn’t really want to broadcast to the world where they took that picture within 15meters (GPS). This can only be explained by the lack of knowledge when it comes to enabling/disabling GPS tagging of images.

Software to read EXIF Data

There is actually an excellent set of software that read’s EXIF (among other image tagged) data. I have used this application for many years to not only strip data that I didn’t want published, but also to read Date/Time stamps of images where I had taken a picture and couldn’t remember when I took it (family photo album). This tool is ExifTool, created by Phil Harvey. You can find information, and download the utility from here: http://www.sno.phy.queensu.ca/~phil/exiftool/

*If you just want to read EXIF data from firefox, there is an excellent plugin called ‘Exif Viewer’. Simple to use, just right-click on an image and view EXIF tag.

Okay, so lets get to installing-configuring this beast, if you don’t have a package manager of your choice (fedora seems to be: perl-Image-ExifTool, debian shows the package as libimage-exiftool-perl). Then you need to go to http://www.sno.phy.queensu.ca/~phil/exiftool/ and download, perl make, make install the package. Once you have successfully installed the exiftool utility; navigate to your favorite directory of photos.

Viewing Image data


Now, because exiftool’s help file is miles long, there are all sorts of different way’s to view whatever you want to with this utility. And because there are different ways to view this data, I will just tell you what I use to view the most data; you can read the help file later and tailor it to your specific needs.

1. From the directory of your photos execute the following:
exiftool -a -u -g1 filename.extension

What the switches do is the following:
-a = allow duplicate tag names in output
-u = extract unknown tags
-g1 = Organize output by tag group
And there you have it, once you execute the exiftool application, you should see all sorts of information from your photo (provided it’s a .jpg or .tiff image, and there is EXIF data to view).


Deleting EXIF Data


So what about all that pesky GPS data? Now that you have gone through all your photos and realized that some of those images that you took, probably shouldn’t have been tagged with GPS data; now what? Well, that’s where exiftool comes in with a simple one-liner, you can remove your GPS tagged data from both images or directories with the following command:
exiftool -geotag= file-or-directory-name
or
exiftool -a -gps:all -file-or-directory-name

-geotag will remove the Geotagged information (as some cellphones put it into a geotag container) but -a -gps:all will remove all GPS information. By running exiftool -a -u -g1 filename.extension after executing your gps removal switch, you can verify that the data has been removed successfully.

Tada! that’s it, now your images have been successfully purged of GPS tagging. But what about other stuff? What if you don’t want someone to know just what kind of phone you are using? After all, we can’t be too paranoid when it comes to paranoid penguins and security.
exiftool -Make= -Model= file-or-directory-name

Are you starting to see a pattern here? By adding a - to the beginning of what you want to delete and/or modify, you change the exif information. For instance, if you wanted to change the make and model (thus further confusing people, no other real purpose); you would do the following:
exiftool -Make=Ford -Model=Mustang file-or-directory-name

And now your image was taken with a Ford Mustang. As you can see, it’s pretty easy to modify and remove information in an EXIF tagged image.

Modify GPS Tagged image


Not only can we delete sensitive information from an image, but we can also modify it. What purpose does this serve? I honestly see no reason to modify GPS data in an EXIF image, other than for giggles. In the past, I have modified information tagged in EXIF format such as date/time stamping (sometimes copying over images from my old blackberry would re-stamp the image, thus screwing with my online family photo album); and other information that I felt was incorrect.

But what if you really want to mess around? How about this one?
exiftool -exif:gpslatitude=”-62.383333” filename.jpg
exiftool -exif:gpslongitude="-58.45" filename.jpg


With this little change, your summer vacation photos appear to have been taken on the northern peninsula in Antarctica. There are all sorts of things you can do with modifying GPS data. Now with being paranoid aside, you can actually use this to later on ‘tag’ your images from vacation, so that you can add valid GPS information to your pictures.

Conclusion

So, as you can see; there is all sorts of information tagged in jpg/tiff photos that you put up on the internet. Some people are aware, and embrace the ability to geotag every image that they take; and yet some people probably had no clue that their images were being tagged with ‘sensitive’ information when they uploaded their latest images to various social media sites.