summaryrefslogtreecommitdiffstats
path: root/authz/simple.c
blob: 0597dcd8ea5a3a2ad3611a37df11177a24d9d490 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * QEMU simple authorization driver
 *
 * Copyright (c) 2018 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
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "qemu/osdep.h"
#include "authz/simple.h"
#include "trace.h"
#include "qemu/module.h"
#include "qom/object_interfaces.h"

static bool qauthz_simple_is_allowed(QAuthZ *authz,
                                     const char *identity,
                                     Error **errp)
{
    QAuthZSimple *sauthz = QAUTHZ_SIMPLE(authz);

    trace_qauthz_simple_is_allowed(authz, sauthz->identity, identity);
    return g_str_equal(identity, sauthz->identity);
}

static void
qauthz_simple_prop_set_identity(Object *obj,
                                const char *value,
                                Error **errp G_GNUC_UNUSED)
{
    QAuthZSimple *sauthz = QAUTHZ_SIMPLE(obj);

    g_free(sauthz->identity);
    sauthz->identity = g_strdup(value);
}


static char *
qauthz_simple_prop_get_identity(Object *obj,
                                Error **errp G_GNUC_UNUSED)
{
    QAuthZSimple *sauthz = QAUTHZ_SIMPLE(obj);

    return g_strdup(sauthz->identity);
}


static void
qauthz_simple_finalize(Object *obj)
{
    QAuthZSimple *sauthz = QAUTHZ_SIMPLE(obj);

    g_free(sauthz->identity);
}


static void
qauthz_simple_complete(UserCreatable *uc, Error **errp)
{
    QAuthZSimple *sauthz = QAUTHZ_SIMPLE(uc);

    if (!sauthz->identity) {
        error_setg(errp, "The 'identity' property must be set");
        return;
    }
}


static void
qauthz_simple_class_init(ObjectClass *oc, void *data)
{
    QAuthZClass *authz = QAUTHZ_CLASS(oc);
    UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);

    ucc->complete = qauthz_simple_complete;
    authz->is_allowed = qauthz_simple_is_allowed;

    object_class_property_add_str(oc, "identity",
                                  qauthz_simple_prop_get_identity,
                                  qauthz_simple_prop_set_identity);
}


QAuthZSimple *qauthz_simple_new(const char *id,
                                const char *identity,
                                Error **errp)
{
    return QAUTHZ_SIMPLE(
        object_new_with_props(TYPE_QAUTHZ_SIMPLE,
                              object_get_objects_root(),
                              id, errp,
                              "identity", identity,
                              NULL));
}


static const TypeInfo qauthz_simple_info = {
    .parent = TYPE_QAUTHZ,
    .name = TYPE_QAUTHZ_SIMPLE,
    .instance_size = sizeof(QAuthZSimple),
    .instance_finalize = qauthz_simple_finalize,
    .class_init = qauthz_simple_class_init,
    .interfaces = (InterfaceInfo[]) {
        { TYPE_USER_CREATABLE },
        { }
    }
};


static void
qauthz_simple_register_types(void)
{
    type_register_static(&qauthz_simple_info);
}


type_init(qauthz_simple_register_types);
'n451' href='#n451'>451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246
# -*- Mode: Python -*-
# vim: filetype=python
#

##
# = Remote desktop
##

{ 'include': 'common.json' }
{ 'include': 'sockets.json' }

##
# @set_password:
#
# Sets the password of a remote display session.
#
# @protocol: - 'vnc' to modify the VNC server password
#            - 'spice' to modify the Spice server password
#
# @password: the new password
#
# @connected: how to handle existing clients when changing the
#             password.  If nothing is specified, defaults to 'keep'
#             'fail' to fail the command if clients are connected
#             'disconnect' to disconnect existing clients
#             'keep' to maintain existing clients
#
# Returns: - Nothing on success
#          - If Spice is not enabled, DeviceNotFound
#
# Since: 0.14
#
# Example:
#
# -> { "execute": "set_password", "arguments": { "protocol": "vnc",
#                                                "password": "secret" } }
# <- { "return": {} }
#
##
{ 'command': 'set_password',
  'data': {'protocol': 'str', 'password': 'str', '*connected': 'str'} }

##
# @expire_password:
#
# Expire the password of a remote display server.
#
# @protocol: the name of the remote display protocol 'vnc' or 'spice'
#
# @time: when to expire the password.
#
#        - 'now' to expire the password immediately
#        - 'never' to cancel password expiration
#        - '+INT' where INT is the number of seconds from now (integer)
#        - 'INT' where INT is the absolute time in seconds
#
# Returns: - Nothing on success
#          - If @protocol is 'spice' and Spice is not active, DeviceNotFound
#
# Since: 0.14
#
# Notes: Time is relative to the server and currently there is no way to
#        coordinate server time with client time.  It is not recommended to
#        use the absolute time version of the @time parameter unless you're
#        sure you are on the same machine as the QEMU instance.
#
# Example:
#
# -> { "execute": "expire_password", "arguments": { "protocol": "vnc",
#                                                   "time": "+60" } }
# <- { "return": {} }
#
##
{ 'command': 'expire_password', 'data': {'protocol': 'str', 'time': 'str'} }

