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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
|
Description: Reimplement using libgnome-keyring
GNOME Keyring daemon in 2.30 no longer exports the socket interface which
gnome-keyring-sharp used. This makes gnome-keyring-sharp totally useless.
.
This patch reimplements the gnome-keyring-sharp functions as a p/invoke
wrapper around libgnome-keyring. API and ABI is unchanged.
Author: Christopher Halse Rogers <christopher.halse.rogers@canonical.com>
Bug-Launchpad: https://bugs.edge.launchpad.net/ubuntu/lucid/+source/gnome-keyring-sharp/+bug/536925
Bug: https://bugzilla.novell.com/show_bug.cgi?id=589166
diff -urNad gnome-keyring-sharp-1.0.0~/Makefile.am gnome-keyring-sharp-1.0.0/Makefile.am
--- gnome-keyring-sharp-1.0.0~/Makefile.am 2008-08-09 03:36:12.000000000 +1000
+++ gnome-keyring-sharp-1.0.0/Makefile.am 2010-03-30 17:32:02.733918042 +1100
@@ -1,3 +1,2 @@
-SUBDIRS=src docs sample
+SUBDIRS=src gnome-keyring-sharp-glue docs sample
EXTRA_DIST=Gnome.Keyring.snk
-
diff -urNad gnome-keyring-sharp-1.0.0~/autogen.sh gnome-keyring-sharp-1.0.0/autogen.sh
--- gnome-keyring-sharp-1.0.0~/autogen.sh 1970-01-01 10:00:00.000000000 +1000
+++ gnome-keyring-sharp-1.0.0/autogen.sh 2010-03-30 17:32:02.733918042 +1100
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+autoreconf -v -i -s
+./configure $*
\ No newline at end of file
diff -urNad gnome-keyring-sharp-1.0.0~/configure.ac gnome-keyring-sharp-1.0.0/configure.ac
--- gnome-keyring-sharp-1.0.0~/configure.ac 2008-08-09 03:36:12.000000000 +1000
+++ gnome-keyring-sharp-1.0.0/configure.ac 2010-03-30 17:32:02.733918042 +1100
@@ -3,6 +3,9 @@
AC_INIT(src/Gnome.Keyring/Ring.cs)
AC_CANONICAL_SYSTEM
+AC_PROG_CC
+AC_PROG_LIBTOOL
+
API_VERSION=1.0
VERSION=$API_VERSION.0
@@ -47,28 +50,13 @@
GACUTIL_FLAGS='/gacdir $(DESTDIR)$(prefix)'
AC_SUBST(GACUTIL_FLAGS)
-#
-# Use D-Bus as a fallback to get the keyring socket address
-#
-AC_ARG_ENABLE(dbus,
- [ --enable-dbus[[=no/yes]] compile with D-Bus support [[default: yes]]],
- ENABLE_DBUS="$enableval")
-AM_CONDITIONAL(ENABLE_DBUS, test "x$ENABLE_DBUS" != "xno")
-
-CSFLAGS=
-DBUS_LIBS=
-if test "x$ENABLE_DBUS" != "xno" ; then
- PKG_CHECK_MODULES(DBUS, ndesk-dbus-1.0 >= 0.4, HAVE_DBUS="yes", HAVE_DBUS="no")
-
- if test "x$HAVE_DBUS" = "xno"; then
- AC_MSG_ERROR($DBUS_PKG_ERRORS: consider passing --enable-dbus=no to configure)
- fi
+PKG_CHECK_MODULES(GLIB_SHARP, [glib-sharp-2.0])
+PKG_CHECK_MODULES(GNOME_KEYRING, [gnome-keyring-1])
- CSFLAGS=" -d:WITH_DBUS "
-fi
AC_SUBST(CSFLAGS)
-AC_SUBST(DBUS_LIBS)
-
+AC_SUBST(GLIB_SHARP_LIBS)
+AC_SUBST(GNOME_KEYRING_CFLAGS)
+AC_SUBST(GNOME_KEYRING_LIBS)
AC_PATH_PROG(MDASSEMBLER, mdassembler, no)
AC_PATH_PROG(MONODOCER, monodocer, no)
@@ -91,6 +79,7 @@
src/gnome-keyring-sharp-1.0.pc
src/Gnome.Keyring/Makefile
src/Gnome.Keyring/AssemblyInfo.cs
+ gnome-keyring-sharp-glue/Makefile
docs/Makefile
sample/Makefile
])
diff -urNad gnome-keyring-sharp-1.0.0~/gnome-keyring-sharp-glue/Makefile.am gnome-keyring-sharp-1.0.0/gnome-keyring-sharp-glue/Makefile.am
--- gnome-keyring-sharp-1.0.0~/gnome-keyring-sharp-glue/Makefile.am 1970-01-01 10:00:00.000000000 +1000
+++ gnome-keyring-sharp-1.0.0/gnome-keyring-sharp-glue/Makefile.am 2010-03-30 17:32:02.733918042 +1100
@@ -0,0 +1,6 @@
+lib_LTLIBRARIES = libgnome-keyring-sharp-glue.la
+
+libgnome_keyring_sharp_glue_la_SOURCES = glue.c
+libgnome_keyring_sharp_glue_la_LDFLAGS = -module -avoid-version -no-undefined
+libgnome_keyring_sharp_glue_la_LIBADD = $(GNOME_KEYRING_LIBS)
+libgnome_keyring_sharp_glue_la_CFLAGS = $(GNOME_KEYRING_CFLAGS)
diff -urNad gnome-keyring-sharp-1.0.0~/gnome-keyring-sharp-glue/glue.c gnome-keyring-sharp-1.0.0/gnome-keyring-sharp-glue/glue.c
--- gnome-keyring-sharp-1.0.0~/gnome-keyring-sharp-glue/glue.c 1970-01-01 10:00:00.000000000 +1000
+++ gnome-keyring-sharp-1.0.0/gnome-keyring-sharp-glue/glue.c 2010-03-30 17:32:02.733918042 +1100
@@ -0,0 +1,36 @@
+#include <gnome-keyring.h>
+
+gpointer gks_attribute_list_new ()
+{
+ return gnome_keyring_attribute_list_new ();
+}
+
+gint32 gks_item_attribute_list_get_length (GnomeKeyringAttributeList *attrs)
+{
+ return (*attrs).len;
+}
+
+gboolean gks_item_attribute_list_index_is_string (GnomeKeyringAttributeList *attrs, gint32 index)
+{
+ return gnome_keyring_attribute_list_index (attrs, index).type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
+}
+
+gboolean gks_item_attribute_list_index_is_uint32 (GnomeKeyringAttributeList *attrs, gint32 index)
+{
+ return gnome_keyring_attribute_list_index (attrs, index).type == GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32;
+}
+
+char * gks_item_attribute_list_get_index_string (GnomeKeyringAttributeList *attrs, gint32 index)
+{
+ return gnome_keyring_attribute_list_index (attrs, index).value.string;
+}
+
+guint32 gks_item_attribute_list_get_index_uint32 (GnomeKeyringAttributeList *attrs, gint32 index)
+{
+ return gnome_keyring_attribute_list_index (attrs, index).value.integer;
+}
+
+char * gks_item_attribute_list_get_index_key (GnomeKeyringAttributeList *attrs, gint32 index)
+{
+ return gnome_keyring_attribute_list_index (attrs, index).name;
+}
diff -urNad gnome-keyring-sharp-1.0.0~/src/Gnome.Keyring/Makefile.am gnome-keyring-sharp-1.0.0/src/Gnome.Keyring/Makefile.am
--- gnome-keyring-sharp-1.0.0~/src/Gnome.Keyring/Makefile.am 2008-08-09 03:36:12.000000000 +1000
+++ gnome-keyring-sharp-1.0.0/src/Gnome.Keyring/Makefile.am 2010-03-30 17:32:02.733918042 +1100
@@ -10,8 +10,5 @@
KeyringInfo.cs \
NetItemData.cs \
NoteItemData.cs \
- Operation.cs \
- RequestMessage.cs \
- ResponseMessage.cs \
ResultCode.cs \
Ring.cs
diff -urNad gnome-keyring-sharp-1.0.0~/src/Gnome.Keyring/Operation.cs gnome-keyring-sharp-1.0.0/src/Gnome.Keyring/Operation.cs
--- gnome-keyring-sharp-1.0.0~/src/Gnome.Keyring/Operation.cs 2008-08-09 03:36:12.000000000 +1000
+++ gnome-keyring-sharp-1.0.0/src/Gnome.Keyring/Operation.cs 1970-01-01 10:00:00.000000000 +1000
@@ -1,54 +0,0 @@
-//
-// Gnome.Keyring.Operation.cs
-//
-// Authors:
-// Gonzalo Paniagua Javier (gonzalo@ximian.com)
-//
-// (C) Copyright 2006 Novell, Inc. (http://www.novell.com)
-//
-
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-namespace Gnome.Keyring {
- enum Operation {
- LockAll,
- SetDefaultKeyring,
- GetDefaultKeyring,
- ListKeyrings,
- CreateKeyring,
- LockKeyring,
- UnlockKeyring,
- DeleteKeyring,
- GetKeyringInfo,
- SetKeyringInfo,
- ListItems,
- Find,
- CreateItem,
- DeleteItem,
- GetItemInfo,
- SetItemInfo,
- GetItemAttributes,
- SetItemAttributes,
- GetItemACL,
- SetItemACL
- }
-}
-
diff -urNad gnome-keyring-sharp-1.0.0~/src/Gnome.Keyring/RequestMessage.cs gnome-keyring-sharp-1.0.0/src/Gnome.Keyring/RequestMessage.cs
--- gnome-keyring-sharp-1.0.0~/src/Gnome.Keyring/RequestMessage.cs 2008-08-09 03:36:12.000000000 +1000
+++ gnome-keyring-sharp-1.0.0/src/Gnome.Keyring/RequestMessage.cs 1970-01-01 10:00:00.000000000 +1000
@@ -1,173 +0,0 @@
-//
-// Gnome.Keyring.RequestMessage.cs
-//
-// Authors:
-// Gonzalo Paniagua Javier (gonzalo@ximian.com)
-//
-// (C) Copyright 2006 Novell, Inc. (http://www.novell.com)
-//
-
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Collections;
-using System.IO;
-using System.Text;
-
-namespace Gnome.Keyring {
- class RequestMessage {
- MemoryStream stream = new MemoryStream ();
- int op_start = -1;
-
- public MemoryStream Stream {
- get { return stream; }
- }
-
- public void CreateSimpleOperation (Operation op)
- {
- StartOperation (op);
- EndOperation ();
- }
-
- public void CreateSimpleOperation (Operation op, string str1)
- {
- StartOperation (op);
- Write (str1);
- EndOperation ();
- }
-
- public void CreateSimpleOperation (Operation op, string str1, string str2)
- {
- StartOperation (op);
- Write (str1);
- Write (str2);
- EndOperation ();
- }
-
- public void CreateSimpleOperation (Operation op, string str1, int i1)
- {
- StartOperation (op);
- Write (str1);
- Write (i1);
- EndOperation ();
- }
-
- public void StartOperation (Operation op)
- {
- string appname = Ring.ApplicationName;
- BinaryWriter writer = new BinaryWriter (stream);
- writer.Write (0);
-
- Write (appname);
- int curpos = (int) stream.Position;
- stream.Position = 0;
- writer = new BinaryWriter (stream);
- writer.Write (SwapBytes (curpos));
- stream.Position = curpos;
-
- op_start = (int) stream.Length;
- writer.Write (0);
- writer.Write (SwapBytes ((int) op));
- }
-
- public void EndOperation ()
- {
- int current = (int) stream.Length;
- int size = SwapBytes (current - op_start);
- stream.Position = op_start;
- BinaryWriter writer = new BinaryWriter (stream);
- writer.Write (size);
- }
-
- public void Write (string str)
- {
- WriteString (new BinaryWriter (stream), str);
- }
-
- static void WriteString (BinaryWriter writer, string str)
- {
- if (str == null) {
- writer.Write ((int) -1);
- return;
- }
- byte [] bytes = Encoding.UTF8.GetBytes (str);
- writer.Write (SwapBytes (bytes.Length));
- writer.Write (bytes);
- }
-
- public void Write (int i)
- {
- BinaryWriter writer = new BinaryWriter (stream);
- writer.Write (SwapBytes (i));
- }
-
- public void WriteAttributes (Hashtable atts)
- {
- Hashtable copy = new Hashtable ();
- foreach (string key in atts.Keys) {
- object o = atts [key];
- if (o != null)
- copy [key] = o;
-
- }
- BinaryWriter writer = new BinaryWriter (stream);
- writer.Write (SwapBytes (copy.Count));
- foreach (string key in copy.Keys) {
- object o = atts [key];
- if (o is string) {
- EncodeAttribute (writer, key, (string) o);
- } else if (o is int) {
- int i = (int) o;
- if (key == "port" && i == 0)
- continue;
- EncodeAttribute (writer, key, i);
- } else {
- throw new Exception ("Should not happen.");
- }
- }
- }
-
- static void EncodeAttribute (BinaryWriter writer, string name, string val)
- {
- WriteString (writer, name);
- writer.Write (SwapBytes ((int) AttributeType.String));
- WriteString (writer, val);
- }
-
- static void EncodeAttribute (BinaryWriter writer, string name, int val)
- {
- WriteString (writer, name);
- writer.Write (SwapBytes ((int) AttributeType.UInt32));
- writer.Write (SwapBytes (val));
- }
-
- static int SwapBytes (int i)
- {
- byte b0 = (byte) ((i >> 24) & 0xFF);
- byte b1 = (byte) ((i >> 16) & 0xFF);
- byte b2 = (byte) ((i >> 8) & 0xFF);
- byte b3 = (byte) (i & 0xFF);
- return b0 + (b1 << 8) + (b2 << 16) + (b3 << 24);
- }
-
- }
-}
-
diff -urNad gnome-keyring-sharp-1.0.0~/src/Gnome.Keyring/ResponseMessage.cs gnome-keyring-sharp-1.0.0/src/Gnome.Keyring/ResponseMessage.cs
--- gnome-keyring-sharp-1.0.0~/src/Gnome.Keyring/ResponseMessage.cs 2008-08-09 03:36:12.000000000 +1000
+++ gnome-keyring-sharp-1.0.0/src/Gnome.Keyring/ResponseMessage.cs 1970-01-01 10:00:00.000000000 +1000
@@ -1,108 +0,0 @@
-//
-// Gnome.Keyring.ResponseMessage.cs
-//
-// Authors:
-// Gonzalo Paniagua Javier (gonzalo@ximian.com)
-//
-// (C) Copyright 2006 Novell, Inc. (http://www.novell.com)
-//
-
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Collections;
-using System.IO;
-using System.Text;
-
-using Mono.Unix.Native;
-
-namespace Gnome.Keyring {
- class ResponseMessage {
- byte [] buffer;
- MemoryStream stream;
-
- public ResponseMessage (byte [] buffer)
- {
- this.buffer = buffer;
- stream = new MemoryStream (buffer);
- }
-
- public bool DataAvailable {
- get { return (stream.Position < stream.Length); }
- }
-
- public string [] GetStringList ()
- {
- int nstrings = GetInt32 ();
- string [] list = new string [nstrings];
- for (int i = 0; i < nstrings; i++) {
- list [i] = GetString ();
- }
-
- return list;
- }
-
- public string GetString ()
- {
- int len = GetInt32 ();
- if (len == -1) {
- return null;
- }
- int offset = (int) stream.Position;
- string result = Encoding.UTF8.GetString (buffer, offset, len);
- stream.Position += len;
- return result;
- }
-
- public int GetInt32 ()
- {
- byte b3 = (byte) stream.ReadByte ();
- byte b2 = (byte) stream.ReadByte ();
- byte b1 = (byte) stream.ReadByte ();
- byte b0 = (byte) stream.ReadByte ();
- return (b0 + (b1 << 8) + (b2 << 16) + (b3 << 24));
- }
-
- public DateTime GetDateTime ()
- {
- return NativeConvert.FromTimeT ((GetInt32 () << 32) + GetInt32 ());
- }
-
- public void ReadAttributes (Hashtable tbl)
- {
- int natts = GetInt32 ();
- for (int i = 0; i < natts; i++) {
- object val;
- string name = GetString ();
- AttributeType type = (AttributeType) GetInt32 ();
- if (AttributeType.String == type) {
- val = GetString ();
- } else if (type == AttributeType.UInt32) {
- val = GetInt32 ();
- } else {
- throw new Exception ("This should not happen: " + type);
- }
- tbl [name] = val;
- }
- }
- }
-}
-
diff -urNad gnome-keyring-sharp-1.0.0~/src/Gnome.Keyring/Ring.cs gnome-keyring-sharp-1.0.0/src/Gnome.Keyring/Ring.cs
--- gnome-keyring-sharp-1.0.0~/src/Gnome.Keyring/Ring.cs 2008-08-09 03:36:12.000000000 +1000
+++ gnome-keyring-sharp-1.0.0/src/Gnome.Keyring/Ring.cs 2010-03-30 17:32:02.733918042 +1100
@@ -31,16 +31,16 @@
using System;
using System.Collections;
+using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
+using System.Runtime.InteropServices;
using Mono.Unix;
-#if WITH_DBUS
-using NDesk.DBus;
-#endif
+using GLib;
namespace Gnome.Keyring {
public class Ring {
@@ -70,394 +70,579 @@
}
}
+ [DllImport ("libgnome-keyring.dll")]
+ static extern bool gnome_keyring_is_available ();
+
public static bool Available {
get {
- Socket sock = Connect ();
- if (sock != null) {
- sock.Close ();
- return true;
- }
- return false;
- }
- }
-
- static Socket Connect ()
- {
- string filename;
- Socket sock;
-
- filename = Environment.GetEnvironmentVariable ("GNOME_KEYRING_SOCKET");
- sock = Connect (filename);
-
-#if WITH_DBUS
- if (sock == null) {
- try {
- filename = Bus.Session.GetObject<IDaemon> ("org.gnome.keyring", new ObjectPath ("/org/gnome/keyring/daemon")).GetSocketPath ();
- } catch (Exception) {
- filename = null;
- }
- sock = Connect (filename);
- }
-#endif
-
- return sock;
- }
-
- static Socket Connect (string filename)
- {
- if (filename == null || filename == "")
- return null;
-
- EndPoint ep = new UnixEndPoint (filename);
- Socket sock = new Socket (AddressFamily.Unix, SocketType.Stream, ProtocolType.IP);
- try {
- sock.Connect (ep);
- } catch (Exception) {
- sock.Close ();
- return null;
- }
- return sock;
- }
-
- static int GetInt32 (Socket sock)
- {
- byte [] cuatro = new byte [4];
- if (sock.Receive (cuatro) != 4)
- throw new KeyringException (ResultCode.IOError);
- return (cuatro [3] + (cuatro [2] << 8) + (cuatro [1] << 16) + (cuatro [0] << 24));
- }
-
- static byte [] one = new byte [1];
- static ResponseMessage SendRequest (MemoryStream stream)
- {
- Socket sock = Connect ();
- if (sock == null)
- throw new KeyringException (ResultCode.NoKeyringDaemon);
-
- try {
- sock.Send (one); // Credentials byte
- byte [] buffer = stream.ToArray ();
- sock.Send (buffer);
- int packet_size = GetInt32 (sock) - 4;
- if (packet_size < 0)
- throw new KeyringException (ResultCode.IOError);
- byte [] response = new byte [packet_size];
- int nbytes = sock.Receive (response);
- if (nbytes != response.Length)
- throw new KeyringException (ResultCode.IOError);
- ResponseMessage resp = new ResponseMessage (response);
- ResultCode result = (ResultCode) resp.GetInt32 ();
- if (result != 0)
- throw new KeyringException (result);
-
- return resp;
- } finally {
- sock.Close ();
+ return gnome_keyring_is_available ();
}
}
+ [DllImport ("libgnome-keyring.dll")]
+ static extern ResultCode gnome_keyring_lock_all_sync ();
+
public static void LockAll ()
{
- RequestMessage req = new RequestMessage ();
- req.CreateSimpleOperation (Operation.LockAll);
- SendRequest (req.Stream);
+ ResultCode result = gnome_keyring_lock_all_sync ();
+ if (result != ResultCode.Ok) {
+ throw new KeyringException (result);
+ }
}
+ [DllImport ("libgnome-keyring.dll")]
+ static extern ResultCode gnome_keyring_set_default_keyring_sync (string keyring);
+
public static void SetDefaultKeyring (string newKeyring)
{
if (newKeyring == null)
throw new ArgumentNullException ("newKeyring");
- RequestMessage req = new RequestMessage ();
- req.CreateSimpleOperation (Operation.SetDefaultKeyring, newKeyring);
- SendRequest (req.Stream);
+ ResultCode result = gnome_keyring_set_default_keyring_sync (newKeyring);
+ if (result != ResultCode.Ok) {
+ throw new KeyringException (result);
+ }
}
+ [DllImport ("libgnome-keyring.dll")]
+ static extern ResultCode gnome_keyring_get_default_keyring_sync (out IntPtr keyring);
+
public static string GetDefaultKeyring ()
{
- RequestMessage req = new RequestMessage ();
- req.CreateSimpleOperation (Operation.GetDefaultKeyring);
- ResponseMessage resp = SendRequest (req.Stream);
- return resp.GetString ();
+ IntPtr keyring_name;
+ ResultCode result = gnome_keyring_get_default_keyring_sync (out keyring_name);
+ if (result != ResultCode.Ok) {
+ throw new KeyringException (result);
+ }
+ return GLib.Marshaller.PtrToStringGFree (keyring_name);
}
- public static string [] GetKeyrings ()
+ [DllImport ("libgnome-keyring.dll")]
+ static extern ResultCode gnome_keyring_list_keyring_names_sync (out IntPtr keyringList);
+
+ [DllImport ("libgnome-keyring.dll")]
+ static extern void gnome_keyring_string_list_free (IntPtr stringList);
+
+ public static string[] GetKeyrings ()
{
- RequestMessage req = new RequestMessage ();
- req.CreateSimpleOperation (Operation.ListKeyrings);
- ResponseMessage resp = SendRequest (req.Stream);
- return resp.GetStringList ();
+ IntPtr keyring_list;
+ ResultCode result = gnome_keyring_list_keyring_names_sync (out keyring_list);
+ if (result != ResultCode.Ok) {
+ throw new KeyringException (result);
+ }
+ var retval = (string[])GLib.Marshaller.ListPtrToArray (keyring_list, typeof(GLib.List), false, false, typeof(string));
+ gnome_keyring_string_list_free (keyring_list);
+ return retval;
}
+ [DllImport ("libgnome-keyring.dll")]
+ static extern ResultCode gnome_keyring_create_sync (string keyringName, string password);
+
public static void CreateKeyring (string name, string password)
{
- RequestMessage req = new RequestMessage ();
- req.CreateSimpleOperation (Operation.CreateKeyring, name, password);
- SendRequest (req.Stream);
+ ResultCode result = gnome_keyring_create_sync (name, password);
+ if (result != ResultCode.Ok) {
+ throw new KeyringException (result);
+ }
}
-
+
+ [DllImport ("libgnome-keyring.dll")]
+ static extern ResultCode gnome_keyring_lock_sync (string keyring);
+
public static void Lock (string keyring)
{
if (keyring == null)
throw new ArgumentNullException ("keyring");
- RequestMessage req = new RequestMessage ();
- req.CreateSimpleOperation (Operation.LockKeyring, keyring);
- SendRequest (req.Stream);
+ ResultCode result = gnome_keyring_lock_sync (keyring);
+ if (result != ResultCode.Ok) {
+ throw new KeyringException (result);
+ }
}
+
+ [DllImport ("libgnome-keyring.dll")]
+ static extern ResultCode gnome_keyring_unlock_sync (string keyring, string password);
public static void Unlock (string keyring, string password)
{
- if (keyring == null)
- throw new ArgumentNullException ("keyring");
-
- if (password == null)
- throw new ArgumentNullException ("password");
-
- RequestMessage req = new RequestMessage ();
- req.CreateSimpleOperation (Operation.UnlockKeyring, keyring, password);
- try {
- SendRequest (req.Stream);
- } catch (KeyringException ke) {
- if (ke.ResultCode != ResultCode.AlreadyUnlocked)
- throw;
+ ResultCode result = gnome_keyring_unlock_sync (keyring, password);
+
+ if (!(result == ResultCode.Ok || result == ResultCode.AlreadyUnlocked)) {
+ throw new KeyringException (result);
}
}
+ [DllImport ("libgnome-keyring.dll")]
+ static extern ResultCode gnome_keyring_delete_sync (string keyring);
+
public static void DeleteKeyring (string keyring)
{
if (keyring == null)
throw new ArgumentNullException ("keyring");
- RequestMessage req = new RequestMessage ();
- req.CreateSimpleOperation (Operation.DeleteKeyring, keyring);
- SendRequest (req.Stream);
+ ResultCode result = gnome_keyring_delete_sync (keyring);
+ if (result != ResultCode.Ok) {
+ throw new KeyringException (result);
+ }
}
- public static int [] ListItemIDs (string keyring)
+ [DllImport ("libgnome-keyring.dll")]
+ static extern ResultCode gnome_keyring_list_item_ids_sync (string keyring, out IntPtr ids);
+
+ public static int[] ListItemIDs (string keyring)
{
if (keyring == null)
throw new ArgumentNullException ("keyring");
- RequestMessage req = new RequestMessage ();
- req.CreateSimpleOperation (Operation.ListItems, keyring);
- ResponseMessage resp = SendRequest (req.Stream);
- int len = resp.GetInt32 ();
- int [] result = new int [len];
- for (int i = 0; i < len; i++) {
- result [i] = resp.GetInt32 ();
+ IntPtr idlist;
+ ResultCode result = gnome_keyring_list_item_ids_sync (keyring, out idlist);
+
+ if (result != ResultCode.Ok) {
+ throw new KeyringException (result);
}
-
- return result;
+
+ IntPtr[] ptrArray = (IntPtr[])GLib.Marshaller.ListPtrToArray (idlist, typeof(GLib.List), true, false, typeof(IntPtr));
+ int[] ids = new int[ptrArray.Length];
+ for (int i = 0; i < ptrArray.Length; i++) {
+ ids[i] = ptrArray[i].ToInt32 ();
+ }
+
+ return ids;
}
+
+ static void NativeListFromAttributes (IntPtr attrList, Hashtable attributes)
+ {
+ foreach (string key in attributes.Keys) {
+ if (attributes[key] is string) {
+ gnome_keyring_attribute_list_append_string (attrList, key, (string)attributes[key]);
+ } else if (attributes[key] is int) {
+ gnome_keyring_attribute_list_append_uint32 (attrList, key, (uint)((int)attributes[key]));
+ } else {
+ throw new ArgumentException (String.Format ("Attribute \"{0}\" has invalid parameter type: {1}", key, attributes[key].GetType ()));
+ }
+ }
+ }
+
+ static void AttributesFromNativeList (IntPtr attrList, Hashtable attributes)
+ {
+ int listLength = gks_item_attribute_list_get_length (attrList);
+ for (int i = 0; i < listLength; i++) {
+ string key = Marshal.PtrToStringAnsi (gks_item_attribute_list_get_index_key (attrList, i));
+ if (gks_item_attribute_list_index_is_string (attrList, i)) {
+ attributes[key] = Marshal.PtrToStringAnsi (gks_item_attribute_list_get_index_string (attrList, i));
+ } else if (gks_item_attribute_list_index_is_uint32 (attrList, i)) {
+ attributes[key] = (int)gks_item_attribute_list_get_index_uint32 (attrList, i);
+ }
+ }
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ struct GnomeKeyringFound
+ {
+ public IntPtr keyring;
+ public UInt32 item_id;
+ public IntPtr attrList;
+ public IntPtr secret;
+ }
+
+ [DllImport ("libgnome-keyring.dll")]
+ static extern ResultCode gnome_keyring_find_items_sync (ItemType type, IntPtr attrList, out IntPtr foundList);
+ [DllImport ("libgnome-keyring.dll")]
+ static extern void gnome_keyring_found_list_free (IntPtr foundList);
+
static ItemData [] empty_item_data = new ItemData [0];
- public static ItemData [] Find (ItemType type, Hashtable atts)
+ public static ItemData[] Find (ItemType type, Hashtable atts)
{
if (atts == null)
throw new ArgumentNullException ("atts");
- RequestMessage req = new RequestMessage ();
- req.StartOperation (Operation.Find);
- req.Write ((int) type);
- req.WriteAttributes (atts);
- req.EndOperation ();
-
- ResponseMessage resp = null;
- try {
- resp = SendRequest (req.Stream);
- } catch (KeyringException ke) {
- if (ke.ResultCode == ResultCode.Denied)
- return empty_item_data;
- throw;
+
+ IntPtr passwordList;
+ IntPtr attrList = gks_attribute_list_new ();
+
+ NativeListFromAttributes (attrList, atts);
+
+ ResultCode result = gnome_keyring_find_items_sync (type, attrList, out passwordList);
+
+ if (result == ResultCode.Denied) {
+ return empty_item_data;
+ }
+
+ if (result != ResultCode.Ok) {
+ throw new KeyringException (result);
+ }
+
+ IntPtr[] passwordStructs = (IntPtr[])GLib.Marshaller.ListPtrToArray (passwordList, typeof(GLib.List), false, false, typeof(IntPtr));
+ List<GnomeKeyringFound> passwords = new List<GnomeKeyringFound> ();
+
+ foreach (IntPtr ptr in passwordStructs) {
+ passwords.Add ((GnomeKeyringFound)Marshal.PtrToStructure (ptr, typeof(GnomeKeyringFound)));
}
ArrayList list = new ArrayList ();
- while (resp.DataAvailable) {
+ foreach (var password in passwords) {
ItemData found = ItemData.GetInstanceFromItemType (type);
- found.Keyring = resp.GetString ();
- found.ItemID = resp.GetInt32 ();
- found.Secret = resp.GetString ();
+ found.ItemID = (int)password.item_id;
+ found.Secret = Marshal.PtrToStringAnsi (password.secret);
+ found.Keyring = Marshal.PtrToStringAnsi (password.keyring);
found.Attributes = new Hashtable ();
- resp.ReadAttributes (found.Attributes);
+ AttributesFromNativeList (password.attrList, found.Attributes);
found.SetValuesFromAttributes ();
list.Add (found);
}
+ gnome_keyring_found_list_free (passwordList);
+ gnome_keyring_attribute_list_free (attrList);
+
return (ItemData []) list.ToArray (typeof (ItemData));
}
+ [StructLayout (LayoutKind.Sequential)]
+ struct GnomeKeyringNetworkPasswordData
+ {
+ public IntPtr keyring;
+ public UInt32 item_id;
+
+ public IntPtr protocol;
+ public IntPtr server;
+ public IntPtr @object;
+ public IntPtr authtype;
+ public UInt32 port;
+
+ public IntPtr user;
+ public IntPtr domain;
+ public IntPtr password;
+ }
+
+ [DllImport ("libgnome-keyring.dll")]
+ static extern ResultCode gnome_keyring_find_network_password_sync (string user, string domain, string server,
+ string @object, string protocol, string authtype, UInt32 port, out IntPtr passwordList);
+
static NetItemData [] empty_net_item_data = new NetItemData [0];
- public static NetItemData [] FindNetworkPassword (string user, string domain, string server, string obj,
+ public static NetItemData[] FindNetworkPassword (string user, string domain, string server, string obj,
string protocol, string authtype, int port)
{
- RequestMessage req = new RequestMessage ();
- req.StartOperation (Operation.Find);
- req.Write ((int) ItemType.NetworkPassword);
- Hashtable tbl = new Hashtable ();
- tbl ["user"] = user;
- tbl ["domain"] = domain;
- tbl ["server"] = server;
- tbl ["object"] = obj;
- tbl ["protocol"] = protocol;
- tbl ["authtype"] = authtype;
- if (port != 0)
- tbl ["port"] = port;
- req.WriteAttributes (tbl);
- req.EndOperation ();
-
- ResponseMessage resp = null;
- try {
- resp = SendRequest (req.Stream);
- } catch (KeyringException ke) {
- if (ke.ResultCode == ResultCode.Denied)
- return empty_net_item_data;
- throw;
+ IntPtr passwordList;
+
+ ResultCode result = gnome_keyring_find_network_password_sync (user, domain, server, obj, protocol, authtype, (uint)port, out passwordList);
+
+ if (result == ResultCode.Denied) {
+ return empty_net_item_data;
+ }
+
+ if (result != ResultCode.Ok) {
+ throw new KeyringException (result);
}
+
+ IntPtr[] passwordStructs = (IntPtr[])GLib.Marshaller.ListPtrToArray (passwordList, typeof(GLib.List), false, false, typeof(IntPtr));
+ List<GnomeKeyringNetworkPasswordData> passwords = new List<GnomeKeyringNetworkPasswordData> ();
+
+ foreach (IntPtr ptr in passwordStructs) {
+ passwords.Add ((GnomeKeyringNetworkPasswordData)Marshal.PtrToStructure (ptr, typeof(GnomeKeyringNetworkPasswordData)));
+ }
+
ArrayList list = new ArrayList ();
- while (resp.DataAvailable) {
+ foreach (var password in passwords) {
NetItemData found = new NetItemData ();
- found.Keyring = resp.GetString ();
- found.ItemID = resp.GetInt32 ();
- found.Secret = resp.GetString ();
+ found.Keyring = Marshal.PtrToStringAnsi (password.keyring);
+ found.ItemID = (int)password.item_id;
+ found.Secret = Marshal.PtrToStringAnsi (password.password);
found.Attributes = new Hashtable ();
- resp.ReadAttributes (found.Attributes);
+
+ SetAttributeIfNonNull (found.Attributes, "protocol", password.protocol);
+ SetAttributeIfNonNull (found.Attributes, "server", password.server);
+ SetAttributeIfNonNull (found.Attributes, "object", password.@object);
+ SetAttributeIfNonNull (found.Attributes, "authtype", password.authtype);
+ SetAttributeIfNonNull (found.Attributes, "user", password.user);
+ SetAttributeIfNonNull (found.Attributes, "domain", password.domain);
+
+ if (password.port != 0) {
+ found.Attributes["port"] = (int)password.port;
+ }
+
found.SetValuesFromAttributes ();
list.Add (found);
}
return (NetItemData []) list.ToArray (typeof (NetItemData));
}
+
+ static void SetAttributeIfNonNull (Hashtable attrs, string key, IntPtr maybeString)
+ {
+ if (maybeString != IntPtr.Zero) {
+ attrs[key] = Marshal.PtrToStringAnsi (maybeString);
+ }
+ }
+ [DllImport ("libgnome-keyring.dll")]
+ static extern ResultCode gnome_keyring_item_create_sync (string keyring,
+ ItemType type,
+ string displayName,
+ IntPtr attributes,
+ IntPtr secret,
+ bool updateIfExists,
+ out UInt32 itemId);
+
+ [DllImport ("libgnome-keyring.dll")]
+ static extern IntPtr gnome_keyring_memory_strdup (string str);
+ [DllImport ("libgnome-keyring.dll")]
+ static extern void gnome_keyring_memory_free (IntPtr str);
+ [DllImport ("libgnome-keyring.dll")]
+ static extern void gnome_keyring_attribute_list_append_string (IntPtr attributes, string name, string val);
+ [DllImport("libgnome-keyring.dll")]
+ static extern void gnome_keyring_attribute_list_append_uint32 (IntPtr attributes, string name, UInt32 val);
+ [DllImport ("libgnome-keyring.dll")]
+ static extern void gnome_keyring_attribute_list_free (IntPtr attributes);
+ [DllImport ("gnome-keyring-sharp-glue.dll")]
+ static extern IntPtr gks_attribute_list_new ();
+
public static int CreateItem (string keyring, ItemType type, string displayName, Hashtable attributes,
string secret, bool updateIfExists)
{
- RequestMessage req = new RequestMessage ();
- req.StartOperation (Operation.CreateItem);
- req.Write (keyring);
- req.Write (displayName);
- req.Write (secret);
- req.WriteAttributes (attributes);
- req.Write ((int) type);
- req.Write (updateIfExists ? 1 : 0);
- req.EndOperation ();
- ResponseMessage resp = SendRequest (req.Stream);
- return resp.GetInt32 ();
+ uint id;
+ IntPtr secure_secret = gnome_keyring_memory_strdup (secret);
+ IntPtr attrs = gks_attribute_list_new ();
+
+ NativeListFromAttributes (attrs, attributes);
+
+ ResultCode result = gnome_keyring_item_create_sync (keyring, type, displayName, attrs, secure_secret, updateIfExists, out id);
+
+ gnome_keyring_attribute_list_free (attrs);
+ gnome_keyring_memory_free (secure_secret);
+
+ if (result != ResultCode.Ok) {
+ throw new KeyringException (result);
+ }
+
+ return (int)id;
}
+ [DllImport ("libgnome-keyring.dll")]
+ static extern ResultCode gnome_keyring_item_delete_sync (string keyring, UInt32 id);
+
public static void DeleteItem (string keyring, int id)
{
if (keyring == null)
throw new ArgumentNullException ("keyring");
- RequestMessage req = new RequestMessage ();
- req.CreateSimpleOperation (Operation.DeleteItem, keyring, id);
- SendRequest (req.Stream);
+ ResultCode result = gnome_keyring_item_delete_sync (keyring, (uint)id);
+
+ if (result != ResultCode.Ok) {
+ throw new KeyringException (result);
+ }
}
+ [DllImport ("libgnome-keyring.dll")]
+ static extern ResultCode gnome_keyring_set_network_password_sync (string keyring,
+ string user,
+ string domain,
+ string server,
+ string @object,
+ string protocol,
+ string authType,
+ UInt32 port,
+ string password,
+ out UInt32 id);
+
public static int CreateOrModifyNetworkPassword (string keyring, string user, string domain, string server, string obj,
string protocol, string authtype, int port, string password)
{
- Hashtable tbl = new Hashtable ();
- tbl ["user"] = user;
- tbl ["domain"] = domain;
- tbl ["server"] = server;
- tbl ["object"] = obj;
- tbl ["protocol"] = protocol;
- tbl ["authtype"] = authtype;
- if (port != 0)
- tbl ["port"] = port;
-
- string display_name;
- if (port != 0)
- display_name = String.Format ("{0}@{1}:{3}/{2}", user, server, obj, port);
- else
- display_name = String.Format ("{0}@{1}/{2}", user, server, obj);
-
- return CreateItem (keyring, ItemType.NetworkPassword, display_name, tbl, password, true);
+ uint id;
+ ResultCode result = gnome_keyring_set_network_password_sync (keyring, user, domain, server, obj, protocol, authtype, (uint)port, password, out id);
+
+ if (result != ResultCode.Ok) {
+ throw new KeyringException (result);
+ }
+
+ return (int)id;
}
+ [DllImport ("libgnome-keyring.dll")]
+ static extern ResultCode gnome_keyring_item_get_info_sync (string keyring, UInt32 id, out IntPtr itemInfo);
+ [DllImport ("libgnome-keyring.dll")]
+ static extern ItemType gnome_keyring_item_info_get_type (IntPtr itemInfo);
+ [DllImport("libgnome-keyring.dll")]
+ static extern IntPtr gnome_keyring_item_info_get_ctime (IntPtr itemInfo);
+ [DllImport("libgnome-keyring.dll")]
+ static extern IntPtr gnome_keyring_item_info_get_mtime (IntPtr itemInfo);
+ [DllImport("libgnome-keyring.dll")]
+ static extern IntPtr gnome_keyring_item_info_get_display_name (IntPtr itemInfo);
+ [DllImport("libgnome-keyring.dll")]
+ static extern IntPtr gnome_keyring_item_info_get_secret (IntPtr itemInfo);
+ [DllImport("libgnome-keyring.dll")]
+ static extern void gnome_keyring_item_info_free (IntPtr itemInfo);
+
public static ItemData GetItemInfo (string keyring, int id)
{
if (keyring == null)
throw new ArgumentNullException ("keyring");
- RequestMessage req = new RequestMessage ();
- req.CreateSimpleOperation (Operation.GetItemInfo, keyring, id);
- ResponseMessage resp = SendRequest (req.Stream);
- ItemType itype = (ItemType) resp.GetInt32 ();
- ItemData item = ItemData.GetInstanceFromItemType (itype);
- string name = resp.GetString ();
- string secret = resp.GetString ();
- DateTime mtime = resp.GetDateTime ();
- DateTime ctime = resp.GetDateTime ();
+ IntPtr itemInfo;
+
+ ResultCode result = gnome_keyring_item_get_info_sync (keyring, (uint)id, out itemInfo);
+
+ if (result != ResultCode.Ok) {
+ throw new KeyringException (result);
+ }
+
+ ItemData item = ItemData.GetInstanceFromItemType (gnome_keyring_item_info_get_type (itemInfo));
+ item.Attributes = new Hashtable ();
+ item.Attributes["keyring_ctime"] = GLib.Marshaller.time_tToDateTime (gnome_keyring_item_info_get_ctime (itemInfo));
+ item.Attributes["keyring_mtime"] = GLib.Marshaller.time_tToDateTime (gnome_keyring_item_info_get_mtime (itemInfo));
+ item.Attributes["name"] = Marshal.PtrToStringAnsi (gnome_keyring_item_info_get_display_name (itemInfo));
+
item.Keyring = keyring;
item.ItemID = id;
- item.Secret = secret;
- Hashtable tbl = new Hashtable ();
- tbl ["name"] = name;
- tbl ["keyring_ctime"] = ctime;
- tbl ["keyring_mtime"] = mtime;
- item.Attributes = tbl;
+ item.Secret = Marshal.PtrToStringAnsi (gnome_keyring_item_info_get_secret (itemInfo));
+
item.SetValuesFromAttributes ();
+
+ gnome_keyring_item_info_free (itemInfo);
+
return item;
}
+
+ [DllImport ("libgnome-keyring.dll")]
+ static extern ResultCode gnome_keyring_item_set_info_sync (string keyring, UInt32 id, IntPtr itemInfo);
+ [DllImport ("libgnome-keyring.dll")]
+ static extern IntPtr gnome_keyring_item_info_new ();
+ [DllImport ("libgnome-keyring.dll")]
+ static extern void gnome_keyring_item_info_set_display_name (IntPtr itemInfo, string displayName);
+ [DllImport("libgnome-keyring.dll")]
+ static extern void gnome_keyring_item_info_set_type (IntPtr itemInfo, ItemType type);
+ [DllImport("libgnome-keyring.dll")]
+ static extern void gnome_keyring_item_info_set_secret (IntPtr itemInfo, string secret);
public static void SetItemInfo (string keyring, int id, ItemType type, string displayName, string secret)
{
if (keyring == null)
throw new ArgumentNullException ("keyring");
- RequestMessage req = new RequestMessage ();
- req.StartOperation (Operation.SetItemInfo);
- req.Write (keyring);
- req.Write (id);
- req.Write ((int) type);
- req.Write (displayName);
- req.Write (secret);
- req.EndOperation ();
- SendRequest (req.Stream);
+ IntPtr itemInfo = gnome_keyring_item_info_new ();
+ gnome_keyring_item_info_set_display_name (itemInfo, displayName);
+ gnome_keyring_item_info_set_type (itemInfo, type);
+ gnome_keyring_item_info_set_secret (itemInfo, secret);
+
+ ResultCode result = gnome_keyring_item_set_info_sync (keyring, (uint)id, itemInfo);
+
+ gnome_keyring_item_info_free (itemInfo);
+
+ if (result != ResultCode.Ok) {
+ throw new KeyringException (result);
+ }
}
+ [DllImport ("libgnome-keyring.dll")]
+ static extern ResultCode gnome_keyring_item_get_attributes_sync (string keyring, UInt32 id, out IntPtr attributes);
+ [DllImport ("gnome-keyring-sharp-glue.dll")]
+ static extern int gks_item_attribute_list_get_length (IntPtr attrList);
+ [DllImport ("gnome-keyring-sharp-glue.dll")]
+ static extern bool gks_item_attribute_list_index_is_string (IntPtr attrList, int index);
+ [DllImport("gnome-keyring-sharp-glue.dll")]
+ static extern bool gks_item_attribute_list_index_is_uint32 (IntPtr attrList, int index);
+ [DllImport ("gnome-keyring-sharp-glue.dll")]
+ static extern IntPtr gks_item_attribute_list_get_index_string (IntPtr attrList, int index);
+ [DllImport ("gnome-keyring-sharp-glue.dll")]
+ static extern UInt32 gks_item_attribute_list_get_index_uint32 (IntPtr attrList, int index);
+ [DllImport ("gnome-keyring-sharp-glue.dll")]
+ static extern IntPtr gks_item_attribute_list_get_index_key (IntPtr attrList, int index);
+
public static Hashtable GetItemAttributes (string keyring, int id)
{
if (keyring == null)
throw new ArgumentNullException ("keyring");
- RequestMessage req = new RequestMessage ();
- req.CreateSimpleOperation (Operation.GetItemAttributes, keyring, id);
- ResponseMessage resp = SendRequest (req.Stream);
- Hashtable tbl = new Hashtable ();
- resp.ReadAttributes (tbl);
- return tbl;
+ IntPtr attributes;
+ Hashtable retVal = new Hashtable ();
+
+ ResultCode result = gnome_keyring_item_get_attributes_sync (keyring, (uint)id, out attributes);
+
+ if (result != ResultCode.Ok) {
+ throw new KeyringException (result);
+ }
+
+ AttributesFromNativeList (attributes, retVal);
+
+ gnome_keyring_attribute_list_free (attributes);
+
+ return retVal;
}
+ [DllImport ("libgnome-keyring.dll")]
+ static extern ResultCode gnome_keyring_item_set_attributes_sync (string keyring, UInt32 id, IntPtr attrList);
+
public static void SetItemAttributes (string keyring, int id, Hashtable atts)
{
if (keyring == null)
throw new ArgumentNullException ("keyring");
- RequestMessage req = new RequestMessage ();
- req.StartOperation (Operation.SetItemAttributes);
- req.Write (keyring);
- req.Write (id);
- req.WriteAttributes (atts);
- req.EndOperation ();
- SendRequest (req.Stream);
+ IntPtr attrList = gks_attribute_list_new ();
+ foreach (string key in atts.Keys) {
+ if (atts[key] is string) {
+ gnome_keyring_attribute_list_append_string (attrList, key, (string)atts[key]);
+ } else if (atts[key] is int) {
+ gnome_keyring_attribute_list_append_uint32 (attrList, key, (uint)((int)atts[key]));
+ } else {
+ throw new ArgumentException (String.Format ("Attribute \"{0}\" has invalid parameter type: {1}", key, atts[key].GetType ()));
+ }
+ }
+
+ ResultCode result = gnome_keyring_item_set_attributes_sync (keyring, (uint)id, attrList);
+
+ gnome_keyring_attribute_list_free (attrList);
+
+ if (result != ResultCode.Ok) {
+ throw new KeyringException (result);
+ }
}
+ [DllImport ("libgnome-keyring.dll")]
+ static extern ResultCode gnome_keyring_get_info_sync (string keyringName, out IntPtr keyringInfo);
+ [DllImport ("libgnome-keyring.dll")]
+ static extern void gnome_keyring_info_free (IntPtr keyringInfo);
+ [DllImport ("libgnome-keyring.dll")]
+ static extern IntPtr gnome_keyring_info_get_ctime (IntPtr keyringInfo);
+ [DllImport ("libgnome-keyring.dll")]
+ static extern IntPtr gnome_keyring_info_get_mtime (IntPtr keyringInfo);
+ [DllImport ("libgnome-keyring.dll")]
+ static extern int gnome_keyring_info_get_lock_timeout (IntPtr keyringInfo);
+ [DllImport("libgnome-keyring.dll")]
+ static extern bool gnome_keyring_info_get_is_locked (IntPtr keyringInfo);
+ [DllImport("libgnome-keyring.dll")]
+ static extern bool gnome_keyring_info_get_lock_on_idle (IntPtr keyringInfo);
+
public static KeyringInfo GetKeyringInfo (string keyring)
{
if (keyring == null)
throw new ArgumentNullException ("keyring");
- RequestMessage req = new RequestMessage ();
- req.CreateSimpleOperation (Operation.GetKeyringInfo, keyring);
- ResponseMessage resp = SendRequest (req.Stream);
- return new KeyringInfo (keyring, (resp.GetInt32 () != 0),
- resp.GetInt32 (),
- resp.GetDateTime (),
- resp.GetDateTime (),
- (resp.GetInt32 () != 0));
+ IntPtr keyring_info = IntPtr.Zero;
+ ResultCode result = gnome_keyring_get_info_sync (keyring, out keyring_info);
+
+ if (result != ResultCode.Ok) {
+ throw new KeyringException (result);
+ }
+
+ DateTime ctime = GLib.Marshaller.time_tToDateTime (gnome_keyring_info_get_ctime (keyring_info));
+ DateTime mtime = GLib.Marshaller.time_tToDateTime (gnome_keyring_info_get_mtime (keyring_info));
+ KeyringInfo retval = new KeyringInfo (keyring,
+ gnome_keyring_info_get_lock_on_idle (keyring_info),
+ gnome_keyring_info_get_lock_timeout (keyring_info),
+ mtime,
+ ctime,
+ gnome_keyring_info_get_is_locked (keyring_info)
+ );
+
+
+ gnome_keyring_info_free (keyring_info);
+ return retval;
}
+
+ [DllImport ("libgnome-keyring.dll")]
+ static extern ResultCode gnome_keyring_set_info_sync (string keyring, IntPtr keyringInfo);
+ [DllImport ("libgnome-keyring.dll")]
+ static extern void gnome_keyring_info_set_lock_timeout (IntPtr keyringInfo, UInt32 timeout);
+ [DllImport ("libgnome-keyring.dll")]
+ static extern void gnome_keyring_info_set_lock_on_idle (IntPtr keyringInfo, bool lockOnIdle);
public static void SetKeyringInfo (string keyring, KeyringInfo info)
{
@@ -467,41 +652,47 @@
if (info == null)
throw new ArgumentNullException ("info");
- RequestMessage req = new RequestMessage ();
- req.StartOperation (Operation.SetKeyringInfo);
- req.Write (keyring);
- req.Write (info.LockOnIdle ? 1 : 0);
- req.Write (info.LockTimeoutSeconds);
- req.EndOperation ();
- SendRequest (req.Stream);
+
+ IntPtr keyring_info;
+ ResultCode result = gnome_keyring_get_info_sync (keyring, out keyring_info);
+
+ if (result != ResultCode.Ok) {
+ throw new KeyringException (result);
+ }
+
+ gnome_keyring_info_set_lock_timeout (keyring_info, (uint)info.LockTimeoutSeconds);
+ gnome_keyring_info_set_lock_on_idle (keyring_info, info.LockOnIdle);
+
+ result = gnome_keyring_set_info_sync (keyring, keyring_info);
+
+ gnome_keyring_info_free (keyring_info);
+
+ if (result != ResultCode.Ok) {
+ throw new KeyringException (result);
+ }
}
+ [Obsolete ("Item ACLs are deprecated. GetItemACL never returns any ACLs")]
public static ArrayList GetItemACL (string keyring, int id)
{
if (keyring == null)
throw new ArgumentNullException ("keyring");
- RequestMessage req = new RequestMessage ();
- req.CreateSimpleOperation (Operation.GetItemACL, keyring, id);
- ResponseMessage resp = SendRequest (req.Stream);
- int count = resp.GetInt32 ();
- ArrayList list = new ArrayList (count);
- for (int i = 0; i < count; i++) {
- list.Add (new ItemACL (resp.GetString (), resp.GetString (), (AccessRights) resp.GetInt32 ()));
- }
- return list;
+ return new ArrayList ();
}
+ [Obsolete("Item ACLs are deprecated. SetItemACL has no effect.")]
public static void SetItemACL (string keyring, int id, ICollection acls)
{
if (acls == null)
throw new ArgumentNullException ("acls");
- ItemACL [] arr = new ItemACL [acls.Count];
+ ItemACL[] arr = new ItemACL[acls.Count];
acls.CopyTo (arr, 0);
SetItemACL (keyring, id, arr);
}
-
+
+ [Obsolete("Item ACLs are deprecated. SetItemACL has no effect.")]
public static void SetItemACL (string keyring, int id, ItemACL [] acls)
{
if (keyring == null)
@@ -512,28 +703,6 @@
if (acls.Length == 0)
throw new ArgumentException ("Empty ACL set.", "acls");
-
- RequestMessage req = new RequestMessage ();
- req.StartOperation (Operation.SetItemACL);
- req.Write (keyring);
- req.Write (id);
- req.Write (acls.Length);
- foreach (ItemACL acl in acls) {
- req.Write (acl.DisplayName);
- req.Write (acl.FullPath);
- req.Write ((int) acl.Access);
- }
- req.EndOperation ();
- SendRequest (req.Stream);
}
}
-
-#if WITH_DBUS
- [Interface ("org.gnome.keyring.Daemon")]
- interface IDaemon
- {
- string GetSocketPath ();
- }
-#endif
}
-
diff -urNad gnome-keyring-sharp-1.0.0~/src/Gnome.Keyring.dll.config gnome-keyring-sharp-1.0.0/src/Gnome.Keyring.dll.config
--- gnome-keyring-sharp-1.0.0~/src/Gnome.Keyring.dll.config 1970-01-01 10:00:00.000000000 +1000
+++ gnome-keyring-sharp-1.0.0/src/Gnome.Keyring.dll.config 2010-03-30 17:34:12.346423305 +1100
@@ -0,0 +1,4 @@
+<configuration>
+ <dllmap dll="libgnome-keyring.dll" target="libgnome-keyring.so.0"/>
+ <dllmap dll="gnome-keyring-sharp-glue.dll" target="libgnome-keyring-sharp-glue.so"/>
+</configuration>
diff -urNad gnome-keyring-sharp-1.0.0~/src/Makefile.am gnome-keyring-sharp-1.0.0/src/Makefile.am
--- gnome-keyring-sharp-1.0.0~/src/Makefile.am 2008-08-09 03:36:12.000000000 +1000
+++ gnome-keyring-sharp-1.0.0/src/Makefile.am 2010-03-30 17:32:02.733918042 +1100
@@ -5,13 +5,13 @@
SNK=$(ASSEMBLY_NAME).snk
pkgconfigdir=$(libdir)/pkgconfig
-CSFLAGS+= -debug+ -debug:full -nologo -r:Mono.Posix.dll
+CSFLAGS += -debug+ -debug:full -nologo -r:Mono.Posix.dll
pkgconfig_DATA = gnome-keyring-sharp-1.0.pc
-CLEANFILES = $(ASSEMBLY_NAME).*
+CLEANFILES = $(ASSEMBLY_NAME).dll $(ASSEMBLY_NAME).dll.mdb $(ASSEMBLY_NAME).snk
-gnomekeyring_references = $(DBUS_LIBS)
+gnomekeyring_references = $(GLIB_SHARP_LIBS)
gnomekeyring_sources = \
Gnome.Keyring/AccessRights.cs \
@@ -24,9 +24,6 @@
Gnome.Keyring/KeyringInfo.cs \
Gnome.Keyring/NetItemData.cs \
Gnome.Keyring/NoteItemData.cs \
- Gnome.Keyring/Operation.cs \
- Gnome.Keyring/RequestMessage.cs \
- Gnome.Keyring/ResponseMessage.cs \
Gnome.Keyring/ResultCode.cs \
Gnome.Keyring/Ring.cs
@@ -50,3 +47,4 @@
echo "$(GACUTIL) /u $(ASSEMBLY_NAME) $(GACUTIL_FLAGS)"; \
$(GACUTIL) /u $(ASSEMBLY_NAME) /package $(PACKAGE)-$(API_VERSION) $(GACUTIL_FLAGS) || exit 1;
+EXTRA_DIST=Gnome.Keyring.dll.config
|