From 32e79e6417464486d8f13a754772630040ea578d Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sun, 17 Jul 2016 20:45:17 +0200 Subject: [PATCH] check for duplicate MACs --- lam/lib/modules/ieee802device.inc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lam/lib/modules/ieee802device.inc b/lam/lib/modules/ieee802device.inc index f6868274..ba496090 100644 --- a/lam/lib/modules/ieee802device.inc +++ b/lam/lib/modules/ieee802device.inc @@ -3,7 +3,7 @@ $Id$ This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) - Copyright (C) 2004 - 2015 Roland Gruber + Copyright (C) 2004 - 2016 Roland Gruber 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 @@ -116,6 +116,19 @@ class ieee802device extends baseModule { function process_attributes() { $errors = array(); $this->processMultiValueInputTextField('macAddress', $errors, 'macAddress'); + // check if MAC is already assigned + if (!empty($this->attributes['macAddress'])) { + foreach ($this->attributes['macAddress'] as $macAddress) { + if (!empty($this->orig['macAddress']) && in_array($macAddress, $this->orig['macAddress'])) { + // check only new MAC addresses + continue; + } + $result = searchLDAPByAttribute('macAddress', $macAddress, 'ieee802Device', array('dn'), array('host')); + if (!empty($result)) { + $errors[] = array('WARN', _('This MAC address is already in use.'), getAbstractDN($result[0]['dn'])); + } + } + } return $errors; }