##
# @screendump:
#
# Write a PPM of the VGA screen to a file.
#
# @filename: the path of a new PPM file to store the image
#
# @device: ID of the display device that should be dumped. If this parameter
#          is missing, the primary display will be used. (Since 2.12)
#
# @head: head to use in case the device supports multiple heads. If this
#        parameter is missing, head #0 will be used. Also note that the head
#        can only be specified in conjunction with the device ID. (Since 2.12)
#
# Returns: Nothing on success
#
# Since: 0.14
#
# Example:
#
# -> { "execute": "screendump",
#      "arguments": { "filename": "/tmp/image" } }
# <- { "return": {} }
#
##
{ 'command': 'screendump',
  'data': {'filename': 'str', '*device': 'str', '*head': 'int'},
  'coroutine': true }

##
# == Spice
##

##
# @SpiceBasicInfo:
#
# The basic information for SPICE network connection
#
# @host: IP address
#
# @port: port number
#
# @family: address family
#
# Since: 2.1
##
{ 'struct': 'SpiceBasicInfo',
  'data': { 'host': 'str',
            'port': 'str',
            'family': 'NetworkAddressFamily' },
  'if': 'defined(CONFIG_SPICE)' }

##
# @SpiceServerInfo:
#
# Information about a SPICE server
#
# @auth: authentication method
#
# Since: 2.1
##
{ 'struct': 'SpiceServerInfo',
  'base': 'SpiceBasicInfo',
  'data': { '*auth': 'str' },
  'if': 'defined(CONFIG_SPICE)' }

##
# @SpiceChannel:
#
# Information about a SPICE client channel.
#
# @connection-id: SPICE connection id number.  All channels with the same id
#                 belong to the same SPICE session.
#
# @channel-type: SPICE channel type number.  "1" is the main control
#                channel, filter for this one if you want to track spice
#                sessions only
#
# @channel-id: SPICE channel ID number.  Usually "0", might be different when
#              multiple channels of the same type exist, such as multiple
#              display channels in a multihead setup
#
# @tls: true if the channel is encrypted, false otherwise.
#
# Since: 0.14
##
{ 'struct': 'SpiceChannel',
  'base': 'SpiceBasicInfo',
  'data': {'connection-id': 'int', 'channel-type': 'int', 'channel-id': 'int',
           'tls': 'bool'},
  'if': 'defined(CONFIG_SPICE)' }

##
# @SpiceQueryMouseMode:
#
# An enumeration of Spice mouse states.
#
# @client: Mouse cursor position is determined by the client.
#
# @server: Mouse cursor position is determined by the server.
#
# @unknown: No information is available about mouse mode used by
#           the spice server.
#
# Note: spice/enums.h has a SpiceMouseMode already, hence the name.
#
# Since: 1.1
##
{ 'enum': 'SpiceQueryMouseMode',
  'data': [ 'client', 'server', 'unknown' ],
  'if': 'defined(CONFIG_SPICE)' }

##
# @SpiceInfo:
#
# Information about the SPICE session.
#
# @enabled: true if the SPICE server is enabled, false otherwise
#
# @migrated: true if the last guest migration completed and spice
#            migration had completed as well. false otherwise. (since 1.4)
#
# @host: The hostname the SPICE server is bound to.  This depends on
#        the name resolution on the host and may be an IP address.
#
# @port: The SPICE server's port number.
#
# @compiled-version: SPICE server version.
#
# @tls-port: The SPICE server's TLS port number.
#
# @auth: the current authentication type used by the server
#
#        - 'none'  if no authentication is being used
#        - 'spice' uses SASL or direct TLS authentication, depending on command
#          line options
#
# @mouse-mode: The mode in which the mouse cursor is displayed currently. Can
#              be determined by the client or the server, or unknown if spice
#              server doesn't provide this information. (since: 1.1)
#
# @channels: a list of @SpiceChannel for each active spice channel
#
# Since: 0.14
##
{ 'struct': 'SpiceInfo',
  'data': {'enabled': 'bool', 'migrated': 'bool', '*host': 'str', '*port': 'int',
           '*tls-port': 'int', '*auth': 'str', '*compiled-version': 'str',
           'mouse-mode': 'SpiceQueryMouseMode', '*channels': ['SpiceChannel']},
  'if': 'defined(CONFIG_SPICE)' }

