summaryrefslogtreecommitdiff
path: root/gnome-keyring.h
blob: 4e9b3ba1226613885daaeec5010010f99544ea71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* gnome-keyring.h - library for talking to the keyring daemon.

   Copyright (C) 2003 Red Hat, Inc

   The Gnome Keyring Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   The Gnome Keyring Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with the Gnome Library; see the file COPYING.LIB.  If not,
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.

   Author: Alexander Larsson <alexl@redhat.com>
*/

#ifndef GNOME_KEYRING_H
#define GNOME_KEYRING_H

#include <glib.h>
#include <time.h>

typedef enum {
	GNOME_KEYRING_RESULT_OK,
	GNOME_KEYRING_RESULT_DENIED,
	GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON,
	GNOME_KEYRING_RESULT_ALREADY_UNLOCKED,
	GNOME_KEYRING_RESULT_NO_SUCH_KEYRING,
	GNOME_KEYRING_RESULT_BAD_ARGUMENTS,
	GNOME_KEYRING_RESULT_IO_ERROR,
	GNOME_KEYRING_RESULT_CANCELLED,
	GNOME_KEYRING_RESULT_ALREADY_EXISTS
} GnomeKeyringResult;

typedef enum {
	GNOME_KEYRING_ITEM_GENERIC_SECRET,
	GNOME_KEYRING_ITEM_NETWORK_PASSWORD,
	GNOME_KEYRING_ITEM_NOTE,
	
	GNOME_KEYRING_ITEM_LAST_TYPE,
	
	GNOME_KEYRING_ITEM_NO_TYPE = 0xffffffff,
} GnomeKeyringItemType;

typedef enum {
	GNOME_KEYRING_ACCESS_ASK,
	GNOME_KEYRING_ACCESS_DENY,
	GNOME_KEYRING_ACCESS_ALLOW
} GnomeKeyringAccessRestriction;

typedef enum {
	GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
	GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32
} GnomeKeyringAttributeType;

typedef struct GnomeKeyringAccessControl GnomeKeyringAccessControl;
typedef struct GnomeKeyringApplicationRef GnomeKeyringApplicationRef;
typedef GArray GnomeKeyringAttributeList;

typedef enum {
	GNOME_KEYRING_ACCESS_READ = 1<<0,
	GNOME_KEYRING_ACCESS_WRITE = 1<<1,
	GNOME_KEYRING_ACCESS_REMOVE = 1<<2
} GnomeKeyringAccessType;

typedef struct GnomeKeyringInfo GnomeKeyringInfo;
typedef struct GnomeKeyringItemInfo GnomeKeyringItemInfo;

typedef struct {
	char *name;
	GnomeKeyringAttributeType type;
	union {
		char *string;
		guint32 integer;
	} value;
} GnomeKeyringAttribute;

typedef struct {
	char *keyring;
	guint item_id;
	GnomeKeyringAttributeList *attributes;
	char *secret;
} GnomeKeyringFound;

typedef void (*GnomeKeyringOperationDoneCallback)           (GnomeKeyringResult result,
							     gpointer           data);
typedef void (*GnomeKeyringOperationGetStringCallback)      (GnomeKeyringResult result,
							     const char        *string,
							     gpointer           data);
typedef void (*GnomeKeyringOperationGetIntCallback)         (GnomeKeyringResult result,
							     guint32            val,
							     gpointer           data);
typedef void (*GnomeKeyringOperationGetListCallback)        (GnomeKeyringResult result,
							     GList             *list,
							     gpointer           data);
typedef void (*GnomeKeyringOperationGetKeyringInfoCallback) (GnomeKeyringResult result,
							     GnomeKeyringInfo  *info,
							     gpointer           data);
typedef void (*GnomeKeyringOperationGetItemInfoCallback)    (GnomeKeyringResult   result,
							     GnomeKeyringItemInfo*info,
							     gpointer             data);
