err.pod 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. =pod
  2. =head1 NAME
  3. err - error codes
  4. =head1 SYNOPSIS
  5. #include <openssl/err.h>
  6. unsigned long ERR_get_error(void);
  7. unsigned long ERR_peek_error(void);
  8. unsigned long ERR_get_error_line(const char **file, int *line);
  9. unsigned long ERR_peek_error_line(const char **file, int *line);
  10. unsigned long ERR_get_error_line_data(const char **file, int *line,
  11. const char **data, int *flags);
  12. unsigned long ERR_peek_error_line_data(const char **file, int *line,
  13. const char **data, int *flags);
  14. int ERR_GET_LIB(unsigned long e);
  15. int ERR_GET_FUNC(unsigned long e);
  16. int ERR_GET_REASON(unsigned long e);
  17. void ERR_clear_error(void);
  18. char *ERR_error_string(unsigned long e, char *buf);
  19. const char *ERR_lib_error_string(unsigned long e);
  20. const char *ERR_func_error_string(unsigned long e);
  21. const char *ERR_reason_error_string(unsigned long e);
  22. void ERR_print_errors(BIO *bp);
  23. void ERR_print_errors_fp(FILE *fp);
  24. void ERR_load_crypto_strings(void);
  25. void ERR_free_strings(void);
  26. void ERR_remove_state(unsigned long pid);
  27. void ERR_put_error(int lib, int func, int reason, const char *file,
  28. int line);
  29. void ERR_add_error_data(int num, ...);
  30. void ERR_load_strings(int lib,ERR_STRING_DATA str[]);
  31. unsigned long ERR_PACK(int lib, int func, int reason);
  32. int ERR_get_next_error_library(void);
  33. =head1 DESCRIPTION
  34. When a call to the OpenSSL library fails, this is usually signalled
  35. by the return value, and an error code is stored in an error queue
  36. associated with the current thread. The B<err> library provides
  37. functions to obtain these error codes and textual error messages.
  38. The L<ERR_get_error(3)|ERR_get_error(3)> manpage describes how to
  39. access error codes.
  40. Error codes contain information about where the error occurred, and
  41. what went wrong. L<ERR_GET_LIB(3)|ERR_GET_LIB(3)> describes how to
  42. extract this information. A method to obtain human-readable error
  43. messages is described in L<ERR_error_string(3)|ERR_error_string(3)>.
  44. L<ERR_clear_error(3)|ERR_clear_error(3)> can be used to clear the
  45. error queue.
  46. Note that L<ERR_remove_state(3)|ERR_remove_state(3)> should be used to
  47. avoid memory leaks when threads are terminated.
  48. =head1 ADDING NEW ERROR CODES TO OPENSSL
  49. See L<ERR_put_error(3)> if you want to record error codes in the
  50. OpenSSL error system from within your application.
  51. The remainder of this section is of interest only if you want to add
  52. new error codes to OpenSSL or add error codes from external libraries.
  53. =head2 Reporting errors
  54. Each sub-library has a specific macro XXXerr() that is used to report
  55. errors. Its first argument is a function code B<XXX_F_...>, the second
  56. argument is a reason code B<XXX_R_...>. Function codes are derived
  57. from the function names; reason codes consist of textual error
  58. descriptions. For example, the function ssl23_read() reports a
  59. "handshake failure" as follows:
  60. SSLerr(SSL_F_SSL23_READ, SSL_R_SSL_HANDSHAKE_FAILURE);
  61. Function and reason codes should consist of upper case characters,
  62. numbers and underscores only. The error file generation script translates
  63. function codes into function names by looking in the header files
  64. for an appropriate function name, if none is found it just uses
  65. the capitalized form such as "SSL23_READ" in the above example.
  66. The trailing section of a reason code (after the "_R_") is translated
  67. into lower case and underscores changed to spaces.
  68. When you are using new function or reason codes, run B<make errors>.
  69. The necessary B<#define>s will then automatically be added to the
  70. sub-library's header file.
  71. Although a library will normally report errors using its own specific
  72. XXXerr macro, another library's macro can be used. This is normally
  73. only done when a library wants to include ASN1 code which must use
  74. the ASN1err() macro.
  75. =head2 Adding new libraries
  76. When adding a new sub-library to OpenSSL, assign it a library number
  77. B<ERR_LIB_XXX>, define a macro XXXerr() (both in B<err.h>), add its
  78. name to B<ERR_str_libraries[]> (in B<crypto/err/err.c>), and add
  79. C<ERR_load_XXX_strings()> to the ERR_load_crypto_strings() function
  80. (in B<crypto/err/err_all.c>). Finally, add an entry
  81. L XXX xxx.h xxx_err.c
  82. to B<crypto/err/openssl.ec>, and add B<xxx_err.c> to the Makefile.
  83. Running B<make errors> will then generate a file B<xxx_err.c>, and
  84. add all error codes used in the library to B<xxx.h>.
  85. Additionally the library include file must have a certain form.
  86. Typically it will initially look like this:
  87. #ifndef HEADER_XXX_H
  88. #define HEADER_XXX_H
  89. #ifdef __cplusplus
  90. extern "C" {
  91. #endif
  92. /* Include files */
  93. #include <openssl/bio.h>
  94. #include <openssl/x509.h>
  95. /* Macros, structures and function prototypes */
  96. /* BEGIN ERROR CODES */
  97. The B<BEGIN ERROR CODES> sequence is used by the error code
  98. generation script as the point to place new error codes, any text
  99. after this point will be overwritten when B<make errors> is run.
  100. The closing #endif etc will be automatically added by the script.
  101. The generated C error code file B<xxx_err.c> will load the header
  102. files B<stdio.h>, B<openssl/err.h> and B<openssl/xxx.h> so the
  103. header file must load any additional header files containing any
  104. definitions it uses.
  105. =head1 USING ERROR CODES IN EXTERNAL LIBRARIES
  106. It is also possible to use OpenSSL's error code scheme in external
  107. libraries. The library needs to load its own codes and call the OpenSSL
  108. error code insertion script B<mkerr.pl> explicitly to add codes to
  109. the header file and generate the C error code file. This will normally
  110. be done if the external library needs to generate new ASN1 structures
  111. but it can also be used to add more general purpose error code handling.
  112. TBA more details
  113. =head1 INTERNALS
  114. The error queues are stored in a hash table with one B<ERR_STATE>
  115. entry for each pid. ERR_get_state() returns the current thread's
  116. B<ERR_STATE>. An B<ERR_STATE> can hold up to B<ERR_NUM_ERRORS> error
  117. codes. When more error codes are added, the old ones are overwritten,
  118. on the assumption that the most recent errors are most important.
  119. Error strings are also stored in hash table. The hash tables can
  120. be obtained by calling ERR_get_err_state_table(void) and
  121. ERR_get_string_table(void) respectively.
  122. =head1 SEE ALSO
  123. L<CRYPTO_set_id_callback(3)|CRYPTO_set_id_callback(3)>,
  124. L<CRYPTO_set_locking_callback(3)|CRYPTO_set_locking_callback(3)>,
  125. L<ERR_get_error(3)|ERR_get_error(3)>,
  126. L<ERR_GET_LIB(3)|ERR_GET_LIB(3)>,
  127. L<ERR_clear_error(3)|ERR_clear_error(3)>,
  128. L<ERR_error_string(3)|ERR_error_string(3)>,
  129. L<ERR_print_errors(3)|ERR_print_errors(3)>,
  130. L<ERR_load_crypto_strings(3)|ERR_load_crypto_strings(3)>,
  131. L<ERR_remove_state(3)|ERR_remove_state(3)>,
  132. L<ERR_put_error(3)|ERR_put_error(3)>,
  133. L<ERR_load_strings(3)|ERR_load_strings(3)>,
  134. L<SSL_get_error(3)|SSL_get_error(3)>
  135. =cut