1 | /* $Id: VBoxGuestR3LibInfoSvc.cpp 10005 2008-06-27 21:33:35Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, information service.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007 Sun Microsystems, Inc.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 |
|
---|
23 | /*******************************************************************************
|
---|
24 | * Header Files *
|
---|
25 | *******************************************************************************/
|
---|
26 | #include <iprt/string.h>
|
---|
27 | #include <iprt/mem.h>
|
---|
28 | #include <iprt/assert.h>
|
---|
29 | #include <VBox/log.h>
|
---|
30 | #include <VBox/HostServices/VBoxInfoSvc.h> /* For Save and RetrieveVideoMode */
|
---|
31 |
|
---|
32 | #include "VBGLR3Internal.h"
|
---|
33 |
|
---|
34 | using namespace svcInfo;
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Connects to the information service.
|
---|
38 | *
|
---|
39 | * @returns VBox status code
|
---|
40 | * @param pu32ClientId Where to put the client id on success. The client id
|
---|
41 | * must be passed to all the other calls to the service.
|
---|
42 | */
|
---|
43 | VBGLR3DECL(int) VbglR3InfoSvcConnect(uint32_t *pu32ClientId)
|
---|
44 | {
|
---|
45 | VBoxGuestHGCMConnectInfo Info;
|
---|
46 | Info.result = (uint32_t)VERR_WRONG_ORDER; /** @todo drop the cast when the result type has been fixed! */
|
---|
47 | Info.Loc.type = VMMDevHGCMLoc_LocalHost_Existing;
|
---|
48 | memset(&Info.Loc.u, 0, sizeof(Info.Loc.u));
|
---|
49 | strcpy(Info.Loc.u.host.achName, "VBoxSharedInfoSvc");
|
---|
50 | Info.u32ClientID = UINT32_MAX; /* try make valgrid shut up. */
|
---|
51 |
|
---|
52 | int rc = vbglR3DoIOCtl(IOCTL_VBOXGUEST_HGCM_CONNECT, &Info, sizeof(Info));
|
---|
53 | if (RT_SUCCESS(rc))
|
---|
54 | {
|
---|
55 | rc = Info.result;
|
---|
56 | if (RT_SUCCESS(rc))
|
---|
57 | *pu32ClientId = Info.u32ClientID;
|
---|
58 | }
|
---|
59 | return rc;
|
---|
60 | }
|
---|
61 |
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Disconnect from the information service.
|
---|
65 | *
|
---|
66 | * @returns VBox status code.
|
---|
67 | * @param u32ClientId The client id returned by VbglR3InfoSvcConnect().
|
---|
68 | */
|
---|
69 | VBGLR3DECL(int) VbglR3InfoSvcDisconnect(uint32_t u32ClientId)
|
---|
70 | {
|
---|
71 | VBoxGuestHGCMDisconnectInfo Info;
|
---|
72 | Info.result = (uint32_t)VERR_WRONG_ORDER; /** @todo drop the cast when the result type has been fixed! */
|
---|
73 | Info.u32ClientID = u32ClientId;
|
---|
74 |
|
---|
75 | int rc = vbglR3DoIOCtl(IOCTL_VBOXGUEST_HGCM_DISCONNECT, &Info, sizeof(Info));
|
---|
76 | if (RT_SUCCESS(rc))
|
---|
77 | rc = Info.result;
|
---|
78 | return rc;
|
---|
79 | }
|
---|
80 |
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * Write a registry value.
|
---|
84 | *
|
---|
85 | * @returns VBox status code.
|
---|
86 | * @param u32ClientId The client id returned by VbglR3InvsSvcConnect().
|
---|
87 | * @param pszKey The registry key to save to.
|
---|
88 | * @param pszValue The value to store. If this is NULL then the key
|
---|
89 | * will be removed.
|
---|
90 | */
|
---|
91 | VBGLR3DECL(int) VbglR3InfoSvcWriteKey(uint32_t u32ClientId, char *pszKey, char *pszValue)
|
---|
92 | {
|
---|
93 | int rc;
|
---|
94 |
|
---|
95 | if (pszValue != NULL)
|
---|
96 | {
|
---|
97 | SetConfigKey Msg;
|
---|
98 |
|
---|
99 | Msg.hdr.result = (uint32_t)VERR_WRONG_ORDER; /** @todo drop the cast when the result type has been fixed! */
|
---|
100 | Msg.hdr.u32ClientID = u32ClientId;
|
---|
101 | Msg.hdr.u32Function = SET_CONFIG_KEY;
|
---|
102 | Msg.hdr.cParms = 2;
|
---|
103 | VbglHGCMParmPtrSet(&Msg.key, pszKey, strlen(pszKey) + 1);
|
---|
104 | VbglHGCMParmPtrSet(&Msg.value, pszValue, strlen(pszValue) + 1);
|
---|
105 | rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
|
---|
106 | if (RT_SUCCESS(rc))
|
---|
107 | rc = Msg.hdr.result;
|
---|
108 | }
|
---|
109 | else
|
---|
110 | {
|
---|
111 | DelConfigKey Msg;
|
---|
112 |
|
---|
113 | Msg.hdr.result = (uint32_t)VERR_WRONG_ORDER; /** @todo drop the cast when the result type has been fixed! */
|
---|
114 | Msg.hdr.u32ClientID = u32ClientId;
|
---|
115 | Msg.hdr.u32Function = DEL_CONFIG_KEY;
|
---|
116 | Msg.hdr.cParms = 1;
|
---|
117 | VbglHGCMParmPtrSet(&Msg.key, pszKey, strlen(pszKey) + 1);
|
---|
118 | rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
|
---|
119 | if (RT_SUCCESS(rc))
|
---|
120 | rc = Msg.hdr.result;
|
---|
121 | }
|
---|
122 | return rc;
|
---|
123 | }
|
---|
124 |
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * Retrieve a registry value.
|
---|
128 | *
|
---|
129 | * @returns VBox status code.
|
---|
130 | * @param u32ClientId The client id returned by VbglR3ClipboardConnect().
|
---|
131 | * @param pszKey The registry key to save to.
|
---|
132 | * @param pszValue Where to store the value retrieved.
|
---|
133 | * @param cbValue The size of the buffer pszValue points to.
|
---|
134 | * @param pcbActual Where to store the required buffer size. This should be set on buffer
|
---|
135 | * overflows errors but actually isn't... Optional.
|
---|
136 | */
|
---|
137 | VBGLR3DECL(int) VbglR3InfoSvcReadKey(uint32_t u32ClientId, char *pszKey,
|
---|
138 | char *pszValue, uint32_t cbValue, uint32_t *pcbActual)
|
---|
139 | {
|
---|
140 | GetConfigKey Msg;
|
---|
141 |
|
---|
142 | Msg.hdr.result = (uint32_t)VERR_WRONG_ORDER; /** @todo drop the cast when the result type has been fixed! */
|
---|
143 | Msg.hdr.u32ClientID = u32ClientId;
|
---|
144 | Msg.hdr.u32Function = GET_CONFIG_KEY;
|
---|
145 | Msg.hdr.cParms = 3;
|
---|
146 | VbglHGCMParmPtrSet(&Msg.key, pszKey, strlen(pszKey) + 1);
|
---|
147 | VbglHGCMParmPtrSet(&Msg.value, pszValue, cbValue);
|
---|
148 | VbglHGCMParmUInt32Set(&Msg.size, 0);
|
---|
149 |
|
---|
150 | int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
|
---|
151 | if (RT_SUCCESS(rc))
|
---|
152 | rc = Msg.hdr.result;
|
---|
153 | uint32_t cbActual;
|
---|
154 | if (RT_SUCCESS(rc))
|
---|
155 | rc = VbglHGCMParmUInt32Get(&Msg.size, &cbActual);
|
---|
156 | if (RT_SUCCESS(rc))
|
---|
157 | {
|
---|
158 | if (pcbActual != NULL)
|
---|
159 | *pcbActual = cbActual;
|
---|
160 | if (cbActual > cbValue)
|
---|
161 | rc = VINF_BUFFER_OVERFLOW;
|
---|
162 | else
|
---|
163 | rc = Msg.hdr.result;
|
---|
164 | }
|
---|
165 | return rc;
|
---|
166 | }
|
---|