Merge lp:~mitya57/ubuntu/raring/gnome-keyring/dbus-fixes into lp:ubuntu/raring/gnome-keyring
- Raring (13.04)
- dbus-fixes
- Merge into raring
Proposed by
Dmitry Shachnev
Status: | Merged |
---|---|
Merge reported by: | Sebastien Bacher |
Merged at revision: | not available |
Proposed branch: | lp:~mitya57/ubuntu/raring/gnome-keyring/dbus-fixes |
Merge into: | lp:ubuntu/raring/gnome-keyring |
Diff against target: |
4024 lines (+3877/-24) 13 files modified
.pc/00git_fix_introspection.patch/daemon/dbus/gkd-secret-introspect.c (+285/-0) .pc/00git_fix_searchitems_method.patch/daemon/dbus/gkd-secret-objects.c (+1710/-0) .pc/00git_fix_searchitems_method.patch/daemon/dbus/gkd-secret-objects.h (+112/-0) .pc/00git_fix_searchitems_method.patch/daemon/dbus/gkd-secret-service.c (+1598/-0) .pc/applied-patches (+2/-0) daemon/dbus/gkd-secret-introspect.c (+2/-3) daemon/dbus/gkd-secret-objects.c (+29/-19) daemon/dbus/gkd-secret-objects.h (+2/-1) daemon/dbus/gkd-secret-service.c (+1/-1) debian/changelog (+9/-0) debian/patches/00git_fix_introspection.patch (+26/-0) debian/patches/00git_fix_searchitems_method.patch (+99/-0) debian/patches/series (+2/-0) |
To merge this branch: | bzr merge lp:~mitya57/ubuntu/raring/gnome-keyring/dbus-fixes |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu branches | Pending | ||
Review via email: mp+152580@code.launchpad.net |
Commit message
Description of the change
Added two upstream patches to fix D-Bus related issues.
* debian/
Upstream patch to fix return value of Collection.
* debian/
Upstream patch to fix introspection of some D-Bus methods.
To post a comment you must log in.
Revision history for this message
Dmitry Shachnev (mitya57) wrote : | # |
- 161. By Dmitry Shachnev
-
Rename 05_fix_
introspection. patch to 00git_fix_ introspection. patch
now that it has been applied upstream - 162. By Dmitry Shachnev
-
Update .pc directory so that the branch is buildable
Revision history for this message
Sebastien Bacher (seb128) wrote : | # |
Thanks, uploaded to raring. Upstream asked if you want some fixes backported to the gnome-3-6 serie, it could be good to have those officially in there
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added directory '.pc/00git_fix_introspection.patch' | |||
2 | === added directory '.pc/00git_fix_introspection.patch/daemon' | |||
3 | === added directory '.pc/00git_fix_introspection.patch/daemon/dbus' | |||
4 | === added file '.pc/00git_fix_introspection.patch/daemon/dbus/gkd-secret-introspect.c' | |||
5 | --- .pc/00git_fix_introspection.patch/daemon/dbus/gkd-secret-introspect.c 1970-01-01 00:00:00 +0000 | |||
6 | +++ .pc/00git_fix_introspection.patch/daemon/dbus/gkd-secret-introspect.c 2013-03-14 13:26:21 +0000 | |||
7 | @@ -0,0 +1,285 @@ | |||
8 | 1 | /* | ||
9 | 2 | * gnome-keyring | ||
10 | 3 | * | ||
11 | 4 | * Copyright (C) 2011 Collabora Ltd. | ||
12 | 5 | * | ||
13 | 6 | * This program is free software; you can redistribute it and/or modify | ||
14 | 7 | * it under the terms of the GNU Lesser General Public License as | ||
15 | 8 | * published by the Free Software Foundation; either version 2.1 of | ||
16 | 9 | * the License, or (at your option) any later version. | ||
17 | 10 | * | ||
18 | 11 | * This program is distributed in the hope that it will be useful, but | ||
19 | 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
21 | 14 | * Lesser General Public License for more details. | ||
22 | 15 | * | ||
23 | 16 | * You should have received a copy of the GNU Lesser General Public | ||
24 | 17 | * License along with this program; if not, write to the Free Software | ||
25 | 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | ||
26 | 19 | * 02111-1307, USA. | ||
27 | 20 | * | ||
28 | 21 | * Author: Stef Walter <stefw@collabora.co.uk> | ||
29 | 22 | */ | ||
30 | 23 | |||
31 | 24 | #include "config.h" | ||
32 | 25 | |||
33 | 26 | #include "gkd-secret-introspect.h" | ||
34 | 27 | |||
35 | 28 | const gchar *gkd_secret_introspect_root = | ||
36 | 29 | "<!DOCTYPE node PUBLIC '-//freedesktop//DTD D-BUS Object Introspection 1.0//EN'\n" | ||
37 | 30 | " 'http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd'>\n" | ||
38 | 31 | "<node>\n" | ||
39 | 32 | " <node name='org/freedesktop/secrets'/>\n" | ||
40 | 33 | "</node>\n"; | ||
41 | 34 | |||
42 | 35 | const gchar *gkd_secret_introspect_collection = | ||
43 | 36 | "<!DOCTYPE node PUBLIC '-//freedesktop//DTD D-BUS Object Introspection 1.0//EN'\n" | ||
44 | 37 | " 'http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd'>\n" | ||
45 | 38 | "<node>\n" | ||
46 | 39 | "\n" | ||
47 | 40 | " <interface name='org.freedesktop.DBus.Introspectable'>\n" | ||
48 | 41 | " <method name='Introspect'>\n" | ||
49 | 42 | " <arg name='data' direction='out' type='s'/>\n" | ||
50 | 43 | " </method>\n" | ||
51 | 44 | " </interface>\n" | ||
52 | 45 | "\n" | ||
53 | 46 | " <interface name='org.freedesktop.DBus.Properties'>\n" | ||
54 | 47 | " <method name='Get'>\n" | ||
55 | 48 | " <arg name='interface' direction='in' type='s'/>\n" | ||
56 | 49 | " <arg name='propname' direction='in' type='s'/>\n" | ||
57 | 50 | " <arg name='value' direction='out' type='v'/>\n" | ||
58 | 51 | " </method>\n" | ||
59 | 52 | " <method name='Set'>\n" | ||
60 | 53 | " <arg name='interface' direction='in' type='s'/>\n" | ||
61 | 54 | " <arg name='propname' direction='in' type='s'/>\n" | ||
62 | 55 | " <arg name='value' direction='in' type='v'/>\n" | ||
63 | 56 | " </method>\n" | ||
64 | 57 | " <method name='GetAll'>\n" | ||
65 | 58 | " <arg name='interface' direction='in' type='s'/>\n" | ||
66 | 59 | " <arg name='props' direction='out' type='a{sv}'/>\n" | ||
67 | 60 | " </method>\n" | ||
68 | 61 | " </interface>\n" | ||
69 | 62 | "\n" | ||
70 | 63 | " <interface name='org.freedesktop.Secret.Collection'>\n" | ||
71 | 64 | " <property name='Items' type='ao' access='read'/>\n" | ||
72 | 65 | " <property name='Label' type='s' access='readwrite'/>\n" | ||
73 | 66 | " <property name='Locked' type='s' access='read'/>\n" | ||
74 | 67 | " <property name='Created' type='t' access='read'/>\n" | ||
75 | 68 | " <property name='Modified' type='t' access='read'/>\n" | ||
76 | 69 | " <method name='Delete'>\n" | ||
77 | 70 | " <arg name='prompt' type='o' direction='out'/>\n" | ||
78 | 71 | " </method>\n" | ||
79 | 72 | " <method name='SearchItems'>\n" | ||
80 | 73 | " <arg name='attributes' type='a{ss}' direction='in'/>\n" | ||
81 | 74 | " <arg name='unlocked' type='ao' direction='out'/>\n" | ||
82 | 75 | " <arg name='locked' type='ao' direction='out'/>\n" | ||
83 | 76 | " </method>\n" | ||
84 | 77 | " <method name='CreateItem'>\n" | ||
85 | 78 | " <arg name='props' type='a{sv}' direction='in'/>\n" | ||
86 | 79 | " <arg name='secret' type='(oayays)' direction='in'/>\n" | ||
87 | 80 | " <arg name='replace' type='b' direction='in'/>\n" | ||
88 | 81 | " <arg name='item' type='o' direction='out'/>\n" | ||
89 | 82 | " <arg name='prompt' type='o' direction='out'/>\n" | ||
90 | 83 | " </method>\n" | ||
91 | 84 | " <signal name='ItemCreated'>\n" | ||
92 | 85 | " <arg name='item' type='o'/>\n" | ||
93 | 86 | " </signal>\n" | ||
94 | 87 | " <signal name='ItemDeleted'>\n" | ||
95 | 88 | " <arg name='item' type='o'/>\n" | ||
96 | 89 | " </signal>\n" | ||
97 | 90 | " <signal name='ItemChanged'>\n" | ||
98 | 91 | " <arg name='item' type='o'/>\n" | ||
99 | 92 | " </signal>\n" | ||
100 | 93 | " </interface>\n" | ||
101 | 94 | "\n" | ||
102 | 95 | "<!--@children@-->" | ||
103 | 96 | "</node>\n"; | ||
104 | 97 | |||
105 | 98 | const gchar *gkd_secret_introspect_item = | ||
106 | 99 | "<!DOCTYPE node PUBLIC '-//freedesktop//DTD D-BUS Object Introspection 1.0//EN'\n" | ||
107 | 100 | " 'http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd'>\n" | ||
108 | 101 | "<node>\n" | ||
109 | 102 | "\n" | ||
110 | 103 | " <interface name='org.freedesktop.DBus.Introspectable'>\n" | ||
111 | 104 | " <method name='Introspect'>\n" | ||
112 | 105 | " <arg name='data' direction='out' type='s'/>\n" | ||
113 | 106 | " </method>\n" | ||
114 | 107 | " </interface>\n" | ||
115 | 108 | "\n" | ||
116 | 109 | " <interface name='org.freedesktop.DBus.Properties'>\n" | ||
117 | 110 | " <method name='Get'>\n" | ||
118 | 111 | " <arg name='interface' direction='in' type='s'/>\n" | ||
119 | 112 | " <arg name='propname' direction='in' type='s'/>\n" | ||
120 | 113 | " <arg name='value' direction='out' type='v'/>\n" | ||
121 | 114 | " </method>\n" | ||
122 | 115 | " <method name='Set'>\n" | ||
123 | 116 | " <arg name='interface' direction='in' type='s'/>\n" | ||
124 | 117 | " <arg name='propname' direction='in' type='s'/>\n" | ||
125 | 118 | " <arg name='value' direction='in' type='v'/>\n" | ||
126 | 119 | " </method>\n" | ||
127 | 120 | " <method name='GetAll'>\n" | ||
128 | 121 | " <arg name='interface' direction='in' type='s'/>\n" | ||
129 | 122 | " <arg name='props' direction='out' type='a{sv}'/>\n" | ||
130 | 123 | " </method>\n" | ||
131 | 124 | " </interface>\n" | ||
132 | 125 | "\n" | ||
133 | 126 | " <interface name='org.freedesktop.Secret.Item'>\n" | ||
134 | 127 | " <property name='Locked' type='b' access='read'/>\n" | ||
135 | 128 | " <property name='Attributes' type='a{ss}' access='readwrite'/>\n" | ||
136 | 129 | " <property name='Label' type='s' access='readwrite'/>\n" | ||
137 | 130 | " <property name='Type' type='s' access='readwrite'/>\n" | ||
138 | 131 | " <property name='Created' type='t' access='read'/>\n" | ||
139 | 132 | " <property name='Modified' type='t' access='read'/>\n" | ||
140 | 133 | " <method name='Delete'>\n" | ||
141 | 134 | " <arg name='prompt' type='o' direction='out'/>\n" | ||
142 | 135 | " </method>\n" | ||
143 | 136 | " <method name='GetSecret'>\n" | ||
144 | 137 | " <arg name='session' type='o' direction='in'/>\n" | ||
145 | 138 | " <arg name='secret' type='(oayays)' direction='out'/>\n" | ||
146 | 139 | " </method>\n" | ||
147 | 140 | " <method name='SetSecret'>\n" | ||
148 | 141 | " <arg name='secret' type='(oayays)' direction='in'/>\n" | ||
149 | 142 | " </method>\n" | ||
150 | 143 | " </interface>\n" | ||
151 | 144 | "\n" | ||
152 | 145 | "</node>\n"; | ||
153 | 146 | |||
154 | 147 | const gchar *gkd_secret_introspect_prompt = | ||
155 | 148 | "<!DOCTYPE node PUBLIC '-//freedesktop//DTD D-BUS Object Introspection 1.0//EN'\n" | ||
156 | 149 | " 'http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd'>\n" | ||
157 | 150 | "<node>\n" | ||
158 | 151 | "\n" | ||
159 | 152 | " <interface name='org.freedesktop.DBus.Introspectable'>\n" | ||
160 | 153 | " <method name='Introspect'>\n" | ||
161 | 154 | " <arg name='data' direction='out' type='s'/>\n" | ||
162 | 155 | " </method>\n" | ||
163 | 156 | " </interface>\n" | ||
164 | 157 | "\n" | ||
165 | 158 | " <interface name='org.freedesktop.Secret.Prompt'>\n" | ||
166 | 159 | " <method name='Prompt'>\n" | ||
167 | 160 | " <arg name='window-id' type='s' direction='in'/>\n" | ||
168 | 161 | " </method>\n" | ||
169 | 162 | " <method name='Dismiss'>\n" | ||
170 | 163 | " </method>\n" | ||
171 | 164 | " <signal name='Completed'>\n" | ||
172 | 165 | " <arg name='dismissed' type='b'/>\n" | ||
173 | 166 | " <arg name='result' type='v'/>\n" | ||
174 | 167 | " </signal>\n" | ||
175 | 168 | " </interface>\n" | ||
176 | 169 | "\n" | ||
177 | 170 | "</node>\n"; | ||
178 | 171 | |||
179 | 172 | const gchar *gkd_secret_introspect_service = | ||
180 | 173 | "<!DOCTYPE node PUBLIC '-//freedesktop//DTD D-BUS Object Introspection 1.0//EN'\n" | ||
181 | 174 | " 'http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd'>\n" | ||
182 | 175 | "<node>\n" | ||
183 | 176 | "\n" | ||
184 | 177 | " <interface name='org.freedesktop.DBus.Introspectable'>\n" | ||
185 | 178 | " <method name='Introspect'>\n" | ||
186 | 179 | " <arg name='data' direction='out' type='s'/>\n" | ||
187 | 180 | " </method>\n" | ||
188 | 181 | " </interface>\n" | ||
189 | 182 | "\n" | ||
190 | 183 | " <interface name='org.freedesktop.DBus.Properties'>\n" | ||
191 | 184 | " <method name='Get'>\n" | ||
192 | 185 | " <arg name='interface' direction='in' type='s'/>\n" | ||
193 | 186 | " <arg name='propname' direction='in' type='s'/>\n" | ||
194 | 187 | " <arg name='value' direction='out' type='v'/>\n" | ||
195 | 188 | " </method>\n" | ||
196 | 189 | " <method name='Set'>\n" | ||
197 | 190 | " <arg name='interface' direction='in' type='s'/>\n" | ||
198 | 191 | " <arg name='propname' direction='in' type='s'/>\n" | ||
199 | 192 | " <arg name='value' direction='in' type='v'/>\n" | ||
200 | 193 | " </method>\n" | ||
201 | 194 | " <method name='GetAll'>\n" | ||
202 | 195 | " <arg name='interface' direction='in' type='s'/>\n" | ||
203 | 196 | " <arg name='props' direction='out' type='a{sv}'/>\n" | ||
204 | 197 | " </method>\n" | ||
205 | 198 | " </interface>\n" | ||
206 | 199 | "\n" | ||
207 | 200 | " <interface name='org.freedesktop.Secret.Service'>\n" | ||
208 | 201 | "\n" | ||
209 | 202 | " <property name='Collections' type='ao' access='read'/>\n" | ||
210 | 203 | "\n" | ||
211 | 204 | " <method name='OpenSession'>\n" | ||
212 | 205 | " <arg name='algorithm' type='s' direction='in'/>\n" | ||
213 | 206 | " <arg name='input' type='v' direction='in'/>\n" | ||
214 | 207 | " <arg name='output' type='v' direction='out'/>\n" | ||
215 | 208 | " <arg name='result' type='o' direction='out'/>\n" | ||
216 | 209 | " </method>\n" | ||
217 | 210 | "\n" | ||
218 | 211 | " <method name='CreateCollection'>\n" | ||
219 | 212 | " <arg name='properties' type='a{sv}' direction='in'/>\n" | ||
220 | 213 | " <arg name='alias' type='s' direction='in'/>\n" | ||
221 | 214 | " <arg name='collection' type='o' direction='out'/>\n" | ||
222 | 215 | " <arg name='prompt' type='o' direction='out'/>\n" | ||
223 | 216 | " </method>\n" | ||
224 | 217 | "\n" | ||
225 | 218 | " <method name='SearchItems'>\n" | ||
226 | 219 | " <arg name='attributes' type='a{ss}' direction='in'/>\n" | ||
227 | 220 | " <arg name='unlocked' type='ao' direction='out'/>\n" | ||
228 | 221 | " <arg name='locked' type='ao' direction='out'/>\n" | ||
229 | 222 | " </method>\n" | ||
230 | 223 | "\n" | ||
231 | 224 | " <method name='Unlock'>\n" | ||
232 | 225 | " <arg name='objects' type='ao' direction='in'/>\n" | ||
233 | 226 | " <arg name='unlocked' type='ao' direction='out'/>\n" | ||
234 | 227 | " <arg name='prompt' type='o' direction='out'/>\n" | ||
235 | 228 | " </method>\n" | ||
236 | 229 | "\n" | ||
237 | 230 | " <method name='Lock'>\n" | ||
238 | 231 | " <arg name='objects' type='ao' direction='in'/>\n" | ||
239 | 232 | " <arg name='locked' type='ao' direction='out'/>\n" | ||
240 | 233 | " <arg name='Prompt' type='o' direction='out'/>\n" | ||
241 | 234 | " </method>\n" | ||
242 | 235 | "\n" | ||
243 | 236 | " <method name='GetSecrets'>\n" | ||
244 | 237 | " <arg name='items' type='ao' direction='in'/>\n" | ||
245 | 238 | " <arg name='session' type='o' direction='in'/>\n" | ||
246 | 239 | " <arg name='secrets' type='a{o(oayays)}' direction='out'/>\n" | ||
247 | 240 | " </method>\n" | ||
248 | 241 | "\n" | ||
249 | 242 | " <method name='ReadAlias'>\n" | ||
250 | 243 | " <arg name='name' type='s' direction='in'/>\n" | ||
251 | 244 | " <arg name='collection' type='o' direction='out'/>\n" | ||
252 | 245 | " </method>\n" | ||
253 | 246 | "\n" | ||
254 | 247 | " <method name='SetAlias'>\n" | ||
255 | 248 | " <arg name='name' type='s' direction='in'/>\n" | ||
256 | 249 | " <arg name='collection' type='o' direction='in'/>\n" | ||
257 | 250 | " </method>\n" | ||
258 | 251 | "\n" | ||
259 | 252 | " <signal name='CollectionCreated'>\n" | ||
260 | 253 | " <arg name='collection' type='o'/>\n" | ||
261 | 254 | " </signal>\n" | ||
262 | 255 | "\n" | ||
263 | 256 | " <signal name='CollectionDeleted'>\n" | ||
264 | 257 | " <arg name='collection' type='o'/>\n" | ||
265 | 258 | " </signal>\n" | ||
266 | 259 | "\n" | ||
267 | 260 | " <signal name='CollectionChanged'>\n" | ||
268 | 261 | " <arg name='collection' type='o'/>\n" | ||
269 | 262 | " </signal>\n" | ||
270 | 263 | "\n" | ||
271 | 264 | " </interface>\n" | ||
272 | 265 | "\n" | ||
273 | 266 | "<!--@children@-->" | ||
274 | 267 | "</node>\n"; | ||
275 | 268 | |||
276 | 269 | const gchar *gkd_secret_introspect_session = | ||
277 | 270 | "<!DOCTYPE node PUBLIC '-//freedesktop//DTD D-BUS Object Introspection 1.0//EN'\n" | ||
278 | 271 | " 'http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd'>\n" | ||
279 | 272 | "<node>\n" | ||
280 | 273 | "\n" | ||
281 | 274 | " <interface name='org.freedesktop.DBus.Introspectable'>\n" | ||
282 | 275 | " <method name='Introspect'>\n" | ||
283 | 276 | " <arg name='data' direction='out' type='s'/>\n" | ||
284 | 277 | " </method>\n" | ||
285 | 278 | " </interface>\n" | ||
286 | 279 | "\n" | ||
287 | 280 | " <interface name='org.freedesktop.Secret.Session'>\n" | ||
288 | 281 | " <method name='Close'>\n" | ||
289 | 282 | " </method>\n" | ||
290 | 283 | " </interface>\n" | ||
291 | 284 | "\n" | ||
292 | 285 | "</node>\n"; | ||
293 | 0 | 286 | ||
294 | === added directory '.pc/00git_fix_searchitems_method.patch' | |||
295 | === added directory '.pc/00git_fix_searchitems_method.patch/daemon' | |||
296 | === added directory '.pc/00git_fix_searchitems_method.patch/daemon/dbus' | |||
297 | === added file '.pc/00git_fix_searchitems_method.patch/daemon/dbus/gkd-secret-objects.c' | |||
298 | --- .pc/00git_fix_searchitems_method.patch/daemon/dbus/gkd-secret-objects.c 1970-01-01 00:00:00 +0000 | |||
299 | +++ .pc/00git_fix_searchitems_method.patch/daemon/dbus/gkd-secret-objects.c 2013-03-14 13:26:21 +0000 | |||
300 | @@ -0,0 +1,1710 @@ | |||
301 | 1 | /* | ||
302 | 2 | * gnome-keyring | ||
303 | 3 | * | ||
304 | 4 | * Copyright (C) 2008 Stefan Walter | ||
305 | 5 | * | ||
306 | 6 | * This program is free software; you can redistribute it and/or modify | ||
307 | 7 | * it under the terms of the GNU Lesser General Public License as | ||
308 | 8 | * published by the Free Software Foundation; either version 2.1 of | ||
309 | 9 | * the License, or (at your option) any later version. | ||
310 | 10 | * | ||
311 | 11 | * This program is distributed in the hope that it will be useful, but | ||
312 | 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
313 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
314 | 14 | * Lesser General Public License for more details. | ||
315 | 15 | * | ||
316 | 16 | * You should have received a copy of the GNU Lesser General Public | ||
317 | 17 | * License along with this program; if not, write to the Free Software | ||
318 | 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | ||
319 | 19 | * 02111-1307, USA. | ||
320 | 20 | */ | ||
321 | 21 | |||
322 | 22 | #include "config.h" | ||
323 | 23 | |||
324 | 24 | #include "gkd-dbus-util.h" | ||
325 | 25 | |||
326 | 26 | #include "gkd-secret-error.h" | ||
327 | 27 | #include "gkd-secret-introspect.h" | ||
328 | 28 | #include "gkd-secret-objects.h" | ||
329 | 29 | #include "gkd-secret-property.h" | ||
330 | 30 | #include "gkd-secret-secret.h" | ||
331 | 31 | #include "gkd-secret-service.h" | ||
332 | 32 | #include "gkd-secret-session.h" | ||
333 | 33 | #include "gkd-secret-types.h" | ||
334 | 34 | #include "gkd-secret-util.h" | ||
335 | 35 | |||
336 | 36 | #include "egg/egg-error.h" | ||
337 | 37 | |||
338 | 38 | #include "pkcs11/pkcs11i.h" | ||
339 | 39 | |||
340 | 40 | #include <string.h> | ||
341 | 41 | |||
342 | 42 | enum { | ||
343 | 43 | PROP_0, | ||
344 | 44 | PROP_PKCS11_SLOT, | ||
345 | 45 | PROP_SERVICE | ||
346 | 46 | }; | ||
347 | 47 | |||
348 | 48 | struct _GkdSecretObjects { | ||
349 | 49 | GObject parent; | ||
350 | 50 | GkdSecretService *service; | ||
351 | 51 | GckSlot *pkcs11_slot; | ||
352 | 52 | }; | ||
353 | 53 | |||
354 | 54 | static gchar * object_path_for_item (const gchar *base, | ||
355 | 55 | GckObject *item); | ||
356 | 56 | |||
357 | 57 | static gchar * object_path_for_collection (GckObject *collection); | ||
358 | 58 | |||
359 | 59 | static gchar * collection_path_for_item (GckObject *item); | ||
360 | 60 | |||
361 | 61 | G_DEFINE_TYPE (GkdSecretObjects, gkd_secret_objects, G_TYPE_OBJECT); | ||
362 | 62 | |||
363 | 63 | /* ----------------------------------------------------------------------------- | ||
364 | 64 | * INTERNAL | ||
365 | 65 | */ | ||
366 | 66 | |||
367 | 67 | static gboolean | ||
368 | 68 | parse_object_path (GkdSecretObjects *self, const gchar *path, gchar **collection, gchar **item) | ||
369 | 69 | { | ||
370 | 70 | const gchar *replace; | ||
371 | 71 | |||
372 | 72 | g_assert (self); | ||
373 | 73 | g_assert (path); | ||
374 | 74 | g_assert (collection); | ||
375 | 75 | |||
376 | 76 | if (!gkd_secret_util_parse_path (path, collection, item)) | ||
377 | 77 | return FALSE; | ||
378 | 78 | |||
379 | 79 | if (g_str_has_prefix (path, SECRET_ALIAS_PREFIX)) { | ||
380 | 80 | replace = gkd_secret_service_get_alias (self->service, *collection); | ||
381 | 81 | if (!replace) { | ||
382 | 82 | g_free (*collection); | ||
383 | 83 | *collection = NULL; | ||
384 | 84 | if (item) { | ||
385 | 85 | g_free (*item); | ||
386 | 86 | *item = NULL; | ||
387 | 87 | } | ||
388 | 88 | return FALSE; | ||
389 | 89 | } | ||
390 | 90 | g_free (*collection); | ||
391 | 91 | *collection = g_strdup (replace); | ||
392 | 92 | } | ||
393 | 93 | |||
394 | 94 | return TRUE; | ||
395 | 95 | } | ||
396 | 96 | |||
397 | 97 | static DBusMessage* | ||
398 | 98 | object_property_get (GckObject *object, DBusMessage *message, | ||
399 | 99 | const gchar *prop_name) | ||
400 | 100 | { | ||
401 | 101 | DBusMessageIter iter; | ||
402 | 102 | GError *error = NULL; | ||
403 | 103 | DBusMessage *reply; | ||
404 | 104 | GckAttribute attr; | ||
405 | 105 | gpointer value; | ||
406 | 106 | gsize length; | ||
407 | 107 | |||
408 | 108 | if (!gkd_secret_property_get_type (prop_name, &attr.type)) | ||
409 | 109 | return dbus_message_new_error_printf (message, DBUS_ERROR_FAILED, | ||
410 | 110 | "Object does not have the '%s' property", prop_name); | ||
411 | 111 | |||
412 | 112 | /* Retrieve the actual attribute */ | ||
413 | 113 | attr.value = value = gck_object_get_data (object, attr.type, NULL, &length, &error); | ||
414 | 114 | if (error != NULL) { | ||
415 | 115 | reply = dbus_message_new_error_printf (message, DBUS_ERROR_FAILED, | ||
416 | 116 | "Couldn't retrieve '%s' property: %s", | ||
417 | 117 | prop_name, egg_error_message (error)); | ||
418 | 118 | g_clear_error (&error); | ||
419 | 119 | return reply; | ||
420 | 120 | } | ||
421 | 121 | |||
422 | 122 | /* Marshall the data back out */ | ||
423 | 123 | attr.length = length; | ||
424 | 124 | reply = dbus_message_new_method_return (message); | ||
425 | 125 | dbus_message_iter_init_append (reply, &iter); | ||
426 | 126 | gkd_secret_property_append_variant (&iter, &attr); | ||
427 | 127 | g_free (value); | ||
428 | 128 | return reply; | ||
429 | 129 | } | ||
430 | 130 | |||
431 | 131 | static DBusMessage* | ||
432 | 132 | object_property_set (GckObject *object, | ||
433 | 133 | DBusMessage *message, | ||
434 | 134 | DBusMessageIter *iter, | ||
435 | 135 | const gchar *prop_name) | ||
436 | 136 | { | ||
437 | 137 | GckBuilder builder = GCK_BUILDER_INIT; | ||
438 | 138 | DBusMessage *reply; | ||
439 | 139 | GError *error = NULL; | ||
440 | 140 | gulong attr_type; | ||
441 | 141 | |||
442 | 142 | g_return_val_if_fail (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_VARIANT, NULL); | ||
443 | 143 | |||
444 | 144 | /* What type of property is it? */ | ||
445 | 145 | if (!gkd_secret_property_get_type (prop_name, &attr_type)) | ||
446 | 146 | return dbus_message_new_error_printf (message, DBUS_ERROR_FAILED, | ||
447 | 147 | "Object does not have the '%s' property", prop_name); | ||
448 | 148 | |||
449 | 149 | /* Retrieve the actual attribute value */ | ||
450 | 150 | if (!gkd_secret_property_parse_variant (iter, prop_name, &builder)) { | ||
451 | 151 | gck_builder_clear (&builder); | ||
452 | 152 | return dbus_message_new_error_printf (message, DBUS_ERROR_FAILED, | ||
453 | 153 | "The property type or value was invalid: %s", prop_name); | ||
454 | 154 | } | ||
455 | 155 | |||
456 | 156 | gck_object_set (object, gck_builder_end (&builder), NULL, &error); | ||
457 | 157 | |||
458 | 158 | if (error != NULL) { | ||
459 | 159 | if (g_error_matches (error, GCK_ERROR, CKR_USER_NOT_LOGGED_IN)) | ||
460 | 160 | reply = dbus_message_new_error (message, SECRET_ERROR_IS_LOCKED, | ||
461 | 161 | "Cannot set property on a locked object"); | ||
462 | 162 | else | ||
463 | 163 | reply = dbus_message_new_error_printf (message, DBUS_ERROR_FAILED, | ||
464 | 164 | "Couldn't set '%s' property: %s", | ||
465 | 165 | prop_name, egg_error_message (error)); | ||
466 | 166 | g_clear_error (&error); | ||
467 | 167 | return reply; | ||
468 | 168 | } | ||
469 | 169 | |||
470 | 170 | return dbus_message_new_method_return (message); | ||
471 | 171 | } | ||
472 | 172 | |||
473 | 173 | static DBusMessage* | ||
474 | 174 | item_property_get (GckObject *object, DBusMessage *message) | ||
475 | 175 | { | ||
476 | 176 | const gchar *interface; | ||
477 | 177 | const gchar *name; | ||
478 | 178 | |||
479 | 179 | if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &interface, | ||
480 | 180 | DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)) | ||
481 | 181 | return NULL; | ||
482 | 182 | |||
483 | 183 | if (!gkd_dbus_interface_match (SECRET_ITEM_INTERFACE, interface)) | ||
484 | 184 | return dbus_message_new_error_printf (message, DBUS_ERROR_FAILED, | ||
485 | 185 | "Object does not have properties on interface '%s'", | ||
486 | 186 | interface); | ||
487 | 187 | |||
488 | 188 | return object_property_get (object, message, name); | ||
489 | 189 | } | ||
490 | 190 | |||
491 | 191 | static DBusMessage* | ||
492 | 192 | item_property_set (GkdSecretObjects *self, | ||
493 | 193 | GckObject *object, | ||
494 | 194 | DBusMessage *message) | ||
495 | 195 | { | ||
496 | 196 | DBusMessageIter iter; | ||
497 | 197 | const char *interface; | ||
498 | 198 | const char *name; | ||
499 | 199 | DBusMessage *reply; | ||
500 | 200 | |||
501 | 201 | if (!dbus_message_has_signature (message, "ssv")) | ||
502 | 202 | return NULL; | ||
503 | 203 | |||
504 | 204 | dbus_message_iter_init (message, &iter); | ||
505 | 205 | dbus_message_iter_get_basic (&iter, &interface); | ||
506 | 206 | dbus_message_iter_next (&iter); | ||
507 | 207 | dbus_message_iter_get_basic (&iter, &name); | ||
508 | 208 | dbus_message_iter_next (&iter); | ||
509 | 209 | |||
510 | 210 | if (!gkd_dbus_interface_match (SECRET_ITEM_INTERFACE, interface)) | ||
511 | 211 | return dbus_message_new_error_printf (message, DBUS_ERROR_FAILED, | ||
512 | 212 | "Object does not have properties on interface '%s'", | ||
513 | 213 | interface); | ||
514 | 214 | |||
515 | 215 | reply = object_property_set (object, message, &iter, name); | ||
516 | 216 | |||
517 | 217 | /* Notify everyone a property changed */ | ||
518 | 218 | if (reply && dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN) | ||
519 | 219 | gkd_secret_objects_emit_item_changed (self, object, name, NULL); | ||
520 | 220 | |||
521 | 221 | return reply; | ||
522 | 222 | } | ||
523 | 223 | |||
524 | 224 | static DBusMessage* | ||
525 | 225 | item_property_getall (GckObject *object, DBusMessage *message) | ||
526 | 226 | { | ||
527 | 227 | GckAttributes *attrs; | ||
528 | 228 | DBusMessageIter iter; | ||
529 | 229 | DBusMessageIter array; | ||
530 | 230 | GError *error = NULL; | ||
531 | 231 | DBusMessage *reply; | ||
532 | 232 | const gchar *interface; | ||
533 | 233 | |||
534 | 234 | if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &interface, DBUS_TYPE_INVALID)) | ||
535 | 235 | return NULL; | ||
536 | 236 | |||
537 | 237 | if (!gkd_dbus_interface_match (SECRET_ITEM_INTERFACE, interface)) | ||
538 | 238 | return dbus_message_new_error_printf (message, DBUS_ERROR_FAILED, | ||
539 | 239 | "Object does not have properties on interface '%s'", | ||
540 | 240 | interface); | ||
541 | 241 | |||
542 | 242 | attrs = gck_object_get (object, NULL, &error, | ||
543 | 243 | CKA_LABEL, | ||
544 | 244 | CKA_G_SCHEMA, | ||
545 | 245 | CKA_G_LOCKED, | ||
546 | 246 | CKA_G_CREATED, | ||
547 | 247 | CKA_G_MODIFIED, | ||
548 | 248 | CKA_G_FIELDS, | ||
549 | 249 | GCK_INVALID); | ||
550 | 250 | |||
551 | 251 | if (error != NULL) | ||
552 | 252 | return dbus_message_new_error_printf (message, DBUS_ERROR_FAILED, | ||
553 | 253 | "Couldn't retrieve properties: %s", | ||
554 | 254 | egg_error_message (error)); | ||
555 | 255 | |||
556 | 256 | reply = dbus_message_new_method_return (message); | ||
557 | 257 | |||
558 | 258 | dbus_message_iter_init_append (reply, &iter); | ||
559 | 259 | dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "{sv}", &array); | ||
560 | 260 | gkd_secret_property_append_all (&array, attrs); | ||
561 | 261 | dbus_message_iter_close_container (&iter, &array); | ||
562 | 262 | return reply; | ||
563 | 263 | } | ||
564 | 264 | |||
565 | 265 | static DBusMessage* | ||
566 | 266 | item_method_delete (GkdSecretObjects *self, GckObject *object, DBusMessage *message) | ||
567 | 267 | { | ||
568 | 268 | GError *error = NULL; | ||
569 | 269 | gchar *collection_path; | ||
570 | 270 | gchar *item_path; | ||
571 | 271 | DBusMessage *reply; | ||
572 | 272 | const gchar *prompt; | ||
573 | 273 | GckObject *collection; | ||
574 | 274 | |||
575 | 275 | if (!dbus_message_get_args (message, NULL, DBUS_TYPE_INVALID)) | ||
576 | 276 | return NULL; | ||
577 | 277 | |||
578 | 278 | collection_path = collection_path_for_item (object); | ||
579 | 279 | item_path = object_path_for_item (NULL, object); | ||
580 | 280 | |||
581 | 281 | if (gck_object_destroy (object, NULL, &error)) { | ||
582 | 282 | collection = gkd_secret_objects_lookup_collection (self, NULL, collection_path); | ||
583 | 283 | if (collection != NULL) { | ||
584 | 284 | gkd_secret_objects_emit_item_deleted (self, collection, item_path); | ||
585 | 285 | g_object_unref (collection); | ||
586 | 286 | } | ||
587 | 287 | |||
588 | 288 | prompt = "/"; /* No prompt necessary */ | ||
589 | 289 | reply = dbus_message_new_method_return (message); | ||
590 | 290 | dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &prompt, DBUS_TYPE_INVALID); | ||
591 | 291 | |||
592 | 292 | } else { | ||
593 | 293 | if (g_error_matches (error, GCK_ERROR, CKR_USER_NOT_LOGGED_IN)) | ||
594 | 294 | reply = dbus_message_new_error_printf (message, SECRET_ERROR_IS_LOCKED, | ||
595 | 295 | "Cannot delete a locked item"); | ||
596 | 296 | else | ||
597 | 297 | reply = dbus_message_new_error_printf (message, DBUS_ERROR_FAILED, | ||
598 | 298 | "Couldn't delete collection: %s", | ||
599 | 299 | egg_error_message (error)); | ||
600 | 300 | |||
601 | 301 | g_clear_error (&error); | ||
602 | 302 | } | ||
603 | 303 | |||
604 | 304 | g_free (collection_path); | ||
605 | 305 | g_free (item_path); | ||
606 | 306 | return reply; | ||
607 | 307 | } | ||
608 | 308 | |||
609 | 309 | static DBusMessage* | ||
610 | 310 | item_method_get_secret (GkdSecretObjects *self, GckObject *item, DBusMessage *message) | ||
611 | 311 | { | ||
612 | 312 | DBusError derr = DBUS_ERROR_INIT; | ||
613 | 313 | GkdSecretSession *session; | ||
614 | 314 | GkdSecretSecret *secret; | ||
615 | 315 | DBusMessage *reply; | ||
616 | 316 | DBusMessageIter iter; | ||
617 | 317 | const char *path; | ||
618 | 318 | |||
619 | 319 | if (!dbus_message_get_args (message, NULL, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID)) | ||
620 | 320 | return NULL; | ||
621 | 321 | |||
622 | 322 | session = gkd_secret_service_lookup_session (self->service, path, dbus_message_get_sender (message)); | ||
623 | 323 | if (session == NULL) | ||
624 | 324 | return dbus_message_new_error (message, SECRET_ERROR_NO_SESSION, "The session does not exist"); | ||
625 | 325 | |||
626 | 326 | secret = gkd_secret_session_get_item_secret (session, item, &derr); | ||
627 | 327 | if (secret == NULL) | ||
628 | 328 | return gkd_secret_error_to_reply (message, &derr); | ||
629 | 329 | |||
630 | 330 | reply = dbus_message_new_method_return (message); | ||
631 | 331 | dbus_message_iter_init_append (reply, &iter); | ||
632 | 332 | gkd_secret_secret_append (secret, &iter); | ||
633 | 333 | gkd_secret_secret_free (secret); | ||
634 | 334 | return reply; | ||
635 | 335 | } | ||
636 | 336 | |||
637 | 337 | static DBusMessage* | ||
638 | 338 | item_method_set_secret (GkdSecretObjects *self, GckObject *item, DBusMessage *message) | ||
639 | 339 | { | ||
640 | 340 | DBusError derr = DBUS_ERROR_INIT; | ||
641 | 341 | DBusMessageIter iter; | ||
642 | 342 | GkdSecretSecret *secret; | ||
643 | 343 | const char *caller; | ||
644 | 344 | |||
645 | 345 | if (!dbus_message_has_signature (message, "(oayays)")) | ||
646 | 346 | return NULL; | ||
647 | 347 | dbus_message_iter_init (message, &iter); | ||
648 | 348 | secret = gkd_secret_secret_parse (self->service, message, &iter, &derr); | ||
649 | 349 | if (secret == NULL) | ||
650 | 350 | return gkd_secret_error_to_reply (message, &derr); | ||
651 | 351 | |||
652 | 352 | caller = dbus_message_get_sender (message); | ||
653 | 353 | g_return_val_if_fail (caller, NULL); | ||
654 | 354 | |||
655 | 355 | gkd_secret_session_set_item_secret (secret->session, item, secret, &derr); | ||
656 | 356 | gkd_secret_secret_free (secret); | ||
657 | 357 | |||
658 | 358 | if (dbus_error_is_set (&derr)) | ||
659 | 359 | return gkd_secret_error_to_reply (message, &derr); | ||
660 | 360 | |||
661 | 361 | return dbus_message_new_method_return (message); | ||
662 | 362 | } | ||
663 | 363 | |||
664 | 364 | static DBusMessage* | ||
665 | 365 | item_message_handler (GkdSecretObjects *self, GckObject *object, DBusMessage *message) | ||
666 | 366 | { | ||
667 | 367 | /* org.freedesktop.Secret.Item.Delete() */ | ||
668 | 368 | if (dbus_message_is_method_call (message, SECRET_ITEM_INTERFACE, "Delete")) | ||
669 | 369 | return item_method_delete (self, object, message); | ||
670 | 370 | |||
671 | 371 | /* org.freedesktop.Secret.Session.GetSecret() */ | ||
672 | 372 | else if (dbus_message_is_method_call (message, SECRET_ITEM_INTERFACE, "GetSecret")) | ||
673 | 373 | return item_method_get_secret (self, object, message); | ||
674 | 374 | |||
675 | 375 | /* org.freedesktop.Secret.Session.SetSecret() */ | ||
676 | 376 | else if (dbus_message_is_method_call (message, SECRET_ITEM_INTERFACE, "SetSecret")) | ||
677 | 377 | return item_method_set_secret (self, object, message); | ||
678 | 378 | |||
679 | 379 | /* org.freedesktop.DBus.Properties.Get */ | ||
680 | 380 | if (dbus_message_is_method_call (message, DBUS_INTERFACE_PROPERTIES, "Get")) | ||
681 | 381 | return item_property_get (object, message); | ||
682 | 382 | |||
683 | 383 | /* org.freedesktop.DBus.Properties.Set */ | ||
684 | 384 | else if (dbus_message_is_method_call (message, DBUS_INTERFACE_PROPERTIES, "Set")) | ||
685 | 385 | return item_property_set (self, object, message); | ||
686 | 386 | |||
687 | 387 | /* org.freedesktop.DBus.Properties.GetAll */ | ||
688 | 388 | else if (dbus_message_is_method_call (message, DBUS_INTERFACE_PROPERTIES, "GetAll")) | ||
689 | 389 | return item_property_getall (object, message); | ||
690 | 390 | |||
691 | 391 | else if (dbus_message_has_interface (message, DBUS_INTERFACE_INTROSPECTABLE)) | ||
692 | 392 | return gkd_dbus_introspect_handle (message, gkd_secret_introspect_item, NULL); | ||
693 | 393 | |||
694 | 394 | return NULL; | ||
695 | 395 | } | ||
696 | 396 | |||
697 | 397 | static void | ||
698 | 398 | item_cleanup_search_results (GckSession *session, GList *items, | ||
699 | 399 | GList **locked, GList **unlocked) | ||
700 | 400 | { | ||
701 | 401 | GError *error = NULL; | ||
702 | 402 | gpointer value; | ||
703 | 403 | gsize n_value; | ||
704 | 404 | GList *l; | ||
705 | 405 | |||
706 | 406 | *locked = NULL; | ||
707 | 407 | *unlocked = NULL; | ||
708 | 408 | |||
709 | 409 | for (l = items; l; l = g_list_next (l)) { | ||
710 | 410 | value = gck_object_get_data (l->data, CKA_G_LOCKED, NULL, &n_value, &error); | ||
711 | 411 | if (value == NULL) { | ||
712 | 412 | if (!g_error_matches (error, GCK_ERROR, CKR_OBJECT_HANDLE_INVALID)) | ||
713 | 413 | g_warning ("couldn't check if item is locked: %s", egg_error_message (error)); | ||
714 | 414 | g_clear_error (&error); | ||
715 | 415 | |||
716 | 416 | /* Is not locked */ | ||
717 | 417 | } if (n_value == 1 && *((CK_BBOOL*)value) == CK_FALSE) { | ||
718 | 418 | *unlocked = g_list_prepend (*unlocked, l->data); | ||
719 | 419 | |||
720 | 420 | /* Is locked */ | ||
721 | 421 | } else { | ||
722 | 422 | *locked = g_list_prepend (*locked, l->data); | ||
723 | 423 | } | ||
724 | 424 | |||
725 | 425 | g_free (value); | ||
726 | 426 | } | ||
727 | 427 | |||
728 | 428 | *locked = g_list_reverse (*locked); | ||
729 | 429 | *unlocked = g_list_reverse (*unlocked); | ||
730 | 430 | } | ||
731 | 431 | |||
732 | 432 | static DBusMessage* | ||
733 | 433 | collection_property_get (GkdSecretObjects *self, GckObject *object, DBusMessage *message) | ||
734 | 434 | { | ||
735 | 435 | DBusMessageIter iter; | ||
736 | 436 | DBusMessage *reply; | ||
737 | 437 | const gchar *interface; | ||
738 | 438 | const gchar *name; | ||
739 | 439 | |||
740 | 440 | if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &interface, | ||
741 | 441 | DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)) | ||
742 | 442 | return NULL; | ||
743 | 443 | |||
744 | 444 | if (!gkd_dbus_interface_match (SECRET_COLLECTION_INTERFACE, interface)) | ||
745 | 445 | return dbus_message_new_error_printf (message, DBUS_ERROR_FAILED, | ||
746 | 446 | "Object does not have properties on interface '%s'", | ||
747 | 447 | interface); | ||
748 | 448 | |||
749 | 449 | /* Special case, the Items property */ | ||
750 | 450 | if (g_str_equal (name, "Items")) { | ||
751 | 451 | reply = dbus_message_new_method_return (message); | ||
752 | 452 | dbus_message_iter_init_append (reply, &iter); | ||
753 | 453 | gkd_secret_objects_append_item_paths (self, dbus_message_get_path (message), &iter, message); | ||
754 | 454 | return reply; | ||
755 | 455 | } | ||
756 | 456 | |||
757 | 457 | return object_property_get (object, message, name); | ||
758 | 458 | } | ||
759 | 459 | |||
760 | 460 | static DBusMessage* | ||
761 | 461 | collection_property_set (GkdSecretObjects *self, GckObject *object, DBusMessage *message) | ||
762 | 462 | { | ||
763 | 463 | DBusMessageIter iter; | ||
764 | 464 | DBusMessage *reply; | ||
765 | 465 | const char *interface; | ||
766 | 466 | const char *name; | ||
767 | 467 | |||
768 | 468 | if (!dbus_message_has_signature (message, "ssv")) | ||
769 | 469 | return NULL; | ||
770 | 470 | |||
771 | 471 | dbus_message_iter_init (message, &iter); | ||
772 | 472 | dbus_message_iter_get_basic (&iter, &interface); | ||
773 | 473 | dbus_message_iter_next (&iter); | ||
774 | 474 | dbus_message_iter_get_basic (&iter, &name); | ||
775 | 475 | dbus_message_iter_next (&iter); | ||
776 | 476 | |||
777 | 477 | if (!gkd_dbus_interface_match (SECRET_COLLECTION_INTERFACE, interface)) | ||
778 | 478 | return dbus_message_new_error_printf (message, DBUS_ERROR_FAILED, | ||
779 | 479 | "Object does not have properties on interface '%s'", | ||
780 | 480 | interface); | ||
781 | 481 | |||
782 | 482 | reply = object_property_set (object, message, &iter, name); | ||
783 | 483 | |||
784 | 484 | /* Notify everyone a property changed */ | ||
785 | 485 | if (reply && dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN) | ||
786 | 486 | gkd_secret_objects_emit_collection_changed (self, object, name, NULL); | ||
787 | 487 | |||
788 | 488 | return reply; | ||
789 | 489 | } | ||
790 | 490 | |||
791 | 491 | static DBusMessage* | ||
792 | 492 | collection_property_getall (GkdSecretObjects *self, GckObject *object, DBusMessage *message) | ||
793 | 493 | { | ||
794 | 494 | GckAttributes *attrs; | ||
795 | 495 | DBusMessageIter iter; | ||
796 | 496 | DBusMessageIter array; | ||
797 | 497 | DBusMessageIter dict; | ||
798 | 498 | GError *error = NULL; | ||
799 | 499 | DBusMessage *reply; | ||
800 | 500 | const gchar *name; | ||
801 | 501 | const gchar *interface; | ||
802 | 502 | |||
803 | 503 | if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &interface, DBUS_TYPE_INVALID)) | ||
804 | 504 | return NULL; | ||
805 | 505 | |||
806 | 506 | if (!gkd_dbus_interface_match (SECRET_COLLECTION_INTERFACE, interface)) | ||
807 | 507 | return dbus_message_new_error_printf (message, DBUS_ERROR_FAILED, | ||
808 | 508 | "Object does not have properties on interface '%s'", | ||
809 | 509 | interface); | ||
810 | 510 | |||
811 | 511 | attrs = gck_object_get (object, NULL, &error, | ||
812 | 512 | CKA_LABEL, | ||
813 | 513 | CKA_G_LOCKED, | ||
814 | 514 | CKA_G_CREATED, | ||
815 | 515 | CKA_G_MODIFIED, | ||
816 | 516 | GCK_INVALID); | ||
817 | 517 | |||
818 | 518 | if (error != NULL) | ||
819 | 519 | return dbus_message_new_error_printf (message, DBUS_ERROR_FAILED, | ||
820 | 520 | "Couldn't retrieve properties: %s", | ||
821 | 521 | egg_error_message (error)); | ||
822 | 522 | |||
823 | 523 | reply = dbus_message_new_method_return (message); | ||
824 | 524 | |||
825 | 525 | dbus_message_iter_init_append (reply, &iter); | ||
826 | 526 | dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "{sv}", &array); | ||
827 | 527 | |||
828 | 528 | /* Append all the usual properties */ | ||
829 | 529 | gkd_secret_property_append_all (&array, attrs); | ||
830 | 530 | |||
831 | 531 | /* Append the Items property */ | ||
832 | 532 | dbus_message_iter_open_container (&array, DBUS_TYPE_DICT_ENTRY, NULL, &dict); | ||
833 | 533 | name = "Items"; | ||
834 | 534 | dbus_message_iter_append_basic (&dict, DBUS_TYPE_STRING, &name); | ||
835 | 535 | gkd_secret_objects_append_item_paths (self, dbus_message_get_path (message), &dict, message); | ||
836 | 536 | dbus_message_iter_close_container (&array, &dict); | ||
837 | 537 | |||
838 | 538 | dbus_message_iter_close_container (&iter, &array); | ||
839 | 539 | return reply; | ||
840 | 540 | } | ||
841 | 541 | |||
842 | 542 | static DBusMessage* | ||
843 | 543 | collection_method_search_items (GkdSecretObjects *self, GckObject *object, DBusMessage *message) | ||
844 | 544 | { | ||
845 | 545 | return gkd_secret_objects_handle_search_items (self, message, dbus_message_get_path (message)); | ||
846 | 546 | } | ||
847 | 547 | |||
848 | 548 | static GckObject* | ||
849 | 549 | collection_find_matching_item (GkdSecretObjects *self, | ||
850 | 550 | GckSession *session, | ||
851 | 551 | const gchar *identifier, | ||
852 | 552 | const GckAttribute *fields) | ||
853 | 553 | { | ||
854 | 554 | GckBuilder builder = GCK_BUILDER_INIT; | ||
855 | 555 | GckObject *result = NULL; | ||
856 | 556 | GError *error = NULL; | ||
857 | 557 | GckObject *search; | ||
858 | 558 | gpointer data; | ||
859 | 559 | gsize n_data; | ||
860 | 560 | |||
861 | 561 | /* Find items matching the collection and fields */ | ||
862 | 562 | gck_builder_add_attribute (&builder, fields); | ||
863 | 563 | gck_builder_add_string (&builder, CKA_G_COLLECTION, identifier); | ||
864 | 564 | gck_builder_add_ulong (&builder, CKA_CLASS, CKO_G_SEARCH); | ||
865 | 565 | gck_builder_add_boolean (&builder, CKA_TOKEN, FALSE); | ||
866 | 566 | |||
867 | 567 | /* Create the search object */ | ||
868 | 568 | search = gck_session_create_object (session, gck_builder_end (&builder), NULL, &error); | ||
869 | 569 | |||
870 | 570 | if (error != NULL) { | ||
871 | 571 | g_warning ("couldn't search for matching item: %s", egg_error_message (error)); | ||
872 | 572 | g_clear_error (&error); | ||
873 | 573 | return NULL; | ||
874 | 574 | } | ||
875 | 575 | |||
876 | 576 | /* Get the matched item handles, and delete the search object */ | ||
877 | 577 | data = gck_object_get_data (search, CKA_G_MATCHED, NULL, &n_data, NULL); | ||
878 | 578 | gck_object_destroy (search, NULL, NULL); | ||
879 | 579 | g_object_unref (search); | ||
880 | 580 | |||
881 | 581 | if (n_data >= sizeof (CK_OBJECT_HANDLE)) | ||
882 | 582 | result = gck_object_from_handle (session, *((CK_OBJECT_HANDLE_PTR)data)); | ||
883 | 583 | |||
884 | 584 | g_free (data); | ||
885 | 585 | return result; | ||
886 | 586 | } | ||
887 | 587 | |||
888 | 588 | static gchar * | ||
889 | 589 | object_path_for_item (const gchar *base, | ||
890 | 590 | GckObject *item) | ||
891 | 591 | { | ||
892 | 592 | GError *error = NULL; | ||
893 | 593 | gpointer identifier; | ||
894 | 594 | gsize n_identifier; | ||
895 | 595 | gchar *alloc = NULL; | ||
896 | 596 | gchar *path = NULL; | ||
897 | 597 | |||
898 | 598 | if (base == NULL) | ||
899 | 599 | base = alloc = collection_path_for_item (item); | ||
900 | 600 | |||
901 | 601 | identifier = gck_object_get_data (item, CKA_ID, NULL, &n_identifier, &error); | ||
902 | 602 | if (identifier == NULL) { | ||
903 | 603 | g_warning ("couldn't get item identifier: %s", egg_error_message (error)); | ||
904 | 604 | g_clear_error (&error); | ||
905 | 605 | path = NULL; | ||
906 | 606 | |||
907 | 607 | } else { | ||
908 | 608 | path = gkd_secret_util_build_path (base, identifier, n_identifier); | ||
909 | 609 | g_free (identifier); | ||
910 | 610 | } | ||
911 | 611 | |||
912 | 612 | g_free (alloc); | ||
913 | 613 | return path; | ||
914 | 614 | } | ||
915 | 615 | |||
916 | 616 | static gchar * | ||
917 | 617 | collection_path_for_item (GckObject *item) | ||
918 | 618 | { | ||
919 | 619 | GError *error = NULL; | ||
920 | 620 | gpointer identifier; | ||
921 | 621 | gsize n_identifier; | ||
922 | 622 | gchar *path = NULL; | ||
923 | 623 | |||
924 | 624 | identifier = gck_object_get_data (item, CKA_G_COLLECTION, NULL, &n_identifier, &error); | ||
925 | 625 | if (!identifier) { | ||
926 | 626 | g_warning ("couldn't get item collection identifier: %s", egg_error_message (error)); | ||
927 | 627 | g_clear_error (&error); | ||
928 | 628 | return NULL; | ||
929 | 629 | } | ||
930 | 630 | |||
931 | 631 | path = gkd_secret_util_build_path (SECRET_COLLECTION_PREFIX, identifier, n_identifier); | ||
932 | 632 | g_free (identifier); | ||
933 | 633 | return path; | ||
934 | 634 | } | ||
935 | 635 | |||
936 | 636 | static gchar * | ||
937 | 637 | object_path_for_collection (GckObject *collection) | ||
938 | 638 | { | ||
939 | 639 | GError *error = NULL; | ||
940 | 640 | gpointer identifier; | ||
941 | 641 | gsize n_identifier; | ||
942 | 642 | gchar *path = NULL; | ||
943 | 643 | |||
944 | 644 | identifier = gck_object_get_data (collection, CKA_ID, NULL, &n_identifier, &error); | ||
945 | 645 | if (identifier == NULL) { | ||
946 | 646 | g_warning ("couldn't get collection identifier: %s", egg_error_message (error)); | ||
947 | 647 | g_clear_error (&error); | ||
948 | 648 | path = NULL; | ||
949 | 649 | |||
950 | 650 | } else { | ||
951 | 651 | path = gkd_secret_util_build_path (SECRET_COLLECTION_PREFIX, identifier, n_identifier); | ||
952 | 652 | g_free (identifier); | ||
953 | 653 | } | ||
954 | 654 | |||
955 | 655 | return path; | ||
956 | 656 | } | ||
957 | 657 | |||
958 | 658 | static DBusMessage* | ||
959 | 659 | collection_method_create_item (GkdSecretObjects *self, GckObject *object, DBusMessage *message) | ||
960 | 660 | { | ||
961 | 661 | GckBuilder builder = GCK_BUILDER_INIT; | ||
962 | 662 | GckSession *pkcs11_session = NULL; | ||
963 | 663 | DBusError derr = DBUS_ERROR_INIT; | ||
964 | 664 | GkdSecretSecret *secret = NULL; | ||
965 | 665 | dbus_bool_t replace = FALSE; | ||
966 | 666 | GckAttributes *attrs = NULL; | ||
967 | 667 | const GckAttribute *fields; | ||
968 | 668 | DBusMessageIter iter, array; | ||
969 | 669 | GckObject *item = NULL; | ||
970 | 670 | const gchar *prompt; | ||
971 | 671 | const gchar *base; | ||
972 | 672 | GError *error = NULL; | ||
973 | 673 | DBusMessage *reply = NULL; | ||
974 | 674 | gchar *path = NULL; | ||
975 | 675 | gchar *identifier; | ||
976 | 676 | gboolean created = FALSE; | ||
977 | 677 | |||
978 | 678 | /* Parse the message */ | ||
979 | 679 | if (!dbus_message_has_signature (message, "a{sv}(oayays)b")) | ||
980 | 680 | return NULL; | ||
981 | 681 | if (!dbus_message_iter_init (message, &iter)) | ||
982 | 682 | g_return_val_if_reached (NULL); | ||
983 | 683 | dbus_message_iter_recurse (&iter, &array); | ||
984 | 684 | if (!gkd_secret_property_parse_all (&array, SECRET_ITEM_INTERFACE, &builder)) { | ||
985 | 685 | reply = dbus_message_new_error (message, DBUS_ERROR_INVALID_ARGS, | ||
986 | 686 | "Invalid properties argument"); | ||
987 | 687 | goto cleanup; | ||
988 | 688 | } | ||
989 | 689 | dbus_message_iter_next (&iter); | ||
990 | 690 | secret = gkd_secret_secret_parse (self->service, message, &iter, &derr); | ||
991 | 691 | if (secret == NULL) { | ||
992 | 692 | reply = gkd_secret_error_to_reply (message, &derr); | ||
993 | 693 | goto cleanup; | ||
994 | 694 | } | ||
995 | 695 | dbus_message_iter_next (&iter); | ||
996 | 696 | dbus_message_iter_get_basic (&iter, &replace); | ||
997 | 697 | |||
998 | 698 | base = dbus_message_get_path (message); | ||
999 | 699 | if (!parse_object_path (self, base, &identifier, NULL)) | ||
1000 | 700 | g_return_val_if_reached (NULL); | ||
1001 | 701 | g_return_val_if_fail (identifier, NULL); | ||
1002 | 702 | |||
1003 | 703 | pkcs11_session = gck_object_get_session (object); | ||
1004 | 704 | g_return_val_if_fail (pkcs11_session, NULL); | ||
1005 | 705 | |||
1006 | 706 | attrs = gck_attributes_ref_sink (gck_builder_end (&builder)); | ||
1007 | 707 | |||
1008 | 708 | if (replace) { | ||
1009 | 709 | fields = gck_attributes_find (attrs, CKA_G_FIELDS); | ||
1010 | 710 | if (fields) | ||
1011 | 711 | item = collection_find_matching_item (self, pkcs11_session, identifier, fields); | ||
1012 | 712 | } | ||
1013 | 713 | |||
1014 | 714 | /* Replace the item */ | ||
1015 | 715 | if (item) { | ||
1016 | 716 | if (!gck_object_set (item, attrs, NULL, &error)) | ||
1017 | 717 | goto cleanup; | ||
1018 | 718 | |||
1019 | 719 | /* Create a new item */ | ||
1020 | 720 | } else { | ||
1021 | 721 | gck_builder_add_all (&builder, attrs); | ||
1022 | 722 | gck_builder_add_string (&builder, CKA_G_COLLECTION, identifier); | ||
1023 | 723 | gck_builder_add_ulong (&builder, CKA_CLASS, CKO_SECRET_KEY); | ||
1024 | 724 | item = gck_session_create_object (pkcs11_session, gck_builder_end (&builder), NULL, &error); | ||
1025 | 725 | if (item == NULL) | ||
1026 | 726 | goto cleanup; | ||
1027 | 727 | created = TRUE; | ||
1028 | 728 | } | ||
1029 | 729 | |||
1030 | 730 | /* Set the secret */ | ||
1031 | 731 | if (!gkd_secret_session_set_item_secret (secret->session, item, secret, &derr)) { | ||
1032 | 732 | if (created) /* If we created, then try to destroy on failure */ | ||
1033 | 733 | gck_object_destroy (item, NULL, NULL); | ||
1034 | 734 | goto cleanup; | ||
1035 | 735 | } | ||
1036 | 736 | |||
1037 | 737 | path = object_path_for_item (base, item); | ||
1038 | 738 | gkd_secret_objects_emit_item_created (self, object, item); | ||
1039 | 739 | |||
1040 | 740 | /* Build up the item identifier */ | ||
1041 | 741 | reply = dbus_message_new_method_return (message); | ||
1042 | 742 | dbus_message_iter_init_append (reply, &iter); | ||
1043 | 743 | dbus_message_iter_append_basic (&iter, DBUS_TYPE_OBJECT_PATH, &path); | ||
1044 | 744 | prompt = "/"; | ||
1045 | 745 | dbus_message_iter_append_basic (&iter, DBUS_TYPE_OBJECT_PATH, &prompt); | ||
1046 | 746 | |||
1047 | 747 | cleanup: | ||
1048 | 748 | if (error) { | ||
1049 | 749 | if (!reply) { | ||
1050 | 750 | if (g_error_matches (error, GCK_ERROR, CKR_USER_NOT_LOGGED_IN)) | ||
1051 | 751 | reply = dbus_message_new_error_printf (message, SECRET_ERROR_IS_LOCKED, | ||
1052 | 752 | "Cannot create an item in a locked collection"); | ||
1053 | 753 | else | ||
1054 | 754 | reply = dbus_message_new_error_printf (message, DBUS_ERROR_FAILED, | ||
1055 | 755 | "Couldn't create item: %s", egg_error_message (error)); | ||
1056 | 756 | } | ||
1057 | 757 | g_clear_error (&error); | ||
1058 | 758 | } | ||
1059 | 759 | |||
1060 | 760 | if (dbus_error_is_set (&derr)) { | ||
1061 | 761 | if (!reply) | ||
1062 | 762 | reply = dbus_message_new_error (message, derr.name, derr.message); | ||
1063 | 763 | dbus_error_free (&derr); | ||
1064 | 764 | } | ||
1065 | 765 | |||
1066 | 766 | gkd_secret_secret_free (secret); | ||
1067 | 767 | gck_attributes_unref (attrs); | ||
1068 | 768 | if (item) | ||
1069 | 769 | g_object_unref (item); | ||
1070 | 770 | if (pkcs11_session) | ||
1071 | 771 | g_object_unref (pkcs11_session); | ||
1072 | 772 | g_free (path); | ||
1073 | 773 | |||
1074 | 774 | return reply; | ||
1075 | 775 | } | ||
1076 | 776 | |||
1077 | 777 | static DBusMessage* | ||
1078 | 778 | collection_method_delete (GkdSecretObjects *self, GckObject *object, DBusMessage *message) | ||
1079 | 779 | { | ||
1080 | 780 | GError *error = NULL; | ||
1081 | 781 | DBusMessage *reply; | ||
1082 | 782 | const gchar *prompt; | ||
1083 | 783 | gchar *path; | ||
1084 | 784 | |||
1085 | 785 | if (!dbus_message_get_args (message, NULL, DBUS_TYPE_INVALID)) | ||
1086 | 786 | return NULL; | ||
1087 | 787 | |||
1088 | 788 | path = object_path_for_collection (object); | ||
1089 | 789 | g_return_val_if_fail (path != NULL, NULL); | ||
1090 | 790 | |||
1091 | 791 | if (!gck_object_destroy (object, NULL, &error)) { | ||
1092 | 792 | reply = dbus_message_new_error_printf (message, DBUS_ERROR_FAILED, | ||
1093 | 793 | "Couldn't delete collection: %s", | ||
1094 | 794 | egg_error_message (error)); | ||
1095 | 795 | g_clear_error (&error); | ||
1096 | 796 | g_free (path); | ||
1097 | 797 | return reply; | ||
1098 | 798 | } | ||
1099 | 799 | |||
1100 | 800 | /* Notify the callers that a collection was deleted */ | ||
1101 | 801 | gkd_secret_service_emit_collection_deleted (self->service, path); | ||
1102 | 802 | g_free (path); | ||
1103 | 803 | |||
1104 | 804 | prompt = "/"; | ||
1105 | 805 | reply = dbus_message_new_method_return (message); | ||
1106 | 806 | dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &prompt, DBUS_TYPE_INVALID); | ||
1107 | 807 | return reply; | ||
1108 | 808 | } | ||
1109 | 809 | |||
1110 | 810 | static void | ||
1111 | 811 | on_each_path_append_to_array (GkdSecretObjects *self, | ||
1112 | 812 | const gchar *path, | ||
1113 | 813 | GckObject *object, | ||
1114 | 814 | gpointer user_data) | ||
1115 | 815 | { | ||
1116 | 816 | GPtrArray *array = user_data; | ||
1117 | 817 | g_ptr_array_add (array, g_strdup (path)); | ||
1118 | 818 | } | ||
1119 | 819 | |||
1120 | 820 | static DBusMessage * | ||
1121 | 821 | collection_introspect (GkdSecretObjects *self, | ||
1122 | 822 | GckObject *object, | ||
1123 | 823 | DBusMessage *message) | ||
1124 | 824 | { | ||
1125 | 825 | GPtrArray *names; | ||
1126 | 826 | DBusMessage *reply; | ||
1127 | 827 | |||
1128 | 828 | names = g_ptr_array_new_with_free_func (g_free); | ||
1129 | 829 | gkd_secret_objects_foreach_item (self, message, dbus_message_get_path (message), | ||
1130 | 830 | on_each_path_append_to_array, names); | ||
1131 | 831 | g_ptr_array_add (names, NULL); | ||
1132 | 832 | |||
1133 | 833 | reply = gkd_dbus_introspect_handle (message, gkd_secret_introspect_collection, | ||
1134 | 834 | (const gchar **)names->pdata); | ||
1135 | 835 | |||
1136 | 836 | g_ptr_array_unref (names); | ||
1137 | 837 | return reply; | ||
1138 | 838 | } | ||
1139 | 839 | |||
1140 | 840 | static DBusMessage* | ||
1141 | 841 | collection_message_handler (GkdSecretObjects *self, GckObject *object, DBusMessage *message) | ||
1142 | 842 | { | ||
1143 | 843 | /* org.freedesktop.Secret.Collection.Delete() */ | ||
1144 | 844 | if (dbus_message_is_method_call (message, SECRET_COLLECTION_INTERFACE, "Delete")) | ||
1145 | 845 | return collection_method_delete (self, object, message); | ||
1146 | 846 | |||
1147 | 847 | /* org.freedesktop.Secret.Collection.SearchItems() */ | ||
1148 | 848 | if (dbus_message_is_method_call (message, SECRET_COLLECTION_INTERFACE, "SearchItems")) | ||
1149 | 849 | return collection_method_search_items (self, object, message); | ||
1150 | 850 | |||
1151 | 851 | /* org.freedesktop.Secret.Collection.CreateItem() */ | ||
1152 | 852 | if (dbus_message_is_method_call (message, SECRET_COLLECTION_INTERFACE, "CreateItem")) | ||
1153 | 853 | return collection_method_create_item (self, object, message); | ||
1154 | 854 | |||
1155 | 855 | /* org.freedesktop.DBus.Properties.Get() */ | ||
1156 | 856 | if (dbus_message_is_method_call (message, DBUS_INTERFACE_PROPERTIES, "Get")) | ||
1157 | 857 | return collection_property_get (self, object, message); | ||
1158 | 858 | |||
1159 | 859 | /* org.freedesktop.DBus.Properties.Set() */ | ||
1160 | 860 | else if (dbus_message_is_method_call (message, DBUS_INTERFACE_PROPERTIES, "Set")) | ||
1161 | 861 | return collection_property_set (self, object, message); | ||
1162 | 862 | |||
1163 | 863 | /* org.freedesktop.DBus.Properties.GetAll() */ | ||
1164 | 864 | else if (dbus_message_is_method_call (message, DBUS_INTERFACE_PROPERTIES, "GetAll")) | ||
1165 | 865 | return collection_property_getall (self, object, message); | ||
1166 | 866 | |||
1167 | 867 | /* org.freedesktop.DBus.Introspectable.Introspect() */ | ||
1168 | 868 | else if (dbus_message_has_interface (message, DBUS_INTERFACE_INTROSPECTABLE)) | ||
1169 | 869 | return collection_introspect (self, object, message); | ||
1170 | 870 | |||
1171 | 871 | return NULL; | ||
1172 | 872 | } | ||
1173 | 873 | |||
1174 | 874 | /* ----------------------------------------------------------------------------- | ||
1175 | 875 | * OBJECT | ||
1176 | 876 | */ | ||
1177 | 877 | |||
1178 | 878 | static GObject* | ||
1179 | 879 | gkd_secret_objects_constructor (GType type, guint n_props, GObjectConstructParam *props) | ||
1180 | 880 | { | ||
1181 | 881 | GkdSecretObjects *self = GKD_SECRET_OBJECTS (G_OBJECT_CLASS (gkd_secret_objects_parent_class)->constructor(type, n_props, props)); | ||
1182 | 882 | |||
1183 | 883 | g_return_val_if_fail (self, NULL); | ||
1184 | 884 | g_return_val_if_fail (self->pkcs11_slot, NULL); | ||
1185 | 885 | g_return_val_if_fail (self->service, NULL); | ||
1186 | 886 | |||
1187 | 887 | return G_OBJECT (self); | ||
1188 | 888 | } | ||
1189 | 889 | |||
1190 | 890 | static void | ||
1191 | 891 | gkd_secret_objects_init (GkdSecretObjects *self) | ||
1192 | 892 | { | ||
1193 | 893 | |||
1194 | 894 | } | ||
1195 | 895 | |||
1196 | 896 | static void | ||
1197 | 897 | gkd_secret_objects_dispose (GObject *obj) | ||
1198 | 898 | { | ||
1199 | 899 | GkdSecretObjects *self = GKD_SECRET_OBJECTS (obj); | ||
1200 | 900 | |||
1201 | 901 | if (self->pkcs11_slot) { | ||
1202 | 902 | g_object_unref (self->pkcs11_slot); | ||
1203 | 903 | self->pkcs11_slot = NULL; | ||
1204 | 904 | } | ||
1205 | 905 | |||
1206 | 906 | if (self->service) { | ||
1207 | 907 | g_object_remove_weak_pointer (G_OBJECT (self->service), | ||
1208 | 908 | (gpointer*)&(self->service)); | ||
1209 | 909 | self->service = NULL; | ||
1210 | 910 | } | ||
1211 | 911 | |||
1212 | 912 | G_OBJECT_CLASS (gkd_secret_objects_parent_class)->dispose (obj); | ||
1213 | 913 | } | ||
1214 | 914 | |||
1215 | 915 | static void | ||
1216 | 916 | gkd_secret_objects_finalize (GObject *obj) | ||
1217 | 917 | { | ||
1218 | 918 | GkdSecretObjects *self = GKD_SECRET_OBJECTS (obj); | ||
1219 | 919 | |||
1220 | 920 | g_assert (!self->pkcs11_slot); | ||
1221 | 921 | g_assert (!self->service); | ||
1222 | 922 | |||
1223 | 923 | G_OBJECT_CLASS (gkd_secret_objects_parent_class)->finalize (obj); | ||
1224 | 924 | } | ||
1225 | 925 | |||
1226 | 926 | static void | ||
1227 | 927 | gkd_secret_objects_set_property (GObject *obj, guint prop_id, const GValue *value, | ||
1228 | 928 | GParamSpec *pspec) | ||
1229 | 929 | { | ||
1230 | 930 | GkdSecretObjects *self = GKD_SECRET_OBJECTS (obj); | ||
1231 | 931 | |||
1232 | 932 | switch (prop_id) { | ||
1233 | 933 | case PROP_PKCS11_SLOT: | ||
1234 | 934 | g_return_if_fail (!self->pkcs11_slot); | ||
1235 | 935 | self->pkcs11_slot = g_value_dup_object (value); | ||
1236 | 936 | g_return_if_fail (self->pkcs11_slot); | ||
1237 | 937 | break; | ||
1238 | 938 | case PROP_SERVICE: | ||
1239 | 939 | g_return_if_fail (!self->service); | ||
1240 | 940 | self->service = g_value_get_object (value); | ||
1241 | 941 | g_return_if_fail (self->service); | ||
1242 | 942 | g_object_add_weak_pointer (G_OBJECT (self->service), | ||
1243 | 943 | (gpointer*)&(self->service)); | ||
1244 | 944 | break; | ||
1245 | 945 | default: | ||
1246 | 946 | G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec); | ||
1247 | 947 | break; | ||
1248 | 948 | } | ||
1249 | 949 | } | ||
1250 | 950 | |||
1251 | 951 | static void | ||
1252 | 952 | gkd_secret_objects_get_property (GObject *obj, guint prop_id, GValue *value, | ||
1253 | 953 | GParamSpec *pspec) | ||
1254 | 954 | { | ||
1255 | 955 | GkdSecretObjects *self = GKD_SECRET_OBJECTS (obj); | ||
1256 | 956 | |||
1257 | 957 | switch (prop_id) { | ||
1258 | 958 | case PROP_PKCS11_SLOT: | ||
1259 | 959 | g_value_set_object (value, gkd_secret_objects_get_pkcs11_slot (self)); | ||
1260 | 960 | break; | ||
1261 | 961 | case PROP_SERVICE: | ||
1262 | 962 | g_value_set_object (value, self->service); | ||
1263 | 963 | break; | ||
1264 | 964 | default: | ||
1265 | 965 | G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec); | ||
1266 | 966 | break; | ||
1267 | 967 | } | ||
1268 | 968 | } | ||
1269 | 969 | |||
1270 | 970 | static void | ||
1271 | 971 | gkd_secret_objects_class_init (GkdSecretObjectsClass *klass) | ||
1272 | 972 | { | ||
1273 | 973 | GObjectClass *gobject_class = G_OBJECT_CLASS (klass); | ||
1274 | 974 | |||
1275 | 975 | gobject_class->constructor = gkd_secret_objects_constructor; | ||
1276 | 976 | gobject_class->dispose = gkd_secret_objects_dispose; | ||
1277 | 977 | gobject_class->finalize = gkd_secret_objects_finalize; | ||
1278 | 978 | gobject_class->set_property = gkd_secret_objects_set_property; | ||
1279 | 979 | gobject_class->get_property = gkd_secret_objects_get_property; | ||
1280 | 980 | |||
1281 | 981 | g_object_class_install_property (gobject_class, PROP_PKCS11_SLOT, | ||
1282 | 982 | g_param_spec_object ("pkcs11-slot", "Pkcs11 Slot", "PKCS#11 slot that we use for secrets", | ||
1283 | 983 | GCK_TYPE_SLOT, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); | ||
1284 | 984 | |||
1285 | 985 | g_object_class_install_property (gobject_class, PROP_SERVICE, | ||
1286 | 986 | g_param_spec_object ("service", "Service", "Service which owns this objects", | ||
1287 | 987 | GKD_SECRET_TYPE_SERVICE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); | ||
1288 | 988 | } | ||
1289 | 989 | |||
1290 | 990 | /* ----------------------------------------------------------------------------- | ||
1291 | 991 | * PUBLIC | ||
1292 | 992 | */ | ||
1293 | 993 | |||
1294 | 994 | GckSlot* | ||
1295 | 995 | gkd_secret_objects_get_pkcs11_slot (GkdSecretObjects *self) | ||
1296 | 996 | { | ||
1297 | 997 | g_return_val_if_fail (GKD_SECRET_IS_OBJECTS (self), NULL); | ||
1298 | 998 | return self->pkcs11_slot; | ||
1299 | 999 | } | ||
1300 | 1000 | |||
1301 | 1001 | DBusMessage* | ||
1302 | 1002 | gkd_secret_objects_dispatch (GkdSecretObjects *self, DBusMessage *message) | ||
1303 | 1003 | { | ||
1304 | 1004 | GckBuilder builder = GCK_BUILDER_INIT; | ||
1305 | 1005 | DBusMessage *reply = NULL; | ||
1306 | 1006 | GError *error = NULL; | ||
1307 | 1007 | GList *objects; | ||
1308 | 1008 | GckSession *session; | ||
1309 | 1009 | gchar *c_ident; | ||
1310 | 1010 | gchar *i_ident; | ||
1311 | 1011 | gboolean is_item; | ||
1312 | 1012 | const char *path; | ||
1313 | 1013 | |||
1314 | 1014 | g_return_val_if_fail (GKD_SECRET_IS_OBJECTS (self), NULL); | ||
1315 | 1015 | g_return_val_if_fail (message, NULL); | ||
1316 | 1016 | |||
1317 | 1017 | path = dbus_message_get_path (message); | ||
1318 | 1018 | g_return_val_if_fail (path, NULL); | ||
1319 | 1019 | |||
1320 | 1020 | if (!parse_object_path (self, path, &c_ident, &i_ident) || !c_ident) | ||
1321 | 1021 | return gkd_secret_error_no_such_object (message); | ||
1322 | 1022 | |||
1323 | 1023 | /* The session we're using to access the object */ | ||
1324 | 1024 | session = gkd_secret_service_get_pkcs11_session (self->service, dbus_message_get_sender (message)); | ||
1325 | 1025 | g_return_val_if_fail (session, NULL); | ||
1326 | 1026 | |||
1327 | 1027 | if (i_ident) { | ||
1328 | 1028 | is_item = TRUE; | ||
1329 | 1029 | gck_builder_add_ulong (&builder, CKA_CLASS, CKO_SECRET_KEY); | ||
1330 | 1030 | gck_builder_add_string (&builder, CKA_G_COLLECTION, c_ident); | ||
1331 | 1031 | gck_builder_add_string (&builder, CKA_ID, i_ident); | ||
1332 | 1032 | } else { | ||
1333 | 1033 | is_item = FALSE; | ||
1334 | 1034 | gck_builder_add_ulong (&builder, CKA_CLASS, CKO_G_COLLECTION); | ||
1335 | 1035 | gck_builder_add_string (&builder, CKA_ID, c_ident); | ||
1336 | 1036 | } | ||
1337 | 1037 | |||
1338 | 1038 | objects = gck_session_find_objects (session, gck_builder_end (&builder), NULL, &error); | ||
1339 | 1039 | |||
1340 | 1040 | g_free (c_ident); | ||
1341 | 1041 | g_free (i_ident); | ||
1342 | 1042 | |||
1343 | 1043 | if (error != NULL) { | ||
1344 | 1044 | g_warning ("couldn't lookup object: %s: %s", path, egg_error_message (error)); | ||
1345 | 1045 | g_clear_error (&error); | ||
1346 | 1046 | } | ||
1347 | 1047 | |||
1348 | 1048 | if (!objects) | ||
1349 | 1049 | return gkd_secret_error_no_such_object (message); | ||
1350 | 1050 | |||
1351 | 1051 | if (is_item) | ||
1352 | 1052 | reply = item_message_handler (self, objects->data, message); | ||
1353 | 1053 | else | ||
1354 | 1054 | reply = collection_message_handler (self, objects->data, message); | ||
1355 | 1055 | |||
1356 | 1056 | gck_list_unref_free (objects); | ||
1357 | 1057 | return reply; | ||
1358 | 1058 | } | ||
1359 | 1059 | |||
1360 | 1060 | GckObject* | ||
1361 | 1061 | gkd_secret_objects_lookup_collection (GkdSecretObjects *self, const gchar *caller, | ||
1362 | 1062 | const gchar *path) | ||
1363 | 1063 | { | ||
1364 | 1064 | GckBuilder builder = GCK_BUILDER_INIT; | ||
1365 | 1065 | GckObject *object = NULL; | ||
1366 | 1066 | GError *error = NULL; | ||
1367 | 1067 | GList *objects; | ||
1368 | 1068 | GckSession *session; | ||
1369 | 1069 | gchar *identifier; | ||
1370 | 1070 | |||
1371 | 1071 | g_return_val_if_fail (GKD_SECRET_IS_OBJECTS (self), NULL); | ||
1372 | 1072 | g_return_val_if_fail (path, NULL); | ||
1373 | 1073 | |||
1374 | 1074 | if (!parse_object_path (self, path, &identifier, NULL)) | ||
1375 | 1075 | return NULL; | ||
1376 | 1076 | |||
1377 | 1077 | /* The session we're using to access the object */ | ||
1378 | 1078 | if (caller == NULL) | ||
1379 | 1079 | session = gkd_secret_service_internal_pkcs11_session (self->service); | ||
1380 | 1080 | else | ||
1381 | 1081 | session = gkd_secret_service_get_pkcs11_session (self->service, caller); | ||
1382 | 1082 | g_return_val_if_fail (session, NULL); | ||
1383 | 1083 | |||
1384 | 1084 | gck_builder_add_ulong (&builder, CKA_CLASS, CKO_G_COLLECTION); | ||
1385 | 1085 | gck_builder_add_string (&builder, CKA_ID, identifier); | ||
1386 | 1086 | |||
1387 | 1087 | objects = gck_session_find_objects (session, gck_builder_end (&builder), NULL, &error); | ||
1388 | 1088 | |||
1389 | 1089 | g_free (identifier); | ||
1390 | 1090 | |||
1391 | 1091 | if (error != NULL) { | ||
1392 | 1092 | g_warning ("couldn't lookup collection: %s: %s", path, egg_error_message (error)); | ||
1393 | 1093 | g_clear_error (&error); | ||
1394 | 1094 | } | ||
1395 | 1095 | |||
1396 | 1096 | if (objects) | ||
1397 | 1097 | object = g_object_ref (objects->data); | ||
1398 | 1098 | |||
1399 | 1099 | gck_list_unref_free (objects); | ||
1400 | 1100 | return object; | ||
1401 | 1101 | } | ||
1402 | 1102 | |||
1403 | 1103 | GckObject* | ||
1404 | 1104 | gkd_secret_objects_lookup_item (GkdSecretObjects *self, const gchar *caller, | ||
1405 | 1105 | const gchar *path) | ||
1406 | 1106 | { | ||
1407 | 1107 | GckBuilder builder = GCK_BUILDER_INIT; | ||
1408 | 1108 | GckObject *object = NULL; | ||
1409 | 1109 | GError *error = NULL; | ||
1410 | 1110 | GList *objects; | ||
1411 | 1111 | GckSession *session; | ||
1412 | 1112 | gchar *collection; | ||
1413 | 1113 | gchar *identifier; | ||
1414 | 1114 | |||
1415 | 1115 | g_return_val_if_fail (GKD_SECRET_IS_OBJECTS (self), NULL); | ||
1416 | 1116 | g_return_val_if_fail (caller, NULL); | ||
1417 | 1117 | g_return_val_if_fail (path, NULL); | ||
1418 | 1118 | |||
1419 | 1119 | if (!parse_object_path (self, path, &collection, &identifier)) | ||
1420 | 1120 | return NULL; | ||
1421 | 1121 | |||
1422 | 1122 | /* The session we're using to access the object */ | ||
1423 | 1123 | session = gkd_secret_service_get_pkcs11_session (self->service, caller); | ||
1424 | 1124 | g_return_val_if_fail (session, NULL); | ||
1425 | 1125 | |||
1426 | 1126 | gck_builder_add_ulong (&builder, CKA_CLASS, CKO_SECRET_KEY); | ||
1427 | 1127 | gck_builder_add_string (&builder, CKA_ID, identifier); | ||
1428 | 1128 | gck_builder_add_string (&builder, CKA_G_COLLECTION, collection); | ||
1429 | 1129 | |||
1430 | 1130 | objects = gck_session_find_objects (session, gck_builder_end (&builder), NULL, &error); | ||
1431 | 1131 | |||
1432 | 1132 | g_free (identifier); | ||
1433 | 1133 | g_free (collection); | ||
1434 | 1134 | |||
1435 | 1135 | if (error != NULL) { | ||
1436 | 1136 | g_warning ("couldn't lookup item: %s: %s", path, egg_error_message (error)); | ||
1437 | 1137 | g_clear_error (&error); | ||
1438 | 1138 | } | ||
1439 | 1139 | |||
1440 | 1140 | if (objects) | ||
1441 | 1141 | object = g_object_ref (objects->data); | ||
1442 | 1142 | |||
1443 | 1143 | gck_list_unref_free (objects); | ||
1444 | 1144 | return object; | ||
1445 | 1145 | } | ||
1446 | 1146 | |||
1447 | 1147 | static void | ||
1448 | 1148 | objects_foreach_item (GkdSecretObjects *self, | ||
1449 | 1149 | GList *items, | ||
1450 | 1150 | const gchar *base, | ||
1451 | 1151 | GkdSecretObjectsForeach callback, | ||
1452 | 1152 | gpointer user_data) | ||
1453 | 1153 | { | ||
1454 | 1154 | gchar *path; | ||
1455 | 1155 | GList *l; | ||
1456 | 1156 | |||
1457 | 1157 | for (l = items; l; l = g_list_next (l)) { | ||
1458 | 1158 | path = object_path_for_item (base, l->data); | ||
1459 | 1159 | (callback) (self, path, l->data, user_data); | ||
1460 | 1160 | g_free (path); | ||
1461 | 1161 | } | ||
1462 | 1162 | } | ||
1463 | 1163 | |||
1464 | 1164 | void | ||
1465 | 1165 | gkd_secret_objects_foreach_item (GkdSecretObjects *self, | ||
1466 | 1166 | DBusMessage *message, | ||
1467 | 1167 | const gchar *base, | ||
1468 | 1168 | GkdSecretObjectsForeach callback, | ||
1469 | 1169 | gpointer user_data) | ||
1470 | 1170 | { | ||
1471 | 1171 | GckBuilder builder = GCK_BUILDER_INIT; | ||
1472 | 1172 | GckSession *session; | ||
1473 | 1173 | GError *error = NULL; | ||
1474 | 1174 | gchar *identifier; | ||
1475 | 1175 | GList *items; | ||
1476 | 1176 | |||
1477 | 1177 | g_return_if_fail (GKD_SECRET_IS_OBJECTS (self)); | ||
1478 | 1178 | g_return_if_fail (base != NULL); | ||
1479 | 1179 | g_return_if_fail (callback != NULL); | ||
1480 | 1180 | |||
1481 | 1181 | /* The session we're using to access the object */ | ||
1482 | 1182 | if (message == NULL) { | ||
1483 | 1183 | session = gkd_secret_service_internal_pkcs11_session (self->service); | ||
1484 | 1184 | } else { | ||
1485 | 1185 | session = gkd_secret_service_get_pkcs11_session (self->service, | ||
1486 | 1186 | dbus_message_get_sender (message)); | ||
1487 | 1187 | } | ||
1488 | 1188 | |||
1489 | 1189 | if (!parse_object_path (self, base, &identifier, NULL)) | ||
1490 | 1190 | g_return_if_reached (); | ||
1491 | 1191 | |||
1492 | 1192 | gck_builder_add_ulong (&builder, CKA_CLASS, CKO_SECRET_KEY); | ||
1493 | 1193 | gck_builder_add_string (&builder, CKA_G_COLLECTION, identifier); | ||
1494 | 1194 | |||
1495 | 1195 | items = gck_session_find_objects (session, gck_builder_end (&builder), NULL, &error); | ||
1496 | 1196 | |||
1497 | 1197 | if (error == NULL) { | ||
1498 | 1198 | objects_foreach_item (self, items, base, callback, user_data); | ||
1499 | 1199 | |||
1500 | 1200 | } else { | ||
1501 | 1201 | g_warning ("couldn't lookup items in '%s' collection: %s", identifier, egg_error_message (error)); | ||
1502 | 1202 | g_clear_error (&error); | ||
1503 | 1203 | } | ||
1504 | 1204 | |||
1505 | 1205 | gck_list_unref_free (items); | ||
1506 | 1206 | g_free (identifier); | ||
1507 | 1207 | } | ||
1508 | 1208 | |||
1509 | 1209 | static void | ||
1510 | 1210 | on_object_path_append_to_iter (GkdSecretObjects *self, | ||
1511 | 1211 | const gchar *path, | ||
1512 | 1212 | GckObject *object, | ||
1513 | 1213 | gpointer user_data) | ||
1514 | 1214 | { | ||
1515 | 1215 | DBusMessageIter *array = user_data; | ||
1516 | 1216 | dbus_message_iter_append_basic (array, DBUS_TYPE_OBJECT_PATH, &path); | ||
1517 | 1217 | } | ||
1518 | 1218 | |||
1519 | 1219 | void | ||
1520 | 1220 | gkd_secret_objects_append_item_paths (GkdSecretObjects *self, | ||
1521 | 1221 | const gchar *base, | ||
1522 | 1222 | DBusMessageIter *iter, | ||
1523 | 1223 | DBusMessage *message) | ||
1524 | 1224 | { | ||
1525 | 1225 | DBusMessageIter variant; | ||
1526 | 1226 | DBusMessageIter array; | ||
1527 | 1227 | |||
1528 | 1228 | g_return_if_fail (GKD_SECRET_IS_OBJECTS (self)); | ||
1529 | 1229 | g_return_if_fail (base); | ||
1530 | 1230 | g_return_if_fail (iter); | ||
1531 | 1231 | |||
1532 | 1232 | |||
1533 | 1233 | dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "ao", &variant); | ||
1534 | 1234 | dbus_message_iter_open_container (&variant, DBUS_TYPE_ARRAY, "o", &array); | ||
1535 | 1235 | |||
1536 | 1236 | gkd_secret_objects_foreach_item (self, message, base, on_object_path_append_to_iter, &array); | ||
1537 | 1237 | |||
1538 | 1238 | dbus_message_iter_close_container (&variant, &array); | ||
1539 | 1239 | dbus_message_iter_close_container (iter, &variant); | ||
1540 | 1240 | } | ||
1541 | 1241 | |||
1542 | 1242 | void | ||
1543 | 1243 | gkd_secret_objects_foreach_collection (GkdSecretObjects *self, | ||
1544 | 1244 | DBusMessage *message, | ||
1545 | 1245 | GkdSecretObjectsForeach callback, | ||
1546 | 1246 | gpointer user_data) | ||
1547 | 1247 | { | ||
1548 | 1248 | GckBuilder builder = GCK_BUILDER_INIT; | ||
1549 | 1249 | GckSession *session; | ||
1550 | 1250 | GError *error = NULL; | ||
1551 | 1251 | GList *collections, *l; | ||
1552 | 1252 | gpointer identifier; | ||
1553 | 1253 | gsize n_identifier; | ||
1554 | 1254 | gchar *path; | ||
1555 | 1255 | |||
1556 | 1256 | g_return_if_fail (GKD_SECRET_IS_OBJECTS (self)); | ||
1557 | 1257 | g_return_if_fail (callback); | ||
1558 | 1258 | |||
1559 | 1259 | /* The session we're using to access the object */ | ||
1560 | 1260 | if (message == NULL) { | ||
1561 | 1261 | session = gkd_secret_service_internal_pkcs11_session (self->service); | ||
1562 | 1262 | } else { | ||
1563 | 1263 | session = gkd_secret_service_get_pkcs11_session (self->service, | ||
1564 | 1264 | dbus_message_get_sender (message)); | ||
1565 | 1265 | } | ||
1566 | 1266 | |||
1567 | 1267 | gck_builder_add_ulong (&builder, CKA_CLASS, CKO_G_COLLECTION); | ||
1568 | 1268 | |||
1569 | 1269 | collections = gck_session_find_objects (session, gck_builder_end (&builder), NULL, &error); | ||
1570 | 1270 | |||
1571 | 1271 | if (error != NULL) { | ||
1572 | 1272 | g_warning ("couldn't lookup collections: %s", egg_error_message (error)); | ||
1573 | 1273 | g_clear_error (&error); | ||
1574 | 1274 | return; | ||
1575 | 1275 | } | ||
1576 | 1276 | |||
1577 | 1277 | for (l = collections; l; l = g_list_next (l)) { | ||
1578 | 1278 | |||
1579 | 1279 | identifier = gck_object_get_data (l->data, CKA_ID, NULL, &n_identifier, &error); | ||
1580 | 1280 | if (identifier == NULL) { | ||
1581 | 1281 | g_warning ("couldn't get collection identifier: %s", egg_error_message (error)); | ||
1582 | 1282 | g_clear_error (&error); | ||
1583 | 1283 | continue; | ||
1584 | 1284 | } | ||
1585 | 1285 | |||
1586 | 1286 | path = gkd_secret_util_build_path (SECRET_COLLECTION_PREFIX, identifier, n_identifier); | ||
1587 | 1287 | g_free (identifier); | ||
1588 | 1288 | |||
1589 | 1289 | (callback) (self, path, l->data, user_data); | ||
1590 | 1290 | g_free (path); | ||
1591 | 1291 | } | ||
1592 | 1292 | |||
1593 | 1293 | gck_list_unref_free (collections); | ||
1594 | 1294 | } | ||
1595 | 1295 | |||
1596 | 1296 | void | ||
1597 | 1297 | gkd_secret_objects_append_collection_paths (GkdSecretObjects *self, | ||
1598 | 1298 | DBusMessageIter *iter, | ||
1599 | 1299 | DBusMessage *message) | ||
1600 | 1300 | { | ||
1601 | 1301 | DBusMessageIter variant; | ||
1602 | 1302 | DBusMessageIter array; | ||
1603 | 1303 | |||
1604 | 1304 | g_return_if_fail (GKD_SECRET_IS_OBJECTS (self)); | ||
1605 | 1305 | g_return_if_fail (iter != NULL); | ||
1606 | 1306 | |||
1607 | 1307 | dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "ao", &variant); | ||
1608 | 1308 | dbus_message_iter_open_container (&variant, DBUS_TYPE_ARRAY, "o", &array); | ||
1609 | 1309 | |||
1610 | 1310 | gkd_secret_objects_foreach_collection (self, message, on_object_path_append_to_iter, &array); | ||
1611 | 1311 | |||
1612 | 1312 | dbus_message_iter_close_container (&variant, &array); | ||
1613 | 1313 | dbus_message_iter_close_container (iter, &variant); | ||
1614 | 1314 | } | ||
1615 | 1315 | |||
1616 | 1316 | DBusMessage* | ||
1617 | 1317 | gkd_secret_objects_handle_search_items (GkdSecretObjects *self, DBusMessage *message, | ||
1618 | 1318 | const gchar *base) | ||
1619 | 1319 | { | ||
1620 | 1320 | GckBuilder builder = GCK_BUILDER_INIT; | ||
1621 | 1321 | DBusMessageIter iter; | ||
1622 | 1322 | DBusMessageIter array; | ||
1623 | 1323 | GckObject *search; | ||
1624 | 1324 | GckSession *session; | ||
1625 | 1325 | DBusMessage *reply; | ||
1626 | 1326 | GError *error = NULL; | ||
1627 | 1327 | gchar *identifier; | ||
1628 | 1328 | gpointer data; | ||
1629 | 1329 | gsize n_data; | ||
1630 | 1330 | GList *locked, *unlocked; | ||
1631 | 1331 | GList *items; | ||
1632 | 1332 | |||
1633 | 1333 | g_return_val_if_fail (GKD_SECRET_IS_OBJECTS (self), NULL); | ||
1634 | 1334 | g_return_val_if_fail (message, NULL); | ||
1635 | 1335 | |||
1636 | 1336 | if (!dbus_message_has_signature (message, "a{ss}")) | ||
1637 | 1337 | return NULL; | ||
1638 | 1338 | |||
1639 | 1339 | dbus_message_iter_init (message, &iter); | ||
1640 | 1340 | if (!gkd_secret_property_parse_fields (&iter, &builder)) { | ||
1641 | 1341 | gck_builder_clear (&builder); | ||
1642 | 1342 | return dbus_message_new_error (message, DBUS_ERROR_FAILED, | ||
1643 | 1343 | "Invalid data in attributes argument"); | ||
1644 | 1344 | } | ||
1645 | 1345 | |||
1646 | 1346 | if (base != NULL) { | ||
1647 | 1347 | if (!parse_object_path (self, base, &identifier, NULL)) | ||
1648 | 1348 | g_return_val_if_reached (NULL); | ||
1649 | 1349 | gck_builder_add_string (&builder, CKA_G_COLLECTION, identifier); | ||
1650 | 1350 | g_free (identifier); | ||
1651 | 1351 | } | ||
1652 | 1352 | |||
1653 | 1353 | gck_builder_add_ulong (&builder, CKA_CLASS, CKO_G_SEARCH); | ||
1654 | 1354 | gck_builder_add_boolean (&builder, CKA_TOKEN, FALSE); | ||
1655 | 1355 | |||
1656 | 1356 | /* The session we're using to access the object */ | ||
1657 | 1357 | session = gkd_secret_service_get_pkcs11_session (self->service, dbus_message_get_sender (message)); | ||
1658 | 1358 | g_return_val_if_fail (session, NULL); | ||
1659 | 1359 | |||
1660 | 1360 | /* Create the search object */ | ||
1661 | 1361 | search = gck_session_create_object (session, gck_builder_end (&builder), NULL, &error); | ||
1662 | 1362 | |||
1663 | 1363 | if (error != NULL) { | ||
1664 | 1364 | reply = dbus_message_new_error_printf (message, DBUS_ERROR_FAILED, | ||
1665 | 1365 | "Couldn't search for items: %s", | ||
1666 | 1366 | egg_error_message (error)); | ||
1667 | 1367 | g_clear_error (&error); | ||
1668 | 1368 | return reply; | ||
1669 | 1369 | } | ||
1670 | 1370 | |||
1671 | 1371 | /* Get the matched item handles, and delete the search object */ | ||
1672 | 1372 | data = gck_object_get_data (search, CKA_G_MATCHED, NULL, &n_data, &error); | ||
1673 | 1373 | gck_object_destroy (search, NULL, NULL); | ||
1674 | 1374 | g_object_unref (search); | ||
1675 | 1375 | |||
1676 | 1376 | if (error != NULL) { | ||
1677 | 1377 | reply = dbus_message_new_error_printf (message, DBUS_ERROR_FAILED, | ||
1678 | 1378 | "Couldn't retrieve matched items: %s", | ||
1679 | 1379 | egg_error_message (error)); | ||
1680 | 1380 | g_clear_error (&error); | ||
1681 | 1381 | return reply; | ||
1682 | 1382 | } | ||
1683 | 1383 | |||
1684 | 1384 | /* Build a list of object handles */ | ||
1685 | 1385 | items = gck_objects_from_handle_array (session, data, n_data / sizeof (CK_OBJECT_HANDLE)); | ||
1686 | 1386 | g_free (data); | ||
1687 | 1387 | |||
1688 | 1388 | /* Filter out the locked items */ | ||
1689 | 1389 | item_cleanup_search_results (session, items, &locked, &unlocked); | ||
1690 | 1390 | |||
1691 | 1391 | /* Prepare the reply message */ | ||
1692 | 1392 | reply = dbus_message_new_method_return (message); | ||
1693 | 1393 | dbus_message_iter_init_append (reply, &iter); | ||
1694 | 1394 | |||
1695 | 1395 | dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "o", &array); | ||
1696 | 1396 | objects_foreach_item (self, unlocked, NULL, on_object_path_append_to_iter, &array); | ||
1697 | 1397 | dbus_message_iter_close_container (&iter, &array); | ||
1698 | 1398 | |||
1699 | 1399 | dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "o", &array); | ||
1700 | 1400 | objects_foreach_item (self, locked, NULL, on_object_path_append_to_iter, &array); | ||
1701 | 1401 | dbus_message_iter_close_container (&iter, &array); | ||
1702 | 1402 | |||
1703 | 1403 | g_list_free (locked); | ||
1704 | 1404 | g_list_free (unlocked); | ||
1705 | 1405 | gck_list_unref_free (items); | ||
1706 | 1406 | |||
1707 | 1407 | return reply; | ||
1708 | 1408 | } | ||
1709 | 1409 | |||
1710 | 1410 | DBusMessage* | ||
1711 | 1411 | gkd_secret_objects_handle_get_secrets (GkdSecretObjects *self, DBusMessage *message) | ||
1712 | 1412 | { | ||
1713 | 1413 | DBusError derr = DBUS_ERROR_INIT; | ||
1714 | 1414 | GkdSecretSession *session; | ||
1715 | 1415 | GkdSecretSecret *secret; | ||
1716 | 1416 | DBusMessage *reply; | ||
1717 | 1417 | GckObject *item; | ||
1718 | 1418 | DBusMessageIter iter, array, dict; | ||
1719 | 1419 | const char *session_path; | ||
1720 | 1420 | const char *caller; | ||
1721 | 1421 | char **paths; | ||
1722 | 1422 | int n_paths, i; | ||
1723 | 1423 | |||
1724 | 1424 | if (!dbus_message_get_args (message, NULL, | ||
1725 | 1425 | DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &paths, &n_paths, | ||
1726 | 1426 | DBUS_TYPE_OBJECT_PATH, &session_path, | ||
1727 | 1427 | DBUS_TYPE_INVALID)) | ||
1728 | 1428 | return NULL; | ||
1729 | 1429 | |||
1730 | 1430 | caller = dbus_message_get_sender (message); | ||
1731 | 1431 | g_return_val_if_fail (caller, NULL); | ||
1732 | 1432 | |||
1733 | 1433 | session = gkd_secret_service_lookup_session (self->service, session_path, | ||
1734 | 1434 | dbus_message_get_sender (message)); | ||
1735 | 1435 | if (session == NULL) | ||
1736 | 1436 | return dbus_message_new_error (message, SECRET_ERROR_NO_SESSION, "The session does not exist"); | ||
1737 | 1437 | |||
1738 | 1438 | reply = dbus_message_new_method_return (message); | ||
1739 | 1439 | dbus_message_iter_init_append (reply, &iter); | ||
1740 | 1440 | dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "{o(oayays)}", &array); | ||
1741 | 1441 | |||
1742 | 1442 | for (i = 0; i < n_paths; ++i) { | ||
1743 | 1443 | |||
1744 | 1444 | /* Try to find the item, if it doesn't exist, just ignore */ | ||
1745 | 1445 | item = gkd_secret_objects_lookup_item (self, caller, paths[i]); | ||
1746 | 1446 | if (!item) | ||
1747 | 1447 | continue; | ||
1748 | 1448 | |||
1749 | 1449 | secret = gkd_secret_session_get_item_secret (session, item, &derr); | ||
1750 | 1450 | g_object_unref (item); | ||
1751 | 1451 | |||
1752 | 1452 | if (secret == NULL) { | ||
1753 | 1453 | /* We ignore is locked, and just leave out from response */ | ||
1754 | 1454 | if (dbus_error_has_name (&derr, SECRET_ERROR_IS_LOCKED)) { | ||
1755 | 1455 | dbus_error_free (&derr); | ||
1756 | 1456 | continue; | ||
1757 | 1457 | |||
1758 | 1458 | /* All other errors stop the operation */ | ||
1759 | 1459 | } else { | ||
1760 | 1460 | dbus_message_unref (reply); | ||
1761 | 1461 | reply = dbus_message_new_error (message, derr.name, derr.message); | ||
1762 | 1462 | dbus_error_free (&derr); | ||
1763 | 1463 | break; | ||
1764 | 1464 | } | ||
1765 | 1465 | } | ||
1766 | 1466 | |||
1767 | 1467 | dbus_message_iter_open_container (&array, DBUS_TYPE_DICT_ENTRY, NULL, &dict); | ||
1768 | 1468 | dbus_message_iter_append_basic (&dict, DBUS_TYPE_OBJECT_PATH, &(paths[i])); | ||
1769 | 1469 | gkd_secret_secret_append (secret, &dict); | ||
1770 | 1470 | gkd_secret_secret_free (secret); | ||
1771 | 1471 | dbus_message_iter_close_container (&array, &dict); | ||
1772 | 1472 | } | ||
1773 | 1473 | |||
1774 | 1474 | if (i == n_paths) | ||
1775 | 1475 | dbus_message_iter_close_container (&iter, &array); | ||
1776 | 1476 | dbus_free_string_array (paths); | ||
1777 | 1477 | |||
1778 | 1478 | return reply; | ||
1779 | 1479 | } | ||
1780 | 1480 | |||
1781 | 1481 | static void | ||
1782 | 1482 | on_each_item_emit_locked (GkdSecretObjects *self, | ||
1783 | 1483 | const gchar *path, | ||
1784 | 1484 | GckObject *object, | ||
1785 | 1485 | gpointer user_data) | ||
1786 | 1486 | { | ||
1787 | 1487 | gkd_secret_objects_emit_item_changed (self, object, "Locked", NULL); | ||
1788 | 1488 | } | ||
1789 | 1489 | |||
1790 | 1490 | void | ||
1791 | 1491 | gkd_secret_objects_emit_collection_locked (GkdSecretObjects *self, | ||
1792 | 1492 | GckObject *collection) | ||
1793 | 1493 | { | ||
1794 | 1494 | const gchar *collection_path; | ||
1795 | 1495 | |||
1796 | 1496 | collection_path = object_path_for_collection (collection); | ||
1797 | 1497 | gkd_secret_objects_foreach_item (self, NULL, collection_path, | ||
1798 | 1498 | on_each_item_emit_locked, NULL); | ||
1799 | 1499 | |||
1800 | 1500 | gkd_secret_objects_emit_collection_changed (self, collection, "Locked", NULL); | ||
1801 | 1501 | } | ||
1802 | 1502 | |||
1803 | 1503 | static void | ||
1804 | 1504 | emit_object_properties_changed (GkdSecretObjects *self, | ||
1805 | 1505 | GckObject *object, | ||
1806 | 1506 | const gchar *path, | ||
1807 | 1507 | const gchar *iface, | ||
1808 | 1508 | va_list va) | ||
1809 | 1509 | { | ||
1810 | 1510 | gchar *collection_path; | ||
1811 | 1511 | const gchar *propname; | ||
1812 | 1512 | DBusMessage *message; | ||
1813 | 1513 | DBusMessageIter iter; | ||
1814 | 1514 | DBusMessageIter array; | ||
1815 | 1515 | DBusMessageIter dict; | ||
1816 | 1516 | CK_ATTRIBUTE_TYPE type; | ||
1817 | 1517 | GckAttributes *attrs; | ||
1818 | 1518 | GError *error = NULL; | ||
1819 | 1519 | gboolean items = FALSE; | ||
1820 | 1520 | GArray *types; | ||
1821 | 1521 | |||
1822 | 1522 | types = g_array_new (FALSE, FALSE, sizeof (CK_ATTRIBUTE_TYPE)); | ||
1823 | 1523 | while ((propname = va_arg (va, const gchar *)) != NULL) { | ||
1824 | 1524 | |||
1825 | 1525 | /* Special case the Items property */ | ||
1826 | 1526 | if (g_str_equal (propname, "Items")) { | ||
1827 | 1527 | items = TRUE; | ||
1828 | 1528 | continue; | ||
1829 | 1529 | } | ||
1830 | 1530 | |||
1831 | 1531 | if (gkd_secret_property_get_type (propname, &type)) | ||
1832 | 1532 | g_array_append_val (types, type); | ||
1833 | 1533 | else | ||
1834 | 1534 | g_warning ("invalid property: %s", propname); | ||
1835 | 1535 | } | ||
1836 | 1536 | |||
1837 | 1537 | attrs = gck_object_get_full (object, (CK_ATTRIBUTE_TYPE *)types->data, | ||
1838 | 1538 | types->len, NULL, &error); | ||
1839 | 1539 | g_array_free (types, TRUE); | ||
1840 | 1540 | |||
1841 | 1541 | if (error != NULL) { | ||
1842 | 1542 | g_warning ("couldn't retrieve properties: %s", egg_error_message (error)); | ||
1843 | 1543 | return; | ||
1844 | 1544 | } | ||
1845 | 1545 | |||
1846 | 1546 | message = dbus_message_new_signal (path, DBUS_INTERFACE_PROPERTIES, | ||
1847 | 1547 | "PropertiesChanged"); | ||
1848 | 1548 | |||
1849 | 1549 | dbus_message_iter_init_append (message, &iter); | ||
1850 | 1550 | dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &iface); | ||
1851 | 1551 | dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "{sv}", &array); | ||
1852 | 1552 | gkd_secret_property_append_all (&array, attrs); | ||
1853 | 1553 | |||
1854 | 1554 | /* Append the Items property */ | ||
1855 | 1555 | if (items) { | ||
1856 | 1556 | collection_path = object_path_for_collection (object); | ||
1857 | 1557 | dbus_message_iter_open_container (&array, DBUS_TYPE_DICT_ENTRY, NULL, &dict); | ||
1858 | 1558 | propname = "Items"; | ||
1859 | 1559 | dbus_message_iter_append_basic (&dict, DBUS_TYPE_STRING, &propname); | ||
1860 | 1560 | gkd_secret_objects_append_item_paths (self, collection_path, &dict, NULL); | ||
1861 | 1561 | dbus_message_iter_close_container (&array, &dict); | ||
1862 | 1562 | g_free (collection_path); | ||
1863 | 1563 | } | ||
1864 | 1564 | |||
1865 | 1565 | dbus_message_iter_close_container (&iter, &array); | ||
1866 | 1566 | dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "s", &array); | ||
1867 | 1567 | dbus_message_iter_close_container (&iter, &array); | ||
1868 | 1568 | |||
1869 | 1569 | if (!dbus_connection_send (gkd_secret_service_get_connection (self->service), | ||
1870 | 1570 | message, NULL)) | ||
1871 | 1571 | g_return_if_reached (); | ||
1872 | 1572 | dbus_message_unref (message); | ||
1873 | 1573 | |||
1874 | 1574 | gck_attributes_unref (attrs); | ||
1875 | 1575 | } | ||
1876 | 1576 | |||
1877 | 1577 | void | ||
1878 | 1578 | gkd_secret_objects_emit_collection_changed (GkdSecretObjects *self, | ||
1879 | 1579 | GckObject *collection, | ||
1880 | 1580 | ...) | ||
1881 | 1581 | { | ||
1882 | 1582 | DBusMessage *message; | ||
1883 | 1583 | gchar *collection_path; | ||
1884 | 1584 | va_list va; | ||
1885 | 1585 | |||
1886 | 1586 | g_return_if_fail (GKD_SECRET_IS_OBJECTS (self)); | ||
1887 | 1587 | g_return_if_fail (GCK_OBJECT (collection)); | ||
1888 | 1588 | |||
1889 | 1589 | collection_path = object_path_for_collection (collection); | ||
1890 | 1590 | |||
1891 | 1591 | message = dbus_message_new_signal (SECRET_SERVICE_PATH, | ||
1892 | 1592 | SECRET_SERVICE_INTERFACE, | ||
1893 | 1593 | "CollectionChanged"); | ||
1894 | 1594 | dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &collection_path, | ||
1895 | 1595 | DBUS_TYPE_INVALID); | ||
1896 | 1596 | |||
1897 | 1597 | if (!dbus_connection_send (gkd_secret_service_get_connection (self->service), | ||
1898 | 1598 | message, NULL)) | ||
1899 | 1599 | g_return_if_reached (); | ||
1900 | 1600 | |||
1901 | 1601 | dbus_message_unref (message); | ||
1902 | 1602 | |||
1903 | 1603 | va_start (va, collection); | ||
1904 | 1604 | emit_object_properties_changed (self, collection, collection_path, | ||
1905 | 1605 | SECRET_COLLECTION_INTERFACE, va); | ||
1906 | 1606 | va_end (va); | ||
1907 | 1607 | |||
1908 | 1608 | g_free (collection_path); | ||
1909 | 1609 | } | ||
1910 | 1610 | |||
1911 | 1611 | void | ||
1912 | 1612 | gkd_secret_objects_emit_item_created (GkdSecretObjects *self, | ||
1913 | 1613 | GckObject *collection, | ||
1914 | 1614 | GckObject *item) | ||
1915 | 1615 | { | ||
1916 | 1616 | DBusMessage *message; | ||
1917 | 1617 | gchar *collection_path; | ||
1918 | 1618 | gchar *item_path; | ||
1919 | 1619 | |||
1920 | 1620 | g_return_if_fail (GKD_SECRET_IS_OBJECTS (self)); | ||
1921 | 1621 | g_return_if_fail (GCK_OBJECT (collection)); | ||
1922 | 1622 | g_return_if_fail (GCK_OBJECT (item)); | ||
1923 | 1623 | |||
1924 | 1624 | collection_path = object_path_for_collection (collection); | ||
1925 | 1625 | item_path = object_path_for_item (collection_path, item); | ||
1926 | 1626 | |||
1927 | 1627 | message = dbus_message_new_signal (collection_path, | ||
1928 | 1628 | SECRET_COLLECTION_INTERFACE, | ||
1929 | 1629 | "ItemCreated"); | ||
1930 | 1630 | dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &item_path, | ||
1931 | 1631 | DBUS_TYPE_INVALID); | ||
1932 | 1632 | |||
1933 | 1633 | if (!dbus_connection_send (gkd_secret_service_get_connection (self->service), | ||
1934 | 1634 | message, NULL)) | ||
1935 | 1635 | g_return_if_reached (); | ||
1936 | 1636 | |||
1937 | 1637 | dbus_message_unref (message); | ||
1938 | 1638 | |||
1939 | 1639 | gkd_secret_objects_emit_collection_changed (self, collection, "Items", NULL); | ||
1940 | 1640 | |||
1941 | 1641 | g_free (item_path); | ||
1942 | 1642 | g_free (collection_path); | ||
1943 | 1643 | } | ||
1944 | 1644 | |||
1945 | 1645 | void | ||
1946 | 1646 | gkd_secret_objects_emit_item_changed (GkdSecretObjects *self, | ||
1947 | 1647 | GckObject *item, | ||
1948 | 1648 | ...) | ||
1949 | 1649 | { | ||
1950 | 1650 | DBusMessage *message; | ||
1951 | 1651 | gchar *collection_path; | ||
1952 | 1652 | gchar *item_path; | ||
1953 | 1653 | va_list va; | ||
1954 | 1654 | |||
1955 | 1655 | g_return_if_fail (GKD_SECRET_IS_OBJECTS (self)); | ||
1956 | 1656 | g_return_if_fail (GCK_OBJECT (item)); | ||
1957 | 1657 | |||
1958 | 1658 | collection_path = collection_path_for_item (item); | ||
1959 | 1659 | item_path = object_path_for_item (collection_path, item); | ||
1960 | 1660 | |||
1961 | 1661 | message = dbus_message_new_signal (collection_path, | ||
1962 | 1662 | SECRET_COLLECTION_INTERFACE, | ||
1963 | 1663 | "ItemChanged"); | ||
1964 | 1664 | dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &item_path, | ||
1965 | 1665 | DBUS_TYPE_INVALID); | ||
1966 | 1666 | |||
1967 | 1667 | if (!dbus_connection_send (gkd_secret_service_get_connection (self->service), | ||
1968 | 1668 | message, NULL)) | ||
1969 | 1669 | g_return_if_reached (); | ||
1970 | 1670 | |||
1971 | 1671 | dbus_message_unref (message); | ||
1972 | 1672 | |||
1973 | 1673 | va_start (va, item); | ||
1974 | 1674 | emit_object_properties_changed (self, item, item_path, | ||
1975 | 1675 | SECRET_ITEM_INTERFACE, va); | ||
1976 | 1676 | va_end (va); | ||
1977 | 1677 | |||
1978 | 1678 | g_free (item_path); | ||
1979 | 1679 | g_free (collection_path); | ||
1980 | 1680 | } | ||
1981 | 1681 | |||
1982 | 1682 | void | ||
1983 | 1683 | gkd_secret_objects_emit_item_deleted (GkdSecretObjects *self, | ||
1984 | 1684 | GckObject *collection, | ||
1985 | 1685 | const gchar *item_path) | ||
1986 | 1686 | { | ||
1987 | 1687 | DBusMessage *message; | ||
1988 | 1688 | gchar *collection_path; | ||
1989 | 1689 | |||
1990 | 1690 | g_return_if_fail (GKD_SECRET_IS_OBJECTS (self)); | ||
1991 | 1691 | g_return_if_fail (GCK_OBJECT (collection)); | ||
1992 | 1692 | g_return_if_fail (item_path != NULL); | ||
1993 | 1693 | |||
1994 | 1694 | collection_path = object_path_for_collection (collection); | ||
1995 | 1695 | |||
1996 | 1696 | message = dbus_message_new_signal (collection_path, | ||
1997 | 1697 | SECRET_COLLECTION_INTERFACE, | ||
1998 | 1698 | "ItemDeleted"); | ||
1999 | 1699 | dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &item_path, | ||
2000 | 1700 | DBUS_TYPE_INVALID); | ||
2001 | 1701 | |||
2002 | 1702 | if (!dbus_connection_send (gkd_secret_service_get_connection (self->service), | ||
2003 | 1703 | message, NULL)) | ||
2004 | 1704 | g_return_if_reached (); | ||
2005 | 1705 | |||
2006 | 1706 | dbus_message_unref (message); | ||
2007 | 1707 | g_free (collection_path); | ||
2008 | 1708 | |||
2009 | 1709 | gkd_secret_objects_emit_collection_changed (self, collection, "Items", NULL); | ||
2010 | 1710 | } | ||
2011 | 0 | 1711 | ||
2012 | === added file '.pc/00git_fix_searchitems_method.patch/daemon/dbus/gkd-secret-objects.h' | |||
2013 | --- .pc/00git_fix_searchitems_method.patch/daemon/dbus/gkd-secret-objects.h 1970-01-01 00:00:00 +0000 | |||
2014 | +++ .pc/00git_fix_searchitems_method.patch/daemon/dbus/gkd-secret-objects.h 2013-03-14 13:26:21 +0000 | |||
2015 | @@ -0,0 +1,112 @@ | |||
2016 | 1 | /* | ||
2017 | 2 | * gnome-keyring | ||
2018 | 3 | * | ||
2019 | 4 | * Copyright (C) 2009 Stefan Walter | ||
2020 | 5 | * | ||
2021 | 6 | * This program is free software; you can redistribute it and/or modify | ||
2022 | 7 | * it under the terms of the GNU Lesser General Public License as | ||
2023 | 8 | * published by the Free Software Foundation; either version 2.1 of | ||
2024 | 9 | * the License, or (at your option) any later version. | ||
2025 | 10 | * | ||
2026 | 11 | * This program is distributed in the hope that it will be useful, but | ||
2027 | 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2028 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
2029 | 14 | * Lesser General Public License for more details. | ||
2030 | 15 | * | ||
2031 | 16 | * You should have received a copy of the GNU Lesser General Public | ||
2032 | 17 | * License along with this program; if not, write to the Free Software | ||
2033 | 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | ||
2034 | 19 | * 02111-1307, USA. | ||
2035 | 20 | */ | ||
2036 | 21 | |||
2037 | 22 | #ifndef __GKD_SECRET_OBJECTS_H__ | ||
2038 | 23 | #define __GKD_SECRET_OBJECTS_H__ | ||
2039 | 24 | |||
2040 | 25 | #include "gkd-secret-types.h" | ||
2041 | 26 | |||
2042 | 27 | #include <gck/gck.h> | ||
2043 | 28 | |||
2044 | 29 | #include <glib-object.h> | ||
2045 | 30 | |||
2046 | 31 | #include <dbus/dbus.h> | ||
2047 | 32 | |||
2048 | 33 | #define GKD_SECRET_TYPE_OBJECTS (gkd_secret_objects_get_type ()) | ||
2049 | 34 | #define GKD_SECRET_OBJECTS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GKD_SECRET_TYPE_OBJECTS, GkdSecretObjects)) | ||
2050 | 35 | #define GKD_SECRET_OBJECTS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GKD_SECRET_TYPE_OBJECTS, GkdSecretObjectsClass)) | ||
2051 | 36 | #define GKD_SECRET_IS_OBJECTS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GKD_SECRET_TYPE_OBJECTS)) | ||
2052 | 37 | #define GKD_SECRET_IS_OBJECTS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GKD_SECRET_TYPE_OBJECTS)) | ||
2053 | 38 | #define GKD_SECRET_OBJECTS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GKD_SECRET_TYPE_OBJECTS, GkdSecretObjectsClass)) | ||
2054 | 39 | |||
2055 | 40 | typedef struct _GkdSecretObjectsClass GkdSecretObjectsClass; | ||
2056 | 41 | |||
2057 | 42 | struct _GkdSecretObjectsClass { | ||
2058 | 43 | GObjectClass parent_class; | ||
2059 | 44 | }; | ||
2060 | 45 | |||
2061 | 46 | typedef void (*GkdSecretObjectsForeach) (GkdSecretObjects *self, | ||
2062 | 47 | const gchar *path, | ||
2063 | 48 | GckObject *object, | ||
2064 | 49 | gpointer user_data); | ||
2065 | 50 | |||
2066 | 51 | GType gkd_secret_objects_get_type (void); | ||
2067 | 52 | |||
2068 | 53 | DBusMessage* gkd_secret_objects_dispatch (GkdSecretObjects *self, | ||
2069 | 54 | DBusMessage *message); | ||
2070 | 55 | |||
2071 | 56 | DBusMessage* gkd_secret_objects_handle_search_items (GkdSecretObjects *self, | ||
2072 | 57 | DBusMessage *message, | ||
2073 | 58 | const gchar *base); | ||
2074 | 59 | |||
2075 | 60 | DBusMessage* gkd_secret_objects_handle_get_secrets (GkdSecretObjects *self, | ||
2076 | 61 | DBusMessage *message); | ||
2077 | 62 | |||
2078 | 63 | void gkd_secret_objects_foreach_collection (GkdSecretObjects *self, | ||
2079 | 64 | DBusMessage *message, | ||
2080 | 65 | GkdSecretObjectsForeach callback, | ||
2081 | 66 | gpointer user_data); | ||
2082 | 67 | |||
2083 | 68 | void gkd_secret_objects_foreach_item (GkdSecretObjects *self, | ||
2084 | 69 | DBusMessage *message, | ||
2085 | 70 | const gchar *base, | ||
2086 | 71 | GkdSecretObjectsForeach callback, | ||
2087 | 72 | gpointer user_data); | ||
2088 | 73 | |||
2089 | 74 | void gkd_secret_objects_append_collection_paths (GkdSecretObjects *self, | ||
2090 | 75 | DBusMessageIter *iter, | ||
2091 | 76 | DBusMessage *message); | ||
2092 | 77 | |||
2093 | 78 | void gkd_secret_objects_append_item_paths (GkdSecretObjects *self, | ||
2094 | 79 | const gchar *base, | ||
2095 | 80 | DBusMessageIter *iter, | ||
2096 | 81 | DBusMessage *message); | ||
2097 | 82 | |||
2098 | 83 | GckSlot* gkd_secret_objects_get_pkcs11_slot (GkdSecretObjects *self); | ||
2099 | 84 | |||
2100 | 85 | GckObject* gkd_secret_objects_lookup_collection (GkdSecretObjects *self, | ||
2101 | 86 | const gchar *caller, | ||
2102 | 87 | const gchar *path); | ||
2103 | 88 | |||
2104 | 89 | GckObject* gkd_secret_objects_lookup_item (GkdSecretObjects *self, | ||
2105 | 90 | const gchar *caller, | ||
2106 | 91 | const gchar *path); | ||
2107 | 92 | |||
2108 | 93 | void gkd_secret_objects_emit_collection_locked (GkdSecretObjects *self, | ||
2109 | 94 | GckObject *collection); | ||
2110 | 95 | |||
2111 | 96 | void gkd_secret_objects_emit_collection_changed (GkdSecretObjects *self, | ||
2112 | 97 | GckObject *collection, | ||
2113 | 98 | ...) G_GNUC_NULL_TERMINATED; | ||
2114 | 99 | |||
2115 | 100 | void gkd_secret_objects_emit_item_created (GkdSecretObjects *self, | ||
2116 | 101 | GckObject *collection, | ||
2117 | 102 | GckObject *item); | ||
2118 | 103 | |||
2119 | 104 | void gkd_secret_objects_emit_item_changed (GkdSecretObjects *self, | ||
2120 | 105 | GckObject *item, | ||
2121 | 106 | ...) G_GNUC_NULL_TERMINATED; | ||
2122 | 107 | |||
2123 | 108 | void gkd_secret_objects_emit_item_deleted (GkdSecretObjects *self, | ||
2124 | 109 | GckObject *collection, | ||
2125 | 110 | const gchar *item_path); | ||
2126 | 111 | |||
2127 | 112 | #endif /* __GKD_SECRET_OBJECTS_H__ */ | ||
2128 | 0 | 113 | ||
2129 | === added file '.pc/00git_fix_searchitems_method.patch/daemon/dbus/gkd-secret-service.c' | |||
2130 | --- .pc/00git_fix_searchitems_method.patch/daemon/dbus/gkd-secret-service.c 1970-01-01 00:00:00 +0000 | |||
2131 | +++ .pc/00git_fix_searchitems_method.patch/daemon/dbus/gkd-secret-service.c 2013-03-14 13:26:21 +0000 | |||
2132 | @@ -0,0 +1,1598 @@ | |||
2133 | 1 | /* | ||
2134 | 2 | * gnome-keyring | ||
2135 | 3 | * | ||
2136 | 4 | * Copyright (C) 2008 Stefan Walter | ||
2137 | 5 | * | ||
2138 | 6 | * This program is free software; you can redistribute it and/or modify | ||
2139 | 7 | * it under the terms of the GNU Lesser General Public License as | ||
2140 | 8 | * published by the Free Software Foundation; either version 2.1 of | ||
2141 | 9 | * the License, or (at your option) any later version. | ||
2142 | 10 | * | ||
2143 | 11 | * This program is distributed in the hope that it will be useful, but | ||
2144 | 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2145 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
2146 | 14 | * Lesser General Public License for more details. | ||
2147 | 15 | * | ||
2148 | 16 | * You should have received a copy of the GNU Lesser General Public | ||
2149 | 17 | * License along with this program; if not, write to the Free Software | ||
2150 | 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | ||
2151 | 19 | * 02111-1307, USA. | ||
2152 | 20 | */ | ||
2153 | 21 | |||
2154 | 22 | #include "config.h" | ||
2155 | 23 | |||
2156 | 24 | #include "gkd-dbus-util.h" | ||
2157 | 25 | #include "gkd-secret-change.h" | ||
2158 | 26 | #include "gkd-secret-create.h" | ||
2159 | 27 | #include "gkd-secret-dispatch.h" | ||
2160 | 28 | #include "gkd-secret-error.h" | ||
2161 | 29 | #include "gkd-secret-introspect.h" | ||
2162 | 30 | #include "gkd-secret-lock.h" | ||
2163 | 31 | #include "gkd-secret-objects.h" | ||
2164 | 32 | #include "gkd-secret-prompt.h" | ||
2165 | 33 | #include "gkd-secret-property.h" | ||
2166 | 34 | #include "gkd-secret-secret.h" | ||
2167 | 35 | #include "gkd-secret-service.h" | ||
2168 | 36 | #include "gkd-secret-session.h" | ||
2169 | 37 | #include "gkd-secret-types.h" | ||
2170 | 38 | #include "gkd-secret-unlock.h" | ||
2171 | 39 | #include "gkd-secret-util.h" | ||
2172 | 40 | |||
2173 | 41 | #include "egg/egg-error.h" | ||
2174 | 42 | #include "egg/egg-unix-credentials.h" | ||
2175 | 43 | |||
2176 | 44 | #include <gck/gck.h> | ||
2177 | 45 | |||
2178 | 46 | #include "pkcs11/pkcs11i.h" | ||
2179 | 47 | |||
2180 | 48 | #include <string.h> | ||
2181 | 49 | |||
2182 | 50 | enum { | ||
2183 | 51 | PROP_0, | ||
2184 | 52 | PROP_CONNECTION, | ||
2185 | 53 | PROP_PKCS11_SLOT, | ||
2186 | 54 | }; | ||
2187 | 55 | |||
2188 | 56 | struct _GkdSecretService { | ||
2189 | 57 | GObject parent; | ||
2190 | 58 | DBusConnection *connection; | ||
2191 | 59 | GHashTable *clients; | ||
2192 | 60 | gchar *match_rule; | ||
2193 | 61 | GkdSecretObjects *objects; | ||
2194 | 62 | GHashTable *aliases; | ||
2195 | 63 | GckSession *internal_session; | ||
2196 | 64 | gchar *alias_directory; | ||
2197 | 65 | }; | ||
2198 | 66 | |||
2199 | 67 | typedef struct _ServiceClient { | ||
2200 | 68 | gchar *caller_peer; | ||
2201 | 69 | gchar *caller_exec; | ||
2202 | 70 | pid_t caller_pid; | ||
2203 | 71 | CK_G_APPLICATION app; | ||
2204 | 72 | GckSession *pkcs11_session; | ||
2205 | 73 | GHashTable *dispatch; | ||
2206 | 74 | } ServiceClient; | ||
2207 | 75 | |||
2208 | 76 | /* Forward declaration */ | ||
2209 | 77 | static void service_dispatch_message (GkdSecretService *, DBusMessage *); | ||
2210 | 78 | |||
2211 | 79 | G_DEFINE_TYPE (GkdSecretService, gkd_secret_service, G_TYPE_OBJECT); | ||
2212 | 80 | |||
2213 | 81 | /* ----------------------------------------------------------------------------- | ||
2214 | 82 | * INTERNAL | ||
2215 | 83 | */ | ||
2216 | 84 | |||
2217 | 85 | static gchar* | ||
2218 | 86 | default_path (GkdSecretService *self) | ||
2219 | 87 | { | ||
2220 | 88 | gchar *old_directory; | ||
2221 | 89 | gchar *new_directory; | ||
2222 | 90 | |||
2223 | 91 | if (self->alias_directory == NULL) { | ||
2224 | 92 | new_directory = g_build_filename (g_get_user_data_dir (), "keyrings", NULL); | ||
2225 | 93 | old_directory = g_build_filename (g_get_home_dir (), ".gnome2", "keyrings", NULL); | ||
2226 | 94 | |||
2227 | 95 | if (!g_file_test (new_directory, G_FILE_TEST_IS_DIR) && | ||
2228 | 96 | g_file_test (old_directory, G_FILE_TEST_IS_DIR)) { | ||
2229 | 97 | self->alias_directory = old_directory; | ||
2230 | 98 | old_directory = NULL; | ||
2231 | 99 | } else { | ||
2232 | 100 | self->alias_directory = new_directory; | ||
2233 | 101 | new_directory = NULL; | ||
2234 | 102 | } | ||
2235 | 103 | |||
2236 | 104 | g_free (old_directory); | ||
2237 | 105 | g_free (new_directory); | ||
2238 | 106 | g_debug ("keyring alias directory: %s", self->alias_directory); | ||
2239 | 107 | } | ||
2240 | 108 | |||
2241 | 109 | return g_build_filename (self->alias_directory, "default", NULL); | ||
2242 | 110 | } | ||
2243 | 111 | |||
2244 | 112 | static void | ||
2245 | 113 | update_default (GkdSecretService *self, gboolean force) | ||
2246 | 114 | { | ||
2247 | 115 | gchar *contents = NULL; | ||
2248 | 116 | const gchar *identifier; | ||
2249 | 117 | gchar *path; | ||
2250 | 118 | |||
2251 | 119 | if (!force) { | ||
2252 | 120 | identifier = g_hash_table_lookup (self->aliases, "default"); | ||
2253 | 121 | if (identifier) | ||
2254 | 122 | return; | ||
2255 | 123 | } | ||
2256 | 124 | |||
2257 | 125 | path = default_path (self); | ||
2258 | 126 | if (g_file_get_contents (path, &contents, NULL, NULL)) { | ||
2259 | 127 | g_strstrip (contents); | ||
2260 | 128 | if (!contents[0]) { | ||
2261 | 129 | g_free (contents); | ||
2262 | 130 | contents = NULL; | ||
2263 | 131 | } | ||
2264 | 132 | } | ||
2265 | 133 | g_free (path); | ||
2266 | 134 | |||
2267 | 135 | g_hash_table_replace (self->aliases, g_strdup ("default"), contents); | ||
2268 | 136 | } | ||
2269 | 137 | |||
2270 | 138 | static void | ||
2271 | 139 | store_default (GkdSecretService *self) | ||
2272 | 140 | { | ||
2273 | 141 | GError *error = NULL; | ||
2274 | 142 | const gchar *identifier; | ||
2275 | 143 | gchar *path; | ||
2276 | 144 | |||
2277 | 145 | identifier = g_hash_table_lookup (self->aliases, "default"); | ||
2278 | 146 | if (!identifier) | ||
2279 | 147 | return; | ||
2280 | 148 | |||
2281 | 149 | path = default_path (self); | ||
2282 | 150 | if (!g_file_set_contents (path, identifier, -1, &error)) | ||
2283 | 151 | g_message ("couldn't store default keyring: %s", egg_error_message (error)); | ||
2284 | 152 | g_free (path); | ||
2285 | 153 | } | ||
2286 | 154 | |||
2287 | 155 | static gboolean | ||
2288 | 156 | object_path_has_prefix (const gchar *path, const gchar *prefix) | ||
2289 | 157 | { | ||
2290 | 158 | gsize len; | ||
2291 | 159 | |||
2292 | 160 | g_assert (prefix); | ||
2293 | 161 | |||
2294 | 162 | if (!path) | ||
2295 | 163 | return FALSE; | ||
2296 | 164 | |||
2297 | 165 | len = strlen (prefix); | ||
2298 | 166 | return g_ascii_strncasecmp (path, prefix, len) == 0 && | ||
2299 | 167 | (path[len] == '\0' || path[len] == '/'); | ||
2300 | 168 | } | ||
2301 | 169 | |||
2302 | 170 | static void | ||
2303 | 171 | dispose_and_unref (gpointer object) | ||
2304 | 172 | { | ||
2305 | 173 | g_return_if_fail (G_IS_OBJECT (object)); | ||
2306 | 174 | g_object_run_dispose (G_OBJECT (object)); | ||
2307 | 175 | g_object_unref (object); | ||
2308 | 176 | } | ||
2309 | 177 | |||
2310 | 178 | static void | ||
2311 | 179 | free_client (gpointer data) | ||
2312 | 180 | { | ||
2313 | 181 | ServiceClient *client = data; | ||
2314 | 182 | |||
2315 | 183 | if (!client) | ||
2316 | 184 | return; | ||
2317 | 185 | |||
2318 | 186 | /* Info about our client */ | ||
2319 | 187 | g_free (client->caller_peer); | ||
2320 | 188 | g_free (client->caller_exec); | ||
2321 | 189 | |||
2322 | 190 | /* The session we use for accessing as our client */ | ||
2323 | 191 | if (client->pkcs11_session) { | ||
2324 | 192 | #if 0 | ||
2325 | 193 | gck_session_close (client->pkcs11_session, NULL); | ||
2326 | 194 | #endif | ||
2327 | 195 | g_object_unref (client->pkcs11_session); | ||
2328 | 196 | } | ||
2329 | 197 | |||
2330 | 198 | /* The sessions and prompts the client has open */ | ||
2331 | 199 | g_hash_table_destroy (client->dispatch); | ||
2332 | 200 | |||
2333 | 201 | g_free (client); | ||
2334 | 202 | } | ||
2335 | 203 | |||
2336 | 204 | typedef struct _on_get_connection_unix_process_id_args { | ||
2337 | 205 | GkdSecretService *self; | ||
2338 | 206 | DBusMessage *message; | ||
2339 | 207 | } on_get_connection_unix_process_id_args; | ||
2340 | 208 | |||
2341 | 209 | static void | ||
2342 | 210 | free_on_get_connection_unix_process_id_args (gpointer data) | ||
2343 | 211 | { | ||
2344 | 212 | on_get_connection_unix_process_id_args *args = data; | ||
2345 | 213 | if (args != NULL) { | ||
2346 | 214 | g_object_unref (args->self); | ||
2347 | 215 | dbus_message_unref (args->message); | ||
2348 | 216 | g_free (args); | ||
2349 | 217 | } | ||
2350 | 218 | } | ||
2351 | 219 | |||
2352 | 220 | static void | ||
2353 | 221 | on_get_connection_unix_process_id (DBusPendingCall *pending, gpointer user_data) | ||
2354 | 222 | { | ||
2355 | 223 | on_get_connection_unix_process_id_args *args = user_data; | ||
2356 | 224 | DBusMessage *reply = NULL; | ||
2357 | 225 | DBusError error = DBUS_ERROR_INIT; | ||
2358 | 226 | dbus_uint32_t caller_pid = 0; | ||
2359 | 227 | GkdSecretService *self; | ||
2360 | 228 | ServiceClient *client; | ||
2361 | 229 | const gchar *caller; | ||
2362 | 230 | |||
2363 | 231 | g_return_if_fail (GKD_SECRET_IS_SERVICE (args->self)); | ||
2364 | 232 | self = args->self; | ||
2365 | 233 | |||
2366 | 234 | /* Get the resulting process ID */ | ||
2367 | 235 | reply = dbus_pending_call_steal_reply (pending); | ||
2368 | 236 | g_return_if_fail (reply); | ||
2369 | 237 | |||
2370 | 238 | caller = dbus_message_get_sender (args->message); | ||
2371 | 239 | g_return_if_fail (caller); | ||
2372 | 240 | |||
2373 | 241 | client = g_hash_table_lookup (self->clients, caller); | ||
2374 | 242 | if (client == NULL) { | ||
2375 | 243 | |||
2376 | 244 | /* An error returned from GetConnectionUnixProcessID */ | ||
2377 | 245 | if (dbus_set_error_from_message (&error, reply)) { | ||
2378 | 246 | g_message ("couldn't get the caller's unix process id: %s", error.message); | ||
2379 | 247 | caller_pid = 0; | ||
2380 | 248 | dbus_error_free (&error); | ||
2381 | 249 | |||
2382 | 250 | /* A PID was returned from GetConnectionUnixProcessID */ | ||
2383 | 251 | } else { | ||
2384 | 252 | if (!dbus_message_get_args (reply, NULL, DBUS_TYPE_UINT32, &caller_pid, DBUS_TYPE_INVALID)) | ||
2385 | 253 | g_return_if_reached (); | ||
2386 | 254 | } | ||
2387 | 255 | |||
2388 | 256 | /* Initialize the client object */ | ||
2389 | 257 | client = g_new0 (ServiceClient, 1); | ||
2390 | 258 | client->caller_peer = g_strdup (caller); | ||
2391 | 259 | client->caller_pid = caller_pid; | ||
2392 | 260 | if (caller_pid != 0) | ||
2393 | 261 | client->caller_exec = egg_unix_credentials_executable (caller_pid); | ||
2394 | 262 | client->app.applicationData = client; | ||
2395 | 263 | client->dispatch = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, dispose_and_unref); | ||
2396 | 264 | |||
2397 | 265 | g_hash_table_replace (self->clients, client->caller_peer, client); | ||
2398 | 266 | |||
2399 | 267 | /* Update default collection each time someone connects */ | ||
2400 | 268 | update_default (self, TRUE); | ||
2401 | 269 | } | ||
2402 | 270 | |||
2403 | 271 | dbus_message_unref (reply); | ||
2404 | 272 | |||
2405 | 273 | /* Dispatch the original message again */ | ||
2406 | 274 | service_dispatch_message (self, args->message); | ||
2407 | 275 | } | ||
2408 | 276 | |||
2409 | 277 | static void | ||
2410 | 278 | initialize_service_client (GkdSecretService *self, DBusMessage *message) | ||
2411 | 279 | { | ||
2412 | 280 | on_get_connection_unix_process_id_args *args; | ||
2413 | 281 | DBusMessage *request; | ||
2414 | 282 | DBusPendingCall *pending; | ||
2415 | 283 | const gchar *caller; | ||
2416 | 284 | |||
2417 | 285 | g_assert (GKD_SECRET_IS_SERVICE (self)); | ||
2418 | 286 | g_assert (message); | ||
2419 | 287 | |||
2420 | 288 | args = g_new0 (on_get_connection_unix_process_id_args, 1); | ||
2421 | 289 | args->self = g_object_ref (self); | ||
2422 | 290 | args->message = dbus_message_ref (message); | ||
2423 | 291 | |||
2424 | 292 | caller = dbus_message_get_sender (message); | ||
2425 | 293 | g_return_if_fail (caller); | ||
2426 | 294 | |||
2427 | 295 | /* Message org.freedesktop.DBus.GetConnectionUnixProcessID(IN String caller) */ | ||
2428 | 296 | request = dbus_message_new_method_call ("org.freedesktop.DBus", "/org/freedesktop/DBus", | ||
2429 | 297 | "org.freedesktop.DBus", "GetConnectionUnixProcessID"); | ||
2430 | 298 | if (!request || !dbus_message_append_args (request, DBUS_TYPE_STRING, &caller, DBUS_TYPE_INVALID)) | ||
2431 | 299 | g_return_if_reached (); | ||
2432 | 300 | |||
2433 | 301 | /* | ||
2434 | 302 | * Send of request for GetConnectionUnixProcessID, with lowish timeout. | ||
2435 | 303 | * We're only talking to the session bus, so the reply should be fast. | ||
2436 | 304 | * In addition we want to send off a reply to our caller, before it | ||
2437 | 305 | * times out. | ||
2438 | 306 | */ | ||
2439 | 307 | if (!dbus_connection_send_with_reply (self->connection, request, &pending, 2000)) | ||
2440 | 308 | g_return_if_reached (); | ||
2441 | 309 | dbus_message_unref (request); | ||
2442 | 310 | |||
2443 | 311 | /* Track our new session object, on this call */ | ||
2444 | 312 | dbus_pending_call_set_notify (pending, on_get_connection_unix_process_id, args, | ||
2445 | 313 | free_on_get_connection_unix_process_id_args); | ||
2446 | 314 | dbus_pending_call_unref (pending); | ||
2447 | 315 | } | ||
2448 | 316 | |||
2449 | 317 | /* ----------------------------------------------------------------------------- | ||
2450 | 318 | * DBUS | ||
2451 | 319 | */ | ||
2452 | 320 | |||
2453 | 321 | static DBusMessage* | ||
2454 | 322 | service_property_get (GkdSecretService *self, DBusMessage *message) | ||
2455 | 323 | { | ||
2456 | 324 | DBusMessage *reply = NULL; | ||
2457 | 325 | DBusMessageIter iter; | ||
2458 | 326 | const gchar *interface; | ||
2459 | 327 | const gchar *name; | ||
2460 | 328 | |||
2461 | 329 | if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &interface, | ||
2462 | 330 | DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)) | ||
2463 | 331 | return NULL; | ||
2464 | 332 | |||
2465 | 333 | if (!gkd_dbus_interface_match (SECRET_SERVICE_INTERFACE, interface)) | ||
2466 | 334 | return dbus_message_new_error_printf (message, DBUS_ERROR_FAILED, | ||
2467 | 335 | "Object does not have properties on interface '%s'", | ||
2468 | 336 | interface); | ||
2469 | 337 | |||
2470 | 338 | /* The "Collections" property */ | ||
2471 | 339 | if (g_str_equal (name, "Collections")) { | ||
2472 | 340 | reply = dbus_message_new_method_return (message); | ||
2473 | 341 | dbus_message_iter_init_append (reply, &iter); | ||
2474 | 342 | gkd_secret_objects_append_collection_paths (self->objects, &iter, message); | ||
2475 | 343 | |||
2476 | 344 | /* No such property */ | ||
2477 | 345 | } else { | ||
2478 | 346 | reply = dbus_message_new_error_printf (message, DBUS_ERROR_FAILED, | ||
2479 | 347 | "Object does not have the '%s' property", name); | ||
2480 | 348 | } | ||
2481 | 349 | |||
2482 | 350 | return reply; | ||
2483 | 351 | } | ||
2484 | 352 | |||
2485 | 353 | static DBusMessage* | ||
2486 | 354 | service_property_set (GkdSecretService *self, DBusMessage *message) | ||
2487 | 355 | { | ||
2488 | 356 | return NULL; /* TODO: Need to implement */ | ||
2489 | 357 | } | ||
2490 | 358 | |||
2491 | 359 | static void | ||
2492 | 360 | service_append_all_properties (GkdSecretService *self, | ||
2493 | 361 | DBusMessageIter *iter) | ||
2494 | 362 | { | ||
2495 | 363 | DBusMessageIter array; | ||
2496 | 364 | DBusMessageIter dict; | ||
2497 | 365 | const gchar *name; | ||
2498 | 366 | |||
2499 | 367 | dbus_message_iter_open_container (iter, DBUS_TYPE_ARRAY, "{sv}", &array); | ||
2500 | 368 | |||
2501 | 369 | name = "Collections"; | ||
2502 | 370 | dbus_message_iter_open_container (&array, DBUS_TYPE_DICT_ENTRY, NULL, &dict); | ||
2503 | 371 | dbus_message_iter_append_basic (&dict, DBUS_TYPE_STRING, &name); | ||
2504 | 372 | gkd_secret_objects_append_collection_paths (self->objects, &dict, NULL); | ||
2505 | 373 | dbus_message_iter_close_container (&array, &dict); | ||
2506 | 374 | |||
2507 | 375 | dbus_message_iter_close_container (iter, &array); | ||
2508 | 376 | } | ||
2509 | 377 | |||
2510 | 378 | static DBusMessage* | ||
2511 | 379 | service_property_getall (GkdSecretService *self, DBusMessage *message) | ||
2512 | 380 | { | ||
2513 | 381 | DBusMessage *reply = NULL; | ||
2514 | 382 | DBusMessageIter iter; | ||
2515 | 383 | const gchar *interface; | ||
2516 | 384 | |||
2517 | 385 | if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &interface, DBUS_TYPE_INVALID)) | ||
2518 | 386 | return NULL; | ||
2519 | 387 | |||
2520 | 388 | if (!gkd_dbus_interface_match (SECRET_SERVICE_INTERFACE, interface)) | ||
2521 | 389 | return dbus_message_new_error_printf (message, DBUS_ERROR_FAILED, | ||
2522 | 390 | "Object does not have properties on interface '%s'", | ||
2523 | 391 | interface); | ||
2524 | 392 | |||
2525 | 393 | reply = dbus_message_new_method_return (message); | ||
2526 | 394 | dbus_message_iter_init_append (reply, &iter); | ||
2527 | 395 | service_append_all_properties (self, &iter); | ||
2528 | 396 | return reply; | ||
2529 | 397 | } | ||
2530 | 398 | |||
2531 | 399 | static DBusMessage* | ||
2532 | 400 | service_method_open_session (GkdSecretService *self, DBusMessage *message) | ||
2533 | 401 | { | ||
2534 | 402 | GkdSecretSession *session; | ||
2535 | 403 | DBusMessage *reply = NULL; | ||
2536 | 404 | const gchar *caller; | ||
2537 | 405 | |||
2538 | 406 | if (!dbus_message_has_signature (message, "sv")) | ||
2539 | 407 | return NULL; | ||
2540 | 408 | |||
2541 | 409 | caller = dbus_message_get_sender (message); | ||
2542 | 410 | |||
2543 | 411 | /* Now we can create a session with this information */ | ||
2544 | 412 | session = gkd_secret_session_new (self, caller); | ||
2545 | 413 | reply = gkd_secret_session_handle_open (session, message); | ||
2546 | 414 | |||
2547 | 415 | if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN) | ||
2548 | 416 | gkd_secret_service_publish_dispatch (self, caller, | ||
2549 | 417 | GKD_SECRET_DISPATCH (session)); | ||
2550 | 418 | |||
2551 | 419 | g_object_unref (session); | ||
2552 | 420 | return reply; | ||
2553 | 421 | } | ||
2554 | 422 | |||
2555 | 423 | static DBusMessage* | ||
2556 | 424 | service_method_create_collection (GkdSecretService *self, DBusMessage *message) | ||
2557 | 425 | { | ||
2558 | 426 | GckBuilder builder = GCK_BUILDER_INIT; | ||
2559 | 427 | DBusMessageIter iter, array; | ||
2560 | 428 | GckAttributes *attrs; | ||
2561 | 429 | GkdSecretCreate *create; | ||
2562 | 430 | DBusMessage *reply; | ||
2563 | 431 | const gchar *path; | ||
2564 | 432 | const gchar *alias; | ||
2565 | 433 | const char *caller; | ||
2566 | 434 | const gchar *coll; | ||
2567 | 435 | |||
2568 | 436 | /* Parse the incoming message */ | ||
2569 | 437 | if (!dbus_message_has_signature (message, "a{sv}s")) | ||
2570 | 438 | return NULL; | ||
2571 | 439 | if (!dbus_message_iter_init (message, &iter)) | ||
2572 | 440 | g_return_val_if_reached (NULL); | ||
2573 | 441 | dbus_message_iter_recurse (&iter, &array); | ||
2574 | 442 | if (!gkd_secret_property_parse_all (&array, SECRET_COLLECTION_INTERFACE, &builder)) { | ||
2575 | 443 | gck_builder_clear (&builder); | ||
2576 | 444 | return dbus_message_new_error_printf (message, DBUS_ERROR_INVALID_ARGS, | ||
2577 | 445 | "Invalid properties"); | ||
2578 | 446 | } | ||
2579 | 447 | if (!dbus_message_iter_next (&iter)) | ||
2580 | 448 | g_return_val_if_reached (NULL); | ||
2581 | 449 | dbus_message_iter_get_basic (&iter, &alias); | ||
2582 | 450 | |||
2583 | 451 | /* Empty alias is no alias */ | ||
2584 | 452 | if (alias) { | ||
2585 | 453 | if (!alias[0]) { | ||
2586 | 454 | alias = NULL; | ||
2587 | 455 | } else if (!g_str_equal (alias, "default")) { | ||
2588 | 456 | gck_builder_clear (&builder); | ||
2589 | 457 | return dbus_message_new_error (message, DBUS_ERROR_NOT_SUPPORTED, | ||
2590 | 458 | "Only the 'default' alias is supported"); | ||
2591 | 459 | } | ||
2592 | 460 | } | ||
2593 | 461 | |||
2594 | 462 | gck_builder_add_boolean (&builder, CKA_TOKEN, TRUE); | ||
2595 | 463 | attrs = gck_attributes_ref_sink (gck_builder_end (&builder)); | ||
2596 | 464 | |||
2597 | 465 | /* Create the prompt object, for the password */ | ||
2598 | 466 | caller = dbus_message_get_sender (message); | ||
2599 | 467 | create = gkd_secret_create_new (self, caller, attrs, alias); | ||
2600 | 468 | gck_attributes_unref (attrs); | ||
2601 | 469 | |||
2602 | 470 | path = gkd_secret_dispatch_get_object_path (GKD_SECRET_DISPATCH (create)); | ||
2603 | 471 | gkd_secret_service_publish_dispatch (self, caller, | ||
2604 | 472 | GKD_SECRET_DISPATCH (create)); | ||
2605 | 473 | |||
2606 | 474 | coll = "/"; | ||
2607 | 475 | reply = dbus_message_new_method_return (message); | ||
2608 | 476 | dbus_message_append_args (reply, | ||
2609 | 477 | DBUS_TYPE_OBJECT_PATH, &coll, | ||
2610 | 478 | DBUS_TYPE_OBJECT_PATH, &path, | ||
2611 | 479 | DBUS_TYPE_INVALID); | ||
2612 | 480 | |||
2613 | 481 | g_object_unref (create); | ||
2614 | 482 | return reply; | ||
2615 | 483 | } | ||
2616 | 484 | |||
2617 | 485 | static DBusMessage* | ||
2618 | 486 | service_method_lock_service (GkdSecretService *self, DBusMessage *message) | ||
2619 | 487 | { | ||
2620 | 488 | if (!dbus_message_get_args (message, NULL, DBUS_TYPE_INVALID)) | ||
2621 | 489 | return NULL; | ||
2622 | 490 | |||
2623 | 491 | /* TODO: Need to implement */ | ||
2624 | 492 | return dbus_message_new_method_return (message); | ||
2625 | 493 | } | ||
2626 | 494 | |||
2627 | 495 | static DBusMessage* | ||
2628 | 496 | service_method_unlock (GkdSecretService *self, DBusMessage *message) | ||
2629 | 497 | { | ||
2630 | 498 | GkdSecretUnlock *unlock; | ||
2631 | 499 | DBusMessage *reply; | ||
2632 | 500 | const char *caller; | ||
2633 | 501 | const gchar *path; | ||
2634 | 502 | int n_objpaths, i; | ||
2635 | 503 | char **objpaths; | ||
2636 | 504 | |||
2637 | 505 | if (!dbus_message_get_args (message, NULL, | ||
2638 | 506 | DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &objpaths, &n_objpaths, | ||
2639 | 507 | DBUS_TYPE_INVALID)) | ||
2640 | 508 | return NULL; | ||
2641 | 509 | |||
2642 | 510 | caller = dbus_message_get_sender (message); | ||
2643 | 511 | unlock = gkd_secret_unlock_new (self, caller, NULL); | ||
2644 | 512 | for (i = 0; i < n_objpaths; ++i) | ||
2645 | 513 | gkd_secret_unlock_queue (unlock, objpaths[i]); | ||
2646 | 514 | dbus_free_string_array (objpaths); | ||
2647 | 515 | |||
2648 | 516 | /* So do we need to prompt? */ | ||
2649 | 517 | if (gkd_secret_unlock_have_queued (unlock)) { | ||
2650 | 518 | gkd_secret_service_publish_dispatch (self, caller, | ||
2651 | 519 | GKD_SECRET_DISPATCH (unlock)); | ||
2652 | 520 | path = gkd_secret_dispatch_get_object_path (GKD_SECRET_DISPATCH (unlock)); | ||
2653 | 521 | |||
2654 | 522 | /* No need to prompt */ | ||
2655 | 523 | } else { | ||
2656 | 524 | path = "/"; | ||
2657 | 525 | } | ||
2658 | 526 | |||
2659 | 527 | reply = dbus_message_new_method_return (message); | ||
2660 | 528 | objpaths = gkd_secret_unlock_get_results (unlock, &n_objpaths); | ||
2661 | 529 | dbus_message_append_args (reply, | ||
2662 | 530 | DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &objpaths, n_objpaths, | ||
2663 | 531 | DBUS_TYPE_OBJECT_PATH, &path, | ||
2664 | 532 | DBUS_TYPE_INVALID); | ||
2665 | 533 | |||
2666 | 534 | gkd_secret_unlock_reset_results (unlock); | ||
2667 | 535 | g_object_unref (unlock); | ||
2668 | 536 | |||
2669 | 537 | return reply; | ||
2670 | 538 | } | ||
2671 | 539 | |||
2672 | 540 | static DBusMessage* | ||
2673 | 541 | service_method_lock (GkdSecretService *self, DBusMessage *message) | ||
2674 | 542 | { | ||
2675 | 543 | DBusMessage *reply; | ||
2676 | 544 | const char *caller; | ||
2677 | 545 | const gchar *prompt; | ||
2678 | 546 | GckObject *collection; | ||
2679 | 547 | int n_objpaths, i; | ||
2680 | 548 | char **objpaths; | ||
2681 | 549 | GPtrArray *array; | ||
2682 | 550 | |||
2683 | 551 | if (!dbus_message_get_args (message, NULL, | ||
2684 | 552 | DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &objpaths, &n_objpaths, | ||
2685 | 553 | DBUS_TYPE_INVALID)) | ||
2686 | 554 | return NULL; | ||
2687 | 555 | |||
2688 | 556 | caller = dbus_message_get_sender (message); | ||
2689 | 557 | array = g_ptr_array_new (); | ||
2690 | 558 | for (i = 0; i < n_objpaths; ++i) { | ||
2691 | 559 | collection = gkd_secret_objects_lookup_collection (self->objects, caller, objpaths[i]); | ||
2692 | 560 | if (collection != NULL) { | ||
2693 | 561 | if (gkd_secret_lock (collection, NULL)) { | ||
2694 | 562 | g_ptr_array_add (array, objpaths[i]); | ||
2695 | 563 | gkd_secret_objects_emit_collection_locked (self->objects, | ||
2696 | 564 | collection); | ||
2697 | 565 | } | ||
2698 | 566 | g_object_unref (collection); | ||
2699 | 567 | } | ||
2700 | 568 | } | ||
2701 | 569 | |||
2702 | 570 | prompt = "/"; | ||
2703 | 571 | reply = dbus_message_new_method_return (message); | ||
2704 | 572 | dbus_message_append_args (reply, | ||
2705 | 573 | DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &array->pdata, array->len, | ||
2706 | 574 | DBUS_TYPE_OBJECT_PATH, &prompt, | ||
2707 | 575 | DBUS_TYPE_INVALID); | ||
2708 | 576 | |||
2709 | 577 | dbus_free_string_array (objpaths); | ||
2710 | 578 | return reply; | ||
2711 | 579 | } | ||
2712 | 580 | |||
2713 | 581 | static DBusMessage* | ||
2714 | 582 | service_method_change_lock (GkdSecretService *self, DBusMessage *message) | ||
2715 | 583 | { | ||
2716 | 584 | GkdSecretChange *change; | ||
2717 | 585 | DBusMessage *reply; | ||
2718 | 586 | const char *caller; | ||
2719 | 587 | const gchar *path; | ||
2720 | 588 | GckObject *collection; | ||
2721 | 589 | |||
2722 | 590 | caller = dbus_message_get_sender (message); | ||
2723 | 591 | if (!dbus_message_get_args (message, NULL, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID)) | ||
2724 | 592 | return NULL; | ||
2725 | 593 | |||
2726 | 594 | /* Make sure it exists */ | ||
2727 | 595 | collection = gkd_secret_objects_lookup_collection (self->objects, caller, path); | ||
2728 | 596 | if (!collection) | ||
2729 | 597 | return dbus_message_new_error (message, SECRET_ERROR_NO_SUCH_OBJECT, | ||
2730 | 598 | "The collection does not exist"); | ||
2731 | 599 | g_object_unref (collection); | ||
2732 | 600 | |||
2733 | 601 | change = gkd_secret_change_new (self, caller, path); | ||
2734 | 602 | path = gkd_secret_dispatch_get_object_path (GKD_SECRET_DISPATCH (change)); | ||
2735 | 603 | gkd_secret_service_publish_dispatch (self, caller, | ||
2736 | 604 | GKD_SECRET_DISPATCH (change)); | ||
2737 | 605 | |||
2738 | 606 | reply = dbus_message_new_method_return (message); | ||
2739 | 607 | dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); | ||
2740 | 608 | |||
2741 | 609 | g_object_unref (change); | ||
2742 | 610 | return reply; | ||
2743 | 611 | } | ||
2744 | 612 | |||
2745 | 613 | static DBusMessage* | ||
2746 | 614 | service_method_read_alias (GkdSecretService *self, DBusMessage *message) | ||
2747 | 615 | { | ||
2748 | 616 | DBusMessage *reply; | ||
2749 | 617 | const char *alias; | ||
2750 | 618 | gchar *path = NULL; | ||
2751 | 619 | const gchar *identifier; | ||
2752 | 620 | GckObject *collection = NULL; | ||
2753 | 621 | |||
2754 | 622 | if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &alias, DBUS_TYPE_INVALID)) | ||
2755 | 623 | return NULL; | ||
2756 | 624 | |||
2757 | 625 | identifier = gkd_secret_service_get_alias (self, alias); | ||
2758 | 626 | if (identifier) | ||
2759 | 627 | path = gkd_secret_util_build_path (SECRET_COLLECTION_PREFIX, identifier, -1); | ||
2760 | 628 | |||
2761 | 629 | /* Make sure it actually exists */ | ||
2762 | 630 | if (path) | ||
2763 | 631 | collection = gkd_secret_objects_lookup_collection (self->objects, | ||
2764 | 632 | dbus_message_get_sender (message), path); | ||
2765 | 633 | if (collection == NULL) { | ||
2766 | 634 | g_free (path); | ||
2767 | 635 | path = NULL; | ||
2768 | 636 | } else { | ||
2769 | 637 | g_object_unref (collection); | ||
2770 | 638 | } | ||
2771 | 639 | |||
2772 | 640 | reply = dbus_message_new_method_return (message); | ||
2773 | 641 | if (path == NULL) | ||
2774 | 642 | path = g_strdup ("/"); | ||
2775 | 643 | dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); | ||
2776 | 644 | g_free (path); | ||
2777 | 645 | |||
2778 | 646 | return reply; | ||
2779 | 647 | } | ||
2780 | 648 | |||
2781 | 649 | static DBusMessage* | ||
2782 | 650 | service_method_set_alias (GkdSecretService *self, DBusMessage *message) | ||
2783 | 651 | { | ||
2784 | 652 | GckObject *collection; | ||
2785 | 653 | gchar *identifier; | ||
2786 | 654 | const char *alias; | ||
2787 | 655 | const char *path; | ||
2788 | 656 | |||
2789 | 657 | if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &alias, | ||
2790 | 658 | DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID)) | ||
2791 | 659 | return NULL; | ||
2792 | 660 | |||
2793 | 661 | g_return_val_if_fail (alias, NULL); | ||
2794 | 662 | g_return_val_if_fail (path, NULL); | ||
2795 | 663 | |||
2796 | 664 | if (!g_str_equal (alias, "default")) | ||
2797 | 665 | return dbus_message_new_error (message, DBUS_ERROR_NOT_SUPPORTED, | ||
2798 | 666 | "Only the 'default' alias is supported"); | ||
2799 | 667 | |||
2800 | 668 | /* No default collection */ | ||
2801 | 669 | if (g_str_equal (path, "/")) { | ||
2802 | 670 | identifier = g_strdup (""); | ||
2803 | 671 | |||
2804 | 672 | /* Find a collection with that path */ | ||
2805 | 673 | } else { | ||
2806 | 674 | if (!object_path_has_prefix (path, SECRET_COLLECTION_PREFIX) || | ||
2807 | 675 | !gkd_secret_util_parse_path (path, &identifier, NULL)) | ||
2808 | 676 | return dbus_message_new_error (message, DBUS_ERROR_INVALID_ARGS, | ||
2809 | 677 | "Invalid collection object path"); | ||
2810 | 678 | |||
2811 | 679 | collection = gkd_secret_objects_lookup_collection (self->objects, | ||
2812 | 680 | dbus_message_get_sender (message), path); | ||
2813 | 681 | if (collection == NULL) { | ||
2814 | 682 | g_free (identifier); | ||
2815 | 683 | return dbus_message_new_error (message, SECRET_ERROR_NO_SUCH_OBJECT, | ||
2816 | 684 | "No such collection exists"); | ||
2817 | 685 | } | ||
2818 | 686 | |||
2819 | 687 | g_object_unref (collection); | ||
2820 | 688 | } | ||
2821 | 689 | |||
2822 | 690 | gkd_secret_service_set_alias (self, alias, identifier); | ||
2823 | 691 | g_free (identifier); | ||
2824 | 692 | |||
2825 | 693 | return dbus_message_new_method_return (message); | ||
2826 | 694 | } | ||
2827 | 695 | |||
2828 | 696 | static DBusMessage* | ||
2829 | 697 | service_method_create_with_master_password (GkdSecretService *self, DBusMessage *message) | ||
2830 | 698 | { | ||
2831 | 699 | GckBuilder builder = GCK_BUILDER_INIT; | ||
2832 | 700 | DBusError derr = DBUS_ERROR_INIT; | ||
2833 | 701 | DBusMessageIter iter, array; | ||
2834 | 702 | DBusMessage *reply = NULL; | ||
2835 | 703 | GkdSecretSecret *secret = NULL; | ||
2836 | 704 | GckAttributes *attrs = NULL; | ||
2837 | 705 | GError *error = NULL; | ||
2838 | 706 | gchar *path; | ||
2839 | 707 | |||
2840 | 708 | /* Parse the incoming message */ | ||
2841 | 709 | if (!dbus_message_has_signature (message, "a{sv}(oayays)")) | ||
2842 | 710 | return NULL; | ||
2843 | 711 | if (!dbus_message_iter_init (message, &iter)) | ||
2844 | 712 | g_return_val_if_reached (NULL); | ||
2845 | 713 | dbus_message_iter_recurse (&iter, &array); | ||
2846 | 714 | if (!gkd_secret_property_parse_all (&array, SECRET_COLLECTION_INTERFACE, &builder)) { | ||
2847 | 715 | gck_builder_clear (&builder); | ||
2848 | 716 | return dbus_message_new_error (message, DBUS_ERROR_INVALID_ARGS, | ||
2849 | 717 | "Invalid properties argument"); | ||
2850 | 718 | } | ||
2851 | 719 | dbus_message_iter_next (&iter); | ||
2852 | 720 | secret = gkd_secret_secret_parse (self, message, &iter, &derr); | ||
2853 | 721 | if (secret == NULL) { | ||
2854 | 722 | gck_builder_clear (&builder); | ||
2855 | 723 | return gkd_secret_error_to_reply (message, &derr); | ||
2856 | 724 | } | ||
2857 | 725 | |||
2858 | 726 | gck_builder_add_boolean (&builder, CKA_TOKEN, TRUE); | ||
2859 | 727 | attrs = gck_attributes_ref_sink (gck_builder_end (&builder)); | ||
2860 | 728 | path = gkd_secret_create_with_secret (attrs, secret, &error); | ||
2861 | 729 | gck_attributes_unref (attrs); | ||
2862 | 730 | gkd_secret_secret_free (secret); | ||
2863 | 731 | |||
2864 | 732 | if (path == NULL) | ||
2865 | 733 | return gkd_secret_propagate_error (message, "Couldn't create collection", error); | ||
2866 | 734 | |||
2867 | 735 | /* Notify the callers that a collection was created */ | ||
2868 | 736 | gkd_secret_service_emit_collection_created (self, path); | ||
2869 | 737 | |||
2870 | 738 | reply = dbus_message_new_method_return (message); | ||
2871 | 739 | dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); | ||
2872 | 740 | g_free (path); | ||
2873 | 741 | |||
2874 | 742 | return reply; | ||
2875 | 743 | } | ||
2876 | 744 | |||
2877 | 745 | static DBusMessage* | ||
2878 | 746 | service_method_change_with_master_password (GkdSecretService *self, DBusMessage *message) | ||
2879 | 747 | { | ||
2880 | 748 | DBusError derr = DBUS_ERROR_INIT; | ||
2881 | 749 | GkdSecretSecret *original, *master; | ||
2882 | 750 | GckObject *collection; | ||
2883 | 751 | DBusMessageIter iter; | ||
2884 | 752 | DBusMessage *reply; | ||
2885 | 753 | GError *error = NULL; | ||
2886 | 754 | const gchar *path; | ||
2887 | 755 | |||
2888 | 756 | /* Parse the incoming message */ | ||
2889 | 757 | if (!dbus_message_has_signature (message, "o(oayays)(oayays)")) | ||
2890 | 758 | return NULL; | ||
2891 | 759 | if (!dbus_message_iter_init (message, &iter)) | ||
2892 | 760 | g_return_val_if_reached (NULL); | ||
2893 | 761 | dbus_message_iter_get_basic (&iter, &path); | ||
2894 | 762 | dbus_message_iter_next (&iter); | ||
2895 | 763 | original = gkd_secret_secret_parse (self, message, &iter, &derr); | ||
2896 | 764 | if (original == NULL) | ||
2897 | 765 | return gkd_secret_error_to_reply (message, &derr); | ||
2898 | 766 | dbus_message_iter_next (&iter); | ||
2899 | 767 | master = gkd_secret_secret_parse (self, message, &iter, &derr); | ||
2900 | 768 | if (master == NULL) { | ||
2901 | 769 | gkd_secret_secret_free (original); | ||
2902 | 770 | return gkd_secret_error_to_reply (message, &derr); | ||
2903 | 771 | } | ||
2904 | 772 | |||
2905 | 773 | /* Make sure we have such a collection */ | ||
2906 | 774 | collection = gkd_secret_objects_lookup_collection (self->objects, | ||
2907 | 775 | dbus_message_get_sender (message), | ||
2908 | 776 | path); | ||
2909 | 777 | |||
2910 | 778 | /* No such collection */ | ||
2911 | 779 | if (collection == NULL) | ||
2912 | 780 | reply = dbus_message_new_error (message, SECRET_ERROR_NO_SUCH_OBJECT, | ||
2913 | 781 | "The collection does not exist"); | ||
2914 | 782 | |||
2915 | 783 | /* Success */ | ||
2916 | 784 | else if (gkd_secret_change_with_secrets (collection, NULL, original, master, &error)) | ||
2917 | 785 | reply = dbus_message_new_method_return (message); | ||
2918 | 786 | |||
2919 | 787 | /* Failure */ | ||
2920 | 788 | else | ||
2921 | 789 | reply = gkd_secret_propagate_error (message, "Couldn't change collection password", error); | ||
2922 | 790 | |||
2923 | 791 | gkd_secret_secret_free (original); | ||
2924 | 792 | gkd_secret_secret_free (master); | ||
2925 | 793 | |||
2926 | 794 | if (collection) | ||
2927 | 795 | g_object_unref (collection); | ||
2928 | 796 | |||
2929 | 797 | return reply; | ||
2930 | 798 | } | ||
2931 | 799 | |||
2932 | 800 | static DBusMessage* | ||
2933 | 801 | service_method_unlock_with_master_password (GkdSecretService *self, DBusMessage *message) | ||
2934 | 802 | { | ||
2935 | 803 | DBusError derr = DBUS_ERROR_INIT; | ||
2936 | 804 | GkdSecretSecret *master; | ||
2937 | 805 | GError *error = NULL; | ||
2938 | 806 | GckObject *collection; | ||
2939 | 807 | DBusMessageIter iter; | ||
2940 | 808 | DBusMessage *reply; | ||
2941 | 809 | const gchar *path; | ||
2942 | 810 | |||
2943 | 811 | /* Parse the incoming message */ | ||
2944 | 812 | if (!dbus_message_has_signature (message, "o(oayays)")) | ||
2945 | 813 | return NULL; | ||
2946 | 814 | if (!dbus_message_iter_init (message, &iter)) | ||
2947 | 815 | g_return_val_if_reached (NULL); | ||
2948 | 816 | dbus_message_iter_get_basic (&iter, &path); | ||
2949 | 817 | dbus_message_iter_next (&iter); | ||
2950 | 818 | master = gkd_secret_secret_parse (self, message, &iter, &derr); | ||
2951 | 819 | if (master == NULL) | ||
2952 | 820 | return gkd_secret_error_to_reply (message, &derr); | ||
2953 | 821 | |||
2954 | 822 | /* Make sure we have such a collection */ | ||
2955 | 823 | collection = gkd_secret_objects_lookup_collection (self->objects, | ||
2956 | 824 | dbus_message_get_sender (message), | ||
2957 | 825 | path); | ||
2958 | 826 | |||
2959 | 827 | /* No such collection */ | ||
2960 | 828 | if (collection == NULL) { | ||
2961 | 829 | reply = dbus_message_new_error (message, SECRET_ERROR_NO_SUCH_OBJECT, | ||
2962 | 830 | "The collection does not exist"); | ||
2963 | 831 | |||
2964 | 832 | /* Success */ | ||
2965 | 833 | } else if (gkd_secret_unlock_with_secret (collection, master, &error)) { | ||
2966 | 834 | reply = dbus_message_new_method_return (message); | ||
2967 | 835 | gkd_secret_objects_emit_collection_locked (self->objects, collection); | ||
2968 | 836 | |||
2969 | 837 | /* Failure */ | ||
2970 | 838 | } else { | ||
2971 | 839 | reply = gkd_secret_propagate_error (message, "Couldn't unlock collection", error); | ||
2972 | 840 | } | ||
2973 | 841 | |||
2974 | 842 | gkd_secret_secret_free (master); | ||
2975 | 843 | |||
2976 | 844 | if (collection) | ||
2977 | 845 | g_object_unref (collection); | ||
2978 | 846 | |||
2979 | 847 | return reply; | ||
2980 | 848 | } | ||
2981 | 849 | |||
2982 | 850 | static void | ||
2983 | 851 | on_each_path_append_to_array (GkdSecretObjects *self, | ||
2984 | 852 | const gchar *path, | ||
2985 | 853 | GckObject *object, | ||
2986 | 854 | gpointer user_data) | ||
2987 | 855 | { | ||
2988 | 856 | GPtrArray *array = user_data; | ||
2989 | 857 | g_ptr_array_add (array, g_strdup (path)); | ||
2990 | 858 | } | ||
2991 | 859 | |||
2992 | 860 | static DBusMessage * | ||
2993 | 861 | service_introspect (GkdSecretService *self, | ||
2994 | 862 | DBusMessage *message) | ||
2995 | 863 | { | ||
2996 | 864 | GPtrArray *names; | ||
2997 | 865 | DBusMessage *reply; | ||
2998 | 866 | ServiceClient *client; | ||
2999 | 867 | const gchar *caller; | ||
3000 | 868 | const gchar *path; | ||
3001 | 869 | GHashTableIter iter; | ||
3002 | 870 | |||
3003 | 871 | names = g_ptr_array_new_with_free_func (g_free); | ||
3004 | 872 | gkd_secret_objects_foreach_collection (self->objects, message, | ||
3005 | 873 | on_each_path_append_to_array, | ||
3006 | 874 | names); | ||
3007 | 875 | |||
3008 | 876 | /* Lookup all sessions and prompts for this client */ | ||
3009 | 877 | caller = dbus_message_get_sender (message); | ||
3010 | 878 | if (caller != NULL) { | ||
3011 | 879 | client = g_hash_table_lookup (self->clients, caller); | ||
3012 | 880 | if (client != NULL) { | ||
3013 | 881 | g_hash_table_iter_init (&iter, client->dispatch); | ||
3014 | 882 | while (g_hash_table_iter_next (&iter, (gpointer *)&path, NULL)) | ||
3015 | 883 | g_ptr_array_add (names, g_strdup (path)); | ||
3016 | 884 | } | ||
3017 | 885 | } | ||
3018 | 886 | |||
3019 | 887 | g_ptr_array_add (names, NULL); | ||
3020 | 888 | |||
3021 | 889 | reply = gkd_dbus_introspect_handle (message, gkd_secret_introspect_service, | ||
3022 | 890 | (const gchar **)names->pdata); | ||
3023 | 891 | |||
3024 | 892 | g_ptr_array_unref (names); | ||
3025 | 893 | return reply; | ||
3026 | 894 | } | ||
3027 | 895 | |||
3028 | 896 | static DBusMessage* | ||
3029 | 897 | service_message_handler (GkdSecretService *self, DBusMessage *message) | ||
3030 | 898 | { | ||
3031 | 899 | g_return_val_if_fail (message, NULL); | ||
3032 | 900 | g_return_val_if_fail (GKD_SECRET_IS_SERVICE (self), NULL); | ||
3033 | 901 | |||
3034 | 902 | /* org.freedesktop.Secret.Service.OpenSession() */ | ||
3035 | 903 | if (dbus_message_is_method_call (message, SECRET_SERVICE_INTERFACE, "OpenSession")) | ||
3036 | 904 | return service_method_open_session (self, message); | ||
3037 | 905 | |||
3038 | 906 | /* org.freedesktop.Secret.Service.CreateCollection() */ | ||
3039 | 907 | if (dbus_message_is_method_call (message, SECRET_SERVICE_INTERFACE, "CreateCollection")) | ||
3040 | 908 | return service_method_create_collection (self, message); | ||
3041 | 909 | |||
3042 | 910 | /* org.freedesktop.Secret.Service.LockService() */ | ||
3043 | 911 | if (dbus_message_is_method_call (message, SECRET_SERVICE_INTERFACE, "LockService")) | ||
3044 | 912 | return service_method_lock_service (self, message); | ||
3045 | 913 | |||
3046 | 914 | /* org.freedesktop.Secret.Service.SearchItems() */ | ||
3047 | 915 | if (dbus_message_is_method_call (message, SECRET_SERVICE_INTERFACE, "SearchItems")) | ||
3048 | 916 | return gkd_secret_objects_handle_search_items (self->objects, message, NULL); | ||
3049 | 917 | |||
3050 | 918 | /* org.freedesktop.Secret.Service.GetSecrets() */ | ||
3051 | 919 | if (dbus_message_is_method_call (message, SECRET_SERVICE_INTERFACE, "GetSecrets")) | ||
3052 | 920 | return gkd_secret_objects_handle_get_secrets (self->objects, message); | ||
3053 | 921 | |||
3054 | 922 | /* org.freedesktop.Secret.Service.Unlock() */ | ||
3055 | 923 | if (dbus_message_is_method_call (message, SECRET_SERVICE_INTERFACE, "Unlock")) | ||
3056 | 924 | return service_method_unlock (self, message); | ||
3057 | 925 | |||
3058 | 926 | /* org.freedesktop.Secret.Service.Lock() */ | ||
3059 | 927 | if (dbus_message_is_method_call (message, SECRET_SERVICE_INTERFACE, "Lock")) | ||
3060 | 928 | return service_method_lock (self, message); | ||
3061 | 929 | |||
3062 | 930 | /* org.gnome.keyring.InternalUnsupportedGuiltRiddenInterface.ChangeWithPrompt() */ | ||
3063 | 931 | if (dbus_message_is_method_call (message, INTERNAL_SERVICE_INTERFACE, "ChangeWithPrompt") || | ||
3064 | 932 | dbus_message_is_method_call (message, SECRET_SERVICE_INTERFACE, "ChangeLock")) | ||
3065 | 933 | return service_method_change_lock (self, message); | ||
3066 | 934 | |||
3067 | 935 | /* org.freedesktop.Secret.Service.ReadAlias() */ | ||
3068 | 936 | if (dbus_message_is_method_call (message, SECRET_SERVICE_INTERFACE, "ReadAlias")) | ||
3069 | 937 | return service_method_read_alias (self, message); | ||
3070 | 938 | |||
3071 | 939 | /* org.freedesktop.Secret.Service.SetAlias() */ | ||
3072 | 940 | if (dbus_message_is_method_call (message, SECRET_SERVICE_INTERFACE, "SetAlias")) | ||
3073 | 941 | return service_method_set_alias (self, message); | ||
3074 | 942 | |||
3075 | 943 | /* org.gnome.keyring.InternalUnsupportedGuiltRiddenInterface.CreateWithMasterPassword */ | ||
3076 | 944 | if (dbus_message_is_method_call (message, INTERNAL_SERVICE_INTERFACE, "CreateWithMasterPassword")) | ||
3077 | 945 | return service_method_create_with_master_password (self, message); | ||
3078 | 946 | |||
3079 | 947 | /* org.gnome.keyring.InternalUnsupportedGuiltRiddenInterface.ChangeWithMasterPassword() */ | ||
3080 | 948 | if (dbus_message_is_method_call (message, INTERNAL_SERVICE_INTERFACE, "ChangeWithMasterPassword")) | ||
3081 | 949 | return service_method_change_with_master_password (self, message); | ||
3082 | 950 | |||
3083 | 951 | /* org.gnome.keyring.InternalUnsupportedGuiltRiddenInterface.UnlockWithMasterPassword() */ | ||
3084 | 952 | if (dbus_message_is_method_call (message, INTERNAL_SERVICE_INTERFACE, "UnlockWithMasterPassword")) | ||
3085 | 953 | return service_method_unlock_with_master_password (self, message); | ||
3086 | 954 | |||
3087 | 955 | /* org.freedesktop.DBus.Properties.Get() */ | ||
3088 | 956 | if (dbus_message_is_method_call (message, DBUS_INTERFACE_PROPERTIES, "Get")) | ||
3089 | 957 | return service_property_get (self, message); | ||
3090 | 958 | |||
3091 | 959 | /* org.freedesktop.DBus.Properties.Set() */ | ||
3092 | 960 | else if (dbus_message_is_method_call (message, DBUS_INTERFACE_PROPERTIES, "Set")) | ||
3093 | 961 | return service_property_set (self, message); | ||
3094 | 962 | |||
3095 | 963 | /* org.freedesktop.DBus.Properties.GetAll() */ | ||
3096 | 964 | else if (dbus_message_is_method_call (message, DBUS_INTERFACE_PROPERTIES, "GetAll")) | ||
3097 | 965 | return service_property_getall (self, message); | ||
3098 | 966 | |||
3099 | 967 | /* org.freedesktop.DBus.Introspectable.Introspect() */ | ||
3100 | 968 | else if (dbus_message_has_interface (message, DBUS_INTERFACE_INTROSPECTABLE)) | ||
3101 | 969 | return service_introspect (self, message); | ||
3102 | 970 | |||
3103 | 971 | return NULL; | ||
3104 | 972 | } | ||
3105 | 973 | |||
3106 | 974 | static gboolean | ||
3107 | 975 | root_dispatch_message (GkdSecretService *self, | ||
3108 | 976 | DBusMessage *message) | ||
3109 | 977 | { | ||
3110 | 978 | DBusMessage *reply = NULL; | ||
3111 | 979 | |||
3112 | 980 | if (dbus_message_has_interface (message, DBUS_INTERFACE_INTROSPECTABLE)) | ||
3113 | 981 | reply = gkd_dbus_introspect_handle (message, gkd_secret_introspect_root, NULL); | ||
3114 | 982 | |||
3115 | 983 | if (reply != NULL) { | ||
3116 | 984 | dbus_connection_send (self->connection, reply, NULL); | ||
3117 | 985 | dbus_message_unref (reply); | ||
3118 | 986 | return TRUE; | ||
3119 | 987 | } | ||
3120 | 988 | |||
3121 | 989 | return FALSE; | ||
3122 | 990 | } | ||
3123 | 991 | |||
3124 | 992 | static void | ||
3125 | 993 | service_dispatch_message (GkdSecretService *self, DBusMessage *message) | ||
3126 | 994 | { | ||
3127 | 995 | DBusMessage *reply = NULL; | ||
3128 | 996 | const gchar *caller; | ||
3129 | 997 | ServiceClient *client; | ||
3130 | 998 | const gchar *path; | ||
3131 | 999 | gpointer object; | ||
3132 | 1000 | |||
3133 | 1001 | g_assert (GKD_SECRET_IS_SERVICE (self)); | ||
3134 | 1002 | g_assert (message); | ||
3135 | 1003 | |||
3136 | 1004 | /* The first thing we do is try to allocate a client context */ | ||
3137 | 1005 | caller = dbus_message_get_sender (message); | ||
3138 | 1006 | if (caller == NULL) { | ||
3139 | 1007 | reply = dbus_message_new_error (message, DBUS_ERROR_FAILED, | ||
3140 | 1008 | "Could not not identify calling client application"); | ||
3141 | 1009 | dbus_connection_send (self->connection, reply, NULL); | ||
3142 | 1010 | dbus_message_unref (reply); | ||
3143 | 1011 | return; | ||
3144 | 1012 | } | ||
3145 | 1013 | |||
3146 | 1014 | client = g_hash_table_lookup (self->clients, caller); | ||
3147 | 1015 | if (client == NULL) { | ||
3148 | 1016 | initialize_service_client (self, message); | ||
3149 | 1017 | return; /* This function called again, when client is initialized */ | ||
3150 | 1018 | } | ||
3151 | 1019 | |||
3152 | 1020 | path = dbus_message_get_path (message); | ||
3153 | 1021 | g_return_if_fail (path); | ||
3154 | 1022 | |||
3155 | 1023 | /* Dispatched to a session or prompt */ | ||
3156 | 1024 | if (object_path_has_prefix (path, SECRET_SESSION_PREFIX) || | ||
3157 | 1025 | object_path_has_prefix (path, SECRET_PROMPT_PREFIX)) { | ||
3158 | 1026 | object = g_hash_table_lookup (client->dispatch, path); | ||
3159 | 1027 | if (object == NULL) | ||
3160 | 1028 | reply = gkd_secret_error_no_such_object (message); | ||
3161 | 1029 | else | ||
3162 | 1030 | reply = gkd_secret_dispatch_message (GKD_SECRET_DISPATCH (object), message); | ||
3163 | 1031 | |||
3164 | 1032 | /* Dispatched to a collection, off it goes */ | ||
3165 | 1033 | } else if (object_path_has_prefix (path, SECRET_COLLECTION_PREFIX) || | ||
3166 | 1034 | object_path_has_prefix (path, SECRET_ALIAS_PREFIX)) { | ||
3167 | 1035 | reply = gkd_secret_objects_dispatch (self->objects, message); | ||
3168 | 1036 | |||
3169 | 1037 | /* Addressed to the service */ | ||
3170 | 1038 | } else if (g_str_equal (path, SECRET_SERVICE_PATH)) { | ||
3171 | 1039 | reply = service_message_handler (self, message); | ||
3172 | 1040 | } | ||
3173 | 1041 | |||
3174 | 1042 | /* Should we send an error? */ | ||
3175 | 1043 | if (!reply && dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_CALL) { | ||
3176 | 1044 | if (!dbus_message_get_no_reply (message)) { | ||
3177 | 1045 | reply = dbus_message_new_error_printf (message, DBUS_ERROR_UNKNOWN_METHOD, | ||
3178 | 1046 | "Method \"%s\" with signature \"%s\" on interface \"%s\" doesn't exist\n", | ||
3179 | 1047 | dbus_message_get_member (message), | ||
3180 | 1048 | dbus_message_get_signature (message), | ||
3181 | 1049 | dbus_message_get_interface (message)); | ||
3182 | 1050 | } | ||
3183 | 1051 | } | ||
3184 | 1052 | |||
3185 | 1053 | if (reply) { | ||
3186 | 1054 | dbus_connection_send (self->connection, reply, NULL); | ||
3187 | 1055 | dbus_message_unref (reply); | ||
3188 | 1056 | } | ||
3189 | 1057 | } | ||
3190 | 1058 | |||
3191 | 1059 | static DBusHandlerResult | ||
3192 | 1060 | gkd_secret_service_filter_handler (DBusConnection *conn, DBusMessage *message, gpointer user_data) | ||
3193 | 1061 | { | ||
3194 | 1062 | GkdSecretService *self = user_data; | ||
3195 | 1063 | const gchar *object_name; | ||
3196 | 1064 | const gchar *old_owner; | ||
3197 | 1065 | const gchar *new_owner; | ||
3198 | 1066 | const gchar *path; | ||
3199 | 1067 | const gchar *interface; | ||
3200 | 1068 | |||
3201 | 1069 | g_return_val_if_fail (conn && message, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); | ||
3202 | 1070 | g_return_val_if_fail (GKD_SECRET_IS_SERVICE (self), DBUS_HANDLER_RESULT_NOT_YET_HANDLED); | ||
3203 | 1071 | |||
3204 | 1072 | /* org.freedesktop.DBus.NameOwnerChanged(STRING name, STRING old_owner, STRING new_owner) */ | ||
3205 | 1073 | if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged") && | ||
3206 | 1074 | dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &object_name, | ||
3207 | 1075 | DBUS_TYPE_STRING, &old_owner, DBUS_TYPE_STRING, &new_owner, | ||
3208 | 1076 | DBUS_TYPE_INVALID)) { | ||
3209 | 1077 | |||
3210 | 1078 | /* | ||
3211 | 1079 | * A peer is connecting or disconnecting from the bus, | ||
3212 | 1080 | * remove any client info, when client gone. | ||
3213 | 1081 | */ | ||
3214 | 1082 | |||
3215 | 1083 | g_return_val_if_fail (object_name && new_owner, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); | ||
3216 | 1084 | if (g_str_equal (new_owner, "") && object_name[0] == ':') | ||
3217 | 1085 | g_hash_table_remove (self->clients, object_name); | ||
3218 | 1086 | |||
3219 | 1087 | return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | ||
3220 | 1088 | } | ||
3221 | 1089 | |||
3222 | 1090 | /* | ||
3223 | 1091 | * If the path is a within our object tree, then we do our own dispatch. | ||
3224 | 1092 | */ | ||
3225 | 1093 | path = dbus_message_get_path (message); | ||
3226 | 1094 | switch (dbus_message_get_type (message)) { | ||
3227 | 1095 | |||
3228 | 1096 | /* Dispatch any method call on our interfaces, for our objects */ | ||
3229 | 1097 | case DBUS_MESSAGE_TYPE_METHOD_CALL: | ||
3230 | 1098 | if (path != NULL && g_str_equal (path, "/")) { | ||
3231 | 1099 | if (root_dispatch_message (self, message)) | ||
3232 | 1100 | return DBUS_HANDLER_RESULT_HANDLED; | ||
3233 | 1101 | } | ||
3234 | 1102 | |||
3235 | 1103 | if (object_path_has_prefix (path, SECRET_SERVICE_PATH)) { | ||
3236 | 1104 | interface = dbus_message_get_interface (message); | ||
3237 | 1105 | if (interface == NULL || | ||
3238 | 1106 | g_str_has_prefix (interface, SECRET_INTERFACE_PREFIX) || | ||
3239 | 1107 | g_str_equal (interface, DBUS_INTERFACE_PROPERTIES) || | ||
3240 | 1108 | g_str_equal (interface, INTERNAL_SERVICE_INTERFACE) || | ||
3241 | 1109 | g_str_equal (interface, DBUS_INTERFACE_INTROSPECTABLE)) { | ||
3242 | 1110 | service_dispatch_message (self, message); | ||
3243 | 1111 | return DBUS_HANDLER_RESULT_HANDLED; | ||
3244 | 1112 | } | ||
3245 | 1113 | } | ||
3246 | 1114 | break; | ||
3247 | 1115 | |||
3248 | 1116 | /* Dispatch any signal for one of our objects */ | ||
3249 | 1117 | case DBUS_MESSAGE_TYPE_SIGNAL: | ||
3250 | 1118 | if (object_path_has_prefix (path, SECRET_SERVICE_PATH)) { | ||
3251 | 1119 | service_dispatch_message (self, message); | ||
3252 | 1120 | return DBUS_HANDLER_RESULT_HANDLED; | ||
3253 | 1121 | } | ||
3254 | 1122 | break; | ||
3255 | 1123 | |||
3256 | 1124 | default: | ||
3257 | 1125 | break; | ||
3258 | 1126 | } | ||
3259 | 1127 | |||
3260 | 1128 | return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | ||
3261 | 1129 | } | ||
3262 | 1130 | |||
3263 | 1131 | /* ----------------------------------------------------------------------------- | ||
3264 | 1132 | * OBJECT | ||
3265 | 1133 | */ | ||
3266 | 1134 | |||
3267 | 1135 | static GObject* | ||
3268 | 1136 | gkd_secret_service_constructor (GType type, guint n_props, GObjectConstructParam *props) | ||
3269 | 1137 | { | ||
3270 | 1138 | GkdSecretService *self = GKD_SECRET_SERVICE (G_OBJECT_CLASS (gkd_secret_service_parent_class)->constructor(type, n_props, props)); | ||
3271 | 1139 | DBusError error = DBUS_ERROR_INIT; | ||
3272 | 1140 | GckSlot *slot = NULL; | ||
3273 | 1141 | guint i; | ||
3274 | 1142 | |||
3275 | 1143 | g_return_val_if_fail (self, NULL); | ||
3276 | 1144 | g_return_val_if_fail (self->connection, NULL); | ||
3277 | 1145 | |||
3278 | 1146 | /* Find the pkcs11-slot parameter */ | ||
3279 | 1147 | for (i = 0; !slot && i < n_props; ++i) { | ||
3280 | 1148 | if (g_str_equal (props[i].pspec->name, "pkcs11-slot")) | ||
3281 | 1149 | slot = g_value_get_object (props[i].value); | ||
3282 | 1150 | } | ||
3283 | 1151 | |||
3284 | 1152 | /* Create our objects proxy */ | ||
3285 | 1153 | g_return_val_if_fail (GCK_IS_SLOT (slot), NULL); | ||
3286 | 1154 | self->objects = g_object_new (GKD_SECRET_TYPE_OBJECTS, | ||
3287 | 1155 | "pkcs11-slot", slot, "service", self, NULL); | ||
3288 | 1156 | |||
3289 | 1157 | /* Register for signals that let us know when clients leave the bus */ | ||
3290 | 1158 | self->match_rule = g_strdup_printf ("type='signal',member=NameOwnerChanged," | ||
3291 | 1159 | "interface='" DBUS_INTERFACE_DBUS "'"); | ||
3292 | 1160 | dbus_bus_add_match (self->connection, self->match_rule, &error); | ||
3293 | 1161 | if (dbus_error_is_set (&error)) { | ||
3294 | 1162 | g_warning ("couldn't listen for NameOwnerChanged signal on session bus: %s", error.message); | ||
3295 | 1163 | dbus_error_free (&error); | ||
3296 | 1164 | g_free (self->match_rule); | ||
3297 | 1165 | self->match_rule = NULL; | ||
3298 | 1166 | } | ||
3299 | 1167 | |||
3300 | 1168 | if (!dbus_connection_add_filter (self->connection, gkd_secret_service_filter_handler, self, NULL)) | ||
3301 | 1169 | g_return_val_if_reached (NULL); | ||
3302 | 1170 | |||
3303 | 1171 | return G_OBJECT (self); | ||
3304 | 1172 | } | ||
3305 | 1173 | |||
3306 | 1174 | static void | ||
3307 | 1175 | gkd_secret_service_init (GkdSecretService *self) | ||
3308 | 1176 | { | ||
3309 | 1177 | self->clients = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, free_client); | ||
3310 | 1178 | self->aliases = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); | ||
3311 | 1179 | } | ||
3312 | 1180 | |||
3313 | 1181 | static void | ||
3314 | 1182 | gkd_secret_service_dispose (GObject *obj) | ||
3315 | 1183 | { | ||
3316 | 1184 | GkdSecretService *self = GKD_SECRET_SERVICE (obj); | ||
3317 | 1185 | |||
3318 | 1186 | if (self->match_rule) { | ||
3319 | 1187 | g_return_if_fail (self->connection); | ||
3320 | 1188 | dbus_bus_remove_match (self->connection, self->match_rule, NULL); | ||
3321 | 1189 | g_free (self->match_rule); | ||
3322 | 1190 | self->match_rule = NULL; | ||
3323 | 1191 | } | ||
3324 | 1192 | |||
3325 | 1193 | /* Closes all the clients */ | ||
3326 | 1194 | g_hash_table_remove_all (self->clients); | ||
3327 | 1195 | |||
3328 | 1196 | /* Hide all the objects */ | ||
3329 | 1197 | if (self->objects) { | ||
3330 | 1198 | g_object_run_dispose (G_OBJECT (self->objects)); | ||
3331 | 1199 | g_object_unref (self->objects); | ||
3332 | 1200 | self->objects = NULL; | ||
3333 | 1201 | } | ||
3334 | 1202 | |||
3335 | 1203 | if (self->connection) { | ||
3336 | 1204 | dbus_connection_remove_filter (self->connection, gkd_secret_service_filter_handler, self); | ||
3337 | 1205 | dbus_connection_unref (self->connection); | ||
3338 | 1206 | self->connection = NULL; | ||
3339 | 1207 | } | ||
3340 | 1208 | |||
3341 | 1209 | if (self->internal_session) { | ||
3342 | 1210 | dispose_and_unref (self->internal_session); | ||
3343 | 1211 | self->internal_session = NULL; | ||
3344 | 1212 | } | ||
3345 | 1213 | |||
3346 | 1214 | G_OBJECT_CLASS (gkd_secret_service_parent_class)->dispose (obj); | ||
3347 | 1215 | } | ||
3348 | 1216 | |||
3349 | 1217 | static void | ||
3350 | 1218 | gkd_secret_service_finalize (GObject *obj) | ||
3351 | 1219 | { | ||
3352 | 1220 | GkdSecretService *self = GKD_SECRET_SERVICE (obj); | ||
3353 | 1221 | |||
3354 | 1222 | g_assert (g_hash_table_size (self->clients) == 0); | ||
3355 | 1223 | g_hash_table_destroy (self->clients); | ||
3356 | 1224 | self->clients = NULL; | ||
3357 | 1225 | |||
3358 | 1226 | g_hash_table_destroy (self->aliases); | ||
3359 | 1227 | self->aliases = NULL; | ||
3360 | 1228 | |||
3361 | 1229 | G_OBJECT_CLASS (gkd_secret_service_parent_class)->finalize (obj); | ||
3362 | 1230 | } | ||
3363 | 1231 | |||
3364 | 1232 | static void | ||
3365 | 1233 | gkd_secret_service_set_property (GObject *obj, guint prop_id, const GValue *value, | ||
3366 | 1234 | GParamSpec *pspec) | ||
3367 | 1235 | { | ||
3368 | 1236 | GkdSecretService *self = GKD_SECRET_SERVICE (obj); | ||
3369 | 1237 | |||
3370 | 1238 | switch (prop_id) { | ||
3371 | 1239 | case PROP_CONNECTION: | ||
3372 | 1240 | g_return_if_fail (!self->connection); | ||
3373 | 1241 | self->connection = g_value_dup_boxed (value); | ||
3374 | 1242 | g_return_if_fail (self->connection); | ||
3375 | 1243 | break; | ||
3376 | 1244 | case PROP_PKCS11_SLOT: | ||
3377 | 1245 | g_return_if_fail (!self->objects); | ||
3378 | 1246 | break; | ||
3379 | 1247 | default: | ||
3380 | 1248 | G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec); | ||
3381 | 1249 | break; | ||
3382 | 1250 | } | ||
3383 | 1251 | } | ||
3384 | 1252 | |||
3385 | 1253 | static void | ||
3386 | 1254 | gkd_secret_service_get_property (GObject *obj, guint prop_id, GValue *value, | ||
3387 | 1255 | GParamSpec *pspec) | ||
3388 | 1256 | { | ||
3389 | 1257 | GkdSecretService *self = GKD_SECRET_SERVICE (obj); | ||
3390 | 1258 | |||
3391 | 1259 | switch (prop_id) { | ||
3392 | 1260 | case PROP_CONNECTION: | ||
3393 | 1261 | g_value_set_boxed (value, gkd_secret_service_get_connection (self)); | ||
3394 | 1262 | break; | ||
3395 | 1263 | case PROP_PKCS11_SLOT: | ||
3396 | 1264 | g_value_set_object (value, gkd_secret_service_get_pkcs11_slot (self)); | ||
3397 | 1265 | break; | ||
3398 | 1266 | default: | ||
3399 | 1267 | G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec); | ||
3400 | 1268 | break; | ||
3401 | 1269 | } | ||
3402 | 1270 | } | ||
3403 | 1271 | |||
3404 | 1272 | static void | ||
3405 | 1273 | gkd_secret_service_class_init (GkdSecretServiceClass *klass) | ||
3406 | 1274 | { | ||
3407 | 1275 | GObjectClass *gobject_class = G_OBJECT_CLASS (klass); | ||
3408 | 1276 | |||
3409 | 1277 | gobject_class->constructor = gkd_secret_service_constructor; | ||
3410 | 1278 | gobject_class->dispose = gkd_secret_service_dispose; | ||
3411 | 1279 | gobject_class->finalize = gkd_secret_service_finalize; | ||
3412 | 1280 | gobject_class->set_property = gkd_secret_service_set_property; | ||
3413 | 1281 | gobject_class->get_property = gkd_secret_service_get_property; | ||
3414 | 1282 | |||
3415 | 1283 | g_object_class_install_property (gobject_class, PROP_CONNECTION, | ||
3416 | 1284 | g_param_spec_boxed ("connection", "Connection", "DBus Connection", | ||
3417 | 1285 | GKD_DBUS_TYPE_CONNECTION, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); | ||
3418 | 1286 | |||
3419 | 1287 | g_object_class_install_property (gobject_class, PROP_PKCS11_SLOT, | ||
3420 | 1288 | g_param_spec_object ("pkcs11-slot", "Pkcs11 Slot", "PKCS#11 slot that we use for secrets", | ||
3421 | 1289 | GCK_TYPE_SLOT, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); | ||
3422 | 1290 | } | ||
3423 | 1291 | |||
3424 | 1292 | /* ----------------------------------------------------------------------------- | ||
3425 | 1293 | * PUBLIC | ||
3426 | 1294 | */ | ||
3427 | 1295 | |||
3428 | 1296 | void | ||
3429 | 1297 | gkd_secret_service_send (GkdSecretService *self, DBusMessage *message) | ||
3430 | 1298 | { | ||
3431 | 1299 | g_return_if_fail (GKD_SECRET_IS_SERVICE (self)); | ||
3432 | 1300 | dbus_connection_send (self->connection, message, NULL); | ||
3433 | 1301 | } | ||
3434 | 1302 | |||
3435 | 1303 | GkdSecretObjects* | ||
3436 | 1304 | gkd_secret_service_get_objects (GkdSecretService *self) | ||
3437 | 1305 | { | ||
3438 | 1306 | g_return_val_if_fail (GKD_SECRET_IS_SERVICE (self), NULL); | ||
3439 | 1307 | return self->objects; | ||
3440 | 1308 | } | ||
3441 | 1309 | |||
3442 | 1310 | DBusConnection* | ||
3443 | 1311 | gkd_secret_service_get_connection (GkdSecretService *self) | ||
3444 | 1312 | { | ||
3445 | 1313 | g_return_val_if_fail (GKD_SECRET_IS_SERVICE (self), NULL); | ||
3446 | 1314 | return self->connection; | ||
3447 | 1315 | } | ||
3448 | 1316 | |||
3449 | 1317 | GckSlot* | ||
3450 | 1318 | gkd_secret_service_get_pkcs11_slot (GkdSecretService *self) | ||
3451 | 1319 | { | ||
3452 | 1320 | g_return_val_if_fail (GKD_SECRET_IS_SERVICE (self), NULL); | ||
3453 | 1321 | return gkd_secret_objects_get_pkcs11_slot (self->objects); | ||
3454 | 1322 | } | ||
3455 | 1323 | |||
3456 | 1324 | static gboolean | ||
3457 | 1325 | log_into_pkcs11_session (GckSession *session, GError **error) | ||
3458 | 1326 | { | ||
3459 | 1327 | GckSessionInfo *sess; | ||
3460 | 1328 | GckTokenInfo *info; | ||
3461 | 1329 | GckSlot *slot; | ||
3462 | 1330 | gboolean login; | ||
3463 | 1331 | |||
3464 | 1332 | /* Perform the necessary 'user' login to secrets token. Doesn't unlock anything */ | ||
3465 | 1333 | slot = gck_session_get_slot (session); | ||
3466 | 1334 | info = gck_slot_get_token_info (slot); | ||
3467 | 1335 | login = info && (info->flags & CKF_LOGIN_REQUIRED); | ||
3468 | 1336 | gck_token_info_free (info); | ||
3469 | 1337 | g_object_unref (slot); | ||
3470 | 1338 | |||
3471 | 1339 | if (login) { | ||
3472 | 1340 | sess = gck_session_get_info (session); | ||
3473 | 1341 | if (sess->state == CKS_RO_USER_FUNCTIONS || | ||
3474 | 1342 | sess->state == CKS_RW_USER_FUNCTIONS) | ||
3475 | 1343 | login = FALSE; | ||
3476 | 1344 | gck_session_info_free (sess); | ||
3477 | 1345 | } | ||
3478 | 1346 | |||
3479 | 1347 | if (login && !gck_session_login (session, CKU_USER, NULL, 0, NULL, error)) | ||
3480 | 1348 | return FALSE; | ||
3481 | 1349 | |||
3482 | 1350 | return TRUE; | ||
3483 | 1351 | } | ||
3484 | 1352 | |||
3485 | 1353 | GckSession* | ||
3486 | 1354 | gkd_secret_service_get_pkcs11_session (GkdSecretService *self, const gchar *caller) | ||
3487 | 1355 | { | ||
3488 | 1356 | ServiceClient *client; | ||
3489 | 1357 | GError *error = NULL; | ||
3490 | 1358 | GckSlot *slot; | ||
3491 | 1359 | |||
3492 | 1360 | g_return_val_if_fail (GKD_SECRET_IS_SERVICE (self), NULL); | ||
3493 | 1361 | g_return_val_if_fail (caller, NULL); | ||
3494 | 1362 | |||
3495 | 1363 | client = g_hash_table_lookup (self->clients, caller); | ||
3496 | 1364 | g_return_val_if_fail (client, NULL); | ||
3497 | 1365 | |||
3498 | 1366 | /* Open a new session if necessary */ | ||
3499 | 1367 | if (!client->pkcs11_session) { | ||
3500 | 1368 | slot = gkd_secret_service_get_pkcs11_slot (self); | ||
3501 | 1369 | client->pkcs11_session = gck_slot_open_session_full (slot, GCK_SESSION_READ_WRITE, | ||
3502 | 1370 | CKF_G_APPLICATION_SESSION, &client->app, | ||
3503 | 1371 | NULL, NULL, &error); | ||
3504 | 1372 | if (!client->pkcs11_session) { | ||
3505 | 1373 | g_warning ("couldn't open pkcs11 session for secret service: %s", | ||
3506 | 1374 | egg_error_message (error)); | ||
3507 | 1375 | g_clear_error (&error); | ||
3508 | 1376 | return NULL; | ||
3509 | 1377 | } | ||
3510 | 1378 | |||
3511 | 1379 | if (!log_into_pkcs11_session (client->pkcs11_session, &error)) { | ||
3512 | 1380 | g_warning ("couldn't log in to pkcs11 session for secret service: %s", | ||
3513 | 1381 | egg_error_message (error)); | ||
3514 | 1382 | g_clear_error (&error); | ||
3515 | 1383 | g_object_unref (client->pkcs11_session); | ||
3516 | 1384 | client->pkcs11_session = NULL; | ||
3517 | 1385 | return NULL; | ||
3518 | 1386 | } | ||
3519 | 1387 | } | ||
3520 | 1388 | |||
3521 | 1389 | return client->pkcs11_session; | ||
3522 | 1390 | } | ||
3523 | 1391 | |||
3524 | 1392 | GckSession* | ||
3525 | 1393 | gkd_secret_service_internal_pkcs11_session (GkdSecretService *self) | ||
3526 | 1394 | { | ||
3527 | 1395 | GError *error = NULL; | ||
3528 | 1396 | GckSlot *slot; | ||
3529 | 1397 | |||
3530 | 1398 | g_return_val_if_fail (GKD_SECRET_IS_SERVICE (self), NULL); | ||
3531 | 1399 | |||
3532 | 1400 | if (self->internal_session) | ||
3533 | 1401 | return self->internal_session; | ||
3534 | 1402 | |||
3535 | 1403 | slot = gkd_secret_service_get_pkcs11_slot (self); | ||
3536 | 1404 | self->internal_session = gck_slot_open_session_full (slot, GCK_SESSION_READ_WRITE, | ||
3537 | 1405 | 0, NULL, NULL, NULL, &error); | ||
3538 | 1406 | if (!self->internal_session) { | ||
3539 | 1407 | g_warning ("couldn't open pkcs11 session for secret service: %s", | ||
3540 | 1408 | egg_error_message (error)); | ||
3541 | 1409 | g_clear_error (&error); | ||
3542 | 1410 | return NULL; | ||
3543 | 1411 | } | ||
3544 | 1412 | |||
3545 | 1413 | if (!log_into_pkcs11_session (self->internal_session, &error)) { | ||
3546 | 1414 | g_warning ("couldn't log in to pkcs11 session for secret service: %s", | ||
3547 | 1415 | egg_error_message (error)); | ||
3548 | 1416 | g_clear_error (&error); | ||
3549 | 1417 | g_object_unref (self->internal_session); | ||
3550 | 1418 | self->internal_session = NULL; | ||
3551 | 1419 | return NULL; | ||
3552 | 1420 | } | ||
3553 | 1421 | |||
3554 | 1422 | return self->internal_session; | ||
3555 | 1423 | } | ||
3556 | 1424 | |||
3557 | 1425 | GkdSecretSession* | ||
3558 | 1426 | gkd_secret_service_lookup_session (GkdSecretService *self, const gchar *path, | ||
3559 | 1427 | const gchar *caller) | ||
3560 | 1428 | { | ||
3561 | 1429 | ServiceClient *client; | ||
3562 | 1430 | gpointer object; | ||
3563 | 1431 | |||
3564 | 1432 | g_return_val_if_fail (GKD_SECRET_IS_SERVICE (self), NULL); | ||
3565 | 1433 | g_return_val_if_fail (path, NULL); | ||
3566 | 1434 | g_return_val_if_fail (caller, NULL); | ||
3567 | 1435 | |||
3568 | 1436 | client = g_hash_table_lookup (self->clients, caller); | ||
3569 | 1437 | g_return_val_if_fail (client, NULL); | ||
3570 | 1438 | |||
3571 | 1439 | object = g_hash_table_lookup (client->dispatch, path); | ||
3572 | 1440 | if (object == NULL || !GKD_SECRET_IS_SESSION (object)) | ||
3573 | 1441 | return NULL; | ||
3574 | 1442 | |||
3575 | 1443 | return GKD_SECRET_SESSION (object); | ||
3576 | 1444 | } | ||
3577 | 1445 | |||
3578 | 1446 | void | ||
3579 | 1447 | gkd_secret_service_close_session (GkdSecretService *self, GkdSecretSession *session) | ||
3580 | 1448 | { | ||
3581 | 1449 | ServiceClient *client; | ||
3582 | 1450 | const gchar *caller; | ||
3583 | 1451 | const gchar *path; | ||
3584 | 1452 | |||
3585 | 1453 | g_return_if_fail (GKD_SECRET_IS_SERVICE (self)); | ||
3586 | 1454 | g_return_if_fail (GKD_SECRET_IS_SESSION (session)); | ||
3587 | 1455 | |||
3588 | 1456 | caller = gkd_secret_session_get_caller (session); | ||
3589 | 1457 | client = g_hash_table_lookup (self->clients, caller); | ||
3590 | 1458 | g_return_if_fail (client); | ||
3591 | 1459 | |||
3592 | 1460 | path = gkd_secret_dispatch_get_object_path (GKD_SECRET_DISPATCH (session)); | ||
3593 | 1461 | g_hash_table_remove (client->dispatch, path); | ||
3594 | 1462 | } | ||
3595 | 1463 | |||
3596 | 1464 | const gchar* | ||
3597 | 1465 | gkd_secret_service_get_alias (GkdSecretService *self, const gchar *alias) | ||
3598 | 1466 | { | ||
3599 | 1467 | const gchar *identifier; | ||
3600 | 1468 | |||
3601 | 1469 | g_return_val_if_fail (GKD_SECRET_IS_SERVICE (self), NULL); | ||
3602 | 1470 | g_return_val_if_fail (alias != NULL, NULL); | ||
3603 | 1471 | |||
3604 | 1472 | identifier = g_hash_table_lookup (self->aliases, alias); | ||
3605 | 1473 | if (!identifier) { | ||
3606 | 1474 | if (g_str_equal (alias, "default")) { | ||
3607 | 1475 | update_default (self, TRUE); | ||
3608 | 1476 | identifier = g_hash_table_lookup (self->aliases, alias); | ||
3609 | 1477 | |||
3610 | 1478 | /* Default to to 'login' if no default keyring */ | ||
3611 | 1479 | if (identifier == NULL) { | ||
3612 | 1480 | identifier = "login"; | ||
3613 | 1481 | g_hash_table_replace (self->aliases, g_strdup (alias), | ||
3614 | 1482 | g_strdup (identifier)); | ||
3615 | 1483 | } | ||
3616 | 1484 | |||
3617 | 1485 | } else if (g_str_equal (alias, "session")) { | ||
3618 | 1486 | identifier = "session"; | ||
3619 | 1487 | g_hash_table_replace (self->aliases, g_strdup (alias), | ||
3620 | 1488 | g_strdup (identifier)); | ||
3621 | 1489 | |||
3622 | 1490 | /* TODO: We should be using CKA_G_LOGIN_COLLECTION */ | ||
3623 | 1491 | } else if (g_str_equal (alias, "login")) { | ||
3624 | 1492 | identifier = "login"; | ||
3625 | 1493 | g_hash_table_replace (self->aliases, g_strdup (alias), | ||
3626 | 1494 | g_strdup (identifier)); | ||
3627 | 1495 | } | ||
3628 | 1496 | } | ||
3629 | 1497 | |||
3630 | 1498 | return identifier; | ||
3631 | 1499 | } | ||
3632 | 1500 | |||
3633 | 1501 | void | ||
3634 | 1502 | gkd_secret_service_set_alias (GkdSecretService *self, const gchar *alias, | ||
3635 | 1503 | const gchar *identifier) | ||
3636 | 1504 | { | ||
3637 | 1505 | g_return_if_fail (GKD_SECRET_IS_SERVICE (self)); | ||
3638 | 1506 | g_return_if_fail (alias); | ||
3639 | 1507 | |||
3640 | 1508 | g_hash_table_replace (self->aliases, g_strdup (alias), g_strdup (identifier)); | ||
3641 | 1509 | |||
3642 | 1510 | if (g_str_equal (alias, "default")) | ||
3643 | 1511 | store_default (self); | ||
3644 | 1512 | } | ||
3645 | 1513 | |||
3646 | 1514 | void | ||
3647 | 1515 | gkd_secret_service_publish_dispatch (GkdSecretService *self, const gchar *caller, | ||
3648 | 1516 | GkdSecretDispatch *object) | ||
3649 | 1517 | { | ||
3650 | 1518 | ServiceClient *client; | ||
3651 | 1519 | const gchar *path; | ||
3652 | 1520 | |||
3653 | 1521 | g_return_if_fail (GKD_SECRET_IS_SERVICE (self)); | ||
3654 | 1522 | g_return_if_fail (caller); | ||
3655 | 1523 | g_return_if_fail (GKD_SECRET_IS_DISPATCH (object)); | ||
3656 | 1524 | |||
3657 | 1525 | /* Take ownership of the session */ | ||
3658 | 1526 | client = g_hash_table_lookup (self->clients, caller); | ||
3659 | 1527 | g_return_if_fail (client); | ||
3660 | 1528 | path = gkd_secret_dispatch_get_object_path (object); | ||
3661 | 1529 | g_return_if_fail (!g_hash_table_lookup (client->dispatch, path)); | ||
3662 | 1530 | g_hash_table_replace (client->dispatch, (gpointer)path, g_object_ref (object)); | ||
3663 | 1531 | } | ||
3664 | 1532 | |||
3665 | 1533 | static void | ||
3666 | 1534 | emit_collections_properties_changed (GkdSecretService *self) | ||
3667 | 1535 | { | ||
3668 | 1536 | const gchar *iface = SECRET_SERVICE_INTERFACE; | ||
3669 | 1537 | DBusMessage *message; | ||
3670 | 1538 | DBusMessageIter array; | ||
3671 | 1539 | DBusMessageIter iter; | ||
3672 | 1540 | |||
3673 | 1541 | message = dbus_message_new_signal (SECRET_SERVICE_PATH, | ||
3674 | 1542 | DBUS_INTERFACE_PROPERTIES, | ||
3675 | 1543 | "PropertiesChanged"); | ||
3676 | 1544 | |||
3677 | 1545 | dbus_message_iter_init_append (message, &iter); | ||
3678 | 1546 | dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &iface); | ||
3679 | 1547 | service_append_all_properties (self, &iter); | ||
3680 | 1548 | dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "s", &array); | ||
3681 | 1549 | dbus_message_iter_close_container (&iter, &array); | ||
3682 | 1550 | |||
3683 | 1551 | if (!dbus_connection_send (self->connection, message, NULL)) | ||
3684 | 1552 | g_return_if_reached (); | ||
3685 | 1553 | dbus_message_unref (message); | ||
3686 | 1554 | } | ||
3687 | 1555 | |||
3688 | 1556 | void | ||
3689 | 1557 | gkd_secret_service_emit_collection_created (GkdSecretService *self, | ||
3690 | 1558 | const gchar *collection_path) | ||
3691 | 1559 | { | ||
3692 | 1560 | DBusMessage *message; | ||
3693 | 1561 | |||
3694 | 1562 | g_return_if_fail (GKD_SECRET_IS_SERVICE (self)); | ||
3695 | 1563 | g_return_if_fail (collection_path != NULL); | ||
3696 | 1564 | |||
3697 | 1565 | message = dbus_message_new_signal (SECRET_SERVICE_PATH, | ||
3698 | 1566 | SECRET_SERVICE_INTERFACE, | ||
3699 | 1567 | "CollectionCreated"); | ||
3700 | 1568 | dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &collection_path, | ||
3701 | 1569 | DBUS_TYPE_INVALID); | ||
3702 | 1570 | |||
3703 | 1571 | if (!dbus_connection_send (self->connection, message, NULL)) | ||
3704 | 1572 | g_return_if_reached (); | ||
3705 | 1573 | dbus_message_unref (message); | ||
3706 | 1574 | |||
3707 | 1575 | emit_collections_properties_changed (self); | ||
3708 | 1576 | } | ||
3709 | 1577 | |||
3710 | 1578 | void | ||
3711 | 1579 | gkd_secret_service_emit_collection_deleted (GkdSecretService *self, | ||
3712 | 1580 | const gchar *collection_path) | ||
3713 | 1581 | { | ||
3714 | 1582 | DBusMessage *message; | ||
3715 | 1583 | |||
3716 | 1584 | g_return_if_fail (GKD_SECRET_IS_SERVICE (self)); | ||
3717 | 1585 | g_return_if_fail (collection_path != NULL); | ||
3718 | 1586 | |||
3719 | 1587 | message = dbus_message_new_signal (SECRET_SERVICE_PATH, | ||
3720 | 1588 | SECRET_SERVICE_INTERFACE, | ||
3721 | 1589 | "CollectionDeleted"); | ||
3722 | 1590 | dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &collection_path, | ||
3723 | 1591 | DBUS_TYPE_INVALID); | ||
3724 | 1592 | |||
3725 | 1593 | if (!dbus_connection_send (self->connection, message, NULL)) | ||
3726 | 1594 | g_return_if_reached (); | ||
3727 | 1595 | dbus_message_unref (message); | ||
3728 | 1596 | |||
3729 | 1597 | emit_collections_properties_changed (self); | ||
3730 | 1598 | } | ||
3731 | 0 | 1599 | ||
3732 | === modified file '.pc/applied-patches' | |||
3733 | --- .pc/applied-patches 2012-05-16 17:39:27 +0000 | |||
3734 | +++ .pc/applied-patches 2013-03-14 13:26:21 +0000 | |||
3735 | @@ -1,2 +1,4 @@ | |||
3736 | 1 | 00git_fix_searchitems_method.patch | ||
3737 | 2 | 00git_fix_introspection.patch | ||
3738 | 1 | 03_kfreebsd.patch | 3 | 03_kfreebsd.patch |
3739 | 2 | 04_nodisplay_autostart.patch | 4 | 04_nodisplay_autostart.patch |
3740 | 3 | 5 | ||
3741 | === modified file 'daemon/dbus/gkd-secret-introspect.c' | |||
3742 | --- daemon/dbus/gkd-secret-introspect.c 2012-05-16 17:39:27 +0000 | |||
3743 | +++ daemon/dbus/gkd-secret-introspect.c 2013-03-14 13:26:21 +0000 | |||
3744 | @@ -63,7 +63,7 @@ | |||
3745 | 63 | " <interface name='org.freedesktop.Secret.Collection'>\n" | 63 | " <interface name='org.freedesktop.Secret.Collection'>\n" |
3746 | 64 | " <property name='Items' type='ao' access='read'/>\n" | 64 | " <property name='Items' type='ao' access='read'/>\n" |
3747 | 65 | " <property name='Label' type='s' access='readwrite'/>\n" | 65 | " <property name='Label' type='s' access='readwrite'/>\n" |
3749 | 66 | " <property name='Locked' type='s' access='read'/>\n" | 66 | " <property name='Locked' type='b' access='read'/>\n" |
3750 | 67 | " <property name='Created' type='t' access='read'/>\n" | 67 | " <property name='Created' type='t' access='read'/>\n" |
3751 | 68 | " <property name='Modified' type='t' access='read'/>\n" | 68 | " <property name='Modified' type='t' access='read'/>\n" |
3752 | 69 | " <method name='Delete'>\n" | 69 | " <method name='Delete'>\n" |
3753 | @@ -71,8 +71,7 @@ | |||
3754 | 71 | " </method>\n" | 71 | " </method>\n" |
3755 | 72 | " <method name='SearchItems'>\n" | 72 | " <method name='SearchItems'>\n" |
3756 | 73 | " <arg name='attributes' type='a{ss}' direction='in'/>\n" | 73 | " <arg name='attributes' type='a{ss}' direction='in'/>\n" |
3759 | 74 | " <arg name='unlocked' type='ao' direction='out'/>\n" | 74 | " <arg name='results' type='ao' direction='out'/>\n" |
3758 | 75 | " <arg name='locked' type='ao' direction='out'/>\n" | ||
3760 | 76 | " </method>\n" | 75 | " </method>\n" |
3761 | 77 | " <method name='CreateItem'>\n" | 76 | " <method name='CreateItem'>\n" |
3762 | 78 | " <arg name='props' type='a{sv}' direction='in'/>\n" | 77 | " <arg name='props' type='a{sv}' direction='in'/>\n" |
3763 | 79 | 78 | ||
3764 | === modified file 'daemon/dbus/gkd-secret-objects.c' | |||
3765 | --- daemon/dbus/gkd-secret-objects.c 2013-03-07 11:39:17 +0000 | |||
3766 | +++ daemon/dbus/gkd-secret-objects.c 2013-03-14 13:26:21 +0000 | |||
3767 | @@ -542,7 +542,7 @@ | |||
3768 | 542 | static DBusMessage* | 542 | static DBusMessage* |
3769 | 543 | collection_method_search_items (GkdSecretObjects *self, GckObject *object, DBusMessage *message) | 543 | collection_method_search_items (GkdSecretObjects *self, GckObject *object, DBusMessage *message) |
3770 | 544 | { | 544 | { |
3772 | 545 | return gkd_secret_objects_handle_search_items (self, message, dbus_message_get_path (message)); | 545 | return gkd_secret_objects_handle_search_items (self, message, dbus_message_get_path (message), FALSE); |
3773 | 546 | } | 546 | } |
3774 | 547 | 547 | ||
3775 | 548 | static GckObject* | 548 | static GckObject* |
3776 | @@ -1314,8 +1314,10 @@ | |||
3777 | 1314 | } | 1314 | } |
3778 | 1315 | 1315 | ||
3779 | 1316 | DBusMessage* | 1316 | DBusMessage* |
3782 | 1317 | gkd_secret_objects_handle_search_items (GkdSecretObjects *self, DBusMessage *message, | 1317 | gkd_secret_objects_handle_search_items (GkdSecretObjects *self, |
3783 | 1318 | const gchar *base) | 1318 | DBusMessage *message, |
3784 | 1319 | const gchar *base, | ||
3785 | 1320 | gboolean separate_locked) | ||
3786 | 1319 | { | 1321 | { |
3787 | 1320 | GckBuilder builder = GCK_BUILDER_INIT; | 1322 | GckBuilder builder = GCK_BUILDER_INIT; |
3788 | 1321 | DBusMessageIter iter; | 1323 | DBusMessageIter iter; |
3789 | @@ -1385,23 +1387,31 @@ | |||
3790 | 1385 | items = gck_objects_from_handle_array (session, data, n_data / sizeof (CK_OBJECT_HANDLE)); | 1387 | items = gck_objects_from_handle_array (session, data, n_data / sizeof (CK_OBJECT_HANDLE)); |
3791 | 1386 | g_free (data); | 1388 | g_free (data); |
3792 | 1387 | 1389 | ||
3793 | 1390 | /* Prepare the reply message */ | ||
3794 | 1391 | reply = dbus_message_new_method_return (message); | ||
3795 | 1392 | dbus_message_iter_init_append (reply, &iter); | ||
3796 | 1393 | |||
3797 | 1388 | /* Filter out the locked items */ | 1394 | /* Filter out the locked items */ |
3814 | 1389 | item_cleanup_search_results (session, items, &locked, &unlocked); | 1395 | if (separate_locked) { |
3815 | 1390 | 1396 | item_cleanup_search_results (session, items, &locked, &unlocked); | |
3816 | 1391 | /* Prepare the reply message */ | 1397 | |
3817 | 1392 | reply = dbus_message_new_method_return (message); | 1398 | dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "o", &array); |
3818 | 1393 | dbus_message_iter_init_append (reply, &iter); | 1399 | objects_foreach_item (self, unlocked, NULL, on_object_path_append_to_iter, &array); |
3819 | 1394 | 1400 | dbus_message_iter_close_container (&iter, &array); | |
3820 | 1395 | dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "o", &array); | 1401 | |
3821 | 1396 | objects_foreach_item (self, unlocked, NULL, on_object_path_append_to_iter, &array); | 1402 | dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "o", &array); |
3822 | 1397 | dbus_message_iter_close_container (&iter, &array); | 1403 | objects_foreach_item (self, locked, NULL, on_object_path_append_to_iter, &array); |
3823 | 1398 | 1404 | dbus_message_iter_close_container (&iter, &array); | |
3824 | 1399 | dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "o", &array); | 1405 | |
3825 | 1400 | objects_foreach_item (self, locked, NULL, on_object_path_append_to_iter, &array); | 1406 | g_list_free (locked); |
3826 | 1401 | dbus_message_iter_close_container (&iter, &array); | 1407 | g_list_free (unlocked); |
3827 | 1402 | 1408 | ||
3828 | 1403 | g_list_free (locked); | 1409 | } else { |
3829 | 1404 | g_list_free (unlocked); | 1410 | dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "o", &array); |
3830 | 1411 | objects_foreach_item (self, items, NULL, on_object_path_append_to_iter, &array); | ||
3831 | 1412 | dbus_message_iter_close_container (&iter, &array); | ||
3832 | 1413 | } | ||
3833 | 1414 | |||
3834 | 1405 | gck_list_unref_free (items); | 1415 | gck_list_unref_free (items); |
3835 | 1406 | 1416 | ||
3836 | 1407 | return reply; | 1417 | return reply; |
3837 | 1408 | 1418 | ||
3838 | === modified file 'daemon/dbus/gkd-secret-objects.h' | |||
3839 | --- daemon/dbus/gkd-secret-objects.h 2012-08-13 12:39:40 +0000 | |||
3840 | +++ daemon/dbus/gkd-secret-objects.h 2013-03-14 13:26:21 +0000 | |||
3841 | @@ -55,7 +55,8 @@ | |||
3842 | 55 | 55 | ||
3843 | 56 | DBusMessage* gkd_secret_objects_handle_search_items (GkdSecretObjects *self, | 56 | DBusMessage* gkd_secret_objects_handle_search_items (GkdSecretObjects *self, |
3844 | 57 | DBusMessage *message, | 57 | DBusMessage *message, |
3846 | 58 | const gchar *base); | 58 | const gchar *base, |
3847 | 59 | gboolean separate_locked); | ||
3848 | 59 | 60 | ||
3849 | 60 | DBusMessage* gkd_secret_objects_handle_get_secrets (GkdSecretObjects *self, | 61 | DBusMessage* gkd_secret_objects_handle_get_secrets (GkdSecretObjects *self, |
3850 | 61 | DBusMessage *message); | 62 | DBusMessage *message); |
3851 | 62 | 63 | ||
3852 | === modified file 'daemon/dbus/gkd-secret-service.c' | |||
3853 | --- daemon/dbus/gkd-secret-service.c 2012-08-24 10:32:10 +0000 | |||
3854 | +++ daemon/dbus/gkd-secret-service.c 2013-03-14 13:26:21 +0000 | |||
3855 | @@ -913,7 +913,7 @@ | |||
3856 | 913 | 913 | ||
3857 | 914 | /* org.freedesktop.Secret.Service.SearchItems() */ | 914 | /* org.freedesktop.Secret.Service.SearchItems() */ |
3858 | 915 | if (dbus_message_is_method_call (message, SECRET_SERVICE_INTERFACE, "SearchItems")) | 915 | if (dbus_message_is_method_call (message, SECRET_SERVICE_INTERFACE, "SearchItems")) |
3860 | 916 | return gkd_secret_objects_handle_search_items (self->objects, message, NULL); | 916 | return gkd_secret_objects_handle_search_items (self->objects, message, NULL, TRUE); |
3861 | 917 | 917 | ||
3862 | 918 | /* org.freedesktop.Secret.Service.GetSecrets() */ | 918 | /* org.freedesktop.Secret.Service.GetSecrets() */ |
3863 | 919 | if (dbus_message_is_method_call (message, SECRET_SERVICE_INTERFACE, "GetSecrets")) | 919 | if (dbus_message_is_method_call (message, SECRET_SERVICE_INTERFACE, "GetSecrets")) |
3864 | 920 | 920 | ||
3865 | === modified file 'debian/changelog' | |||
3866 | --- debian/changelog 2013-03-07 11:39:17 +0000 | |||
3867 | +++ debian/changelog 2013-03-14 13:26:21 +0000 | |||
3868 | @@ -1,3 +1,12 @@ | |||
3869 | 1 | gnome-keyring (3.6.3-0ubuntu2) raring; urgency=low | ||
3870 | 2 | |||
3871 | 3 | * debian/patches/00git_fix_searchitems_method.patch: | ||
3872 | 4 | Upstream patch to fix return value of Collection.SearchItems(). | ||
3873 | 5 | * debian/patches/00git_fix_introspection.patch: | ||
3874 | 6 | Upstream patch to fix introspection of some D-Bus methods. | ||
3875 | 7 | |||
3876 | 8 | -- Dmitry Shachnev <mitya57@ubuntu.com> Thu, 14 Mar 2013 17:18:23 +0400 | ||
3877 | 9 | |||
3878 | 1 | gnome-keyring (3.6.3-0ubuntu1) raring; urgency=low | 10 | gnome-keyring (3.6.3-0ubuntu1) raring; urgency=low |
3879 | 2 | 11 | ||
3880 | 3 | * New upstream release | 12 | * New upstream release |
3881 | 4 | 13 | ||
3882 | === added file 'debian/patches/00git_fix_introspection.patch' | |||
3883 | --- debian/patches/00git_fix_introspection.patch 1970-01-01 00:00:00 +0000 | |||
3884 | +++ debian/patches/00git_fix_introspection.patch 2013-03-14 13:26:21 +0000 | |||
3885 | @@ -0,0 +1,26 @@ | |||
3886 | 1 | Author: Dmitry Shachnev <mitya57@ubuntu.com> | ||
3887 | 2 | Description: Fix introspection of some D-Bus methods | ||
3888 | 3 | Forwarded: yes | ||
3889 | 4 | Last-Update: 2013-03-10 | ||
3890 | 5 | |||
3891 | 6 | --- a/daemon/dbus/gkd-secret-introspect.c | ||
3892 | 7 | +++ b/daemon/dbus/gkd-secret-introspect.c | ||
3893 | 8 | @@ -63,7 +63,7 @@ | ||
3894 | 9 | " <interface name='org.freedesktop.Secret.Collection'>\n" | ||
3895 | 10 | " <property name='Items' type='ao' access='read'/>\n" | ||
3896 | 11 | " <property name='Label' type='s' access='readwrite'/>\n" | ||
3897 | 12 | - " <property name='Locked' type='s' access='read'/>\n" | ||
3898 | 13 | + " <property name='Locked' type='b' access='read'/>\n" | ||
3899 | 14 | " <property name='Created' type='t' access='read'/>\n" | ||
3900 | 15 | " <property name='Modified' type='t' access='read'/>\n" | ||
3901 | 16 | " <method name='Delete'>\n" | ||
3902 | 17 | @@ -71,8 +71,7 @@ | ||
3903 | 18 | " </method>\n" | ||
3904 | 19 | " <method name='SearchItems'>\n" | ||
3905 | 20 | " <arg name='attributes' type='a{ss}' direction='in'/>\n" | ||
3906 | 21 | - " <arg name='unlocked' type='ao' direction='out'/>\n" | ||
3907 | 22 | - " <arg name='locked' type='ao' direction='out'/>\n" | ||
3908 | 23 | + " <arg name='results' type='ao' direction='out'/>\n" | ||
3909 | 24 | " </method>\n" | ||
3910 | 25 | " <method name='CreateItem'>\n" | ||
3911 | 26 | " <arg name='props' type='a{sv}' direction='in'/>\n" | ||
3912 | 0 | 27 | ||
3913 | === added file 'debian/patches/00git_fix_searchitems_method.patch' | |||
3914 | --- debian/patches/00git_fix_searchitems_method.patch 1970-01-01 00:00:00 +0000 | |||
3915 | +++ debian/patches/00git_fix_searchitems_method.patch 2013-03-14 13:26:21 +0000 | |||
3916 | @@ -0,0 +1,99 @@ | |||
3917 | 1 | Description: Only return one object path list from Collection.SearchItems() | ||
3918 | 2 | In the Secret Service dbus interface the SearchItems method of the | ||
3919 | 3 | Collection interface only returns one list of object paths, unlike | ||
3920 | 4 | SearchItems on the Service interface which splits its return values | ||
3921 | 5 | by locked and unlocked items. | ||
3922 | 6 | Origin: upstream, https://git.gnome.org/browse/gnome-keyring/commit/?id=ddb87ccad9 | ||
3923 | 7 | Last-Update: 2013-03-10 | ||
3924 | 8 | |||
3925 | 9 | --- a/daemon/dbus/gkd-secret-objects.c | ||
3926 | 10 | +++ b/daemon/dbus/gkd-secret-objects.c | ||
3927 | 11 | @@ -542,7 +542,7 @@ | ||
3928 | 12 | static DBusMessage* | ||
3929 | 13 | collection_method_search_items (GkdSecretObjects *self, GckObject *object, DBusMessage *message) | ||
3930 | 14 | { | ||
3931 | 15 | - return gkd_secret_objects_handle_search_items (self, message, dbus_message_get_path (message)); | ||
3932 | 16 | + return gkd_secret_objects_handle_search_items (self, message, dbus_message_get_path (message), FALSE); | ||
3933 | 17 | } | ||
3934 | 18 | |||
3935 | 19 | static GckObject* | ||
3936 | 20 | @@ -1314,8 +1314,10 @@ | ||
3937 | 21 | } | ||
3938 | 22 | |||
3939 | 23 | DBusMessage* | ||
3940 | 24 | -gkd_secret_objects_handle_search_items (GkdSecretObjects *self, DBusMessage *message, | ||
3941 | 25 | - const gchar *base) | ||
3942 | 26 | +gkd_secret_objects_handle_search_items (GkdSecretObjects *self, | ||
3943 | 27 | + DBusMessage *message, | ||
3944 | 28 | + const gchar *base, | ||
3945 | 29 | + gboolean separate_locked) | ||
3946 | 30 | { | ||
3947 | 31 | GckBuilder builder = GCK_BUILDER_INIT; | ||
3948 | 32 | DBusMessageIter iter; | ||
3949 | 33 | @@ -1385,23 +1387,31 @@ | ||
3950 | 34 | items = gck_objects_from_handle_array (session, data, n_data / sizeof (CK_OBJECT_HANDLE)); | ||
3951 | 35 | g_free (data); | ||
3952 | 36 | |||
3953 | 37 | - /* Filter out the locked items */ | ||
3954 | 38 | - item_cleanup_search_results (session, items, &locked, &unlocked); | ||
3955 | 39 | - | ||
3956 | 40 | /* Prepare the reply message */ | ||
3957 | 41 | reply = dbus_message_new_method_return (message); | ||
3958 | 42 | dbus_message_iter_init_append (reply, &iter); | ||
3959 | 43 | |||
3960 | 44 | - dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "o", &array); | ||
3961 | 45 | - objects_foreach_item (self, unlocked, NULL, on_object_path_append_to_iter, &array); | ||
3962 | 46 | - dbus_message_iter_close_container (&iter, &array); | ||
3963 | 47 | - | ||
3964 | 48 | - dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "o", &array); | ||
3965 | 49 | - objects_foreach_item (self, locked, NULL, on_object_path_append_to_iter, &array); | ||
3966 | 50 | - dbus_message_iter_close_container (&iter, &array); | ||
3967 | 51 | + /* Filter out the locked items */ | ||
3968 | 52 | + if (separate_locked) { | ||
3969 | 53 | + item_cleanup_search_results (session, items, &locked, &unlocked); | ||
3970 | 54 | + | ||
3971 | 55 | + dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "o", &array); | ||
3972 | 56 | + objects_foreach_item (self, unlocked, NULL, on_object_path_append_to_iter, &array); | ||
3973 | 57 | + dbus_message_iter_close_container (&iter, &array); | ||
3974 | 58 | + | ||
3975 | 59 | + dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "o", &array); | ||
3976 | 60 | + objects_foreach_item (self, locked, NULL, on_object_path_append_to_iter, &array); | ||
3977 | 61 | + dbus_message_iter_close_container (&iter, &array); | ||
3978 | 62 | + | ||
3979 | 63 | + g_list_free (locked); | ||
3980 | 64 | + g_list_free (unlocked); | ||
3981 | 65 | + | ||
3982 | 66 | + } else { | ||
3983 | 67 | + dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "o", &array); | ||
3984 | 68 | + objects_foreach_item (self, items, NULL, on_object_path_append_to_iter, &array); | ||
3985 | 69 | + dbus_message_iter_close_container (&iter, &array); | ||
3986 | 70 | + } | ||
3987 | 71 | |||
3988 | 72 | - g_list_free (locked); | ||
3989 | 73 | - g_list_free (unlocked); | ||
3990 | 74 | gck_list_unref_free (items); | ||
3991 | 75 | |||
3992 | 76 | return reply; | ||
3993 | 77 | --- a/daemon/dbus/gkd-secret-objects.h | ||
3994 | 78 | +++ b/daemon/dbus/gkd-secret-objects.h | ||
3995 | 79 | @@ -55,7 +55,8 @@ | ||
3996 | 80 | |||
3997 | 81 | DBusMessage* gkd_secret_objects_handle_search_items (GkdSecretObjects *self, | ||
3998 | 82 | DBusMessage *message, | ||
3999 | 83 | - const gchar *base); | ||
4000 | 84 | + const gchar *base, | ||
4001 | 85 | + gboolean separate_locked); | ||
4002 | 86 | |||
4003 | 87 | DBusMessage* gkd_secret_objects_handle_get_secrets (GkdSecretObjects *self, | ||
4004 | 88 | DBusMessage *message); | ||
4005 | 89 | --- a/daemon/dbus/gkd-secret-service.c | ||
4006 | 90 | +++ b/daemon/dbus/gkd-secret-service.c | ||
4007 | 91 | @@ -913,7 +913,7 @@ | ||
4008 | 92 | |||
4009 | 93 | /* org.freedesktop.Secret.Service.SearchItems() */ | ||
4010 | 94 | if (dbus_message_is_method_call (message, SECRET_SERVICE_INTERFACE, "SearchItems")) | ||
4011 | 95 | - return gkd_secret_objects_handle_search_items (self->objects, message, NULL); | ||
4012 | 96 | + return gkd_secret_objects_handle_search_items (self->objects, message, NULL, TRUE); | ||
4013 | 97 | |||
4014 | 98 | /* org.freedesktop.Secret.Service.GetSecrets() */ | ||
4015 | 99 | if (dbus_message_is_method_call (message, SECRET_SERVICE_INTERFACE, "GetSecrets")) | ||
4016 | 0 | 100 | ||
4017 | === modified file 'debian/patches/series' | |||
4018 | --- debian/patches/series 2012-05-16 17:39:27 +0000 | |||
4019 | +++ debian/patches/series 2013-03-14 13:26:21 +0000 | |||
4020 | @@ -1,2 +1,4 @@ | |||
4021 | 1 | 00git_fix_searchitems_method.patch | ||
4022 | 2 | 00git_fix_introspection.patch | ||
4023 | 1 | 03_kfreebsd.patch | 3 | 03_kfreebsd.patch |
4024 | 2 | 04_nodisplay_autostart.patch | 4 | 04_nodisplay_autostart.patch |
FWIW, I've also reviewed all the implementations I know to make sure this doesn't cause any regressions:
- libsecret: expect the *right* behavior (confirmed by Stef Walter); secretstorage: handles both cases correctly;
- python-
- ubuntu-sso-client, python-keyring: do not use that function at all.