On Tue, Dec 04, 2007 at 10:10:28PM +0100, Jim Meyering wrote: > "Daniel P. Berrange" <berrange@xxxxxxxxxx> wrote: > > This adds a binding for the virConnectOpenAuth() api in the python > > API. This allows a python function to be used as the callback. > > > > This short example code illustrates the use of the API from a > > python app which wants to support username/password credentials > > only. > > > > from getpass import getpass > > mydata = "Hello" > > > > def getCred(creds, data): > > print "yes" > > print str(creds) > > for cred in creds: > > print cred[1] + ": ", > > if cred[0] == libvirt.VIR_CRED_AUTHNAME: > > data = sys.stdin.readline() > > data = data[0:len(data)-1] > > cred[4] = data > > elif cred[0] == libvirt.VIR_CRED_PASSPHRASE: > > cred[4] = getpass("") > > else: > > return -1 > > return 0 > > > > uri = "qemu+tcp://localhost/system" > > conn = libvirt.openAuth(uri, > > [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_PASSPHRASE], > > getCred, > > mydata], 0) > > > > > > print str(conn.listDefinedDomains()) > > Nice. > One nit: > > > diff -r 8a79678f789f python/libvir.c > > --- a/python/libvir.c Wed Nov 28 23:01:30 2007 -0500 > > +++ b/python/libvir.c Wed Nov 28 23:29:40 2007 -0500 > ... > > +static PyObject * > > +libvirt_virConnectOpenAuth(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { > ... > > + auth.ncredtype = PyList_Size(pycredtype); > > + if (auth.ncredtype) { > > + int i; > > + auth.credtype = malloc(sizeof(int) * auth.ncredtype); > > Check for malloc failure: > > if (!auth.credtype) > return NULL; Committed with this fix included. Regards, Dan. -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=| -- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list