From 537d85c249e90473f846ee70a51a272a32dfa249 Mon Sep 17 00:00:00 2001 From: Chris Dituri Date: Sat, 16 Apr 2016 15:49:36 -0500 Subject: [PATCH] tools/pamusb-conf: tighten --add-device logic Prevent pamusb-conf from creating a new device when that new device collides with existing node in the pam_usb configuration file. --- tools/pamusb-conf | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/pamusb-conf b/tools/pamusb-conf index c253fb2..14cfe73 100755 --- a/tools/pamusb-conf +++ b/tools/pamusb-conf @@ -187,6 +187,16 @@ def addDevice(options): sys.exit(1) devs = doc.getElementsByTagName('devices') + + # Check that the id of the device to add is not already present in the configFile + for devices in devs: + for device in devices.getElementsByTagName("device"): + if device.getAttribute("id") == options['deviceName']: + msg = [ '\nWARNING: A device node already exits for new device \'%s\'.', + '\nTo proceed re-run --add-device using a different name or remove the existing entry in %s.' ] + print '\n'.join(msg) % (options['deviceName'], options['configFile']) + sys.exit(2) + dev = doc.createElement('device') dev.attributes['id'] = options['deviceName']