Commit 44859c2a 44859c2a7a6cfb8e8ee2a9773a671535e3d69738 by Wojciech Polak

Add Secret class to Python interface.

* python/libmu_py/secret.c: New file.
* python/mailutils/secret.py: New file.
* python/mailutils/url.py (get_secret): New method.
(get_passwd): Remove.

* python/mailutils/mailbox.py (MailboxBase.open): Access mode argument
value can be now one of the following strings: "r", "w", "a", "c".
1 parent acef5b6f
...@@ -28,7 +28,11 @@ def parse (str): ...@@ -28,7 +28,11 @@ def parse (str):
28 28
29 print "\tscheme <%s>" % u.get_scheme () 29 print "\tscheme <%s>" % u.get_scheme ()
30 print "\tuser <%s>" % u.get_user () 30 print "\tuser <%s>" % u.get_user ()
31 print "\tpasswd <%s>" % u.get_passwd () 31
32 sec = u.get_secret ()
33 print "\tpasswd <%s>" % sec.password ()
34 sec.password_unref ()
35
32 print "\tauth <%s>" % u.get_auth () 36 print "\tauth <%s>" % u.get_auth ()
33 print "\thost <%s>" % u.get_host () 37 print "\thost <%s>" % u.get_host ()
34 print "\tport %d" % u.get_port () 38 print "\tport %d" % u.get_port ()
......
...@@ -112,6 +112,11 @@ typedef struct { ...@@ -112,6 +112,11 @@ typedef struct {
112 112
113 typedef struct { 113 typedef struct {
114 PyObject_HEAD; 114 PyObject_HEAD;
115 mu_secret_t secret;
116 } PySecret;
117
118 typedef struct {
119 PyObject_HEAD;
115 mu_stream_t stm; 120 mu_stream_t stm;
116 } PyStream; 121 } PyStream;
117 122
...@@ -137,6 +142,7 @@ extern int mu_py_init_mailbox (void); ...@@ -137,6 +142,7 @@ extern int mu_py_init_mailbox (void);
137 extern int mu_py_init_mailcap (void); 142 extern int mu_py_init_mailcap (void);
138 extern int mu_py_init_message (void); 143 extern int mu_py_init_message (void);
139 extern int mu_py_init_mime (void); 144 extern int mu_py_init_mime (void);
145 extern int mu_py_init_secret (void);
140 extern int mu_py_init_stream (void); 146 extern int mu_py_init_stream (void);
141 extern int mu_py_init_url (void); 147 extern int mu_py_init_url (void);
142 148
...@@ -160,6 +166,7 @@ extern PyMailbox * PyMailbox_NEW (); ...@@ -160,6 +166,7 @@ extern PyMailbox * PyMailbox_NEW ();
160 extern PyMailer * PyMailer_NEW (); 166 extern PyMailer * PyMailer_NEW ();
161 extern PyMessage * PyMessage_NEW (); 167 extern PyMessage * PyMessage_NEW ();
162 extern PyMime * PyMime_NEW (); 168 extern PyMime * PyMime_NEW ();
169 extern PySecret * PySecret_NEW ();
163 extern PyStream * PyStream_NEW (); 170 extern PyStream * PyStream_NEW ();
164 extern PyUrl * PyUrl_NEW (); 171 extern PyUrl * PyUrl_NEW ();
165 172
...@@ -169,6 +176,7 @@ extern int PyTicket_Check (PyObject *x); ...@@ -169,6 +176,7 @@ extern int PyTicket_Check (PyObject *x);
169 extern int PyWicket_Check (PyObject *x); 176 extern int PyWicket_Check (PyObject *x);
170 extern int PyAuthData_Check (PyObject *x); 177 extern int PyAuthData_Check (PyObject *x);
171 extern int PyMessage_Check (PyObject *x); 178 extern int PyMessage_Check (PyObject *x);
179 extern int PySecret_Check (PyObject *x);
172 extern int PyStream_Check (PyObject *x); 180 extern int PyStream_Check (PyObject *x);
173 181
174 typedef struct { 182 typedef struct {
......
...@@ -43,6 +43,7 @@ libmu_py_la_SOURCES = \ ...@@ -43,6 +43,7 @@ libmu_py_la_SOURCES = \
43 message.c \ 43 message.c \
44 mime.c \ 44 mime.c \
45 script.c \ 45 script.c \
46 secret.c \
46 stream.c \ 47 stream.c \
47 registrar.c \ 48 registrar.c \
48 url.c \ 49 url.c \
......
...@@ -438,6 +438,27 @@ api_ticket_destroy (PyObject *self, PyObject *args) ...@@ -438,6 +438,27 @@ api_ticket_destroy (PyObject *self, PyObject *args)
438 return _ro (Py_None); 438 return _ro (Py_None);
439 } 439 }
440 440
441 static PyObject *
442 api_ticket_set_secret (PyObject *self, PyObject *args)
443 {
444 int status;
445 PyTicket *py_ticket;
446 PySecret *py_secret;
447
448 if (!PyArg_ParseTuple (args, "O!O", &PyTicketType, &py_ticket, &py_secret))
449 return NULL;
450
451 if (!PySecret_Check ((PyObject *)py_secret))
452 {
453 PyErr_SetString (PyExc_TypeError, "");
454 return NULL;
455 }
456
457 status = mu_ticket_set_secret (py_ticket->ticket,
458 py_secret->secret);
459 return _ro (PyInt_FromLong (status));
460 }
461
441 /* 462 /*
442 * Wicket 463 * Wicket
443 */ 464 */
...@@ -468,6 +489,24 @@ api_wicket_destroy (PyObject *self, PyObject *args) ...@@ -468,6 +489,24 @@ api_wicket_destroy (PyObject *self, PyObject *args)
468 return _ro (Py_None); 489 return _ro (Py_None);
469 } 490 }
470 491
492 static PyObject *
493 api_wicket_get_ticket (PyObject *self, PyObject *args)
494 {
495 int status;
496 char *user;
497 PyWicket *py_wicket;
498 PyTicket *py_ticket = PyTicket_NEW ();
499
500 if (!PyArg_ParseTuple (args, "O!s", &PyWicketType, &py_wicket, &user))
501 return NULL;
502
503 Py_INCREF (py_ticket);
504
505 status = mu_wicket_get_ticket (py_wicket->wicket, user,
506 &py_ticket->ticket);
507 return status_object (status, (PyObject *)py_ticket);
508 }
509
471 /* 510 /*
472 * mu_auth 511 * mu_auth
473 */ 512 */
...@@ -607,12 +646,18 @@ static PyMethodDef methods[] = { ...@@ -607,12 +646,18 @@ static PyMethodDef methods[] = {
607 { "ticket_destroy", (PyCFunction) api_ticket_destroy, METH_VARARGS, 646 { "ticket_destroy", (PyCFunction) api_ticket_destroy, METH_VARARGS,
608 "" }, 647 "" },
609 648
649 { "ticket_set_secret", (PyCFunction) api_ticket_set_secret, METH_VARARGS,
650 "" },
651
610 { "wicket_create", (PyCFunction) api_wicket_create, METH_VARARGS, 652 { "wicket_create", (PyCFunction) api_wicket_create, METH_VARARGS,
611 "" }, 653 "" },
612 654
613 { "wicket_destroy", (PyCFunction) api_wicket_destroy, METH_VARARGS, 655 { "wicket_destroy", (PyCFunction) api_wicket_destroy, METH_VARARGS,
614 "" }, 656 "" },
615 657
658 { "wicket_get_ticket", (PyCFunction) api_wicket_get_ticket, METH_VARARGS,
659 "" },
660
616 { "register_module", (PyCFunction) api_register_module, METH_VARARGS, 661 { "register_module", (PyCFunction) api_register_module, METH_VARARGS,
617 "" }, 662 "" },
618 663
......
...@@ -84,6 +84,7 @@ mu_py_init (void) ...@@ -84,6 +84,7 @@ mu_py_init (void)
84 mu_py_init_mailcap (); 84 mu_py_init_mailcap ();
85 mu_py_init_message (); 85 mu_py_init_message ();
86 mu_py_init_mime (); 86 mu_py_init_mime ();
87 mu_py_init_secret ();
87 mu_py_init_stream (); 88 mu_py_init_stream ();
88 mu_py_init_url (); 89 mu_py_init_url ();
89 } 90 }
...@@ -123,6 +124,7 @@ mu_py_attach_modules (void) ...@@ -123,6 +124,7 @@ mu_py_attach_modules (void)
123 _mu_py_attach_message (); 124 _mu_py_attach_message ();
124 _mu_py_attach_mime (); 125 _mu_py_attach_mime ();
125 _mu_py_attach_registrar (); 126 _mu_py_attach_registrar ();
127 _mu_py_attach_secret ();
126 _mu_py_attach_stream (); 128 _mu_py_attach_stream ();
127 _mu_py_attach_url (); 129 _mu_py_attach_url ();
128 _mu_py_attach_util (); 130 _mu_py_attach_util ();
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
42 #include <mailutils/mutil.h> 42 #include <mailutils/mutil.h>
43 #include <mailutils/registrar.h> 43 #include <mailutils/registrar.h>
44 #include <mailutils/tls.h> 44 #include <mailutils/tls.h>
45 #include <mailutils/secret.h>
45 #include <mailutils/stream.h> 46 #include <mailutils/stream.h>
46 #include <mailutils/url.h> 47 #include <mailutils/url.h>
47 #include <mailutils/python.h> 48 #include <mailutils/python.h>
...@@ -73,6 +74,7 @@ extern void _mu_py_attach_mailcap (void); ...@@ -73,6 +74,7 @@ extern void _mu_py_attach_mailcap (void);
73 extern void _mu_py_attach_message (void); 74 extern void _mu_py_attach_message (void);
74 extern void _mu_py_attach_mime (void); 75 extern void _mu_py_attach_mime (void);
75 extern void _mu_py_attach_registrar (void); 76 extern void _mu_py_attach_registrar (void);
77 extern void _mu_py_attach_secret (void);
76 extern void _mu_py_attach_stream (void); 78 extern void _mu_py_attach_stream (void);
77 extern void _mu_py_attach_url (void); 79 extern void _mu_py_attach_url (void);
78 extern void _mu_py_attach_util (void); 80 extern void _mu_py_attach_util (void);
......
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #include "libmu_py.h"
22
23 #define PY_MODULE "secret"
24 #define PY_CSNAME "SecretType"
25
26 static PyObject *
27 _repr (PyObject *self)
28 {
29 char buf[80];
30 sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
31 return PyString_FromString (buf);
32 }
33
34 static PyTypeObject PySecretType = {
35 PyObject_HEAD_INIT(NULL)
36 0, /* ob_size */
37 PY_MODULE "." PY_CSNAME, /* tp_name */
38 sizeof (PySecret), /* tp_basicsize */
39 0, /* tp_itemsize */
40 (destructor)_py_dealloc, /* tp_dealloc */
41 0, /* tp_print */
42 0, /* tp_getattr; __getattr__ */
43 0, /* tp_setattr; __setattr__ */
44 0, /* tp_compare; __cmp__ */
45 _repr, /* tp_repr; __repr__ */
46 0, /* tp_as_number */
47 0, /* tp_as_sequence */
48 0, /* tp_as_mapping */
49 0, /* tp_hash; __hash__ */
50 0, /* tp_call; __call__ */
51 _repr, /* tp_str; __str__ */
52 0, /* tp_getattro */
53 0, /* tp_setattro */
54 0, /* tp_as_buffer */
55 Py_TPFLAGS_DEFAULT, /* tp_flags */
56 "", /* tp_doc */
57 0, /* tp_traverse */
58 0, /* tp_clear */
59 0, /* tp_richcompare */
60 0, /* tp_weaklistoffset */
61 0, /* tp_iter */
62 0, /* tp_iternext */
63 0, /* tp_methods */
64 0, /* tp_members */
65 0, /* tp_getset */
66 0, /* tp_base */
67 0, /* tp_dict */
68 0, /* tp_descr_get */
69 0, /* tp_descr_set */
70 0, /* tp_dictoffset */
71 0, /* tp_init */
72 0, /* tp_alloc */
73 0, /* tp_new */
74 };
75
76 PySecret *
77 PySecret_NEW ()
78 {
79 return (PySecret *)PyObject_NEW (PySecret, &PySecretType);
80 }
81
82 int
83 PySecret_Check (PyObject *x)
84 {
85 return x->ob_type == &PySecretType;
86 }
87
88 static PyObject *
89 api_secret_create (PyObject *self, PyObject *args)
90 {
91 int status;
92 char *str;
93 size_t len;
94 PySecret *py_secret;
95
96 if (!PyArg_ParseTuple (args, "O!si", &PySecretType, &py_secret,
97 &str, &len))
98 return NULL;
99
100 status = mu_secret_create (&py_secret->secret, str, len);
101 return _ro (PyInt_FromLong (status));
102 }
103
104 static PyObject *
105 api_secret_destroy (PyObject *self, PyObject *args)
106 {
107 PySecret *py_secret;
108
109 if (!PyArg_ParseTuple (args, "O!", &PySecretType, &py_secret))
110 return NULL;
111
112 mu_secret_destroy (&py_secret->secret);
113 return _ro (Py_None);
114 }
115
116 static PyObject *
117 api_secret_password (PyObject *self, PyObject *args)
118 {
119 int status;
120 const char *pass;
121 PySecret *py_secret;
122
123 if (!PyArg_ParseTuple (args, "O!", &PySecretType, &py_secret))
124 return NULL;
125
126 pass = mu_secret_password (py_secret->secret);
127 return _ro (PyString_FromString (pass ? pass : ""));
128 }
129
130 static PyObject *
131 api_secret_password_unref (PyObject *self, PyObject *args)
132 {
133 PySecret *py_secret;
134
135 if (!PyArg_ParseTuple (args, "O!", &PySecretType, &py_secret))
136 return NULL;
137
138 mu_secret_password_unref (py_secret->secret);
139 return _ro (Py_None);
140 }
141
142 static PyObject *
143 api_clear_passwd (PyObject *self, PyObject *args)
144 {
145 char *p;
146
147 if (!PyArg_ParseTuple (args, "s", &p))
148 return NULL;
149
150 while (*p)
151 *p++ = 0;
152 return _ro (Py_None);
153 }
154
155 static PyMethodDef methods[] = {
156 { "create", (PyCFunction) api_secret_create, METH_VARARGS,
157 "Create the secret data structure." },
158
159 { "destroy", (PyCFunction) api_secret_destroy, METH_VARARGS,
160 "Destroy the secret and free its resources." },
161
162 { "password", (PyCFunction) api_secret_password, METH_VARARGS,
163 "" },
164
165 { "password_unref", (PyCFunction) api_secret_password_unref, METH_VARARGS,
166 "" },
167
168 { "clear_passwd", (PyCFunction) api_clear_passwd, METH_VARARGS,
169 "" },
170
171 { NULL, NULL, 0, NULL }
172 };
173
174 int
175 mu_py_init_secret (void)
176 {
177 PySecretType.tp_new = PyType_GenericNew;
178 return PyType_Ready (&PySecretType);
179 }
180
181 void
182 _mu_py_attach_secret (void)
183 {
184 PyObject *m;
185 if ((m = _mu_py_attach_module (PY_MODULE, methods)))
186 {
187 Py_INCREF (&PySecretType);
188 PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PySecretType);
189 }
190 }
...@@ -160,23 +160,21 @@ api_url_get_user (PyObject *self, PyObject *args) ...@@ -160,23 +160,21 @@ api_url_get_user (PyObject *self, PyObject *args)
160 return status_object (status, PyString_FromString (buf ? buf : "")); 160 return status_object (status, PyString_FromString (buf ? buf : ""));
161 } 161 }
162 162
163 #if 0
164 /* FIXME: Returning plaintext (unobfuscated) password from
165 a secret actually makes the latter useless. */
166 static PyObject * 163 static PyObject *
167 api_url_get_passwd (PyObject *self, PyObject *args) 164 api_url_get_secret (PyObject *self, PyObject *args)
168 { 165 {
169 int status; 166 int status;
170 const char *buf = NULL;
171 PyUrl *py_url; 167 PyUrl *py_url;
168 PySecret *py_secret = PySecret_NEW ();
172 169
173 if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url)) 170 if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
174 return NULL; 171 return NULL;
175 172
176 status = mu_url_sget_passwd (py_url->url, &buf); 173 Py_INCREF (py_secret);
177 return status_object (status, PyString_FromString (buf ? buf : "")); 174
175 status = mu_url_get_secret (py_url->url, &py_secret->secret);
176 return status_object (status, (PyObject *)py_secret);
178 } 177 }
179 #endif
180 178
181 static PyObject * 179 static PyObject *
182 api_url_get_auth (PyObject *self, PyObject *args) 180 api_url_get_auth (PyObject *self, PyObject *args)
...@@ -271,9 +269,7 @@ static PyMethodDef methods[] = { ...@@ -271,9 +269,7 @@ static PyMethodDef methods[] = {
271 { "get_port", (PyCFunction) api_url_get_port, METH_VARARGS, "" }, 269 { "get_port", (PyCFunction) api_url_get_port, METH_VARARGS, "" },
272 { "get_scheme", (PyCFunction) api_url_get_scheme, METH_VARARGS, "" }, 270 { "get_scheme", (PyCFunction) api_url_get_scheme, METH_VARARGS, "" },
273 { "get_user", (PyCFunction) api_url_get_user, METH_VARARGS, "" }, 271 { "get_user", (PyCFunction) api_url_get_user, METH_VARARGS, "" },
274 #if 0 /*FIXME: See above */ 272 { "get_secret", (PyCFunction) api_url_get_secret, METH_VARARGS, "" },
275 { "get_passwd", (PyCFunction) api_url_get_passwd, METH_VARARGS, "" },
276 #endif
277 { "get_auth", (PyCFunction) api_url_get_auth, METH_VARARGS, "" }, 273 { "get_auth", (PyCFunction) api_url_get_auth, METH_VARARGS, "" },
278 { "get_host", (PyCFunction) api_url_get_host, METH_VARARGS, "" }, 274 { "get_host", (PyCFunction) api_url_get_host, METH_VARARGS, "" },
279 { "get_path", (PyCFunction) api_url_get_path, METH_VARARGS, "" }, 275 { "get_path", (PyCFunction) api_url_get_path, METH_VARARGS, "" },
......
...@@ -35,6 +35,7 @@ MU_PY_PKGPYTHON_LIST=\ ...@@ -35,6 +35,7 @@ MU_PY_PKGPYTHON_LIST=\
35 message.py \ 35 message.py \
36 mime.py \ 36 mime.py \
37 registrar.py \ 37 registrar.py \
38 secret.py \
38 stream.py \ 39 stream.py \
39 url.py \ 40 url.py \
40 util.py 41 util.py
......
...@@ -33,6 +33,7 @@ __all__ = [ ...@@ -33,6 +33,7 @@ __all__ = [
33 "message", 33 "message",
34 "mime", 34 "mime",
35 "registrar", 35 "registrar",
36 "secret",
36 "stream", 37 "stream",
37 "url", 38 "url",
38 "util", 39 "util",
......
...@@ -100,6 +100,11 @@ class Ticket: ...@@ -100,6 +100,11 @@ class Ticket:
100 auth.ticket_destroy (self.ticket) 100 auth.ticket_destroy (self.ticket)
101 del self.ticket 101 del self.ticket
102 102
103 def set_secret (self, secret):
104 status = auth.ticket_set_secret (self.ticket, secret.secret)
105 if status:
106 raise AuthError (status)
107
103 class Wicket: 108 class Wicket:
104 __owner = False 109 __owner = False
105 110
...@@ -118,16 +123,8 @@ class Wicket: ...@@ -118,16 +123,8 @@ class Wicket:
118 auth.wicket_destroy (self.wicket) 123 auth.wicket_destroy (self.wicket)
119 del self.wicket 124 del self.wicket
120 125
121 def __str__ (self): 126 def get_ticket (self, user):
122 return self.get_filename () 127 status, ticket = auth.wicket_get_ticket (self.wicket, user)
123
124 def get_filename (self):
125 status, filename = auth.wicket_get_filename (self.wicket)
126 if status:
127 raise AuthError (status)
128 return filename
129
130 def set_filename (self, filename):
131 status = auth.wicket_set_filename (self.wicket, filename)
132 if status: 128 if status:
133 raise AuthError (status) 129 raise AuthError (status)
130 return Ticket (ticket)
......
...@@ -42,6 +42,7 @@ class MailboxError (Error): pass ...@@ -42,6 +42,7 @@ class MailboxError (Error): pass
42 class MailcapError (Error): pass 42 class MailcapError (Error): pass
43 class MessageError (Error): pass 43 class MessageError (Error): pass
44 class MimeError (Error): pass 44 class MimeError (Error): pass
45 class SecretError (Error): pass
45 class StreamError (Error): pass 46 class StreamError (Error): pass
46 class UrlError (Error): pass 47 class UrlError (Error): pass
47 48
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
18 # Boston, MA 02110-1301 USA 18 # Boston, MA 02110-1301 USA
19 # 19 #
20 20
21 import types
21 from mailutils.c_api import mailbox 22 from mailutils.c_api import mailbox
22 from mailutils import message 23 from mailutils import message
23 from mailutils import folder 24 from mailutils import folder
...@@ -26,9 +27,21 @@ from mailutils import debug ...@@ -26,9 +27,21 @@ from mailutils import debug
26 from mailutils.error import MailboxError 27 from mailutils.error import MailboxError
27 28
28 class MailboxBase: 29 class MailboxBase:
29 def open (self, flags = 0): 30 def open (self, mode = 0):
30 """Open the connection.""" 31 """Open the connection."""
31 status = mailbox.open (self.mbox, flags) 32 if isinstance (mode, types.StringType):
33 from mailutils import stream
34 flags = 0
35 if mode == 'r':
36 flags = flags | stream.MU_STREAM_READ
37 elif mode == 'w':
38 flags = flags | stream.MU_STREAM_WRITE
39 elif mode == 'a':
40 flags = flags | stream.MU_STREAM_APPEND
41 elif mode == 'c':
42 flags = flags | stream.MU_STREAM_CREAT
43 mode = flags
44 status = mailbox.open (self.mbox, mode)
32 if status: 45 if status:
33 raise MailboxError (status) 46 raise MailboxError (status)
34 47
......
1 #
2 # GNU Mailutils -- a suite of utilities for electronic mail
3 # Copyright (C) 2009 Free Software Foundation, Inc.
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 3 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General
16 # Public License along with this library; if not, write to the
17 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 # Boston, MA 02110-1301 USA
19 #
20
21 from mailutils.c_api import secret
22 from mailutils.error import SecretError
23
24 def clear_passwd (passwd):
25 secret.clear_passwd (passwd)
26
27 class Secret:
28 __owner = False
29
30 def __init__ (self, sec):
31 if isinstance (sec, secret.SecretType):
32 self.secret = sec
33 else:
34 self.secret = secret.SecretType ()
35 self.__owner = True
36 status = secret.create (self.secret, sec, len (sec))
37 if status:
38 raise SecretError (status)
39
40 def __del__ (self):
41 if self.__owner:
42 secret.destroy (self.secret)
43 del self.secret
44
45 def password (self):
46 return secret.password (self.secret)
47
48 def password_unref (self):
49 secret.password_unref (self.secret)
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
19 # 19 #
20 20
21 from mailutils.c_api import url 21 from mailutils.c_api import url
22 from mailutils import secret
22 from mailutils.error import * 23 from mailutils.error import *
23 24
24 class Url: 25 class Url:
...@@ -72,13 +73,13 @@ class Url: ...@@ -72,13 +73,13 @@ class Url:
72 raise UrlError (status) 73 raise UrlError (status)
73 return user 74 return user
74 75
75 def get_passwd (self): 76 def get_secret (self):
76 status, passwd = url.get_passwd (self.url) 77 status, sec = url.get_secret (self.url)
77 if status == MU_ERR_NOENT: 78 if status == MU_ERR_NOENT:
78 return '' 79 return secret.Secret ('')
79 elif status: 80 elif status:
80 raise UrlError (status) 81 raise UrlError (status)
81 return passwd 82 return secret.Secret (sec)
82 83
83 def get_auth (self): 84 def get_auth (self):
84 status, auth = url.get_auth (self.url) 85 status, auth = url.get_auth (self.url)
......