diff options
| author | Ken Raeburn <raeburn@mit.edu> | 2007-08-16 22:55:06 +0000 |
|---|---|---|
| committer | Ken Raeburn <raeburn@mit.edu> | 2007-08-16 22:55:06 +0000 |
| commit | c15ec7751a7d7c1d97dbeb1dd88dda2a328515e0 (patch) | |
| tree | 824bd8c158b1c5b72913515953c7e8576399d912 /src/util/t_array.pm | |
| parent | 9db2f5eb745287654117e70032d05dd9f5a91a3f (diff) | |
| download | krb5-c15ec7751a7d7c1d97dbeb1dd88dda2a328515e0.tar.gz krb5-c15ec7751a7d7c1d97dbeb1dd88dda2a328515e0.tar.xz krb5-c15ec7751a7d7c1d97dbeb1dd88dda2a328515e0.zip | |
remap mechanism-specific status codes in mechglue/spnego
This patch creates a mapping in the mechglue/spnego code to modify
mechanism status codes when passing them back to the application, so
that mechglue's display_status dispatcher can determine the correct
mechanism to dispatch to.
This is part of the "get enhanced error messages from gssapi
applications" project; ticket 5590 has updates to the Kerberos 5
mechanism to extract enhanced error messages (when there are any) from
the Kerberos library.
util/gen.pl, util/t_*.pm: New code generation script and templates.
lib/gssapi/generic: Add a new, global mapping that enumerates the
{mechOID,status} pairs as they're seen, allowing a magic mechOID value
to indicate com_err error codes from mechglue and spnego, and
reserving status code 0 for unknown errors. Preload the Kerberos
"wrong principal" error code once for each mechanism OID used for
Kerberos, so the entries get fixed positions (1-3) in the table.
lib/gssapi/gss_libinit.c: Call the initializer and destructor
functions.
lib/gssapi/mechglue, lib/gssapi/spnego: Enter all mechanism-generated
or locally-generated status codes into the mapping table, and return
the table index to the application. Do the reverse in display_status,
to get the messages from the mechanism..
lib/rpc: Define new function gssrpcint_printf to use for debugging
instead of printf, to redirect output away from dejagnu; add a couple
more debugging calls. Check for minor status codes 1-3 now instead of
KRB5KRB_AP_WRONG_PRINC.
tests/dejagnu/krb-standalone/gssftp.exp: Test getting more detailed
error messages back, by having the ftp client attempt to authenticate
to a non-existent service, and examining the error message for the
service principal name.
ticket: new
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@19831 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/util/t_array.pm')
| -rw-r--r-- | src/util/t_array.pm | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/src/util/t_array.pm b/src/util/t_array.pm new file mode 100644 index 000000000..d4b217393 --- /dev/null +++ b/src/util/t_array.pm @@ -0,0 +1,129 @@ +package t_array; + +use strict; +use vars qw(@ISA); + +#require ktemplate; +require t_template; + +@ISA=qw(t_template); + +my @parms = qw(NAME TYPE); +my %defaults = ( ); +my @templatelines = <DATA>; + +sub new { # no args + my $self = {}; + bless $self; + $self->init(\@parms, \%defaults, \@templatelines); + return $self; +} + +__DATA__ + +/* + * array type, derived from template + * + * parameters: + * NAME: <NAME> + * TYPE: <TYPE> + * + * methods: + * int init() -> nonzero if fail initial allocation + * unsigned long size() -> nonnegative number of values stored + * int grow(newsize) -> negative if fail allocation, memset(,0,) new space + * <TYPE> *getaddr(idx) -> aborts if out of range + * void set(idx, value) -> aborts if out of range + * <TYPE> get(idx) -> value, or aborts if out of range + */ + +#include <stdlib.h> +#include <errno.h> +#include <limits.h> +#include <string.h> + +struct <NAME>__header { + size_t allocated; + <TYPE> *elts; +}; +typedef struct <NAME>__header <NAME>; + +static inline int +<NAME>_init(<NAME> *arr) +{ + arr->elts = calloc(10, sizeof(<TYPE>)); + if (arr->elts == NULL) + return ENOMEM; + arr->allocated = 10; + return 0; +} + +static inline long +<NAME>_size(<NAME> *arr) +{ + return arr->allocated; +} + +static inline long +<NAME>_max_size(<NAME> *arr) +{ + size_t upper_bound; + + upper_bound = SIZE_MAX / sizeof(*arr->elts); + if (upper_bound > LONG_MAX) + upper_bound = LONG_MAX; + return (long) upper_bound; +} + +static inline int +<NAME>_grow(<NAME> *arr, unsigned long newcount) +{ + size_t oldsize = sizeof(*arr->elts) * arr->allocated; + size_t newsize; + void *ptr; + + if (newcount > LONG_MAX) + return -1; + if (newcount < arr->allocated) + return 0; + if (newcount > <NAME>_max_size(arr)) + return -1; + + newsize = sizeof(*arr->elts) * newcount; + ptr = realloc(arr->elts, newsize); + if (ptr == NULL) + return -1; + memset((char *)arr->elts + oldsize, 0, newsize - oldsize); + arr->elts = ptr; + arr->allocated = newcount; + return 0; +} + +static inline <TYPE> * +<NAME>_getaddr (<NAME> *arr, long idx) +{ + if (idx < 0 || idx >= arr->allocated) + abort(); + return arr->elts + idx; +} + +static inline void +<NAME>_set (<NAME> *arr, long idx, <TYPE> value) +{ + <TYPE> *newvalp; + newvalp = <NAME>_getaddr(arr, idx); + *newvalp = value; +} + +static inline <TYPE> +<NAME>_get (<NAME> *arr, long idx) +{ + return *<NAME>_getaddr(arr, idx); +} + +static inline void +<NAME>_destroy (<NAME> *arr) +{ + free(arr->elts); + arr->elts = 0; +} |
