LCOV - code coverage report
Current view: top level - third_party/heimdal/lib/krb5 - warn.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 22 50 44.0 %
Date: 2024-04-21 15:09:00 Functions: 7 15 46.7 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 1997 - 2001 Kungliga Tekniska Högskolan
       3             :  * (Royal Institute of Technology, Stockholm, Sweden).
       4             :  * All rights reserved.
       5             :  *
       6             :  * Redistribution and use in source and binary forms, with or without
       7             :  * modification, are permitted provided that the following conditions
       8             :  * are met:
       9             :  *
      10             :  * 1. Redistributions of source code must retain the above copyright
      11             :  *    notice, this list of conditions and the following disclaimer.
      12             :  *
      13             :  * 2. Redistributions in binary form must reproduce the above copyright
      14             :  *    notice, this list of conditions and the following disclaimer in the
      15             :  *    documentation and/or other materials provided with the distribution.
      16             :  *
      17             :  * 3. Neither the name of the Institute nor the names of its contributors
      18             :  *    may be used to endorse or promote products derived from this software
      19             :  *    without specific prior written permission.
      20             :  *
      21             :  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
      22             :  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
      23             :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
      24             :  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
      25             :  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
      26             :  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
      27             :  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
      28             :  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
      29             :  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
      30             :  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
      31             :  * SUCH DAMAGE.
      32             :  */
      33             : 
      34             : #if defined(_MSC_VER)
      35             : # pragma warning(disable: 4646)
      36             : # pragma warning(disable: 4716)
      37             : #endif
      38             : 
      39             : #include "krb5_locl.h"
      40             : #include <err.h>
      41             : 
      42             : static krb5_error_code _warnerr(krb5_context context, int do_errtext,
      43             :          krb5_error_code code, int level, const char *fmt, va_list ap)
      44             :         __attribute__ ((__format__ (__printf__, 5, 0)));
      45             : 
      46             : static krb5_error_code
      47           2 : _warnerr(krb5_context context, int do_errtext,
      48             :          krb5_error_code code, int level, const char *fmt, va_list ap)
      49             : {
      50           2 :     if (do_errtext)
      51           2 :         return heim_vwarn(context ? context->hcontext : NULL, code, fmt, ap);
      52             :     else
      53           0 :         return heim_vwarnx(context ? context->hcontext : NULL, fmt, ap);
      54             : }
      55             : 
      56             : #define FUNC_NORET(ETEXT, CODE, LEVEL)                                 \
      57             :     va_list ap;                                                        \
      58             :     va_start(ap, fmt);                                                 \
      59             :     (void) _warnerr(context, ETEXT, CODE, LEVEL, fmt, ap);             \
      60             :     va_end(ap);
      61             : 
      62             : #undef __attribute__
      63             : #define __attribute__(X)
      64             : 
      65             : /**
      66             :  * Log a warning to the log, default stderr, include the error from
      67             :  * the last failure.
      68             :  *
      69             :  * @param context A Kerberos 5 context.
      70             :  * @param code error code of the last error
      71             :  * @param fmt message to print
      72             :  * @param ap arguments
      73             :  *
      74             :  * @ingroup krb5_error
      75             :  */
      76             : 
      77             : KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
      78          49 : krb5_vwarn(krb5_context context, krb5_error_code code,
      79             :            const char *fmt, va_list ap)
      80             :      __attribute__ ((__format__ (__printf__, 3, 0)))
      81             : {
      82          49 :     return heim_vwarn(context ? context->hcontext : NULL, code, fmt, ap);
      83             : }
      84             : 
      85             : /**
      86             :  * Log a warning to the log, default stderr, include the error from
      87             :  * the last failure.
      88             :  *
      89             :  * @param context A Kerberos 5 context.
      90             :  * @param code error code of the last error
      91             :  * @param fmt message to print
      92             :  *
      93             :  * @ingroup krb5_error
      94             :  */
      95             : 
      96             : KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
      97          49 : krb5_warn(krb5_context context, krb5_error_code code, const char *fmt, ...)
      98             :      __attribute__ ((__format__ (__printf__, 3, 4)))
      99             : {
     100           0 :     krb5_error_code ret;
     101           0 :     va_list ap;
     102             : 
     103          49 :     va_start(ap, fmt);
     104          49 :     ret = krb5_vwarn(context, code, fmt, ap);
     105          49 :     va_end(ap);
     106          49 :     return ret;
     107             : }
     108             : 
     109             : /**
     110             :  * Log a warning to the log, default stderr.
     111             :  *
     112             :  * @param context A Kerberos 5 context.
     113             :  * @param fmt message to print
     114             :  * @param ap arguments
     115             :  *
     116             :  * @ingroup krb5_error
     117             :  */
     118             : 
     119             : KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     120         732 : krb5_vwarnx(krb5_context context, const char *fmt, va_list ap)
     121             :      __attribute__ ((__format__ (__printf__, 2, 0)))
     122             : {
     123         732 :     return heim_vwarnx(context ? context->hcontext : NULL, fmt, ap);
     124             : }
     125             : 
     126             : /**
     127             :  * Log a warning to the log, default stderr.
     128             :  *
     129             :  * @param context A Kerberos 5 context.
     130             :  * @param fmt message to print
     131             :  *
     132             :  * @ingroup krb5_error
     133             :  */
     134             : 
     135             : KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     136         732 : krb5_warnx(krb5_context context, const char *fmt, ...)
     137             :      __attribute__ ((__format__ (__printf__, 2, 3)))
     138             : {
     139           0 :     krb5_error_code ret;
     140           0 :     va_list ap;
     141             : 
     142         732 :     va_start(ap, fmt);
     143         732 :     ret = krb5_vwarnx(context, fmt, ap);
     144         732 :     va_end(ap);
     145         732 :     return ret;
     146             : }
     147             : 
     148             : /**
     149             :  * Log a warning to the log, default stderr, include bthe error from
     150             :  * the last failure and then exit.
     151             :  *
     152             :  * @param context A Kerberos 5 context
     153             :  * @param eval the exit code to exit with
     154             :  * @param code error code of the last error
     155             :  * @param fmt message to print
     156             :  * @param ap arguments
     157             :  *
     158             :  * @ingroup krb5_error
     159             :  */
     160             : 
     161             : KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
     162           0 : krb5_verr(krb5_context context, int eval, krb5_error_code code,
     163             :           const char *fmt, va_list ap)
     164             :      __attribute__ ((__noreturn__, __format__ (__printf__, 4, 0)))
     165             : {
     166           0 :     _warnerr(context, 1, code, 0, fmt, ap);
     167           0 :     exit(eval);
     168             :     UNREACHABLE(return 0);
     169             : }
     170             : 
     171             : /**
     172             :  * Log a warning to the log, default stderr, include bthe error from
     173             :  * the last failure and then exit.
     174             :  *
     175             :  * @param context A Kerberos 5 context
     176             :  * @param eval the exit code to exit with
     177             :  * @param code error code of the last error
     178             :  * @param fmt message to print
     179             :  *
     180             :  * @ingroup krb5_error
     181             :  */
     182             : 
     183             : KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
     184           2 : krb5_err(krb5_context context, int eval, krb5_error_code code,
     185             :          const char *fmt, ...)
     186             :      __attribute__ ((__noreturn__, __format__ (__printf__, 4, 5)))
     187             : {
     188           2 :     FUNC_NORET(1, code, 0);
     189           2 :     exit(eval);
     190             :     UNREACHABLE(return 0);
     191             : }
     192             : 
     193             : /**
     194             :  * Log a warning to the log, default stderr, and then exit.
     195             :  *
     196             :  * @param context A Kerberos 5 context
     197             :  * @param eval the exit code to exit with
     198             :  * @param fmt message to print
     199             :  * @param ap arguments
     200             :  *
     201             :  * @ingroup krb5_error
     202             :  */
     203             : 
     204             : KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
     205           0 : krb5_verrx(krb5_context context, int eval, const char *fmt, va_list ap)
     206             :      __attribute__ ((__noreturn__, __format__ (__printf__, 3, 0)))
     207             : {
     208           0 :     _warnerr(context, 0, 0, 0, fmt, ap);
     209           0 :     exit(eval);
     210             :     UNREACHABLE(return 0);
     211             : }
     212             : 
     213             : /**
     214             :  * Log a warning to the log, default stderr, and then exit.
     215             :  *
     216             :  * @param context A Kerberos 5 context
     217             :  * @param eval the exit code to exit with
     218             :  * @param fmt message to print
     219             :  *
     220             :  * @ingroup krb5_error
     221             :  */
     222             : 
     223             : KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
     224           0 : krb5_errx(krb5_context context, int eval, const char *fmt, ...)
     225             :      __attribute__ ((__noreturn__, __format__ (__printf__, 3, 4)))
     226             : {
     227           0 :     FUNC_NORET(0, 0, 0);
     228           0 :     exit(eval);
     229             :     UNREACHABLE(return 0);
     230             : }
     231             : 
     232             : /**
     233             :  * Log a warning to the log, default stderr, include bthe error from
     234             :  * the last failure and then abort.
     235             :  *
     236             :  * @param context A Kerberos 5 context
     237             :  * @param code error code of the last error
     238             :  * @param fmt message to print
     239             :  * @param ap arguments
     240             :  *
     241             :  * @ingroup krb5_error
     242             :  */
     243             : 
     244             : KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
     245           0 : krb5_vabort(krb5_context context, krb5_error_code code,
     246             :             const char *fmt, va_list ap)
     247             :      __attribute__ ((__noreturn__, __format__ (__printf__, 3, 0)))
     248             : {
     249           0 :     _warnerr(context, 1, code, 0, fmt, ap);
     250           0 :     abort();
     251             :     UNREACHABLE(return 0);
     252             : }
     253             : 
     254             : /**
     255             :  * Log a warning to the log, default stderr, include the error from
     256             :  * the last failure and then abort.
     257             :  *
     258             :  * @param context A Kerberos 5 context
     259             :  * @param code error code of the last error
     260             :  * @param fmt message to print
     261             :  * @param ... arguments for format string
     262             :  *
     263             :  * @ingroup krb5_error
     264             :  */
     265             : 
     266             : KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
     267           0 : krb5_abort(krb5_context context, krb5_error_code code, const char *fmt, ...)
     268             :      __attribute__ ((__noreturn__, __format__ (__printf__, 3, 4)))
     269             : {
     270           0 :     FUNC_NORET(1, code, 0);
     271           0 :     abort();
     272             :     UNREACHABLE(return 0);
     273             : }
     274             : 
     275             : KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
     276           0 : krb5_vabortx(krb5_context context, const char *fmt, va_list ap)
     277             :      __attribute__ ((__noreturn__, __format__ (__printf__, 2, 0)))
     278             : {
     279           0 :     _warnerr(context, 0, 0, 0, fmt, ap);
     280           0 :     abort();
     281             :     UNREACHABLE(return 0);
     282             : }
     283             : 
     284             : /**
     285             :  * Log a warning to the log, default stderr, and then abort.
     286             :  *
     287             :  * @param context A Kerberos 5 context
     288             :  * @param fmt printf format string of message to print
     289             :  * @param ... arguments for format string
     290             :  *
     291             :  * @ingroup krb5_error
     292             :  */
     293             : 
     294             : KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
     295           0 : krb5_abortx(krb5_context context, const char *fmt, ...)
     296             :      __attribute__ ((__noreturn__, __format__ (__printf__, 2, 3)))
     297             : {
     298           0 :     FUNC_NORET(0, 0, 0);
     299           0 :     abort();
     300             :     UNREACHABLE(return 0);
     301             : }
     302             : 
     303             : /**
     304             :  * Set the default logging facility.
     305             :  *
     306             :  * @param context A Kerberos 5 context
     307             :  * @param fac Facility to use for logging.
     308             :  *
     309             :  * @ingroup krb5_error
     310             :  */
     311             : 
     312             : KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     313     1104731 : krb5_set_warn_dest(krb5_context context, krb5_log_facility *fac)
     314             : {
     315     1104731 :     return heim_set_warn_dest(context->hcontext, fac);
     316             : }
     317             : 
     318             : /**
     319             :  * Get the default logging facility.
     320             :  *
     321             :  * @param context A Kerberos 5 context
     322             :  *
     323             :  * @ingroup krb5_error
     324             :  */
     325             : 
     326             : KRB5_LIB_FUNCTION krb5_log_facility * KRB5_LIB_CALL
     327           0 : krb5_get_warn_dest(krb5_context context)
     328             : {
     329           0 :     return heim_get_warn_dest(context->hcontext);
     330             : }

Generated by: LCOV version 1.14