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

Tim Marx t.marx at proxmox.com
Thu Jun 6 14:19:02 CEST 2019


Looks good.

> Christian Ebner <c.ebner at proxmox.com> hat am 4. Juni 2019 um 16:47 geschrieben:
> 
> 
> 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 3:
>     * use base64 encoding instead of URL encoding
>     * backwards compatible to old configs
> 
>  www/manager6/Parser.js           | 19 ++++++++++++++++---
>  www/manager6/qemu/Smbios1Edit.js |  6 ------
>  2 files changed, 16 insertions(+), 9 deletions(-)
> 
> diff --git a/www/manager6/Parser.js b/www/manager6/Parser.js
> index 958deae5..d266a4f3 100644
> --- a/www/manager6/Parser.js
> +++ b/www/manager6/Parser.js
> @@ -530,21 +530,34 @@ Ext.define('PVE.Parser', { statics: {
>      parseQemuSmbios1: function(value) {
>  	var res = {};
>  
> +	var regex = new RegExp("=(.+)");
>  	Ext.Array.each(value.split(','), function(p) {
> -	    var kva = p.split('=', 2);
> +	    var kva = p.split(regex);
>  	    res[kva[0]] = kva[1];
>  	});
>
Just as info you have the opportunity to use reduce here:
e.g.:

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;
>      },
>  
>      printQemuSmbios1: function(data) {
>  
> -	var datastr = '';
> +	// values should be base64 encoded from now on, mark config strings correspondingly
> +	var datastr = 'base64=1';
> 

this will be added regardless if there is any other config, is this intended?

>  	Ext.Object.each(data, function(key, value) {
>  	    if (value === '') { return; }
> -	    datastr += (datastr !== '' ? ',' : '') + key + '=' + value;
> +	    if (key === 'uuid') {
> +		datastr += ',' + key + '=' + value;
> +	    } else {
> +		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
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel




More information about the pve-devel mailing list