##
# @query-spice:
#
# Returns information about the current SPICE server
#
# Returns: @SpiceInfo
#
# Since: 0.14
#
# Example:
#
# -> { "execute": "query-spice" }
# <- { "return": {
#          "enabled": true,
#          "auth": "spice",
#          "port": 5920,
#          "tls-port": 5921,
#          "host": "0.0.0.0",
#          "channels": [
#             {
#                "port": "54924",
#                "family": "ipv4",
#                "channel-type": 1,
#                "connection-id": 1804289383,
#                "host": "127.0.0.1",
#                "channel-id": 0,
#                "tls": true
#             },
#             {
#                "port": "36710",
#                "family": "ipv4",
#                "channel-type": 4,
#                "connection-id": 1804289383,
#                "host": "127.0.0.1",
#                "channel-id": 0,
#                "tls": false
#             },
#             [ ... more channels follow ... ]
#          ]
#       }
#    }
#
##
{ 'command': 'query-spice', 'returns': 'SpiceInfo',
  'if': 'defined(CONFIG_SPICE)' }

##
# @SPICE_CONNECTED:
#
# Emitted when a SPICE client establishes a connection
#
# @server: server information
#
# @client: client information
#
# Since: 0.14
#
# Example:
#
# <- { "timestamp": {"seconds": 1290688046, "microseconds": 388707},
#      "event": "SPICE_CONNECTED",
#      "data": {
#        "server": { "port": "5920", "family": "ipv4", "host": "127.0.0.1"},
#        "client": {"port": "52873", "family": "ipv4", "host": "127.0.0.1"}
#    }}
#
##
{ 'event': 'SPICE_CONNECTED',
  'data': { 'server': 'SpiceBasicInfo',
            'client': 'SpiceBasicInfo' },
  'if': 'defined(CONFIG_SPICE)' }

##
# @SPICE_INITIALIZED:
#
# Emitted after initial handshake and authentication takes place (if any)
# and the SPICE channel is up and running
#
# @server: server information
#
# @client: client information
#
# Since: 0.14
#
# Example:
#
# <- { "timestamp": {"seconds": 1290688046, "microseconds": 417172},
#      "event": "SPICE_INITIALIZED",
#      "data": {"server": {"auth": "spice", "port": "5921",
#                          "family": "ipv4", "host": "127.0.0.1"},
#               "client": {"port": "49004", "family": "ipv4", "channel-type": 3,
#                          "connection-id": 1804289383, "host": "127.0.0.1",
#                          "channel-id": 0, "tls": true}
#    }}
#
##
{ 'event': 'SPICE_INITIALIZED',
  'data': { 'server': 'SpiceServerInfo',
            'client': 'SpiceChannel' },
  'if': 'defined(CONFIG_SPICE)' }

##
# @SPICE_DISCONNECTED:
#
# Emitted when the SPICE connection is closed
#
# @server: server information
#
# @client: client information
#
# Since: 0.14
#
# Example:
#
# <- { "timestamp": {"seconds": 1290688046, "microseconds": 388707},
#      "event": "SPICE_DISCONNECTED",
#      "data": {
#        "server": { "port": "5920", "family": "ipv4", "host": "127.0.0.1"},
#        "client": {"port": "52873", "family": "ipv4", "host": "127.0.0.1"}
#    }}
#
##
{ 'event': 'SPICE_DISCONNECTED',
  'data': { 'server': 'SpiceBasicInfo',
            'client': 'SpiceBasicInfo' },
  'if': 'defined(CONFIG_SPICE)' }

##
# @SPICE_MIGRATE_COMPLETED:
#
# Emitted when SPICE migration has completed
#
# Since: 1.3
#
# Example:
#
# <- { "timestamp": {"seconds": 1290688046, "microseconds": 417172},
#      "event": "SPICE_MIGRATE_COMPLETED" }
#
##
{ 'event': 'SPICE_MIGRATE_COMPLETED',
  'if': 'defined(CONFIG_SPICE)' }

##
# == VNC
##

##
# @VncBasicInfo:
#
# The basic information for vnc network connection
#
# @host: IP address
#
# @service: The service name of the vnc port. This may depend on the host
#           system's service database so symbolic names should not be relied
#           on.
#
# @family: address family
#
# @websocket: true in case the socket is a websocket (since 2.3).
#
# Since: 2.1
##
{ 'struct': 'VncBasicInfo',
  'data': { 'host': 'str',
            'service': 'str',
            'family': 'NetworkAddressFamily',
            'websocket': 'bool' },
  'if': 'defined(CONFIG_VNC)' }

##
# @VncServerInfo:
#
# The network connection information for server
#
# @auth: authentication method used for
#        the plain (non-websocket) VNC server
#
# Since: 2.1
##
{ 'struct': 'VncServerInfo',
  'base': 'VncBasicInfo',
  'data': { '*auth': 'str' },
  'if': 'defined(CONFIG_VNC)' }

##
# @VncClientInfo:
#
# Information about a connected VNC client.
#
# @x509_dname: If x509 authentication is in use, the Distinguished
#              Name of the client.
#
# @sasl_username: If SASL authentication is in use, the SASL username
#                 used for authentication.
#
# Since: 0.14
##
{ 'struct': 'VncClientInfo',
  'base': 'VncBasicInfo',
  'data': { '*x509_dname': 'str', '*sasl_username': 'str' },
  'if': 'defined(CONFIG_VNC)' }

