Sandro Bonazzola has uploaded a new change for review.

Change subject: packaging: setup: validate unicast MAC address
......................................................................

packaging: setup: validate unicast MAC address

Change-Id: I6af3523bff99d153691996152f39b7d4750eeaf5
Bug-Url: https://bugzilla.redhat.com/1116785
Signed-off-by: Sandro Bonazzola <[email protected]>
(cherry picked from commit 6c1b4046ea12306dc8dd556f0ca41f70defdbfe6)
---
M src/ovirt_hosted_engine_setup/util.py
M src/plugins/ovirt-hosted-engine-setup/vm/mac.py
2 files changed, 24 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-hosted-engine-setup 
refs/changes/26/30926/1

diff --git a/src/ovirt_hosted_engine_setup/util.py 
b/src/ovirt_hosted_engine_setup/util.py
index 3b7237b..d482ad8 100644
--- a/src/ovirt_hosted_engine_setup/util.py
+++ b/src/ovirt_hosted_engine_setup/util.py
@@ -23,12 +23,15 @@
 
 import os
 import random
+import re
 
 
 from otopi import util
 
 
 from . import constants as ohostedcons
+
+UNICAST_MAC_ADDR = re.compile("[a-fA-F0-9][02468aAcCeE](:[a-fA-F0-9]{2}){5}")
 
 
 @util.export
@@ -54,19 +57,15 @@
 
 
 def validMAC(mac):
-    fields = mac.split(':')
-    if len(fields) != 6:
-        return False
-    for field in fields:
-        if len(field) != 2:
-            return False
-        try:
-            val = int(field, 16)
-        except ValueError:
-            return False
-        if val < 0 or val > 255:
-            return False
-    return True
+    """
+    Ensure that mac is a valid unicast MAC address.
+    @see: https://bugzilla.redhat.com/1116785
+    @see: "http://libvirt.org/git/?
+        p=libvirt.git;
+        a=commitdiff;
+        h=0007237301586aa90f58a7cc8d7cb29a16b00470"
+    """
+    return (UNICAST_MAC_ADDR.match(mac) is not None)
 
 
 class VirtUserContext(object):
diff --git a/src/plugins/ovirt-hosted-engine-setup/vm/mac.py 
b/src/plugins/ovirt-hosted-engine-setup/vm/mac.py
index f94c64a..165b266 100644
--- a/src/plugins/ovirt-hosted-engine-setup/vm/mac.py
+++ b/src/plugins/ovirt-hosted-engine-setup/vm/mac.py
@@ -1,6 +1,6 @@
 #
 # ovirt-hosted-engine-setup -- ovirt hosted engine setup
-# Copyright (C) 2013 Red Hat, Inc.
+# Copyright (C) 2013-2014 Red Hat, Inc.
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -19,7 +19,7 @@
 
 
 """
-VM mac address configuration plugin.
+VM MAC address configuration plugin.
 """
 
 
@@ -40,7 +40,7 @@
 @util.export
 class Plugin(plugin.PluginBase):
     """
-    VM mac address configuration plugin.
+    VM MAC address configuration plugin.
     """
 
     def __init__(self, context):
@@ -81,17 +81,20 @@
                 ] = self.dialog.queryString(
                     name='ovehosted_vmenv_mac',
                     note=_(
-                        'You may specify a MAC address for the VM or '
+                        'You may specify a unicast MAC address for the VM or '
                         'accept a randomly generated default [@DEFAULT@]: '
                     ),
                     prompt=True,
                     default=default_mac,
                 ).strip()
             valid = ohostedutil.validMAC(
-                self.environment[ohostedcons.VMEnv.MAC_ADDR])
+                self.environment[ohostedcons.VMEnv.MAC_ADDR]
+            )
             if not valid and not interactive:
                 raise RuntimeError(
-                    _('Invalid mac address specified: \'{mac}\'').format(
+                    _(
+                        'Invalid unicast MAC address specified: \'{mac}\''
+                    ).format(
                         mac=self.environment[
                             ohostedcons.VMEnv.MAC_ADDR
                         ],
@@ -99,7 +102,9 @@
                 )
             if not valid and interactive:
                 self.logger.error(
-                    _('Invalid mac address specified: \'{mac}\'').format(
+                    _(
+                        'Invalid unicast MAC address specified: \'{mac}\''
+                    ).format(
                         mac=self.environment[
                             ohostedcons.VMEnv.MAC_ADDR
                         ],


-- 
To view, visit http://gerrit.ovirt.org/30926
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6af3523bff99d153691996152f39b7d4750eeaf5
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-hosted-engine-setup
Gerrit-Branch: ovirt-hosted-engine-setup-1.2
Gerrit-Owner: Sandro Bonazzola <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to