1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* gnome-keyring-utils.c - shared utility functions
3
4 Copyright (C) 2003 Red Hat, Inc
5
6 The Gnome Keyring Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
10
11 The Gnome Keyring Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public
17 License along with the Gnome Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20
21 Author: Alexander Larsson <alexl@redhat.com>
22 */
23 #include "config.h"
24
25 #include <string.h>
26 #include <glib.h>
27 #include <glib/gi18n-lib.h>
28
29 #include "gnome-keyring.h"
30 #include "gnome-keyring-private.h"
31 #include "gnome-keyring-memory.h"
32
33 #include "egg/egg-secure-memory.h"
34
35 EGG_SECURE_DECLARE (libgnome_keyring_utils);
36
37 /**
38 * SECTION:gnome-keyring-result
39 * @title: Result Codes
40 * @short_description: Gnome Keyring Result Codes
41 *
42 * <warning>All of these APIs are deprecated. Use
43 * <ulink href="http://developer.gnome.org/libsecret/stable/">libsecret</ulink>
44 * instead.</warning>
45 *
46 * <para>
47 * Result codes used through out GNOME Keyring. Additional result codes may be
48 * added from time to time and these should be handled gracefully.
49 * </para>
50 **/
51
52 /**
53 * gnome_keyring_free_password:
54 * @password: the password to be freed
55 *
56 * Clears the memory used by password by filling with '\0' and frees the memory
57 * after doing this. You should use this function instead of g_free() for
58 * secret information.
59 *
60 * Deprecated: Use secret_password_free() instead.
61 **/
62
63 /**
64 * GnomeKeyringAccessControl:
65 *
66 * A structure which contains access control information.
67 */
68
69 /**
70 * GnomeKeyringItemType:
71 * @GNOME_KEYRING_ITEM_GENERIC_SECRET: Generic secret
72 * @GNOME_KEYRING_ITEM_NETWORK_PASSWORD: Network password
73 * @GNOME_KEYRING_ITEM_NOTE: Note
74 * @GNOME_KEYRING_ITEM_CHAINED_KEYRING_PASSWORD: Keyring password
75 * @GNOME_KEYRING_ITEM_ENCRYPTION_KEY_PASSWORD: Password for encryption key
76 * @GNOME_KEYRING_ITEM_PK_STORAGE: Key storage password
77 * @GNOME_KEYRING_ITEM_LAST_TYPE: Not used
78 *
79 * The types of items.
80 *
81 * Deprecated: Use #SecretSchema instead.
82 */
83
84 /**
85 * GnomeKeyringResult:
86 * @GNOME_KEYRING_RESULT_OK: The operation completed successfully.
87 * @GNOME_KEYRING_RESULT_DENIED: Either the user or daemon denied access.
88 * @GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON: Keyring daemon is not available.
89 * @GNOME_KEYRING_RESULT_ALREADY_UNLOCKED: Keyring was already unlocked.
90 * @GNOME_KEYRING_RESULT_NO_SUCH_KEYRING: No such keyring exists.
91 * @GNOME_KEYRING_RESULT_BAD_ARGUMENTS: Bad arguments to function.
92 * @GNOME_KEYRING_RESULT_IO_ERROR: Problem communicating with daemon.
93 * @GNOME_KEYRING_RESULT_CANCELLED: Operation was cancelled.
94 * @GNOME_KEYRING_RESULT_KEYRING_ALREADY_EXISTS: The keyring already exists.
95 * @GNOME_KEYRING_RESULT_NO_MATCH: No such match found.
96 *
97 * Various result codes returned by functions.
98 *
99 * Deprecated: Errors are returned from libsecret functions as #GError.
100 */
101
102 /**
103 * GnomeKeyringAttribute:
104 * @name: The name of the attribute.
105 * @type: The data type.
106 *
107 * An item attribute. Set <code>string</code> if data type is
108 * %GNOME_KEYRING_ATTRIBUTE_TYPE_STRING or <code>integer</code> if data type is
109 * %GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32
110 *
111 * Deprecated: libsecret only supports string attributes.
112 */
113
114 /**
115 * GnomeKeyringAccessType:
116 * @GNOME_KEYRING_ACCESS_READ: Read access
117 * @GNOME_KEYRING_ACCESS_WRITE: Write access
118 * @GNOME_KEYRING_ACCESS_REMOVE: Delete access
119 *
120 * Type of access.
121 *
122 * Deprecated: libsecret only supports string attributes.
123 */
124
125 /**
126 * GnomeKeyringAccessRestriction:
127 * @GNOME_KEYRING_ACCESS_ASK: Ask permission.
128 * @GNOME_KEYRING_ACCESS_DENY: Deny permission.
129 * @GNOME_KEYRING_ACCESS_ALLOW: Give permission.
130 *
131 * Type of access restriction.
132 *
133 * Deprecated: No permission prompts are supported.
134 */
135
136 /**
137 * GnomeKeyringNetworkPasswordData:
138 * @keyring: Keyring item stored in.
139 * @item_id: The identifier of the item.
140 * @protocol: Network protocol or scheme.
141 * @server: Server or host name.
142 * @object: Share or other object on server.
143 * @authtype: Type of authentication.
144 * @port: TCP port.
145 * @user: User name.
146 * @domain: User domain
147 * @password: The password.
148 *
149 * Network password info.
150 *
151 * Deprecated: Use #SECRET_SCHEMA_COMPAT_NETWORK instead.
152 */
153
154 void
gnome_keyring_free_password(gchar * password)155 gnome_keyring_free_password (gchar *password)
156 {
157 egg_secure_strfree (password);
158 }
159
160 /**
161 * gnome_keyring_string_list_free:
162 * @strings: (element-type utf8): A %GList of string pointers.
163 *
164 * Free a list of string pointers.
165 *
166 * Deprecated: Not needed when using libsecret.
167 **/
168 void
gnome_keyring_string_list_free(GList * strings)169 gnome_keyring_string_list_free (GList *strings)
170 {
171 g_list_foreach (strings, (GFunc) g_free, NULL);
172 g_list_free (strings);
173 }
174
175 /**
176 * gnome_keyring_result_to_message:
177 * @res: A #GnomeKeyringResult
178 *
179 * The #GNOME_KEYRING_RESULT_OK and #GNOME_KEYRING_RESULT_CANCELLED
180 * codes will return an empty string.
181 *
182 * Note that there are some results for which the application will need to
183 * take appropriate action rather than just display an error message to
184 * the user.
185 *
186 * Return value: a string suitable for display to the user for a given
187 * #GnomeKeyringResult, or an empty string if the message wouldn't make
188 * sense to a user.
189 *
190 * Deprecated: libsecret returns errors as #GError directly. Use the
191 * error message field for a description.
192 **/
193 const gchar*
gnome_keyring_result_to_message(GnomeKeyringResult res)194 gnome_keyring_result_to_message (GnomeKeyringResult res)
195 {
196 switch (res) {
197
198 /* If the caller asks for messages for these, they get what they deserve */
199 case GNOME_KEYRING_RESULT_OK:
200 case GNOME_KEYRING_RESULT_CANCELLED:
201 return "";
202
203 /* Valid displayable error messages */
204 case GNOME_KEYRING_RESULT_DENIED:
205 return _("Access Denied");
206 case GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON:
207 return _("The gnome-keyring-daemon application is not running.");
208 case GNOME_KEYRING_RESULT_IO_ERROR:
209 return _("Error communicating with gnome-keyring-daemon");
210 case GNOME_KEYRING_RESULT_ALREADY_EXISTS:
211 return _("A keyring with that name already exists");
212 case GNOME_KEYRING_RESULT_BAD_ARGUMENTS:
213 return _("Programmer error: The application sent invalid data.");
214 case GNOME_KEYRING_RESULT_NO_MATCH:
215 return _("No matching results");
216 case GNOME_KEYRING_RESULT_NO_SUCH_KEYRING:
217 return _("A keyring with that name does not exist.");
218
219 /*
220 * This would be a dumb message to display to the user, we never return
221 * this from the daemon, only here for compatibility
222 */
223 case GNOME_KEYRING_RESULT_ALREADY_UNLOCKED:
224 return _("The keyring has already been unlocked.");
225
226 default:
227 g_return_val_if_reached (NULL);
228 };
229 }
230
231 /**
232 * gnome_keyring_found_free:
233 * @found: a #GnomeKeyringFound
234 *
235 * Free the memory used by a #GnomeKeyringFound item.
236 *
237 * You usually want to use gnome_keyring_found_list_free() on the list of
238 * results.
239 *
240 * Deprecated: Deprecated: Not needed when using libsecret.
241 */
242 void
gnome_keyring_found_free(GnomeKeyringFound * found)243 gnome_keyring_found_free (GnomeKeyringFound *found)
244 {
245 if (found == NULL)
246 return;
247 g_free (found->keyring);
248 gnome_keyring_free_password (found->secret);
249 gnome_keyring_attribute_list_free (found->attributes);
250 g_free (found);
251 }
252
253 /**
254 * gnome_keyring_found_copy:
255 * @found: a #GnomeKeyringFound
256 *
257 * Copy a #GnomeKeyringFound item.
258 *
259 * Return value: (transfer full): The new #GnomeKeyringFound
260 *
261 * Deprecated: Not needed when using libsecret.
262 */
263 GnomeKeyringFound*
gnome_keyring_found_copy(GnomeKeyringFound * found)264 gnome_keyring_found_copy (GnomeKeyringFound *found)
265 {
266 GnomeKeyringFound *copy;
267
268 if (found == NULL)
269 return NULL;
270
271 copy = g_new (GnomeKeyringFound, 1);
272 copy->keyring = g_strdup (found->keyring);
273 copy->item_id = found->item_id;
274 copy->attributes = gnome_keyring_attribute_list_copy (found->attributes);
275 copy->secret = egg_secure_strdup (found->secret);
276
277 return copy;
278 }
279
280 G_DEFINE_BOXED_TYPE (GnomeKeyringFound,
281 gnome_keyring_found,
282 gnome_keyring_found_copy,
283 gnome_keyring_found_free);
284
285 /**
286 * gnome_keyring_found_list_free:
287 * @found_list: (element-type GnomeKeyringFound): a #GList of #GnomeKeyringFound
288 *
289 * Free the memory used by the #GnomeKeyringFound items in @found_list.
290 *
291 * Deprecated: Not needed when using libsecret.
292 **/
293 void
gnome_keyring_found_list_free(GList * found_list)294 gnome_keyring_found_list_free (GList *found_list)
295 {
296 g_list_foreach (found_list, (GFunc) gnome_keyring_found_free, NULL);
297 g_list_free (found_list);
298 }
299
300 /**
301 * SECTION:gnome-keyring-attributes
302 * @title: Item Attributes
303 * @short_description: Attributes of individual keyring items.
304 *
305 * <warning>All of these APIs are deprecated. Use
306 * <ulink href="http://developer.gnome.org/libsecret/stable/">libsecret</ulink>
307 * instead.</warning>
308 *
309 * Attributes allow various other pieces of information to be associated with an item.
310 * These can also be used to search for relevant items. Use gnome_keyring_item_get_attributes()
311 * or gnome_keyring_item_set_attributes().
312 *
313 * Attributes are not stored in a secret or encrypted manner by gnome-keyring. Do
314 * not store sensitive information in attributes.
315 *
316 * Each attribute has either a string, or unsigned integer value.
317 **/
318
319 /**
320 * gnome_keyring_attribute_get_string:
321 * @attribute: a #GnomeKeyringAttribute
322 *
323 * Return the string value. It is an error to call this method if
324 * @attribute.type is not #GNOME_KEYRING_ATTRIBUTE_TYPE_STRING. This method is
325 * mostly useful for language bindings which do not provide union access. In C
326 * you should just use attribute->value.string.
327 *
328 * Returns: (transfer none): The value.string pointer of @attribute. This is
329 * not a copy, do not free.
330 *
331 * Deprecated: Not needed when using libsecret.
332 **/
333 const gchar*
gnome_keyring_attribute_get_string(GnomeKeyringAttribute * attribute)334 gnome_keyring_attribute_get_string (GnomeKeyringAttribute *attribute)
335 {
336 g_return_val_if_fail (attribute->type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING, NULL);
337 return attribute->value.string;
338 }
339
340 /**
341 * gnome_keyring_attribute_get_uint32:
342 * @attribute: a #GnomeKeyringAttribute
343 *
344 * Return the uint32 value. It is an error to call this method if
345 * @attribute.type is not #GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32. This method is
346 * mostly useful for language bindings which do not provide union access. In C
347 * you should just use attribute->value.integer.
348 *
349 * Returns: The value.integer of @attribute.
350 *
351 * Deprecated: Not needed when using libsecret.
352 **/
353 guint32
gnome_keyring_attribute_get_uint32(GnomeKeyringAttribute * attribute)354 gnome_keyring_attribute_get_uint32 (GnomeKeyringAttribute *attribute)
355 {
356 g_return_val_if_fail (attribute->type == GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32, 0);
357 return attribute->value.integer;
358 }
359
360 /**
361 * gnome_keyring_attribute_free:
362 * @attribute: a #GnomeKeyringAttribute.
363 *
364 * Free the memory used by the #GnomeKeyringAttribute @attribute.
365 *
366 * Deprecated: Not needed when using libsecret.
367 **/
368 static void
gnome_keyring_attribute_free(GnomeKeyringAttribute * attribute)369 gnome_keyring_attribute_free (GnomeKeyringAttribute *attribute)
370 {
371 if (attribute == NULL)
372 return;
373
374 g_free (attribute->name);
375 if (attribute->type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) {
376 g_free (attribute->value.string);
377 }
378 g_free (attribute);
379 }
380
381 /**
382 * gnome_keyring_attribute_copy:
383 * @attribute: a #GnomeKeyringAttribute to copy.
384 *
385 * Copy a #GnomeKeyringAttribute.
386 *
387 * Return value: (transfer full): The new #GnomeKeyringAttribute
388 *
389 * Deprecated: Not needed when using libsecret.
390 **/
391 static GnomeKeyringAttribute*
gnome_keyring_attribute_copy(GnomeKeyringAttribute * attribute)392 gnome_keyring_attribute_copy (GnomeKeyringAttribute *attribute)
393 {
394 GnomeKeyringAttribute *copy;
395
396 if (attribute == NULL)
397 return NULL;
398
399 copy = g_new (GnomeKeyringAttribute, 1);
400 copy->name = g_strdup (attribute->name);
401 copy->type = attribute->type;
402 if (attribute->type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) {
403 copy->value.string = g_strdup (attribute->value.string);
404 } else {
405 copy->value.integer = attribute->value.integer;
406 }
407
408 return copy;
409 }
410
411 G_DEFINE_BOXED_TYPE (GnomeKeyringAttribute,
412 gnome_keyring_attribute,
413 gnome_keyring_attribute_copy,
414 gnome_keyring_attribute_free);
415
416
417 /**
418 * gnome_keyring_attribute_list_append_string:
419 * @attributes: A #GnomeKeyringAttributeList
420 * @name: The name of the new attribute
421 * @value: The value to store in @attributes
422 *
423 * Store a key-value-pair with a string value in @attributes.
424 *
425 * Deprecated: libsecret stores attributes as a #GHashTable containing
426 * string keys and values, use g_hash_table_replace() instead.
427 **/
428 void
gnome_keyring_attribute_list_append_string(GnomeKeyringAttributeList * attributes,const char * name,const char * value)429 gnome_keyring_attribute_list_append_string (GnomeKeyringAttributeList *attributes,
430 const char *name, const char *value)
431 {
432 GnomeKeyringAttribute attribute;
433
434 g_return_if_fail (attributes);
435 g_return_if_fail (name);
436
437 attribute.name = g_strdup (name);
438 attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
439 attribute.value.string = g_strdup (value);
440
441 g_array_append_val (attributes, attribute);
442 }
443
444 /**
445 * gnome_keyring_attribute_list_append_uint32:
446 * @attributes: A #GnomeKeyringAttributeList
447 * @name: The name of the new attribute
448 * @value: The value to store in @attributes
449 *
450 * Store a key-value-pair with an unsigned 32bit number value in @attributes.
451 *
452 * Deprecated: libsecret does not support number attributes.
453 **/
454 void
gnome_keyring_attribute_list_append_uint32(GnomeKeyringAttributeList * attributes,const char * name,guint32 value)455 gnome_keyring_attribute_list_append_uint32 (GnomeKeyringAttributeList *attributes,
456 const char *name, guint32 value)
457 {
458 GnomeKeyringAttribute attribute;
459
460 g_return_if_fail (attributes);
461 g_return_if_fail (name);
462
463 attribute.name = g_strdup (name);
464 attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32;
465 attribute.value.integer = value;
466 g_array_append_val (attributes, attribute);
467 }
468
469 /**
470 * gnome_keyring_attribute_list_new:
471 *
472 * Create a new #GnomeKeyringAttributeList.
473 *
474 * Return value: (transfer full): The new #GnomeKeyringAttributeList
475 *
476 * Deprecated: libsecret stores attributes as a #GHashTable containing
477 * string keys and values; use g_hash_table_new() instead.
478 **/
479 GnomeKeyringAttributeList *
gnome_keyring_attribute_list_new(void)480 gnome_keyring_attribute_list_new (void)
481 {
482 return g_array_new (FALSE, FALSE, sizeof (GnomeKeyringAttribute));
483 }
484
485 /**
486 * gnome_keyring_attribute_list_free:
487 * @attributes: A #GnomeKeyringAttributeList
488 *
489 * Free the memory used by @attributes.
490 *
491 * If a %NULL pointer is passed, it is ignored.
492 *
493 * Deprecated: libsecret stores attributes as a #GHashTable containing
494 * string keys and values, use g_hash_table_unref() instead.
495 **/
496 void
gnome_keyring_attribute_list_free(GnomeKeyringAttributeList * attributes)497 gnome_keyring_attribute_list_free (GnomeKeyringAttributeList *attributes)
498 {
499 GnomeKeyringAttribute *array;
500 int i;
501
502 if (attributes == NULL)
503 return;
504
505 array = (GnomeKeyringAttribute *)attributes->data;
506 for (i = 0; i < attributes->len; i++) {
507 g_free (array[i].name);
508 if (array[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) {
509 g_free (array[i].value.string);
510 }
511 }
512
513 g_array_free (attributes, TRUE);
514 }
515
516 /**
517 * gnome_keyring_attribute_list_copy:
518 * @attributes: A #GnomeKeyringAttributeList to copy.
519 *
520 * Copy a list of item attributes.
521 *
522 * Return value: (transfer full): The new #GnomeKeyringAttributeList
523 *
524 * Deprecated: Not needed when using libsecret.
525 **/
526 GnomeKeyringAttributeList *
gnome_keyring_attribute_list_copy(GnomeKeyringAttributeList * attributes)527 gnome_keyring_attribute_list_copy (GnomeKeyringAttributeList *attributes)
528 {
529 GnomeKeyringAttribute *array;
530 GnomeKeyringAttributeList *copy;
531 int i;
532
533 if (attributes == NULL)
534 return NULL;
535
536 copy = g_array_sized_new (FALSE, FALSE, sizeof (GnomeKeyringAttribute), attributes->len);
537
538 copy->len = attributes->len;
539 memcpy (copy->data, attributes->data, sizeof (GnomeKeyringAttribute) * attributes->len);
540
541 array = (GnomeKeyringAttribute *)copy->data;
542 for (i = 0; i < copy->len; i++) {
543 array[i].name = g_strdup (array[i].name);
544 if (array[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) {
545 array[i].value.string = g_strdup (array[i].value.string);
546 }
547 }
548 return copy;
549 }
550
551 /**
552 * gnome_keyring_attribute_list_to_glist:
553 * @attributes: A #GnomeKeyringAttributeList
554 *
555 * Create #GList of #GnomeKeyringAttribute pointers from @attributes. This is
556 * mostly useful in language bindings which cannot directly use a #GArray.
557 *
558 * Returns: (transfer full) (element-type GnomeKeyringAttribute): #GList
559 * of #GnomeKeyringAttribute.
560 *
561 * Since: 3.4
562 *
563 * Deprecated: Not needed when using libsecret.
564 **/
565 GList*
gnome_keyring_attribute_list_to_glist(GnomeKeyringAttributeList * attributes)566 gnome_keyring_attribute_list_to_glist (GnomeKeyringAttributeList *attributes)
567 {
568 GList *list = NULL;
569 GnomeKeyringAttribute *attr;
570 guint i;
571
572 if (attributes == NULL)
573 return NULL;
574
575 for (i = 0; i < attributes->len; ++i) {
576 attr = &g_array_index (attributes, GnomeKeyringAttribute, i);
577 list = g_list_append (list, gnome_keyring_attribute_copy (attr));
578 }
579
580 return list;
581 }
582
583 G_DEFINE_BOXED_TYPE (GnomeKeyringAttributeList,
584 gnome_keyring_attribute_list,
585 gnome_keyring_attribute_list_copy,
586 gnome_keyring_attribute_list_free);
587
588 /**
589 * SECTION:gnome-keyring-keyring-info
590 * @title: Keyring Info
591 * @short_description: Keyring Information
592 *
593 * <warning>All of these APIs are deprecated. Use
594 * <ulink href="http://developer.gnome.org/libsecret/stable/">libsecret</ulink>
595 * instead.</warning>
596 *
597 * Use gnome_keyring_get_info() or gnome_keyring_get_info_sync() to get a #GnomeKeyringInfo
598 * pointer to use with these functions.
599 **/
600
601 /**
602 * gnome_keyring_info_free:
603 * @keyring_info: The keyring info to free.
604 *
605 * Free a #GnomeKeyringInfo object. If a %NULL pointer is passed
606 * nothing occurs.
607 *
608 * Deprecated: Use #SecretCollection objects instead.
609 **/
610 void
gnome_keyring_info_free(GnomeKeyringInfo * keyring_info)611 gnome_keyring_info_free (GnomeKeyringInfo *keyring_info)
612 {
613 g_free (keyring_info);
614 }
615
616 /**
617 * SECTION:gnome-keyring-item-info
618 * @title: Item Information
619 * @short_description: Keyring Item Info
620 *
621 * <warning>All of these APIs are deprecated. Use
622 * <ulink href="http://developer.gnome.org/libsecret/stable/">libsecret</ulink>
623 * instead.</warning>
624 *
625 * #GnomeKeyringItemInfo represents the basic information about a keyring item.
626 * Use gnome_keyring_item_get_info() or gnome_keyring_item_set_info().
627 **/
628
629 /**
630 * gnome_keyring_info_copy:
631 * @keyring_info: The keyring info to copy.
632 *
633 * Copy a #GnomeKeyringInfo object.
634 *
635 * Return value: The newly allocated #GnomeKeyringInfo. This must be freed with
636 * gnome_keyring_info_free()
637 *
638 * Deprecated: Use #SecretCollection objects instead.
639 **/
640 GnomeKeyringInfo *
gnome_keyring_info_copy(GnomeKeyringInfo * keyring_info)641 gnome_keyring_info_copy (GnomeKeyringInfo *keyring_info)
642 {
643 GnomeKeyringInfo *copy;
644
645 if (keyring_info == NULL)
646 return NULL;
647
648 copy = g_new (GnomeKeyringInfo, 1);
649 memcpy (copy, keyring_info, sizeof (GnomeKeyringInfo));
650
651 return copy;
652 }
653
654 G_DEFINE_BOXED_TYPE (GnomeKeyringInfo,
655 gnome_keyring_info,
656 gnome_keyring_info_copy,
657 gnome_keyring_info_free);
658
659 /**
660 * gnome_keyring_item_info_free:
661 * @item_info: The keyring item info pointer.
662 *
663 * Free the #GnomeKeyringItemInfo object.
664 *
665 * A %NULL pointer may be passed, in which case it will be ignored.
666 *
667 * Deprecated: Use #SecretItem objects instead.
668 **/
669 void
gnome_keyring_item_info_free(GnomeKeyringItemInfo * item_info)670 gnome_keyring_item_info_free (GnomeKeyringItemInfo *item_info)
671 {
672 if (item_info != NULL) {
673 g_free (item_info->display_name);
674 gnome_keyring_free_password (item_info->secret);
675 g_free (item_info);
676 }
677 }
678
679 /**
680 * gnome_keyring_item_info_new:
681 *
682 * Create a new #GnomeKeyringItemInfo object.
683 * Free the #GnomeKeyringItemInfo object.
684 *
685 * Return value: A keyring item info pointer.
686 *
687 * Deprecated: Use #SecretItem objects instead.
688 **/
689 GnomeKeyringItemInfo *
gnome_keyring_item_info_new(void)690 gnome_keyring_item_info_new (void)
691 {
692 GnomeKeyringItemInfo *info;
693
694 info = g_new0 (GnomeKeyringItemInfo, 1);
695
696 info->type = GNOME_KEYRING_ITEM_NO_TYPE;
697
698 return info;
699 }
700
701 /**
702 * gnome_keyring_item_info_copy:
703 * @item_info: A keyring item info pointer.
704 *
705 * Copy a #GnomeKeyringItemInfo object.
706 *
707 * Return value: A keyring item info pointer.
708 *
709 * Deprecated: Use #SecretItem objects instead.
710 **/
711 GnomeKeyringItemInfo *
gnome_keyring_item_info_copy(GnomeKeyringItemInfo * item_info)712 gnome_keyring_item_info_copy (GnomeKeyringItemInfo *item_info)
713 {
714 GnomeKeyringItemInfo *copy;
715
716 if (item_info == NULL)
717 return NULL;
718
719 copy = g_new (GnomeKeyringItemInfo, 1);
720 memcpy (copy, item_info, sizeof (GnomeKeyringItemInfo));
721
722 copy->display_name = g_strdup (item_info->display_name);
723 copy->secret = egg_secure_strdup (item_info->secret);
724
725 return copy;
726 }
727
728 /* gnome_keyring_item_info_get_type() is already part of the API, cannot use
729 * G_DEFINE_BOXED_TYPE here */
730 GType
gnome_keyring_item_info_get_gtype(void)731 gnome_keyring_item_info_get_gtype (void)
732 {
733 static volatile gsize initialized = 0;
734 static GType type = 0;
735
736 if (g_once_init_enter (&initialized)) {
737 type = g_boxed_type_register_static ("GnomeKeyringItemInfo",
738 (GBoxedCopyFunc) gnome_keyring_item_info_copy,
739 (GBoxedFreeFunc) gnome_keyring_item_info_free);
740 g_once_init_leave (&initialized, 1);
741 }
742
743 return type;
744 }
745
746 /**
747 * gnome_keyring_application_ref_new:
748 *
749 * Create a new application reference.
750 *
751 * Return value: A new #GnomeKeyringApplicationRef pointer.
752 *
753 * Deprecated: Not needed when using libsecret.
754 **/
755 GnomeKeyringApplicationRef *
gnome_keyring_application_ref_new(void)756 gnome_keyring_application_ref_new (void)
757 {
758 GnomeKeyringApplicationRef *app_ref;
759
760 app_ref = g_new0 (GnomeKeyringApplicationRef, 1);
761
762 return app_ref;
763 }
764
765 /**
766 * gnome_keyring_application_ref_free:
767 * @app: A #GnomeKeyringApplicationRef pointer
768 *
769 * Free an application reference.
770 *
771 * Deprecated: Not needed when using libsecret.
772 **/
773 void
gnome_keyring_application_ref_free(GnomeKeyringApplicationRef * app)774 gnome_keyring_application_ref_free (GnomeKeyringApplicationRef *app)
775 {
776 if (app) {
777 g_free (app->display_name);
778 g_free (app->pathname);
779 g_free (app);
780 }
781 }
782
783 /**
784 * gnome_keyring_application_ref_copy:
785 * @app: A #GnomeKeyringApplicationRef pointer
786 *
787 * Copy an application reference.
788 *
789 * Return value: A new #GnomeKeyringApplicationRef pointer.
790 *
791 * Deprecated: Not needed when using libsecret.
792 **/
793 GnomeKeyringApplicationRef *
gnome_keyring_application_ref_copy(const GnomeKeyringApplicationRef * app)794 gnome_keyring_application_ref_copy (const GnomeKeyringApplicationRef *app)
795 {
796 GnomeKeyringApplicationRef *copy;
797
798 if (app == NULL)
799 return NULL;
800
801 copy = g_new (GnomeKeyringApplicationRef, 1);
802 copy->display_name = g_strdup (app->display_name);
803 copy->pathname = g_strdup (app->pathname);
804
805 return copy;
806 }
807
808 G_DEFINE_BOXED_TYPE (GnomeKeyringApplicationRef,
809 gnome_keyring_application_ref,
810 gnome_keyring_application_ref_copy,
811 gnome_keyring_application_ref_free);
812
813 /**
814 * gnome_keyring_access_control_new:
815 * @application: A #GnomeKeyringApplicationRef pointer
816 * @types_allowed: Access types allowed.
817 *
818 * Create a new access control for an item. Combine the various access
819 * rights allowed.
820 *
821 * Return value: The new #GnomeKeyringAccessControl pointer. Use
822 * gnome_keyring_access_control_free() to free the memory.
823 *
824 * Deprecated: Not needed when using libsecret.
825 **/
826 GnomeKeyringAccessControl *
gnome_keyring_access_control_new(const GnomeKeyringApplicationRef * application,GnomeKeyringAccessType types_allowed)827 gnome_keyring_access_control_new (const GnomeKeyringApplicationRef *application,
828 GnomeKeyringAccessType types_allowed)
829 {
830 GnomeKeyringAccessControl *ac;
831 ac = g_new (GnomeKeyringAccessControl, 1);
832
833 ac->application = gnome_keyring_application_ref_copy (application);
834 ac->types_allowed = types_allowed;
835
836 return ac;
837 }
838
839 /**
840 * gnome_keyring_access_control_free:
841 * @ac: A #GnomeKeyringAccessControl pointer
842 *
843 * Free an access control for an item.
844 *
845 * Deprecated: Not needed when using libsecret.
846 **/
847 void
gnome_keyring_access_control_free(GnomeKeyringAccessControl * ac)848 gnome_keyring_access_control_free (GnomeKeyringAccessControl *ac)
849 {
850 if (ac == NULL)
851 return;
852 gnome_keyring_application_ref_free (ac->application);
853 g_free (ac);
854 }
855
856 /**
857 * gnome_keyring_access_control_copy:
858 * @ac: A #GnomeKeyringAccessControl pointer
859 *
860 * Copy an access control for an item.
861 *
862 * Return value: The new #GnomeKeyringAccessControl pointer. Use
863 * gnome_keyring_access_control_free() to free the memory.
864 *
865 * Deprecated: Not needed when using libsecret.
866 **/
867 GnomeKeyringAccessControl *
gnome_keyring_access_control_copy(GnomeKeyringAccessControl * ac)868 gnome_keyring_access_control_copy (GnomeKeyringAccessControl *ac)
869 {
870 GnomeKeyringAccessControl *ret;
871
872 if (ac == NULL)
873 return NULL;
874
875 ret = gnome_keyring_access_control_new (gnome_keyring_application_ref_copy (ac->application), ac->types_allowed);
876
877 return ret;
878 }
879
880 G_DEFINE_BOXED_TYPE (GnomeKeyringAccessControl,
881 gnome_keyring_access_control,
882 gnome_keyring_access_control_copy,
883 gnome_keyring_access_control_free);
884
885 /**
886 * gnome_keyring_acl_copy:
887 * @list: (element-type GnomeKeyringAccessControl): A list of
888 * #GnomeKeyringAccessControl pointers.
889 *
890 * Copy an access control list.
891 *
892 * Return value: (transfer full) (element-type GnomeKeyringAccessControl):
893 * A new list of #GnomeKeyringAccessControl items. Use gnome_keyring_acl_free()
894 * to free the memory.
895 *
896 * Deprecated: Not needed when using libsecret.
897 **/
898 GList *
gnome_keyring_acl_copy(GList * list)899 gnome_keyring_acl_copy (GList *list)
900 {
901 GList *ret, *l;
902
903 ret = g_list_copy (list);
904 for (l = ret; l != NULL; l = l->next) {
905 l->data = gnome_keyring_access_control_copy (l->data);
906 }
907
908 return ret;
909 }
910
911 /**
912 * gnome_keyring_acl_free:
913 * @acl: (element-type GnomeKeyringAccessControl): A list of
914 * #GnomeKeyringAccessControl pointers.
915 *
916 * Free an access control list.
917 *
918 * Deprecated: Not needed when using libsecret.
919 **/
920 void
gnome_keyring_acl_free(GList * acl)921 gnome_keyring_acl_free (GList *acl)
922 {
923 g_list_foreach (acl, (GFunc)gnome_keyring_access_control_free, NULL);
924 g_list_free (acl);
925 }
926
927 /**
928 * gnome_keyring_info_set_lock_on_idle:
929 * @keyring_info: The keyring info.
930 * @value: Whether to lock or not.
931 *
932 * Set whether or not to lock a keyring after a certain amount of idle time.
933 *
934 * See also gnome_keyring_info_set_lock_timeout().
935 *
936 * Deprecated: Not supported when using libsecret.
937 **/
938 void
gnome_keyring_info_set_lock_on_idle(GnomeKeyringInfo * keyring_info,gboolean value)939 gnome_keyring_info_set_lock_on_idle (GnomeKeyringInfo *keyring_info,
940 gboolean value)
941 {
942 g_return_if_fail (keyring_info);
943 keyring_info->lock_on_idle = value;
944 }
945
946 /**
947 * gnome_keyring_info_get_lock_on_idle:
948 * @keyring_info: The keyring info.
949 *
950 * Get whether or not to lock a keyring after a certain amount of idle time.
951 *
952 * See also gnome_keyring_info_get_lock_timeout().
953 *
954 * Return value: Whether to lock or not.
955 *
956 * Deprecated: Not supported when using libsecret.
957 **/
958 gboolean
gnome_keyring_info_get_lock_on_idle(GnomeKeyringInfo * keyring_info)959 gnome_keyring_info_get_lock_on_idle (GnomeKeyringInfo *keyring_info)
960 {
961 g_return_val_if_fail (keyring_info, FALSE);
962 return keyring_info->lock_on_idle;
963 }
964
965 /**
966 * gnome_keyring_info_set_lock_timeout:
967 * @keyring_info: The keyring info.
968 * @value: The lock timeout in seconds.
969 *
970 * Set the idle timeout, in seconds, after which to lock the keyring.
971 *
972 * See also gnome_keyring_info_set_lock_on_idle().
973 *
974 * Deprecated: Not supported when using libsecret.
975 **/
976 void
gnome_keyring_info_set_lock_timeout(GnomeKeyringInfo * keyring_info,guint32 value)977 gnome_keyring_info_set_lock_timeout (GnomeKeyringInfo *keyring_info,
978 guint32 value)
979 {
980 g_return_if_fail (keyring_info);
981 keyring_info->lock_timeout = value;
982 }
983
984 /**
985 * gnome_keyring_info_get_lock_timeout:
986 * @keyring_info: The keyring info.
987 *
988 * Get the idle timeout, in seconds, after which to lock the keyring.
989 *
990 * See also gnome_keyring_info_get_lock_on_idle().
991 *
992 * Return value: The idle timeout, in seconds.
993 *
994 * Deprecated: Not supported when using libsecret.
995 **/
996 guint32
gnome_keyring_info_get_lock_timeout(GnomeKeyringInfo * keyring_info)997 gnome_keyring_info_get_lock_timeout (GnomeKeyringInfo *keyring_info)
998 {
999 g_return_val_if_fail (keyring_info, 0);
1000 return keyring_info->lock_timeout;
1001 }
1002
1003 /**
1004 * gnome_keyring_info_get_mtime:
1005 * @keyring_info: The keyring info.
1006 *
1007 * Get the time at which the keyring was last modified.
1008 *
1009 * Return value: The last modified time.
1010 *
1011 * Deprecated: Use secret_collection_get_modified() instead.
1012 **/
1013 time_t
gnome_keyring_info_get_mtime(GnomeKeyringInfo * keyring_info)1014 gnome_keyring_info_get_mtime (GnomeKeyringInfo *keyring_info)
1015 {
1016 g_return_val_if_fail (keyring_info, 0);
1017 return keyring_info->mtime;
1018 }
1019
1020 /**
1021 * gnome_keyring_info_get_ctime:
1022 * @keyring_info: The keyring info.
1023 *
1024 * Get the time at which the keyring was created.
1025 *
1026 * Return value: The created time.
1027 *
1028 * Deprecated: Use secret_collection_get_created() instead.
1029 **/
1030 time_t
gnome_keyring_info_get_ctime(GnomeKeyringInfo * keyring_info)1031 gnome_keyring_info_get_ctime (GnomeKeyringInfo *keyring_info)
1032 {
1033 g_return_val_if_fail (keyring_info, 0);
1034 return keyring_info->ctime;
1035 }
1036
1037 /**
1038 * gnome_keyring_info_get_is_locked:
1039 * @keyring_info: The keyring info.
1040 *
1041 * Get whether the keyring is locked or not.
1042 *
1043 * Return value: Whether the keyring is locked or not.
1044 *
1045 * Deprecated: Use secret_collection_get_locked() instead.
1046 **/
1047 gboolean
gnome_keyring_info_get_is_locked(GnomeKeyringInfo * keyring_info)1048 gnome_keyring_info_get_is_locked (GnomeKeyringInfo *keyring_info)
1049 {
1050 g_return_val_if_fail (keyring_info, FALSE);
1051 return keyring_info->is_locked;
1052 }
1053
1054 /**
1055 * gnome_keyring_item_info_get_type:
1056 * @item_info: A keyring item info pointer.
1057 *
1058 * Get the item type.
1059 *
1060 * Return value: The item type
1061 *
1062 * Deprecated: Use secret_item_get_schema_name() instead.
1063 **/
1064 GnomeKeyringItemType
gnome_keyring_item_info_get_type(GnomeKeyringItemInfo * item_info)1065 gnome_keyring_item_info_get_type (GnomeKeyringItemInfo *item_info)
1066 {
1067 g_return_val_if_fail (item_info, 0);
1068 return item_info->type;
1069 }
1070
1071 /**
1072 * gnome_keyring_item_info_set_type:
1073 * @item_info: A keyring item info pointer.
1074 * @type: The new item type
1075 *
1076 * Set the type on an item info.
1077 *
1078 * Deprecated: Use secret_item_set_attributes() instead.
1079 **/
1080 void
gnome_keyring_item_info_set_type(GnomeKeyringItemInfo * item_info,GnomeKeyringItemType type)1081 gnome_keyring_item_info_set_type (GnomeKeyringItemInfo *item_info,
1082 GnomeKeyringItemType type)
1083 {
1084 g_return_if_fail (item_info);
1085 item_info->type = type;
1086 }
1087
1088 /**
1089 * gnome_keyring_item_info_get_secret:
1090 * @item_info: A keyring item info pointer.
1091 *
1092 * Get the item secret.
1093 *
1094 * Return value: The newly allocated string containing the item secret.
1095 *
1096 * Deprecated: Use secret_item_get_secret() instead.
1097 **/
1098 char *
gnome_keyring_item_info_get_secret(GnomeKeyringItemInfo * item_info)1099 gnome_keyring_item_info_get_secret (GnomeKeyringItemInfo *item_info)
1100 {
1101 /* XXXX For compatibility reasons we can't use secure memory here */
1102 g_return_val_if_fail (item_info, NULL);
1103 return g_strdup (item_info->secret);
1104 }
1105
1106 /**
1107 * gnome_keyring_item_info_set_secret:
1108 * @item_info: A keyring item info pointer.
1109 * @value: The new item secret
1110 *
1111 * Set the secret on an item info.
1112 *
1113 * Deprecated: Use secret_item_set_secret() instead.
1114 **/
1115 void
gnome_keyring_item_info_set_secret(GnomeKeyringItemInfo * item_info,const char * value)1116 gnome_keyring_item_info_set_secret (GnomeKeyringItemInfo *item_info,
1117 const char *value)
1118 {
1119 g_return_if_fail (item_info);
1120 gnome_keyring_free_password (item_info->secret);
1121 item_info->secret = gnome_keyring_memory_strdup (value);
1122 }
1123
1124 /**
1125 * gnome_keyring_item_info_get_display_name:
1126 * @item_info: A keyring item info pointer.
1127 *
1128 * Get the item display name.
1129 *
1130 * Return value: The newly allocated string containing the item display name.
1131 *
1132 * Deprecated: Use secret_item_get_label() instead.
1133 **/
1134 char *
gnome_keyring_item_info_get_display_name(GnomeKeyringItemInfo * item_info)1135 gnome_keyring_item_info_get_display_name (GnomeKeyringItemInfo *item_info)
1136 {
1137 g_return_val_if_fail (item_info, NULL);
1138 return g_strdup (item_info->display_name);
1139 }
1140
1141 /**
1142 * gnome_keyring_item_info_set_display_name:
1143 * @item_info: A keyring item info pointer.
1144 * @value: The new display name.
1145 *
1146 * Set the display name on an item info.
1147 *
1148 * Deprecated: Use secret_item_set_label() instead.
1149 **/
1150 void
gnome_keyring_item_info_set_display_name(GnomeKeyringItemInfo * item_info,const char * value)1151 gnome_keyring_item_info_set_display_name (GnomeKeyringItemInfo *item_info,
1152 const char *value)
1153 {
1154 g_return_if_fail (item_info);
1155 g_free (item_info->display_name);
1156 item_info->display_name = g_strdup (value);
1157 }
1158
1159 /**
1160 * gnome_keyring_item_info_get_mtime:
1161 * @item_info: A keyring item info pointer.
1162 *
1163 * Get the item last modified time.
1164 *
1165 * Return value: The item last modified time.
1166 *
1167 * Deprecated: Use secret_item_get_modified() instead.
1168 **/
1169 time_t
gnome_keyring_item_info_get_mtime(GnomeKeyringItemInfo * item_info)1170 gnome_keyring_item_info_get_mtime (GnomeKeyringItemInfo *item_info)
1171 {
1172 g_return_val_if_fail (item_info, 0);
1173 return item_info->mtime;
1174 }
1175
1176 /**
1177 * gnome_keyring_item_info_get_ctime:
1178 * @item_info: A keyring item info pointer.
1179 *
1180 * Get the item created time.
1181 *
1182 * Return value: The item created time.
1183 *
1184 * Deprecated: Use secret_item_get_created() instead.
1185 **/
1186 time_t
gnome_keyring_item_info_get_ctime(GnomeKeyringItemInfo * item_info)1187 gnome_keyring_item_info_get_ctime (GnomeKeyringItemInfo *item_info)
1188 {
1189 g_return_val_if_fail (item_info, 0);
1190 return item_info->ctime;
1191 }
1192
1193 /**
1194 * SECTION:gnome-keyring-acl
1195 * @title: Item ACLs
1196 * @short_description: Access control lists for keyring items.
1197 *
1198 * <warning>All of these APIs are deprecated. Use
1199 * <ulink href="http://developer.gnome.org/libsecret/stable/">libsecret</ulink>
1200 * instead.</warning>
1201 *
1202 * Each item has an access control list, which specifies the applications that
1203 * can read, write or delete an item. The read access applies only to reading the secret.
1204 * All applications can read other parts of the item. ACLs are accessed and changed
1205 * gnome_keyring_item_get_acl() and gnome_keyring_item_set_acl().
1206 **/
1207
1208 /**
1209 * gnome_keyring_item_ac_get_display_name:
1210 * @ac: A #GnomeKeyringAccessControl pointer.
1211 *
1212 * Get the access control application's display name.
1213 *
1214 * Return value: A newly allocated string containing the display name.
1215 *
1216 * Deprecated: Not supported when using libsecret.
1217 **/
1218 char *
gnome_keyring_item_ac_get_display_name(GnomeKeyringAccessControl * ac)1219 gnome_keyring_item_ac_get_display_name (GnomeKeyringAccessControl *ac)
1220 {
1221 g_return_val_if_fail (ac, NULL);
1222 return g_strdup (ac->application->display_name);
1223 }
1224
1225 /**
1226 * gnome_keyring_item_ac_set_display_name:
1227 * @ac: A #GnomeKeyringAccessControl pointer.
1228 * @value: The new application display name.
1229 *
1230 * Set the access control application's display name.
1231 *
1232 * Deprecated: Not supported when using libsecret.
1233 **/
1234 void
gnome_keyring_item_ac_set_display_name(GnomeKeyringAccessControl * ac,const char * value)1235 gnome_keyring_item_ac_set_display_name (GnomeKeyringAccessControl *ac,
1236 const char *value)
1237 {
1238 g_return_if_fail (ac);
1239 g_free (ac->application->display_name);
1240 ac->application->display_name = g_strdup (value);
1241 }
1242
1243 /**
1244 * gnome_keyring_item_ac_get_path_name:
1245 * @ac: A #GnomeKeyringAccessControl pointer.
1246 *
1247 * Get the access control application's full path name.
1248 *
1249 * Return value: A newly allocated string containing the display name.
1250 *
1251 * Deprecated: Not supported when using libsecret.
1252 **/
1253 char *
gnome_keyring_item_ac_get_path_name(GnomeKeyringAccessControl * ac)1254 gnome_keyring_item_ac_get_path_name (GnomeKeyringAccessControl *ac)
1255 {
1256 g_return_val_if_fail (ac, NULL);
1257 return g_strdup (ac->application->pathname);
1258 }
1259
1260 /**
1261 * gnome_keyring_item_ac_set_path_name:
1262 * @ac: A #GnomeKeyringAccessControl pointer
1263 * @value: The new application full path.
1264 *
1265 * Set the access control application's full path name.
1266 *
1267 * Deprecated: Not supported when using libsecret.
1268 **/
1269 void
gnome_keyring_item_ac_set_path_name(GnomeKeyringAccessControl * ac,const char * value)1270 gnome_keyring_item_ac_set_path_name (GnomeKeyringAccessControl *ac,
1271 const char *value)
1272 {
1273 g_return_if_fail (ac);
1274 g_free (ac->application->pathname);
1275 ac->application->pathname = g_strdup (value);
1276 }
1277
1278 /**
1279 * gnome_keyring_item_ac_get_access_type:
1280 * @ac: A #GnomeKeyringAccessControl pointer.
1281 *
1282 * Get the application access rights for the access control.
1283 *
1284 * Return value: The access rights.
1285 *
1286 * Deprecated: Not supported when using libsecret.
1287 **/
1288 GnomeKeyringAccessType
gnome_keyring_item_ac_get_access_type(GnomeKeyringAccessControl * ac)1289 gnome_keyring_item_ac_get_access_type (GnomeKeyringAccessControl *ac)
1290 {
1291 g_return_val_if_fail (ac, 0);
1292 return ac->types_allowed;
1293 }
1294
1295 /**
1296 * gnome_keyring_item_ac_set_access_type:
1297 * @ac: A #GnomeKeyringAccessControl pointer.
1298 * @value: The new access rights.
1299 *
1300 * Set the application access rights for the access control.
1301 *
1302 * Deprecated: Not supported when using libsecret.
1303 **/
1304 void
gnome_keyring_item_ac_set_access_type(GnomeKeyringAccessControl * ac,const GnomeKeyringAccessType value)1305 gnome_keyring_item_ac_set_access_type (GnomeKeyringAccessControl *ac,
1306 const GnomeKeyringAccessType value)
1307 {
1308 g_return_if_fail (ac);
1309 ac->types_allowed = value;
1310 }
1311