##
# @VncInfo:
#
# Information about the VNC session.
#
# @enabled: true if the VNC server is enabled, false otherwise
#
# @host: The hostname the VNC server is bound to.  This depends on
#        the name resolution on the host and may be an IP address.
#
# @family: - 'ipv6' if the host is listening for IPv6 connections
#          - 'ipv4' if the host is listening for IPv4 connections
#          - 'unix' if the host is listening on a unix domain socket
#          - 'unknown' otherwise
#
# @service: The service name of the server's port.  This may depends
#           on the host system's service database so symbolic names should not
#           be relied on.
#
# @auth: the current authentication type used by the server
#
#        - 'none' if no authentication is being used
#        - 'vnc' if VNC authentication is being used
#        - 'vencrypt+plain' if VEncrypt is used with plain text authentication
#        - 'vencrypt+tls+none' if VEncrypt is used with TLS and no authentication
#        - 'vencrypt+tls+vnc' if VEncrypt is used with TLS and VNC authentication
#        - 'vencrypt+tls+plain' if VEncrypt is used with TLS and plain text auth
#        - 'vencrypt+x509+none' if VEncrypt is used with x509 and no auth
#        - 'vencrypt+x509+vnc' if VEncrypt is used with x509 and VNC auth
#        - 'vencrypt+x509+plain' if VEncrypt is used with x509 and plain text auth
#        - 'vencrypt+tls+sasl' if VEncrypt is used with TLS and SASL auth
#        - 'vencrypt+x509+sasl' if VEncrypt is used with x509 and SASL auth
#
# @clients: a list of @VncClientInfo of all currently connected clients
#
# Since: 0.14
##
{ 'struct': 'VncInfo',
  'data': {'enabled': 'bool', '*host': 'str',
           '*family': 'NetworkAddressFamily',
           '*service': 'str', '*auth': 'str', '*clients': ['VncClientInfo']},
  'if': 'defined(CONFIG_VNC)' }

##
# @VncPrimaryAuth:
#
# vnc primary authentication method.
#
# Since: 2.3
##
{ 'enum': 'VncPrimaryAuth',
  'data': [ 'none', 'vnc', 'ra2', 'ra2ne', 'tight', 'ultra',
            'tls', 'vencrypt', 'sasl' ],
  'if': 'defined(CONFIG_VNC)' }

##
# @VncVencryptSubAuth:
#
# vnc sub authentication method with vencrypt.
#
# Since: 2.3
##
{ 'enum': 'VncVencryptSubAuth',
  'data': [ 'plain',
            'tls-none',  'x509-none',
            'tls-vnc',   'x509-vnc',
            'tls-plain', 'x509-plain',
            'tls-sasl',  'x509-sasl' ],
  'if': 'defined(CONFIG_VNC)' }

##
# @VncServerInfo2:
#
# The network connection information for server
#
# @auth: The current authentication type used by the servers
#
# @vencrypt: The vencrypt sub authentication type used by the
#            servers, only specified in case auth == vencrypt.
#
# Since: 2.9
##
{ 'struct': 'VncServerInfo2',
  'base': 'VncBasicInfo',
  'data': { 'auth'      : 'VncPrimaryAuth',
            '*vencrypt' : 'VncVencryptSubAuth' },
  'if': 'defined(CONFIG_VNC)' }

##
# @VncInfo2:
#
# Information about a vnc server
#
# @id: vnc server name.
#
# @server: A list of @VncBasincInfo describing all listening sockets.
#          The list can be empty (in case the vnc server is disabled).
#          It also may have multiple entries: normal + websocket,
#          possibly also ipv4 + ipv6 in the future.
#
# @clients: A list of @VncClientInfo of all currently connected clients.
#           The list can be empty, for obvious reasons.
#
# @auth: The current authentication type used by the non-websockets servers
#
# @vencrypt: The vencrypt authentication type used by the servers,
#            only specified in case auth == vencrypt.
#
# @display: The display device the vnc server is linked to.
#
# Since: 2.3
##
{ 'struct': 'VncInfo2',
  'data': { 'id'        : 'str',
            'server'    : ['VncServerInfo2'],
            'clients'   : ['VncClientInfo'],
            'auth'      : 'VncPrimaryAuth',
            '*vencrypt' : 'VncVencryptSubAuth',
            '*display'  : 'str' },
  'if': 'defined(CONFIG_VNC)' }

##
# @query-vnc:
#
# Returns information about the current VNC server
#
# Returns: @VncInfo
#
# Since: 0.14
#
# Example:
#
# -> { "execute": "query-vnc" }
# <- { "return": {
#          "enabled":true,
#          "host":"0.0.0.0",
#          "service":"50402",
#          "auth":"vnc",
#          "family":"ipv4",
#          "clients":[
#             {
#                "host":"127.0.0.1",
#                "service":"50401",
#                "family":"ipv4"
#             }
#          ]
#       }
#    }
#
##
{ 'command': 'query-vnc', 'returns': 'VncInfo',
  'if': 'defined(CONFIG_VNC)' }
