~ubuntu-branches/ubuntu/trusty/postfix/trusty-proposed

« back to all changes in this revision

Viewing changes to src/global/debug_peer.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2005-02-27 09:33:07 UTC
  • Revision ID: james.westby@ubuntu.com-20050227093307-cn789t27ibnlh6tf
Tags: upstream-2.1.5
ImportĀ upstreamĀ versionĀ 2.1.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*++
 
2
/* NAME
 
3
/*      debug_peer 3
 
4
/* SUMMARY
 
5
/*      increase verbose logging for specific peers
 
6
/* SYNOPSIS
 
7
/*      #include <debug_peer.h>
 
8
/*
 
9
/*      void    debug_peer_init(void)
 
10
/*
 
11
/*      int     peer_debug_check(peer_name, peer_addr)
 
12
/*      const char *peer_name;
 
13
/*      const char *peer_addr;
 
14
/*
 
15
/*      void    debug_peer_restore()
 
16
/* DESCRIPTION
 
17
/*      This module implements increased verbose logging for specific
 
18
/*      network peers.
 
19
/*
 
20
/*      The \fIdebug_peer_list\fR configuration parameter
 
21
/*      specifies what peers receive this special treatment; see
 
22
/*      namadr_list(3) for a description of the matching process.
 
23
/*
 
24
/*      The \fIdebug_peer_level\fR configuration parameter specifies
 
25
/*      by what amount the verbose logging level should increase when
 
26
/*      a peer is listed in \fIdebug_peer_list\fR.
 
27
/*
 
28
/*      debug_peer_init() performs initializations that must be
 
29
/*      performed once at the start of the program.
 
30
/*
 
31
/*      debug_peer_check() increases the verbose logging level when the
 
32
/*      client name or address matches the debug_peer_list pattern.
 
33
/*      The result is non-zero when the noise leven was increased.
 
34
/*
 
35
/*      debug_peer_restore() restores the verbose logging level.
 
36
/*      This routine has no effect when debug_peer_check() had no
 
37
/*      effect; this routine can safely be called multiple times.
 
38
/* DIAGNOSTICS
 
39
/*      Panic: interface violations.
 
40
/*      Fatal errors: unable to access a peer_list file; invalid
 
41
/*      peer_list pattern; invalid verbosity level increment.
 
42
/* SEE ALSO
 
43
/*      msg(3) the msg_verbose variable
 
44
/*      namadr_list(3) match host by name or by address
 
45
/* CONFIG PARAMETERS
 
46
/*      debug_peer_list, patterns as described in namadr_list(3)
 
47
/*      debug_peer_level, verbose logging level
 
48
/* LICENSE
 
49
/* .ad
 
50
/* .fi
 
51
/*      The Secure Mailer license must be distributed with this software.
 
52
/* AUTHOR(S)
 
53
/*      Wietse Venema
 
54
/*      IBM T.J. Watson Research
 
55
/*      P.O. Box 704
 
56
/*      Yorktown Heights, NY 10598, USA
 
57
/*--*/
 
58
 
 
59
/* System library. */
 
60
 
 
61
#include <sys_defs.h>
 
62
 
 
63
/* Utility library. */
 
64
 
 
65
#include <msg.h>
 
66
 
 
67
/* Global library. */
 
68
 
 
69
#include <mail_params.h>
 
70
#include <namadr_list.h>
 
71
#include <debug_peer.h>
 
72
#include <match_parent_style.h>
 
73
 
 
74
/* Application-specific. */
 
75
 
 
76
#define UNUSED_SAVED_LEVEL      (-1)
 
77
 
 
78
static NAMADR_LIST *debug_peer_list;
 
79
static int saved_level = UNUSED_SAVED_LEVEL;
 
80
 
 
81
/* debug_peer_init - initialize */
 
82
 
 
83
void    debug_peer_init(void)
 
84
{
 
85
    char   *myname = "debug_peer_init";
 
86
 
 
87
    /*
 
88
     * Sanity check.
 
89
     */
 
90
    if (debug_peer_list)
 
91
        msg_panic("%s: repeated call", myname);
 
92
    if (var_debug_peer_list == 0)
 
93
        msg_panic("%s: uninitialized %s", myname, VAR_DEBUG_PEER_LIST);
 
94
    if (var_debug_peer_level <= 0)
 
95
        msg_fatal("%s: %s <= 0", myname, VAR_DEBUG_PEER_LEVEL);
 
96
 
 
97
    /*
 
98
     * Finally.
 
99
     */
 
100
    if (*var_debug_peer_list)
 
101
        debug_peer_list =
 
102
            namadr_list_init(match_parent_style(VAR_DEBUG_PEER_LIST),
 
103
                             var_debug_peer_list);
 
104
}
 
105
 
 
106
/* debug_peer_check - see if this peer needs verbose logging */
 
107
 
 
108
int     debug_peer_check(const char *name, const char *addr)
 
109
{
 
110
 
 
111
    /*
 
112
     * Crank up the noise when this peer is listed.
 
113
     */
 
114
    if (debug_peer_list != 0
 
115
        && saved_level == UNUSED_SAVED_LEVEL
 
116
        && namadr_list_match(debug_peer_list, name, addr) != 0) {
 
117
        saved_level = msg_verbose;
 
118
        msg_verbose += var_debug_peer_level;
 
119
        return (1);
 
120
    }
 
121
    return (0);
 
122
}
 
123
 
 
124
/* debug_peer_restore - restore logging level */
 
125
 
 
126
void    debug_peer_restore(void)
 
127
{
 
128
    if (saved_level != UNUSED_SAVED_LEVEL) {
 
129
        msg_verbose = saved_level;
 
130
        saved_level = UNUSED_SAVED_LEVEL;
 
131
    }
 
132
}