typedef void (*GnomeKeyringOperationGetAttributesCallback)  (GnomeKeyringResult   result,
							     GnomeKeyringAttributeList *attributes,
							     gpointer             data);

#define gnome_keyring_attribute_list_index(a, i) g_array_index ((a), GnomeKeyringAttribute, (i))
#define gnome_keyring_attribute_list_new() (g_array_new (FALSE, FALSE, sizeof (GnomeKeyringAttribute)))
void                       gnome_keyring_attribute_list_append_string (GnomeKeyringAttributeList *attributes,
								       const char                *attribute,
								       const char                *value);
void                       gnome_keyring_attribute_list_append_uint32 (GnomeKeyringAttributeList *attributes,
								       const char                *attribute,
								       guint32                    value);
void                       gnome_keyring_attribute_list_free          (GnomeKeyringAttributeList *attributes);
GnomeKeyringAttributeList *gnome_keyring_attribute_list_copy          (GnomeKeyringAttributeList *attributes);


gboolean gnome_keyring_is_available (void);

void gnome_keyring_free_password (char *password);

void gnome_keyring_found_free (GnomeKeyringFound *found);
void gnome_keyring_found_list_free (GList *found_list);

void gnome_keyring_cancel_request (gpointer request);

gpointer           gnome_keyring_set_default_keyring      (const char                              *keyring,
							   GnomeKeyringOperationDoneCallback        callback,
							   gpointer                                 data,
							   GDestroyNotify                           destroy_data);
GnomeKeyringResult gnome_keyring_set_default_keyring_sync (const char                              *keyring);
gpointer           gnome_keyring_get_default_keyring      (GnomeKeyringOperationGetStringCallback   callback,
							   gpointer                                 data,
							   GDestroyNotify                           destroy_data);
GnomeKeyringResult gnome_keyring_get_default_keyring_sync (char                                   **keyring);
gpointer           gnome_keyring_list_keyring_names       (GnomeKeyringOperationGetListCallback     callback,
						           gpointer                                 data,
							   GDestroyNotify                           destroy_data);
GnomeKeyringResult gnome_keyring_list_keyring_names_sync  (GList                                  **keyrings);
gpointer           gnome_keyring_lock_all                 (GnomeKeyringOperationDoneCallback        callback,
							   gpointer                                 data,
							   GDestroyNotify                           destroy_data);
GnomeKeyringResult gnome_keyring_lock_all_sync            (void);


/* NULL password means ask user */
gpointer           gnome_keyring_create             (const char                                   *keyring_name,
						     const char                                   *password,
						     GnomeKeyringOperationDoneCallback             callback,
						     gpointer                                      data,
						     GDestroyNotify                                destroy_data);
GnomeKeyringResult gnome_keyring_create_sync        (const char                                   *keyring_name,
					             const char                                   *password);
gpointer           gnome_keyring_unlock             (const char                                   *keyring,
						     const char                                   *password,
						     GnomeKeyringOperationDoneCallback             callback,
						     gpointer                                      data,
						     GDestroyNotify                                destroy_data);
GnomeKeyringResult gnome_keyring_unlock_sync        (const char                                   *keyring,
						     const char                                   *password);
gpointer           gnome_keyring_lock               (const char                                   *keyring,
						     GnomeKeyringOperationDoneCallback             callback,
						     gpointer                                      data,
						     GDestroyNotify                                destroy_data);
GnomeKeyringResult gnome_keyring_lock_sync          (const char                                   *keyring);
gpointer           gnome_keyring_delete             (const char                                   *keyring,
						     GnomeKeyringOperationDoneCallback             callback,
						     gpointer                                      data,
						     GDestroyNotify                                destroy_data);
GnomeKeyringResult gnome_keyring_delete_sync        (const char                                   *keyring);
gpointer           gnome_keyring_change_password             (const char                                   *keyring,
						     const char                                   *original,
						     const char                                   *password,
						     GnomeKeyringOperationDoneCallback             callback,
						     gpointer                                      data,
						     GDestroyNotify                                destroy_data);