##
# @query-vnc-servers:
#
# Returns a list of vnc servers.  The list can be empty.
#
# Returns: a list of @VncInfo2
#
# Since: 2.3
##
{ 'command': 'query-vnc-servers', 'returns': ['VncInfo2'],
  'if': 'defined(CONFIG_VNC)' }

##
# @change-vnc-password:
#
# Change the VNC server password.
#
# @password: the new password to use with VNC authentication
#
# Since: 1.1
#
# 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' },
  'if': 'defined(CONFIG_VNC)' }

##
# @VNC_CONNECTED:
#
# Emitted when a VNC client establishes a connection
#
# @server: server information
#
# @client: client information
#
# Note: This event is emitted before any authentication takes place, thus
#       the authentication ID is not provided
#
# Since: 0.13
#
# Example:
#
# <- { "event": "VNC_CONNECTED",
#      "data": {
#            "server": { "auth": "sasl", "family": "ipv4",
#                        "service": "5901", "host": "0.0.0.0" },
#            "client": { "family": "ipv4", "service": "58425",
#                        "host": "127.0.0.1" } },
#      "timestamp": { "seconds": 1262976601, "microseconds": 975795 } }
#
##
{ 'event': 'VNC_CONNECTED',
  'data': { 'server': 'VncServerInfo',
            'client': 'VncBasicInfo' },
  'if': 'defined(CONFIG_VNC)' }

##
# @VNC_INITIALIZED:
#
# Emitted after authentication takes place (if any) and the VNC session is
# made active
#
# @server: server information
#
# @client: client information
#
# Since: 0.13
#
# Example:
#
# <-  { "event": "VNC_INITIALIZED",
#       "data": {
#            "server": { "auth": "sasl", "family": "ipv4",
#                        "service": "5901", "host": "0.0.0.0"},
#            "client": { "family": "ipv4", "service": "46089",
#                        "host": "127.0.0.1", "sasl_username": "luiz" } },
#       "timestamp": { "seconds": 1263475302, "microseconds": 150772 } }
#
##
{ 'event': 'VNC_INITIALIZED',
  'data': { 'server': 'VncServerInfo',
            'client': 'VncClientInfo' },
  'if': 'defined(CONFIG_VNC)' }

##
# @VNC_DISCONNECTED:
#
# Emitted when the connection is closed
#
# @server: server information
#
# @client: client information
#
# Since: 0.13
#
# Example:
#
# <- { "event": "VNC_DISCONNECTED",
#      "data": {
#            "server": { "auth": "sasl", "family": "ipv4",
#                        "service": "5901", "host": "0.0.0.0" },
#            "client": { "family": "ipv4", "service": "58425",
#                        "host": "127.0.0.1", "sasl_username": "luiz" } },
#      "timestamp": { "seconds": 1262976601, "microseconds": 975795 } }
#
##
{ 'event': 'VNC_DISCONNECTED',
  'data': { 'server': 'VncServerInfo',
            'client': 'VncClientInfo' },
  'if': 'defined(CONFIG_VNC)' }

##
# = Input
##

##
# @MouseInfo:
#
# Information about a mouse device.
#
# @name: the name of the mouse device
#
# @index: the index of the mouse device
#
# @current: true if this device is currently receiving mouse events
#
# @absolute: true if this device supports absolute coordinates as input
#
# Since: 0.14
##
{ 'struct': 'MouseInfo',
  'data': {'name': 'str', 'index': 'int', 'current': 'bool',
           'absolute': 'bool'} }

##
# @query-mice:
#
# Returns information about each active mouse device
#
# Returns: a list of @MouseInfo for each device
#
# Since: 0.14
#
# Example:
#
# -> { "execute": "query-mice" }
# <- { "return": [
#          {
#             "name":"QEMU Microsoft Mouse",
#             "index":0,
#             "current":false,
#             "absolute":false
#          },
#          {
#             "name":"QEMU PS/2 Mouse",
#             "index":1,
#             "current":true,
#             "absolute":true
#          }
#       ]
#    }
#
##
{ 'command': 'query-mice', 'returns': ['MouseInfo'] }

