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
|
/*
Copyright (C) 2011 Giuseppe Borzi <gborzi@ieee.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
*/
#include <gnome-keyring.h>
gchar* cleanurl( const gchar *url )
{
gchar *cleaned, *id;
gssize il = -1;
gsize lprt;
if ( ( id = g_strstr_len(url + 8,il,"/") ) != NULL )
{
lprt = id - url;
cleaned = g_strndup(url,lprt);
}
else
cleaned = g_strdup(url);
return cleaned;
}
int main( int argc, char **argv ) {
if ( argc < 4 ) {
g_print("Usage: %s url user password\n",argv[0]);
return 1;
}
if ( gnome_keyring_is_available() ) {
guint32 item_id; gchar *cleaned = cleanurl(argv[1]);
gnome_keyring_set_network_password_sync(NULL,
argv[2],
"midori",
cleaned,
NULL,
NULL,
NULL,
0,
argv[3],
&item_id);
g_free(cleaned);
g_print("Created Gnome Keyring entry # %d\n",item_id);
} else {
g_print("Gnome Keyring not available!\n");
return 1;
}
return 0;
}
|