PATCH: 0/9: Support SASL authentication in VNC server (version 3)
Previously I provided patches for QEMU's VNC server to support SSL/TLS and x509 certificates. This provides good encryption capabilities for the VNC session. It doesn't really address the authentication problem though.
I have been working to create a new authentication type in the RFB protocol to address this need in a generic, extendable way, by mapping the SASL API into the RFB protocol. Since SASL is a generic plugin based API, this will allow use of a huge range of auth mechanims over VNC, without us having to add any more auth code. For example, PAM, Digest-MD5, GSSAPI/Kerberos, One-time key/password, LDAP password lookup, SQL db password lookup, and more.
I have got a VNC auth type assigned by the RFB spec maintainers:
http://realvnc.com/pipermail/vnc-list/2008-December/059463.html
With the full current spec for the SASL extension currently documented here:
http://realvnc.com/pipermail/vnc-list/2008-December/059462.html
This is the 3rd version of the patches I previously posted:
v1: http://lists.gnu.org/archive/html/qemu-devel/2009-02/msg00255.html
v2: http://lists.gnu.org/archive/html/qemu-devel/2009-02/msg00826.html
Changes since last time
- Split the keymap refactoring out into separate patch
- Switch to use sys-queue.h TAILQ for ACL management
- Added monitor command to remove an ACL entry
- Misc minor bug fixes
- Adjust to cope with multiple client connections
The combined diffstat for all 9 patches about to follow, is
Makefile | 27 + Makefile.target | 5 b/acl.c | 274 ++++++++++++ b/acl.h | 77 +++ b/keymaps.h | 60 ++ b/qemu.sasl | 34 + b/vnc-auth-sasl.c | 636 ++++++++++++++++++++++++++++ b/vnc-auth-sasl.h | 74 +++ b/vnc-auth-vencrypt.c | 175 +++++++ b/vnc-auth-vencrypt.h | 33 + b/vnc-tls.c | 450 ++++++++++++++++++++ b/vnc-tls.h | 76 +++ configure | 34 + curses.c | 3 curses_keys.h | 9 keymaps.c | 45 -- monitor.c | 95 ++++ qemu-doc.texi | 109 ++++ sdl.c | 3 sdl_keysym.h | 7 vl.c | 12 vnc.c | 1108 ++++++++++++++++++-------------------------------- vnc.h | 229 +++++++++- vnc_keysym.h | 7 25 files changed, 2830 insertions(+), 770 deletions(-)
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Re: [Qemu-devel] PATCH: 1/9: Fix bug in TLS authenticataion
This patch was previously posted here:
http://lists.gnu.org/archive/html/qemu-devel/2009-02/msg00820.html
In the case where the TLS handshake does *not* block on I/O, QEMU sends the next 'start sub-auth' message twice. This seriously confuses the VNC client :-) Fortunately the chances of the handshake not blocking are close to zero for a TCP socket, which is why it has not been noticed thus far. Even with both client & server on localhost, I can only hit the bug 1 time in 20.
NB, the diff context here is not too informative. If you look at the full code you'll see that a few lines early we called vnc_start_tls() which called vnc_continue_handshake() which called the method start_auth_vencrypt_subauth(). Hence, fixing the bug, just involves removing the 2nd bogus call to start_auth_vencrypt_subauth() as per this patch.
vnc.c | 8 -------- 1 file changed, 8 deletions(-)
vnc.c +0 -8
@@ -2096,14 +2096,6 @@ static int protocol_client_vencrypt_authVNC_DEBUG ("Failed to complete TLS\n" );return 0 ; } - -if (vs->wiremode ==VNC_WIREMODE_TLS ) { -VNC_DEBUG ("Starting VeNCrypt subauth\n" ); -return start_auth_vencrypt_subauth (vs); - }else { -VNC_DEBUG ("TLS handshake blocked\n" ); -return 0 ; - } }return 0 ; }
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Re: [Qemu-devel] PATCH: 2/9: Enhance 'info vnc' monitor output
In reply to Daniel P. BerrangeThe current 'info vnc' monitor output just displays the VNC server address as provided by the -vnc command line flag. This isn't particularly useful since it doesn't tell you what VNC is actually listening on. eg, if you use '-vnc :1' it is useful to know whether this translated to '0.0.0.0:5901' or chose IPv6 ':::5901'. It is also useful to know the address of the client that is currently connected. It is also useful to know the active authentication (if any).
This patch tweaks the monitor output to look like:
(qemu) info vnc
Server:
address: 0.0.0.0:5902
auth: vencrypt+x509
Client: noneAnd when 2 clients are connected
(qemu) info vnc
Server:
address: 0.0.0.0:5902
auth: vencrypt+x509
Client:
address: 10.33.6.67:38621
Client:
address: 10.33.6.63:38620More data will be added to this later in the patch series...
The 'addr_to_string' helper method in this patch is overly generic for the needs of this patch alone. This is because it will be re-used by the later SASL patches in this series, where the flexibility is important.
vnc.c | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 127 insertions(+), 10 deletions(-)
vnc.c +127 -10
@@ -166,19 +166,136 @@ struct VncStatestatic VncDisplay *vnc_display;/* needed for info vnc */ static DisplayChangeListener *dcl; +static char *addr_to_string (const char *format, +struct sockaddr_storage *sa, +socklen_t salen) { +char *addr; +char host[NI_MAXHOST ]; +char serv[NI_MAXSERV ]; +int err; + +if ((err =getnameinfo ((struct sockaddr *)sa, salen, + host,sizeof (host), + serv,sizeof (serv), +NI_NUMERICHOST |NI_NUMERICSERV )) !=0 ) { +VNC_DEBUG ("Cannot resolve address %d: %s\n" , + err,gai_strerror (err)); +return NULL ; + } + +if (asprintf (&addr, format, host, serv) <0 ) +return NULL ; + +return addr; +} + +static char *vnc_socket_local_addr (const char *format,int fd) { +struct sockaddr_storage sa; +socklen_t salen; + + salen =sizeof (sa); +if (getsockname (fd, (struct sockaddr *)&sa, &salen) <0 ) +return NULL ; + +return addr_to_string (format, &sa, salen); +} + +static char *vnc_socket_remote_addr (const char *format,int fd) { +struct sockaddr_storage sa; +socklen_t salen; + + salen =sizeof (sa); +if (getpeername (fd, (struct sockaddr *)&sa, &salen) <0 ) +return NULL ; + +return addr_to_string (format, &sa, salen); +} + +static const char *vnc_auth_name (VncDisplay *vd) { +switch (vd->auth) { +case VNC_AUTH_INVALID : +return "invalid" ; +case VNC_AUTH_NONE : +return "none" ; +case VNC_AUTH_VNC : +return "vnc" ; +case VNC_AUTH_RA2 : +return "ra2" ; +case VNC_AUTH_RA2NE : +return "ra2ne" ; +case VNC_AUTH_TIGHT : +return "tight" ; +case VNC_AUTH_ULTRA : +return "ultra" ; +case VNC_AUTH_TLS : +return "tls" ; +case VNC_AUTH_VENCRYPT : +#ifdef CONFIG_VNC_TLS +switch (vd->subauth) { +case VNC_AUTH_VENCRYPT_PLAIN : +return "vencrypt+plain" ; +case VNC_AUTH_VENCRYPT_TLSNONE : +return "vencrypt+tls+none" ; +case VNC_AUTH_VENCRYPT_TLSVNC : +return "vencrypt+tls+vnc" ; +case VNC_AUTH_VENCRYPT_TLSPLAIN : +return "vencrypt+tls+plain" ; +case VNC_AUTH_VENCRYPT_X509NONE : +return "vencrypt+x509+none" ; +case VNC_AUTH_VENCRYPT_X509VNC : +return "vencrypt+x509+vnc" ; +case VNC_AUTH_VENCRYPT_X509PLAIN : +return "vencrypt+x509+plain" ; +default : +return "vencrypt" ; + } +#else +return "vencrypt" ; +#endif + } +return "unknown" ; +} + +#define VNC_SOCKET_FORMAT_PRETTY "local %s:%s" + +static void do_info_vnc_client (VncState *client) +{ +char *clientAddr = +vnc_socket_remote_addr (" address: %s:%s\n" , + client->csock); +if (!clientAddr) +return ; + +term_puts ("Client:\n" ); +term_puts (clientAddr); +free (clientAddr); +} +void do_info_vnc (void ) { -if (vnc_display ==NULL || vnc_display->display ==NULL ) -term_printf ("VNC server disabled\n" ); -else { -term_printf ("VNC server active on: " ); -term_print_filename (vnc_display->display); -term_printf ("\n" ); +if (vnc_display ==NULL || vnc_display->display ==NULL ) { +term_printf ("Server: disabled\n" ); + }else { +char *serverAddr =vnc_socket_local_addr (" address: %s:%s\n" , + vnc_display->lsock); -if (vnc_display->clients ==NULL ) -term_printf ("No client connected\n" ); -else -term_printf ("Client connected\n" ); +if (!serverAddr) +return ; + +term_puts ("Server:\n" ); +term_puts (serverAddr); +free (serverAddr); +term_printf (" auth: %s\n" ,vnc_auth_name (vnc_display)); + +if (vnc_display->clients) { +VncState *client = vnc_display->clients; +while (client) { +do_info_vnc_client (client); + client = client->next; + } + }else { +term_printf ("Client: none\n" ); + } } }
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Re: [Qemu-devel] PATCH: 3/9: Refactor keymap code to avoid duplication
In reply to Daniel P. BerrangeEach of the graphical frontends #include a .c file, for keymap code resulting in duplicated definitions & duplicated compiled code. A couple of small changes allowed this to be sanitized, so instead of doing a #include "keymaps.c", duplicating all code, we can have a shared keymaps.h file, and only compile code once. This allows the next patch to move the VncState struct out into a header file without causing clashing definitions.
Makefile | 9 +++++--- b/keymaps.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ curses.c | 3 -- curses_keys.h | 9 +++----- keymaps.c | 45 ++++++++++++++++--------------------------- sdl.c | 3 -- sdl_keysym.h | 7 ++---- vnc.c | 5 +--- vnc_keysym.h | 7 ++---- 9 files changed, 97 insertions(+), 51 deletions(-)
Makefile +6 -3
@@ -137,6 +137,7 @@ endif AUDIO_OBJS+= wavcapture.o OBJS+=$(addprefix audio/, $(AUDIO_OBJS)) +OBJS+=keymaps.o ifdef CONFIG_SDL OBJS+=sdl.o x_keymap.o endif
@@ -161,15 +162,17 @@ LIBS+=$(VDE_LIBS) cocoa.o: cocoa.m -sdl.o: sdl.c keymaps.c sdl_keysym.h +keymaps.o: keymaps.c keymaps.h + +sdl.o: sdl.c keymaps.h sdl_keysym.h sdl.o audio/sdlaudio.o: CFLAGS += $(SDL_CFLAGS) -vnc.o: vnc.c keymaps.c sdl_keysym.h vnchextile.h d3des.c d3des.h +vnc.o: vnc.c keymaps.h sdl_keysym.h vnchextile.h d3des.c d3des.h vnc.o: CFLAGS += $(CONFIG_VNC_TLS_CFLAGS) -curses.o: curses.c keymaps.c curses_keys.h +curses.o: curses.c keymaps.h curses_keys.h bt-host.o: CFLAGS += $(CONFIG_BLUEZ_CFLAGS)
curses.c +1 -2
@@ -158,7 +158,6 @@ static void curses_cursor_position(Displ/* generic keyboard conversion */ #include "curses_keys.h" -#include "keymaps.c" static kbd_layout_t *kbd_layout =0 ;static int keycode2keysym[CURSES_KEYS ];
@@ -311,7 +310,7 @@ static void curses_keyboard_setup(void) keyboard_layout ="en-us" ;#endif if (keyboard_layout) { - kbd_layout =init_keyboard_layout (keyboard_layout); + kbd_layout =init_keyboard_layout (name2keysym, keyboard_layout);if (!kbd_layout)exit (1 ); }
curses_keys.h +4 -5
@@ -21,6 +21,10 @@* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + +#include "keymaps.h" + +#define KEY_RELEASE 0x80#define KEY_MASK 0x7f#define SHIFT_CODE 0x2a
@@ -239,11 +243,6 @@ static const int curses2keysym[CURSES_KE }; -typedef struct { -const char * name; -int keysym; -}name2keysym_t ; -static const name2keysym_t name2keysym[] = {/* Plain ASCII */ {"space" ,0x020 },
keymaps.c +17 -28
98 lines not on this page · raw message
keymaps.h new file +60 -0
60 lines not on this page · raw message
sdl.c +1 -2
@@ -107,7 +107,6 @@ static void sdl_resize(DisplayState *ds)/* generic keyboard conversion */ #include "sdl_keysym.h" -#include "keymaps.c" static kbd_layout_t *kbd_layout =NULL ;
@@ -623,7 +622,7 @@ void sdl_display_init(DisplayState *ds, keyboard_layout ="en-us" ;#endif if (keyboard_layout) { - kbd_layout =init_keyboard_layout (keyboard_layout); + kbd_layout =init_keyboard_layout (name2keysym, keyboard_layout);if (!kbd_layout)exit (1 ); }
sdl_keysym.h +3 -4
@@ -1,7 +1,6 @@ -typedef struct { -const char * name; -int keysym; -}name2keysym_t ; + +#include "keymaps.h" +static const name2keysym_t name2keysym[]={/* ascii */ {"space" ,0x020 },
vnc.c +2 -3
@@ -35,7 +35,6 @@#include "vnc.h" #include "vnc_keysym.h" -#include "keymaps.c" #include "d3des.h" #ifdef CONFIG_VNC_TLS
@@ -2420,9 +2419,9 @@ void vnc_display_init(DisplayState *ds) vs->ds = ds;if (keyboard_layout) - vs->kbd_layout =init_keyboard_layout (keyboard_layout); + vs->kbd_layout =init_keyboard_layout (name2keysym, keyboard_layout);else - vs->kbd_layout =init_keyboard_layout ("en-us" ); + vs->kbd_layout =init_keyboard_layout (name2keysym,"en-us" );if (!vs->kbd_layout)exit (1 );
vnc_keysym.h +3 -4
@@ -1,7 +1,6 @@ -typedef struct { -const char * name; -int keysym; -}name2keysym_t ; + +#include "keymaps.h" +static const name2keysym_t name2keysym[]={/* ascii */ {"space" ,0x020 },
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Re: [Qemu-devel] PATCH: 4/9: Move VNC structs into header file
In reply to Daniel P. BerrangeThis patch moves the definitions of VncState and VncDisplay structs out into a vnc.h header file. This is to allow the code for TLS and SASL auth mechanisms to be moved out of the main vnc.c file.
vnc.c | 109 ------------------------------------------------ vnc.h | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 148 insertions(+), 110 deletions(-)
vnc.c +2 -107
@@ -3,6 +3,7 @@* * Copyright (C) 2006 Anthony Liguori <[email protected]> * Copyright (C) 2006 Fabrice Bellard +* Copyright (C) 2009 Red Hat, Inc * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal
@@ -23,25 +24,16 @@* THE SOFTWARE. */ -#include "qemu-common.h" -#include "console.h" +#include "vnc.h" #include "sysemu.h" #include "qemu_socket.h" #include "qemu-timer.h" -#include "audio/audio.h" -#include <zlib.h> #define VNC_REFRESH_INTERVAL (1000 / 30) -#include "vnc.h" #include "vnc_keysym.h" #include "d3des.h" -#ifdef CONFIG_VNC_TLS -#include <gnutls/gnutls.h> -#include <gnutls/x509.h> -#endif /* CONFIG_VNC_TLS */ -// #define _VNC_DEBUG 1 #ifdef _VNC_DEBUG
@@ -64,103 +56,6 @@ static void vnc_debug_gnutls_log(int lev } \ } -typedef struct Buffer -{ -size_t capacity; -size_t offset; -uint8_t *buffer; -}Buffer ; - -typedef struct VncState VncState ; - -typedef int VncReadEvent (VncState *vs,uint8_t *data,size_t len); - -typedef void VncWritePixels (VncState *vs,void *data,int size); - -typedef void VncSendHextileTile (VncState *vs, -int x,int y,int w,int h, -void *last_bg, -void *last_fg, -int *has_bg,int *has_fg); - -#define VNC_MAX_WIDTH 2048 -#define VNC_MAX_HEIGHT 2048 -#define VNC_DIRTY_WORDS (VNC_MAX_WIDTH / (16 * 32)) - -#define VNC_AUTH_CHALLENGE_SIZE 16 - -typedef struct VncDisplay VncDisplay ; - -struct VncDisplay -{ -int lsock; -DisplayState *ds; -VncState *clients; -kbd_layout_t *kbd_layout; - -char *display; -char *password; -int auth; -#ifdef CONFIG_VNC_TLS -int subauth; -int x509verify; - -char *x509cacert; -char *x509cacrl; -char *x509cert; -char *x509key; -#endif -}; - -struct VncState -{ -QEMUTimer *timer; -int csock; -DisplayState *ds; -VncDisplay *vd; -int need_update; -uint32_t dirty_row[VNC_MAX_HEIGHT ][VNC_DIRTY_WORDS ]; -char *old_data; -uint32_t features; -int absolute; -int last_x; -int last_y; - -uint32_t vnc_encoding; -uint8_t tight_quality; -uint8_t tight_compression; - -int major; -int minor; - -char challenge[VNC_AUTH_CHALLENGE_SIZE ]; - -#ifdef CONFIG_VNC_TLS -int wiremode; -gnutls_session_t tls_session; -#endif - -Buffer output; -Buffer input; -/* current output mode information */ -VncWritePixels *write_pixels; -VncSendHextileTile *send_hextile_tile; -DisplaySurface clientds, serverds; - -CaptureVoiceOut *audio_cap; -struct audsettings as; - -VncReadEvent *read_handler; -size_t read_handler_expect; -/* input */ -uint8_t modifiers_state[256 ]; - -Buffer zlib; -Buffer zlib_tmp; -z_stream zlib_stream[4 ]; - -VncState *next; -};static VncDisplay *vnc_display;/* needed for info vnc */ static DisplayChangeListener *dcl;
vnc.h +146 -3
155 lines not on this page · raw message
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Re: [Qemu-devel] PATCH: 5/9: Move TLS auth into separate file
In reply to Daniel P. BerrangeThis patch refactors the existing TLS code to make the main VNC code more managable. The code moves to two new files
- vnc-tls.c: generic helpers for TLS handshake & credential setup
- vnc-auth-vencrypt.c: the actual VNC TLS authentication mechanism.
The reason for this split is that there are other TLS based auth mechanisms which we may like to use in the future. These can all share the same vnc-tls.c routines. In addition this will facilitate anyone who may want to port the vnc-tls.c file to allow for choice of GNUTLS & NSS for impl.
The TLS state is moved out of the VncState struct, and into a separate VncStateTLS struct, defined in vnc-tls.h. This is then referenced from the main VncState. End size of the struct is the same, but it keeps things a little more managable.
The vnc.h file gains a bunch more function prototypes, for functions in vnc.c that were previously static, but now need to be accessed from the separate auth code files.
The only TLS related code still in the main vl.c is the command line argument handling / setup, and the low level I/O routines calling gnutls_send/recv.
Makefile | 11 b/vnc-auth-vencrypt.c | 167 ++++++++++++++ b/vnc-auth-vencrypt.h | 33 ++ b/vnc-tls.c | 414 +++++++++++++++++++++++++++++++++++ b/vnc-tls.h | 70 ++++++ vnc.c | 581 +++----------------------------------------------- vnc.h | 76 ++++-- 7 files changed, 780 insertions(+), 572 deletions(-)
Makefile +10 -1
@@ -145,6 +145,9 @@ ifdef CONFIG_CURSES OBJS+=curses.o endif OBJS+=vnc.o d3des.o +ifdef CONFIG_VNC_TLS +OBJS+=vnc-tls.o vnc-auth-vencrypt.o +endif ifdef CONFIG_COCOA OBJS+=cocoa.o
@@ -168,10 +171,16 @@ sdl.o: sdl.c keymaps.h sdl_keysym.h sdl.o audio/sdlaudio.o: CFLAGS += $(SDL_CFLAGS) -vnc.o: vnc.c keymaps.h sdl_keysym.h vnchextile.h d3des.c d3des.h +vnc.h: vnc-tls.h vnc-auth-vencrypt.h keymaps.h + +vnc.o: vnc.c vnc.h vnc_keysym.h vnchextile.h d3des.c d3des.h vnc.o: CFLAGS += $(CONFIG_VNC_TLS_CFLAGS) +vnc-tls.o: vnc-tls.c vnc.h + +vnc-auth-vencrypt.o: vnc-auth-vencrypt.c vnc.h + curses.o: curses.c keymaps.h curses_keys.h bt-host.o: CFLAGS += $(CONFIG_BLUEZ_CFLAGS)
vnc-auth-vencrypt.c new file +167 -0
167 lines not on this page · raw message
vnc-auth-vencrypt.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* QEMU VNC display driver +* +* Copyright (C) 2006 Anthony Liguori <[email protected]> +* Copyright (C) 2006 Fabrice Bellard +* Copyright (C) 2009 Red Hat, Inc +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + + +#ifndef __QEMU_VNC_AUTH_VENCRYPT_H__ +#define __QEMU_VNC_AUTH_VENCRYPT_H__ + +void start_auth_vencrypt (VncState *vs); + +#endif /* __QEMU_VNC_AUTH_VENCRYPT_H__ */
vnc-tls.c new file +414 -0
414 lines not on this page · raw message
vnc-tls.h new file +70 -0
70 lines not on this page · raw message
vnc.c +36 -545
756 lines not on this page · raw message
vnc.h +50 -26
117 lines not on this page · raw message
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Re: [Qemu-devel] PATCH: 6/9: Add SASL authentication support
In reply to Daniel P. BerrangeThis patch adds the new SASL authentication protocol to the VNC server.
It is enabled by setting the 'sasl' flag when launching VNC. SASL can optionally provide encryption via its SSF layer, if a suitable mechanism is configured (eg, GSSAPI/Kerberos, or Digest-MD5). If an SSF layer is not available, then it should be combined with the x509 VNC authentication protocol which provides encryption.
eg, if using GSSAPI
qemu -vnc localhost:1,sasl
eg if using TLS/x509 for encryption
qemu -vnc localhost:1,sasl,tls,x509
By default the Cyrus SASL library will look for its configuration in the file /etc/sasl2/qemu.conf. For non-root users, this can be overridden by setting the SASL_CONF_PATH environment variable, eg to make it look in $HOME/.sasl2. NB unprivileged users may not have access to the full range of SASL mechanisms, since some of them require some administrative privileges to configure. The patch includes an example SASL configuration file which illustrates config for GSSAPI and Digest-MD5, though it should be noted that the latter is not really considered secure any more.
Most of the SASL authentication code is located in a separate source file, vnc-auth-sasl.c. The main vnc.c file only contains minimal integration glue, specifically parsing of command line flags / setup, and calls to start the SASL auth process, to do encoding/decoding for data.
There are several possible stacks for reading & writing of data, depending on the combo of VNC authentication methods in use
- Clear. read/write straight to socket - TLS. read/write via GNUTLS helpers - SASL. encode/decode via SASL SSF layer, then read/write to socket
- SASL+TLS. encode/decode via SASL SSF layer, then read/write via GNUTLS
Hence, the vnc_client_read & vnc_client_write methods have been refactored a little.
vnc_client_read: main entry point for reading, calls either
- vnc_client_read_plain reading, with no intermediate decoding
- vnc_client_read_sasl reading, with SASL SSF decoding
These two methods, then call vnc_client_read_buf(). This decides whether to write to the socket directly or write via GNUTLS.
The situation is the same for writing data. More extensive comments have been added in the code / patch. The vnc_client_read_sasl and vnc_client_write_sasl method implementations live in the separate vnc-auth-sasl.c file.
The state required for the SASL auth mechanism is kept in a separate VncStateSASL struct, defined in vnc-auth-sasl.h and included in the main VncState.
The configure script probes for SASL and automatically enables it if found, unless --disable-vnc-sasl was given to override it.
Makefile | 7 Makefile.target | 5 b/qemu.sasl | 34 ++ b/vnc-auth-sasl.c | 626 ++++++++++++++++++++++++++++++++++++++++++++++++++++ b/vnc-auth-sasl.h | 67 +++++ configure | 34 ++ qemu-doc.texi | 109 ++++++++- vnc-auth-vencrypt.c | 12 vnc.c | 249 ++++++++++++++++++-- vnc.h | 31 ++ 10 files changed, 1134 insertions(+), 40 deletions(-)
Makefile +6 -1
@@ -148,6 +148,9 @@ OBJS+=vnc.o d3des.o ifdef CONFIG_VNC_TLS OBJS+=vnc-tls.o vnc-auth-vencrypt.o endif +ifdef CONFIG_VNC_SASL +OBJS+=vnc-auth-sasl.o +endif ifdef CONFIG_COCOA OBJS+=cocoa.o
@@ -171,7 +174,7 @@ sdl.o: sdl.c keymaps.h sdl_keysym.h sdl.o audio/sdlaudio.o: CFLAGS += $(SDL_CFLAGS) -vnc.h: vnc-tls.h vnc-auth-vencrypt.h keymaps.h +vnc.h: vnc-tls.h vnc-auth-vencrypt.h vnc-auth-sasl.h keymaps.h vnc.o: vnc.c vnc.h vnc_keysym.h vnchextile.h d3des.c d3des.h
@@ -181,6 +184,8 @@ vnc-tls.o: vnc-tls.c vnc.h vnc-auth-vencrypt.o: vnc-auth-vencrypt.c vnc.h +vnc-auth-sasl.o: vnc-auth-sasl.c vnc.h + curses.o: curses.c keymaps.h curses_keys.h bt-host.o: CFLAGS += $(CONFIG_BLUEZ_CFLAGS)
Makefile.target +5 -0
@@ -554,6 +554,11 @@ CPPFLAGS += $(CONFIG_VNC_TLS_CFLAGS) LIBS += $(CONFIG_VNC_TLS_LIBS) endif +ifdef CONFIG_VNC_SASL +CPPFLAGS += $(CONFIG_VNC_SASL_CFLAGS) +LIBS += $(CONFIG_VNC_SASL_LIBS) +endif + ifdef CONFIG_BLUEZ LIBS += $(CONFIG_BLUEZ_LIBS) endif
configure +34 -0
@@ -164,6 +164,7 @@ fmod_lib="" fmod_inc="" oss_lib="" vnc_tls="yes" +vnc_sasl="yes" bsd="no" linux="no" solaris="no"
@@ -387,6 +388,8 @@ for opt do ;; --disable-vnc-tls) vnc_tls="no" ;; + --disable-vnc-sasl) vnc_sasl="no" + ;; --disable-slirp) slirp="no" ;; --disable-vde) vde="no"
@@ -544,6 +547,7 @@ echo " Availab echo " --enable-mixemu enable mixer emulation" echo " --disable-brlapi disable BrlAPI" echo " --disable-vnc-tls disable TLS encryption for VNC server" +echo " --disable-vnc-sasl disable SASL encryption for VNC server" echo " --disable-curses disable curses output" echo " --disable-bluez disable bluez stack connectivity" echo " --disable-kvm disable KVM acceleration support"
@@ -823,6 +827,25 @@ EOF fi ########################################## +# VNC SASL detection +if test "$vnc_sasl" = "yes" ; then +cat > $TMPC <<EOF +#include <sasl/sasl.h> +#include <stdio.h> +int main(void) { sasl_server_init(NULL, "qemu"); return 0; } +EOF + # Assuming Cyrus-SASL installed in /usr prefix + vnc_sasl_cflags="" + vnc_sasl_libs="-lsasl2" + if $cc $ARCH_CFLAGS -o $TMPE ${OS_CFLAGS} $vnc_sasl_cflags $TMPC \ + $vnc_sasl_libs 2> /dev/null ; then + : + else + vnc_sasl="no" + fi +fi + +########################################## # vde libraries probe if test "$vde" = "yes" ; then cat > $TMPC << EOF
@@ -1130,6 +1153,11 @@ if test "$vnc_tls" = "yes" ; then echo " TLS CFLAGS $vnc_tls_cflags" echo " TLS LIBS $vnc_tls_libs" fi +echo "VNC SASL support $vnc_sasl" +if test "$vnc_sasl" = "yes" ; then + echo " SASL CFLAGS $vnc_sasl_cflags" + echo " SASL LIBS $vnc_sasl_libs" +fi if test -n "$sparc_cpu"; then echo "Target Sparc Arch $sparc_cpu" fi
@@ -1371,6 +1399,12 @@ if test "$vnc_tls" = "yes" ; then echo "CONFIG_VNC_TLS_LIBS=$vnc_tls_libs" >> $config_mak echo "#define CONFIG_VNC_TLS 1" >> $config_h fi +if test "$vnc_sasl" = "yes" ; then + echo "CONFIG_VNC_SASL=yes" >> $config_mak + echo "CONFIG_VNC_SASL_CFLAGS=$vnc_sasl_cflags" >> $config_mak + echo "CONFIG_VNC_SASL_LIBS=$vnc_sasl_libs" >> $config_mak + echo "#define CONFIG_VNC_SASL 1" >> $config_h +fi qemu_version=`head $source_path/VERSION` echo "VERSION=$qemu_version" >>$config_mak echo "#define QEMU_VERSION \"$qemu_version\"" >> $config_h
qemu-doc.texi +102 -7
158 lines not on this page · raw message
qemu.sasl new file +34 -0
@@ -0,0 +1,34 @@ +# If you want to use the non-TLS socket, then you *must* include +# the GSSAPI or DIGEST-MD5 mechanisms, because they are the only +# ones that can offer session encryption as well as authentication. +# +# If you're only using TLS, then you can turn on any mechanisms +# you like for authentication, because TLS provides the encryption +# +# Default to a simple username+password mechanism +# NB digest-md5 is no longer considered secure by current standards +mech_list: digest-md5 + +# Before you can use GSSAPI, you need a service principle on the +# KDC server for libvirt, and that to be exported to the keytab +# file listed below +#mech_list: gssapi +# +# You can also list many mechanisms at once, then the user can choose +# by adding '?auth=sasl.gssapi' to their libvirt URI, eg +# qemu+tcp://hostname/system?auth=sasl.gssapi +#mech_list: digest-md5 gssapi + +# Some older builds of MIT kerberos on Linux ignore this option & +# instead need KRB5_KTNAME env var. +# For modern Linux, and other OS, this should be sufficient +keytab: /etc/qemu/krb5.tab + +# If using digest-md5 for username/passwds, then this is the file +# containing the passwds. Use 'saslpasswd2 -a qemu [username]' +# to add entries, and 'sasldblistusers2 -a qemu' to browse it +sasldb_path: /etc/qemu/passwd.db + + +auxprop_plugin: sasldb +
vnc-auth-sasl.c new file +626 -0
626 lines not on this page · raw message
vnc-auth-sasl.h new file +67 -0
67 lines not on this page · raw message
vnc-auth-vencrypt.c +10 -2
@@ -43,8 +43,15 @@ static void start_auth_vencrypt_subauth(start_auth_vnc (vs);break ; +#ifdef CONFIG_VNC_SASL +case VNC_AUTH_VENCRYPT_TLSSASL : +case VNC_AUTH_VENCRYPT_X509SASL : +VNC_DEBUG ("Start TLS auth SASL\n" ); +return start_auth_sasl (vs); +#endif /* CONFIG_VNC_SASL */ +default :/* Should not be possible, but just in case */ -VNC_DEBUG ("Reject auth %d\n" , vs->vd->auth); +VNC_DEBUG ("Reject subauth %d server bug\n" , vs->vd->auth);vnc_write_u8 (vs,1 );if (vs->minor >=8 ) {static const char err[] ="Unsupported authentication type" ;
@@ -105,7 +112,8 @@ static void vnc_tls_handshake_io(void *o#define NEED_X509_AUTH (vs) \ ((vs)->vd->subauth == VNC_AUTH_VENCRYPT_X509NONE || \ (vs)->vd->subauth == VNC_AUTH_VENCRYPT_X509VNC || \ - (vs)->vd->subauth == VNC_AUTH_VENCRYPT_X509PLAIN) + (vs)->vd->subauth == VNC_AUTH_VENCRYPT_X509PLAIN || \ + (vs)->vd->subauth == VNC_AUTH_VENCRYPT_X509SASL)static int protocol_client_vencrypt_auth (VncState *vs,uint8_t *data,size_t len)
vnc.c +222 -27
392 lines not on this page · raw message
vnc.h +28 -3
@@ -79,6 +79,10 @@ typedef struct VncDisplay VncDisplay;#include "vnc-tls.h" #include "vnc-auth-vencrypt.h" #endif +#ifdef CONFIG_VNC_SASL +#include "vnc-auth-sasl.h" +#endif +struct VncDisplay {
@@ -118,10 +122,12 @@ struct VncStateint minor;char challenge[VNC_AUTH_CHALLENGE_SIZE ]; -#ifdef CONFIG_VNC_TLS VncStateTLS tls;#endif +#ifdef CONFIG_VNC_SASL +VncStateSASL sasl; +#endif Buffer output;Buffer input;
@@ -160,8 +166,9 @@ enum {VNC_AUTH_RA2NE =6 ,VNC_AUTH_TIGHT =16 ,VNC_AUTH_ULTRA =17 , -VNC_AUTH_TLS =18 , -VNC_AUTH_VENCRYPT =19 +VNC_AUTH_TLS =18 ,/* Supported in GTK-VNC & VINO */ +VNC_AUTH_VENCRYPT =19 ,/* Supported in GTK-VNC & VeNCrypt */ + VNC_AUTH_SASL = 20, /* Supported in GTK-VNC & VINO */ }; enum {
@@ -172,6 +179,8 @@ enum {VNC_AUTH_VENCRYPT_X509NONE =260 ,VNC_AUTH_VENCRYPT_X509VNC =261 ,VNC_AUTH_VENCRYPT_X509PLAIN =262 , +VNC_AUTH_VENCRYPT_X509SASL =263 , + VNC_AUTH_VENCRYPT_TLSSASL = 264, };
@@ -255,6 +264,8 @@ enum {void vnc_client_read (void *opaque);void vnc_client_write (void *opaque); +long vnc_client_read_buf (VncState *vs,uint8_t *data,size_t datalen); +long vnc_client_write_buf (VncState *vs,const uint8_t *data,size_t datalen);/* Protocol I/O functions */ void vnc_write (VncState *vs,const void *data,size_t len);
@@ -274,8 +285,22 @@ uint32_t read_u32(uint8_t *data, size_t/* Protocol stage functions */ void vnc_client_error (VncState *vs); +int vnc_client_io_error (VncState *vs,int ret,int last_errno);void start_client_init (VncState *vs);void start_auth_vnc (VncState *vs); +/* Buffer management */ +void buffer_reserve (Buffer *buffer,size_t len); +int buffer_empty (Buffer *buffer); +uint8_t *buffer_end (Buffer *buffer); +void buffer_reset (Buffer *buffer); +void buffer_append (Buffer *buffer,const void *data,size_t len); + + +/* Misc helpers */ + +char *vnc_socket_local_addr (const char *format,int fd); +char *vnc_socket_remote_addr (const char *format,int fd); +#endif /* __QEMU_VNC_H */
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Re: [Qemu-devel] PATCH: 6/9: Add SASL authentication support
Quoted 32 lines · Daniel P. Berrange
This patch adds the new SASL authentication protocol to the VNC server.
@@ -2436,7 +2531,7 @@ QEMU emulates the following PowerMac per
@itemize @minus
@item
-UniNorth or Grackle PCI Bridge
+UniNorth PCI Bridge
@item
PCI VGA compatible card with VESA Bochs Extensions @item
@@ -2474,9 +2569,9 @@ QEMU uses the Open Hack'Ware Open Firmwa
@url{http://perso.magic.fr/l_indien/OpenHackWare/index.htm}.Since version 0.9.1, QEMU uses OpenBIOS @url{http://www.openbios.org/}
-for the g3beige and mac99 PowerMac machines. OpenBIOS is a free (GPL -v2) portable firmware implementation. The goal is to implement a 100% -IEEE 1275-1994 (referred to as Open Firmware) compliant firmware. +for the g3beige PowerMac machine. OpenBIOS is a free (GPL v2) portable +firmware implementation. The goal is to implement a 100% IEEE +1275-1994 (referred to as Open Firmware) compliant firmware.@c man begin OPTIONS
@@ -2705,7 +2800,7 @@ PCnet32 PCI network card
@item
Malta FPGA serial device
@item
-Cirrus (default) or any other PCI VGA graphics card +Cirrus VGA graphics card
@end itemize
Quoted 1 line
The ACER Pica emulation supports:
Please remove these changes.
Re: [Qemu-devel] PATCH: 6/9: Add SASL authentication support
Quoted 33 lines · Blue Swirl
Quoted 32 lines · Daniel P. Berrange
This patch adds the new SASL authentication protocol to the VNC server.
@@ -2436,7 +2531,7 @@ QEMU emulates the following PowerMac per
@itemize @minus
@item
-UniNorth or Grackle PCI Bridge
+UniNorth PCI Bridge
@item
PCI VGA compatible card with VESA Bochs Extensions @item
@@ -2474,9 +2569,9 @@ QEMU uses the Open Hack'Ware Open Firmwa
@url{http://perso.magic.fr/l_indien/OpenHackWare/index.htm}.Since version 0.9.1, QEMU uses OpenBIOS @url{http://www.openbios.org/}
-for the g3beige and mac99 PowerMac machines. OpenBIOS is a free (GPL -v2) portable firmware implementation. The goal is to implement a 100% -IEEE 1275-1994 (referred to as Open Firmware) compliant firmware. +for the g3beige PowerMac machine. OpenBIOS is a free (GPL v2) portable +firmware implementation. The goal is to implement a 100% IEEE +1275-1994 (referred to as Open Firmware) compliant firmware.@c man begin OPTIONS
@@ -2705,7 +2800,7 @@ PCnet32 PCI network card
@item
Malta FPGA serial device
@item
-Cirrus (default) or any other PCI VGA graphics card +Cirrus VGA graphics card
@end itemize
Quoted 3 lines
Quoted 1 line
The ACER Pica emulation supports:
Please remove these changes.
Sorry about that - merge error when rebasing to latest svn. Here's an update without the bogus chunks.
Daniel
Makefile +6 -1
@@ -148,6 +148,9 @@ OBJS+=vnc.o d3des.o ifdef CONFIG_VNC_TLS OBJS+=vnc-tls.o vnc-auth-vencrypt.o endif +ifdef CONFIG_VNC_SASL +OBJS+=vnc-auth-sasl.o +endif ifdef CONFIG_COCOA OBJS+=cocoa.o
@@ -171,7 +174,7 @@ sdl.o: sdl.c keymaps.h sdl_keysym.h sdl.o audio/sdlaudio.o: CFLAGS += $(SDL_CFLAGS) -vnc.h: vnc-tls.h vnc-auth-vencrypt.h keymaps.h +vnc.h: vnc-tls.h vnc-auth-vencrypt.h vnc-auth-sasl.h keymaps.h vnc.o: vnc.c vnc.h vnc_keysym.h vnchextile.h d3des.c d3des.h
@@ -181,6 +184,8 @@ vnc-tls.o: vnc-tls.c vnc.h vnc-auth-vencrypt.o: vnc-auth-vencrypt.c vnc.h +vnc-auth-sasl.o: vnc-auth-sasl.c vnc.h + curses.o: curses.c keymaps.h curses_keys.h bt-host.o: CFLAGS += $(CONFIG_BLUEZ_CFLAGS)
Makefile.target +5 -0
@@ -554,6 +554,11 @@ CPPFLAGS += $(CONFIG_VNC_TLS_CFLAGS) LIBS += $(CONFIG_VNC_TLS_LIBS) endif +ifdef CONFIG_VNC_SASL +CPPFLAGS += $(CONFIG_VNC_SASL_CFLAGS) +LIBS += $(CONFIG_VNC_SASL_LIBS) +endif + ifdef CONFIG_BLUEZ LIBS += $(CONFIG_BLUEZ_LIBS) endif
configure +34 -0
@@ -164,6 +164,7 @@ fmod_lib="" fmod_inc="" oss_lib="" vnc_tls="yes" +vnc_sasl="yes" bsd="no" linux="no" solaris="no"
@@ -387,6 +388,8 @@ for opt do ;; --disable-vnc-tls) vnc_tls="no" ;; + --disable-vnc-sasl) vnc_sasl="no" + ;; --disable-slirp) slirp="no" ;; --disable-vde) vde="no"
@@ -544,6 +547,7 @@ echo " Availab echo " --enable-mixemu enable mixer emulation" echo " --disable-brlapi disable BrlAPI" echo " --disable-vnc-tls disable TLS encryption for VNC server" +echo " --disable-vnc-sasl disable SASL encryption for VNC server" echo " --disable-curses disable curses output" echo " --disable-bluez disable bluez stack connectivity" echo " --disable-kvm disable KVM acceleration support"
@@ -823,6 +827,25 @@ EOF fi ########################################## +# VNC SASL detection +if test "$vnc_sasl" = "yes" ; then +cat > $TMPC <<EOF +#include <sasl/sasl.h> +#include <stdio.h> +int main(void) { sasl_server_init(NULL, "qemu"); return 0; } +EOF + # Assuming Cyrus-SASL installed in /usr prefix + vnc_sasl_cflags="" + vnc_sasl_libs="-lsasl2" + if $cc $ARCH_CFLAGS -o $TMPE ${OS_CFLAGS} $vnc_sasl_cflags $TMPC \ + $vnc_sasl_libs 2> /dev/null ; then + : + else + vnc_sasl="no" + fi +fi + +########################################## # vde libraries probe if test "$vde" = "yes" ; then cat > $TMPC << EOF
@@ -1130,6 +1153,11 @@ if test "$vnc_tls" = "yes" ; then echo " TLS CFLAGS $vnc_tls_cflags" echo " TLS LIBS $vnc_tls_libs" fi +echo "VNC SASL support $vnc_sasl" +if test "$vnc_sasl" = "yes" ; then + echo " SASL CFLAGS $vnc_sasl_cflags" + echo " SASL LIBS $vnc_sasl_libs" +fi if test -n "$sparc_cpu"; then echo "Target Sparc Arch $sparc_cpu" fi
@@ -1371,6 +1399,12 @@ if test "$vnc_tls" = "yes" ; then echo "CONFIG_VNC_TLS_LIBS=$vnc_tls_libs" >> $config_mak echo "#define CONFIG_VNC_TLS 1" >> $config_h fi +if test "$vnc_sasl" = "yes" ; then + echo "CONFIG_VNC_SASL=yes" >> $config_mak + echo "CONFIG_VNC_SASL_CFLAGS=$vnc_sasl_cflags" >> $config_mak + echo "CONFIG_VNC_SASL_LIBS=$vnc_sasl_libs" >> $config_mak + echo "#define CONFIG_VNC_SASL 1" >> $config_h +fi qemu_version=`head $source_path/VERSION` echo "VERSION=$qemu_version" >>$config_mak echo "#define QEMU_VERSION \"$qemu_version\"" >> $config_h
qemu-doc.texi +97 -0
122 lines not on this page · raw message
qemu.sasl new file +34 -0
@@ -0,0 +1,34 @@ +# If you want to use the non-TLS socket, then you *must* include +# the GSSAPI or DIGEST-MD5 mechanisms, because they are the only +# ones that can offer session encryption as well as authentication. +# +# If you're only using TLS, then you can turn on any mechanisms +# you like for authentication, because TLS provides the encryption +# +# Default to a simple username+password mechanism +# NB digest-md5 is no longer considered secure by current standards +mech_list: digest-md5 + +# Before you can use GSSAPI, you need a service principle on the +# KDC server for libvirt, and that to be exported to the keytab +# file listed below +#mech_list: gssapi +# +# You can also list many mechanisms at once, then the user can choose +# by adding '?auth=sasl.gssapi' to their libvirt URI, eg +# qemu+tcp://hostname/system?auth=sasl.gssapi +#mech_list: digest-md5 gssapi + +# Some older builds of MIT kerberos on Linux ignore this option & +# instead need KRB5_KTNAME env var. +# For modern Linux, and other OS, this should be sufficient +keytab: /etc/qemu/krb5.tab + +# If using digest-md5 for username/passwds, then this is the file +# containing the passwds. Use 'saslpasswd2 -a qemu [username]' +# to add entries, and 'sasldblistusers2 -a qemu' to browse it +sasldb_path: /etc/qemu/passwd.db + + +auxprop_plugin: sasldb +
vnc-auth-sasl.c new file +626 -0
626 lines not on this page · raw message
vnc-auth-sasl.h new file +67 -0
67 lines not on this page · raw message
vnc-auth-vencrypt.c +10 -2
@@ -43,8 +43,15 @@ static void start_auth_vencrypt_subauth(start_auth_vnc (vs);break ; +#ifdef CONFIG_VNC_SASL +case VNC_AUTH_VENCRYPT_TLSSASL : +case VNC_AUTH_VENCRYPT_X509SASL : +VNC_DEBUG ("Start TLS auth SASL\n" ); +return start_auth_sasl (vs); +#endif /* CONFIG_VNC_SASL */ +default :/* Should not be possible, but just in case */ -VNC_DEBUG ("Reject auth %d\n" , vs->vd->auth); +VNC_DEBUG ("Reject subauth %d server bug\n" , vs->vd->auth);vnc_write_u8 (vs,1 );if (vs->minor >=8 ) {static const char err[] ="Unsupported authentication type" ;
@@ -105,7 +112,8 @@ static void vnc_tls_handshake_io(void *o#define NEED_X509_AUTH (vs) \ ((vs)->vd->subauth == VNC_AUTH_VENCRYPT_X509NONE || \ (vs)->vd->subauth == VNC_AUTH_VENCRYPT_X509VNC || \ - (vs)->vd->subauth == VNC_AUTH_VENCRYPT_X509PLAIN) + (vs)->vd->subauth == VNC_AUTH_VENCRYPT_X509PLAIN || \ + (vs)->vd->subauth == VNC_AUTH_VENCRYPT_X509SASL)static int protocol_client_vencrypt_auth (VncState *vs,uint8_t *data,size_t len)
vnc.c +222 -27
392 lines not on this page · raw message
vnc.h +28 -3
@@ -79,6 +79,10 @@ typedef struct VncDisplay VncDisplay;#include "vnc-tls.h" #include "vnc-auth-vencrypt.h" #endif +#ifdef CONFIG_VNC_SASL +#include "vnc-auth-sasl.h" +#endif +struct VncDisplay {
@@ -118,10 +122,12 @@ struct VncStateint minor;char challenge[VNC_AUTH_CHALLENGE_SIZE ]; -#ifdef CONFIG_VNC_TLS VncStateTLS tls;#endif +#ifdef CONFIG_VNC_SASL +VncStateSASL sasl; +#endif Buffer output;Buffer input;
@@ -160,8 +166,9 @@ enum {VNC_AUTH_RA2NE =6 ,VNC_AUTH_TIGHT =16 ,VNC_AUTH_ULTRA =17 , -VNC_AUTH_TLS =18 , -VNC_AUTH_VENCRYPT =19 +VNC_AUTH_TLS =18 ,/* Supported in GTK-VNC & VINO */ +VNC_AUTH_VENCRYPT =19 ,/* Supported in GTK-VNC & VeNCrypt */ + VNC_AUTH_SASL = 20, /* Supported in GTK-VNC & VINO */ }; enum {
@@ -172,6 +179,8 @@ enum {VNC_AUTH_VENCRYPT_X509NONE =260 ,VNC_AUTH_VENCRYPT_X509VNC =261 ,VNC_AUTH_VENCRYPT_X509PLAIN =262 , +VNC_AUTH_VENCRYPT_X509SASL =263 , + VNC_AUTH_VENCRYPT_TLSSASL = 264, };
@@ -255,6 +264,8 @@ enum {void vnc_client_read (void *opaque);void vnc_client_write (void *opaque); +long vnc_client_read_buf (VncState *vs,uint8_t *data,size_t datalen); +long vnc_client_write_buf (VncState *vs,const uint8_t *data,size_t datalen);/* Protocol I/O functions */ void vnc_write (VncState *vs,const void *data,size_t len);
@@ -274,8 +285,22 @@ uint32_t read_u32(uint8_t *data, size_t/* Protocol stage functions */ void vnc_client_error (VncState *vs); +int vnc_client_io_error (VncState *vs,int ret,int last_errno);void start_client_init (VncState *vs);void start_auth_vnc (VncState *vs); +/* Buffer management */ +void buffer_reserve (Buffer *buffer,size_t len); +int buffer_empty (Buffer *buffer); +uint8_t *buffer_end (Buffer *buffer); +void buffer_reset (Buffer *buffer); +void buffer_append (Buffer *buffer,const void *data,size_t len); + + +/* Misc helpers */ + +char *vnc_socket_local_addr (const char *format,int fd); +char *vnc_socket_remote_addr (const char *format,int fd); +#endif /* __QEMU_VNC_H */
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Re: [Qemu-devel] PATCH: 6/9: Add SASL authentication support
In reply to Daniel P. BerrangeQuoted 27 lines · Daniel P. Berrange
diff -r
0eb0b12c0673qemu-doc.texiqemu-doc.texi +15
-0@@ -616,6 +616,21 @@ path following this option specifies whe be loaded from. See the @ref{vnc_security} section for details on generating certificates. +@item sasl + +Require that the client use SASL to authenticate with the VNC server. +The exact choice of authentication method used is controlled from the +system / user's SASL configuration file for the 'qemu' service. This +is typically found in /etc/sasl2/qemu.conf. If running QEMU as an +unprivileged user, an environment variable SASL_CONF_PATH can be used +to make it search alternate locations for the service config. +While some SASL auth methods can also provide data encryption (eg GSSAPI), +it is recommended that SASL always be combined with the 'tls' and +'x509' settings to enable use of SSL and server certificates. This +ensures a data encryption preventing compromise of authentication +credentials. See the @ref{vnc_security} section for details on using +SASL authentication. + @end table @end table
qemu-doc.texi This implements UDP Net Console. · line 984
Quoted 8 lines
qemu-doc.texi +0
-2@@ -964,8 +979,6 @@ This implements UDP Net Console. When @var{remote_host} or @var{src_ip} are not specified they default to @code{0.0.0.0}. When not using a specified @var{src_port} a random port is automatically chosen. -@item msmouse -Three button serial mouse. Configure the guest to use Microsoft protocol. If you just want a simple readonly console you can use @code{netcat} or @code{nc}, by starting qemu with: @code{-serial udp::4555} and nc as:
That removal looks like a mistake to me. I'm going to remove it from your patch.
Regards,
Anthony Liguori
Re: [Qemu-devel] PATCH: 6/9: Add SASL authentication support
In reply to Daniel P. Berrangevnc-auth-sasl.c line 29
Quoted 13 lines · Daniel P. Berrange
This patch adds the new SASL authentication protocol to the VNC server.
diff -r
0eb0b12c0673vnc-auth-sasl.cvnc-auth-sasl.c new file +6
-0+ +#include "vnc.h" + +/* Max amount of data we send/recv for SASL steps to prevent DOS */ +#define SASL_DATA_MAX_LEN (1024 * 1024) +
FYI, last time I posted this series, a question was raised about whether this limit is large enough for Windows Kerberos tickets with lots of groups. I've done a little googling and found this MicroSoft technote
http://technet.microsoft.com/en-us/library/cc756101.aspx
"Recommended Maximum Kerberos Settings
The maximum recommended size for a Kerberos ticket is 65,535 bytes, which is configured through the MaxTokenSize REG_DWORD value in the registry (HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Lsa\Kerberos\Parameters). Increasing this value from the default may cause errors, particularly when Web browsers or Web servers are used. "
Given that Microsoft recommends a max size of 65,535 bytes I think we should be OK with this 1MB limit on a SASL auth step. In any case this is only a server side sanity check, not a fundamental part of the auth protocol definition, so we can easily increase in future should it become a problem
Regards,
Daniel
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Re: [Qemu-devel] PATCH: 6/9: Add SASL authentication support
Quoted 28 lines · Daniel P. Berrange
vnc-auth-sasl.c line 29
Quoted 10 lines · Daniel P. Berrange
diff -r
0eb0b12c0673vnc-auth-sasl.cvnc-auth-sasl.c new file +6
-0+ +#include "vnc.h" + +/* Max amount of data we send/recv for SASL steps to prevent DOS */ +#define SASL_DATA_MAX_LEN (1024 * 1024) +FYI, last time I posted this series, a question was raised about whether this limit is large enough for Windows Kerberos tickets with lots of groups. I've done a little googling and found this MicroSoft technote
http://technet.microsoft.com/en-us/library/cc756101.aspx
"Recommended Maximum Kerberos Settings
The maximum recommended size for a Kerberos ticket is 65,535 bytes, which is configured through the MaxTokenSize
REG_DWORDvalue in the registry (HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Lsa\Kerberos\Parameters). Increasing this value from the default may cause errors, particularly when Web browsers or Web servers are used. "
Quoted 6 lines
Given that Microsoft recommends a max size of 65,535 bytes I think we should be OK with this 1MB limit on a SASL auth step. In any case this is only a server side sanity check, not a fundamental part of the auth protocol definition, so we can easily increase in future should it become a problem
If I recall correctly, 1MB was the limit I placed on SASL authentication steps a while ago and while we had all kinds of trouble with large kerberos tickets from windows machines, it wasn't with SASL. That code has been in production for a few years now.
jch
Re: [Qemu-devel] PATCH: 7/9: Include auth credentials in 'info vnc'
In reply to Daniel P. BerrangeThis patch extends the 'info vnc' monitor output to include information about the VNC client authentication credentials.
For clients authenticated using SASL, this will output the username.
For clients authenticated using x509 certificates, this will output the x509 distinguished name.
Auth can be stacked, so both username & x509 dname may be shown.
Server:
address: 0.0.0.0:5902
auth: vencrypt+x509+sasl
Client:
address: 10.33.6.67:38621
x509 dname: C=GB,O=ACME,L=London,ST=London,CN=localhost
username: admin
Client:
address: 10.33.6.63:38620
x509 dname: C=GB,O=ACME,L=London,ST=London,CN=localhost
username: adminvnc-tls.c | 17 +++++++++++++++++ vnc-tls.h | 3 +++ vnc.c | 19 +++++++++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-)
vnc-tls.c +17 -0
@@ -241,6 +241,22 @@ int vnc_tls_validate_certificate(structreturn -1 ; } +if (i ==0 ) { +size_t dnameSize =1024 ; + vs->tls.dname =qemu_malloc (dnameSize); + requery: +if ((ret =gnutls_x509_crt_get_dn (cert, vs->tls.dname, &dnameSize)) !=0 ) { +if (ret ==GNUTLS_E_SHORT_MEMORY_BUFFER ) { + vs->tls.dname =qemu_realloc (vs->tls.dname, dnameSize); + goto requery; + } +gnutls_x509_crt_deinit (cert); +VNC_DEBUG ("Cannot get client distinguished name: %s" , +gnutls_strerror (ret)); +return -1 ; + } + } +gnutls_x509_crt_deinit (cert); }
@@ -347,6 +363,7 @@ void vnc_tls_client_cleanup(struct VncSt vs->tls.session =NULL ; } vs->tls.wiremode =VNC_WIREMODE_CLEAR ; +free (vs->tls.dname); }
vnc-tls.h +3 -0
@@ -55,6 +55,9 @@ struct VncStateTLS {/* Whether data is being TLS encrypted yet */ int wiremode;gnutls_session_t session; + +/* Client's Distinguished Name from the x509 cert */ +char *dname; };int vnc_tls_client_setup (VncState *vs,int x509Creds);
vnc.c +17 -2
@@ -156,6 +156,21 @@ static void do_info_vnc_client(VncStateterm_puts ("Client:\n" );term_puts (clientAddr);free (clientAddr); + +#ifdef CONFIG_VNC_TLS +if (client->tls.session && + client->tls.dname) +term_printf (" x509 dname: %s\n" , client->tls.dname); +else +term_puts (" x509 dname: none\n" ); +#endif +#ifdef CONFIG_VNC_SASL +if (client->sasl.conn && + client->sasl.username) +term_printf (" username: %s\n" , client->sasl.username); +else +term_puts (" username: none\n" ); +#endif }void do_info_vnc (void )
@@ -1823,7 +1838,7 @@ static int protocol_client_auth(VncState/* We only advertise 1 auth scheme at a time, so client * must pick the one we sent. Verify this */ if (data[0 ] != vs->vd->auth) {/* Reject auth */ -VNC_DEBUG ("Reject auth %d\n" , (int )data[0 ]); +VNC_DEBUG ("Reject auth %d because it didn't match advertized\n" , (int )data[0 ]);vnc_write_u32 (vs,1 );if (vs->minor >=8 ) {static const char err[] ="Authentication failed" ;
@@ -1863,7 +1878,7 @@ static int protocol_client_auth(VncState#endif /* CONFIG_VNC_SASL */ default :/* Should not be possible, but just in case */ -VNC_DEBUG ("Reject auth %d\n" , vs->vd->auth); +VNC_DEBUG ("Reject auth %d server code bug\n" , vs->vd->auth);vnc_write_u8 (vs,1 );if (vs->minor >=8 ) {static const char err[] ="Authentication failed" ;
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Re: [Qemu-devel] PATCH: 8/9: Support ACLs for controlling VNC access
In reply to Daniel P. BerrangeThis patch introduces a generic internal API for access control lists to be used by network servers in QEMU. It adds support for checking these ACL in the VNC server, in two places. The first ACL is for the SASL authentication mechanism, checking the SASL username. This ACL is called 'vnc.username'. The second is for the TLS authentication mechanism, when x509 client certificates are turned on, checking against the Distinguished Name of the client. This ACL is called 'vnc.x509dname'
The internal API provides for an ACL with the following characteristics
- A unique name, eg vnc.username, and vnc.x509dname.
- A default policy, allow or deny
- An ordered series of match rules, with allow or deny policy
If none of the match rules apply, then the default policy is used.
There is a monitor API to manipulate the ACLs, which I'll describe via examples
(qemu) acl show vnc.username
policy: allow
(qemu) acl policy vnc.username denya
acl: policy set to 'deny'
(qemu) acl allow vnc.username fred
acl: added rule at position 1
(qemu) acl allow vnc.username bob
acl: added rule at position 2
(qemu) acl allow vnc.username joe 1
acl: added rule at position 1
(qemu) acl show vnc.username
policy: deny
0: allow fred
1: allow joe
2: allow bob
(qemu) acl show vnc.x509dname
policy: allow
(qemu) acl policy vnc.x509dname deny
acl: policy set to 'deny'
(qemu) acl allow vnc.x509dname C=GB,O=ACME,L=London,CN=*
acl: added rule at position 1
(qemu) acl allow vnc.x509dname C=GB,O=ACME,L=Boston,CN=bob
acl: added rule at position 2
(qemu) acl show vnc.x509dname
policy: deny
0: allow C=GB,O=ACME,L=London,CN=*
1: allow C=GB,O=ACME,L=Boston,CN=bob
At startup the ACLs currently default to an allow policy. The next patch will provide a way to load a pre-defined ACL when starting up
Makefile | 6 +- b/acl.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ b/acl.h | 74 ++++++++++++++++++++++++ monitor.c | 95 +++++++++++++++++++++++++++++++ vnc-auth-sasl.c | 16 ++++- vnc-auth-sasl.h | 7 ++ vnc-tls.c | 19 ++++++ vnc-tls.h | 3 + vnc.c | 14 ++++ vnc.h | 3 + 10 files changed, 398 insertions(+), 7 deletions(-)
Makefile +4 -2
@@ -144,7 +144,7 @@ endif ifdef CONFIG_CURSES OBJS+=curses.o endif -OBJS+=vnc.o d3des.o +OBJS+=vnc.o acl.o d3des.o ifdef CONFIG_VNC_TLS OBJS+=vnc-tls.o vnc-auth-vencrypt.o endif
@@ -174,9 +174,11 @@ sdl.o: sdl.c keymaps.h sdl_keysym.h sdl.o audio/sdlaudio.o: CFLAGS += $(SDL_CFLAGS) +acl.o: acl.h acl.c + vnc.h: vnc-tls.h vnc-auth-vencrypt.h vnc-auth-sasl.h keymaps.h -vnc.o: vnc.c vnc.h vnc_keysym.h vnchextile.h d3des.c d3des.h +vnc.o: vnc.c vnc.h vnc_keysym.h vnchextile.h d3des.c d3des.h acl.h vnc.o: CFLAGS += $(CONFIG_VNC_TLS_CFLAGS)
acl.c new file +168 -0
168 lines not on this page · raw message
acl.h new file +74 -0
74 lines not on this page · raw message
monitor.c +95 -0
116 lines not on this page · raw message
vnc-auth-sasl.c +13 -3
@@ -120,22 +120,32 @@ static int vnc_auth_sasl_check_access(Vn {const void *val;int err; +int allow; err =sasl_getprop (vs->sasl.conn,SASL_USERNAME , &val);if (err !=SASL_OK ) { -VNC_DEBUG ("cannot query SASL username on connection %d (%s)\n" , +VNC_DEBUG ("cannot query SASL username on connection %d (%s), denying access\n" , err,sasl_errstring (err,NULL ,NULL ));return -1 ; }if (val ==NULL ) { -VNC_DEBUG ("no client username was found\n" ); +VNC_DEBUG ("no client username was found, denying access\n" );return -1 ; }VNC_DEBUG ("SASL client username %s\n" , (const char *)val); vs->sasl.username =qemu_strdup ((const char *)val); -return 0 ; +if (vs->vd->sasl.acl ==NULL ) { +VNC_DEBUG ("unexpectedly missing ACL, denying access\n" ); +return -1 ; + } + + allow =qemu_acl_party_is_allowed (vs->vd->sasl.acl, vs->sasl.username); + +VNC_DEBUG ("SASL client %s %s by ACL\n" , vs->sasl.username, + allow ?"allowed" :"denied" ); +return allow ?0 :-1 ; }static int vnc_auth_sasl_check_ssf (VncState *vs)
vnc-auth-sasl.h +7 -0
@@ -30,6 +30,9 @@#include <sasl/sasl.h> typedef struct VncStateSASL VncStateSASL ; +typedef struct VncDisplaySASL VncDisplaySASL ; + +#include "acl.h" struct VncStateSASL {sasl_conn_t *conn;
@@ -56,6 +59,10 @@ struct VncStateSASL {char *mechlist; }; +struct VncDisplaySASL { +ACL *acl; +}; +void vnc_sasl_client_cleanup (VncState *vs);long vnc_client_read_sasl (VncState *vs);
vnc-tls.c +19 -0
@@ -255,6 +255,25 @@ int vnc_tls_validate_certificate(struct gnutls_strerror (ret));return -1 ; } + +if (vs->vd->tls.x509verify) { +int allow; +if (!vs->vd->tls.acl) { +VNC_DEBUG ("unexpected missing acl, denying client\n" ); +gnutls_x509_crt_deinit (cert); +return -1 ; + } + + allow =qemu_acl_party_is_allowed (vs->vd->tls.acl, + vs->tls.dname); + +VNC_DEBUG ("TLS x509 ACL check for %s is %s\n" , + vs->tls.dname, allow ?"allowed" :"denied" ); +if (!allow) { +gnutls_x509_crt_deinit (cert); +return -1 ; + } + } }gnutls_x509_crt_deinit (cert);
vnc-tls.h +3 -0
@@ -31,6 +31,8 @@#include <gnutls/gnutls.h> #include <gnutls/x509.h> +#include "acl.h" +enum {VNC_WIREMODE_CLEAR ,VNC_WIREMODE_TLS ,
@@ -42,6 +44,7 @@ typedef struct VncStateTLS VncStateTLS;/* Server state */ struct VncDisplayTLS {int x509verify;/* Non-zero if server requests & validates client cert */ +ACL *acl;/* Paths to x509 certs/keys */ char *x509cacert;
vnc.c +12 -2
@@ -28,6 +28,7 @@#include "sysemu.h" #include "qemu_socket.h" #include "qemu-timer.h" +#include "acl.h" #define VNC_REFRESH_INTERVAL (1000 / 30)
@@ -2104,6 +2105,10 @@ int vnc_display_open(DisplayState *ds, c #ifdef CONFIG_VNC_SASL }else if (strncmp (options,"sasl" ,4 ) ==0 ) { sasl =1 ;/* Require SASL auth */ +if (!(vs->sasl.acl =qemu_acl_init ("vnc.username" ))) { +fprintf (stderr,"Failed to create username ACL\n" ); +exit (1 ); + }#endif #ifdef CONFIG_VNC_TLS }else if (strncmp (options,"tls" ,3 ) ==0 ) {
@@ -2111,8 +2116,13 @@ int vnc_display_open(DisplayState *ds, c }else if (strncmp (options,"x509" ,4 ) ==0 ) {char *start, *end; x509 =1 ;/* Require x509 certificates */ -if (strncmp (options,"x509verify" ,10 ) ==0 ) - vs->tls.x509verify =1 ;/* ...and verify client certs */ +if (strncmp (options,"x509verify" ,10 ) ==0 ) { + vs->tls.x509verify =1 ;/* ...and verify client certs */ +if (!(vs->tls.acl =qemu_acl_init ("vnc.x509dname" ))) { +fprintf (stderr,"Failed to create x509 dname ACL\n" ); +exit (1 ); + } + }/* Now check for 'x509=/some/path' postfix * and use that to setup x509 certificate/key paths */
vnc.h +3 -0
@@ -98,6 +98,9 @@ struct VncDisplayint subauth;/* Used by VeNCrypt */ VncDisplayTLS tls;#endif +#ifdef CONFIG_VNC_SASL +VncDisplaySASL sasl; +#endif };struct VncState
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Re: [Qemu-devel] PATCH: 8/9: Support ACLs for controlling VNC access
Quoted 67 lines · Daniel P. Berrange
This patch introduces a generic internal API for access control lists to be used by network servers in QEMU. It adds support for checking these ACL in the VNC server, in two places. The first ACL is for the SASL authentication mechanism, checking the SASL username. This ACL is called 'vnc.username'. The second is for the TLS authentication mechanism, when x509 client certificates are turned on, checking against the Distinguished Name of the client. This ACL is called 'vnc.x509dname'
The internal API provides for an ACL with the following characteristics
- A unique name, eg vnc.username, and vnc.x509dname.
- A default policy, allow or deny
- An ordered series of match rules, with allow or deny policyIf none of the match rules apply, then the default policy is used.
There is a monitor API to manipulate the ACLs, which I'll describe via examples
(qemu) acl show vnc.username
policy: allow
(qemu) acl policy vnc.username denya
acl: policy set to 'deny'
(qemu) acl allow vnc.username fred
acl: added rule at position 1
(qemu) acl allow vnc.username bob
acl: added rule at position 2
(qemu) acl allow vnc.username joe 1
acl: added rule at position 1
(qemu) acl show vnc.username
policy: deny
0: allow fred
1: allow joe
2: allow bob(qemu) acl show vnc.x509dname
policy: allow
(qemu) acl policy vnc.x509dname deny
acl: policy set to 'deny'
(qemu) acl allow vnc.x509dname C=GB,O=ACME,L=London,CN=*
acl: added rule at position 1
(qemu) acl allow vnc.x509dname C=GB,O=ACME,L=Boston,CN=bob
acl: added rule at position 2
(qemu) acl show vnc.x509dname
policy: deny
0: allow C=GB,O=ACME,L=London,CN=*
1: allow C=GB,O=ACME,L=Boston,CN=bobAt startup the ACLs currently default to an allow policy. The next patch will provide a way to load a pre-defined ACL when starting up
Makefile | 6 +- b/acl.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ b/acl.h | 74 ++++++++++++++++++++++++ monitor.c | 95 +++++++++++++++++++++++++++++++ vnc-auth-sasl.c | 16 ++++- vnc-auth-sasl.h | 7 ++ vnc-tls.c | 19 ++++++ vnc-tls.h | 3 + vnc.c | 14 ++++ vnc.h | 3 + 10 files changed, 398 insertions(+), 7 deletions(-)
Quoted 2 lines
Signed-off-by Daniel P. Berrange <[email protected]>
This breaks the build on win32. Attached are the build log and config info.
Regards,
Anthony Liguori
# Automatically generated by configure - do not modify
# Configured with: '/home/anthony/git/qemu/configure' '--cross-prefix=i686-pc-mingw32-' '--target-list=x86_64-softmmu' prefix=c:\\Program Files\\Qemu
bindir=${prefix}
mandir=${prefix}
datadir=${prefix}
docdir=${prefix}
MAKE=make
INSTALL=install
CC=i686-pc-mingw32-gcc
HOST_CC=gcc
AR=i686-pc-mingw32-ar
STRIP=i686-pc-mingw32-strip -s -R .comment -R .note
OS_CFLAGS=
OS_LDFLAGS=
ARCH_CFLAGS=-m32
ARCH_LDFLAGS=-m32
CFLAGS= -O2 -g -fno-strict-aliasing -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls LDFLAGS= -g -Wl,--warn-common
EXESUF=.exe
AIOLIBS=
ARCH=i386CONFIG_WIN32=yesCONFIG_GDBSTUB=yesCONFIG_SLIRP=yesCONFIG_AC97=yesCONFIG_ES1370=yesCONFIG_SB16=yesCONFIG_VNC_TLS=yesCONFIG_VNC_TLS_CFLAGS=-I/usr/i686-pc-mingw32/sys-root/mingw/include CONFIG_VNC_TLS_LIBS=-L/usr/i686-pc-mingw32/sys-root/mingw/lib -lgnutls
VERSION=0.9.1
SRC_PATH=/home/anthony/git/qemu
VPATH=/home/anthony/git/qemu
TARGET_DIRS=x86_64-softmmuCONFIG_SDL=yes
SDL_LIBS=-lmingw32 -lSDLmain -lSDL -mwindows
SDL_CFLAGS=-I/usr/i686-pc-mingw32/sys-root/mingw/include/SDL -D_GNU_SOURCE=1 -Dmain=SDL_main
INSTALL_BLOBS=yes
HOST_USB=stub
TOOLS=qemu-img$(EXESUF)
Install prefix c:\\Program Files\\Qemu
BIOS directory c:\\Program Files\\Qemu
binary directory c:\\Program Files\\Qemu
Source path /home/anthony/git/qemu
C compiler i686-pc-mingw32-gcc
Host C compiler gcc
ARCH_CFLAGS -m32
make make
install install
host CPU i386
host big endian no
target list x86_64-softmmu
gprof enabled no
sparse enabled no
profiler no
static build no
-Werror enabled no
SDL support yes
SDL static link yes
curses support no
mingw32 support yes
Audio drivers
Extra audio cards ac97 es1370 sb16
Mixer emulation no
VNC TLS support yes
TLS CFLAGS -I/usr/i686-pc-mingw32/sys-root/mingw/include
TLS LIBS -L/usr/i686-pc-mingw32/sys-root/mingw/lib -lgnutls
VNC SASL support no
kqemu support yes
brlapi support no
Documentation no
NPTL support no
vde support no
AIO support no
Install blobs yes
KVM support no - (linux/kvm.h: No such file or directory, #error Invalid KVM version, #error Missing KVM capability KVM_CAP_USER_MEMORY, #error Missing KVM capability KVM_CAP_SET_TSS_ADDR, #error Missing KVM capability KVM_CAP_DESTROY_MEMORY_REGION_WORKS)
fdt support noRe: [Qemu-devel] PATCH: 8/9: Support ACLs for controlling VNC access
In reply to Daniel P. BerrangeQuoted 67 lines · Daniel P. Berrange
This patch introduces a generic internal API for access control lists to be used by network servers in QEMU. It adds support for checking these ACL in the VNC server, in two places. The first ACL is for the SASL authentication mechanism, checking the SASL username. This ACL is called 'vnc.username'. The second is for the TLS authentication mechanism, when x509 client certificates are turned on, checking against the Distinguished Name of the client. This ACL is called 'vnc.x509dname'
The internal API provides for an ACL with the following characteristics
- A unique name, eg vnc.username, and vnc.x509dname.
- A default policy, allow or deny
- An ordered series of match rules, with allow or deny policyIf none of the match rules apply, then the default policy is used.
There is a monitor API to manipulate the ACLs, which I'll describe via examples
(qemu) acl show vnc.username
policy: allow
(qemu) acl policy vnc.username denya
acl: policy set to 'deny'
(qemu) acl allow vnc.username fred
acl: added rule at position 1
(qemu) acl allow vnc.username bob
acl: added rule at position 2
(qemu) acl allow vnc.username joe 1
acl: added rule at position 1
(qemu) acl show vnc.username
policy: deny
0: allow fred
1: allow joe
2: allow bob(qemu) acl show vnc.x509dname
policy: allow
(qemu) acl policy vnc.x509dname deny
acl: policy set to 'deny'
(qemu) acl allow vnc.x509dname C=GB,O=ACME,L=London,CN=*
acl: added rule at position 1
(qemu) acl allow vnc.x509dname C=GB,O=ACME,L=Boston,CN=bob
acl: added rule at position 2
(qemu) acl show vnc.x509dname
policy: deny
0: allow C=GB,O=ACME,L=London,CN=*
1: allow C=GB,O=ACME,L=Boston,CN=bobAt startup the ACLs currently default to an allow policy. The next patch will provide a way to load a pre-defined ACL when starting up
Makefile | 6 +- b/acl.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ b/acl.h | 74 ++++++++++++++++++++++++ monitor.c | 95 +++++++++++++++++++++++++++++++ vnc-auth-sasl.c | 16 ++++- vnc-auth-sasl.h | 7 ++ vnc-tls.c | 19 ++++++ vnc-tls.h | 3 + vnc.c | 14 ++++ vnc.h | 3 + 10 files changed, 398 insertions(+), 7 deletions(-)
Quoted 2 lines
Signed-off-by Daniel P. Berrange <[email protected]>
This breaks the win32 build. Attached are the make and config logs. I'm using the F10 mingw packages fwiw.
Regards,
Anthony Liguori
# Automatically generated by configure - do not modify
# Configured with: '/home/anthony/git/qemu/configure' '--cross-prefix=i686-pc-mingw32-' '--target-list=x86_64-softmmu' prefix=c:\\Program Files\\Qemu
bindir=${prefix}
mandir=${prefix}
datadir=${prefix}
docdir=${prefix}
MAKE=make
INSTALL=install
CC=i686-pc-mingw32-gcc
HOST_CC=gcc
AR=i686-pc-mingw32-ar
STRIP=i686-pc-mingw32-strip -s -R .comment -R .note
OS_CFLAGS=
OS_LDFLAGS=
ARCH_CFLAGS=-m32
ARCH_LDFLAGS=-m32
CFLAGS= -O2 -g -fno-strict-aliasing -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls LDFLAGS= -g -Wl,--warn-common
EXESUF=.exe
AIOLIBS=
ARCH=i386CONFIG_WIN32=yesCONFIG_GDBSTUB=yesCONFIG_SLIRP=yesCONFIG_AC97=yesCONFIG_ES1370=yesCONFIG_SB16=yesCONFIG_VNC_TLS=yesCONFIG_VNC_TLS_CFLAGS=-I/usr/i686-pc-mingw32/sys-root/mingw/include CONFIG_VNC_TLS_LIBS=-L/usr/i686-pc-mingw32/sys-root/mingw/lib -lgnutls
VERSION=0.9.1
SRC_PATH=/home/anthony/git/qemu
VPATH=/home/anthony/git/qemu
TARGET_DIRS=x86_64-softmmuCONFIG_SDL=yes
SDL_LIBS=-lmingw32 -lSDLmain -lSDL -mwindows
SDL_CFLAGS=-I/usr/i686-pc-mingw32/sys-root/mingw/include/SDL -D_GNU_SOURCE=1 -Dmain=SDL_main
INSTALL_BLOBS=yes
HOST_USB=stub
TOOLS=qemu-img$(EXESUF)
Install prefix c:\\Program Files\\Qemu
BIOS directory c:\\Program Files\\Qemu
binary directory c:\\Program Files\\Qemu
Source path /home/anthony/git/qemu
C compiler i686-pc-mingw32-gcc
Host C compiler gcc
ARCH_CFLAGS -m32
make make
install install
host CPU i386
host big endian no
target list x86_64-softmmu
gprof enabled no
sparse enabled no
profiler no
static build no
-Werror enabled no
SDL support yes
SDL static link yes
curses support no
mingw32 support yes
Audio drivers
Extra audio cards ac97 es1370 sb16
Mixer emulation no
VNC TLS support yes
TLS CFLAGS -I/usr/i686-pc-mingw32/sys-root/mingw/include
TLS LIBS -L/usr/i686-pc-mingw32/sys-root/mingw/lib -lgnutls
VNC SASL support no
kqemu support yes
brlapi support no
Documentation no
NPTL support no
vde support no
AIO support no
Install blobs yes
KVM support no - (linux/kvm.h: No such file or directory, #error Invalid KVM version, #error Missing KVM capability KVM_CAP_USER_MEMORY, #error Missing KVM capability KVM_CAP_SET_TSS_ADDR, #error Missing KVM capability KVM_CAP_DESTROY_MEMORY_REGION_WORKS)
fdt support no
CC qemu-img.o
CC qemu-tool.o
CC osdep.o
CC cutils.o
CC qemu-malloc.o
CC block-cow.o
CC block-qcow.o
CC aes.o
CC block-vmdk.o
/home/anthony/git/qemu/block-vmdk.c: In function 'vmdk_create':
/home/anthony/git/qemu/block-vmdk.c:787: warning: format '%I64d' expects type 'int', but argument 5 has type 'int64_t'
/home/anthony/git/qemu/block-vmdk.c:787: warning: format '%I64d' expects type 'int', but argument 8 has type 'long long int'
CC block-cloop.o
CC block-dmg.o
CC block-bochs.o
CC block-vpc.o
CC block-vvfat.o
CC block-qcow2.o
CC block-parallels.o
CC block-nbd.o
CC nbd.o/home/anthony/git/qemu/nbd.c: In function 'tcp_socket_incoming':/home/anthony/git/qemu/nbd.c:172: warning: passing argument 4 of 'setsockopt' from incompatible pointer type
CC block.o/home/anthony/git/qemu/block.c: In function 'bdrv_info_stats':/home/anthony/git/qemu/block.c:1087: warning: format '%I64u' expects type 'unsigned int', but argument 3 has type 'uint64_t' /home/anthony/git/qemu/block.c:1087: warning: format '%I64u' expects type 'unsigned int', but argument 4 has type 'uint64_t' /home/anthony/git/qemu/block.c:1087: warning: format '%I64u' expects type 'unsigned int', but argument 5 has type 'uint64_t' /home/anthony/git/qemu/block.c:1087: warning: format '%I64u' expects type 'unsigned int', but argument 6 has type 'uint64_t' /home/anthony/git/qemu/block.c:1091: warning: format '%I64d' expects type 'int', but argument 2 has type 'int64_t' /home/anthony/git/qemu/block.c:1091: warning: format '%I64d' expects type 'int', but argument 3 has type 'int64_t' /home/anthony/git/qemu/block.c: In function 'get_human_readable_size':/home/anthony/git/qemu/block.c:1183: warning: format '%I64d' expects type 'int', but argument 4 has type 'int64_t' /home/anthony/git/qemu/block.c:1195: warning: format '%I64d' expects type 'int', but argument 4 has type 'int64_t'
CC aio.o
CC block-raw-win32.o/home/anthony/git/qemu/block-raw-win32.c: In function 'raw_truncate':/home/anthony/git/qemu/block-raw-win32.c:286: warning: pointer targets in passing argument 3 of 'SetFilePointer' differ in signedness /home/anthony/git/qemu/block-raw-win32.c: In function 'raw_getlength':/home/anthony/git/qemu/block-raw-win32.c:304: warning: pointer targets in passing argument 2 of 'GetFileSize' differ in signedness
LINK qemu-img.exe
CC readline.o
CC console.o
CC irq.o
CC i2c.o
CC smbus.o
CC smbus_eeprom.o
CC max7310.o
CC max111x.o
CC wm8750.o
CC ssd0303.o
CC ssd0323.o
CC ads7846.o
CC stellaris_input.o
CC twl92230.o
CC tmp105.o
CC lm832x.o
CC scsi-disk.o
CC cdrom.o
CC scsi-generic.o
CC usb.o
CC usb-hub.o
CC usb-stub.o
CC usb-hid.o
CC usb-msd.o
CC usb-wacom.o
CC usb-serial.o
CC usb-net.o
CC sd.o
CC ssi-sd.o
CC bt.o
CC bt-host.o
/home/anthony/git/qemu/bt-host.c:200: warning: no previous prototype for 'bt_host_hci'
CC bt-vhci.o
CC bt-l2cap.o
CC bt-sdp.o
/home/anthony/git/qemu/hw/bt-sdp.c:790:1: warning: "TRUE" redefined
In file included from /usr/i686-pc-mingw32/sys-root/mingw/include/windows.h:48,
from /home/anthony/git/qemu/qemu-common.h:8,
from /home/anthony/git/qemu/hw/bt-sdp.c:21:
/usr/i686-pc-mingw32/sys-root/mingw/include/windef.h:55:1: warning: this is the location of the previous definition
/home/anthony/git/qemu/hw/bt-sdp.c:794:1: warning: "FALSE" redefined
/usr/i686-pc-mingw32/sys-root/mingw/include/windef.h:52:1: warning: this is the location of the previous definition
CC bt-hci.o
CC bt-hid.o
CC usb-bt.o
CC buffered_file.o
CC migration.o
CC migration-tcp.o/home/anthony/git/qemu/migration-tcp.c: In function 'tcp_wait_for_connect':/home/anthony/git/qemu/migration-tcp.c:62: warning: passing argument 4 of 'getsockopt' from incompatible pointer type
CC net.o/home/anthony/git/qemu/net.c: In function 'net_socket_receive_dgram':/home/anthony/git/qemu/net.c:1124: warning: pointer targets in passing argument 2 of 'sendto' differ in signedness /home/anthony/git/qemu/net.c: In function 'net_socket_send':/home/anthony/git/qemu/net.c:1134: warning: pointer targets in passing argument 2 of 'recv' differ in signedness /home/anthony/git/qemu/net.c: In function 'net_socket_send_dgram':/home/anthony/git/qemu/net.c:1188: warning: pointer targets in passing argument 2 of 'recv' differ in signedness /home/anthony/git/qemu/net.c: In function 'net_cleanup':/home/anthony/git/qemu/net.c:1898: warning: unused variable 'vlan'
CC qemu-sockets.o
CC qemu-char.o/home/anthony/git/qemu/qemu-char.c: In function 'udp_chr_write':/home/anthony/git/qemu/qemu-char.c:1679: warning: pointer targets in passing argument 2 of 'sendto' differ in signedness /home/anthony/git/qemu/qemu-char.c: In function 'udp_chr_read':/home/anthony/git/qemu/qemu-char.c:1707: warning: pointer targets in passing argument 2 of 'recv' differ in signedness /home/anthony/git/qemu/qemu-char.c: In function 'tcp_chr_read':/home/anthony/git/qemu/qemu-char.c:1872: warning: pointer targets in passing argument 2 of 'recv' differ in signedness
CC net-checksum.o
CC savevm.o/home/anthony/git/qemu/savevm.c: In function 'socket_get_buffer':/home/anthony/git/qemu/savevm.c:171: warning: pointer targets in passing argument 2 of 'recv' differ in signedness
CC cache-utils.o
CC tap-win32.o/home/anthony/git/qemu/tap-win32.c: In function 'is_tap_win32_dev':/home/anthony/git/qemu/tap-win32.c:259: warning: pointer targets in passing argument 5 of 'RegQueryValueExA' differ in signedness /home/anthony/git/qemu/tap-win32.c:269: warning: pointer targets in passing argument 5 of 'RegQueryValueExA' differ in signedness /home/anthony/git/qemu/tap-win32.c: In function 'get_device_guid':/home/anthony/git/qemu/tap-win32.c:358: warning: pointer targets in passing argument 5 of 'RegQueryValueExA' differ in signedness /home/anthony/git/qemu/tap-win32.c: In function 'tap_win32_open':/home/anthony/git/qemu/tap-win32.c:615: warning: pointer targets in passing argument 7 of 'DeviceIoControl' differ in signedness /home/anthony/git/qemu/tap-win32.c: In function 'tap_win32_send':/home/anthony/git/qemu/tap-win32.c:659: warning: pointer targets in passing argument 2 of 'tap_win32_free_buffer' differ in signedness
CC audio/audio.o/home/anthony/git/qemu/audio/audio.c: In function 'audio_get_avail':/home/anthony/git/qemu/audio/audio.c:1225: warning: format '%I64d' expects type 'int', but argument 4 has type 'long long int'
CC audio/noaudio.o
CC audio/wavaudio.o
CC audio/mixeng.o
CC audio/sdlaudio.o
CC audio/wavcapture.o
CC keymaps.o
CC sdl.o
CC x_keymap.o
CC vnc.o
In file included from /home/anthony/git/qemu/vnc-tls.h:34,
from /home/anthony/git/qemu/vnc.h:79,
from /home/anthony/git/qemu/vnc.c:27:/home/anthony/git/qemu/acl.h:31: error: conflicting types for 'ACL' /usr/i686-pc-mingw32/sys-root/mingw/include/winnt.h:1834: error: previous declaration of 'ACL' was here /home/anthony/git/qemu/vnc.c: In function 'addr_to_string':/home/anthony/git/qemu/vnc.c:66: warning: implicit declaration of function 'asprintf' /home/anthony/git/qemu/vnc.c: In function 'vnc_client_write_buf':/home/anthony/git/qemu/vnc.c:939: warning: pointer targets in passing argument 2 of 'send' differ in signedness /home/anthony/git/qemu/vnc.c: In function 'vnc_client_read_buf':/home/anthony/git/qemu/vnc.c:1044: warning: pointer targets in passing argument 2 of 'recv' differ in signedness
make: *** [vnc.o] Error 1
Re: [Qemu-devel] PATCH: 8/9: Support ACLs for controlling VNC access
Quoted 15 lines · Anthony Liguori
Quoted 15 lines
Makefile| 6 +-b/acl.c| 168
++++++++++++++++++++++++++++++++++++++++++++++++++++++++b/acl.h | 74 ++++++++++++++++++++++++ monitor.c | 95 +++++++++++++++++++++++++++++++ vnc-auth-sasl.c | 16 ++++- vnc-auth-sasl.h | 7 ++ vnc-tls.c | 19 ++++++ vnc-tls.h | 3 + vnc.c | 14 ++++ vnc.h | 3 + 10 files changed, 398 insertions(+), 7 deletions(-)
Quoted 5 lines
Quoted 2 lines
Signed-off-by Daniel P. Berrange <[email protected]>This breaks the win32 build. Attached are the make and config logs. I'm using the F10 mingw packages fwiw.
Ahh, I see one of the Windows system headers define a type called 'ACL' already, so I'll have to adjust that.
Quoted 6 lines
CC vnc.o
In file included from/home/anthony/git/qemu/vnc-tls.h:34,from /home/anthony/git/qemu/vnc.h:79, from /home/anthony/git/qemu/vnc.c:27:
/home/anthony/git/qemu/acl.h:31: error: conflicting types for 'ACL'/usr/i686-pc-mingw32/sys-root/mingw/include/winnt.h:1834: error: previous declaration of 'ACL' was here
Daniel
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Re: [Qemu-devel] PATCH: 9/9: Persist ACLs in external files
In reply to Daniel P. BerrangeThis patch introduces a simple access control file capability for authorizing clients of QEMU's various network services. The file is designed such that it can be shared amongst multiple QEMU instances. The style of commands is similar to that used in the monitor ACL commands. It is a line oriented format, with comments indicated by leading '#'.Each non-comment line consists of 4 fields, 'scope', 'aclname', 'action' and 'value'.
The scope allows control over what VMs the rule applies to. This is a glob, so '*' matches any VM. An explicit value can be match against the VM name, as given by the '-name' argument.
The aclname is one of the ACLs defined by QEMU, either vnc.username or vnc.x509dname for now. More later perhaps.
The action can be one of 'policy' 'allow', or 'deny'. The policy sets the default allow/deny state for the ACL, if no rules match.
Finally the 'value' is another glob matching against the client name being checked.
An example showing use of both SASL username ACLs, and x509 client certificate distinguished name ACLs.
# Default deny all for all SASL authenticated users in all VMs
* vnc.username policy deny
# Allow bob access to all VMs
* vnc.username allow bob
# Allow fred and test access to the VM named 'demo' demo vnc.username allow fred
demo vnc.username allow test
# Deny all x509 client certificates on all VMs
* vnc.x509dname policy deny
# Allow all users from the ACME, London office to all VMs
* vnc.x509dname allow "C=GB,O=ACME,L=London,CN=*"
# Allow Joe from Boston, access to VM 'demo' demo vnc.x509dname allow "C=GB,O=ACME,L=Boston,CN=joe"
Save this to a file, and give it to QEMU at startup with '-acl demo.acl'
The code for parsing the file is a little crude because I didn't want to spend too much time writing this. Its more of a proof of concept of how it might be possible to store ACL rules in a simple way.
acl.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ acl.h | 3 + vl.c | 12 +++++++ 3 files changed, 121 insertions(+)
acl.c +106 -0
@@ -67,6 +67,112 @@ ACL *qemu_acl_init(const char *aclname)return acl; } +#define SKIP_SPACES (buf) while (*buf == ' ') { buf++; } + +int qemu_acl_load_file (const char *path, +const char *name) +{ +FILE *f =fopen (path,"r" ); +char line[1024 ]; +int ret =-1 ; +int linenum =0 ; + +if (!f) +return -1 ; + +/* * vnc.username policy deny */ +/* * vnc.username allow fred */ +/* somevm vnc.username allow joe */ +/* somevm vnc.username deny bob*/ +while (fgets (line,sizeof (line), f)) { +char *scope, *aclname, *action, *value; +char *tmp = line; +ACL *acl; +int quoted =0 ; + + linenum++; + +SKIP_SPACES (tmp); +if (line[0 ] =='#' || + line[0 ] =='\n' || + line[0 ] =='\0' ) +continue ; + + scope = tmp; + + tmp =strchr (tmp,' ' ); +if (!tmp) { +fprintf (stderr,"missing aclname data at line %d\n" , linenum); +continue ; + } + *tmp++ ='\0' ; +SKIP_SPACES (tmp); + aclname = tmp; + + tmp =strchr (tmp,' ' ); +if (!tmp) { +fprintf (stderr,"missing action data at line %d\n" , linenum); +continue ; + } + *tmp++ ='\0' ; +SKIP_SPACES (tmp); + action = tmp; + + tmp =strchr (tmp,' ' ); +if (!tmp) { +fprintf (stderr,"missing value data at line %d\n" , linenum); +continue ; + } + *tmp++ ='\0' ; +SKIP_SPACES (tmp); + value = tmp; + + +if (*tmp =='"' ) { + quoted =1 ; + value++; + tmp++; + } +while (*tmp !='\0' && *tmp !='\n' ) { +if ((quoted && *tmp =='"' ) || + (!quoted && *tmp ==' ' )) +break ; + tmp++; + } +if (tmp) + *tmp ='\0' ; + +if (fnmatch (scope, name ? name :"" ,0 ) !=0 ) { +continue ; + } + + acl =qemu_acl_init (aclname); +if (!acl) + goto cleanup; + +if (strcmp (action,"policy" ) ==0 ) { +if (strcmp (value,"allow" ) ==0 ) + acl->defaultDeny =0 ; +else if (strcmp (value,"deny" ) ==0 ) + acl->defaultDeny =1 ; +else +fprintf (stderr,"unknown ACL policy '%s'\n" , value); + }else if (strcmp (action,"allow" ) ==0 || +strcmp (action,"deny" ) ==0 ) { +int deny =strcmp (action,"deny" ) ==0 ?1 :0 ; +qemu_acl_append (acl, deny, value); + }else { +fprintf (stderr,"unknown ACL action '%s'\n" , action); + } + } + ret =0 ; + + cleanup: +fclose (f); + +return ret; +} +int qemu_acl_party_is_allowed (ACL *acl,const char *party) {
acl.h +3 -0
@@ -48,6 +48,9 @@ ACL *qemu_acl_init(const char *aclname);ACL *qemu_acl_find (const char *aclname); +int qemu_acl_load_file (const char *path, +const char *name); +int qemu_acl_party_is_allowed (ACL *acl,const char *party);
vl.c +12 -0
@@ -42,6 +42,7 @@#include "migration.h" #include "kvm.h" #include "balloon.h" +#include "acl.h" #include <unistd.h> #include <fcntl.h>
@@ -3955,6 +3956,7 @@ static void help(int exitcode) "-g WxH[xDEPTH] Set the initial graphical resolution and depth\n"#endif "-vnc display start a VNC server on display\n" +"-acl path path to access control list for network services\n" "\n" "Network options:\n" "-net nic[,vlan=n][,macaddr=addr][,model=type][,name=str]\n"
@@ -4136,6 +4138,7 @@ enum { QEMU_OPTION_full_screen, QEMU_OPTION_g, QEMU_OPTION_vnc, + QEMU_OPTION_acl,/* Network options: */ QEMU_OPTION_net,
@@ -4250,6 +4253,7 @@ static const QEMUOption qemu_options[] = { "g", 1, QEMU_OPTION_g }, #endif { "vnc", HAS_ARG, QEMU_OPTION_vnc }, + { "acl", HAS_ARG, QEMU_OPTION_acl }, /* Network options: */ { "net", HAS_ARG, QEMU_OPTION_net},
@@ -4628,6 +4632,7 @@ int main(int argc, char **argv, char **econst char *pid_file =NULL ;int autostart;const char *incoming =NULL ; +const char *acl_file =NULL ;qemu_cache_utils_init (envp);
@@ -5167,6 +5172,9 @@ int main(int argc, char **argv, char **ecase QEMU_OPTION_vnc: vnc_display = optarg;break ; +case QEMU_OPTION_acl: + acl_file = optarg; +break ;case QEMU_OPTION_no_acpi: acpi_enabled =0 ;break ;
@@ -5618,6 +5626,10 @@ int main(int argc, char **argv, char **e } } +/* Load access control data */ +if (acl_file) +qemu_acl_load_file (acl_file, qemu_name); +if (!display_state)dumb_display_init ();/* just use the first displaystate for the moment */
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|