##
# @QKeyCode:
#
# An enumeration of key name.
#
# This is used by the @send-key command.
#
# @unmapped: since 2.0
# @pause: since 2.0
# @ro: since 2.4
# @kp_comma: since 2.4
# @kp_equals: since 2.6
# @power: since 2.6
# @hiragana: since 2.9
# @henkan: since 2.9
# @yen: since 2.9
#
# @sleep: since 2.10
# @wake: since 2.10
# @audionext: since 2.10
# @audioprev: since 2.10
# @audiostop: since 2.10
# @audioplay: since 2.10
# @audiomute: since 2.10
# @volumeup: since 2.10
# @volumedown: since 2.10
# @mediaselect: since 2.10
# @mail: since 2.10
# @calculator: since 2.10
# @computer: since 2.10
# @ac_home: since 2.10
# @ac_back: since 2.10
# @ac_forward: since 2.10
# @ac_refresh: since 2.10
# @ac_bookmarks: since 2.10
#
# @muhenkan: since 2.12
# @katakanahiragana: since 2.12
#
# @lang1: since 6.1
# @lang2: since 6.1
#
# 'sysrq' was mistakenly added to hack around the fact that
# the ps2 driver was not generating correct scancodes sequences
# when 'alt+print' was pressed. This flaw is now fixed and the
# 'sysrq' key serves no further purpose. Any further use of
# 'sysrq' will be transparently changed to 'print', so they
# are effectively synonyms.
#
# Since: 1.3
#
##
{ 'enum': 'QKeyCode',
  'data': [ 'unmapped',
            'shift', 'shift_r', 'alt', 'alt_r', 'ctrl',
            'ctrl_r', 'menu', 'esc', '1', '2', '3', '4', '5', '6', '7', '8',
            '9', '0', 'minus', 'equal', 'backspace', 'tab', 'q', 'w', 'e',
            'r', 't', 'y', 'u', 'i', 'o', 'p', 'bracket_left', 'bracket_right',
            'ret', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'semicolon',
            'apostrophe', 'grave_accent', 'backslash', 'z', 'x', 'c', 'v', 'b',
            'n', 'm', 'comma', 'dot', 'slash', 'asterisk', 'spc', 'caps_lock',
            'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'f10',
            'num_lock', 'scroll_lock', 'kp_divide', 'kp_multiply',
            'kp_subtract', 'kp_add', 'kp_enter', 'kp_decimal', 'sysrq', 'kp_0',
            'kp_1', 'kp_2', 'kp_3', 'kp_4', 'kp_5', 'kp_6', 'kp_7', 'kp_8',
            'kp_9', 'less', 'f11', 'f12', 'print', 'home', 'pgup', 'pgdn', 'end',
            'left', 'up', 'down', 'right', 'insert', 'delete', 'stop', 'again',
            'props', 'undo', 'front', 'copy', 'open', 'paste', 'find', 'cut',
            'lf', 'help', 'meta_l', 'meta_r', 'compose', 'pause',
            'ro', 'hiragana', 'henkan', 'yen', 'muhenkan', 'katakanahiragana',
            'kp_comma', 'kp_equals', 'power', 'sleep', 'wake',
            'audionext', 'audioprev', 'audiostop', 'audioplay', 'audiomute',
            'volumeup', 'volumedown', 'mediaselect',
            'mail', 'calculator', 'computer',
            'ac_home', 'ac_back', 'ac_forward', 'ac_refresh', 'ac_bookmarks',
            'lang1', 'lang2' ] }

##
# @KeyValue:
#
# Represents a keyboard key.
#
# Since: 1.3
##
{ 'union': 'KeyValue',
  'data': {
    'number': 'int',
    'qcode': 'QKeyCode' } }

##
# @send-key:
#
# Send keys to guest.
#
# @keys: An array of @KeyValue elements. All @KeyValues in this array are
#        simultaneously sent to the guest. A @KeyValue.number value is sent
#        directly to the guest, while @KeyValue.qcode must be a valid
#        @QKeyCode value
#
# @hold-time: time to delay key up events, milliseconds. Defaults
#             to 100
#
# Returns: - Nothing on success
#          - If key is unknown or redundant, InvalidParameter
#
# Since: 1.3
#
# Example:
#
# -> { "execute": "send-key",
#      "arguments": { "keys": [ { "type": "qcode", "data": "ctrl" },
#                               { "type": "qcode", "data": "alt" },
#                               { "type": "qcode", "data": "delete" } ] } }
# <- { "return": {} }
#
##
{ 'command': 'send-key',
  'data': { 'keys': ['KeyValue'], '*hold-time': 'int' } }

##
# @InputButton:
#
# Button of a pointer input device (mouse, tablet).
#
# @side: front side button of a 5-button mouse (since 2.9)
#
# @extra: rear side button of a 5-button mouse (since 2.9)
#
# Since: 2.0
##
{ 'enum'  : 'InputButton',
  'data'  : [ 'left', 'middle', 'right', 'wheel-up', 'wheel-down', 'side',
  'extra' ] }

##
# @InputAxis:
#
# Position axis of a pointer input device (mouse, tablet).
#
# Since: 2.0
##
{ 'enum'  : 'InputAxis',
  'data'  : [ 'x', 'y' ] }

##
# @InputKeyEvent:
#
# Keyboard input event.
#
# @key:    Which key this event is for.
# @down:   True for key-down and false for key-up events.
#
# Since: 2.0
##
{ 'struct'  : 'InputKeyEvent',
  'data'  : { 'key'     : 'KeyValue',
              'down'    : 'bool' } }

