Add #if defined(CONFIG_VNC) in generated code, and adjust the qmp/hmp code accordingly.
Commands made conditional: * query-vnc, query-vnc-servers, change-vnc-password Before the patch, the commands for !CONFIG_VNC are stubs that fail like this: {"error": {"class": "GenericError", "desc": "The feature 'vnc' is not enabled"}} Afterwards, they fail like this: {"error": {"class": "CommandNotFound", "desc": "The command FOO has not been found"}} I call that an improvement, because it lets clients distinguish between command unavailable (class CommandNotFound) and command failed (class GenericError). Events made conditional: * VNC_CONNECTED, VNC_INITIALIZED, VNC_DISCONNECTED Enum made conditional: * QCryptoCipherAlgorithm # @des-rfb: RFB specific variant of single DES. Do not use except in VNC. Occurrences of VNC (case insensitive) in the schema that aren't covered by this change: * add_client Command has other uses, including "socket bases character devices". These are unconditional as far as I can tell. * set_password, expire_password In theory, these commands could be used for managing any service's password. In practice, they're used for VNC and SPICE services. They're documented for "remote display session" / "remote display server". The service is selected by argument @protocol. The code special-cases protocol-specific argument checking, then calls a protocol-specific function to do the work. If it fails, the command fails with "Could not set password". It does when the service isn't compiled in (it's a stub then). We could make these commands conditional on the conjunction of all services [currently: defined(CONFIG_VNC) || defined(CONFIG_SPICE)], but I doubt it's worthwhile. * change Command has other uses, namely changing media. This patch inlines a stub; no functional change. Signed-off-by: Marc-André Lureau <marcandre.lur...@redhat.com> --- qapi-schema.json | 34 ++++++++++++++++++++++------------ qapi/crypto.json | 3 ++- qapi/event.json | 9 ++++++--- crypto/cipher-builtin.c | 9 +++++++++ crypto/cipher-gcrypt.c | 10 ++++++++-- crypto/cipher-nettle.c | 14 +++++++++++--- crypto/cipher.c | 13 +++++++++++-- hmp.c | 9 ++++++++- qmp.c | 30 ++++-------------------------- hmp-commands-info.hx | 2 ++ 10 files changed, 83 insertions(+), 50 deletions(-) diff --git a/qapi-schema.json b/qapi-schema.json index 802ea53d00..4ffbe1d9ff 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1660,7 +1660,8 @@ 'data': { 'host': 'str', 'service': 'str', 'family': 'NetworkAddressFamily', - 'websocket': 'bool' } } + 'websocket': 'bool' }, + 'if': 'defined(CONFIG_VNC)' } ## # @VncServerInfo: @@ -1674,7 +1675,8 @@ ## { 'struct': 'VncServerInfo', 'base': 'VncBasicInfo', - 'data': { '*auth': 'str' } } + 'data': { '*auth': 'str' }, + 'if': 'defined(CONFIG_VNC)' } ## # @VncClientInfo: @@ -1691,7 +1693,8 @@ ## { 'struct': 'VncClientInfo', 'base': 'VncBasicInfo', - 'data': { '*x509_dname': 'str', '*sasl_username': 'str' } } + 'data': { '*x509_dname': 'str', '*sasl_username': 'str' }, + 'if': 'defined(CONFIG_VNC)' } ## # @VncInfo: @@ -1732,7 +1735,8 @@ { 'struct': 'VncInfo', 'data': {'enabled': 'bool', '*host': 'str', '*family': 'NetworkAddressFamily', - '*service': 'str', '*auth': 'str', '*clients': ['VncClientInfo']} } + '*service': 'str', '*auth': 'str', '*clients': ['VncClientInfo']}, + 'if': 'defined(CONFIG_VNC)' } ## # @VncPrimaryAuth: @@ -1743,7 +1747,8 @@ ## { 'enum': 'VncPrimaryAuth', 'data': [ 'none', 'vnc', 'ra2', 'ra2ne', 'tight', 'ultra', - 'tls', 'vencrypt', 'sasl' ] } + 'tls', 'vencrypt', 'sasl' ], + 'if': 'defined(CONFIG_VNC)' } ## # @VncVencryptSubAuth: @@ -1757,7 +1762,8 @@ 'tls-none', 'x509-none', 'tls-vnc', 'x509-vnc', 'tls-plain', 'x509-plain', - 'tls-sasl', 'x509-sasl' ] } + 'tls-sasl', 'x509-sasl' ], + 'if': 'defined(CONFIG_VNC)' } ## @@ -1775,7 +1781,8 @@ { 'struct': 'VncServerInfo2', 'base': 'VncBasicInfo', 'data': { 'auth' : 'VncPrimaryAuth', - '*vencrypt' : 'VncVencryptSubAuth' } } + '*vencrypt' : 'VncVencryptSubAuth' }, + 'if': 'defined(CONFIG_VNC)' } ## @@ -1808,7 +1815,8 @@ 'clients' : ['VncClientInfo'], 'auth' : 'VncPrimaryAuth', '*vencrypt' : 'VncVencryptSubAuth', - '*display' : 'str' } } + '*display' : 'str' }, + 'if': 'defined(CONFIG_VNC)' } ## # @query-vnc: @@ -1839,7 +1847,8 @@ # } # ## -{ 'command': 'query-vnc', 'returns': 'VncInfo' } +{ 'command': 'query-vnc', 'returns': 'VncInfo', + 'if': 'defined(CONFIG_VNC)' } ## # @query-vnc-servers: @@ -1850,7 +1859,8 @@ # # Since: 2.3 ## -{ 'command': 'query-vnc-servers', 'returns': ['VncInfo2'] } +{ 'command': 'query-vnc-servers', 'returns': ['VncInfo2'], + 'if': 'defined(CONFIG_VNC)' } ## # @SpiceBasicInfo: @@ -3077,8 +3087,8 @@ # Notes: An empty password in this command will set the password to the empty # string. Existing clients are unaffected by executing this command. ## -{ 'command': 'change-vnc-password', 'data': {'password': 'str'} } - +{ 'command': 'change-vnc-password', 'data': {'password': 'str'}, + 'if': 'defined(CONFIG_VNC)' } ## # @change: # diff --git a/qapi/crypto.json b/qapi/crypto.json index 6b6fde367a..b9bfff202c 100644 --- a/qapi/crypto.json +++ b/qapi/crypto.json @@ -79,7 +79,8 @@ { 'enum': 'QCryptoCipherAlgorithm', 'prefix': 'QCRYPTO_CIPHER_ALG', 'data': ['aes-128', 'aes-192', 'aes-256', - 'des-rfb', '3des', + { 'name': 'des-rfb', 'if': 'defined(CONFIG_VNC)' }, + '3des', 'cast5-128', 'serpent-128', 'serpent-192', 'serpent-256', 'twofish-128', 'twofish-192', 'twofish-256']} diff --git a/qapi/event.json b/qapi/event.json index 6d22b025cc..c8b8e9f384 100644 --- a/qapi/event.json +++ b/qapi/event.json @@ -263,7 +263,8 @@ ## { 'event': 'VNC_CONNECTED', 'data': { 'server': 'VncServerInfo', - 'client': 'VncBasicInfo' } } + 'client': 'VncBasicInfo' }, + 'if': 'defined(CONFIG_VNC)' } ## # @VNC_INITIALIZED: @@ -290,7 +291,8 @@ ## { 'event': 'VNC_INITIALIZED', 'data': { 'server': 'VncServerInfo', - 'client': 'VncClientInfo' } } + 'client': 'VncClientInfo' }, + 'if': 'defined(CONFIG_VNC)' } ## # @VNC_DISCONNECTED: @@ -316,7 +318,8 @@ ## { 'event': 'VNC_DISCONNECTED', 'data': { 'server': 'VncServerInfo', - 'client': 'VncClientInfo' } } + 'client': 'VncClientInfo' }, + 'if': 'defined(CONFIG_VNC)' } ## # @SPICE_CONNECTED: diff --git a/crypto/cipher-builtin.c b/crypto/cipher-builtin.c index e956cc5a53..647bcf3247 100644 --- a/crypto/cipher-builtin.c +++ b/crypto/cipher-builtin.c @@ -35,17 +35,22 @@ struct QCryptoCipherBuiltinAES { QCryptoCipherBuiltinAESContext key_tweak; uint8_t iv[AES_BLOCK_SIZE]; }; + +#ifdef CONFIG_VNC typedef struct QCryptoCipherBuiltinDESRFB QCryptoCipherBuiltinDESRFB; struct QCryptoCipherBuiltinDESRFB { uint8_t *key; size_t nkey; }; +#endif typedef struct QCryptoCipherBuiltin QCryptoCipherBuiltin; struct QCryptoCipherBuiltin { union { QCryptoCipherBuiltinAES aes; +#ifdef CONFIG_VNC QCryptoCipherBuiltinDESRFB desrfb; +#endif } state; size_t blocksize; void (*free)(QCryptoCipher *cipher); @@ -403,7 +408,9 @@ bool qcrypto_cipher_supports(QCryptoCipherAlgorithm alg, QCryptoCipherMode mode) { switch (alg) { +#ifdef CONFIG_VNC case QCRYPTO_CIPHER_ALG_DES_RFB: +#endif case QCRYPTO_CIPHER_ALG_AES_128: case QCRYPTO_CIPHER_ALG_AES_192: case QCRYPTO_CIPHER_ALG_AES_256: @@ -449,9 +456,11 @@ static QCryptoCipherBuiltin *qcrypto_cipher_ctx_new(QCryptoCipherAlgorithm alg, } switch (alg) { +#ifdef CONFIG_VNC case QCRYPTO_CIPHER_ALG_DES_RFB: ctxt = qcrypto_cipher_init_des_rfb(mode, key, nkey, errp); break; +#endif case QCRYPTO_CIPHER_ALG_AES_128: case QCRYPTO_CIPHER_ALG_AES_192: case QCRYPTO_CIPHER_ALG_AES_256: diff --git a/crypto/cipher-gcrypt.c b/crypto/cipher-gcrypt.c index 3e46ee7502..18c01ca424 100644 --- a/crypto/cipher-gcrypt.c +++ b/crypto/cipher-gcrypt.c @@ -29,7 +29,9 @@ bool qcrypto_cipher_supports(QCryptoCipherAlgorithm alg, QCryptoCipherMode mode) { switch (alg) { +#ifdef CONFIG_VNC case QCRYPTO_CIPHER_ALG_DES_RFB: +#endif case QCRYPTO_CIPHER_ALG_3DES: case QCRYPTO_CIPHER_ALG_AES_128: case QCRYPTO_CIPHER_ALG_AES_192: @@ -114,10 +116,11 @@ static QCryptoCipherGcrypt *qcrypto_cipher_ctx_new(QCryptoCipherAlgorithm alg, } switch (alg) { +#ifdef CONFIG_VNC case QCRYPTO_CIPHER_ALG_DES_RFB: gcryalg = GCRY_CIPHER_DES; break; - +#endif case QCRYPTO_CIPHER_ALG_3DES: gcryalg = GCRY_CIPHER_3DES; break; @@ -181,6 +184,7 @@ static QCryptoCipherGcrypt *qcrypto_cipher_ctx_new(QCryptoCipherAlgorithm alg, } } +#ifdef CONFIG_VNC if (alg == QCRYPTO_CIPHER_ALG_DES_RFB) { /* We're using standard DES cipher from gcrypt, so we need * to munge the key so that the results are the same as the @@ -190,7 +194,9 @@ static QCryptoCipherGcrypt *qcrypto_cipher_ctx_new(QCryptoCipherAlgorithm alg, err = gcry_cipher_setkey(ctx->handle, rfbkey, nkey); g_free(rfbkey); ctx->blocksize = 8; - } else { + } else +#endif /* CONFIG_VNC */ + { if (mode == QCRYPTO_CIPHER_MODE_XTS) { nkey /= 2; err = gcry_cipher_setkey(ctx->handle, key, nkey); diff --git a/crypto/cipher-nettle.c b/crypto/cipher-nettle.c index 5e70c7984a..7b14f23f7e 100644 --- a/crypto/cipher-nettle.c +++ b/crypto/cipher-nettle.c @@ -67,6 +67,7 @@ static void aes_decrypt_native(cipher_ctx_t ctx, cipher_length_t length, aes_decrypt(&aesctx->dec, length, dst, src); } +#ifdef CONFIG_VNC static void des_encrypt_native(cipher_ctx_t ctx, cipher_length_t length, uint8_t *dst, const uint8_t *src) { @@ -78,6 +79,7 @@ static void des_decrypt_native(cipher_ctx_t ctx, cipher_length_t length, { des_decrypt(ctx, length, dst, src); } +#endif static void des3_encrypt_native(cipher_ctx_t ctx, cipher_length_t length, uint8_t *dst, const uint8_t *src) @@ -141,6 +143,7 @@ static void aes_decrypt_wrapper(const void *ctx, size_t length, aes_decrypt(&aesctx->dec, length, dst, src); } +#ifdef CONFIG_VNC static void des_encrypt_wrapper(const void *ctx, size_t length, uint8_t *dst, const uint8_t *src) { @@ -152,6 +155,7 @@ static void des_decrypt_wrapper(const void *ctx, size_t length, { des_decrypt(ctx, length, dst, src); } +#endif static void des3_encrypt_wrapper(const void *ctx, size_t length, uint8_t *dst, const uint8_t *src) @@ -221,7 +225,9 @@ bool qcrypto_cipher_supports(QCryptoCipherAlgorithm alg, QCryptoCipherMode mode) { switch (alg) { +#ifdef CONFIG_VNC case QCRYPTO_CIPHER_ALG_DES_RFB: +#endif case QCRYPTO_CIPHER_ALG_3DES: case QCRYPTO_CIPHER_ALG_AES_128: case QCRYPTO_CIPHER_ALG_AES_192: @@ -271,7 +277,6 @@ static QCryptoCipherNettle *qcrypto_cipher_ctx_new(QCryptoCipherAlgorithm alg, Error **errp) { QCryptoCipherNettle *ctx; - uint8_t *rfbkey; switch (mode) { case QCRYPTO_CIPHER_MODE_ECB: @@ -292,7 +297,9 @@ static QCryptoCipherNettle *qcrypto_cipher_ctx_new(QCryptoCipherAlgorithm alg, ctx = g_new0(QCryptoCipherNettle, 1); switch (alg) { - case QCRYPTO_CIPHER_ALG_DES_RFB: +#ifdef CONFIG_VNC + case QCRYPTO_CIPHER_ALG_DES_RFB: { + uint8_t *rfbkey; ctx->ctx = g_new0(struct des_ctx, 1); rfbkey = qcrypto_cipher_munge_des_rfb_key(key, nkey); des_set_key(ctx->ctx, rfbkey); @@ -305,7 +312,8 @@ static QCryptoCipherNettle *qcrypto_cipher_ctx_new(QCryptoCipherAlgorithm alg, ctx->blocksize = DES_BLOCK_SIZE; break; - + } +#endif case QCRYPTO_CIPHER_ALG_3DES: ctx->ctx = g_new0(struct des3_ctx, 1); des3_set_key(ctx->ctx, key); diff --git a/crypto/cipher.c b/crypto/cipher.c index 43291cba7e..3e39882b7c 100644 --- a/crypto/cipher.c +++ b/crypto/cipher.c @@ -29,7 +29,9 @@ static size_t alg_key_len[QCRYPTO_CIPHER_ALG__MAX] = { [QCRYPTO_CIPHER_ALG_AES_128] = 16, [QCRYPTO_CIPHER_ALG_AES_192] = 24, [QCRYPTO_CIPHER_ALG_AES_256] = 32, +#ifdef CONFIG_VNC [QCRYPTO_CIPHER_ALG_DES_RFB] = 8, +#endif [QCRYPTO_CIPHER_ALG_3DES] = 24, [QCRYPTO_CIPHER_ALG_CAST5_128] = 16, [QCRYPTO_CIPHER_ALG_SERPENT_128] = 16, @@ -44,7 +46,9 @@ static size_t alg_block_len[QCRYPTO_CIPHER_ALG__MAX] = { [QCRYPTO_CIPHER_ALG_AES_128] = 16, [QCRYPTO_CIPHER_ALG_AES_192] = 16, [QCRYPTO_CIPHER_ALG_AES_256] = 16, +#ifdef CONFIG_VNC [QCRYPTO_CIPHER_ALG_DES_RFB] = 8, +#endif [QCRYPTO_CIPHER_ALG_3DES] = 8, [QCRYPTO_CIPHER_ALG_CAST5_128] = 8, [QCRYPTO_CIPHER_ALG_SERPENT_128] = 16, @@ -107,8 +111,11 @@ qcrypto_cipher_validate_key_length(QCryptoCipherAlgorithm alg, } if (mode == QCRYPTO_CIPHER_MODE_XTS) { - if (alg == QCRYPTO_CIPHER_ALG_DES_RFB - || alg == QCRYPTO_CIPHER_ALG_3DES) { + if ( +#ifdef CONFIG_VNC + alg == QCRYPTO_CIPHER_ALG_DES_RFB || +#endif + alg == QCRYPTO_CIPHER_ALG_3DES) { error_setg(errp, "XTS mode not compatible with DES-RFB/3DES"); return false; } @@ -132,6 +139,7 @@ qcrypto_cipher_validate_key_length(QCryptoCipherAlgorithm alg, return true; } +#if defined(CONFIG_VNC) #if defined(CONFIG_GCRYPT) || defined(CONFIG_NETTLE) static uint8_t * qcrypto_cipher_munge_des_rfb_key(const uint8_t *key, @@ -149,6 +157,7 @@ qcrypto_cipher_munge_des_rfb_key(const uint8_t *key, return ret; } #endif /* CONFIG_GCRYPT || CONFIG_NETTLE */ +#endif /* CONFIG_VNC */ #ifdef CONFIG_GCRYPT #include "crypto/cipher-gcrypt.c" diff --git a/hmp.c b/hmp.c index 0eb318f938..bb0a695f2d 100644 --- a/hmp.c +++ b/hmp.c @@ -620,6 +620,7 @@ void hmp_info_blockstats(Monitor *mon, const QDict *qdict) qapi_free_BlockStatsList(stats_list); } +#ifdef CONFIG_VNC /* Helper for hmp_info_vnc_clients, _servers */ static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info, const char *name) @@ -708,6 +709,7 @@ void hmp_info_vnc(Monitor *mon, const QDict *qdict) qapi_free_VncInfo2List(info2l); } +#endif #ifdef CONFIG_SPICE void hmp_info_spice(Monitor *mon, const QDict *qdict) @@ -1718,12 +1720,14 @@ void hmp_eject(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, &err); } +#ifdef CONFIG_VNC static void hmp_change_read_arg(void *opaque, const char *password, void *readline_opaque) { qmp_change_vnc_password(password, NULL); monitor_read_command(opaque, 1); } +#endif void hmp_change(Monitor *mon, const QDict *qdict) { @@ -1734,6 +1738,7 @@ void hmp_change(Monitor *mon, const QDict *qdict) BlockdevChangeReadOnlyMode read_only_mode = 0; Error *err = NULL; +#ifdef CONFIG_VNC if (strcmp(device, "vnc") == 0) { if (read_only) { monitor_printf(mon, @@ -1748,7 +1753,9 @@ void hmp_change(Monitor *mon, const QDict *qdict) } } qmp_change("vnc", target, !!arg, arg, &err); - } else { + } else +#endif + { if (read_only) { read_only_mode = qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup, read_only, BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err); diff --git a/qmp.c b/qmp.c index b86201e349..2c90dacb56 100644 --- a/qmp.c +++ b/qmp.c @@ -130,22 +130,6 @@ void qmp_cpu_add(int64_t id, Error **errp) } } -#ifndef CONFIG_VNC -/* If VNC support is enabled, the "true" query-vnc command is - defined in the VNC subsystem */ -VncInfo *qmp_query_vnc(Error **errp) -{ - error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); - return NULL; -}; - -VncInfo2List *qmp_query_vnc_servers(Error **errp) -{ - error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); - return NULL; -}; -#endif - #ifndef CONFIG_SPICE /* * qmp-commands.hx ensures that QMP command query-spice exists only @@ -403,23 +387,17 @@ static void qmp_change_vnc(const char *target, bool has_arg, const char *arg, qmp_change_vnc_listen(target, errp); } } -#else -void qmp_change_vnc_password(const char *password, Error **errp) -{ - error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); -} -static void qmp_change_vnc(const char *target, bool has_arg, const char *arg, - Error **errp) -{ - error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); -} #endif /* !CONFIG_VNC */ void qmp_change(const char *device, const char *target, bool has_arg, const char *arg, Error **errp) { if (strcmp(device, "vnc") == 0) { +#ifdef CONFIG_VNC qmp_change_vnc(target, has_arg, arg, errp); +#else + error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); +#endif } else { qmp_blockdev_change_medium(true, device, false, NULL, target, has_arg, arg, false, 0, errp); diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index d9df238a5f..2fb7a556a3 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -419,6 +419,7 @@ STEXI Show which guest mouse is receiving events. ETEXI +#if defined(CONFIG_VNC) { .name = "vnc", .args_type = "", @@ -426,6 +427,7 @@ ETEXI .help = "show the vnc server status", .cmd = hmp_info_vnc, }, +#endif STEXI @item info vnc -- 2.14.1.146.gd35faa819