pam_usb-0.5.0/0000755000175000001440000000000011553700122012031 5ustar scoxuserspam_usb-0.5.0/tools/0000755000175000001440000000000011553677177013220 5ustar scoxuserspam_usb-0.5.0/tools/pamusb-agent0000755000175000001440000001323211553677177015532 0ustar scoxusers#!/usr/bin/env python # # Copyright (c) 2003-2007 Andrea Luzzardi # # This file is part of the pam_usb project. pam_usb is free software; # you can redistribute it and/or modify it under the terms of the GNU General # Public License version 2, as published by the Free Software Foundation. # # pam_usb is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., 59 Temple # Place, Suite 330, Boston, MA 02111-1307 USA import os import sys import pwd import getopt import syslog import gobject import dbus if getattr(dbus, 'version', (0,0,0)) >= (0,41,0): import dbus.glib try: # Python 2.5 import xml.etree.ElementTree as et except ImportError: # Python 2.4 try: import cElementTree as et except ImportError: import elementtree.ElementTree as et class HotPlugDevice: def __init__(self, serial): self.__udi = None self.__serial = serial self.__callbacks = [] self.__bus = dbus.SystemBus() self.__running = False def run(self): self.__scanDevices() self.__registerSignals() self.__running = True gobject.MainLoop().run() print 'signals registered' def addCallback(self, callback): self.__callbacks.append(callback) def __scanDevices(self): halService = self.__bus.get_object('org.freedesktop.UDisks', '/org/freedesktop/UDisks') halManager = dbus.Interface(halService, 'org.freedesktop.UDisks') for udi in halManager.EnumerateDevices(): self.__deviceAdded(udi) def __registerSignals(self): halService = self.__bus.get_object('org.freedesktop.UDisks', '/org/freedesktop/UDisks') halManager = dbus.Interface(halService, 'org.freedesktop.UDisks') for signal, callback in (('DeviceAdded', self.__deviceAdded), ('DeviceRemoved', self.__deviceRemoved)): halManager.connect_to_signal(signal, callback) def __deviceAdded(self, udi): if self.__udi is not None: return deviceObj = self.__bus.get_object('org.freedesktop.UDisks', udi) deviceProperties = dbus.Interface(deviceObj, dbus.PROPERTIES_IFACE) if deviceProperties.Get('org.freedesktop.UDisks.Device', 'DriveSerial') != self.__serial: return self.__udi = udi if self.__running: [ cb('added') for cb in self.__callbacks ] def __deviceRemoved(self, udi): if self.__udi is None: return if self.__udi != udi: return self.__udi = None if self.__running: [ cb('removed') for cb in self.__callbacks ] class Log: def __init__(self): syslog.openlog('pamusb-agent', syslog.LOG_PID | syslog.LOG_PERROR, syslog.LOG_AUTH) def info(self, message): self.__logMessage(syslog.LOG_NOTICE, message) def error(self, message): self.__logMessage(syslog.LOG_ERR, message) def __logMessage(self, priority, message): syslog.syslog(priority, message) def usage(): print 'Usage: %s [--help] [--config=path] [--daemon] [--check=path]' % \ os.path.basename(__file__) sys.exit(1) import getopt try: opts, args = getopt.getopt(sys.argv[1:], "hc:dc:", ["help", "config=", "daemon", "check="]) except getopt.GetoptError: usage() options = {'configFile' : '/etc/pamusb.conf', 'daemon' : False, 'check' : '/usr/bin/pamusb-check'} if len(args) != 0: usage() for o, a in opts: if o in ('-h', '--help'): usage() if o in ('-c', '--config'): options['configFile'] = a if o in ('-d', '--daemon'): options['daemon'] = True if o in ('-c', '--check'): options['check'] = a if not os.path.exists(options['check']): print '%s not found.' % options['check'] print "You might specify manually pamusb-check's location using --check." usage() username = pwd.getpwuid(os.getuid())[0] logger = Log() doc = et.parse(options['configFile']) users = doc.findall('users/user') for user in users: if user.get('id') == username: break else: logger.error('User %s not found in configuration file' % username) sys.exit(1) events = { 'lock' : [], 'unlock' : [] } for hotplug in user.findall('agent'): events[hotplug.get('event')].append(hotplug.text) deviceName = user.find('device').text.strip() devices = doc.findall("devices/device") for device in devices: if device.get('id') == deviceName: break else: logger.error('Device %s not found in configurtion file' % deviceName) sys.exit(1) serial = device.find('serial').text.strip() def authChangeCallback(event): if event == 'removed': logger.info('Device "%s" has been removed, ' \ 'locking down user "%s"...' % (deviceName, username)) for cmd in events['lock']: logger.info('Running "%s"' % cmd) os.system(cmd) logger.info('Locked.') return logger.info('Device "%s" has been inserted. ' \ 'Performing verification...' % deviceName) cmdLine = "%s --quiet --config=%s --service=pamusb-agent %s" % ( options['check'], options['configFile'], username) logger.info('Executing "%s"' % cmdLine) if not os.system(cmdLine): logger.info('Authentication succeeded. ' \ 'Unlocking user "%s"...' % username) for cmd in events['unlock']: logger.info('Running "%s"' % cmd) os.system(cmd) logger.info('Unlocked.') else: logger.info('Authentication failed for device %s. ' \ 'Keeping user "%s" locked down.' % (deviceName, username)) hpDev = HotPlugDevice(serial) hpDev.addCallback(authChangeCallback) if options['daemon'] and os.fork(): sys.exit(0) logger.info('pamusb-agent up and running.') logger.info('Watching device "%s" for user "%s"' % (deviceName, username)) try: hpDev.run() except KeyboardInterrupt: logger.error('Caught keyboard interruption, exiting...') pam_usb-0.5.0/tools/pamusb-conf0000755000175000001440000001734611553677177015373 0ustar scoxusers#!/usr/bin/env python # # Copyright (c) 2003-2007 Andrea Luzzardi # # This file is part of the pam_usb project. pam_usb is free software; # you can redistribute it and/or modify it under the terms of the GNU General # Public License version 2, as published by the Free Software Foundation. # # pam_usb is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., 59 Temple # Place, Suite 330, Boston, MA 02111-1307 USA import dbus import sys import os from xml.dom import minidom class Device: def __init__(self, udi): self.__udi = udi deviceObj = bus.get_object('org.freedesktop.UDisks', udi) deviceProperties = dbus.Interface(deviceObj, dbus.PROPERTIES_IFACE) if deviceProperties.Get('org.freedesktop.UDisks.Device', 'DeviceIsRemovable') != 1: raise Exception, 'Not a removable device' self.vendor = deviceProperties.Get('org.freedesktop.UDisks.Device', 'DriveVendor') self.product = deviceProperties.Get('org.freedesktop.UDisks.Device', 'DriveModel') self.serialNumber = deviceProperties.Get('org.freedesktop.UDisks.Device', 'DriveSerial') if len(self.volumes()) < 1: raise Exception, 'Device does not contain any volume' def volumes(self): vols = [] for udi in halManager.get_dbus_method('EnumerateDevices')(): deviceObj = bus.get_object('org.freedesktop.UDisks', udi) deviceProperties = dbus.Interface(deviceObj, dbus.PROPERTIES_IFACE) if deviceProperties.Get('org.freedesktop.UDisks.Device', 'DeviceIsPartition') != 1: continue if deviceProperties.Get('org.freedesktop.UDisks.Device', 'PartitionSlave') != self.__udi: continue vols.append({'uuid' : deviceProperties.Get('org.freedesktop.UDisks.Device', 'IdUuid'), 'device' : deviceProperties.Get('org.freedesktop.UDisks.Device', 'DeviceFile')}) return vols def __repr__(self): if self.product is not None: return "%s %s (%s)" % (self.vendor, self.product, self.serialNumber) return self.serialNumber def listOptions(question, options, autodetect = True): if autodetect == True and len(options) == 1: print question print "* Using \"%s\" (only option)" % options[0] print return 0 while True: try: print question for i in range(len(options)): print "%d) %s" % (i, options[i]) print sys.stdout.write('[%s-%s]: ' % (0, len(options) - 1)) optionId = int(sys.stdin.readline()) print if optionId not in range(len(options)): raise Exception return optionId except KeyboardInterrupt: sys.exit() except Exception: pass else: break def writeConf(options, doc): try: f = open(options['configFile'], 'w') doc.writexml(f) f.close() except Exception, err: print 'Unable to save %s: %s' % (options['configFile'], err) sys.exit(1) else: print 'Done.' def shouldSave(options, items): print "\n".join(["%s\t\t: %s" % item for item in items]) print print 'Save to %s ?' % options['configFile'] sys.stdout.write('[Y/n] ') response = sys.stdin.readline().strip() if len(response) > 0 and response.lower() != 'y': sys.exit(1) def prettifyElement(element): tmp = minidom.parseString(element.toprettyxml()) return tmp.lastChild def addUser(options): try: doc = minidom.parse(options['configFile']) except Exception, err: print 'Unable to read %s: %s' % (options['configFile'], err) sys.exit(1) devSection = doc.getElementsByTagName('devices') if len(devSection) == 0: print 'Malformed configuration file: No section found.' sys.exit(1) devicesObj = devSection[0].getElementsByTagName('device') if len(devicesObj) == 0: print 'No devices found.' print 'You must add a device (--add-device) before adding users' sys.exit(1) devices = [] for device in devicesObj: devices.append(device.getAttribute('id')) device = devices[listOptions("Which device would you like to use for authentication ?", devices)] shouldSave(options, [ ('User', options['userName']), ('Device', device) ]) users = doc.getElementsByTagName('users') user = doc.createElement('user') user.attributes['id'] = options['userName'] e = doc.createElement('device') t = doc.createTextNode(device) e.appendChild(t) user.appendChild(e) users[0].appendChild(prettifyElement(user)) writeConf(options, doc) def addDevice(options): devices = [] for udi in halManager.get_dbus_method('EnumerateDevices')(): try: if options['verbose']: print 'Inspecting %s' % udi devices.append(Device(udi)) except Exception, ex: if options['verbose']: print "\tInvalid: %s" % ex pass else: if options['verbose']: print "\tValid" if len(devices) == 0: print 'No devices detected. Try running in verbose (-v) mode to see what\'s going on.' sys.exit() device = devices[listOptions("Please select the device you wish to add.", devices)] volumes = device.volumes() volume = volumes[listOptions("Which volume would you like to use for " \ "storing data ?", ["%s (UUID: %s)" % (volume['device'], volume['uuid'] or "") for volume in volumes] )] if volume['uuid'] == '': print 'WARNING: No UUID detected for device %s. One time pads will be disabled.' % volume['device'] shouldSave(options,[ ('Name', options['deviceName']), ('Vendor', device.vendor or "Unknown"), ('Model', device.product or "Unknown"), ('Serial', device.serialNumber), ('UUID', volume['uuid'] or "Unknown") ]) try: doc = minidom.parse(options['configFile']) except Exception, err: print 'Unable to read %s: %s' % (options['configFile'], err) sys.exit(1) devs = doc.getElementsByTagName('devices') dev = doc.createElement('device') dev.attributes['id'] = options['deviceName'] for name, value in (('vendor', device.vendor), ('model', device.product), ('serial', device.serialNumber), ('volume_uuid', volume['uuid'])): if value is None or value == '': continue e = doc.createElement(name) t = doc.createTextNode(value) e.appendChild(t) dev.appendChild(e) # Disable one time pads if there's no device UUID if volume['uuid'] == '': e = doc.createElement('option') e.setAttribute('name', 'one_time_pad') e.appendChild(doc.createTextNode('false')) dev.appendChild(e) devs[0].appendChild(prettifyElement(dev)) writeConf(options, doc) def usage(): print 'Usage: %s [--help] [--verbose] [--config=path] [--add-user=name | --add-device=name]' % os.path.basename(__file__) sys.exit(1) import getopt try: opts, args = getopt.getopt(sys.argv[1:], "hvd:nu:c:", ["help", "verbose", "add-device=", "add-user=", "config="]) except getopt.GetoptError: usage() if len(args) != 0: usage() options = { 'deviceName' : None, 'userName' : None, 'configFile' : '/etc/pamusb.conf', 'verbose' : False } for o, a in opts: if o in ("-h", "--help"): usage() if o in ("-v", "--verbose"): options['verbose'] = True if o in ("-d", "--add-device"): options['deviceName'] = a if o in ("-u", "--add-user"): options['userName'] = a if o in ("-c", "--config"): options['configFile'] = a if options['deviceName'] is not None and options['userName'] is not None: print 'You cannot use both --add-user and --add-device' usage() if options['deviceName'] is None and options['userName'] is None: usage() if options['deviceName'] is not None: bus = dbus.SystemBus() halService = bus.get_object('org.freedesktop.UDisks', '/org/freedesktop/UDisks') halManager = dbus.Interface(halService, 'org.freedesktop.UDisks') try: addDevice(options) except KeyboardInterrupt: sys.exit(1) if options['userName'] is not None: try: addUser(options) except KeyboardInterrupt: sys.exit(1) pam_usb-0.5.0/Makefile0000644000175000001440000000444511553677177013527 0ustar scoxusers# Set to 'yes' to include debugging informations, e.g. DEBUG=yes make -e DEBUG := no # compiler/linker options CC := gcc CFLAGS := $(CFLAGS) -Wall -fPIC `pkg-config --cflags libxml-2.0` \ `pkg-config --cflags dbus-1` LIBS := `pkg-config --libs libxml-2.0` \ `pkg-config --libs dbus-1` # common source files SRCS := src/conf.c \ src/mem.c \ src/log.c \ src/xpath.c \ src/hal.c \ src/pad.c \ src/volume.c \ src/local.c \ src/device.c OBJS := $(SRCS:.c=.o) # pam_usb PAM_USB_SRCS := src/pam.c PAM_USB_OBJS := $(PAM_USB_SRCS:.c=.o) PAM_USB := pam_usb.so PAM_USB_LDFLAGS := -shared PAM_USB_DEST := $(DESTDIR)/lib/security # pamusb-check PAMUSB_CHECK_SRCS := src/pamusb-check.c PAMUSB_CHECK_OBJS := $(PAMUSB_CHECK_SRCS:.c=.o) PAMUSB_CHECK := pamusb-check # Tools PAMUSB_CONF := pamusb-conf PAMUSB_AGENT := pamusb-agent TOOLS_DEST := $(DESTDIR)/usr/bin TOOLS_SRC := tools # Conf CONFS := doc/pamusb.conf CONFS_DEST := $(DESTDIR)/etc # Doc DOCS := doc/QUICKSTART doc/CONFIGURATION doc/UPGRADING doc/FAQ DOCS_DEST := $(DESTDIR)/usr/share/doc/pamusb # Man MANS := doc/pamusb-conf.1.gz doc/pamusb-agent.1.gz doc/pamusb-check.1.gz MANS_DEST := $(DESTDIR)/usr/share/man/man1 # Binaries RM := rm INSTALL := install MKDIR := mkdir ifeq (yes, ${DEBUG}) CFLAGS := ${CFLAGS} -ggdb endif all : $(PAM_USB) $(PAMUSB_CHECK) $(PAM_USB) : $(OBJS) $(PAM_USB_OBJS) $(CC) -o $(PAM_USB) $(PAM_USB_LDFLAGS) $(LDFLAGS) $(OBJS) $(PAM_USB_OBJS) $(LIBS) $(PAMUSB_CHECK) : $(OBJS) $(PAMUSB_CHECK_OBJS) $(CC) -o $(PAMUSB_CHECK) $(LDFLAGS) $(OBJS) $(PAMUSB_CHECK_OBJS) $(LIBS) %.o : %.c ${CC} -c ${CFLAGS} $< -o $@ clean : $(RM) -f $(PAM_USB) $(PAMUSB_CHECK) $(OBJS) $(PAMUSB_CHECK_OBJS) $(PAM_USB_OBJS) install : all $(MKDIR) -p $(CONFS_DEST) $(DOCS_DEST) $(MANS_DEST) $(TOOLS_DEST) $(PAM_USB_DEST) $(INSTALL) -m755 $(PAM_USB) $(PAM_USB_DEST) $(INSTALL) -m755 $(PAMUSB_CHECK) $(TOOLS_SRC)/$(PAMUSB_CONF) $(TOOLS_SRC)/$(PAMUSB_AGENT) $(TOOLS_DEST) $(INSTALL) -b -m644 $(CONFS) $(CONFS_DEST) $(INSTALL) -m644 $(DOCS) $(DOCS_DEST) $(INSTALL) -m644 $(MANS) $(MANS_DEST) deinstall : $(RM) -f $(PAM_USB_DEST)/$(PAM_USB) $(RM) -f $(TOOLS_DEST)/$(PAMUSB_CHECK) $(TOOLS_DEST)/$(PAMUSB_CONF) $(TOOLS_DEST)/$(PAMUSB_AGENT) $(RM) -rf $(DOCS_DEST) $(RM) -f $(MANS_DEST)/pusb_* pam_usb-0.5.0/ChangeLog0000644000175000001440000002200711553677177013633 0ustar scoxusers* 0.5.0 - Migrated the code base to UDisks. pam_usb doesn't depend on HAL anymore. - Added deny_remote option (defaults to true). If false, local login check will be disabled. - Fixed a bug in the device recognition (--add-device) * 0.4.2 - Added the pad_expiration option which tells pam_usb how often pads should be updated in order to reduce device writing. - Support for time options in the configuration parser (5s, 2h, 10m, etc) - Added the --verbose option to pamusb-conf - Added the --debug option to pamusb-check - Fixed the ElementTree import statement of pamusb-agent to work with Python 2.5. Thanks to Donald Hayward for the patch. - Fixed pamusb-conf to work without vendor and product name - Improved the device detection to work with any removable storage device. Thanks to Guillermo Antonio Amaral Bastidas for providing the patch. - Added a workaround for a DBUS bug that prevented pam_usb to work with su. https://bugs.freedesktop.org/show_bug.cgi?id=11876 - Disable log outputting if the application doesn't have any tty attached (fixes gksudo and other software). - Various minor bugfix * 0.4.1 - Fixed a security issue related to OpenSSH authentication - Fixed the quiet option (now it is really quiet) - Support for devices without vendor/model information * 0.4.0 - Both pam_usb and its tools (adm, hotplug) have been redesigned from the ground up and rewritten from scratch. - Hardware recognition is now done through HAL which provides a stable interface over kernel changes. - Certificates have been replaced by one time pads. That will prevent copies of the USB device to be used for authentication. - Device's manufacturer properties verification. pam_usb now verifies device informations (vendor, product, serial number, UUID) in the authentication process. - Configuration is now handled in a central place, the pamusb.conf configuration file. This XML file contains configuration entries for users, devices and services. - pamusb-agent (formely usbhotplug) make use of DBUS signals (sent by HAL) instead of kernel hotplugging. Also, its configuration has been merged into the pamusb.conf configuration file. - A new tool named pamusb-check has been added. It can perform authentication the way the PAM module does. It can be useful for testing and scripting purposes. * 0.3.3 - The option keypath is now splitted into local_keypath and device_keypath. - Fixed a bug that occurred when the TTY entry was empty. - pam_usb doesn't get anymore the tty name from PAM_TTY as it used to be empty on some systems. - Better defaults. The default options have been set to fit most needs, you are no longer required to use !check_device on 2.6. - Verbose mode. By default, pam_usb now prints some informations during the login process (access granted, the reason why access was refused, etc). This can be turned off using the brand new 'quiet' option. - Other small fixes. * 0.3.2 - Now pam_usb will also try to autodetect /dev/sdN devices (not just /dev/sdNX). - Fixed a bug that happened when the application using PAM didn't set PAM_TTY correctly. - Added the use_first_pass and try_first_pass options. Now if you enter your password on another PAM module (such as pam_mount or pam_ssh), pam_usb will use that password to decrypt the private key. * 0.3.1 - Lot of misc fixes (memory management, Makefiles, sanity checks, etc). I'd like to thank the PaX Team who did almost the whole job. - Added the hostname option which allows to select what hostname should be used for authentication (useful for shared public keys over lan). Thanks to Nicolas Chauvat who reported the issue, the idea and the patch for this feature. * 0.3.0 - Not much changes in this version beside a gcc fix, but the 0.2 branch reached too many new features so i wanted to name this release 0.3.0 as i should have done with 0.2.3 - Fixed a gcc 3.3 compile issue, and all related warning. I would like to thank the following guys for having reported this bug so fast: Lalande Fabrice Marco Neil Dunbar * 0.2.3 - Added the usbhotplug tool. usbhotplug is a hotplug agent that will automagically start a lock handler when the usb device is removed and an unlock handler when the usb device is plugged back in and authenticated through pam_usb. The default handlers will start xlock when the usb device is removed, and will kill it when the usb device is plugged back in and authenticated. I'd like to thank Wout Mertens as we had a couple of discussions about hotplug which helped me implementing this tool. - The parser can now understand "option" and "!option" instead of option=1 and option=-1 (e.g. debug !check_device). Thanks to Jean-Christophe JASKULA who suggested me that and provided an initial patch. - Fixed a loop bug on serial number checking. Thanks to Zs for reporting the bug and a patch to fix it. - Added the direct_open option which allows to open the private key using O_DIRECT to avoid disk caching (works only on devices that supports it). Thanks to myles who suggested me that. - Added some sanity checks here and there because it seems that the PAM API can return weird stuff from time to time. - Handling the mount point creation/remotion in a better way which seems to fix a couple of mntpoint problems. * 0.2.2 - Added the keep_mounted option, which allows to not umount the mount point once logged (useful if the gpg/ssh key is stored on there) - Fixed the mntpoint option: do not delete the directory if it's not a temporary one. - Added the support to pass multiple filesystems name with the fs= option (comma separated list). Changed the default fs to "ext2,vfat" - Added the log_file option. Takes a filename as a argument. Combined with debug=1 it can log debug messages to a file. - Not mounting the device as read-only anymore. Instead, the mount_opts option has been created. It accepts a comma separated list of mount options (accepted options are: ro,bind,sync,remount,nosuid,noexec,nodev). - Fixed an issue which made the allow_remote feature not working correctly with gdm/kdm. - Introduced the local_hosts and local_consoles options. They contain a comma separated lists of hosts and consoles allowed to log in while using allow_remote=-1 * 0.2.1 - Changed the naming method from x.y to x.y.z - pam_usb is now able to distinguish local users from remote (as in logged via ssh), and denies the authentication of non-local users. Setting allow_remote to 1 disable this feature. - Mounting is now done in read-only. - Added the missing mandatory PAM functions. * 0.2_rc2 - Workaround to make pam_usb not use /proc so it can run on Linux 2.6 By setting check_device to -1, pam_usb will neither check the device's serial number, nor if it's attached. It's not a real problem if you don't need serial number checking, but don't combine it with check_if_mounted. - Added the force_device capability. Now you can specify a device that will be mounted without going in guessing mode. If the device cannot be mounted, it'll switch back to the default guess mode. Useful if guess mode fails, if you don't want it to try several devices before getting the right one (so you can login faster), or if you want to login using a floppy disk, a cdrom or whatever you want. - Modified the serial number authentication method so now if no serial numbers are avaible on a device, it will try to use the GUID. Thanks to Damien Braillard who reported the issue, suggested a way to fix it, and provided a first patch for it. * 0.2_rc1 - Radically changed the way pam_usb authenticates the user on the system. Now it works with a pair of DSA keys. Thanks to Wout Mertens who told me that i could use a couple of SSH keys to fix the authentication issue. That gave me the idea to use a set of private/public keys. Thanks to Ilkka Mattila who helped me to find out a better way to implement the key challenge: extracting the public key was inadequate. Also thanks to those who brought up weird scenarios and/or tested pre-releases of pam_usb, in alphabetical order: Ilkka Mattila Joonas Kortesalmi Thomas Stewart Tuure Laurinolli * 0.1: - Now pam_usb doesn't require a mount point. Instead, it creates a temporary directory under /tmp. Thanks to Loic Jaquemet who gave me the idea. - Compiles with gcc 2.95 thanks to Tobias Bayer bug report. * 0.1-beta2: - procfile and device entries autodetection have been fixed thanks to Thomas Stewart bug reports. - devfs support added. Thanks to Loic Jaquemet for the bug report. * 0.1-beta1: - Initial release pam_usb-0.5.0/COPYING0000644000175000001440000004311011553677177013112 0ustar scoxusers GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. pam_usb-0.5.0/doc/0000755000175000001440000000000011553677177012625 5ustar scoxuserspam_usb-0.5.0/doc/CONFIGURATION0000644000175000001440000001731211553677177014563 0ustar scoxusers====== Configuration ====== Configuration is done through the pamusb-conf tool, as explained in the [[quickstart]] section. Most users don't have to manually change pamusb.conf, however if you want to change some default settings, this document explains the syntax of the pamusb.conf configuration file. ===== Introduction ===== * The configuration file is formatted in XML and subdivided in 4 sections: - Default options, shared among every device, user and service - Devices declaration and settings - Users declaration and settings - Services declaration and settings * The syntax is the following: * Location of the configuration file By default, pam_usb.so and its tools will look for the configuration file located in /etc/pamusb.conf, but you can tell it to use a different file by using the -c option: # /etc/pam.d/common-auth auth sufficient pam_usb.so -c /some/other/path.conf auth required pam_unix.so nullok_secure You will also have to use the -c option when calling pam_usb's tools. For instance, when calling pamusb-agent: pamusb-agent -c /some/other/path.conf ===== Options ===== ^ Name ^ Type ^ Default value ^ Description ^ | enable | Boolean | true | Enable pam_usb | | debug | Boolean | false | Enable debug messages | | quiet | Boolean | false | Quiet mode (no verbose output) | | color_log | Boolean | true | Enable colored output | | one_time_pad | Boolean | true | Enable the use of one time pads | | deny_remote | Boolean | true | Deny access from remote host (ssh) | | probe_timeout | Time | 10s | Time to wait for the volume to be detected| | pad_expiration| Time | 1h | Time between pads regeneration| | hostname | String | Computer's hostname | Computer name. Must be unique accross computers using the same device | | system_pad_directory | String | .pamusb | Relative path to the user's home used to store one time pads | | device_pad_directory | String | .pamusb | Relative path to the device used to store one time pads| * Example: ===== Devices ===== ^ Name ^ Type ^ Description ^ Example ^ | id | Attribute | Arbitrary device name | MyDevice | | vendor | Element | device's vendor name | SanDisk Corp. | | model | Element | device's model name | Cruzer Titanium | | serial | Element | serial number of the device | SNDKXXXXXXXXXXXXXXXX | | volume_uuid | Element | UUID of the device's volume used to store pads | 6F6B-42FC | * Example: SanDisk Corp. Cruzer Titanium SNDKXXXXXXXXXXXXXXXX 6F6B-42FC ===== Users ===== ^ Name ^ Type ^ Description ^ Example ^ | id | Attribute | Login of the user | root | | device | Element | id of the device associated to the user | MyDevice | | agent | Element | Agent commands, for use with pamusb-agent | See below | * Example: MyDevice gnome-screensaver-command --lock beep-media-player --pause gnome-screensaver-command --deactivate beep-media-player --play ===== Services ===== ^ Name ^ Type ^ Description ^ Example ^ | id | Attribute | Name of the service | su | ===== Full example ===== This example demonstrates how to write a pam_usb configuration file and how to combine and override options. --> --> SanDisk Corp. Cruzer Titanium SNDKXXXXXXXXXXXXXXXX 6F6B-42FC MyDevice MyDevice gnome-screensaver-command --lock gnome-screensaver-command --deactivate pam_usb-0.5.0/doc/UPGRADING0000644000175000001440000000272511553677177014076 0ustar scoxusers====== Upgrading ====== If you're already using a pam_usb version prior to 0.4.0, you will have to remove the older version before installing. You do not have to do this if you're already using >=0.4.0. ===== Remove pam_usb.so from pam.d ===== $ grep -r pam_usb.so /etc/pam.d /etc/pam.d/su:auth sufficient pam_usb.so /etc/pam.d/gdm:auth sufficient pam_usb.so [...] Edit every matching file and remove the pam_usb.so lines. At the end of the operation, there shouldn't be any file contanining a reference to pam_usb.so: $ grep -r pam_usb /etc/pam.d $ ===== Remove .auth directories ===== Older versions of pam_usb used to create .auth directories in both the device and the user's home directory. Those directories aren't used anymore, so feel free to remove them: # rm -rf /root/.auth # rm -rf /home/scox/.auth # rm -rf /media/usbdisk/.auth ===== Remove configuration files ===== As configuration files of pam_usb 0.4.0 aren't backward compatible, the old /etc/pam_usb is no more needed. # rm -rf /etc/pam_usb ===== Deinstall pam_usb ===== If you installed the old pam_usb version using your operating system's package manager, then remove it by the same mean. Otherwise, you can remove it by hand by performing the following instructions: # rm -f /usr/bin/usbadm /usr/share/man/usbadm.1.gz # rm -f /usr/bin/usbhotplug /etc/hotplug.d/default/pamusb.hotplug /etc/pam.d/usbhotplug # rm -f /lib/security/pam_usb.so ===== Next ===== Go aheand and install the new version. pam_usb-0.5.0/doc/QUICKSTART0000644000175000001440000001621511553677177014247 0ustar scoxusers====== Quickstart ====== Before going ahead, make sure to follow the upgrading instructions if you're using a version of pam_usb prior to 0.4.0. ===== Installing ==== ==== Gentoo Linux ==== # emerge -av pam_usb ==== Ubuntu and Debian ==== # apt-get install libpam-usb pamusb-tools ==== Installing from sources ==== * Step 1: Download the latest release * Step 2: Unpack the distribution tarball $ tar -zxvf pam_usb-.tar.gz $ cd pam_usb- * Step 3: Make sure that you have installed the required dependencies pam_usb depends on libxml2, PAM, udisks and pmount. pam_usb's tools (pamusb-agent, pamusb-conf) depends on python, python-celementtree and python-gobject. * Step 3: Compile and install $ make # make install ==== Installing from git ==== If you want to use the development version, you can fetch the sources from GitHub $ git clone git:github.com/aluzzardi/pam_usb.git ===== Setting up ===== ==== Devices and Users ==== * Once you've connected your USB device to the computer, use pamusb-conf to add it to the configuration file: # pamusb-conf --add-device MyDevice Please select the device you wish to add. * Using "SanDisk Corp. Cruzer Titanium (SNDKXXXXXXXXXXXXXXXX)" (only option) Which volume would you like to use for storing data ? * Using "/dev/sda1 (UUID: <6F6B-42FC>)" (only option) Name : MyDevice Vendor : SanDisk Corp. Model : Cruzer Titanium Serial : SNDKXXXXXXXXXXXXXXXX Volume UUID : 6F6B-42FC (/dev/sda1) Save to /etc/pamusb.conf ? [Y/n] y Done. Note that MyDevice can be any arbitrary name you'd like. Also, you can add as many devices as you want. * Users Now that we have added the devices, we have to configure the users. # pamusb-conf --add-user root Which device would you like to use for authentication ? * Using "MyDevice" (only option) User : root Device : MyDevice Save to /etc/pamusb.conf ? [Y/n] y Done. Repeat this step for every other username you'd like to use pam_usb with (e.g. pamusb-conf --add-user MyUsername). * In order to check if everything went fine, we are going to use the pamusb-check tool which will simulate an authentication event. # pamusb-check root * Authentication request for user "root" (pamusb-check) * Device "MyDevice" is connected (good). * Performing one time pad verification... * Verification match, updating one time pads... * Access granted. ==== PAM Module ==== The PAM module pam_usb.so is used to let applications authenticate you using your USB device instead of asking your password. The default password-based authentication will be used as fallback if the device authentication goes wrong. * Depending on the operating system you're using, you have to tell PAM to use pam_usb.so as default authentication method. There should be a file named either common-auth (Gentoo) under /etc/pam.d/. If you do NOT have neither of those files, you'll have to edit each pam.d service file you want to use (e.g. /etc/pam.d/su, /etc/pam.d/gdm and so on). * Locate the following line on /etc/pam.d/common-auth or /etc/pam.d/system-auth: auth required pam_unix.so nullok_secure * And change it to look something like that: auth sufficient pam_usb.so auth required pam_unix.so nullok_secure * You should now be able to authenticate the users configured in pamusb.conf using your USB device: scox $ su * pam_usb v.SVN * Authentication request for user "root" (su) * Device "MyDevice" is connected (good). * Performing one time pad verification... * Verification match, updating one time pads... * Access granted. * Try to authenticate to a different application. pam_usb.so should work with any application using xscreensaver and many more). ==== Agent ==== The pam_usb agent (pamusb-agent) allows you to automatically execute commands upon locking and unlocking events. Those events are generated when you insert or remove your authentication device. To configure the commands, you have to edit pam_usb's configuration file (/etc/pamusb.conf) and add agent entries into your user section. For instance, you could automatically start your screensaver as soon as you remove the device, and deactivate it when you plug the device back. * GNOME (gnome-screensaver): MyDevice gnome-screensaver-command --lock gnome-screensaver-command --deactivate * KDE (kscreensaver): MyDevice dcop kdesktop KScreensaverIface lock dcop kdesktop KScreensaverIface quit You can execute more commands by adding extra entries. $ pamusb-agent pamusb-agent[18329]: pamusb-agent up and running. pamusb-agent[18329]: Watching device "MyDevice" for user "scox" pamusb-agent[18329]: Device "MyDevice" has been removed, locking down user "scox"... pamusb-agent[18329]: Running "gnome-screensaver-command --lock" pamusb-agent[18329]: Locked. pamusb-agent[18329]: Device "MyDevice" has been inserted. Performing verification... pamusb-agent[18329]: Executing "/usr/bin/pamusb-check --quiet --config=/etc/pamusb.conf --service=pamusb-agent scox" pamusb-agent[18329]: Authentication succeeded. Unlocking user "scox"... pamusb-agent[18329]: Running "gnome-screensaver-command --deactivate" pamusb-agent[18329]: Unlocked. Depending on your desktop environment, you have to add pamusb-agent to the list of autostarted applications so it will be started automatically. * GNOME: - Open System -> Preferences -> Sessions - Select Startup Programs and press Add - Enter pamusb-agent and press OK - Press Close * KDE: - cd ~/.kde/Autostart - ln -s /usr/bin/pamusb-agent pamusb-agent ===== Troubleshooting ===== ==== Log Analysis ==== Both pam_usb.so and pamusb-agent use the syslog facility to log authentication attempts. This can be useful for GUI-driven applications (for instance GDM) where you don't get to see console output. Messages are logged with the AUTH facility, they are usually written to /var/log/auth.log but may vary depending on the operating system you're using. # tail -f /var/log/auth.log pamusb-agent[25429]: Device "sandisk" has been inserted. Performing verification... pamusb-agent[25429]: Executing "/usr/bin/pamusb-check --quiet --config=/etc/pamusb.conf --service=pamusb-agent scox" pam_usb[25485]: Authentication request for user "scox" (pamusb-agent) pam_usb[25485]: Device "sandisk" is connected (good). pam_usb[25485]: Access granted. pamusb-agent[25429]: Authentication succeeded. Unlocking user "scox"... pamusb-agent[25429]: Unlocked. ==== Enabling debug ==== Enabling debug messages may help you find out what's wrong. To enable them, edit /etc/pamusb.conf and set the following option: If you wish, you could enable debug messages only for a specific user, device or service. For instance, if you want to enable debug messages only for the sudo service, you could do the following: ===== It works - What next ? ===== * Have a look at the configuration documentation pam_usb-0.5.0/doc/FAQ0000644000175000001440000000235511553677177013164 0ustar scoxusers====== Frequently Asked Questions ====== > Q: Can I use my USB drive as usual ? >> A: Yes. pam_usb only occupies a few kilobytes of the device's space. > Q: What if I lose or break my USB key ? Will I be able to log back in ? >> A: Sure. Your usual password will be asked. > Q: How is the USB key identified ? >> A: The USB device is both identified by its manufacturer attributes (vendor, product, serial number) and by a few random bytes called one time pads that pam_usb writes and updates on the USB device upon authentication. > Q: What if someone copies the content of my flash drive ? Will she/he be able to log into my account ? >> A: Even if that person manages to fake your device's attributes (vendor, product, serial number, UUID), the one time pad they copied will be outdated as soon as you authenticate. > Q: Is my USB drive compatible with pam_usb ? >> A: About every USB flash drive will work with pam_usb. > Q: I can't authenticate anymore, pam_usb gives me the following error: Pad checking failed. What should I do ? >> A: It's a machine/device synchronization issue. To get rid of that error you have to reset the pads of your system by removing the .pamusb folder located on your home (/root/.pamusb/, /home/foobar/.pamusb/, etc). pam_usb-0.5.0/doc/pamusb-agent.1.gz0000644000175000001440000000106711553677177015715 0ustar scoxusers‹¼*èFpamusb-agent.1mRÛjÛ@}߯Ü—âuì—BiKí4Ô†&–ýPšÖ«‘´DÚ{ñ%_ßYÉNí4 4Ìœ9—á=XáÞƒÞÔÂ+)ªêj´Âc›ø½×B3¾šA#êà6A FÐK±ñXoÐÂh| ã››=èÑ“LîŸÖé´ÇOgð0¹¿cùôbú1Oï‰J€ÛX*…Î*´íLúëa‘¤ó”q3ž‹nßBü¦Ú`PbÕÐߟã¯4:W¾4—§j&°6ú¼­DùüÚÕ-YÑKµ¾ß¥·Ëy²š/Þ[¬( ²¶@09àeðJ MMveBc4 áVI¤~‡Ö+*^-‘‘ç%¡‘çÑi_ZŠòdI,QÞŠŠ3ž$,E„ÒûæÓn·ãnl1ÌŒ¶§èD„ÿPßT¡€ÜظÔÛ cÝ­.ͼa}hà]¼Õ¾he“÷«„ñ);÷ø: JúbiÄrÔÚC´À4íÎ.Cè&d4mít"Šò†®#Ø–4äªB¸Ê0¡òŽ8½uÆÞþù5È9‹ÈË ßQ#Šû6B>d¯Îø…¦Óü£H&ûv$ÞD$qDl;ßÐ Î7JÏ[ú­Óõ”% ÒërÜPc»ÑnAwúµPU<›J9ß¹?Y¯f‹%›èÌ¢€ŸáåEØLÁg'Íþ›SÅhcÿÊþ¾õu@¼pam_usb-0.5.0/doc/pamusb-check.1.gz0000644000175000001440000000156011553677177015672 0ustar scoxusers‹»*èFpamusb-check.1½UÛnÛ8}çW „k‰§ mQç‚Æ@“¨• t±) JIÄJ¤ÂK÷ëwHÆ©ìõ¾ìÃlçz8ç8M`‰Ï¸³ªçV”¼ë6РDÍ-VPlÀ>ÛÓžK–.¯aà½3ÅqÙbùÌ Éq°Ø¨avz§''¿'Ð'›ß¬WùyÂXš_ÃíüæŠÝ×çãèp‘ÿq{—勜¥²fiÍ{¸`+Ã<ƒûz1v¿¯3ø“R·Ø túñr¬°pÍè\*Y oø0pÛn­õ£(Ñ›%ïñ5Øõ!‹Ç'І\ïExϱ­%}‰ÐòåU~ñm‘-w·ì@%—`Dï:Bσڢô Z¡$ØV+×´ôÈ5ÊFHLÙ‚0@Uk×A­4Ê’'+dƒÓƒ2h`bDðÇIâÌN‡2ìIØV9 -ô±aõ¼8ÓÈ;´j4ï§GPïŒ %M©Åàë¥ÐÿÍ> Kµ*ô­ž€¨}loÈ'nÀ¸²Dch”#Zõ“0ã)Ãb½T ç–v«Ð¿V¿ú>¿É¾\åìÍ¡0¥zfé"ƒûIáà›ïv£ñÁ†a<ÿ¤ø€&ÿL5§¹ @R^VªŒóØÔA—¬EøKÞtŽ[Qàñæipû—èÝý¼É®ïi¾X-ÿãJ`ý$ÀшJz”VApy„+d¶ÆRÚS ¥hö½V}"O ‘Ó‰Ï!œjÿE²Z½€qmËôT ª e ¥½“2·!ó÷ ‚r¶svÿÆm/BøÚ‡ë•Ø¢ü°½`¾p,™k¬ñC“ ´ÅÅÉ”gcC#ÔCš$œ{„Ãͧ„ÃΆp÷ôžØlý+#iƒÌ[5(ýì*ÐØ)Ý›:’ï¿–‰&l£Æ¼“u>_Ý“Dr nÝë+Ó\À7S¨Ý¿ÎÉ„*]}'ÿ+¬m·>pam_usb-0.5.0/doc/pamusb.conf0000644000175000001440000000340211553677177014762 0ustar scoxusers pam_usb-0.5.0/README.md0000644000175000001440000000246211553677177013343 0ustar scoxuserspam\_usb provides hardware authentication for Linux using ordinary USB Flash Drives. It works with any application supporting PAM, such as _su_, any login manager (_GDM_, _KDM_), etc. The pam\_usb package contains: * A PAM Module * Password-less authentication. Use your USB stick for authentication, don't type passwords anymore. * Device auto probing.You don't need to mount the device, or even to configure the device location (_sda1_, _sdb1_, etc). pam\_usb.so will automatically locate the device using _HAL_ and access its data by itself. * Two-factor authentication. Achieve greater security by requiring both the USB stick and the password to authenticate the user. * Non-intrusive. pam\_usb doesn't require any modifications of the USB storage device to work (no additional partitions required). * USB Serial number, model and vendor verification. * Support for **One Time Pads** authentication. * You can use the same device accross multiple machines. * Support for all kind of removable devices (SD, MMC, etc). * Several tools * **pamusb-agent**: trigger actions (such as locking the screen) upon device authentication and removal. * **pamusb-conf**: configuration helper. * **pamusb-check**: integrate pam\_usb's authentication engine within your scripts or applications. pam_usb-0.5.0/src/0000755000175000001440000000000011553677177012647 5ustar scoxuserspam_usb-0.5.0/src/xpath.h0000644000175000001440000000300711553677177014144 0ustar scoxusers/* * Copyright (c) 2003-2007 Andrea Luzzardi * * This file is part of the pam_usb project. pam_usb is free software; * you can redistribute it and/or modify it under the terms of the GNU General * Public License version 2, as published by the Free Software Foundation. * * pam_usb is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef PUSB_XPATH_H_ # define PUSB_XPATH_H_ # include int pusb_xpath_get_string(xmlDocPtr doc, const char *path, char *value, size_t size); int pusb_xpath_get_string_from(xmlDocPtr doc, const char *base, const char *path, char *value, size_t size); int pusb_xpath_get_bool(xmlDocPtr doc, const char *path, int *value); int pusb_xpath_get_bool_from(xmlDocPtr doc, const char *base, const char *path, int *value); int pusb_xpath_get_time(xmlDocPtr doc, const char *path, time_t *value); int pusb_xpath_get_time_from(xmlDocPtr doc, const char *base, const char *path, time_t *value); int pusb_xpath_get_int(xmlDocPtr doc, const char *path, int *value); int pusb_xpath_get_int_from(xmlDocPtr doc, const char *base, const char *path, int *value); #endif /* !PUSB_XPATH_H_ */ pam_usb-0.5.0/src/version.h0000644000175000001440000000153711553677177014513 0ustar scoxusers/* * Copyright (c) 2003-2007 Andrea Luzzardi * * This file is part of the pam_usb project. pam_usb is free software; * you can redistribute it and/or modify it under the terms of the GNU General * Public License version 2, as published by the Free Software Foundation. * * pam_usb is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef PUSB_VERSION_H_ # define PUSB_VERSION_H_ # define PUSB_VERSION "0.5.0" #endif /* !PUSB_VERSION_H_ */ pam_usb-0.5.0/src/local.c0000644000175000001440000000352111553677177014106 0ustar scoxusers/* * Copyright (c) 2003-2007 Andrea Luzzardi * * This file is part of the pam_usb project. pam_usb is free software; * you can redistribute it and/or modify it under the terms of the GNU General * Public License version 2, as published by the Free Software Foundation. * * pam_usb is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include "log.h" #include "conf.h" int pusb_local_login(t_pusb_options *opts, const char *user) { struct utmp utsearch; struct utmp *utent; const char *from; int i; if (!opts->deny_remote) { log_debug("deny_remote is disabled. Skipping local check.\n"); return (1); } log_debug("Checking whether the caller is local or not...\n"); from = ttyname(STDIN_FILENO); if (!from || !(*from)) { log_debug("Couldn't retrieve the tty name, aborting.\n"); return (1); } if (!strncmp(from, "/dev/", strlen("/dev/"))) from += strlen("/dev/"); log_debug("Authentication request from tty %s\n", from); strncpy(utsearch.ut_line, from, sizeof(utsearch.ut_line) - 1); setutent(); utent = getutline(&utsearch); endutent(); if (!utent) { log_debug("No utmp entry found for tty \"%s\"\n", from); return (1); } for (i = 0; i < 4; ++i) { if (utent->ut_addr_v6[i] != 0) { log_error("Remote authentication request: %s\n", utent->ut_host); return (0); } } log_debug("Caller is local (good)\n"); return (1); } pam_usb-0.5.0/src/hal.c0000644000175000001440000001734711553677177013573 0ustar scoxusers/* * Copyright (c) 2003-2007 Andrea Luzzardi * * This file is part of the pam_usb project. pam_usb is free software; * you can redistribute it and/or modify it under the terms of the GNU General * Public License version 2, as published by the Free Software Foundation. * * pam_usb is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include "mem.h" #include "log.h" #include "hal.h" DBusConnection *pusb_hal_dbus_connect(void) { DBusConnection *dbus = NULL; DBusError error; dbus_error_init(&error); if (!(dbus = dbus_bus_get(DBUS_BUS_SYSTEM, &error))) { /* Workaround for https://bugs.freedesktop.org/show_bug.cgi?id=11876 */ uid_t ruid; uid_t euid; if (!(euid = geteuid()) && (ruid = getuid())) { dbus_error_free(&error); setreuid(euid, euid); dbus = dbus_bus_get(DBUS_BUS_SYSTEM, &error); setreuid(ruid, euid); } if (!dbus) { log_error("Cannot connect to system bus: %s\n", error.message); dbus_error_free(&error); return (NULL); } } return (dbus); } void pusb_hal_dbus_disconnect(DBusConnection *dbus) { dbus_connection_unref(dbus); } void pusb_hal_free_string_array(char **str_array, int length) { int i; if (str_array == NULL) return ; for (i = 0; i < length; ++i) xfree(str_array[i]); xfree(str_array); } char **pusb_hal_get_string_array_from_iter(DBusMessageIter *iter, int *num_elements) { int count; char **buffer; count = 0; buffer = (char **)xmalloc(sizeof(char *) * 8); buffer[0] = NULL; while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING || dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_OBJECT_PATH) { const char *value; if ((count % 8) == 0 && count != 0) { buffer = xrealloc(buffer, sizeof (char *) * (count + 8)); } dbus_message_iter_get_basic(iter, &value); buffer[count] = xstrdup(value); dbus_message_iter_next(iter); count++; } if (num_elements != NULL) *num_elements = count; return buffer; } DBusMessage *pusb_hal_get_raw_property(DBusConnection *dbus, const char *udi, const char *name) { DBusMessage *message; DBusMessage *reply; DBusMessageIter iter; DBusError error; char *iface = "org.freedesktop.UDisks.Device"; message = dbus_message_new_method_call("org.freedesktop.UDisks", udi, "org.freedesktop.DBus.Properties", "Get"); if (message == NULL) { log_error("Could not allocate D-BUS message\n"); return (NULL); } dbus_message_iter_init_append(message, &iter); dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &iface); dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &name); dbus_error_init(&error); reply = dbus_connection_send_with_reply_and_block(dbus, message, -1, &error); dbus_message_unref(message); if (dbus_error_is_set(&error)) { log_error("Error communicating with D-BUS\n"); return (NULL); } dbus_error_free(&error); return (reply); } char *pusb_hal_get_string_property(DBusConnection *dbus, const char *udi, const char *name) { DBusMessage *reply; DBusMessageIter reply_iter; char *data; char *dbus_str; reply = pusb_hal_get_raw_property(dbus, udi, name); if (reply == NULL) { return (NULL); } dbus_message_iter_init(reply, &reply_iter); if (dbus_message_iter_get_arg_type(&reply_iter) != DBUS_TYPE_VARIANT) { dbus_message_unref(reply); return (NULL); } DBusMessageIter subiter; dbus_message_iter_recurse(&reply_iter, &subiter); dbus_message_iter_get_basic(&subiter, &dbus_str); if (dbus_str != NULL) data = xstrdup(dbus_str); dbus_message_unref(reply); return (data); } char **pusb_hal_get_string_array_property(DBusConnection *dbus, const char *udi, const char *name, int *n_items) { DBusMessage *reply; DBusMessageIter reply_iter; char **items; reply = pusb_hal_get_raw_property(dbus, udi, name); if (reply == NULL) { return (NULL); } dbus_message_iter_init(reply, &reply_iter); if (dbus_message_iter_get_arg_type(&reply_iter) != DBUS_TYPE_VARIANT) { dbus_message_unref(reply); return (NULL); } DBusMessageIter subiter, subsubiter; dbus_message_iter_recurse(&reply_iter, &subiter); dbus_message_iter_recurse(&subiter, &subsubiter); items = pusb_hal_get_string_array_from_iter(&subsubiter, n_items); dbus_message_unref(reply); if (!*n_items) { pusb_hal_free_string_array(items, *n_items); return (NULL); } return (items); } int pusb_hal_get_bool_property(DBusConnection *dbus, const char *udi, const char *name, dbus_bool_t *value) { DBusMessage *reply; DBusMessageIter reply_iter; reply = pusb_hal_get_raw_property(dbus, udi, name); if (reply == NULL) { return (0); } dbus_message_iter_init(reply, &reply_iter); if (dbus_message_iter_get_arg_type(&reply_iter) != DBUS_TYPE_VARIANT) { dbus_message_unref(reply); return (0); } DBusMessageIter subiter; dbus_message_iter_recurse(&reply_iter, &subiter); dbus_message_iter_get_basic(&subiter, value); dbus_message_unref(reply); return (1); } int pusb_hal_check_property(DBusConnection *dbus, const char *udi, const char *name, const char *value) { char *data; int retval; data = pusb_hal_get_string_property(dbus, udi, name); if (!data) return (0); retval = (strcmp(data, value) == 0); xfree(data); return (retval); } char **pusb_hal_find_all_items(DBusConnection *dbus, int *count) { DBusError error; DBusMessage *message; DBusMessage *reply; DBusMessageIter iter_array, reply_iter; char **devices; int n_devices; *count = 0; message = dbus_message_new_method_call("org.freedesktop.UDisks", "/org/freedesktop/UDisks", "org.freedesktop.UDisks", "EnumerateDevices"); if (message == NULL) { log_error("Couldn't allocate D-BUS message\n"); return (NULL); } dbus_error_init(&error); reply = dbus_connection_send_with_reply_and_block(dbus, message, -1, &error); dbus_message_unref(message); if (dbus_error_is_set(&error)) { log_error("Error communicating with D-BUS\n"); return (NULL); } if (reply == NULL) { return (NULL); } dbus_message_iter_init(reply, &reply_iter); if (dbus_message_iter_get_arg_type(&reply_iter) != DBUS_TYPE_ARRAY) { log_error("Malformed D-BUS reply"); return (NULL); } dbus_message_iter_recurse(&reply_iter, &iter_array); devices = pusb_hal_get_string_array_from_iter(&iter_array, &n_devices); dbus_message_unref(reply); if (!n_devices) { pusb_hal_free_string_array(devices, n_devices); return (NULL); } *count = n_devices; return (devices); } char *pusb_hal_find_item(DBusConnection *dbus, ...) { char **devices; int n_devices; char *udi = NULL; va_list ap; int i; devices = pusb_hal_find_all_items(dbus, &n_devices); if (!devices) return (NULL); if (!n_devices) return (NULL); for (i = 0; i < n_devices; ++i) { char *key = NULL; int match = 1; va_start(ap, dbus); while ((key = va_arg(ap, char *))) { char *value = NULL; value = va_arg(ap, char *); if (!value || *value == 0x0) continue ; if (!pusb_hal_check_property(dbus, devices[i], key, value)) { match = 0; break; } } if (match) { udi = xstrdup(devices[i]); break; } va_end(ap); } pusb_hal_free_string_array(devices, n_devices); return (udi); } pam_usb-0.5.0/src/mem.c0000644000175000001440000000226611553677177013577 0ustar scoxusers/* * Copyright (c) 2003-2007 Andrea Luzzardi * * This file is part of the pam_usb project. pam_usb is free software; * you can redistribute it and/or modify it under the terms of the GNU General * Public License version 2, as published by the Free Software Foundation. * * pam_usb is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include "mem.h" void *xmalloc(size_t size) { void *data = malloc(size); assert(data != NULL && "malloc() failed"); return (data); } void *xrealloc(void *ptr, size_t size) { void *data = realloc(ptr, size); assert(data != NULL && "realloc() failed"); return (data); } void xfree(void *ptr) { free(ptr); } char *xstrdup(const char *s) { char *data = strdup(s); assert(data != NULL && "strdup() failed"); return (data); } pam_usb-0.5.0/src/volume.h0000644000175000001440000000165611553677177014337 0ustar scoxusers/* * Copyright (c) 2003-2007 Andrea Luzzardi * * This file is part of the pam_usb project. pam_usb is free software; * you can redistribute it and/or modify it under the terms of the GNU General * Public License version 2, as published by the Free Software Foundation. * * pam_usb is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef VOLUME_H_ # define VOLUME_H_ # include "hal.h" char *pusb_volume_get(t_pusb_options *opts, DBusConnection *dbus); void pusb_volume_destroy(char *mntpoint); #endif /* !VOLUME_H_ */ pam_usb-0.5.0/src/device.c0000644000175000001440000000404311553677177014253 0ustar scoxusers/* * Copyright (c) 2003-2007 Andrea Luzzardi * * This file is part of the pam_usb project. pam_usb is free software; * you can redistribute it and/or modify it under the terms of the GNU General * Public License version 2, as published by the Free Software Foundation. * * pam_usb is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include "mem.h" #include "conf.h" #include "hal.h" #include "log.h" #include "pad.h" #include "device.h" static int pusb_device_connected(t_pusb_options *opts, DBusConnection *dbus) { char *udi = NULL; log_debug("Searching for \"%s\" in the hardware database...\n", opts->device.name); udi = pusb_hal_find_item(dbus, "DriveSerial", opts->device.serial, "DriveVendor", opts->device.vendor, "DriveModel", opts->device.model, NULL); if (!udi) { log_error("Device \"%s\" is not connected.\n", opts->device.name); return (0); } xfree(udi); log_info("Device \"%s\" is connected (good).\n", opts->device.name); return (1); } int pusb_device_check(t_pusb_options *opts, const char *user) { DBusConnection *dbus = NULL; int retval = 0; log_debug("Connecting to HAL...\n"); if (!(dbus = pusb_hal_dbus_connect())) return (0); if (!pusb_device_connected(opts, dbus)) { pusb_hal_dbus_disconnect(dbus); return (0); } if (opts->one_time_pad) { log_info("Performing one time pad verification...\n"); retval = pusb_pad_check(opts, dbus, user); } else { log_debug("One time pad is disabled, no more verifications to do.\n"); retval = 1; } pusb_hal_dbus_disconnect(dbus); return (retval); } pam_usb-0.5.0/src/pam.c0000644000175000001440000000524411553677177013575 0ustar scoxusers/* * Copyright (c) 2003-2007 Andrea Luzzardi * * This file is part of the pam_usb project. pam_usb is free software; * you can redistribute it and/or modify it under the terms of the GNU General * Public License version 2, as published by the Free Software Foundation. * * pam_usb is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */ #define PAM_SM_AUTH #include #include #include "version.h" #include "conf.h" #include "log.h" #include "local.h" #include "device.h" PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv) { t_pusb_options opts; const char *service; const char *user; const char *tty; char *conf_file = PUSB_CONF_FILE; int retval; pusb_log_init(&opts); retval = pam_get_item(pamh, PAM_SERVICE, (const void **)(const void *)&service); if (retval != PAM_SUCCESS) { log_error("Unable to retrieve the PAM service name.\n"); return (PAM_AUTH_ERR); } if (pam_get_user(pamh, &user, NULL) != PAM_SUCCESS || !user || !*user) { log_error("Unable to retrieve the PAM user name.\n"); return (PAM_AUTH_ERR); } if (argc > 1) if (!strcmp(argv[0], "-c")) conf_file = (char *)argv[1]; if (!pusb_conf_init(&opts)) return (PAM_AUTH_ERR); if (!pusb_conf_parse(conf_file, &opts, user, service)) return (PAM_AUTH_ERR); if (!opts.enable) { log_debug("Not enabled, exiting...\n"); return (PAM_IGNORE); } log_info("pam_usb v%s\n", PUSB_VERSION); log_info("Authentication request for user \"%s\" (%s)\n", user, service); if (pam_get_item(pamh, PAM_TTY, (const void **)(const void *)&tty) == PAM_SUCCESS) { if (tty && !strcmp(tty, "ssh")) { log_debug("SSH Authentication, aborting.\n"); return (PAM_AUTH_ERR); } } if (!pusb_local_login(&opts, user)) { log_error("Access denied.\n"); return (PAM_AUTH_ERR); } if (pusb_device_check(&opts, user)) { log_info("Access granted.\n"); return (PAM_SUCCESS); } log_error("Access denied.\n"); return (PAM_AUTH_ERR); } PAM_EXTERN int pam_sm_setcred(pam_handle_t *pamh,int flags,int argc, const char **argv) { return (PAM_SUCCESS); } #ifdef PAM_STATIC struct pam_module _pam_usb_modstruct = { "pam_usb", pam_sm_authenticate, pam_sm_setcred, NULL, NULL, NULL, NULL }; #endif pam_usb-0.5.0/src/pamusb-check.c0000644000175000001440000001077411553677177015366 0ustar scoxusers/* * Copyright (c) 2003-2007 Andrea Luzzardi * * This file is part of the pam_usb project. pam_usb is free software; * you can redistribute it and/or modify it under the terms of the GNU General * Public License version 2, as published by the Free Software Foundation. * * pam_usb is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include "conf.h" #include "log.h" #include "device.h" #include "local.h" static void pusb_check_conf_dump(t_pusb_options *opts, const char *username, const char *service) { fprintf(stdout, "Configuration dump for user %s (service: %s):\n", username, service); fprintf(stdout, "enable\t\t\t: %s\n", opts->enable ? "true" : "false"); fprintf(stdout, "debug\t\t\t: %s\n", opts->debug ? "true" : "false"); fprintf(stdout, "quiet\t\t\t: %s\n", opts->quiet ? "true" : "false"); fprintf(stdout, "color_log\t\t: %s\n", opts->color_log ? "true" : "false"); fprintf(stdout, "one_time_pad\t\t: %s\n", opts->one_time_pad ? "true" : "false"); fprintf(stdout, "deny_remote\t\t: %s\n", opts->deny_remote ? "true" : "false"); fprintf(stdout, "pad_expiration\t\t: %u seconds\n", (unsigned int)opts->pad_expiration); fprintf(stdout, "probe_timeout\t\t: %d seconds\n", (unsigned int)opts->probe_timeout); fprintf(stdout, "hostname\t\t: %s\n", opts->hostname); fprintf(stdout, "system_pad_directory\t: %s\n", opts->system_pad_directory); fprintf(stdout, "device_pad_directory\t: %s\n", opts->device_pad_directory); } static int pusb_check_perform_authentication(t_pusb_options *opts, const char *user, const char *service) { int retval; if (!opts->enable) { log_debug("Not enabled, exiting...\n"); return (0); } log_info("Authentication request for user \"%s\" (%s)\n", user, service); if (!pusb_local_login(opts, user)) { log_error("Access denied.\n"); return (0); } retval = pusb_device_check(opts, user); if (retval) log_info("Access granted.\n"); else log_error("Access denied.\n"); return (retval); } static void pusb_check_usage(const char *name) { fprintf(stderr, "Usage: %s [--help] [--debug] [--config=path] [--service=name] [--dump] [--quiet] [--debug]" \ " \n", name); } int main(int argc, char **argv) { t_pusb_options opts; char *conf_file = PUSB_CONF_FILE; char *service = "pamusb-check"; char *user = NULL; int quiet = 0; int dump = 0; int debug = 0; int opt; int opt_index = 0; extern char *optarg; char *short_options = "hc:s:dqD"; struct option long_options[] = { { "help", 0, 0, 0 }, { "config", 1, 0, 0 }, { "service", 1, 0, 0 }, { "dump", 0, 0, 0 }, { "quiet", 0, 0, 0 }, { "debug", 0, 0, 0 }, { 0, 0, 0, 0 } }; while ((opt = getopt_long(argc, argv, short_options, long_options, &opt_index)) != EOF) { if (opt == 'h' || (!opt && !strcmp(long_options[opt_index].name, "help"))) { pusb_check_usage(argv[0]); return (1); } else if (opt == 'c' || (!opt && !strcmp(long_options[opt_index].name, "config"))) conf_file = optarg; else if (opt == 's' || (!opt && !strcmp(long_options[opt_index].name, "service"))) service = optarg; else if (opt == 'd' || (!opt && !strcmp(long_options[opt_index].name, "dump"))) dump = 1; else if (opt == 'q' || (!opt && !strcmp(long_options[opt_index].name, "quiet"))) quiet = 1; else if (opt == 'D' || (!opt && !strcmp(long_options[opt_index].name, "debug"))) debug = 1; else if (opt == '?') { pusb_check_usage(argv[0]); return (1); } } if ((argc - 1) == optind) user = argv[optind]; else { pusb_check_usage(argv[0]); return (1); } if (quiet && debug) { fprintf(stderr, "Error: You cannot use --quiet and --debug together."); return (1); } pusb_log_init(&opts); if (!pusb_conf_init(&opts)) return (1); if (!pusb_conf_parse(conf_file, &opts, user, service)) return (1); if (quiet) { opts.quiet = 1; opts.debug = 0; } else if (debug) { opts.quiet = 0; opts.debug = 1; } if (dump) { pusb_check_conf_dump(&opts, user, service); return (1); } return (!pusb_check_perform_authentication(&opts, user, service)); } pam_usb-0.5.0/src/conf.c0000644000175000001440000001314511553677177013744 0ustar scoxusers/* * Copyright (c) 2003-2007 Andrea Luzzardi * * This file is part of the pam_usb project. pam_usb is free software; * you can redistribute it and/or modify it under the terms of the GNU General * Public License version 2, as published by the Free Software Foundation. * * pam_usb is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include "mem.h" #include "conf.h" #include "xpath.h" #include "log.h" static void pusb_conf_options_get_from(t_pusb_options *opts, const char *from, xmlDoc *doc) { pusb_xpath_get_string_from(doc, from, "option[@name='hostname']", opts->hostname, sizeof(opts->hostname)); pusb_xpath_get_string_from(doc, from, "option[@name='system_pad_directory']", opts->system_pad_directory, sizeof(opts->system_pad_directory)); pusb_xpath_get_string_from(doc, from, "option[@name='device_pad_directory']", opts->device_pad_directory, sizeof(opts->device_pad_directory)); pusb_xpath_get_bool_from(doc, from, "option[@name='debug']", &(opts->debug)); pusb_xpath_get_bool_from(doc, from, "option[@name='quiet']", &(opts->quiet)); pusb_xpath_get_bool_from(doc, from, "option[@name='color_log']", &(opts->color_log)); pusb_xpath_get_bool_from(doc, from, "option[@name='enable']", &(opts->enable)); pusb_xpath_get_bool_from(doc, from, "option[@name='one_time_pad']", &(opts->one_time_pad)); pusb_xpath_get_time_from(doc, from, "option[@name='pad_expiration']", &(opts->pad_expiration)); pusb_xpath_get_time_from(doc, from, "option[@name='probe_timeout']", &(opts->probe_timeout)); pusb_xpath_get_bool_from(doc, from, "option[@name='deny_remote']", &(opts->deny_remote)); } static int pusb_conf_parse_options(t_pusb_options *opts, xmlDoc *doc, const char *user, const char *service) { char *xpath = NULL; size_t xpath_size; int i; struct s_opt_list opt_list[] = { { CONF_DEVICE_XPATH, opts->device.name }, { CONF_USER_XPATH, (char *)user }, { CONF_SERVICE_XPATH, (char *)service }, { NULL, NULL } }; pusb_conf_options_get_from(opts, "//configuration/defaults/", doc); for (i = 0; opt_list[i].name != NULL; ++i) { xpath_size = strlen(opt_list[i].name) + strlen(opt_list[i].value) + 1; xpath = xmalloc(xpath_size); memset(xpath, 0x00, xpath_size); snprintf(xpath, xpath_size, opt_list[i].name, opt_list[i].value, ""); pusb_conf_options_get_from(opts, xpath, doc); xfree(xpath); } return (1); } static int pusb_conf_device_get_property(t_pusb_options *opts, xmlDoc *doc, const char *property, char *store, size_t size) { char *xpath = NULL; size_t xpath_len; int retval; xpath_len = strlen(CONF_DEVICE_XPATH) + strlen(opts->device.name) + \ strlen(property) + 1; xpath = xmalloc(xpath_len); memset(xpath, 0x00, xpath_len); snprintf(xpath, xpath_len, CONF_DEVICE_XPATH, opts->device.name, property); retval = pusb_xpath_get_string(doc, xpath, store, size); xfree(xpath); return (retval); } static int pusb_conf_parse_device(t_pusb_options *opts, xmlDoc *doc) { pusb_conf_device_get_property(opts, doc, "vendor", opts->device.vendor, sizeof(opts->device.vendor)); pusb_conf_device_get_property(opts, doc, "model", opts->device.model, sizeof(opts->device.model)); if (!pusb_conf_device_get_property(opts, doc, "serial", opts->device.serial, sizeof(opts->device.serial))) return (0); pusb_conf_device_get_property(opts, doc, "volume_uuid", opts->device.volume_uuid, sizeof(opts->device.volume_uuid)); return (1); } int pusb_conf_init(t_pusb_options *opts) { struct utsname u; memset(opts, 0x00, sizeof(*opts)); if (uname(&u) == -1) { log_error("uname: %s\n", strerror(errno)); return (0); } strncpy(opts->hostname, u.nodename, sizeof(opts->hostname) - 1); if (strlen(u.nodename) > sizeof(opts->hostname)) log_info("Hostname \"%s\" is too long, truncating to \"%s\".\n", u.nodename, opts->hostname); strcpy(opts->system_pad_directory, ".pamusb"); strcpy(opts->device_pad_directory, ".pamusb"); opts->probe_timeout = 10; opts->enable = 1; opts->debug = 0; opts->quiet = 0; opts->color_log = 1; opts->one_time_pad = 1; opts->pad_expiration = 3600; opts->deny_remote = 1; return (1); } int pusb_conf_parse(const char *file, t_pusb_options *opts, const char *user, const char *service) { xmlDoc *doc = NULL; int retval; char device_xpath[sizeof(CONF_USER_XPATH) + CONF_USER_MAXLEN + \ sizeof("device")]; log_debug("Parsing settings...\n", user, service); if (strlen(user) > CONF_USER_MAXLEN) { log_error("Username \"%s\" is too long (max: %d).\n", user, CONF_USER_MAXLEN); return (0); } if (!(doc = xmlReadFile(file, NULL, 0))) { log_error("Unable to parse \"%s\".\n", file); return (0); } snprintf(device_xpath, sizeof(device_xpath), CONF_USER_XPATH, user, "device"); retval = pusb_xpath_get_string(doc, device_xpath, opts->device.name, sizeof(opts->device.name)); if (!retval || !pusb_conf_parse_device(opts, doc)) { log_error("No device configured for user \"%s\".\n", user); xmlFreeDoc(doc); xmlCleanupParser(); return (0); } if (!pusb_conf_parse_options(opts, doc, user, service)) { xmlFreeDoc(doc); xmlCleanupParser(); return (0); } xmlFreeDoc(doc); xmlCleanupParser(); return (1); } pam_usb-0.5.0/src/conf.h0000644000175000001440000000357511553677177013757 0ustar scoxusers/* * Copyright (c) 2003-2007 Andrea Luzzardi * * This file is part of the pam_usb project. pam_usb is free software; * you can redistribute it and/or modify it under the terms of the GNU General * Public License version 2, as published by the Free Software Foundation. * * pam_usb is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef PUSB_CONF_H_ # define PUSB_CONF_H_ # define PUSB_CONF_FILE "/etc/pamusb.conf" # define CONF_DEVICE_XPATH "//configuration/devices/device[@id='%s']/%s" # define CONF_USER_XPATH "//configuration/users/user[@id='%s']/%s" # define CONF_SERVICE_XPATH "//configuration/services/service[@id='%s']/%s" # define CONF_USER_MAXLEN 32 # include # include # include # ifndef PATH_MAX # define PATH_MAX 4096 # endif typedef struct pusb_device { char name[128]; char vendor[128]; char model[128]; char serial[128]; char volume_uuid[128]; } t_pusb_device; typedef struct pusb_options { time_t probe_timeout; int enable; int debug; int quiet; int color_log; int one_time_pad; time_t pad_expiration; int deny_remote; char hostname[64]; char system_pad_directory[PATH_MAX]; char device_pad_directory[PATH_MAX]; t_pusb_device device; } t_pusb_options; struct s_opt_list { char *name; char *value; }; int pusb_conf_init(t_pusb_options *opts); int pusb_conf_parse(const char *file, t_pusb_options *opts, const char *user, const char *service); #endif /* !PUSB_CONF_H_ */ pam_usb-0.5.0/src/log.c0000644000175000001440000000432511553677177013600 0ustar scoxusers/* * Copyright (c) 2003-2007 Andrea Luzzardi * * This file is part of the pam_usb project. pam_usb is free software; * you can redistribute it and/or modify it under the terms of the GNU General * Public License version 2, as published by the Free Software Foundation. * * pam_usb is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include "conf.h" #include "log.h" static t_pusb_options *pusb_opts = NULL; static void pusb_log_syslog(int level, const char *format, va_list ap) { openlog("pam_usb", LOG_PID, LOG_AUTH); vsyslog(level, format, ap); closelog(); } static void pusb_log_output(int level, const char *format, va_list ap) { if (!isatty(fileno(stdin))) return ; if (pusb_opts && !pusb_opts->quiet) { if (pusb_opts && pusb_opts->color_log) { if (level == LOG_ERR) fprintf(stderr, "\033[01;31m*\033[00m "); else if (level == LOG_NOTICE) fprintf(stderr, "\033[01;32m*\033[00m "); } else fprintf(stderr, "* "); vfprintf(stderr, format, ap); } } void __log_debug(const char *file, int line, const char *fmt, ...) { va_list ap; if (!pusb_opts || !pusb_opts->debug) return ; fprintf(stderr, "[%s:%03d] ", file, line); va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); va_start(ap, fmt); pusb_log_syslog(LOG_DEBUG, fmt, ap); va_end(ap); } void log_error(const char *fmt, ...) { va_list ap; va_start(ap, fmt); pusb_log_syslog(LOG_ERR, fmt, ap); va_end(ap); va_start(ap, fmt); pusb_log_output(LOG_ERR, fmt, ap); va_end(ap); } void log_info(const char *fmt, ...) { va_list ap; va_start(ap, fmt); pusb_log_syslog(LOG_NOTICE, fmt, ap); va_end(ap); va_start(ap, fmt); pusb_log_output(LOG_NOTICE, fmt, ap); va_end(ap); } void pusb_log_init(t_pusb_options *opts) { pusb_opts = opts; } pam_usb-0.5.0/src/local.h0000644000175000001440000000157111553677177014116 0ustar scoxusers/* * Copyright (c) 2003-2007 Andrea Luzzardi * * This file is part of the pam_usb project. pam_usb is free software; * you can redistribute it and/or modify it under the terms of the GNU General * Public License version 2, as published by the Free Software Foundation. * * pam_usb is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef PUSB_LOCAL_H_ # define PUSB_LOCAL_H_ int pusb_local_login(t_pusb_options *opts, const char *user); #endif /* !PUSB_LOCAL_H_ */ pam_usb-0.5.0/src/device.h0000644000175000001440000000157511553677177014267 0ustar scoxusers/* * Copyright (c) 2003-2007 Andrea Luzzardi * * This file is part of the pam_usb project. pam_usb is free software; * you can redistribute it and/or modify it under the terms of the GNU General * Public License version 2, as published by the Free Software Foundation. * * pam_usb is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef PUSB_DEVICE_H_ # define PUSB_DEVICE_H_ int pusb_device_check(t_pusb_options *opts, const char *user); #endif /* !PUSB_DEVICE_H_ */ pam_usb-0.5.0/src/xpath.c0000644000175000001440000001323111553677177014137 0ustar scoxusers/* * Copyright (c) 2003-2007 Andrea Luzzardi * * This file is part of the pam_usb project. pam_usb is free software; * you can redistribute it and/or modify it under the terms of the GNU General * Public License version 2, as published by the Free Software Foundation. * * pam_usb is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include "mem.h" #include "xpath.h" #include "log.h" static xmlXPathObject *pusb_xpath_match(xmlDocPtr doc, const char *path) { xmlXPathContext *context = NULL; xmlXPathObject *result = NULL; context = xmlXPathNewContext(doc); if (context == NULL) { log_error("Unable to create XML context\n"); return (NULL); } result = xmlXPathEvalExpression((xmlChar *)path, context); xmlXPathFreeContext(context); if (result == NULL) { log_error("Error in xmlXPathEvalExpression\n"); return (NULL); } if (xmlXPathNodeSetIsEmpty(result->nodesetval)) { xmlXPathFreeObject(result); return (NULL); } return (result); } static int pusb_xpath_strip_string(char *dest, const char *src, size_t size) { int first_char = -1; int last_char = -1; int i; for (i = 0; src[i]; ++i) { if (isspace(src[i])) continue ; if (first_char == -1) first_char = i; last_char = i; } if (first_char == -1 || last_char == -1) return (0); if ((last_char - first_char) > (size - 1)) { log_error("Device name is too long: %s", src); return (0); } memset(dest, 0x0, size); strncpy(dest, &(src[first_char]), last_char - first_char + 1); return (1); } int pusb_xpath_get_string(xmlDocPtr doc, const char *path, char *value, size_t size) { xmlXPathObject *result = NULL; xmlNode *node = NULL; xmlChar *result_string = NULL; if (!(result = pusb_xpath_match(doc, path))) return (0); if (result->nodesetval->nodeNr > 1) { xmlXPathFreeObject(result); log_debug("Syntax error: %s: more than one record found\n", path); return (0); } node = result->nodesetval->nodeTab[0]->xmlChildrenNode; result_string = xmlNodeListGetString(doc, node, 1); if (!result_string) { xmlXPathFreeObject(result); log_debug("Empty value for %s\n", path); return (0); } if (!pusb_xpath_strip_string(value, (const char *)result_string, size)) { xmlFree(result_string); xmlXPathFreeObject(result); log_debug("Result for %s (%s) is too long (max: %d)\n", path, (const char *)result_string, size); return (0); } xmlFree(result_string); xmlXPathFreeObject(result); return (1); } int pusb_xpath_get_string_from(xmlDocPtr doc, const char *base, const char *path, char *value, size_t size) { char *xpath = NULL; size_t xpath_size; int retval; xpath_size = strlen(base) + strlen(path) + 1; xpath = xmalloc(xpath_size); memset(xpath, 0x00, xpath_size); snprintf(xpath, xpath_size, "%s%s", base, path); retval = pusb_xpath_get_string(doc, xpath, value, size); if (retval) log_debug("%s%s -> %s\n", base, path, value); xfree(xpath); return (retval); } int pusb_xpath_get_bool(xmlDocPtr doc, const char *path, int *value) { char ret[6]; /* strlen("false") + 1 */ if (!pusb_xpath_get_string(doc, path, ret, sizeof(ret))) return (0); if (!strcmp(ret, "true")) { *value = 1; return (1); } if (!strcmp(ret, "false")) { *value = 0; return (1); } log_debug("Expecting a boolean, got %s\n", ret); return (0); } int pusb_xpath_get_bool_from(xmlDocPtr doc, const char *base, const char *path, int *value) { char *xpath = NULL; size_t xpath_size; int retval; xpath_size = strlen(base) + strlen(path) + 1; xpath = xmalloc(xpath_size); memset(xpath, 0x00, xpath_size); snprintf(xpath, xpath_size, "%s%s", base, path); retval = pusb_xpath_get_bool(doc, xpath, value); xfree(xpath); return (retval); } int pusb_xpath_get_time(xmlDocPtr doc, const char *path, time_t *value) { char ret[64]; char *last; int coef; if (!pusb_xpath_get_string(doc, path, ret, sizeof(ret))) return (0); last = &(ret[strlen(ret) - 1]); coef = 1; if (*last == 's') coef = 1; else if (*last == 'm') coef = 60; else if (*last == 'h') coef = 3600; else if (*last == 'd') coef = 3600 * 24; else if (!isdigit(*last)) { log_debug("Expecting a time modifier, got %c\n", *last); return (0); } if (!isdigit(*last)) *last = '\0'; *value = atoi(ret) * coef; return (0); } int pusb_xpath_get_time_from(xmlDocPtr doc, const char *base, const char *path, time_t *value) { char *xpath = NULL; size_t xpath_size; int retval; xpath_size = strlen(base) + strlen(path) + 1; xpath = xmalloc(xpath_size); memset(xpath, 0x00, xpath_size); snprintf(xpath, xpath_size, "%s%s", base, path); retval = pusb_xpath_get_time(doc, xpath, value); xfree(xpath); return (retval); } int pusb_xpath_get_int(xmlDocPtr doc, const char *path, int *value) { char ret[64]; if (!pusb_xpath_get_string(doc, path, ret, sizeof(ret))) return (0); *value = atoi(ret); return (1); } int pusb_xpath_get_int_from(xmlDocPtr doc, const char *base, const char *path, int *value) { char *xpath = NULL; size_t xpath_size; int retval; xpath_size = strlen(base) + strlen(path) + 1; xpath = xmalloc(xpath_size); memset(xpath, 0x00, xpath_size); snprintf(xpath, xpath_size, "%s%s", base, path); retval = pusb_xpath_get_int(doc, xpath, value); xfree(xpath); return (retval); } pam_usb-0.5.0/src/pad.h0000644000175000001440000000160711553677177013570 0ustar scoxusers/* * Copyright (c) 2003-2007 Andrea Luzzardi * * This file is part of the pam_usb project. pam_usb is free software; * you can redistribute it and/or modify it under the terms of the GNU General * Public License version 2, as published by the Free Software Foundation. * * pam_usb is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef PUSB_OTP_H_ # define PUSB_OTP_H_ int pusb_pad_check(t_pusb_options *opts, DBusConnection *dbus, const char *user); #endif /* !PUSB_OTP_H_ */ pam_usb-0.5.0/src/hal.h0000644000175000001440000000271011553677177013564 0ustar scoxusers/* * Copyright (c) 2003-2007 Andrea Luzzardi * * This file is part of the pam_usb project. pam_usb is free software; * you can redistribute it and/or modify it under the terms of the GNU General * Public License version 2, as published by the Free Software Foundation. * * pam_usb is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef PUSB_HAL_H_ # define PUSB_HAL_H_ # include DBusConnection *pusb_hal_dbus_connect(void); void pusb_hal_dbus_disconnect(DBusConnection *dbus); char *pusb_hal_get_string_property(DBusConnection *dbus, const char *udi, const char *name); int pusb_hal_get_bool_property(DBusConnection *dbus, const char *udi, const char *name, dbus_bool_t *value); char **pusb_hal_get_string_array_property(DBusConnection *dbus, const char *udi, const char *name, int *n_items); int pusb_hal_check_property(DBusConnection *dbus, const char *udi, const char *name, const char *value); char *pusb_hal_find_item(DBusConnection *dbus, ...); void pusb_hal_free_string_array(char **str_array, int length); #endif /* !PUSB_HAL_H_ */ pam_usb-0.5.0/src/pad.c0000644000175000001440000001477111553677177013571 0ustar scoxusers/* * Copyright (c) 2003-2007 Andrea Luzzardi * * This file is part of the pam_usb project. pam_usb is free software; * you can redistribute it and/or modify it under the terms of the GNU General * Public License version 2, as published by the Free Software Foundation. * * pam_usb is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include "conf.h" #include "log.h" #include "volume.h" #include "pad.h" static FILE *pusb_pad_open_device(t_pusb_options *opts, const char *mnt_point, const char *user, const char *mode) { FILE *f; char path[PATH_MAX]; struct stat sb; memset(path, 0x00, PATH_MAX); snprintf(path, PATH_MAX, "%s/%s", mnt_point, opts->device_pad_directory); if (stat(path, &sb) != 0) { log_debug("Directory %s does not exist, creating one.\n", path); if (mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR) != 0) { log_debug("Unable to create directory %s: %s\n", path, strerror(errno)); return (NULL); } memset(path, 0x00, PATH_MAX); } snprintf(path, PATH_MAX, "%s/%s/%s.%s.pad", mnt_point, opts->device_pad_directory, user, opts->hostname); f = fopen(path, mode); if (!f) { log_debug("Cannot open device file: %s\n", strerror(errno)); return (NULL); } return (f); } static FILE *pusb_pad_open_system(t_pusb_options *opts, const char *user, const char *mode) { FILE *f; char path[PATH_MAX]; struct passwd *user_ent = NULL; struct stat sb; if (!(user_ent = getpwnam(user)) || !(user_ent->pw_dir)) { log_error("Unable to retrieve informations for user \"%s\": %s\n", strerror(errno)); return (0); } memset(path, 0x00, PATH_MAX); snprintf(path, PATH_MAX, "%s/%s", user_ent->pw_dir, opts->system_pad_directory); if (stat(path, &sb) != 0) { log_debug("Directory %s does not exist, creating one.\n", path); if (mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR) != 0) { log_debug("Unable to create directory %s: %s\n", path, strerror(errno)); return (NULL); } chown(path, user_ent->pw_uid, user_ent->pw_gid); chmod(path, S_IRUSR | S_IWUSR | S_IXUSR); } memset(path, 0x00, PATH_MAX); snprintf(path, PATH_MAX, "%s/%s/%s.pad", user_ent->pw_dir, opts->system_pad_directory, opts->device.name); f = fopen(path, mode); if (!f) { log_debug("Cannot open system file: %s\n", strerror(errno)); return (NULL); } return (f); } static int pusb_pad_protect(const char *user, int fd) { struct passwd *user_ent = NULL; log_debug("Protecting pad file...\n"); if (!(user_ent = getpwnam(user))) { log_error("Unable to retrieve informations for user \"%s\": %s\n", strerror(errno)); return (0); } if (fchown(fd, user_ent->pw_uid, user_ent->pw_gid) == -1) { log_debug("Unable to change owner of the pad: %s\n", strerror(errno)); return (0); } if (fchmod(fd, S_IRUSR | S_IWUSR) == -1) { log_debug("Unable to change mode of the pad: %s\n", strerror(errno)); return (0); } return (1); } static int pusb_pad_should_update(t_pusb_options *opts, const char *user) { FILE *f_system = NULL; struct stat st; time_t now; time_t delta; log_debug("Checking whether pads are expired or not...\n"); if (!(f_system = pusb_pad_open_system(opts, user, "r"))) { log_debug("Unable to open system pad, pads must be generated.\n"); return (1); } if (fstat(fileno(f_system), &st) == -1) { fclose(f_system); return (1); } fclose(f_system); if (time(&now) == ((time_t)-1)) { log_error("Unable to fetch current time.\n"); return (1); } delta = now - st.st_mtime; if (delta > opts->pad_expiration) { log_debug("Pads expired %u seconds ago, updating...\n", delta - opts->pad_expiration); return (1); } else { log_debug("Pads were generated %u seconds ago, not updating.\n", delta); return (0); } return (1); } static void pusb_pad_update(t_pusb_options *opts, const char *volume, const char *user) { FILE *f_device = NULL; FILE *f_system = NULL; char magic[1024]; int i; if (!pusb_pad_should_update(opts, user)) return ; log_info("Regenerating new pads...\n"); if (!(f_device = pusb_pad_open_device(opts, volume, user, "w+"))) { log_error("Unable to update pads.\n"); return ; } pusb_pad_protect(user, fileno(f_device)); if (!(f_system = pusb_pad_open_system(opts, user, "w+"))) { log_error("Unable to update pads.\n"); fclose(f_device); return ; } pusb_pad_protect(user, fileno(f_system)); log_debug("Generating %d bytes unique pad...\n", sizeof(magic)); srand(getpid() * time(NULL)); for (i = 0; i < sizeof(magic); ++i) magic[i] = (char)rand(); log_debug("Writing pad to the device...\n"); fwrite(magic, sizeof(char), sizeof(magic), f_system); log_debug("Writing pad to the system...\n"); fwrite(magic, sizeof(char), sizeof(magic), f_device); log_debug("Synchronizing filesystems...\n"); fclose(f_system); fclose(f_device); sync(); log_debug("One time pads updated.\n"); } static int pusb_pad_compare(t_pusb_options *opts, const char *volume, const char *user) { FILE *f_device = NULL; FILE *f_system = NULL; char magic_device[1024]; char magic_system[1024]; int retval; if (!(f_system = pusb_pad_open_system(opts, user, "r"))) return (1); if (!(f_device = pusb_pad_open_device(opts, volume, user, "r"))) { fclose(f_system); return (0); } log_debug("Loading device pad...\n"); fread(magic_device, sizeof(char), sizeof(magic_device), f_device); log_debug("Loading system pad...\n"); fread(magic_system, sizeof(char), sizeof(magic_system), f_system); retval = memcmp(magic_system, magic_device, sizeof(magic_system)); fclose(f_system); fclose(f_device); if (!retval) log_debug("Pad match.\n"); return (retval == 0); } int pusb_pad_check(t_pusb_options *opts, DBusConnection *dbus, const char *user) { char *volume = NULL; int retval = 0; volume = pusb_volume_get(opts, dbus); if (!volume) return (0); retval = pusb_pad_compare(opts, volume, user); if (retval) pusb_pad_update(opts, volume, user); else log_error("Pad checking failed !\n"); pusb_volume_destroy(volume); return (retval); } pam_usb-0.5.0/src/log.h0000644000175000001440000000211711553677177013602 0ustar scoxusers/* * Copyright (c) 2003-2007 Andrea Luzzardi * * This file is part of the pam_usb project. pam_usb is free software; * you can redistribute it and/or modify it under the terms of the GNU General * Public License version 2, as published by the Free Software Foundation. * * pam_usb is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef PUSB_LOG_H_ # define PUSB_LOG_H_ # define log_debug(s, ...) __log_debug(__FILE__, __LINE__, s, ##__VA_ARGS__) # include "conf.h" void __log_debug(const char *file, int line, const char *fmt, ...); void log_error(const char *fmt, ...); void log_info(const char *fmt, ...); void pusb_log_init(t_pusb_options *opts); #endif /* !PUSB_LOG_H_ */ pam_usb-0.5.0/src/volume.c0000644000175000001440000001022211553677177014317 0ustar scoxusers/* * Copyright (c) 2003-2007 Andrea Luzzardi * * This file is part of the pam_usb project. pam_usb is free software; * you can redistribute it and/or modify it under the terms of the GNU General * Public License version 2, as published by the Free Software Foundation. * * pam_usb is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include "mem.h" #include "conf.h" #include "log.h" #include "hal.h" #include "volume.h" static int pusb_volume_mount(t_pusb_options *opts, char *udi, DBusConnection *dbus) { char command[1024]; char tempname[32]; const char *devname; snprintf(tempname, sizeof(tempname), "pam_usb%d", getpid()); if (!(devname = pusb_hal_get_string_property(dbus, udi, "DeviceFile"))) { log_error("Unable to retrieve device filename\n"); return (0); } log_debug("Attempting to mount device %s with label %s\n", devname, tempname); snprintf(command, sizeof(command), "pmount -A -s %s %s", devname, tempname); log_debug("Executing \"%s\"\n", command); if (system(command) != 0) { log_error("Mount failed\n"); return (0); } log_debug("Mount succeeded.\n"); return (1); } static char *pusb_volume_mount_path(t_pusb_options *opts, char *udi, DBusConnection* dbus) { dbus_bool_t is_mounted; if (!pusb_hal_get_bool_property(dbus, udi, "DeviceIsMounted", &is_mounted)) { return (NULL); } if (is_mounted != TRUE) { log_debug("Device %s is not mounted\n", udi); return (NULL); } int n_mount; char **mount_pathes = pusb_hal_get_string_array_property(dbus, udi, "DeviceMountPaths", &n_mount); if (!mount_pathes) { log_debug("Failed to retrieve device %s mount path\n", udi); return (NULL); } if (n_mount > 1) { log_debug("Device %s is mounted more than once\n", udi); } char *mount_path = xstrdup(mount_pathes[0]); pusb_hal_free_string_array(mount_pathes, n_mount); log_debug("Device %s is mounted on %s\n", udi, mount_path); return (mount_path); } static char *pusb_volume_probe(t_pusb_options *opts, DBusConnection *dbus) { int maxtries = 0; int i; if (!*(opts->device.volume_uuid)) { log_debug("No UUID configured for device\n"); return (NULL); } log_debug("Searching for volume with uuid %s\n", opts->device.volume_uuid); maxtries = ((opts->probe_timeout * 1000000) / 250000); for (i = 0; i < maxtries; ++i) { char *udi = NULL; if (i == 1) log_info("Probing volume (this could take a while)...\n"); udi = pusb_hal_find_item(dbus, "IdUuid", opts->device.volume_uuid, NULL); if (!udi) { usleep(250000); continue; } return (udi); } return (NULL); } char *pusb_volume_get(t_pusb_options *opts, DBusConnection *dbus) { char *volume_udi; char *mount_point; if (!(volume_udi = pusb_volume_probe(opts, dbus))) return (NULL); log_debug("Found volume %s\n", opts->device.volume_uuid); mount_point = pusb_volume_mount_path(opts, volume_udi, dbus); if (mount_point) { log_debug("Volume is already mounted.\n"); return (mount_point); } if (!pusb_volume_mount(opts, volume_udi, dbus)) { xfree(volume_udi); return (NULL); } mount_point = pusb_volume_mount_path(opts, volume_udi, dbus); if (!mount_point) { log_error("Unable to retrieve %s mount point\n", volume_udi); return (NULL); } return (mount_point); } void pusb_volume_destroy(char *mntpoint) { if (mntpoint && strstr(mntpoint, "pam_usb")) { char command[1024]; log_debug("Attempting to umount %s\n", mntpoint); snprintf(command, sizeof(command), "pumount %s", mntpoint); log_debug("Executing \"%s\"\n", command); if (!system(command)) log_debug("Umount succeeded.\n"); else log_error("Unable to umount %s\n", mntpoint); } xfree(mntpoint); } pam_usb-0.5.0/src/mem.h0000644000175000001440000000173011553677177013577 0ustar scoxusers/* * Copyright (c) 2003-2007 Andrea Luzzardi * * This file is part of the pam_usb project. pam_usb is free software; * you can redistribute it and/or modify it under the terms of the GNU General * Public License version 2, as published by the Free Software Foundation. * * pam_usb is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef PUSB_MEM_H_ # define PUSB_MEM_H_ # include # include void *xmalloc(size_t size); void *xrealloc(void *ptr, size_t size); void xfree(void *ptr); char *xstrdup(const char *s); #endif /* !PUSB_MEM_H_ */