##
# @InputBtnEvent:
#
# Pointer button input event.
#
# @button: Which button this event is for.
# @down:   True for key-down and false for key-up events.
#
# Since: 2.0
##
{ 'struct'  : 'InputBtnEvent',
  'data'  : { 'button'  : 'InputButton',
              'down'    : 'bool' } }

##
# @InputMoveEvent:
#
# Pointer motion input event.
#
# @axis: Which axis is referenced by @value.
# @value: Pointer position.  For absolute coordinates the
#         valid range is 0 -> 0x7ffff
#
# Since: 2.0
##
{ 'struct'  : 'InputMoveEvent',
  'data'  : { 'axis'    : 'InputAxis',
              'value'   : 'int' } }

##
# @InputEvent:
#
# Input event union.
#
# @type: the input type, one of:
#
#        - 'key': Input event of Keyboard
#        - 'btn': Input event of pointer buttons
#        - 'rel': Input event of relative pointer motion
#        - 'abs': Input event of absolute pointer motion
#
# Since: 2.0
##
{ 'union' : 'InputEvent',
  'data'  : { 'key'     : 'InputKeyEvent',
              'btn'     : 'InputBtnEvent',
              'rel'     : 'InputMoveEvent',
              'abs'     : 'InputMoveEvent' } }

##
# @input-send-event:
#
# Send input event(s) to guest.
#
# The @device and @head parameters can be used to send the input event
# to specific input devices in case (a) multiple input devices of the
# same kind are added to the virtual machine and (b) you have
# configured input routing (see docs/multiseat.txt) for those input
# devices.  The parameters work exactly like the device and head
# properties of input devices.  If @device is missing, only devices
# that have no input routing config are admissible.  If @device is
# specified, both input devices with and without input routing config
# are admissible, but devices with input routing config take
# precedence.
#
# @device: display device to send event(s) to.
# @head: head to send event(s) to, in case the
#        display device supports multiple scanouts.
# @events: List of InputEvent union.
#
# Returns: Nothing on success.
#
# Since: 2.6
#
# Note: The consoles are visible in the qom tree, under
#       /backend/console[$index]. They have a device link and head property,
#       so it is possible to map which console belongs to which device and
#       display.
#
# Example:
#
# 1. Press left mouse button.
#
# -> { "execute": "input-send-event",
#     "arguments": { "device": "video0",
#                    "events": [ { "type": "btn",
#                    "data" : { "down": true, "button": "left" } } ] } }
# <- { "return": {} }
#
# -> { "execute": "input-send-event",
#     "arguments": { "device": "video0",
#                    "events": [ { "type": "btn",
#                    "data" : { "down": false, "button": "left" } } ] } }
# <- { "return": {} }
#
# 2. Press ctrl-alt-del.
#
# -> { "execute": "input-send-event",
#      "arguments": { "events": [
#         { "type": "key", "data" : { "down": true,
#           "key": {"type": "qcode", "data": "ctrl" } } },
#         { "type": "key", "data" : { "down": true,
#           "key": {"type": "qcode", "data": "alt" } } },
#         { "type": "key", "data" : { "down": true,
#           "key": {"type": "qcode", "data": "delete" } } } ] } }
# <- { "return": {} }
#
# 3. Move mouse pointer to absolute coordinates (20000, 400).
#
# -> { "execute": "input-send-event" ,
#   "arguments": { "events": [
#                { "type": "abs", "data" : { "axis": "x", "value" : 20000 } },
#                { "type": "abs", "data" : { "axis": "y", "value" : 400 } } ] } }
# <- { "return": {} }
#
##
{ 'command': 'input-send-event',
  'data': { '*device': 'str',
            '*head'  : 'int',
            'events' : [ 'InputEvent' ] } }

##
# @DisplayGTK:
#
# GTK display options.
#
# @grab-on-hover: Grab keyboard input on mouse hover.
# @zoom-to-fit: Zoom guest display to fit into the host window.  When
#               turned off the host window will be resized instead.
#               In case the display device can notify the guest on
#               window resizes (virtio-gpu) this will default to "on",
#               assuming the guest will resize the display to match
#               the window size then.  Otherwise it defaults to "off".
#               Since 3.1
#
# Since: 2.12
#
##
{ 'struct'  : 'DisplayGTK',
  'data'    : { '*grab-on-hover' : 'bool',
                '*zoom-to-fit'   : 'bool'  } }

##
# @DisplayEGLHeadless:
#
# EGL headless display options.
#
# @rendernode: Which DRM render node should be used. Default is the first
#              available node on the host.
#
# Since: 3.1
#
##
{ 'struct'  : 'DisplayEGLHeadless',
  'data'    : { '*rendernode' : 'str' } }

 ##
 # @DisplayGLMode:
 #
 # Display OpenGL mode.
 #
 # @off: Disable OpenGL (default).
 # @on: Use OpenGL, pick context type automatically.
 #      Would better be named 'auto' but is called 'on' for backward
 #      compatibility with bool type.
 # @core: Use OpenGL with Core (desktop) Context.
 # @es: Use OpenGL with ES (embedded systems) Context.
 #
 # Since: 3.0
 #
 ##
{ 'enum'    : 'DisplayGLMode',
  'data'    : [ 'off', 'on', 'core', 'es' ] }

