diff options
| author | Ken Raeburn <raeburn@mit.edu> | 2006-03-26 20:55:59 +0000 |
|---|---|---|
| committer | Ken Raeburn <raeburn@mit.edu> | 2006-03-26 20:55:59 +0000 |
| commit | b5a541c640dfedda7480332f4838e30f0a9e1770 (patch) | |
| tree | b5182550f1c3fb475c3b71d15f4944fbcc16c4bb /src/plugins/locate/python | |
| parent | 976289e5db9426efb6aa56cf0c97b89b4e30d1b4 (diff) | |
| download | krb5-b5a541c640dfedda7480332f4838e30f0a9e1770.tar.gz krb5-b5a541c640dfedda7480332f4838e30f0a9e1770.tar.xz krb5-b5a541c640dfedda7480332f4838e30f0a9e1770.zip | |
Initial enhanced error message support, similar to what I sent to
krbdev except for some function renaming (krb5_free_error was already
in use, so added _message to everything), and the context is allowed
to be NULL (in which case we fall back to error_message() and storing
no strings) to simplify some code.
Low-level routines in the support library, using a private data
structure; higher-level routines in libkrb5, using a krb5_context.
Added error info strings to the KRB_ERR_GENERIC case in gc_via_tkt.c
and the python sample service location plugin. Added code to kinit
and kvno to look up and display the strings.
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@17776 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/plugins/locate/python')
| -rw-r--r-- | src/plugins/locate/python/ChangeLog | 8 | ||||
| -rw-r--r-- | src/plugins/locate/python/Makefile.in | 11 | ||||
| -rw-r--r-- | src/plugins/locate/python/py-locate.c | 58 |
3 files changed, 56 insertions, 21 deletions
diff --git a/src/plugins/locate/python/ChangeLog b/src/plugins/locate/python/ChangeLog index 897919e11..db471def6 100644 --- a/src/plugins/locate/python/ChangeLog +++ b/src/plugins/locate/python/ChangeLog @@ -1,3 +1,11 @@ +2006-03-26 Ken Raeburn <raeburn@mit.edu> + + * Makefile.in (SHLIB_EXPLIBS, SHLIB_EXPDEPS): Add krb5 lib. + * py-locate.c (sctx): New variable. + (my_init, lookup): Call krb5_set_error_message instead of fprintf + in most cases. Use sctx to pass context (not thread safe!), and + store it as "blob" value. + 2006-03-07 Ken Raeburn <raeburn@mit.edu> * py-locate.c: Include k5-locate.h instead of k5-plugin.h. diff --git a/src/plugins/locate/python/Makefile.in b/src/plugins/locate/python/Makefile.in index 46a83fede..1d0b95964 100644 --- a/src/plugins/locate/python/Makefile.in +++ b/src/plugins/locate/python/Makefile.in @@ -10,8 +10,8 @@ SO_EXT=.so RELDIR=../plugins/locate/python MODULE_INSTALL_DIR = $(KRB5_LIBKRB5_MODULE_DIR) -SHLIB_EXPDEPS= -SHLIB_EXPLIBS= -lpython2.3 +SHLIB_EXPDEPS= $(KRB5_DEPLIB) +SHLIB_EXPLIBS= -lpython2.3 $(KRB5_LIB) SHLIB_DIRS=-L$(TOPLIBD) SHLIB_RDIRS=$(KRB5_LIBDIR) @@ -34,9 +34,10 @@ clean-unix:: clean-libs clean-libobjs # the Makefile.in file # py-locate.so py-locate.po $(OUTPRE)py-locate.$(OBJEXT): \ - py-locate.c $(BUILDTOP)/include/krb5/autoconf.h $(SRCTOP)/include/k5-int.h \ - $(BUILDTOP)/include/krb5/osconf.h $(SRCTOP)/include/k5-platform.h \ + py-locate.c $(BUILDTOP)/include/autoconf.h $(SRCTOP)/include/k5-int.h \ + $(BUILDTOP)/include/osconf.h $(SRCTOP)/include/k5-platform.h \ $(SRCTOP)/include/k5-thread.h $(BUILDTOP)/include/krb5.h \ $(COM_ERR_DEPS) $(BUILDTOP)/include/profile.h $(SRCTOP)/include/port-sockets.h \ - $(SRCTOP)/include/socket-utils.h $(SRCTOP)/include/krb5/kdb.h \ + $(SRCTOP)/include/socket-utils.h $(SRCTOP)/include/k5-err.h \ + $(SRCTOP)/include/k5-locate.h $(SRCTOP)/include/kdb.h \ $(SRCTOP)/include/k5-plugin.h diff --git a/src/plugins/locate/python/py-locate.c b/src/plugins/locate/python/py-locate.c index 548210a6b..f5dc62932 100644 --- a/src/plugins/locate/python/py-locate.c +++ b/src/plugins/locate/python/py-locate.c @@ -79,6 +79,8 @@ MAKE_FINI_FUNCTION(my_fini); #define F (strchr(__FILE__, '/') ? 1 + strrchr(__FILE__, '/') : __FILE__) +static krb5_context sctx; /* XXX ugly hack! */ + int my_init (void) { @@ -88,8 +90,13 @@ my_init (void) Py_Initialize (); // fprintf(stderr, "trying to load %s\n", SCRIPT_PATH); f = fopen(SCRIPT_PATH, "r"); - if (f == NULL) + if (f == NULL) { + if (sctx) + krb5_set_error_message(sctx, -1, + "couldn't open Python script %s (%s)", + SCRIPT_PATH, strerror(errno)); return -1; + } PyRun_SimpleFile (f, SCRIPT_PATH); fclose(f); mainmodule = PyModule_GetDict(PyImport_AddModule("__main__")); @@ -128,7 +135,7 @@ ctxinit (krb5_context ctx, void **blobptr) interpreter, this would be a good place for it; the blob could be allocated to hold the reference to the interpreter instance. */ - *blobptr = 0; + *blobptr = ctx; return 0; } @@ -164,10 +171,12 @@ lookup (void *blob, enum locate_service_type svc, const char *realm, // fprintf(stderr, "%s:%d: lookup(%d,%s,%d,%d)\n", F, __LINE__, // svc, realm, socktype, family); + sctx = blob; /* XXX: Not thread safe! */ i = CALL_INIT_FUNCTION (my_init); if (i) { - fprintf(stderr, "%s:%d: module initialization failed %d\n", - F, __LINE__, i); +#if 0 + fprintf(stderr, "%s:%d: module initialization failed\n", F, __LINE__); +#endif return i; } if (locatefn == 0) @@ -187,7 +196,13 @@ lookup (void *blob, enum locate_service_type svc, const char *realm, py_result = PyObject_CallObject (locatefn, arglist); Py_DECREF (arglist); - if (PyErr_Occurred()) { fprintf(stderr,"%s:%d: python error\n", F, __LINE__); PyErr_Print(); return -1; } + if (PyErr_Occurred()) { + fprintf(stderr,"%s:%d: python error\n", F, __LINE__); + PyErr_Print(); + krb5_set_error_message(blob, -1, + "Python evaluation error, see stderr"); + return -1; + } if (py_result == 0) { fprintf(stderr, "%s:%d: returned null object\n", F, __LINE__); return -1; @@ -197,6 +212,8 @@ lookup (void *blob, enum locate_service_type svc, const char *realm, if (! PyList_Check (py_result)) { Py_DECREF (py_result); fprintf(stderr, "%s:%d: returned non-list, non-False\n", F, __LINE__); + krb5_set_error_message(blob, -1, + "Python script error -- returned non-list, non-False result"); return -1; } listsize = PyList_Size (py_result); @@ -211,20 +228,24 @@ lookup (void *blob, enum locate_service_type svc, const char *realm, answer = PyList_GetItem (py_result, i); if (! PyTuple_Check (answer)) { - fprintf(stderr, "%s:%d: item %d non-tuple\n", F, __LINE__, i); + krb5_set_error_message(blob, -1, + "Python script error -- returned item %d not a tuple", i); /* leak? */ return -1; } if (PyTuple_Size (answer) != 3) { - fprintf(stderr, "%s:%d: item %d tuple size %d should be 3\n", F, __LINE__, i, - PyTuple_Size (answer)); + krb5_set_error_message(blob, -1, + "Python script error -- returned tuple %d size %d should be 3", + i, PyTuple_Size (answer)); /* leak? */ return -1; } field = PyTuple_GetItem (answer, 0); if (! PyString_Check (field)) { /* leak? */ - fprintf(stderr, "%s:%d: item %d first component not a string\n", F, __LINE__, i); + krb5_set_error_message(blob, -1, + "Python script error -- first component of tuple %d is not a string", + i); return -1; } hoststr = PyString_AsString (field); @@ -235,14 +256,17 @@ lookup (void *blob, enum locate_service_type svc, const char *realm, sprintf(portbuf, "%ld", PyInt_AsLong (field)); portstr = portbuf; } else { - fprintf(stderr, "%s:%d: item %d second component neither string nor int\n", - F, __LINE__, i); + krb5_set_error_message(blob, -1, + "Python script error -- second component of tuple %d neither a string nor an integer", + i); /* leak? */ return -1; } field = PyTuple_GetItem (answer, 2); if (! PyInt_Check (field)) { - fprintf(stderr, "%s:%d: item %d third component not int\n", F, __LINE__, i); + krb5_set_error_message(blob, -1, + "Python script error -- third component of tuple %d not an integer", + i); /* leak? */ return -1; } @@ -252,16 +276,18 @@ lookup (void *blob, enum locate_service_type svc, const char *realm, case SOCK_DGRAM: /* okay */ if (socktype != 0 && socktype != thissocktype) { - fprintf(stderr, "%s:%d: item %d socket type %d should be %d\n", - F, __LINE__, i, thissocktype, socktype); + krb5_set_error_message(blob, -1, + "Python script error -- tuple %d has socket type %d, should only have %d", + i, thissocktype, socktype); /* leak? */ return -1; } break; default: /* 0 is not acceptable */ - fprintf(stderr, "%s:%d: item %d socket type %d invalid\n", F, __LINE__, i, - thissocktype); + krb5_set_error_message(blob, -1, + "Python script error -- tuple %d has invalid socket type %d", + i, thissocktype); /* leak? */ return -1; } |
