From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51623) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZV6uq-00052V-Fy for qemu-devel@nongnu.org; Thu, 27 Aug 2015 19:49:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZV6un-0006Px-7k for qemu-devel@nongnu.org; Thu, 27 Aug 2015 19:49:08 -0400 Received: from e18.ny.us.ibm.com ([129.33.205.208]:43467) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZV6un-0006PI-3t for qemu-devel@nongnu.org; Thu, 27 Aug 2015 19:49:05 -0400 Received: from /spool/local by e18.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 27 Aug 2015 19:49:04 -0400 Received: from b01cxnp22035.gho.pok.ibm.com (b01cxnp22035.gho.pok.ibm.com [9.57.198.25]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id 81527C90041 for ; Thu, 27 Aug 2015 19:40:06 -0400 (EDT) Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t7RNn2O559768912 for ; Thu, 27 Aug 2015 23:49:02 GMT Received: from d01av02.pok.ibm.com (localhost [127.0.0.1]) by d01av02.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t7RNn13m019037 for ; Thu, 27 Aug 2015 19:49:01 -0400 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Roth In-Reply-To: <1435675033-9926-1-git-send-email-marcandre.lureau@gmail.com> References: <1435675033-9926-1-git-send-email-marcandre.lureau@gmail.com> Message-ID: <20150827234849.24880.3606@loki> Date: Thu, 27 Aug 2015 18:48:49 -0500 Subject: Re: [Qemu-devel] [PATCH] qemu-ga: implement win32 guest-set-user-password List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , qemu-devel@nongnu.org Quoting Marc-Andr=C3=A9 Lureau (2015-06-30 09:37:13) > Use NetUserSetInfo() to set the user password. > = > This function is notoriously known to be problematic for users with EFS > encrypted files. But the alternative, NetUserChangePassword() requires > the old password. Nevertheless, The EFS file should be recovered by > changing back to the old password. > = > Signed-off-by: Marc-Andr=C3=A9 Lureau Thanks, applied to qga tree: https://github.com/mdroth/qemu/commits/qga > --- > configure | 2 +- > qga/commands-win32.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++= ++++-- > 2 files changed, 76 insertions(+), 3 deletions(-) > = > diff --git a/configure b/configure > index 3063739..400de0d 100755 > --- a/configure > +++ b/configure > @@ -732,7 +732,7 @@ if test "$mingw32" =3D "yes" ; then > sysconfdir=3D"\${prefix}" > local_statedir=3D > confsuffix=3D"" > - libs_qga=3D"-lws2_32 -lwinmm -lpowrprof $libs_qga" > + libs_qga=3D"-lws2_32 -lwinmm -lpowrprof -lnetapi32 $libs_qga" > fi > = > werror=3D"" > diff --git a/qga/commands-win32.c b/qga/commands-win32.c > index fbddc8b..d31530c 100644 > --- a/qga/commands-win32.c > +++ b/qga/commands-win32.c > @@ -16,6 +16,8 @@ > #include > #include > #include > +#include > + > #include "qga/guest-agent-core.h" > #include "qga/vss-win32.h" > #include "qga-qmp-commands.h" > @@ -676,12 +678,84 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorLi= st *vcpus, Error **errp) > return -1; > } > = > +static gchar * > +get_net_error_message(gint error) > +{ > + HMODULE module =3D NULL; > + gchar *retval =3D NULL; > + wchar_t *msg =3D NULL; > + int flags, nchars; > + > + flags =3D FORMAT_MESSAGE_ALLOCATE_BUFFER > + |FORMAT_MESSAGE_IGNORE_INSERTS > + |FORMAT_MESSAGE_FROM_SYSTEM; > + > + if (error >=3D NERR_BASE && error <=3D MAX_NERR) { > + module =3D LoadLibraryExW(L"netmsg.dll", NULL, LOAD_LIBRARY_AS_D= ATAFILE); > + > + if (module !=3D NULL) { > + flags |=3D FORMAT_MESSAGE_FROM_HMODULE; > + } > + } > + > + FormatMessageW(flags, module, error, 0, (LPWSTR)&msg, 0, NULL); > + > + if (msg !=3D NULL) { > + nchars =3D wcslen(msg); > + > + if (nchars > 2 && msg[nchars-1] =3D=3D '\n' && msg[nchars-2] =3D= =3D '\r') { > + msg[nchars-2] =3D '\0'; > + } > + > + retval =3D g_utf16_to_utf8(msg, -1, NULL, NULL, NULL); > + > + LocalFree(msg); > + } > + > + if (module !=3D NULL) { > + FreeLibrary(module); > + } > + > + return retval; > +} > + > void qmp_guest_set_user_password(const char *username, > const char *password, > bool crypted, > Error **errp) > { > - error_setg(errp, QERR_UNSUPPORTED); > + NET_API_STATUS nas; > + char *rawpasswddata =3D NULL; > + size_t rawpasswdlen; > + wchar_t *user, *wpass; > + USER_INFO_1003 pi1003 =3D { 0, }; > + > + if (crypted) { > + error_setg(errp, QERR_UNSUPPORTED); > + return; > + } > + > + rawpasswddata =3D (char *)g_base64_decode(password, &rawpasswdlen); > + rawpasswddata =3D g_renew(char, rawpasswddata, rawpasswdlen + 1); > + rawpasswddata[rawpasswdlen] =3D '\0'; > + > + user =3D g_utf8_to_utf16(username, -1, NULL, NULL, NULL); > + wpass =3D g_utf8_to_utf16(rawpasswddata, -1, NULL, NULL, NULL); > + > + pi1003.usri1003_password =3D wpass; > + nas =3D NetUserSetInfo(NULL, user, > + 1003, (LPBYTE)&pi1003, > + NULL); > + > + if (nas !=3D NERR_Success) { > + gchar *msg =3D get_net_error_message(nas); > + error_setg(errp, "failed to set password: %s", msg); > + g_free(msg); > + } > + > + g_free(user); > + g_free(wpass); > + g_free(rawpasswddata); > } > = > GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp) > @@ -709,7 +783,6 @@ GList *ga_command_blacklist_init(GList *blacklist) > const char *list_unsupported[] =3D { > "guest-suspend-hybrid", "guest-network-get-interfaces", > "guest-get-vcpus", "guest-set-vcpus", > - "guest-set-user-password", > "guest-get-memory-blocks", "guest-set-memory-blocks", > "guest-get-memory-block-size", > "guest-fsfreeze-freeze-list", "guest-get-fsinfo", > -- = > 2.4.3 >=20