[pve-devel] [PATCH v4 manager 2/2] fix #2190: Base64 encode SMBIOS value strings in order to allow more characters

Christian Ebner c.ebner at proxmox.com
Tue Jun 11 12:13:53 CEST 2019


On some occasions e.g. license checking, the manufacturer string in the
SMBIOS settings edit has to allow characters such as whitespaces.
https://forum.proxmox.com/threads/proxmox-and-windows-rok-license-for-dell.53236/
In principle SMBIOS allows to pass any zero terminated string to the
corresponding fields in the structure type 1 (System Information).

By base64 encoding the values clashing of the config is avoided.

Relies on the corresponding patch to qemu-server to pass parameter verification
and correct parsing.

Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
Version 4:
    * Cleaner code by the use of reduce() to parse the property string
    * make sure the base64=1 is only appended if the string contains 
      base64 encoded values

 www/manager6/Parser.js           | 31 +++++++++++++++++++++++--------
 www/manager6/qemu/Smbios1Edit.js |  6 ------
 2 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/www/manager6/Parser.js b/www/manager6/Parser.js
index 958deae5..242965dd 100644
--- a/www/manager6/Parser.js
+++ b/www/manager6/Parser.js
@@ -528,12 +528,18 @@ Ext.define('PVE.Parser', { statics: {
     },
 
     parseQemuSmbios1: function(value) {
-	var res = {};
-
-	Ext.Array.each(value.split(','), function(p) {
-	    var kva = p.split('=', 2);
-	    res[kva[0]] = kva[1];
-	});
+	var res = value.split(',').reduce(function (accumulator, currentValue) {
+	    var splitted = currentValue.split(new RegExp("=(.+)"));
+	    accumulator[splitted[0]] = splitted[1];
+	    return accumulator;
+	}, {});
+
+	if (PVE.Parser.parseBoolean(res.base64, false)) {
+	    Ext.Object.each(res, function(key, value) {
+		if (key === 'uuid') { return; }
+		res[key] = Ext.util.Base64.decode(value);
+	    });
+	}
 
 	return res;
     },
@@ -541,10 +547,19 @@ Ext.define('PVE.Parser', { statics: {
     printQemuSmbios1: function(data) {
 
 	var datastr = '';
-
+	var base64 = false;
 	Ext.Object.each(data, function(key, value) {
 	    if (value === '') { return; }
-	    datastr += (datastr !== '' ? ',' : '') + key + '=' + value;
+	    if (key === 'uuid') {
+		datastr += (datastr !== '' ? ',' : '') + key + '=' + value;
+	    } else {
+		// values should be base64 encoded from now on, mark config strings correspondingly
+		if (!base64) {
+		    base64 = true;
+		    datastr += (datastr !== '' ? ',' : '') + 'base64=1';
+		}
+		datastr += (datastr !== '' ? ',' : '') + key + '=' + Ext.util.Base64.encode(value);
+	    }
 	});
 
 	return datastr;
diff --git a/www/manager6/qemu/Smbios1Edit.js b/www/manager6/qemu/Smbios1Edit.js
index fdb0d150..c0c43683 100644
--- a/www/manager6/qemu/Smbios1Edit.js
+++ b/www/manager6/qemu/Smbios1Edit.js
@@ -38,37 +38,31 @@ Ext.define('PVE.qemu.Smbios1InputPanel', {
 	    {
 		xtype: 'textfield',
 		fieldLabel: gettext('Manufacturer'),
-		regex: /^\S+$/,
 		name: 'manufacturer'
 	    },
 	    {
 		xtype: 'textfield',
 		fieldLabel: gettext('Product'),
-		regex: /^\S+$/,
 		name: 'product'
 	    },
 	    {
 		xtype: 'textfield',
 		fieldLabel: gettext('Version'),
-		regex: /^\S+$/,
 		name: 'version'
 	    },
 	    {
 		xtype: 'textfield',
 		fieldLabel: gettext('Serial'),
-		regex: /^\S+$/,
 		name: 'serial'
 	    },
 	    {
 		xtype: 'textfield',
 		fieldLabel: 'SKU',
-		regex: /^\S+$/,
 		name: 'sku'
 	    },
 	    {
 		xtype: 'textfield',
 		fieldLabel: gettext('Family'),
-		regex: /^\S+$/,
 		name: 'family'
 	    }
 	];
-- 
2.11.0




More information about the pve-devel mailing list