GnomeKeyringResult gnome_keyring_change_password_sync        (const char                                   *keyring,
							 const char								   *original,
						     const char                                   *password);
gpointer           gnome_keyring_get_info           (const char                                   *keyring,
						     GnomeKeyringOperationGetKeyringInfoCallback   callback,
						     gpointer                                      data,
						     GDestroyNotify                                destroy_data);
GnomeKeyringResult gnome_keyring_get_info_sync      (const char                                   *keyring,
						     GnomeKeyringInfo                            **info);
gpointer           gnome_keyring_set_info           (const char                                   *keyring,
						     GnomeKeyringInfo                             *info,
						     GnomeKeyringOperationDoneCallback             callback,
						     gpointer                                      data,
						     GDestroyNotify                                destroy_data);
GnomeKeyringResult gnome_keyring_set_info_sync      (const char                                   *keyring,
						     GnomeKeyringInfo                             *info);
gpointer           gnome_keyring_list_item_ids      (const char                                   *keyring,
						     GnomeKeyringOperationGetListCallback          callback,
						     gpointer                                      data,
						     GDestroyNotify                                destroy_data);
GnomeKeyringResult gnome_keyring_list_item_ids_sync (const char                                   *keyring,
						     GList                                       **ids);

GnomeKeyringResult gnome_keyring_daemon_set_display_sync (const char *display);


void              gnome_keyring_info_free             (GnomeKeyringInfo *keyring_info);
GnomeKeyringInfo *gnome_keyring_info_copy             (GnomeKeyringInfo *keyring_info);
void              gnome_keyring_info_set_lock_on_idle (GnomeKeyringInfo *keyring_info,
						       gboolean          value);
gboolean          gnome_keyring_info_get_lock_on_idle (GnomeKeyringInfo *keyring_info);
void              gnome_keyring_info_set_lock_timeout (GnomeKeyringInfo *keyring_info,
						       guint32           value);
guint32           gnome_keyring_info_get_lock_timeout (GnomeKeyringInfo *keyring_info);
time_t            gnome_keyring_info_get_mtime        (GnomeKeyringInfo *keyring_info);
time_t            gnome_keyring_info_get_ctime        (GnomeKeyringInfo *keyring_info);
gboolean          gnome_keyring_info_get_is_locked    (GnomeKeyringInfo *keyring_info);

gpointer gnome_keyring_find_items  (GnomeKeyringItemType                  type,
				    GnomeKeyringAttributeList            *attributes,
				    GnomeKeyringOperationGetListCallback  callback,
				    gpointer                              data,
				    GDestroyNotify                        destroy_data);
gpointer gnome_keyring_find_itemsv (GnomeKeyringItemType                  type,
				    GnomeKeyringOperationGetListCallback  callback,
				    gpointer                              data,
				    GDestroyNotify                        destroy_data,
				    ...);

GnomeKeyringResult gnome_keyring_find_items_sync  (GnomeKeyringItemType        type,
						   GnomeKeyringAttributeList  *attributes,
						   GList                     **found);
GnomeKeyringResult gnome_keyring_find_itemsv_sync (GnomeKeyringItemType        type,
						   GList                     **found,
						   ...);

gpointer           gnome_keyring_item_create              (const char                                 *keyring,
							   GnomeKeyringItemType                        type,
							   const char                                 *display_name,
							   GnomeKeyringAttributeList                  *attributes,
							   const char                                 *secret,
							   gboolean                                    update_if_exists,
							   GnomeKeyringOperationGetIntCallback         callback,
							   gpointer                                    data,
							   GDestroyNotify                              destroy_data);
GnomeKeyringResult gnome_keyring_item_create_sync         (const char                                 *keyring,
							   GnomeKeyringItemType                        type,
							   const char                                 *display_name,
							   GnomeKeyringAttributeList                  *attributes,
							   const char                                 *secret,
							   gboolean                                    update_if_exists,
							   guint32                                    *item_id);
