LCOV - code coverage report
Current view: top level - third_party/heimdal/lib/krb5 - log.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 35 77 45.5 %
Date: 2024-04-21 15:09:00 Functions: 8 17 47.1 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 1997-2006 Kungliga Tekniska Högskolan
       3             :  * (Royal Institute of Technology, Stockholm, Sweden).
       4             :  * All rights reserved.
       5             :  *
       6             :  * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
       7             :  *
       8             :  * Redistribution and use in source and binary forms, with or without
       9             :  * modification, are permitted provided that the following conditions
      10             :  * are met:
      11             :  *
      12             :  * 1. Redistributions of source code must retain the above copyright
      13             :  *    notice, this list of conditions and the following disclaimer.
      14             :  *
      15             :  * 2. Redistributions in binary form must reproduce the above copyright
      16             :  *    notice, this list of conditions and the following disclaimer in the
      17             :  *    documentation and/or other materials provided with the distribution.
      18             :  *
      19             :  * 3. Neither the name of the Institute nor the names of its contributors
      20             :  *    may be used to endorse or promote products derived from this software
      21             :  *    without specific prior written permission.
      22             :  *
      23             :  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
      24             :  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
      25             :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
      26             :  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
      27             :  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
      28             :  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
      29             :  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
      30             :  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
      31             :  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
      32             :  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
      33             :  * SUCH DAMAGE.
      34             :  */
      35             : 
      36             : #include "krb5_locl.h"
      37             : #include <assert.h>
      38             : #include <vis.h>
      39             : 
      40             : KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
      41      553462 : krb5_initlog(krb5_context context,
      42             :              const char *program,
      43             :              krb5_log_facility **fac)
      44             : {
      45      553462 :     return heim_initlog(context->hcontext, program, fac);
      46             : }
      47             : 
      48             : struct krb5_addlog_func_wrapper {
      49             :     krb5_context context;
      50             :     krb5_log_log_func_t log_func;
      51             :     krb5_log_close_func_t close_func;
      52             :     void *data;
      53             : };
      54             : 
      55             : static void HEIM_CALLCONV
      56     2182483 : krb5_addlog_func_wrapper_log(heim_context hcontext,
      57             :                              const char *prefix,
      58             :                              const char *msg,
      59             :                              void *data)
      60             : {
      61     2182483 :     struct krb5_addlog_func_wrapper *w = data;
      62             : 
      63     2182483 :     w->log_func(w->context,
      64             :                 prefix,
      65             :                 msg,
      66             :                 w->data);
      67     2182483 : }
      68             : 
      69             : static void HEIM_CALLCONV
      70      551269 : krb5_addlog_func_wrapper_close(void *data)
      71             : {
      72      551269 :     struct krb5_addlog_func_wrapper *w = data;
      73             : 
      74      551269 :     w->close_func(w->data);
      75      551269 :     free(w);
      76      551269 : }
      77             : 
      78             : KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
      79      553462 : krb5_addlog_func(krb5_context context,
      80             :                  krb5_log_facility *fac,
      81             :                  int min,
      82             :                  int max,
      83             :                  krb5_log_log_func_t log_func,
      84             :                  krb5_log_close_func_t close_func,
      85             :                  void *data)
      86             : {
      87      553462 :     struct krb5_addlog_func_wrapper *w = NULL;
      88             : 
      89      553462 :     w = calloc(1, sizeof(*w));
      90      553462 :     if (w == NULL)
      91           0 :         return krb5_enomem(context);
      92             : 
      93      553462 :     w->context = context;
      94      553462 :     w->log_func = log_func;
      95      553462 :     w->close_func = close_func;
      96      553462 :     w->data = data;
      97             : 
      98      553462 :     return heim_addlog_func(context->hcontext, fac, min, max,
      99             :                             krb5_addlog_func_wrapper_log,
     100             :                             krb5_addlog_func_wrapper_close,
     101             :                             w);
     102             : }
     103             : 
     104             : KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     105           0 : krb5_addlog_dest(krb5_context context, krb5_log_facility *f, const char *orig)
     106             : {
     107           0 :     return heim_addlog_dest(context->hcontext, f, orig);
     108             : }
     109             : 
     110             : 
     111             : KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     112           0 : krb5_openlog(krb5_context context,
     113             :              const char *program,
     114             :              krb5_log_facility **fac)
     115             : {
     116           0 :     krb5_error_code ret;
     117           0 :     char **p;
     118             : 
     119           0 :     p = krb5_config_get_strings(context, NULL, "logging", program, NULL);
     120           0 :     if (p == NULL)
     121           0 :         p = krb5_config_get_strings(context, NULL, "logging", "default", NULL);
     122           0 :     ret = heim_openlog(context->hcontext, program, (const char **)p, fac);
     123           0 :     krb5_config_free_strings(p);
     124           0 :     return ret;
     125             : }
     126             : 
     127             : KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     128      551269 : krb5_closelog(krb5_context context,
     129             :              krb5_log_facility *fac)
     130             : {
     131      551269 :     heim_closelog(context->hcontext, fac);
     132      551269 :     return 0;
     133             : }
     134             : 
     135             : #undef __attribute__
     136             : #define __attribute__(X)
     137             : 
     138             : KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     139     1037068 : krb5_vlog_msg(krb5_context context,
     140             :               krb5_log_facility *fac,
     141             :               char **reply,
     142             :               int level,
     143             :               const char *fmt,
     144             :               va_list ap)
     145             :      __attribute__ ((__format__ (__printf__, 5, 0)))
     146             : {
     147     1037068 :     return heim_vlog_msg(context->hcontext, fac, reply, level, fmt, ap);
     148             : }
     149             : 
     150             : KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     151           0 : krb5_vlog(krb5_context context,
     152             :           krb5_log_facility *fac,
     153             :           int level,
     154             :           const char *fmt,
     155             :           va_list ap)
     156             :      __attribute__ ((__format__ (__printf__, 4, 0)))
     157             : {
     158           0 :     return heim_vlog_msg(context->hcontext, fac, NULL, level, fmt, ap);
     159             : }
     160             : 
     161             : KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     162           0 : krb5_log_msg(krb5_context context,
     163             :              krb5_log_facility *fac,
     164             :              int level,
     165             :              char **reply,
     166             :              const char *fmt,
     167             :              ...)
     168             :      __attribute__ ((__format__ (__printf__, 5, 6)))
     169             : {
     170           0 :     va_list ap;
     171           0 :     krb5_error_code ret;
     172             : 
     173           0 :     va_start(ap, fmt);
     174           0 :     ret = heim_vlog_msg(context->hcontext, fac, reply, level, fmt, ap);
     175           0 :     va_end(ap);
     176           0 :     return ret;
     177             : }
     178             : 
     179             : 
     180             : KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     181           0 : krb5_log(krb5_context context,
     182             :          krb5_log_facility *fac,
     183             :          int level,
     184             :          const char *fmt,
     185             :          ...)
     186             :      __attribute__ ((__format__ (__printf__, 4, 5)))
     187             : {
     188           0 :     va_list ap;
     189           0 :     krb5_error_code ret;
     190             : 
     191           0 :     va_start(ap, fmt);
     192           0 :     ret = heim_vlog(context->hcontext, fac, level, fmt, ap);
     193           0 :     va_end(ap);
     194           0 :     return ret;
     195             : }
     196             : 
     197             : void KRB5_LIB_FUNCTION
     198     2159276 : _krb5_debug(krb5_context context,
     199             :             int level,
     200             :             const char *fmt,
     201             :             ...)
     202             :     __attribute__ ((__format__ (__printf__, 3, 4)))
     203             : {
     204       56821 :     va_list ap;
     205             : 
     206     2159276 :     va_start(ap, fmt);
     207     2159276 :     if (context && context->hcontext)
     208     2159276 :         heim_vdebug(context->hcontext, level, fmt, ap);
     209     2159276 :     va_end(ap);
     210     2159276 : }
     211             : 
     212             : void KRB5_LIB_FUNCTION
     213           0 : krb5_debug(krb5_context context,
     214             :             int level,
     215             :             const char *fmt,
     216             :             ...)
     217             :     __attribute__ ((__format__ (__printf__, 3, 4)))
     218             : {
     219           0 :     va_list ap;
     220             : 
     221           0 :     va_start(ap, fmt);
     222           0 :     if (context && context->hcontext)
     223           0 :         heim_vdebug(context->hcontext, level, fmt, ap);
     224           0 :     va_end(ap);
     225           0 : }
     226             : 
     227             : KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
     228      711494 : _krb5_have_debug(krb5_context context, int level)
     229             : {
     230      711494 :     if (context == NULL || context->hcontext == NULL)
     231           0 :         return 0;
     232      711494 :     return heim_have_debug(context->hcontext, level);
     233             : }
     234             : 
     235             : KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
     236           0 : krb5_have_debug(krb5_context context, int level)
     237             : {
     238           0 :     return _krb5_have_debug(context, level);
     239             : }
     240             : 
     241             : KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     242           0 : krb5_set_debug_dest(krb5_context context, const char *program,
     243             :                     const char *log_spec)
     244             : {
     245           0 :     return heim_add_debug_dest(context->hcontext, program, log_spec);
     246             : }
     247             : 
     248             : KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     249           0 : krb5_set_log_dest(krb5_context context, krb5_log_facility *fac)
     250             : {
     251           0 :     return heim_set_log_dest(context->hcontext, fac);
     252             : }

Generated by: LCOV version 1.14