##
# @DisplayCurses:
#
# Curses display options.
#
# @charset:       Font charset used by guest (default: CP437).
#
# Since: 4.0
#
##
{ 'struct'  : 'DisplayCurses',
  'data'    : { '*charset'       : 'str' } }

##
# @DisplayType:
#
# Display (user interface) type.
#
# @default: The default user interface, selecting from the first available
#           of gtk, sdl, cocoa, and vnc.
#
# @none: No user interface or video output display. The guest will
#        still see an emulated graphics card, but its output will not
#        be displayed to the QEMU user.
#
# @gtk: The GTK user interface.
#
# @sdl: The SDL user interface.
#
# @egl-headless: No user interface, offload GL operations to a local
#                DRI device. Graphical display need to be paired with
#                VNC or Spice. (Since 3.1)
#
# @curses: Display video output via curses.  For graphics device
#          models which support a text mode, QEMU can display this
#          output using a curses/ncurses interface. Nothing is
#          displayed when the graphics device is in graphical mode or
#          if the graphics device does not support a text
#          mode. Generally only the VGA device models support text
#          mode.
#
# @cocoa: The Cocoa user interface.
#
# @spice-app: Set up a Spice server and run the default associated
#             application to connect to it. The server will redirect
#             the serial console and QEMU monitors. (Since 4.0)
#
# Since: 2.12
#
##
{ 'enum'    : 'DisplayType',
  'data'    : [
    { 'name': 'default' },
    { 'name': 'none' },
    { 'name': 'gtk', 'if': 'defined(CONFIG_GTK)' },
    { 'name': 'sdl', 'if': 'defined(CONFIG_SDL)' },
    { 'name': 'egl-headless',
              'if': 'defined(CONFIG_OPENGL) && defined(CONFIG_GBM)' },
    { 'name': 'curses', 'if': 'defined(CONFIG_CURSES)' },
    { 'name': 'cocoa', 'if': 'defined(CONFIG_COCOA)' },
    { 'name': 'spice-app', 'if': 'defined(CONFIG_SPICE)'} ] }

##
# @DisplayOptions:
#
# Display (user interface) options.
#
# @type:          Which DisplayType qemu should use.
# @full-screen:   Start user interface in fullscreen mode (default: off).
# @window-close:  Allow to quit qemu with window close button (default: on).
# @show-cursor:   Force showing the mouse cursor (default: off).
#                 (since: 5.0)
# @gl:            Enable OpenGL support (default: off).
#
# Since: 2.12
#
##
{ 'union'   : 'DisplayOptions',
  'base'    : { 'type'           : 'DisplayType',
                '*full-screen'   : 'bool',
                '*window-close'  : 'bool',
                '*show-cursor'   : 'bool',
                '*gl'            : 'DisplayGLMode' },
  'discriminator' : 'type',
  'data'    : {
      'gtk': { 'type': 'DisplayGTK', 'if': 'defined(CONFIG_GTK)' },
      'curses': { 'type': 'DisplayCurses', 'if': 'defined(CONFIG_CURSES)' },
      'egl-headless': { 'type': 'DisplayEGLHeadless',
                        'if': 'defined(CONFIG_OPENGL) && defined(CONFIG_GBM)' }
  }
}

##
# @query-display-options:
#
# Returns information about display configuration
#
# Returns: @DisplayOptions
#
# Since: 3.1
#
##
{ 'command': 'query-display-options',
  'returns': 'DisplayOptions' }

##
# @DisplayReloadType:
#
# Available DisplayReload types.
#
# @vnc: VNC display
#
# Since: 6.0
#
##
{ 'enum': 'DisplayReloadType',
  'data': ['vnc'] }

##
# @DisplayReloadOptionsVNC:
#
# Specify the VNC reload options.
#
# @tls-certs: reload tls certs or not.
#
# Since: 6.0
#
##
{ 'struct': 'DisplayReloadOptionsVNC',
  'data': { '*tls-certs': 'bool' } }

##
# @DisplayReloadOptions:
#
# Options of the display configuration reload.
#
# @type: Specify the display type.
#
# Since: 6.0
#
##
{ 'union': 'DisplayReloadOptions',
  'base': {'type': 'DisplayReloadType'},
  'discriminator': 'type',
  'data': { 'vnc': 'DisplayReloadOptionsVNC' } }

##
# @display-reload:
#
# Reload display configuration.
#
# Returns: Nothing on success.
#
# Since: 6.0
#
# Example:
#
# -> { "execute": "display-reload",
#      "arguments": { "type": "vnc", "tls-certs": true  } }
# <- { "return": {} }
#
##
{ 'command': 'display-reload',
  'data': 'DisplayReloadOptions',
  'boxed' : true }