gpointer           gnome_keyring_item_delete              (const char                                 *keyring,
							   guint32                                     id,
							   GnomeKeyringOperationDoneCallback           callback,
							   gpointer                                    data,
							   GDestroyNotify                              destroy_data);
GnomeKeyringResult gnome_keyring_item_delete_sync         (const char                                 *keyring,
							   guint32                                     id);
gpointer           gnome_keyring_item_get_info            (const char                                 *keyring,
							   guint32                                     id,
							   GnomeKeyringOperationGetItemInfoCallback    callback,
							   gpointer                                    data,
							   GDestroyNotify                              destroy_data);
GnomeKeyringResult gnome_keyring_item_get_info_sync       (const char                                 *keyring,
							   guint32                                     id,
							   GnomeKeyringItemInfo                      **info);
gpointer           gnome_keyring_item_set_info            (const char                                 *keyring,
							   guint32                                     id,
							   GnomeKeyringItemInfo                       *info,
							   GnomeKeyringOperationDoneCallback           callback,
							   gpointer                                    data,
							   GDestroyNotify                              destroy_data);
GnomeKeyringResult gnome_keyring_item_set_info_sync       (const char                                 *keyring,
							   guint32                                     id,
							   GnomeKeyringItemInfo                       *info);
gpointer           gnome_keyring_item_get_attributes      (const char                                 *keyring,
							   guint32                                     id,
							   GnomeKeyringOperationGetAttributesCallback  callback,
							   gpointer                                    data,
							   GDestroyNotify                              destroy_data);
GnomeKeyringResult gnome_keyring_item_get_attributes_sync (const char                                 *keyring,
							   guint32                                     id,
							   GnomeKeyringAttributeList                 **attributes);
gpointer           gnome_keyring_item_set_attributes      (const char                                 *keyring,
							   guint32                                     id,
							   GnomeKeyringAttributeList                  *attributes,
							   GnomeKeyringOperationDoneCallback           callback,
							   gpointer                                    data,
							   GDestroyNotify                              destroy_data);
GnomeKeyringResult gnome_keyring_item_set_attributes_sync (const char                                 *keyring,
							   guint32                                     id,
							   GnomeKeyringAttributeList                  *attributes);
gpointer           gnome_keyring_item_get_acl             (const char                                 *keyring,
							   guint32                                     id,
							   GnomeKeyringOperationGetListCallback        callback,
							   gpointer                                    data,
							   GDestroyNotify                              destroy_data);
GnomeKeyringResult gnome_keyring_item_get_acl_sync        (const char                                 *keyring,
							   guint32                                     id,
							   GList                                     **acl);
gpointer           gnome_keyring_item_set_acl             (const char                                 *keyring,
							   guint32                                     id,
							   GList                                      *acl,
							   GnomeKeyringOperationDoneCallback           callback,
							   gpointer                                    data,
							   GDestroyNotify                              destroy_data);
GnomeKeyringResult gnome_keyring_item_set_acl_sync        (const char                                 *keyring,
							   guint32                                     id,
							   GList                                      *acl);



void                  gnome_keyring_item_info_free             (GnomeKeyringItemInfo *item_info);
GnomeKeyringItemInfo *gnome_keyring_item_info_new              (void);
GnomeKeyringItemInfo *gnome_keyring_item_info_copy             (GnomeKeyringItemInfo *item_info);
GnomeKeyringItemType  gnome_keyring_item_info_get_type         (GnomeKeyringItemInfo *item_info);
void                  gnome_keyring_item_info_set_type         (GnomeKeyringItemInfo *item_info,
								GnomeKeyringItemType  type);
char *                gnome_keyring_item_info_get_secret       (GnomeKeyringItemInfo *item_info);
void                  gnome_keyring_item_info_set_secret       (GnomeKeyringItemInfo *item_info,
								const char           *value);
