diff options
author | Ken Raeburn <raeburn@mit.edu> | 2005-06-21 03:58:43 +0000 |
---|---|---|
committer | Ken Raeburn <raeburn@mit.edu> | 2005-06-21 03:58:43 +0000 |
commit | 85861b62364e7e7de472bbfe55ca90cdf9aa8ddd (patch) | |
tree | ae38d376a0ad52312550bef10ce497dd30de58e6 /src/lib/kadm5/clnt | |
parent | 13a83f750fbfdd0db56a46adaf0ed48c6c889f09 (diff) | |
download | krb5-85861b62364e7e7de472bbfe55ca90cdf9aa8ddd.tar.gz krb5-85861b62364e7e7de472bbfe55ca90cdf9aa8ddd.tar.xz krb5-85861b62364e7e7de472bbfe55ca90cdf9aa8ddd.zip |
reformat
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@17267 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib/kadm5/clnt')
-rw-r--r-- | src/lib/kadm5/clnt/err_handle.c | 130 | ||||
-rw-r--r-- | src/lib/kadm5/clnt/err_handle.h | 23 |
2 files changed, 86 insertions, 67 deletions
diff --git a/src/lib/kadm5/clnt/err_handle.c b/src/lib/kadm5/clnt/err_handle.c index 997544d5e..99d8c9423 100644 --- a/src/lib/kadm5/clnt/err_handle.c +++ b/src/lib/kadm5/clnt/err_handle.c @@ -8,11 +8,13 @@ * **********************************************************************/ #ifndef lint -static char *_csrc = "@(#) %filespec: err_handle.c~1 % (%full_filespec: err_handle.c~1:csrc:idc_sec#2 %)"; +static char *_csrc = + "@(#) %filespec: err_handle.c~1 % (%full_filespec: err_handle.c~1:csrc:idc_sec#2 %)"; #endif -/* this file should be ideally be in util/et. But, for now thread safety requirement stops me from putting there. - if I do, then all the applications have to link to pthread */ +/* This file should be ideally be in util/et. But, for now thread + safety requirement stops me from putting there. If I do, then all + the applications have to link to pthread. */ #ifdef HAVE_PTHREAD_H #include <pthread.h> @@ -24,22 +26,25 @@ static char *_csrc = "@(#) %filespec: err_handle.c~1 % (%full_filespec: err_han krb5_errcode_2_string_func old_error_2_string = NULL; #endif -typedef struct { - char krb5_err_str[KRB5_MAX_ERR_STR + 1]; - long err_code; +typedef struct +{ + char krb5_err_str[KRB5_MAX_ERR_STR + 1]; + long err_code; krb5_err_subsystem subsystem; krb5_context kcontext; } krb5_err_struct_t; #ifdef HAVE_PTHREAD_H -static void tsd_key_destructor(void *data) +static void +tsd_key_destructor(void *data) { free(data); } static pthread_key_t krb5_err_key; -static void init_err_handling( void ) +static void +init_err_handling(void) { assert(!pthread_key_create(&krb5_err_key, tsd_key_destructor)); #ifdef NOVELL @@ -50,54 +55,57 @@ static void init_err_handling( void ) static pthread_once_t krb5_key_create = PTHREAD_ONCE_INIT; -krb5_error_code krb5_set_err( krb5_context kcontext, krb5_err_subsystem subsystem, long err_code, char *str ) +krb5_error_code +krb5_set_err(krb5_context kcontext, krb5_err_subsystem subsystem, + long err_code, char *str) { - int ret; + int ret; krb5_err_struct_t *err_struct; pthread_once(&krb5_key_create, init_err_handling); - - err_struct = (krb5_err_struct_t*) pthread_getspecific(krb5_err_key); - if( err_struct == NULL ) - { + + err_struct = (krb5_err_struct_t *) pthread_getspecific(krb5_err_key); + if (err_struct == NULL) { err_struct = calloc(sizeof(krb5_err_struct_t), 1); - if( err_struct == NULL ) + if (err_struct == NULL) return ENOMEM; - if((ret = pthread_setspecific(krb5_err_key, err_struct))) - { - free( err_struct ); + if ((ret = pthread_setspecific(krb5_err_key, err_struct))) { + free(err_struct); return ret; } } err_struct->subsystem = subsystem; - err_struct->err_code = err_code; - err_struct->kcontext = kcontext; - if( err_struct->subsystem == krb5_err_have_str ) - { - strncpy( err_struct->krb5_err_str, str, sizeof(err_struct->krb5_err_str) ); + err_struct->err_code = err_code; + err_struct->kcontext = kcontext; + if (err_struct->subsystem == krb5_err_have_str) { + strncpy(err_struct->krb5_err_str, str, + sizeof(err_struct->krb5_err_str)); err_struct->krb5_err_str[KRB5_MAX_ERR_STR] = '\0'; } return 0; } -const char * KRB5_CALLCONV krb5_get_err_string(long err_code) +const char *KRB5_CALLCONV +krb5_get_err_string(long err_code) { krb5_err_struct_t *err_struct; pthread_once(&krb5_key_create, init_err_handling); - - err_struct = (krb5_err_struct_t*) pthread_getspecific(krb5_err_key); - if( err_struct && (err_struct->subsystem == krb5_err_have_str) && (err_code == err_struct->err_code) ) - { - /* checking error code is for safety. - In case, the caller ignores a database error and calls other calls before doing com_err. - Though not perfect, caller should call krb5_clr_error before this*/ + + err_struct = (krb5_err_struct_t *) pthread_getspecific(krb5_err_key); + if (err_struct && (err_struct->subsystem == krb5_err_have_str) + && (err_code == err_struct->err_code)) { + /* checking error code is for safety. + In case, the caller ignores a database error and calls + other calls before doing com_err. Though not perfect, + caller should call krb5_clr_error before this. */ err_struct->subsystem = krb5_err_unknown; return err_struct->krb5_err_str; } - /* Error strings are not generated here. the remaining two cases are handled by the default error string convertor */ + /* Error strings are not generated here. the remaining two cases + are handled by the default error string convertor. */ #ifdef NOVELL return old_error_2_string(err_code); #else @@ -105,24 +113,25 @@ const char * KRB5_CALLCONV krb5_get_err_string(long err_code) #endif } -void krb5_clr_error() +void +krb5_clr_error() { krb5_err_struct_t *err_struct; pthread_once(&krb5_key_create, init_err_handling); - - err_struct = (krb5_err_struct_t*) pthread_getspecific(krb5_err_key); - if( err_struct ) + + err_struct = (krb5_err_struct_t *) pthread_getspecific(krb5_err_key); + if (err_struct) err_struct->subsystem = krb5_err_unknown; } #else -krb5_err_struct_t krb5_err = {{0}, 0, 0, 0}; +krb5_err_struct_t krb5_err = { {0}, 0, 0, 0 }; krb5_boolean krb5_init_once = TRUE; -static void init_err_handling( void ) +static void +init_err_handling(void) { - if( krb5_init_once ) - { + if (krb5_init_once) { #ifdef NOVELL old_error_2_string = error_message; error_message = krb5_get_err_string; @@ -131,40 +140,45 @@ static void init_err_handling( void ) } } -krb5_error_code krb5_set_err( krb5_context kcontext, krb5_err_subsystem subsystem, long err_code, char *str ) +krb5_error_code +krb5_set_err(krb5_context kcontext, krb5_err_subsystem subsystem, + long err_code, char *str) { krb5_err_struct_t *err_struct = &krb5_err; - init_err_handling(); /* takes care for multiple inits */ + init_err_handling(); /* takes care for multiple inits */ err_struct->subsystem = subsystem; - err_struct->err_code = err_code; - err_struct->kcontext = kcontext; - if( err_struct->subsystem == krb5_err_have_str ) - { - strncpy( err_struct->krb5_err_str, str, sizeof(err_struct->krb5_err_str) ); + err_struct->err_code = err_code; + err_struct->kcontext = kcontext; + if (err_struct->subsystem == krb5_err_have_str) { + strncpy(err_struct->krb5_err_str, str, + sizeof(err_struct->krb5_err_str)); err_struct->krb5_err_str[KRB5_MAX_ERR_STR] = '\0'; } return 0; } -const char * KRB5_CALLCONV krb5_get_err_string(long err_code) +const char *KRB5_CALLCONV +krb5_get_err_string(long err_code) { krb5_err_struct_t *err_struct = &krb5_err; - init_err_handling(); /* takes care for multiple inits */ + init_err_handling(); /* takes care for multiple inits */ - if( (err_struct->subsystem == krb5_err_have_str) && (err_code == err_struct->err_code) ) - { - /* checking error code is for safety. - In case, the caller ignores a database error and calls other calls before doing com_err. - Though not perfect, caller should call krb5_clr_error before this*/ + if ((err_struct->subsystem == krb5_err_have_str) + && (err_code == err_struct->err_code)) { + /* checking error code is for safety. + In case, the caller ignores a database error and calls + other calls before doing com_err. Though not perfect, + caller should call krb5_clr_error before this. */ err_struct->subsystem = krb5_err_unknown; return err_struct->krb5_err_str; } - /* it is not generated here. the remaining two cases are handled by the default error string convertor */ + /* It is not generated here. the remaining two cases are handled + by the default error string convertor. */ #ifdef NOVELL return old_error_2_string(err_code); #else @@ -172,14 +186,14 @@ const char * KRB5_CALLCONV krb5_get_err_string(long err_code) #endif } -void krb5_clr_error() +void +krb5_clr_error() { krb5_err_struct_t *err_struct = &krb5_err; - init_err_handling(); /* takes care for multiple inits */ + init_err_handling(); /* takes care for multiple inits */ err_struct->subsystem = krb5_err_unknown; } - #endif diff --git a/src/lib/kadm5/clnt/err_handle.h b/src/lib/kadm5/clnt/err_handle.h index 76b6ee43c..4215e1496 100644 --- a/src/lib/kadm5/clnt/err_handle.h +++ b/src/lib/kadm5/clnt/err_handle.h @@ -14,19 +14,24 @@ /* Everything else goes here */ #define KRB5_MAX_ERR_STR 1024 -typedef enum krb5_err_subsystem { krb5_err_unknown = 0, /* no error or unknown system. Has to be probed */ - krb5_err_system, /* error in system call */ - krb5_err_krblib, /* error in kerberos library call, should lookup in the error table */ - krb5_err_have_str, /* error message is available in the string */ - krb5_err_db /* error is a database error, should be handled by calling DB */ +typedef enum krb5_err_subsystem { + krb5_err_unknown = 0, /* no error or unknown system. Has to be probed */ + krb5_err_system, /* error in system call */ + krb5_err_krblib, /* error in kerberos library call, should lookup in the error table */ + krb5_err_have_str, /* error message is available in the string */ + krb5_err_db /* error is a database error, should be handled by calling DB */ } krb5_err_subsystem; -typedef krb5_error_code (*krb5_set_err_func_t)( krb5_context, krb5_err_subsystem, long, char*); +typedef krb5_error_code(*krb5_set_err_func_t) (krb5_context, + krb5_err_subsystem, long, + char *); -krb5_error_code krb5_set_err( krb5_context kcontext, krb5_err_subsystem subsystem, long err_code, char *str ); +krb5_error_code krb5_set_err(krb5_context kcontext, + krb5_err_subsystem subsystem, long err_code, + char *str); -const char * KRB5_CALLCONV krb5_get_err_string(long err_code); +const char *KRB5_CALLCONV krb5_get_err_string(long err_code); -void krb5_clr_error(void); +void krb5_clr_error(void); #endif |