char *                gnome_keyring_item_info_get_display_name (GnomeKeyringItemInfo *item_info);
void                  gnome_keyring_item_info_set_display_name (GnomeKeyringItemInfo *item_info,
								const char           *value);
time_t                gnome_keyring_item_info_get_mtime        (GnomeKeyringItemInfo *item_info);
time_t                gnome_keyring_item_info_get_ctime        (GnomeKeyringItemInfo *item_info);

GnomeKeyringApplicationRef * gnome_keyring_application_ref_new          (void);
GnomeKeyringApplicationRef * gnome_keyring_application_ref_copy         (const GnomeKeyringApplicationRef *app);
void                         gnome_keyring_application_ref_free         (GnomeKeyringApplicationRef       *app);

GnomeKeyringAccessControl *  gnome_keyring_access_control_new  (const GnomeKeyringApplicationRef *application,
                                  			       GnomeKeyringAccessType             types_allowed);
GnomeKeyringAccessControl *  gnome_keyring_access_control_copy (GnomeKeyringAccessControl        *ac);


void    gnome_keyring_access_control_free (GnomeKeyringAccessControl *ac);
GList * gnome_keyring_acl_copy            (GList                     *list);
void    gnome_keyring_acl_free            (GList                     *acl);


char *                gnome_keyring_item_ac_get_display_name   (GnomeKeyringAccessControl *ac);
void                  gnome_keyring_item_ac_set_display_name   (GnomeKeyringAccessControl *ac,
								const char           *value);

char *                gnome_keyring_item_ac_get_path_name      (GnomeKeyringAccessControl *ac);
void                  gnome_keyring_item_ac_set_path_name      (GnomeKeyringAccessControl *ac,
							        const char           *value);


GnomeKeyringAccessType gnome_keyring_item_ac_get_access_type   (GnomeKeyringAccessControl *ac);
void                   gnome_keyring_item_ac_set_access_type   (GnomeKeyringAccessControl *ac,
							        const GnomeKeyringAccessType value);

/* Specialized Helpers for network passwords items */

typedef struct {
	char *keyring;
	guint32 item_id;

	char *protocol;
	char *server;
	char *object;
	char *authtype;
	guint32 port;

	char *user;
	char *domain;
	char *password;
} GnomeKeyringNetworkPasswordData;

void gnome_keyring_network_password_free (GnomeKeyringNetworkPasswordData *data);
void gnome_keyring_network_password_list_free (GList *list);

gpointer           gnome_keyring_find_network_password      (const char                            *user,
							     const char                            *domain,
							     const char                            *server,
							     const char                            *object,
							     const char                            *protocol,
							     const char                            *authtype,
							     guint32                                port,
							     GnomeKeyringOperationGetListCallback   callback,
							     gpointer                               data,
							     GDestroyNotify                         destroy_data);
GnomeKeyringResult gnome_keyring_find_network_password_sync (const char                            *user,
							     const char                            *domain,
							     const char                            *server,
							     const char                            *object,
							     const char                            *protocol,
							     const char                            *authtype,
							     guint32                                port,
							     GList                                **result);
gpointer           gnome_keyring_set_network_password       (const char                            *keyring,
							     const char                            *user,
							     const char                            *domain,
							     const char                            *server,
							     const char                            *object,
							     const char                            *protocol,
							     const char                            *authtype,
							     guint32                                port,
							     const char                            *password,
							     GnomeKeyringOperationGetIntCallback    callback,
							     gpointer                               data,
							     GDestroyNotify                         destroy_data);
GnomeKeyringResult gnome_keyring_set_network_password_sync  (const char                            *keyring,
							     const char                            *user,
							     const char                            *domain,
							     const char                            *server,
							     const char                            *object,
							     const char                            *protocol,
							     const char                            *authtype,
							     guint32                                port,
							     const char                            *password,
							     guint32                               *item_id);


#endif /* GNOME_KEYRING_H */